@@ -44,7 +44,7 @@ Controller.prototype = {
44
44
this . fnDirectInputHandler = this . fnDirectInput . bind ( this ) ;
45
45
this . fnPutKeyInBufferHandler = this . fnPutKeyInBuffer . bind ( this ) ;
46
46
47
- this . sMetaIdent = "CPCBasic" ; //TTT
47
+ this . sMetaIdent = "CPCBasic" ;
48
48
49
49
this . fnScript = null ;
50
50
@@ -98,8 +98,7 @@ Controller.prototype = {
98
98
keyboard : this . oKeyboard ,
99
99
sound : this . oSound ,
100
100
variables : this . oVariables ,
101
- tron : oModel . getProperty ( "tron" ) ,
102
- onCharReturn : this . fnPutKeyInBufferHandler
101
+ tron : oModel . getProperty ( "tron" )
103
102
} ) ;
104
103
this . oVm . vmReset ( ) ;
105
104
@@ -372,18 +371,39 @@ Controller.prototype = {
372
371
this . startMainLoop ( ) ;
373
372
} ,
374
373
374
+ fnWaitSound : function ( ) { // rather fnEvent
375
+ var oStop = this . oVm . vmGetStopObject ( ) ,
376
+ aSoundData ;
377
+
378
+ this . oVm . vmLoopCondition ( ) ; // update iNextFrameTime, timers, inks; schedule sound: free queue
379
+ if ( this . oSound . isActivatedByUser ( ) ) { // only if activated
380
+ aSoundData = this . oVm . vmGetSoundData ( ) ;
381
+ while ( aSoundData . length && this . oSound . testCanQueue ( aSoundData [ 0 ] . iState ) ) {
382
+ this . oSound . sound ( aSoundData . shift ( ) ) ;
383
+ }
384
+ if ( ! aSoundData . length ) {
385
+ if ( oStop . sReason === "waitSound" ) { // only for this reason
386
+ this . oVm . vmStop ( "" , 0 , true ) ; // no more wait
387
+ }
388
+ }
389
+ }
390
+ this . iNextLoopTimeOut = this . oVm . vmGetTimeUntilFrame ( ) ; // wait until next frame
391
+ } ,
392
+
375
393
fnWaitKey : function ( ) {
376
394
var sKey ;
377
395
378
396
sKey = this . oKeyboard . getKeyFromBuffer ( ) ;
379
- if ( sKey !== "" ) {
397
+ if ( sKey !== "" ) { // do we have a key from the buffer already?
380
398
Utils . console . log ( "Wait for key:" , sKey ) ;
381
399
this . oVm . vmStop ( "" , 0 , true ) ;
382
400
this . oKeyboard . setKeyDownHandler ( null ) ;
383
- this . startMainLoop ( ) ;
401
+ // this.startMainLoop();
384
402
} else {
403
+ this . fnWaitSound ( ) ; // sound and blinking events
385
404
this . oKeyboard . setKeyDownHandler ( this . fnWaitKeyHandler ) ; // wait until keypress handler (for call &bb18)
386
405
}
406
+ return sKey ;
387
407
} ,
388
408
389
409
fnWaitInput : function ( ) { // eslint-disable-line complexity
@@ -460,7 +480,7 @@ Controller.prototype = {
460
480
461
481
oInput . sInput = sInput ;
462
482
if ( sKey === "\r" ) {
463
- Utils . console . log ( "fnWaitInput:" , sInput ) ;
483
+ Utils . console . log ( "fnWaitInput:" , sInput , "reason" , oStop . sReason ) ;
464
484
if ( ! oInput . sNoCRLF ) {
465
485
this . oVm . print ( iStream , "\r\n" ) ;
466
486
}
@@ -471,29 +491,20 @@ Controller.prototype = {
471
491
}
472
492
if ( bInputOk ) {
473
493
this . oKeyboard . setKeyDownHandler ( null ) ;
474
- this . startContinue ( ) ;
494
+ if ( oStop . sReason === "waitInput" ) { // only for this reason
495
+ this . oVm . vmStop ( "" , 0 , true ) ; // no more wait
496
+ } else {
497
+ this . startContinue ( ) ; //TTT
498
+ }
475
499
}
476
500
}
477
501
478
502
if ( ! bInputOk ) {
479
- this . oKeyboard . setKeyDownHandler ( this . fnWaitInputHandler ) ; // make sure it is set
480
- }
481
- } ,
482
-
483
- fnWaitSound : function ( ) {
484
- var aSoundData ;
485
-
486
- this . oVm . vmLoopCondition ( ) ; // update iNextFrameTime, timers, inks; schedule sound: free queue
487
- if ( this . oSound . isActivatedByUser ( ) ) { // only if activated
488
- aSoundData = this . oVm . vmGetSoundData ( ) ;
489
- while ( aSoundData . length && this . oSound . testCanQueue ( aSoundData [ 0 ] . iState ) ) {
490
- this . oSound . sound ( aSoundData . shift ( ) ) ;
491
- }
492
- if ( ! aSoundData . length ) {
493
- this . oVm . vmStop ( "" , 0 , true ) ; // no more wait
503
+ if ( oStop . sReason === "waitInput" ) { // only for this reason
504
+ this . fnWaitSound ( ) ; // sound and blinking events
494
505
}
506
+ this . oKeyboard . setKeyDownHandler ( this . fnWaitInputHandler ) ; // make sure it is set
495
507
}
496
- this . iNextLoopTimeOut = this . oVm . vmGetTimeUntilFrame ( ) ; // wait until next frame
497
508
} ,
498
509
499
510
// merge two scripts with sorted line numbers, lines from script2 overwrite lines from script1
@@ -757,8 +768,6 @@ Controller.prototype = {
757
768
oData ,
758
769
sType ;
759
770
760
- //this.oVm.vmStop("", 0, true);
761
-
762
771
if ( sInput !== null && sInput !== undefined ) {
763
772
oData = this . splitMeta ( sInput ) ;
764
773
sInput = oData . sData ; // maybe changed
@@ -814,7 +823,7 @@ Controller.prototype = {
814
823
this . fnParseRun ( ) ;
815
824
break ;
816
825
case "load" :
817
- if ( ! bPutInMemory ) { //sType !== "B") { // not for binary files
826
+ if ( ! bPutInMemory ) {
818
827
this . view . setAreaValue ( "inputText" , sInput ) ;
819
828
this . view . setAreaValue ( "resultText" , "" ) ;
820
829
this . invalidateScript ( ) ;
@@ -830,14 +839,14 @@ Controller.prototype = {
830
839
break ;
831
840
case "chain" : // TODO: run through... : if we have a line number, make sure it is not optimized away when compiling!
832
841
case "run" :
833
- if ( ! bPutInMemory ) { //if (sType !== "B") { // not for binary files
842
+ if ( ! bPutInMemory ) {
834
843
this . view . setAreaValue ( "inputText" , sInput ) ;
835
844
this . view . setAreaValue ( "resultText" , "" ) ;
836
845
iStartLine = oInFile . iLine || 0 ;
837
846
this . fnReset ( ) ;
838
847
this . fnParseRun ( ) ;
839
848
} else {
840
- this . fnReset ( ) ; //TTT
849
+ this . fnReset ( ) ;
841
850
}
842
851
break ;
843
852
default :
@@ -1012,7 +1021,6 @@ Controller.prototype = {
1012
1021
aMeta = sMeta . split ( ";" ) ;
1013
1022
1014
1023
oMeta = {
1015
- //sIdent: aMeta[0],
1016
1024
sType : aMeta [ 1 ] ,
1017
1025
iStart : aMeta [ 2 ] ,
1018
1026
iLength : aMeta [ 3 ] ,
@@ -1115,7 +1123,7 @@ Controller.prototype = {
1115
1123
var sInput = this . view . getAreaValue ( "inputText" ) ,
1116
1124
iStream = oParas . iStream ,
1117
1125
aLines = this . fnGetLinesInRange ( sInput , oParas . iFirst , oParas . iLast ) ,
1118
- oRegExp = new RegExp ( / ( [ \x00 - \x1f ] ) / g) , //eslint-disable-line no-control-regex
1126
+ oRegExp = new RegExp ( / ( [ \x00 - \x1f ] ) / g) , // eslint-disable-line no-control-regex
1119
1127
i , sLine ;
1120
1128
1121
1129
for ( i = 0 ; i < aLines . length ; i += 1 ) {
@@ -1470,8 +1478,8 @@ Controller.prototype = {
1470
1478
this . updateResultText ( ) ;
1471
1479
1472
1480
this . view . setDisabled ( "runButton" , sReason === "reset" ) ;
1473
- this . view . setDisabled ( "stopButton" , sReason !== "waitInput" && sReason !== "waitKey" && sReason !== " fileLoad" && sReason !== "fileSave" ) ;
1474
- this . view . setDisabled ( "continueButton" , sReason === "end" || sReason === "waitInput" || sReason === "waitKey" || sReason === " fileLoad" || sReason === "fileSave" || sReason === "parse" || sReason === "renumLines" || sReason === "reset" ) ;
1481
+ this . view . setDisabled ( "stopButton" , sReason !== "fileLoad" && sReason !== "fileSave" ) ;
1482
+ this . view . setDisabled ( "continueButton" , sReason === "end" || sReason === "fileLoad" || sReason === "fileSave" || sReason === "parse" || sReason === "renumLines" || sReason === "reset" ) ;
1475
1483
1476
1484
this . setVarSelectOptions ( "varSelect" , this . oVariables ) ;
1477
1485
this . commonEventHandler . onVarSelectChange ( ) ;
@@ -1535,7 +1543,7 @@ Controller.prototype = {
1535
1543
this . oVm . vmStop ( "error" , 55 ) ; //TTT
1536
1544
}
1537
1545
1538
- if ( oStop . sReason && oStop . sReason !== "waitSound" ) {
1546
+ if ( oStop . sReason && oStop . sReason !== "waitSound" && oStop . sReason !== "waitKey" && oStop . sReason !== "waitInput" ) {
1539
1547
this . bTimeoutHandlerActive = false ; // not running any more
1540
1548
this . exitLoop ( ) ;
1541
1549
} else {
@@ -1615,7 +1623,7 @@ Controller.prototype = {
1615
1623
this . view . setDisabled ( "runButton" , true ) ;
1616
1624
this . view . setDisabled ( "stopButton" , false ) ;
1617
1625
this . view . setDisabled ( "continueButton" , true ) ;
1618
- if ( oStop . sReason === "break" || oStop . sReason === "escape" || oStop . sReason === "stop" || oStop . sReason === "direct" || oStop . sReason === "waitInput" ) {
1626
+ if ( oStop . sReason === "break" || oStop . sReason === "escape" || oStop . sReason === "stop" || oStop . sReason === "direct" /*TTT || oStop.sReason === "waitInput" */ ) {
1619
1627
if ( ! oSavedStop . fnInputCallback ) { // no keyboard callback? make sure no handler is set (especially for direct->continue)
1620
1628
this . oKeyboard . setKeyDownHandler ( null ) ;
1621
1629
}
0 commit comments