A2osX/BIN/MD4.S.txt
2023-06-02 22:31:09 +02:00

213 lines
3.7 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
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/md4
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/mli.e.i
.INB inc/libcrypt.i
*--------------------------------------
FILEBUF.SIZE .EQ 4096
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
ZPDataBufPtr .BS 2
ZPDataLen .BS 2
ArgIndex .BS 1
Arg .BS 1
bText .BS 1
hFile .BS 1
hDataBuf .BS 1
hMD4Ctx .BS 1
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
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #ZS.END-ZS.START 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 >LDYA L.LIBCRYPT
>SYSCALL LoadLib
bcs .9
sta hLIBCRYPT
* clc
.9 rts
*--------------------------------------
CS.RUN ldy #S.PS.ARGC
lda (pPS),y
beq .99
.1 inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs .8
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
beq .99
ldy #OptionVars-OptionList-1
.2 cmp OptionList,y
beq .3
dey
bpl .2
.99 >PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
lda #E.SYN
sec
rts
.3 ldx OptionVars,y
sec
ror 0,x
bra .1
.4 lda Arg
bne .99
lda ArgIndex
sta Arg
bra .1
.8 lda Arg
beq .99
lda bText
beq CS.RUN.FILE
*--------------------------------------
CS.RUN.TEXT lda Arg
>SYSCALL ArgV
>PUSHYA
>PUSHEA.G MD4Buf
>LIBCALL hLIBCRYPT,LIBCRYPT.MD4
jmp CS.RUN.PRINT
*--------------------------------------
CS.RUN.FILE >LDYAI FILEBUF.SIZE
>SYSCALL GetMem
bcs .9
>STYA ZPDataBufPtr
stx hDataBuf
lda Arg
>SYSCALL ArgV
>PUSHYA
>PUSHBI O.RDONLY
>PUSHBI 0 ftype
>PUSHWZ Aux type
>SYSCALL FOpen
bcs .9
sta hFile
>LIBCALL hLIBCRYPT,LIBCRYPT.MD4Init
bcs .9
sta hMD4Ctx
.1 >SLEEP
>PUSHB hFile
>PUSHW ZPDataBufPtr Dst Ptr
>PUSHWI FILEBUF.SIZE Bytes To Read
>SYSCALL FRead
bcc .2
cmp #MLI.E.EOF
beq .8
.9 rts
.2 >STYA ZPDataLen
>SLEEP
>PUSHB hMD4Ctx
>PUSHW ZPDataBufPtr
>PUSHW ZPDataLen
>LIBCALL hLIBCRYPT,LIBCRYPT.MD4Update
bra .1
.8 >PUSHB hMD4Ctx
>PUSHEA.G MD4Buf
>LIBCALL hLIBCRYPT,LIBCRYPT.MD4Finalize
CS.RUN.PRINT >LEA.G MD4Buf
>SYSCALL PutS
lda #0
* sec
* rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT lda hLIBCRYPT
beq .1
>SYSCALL UnloadLib
.1 lda hDataBuf
beq .2
>SYSCALL FreeMem
.2 lda hFile
beq .3
>SYSCALL FClose
.3 clc
rts
*--------------------------------------
CS.END
LIBCRYPT .AZ "libcrypt"
hLIBCRYPT .BS 1
*--------------------------------------
OptionList .AS "Dd"
OptionVars .DA #bText,#bText
*--------------------------------------
MSG.USAGE .CZ "Usage : MD4 [ -d input text | input file ]\r\n"
*--------------------------------------
.DUMMY
.OR 0
DS.START
MD4Buf .BS 33
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/md4.s
ASM