A2osX/SYS/KERNEL.S.BIN.txt
2016-06-23 17:56:13 +02:00

150 lines
3.0 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.LoadBinA
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = MEMPTR
* X = hMem of Code Segment
*--------------------------------------
S.LoadBinA sta S.LoadBinA.hFilename save file path
jsr S.GetMemPtrA
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
tay
.1 lda (ZPQuickPtr1),y convert to UPPERCASE
cmp #'a'
bmi .2
cmp #'z'+1
bpl .2
eor #$20
sta (ZPQuickPtr1),y
.2 dey
bne .1
>LDYA ZPQuickPtr1
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 ZPQuickPtr1
jsr S.LoadFileYA
bcc .4
rts Error Loading file
.4 >STYA S.LoadBinA.FileLen
stx S.LoadBinA.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
lda S.LoadBinA.hFilename
jsr S.GetMemPtrA
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.LoadBinA.AuxType
clc
adc S.LoadBinA.FileLen
sta R.CL Make CX=Range End=AUXTYPE+FILELEN
iny
lda (ZPQuickPtr2),y
sta R.BH
sta S.LoadBinA.AuxType+1
adc S.LoadBinA.FileLen+1
sta R.CH
lda ZPQuickPtr1 Compute relocation offset in DX
sec
sbc S.LoadBinA.AuxType
sta R.DL DX=Offset=ZPQuickPtr1-AUXTYPE
lda ZPQuickPtr1+1
sbc S.LoadBinA.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
lda S.LoadBinA.hFilename get back bin path
jsr S.PStrCpyA
bcs .98
pha
lda S.LoadBinA.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.LoadBinA.hMem
tax return hMEM to Caller...
jsr S.GetMemPtrA
clc ...and Y,A=PTR to CS
rts
.98 pha
lda S.LoadBinA.hMem
jsr S.FreeMemA Discard Loaded Code
pla
sec
rts
*--------------------------------------
S.LoadBinA.hFilename .BS 1
S.LoadBinA.hMem .BS 1
S.LoadBinA.AuxType .BS 2
S.LoadBinA.FileLen .BS 2
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.BIN
LOAD SYS/KERNEL.S
ASM