← C443 Credits and greetings scroll Map C61D → Spawn objects from the current level's wave script
C5C4: Compute an object's spawn position
Computes a spawn position for an object into the work X and work Y, from an entry of the current level's spawn-cell table. It draws nothing.
Each table entry packs one cell of the brick grid as a column and a row. The spawn position is that cell's on-screen position, mirrored when the bat is on the left.
calc_spawn_coords C5C4 PUSH BC Index the current level's 4-entry spawn-cell table, 4 bytes per level.
C5C5 LD A,(level)
C5C8 LD L,A
C5C9 LD H,$00
C5CB ADD HL,HL
C5CC ADD HL,HL
C5CD LD DE,spawn_cell_table
C5D0 ADD HL,DE
C5D1 LD A,(spawn_fixed_pos) Fixed-position flag set: use the table's first entry.
C5D4 OR A
C5D5 JR Z,calc_spawn_coords_0
C5D7 LD E,$00
C5D9 JR calc_spawn_coords_1
calc_spawn_coords_0 C5DB CALL next_random Flag clear: pick a random entry 0–3.
C5DE AND $03
C5E0 LD E,A
calc_spawn_coords_1 C5E1 LD D,$00 Read the chosen packed cell.
C5E3 ADD HL,DE
C5E4 LD A,(HL)
C5E5 LD B,$00 Split the cell number into its row, counted in B, and its column, the remainder left in A.
calc_spawn_coords_2 C5E7 CP $09
C5E9 JR C,calc_spawn_coords_3
C5EB SUB $09
C5ED INC B
C5EE JR calc_spawn_coords_2
calc_spawn_coords_3 C5F0 EX AF,AF' Stash the column, then turn the row into the work Y, 16 pixels per row below the field's top edge.
C5F1 LD A,B
C5F2 ADD A,A
C5F3 ADD A,A
C5F4 ADD A,A
C5F5 ADD A,A
C5F6 ADD A,$20
C5F8 LD (work_y),A
C5FB LD A,(bat_side) Bat on the left? Mirror the column.
C5FE OR A
C5FF JR NZ,calc_spawn_coords_4
C601 EX AF,AF' Bat on the right: turn the column into the work X, then return.
C602 ADD A,A
C603 ADD A,A
C604 ADD A,A
C605 ADD A,A
C606 ADD A,$10
C608 LD (work_x),A
C60B POP BC
C60C RET
calc_spawn_coords_4 C60D EX AF,AF' Bat on the left: count the column from the far side, then turn it into the work X. That mirrors the column.
C60E LD B,A
C60F LD A,$08
C611 SUB B
C612 ADD A,A
C613 ADD A,A
C614 ADD A,A
C615 ADD A,A
C616 ADD A,$60
C618 LD (work_x),A
C61B POP BC
C61C RET
← C443 Credits and greetings scroll Map C61D → Spawn objects from the current level's wave script
Fork me on GitHub