| Prev: 6836 | Up: Map | Next: 68A1 |
683B: Scroll screen pixels vertically
|
Core vertical scroll engine. Scrolls all screen content by copying pixel data between screen lines. Called every frame from render_plane_and_terrain.
|
||||
|
The algorithm processes 144 screen lines ($8F to $00), each copying 32 bytes via LDDR. This creates the vertical scroll effect by shifting pixel data from source to destination addresses, where the offset between source/destination is determined by current speed.
Counter bits 7-6 select screen memory banks: bit 7 adds $1000, bit 6 adds $0800 to the base address. This allows 4 banks of screen patterns (64 lines each × 4 = 256 total pattern lines).
Performance note: This is the game's hottest code path, executing 144 iterations × ~50 frames/sec. The inner loop accounts for ~300M+ executions per session.
|
||||
| scroll_screen | 683B | LD A,$8F | Initialize line counter to $8F (143 lines to process). | |
| scroll_screen_line | 683D | LD ($5EF9),A | ||
| 6840 | AND $3F | Mask lower 6 bits for table index (0-63). | ||
| 6842 | LD HL,$5B00 | Look up destination address in table at screen_row_table. | ||
| 6845 | LD C,A | |||
| 6846 | SLA C | |||
| 6848 | LD B,$00 | |||
| 684A | ADD HL,BC | |||
| 684B | LD E,(HL) | |||
| 684C | INC HL | |||
| 684D | LD D,(HL) | |||
| 684E | EX DE,HL | |||
| 684F | LD A,($5EF9) | Apply bank offset based on bits 7-6. | ||
| 6852 | BIT 7,A | |||
| 6854 | CALL NZ,add_screen_bank_1000 | |||
| 6857 | BIT 6,A | |||
| 6859 | CALL NZ,add_screen_bank_800 | |||
| 685C | PUSH HL | Save destination pointer. | ||
| 685D | LD HL,$5B00 | Look up source address (counter - speed). | ||
| 6860 | LD A,($5F64) | |||
| 6863 | LD B,A | |||
| 6864 | LD A,($5EF9) | |||
| 6867 | SUB B | |||
| 6868 | AND $3F | |||
| 686A | LD B,$00 | |||
| 686C | LD C,A | |||
| 686D | SLA C | |||
| 686F | ADD HL,BC | |||
| 6870 | LD E,(HL) | |||
| 6871 | INC HL | |||
| 6872 | LD D,(HL) | |||
| 6873 | EX DE,HL | |||
| 6874 | LD A,($5F64) | Apply bank offset to source pointer. | ||
| 6877 | LD D,A | |||
| 6878 | LD A,($5EF9) | |||
| 687B | SUB D | |||
| 687C | BIT 7,A | |||
| 687E | CALL NZ,add_screen_bank_1000 | |||
| 6881 | BIT 6,A | |||
| 6883 | CALL NZ,add_screen_bank_800 | |||
| 6886 | POP DE | Copy 32 bytes from source to destination (LDDR). | ||
| 6887 | LD BC,$0020 | |||
| 688A | LDDR | |||
| 688C | LD A,($5EF9) | If counter reached 0, jump to clear_top_rows to clear top rows. | ||
| 688F | DEC A | |||
| 6890 | CP $00 | |||
| 6892 | JP Z,clear_top_rows | |||
| 6895 | CP $7F | At counter $7F, render plane sprite mid-scroll. | ||
| 6897 | CALL Z,render_plane | |||
| 689A | LD A,($5EF9) | Decrement and continue loop. | ||
| 689D | DEC A | |||
| 689E | JP scroll_screen_line | |||
| Prev: 6836 | Up: Map | Next: 68A1 |