jsbasic
jsbasic copied to clipboard
WAIT command implementation
I've attempted to add support for WAIT for my project, and I'm kinda stuck...
I'm implementing a minimal simulation of the Super Serial card, which has a 6551 ACIA. I've shoved my hooks in for PEEK and POKE to the four addresses for the ACIA, and that all works great, I can send and receive from JSBASIC to my project javascript code.
The BASIC program I'm using though has a WAIT call, which (to my understanding) on real hardware will sit and block on a bit changing. In this case, it's waiting for a bit to be set to indicate that it received a character from the serial-attached laserdisc player. Here's the original BASIC:
40000 REM PLAY VIDEO CLIP 40010 IF NOT DISC THEN RETURN 40020 FOR I = 1 TO LEN (VC$) 40030 IF MID$ (VC$,I,1) = "/" THEN POKE 49320,13: WAIT 49321,8:J = PEEK (49320): GOTO 40060 40040 POKE 49320, ASC ( MID$ (VC$,I,1)) 40060 NEXT I 40070 RETURN
So it should write out to the serial port (POKE 49320,13) then WAIT for a character to be received. In the meantime, I've replaced it with this:
40030 IF MID$ (VC$,I,1) = "/" THEN GOTO 40100
40100 POKE 49320,13 40110 J = PEEK( 49321 ) 40120 IF J <> 8 THEN GOTO 40110 40130 J = PEEK( 49320 ) 40140 GOTO 40060
So i implemented it such that it sits in a loop, waiting for the byte to change... but obviously this doesn't work since it can't yield.
Do you have any suggestions or thoughts about how to implement this?
Look at how input blocks - a custom exception type is thrown which is caught by the driver loop to do additional processing. Once input is available, the driver loop restarts.
A similar model would probably work here.
Excellent. I'll look into that!
(I just checked in my fork, which adds acia.js but also an autorun for after the page loads. Feel free to pick and choose any changes i've made. I do not know your full roadplan for the project, and I'm sure my quick-and-dirty implementations aren't really PR'able... ;)
Would you recommend using the BlockingInput() function itself, or a whole new one, like BlockingWait()? I'm trying to understand how that fits in, and how it gets called...
Does that mechanism basically get thrown, in the catch, it runs from there, where the method gets called... the method can reschedule itself or call the callback? If i have it reschedule itself, it seems to just hang, so i must be doing it wrong. I tried having my Wait handler just reschedule itself 100 times, then call the callback...
A new exception type. Start off by just having it handled and setTimeout for 1 second before resuming execution to make sure you get the flow right. Then replace that sleep with whatever you're doing to simulate serial reads.
On Aug 15, 2018, at 9:40 AM, Scott Lawrence [email protected] wrote:
Would you recommend using the BlockingInput() function itself, or a whole new one, like BlockingWait()? I'm trying to understand how that fits in, and how it gets called...
Does that mechanism basically get thrown, in the catch, it runs from there, where the method gets called... the method can reschedule itself or call the callback? If i have it reschedule itself, it seems to just hang, so i must be doing it wrong. I tried having my Wait handler just reschedule itself 100 times, then call the callback...
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.