I am starting this thread to collect various examples of bitmap graphics programming in fbForth 2.0.

This first example is a quick-and-dirty joystick drawing program, JDRAW , ported from the program of the same name I wrote four years ago for TI Forth in post #48 of thread, TI FORTH Version 3.0 dated October 20 1982. As I stated then, it is a pretty useless program except as a demo and proof of concept.

It uses the CRU mode of JOYST for joystick-only use. There is a three-choice menu accessed with the fire button. The choices are

P—Toggle pen up/down [blue pen = pen down; white pen = pen up]

D—Toggle draw/erase [ solid pen = draw mode; hollow pen = erase mode]

Q—Quit program

The joystick moves the pen around the display screen.

There is much that could be done to make it more useful. One such thing would be to provide finer control over the pen—reaction to joystick movement is too fast for any useful drawing. Another would probably be to dispense with the menu and use the fire button for pen-up/pen-down. But, that leaves managing draw/erase mode, which would probably require using the JOYST word in keyboard (KSCAN) mode. Anyway, here is the fbForth 2.0 source code for JDRAW :

Spoiler

HEX

0 VARIABLE JPEN

5F VARIABLE JDR

7F VARIABLE JDC

: J_INIT

GRAPHICS2

1E SCREEN

1E DCOLOR !

DELALL

1 DMODE !

F890 A0C0 8000 0000 10 SPCHAR

0000 0000 0000 0000 11 SPCHAR

0000 0000 0000 0000 12 SPCHAR

0000 0000 0000 0000 13 SPCHAR

0078 4444 7940 4040 14 SPCHAR

0078 2424 2524 2478 15 SPCHAR

0000 000E D11F 100E 16 SPCHAR

0000 0016 D910 1010 17 SPCHAR

0000 0016 1911 1111 18 SPCHAR

0000 000E 010F 110F 19 SPCHAR

0000 0000 0000 0000 1A SPCHAR

0000 0011 1115 150A 1B SPCHAR

0038 4444 4554 4834 1C SPCHAR

00FF 0034 2A2A 2A2A 1D SPCHAR

0000 0011 D111 130D 1E SPCHAR

00FF 001C 223E 201C 1F SPCHAR

0004 000C 0404 040F 20 SPCHAR

00FF 002C 3222 2222 21 SPCHAR

0004 041F 0404 0502 22 SPCHAR

00FF 0022 2222 261A 23 SPCHAR

JDC @ JDR @ 0F 010 0 SPRITE

0F 0D0 08 014 01 SPRITE

01F 0D0 08 018 02 SPRITE

0F 0D0 08 01C 03 SPRITE

01F 0D0 08 020 04 SPRITE

2 MAGNIFY

;

: JUP_CUR

JPEN @

IF

5 0 SPRCOL

ELSE

0F 0 SPRCOL

THEN

;

: JER_CUR

F890 A0C0 8000 0000 10 SPCHAR

;

: JDR_CUR

F8F0 E0C0 8000 0000 10 SPCHAR

;

( Loop until 'P', 'D' or 'Q', then leave it on stack)

: JMENU ( --- n )

0F 0F 01 SPRPUT

01F 0F 02 SPRPUT

0F 01F 03 SPRPUT

01F 01F 04 SPRPUT

BEGIN

KEY DUP

CASE ( Toggle DMODE|JPEN|Quit & leave key)

44 OF DMODE @ 1 XOR DUP DMODE !

IF

JER_CUR

ELSE

JDR_CUR

THEN

ENDOF

50 OF JPEN @ 1 XOR JPEN ! JUP_CUR ENDOF

51 OF ( Just leave 'Q') ENDOF

ELSEOF DROP 0 ENDOF ( Leave 0 if illegal key)

ENDCASE

-DUP

UNTIL ( Leave value if legal key)

5 1 DO ( Hide menu)

10 0D0 I SPRPUT

LOOP

;

1 JMODE !

: JLIM ( n1 n2 --- n1|0|n2 ) ( test if n1 is 0..n2)

OVER 0<

IF

DROP DROP 0

ELSE

OVER OVER <

IF

DROP

ELSE

SWAP DROP

THEN

THEN

;

: JDRAW

VDPMDE @ ( current VDP mode to stack)

J_INIT

BEGIN ( Main program loop)

1 JOYST DUP

IF

DUP 1 AND

IF ( fire)

DROP ( don't need joystick value)

JMENU ( get 'P', 'D' or 'Q')

051 = ( match will leave 1 to quit loop)

ELSE

DUP 06 AND

CASE ( W or E)

02 OF -1 ENDOF ( W)

04 OF 1 ENDOF ( E)

ELSEOF 00 ENDOF ( neither)

ENDCASE

JDC @ + 0FF JLIM JDC ! ( new dotcol)

018 AND

CASE ( S or N)

08 OF 1 ENDOF ( S)

010 OF -1 ENDOF ( N)

ELSEOF 00 ENDOF ( neither)

ENDCASE

JDR @ + 0BF JLIM JDR ! ( new dotrow)

JDC @ JDR @ 0 SPRPUT ( move pen)

JPEN @ ( draw or erase?)

IF ( draw)

JDC @ JDR @ DOT

THEN

0 ( 0 to continue loop)

THEN

THEN

UNTIL

VMODE ( restore VDP mode)

;

DECIMAL

I will add a blocks file, later. For now, you can paste this in Classic99 at the command line of fbForth 2.0. Start the program by typing:

Here's the work disk I coded the demo on. The code starts on screen 91 (DSK2). I wrote it directly into TIF, so I don't have a text listing unfortunately and there is no utility available that can read the screens outside for Forth... Of note is that I used look up tables for the sine-cosine values to speed things up. Let's see how this works under FbForth

EDIT: Actually that's not the same demo. It was my attempt at creating 3D wireframe animations! I can't seem to find the code for the original demo... In any case, this demo takes for ever to load and requires the GRAPH2 library and is deathly slow. I never really got it to work properly and I gave up on it because of how slow it was running. There is a bug in the transformation matrices somewhere. Believe it or not this was supposed to be a cube rotating

To run:

91 LOAD

START

Attached Files

Here's the work disk I coded the demo on. The code starts on screen 91 (DSK2). I wrote it directly into TIF, so I don't have a text listing unfortunately and there is no utility available that can read the screens outside for Forth... Of note is that I used look up tables for the sine-cosine values to speed things up. Let's see how this works under FbForth

EDIT: Actually that's not the same demo. It was my attempt at creating 3D wireframe animations! I can't seem to find the code for the original demo... In any case, this demo takes for ever to load and requires the GRAPH2 library and is deathly slow. I never really got it to work properly and I gave up on it because of how slow it was running. There is a bug in the transformation matrices somewhere. Believe it or not this was supposed to be a cube rotating

To run:

91 LOAD

START

There is a 6-block “2D TRIANGLE ROUTINE” that begins in the second block. Is that it?

BTW, the “TI Forth Block Utilities” in the latest FBLOCKS (12/08/2015) will allow visualizing in fbForth and copying to an fbForth blocks file, which can be converted to a TXT file by TI99Dir and, probably, TIImageTool.

Attached is a blocks file for fbForth (VORTICON), which is a copy of your TIF-WORK.DSK. I have, so far, made no substantive changes. I did have to change block 1 to load blocks 7 and 8 instead of 97 and 98 to make it compatible with fbForth for obvious reasons to anyone who knows TI Forth. The attached actually loads blocks 7 and 2 because block 2 starts loading the routine in your video, which takes 75 seconds in TI Forth but only 10 seconds in fbForth 2.0 with the identical code. To run the 2D example, assuming the blocks file, VORTICON, is in DSK1, type the following:

I forgot about one other change I made to the TI Forth code in my last post. I removed the second line from block 1

-64SUPPORT -FLOAT 180 DISK_HI !

because it loads the graphics mode code, the graphics primitives, the 64-column editor and the floating point library, which are all (except the 64-column editor) resident in fbForth 2.0. The 64-column editor is not necessary to run the program. If it is desired by the user, it can easily be loaded separately.

It also sets the highest disk block #, which is irrelevant in fbForth. Furthermore, the word DISK_HI does not exist in fbForth.

The principal reason this program runs so much faster in fbForth is that I coded the graphics primitives, which are in the fbForth 2.0 ROM, in ALC. This is particularly important for the definition of LINE .

Lee, I did not see much of a difference in the bitmap drawing speed between TIF and FbForth. What am I missing?

You’re using fbForth 2.0:+, right? TI Forth and fbForth 1.0 cannot hold a candle to fbForth 2.0 because all of the graphics primitives of the former are in high-level Forth and the latter, in ALC. Once the blocks (1, 7, 2 – 6) are loaded and the program is started with START , it’s over in 10 seconds.