nesdev.com
http://forums.nesdev.com/

ASM6 string question
http://forums.nesdev.com/viewtopic.php?f=10&t=17423
Page 1 of 1

Author:  JoeGtake2 [ Thu Jun 07, 2018 6:39 am ]
Post subject:  ASM6 string question

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:

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 :-)

Author:  dougeff [ Thu Jun 07, 2018 7:05 am ]
Post subject:  Re: ASM6 string question

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.

Author:  JoeGtake2 [ Thu Jun 07, 2018 7:17 am ]
Post subject:  Re: ASM6 string question

Alright, let me try to explain better.

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

Code:
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:
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:
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.

Author:  dougeff [ Thu Jun 07, 2018 7:58 am ]
Post subject:  Re: ASM6 string question

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

Author:  JoeGtake2 [ Thu Jun 07, 2018 8:26 am ]
Post subject:  Re: ASM6 string question

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)

Author:  thefox [ Thu Jun 07, 2018 9:00 am ]
Post subject:  Re: ASM6 string question

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

It can be done in ca65 with .sprintf/.string/.ident.

Author:  dougeff [ Thu Jun 07, 2018 9:32 am ]
Post subject:  Re: ASM6 string question

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.

Author:  tokumaru [ Thu Jun 07, 2018 10:45 am ]
Post subject:  Re: ASM6 string question

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".

Author:  JoeGtake2 [ Thu Jun 07, 2018 11:11 am ]
Post subject:  Re: ASM6 string question

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.

Author:  tepples [ Thu Jun 07, 2018 12:16 pm ]
Post subject:  Re: ASM6 string question

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.

Author:  JoeGtake2 [ Thu Jun 07, 2018 12:33 pm ]
Post subject:  Re: ASM6 string question

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!

Author:  thefox [ Fri Jun 08, 2018 7:33 am ]
Post subject:  Re: ASM6 string question

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.

Author:  pubby [ Fri Jun 08, 2018 7:53 am ]
Post subject:  Re: ASM6 string question

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:
#define CONCAT(a, b) CONCAT_IMPL(a, b)
#define CONCAT_IMPL(a, b) a##b

#define FOO whatever_
#define BAR 0

CONCAT(FOO, BAR)

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/