Routines |
Prev: C41A | Up: Map | Next: C47E |
This iterates over all of the character structs testing each one to see if it can be brought on-screen.
Used by the routines at setup_movable_items and main_loop.
|
||||
Form a clamped map position in DE.
|
||||
spawn_characters | C41C | LD HL,($81BB) | Read the current map position into HL | |
C41F | LD A,L | Get map_position.x | ||
C420 | SUB $08 | Subtract 8 | ||
C422 | JR NC,spawn_characters_0 | Jump if it was >= 8 | ||
C424 | XOR A | Otherwise zero it | ||
spawn_characters_0 | C425 | LD E,A | E is the result: map_x_clamped | |
C426 | LD A,H | Get map_position.y | ||
C427 | SUB $08 | Subtract 8 | ||
C429 | JR NC,spawn_characters_1 | Jump if it was >= 8 | ||
C42B | XOR A | Otherwise zero it | ||
spawn_characters_1 | C42C | LD D,A | D is the result: map_y_clamped | |
Walk all character structs.
|
||||
C42D | LD HL,$7612 | Point HL at character_structs[0] (charstr) | ||
C430 | LD B,$1A | Set B for 26 iterations (26 characters) | ||
Start loop
|
||||
sc_loop | C432 | BIT 6,(HL) | Fetch flags and test for characterstruct_FLAG_ON_SCREEN | |
C434 | JR NZ,sc_next | Jump if already on-screen | ||
Is this character in the current room?
|
||||
C436 | PUSH HL | Preserve the character struct pointer | ||
C437 | INC HL | Point HL at charstr.room | ||
C438 | LD A,($68A0) | Get the global current room index | ||
C43B | CP (HL) | Same room? | ||
C43C | JR NZ,sc_unstash_next | Jump if not | ||
C43E | AND A | Outdoors? | ||
C43F | JR NZ,sc_indoors | Jump if not | ||
Handle outdoors.
|
||||
C441 | INC HL | Point HL at charstr.pos.x | ||
Do screen Y calculation:
y = ((256 - charstr.pos.x) - charstr.pos.y) - charstr.pos.height
A is zero here, and represents 0x100.
|
||||
C442 | SUB (HL) | Subtract charstr.pos.x | ||
C443 | INC HL | Advance HL to charstr.pos.y | ||
C444 | SUB (HL) | Subtract charstr.pos.y | ||
C445 | INC HL | Advance HL to charstr.pos.height | ||
C446 | SUB (HL) | Subtract charstr.pos.height | ||
C447 | LD C,A | Copy y to C | ||
C448 | LD A,D | Copy map_y_clamped to D | ||
C449 | CP C | Is map_y_clamped >= y? | ||
C44A | JR NC,sc_unstash_next | Jump if so | ||
C44C | ADD A,$20 | Add 16 + 2 * 8 (16 => screen height, 8 => spawn zone size) | ||
C44E | JR NC,spawn_characters_2 | Clamp to a maximum of 255 | ||
C450 | LD A,$FF | |||
spawn_characters_2 | C452 | CP C | Is y > (map_y_clamped + spawn size, clamped to 255)? | |
C453 | JR C,sc_unstash_next | Jump if so | ||
Do screen X calculation:
x = (64 - charstr.pos.x + charstr.pos.y) * 2
|
||||
C455 | DEC HL | Step HL back to charstr.pos.y | ||
C456 | LD A,$40 | Start with x = 64 | ||
C458 | ADD A,(HL) | Add charstr.pos.y | ||
C459 | DEC HL | Step HL back to charstr.pos.x | ||
C45A | SUB (HL) | Subtract charstr.pos.x | ||
C45B | ADD A,A | Double it | ||
C45C | LD C,A | Copy x to C | ||
C45D | LD A,E | Copy map_x_clamped to E | ||
C45E | CP C | Is map_x_clamped >= x? | ||
C45F | JR NC,sc_unstash_next | Jump if so | ||
C461 | ADD A,$28 | Add 24 + 2 * 8 (24 => screen width, 8 => spawn zone size) | ||
C463 | JR NC,spawn_characters_3 | Clamp to a maximum of 255 | ||
C465 | LD A,$FF | |||
spawn_characters_3 | C467 | CP C | Is x > (map_x_clamped + spawn size, clamped to 255)? | |
C468 | JR C,sc_unstash_next | Jump if so | ||
sc_indoors | C46A | POP HL | Restore the character struct pointer (spawn_character arg) | |
C46B | PUSH HL | Preserve the character struct pointer over the call | ||
C46C | PUSH DE | Preserve map_x/y_clamped | ||
C46D | PUSH BC | Preserve the loop counter | ||
C46E | CALL spawn_character | Add characters to the visible character list | ||
C471 | POP BC | Restore the loop counter | ||
C472 | POP DE | Restore map_x/y_clamped | ||
sc_unstash_next | C473 | POP HL | Restore the character struct pointer | |
sc_next | C474 | LD A,L | Advance to the next characterstruct | |
C475 | ADD A,$07 | |||
C477 | LD L,A | |||
C478 | JR NC,spawn_characters_4 | |||
C47A | INC H | |||
spawn_characters_4 | C47B | DJNZ sc_loop | ...loop | |
C47D | RET | Return |
Prev: C41A | Up: Map | Next: C47E |