It is currently Sun Dec 17, 2017 12:30 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 26, 2016 2:29 pm 
Offline

Joined: Sun Jan 31, 2016 9:55 pm
Posts: 38
I'm working on some code that needs to draw data over what exists in a tile in CHR RAM, like adding a line with a pencil. I only care about one bit plane, so I need to read 8 bytes from the PPU, perform ORA, and write them back.

I don't have enough RAM to hold all of CHR RAM, so I need to read the data during VBLANK.

This is what I have right now:
It takes 159153 cycles (if I counted correctly).


Code:
lda #>TILEADDRESS
sta $2006
lda #<TILEADDRESS
sta $2006

bit $2007 ; clear read buffer

lda $2007 ; read 8 bytes, store on zero page
sta tmp0

lda $2007
sta tmp1

lda $2007
sta tmp2

lda $2007
sta tmp3

lda $2007
sta tmp4

lda $2007
sta tmp5

ldy $2007

ldx $2007

lda #<TILEADDRESS
sta $2005 ; keep high byte
sta $2006 ; go back to tile address

; write 8 bytes, ora'd with bytes read.
lda tmp0
ora #val0
sta $2007

lda tmp1
ora #val1
sta $2007

lda tmp2
ora #val2
sta $2007

lda tmp3
ora #val3
sta $2007

lda tmp4
ora #val4
sta $2007

lda tmp5
ora #val5
sta $2007

tya
ora #val6
sta $2007

txa
ora #val7
sta $2007


I feel like there should be a faster way to do it, but I'm not very knowledgeable about the PPU's internal state. Do I need to buffer the values, or is it possible to read, modify, then write to a value in the PPU?

EDIT: Saved some time using tokumaru's trick


Top
 Profile  
 
PostPosted: Fri Aug 26, 2016 3:04 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19353
Location: NE Indiana, USA (NTSC)
Say you're doing a bunch of tiles at once, and you have no big WRAM to hold your frame buffer. (Canonical example: Videomation.) The easiest way to make this fast is to read up to 8 or so tiles out of CHR RAM during vblank, modify them during active picture, and write them back to CHR RAM during the next vblank.


Top
 Profile  
 
PostPosted: Fri Aug 26, 2016 3:23 pm 
Offline

Joined: Sun Jan 31, 2016 9:55 pm
Posts: 38
I guess that could get me better average speeds at the cost of a one frame latency.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group