From c53ca56775e52036b59ece3d69fb8c2e4da2d7cf Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 13 Jul 2023 10:49:49 -0700 Subject: [PATCH] Print memory size left --- cli/uxnvm/uxnvm.tal | 56 ++++++++++++++++++++++----------------------- cli/uxnvm/vm.tal | 8 +++---- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cli/uxnvm/uxnvm.tal b/cli/uxnvm/uxnvm.tal index a121793..68d7967 100644 --- a/cli/uxnvm/uxnvm.tal +++ b/cli/uxnvm/uxnvm.tal @@ -13,7 +13,7 @@ @on-reset ( -> ) .Console/type DEI ?&>has-arg - ;Dict/usage + ;dict/usage &err #010f DEO BRK &>has-arg ;on-waitsrc .Console/vector DEO2 @@ -24,7 +24,8 @@ BRK @on-ready ( -> ) - ;src load-rom reset run #800f DEO + + ;src load-rom run #800f DEO BRK ( @@ -32,21 +33,17 @@ @load-rom ( filename* -- ) .File/name DEO2 - #fff0 ;rom/reset SUB2 .File/length DEO2 + #fff0 ;rom/reset SUB2 DUP2 .File/length DEO2 ;rom/reset .File/read DEO2 - .File/success DEI2 #fff0 ;rom/reset SUB2 EQU2 ?&err-overflow - .File/success DEI2 #0000 EQU2 ?&err-empty - JMP2r - &err-empty ( -- ) - ( TODO ) JMP2r - &err-overflow ( -- ) - ( TODO ) JMP2r + .File/success DEI2 SUB2 + ;dict/bytes-free ! @run ( -- ) [ LIT2 00 -emu/sleep ] STZ #0000 &w ( -- ) - step .uxn/err LDZ ?&err + POP + .uxn/err LDZ ?&err .emu/sleep LDZ ?&end INC2 ORAk ?&w &end POP2 @@ -56,6 +53,10 @@ #00 ;rst/ptr STA JMP2r +@halt ( opcode -- opcode ) + #01 .emu/sleep STZ + JMP2r + @send ( v* p* -- ) NIP ( | handlers ) @@ -77,10 +78,6 @@ #0a18 DEO JMP2r -@halt ( opcode -- ) - #01 .emu/sleep STZ - JMP2r - ( @|stdlib ) @@ -91,14 +88,13 @@ POP2 #01 JMP2r @scap ( str* -- end* ) - !&a + !& &w ( -- ) - INC2 &a LDAk ?&w + INC2 & LDAk ?&w JMP2r @sput ( chr str* -- ) - scap INC2k #00 ROT ROT STA - STA + scap/ ROT #00 SWP2 STA2 JMP2r @ ( short* -- ) @@ -109,22 +105,26 @@ #0f AND DUP #09 GTH #27 MUL ADD LIT "0 ADD #18 DEO JMP2r -@ ( err* -- ) - !&a - &w ( -- ) - LDAk #19 DEO - INC2 &a LDAk ?&w - POP2 JMP2r - @ ( str* -- ) &w ( -- ) - LDAk #18 DEO + LDAk #19 DEO INC2 LDAk ?&w POP2 JMP2r +@ ( short* -- ) + #2710 [ LIT2r 00fb ] + &w ( -- ) + DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip + DUP LIT "0 ADD #19 DEO + INCr &>skip + POP2 #000a DIV2 SWPr INCr STHkr ?&w + POP2r POP2 POP2 JMP2r + ( @|res ) -@Dict &usage "usage: 20 "uxnvm.rom 20 "game.rom 0a $1 +@dict &usage "usage: 20 "uxnvm.rom 20 "game.rom 0a $1 + &bytes-free 20 "bytes 20 "free. 0a $1 + ~vm.tal diff --git a/cli/uxnvm/vm.tal b/cli/uxnvm/vm.tal index eb494b5..5f70796 100644 --- a/cli/uxnvm/vm.tal +++ b/cli/uxnvm/vm.tal @@ -1,14 +1,14 @@ ( emulator ) -@reset ( -- ) +@ ( -- ) #00 .uxn/err STZ #0100 .uxn/pc STZ2 #0000 ;wst/ptr STA2 #0000 ;rst/ptr STA2 - #0000 ;step/cycles STA2 + #0000 ;/cycles STA2 JMP2r -@step ( -- ) +@ ( -- ok ) ( get opcode ) .uxn/pc LDZ2 ;rom ADD2 LDA ( exit on BRK ) DUP #00 EQU ?halt ( move PC ) .uxn/pc LDZ2k INC2 ROT STZ2 @@ -20,7 +20,7 @@ ( get routine ) #00 OVR #1f AND DUP2 ADD2 ;optbl ADD2 LDA2 JSR2 ( incr time ) [ LIT2 &cycles $2 ] INC2 ,&cycles STR2 ( check err ) .uxn/err LDZ ?halt - POP JMP2r + JMP2r ( @|primitives )