Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Kick Assembler Thread 2
2009-07-21 17:20
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..
 
... 590 posts hidden. Click here to view all posts....
 
2012-02-08 15:55
Slammer

Registered: Feb 2004
Posts: 416
Constants are visible after you have defined them. So the example you give, will work if you declare your const before you use the macro:

:MyMacro($32) 	// This won't work
.const MyConst = $d012
:MyMacro($32) 	// This will work
.macro myMacro(val)
{
    ldy #val
    sty MyConst
}

However, labels can be seen in the whole scope so they can be used before they are declared:

:MyMacro($32) 	// This will work
.label MyLabel = $d012
.macro myMacro(val)
{
    ldy #val
    sty MyLabel
}
2012-02-08 16:29
McKrackeN

Registered: Feb 2011
Posts: 20
Thanks for your help!

I think i'm declaring the constant before using the macro but i'm still getting the compiler error.

I have two separate files. One called system.asm and the other test.asm.
// System.asm

.const MyConst = $d012

.macro myMacro(val)
{
        ldy #val
	sty MyConst
}


Then in the test.asm:

// test.asm
.import source "system.asm"

// some code

:myMacro(0)

2012-02-08 22:35
Slammer

Registered: Feb 2004
Posts: 416
I Just tried it and it works fine here. My guess is that you define the macro+constant inside one scope and execute your macro outside the scope. Eg. if you start you system.asm file with a .filenamespace directive.



2012-02-08 22:43
McKrackeN

Registered: Feb 2011
Posts: 20
Yes!! That's it!! Thanks for your help and for this amazing compiler!!
2012-02-10 22:38
TWW

Registered: Jul 2009
Posts: 541
How would I go about doing a:

.fill 256,invert(data.get(i))

i.e. invert the data filled into memory on the fly?
2012-02-19 12:39
Slammer

Registered: Feb 2004
Posts: 416
Suppose by invert you mean exclusive or you can:
.fill 256,data.get(i)^$ff
2012-02-19 13:27
chatGPZ

Registered: Dec 2001
Posts: 11100
i found this bug:

test1.asm:

.if (1 == 1) {
    .import source "test2.asm"
}


test2.asm can be whatever (even empty file)

assembling results in the following error:

.if (1 == 1) {
    .import source "test2.asm"
    ^

Error: Unknown import type 'source'
at line 3, column 5 in test1.asm


additional question: if there are labels defined in test2.asm, then how do i export them outside the scope of the if statement? (i find it really super useless and annoying that if statements have their own scope to be honest, it effectively prevents me from being able to use them properly :/)

eg i am used to do stuff like this:

.if testing = 1
screen = $0400
chars = $0800
.else
screen = $e400
chars = $e800
.endif


how do you do this in kickass? (assuming there are many more such labels, replacing them all by a function is really not an option)
2012-02-19 16:13
TWW

Registered: Jul 2009
Posts: 541
Yepp, that's exactly what I ment. Thanx Slammer!
2012-02-19 16:24
Slammer

Registered: Feb 2004
Posts: 416
I see your problem. You can't use the .import source directive this way, it can't be nested inside a .for or an .if. The reason is that the .import source directive is evaluated in a pre parse that collects pseudocommands, macros, functions, etc so you can use them in the evaluation, but the error message is wrong. Should be something like 'Cant use an import source directive here'.

If you are importing libraries and only want to import them once, then use the .importonce directive instead.

btw. booleans are implemented so you can do: .if (true) { ..}

----

About labels/Constants/Variables:

Constants: Is defined like '.const myConst=25' and can only be accessed after they are defined. Constants can't change values.

Variables: Is defined like '.var myVar=true' and works like constants. The only difference is that you can change the value of a variable. e.g.: '.eval myVar=false'

Labels: Is defined like 'myLabel1:' or '.label myLabel2="HelloWorld" and can be accessed before they are declared (Note that they don't necessarily have to be numbers). Labels can't change values.

Now back to your question. To do a test setup like the one you describe you can do it in two ways. The first way defines your constants in a really compact way:

   // Define Mode
   .const TEST = true

   // Define Data
   .const screen = TEST ? $0400 : $e400 
   .const chars = TEST ? $0800 : $e800

Another way, that keeps the test setup more separated from the normal setup, is to define the datafields as variables and assign them insides ifs:
   // Define Mode
   .const TEST = true

   // Define Data
   .var screen .var chars 
   .if (TEST) {
	.eval screen = $0400 
	.eval chars = $0800 
   } else {
	.eval screen = $e400 
	.eval chars = $e800 
   }
2012-02-19 17:47
chatGPZ

Registered: Dec 2001
Posts: 11100
Quote:
I see your problem. You can't use the .import source directive this way, it can't be nested inside a .for or an .if. The reason is that the .import source directive is evaluated in a pre parse that collects pseudocommands, macros, functions, etc so you can use them in the evaluation, but the error message is wrong. Should be something like 'Cant use an import source directive here'.
If you are importing libraries and only want to import them once, then use the .importonce directive instead.

urks :( i am selectively including other sourcefiles there, depending on some other settings (ie, its not an include-guard). bummer, that will be tricky to solve :/
Previous - 1 | ... | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | ... | 60 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Higgie/Kraze/Onslaught
Mixer
pcollins/Quantum
Røly/Mayday!
Falborg
A3/AFL
radius75
kbs/Pht/Lxt
Guests online: 82
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.073 sec.