2017-12-22 21:24:30 +00:00
|
|
|
|
NEW
|
2019-05-25 19:24:07 +00:00
|
|
|
|
AUTO 3,1
|
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
|
2018-05-04 14:55:29 +00:00
|
|
|
|
ZPMemMgrSize .EQ ZPMEMMGR+4
|
2020-05-17 17:34:32 +00:00
|
|
|
|
MEM.ReqFlags .EQ ZPMEMMGR+6 store requested Flags
|
|
|
|
|
MEM.BestSlot .EQ ZPMEMMGR+7
|
2019-02-01 20:01:54 +00:00
|
|
|
|
MEM.BestScore .EQ ZPMemMgrTmp1
|
2020-01-31 16:12:25 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # Realloc
|
|
|
|
|
* ## C
|
|
|
|
|
* `void *realloc(short int hMem, int size);`
|
|
|
|
|
* ## ASM
|
|
|
|
|
* `>PUSHB hMem`
|
|
|
|
|
* `>PUSHW size`
|
|
|
|
|
* `>SYSCALL realloc`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* YA = ptr
|
|
|
|
|
* X = hMem
|
|
|
|
|
*\--------------------------------------
|
2020-02-03 15:17:34 +00:00
|
|
|
|
MEM.NewSize .BS 2
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
K.Realloc >PULLW MEM.NewSize
|
|
|
|
|
|
2020-03-05 16:55:02 +00:00
|
|
|
|
>PULLA Src hMem
|
2020-02-03 15:17:34 +00:00
|
|
|
|
K.Realloc.I tax
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
jsr MEM.GetMemByID
|
|
|
|
|
|
|
|
|
|
ldy #S.MEM.LEN
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
pha
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
ply
|
2020-02-02 14:58:01 +00:00
|
|
|
|
|
2020-02-12 14:42:07 +00:00
|
|
|
|
jsr MEM.MoveToAux x = Src hMem, YA = Old size
|
2020-01-31 16:12:25 +00:00
|
|
|
|
bcs .99
|
|
|
|
|
|
2020-02-12 14:42:07 +00:00
|
|
|
|
stx .7+1 Aux hMem
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
2020-02-03 15:17:34 +00:00
|
|
|
|
>LDYA MEM.NewSize
|
2020-02-12 14:42:07 +00:00
|
|
|
|
>STYA A2L size for MoveSetupA1A2
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
jsr K.getmem
|
|
|
|
|
bcs .99
|
|
|
|
|
|
2020-02-12 14:42:07 +00:00
|
|
|
|
stx .8+1 new main hMem to return
|
|
|
|
|
>STYA A4L Save MAIN Ptr
|
|
|
|
|
|
|
|
|
|
lda .7+1
|
|
|
|
|
>SYSCALL2 GetStkObjPtr
|
|
|
|
|
jsr MEM.MoveSetupA1A2 Setup AUX base & End Ptrs
|
|
|
|
|
|
|
|
|
|
clc Aux To Main
|
|
|
|
|
jsr AuxMove
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
2020-02-12 14:42:07 +00:00
|
|
|
|
.7 lda #$ff SELF MODIFIED
|
|
|
|
|
>SYSCALL2 FreeStkObj
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
.8 lda #$ff SELF MODIFIED
|
2020-02-12 14:42:07 +00:00
|
|
|
|
tax X = new hMem
|
2020-02-03 15:17:34 +00:00
|
|
|
|
jmp k.GetMemPtr YA = new ptr
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
2020-02-03 15:17:34 +00:00
|
|
|
|
.99 rts
|
2017-07-06 15:30:40 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # GetMem
|
2017-07-06 15:30:40 +00:00
|
|
|
|
* Y,A = Size Requested
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2017-07-06 15:30:40 +00:00
|
|
|
|
* CC : success
|
|
|
|
|
* YA = PTR to Mem (Uninitialised)
|
|
|
|
|
* X = hMem
|
|
|
|
|
* CS :
|
|
|
|
|
* A = EC
|
|
|
|
|
*\--------------------------------------
|
2020-01-31 16:12:25 +00:00
|
|
|
|
K.GetMem0 ldx #S.MEM.F.INIT0
|
|
|
|
|
.HS 2C BIT ABS
|
2018-06-18 06:22:50 +00:00
|
|
|
|
K.GetMem ldx #0
|
2019-01-21 14:51:10 +00:00
|
|
|
|
MEM.GetMem.YAX stx MEM.ReqFlags
|
2018-05-04 14:55:29 +00:00
|
|
|
|
sta ZPMemMgrSize+1
|
2017-12-07 16:33:39 +00:00
|
|
|
|
|
|
|
|
|
tya
|
2019-01-17 20:43:29 +00:00
|
|
|
|
bit #K.MEM.ALIGN-1 aligned ?
|
2017-10-09 05:51:32 +00:00
|
|
|
|
beq .10 yes, request it
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2019-01-17 20:43:29 +00:00
|
|
|
|
and #K.MEM.nALIGNm1 align on boundary
|
2017-06-28 14:34:11 +00:00
|
|
|
|
clc
|
2019-01-17 20:43:29 +00:00
|
|
|
|
adc #K.MEM.ALIGN
|
2017-10-09 05:51:32 +00:00
|
|
|
|
bcc .10
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2018-05-04 14:55:29 +00:00
|
|
|
|
inc ZPMemMgrSize+1
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2018-05-04 14:55:29 +00:00
|
|
|
|
.10 sta ZPMemMgrSize
|
2017-10-27 06:36:46 +00:00
|
|
|
|
>LDYAI Mem.Table
|
2015-06-03 18:30:57 +00:00
|
|
|
|
>STYA ZPMemMgrSPtr
|
2019-01-21 14:51:10 +00:00
|
|
|
|
stz MEM.BestSlot
|
|
|
|
|
ldx #$ff
|
|
|
|
|
stx MEM.BestScore
|
|
|
|
|
stx MEM.BestScore+1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
ldx #0 Current slot=0
|
2016-10-07 15:28:17 +00:00
|
|
|
|
bra .4 skip slot 0, Check if some free slot to reuse first
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
.1 inx move to next slot
|
2017-10-27 06:36:46 +00:00
|
|
|
|
jsr Mem.NextSlot
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr) Get Flags
|
|
|
|
|
bmi .4 in use ?
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2019-01-21 14:51:10 +00:00
|
|
|
|
.2 lda MEM.ReqFlags Found an empty slot
|
2019-11-15 14:40:48 +00:00
|
|
|
|
bit #S.MEM.F.NOCROSS
|
|
|
|
|
beq .21
|
|
|
|
|
|
|
|
|
|
ldy ZPMemMgrSize+1 > 255, not applicable
|
|
|
|
|
bne .22 Align to page if $100
|
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
2019-11-15 14:40:48 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y get LO of PTR
|
|
|
|
|
clc
|
|
|
|
|
adc ZPMemMgrSize
|
|
|
|
|
bcs .4 cross page boundary....
|
|
|
|
|
|
|
|
|
|
lda MEM.ReqFlags get back flags to test if match
|
|
|
|
|
|
|
|
|
|
.21 bit #S.MEM.F.ALIGN is request needs a page align ?
|
|
|
|
|
beq .3
|
|
|
|
|
|
|
|
|
|
.22 ldy #S.MEM.PTR
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y get LO of PTR
|
|
|
|
|
bne .4 not page-aligned
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
.3 ldy #S.MEM.LEN
|
2019-01-21 14:51:10 +00:00
|
|
|
|
sec
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y get LEN of this block
|
2019-01-21 14:51:10 +00:00
|
|
|
|
sbc ZPMemMgrSize compare with requested size
|
|
|
|
|
pha
|
2015-03-14 21:48:35 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2019-01-21 14:51:10 +00:00
|
|
|
|
sbc ZPMemMgrSize+1
|
|
|
|
|
ply Y,A = SlotLen - ReqSize
|
|
|
|
|
bcc .4 req size > slot size
|
|
|
|
|
|
|
|
|
|
cpy MEM.BestScore
|
|
|
|
|
pha
|
|
|
|
|
sbc MEM.BestScore+1
|
|
|
|
|
pla
|
|
|
|
|
bcs .4 Delta is >= BestScore
|
|
|
|
|
bne .4 Delta is > 255...
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2019-01-21 14:51:10 +00:00
|
|
|
|
sty MEM.BestScore
|
|
|
|
|
sta MEM.BestScore+1
|
|
|
|
|
stx MEM.BestSlot
|
2017-10-27 06:36:46 +00:00
|
|
|
|
.4 cpx Mem.LastSlot any other slot to check?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .1 last one, create a new slot
|
2019-07-31 15:10:59 +00:00
|
|
|
|
|
2019-01-21 14:51:10 +00:00
|
|
|
|
lda MEM.BestSlot
|
|
|
|
|
beq .5
|
|
|
|
|
tax
|
2019-01-30 06:20:13 +00:00
|
|
|
|
jsr MEM.GetMemByID
|
2019-01-21 14:51:10 +00:00
|
|
|
|
bra .7
|
2015-06-03 18:30:57 +00:00
|
|
|
|
*-------------- Create a New SLOT
|
2018-08-20 15:15:37 +00:00
|
|
|
|
|
2019-01-21 14:51:10 +00:00
|
|
|
|
.5 lda MEM.ReqFlags
|
2019-11-15 14:40:48 +00:00
|
|
|
|
bit #S.MEM.F.NOCROSS
|
|
|
|
|
beq .51
|
|
|
|
|
|
|
|
|
|
lda ZPMemMgrSize+1 > 255, not applicable
|
|
|
|
|
bne .52 Align to page if $100
|
2019-11-20 10:08:49 +00:00
|
|
|
|
|
2019-11-15 14:40:48 +00:00
|
|
|
|
lda Mem.Free target PTR will be in same page ?
|
2020-01-18 19:37:32 +00:00
|
|
|
|
beq .6 Memfree is xx00, will be in same page
|
2019-11-15 14:40:48 +00:00
|
|
|
|
cmp ZPMemMgrSize
|
|
|
|
|
bcs .6 yes, allocate
|
|
|
|
|
|
|
|
|
|
tay no, reserve a free slot to fill gap
|
|
|
|
|
lda #0
|
|
|
|
|
jsr Mem.AddSlot X = new slot
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
lda #S.MEM.F.NOCROSS Make sure marked FREE
|
|
|
|
|
sta (ZPMemMgrSPtr)
|
|
|
|
|
bra .6
|
|
|
|
|
|
|
|
|
|
.51 bit #S.MEM.F.ALIGN is request needs a page align ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .6
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
|
|
|
|
.52 lda Mem.Free target PTR will be page aligned ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sec
|
2018-05-04 14:55:29 +00:00
|
|
|
|
sbc ZPMemMgrSize
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .6 yes, allocate
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2015-06-03 18:30:57 +00:00
|
|
|
|
tay no, reserve a free slot to fill gap
|
|
|
|
|
lda #0
|
2017-11-22 16:27:50 +00:00
|
|
|
|
jsr Mem.AddSlot X = new slot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bcs .9
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2018-08-21 13:12:47 +00:00
|
|
|
|
lda #S.MEM.F.ALIGN Make sure marked FREE
|
|
|
|
|
sta (ZPMemMgrSPtr)
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2018-05-04 14:55:29 +00:00
|
|
|
|
.6 >LDYA ZPMemMgrSize
|
2017-11-22 16:27:50 +00:00
|
|
|
|
jsr Mem.AddSlot X = new slot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bcs .9
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*-------------- Reuse this SLOT
|
2017-11-22 16:27:50 +00:00
|
|
|
|
|
2019-01-21 14:51:10 +00:00
|
|
|
|
.7 lda MEM.ReqFlags get requested flags
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ora #S.MEM.F.INUSE mark as in use
|
|
|
|
|
sta (ZPMemMgrSPtr)
|
2015-06-03 18:30:57 +00:00
|
|
|
|
and #S.MEM.F.INIT0
|
|
|
|
|
beq .8
|
2016-11-01 21:34:29 +00:00
|
|
|
|
|
2019-11-15 14:40:48 +00:00
|
|
|
|
jsr MEM.Init0
|
|
|
|
|
|
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
|
2020-03-04 16:38:32 +00:00
|
|
|
|
|
|
|
|
|
lda RDREADAUX
|
|
|
|
|
pha
|
|
|
|
|
|
|
|
|
|
sta CLRREADAUX
|
|
|
|
|
|
2016-10-29 19:58:21 +00:00
|
|
|
|
ldy #S.PS.PID
|
2020-02-28 07:21:46 +00:00
|
|
|
|
lda (pPS),y
|
2020-03-04 16:38:32 +00:00
|
|
|
|
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ldy #S.MEM.OWNERPID
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
2020-03-04 16:38:32 +00:00
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
bpl .80
|
|
|
|
|
|
|
|
|
|
sta SETREADAUX
|
|
|
|
|
|
|
|
|
|
.80 clc
|
|
|
|
|
|
2019-02-03 21:58:26 +00:00
|
|
|
|
jmp MEM.GetMEMPTR
|
2018-12-20 16:23:43 +00:00
|
|
|
|
* A = HI PTR,Y = LO PTR,X = Current hMem
|
2019-10-03 06:25:27 +00:00
|
|
|
|
.9 rts
|
2015-06-03 18:30:57 +00:00
|
|
|
|
*--------------------------------------
|
2017-10-27 06:36:46 +00:00
|
|
|
|
* Mem.AddSlot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
* In:
|
|
|
|
|
* Y,A = Requested size
|
|
|
|
|
* Out:
|
|
|
|
|
*--------------------------------------
|
2017-10-27 14:56:46 +00:00
|
|
|
|
Mem.AddSlot >STYA ZPMemMgrTmp1 save req size
|
2018-08-11 10:57:57 +00:00
|
|
|
|
ldx Mem.LastSlot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
inx
|
|
|
|
|
beq .99 > 255 ERR:OUT OF SLOT
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
lda Mem.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
|
2017-10-27 06:36:46 +00:00
|
|
|
|
tay save new Mem.Free LO
|
|
|
|
|
lda Mem.Free+1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sbc ZPMemMgrTmp1+1
|
2019-10-03 06:25:27 +00:00
|
|
|
|
pha save new Mem.Free HI
|
2017-10-27 06:36:46 +00:00
|
|
|
|
cpy Mem.LoMem
|
|
|
|
|
sbc Mem.LoMem+1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bcc .98 ERR out of mem
|
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
jsr Mem.NextSlot X,Y unmodified
|
|
|
|
|
tya get back Mem.Free LO
|
2015-06-03 18:30:57 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
2017-10-27 06:36:46 +00:00
|
|
|
|
sta Mem.Free set as system Mem.Free value
|
2018-08-11 10:57:57 +00:00
|
|
|
|
sta (ZPMemMgrSPtr),y store it as base address of new slot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
iny
|
2017-10-27 06:36:46 +00:00
|
|
|
|
pla get back Mem.Free HI
|
|
|
|
|
sta Mem.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
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
stx Mem.LastSlot mark this slot allocated
|
2015-03-14 21:48:35 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
2017-10-27 06:36:46 +00:00
|
|
|
|
.98 pla discard new Mem.Free HI
|
2019-11-15 14:40:48 +00:00
|
|
|
|
|
2018-10-21 20:54:07 +00:00
|
|
|
|
.99 lda #E.OOM
|
2015-06-03 18:30:57 +00:00
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2018-12-20 16:23:43 +00:00
|
|
|
|
MEM.NextSlot lda ZPMemMgrSPtr
|
2015-06-03 18:30:57 +00:00
|
|
|
|
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
|
2019-11-15 14:40:48 +00:00
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MEM.Init0 phx
|
|
|
|
|
ldy #S.MEM.PTR
|
|
|
|
|
lda (ZPMemMgrSPtr),y ZPMemMgrSPtr already set
|
|
|
|
|
sta .12+1
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
sta .12+2
|
|
|
|
|
lda ZPMemMgrSize
|
|
|
|
|
eor #$ff
|
|
|
|
|
tay y=not lo count
|
|
|
|
|
lda ZPMemMgrSize+1
|
|
|
|
|
eor #$ff a=not hi count
|
|
|
|
|
|
|
|
|
|
ldx #0
|
|
|
|
|
|
|
|
|
|
.11 iny
|
|
|
|
|
bne .12
|
|
|
|
|
|
|
|
|
|
inc
|
|
|
|
|
beq .13
|
|
|
|
|
|
|
|
|
|
.12 stz $ffff,x
|
|
|
|
|
inx
|
|
|
|
|
bne .11
|
|
|
|
|
|
|
|
|
|
inc .12+2
|
|
|
|
|
bra .11
|
|
|
|
|
|
|
|
|
|
.13 plx
|
|
|
|
|
rts
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # FreeMem
|
2015-03-14 21:48:35 +00:00
|
|
|
|
* A = hMem To Free
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* none.
|
2018-08-21 13:12:47 +00:00
|
|
|
|
* (X unmodified)
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*\--------------------------------------
|
2019-02-11 16:44:56 +00:00
|
|
|
|
K.FreeMem.MSG .AZ "FreeMem:hMem=$%h,PID=%d\r\n"
|
2018-11-26 16:36:55 +00:00
|
|
|
|
*--------------------------------------
|
2020-02-16 20:45:16 +00:00
|
|
|
|
K.FreeMem.ERR >PUSHWI K.FreeMem.MSG
|
|
|
|
|
|
|
|
|
|
tya hMem n Y
|
|
|
|
|
>PUSHA
|
|
|
|
|
|
2019-02-11 16:44:56 +00:00
|
|
|
|
ldy #S.PS.PID
|
2018-11-26 16:36:55 +00:00
|
|
|
|
lda (pPS),y
|
2019-02-11 16:44:56 +00:00
|
|
|
|
>PUSHA
|
|
|
|
|
>PUSHBI 2
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
|
|
|
|
.1 >SYSCALL2 printf
|
2020-08-09 19:47:42 +00:00
|
|
|
|
>DEBUG
|
2019-06-07 15:02:51 +00:00
|
|
|
|
lda #E.INVH
|
2018-11-26 16:36:55 +00:00
|
|
|
|
sec
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
K.FreeMem tay
|
2019-02-11 16:44:56 +00:00
|
|
|
|
beq K.FreeMem.ERR Slot=0, reserved by Kernel
|
2018-08-20 15:15:37 +00:00
|
|
|
|
cmp Mem.LastSlot
|
|
|
|
|
bcc .10
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2019-02-11 16:44:56 +00:00
|
|
|
|
bne K.FreeMem.ERR
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2020-05-04 20:46:21 +00:00
|
|
|
|
.10 jsr MEM.GetMemByID X,Y unmodified
|
2018-11-28 14:58:42 +00:00
|
|
|
|
lda (ZPMemMgrSPtr) In use ?
|
2019-02-11 16:44:56 +00:00
|
|
|
|
bpl K.FreeMem.ERR
|
2018-11-28 14:58:42 +00:00
|
|
|
|
|
2019-07-18 15:55:43 +00:00
|
|
|
|
jsr MEM.DecRefCnt only one left ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
bne .8 no, must be a code segment loaded several times
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2018-08-21 13:12:47 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
2020-03-06 16:20:29 +00:00
|
|
|
|
and #$7f keep flags for memdump
|
2018-08-21 13:12:47 +00:00
|
|
|
|
sta (ZPMemMgrSPtr) Mark as FREE
|
2020-03-06 16:20:29 +00:00
|
|
|
|
and #S.MEM.F.CODE CS: Any BINPATH to discard ?
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .1
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2018-08-21 13:12:47 +00:00
|
|
|
|
ldy #S.MEM.BIN
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2019-01-30 06:20:13 +00:00
|
|
|
|
jsr MEM.GetMemByID X unmodified
|
2019-07-18 15:55:43 +00:00
|
|
|
|
* lda (ZPMemMgrSPtr)
|
|
|
|
|
* bpl * ***MUST BE ALLOCATED***
|
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)
|
2020-03-04 16:38:32 +00:00
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
.1 lda Mem.LastSlot
|
2015-06-03 18:30:57 +00:00
|
|
|
|
beq .8
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2019-01-30 06:20:13 +00:00
|
|
|
|
jsr MEM.GetMemByID X unmodified
|
2015-03-14 21:48:35 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
2017-10-09 05:51:32 +00:00
|
|
|
|
bmi .8 used, exit
|
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
.2 dec Mem.LastSlot free! get previous....
|
2018-08-21 13:12:47 +00:00
|
|
|
|
beq .80 empty list: go set Mem.Free=Mem.HiMem
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2017-10-27 06:36:46 +00:00
|
|
|
|
lda Mem.LastSlot
|
2019-01-30 06:20:13 +00:00
|
|
|
|
jsr MEM.GetMemByID X unmodified
|
2017-10-09 05:51:32 +00:00
|
|
|
|
lda (ZPMemMgrSPtr)
|
|
|
|
|
bpl .2 free again! loop
|
2020-02-16 20:45:16 +00:00
|
|
|
|
|
2017-10-09 05:51:32 +00:00
|
|
|
|
ldy #S.MEM.PTR
|
2017-10-27 06:36:46 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y set Mem.Free...
|
|
|
|
|
sta Mem.Free
|
2015-03-14 21:48:35 +00:00
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
2017-10-27 06:36:46 +00:00
|
|
|
|
sta Mem.Free+1
|
2015-06-03 18:30:57 +00:00
|
|
|
|
|
2018-08-21 13:12:47 +00:00
|
|
|
|
.8 clc
|
2015-03-14 21:48:35 +00:00
|
|
|
|
rts
|
2020-03-04 16:38:32 +00:00
|
|
|
|
|
2018-08-21 13:12:47 +00:00
|
|
|
|
.80 >LDYA Mem.HiMem
|
2017-10-27 06:36:46 +00:00
|
|
|
|
>STYA Mem.Free
|
2018-08-21 13:12:47 +00:00
|
|
|
|
clc
|
|
|
|
|
rts
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # GetMemPtr
|
2018-08-21 13:12:47 +00:00
|
|
|
|
* A = hMem
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-08-21 13:12:47 +00:00
|
|
|
|
* Y,A = PTR to MemBlock
|
|
|
|
|
* (X unmodified)
|
2016-10-25 06:58:15 +00:00
|
|
|
|
*\--------------------------------------
|
|
|
|
|
* Optimized for :
|
2019-03-14 16:51:02 +00:00
|
|
|
|
* Mem.Table is page aligned at $800
|
2016-10-25 06:58:15 +00:00
|
|
|
|
* S.MEM is 8 bytes
|
2015-03-14 21:48:35 +00:00
|
|
|
|
*--------------------------------------
|
2018-12-17 07:02:03 +00:00
|
|
|
|
.DO Mem.Table=$800
|
2016-10-03 15:59:36 +00:00
|
|
|
|
.ELSE
|
|
|
|
|
!!!!!WARNING!!!!!
|
|
|
|
|
.FIN
|
|
|
|
|
.DO S.MEM=8
|
|
|
|
|
.ELSE
|
|
|
|
|
!!!!!WARNING!!!!!
|
|
|
|
|
.FIN
|
|
|
|
|
*--------------------------------------
|
2019-02-01 20:01:54 +00:00
|
|
|
|
K.GetMemPtr jsr MEM.GetMemByID
|
2019-02-03 21:58:26 +00:00
|
|
|
|
MEM.GetMEMPTR ldy #S.MEM.PTR
|
2018-08-21 13:12:47 +00:00
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
pha
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
ply
|
|
|
|
|
rts
|
2019-02-01 20:01:54 +00:00
|
|
|
|
*--------------------------------------
|
2019-01-30 06:20:13 +00:00
|
|
|
|
MEM.GetMemByID sta ZPMemMgrSPtr
|
2017-10-27 06:36:46 +00:00
|
|
|
|
lda /Mem.Table/8
|
2016-10-03 15:59:36 +00:00
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
|
|
|
|
asl ZPMemMgrSPtr
|
|
|
|
|
rol
|
2015-03-14 21:48:35 +00:00
|
|
|
|
sta ZPMemMgrSPtr+1
|
|
|
|
|
rts
|
2019-03-15 16:20:28 +00:00
|
|
|
|
*--------------------------------------
|
2019-07-18 15:55:43 +00:00
|
|
|
|
Mem.SetOwner ldy #S.MEM.OWNERPID
|
|
|
|
|
lda CORE.LastPSID
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
Mem.IncRefCnt ldy #S.MEM.REFCNT
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
inc
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
Mem.DecRefCnt ldy #S.MEM.REFCNT
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
dec
|
|
|
|
|
sta (ZPMemMgrSPtr),y
|
|
|
|
|
rts
|
2018-05-04 14:55:29 +00:00
|
|
|
|
*/--------------------------------------
|
2018-06-18 06:22:50 +00:00
|
|
|
|
* # NewStkObj
|
2018-04-29 19:10:13 +00:00
|
|
|
|
* Y,A = Size Requested
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2018-04-29 19:10:13 +00:00
|
|
|
|
* CC : success
|
|
|
|
|
* YA = PTR to Mem (Uninitialised)
|
|
|
|
|
* X = hMem
|
|
|
|
|
* CS :
|
|
|
|
|
* A = EC
|
|
|
|
|
*\--------------------------------------
|
2017-10-17 15:40:21 +00:00
|
|
|
|
*/--------------------------------------
|
2017-12-07 16:33:39 +00:00
|
|
|
|
* # LoadStkObj
|
|
|
|
|
* Load a file in AUX memory (Stock Objects)
|
2020-02-14 07:21:56 +00:00
|
|
|
|
* PUSHW = PATH (Handled by....
|
2017-12-07 16:33:39 +00:00
|
|
|
|
* PUSHB = MODE ...
|
2020-02-14 07:21:56 +00:00
|
|
|
|
* PUSHB = TYPE ...
|
|
|
|
|
* PUSHW = AUXTYPE ...FOpen)
|
2018-10-11 15:23:06 +00:00
|
|
|
|
* ## RETURN VALUE
|
2017-12-07 16:33:39 +00:00
|
|
|
|
* Y,A = File Length
|
|
|
|
|
* X = hMem of Loaded Object in AUX mem
|
2017-10-17 15:40:21 +00:00
|
|
|
|
*\--------------------------------------
|
2020-02-11 16:32:33 +00:00
|
|
|
|
K.LoadStkObj >SYSCALL2 LoadTxtFile To get ending \0
|
2017-12-07 16:33:39 +00:00
|
|
|
|
bcs .99
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
stx .90+1
|
2019-08-02 14:36:49 +00:00
|
|
|
|
sty .81+1 Save File Len
|
2019-04-11 15:59:57 +00:00
|
|
|
|
sta .82+1
|
2020-02-11 16:32:33 +00:00
|
|
|
|
|
2019-02-03 21:58:26 +00:00
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
inc +1 for ending 0
|
2019-07-30 15:35:42 +00:00
|
|
|
|
|
2020-01-31 16:12:25 +00:00
|
|
|
|
.1 jsr MEM.MoveToAux X = AUX hMem
|
2017-12-07 16:33:39 +00:00
|
|
|
|
bcs .9
|
2019-07-30 15:35:42 +00:00
|
|
|
|
|
2019-04-11 15:59:57 +00:00
|
|
|
|
.81 ldy #$ff and file len in Y,A
|
|
|
|
|
.82 lda #$ff
|
|
|
|
|
* clc
|
2017-12-07 16:33:39 +00:00
|
|
|
|
rts
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
2017-12-07 16:33:39 +00:00
|
|
|
|
.9 pha
|
2020-01-31 16:12:25 +00:00
|
|
|
|
.90 lda #$ff SELF MODIFIED
|
|
|
|
|
jsr K.freemem
|
2017-12-07 16:33:39 +00:00
|
|
|
|
pla
|
|
|
|
|
sec
|
2019-10-03 06:25:27 +00:00
|
|
|
|
.99 rts
|
2019-03-15 16:20:28 +00:00
|
|
|
|
*/--------------------------------------
|
2019-06-19 15:56:59 +00:00
|
|
|
|
* # GetStkObjPtr
|
2019-03-15 16:20:28 +00:00
|
|
|
|
* ## ASM
|
|
|
|
|
* `lda hStkObj`
|
2019-06-19 15:56:59 +00:00
|
|
|
|
* `>SYSCALL GetStkObjPtr`
|
2019-03-15 16:20:28 +00:00
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
*\--------------------------------------
|
2019-06-19 15:56:59 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* # FreeStkObj
|
|
|
|
|
* A = hMem To Free (AUX Memory)
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* none.
|
|
|
|
|
* (X,Y unmodified)
|
|
|
|
|
*\--------------------------------------
|
2020-02-03 16:05:54 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MEM.DupX sta SETREADAUX
|
|
|
|
|
sta SETWRITEAUX
|
|
|
|
|
jsr MEM.Dup
|
|
|
|
|
sta CLRREADAUX
|
|
|
|
|
sta CLRWRITEAUX
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MEM.Dup jsr K.GetMemPtr
|
|
|
|
|
>STYA A1L
|
|
|
|
|
|
|
|
|
|
ldy #S.MEM.LEN
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
pha
|
|
|
|
|
eor #$ff
|
|
|
|
|
sta A4L
|
|
|
|
|
iny
|
|
|
|
|
lda (ZPMemMgrSPtr),y
|
|
|
|
|
eor #$ff
|
|
|
|
|
sta A4L+1
|
|
|
|
|
eor #$ff
|
|
|
|
|
ply
|
|
|
|
|
|
|
|
|
|
jsr K.GetMem
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
>STYA A2L
|
|
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
|
|
.1 inc A4L
|
|
|
|
|
bne .2
|
|
|
|
|
inc A4L+1
|
|
|
|
|
beq .8
|
|
|
|
|
|
|
|
|
|
.2 lda (A1L),y
|
|
|
|
|
sta (A2L),y
|
|
|
|
|
iny
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
inc A1L+1
|
|
|
|
|
inc A2L+1
|
|
|
|
|
bra .1
|
|
|
|
|
|
|
|
|
|
.8 txa
|
|
|
|
|
* clc
|
2020-02-16 20:45:16 +00:00
|
|
|
|
.9
|
|
|
|
|
MEM.Dup.RTS rts
|
2020-02-03 16:05:54 +00:00
|
|
|
|
*--------------------------------------
|
2020-02-02 14:58:01 +00:00
|
|
|
|
MEM.CopyToMain clc
|
|
|
|
|
.HS B0 BCS
|
|
|
|
|
MEM.MoveToMain sec
|
|
|
|
|
ror .1+1
|
|
|
|
|
stx .2+1 Save AUX hMem
|
|
|
|
|
>STYA A2L Save LEN to copy/move
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
2020-02-10 16:24:49 +00:00
|
|
|
|
sta CLRREADAUX Make sure MAIN !!!!
|
|
|
|
|
sta CLRWRITEAUX
|
|
|
|
|
jsr K.GetMem
|
2020-02-16 20:45:16 +00:00
|
|
|
|
bcs MEM.Dup.RTS
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
stx .8+1 Save MAIN hMem
|
|
|
|
|
>STYA A4L Save MAIN Ptr
|
|
|
|
|
|
2020-02-02 14:58:01 +00:00
|
|
|
|
lda .2+1
|
2020-01-31 16:12:25 +00:00
|
|
|
|
>SYSCALL2 GetStkObjPtr
|
2020-02-11 16:32:33 +00:00
|
|
|
|
jsr MEM.MoveSetupA1A2 Setup AUX base & End Ptrs
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
clc Aux To Main
|
|
|
|
|
jsr AuxMove
|
|
|
|
|
|
|
|
|
|
.1 lda #$ff SELF MODIFIED
|
2020-02-02 14:58:01 +00:00
|
|
|
|
bpl .8
|
|
|
|
|
|
|
|
|
|
.2 lda #$ff SELF MODIFIED
|
2020-01-31 16:12:25 +00:00
|
|
|
|
>SYSCALL2 FreeStkObj release AUX memory
|
|
|
|
|
|
|
|
|
|
.8 ldx #$ff Returns MAIN hMem
|
2020-02-02 14:58:01 +00:00
|
|
|
|
txa
|
|
|
|
|
jmp K.GetMemPtr Y,A = Ptr
|
2020-01-31 16:12:25 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MEM.MoveToAux stx .1+1 Save MAIN hMem
|
|
|
|
|
>STYA A2L Save LEN to move
|
|
|
|
|
|
|
|
|
|
>SYSCALL2 NewStkObj
|
|
|
|
|
bcs .9
|
|
|
|
|
|
|
|
|
|
stx .8+1 Save AUX hMem
|
|
|
|
|
>STYA A4L Save AUX Ptr
|
|
|
|
|
|
|
|
|
|
lda .1+1
|
|
|
|
|
jsr K.GetMemPtr
|
2020-02-11 16:32:33 +00:00
|
|
|
|
jsr MEM.MoveSetupA1A2 Setup MAIN base & End Ptrs
|
2020-01-31 16:12:25 +00:00
|
|
|
|
|
|
|
|
|
sec Main To Aux
|
|
|
|
|
jsr AuxMove
|
|
|
|
|
|
|
|
|
|
.1 lda #$ff SELF MODIFIED
|
|
|
|
|
jsr K.FreeMem release MAIN memory
|
|
|
|
|
|
|
|
|
|
.8 ldx #$ff Returns AUX hMem
|
|
|
|
|
* clc
|
|
|
|
|
|
|
|
|
|
.9 rts
|
2018-04-29 19:10:13 +00:00
|
|
|
|
*--------------------------------------
|
2020-02-11 16:32:33 +00:00
|
|
|
|
MEM.MoveSetupA1A2
|
|
|
|
|
>STYA A1L Start Address
|
|
|
|
|
pha
|
|
|
|
|
tya
|
|
|
|
|
clc
|
|
|
|
|
adc A2L
|
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
adc A2L+1
|
|
|
|
|
sta A2L+1
|
|
|
|
|
|
|
|
|
|
tya
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
dec A2L+1
|
|
|
|
|
|
|
|
|
|
.1 dey
|
|
|
|
|
sty A2L
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2019-01-11 16:06:05 +00:00
|
|
|
|
MEM.GetKrnlBuf pha
|
|
|
|
|
tya
|
|
|
|
|
clc
|
|
|
|
|
adc DevMgr.Free
|
|
|
|
|
tax
|
|
|
|
|
pla
|
|
|
|
|
adc DevMgr.Free+1
|
|
|
|
|
bcs .99 we crossed $FFFF, out of mem
|
|
|
|
|
cpx #DevMgr.HiMem
|
|
|
|
|
pha
|
|
|
|
|
sbc /DevMgr.HiMem
|
2019-07-29 15:38:55 +00:00
|
|
|
|
pla
|
|
|
|
|
bcs .99 No More Room...
|
2019-01-11 16:06:05 +00:00
|
|
|
|
ldy DevMgr.Free
|
|
|
|
|
stx DevMgr.Free
|
|
|
|
|
ldx DevMgr.Free+1
|
|
|
|
|
sta DevMgr.Free+1
|
|
|
|
|
txa
|
|
|
|
|
* clc
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.99 lda #E.OOM
|
|
|
|
|
* sec
|
2019-10-03 06:25:27 +00:00
|
|
|
|
rts
|
2019-01-11 16:06:05 +00:00
|
|
|
|
*--------------------------------------
|
2015-03-14 21:48:35 +00:00
|
|
|
|
MAN
|
2018-11-17 17:17:13 +00:00
|
|
|
|
SAVE USR/SRC/SYS/KERNEL.S.MEM
|
|
|
|
|
LOAD USR/SRC/SYS/KERNEL.S
|
2015-03-14 21:48:35 +00:00
|
|
|
|
ASM
|