Prev: 45965 Up: Map Next: 46170
45999: Advance graphic layout data pointer by two bytes, and process data
Used by the routines at 46427, 46442 and 46460.
Input
IX Address of graphic layout data to draw
B 0 if current position in display buffer needs to be recalculated. 1 otherwise.
45999 INC IX Advance IX by one byte
This entry point is used by the routines at 46284, 46295 and 46306.
46001 INC IX Advance IX by one byte
This entry point is used by the routines at 45965, 46317, 46347, 46363, 46460, 46481, 46495, 46611, 46628, 46647 and 46664.
46003 LD A,(IX+0) If first byte of graphic layout data entry is at least 236, i.e. IX points to an instruction, then jump to appropriate graphic layout routine
46006 CP 236
46008 JP NC,46218
At this point, the graphic layout data pointed to by IX is graphical data, not an instruction. We only draw the graphics if they lie within the display area (i.e. have x- and y-coordinates less than 32 and 24 respectively, see trivia).
46011 LD A,H If x-coordinate is greater than 31 or y-coordinate is greater than 23 then skip ahead to 46151
46012 CP 32
46014 JP NC,46151
46017 LD A,L
46018 CP 24
46020 JP NC,46151
46023 PUSH HL Store HL (H = x-coordinate, L = y-coordinate)
46024 DEC B Decrease value of do-not-recalculate-display-buffer-address flag
46025 JP Z,46051 If we don't need to recalculate current position in display buffer then skip ahead to 46051
If B was 1, then we need to load DE with the address of the current position in the primary display buffer.
46028 LD A,H Load BC with three times x-coordinate and DE with double y-coordinate
46029 ADD A,A
46030 ADD A,H
46031 LD C,A
46032 LD A,L
46033 ADD A,A
46034 LD E,A
46035 LD D,0
46037 LD B,D
46038 LD HL,46170 Load DE with multiple of 96 corresponding to y-coordinate
46041 ADD HL,DE
46042 LD E,(HL)
46043 INC HL
46044 LD D,(HL)
The operand of the instruction at 46045 represents the address of the primary display buffer. This is modified by the instruction at 45902.
46045 LD HL,0 Load DE with address in primary display buffer corresponding to x- and y-coordinates
46048 ADD HL,DE
46049 ADD HL,BC
46050 EX DE,HL
46051 LD A,(DE) Load A with graphic set index plus one from this entry in primary display buffer and if value is now zero (i.e. old value was 255 corresponding to a block outside dimensions of room) then skip ahead to 46150
46052 INC A
46053 JP Z,46150
46056 LD A,(34268) Load current graphic set index into this location in primary display buffer
46059 LD (DE),A
46060 INC DE Advance to graphic index in current character block's entry in primary display buffer
46061 LD A,(IX+0) Load graphic index into current display buffer location
46064 LD (DE),A
46065 INC DE Advance to next byte in current character block's display buffer entry (attribute)
46066 LD A,(34270) Load A with current attribute and if this is not zero then skip ahead to 46077
46069 OR A
46070 JR NZ,46077
Current attribute is zero (i.e. not set) so graphic layout data contains attribute information
46072 INC IX Advance IX to next byte in graphic layout data (attribute) and load into A
46074 LD A,(IX+0)
At this point, A holds an attribute value either from the graphic layout data, or the current attribute as stored at 34270. This attribute is to be applied to the current display buffer location.
IX (current position in graphic layout data) is pointing to either the graphic index (if the current attribute at 34270 is set) or the attribute data (if the current attribute is not set). In either case, IX+1 is the address of the cursor shift byte. Bit 7 of the cursor shift byte is the override-attribute flag.
46077 BIT 7,(IX+1) If bit 7 (override-attribute flag) is set then skip ahead to 46111
46081 JP NZ,46111
Override-attribute flag reset
46084 LD L,A If PAPER is not zero (black) then skip ahead to 46111
46085 AND 56
46087 LD A,L
46088 JP NZ,46111
The instructions between 46091 and 46110 (inclusive) are executed only when the PAPER component of the attribute in A (and L) is black. If the preserve-INK flag is reset in the attribute value loaded (at 46098) from the display buffer, then the instruction at 46107 will leave the reset (i.e. black) PAPER bits in A. If the preserve-INK flag is set, then the instructions between 46104 and 46106 (inclusive) will shift the bits used for INK into the PAPER positions and this PAPER colour (originally INK colour) will be preserved when the instruction at 46107 is executed.
46091 AND 192 Load B with preserve-INK and mirror flags
46093 LD B,A
46094 LD A,L
46095 AND 63 Reset preserve-INK and mirror flags
46097 LD C,A Load C with INK and PAPER bits
46098 LD A,(DE) Load value currently in display buffer into A and if preserve-INK flag is reset then skip ahead to 46107
46099 BIT 6,A
46101 JP Z,46107
Preserve INK flag set in display buffer
46104 ADD A,A Shift INK bits into PAPER bits
46105 ADD A,A
46106 ADD A,A
46107 AND 56 Reset all except PAPER bits
46109 OR B (Re)set preserve-INK and mirror flags as stored in B previously
46110 OR C Set INK bits as stored in C previously (PAPER was black)
46111 LD (DE),A Load attribute in A into display buffer
46112 POP HL Restore HL (H = x-coordinate, L = y-coordinate)
Read cursor shift byte. The value n, encoded in bits 0-6 of this byte, control where the cursor to write to the primary display buffer is moved to after writing the current character block.
If n is less than 33 then we move the cursor down a character row, and left by (32-n) characters.
If n is 33 or greater then we move the cursor right by (n-32) characters.
Bit 7 is the override-attribute flag.
46113 LD A,(IX+1) Load A with cursor shift byte and if this is 255 (end marker) then jump to 46418 (load HL with stored coordinates from 34281 and return from drawing)
46116 CP 255
46118 JP Z,46418
46121 AND 127 Reset bit 7 (override-attribute flag)
46123 SUB 33 Subtract 33, and if remaining value is 0 (i.e. original value was 33) then skip ahead to 46140, else if value was greater than 33 then skip ahead to 46132
46125 JP Z,46140
46128 JP NC,46132
Cursor shift byte was less than 33 (move the cursor down a character row, and left by (32-n) characters)
46131 INC L Increase y-coordinate
46132 INC A Increase A (x-coordinate offset) and add to x-coordinate
46133 ADD A,H
46134 LD H,A
46135 LD B,0 Prepare to recalculate display buffer address as change in coordinates is non-trivial
46137 JP 45999 Advance graphic layout data pointer by two bytes and read / process next data
Cursor shift byte was 33 (move the cursor right by one character)
46140 INC DE Advance pointer to start of next entry in primary display buffer
46141 INC H Increase x-coordinate by one
46142 JP Z,46135 If x-coordinate is zero then jump back to 46135 (see trivia)
46145 LD B,1 Prepare to skip over recalculation of display buffer address as we moved right one character
46147 JP 45999 Advance graphic layout data pointer by two bytes and read / process next data
First byte in primary display buffer entry for current position is 255 (i.e. outside dimensions of room)
46150 POP HL Restore HL (H = x-coordinate to draw to, L = y-coordinate to draw to)
46151 LD A,(34270) Load A with current attribute and if not zero then skip ahead to 46160
46154 OR A
46155 JP NZ,46160
46158 INC IX Advance IX to next byte in graphic layout data (attribute)
46160 LD A,(IX+1) Load A with cursor shift byte, reset bit 7 (override-attribute flag), subtract 33 and jump back to 46128 to update current drawing position
46163 AND 127
46165 SUB 33
46167 JP 46128
Prev: 45965 Up: Map Next: 46170