FORTH for the SHARP PC-E500 (S)
01-13-2022, 03:40 AM
Post: #61
 robve Member Posts: 287 Joined: Sep 2020
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.)

I have a problem with the KEY? word. If no key is pressed, it returns "error -57" instead of 0.
The same problem occurs with EKEY? Furthermore, if a key is pressed, EKEY? returns 255. I think it should be -1.

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" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
01-16-2022, 09:22 PM
Post: #62
 robve Member Posts: 287 Joined: Sep 2020
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" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
01-18-2022, 12:32 AM
Post: #63
 Helix Member Posts: 238 Joined: Dec 2013
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
 Helix Member Posts: 238 Joined: Dec 2013
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
 robve Member Posts: 287 Joined: Sep 2020
RE: FORTH for the SHARP PC-E500 (S)
(02-19-2022 09:40 PM)Helix Wrote:  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*/

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" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
02-20-2022, 11:12 PM
Post: #66
 Helix Member Posts: 238 Joined: Dec 2013
RE: FORTH for the SHARP PC-E500 (S)
Thanks for the update

Jean-Charles
04-03-2022, 12:53 AM
Post: #67
 robve Member Posts: 287 Joined: Sep 2020
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:
\ Author: Robert van Engelen

DECIMAL

\ open file and save fileid to the return stack
R/O OPEN-FILE THROW >R
FIB 19 R@ READ-FILE 0= SWAP 19 = AND
\ and check if it is a TEXT file header
FIB 5 S\" \xff\x00\x08\x00\x34" S= AND IF
BEGIN
\ while not EOF and line number high byte is not $FF R@ READ-CHAR 0= SWAP$FF <> AND WHILE
\ read and nip line number low byte
\ get line len byte
R@ READ-CHAR 0= WHILE ( -- len1 )
\ read the len number of bytes into the FIB
FIB OVER R@ READ-FILE 0= WHILE ( -- len1 len2 )
OVER = WHILE ( -- len1 )
FIB SWAP ['] EVALUATE CATCH ?DUP IF
\ drop string that failed to evaluate, close file and rethrow
2DROP R> CLOSE-FILE DROP THROW
THEN
AGAIN
ELSE DROP THEN
ELSE 2DROP THEN
ELSE DROP THEN
THEN
THEN
ELSE
." not TEXT"
THEN
\ pop fileid from the return stack and close file
R> CLOSE-FILE DROP
;

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

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)
7. done!

- Rob

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
04-03-2022, 11:06 PM (This post was last modified: 04-03-2022 11:10 PM by Helix.)
Post: #68
 Helix Member Posts: 238 Joined: Dec 2013
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/

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:

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
 robve Member Posts: 287 Joined: Sep 2020
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" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)