mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-22 16:31:07 +00:00
343 lines
7.2 KiB
Plaintext
343 lines
7.2 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* S.InsDrv
|
||
* pDrv = .DRV File Loaded Address
|
||
*--------------------------------------
|
||
S.InsDrv ldy #H.BIN.DRV.CODE.LEN
|
||
lda (pDrv),y
|
||
sta R.AL
|
||
iny
|
||
lda (pDrv),y
|
||
sta R.AH
|
||
|
||
ldy #H.BIN.DRV.CODE.O
|
||
lda (pDrv),y
|
||
clc
|
||
adc S.LoadBin.AuxType
|
||
sta R.BL
|
||
iny
|
||
lda (pDrv),y
|
||
adc S.LoadBin.AuxType+1
|
||
sta R.BH set BX=End Of Code
|
||
|
||
lda S.LoadBin.AuxType
|
||
clc
|
||
adc S.LoadBin.FileLen
|
||
sta R.CL
|
||
lda S.LoadBin.AuxType+1
|
||
adc S.LoadBin.FileLen+1
|
||
sta R.CH set CX=End Of Range
|
||
|
||
ldy #H.BIN.DRV.CODE.O
|
||
lda S.LoadBin.FileLen
|
||
sec
|
||
sbc (pDrv),y
|
||
sta S.InsDrv.DRVLen
|
||
iny
|
||
lda S.LoadBin.FileLen+1
|
||
sbc (pDrv),y
|
||
sta S.InsDrv.DRVLen+1 Compute DRV Len
|
||
|
||
lda DevMgr.Free
|
||
clc
|
||
adc S.InsDrv.DRVLen
|
||
sta S.InsDrv.DRVEnd
|
||
lda DevMgr.Free+1
|
||
adc S.InsDrv.DRVLen+1
|
||
sta S.InsDrv.DRVEnd+1
|
||
|
||
bcs .98 we crossed $FFFF, out of mem
|
||
|
||
lda S.InsDrv.DRVEnd
|
||
sec
|
||
sbc #DevMgr.HiMem
|
||
lda S.InsDrv.DRVEnd+1
|
||
sbc /DevMgr.HiMem
|
||
bcs .98 No More Room to load Driver....
|
||
|
||
lda DevMgr.LastDevID
|
||
inc
|
||
cmp #K.DEV.MAX
|
||
beq .99 No Device Handle Left
|
||
|
||
sta DevMgr.LastDevID
|
||
|
||
ldy #H.BIN.DEV.HEADER.O
|
||
lda (pDrv),y
|
||
clc
|
||
adc pDrv
|
||
sta ZPQuickPtr1
|
||
iny
|
||
lda (pDrv),y
|
||
adc pDrv+1
|
||
sta ZPQuickPtr1+1
|
||
|
||
ldy #S.DEV.JMP
|
||
|
||
lda DevMgr.Free
|
||
sec
|
||
sbc (ZPQuickPtr1),y
|
||
sta R.DL
|
||
lda DevMgr.Free+1
|
||
iny
|
||
sbc (ZPQuickPtr1),y
|
||
sta R.DH set DX=Offset
|
||
|
||
ldy #H.BIN.DRV.CODE.O
|
||
lda (pDrv),y
|
||
clc
|
||
adc pDrv
|
||
pha
|
||
iny
|
||
lda (pDrv),y
|
||
adc pDrv+1
|
||
ply
|
||
|
||
jsr S.DrvRelocateYA
|
||
|
||
jsr S.InsDrv.Move
|
||
|
||
>LDYA S.InsDrv.DrvEnd
|
||
>STYA DevMgr.Free
|
||
clc
|
||
rts
|
||
|
||
.98 lda #DEVMGR.ERROOM
|
||
sec
|
||
rts
|
||
|
||
.99 lda #DEVMGR.ERROOH
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
S.InsDrv.Move ldy #H.BIN.DEV.HEADER.O
|
||
lda (pDrv),y
|
||
clc
|
||
adc pDrv
|
||
sta ZPQuickPtr1
|
||
iny
|
||
lda (pDrv),y
|
||
adc pDrv+1
|
||
sta ZPQuickPtr1+1
|
||
|
||
ldy #S.DEV.JMP Relocate Main JMP
|
||
lda (ZPQuickPtr1),y
|
||
clc
|
||
adc R.DL
|
||
sta (ZPQuickPtr1),y
|
||
iny
|
||
lda (ZPQuickPtr1),y
|
||
adc R.DH
|
||
sta (ZPQuickPtr1),y
|
||
|
||
lda DevMgr.LastDevID
|
||
jsr S.GetDevByIDA
|
||
>STYA pDev
|
||
|
||
ldy #S.DEV.SIZE Make sure DevMgr.Table Ends with 0
|
||
lda #0
|
||
sta (pDev),y
|
||
dey
|
||
|
||
.1 lda (ZPQuickPtr1),y Copy DRV.Header
|
||
sta (pDev),y
|
||
dey
|
||
bpl .1
|
||
|
||
lda DevMgr.LastDevID Save Dev.ID in the driver for SELECT
|
||
ldy #S.DEV.ID
|
||
sta (pDev),y
|
||
|
||
ldy #H.BIN.DRV.CODE.O
|
||
lda (pDrv),y
|
||
clc
|
||
adc pDrv
|
||
sta ZPQuickPtr1
|
||
iny
|
||
lda (pDrv),y
|
||
adc pDrv+1
|
||
sta ZPQuickPtr1+1 Make ZPQuickPtr1=DRV.CODE
|
||
|
||
lda DevMgr.Free
|
||
sta ZPQuickPtr2
|
||
lda DevMgr.Free+1
|
||
sta ZPQuickPtr2+1 Make ZPQuickPtr2=Dest Ram Location
|
||
|
||
ldy S.InsDrv.DrvLen
|
||
ldx S.InsDrv.DrvLen+1
|
||
|
||
.2 lda (ZPQuickPtr1)
|
||
sta (ZPQuickPtr2)
|
||
|
||
inc ZPQuickPtr1
|
||
bne .3
|
||
inc ZPQuickPtr1+1
|
||
|
||
.3 inc ZPQuickPtr2
|
||
bne .4
|
||
inc ZPQuickPtr2+1
|
||
|
||
.4 tya
|
||
bne .5
|
||
txa
|
||
beq .8
|
||
dex
|
||
|
||
.5 dey
|
||
bra .2
|
||
.8 rts
|
||
*--------------------------------------
|
||
S.InsDrv.DrvLen .BS 2
|
||
S.InsDrv.DrvEnd .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.REL
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|