| |
Slammer
Registered: Feb 2004 Posts: 425 |
Kick Assembler Thread 2
The previous thread took a little long to load, so this is a new fresh one.. |
|
... 594 posts hidden. Click here to view all posts.... |
| |
trident
Registered: May 2002 Posts: 101 |
Quote: I have a small problem, and I don't know if Kick Assembler has a way to provide the solution.
What I think I'd need is dynamic labels - that is, labels that are created and named dynamically at compile time.
In my macro, i'm generating code based on some input data, and I'd need labels within that code (in positions and numbers I don't know of yet at the time of generating the code). Then I'm generating another code block that would refer to those generated labels.
E.g. first bit of macro creates code with label1, label2, label3 etc.
Second bit of macro creates code that updates the values at the aforementioned labels.
As far as I can see this is not possible, at least with the usual labels that seem to be always hard-coded? Any other ideas how to do something like this?
Instead of using a bunch of labels, you can create a list to keep track of the addresses, and then use that list to reach them. Like this:
.var ldas = List()
.macro the_macro_that_creates_the_code() {
.eval ldas.add(* + 1)
lda #0
sta $d020
}
Then, further down in the code:
.macro the_macro_that_refers_to_the_created_code() {
.for (var i = 0; i < ldas.size(); i++) {
lda colors + i,x
sta ldas.get(i)
}
} |
| |
Frostbyte
Registered: Aug 2003 Posts: 184 |
Quote: Instead of using a bunch of labels, you can create a list to keep track of the addresses, and then use that list to reach them. Like this:
.var ldas = List()
.macro the_macro_that_creates_the_code() {
.eval ldas.add(* + 1)
lda #0
sta $d020
}
Then, further down in the code:
.macro the_macro_that_refers_to_the_created_code() {
.for (var i = 0; i < ldas.size(); i++) {
lda colors + i,x
sta ldas.get(i)
}
}
Ahhh of course, brilliant! Thank you! I haven't tried it yet, but I can already see it solves my problem. :) |
| |
Slammer
Registered: Feb 2004 Posts: 425 |
This is probably one of the most asked questions. There are different ways to handle these kind of cases one of them is shown by Trident. Let me point you to another feature that solves it quite nicely.
Normally, when you want label1, label2, etc. the labels are inside a loop, like:
spriteLoop: .for (var i=0; i<8; i++) {
lda data: #0 // <- Fancy inbetween label declaration so you dont need +1
sta $07f8+i
}
You can now use the 'spriteLoop' label to access the 'data' labels of the different iterations of the loop like this:
lda #0
sta spriteLoop[0].data // Sprite 0
sta spriteLoop[1].data // Sprite 1
sta spriteLoop[2].data // Sprite 2
...
// Or simply .for (var i=0; i<8; i++) sta spriteLoop[i].data
If you want to do a table with the addresses, simply:
addrTable: .fill 8, <spriteLoop[i].data
You can access the labels of an executed macros by putting a label in front of the execution, just like we did with the .for loop. |
| |
Slammer
Registered: Feb 2004 Posts: 425 |
With regards to the dicussion earlier in the thread. Several years ago I moved the main feedback/support channel of Kick Assembler to the following facebook group:
https://www.facebook.com/groups/RetroAssembler
This was to ensure a forum were the discussion where not interupted by other things. You are welcome to join regardless of which assembler you are using.
(Please notice that I do not visit this CSDb thread often). |
| |
Frostbyte
Registered: Aug 2003 Posts: 184 |
Quote: With regards to the dicussion earlier in the thread. Several years ago I moved the main feedback/support channel of Kick Assembler to the following facebook group:
https://www.facebook.com/groups/RetroAssembler
This was to ensure a forum were the discussion where not interupted by other things. You are welcome to join regardless of which assembler you are using.
(Please notice that I do not visit this CSDb thread often).
Yesterday I sent a request to join that group, but it's still pending. :) |
| |
Frostbyte
Registered: Aug 2003 Posts: 184 |
Quote: This is probably one of the most asked questions. There are different ways to handle these kind of cases one of them is shown by Trident. Let me point you to another feature that solves it quite nicely.
Normally, when you want label1, label2, etc. the labels are inside a loop, like:
spriteLoop: .for (var i=0; i<8; i++) {
lda data: #0 // <- Fancy inbetween label declaration so you dont need +1
sta $07f8+i
}
You can now use the 'spriteLoop' label to access the 'data' labels of the different iterations of the loop like this:
lda #0
sta spriteLoop[0].data // Sprite 0
sta spriteLoop[1].data // Sprite 1
sta spriteLoop[2].data // Sprite 2
...
// Or simply .for (var i=0; i<8; i++) sta spriteLoop[i].data
If you want to do a table with the addresses, simply:
addrTable: .fill 8, <spriteLoop[i].data
You can access the labels of an executed macros by putting a label in front of the execution, just like we did with the .for loop.
Nice! As in my scenario I don't know how many labels I'll end up with, I suppose in the second loop I could also iterate while i < spriteLoop.size()? (in other words, compiler considers spriteLoop as an array or list?) |
| |
mutetus
Registered: Dec 2020 Posts: 13 |
I'm having a small problem (ka 5.25). So, this works:
.var filename = "textfile.txt"
.import binary filename
But .import text filename doesn't work and it doesn't even tell me what the problem is. Any way around this? |
| |
Maxlide
Registered: Apr 2003 Posts: 33 |
Huhm.
When using a string literal instead of a variable it works.
.import text "textfile.txt"
But why .import binary is working fine with a variable and .import text is not... Well, very odd! |
| |
TWW
Registered: Jul 2009 Posts: 548 |
KickAss has the possibility to create tables with Lo/Hi byte pointers as follows:
Table:
.lohifill 4, List().add($00a0, $01b0, $02c0, $03d0).get(mod(i,16))
Then the LoByte table and HiByte table can be accessed as follows:
ldx #whatever
lda Table.lo,x
sta $fb
lda Table.hi,x
sta $fc
The lengt of the table does not matter, as the .lo/.hi affixes will point to the correct memory location for the tables.
------------------
Now to the question;
Is there a way to know if an address or pointer such as this 'Table' pointer is passed to a pseudocommand (i.e. that it has 2 pointers attached to it or however the internals of this works), and is there a way to easily derive the .lo/.hi addresses within said pseudo?
Reason for the question is because I would like to do this instead of the above example of use:
ldx #whatever
mov16 Table,x : $fb
|
| |
Slammer
Registered: Feb 2004 Posts: 425 |
I know why you want it, since I have also been in a situation where it would be handy. But currently you cannot do that. If you wanna support it you could make a dedicated command like this (Not tested):
.pseudocommand movlh lo : hi : tar {
lda lo
sta tar
lda hi
sta _16bit_nextArgument(tar)
}
.function _16bit_nextArgument(arg) {
.if (arg.getType()==AT_IMMEDIATE)
.return CmdArgument(arg.getType(),>arg.getValue())
.return CmdArgument(arg.getType(),arg.getValue()+1)
}
usage:
movlh table.lo,x : table.hi,x : $fb
The types you can give currently are the normal mnemonic modes (abs, immediate, absx, etc). But there are other situations where extra types are useful. For instance being able to give regA, regX and regY as arguments to a pseudocommand is very usful for e.g. telling the command to leave the result in register A instead of a memory address. So i might extend the pseudocommand arguments in the future. (NB you can achieve regA, regX and regY by being a little creative, but a dedicated argumenttype is nicer) |
Previous - 1 | ... | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 - Next |