Prev: 53601 Up: Map Next: 53714
53625: Tunnel position & direction
Used by the routine at 51359.
The first byte in the data sets (31744) for tunnels has the ID number of 15, which is the general tunnel position and direction.
The other tunnel elements - walls/boundaries, spiders and bats - are dealt with separately in the same way as room objects.
53625 LD A,0
53627 LD (60234),A Set vertical pixel position to 0 (top of screen)
The game timer is used to generate actions such as changing the tunnel direction, spiders, bats etc.
Every 16th cycle of the game timer, a new tunnel direction is calculated:
53630 LD A,(60074) Get incremental game timer
53633 AND 15 Check if any of bits 0-3 are set
53635 JR NZ,53685 If so, continue the tunnel. The number bit value in the AND instruction acts as an interval that affects tunnel duration. It can be changed for shorter tunnels - see the POKEs section.
Check if Maroc has reached the end of the tunnel
53637 LD A,(60285) Get tunnel length counter (first byte of tunnel data sets at 26384 multiplied by 2)
53640 DEC A ...decrement it..
53641 LD (60285),A ...and re-store
53644 JR NZ,53651 Interval check - has Maroc reached the end of the tunnel?
53646 LD A,255 ...If so, set the 'end-of-tunnel' byte accordingly - this is checked at 55837 and indicates that the new room number at the end of the tunnel will need evaluating/setting.
53648 LD (60080),A
Determine left/right direction, and offset, of tunnel walls. Bytes in ROM are used to randomize direction.
Tunnel horizontal position can change left or right between -31 and +31 pixels. If the byte value is outside these values (32 - 224) the current offset is not changed, i.e. the tunnel continues in the same direction without changing.
53651 LD HL,(60228) Value used to address various ROM locations to generate pseudo-random numbers for tunnels
53654 INC HL Move to the next ROM address
53655 LD (60228),HL ..and re-store pointer
53658 LD A,(HL) Get byte from ROM address
53659 AND 63 Keep a range of 0-63
53661 SUB 31 Subtract 31, giving a value of +32 to -31
53663 LD C,A Put in C register
53664 LD A,(60236) Get the current horizontal offset byte
53667 ADD A,C Add or subtract the direction change offset (+32 to +31)
53668 CP 128 Check if byte value is >= 128 (bit 7 set)
53670 JR NC,53678
53672 CP 32 If not, check if byte value >= 32
53674 JR NC,53685 If so, it's outside the threshold so jump straight to 53685 (don't change horizontal offset value)
53676 JR 53682
53678 CP 224 Byte value is > 128 so check if value < 224
53680 JR C,53685 If so, it's outside the threshold so jump straight to 53685 (don't change horizontal offset value)
53682 LD (60236),A Byte value is OK - store the new horizontal offset value
If the tunnel's horizontal position is too close to the left or right edge of the screen, shift its direction slightly back towards the centre:
53685 LD A,(60232) Horizontal position (in 4-pixel/half-character steps)
53688 LD (60574),A Copy to item horizontal position data store
53691 LD C,A Temp store in C
53692 SUB 16 If we subtract 16...
53694 CP 32 ...and check against 32...
53696 JR C,53711 ...a carry (jump to the end of the routine) will occur if the boundary is between 16 half-character steps and 48 half-character steps (this is OK)
53698 LD A,28 Otherwise, subtract the horizontal position from 28 (roughly centre of screen)
53700 SUB C
53701 SRA A ...and halve the offset, bringing it slightly closer to the centre of the screen
53703 LD (60236),A Re-store as the new horizontal position
53706 NEG Maroc's offset is the opposite of the scenery
53708 LD (60164),A ...So store the negative of this value for his horizontal offset.
53711 JP 53885
Prev: 53601 Up: Map Next: 53714