Jump to content
IGNORED

TF, camel, FB Forth fun


GDMike

Recommended Posts

54 minutes ago, FarmerPotato said:

Oops.  I understood VFILL to mean VDP fill and that it went horizontal. Like I'd think of 0 768 32 VFILL to clear the screen.

 

I also found it annoying that vaddr is below len and char.  If I'm iterating on vaddr, it requires a nasty 2DUP I -ROT to prepare the stack for FILL/VFILL.

I imagine a ! order: 

: VFILL! ( char len vaddr -- )

  SETVWA

  0 DO DUP VDPWD ! LOOP ;
 

You are correct. I was trying to say that where HCHAR uses x,y   VFILL uses a VDP address as a starting point. 

 

Typically VFILL like FILL is a code word so we can access args randomly. 

 

But if I had to do VFILL in Forth I might do this:

: VFILL ( Vaddr len char -- )
        -ROT   ( char vaddr len)
        OVER + SWAP  ( char Vend Vstart)
        DO 
           DUP I C!
        LOOP 
        DROP ; 

 

Your version would work faster with SETWA defined and using the -ROT (reverse rotate) operator.

I actually did it this way in my "RECOMPILER" as an experiment. :)  Check out this driver in Forth.

(FOR NEXT is a simple down counter. Way less code than DO/LOOP.

https://github.com/bfox9900/RECOMPILER/blob/main/src/LIB/VDPDRVR-FORNEXT.FTH

 

 

See here for my ALC version use in Camell99 Forth 

https://github.com/bfox9900/CAMEL99-ITC/blob/master/Compiler/cc9900/SRC.ITC/TI99IOX.HSF

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Still working on cleaning up my repository and I came across the old sevens problem. 

 

I always wanted a version that was a literal translation of the BASIC so I did one. 

It's fun to look at.  I did not use any tricks unless you call one DUP a trick. :) 

 

Here is the TI BASIC version that runs in 27 minutes.  I am afraid I have lost the accreditation for it so speak up if it's yours. (Lucien?)

Edit: Original program was written by @unhuman.

I modified lines 340 to 360 to speed up printing. The original used HCHAR. 

 

Spoiler
1 rem for comparison to Forth
2 rem TI BASIC version runs in 27mins and 20 seconds 
10 OPEN #1:"CLOCK"
20 INPUT #1:A$,DATE$,START$
100 DIM A(256)
110 PRINT "7's Problem"
120 A(1)=7
130 WIN=0
140 POWER=1
150 NUMLEN=1
160 POWER=POWER+1
170 PRINT "7 ^";POWER;"IS:"
180 CARRY=0
190 INAROW=0
200 FOR I=1 TO NUMLEN
210    A(I)=A(I)*7+CARRY
220    CARRY=INT(A(I)/10)
230    A(I)=A(I)-CARRY*10
240    IF A(I)<>7 THEN 290
250    INAROW=INAROW+1
260    IF INAROW<>6 THEN 300
270    WIN=1
280    GOTO 300
290    INAROW=0
300 NEXT I
310 A(I)=CARRY
320 IF CARRY=0 THEN 340
330 NUMLEN=NUMLEN+1
340 FOR I=NUMLEN TO 1 STEP -1
350     PRINT CHR$(A(I)+48);
360 NEXT I
363 REM we're done get the time
365 INPUT #1:A$,DATE$,END$
370 PRINT ::
380 IF WIN<>1 THEN 160
390 PRINT "WINNER IS 7 ^";POWER
394 Print "Sevens started:";START$
400 PRINT "Ended at ";END$
410 CLOSE #1
420 END

 

 

And here is a Forth literal translation that runs in edit:  1 minute 10 seconds on my indirect threaded system. 

( Re-timed using a stop-watch because the there was too much VDP I/O playing with the ISR timer)

I have included the BASIC code as comments. 

It would be faster if I replace the VARIABLEs with VALUEs  but this is vanilla Forth. 

Most systems have character array creator CARRAY or it can be made easily enough. 

 

Spoiler
\ literal translation of BASIC program to Forth 

INCLUDE DSK1.TOOLS 
INCLUDE DSK1.ELAPSE 
INCLUDE DSK1.ARRAYS 

DECIMAL 
: ?BREAK   ?TERMINAL ABORT" *BREAK*" ; 

\ must define all data before use
VARIABLE WIN 
VARIABLE POWER 
VARIABLE NUMLEN 
VARIABLE CARRY 
VARIABLE INAROW 
VARIABLE NDX   ( transfers loop index out of DO LOOP )

 256 CARRAY ]A                  \  100 DIM A(256)
: RUN 
  CR ." 7's Problem "           \ 110 PRINT "7's Problem"
  0 ]A 256 0 FILL               \ init ]A to zero
  7 0 ]A C!                     \ 120 A(1)=7
   WIN OFF                      \ 130 WIN=0
  1 POWER !                     \ 140 POWER=1
  0 NUMLEN !                    \ 150 NUMLEN=1
  BEGIN POWER 1+!               \ 160 POWER=POWER+1
    ." 7 ^" POWER @ . ." IS:"   \ 170 PRINT "7 ^";POWER;"IS:"
    ?BREAK 
    CARRY OFF                   \ 180 CARRY=0
    INAROW OFF                  \ 190 INAROW=0
    NUMLEN @ 1+ 0               \ 200 FOR I=1 TO NUMLEN
    DO    
        I NDX !                 \ copy I for later 
        I ]A C@ 7 *  CARRY @ +  \ 210 A(I)=A(I)*7+CARRY
\ We avoid some math with divide & mod function 
        0 10 UM/MOD  CARRY !    \ 220 CARRY=INT(A(I)/10)
        I ]A C!                 \ 230 A(I)=A(I)-CARRY*10
        I ]A C@ 7 =             \ 240 IF A(I)<>7 THEN 290
        IF     
            INAROW 1+!          \ 250 INAROW=INAROW+1
            INAROW @ 6 =        \ 260 IF INAROW<>6 THEN 300
            IF                
              WIN ON            \ 270 WIN=1
              LEAVE 
            THEN                
        ELSE                    \ 280 GOTO 300 
            INAROW OFF          \ 290 INAROW=0
        THEN 
        ?BREAK 
    LOOP                        \ 300 NEXT I

    CARRY @ 
    DUP NDX @ 1+ ]A C!          \ 310 A(I)=CARRY
    IF                          \ 320 IF CARRY=0 THEN 340
        NUMLEN 1+!              \ 330 NUMLEN=NUMLEN+1
    THEN 
    CR                          \ replaces PRINT 
    0 NUMLEN @                  \ 340 FOR I=NUMLEN TO 1 
    DO   
      I ]A C@ >DIGIT (EMIT)     \ 350 PRINT CHR$(A(I)+48);
    -1 +LOOP                    \ 360 NEXT I ( STEP -1)
    CR CR                       \ 370 PRINT ::
    WIN @                       \ 380 IF WIN<>1
  UNTIL                         \     THEN 160
  ." Winner is 7 ^" POWER @ .   \ 390 PRINT "WINNER IS 7 ^";POWER
;                               \ 420 END

 

 

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

10 hours ago, TheBF said:

Here is the TI BASIC version that runs in 27 minutes.  I am afraid I have lost the accreditation for it so speak up if it's yours. (Lucien?)

 

Could be @lucien2, but check the first few posts of 

 

 

@Willsy opened with saying he had coded a TI Basic version, but I don’t know whether he ever posted it.

 

...lee

  • Thanks 1
Link to comment
Share on other sites

When I reviewed the thread on this program I found the results of this program compiled with the BASIC compiler. 

  On 3/24/2011 at 8:59 PM, unhuman said:

Compiled it kicks Forth's butt!

       "Maybe versus Weiand's Forth:

        Compiled-Basic: 1m40s

        Weiand-Forth: 3m"

 

But the Weiand Forth version was written by Lucien who admitted that he was new to Forth and the algorithm is completely different. 

 

Now, with a line by line translation, we can see that indirect-threaded Forth and compiled BASIC are running about the same speed.

If we compiled my BASIC version with simpler printing it would probably take the extra 20 seconds off or maybe more.

 

@Lee Stewart wrote a version using Forth idiomatically at it runs on my system in 1:02 with the default scroll code.

If increase the scroll buffer to the entire screen it runs in 55 seconds, but that's wasteful.

 

LOL. I am moving over to the old Seven's problem post. I wonder if my JIT can swallow the new version... ? ;) 

 

 

 

 

 

 

Link to comment
Share on other sites

I'm pretty sure the original source for this is a magazine article. I'm 90% sure it would have been a TI*MES article since I'm a Brit and us Brit 99ers were fed on a diet of TI*MES back in the day. Stephen Shaw will probably remember. I can't remember his handle on this forum.

 

Yeah, I was pretty impressed with the Forth cut, until @sometimes99er did a version in assembly which blew everything away! Doh!

  • Like 3
Link to comment
Share on other sites

2 hours ago, Willsy said:

I'm pretty sure the original source for this is a magazine article. I'm 90% sure it would have been a TI*MES article since I'm a Brit and us Brit 99ers were fed on a diet of TI*MES back in the day. Stephen Shaw will probably remember. I can't remember his handle on this forum.

 

Yeah, I was pretty impressed with the Forth cut, until @sometimes99er did a version in assembly which blew everything away! Doh!

 

Stephen Shaw is @blackbox here.

 

...lee

  • Like 2
  • Thanks 1
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...