(PC-1211) Engineering format
|
05-10-2022, 02:32 PM
Post: #1
|
|||
|
|||
(PC-1211) Engineering format
Most of the Sharp pocket computers don't have any built in engineering display format, so I whipped up this quickie to somewhat fill this gap. I wrote it on my PC-1211, but it should work on pretty much any model of Sharp that adheres to the INT function always rounding down (i.e. not truncate/round toward zero).
Usage From the keyboard: press SHIFT (or DEF) = to display current input/result in engineering format. Note that attempting to do this in the middle of a running program will terminate the running program. From a program: GOSUB "ENG" to convert X to mantissa and exponent stored in M and E respectively. You can then format these values as desired in your PRINT/USING statements. Code: 1:"="AREAD X:GOSUB "ENG":PRINT M;"E";E:END |
|||
05-10-2022, 05:15 PM
(This post was last modified: 05-10-2022 05:19 PM by Dan C.)
Post: #2
|
|||
|
|||
RE: (PC-1211) Engineering format
Nice! Can i use this on my PC-1262 also? Is the basic in PC-1211 the same as in later SHARP machines, like the PC-1262 and many others?
|
|||
05-10-2022, 05:19 PM
Post: #3
|
|||
|
|||
RE: (PC-1211) Engineering format
Your nifty solution reminds me of the decimal places and scientific display DEF assignments I've used in the past on my Sharp PC-1350 in the 80s:
Code: ' <expr> DEF-S scientific notation with #=? decimal places Works on other Sharp PC, but unfortunately not on the PC-1211. Allows the output to be used as an answer to continue calculations. One of the reasons I kept using the Sharp pocket computers is because it was so easy to add features. Modern advanced calculators like the wonderful HP Prime have everything already built-in of course - Rob "I count on old friends to remain rational" |
|||
05-10-2022, 06:03 PM
Post: #4
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-10-2022 05:15 PM)Dan C Wrote: Nice! Can i use this on my PC-1262 also? Is the basic in PC-1211 the same as in later SHARP machines, like the PC-1262 and many others? Yup! I just typed it in on my 1261 to test (it's basically identical to the 1262). I think this will work on nearly any Sharp, though the "=" label depends on having the user-definable keys and AREAD available, which a few models lack (PC-E500, Sharp Wizard BASIC cards...). The GOSUB routine probably would still work the same, though. (05-10-2022 05:19 PM)robve Wrote: Your nifty solution reminds me of the decimal places and scientific display DEF assignments I've used in the past on my Sharp PC-1350 in the 80s: That's a clever way to do it. You could probably get this to work on the 1211 by using a calculated GOTO/GOSUB and a bunch of different sized string literals, but it wouldn't be terribly efficient in terms of RAM usage! I agree that the Sharp models are nice for customizing by adding small routines like this to memory. I just wish they had something resembling the multiple program spaces of Casios, and a simple way to overload/switch your DEF key assignments on the fly. |
|||
05-10-2022, 08:47 PM
Post: #5
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-10-2022 06:03 PM)Dave Britten Wrote: I agree that the Sharp models are nice for customizing by adding small routines like this to memory. I just wish they had something resembling the multiple program spaces of Casios. Ha, my machine can do that already: - Rob "I count on old friends to remain rational" |
|||
05-10-2022, 09:16 PM
Post: #6
|
|||
|
|||
RE: (PC-1211) Engineering format
A quick-and-dirty combination of the two programs to display scientific or engineering notation with a given number of digits (0 to 9):
Code: 1 "=" AREAD X: INPUT "SCI#";O: PRINT USING LEFT$("##.#########",O+3)+"^";X: END DEF= to display the current value scientific notation with the specified SCI# digits. Press ENTER (to skip SCI#) to display in engineering with the specified ENG# digits. Press ENTER to display normally "as is" . Won't work on the PC-1211 but should work on all other PC that have 24 character wide LCDs. - Rob "I count on old friends to remain rational" |
|||
05-11-2022, 02:14 AM
Post: #7
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-10-2022 08:47 PM)robve Wrote:(05-10-2022 06:03 PM)Dave Britten Wrote: I agree that the Sharp models are nice for customizing by adding small routines like this to memory. I just wish they had something resembling the multiple program spaces of Casios. Oh yes, I think I've seen that before. Very nice little hack. Haven't tried it on my 1360 to see if it'll work yet. Of course, I have approximately a gallon of 8 KB RAM cards, so I can just swap between a handful of those easily enough too. |
|||
05-11-2022, 10:38 PM
Post: #8
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-11-2022 02:14 AM)Dave Britten Wrote: Oh yes, I think I've seen that before. Very nice little hack. Haven't tried it on my 1360 to see if it'll work yet. Of course, I have approximately a gallon of 8 KB RAM cards, so I can just swap between a handful of those easily enough too. Yep, RAM cards work well too. The MultiPC machine program won't work on the PC-1360 without updating it to call the appropriate ROM routines. It uses a few ROM routine calls. In that respect the PC-1360 is slightly more complex to program in assembly since the routines reside in ROM banks. Switching banks isn't as easy as on the PC-E500 CPU that has a 20 bit address space. I could perhaps write a new machine program to allow multiple BASIC programs to be used in a different way than MultiPC. This machine program I have in mind simply moves one of the earlier MERGEd BASIC programs on top that you select with a CALL, so it can be edited. Kind of like a Rolodex of BASIC programs from which you can pick one to work on. It is also possible to create a new (MERGEd) BASIC program on top to start writing a new BASIC program, without having to MERGE from cassette or serial. This should always work, because MERGE already supports multiple BASIC programs "stacked" (i.e. not really merging the BASIC lines as other BASIC dialects typically do). The BASIC program on top of the "stack" can be edited. I suspect that this machine program I have in mind will be small and won't need much ROM routine support, if any. Only the addresses of the BASIC start, BASIC end and the last MERGE address are needed, which all Sharp PC have in RAM (and on RAM cards) and those are well documented. - Rob "I count on old friends to remain rational" |
|||
05-11-2022, 11:19 PM
Post: #9
|
|||
|
|||
RE: (PC-1211) Engineering format
That would be extremely handy to have. How do the Sharp computers distinguish between MERGEd programs? Do they just look for out-of-order line numbers? Some kind of catalog command to list all the labels in memory would be nice too.
|
|||
05-13-2022, 05:43 PM
(This post was last modified: 05-13-2022 08:01 PM by robve.)
Post: #10
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-11-2022 11:19 PM)Dave Britten Wrote: That would be extremely handy to have. How do the Sharp computers distinguish between MERGEd programs? Do they just look for out-of-order line numbers?\ I dusted off some of my old PC-1350 notes. The following is for S-BASIC for most Sharp PCs. I don't know for sure if this also holds for the earlier PC-1211 BASIC, probably not. Also the PC-1500, PC-1600, PC-E500 and PC-G850 use variations of this memory layout. MERGEd programs are separated by 255 byte markers: 255 <- BASIC START ADDRESS hi <- hi line number byte lo <- lo line number byte len <- line length, including 0xD (13) BASIC tokenized line 13 <- 0xD end of line (carriage return) hi lo len ... etc ... 255 <- MARGE MARKER hi <- hi line number byte lo <- lo line number byte len <- line length, including 0xD (13) BASIC tokenized line 13 <- 0xD hi lo len ... etc ... 255 <- LAST MERGE MARKER AT BASIC MERGE ADDRESS hi <- hi line number byte lo <- lo line number byte len <- line length, including 0xD (13) BASIC tokenized line 13 <- 0xD hi lo len ... etc ... 255 <- BASIC END ADDRESS A program ends when the next hi byte of the line number is 255, which is either the next MERGEd program or the BASIC END ADDRESS with marker. The last MERGEd program is editable, stored in memory starting at the BASIC MERGE ADDRESS. For the PC-1360 there are two pairs of addresses for START, END and MARGE. One extra set resides on the RAM card, so RAM card with BASIC (merged) programs can be swapped. The internal START, END and MERGE are copies that must be synched. PC-1360 BASIC addresses with low/high address byte pairs pointers are stored at the following locations in RAM:
So all that we need to do to create a new "MERGEd" program is manipulate these pointers and POKE a small new program in memory with this 3 liner: Code: 1 "NEW" L=PEEK 65497,H=PEEK 65498,E=L+256*H: POKE 65499,L,H: POKE 32779,L,H To create a new "MERGEd" program:
(05-11-2022 11:19 PM)Dave Britten Wrote: Some kind of catalog command to list all the labels in memory would be nice too. Here you go: Code: 1 "CAT" WAIT 0: A=PEEK 65495+256*PEEK 65496+1,E=PEEK 65497+256*PEEK 65498 It would be a whole lot faster in machine code, but this works reasonably quickly. These two programs work for most Sharp PC, if you can find the BASIC START and BASIC END addresses with the pointers to manipulate. The above was for the PC-1360. For the PC-1350: 28417 BASIC START 28419 BASIC END 28421 BASIC MERGE But the RAM card BASIC pointers differ depending on the RAM card size: RAM card address + 7: RAM BASIC START RAM card address + 9: RAM BASIC END RAM card address + 11: RAM BASIC MERGE No RAM card address = &6000, 8K RAM card address = &4000, 16K RAM card address = &2000 For the PC-1403 (no RAM cards): 65281 BASIC START 65283 BASIC END 65285 BASIC MERGE For the PC-1262 (no RAM cards): 26337 BASIC START 26339 BASIC END 26341 BASIC MERGE I've tested this on the PC-1360 without any issues so far. Feedback is appreciated if you encounter a problem. The "NEW" program assumes that at least a 9 bytes are available to POKE the new program in memory. It does not check for available space (adding a MEM check might be useful). Minor edit: changed "LIST" to "CAT" as suggested to catalog labels. - Rob "I count on old friends to remain rational" |
|||
05-13-2022, 06:01 PM
Post: #11
|
|||
|
|||
RE: (PC-1211) Engineering format
Neato, thanks Rob! I'll try to play around with these this weekend.
The PC-1211 doesn't have PEEK/POKE, so information on that system's internals would largely be academic, I think. |
|||
05-13-2022, 08:12 PM
Post: #12
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-13-2022 06:01 PM)Dave Britten Wrote: Neato, thanks Rob! I'll try to play around with these this weekend. Quite right. It has no MERGE either! - Rob "I count on old friends to remain rational" |
|||
05-13-2022, 08:37 PM
(This post was last modified: 05-13-2022 08:50 PM by Dave Britten.)
Post: #13
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-13-2022 08:12 PM)robve Wrote:(05-13-2022 06:01 PM)Dave Britten Wrote: Neato, thanks Rob! I'll try to play around with these this weekend. It actually does! But it's some syntax variation of the CLOAD command (which I always forget), rather than a separate MERGE command. EDIT: Or maybe not? I'm not seeing it in the manual. Maybe I'm thinking of a different computer... Hmm... EDIT AGAIN: Okay, I'm NOT losing my marbles! The command is CLOAD1. This is the same as MERGE on the later models, as far as I can tell. CLOAD1"filename" |
|||
05-13-2022, 11:26 PM
Post: #14
|
|||
|
|||
RE: (PC-1211) Engineering format
One of the best uses of the DEF key is to define:
1 " " AREAD A$: GOTO A$ Now, just type CAT DEF-SPC (DEF then SPACE key) to run "CAT". Much quicker than RUN "CAT" or GOTO "CAT". With several MERGEd programs, this can be a handy addition, I think. The "119 Practical Programs for the TRS-80 Pocket Computer" book suggested something similar, but with INPUT Z$: GOTO Z$ to call routines. PS. today I got a mint (no signs of use whatsoever) PC-1350 with manual from eBay. The seller has 6 of these that are (almost) unused, he said. He sold 2. The listing is still up. - Rob "I count on old friends to remain rational" |
|||
05-14-2022, 12:23 AM
(This post was last modified: 05-14-2022 12:29 AM by Dave Britten.)
Post: #15
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-13-2022 11:26 PM)robve Wrote: One of the best uses of the DEF key is to define: Oh yeah, that's a good way to use DEF. Even more succinct than the little "command prompt" program in the book you mentioned. It's weird, the ONLY mention I can find of the CLOAD1 command for merging in programs on the PC-1211 is on pages 62-63 of "Problem-Solving on the TRS-80 Pocket Computer". Not sure how the author got that seemingly insider information! I don't see it anywhere in the manuals. EDIT: Oh, it's in the TRS-80 version of the manual, on page 96. Weird that it's not in the Sharp manual - my PC-1211 seems to respond to CLOAD1"filename"... I'll have to test it and see if it actually behaves as expected on the Sharp version. |
|||
05-15-2022, 09:24 PM
(This post was last modified: 05-15-2022 09:26 PM by robve.)
Post: #16
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-13-2022 05:43 PM)robve Wrote: [...] After a bit of experimentation with the PC-1350/60, I found that LIST may show incomplete listings after running "NEW". The programs are still there, but aren't always LISTed, unless you use LIST "label" and everything looks OK again. Deleting the last program shows nothing with LIST afterwards. Again, the programs are still there and are perfectly RUNnable. Deleting the last program does not seem to be a good idea since things may get unstable as I had noted. Apparently, there is an internal flag in RAM to indicate merged programs are present, because the problem does not happen after executing a normal MERGE, which presumably sets this flag. It's not a big problem to use the "NEW" program, just don't delete the last program. To work around this, before using the "NEW" program, it might be best to CLOAD/LOAD a program (like the "NEW" program), then MERGE another program to activate this state properly. This way the LIST and delete problem never happens on the PC-1350 and PC-1360 and the "NEW" program creates new program slots without issues. Now, if I could just find the location of this darn flag in RAM to activate. Also still need to finish the MERGEd program rotator in assembly. - Rob "I count on old friends to remain rational" |
|||
05-16-2022, 12:38 AM
Post: #17
|
|||
|
|||
RE: (PC-1211) Engineering format
With a bit of logical guessing and a few PEEK and POKE experiments, I found the BASIC MERGE flags. The 8th bit of this flag is set when BASIC programs were merged. This resolves the problem with the "NEW" program garbling the LIST command.
For the PC-1360: 65512 BASIC FLAGS (128=merged programs are present) 32792 RAM BASIC FLAGS (128=merged programs are present) For the PC-1350: 28434 BASIC FLAGS (128=merged programs are present) RAM card address + 24: BASIC FLAGS (128=merged programs are present For the PC-2500: 28066 BASIC FLAGS (128=merged programs are present) RAM card address + 24: BASIC FLAGS (128=merged programs are present) I don't have access to other Sharp PC for a while to look for the flag address. My bet is that the PC-1262 uses 26354 and the PC-1403 uses 65298 The updated PC-1360 "NEW" program: Code: 1 "NEW" L=PEEK 65497,H=PEEK 65498,E=L+256*H: POKE 65499,L,H: POKE 32779,L,H And a PC-1350 "NEW" program (note that &60xx in the program must be replaced with the RAM card starting address when a RAM card is present, &40xx for 8K and &20xx for 16K): Code: 1 "NEW" L=PEEK 28419,H=PEEK 28420,E=L+256*H: POKE 28421,L,H: POKE &600B,L,H - Rob "I count on old friends to remain rational" |
|||
05-20-2022, 02:23 AM
(This post was last modified: 05-21-2022 09:23 PM by robve.)
Post: #18
|
|||
|
|||
RE: (PC-1211) Engineering format
(05-11-2022 11:19 PM)Dave Britten Wrote: That would be extremely handy to have. How do the Sharp computers distinguish between MERGEd programs? Do they just look for out-of-order line numbers? Some kind of catalog command to list all the labels in memory would be nice too. The MERGEd BASIC Programs Rotator "prot" code is complete I'm quite happy with it. It makes it much more convenient to store and run multiple programs on the early Sharp pocket computer models that lack a RAM file system. I've tested "prot" on a PC-1360 and a PC-1350. I wanted to make sure that the code is fully compatible with the internals of these machines. So the machines won't hang or otherwise misbehave. To do so, I had to research materials on the memory organization of these machines to find the flags that control program editing and the display of the last line when cursor up is pressed. The START, END and MERGE pointers are not sufficient to update. Other flags must be set. However, there was not a single source of information I could find among many online resources that I've collected over years that point to the 0x35 internal RAM register used by the BASIC interpreter. After dumping and comparing external and internal RAM and much experimenting, I am convinced that I found the right flags in register 0x35 as well as the external RAM flags and pointers to update. Installation
Now you have two CALLs, one to create a new MERGEd BASIC program that is added to the list at the bottom and one to rotate the programs so that the previous MERGEd program rotates to the bottom of the list and can be edited. For example, suppose we have one program "A" already in memory: 1 "A" REM my first program 2 PRINT "I am program A" To add a new program, CALL 32818 (PC-1360) to create a new MERGEd program consisting of one line with a quote: 1 "A" REM my first program 2 PRINT "I am program A" 1 " Note that the new line 1 " starts a new program that is independent of the previous programs, even when the listing appears to be continuous. To verify, LIST only lists the last merged program's first lines. In this case: LIST 1 " Complete the new program by adding a label "B" and the rest of the code: 1 "A" REM my first program 2 PRINT "I am program A" 1 "B" REM my second program 2 PRINT "I am program B" Executing RUN will run program "B", because it is the last MERGEd just as LIST list program "B". Program "A" is executed with RUN "A". Program "A" stops at line 2 and will not run program "B". Programs are internally separated when MERGEd. Separate programs can call each other using GOTO and GOSUB with labels or string expressions. RESTORE of labelled data in another program is also possible. In this way, libraries of routines and data can be created and shared among several programs. CALL 32820 (PC-1360) rotates the programs, effectively switching "A" and "B": 1 "B" REM my second program 2 PRINT "I am program B" 1 "A" REM my first program 2 PRINT "I am program A" Program "A" can now be edited, which was not possible before the rotation: 1 "B" REM my second program 2 PRINT "I am program B" 1 "A" REM my first program 2 PRINT "I am the first program" Note that only the last program MERGEd can be edited, as stated in the Sharp manuals. If you try to edit a line of an older MERGEd program, it will end up in the last program! Use the "CAT" program to list program labels (see earlier post.) The last program can be deleted with DELETE, (with comma) or just type the line numbers until the program is deleted. When the last program is deleted, the one before it will become the last program that can be edited. Note that NEW, LOAD/CLOAD and MERGE can be used and work fine. SAVE/CSAVE saves all programs. The "prot" machine code takes only about 245 bytes of RAM space. Program source and usage on the PC-1360 Code: 100 CLEAR:V=1
Disclaimer: I have only tested with ONE RAM card in slot S1!! Not sure if a second card in slot S2 works. Program source and usage on the PC-1350 with 16K RAM card Code: 100 CLEAR:V=1
Program source and usage on the PC-1350 without RAM card Code: 100 CLEAR:V=1
What about other Sharp PC? The "prot" program (for lack of a better name) should in principle work on other Sharp PC with some modifications, because it does not use non-portable syscalls. If there is some interest in this, then we should create a new thread. I will create a GitHub repo with the source code, installers and documentation. - Rob "I count on old friends to remain rational" |
|||
05-21-2022, 09:44 PM
Post: #19
|
|||
|
|||
RE: (PC-1211) Engineering format
I've created a new GitHub repository with an improved version named "prolly" (program roll-y) to reduce the code size after installation on a machine, taking only about 220 bytes of RAM space. The repository includes the full documentation in a README and the annotated assembly source code. Bootloader bas and wav files are included for the Sharp PC-1350 and PC-1360 to install the program.
The program should be portable to the Sharp PC-126x and PC-1403 with some modifications. However, I don't have these machines to work with until much later and the PockEmul emulator doesn't appear to offer a way to load machine code for testing. But perhaps I find a way. Nothing is impossible, after all - Rob "I count on old friends to remain rational" |
|||
05-24-2022, 02:38 PM
Post: #20
|
|||
|
|||
RE: (PC-1211) Engineering format
Cool stuff, Rob. I've been super busy lately and haven't had a chance to really tinker with this, but it's on my to-do list.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)