summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBALATON Zoltan <balaton@eik.bme.hu>2023-01-13 22:25:09 +0100
committerMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>2023-01-26 19:46:15 +0000
commit9711c61be48330a9152593a3f36eda957b105c1f (patch)
treef241c7b563ac64c502e94a54c6370c5df7a1fe62
parent1be046b64176206bc5b743f528c61e10dde73de4 (diff)
downloadqemu-openbios-9711c61be48330a9152593a3f36eda957b105c1f.tar.gz
Generalise parse-hex
Add parse-nhex word reusing existing parse-ints and use that in parse-hex instead of an independent implementation. The parse-nhex name matches Apple OF, while SLOF calls the same operation hex-decode-unit so adding this word increases compatibility with other OF implementations. Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
-rw-r--r--forth/device/package.fs29
-rw-r--r--forth/lib/string.fs36
2 files changed, 34 insertions, 31 deletions
diff --git a/forth/device/package.fs b/forth/device/package.fs
index 1e01e202..f83ef7ac 100644
--- a/forth/device/package.fs
+++ b/forth/device/package.fs
@@ -212,35 +212,6 @@ defer find-dev
left-split
;
-\ parse ints "hi,...,lo" separated by comma
-: parse-ints ( str len num -- val.lo .. val.hi )
- -rot 2 pick -rot
- begin
- rot 1- -rot 2 pick 0>=
- while
- ( num n str len )
- 2dup ascii , strchr ?dup if
- ( num n str len p )
- 1+ -rot
- 2 pick 2 pick - ( num n p str len len1+1 )
- dup -rot - ( num n p str len1+1 len2 )
- -rot 1- ( num n p len2 str len1 )
- else
- 0 0 2swap
- then
- $number if 0 then >r
- repeat
- 3drop
-
- ( num )
- begin 1- dup 0>= while r> swap repeat
- drop
-;
-
-: parse-2int ( str len -- val.lo val.hi )
- 2 parse-ints
-;
-
\
\ 5.3.4.4 Mapping tools
diff --git a/forth/lib/string.fs b/forth/lib/string.fs
index f97db232..be774910 100644
--- a/forth/lib/string.fs
+++ b/forth/lib/string.fs
@@ -122,10 +122,42 @@
\ string to number conversion
\ -----------------------------------------------------
-: parse-hex ( str len -- value )
- base @ hex -rot $number if 0 then swap base !
+\ parse ints "hi,...,lo" separated by comma
+: parse-ints ( str len num -- val.lo .. val.hi )
+ -rot 2 pick -rot
+ begin
+ rot 1- -rot 2 pick 0>=
+ while
+ ( num n str len )
+ 2dup ascii , strchr ?dup if
+ ( num n str len p )
+ 1+ -rot
+ 2 pick 2 pick - ( num n p str len len1+1 )
+ dup -rot - ( num n p str len1+1 len2 )
+ -rot 1- ( num n p len2 str len1 )
+ else
+ 0 0 2swap
+ then
+ $number if 0 then >r
+ repeat
+ 3drop
+
+ ( num )
+ begin 1- dup 0>= while r> swap repeat
+ drop
;
+: parse-2int ( str len -- val.lo val.hi )
+ 2 parse-ints
+;
+
+: parse-nhex ( str len num -- values )
+ base @ >r hex parse-ints r> base !
+;
+
+: parse-hex ( str len -- value )
+ 1 parse-nhex
+;
\ -----------------------------------------------------
\ miscellaneous functions