Post Reply 
FORTH for the SHARP PC-E500 (S)
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
Post Reply 


Messages In This Thread
FORTH for the SHARP PC-E500 (S) - Helix - 09-06-2021, 11:41 PM
RE: FORTH for the SHARP PC-E500 (S) - dmh - 10-02-2022, 02:29 PM
RE: FORTH for the SHARP PC-E500 (S) - dmh - 10-04-2022, 12:46 PM
RE: FORTH for the SHARP PC-E500 (S) - dmh - 10-04-2022, 10:55 PM
RE: FORTH for the SHARP PC-E500 (S) - Helix - 09-15-2023 10:15 AM



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