Page 14 of 44
Re: gtBASIC
Posted: 16 Sep 2021, 12:51
by wbushby
Neither set or get are working. same error
Assembler::assemble() : 'starraiders64k.gasm:3919' : invalid label/equate 'realTS_rti'
Re: gtBASIC
Posted: 17 Sep 2021, 02:00
by wbushby
I am struggling with the sound in assembler. Best I could figure out for Channel 1 is this:
POKE 0x01FC, SX ' Frequency
POKE 0x01FE, SX + 10 ' Volume
POKE 0x2C, 255 ' Timer
But I get a short staccato sound.
Re: gtBASIC
Posted: 17 Sep 2021, 10:49
by at67
It doesn't work like that, it's more complicated :/
- Ignore xxFE and xxFF they are free running timers used by the audio subsytem.
- Frequency is a 15bit value, high byte into xxFD, low byte, (7bits shifted right once), into xxFC, xx = 01 to 04 for channel 1 to 4. If you want to skip the shift right of the low byte for sound effects you can, you only need the shift right for accurate musical notes, so DOKE xxFC, freq_15bit
- Volume is a 7bit value value between 127 and 64 for volume = 0 to 63, so POKE xxFA, (63-v) + 64.
- Wave type, (0 to 3, i.e. noise, triangle, square, ramp), so POKE xxFB, wave AND 3, higher values will modulate the signal for effects, you need to experiment).
- audio.i in gbas/runtime has assembly source code.
Re: gtBASIC
Posted: 17 Sep 2021, 14:31
by wbushby
I had tried the code in audio.i but I am missing something.
Compiler::createAsmLine() : 'Main:6653' : vASM syntax error, undefined opcode : sndChannel EQU register8
Code: Select all
ENGINESOUND:
asm
sndChannel EQU register8
sndFrequency EQU register9
sndVolume EQU register10
LDI 0xFC
ST sndChannel
LD _SX
SYS 48
ST sndFrequency ; right shift low byte of sndFrequency by 1
LDW sndFrequency ; format = high:8 low:07, (bit 7 of low byte = 0)
DOKE sndChannel ; turn on channel
endasm
RET
Re: gtBASIC
Posted: 17 Sep 2021, 22:40
by at67
There's a few things wrong with your code:
1) Equates and labels have to start in the first column of the line otherwise they will be interpreted as opcodes, (that's why your equates are giving that error message).
2) The registerX equates are defined in gigatron.i, but you don't want to use the gtBASIC internal register vars in an interrupt routine as that is what causes the race conditions between the interrupt routine and gtBASIC, (use your own vars).
3) You are using SYS 48 on it's own, which will cause undefined behaviour depending on the contents of sysFn, (0x0022), you need to load sysFn first, then use SYS with the corresponding number of ticks for that sys function. So in your case if you want the right shift by 1 sys function, (SYS_LSRW1_48), then you need to pre-load sysFn and use sys in the following way:
Code: Select all
LDWI SYS_LSRW1_48
STW giga_sysFn
.
.
.
SYS 48 ' shifts AC right by 1 bit
Here is a version of your code that has more chance to succeed: (*note* I didn't test this)
Code: Select all
' more accurate frequency version, (only needed for musical note accuracy)
ENGINESOUND_NOTE:
sndVolAddr = &h01FA ; channel 1, (out of 1 to 4)
sndWaveAddr = &h01FB ; channel 1, (out of 1 to 4)
sndFreqAddr = &h01FC ; channel 1, (out of 1 to 4)
sndVol = 96 ; 127 to 64 -> 0 to 63 volume
sndWave = 3 ; wave type, (noise=0, triangle=1, square=2, ramp=3)
sndFreq = 2000
asm
LDWI SYS_LSRW1_48
STW giga_sysFn
LD _sndFreq ; use underscores when accessing gtBASIC vars in asm
SYS 48
ST _sndFreq ; use underscores when accessing gtBASIC vars in asm
LDW _sndFreq ; format = high:8 low:07, (bit 8 of low byte = 0)
DOKE _sndFreqAddr ; turn on channel
LD _sndVol
POKE _sndVolAddr
LD _sndWave
POKE _sndWaveAddr
endasm
RET
' less accurate frequency version, (use for sound effects)
ENGINESOUND_FX:
sndVolAddr = &h01FA ; channel 1, (out of 1 to 4)
sndWaveAddr = &h01FB ; channel 1, (out of 1 to 4)
sndFreqAddr = &h01FC ; channel 1, (out of 1 to 4)
sndVol = 96 ; 127 to 64 -> 0 to 63 volume
sndWave = 3 ; wave type, (noise=0, triangle=1, square=2, ramp=3)
sndFreq = 2000
asm
LDW _sndFreq ; format = high:8 low:07, (bit 8 of low byte = 0)
DOKE _sndFreqAddr ; turn on channel
LD _sndVol
POKE _sndVolAddr
LD _sndWave
POKE _sndWaveAddr
endasm
RET
Re: gtBASIC
Posted: 17 Sep 2021, 22:59
by wbushby
Unfortunately that doesn't compile. just returns with no error message immediately.
gtbasic v1.0.9R
*******************************************************
* Compiling file './starraiders64k.gbas'
*******************************************************
C:\RetroComputors\Gigatron\gigatron-rom-master\gigatron-rom-master\Contrib\at67\gbas\classic\Test>
I copied the exact routine in as presented.
Re: gtBASIC
Posted: 17 Sep 2021, 23:18
by at67
Change all the semi-colons to single quotes, it's a parsing bug in your version of the compiler, I just tested this and it works:
Code: Select all
_runtimePath_ "../runtime"
_runtimeStart_ &h7FFF
_codeRomType_ ROMv3
repeat
POKE &h2C, 255
gosub ENGINESOUND_FX
forever
' less accurate frequency version, (use for sound effects)
ENGINESOUND_FX:
sndVolAddr = &h01FA ' channel 1, (out of 1 to 4)
sndWaveAddr = &h01FB ' channel 1, (out of 1 to 4)
sndFreqAddr = &h01FC ' channel 1, (out of 1 to 4)
sndVol = 64 ' 127 to 64 -> 0 to 63 volume
sndWave = 1 ' wave type, (noise=0, triangle=1, square=2, ramp=3)
sndFreq = 12000
asm
LDW _sndFreq ' format = high:8 low:07, (bit 8 of low byte = 0)
DOKE _sndFreqAddr ' turn on channel
LD _sndVol
POKE _sndVolAddr
LD _sndWave
POKE _sndWaveAddr
endasm
RETURN
Re: gtBASIC
Posted: 18 Sep 2021, 00:18
by at67
Here's a slightly better example:
Code: Select all
_runtimePath_ "../runtime"
_runtimeStart_ &h7FFF
_codeRomType_ ROMv1
sndVolAddr = &h01FA ' channel 1, (out of 1 to 4)
sndWaveAddr = &h01FB ' channel 1, (out of 1 to 4)
sndFreqAddr = &h01FC ' channel 1, (out of 1 to 4)
sndVol = 64 ' 127 to 64 -> 0 to 63 volume
sndWave = 2 ' wave type, (noise=0, triangle=1, square=2, ramp=3)
sndFreq = 5000
step = 300
repeat
wait 1
set SOUND_TIMER, 5 ' enable all sound for 5 ticks, (>= 1 for this loop is fine)
gosub DUMB_SIREN_FX:
sndFreq = sndFreq + step
if (sndFreq > 14000) OR (sndFreq < 1500) then step = -step
forever
' less accurate frequency version, (use for sound effects)
DUMB_SIREN_FX:
asm
LDW _sndFreq ' format = high:8 low:07, (bit 8 of low byte = 0)
DOKE _sndFreqAddr ' turn on channel
LD _sndVol
POKE _sndVolAddr
LD _sndWave
POKE _sndWaveAddr
endasm
RETURN
Re: gtBASIC
Posted: 18 Sep 2021, 01:52
by wbushby
I have been having one of those days. I completely missed the semi-colon
I also soldered a CPLD on turned 180 degrees today as well
Re: gtBASIC
Posted: 18 Sep 2021, 10:03
by wbushby
I am just not getting this for some reason.
Compiler::createAsmLine() : 'Main:6668' : vASM syntax error, undefined opcode : LD _sndTime
Compiler::factor() : 'Main:6617' : found an unknown symbol 'LD _sndTime' : LD _sndTime
I don't see the difference between sndTime and sndFreq which works
Code: Select all
ENGINESOUND2:
sndVolAddr = &h01FA ' channel 1, (out of 1 to 4)
sndWaveAddr = &h01FB ' channel 1, (out of 1 to 4)
sndFreqAddr = &h01FC ' channel 1, (out of 1 to 4)
sndTimer = &h2C
sndVol = 120 ' 127 to 64 -> 0 to 63 volume
sndWave = 0 ' wave type, (noise=0, triangle=1, square=2, ramp=3)
sndFreq = 44
sndTime = 255
asm
LDW _sndFreq ' format = high:8 low:07, (bit 8 of low byte = 0)
DOKE _sndFreqAddr ' turn on channel
LD _sndVol
POKE _sndVolAddr
LD _sndWave
POKE _sndWaveAddr
LD _sndTime
POKE _sndTimer
endasm
RET