| |
PopMilo
Registered: Mar 2004 Posts: 146 |
-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 :)
|
|
| |
Digger
Registered: Mar 2005 Posts: 437 |
Check for KickAssembler pseudo commands. |
| |
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
|
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
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.
|
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
@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.
|
| |
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. |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
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
|
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
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!
|
| |
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
|
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
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.
|
| |
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. |
| |
Mace
Registered: May 2002 Posts: 1799 |
MagerValp's "lda #towne" should of course be "ldx #towne"... |
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
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.
|
| |
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 ;-) |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
Quote: MagerValp's "lda #towne" should of course be "ldx #towne"...
Good catch, thanks. |
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
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/
|
| |
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.
|
| |
PopMilo
Registered: Mar 2004 Posts: 146 |
@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 ;)
|