A2osX/BIN/MD5.S.txt
2018-08-23 17:16:20 +02:00

223 lines
4.1 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 /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/MD5
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.ERR.I
.INB INC/LIBCRYPT.I
*--------------------------------------
FILEBUF.SIZE .EQ 4096
*--------------------------------------
ZPPtr1 .EQ ZPBIN
ZPDataBufPtr .EQ ZPBIN+2
*--------------------------------------
* 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 #16 SS
.DA #4 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBCRYPT .DA LIBCRYPT
L.MSG.USAGE .DA MSG.USAGE
.DA 0
*--------------------------------------
CS.INIT ldy #S.PS.ARGC
lda (pPs),y
beq .99
.1 >INC.G ArgIndex
>SYSCALL GetArg
bcs .8
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
beq .99
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >PUSHBI 0
>LDYA L.MSG.USAGE
>SYSCALL printf
lda #K.E.SYN
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 >LDA.G Arg
bne .99
>LDA.G ArgIndex
>STA.G Arg
bra .1
.8 >LDYA L.LIBCRYPT
>SYSCALL LoadLib
bcs .9
sta hLIBCRYPT
* lda (pPs)
* ora #S.PS.F.EVENT Now accept events
* sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >LDA.G bText
beq CS.RUN.FILE
*--------------------------------------
CS.RUN.TEXT >LDA.G Arg
>SYSCALL GetArg
>PUSHYA
>PUSHEA.G MD5Buf
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5
bcs CS.RUN.TEXT.RTS
jmp CS.RUN.PRINT
CS.RUN.TEXT.RTS rts
*--------------------------------------
CS.RUN.FILE >LDA.G Arg
>SYSCALL GetArg
>SYSCALL RealPath
bcs CS.RUN.TEXT.RTS
txa
>STA.G hFullPath
>LDYAI FILEBUF.SIZE
>SYSCALL getmem
bcs .9
>STYA ZPDataBufPtr
txa
>STA.G hDataBuf
>PUSHWI 0 Aux type
>PUSHBI 0
>PUSHBI SYS.FOpen.R
>LDA.G hFullPath
>SYSCALL GetMemPtr
>SYSCALL FOpen
bcs .9
>STA.G hFile
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Init
bcs .9
>STA.G hMD5Ctx
.1 >PUSHWI FILEBUF.SIZE Bytes To Read
>PUSHW ZPDataBufPtr Dst Ptr
>LDA.G hFile
>SYSCALL FRead
bcc .2
eor #MLI.E.EOF
beq .8
.9 rts
.2 >PUSHYA MD5 DataLen
>PUSHW ZPDataBufPtr
>PUSHB.G hMD5Ctx
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Update
bra .1
.8 >PUSHEA.G MD5Buf
>PUSHB.G hMD5Ctx
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Finalize
CS.RUN.PRINT >LEA.G MD5Buf
>SYSCALL puts
lda #0
sec
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT >LDA.G hFullPath
beq .1
>SYSCALL FreeMem
.1 >LDA.G hDataBuf
beq .2
>SYSCALL FreeMem
.2 >LDA.G hFile
beq .3
>SYSCALL fclose
.3
.7 lda hLIBCRYPT
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "Dd"
OptionVars .DA #bText,#bText
*--------------------------------------
MSG.USAGE .AZ "Usage : MD5 [ -d input text | input file ]\r\n"
*--------------------------------------
LIBCRYPT .AZ "libcrypt.o"
hLIBCRYPT .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
ArgIndex .BS 1
Arg .BS 1
bText .BS 1
hFullPath .BS 1
hFile .BS 1
hDataBuf .BS 1
hMD5Ctx .BS 1
MD5Buf .BS 33
DS.END .ED
*--------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/MD5.S
ASM