[OpenBIOS] [RFC v2] Pretty-print reg property

Segher Boessenkool segher at kernel.crashing.org
Thu Nov 4 23:16:08 CET 2010


>>> +    dup my-#acellbytes my-#scellbytes + mod 0= if
>>> +      2dup <> if
>>> +        cr 0 begin ."  " 1+ dup d# 26 >= until drop
>>
>> 26?  Why that?
>
> Indentation of non-first line, adapted from .properties.

Ah I see.

>> Maybe something like this:
>>
>> : .p-reg ( prop len -- )
>>  >r >r my-#scells my-#acells dup r> r> bounds ?DO
>>  2dup = IF cr THEN          \ start of line
>>  dup 0= IF 2 spaces THEN    \ start of "size" part
>>  dup 3 and 0= IF space THEN \ make numbers more readable
>>  i c@ 2 0.r                 \ print byte
>>  1- 3dup nip + 0= IF drop dup THEN  \ update counter
>>  LOOP ;
>>
>> (untested, mind the bogons).
>
> Leads to:
>
> 0 > dev /memory  ok
> 0 > .properties
> name                      "memory"
> device_type               "memory"
> reg
> 00   00
> 00   00
> 40   00
> 00   00
> N?!H                     -- 5 : 4e 80 04 21 48
> available
> 00   00
> 40   00
> 3f   bd
> 40   00
>                            <empty>
>   ok
>
> My patch did:
>
> 0 > dev /memory  ok
> 0 > .properties
> name                      "memory"
> device_type               "memory"
> reg                       00000000 40000000
> available                 00004000 3fbd4000
>   ok
>
> Any hint? My code may have been inefficient but better unstandable for
> a Forth newbie...

I found it quite the opposite -- I'm not a newbie but I found it very
hard to read.  Maybe needs a bit more factoring?

I forgot to multiply acells and scells by 4; also, no indent, and I
put the newlines at the start of the line, not the end (this is normal
in Forth, and has some advantages).  This needs changing here of course.

>> Default for #size-cells is 1, not 2.
>
> Copied from my-#acells. Is it wrong for #address-cells, too?

It is correct for acells.


Segher




More information about the OpenBIOS mailing list