It is currently Sat Jun 23, 2018 10:15 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: ASM6 string question
PostPosted: Thu Jun 07, 2018 6:39 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 291
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 :-)


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 7:05 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2092
Location: DIGDUG
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


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 7:17 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 291
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.


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 7:58 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2092
Location: DIGDUG
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


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 8:26 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 291
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)


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 9:00 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3078
Location: Tampere, Finland
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


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 9:32 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2092
Location: DIGDUG
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


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 10:45 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10526
Location: Rio de Janeiro - Brazil
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".


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 11:11 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 291
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.


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 12:16 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20167
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Thu Jun 07, 2018 12:33 pm 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 291
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!


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Fri Jun 08, 2018 7:33 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3078
Location: Tampere, Finland
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


Top
 Profile  
 
 Post subject: Re: ASM6 string question
PostPosted: Fri Jun 08, 2018 7:53 am 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 308
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group