TUTORIAL · BREAKOUT · STAGE 1 OF 8BETA
Stage 1 · Title screen
Before any game code: pin down the machine, the BASIC, the ROMs and how many bytes you have, then put a title screen up and wait for SPACE. Most mysterious BBC crashes come from getting one of those four wrong.

The target
| Question | Answer for BRICKFALL |
|---|---|
| Machine | BBC Master 128, 65C12 at 2 MHz, no second processor |
| Language | BBC BASIC IV, integer variables throughout. No BASIC V keywords: no INSTALL, LIBRARY or WHILE |
| Filing system | DFS from a floppy image |
| Screen | MODE 1: 320×256 in four colours, 20 KB, twice over, because the Master has a shadow page |
| ROMs | EGFX in slots 4 and 6 (all drawing), the EGASSETS sprite ROM in slot 7, EAudio in slot 5 (sound, stage 8) |
The game is Master-only on purpose: from stage 2 it draws on one screen page while you look at the other, and a BBC B has no second page to draw on.
The memory map
| Address | Owner | Notes |
|---|---|---|
&0E00 | PAGE | Measured on the Master with DFS (a BBC B with DFS starts at &1900) |
&0E00–&1DFF | Program, 4096 bytes | The finished game is 4090 tokenised bytes, so there are 6 to spare. The build fails if any stage goes over |
&1E00–&23FF | Variables, arrays, strings, BASIC stack | 1536 bytes for a%(5,7), the 64-byte request block and PROC frames |
&2400 | HIMEM | Set on line 5, before any PROC call or DIM |
&2400–&2BFF | EGFX workspace | Particle pool, fast kernels, scratch and the parameter block |
&3000–&7FFF | Screen | Main and shadow pages: EGFX decides which one is mapped in for drawing |
PROCeginit checks TOP<=&2200 and HIMEM=&2400, so a program that has grown past its budget stops with EGFX MEM instead of quietly overwriting the ROM's workspace.
The lines
Type these 9 lines, or load them from the disc with CHAIN "STAGE1".
Text after :REM and indented continuation lines are Beeb-dev notes and layout: the build strips them, so they cost the BBC nothing. Typing into a real BBC, leave the notes out and join each continuation line onto the line above.
5 MODE 1:HIMEM=&2400 :REM four colours, 320x256, 20K of screen
REM HIMEM drops to &2400 before any PROC call or DIM: EGFX's
REM workspace starts there and BASIC's stack must never reach it
20 PROCeginit :REM start EGFX: checks TOP<=&2200 and HIMEM=&2400,
REM fills the 64-byte request block and makes sure EGFX is fitted
40 PROCstartscreen :REM title screen: comes back when SPACE is pressed
210 MODE 7:END :REM back to the text screen
220 DEF PROCstartscreen :REM the title is one frame, drawn once
230 PROCegbegin :REM clear the hidden page
:FOR y%=24 TO 88 STEP 8 :REM nine lines, 8 pixels apart...
:PROCegline(40,y%,280,y%,(y% DIV 8) MOD 4) :REM ...cycling colours 0-3
:NEXT :REM for a raster-stripe effect
:PROCegtext("BRICKFALL",120,48) :REM text must sit on 8-pixel boundaries
:PROCegline(64,80,256,80,3) :REM underline in colour 3
240 PROCegtext("PRESS SPACE",112,176)
:PROCegpresent :REM show it at vsync
250 REPEAT:UNTIL INKEY(0)=32:*FX 15
REM wait for SPACE in the keyboard buffer (positive INKEY), then *FX 15
REM empties the buffer so the key cannot leak into the game
260 ENDPROC
Line 5 changes MODE and moves HIMEM before anything else runs (lowering HIMEM later, once PROC frames exist, would pull BASIC's stack out from under a running program). Line 20 starts EGFX. Line 40 shows the title, and line 210 goes back to MODE 7 and ends, which is all a title screen with no game behind it can do.
One call, every time
1000 DEF PROCeginit
1010 IF HIMEM>&2400 OR TOP>&2200 PRINT "EGFX MEM":END
1020 DIM egb% 63:LOCAL egi%
1025 FOR egi%=0 TO 63:egb%?egi%=0:NEXT
1040 egb%?0=64:egb%?1=8:egb%?2=69:egb%?3=71:egb%?4=1
1045 PROCegcall(0):ENDPROC
1050 DEF PROCegcall(egf%)
1070 egb%?5=egf%:egb%?7=0
1080 A%=&C0:X%=egb% MOD 256:Y%=egb% DIV 256:CALL &FFF1
1090 IF egb%?7<>&A5 PRINT "NO EGFX ROM":END
1095 IF egf%>=11 AND egf%<>22 AND egf%<>23 AND egb%?6<>0 PRINT "EG ERROR":END
1100 ENDPROC
Every EGFX feature is reached the same way: fill in a 64-byte block and pass it to OSWORD &C0. The MOS offers the block to each sideways ROM, and EGFX claims it because of the EG signature and version byte. The header is written once in PROCeginit, then each call sets only the function number, clears the acknowledgement byte and checks the ROM answered &A5 (a missing ROM stops with NO EGFX ROM instead of drawing nothing). That round trip costs about 1.7 centiseconds before EGFX draws a pixel, and that one number explains a lot of the later stages.
The title screen
220 DEF PROCstartscreen :REM the title is one frame, drawn once
230 PROCegbegin :REM clear the hidden page
:FOR y%=24 TO 88 STEP 8 :REM nine lines, 8 pixels apart...
:PROCegline(40,y%,280,y%,(y% DIV 8) MOD 4) :REM ...cycling colours 0-3
:NEXT :REM for a raster-stripe effect
:PROCegtext("BRICKFALL",120,48) :REM text must sit on 8-pixel boundaries
:PROCegline(64,80,256,80,3) :REM underline in colour 3
240 PROCegtext("PRESS SPACE",112,176)
:PROCegpresent :REM show it at vsync
250 REPEAT:UNTIL INKEY(0)=32:*FX 15
REM wait for SPACE in the keyboard buffer (positive INKEY), then *FX 15
REM empties the buffer so the key cannot leak into the game
260 ENDPROC
The title is a single frame: PROCegbegin clears the hidden page, nine lines cycle through the four colours for a raster-stripe effect, two strings go in as EGFX text (which must sit on 8-pixel boundaries: a misaligned call is refused, not drawn crooked) and PROCegpresent waits for vertical sync and shows the page. REPEAT:UNTIL INKEY(0)=32 waits for SPACE in the keyboard buffer, and *FX 15 empties the buffer so that keypress cannot leak into the game.
Where the PROCeg helpers come from
The lines you type end at 260, but the program on the disc also contains the EGFX helpers it calls. When the disc is built, basic-program.py follows every PROC and FN call into the helper library, appends only the ones that are reached, strips the REMs and checks the line numbers still go up. That happens on your PC, not on the BBC: stock BASIC IV has no INSTALL, and none is needed. If you are typing in, copy the helpers from the full listing below.
The whole of stage 1, ready to type in: the EGFX helpers merged and the notes stripped (31 BASIC lines)
5 MODE 1:HIMEM=&2400
20 PROCeginit
40 PROCstartscreen
210 MODE 7:END
220 DEF PROCstartscreen
230 PROCegbegin:FOR y%=24 TO 88 STEP 8:PROCegline(40,y%,280,y%,(y% DIV 8) MOD 4):NEXT:PROCegtext("BRICKFALL",120,48):PROCegline(64,80,256,80,3)
240 PROCegtext("PRESS SPACE",112,176):PROCegpresent
250 REPEAT:UNTIL INKEY(0)=32:*FX 15
260 ENDPROC
1000 DEF PROCeginit
1010 IF HIMEM>&2400 OR TOP>&2200 PRINT "EGFX MEM":END
1020 DIM egb% 63:LOCAL egi%
1025 FOR egi%=0 TO 63:egb%?egi%=0:NEXT
1040 egb%?0=64:egb%?1=8:egb%?2=69:egb%?3=71:egb%?4=1
1045 PROCegcall(0):ENDPROC
1050 DEF PROCegcall(egf%)
1070 egb%?5=egf%:egb%?7=0
1080 A%=&C0:X%=egb% MOD 256:Y%=egb% DIV 256:CALL &FFF1
1090 IF egb%?7<>&A5 PRINT "NO EGFX ROM":END
1095 IF egf%>=11 AND egf%<>22 AND egf%<>23 AND egb%?6<>0 PRINT "EG ERROR":END
1100 ENDPROC
1110 DEF PROCegxy(egx%,egy%)
1120 egb%?8=egx%:egb%?9=egx% DIV 256
1130 egb%?10=egy%:egb%?11=egy% DIV 256:ENDPROC
1140 DEF PROCegbegin:PROCegcall(1):ENDPROC
1150 DEF PROCegpresent:PROCegcall(6):ENDPROC
1180 DEF PROCegtext(egs$,egx%,egy%)
1190 PROCegxy(egx%,egy%):$(egb%+22)=egs$+CHR$0:PROCegcall(7):ENDPROC
1260 DEF PROCegline(egx%,egy%,egex%,egey%,egc%)
1270 PROCegxy(egx%,egy%):egb%?13=egc%:egb%?16=egex% AND 255:egb%?17=(egex% AND &FFFF) DIV 256
1280 egb%?20=egey% AND 255:egb%?21=(egey% AND &FFFF) DIV 256:PROCegcall(10):ENDPROCTry it: run it, press ESCAPE at the title, then type PRINT ~PAGE,~TOP,~HIMEM. Add a third PROCegtext line and watch TOP move.