Zim*_*Zim -2 assembly initialization 6502 reset
; We now have about 30,000 cycles to burn before the PPU stabilizes.
; One thing we can do with this time is put RAM in a known state.
; Here we fill it with $00, which matches what (say) a C compiler
; expects for BSS. Conveniently, X is still 0.
txa
@clrmem:
sta $000,x
sta $100,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x ; Remove this if you're storing reset-persistent data
; We skipped $200,x on purpose. Usually, RAM page 2 is used for the
; display list to be copied to OAM. OAM needs to be initialized to
; $EF-$FF, not 0, or you'll get a bunch of garbage sprites at (0, 0).
inx
bne @clrmem
Run Code Online (Sandbox Code Playgroud)
基本上它似乎做的是用0增加所有上述地址,增加x,跳回标签的开头,用1填充所有地址,再次增加x,并且它一遍又一遍地发生直到BNE为假(所以如果Zero标志是1).所以基本上当INX发生时,当X为0xFF时,X将为0(对吗?),而BNE将为假,它将停止分支并继续执行程序.我了解其余的大多数,但为什么它用看似随机的内存地址做到这一点?为什么0x000,0x100,0x200等?为什么这个循环发生256次?之后的代码显示程序正在等待第二个VBLANK(NES PPU相关),我有点得到,但256时间循环是什么?它说它需要燃烧大约30k周期,但为什么这样呢?
注意:结果我在阅读代码时没有注意,当我问这个问题时,我忘记了STA指令做了一秒钟.以上部分信息不正确.
仔细查看STA(Store Accumulator)指令.特定
sta $300,x
Run Code Online (Sandbox Code Playgroud)
它正在存储累加器$300+x,并x正在递增..
因此,在您执行的连续迭代中:
Accumulator -> $300+00
Accumulator -> $300+01
Accumulator -> $300+02
...
Accumulator -> $300+FF
Run Code Online (Sandbox Code Playgroud)
为什么需要这样做:由于存在所需的等待时间,为什么不将内存置于"已知状态".这有助于消除由于以后的错误导致的不可预测的行为.例如,在C:中,始终具有值0(null)的未初始化指针可能会有所帮助.
| 归档时间: |
|
| 查看次数: |
707 次 |
| 最近记录: |