Prev: 50433 Up: Map Next: 50613
50545: 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 31744 and the foreground scenery object sets at 32513.
Calculate offset based on Maroc's default room position and his room entry point
50545 LD A,(60277) Maroc's horizontal (entry) position when he moves to a new room, in half-character/4-pixel steps
50548 LD C,A
50549 LD A,(60096) Maroc's default horizontal (X-axis) room position (in half-characters = 29)
50552 SUB C Offset amount = Maroc's default horizontal room position (~ 14.5 character spaces) minus his horizontal entry position
50553 LD B,A ...store in B register
50554 LD A,(60278) Maroc's vertical (entry) position when he moves to a new room, in pixels
50557 LD C,A
50558 LD A,(60276) Maroc's default vertical (Y-axis) room position (in pixels)
50561 SUB C Offset amount = Maroc's default vertical room position (~ 48 pixels) minus his vertical entry position
50562 LD C,A
50563 LD D,0 Clear D register ready for DE offset addition shortly
50565 LD HL,(56046) Address pointer to room item data sets at 31744
Add co-ordinate offsets into bytes 6 (horizontal co-ordinate) and 8 (vertical co-ordinate) of each of the room item data sets at 31744
50568 LD A,(HL)
50569 CP 255 Skip next bit if no more data sets
50571 JR Z,50589
50573 LD E,5 DE contains offset to move along 5 bytes to 6th byte of set
50575 ADD HL,DE
50576 LD A,(HL) Get item's horizontal room position (4-pixel/half-character steps)
50577 ADD A,B Add (or subtract if negative) the horizontal offset
50578 LD (HL),A ...and re-store
50579 INC HL Move along two bytes
50580 INC HL
50581 LD A,(HL) Get item's vertical room position (in pixels)
50582 ADD A,C Add (or subtract if negative) the vertical offset
50583 LD (HL),A ...and re-store
50584 LD E,9 Move along 9 bytes - this puts the pointer at the start of the next bank of data
50586 ADD HL,DE
50587 JR 50568 Repeat until all data sets adjusted
Next do the same for the foreground scenery items, which are stored separately at 32513
50589 LD HL,(60272) Get address pointer to foreground scenery data sets at 32513
Update data item loop:
50592 LD A,(HL)
50593 CP 255 Check first byte for end-of-data byte
50595 JP Z,50747 Skip out of routine if found - all sets dealt with
Update co-ordinates at bytes 3 (horizontal) and 5 (vertical) of data set
50598 INC HL Move to byte 3 - horizontal co-ordinate
50599 INC HL
50600 LD A,(HL)
50601 ADD A,B Add (or subtract if negative) horizontal co-ordinate offset
50602 LD (HL),A ...and re-store
50603 INC HL Move to byte 5 - vertical co-ordinate
50604 INC HL
50605 LD A,(HL)
50606 ADD A,C Add (or subtract if negative) vertical co-ordinate offset
50607 LD (HL),A ...and re-store
50608 INC HL Move along three bytes to the next data set
50609 INC HL
50610 INC HL
50611 JR 50592 ...and repeat until all sets have been adjusted.
The routine that follows this one is at 50747 (jump at end of data sets from 50595)
Prev: 50433 Up: Map Next: 50613