Implement CALL-3288; resolves #8

This commit is contained in:
Joshua Bell 2014-12-27 17:51:21 -07:00
parent ef4ed17f37
commit 7a01309073
3 changed files with 780 additions and 761 deletions

View File

@ -451,6 +451,16 @@ this.basic = (function() {
}; };
call_table = { call_table = {
0xD683: function() { // Clear stack
state.stack = [];
},
0xF328: function() { // Pop error entry off stack
var stack_record = state.stack.pop();
if (!{}.hasOwnProperty.call(stack_record, 'resume_stmt_index')) {
runtime_error(ERRORS.SYNTAX_ERROR);
return;
}
},
0xF3E4: function() { // Reveal hi-res page 1 0xF3E4: function() { // Reveal hi-res page 1
if (!env.hires) { runtime_error('Hires graphics not supported'); } if (!env.hires) { runtime_error('Hires graphics not supported'); }
env.display.setState('graphics', true, 'full', true, 'page1', true, 'lores', false); env.display.setState('graphics', true, 'full', true, 'page1', true, 'lores', false);
@ -465,9 +475,6 @@ this.basic = (function() {
if (!hires) { runtime_error('Hires graphics not supported'); } if (!hires) { runtime_error('Hires graphics not supported'); }
hires.clear(hires.color); hires.clear(hires.color);
}, },
0xD683: function() { // Clear stack
state.stack = [];
},
0xFBF4: function() { // Move cursor right 0xFBF4: function() { // Move cursor right
if (env.tty.cursorRight) { env.tty.cursorRight(); } if (env.tty.cursorRight) { env.tty.cursorRight(); }
}, },
@ -563,14 +570,11 @@ this.basic = (function() {
}, },
'pop': function POP() { 'pop': function POP() {
var stack_record; var stack_record = state.stack.pop();
while (state.stack.length) { if (!{}.hasOwnProperty.call(stack_record, 'gosub_return')) {
stack_record = state.stack.pop(); runtime_error(ERRORS.RETURN_WITHOUT_GOSUB);
if ({}.hasOwnProperty.call(stack_record, 'gosub_return')) {
return; return;
} }
}
runtime_error(ERRORS.RETURN_WITHOUT_GOSUB);
}, },
'for': function FOR(varname, from, to, step) { 'for': function FOR(varname, from, to, step) {
@ -640,8 +644,13 @@ this.basic = (function() {
}, },
'resume': function RESUME() { 'resume': function RESUME() {
state.stmt_index = state.resume_stmt_index; var stack_record = state.stack.pop();
state.line_number = state.resume_line_number; if (!{}.hasOwnProperty.call(stack_record, 'resume_stmt_index')) {
runtime_error(ERRORS.SYNTAX_ERROR);
return;
}
state.line_number = stack_record.resume_line_number;
state.stmt_index = stack_record.resume_stmt_index;
}, },
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -2175,8 +2184,6 @@ this.basic = (function() {
onerr_code: 255, onerr_code: 255,
onerr_handler: void 0, onerr_handler: void 0,
resume_stmt_index: 0,
resume_line_number: 0,
trace_mode: false, trace_mode: false,
input_continuation: null, input_continuation: null,
@ -2319,8 +2326,10 @@ this.basic = (function() {
if (rte instanceof basic.RuntimeError) { if (rte instanceof basic.RuntimeError) {
state.onerr_code = rte.code || 0; state.onerr_code = rte.code || 0;
if (state.onerr_handler !== void 0) { if (state.onerr_handler !== void 0) {
state.resume_stmt_index = state.stmt_index; state.stack.push({
state.resume_line_number = state.line_number; resume_stmt_index: state.stmt_index,
resume_line_number: state.line_number
});
gotoline(state.onerr_handler); gotoline(state.onerr_handler);
return basic.STATE_RUNNING; return basic.STATE_RUNNING;
} else if (rte.code === ERRORS.REENTER[0]) { } else if (rte.code === ERRORS.REENTER[0]) {

View File

@ -211,10 +211,11 @@ can be literals (unquoted strings), strings, or numbers
<dt>CALL <var>aexpr</var><dd>Call native routine <dt>CALL <var>aexpr</var><dd>Call native routine
<ul> <ul>
<li><code>CALL -3288</code> - pop <code>ONERR</code>/<code>RESUME</code> entry from stack
<li><code>CALL -3100</code> - reveal hi-res page 1 <li><code>CALL -3100</code> - reveal hi-res page 1
<li><code>CALL -3086</code> - clear current hi-res page to black <li><code>CALL -3086</code> - clear current hi-res page to black
<li><code>CALL -3082</code> - clear current hi-res page to current color <li><code>CALL -3082</code> - clear current hi-res page to current color
<li><code>CALL 54951</code> - clear stack (cancel pending <code>FOR</code>-<code>NEXT</code> loops and <code>GOSUB</code>s) <li><code>CALL 54951</code> - clear stack (pop all <code>FOR</code>/<code>NEXT</code>, <code>GOSUB</code>/<code>RETURN</code>, and <code>ONERR</code>/<code>RESUME</code> entries)
<li><code>CALL -1036</code> - move cursor right <li><code>CALL -1036</code> - move cursor right
<li><code>CALL -1008</code> - move cursor left <li><code>CALL -1008</code> - move cursor left
<li><code>CALL -998</code> - move cursor up <li><code>CALL -998</code> - move cursor up

View File

@ -242,6 +242,17 @@
: T = 2 : T = 2
3261 S = (T=1) AND (PEEK(222)=255) : GOSUB 1 3261 S = (T=1) AND (PEEK(222)=255) : GOSUB 1
3270 T$ = "CALL-3288" :
: T = 1 : ONERR GOTO 3274
3271 GOSUB 3272
: T = T + 1
: GOTO 3275
3272 X = FN UF(0)
: T = 10
3274 CALL -3288
: T = T + 1
: RETURN
3275 S = (T=3) : GOSUB 1
3999 POKE 216,0 : REM Disable ONERR handler 3999 POKE 216,0 : REM Disable ONERR handler
@ -808,5 +819,3 @@
20010 PRINT "Successful tests: "; TS 20010 PRINT "Successful tests: "; TS
20019 IF F THEN INVERSE 20019 IF F THEN INVERSE
20020 PRINT "Failed tests: "; F; : NORMAL 20020 PRINT "Failed tests: "; F; : NORMAL