1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-10 21:30:04 +00:00

More immidiate ops, add/sub next branches

This commit is contained in:
Dave Schmenk 2018-03-04 10:18:31 -08:00
parent 793b1760a0
commit 2b2e464c9b
10 changed files with 280 additions and 136 deletions

View File

@ -617,7 +617,12 @@ void emit_conststr(long conststr)
void emit_addi(int cval)
{
emit_pending_seq();
printf("\t%s\t$34,$%02X\t\t\t; ADDI\t%d\n", DB, cval, cval);
printf("\t%s\t$38,$%02X\t\t\t; ADDI\t%d\n", DB, cval, cval);
}
void emit_subi(int cval)
{
emit_pending_seq();
printf("\t%s\t$3A,$%02X\t\t\t; SUBI\t%d\n", DB, cval, cval);
}
void emit_andi(int cval)
{
@ -627,7 +632,7 @@ void emit_andi(int cval)
void emit_ori(int cval)
{
emit_pending_seq();
printf("\t%s\t$52,$%02X\t\t\t; IORI\t%d\n", DB, cval, cval);
printf("\t%s\t$3E,$%02X\t\t\t; ORI\t%d\n", DB, cval, cval);
}
void emit_lb(void)
{
@ -784,52 +789,46 @@ void emit_brnch(int tag)
printf("\t%s\t$50\t\t\t; BRNCH\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
//void emit_breq(int tag)
//{
// emit_pending_seq();
// printf("\t%s\t$3C\t\t\t; BREQ\t_B%03d\n", DB, tag);
// printf("\t%s\t_B%03d-*\n", DW, tag);
//}
void emit_brne(int tag)
{
emit_pending_seq();
printf("\t%s\t$3E\t\t\t; BRNE\t_B%03d\n", DB, tag);
printf("\t%s\t$52\t\t\t; BRNE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_brgt(int tag)
{
emit_pending_seq();
printf("\t%s\t$38\t\t\t; BRGT\t_B%03d\n", DB, tag);
printf("\t%s\t$88\t\t\t; BRGT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_brlt(int tag)
{
emit_pending_seq();
printf("\t%s\t$3A\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t$8A\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_brle(int tag)
void emit_addbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$80\t\t\t; NXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t$80\t\t\t; BRLE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_incbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$82\t\t\t; INXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t$82\t\t\t; INCBRLE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_brge(int tag)
void emit_subbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$84\t\t\t; NXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t$84\t\t\t; BRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_decbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$84\t\t\t; DNXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t$86\t\t\t; DECBRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_call(int tag, int type)
@ -880,11 +879,16 @@ void emit_drop(void)
emit_pending_seq();
printf("\t%s\t$30\t\t\t; DROP\n", DB);
}
void emit_dup(void)
void emit_drop2(void)
{
emit_pending_seq();
printf("\t%s\t$32\t\t\t; DUP\n", DB);
}
void emit_dup(void)
{
emit_pending_seq();
printf("\t%s\t$34\t\t\t; DUP\n", DB);
}
int emit_unaryop(t_token op)
{
emit_pending_seq();
@ -1267,6 +1271,12 @@ int crunch_seq(t_opseq **seq, int pass)
freeops = 1;
}
break;
case BINARY_CODE(SUB_TOKEN):
if (op->val >= 0 && op->val <= 255)
{
op->code = SUBI_CODE;
freeops = 1;
}
case BINARY_CODE(AND_TOKEN):
if (op->val >= 0 && op->val <= 255)
{
@ -1651,6 +1661,9 @@ int emit_pending_seq()
case ADDI_CODE:
emit_addi(op->val);
break;
case SUBI_CODE:
emit_subi(op->val);
break;
case ANDI_CODE:
emit_andi(op->val);
break;

View File

@ -60,13 +60,14 @@ typedef struct _opseq {
#define DROP_CODE 0x0318
#define DUP_CODE 0x0319
#define ADDI_CODE 0x031A
#define ANDI_CODE 0x031B
#define ORI_CODE 0x31C
#define BRNCH_CODE 0x031D
#define BRFALSE_CODE 0x031E
#define BRTRUE_CODE 0x031F
#define CODETAG_CODE 0x0320
#define NOP_CODE 0x0321
#define SUBI_CODE 0x031B
#define ANDI_CODE 0x031C
#define ORI_CODE 0x31D
#define BRNCH_CODE 0x0320
#define BRFALSE_CODE 0x0321
#define BRTRUE_CODE 0x0322
#define CODETAG_CODE 0x0323
#define NOP_CODE 0x0324
#define gen_uop(seq,op) gen_seq(seq,UNARY_CODE(op),0,0,0,0)
#define gen_op(seq,op) gen_seq(seq,BINARY_CODE(op),0,0,0,0)
@ -106,6 +107,7 @@ void emit_codetag(int tag);
void emit_const(int cval);
void emit_conststr(long conststr);
void emit_addi(int cval);
void emit_subi(int cval);
void emit_andi(int cval);
void emit_ori(int cval);
void emit_lb(void);
@ -138,12 +140,13 @@ void emit_brne(int tag);
void emit_brnch(int tag);
void emit_brgt(int tag);
void emit_brlt(int tag);
void emit_brle(int tag);
void emit_addbrle(int tag);
void emit_incbrle(int tag);
void emit_brge(int tag);
void emit_subbrge(int tag);
void emit_decbrge(int tag);
void emit_empty(void);
void emit_drop(void);
void emit_drop2(void);
void emit_dup(void);
void emit_leave(void);
void emit_ret(void);

View File

@ -173,7 +173,7 @@ def emit_daw(tag, offset)#0
end
def emit_brne(tag)#0
emit_pending_seq
emit_byte($3E)
emit_byte($52)
emit_reladdr(tag)
end
def emit_branch(tag)#0
@ -183,15 +183,15 @@ def emit_branch(tag)#0
end
def emit_brgt(tag)#0
emit_pending_seq
emit_byte($38)
emit_byte($88)
emit_reladdr(tag)
end
def emit_brlt(tag)#0
emit_pending_seq
emit_byte($3A)
emit_byte($8A)
emit_reladdr(tag)
end
def emit_brle(tag)#0
def emit_addbrle(tag)#0
emit_pending_seq
emit_byte($80)
emit_reladdr(tag)
@ -201,7 +201,7 @@ def emit_incbrle(tag)#0
emit_byte($82)
emit_reladdr(tag)
end
def emit_brge(tag)#0
def emit_subbrge(tag)#0
emit_pending_seq
emit_byte($84)
emit_reladdr(tag)

View File

@ -220,6 +220,12 @@ def crunch_seq(seq, pass)
freeops = 1
fin
break
is SUB_CODE
if op=>opval >= 0 and op=>opval <= 255
op->opcode = SUBI_CODE
freeops = 1
fin
break
is AND_CODE
if op=>opval >= 0 and op=>opval <= 255
op->opcode = ANDI_CODE

View File

@ -3,9 +3,10 @@
//
const CONST_GROUP = $00
const CONST_CODE = $2C
const ADDI_CODE = $34
const ADDI_CODE = $38
const SUBI_CODE = $3A
const ANDI_CODE = $3C
const ORI_CODE = $52
const ORI_CODE = $3E
const CONSTR_GROUP = $01
const CONSTR_CODE = $2E
//
@ -32,7 +33,8 @@ const LOGIC_NOT_CODE = $20
const LOGIC_OR_CODE = $22
const LOGIC_AND_CODE = $24
const DROP_CODE = $30
const DUP_CODE = $32
const DROP2_CODE = $32
const DUP_CODE = $34
const EQ_CODE = $40
const NE_CODE = $42
const GT_CODE = $44

View File

@ -5,7 +5,7 @@
#define RVALUE 1
#define MAX_LAMBDA 64
int infunc = 0, break_tag = 0, cont_tag = 0, stack_loop = 0, for_loop = 0;
int infunc = 0, break_tag = 0, cont_tag = 0, stack_loop = 0, infor = 0;
long infuncvals = 0;
t_token prevstmnt;
static int lambda_num = 0;
@ -798,7 +798,7 @@ t_opseq *parse_set(t_opseq *codeseq)
int parse_stmnt(void)
{
int tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend, tag_repeat, tag_for, tag_choice, tag_of;
int type, addr, step, cfnvals, prev_forlp;
int type, addr, step, cfnvals, prev_for;
char *idptr;
t_opseq *seq, *fromseq, *toseq;
@ -856,8 +856,8 @@ int parse_stmnt(void)
parse_error("Missing IF/FIN");
break;
case WHILE_TOKEN:
prev_forlp = for_loop;
for_loop = 0;
prev_for = infor;
infor = 0;
tag_while = tag_new(BRANCH_TYPE);
tag_wend = tag_new(BRANCH_TYPE);
tag_prevcnt = cont_tag;
@ -881,11 +881,11 @@ int parse_stmnt(void)
emit_codetag(tag_wend);
break_tag = tag_prevbrk;
cont_tag = tag_prevcnt;
for_loop = prev_forlp;
infor = prev_for;
break;
case REPEAT_TOKEN:
prev_forlp = for_loop;
for_loop = 0;
prev_for = infor;
infor = 0;
tag_prevbrk = break_tag;
break_tag = tag_new(BRANCH_TYPE);
tag_repeat = tag_new(BRANCH_TYPE);
@ -909,11 +909,11 @@ int parse_stmnt(void)
emit_seq(seq);
emit_codetag(break_tag);
break_tag = tag_prevbrk;
for_loop = prev_forlp;
infor = prev_for;
break;
case FOR_TOKEN:
prev_forlp = for_loop;
for_loop = 1;
prev_for = infor;
infor = 1;
stack_loop += 2;
tag_prevbrk = break_tag;
break_tag = tag_new(BRANCH_TYPE);
@ -978,8 +978,7 @@ int parse_stmnt(void)
if (seq)
{
emit_seq(seq);
emit_op(ADD_TOKEN);
emit_brle(tag_for);
emit_addbrle(tag_for);
}
else
emit_incbrle(tag_for);
@ -989,8 +988,7 @@ int parse_stmnt(void)
if (seq)
{
emit_seq(seq);
emit_op(SUB_TOKEN);
emit_brge(tag_for);
emit_subbrge(tag_for);
}
else
emit_decbrge(tag_for);
@ -998,11 +996,11 @@ int parse_stmnt(void)
emit_codetag(break_tag);
break_tag = tag_prevbrk;
stack_loop -= 2;
for_loop = prev_forlp;
infor = prev_for;
break;
case CASE_TOKEN:
prev_forlp = for_loop;
for_loop = 0;
prev_for = infor;
infor = 0;
stack_loop++;
tag_prevbrk = break_tag;
break_tag = tag_new(BRANCH_TYPE);
@ -1058,16 +1056,13 @@ int parse_stmnt(void)
emit_drop();
break_tag = tag_prevbrk;
stack_loop--;
for_loop = prev_forlp;
infor = prev_for;
break;
case BREAK_TOKEN:
if (break_tag)
{
if (for_loop)
{
emit_drop();
emit_drop();
}
if (infor)
emit_drop2();
emit_brnch(break_tag);
}
else

View File

@ -587,7 +587,7 @@ def parse_set(codeseq)
return codeseq
end
def parse_stmnt
byte type, elem_type, elem_size, i, cfnvals, prev_forlp
byte type, elem_type, elem_size, i, cfnvals, prev_for
word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend
word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir
@ -640,8 +640,8 @@ def parse_stmnt
if token <> FIN_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_STATE); fin
break
is WHILE_TKN
prev_forlp = for_loop
for_loop = FALSE
prev_for = infor
infor = FALSE
tag_while = new_tag(RELATIVE_FIXUP)
tag_wend = new_tag(RELATIVE_FIXUP)
tag_prevcnt = cont_tag
@ -665,11 +665,11 @@ def parse_stmnt
emit_tag(tag_wend)
break_tag = tag_prevbrk
cont_tag = tag_prevcnt
for_loop = prev_forlp
infor = prev_for
break
is REPEAT_TKN
prev_forlp = for_loop
for_loop = FALSE
prev_for = infor
infor = FALSE
tag_repeat = new_tag(RELATIVE_FIXUP)
tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP)
@ -693,11 +693,11 @@ def parse_stmnt
emit_seq(seq)
emit_tag(break_tag)
break_tag = tag_prevbrk
for_loop = prev_forlp
infor = prev_for
break
is FOR_TKN
prev_forlp = for_loop
for_loop = TRUE
prev_for = infor
infor = TRUE
stack_loop = stack_loop + 2
tag_for = new_tag(RELATIVE_FIXUP)
tag_prevcnt = cont_tag
@ -761,16 +761,14 @@ def parse_stmnt
if stepdir > 0
if seq
emit_seq(seq)
emit_code(ADD_CODE)
emit_brle(tag_for)
emit_addbrle(tag_for)
else
emit_incbrle(tag_for)
fin
else
if seq
emit_seq(seq)
emit_code(SUB_CODE)
emit_brge(tag_for)
emit_subbrge(tag_for)
else
emit_decbrge(tag_for)
fin
@ -779,11 +777,11 @@ def parse_stmnt
emit_tag(break_tag)
break_tag = tag_prevbrk
stack_loop = stack_loop - 2
for_loop = prev_forlp
infor = prev_for
break
is CASE_TKN
prev_forlp = for_loop
for_loop = FALSE
prev_for = infor
infor = FALSE
stack_loop++
tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP)
@ -842,14 +840,11 @@ def parse_stmnt
emit_code(DROP_CODE)
break_tag = tag_prevbrk
stack_loop--
for_loop = prev_forlp
infor = prev_for
break
is BREAK_TKN
if break_tag
if for_loop
emit_code(DROP_CODE)
emit_code(DROP_CODE)
fin
if infor; emit_code(DROP2_CODE); fin
emit_branch(break_tag)
else
exit_err(ERR_INVAL|ERR_STATE)

View File

@ -298,9 +298,8 @@ const RVALUE = 1
const LAMBDANUM = 16
word strconstbuff
word strconstptr
byte infunc, inlambda
byte infunc, inlambda, infor
byte stack_loop
byte for_loop
byte prevstmnt
word infuncvals
word break_tag

View File

@ -198,12 +198,12 @@ VMCORE = *
OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
!WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,ADDI,DIVMOD,BRGT,BRLT,ANDI,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E
!WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
!WORD BRNCH,ORI,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD BRNCH,BRNE,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD BRLE,INCBRLE,BRGE,DECBRGE ; 80 82 84 86 88 8A 8C 8E
!WORD ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
;*
;* ENTER INTO BYTECODE INTERPRETER
;*
@ -408,12 +408,12 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY
OPXTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
!WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,ADDI,DIVMOD,BRGT,BRLT,ANDI,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E
!WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
!WORD BRNCH,ORI,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD BRNCH,BRNE,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LBX,LWX,LLBX,LLWX,LABX,LAWX,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD BRLE,INCBRLE,BRGE,DECBRGE ; 80 82 84 86 88 8A 8C 8E
!WORD ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
;*
;* ADD TOS TO TOS-1
;*
@ -765,12 +765,25 @@ ADDI INY ;+INC_IP
INC ESTKH,X
+ JMP NEXTOP
;*
;* SUB IMMEDIATE FROM TOS
;*
SUBI INY ;+INC_IP
LDA ESTKL,X
SEC
SBC (IP),Y
STA ESTKL,X
BCS +
DEC ESTKH,X
+ JMP NEXTOP
;*
;* AND IMMEDIATE TO TOS
;*
ANDI INY ;+INC_IP
LDA (IP),Y
AND ESTKL,X
STA ESTKL,X
LDA #$00
STA ESTKH,X
JMP NEXTOP
;*
;* IOR IMMEDIATE TO TOS
@ -1105,7 +1118,10 @@ SW LDA ESTKL,X
JMP DROP
+ INC ESTKH,X
STA (ESTKH-1,X)
INX
;*
;* DROP TOS, TOS-1
;*
DROP2 INX
JMP DROP
;*
;* STORE VALUE TO LOCAL FRAME OFFSET
@ -1349,7 +1365,7 @@ BRNCH TYA ; FLATTEN IP
;*
;* FOR LOOPS PUT TERMINAL VALUE AT ESTK+1 AND CURRENT COUNT ON ESTK
;*
BRGT LDA ESTKL+1,X ; $D95D
BRGT LDA ESTKL+1,X
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X
@ -1370,11 +1386,13 @@ BRLT LDA ESTKL,X
+ BMI NOBRNCH
BPL -
DECBRGE LDA ESTKL,X
BNE +
SEC
SBC #$01
STA ESTKL,X
BCS +
DEC ESTKH,X
+ DEC ESTKL,X
BRGE LDA ESTKL,X ; BRGE
CMP ESTKL+1,X
_BRGE LDA ESTKL,X ; BRGE
+ CMP ESTKL+1,X
LDA ESTKH,X
SBC ESTKH+1,X
BVS +
@ -1383,9 +1401,9 @@ BRGE LDA ESTKL,X ; BRGE
INX
BNE NOBRNCH ; BMI NOBRNCH
INCBRLE INC ESTKL,X
BNE BRLE
BNE _BRLE
INC ESTKH,X
BRLE LDA ESTKL+1,X ; BRLE
_BRLE LDA ESTKL+1,X ; BRLE
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X
@ -1396,6 +1414,24 @@ BRLE LDA ESTKL+1,X ; BRLE
BNE NOBRNCH ; BMI NOBRNCH
+ BMI BRNCH
BPL -
SUBBRGE LDA ESTKL+1,X
SEC
SBC ESTKL,X
STA ESTKL+1,X
LDA ESTKH+1,X
SBC ESTKH,X
STA ESTKH+1,X
INX
BNE _BRGE
ADDBRLE LDA ESTKL,X
CLC
ADC ESTKL+1,X
STA ESTKL+1,X
LDA ESTKH,X
ADC ESTKH+1,X
STA ESTKH+1,X
INX
BNE _BRLE
;IBRNCH TYA ; FLATTEN IP
; CLC
; ADC IPL

View File

@ -36,7 +36,7 @@ uword sp = 0x01FE, fp = 0xFFFF, heap = 0x0200, deftbl = DEF_CALL, lastdef = DEF_
#define UPOP ((uword)(*(esp++)))
#define TOS (esp[0])
word eval_stack[EVAL_STACKSZ];
word *esp = eval_stack + EVAL_STACKSZ;
word *esp = &eval_stack[EVAL_STACKSZ];
#define SYMTBLSZ 1024
#define SYMSZ 16
@ -517,21 +517,28 @@ void call(uword pc)
/*
* OPCODE TABLE
*
OPTBL: DW ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
DW NEG,COMP,AND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
DW NOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
DW DROP,DUP,PUSH,PULL,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
OPTBL: DW ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
DW NEG,COMP,AND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
DW NOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
DW DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E
DW ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
DW BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
DW LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
DW SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
DW BRNCH,BRNE,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
DW LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
DW SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
DW ADDBRLE,INCBRLE,SUBBRGE,DECBRGE,BRGT,BRLT ; 80 82 84 86 88 8A 8C 8E
*/
void interp(code *ip)
{
int val, ea, frmsz, parmcnt;
code *previp = ip;
while (1)
{
if ((esp - eval_stack) < 0 || (esp - eval_stack) > EVAL_STACKSZ)
{
printf("Eval stack over/underflow! - $%04X: $%02X [%d]\n", previp - mem_data, *previp, EVAL_STACKSZ - (esp - eval_stack));
show_state = 1;
}
if (show_state)
{
char cmdline[16];
@ -542,11 +549,12 @@ void interp(code *ip)
printf("]\n");
gets(cmdline);
}
previp = ip;
switch (*ip++)
{
/*
* 0x00-0x0F
*/
/*
* 0x00-0x0F
*/
case 0x00: // ZERO : TOS = 0
PUSH(0);
break;
@ -662,41 +670,31 @@ void interp(code *ip)
case 0x30: // DROP : TOS =
POP;
break;
case 0x32: // DUP : TOS = TOS
case 0x32: // DROP2 : TOS ==
POP;
POP;
break;
case 0x34: // DUP : TOS = TOS
val = TOS;
PUSH(val);
break;
case 0x34: // NOP
case 0x36: // DIVMOD
break;
case 0x36: // NOP
case 0x38: // ADDI
PUSH(POP + BYTE_PTR(ip));
ip++;
break;
case 0x38: // BRGT : TOS-1 > TOS ? IP += (IP)
val = POP;
if (TOS > val)
ip += WORD_PTR(ip);
else
ip += 2;
case 0x3A: // SUBI
PUSH(POP - BYTE_PTR(ip));
ip++;
break;
case 0x3A: // BRLT : TOS-1 < TOS ? IP += (IP)
val = POP;
if (TOS < val)
ip += WORD_PTR(ip);
else
ip += 2;
case 0x3C: // ANDI
PUSH(POP & BYTE_PTR(ip));
ip++;
break;
case 0x3C: // BREQ : TOS == TOS-1 ? IP += (IP)
val = POP;
if (TOS == val)
ip += WORD_PTR(ip);
else
ip += 2;
break;
case 0x3E: // BRNE : TOS != TOS-1 ? IP += (IP)
val = POP;
if (TOS != val)
ip += WORD_PTR(ip);
else
ip += 2;
case 0x3E: // ORI
PUSH(POP | BYTE_PTR(ip));
ip++;
break;
/*
* 0x40-0x4F
@ -749,8 +747,18 @@ void interp(code *ip)
case 0x50: // BRNCH : IP += (IP)
ip += WORD_PTR(ip);
break;
case 0x52: // IBRNCH : IP += TOS
ip += POP;
case 0x52: // BRNE : TOS != TOS-1 ? IP += (IP)
val = POP;
if (TOS != val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
case 0x54: // CALL : TOFP = IP, IP = (IP) ; call
call(UWORD_PTR(ip));
@ -873,6 +881,93 @@ void interp(code *ip)
mem_data[ea + 1] = TOS >> 8;
ip += 2;
break;
/*
* 0x80-0x8F
*/
case 0x80: // ADDBRLE : TOS = TOS + TOS-1
val = POP;
ea = POP;
val = ea + val;
if (TOS >= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x82: // INCBRLE : TOS = TOS + 1
val = POP;
val++;
if (TOS >= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x84: // SUBBRGE : TOS = TOS-1 - TOS
val = POP;
ea = POP;
val = ea - val;
if (TOS <= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x86: // DECBRGE : TOS = TOS - 1
val = POP;
val--;
if (TOS <= val)
{
PUSH(val);
ip += WORD_PTR(ip);
}
else
{
POP;
ip += 2;
}
break;
case 0x88: // BRGT : TOS-1 > TOS ? IP += (IP)
val = POP;
if (TOS < val)
{
POP;
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
case 0x8A: // BRLT : TOS-1 < TOS ? IP += (IP)
val = POP;
if (TOS > val)
{
POP;
ip += WORD_PTR(ip);
}
else
{
PUSH(val);
ip += 2;
}
break;
/*
* Odd codes and everything else are errors.
*/