Prev: 949C Up: Map Next: 9618
9542: Sprite plotter for back buffer, up to 64px wide, 15px high, no mask, flips
Used by the routines at draw_object_right and draw_car.
Input
A Plot (A + 1) * 8 pixels
DE' Stride of bitmap data in bytes
HL Address in back buffer to plot at
HL' Address of bitmap data
plot_sprite_flipped 9542 LD D,$00 Advance the back buffer pointer to the end of the first line, so we can draw in reverse
9544 LD E,A
9545 ADD HL,DE
9546 SRL A Use psf_odd if the bottom bit is set (odd widths)
9548 JP C,psf_odd
954B LD ($956B),SP Save SP to restore later (self modify)
954F LD IX,$9575 IX = Base of jump table
9553 CPL (~A + 5) is (4 - A) is the number of plot operations to skip
9554 ADD A,$05
9556 LD C,A Multiply A by 9: the length of an individual plot operation
9557 RLCA
9558 RLCA
9559 RLCA
955A ADD A,C
955B LD C,A Move result to BC
955C LD B,$00
955E ADD IX,BC Add it to IX to complete the jump target
9560 LD D,$EF Point DE at table of flipped bytes at $EF00
9562 EXX Bank
9563 LD D,$00
9565 JR psf_even_body Jump into body of loop
psf_even_continue 9567 EXX Bank
9568 DJNZ psf_even_next Next scanline
956A LD SP,$0000 Restore SP (self modified)
956D RET Return
psf_even_next 956E ADD HL,DE Calculate address of next bitmap scanline
psf_even_body 956F LD SP,HL Put it in SP (so we can use POP for speed)
9570 EXX Unbank
9571 LD A,L [check elsewhere too]
9572 EX AF,AF'
9573 JP (IX) Jump table
9575 POP BC Transfer two bitmap bytes (16 pixels) from the "stack" to screen buffer with flipping
9576 LD E,C Set flip table address
9577 LD A,(DE) Flip byte and write to screen
9578 LD (HL),A
9579 DEC L Advance backwards
957A LD E,B Set flip table address
957B LD A,(DE) Flip byte and write to screen
957C LD (HL),A
957D DEC L Advance backwards
957E POP BC Transfer another 16 pixels
957F LD E,C
9580 LD A,(DE)
9581 LD (HL),A
9582 DEC L
9583 LD E,B
9584 LD A,(DE)
9585 LD (HL),A
9586 DEC L
9587 POP BC Transfer another 16 pixels
9588 LD E,C
9589 LD A,(DE)
958A LD (HL),A
958B DEC L
958C LD E,B
958D LD A,(DE)
958E LD (HL),A
958F DEC L
9590 POP BC Transfer another 16 pixels
9591 LD E,C
9592 LD A,(DE)
9593 LD (HL),A
9594 DEC L
9595 LD E,B
9596 LD A,(DE)
9597 LD (HL),A
9598 EX AF,AF'
9599 LD L,A Restore HL
959A LD A,H Save H in A then H--
959B DEC H
959C AND $0F Extract low four bits of row address
959E JP NZ,psf_even_continue If zero we'll need to handle it below, otherwise just loop
95A1 LD A,H H += 16
95A2 ADD A,$10
95A4 LD H,A
95A5 LD A,L Decrement the high three bits of row address
95A6 SUB $20
95A8 LD L,A
95A9 JP NC,psf_even_continue No carry, so finish scanline
95AC LD A,H H -= 16
95AD SUB $10
95AF LD H,A
95B0 JP psf_even_continue Loop back to psf_even_continue
psf_odd 95B3 INC A Increment A for upcoming calculation
95B4 LD ($95D4),SP Save SP to restore later (self modify) [in a different position to others]
95B8 LD IX,$95DE Point IX at start of plot instructions
95BC CPL (~A + 5) is (4 - A) is the number of plot operations to skip
95BD ADD A,$05
95BF LD C,A Multiply A by 9: the length of an individual plot operation
95C0 RLCA
95C1 RLCA
95C2 RLCA
95C3 ADD A,C
95C4 LD C,A Move result to BC
95C5 LD B,$00
95C7 ADD IX,BC Add it to IX to complete the jump target
95C9 LD D,$EF Point DE at table of flipped bytes at $EF00
95CB EXX Bank
95CC LD D,$00
95CE JR psf_odd_body Jump into body of loop
psf_odd_continue 95D0 EXX Bank
95D1 DJNZ psf_odd_next Next scanline
95D3 LD SP,$0000 Restore SP (self modified)
95D6 RET Return
psf_odd_next 95D7 ADD HL,DE Calculate address of next bitmap scanline
psf_odd_body 95D8 LD SP,HL Put it in SP (so we can use POP for speed)
95D9 EXX Unbank
95DA LD A,L
95DB EX AF,AF'
95DC JP (IX) Jump table
95DE POP BC Transfer two bitmap bytes (16 pixels) from the "stack" to screen buffer with flipping
95DF LD E,C Set flip table address
95E0 LD A,(DE) Flip byte and write to screen
95E1 LD (HL),A
95E2 DEC L Advance backwards
95E3 LD E,B Set flip table address
95E4 LD A,(DE) Flip byte and write to screen
95E5 LD (HL),A
95E6 DEC L Advance backwards
95E7 POP BC Transfer another 16 pixels
95E8 LD E,C
95E9 LD A,(DE)
95EA LD (HL),A
95EB DEC L
95EC LD E,B
95ED LD A,(DE)
95EE LD (HL),A
95EF DEC L
95F0 POP BC Transfer another 16 pixels
95F1 LD E,C
95F2 LD A,(DE)
95F3 LD (HL),A
95F4 DEC L
95F5 LD E,B
95F6 LD A,(DE)
95F7 LD (HL),A
95F8 DEC L
95F9 POP BC Transfer another 8 pixels
95FA LD E,C
95FB LD A,(DE)
95FC LD (HL),A
95FD EX AF,AF'
95FE LD L,A Restore HL
95FF LD A,H Save H in A then H--
9600 DEC H
Decrement the screen address.
9601 AND $0F Extract low four bits of row address
9603 JP NZ,psf_odd_continue If zero we'll need to handle it below, otherwise just loop
9606 LD A,H H += 16
9607 ADD A,$10
9609 LD H,A
960A LD A,L Decrement the high three bits of row address
960B SUB $20
960D LD L,A
960E JP NC,psf_odd_continue No carry, so finish scanline
9611 LD A,H H -= 16
9612 SUB $10
9614 LD H,A
9615 JP psf_odd_continue Loop back to psf_odd_continue
Prev: 949C Up: Map Next: 9618