A2osX/BIN/ASM.S.txt

553 lines
11 KiB
Plaintext
Raw Normal View History

PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2016-06-07 06:10:18 +00:00
LOMEM $C00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/ASM
*---------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
*---------------------------------------
2015-10-06 16:14:48 +00:00
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
2015-10-30 16:34:59 +00:00
ZPPtr3 .EQ ZPBIN+4
2015-11-20 16:31:14 +00:00
ZPBlockPtr .EQ ZPBIN+6
2015-11-27 16:26:11 +00:00
ZPSymbolPtr .EQ ZPBIN+8
2015-10-06 16:14:48 +00:00
*---------------------------------------
2015-10-28 16:55:12 +00:00
ASM.T.AM .EQ 0
ASM.T.R .EQ 2
ASM.T.O .EQ 4
*---------------------------------------
2015-12-04 16:33:33 +00:00
SRC.DO.MAXDEPTH .EQ 8
2015-10-30 16:34:59 +00:00
SRC.IN.MAXDEPTH .EQ 7
2015-11-13 16:25:31 +00:00
SRC.GLABEL.MAXLEN .EQ 32
*---------------------------------------
2015-11-20 16:31:14 +00:00
SYM.GBLOCK.MAX .EQ 96 96*256=24k
2015-11-13 16:25:31 +00:00
SYM.SBLOCK.MAX .EQ 16 16*256=4k
SYM.PBLOCK.MAX .EQ 32 32*256=8k
SYM.MBLOCK.MAX .EQ 32 32*256=8k
*---------------------------------------
2015-10-06 16:14:48 +00:00
ERR.INV.ARGS .EQ $80
ERR.SRC.INV.TYPE .EQ $90
ERR.SRC.TOO.MANY.IN .EQ $91
2015-10-09 15:53:30 +00:00
ERR.SRC.UNEXP.EOF .EQ $92
2015-10-30 16:34:59 +00:00
ERR.OOM .EQ $93
2015-10-06 16:14:48 +00:00
ERR.SYNTAX.ERROR .EQ $A0
ERR.SYM.TOO.LONG .EQ $A1
ERR.VAL.TOO.BIG .EQ $A2
ERR.LINE.TOO.LONG .EQ $A3
ERR.INVALID.LABEL .EQ $A4
ERR.INVALID.DIRECTIVE .EQ $A5
2015-10-28 16:55:12 +00:00
ERR.INVALID.OPCODE .EQ $A6
2015-10-30 16:34:59 +00:00
ERR.INVALID.AM.SYN .EQ $A7
ERR.INVALID.AM.4.OC .EQ $A8
2015-11-20 16:31:14 +00:00
ERR.RANGE .EQ $A9
ERR.UNDEF.SYMBOL .EQ $AA
ERR.SYMBOL.REDEFINE .EQ $AB
2015-12-04 16:33:33 +00:00
ERR.TOO.MANY.DO .EQ $AC
2015-10-09 15:53:30 +00:00
ERR.MISSING.EXP .EQ $B0
ERR.EXP.SYN.ERROR .EQ $B1
2015-10-06 16:14:48 +00:00
ERR.INVALID.MACRO.DEF .EQ $E0
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBSTR .DA LIBSTR
L.MSG.HELP .DA MSG.HELP
L.MSG.SRCLINE .DA MSG.SRCLINE
2015-10-02 16:04:30 +00:00
L.MSG.ERROR .DA MSG.ERROR
2015-11-20 16:31:14 +00:00
L.MSG.SYMBOLS .DA MSG.SYMBOLS
L.MSG.GSYMBOL .DA MSG.GSYMBOL
L.MSG.LSYMBOL .DA MSG.LSYMBOL
L.MSG.SUMMARY .DA MSG.SUMMARY
2015-10-06 16:14:48 +00:00
L.MSG.PASS .DA MSG.PASS
L.MSG.SRC.FILE .DA MSG.SRC.FILE
L.MSG.OBJ.FILE .DA MSG.OBJ.FILE
2015-10-21 16:24:11 +00:00
L.MSG.T.FILE .DA MSG.T.FILE
2015-11-20 16:31:14 +00:00
L.SRC.AM.StrBuf .DA SRC.AM.StrBuf
2015-11-27 16:26:11 +00:00
L.SRC.GLabel.Flags .DA SRC.GLabel.Flags
2015-11-20 16:31:14 +00:00
L.SRC.GLabel.Len .DA SRC.GLabel.Len
2015-11-27 16:26:11 +00:00
L.SRC.ELabel.Flags .DA SRC.ELabel.Flags
2015-11-20 16:31:14 +00:00
L.SRC.ELabel.Len .DA SRC.ELabel.Len
2015-10-06 16:14:48 +00:00
L.SRC.BUFFER .DA SRC.BUFFER
2015-10-21 16:24:11 +00:00
L.ASM.T.FILENAME .DA ASM.T.FILENAME
2015-10-04 20:55:51 +00:00
L.T.DIRECTIVES .DA T.DIRECTIVES
J.DIRECTIVES .DA DIR.AC
.DA DIR.AS
.DA DIR.AT
.DA DIR.AZ
.DA DIR.BS
.DA DIR.DA
.DA DIR.DO
.DA DIR.DU
2015-10-06 16:14:48 +00:00
.DA DIR.DU
2015-10-04 20:55:51 +00:00
.DA DIR.ED
.DA DIR.EL
2015-10-06 16:14:48 +00:00
.DA DIR.EM
2015-10-04 20:55:51 +00:00
.DA DIR.EN
.DA DIR.EP
.DA DIR.EQ
.DA DIR.FI
.DA DIR.HS
.DA DIR.IN
2015-10-06 16:14:48 +00:00
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.IN
.DA DIR.LI
2015-10-04 20:55:51 +00:00
.DA DIR.LI
.DA DIR.MA
.DA DIR.OP
.DA DIR.OR
.DA DIR.PG
.DA DIR.PH
.DA DIR.SE
.DA DIR.TA
.DA DIR.TF
.DA DIR.TI
.DA DIR.US
2015-10-06 16:14:48 +00:00
L.T.LI .DA T.LI
J.LI .DA DIR.LI.CON
.DA DIR.LI.COFF
.DA DIR.LI.XON
.DA DIR.LI.XOFF
.DA DIR.LI.ON
.DA DIR.LI.OFF
J.EXP.OP .DA EXP.OP.EOR ^!|&<=>+-*/
.DA EXP.OP.ORA
.DA EXP.OP.ORA
.DA EXP.OP.AND
.DA EXP.OP.LOW
.DA EXP.OP.EQU
.DA EXP.OP.GRT
.DA EXP.OP.ADD
.DA EXP.OP.SUB
.DA EXP.OP.MUL
.DA EXP.OP.DIV
.DA 0
*---------------------------------------
CS.INIT >LDYA L.LIBSTR
>SYSCALL SYS.LoadLibYA
sta hLIBSTR
>SYSCALL SYS.GetArgC
cmp #1
beq .99 No arg, new file....
lda #1
>SYSCALL SYS.GetArgA
>SYSCALL SYS.GetFullPathYA
2016-08-17 06:25:58 +00:00
txa
2015-10-06 16:14:48 +00:00
ldy #SRC.hFILENAME
2015-12-04 16:33:33 +00:00
sta (pData),y
2015-10-21 16:24:11 +00:00
2015-12-04 16:33:33 +00:00
jsr FIO.Init
bcs .9
2015-10-21 16:24:11 +00:00
2015-11-20 16:31:14 +00:00
jsr SYM.Init
2015-12-04 16:33:33 +00:00
bcs .9
2015-11-20 16:31:14 +00:00
2015-12-04 16:33:33 +00:00
jsr DIR.Init
2015-10-06 16:14:48 +00:00
2015-10-04 20:55:51 +00:00
lda (pPs)
2015-12-04 16:33:33 +00:00
ora #S.PS.F.EVENT
sta (pPs)
clc
rts
.99 >PUSHW L.MSG.HELP
2015-12-04 16:33:33 +00:00
>LIBCALL hLIBSTR,LIBSTR.PRINTF
lda #ERR.INV.ARGS
sec
2015-12-04 16:33:33 +00:00
.9 rts
*--------------------------------------
2015-09-16 20:48:59 +00:00
CS.RUN ldy #bCANCEL
lda (pData),y
2015-10-02 16:04:30 +00:00
bne .99
2015-10-02 16:04:30 +00:00
ldy #bSTOP
2015-09-16 20:48:59 +00:00
lda (pData),y
2015-10-02 16:04:30 +00:00
bne .8
ldy #SRC.COUNT root file is already opened?
lda (pData),y
bne .10
2015-10-06 16:14:48 +00:00
ldy #ASM.PASS
2015-10-09 15:53:30 +00:00
lda (pData),y
inc
2015-10-06 16:14:48 +00:00
>PUSHA
>PUSHW L.MSG.PASS
>LIBCALL hLIBSTR,LIBSTR.PRINTF
2015-10-02 16:04:30 +00:00
ldy #SRC.hFILENAME
lda (pData),y
2015-10-28 16:55:12 +00:00
jsr FIO.OpenFileA
2015-10-06 16:14:48 +00:00
bcs .99
2015-10-02 16:04:30 +00:00
2015-10-28 16:55:12 +00:00
.10 jsr FIO.ReadLine
2015-10-02 16:04:30 +00:00
bcc .2
cmp #$4C End Of File?
bne .9
2015-10-28 16:55:12 +00:00
jsr FIO.FileClose
2015-10-09 15:53:30 +00:00
2015-10-28 16:55:12 +00:00
ldy #SRC.COUNT end of root file ?
2015-10-02 16:04:30 +00:00
lda (pData),y
bne .8 no continue back to previous file
ldy #ASM.PASS
lda (pData),y End of pass #2 ??
bne .1
inc
sta (pData),y
clc
rts
2015-11-20 16:31:14 +00:00
.1 jsr SYM.Dump
>PUSHW L.MSG.SUMMARY
>LIBCALL hLIBSTR,LIBSTR.PRINTF
lda #0 End of assembly, exit with no error
2015-10-02 16:04:30 +00:00
.99 sec
rts
2015-12-17 16:57:35 +00:00
.2 jsr SRC.PrintLine
2015-09-25 15:50:15 +00:00
2015-11-27 16:26:11 +00:00
jsr SRC.ParseLine
bcs .9
2015-10-02 16:04:30 +00:00
.8 clc
rts
2015-10-06 16:14:48 +00:00
.9 pha
2015-12-17 16:57:35 +00:00
jsr SRC.PrintLineErr
2015-10-06 16:14:48 +00:00
pla
pha
>PUSHA
2015-10-02 16:04:30 +00:00
>PUSHW SRC.LINENUM
>PUSHW L.MSG.ERROR
>LIBCALL hLIBSTR,LIBSTR.PRINTF
2015-10-06 16:14:48 +00:00
pla
2015-10-02 16:04:30 +00:00
sec
rts
*--------------------------------------
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPs),y
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .1
2015-09-16 20:48:59 +00:00
lda #$FF
2015-09-16 20:48:59 +00:00
ldy #bCANCEL
sta (pData),y
bra .8
2015-09-16 20:48:59 +00:00
.1 cmp #$13 Ctrl-S
bne .8
2015-09-16 20:48:59 +00:00
ldy #bSTOP
lda (pData),y
eor #$FF
2015-09-16 20:48:59 +00:00
sta (pData),y
.8 clc
rts
.9 sec
rts
*--------------------------------------
2015-10-28 16:55:12 +00:00
CS.QUIT jsr FIO.FileClose
2015-10-02 16:04:30 +00:00
bne CS.QUIT
2015-11-20 16:31:14 +00:00
jsr SYM.Quit
2015-10-21 16:24:11 +00:00
ldy #ASM.T.hMem
lda (pData),y
beq .1
>SYSCALL SYS.FreeMemA
.1 ldy #SRC.hFILENAME
lda (pData),y
2015-09-16 15:58:06 +00:00
beq .8
>SYSCALL SYS.FreeMemA
2015-10-28 16:55:12 +00:00
.8 lda hLIBSTR
>SYSCALL SYS.UnloadLibA
clc
rts
*---------------------------------------
2015-10-04 20:55:51 +00:00
.INB BIN/ASM.S.DIR
2015-10-28 16:55:12 +00:00
.INB BIN/ASM.S.EXP
.INB BIN/ASM.S.FIO
.INB BIN/ASM.S.SRC
2015-10-04 20:55:51 +00:00
.INB BIN/ASM.S.SYM
2015-10-02 16:04:30 +00:00
*---------------------------------------
CS.END
SRC.DIR.MAXLEN .EQ 5
2015-10-04 20:55:51 +00:00
T.DIRECTIVES .HS 02
.AS "AC"
.HS 02
.AS "AS"
.HS 02
.AS "AT"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "AZ"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "BS"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "DA"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "DO"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "DU"
2015-10-04 20:55:51 +00:00
.HS 05
.AS "DUMMY"
.HS 02
.AS "ED"
2015-10-04 20:55:51 +00:00
.HS 04
.AS "ELSE"
.HS 02
2015-10-06 16:14:48 +00:00
.AS "EM"
.HS 02
.AS "EN"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "EP"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "EQ"
2015-10-04 20:55:51 +00:00
.HS 03
.AS "FIN"
.HS 02
.AS "HS"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "IN"
2015-10-04 20:55:51 +00:00
.HS 03
.AS "INB"
.HS 04
.AS "INB1"
.HS 04
.AS "INB2"
.HS 04
.AS "INB3"
.HS 04
.AS "INB4"
.HS 04
.AS "INB5"
.HS 04
.AS "INB6"
.HS 04
.AS "INB7"
.HS 04
.AS "INB8"
.HS 04
.AS "INB9"
.HS 02
.AS "LI"
2015-10-04 20:55:51 +00:00
.HS 04
.AS "LIST"
.HS 02
.AS "MA"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "OP"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "OR"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "PG"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "PH"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "SE"
.HS 02
.AS "TA"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "TF"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "TI"
2015-10-04 20:55:51 +00:00
.HS 02
.AS "US"
2015-10-04 20:55:51 +00:00
.HS 00
*---------------------------------------
2015-10-06 16:14:48 +00:00
T.LI .HS 03
.AS "CON"
.HS 04
.AS "COFF"
.HS 03
.AS "XON"
.HS 04
.AS "XOFF"
.HS 02
.AS "ON"
.HS 03
.AS "OFF"
.HS 00
*---------------------------------------
LIBSTR >PSTRING "libstr.o"
MSG.HELP >CSTRING "A2osX-Macro Assembler (S-C MASM 3.0 Based)\nUsage : ASM <src file> [type TXT ($04) or S-C/BAS ($FA)]\n"
2015-10-06 16:14:48 +00:00
MSG.PASS >CSTRING "Pass:#%d\n"
2015-11-20 16:31:14 +00:00
MSG.SRC.FILE >CSTRING "Reading SRC File:%S\n"
MSG.OBJ.FILE >CSTRING "Writing OBJ File:%S, Type=%02x\n"
MSG.T.FILE >CSTRING "Loading CPU File:%S\n"
2015-12-04 16:33:33 +00:00
MSG.SRCLINE >CSTRING "%H: %05D-%s\n"
2015-10-02 16:04:30 +00:00
MSG.ERROR >CSTRING "%05D-Error:$%h\n"
2015-11-20 16:31:14 +00:00
MSG.SYMBOLS >CSTRING "Symbol Table:\n"
MSG.GSYMBOL >CSTRING "$%H%H:%S"
MSG.LSYMBOL >CSTRING " .%d:+$%h"
MSG.SUMMARY >CSTRING "\nEnd Of Assembly.\n"
2015-12-17 16:57:35 +00:00
SRC.AM.RESERVED >PSTRING "[](),"
2015-11-20 16:31:14 +00:00
SRC.MOD.RESERVED >PSTRING "#/<>"
2015-10-30 16:34:59 +00:00
SRC.EXP.RESERVED >PSTRING "^!|&<=>+-*/"
2015-10-21 16:24:11 +00:00
ASM.T.DEFAULT .AS ".T.6502"
ASM.T.FILENAMELEN .BS 1
ASM.T.FILENAME .BS 65
hLIBSTR .BS 1
2015-11-20 16:31:14 +00:00
FIO.hFileName .BS 1
FIO.hFullPath .BS 1
EXP.Operator .BS 1
2015-12-17 16:57:35 +00:00
EXP.Modifier .BS 1
SYM.iCurGBlock.Save .BS 1
SYM.pCurGBlock.Save .BS 1
2015-11-20 16:31:14 +00:00
2015-09-16 20:48:59 +00:00
SRC.LINENUM .BS 2
2015-10-06 16:14:48 +00:00
SRC.Directive.ID .BS 1
SRC.Keyword.ID .BS 1
2015-10-02 16:04:30 +00:00
SRC.ACC .BS 4
SRC.ACCTMP .BS 4
2015-11-27 16:26:11 +00:00
SRC.ARG .BS 4
2015-10-30 16:34:59 +00:00
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
2015-10-06 16:14:48 +00:00
SRC.Buffer .BS 256
2015-11-20 16:31:14 +00:00
SRC.GLabel.New .BS 1
2015-11-13 16:25:31 +00:00
SRC.GLabel.Flags .BS 1
2015-11-20 16:31:14 +00:00
SRC.GLabel.Value .BS 4
2015-11-13 16:25:31 +00:00
SRC.GLabel.Len .BS 1
SRC.GLabel.Name .BS SRC.GLABEL.MAXLEN
2015-11-20 16:31:14 +00:00
SRC.LLabel.ID .BS 1
SRC.LLabel.Offset .BS 1
SRC.ELabel.Flags .BS 1
SRC.ELabel.Value .BS 4
SRC.ELabel.Len .BS 1
SRC.ELabel.Name .BS SRC.GLABEL.MAXLEN
SRC.FLabel.Flags .BS 1
SRC.FLabel.Value .BS 4
SRC.FLabel.Len .BS 1
SRC.FLabel.Name .BS SRC.GLABEL.MAXLEN
*--------------------------------------
.DUMMY
.OR 0
DS.START
bSTOP .BS 1
bCANCEL .BS 1
2015-09-16 20:48:59 +00:00
2015-10-02 16:04:30 +00:00
SRC.hFILENAME .BS 1
2015-09-16 15:58:06 +00:00
SRC.COUNT .BS 1
2015-12-04 16:33:33 +00:00
SRC.hREFNUMS .BS SRC.IN.MAXDEPTH
SRC.hBUFFERS .BS SRC.IN.MAXDEPTH
SRC.hFILETYPES .BS SRC.IN.MAXDEPTH
DST.hFILENAME .BS 1
DST.hREFNUM .BS 1
DST.hBUFFER .BS 1
2015-10-02 16:04:30 +00:00
DST.hFILETYPE .BS 1
2015-09-16 20:48:59 +00:00
2015-12-04 16:33:33 +00:00
ASM.T.hMem .BS 1
2015-10-06 16:14:48 +00:00
2015-11-20 16:31:14 +00:00
SYM.hCurSBlock .BS 1
SYM.iCurSBlock .BS 1
2015-11-13 16:25:31 +00:00
SYM.LastSBlock .BS 1
SYM.hSBlocks .BS SYM.SBLOCK.MAX
2015-12-04 16:33:33 +00:00
SYM.pCurGBlock .BS 1
2015-11-20 16:31:14 +00:00
SYM.iCurGBlock .BS 1
2015-12-04 16:33:33 +00:00
SYM.pLastGBlock .BS 1
SYM.iLastGBlock .BS 1
2015-11-20 16:31:14 +00:00
SYM.hGBlocks .BS SYM.GBLOCK.MAX
SYM.hCurPBlock .BS 1
SYM.iCurPBlock .BS 1
SYM.LastPBlock .BS 1
2015-11-13 16:25:31 +00:00
SYM.hPBlocks .BS SYM.PBLOCK.MAX
2015-11-20 16:31:14 +00:00
SYM.hCurMBlock .BS 1
SYM.iCurMBlock .BS 1
SYM.LastMBlock .BS 1
2015-11-13 16:25:31 +00:00
SYM.hMBlocks .BS SYM.MBLOCK.MAX
2015-11-20 16:31:14 +00:00
SYM.DumpCount .BS 1
2015-10-30 16:34:59 +00:00
2015-12-04 16:33:33 +00:00
DIR.Counter .BS 2
DIR.Byte .BS 1
ASM.PASS .BS 1
2015-10-28 16:55:12 +00:00
ASM.MACRO.ON .BS 1
2015-12-04 16:33:33 +00:00
ASM.DO.Count .BS 1
ASM.DOELSE.Flag .BS SRC.DO.MAXDEPTH
ASM.DO.ON .BS 1
2015-10-02 16:04:30 +00:00
ASM.PH.ON .BS 1
2015-10-06 16:14:48 +00:00
ASM.LI.ON .BS 1
ASM.LI.CON .BS 1
ASM.LI.XON .BS 1
2015-12-04 16:33:33 +00:00
ASM.PC .BS 4
ASM.PC.PH .BS 4
ASM.PC.GLABEL .BS 4
2015-12-17 16:57:35 +00:00
ASM.LOCAL.OFFSET .BS 1
ASM.LOCAL.INVALID .BS 1
ASM.SYM.ID .BS 2
DS.END .ED
2015-11-20 16:31:14 +00:00
*---------------------------------------
.DO DS.END-DS.START>$FF
ERROR:DS too big
.FIN
*---------------------------------------
MAN
SAVE BIN/ASM.S
ASM