From de16e334898b974cb0a38461947139935f8983cb Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 28 Oct 2023 09:02:44 -0700 Subject: [PATCH] (stdlib) Added checks for sdec and shex --- cli/stdlib/stdlib.tal | 189 ++++++++++++++++++++++++++++-------------- 1 file changed, 129 insertions(+), 60 deletions(-) diff --git a/cli/stdlib/stdlib.tal b/cli/stdlib/stdlib.tal index fa7559a..7a71528 100644 --- a/cli/stdlib/stdlib.tal +++ b/cli/stdlib/stdlib.tal @@ -1,88 +1,158 @@ |0100 +@on-reset ( -> ) ;tests/end ;tests - &l - LDA2k JSR2 test - INC2 INC2 GTH2k ?&l + &l ( -- ) + LDA2k JSR2 test INC2 INC2 GTH2k ?&l POP2 POP2 - #800f DEO - -BRK + ( debugger ) #010e DEO + ( exit ) #800f DEO + BRK @test ( f -- ) - - #30 ADD #18 DEO #0a18 DEO - -JMP2r - -@tests [ - =test-dec1 =test-dec2 =test-dec3 =test-dec4 - =test-hex1 =test-hex2 =test-hex3 =test-hex4 -] &end + #30 ADD #18 DEO + #0a18 DEO + JMP2r ( @|tests ) - @test-dec1 ;dict/dec1 sdec #1234 EQU2 JMP2r - @test-dec2 ;dict/dec2 sdec #0123 EQU2 JMP2r - @test-dec3 ;dict/dec3 sdec #0000 EQU2 JMP2r - @test-dec4 ;dict/dec4 sdec #0000 EQU2 JMP2r - @test-hex1 ;dict/hex1 shex #12c0 EQU2 JMP2r - @test-hex2 ;dict/hex2 shex #034f EQU2 JMP2r - @test-hex3 ;dict/dec3 sdec #0000 EQU2 JMP2r - @test-hex4 ;dict/dec4 sdec #0000 EQU2 JMP2r +@tests [ + =test-dec1 =test-dec2 =test-dec3 =test-dec4 + =test-hex1 =test-hex2 =test-hex3 =test-hex4 ] &end + +@test-dec1 + ;dict/dec1 sdec #1234 EQU2 JMP2r + +@test-dec2 + ;dict/dec2 sdec #0123 EQU2 JMP2r + +@test-dec3 + ;dict/dec3 sdec #0000 EQU2 JMP2r + +@test-dec4 + ;dict/dec4 sdec #0000 EQU2 JMP2r + +@test-hex1 + ;dict/hex1 shex #12c0 EQU2 JMP2r + +@test-hex2 + ;dict/hex2 shex #034f EQU2 JMP2r + +@test-hex3 + ;dict/dec3 sdec #0000 EQU2 JMP2r + +@test-hex4 + ;dict/dec4 sdec #0000 EQU2 JMP2r ( @|stdlib ) -@pstr ( str* -- ) LDAk ?&w POP2 JMP2r &w LDAk #18 DEO INC2 LDAk ?&w POP2 JMP2r -@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r -@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r -@slen ( str* -- len* ) DUP2 scap SWP2 SUB2 JMP2r -@scat ( src* dst* -- ) scap -@scpy ( src* dst* -- ) OVR2 LDA ?&e POP2 POP2 JMP2r &e STH2 &w LDAk STH2kr STA INC2r INC2 LDAk ?&w POP2 #00 STH2r STA JMP2r -@sclr ( str* -- ) LDAk ?&w POP2 JMP2r &w STH2k #00 STH2r STA INC2 LDAk ?&w POP2 JMP2r -@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ?&e NEQk ?&e POP2 INC2 INC2r !&l &e NIP2 POP2r EQU JMP2r +@scap ( str* -- end* ) + LDAk ?&w + JMP2r + &w ( -- ) + INC2 LDAk ?&w + JMP2r + +@sput ( chr str* -- ) + scap INC2k #00 ROT ROT STA + STA + JMP2r + +@slen ( str* -- len* ) + DUP2 scap SWP2 SUB2 JMP2r + +@scat ( src* dst* -- ) + scap + +@scpy ( src* dst* -- ) + OVR2 LDA ?&e + POP2 POP2 JMP2r + &e STH2 + &w ( -- ) + LDAk STH2kr STA + INC2r INC2 LDAk ?&w + POP2 #00 STH2r STA + JMP2r + +@sclr ( str* -- ) + LDAk ?&w + POP2 JMP2r + &w ( -- ) + STH2k #00 STH2r STA + INC2 LDAk ?&w + POP2 JMP2r + +@scmp ( a* b* -- f ) + STH2 + &l ( -- ) + LDAk LDAkr STHr ANDk #00 EQU ?&e + NEQk ?&e + POP2 INC2 INC2r !&l + &e NIP2 POP2r EQU JMP2r @sdec ( str* -- val* ) - - LIT2r 0000 - &w - LIT2r 000a MUL2r - LITr 00 - LDAk #30 SUB STH ADD2r - INC2 LDAk ?&w - POP2 - STH2r - -JMP2r + [ LIT2r 0000 ] + &w ( -- ) + ( validate ) LDAk [ LIT "0 ] SUB #09 GTH ?&end + ( accumulate ) [ LIT2r 000a ] MUL2r + ( combine ) LDAk [ LIT "0 ] SUB [ LITr 00 ] STH ADD2r + ( continue ) INC2 LDAk ?&w + &end POP2 STH2r JMP2r @shex ( str* -- val* ) - - LIT2r 0000 - &w - LITr 40 SFT2r - LITr 00 - LDAk chex STH ADD2r - INC2 LDAk ?&w - POP2 - STH2r - -JMP2r + [ LIT2r 0000 ] + &w ( -- ) + ( validate ) LDAk chex INC #00 EQU ?&end + ( accumulate ) [ LITr 40 ] SFT2r + ( combine ) LDAk chex [ LITr 00 ] STH ADD2r + ( continue ) INC2 LDAk ?&w + &end POP2 STH2r JMP2r @chex ( c -- val|ff ) + ( dec ) [ LIT "0 ] SUB DUP #09 GTH ?{ JMP2r } + ( hex ) #27 SUB DUP #0f GTH ?{ JMP2r } + ( err ) POP #ff JMP2r - LIT "0 SUB DUP #09 GTH [ JMP JMP2r ] - #27 SUB DUP #0f GTH [ JMP JMP2r ] - POP #ff +( +@|print ) -JMP2r +@ ( str* -- ) + &w ( -- ) + LDAk #18 DEO + INC2 & LDAk ?&w + POP2 JMP2r + +@ ( short* -- ) + SWP /b + &b ( -- ) + DUP #04 SFT /c + &c ( -- ) + #0f AND DUP #09 GTH #27 MUL ADD [ LIT "0 ] ADD #18 DEO + JMP2r + +@ ( short* -- ) + #2710 [ LIT2r 00fb ] + &w ( -- ) + DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{ + DUP [ LIT "0 ] ADD #19 DEO + INCr } + POP2 #000a DIV2 SWPr INCr STHkr ?&w + POP2r POP2 POP2 JMP2r + +@ ( addr* -- ) + #0000 + &l ( -- ) + ADD2k LDA /b + DUP #0f AND #0f NEQ #16 MUL #0a ADD #18 DEO + INC NEQk ?&l + POP2 POP2 JMP2r ( @|assets ) -@dict [ - &dec1 "4660 $1 +@dict &dec1 "4660 $1 &dec2 "291 $1 &dec3 "0 $1 &dec4 "q2x*63? $1 @@ -90,5 +160,4 @@ JMP2r &hex2 "34f $1 &hex3 "0 $1 &hex4 "q2x*63? $1 -]