gtBASIC

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

I will probably add a label modifier that allows you to manually disable the emitted push for gosub labels, thus giving the programmer maximum flexibility, (super dangerous, but must be manually enabled, so user assumes all responsibility).

Something like this:

Code: Select all

MODDLST:(NO_PUSH)
    asm
        PUSH
    endasm
MODDLST1:
    print "TITLE3" 
return
This would then save the LSLW dummy instruction, (which is super bodge), and hence 1 byte.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

Once you get to the limits of RAM on ROMv5 or lower you'll have to start using the & and && optimisations on goto's and relational expressions, they are annoying as hell to use as once you add one, it can invalidate others as the code changes size and crosses page boundaries at different points, but is the only way to claw back RAM from code.

These optimisations are not needed for ROMvX0.

Here's a quick synopsis of how they work:

Code: Select all

The & symbol is used to control how branches and jumps are optimised. e.g.

    No '&' symbol produces ordinary code that allows the full use of relational logic, (but produces the slowest and
    largest code).

if (a = 1) AND (b = 2)
    ...
endif

    One '&' symbol removes the call to the runtime relational logic subroutines and uses jump macros that can jump
    between pages, (this produces faster and slightly smaller code at the expense of not allowing relational operators).
    So to implement the above if statement you would need to do something like this:

if &a = 1
    if &b = 2
        ...
    endif
endif

    Two '&&' symbols does the same as one '&' symbol but goes even further and replaces the jump macros with inline
    branches for the most optimal production of code in terms of speed and size, (branches are limited to branching
    within the same page which can be quite limiting depending on the size of the page, e.g. offscreen video memory pages).

if &&a = 1
    if &&b = 2
        ...
    endif
endif

I use option 1 for general code readability and when debugging algorithms.

I use option 2 when beginning the optimisation phase, it can substantially increase code speed but more importantly reduce
code size and thus allowing for more code to be added once you start hitting the Gigatron's RAM limits.

I use option 3 inside tight loops and when I have completely run out of Gigatron RAM, it's the most powerful of the user
controllable optimisation hints, but produces code that is inherently page limited with branches. e.g. you optimise a
subroutine using '&&' which may save you many tens of bytes, this now relocates all subsequent code at higher addresses by
those tens of bytes. If any of the subsequent code at higher addresses also contains '&&' optimisations then it has a good
chance of breaking as it produces code that tries to branch between pages, (the optimiser pass will warn you of these
situations and not allow the code to compile or run).

I basically never use '&&' unless the code is in an inner tight loop or I have run out of RAM, PucMon extensively uses it
throughout the entirety of it's code, without this hint PucMon would never have been possible with sound effects, (the '&&'
hint saved around 3.5K of RAM for the entire project).

Note the '&' hint can be used on for next loops, repeat until loops, goto's and gosub's as well, basically code that can
generate some kind of jump can be optimised into a branch using '&'.

The '&&' hint is only used for IF statements.
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

That will be a helpful optimisation tool when I get the code better ported. Thank you
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

If you are interested. This is the full array I am trying to define in my program but which falls apart even with your fix from the other day.
If I remove the comments the array fails at the second line on the 0x05.

Code: Select all

const EOP       = 0x40                                 		' End of phrase
const EOS       = 0x80                                 		' End of segment
const LONG      = 0xC0                                 		' Display title phrase for a long time

															' Title Phrase Offset, Text

DIM PHRASETAB%(129)  =  		{0x00,                             		' (unused)
						0x05,0x06,0x02 OR EOP,              ' $01  "ATTACK COMPUTER ON"
						0x05,0x06,0x03 OR EOP,              ' $04  "ATTACK COMPUTER OFF"
						0x04,0x02 OR EOP,                   ' $07  "SHIELDS ON"
						0x04,0x03 OR EOP,                   ' $09  "SHIELDS OFF"
						0x06,0x07,0x02 OR EOP,              ' $0B  "COMPUTER TRACKING ON"
						0x07,0x03 OR EOP,                   ' $0E  "TRACKING OFF"
						0x08 OR EOP,                        ' $10  "WHATS WRONG?"
						0x09,0x0A OR EOP,                   ' $11  "HYPERWARP ENGAGED"
						0x0B,0x0D OR LONG,                  ' $13  "STARBASE SURROUNDED"
						0x0B,0x0C OR LONG,                  ' $15  "STARBASE DESTROYED"
						0x09,0x0E OR EOP,                   ' $17  "HYPERWARP ABORTED"
						0x09,0x0F OR EOP,                   ' $19  "HYPERWARP COMPLETE"
						0x10 OR LONG,                       ' $1B  "HYPERSPACE"
						0x11,0x12 OR EOS,                   ' $1C  "ORBIT ESTABLISHED"
						0x16 OR EOP,                        ' $1E  "STANDBY"
						0x13,0x0E OR EOP,                   ' $1F  "DOCKING ABORTED"
						0x15,0x0F OR EOP,                   ' $21  "TRANSFER COMPLETE"
						0x38 OR EOS,                        ' $23  " "
						0x17 OR EOS,                        ' $24  "STAR FLEET TO"
						0x19 OR EOS,                        ' $25  "ALL UNITS"
						0x18 OR EOS,                        ' $26  "STAR CRUISER 7"
						0x0C OR EOS,                        ' $27  "DESTROYED"
						0x1D OR EOS,                        ' $28  "BY ZYLON FIRE"
						0x1E,0x1F OR EOS,                   ' $29  "POSTHUMOUS RANK IS:"
						0xFD,                             	' $2B  "<PLACEHOLDER FOR RANK>"
						0x25,0xFC,                          ' $2C  "CLASS <PLACEHOLDER FOR CLASS>"
						0x38 OR EOP,                        ' $2E  " "
						0x1B OR EOS,                        ' $2F  "STAR RAIDERS"
						0x20 OR EOP,                        ' $30  "COPYRIGHT ATARI 1979"
						0x38 OR EOS,                        ' $31  " "
						0x17 OR EOS,                        ' $32  "STAR FLEET TO"
						0x18 OR EOS,                        ' $33  "STAR CRUISER 7"
						0x1A,0x0E OR EOS,                   ' $34  "MISSION ABORTED"
						0x1C,0x14 OR EOS,                   ' $36  "ZERO ENERGY"
						0x24,0x1F OR EOS,                   ' $38  "NEW RANK IS"
						0xFD,                             	' $3A  "<PLACEHOLDER FOR RANK>"
						0x25,0xFC,                         	' $3B  "CLASS <PLACEHOLDER FOR CLASS>"
						0x27 OR EOS,                        ' $3D  "REPORT TO BASE"
						0x28 OR EOP,                        ' $3E  "FOR TRAINING"
						0x38 OR EOS,                        ' $3F  " "
						0x17 OR EOS,                        ' $40  "STAR FLEET TO"
						0x18 OR EOS,                        ' $41  "STAR CRUISER 7"
						0x1A,0x0F OR EOS,                   ' $42  "MISSION COMPLETE"
						0x24,0x1F OR EOS,                   ' $44  "NEW RANK IS:"
						0xFD,                             	' $46  "<PLACEHOLDER FOR RANK>"
						0x25,0xFC,                         	' $47  "CLASS <PLACEHOLDER FOR CLASS>"
						0x26 OR EOP,                        ' $49  "CONGRATULATIONS"
						0x2C,0x1A OR EOP,                   ' $4A  "NOVICE MISSION"
						0x2E,0x1A OR EOP,                   ' $4C  "PILOT MISSION"
						0x31,0x1A OR EOP,                   ' $4E  "WARRIOR MISSION"
						0x33,0x1A OR EOP,                   ' $50  "COMMANDER MISSION"
						0x38 OR EOS,                        ' $52  " "
						0x34,0x36 OR EOP,                   ' $53  "DAMAGE CONTROL"
						0x37,0x35 OR EOS,                   ' $55  "PHOTONS DAMAGED"
						0x38 OR EOP,                        ' $57  " "
						0x37,0x0C OR EOS,                   ' $58  "PHOTONS DESTROYED"
						0x38 OR EOP,                        ' $5A  " "
						0x23,0x35 OR EOS,                   ' $5B  "ENGINES DAMAGED"
						0x38 OR EOP,                        ' $5D  " "
						0x23,0x0C OR EOS,                   ' $5E  "ENGINES DESTROYED"
						0x38 OR EOP,                        ' $60  " "
						0x04,0x35 OR EOS,                   ' $61  "SHIELDS DAMAGED"
						0x38 OR EOP,                        ' $63  " "
						0x04,0x0C OR EOS,                   ' $64  "SHIELDS DESTROYED"
						0x38 OR EOP,                        ' $66  " "
						0x06,0x35 OR EOS,                   ' $67  "COMPUTER DAMAGED"
						0x38 OR EOP,                        ' $69  " "
						0x06,0x0C OR EOS,                   ' $6A  "COMPUTER DESTROYED"
						0x38 OR EOP,                        ' $6C  " "
						0x22 OR EOS,                        ' $6D  "SECTOR SCAN"
						0x35 OR EOP,                        ' $6E  "DAMAGED"
						0x22 OR EOS,                        ' $6F  "SECTOR SCAN"
						0x0C OR EOP,                        ' $70  "DESTROYED"
						0x21 OR EOS,                        ' $71  "SUB-SPACE RADIO"
						0x35 OR EOP,                        ' $72  "DAMAGED"
						0x21 OR EOS,                        ' $73  "SUB-SPACE RADIO"
						0x0C OR EOP,                        ' $74  "DESTROYED"
						0x01 OR LONG,                       ' $75  "RED ALERT"
						0x38 OR EOS,                        ' $76  " "
						0x17 OR EOS,                        ' $77  "STAR FLEET TO"
						0x18 OR EOS,                        ' $78  "STAR CRUISER 7"
						0x1A,0x0E OR EOS,                   ' $79  "MISSION ABORTED"
						0x24,0x1F OR EOS,                   ' $7B  "NEW RANK IS:"
						0xFD,                             	' $7D  "<PLACEHOLDER FOR RANK>"
						0x25,0xFC,                         	' $7E  "CLASS <PLACEHOLDER FOR CLASS>"
						0x26 OR EOP}                        ' $80  "CONGRATULATIONS"
 
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

Try this:

Revert the change you made to line 2529 in keywords.cpp, so it should look like this:

Code: Select all

            std::string initText = codeLine._code.substr(equalsPos + 1);
            Expression::stripWhitespace(initText);
            std::vector<std::string> initTokens = Expression::tokenise(initText, ',', true);
And swap lines 358 and 359 in compiler.cpp, so that they look like this:

Code: Select all

            lineToken = Expression::removeCommentsNotInStrings(lineToken);
            inp._text += lineToken;
With these changes I was able to compile your array and all my test samples, I didn't test the changes I posted yesterday fully :/
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

Nearly perfect now. When I applied that last change I had many errors to correct as I have several arrays defined in the same way and various errors had been masked previously.

I reverted that array definition from a temporary fix which recovered 1200 bytes of memory :)

Now I can move on quickly.

Thank you so much. Great compiler and improving all the time
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

If you find more compiler bugs, (which I am sure you will), posting small code snippets like you did above will make it much simpler for me to provide working and tested fixes, cheers.
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

I have a weird problem at moment. When I set the Variable TEST below it automatically changes JOYSTICKX to be the same.
If I add a line to set JOYSTICKX then TEST changes to equal.
JOYSTICKX is defined at the beginning of the program and TEST is defined in this code. I have tried moving things around thinking there was a clash but nothing changed.

Code: Select all

	
	A = 60
	PRINT "JOYSTICKX INIT1f = ";JOYSTICKX
	TEST = L_TOKEN AND 0xC0						' Test Bits 6 and 7
	PRINT "JOYSTICKX INIT1g = ";JOYSTICKX
	PRINT "TEST = ";TEST
	WAIT 500
	IF TEST = 0 THEN GOTO SKIP182				' %00 -> Copy next word to title line
	IF TEST = 0x40 THEN GOTO SKIP183			' %01 -> End-of-phrase, short delay, hide title line
	A = 254                						'        Title segment lifetime := 60 game loops
Attachments
codeproblem.jpg
codeproblem.jpg (249.66 KiB) Viewed 1464 times
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

It's probably two variables with the same address, there is a couple of ways that can happen, but the compiler should warn you about all of them.

The first thing to do is to verify if those vars have same the address, either view the corresponding .gasm file produced by the compiler and search for their definitions, or use the @ shortcut to print out their address in code.

If they are not the same address, then you have indeed found some sort of bug I have never come across and I will need a code segment that can reproduce it.

If they do have the same address, (did you check the console for warnings?), then the compiler should have reported that, if it didn't then I will again need a code segment with the reproducible bug.
wbushby
Posts: 208
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

They have the same address.
Is that this warning ?
Attachments
bug.jpg
bug.jpg (293.95 KiB) Viewed 1433 times
Post Reply