gtBASIC

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

Re: gtBASIC

Post by at67 »

You've found another bug in the parser, you have \t, (i.e. real tabs as whitespace), the parser expects spaces as all my editors expand \t to spaces.

I'll fix that for the next release, for now either replace your tabs with spaces or set your editor to do it automatically.
at67
Posts: 389
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

If you'd like to be able to use tabs in the current compiler, then you can add the following two patches to expression.cpp

Patch 1: change 1047-1053 from:

Code: Select all

            while(*str  &&  (*str != c  ||  (numQuotes & 1)  ||  numBrackets))
            {
                if(*str == '"'  &&  (str == begin  ||  (str > begin  &&  *(str-1) != '\\'))) numQuotes++;
                if(*str == '(') numBrackets++;
                if(*str == ')') numBrackets--;
                str++;
            }
To:

Code: Select all

            while(*str)
            {
                bool foundChar = (c == ' ') ? isSpace(*str) : (*str == c);
                if(!foundChar  ||  (numQuotes & 1)  ||  numBrackets)
                {
                    if(*str == '"'  &&  (str == begin  ||  (str > begin  &&  *(str-1) != '\\'))) numQuotes++;
                    if(*str == '(') numBrackets++;
                    if(*str == ')') numBrackets--;
                    str++;
                }
                else
                {
                    break;
                }
            }
Patch 2: change 1078 - 1082 from:

Code: Select all

            while(*str  &&  (*str != c  ||  (numQuotes & 1)))
            {
                if(*str == '"'  &&  (str == begin  ||  (str > begin  &&  *(str-1) != '\\'))) numQuotes++;
                str++;
            }
To:

Code: Select all

            while(*str)
            {
                bool foundChar = (c == ' ') ? isSpace(*str) : (*str == c);
                if(!foundChar  ||  (numQuotes & 1))
                {
                    if(*str == '"'  &&  (str == begin  ||  (str > begin  &&  *(str-1) != '\\'))) numQuotes++;
                    str++;
                }
                else
                {
                    break;
                }
            }
at67
Posts: 389
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

Optimiser patch for current release of gtBASIC/gtemuAT67 1.0.9R, increases speed of the optimiser by 10x to 20x, depending on the project.

Edit optimiser.cpp and change the following at lines 1084 - 1093 from: (if you're using the optimiser from page 12 of this thread, then lines are 1118 to 1127)

Code: Select all

                        // Optimising can cause new optimising opportunities to present, so restart
                        goto RESTART_OPTIMISE;
                    }
                }
            }
        }

        return true;
    }
}
to: (the indentation will look a little wonky, just ignore it, it will compile fine)

Code: Select all

                           optimised = true;
                        }
                    }
                }
            }

            numOptimiserPasses++;
        }
        // Successful optimisation can cause new optimising opportunities to present themselves, so restart
        while(optimised);

        fprintf(stderr, "\n*******************************************************\n");
        fprintf(stderr, "* Optimiser performed %d passes\n", numOptimiserPasses);
        fprintf(stderr, "*******************************************************\n");

        return true;
    }
}
And lines 386 - 387 from:

Code: Select all


RESTART_OPTIMISE:
to:

Code: Select all

        bool optimised;
        int numOptimiserPasses = 0;

        do
        {
            optimised = false;
wbushby
Posts: 50
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

I have my Engine Sound playing OK but it is using too many zero page variables. I have tried to create an array to hold them but the sound routine stops playing the sound and starts just clicking.

This code works but if I replace all the address references in the ASM with the array references it doesn't.

Can the addresses be constants ?

Code: Select all

ENGINESOUND:

	sndMute = Globals(MUTE)

'	DIM sndAddr(2,2) = {&h01FA, &h01FB, &h01FC,
'					&h02FA, &h02FB, &h02FC,
'					&h03FA, &h03FB, &h03FC}
	sndVolAddr1  = &h01FA                      ' channel 1, (out of 1 to 4)
	sndWaveAddr1 = &h01FB                      ' channel 1, (out of 1 to 4)
	sndFreqAddr1 = &h01FC                      ' channel 1, (out of 1 to 4)
	sndVolAddr2  = &h02FA                      ' channel 2, (out of 1 to 4)
	sndWaveAddr2 = &h02FB                      ' channel 2, (out of 1 to 4)
	sndFreqAddr2 = &h02FC                      ' channel 2, (out of 1 to 4)
	sndVolAddr3  = &h03FA                      ' channel 3, (out of 1 to 4)
	sndWaveAddr3 = &h03FB                      ' channel 3, (out of 1 to 4)
	sndFreqAddr3 = &h03FC                      ' channel 3, (out of 1 to 4)
    	sndTimer = &h2C

	sndVol  = 127 - Globals(VELOCITY)			' 127 to 64 -> 0 to 63 volume
	sndWave = 0                                 ' wave type, (noise=0, triangle=1, square=2, ramp=3)
	sndFreq = Globals(VELOCITY) + 20
    	sndTime = 255

    asm
		LD      _sndMute
		BNE     _EndSound

        LDW     _sndFreq                    ' format = high:8 low:07, (bit 8 of low byte = 0)
        DOKE    _sndFreqAddr1                ' turn on channel
	LD      _sndVol
        POKE    _sndVolAddr1
        LD      _sndWave
        POKE    _sndWaveAddr1

        LDW     _sndFreq
	LSLW    3
        DOKE    _sndFreqAddr2                
	LD      _sndVol
        POKE    _sndVolAddr2
        LD      _sndWave
        POKE    _sndWaveAddr2

        LDW     _sndFreq
	LSLW    1
	XORI     0x8F
        DOKE    _sndFreqAddr3                
	LD      _sndVol
        POKE    _sndVolAddr3
        LD      _sndWave
        POKE    _sndWaveAddr3

        LD      _sndTime

        POKE    _sndTimer

    endasm

EndSound:

RET
at67
Posts: 389
Joined: 14 May 2018, 08:29

Re: gtBASIC

Post by at67 »

You'd have to show me the code, but generally you can't just replace zero page variable access with array accesses using the same ASM code, e.g.

Zero Page:

Code: Select all

        LDW     _sndFreq                 ' format = high:8 low:07, (bit 8 of low byte = 0)
        DOKE    _sndFreqAddr1
Non Zero Page, (e.g. DIM array of ints or DEF WORD):

Code: Select all

        LDWI    _sndFreqAddr_array + 2   ' = sndFreqAddr(1) : add _array when accessing gtBASIC arrays and *2 for words
        DEEK
        STW	_tmp
        LDW     _sndFreq
        DOKE    _tmp
wbushby
Posts: 50
Joined: 16 Jul 2021, 10:59

Re: gtBASIC

Post by wbushby »

Thank you for that information. I was able to work out my issue and move onto the next section of the code.
Post Reply