Prev: B440 Up: Map Next: B5E6
B4A5: Put moving objects into the live buffer
Used by the routine at AE77.
Input
IX Pointer to the moving object buffer
HL Pointer to data from the room
B4A5 LD E,(HL) Put the initial offset value in DE
B4A6 INC HL
B4A7 LD D,(HL)
B4A8 LD A,D Is it zero?
B4A9 OR E
B4AA RET Z All done with moving objects, nothing else to do
Store moving object flags
B4AB LD A,D Keep bit 7 in place and right shift all other bits
B4AC RRA
B4AD XOR D
B4AE AND $0F
B4B0 XOR D
B4B1 AND $AF
B4B3 LD (IX+$06),A Store flags
Store position
B4B6 LD A,D Get bit 0 of D
B4B7 AND $01
B4B9 LD D,A
B4BA RLC A Convert to graphic offset
B4BC RLC A
B4BE RLC A
B4C0 ADD A,$80
B4C2 LD (IX+$01),A Store it
B4C5 LD (IX+$00),E
B4C8 LD B,$02 Two entries
B4CA INC HL Move to next entry
B4CB PUSH HL Remember this
B4CC LD A,(HL) Get the value
B4CD AND $1F Extract bits 0-4
B4CF BIT 7,(IX+$06) Move ahead if this left / right movement
B4D3 JR Z,$B4E3
B4D5 ADD A,A Change the displacement value to reflect up / down
B4D6 ADD A,A
B4D7 ADD A,A
B4D8 ADD A,A
B4D9 RR D
B4DB ADD A,A
B4DC RL D
B4DE XOR E
B4DF AND $E0
B4E1 JR $B4E6
B4E3 XOR E
B4E4 AND $1F
B4E6 XOR E
B4E7 LD E,A
B4E8 LD HL,$A000 Point to attributes buffer
B4EB ADD HL,DE Add offset
B4EC EX (SP),HL Put the offset on stack and restore pointer to next room data byte
B4ED DJNZ $B4CA Loop back if more to do
B4EF POP BC Get first value
B4F0 LD (IX+$04),C Set first screen bounds
B4F3 LD (IX+$05),B
B4F6 POP BC Get second value
B4F7 LD (IX+$02),C Set second screen bounds
B4FA LD (IX+$03),B
B4FD DEC HL Move back to get the attribute
B4FE LD A,(HL) Get next value
B4FF RRCA Extract height
B500 RRCA
B501 AND $38
B503 ADD A,$08
B505 LD (IX+$07),A Store it
B508 INC HL Next value
B509 LD A,(HL) Get value
B50A RLCA Extract width
B50B RLCA
B50C RLCA
B50D AND $03
B50F INC A
B510 LD (IX+$08),A Store it
B513 INC HL Next value
B514 LD A,(HL) Get attribute
B515 LD (IX+$09),A Store it
B518 INC HL Next value
B519 PUSH HL Remember this
B51A LD L,(HL) Convert from graphic offset to word
B51B LD H,$00
B51D ADD HL,HL
B51E LD BC,($A469) Get base pointer to moving graphic offsets
B522 ADD HL,BC Get the appropriate value for this graphic
B523 LD C,(HL) Put the offsest in BC
B524 INC HL
B525 LD B,(HL)
B526 LD HL,($A46B) Get base pointer to moving graphics
B529 ADD HL,BC Add the offset
B52A LD (IX+$0A),L Store the value
B52D LD (IX+$0C),L
B530 LD (IX+$0B),H
B533 LD (IX+$0D),H
B536 POP HL Restore HL
B537 LD A,$01
B539 INC HL Move to next value
B53A BIT 2,(IX+$06) Skip if bit 2 of the flags set
B53E JR Z,$B542
B540 LD A,(HL) Get next value
B541 INC HL Point to next entry
B542 LD (IX+$0E),A Store offset between frames
B545 LD (IX+$0F),A
B548 LD (IX+$10),$00
B54C LD (IX+$11),$00
B550 LD A,(HL)
B551 PUSH AF
B552 AND $07
B554 INC A
B555 LD (IX+$12),A
B558 LD (IX+$13),$FF
B55C LD A,(HL)
B55D RRCA
B55E RRCA
B55F RRCA
B560 AND $07
B562 INC A
B563 LD B,A
B564 XOR A
B565 SCF
B566 RLA
B567 DJNZ $B565
B569 LD (IX+$1C),A
B56C INC HL
B56D LD A,$01
B56F BIT 2,(IX+$06)
B573 JR Z,$B577
B575 LD A,(HL)
B576 INC HL
B577 LD (IX+$18),A
B57A LD (IX+$19),A
Store the speed
B57D LD A,$01 Default value
B57F BIT 1,(IX+$06) Is the "default speed" flag set?
B583 JR Z,$B587 Move on if so
B585 LD A,(HL) Get next value
B586 INC HL Move to point to next entry in the room data
B587 LD (IX+$1A),A Store speed
B58A LD (IX+$1B),A
B58D PUSH HL
B58E LD D,B
B58F LD C,(IX+$07)
B592 LD E,(IX+$08)
B595 CALL $B5E6
B598 LD (IX+$14),L
B59B LD (IX+$15),H
B59E BIT 7,(IX+$06)
B5A2 JR NZ,$B5AF
B5A4 LD A,(IX+$12)
B5A7 BIT 3,A
B5A9 JR NZ,$B5AF
B5AB ADD HL,HL
B5AC ADD A,A
B5AD JR $B5A7
B5AF LD (IX+$16),L
B5B2 LD (IX+$17),H
B5B5 EX DE,HL
B5B6 POP HL
B5B7 POP AF
B5B8 PUSH DE
B5B9 BIT 6,A
B5BB JR Z,$B5C1
B5BD LD E,(HL)
B5BE INC HL
B5BF LD D,(HL)
B5C0 INC HL
B5C1 LD (IX+$1D),E
B5C4 LD (IX+$1E),D
B5C7 POP BC
B5C8 LD DE,$0000
B5CB BIT 7,A
B5CD JR Z,$B5D8
B5CF LD E,(IX+$0E)
B5D2 PUSH HL
B5D3 CALL $B5E6
B5D6 EX DE,HL
B5D7 POP HL
B5D8 LD (IX+$1F),E
B5DB LD (IX+$20),D
B5DE LD DE,$0021
B5E1 ADD IX,DE
B5E3 JP $B4A5
Prev: B440 Up: Map Next: B5E6