ASM6 string question

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

Post Reply
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

ASM6 string question

Post by JoeGtake2 »

Hey all - I know some of the answers will be "use this other assembler"...so we'll skip those for a moment. :-)

Recently I was inquiring about getting specific strings, and was shown the EQU opcode. It works like a charm for the purpose I needed.

To extend the question, though, does anyone know of the proper syntax, or if it's even possible, to get a variable value for an EQU? What I mean is something like this (this is not any sort of real code, just to demonstrate the desired result)

Code: Select all


SOME_CONSTANT EQU whatever_
SOME_CONSTANT_2 = $00
SOME_CONSTANT_3 EQU _thing

value = #SOME_CONSTANT + SOME_CONSTANT_2 + #SOME_CONSTANT_3
;;; to where value would then be whatever_00_thing 

I obviously know THAT won't work. I'd be surprised if this is somehow NOT possible, to get a variable string like this, but I've tried a bunch of things to no avail.

Any advice? It's totally a *want* and not a *need*, but it would make some things cleaner for me :-)
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: ASM6 string question

Post by dougeff »

I don't really understand what you want. But the #s might be the problem.

you can give a value to a constant.

Foo = 2

the # is to tell the assembler to use immediate mode.

lda #foo ;a9 02

rather than zero page

lda foo ;a5 02

you can add constants when used

lda #constant1 + constant2 + constant3

this works.
nesdoug.com -- blog/tutorial on programming for the NES
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: ASM6 string question

Post by JoeGtake2 »

Alright, let me try to explain better.

Let's say I have a constant that represents a variable image.

Code: Select all

VARIABLE_IMAGE_0 = #$00
VARIABLE_IMAGE_1 = #$19
And I want to create some sort of procedural string to call the VARIABLE_IMAGE, based on a variable, without taking up the ROM space...

So my thought was, if I made a constant that was a string, like this:

Code: Select all

TEST EQU VARIABLE_IMAGE_
And could add the string of the variable, I'd be able to procedurally load the variable image constant.

Basically I'm trying to use this method to execute a string, which is pretty common in higher level languages, and easy. I was just wondering if I could bend this to do the same.

But if I do this:

Code: Select all

CONSTANT_0 EQU Whatever_
CONSTANT_1 = 0
Whatever_0 = $05

;;;; THIS DOES NOT WORK
LDA #CONSTANT_0 + CONSTANT_1

;;; what I'm hoping to get is the value in Whatever_0, which would be 5.

;;; additionally, CONSTANT_1 EQU 0, which should make it a "STRING" 0 rather than a numeric value, does not allow it to work either.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: ASM6 string question

Post by dougeff »

LDA #CONSTANT_0 + CONSTANT_1

turns into

LDA #Whatever_ + CONSTANT_1

since it replaces "CONSTANT_0" with "Whatever_"

You haven't defined Whatever_

Perhaps you wanted

CONSTANT_ EQU Whatever_

so the assembler turns

LDA #CONSTANT_0 + CONSTANT_1

into

LDA #Whatever_0 + CONSTANT_1
nesdoug.com -- blog/tutorial on programming for the NES
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: ASM6 string question

Post by JoeGtake2 »

I'm trying to have it merge the EQU strings of two constants.

So...it's replacing CONSTANT_0 with Whatever_ and CONSTANT_1 with 0, so then a new value becomes Whatever_0, and then reading the value of Whatever_0

Is this not possible?

(the addition is not meant to ADD a value of CONSTANT_1 to what is in Whatever_. I'm trying to have it read a full string of CONSTANT_0 followed by CONSTANT_1

So if CONSTANT_0 EQU Nes and CONSTANT_1 EQU Dev, I could set CONSTANT_Z to be NesDev...effectively CONSTANT_0CONSTANT_1, but I don't know if there is a syntax for that)
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: ASM6 string question

Post by thefox »

I don't think it's possible to do this in asm6.

It can be done in ca65 with .sprintf/.string/.ident.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: ASM6 string question

Post by dougeff »

Oh I get it now. Concatinating 2 strings to equal another string that is a label with a value.

What about skipping the plus sign?

CONSTANT_ EQU Whatever_
ZERO EQU 0
Whatever_0 = [some value]

LDA #CONSTANT_ZERO

I don't think it would work, but I might try it.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 string question

Post by tokumaru »

I don't think this is possible in ASM6. Also, a small correction: EQU is not an opcode, since it does not translate into a code that represents a CPU instruction. I believe the correct term is "assembler directive".
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: ASM6 string question

Post by JoeGtake2 »

Tokumaru - haha thanks. Yeah, just trying to be close enough with the nomenclature for ASM to have people understand me. I would've likely called it an assembler operation if I'd really thought it through. haha. And drat. Curses. Was hoping.

And Dougeff - yeah, you're getting close to what I'm looking for. THAT'S the sort of thing I was trying, but it kicks back an unknown variable error...which makes sense because it doesn't respect that they're two values and can't find the single value. Also, with a space there, it kicks back an error, presumably because it doesn't find a variable with a space. Also tried, for kicks, with quotes, but that as I figured was a wash.

Ah well. Worth a try. If anyone DOES have a solution for this, let me know, and I appreciate the feedback! I half expected "no, ASM6 can't do that" anyway.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: ASM6 string question

Post by tepples »

You could write a preprocessor in Perl, Python, Lua, or your favorite text manipulation language that processes each file before handing it off to ASM6.
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: ASM6 string question

Post by JoeGtake2 »

Tepples - yeah, that's sort of where our minds started going, just wondering if it was possible using what we were already using in a creative way. Thanks!
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: ASM6 string question

Post by thefox »

You might also be able to exploit the C preprocessor for this (e.g., in cc65: cc65 -E filein.txt -o fileout.txt). But the C preprocessor is quite limited so things might get ugly pretty quickly.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: ASM6 string question

Post by pubby »

thefox wrote:You might also be able to exploit the C preprocessor for this (e.g., in cc65: cc65 -E filein.txt -o fileout.txt). But the C preprocessor is quite limited so things might get ugly pretty quickly.
you'd have to do stuff like

Code: Select all

#define CONCAT(a, b) CONCAT_IMPL(a, b)
#define CONCAT_IMPL(a, b) a##b

#define FOO whatever_
#define BAR 0

CONCAT(FOO, BAR)
Post Reply