Routines |
Prev: F296 | Up: Map | Next: F34B |
|
||||
Clear/reset input area (clear by printing 5 spaces):
|
||||
F2F9 | LD BC,$0E13 | Line number (B) = 14 Column number (C) = 19 |
||
F2FC | CALL $0DD9 | Call ROM 'CL-SET' routine HL register pair returned with screen display position to print at (18510) |
||
F2FF | CALL $F268 | Print the following characters on screen. On RETurn from this CALL, continue from F308 | ||
Characters to print - spaces to clear input area:
|
||||
F302 | DEFM " " | 5 spaces | ||
F307 | DEFB $FF | End-of-data byte | ||
Prepare for player input:
|
||||
F308 | LD BC,$0E13 | Line number (B) = 14 Column number (C) = 19 |
||
F30B | CALL $0DD9 | Call ROM 'CL-SET' routine HL register pair returned with screen display position to print at |
||
F30E | LD B,$04 | 4 digits to enter | ||
F310 | LD HL,$0000 | HL not needed for print routine (uses RST 16 instruction and stack pointer to the following data) | ||
F313 | CALL $F268 | Print the (following) characters on screen | ||
Characters for flashing cursor:
|
||||
F316 | DEFM $12,$01," ",$12,$00,$08 | ASCII codes for: - FLASH 1 - " " (SPACE) - FLASH 0 - CURSOR LEFT |
||
F31C | DEFB $FF | End-of-data marker | ||
Check player input:
|
||||
F31D | BIT 5,(IY+$01) | FLAGS (system variable) - bit 5 is set if a key is pressed | ||
F321 | JR Z,$F31D | Keep checking until it's pressed | ||
F323 | RES 5,(IY+$01) | Key pressed - reset bit 5 of FLAGS system variable | ||
F327 | LD A,($5C08) | Get value of LAST-K (last pressed key) | ||
F32A | CP $0C | Has DELETE been pressed? | ||
F32C | JR Z,$F2F9 | If so, jump back and reset the player's input (clear the input area) | ||
Evaluate key pressed:
|
||||
F32E | LD C,A | Store key value in C register | ||
F32F | SUB $30 | Is code for key pressed <48 (number 0 = value of 48, the first valid character that can be typed) | ||
F331 | JR C,$F31D | If so, it's not valid - jump back until another key is pressed | ||
F333 | CP $0A | Is the code for the key press one of the numbers (0-9)? | ||
F335 | JR NC,$F31D | If not, it's not valid - jump back until another key is pressed | ||
A valid key between 0 and 9 has been pressed
|
||||
F337 | LD E,A | Store value of key pressed (0-9) in E register | ||
F338 | LD A,C | Retrieve key code value from C register | ||
F339 | RST $10 | Print the value on screen | ||
The value to check against is a 2 byte value stored at F1F8. Therefore we need to multiple each accumulated figure/digit by 16 before adding the next:
|
||||
F33A | ADD HL,HL | HL = HL x2 | ||
F33B | ADD HL,HL | x4 | ||
F33C | ADD HL,HL | x8 | ||
F33D | ADD HL,HL | x16 | ||
F33E | LD D,$00 | |||
F340 | ADD HL,DE | |||
F341 | DJNZ $F313 | Decrement the counter in the B register. Continue to check for input until all 4 digits have been entered | ||
We now have the code value in the HL register pair - check it against the correct code:
|
||||
F343 | LD DE,($F1F8) | Get the correct code value | ||
F347 | XOR A | Clear the carry flag | ||
F348 | SBC HL,DE | Subtract the correct code from the user-entered code | ||
F34A | RET | Return to F354 with zero flag result (Z = correct, NZ = incorrect) |
Prev: F296 | Up: Map | Next: F34B |