MACHINE CODE ROUTINE FOR AUGUST
‘HOW THE HELL?....’
ORG 0FC00H ;THIS MUST BE ON A PAGE BOUNDARY!
MATRIX: DEFB 10H,2EH,48H,2FH,$A0,30H
DEFB $F8,31H,10H,4EH
DEFB $C8,4FH,$A0,50H,28H,51H,60H,6EH,78H,6FH
DEFB 08H,70H,20H,71H,98H,8EH,08H,8FH,$B0,90H
DEFB 28H,91H,68H,$AE,28H,$AF,38H,$B0,08H,$B1
OFFTB: DEFB 17H,26H,2DH,3CH,46H,75H,80H,8EH,$FF
RLIST: DEFB 32H,36H,00H,02H,04H,06H,08H,0AH,0CH
DEFB 0EH,10H,12H,14H,16H,18H,1AH,1CH,1EH
DEFB 20H,22H,24H,26H,32H,34H
RL: DEFB 30H,30H
JPTAB: DEFW PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT
DEFW PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT,PRT
DEFW MVLT,MVRT,MVUP,MVDN,GOTO,KEYS,VECT,DEBN
JVAR: DEFB 0 ; Should be defW?
XPOS: DEFB 3
YPOS: DEFB 0
PNTR: DEFW MATRIX+6
SAVE: LD IX,4000H ;THIS IS THE SAVE ROUTINE
LD DE,1B00H ;IX=BASE ADDRESS, DE=LENGTH
LD A,$FF
SCF ;FINALLY JUMP TO THE SAVE ROUTINE IN THE
JP 04C2H ;ROM TO SAVE THE DATA IN HEADERLESS
;FORMAT
LOAD: EXX ;FIRST SAVE THE AUXILIARY HL REGISTERS
PUSH HL
LD HL,RLIST ;SET HL' TO POINT TO THE ROUTINE TABLE
EXX
CALL RELOC ;NOW RELOCATE THE ROM LOAD ROUTINE
LD IX,4000H ;LIKE THE SAVE ROUTINE ABOVE, IX=BASE
LD DE,1B00H ;AND DE=LENGTH FOR THE LOAD ROUTINE
LD A,0FFH
SCF ;NOW CALL OUR MODIFIED ROM LOAD ROUTINE
CALL LSTART ;WHICH HAS BEEN RELOCATED
EIRET: EI ;ENSURE INTERRUPTS ARE ON
EXX
POP HL ;RESTORE THE AUXILIARY HL' REGISTERS
EXX
RET ;BEFORE RETURNING
RELOC: LD HL,0556H ;THIS CODE SIMPLY MOVES THE ROM
LD DE,LSTART ;LOADING ROUTINE FROM 0556 TO THE
LD BC,0605H-0556H ;END OF THIS CODE AT THE LABEL
LDIR ;'LSTART'
LD HL,LSTART+150
LD DE,LSTART+148
LD BC,27
LDIR
LD HL,LSTART+145 ;A FEW MODIFICATIONS ARE NECESSARY
LD (HL),0CDH ;BECAUSE THERE ARE A FEW LINES OF
LD HL,GAME ;CODE IN THE LOADER THAT REFER TO
LD (LSTART+146),HL ;ABSOLUTE ADDRESSES WITH THE ROM
LD HL,EIRET ;SO THE CODE FROM RELOOP BELOW IS
LD (LSTART+9),HL ;DEDICATED TO RE-CALCULATING THE
LD BC,LSTART-0556H ;INSTRUCTIONS ONCE THE LOADER HAS
LD DE,OFFTB ;BEEN REPOSITIONED. NOTE HOW IT
RELOOP: LD A,(DE) ;USES THE OFFSET TABLE 'OFFTB'
INC DE ;A IS THE 8 BIT OFFSET
CP 0FFH ;FF IS THE STOP BYTE
RET Z ;IF EQUAL TO FF THEN RETURN
PUSH DE ;SAVE DE TEMPORARILY
ADD A,LSTART & 255 ;ADD IN THE OFFSET TO LSTART AND
LD L,A ;STORE RESULT IN HL
ADC A,LSTART/256
SUB L
LD H,A
LD E,(HL) ;MAKE DE=ABSOLUTE VALUE FROM THE
INC HL ;OLD INSTRUCTION FROM 0556+
LD D,(HL)
DEC HL
EX DE,HL
ADD HL,BC ;PUT DE INTO HL FOR THE ADDITION TO
EX DE,HL ;BC AND PUT THE NEWLY CALCULATED
LD (HL),E ;ABSOLUTE ADDRESS BACK
INC HL
LD (HL),D
POP DE ;RESTORE DE
JR RELOOP ;AND CONTINUE UNTIL COMPLETE
GAME: EXX ;THE SHUFFLE GAME IS COMPLETELY
LD B,MATRIX/256 ;WRITTEN USING THE EXCHANGE
LD A,(HL) ;REGISTERS
LD C,A ;A AND C BOTH = ROUTINE NUMBER*2
INC HL ;STEP ROUTINE POINTER ON FOR NEXT
PUSH HL ;VALUE AND SAVE IT FOR LATER
ADD A,JPTAB & 255 ;VECTOR IN TO THE JUMP TABLE FOR
LD L,A ;THE REQUIRED ROUTINE WITH THE
ADC A,JPTAB/256 ;ADDITION OF A AND HL
SUB L
LD H,A
LD A,(HL) ;USING THE ACCUMULATOR AND HL
INC HL ;WE NOW GET THE JUMP TABLE VALUE
LD H,(HL) ;FOR THE REQUIRED ROUTINE AND
LD L,A ;AFTER SETTING HL TO POINT TO IT,
JP (HL) ;WE JUMP TO THE ROUTINE
PRET: POP HL ;ALL BUT ONE ROUTINE JUMPS BACK
EXX ;HERE WHEN FINISHED
RET ;NOW RETURN TO THE LOADER 360ish T
;STATES LATER
VECT: LD HL,JVAR ;HL POINTS TO THE SHUFFLE DIRECTION
LD A,4 ;NUMBER
SUB (HL) ;USING THE ACCUMULATOR, WE NOW DO A
ADD A,A ;SIMPLE CALCULATION TO ARRIVE AT A
ADD A,28H ;ROUTINE NUMBER AND 'POKE' IT INTO
LD (RL),A ;THE ROUTINE LIST AT 'RL'
LD B,13 ;NOW WE SIT AROUND FOR A WHILE
VE10: DJNZ VE10 ;TO TOT UP OUR 358 OR SO T STATES
JP PRET ;AND FINALLY RETURN
MVLT: LD A,(XPOS) ;AFTER PRESSING 'O', WE ENTER HERE
CP 3 ;FROM THE JP(HL) IN GAME, WE CHECK
JR Z,MV20 ;TO SEE IF WE CAN MOVE A LETTER TO
INC A ;THE LEFT AND IF NOT, WE JUMP TO
LD (XPOS),A ;MV20 OR ELSE WE UPDATE THE XPOS
LD A,2 ;VARIABLE AND JUMP TO MV10
JR MV10
MVRT: LD A,(XPOS) ;THIS IS AN IDENTICAL PIECE OF CODE
CP 0 ;AS FOR 'MVLT' EXCEPT IT ACTS UPON
JR Z,MV20 ;THE PRESSING OF THE 'p' KEY AND IS
DEC A ;FOR TESTING WHETHER WE CAN MOVE A
LD (XPOS),A ;A LETTER TO THE RIGHT.
LD A,-2
JR MV10
MVUP: LD A,(YPOS) ;TEST FOR MOVING A LETTER UP WITH
CP 4 ;THE 'q' KEY
JR Z,MV20
INC A
LD (YPOS),A
LD A,8
JR MV10
MVDN: LD A,(YPOS) ;TEST FOR MOVING LETTER DOWN WITH
CP 0 ;THE 'a' KEY.
JR Z,MV20
DEC A
LD (YPOS),A
LD A,-8
JR MV10
MV10: LD HL,(PNTR) ;IF A LETTER WAS ABLE TO BE MOVED,
LD D,H ;WE COME IN HERE WITH ACCUMULATOR
LD E,L ;HOLDING AN OFFSET NUMBER TO ADD TO
ADD A,L ;THE VARIABLE (PNTR) TO UPDATE IT
LD L,A ;TO POINT TO THE BLANK SPACE
LD (PNTR),HL
LD A,(HL)
LD (DE),A
LD (HL),0F8H ;STORE AN UNDERLINE CHARACTER IN
LD B,2 ;THE BLANK SPACE AND PRESET 'B' FOR
JR MV30 ;THE DELAY ROUTINE AT MV30
MV20: LD B,12
MV30: DJNZ MV30 ;WAIT 'B'*13-5 T STATES
JP PRET ;RETURN
KEYS: LD A,0FDH ;FIRST WE TEST THE 'a' KEY FOR THE
IN A,(0FEH) ;MOVE LETTER DOWN ROUTINE
AND 1
JR NZ,KY10 ;JUMP IF NOT PRESSED
LD A,1 ;THE DOWN ROUTINE IS NUMBER 1
LD B,12 ;B IS A DELAY
JR KY50
KY10: LD A,0FBH ;NOW TEST THE 'q' KEY FOR THE MOVE
IN A,(0FEH) ;LETTER UP ROUTINE
AND 1
JR NZ,KY20 ;JUMP IF NOT PRESSED
LD A,2 ;THE UP ROUTINE IS NUMBER 2
LD B,9 ;B IS A DELAY
JR KY50
KY20: LD A,0DFH ;NOW TEST THE 'p' KEY FOR THE MOVE
IN A,(0FEH) ;LETTER RIGHT ROUTINE
LD C,A ;SAVE BIT 1 IN C
AND 1
JR NZ,KY30 ;JUMP IF NOT PRESSED
LD A,3 ;THE RIGHT ROUTINE IS NUMBER 3
LD B,7 ;B IS A DELAY
JR KY50
KY30: LD A,C ;FINALLY TEST THE 'o' KEY FOR THE
AND 2 ;MOVE LETTER LEFT ROUTINE
JR NZ,KY40 ;JUMP IF NO KEYS PRESSED
LD A,4 ;THE LEFT ROUTINE IS NUMBER 4
LD B,4 ;B IS A DELAY
JR KY50
KY40: XOR A ;IF NO KEYS WERE PRESSED, MAKE 'A'
LD B,5 ;EQUAL TO ZERO
KY50: DJNZ KY50 ;WAIT FOR THE RELEVANT DELAY
LD (JVAR),A ;STORE THE ROUTINE NUMBER IN JVAR
JP PRET ;RETURN
;THIS ROUTINE PRINTS ONE CHARACTER
PRT: LD A,(BC) ;FETCH THE CHARACTER CODE*8 FROM
INC BC ;MATRIX AND PUT IT INTO 'L'
LD L,A
LD A,(BC) ;NOW FETCH THE SCREEN ADDRESS LOW
LD E,A ;BYTE FROM MATRIX AND PUT IT INTO
LD H,3EH ;'E'. SET UP 'H' AND 'D' WITH THEIR
LD D,48H ;RELEVANT HIGH BYTE VALUES
DEFB 7EH,12H,2CH,14H ;THESE BYTES ARE REPEATED INSTRUCTIONS
DEFB 7EH,12H,2CH,14H ;OF THE FORM
DEFB 7EH,12H,2CH,14H ;LD A,(HL)
DEFB 7EH,12H,2CH,14H ;LD (DE),A
DEFB 7EH,12H,2CH,14H ;INC L
DEFB 7EH,12H,2CH,14H ;INC D
DEFB 7EH,12H,2CH,14H ;FOR SPEED, THE INSTRUCTIONS ARE
DEFB 7EH,12H ;REPEATED 8 TIMES
JP PRET ;RETURN
;DEBOUNCE THE KEY PRESSES
DEBN: LD A,(JVAR) ;IF A KEY WAS PRESSED ON THE LAST
LD B,14 ;LOOP, (JVAR) WILL BE NON-ZERO
AND A ;IF NON-ZERO, JUMP TO GO10 TO RESET
JR NZ,GO10 ;THE ROUTINE POINTER TO 'RLIST'
LD B,14 ;IF NOT, JUST SIT AROUND AND WAIT
DE10: DJNZ DE10 ;FOR A BIT BEFORE
JP PRET ;RETURNING
GOTO: LD B,16 ;THIS ROUTINE RE-SETS THE ROUTINE
GO10: POP HL ;POINTER HL' TO 'RLIST' PRIOR TO
GO20: DJNZ GO20 ;DELAYING FOR A BIT
LD HL,RLIST
EXX ;FLIP REGISTERS BACK AND RETURN
RET ;DIRECTLY TO THE LOADER AT
;LSTART+148
LSTART: ;THIS IS WHERE THE LOADER IS MOVED
;TO
|