New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Anything QL Software or Programming Related.
User avatar
polka
Trump Card
Posts: 196
Joined: Mon Mar 07, 2011 11:43 am

New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by polka »

Before digging into the machine code of Supper FORTH, I wanted to test my new "Folly" program with ComputerOne FORTH. The issue being how to port its simple looping construct "...TIMES(...)" to SupperFORTH. To sum up :
IN FORTH the "DO...LOOP" expects two parameters on the stack : lower and upper bounds of looping.
When executing :
: test 10 0 DO I . LOOP ;
"I" gets the value of the index and "." prints it, so the output is :
0 1 2 3 4 5 6 7 8 9 ok
For eight years old children, I wanted a simpler looping construct expecting only one parameter :
: test 10 TIMES( I . ) ;
to get the same output.
With ComputerOne FORTH, it is relatively easy to implement this new control structure, but not so with SupperFORTH !
But with both FORTHs, when trying to execute :
: test 0 0 DO I . LOOP ;
or :
: test 0 TIMES( I . ) ;
instead of getting zero looping, wich seems natural, you get 65535 loops ! But why would you do such a silly thing ? I discovered this "feature" when I tried to code a "Folly" word to plot spirals :
SPIRAL.jpg
with first a word called SIDE to plot a strait line of <n> STEP and a RIGHT 90° turn :
: SIDE TIMES( STEP ) RIGHT ; expecting a number <n> of steps
and then a word using SIDE in another loop together with its index I :
: SPIRAL 30 TIMES( I SIDE ) ; for a fixed number of <30> sides
or :
: SPIRAL TIMES( I SIDE ) ; expecting the number <n> of sides to plot
This of course did not work, because entering the loop of SPIRAL, the first value of I was 0 and thus, the loop of SIDE got to do STEP zero times and did it actually 65535 times !
However, ComputerOne FORTH (and Folly on it) had a way to solve this issue : instead of DO , it has also a word ?DO that checks this "runtime condition" and does nothing when both bounds of a loop are equal.
whereas DO is coded using a looping primitive called (DO), ?DO uses a primitive called (?DO).
Wich I adopted for coding TIMES(
Let's compare :
: DO ?COMP COMPILE (DO) 0 , 3 ; IMMEDIATE
: ?DO ?COMP COMPILE (?DO) 0 , 3 ; IMMEDIATE
: TIMES( ?COMP COMPILE 0 COMPILE (?DO) HERE 0 , 3 ; IMMEDIATE
: LOOP ?COMP 3 ?PAIRS COMPILE (LOOP) 2+ BACK HERE SWAP ! ; IMMEDIATE
: ) ?COMP 3 ?PAIRS COMPILE (LOOP) DUP 2+ BACK HERE SWAP ! ; IMMEDIATE

To be continued when I discover how to do Folly with Supper FORTH ! Wich by the way has no ?DO word to inspire me.
For the time being, here is the final version of "Folly" for ComputerOne FORTH owners :

Code: Select all

40-COLS 

VOCABULARY folly 
folly DEFINITIONS 

VARIABLE COLOR

HEX

: black   0000 COLOR ! ;
: blue    0055 COLOR ! ;
: red     00AA COLOR ! ;
: green   AA00 COLOR ! ;
: magenta 00FF COLOR ! ;
: cyan    AA55 COLOR ! ;
: yellow  AAAA COLOR ! ;
: white   AAFF COLOR ! ;

 AAFF.A8FC 2CONSTANT FC

 0 CONSTANT SOUTH
 1 CONSTANT EAST
 2 CONSTANT NORTH
 3 CONSTANT WEST

CREATE TURNS
 AAFF , A8FC , AAFF , A8FC , AAFF , A8FC , AAFF , A8FC , AAFF ,
 A0F0 , AAFF , A0F0 , AAFF , A0F0 , AAFF , 80C0 , AAFF , 80C0 ,
 AAFF , 0000 , A0F0 , 0000 , A8FC , A8FC , A0F0 , A0F0 , 80C0 ,
 A0F0 , 0000 , AAFF , 0000 , AAFF , 80C0 , AAFF , 80C0 , AAFF ,
 A0F0 , AAFF , A0F0 , AAFF , A0F0 , AAFF , A8FC , AAFF , A8FC ,
 AAFF , A8FC , AAFF , A8FC , 80C0 , A0F0 , A0F0 , A8FC , A8FC ,
 0000 , 283C , 0203 , A8FC , 0A0F , A8FC , 0A0F , A8FC , 2A3F ,
 A8FC , 2A3F , A8FC , 2A3F , A8FC , AAFF , A8FC , AAFF , A8FC ,
 AAFF , A8FC , AAFF , A8FC , 080C , 283C , 283C , A8FC , A8FC ,
 AAFF , A8FC , AAFF , A8FC , AAFF , A8FC , AAFF , A8FC , 2A3F ,
 A8FC , 2A3F , A8FC , 3A3F , A8FC , 0A0F , A8FC , 0A0F , A8FC ,
 0203 , A8FC , 0000 , 283C , A8FC , A8FC , 283C , 283C , 080C ,

DECIMAL

: DEFER CREATE ['] NOOP , DOES> @ EXECUTE ; DEFER GRID
: (IS) R@ @ >BODY ! R> 2+ >R ; DEFER PLOT-STEP DEFER PLOT-TURN
: IS STATE @ IF COMPILE (IS) ELSE ' >BODY ! THEN ; IMMEDIATE

( couleur,x,y -- )
: SMALL-STEP
     5 0 DO
         2DUP 6 * I + 128 *
         SWAP 2* + 3 PICK FC DROP AND
         SWAP 900 + 2 !L
     LOOP
  2DROP DROP ;
: BIG-STEP
     11 0 DO
          2DUP 12 * I + 128 *
          SWAP 2* 2* + DUP 4 PICK FC SWAP >R AND
          SWAP 900 + 2 !L
          3 PICK R> AND SWAP 902 + 2 !L
     LOOP
  2DROP DROP ;

( couleur,v,x,y -- )
: SMALL-TURN
     5 0 DO
         2DUP 6 * I + 128 *
         SWAP 2* + 3 PICK 2/ 27 * I + 22 + 2*
         TURNS + @ 5 PICK AND SWAP 900 + 2 !L
     LOOP
  2DROP 2DROP ;
: BIG-TURN
     11 0 DO
         2DUP 12 * I + 128 *
         SWAP 2* 2* + I 2* 2* 4 PICK 27 * +
         TURNS + 2@ 6 PICK AND 2 PICK 900 + 2 !L
         5 PICK AND SWAP 902 + 2 !L
     LOOP
  2DROP 2DROP ;

VARIABLE AZIMUTH    2VARIABLE XY    DEFER MX    DEFER MY

60 CONSTANT SMX 34 CONSTANT SMY 30 CONSTANT BMX 17 CONSTANT BMY

: BG 26886 2310 DO 116 0 DO 2 I J + 2 !L 4 +LOOP 1536 +LOOP ;
: SG 26118 1540 DO 118 0 DO 2 I J + 2 !L 2 +LOOP 768 +LOOP ;

 ATTACH DIALOG CON_486x42a12x213 ATTACH WORKSP SCR_486x207a12x5

: small ['] SG IS GRID ['] SMX IS MX ['] SMY IS MY
  ['] SMALL-STEP IS PLOT-STEP ['] SMALL-TURN IS PLOT-TURN ;
: big   ['] BG IS GRID ['] BMX IS MX ['] BMY IS MY
  ['] BIG-STEP   IS PLOT-STEP ['] BIG-TURN   IS PLOT-TURN ;

: zap WORKSP CHANNEL IS-WORK 0 PAPER 1 7 BORDER CLS DIALOG
  IS-IO 2 PAPER 7 INK 1 7 BORDER 2 1 CSIZE CLS GRID ;

: SOUTH>EAST COLOR @ 6 XY 2@ PLOT-TURN
  XY 2@ SWAP 1+ MX MOD SWAP XY 2! EAST azimuth ! ;
: EAST>NORTH COLOR @ 0 XY 2@ PLOT-TURN
  XY 2@ 1- MY MOD XY 2! NORTH azimuth ! ;
: NORTH>WEST COLOR @ 2 XY 2@ PLOT-TURN
  XY 2@ SWAP 1- MX MOD SWAP XY 2! WEST azimuth ! ;
: WEST>SOUTH COLOR @ 4 XY 2@ PLOT-TURN
  XY 2@ 1+ MY MOD XY 2! SOUTH azimuth ! ;
: SOUTH>WEST COLOR @ 0 XY 2@ PLOT-TURN
  XY 2@ SWAP 1- MX MOD SWAP XY 2! WEST azimuth ! ;
: WEST>NORTH COLOR @ 6 XY 2@ PLOT-TURN
  XY 2@ 1- MY MOD XY 2! NORTH azimuth ! ;
: NORTH>EAST COLOR @ 4 XY 2@ PLOT-TURN
  XY 2@ SWAP 1+ MX MOD SWAP XY 2! EAST azimuth ! ;
: EAST>SOUTH COLOR @ 2 XY 2@ PLOT-TURN
  XY 2@ 1+ MY MOD XY 2! SOUTH azimuth ! ;

: step COLOR @ XY 2@ PLOT-STEP AZIMUTH @ CASE
     SOUTH OF XY 2@ 1+ MY MOD XY 2! ENDOF
     EAST OF XY 2@ SWAP 1+ MX MOD SWAP XY 2! ENDOF
     NORTH OF XY 2@ 1- MY MOD XY 2! ENDOF
     WEST OF XY 2@ SWAP 1- MX MOD SWAP XY 2! ENDOF ENDCASE ;

: left AZIMUTH @ CASE
     SOUTH OF SOUTH>EAST ENDOF
     EAST  OF EAST>NORTH ENDOF
     NORTH OF NORTH>WEST ENDOF
     WEST  OF WEST>SOUTH ENDOF ENDCASE ;

: right AZIMUTH @ CASE
     SOUTH OF SOUTH>WEST ENDOF
     EAST  OF EAST>SOUTH ENDOF
     NORTH OF NORTH>EAST ENDOF
     WEST  OF WEST>NORTH ENDOF ENDCASE ;

: times( ?COMP COMPILE 0 COMPILE (?DO) HERE 0 , 3 ; IMMEDIATE
: ) ?COMP 3 ?PAIRS COMPILE (LOOP) DUP 2+ BACK HERE SWAP ! ; IMMEDIATE

: steps times( step ) ;

ATTACH WHOLE CON_492x256a10x0
: vlist WHOLE IS-IO 0 PAPER 4 INK 0 0 CSIZE CLS WORDS ;

: origin ( color,azimuth,x,y --- ) XY 2! AZIMUTH ! step ;
: loleft red NORTH 1 MY 2 - origin ;
: center red NORTH MX 2/ MY 2/ origin ;

big zap

EOF

FCB SOURCE SOURCE FILENAME mdv1_source_fth
: LOAD-SOURCE SOURCE OPEN-FILE 0<> IF
  ABORT" File not found" THEN SOURCE CHANNEL IS-INPUT ;
: EOF OUTPUT IS-INPUT SOURCE CLOSE-FILE . ;
: LOAD-FILE SOURCE FILENAME LOAD-SOURCE ;
: PRINT SCR ! 16 0 DO CR I SCR @ .LINE LOOP ;
: MAKE-SOURCE ( n1,n2 --- ) SOURCE FILENAME SOURCE MAKE-FILE .
  SOURCE CHANNEL IS-OUTPUT 1+ SWAP DO I PRINT LOOP CR ." EOF"
  CR INPUT IS-OUTPUT SOURCE CLOSE-FILE . ;

By the way, ComputerOne FORTH as is cannot compile text files only the classic "screen" files. But after EOF, I added a few words that you may type in to a "screen" and compile to use to load text files.
Last edited by polka on Mon Apr 18, 2022 3:33 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
ones' complement
Over Heated PSU
Posts: 131
Joined: Tue Nov 30, 2021 1:19 am

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by ones' complement »

Where is ComputerOne FORTH ?


User avatar
polka
Trump Card
Posts: 196
Joined: Mon Mar 07, 2011 11:43 am

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by polka »

ComputerOne is a company that sold in the eighties software products for the Sinclair QL. Surprisingly, some of their product (like their assembler and a monitor) are today PD, but not their FORTH, because apparently nobody knows who owns the copyright. I was lucky to buy one in these times and I find it much better than the Digital Precision so called SuperForth, wich IS PD and can be freely downloaded from the QL archve sites.
As I used it intensively, I found three bugs (one major one) and patched them out (I published these corrections on this forum).

I only know that this FORTH was developped by MPE (microprocessor engineeriing) https://www.mpeforth.com/ like mentionned on page 0 of its default screen file and in its user manual, and that inside the program a message is hidden saying "Stephen Pelc fecit" : Stephen Pelc was then with MPE, and besides, he is also the author of a very complete book on FORTH.

I would be very curious to find out who in this QL community has this FORTH, because today you can no longer buy it anyhere ?


May the FORTH be with you !
POLKa
ones' complement
Over Heated PSU
Posts: 131
Joined: Tue Nov 30, 2021 1:19 am

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by ones' complement »

I wonder who now holds the rights, ComputerOne (?) or Stephen Pelc (https://www.mpeforth.com/sample-page/46-2/)


User avatar
pjw
QL Wafer Drive
Posts: 1297
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by pjw »

I used to have C1 Forth - my first real PL before getting to grips with
SuperBASIC - but I sold it on recently.

While I enjoyed Forth in the early days, I found C1 Forth too limiting: No
floating point (at least back then. Perhaps that changed?), and the 1k
"screens" (probably a remnant from old computer hardware) among other
things.

Anyway, once I got to grips with writing my own toolkits, SuperBASIC - an
extendable, compilable, procedural language, just made for Qdos and the QL
- there didnt seem much point to continuing with Forth except for fun,
something I didnt have a lot of time for back then.

The examples shown by polka look intriguing, but I dont think I can get my
creaky old brain to engage with it, and my "QL time" is rather fully
booked.


Per
dont be happy. worry
- ?
Derek_Stewart
Font of All Knowledge
Posts: 3957
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by Derek_Stewart »

I have scanned copy of the Computer 1 Forth Manual, but not the software.

With regards to Super Forth, the source code is on Gerry Jackson 's Git Hub page, maybe the code could updated?


Regards,

Derek
User avatar
polka
Trump Card
Posts: 196
Joined: Mon Mar 07, 2011 11:43 am

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by polka »

Typically, the FORTH machines adopting the norms up to FORTH83 were 16 bit machines in a memory space of 64Kb (or less). They may be metacompiled with the help of a FORTH macro-assembler for the FORTH engine and all the low level and hardware dependant primitives. Stephen Pelc at MPE did it this way : using a FORTH that he had for another machine to create FORTH for the QL with af FORTH macro-assembler module for 68K machine code. Its machine coded primitives are inside the 64Kb memory space and can be called or compiled into high level words by the FORTH engine like any FORTH word.
I looked at the SuperForth sources (not sure that they are up to date) and the way this FORTH was made is different : the machine code primitive are assembled with a classic macro-assembler, most of them are headerless and there is a table of their CFA (code field addresses) linked into the 64Kb FORTH system. So to update it with new primitives you have to MAKE the whole thing anew.
I will not do it, because I am not interested in assembler programming. In my ComputerOne FORTH, all primitives have headers and can be accessed directly by the FORTH engine to compile new FORTH words, even new control structures (like I did fot "TIMES(...)" instead of "DO...LOOP").


May the FORTH be with you !
POLKa
User avatar
NormanDunbar
Forum Moderator
Posts: 2273
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by NormanDunbar »

polka wrote:... I am not interested in assembler programming.
Sacrilege! ;)

Funnily enough, I find that when I get a new CPU to play with, I immediately start looking for Assembly Language stuff! I have to admit, either I don't look and play hard enough with ARM assembly, or it's just too weird for my ageing brain! I suspect the latter.

Mind you, even when I was at college, I never got into Forth either. I don't know why.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 3957
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by Derek_Stewart »

Hi,

I find M68K and ARM assembler easy to understand, unlike Z80 and 8086, whether I am any good at assembler programming is debatable.

I like the Forth way of thinking, which most books reckcon that Forth is as fast as assembler but at a high level.

The Reversi supplied with SuperForth, is supposed be written in Forth, but I maybe wrong, maybe Gerry Jackson could confirm this.
Last edited by Derek_Stewart on Wed Apr 20, 2022 4:28 pm, edited 1 time in total.


Regards,

Derek
User avatar
polka
Trump Card
Posts: 196
Joined: Mon Mar 07, 2011 11:43 am

Re: New "feature" (aka "bug") in both ComputerOne and Supper FORTH :

Post by polka »

That I am not interested in assembler does not mean that I did not. My first "personnal" computer was a SCMP elektor kit that you could only program with machine code through a hex keyboard, my second was the elektor so called "game" computer with a Signetics 2650 CPU to program also only with machine code, then I programmed my ZX81 with its ZXAS assembler (sometimes).
With the QL, I only used the FORTH assembler module once to program a DOT and a LINE word to accelerate my perspective drawings (shown elsewere on this forum). I bought also the GST macro assembler but I never used it. I am not a fan of assembler, I am a fan of FORTH !
And yes, the reversi program is coded in FORTH, and with words that are not all documented in the manual that goes with DP Superforth. Its source is given in the manual.


May the FORTH be with you !
POLKa
Post Reply