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

If Emu48 can directly transfer only binary objects
between its stack and the computer disk, then people
who want to transfer ascii programs (as text files)
need some additional functions to do this.

Previous posts offered several independent small programs
to do separate steps which might be useful in these tasks.

Eric Rechlin conceived of making a "universal"
program (EMU48ASC) which would do everything, but
when it was sent to me just recently, I noticed
some things which we might want to adjust:

o Handles User-RPL only (what about SysRPL/ML programs?)

o Decompiles programs without ensuring STD number display
  mode and binary wordsize of 64 (this may truncate some values,
  depending upon current settings and program contents).

o Assumes some modes which various users might rather
  adjust for themselves (but program is in SysRPL
  and no source is provided in zip file).

o Can be improved through use of additional system functions,
  which I had not previously researched.

So, I have listed below another package of functions,
in User-RPL (so that everyone can understand and
adjust it for their own purposes), borrowing Eric's
idea to try to combine functions as much as possible,
but still allowing for the above flexibility.

This package contains four functions:

o User-RPL import/export (uses text conversions below).
o SysRPL   import/export (uses text conversions below).
o Text conversion for import (into HP48 or emulator).
o Text conversion for export (from HP48 or emulator).

The basic idea is that since you can't use Kermit
to do "load/store object" between Emu48 and the disk,
we do what Kermit would otherwise have done
when transferring files in "ascii" mode.

The files which these functions can read or produce should
be compatible with a real HP48 and Kermit, so that a
real HP48 and the emulator may be used interchangeably.

Additional system entry points are available (see comments
in listing) to make sure that the current modes are output
and restored, using standard "%%HP:..." ascii headers,
just as occurs when using Kermit; however, since these
entry points are not supported (and I have not found out
whether they are compatible with older ROM versions),
I have left these as comments, for you to use only if
you are sure that they are compatible with your calc.

The program as listed below should work with all ROM versions;
if you have version M thru R, then you can enable the additional
features as well, as noted in the comments.

Anyone have info whether these entry points have been
the same in other ROM versions?  S/SX?  Thanks!

I hope this is of some benefit to Emu48 users
(which doesn't include me as yet :)

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


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)
