| |
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.... |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Yes, variables and other fancy stuff is only evaluated during assembly. Nothing but the machine code is compiled to the executable, so it's not like a normal programming language where you can do color++ in "realtime". In your case you need a memory location to hold your color value, and a machine code way of incrementing it:
read_joy:
lda $dc00
lsr
bcc joy_up
jmp read_joy
joy_up:
inc color
lda color
sta $d021
jmp read_joy
color: .byte 0
|
| |
Carlos Account closed
Registered: Mar 2009 Posts: 15 |
Yeah.. this was my second approach but, as far as i know, i can't use a memory location as the parameter of a KickAss macro. I have tested it and the assembler gives no error but nothing happens:
read_joy:
lda $dc00
lsr
bcc joy_up
jmp read_joy
joy_up:
inc color
:setBackground(color)
jmp read_joy
color: .byte 0
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Change the macro to this, to avoid immediate addressing mode:
.macro setBackground(color) {
lda color
sta $d021
} |
| |
Carlos Account closed
Registered: Mar 2009 Posts: 15 |
Great! didn't notice that.. thks Cruzer. |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Once you get more comfortable with the basic stuff, you can start using pseudocommands, which support both things at once.
.pseudocommand setBackground(color) {
lda color
sta $d021
}
:setBackground #color // Use predetermined value (immediate mode)
:setBackground color // Use value from memory (absolute mode)
Btw. The background color macro is just an example of how to create and use a macro. I guess you cant benefit much by using this particular macro.. |
| |
Carlos Account closed
Registered: Mar 2009 Posts: 15 |
Interesting Slammer, i will try it.
Another question: User defined structures. Can the fields of the structure be of any size or each field is always a byte?
.struct foo {x , y) (i want x be a word and y a byte) |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
The struct directive is just a collection of fields with no particular type. The fields can be anything: Numbers, lists, strings, etc. For example:
.stuct MyStruct {a, b}
.var myVar = MyStruct(27, "Hello World")
.byte myVar.a // is the same as .byte 27
.print myVar.b // is the same as .print "Hello world"
In the above example only the '.byte myVar.a' directive will produce output to the assembled .prg file. It will be a byte because a .byte directive is used, but if you had written .word myVar.a it would have been a word.
hope it helped..
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11145 |
mmmmh. whats the difference between a struct and a namespace then? *shrug* |
| |
Pantaloon
Registered: Aug 2003 Posts: 124 |
groepaz, you dont know the difference between namespace & structs ? i hope you are trolling :) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Groepaz doesn't even know the difference between .align and .fill :P |
Previous - 1 | ... | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ... | 61 - Next |