Machine Code Programming

See all articles from Sinc-Link v2 n6
Author(s): Stan Piotrowski
Publication: Sinc-Link
Pub Details: Sinc-Link v2 n6 (Volume 2, Issue 6)
Date: November 1984
Pages: 10-11

The following is a list of the keyboard values when K-SCAN called in M/L (CALL 699 or in code: 205, 187, 2) which returns the value in the HL register. Note, these are all computed values so to find the value in ‘H’ & ‘L’ we must find it ourselves. e.g., the value returned to HL when the number ‘5’ is pressed (or left arrow) is 57335. Therefore, to find the value contained in ‘HL’,:

10 LET H = INT (57335/256)      :223
20 LET L = 57335 - (H * 256) :247
30 PRINT "H=";H, "L=";L
40 STOP

Therefore, if we were testing to see if the user was pressing the ‘5’ key (or left arrow), we would first CALL 699 then LD B,223 & LD C,247; LD A,H & CP B; LD A,L & CP C. If they matched, then continue on with the program.

Whenever you’re programming in machine code, do not forget that there are many routines in ROM that we can use (which will be discussed as we go along). Also, when reading articles about machine code, they sometimes have a useful routine which can be called. For example, in Toni Baker‘s book, “MASTERING MACHINE CODE ON YOUR ZX-81“, has many useful subroutines. We will be using some of them such as printing numbers to the screen for increasing/decreasing the scores; or on page 59 is a very useful routine for printing a complete picture or text to the screen in machine code.

TRIVIA:

250 baud means about 25 bytes per second; 1500 baud means about 150 bytes per second: for LOADing or SAVEing values which is why the ZX-81 takes so long to LOAD or SAVE!

Table of ‘Key Values’

Key       Hex. Value  Dec. Value  Key       Hex. Value  Dec. Value

1         FDF7        65015       EDIT      FCF7        64759
2         FBF7        64503       AND       FAF7        64247
3         F7F7        63479       THEN      F6F7        63223
4         EFF7        61431       TO        EEF7        61175
5         DFF7        57335       ←         DEF7        57079
6         DFEF        57327       ↓         DEEF        57071
7         EFEF        61423       ↑         EEEF        61167
8         F7EF        63471       →         F6EF        63215
9         FBEF        64495       GRAPHICS  FAEF        64239
0         FDEF        65007       RUBOUT    FCEF        64751
Q         FDFB        65019       ""        FCFB        64763
W         FBFB        64507       OR        FAFB        64251
E         F7FB        63438       STEP      F6FB        63227
R         EFFB        61435       <=        EEFB        61179
T         DFFB        57339       <>        DEFB        57083
Y         DFDF        57311       >=        DEDF        57055
U         EFDF        61407       S         EEDF        61151
I         F7DF        63455       (         F6DF        63199
O         FBDF        64479       )         FADF        64223
P         FDDF        64991       "         FCDF        64735
A         FDFD        65021       STOP      FCFD        64765
S         FBFD        64509       LPRINT    FAFD        64253
D         F7FD        63485       SLOW      F6FD        63229
F         EFFD        61437       FAST      EEFD        61181
G         DFFD        57341       LLIST     DEFD        57085
H         DFBF        57279       **        DEBF        57023
J         EFBF        61375       -         EEBF        61119
K         F7BF        63423       +         F6BF        63167
L         FBBF        64447       =         FABF        64191
NEWLINE   FDBF        64959       FUNCTION  FCBF        64959
Z         FBFE        64510       :         FAFE        64254
X         F7FE        63486       ;         F6FE        63230
C         EFFE        61438       ?         EEFE        61182
V         DFFE        57342       /         DEFE        57086
B         DF7F        57215       *         DE7F        56959
N         EF7F        61311       <         EE7F        61055
M         F77F        63359       >         F67F        63103
.         FB7F        64383       ,         FA7F        64127
SPACE     FD7F        64895       £         FC7F        64639
NO KEY    FFFF        65535