NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectBizarre Starting Code in Kirby's Adventure new  
Posted bybeneficii
Posted on7/17/03 06:47 AM
From IP68.18.219.125  



Kirby's Adventure, which is Mapper #4 or MMC3, starts off like this:

sei
lda #$00
sta $8000
jmp $c000

$C000:
lda #$08
sta $2000
lda #$18
sta $2001
lda #$00
sta $4010
lda #$40
sta $4017 ; ??? WTF ???
sta $e000
lda $2002
lda #$10
sta $67

label1: ;??? WTF ???
tax ;??? WTF ???
sta $2006
sta $2006
eor #$10
dex
bne label1 ;??? WTF ???

Can anyone explain this bizarre code? Thanks. ^_^






SubjectRe: Bizarre Starting Code in Kirby's Adventure  
Posted bybeneficii
Posted on7/17/03 06:57 AM
From IP68.18.219.125  



Here's more (cont'd from where last left off):

stx $2001

wait_vblank:
lda $2002
bpl wait_vblank

wait_novblank:
lda $2002
bmi wait_novblank

wait_vblank1:
lda $2002
bpl wait_vblank1

wait_novblank1:
lda $2002
bmi wait_novblank ;??? WTF ???

Can't really explain it. That's just how it is.






SubjectRe: Bizarre Starting Code in Kirby's Adventure new  
Posted bybeneficii
Posted on7/17/03 08:21 AM
From IP68.18.219.125  



More (starting from the last):

cld
ldx #$ff
txs
lda #$80
sta $a001 ; enabling SaveRAM
jsr $d805

$d805:
sta $10
sty $12
pla
sta $16
pla
sta $17
lda $16
clc
adc #$03
tay
lda $17
adc #$00
pha
tya
pha
ldy #$01
lda [$16], y
sta $6038
iny
lda [$16], y
sta $6039
cmp #$80

That's it for now!






SubjectRe: Bizarre Starting Code in Kirby's Adventure new  
Posted byASMGuy
Posted on7/17/03 1:29 PM



This is from NES101.html by Michael Martin:

...
Then there's $4017.

$4017 is a sound initialization register. Only bits 6 and 7 of $4017 are important, when you write to it. Bit 6 controls Sound IRQs: if bit 6 is set, no sound IRQs will occur. If it's clear (which is the default), interrupts to a sound routine will occur at the end of every audio frame. Audio and video frames have slightly different lengths, apparently; bit 7 lets you get some control about how different they are. Writing a 1 into bit 7, then never touching $4017 after that makes envelopes decay about 20% more slowly. Writing a 1 into bit 7 every NMI will produce similar decay rates to cleared 7 (probably the 'normal' decay rate) but timed effects like slides and fades won't happen until later in the frame - this will allow you to do more advanced sound computation without glitching the sound.

If an IRQ goes off, you must acknowledge it, either by writing $4017 or reading $4015. If you don't, another IRQ will be generated after one instruction. This is rarely what you want.

We don't care about any of that, but we'd rather not have any IRQs. We'll write a $40 into $4017 as well.

init'sound:
; initialize sound hardware
lda #$01
sta $4015
lda #$00
sta $4001
lda #$40
sta $4017
rts
...

I haven't seen that in any other docs, but I could of just as
easily plain missed it.






SubjectRe: Bizarre Starting Code in Kirby's Adventure new  
Posted bybeneficii
Posted on7/17/03 4:30 PM
From IP68.18.219.125  



Ah OK.






SubjectRe: Bizarre Starting Code in Kirby's Adventure new  
Posted bymcmartin
Posted on7/17/03 5:50 PM
From IP128.12.190.38  



The NESSOUND.txt file describes the effects of writing to $4017 in full detail. (It didn't while NES 101 was being written; that document seems to have been updated fairly recently.)

--Michael




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo