Last active
May 25, 2020 21:10
-
-
Save sinewalker/c8fa68158a63f95c01c5eb39f354df7b to your computer and use it in GitHub Desktop.
Pick-up Sticks: early 8-bit graphics hack (BASIC)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 5 REM This is for Amstrad CPC Locomotive BASIC | |
| 10 CLS | |
| 20 WHILE 1>0 | |
| 30 GRAPHICS PEN 15*RND | |
| 40 MOVE 640*RND,400*RND | |
| 50 DRAW 640*RND,400*RND | |
| 60 WEND |
Author
Author
Note that the presence of GRAPHICS PEN means that this program would not run on a CPC-464. In fact when I wrote this, around 1986-or-so, it was on the family's old/original generation CPC-6128.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See a Web implementation of this program (The code is 64(Javascript) +15(CSS) +6(HTML5) SLOC as opposed to just 6 SLOC for the original!)
The Amstrad CPC uses a logical graphics coordinate space with Origin in the bottom-left corner, and a fixed coordinate range of 640 logical coordinates increasing horizontally, by 400 logical coordinates increasing vertically. The
MOVE,DRAW, etc BASIC graphics commands will execute ROM code that translates from these logical coordinates into the physical pixels on the screen.The CPC has different graphics Modes where the pixels are physically larger. On the lowest resolution, 4-bit colour mode, the screen is actually only 160x200 pixels, and even on the highest resolution, monochrome mode, the screen is still only 640x200 pixels. This is so that the ROM can maintain a shared video buffer at a constant 16kiB of RAM even though each pixel's memory requirement goes up by powers of 2 for more colour depth.
By using the logical coordinates, although the physical pixels are not individually addressable (unless you calculate their logical coordinates yourself) it does mean that logical position 320,200 is always the centre of the screen in any mode, and 640,400 is always the top-right corner, and so on. Also the aspect of images specified by logical coordinates is maintained, even though the aspect of pixels varies dramatically: a 100x100 box is always drawn as a square on the CPC, but 100x100 pixels is only square in the 2-bit colour mode that is 320x200 pixels (sharing the screen's 4:3 aspect ratio).
All of these are constraints of the ROM library only. It's possible to reprogram the CPC's programmable gate array (below the ROM, directly at the chip) to have more pixels (requiring more RAM for the buffer), or have different parts of the screen using different sized pixels/colours and so on, although I believe that the maximum bit depth supported by the RAMDAC is 4-bits (16 colours), and the colour palette is lookup based with limited control over the actual RBG values you can set for each palette entry (there is a table of 32 palette colours, 0-27 are fixed and the final 4 are programmable).