Too many sprites on a line flicker rather than vanish, the way Mario's do
Ten figures standing on one line, two more than the console can draw there. Play it and press Select to turn the order on and off: off, the same two are missing every frame; on, they all flicker. The program is 141 instructions in 341 bytes, built and checked the same way.
Play it here Change it on the desk The cartridge, to play anywhere that plays NES cartridges: flicker.nes
On the screen
The console draws eight sprites on a line
The picture chip looks through sprite memory as it draws each line and takes the first eight sprites it finds there; any more on that line are simply left out. A game that writes its sprites in the same order every frame loses the same ones every frame, and they are never seen. Super Mario Bros. moves an enemy’s sprites to a different place in sprite memory each frame, round a short cycle, so that if a line ever has too many, a different one goes missing each time and they all flicker instead. In the run we measured it never had more than eight on a line, so nothing was left out; the turning is there all the same. This cartridge shows the problem and the cure side by side.
| this cartridge | Super Mario Bros. | |
|---|---|---|
| most sprites on one line | 10 | 6 |
| sprites left out on that line each frame | 2 | 0 |
| figures never drawn, written in the same order every frame | 2 | it always turns |
| figures never drawn, with the order turning | 0 | 0 |
| frames before a figure's sprites are back in the same place in sprite memory | 10 | 3 |
As written
The part of the program this lesson is about. The whole program is a plain text file: flicker.s
;; Select turns the turning on or off; while it is on, each frame starts
;; one figure further on, round all ten.
order:
LDA $02
EOR #$FF
AND $01
AND #$20
BEQ same
LDA $40
EOR #$01
STA $40
same:
LDA $40
BEQ kept
INC $41
LDA $41
CMP #$0A
BCC kept
LDA #$00
STA $41
kept:
RTS
;; Each figure, two sprites (head over body), written into sprite memory
;; at its place in this frame's order: the figure written first takes
;; the first two sprites, and so on round.
figures:
LDX #$00
figure:
TXA
SEC
SBC $41
BCS placed
ADC #$0A
placed:
ASL A
ASL A
ASL A
TAY
LDA #$77
STA $0200,Y
LDA #$7F
STA $0204,Y
LDA #$06
STA $0201,Y
LDA #$07
STA $0205,Y
LDA #$00
STA $0202,Y
STA $0206,Y
LDA across,X
STA $0203,Y
STA $0207,Y
INX
CPX #$0A
BNE figure
RTSBefore this one: A status bar that stays still, the way Mario's does