Fortunately, the game is not heavily dependent on scrolling, but after toying with it and it stumping me, I'd still like to figure it out. I adapted some of the Nerdy Nights tutorials to a simple engine I slammed together for testing, and I do have scrolling 'working', but very wonkily.
Here are my two nametables:
NT0:
NT00.bmp [ 30.12 KiB | Viewed 2974 times ]
NT1:
NT01.bmp [ 30.12 KiB | Viewed 2974 times ]
But when I actually work them in code, the second, procedurally loaded nametable is drawn 'sideways' (tiles seem correct, but position is flipped and rotated...evidenced especially by the fact only 240 across are drawn). I have not yet worked on attributes so not worried about that issue yet, but this should demonstrate what I mean...see tile orientation here compared to the previous attachment:
scrolled to NT1:
NT2.png [ 1.67 KiB | Viewed 2974 times ]
Here is the current code, from the NMI forward:
NMI:
;first push whatever is in the accumulator to the stack
PHA
TXA
PHA
TYA
PHA
NewColumnCheck:
LDA hScroll
AND #%00000111
BNE NewColumnCheckDone
JSR DrawNewColumn
NewColumnCheckDone:
LDA #$00
STA $2003
LDA #$02
STA $4014
LDA #$00
STA $2006
STA $2006
LDA hScroll
STA $2005 ;reset scroll values to zero
LDA vScroll
STA $2005 ;reset scroll values to zero
JSR GamePadCheck
LDA #%10010000
ORA nametable
STA $2000
LDA #%00011110
STA $2001
PLA
TAY
PLA
TAX
PLA
;; keep constant frame rate:
DEC vBlankTimer
;;return from this interrupt
RTI
StartGame:
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDX #$00
LoadPaletteLoop:
LDA PaletteData,x
STA $2007
INX
CPX #$20
BNE LoadPaletteLoop
LDA #$00
STA hScroll
STA vScroll
LDA #$00
STA newScreen
LDA #$00
STA nametable
LDA #$00
STA columnNumber
LDA #$00
STA $2000
STA $2001
JSR LoadNametable
LDA #$10 ;; what row of pattern table to load
LDX #$00
LDY #$00 ;; what column
JSR LoadChrRam
MainGameLoop:
bit $2002
vBlankWait:
bit $2002
BPL vBlankWait
LDA gamepad
AND #PAD_R
BEQ dontScrollRight
INC hScroll
LDA hScroll
AND #%00000111
BNE doneScroll
INC columnNumber
jmp doneScroll
dontScrollRight:
doneScroll:
JMP MainGameLoop
DrawNewColumn:
LDA hScroll
LSR A
LSR A
LSR A
STA columnLo
LDA #$24
STA columnHi
LDA columnNumber
ASL A
ASL A
ASL A
ASL A
ASL A
STA sourceLo
LDA columnNumber
LSR A
LSR A
LSR A
STA sourceHi
LDA sourceLo
CLC
ADC #<Room1
STA sourceLo
LDA sourceHi
ADC #>Room1
STA sourceHi
DrawColumn:
LDA #%0000100
STA $2000
LDA $2002
LDA columnHi
STA $2006
LDA columnLo
STA $2006
LDX #$1E
LDY #$00
DrawColumnLoop:
LDA (sourceLo),y
STA $2007
INY
DEX
BNE DrawColumnLoop
RTS
GamePadCheck:
;strobe the gamepad
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadControllerBytesLoop:
PHA
LDA $4016
AND #%00000011
CMP #%00000001
PLA
ROR
DEX
BNE ReadControllerBytesLoop
STA gamepad
RTS
LoadNametable:
LDA #$00
STA $2001
LDA $2002
LDA #$20
STA $2006
LDA #$00
STA $2006
LDA newScreen
TAX
LDA NTPointerLo,x
STA ntRam
LDA NTPointerHi,x
STA ntRam+1
LDX #$04
LDY #$00
LoadNametableLoop:
LDA #$00
STA $2001
LDA (ntRam),y
STA $2007
INY
BNE LoadNametableLoop
INC ntRam+1
DEX
BNE LoadNametableLoop
RTS
LoadRam:
.include "LoadRamRoutine.asm"
CHRTileCount:
.db #$50
CHRAddressLo:
.db <bckTiles
CHRAddressHi:
.db >bckTiles
bckTiles:
.incbin "HudTiles.chr"
NTPointerLo:
.db <Room0, <Room1
NTPointerHi:
.db >Room0, >Room1
Room0:
.incbin "MapNametables\NT00.nam"
Room1:
.incbin "MapNametables\NT01.nam"
Any thoughts? Thanks!
Here are my two nametables:
NT0:
Attachment:
NT00.bmp [ 30.12 KiB | Viewed 2974 times ]
NT1:
Attachment:
NT01.bmp [ 30.12 KiB | Viewed 2974 times ]
But when I actually work them in code, the second, procedurally loaded nametable is drawn 'sideways' (tiles seem correct, but position is flipped and rotated...evidenced especially by the fact only 240 across are drawn). I have not yet worked on attributes so not worried about that issue yet, but this should demonstrate what I mean...see tile orientation here compared to the previous attachment:
scrolled to NT1:
Attachment:
NT2.png [ 1.67 KiB | Viewed 2974 times ]
Here is the current code, from the NMI forward:
Code:
NMI:
;first push whatever is in the accumulator to the stack
PHA
TXA
PHA
TYA
PHA
NewColumnCheck:
LDA hScroll
AND #%00000111
BNE NewColumnCheckDone
JSR DrawNewColumn
NewColumnCheckDone:
LDA #$00
STA $2003
LDA #$02
STA $4014
LDA #$00
STA $2006
STA $2006
LDA hScroll
STA $2005 ;reset scroll values to zero
LDA vScroll
STA $2005 ;reset scroll values to zero
JSR GamePadCheck
LDA #%10010000
ORA nametable
STA $2000
LDA #%00011110
STA $2001
PLA
TAY
PLA
TAX
PLA
;; keep constant frame rate:
DEC vBlankTimer
;;return from this interrupt
RTI
StartGame:
LDA $2002
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDX #$00
LoadPaletteLoop:
LDA PaletteData,x
STA $2007
INX
CPX #$20
BNE LoadPaletteLoop
LDA #$00
STA hScroll
STA vScroll
LDA #$00
STA newScreen
LDA #$00
STA nametable
LDA #$00
STA columnNumber
LDA #$00
STA $2000
STA $2001
JSR LoadNametable
LDA #$10 ;; what row of pattern table to load
LDX #$00
LDY #$00 ;; what column
JSR LoadChrRam
MainGameLoop:
bit $2002
vBlankWait:
bit $2002
BPL vBlankWait
LDA gamepad
AND #PAD_R
BEQ dontScrollRight
INC hScroll
LDA hScroll
AND #%00000111
BNE doneScroll
INC columnNumber
jmp doneScroll
dontScrollRight:
doneScroll:
JMP MainGameLoop
DrawNewColumn:
LDA hScroll
LSR A
LSR A
LSR A
STA columnLo
LDA #$24
STA columnHi
LDA columnNumber
ASL A
ASL A
ASL A
ASL A
ASL A
STA sourceLo
LDA columnNumber
LSR A
LSR A
LSR A
STA sourceHi
LDA sourceLo
CLC
ADC #<Room1
STA sourceLo
LDA sourceHi
ADC #>Room1
STA sourceHi
DrawColumn:
LDA #%0000100
STA $2000
LDA $2002
LDA columnHi
STA $2006
LDA columnLo
STA $2006
LDX #$1E
LDY #$00
DrawColumnLoop:
LDA (sourceLo),y
STA $2007
INY
DEX
BNE DrawColumnLoop
RTS
GamePadCheck:
;strobe the gamepad
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadControllerBytesLoop:
PHA
LDA $4016
AND #%00000011
CMP #%00000001
PLA
ROR
DEX
BNE ReadControllerBytesLoop
STA gamepad
RTS
LoadNametable:
LDA #$00
STA $2001
LDA $2002
LDA #$20
STA $2006
LDA #$00
STA $2006
LDA newScreen
TAX
LDA NTPointerLo,x
STA ntRam
LDA NTPointerHi,x
STA ntRam+1
LDX #$04
LDY #$00
LoadNametableLoop:
LDA #$00
STA $2001
LDA (ntRam),y
STA $2007
INY
BNE LoadNametableLoop
INC ntRam+1
DEX
BNE LoadNametableLoop
RTS
LoadRam:
.include "LoadRamRoutine.asm"
CHRTileCount:
.db #$50
CHRAddressLo:
.db <bckTiles
CHRAddressHi:
.db >bckTiles
bckTiles:
.incbin "HudTiles.chr"
NTPointerLo:
.db <Room0, <Room1
NTPointerHi:
.db >Room0, >Room1
Room0:
.incbin "MapNametables\NT00.nam"
Room1:
.incbin "MapNametables\NT01.nam"
Any thoughts? Thanks!