Jump to content
Sign in to follow this  
dhe

Fortran99 Challenge

Recommended Posts

ok.. we need a new thread tp99 Challenge!

 

I like tp99, I wrote Dan O'Quinn who wrote a tutorial on it, but now that seems lost in time. I was the original purchaser from LL Connor Enterprises and was very geeked out, when I found out there was additional packages to follow - sound and windows. I think tp99 was another one of those packages, that JUST needs a little more love and care, and had the source code been released at some point...

Share this post


Link to post
Share on other sites

That's too bad. But then it's not really the best Pascal version to use anyway and UCSD Pascal already runs perfectly in MAME :)

Fortran 99 crammed so much in that package that it makes me wonder why WipoSoft was not able (or willing) to come up with a full Pascal implementation. No to mention that bone-headed memory protection scheme...

Share this post


Link to post
Share on other sites

Ok a little more fun with Fortran 99. This time I'm really stressing its number crunching abilities by having it render and animate a wire frame 3D cube. The controls are:

 

K = turn left

L = turn right

S = rotate left

D = rotate right

E = rotate up

X = rotate down

+ = enlarge scale

-  = reduce scale

< = move toward screen

> = move away from screen

Q = quit

 

 

The rendering speed is a blazing 1 frame every 2 seconds or so using the single precision sine/cosine functions. Obviously there are some optimizations to be had, such as using a look up table for the sine/cosine functions, but honestly even in this current state this is a very respectable rendering speed given what we are working with. I am certainly impressed with the numerical prowess of Fortran 99.

 

Here's the main program:

C 3D SHAPE ROTATION PROGRAM
 
      PROGRAM SHAPE3D
 
      REAL SFX, SFY, SFZ, TFX, TFY, TFZ
      REAL XANG, YANG, ZANG, CUBE_W(32)
      INTEGER CUBE_L(32), CUBE_S(16), CUBE_VL(48)
      INTEGER XORG, YORG, VDIST
 
      DATA CUBE_L /-10,-10,10,1, 10,-10,10,1, 10,10,10,1,
     !             -10,10,10,1, -10,-10,-10,1, 10,-10,-10,1,
     !             10,10,-10,1, -10,10,-10,1/
 
      DATA CUBE_VL /1,2,3,4, 3,4,5,6, 5,6,7,8, 7,8,1,2, 9,10,
     !              11,12, 11,12,13,14, 13,14,15,16, 15,16,9,10,
     !              1,2,9,10, 3,4,11,12, 5,6,13,14, 7,8,15,16/
 
      XORG = 125
      YORG = 99
      SFX = 2
      SFY = 2
      SFZ = 2
      TFX = 0
      TFY = 0
      TFZ = 100
      XANG = 1.1
      YANG = 0.6
      ZANG = 0.3
      VDIST = 150
 
      CALL FILES(1)
      CALL SETMOD(4)
      CALL SCREEN(2, 2)
 
      DO WHILE(.TRUE.)
        CALL CLEAR
 
        CALL TRFM(SFX,SFY,SFZ,TFX,TFY,TFZ,XANG,YANG,ZANG,32,16,48,
     !          CUBE_L,CUBE_W,CUBE_S,CUBE_VL,XORG,YORG,VDIST)
 
10      CALL KEY(0, KEYC, ISTATUS)
        IF (ISTATUS .EQ. 0) GOTO 10
 
        IF (KEYC .EQ. 88) THEN
          XANG = XANG + 0.2
          IF (XANG .GT. 6.2) XANG = 0
        ENDIF
 
        IF (KEYC .EQ. 69) THEN
          XANG = XANG - 0.2
          IF (XANG .LT. 0) XANG = 6.2
        ENDIF
 
        IF (KEYC .EQ. 83) THEN
          YANG = YANG - 0.2
          IF (YANG .LT. 0) YANG = 6.2
        ENDIF
 
        IF (KEYC .EQ. 68) THEN
          YANG = YANG + 0.2
          IF (YANG .GT. 6.2) YANG = 0
        ENDIF
 
        IF (KEYC .EQ. 75) THEN
          ZANG = ZANG - 0.2
          IF (ZANG .LT. 0) ZANG = 6.2
        ENDIF
 
        IF (KEYC .EQ. 76) THEN
          ZANG = ZANG + 0.2
          IF (ZANG .GT. 6.2) ZANG = 0
        ENDIF
 
        IF (KEYC .EQ. 43) THEN
          SFX = SFX + 1
          SFY = SFY + 1
          SFZ = SFZ + 1
        ENDIF
 
        IF (KEYC .EQ. 45) THEN
          SFX = SFX - 1
          SFY = SFY - 1
          SFZ = SFZ - 1
        ENDIF
 
        IF (KEYC .EQ. 60) TFZ = TFZ - 10
 
        IF (KEYC .EQ. 62) TFZ = TFZ + 10
 
        IF (KEYC .EQ. 81) STOP
 
      REPEAT
 
      STOP
      END

And here's the transformations subroutine:

 

C 3D VECTOR TRANSFORMATION ROUTINE
 
      SUBROUTINE TRFM(SX,SY,SZ,TX,TY,TZ,AX,AY,AZ,S1,S2,S3,
     !                ARL,ARW,ARS,LIST,XO,YO,VD)
 
      REAL ZROT(4,4), XROT(4,4), YROT(4,4)
      REAL MASTER(4,4), MASTER1(4,4), MASTER2(4,4), MASTER3(4,4)
      REAL SCALE(4,4), TRANS(4,4)
      REAL SX, SY, SZ, TX, TY, TZ, AX, AY, AZ
      INTEGER S1, S2, S3, ARL(S1), ARS(S2), LIST(S3)
      INTEGER VD,XO,YO
      REAL ARW(S1)
 
      SCALE(1,1) = SX
      SCALE(2,2) = SY
      SCALE(3,3) = SZ
      SCALE(4,4) = 1
 
      TRANS(4,1) = TX
      TRANS(4,2) = TY
      TRANS(4,3) = TZ
      TRANS(1,1) = 1
      TRANS(2,2) = 1
      TRANS(3,3) = 1
      TRANS(4,4) = 1
 
      XROT(1,1) = 1
      XROT(2,2) = COS(AX)
      XROT(2,3) = SIN(AX)
      XROT(3,2) = -SIN(AX)
      XROT(3,3) = COS(AX)
      XROT(4,4) = 1
 
      YROT(1,1) = COS(AY)
      YROT(1,3) = -SIN(AY)
      YROT(2,2) = 1
      YROT(3,1) = SIN(AY)
      YROT(3,3) = COS(AY)
      YROT(4,4) = 1
 
      ZROT(1,1) = COS(AZ)
      ZROT(1,2) = SIN(AZ)
      ZROT(2,1) = -SIN(AZ)
      ZROT(2,2) = COS(AZ)
      ZROT(3,3) = 1
      ZROT(4,4) = 1
 
      DO 10 I = 1, 4
        DO 20 J = 1, 4
          MASTER1(I,J) = 0
          DO 30 K = 1, 4
30          MASTER1(I,J) = MASTER1(I,J) + SCALE(I,K) * TRANS(K,J)
20      CONTINUE
10    CONTINUE
 
      DO 40 I = 1, 4
        DO 50 J = 1, 4
          MASTER2(I,J) = 0
          DO 60 K = 1, 4
60          MASTER2(I,J) = MASTER2(I,J) + XROT(I,K) * MASTER1(K,J)
50      CONTINUE
40    CONTINUE
 
      DO 70 I = 1, 4
        DO 80 J = 1, 4
          MASTER3(I,J) = 0
          DO 90 K = 1, 4
90          MASTER3(I,J) = MASTER3(I,J) + YROT(I,K) * MASTER2(K,J)
80      CONTINUE
70    CONTINUE
 
      DO 100 I = 1, 4
        DO 110 J = 1, 4
          MASTER(I,J) = 0
      DO 120 K = 1, 4
120         MASTER(I,J) = MASTER(I,J) + ZROT(I,K) * MASTER3(K,J)
110     CONTINUE
100   CONTINUE
 
      DO 160 I = 1, S1, 4
        ARW(I) = ARL(I) * MASTER(1,1) + ARL(I+1) * MASTER(2,1) +
     !           ARL(I+2) * MASTER(3,1) + MASTER(4,1)
        ARW(I+1) = ARL(I) * MASTER(1,2) + ARL(I+1) * MASTER(2,2) +
     !             ARL(I+2) * MASTER(3,2) + MASTER(4,2)
        ARW(I+2) = ARL(I) * MASTER(1,3) + ARL(I+1) * MASTER(2,3) +
     !             ARL(I+2) * MASTER(3,3) + MASTER(4,3)
        ARW(I+3) = ARL(I) * MASTER(1,4) + ARL(I+1) * MASTER(2,4) +
     !             ARL(I+2) * MASTER(3,4) + MASTER(4,4)
160   CONTINUE
 
      J = 1
      DO 170 I = 1, S1, 4
        ARS(J) = IFIX(VD * ARW(I) / ARW(I+2))
        ARS(J+1) = IFIX(VD * ARW(I+1) / ARW(I+2))
        J = J + 2
170   CONTINUE
 
      DO 180 I = 1, S3, 4
        IX1 = LIST(I)
        IY1 = LIST(I+1)
        IX2 = LIST(I+2)
        IY2 = LIST(I+3)
        CALL SETVEC(ARS(IX1) + XO, ARS(IY1) + YO,
     !              ARS(IX2) + XO, ARS(IY2) + YO, 16, 1)
180   CONTINUE
 
      RETURN
      END

 

  • Like 7

Share this post


Link to post
Share on other sites

Here's another little fun demo: Explore the pyramids of Giza in 3D wireframe :) It's quite slow to render as expected, but the 3D engine was entirely written in Fortran 99 with no assembly support. It's still quite rough at the edges with no account made for fringe cases, such as going inside one of the pyramids which causes all sorts of weird stuff to happen.

 

 

 

I based the 3D engine on the information from this excellent book from 1993. It has very lucid explanations and complete coding examples, albeit in C++, of how to approach 3D rendering. It even includes a floppy disk with all the programs he he...

 

1629753802_FlightsofFantasy.thumb.jpg.aeb7349360cc6709b34e7a9a5d2d9503.jpg

 

Attached is the disk image with source code and binaries. The PYRAMID program will run as an EA5 program. The controls are as follows:

 

E: pitch down

X: pitch up

S: rotate left

D : rotate right

T: move up

V: move down

F: move left

G: move right

K: bank left

L: bank right

<: move back

>: move forward

PYRAMID.dsk

  • Like 6

Share this post


Link to post
Share on other sites

Really appreciate the Fortran education here Vorticon; great demos. It has been a very long time, to have it up and running on this restricted hardware is a treat.

 

It would be quite useful if it had some string-handling capabilities added. 

Share this post


Link to post
Share on other sites
2 hours ago, JJB said:

Really appreciate the Fortran education here Vorticon; great demos. It has been a very long time, to have it up and running on this restricted hardware is a treat.

 

It would be quite useful if it had some string-handling capabilities added. 

Yeah it's actually pretty impressive to have Fortran for the TI. String handling and file I/O are some of its biggest shortcomings, but the ability to use assembly language support can help compensate for that if needed. It's number crunching abilities on the other hand are outstanding.

Surprisingly, it was super easy to pick up as a language as I was writing meaningful programs for it within a couple of days, partly because it is a very archaic language with a very limited syntax. No complex structures, records, pointers, linked lists etc... here :)

 

  • Like 1

Share this post


Link to post
Share on other sites

fwiw - my playing with Fortran99 has basically come to halt. It would appear, one of the more useful commands (setpos) has a bug, that causes a lockup when that command is encountered! Maybe,  someday,  if we get the source a quick patch can be found.

Share this post


Link to post
Share on other sites
3 hours ago, dhe said:

fwiw - my playing with Fortran99 has basically come to halt. It would appear, one of the more useful commands (setpos) has a bug, that causes a lockup when that command is encountered! Maybe,  someday,  if we get the source a quick patch can be found.

Is the bug with the MDOS or TI version?

 

If MDOS, can you do something in assembly to confirm it is not a bug in the XOP?

 

Beery

Share this post


Link to post
Share on other sites

Thanks for the help Beery, all the work I've done is with the GPL version in Classic99.

If I was really smart, Fortran99 has a debugger facility that could possibly be used to trace this down.

This is one of those cases, where having in compile first to intermediate assembly would be helpful. alas.

thanks,d.

Share this post


Link to post
Share on other sites

Could you post a small fortran program with the setpos command which locks up your system reproducibly?

Share this post


Link to post
Share on other sites
C SIMPLE TEST PROGRAM
C234567
      PROGRAM STP
 
      INTEGER MY_MAT(3,3)
 
      DATA MY_MAT /1,2,3,
     !             4,5,6,
     !             7,8,9/
 
      CALL SET40
      CALL SCREEN ( 12, 2 )
 
      CALL CHAR ( 111, '1824429999422418'X )
C      SPRITE BUILT WITH FSF.IO SPRITEPAINTER
 
      PRINT , 'The gAme of Life'
 
C     Now lets unroll the array
      DO 10 I = 1, 3
        CALL SETPOS ( 4+I, 1)
        DO 20 J = 1, 3
          PRINT , MY_MAT(J,I)
   20   CONTINUE
   10 CONTINUE
 
      CALL DELAY ( 30 )
C      WAITS 3 SECONDS, COMPARE WITH CALL WAIT
 
      CALL DELAY ( 40 )
 
      STOP
      END

 

Share this post


Link to post
Share on other sites
Posted (edited)

It is working for me with F9640 (Geneve). I'm not sure whether the output is as expected: The PRINT line will always do a newline, so you print the matrix line elements under each other. The output looks like

 

The gAme of Life

    1
    4
    7
   8
   9

 

(it print 1 2 3 vertically starting at row 5, then it goes back to row 6, prints 4 5 6 vertically, then it goes back to row 7 and prints 7 8 9)

 

 

Edited by mizapf

Share this post


Link to post
Share on other sites

With the 99/4a version, you get 'game of life' and lock up.

Vorticon played with it on a real TI and received that same results, so we know it's a bug in the gpl version, that apparently is not seen in the MDOS version.

Share this post


Link to post
Share on other sites
Posted (edited)

Not a bug; SETPOS is simply not contained in the 99 version of the GL lib. The same is true for GETPOS ... for whatever reason. Maybe someone thought this is a 9938-related graphic function. The manual and errata do not state anything about that.

 

You can check this when you use the linker with CRT as list output. It will list SETPOS as "bad reference".

 

It seems to me as if this Fortran was targeted at the Geneve primarily. I can at least say that developing Fortran programs on the Geneve is much more fun. This is my MAKE script:

 

ECHO OFF
CD \FORTRAN
F9640 /OPROG\%1_O SRC\%1_F
ECHO
ECHO Ready for linking?
ECHO
PAUSE
FLINK /OPROG\%1_O /IGL,CL,ML,FL PROG\%1
DEL PROG\%1_O

 

Then I say "MAKE FORTEST", and it takes SRC\FORTEST_F, compiles it, then links it against all libs, creates a standalone program as PROG\FORTEST, and removes the intermediate object code.

Edited by mizapf
  • Sad 1

Share this post


Link to post
Share on other sites

So, I issue you a programming challenge! 😃

 

I did manage to display the matrix, basically by building a whole screen at a time.

 

Let's say, I wanted to build a program to allow cross word puzzles to be filled in...

 

How could one do that with out a set or get pos?

 

 

C GRAPHICS EXAMPLE - 04/28/2020 - DHE
 
      PROGRAM G2_S
C             GRAPHICS EXAMPLE 2 SOURCE
C2345678
      INTEGER MY_MAT(3,3)
 
      DATA MY_MAT /1,2,3,
     !             4,5,6,
     !             7,8,9/
 
      CALL SETVID
 
      CALL CHAR ( 111, '1824429999422418'X )
C      SPRITE BUILT WITH FSF.IO SPRITEPAINTER
 
      PRINT , 'The gAme of Life'
 
C     With out a work setpol must build whole screen at once
      WRITE ( 6, 900 ) MY_MAT(1,1), MY_MAT(2,1), MY_MAT(3,1)
      WRITE ( 6, 910 ) MY_MAT(1,2), MY_MAT(2,2), MY_MAT(3,2)
      WRITE ( 6, 920 ) MY_MAT(1,3), MY_MAT(2,3), MY_MAT(3,3)
  900 FORMAT ( '+', M10.10, 3I1 )
  910 FORMAT ( '+', M11.10, 3I1 )
  920 FORMAT ( '+', M12.10, 3I1 )
C         PRINT , MY_MAT(J,I)
          CALL DELAY ( 5 )
   20   CONTINUE
   10 CONTINUE
 
      CALL DELAY ( 30 )
C      WAITS 3 SECONDS, COMPARE WITH CALL WAIT
 
      CALL DELAY ( 40 )
 
      STOP
      END

 

 

Share this post


Link to post
Share on other sites
On 5/1/2020 at 7:18 PM, mizapf said:

Not a bug; SETPOS is simply not contained in the 99 version of the GL lib. The same is true for GETPOS ... for whatever reason. Maybe someone thought this is a 9938-related graphic function. The manual and errata do not state anything about that.

 

You can check this when you use the linker with CRT as list output. It will list SETPOS as "bad reference".

 

It seems to me as if this Fortran was targeted at the Geneve primarily. I can at least say that developing Fortran programs on the Geneve is much more fun. This is my MAKE script:

 

ECHO OFF
CD \FORTRAN
F9640 /OPROG\%1_O SRC\%1_F
ECHO
ECHO Ready for linking?
ECHO
PAUSE
FLINK /OPROG\%1_O /IGL,CL,ML,FL PROG\%1
DEL PROG\%1_O

 

Then I say "MAKE FORTEST", and it takes SRC\FORTEST_F, compiles it, then links it against all libs, creates a standalone program as PROG\FORTEST, and removes the intermediate object code.

This is weird, since the bitmap routines were implemented for GPL.  And yes, the Geneve implementation is much more interesting and capable. Nonetheless having Fortran on the TI 99 was still an outstanding achievement.

Share this post


Link to post
Share on other sites
On 5/1/2020 at 7:46 PM, dhe said:

So, I issue you a programming challenge! 😃

 

I did manage to display the matrix, basically by building a whole screen at a time.

 

Let's say, I wanted to build a program to allow cross word puzzles to be filled in...

 

How could one do that with out a set or get pos?

Hint: Use HCHAR or VCHAR

Share this post


Link to post
Share on other sites

I figured out how to build a whole screen, and display it at once.

What I can't figure out how to do, is go to a row, and col and do a an equivalent of accept at.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...