A2osX/BIN/ASM.S.txt

519 lines
10 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BUILD/BIN/DEV/ASM
*---------------------------------------
.INB /A2OSX.BUILD/INC/MACROS.I
.INB /A2OSX.BUILD/INC/A2OSX.I
*---------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
ZPPtr3 .EQ ZPBIN+4
ZPBlockPtr .EQ ZPBIN+6
ZPSymbolPtr .EQ ZPBIN+8
*---------------------------------------
ASM.T.AM .EQ 0
ASM.T.R .EQ 2
ASM.T.O .EQ 4
*---------------------------------------
SRC.DO.MAXDEPTH .EQ 8
SRC.IN.MAXDEPTH .EQ 7
SRC.GLABEL.MAXLEN .EQ 32
*---------------------------------------
SYM.GBLOCK.MAX .EQ 96 96*256=24k
SYM.SBLOCK.MAX .EQ 16 16*256=4k
SYM.PBLOCK.MAX .EQ 32 32*256=8k
SYM.MBLOCK.MAX .EQ 32 32*256=8k
*---------------------------------------
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
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.RANGE .EQ $A9
ERR.UNDEF.SYMBOL .EQ $AA
ERR.SYMBOL.REDEFINE .EQ $AB
ERR.TOO.MANY.DO .EQ $AC
ERR.MISSING.EXP .EQ $B0
ERR.EXP.SYN.ERROR .EQ $B1
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 CS
.DA DS.END-DS.START DS
.DA #128 SS
.DA #10 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.HELP .DA MSG.HELP
L.MSG.SRCLINE .DA MSG.SRCLINE
L.MSG.ERROR .DA MSG.ERROR
L.MSG.SYMBOLS .DA MSG.SYMBOLS
L.MSG.GSYMBOL .DA MSG.GSYMBOL
L.MSG.LSYMBOL .DA MSG.LSYMBOL
L.MSG.SUMMARY .DA MSG.SUMMARY
L.MSG.PASS .DA MSG.PASS
L.MSG.SRC.FILE .DA MSG.SRC.FILE
L.MSG.OBJ.FILE .DA MSG.OBJ.FILE
L.MSG.T.FILE .DA MSG.T.FILE
L.SRC.AM.StrBuf .DA SRC.AM.StrBuf
L.SRC.GLabel.Flags .DA SRC.GLabel.Flags
L.SRC.GLabel.Len .DA SRC.GLabel.Len
L.SRC.ELabel.Flags .DA SRC.ELabel.Flags
L.SRC.ELabel.Len .DA SRC.ELabel.Len
L.SRC.BUFFER .DA SRC.BUFFER
L.ASM.T.FILENAME .DA ASM.T.FILENAME
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
.DA DIR.DU
.DA DIR.ED
.DA DIR.EL
.DA DIR.EM
.DA DIR.EN
.DA DIR.EP
.DA DIR.EQ
.DA DIR.FI
.DA DIR.HS
.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.IN
.DA DIR.LI
.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
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 ldy #S.PS.ARGC
lda (pPs),y
beq .99
lda #1
>SYSCALL GetArg.A
>SYSCALL RealPath.YA
txa
ldy #SRC.hFILENAME
sta (pData),y
jsr FIO.Init
bcs .9
jsr SYM.Init
bcs .9
jsr DIR.Init
* lda (pPs)
* ora #S.PS.F.EVENT
* sta (pPs)
clc
rts
.99 >LDYA L.MSG.HELP
>SYSCALL PrintF.YA
lda #ERR.INV.ARGS
sec
.9 rts
*--------------------------------------
CS.RUN >SYSCALL GetChar
bcs .11 no char
cmp #$03 Ctrl-C
beq .99 Abort....
cmp #$13 Ctrl-S
bne .11
ldy #bPause
lda (pData),y
eor #$ff
sta (pData),y
bne .8
.11 ldy #SRC.COUNT root file is already opened?
lda (pData),y
bne .10
ldy #ASM.PASS
lda (pData),y
inc
>PUSHA
>LDYA L.MSG.PASS
>SYSCALL PrintF.YA
ldy #SRC.hFILENAME
lda (pData),y
jsr FIO.OpenFileA
bcs .99
.10 stz UsrBuf256
jsr FIO.ReadLine
bcc .2
cmp #$4C End Of File?
bne .9
jsr FIO.FileClose
ldy #SRC.COUNT end of root file ?
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
.1 jsr SYM.Dump
>LDYA L.MSG.SUMMARY
>SYSCALL PrintF.YA
lda #0 End of assembly, exit with no error
.99 sec
rts
.2 jsr SRC.PrintLine
jsr SRC.ParseLine
bcs .9
.8 clc
rts
.9 pha
jsr SRC.PrintLineErr
pla
pha
>PUSHA
>PUSHW SRC.LINENUM
>LDYA L.MSG.ERROR
>SYSCALL PrintF.YA
pla
sec
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT jsr FIO.FileClose
bne CS.QUIT
jsr SYM.Quit
ldy #ASM.T.hMem
lda (pData),y
beq .1
>SYSCALL FreeMem.A
.1 ldy #SRC.hFILENAME
lda (pData),y
beq .8
>SYSCALL FreeMem.A
.8 clc
rts
*---------------------------------------
.INB /A2OSX.SRC/BIN/ASM.S.DIR
.INB /A2OSX.SRC/BIN/ASM.S.EXP
.INB /A2OSX.SRC/BIN/ASM.S.FIO
.INB /A2OSX.SRC/BIN/ASM.S.SRC
.INB /A2OSX.SRC/BIN/ASM.S.SYM
*---------------------------------------
CS.END
SRC.DIR.MAXLEN .EQ 5
T.DIRECTIVES .HS 02
.AS "AC"
.HS 02
.AS "AS"
.HS 02
.AS "AT"
.HS 02
.AS "AZ"
.HS 02
.AS "BS"
.HS 02
.AS "DA"
.HS 02
.AS "DO"
.HS 02
.AS "DU"
.HS 05
.AS "DUMMY"
.HS 02
.AS "ED"
.HS 04
.AS "ELSE"
.HS 02
.AS "EM"
.HS 02
.AS "EN"
.HS 02
.AS "EP"
.HS 02
.AS "EQ"
.HS 03
.AS "FIN"
.HS 02
.AS "HS"
.HS 02
.AS "IN"
.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"
.HS 04
.AS "LIST"
.HS 02
.AS "MA"
.HS 02
.AS "OP"
.HS 02
.AS "OR"
.HS 02
.AS "PG"
.HS 02
.AS "PH"
.HS 02
.AS "SE"
.HS 02
.AS "TA"
.HS 02
.AS "TF"
.HS 02
.AS "TI"
.HS 02
.AS "US"
.HS 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
*---------------------------------------
MSG.HELP >CSTR "A2osX-Macro Assembler (S-C MASM 3.0 Based)\r\nUsage : ASM <src file> [type TXT ($04) or S-C/BAS ($FA)]\r\n"
MSG.PASS >CSTR "Pass:#%d\r\n"
MSG.SRC.FILE >CSTR "Reading SRC File:%S\r\n"
MSG.OBJ.FILE >CSTR "Writing OBJ File:%S, Type=%02x\r\n"
MSG.T.FILE >CSTR "Loading CPU File:%S\r\n"
MSG.SRCLINE >CSTR "%H: %05D-%s\r\n"
MSG.ERROR >CSTR "%05D-Error:$%h\r\n"
MSG.SYMBOLS >CSTR "Symbol Table:\r\n"
MSG.GSYMBOL >CSTR "$%H%H:%S"
MSG.LSYMBOL >CSTR " .%d:+$%h"
MSG.SUMMARY >CSTR "\r\nEnd Of Assembly.\r\n"
SRC.AM.RESERVED >PSTR "[](),"
SRC.MOD.RESERVED >PSTR "#/<>"
SRC.EXP.RESERVED >PSTR "^!|&<=>+-*/"
ASM.T.DEFAULT .AS ".T.6502"
ASM.T.FILENAMELEN .BS 1
ASM.T.FILENAME .BS 65
FIO.hFileName .BS 1
FIO.hFullPath .BS 1
EXP.Operator .BS 1
EXP.Modifier .BS 1
SYM.iCurGBlock.Save .BS 1
SYM.pCurGBlock.Save .BS 1
SRC.LINENUM .BS 2
SRC.Directive.ID .BS 1
SRC.Keyword.ID .BS 1
SRC.ACC .BS 4
SRC.ACCTMP .BS 4
SRC.ARG .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
SRC.GLabel.New .BS 1
SRC.GLabel.Flags .BS 1
SRC.GLabel.Value .BS 4
SRC.GLabel.Len .BS 1
SRC.GLabel.Name .BS SRC.GLABEL.MAXLEN
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
UsrBuf256 .BS 256
*--------------------------------------
.DUMMY
.OR 0
DS.START
bPause .BS 1
SRC.hFILENAME .BS 1
SRC.COUNT .BS 1
SRC.hFILES .BS SRC.IN.MAXDEPTH
SRC.hFILETYPES .BS SRC.IN.MAXDEPTH
DST.hFILENAME .BS 1
DST.hREFNUM .BS 1
DST.hBUFFER .BS 1
DST.hFILETYPE .BS 1
ASM.T.hMem .BS 1
SYM.hCurSBlock .BS 1
SYM.iCurSBlock .BS 1
SYM.LastSBlock .BS 1
SYM.hSBlocks .BS SYM.SBLOCK.MAX
SYM.pCurGBlock .BS 1
SYM.iCurGBlock .BS 1
SYM.pLastGBlock .BS 1
SYM.iLastGBlock .BS 1
SYM.hGBlocks .BS SYM.GBLOCK.MAX
SYM.hCurPBlock .BS 1
SYM.iCurPBlock .BS 1
SYM.LastPBlock .BS 1
SYM.hPBlocks .BS SYM.PBLOCK.MAX
SYM.hCurMBlock .BS 1
SYM.iCurMBlock .BS 1
SYM.LastMBlock .BS 1
SYM.hMBlocks .BS SYM.MBLOCK.MAX
SYM.DumpCount .BS 1
DIR.Counter .BS 2
DIR.Byte .BS 1
ASM.PASS .BS 1
ASM.MACRO.ON .BS 1
ASM.DO.Count .BS 1
ASM.DOELSE.Flag .BS SRC.DO.MAXDEPTH
ASM.DO.ON .BS 1
ASM.PH.ON .BS 1
ASM.LI.ON .BS 1
ASM.LI.CON .BS 1
ASM.LI.XON .BS 1
ASM.PC .BS 4
ASM.PC.PH .BS 4
ASM.PC.GLABEL .BS 4
ASM.LOCAL.OFFSET .BS 1
ASM.LOCAL.INVALID .BS 1
ASM.SYM.ID .BS 2
DS.END .ED
*---------------------------------------
.DO DS.END-DS.START>$FF
ERROR:DS too big
.FIN
*---------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/ASM.S
ASM