This page (revision-19) was last changed on 11-Jun-2023 19:50 by Administrator 

This page was created on 15-Aug-2017 16:14 by Roland B. Wassenberg

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
19 11-Jun-2023 19:50 9 KB Administrator to previous
18 03-Feb-2023 15:21 9 KB Maury Markowitz to previous | to last
17 03-May-2018 20:17 9 KB Maury Markowitz to previous | to last
16 03-May-2018 18:12 9 KB Maury Markowitz to previous | to last ACTION ==> Action
15 01-May-2018 01:31 9 KB Roland B. Wassenberg to previous | to last
14 28-Apr-2018 12:48 9 KB Maury Markowitz to previous | to last
13 28-Apr-2018 12:47 9 KB Maury Markowitz to previous | to last
12 28-Apr-2018 12:09 7 KB Maury Markowitz to previous | to last
11 15-Aug-2017 18:29 7 KB Roland B. Wassenberg to previous | to last
10 15-Aug-2017 18:23 7 KB Roland B. Wassenberg to previous | to last
9 15-Aug-2017 18:12 4 KB Roland B. Wassenberg to previous | to last
8 15-Aug-2017 17:18 4 KB Roland B. Wassenberg to previous | to last
7 15-Aug-2017 17:16 3 KB Roland B. Wassenberg to previous | to last
6 15-Aug-2017 17:09 4 KB Roland B. Wassenberg to previous | to last
5 15-Aug-2017 16:53 4 KB Roland B. Wassenberg to previous | to last
4 15-Aug-2017 16:36 3 KB Roland B. Wassenberg to previous | to last
3 15-Aug-2017 16:31 3 KB Roland B. Wassenberg to previous | to last
2 15-Aug-2017 16:24 3 KB Roland B. Wassenberg to previous | to last
1 15-Aug-2017 16:14 648 bytes Roland B. Wassenberg to last PL65

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 6 added 2 lines
* [pl65-fixed.atr] ; Thank you ddez from AtariAge for fixing the existing image! :-)
* [PL65_Compiler_SpartaDOS_X_33a_360.atr] ; Thank you 576XE from AtariAge for providing this version! :-)
At line 34 added one line
Thank you 576XE from AtariAge!
At line 119 added 147 lines
{{{
!====================================!
! ALLOC.LIB Memory allocation library
! for PL65 compiler !
! First-fit algorythm for malloc/free
!------------------------------------!
! by Evgeny Zolotarev (aka 576XE),2017
!====================================!
CONST NULL=0,FRED=1,USED=0
CONST MEMSTART=$4000,MEMEND=$BC00
CONST MEMSIZ=MEMEND-MEMSTART
CONST METALEN=6,BYTSZ=1,INTSZ=2
!------------------------------------!
POINTER gpP INT gpV BASED gpP
POINTER freList
!------------------------------------!
FUNC getFlag(INT adr)
BEGIN gpP=adr END gpV
!------------------------------------!
FUNC getSize(INT adr)
BEGIN gpP=adr+2 END gpV
!------------------------------------!
FUNC getNext(INT adr)
BEGIN gpP=adr+4 END gpV
!------------------------------------!
PROC setFlag(INT adr,flag)
BEGIN gpP=adr gpV=flag END
!------------------------------------!
PROC setSize(INT adr,size)
BEGIN gpP=adr+2 gpV=size END
!------------------------------------!
PROC setNext(INT adr,next)
BEGIN gpP=adr+4 gpV=next END
!------------------------------------!
PROC memInit()
BEGIN
setFlag(freList,FRED)
setSize(freList,MEMSIZ-METALEN)
setNext(freList,NULL)
END
!------------------------------------!
PROC split(POINTER fits INT size)
POINTER new INT blkSiz
BEGIN
blkSiz=METALEN+size
new=fits+blkSiz
setFlag(new,FRED)
setSize(new,getSize(fits)-blkSiz)
setNext(new,getNext(fits))
setFlag(fits,USED)
setSize(fits,size)
setNext(fits,new)
END
!------------------------------------!
FUNC alloc(INT nBytes)
POINTER curr,result
BEGIN
IF (getSize(freList)=0) THEN
memInit()
WRTLN("Memory initialized") CR()
ENDIF
curr=freList
WHILE ((getSize(curr)<nBytes OR getFlag(curr)=USED) AND getNext(curr)<>NULL) DO
curr=getNext(curr)
WRTLN("- Search for fitting block...")
ENDWHILE
IF getSize(curr)=nBytes THEN
setFlag(curr,USED)
result=curr+METALEN
WRTLN("+ Exact fitting block allocated")
RETURN result
ENDIF
IF getSize(curr)>nBytes+METALEN THEN
split(curr,nBytes)
result=curr+METALEN
BASE=16
WRTSTR("Block $") WRITE(result) WRTSTR("-$") WRITE(result+nBytes)
WRTSTR(" size=") BASE=10 WRITE(getSize(curr)) WRTLN(" allocated")
RETURN result
ELSE
result=NULL
WRTLN("- No sufficient memory to allocate")
ENDIF
END result
!------------------------------------!
PROC merge()
POINTER curr
INT size,next
BEGIN
curr=freList
WHILE getNext(curr)<>NULL DO
IF (getFlag(curr) AND getFlag(getNext(curr))) THEN
size=getSize(curr)+getSize(getNext(curr))+METALEN
setSize(curr,size)
next=getNext(getNext(curr))
setNext(curr,next)
ENDIF
curr=getNext(curr)
ENDWHILE
END
!------------------------------------!
PROC free(POINTER ptr)
POINTER curr
BEGIN
IF ptr>=MEMSTART AND ptr<=MEMEND THEN
curr=ptr
curr=curr-METALEN
setFlag(curr,FRED)
merge()
WRTLN("+ Block freed, space merged")
ELSE
WRTLN("Please provide a valid allocated pointer")
ENDIF
END
!====================================!
! End of Library
ENDFILE
}}}
{{{
INCLUDE TERMINAL.LIB
INCLUDE ALLOC.LIB
MAIN()
POINTER p,r,k
POINTER q,w
BEGIN
freList=MEMSTART
p=alloc(100*INTSZ)
q=alloc(250*BYTSZ)
r=alloc(1000*INTSZ)
free(p)
w=alloc(700)
free(r)
k=alloc(500*INTSZ)
CR() WRTLN("Allocation and deallocation")
WRTLN("are done successfully!")
END
}}}