[comp.sys.handhelds] Asc2bin and Bin2asc, too.

kskalb@faui19.informatik.uni-erlangen.de (Klaus Kalb) (02/28/91)

cloos@acsu.buffalo.edu (James H. Cloos) writes:

>Please find below a slightly improved version of asc2bin.c; its improvement
>is the ability to create an ASC format file from a hp48sx binary file.

I've tried to implement bin2asc and run into trouble with binary files
of odd length. Since two nibbles make a byte, those files will have
a zero nibble at their tail to pad them to even length.
ASC\-> can't cope with those padded binary files. It will give you
an invalid string error if it sees such a padded file.

IMHO it's nearly impossible to get this right on the workstation (or PC).
The length (in nibbles) isn't contained in binary files.
So bin2asc must figure out what's the case by itself. It can't simple
drop a trailing zero for there are quite a lot objects ending with
an end token (someting like 03B21) and so there will be a trailing zero
that can't be omitted. And I'm sure that's not the only case...

So there are several possiblities to make this work:

  ---   bin2asc will work correctly only on binary files of even length.
        Then we need a version of ASC\-> that can cope with ASC-strings
        with an additional zero nibble sticked to their end.
        That's the way I currently do it.

  ---   bin2asc must have a profound knowledge of the structure of
        binary files to decide wether the last zero nibble is significant
        or not.
        That's the hard way to do it. IMHO it's impossible to get this right.

  ---   Make bin2asc a part of the assembler. The assembler knows wether it
        has generated an odd or even number of nibbles. So it can do it right.
        That's the way I did it. I had a hacked version of star that could
        generate ASC-output. But I moved to Star 1.04 and didn't have time
        to do the hack again...

  ---   Limit yourself to objects of even length.
        That's a fool's way to do it.

Jim's bin2asc will keep the trailing zero. So it will give you invalid
ASC-strings on objects of odd length.

So I would like to trigger a discussion of this issue.
We (those guys that will move to comp.sys.handhelds.hp48.hackers soon ;-)
should try to find out what's the best way to get around this problem.
A working setup of bin2asc on the host and ASC\-> on the HP48 would be nice.
(read: is what I need)

>I've checked the output of bin2asc vs. hyde.lib, chip225 & its games, and a
>few short things I could type in off the 48's screen and into the Sun.

You obviously never tried an object of odd length, did you ?

>can't use ckermit between the workstations and the 48 just now as I get
>/usr/spool/locks: permission denied errors; w/ luck that could change in
>the future.)    **{Excuse the wordiness, bitte.}**

The Kermit on my SPARC (oops, the SPARC I'm allowed to use) greets me by saying

  Warning, write access to lock directory denied
  C-Kermit, 4E(070) 29 Jan 88, 4.2 BSD
  Type ? for help

and works einfach wunderbar, despite the warning.
(Excuse the german words, bitte. ;-)
Seems you need to contact your friendly local superuser...

>Here is the src:

Thank you, I've tried it. I've found a small bug. (Type of the bug:
"Oh no, I thought I wont never make this foolish mistake again..." ;-)
The diffs are appended to this posting (at the very tail of it)

Here's the modified ASC\-> I mentioned above: (I called it ASC\->\->)
It's not a bright program, but it could serve as a basis for improvements.
It isn't thoroughly tested either, but it ran well on all cases I've 
encountered up to now. Maybe I should have used Derek's HEX\-> instead 
of counting characters.
It needs ASC\-> and the TOOLS-Lib.

 
%%HP: T(3)A(R)F(,);
\<< DUP SIZE RCLF \-> s
l f
  \<< HEX 64 STWS s
    IFERR ASC\->
    THEN DROP s DUP
l 3 - l SUB "
" POS
\-> b
      \<< b 6 5 IFTE
1 l ROT - SUB DUP
DNL CRC # 65536d +
\->STR 4 7 SUB RVRS
        IF 'b AND b
<4'
        THEN DUP 1
b 1 + SUB SWAP b 2
+ 4 SUB "
" SWAP +
+
        END + ASC\->
      \>>
    END f STOF
  \>>
\>>


diffs for bin2asc / asc2bin :


390c390
<       if ( argc <= 1 )
---
>       if ( argc < 1 )
394c394
<       if (argc <= 2 )
---
>       if (argc < 2 )


Keep on hacking, -KK

------------------------------------------------------------------------------
   Klaus Kalb    | mail :  IMMD1 / Martenstr. 3 / W-8520 Erlangen / Germany
 SPARC vs. HP48  | email:  kskalb@immd1.informatik.uni-erlangen.de
------------------------------------------------------------------------------

cloos@acsu.buffalo.edu (James H. Cloos) (02/28/91)

In article <kskalb.667684200@faui19> kskalb@faui19.informatik.uni-erlangen.de (Klaus Kalb) writes:
>cloos@acsu.buffalo.edu (James H. Cloos) writes:
>
[etc.]
>>I've checked the output of bin2asc vs. hyde.lib, chip225 & its games, and a
>>few short things I could type in off the 48's screen and into the Sun.
>
>You obviously never tried an object of odd length, did you ?

Not until today, it seems. ;-(

>>can't use ckermit between the workstations and the 48 just now as I get
>>/usr/spool/locks: permission denied errors; w/ luck that could change in
>>the future.)    **{Excuse the wordiness, bitte.}**
>
>The Kermit on my SPARC (oops, the SPARC I'm allowed to use)
>greets me by saying
>
>  Warning, write access to lock directory denied
>  C-Kermit, 4E(070) 29 Jan 88, 4.2 BSD
>  Type ? for help
>
>and works einfach wunderbar, despite the warning.
>(Excuse the german words, bitte. ;-)
>Seems you need to contact your friendly local superuser...
Yeah.  The responce was to rewrite kermit to ignore the locks.  I used to
get just the warning back on the Sun3's, but those were replaced with SPARC
SLC's earlier.  [SIGH].

And as for the use of the word 'bitte,' I tend to do that every so often
when I'm falling asleep.....

At least asc2bin works right all of the time. (knock on wood).

-JimC
--
James H. Cloos, Jr.		Phone:  +1 716 673-1250
cloos@ACSU.Buffalo.EDU		Snail:  PersonalZipCode:  14048-0772, USA
cloos@ub.UUCP		(Loose)	Quote:  "There was movement detected,
					we reacted, now there is no
					more movement." -USAF spokesman,
					back during 'Shield.