Hello,
Both Apple OF and SLOF has words to parse hex numbers from comma separated strings which is easily implemented using existing parse-ints word. Doing that removes some duplicated implementations and makes it easy to add compatibility words for Mac FCode ROMs.
Originally I've also proposed to rename the existing parse-hex to patse-1hex as it does not matter what it's called as parse-hex is not standard. I still think that would be simpler but this series keeps that word and only adds another parse-1hex for ppc/qemu specifically. That patch renaming patse-hex could still be resurrected if needed.
Regards, BALATON Zoltan
BALATON Zoltan (3): Generalise parse-hex Use parse-nhex arch/ppc/qemu: Add parse hex words for compatibility with Apple OF
arch/ppc/qemu/qemu.fs | 8 ++++++++ arch/sparc64/tree.fs | 6 +----- drivers/esp.fs | 6 +----- drivers/sbus.fs | 6 +----- forth/device/package.fs | 29 ----------------------------- forth/lib/string.fs | 36 ++++++++++++++++++++++++++++++++++-- 6 files changed, 45 insertions(+), 46 deletions(-)
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 --- forth/device/package.fs | 29 ----------------------------- forth/lib/string.fs | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/forth/device/package.fs b/forth/device/package.fs index 1e01e20..f83ef7a 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 f97db23..be77491 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
Instead of reimplementing it several times use parse-nhex to decode two hex numbers,
Signed-off-by: BALATON Zoltan balaton@eik.bme.hu --- arch/sparc64/tree.fs | 6 +----- drivers/esp.fs | 6 +----- drivers/sbus.fs | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/arch/sparc64/tree.fs b/arch/sparc64/tree.fs index af8948d..f390f6c 100644 --- a/arch/sparc64/tree.fs +++ b/arch/sparc64/tree.fs @@ -5,11 +5,7 @@ include config.fs \ -------------------------------------------------------------------------
: decode-unit-upa ( str len -- id lun ) - ascii , left-split - ( addr-R len-R addr-L len-L ) - parse-hex - -rot parse-hex - swap + 2 parse-nhex ;
: encode-unit-upa ( id lun -- str len) diff --git a/drivers/esp.fs b/drivers/esp.fs index 9e37c0a..ebf0769 100644 --- a/drivers/esp.fs +++ b/drivers/esp.fs @@ -3,11 +3,7 @@ \ -------------------------------------------------------------------------
: decode-unit-scsi ( str len -- id lun ) - ascii , left-split - ( addr-R len-R addr-L len-L ) - parse-hex - -rot parse-hex - swap + 2 parse-nhex ;
: encode-unit-scsi ( id lun -- str len) diff --git a/drivers/sbus.fs b/drivers/sbus.fs index b84a3ac..9aa51e2 100644 --- a/drivers/sbus.fs +++ b/drivers/sbus.fs @@ -3,11 +3,7 @@ \ -------------------------------------------------------------------------
: decode-unit-sbus ( str len -- id lun ) - ascii , left-split - ( addr-R len-R addr-L len-L ) - parse-hex - -rot parse-hex - swap + 2 parse-nhex ;
: encode-unit-sbus ( id lun -- str len)
Apple OF has parse-1hex, parse-2hex, parse-3hex words that may be used by FCode ROMs so add these for compatibility
Signed-off-by: BALATON Zoltan balaton@eik.bme.hu --- arch/ppc/qemu/qemu.fs | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/ppc/qemu/qemu.fs b/arch/ppc/qemu/qemu.fs index d683421..7211d2d 100644 --- a/arch/ppc/qemu/qemu.fs +++ b/arch/ppc/qemu/qemu.fs @@ -95,6 +95,14 @@ variable keyboard-phandle 0 keyboard-phandle ! set-defaults ; PREPOST-initializer
+\ ------------------------------------------------------------------------- +\ Mac OF specific words +\ ------------------------------------------------------------------------- + +: parse-1hex 1 parse-nhex ; +: parse-2hex 2 parse-nhex ; +: parse-3hex 3 parse-nhex ; + \ ------------------------------------------------------------------------- \ copyright property handling \ -------------------------------------------------------------------------
On 13/01/2023 21:25, BALATON Zoltan wrote:
Hello,
Both Apple OF and SLOF has words to parse hex numbers from comma separated strings which is easily implemented using existing parse-ints word. Doing that removes some duplicated implementations and makes it easy to add compatibility words for Mac FCode ROMs.
Originally I've also proposed to rename the existing parse-hex to patse-1hex as it does not matter what it's called as parse-hex is not standard. I still think that would be simpler but this series keeps that word and only adds another parse-1hex for ppc/qemu specifically. That patch renaming patse-hex could still be resurrected if needed.
Regards, BALATON Zoltan
BALATON Zoltan (3): Generalise parse-hex Use parse-nhex arch/ppc/qemu: Add parse hex words for compatibility with Apple OF
arch/ppc/qemu/qemu.fs | 8 ++++++++ arch/sparc64/tree.fs | 6 +----- drivers/esp.fs | 6 +----- drivers/sbus.fs | 6 +----- forth/device/package.fs | 29 ----------------------------- forth/lib/string.fs | 36 ++++++++++++++++++++++++++++++++++-- 6 files changed, 45 insertions(+), 46 deletions(-)
Thanks - I've given this a test with the SPARC64 UPA device and it still works as expected, so assuming there are no other comments, I'll push to master over the weekend.
ATB,
Mark.
On 26/01/2023 22:16, Mark Cave-Ayland wrote:
On 13/01/2023 21:25, BALATON Zoltan wrote:
Hello,
Both Apple OF and SLOF has words to parse hex numbers from comma separated strings which is easily implemented using existing parse-ints word. Doing that removes some duplicated implementations and makes it easy to add compatibility words for Mac FCode ROMs.
Originally I've also proposed to rename the existing parse-hex to patse-1hex as it does not matter what it's called as parse-hex is not standard. I still think that would be simpler but this series keeps that word and only adds another parse-1hex for ppc/qemu specifically. That patch renaming patse-hex could still be resurrected if needed.
Regards, BALATON Zoltan
BALATON Zoltan (3): Generalise parse-hex Use parse-nhex arch/ppc/qemu: Add parse hex words for compatibility with Apple OF
arch/ppc/qemu/qemu.fs | 8 ++++++++ arch/sparc64/tree.fs | 6 +----- drivers/esp.fs | 6 +----- drivers/sbus.fs | 6 +----- forth/device/package.fs | 29 ----------------------------- forth/lib/string.fs | 36 ++++++++++++++++++++++++++++++++++-- 6 files changed, 45 insertions(+), 46 deletions(-)
Thanks - I've given this a test with the SPARC64 UPA device and it still works as expected, so assuming there are no other comments, I'll push to master over the weekend.
As there were no further comments, I've now pushed this to master.
ATB,
Mark.