Work In Progress (ASM)

This commit is contained in:
Rémy GIBERT 2015-10-30 17:34:59 +01:00
parent 40b78c11a4
commit 84712111d5
6 changed files with 282 additions and 18 deletions

View File

@ -45,7 +45,7 @@ DIR.EN clc
DIR.EP clc
rts
*---------------------------------------
DIR.EQ jsr EXP.Get
DIR.EQ jsr EXP.Eval
bcs .9
clc
@ -176,7 +176,7 @@ DIR.OP jsr SRC.GetArg
sec
rts
*---------------------------------------
DIR.OR jsr EXP.Get
DIR.OR jsr EXP.Eval
bcs .9
ldy #ASM.PC

View File

@ -5,8 +5,6 @@ INC 1
AUTO 6
.LIST OFF
*---------------------------------------
* Addressing Mode reserved : []#(),
* EXP.Operators .AS "^!|&<=>+-*/"
* U-Operators :
* B-Operators :
* Num Format : 0-9 -> decimal
@ -15,7 +13,7 @@ AUTO 6
* & = octal
* * = PC
*---------------------------------------
EXP.Get jsr SRC.GetCharNB
EXP.Eval jsr SRC.GetCharNB
beq .98
cmp #'*'
bne .10
@ -55,7 +53,14 @@ EXP.Get jsr SRC.GetCharNB
bra .8
.3 jsr SRC.IsLetter Symbol ?
.3 cmp #'&' octal?
bne .4
jsr SRC.GetOctal
bcs .97
bra .8
.4 jsr SRC.IsLetter Symbol ?
bcs .97

View File

@ -29,7 +29,7 @@ FIO.OpenFileA sta hFileName
ldy #SRC.COUNT
lda (pData),y
cmp #SRC.IN.DEPTH.MAX
cmp #SRC.IN.MAXDEPTH
bne .10
lda #ERR.SRC.TOO.MANY.IN

View File

@ -118,7 +118,7 @@ SRC.ParseLine.OpCode
>SYSCALL SYS.GetMemPtrA
>STYA ZPPtr1
ldy #ASM.T.O
ldy #ASM.T.O setup Ptr to Opcodes
lda (ZPPtr1),y
clc
adc ZPPtr1
@ -128,6 +128,17 @@ SRC.ParseLine.OpCode
adc ZPPtr1+1
sta ZPPtr2+1
ldy #ASM.T.R setup Ptr to Registers
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPPtr3
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPPtr3+1
.10 lda (ZPPtr2)
ldy #1
ora (ZPPtr2),y
@ -144,6 +155,8 @@ SRC.ParseLine.OpCode
cpx SRC.Buffer
bne .1
jsr SRC.ParseLine.AM
bcs .99
clc
rts
@ -160,7 +173,97 @@ SRC.ParseLine.OpCode
.9 lda #ERR.INVALID.OPCODE
sec
.99 rts
*---------------------------------------
SRC.ParseLine.AM stz SRC.AM.ID
stz SRC.AM.StrBuf
.1 jsr SRC.GetCharUC any arg immediately after ' '?
beq .8 no, AM.ID=0 (implied)
cmp #' ' another space ?
beq .8 ignore end of line (comment)
jsr SRC.IsAMReserved
bcs .2
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
bra .1
.8 lda SRC.AM.StrBuf
beq .89
>PUSHW L.SRC.AM.StrBuf
>PUSHW L.MSG.DEBUG
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.89 clc
rts
.2 jsr SRC.IsLetter Any register?
bcs .70 no, try something else
stz SRC.AM.tmpBuf
sta SRC.AM.tmpBuf+1
inc SRC.AM.tmpBuf
.3 jsr SRC.GetCharUC
beq .4
jsr SRC.IsLetterOrDigit
bne .4
inc SRC.AM.tmpBuf
ldx SRC.AM.tmpBuf
sta SRC.AM.tmpBuf,x
bra .3
.4 dec SRC.BufPtr back one char
ldy #0
.5 lda (ZPPtr3),y
beq .71 last register ?
ldx #$ff
.6 lda (ZPPtr3),y
iny
inx
cmp SRC.AM.tmpBuf,x
bne .7
cpx SRC.AM.tmpBuf
bne .6
ldy #0 register match, add to AM string
ldx SRC.AM.StrBuf
.61 iny
lda SRC.AM.tmpBuf,y
sta SRC.AM.StrBuf,x
inx
cpy SRC.AM.tmpBuf
bne .61
stx SRC.AM.StrBuf
bra .72
.7 iny
bra .5
.70 dec SRC.BufPtr back one char
.71 jsr SRC.GetExp
bcs .99
.72 jmp .1
clc
rts
.9 lda #ERR.INVALID.AM.SYN
sec
.99 rts
*---------------------------------------
SRC.PrintLine bcs .8 if CS, unconditional
ldy #ASM.MACRO.ON
@ -269,6 +372,52 @@ SRC.GetHex stz SRC.ACC+1
sec
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetOctal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetChar
beq .99
jsr SRC.IsDigit8
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
jsr SRC.IsDigit8
bcs .99
asl
asl
asl
asl
asl
ldx #3
.2 asl
rol SRC.ACC
rol SRC.ACC+1
rol SRC.ACC+2
rol SRC.ACC+3
bcs .9
dex
bne .2
bra .1
.8 clc
rts
.9 lda #ERR.VAL.TOO.BIG
sec
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
@ -386,6 +535,35 @@ SRC.GetKeyword >STYA ZPPtr1
inc SRC.Keyword.ID
bra .3
.9 sec
rts
*---------------------------------------
SRC.GetExp stz SRC.Exp
jsr SRC.GetCharUC
beq .9
ldy #0
jsr SRC.IsAMReserved
bcc .8
iny
sta SRC.Exp+1
.1 jsr SRC.GetCharUC
beq .89
cmp #' '
beq .89
jsr SRC.IsAMReserved
bcc .8
iny
sta SRC.Exp,y
bra .1
.8 dec SRC.BufPtr
.89 sty SRC.Exp
clc
rts
.9 sec
rts
*---------------------------------------
@ -410,6 +588,26 @@ SRC.GetArg jsr SRC.GetCharUC
.9 sec
rts
*---------------------------------------
SRC.IsAMReserved ldx SRC.AM.RESERVED
.1 cmp SRC.AM.RESERVED,x
beq .8
dex
bne .1
sec
rts
.8 clc
rts
*---------------------------------------
SRC.IsEXPReserved ldx SRC.EXP.RESERVED
.1 cmp SRC.EXP.RESERVED,x
beq .8
dex
bne .1
sec
rts
.8 clc
rts
*---------------------------------------
SRC.IsLetterOrDigit jsr SRC.IsDigit10
bcc SRC.IsLetterRTS
*---------------------------------------
@ -447,6 +645,14 @@ SRC.IsDigit10 cmp #'0'
cmp #'9'+1
rts cc if ok, cs if not
.9 sec
rts
*---------------------------------------
SRC.IsDigit8 cmp #'0'
bcc .9
cmp #'7'+1
rts cc if ok, cs if not
.9 sec
rts
*---------------------------------------
@ -460,7 +666,7 @@ SRC.GetCharUC jsr SRC.GetChar
beq .9
cmp #'a'
bcc .9
cmp #'{'
cmp #'z'+1
bcs .9
eor #$20 to Uppercase
.9 rts

View File

@ -5,6 +5,42 @@ INC 1
AUTO 6
.LIST OFF
*---------------------------------------
* Global Symbol Record: (7 bytes)
* 0 : SYM.Block.ID
* 1 : Index in SYM.Block
* 2 : Flags:
* b7=R/W (.SE)
* b6=Forward ref
* 3-6 : Value
*---------------------------------------
* Local Symbol Record: (4 bytes)
* 0,1 : Pointer to Global Symbol in main table
* 2 : 2 digits name (.99)
* 3 : offset from Global Symbol
*---------------------------------------
* Private Symbol Record: (7 bytes)
* 0,1 : MacroID
* 2 : 2 digits name (:99)
* 3-6 : Value
*---------------------------------------
SYM.Init >PUSHWI SYM.MAXCOUNT*8
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem
bcs .9
ldy #SYM.hMem
txa
sta (pData),y
clc
.9 rts
*---------------------------------------
SYM.Quit ldy #SYM.hMem
lda (pData),y
beq .8
>SYSCALL SYS.FreeMemA
.8 clc
rts
*---------------------------------------
SYM.Add
clc
rts
@ -41,7 +77,7 @@ SYM.LookupPrivate
clc
rts
*---------------------------------------
SYM.BLOCK.ALLOC ldx #0
SYM.AddBlock ldx #0
.1 lda SYM.BLOCKS,x
beq .2
inx

View File

@ -15,20 +15,22 @@ AUTO 6
*---------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
ZPPtr3 .EQ ZPBIN+4
*---------------------------------------
ASM.T.AM .EQ 0
ASM.T.R .EQ 2
ASM.T.O .EQ 4
*---------------------------------------
SYM.BLOCK.SIZE .EQ 4096
SYM.BLOCK.MAX .EQ 8
SRC.IN.DEPTH.MAX .EQ 7
SYM.BLOCK.MAX .EQ 128 128*256 = 32k max of symbols
SYM.MAXCOUNT .EQ 1024
SRC.IN.MAXDEPTH .EQ 7
SRC.LABEL.MAXLEN .EQ 32
*---------------------------------------
ERR.INV.ARGS .EQ $80
ERR.SRC.INV.TYPE .EQ $90
ERR.SRC.TOO.MANY.IN .EQ $91
ERR.SRC.UNEXP.EOF .EQ $92
ERR.OOM .EQ $93
ERR.SYNTAX.ERROR .EQ $A0
ERR.SYM.TOO.LONG .EQ $A1
ERR.VAL.TOO.BIG .EQ $A2
@ -36,6 +38,8 @@ ERR.LINE.TOO.LONG .EQ $A3
ERR.INVALID.LABEL .EQ $A4
ERR.INVALID.DIRECTIVE .EQ $A5
ERR.INVALID.OPCODE .EQ $A6
ERR.INVALID.AM.SYN .EQ $A7
ERR.INVALID.AM.4.OC .EQ $A8
ERR.MISSING.EXP .EQ $B0
ERR.EXP.SYN.ERROR .EQ $B1
ERR.INVALID.MACRO.DEF .EQ $E0
@ -63,6 +67,8 @@ L.MSG.HELP1 .DA MSG.HELP1
L.MSG.HELP2 .DA MSG.HELP2
L.MSG.SRCLINE .DA MSG.SRCLINE
L.MSG.ERROR .DA MSG.ERROR
L.MSG.DEBUG .DA MSG.DEBUG
L.SRC.AM.StrBuf .DA SRC.AM.StrBuf
L.MSG.PASS .DA MSG.PASS
L.MSG.SRC.FILE .DA MSG.SRC.FILE
L.MSG.OBJ.FILE .DA MSG.OBJ.FILE
@ -427,13 +433,15 @@ MSG.OBJ.FILE >CSTRING "Object File:%S, Type=%02x\n"
MSG.T.FILE >CSTRING "CPU Definition File:%S\n"
MSG.SRCLINE >CSTRING "%05D-%s\n"
MSG.ERROR >CSTRING "%05D-Error:$%h\n"
MSG.DEBUG >CSTRING "DEBUG:%S\n"
SRC.AM.RESERVED >PSTRING "[]#(),"
SRC.EXP.RESERVED >PSTRING "^!|&<=>+-*/"
ASM.T.DEFAULT .AS ".T.6502"
ASM.T.FILENAMELEN .BS 1
ASM.T.FILENAME .BS 65
hLIBSTR .BS 1
hFileName .BS 1
SRC.LINENUM .BS 2
SRC.BufPtr .BS 1
SRC.Label.Flags .BS 1
SRC.Label .BS SRC.LABEL.MAXLEN
SRC.LabelValue .BS 4
@ -441,6 +449,12 @@ SRC.Directive.ID .BS 1
SRC.Keyword.ID .BS 1
SRC.ACC .BS 4
SRC.ACCTMP .BS 4
SRC.AM.ID .BS 1
SRC.AM.StrBuf .BS 32
SRC.AM.tmpBuf .BS 32
SRC.Exp .BS 128
SRC.BufPtr .BS 1
SRC.BufPtrSave .BS 1
SRC.Buffer .BS 256
*--------------------------------------
.DUMMY
@ -452,9 +466,9 @@ bCANCEL .BS 1
SRC.hFILENAME .BS 1
SRC.COUNT .BS 1
SRC.hREFNUMS .BS SRC.IN.DEPTH.MAX Store ref_num of opened files (Main, .INs & .INBs)
SRC.hBUFFERS .BS SRC.IN.DEPTH.MAX Store hMem to allocated buffers
SRC.hFILETYPES .BS SRC.IN.DEPTH.MAX Store file type of opened SRC files
SRC.hREFNUMS .BS SRC.IN.MAXDEPTH Store ref_num of opened files (Main, .INs & .INBs)
SRC.hBUFFERS .BS SRC.IN.MAXDEPTH Store hMem to allocated buffers
SRC.hFILETYPES .BS SRC.IN.MAXDEPTH Store file type of opened SRC files
DST.hFILENAME .BS 1
DST.hREFNUM .BS 1
@ -463,6 +477,10 @@ DST.hFILETYPE .BS 1
ASM.T.hMem .BS 1 handle to ASM.T.xxxxx
SYM.Count .BS 2
SYM.hMem .BS 1
SYM.hBlocks .BS SYM.BLOCK.MAX
ASM.PASS .BS 1
ASM.MACRO.ON .BS 1
ASM.PH.ON .BS 1
@ -472,7 +490,6 @@ ASM.LI.XON .BS 1
ASM.PC .BS 4 32Bits PC
ASM.PC.PH .BS 4 32Bits PC saved for PH directive
SYM.BLOCKS .BS SYM.BLOCK.MAX
DS.END .ED
*---------------------------------------
MAN