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.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Super NES EMULATOR SE dev question

Post by Peperocket »

Hello,

I own a SUPER NES EMULATOR SE with Assembler, Linker and Debugger.

I modified a public code for assemble and link it. After assemble it without error, I found 2 issues when run it:

First : $4212 register never return $01 but $?2. How is possible to return 2 value when only bit 0, 6 an 7 can be set?

Second : When I CMP with $02 value in VBlank, only the first two conditions works (Red and Yellow BEQ) but not all others.

Please, look at the screenshot attachment. I can provide the ISX file is needed. Thanks for your help!

Here is the main file code :

Code: Select all

; bgcolor
; Press the A, B, X and Y buttons to change the background color. 

	file head.s
	file reg.s
	file set.s
	file val.s
	file init.s

bank0 group 0

	org $8000

Reset:

	Reset

Main:

    ; Set accumulator register to 8-bit
    sep #$20

    ; Set color 0 of palette 0 to white
    stz CGADD
    lda #$FF
    sta CGDATA
    lda #$7F
    sta CGDATA

    ; Enable the screen at full brightness
    lda #$0F
    sta INIDISP

    ; Enable VBlank and the joypad
    lda #(NMITIMEN_NMI_ENABLE | NMITIMEN_JOY_ENABLE)
    sta NMITIMEN

    ; Keep waiting for interrupts
w00 wai
    jmp w00

VBlank:
    ; Wait until the joypad input can be read
    lda #HVBJOY_JOYREADY
w01 and HVBJOY
    cmp #HVBJOY_JOYREADY
    bne w01

    ; Prepare to change color 0 of palette 0
    stz CGADD

    ; Reset accumulator register to 16-bit
    rep #$20
    
    on16a
    
    ; Jump to label Yellow if the A and Y buttons were pressed
    lda #(JOY_RED + JOY_GREEN)
    and JOY1
    cmp #(JOY_RED + JOY_GREEN)
    beq Yellow

    ; Jump to label Red if the A button was pressed
    lda #JOY_RED
    and JOY1
    cmp #JOY_RED
    beq Red

    ; Jump to label Yellow if the B button was pressed
    lda #JOY_YELLOW
    and JOY1
    cmp #JOY_YELLOW
    beq Yellow

    ; Jump to label Blue if the X button was pressed
    lda #JOY_BLUE
    and JOY1
    cmp #JOY_BLUE
    beq Blue

    ; Jump to label Green if the Y button was pressed
    lda #JOY_GREEN
    and JOY1
    cmp #JOY_GREEN
    beq Green

    lda #RDNMI
    
    off16a

    rti

Red:
    ; Set accumulator register back to 8-bit
    sep #$20
    
    ; Set color 0 of palette 0 to red
    lda #%00011111
    sta CGDATA
    lda #%00000000
    sta CGDATA

    rti

Green:
    ; Set accumulator register back to 8-bit
    sep #$20

    ; Set color 0 of palette 0 to green
    lda #%11100000
    sta CGDATA
    lda #%00000011
    sta CGDATA

    rti

Blue:
    ; Set accumulator register back to 8-bit
    sep #$20

    ; Set color 0 of palette 0 to blue
    lda #%00000000
    sta CGDATA
    lda #%01111100
    sta CGDATA

    rti

Yellow:
    ; Set accumulator register back to 8-bit
    sep #$20

    ; Set color 0 of palette 0 to yellow
    lda #%11111111
    sta CGDATA
    lda #%00000011
    sta CGDATA

    rti

EmptyHandler:

    rti
    
    end
Attachments
Screenshot
Screenshot
Last edited by Peperocket on Wed Apr 26, 2017 6:07 am, edited 1 time in total.
lint
Posts: 25
Joined: Thu May 15, 2008 4:05 am

Re: Super NES EMULATOR SE dev question

Post by lint »

Can you post the rom ? Might be easier to analyze ...

Also great to see that some owner of the SE devkit are really using it ! <3
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
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 answer.

Pseudo Instruction ON16A/ON16OFF notified the assembler that the effective data range is being processed in 16 bits.

I've attached the source and ISX files. Don't know if ISX is readed by other emulator however.

ISX is the output file from ISLK (linker) and include symbol value and data area definition table for debugger.
Attachments
20170426.zip
Source and ISX file
(6.26 KiB) Downloaded 197 times
lint
Posts: 25
Joined: Thu May 15, 2008 4:05 am

Re: Super NES EMULATOR SE dev question

Post by lint »

Is there a way to ouput something else than .isx format ?
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

I found an ISX to ROM converter and apply to ISX file but ROM doesn't seem to work on my Everdrive flash card.

http://www.inetmie.or.jp/~koh/inside/koh-tool.htm

I attached the converted rom, I hope it could help.
Attachments
PROG.ROM
Converted ROM from ISX file
(32 KiB) Downloaded 201 times
lint
Posts: 25
Joined: Thu May 15, 2008 4:05 am

Re: Super NES EMULATOR SE dev question

Post by lint »

in your code you have :
VBlank:
; Wait until the joypad input can be read
lda #HVBJOY_JOYREADY
w01 and HVBJOY
cmp #HVBJOY_JOYREADY
bne w01
Could you try to change that to :
VBlank:
; Wait until the joypad input can be read
lda HVBJOY
w01 and #HVBJOY_JOYREADY
cmp #HVBJOY_JOYREADY
bne w01
and change
HVBJOY_JOYREADY def $82
to
HVBJOY_JOYREADY def $81
wich is the right value.

I really suspect that the "and $4212" is not the correct way to check for value.
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
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 your help.

The initial HVBJOY_JOYREADY value was $01 but as you can see on screenshot, my $4212 register always return $?2 values ($C2, $82, $02, etc ...).

After making the change for check the value code, I got the same issue (only the two first colors (yellow and red) are display when I push joypad buttons, others don't work)

When I change the $81 value too for HVBJOY_JOYREADY, nothing is happend when I push joypad buttons.
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: Super NES EMULATOR SE dev question

Post by niconii »

Hang on, you have the software for the Emulator SE? Last I heard, people haven't been able to find that anywhere; is there a chance you could upload it somewhere?
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Super NES EMULATOR SE dev question

Post by lidnariq »

Peperocket wrote:The initial HVBJOY_JOYREADY value was $01 but as you can see on screenshot, my $4212 register always return $?2 values ($C2, $82, $02, etc ...).
Odds are good that the middle five bits are not explicitly driven, and that "2" is set because the last byte on the data bus was the $42. (And the other four bits are low for the same reason)

So, while you're ≈right that you should mask the result you loaded, that should look like "and #$c1" to get rid of the bits that aren't explicitly driven.

Actually, really, you should mask and compare only the bits that you care about. You don't care about hsync/vsync in this case, so why are you keeping them at all? Use the BIT instruction.
Peperocket
Posts: 20
Joined: Mon Nov 14, 2016 3:12 pm
Location: France

Re: Super NES EMULATOR SE dev question

Post by Peperocket »

Nicole wrote:Last I heard, people haven't been able to find that anywhere
Maybe they don't know the VUE Debugger software (Virtual Boy) hold SHVC/SNES abilities.

You can find here : http://www.planetvb.com/modules/hardware/?type=vue

Use the japanese VUE Developement Software version for Intelligent System SHVC Debugger and US version for SNES Emulator SE.

I can provide the Assembler/Linker/Debugger english version manual if needed.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Super NES EMULATOR SE dev question

Post by lidnariq »

Also, warning, from my own experience:

vblank NMI has enough time to start executing code before autoread starts, so you can't just wait for vblank, then wait for autoread to end.
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. I don't really understood what you mean when you're talking about "VBlank has enought time to start executing code before autoread start" because only thing I need to do in VBlank is reading joypad register and I can do only at the autoread start.

Do you think my VBlank handler is not reliable?
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: Super NES EMULATOR SE dev question

Post by niconii »

What they mean is, autoreading doesn't start until a little bit after vblank, so HVBJOY can show up as "ready" from the previous frame before it becomes "not ready". It's better to wait for it to not be ready, and then wait for it to be ready, to make sure you don't end up reading it before autoreading happens.
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Super NES EMULATOR SE dev question

Post by lidnariq »

Exactly.

Per anomie's documentation, there's 32-97 pixels after NMI before [$4212]&1 reads as 0. That's 128-388 master cycles, 13-64 instruction cycles, or enough time after the NMI starts for 1-20 instructions to execute.

So ... make sure you do something else in your NMI before you check HVBJOY. Doesn't have to be much. If you're not using an NMI (as I wasn't), wait for autoread to start and finish, instead of waiting for Vblank to start.
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 all for explanation. I have re-written the Joypad routine and NMI's one but at this time, the program is a little bit buggy since the left direction doesn't show anything and the right one show blue screen (it must be yellow). I don't really understand ... Could you help me please?

Code: Select all

; ***********************************************************
; *** Bgcolor 20170428 V0.1 							  ***        
; *** Press the U, D, L, R buttons to change the          ***
; *** background color.  					              ***
; ***********************************************************

	file head.s
	file reg.s
	file set.s
	file val.s
	file init.s

bank0 group 0

	org $8000

Reset:
	Reset

Main:
    ; Set accumulator register to 8-bit
    sep #$20

    ; Set color 0 of palette 0 to white
    stz CGADD
    lda #$FF
    sta CGDATA
    lda #$7F
    sta CGDATA

    ; Enable the screen at full brightness
    lda #$0F
    sta INIDISP

    ; Enable VBlank and the joypad
    lda #(NMITIMEN_NMI_ENABLE | NMITIMEN_JOY_ENABLE)
    sta NMITIMEN

	
; ***********************************************************
; ***  Main Code 										  ***        
; ***    												  ***
; ***            										  ***
; ***********************************************************
				      
MainLoop:
	wai
	
	lda JoypadLo					; Put pad register copied in Direct Page into Accumulator
	
	; Prepare to change color 0 of palette 0
    stz CGADD
	
Up:
	bit #JOYH_UP					 
	beq Down						 
	
    ; Set color 0 of palette 0 to red
    lda #%00011111
    sta CGDATA
    lda #%00000000
    sta CGDATA
	
Down:
	bit #JOYH_DOWN					 
	beq Left						 
	
    ; Set color 0 of palette 0 to green
    lda #%11100000
    sta CGDATA
    lda #%00000011
    sta CGDATA

Left: 
	bit JOYH_LEFT					 
	beq Right						 

    ; Set color 0 of palette 0 to blue
    lda #%00000000
    sta CGDATA
    lda #%01111100
    sta CGDATA

Right:
	bit JOYH_RIGHT					 
	beq TerminateControl	

    ; Set color 0 of palette 0 to yellow
    lda #%11111111
    sta CGDATA
    lda #%00000011
    sta CGDATA

TerminateControl: 	
	bra MainLoop					

	
; ***********************************************************
; *** NMI Interrupt 									  ***
; *** 											          ***
; ***********************************************************

NMI:
    php
	pha
	phx
	
w00: 
	lda HVBJOY						; status register, bit 0 joypad ready?
	and #$00			
	bne w00
	
w01: 
	lda HVBJOY						; status register, bit 0 joypad ready?
	and #$01			
	bne w01

	lda JOY1H 						; on stock le registre $4219 (status register) dans A (bystudlr)      
	sta JoypadLo					; pour le copier en page 0
	
	lda #RDNMI						; clear NMI flag
	
	plx
	pla
	plp
	
	rti

EmptyHandler:
    rti
    
    end


Post Reply