1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-11 13:29:44 +00:00

Nybble constants encoded in opcode

This commit is contained in:
David Schmenk 2018-03-05 11:38:16 -08:00
parent eff01c5f12
commit 334bf1ec4d
7 changed files with 107 additions and 98 deletions

View File

@ -600,8 +600,10 @@ void emit_codetag(int tag)
void emit_const(int cval)
{
emit_pending_seq();
if (cval == 0x0000)
printf("\t%s\t$00\t\t\t; ZERO\n", DB);
if ((cval & 0xFFFF) == 0xFFFF)
printf("\t%s\t$80\t\t\t; MINUS ONE\n", DB);
else if ((cval & 0xFFF0) == 0x0000)
printf("\t%s\t$%02X\t\t\t; CN\t%d\n", DB, cval*2, cval);
else if ((cval & 0xFF00) == 0x0000)
printf("\t%s\t$2A,$%02X\t\t\t; CB\t%d\n", DB, cval, cval);
else if ((cval & 0xFF00) == 0xFF00)
@ -767,11 +769,11 @@ void emit_globaladdr(int tag, int offset, int type)
}
void emit_indexbyte(void)
{
printf("\t%s\t$02\t\t\t; IDXB\n", DB);
printf("\t%s\t$82\t\t\t; IDXB\n", DB);
}
void emit_indexword(void)
{
printf("\t%s\t$1E\t\t\t; IDXW\n", DB);
printf("\t%s\t$9E\t\t\t; IDXW\n", DB);
}
void emit_select(int tag)
{
@ -809,49 +811,49 @@ void emit_brnch(int tag)
void emit_brand(int tag)
{
emit_pending_seq();
printf("\t%s\t$8C\t\t\t; BRAND\t_B%03d\n", DB, tag);
printf("\t%s\t$AC\t\t\t; BRAND\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_bror(int tag)
{
emit_pending_seq();
printf("\t%s\t$8E\t\t\t; BROR\t_B%03d\n", DB, tag);
printf("\t%s\t$AE\t\t\t; BROR\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$80\t\t\t; BRGT\t_B%03d\n", DB, tag);
printf("\t%s\t$A0\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$82\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t$A2\t\t\t; BRLT\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$84\t\t\t; INCBRLE\t_B%03d\n", DB, tag);
printf("\t%s\t$A4\t\t\t; INCBRLE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_addbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$86\t\t\t; BRLE\t_B%03d\n", DB, tag);
printf("\t%s\t$A6\t\t\t; BRLE\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$88\t\t\t; DECBRGE\t_B%03d\n", DB, tag);
printf("\t%s\t$A8\t\t\t; DECBRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_subbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$8A\t\t\t; BRGE\t_B%03d\n", DB, tag);
printf("\t%s\t$AA\t\t\t; BRGE\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_call(int tag, int type)
@ -918,19 +920,19 @@ int emit_unaryop(t_token op)
switch (op)
{
case NEG_TOKEN:
printf("\t%s\t$10\t\t\t; NEG\n", DB);
printf("\t%s\t$90\t\t\t; NEG\n", DB);
break;
case COMP_TOKEN:
printf("\t%s\t$12\t\t\t; COMP\n", DB);
printf("\t%s\t$92\t\t\t; COMP\n", DB);
break;
case LOGIC_NOT_TOKEN:
printf("\t%s\t$20\t\t\t; NOT\n", DB);
break;
case INC_TOKEN:
printf("\t%s\t$0C\t\t\t; INCR\n", DB);
printf("\t%s\t$8C\t\t\t; INCR\n", DB);
break;
case DEC_TOKEN:
printf("\t%s\t$0E\t\t\t; DECR\n", DB);
printf("\t%s\t$8E\t\t\t; DECR\n", DB);
break;
case BPTR_TOKEN:
emit_lb();
@ -950,34 +952,34 @@ int emit_op(t_token op)
switch (op)
{
case MUL_TOKEN:
printf("\t%s\t$06\t\t\t; MUL\n", DB);
printf("\t%s\t$86\t\t\t; MUL\n", DB);
break;
case DIV_TOKEN:
printf("\t%s\t$08\t\t\t; DIV\n", DB);
printf("\t%s\t$88\t\t\t; DIV\n", DB);
break;
case MOD_TOKEN:
printf("\t%s\t$0A\t\t\t; MOD\n", DB);
printf("\t%s\t$8A\t\t\t; MOD\n", DB);
break;
case ADD_TOKEN:
printf("\t%s\t$02\t\t\t; ADD\n", DB);
printf("\t%s\t$82\t\t\t; ADD\n", DB);
break;
case SUB_TOKEN:
printf("\t%s\t$04\t\t\t; SUB\n", DB);
printf("\t%s\t$84\t\t\t; SUB\n", DB);
break;
case SHL_TOKEN:
printf("\t%s\t$1A\t\t\t; SHL\n", DB);
printf("\t%s\t$9A\t\t\t; SHL\n", DB);
break;
case SHR_TOKEN:
printf("\t%s\t$1C\t\t\t; SHR\n", DB);
printf("\t%s\t$9C\t\t\t; SHR\n", DB);
break;
case AND_TOKEN:
printf("\t%s\t$14\t\t\t; AND\n", DB);
printf("\t%s\t$94\t\t\t; AND\n", DB);
break;
case OR_TOKEN:
printf("\t%s\t$16\t\t\t; IOR\n", DB);
printf("\t%s\t$96\t\t\t; IOR\n", DB);
break;
case EOR_TOKEN:
printf("\t%s\t$18\t\t\t; XOR\n", DB);
printf("\t%s\t$98\t\t\t; XOR\n", DB);
break;
case EQ_TOKEN:
printf("\t%s\t$40\t\t\t; ISEQ\n", DB);

View File

@ -132,8 +132,10 @@ def emit_codeseg#0
end
def emit_const(cval)#0
emit_pending_seq
if cval == $0000 // ZERO
emit_byte($00)
if cval == $FFFF // MINUS ONE
emit_byte($80)
elsif cval & $FFF0 == $0000 // Constant NYBBLE
emit_byte(cval*2)
elsif cval & $FF00 == $0000 // Constant BYTE
emit_byte($2A)
emit_byte(cval)
@ -179,6 +181,7 @@ end
def emit_caseblock(cnt, oflist, taglist)#0
byte i
emit_pending_seq
emit_byte(cnt)
for i = 0 to cnt-1
emit_word(oflist=>[i])
@ -190,44 +193,44 @@ def emit_branch(tag)#0
emit_byte($50)
emit_reladdr(tag)
end
def emit_brand(tag)#0
emit_pending_seq
emit_byte($8C)
emit_reladdr(tag)
end
def emit_bror(tag)#0
emit_pending_seq
emit_byte($8E)
emit_reladdr(tag)
end
def emit_brgt(tag)#0
emit_pending_seq
emit_byte($80)
emit_byte($A0)
emit_reladdr(tag)
end
def emit_brlt(tag)#0
emit_pending_seq
emit_byte($82)
emit_byte($A2)
emit_reladdr(tag)
end
def emit_incbrle(tag)#0
emit_pending_seq
emit_byte($84)
emit_byte($A4)
emit_reladdr(tag)
end
def emit_addbrle(tag)#0
emit_pending_seq
emit_byte($86)
emit_byte($A6)
emit_reladdr(tag)
end
def emit_decbrge(tag)#0
emit_pending_seq
emit_byte($88)
emit_byte($A8)
emit_reladdr(tag)
end
def emit_subbrge(tag)#0
emit_pending_seq
emit_byte($8A)
emit_byte($AA)
emit_reladdr(tag)
end
def emit_brand(tag)#0
emit_pending_seq
emit_byte($AC)
emit_reladdr(tag)
end
def emit_bror(tag)#0
emit_pending_seq
emit_byte($AE)
emit_reladdr(tag)
end
def emit_leave#0
@ -732,15 +735,15 @@ def gen_uop(seq, tkn)
fin
when tkn
is NEG_TKN
code = $10; break
code = $90; break
is COMP_TKN
code = $12; break
code = $92; break
is LOGIC_NOT_TKN
code = $20; break
is INC_TKN
code = $0C; break
code = $8C; break
is DEC_TKN
code = $0E; break
code = $8E; break
is BPTR_TKN
code = $60; break
is WPTR_TKN
@ -767,25 +770,25 @@ def gen_bop(seq, tkn)
fin
when tkn
is MUL_TKN
code = $06; break
code = $86; break
is DIV_TKN
code = $08; break
code = $88; break
is MOD_TKN
code = $0A; break
code = $8A; break
is ADD_TKN
code = $02; break
code = $82; break
is SUB_TKN
code = $04; break
code = $84; break
is SHL_TKN
code = $1A; break
code = $9A; break
is SHR_TKN
code = $1C; break
code = $9C; break
is AND_TKN
code = $14; break
code = $94; break
is OR_TKN
code = $16; break
code = $96; break
is EOR_TKN
code = $18; break
code = $98; break
is EQ_TKN
code = $40; break
is NE_TKN

View File

@ -13,22 +13,22 @@ const CONSTR_CODE = $2E
// Stack code group
//
const STACK_GROUP = $02
const INDEXB_CODE = $02
const ADD_CODE = $02
const SUB_CODE = $04
const MUL_CODE = $06
const DIV_CODE = $08
const MOD_CODE = $0A
const INC_CODE = $0C
const DEC_CODE = $0E
const NEG_CODE = $10
const COMP_CODE = $12
const AND_CODE = $14
const OR_CODE = $16
const EOR_CODE = $18
const SHL_CODE = $1A
const SHR_CODE = $1C
const INDEXW_CODE = $1E
const INDEXB_CODE = $82
const ADD_CODE = $82
const SUB_CODE = $84
const MUL_CODE = $86
const DIV_CODE = $88
const MOD_CODE = $8A
const INC_CODE = $8C
const DEC_CODE = $8E
const NEG_CODE = $90
const COMP_CODE = $92
const AND_CODE = $94
const OR_CODE = $96
const EOR_CODE = $98
const SHL_CODE = $9A
const SHR_CODE = $9C
const INDEXW_CODE = $9E
const LOGIC_NOT_CODE = $20
//const LOGIC_OR_CODE = $22
//const LOGIC_AND_CODE = $24
@ -79,8 +79,8 @@ const RELATIVE_GROUP = $05
const BRFALSE_CODE = $4C
const BRTRUE_CODE = $4E
const BRNCH_CODE = $50
const BRAND_CODE = $8C
const BROR_CODE = $8E
const BRAND_CODE = $AC
const BROR_CODE = $AE
//
// Code tag address group
//

View File

@ -1123,7 +1123,7 @@ def cmdmode#0
word cmdptr
clrscrn
puts("PLASMA Editor, Version 1.01\n")
puts("PLASMA Editor, Version 2.0 Dev\n")
while not exit
puts(@filename)
cmdptr = gets($BA)

View File

@ -411,7 +411,7 @@ include "toolsrc/parse.pla"
//
// Look at command line arguments and compile module
//
puts("PLASMA Compiler, Version 1.02\n")
puts("PLASMA Compiler, Version 2.0 Dev\n")
arg = argNext(argFirst)
if ^arg and ^(arg + 1) == '-'
opt = arg + 2

View File

@ -38,7 +38,7 @@ predef execmod(modfile)#1
//
// Exported CMDSYS table
//
word version = $0101 // 01.01
word version = $0200 // 02.00 Dev
word syspath
word syscmdln
word = @execmod
@ -1433,7 +1433,7 @@ heap = *freemem
//
// Print PLASMA version
//
prstr("PLASMA "); prbyte(version.1); cout('.'); prbyte(version.0); crout
prstr("PLASMA 2.0 Dev\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout
//
// Init symbol table.
//

View File

@ -193,17 +193,17 @@ VMCORE = *
;* *
;****************
!ALIGN 255,0
;OPTBL !WORD CONST,CONST,CONST,CONST,CONST,CONST,CONST,CONST ; 00 02 04 06 08 0A 0C 0E
; !WORD CONST,CONST,CONST,CONST,CONST,CONST,CONST,CONST ; 10 12 14 16 18 1A 1C 1E
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
OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E
!WORD CN,CN,CN,CN,CN,CN,CN,CN ; 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,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,SEL,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 BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; 80 82 84 86 88 8A 8C 8E
!WORD MINUS1,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 80 82 84 86 88 8A 8C 8E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 90 92 94 96 98 9A 9C 9E
!WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; A0 A2 A4 A6 A8 AA AC AE
;*
;*
;* ENTER INTO BYTECODE INTERPRETER
@ -404,17 +404,17 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY
;* *
;*****************
!ALIGN 255,0
;OPXTBL !WORD CONST,CONST,CONST,CONST,CONST,CONST,CONST,CONST ; 00 02 04 06 08 0A 0C 0E
; !WORD CONST,CONST,CONST,CONST,CONST,CONST,CONST,CONST ; 10 12 14 16 18 1A 1C 1E
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
OPXTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E
!WORD CN,CN,CN,CN,CN,CN,CN,CN ; 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,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,SEL,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 BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; 80 82 84 86 88 8A 8C 8E
!WORD MINUS1,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 80 82 84 86 88 8A 8C 8E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 90 92 94 96 98 9A 9C 9E
!WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; A0 A2 A4 A6 A8 AA AC AE
;*
;* ADD TOS TO TOS-1
;*
@ -731,24 +731,28 @@ DUP DEX
STA ESTKH,X
JMP NEXTOP
;*
;* CONSTANT
;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW)
;*
ZERO
CONST DEX
LSR ;LDA #$00
MINUS1 DEX
LDA #$FF
STA ESTKL,X
STA ESTKH,X
JMP NEXTOP
CN DEX
LSR ; A = CONST * 2
STA ESTKL,X
LDA #$00
STA ESTKH,X
JMP NEXTOP
CFFB DEX
LDA #$FF
CB DEX
LDA #$00
STA ESTKH,X
INY ;+INC_IP
LDA (IP),Y
STA ESTKL,X
JMP NEXTOP
CB DEX
LDA #$00
CFFB DEX
LDA #$FF
STA ESTKH,X
INY ;+INC_IP
LDA (IP),Y