Jump to content

Photo

Camel99 Forth Information goes here

Camel99 Forth Concatentive Programming ANS Forth

13 replies to this topic

#1 TheBF OFFLINE  

TheBF

    Moonsweeper

  • 458 posts
  • Location:The Great White North

Posted Wed Jan 3, 2018 4:14 PM

I thought it was about time that I create a goto place (no pun intended) for all things Camel99. 

 

So from now on I will put updates here.

 

This update is my first Pong Game. It's a little quirky but it uses sound and sprites with no interrupts or multi-tasking.

It's not that easy to win.  The computer player is very crude but it make enough mistakes so that you can win. :-)

 

Since I never spent much time writing games this has been educational for me.

 

I have added a new simple word to CAMEL99 to create named character patterns.  It's called PATTERN:

"PATTERN:" words return the address (ie: a pointer) to the data that loads into VDP very fast using VWRITE.

 

If you wanted to add PATTERN: to another Forth the code is:

\ PATTERN: lets us define named character patterns

\ usage: 
\  HEX 3C42 A581 A599 423C PATTERN: HAPPY_FACE
\      3C42 A581 99A5 423C PATTERN: SAD_FACE

\ DECIMAL
\ SAD_FACE  159 CHARDEF

: PATTERN: ( u u u u  -- )
           CREATE
           >R >R >R              \ push 3 values so we can reverse order
           ,  R> , R> , R> ,     \ compile 4 ints in VDP useable order
;

The PONG code is in the spoiler.  You have to load CAMEL99 with EA5 option and then paste PONG it into the emulator.

When the codes finishes compiling type RUN.

 

Latest version of CAMEL99 is on GitHub at the URL in the signature.

 

 

Spoiler

Edited by TheBF, Thu Jan 4, 2018 9:25 AM.


#2 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,512 posts
  • Location:Silver Run, Maryland

Posted Thu Jan 4, 2018 4:44 PM

This thread is a good idea!

 

Sorry, I have not been very responsive lately.  First it was getting settled down here in FL, then the holiday season with a week of some of the kids and grandkids, then a week of friends staying with us and now I am a bit under the weather with some bug or other and not much energy.  Of course, the beach and horseshoes got in the way a lot!  I haven’t even updated the fbForth thread or my website in quite a while—needed too large a block of time.  That is my excuse and I am sticking to it.

 

Anyway, I need to download Camel99 Forth to test PONG and then, of course, see about porting it to you-know-what.

 

...lee



#3 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Thu Jan 4, 2018 8:10 PM

I actually think of you when I concoct these programs.

 

This one has one text macro in it that could be replaced for FigForth.

I have grown fond of these things in ANS Forth because they put the low level code into your definitions directly but you can use a high level name.

No COMPILE [COMPILE] POSTPONE confusion.

: [HZ] ( freq -- fcode ) S" HZ>CODE ] LITERAL" EVALUATE ;

\ I think it could be this in FigForth (untested)
: [HZ] ( freq -- fcode ) 
       COMPILE HZ>CODE  
       COMPILE ] 
       [COMPILE] LITERAL ; IMMEDIATE 


#4 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,512 posts
  • Location:Silver Run, Maryland

Posted Fri Jan 5, 2018 12:25 PM

 

I actually think of you when I concoct these programs.

 

This one has one text macro in it that could be replaced for FigForth.

I have grown fond of these things in ANS Forth because they put the low level code into your definitions directly but you can use a high level name.

No COMPILE [COMPILE] POSTPONE confusion.

: [HZ] ( freq -- fcode ) S" HZ>CODE ] LITERAL" EVALUATE ;

\ I think it could be this in FigForth (untested)
: [HZ] ( freq -- fcode ) 
       COMPILE HZ>CODE  
       COMPILE ] 
       [COMPILE] LITERAL ; IMMEDIATE 

 

My head always hurts when I work with COMPILE !  I always have to test that sort of code extensively until it works and I actually understand it.  That figForth code won’t work!  Declaring it immediate will cause LITERAL to execute during the definition of ]HZ , but you want it to execute while defining words that use ]HZ after they have been temporarily set to execution mode by [ .  This definition appears to work:

: [HZ] ( freq -- fcode ) 
       HZ>CODE  
       [COMPILE] ] 
       [COMPILE] LITERAL ; 

I may eventually implement EVALUATE for fbForth, but I would need to define a different string word that would append a couple of nulls and not leave a character count on the stack.  The spoiler below is for those craving an explanation.

Spoiler

 

...lee



#5 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Fri Jan 5, 2018 3:03 PM

 

My head always hurts when I work with COMPILE !  I always have to test that sort of code extensively until it works and I actually understand it.  That figForth code won’t work!  Declaring it immediate will cause LITERAL to execute during the definition of ]HZ , but you want it to execute while defining words that use ]HZ after they have been temporarily set to execution mode by [ .  This definition appears to work:

: [HZ] ( freq -- fcode ) 
       HZ>CODE  
       [COMPILE] ] 
       [COMPILE] LITERAL ; 

I may eventually implement EVALUATE for fbForth, but I would need to define a different string word that would append a couple of nulls and not leave a character count on the stack.  The spoiler below is for those craving an explanation.

Spoiler

 

...lee

 

 

Wow. I learned something. I am so long away from FigForth and I never did know about the ASCII 0 thing.

I think the ANS group did a few good things for Forth.  The interpreter mechanism might be one.

 

I bet you are happy to be in Florida right now.  Up here it was -4 F overnight and it came up above 0 F  in the day time!

Woohoo! Its heat wave.

 

And we got 9..10 " of snow and it's still coming down  :-)

 

But the east coast of the US is way worse than the Detroit/Toronto corridor.



#6 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Sat Jan 13, 2018 2:03 PM

Adding 80 Columns to Camel99 Forth

 

Finally got around to adding this functionality for the F18A.

 

Thanks to Willsy for the register data.

 

You can only toggle between 40 column and 80 column after this code is loaded.

GRAPHICS will just give you a warning.

 

Added the simple word TINT so you can change text and screen color.

(uses machine values for colors to keep it simply)

\ 80 column mode for F18A video card (tested on Classic99)
\ Register DATA taken from Turbo Forth by Mark Wills
( default colors changed to green on black screen)

HEX
CREATE 40COL
       00 C, F0 C, 00 C, 0E C, 01 C, 06 C, 02 C, 20 C,

CREATE 80COL
       04 C, 70 C, 03 C, E8 C, 01 C, 06 C, 00 C, 20 C,
       88 C, 00 C, 00 C, 00 C, 94 C, 10 C, 00 C,

: VREGS  ( addr n -- )  0 DO  DUP I + C@  I VWTR  LOOP DROP ;

DECIMAL
: 80COLS ( -- )   80COL 15 VREGS  80 C/L!  PAGE  80 VMODE ! ;

\ we have to over-write the old versions to handle 80cols
: TEXT    ( -- ) 40COL   8 VREGS  TEXT  ;
: COLD    ( -- ) TEXT  COLD ;
: TINT    ( fg bg -- ) SWAP 4 LSHIFT +  7 VWTR ;

: GRAPHICS ( -- ) -1 ABORT" Needs restart" ;



#7 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Sun Jan 14, 2018 9:11 AM

*New and Improved*  80 Columns to Camel99 Forth

 

It didn't sit well with me that I could not change screen modes freely.

After I played around I found out that if I reset to TEXT mode, I could jump to a 80cols or GRAPHICS 

mode with no problem.  It takes just a few milli-seconds longer but you can jump from 80cols

to GRAPHICS and back. Classic99 does not seem to be able to record the 80COLS screens

so you will have to load this code yourself for proof that it works. 

 

Here is the new code:

HEX
CREATE 40COL
       00 C, F0 C, 00 C, 0E C, 01 C, 06 C, 02 C, 20 C,

CREATE 80COL
       04 C, 70 C, 03 C, E8 C, 01 C, 06 C, 00 C, 20 C,
       88 C, 00 C, 00 C, 00 C, 94 C, 10 C, 00 C,

: VREGS  ( addr n -- )  0 DO  DUP I + C@  I VWTR  LOOP DROP ;

DECIMAL

\ we have to over-write the old versions to handle 80cols
: TEXT    ( -- ) 40COL   8 VREGS  TEXT  ;
: COLD    ( -- ) TEXT  COLD ;
: TINT    ( fg bg -- ) SWAP 4 LSHIFT +  7 VWTR ;

: 80COLS ( -- )   TEXT 80COL 15 VREGS  80 C/L!  PAGE  80 VMODE ! ;
: GRAPHICS ( -- ) TEXT GRAPHICS  ;



#8 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Sun Jan 14, 2018 11:00 PM

Adding Elapsed Time Timer

 

When you are trying to find out if one way to code something is faster than another method this little tool is soooo handy.

 

The code uses the fact that the TI-99 is running a countdown timer for the screen timeout at address >83D6.

Each tick of this timer is .008333 seconds so it will run for about 9 minutes. That is the maximum time we can measure with this method.

 

The first time I saw this word ELAPSE was in FPC Forth by Tom Zimmer.  I have moved it to other Forth systems since then.

 

The video shows ELAPSE in action.

\ ELAPSE.FTH  elapsed time measurment words
\ Thanks to Tom Zimmer for the good ideas in FPC circa 1990
\ Ported to HsForth 08MAR91  Brian Fox Canada

\ Ported to CAMEL99 Nov 29 2017
\ Good for 9 minutes maximum duration

\ *** YOU CANNOT CALL KSCAN WHILE TIMING ***

HEX
83D6 CONSTANT TICKER   \ screen timeout counter increments by 2 /16mS

DECIMAL
: ##      ( n -- )  0 <#  # #  #> TYPE ;

: .MINS   ( h S M  -- )
          BASE @ >R   
          DECIMAL  ## [CHAR] : EMIT  ##  [CHAR] . EMIT ##
          R> BASE ! ;

\ 1 TICK = .008333 mS
: REALTIME ( -- n )  TICKER @  5 6  */ ;  \ changed to 5/6 ratio from input by Lee Stewart. Better now

: >TIME  ( n -- .hh secs mins  )  \ convert n to time
          6000 /MOD   ( -- rem mins) >R  \ push minutes
          100  /MOD   ( -- ms secs)      \ calculate seconds & hundredths
          R> ;                           \ pop minutes

: .ELAPSED ( -- ) CR ." Elapsed time ="  REALTIME >TIME .MINS ;

: ELAPSE  ( -- <forth words> )
           1 PARSE   \ BF edit to allow timing a line of code
           TICKER OFF
           EVALUATE
          .ELAPSED ;

Attached Files


Edited by TheBF, Mon Jan 15, 2018 3:38 PM.


#9 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,512 posts
  • Location:Silver Run, Maryland

Posted Mon Jan 15, 2018 10:57 AM

I don’t know if the accuracy of the result is really improved due to truncation, but the following definition of REALTIME uses 0.833... as the multiplier, exactly:

: REALTIME ( -- n )  TICKER @  5 6 */ ; 

...lee



#10 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Mon Jan 15, 2018 3:33 PM

Well done.

 

Yes it does make a difference.  I ran this code on FB-Forth and CAMEL99 and they go out of sync pretty quickly.

: TEST ( start end -- )
  SWAP 
  DO
     CR  I U.  SPACE  I  5 6 */ U.  SPACE  I 83 100 */  U.
  LOOP ;
  

Thanks.  I will fix it in the original post.

 

 

B



#11 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Mon Jan 15, 2018 3:41 PM

I don’t know if the accuracy of the result is really improved due to truncation, but the following definition of REALTIME uses 0.833... as the multiplier, exactly:

: REALTIME ( -- n )  TICKER @  5 6 */ ; 

...lee

 

Looking at it again I saw another bug for ANS Forth only.

: ELAPSE  ( -- <forth words> )
           1 PARSE
           TICKER OFF
           EVALUATE
          .ELAPSED ;

I had used BL PARSE,  which of course parsed a space delimited word in the input.

1 PARSE will never find a delimiter and so will take in an entire line of text.

 

You help me find bugs without even looking at them.

 

You're a wizard.

 

B



#12 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,512 posts
  • Location:Silver Run, Maryland

Posted Mon Jan 15, 2018 3:49 PM

...

You help me find bugs without even looking at them.

 

You're a wizard.

 

B

 

Hah!  :-o

 

...lee



#13 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,512 posts
  • Location:Silver Run, Maryland

Posted Mon Jan 15, 2018 4:02 PM

Here it is ported to fbForth 2.0:

 

Spoiler

 

I had to define OFF and make changes in .MINS and ELAPSE .  Two changes I made in .MINS were gratuitous ( BASE->R and R->BASE ).

 

...lee



#14 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 458 posts
  • Location:The Great White North

Posted Mon Jan 15, 2018 4:04 PM

Cool!

 

It's much handier than using a stop-watch.







Also tagged with one or more of these keywords: Camel99, Forth, Concatentive Programming, ANS Forth

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users