Prev: C501 Up: Map Next: C5B5
C571: Adjust room element co-ordinates based on Maroc's room entry point
Room scenery elements' co-ordinates need to be tweaked with an offset amount based on Maroc's room entry point.
This routine adjusts each element's horizontal and vertical positions of each of the room item data sets at 7C00 and the foreground scenery object sets at 7F01.
Calculate offset based on Maroc's default room position and his room entry point
C571 LD A,($EB75) Maroc's horizontal (entry) position when he moves to a new room, in half-character/4-pixel steps
C574 LD C,A
C575 LD A,($EAC0) Maroc's default horizontal (X-axis) room position (in half-characters = 29)
C578 SUB C Offset amount = Maroc's default horizontal room position (~ 14.5 character spaces) minus his horizontal entry position
C579 LD B,A ...store in B register
C57A LD A,($EB76) Maroc's vertical (entry) position when he moves to a new room, in pixels
C57D LD C,A
C57E LD A,($EB74) Maroc's default vertical (Y-axis) room position (in pixels)
C581 SUB C Offset amount = Maroc's default vertical room position (~ 48 pixels) minus his vertical entry position
C582 LD C,A
C583 LD D,$00 Clear D register ready for DE offset addition shortly
C585 LD HL,($DAEE) Address pointer to room item data sets at 7C00
Add co-ordinate offsets into bytes 6 (horizontal co-ordinate) and 8 (vertical co-ordinate) of each of the room item data sets at 7C00
C588 LD A,(HL)
C589 CP $FF Skip next bit if no more data sets
C58B JR Z,$C59D
C58D LD E,$05 DE contains offset to move along 5 bytes to 6th byte of set
C58F ADD HL,DE
C590 LD A,(HL) Get item's horizontal room position (4-pixel/half-character steps)
C591 ADD A,B Add (or subtract if negative) the horizontal offset
C592 LD (HL),A ...and re-store
C593 INC HL Move along two bytes
C594 INC HL
C595 LD A,(HL) Get item's vertical room position (in pixels)
C596 ADD A,C Add (or subtract if negative) the vertical offset
C597 LD (HL),A ...and re-store
C598 LD E,$09 Move along 9 bytes - this puts the pointer at the start of the next bank of data
C59A ADD HL,DE
C59B JR $C588 Repeat until all data sets adjusted
Next do the same for the foreground scenery items, which are stored separately at 7F01
C59D LD HL,($EB70) Get address pointer to foreground scenery data sets at 7F01
Update data item loop:
C5A0 LD A,(HL)
C5A1 CP $FF Check first byte for end-of-data byte
C5A3 JP Z,$C63B Skip out of routine if found - all sets dealt with
Update co-ordinates at bytes 3 (horizontal) and 5 (vertical) of data set
C5A6 INC HL Move to byte 3 - horizontal co-ordinate
C5A7 INC HL
C5A8 LD A,(HL)
C5A9 ADD A,B Add (or subtract if negative) horizontal co-ordinate offset
C5AA LD (HL),A ...and re-store
C5AB INC HL Move to byte 5 - vertical co-ordinate
C5AC INC HL
C5AD LD A,(HL)
C5AE ADD A,C Add (or subtract if negative) vertical co-ordinate offset
C5AF LD (HL),A ...and re-store
C5B0 INC HL Move along three bytes to the next data set
C5B1 INC HL
C5B2 INC HL
C5B3 JR $C5A0 ...and repeat until all sets have been adjusted.
The routine that follows this one is at C63B (jump at end of data sets from C5A3)
Prev: C501 Up: Map Next: C5B5