mirror of
https://github.com/A2osX/A2osX.git
synced 2025-01-24 05:35:33 +00:00
450 lines
8.8 KiB
Plaintext
450 lines
8.8 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
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/A2OSX.API.I
|
||
.INB INC/LIBSTR.I
|
||
*---------------------------------------
|
||
ZPPtr1 .EQ ZPBIN
|
||
ZPPtr2 .EQ ZPBIN+2
|
||
*---------------------------------------
|
||
SYM.BLOCK.SIZE .EQ 4096
|
||
SYM.BLOCK.MAX .EQ 8
|
||
SRC.IN.DEPTH.MAX .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.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.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
|
||
.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.HELP1 .DA MSG.HELP1
|
||
L.MSG.HELP2 .DA MSG.HELP2
|
||
L.MSG.SRCLINE .DA MSG.SRCLINE
|
||
L.MSG.ERROR .DA MSG.ERROR
|
||
L.MSG.PASS .DA MSG.PASS
|
||
L.MSG.SRC.FILE .DA MSG.SRC.FILE
|
||
L.MSG.OBJ.FILE .DA MSG.OBJ.FILE
|
||
L.SRC.BUFFER .DA SRC.BUFFER
|
||
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
|
||
.DA 0
|
||
*---------------------------------------
|
||
CS.INIT >LDYA L.LIBSTR
|
||
>LOADLIBYA
|
||
sta hLIBSTR
|
||
|
||
ldy #S.PS.hARGS
|
||
lda (pPs),y
|
||
bne .1
|
||
|
||
>PUSHW L.MSG.HELP1
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTF
|
||
>PUSHW L.MSG.HELP2
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTF
|
||
lda #ERR.INV.ARGS
|
||
sec
|
||
rts
|
||
|
||
.1 >SYSCALL SYS.PStrCpyA
|
||
ldy #SRC.hFILENAME
|
||
sta (pData),y Store filename
|
||
|
||
lda #$80
|
||
ldy #ASM.LI.ON
|
||
sta (pData),y
|
||
|
||
lda #$00
|
||
ldy #ASM.LI.CON
|
||
sta (pData),y
|
||
ldy #ASM.LI.XON
|
||
sta (pData),y
|
||
|
||
lda (pPs)
|
||
ora #S.PS.F.EVENT Now accept events
|
||
sta (pPs)
|
||
|
||
clc
|
||
rts
|
||
|
||
.98 lda #ERR.INV.ARGS
|
||
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
CS.RUN ldy #bCANCEL
|
||
lda (pData),y
|
||
bne .99
|
||
|
||
ldy #bSTOP
|
||
lda (pData),y
|
||
bne .8
|
||
|
||
ldy #SRC.COUNT root file is already opened?
|
||
lda (pData),y
|
||
bne .10
|
||
|
||
ldy #ASM.PASS
|
||
lda (pData),y
|
||
inc
|
||
>PUSHA
|
||
>PUSHW L.MSG.PASS
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTF
|
||
|
||
ldy #SRC.hFILENAME
|
||
lda (pData),y
|
||
|
||
jsr SRC.OpenFileA
|
||
bcs .99
|
||
|
||
.10 jsr SRC.ReadLine
|
||
bcc .2
|
||
cmp #$4C End Of File?
|
||
bne .9
|
||
|
||
jsr SRC.FileClose
|
||
|
||
ldy #ASM.MA.ON Macro learning mode ?
|
||
lda (pData),y
|
||
bpl .22
|
||
|
||
lda #ERR.SRC.UNEXP.EOF
|
||
sec
|
||
rts
|
||
|
||
.22 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 lda #0 End of assembly, exit with no error
|
||
.99 sec
|
||
rts
|
||
|
||
.2 jsr SRC.ParseLine
|
||
bcs .9
|
||
|
||
jsr SRC.PrintLine with CC, conditional
|
||
|
||
ldy #ASM.MA.ON Macro learning mode ?
|
||
lda (pData),y
|
||
bmi .10
|
||
.8 clc
|
||
rts
|
||
|
||
.9 pha
|
||
sec
|
||
jsr SRC.PrintLine with CS, print always
|
||
pla
|
||
pha
|
||
>PUSHA
|
||
>PUSHW SRC.LINENUM
|
||
>PUSHW L.MSG.ERROR
|
||
>LIBCALL hLIBSTR,LIBSTR.PRINTF
|
||
pla
|
||
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
|
||
|
||
lda #$FF
|
||
ldy #bCANCEL
|
||
sta (pData),y
|
||
bra .8
|
||
|
||
.1 cmp #$13 Ctrl-S
|
||
bne .8
|
||
|
||
ldy #bSTOP
|
||
lda (pData),y
|
||
eor #$FF
|
||
sta (pData),y
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.QUIT jsr SRC.FileClose
|
||
bne CS.QUIT
|
||
|
||
ldy #SRC.hFILENAME
|
||
lda (pData),y
|
||
beq .8
|
||
|
||
>SYSCALL SYS.FreeMemA
|
||
|
||
.8 lda hLIBSTR
|
||
>SYSCALL SYS.UnloadLibA
|
||
clc
|
||
rts
|
||
*---------------------------------------
|
||
LOAD.ASM.T
|
||
clc
|
||
rts
|
||
*---------------------------------------
|
||
*---------------------------------------
|
||
.INB BIN/ASM.S.SRC
|
||
.INB BIN/ASM.S.DIR
|
||
.INB BIN/ASM.S.SYM
|
||
*---------------------------------------
|
||
CS.END
|
||
SRC.DIR.MAXLEN .EQ 5 (DUMMY)
|
||
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
|
||
*---------------------------------------
|
||
LIBSTR >PSTRING "libstr.o"
|
||
MSG.HELP1 >CSTRING "A2osX-Macro Assembler (S-C MASM 3.0 Based)\n"
|
||
MSG.HELP2 >CSTRING "Usage : ASM <src file> [type TXT ($04) or S-C/BAS ($FA)]\n"
|
||
MSG.PASS >CSTRING "Pass:#%d\n"
|
||
MSG.SRC.FILE >CSTRING "Source File:%S\n"
|
||
MSG.OBJ.FILE >CSTRING "Object File:%S, Type=%02x\n"
|
||
MSG.SRCLINE >CSTRING "%05D-%s\n"
|
||
MSG.ERROR >CSTRING "%05D-Error:$%h\n"
|
||
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
|
||
SRC.Directive.ID .BS 1
|
||
SRC.Keyword.ID .BS 1
|
||
SRC.ACC .BS 4
|
||
SRC.ACCTMP .BS 4
|
||
SRC.Buffer .BS 256
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
bSTOP .BS 1
|
||
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
|
||
|
||
DST.hFILENAME .BS 1
|
||
DST.hREFNUM .BS 1
|
||
DST.hBUFFER .BS 1
|
||
DST.hFILETYPE .BS 1
|
||
|
||
ASM.T.hFILENAME .BS 1
|
||
ASM.T.hFILE .BS 1 handle to ASM.T.xxxxx
|
||
|
||
ASM.PASS .BS 1
|
||
ASM.PH.ON .BS 1
|
||
ASM.LI.ON .BS 1
|
||
ASM.LI.CON .BS 1
|
||
ASM.LI.XON .BS 1
|
||
ASM.MA.ON .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
|
||
SAVE BIN/ASM.S
|
||
ASM
|