jbs30000 Posted December 3, 2011 Share Posted December 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted December 3, 2011 Share Posted December 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
jbs30000 Posted December 3, 2011 Author Share Posted December 3, 2011 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? Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted December 3, 2011 Share Posted December 3, 2011 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 Quote Link to comment Share on other sites More sharing options...
jbs30000 Posted December 3, 2011 Author Share Posted December 3, 2011 Wonderful, thank you. I did read the manual, but I guess I misunderstood the part that explained that. Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted December 3, 2011 Share Posted December 3, 2011 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 1 Quote Link to comment Share on other sites More sharing options...
jbs30000 Posted December 3, 2011 Author Share Posted December 3, 2011 I understand completely. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.