Page 1 of 1
Scrolling on the SNES?
Posted: Tue Apr 22, 2014 10:47 pm
by DoNotWant
Hey!
I'm having trouble getting scrolling to work on the SNES.
I have looked through "Walker.asm" from neviksti's SNES-starterkit, and as far as I see, you only
have to update 2 variables in RAM in your moving routine and then write those coordinates to $210d and $210e in the NMI.
This is basically what I do for up/down/left/right:
Code: Select all
HandleInput:
php
sep #{MEM}
rep #{XY}
lda {joy1_held} + 1
and #{JOY_UP}
beq .notUp
lda {player1_y}
sec
sbc #$01
sta {player1_y}
lda {camera_y}
sec
sbc #$02
sta {camera_y}
lda {player1_direction}
and #%11111101
sta {player1_direction}
.notUp:
lda {joy1_held} + 1
and #{JOY_DOWN}
beq .notDown
e.t.c.
and at the end of the NMI I have:
Code: Select all
lda <{camera_x}
sta $210d
lda <{camera_x} + 1
sta $210d
lda <{camera_y}
sta $210e
lda <{camera_y} + 1
sta $210e
jsr ReadJoypad
lda $4210
plp
ply
plx
pla
rti
Now, my sprite is moving around as it should, but I get no scrolling at all. I looked at it in the no$sns VRAM viewer, and my 64*64 map is loaded as it should be, and the camera_n variables are updated in RAM appropriately.
Thanks!
Re: Scrolling on the SNES?
Posted: Wed Apr 23, 2014 5:19 am
by doppelganger
Is it possible to check the PPU regs in no$snes? If it is, you should check to see if the scroll registers are being written properly. Since you have only posted a little bit of the NMI, I can't say for certain what's wrong with the code.
Re: Scrolling on the SNES?
Posted: Wed Apr 23, 2014 5:39 am
by DoNotWant
Yupp, found a way to check the registers, and it seems like they are not updated at all.
This is all of the NMI:
Code: Select all
NMI:
pha
phx
phy
php
sep #{MEM}
stz $2102
stz $2103
stz $4300
lda #$04
sta $4301
stz $4302
stz $4303
stz $4304
lda #$20
sta $4305
lda #$02
sta $4306
lda #$01
sta $420B
lda <{camera_x}
sta $210d
lda <{camera_x} + 1
sta $210d
lda <{camera_y}
sta $210e
lda <{camera_y} + 1
sta $210e
jsr ReadJoypad
lda $4210
plp
ply
plx
pla
rti
Main loop:
Code: Select all
Forever:
wai
jsr HandleInput
jmp Forever
HandleInput:
Code: Select all
HandleInput:
php
sep #{MEM}
lda {joy1_held} + 1
and #{JOY_UP}
beq .notUp
lda {player1_y}
sec
sbc #$01
sta {player1_y}
lda {camera_y}
sec
sbc #$02
sta {camera_y}
lda {player1_direction}
and #%11111101
sta {player1_direction}
.notUp:
lda {joy1_held} + 1
and #{JOY_DOWN}
beq .notDown
lda {player1_y}
clc
adc #$01
sta {player1_y}
lda {camera_y}
clc
adc #$02
sta {camera_y}
lda {player1_direction}
ora #%00000010
sta {player1_direction}
.notDown:
lda {joy1_held} + 1
and #{JOY_LEFT}
beq .notLeft
lda {player1_x}
sec
sbc #$01
sta {player1_x}
lda {camera_x}
sec
sbc #$02
sta {camera_x}
lda {player1_direction}
and #%11111110
sta {player1_direction}
.notLeft:
lda {joy1_held} + 1
and #{JOY_RIGHT}
beq .notRight
lda {player1_x}
clc
adc #$01
sta {player1_x}
lda {camera_x}
clc
adc #$02
sta {camera_x}
lda {player1_direction}
ora #%00000001
sta {player1_direction}
.notRight:
plp
rts
Thanks!
Re: Scrolling on the SNES?
Posted: Wed Apr 23, 2014 5:45 pm
by psycopathicteen
It could be the joypad reading that isn't working. Try making it scroll automatically. If it works automatically, then it must be a problem with the joypad.
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 4:54 am
by DoNotWant
I doubt that since the sprite moves around, and camera_x and camera_y is updated in RAM. It won't write to the PPU registers for some reason. Anyway, here it is:
Code: Select all
ReadJoypad:
php
-
lda $4212 // When 4212.b0 is reset, the joypad is ready.
and #$01
bne -
rep #({MEM} | {XY})
ldx {joy1_raw}
lda $4218
sta {joy1_raw}
txa
eor {joy1_raw}
and {joy1_raw}
sta {joy1_press}
txa
and {joy1_raw}
sta {joy1_held}
sep #{MEM}
ldx #$0000
lda $4016
bne +
stx {joy1_raw}
stx {joy1_press}
stx {joy1_held}
+
plp
rts
Thanks!
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 9:18 am
by psycopathicteen
I don't know as much about bass, but what is the difference between "<{camera_x}" and "{camera_x}" syntax?
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 10:01 am
by DoNotWant
< byte, > word, ^ long(24-bit).
Like lda.b or sta.w in WLA.
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 10:04 am
by koitsu
Then that brings into question why you're using < in some places where 8-bit accumulator operations are occurring, but not in others (and where others look like you might be expecting 16-bit behaviour but at a glance your accumulator is still 8-bit (I see no rep #$20).
What you really need to do is look at a generated assembly listing from your assembler to see what your code is actually assembling into. You might be surprised by what you find.
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 10:57 am
by DoNotWant
Sorry, I forgot to mention that I did fix HandleInput: to use 16-bit indexing registers and increment the camera in X. Damn, it was those < things, it works now. I did remove them at one point to see if that was it but it wouldn't work then either. Must have been something else at that point messing things up. Thanks for the help!
Edit: I did check in a hex editor before trying to remove them again, and I did see that the ldas fetched data from places it shouldn't. I'll never forget to check in a hex editor before asking for help.
Re: Scrolling on the SNES?
Posted: Thu Apr 24, 2014 5:16 pm
by koitsu
No need for a hex editor if your assembler can just generate a listing. I just checked the bass documentation (for v06) and it doesn't appear to have this capability, so yeah, manually checking the bytes is one of your choices.