Prev: 8DDD Up: Map Next: 8E0F
8DE3: Print Handler
The default print handler for the state machine pointer at PrintState_Handler. Called on initialisation, and restored after each byte is consumed. Dispatches each byte of a messaging string to the appropriate action based on its value:
Byte Action
20–7F Print the ASCII character.
80–FF Replace with 21 ("!") and print.
0D Carriage return: reset X to left margin, advance Y by one line.
10–1A Control code: install a parameter handler into PrintState_Handler.
All others Replace with 3F ("?") and print.
Input
A Byte to print or control code
PrintHandler 8DE3 CP $80 If the byte is less than 80 jump to PrintHandler_Dispatch.
8DE5 JR C,PrintHandler_Dispatch
8DE7 LD A,$21 Otherwise replace the byte with 21 ("!").
8DE9 JP PrintHandler_Render Jump to PrintHandler_Render to render the character.
Dispatch handler for printing.
PrintHandler_Dispatch 8DEC CP $20 If the byte is 20 or higher (printable ASCII), jump to PrintHandler_Render to render it.
8DEE JP NC,PrintHandler_Render
8DF1 CP $0D If the byte is a carriage return (0D), jump to PrintHandler_Newline.
8DF3 JR Z,PrintHandler_Newline
8DF5 CP $10 If the byte is less than 10 jump to PrintHandler_Invalid (unsupported code).
8DF7 JR C,PrintHandler_Invalid
8DF9 CP $1B If the byte is 1B or higher, jump to PrintHandler_Invalid (unsupported code).
8DFB JR NC,PrintHandler_Invalid
Look up the two-byte handler address from the control code dispatch table at ControlCode_DispatchTable. The code is zero-indexed from 10 and doubled since each table entry is two bytes wide.
8DFD LD HL,$8FD0 HL=ControlCode_DispatchTable (base of the control code dispatch table).
8E00 SUB $10 Zero-index the control code from 10.
8E02 LD D,$00 DE=zero-indexed control code.
8E04 LD E,A
8E05 ADD HL,DE Double the index (two bytes per table entry).
8E06 ADD HL,DE
8E07 LD E,(HL) Read the handler address from the dispatch table into DE.
8E08 INC HL
8E09 LD D,(HL)
8E0A LD ($800A),DE Write the handler address to PrintState_Handler.
8E0E RET Return.
Prev: 8DDD Up: Map Next: 8E0F