Poke: Small Change for Machine Language Pokers

Author(s): Joseph Hartmann
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n12 (Volume 3, Issue 12)
Date: December 1982
Pages: 6-7

We wrote up this small “monitor” during the debug phase of a more comprehensive PEEK and POKE utility. It is not small enough for the 2K machine–but I trust everyone is aware by now that few things are.

Load it into a 16K ZX/TS and you will be surprised how useful it is in your machine code experimentation. It’s shortness is especially valuable if your code insists on bombing out, forcing you to repeatedly reload until you find the bug.

Turn on your ZX/TS and type: POKE 16389,112 ENTER. This will isolate the upper 4K of RAM starting from 28672 to the upper limit of 32767. Next, type: NEW followed by ENTER–this actually restructures BASIC’s workspace so BASIC will ignore 28672 to 32767 unless you tell it to jump there by invoking the USR function.

After you type in the code and debug your typos, type: RUN ENTER –POKE will start running by printing: (28758)=0 and you will get the “L” prompt at the bottom of the screen. POKE is now waiting for your input. Follow all input with ENTER. When you finish your code, remember to insert a return command, decimal 201.

Menu for POKE:

An...n   Examine memory with new
         Address (O-65535)

STOP     Return to BASIC

n...n    Deposit value in current
         memory location
         (0 to 255)

R        Execute your machine
         code starting at memory
         address 28758

ENTER    Examine next memory
         location, do not deposit
         anything in current
         memory location.

Note: n is a digit from 0 to 9.

Comments on the Program:

4      Reason for choosing this
       number is tied up with
       the more comprehensive
       utility--you could pick
       up any location in the
       protected area from 28672
       to 32767

50     When we say STOP we mean
       shift A

40     If your input starts with
       an A you GOTO 100

100    Interpret the string you
       inputed with a leading A
       to be the numerical
       string without the A

1100   This is where we leave
       BASIC and start executing
       your code which you
       POKE'd in starting at
       28758.

General Comments:

Read chapters 25 and 26 in the Timex Manual and note that before you return to BASIC the IY register must contain 30. (All numbers we discuss are DECIMAL.) The manual doesn’t tell you that the INT line of the processor is being used–so don’t enable the interrupt function (EI) because you will not be able to return to your machine code.

When you return from your machine code BASIC will interpret the value it finds in the BC register as a parameter you have passed to it. For example if you load the BC register with the value 1024 then you will print 1024 on the video screen–refer to line 1100 which establishes the BASIC variable B as containing the value you passed to BASIC in the BC register.

Here is a simple machine code demonstration program:

Address  Byte 1  2  3  Mnemonic

 28758        1  0  4  LD BC, 1024
 28761      201        RET

Deposit the preceding code in memory locations indicated and you will see the execution of your own machine code with parameter passed back to BASIC.

To enter more than one screenful of bytes add lines 6 SCROLL, 1103 SCROLL, and 1107 SCROLL.

   4 LET A=28758
5 PRINT
10 PRINT "(";A;")=";PEEK A;
30 INPUT A$
40 IF CODE A$=CODE "A" THEN GOTO 100
50 IF CODE A$=CODE " STOP " THEN STOP
60 IF A$="" THEN GOTO 78
62 IF CODE A$=CODE "R" THEN GOTO 1100
70 POKE A,VAL A$
75 PRINT TAB 14;VAL A$;
78 LET A=A+1
80 GOTO 5
100 LET A=VAL A$(2 TO )
105 PRINT
110 GOTO 5
1100 LET B=USR 28758
1102 PRINT
1105 PRINT B
1110 GOTO 5
SYNTACTIC SUM: 19030, 8K ROM