Post Reply 
FORTH for the SHARP PC-E500 (S)
10-13-2022, 11:30 PM
Post: #81
RE: FORTH for the SHARP PC-E500 (S)
(09-16-2022 06:54 PM)robve Wrote:  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 ↲
↲                           \ start editing (press enter)
.( TED is great!) ↲        \ a line of Forth (press enter to save)
[CCE]                       \ end editing and read MYWORK.FTH
TED is great!

I've tried TED, and it works perfectly! It's very easy now to write Forth definitions without being linked to a PC, which is the charm of these pocket calculators after all.
I've also tried TLOAD, but it requires more manipulations than TED.
So I can confirm: TED is great! Smile

Jean-Charles
Find all posts by this user
Quote this message in a reply
11-06-2022, 04:15 AM (This post was last modified: 11-06-2022 01:57 PM by robve.)
Post: #82
RE: FORTH for the SHARP PC-E500 (S)
Recently started a new Forth project. This time for the Sharp PC-850(V)(S).

New thread here: https://www.hpmuseum.org/forum/thread-19085.html

[Image: PC-G850-forth.png]

- 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...
Visit this user's website Find all posts by this user
Quote this message in a reply
11-06-2022, 01:20 PM
Post: #83
RE: FORTH for the SHARP PC-E500 (S)
(11-06-2022 04:15 AM)robve Wrote:  Recently started a new Forth project. This time for the Sharp PC-850(V)(S)...

@rob - I'd move this to a new thread, dedicated to the 850V version, it will make it easier to find for folks with that machine.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
11-14-2022, 12:55 AM
Post: #84
RE: FORTH for the SHARP PC-E500 (S)
(11-06-2022 04:15 AM)robve Wrote:  Recently started a new Forth project. This time for the Sharp PC-850(V)(S).

New thread here: https://www.hpmuseum.org/forum/thread-19085.html

Rob,
In the Forth850 thread, you presented an interesting example on how to use machine code inside Forth definitions. I've not investigated this question (I own a G850VS, but now I'm busy enough with the E500S Wink ), but is the same technique possible with Forth500, just writing HEX codes?

Jean-Charles
Find all posts by this user
Quote this message in a reply
11-14-2022, 01:18 AM
Post: #85
RE: FORTH for the SHARP PC-E500 (S)
(11-14-2022 12:55 AM)Helix Wrote:  
(11-06-2022 04:15 AM)robve Wrote:  Recently started a new Forth project. This time for the Sharp PC-850(V)(S).

New thread here: https://www.hpmuseum.org/forum/thread-19085.html

Rob,
In the Forth850 thread, you presented an interesting example on how to use machine code inside Forth definitions. I've not investigated this question (I own a G850VS, but now I'm busy enough with the E500S Wink ), but is the same technique possible with Forth500, just writing HEX codes?

Writing an assembler for the ESR-L in Forth would take some time, something I'm short of. Using the PC-G850's Assembler with Forth850 is cheap: it's already there. I didn't have to write one or find a Z80 assembler to integrate with Forth850. Note that Forth500 is a lot more powerful than Forth850 (thanks to the fact that the E500 is a professional machine with reasonably powerful FCS and IOCS system), so you're not missing out on anything really, except speed perhaps.

I'm not sure how many folks would actually use an ESR-L assembler in Forth500 besides you and me? I hope I'm mistaken, but our world with our "toys" is pretty small.

I will keep updating Forth500 and Forth850 (as well as other side projects.) But I tend to move quickly between things to do. I recently acquired two PC-1600's that peaked my interest, one close to NIB with 2 64K RAM modules and one with a CE-1600 printer. Forth850 may as well be ported to that PC too. Now that I've said it, I probably can't get that out of my head... oh no

- 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...
Visit this user's website Find all posts by this user
Quote this message in a reply
11-14-2022, 02:17 AM (This post was last modified: 11-14-2022 06:35 PM by Helix.)
Post: #86
RE: FORTH for the SHARP PC-E500 (S)
(11-14-2022 01:18 AM)robve Wrote:  Writing an assembler for the ESR-L in Forth would take some time, something I'm short of.

My question was not about an assembler. Here is the section that interested me:

(11-13-2022 10:15 PM)robve Wrote:  Alternatively, the BEEP word can also be defined with HEX codes in Forth850 as follows, which takes more effort but with the same result:
Code:
NFA, BEEP       ( -- )
  HEX
  F3 C,         \       di              ;
  F3 C,         \       di              ; disable interrupts
  21 C, 0 ,     \       ld hl,0000h     ;
  AF C,         \       xor a           ;
  D3 C, 18 C,   \ loop: out (18h),a     ; loop, out audio port
  D2 C,         \ wait: dec l           ;   loop
  20 C, FD C,   \       jr nz,wait      ;   until --l=0
  2F C,         \       cpl             ; switch on/off
  25 C,         \       dec h           ;
  20 C, F7 C,   \       jr nz,loop      ; until --h=0
  FB C,         \       ei              ; enable interrupts
  FD C, E9 C,   \       jp (iy)         ; next
  DECIMAL       \ 18 bytes

Here you don't use the built-in assembler, so I was only asking if the same thing is possible in Forth500. But I think I know the answer now.


(11-14-2022 01:18 AM)robve Wrote:  I will keep updating Forth500 and Forth850 (as well as other side projects.) But I tend to move quickly between things to do. I recently acquired two PC-1600's that peaked my interest, one close to NIB with 2 64K RAM modules and one with a CE-1600 printer. Forth850 may as well be ported to that PC too. Now that I've said it, I probably can't get that out of my head... oh no

Ha ha! I don't own a PC-1600, but I have a TI-92 Plus and a TI Voyage 200. I see in your signature that you also have a TI Voyage 200… A Forth for these machines would be great too. Big Grin

Jean-Charles
Find all posts by this user
Quote this message in a reply
09-15-2023, 10:06 AM
Post: #87
RE: FORTH for the SHARP PC-E500 (S)
(09-18-2022 12:21 AM)robve Wrote:  
(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!
Do you know if there is a common CPU that is comparable to the ESR-L, if my question makes sense?

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 Systemhandbuch PDF is excellent to learn this machine code!
I decided to make an English version of chapters 12 and 13 for my personal use, in order to have a handy reference. In case it’s useful for someone else, this document can be downloaded from this page.

The text is the result of automatic translation, with very few corrections.
I’ve clarified the paragraph structure, corrected a few typos in the tables, and rearranged the abbreviation list in a more convenient order, at least for me.
This file was created with LibreOffice. I don’t know if it’s correctly displayed with Word.
This document must be viewed in Web Mode only.

Jean-Charles
Find all posts by this user
Quote this message in a reply
09-15-2023, 10:15 AM
Post: #88
RE: FORTH for the SHARP PC-E500 (S)
(09-18-2022 12:21 AM)robve Wrote:  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.

At first, I was surprised by the complexity of the instructions set. It’s a big change from the Sharp PC-1401! The reason is the presence of internal RAM, and this kind of "double stage" pointers, i.e. pointers to other pointers. But it’s interesting.

Understanding the source code of Forth500 allowed me to make three minor additions, mainly cosmetic.

First, I was annoyed not to see whether Forth500 was in decimal mode or in hexadecimal mode. So, I decided to set the "E" annunciator in Hex mode. It’s an easy fix:

: HEX ( -- ) HEX $4F C@ 2+ 3 SET-SYMBOLS ;
: DECI ( -- ) DECIMAL $4F C@ 3 SET-SYMBOLS ;


DECI is faster to type than DECIMAL Wink


Then, I found inelegant to be forced to return to BASIC to change the angular unit for trigonometric functions, or to use conversions.
The Systemhandbuch tells that this parameter is controlled by bits 0 and 1 of address BFC5C (p.63).
The following words allow to change this parameter inside Forth500:

: TRIGMODE ( b1 b2 -- ) $FC5C C@ $FC AND + $FC5C C! DUP $4F C! 3 SET-SYMBOLS ;
: DEG ( -- ) 24 1 TRIGMODE ;
: RAD ( -- ) 4 0 TRIGMODE ;
: GRAD ( -- ) 12 2 TRIGMODE ;


The setting made in Forth500 also applies to BASIC.


Finally, I wanted a convenient way to define words by machine code. Inspired by Forth850, I defined these three words:

: NFA, ( <name> ( -- ) HERE CURRENT @ , CURRENT ! BL WORD C@ 1+ ALLOT HERE ['] LAST-XT >BODY ! HEX ;
: CODE, ( b1 ... bn -- ) DEPTH 0 DO DEPTH 1- ROLL C, LOOP ;
: END-CODE, ( -- ) $E1 $24 $36 $10 $36 CODE, DECI ;


Here is a simple and useless example: the duplication of the word @ in machine code.
The source listing indicates that the core of this word consists in two instructions:
mv (!yi),ba
mv ba,[(!yi)]
Given that !yi means BP+36, the hexadecimal machine codes are respectively A2 36 and 9A 00 36.
Now it’s possible to define MY@, starting with an empty stack:

NFA, MY@ 0A2 36 9A 0 36 CODE, END-CODE,

0A2 avoids confusion with A2 if this word already exists. $A2 works too Wink

Jean-Charles
Find all posts by this user
Quote this message in a reply
09-15-2023, 11:47 AM
Post: #89
RE: FORTH for the SHARP PC-E500 (S)
(09-15-2023 10:06 AM)Helix Wrote:  The Systemhandbuch PDF is excellent to learn this machine code!
I decided to make an English version of chapters 12 and 13 for my personal use, in order to have a handy reference. In case it’s useful for someone else, this document can be downloaded from this page.

The text is the result of automatic translation, with very few corrections.
I’ve clarified the paragraph structure, corrected a few typos in the tables, and rearranged the abbreviation list in a more convenient order, at least for me.
This file was created with LibreOffice. I don’t know if it’s correctly displayed with Word.
This document must be viewed in Web Mode only.

It seems fine in Word.

Thanks for the effort to translate and share this!

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
Post Reply 




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