Created
August 24, 2018 21:53
-
-
Save slembcke/6a53fd021e9b0430e99e105729a98bf7 to your computer and use it in GitHub Desktop.
Code snippets for my flicker issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void px_ppu_sync_off(){ | |
px_mask &= ~PX_MASK_RENDER_ENABLE; | |
px_wait_nmi(); | |
// Without these I get a few garbage lines at the top of the screen | |
waitvsync(); | |
waitvsync(); | |
} | |
static void px_ppu_sync_on(){ | |
px_mask |= PX_MASK_RENDER_ENABLE; | |
px_wait_nmi(); | |
} | |
************************************************* | |
// Screen changes all look like this. | |
// Buffer the background color change to be run in NMI | |
px_buffer_set_color(0, CLR_BLACK); | |
px_ppu_sync_off(); { | |
// Update whole screen here... | |
} px_ppu_sync_on(); | |
************************************************* | |
// My NMI routines look like this: | |
.proc px_nmi | |
; Interrupt enter. | |
pha | |
txa | |
pha | |
tya | |
pha | |
lda px_nmi_ready | |
beq @skip_frame | |
lda px_mask | |
sta PPU_MASK | |
lda px_ctrl | |
sta PPU_CTRL | |
; Invoke OAM DMA copy. | |
lda #>OAM | |
sta APU_SPR_DMA | |
; Execute the display list buffer. | |
jsr _px_buffer_exec | |
; Reset PPU Address | |
lda #0 | |
sta PPU_VRAM_ADDR | |
sta PPU_VRAM_ADDR | |
; Set the scroll registers. | |
lda PX_scroll_x+0 | |
sta PPU_SCROLL | |
div240_quick PX_scroll_y | |
sta PPU_SCROLL | |
; Note: Y-scroll remainder is in x. | |
; Set nametable base address. | |
lda PX_scroll_x+1 | |
lsr a | |
txa | |
rol a | |
and #$03 | |
ora px_ctrl | |
sta PPU_CTRL | |
@skip_frame: | |
jsr FamiToneUpdate | |
; Reset ready flag. | |
lda #0 | |
sta px_nmi_ready | |
; Interrupt exit. | |
pla | |
tay | |
pla | |
tax | |
pla | |
rti | |
.endproc | |
.export _px_wait_nmi | |
.proc _px_wait_nmi | |
lda #1 | |
sta px_nmi_ready | |
: lda px_nmi_ready | |
bne :- | |
inc px_ticks | |
rts | |
.endproc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment