8x16 and whatever else unreg wants to know

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

unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Is it good to set up the controller reading part with a system that checks each button-part to see if it has already been pressed and so then it should be ignored until it's released?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

You don't need any complex logic for that. With just a few bitwise operations you can detect all kinds of keypresses. Read this post and the ones after it.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

I have the controller reading code a subroutine, then I put my movement and actions based off the computer in my main engine, I think that'd the standard way of doing things.
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Sweet! Thank you tokumaru! :D I can move our sprite reguarly now!!!

Thank you 3gengames for those two sentences, they helped me alot :D once I finally spent time to understand it.

So far only half of my controller works... the controlpad part works; A B Select Start don't do anything. Do you have an idea of what coould be wrong?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Well, can't tell without the code... :P
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Code: Select all

lookatController:
  lda ControllerButtons
  sta lastControllerButtons

	LDX #$01 
STX $4016 
DEX 
STX $4016 
LDX #$08 
-Loop: 
LDA $4016 
LSR A 
ROr ControllerButtons 
DEX 
BNE -Loop 

  lda lastControllerButtons
  eor #$ff ;invert
  and ControllerButtons ;AND result with the new state
  sta pressedControllerButtons

RTS ;Controller value in the variable ControllerButtons. 

...

react_to_input:
    
	jsr lookatController

	lda pressedControllerButtons    ; Is the A button down?
        and BUTTON_A ;#00000001b
		beq @b
		inc aFrame        ;run only once per press.
        		
@b:		lda pressedControllerButtons		;Is the B button down?
		and BUTTON_B ;#00000010b
		beq @select
		lda #0
		sta aFrame
		jsr low_c    ;low_c is just small code that plays a note 
		
@select lda pressedControllerButtons  ; Select does something(music no working)
		and BUTTON_SELECT ;#00000100b
		beq @start
		ldx <musicA_module ;also songA
		ldy >musicA_module		
		jsr FamiToneMusicStart
		
@start	lda pressedControllerButtons  ; Start does nothing
		and BUTTON_START ;#00001000b
		beq @up
		jsr FamiToneMusicStop
		
@up		lda pressedControllerButtons   ;Is Up  down?
		and BUTTON_UP ;#00010000b
		beq @down
		dec oY
@down	lda pressedControllerButtons ;is Down down?
		and BUTTON_DOWN ;#00100000b
		beq @left
		inc oY
@left   lda pressedControllerButtons  ;is Left down?
		and BUTTON_LEFT ;#01000000b
		beq @right
		dec oX
@right  lda pressedControllerButtons  ;Is Right down?
        and BUTTON_RIGHT ;#10000000b
		beq not_dn
		inc oX
not_dn:	rts  
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Hmm, not sure what it's doing here and I don't know if I can find out. Is it doing anything at all? What isn't happening?
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

unregistered wrote: So far only half of my controller works... the controlpad part works; A B Select Start don't do anything.
A & B aren't working at all, they are susposed to advance and reset the sprite frame. Select and start arent working at alll, they are susposed to start and stop a famitone song.
Last edited by unregistered on Wed Jun 29, 2011 11:13 am, edited 1 time in total.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Are you ROLing them the right way in your routine? You ROR, I dunno if you ment to do a ROL instead.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Have you tried swapping around which button does what?

What are the definitions of BUTTON_A, BUTTON_B, BUTTON_SELECT, and BUTTON_START? They appear not to be present in this page of the discussion or on the previous page.

Have you made sure that A, B, Select, and Start are correctly mapped in the emulator on which you're testing, such as by playing someone else's homebrew game?

Have you tried getting on a PC running Windows and stepping through react_to_input using FCEUX or Nintendulator?


EDIT:
@3gengames: ROR is fine if you prefer little-endian bit order of the buttons in the byte, not unlike how the Game Boy Advance buttons are ordered.
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tepples wrote:Have you tried swapping around which button does what?
No... well, I did a long time ago, I remember. :)
tepples wrote:What are the definitions of BUTTON_A, BUTTON_B, BUTTON_SELECT, and BUTTON_START? They appear not to be present in this page of the discussion or on the previous page.
next to each one of these i commented out the value (in the last code up there)

Code: Select all

BUTTON_RIGHT .equ #10000000b
BUTTON_LEFT  .equ #01000000b
BUTTON_DOWN  .equ #00100000b
BUTTON_UP    .equ #00010000b
BUTTON_START .equ #00001000b
BUTTON_SELECT .equ #00000100b
BUTTON_B     .equ #00000010b
BUTTON_A     .equ #00000001b
tepples wrote:Have you made sure that A, B, Select, and Start are correctly mapped in the emulator on which you're testing, such as by playing someone else's homebrew game?
No, that is a good idea, thank you... now, yes they are working
tepples wrote:Have you tried getting on a PC running Windows and stepping through react_to_input using FCEUX or Nintendulator?
I've never stepped through anything. Do you have any tips/suggestions? I'm going to use Nintendulator.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

In Nintendulator 0.970, open your ROM and under Debug, choose Disassembly. In the Controls pane of the debugger window, click "Step" to stop your program. Click "Step" a few more times to execute an instruction at a time. In the Trace pane, scroll up and down to see instructions around the program counter. You can double-click an instruction to set a breakpoint. Once you've set a breakpoint on an instruction; the "Run" button in the will run the program until a breakpoint is executed. So if you put a breakpoint just before jsr react_to_input, you can run the program and then step through the subroutine.
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tepples wrote:In Nintendulator 0.970, open your ROM and under Debug, choose Disassembly. In the Controls pane of the debugger window, click "Step" to stop your program. Click "Step" a few more times to execute an instruction at a time. In the Trace pane, scroll up and down to see instructions around the program counter. You can double-click an instruction to set a breakpoint. Once you've set a breakpoint on an instruction; the "Run" button in the will run the program until a breakpoint is executed. So if you put a breakpoint just before jsr react_to_input, you can run the program and then step through the subroutine.
tepples, thanks for these instructions! :)

How can i find out what the line number address is just before jsr react_to_input?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

That depends on how your assembler outputs listing or map files.
User avatar
qbradq
Posts: 952
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

What I usually do is put in a dummy instruction and set a breakpoint on that. In Nintendulator you can tell it to break when a certain address is read or written to.

I usually do a bit $0100 to read from the last byte of the stack, something that does not normally happen in my programs. I stick that instruction in wherever I want a break, then set the break point to Read $0100.
Post Reply