Challenge 3
Due: Monday, February 10 at 4:15 p.m. (in class)
You may work on this challenge as a team.
Before you start…
- If you want stay with the same team (or solo) arrangement as Challenge 1 or 2, you use your existing repository and create a
Challenge03directory in it. - If you want to work with a new group (or switch to solo work) Accept the Challenge on GitHub Classroom.
- There is no starter code in the repository, so don't worry if you don't see anything much there. It's up to you to add material to the repository (in the
Challenge03directory) and then push your changes to GitHub.
Log in to the Course Server
If you're using Visual Studio Code, you can use the Remote - SSH extension to connect to the course server. If you're using a different editor, you can use ssh to connect to the course server. The course server is retro.cs.hmc.edu, and your id and login information was emailed to you by Nic Dodds.
Explore the SDCC C Compiler
Although it would be cool to write directly in Z80 assembly language, it's a little arcane and has a somewhat steep learning code. C code can often be close to the performance of hand-written assembly, and is much easier to write and maintain. The SDCC C Compiler is a free, open-source, retargettable, optimizing ANSI C compiler suite that supports a number of different 8-bit processors, including the Z80.
The compiler is installed on the course server (retro.cs.hmc.edu). You can find a demo directory to try by logging in and running:
cp -a ~melissa/pub/sdcc-demo .
cd sdcc-demo
make
This will create the following .tap files:
-
screenfill.tap— compiled fromscreenfill.c, which a simple program that fills the screen the vertical-line pattern we saw in class. The code generated by SDCC can be found inscreenfill.asmand is quite efficient. The main screen-filling loop is:asm _main:: ld hl, $4000 ;; Start of screen memory main_loop: ld a, h sub a, $58 ;; Past-the-end of screen memory is $5800 jr NC, loop_done ld (hl), $aa ;; 0b10101010; inc hl jr main_loop loop_done: ld de, 42 ;; main returns 42 ret -
demo.tap— compiled fromdemo.c, which is a simple program that calls some of the functions defined inzx-rom.hand the standard C library. -
generic-loader.tap— a BASIC program that can load and run the machine code in the other two tapes.
To make a tape which has both the loader and the code, you can just concatenate the files together, like this:
cat generic-loader.tap screenfill.tap > combined1.tap
cat generic-loader.tap demo.tap > combined2.tap
Check Out Some Sample Game Code
(Coming soon!)
Your task…
Last week, you wrote a game in BASIC for the ZX Spectrum that showcased what can be achieved in BASIC on the machine your challenge is this:
- “Outdo” your previous game.
There are a few ways you could do this:
- Add some sound effects to your game (from simple
BEEPcommands, to more complex sound effects generated by the machine code routines). - Add background music to your game (advanced!)
- Make your game faster or more responsive.
- Add more levels or complexity to your game, fixing any bugs that you found in the previous version, or improving the graphics or interface.
- Write an entirely new game based on a different idea.
You may steal ideas from other games, but be sure to be generous with your attribution. If you use a routine written by someone else, or a clever approach someone else figured out, be sure to mention it somewhere in your code or documentation.
(When logged in, completion status appears here.)