snasm68k variable defines...

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

snasm68k variable defines...

Post by tomaitheous »

Ok, I'm sick of writing equates with manual addresses for every single variable in ram. There has to be a more automated way like other assemblers.

Edit:

This seems to assemble fine;

Code: Select all

	org $ff0100

	var1:	dc.w $0000
	var2:	dc.w $0000
	var3:	dc.w $0000
	var4:	dc.w $0000
It'd be nice not to have to declare a value after it though. So, where is the documentation to snasm68k?

Edit2: Ok, the DS.x directive works out very nicely (glad to see that directive in there), but there's no BSS in snasm?
Last edited by tomaitheous on Thu May 07, 2009 7:13 pm, edited 1 time in total.
HardWareMan
Very interested
Posts: 753
Joined: Sat Dec 15, 2007 7:49 am

Post by HardWareMan »

Becouse of memory map, that separate ROM and RAM too far of each other, I use this method:
1. When I need some constant in ROM area, I use DC.x directive, like this:

Code: Select all

Text: dc.b 'Some text',0 ;You should watch out odd count of chars (with break one)! It must be even, or when you try to access to next one you will get an Address Error exception.
Word: dc.w $0000
Long: dc.l $00000000
2. When I need some RAM variables, I use this:

Code: Select all

BaseAddr equ $FF0000
SomeVar1 equ BaseAddr
SomeVar2 equ SomeVar1+2 ;SomeVar1 is WORD, so next one must skip 2 bytes
SomeVar3 equ SomeVar2+1 ;SomeVar2 is BYTE.
SomeVar4 equ SomeVar3+1
SomeVar5 equ SomeVar4+2
FreeMem  equ SomeVar5+4 ;FreeMem pointer to free location.
You can set any BaseAddr value and move your variable file anywhere in RAM. And when you will assemble your ROM, it will consist only actual ROM data.
And ofcourse this is assembler. there are no restrictions to data type. Both cases used pointer to data. So, two byte variables SomeVar2 and SomeVar3 can be read as single word at pointer SomeVar2. It's very usefull when you using, for exsample, X and Y coordinates.

Code: Select all

move.b SomeVar2,d0 ; d0 will contain the X at lower byte
move.b SomeVar3,d1 ; d1 will contain the Y at lower byte
move.w SomeVar2,d2 ; d2 will contain the X and Y at lower word and X will placed to high byte, Y placed to low byte of word
Ofcourse, we can use pointer as number and use this method:

Code: Select all

move.l #SomeVar2,d0 ; We placed address (not value! using #) of variable to d0 register
move.l d0,a0        ; Then moved this address to a0 register
move.b (a0)+,d0     ; And then get access to our variables
move.b (a0)+,d1
That is enough?
tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous »

I understand both those methods, but that's a convoluted/tedious way of going about variable management. I want something more flexible and dynamically relocatable. BSS was designed specifically for this reason.

Writing equates for a few variables is fine and for a small project, but this method is a bit easier:

Code: Select all

	org $ff0000

	var1: ds.w 1			;word var
	var2: ds.l 1			;long var
	var3: ds.b 1			;byte var
	even
	array2: ds.w 40		;word array
	array3: ds.l 16		;long array
	array1: ds.b 24		;byte array
Looks clean, easy to read and understand, and you could "include" variable define files in the section without having to worry manually maintaining offsets/increments as it relocates/appends the internal symbol value for you.

But that still doesn't equate (pun intended) to what you can do with BSS. Once you define the value of BSS, you can call BSS directive in any separate source file and automatically append variables to the listing, as BSS is a self incrementing symbol system. You can define variables inside the source file and not have to worry about any offsets or address. It's extremely flexible. Whether you're writing a library file for the public or someone else to use, or even if it's a private reusable lib/code of your own.

And to be clear, my definitions are: variable = ram address (changeable), static variable = rom address(unchangeable).
Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Post by Pascal »

i'm using a BSS behavior with my rick dangerous project. The key is to compile in 2 passes and generate a .cof file on first compile. then you link. First create a .lnk file:

for my example, it'll be named "main.lnk"

Code: Select all

Cart	group  obj $0
	section	M68Kcode,Cart

68kBss	group  obj $00ff0000
	section	Vars,68kBss
	
	include rick.cof
As you can see there's 2 important section definition:
Vars : define the ram
M68Kcode : everything which go to rom

For compiling

Code: Select all

snasm68k /l -o v+ -o c+ -o m+ cart.asm,rick,rick,rick
snasm68k /p -o v+ -o c+ -o m+ main.lnk,rick.bin
And finaly in your code , just define as many sections "Vars" & "M68Kcode" you'll need. It took me a really looooooong time before figuring all this stuff without documentation ;)

Code: Select all

******************************************************************************
* Définition des variables
*******************************************************************************
	section Vars
*******************************************************************************
Rick_Vars_Start:

rand_seed	ds.l	1
rand_val	ds.l	1

loaded_world	ds.w	1
start_world	ds.w	1
byte_3F9FC	ds.b	30*8	
*******************************************************************************
       section M68Kcode
*******************************************************************************
<Code goes here>[/quote]
Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Post by Pascal »

I forgot ....

A drawback of this method, is that you can not use ORG nor ALIGN anymore

for the org,it's not problem as we have the link script. But for align, you'll have to use CNOP 0,2
tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous »

Awesome :D I'll try this out.
notaz
Very interested
Posts: 193
Joined: Mon Feb 04, 2008 11:58 pm
Location: Lithuania

Post by notaz »

Why not just use GNU toolchain instead of snasm68k and get working .bss?
plee
Very interested
Posts: 66
Joined: Wed Nov 29, 2006 11:32 am
Location: Houston, Texas

Post by plee »

The GNU assembler will allow you to use a ".bss" command

So you could do something like this:

.bss
ships ds.w 1
players ds.w 1

.text

blah....

.bss
score ds.l 1

.text

blah...


And it will resolve the addresses for you when you link. The GNU assembler is not friendly on syntax as some assemblers so hopefully you can find a better assembler :(
tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous »

Actually, "ds.x" is working fine for me at the moment. I just include my variable define files into the main file where the variable define starts. No biggie :)
Post Reply