Prev: BA34 Up: Map Next: BA8B
BA3B: Collision detection based on attributes
Used by the routines at B9EF and BA34.
Input
HL Current screen address to check
DE Current graphic address of Ted to check
A Combination of the two pixels of each address
Returns the attribute found if the collision was "safe" If the carry flag is set, the collision was "hostile"
BA3B PUSH HL Remember base values
BA3C PUSH BC
BA3D PUSH AF
BA3E LD A,H Get screen address
BA3F RRA Convert to offset from attribute buffer at A000
BA40 RRA
BA41 RRA
BA42 AND $03
BA44 ADD A,$A0
BA46 LD H,A Store this so HL now points to attributes
BA47 LD B,(HL) Get the attribute
BA48 BIT 6,B Is the attribute bright?
BA4A JR Z,$BA54 Move on if so
BA4C LD A,($A422) Are we in the lift?
BA4F CP $2A
BA51 CALL Z,$BABD Check lift button logic if we are
BA54 BIT 7,B Is the attribute flashing?
BA56 CALL NZ,$B2D2 Yes, Ted hit a task button - check what to do next
BA59 LD HL,($A41D) Get the static object collision table
Check if Ted is standing in a "safe" spot
BA5C LD A,(HL) Get the next attribute to check
BA5D AND A Is it zero?
BA5E JR Z,$BA69 If so, that's the end of the list - move forward
BA60 XOR B Does this attribute match the current one?
BA61 INC HL Move to next attribute if there is not a match
BA62 JR NZ,$BA5C
BA64 POP AF Restore flags
BA65 LD A,B Return found attribute
BA66 POP BC Restore base values stored earlier
BA67 POP HL
BA68 RET Return that Ted has matched a safe attribute
BA69 POP AF Restore bitmask / flags and swap them out
BA6A EX AF,AF'
BA6B LD C,A Put it in C
BA6C INC HL Move to next attribute
BA6D LD A,(HL)
BA6E AND A Is it zero?
BA6F JR Z,$BA84 If so, that's the end of the list - move forward
BA71 XOR B Does this attribute match the current one?
BA72 JR NZ,$BA6C Move to the next attribute if there's not a match
BA74 LD A,($A439) Get flags
BA77 BIT 3,A Is bit 3 (Ted suck in wall) set?
BA79 JR NZ,$BA85 Move forward if not
BA7B OR $10 Set bit 5 (Ted touched a wall) and write it back
BA7D LD ($A439),A
BA80 LD A,C Restore A
BA81 EX AF,AF'
BA82 JR $BA65 Signal this is a safe attribute and return it
This attribute is not in the list of water or earth - it must be fatal
BA84 SCF Set the carry flag - Ted has hit something unpleasant :-(
BA85 LD A,B Put the attribute found in A
BA86 POP BC Restore registers
BA87 POP HL
BA88 POP DE
BA89 POP DE
BA8A RET Return marking Ted hit something hostile
Prev: BA34 Up: Map Next: BA8B