Points of Required Attention™
Smaghetti, a new Super Mario Advance 4 editor, is currently in development! Check out the thread HERE!

Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,314,558
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 03-28-24 11:49 PM
Guest: Register | Login

0 users currently in ROM Hacking | 3 guests

Main - ROM Hacking - Question about Endless Loop New thread | New reply


RetroRain
Posted on 03-05-12 06:39 PM Link | Quote | ID: 150346


Fuzz Ball
Level: 66

Posts: 572/994
EXP: 2432458
Next: 29393

Since: 09-30-07

Last post: 1906 days
Last view: 929 days
I was taking a look at the Super Mario Bros. Disassembly. And I noticed this once before when I was looking at a tutorial to program a NES demo. Is the endless loop the very last line of code that is run? Because if it is not, I don't see how all of the code after it can run if it is constantly stuck in that loop. I just wanted to validate that logic.



Start:
sei ;pretty standard 6502 type init here
cld
lda #%00010000 ;init PPU control register 1
sta PPU_CTRL_REG1
ldx #$ff ;reset stack pointer
txs
VBlank1: lda PPU_STATUS ;wait two frames
bpl VBlank1
VBlank2: lda PPU_STATUS
bpl VBlank2
ldy #ColdBootOffset ;load default cold boot pointer
ldx #$05 ;this is where we check for a warm boot
WBootCheck: lda TopScoreDisplay,x ;check each score digit in the top score
cmp #10 ;to see if we have a valid digit
bcs ColdBoot ;if not, give up and proceed with cold boot
dex
bpl WBootCheck
lda WarmBootValidation ;second checkpoint, check to see if
cmp #$a5 ;another location has a specific value
bne ColdBoot
ldy #WarmBootOffset ;if passed both, load warm boot pointer
ColdBoot: jsr InitializeMemory ;clear memory using pointer in Y
sta SND_DELTA_REG+1 ;reset delta counter load register
sta OperMode ;reset primary mode of operation
lda #$a5 ;set warm boot flag
sta WarmBootValidation
sta PseudoRandomBitReg ;set seed for pseudorandom register
lda #%00001111
sta SND_MASTERCTRL_REG ;enable all sound channels except dmc
lda #%00000110
sta PPU_CTRL_REG2 ;turn off clipping for OAM and background
jsr MoveAllSpritesOffscreen
jsr InitializeNameTables ;initialize both name tables
inc DisableScreenFlag ;set flag to disable screen output
lda Mirror_PPU_CTRL_REG1
ora #%10000000 ;enable NMIs
jsr WritePPUReg1
EndlessLoop: jmp EndlessLoop ;endless loop, need I say more?


____________________
My YouTube Channel

never-obsolete
Posted on 03-05-12 08:15 PM (rev. 3 of 03-05-12 08:21 PM) Link | Quote | ID: 150348


Rat
Level: 24

Posts: 82/96
EXP: 74326
Next: 3799

Since: 02-22-07
From: Phoenix, AZ

Last post: 2567 days
Last view: 2567 days
The loop is broken when the nmi is triggered at the start of vblank. From my understanding of SMB, all game logic is run in the nmi handler and the “main“ thread is just a loop. There's a thread over at nesdev about the pros and cons of this method versus others.

RetroRain
Posted on 03-07-12 07:20 AM (rev. 2 of 03-07-12 07:21 AM) Link | Quote | ID: 150370


Fuzz Ball
Level: 66

Posts: 574/994
EXP: 2432458
Next: 29393

Since: 09-30-07

Last post: 1906 days
Last view: 929 days
Thanks never-obsolete.

____________________
My YouTube Channel

Main - ROM Hacking - Question about Endless Loop New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.019 seconds. (340KB of memory used)
MySQL - queries: 47, rows: 69/70, time: 0.016 seconds.