Jump to content
IGNORED

Overscan and VBlank line counts


RevEng

Recommended Posts

If you have the luxury of too much ROM (probably not, but who knows...), you could use a look-up table. Something like...

ldx TrafficOffset0
lda TrafficCacheStart,x
ldx TrafficOffset1
ora TrafficCacheStart,x
tax
lda LookUpTable,x
sta PF1Cache

Uses constant 23 cycles in all cases, but uses also 256 bytes of ROM for the look-up table. :P

 

And in case the numerical ranges of TrafficOffset 0 and 1 are <16 and can be packed into one byte, this becomes even faster (16 cycles, or 14 if you can spare y as well).

Link to comment
Share on other sites

Oh, and if you add an "and #%11000000" before the "tax", your look-up table only needs 4 bytes instead of 256, for an additional 2 cycles (for a total of 25 cycles). The downside is that your four bytes have to be stored exactly at location 0, 64, 128 and 192, but if you have other data or code that you can store inbetween, this is very much doable and should be fastest (and in the ideal case even the smallest) solution.

 

My cycle counts assume that the look-up table is aligned to $100, by the way.

Link to comment
Share on other sites

If you have the luxury of too much ROM (probably not, but who knows...), you could use a look-up table. Something like...

 

ldx TrafficOffset0
lda TrafficCacheStart,x
ldx TrafficOffset1
ora TrafficCacheStart,x
tax
lda LookUpTable,x
sta PF1Cache

Uses constant 23 cycles in all cases, but uses also 256 bytes of ROM for the look-up table. :P

 

And in case the numerical ranges of TrafficOffset 0 and 1 are <16 and can be packed into one byte, this becomes even faster (16 cycles, or 14 if you can spare y as well).

 

I don't think this works I'm afraid - if [TrafficCacheStart+TrafficOffset0]=%11000000 and [TrafficCacheStart+TrafficOffset1]=%00000000 then it will have both cars enabled where only the first should be (where [address] is the contents of memory at address)

Link to comment
Share on other sites

Sorry for the triple post, but I have another one. ;)

 

If you could use Y instead of X, you could make TrafficOffset0 and 1 the low bytes of pointers into TrafficCacheStart, using an additional 2 bytes of RAM. Then instead of

 

	ldx TrafficOffset0
	lda TrafficCacheStart,x
you could do

 

	ldy #0
	lda (TrafficOffset0),y
which saves you nothing for the first access, but 2 cycles for every subsequent access if you keep Y at zero. So eshu's solution becomes

 

	ldy #0
	lda (TrafficOffset0),y
	bpl NoCar0
	lda (TrafficOffset1),y
	and #%01000000
	beq Car0NoCar1
	lda #%01110111
	bne StoreCache
Car0NoCar1:
	lda #%01110000
	bne StoreCache
NoCar0:
	lda (TrafficOffset1),y
	and #%01000000
	beq StoreCache
	lda #%00000111
StoreCache:
	sta PF1Cache
for 27 cycles worst case. Edited by Kylearan
Link to comment
Share on other sites

I don't think this works I'm afraid - if [TrafficCacheStart+TrafficOffset0]=%11000000 and [TrafficCacheStart+TrafficOffset1]=%00000000 then it will have both cars enabled where only the first should be (where [address] is the contents of memory at address)

Ah you're right. Somehow I misunderstood the meaning of these variables. Sorry for the confusion, my bad. I shouldn't post when I'm at work. ;)

Link to comment
Share on other sites

  • 6 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...