Simple Cursor Menu For a SNES MultiCart

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

Hi Guys

I made this menu using Byuu Bass
I using BG mode 3 and using a Tile in BG1 as the cursor and the BG

But when i press the Down Button, the cursor go full down or full up when i press up

My question is, how i register 1 press then release and press again?

That is the part of the code

//------------------------------------------------------------------------------------------------

Pos1Loop:
LoadLOVRAM(BLANK, $FA84, 1, 1) // Load Text To VRAM Lo Bytes
LoadLOVRAM(CURSOR, $FA44, 1, 1) // Load Text To VRAM Lo Bytes
WaitNMI() // Wait For Vertical Blank

DownA:
ReadJOY({JOY_DOWN}) // Test DOWN Button
beq StartA // "DOWN" Not Pressed? Branch Down
jmp Pos2Loop

StartA:
ReadJOY({JOY_START}) // Test LEFT Button
beq Pos1Loop // "START" Not Pressed? Branch Down
jml $008000


Pos2Loop:
LoadLOVRAM(BLANK, $FA44, 1, 1) // Load Text To VRAM Lo Bytes
LoadLOVRAM(CURSOR, $FA84, 1, 1) // Load Text To VRAM Lo Bytes
WaitNMI() // Wait For Vertical Blank

UpB:
ReadJOY({JOY_UP}) // Test DOWN Button
beq DownB // "DOWN" Not Pressed? Branch Down
jmp Pos1Loop

DownB:
ReadJOY({JOY_DOWN}) // Test DOWN Button
beq StartB // "DOWN" Not Pressed? Branch Down
jmp Pos3Loop

StartB:
ReadJOY({JOY_START}) // Test LEFT Button
beq Pos2Loop // "START" Not Pressed? Branch Down
stz.w REG_CGADD // $2121: CGRAM Address
lda.b #%00011111 // Load Black Colour Lo Byte
sta.w REG_CGDATA // $2122: CGRAM Data Write Lo Byte
lda.b #%00000000 // Load Black Colour Hi Byte
sta.w REG_CGDATA // $2122: CGRAM Data Write Hi Byte

Pos3Loop:
LoadLOVRAM(BLANK, $FA84, 1, 1) // Load Text To VRAM Lo Bytes
LoadLOVRAM(CURSOR, $FAC4, 1, 1) // Load Text To VRAM Lo Bytes

WaitNMI() // Wait For Vertical Blank

UpC:
ReadJOY({JOY_UP}) // Test DOWN Button
beq StartC // "DOWN" Not Pressed? Branch Down
jmp Pos1Loop
StartC:
ReadJOY({JOY_START}) // Test LEFT Button
beq Pos3Loop // "START" Not Pressed? Branch Down
stz.w REG_CGADD // $2121: CGRAM Address
lda.b #%11100000 // Load Black Colour Lo Byte
sta.w REG_CGDATA // $2122: CGRAM Data Write Lo Byte
lda.b #%00000011 // Load Black Colour Hi Byte
sta.w REG_CGDATA // $2122: CGRAM Data Write Hi Byte
jmp Pos3Loop
//------------------------------------------------------------------------------------------------

Thanks
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Simple Cursor Menu For a SNES MultiCart

Post by Memblers »

You have the button status of the current frame, but you also need to keep the button status from the previous frame. Before JOY is updated (but after you've used it for that frame), copy JOY into a new variable like JOY_OLD or something. If you want to detect only the transition into each "new" button press, then in the same frame JOY_UP must be 1 and JOY_UP_OLD must be 0.
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

I use the "bne" at the begning of each loop to stuck in a loop when the control is pressed

Pos2Loop:
ReadJOY({JOY_DOWN}) // Test DOWN Button
bne Pos2Loop

But seens stuck on the line 2
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Simple Cursor Menu For a SNES MultiCart

Post by Memblers »

Seeing the code helps, but it's incomplete, as ReadJOY appears to be a macro. For now I'll have to make assumptions about what it expands to, but that could lead us down the wrong path.
Vini Ness wrote: Sat Feb 26, 2022 8:39 am I use the "bne" at the begning of each loop to stuck in a loop when the control is pressed

Pos2Loop:
ReadJOY({JOY_DOWN}) // Test DOWN Button
bne Pos2Loop

But seens stuck on the line 2
What I suspect is that ReadJOY doesn't read the controller, instead the controller gets read during the NMI routine (or later in the main loop), and gets saved in RAM. The game logic only works directly with that RAM variable. That's normally how it's done in SNES and NES programs. This test will hang because bne Pos2Loop keeps re-checking a variable that can never change, because it never reaches the actual controller reading.

You need something like:

Code: Select all

 lda joy1
 and #button_a
 beq a_not_pressed
 and joy1old
 bne a_held
 ; if we didn't take those branches, it's a new button press
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

Memblers wrote: Sat Feb 26, 2022 11:36 pm Seeing the code helps, but it's incomplete, as ReadJOY appears to be a macro. For now I'll have to make assumptions about what it expands to, but that could lead us down the wrong path.
Yes ReadJOY is a macro and sorry for not post the entire code
Here is the code and the macro files
Menu.zip
(24.9 KiB) Downloaded 42 times


I don't know if the ideia is of the cursors, but i set 3 Loops (one for each line) and a arbitrary stuff to do with star button
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Simple Cursor Menu For a SNES MultiCart

Post by Fiskbit »

What you want to do is have 2 variables for a joypad: one that has the buttons that are currently held down (joypad1_down), and one which says which buttons were pressed on this frame (joypad1_press). Then you can just check the variable tracking presses.

Code: Select all

    ; Button state was just read into joypad1_press. joypad1_down currently has last frame's button state.
    LDA joypad1_press
    TAY
    EOR joypad1_down
    AND joypad1_press
    STA joypad1_press
    STY joypad1_down
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

Ok i get the point, but new questions apears

1º: • I know that the buttons register are 2 for the joypad 1, ($4218 and $4219) 16bit
• I know that i have to use REP#$30 to set the A X Y to 16bit mode
• Question is, how can i "LDA" two registers in one A, X or Y

2º: I set like this my variables, is correct?

Code: Select all

seek(WRAM)
Joypad1_down:
	db 0
Joypad1_press:
	db 0
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Simple Cursor Menu For a SNES MultiCart

Post by Quietust »

Vini Ness wrote: Mon Feb 28, 2022 7:34 am Ok i get the point, but new questions apears

1º: • I know that the buttons register are 2 for the joypad 1, ($4218 and $4219) 16bit
• I know that i have to use REP#$30 to set the A X Y to 16bit mode
• Question is, how can i "LDA" two registers in one A, X or Y

2º: I set like this my variables, is correct?

Code: Select all

seek(WRAM)
Joypad1_down:
	db 0
Joypad1_press:
	db 0
Your "down" and "press" variables should both be 16-bit (i.e. probably dw 0), and the above-quoted code should work exactly as-is.
On the NES, they'd only be 8 bits wide (for standard controllers) and the code would be exactly the same.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

Quietust wrote: Mon Feb 28, 2022 9:20 am Your "down" and "press" variables should both be 16-bit (i.e. probably dw 0)
Thanks for the reply, i get some info about it too
db = 8 bits
dw = 16 bits

Now about the controls, i coding for the SNES (16bit controllers), i know that i can take the NES (8bit controllers) and use, but i don't know how
But think that i need to take registers $4218 (Joy 1 Lower 8 Bits) and $4219 (Joy 1 higher 8 Bits), but i don't know how to do that
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

Hi guys, today i make some testes
And try to get a 16bits out of register $4218, and worked ok
I used the BSNES Plus to confirm

i wrote this simple code to test

Code: Select all

loop:	
	lda.b #%00000001
	sta.w REG_NMITIMEN // Enable Joypad NMI Reading Interrupt
	
	rep #$30
	lda.w $4218
	sta.w Joypad1_down
	sep #$30
	

	jmp loop
Now i will try to implement the lines you sugested
Thanks again
And sorry for newbie and simple questions
Vini Ness
Posts: 27
Joined: Wed Jul 11, 2018 10:22 am

Re: Simple Cursor Menu For a SNES MultiCart

Post by Vini Ness »

I made it, thanks guys
I created a loop to count $0000 to $1000 at begning of each line loop

Code: Select all

Pos2Loop:
	//WaitNMI() // Wait For Vertical Blank
	ldy #$0000
	LoopB:
	LoadLOVRAM(BLANK, $FAC4, 1, 1) // Load Text To VRAM Lo Bytes
	LoadLOVRAM(BLANK, $FA44, 1, 1) // Load Text To VRAM Lo Bytes
	LoadLOVRAM(CURSOR, $FA84, 1, 1) // Load Text To VRAM Lo Bytes
	iny
	cpy #$1000
	bne LoopB

	UpB:
		ReadJOY({JOY_UP}) 
		beq DownB         
		jmp Pos1Loop
		
	DownB:
		ldx.w $4218
		cpx #$0400
		bne StartB          
		jmp Pos3Loop	
		
	StartB:
		ldx.w $4218
		cpx #$1000 
		bne UpB		      
		stz.w REG_CGADD  
		lda.b #%00011111 
		sta.w REG_CGDATA 
		lda.b #%00000000 
		sta.w REG_CGDATA 
	jmp UpB
Post Reply