Prev: 39224 Up: Map Next: 40140
39989: Update attributes at Magic Knight's predicted position
Used by the routine at 39224.
39989 PUSH IX Store IX
39991 PUSH BC Store BC
39992 PUSH DE Store DE
39993 LD A,(23331) Load Magic Knight's predicted x-coordinate into A
39996 RRCA Divide by eight, rounding down to nearest integer...
39997 RRCA ...
39998 RRCA ...
39999 AND 31 ...
40001 LD (23333),A ...and store at 23333
40004 LD A,(23331) Load three least significant bits of predicted x-coordinate into 23335...
40007 AND 7 ...
40009 LD (23335),A ...
40012 LD A,(23332) Load Magic Knight's predicted x-coordinate into A
40015 RRCA Divide by eight, rounding down to nearest integer...
40016 RRCA ...
40017 RRCA ...
40018 AND 31 ...
40020 LD (23334),A ...and store at 23333
40023 LD A,(23332) Load three least significant bits of predicted x-coordinate into 23336...
40026 AND 7 ...
40028 LD (23336),A ...
40031 LD A,(23334) Load predicted y-coordinate in characters into A
40034 ADD A,A Multiply by 8...
40035 ADD A,A ...
40036 ADD A,A ...
40037 LD H,0 Load into HL...
40039 LD L,A ...
40040 ADD HL,HL Multiply by 4 (i.e. 32 times original value)...
40041 ADD HL,HL ...
40042 LD A,(23333) Load predicted x-coordinate in characters into A
40045 LD D,0 Load into DE...
40047 LD E,A ...
40048 ADD HL,DE Add x-coordinate to 32 times y-coordinate (to get offset from, for example, start of attribute file)
40049 PUSH HL Store HL (x + 32 × y offset value)
40050 LD DE,22528 Point DE at start of attribute file
40053 ADD HL,DE Add HL to address of start of attribute file as offset
40054 PUSH HL Transfer updated display file address (predicted attribute display file address of Magic Knight) from HL to IX...
40055 POP IX ...
40057 POP HL Restore HL (x + 32 × y offset value)
40058 LD DE,24539 Point DE at start of terrain interaction data
40061 ADD HL,DE Add HL to DE as offset (in HL)
40062 LD B,0 Load BC with 30, as 30 characters have to be skipped when moving from right side of Magic Knight on one character row to left side on next row
40064 LD C,30
40066 LD A,(23335) Load pixel-within-character predicted x-coordinate of Magic Knight into A
40069 OR A If this is zero...
40070 JR Z,40074 ...then skip ahead to 40074...
40072 LD C,29 ...else load BC with 29, as Magic Knight is spans three characters rather than two
40074 LD DE,(23337) Load Magic Knight's attribute and update-attributes-at-Magic-Knight's-predicted-position flag into DE
40078 EXX Switch registers
40079 LD C,4 Load C with 4 (as Magic Knight is 4 characters tall)
40081 LD A,(23336) Load predicted pixel-within-character y-coordinate
40084 OR A If this is zero...
40085 JR Z,40089 ...then skip ahead to 40089...
40087 LD C,5 ...else add one, as Magic Knight is "between" characters, and therefore spans 5 characters tall
40089 LD B,2 Load B with 2 (as Magic Knight is 2 characters wide)
40091 LD A,(23335) Load predicted pixel-within-character x-coordinate
40094 OR A If this is zero...
40095 JR Z,40099 ...then skip ahead to 40099...
40097 LD B,3 ...else add one, as Magic Knight is "between" characters, and therefore spans 3 characters wide
40099 LD A,B Load number of characters spanned by Magic Knight into A...
40100 LD (40104),A ...and into instruction at 40103
The operand of the instruction at 40103 represents the number of characters spanned by Magic Knight horizontally. This is modified by the instruction at 40100.
40103 LD B,0 Load B with number of characters spanned by Magic Knight horizontally
40105 EXX Switch registers
40106 BIT 6,(HL) If bit 6 (i.e. preserve-attribute) is set in terrain interaction data for Magic Knight's predicted x- and y-coordinates...
40108 JP NZ,40120 ...then skip ahead to 40120
40111 LD A,(IX+0) Load attribute at Magic Knight's predicted x- and y-coordinates into A
40114 XOR E XOR with Magic Knight's current attribute
40115 AND D Reset INK and BRIGHT bits, preserving only PAPER and FLASH
40116 XOR E XOR with Magic Knight's current attribute (Magic Knight's INK and BRIGHT bits override whatever was there before)
40117 LD (IX+0),A Load processed attribute value at Magic Knight's predicted x- and y-coordinates back into display file
40120 INC HL Advance by one byte in terrain interaction data
40121 INC IX Advance by one byte in display file
40123 EXX Switch registers
40124 DJNZ 40105 Loop back to 40105 for next character in Magic Knight's spanned characters
40126 EXX Switch registers
40127 ADD HL,BC Advance pointer in terrain interaction data by 29/30 bytes (down to next row, depending on how many characters Magic Knight spans)
40128 ADD IX,BC Advance pointer in attribute file by 29/30 bytes (down to next row, depending on how many characters Magic Knight spans)
40130 EXX Switch registers
40131 DEC C Decrease number of characters spanned by Magic Knight vertically...
40132 JR NZ,40103 ...and if not zero (i.e. more to go) then loop back to 40103
40134 EXX Switch registers
40135 POP DE Restore DE
40136 POP BC Restore BC
40137 POP IX Restore IX
40139 RET Return
Prev: 39224 Up: Map Next: 40140