ASM6 confusion

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

ASM6 confusion

Post by za909 »

So I have a couple problems with variables and constants, and having looked at the templates made by tokumaru it's even worse in my head now. I've always been "declaring" variables simply by naming the RAM offsets like:

Code: Select all

temp_0 = $00
These are all in a separate "RAM map" source file which is included in the main source during assembly.
Am I really supposed to use the ;MyVariable0 .dsb 1 declaration instead? Or what is exactly happening in both cases?

How is .base and .org different exactly? I sort of see that .base has greater significance but I'm not entirely sure about the relation between the two.

Are constant declarations done without the $ symbol and that's it?
If MIRRORING = %0001, does that mean I can do stuff like lda #%0000|MIRRORING and then A is loaded with #$01?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 confusion

Post by tokumaru »

za909 wrote:Am I really supposed to use the ;MyVariable0 .dsb 1 declaration instead? Or what is exactly happening in both cases?
Using the equal sign you directly specify what address the variable will use, while .dsb reserves a number of bytes from the current Program Counter onward. Declaring the size of the variables instead of directly defining their addresses helps with maintainability, because you can freely rearrange, add and remove variables without worrying about fixing all the other addresses by hand, which would be tedious and error-prone once you have hundreds of variables.

If you're more comfortable using the equal sign, then go with that, but I'll bet you that when your project has grown to the point where you have hundreds of variables and arrays you'll feel the need for something easier to maintain and will look at .dsb again.
How is .base and .org different exactly?
When you use them for the first time, they do the same thing, which is set the Program Counter. After that, .org fills the ROM until the address you specify, while .base just resets the Program Counter to the value you specify without filling anything. This makes .base useful for creating multiple banks, because when the end of a bank is reached you can use .base to move the Program Counter back to the beginning and start filling the next one.
Are constant declarations done without the $ symbol and that's it?
$ is the prefix for hexadecimal, % is the prefix for binary, and unprefixed numbers are decimal. Sometimes (usually when writing to registers, but also when setting some fields in the header) it makes more sense to use binary than hex, it makes the options more readable.
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

Oh thank you! So it's sort of an automated way of creating variables, which could be global or local to a bank I declare them in I suppose.

Code: Select all

.enum $0000

temp_0 .dsb 1
temp_1 .dsb 1
;...
.ende 
So does that mean that when I say lda temp_1 it's going to load from $0001? Not that it really matters as long as everything stays the same.
That is until I re-define temp_1 somewhere else with .enum something that's not $0000.
Although I still don't get what the size argument exactly does in this case, I mean what is the second byte "called" if I declare a variable with .dsb 2? Can I only refer to it as the original name+1?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 confusion

Post by tokumaru »

za909 wrote:Oh thank you! So it's sort of an automated way of creating variables
Yes.
which could be global or local to a bank I declare them in I suppose.
I'm not sure what you mean here... these symbols will always be global, in the sense that they'll be visible everywhere. I do use local variables in my projects though, and here's how I do it:

Code: Select all

.enum $0000

GlobalVariable1 .dsb 1
GlovalVariable2 .dsb 1
GlobalVariable3 .dsb 2
Page0End

.ende
I put a label marking the end of the global variables, which I can use in other parts of the game as the starting point for the local variables:

Code: Select all

.enum Page0Locals

LocalVariable1 .dsb 1
LocalVariable2 .dsb 4

.ende
I use this kind of local variables for different areas of the game that never run simultaneously. You can even extend this further, by putting another maker at the end of the local variables and use it to declare more variables in sub-areas of each area. I do this for variables local to subroutines mostly.
So does that mean that when I say lda temp_1 it's going to load from $0001?
Exactly. But since this could change as you add/change variables, you shouldn't count on variables pointing to specific addresses. The idea is to abstract this.
That is until I re-define temp_1 somewhere else with .enum something that's not $0000.
I don't think you can redefine symbols like that, the assembler will probably throw an error. ASM6 does have temporary and local labels though, so when I need a variable I can redefine I prepend it with "-", and make sure the definition is before the code that uses the variable (the same goes for after it's redefined). This is another thing you have to do carefully, because the order in which the code is assembly will matter.
I mean what is the second byte "called" if I declare a variable with .dsb 2? Can I only refer to it as the original name+1?
Exactly. That's how you normally access multi-byte variables. I even use Name+0 for the first byte in this case, just to make it clear that it's a multi-byte variable.
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

Hey, I'm back again because I've hit a roadblock, for which I can't seem to find any explanation.
Everything is fine and dandy, but my jump table deciding which music effect to execute is completely crazy, and likely because of an assembler related issue and not because of my programming.

Code: Select all

EffByteHandler_TBL:
	.dw ChangeVolLoad,ChangeRelease,ChangeOctave,ChangeTripitchadd
	.dw NextBlock,JumpToBlock,ChangeArp,ChangeVib
	.dw ChangeDetune,ChangeDuty,ChangeTrans,CallSFX
	.dw LoadPuInst,Add2Octave,Dec2Octave,TriVolMin
	.dw TriVolMax,VibTable,ChangeCounter,GlobalTrans
So this is the table for the individual routine labels, but in the output rom, these all form words like $0000, $0100 ...
and I have absolutely no idea why ASM6 translates these labels like that. I've tried moving the table past the actual routines but it still produces the same result.
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Re: ASM6 confusion

Post by loopy »

Generate a code listing and look where your labels are at. Are you missing an .org at the top of your code?
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

No, it has .base $8000 at the top, this being a 16k UNROM bank. Also, loading words until this comes into play is working as intended.
I would create a listing, but if I launch asm6.exe from the command prompt it can't open any other included assembly sources, however when I simply drag my main source on to its icon it assembles everything properly (well other than this problem).
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Re: ASM6 confusion

Post by loopy »

za909 wrote:I would create a listing, but if I launch asm6.exe from the command prompt it can't open any other included assembly sources
I don't understand what you mean by this.
If you create a listing, it may reveal what's going wrong.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 confusion

Post by tokumaru »

za909 wrote:I would create a listing, but if I launch asm6.exe from the command prompt it can't open any other included assembly sources
If you ask it to create a listing, assembling the main source file will generate a listing containing everything, even the included files.
however when I simply drag my main source on to its icon it assembles everything properly (well other than this problem).
When you drag a file over an executable in windows, it calls that program passing the file you dragged as the first parameter.

This is actually a very bad way to assemble your programs. First because you can't see the assembler's output (because the command window closes too quickly), and that output is essential for debugging assembly errors. Second, because you can't use other features of the assembler, such as the generation of listing files.

To create the listing file, you'll have to call ASM6 with -l as the first parameter, and the main source file as the second. If you have ASM6 in the same folder as the main source file, this is as simple as creating a text file named assemble.bat with the following text in it: asm6 -l main.asm game.nes

Optionally, you can put a "pause" command (without quotes) in the next line, which will prevent the window from closing before you press a key, giving you time to read the assembler's output. Anyway, just double click the batch file to assemble your project.

If the assembler is in a separate folder, you can still create the batch file in the game's folder, but you'll have to write the full path to the assembler. Something like: c:/programs/asm6/asm6 -l main.asm game.nes
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

Yeah I got it working, the assembler was not in the same folder as my sources.
So I got the listing and the labels are at the right place, because other word tables function as they should, but for the jump table ones I get this:

Code: Select all

08168                              ChangeVolLoad:
08174                              ChangeRelease:
0818D                              ChangeOctave:
08199                              ChangeTripitchadd:

;...

082F1                           EffByteHandler_TBL:
082F1 00 00 01 00 02 00 03 00   	.dw ChangeVolLoad,ChangeRelease,ChangeOctave,ChangeTripitchadd
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 confusion

Post by tokumaru »

Weird... did you try using the addresses some other way near the EffByteHandler_TBL table? Like, try JMP ChangeRelease, .db <ChangeRelease, just to see if the address shows up correctly in those cases. I have no idea what could be causing this though... I've never had any problems like this in ASM6.
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

Nope, still nothing. Splitting them into bytes makes no difference, and even a regular "jmp something" I put right after the Init jump at $8000 still turns into 4C 00 00. I also tried putting .org $816B right before the first of the problematic labels to make sure the assembler PC is at the right value and it still turns into incorrect values.
It's not the end of the world, I can always use the listing and put the right words there manually, if they all work I'll never need to change them anyway and adding more won't push them as long as the table is after the routines.
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Re: ASM6 confusion

Post by loopy »

I'd need to look at the source code to figure out what's going on. It should not be doing what you describe.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 confusion

Post by tokumaru »

Even if you can get around the problem this time by using the addresses directly, this is a serious issue that should be looked into. Tables of pointers are often used for many other things, so the chances of this problem showing up somewhere else are quite high.

Would you mind sharing the complete listing file so we can take a better look at it?
User avatar
za909
Posts: 229
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: ASM6 confusion

Post by za909 »

It's an interesting situation, because I'll either embarass myself somehow, or be the catalyst to finding something so broken.
Don't mind the sound effect parts or anything because that's not finished yet. It probably has a lot of unorthodox methods but I can always go back and improve it once it works. (I had to turn it into a text file because apparently .lst is not allowed)

EDIT: Oh never mind I see what it is. I wanted to also assign these names to constants and that's where the problem lies
Attachments
MainSource.txt
(92.22 KiB) Downloaded 92 times
Post Reply