A2osX/BIN/FORMAT.S.txt
2019-10-03 08:25:27 +02:00

280 lines
5.4 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.

NEW
PREFIX
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/FORMAT
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.E.I
.INB INC/KERNEL.I
.INB INC/LIBBLKDEV.I
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
ZPPtr2 .BS 2
ZPPtrFD .BS 2
ZPPtrDevName .BS 2
ZS.END
.ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DA #32 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBBLKDEV .DA LIBBLKDEV
L.MSG.USAGE .DA MSG.USAGE
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
L.MSG.NOSIZE .DA MSG.NOSIZE
L.MSG.INIT .DA MSG.INIT
L.FMT.BLANK .DA FMT.BLANK
.DA 0
*--------------------------------------
CS.INIT ldy #S.PS.ARGC
lda (pPs),y
beq .90
.1 >INC.G ArgIndex
>SYSCALL ArgV
bcc .11
jmp .8
.11 >STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
beq .90
cmp #'0'
bcc .20
cmp #'9'+1
bcs .20
and #$0F
>STA.G CatSize
bra .1
.20 ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.90 bra .99
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 >LDA.G hDevID
bne .5 Already have a dev...go get VolName
>LDYA ZPPtr1
>SYSCALL GetDevByName
bcs .99
>STYA ZPPtrFD
txa
>STA.G hDevID
>LDYA ZPPtr1
>STYA ZPPtrDevName
bra .1
.5 ldy #$ff
.6 iny
lda (ZPPtr1),y
beq .61
cpy #15
beq .99 VolName too long
.61 >PUSHW ZPPtr1
>LEA.G VolName
>SYSCALL StrCpy
jmp .1 success, scan for any other args
.8 >LDYA L.LIBBLKDEV
>SYSCALL LoadLib
bcs .9
sta hLIBBLKDEV
clc
.9 rts
.99 >PUSHBI 0
>LDYA L.MSG.USAGE
>SYSCALL printf
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN jsr CS.RUN.InitCat
bcs .9
jsr CS.RUN.BuildCat
bcs .9
jsr CS.RUN.WriteCat
bcs .9
>LDYA L.MSG.OK
>SYSCALL puts
lda #0
sec
rts
.9 pha
>PUSHA
>PUSHBI 1
>LDYA L.MSG.ERR
>SYSCALL printf
pla
sec
rts
*--------------------------------------
CS.RUN.InitCat >LDA.G CatSize
bne .1
lda #4
sta (pData),y
.1 >LDA.G VolName
bne .8 Volume name ok
>PUSHW A2osX.TIMER16
>PUSHW A2osX.RANDOM16
>PUSHBI 4
>PUSHW L.FMT.BLANK
>LEA.G VolName
>SYSCALL sprintf
rts
.8 clc
rts
*--------------------------------------
CS.RUN.BuildCat >PUSHEA.G DIB
>LDA.G hDevID
>SYSCALL GetDevStatus
bcs .99
>LDA.G DIB+S.DIB.SIZE
iny
ora (pData),y
bne .1
>PUSHBI 0
>LDYA L.MSG.NOSIZE
>SYSCALL printf
lda #MLI.E.IO
sec
rts
.1 >PUSHEA.G VolName
>PUSHW.G DIB+S.DIB.SIZE
>PUSHW ZPPtrDevName
>PUSHBI 6
>LDYA L.MSG.INIT
>SYSCALL printf
.99 bcs .9
jsr .7
>LIBCALL hLIBBLKDEV,LIBBLKDEV.GetProDOSCatSize
bcs .9
phy
pha
txa
>STA.G BlkCnt
pla
ply
>SYSCALL GetMem0 BufferSize
bcs .9
phx
>STYA.G IOCTL+S.IOCTL.BUFPTR
pla
>STA.G hBuf
jsr .7
>PUSHEA.G VolName
>PUSHW.G IOCTL+S.IOCTL.BUFPTR
>LIBCALL hLIBBLKDEV,LIBBLKDEV.BuildProDOSCat
.9 rts
.7 >PUSHW.G DIB+S.DIB.SIZE
>PUSHB.G CatSize
>PUSHB.G CatOptions
rts
*--------------------------------------
CS.RUN.WriteCat >PUSHEA.G IOCTL
>PUSHBI IOCTL.WRITEBLOCK
>LDA.G hDevID
>SYSCALL IOCTL
bcs .9
lda #'.'
>SYSCALL PutChar
>LDA.G IOCTL+S.IOCTL.BUFPTR+1
inc
inc
sta (pData),y
>INC.G IOCTL+S.IOCTL.BLKNUM
>SLEEP
>DEC.G BlkCnt
bne CS.RUN.WriteCat
.9 rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT >LDA.G hBuf
beq .1
>SYSCALL FreeMem
.1 lda hLIBBLKDEV
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
LIBBLKDEV .AZ "libblkdev"
hLIBBLKDEV .BS 1
*--------------------------------------
MSG.USAGE .AS "Usage : FORMAT <BLOCKDEV> [VOLUME.NAME]\r\n"
.AS " -L : Low-Level Format\r\n"
.AZ " -1-9 : Catalog Size (Blocks)\r\n"
MSG.OK .AZ "[OK]"
MSG.ERR .AZ "[%h]\r\n"
MSG.NOSIZE .AZ "Unable to get media size."
MSG.INIT .AZ "Formatting %s (%D Blks),Volname:%s..."
FMT.BLANK .AZ "BLANK%H%H"
*--------------------------------------
OptionList >PSTR "Ll"
OptionVars .DA #bLL,#bLL
*--------------------------------------
.DUMMY
.OR 0
DS.START
ArgIndex .BS 1
bLL .BS 1
VolName .BS 16
hDevID .BS 1
CatSize .BS 1
CatOptions .BS 1
BlkCnt .BS 1
IOCTL .BS S.IOCTL
hBuf .BS 1
DIB .BS S.DIB
DS.END .ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/FORMAT.S
ASM