| |
Slammer
Registered: Feb 2004 Posts: 416 |
Kick Assembler Thread 2
The previous thread took a little long to load, so this is a new fresh one.. |
|
... 592 posts hidden. Click here to view all posts.... |
| |
TWW
Registered: Jul 2009 Posts: 543 |
I know even before posting that this question will sound weird but here goes;
Can I create a macro/pseudocommand which will compile differently depending on arguments passed?
f.ex.
ex #1:
A routine changes the code it produces based on arguments passed. Like a multiply routine which choosed 8 bit or 16 bit multiply depending on which arguments the macro/pseudo is called with.
ex #2:
A joystick routine called with port as a parameter simply returns the joystick status in A or something BUT if an aditional parameter like acceleration is passed the routine "changes" into different produced code which handles acceleration this aswell (somehow^^)...
TWW/Creators |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Yes you can. Use the if command or modify arguments to change the behavior. Here are a couple of examples from my own library (increasing complexity).
Example 1. I got two versions of a move macro, one that is fast and a general one for moving a lot of data. Dependent of the number of bytes to be moved i select one of the two:
.macro Move(source, target, size) {
.if (size <= $1000) :FastMove(source,target,size)
else :GeneralMove(source,target,size)
}
.macro FastMove(source, target, size) {
..
}
.macro GeneralMove(source, target, size) {
...
}
Example 2. I got a 8/16 bit library that gives me amiga/pc like pseudo commands. Below is an example of an 8 bit adc command. You con give it 3 arguments it adds the first two and place the result in the third argument (eg: :add #3 ; table1,x ; result). But you can also leave out the third argument and then the result is placed in the second (eg: :add #3 ; score)
.pseudocommand adc arg1;arg2;tar {
.if (tar.getType()==AT_NONE) .eval tar=arg2
lda arg2
adc arg1
sta tar
}
Example 3. Now lets take the 16bit version of the adc command which is a bit harder since the highbyte of each argument should be treated different dependent on the mode of the arguments (absolute, immediate, zeropage, etc). Eg if you have an immediate argument like #$1234 the the lowbyte is 34 and the highbyte is 12, but if you have an absolute like $1000 then the lowbyte is in $1000 and the highbyte is in $1001. To take care of this we define a nextArguent function and use it as show below.
.pseudocommand adc16 arg1 ; arg2 ; tar {
.if (tar.getType()==AT_NONE) .eval tar=arg2
lda arg2
adc arg1
sta tar
lda _16bit_nextArgument(arg2)
adc _16bit_nextArgument(arg1)
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)
}
// the above macro is use like this:
:add16 #$2800 ; $1000
:add16 screen ; offset ; zpPointer
|
| |
TWW
Registered: Jul 2009 Posts: 543 |
Awesome.
Seriously, Thanx for such a cool tool!
TWW/Creators |
| |
Mace
Registered: May 2002 Posts: 1799 |
Hmm, 'nested' macros... interesting and simple, yet I never thought of it :-) |
| |
Pantaloon
Registered: Aug 2003 Posts: 124 |
i found a bug:
.const LINK = false
begin:
.if (LINK == false)
{
.import c64 "\datapata\myfile.prg"
}
end:
.print end - begin
the print won't work, it will output the address at begin:
if i remove .if () it works.
-P |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
I will have a look at it.. Right now im on vacation in Austria - will be home on monday. |
| |
Pantaloon
Registered: Aug 2003 Posts: 124 |
Feature request:
a method to generate a random unique list, ie:
.var randomNumbers = randomUniqueList(numberOfElements)
the randomUniqueList would give you back a list of values
between 0 and numberOfElements, no number should me mapped twice in the list.
Generating this kind of list using the built in Hashtable takes forever today.
Edit:
i found out doing this,
.var random_table = Hashtable()
.for (var i = 0; i < 12*40; i++ )
{
.eval random_table.put(i,i)
}
would generate a somewhat unique list because of the nature of the hashtable, but still its not random.
|
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Why dont you use the random function? Quick Pseudocode:
for (;hashtable.getKeys().getsize()< noOfDesiredElements;) {
.var randomNo = random()
.eval hashtable.put(randomNo, randomNo)
}
Nb. Since we dont have a while statement (yet) I use the for statement as a while |
| |
Pantaloon
Registered: Aug 2003 Posts: 124 |
i found a better way,
shuffle() that can be done on lists :)
|
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: i found a better way,
shuffle() that can be done on lists :)
@Slammer: Collections.shuffle(List<?> list); *hint* *hint* and while you're at it, Collections.sort(List<?> list); :D Heck, .reverse is useful too!
|
Previous - 1 | ... | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ... | 61 - Next |