Jump to content

Photo

fbForth—TI Forth with File-based Block I/O [Post #1 UPDATED: 11/10/2017]

fbForth Forth TI Forth

1478 replies to this topic

#1476 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • Topic Starter
  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Tue Nov 27, 2018 7:35 AM

I think I get it now.  ?OF should actually find 2 numbers on the stack, viz., the number being tested by CASE and the flag.  I have not yet tested what follows, but I think it will work.  The idea of the code is to toggle the flag and add it to a duplicate of the test number before presenting it to OF .  A false flag will then force a mismatch, while a true flag will force a match.  It must be paired with ENDOF .

 

Here it is for Camel99 Forth:

: ?OF    \ compile-time: ( 4 -- here 5 )  run-time: ( n flag -- []|n)
      \ toggling flag will force proper match/mismatch for OF
      POSTPONE 0= POSTPONE OVER POSTPONE +         \ S:n flag'+n
      POSTPONE OF  ; IMMEDIATE 

Here is the equivalent fbForth version:

: ?OF    \ compile-time: ( 4 -- here 5 )  run-time: ( n flag -- []|n)
      \ toggling flag will force proper match/mismatch for OF
      COMPILE 0= COMPILE OVER COMPILE +         \ S:n flag'+n
      [COMPILE] OF  ; IMMEDIATE 

Here is an example of its use (block #41 of FBLOCKS must be loaded to use WITHIN ):

: XX  ( n -- ) 
      CASE
         DUP 2 9 WITHIN ?OF ." In range (2,9)." ENDOF
         ELSEOF ." No match!" ENDOF
      ENDCASE  ;

...lee

 

[Edits in this color.]



#1477 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • Topic Starter
  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Tue Nov 27, 2018 8:52 AM

The above version of ?OF works in fbForth 2.0!

 

TheBF’s example use of ?OF inspired the following word, which requires block #41 of FBLOCKS to be loaded for PICK , WITHIN and -ROT :

: RANGEOF   \ compile-time ( 4 -- here 5 )   run-time: ( n lo hi -- []|n )
      COMPILE 2 COMPILE PICK COMPILE -ROT       \ S:n n lo hi
      COMPILE WITHIN                            \ S:n flag
      COMPILE 0= COMPILE OVER COMPILE +         \ S:n flag'+n
      [COMPILE] OF  ; IMMEDIATE

It must be paired with ENDOF and used within a CASE ... ENDCASE construct as

: TEST  ( n -- )
    CASE
       2 9 RANGEOF ." In range." ENDOF
       ELSEOF ." No match!" ENDOF
    ENDCASE  ;

...lee



#1478 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 821 posts
  • Location:The Great White North

Posted Tue Nov 27, 2018 1:02 PM

Cool!  I forgot I posted this experiment. So yeah. That's what I meant.  ;)

Thanks for figuring it out for me

 

I have been crunching on resurrecting the directed threaded version of CAMEL99 Forth which means fixing the cross-compiler and all the rest. I broke it a year ago, but decided to focus on one code base until I got things working better.

 

My old brain is sweating, but I am getting closer.

 

After DTC I want to take serious run at sub-routine threading with some inline primitives. It should run 3 times faster...

in theory.



#1479 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • Topic Starter
  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Tue Nov 27, 2018 4:42 PM

As I looked at your code, I realized that Chuck says "the dictionary is your case statement" (or something like that).
 
Here is my interpretation of what that means in regards to your SAVE-FONT word:
 
Spoiler

 

My 2 cents Canadian.  (about 1.44 cents USD so take it for what it's worth)

 

 

Here is my version, after some re-thinking of SAVE-FONT :

HEX
\ The following 2 words are Brian Fox’s creations
: VPLACE   ( addr len vaddr -- )  \ like PLACE, but for RAM to VRAM
      OVER OVER VSBW 1+ SWAP VMBW ;
: CLIP ( n min max -- n') ROT MIN MAX ; 

PABS @         \ VRAM address for PAB
HERE           \ RAM addres for PAB-BUF (dummy not actually used)
PDT            \ VRAM address for PAB-VBUF (Pattern Descriptor Table)
FILE FONTFIL   \ associate above 3 addresses with FONTFIL

\ SAVE-FONT forces bytes to be 1024..2048
: SAVE-FONT  \ ( bytes -- )   ( IS:<fontFileName> )
      400 800 CLIP         \ forces font file size of 1..2 KiB 
      FONTFIL SET-PAB      \ set up FONTFIL
      BL WORD HERE COUNT   \ filename-addr cnt
      PAB-ADDR @ 9 +       \ vaddr
      VPLACE               \ cnt+filename->PAB+9
      SV    \ save 1024..2048-byte binary font image to file
;  
\ Usage example: 400 SAVE-FONT DSK1.FONT0230
DECIMAL

And, here it is à la MKBFL (requires same preamble as SAVE-FONT):

HEX
: SVFFL  ( IS:<fontFileName> <bytes> )
      FONTFIL SET-PAB      \ set up FONTFIL
      BL WORD HERE COUNT   \ filename-addr cnt
      PAB-ADDR @ 9 +       \ vaddr
      VPLACE               \ cnt+filename->PAB+9
      BL WORD              \ <bytes> input string to HERE
      HERE NUMBER DROP     \ convert to 16-bit number on stack
      400 800 CLIP         \ force font file size of 1..2 KiB 
      SV    \ save 1024..2048-byte binary font image to file
;
\ Usage example: SVFFL DSK1.FONT0230 400
DECIMAL

...lee







Also tagged with one or more of these keywords: fbForth, Forth, TI Forth

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users