Ascii Import/Export for SD card and Emulator

1402 views
Skip to first unread message

John H Meyers

unread,
May 27, 2007, 10:28:54 AM5/27/07
to
The question keeps coming up about how to transfer
UserRPL programs, from text files on a computer,
especially when using an SD card,
and the same situation when using an emulator.

When source text files are transmitted over a cable,
the designed-in file transfer system kicks in,
translating special-character representations
("backslash codes" for 8-bit, non-universal characters)
and compiling the text automatically into an actual program,
also using a file header to preserve modes affecting the
interpretation of the file, as explained in:

http://groups.google.com/group/comp.sys.hp48/msg/52e9cc3ee2b369b8

However, when you put the source text files on an SD card
(or drop/paste them onto the emulator stack as strings),
any PC text file from an SD card just sits there,
as a string on the stack, waiting for translation help,
like a lost foreign child in an airport waiting room :)

Here is a very simple program to provide that help,
on all HP48/49/50 (real or emulated); note that
you must first *remove* any "%%HP: T()A()F();" header
(which indicates calc modes, and isn't part of the program);
you can easily do this on the calc itself, using the editor.

@ 7-bit ascii string -> calc object
\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + STR\-> \>> 'IN' STO

Here is an equally simple program to do the reverse,
i.e. to make a string for posting or to save on computer
or SD card, to represent the object on the stack:

@ Calc object -> 7-bit ascii string
\<< STD 64 STWS \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Fh #2FEC9h IFTE SYSEVAL \>> 'OUT' STO

If you are using Linux and don't want "CRLF" line endings,
change the last system addresses to #2F34Eh and #2FEDDh

Make a memory backup, of course, before using the above!
(the exact binary addresses are very critical)

What's lacking in the above simple programs:

o Doesn't accept or generate "%%HP: T()A()F();" file headers

o Unprotected - executes all commands, etc.

o Gets "Invalid Syntax" when used on anything that
isn't UserRPL (e.g. SysRPL, or any other kind of text).

What's below is a more complete system, including:

IN like above, but accepts "%%HP: T()A()F();" headers
INX like IN, but safer (doesn't execute/evaluate)

OUT like above, doesn't create "%%HP: T()A()F();" header
OUTX like OUT, but includes "%%HP: T()A()F();" header

The above, in turn, call upon the following:

KINV character translation only, for PC -> calc (IN)
KVIS character translation only, for calc -> PC (OUT)
KHIN function that accepts "%%HP: T()A()F();" header
KHOUT function that creates "%%HP: T()A()F();" header
STRC replaces STR\-> (doesn't execute/evaluate commands)

Special additional function:

KQP - Quoted-Printable encoding corrector for email/postings
(enables importing "Original" from over-processed postings);
use first, before IN or any other function.

STRC and KQP are elaborated in detail at:
http://groups.google.com/group/comp.sys.hp48/browse_thread/thread/b2623cb1ed61104a

KHIN & KHOUT are provided below in both pure UserRPL (longer)
and a shorter version using unsupported (but probably stable)
internal functions invoked via SYSEVAL; STRC is provided both
in pure SysRPL (recommended) and UserRPL (less rigorous).

How to transfer stuff between computer, emulator, and calc:

Transfer from computer (or SD card) to emulator:

o Drag stored binary *or* text files to emulator window
(or use "Load object").

o Text that has first been copied into clipboard
can be put directly on stack via "Paste string/stack"

Transfer from emulator to computer or to SD card:

o Text that is on stack can be copied directly to clipboard
using "Copy string/stack," and then pasted from clipboard
into text files, emails, or postings.

o "Save object" can be used directly to SD card,
if the emulated calc is HP50/49/new48 series

Transfer from calc to SD card (storing text onto SD card):

o The calculator inserts "HPHP4x-y" before *all* objects
that are stored, just as does the emulator's "Save object"
function (which stores objects as *binary* internal files);
for string objects, the next five bytes are also not part
of the string, and should be deleted when editing on PC.

o If you happen to have your emulator running on the PC,
you can first drag from SD card or "Load object"
to the emulator, then "Copy string/stack" from emulator
to PC clipboard, then paste clipboard into documents.

The entire file below (with "@" preceding comments)
is downloadable by the original *short* IN program above
(just remove the header line first),
so don't waste any time typing it manually!

Caution:

Programs using SYSEVAL could corrupt or wipe out
calc memory if entered incorrectly; make memory backups
before using any of these programs (including those above).

%%HP: T(3); @ Header for ascii file transfer only

@ This file is for all HP48/49/50

@ KHIN and KHOUT (optional ascii header functions)
@ are available as pure UserRPL, or using
@ "unsupported but probably stable" entry points
@ (the latter versions are much shorter).

@ STRC (compile without evaluating)
@ is also available in SysRPL (short) or UserRPL (long)

@ Complete Input system:

@ Ascii string -> translate, compile, evaluate
\<< KINV STR\-> \>> 'IN' STO

@ Ascii string -> translate, compile, *don't* execute
\<< KINV STRC \>> 'INX' STO

@ 7-bit ascii string -> translate to internal 8-bit
@ Accepts optional "%%hp: T()A()F();" header
\<< \->STR 3 TRANSIO KHIN RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + \>> 'KINV' STO

@ Process and remove "%%hp: T()A()F();" header
@ (UserRPL version)
@ (leaves modes set as specified in header)
\<< \->STR DUP 1 64 SUB "%%" "HP:" +
POS { DUP 1 OVER ";" POS SUB
DUP "T(0)" POS { 0 TRANSIO } IFT
DUP "T(1)" POS { 1 TRANSIO } IFT
DUP "T(2)" POS { 2 TRANSIO } IFT
DUP "T(3)" POS { 3 TRANSIO } IFT
DUP "A(D)" POS { DEG } IFT
DUP "A(R)" POS { RAD } IFT
DUP "A(G)" POS { GRAD } IFT
DUP "F(.)" POS { -51 CF } IFT
DUP "F(,)" POS { -51 SF } IFT
SIZE 1 + OVER SIZE SUB } IFT \>> 'KHIN' STO

@ Process and remove "%%hp: T()A()F();" header,
@ using unsupported (probably stable) entry point
@ (leaves modes set as specified in header)
\<< \->STR DUP 1 64 SUB
DUP ";" POS OVER "%%" "HP:" + POS
DUP2 AND 3 DUPN DROP > AND
{ 5 + SWAP DUP 4 ROLLD 1 - SUB RCLF SIZE 3 >
#25F31h #30477h IFTE SYSEVAL DROP 1 + OVER SIZE SUB }
{ DROP2 DROP } IFTE \>> 'KHIN' STO

@ Replacement for STR\-> (to compile without evaluating)
@ UserRPL version (multiple objects -> list)
@ (less rigorous than SysRPL version)
\<< \->STR "\<<\<<\>>'x'" SWAP + "\>>" + STR\->
#54AFh SYSEVAL #5459h SYSEVAL @ All HP48/49/50
DUP 2 GET OVER 4 GET 2 \->LIST
SWAP 7 OVER SIZE 1 - SUB DUP SIZE 1 > { SWAP
OVER SIZE 1 - DUP SUB OVER 1 DUP SUB SAME { EVAL } }
{ SWAP DROP DUP SIZE { 1 GET } } IFTE IFT \>> 'STRC' STO

@ SysRPL version (multiple objects -> program)
@ [this installs program via hex string, no source here]
@ On original 48[S/G] you must have ASC\-> pre-installed
RCLF SIZE 3 > { @ 49/50 series
"D9D20792628236252133D9D2026FE267"
"943431622715329A4347A2073883FE98" +
"3B21302C230B7650E0E306B65029A432" +
"C23098050A3D63E8F60B2130B2130" +
64 STWS DUP BYTES DROP #13Bh ==
#100001h * LIBEVAL @ built-in H\->
} { 10 CHR @ need ASC\-> on original 48[S/G]
"D9D202BA812BF81D0040D9D204A83201"
"91668F017E126C2A1647A20C94324563" + OVER +
"2B21302C230B7650E0E306B650C2A162" +
"C230980506DC36E8F60B2130B2130F49" + SWAP +
"D" + ASC\-> } IFTE 'STRC' STO

@ Quoted-Printable encoding corrector for email/postings
@ "QP string" -> "Corrected string" (use before IN[X])
\<< 61 CHR \-> e \<< \->STR DUP e "3D" + POS
{ 13 CHR "" SREPL DROP e 10 CHR + "" SREPL DROP
e "3D" + e SREPL DROP } IFT \>> \>> 'KQP'
RCLF SIZE 3 > { STO } { DROP2 } IFTE @ 49/50 series only

@ Complete Output system:

@ Any object -> Ascii string (without header)
\<< DUP TYPE 2 \=/
{ RCLF SIZE 3 > #25ECEh #15A0Eh IFTE SYSEVAL }
IFT KVIS \>> 'OUT' STO

@ Any object -> Ascii string, with "%%hp: T()A()F();"
\<< DUP TYPE 2 == { "C$ $" 10 CHR + SWAP + }
{ RCLF SIZE 3 > #25ECEh #15A0Eh IFTE SYSEVAL }
IFTE KVIS KHOUT \>> 'OUTX' STO

@ "string" -> Ascii (7-bit) output string
\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Fh #2FEC9h IFTE SYSEVAL \>> 'KVIS' STO
@ #2F34Eh #2FEDDh to not insert CR before LF

@ Prefix a header "%%hp: T()A()F();" to string
@ (UserRPL version)
\<< \->STR "%%" "HP: " +
{ "T(0)" "T(1)" "T(2)" "T(3)" } OPENIO CLOSEIO
{ HOME IOPAR } RCL 6 GET 1 + GET +
-17 FS? "A(R)" { -18 FS? "A(G)" "A(D)" IFTE }
IFTE + -51 FS? "F(,)" "F(.)" IFTE +
";" + 10 CHR + SWAP + \>> 'KHOUT' STO

@ Prefix a header "%%hp: T()A()F();" to string,
@ using unsupported (probably stable) entry point
\<< \->STR "%%" "HP:" + RCLF SIZE 3 >
#25F30h #303ACh IFTE SYSEVAL + ";" +
10 CHR + SWAP + \>> 'KHOUT' STO

@ End of downloadable file

Jacko

unread,
Nov 14, 2011, 10:56:36 PM11/14/11
to
D9D20E1632B0BC13F2A2C4022916C18B9C13F2A2D5CE1E4A2051000D43F20000
0000000E4A2051000B610300000000000EF3A1E25A176BA162BC193632B2130C
29E

@ASC\-> 'IN' STO

\<< STD 64 STWS \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Fh #2FEC9h IFTE SYSEVAL \>> 'OUT' STO

@IN

Cheers Jacko

Jacko

unread,
Nov 14, 2011, 11:33:55 PM11/14/11
to
For some reason the Invalid String error can be fixed by importing it from a file with quotes around it, and deleting the extra quote pair in an edit, before ASC\-> 'IN' STO. But now I have the input function IN, I can import things from the desktop emulator. Just what I needed.

With ALG48, HPSauce (mild), QPI, ASC, AKEYS (from ALG48) and 5 SF, I have a setup as useful as my old HP-28 then some. On the Droid48 emulator, the keyword OFF allows the turn off for installing libraries, and by checking save memory on exit, the whole thing is excellent.

Not sure what all the numbers are in the status of HPSauce, looks like TYPE and stack count, (and the W in emu48 maybe port writable?).

CheersJacko

John H Meyers

unread,
Nov 15, 2011, 3:36:08 AM11/15/11
to
On 11/14/2011 9:56 PM, Jacko wrote:

> D9D20E1632B0BC13F2A2C4022916C18B9C13F2A2D5CE1E4A2051000D43F20000
> 0000000E4A2051000B610300000000000EF3A1E25A176BA162BC193632B2130C
> 29E
>
> @ASC\-> 'IN' STO

Is that supposed to be easier to type
(and read, and use, without needing an ASC\-> program) than

\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + STR\-> \>> 'IN' STO

Where, to manually input the above UserRPL,
required for this one single program,
it is best to actually input program delimiters and right-arrow character
from the keyboard, so that no "translation" (other than mental) is needed :)

The reason that ASC\-> complained is that what you originally pasted
included line breaks with CRLF, rather than just LF -- removing
the CR ["black square"] at the end of each line would fix that.

[r->] [OFF]
Reply all
Reply to author
Forward
0 new messages