A2osX/SYS/KERNEL.S.BIN.txt
2016-08-17 08:25:58 +02:00

134 lines
2.8 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.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* S.LoadBinYA
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
S.LoadBinYA >STYA S.LoadBin.Filename
jsr S.PStrUprYA
>LDYA S.LoadBin.Filename
jsr S.GetMemByNameYA
bcs .3 not already loaded
>STYA ZPQuickPtr1 Save base address
ldy #S.MEM.REFCNT
lda (ZPQuickPtr1),y
inc
sta (ZPQuickPtr1),y
ldy #S.MEM.PTR
lda (ZPQuickPtr1),y
pha Y,A = MEM PTR...
iny
lda (ZPQuickPtr1),y
ply X=hMem from S.GetMemByNameA
clc
rts
.3 >LDYA S.LoadBin.Filename
jsr S.LoadFileYA
bcc .4
rts Error Loading file
.4 >STYA S.LoadBin.FileLen
stx S.LoadBin.hMem save hMem
txa
jsr S.GetMemPtrA
>STYA ZPQuickPtr1 save base address for relocation
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
jsr S.MLIGetFileInfoYA Get File Info for AUXTYPE
bcs .98
>STYA ZPQuickPtr2
ldy #2 get AUXTYPE
lda (ZPQuickPtr2),y
sta R.BL Make BX=Range Start=AUXTYPE
sta S.LoadBin.AuxType
clc
adc S.LoadBin.FileLen
sta R.CL Make CX=Range End=AUXTYPE+FILELEN
iny
lda (ZPQuickPtr2),y
sta R.BH
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
jsr S.BinRelocateYA
bit RRAMWRAMBNK1
bit RRAMWRAMBNK1
bcs .98 relocation error, dicard Code segment
>LDYA S.LoadBin.Filename get back bin path
jsr S.NewPStrYA make a copy of this string
bcs .98
phx save copy
lda S.LoadBin.hMem
jsr S.GetMemByIDA
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
ora #S.MEM.F.CODE This is a code segment
sta (ZPQuickPtr1)
pla
ldy #S.MEM.BIN
sta (ZPQuickPtr1),y
lda S.LoadBin.hMem
tax return hMEM to Caller...
jsr S.GetMemPtrA
clc ...and Y,A=PTR to CS
rts
.98 pha
lda S.LoadBin.hMem
jsr S.FreeMemA Discard Loaded Code
pla
sec
rts
*--------------------------------------
S.LoadBin.Filename .BS 2
S.LoadBin.hMem .BS 1
S.LoadBin.AuxType .BS 2
S.LoadBin.FileLen .BS 2
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.BIN
LOAD SYS/KERNEL.S
ASM