Code: Select all
scroll_screen:
;PPUCTRL Controller ($2000) > write
;PPUMASK Mask ($2001) > write
;PPUSTATUS Status ($2002) < read
;OAMADDR address ($2003) > write
;OAMDATA OAM data ($2004) <> read/write
;PPUSCROLL Scroll ($2005) >> write x2
;PPUADDR Address ($2006) >> write x2
;PPUDATA Data ($2007) <> read/write
sta $ff
;if CameraX == 0
lda CameraX+0
bne +
dec distance
inc CameraX+0
; lda nametable
; eor #$01
; sta nametable
+ ;if oX >= 425 (01a9)
sec ;Set Subtract. Clear Add.
lda oX+0
sbc #$80 ;32 ;e8 ;80 ;#$a9
bcc +postincrem
;if player is pressing right
lda currControllerButtons
and #BUTTON_RIGHT
beq +postincrem
+ ;increment SCROLL position
lda CameraX+0
clc
adc #$01
sta CameraX+0
lda CameraX+1
adc #$00
sta CameraX+1
+postincrem:
lda #10001000b
sta currNameTable
lda CameraX+1 ;get the high byte of the camera ((is #$ff in the start after reset) WHY?)
and #$01 ;keep only the lowest (first) bit
ora currNameTable ;combine with the other PPU settings
sta currNameTable ;this is what you'll write to $2000 when setting the scroll
; run other game graphic updating code here
;lda CameraX+0
;and #00000111b ; throw away higher bits
;bne + ; see if lower bits == 0
;jsr next ;sometimes sets correct address for drawing the next column
+ lda currNameTable
sta PPUCTRL0
sta my_copy_of_last_write_to_PPUCTRL
bit PPUSTATUS2 ;<reading $2002 resets both double write registers ($2005 and $2006) so that my first write will go to Xcoord.
lda CameraX+0 ; time to MOVE THE CAMERA OBJECT!
sta PPUSCROLL5 ; write the horizontal scroll count register
lda #$00 ; (no vertical srolling)
sta PPUSCROLL5 ; set the vertical scroll
rts ;end of scroll_screen
Ok I'm wondering if there is an easy way to make this bit not be equal to 1 at the beginning when CameraX+1 is equal to #$FF. It is at #$FF in the beginning because it always subtracts 128 from CameraX and it's a 16 bit subtraction. CameraX is equal to 6 and so 6-128 = -122. CameraX+1 is set to #$FF.lda CameraX+1 ;get the high byte of the camera ((is #$ff in the start after reset) WHY?)
and #$01 ;keep only the lowest (first) bit
ora currNameTable ;combine with the other PPU settings
sta currNameTable ;this is what you'll write to $2000 when setting the scroll