2015-03-14 21:48:35 +00:00
|
|
|
|
PR#3
|
2017-03-29 15:48:15 +00:00
|
|
|
|
PREFIX /A2OSX.BUILD
|
2017-03-15 16:44:15 +00:00
|
|
|
|
LOMEM $A00
|
2015-03-14 21:48:35 +00:00
|
|
|
|
INC 1
|
|
|
|
|
AUTO 6
|
|
|
|
|
*--------------------------------------
|
2017-01-12 17:43:45 +00:00
|
|
|
|
* !!!!!! DO NOT USE ZPPtrs !!!!!
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
2016-08-17 06:25:58 +00:00
|
|
|
|
ZPMemMgrSPtr .EQ ZPMEMMGR Pointer To Slot selected
|
|
|
|
|
ZPMemMgrTmp1 .EQ ZPMEMMGR+2
|
2017-08-31 15:35:15 +00:00
|
|
|
|
MemMgr.ReqSize .EQ ZPMEMMGR+4 store requested Size
|
|
|
|
|
MemMgr.ReqFlags .EQ ZPMEMMGR+6 store requested Flags
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* TODO :
|
2015-06-03 18:30:57 +00:00
|
|
|
|
* - Create a 256 bytes table
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* mapping hMem's to real memory blocks to help
|
|
|
|
|
* Garbage collector move blocks
|
2015-06-03 18:30:57 +00:00
|
|
|
|
* - mem.ID=0 always used! useful to test if hMem=0
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* PUBLIC
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* # GetMem
|
|
|
|
|
* ## In:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* PUSHW = Size Requested
|
|
|
|
|
* PUSHB = Options
|
|
|
|
|
* S.MEM.F.INIT0 : init memory with 00
|
|
|
|
|
* S.MEM.F.ALIGN : page aligned
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## Out:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* CC : success
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* YA = PTR to Mem
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* X = hMem
|
|
|
|
|
* CS :
|
|
|
|
|
* A = EC
|
|
|
|
|
*\--------------------------------------
|
2016-09-21 15:20:37 +00:00
|
|
|
|
K.GetMem >PULLB MemMgr.ReqFlags store requested flags
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-09-05 15:17:10 +00:00
|
|
|
|
clc
|
|
|
|
|
>PULLA get requested size LO
|
2016-10-07 15:28:17 +00:00
|
|
|
|
bit #$0F 16 bytes aligned ?
|
2017-09-05 15:17:10 +00:00
|
|
|
|
beq .1 yes, request it
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
and #$F0 align on 16 bytes
|
2015-03-14 21:48:35 +00:00
|
|
|
|
adc #$10
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-09-05 15:17:10 +00:00
|
|
|
|
.1 sta MemMgr.ReqSize
|
|
|
|
|
|
|
|
|
|
>PULLA get requested size HI
|
|
|
|
|
adc #0
|
|
|
|
|
sta MemMgr.ReqSize+1
|
2017-06-28 14:34:11 +00:00
|
|
|
|
|
|
|
|
|
bit MemMgr.ReqFlags S.MEM.F.AUX ?
|
2017-09-05 15:17:10 +00:00
|
|
|
|
bpl K.GetMem.I
|
|
|
|
|
|
|
|
|
|
and #S.MEM.F.AUX
|
|
|
|
|
beq .1
|
|
|
|
|
|
|
|
|
|
sta SETREADAUX Aux Mem requested,switch to AUX
|
|
|
|
|
sta SETWRITEAUX
|
|
|
|
|
|
|
|
|
|
jsr K.GetMem.I
|
2017-06-28 14:34:11 +00:00
|
|
|
|
|
|
|
|
|
sta CLRREADAUX
|
|
|
|
|
sta CLRWRITEAUX
|
|
|
|
|
|
|
|
|
|
.9 rts
|
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # GetMem0.YA
|
2017-06-28 14:34:11 +00:00
|
|
|
|
* ## In:
|
|
|
|
|
* Y,A = Size Requested
|
|
|
|
|
* ## Out:
|
|
|
|
|
* CC : success
|
2017-07-06 15:30:40 +00:00
|
|
|
|
* YA = PTR to Mem (ZERO Initialised)
|
2017-06-28 14:34:11 +00:00
|
|
|
|
* X = hMem
|
|
|
|
|
* CS :
|
|
|
|
|
* A = EC
|
|
|
|
|
*\--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.GetMem0.YA ldx #S.MEM.F.INIT0
|
2017-07-01 13:44:40 +00:00
|
|
|
|
stx MemMgr.ReqFlags
|
2017-07-06 15:30:40 +00:00
|
|
|
|
.HS 2C bit abs
|
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # GetMem.YA
|
2017-07-06 15:30:40 +00:00
|
|
|
|
* ## In:
|
|
|
|
|
* Y,A = Size Requested
|
|
|
|
|
* ## Out:
|
|
|
|
|
* CC : success
|
|
|
|
|
* YA = PTR to Mem (Uninitialised)
|
|
|
|
|
* X = hMem
|
|
|
|
|
* CS :
|
|
|
|
|
* A = EC
|
|
|
|
|
*\--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.GetMem.YA stz MemMgr.ReqFlags
|
2017-06-28 14:34:11 +00:00
|
|
|
|
sta MemMgr.ReqSize+1
|
|
|
|
|
tya
|
|
|
|
|
bit #$0F 16 bytes aligned ?
|
|
|
|
|
beq .1 yes, request it
|
|
|
|
|
|
|
|
|
|
and #$F0 align on 16 bytes
|
|
|
|
|
clc
|
|
|
|
|
adc #$10
|
|
|
|
|
bcc .1
|
|
|
|
|
inc MemMgr.ReqSize+1
|
|
|
|
|
|
|
|
|
|
.1 sta MemMgr.ReqSize
|
|
|
|
|
|
|
|
|
|
K.GetMem.I >LDYAI MemMgr.Table
|
2015-06-03 18:30:57 +00:00
|
|
|
|
>STYA ZPMemMgrSPtr
|
|
|
|
|
|
|
|
|
|
ldx #0 Current slot=0
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
bra .4 skip slot 0, Check if some free slot to reuse first
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
.1 inx move to next slot
|
|
|
|
|
jsr MemMgr.NextSlot
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr) Get Flags
|
|
|
|
|
bmi .4 in use ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
.2 lda MemMgr.ReqFlags Found an empty slot
|
2015-03-14 21:48:35 +00:00
|
|
|
|
and #S.MEM.F.ALIGN is request needs a page align ?
|
|
|
|
|
beq .3
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
|
|
|
|
lda (ZPMemMgrSPtr),y get LO of PTR
|
|
|
|
|
bne .4 not page-aligned
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
.3 ldy #S.MEM.LEN
|
|
|
|
|
lda (ZPMemMgrSPtr),y get LEN of this block
|
2015-06-03 18:30:57 +00:00
|
|
|
|
cmp MemMgr.ReqSize compare with requested size
|
2015-03-14 21:48:35 +00:00
|
|
|
|
bne .4
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
cmp MemMgr.ReqSize+1
|
|
|
|
|
beq .7 requested size matches slot size !!!
|
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
.4 cpx MemMgr.LastSlot any other slot to check?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .1 last one, create a new slot
|
2016-10-07 15:28:17 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
*-------------- Create a New SLOT
|
2016-10-07 15:28:17 +00:00
|
|
|
|
lda MemMgr.ReqFlags
|
2015-06-03 18:30:57 +00:00
|
|
|
|
and #S.MEM.F.ALIGN is request needs a page align ?
|
|
|
|
|
beq .6
|
|
|
|
|
|
|
|
|
|
lda MemMgr.Free target PTR will be page aligned ?
|
|
|
|
|
sec
|
|
|
|
|
sbc MemMgr.ReqSize
|
|
|
|
|
beq .6 yes, allocate
|
|
|
|
|
|
|
|
|
|
tay no, reserve a free slot to fill gap
|
|
|
|
|
lda #0
|
|
|
|
|
jsr MemMgr.AddSlot X = new slot
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
.6 >LDYA MemMgr.ReqSize
|
|
|
|
|
jsr MemMgr.AddSlot X = new slot
|
|
|
|
|
bcs .9
|
2016-10-07 15:28:17 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*-------------- Reuse this SLOT
|
2015-06-03 18:30:57 +00:00
|
|
|
|
.7 lda MemMgr.ReqFlags get requested flags
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ora #S.MEM.F.INUSE mark as in use
|
|
|
|
|
sta (ZPMemMgrSPtr)
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
and #S.MEM.F.INIT0
|
|
|
|
|
beq .8
|
2016-11-01 21:34:29 +00:00
|
|
|
|
|
2017-04-28 15:04:16 +00:00
|
|
|
|
jsr MemMgr.Init0 X not modified
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
.8 lda #0
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.BIN
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
inc Mark this slot used by one process
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.REFCNT
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2016-10-29 19:58:21 +00:00
|
|
|
|
ldy #S.PS.PID
|
2015-06-03 18:30:57 +00:00
|
|
|
|
lda (pPs),y
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.OWNERPID
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
pha
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y A = HI PTR
|
|
|
|
|
ply Y = LO PTR
|
|
|
|
|
clc X = Current hMem
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2017-06-28 14:34:11 +00:00
|
|
|
|
.9 rts
|
2015-06-03 18:30:57 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* MemMgr.AddSlot
|
|
|
|
|
* In:
|
|
|
|
|
* Y,A = Requested size
|
|
|
|
|
* Out:
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MemMgr.AddSlot >STYA ZPMemMgrTmp1 save req size
|
|
|
|
|
ldx MemMgr.LastSlot
|
|
|
|
|
inx
|
|
|
|
|
beq .99 > 255 ERR:OUT OF SLOT
|
|
|
|
|
|
|
|
|
|
lda MemMgr.Free Compute base PTR=FREE-REQ size
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sec
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sbc ZPMemMgrTmp1
|
2016-10-03 15:59:36 +00:00
|
|
|
|
tay save new MemMgr.Free LO
|
2015-06-03 18:30:57 +00:00
|
|
|
|
lda MemMgr.Free+1
|
|
|
|
|
sbc ZPMemMgrTmp1+1
|
2016-10-03 15:59:36 +00:00
|
|
|
|
pha save new MemMgr.Free HI
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-03 15:59:36 +00:00
|
|
|
|
cpy MemMgr.LoMem
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sbc MemMgr.LoMem+1
|
|
|
|
|
bcc .98 ERR out of mem
|
|
|
|
|
|
2016-10-03 15:59:36 +00:00
|
|
|
|
jsr MemMgr.NextSlot X,Y unmodified
|
|
|
|
|
|
|
|
|
|
tya get back MemMgr.Free LO
|
2015-03-15 22:00:40 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
|
|
|
|
sta MemMgr.Free set as system MemMgr.Free value
|
|
|
|
|
sta (ZPMemMgrSPtr),y store is as base address of new slot
|
|
|
|
|
iny
|
2016-10-03 15:59:36 +00:00
|
|
|
|
pla get back MemMgr.Free HI
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sta MemMgr.Free+1
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
iny
|
|
|
|
|
lda ZPMemMgrTmp1 get requested size
|
|
|
|
|
sta (ZPMemMgrSPtr),y setup slot LEN
|
|
|
|
|
iny
|
|
|
|
|
lda ZPMemMgrTmp1+1
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
stx MemMgr.LastSlot mark this slot allocated
|
2015-03-14 21:48:35 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-03 15:59:36 +00:00
|
|
|
|
.98 pla discard new MemMgr.Free HI
|
|
|
|
|
lda #MemMgr.ERROOM
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sec
|
2015-03-14 21:48:35 +00:00
|
|
|
|
rts
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
.99 lda #MemMgr.ERROOH
|
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MemMgr.NextSlot lda ZPMemMgrSPtr
|
|
|
|
|
clc
|
2016-10-03 15:59:36 +00:00
|
|
|
|
adc #S.MEM
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sta ZPMemMgrSPtr
|
|
|
|
|
bcc .8
|
|
|
|
|
inc ZPMemMgrSPtr+1
|
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MemMgr.Init0 ldy #S.MEM.PTR
|
|
|
|
|
lda (ZPMemMgrSPtr),y ZPMemMgrSPtr already set
|
2016-06-23 15:56:13 +00:00
|
|
|
|
sta .2+1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2016-06-23 15:56:13 +00:00
|
|
|
|
sta .2+2
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
ldy #S.MEM.LEN
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2016-06-23 15:56:13 +00:00
|
|
|
|
eor #$ff
|
|
|
|
|
pha
|
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2016-06-23 15:56:13 +00:00
|
|
|
|
eor #$ff a=not hi count
|
|
|
|
|
|
|
|
|
|
ply y=not lo count
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-04-28 15:04:16 +00:00
|
|
|
|
phx
|
|
|
|
|
ldx #0
|
|
|
|
|
|
2016-06-23 15:56:13 +00:00
|
|
|
|
.1 iny
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .2
|
2016-06-23 15:56:13 +00:00
|
|
|
|
inc
|
|
|
|
|
beq .8
|
|
|
|
|
|
2017-04-28 15:04:16 +00:00
|
|
|
|
.2 stz $ffff,x
|
|
|
|
|
inx
|
2016-06-23 15:56:13 +00:00
|
|
|
|
bne .1
|
|
|
|
|
inc .2+2
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
2017-04-28 15:04:16 +00:00
|
|
|
|
.8 plx
|
|
|
|
|
rts
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # FreeMem.A
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## In:
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* A = hMem To Free
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## Out:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* none.
|
|
|
|
|
* (X,Y unmodified)
|
|
|
|
|
*\--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.FreeMem.A phy
|
2016-10-03 15:59:36 +00:00
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
beq * Slot=0, reserved by Kernel
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-08-25 06:37:21 +00:00
|
|
|
|
jsr K.GetMemByID.A X unmodified
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
2016-10-03 15:59:36 +00:00
|
|
|
|
bpl .9 In use ?
|
2015-03-14 21:48:35 +00:00
|
|
|
|
|
2015-03-15 22:00:40 +00:00
|
|
|
|
ldy #S.MEM.REFCNT
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y Get count of those referencing this hMem
|
|
|
|
|
dec only one left ?
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .8 no, must be a code segment loaded several times
|
2015-03-14 21:48:35 +00:00
|
|
|
|
|
2016-11-01 21:34:29 +00:00
|
|
|
|
lda #0 mark this slot as free
|
|
|
|
|
sta (ZPMemMgrSPtr)
|
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.BIN
|
|
|
|
|
lda (ZPMemMgrSPtr),y Any BINPATH to discard ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .1
|
2015-03-14 21:48:35 +00:00
|
|
|
|
|
2017-08-25 06:37:21 +00:00
|
|
|
|
jsr K.GetMemByID.A X unmodified
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bpl * ***MUST BE ALLOCATED***
|
2015-03-14 21:48:35 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
lda #0 mark BINPATH slot as free
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sta (ZPMemMgrSPtr)
|
|
|
|
|
|
2016-11-01 21:34:29 +00:00
|
|
|
|
.1 lda MemMgr.LastSlot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .8
|
|
|
|
|
|
2017-08-25 06:37:21 +00:00
|
|
|
|
jsr K.GetMemByID.A X unmodified
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bmi .8
|
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.LEN
|
|
|
|
|
lda (ZPMemMgrSPtr),y give back LEN bytes
|
|
|
|
|
clc
|
2015-06-03 18:30:57 +00:00
|
|
|
|
adc MemMgr.Free to MemMgr.Free
|
|
|
|
|
sta MemMgr.Free
|
2015-03-14 21:48:35 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
adc MemMgr.Free+1
|
|
|
|
|
sta MemMgr.Free+1
|
|
|
|
|
|
|
|
|
|
dec MemMgr.LastSlot discard last slot
|
2016-11-01 21:34:29 +00:00
|
|
|
|
bne .1 no slot left, exit
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-03 15:59:36 +00:00
|
|
|
|
.8 ply
|
2015-03-14 21:48:35 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
2016-10-03 15:59:36 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
.9 ply discard saved Y
|
|
|
|
|
|
|
|
|
|
lda $D000
|
|
|
|
|
sta .91+1
|
2016-10-07 15:28:17 +00:00
|
|
|
|
bit RRAMWRAMBNK2
|
|
|
|
|
bit RRAMWRAMBNK2
|
2016-10-03 15:59:36 +00:00
|
|
|
|
|
2017-08-21 14:58:48 +00:00
|
|
|
|
>LDYAI TskMgr.Table Delect PS0 for proper In/out devices
|
|
|
|
|
>STYA pPs
|
|
|
|
|
|
2017-01-12 17:43:45 +00:00
|
|
|
|
jsr DevMgr.SYS.Control
|
2016-10-03 15:59:36 +00:00
|
|
|
|
|
|
|
|
|
pla Get PC and sub 2 for calling address
|
|
|
|
|
sec
|
|
|
|
|
sbc #2
|
|
|
|
|
tay
|
|
|
|
|
pla
|
|
|
|
|
sbc #0
|
|
|
|
|
|
|
|
|
|
>PUSHYA
|
|
|
|
|
|
2017-08-25 06:37:21 +00:00
|
|
|
|
>LDYAI K.FreeMem.A.ERR
|
2017-08-24 12:46:48 +00:00
|
|
|
|
jsr K.PrintF.YA
|
2016-10-03 15:59:36 +00:00
|
|
|
|
|
|
|
|
|
.91 ldx #$ff
|
|
|
|
|
bit $C000,x
|
|
|
|
|
bit $C000,x
|
|
|
|
|
bra *
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.FreeMem.A.ERR >CSTR "***MemMgr:Attempt to Free an already freed hMem at $%H"
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # GetMemPtr.A
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## In:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* A = hMem
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## Out:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* Y,A = PTR to MemBlock
|
|
|
|
|
* (X unmodified)
|
|
|
|
|
*\--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.GetMemPtr.A jsr K.GetMemByID.A
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
pha
|
2015-03-14 21:48:35 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2015-06-03 18:30:57 +00:00
|
|
|
|
ply
|
2015-03-14 21:48:35 +00:00
|
|
|
|
rts
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # GetMemByID.A
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## In:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* A = hMem
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## Out:
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* Y,A = ZPMemMgrSPtr = PTR to S.MEM
|
|
|
|
|
* X unmodified
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
* Optimized for :
|
|
|
|
|
* MemMgr.Table is page aligned at $1800
|
|
|
|
|
* S.MEM is 8 bytes
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
2016-10-03 15:59:36 +00:00
|
|
|
|
.DO MemMgr.Table=$1800
|
|
|
|
|
.ELSE
|
|
|
|
|
!!!!!WARNING!!!!!
|
|
|
|
|
.FIN
|
|
|
|
|
.DO S.MEM=8
|
|
|
|
|
.ELSE
|
|
|
|
|
!!!!!WARNING!!!!!
|
|
|
|
|
.FIN
|
|
|
|
|
*--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.GetMemByID.A sta ZPMemMgrSPtr
|
2016-10-03 15:59:36 +00:00
|
|
|
|
lda /MemMgr.Table/8
|
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sta ZPMemMgrSPtr+1
|
2016-10-03 15:59:36 +00:00
|
|
|
|
ldy ZPMemMgrSPtr
|
2015-03-14 21:48:35 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-10-03 15:59:36 +00:00
|
|
|
|
* OLD CODE
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* stz ZPMemMgrSPtr+1
|
|
|
|
|
* asl
|
|
|
|
|
* rol ZPMemMgrSPtr+1
|
|
|
|
|
* asl
|
|
|
|
|
* rol ZPMemMgrSPtr+1
|
|
|
|
|
* asl
|
|
|
|
|
* rol ZPMemMgrSPtr+1
|
|
|
|
|
** clc IMPLICIT
|
|
|
|
|
* adc #MemMgr.Table
|
|
|
|
|
* tay
|
|
|
|
|
* lda ZPMemMgrSPtr+1
|
|
|
|
|
* adc /MemMgr.Table
|
|
|
|
|
* sty ZPMemMgrSPtr
|
|
|
|
|
* sta ZPMemMgrSPtr+1
|
|
|
|
|
* rts
|
2017-09-05 15:17:10 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # NewStr.YA
|
|
|
|
|
* Create a new copy of this C-String
|
|
|
|
|
* ## In:
|
|
|
|
|
* Y,A = Ptr to source C-String
|
|
|
|
|
* ## Out:
|
|
|
|
|
* CC : success
|
|
|
|
|
* Y,A = PTR to String
|
|
|
|
|
* X = hMem (PSTR)
|
|
|
|
|
* CS : error
|
|
|
|
|
* A = SYS error code
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
K.NewStr.YA >STYA .1+1
|
2017-09-06 15:00:10 +00:00
|
|
|
|
>STYA .4+1
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
ldy #0
|
|
|
|
|
stz MemMgr.ReqFlags
|
|
|
|
|
stz MemMgr.ReqSize+1
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
.1 lda $ffff,y
|
|
|
|
|
beq .2
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
inc MemMgr.ReqSize+1
|
|
|
|
|
inc .1+2
|
|
|
|
|
bne .1
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
.2 iny
|
|
|
|
|
bne .3
|
|
|
|
|
inc MemMgr.ReqSize+1
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
.3 sty MemMgr.ReqSize
|
|
|
|
|
|
|
|
|
|
jsr K.GetMem.I
|
2017-09-05 15:17:10 +00:00
|
|
|
|
bcs .9
|
2017-09-06 15:00:10 +00:00
|
|
|
|
>STYA .5+1
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
phy
|
|
|
|
|
pha
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
ldy #0
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
.4 lda $ffff,y
|
|
|
|
|
.5 sta $ffff,y
|
|
|
|
|
beq .8
|
|
|
|
|
iny
|
|
|
|
|
bne .4
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
inc .4+2
|
|
|
|
|
inc .5+2
|
|
|
|
|
bne .4
|
2017-09-05 15:17:10 +00:00
|
|
|
|
|
2017-09-06 15:00:10 +00:00
|
|
|
|
.8 pla
|
|
|
|
|
ply
|
|
|
|
|
clc
|
|
|
|
|
.9 rts
|
2016-10-03 15:59:36 +00:00
|
|
|
|
*--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.LoadStkObj.YA
|
2016-11-01 21:34:29 +00:00
|
|
|
|
*--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.GetStkObj.A
|
2016-11-01 21:34:29 +00:00
|
|
|
|
*--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
K.FreeStkObj.A
|
2016-11-01 21:34:29 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
K.SetLoMem
|
|
|
|
|
clc
|
|
|
|
|
rts
|
|
|
|
|
*/--------------------------------------
|
2017-08-25 06:37:21 +00:00
|
|
|
|
* # GetMemStat.YA
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## In:
|
2017-09-05 15:17:10 +00:00
|
|
|
|
* Y,A = Ptr to 24 bytes buffer
|
2017-03-30 16:11:31 +00:00
|
|
|
|
* ## Out:
|
2016-11-01 21:34:29 +00:00
|
|
|
|
* Buffer filled with memory stats
|
|
|
|
|
*\--------------------------------------
|
2017-08-31 15:35:15 +00:00
|
|
|
|
K.GetMemStat.YA >STYA ZPMemMgrTmp1
|
2016-11-01 21:34:29 +00:00
|
|
|
|
|
|
|
|
|
ldy #6
|
|
|
|
|
|
|
|
|
|
.1 lda MemMgr.Table,y
|
2017-08-31 15:35:15 +00:00
|
|
|
|
sta (ZPMemMgrTmp1),y
|
2016-11-01 21:34:29 +00:00
|
|
|
|
dey
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ldx #6
|
|
|
|
|
ldy #14
|
|
|
|
|
|
|
|
|
|
sta SETREADAUX
|
|
|
|
|
|
|
|
|
|
.2 lda MemMgr.Table,x
|
2017-08-31 15:35:15 +00:00
|
|
|
|
sta (ZPMemMgrTmp1),y
|
2016-11-01 21:34:29 +00:00
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .2
|
|
|
|
|
|
|
|
|
|
sta CLRREADAUX
|
|
|
|
|
|
|
|
|
|
ldx #6
|
|
|
|
|
ldy #22
|
|
|
|
|
|
|
|
|
|
.3 lda DevMgr.Stat,x
|
2017-08-31 15:35:15 +00:00
|
|
|
|
sta (ZPMemMgrTmp1),y
|
2016-11-01 21:34:29 +00:00
|
|
|
|
dey
|
|
|
|
|
dex
|
|
|
|
|
bpl .3
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* In:
|
2017-08-30 15:26:34 +00:00
|
|
|
|
* Y,A = BINPATH (C-String)
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* Out:
|
|
|
|
|
* Y,A = ZPMemMgrSPtr = PTR to S.MEM
|
|
|
|
|
* X = hMem
|
|
|
|
|
*--------------------------------------
|
2016-11-01 21:34:29 +00:00
|
|
|
|
MEM.GetMemByNameYA
|
2016-10-03 15:59:36 +00:00
|
|
|
|
ldx MemMgr.LastSlot
|
|
|
|
|
beq .9
|
|
|
|
|
|
2017-08-30 15:26:34 +00:00
|
|
|
|
>STYA .2+1
|
2015-09-13 20:35:07 +00:00
|
|
|
|
>LDYAI MemMgr.Table
|
2016-10-07 15:28:17 +00:00
|
|
|
|
>STYA ZPMemMgrTmp1
|
2016-10-03 15:59:36 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldx #0
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
.1 lda (ZPMemMgrTmp1)
|
2015-03-14 21:48:35 +00:00
|
|
|
|
bpl .6 In Use?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.BIN any BIN PATH in this slot?
|
2016-10-07 15:28:17 +00:00
|
|
|
|
lda (ZPMemMgrTmp1),y
|
2015-03-14 21:48:35 +00:00
|
|
|
|
beq .6
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-08-25 06:37:21 +00:00
|
|
|
|
jsr K.GetMemPtr.A get pathname
|
2017-08-30 15:26:34 +00:00
|
|
|
|
>STYA .3+1
|
2015-09-13 20:35:07 +00:00
|
|
|
|
|
2017-08-30 15:26:34 +00:00
|
|
|
|
ldy #0
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2017-08-30 15:26:34 +00:00
|
|
|
|
.2 lda $ffff,y
|
|
|
|
|
.3 cmp $ffff,y
|
2015-03-14 21:48:35 +00:00
|
|
|
|
bne .6
|
2017-08-30 15:26:34 +00:00
|
|
|
|
iny
|
|
|
|
|
ora #0
|
2015-03-14 21:48:35 +00:00
|
|
|
|
bne .2
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
>LDYA ZPMemMgrTmp1
|
2015-08-05 20:38:05 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
.6 lda ZPMemMgrTmp1
|
2015-03-14 21:48:35 +00:00
|
|
|
|
clc
|
2016-10-03 15:59:36 +00:00
|
|
|
|
adc #S.MEM
|
2016-10-07 15:28:17 +00:00
|
|
|
|
sta ZPMemMgrTmp1
|
|
|
|
|
bcc .7
|
|
|
|
|
inc ZPMemMgrTmp1+1
|
2015-09-13 20:35:07 +00:00
|
|
|
|
|
2016-10-07 15:28:17 +00:00
|
|
|
|
.7 inx
|
|
|
|
|
cpx MemMgr.LastSlot
|
2016-10-03 15:59:36 +00:00
|
|
|
|
bne .1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
|
|
|
|
.9 sec
|
2015-03-14 21:48:35 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2016-10-07 15:28:17 +00:00
|
|
|
|
MEM.GarbageCollector
|
|
|
|
|
clc
|
|
|
|
|
rts
|
2016-10-03 15:59:36 +00:00
|
|
|
|
*--------------------------------------
|
2015-03-14 21:48:35 +00:00
|
|
|
|
MAN
|
2017-03-29 15:48:15 +00:00
|
|
|
|
SAVE /A2OSX.SRC/SYS/KERNEL.S.MEM
|
|
|
|
|
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ASM
|