gtBASIC
Forum rules
Be nice. No drama.
Be nice. No drama.
Re: gtBASIC
I have a question regarding Keyboard input. I am trying to check keyboard in a game loop using GET("SERIAL_RAW") there is no buffer it seems so I miss the key press if I am not checking at that point in time.
Is there a better way of getting these key presses in GTBasic ?
Is there a better way of getting these key presses in GTBasic ?
Re: gtBASIC
gtBASIC exposes every way possible way that the Gigatron has for input through GET("PS2_KEYBD"), GET("SERIAL_RAW") and GET("BUTTON_STATE"), PS2_KEYBD is just an alias for SERIAL_RAW.
- Are you trying to get PS2 keyboard scan-codes through an Arduino interface? PS2 keys last around three 60Hz frames, so unless your application is running at lower than 20Hz, you shouldn't be missing any keys.
- Are you trying to run in one of the demanding video modes, (mode 0 or 1)? Most real-time apps on the Gigatron, (30Hz to 60Hz), should be using mode 2 or 3.
- Are you trying to do edge detection?
- Can you post some simple code that shows the problem?
- Are you trying to get PS2 keyboard scan-codes through an Arduino interface? PS2 keys last around three 60Hz frames, so unless your application is running at lower than 20Hz, you shouldn't be missing any keys.
- Are you trying to run in one of the demanding video modes, (mode 0 or 1)? Most real-time apps on the Gigatron, (30Hz to 60Hz), should be using mode 2 or 3.
- Are you trying to do edge detection?
- Can you post some simple code that shows the problem?
Re: gtBASIC
So I have a Loop that scrolls a message and plays a tune
Then I have a get input function that checks if ENTER has been pressed
I have to press ENTER several times for it to be picked up
I am running in video mode 2 and on the gtemulater vX0
Loop
EnterWait:
' Scroll Message horizontally
CALL ScrollMessage
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
CALL PlayTitleTune
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
GOTO EnterWait
EndEnterWait:
Input Routine
PROC HandleInput
jj = 255
LOOPWait:
j = GET("SERIAL_RAW")
IF jj = 255
KeyPressed = j
RETURN
ENDIF
jj = j
GOTO LOOPWait
ENDPROC
Then I have a get input function that checks if ENTER has been pressed
I have to press ENTER several times for it to be picked up
I am running in video mode 2 and on the gtemulater vX0
Loop
EnterWait:
' Scroll Message horizontally
CALL ScrollMessage
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
CALL PlayTitleTune
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
GOTO EnterWait
EndEnterWait:
Input Routine
PROC HandleInput
jj = 255
LOOPWait:
j = GET("SERIAL_RAW")
IF jj = 255
KeyPressed = j
RETURN
ENDIF
jj = j
GOTO LOOPWait
ENDPROC
Re: gtBASIC
Is this the actual code sample that causes the problem? I created a version of it as below:
And it also misses keystrokes, but because the 'IF KeyPressed = 10 THEN EndEnterWait' statements goto the PROC, which is undefined, bad joojoo, etc.
Is that your problem? i.e. if I uncomment the GOTO EnterWait after the print "YES!", it works fine.
Code: Select all
_runtimePath_ "../runtime"
_codeRomType_ ROMvX0
cls
KeyPressed = 0
EnterWait:
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
'wait 120
CALL HandleInput
IF KeyPressed = 10 THEN EndEnterWait
GOTO EnterWait
EndEnterWait:
print "YES!"
'GOTO EnterWait
PROC HandleInput
jj = 255
LOOPWait:
j = GET("SERIAL_RAW")
IF jj = 255
KeyPressed = j
RETURN
ENDIF
jj = j
GOTO LOOPWait
ENDPROC
Is that your problem? i.e. if I uncomment the GOTO EnterWait after the print "YES!", it works fine.
Re: gtBASIC
The problem is caused by the scrolling routine which has a WAIT 30 in it as it scrolls text across the bottom of the screen.
If I press a key during this period it is not picked up in the next GET(SERIAL_RAW) call.
In a more advanced computer such as a VIC 20 there is a keyboard buffer which captures and keeps the previous keystrokes so this doesn't happen.
I might have to use an 'Interrupt' type of approach
If I press a key during this period it is not picked up in the next GET(SERIAL_RAW) call.
In a more advanced computer such as a VIC 20 there is a keyboard buffer which captures and keeps the previous keystrokes so this doesn't happen.
I might have to use an 'Interrupt' type of approach
Re: gtBASIC
Lots of ways to poll for keyboard during wait's, interrupts as you suggested is one, an easier way though is to write your own wait routine.
e.g.
e.g.
Code: Select all
proc myWait, ticks
local i
for i=0 to ticks
call handleInput
wait 1
next i
endproc
Re: gtBASIC
Another way to do a main loop, (rather than having busy waits), is to have it running at 60Hz or 30Hz, (depending on how complex your code is), and trigger events off that main loop at different frequencies. e.g.
Code: Select all
' you can use MOD to get finer granularity in timing, but it is much more expensive than AND
tick = 0
repeat
wait
call doSomethingAt60Hz
if (tick AND 1) = 0 then call doSomethingAt30Hz
if (tick AND 3) = 0 then call doSomethingAt15Hz
if (tick AND 7) = 0 then call doSomethingAt7_5Hz
if (tick AND 15) = 0 then call doSomethingAt3_75Hz
if (tick AND 31) = 0 then call doSomethingAt1_875Hz
inc tick
forever
Re: gtBASIC
Thank you for those suggestions. I had already moved to suggestion 1 but I really like suggestion 2 and I think I will try that for the main game flow
Re: gtBASIC
I have a question regarding MIDI and GTMIDI files. Where can I get a definition of the file structure ?
One is Text values and the other is binary. The text values don't look like standard MIDI
One is Text values and the other is binary. The text values don't look like standard MIDI