mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 03:28:07 +11:00
2d17b4e8ec
I'm not sure why I chose null-terminated initially. Probably because the z80asm version had null-terminated strings. Length-prefixes strings are the traditional form of strings in Forth and it's a bit easier to work with them with traditional forth words when they're under this form.
11 lines
347 B
Plaintext
11 lines
347 B
Plaintext
: (parseb) ( a -- n f )
|
|
( '0': ASCII 0x30 'b': 0x62 0x6230 )
|
|
DUP 1+ @ 0x6230 = NOT IF 0 EXIT THEN ( a 0 )
|
|
( We have "0b" prefix )
|
|
DUP C@ ( a len )
|
|
0 SWAP 1+ ( len+1 ) 3 DO ( a r )
|
|
OVER I + C@ ( a r c ) _ ( a r n )
|
|
DUP 0< IF 2DROP 0 UNLOOP EXIT THEN
|
|
SWAP 1 LSHIFT + ( a r*2+n ) LOOP
|
|
NIP 1 ;
|