SNES Splatoon (How do I shot HiROM?)
Moderator: Moderators
Forum rules
- For making cartridges of your Super NES games, see Reproduction.
-
psycopathicteen
- Posts: 3001
- Joined: Wed May 19, 2010 6:12 pm
Re: SNES Splatoon (How do I shot HiROM?)
What was wrong with his avatar?
I wonder why there's all this fuss about ca65? Byuu has a very nice assembler on his website, it has none of that segment crap on it. It's pretty much tell the assembler what kind of ROM it is, and what CPU address to start the code at, and that's all.
I wonder why there's all this fuss about ca65? Byuu has a very nice assembler on his website, it has none of that segment crap on it. It's pretty much tell the assembler what kind of ROM it is, and what CPU address to start the code at, and that's all.
- Drew Sebastino
- Formerly Espozo
- Posts: 3496
- Joined: Mon Sep 15, 2014 4:35 pm
- Location: Richmond, Virginia
Re: SNES Splatoon (How do I shot HiROM?)
His Vblank routine is messed up:koitsu wrote:Otherwise you have some code that's stomping all over RAM contents (I peeked at the memory contents at one point -- they become a giant mess, usually filled with a lot of zeros), and it's not my job to figure out why.
Code: Select all
.proc VBlank
rep #$30 ;A=16, X/Y=16
pha
phx
phy
phd
phb
php
lda #$0000
tcd
----------------------- snip -----------------------
jsr get_input ;update joypad data
lda $4210 ;clear NMI Flag
plp
plb
pld
ply
plx
pla
rti
.endproc
Also worth noting is that the php / plp combo in the Vblank routine is completely useless (Edit: though not in this particular case actually, see above), as the processor status gets pushed onto the stack automatically as soon as NMI fires, and rti pulls it back along with K and PC.
Anyway, the bug must be lurking elsewhere in the code.
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Re: SNES Splatoon (How do I shot HiROM?)
Besides, I have a question, I see many people do pha / pla phx / plx during VBlank, I know what it is I use the Stack but is it really necessary for VBlank?
I mean, normally you don't execute code before calling the Vlank (unless you make a wai) or you made a loop to wait VBlank?
I mean, normally you don't execute code before calling the Vlank (unless you make a wai) or you made a loop to wait VBlank?
Re: SNES Splatoon (How do I shot HiROM?)
Well, you can wait for the VBlank ... But the VBlank can also occurs when you execute code in your main loop. You never know ... 
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
Re: SNES Splatoon (How do I shot HiROM?)
I understand, but In general I always look at the CPU , so my code is done fast enough before the VBlank activates. 
Re: SNES Splatoon (How do I shot HiROM?)
Can you guarantee that, even in a worst-case slowdown situation? It's only about a dozen or so cycles.Kannagi wrote:I understand, but In general I always look at the CPU , so my code is done fast enough before the VBlank activates.
Re: SNES Splatoon (How do I shot HiROM?)
Just don't be at 90% CPU (it is a good exercise).
After this depends on if it is true that my game loop is too long may be that I will reflect to a push / pop ( I worked first on the optimization).
After this depends on if it is true that my game loop is too long may be that I will reflect to a push / pop ( I worked first on the optimization).
-
psycopathicteen
- Posts: 3001
- Joined: Wed May 19, 2010 6:12 pm
Re: SNES Splatoon (How do I shot HiROM?)
You could disable the interrupts and re-enable it at the end of the frame, just to be on the safe side. You might get a black bar at the top from entering vblank late on busy frames, but it's still a lot more stable than interrupting an unfinished frame.
Too bad I can't do this because I run software sprite rotation code while it's waiting for vblank. I think I used to do this way, actually.
Too bad I can't do this because I run software sprite rotation code while it's waiting for vblank. I think I used to do this way, actually.
Re: SNES Splatoon (How do I shot HiROM?)
Yes, it is necessary. Think about this situation:Kannagi wrote:Besides, I have a question, I see many people do pha / pla phx / plx during VBlank, I know what it is I use the Stack but is it really necessary for VBlank?
I mean, normally you don't execute code before calling the Vlank (unless you make a wai) or you made a loop to wait VBlank?
VBlank routine (and is tied to NMI) does this
Code: Select all
lda #$1234
rti
Code: Select all
lda #$4444
sta $2122
Re: SNES Splatoon (How do I shot HiROM?)
I don't really understand your example but in my code $2122 is $44
(But $ 2122 must be written in the VBlank normally).
I changed the code a bit I did this:
Game loop :
VBlank :
And I didn't see change.
(But $ 2122 must be written in the VBlank normally).
I changed the code a bit I did this:
Game loop :
Code: Select all
lda $00
sta 2121
rep #$20
lda #$4444
sta $2122
sep #$20
;code game
Code: Select all
;code
rep #$20
lda #$1234
sep #$20
rti
Re: SNES Splatoon (How do I shot HiROM?)
The whole point is: If NMI should fire right in between the two instructions in the main code, then an immediate value (i.e., the number) of $1234 gets written to the destination (whatever that may be) instead of the intended immediate value of $4444.Kannagi wrote:I don't really understand your example but in my code $2122 is $44
(But $ 2122 must be written in the VBlank normally).
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Re: SNES Splatoon (How do I shot HiROM?)
What Ramsis said. In other words: I don't think you understand the fact that NMI can actually happen at any time (it's tied to VBlank in most cases, so you can "sort of" know when it's going to happen, but not definitively -- hence tepples asking the question).
When an interrupt occurs, the contents of all registers aren't saved or restored automatically. So in the example I gave, think about what happens. This is LITERALLY what goes on within the processor:
Now, if you save/restore the accumulator in your NMI routine, all is fine:
So, to recap: "is saving/restoring all the registers in an interrupt routine really needed?" The answer is YES.
I'm well aware that on 65816 you can use wai to pause/wait for NMI (VBlank) to end, but there's going to come a time where you've got code running in a main (non-VBlank) loop and NMI kicks in, and suddenly all your registers change for a reason not immediately apparent. So if your NMI routine uses A/X/Y registers, tweaks B, and/or changes register sizes, then you absolutely need to push A/X/Y/B/P and restore those before doing the rti, otherwise once returning control to your main loop (non-VBlank), previous register contents are trashed.
When an interrupt occurs, the contents of all registers aren't saved or restored automatically. So in the example I gave, think about what happens. This is LITERALLY what goes on within the processor:
Code: Select all
Main: lda #$1234 ; A=$1234
{NMI begins}
NMI: lda #$4444 ; A=$4444
NMI: rti
{NMI ends}
Main: sta $2122 ; $4444 is written to $2122
Code: Select all
Main: lda #$1234 ; A=$1234
{NMI begins}
NMI: pha
NMI: lda #$4444 ; A=$4444
NMI: pla ; A=$1234
NMI: rti
{NMI ends}
Main: sta $2122 ; $1234 is written to $2122
I'm well aware that on 65816 you can use wai to pause/wait for NMI (VBlank) to end, but there's going to come a time where you've got code running in a main (non-VBlank) loop and NMI kicks in, and suddenly all your registers change for a reason not immediately apparent. So if your NMI routine uses A/X/Y registers, tweaks B, and/or changes register sizes, then you absolutely need to push A/X/Y/B/P and restore those before doing the rti, otherwise once returning control to your main loop (non-VBlank), previous register contents are trashed.
Re: SNES Splatoon (How do I shot HiROM?)
Yes I understand, the VBlank, it can occur at any time?
Normally it does not come at the end of the final line ?
There is an example or VBlank comes before?
Normally it does not come at the end of the final line ?
There is an example or VBlank comes before?
-
psycopathicteen
- Posts: 3001
- Joined: Wed May 19, 2010 6:12 pm
Re: SNES Splatoon (How do I shot HiROM?)
When does it NMI besides vblank?