FORTH for the SHARP PC-E500 (S)
|
01-13-2022, 03:40 AM
Post: #61
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(01-12-2022 11:06 PM)Helix Wrote: I'm still learning Forth, following the book Starting Forth 2nd edition. (I know it's outdated, but it's didactic and enjoyable. I have also the Forth Programmer's Handbook for a more modern reference.) It is good to hear you are putting Forth500 through its paces You made a good point. The EKEY? word calls CHAR-READY? but then throws exception -57 if CHAR-READY? returns true. This is a small part of the older pceForth version, which looks wrong to me. The EKEY? Forth standard word requires EKEY? to return true or false. I will correct this discrepancy soon and release an update. I may also add a new module LOCALS.FTH that I wrote from scratch to implement the LOCALS word set (I heard that Forth purists turn their nose up to LOCALS, arguing that it is superfluous since everything can be done via the stacks.) I was tinkering with some code I wrote to add dynamic scoping of arguments and locals to Forth definitions. This turns out to be surprisingly simple to implement in Forth itself, so I wouldn't be surprised if someone hasn't done this already. - Rob "I count on old friends to remain rational" |
|||
01-16-2022, 09:22 PM
Post: #62
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Helix,
The EKEY? and KEY? exception problem is fixed. That was annoying. Thanks for reporting. Sorry to have missed that. I try to test Forth500 as much as possible before releasing updates, but there is only so much time one person can put into this. The Forth500 update includes the following changes: - updated BREAK key pressing exception to display Break instead of <Error -28 - updated REPRESENT to produce 12 or 13 non-rounded digits for single floating point results instead of 10, which means that single precision arithmetic is practically performed with 12 or even 13 digits without rounding - updated double floating point computation results to round to 20 digits rather than ignoring the guard digits - fixed EKEY? issue that affected KEY? as well - Rob "I count on old friends to remain rational" |
|||
01-18-2022, 12:32 AM
Post: #63
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Thank you for the update! Now EKEY? works as expected.
Jean-Charles |
|||
02-19-2022, 09:40 PM
Post: #64
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
I think I have found another quirk.
M*/ ignores negative numbers. For example -1. 1 1 M*/ D. gives 1 instead of -1 Same result with 1. -1 1 M*/ Jean-Charles |
|||
02-20-2022, 09:13 PM
Post: #65
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(02-19-2022 09:40 PM)Helix Wrote: I think I have found another quirk. It's easy to fix and I will update the repo soon. There is an internal RAM register clash that resets the sign bit of the result. This issue should not have happened. I may have overlooked this specific case when testing the latest round of speed optimizations and code size reductions to make the Forth500 system fit in about 20K -Rob "I count on old friends to remain rational" |
|||
02-20-2022, 11:12 PM
Post: #66
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Thanks for the update
Jean-Charles |
|||
04-03-2022, 12:53 AM
Post: #67
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
I haven't had the time to work on a text file editor for Forth500 to edit Forth source code. I usually INCLUDE my programs from COM: or use CLOAD with the CE-126P. Editing text files on the RAM disk can be done with a separate BASIC program called edit500 available at: http://www.andrewwoods3d.com/pce500/
Or you could use my new Forth500 TLOAD command defined below that loads Forth from a TEXT file created in BASIC with the built-in BASIC editor: Code: \ TLOAD.FTH load TEXT file with line numbers as Forth source This approach is similar to the PC-G850(V)(S) C programming with its built-in line-number-based text editor. It is a bit odd to use line numbers. But hey, this is a throwback to the 80s How to use TLOAD: 1. in BASIC key in TEXT, the prompt will change to < to indicate the TEXT mode 2. type in your Forth program line-by-line with line numbers 3. use RENUM in case you can't insert a line 4. then SAVE "name" to save your program to RAM disk as name.BAS (don't forget this step!) 5. go back to Forth500 with CALL&B0000 (or CALL&B9000 on a 32K machine) 6. key in TLOAD name.BAS 7. done! - Rob "I count on old friends to remain rational" |
|||
04-03-2022, 11:06 PM
(This post was last modified: 04-03-2022 11:10 PM by Helix.)
Post: #68
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(04-03-2022 12:53 AM)robve Wrote: I haven't had the time to work on a text file editor for Forth500 to edit Forth source code. I usually INCLUDE my programs from COM: or use CLOAD with the CE-126P. Editing text files on the RAM disk can be done with a separate BASIC program called edit500 available at: http://www.andrewwoods3d.com/pce500/ Thank you for this suggestion and for this clever program. However I'm currently busy with other things, and I will not test them soon. I've just spent an hour trying the INCLUDE command, that I have never used so far, but for some reason it didn't work. Maybe I'm messing something in the file format, or I've forgotten one important detail, but I give up. I will certainly return to Forth and to the PC-E500 next winter. However, if this program works as expected, it should completly satisfy my needs . So, thank you again! Jean-Charles |
|||
04-04-2022, 12:47 AM
(This post was last modified: 04-12-2022 02:17 AM by robve.)
Post: #69
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(04-03-2022 11:06 PM)Helix Wrote: I've just spent an hour trying the INCLUDE command, that I have never used so far, but for some reason it didn't work. Maybe I'm messing something in the file format, or I've forgotten one important detail, but I give up. Have you tried this? To load from COM:, make sure to set the serial parameters first on the E500 to correspond to the settings of your sending program, which should be done once (and for all) in BASIC with OPEN "baud rate, parity, word length, stop bit, A, C, &H1A, XON" AS #1 then CLOSE #1. The file to send should have an ending &1A (ctrl-Z) end of file. PS. I should add that commands like INCLUDE open and then close the file, even when an error occurred. However, if files or COM: cannot be opened, then try fileid CLOSE-FILE . for some fileid>0 values to close the file. This closes the file if for some reason it stayed open e.g. after a program aborted due to an error when files are open. - Rob "I count on old friends to remain rational" |
|||
06-21-2022, 02:16 AM
Post: #70
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Compute digits of pi.
The following Forth500 program is based on the C code to compute the digits of pi by Dik T. Winter, CWI Amsterdam. It computes up to 9864 digits of pi, but is memory-restricted to about 6000 digits max: Code: .( Loading BIG-PI...) A screenful with the first 152 digits of pi (this takes one minute to compute): Code: 152 big-pi A C program for the PC-G850(V)(S): Code: 1 unsigned long a=10000,d; The PC-G850VS calculates the first 152 digits of pi in 1 minute and 15 seconds. This slightly modified version in C with 64 bit integers correctly computes up to 54935 digits of pi: Code: uint64_t a=10000,b,c,d,e,*f,g; The 54936th digit is off by one, followed by 10000 instead of 0000: 362524395716152714669005814610000 ___________________________^x____ where a 7 should appear in place of the 6, falling the 1 to carry over to the 6. When pushing for 100000 digits this happens a few more times. I reckon the algorithm can be fixed to perform the carry. But this algorithm is quite slow for long digit sequences. There are also better algorithms, e.g. BBP, Chudnovsky. - Rob "I count on old friends to remain rational" |
|||
09-16-2022, 06:54 PM
Post: #71
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Forth500 2.0 released
Forth500 2.0 is a standard Forth system for the Sharp PC-E500(S) with 564 built-in Forth words. Forth500 2.0 runs up to 20% faster by exploiting faster 16-to-20 bit address conversion via the internal RAM registers of the ESR-L CPU. The NQUEENS calculator benchmark finishes in 3.47 seconds in Forth500 2.0. It took 4.15 seconds in Forth500 1.0. Tested with a loop of 20 NQUEENS runs. The speed boost should be noticible to colon definition calls (20% less overhead) and also to all Forth primitives involving single and double integer literals, variables, values, constants, single and double integer store and fetch, single integer arithmetic involving addition and subtraction, and single and double integer stack operations. Improvements are also made to the Forth500 manual and to the Forth500 implementation overall, including new support for Forth vocabularies (yes, finally...) Also included in Forth500 2.0 is a new text editor "TED". TED.FTH is located in the Forth500 additions folder. With TED you can interactively write, edit and run Forth code in Forth500: Code: TEDI MYWORK.FTH ↲ Synopsis: TED edit the last file edited TED FILE.FTH edit FILE.FTH TEDI edit the last file edited, then read it into Forth500 TEDI FILE.FTH edit FILE.FTH, then read it into Forth500 Files are saved to the E: or F: RAM disk. See also the TED editor instructions. By the way, any suggestions for additions, improvements and issues are of course always welcome. Enjoy! - Rob "I count on old friends to remain rational" |
|||
09-16-2022, 11:09 PM
Post: #72
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
I like some of the new additions.
Now that you have vocabulary words, and if you have time to waste, you can write an assembler. Jean-Charles |
|||
09-17-2022, 12:38 AM
Post: #73
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(09-16-2022 11:09 PM)Helix Wrote: I like some of the new additions. Note that there are also a number of new separate Forth500 additions and examples: CALENDAR.FTH (borrowed from Jupiter ACE), HANOI.FTH (a classic, shows deep recursion), HITOMEZA.FTH (patterns), LINES.FTH (a bounding lines screen saver), MORE.FTH (like Unix more command), REDEF.FTH (redefine any Forth word, like the Jupiter ACE REDEFINE word), SAVE.FTH (save Forth500 image with all user code to a file), and TED.FTH. I kept TED small, so loading does not take too much time and the application itself does not require much memory to run. But it pushes memory limits on an unexpanded E500. (09-16-2022 11:09 PM)Helix Wrote: Now that you have vocabulary words, and if you have time to waste, you can write an assembler. Give me a day or two Eager to try ESR-L CPU programming? Try the XASM126 assembler written in Pascal. It's included with Forth500 to build Forth500. Also included are ESR-L and E500 technical manuals. I've translated the Japanese XASM documentation to English for convenience and CPU resources OK, so honestly most of the Forth500 improvements were done during an extended weekend fairly recently to execute my plan I'd talked about before, i.e. to use a different method for the Forth execution token fetch/execute cycle and other internals that require 16-to-20 bit address conversions. But testing and iterating to ensure perfection always takes some days with projects like this, especially since testing is done on the actual machines, before I'm confident to commit the update. This is necessary, because over 900 lines of assembly were changed/removed/added to the 2.0 release. All of this taking only 16 more bytes of the binary, by shuffling things and by reusing code in cases where this wasn't done before. IMHO the low-power ESR-L CPU ISA is interesting and powerful for an 8 bit CPU with 20 bit address space. OK, it's not a famous Z80 or HP Saturn, but I actually like it better than a Z80 (don't know if anyone can agree or not). Most of the Sharp IQ and OZ Wizards have this CPU on board, no surprise. It runs a 2.3MHz clock. But you have to divide this by 3 since a single CPU instruction cycle takes three clock ticks. So effectively it runs at 768KHz. This makes sense, because a typical instruction fetch-decode-execute takes three ticks and just one cycle on the ESR-L when other CPUs take 3 cycles. Also, most CPU instructions on the ESR-L take only a few CPU cycles, such as 2, 3 or 4 CPU cycles for 8, 16, 24 bit register moves respectively. - Rob "I count on old friends to remain rational" |
|||
09-17-2022, 10:44 PM
Post: #74
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(09-17-2022 12:38 AM)robve Wrote: Note that there are also a number of new separate Forth500 additions and examples: CALENDAR.FTH (borrowed from Jupiter ACE), HANOI.FTH (a classic, shows deep recursion), HITOMEZA.FTH (patterns), LINES.FTH (a bounding lines screen saver), MORE.FTH (like Unix more command), REDEF.FTH (redefine any Forth word, like the Jupiter ACE REDEFINE word), SAVE.FTH (save Forth500 image with all user code to a file), and TED.FTH. I kept TED small, so loading does not take too much time and the application itself does not require much memory to run. But it pushes memory limits on an unexpanded E500. I've noticed them (09-17-2022 12:38 AM)robve Wrote: Eager to try ESR-L CPU programming? Try the XASM126 assembler written in Pascal. It's included with Forth500 to build Forth500. Also included are ESR-L and E500 technical manuals. I've translated the Japanese XASM documentation to English for convenience and CPU resources This is something I will investigate later. I still have to finish learning Forth, especially all the features of Forth500, and I have a lot to explore with all your examples. The only CPU I know is the SC61860, because I learned the machine language of my Sharp PC-1401. But I've forgotten everything since that time! Do you know if there is a common CPU that is comparable to the ESR-L, if my question makes sense? Jean-Charles |
|||
09-18-2022, 12:21 AM
(This post was last modified: 10-06-2022 03:40 PM by robve.)
Post: #75
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(09-17-2022 10:44 PM)Helix Wrote: The only CPU I know is the SC61860, because I learned the machine language of my Sharp PC-1401. But I've forgotten everything since that time! I tend to think of the ESR-L as a mix of Z80, 6809 and SC61860 (ESR-H or "old-SC") flavors. The German Systemhandbuch section 12 on the CPU gives a good technical overview, albeit in German. There are also suggestions on how to reserve space for machine code and there is info on the PC-E500 internals. For the FCS and IOCS system calls, see the PC-E500 technical manual. Both texts are included as PDFs in the Forth500 resources. There is also a ESR L CPU technical manual. The ESR-L machine code prefix bytes are the odd ones for this CPU. A prefix byte applies to internal RAM registers. The internal RAM acts like a large register window with base pointer BP. It allows for a clever way to run routines that have their private internal RAM by shifting the window. For example, BASIC uses an internal RAM window. Forth500 too, but using a different location of the window. This is done with "prefix bytes" added to CPU instructions to address internal RAM. Without a prefix byte, an internal RAM register (a location) is always relative to the BP. So internal register (ex) for example is really (BP+ex) when prefix bytes are turned off with pre_off. A prefix byte must be used for absolute RAM register addressing like (ex) but with prefix bytes on with pre_on, which is required with the operating system FCS and IOCS calls. A prefix byte can also be used to address internal RAM registers relative to the PX index register, either (PX+n) or (BP+PX). I've only used (BP+PX) for the floating point routines, to index BCD digits stored in internal RAM. Note that internal RAM memory is written (n) with location n (could be BP+n), whereas external RAM is written [nm] for 16 bits nm or written [lmn] for 20 bits lmn. Registers are one byte (A, B, IL), two bytes (BA, I) or three bytes (memory/index registers X, Y and stack pointers U, S like the 6809). Internal RAM can contain integers of one, two or three bytes. Register BA combines A (lo) and B (hi). I combines IH and IL. Assigning to IL makes IH zero (IH is not directly addressable). That's often very handy, as it results in shorter and slightly faster code. There are RAM memory block moves MVL with IL number of bytes moved. Internal RAM block binary addition ADCL and subtraction SBCL instructions and BCD DADL and DSBL. Except for those specialized cases, most ESR-L instructions should be easy to get familiar with. Perhaps take a look at the Forth500.s assembly? It's all explained and annotated. - Rob EDIT: mention PC-E500 technical manual. "I count on old friends to remain rational" |
|||
10-02-2022, 02:29 PM
Post: #76
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Can this article still be updated as it looks to be in an older format?
If so, can you please also add my 50G version (posted in the general forum here). TIA, dmh (09-15-2021 11:51 PM)xerxes Wrote:(09-12-2021 02:00 AM)robve Wrote: - improved execution speed and reduced code size Calculator Clique on YouTube |
|||
10-04-2022, 12:02 AM
Post: #77
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(10-02-2022 02:29 PM)dmh Wrote: Can this article still be updated as it looks to be in an older format? Yes, it's still possible to update the old format list. Can you please let me know, which version of Forth do you have ported? Calculator Benchmark |
|||
10-04-2022, 12:46 PM
Post: #78
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
It's a C version based on Richard W.M. Jones' Jonesforth and then ported to the 50G using HP GCC 2.0.
(10-04-2022 12:02 AM)xerxes Wrote:(10-02-2022 02:29 PM)dmh Wrote: Can this article still be updated as it looks to be in an older format? Calculator Clique on YouTube |
|||
10-04-2022, 10:39 PM
Post: #79
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
(10-04-2022 12:46 PM)dmh Wrote: It's a C version based on Richard W.M. Jones' Jonesforth and then ported to the 50G using HP GCC 2.0. Thank you. I've updated the list. Calculator Benchmark |
|||
10-04-2022, 10:55 PM
Post: #80
|
|||
|
|||
RE: FORTH for the SHARP PC-E500 (S)
Great, thanks :-)
Note, the FORTH code for the 50G is different. I have included below in case you want to list it. Code: 8 CONSTANT RR (10-04-2022 10:39 PM)xerxes Wrote:(10-04-2022 12:46 PM)dmh Wrote: It's a C version based on Richard W.M. Jones' Jonesforth and then ported to the 50G using HP GCC 2.0. Calculator Clique on YouTube |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)