HiRes package for Toddy Forth

Discussion about ZX80 / ZX81 Software
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: HiRes package for Toddy Forth

Post by kmurta »

* Files replaced due a issue with ABS word, see previous post
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: HiRes package for Toddy Forth

Post by Moggy »

Great work Kelly.

I cannot wait to see what V2.0 will be like considering how good this is already. I know you are very busy but is there any chance you could perhaps print a few tips on how to use this add on for those of us(me :oops: ) who struggle a bit with these things. I understand the principle but not the execution of the commands if you see what I mean.
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: HiRes package for Toddy Forth

Post by kmurta »

Moggy wrote: Tue Mar 02, 2021 2:03 pm I cannot wait to see what V2.0 will be like considering how good this is already. I know you are very busy but is there any chance you could perhaps print a few tips on how to use this add on for those of us(me :oops: ) who struggle a bit with these things. I understand the principle but not the execution of the commands if you see what I mean.
The intention is to make tforth as close as possible with Forth 79, so version 1.6 brings the following vocabulary changes:

Code: Select all

Tforth 1.5	tForth 1.6
CLS		PAGE
INVERT		(excluded)
CONTEXT		(excluded)
CURRENT		(excluded)
M+		(excluded)
D-		(excluded)
UM*		U*
UM/MOD		U/MOD
UD/MOD		M/MOD
INPUT		QUERY
LFA		>LFA
CFA		>CFA
-		>NFA
-		SPACES
-		FILL
-		DPL
-		CONVERT
In addition, the behavior of the DO-LOOP structures and the words PICK and ROLL have been altered to respond in accordance with the standard F79.

For version 2.0 I am planning some more facilities and a better way to manipulate the sources blocks.

Regarding the HGR package, I don't know if I understood what your doubts are, but I'll give you some examples to see if it helps.

First point to be understood is that we now have two screens, the normal text and the other graphic in high resolution. Use the word HGR to activate the graphic screen and the word TEXT to return to the standard screen, where you interact with the system by typing instructions. And to clear the graphical screen use the HPAGE word.

The graphic screen has a resolution of 256x192 pixels and occupies an area of 6144 bytes from address 40960 (A000h). Each pixel can be manipulated individually using the different words provided by the HR package.

The words that change the state of a pixel (or set of pixels) are GPIX, GLINE and GLINETO. These words can set, clear or invert the pixels on the screen and the word PMODE (Pixel MODE), through the parameter passed to it, is responsible for determining the behavior of GPIX, GLINE and GLINETO.

So, if you want GPIX, GLINE or GLINETO set the pixels, before uses PMODE with parameter 1:

1 PMODE

The other parameters are 0 to clear the pixel, and 2 to invert the pixel. The action of PMODE is persistent, that is, once its state is defined it remains the same until it is changed by another definition of PMODE.

Here are some examples:

Set the pixel at coordinates (0,0) typing:

Code: Select all

GPAGE  ( clear the graphics screen )

1 PMODE  ( set pixels )

HGR 0 0 GPIX KEY DROP TEXT
HGR switches to the graphics screen, 0 0 GPIX sets the pixel at coordinate (0,0) and TEXT returns to normal screen. Note the use of KEY to wait for the press of a key before returning to the text screen, allowing you to view the result of the typed sequence. And DROP discards the keystroke code, clearing the stack.

Now type in the following sequences and observe the result:

Code: Select all

HGR 100 0 GPIX 50 86 GPIX KEY DROP

HGR -50 -86 GLINE 100 0 GLINE -50 86 GLINE KEY DROP TEXT
GLINE is used to draw line segments starting at the last point used and according to the values provided, the horizontal offset (dx) and the vertical offset (dy). So, the first GLINE starts from the point (50,86) and moves 50 points to the left and 86 points to the bottom.

The GLINETO word is an alternative to GLINE and permite draw lines using direct coordinates instead of offsets. The last example can be done with GLINETO as follows:

Code: Select all

HPAGE HGR 50 86 GPIX  0 0 GLINETO 100 0 GLINETO 50 86 GLINETO KEY DROP TEXT
All examples so far have been made using the words in interpretive mode, now let's see how to use them in colon definitions creating a word to draw a box:

Code: Select all

: GBOX	( width height -- )
   OVER 0 GLINE  0 OVER GLINE
   SWAP NEGATE 0 GLINE
   NEGATE 0 SWAP GLINE ;
and test it with:

Code: Select all

GPAGE HGR 1 PMODE 0 0 GPIX 100 50 GBOX KEY 50 100 GBOX KEY 2DROP TEXT
And now, without clear the screen after that last example:

Code: Select all

HGR 0 PMODE 100 50 GBOX KEY 2 PMODE 50 100 GBOX KEY 2DROP TEXT
Try to understand what happened ;-)

A last example:

Code: Select all

: MOIRE PMODE 192 0 DO 0 0 GPIX 255 I GLINE LOOP ;

GPAGE HGR 1 MOIRE 2 MOIRE 0 MOIRE TEXT
I hope these simple examples can help you answer your questions.
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: HiRes package for Toddy Forth

Post by Moggy »

This is pure gold for me Kelly many thanks for taking the time to write this. :D

Toddy Hi-res is working similar to the Memotech H-res module where you write all the commands in BASIC then call the Hi-res screen only now we write the commands in Forth then call the screen.

I am also impressed at the speed of the GLINE command which for a slow machine like the 81 is very impressive.

The move to make Toddy more like Forth-79 is very welcome as a lot of examples from older books work to this standard and translate very easily.

I have also discovered why Brodies two books cause some problems with programming examples, it seem that when he found out that his publisher was not reprinting them he gave permission for internet versions to be made providing they were brought up to ANSI standard and you need to search for the early version of the book that was more like FIG/79 or buy the original book to be useful for Toddy type Forths.

Again excellent work Kelly please accept my thanks for this.
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: HiRes package for Toddy Forth

Post by kmurta »

Moggy wrote: Wed Mar 03, 2021 12:16 pm Toddy Hi-res is working similar to the Memotech H-res module where you write all the commands in BASIC then call the Hi-res screen only now we write the commands in Forth then call the screen.
Yes, and also like other computers like Apple or TRS Color that have different video modes for text and graphics.
I am also impressed at the speed of the GLINE command which for a slow machine like the 81 is very impressive.
Thanks to Garry Lancaster, as I'm using his Z88 Camel Forth "draw Line routine". But my "find pixel address" routine also helps a lot.
I have also discovered why Brodies two books cause some problems with programming examples, it seem that when he found out that his publisher was not reprinting them he gave permission for internet versions to be made providing they were brought up to ANSI standard and you need to search for the early version of the book that was more like FIG/79 or buy the original book to be useful for Toddy type Forths.
I have the "Camel Forth" practically ready to run on the ZX81, possibly after the release of Toddy Forth 2.0 I will also make it available, so we will have a Forth 79 and also an ANS Forth for the ZX81, expanding the range of options.

I'm glad you're having fun with Toddy Forth, it encourages me to continue the development, although I also have a lot of fun with the process ;-)

But let me give you one more tip to use with the HIRES package, I found this little program for the ZX Spectrum in a magazine:

Code: Select all

  10 FOR n=0 TO 174
  20 PLOT n,0: PLOT n,175
  30 NEXT n
  40 FOR n=0 TO 174
  50 PLOT 0,n: PLOT 175,n
  60 NEXT n
  70 LET a=0
  80 FOR n=167 TO 0 STEP -8
  90 LET a=a+8
 100 PLOT 0,n: DRAW a,-n
 110 DRAW n,a
 120 DRAW -a,n
 130 DRAW -n,-a
 140 NEXT n
and I converted it to Toddy Forth:

Code: Select all

: HLINES
  175 0 DO I 0 GPIX I 175 GPIX LOOP ;
: VLINES
  175 0 DO 0 I GPIX 175 I GPIX LOOP ;
: WEB
  GPAGE  HGR  1 PMODE
  HLINES  VLINES  0
  0 167 DO 8 +
    0 I GPIX DUP I NEGATE GLINE
    I OVER GLINE
    DUP NEGATE I GLINE
    I NEGATE OVER NEGATE GLINE
  -8 +LOOP DROP ;
Type it and run with WEB.

web.gif
(Click on image to see the animation)
Last edited by kmurta on Thu Mar 04, 2021 1:56 am, edited 1 time in total.
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: HiRes package for Toddy Forth

Post by Moggy »

Wow superb and very quick too I shall have some fun with this and I'm slowly working out what it is doing as well.

I am looking forward to Camel as well as Toddy v2.0,the future looks well for Forth on the 81.
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: HiRes package for Toddy Forth

Post by kmurta »

A new fix for tforth 1.6 has been released, see at

https://sinclairzxworld.com/viewtopic.p ... 767#p41767
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: HiRes package for Toddy Forth

Post by Moggy »

Many thanks for quick response Kelly much appreciated. :D
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: HiRes package for Toddy Forth

Post by kmurta »

Now its time to play with some circles! :D

Code: Select all

( DRAW CIRCLES AND ELLIPSES   )

CREATE SINES
    0000 , 0175 , 0349 , 0523 , 
    0698 , 0872 , 1045 , 1219 , 
    1392 , 1564 , 1736 , 1908 , 
    2079 , 2250 , 2419 , 2588 , 
    2756 , 2924 , 3090 , 3256 , 
    3420 , 3548 , 3746 , 3907 , 
    4067 , 4226 , 4384 , 4540 , 
    4695 , 4848 , 5000 , 5150 , 
    5229 , 5446 , 5592 , 5736 , 
    5878 , 6018 , 6157 , 6293 , 
    6428 , 6561 , 6691 , 6820 , 
    6947 , 7071 , 7193 , 7313 , 
    7431 , 7547 , 7660 , 7771 , 
    7880 , 7986 , 8090 , 8191 , 
    8290 , 8387 , 8480 , 8572 , 
    8660 , 8746 , 8829 , 8910 , 
    8988 , 9063 , 9135 , 9205 , 
    9272 , 9336 , 9397 , 9455 , 
    9511 , 9563 , 9613 , 9659 , 
    9703 , 9744 , 9781 , 9816 , 
    9848 , 9877 , 9903 , 9926 , 
    9956 , 9962 , 9976 , 9986 , 
    9994 , 9998 , 10000 ,

: SIN*  ( n ang -- n*sin[ang] )
  ABS 90 /MOD
  TUCK 1 AND IF  90 SWAP -  THEN
  2* SINES + @ SWAP 2 AND
  IF  NEGATE  THEN 10000 */ ;

: COS* ( n ang -- n*cos[ang] )
  90 + SIN* ;

( Draw ellipse )
: GELLIPSE  ( x y w h -- )
  SWAP ABS SWAP ABS 1 MAX
  DUP 8 * 360 MIN ( nr of steps)
  360 SWAP / >R
  DUP >R 2OVER R> + GPIX R>
  360 0 DO  16477 !
          2OVER 2OVER 
          I COS* ROT + SWAP
          I SIN* ROT + SWAP
          GLINETO
          16477 @ DUP
        +LOOP
  DROP NIP + GLINETO ;

( Draw circle )
: GCIRCLE  ( x y r -- )
  DUP GELLIPSE ;
Load it and test with the followed code:

Code: Select all

: GLOBE  ( -- )
  GPAGE HGR 1 PMODE
  80 0 DO
  127 95 80 I GELLIPSE
  127 95 I 80 GELLIPSE
  20 +LOOP
  127 95 80 GCIRCLE ;
globe.gif
globe.gif (2.91 KiB) Viewed 2684 times

And using the trigonometric functions:

Code: Select all

: DISCO  ( -- )
  GPAGE HGR
  360 0 DO 127 95 GPIX
  90 DUP I COS*
  SWAP I SIN* GLINE
  LOOP ;
( Experiment with 1 PMODE DISCO, and then with 2 PMODE DISCO )
disco.gif
disco.gif (7.95 KiB) Viewed 2684 times

And finally a program from the Apple II:

Code: Select all

10 HGR2: HCOLOR=3
20 FOR F=1 TO 139
30 H=80+80*COS(f/16)
40 HPLOT F,H TO H,F
50 NEXT F
converted to Toddy Forth:

Code: Select all

: RAD2DEG 180 * 10000 U* 31416 U/MOD NIP ;
: HGLASS GPAGE HGR 1 PMODE
  140 1 DO
  80 80 I RAD2DEG 16 / COS* +
  I OVER GPIX I GLINETO
  LOOP ;
HGLASS.gif
HGLASS.gif (3.17 KiB) Viewed 2684 times

Enjoy!
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: HiRes package for Toddy Forth

Post by Moggy »

Pure magic! :ugeek:
Post Reply