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

3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

unregistered wrote:
3gengames wrote:Go to the debugger, and set a break point for every time it reads/write from/to that location in memory, it won't do anything with your game [besides possibly mess it up]...
It reads $0100 and then writes twice to the status register, right? That's pretty safe, to me. :)
I dunno, but you're stack is there, but you probably shouldn't ever use all of it to even $100, haha. :P Did you get the debugging to work?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Heh, I actually use $FF as my breakpoint location. But that's because I use a good part of page 1 for variables, starting at $0100, since I won't ever need all 256 for the stack. If I'm not mistaken, I use only 32 bytes or so for the stack, the rest is all variables. ZP is also filled with variables, but until I reach the very last byte of it, $FF is a safe place for breakpoints.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

3gengames wrote:Did you get the debugging to work?
Yes, I feel I'm making progress. :) But, it was too weird and so I changed back to the ROL and so now after pressing select it does something... my meta-sprite returns to the left-hand side of the screen... and then, after that, the controls start working normaly. Each button only completes its ppurpose one time per press. So, it kindof works more now... but if i dont press select, the directional pad does nothing. :?

edit: I changed it back to ROL because I wanted to see if select worked. With the ROR I could only press directions on the directional pad. After changing it to ROL I updated my BUTTON definitions:

Code: Select all

BUTTON_RIGHT .equ #00000001b
BUTTON_LEFT  .equ #00000010b
BUTTON_DOWN  .equ #00000100b
BUTTON_UP    .equ #00001000b
BUTTON_START .equ #00010000b
BUTTON_SELECT equ #00100000b
BUTTON_B     .equ #01000000b
BUTTON_A     .equ #10000000b
(They're in the wrong order but that doesn't matter :).) The ROL started to work right... kindof, Select, Start, B, and A worked now. And now the other half doesn't work... It's the same problem on BOTH ROL AND ROR! :D Select doesn't play the famitone song, but it does fix whatever is wrong with my controller reading code. After pressing select all the buttons do something. :?
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Thank you qbradq for all your code you posted... I can't bring myself to copy it... yet because I learn by trying to fix by myself. : )

tokumaru wrote:Heh, I actually use $FF as my breakpoint location. But that's because I use a good part of page 1 for variables, starting at $0100
Isn't the stack inverted? Is that why you say, "I use a good part of page 1 for variables, starting at $0100"?
Last edited by unregistered on Fri Jul 01, 2011 9:03 pm, edited 1 time in total.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

He's making the RAM in "pages" of 256.

Page 0=$0000-$00FF
Page 1=$0100-$01FF

And so on. Page 1 is the stck area, it's hard wired. Phen you put something on it, it DE-INCREMENTS the stack. So when you load the stack with FF (LDX #$FF, TXS) it's at the highest point. Most people don't use all of the stack, so sometimes random variables go into the unused space, despite the stack being there. I don't put any there myself, but if I need to, they're going there. I doubt I'll need it though. :)
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

unregistered wrote:Isn't the stack inverted? Is that why you say, "I use a good part of page 1 for variables, starting at $0100"?
I just meant that since I don't use the whole stack, I put variables in the unused space. So while the stack grows from $1FF down, I have variables from $100 up. As long as the variables don't touch the deepest level my stack goes, that's fine.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

Just a minor point, but I would suggest to avoid doing .equ #00000000 and would do .equ 00000000 instead, then put the # in your code. I know it should work either way, but it's helpful to have your code be as clear as possible that immediate mode is being used (in addition to using all caps for defined constants, like you're doing already).
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Memblers wrote:Just a minor point, but I would suggest to avoid doing .equ #00000000 and would do .equ 00000000 instead, then put the # in your code. I know it should work either way, but it's helpful to have your code be as clear as possible that immediate mode is being used (in addition to using all caps for defined constants, like you're doing already).
:? :( I thought # ment immediate mode. :?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

It does, but the immediate mode goes in an instruction, not in the equate statement. The instruction is "LDA #" or "AND #"; its operand is 0.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tepples wrote:It does, but the immediate mode goes in an instruction, not in the equate statement. The instruction is "LDA #" or "AND #"; its operand is 0.
Ah! :) Thank you tepples! Thank you Memblers! :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

My computer got changed or fixed... sorry for missing 3 weeks.

How do I enable the character to move like it used to when pressing a direction? It used to move until you released the dpad direction. Now it only moves 1 pixel per press because of the changes I've been instructed to make. It doesn't check the controller 60 times each second anymore. I don't get it. :(
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

You should use different kinds of button detection for different game events. For things like menu navigation and shooting for example, you'll want to detect when buttons are pressed, but for walking you'll actually want to react 60 times per second.

Most people just keep 2 button state bytes, one with the buttons that are currently pressed (regardless of their state in the previous frame), and one with the buttons that are pressed now but weren't last frame (i.e. new buttons). Both of them are useful in games.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Ah, thank you so much tokumaru! This seems possible now! :D
Thank you God for this understanding! He always helps. :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

this is crazy. Here is my code

Code: Select all

lookatController:
  lda currControllerButtons
  sta lastControllerButtons

	LDX #$01 
	
STX $4016 
DEX 
STX $4016 

 
 
    bit $0100 



LDX #$08 
-Loop: 
;LDA $4016 
;LSR A 
;ROl currControllerButtons 
;DEX
       pha
       
       ; Read next button state and mask off low 2 bits.
       ; Compare with $01, which will set carry flag if
       ; either or both bits are set.
       lda $4016
       and #$03
       cmp #$01
       
       ; Now, rotate the carry flag into the top of A,
       ; land shift all the other buttons to the right
       pla
       rol a
       
       dex
       
       
       
 
BNE -Loop
 

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

RTS ;Controller value in the variable currControllerButtons. 
The wiki code is there in the -Loop part; I commented out the 4 lines and pasted the wiki code... just to see what would happen. It totally suprized me! My figure chose to start moving left and then went on a diagonally north-east path until I stopped nintendulator. Pressing buttons didn't help. I'm so tired... been up all night trying to complete the movement part. There must be some horrible mistake in that code... posting it here to see if yall could figure it out. I'm going to be away from my computer until next Tuesday. We're leaving this morning.. have to get ready. Thank you for reading all of this. Love yall. :) God, please help me some more. Amen. : )
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

You are not saving the current button status anywhere after reading. Just put "sta currControllerButtons" right below "BNE -Loop". OR replace the whole loop with the following:

Code: Select all

-Loop:
	lda $4016
	and #$03
	cmp #$01
	rol currControllerButtons
	dex
	bne - Loop
I see absolutely no reason for you to be monkeying around with the stack.

I must remind you that copying and pasting code around just to "see if it works" is a terrible way to program. Things end up working by pure luck, meaning you don't learn anything (because you don't know why they worked) and your programs aren't reliable at all, since different circumstances could easily break them.

EDIT: I just want to add that what I meant in my previous messages is that for some game events you should use currControllerButtons (walking, jumping - if you have variable jump heights -, etc.), but for others you should use newControllerButtons (menu navigation, shooting, etc.).
Last edited by tokumaru on Fri Jul 29, 2011 7:10 am, edited 1 time in total.
Post Reply