Prev: B460 Up: Map Next: B52E
B4C2: Fill Debris Slots
Write 11 type-E4 slots from World_Slot_1 using the actor X/Y at DE and ROM bytes addressed by RandomNumber.
Input
DE Address of the actor world X and Y
Point HL at the first world slot.
FillDebrisSlots B4C2 LD HL,$60A8 HL=World_Slot_1.
B4C5 LD BC,$0711 Set B to 07 bytes to clear and C to 11 slots.
Point HL' at ROM using RandomNumber as the low byte.
B4C8 EXX Switch to the shadow registers.
B4C9 LD A,($5E40) Fetch RandomNumber.
B4CC LD L,A Copy it into the low byte of HL'.
B4CD LD H,$00 Clear the high byte of HL'.
B4CF EXX Switch back.
Write type E4 and copy the three-byte X/Y seed.
FillDebrisSlots_Loop B4D0 PUSH BC Stash the slot counters on the stack.
B4D1 LD (HL),$E4 Write type E4.
B4D3 INC HL Skip the screen-column byte.
B4D4 INC HL
B4D5 LD A,(DE) Fetch the low world X.
B4D6 LD (HL),A Write it.
B4D7 INC DE Advance the seed pointer.
B4D8 INC HL Advance the slot pointer.
B4D9 LD A,(DE) Fetch the high world X.
B4DA LD (HL),A Write it.
B4DB INC HL Advance the slot pointer.
B4DC INC DE Advance the seed pointer.
B4DD LD A,(DE) Fetch the Y.
B4DE LD (HL),A Write it.
B4DF DEC DE Rewind the seed pointer by two bytes.
B4E0 DEC DE
B4E1 INC HL Advance to the speed byte.
Take the next ROM byte as the speed.
B4E2 EXX Switch to the shadow registers.
B4E3 LD A,(HL) Fetch the next ROM byte from *HL'.
B4E4 INC HL Advance HL'.
B4E5 AND A Jump to FillDebrisSlots_PositiveSpeed if it is positive.
B4E6 JP P,FillDebrisSlots_PositiveSpeed
B4E9 OR %11111100 Set bits 2-7.
FillDebrisSlots_WriteSpeed B4EB EXX Switch back.
B4EC LD (HL),A Write the speed.
B4ED INC HL Advance to the thrust byte.
Force the thrust into the range FB-FE.
B4EE EXX Switch to the shadow registers.
B4EF LD A,(HL) Fetch the next ROM byte from *HL'.
B4F0 INC HL Advance HL'.
B4F1 AND %00000011 Keep only bits 0-1.
B4F3 OR %11111100 Set bits 2-7.
B4F5 SUB $01 Subtract 01.
B4F7 EXX Switch back.
B4F8 LD (HL),A Write the thrust.
B4F9 INC HL Advance to the colour byte.
Colour is bits 0-2 of the next ROM byte (00 and 01 become WHITE), plus BRIGHT.
B4FA EXX Switch to the shadow registers.
B4FB LD A,(HL) Fetch the next ROM byte from *HL'.
B4FC INC HL Advance HL'.
B4FD AND %00000111 Keep only bits 0-2.
B4FF CP $02 Jump to FillDebrisSlots_SetBright if it is at least 02.
B501 JR NC,FillDebrisSlots_SetBright
B503 LD A,$07 A=WHITE.
FillDebrisSlots_SetBright B505 OR %01000000 Set bit 6.
B507 EXX Switch back.
B508 LD (HL),A Write the colour.
B509 INC HL Skip the flags byte.
B50A INC HL
Clear the next 07 bytes.
FillDebrisSlots_ClearBytes B50B LD (HL),$00 Write 00.
B50D INC HL Advance the slot pointer.
B50E DJNZ FillDebrisSlots_ClearBytes Decrease the counter by one and jump back to FillDebrisSlots_ClearBytes until it is zero.
Write the sprite delay and its reload value, then step to the next slot.
B510 EXX Switch to the shadow registers.
B511 LD A,(HL) Fetch the next ROM byte from *HL'.
B512 INC HL Advance HL'.
B513 AND %00000111 Keep only bits 0-2.
B515 INC A Increase it by one.
B516 EXX Switch back.
B517 LD (HL),A Write the sprite delay.
B518 INC HL Advance the slot pointer.
B519 LD (HL),A Write the same value as the delay reload.
B51A LD A,L Advance HL by 07 to the next slot.
B51B ADD A,$07
B51D LD L,A
B51E LD A,H
B51F ADC A,$00
B521 LD H,A
Loop until every slot has been written, then initialise the explosion.
B522 POP BC Restore the slot counters from the stack.
B523 DEC C Decrease the remaining slot count by one.
B524 JR NZ,FillDebrisSlots_Loop Jump back to FillDebrisSlots_Loop if there are slots left.
B526 JP InitialiseExplosion_3 Jump to InitialiseExplosion_3.
Positive ROM speeds become 01-04.
FillDebrisSlots_PositiveSpeed B529 AND %00000011 Keep only bits 0-1.
B52B INC A Increase it by one.
B52C JR FillDebrisSlots_WriteSpeed Jump to FillDebrisSlots_WriteSpeed.
Prev: B460 Up: Map Next: B52E