Rooms that slide in the way Zelda's do
The square in a grid of rooms, seen from above. The picture stands still while it walks; out of the left or right side, the next room slides in and carries it along. The program is 354 instructions in 759 bytes, built and checked the same way.
Play it here The cartridge, to play anywhere that plays NES cartridges: rooms.nes
On the screen
A room at a time
Watching The Legend of Zelda’s memory showed one byte that changes each time Link leaves a screen: it went down by 1 for a step left and by 16 for a step up, so the land is a grid 16 rooms wide, numbered along its rows. At the edge, the picture slides a whole screen at a steady rate and Link is carried with it. This cartridge keeps a room number the same way and slides the same way. How each draws the room that is coming in is where they differ, and the table says how, from the log of every write each made to the picture chip.
| this cartridge | The Legend of Zelda | |
|---|---|---|
| the room's number, before and after a step left | 119 to 118 | 119 to 118 |
| frames from the number changing to the picture moving | 1 | 30 |
| frames the slide takes | 64 | 64 |
| pixels moved, and pixels a frame | 256, 4 a frame | 256, 4 a frame |
| written before the picture moves | none | 23 rows of 32 tiles across, 2 rows of 24 tiles across |
| written while it slides | 32 columns of 30 tiles down | 32 columns of 22 tiles down, 1 row of 24 tiles across |
| frame of the slide the first column is written in | 1 | 32 |
| frames between columns | 2 | 1 |
Where the two part ways
The Legend of Zelda writes 23 rows of 32 tiles across, 2 rows of 24 tiles across before the picture moves, which takes it 30 frames, and writes nothing for the first half of the slide; its columns come from frame 32 of the slide on, one a frame. This cartridge writes nothing beforehand and draws the incoming room through the whole slide, a column every second frame, each just ahead of the edge coming into sight. What The Legend of Zelda’s rows are for has not been read yet.
Not yet
Up and down stop at the edge here: the slide is across only. In the game a step up slides the screen down; that is the next cut.
As written
The part of the program this lesson is about. The whole program is a plain text file: rooms.s
;; Sliding: on every second step a column of the new room, the next to
;; come into sight (from its right side going left, from its left going
;; right); then the scroll moves 4 pixels toward the new room, the square
;; goes with the picture, and after 64 steps the new room is the one on
;; the screen.
slide:
LDA $34
AND #$01
BNE stepped
LDA $34
LSR A
LDX $32
BNE fromleft
EOR #$1F
fromleft:
JSR prepcol
LDA $35
EOR #$01
ASL A
ASL A
ORA $39
STA $39
LDA #$01
STA $38
stepped:
LDA $32
BNE east
SEC
LDA $36
SBC #$04
STA $36
LDA $37
SBC #$00
AND #$01
STA $37
LDA $11
CMP #$EC
BCS carried
CLC
ADC #$04
STA $11
JMP carried
east:
CLC
LDA $36
ADC #$04
STA $36
LDA $37
ADC #$00
AND #$01
STA $37
LDA $11
CMP #$04
BCC carried
SEC
SBC #$04
STA $11
carried:
INC $34
LDA $34
CMP #$40
BNE sliding
LDA $35
EOR #$01
STA $35
STA $37
LDA #$00
STA $36
STA $31
sliding:
RTS