Super NES EMULATOR SE dev question

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: Super NES EMULATOR SE dev question

Post by niconii »

You forgot a # before JOYH_LEFT and JOYH_RIGHT.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Well seen !!! Thank you very much Nicole, It's working without problem now!

Thank you ALL for the help!

I attached the source and the binary files for those interested by.
Attachments
20170428.zip
Change background color with D-Pad. Source and binaries files included
(6.76 KiB) Downloaded 171 times
UnDisbeliever
Posts: 123
Joined: Mon Mar 02, 2015 1:11 am
Location: Australia (PAL)
Contact:

Re: Super NES EMULATOR SE dev question

Post by UnDisbeliever »

Peperocket wrote:I attached the source and the binary files for those interested by.
Nice, It's great to see another person try their hand at programming a Super Nintendo.


I've tried running your ROM on my PAL SNES and it only showed a white screen.
Tracing the code through bsnes-plus I discovered your NMI routine is broken. The two and NMITIMEN_JOY_ENABLE lines should be and #NMITIMEN_JOY_ENABLE. The code worked on your system because memory address $000001 had bits 7, 6 or 0 set. If all those bits were clear then NMI would never end.



Besides that bug, I have the following observations about your code. I apologise in advance for my tone, but I believe these sort of issues should be caught early.

1) Your storing and retrieving JOYH from JoypadLo, not JoypadHi.

2) The mainloop is setting CGRAM colour 1 to Blue when down is pressed.

3) You should remove the # from the following line:

Code: Select all

    lda #RDNMI
4) Your register push/pop code for NMI is incomplete. It only works because your used an 8 bit accumulator and never touched bits 8-15 of A in the program.

The following code correctly saves the CPU state, resets DB/DP to 0, and restores the CPU state for an Interrupt Service Routine. We do not need to push/pop the P register, as the 65816 will push P to the stack when an interrupt is triggered.

Code: Select all

NMI:
; save CPU state
    rep     #$30
on16i
on16a
    pha
    phx
    phy
    phd
    phb

; set DB to 0
    phk
    plb

; set DP to 0
    lda   #0
    tcd


; set a/x size
; code goes here


; restore CPU state
    rep     #$30
on16i
on16a
    plb
    pld
    ply
    plx
    pla

    rti
Peperocket wrote:$4212 register never return $01 but $?2. How is possible to return 2 value when only bit 0, 6 an 7 can be set?
Only bits 0, 6, 7 of register $4212 are set/cleared, the unmaped bits will contain the previous value of the data bus. See https://wiki.superfamicom.org/snes/show/Open+Bus for more details


---
EDIT: Removed clear decimal flag code from NMI ISR. The 65816 clears the decimal flag when an interrupt is triggered.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Hello,

Thank you for your answer.
Tracing the code through bsnes-plus I discovered your NMI routine is broken. The two and NMITIMEN_JOY_ENABLE lines should be and #NMITIMEN_JOY_ENABLE. The code worked on your system because memory address $000001 had bits 7, 6 or 0 set. If all those bits were clear then NMI would never end.
What a stupid error!
1) Your storing and retrieving JOYH from JoypadLo, not JoypadHi.

2) The mainloop is setting CGRAM colour 1 to Blue when down is pressed.

3) You should remove the # from the following line:
Code:
lda #RDNMI
You right. I don't understand the second point however. Could you explain?
4) Your register push/pop code for NMI is incomplete. It only works because your used an 8 bit accumulator and never touched bits 8-15 of A in the program.

The following code correctly saves the CPU state, resets DB/DP to 0, and restores the CPU state for an Interrupt Service Routine. We do not need to push/pop the P register, as the 65816 will push P to the stack when an interrupt is triggered.
Code:
NMI:
; save CPU state
rep #$30
on16i
on16a
pha
phx
phy
phd
phb

; set DB to 0
phk
plb

; set DP to 0
lda #0
tcd


; set a/x size
; code goes here


; restore CPU state
rep #$30
on16i
on16a
plb
pld
ply
plx
pla

rti
Great, thank you! What is the assembler/linker you use? If you use Intelligent System stuff, how do you generate a usable snes rom because I would like put my works on a flash card because I only output ISX files from Linker?
Only bits 0, 6, 7 of register $4212 are set/cleared, the unmaped bits will contain the previous value of the data bus. See https://wiki.superfamicom.org/snes/show/Open+Bus for more details
Ohhh ... I understand now ...
EDIT: Removed clear decimal flag code from NMI ISR. The 65816 clears the decimal flag when an interrupt is triggered.
Right, I read this yesterday.
UnDisbeliever
Posts: 123
Joined: Mon Mar 02, 2015 1:11 am
Location: Australia (PAL)
Contact:

Re: Super NES EMULATOR SE dev question

Post by UnDisbeliever »

Peperocket wrote:I don't understand the second point however. Could you explain?
When down is pressed it loads green into CGDATA (at color 0) and the Accumulator is set to 3. The Accumulator (3) is then bit tested with JOYH_LEFT (2), which always passes, so blue is also loaded into CGDATA (at colour 1).

To fix this you need to add an exit branch to each direction test after setting CGDATA. To demonstrate:

Code: Select all

Up:
    bit #JOYH_UP                                    ; on compare bit a bit avec haut
    beq Down                                                ; si non egal, passe au prochain boutton
	
    ; Set color 0 of palette 0 to red
    lda #%00011111
    sta CGDATA
    lda #%00000000
    sta CGDATA

    bra EndJoypadTest

Down:
; ...
; Add `bra EndJoypadTest` to Down and Left tests
; ...

NotRight:
EndJoypadTest:
Peperocket wrote:Great, thank you! What is the assembler/linker you use?
No problem. I've used both ca65/ld65 and byuu's bass assembler for my SNESdev projects.
Peperocket wrote:If you use Intelligent System stuff, how do you generate a usable snes rom because I would like put my works on a flash card because I only output ISX files from Linker?
I just used iscv.exe to convert PROG.ISX to PROG.ROM, renamed PROG.ROM to PROG.SFC and it worked fine on my Quickdev16. I don't see why it shouldn't work on a flash cart.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Thank you for these clear explanation. I tried to convert once again ISX file to ROM/SFC but it always fail running on my SD2SNES.

I attached the updated code and ISX/ROM files. Could you confirm it works on your QUICKDEV?
Attachments
20170429.zip
(7.63 KiB) Downloaded 174 times
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: Super NES EMULATOR SE dev question

Post by niconii »

Your ROM file does seem fine, though the header claims the ROM is 256 KB when it's actually 32 KB, and the checksums haven't been set.

My guess is that the ROM size is the problem, and it should be zero-padded out to 256 KB. I don't own a SD2SNES, but at least on the Super EverDrive, I've had problems with ROMs that were too small in the past.

Correct checksums would also be nice, but I can't imagine it's the problem here. So many ROM hacks and homebrew games don't bother, so I doubt the SD2SNES would check them, and the SNES itself doesn't care about the header at all besides the vectors.
User avatar
ikari_01
Posts: 141
Joined: Sat Jul 04, 2009 2:28 pm
Location: Wunstorf, Germany

Re: Super NES EMULATOR SE dev question

Post by ikari_01 »

HEAD.S specifies Mode 21 (HiROM) but the ROM is only half a bank in size and expects to be loaded from $8000. Try changing

Code: Select all

		db      MODE_21                                         ; D5 - map mode
to

Code: Select all

		db      MODE_20                                         ; D5 - map mode
in HEAD.S.

Edit: still doesn't work, it gets stuck at the white screen... I shall take a closer look.
UnDisbeliever
Posts: 123
Joined: Mon Mar 02, 2015 1:11 am
Location: Australia (PAL)
Contact:

Re: Super NES EMULATOR SE dev question

Post by UnDisbeliever »

Peperocket wrote:I attached the updated code and ISX/ROM files. Could you confirm it works on your QUICKDEV?
The updated PROG.ROM works perfectly on my Quickdev16.

ikari_01 wrote:HEAD.S specifies Mode 21 (HiROM) but the ROM is only half a bank in size and expects to be loaded from $8000....
I looked at the SD2SNES source code and discovered that SD2SNES uses the map mode byte from the ROM Header to determine which memory map to use.

I did not notice the incorrect header because bsnes/higan/snes9x uses the location of the header in the ROM file to determine the memory map.
User avatar
ikari_01
Posts: 141
Joined: Sat Jul 04, 2009 2:28 pm
Location: Wunstorf, Germany

Re: Super NES EMULATOR SE dev question

Post by ikari_01 »

True, I only fall back to the header location if the header data is found to be unusable (invalid map mode byte). I guess I could add in another little plausibility check to match the map byte against the header location.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Hello all!

After changing header adress to $7FB0 and mode 20, rom works on my sd2snes.

I don't understand why mode 21 doesn't work however ...
Doriphor
Posts: 3
Joined: Mon May 29, 2017 1:17 pm

Re: Super NES EMULATOR SE dev question

Post by Doriphor »

I've been trying to setup the tool chain for SNES programming, and I'd love the manuals in English! (Also a manual for VUCC would be nice, if possible...)
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Hello,

Because Nintendo legal issue, I don't know if I can attached the manual here.

Is it possible?
Doriphor
Posts: 3
Joined: Mon May 29, 2017 1:17 pm

Re: Super NES EMULATOR SE dev question

Post by Doriphor »

Peperocket wrote:Hello,

Because Nintendo legal issue, I don't know if I can attached the manual here.

Is it possible?
I honestly don't know myself. All I know, is that Nintendo doesn't seem to have bothered about all the other VUE Debugger floppies that have been released in the past.

If you feel uncomfortable about this, I completely understand!
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Super NES EMULATOR SE dev question

Post by lidnariq »

At least, in the past, there was one takedown request for the SNES dev manuals, and Koitsu has been justifiably jumpy ever since.

If that's what you're talking about. They're really east to search google for.
Post Reply