Prev: 51279 Up: Map Next: 51529
51286: Draw Narrow Entity Sprite
Entry point for drawing a narrow entity sprite. Sets draw mode (attribute writes enabled) and falls through to Render_Narrow_Entity_Sprite. XOR-renders 8 rows of 2 bytes each; the sprite type is looked up in Sprite_Pixel_Data_Table for the pixel data address, and the entity colour is written to the 2 attribute cells flanking each pixel row.
Input
HL Entity record pointer
Draw_Narrow_Entity_Sprite 51286 EXX Set draw mode: set the attribute-write flag in D'.
51287 LD D,1
51289 EXX
This entry point is used by the routine at Erase_Narrow_Entity_Sprite.
Compute the sprite pixel data pointer and screen coordinate.
Render_Narrow_Entity_Sprite 51290 LD B,H Copy the entity record pointer to BC.
51291 LD C,L
51292 LD E,(HL) Read the sprite type byte and form a word offset in DE.
51293 SLA E
51295 LD D,0
51297 LD HL,50700 Look up the sprite pixel data address in the table at Sprite_Pixel_Data_Table.
51300 ADD HL,DE
51301 LD E,(HL)
51302 INC HL
51303 LD D,(HL)
51304 LD H,B Restore the entity record pointer to HL.
51305 LD L,C
51306 INC HL Advance past the sprite type byte and load the screen row address high byte from the entity record.
51307 LD B,70
51309 LD C,(HL)
51310 INC HL
51311 SLA C Shift the coordinate into B to build the screen address high byte.
51313 RL B
51315 PUSH BC Stash the screen coordinate on the stack.
51316 LD A,(HL) Load the column byte, clear HL, and distribute its bits into L via successive right-rotations to form the pixel offset.
51317 AND A
51318 LD HL,0
51321 RRA
51322 RR L
51324 RRA
51325 RR L
51327 RRA
51328 RR L
51330 RRC L
51332 ADD HL,DE Add the sprite data base to the offset, set BC as the sprite pixel data pointer, and restore the screen coordinate.
51333 LD B,H
51334 LD C,L
51335 POP HL
51336 EXX
51337 LD C,A Stash the column offset in alternate C and return to the main register set.
51338 EXX
Row 1: XOR-render the first sprite row and optionally write the entity colour to the flanking attribute cells.
51339 ADD A,(HL) Compute the first screen row address from the entity record into DE.
51340 LD E,A
51341 INC HL
51342 LD D,(HL)
51343 INC HL
51344 LD A,(BC) XOR-render 2 sprite pixel bytes at the first screen row.
51345 EX DE,HL
51346 XOR (HL)
51347 LD (HL),A
51348 INC BC
51349 INC HL
51350 LD A,(BC)
51351 INC BC
51352 XOR (HL)
51353 LD (HL),A
51354 EXX Check whether attribute writes are enabled; jump to Render_Narrow_Entity_Sprite_Row2 to skip the colour write in erase mode.
51355 LD A,D
51356 AND A
51357 EXX
51358 JR Z,Render_Narrow_Entity_Sprite_Row2
51360 LD A,H Convert the screen address high byte to an attribute address.
51361 RRCA
51362 RRCA
51363 RRCA
51364 AND %00000011 Mask to the attribute page bits.
51366 OR %01011000 Set the attribute area high byte.
51368 LD H,A Update H to point into attribute RAM.
51369 EXX Fetch the entity colour via B' and write it to the first attribute cell.
51370 LD A,B
51371 EXX
51372 LD (HL),A
51373 DEC HL
51374 LD (HL),A Write the entity colour to the second attribute cell.
Rows 2–7: XOR-render the remaining sprite rows without attribute writes (attribute colour was set once on row 1).
Render_Narrow_Entity_Sprite_Row2 51375 EX DE,HL Restore the entity record pointer and fetch the column offset from alternate C.
51376 EXX
51377 LD A,C
51378 EXX
51379 ADD A,(HL) Compute the second screen row address from the entity record.
51380 LD E,A
51381 INC HL
51382 LD D,(HL)
51383 INC HL
51384 LD A,(BC) XOR-render 2 sprite bytes at the second screen row and restore the entity record pointer.
51385 EX DE,HL
51386 XOR (HL)
51387 LD (HL),A
51388 INC BC
51389 INC HL
51390 LD A,(BC)
51391 INC BC
51392 XOR (HL)
51393 LD (HL),A
51394 EX DE,HL
51395 EXX Fetch the column offset from alternate C.
51396 LD A,C
51397 EXX
51398 ADD A,(HL) Compute the third screen row address from the entity record.
51399 LD E,A
51400 INC HL
51401 LD D,(HL)
51402 INC HL
51403 LD A,(BC) XOR-render 2 sprite bytes at the third screen row and restore.
51404 EX DE,HL
51405 XOR (HL)
51406 LD (HL),A
51407 INC BC
51408 INC HL
51409 LD A,(BC)
51410 INC BC
51411 XOR (HL)
51412 LD (HL),A
51413 EX DE,HL
51414 EXX Fetch the column offset from alternate C.
51415 LD A,C
51416 EXX
51417 ADD A,(HL) Compute the fourth screen row address from the entity record.
51418 LD E,A
51419 INC HL
51420 LD D,(HL)
51421 INC HL
51422 LD A,(BC) XOR-render 2 sprite bytes at the fourth screen row and restore.
51423 EX DE,HL
51424 XOR (HL)
51425 LD (HL),A
51426 INC BC
51427 INC HL
51428 LD A,(BC)
51429 INC BC
51430 XOR (HL)
51431 LD (HL),A
51432 EX DE,HL
51433 EXX Fetch the column offset from alternate C.
51434 LD A,C
51435 EXX
51436 ADD A,(HL) Compute the fifth screen row address from the entity record.
51437 LD E,A
51438 INC HL
51439 LD D,(HL)
51440 INC HL
51441 LD A,(BC) XOR-render 2 sprite bytes at the fifth screen row and restore.
51442 EX DE,HL
51443 XOR (HL)
51444 LD (HL),A
51445 INC BC
51446 INC HL
51447 LD A,(BC)
51448 INC BC
51449 XOR (HL)
51450 LD (HL),A
51451 EX DE,HL
51452 EXX Fetch the column offset from alternate C.
51453 LD A,C
51454 EXX
51455 ADD A,(HL) Compute the sixth screen row address from the entity record.
51456 LD E,A
51457 INC HL
51458 LD D,(HL)
51459 INC HL
51460 LD A,(BC) XOR-render 2 sprite bytes at the sixth screen row and restore.
51461 EX DE,HL
51462 XOR (HL)
51463 LD (HL),A
51464 INC BC
51465 INC HL
51466 LD A,(BC)
51467 INC BC
51468 XOR (HL)
51469 LD (HL),A
51470 EX DE,HL
51471 EXX Fetch the column offset from alternate C.
51472 LD A,C
51473 EXX
51474 ADD A,(HL) Compute the seventh screen row address from the entity record.
51475 LD E,A
51476 INC HL
51477 LD D,(HL)
51478 INC HL
51479 LD A,(BC) XOR-render 2 sprite bytes at the seventh screen row and restore the entity record pointer.
51480 EX DE,HL
51481 XOR (HL)
51482 LD (HL),A
51483 INC BC
51484 INC HL
51485 LD A,(BC)
51486 INC BC
51487 XOR (HL)
51488 LD (HL),A
51489 EX DE,HL
Row 8: XOR-render the final sprite row and write the entity colour to the flanking attribute cells if in draw mode.
51490 EXX Fetch the column offset from alternate C.
51491 LD A,C
51492 EXX
51493 ADD A,(HL) Compute the eighth screen row address from the entity record.
51494 LD E,A
51495 INC HL
51496 LD D,(HL)
51497 INC HL
51498 LD A,(BC) XOR-render 2 sprite bytes at the eighth screen row.
51499 EX DE,HL
51500 XOR (HL)
51501 LD (HL),A
51502 INC BC
51503 INC HL
51504 LD A,(BC)
51505 INC BC
51506 XOR (HL)
51507 LD (HL),A
51508 EXX Return without writing attributes if in erase mode.
51509 LD A,D
51510 AND A
51511 EXX
51512 RET Z
51513 LD A,H Convert the screen address high byte to an attribute address.
51514 RRCA
51515 RRCA
51516 RRCA
51517 AND %00000011 Mask to the attribute page bits.
51519 OR %01011000 Set the attribute area high byte.
51521 LD H,A Update H to point into attribute RAM.
51522 EXX Fetch the entity colour via B' and write it to the first attribute cell.
51523 LD A,B
51524 EXX
51525 LD (HL),A
51526 DEC HL Write the entity colour to the second attribute cell.
51527 LD (HL),A
51528 RET Return.
Prev: 51279 Up: Map Next: 51529