I am having difficulty mapping screen coordinates to nametable addresses (only the currently visible one). I have read http://forums.nesdev.com/viewtopic.php?f=10&t=14788 which is going the other way, but I am missing something apparently. Here is what I am currently trying. Ideas or psuedo-code are welcome!
Code:
.export __gfx_schedule_tile
.proc __gfx_schedule_tile
fory #0, #MAX_TILE_UPDATES
lda tile_ids, y
cmp #255
beq cont
nexty
; found an empty slot
cont:
lda #$35
;lda params::arg3
sta tile_ids, y
; compute and save address
lda params::arg2
add params::arg2
sta params::arg2
lda params::arg1
lsr a
lsr a
lsr a
add params::arg2
sta tile_ppu_lo, y
; hi byte
;lda __gfx_visible_nametable
;asl a
;asl a
lda #0
add #32
add #2
sta tile_ppu_hi, y
rts
endfory
rts
.endproc
.proc __gfx_schedule_tile
fory #0, #MAX_TILE_UPDATES
lda tile_ids, y
cmp #255
beq cont
nexty
; found an empty slot
cont:
lda #$35
;lda params::arg3
sta tile_ids, y
; compute and save address
lda params::arg2
add params::arg2
sta params::arg2
lda params::arg1
lsr a
lsr a
lsr a
add params::arg2
sta tile_ppu_lo, y
; hi byte
;lda __gfx_visible_nametable
;asl a
;asl a
lda #0
add #32
add #2
sta tile_ppu_hi, y
rts
endfory
rts
.endproc