Retro programming! Pascal and CP/M on a Z80 computer
Let's investigate CP/M on my RC2014 Z80 based computer.
CP/M was an operating system before MS-DOS existed, and it requires surprisingly few resources to run. This computer runs at 7MHz and has 64K of RAM. CP/M itself fits into just 8K!
Let's celebrate #piday in this appropriately short video by writing some #python programs to calculate Pi.
The first method uses something called the Gauss-Legendre method. It works by iteratively refining an approximation of Pi, generating the answer digit by digit.
When writing code to calculate Pi we run into issues trying to store the calculated value. A floating point or double precision float will only store so many bits. It's like fractal zoom programs where there is a maximum depth due to the computer being unable to store the values being used.
Generating Pi digit by digit seems to get around this problem for the most part. Although I'm sure the intermediate values stored in the variables will eventually overflow.
The second way uses a statistical method that you've unknowingly seen if you've ever used Blender. Based on the Monte Carlo statistical methods, there is a way to calculate Pi by simply drawing a circle inside a square and randomly filling it with points.
Dividing the number of points inside the circle by the number of points plotted, and multiplying the result by four gives an approximation of Pi.
Coding this is quite easy because it doesn't need to be done visually. Working out whether a point is inside a circle is a simple piece of maths.
Interestingly if we draw all the points on the screen and colour them, the result draws an arc.
But since Pi is an irrational number, we could just round it down to 3 and use that. It's probably close enough. Although saying this near mathematicians makes them go all irrational too.
Happy Pi day!
Links:
Web - https://ncot.uk
Gauss-legendre python code - https://gist.github.com/ncot-tech/4b109dca121f7e02fd21a6314f4dd645
Monte-Carlo method for calculating pi - https://gist.github.com/ncot-tech/2f29a6dfb7bc5f955eacdc2770285beb
Credits:
Raspberry Pi Pico 3D Model - https://www.blendswap.com/blend/27180
...
https://www.youtube.com/watch?v=cQA4AHlO8PQ
Trying out some short generative art programs using P5.js
Source code here: https://editor.p5js.org/piku/sketches/He6MD-PCj
Subscribe for more!
...
https://www.youtube.com/watch?v=ktsdjHhpnHs
It now has a proper game loop and everything!
For reasons beyond my understanding some of the sounds don't always play. Never mind. The game might hate you, but the devkit sure does hate me.
...
https://www.youtube.com/watch?v=GEyUnLHETk8
Soldering (so much soldering!), oscilloscopes and logic analysers! My experience building an RC2014 Z80 based computer kit.
The kit consists of a backplane, Z80 CPU board, RAM, ROM, Serial I/O and a Compact Flash storage card. Currently it's running MS Basic, but later I'll get CP/M running and explore that.
...
https://www.youtube.com/watch?v=2HVt1FPGzpA
Visit my blog here: http://www.ncot.uk/blog/posts/getting-down-to-the-metal/
My first code using the ESP-IDF toolchain and code from https://github.com/OtherCrashOverride/odroid-go-firmware/tree/feature-lcd/main
...
https://www.youtube.com/watch?v=hkOt2E2t1ug