Routines |
Prev: 54065 | Up: Map | Next: 54342 |
Used by the routine at 54065.
|
||||||||||||||||||||||
Set Maroc's facing direction depending on keys pressed, and set his height (above his shadow) based on his speed
Prepare Maroc's sprite - direction, height and movement
Set attributes and reset movement if needed
|
||||||||||||||||||||||
54120 | CALL 57888 | Set attribute colours for Maroc | ||||||||||||||||||||
54123 | LD A,(60074) | Get generic game counter/timer | ||||||||||||||||||||
54126 | INC A | Increment | ||||||||||||||||||||
54127 | LD (60074),A | ...and re-store | ||||||||||||||||||||
54130 | AND 2 | Check bit 1 - this will be set every other frame | ||||||||||||||||||||
54132 | JR Z,54142 | |||||||||||||||||||||
54134 | LD A,0 | |||||||||||||||||||||
54136 | LD (60075),A | If not set (i.e. every other game frame), set vertical & horizontal movement velocity to 0 | ||||||||||||||||||||
54139 | LD (60076),A | By only resetting it every other frame, this has the effect of continuing Maroc's forward movement very briefly when he enters a new room (through a door), before stopping | ||||||||||||||||||||
Identify Maroc's current X/Y pixel co-ordinates (including offsets):
|
||||||||||||||||||||||
54142 | LD A,0 | High overflow/precision byte for graphic horizontal screen position - reset just in case | ||||||||||||||||||||
54144 | LD (60116),A | |||||||||||||||||||||
54147 | LD HL,(60098) | Get Maroc's sprite frame graphic address pointer (table at 38851) | ||||||||||||||||||||
54150 | LD (60109),HL | Copy to graphics address buffer | ||||||||||||||||||||
54153 | LD A,(60096) | Maroc's horizontal (X-axis) screen position (4-pixel/half-character steps) | ||||||||||||||||||||
54156 | RLA | x 2 | ||||||||||||||||||||
54157 | RLA | x 4 - screen position is now in pixels | ||||||||||||||||||||
54158 | AND 252 | Filter out any unwanted bits 0 & 1 caused by the RLA | ||||||||||||||||||||
54160 | LD (60115),A | Store horizontal pixel position in graphics data buffer | ||||||||||||||||||||
54163 | LD A,(60577) | Maroc's height offset as he moves (above his shadow) in pixels | ||||||||||||||||||||
54166 | LD D,A | |||||||||||||||||||||
54167 | LD A,(60097) | Maroc's vertical (Y-axis) screen position | ||||||||||||||||||||
54170 | LD (60114),A | Copy to graphics buffer | ||||||||||||||||||||
54173 | SUB D | Subtract Maroc's height offset (changes depending on how fast he's moving) | ||||||||||||||||||||
54174 | LD D,A | Store back in D register | ||||||||||||||||||||
Convert Maroc's horizontal and vertical speeds to positive numbers if needed:
|
||||||||||||||||||||||
54175 | LD A,(60164) | Maroc's horizontal movement speed/rate | ||||||||||||||||||||
54178 | CP 128 | If bit 7 is set, Maroc's moving right | ||||||||||||||||||||
54180 | JR C,54184 | ...So if there's a carry, it means bit 7 isn't set (Maroc's moving left) | ||||||||||||||||||||
54182 | NEG | If Maroc's moving right, change his speed to a positive value (i.e. reset bit 7) ready for the next calculations | ||||||||||||||||||||
54184 | LD C,A | Store horizontal speed in C register | ||||||||||||||||||||
54185 | LD A,(60165) | Maroc's vartical movement speed/rate | ||||||||||||||||||||
54188 | CP 128 | If bit 7 is set, Maroc's moving down | ||||||||||||||||||||
54190 | JR C,54194 | ...So if there's a carry, it means bit 7 isn't set (Maroc's moving up) | ||||||||||||||||||||
54192 | NEG | If Maroc's moving up, change his speed to a positive value (i.e. reset bit 7) ready for the next calculations | ||||||||||||||||||||
Get Maroc's speed, and adjust his height above his shadow (pixel offset) accordingly.
First, get the greater of either his horizontal or vertical speed:
|
||||||||||||||||||||||
54194 | CP C | Check vertical speed (A register) vs horizontal speed (C register) | ||||||||||||||||||||
54195 | JR NC,54198 | If no carry, vertical speed >= horizontal speed | ||||||||||||||||||||
54197 | LD A,C | Otherwise, pick horizontal speed | ||||||||||||||||||||
Calculate Maroc's new height pixel offset based on his current speed:
|
||||||||||||||||||||||
54198 | RRA | |||||||||||||||||||||
54199 | RRA | Divide by 4. e.g. if Maroc is at 32 (max speed) the offset will be 8 | ||||||||||||||||||||
54200 | AND 31 | ...and filter out any unwanted bits (bits 5-7) | ||||||||||||||||||||
54202 | LD C,A | |||||||||||||||||||||
54203 | LD A,7 | 7 (pixels) is the base value (if Maroc isn't moving) | ||||||||||||||||||||
54205 | SUB C | Subtract the offset (offset is now between -1 and +7 pixels) | ||||||||||||||||||||
54206 | LD (60577),A | ...and store the new offset. | ||||||||||||||||||||
54209 | ADD A,D | Add the new offset to Maroc's vertical (Y-axis) pixel position | ||||||||||||||||||||
54210 | LD (60097),A | ...and store. | ||||||||||||||||||||
Identify Maroc's left/right movement
|
||||||||||||||||||||||
54213 | LD A,(60157) | Get left/right direction key press flag | ||||||||||||||||||||
54216 | CP 0 | If it's 0, neither right/left is being pressed | ||||||||||||||||||||
54218 | JR Z,54247 | |||||||||||||||||||||
54220 | CP 128 | Left or right direction controls are being pressed so check bit 7 to determine which one. | ||||||||||||||||||||
54222 | JR C,54266 | Carry = right control key used | ||||||||||||||||||||
54224 | LD A,(60158) | No carry = left control key used. Get up/down direction key press flag | ||||||||||||||||||||
54227 | CP 0 | If it's 0, neither up/down is being pressed | ||||||||||||||||||||
54229 | JR Z,54239 | |||||||||||||||||||||
54231 | CP 128 | Up or down direction controls are being pressed so check bit 7 to determine which one. | ||||||||||||||||||||
54233 | JR C,54243 | Carry = up control key used | ||||||||||||||||||||
LEFT and DOWN controls pressed
|
||||||||||||||||||||||
54235 | LD A,32 | |||||||||||||||||||||
54237 | JR 54287 | |||||||||||||||||||||
LEFT control pressed, no up/down controls pressed.
|
||||||||||||||||||||||
54239 | LD A,64 | |||||||||||||||||||||
54241 | JR 54287 | |||||||||||||||||||||
LEFT and UP controls pressed
|
||||||||||||||||||||||
54243 | LD A,96 | |||||||||||||||||||||
54245 | JR 54287 | |||||||||||||||||||||
Neither left or right controls pressed. Check up/down controls.
|
||||||||||||||||||||||
54247 | LD A,(60158) | Get up/down direction key press flag | ||||||||||||||||||||
54250 | CP 0 | If it's 0, neither up/down (or left/right) is being pressed - skip out of routine | ||||||||||||||||||||
54252 | JR Z,54310 | |||||||||||||||||||||
54254 | CP 128 | Up or down direction controls are being pressed so check bit 7 to determine which one | ||||||||||||||||||||
54256 | JR NC,54262 | No carry = down control key used | ||||||||||||||||||||
UP control pressed, no left/right controls pressed
|
||||||||||||||||||||||
54258 | LD A,128 | |||||||||||||||||||||
54260 | JR 54287 | |||||||||||||||||||||
DOWN control pressed, no left/right controls pressed
|
||||||||||||||||||||||
54262 | LD A,0 | |||||||||||||||||||||
54264 | JR 54287 | |||||||||||||||||||||
Right control pressed - check up/down options
|
||||||||||||||||||||||
54266 | LD A,(60158) | Right control pressed. Get up/down direction key press flag | ||||||||||||||||||||
54269 | CP 0 | If it's 0, neither up/down is being pressed | ||||||||||||||||||||
54271 | JR Z,54281 | |||||||||||||||||||||
54273 | CP 128 | Up or down direction controls are being pressed so check bit 7 to determine which one | ||||||||||||||||||||
54275 | JR C,54285 | Carry = up control key used | ||||||||||||||||||||
RIGHT and DOWN controls pressed
|
||||||||||||||||||||||
54277 | LD A,224 | |||||||||||||||||||||
54279 | JR 54287 | |||||||||||||||||||||
RIGHT control pressed, no up/down controls pressed
|
||||||||||||||||||||||
54281 | LD A,192 | |||||||||||||||||||||
54283 | JR 54287 | |||||||||||||||||||||
RIGHT and UP controls pressed
|
||||||||||||||||||||||
54285 | LD A,160 | |||||||||||||||||||||
Determine Maroc's direction - part 2
Control key presses have now been evaluated, and the A register contains a value based on these.
Each additional 32 increment indicates a clockwise rotation of the sprite. As Maroc moves, he smoothly rotates towards the new position using these increments, rather than the sprite suddenly switching to a new direction.
|
||||||||||||||||||||||
54287 | LD B,A | Store above value in B register | ||||||||||||||||||||
54288 | LD A,(60163) | Get Maroc's current facing direction | ||||||||||||||||||||
54291 | LD C,A | Store in C register | ||||||||||||||||||||
54292 | LD A,B | Get the new direction based on the previously evaluated keys pressed | ||||||||||||||||||||
54293 | SUB C | ...and subtract the existing direction | ||||||||||||||||||||
54294 | JR Z,54310 | If the result is 0, Maroc is already facing in the right direction - nothing to change | ||||||||||||||||||||
54296 | CP 128 | Check bit 7 to see if the result is positive or negative, i.e. whether Maroc needs to rotate clockwise or anti-clockwise. | ||||||||||||||||||||
54298 | JR NC,54304 | |||||||||||||||||||||
54300 | LD A,32 | If it's positive, set the increment amount to 32 - Maroc is rotating CLOCKWISE | ||||||||||||||||||||
54302 | JR 54306 | |||||||||||||||||||||
54304 | LD A,224 | If it's negative, set the increment amount to -32 - Maroc is rotating ANTI-CLOCKWISE | ||||||||||||||||||||
54306 | ADD A,C | Add this offset to the existing position | ||||||||||||||||||||
54307 | LD (60163),A | ...and store. | ||||||||||||||||||||
Get the graphic address offset corresponding to this new rotational position.
|
||||||||||||||||||||||
54310 | LD A,(60163) | Get Maroc's new rotational position (see values in table at 54287) | ||||||||||||||||||||
54313 | RRA | Divide by 16 | ||||||||||||||||||||
54314 | RRA | |||||||||||||||||||||
54315 | RRA | |||||||||||||||||||||
54316 | RRA | |||||||||||||||||||||
54317 | AND 14 | Filter out any other bits set by the RRA instructions | ||||||||||||||||||||
The A register value is now even and in the range of 0-14. This is the address pointer offset for Maroc's sprite frame (starting at 38851).
|
||||||||||||||||||||||
54319 | LD E,A | Store in E register | ||||||||||||||||||||
54320 | LD C,0 | Reset C register (will act as a flag to indicate if anything has changed with Maroc's sprite) | ||||||||||||||||||||
54322 | LD A,(60575) | Get the current address pointer offset | ||||||||||||||||||||
54325 | CP E | Compare with the newly calculated one | ||||||||||||||||||||
54326 | JR Z,54342 | If it's the same, there's nothing to change, so skip out of this routine | ||||||||||||||||||||
54328 | INC C | Increment the (flag) C register (this indicates that there's been a change to Maroc's sprite graphic) | ||||||||||||||||||||
54329 | LD A,E | Get the newly calculated graphics offset address value | ||||||||||||||||||||
54330 | LD (60575),A | ...and store | ||||||||||||||||||||
54333 | LD D,0 | The graphics address offset will be in DE, the high byte of the offset isn't needed so reset it | ||||||||||||||||||||
54335 | LD HL,(60266) | Address pointer to graphics at 38851 | ||||||||||||||||||||
54338 | ADD HL,DE | Add the offset for Maroc's new graphics frame | ||||||||||||||||||||
54339 | LD (60098),HL | ...and store. |
Prev: 54065 | Up: Map | Next: 54342 |