VCPU16 removed from Relocator & LIB/LIBCRYPT.S

This commit is contained in:
Rémy GIBERT 2016-08-19 16:52:18 +02:00
parent 07813cc5d6
commit 9222922ed3
6 changed files with 164 additions and 145 deletions

Binary file not shown.

Binary file not shown.

View File

@ -16,6 +16,9 @@ ZPTmpPtr1 .EQ ZPLIB
ZPTmpPtr2 .EQ ZPLIB+2 ZPTmpPtr2 .EQ ZPLIB+2
ZPTmpPtr3 .EQ ZPLIB+4 ZPTmpPtr3 .EQ ZPLIB+4
ZPTmpPtr4 .EQ ZPLIB+6 ZPTmpPtr4 .EQ ZPLIB+6
ZPDataPtr .EQ ZPLIB+8
ZPDataLen .EQ ZPLIB+10
ZPChunkLen .EQ ZPLIB+12
*-------------------------------------- *--------------------------------------
* DWORD Macros : Do NOT disturb carry with cpx, cpy... * DWORD Macros : Do NOT disturb carry with cpx, cpy...
*-------------------------------------- *--------------------------------------
@ -181,29 +184,30 @@ MD5Init >PUSHWI S.MD5.SIZE
MD5Update >PULLA get MD5 Context MD5Update >PULLA get MD5 Context
>SYSCALL SYS.GetMemPtrA >SYSCALL SYS.GetMemPtrA
>STYA ZPTmpPtr1 get MD5 Context >STYA ZPTmpPtr1 get MD5 Context
>PULLW R.AX get DATA >PULLW ZPDataPtr get DATA
>PULLW R.BX get LEN >PULLW ZPDataLen get LEN
ldy #S.MD5.FINALIZED ldy #S.MD5.FINALIZED
lda (ZPTmpPtr1),y lda (ZPTmpPtr1),y
beq .1 beq .1
sec sec
rts rts
.1 lda R.BH More than 256 Bytes remaining to hash ? .1 lda ZPDataLen+1 More than 256 Bytes remaining to hash ?
bne .3 yes bne .3 yes
lda R.BL lda ZPDataLen
bne .2 Len = O ? bne .2 Len = O ?
clc All data processed clc All data processed
rts rts
.2 cmp #64 More than 64 Bytes remaining to hash ? .2 cmp #64 More than 64 Bytes remaining to hash ?
bcc .50 yes bcc .50 yes
.3 lda #64 .3 lda #64
.50 sta R.CL Save Chunk Len .50 sta ZPChunkLen Save Chunk Len
jsr MD5UpdateBitCount jsr MD5UpdateBitCount
ldy #0 ldy #0
.51 lda (R.AX),y Load Buffer with data .51 lda (ZPDataPtr),y Load Buffer with data
sta MD5.BUFFER64,y sta MD5.BUFFER64,y
iny iny
cpy R.CL cpy ZPChunkLen
bne .51 bne .51
cpy #64 Full 64 Bytes DATA ? cpy #64 Full 64 Bytes DATA ?
beq .58 beq .58
@ -218,25 +222,25 @@ MD5Update >PULLA get MD5 Context
.53 ldy #S.MD5.EXTRABIT Mark MD5 Context as Appended .53 ldy #S.MD5.EXTRABIT Mark MD5 Context as Appended
lda #$80 lda #$80
sta (ZPTmpPtr1),y sta (ZPTmpPtr1),y
lda R.CL lda ZPChunkLen
cmp #56 Enough room for BITCOUNT ? cmp #56 Enough room for BITCOUNT ?
bcs .58 no bcs .58 no
jsr MD5AppendBitCount jsr MD5AppendBitCount
.58 jsr MD5Transform .58 jsr MD5Transform
jsr MD5UpdateABCD0 jsr MD5UpdateABCD0
.8 lda R.BL Substract Bytes processed from LEN .8 lda ZPDataLen Substract Bytes processed from LEN
sec sec
sbc R.CL get back chunk Len sbc ZPChunkLen get back chunk Len
sta R.BL sta ZPDataLen
bcs .81 bcs .81
dec R.BH dec ZPDataLen+1
.81 lda R.AL Add Bytes processed to DATA .81 lda ZPDataPtr Add Bytes processed to DATA
clc clc
adc R.CL adc ZPChunkLen
sta R.AL sta ZPDataPtr
bcc .82 bcc .82
inc R.AH inc ZPDataPtr+1
.82 jmp .1 .82 bra .1
*-------------------------------------- *--------------------------------------
* MD5FinalizeA * MD5FinalizeA
* In : * In :
@ -314,20 +318,20 @@ MD5AppendBitCount
* ZPTmpPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
*-------------------------------------- *--------------------------------------
MD5UpdateBitCount MD5UpdateBitCount
stz R.CH stz ZPChunkLen+1
lda R.CL lda ZPChunkLen
asl asl
rol R.CH rol ZPChunkLen+1
asl times 8 to get bit count asl times 8 to get bit count
rol R.CH rol ZPChunkLen+1
asl asl
rol R.CH rol ZPChunkLen+1
clc clc
ldy #S.MD5.BITCOUNT ldy #S.MD5.BITCOUNT
adc (ZPTmpPtr1),y adc (ZPTmpPtr1),y
sta (ZPTmpPtr1),y sta (ZPTmpPtr1),y
iny iny
lda R.CH lda ZPChunkLen+1
adc (ZPTmpPtr1),y adc (ZPTmpPtr1),y
sta (ZPTmpPtr1),y sta (ZPTmpPtr1),y
bcc .8 bcc .8

View File

@ -36,55 +36,31 @@ S.LoadBinYA >STYA S.LoadBin.Filename
.3 >LDYA S.LoadBin.Filename .3 >LDYA S.LoadBin.Filename
jsr S.LoadFileYA jsr S.LoadFileYA
bcc .4 bcs .99 Error Loading file
rts Error Loading file
.4 >STYA S.LoadBin.FileLen >STYA S.LoadBin.SegLen
stx S.LoadBin.hMem save hMem stx S.LoadBin.hMem save hMem
txa txa
jsr S.GetMemPtrA jsr S.GetMemPtrA
>STYA ZPQuickPtr1 save base address for relocation >STYA S.LoadBin.NewBase
ldy #H.BIN.CODE.LEN make AX = Code Len
lda (ZPQuickPtr1),y
sta R.AL
iny
lda (ZPQuickPtr1),y
sta R.AH
>LDYA S.LoadBin.Filename >LDYA S.LoadBin.Filename
jsr S.MLIGetFileInfoYA Get File Info for AUXTYPE jsr S.MLIGetFileInfoYA Get File Info for AUXTYPE
bcs .98 bcs .98
>STYA ZPQuickPtr2 >STYA ZPQuickPtr1
ldy #2 get AUXTYPE ldy #2 get AUXTYPE
lda (ZPQuickPtr2),y lda (ZPQuickPtr1),y
sta R.BL Make BX=Range Start=AUXTYPE sta S.LoadBin.OldBase
sta S.LoadBin.AuxType
clc
adc S.LoadBin.FileLen
sta R.CL Make CX=Range End=AUXTYPE+FILELEN
iny iny
lda (ZPQuickPtr2),y lda (ZPQuickPtr1),y
sta R.BH sta S.LoadBin.OldBase+1
sta S.LoadBin.AuxType+1
adc S.LoadBin.FileLen+1
sta R.CH
lda ZPQuickPtr1 Compute relocation offset in DX
sec
sbc S.LoadBin.AuxType
sta R.DL DX=Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
sbc S.LoadBin.AuxType+1
sta R.DH
>LDYA ZPQuickPtr1
bit RRAMWRAMBNK2 bit RRAMWRAMBNK2
bit RRAMWRAMBNK2 bit RRAMWRAMBNK2
jsr S.BinRelocateYA jsr S.InsBin
bit RRAMWRAMBNK1 bit RRAMWRAMBNK1
bit RRAMWRAMBNK1 bit RRAMWRAMBNK1
@ -120,12 +96,13 @@ S.LoadBinYA >STYA S.LoadBin.Filename
pla pla
sec sec
rts .99 rts
*-------------------------------------- *--------------------------------------
S.LoadBin.Filename .BS 2 S.LoadBin.Filename .BS 2
S.LoadBin.hMem .BS 1 S.LoadBin.hMem .BS 1
S.LoadBin.AuxType .BS 2 S.LoadBin.OldBase .BS 2
S.LoadBin.FileLen .BS 2 S.LoadBin.NewBase .BS 2
S.LoadBin.SegLen .BS 2
*-------------------------------------- *--------------------------------------
MAN MAN
SAVE SYS/KERNEL.S.BIN SAVE SYS/KERNEL.S.BIN

View File

@ -239,7 +239,7 @@ S.ListDirInitYA >STYA R.BX Store path
>PUSHBI S.MEM.F.INIT0 reset all bytes >PUSHBI S.MEM.F.INIT0 reset all bytes
jsr S.GetMem jsr S.GetMem
bcs .99 bcs .99
stx R.AH stx S.ListDirInitYA.hDir
>STYA R.CX Store LISTDIR Struct >STYA R.CX Store LISTDIR Struct
>LDYA R.BX >LDYA R.BX
@ -275,21 +275,23 @@ S.ListDirInitYA >STYA R.BX Store path
bne .6 bne .6
jsr S.ListDirInitAV jsr S.ListDirInitAV
bcs .98 bcs .98
lda R.AH lda S.ListDirInitYA.hDir
rts rts
.6 jsr S.ListDirInitAD .6 jsr S.ListDirInitAD
bcs .98 bcs .98
lda R.AH lda S.ListDirInitYA.hDir
rts rts
.98 pha .98 pha
lda R.AH Discard S.LISTDIR lda S.ListDirInitYA.hDir Discard S.LISTDIR
jsr S.ListDirCloseA jsr S.ListDirCloseA
pla pla
.99 sec .99 sec
rts rts
*-------------------------------------- *--------------------------------------
S.ListDirInitYA.hDir .BS 1
*--------------------------------------
S.ListDirInitAV >PUSHWI 256 S.ListDirInitAV >PUSHWI 256
>PUSHBI 0 >PUSHBI 0
jsr S.GetMem jsr S.GetMem
@ -430,7 +432,7 @@ S.ListDirNextAV jsr S.GetMemPtrA
.9 sec .9 sec
rts rts
*-------------------------------------- *--------------------------------------
S.ListDirNextAD stz R.DL Reset Return Record hMem S.ListDirNextAD stz S.ListDirNext.hRec Reset Return Record hMem
ldy #S.LISTDIR.FI File Index = File count ? ldy #S.LISTDIR.FI File Index = File count ?
lda (R.CX),y lda (R.CX),y
ldy #S.LISTDIR.FC ldy #S.LISTDIR.FC
@ -505,7 +507,7 @@ S.ListDirNextAD stz R.DL Reset Return Record hMem
jsr S.GetMem jsr S.GetMem
bcs .99 bcs .99
>STYA R.BX R.BX = DEST RECORD >STYA R.BX R.BX = DEST RECORD
stx R.DL stx S.ListDirNext.hRec
ldy #S.LISTDIR.EL ldy #S.LISTDIR.EL
lda (R.CX),y lda (R.CX),y
@ -547,7 +549,7 @@ S.ListDirNextAD stz R.DL Reset Return Record hMem
inc inc
sta (R.CX),y sta (R.CX),y
.6 lda R.DL .6 lda S.ListDirNext.hRec
bne .8 bne .8
jmp S.ListDirNextAD Nothing to return, start over for next file entry jmp S.ListDirNextAD Nothing to return, start over for next file entry
@ -557,6 +559,37 @@ S.ListDirNextAD stz R.DL Reset Return Record hMem
.99 sec .99 sec
rts rts
*-------------------------------------- *--------------------------------------
* S.ListDirReadBlock
* In :
* CX = LISTDIR
* Out :
* Y,A = READ BUFFER
*--------------------------------------
S.ListDirReadBlock
ldy #S.LISTDIR.REFNUM
lda (R.CX),y get ref_num
sta MLICALL.PARAMS+1
ldy #S.LISTDIR.hREADBUF
lda (R.CX),y get READ BUFFER
jsr S.GetMemPtrA
>STYA MLICALL.PARAMS+2
>LDYAI 512
>STYA MLICALL.PARAMS+4
>MLICALL MLIREAD
bcs .9
ldy #S.LISTDIR.BLKPTR set BLKPTR to $0004
lda #4
sta (R.CX),y
iny
lda #0
sta (R.CX),y
ldy #S.LISTDIR.EIB set EIB to 0
sta (R.CX),y
>LDYA MLICALL.PARAMS+2
.9 rts
*--------------------------------------
S.ListDirNext.hRec .BS 1
*--------------------------------------
* S.DirListCloseA * S.DirListCloseA
* in : * in :
* A = hS.LISTDIR * A = hS.LISTDIR
@ -600,37 +633,6 @@ S.ListDirCloseA pha
clc clc
rts rts
*-------------------------------------- *--------------------------------------
* PRIVATE
*--------------------------------------
* S.ListDirReadBlock
* In :
* CX = LISTDIR
* Out :
* Y,A = READ BUFFER
*--------------------------------------
S.ListDirReadBlock
ldy #S.LISTDIR.REFNUM
lda (R.CX),y get ref_num
sta MLICALL.PARAMS+1
ldy #S.LISTDIR.hREADBUF
lda (R.CX),y get READ BUFFER
jsr S.GetMemPtrA
>STYA MLICALL.PARAMS+2
>LDYAI 512
>STYA MLICALL.PARAMS+4
>MLICALL MLIREAD
bcs .9
ldy #S.LISTDIR.BLKPTR set BLKPTR to $0004
lda #4
sta (R.CX),y
iny
lda #0
sta (R.CX),y
ldy #S.LISTDIR.EIB set EIB to 0
sta (R.CX),y
>LDYA MLICALL.PARAMS+2
.9 rts
*--------------------------------------
TmpFileName .BS 16 TmpFileName .BS 16
*-------------------------------------- *--------------------------------------
MAN MAN

View File

@ -5,41 +5,74 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*-------------------------------------- *--------------------------------------
* S.InsBin
*--------------------------------------
S.InsBin >LDYA S.LoadBin.NewBase
>STYA ZPQuickPtr1
ldy #H.BIN.CODE.LEN make AX = Code Len
lda (ZPQuickPtr1),y
sta Rel.CodeLen
iny
lda (ZPQuickPtr1),y
sta Rel.CodeLen+1
lda S.LoadBin.OldBase
sta Rel.Start Make BX=Range Start=AUXTYPE
clc
adc S.LoadBin.SegLen
sta Rel.End Make CX=Range End=AUXTYPE+FILELEN
lda S.LoadBin.OldBase+1
sta Rel.Start+1
adc S.LoadBin.SegLen+1
sta Rel.End+1
lda ZPQuickPtr1 Compute relocation offset in DX
sec
sbc S.LoadBin.OldBase
sta Rel.Offset DX=Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
sbc S.LoadBin.OldBase+1
sta Rel.Offset+1
jmp S.BinRelocate
*--------------------------------------
* S.InsDrv * S.InsDrv
* pDrv = .DRV File Loaded Address * pDrv = .DRV File Loaded Address
*-------------------------------------- *--------------------------------------
S.InsDrv ldy #H.BIN.DRV.CODE.LEN S.InsDrv ldy #H.BIN.DRV.CODE.LEN
lda (pDrv),y lda (pDrv),y
sta R.AL sta Rel.CodeLen
iny iny
lda (pDrv),y lda (pDrv),y
sta R.AH sta Rel.CodeLen+1
ldy #H.BIN.DRV.CODE.O ldy #H.BIN.DRV.CODE.O
lda (pDrv),y lda (pDrv),y
clc clc
adc S.LoadBin.AuxType adc S.LoadBin.OldBase
sta R.BL sta Rel.Start
iny iny
lda (pDrv),y lda (pDrv),y
adc S.LoadBin.AuxType+1 adc S.LoadBin.OldBase+1
sta R.BH set BX=End Of Code sta Rel.Start+1 set BX=End Of Code
lda S.LoadBin.AuxType lda S.LoadBin.OldBase
clc clc
adc S.LoadBin.FileLen adc S.LoadBin.SegLen
sta R.CL sta Rel.End
lda S.LoadBin.AuxType+1 lda S.LoadBin.OldBase+1
adc S.LoadBin.FileLen+1 adc S.LoadBin.SegLen+1
sta R.CH set CX=End Of Range sta Rel.End+1 set CX=End Of Range
ldy #H.BIN.DRV.CODE.O ldy #H.BIN.DRV.CODE.O
lda S.LoadBin.FileLen lda S.LoadBin.SegLen
sec sec
sbc (pDrv),y sbc (pDrv),y
sta S.InsDrv.DRVLen sta S.InsDrv.DRVLen
iny iny
lda S.LoadBin.FileLen+1 lda S.LoadBin.SegLen+1
sbc (pDrv),y sbc (pDrv),y
sta S.InsDrv.DRVLen+1 Compute DRV Len sta S.InsDrv.DRVLen+1 Compute DRV Len
@ -82,23 +115,24 @@ S.InsDrv ldy #H.BIN.DRV.CODE.LEN
lda DevMgr.Free lda DevMgr.Free
sec sec
sbc (ZPQuickPtr1),y sbc (ZPQuickPtr1),y
sta R.DL sta Rel.Offset
lda DevMgr.Free+1 lda DevMgr.Free+1
iny iny
sbc (ZPQuickPtr1),y sbc (ZPQuickPtr1),y
sta R.DH set DX=Offset sta Rel.Offset+1 set DX=Offset
ldy #H.BIN.DRV.CODE.O ldy #H.BIN.DRV.CODE.O
lda (pDrv),y lda (pDrv),y
clc clc
adc pDrv adc pDrv
pha sta ZPQuickPtr1
iny iny
lda (pDrv),y lda (pDrv),y
adc pDrv+1 adc pDrv+1
ply sta ZPQuickPtr1+1
jsr S.DrvRelocateYA jsr S.DrvRelocate
jsr S.InsDrv.Move jsr S.InsDrv.Move
@ -128,11 +162,11 @@ S.InsDrv.Move ldy #H.BIN.DEV.HEADER.O
ldy #S.DEV.JMP Relocate Main JMP ldy #S.DEV.JMP Relocate Main JMP
lda (ZPQuickPtr1),y lda (ZPQuickPtr1),y
clc clc
adc R.DL adc Rel.Offset
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
iny iny
lda (ZPQuickPtr1),y lda (ZPQuickPtr1),y
adc R.DH adc Rel.Offset+1
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
lda DevMgr.LastDevID lda DevMgr.LastDevID
@ -195,60 +229,57 @@ S.InsDrv.Move ldy #H.BIN.DEV.HEADER.O
S.InsDrv.DrvLen .BS 2 S.InsDrv.DrvLen .BS 2
S.InsDrv.DrvEnd .BS 2 S.InsDrv.DrvEnd .BS 2
*-------------------------------------- *--------------------------------------
* S.BinRelocateYA : * S.BinRelocate :
* YA = Ptr to Code * ZPQuickPtr1 = Ptr to Code
* R.AX = Code Length * R.AX = Code Length
* R.BX = Range Start address to relocate * R.BX = Range Start address to relocate
* R.CX = Range End address to relocate * R.CX = Range End address to relocate
* R.DX = offset to apply to all abs addresses between R.BX and R.CX * R.DX = offset to apply to all abs addresses between R.BX and R.CX
*-------------------------------------- *--------------------------------------
S.BinRelocateYA >STYA ZPQuickPtr1 S.BinRelocate ldy #H.BIN.JMP relocate Main JMP
ldy #H.BIN.JMP relocate Main JMP
lda (ZPQuickPtr1),y lda (ZPQuickPtr1),y
clc clc
adc R.DL adc Rel.Offset
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
iny iny
lda (ZPQuickPtr1),y lda (ZPQuickPtr1),y
adc R.DH adc Rel.Offset+1
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes) ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
bra S.JmpRelocate
S.DrvRelocateYA >STYA ZPQuickPtr1 .HS 2C bit abs
ldy #0
S.JmpRelocate lda (ZPQuickPtr1),y Start Relocate JMP table S.DrvRelocate ldy #0
.1 lda (ZPQuickPtr1),y Start Relocate JMP table
tax tax
iny iny
ora (ZPQuickPtr1),y ora (ZPQuickPtr1),y
beq S.CodeRelocate $0000 = end of table beq .2 $0000 = end of table
dey dey
txa txa
clc clc
adc R.DL adc Rel.Offset
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
iny iny
lda (ZPQuickPtr1),y lda (ZPQuickPtr1),y
adc R.DH adc Rel.Offset+1
sta (ZPQuickPtr1),y sta (ZPQuickPtr1),y
iny iny
bra S.JmpRelocate bra .1
S.CodeRelocate lda ZPQuickPtr1 .2 lda ZPQuickPtr1
clc clc
adc R.AL Make ZPQuickPtr2=End of code adc Rel.CodeLen Make ZPQuickPtr2=End of code
sta ZPQuickPtr2 =ZPQuickPtr1+AX (code len) sta ZPQuickPtr2 =ZPQuickPtr1+AX (code len)
lda ZPQuickPtr1+1 lda ZPQuickPtr1+1
adc R.AH adc Rel.CodeLen+1
sta ZPQuickPtr2+1 sta ZPQuickPtr2+1
iny iny
@ -271,29 +302,29 @@ S.CodeRelocate lda ZPQuickPtr1
ldy #1 ldy #1
lda (ZPQuickPtr1),y Get LO lda (ZPQuickPtr1),y Get LO
sec sec
sbc R.BL sbc Rel.Start
iny iny
lda (ZPQuickPtr1),y Get HI lda (ZPQuickPtr1),y Get HI
sbc R.BH sbc Rel.Start+1
bcc .6 addr < AX, out of range bcc .6 addr < AX, out of range
dey dey
lda (ZPQuickPtr1),y Get LO lda (ZPQuickPtr1),y Get LO
sec sec
sbc R.CL sbc Rel.End
iny iny
lda (ZPQuickPtr1),y Get HI lda (ZPQuickPtr1),y Get HI
sbc R.CH sbc Rel.End+1
bcs .6 addr > CX, out of range bcs .6 addr > CX, out of range
dey dey
lda (ZPQuickPtr1),y Get LO lda (ZPQuickPtr1),y Get LO
clc clc
adc R.DL add DX to abs address adc Rel.Offset add DX to abs address
sta (ZPQuickPtr1),y store relocated addr LO sta (ZPQuickPtr1),y store relocated addr LO
iny iny
lda (ZPQuickPtr1),y Get HI lda (ZPQuickPtr1),y Get HI
adc R.DH adc Rel.Offset+1
sta (ZPQuickPtr1),y store relocated addr HI sta (ZPQuickPtr1),y store relocated addr HI
.6 pla .6 pla
@ -336,6 +367,11 @@ OPCODES .HS 01.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03 .HS 02.02.02.01.02.02.02.02.01.02.01.01.83.83.83.03
.HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03 .HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03
*-------------------------------------- *--------------------------------------
Rel.CodeLen .BS 2
Rel.Start .BS 2
Rel.End .BS 2
Rel.Offset .BS 2
*--------------------------------------
MAN MAN
SAVE SYS/KERNEL.S.REL SAVE SYS/KERNEL.S.REL
LOAD SYS/KERNEL.S LOAD SYS/KERNEL.S