6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 8:42 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Question on tables
PostPosted: Tue Oct 06, 2020 9:39 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
Hello all. Sorry I've been away for a while.

Recently, I've been doing a lot of programming on the C64 and I've run across a section that I want to optimize in my program.

My initial thoughts tell me I should be using some lookup table but I'm struggling with the implementation.

Let's say, for example, that I have the following:

Code:
lda #240
sta ($10), y


$10 and $11 contain the address of the C64's SCREEN RAM. And, for the sake of example, the Y register contains an offset to some column. In other words, that code above would plot the character #240 roughly in the middle of the screen.

Now, what I want to do next is add 9 more locations (total of 10) that would be something like 16, 40, 56, 80, 96, etc. All 8-bit numbers.

It's easy enough to do something like this:

Code:
lda #16
clc
adc $10
sta $10
lda #00
adc $11
sta $11

...

lda #40
clc
adc $10
sta $10
lda #00
adc $11
sta $11

...

lda #56
clc
adc $10
sta $10
lda #00
adc $11
sta $11

...

etc...


That certainly works. But looks messy. Especially since I need to do it 10 times per frame.

I hope I'm making sense.

So, any tips would be appreciated.

Thanks!!

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on tables
PostPosted: Tue Oct 06, 2020 11:04 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
For a start, you can replace LDA #0 : ADC $11 : STA $11 with BCC *+4 : INC $11 which is both smaller and faster, though the cycle counts might be less predictable since they are now data dependent.

If all of the offsets are within 255 bytes of the base, then you could use the Y register for that instead of addition, and add the value of the Y register to the base just once. Then you only need LDY# instead of addition sequences.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on tables
PostPosted: Wed Oct 07, 2020 2:44 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 702
Location: North Tejas
cbmeeks wrote:
$10 and $11 contain the address of the C64's SCREEN RAM. And, for the sake of example, the Y register contains an offset to some column. In other words, that code above would plot the character #240 roughly in the middle of the screen.

Now, what I want to do next is add 9 more locations (total of 10) that would be something like 16, 40, 56, 80, 96, etc. All 8-bit numbers.

It's easy enough to do something like this:

Code:
lda #16
clc
adc $10
sta $10
lda #00
adc $11
sta $11



Unless I'm missing something obvious, can't you do something like this?

Code:
Offsets
    .word   Screen+16
    .word   Screen+40
etc. in ZP


then use something like

Code:
    ldx     Col
    sta     (Offsets,X)


to use it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on tables
PostPosted: Wed Oct 07, 2020 2:57 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
Hmm. Let me see if I can try some of those suggestions.

Yeah, the INC is definitely better than the ADC #00 because I'm not counting cycles here.
I'll try that (Offsets, X) too.

Thanks!!

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question on tables
PostPosted: Wed Oct 07, 2020 4:20 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I think this can all be done simply with a table.

LDX #0
LOOP EQU *
LDY COLUMNS,X
LDA VALUES,X
STA ($10),Y
INX
CPX #?? ; # of values in table
BNE LOOP

COLUMNS DFB #16,#40,#56,#80,#96
VALUES DFB #240, ... ??


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 20 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: