77 lines
2.3 KiB
Tal
77 lines
2.3 KiB
Tal
|
%NL { #0a18 DEO }
|
||
|
%SP { #2018 DEO }
|
||
|
%WR { #18 DEO }
|
||
|
%HX { ;emit/short JSR2 }
|
||
|
|
||
|
|0000
|
||
|
@arena $2
|
||
|
@saved $2
|
||
|
|
||
|
|0100
|
||
|
( initialize arena: 16 cells x 4 bytes each )
|
||
|
LIT "i WR LIT "n WR LIT "i WR LIT "t WR NL
|
||
|
#0040 #0004 ;init-arena JSR2 .arena STZ2
|
||
|
|
||
|
( display the metadata about the arena )
|
||
|
LIT "h WR LIT "e WR LIT "a WR LIT "d WR LIT "e WR LIT "r WR LIT "s WR SP
|
||
|
.arena LDZ2 ;arena-item JSR2 HX SP
|
||
|
.arena LDZ2 ;arena-next JSR2 HX SP
|
||
|
.arena LDZ2 ;arena-data JSR2 HX SP
|
||
|
.arena LDZ2 ;arena-header JSR2 HX NL
|
||
|
|
||
|
( start allocating, addresses should increase in steps of 4 )
|
||
|
LIT "a WR LIT "l WR LIT "l WR LIT "o WR LIT "c WR SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX NL
|
||
|
|
||
|
( clear the arena )
|
||
|
LIT "c WR LIT "l WR LIT "e WR LIT "a WR LIT "r WR NL
|
||
|
.arena LDZ2 ;clear-arena JSR2
|
||
|
|
||
|
( allocate again, addresses should be the same as before )
|
||
|
LIT "a WR LIT "l WR LIT "l WR LIT "o WR LIT "c WR SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX NL
|
||
|
|
||
|
( clear again )
|
||
|
LIT "c WR LIT "l WR LIT "e WR LIT "a WR LIT "r WR NL
|
||
|
.arena LDZ2 ;clear-arena JSR2
|
||
|
|
||
|
( use alloc-of, addresses should be the same as above )
|
||
|
LIT "a WR LIT "l WR LIT "l WR LIT "o WR LIT "c WR LIT "- WR LIT "o WR LIT "f WR SP
|
||
|
#0004 ;alloc-of JSR2 HX SP
|
||
|
#0004 ;alloc-of JSR2 HX SP
|
||
|
#0004 ;alloc-of JSR2 HX SP
|
||
|
#0004 ;alloc-of JSR2 HX NL
|
||
|
|
||
|
( keep allocating, save one allocated address to use later )
|
||
|
LIT "a WR LIT "l WR LIT "l WR LIT "o WR LIT "c WR SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 DUP2 .saved STZ2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX NL
|
||
|
|
||
|
( free the saved address )
|
||
|
LIT "f WR LIT "r WR LIT "e WR LIT "e WR NL
|
||
|
.saved LDZ2 ;free JSR2
|
||
|
|
||
|
( continue allocating, should see free address and then unused one )
|
||
|
LIT "a WR LIT "l WR LIT "l WR LIT "o WR LIT "c WR SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX SP
|
||
|
.arena LDZ2 ;alloc JSR2 HX NL
|
||
|
|
||
|
( done, so exit )
|
||
|
#010f DEO BRK
|
||
|
|
||
|
@emit
|
||
|
&short SWP ,&byte JSR
|
||
|
&byte DUP #04 SFT ,&char JSR
|
||
|
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
|
||
|
JMP2r
|
||
|
|
||
|
~alloc.tal
|