Prev: D6C7 Up: Map Next: D71C
D6D2: Tunnel section - Generate and prepare tunnel items
Used by the routine at D4FC.
This routine uses the cyclical game timer at EAAA to generate the left and right walls of the tunnel.
D6D2 LD A,$00 Reset current horizontal & vertical speeds back to zero
D6D4 LD ($EB4D),A
D6D7 LD ($EB4C),A
D6DA LD A,($EAAA) Game timer
D6DD LD C,A
D6DE AND $01 Every other game timer frame, decide whether to generate a left/right tunnel boundary wall
D6E0 JP NZ,$D71C
D6E3 LD A,($EB7E) Incremental tunnel counter
D6E6 INC A Add 1
D6E7 CP $14 Check if >=20 (this determines the limit to how many boundary wall sections can be generated on screen)
D6E9 JP NC,$D794 If it's >=20, skip out of this routine. The most that will realistically fit on screen is 10, so this limit shouldn't normally be reached.
D6EC LD ($EB7E),A Counter is <20. Restore incremented counter
Use the game timer to create left/right tunnel border sections:
D6EF LD A,C Retrieve game timer
D6F0 AND $02 Check bit 2 - 50/50 set/unset. Will go in a sequence of 11-00-11-00-11
D6F2 JR Z,$D6FC The 50/50 is used to create either a left-hand or right-hand tunnel boundary graphic. In this sequence this creates a 'staggered' effect for the tunnel walls.
Right tunnel boundary wall:
D6F4 LD A,$01 Graphic offset = 1 (no offset - use graphic at A09A)
D6F6 LD C,$10 Horizontal movement speed/direction = +16 (moving right)
D6F8 LD E,$04 Horizontal movement position offset - in half-character/4-pixel steps (2 character squares to the right)
D6FA JR $D702
Left tunnel boundary wall:
D6FC LD A,$02 Graphic offset = 2 (a mirrored version of the tunnel graphic at A09A will be created and the graphics address stored at 9811)
D6FE LD C,$F0 Horizontal movement speed/direction = -16 (moving left)
D700 LD E,$FC Horizontal movement position offset - in half-character/4-pixel steps (2 character squares to the left)
Store calculated boundary attributes:
D702 LD ($EB46),A 1 = Right boundary, 2 = Left boundary (mirror version)
D705 LD ($EB50),A Graphic frame offset (1 = no offset or 2 = mirrored)
D708 LD A,$0E Graphic type = Tunnel object
D70A LD ($EB43),A
D70D LD A,C Retrieve horizontal position/movement offset
D70E LD ($EB4C),A ...and store
D711 LD A,($EC9E) Get horizontal graphic position (in 4-pixel/half-character steps)
D714 ADD A,E Add the offset (+ or - 2 character squares)
D715 LD ($EB48),A ...and store as graphic's horizontal screen position
D718 LD A,$27 Graphic number for tunnel boundary graphic address pointer at 980F
D71A JR $D77D Set up the tunnel wall graphic
Prev: D6C7 Up: Map Next: D71C