NintendoAge http://nintendoage.com/forum/ -Sqooner Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2019-03-26T08:33:26 -05.00 bunnyboy 175
I'm sure I'm missing something dumb, but what is it?

MovePaddleUp:
;;if up button pressed

LDA buttons1
AND #$08
BEQ MovePaddleUpDone
;; if paddle top > top wall
LDA #$20
SEC
SBC paddle1ytop
BPL MovePaddleUpDone
DEC paddle1ytop
DEC paddle2ybot

;; move paddle top and bottom up
MovePaddleUpDone:

MovePaddleDown:
LDA buttons1
AND #$04
BEQ MovePaddleDownDone
;; if paddle top > top wall
LDA #$E0
SEC
SBC paddle1ytop
BMI MovePaddleDownDone
INC paddle1ytop
INC paddle2ybot
MovePaddleDownDone: ]]>
Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-26T11:12:33 -05.00 bunnyboy 175 Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-26T10:38:07 -05.00 bunnyboy 175
Anytime I have a tile to update, I'll write it to the $0400 page. First I check to see if anything is written to $0400 (if so, that means I've already told it to update tile(s) this frame, so I need to skip ahead and go to the first free bytes in that page.)

In this example, let's say I want to change four background tiles beginning at $2165. The tiles will be $23, $91, $46, and $90. But earlier in the frame I decided I wanted to change background tile $2310 to tile $12.

Like the website I gave you to did, I have my buffer set up like this.

Byte 0 - Number of tiles I'm updating.
Byte.1 - Hi byte of nametable I'm updating.
Byte 2 - Lo byte of nametable I'm updating.
Bytes 3 - ? - The tiles I'm updating to that address.

Zero page variables:
NumBuffer: .rs 1
HiBuffer: .rs 1
LoBuffer: .rs 1
BufferTiles: .rs xx (however many bytes you want to set aside for buffer updates)

Current state of $0400 page (from previous routine that wants to update background tile $2310 to tile $12:

$01,$23,$10,$12

I have a subroutine somewhere that you will jump to anytime you want to load stuff into the buffer, it will look liks this:

LoadBuffer:
LDX #$00
LDY #$00
.PreLoad:
LDA $0400,x ;check to see if this is an open spot in the $0400 page
CMP #$00 ;if it is, go straight to Load.
BEQ .Load
TAY ;move the current number of bytes that this bkgd update is doing into Y so we can move ahead that many to check next open spot
.Loop:
DEY
INX
CPY #$00
BEQ .PreLoad ;we have successfully moved ahead past the current update. check next spot by jumping back to PreLoad
JMP .Loop
.Load: ;it is now safe to put our updates into this spot of $0400 page
LDA NumBuffer
STA $0400,x
LDA HiBuffer
STA $0401,x
LDA LoBuffer
STA $0402,x
LDY #$00
.ExitLoop:
LDA BufferTiles,y
STA $0403,x
INX
INY
DEC NumBuffer
LDA NumBuffer
CMP #$00
BNE .ExitLoop
RTS

Then I have a routine that happens at the beginning of NMI (and we know this is vblank time) that goes something like this. It actually loads your buffer and makes the changes you want:

RunBuffer:
LDX #$00
.Loop:
LDA $0400,x ;see if anything is set to update
CMP #$00
BEQ .End ;nothing is set to update, go to end
LDA $0400,x
TAY
LDA $0401,x
STA $2006
LDA $0402,x
STA $2006
.OutroLoop:
LDA $0403,x
STA $2007
INX
DEY
CPY #$00
BNE .OutroLoop
JMP .Loop
.End:
RTS

Now that you have your two routines down, at any point in your code to update the tiles we previously mentioned, you can just do this:

;;anywhere in game
LDA #$04 ;we are updating four tiles, like we mentioned
STA NumBuffer
LDA #$21 ;hi byte we are updating
STA HiBuffer
LDA #$65 ;lo byte we are updating
STA LoBuffer
LDA #$23 ;first of four tiles we are updating
STA BufferTiles
LDA #$91
STA BufferTiles+1
LDA #$46
STA BufferTiles+2
LDA #$90
STA BufferTiles+3
JSR LoadBuffer ;take these values and load them into our buffer
;;any code

Then when your updates are done for the frame, you probably need to figure out a way to set $0400 to #$00 so that the game knows not to run the updates the next frame. But I'll let you figure that out.   ]]>
Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-26T06:23:14 -05.00 bunnyboy 175 Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-26T00:58:20 -05.00 bunnyboy 175 Originally posted by: brilliancenp

Oh wait! Do you set it up using the .db command? Im going to try that


No. You would section off a part of ram. Such as: BufferRAM .rs 64 That would reserve 64 bytes in ram just for buffering. I have never done it, but you could adjust that number according to what is needed thr most in any given frame in the game. ]]>
Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-25T20:49:23 -05.00 bunnyboy 175 Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-25T20:39:17 -05.00 bunnyboy 175 Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-23T05:34:07 -05.00 bunnyboy 175
Just something to keep in mind perhaps as you continue on your journey; that constant trade between what you can do and what you need to do. What's that saying, beginning coders hardcode everything and so do veteran ones? Something like that.

And of course, welcome to the forums!

]]>
Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-22T23:40:10 -05.00 bunnyboy 175   Thanks again and yes I am glad to be here. I will read my homework! ]]> Nerdy Nights week 7 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747 2017-08-22T23:13:34 -05.00 bunnyboy 175 Originally posted by: brilliancenp

Ok so this is an old thread I know, I have been going through the tutorials and have everything working except updating the score. I didn't see this explained anywhere but the comments say to update using background tiles or lots of sprites. I would figure updating using background tiles is best since the background tile numbers correspond to the numbers so '0' = $00 '1' = $01 and so on. The problem I am having is updating the background sprites. I can t seem to figure out how to do it and searching google I cant find an answer. Anyone have an example? I would figure I would need to update the background table which I can do (I think) but how to push it to the ppu correctly. Any help would be greatly appreciated.
The best way is to write it to a buffer to where it writes all your background updates in a single frame, but I won't confuse you with that just yet until you get your bearings a little more.

Basically, somewhere in the vblank (which is typically at the beginning of NMI), you have to update the background tiles. The code will look something like this:

UpdateBackgroundTile:
  LDA $2002 ;wake up PPU and let it know we are about to update stuff
  LDA #$20 ;this is the hi byte of the address you're writing to. so if the nametable tile you're updating is located at $2084, $20 is the hi byte.
  STA $2006
  LDA #$84 ;this is the low byte of the address you're writing to. I kept the same address example that I used above.
  STA $2006
  LDA #$xx ;this is the tile number of the new tile you are writing to the address you described above.
  STA $2007 ;write the tile
  RTS

Now, doing it this way is fine, but you have to understand that unless you have a flag telling it to only do it once, it's going to re-draw this tile every single frame until you tell it otherwise. And when you start developing a bigger game, you won't get far before updates like this prevent you from expanding, because vblank is a treasured commodity.

Let us know if you need further clarification, or when you're ready for more advanced solutions.

Homework is to read this: https://wiki.nesdev.com/w/index.php/The_frame_and_NMIs

You don't need to understand the technical details of what it's doing, but at least try to give it a read and understand the concepts. We'll get there. One step at a time!

Also, welcome to NintendoAge!
  ]]>