Prev: B243 Up: Map Next: B37F
B296: Draw an entity (enemy, object or player)
Used by the routines at 9683, 9BA7 and BC48.
B296 PUSH DE Save DE
B297 OR A is entity facing left?
B298 JP NZ,$B303 Jump if so
Entity facing right. Computes address of graphic data for entity and address destination on room buffer
B29B LD A,($A248) Set A to the x-position of entity
B29E AND $07 Set A to the bit position of the entity (bits2-0)
B2A0 LD E,A Set HL to the address pointer of offset for sprite movement
B2A1 LD D,$00
B2A3 ADD HL,DE
B2A4 LD E,(HL) Set DE to the corresponding offset based on the position of the sprite
B2A5 LD D,$00
B2A7 POP HL Recover HL (graphics data of the sprite)
B2A8 ADD HL,DE Set HL to the address of the corresponding sprite based on the offset
B2A9 LD A,($A248) Computes at HL the address into room graphic data buffer for the entity
B2AC SRL A
B2AE SRL A
B2B0 SRL A
B2B2 LD ($A248),A
B2B5 PUSH HL
B2B6 LD A,($A249)
B2B9 LD L,A
B2BA LD H,$00
B2BC ADD HL,HL
B2BD ADD HL,HL
B2BE ADD HL,HL
B2BF ADD HL,HL
B2C0 ADD HL,HL
B2C1 LD DE,$E8FF
B2C4 ADD HL,DE
B2C5 LD A,($A248)
B2C8 LD E,A
B2C9 LD D,$00
B2CB ADD HL,DE
B2CC EX DE,HL Exchange DE and HL
B2CD POP HL Recover HL (the address of the corresponding sprite based on the offset)
B2CE PUSH DE Save DE
B2CF LD A,($A24A) Set A to the width of the sprite (in bytes)
B2D2 LD ($B2F2),A Configure LD opcode at B2F1 to set B register to the width of the sprite
B2D5 LD A,($A24B) Set A to the height of the sprite (in pixels)
B2D8 LD ($B2EE),A Configure LD opcode at B2ED to set B register to the height of the sprite
B2DB EX DE,HL Exchange DE and HL
B2DC LD A,($A1CC) Check bit for Graphic Data Select
B2DF BIT 7,A
B2E1 JP Z,$B2E8 Jump if graphic data is based in animation offsets
B2E4 LD DE,($A1CD) Set DE to the graphic data for static (non animated) sprite
Entity facing right. Draw entity (enemy, object or Rex)
B2E8 LD ($A25E),DE Set the address for the graphic data of the entity
B2EC POP HL Restore HL
B2ED LD B,$00 Set B to the width of the sprite
B2EF PUSH BC Save BC and HL
B2F0 PUSH HL
B2F1 LD B,$00 Set B to the height of the sprite
B2F3 LD A,(DE) Set A to the graphic data to copy
B2F4 OR (HL) Blend the graphic data with the graphic data on the room
B2F5 LD (HL),A Copy graphics data to the room buffer
B2F6 INC DE Increment sprite graphic data and room graphic data destination
B2F7 INC HL
B2F8 DJNZ $B2F3 Jump back if the are more sprite rows o draw
B2FA POP HL Restore HL
B2FB LD BC,$0020 Increment one row for the room graphic data
B2FE ADD HL,BC
B2FF POP BC Restore BC
B300 DJNZ $B2EF Jump back until all rows drawn
B302 RET
Entity facing left. Computes address of graphic data for entity and address destination on room buffer
B303 LD A,($A248) Set A to the x-position
B306 LD DE,$0007 Set HL to point to the last byte of the offset animation
B309 ADD HL,DE
B30A AND $07 And substract the position bit2-0 for the sprite x-position to point to the correspondent offset
B30C LD E,A
B30D LD D,$00
B30F AND A
B310 SBC HL,DE
B312 LD E,(HL) Set DE to the offset animation value
B313 LD D,$00
B315 POP HL Recover HL (address pointer for graphic data of sprite)
B316 ADD HL,DE And adds the offset
B317 LD A,($A248) Computes at HL the address into room graphic data buffer for the entity
B31A SRL A
B31C SRL A
B31E SRL A
B320 LD ($A248),A
B323 PUSH HL
B324 LD A,($A249)
B327 LD L,A
B328 LD H,$00
B32A ADD HL,HL
B32B ADD HL,HL
B32C ADD HL,HL
B32D ADD HL,HL
B32E ADD HL,HL
B32F LD DE,$E8FF
B332 ADD HL,DE
B333 LD A,($A248)
B336 LD E,A
B337 LD D,$00
B339 ADD HL,DE
B33A EX DE,HL Exchange DE an HL
B33B POP HL Restore HL
B33C PUSH DE Save DE
B33D LD A,($A24A) Set A to the width of the sprite (in bytes)
B340 LD ($B362),A Configure LD opcode at B361 to set B register to the width of the sprite
B343 LD A,($A24B) Set A to the height of the sprite (in pixels)
B346 LD ($B35E),A Configure LD opcode at B35D to set B register to the height of the sprite
B349 EX DE,HL Exchange DE and HL
B34A LD A,($A1CC) Check bit for Graphic Data Select
B34D BIT 7,A
B34F JP Z,$B356 Jump if graphic data is based in animation offsets
B352 LD DE,($A1CD) Set DE to the graphic data for static (non animated) sprite
Entity facing left. Draw entity (enemy, object or Rex)
B356 LD ($A25E),DE Set the address for the graphic data of the entity
B35A POP HL Restore HL (address pointer to room graphic buffer)
B35B INC HL Increment address pointer to draw backwards from here
B35C INC HL
B35D LD B,$00 Set B to the width of the sprite
B35F PUSH BC Save BC and REGhl
B360 PUSH HL
B361 LD B,$00 Set B to the height of the sprite
B363 LD A,(DE) Set A to the byte of the graphic data
B364 PUSH DE Save DE and HL
B365 PUSH HL
B366 LD E,A Point graphic value into Invert byte lookup table
B367 LD D,$00
B369 LD HL,$AE52
B36C ADD HL,DE
B36D LD A,(HL) Set A to the corresponent inverted byte
B36E POP HL Restore HL and DE
B36F POP DE
B370 OR (HL) Blend byte with graphic data of room
B371 LD (HL),A Set graphic data into room
B372 INC DE Increment address to graphic data
B373 DEC HL Decrement address to room graphic buffer
B374 DJNZ $B363 Jump back until the row is completed
B376 POP HL Restore HL
B377 LD BC,$0020 Add one row to the address pointer for the room graphic data
B37A ADD HL,BC
B37B POP BC Restore BC
B37C DJNZ $B35F Jump back until all the rows has been draw
B37E RET
Prev: B243 Up: Map Next: B37F