Skip navigation
NintendoAge
Welcome, Guest! Please Login or Join
Loading...

Nerdy Nights week 5 multiple sprites, reading controllers, more instructions

Apr 25, 2011 at 6:23:20 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
make sense like a cut scene where the sprite is present but you don't want them moving around and such. but in the tutorials so far there hasn't been a comment that says "; variable"
so I assume that " controller1: " would be a variable? and the information contained under it would be it's parameters?

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Apr 25, 2011 at 6:28:18 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
No, it's just the memory where it's stored at when it reads the controller. A lot of programs that people do just read the controller and then move, but if it's not one right ofter the other, it's probably better, haha.

Apr 25, 2011 at 7:04:02 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
so then how would you put the controller functions into a variable?

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Apr 25, 2011 at 7:05:46 PM
bunnyboy (81)
avatar
(Funktastic B) < Master Higgins >
Posts: 7704 - Joined: 02/28/2007
California
Profile
Overly complicated tutorials is a common mistake. By trying to teach everything exactly right the first time the reader will be overloaded and far more likely to fail. Keeping it simple on purpose, then adding more detail in future lessons keeps the progress moving forward. Ignore variables until they are brought up in week 7.

Apr 25, 2011 at 7:12:46 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
Oh ok, I'll do just that then. Currently I've got the back of Mario's head working on the x and y axis and can move it in 8 directions. No I've just got to get all 4 sprites moving in tangent.

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Apr 25, 2011 at 7:26:10 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
The variable is already there, it's whatever it rotates the values into. If you aren't using variables, how else do you remember the sprites X and Y coordinates?

Apr 25, 2011 at 8:40:49 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
By going back and looking at the code to see in which memory address they were put into???...

but right now I'm having the hardest time getting all four sprites to move together. I saw resynthesize's code and it somewhat makes sense to me but not entirely. I can get it to work left and right but up and down does some freaky stuff. I figured that my replacing the x's with y's and where the sprite address started it would just kick over and work

ReadUp: ;Player 1 D-Pad UP
LDA $4016 ; controller port 1 IRQ
AND #%00000001 ; AND IRQ byte
BEQ ReadUpDone ; Branch EQuals to ReadUpDone if Up was NOT pressed
;button is pressed

ldY #$00 ; y position of sprite starts at $0203

moveloopUp:
lda $0203, y ; load sprite y position ($2000 + y)
clc ; make sure the carry flag is clear
SBC #$02 ; A = A + 1
sta $0203, y ; save sprite y position
iny ; increment y 4 times to get to next sprite
iny ; y position
iny
iny
cpY #$13 ; if x = $13 (HEX), all 4 sprites have been moved
bne moveloopUp ; otherwise keep going.

ReadUpDone:

vs his

ldx #$03 ; x position of sprite starts at $0203

moveloop:
lda $2000, x ; load sprite X position ($2000 + x)
clc ; make sure the carry flag is clear
adc #$02 ; A = A + 1
sta $2000, x ; save sprite X position
inx ; increment X 4 times to get to next sprite
inx ; x position
inx
inx
cpx #$0F ; if x = $0f, all 4 sprites have been moved
bne moveloop ; otherwise keep going.


-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Apr 25, 2011 at 8:53:57 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
Mailed, I'll help you there.

Apr 27, 2011 at 2:31:25 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
Alright, So I came back to this and finally managed to get all the sprites moving together But now I've come to another problem. they seem to move at different speeds in different direction. Up goes nice and slow, left goes the same speed. however Down and right go faster. I assume it has to deal with the Y and X coordinate getting   loaded first for Up and Left, then for Down and right it doubles it in some respect.

I have the flag CLC'ed for each sprite on each direction then SEC'ed for each one in each direction. (At first I thought it was because the flag was carrying the math and at first it helped with one of the direction when 3 of them were moving fast and Up was the only one that was slow) and it may be a Flag issue but I'm just not sure

any suggestions?

P.S. I'm also working on the Background as part of this piece and I'm not quite finished with it so a lot of 2's will show up when complied.

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Apr 27, 2011 at 2:50:59 PM
Mario's Right Nut (352)
avatar
(Cunt Punch) < Bowser >
Posts: 6636 - Joined: 11/21/2008
Texas
Profile
You only need SEC with SBC and CLC with ADC. Not both SEC and CLC.

You're clearing the carry flag and setting the carry flag. Try that and see if it works.

-------------------------

This is my shiny thing, and if you try to take it off me, I may have to eat you.

Check out my dev blog.


Apr 27, 2011 at 2:59:29 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
Yup, that Did it. thanks MRM!

but why do you only use one for one not the other?

[EDIT]

let me rephrase, why do you only use SEC with SBC and CLC with ADC? what makes the difference?

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain


Edited: 04/27/2011 at 03:58 PM by JC-Dragon

Jun 21, 2011 at 12:41:24 PM
Berserker (41)
avatar
(< • • ll Andrew O. ll • • >) < Kraid Killer >
Posts: 2129 - Joined: 06/29/2010
New Hampshire
Profile
Sorry to bump a rather old thread but...

How do I get the sprite to:

A. Move faster. (Doesn't necessarily need to be variable, but I may be doing it wrong or there may be a better way. Code only changed for Dpad_Right)
B. Move more smoothly.
C. Move more accurately to the button press.

Thanks.

Jun 21, 2011 at 2:38:45 PM
Mario's Right Nut (352)
avatar
(Cunt Punch) < Bowser >
Posts: 6636 - Joined: 11/21/2008
Texas
Profile
Originally posted by: Berserker

Sorry to bump a rather old thread but...

How do I get the sprite to:

A. Move faster. (Doesn't necessarily need to be variable, but I may be doing it wrong or there may be a better way. Code only changed for Dpad_Right)
B. Move more smoothly.
C. Move more accurately to the button press.

Thanks.

A. Change $01 to however fast you want it to move. As you get more advanced, you'll figure out the whole "meta sprite" deal.  It works easier.

B. I assume that this is in reference to the "$08" you put in there.  That means that you move 8 pixels per frame.  You need to slow down if you don't want it to jump around.

C.  I don't know, but I suspect that if you used a more advanced controller reading method, it would work better.  Like MetalSlime uses. 



-------------------------

This is my shiny thing, and if you try to take it off me, I may have to eat you.

Check out my dev blog.


Jun 21, 2011 at 4:19:19 PM
Memblers (3)
avatar
(Joey Parsell) < Eggplant Wizard >
Posts: 247 - Joined: 05/12/2008
Indiana
Profile
Originally posted by: Berserker

Sorry to bump a rather old thread but...

How do I get the sprite to:

A. Move faster. (Doesn't necessarily need to be variable, but I may be doing it wrong or there may be a better way. Code only changed for Dpad_Right)
B. Move more smoothly.
C. Move more accurately to the button press.

Thanks.


A/B:  You'll use what is known as fixed-point addition (also using it like this it's often called "sub-pixel precision".  That just means there is a decimal point, and it's fixed to a certain position.    The easy way is to make your speed use 2 bytes, instead of adding #1 per pixel to your sprite position, you do a 16-bit add and use the upper 8 bits as the actual sprite position (so your sprite position must be 16-bit as well, with the lower 8-bits as it's own variable, completely separate from NES sprite-memory).  So the "decimal point" is between those 2 bytes, giving you 256 fractional speeds (and by preserving the lower 8 bits of the sprite position, you'll have 256 fractional positions within each pixel on the screen).  That allows for really smooth movement, and all kinds of different speed possibilities.  Also makes it easy to adjust for NTSC/PAL differences.

-------------------------
 

Jun 21, 2011 at 9:01:48 PM
Mario's Right Nut (352)
avatar
(Cunt Punch) < Bowser >
Posts: 6636 - Joined: 11/21/2008
Texas
Profile
^^ think the "ticker" in metalslimes sound tutorials.

-------------------------

This is my shiny thing, and if you try to take it off me, I may have to eat you.

Check out my dev blog.


Feb 15, 2012 at 4:55:28 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Is this an acceptable way to make sprites move slower than 1 pixel per Vblank:

; Just before JMP Forever I cleared the X register.
ReadA:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
INX ; if a press is registered for 3 Vblanks then translate the sprite.
CPX #$03
BNE ReadADone
LDX #$00 ; Once it has been moved reset the Vblank counter.
LDA $0203 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 3 (changed to 3)
STA $0203 ; save sprite X position (sprite moves 1 unit right).
ReadADone: ; handling this button is done

I've tried it and it works, just wondering if it's the right way to go about it.

Feb 15, 2012 at 7:18:05 AM
muffins (0)
avatar
(I am Error.) < Tourian Tourist >
Posts: 44 - Joined: 01/31/2012
Maine
Profile
It looks like a workaround. I don't see anything wrong with it up front though I can see that if you really wanted something to drag, like moving through mud, it could use up precious processor time. I think what Memblers is suggesting three posts above is worth looking into.

-------------------------


Feb 15, 2012 at 12:17:33 PM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8126 - Joined: 06/21/2007
Florida
Profile
Basically what Memblers is saying is this:

LDA PartialVariable
CLC
ADC #$80 ;any speed here.
STA PartialVariable
LDA $0200
ADC #$00 ;any speed here. (usually #00 or #01 unless your stuff is moving super fast)
STA $0200

You have control over two addresses now, with this way giving you a ton more speed options. The downside to this is you have to have a partialvariable for every sprite you want more control over.

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin


Feb 15, 2012 at 6:22:19 PM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Thanks for the replies guys. But I don't exactly follow where the sprites postion ($0200) is being updated though, following memory:

A = PartialVariable
A = PartialVariable+$80
PartialVariable = A (so partialVariable is being updated each time).
A = $0200 (same x-position each time? PartialVariable isn't being to offset number stored in $0200?)
A = $0200
$0200 = A


Edited: 02/15/2012 at 07:16 PM by glenn101

Feb 15, 2012 at 9:39:33 PM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8126 - Joined: 06/21/2007
Florida
Profile
I think it has to do with the carry flag. Someone with better knowledge should reply. I just know it works.

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin


Jun 30, 2012 at 9:45:28 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
alright, so I'm back at the NN tutorials after a year of hiatus. Sadly most of my saved stuff from back then is gone so I've started over. a lot of things make WAY more sense this time around but I have a question. why does this
ReadUp:
LDA $4016 ; player 1 - Up
AND #%00000001
BEQ ReadUpDone
LDA $0203 ; load sprite 1 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $0203 ; save sprite 1 position
LDA $0207 ; load sprite 2 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $0207 ; save sprite 2 position
LDA $020B ; load sprite 3 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $020B ; save sprite 3 position
LDA $020F ; load sprite 4 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $020F ; save sprite 4 position
ReadUpDone:


move it horizontally while this

ReadUp:
LDA $4016 ; player 1 - Up
AND #%00000001
BEQ ReadUpDone
LDA $0200 ; load sprite 1 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $0200 ; save sprite 1 position
LDA $0204 ; load sprite 2 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $0204 ; save sprite 2 position
LDA $0208 ; load sprite 3 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $0208 ; save sprite 3 position
LDA $020C ; load sprite 4 position
SEC ; make sure carry flag is set
SBC #$01 ; A = A - 1
STA $020C ; save sprite 4 position
ReadUpDone:

moves it vertically?



-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain

Jun 30, 2012 at 9:49:54 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
I'm not sure what you're doing, but that's a terrible way of reading the controller. Just realize the right way to do it is to get all the data in one byte then do your bit masks with it, not straight off of $4016 like it is doing.

But the reason it moves it different ways is because each of the 64 OAM data values goes $200=Y location,$201=Tile,$202=Sprite Attribute,$204=X location.


Edited: 06/30/2012 at 09:58 PM by removed04092017

Jun 30, 2012 at 9:56:31 PM
JC-Dragon (0)
avatar
(JC Childs) < Eggplant Wizard >
Posts: 388 - Joined: 04/24/2011
United States
Profile
yes yes I know, we talked about that last year. lol but I'm just going through the tutorials as they are. You sent me a ton of PMs helping me but going back over them my mind decided to freeze. For right now I just want to know why there's a difference in the movement.

---EDIT--

i didn't realize that you had answered my question in that response. thank you.

-------------------------
You can't depend on your eyes when your imagination is out of focus
- Mark Twain


Edited: 06/30/2012 at 10:08 PM by JC-Dragon

Sep 27, 2012 at 4:34:00 AM
The Adventurer (0)
avatar
(James Purcell) < Cherub >
Posts: 7 - Joined: 09/27/2012
Connecticut
Profile
I've been going through the tutorial (amazing resource btw) and have managed to suss out how to rebind all four sprites to move with the directional buttons. Figuring out that everything as a specific registry port in a specific order was a bit of a learning experience. But I'm starting to get it.
 
My question is... I know this works...
 
ReadR:
  LDA $4016       ; player 1 - Right
  AND #%00000001  ; only look at bit 0
  BEQ ReadRDone   ; branch to ReadBDone if button is NOT pressed (0)
                  ; add instructions here to do something when button IS pressed (1)
 
  LDA $0203       ; load sprite0 X position
  CLC             ; make sure carry flag is set
  ADC #$01        ; A = A + 1
  STA $0203       ; save sprite0 X position
 
  LDA $0207       ; load sprite1 X position
  CLC
  ADC #$01
  STA $0207
 
  LDA $020B       ; load sprite2 X position
  CLC
  ADC #$01
  STA $020B
 
  LDA $020F       ; load sprite3 X position
  CLC
  ADC #$01
  STA $020F
  
ReadRDone:        ; handling this button is done
 
 
But... why doesn't this work?
 
ReadRight:
  LDA $4016       ; player 1 - Right
  AND #%00000001  ; only look at bit 0
  BEQ ReadRightDone   ; branch to ReadBDone if button is NOT pressed (0)
                  ; add instructions here to do something when button IS pressed (1)
  LDA $0203
  LDA $0207
  LDA $020B
  LDA $020F
  CLC
  ADC #$01
  STA $0203
  STA $0207
  STA $020B
  STA $020F  
  
ReadRightDone:        ; handling this button is done
 
I mean... it sort of works. It will move the entire sprite around the screen. BUT. It garbles the sprites themselves (it kinda reverses them front to back on the first button press) Is there anything at a glance that would cause this strangeness? Because it sure cuts down on a few lines of code, and makes it look neater.
 


Edited: 09/27/2012 at 04:34 AM by The Adventurer

Sep 27, 2012 at 8:42:23 AM
DoNotWant (1)

(Ham Sammich) < Eggplant Wizard >
Posts: 441 - Joined: 12/08/2011
Sweden
Profile
You can only have one value in a register at a time.
So your way, you add 1 to the value in $020F.

-------------------------
 


Edited: 09/27/2012 at 08:44 AM by DoNotWant