| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
Kick Assembler - Removal of unused code?
I'm trying out Kick Assembler and I'm wondering if it has a feature I used a lot in my own assemblers over the years.
I like to collect useful subroutines and keep them in an external ASM file that I include at the top of my code. Is there a way that I can do that BUT have the assembler not compile code that I don't actually call?
I hate to eat the memory space for stuff that I won't be calling in that specific app.
How do you guys handle this sort of thing? Am I over engineering? :) |
|
... 20 posts hidden. Click here to view all posts.... |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
That is already described in the first post? |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
To be fair, we sort of switched topics ... or side stepped, anyway.
But currently what I'm looking to do is use the Kick scripting language, or something else, to generate code.
This would allow me to write some generic wrapper macros that would auto-write the boilerplate necessary for the technique that Digger was sharing. |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Here's slightly "abstracted out" and cleaner version, using some tips from Slammer:
https://pastebin.com/print/cZqgdv7C
What remains is to figure out:
1) the ways of passing params to these lib code, a good write-up here: https://maciejmalecki.github.io/blog/macro-hosted-subroutines
2) what's the best way to utilise macro's variables |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
Wow, this got a lot deeper than I was expecting ... thanks for the replies, everyone, it's been informative! |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
So, to underscore what I wanted to do here in the end ... I wanted some way to boilerplate the code that Digger inspired above.
LONG STORY SHORT, I WANT TO USE THE SCRIPTING LANGUAGE TO GENERATE CODE THAT THEN GETS COMPILED AS IF I HAD TYPED IT.
Code like this gives me what I want, in terms of conditional compilation and I love it:
NOTE : SUBSYS_MasterAddr is defined elsewhere.
.var GFX_HideROMCharSet_Addr = 0
.macro GFX_HideROMCharSet()
{
.if( GFX_HideROMCharSet_Addr == 0 )
{
.var save_pc = *
* = GFX_HideROMCharSet_Addr = SUBSYS_MasterAddr
{
lda #$37
sta $01
cli
rts
}
.eval SUBSYS_MasterAddr = *
* = save_pc
}
jsr GFX_HideROMCharSet_Addr
}
The trouble is, this is all the code that I actually need:
lda #$37
sta $01
cli
All the rest is boilerplate cruft. So I wanted a way, in Kick Assembler, to generically insert that code for me. But I need some sort of text replacement ability before compilation begins. It FEELS like it should be possible. So something like:
ProcStart(GFX_HideROMCharSet)
{
lda #$37
sta $01
cli
}
ProcEnd(GFX_HideROMCharSet)
"ProcStart" and "ProcEnd" take the name I provide it and drop it into the assigned slots in the code templates and away we go. So, everywhere you see a [ARG_HERE] ...
-----------------------
ProcStart
-----------------------
.var [ARG_HERE]_Addr = 0
.macro [ARG_HERE]()
{
.if( [ARG_HERE]_Addr == 0 )
{
.var save_pc = *
* = [ARG_HERE]_Addr = SUBSYS_MasterAddr
{
-----------------------
ProcEnd
-----------------------
rts
}
.eval SUBSYS_MasterAddr = *
* = save_pc
}
jsr [ARG_HERE]_Addr
}
This feels like it SHOULD be scriptable ... is it? |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Check my pastebin code above :) |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
I saw that, thanks!
And that is a way to get where I'm going but I'm now wondering about the more generic question ...
Is there a way to write code with the Kick scripting language so that it dynamically creates source that will be compiled in later passes?
I know you can use FOR loops with VARs and modify operand arguments, but ... is there any way to emit straight text or strings?
Like, if I have:
.var myCmd = "lda #0"
Can I get that "lda #0" line emitted to the source code somehow? |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Why would you like to do it?
I often use JS to generate the KickAss code that later gets compiled, but that's useful usually for speed code, for example for texture lookups. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
* = $1000
changebackr .proc
sta $d020
rts
.pend
jmp *
result in memory:
.C:1000 4C 00 10 JMP $1000
* = $1000
changebackr .proc
sta $d020
rts
.pend
jsr changebackr
jmp *
result in memory:
.C:1000 8D 20 D0 STA $D020
.C:1003 60 RTS
.C:1004 20 00 10 JSR .changebackr
.C:1007 4C 07 10 JMP $1007
also macros do what you want in your post #1, they only get compiled into memory when you use them.
* = $1000
changebackgr .macro
lda #\1
sta $d020
.endm
#changebackgr 0
jmp *
result in memory:
.C:1000 A9 00 LDA #$00
.C:1002 8D 20 D0 STA $D020
.C:1005 4C 05 10 JMP $1005 |
| |
Compyx
Registered: Jan 2005 Posts: 631 |
That looks like 64tass code. The topic is about Kickassembler. |
Previous - 1 | 2 | 3 - Next |