mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-10 22:54:59 +00:00
282 lines
6.6 KiB
Plaintext
282 lines
6.6 KiB
Plaintext
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
|
||
|
||
lda S.LoadBinA.hFilename
|
||
jsr S.GetMemByNameA
|
||
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 lda S.LoadBinA.hFilename
|
||
jsr S.LoadFileA
|
||
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.MLIGetFileInfoA 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
|
||
jsr S.BinRelocateYA
|
||
|
||
bcs .98 relocation error, dicard Code segment
|
||
|
||
lda S.LoadBinA.hFilename get back bin path
|
||
jsr S.PStrCpyA
|
||
bcs .98
|
||
|
||
pha save copy of bin path
|
||
|
||
lda S.LoadBinA.hMem
|
||
jsr S.GetMemByIDA
|
||
>STYA ZPQuickPtr1
|
||
|
||
lda (ZPQuickPtr1)
|
||
ora #S.MEM.F.CODE This is a code segment
|
||
sta (ZPQuickPtr1)
|
||
|
||
ldy #S.MEM.BIN
|
||
pla get back copy of bin path
|
||
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
|
||
*--------------------------------------
|
||
* S.BinRelocateYA :
|
||
* YA = Ptr to Code
|
||
* R.AX = Code Length
|
||
* R.BX = Range Start 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
|
||
*--------------------------------------
|
||
S.BinRelocateYA >STYA ZPQuickPtr1
|
||
ldy #H.BIN.JMP relocate Main JMP
|
||
lda (ZPQuickPtr1),y
|
||
clc
|
||
adc R.DL
|
||
sta (ZPQuickPtr1),y
|
||
|
||
iny
|
||
lda (ZPQuickPtr1),y
|
||
adc R.DH
|
||
sta (ZPQuickPtr1),y
|
||
|
||
ldy #H.BIN.RELOC.TABLE skip Header, CS.SIZE & DS.SIZE... (16 bytes)
|
||
bra S.JmpRelocate
|
||
|
||
S.DrvRelocateYA >STYA ZPQuickPtr1
|
||
ldy #0
|
||
|
||
S.JmpRelocate lda (ZPQuickPtr1),y Start Relocate JMP table
|
||
tax
|
||
iny
|
||
ora (ZPQuickPtr1),y
|
||
beq S.CodeRelocate $0000 = end of table
|
||
|
||
dey
|
||
txa
|
||
clc
|
||
adc R.DL
|
||
sta (ZPQuickPtr1),y
|
||
|
||
iny
|
||
lda (ZPQuickPtr1),y
|
||
adc R.DH
|
||
sta (ZPQuickPtr1),y
|
||
|
||
iny
|
||
|
||
bra S.JmpRelocate
|
||
|
||
S.CodeRelocate lda ZPQuickPtr1
|
||
clc
|
||
adc R.AL Make ZPQuickPtr2=End of code
|
||
sta ZPQuickPtr2 =ZPQuickPtr1+AX (code len)
|
||
lda ZPQuickPtr1+1
|
||
adc R.AH
|
||
sta ZPQuickPtr2+1
|
||
|
||
iny
|
||
tya add current offset in Y to Ptr
|
||
clc
|
||
adc ZPQuickPtr1
|
||
sta ZPQuickPtr1
|
||
bcc .5
|
||
inc ZPQuickPtr1+1 ZPQuickPtr1=Current Code PTR
|
||
clc
|
||
|
||
.5 lda (ZPQuickPtr1) get OPCODE
|
||
tax
|
||
lda OPCODES,x get OPCODE definition
|
||
bpl .7 abs addressing?
|
||
|
||
and #3 save Opcode length...
|
||
pha
|
||
|
||
ldy #1
|
||
lda (ZPQuickPtr1),y Get LO
|
||
sec
|
||
sbc R.BL
|
||
iny
|
||
lda (ZPQuickPtr1),y Get HI
|
||
sbc R.BH
|
||
bcc .6 addr < AX, out of range
|
||
|
||
dey
|
||
lda (ZPQuickPtr1),y Get LO
|
||
sec
|
||
sbc R.CL
|
||
iny
|
||
lda (ZPQuickPtr1),y Get HI
|
||
sbc R.CH
|
||
bcs .6 addr > CX, out of range
|
||
|
||
dey
|
||
lda (ZPQuickPtr1),y Get LO
|
||
clc
|
||
adc R.DL add DX to abs address
|
||
sta (ZPQuickPtr1),y store relocated addr LO
|
||
iny
|
||
lda (ZPQuickPtr1),y Get HI
|
||
adc R.DH
|
||
sta (ZPQuickPtr1),y store relocated addr HI
|
||
|
||
.6 pla
|
||
|
||
.7 clc A = OPCODE length
|
||
adc ZPQuickPtr1
|
||
sta ZPQuickPtr1
|
||
bcc .8
|
||
inc ZPQuickPtr1+1
|
||
|
||
.8 lda ZPQuickPtr1 is Current PTR < Code Limit ?
|
||
sec
|
||
sbc ZPQuickPtr2
|
||
lda ZPQuickPtr1+1
|
||
sbc ZPQuickPtr2+1
|
||
bcc .5 yes, continue relocating
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* 65C02 OPCODES
|
||
* Bit 7 : 1 absolute addressing
|
||
* Bit 1-0 : opcode + @ length
|
||
*--------------------------------------
|
||
* x0.x1.x2.x3.x4.x5.x6.x7.x8.x9.xA.xB.xC.xD.xE.xF
|
||
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.83.01.01.83.83.83.03
|
||
.HS 83.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.83.83.83.03
|
||
.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.83.01.01.01.83.83.03
|
||
.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.83.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.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.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.02.01.01.83.83.83.03
|
||
.HS 02.02.02.01.02.02.02.02.01.83.01.01.01.83.83.03
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE SYS/KERNEL.S.BIN
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|