NintendoAge http://nintendoage.com/forum/ -Sqooner Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-12-22T13:39:19 -05.00 bunnyboy 18 Originally posted by: user

In case you did not read these two articles yet, give a look:

 http://wiki.nesdev.com/w/index.ph...

 http://wiki.nesdev.com/w/index.ph...
 
I'll read them. Thanks!
  ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-12-22T12:29:29 -05.00 bunnyboy 18 Originally posted by: FarruOne

The problem lies in the NMI, the PPU or both.

I have just tried a different appeoach and it works fine: I have kept the scrolling code in the NMI but it is branched by a variable flag enabled when the right button is pressed.

Anyway, I should get more familiar with the NMI mechanism...
Thank you!
In case you did not read these two articles yet, give a look:

 http://wiki.nesdev.com/w/index.php/PPU_scrolling

 http://wiki.nesdev.com/w/index.php/The_frame_and_NMIs

they can probably help you out. Also, I know there is a buggy behaviour about writing values to $2005 in some scenarios, but I can't find where such behaviour is explained, and my English and tech language I fear it is not good enough to explain it myself. I'm sure someone else will point out this issue if needed to have your code working correctly.

Edit: correction. ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-12-22T10:45:40 -05.00 bunnyboy 18
I have just tried a different appeoach and it works fine: I have kept the scrolling code in the NMI but it is branched by a variable flag enabled when the right button is pressed.

Anyway, I should get more familiar with the NMI mechanism...
Thank you! ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-12-22T09:10:18 -05.00 bunnyboy 18 Originally posted by: FarruOne

Hi! I am new to NES developement and I find these tutorials truly valuable.
I am trying to scroll on moving to the right, so I moved the code in the NMI block to the Right button one. However, when I move right, the game screws up and I don't know what I'm doing wrong.

My ASM code: http://pastebin.com/Zmv0H25A

Edit: this problem is solved if I move the controller block right before the PPU clean up section, but then the background goes by fits and starts.
Welcome.

845 lines of code are pretty time consuming to check out: do you have an idea about what the problem could be and which snippet of code to look for?

Also, the way you check for inputs from the joypad is excellent to begin learning and understand how reading from the controllers works on a NES, but in the following nerdy nights chapters better alternatives, using subroutines, are explained.

Such as:
 
ReadController:

  LDA #$01

  STA $4016

  LDA #$00

  STA $4016

  LDX #$08

ReadControllerLoop:

  LDA $4016

  LSR A           ; bit0 -> Carry

  ROL buttons     ; bit0 <- Carry

  DEX

  BNE ReadControllerLoop

  RTS

 

 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=8747

Once you fully understand the concept, this would make your code shorter, and your life easier. ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-12-21T15:09:45 -05.00 bunnyboy 18 I am trying to scroll on moving to the right, so I moved the code in the NMI block to the Right button one. However, when I move right, the game screws up and I don't know what I'm doing wrong.

My ASM code: http://pastebin.com/Zmv0H25A

Edit: this problem is solved if I move the controller block right before the PPU clean up section, but then the background goes by fits and starts. ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-09-28T11:37:26 -05.00 bunnyboy 18

---
Originally posted by: thefox

You need to manually reset the "scroll" variable to 0 when it becomes 240 (for the horizontal case it's automatically reset as it wraps 255->0).
So my solution is the common way to do it.

Edit: word changed ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-09-28T11:35:28 -05.00 bunnyboy 18 Originally posted by: bunnyboy

This Week: Time to learn how to do horizontal background scrolling Any chance you wrote something about vertical scrolling?
Since the screen is high only 240px vertically (rather than 256px), it is a bit more messy to find a solution.

Of course, I can manage a solution, however I was just wondering how you would face the issue.

Thanks! ]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-02-16T08:21:55 -05.00 bunnyboy 18 Originally posted by: thefox

Originally posted by: SoleGooseProductions

Or I am missing a step when it comes to switching this up?
You need to manually reset the "scroll" variable to 0 when it becomes 240 (for the horizontal case it's automatically reset as it wraps 255->0).

 
Seamless! Thanks Kalle!

]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-02-15T14:34:45 -05.00 bunnyboy 18 Originally posted by: SoleGooseProductions

Or I am missing a step when it comes to switching this up? You need to manually reset the "scroll" variable to 0 when it becomes 240 (for the horizontal case it's automatically reset as it wraps 255->0).


]]>
Advanced Nerdy Nights #3 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=36958 2015-02-15T12:43:32 -05.00 bunnyboy 18
NMI:

INC scroll ; add one to our scroll variable each frame
NTSwapCheck:
LDA scroll ; check if the scroll just wrapped from 255 to 0
; CMP #$EF ; *A compare seems to be needed here, see question below
BNE NTSwapCheckDone

NTSwap:
LDA nametable ; load current nametable number (0 or 1)
EOR #%00000010 ; exclusive OR of bit 0 will flip that bit
;*bit 1 selects nametable 2 (instead of nametable 1)
STA nametable ; so if nametable was 0, now 2
; if nametable was 2, now 0
NTSwapCheckDone:

LDA #$00
STA $2003
LDA #$02
STA $4014 ; sprite DMA from $0200

; run other game graphics updating code here

LDA #$00
STA $2006 ; clean up PPU address registers
STA $2006

LDA #$00
STA $2005 ; write the horizontal scroll count register

LDA scroll ; vertical scrolling
STA $2005

;;This is the PPU clean up section, so rendering the next frame starts properly.
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
ORA nametable ; select correct nametable for bit 0
STA $2000

LDA #%00011110 ; enable sprites, enable background, no clipping on left side
STA $2001

Everything works and scrolls smoothly, except that the screen jumps (or reloads?) between nametables. I am guessing that the section below needs to be changed to some sort of actual compare (vertical = 240 vs horizontal = 256 screen dimensions), but have not been able to figure out what exactly. I would have thought that #$EF/240 or #$E7/239 would have worked, but neither does. Any thoughts? Or I am missing a step when it comes to switching this up?

INC scroll ; add one to our scroll variable each frame
NTSwapCheck:
LDA scroll ; check if the scroll just wrapped from 255 to 0
CMP #$__ ; *check to see if the scroll wrapped from 240 to 0
BNE NTSwapCheckDone

Thanks! ]]>