SuperFORTH Editor

Anything QL Software or Programming Related.
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

SuperFORTH Editor

Post by tcat »

Hi,

I have been toying with SuperForth for some days, I am fairly new to the language, just learning its grammar.
Interesting concept is that of files being stored in 1024B blocks, supplied Editor displays one block a time allowing to browse trough the file displaying [CTRL] [F3] next or [SHIFT] [F3] previous block.

There is a utility Word SAVE_FILE provided in BLK4, accepting start + end blocks to create a single named file.

A named file can be executed by LOAD_FILE.

I was thinking of a reverse Word, that would take a named file and recreate blocks suitable to display in the Editor. As is not present in the dictionary, here's my first attempt to define READ_FILE ...

Code: Select all

2VARIABLE #TEMP
VARIABLE #EOF

: READ_FILE   ( first_block "filename" --- )

  #IN 2@ #TEMP 2! 0 OPEN #IN 2!
  BEGIN DUP BUFFER 
  L/B 0 DO
       DUP QUERY 10 WORD DUP C@ 0= #EOF !
       COUNT ROT SWAP CMOVE
       SPAN @ + C/L SPAN @ - + 
  LOOP DROP 
  UPDATE SAVE-BUFFERS
  1+ #EOF @ UNTIL DROP
  #IN 2@ CLOSE
  #TEMP 2@ #IN 2!

  ;

END_FILE
Is far from perfect, e.g I am not able to correclty detect EOF, also I do not get 100% match to original named file when running SAVE_FILE on resulting blocks.

I use "QUERY 10 WORD" to read a line of input file, but using "TIB C/L EXPECT 10 WORD" would be better as C/L reflects curent system settings of characters per line, but I discovered that the latter only reads 29 chars of each line.

Tom
Last edited by tcat on Wed Dec 30, 2015 3:39 pm, edited 1 time in total.


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SuperFORTH Editor

Post by tcat »

Hi,

Improved version of READ_FILE, it now detects EOF, it scans for the END_FILE in the input stream. It also puts out --> continuation mark as : colon definitions may span across block's boundary. Single nnn LOAD will then load all file blocks. If the input file has got more than C/L chars per line, trailing chars are truncated.

Not perfect, but does things.

Save as ... e.g. MDV2_READ_FTH

Code: Select all

2VARIABLE #TEMP  VARIABLE #EOF
: NB ." -->" ; : EF ." END_FILE" ;
: READ_FILE   ( first_block "filename" --- )

  #IN 2@ #TEMP 2! 0 OPEN #IN 2!
  BEGIN DUP BUFFER
  L/B 1 DO
       DUP QUERY 10 WORD DUP
       ['] EF >BODY 2+ $= DUP #EOF !
       IF LEAVE THEN
       COUNT ROT SWAP CMOVE
       SPAN @ + C/L SPAN @ - +
  LOOP ['] NB >BODY 2+ COUNT ROT SWAP CMOVE
  UPDATE SAVE-BUFFERS
  1+ #EOF @ UNTIL DROP 2DROP
  #IN 2@ CLOSE #TEMP 2@ #IN 2! ;

END_FILE
10 READ_FILE MDV2_READ_FTH can be used to put the above into a single block BLK10.

100 READ_FILE MDV2_EDITOR_FTH will create BLK100 ... BLK112 of the editor file.

100 LOAD
100 EDIT will start editing itself.

Tom
Last edited by tcat on Wed Dec 30, 2015 3:43 pm, edited 1 time in total.


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SuperFORTH Editor

Post by tcat »

Hi,

Just learning more of the SuperFORTH, making a little progress. This is my first attempt to define strings, very simple not perfect, no range checking, etc. I found this site useful http://www.forth.com/starting-forth/sf11/sf11.html, it helped me with learning Forth's basics.

You may save as, then LOAD_FILE mdv2_STRINGS_FTH

Code: Select all

( Create string constant )
: S"       ( S" ..." --- adr n )
  34 WORD DUP COUNT PAD SWAP CMOVE
  C@ PAD SWAP ;

( Create string variable )
: STRING   ( --- adr n )
  CREATE DUP , ALLOT DOES> DUP 2+ SWAP @ ;

( Move string function , ad1 +1..+n1 ->  ad2 +1.. )
: $MOVE    ( ad1 n1 ad2 n2  --- ) 
  DROP SWAP CMOVE ;

( Print string function )
: $.       ( ad n --- )
  -TRAILING CR TYPE ;

( Two strings 20 bytes each ) 
20 STRING GREET
20 STRING INGS

( Test, move constant -> GREET )
( Print string GREET ) 
S" HELLO THERE         " GREET $MOVE
GREET $.

( Move GREET -> INGS )
( Print string INGS )
GREET INGS $MOVE
INGS $.

END_FILE
Or as a block, if you like save as e.g. BLK11, then 11 LOAD

Code: Select all

: S"                                                              34 WORD DUP COUNT PAD SWAP CMOVE                                C@ PAD SWAP ;                                                                                                                 : STRING CREATE DUP , ALLOT DOES> DUP 2+ SWAP @ ;                                                                               : $MOVE DROP SWAP CMOVE ;  : $. -TRAILING CR TYPE ;                                                                             20 STRING GREET                                                 20 STRING INGS                                                                                                                  S" HELLO THERE         " GREET $MOVE                            GREET $.                                                                                                                        GREET INGS $MOVE                                                INGS $.                                                         
For the sake of preservation, does anybody have REVERSI_FTH source, and also pssibly SuperFORTH version 1.6, the one preceeding 2.0?

Many thanks.
Tom


gregtaylor
ROM Dongle
Posts: 33
Joined: Thu Aug 13, 2015 12:42 pm
Location: East Yorkshire
Contact:

Re: SuperFORTH Editor

Post by gregtaylor »

Tom,

I have not used Superforth by wanted to see what you were up to. Superforth loads and works (e.g.
1 1 + . correctly returns 2 OK)
but the editor fails to load. On startup I get the error
Reading Block 1 ? Not found
and trying to load a block (e.g. 8 BLOCK) gives a similar error. The BLK1 to BLK9 files are on win1_ and I have even copied them to mdv1_ as the manual suggests it is where it looks.
How did you get beyond this basic point? Other versions of FORTH run fine.
Running it on QLAY2 by the way,
Greg


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SuperFORTH Editor

Post by tcat »

Greg,

EDIT>

You might also change file name be in UPPER CASE, BLK1, EDITOR_FTH, rather than blk1, editor_fth, etc.
You can switch the case handling later, you can also set it in boot BLK1, using the words UPPER, LOWER.

<EDIT

Thank you for reading my post on SuperFORTH, I am a beginner, still learning the basics.

SuperFORTH at boot time looks for BLK1, on default BOOT device MDV or FLP it tries both drives 1 .. 2, cannot be changed as is hard inside the code.

But you may chage the default WORK device, e.g.
2 MDV ( sets drive 2 )
1 MDV ( sets drive 1 )

1 LOAD, also COLD, as I hope, should work then.

You can set default WORK device in BLK1, using the editor,
1 EDIT or LOAD_FILE mdv1_EDITOR_FTH first.

Or you may edit BLK1 by hand in another editor, make sure it has 1024 bytes after save, and everything should appear on a single line, with no CR/LF.
My block BLK1 below, just in case,

Code: Select all

( Login block, called by COLD, modify as required )                                                                             0 OPEN CON_460x244a32x12   ( the main console window )          2DUP #IN 2! 2DUP #OUT 2!                                        #DEFAULT CLOSE ' #DEFAULT >BODY 2!                              4 MODE 0 PAPER 0 STRIP 7 INK 1 0 CSIZE  ( parameters )          MDV1_                                                           LOAD_FILE MDV1_EDITOR_FTH          ( load the editor )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

BACKUP S*BASIC script lets you backup the whole system, either with default BOOT device MDV or FLP and other e.g. FDK etc., I have not tested it yet, offsets here for boot device are 4112,4113, 4114, 4115 (counting from 0), assuming you have version 2.0, code size 15712 bytes. Backing the system on a new device sets the new BOOT device in the code, the device is POKED by the supplied script.

You may also try to create new devices, by the use of utility CREATE_DEVICE in BLK9. I have not tested it too.

Tom
Last edited by tcat on Thu Dec 31, 2015 8:59 am, edited 2 times in total.


User avatar
programandala.net
Chuggy Microdrive
Posts: 74
Joined: Mon Dec 13, 2010 12:41 pm
Location: Spain
Contact:

Re: SuperFORTH Editor

Post by programandala.net »

tcat wrote: SuperFORTH at boot time looks for BLK1, on default BOOT device MDV or FLP it tries both drives 1 .. 2, cannot be changed as is hard inside the code.
You're right, the device is hardcoded in the binary. I had this very same problem in 1995; and also a few days ago, while adapting my QL environment to SMSQmulator. I almost had forgotten how I solved it years ago.

It seems the only way to make SuperForth boot from a different device is to patch the binary using a binary editor. Just search for the string "flp1_BLK" and change it. But unfortunately only "ram1_" and "win1_" work (of course, with any number, not just 1). If you use "dev", "dos", "nfa" or any virtual device provided by the OS or the emulator, SuperForth will not find BLK1.

In 1995, when I used a QXL, I patched SuperForth to boot from ram1_, and the main system boot copied BLK1 to ram1_. The only words in BLK1 were `LOWER` to make SuperForth case-insensitive and `load_file dev4_boot_fth` to interpret the actual Forth boot file from a directory QXL.WIN.

Now I have done a similar trick with SMSQmulator, but keeping BLK1 in the root of the win1 drive.


Marcos Cruz (programandala.net)
User avatar
programandala.net
Chuggy Microdrive
Posts: 74
Joined: Mon Dec 13, 2010 12:41 pm
Location: Spain
Contact:

Re: SuperFORTH Editor

Post by programandala.net »

Hi Tom, we are already in touch in the Forth on Sinclair (and Z80) computers email list. Nice to see you here.
tcat wrote:I am fairly new to the language, just learning its grammar.
I hope you already learned it well, since it's almost unexistent ;)
tcat wrote: Interesting concept is that of files being stored in 1024B blocks,
Blocks make sense in order to use the disk drives directly to store source and data, without an OS or a file system. Blocks are very efficient for certain applications or specific platforms. But for general programming on modern operating systems they have many disadvantages.

Forth systems that run on an OS include optional support for blocks, but simulated with files. The usual implementation uses one single file to contain as many blocks as required, or even any number of blocks files, which can be freely associated to block numbers.

SuperForth uses one file por block, what maybe was a good decision for a 128 K QL with microdrives or floppies, but this way it's uncomfortable to manage the sources, even just to know what's in every block. You must use the tools of the Forth system (`list`, `index` and others).

SuperForth can also interpret ordinary text files, with `load_file`, but this word has some limitations; the main one is it can not be nested. I think it would not be hard write a modern word `include`.

Finally, SuperForth follows the Forth-83 Standard, which lacks many features of newer standards, Forth-94 and Forth-2012. But happily Forth can be easily extended any way you need.


Marcos Cruz (programandala.net)
Derek_Stewart
Font of All Knowledge
Posts: 4058
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: SuperFORTH Editor

Post by Derek_Stewart »

Hi,

A possible solution this this would be to use SUB by Phil Borman.

SUB allows substitution of directories to a single device called SUB, much like DEV, but work better.

To get the Superforth editor working without patching the executable file, just use SUB to use FLP i.e.

FLP_USE "FDD": REMark Change FLP device to use FDD, floppies still work.

SUB_USE "FLP"

point SUB1 to the directory where the Superforth is, I have it is a directory called SF, so set SUB1 to SF

SUB_USE 1,"SF"

Performing a directory of FLP1_ should give a listing of the SF directory.

This is assuming that FLP_USE is available on your system.


Regards,

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

Re: SuperFORTH Editor

Post by polka »

Hey ! At last, some FORTH fanatics onboard ?

An opportunity for my two cents view about blocks and text files :

1024 byte blocks were invented by Chuck Moore as a way to manage from inside FORTH the primitive mass stores that they had in those times. They were kept for a long time by the FORTH community on small µprocessor systems. But to use instead plain text files, you basically only have to be able to redirect the (otherwise interactive keyboard and screen) input/output.

The way blocks are managed in the two FORTH machines that I know are running on the QL (the Computer One FORTH and the Digital Precision SuperFORTH) are completely opposed and I prefer the Computer One way :

In this, a large number of blocks are grouped in one QL file, that you open for instance by :

USING mdv1_MyFile_scr

And then you may load the blocks you select for instance by :

55 LOAD

that will load block 55 and if it contains "immediate" word --> , it will load next block and so on...

Computer One has a "screen editor" that you call by the simple word EDIT through which you may browse and edit any pages of 16 lines of 64 characters representing one sreen (actually block) only with [control]N to go to the next one or [control]P to go to the previous one.

Digital Precision SuperFORTH obviously prefers text source files (as all the added packages like the editor ... the reversi) are provided in this form. But they provided also a block manager, which I find not so good : each block is in fact a QL file on its own, somehow only accessible by the Digital Precision EDITOR (itself loaded as a text file) and completely incompatible with the Computer One "screen files".

However, the more modern text source files are even compatible with other FORTH machines that nowadays often only offer this solution : for instance a FORTH running on x86 PCs called TurboFORTH that I like also very much.

So I would advise not to bother any longer with block files managers (especially the Digital Precision ones) and to adopt preferably text source files. They are not supported by Computer One FORTH, but I feel their management should be rather easy to implement and I will do it.

May the FORTH be with you !

BYE Polka
Last edited by polka on Wed Dec 30, 2015 1:15 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
gregtaylor
ROM Dongle
Posts: 33
Joined: Thu Aug 13, 2015 12:42 pm
Location: East Yorkshire
Contact:

Re: SuperFORTH Editor

Post by gregtaylor »

It is very difficult to ge it working in qlay (DOS or Windows). In the end I tried it in Q-emulator and it worked first time. Out of interest, q-emulator seems to work much better under Windows 10, Qlay does work but loading and saving is incredibly slow - even worse than original microdrives!

Thanks all for the help, now I can enjoy getting to grips with Superforth.

Again, for interest, pygmy17 forth is a similar utility running in MS-DOS (or in DOSBOX if running something newer).

Greg


Post Reply