BBC Basic Program Examples
Hex dump
The Hex dump program below was originally published to the EPROM User group. It is of note as it provides a worked example of the in-line assembler abilities of the BBC Basic application.
Â
10 REM **********************************
20 REM Hexdump (C) Danny Langton *
30 REM Aware Technology, DECEMBER 1988 *
40 REM TO BE TREATED AS PUBLIC DOMAIN *
50 REM I.E. COPY AND USE BUT DON'T SELL *
60 REM **********************************
70 PROCassemble
80 REPEAT
90 CLS:REPEATINPUT''"Name of file to dump : "'"(Use [ESCAPE] to quit)"SPC10""D$:UNTILLEND$
100 X=OPENIN D$:IFX=0PRINT'"That file does not exist":GOTO90
110 PRINT"Use UP and DOWN cursor keys to move through file"'"a line at a time,"'"[SHIFT] and cursor keys for a page at a time"'"and [DEL] to quit":TIME=0:REPEATUNTILTIME>300
120 L%=0
130 CLS
140 REPEAT
150 PROCdump(L%)
160 CALL flush
170 G%=GET:IFG%=0 G%=GET
180 L%=L%+(G%=255)*16+(G%=251)*112-(G%=254)*16-(G%=250)*112
190 IF G%=246 L%=EXT#X-96-(EXT#X)MOD16
200 IF L%<0 OR L%>EXT#X OR G%=247L%=0
210 UNTILG%=127
220 UNTIL0
230 :
240 DEFPROCdump(L%)
250 CLS
260 PTR#X=L%
270 IFEXT#X-L%<112 F%=EXT#X-L% ELSE F%=112
280 R%=0:C%=0
290 PRINTTAB(0,0)STRING$(8-LENSTR$~L%,"0")STR$~L%
300 FOR M%=L% TO L%+F%-1
310 IFR%=7GOTO360
320 N%=BGET#X:N$=STR$~N%:IF LEN N$=1 N$="0"+N$
330 PRINTTAB(12+C%*3,R%)N$TAB(64+C%,R%);
340 IFN%>31 AND N%<127 PRINTCHR$N%; ELSE PRINT".";
350 C%=C%+1:IFC%=16 C%=0:R%=R%+1:IFR%<7PRINTTAB(0,R%)STRING$(8-LENSTR$~(L%+R%*16),"0")+STR$~(L%+R%*16)
360 NEXT
370 ENDPROC
380 :
390 DEFPROCassemble
400 DIMflush 50
410 FORpass=0TO2STEP2
420 P%=flush
430 [OPT pass
440 LD HL,0:ADD HL,SP:LD SP,(&1FFE):PUSH HL:CALL main:POP HL:LD SP,HL:RET
450 .main
460 RST &20
470 DEFB &33
480 RET
490 ]
500 NEXT
510 ENDPROC
520 :
Music Program for the Z88
Written by J. Mark Stevenson in 1989 - note the warnings in the REM statements.
Â
10 REM J.MARK STEVENSON 12 FEB 89
20 REM JUST TO PROVE THE Z88 CAN MAKE MUSIC!
30 REM YOU ARE INVITED TO EXPERIMENT WITH THIS PROGRAM
40 REM BUT BEWARE - THIS MAY CAUSE THE MACHINE TO HANG
50 DIM Z% 200
60 FOR Y% = 0 TO 2 STEP 2
70 P%=Z%
80 [ OPT Y%
90 .cnt DEFW 0 :DEFW 0
100 .del1 DEFW 0 :DEFW 0
110 .del2 DEFW 0 :DEFW 0
120 .flag DEFW 0
130 .code
140 LD HL,(cnt)
150 .cnt_loop
160 LD A,(flag) :OR A :CALL Z,inc :DEC A :CALL Z,dec
170 LD BC,(del1) :CALL del_loop
180 LD A,(&4B0) :PUSH AF :OR &40 :OUT (&B0),A
190 LD BC,(del2) :CALL del_loop
200 POP AF :OUT (&B0),A
210 DEC HL :LD A,H :OR L :JR NZ,cnt_loop
220 RET
230 \
240 .del_loop DEC BC :LD A,B :OR C :JR NZ,del_loop :RET
250 \
260 .inc
270 LD DE,(del1) :INC DE :INC DE :LD (del1),DE
280 LD DE,(del2) :INC DE :INC DE :LD (del2),DE
290 RET
300 \
310 .dec
320 LD DE,(del1) :DEC DE :DEC DE :LD (del1),DE
330 LD DE,(del2) :DEC DE :DEC DE :LD (del2),DE
340 RET
350 ]
360 NEXT
370 :
380 FOR T%=0 TO 2
390 ?flag=T%
400 FOR R%= 90 TO 41 STEP -3
410 !cnt=3000/R% :!del1=R%*4 :!del2=R%*4
420 Q%=USR(code)
430 NEXT
440 NEXT
Z88 Easter Eggs / ROM 2
There is a hidden message immediately before the internal ROM application front DOR in bank 7 at offset 3F57. Enter the command: .MV 3F57 07 in Gunther Strube's Intuition on the Assembler Workbench ROM.
Or use Thierry Peycru's Zmonitor on the Z88 Forever Compilation ROM. Or use ROMDMPx.BAS or similar program.
Or enter and run this BASIC / machine code program at your own risk. One small mistake in typing it in could corrupts memory in your Z88 and cause a FAIL or HARD RESET immediately or months later loosing all your files.
10 DIM code 29
20 DIM buff 104
30 P%=code
40 [
50 OPT 2
60 LD A,(&4D3)
70 PUSH AF
80 LD A,7
90 LD (&4D3),A
100 OUT (&D3),A
110 LD HL,&FF57
120 LD DE,buff
130 LD BC,104
140 LDIR
150 POP AF
160 LD (&4D3),A
170 OUT (&D3),A
180 RET
190 ]
200 CALL code
210 PRINT $buff
Yahtzee
The popular dice game.