Brass 3.0.0.0 Beta 13

One suite to code them all. An complete IDE and assembler for all your z80 projects!

Moderators: benryves, kv83

Post Reply
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Hm, that's one of the more novel error messages I've seen it generate. :\
User avatar
waeV
New Member
Posts: 74
Joined: Wed 23 Apr, 2008 12:52 am
Location: Maine

Post by waeV »

So, how does one use brass? Is there a tutorial nestled somewhere in this thread or summat?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

No tutorial, sorry.

If you use the installer, you should have some sample projects in your Documents directory (Documents\Brass Projects\Samples). If you open any of the .brassproj project files (double-click), hitting F6 should build them (F5 will run them). To debug you will need to copy ROMs into C:\Program Files\Brass\Debug\TI\ROMs (see ROMs.txt for information).

The easiest way to make new projects is to copy the sample directory, edit the .brassproj (it's just an XML file, any text editor will do) to the name of your program and work from that.

It's all a bit messy, but I don't have as much time to work on this (and everything else) as I'd like. :(

If you have any questions, I'd be glad to answer them!
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

Soooooo, any news?

To make this post somewhat useful:


[hr]
^ I want this tag to work >_<


I'm trying to make a label generator that generates a new label after every invoke:

Code: Select all

labelgenvar = 0
.macro GENERATE_LABEL(base, value)
    eval(strformat("{0}{1} = {2}", base, labelgenvar, value))
    labelgenvar += 1
.endmacro
Might not look useful in this state, but I have plans for something similar in my generic game engine project

The problem is that the above code doesn't seem to make the label since

Code: Select all

GENERATE_LABEL("label",5)
.db label1
Gives me a "label 'label1' not found" error.

Is something like this already possible, if so, how? If not, could you make it possible?


[hr]
^ same here


Something else:

Code: Select all

x=y
z=5
y=z
Fails with "label 'y' not found" however it is clear that there is only one possible value for x, y and z.

EDIT: of course, if you allow variables to be reassigned that would give a huge mess... Meh...
But I *really* need it in my api (idea courtesy of timendus):
api.inc wrote:

Code: Select all

;apivars = statvars ; Damn forward referencing is broken :(
apivars_size = 18
;define variables here (*)

.include "api_routines.inc"
api_routines.inc wrote:

Code: Select all

api_start
;...
smc_start
#ifdef APPLICATION
; Relocate these
$ = smc_reloc
#endif
;...
smc_end

#ifdef APPLICATION
smc_size = smc_end-smc_reloc+apivars_size
$ = smc_start+smc_size
apivars = smc_reloc+smc_size-apivars_size
#else
smc_size = smc_end-smc_start
apivars = $
.block apivars_size, 0
#endif

api_end
This gives an error in "api.inc": "label apivars not found", if I move (*) after the include then Brass3 complains about non-existent variables

Is there any way to get around this, am I missing something obvious or is there just no way?


[hr]
^ again...


And there is one more thing...

Code: Select all

.dw x,y,z
; Seems to result in
.dw z,z,z
I haven't been able to test this one thoroughly (or verify that it is my fault and not Brass3's fault)
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by benryves »

driesguldolf wrote:[hr]
^ I want this tag to work >_<
Doesn't appear to be possible with phpBB (needs start and end tags).
I'm trying to make a label generator that generates a new label after every invoke:

Code: Select all

labelgenvar = 0
.macro GENERATE_LABEL(base, value)
    eval(strformat("{0}{1} = {2}", base, labelgenvar, value))
    labelgenvar += 1
.endmacro
Might not look useful in this state, but I have plans for something similar in my generic game engine project

The problem is that the above code doesn't seem to make the label since

Code: Select all

GENERATE_LABEL("label",5)
.db label1
Gives me a "label 'label1' not found" error.

Is something like this already possible, if so, how? If not, could you make it possible?
This does appear to be broken, not sure why (probably some eval-related problem). You could use a C# script:

Code: Select all

private static int labelgenvar = 1;
public static void GENERATE_LABEL(Compiler compiler, string name, double value) {
	compiler.Labels.Add(new Label(compiler.Labels, new TokenisedSource.Token(compiler.Labels.ModuleGetFullLabelPath(name + labelgenvar)), true, value, compiler.Labels.ProgramCounter.Page, null));
	++labelgenvar;
}
...if you need to. You would use it like this:

Code: Select all

.GENERATE_LABEL "label", 5
.echoln label1 ; Outputs 5
Something else:

Code: Select all

x=y
z=5
y=z
Fails with "label 'y' not found" however it is clear that there is only one possible value for x, y and z.
You need to assign variables in order, like most other programming languages. z=5 \ y=z \ x=y works. :)
And there is one more thing...

Code: Select all

.dw x,y,z
; Seems to result in
.dw z,z,z
I haven't been able to test this one thoroughly (or verify that it is my fault and not Brass3's fault)
The values for .dw are calculated after the entire source file has been assembled. Thus:

Code: Select all

x = 1 \ y = 2 \ z = 3
.db x,y,z
x = 4 \ y = 5 \ z = 6
...assembles as 4, 5, 6.

Probably not what you wanted to hear, but it may explain what's going on...
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

Thanks for the explanation but,

About the tags, that wasn't really the point. I just want more tags to work with :P. SimpleMachinesForum has a lot more (strike trough, tables, horizontal rule, etc.)

About the .dw case, could you explain these?
http://img300.imageshack.us/img300/7278/crap1we1.png
http://img296.imageshack.us/img296/2919/crap2yk5.png
Only the 2nd is correct.

http://img228.imageshack.us/img228/2761/crap3ru7.png
Neither of the pointers are correct.
EDIT: Meh, I mislooked, only the 2nd is correct.
Last edited by driesguldolf on Tue 09 Sep, 2008 8:42 pm, edited 2 times in total.
User avatar
calc84maniac
Regular Member
Posts: 112
Joined: Wed 18 Oct, 2006 7:34 pm
Location: The ex-planet Pluto
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by calc84maniac »

You should be checking for "label0", since the counter starts at 0 and increases *after* the label is generated.
~calc84maniac has spoken.

Projects:
F-Zero 83+
Project M (Super Mario for 83+)
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

calc84maniac wrote:You should be checking for "label0", since the counter starts at 0 and increases *after* the label is generated.
Oh, lol. Unfortunately it doesn't work with label0 either.
Writing the generated label to the console indeed gives "label0" so there's no mistake that one is correct.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by benryves »

The way labels are handled and expressions are parsed is pretty lousy (eg labels can only be strings or doubles and when parsing expressions any unknown terms generate temporary labels which can confuse the assembler).

I'm glad you haven't asked about structs or array[index] type syntax as those are even more horribly broken. :( I'd very much like to rewrite this part of the assembler when I have time, with a more sensible parser and using full .NET objects as labels (which wouldn't break existing code as the assembler syntax would remain much the same, just would actually work).

I'll try to take a closer look at it soon. :|
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

Hmm, I've been thinking about a way to handle such forward referencing without breaking backwards compatibility :P

During the first phase (where macro processing happens):
Generate a list with the footprints a label when you encounter one, a footprint are the labels of which the value of this label is dependent of.
Now either:
1) The label has not yet been registered: Mark the label as "Forward reference enabled"
2) The label has already been registered: Mark it as "No forward reference allowed" (since "forward referencing" basically means a label has a universal value throughout the source, a redefinition will make the label ambiguous, instead this label will be treated as #defines)

Now before the second phase starts we're going to solve the label values:
First delete all labels who are marked as "No forward reference allowed" (these will be re-calculated during the 2nd phase).
Next create a new list of labels, these will hold the solved labels.

While the last iteration solved at least one label do:
For each label check if all the labels its value depends on is calculated (ie, the labels are found in the solved labels list), if so calculate its value and add it to the list of solved labels.
Repeat.

If there are still unsolved labels this means that there was a circular definition: Like "a=b\ b=a"

Now start the 2nd phase, using the solved labels list.


That should do the trick, what do you think?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by benryves »

A nice idea, but there is only a single pass (stuff that needs to output data based on labels that may be defined in the future registers a delegate which is invoked at the end of the pass to insert the correct values). eg ".dw somelabel" says "reserve 2 bytes for me", and at the end of the pass the assembler invokes the delegate to retrieve the proper byte[2]. Macro preprocessing is done as statements are read in from the file in the same pass.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

Ah yes, that complicates matters...

Also, I just saw that the algorithm doesn't work when "forward ref enabled" labels are defined in terms of "no forward ref allowed" labels...

I'll see if I can find a way around it :)
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by benryves »

I still stand by my original point; the expression parsing bit and handling of labels needs to be completely rewritten. The expression parser relies on each and every label in an expression already existing (even x in x=1 has to exist beforehand, so there's lots of fudging around creating potentional temporary labels), which causes all sorts of issues. It would be much nicer to just have a label reference that may - or may not - have a value, and that value is only extracted at the last minute when it's actually needed.

Allowing for full .NET objects with properties and methods makes logical sense (see how PowerShell handles this for example). There's all sorts of hackery involved with labels either being strings or numbers (including the fun feature that 'a'+1 is 'a1', not 'b' as you may expect, you need to do 'a'*1+1) as well as creating constants (values that can't be changed). Again, proper .NET objects with conversion operators and member properties would help alleviate most of these problems.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by driesguldolf »

Yeah, but that's independent of labels who allow forward referencing. I really want 'em :mad:
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: Brass 3.0.0.0 Beta 12

Post by benryves »

Well, the source is available. ;) (I kid, I wouldn't wish that monstrosity on my worst enemy). :(
Post Reply