8K ROMCALLS

Why reinvent the wheel? Sinclair put useful machine code routines in its 8K ROM. Some of us use these routines to great advantage by CALLing them from machine code. You might like to know the ROM contains 295 unconditional and 27 conditional CALLs, what address calls them, and where they reside.

This program first scans the ROM up to 7679, building a stack of CALLED and CALLING addresses. Then it sorts and displays them. Since it does lots of work, the first two phases take about 20 minutes. The printing procedure follows.

You can see the calls in lines 120-140. All Z80 conditional calls use decimal codes of 196 or greater at intervals of 8. Line 140 checks for these, sending all other codes through. Since no call uses values below 196, line 120 shunts lower values around the loop. Code 205 means an unconditional call; line 130 sends this address directly to the call processing routine.

Calls for the Z80 processor:

Value   Call
 196    NZ,NN
 204    Z,NN
 205    NN
 212    NC,NN
 220    C,NN
 228    PO,NN
 236    PE,NN
 244    P,NN
 252    M,NN

Run the program once, SAVE it. Then GOTO 1000 to review the list (do not RUN). GOTO 2000 LPRINTs the entire list of 322 addresses.

   1 REM THIS PROGRAM LISTS ALL CALLS IN 8K 0F ROM.
2 REM BY MARTY IRONS, K2MI, 46 MAGIC CIRCLE DR., GOSHEN. NY 10924
3 REM 5 MAY 1982
4 REM THIS PROGRAM TAKES ABOUT 20 MINUTES TO SCAN THE ROMSORT AND START TO PRINT
5 REM "GOTO 1000" TO LIST ALL CALLS, AFTER RUNNING IT AND SAVING IT.
6 REM MODIFIED BY SYNTAX DEC 83
10 DIM C$(400,10)
20 LET MAX=0
30 FAST
100 FOR I=0 TO 7679
110 LET V=PEEK I
120 IF V<196 THEN GOTO 290
130 IF V=205 THEN GOTO 200
140 IF V-8*(INT (V/8))<>4 THEN GOTO 290
200 REM TEST CALLED ADDRESS
205 LET V=PEEK (I+1)+256*PEEK (I+2)
210 IF V>7679 THEN GOTO 290
215 REM THIS IS A CALL
220 LET MAX=MAX+1
230 LET V$=STR$ (V)+(STR$ (I+100000))(2 TO 6)
240 IF LEN V$>9 THEN GOTO 270
250 LET V$="0"+V$
260 GOTO 240
270 LET C$(MAX)=V$
280 LET I=I+2
290 NEXT I
300 PRINT "SORTING ";MAX;" ENTRIES"
302 PAUSE 100
304 CLS
310 FOR I=1 TO MAX-1
320 LET P=I
330 FOR J=I+1 TO MAX
340 IF C$(J)<C$(P) THEN LET P=J
350 NEXT J
360 LET Z$=C$(P)
370 LET C$(P)=C$(I)
380 LET C$(I)=Z$
390 NEXT I
400 PRINT "SORT COMPLETE"
410 PAUSE 100
420 CLS
430 GOTO 1000
500 PRINT "CALLED ROUTINES IN ROM"
510 PRINT
520 PRINT "CALLED ADDR","CALLING ADDR"
530 PRINT
540 RETURN
1000 GOSUB 500
1010 FOR I=1 TO MAX
1020 IF PEEK 16442>3 THEN GOTO 1070
1030 INPUT Z$
1040 CLS
1050 IF Z$<>"" THEN GOTO 9999
1060 GOSUB 500
1070 PRINT " ";C$(I,1 TO 5)," ";C$(I,6 TO 10)
1080 NEXT I
1200 PRINT
1210 PRINT " THERE ARE ";MAX;" CALLS"
1220 GOTO 9999
2000 REM IF YOU HAVE A PRINTER "GOTO 2000" TO PRINT ALL CALLS.
2010 LPRINT "CALLED ROUTINES IN ROM"
2020 LPRINT
2030 LPRINT "CALLED ADDR","CALLING ADDR"
2040 LPRINT
2050 FOR I=1 TO MAX
2060 LPRINT " ";C$(I,1 TO 5)," ";C$(I,6 TO 10)
2070 NEXT I
9999 STOP
SYNTACTIC SUM: 20578, 8K ROM

EXAMINE THE ROUTINES IN CONTEXT:

this program assumes every byte is instruction–not text or address. Our modifications to this program limit the addresses to those within the ROM and do not scan addresses above the last return in the ZX/TS or Spectrum ROMs. We also changed the formula for V$ to permit five-digit addresses.

SYNTAX translated this program with Firstloader (this issue) and found the following modifications needed:

LINE  CHANGE                    CAUSE
  10  DIM(800,10)               ROM SIZE
  30  Delete, was FAST          MACH SPEC
 100  ...TO 14446               ROM SIZE
 230  ...STR$(V)+               ROM SIZE
        (STR$(I+100000))(2TO6)
 240  ...>9...                  ROM SIZE
1020  ...23689...               MACH SPEC
1070  ...TO 5...6 TO 10         ROM SIZE
2060  ...TO 5...6 TO 10         ROM SIZE

Spectrum & 2068 use 23689 in 1020.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.