From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: Re: Emu48 <-> Ascii programs
Date: 28 Aug 1998 03:05:14 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 199
Message-ID: <6s56pa$7v3$1@news.iastate.edu>
References: <35CE257B.83095A9B@sti.com.br>,<6r87af$nev$2@news.iastate.edu>,<6rhl9v$kl3$1@news.iastate.edu>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:15140

Late-breaking improvements:

o Create and use "%%HP: ..." headers exactly like Kermit.

o Parse input text exactly like Kermit.

-------------

The following functions, in conjunction with the
"Load object" and "Store object" operations, allow
Emu48 to import or export programs "in ascii mode,"
just as Kermit does with a real HP48; similarly,
they can be employed to allow a real HP48 to use
XModem for ascii file transfers, if desired.

If you load an ascii program file (which may
include a standard Kermit header "%%HP: ...")
onto the stack, then the 'URpl' function does exactly
what Kermit would do during RECV, and the result will
be the correctly imported User-RPL program or object.

Conversely, if you have a User-RPL program on the stack,
then the 'URpl' function will do what Kermit would do during
SEND (including prefixing a header "%%HP: ..."), allowing
you to store the result as an ascii file; actually,
"Store object" (or XModem) stores a binary object file
corresponding to this string, but if you delete the
first 13 characters of the stored file (HPHP48-xyyyyy),
then what remains is the desired exported pure ascii text,
beginning with "%%HP: ..."

Although a real HP48, using Kermit, can import and export
(in ascii mode) only User-RPL programs, we have included
an extra function 'SRpl', which extends this ability
to SysRPL/ML programs as well, provided that you have
already installed Jazz on your Emu48; you can use 'SRpl'
exactly like 'URpl', whenever the ascii text
is a Jazz source file, or when a program
to be exported is not in User-RPL.

Two internal functions, 'ImpT' (import text) and
'ExpT' (export text) are also provided; these are the
functions which do ascii translations like Kermit,
creating or obeying any "%%HP: ..." headers,
but skipping the compiling and decompiling.

'ImpT' may be used by itself to import text files
which do not represent programs or other objects;
'ExpT' may be used likewise for plain text export
(quote the text if future compatibility with Kermit is desired).


Notes:

If a text file does not represent exactly one HP48 object,
e.g. "1 2 3", then HP48 Kermit imports the objects, enclosed
within a "secondary" (a program without visible delimiters);
this behavior is duplicated by our functions.  In addition,
text such as "CLVAR" (a command)  or "IOPAR" (a name) will be
imported *without* evaluation; this is somewhat more desirable
than would be the result of using OBJ->  :)

The program file below is just such a case; importing it
with Kermit on your real HP48 produces one program
(without program delimiters), which you must evaluate
to run it; the same will occur if you use these
functions to import the text below into Emu48.

Several *unsupported* entry points are used, of which some
have been verified to be stable in versions D, M, and R
(all have been tested on my own versions M and R);
test first in an inconspicuous area if your version differs :)

Many thanks to Dan Kirkland for thoroughly explaining
PTR 25934 in 'Re: "palparse" question' 1996/07/03
<http://www.dejanews.com/getdoc.xp?AN=163446782>
and to Eric Rechlin for creating his own SysRPL program
along similar lines, at his hpcalc.org site.

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
-----------------------------------------------------------

%%HP: T(3); @ Ascii translations are used herein, per User's Guide

@ Functions to assist with Emu48, importing/exporting text files
@ (useful only with *binary* mode text transfers or object loads);
@ also usable for XModem (binary) transfers of text files.

@ Download or type in the following; execute to store variables
@ (to get this into Emu48 to begin with, download to real HP48,
@ upload in *binary* to PC, then load into Emu48, then execute).

@ Caution: All system addresses are shown in hex;
@          incorrect addresses or arguments may cause memory loss.

@ Caution: Uses unsupported entry points!


@ Functions which act as does Kermit during ascii SEND/RECV,
@ including [de]compiling (of *either* User-RPL or SysRPL/ML):

\<< @ For User-RPL programs only:
  DUP TYPE 2 == @ String?
  { ImpT #238A4h SYSEVAL #3AC0h SYSEVAL SAME @ palparse FALSE
    { DROP2 STR\-> } IFT DUP #25934h SYSEVAL DROP2 DROP @ Unsupported!
  } @ Import text and parse as does Kermit [thanks to Dan Kirkland]
  { -55 CF QUOTE #15A0Eh SYSEVAL @ SysRPL: EDITDECOMP$
    ExpT } IFTE @ Convert to text, then export
\>> 'URpl' STO @ Arbitrary variable name

\<< @ For SysRPL programs only (requires Jazz library):
  DUP TYPE 2 == @ String?
  { ImpT DUP 1 9 SUB @ Handle a quoted internal string
    DUP "C$ " POS SWAP 34 CHR POS + { STR\-> } IFT "ASS" STR\->
  } @ Import text and assemble
  { -55 CF "DIS" STR\-> "C$ $" 10 CHR + SWAP + @ Quote entire text
    ExpT } IFTE @ Disassemble to text, then export
\>> 'SRpl' STO @ Arbitrary variable name


@ Ascii translation functions alone (without [de]compiling):


\<< @ Ascii translation after importing a string
    @ (may also be used on non-program text file):

  -55 CF @ Enable "Last Arguments"

  3 TRANSIO @ A generally satisfactory assumption for
  @ importing text ( but "every rule has exceptions" :)


  @ Process (or remove) any header used for Kermit
  @ (uncomment one of the following two alternatives):

  @ " T(x)A(x)F(x)" ==> TRUE/FALSE (sets indicated modes)
    DUP 1 9 SUB "%%HP:" POS DUP
    { 5 + 7 ALOG SUB DUP ";" POS DUP2 1 + 7 ALOG SUB
      ROT ROT 1 - 1 SWAP SUB #30477h SYSEVAL } IFT DROP
  @ Unsupported entry point (but ok for versions D,M,R)

  @ Following just removes header; you must set modes manually:
  @ DUP 1 9 SUB "%%HP:" POS { DUP ";" POS 1 + 7 ALOG SUB } IFT


  @ Do the ascii (input) translations ( SysRPL: KINVISLF &$ )
  DUP TYPE 2 == { #3016Bh SYSEVAL + } IFT

\>> 'ImpT' STO @ Arbitrary variable name

\<< @ Ascii translation before exporting a string
    @ (string needs to be quoted if not User-RPL):

  -55 CF @ Enable "Last Arguments"

  @ Strings that aren't User-RPL should generally be quoted
  @ (especially if a Kermit header is prefixed below)

  3 TRANSIO @ Avoid any non-ascii symbols (i.e. translate all)
  @ (adjust for your own system and environment)
  @ (should agree with the mode in the following Kermit header)


  @ Prefix a Kermit header (optional)
  @ (uncomment one of the following two alternatives):

  @ Generate " T(x)A(x)F(x)" (according to current flags and IOPAR)
    "%%HP:" #303ACh SYSEVAL + ";" + 10 CHR + SWAP +
  @ Unsupported entry point (but ok for versions D,M,R)

  @ Basic header only; you must set modes manually:
  @ "%%HP: T(3);" 10 CHR + SWAP +


  @ Do the ascii (output) translations ( SysRPL: KVISLF )
    DUP TYPE 2 == { #2FEC9h SYSEVAL } IFT
  @ This also inserts carriage-returns before linefeeds,
  @ which suits MS-DOS/Windows, but not Unix/Linux;
  @ use address #2FEDDh instead (KVIS) for no <CR>s

  @ When you export a string as a *binary* object, you will
  @ get a 13-byte prefix (HPHP48-?xxxxx) on your computer;
  @ if you subsequently edit the file on your computer,
  @ don't forget to delete these first 13 characters!
  @ (also any trailing nulls, in case XModem is used).

\>> 'ExpT' STO @ Arbitrary variable name

@ Re-arrange variables:
{ URpl SRpl ImpT ExpT } ORDER

@ End of downloadable object
@ (execute and then discard it to create above set of programs)
@ (upload in *binary* to Emu48 *before* executing)

@ Object (*before* execution): 718.5 bytes, #7AD3h
@ Stored objects after execution: 634 bytes (total)
