Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > -Set multiple values according to table- routine ?
2011-05-08 14:56
PopMilo

Registered: Mar 2004
Posts: 145
-Set multiple values according to table- routine ?

What do you guys think: what would be a best way for routine that would set multiple values in memory according to simple table ?

Example:

Instead of this:
lda #$00
sta $d020
lda #$0f
sta $d022
lda #$ff
sta $d012

Something like this:
ldx #>table
ldy #<table
jsr setvalues

table .word $D020
      .byte $0
      .word $D022
      .byte $0f
      .word $D012
      .byte $ff
      .byte $0,$0    ; end of table


Or maybe it could be done with macros ?

ps. I don't think I would save any memory with this, it wouldn't be faster, but at least it's something to do in a free afternoon :)
2011-05-08 15:06
Digger

Registered: Mar 2005
Posts: 421
Check for KickAssembler pseudo commands.
2011-05-08 15:16
JCB
Account closed

Registered: Jun 2002
Posts: 241
For a start you don't need to store the $D0 byte in the table if you're only putting stuff in VIC, just do like ldy table,x to get the offset to use for a sta $d000,y

2011-05-08 16:10
MagerValp

Registered: Dec 2001
Posts: 1059
What's the goal? Is it:

* to save space?
* to be able to reuse the code?
* to make the source easy to read and maintain?
* to be able to load values?

Which approach is "best" very much depends on what you're trying to accomplish.
2011-05-08 16:53
PopMilo

Registered: Mar 2004
Posts: 145
@Digger: yeah, Kickassembler is one of tools I was thinking about using... But I kinda like pure asm more :)

@JCB: That sounds good, but I have list of addresses without any rules. It could be any address (except something like $0000 that would signalize end of table).

@Magervalp: I should have started with describing the purpose of it :)

I have "states" in my game engine, and each change of state needs quite a lot of changes in memory (Colors, Screen, Character set and sprite pointers, raster irq addresses etc.).

I just thought to ask if there is a "better" way of doing stuff like this beside LDA-STA ?

So:
Save space - not so important.
Although I would save two bytes per LDA-STA. If there are enough states and values - that could result in memory saved.

Reuse code and Easy to read and maintain - most definitely.
I would like to use this code in more than one project.

In some kind of pseudo language it should look like this:
set_state("graphics character based screen 16x16")
or
set_state("standard 38x24 column multicolor char mode")

Thinking about it - wouldn't be bad if it could do more than simple (address)=value.
Put this in table: $0400, 1000, $0 - and routine would fill 1000 bytes from $0400 with $0.
Almost like a decompression, just into separate memory spaces.
2011-05-08 18:18
Mace

Registered: May 2002
Posts: 1799
Wouldn't it be an idea to work the other way around?

I would set one address with the value of the state.
That value can then be read at any location in your program where a value has to be set that is dependent of the state.

So:

$02 = state value

ldy $02
lda bordertable,y
sta $d020

ldy $02
lda screentable,y
sta $d021

etc.

The plus side is that you can extend your program at any location without having to change predefined tables and without having to know all the address location inside your program.
2011-05-08 18:43
MagerValp

Registered: Dec 2001
Posts: 1059
Yeah, stripe your data and do it the way Mace suggests. It's compact (no overhead) and fast:

overworld = 1
dungeon = 2
towne = 3

state_d012:
    .byte $ff, $32, $a2
state_d020:
    .byte 0, 0, 11
state_d022:
    .byte 6, 9, 5

set_state:
    lda state_d012,x
    sta $d012
    lda state_d020,x
    sta $d020
    lda state_d022,x
    sta $d022
    rts


    lda #towne
    jsr set_state
2011-05-08 19:09
PopMilo

Registered: Mar 2004
Posts: 145
Well, I do have current state defined as one byte value already :)

Only problem I see in approach with tables like this is too many different addresses ...

But it is good enough for hardware registers.
I can make separate routines for VIC and SID for example...
set_sid_state, set_vic_state, set_mem_state

Sid will probably be set only once. And I would change VIC parameters more often.

Thanks!
2011-05-08 19:11
Cruzer

Registered: Dec 2001
Posts: 1048
For easy-to-read and more compact sourcecode I'm using a KickAss pseudocommand called mb ("move byte') for simple lda/sta's.
.pseudocommand mb arg1;arg2 {
	lda arg1
	sta arg2
}

With this your code would look like:
:mb #$00; $d020
:mb #$0f; $d022
:mb #$ff; $d012
2011-05-08 19:47
PopMilo

Registered: Mar 2004
Posts: 145
KickAss does seem like good choice for new asm (I'm still using tasm :) ).

I did try it when it came out, but I remember some bugs prevented me from using it. As I see now, lots of new versions and lots of bug fixes.

Will give it a go.
2011-05-08 21:03
Cruzer

Registered: Dec 2001
Posts: 1048
Yep, KickAss has reached a much more stable state since the early days in 2005/06. It's years since I have encountered any serious bug. I also know that Slammer has written a huge test suite (100s of unit tests as far as I remember) which get checked before each release.
2011-05-09 09:07
Mace

Registered: May 2002
Posts: 1799
MagerValp's "lda #towne" should of course be "ldx #towne"...
2011-05-09 09:25
PopMilo

Registered: Mar 2004
Posts: 145
Does Kick assembler have something like XASM, MADS - DTA directive ?

It is like .byte or .word but types of values can be mixed.

so instead of:

.byte $00
.word $d000

it looks like this:

dta $00,a($d000)

"a()" is used for "lo hi address" type.

---------------------------------------
Just red kickass manual... Lists, hashtables, vectors... It sure is much more than simple compiler :)

So even if does not have "dta" I can make one.
2011-05-09 18:12
Slammer

Registered: Feb 2004
Posts: 416
No not at the moment. If I see a good notation i might give it a go.

MADS assembler.. Sounds like a good one ;-)
2011-05-09 19:10
MagerValp

Registered: Dec 2001
Posts: 1059
Quote: MagerValp's "lda #towne" should of course be "ldx #towne"...

Good catch, thanks.
2011-05-09 20:22
PopMilo

Registered: Mar 2004
Posts: 145
Quote: No not at the moment. If I see a good notation i might give it a go.

MADS assembler.. Sounds like a good one ;-)


I'll try Kickassembler and make macros for something like this.

@MADS:
Yeah, name is well chosen :)

It is made by Polish Atari group so all instructions are in Polish - that can make a foreigner go mad.

Great 6502 assembler thou, lots of cool features. A8 specific.
"MAD-ASSEMBLER"
http://mads.atari8.info/
2011-09-01 00:34
Glasnost
Account closed

Registered: Aug 2011
Posts: 26
y try macro or pseudocommand in kickass.


with a defined as:

.pseudocommand a adress;value {.word adress .byte value}

you can write it down as
:a $d020;0
:a $d022;$0f
:a $d012;$ff

and make that script for initialising variables.

or as cruzer recommends for the faster runtime and more readable program.

2011-09-01 06:52
PopMilo

Registered: Mar 2004
Posts: 145
@Glasnost: Thanks!
That looks just like that dta archive from atari assembler.

I'm using simple macro (lda #n sta ad) for now.
As always it turns out - "keep it simple" is still best way to go :)

ps. I do have ideas about my own new compiler ;)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Dymo/G★P
Krill/Plush
Luca/FIRE
Clown
tlr
Guests online: 128
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Graphicians
1 Sulevi  (10)
2 Mirage  (9.8)
3 Lobo  (9.7)
4 Mikael  (9.7)
5 Archmage  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.