Jump to content

Photo

Quick & easy (I think) Dasm DS question


6 replies to this topic

#1 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • 464 posts

Posted Sat Dec 3, 2011 1:30 AM

I tried Googling this, looking at the documentation that came with DASM (I'm using version 2.20.11), and checked my list file before deciding to ask here.

After a

SEG.U
ORG $80

I tried to see if I could initialize a ds variable.
SpriteHeight0 ds 1 = 8

Now this compiles just fine, but sometimes a program will compile but not give the desired results. So, will that code initialize the variable to 8 instead of the default 0? Thanks.

#2 GroovyBee OFFLINE  

GroovyBee

    Games Developer

  • 7,768 posts
  • Busy bee!
  • Location:North, England

Posted Sat Dec 3, 2011 2:44 AM

Unless you explicitly have code to set it to 8 it will have any random value. You need to fill the RAM with the values that you want. Since you are following the Andrew Davie tutorials, you'll see a macro near the top of your code that fills all the RAM with $00. After that, its up to you what values you put in it.

#3 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • Topic Starter
  • 464 posts

Posted Sat Dec 3, 2011 3:43 AM

Well, I've read through all of the tutorials, and I'm very slowly trying my own code now, but you make an excellent point. Even if I could initialize it, it would get wiped out with the reset code.

But I am still curious. The wording for DS says it fills the memory location with a default of 0. That makes it sound like you can intialize a DS variable to something else. So if you can, then how?

#4 GroovyBee OFFLINE  

GroovyBee

    Games Developer

  • 7,768 posts
  • Busy bee!
  • Location:North, England

Posted Sat Dec 3, 2011 3:57 AM

Well, I've read through all of the tutorials, and I'm very slowly trying my own code now, but you make an excellent point. Even if I could initialize it, it would get wiped out with the reset code.


It depends where you initialise it ;). If its before the RAM clearing macro it'll be set to $00 by the time you read it. If its after the RAM clearing macro it will remain at that value (providing nothing else touches it) until you power off the console.

But I am still curious. The wording for DS says it fills the memory location with a default of 0. That makes it sound like you can intialize a DS variable to something else. So if you can, then how?


Just checked the DASM manual (I don't use that assembler) and the DS assembler directive takes the following form :-

[label] ds[.bwl] exp[,filler]

To have a value of 8 in ROM you would use :-

	ds.b 1, 8

More commonly you'd use dc (declare constant) :-

	dc.b 8


#5 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • Topic Starter
  • 464 posts

Posted Sat Dec 3, 2011 4:01 AM

Wonderful, thank you.

I did read the manual, but I guess I misunderstood the part that explained that.

#6 Andrew Davie OFFLINE  

Andrew Davie

    Stargunner

  • 1,583 posts
  • Dr.Boo
  • Location:Tasmania

Posted Sat Dec 3, 2011 9:05 AM

Don't forget that you are building a ROM file with DASM. As such, there's no concept of intialising *variables* because variables are in RAM. You use RAM, yes. But the assembler is making a ROM binary. So, the first answer is -- you don't initialise variables through some sort of DASM trickery.

When you use SEG.U you are telling DASM that this is an *uninitialised* segment. What you're really doing is saying that all data in the segment is pretty much only for the purposes of generating labels and calculating addresses. There is no actual data generated in the ROM binary that DASM is creating. And so, DS becomes very useful for variable definition, insofar as calculating the addresses of variables. But *not* initialising the contents of those variables.

But there is one instance where you can use DS to initialise variables... and that's where you copy some ROM code/variables to RAM for execution. In that case, you can have DASM initialise the variables through DS or any other method. They're not variables while in ROM, but after you copy the ROM data to the appropriate RAM location, you have all your variables auto-initialised.

There are a number of ways for DASM to define bytes, characters, etc. Personally I use ".byte" for defining bytes, but you can use this sort of thing too... "ds 4, %11000000". That will place 4 bytes in the ROM of value %11000000. Note, we're still not initialising variables -- we're simply setting values in the ROM binary.

Hope this helps clear things up.

Cheers
A

#7 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • Topic Starter
  • 464 posts

Posted Sat Dec 3, 2011 2:17 PM

I understand completely. Thank you.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users