Benutzer-Werkzeuge

Webseiten-Werkzeuge


projects:sample1.blk

Examples and notes for lecture # 1

print Screen 0 not modified     
 0 \ Examples and notes for lecture # 1           13:10JWB04/09/87 
 1 \ Last change:   Screen  009                   13:38JWB04/09/87 
 2                                                                 
 3         Making new words.                                       
 4         How to get in/out of the system                         
 5         Simple programs.                                        
 6         Numeric input.                                          
 7         The outer interpreter.                                  
 8         How to use the editor VEDIT.                            
 9         How to use the HELP system.                             
10         Some important system words.                            
11                                                                 
12 The B.C. Chapter of the FORTH Interest Group meets at BCIT      
13 in Room 1A-324 on the first Thursday of each month.             
14 The FORTH Board is a Computer Bulletin Board System run by BCFIG
15 Phone: 434-5886 if you have a modem and communication software. 


Screen 1 not modified     
 0 \  Load screen for HELP system                 12:54JWB04/09/87 
 1                                                                 
 2 ONLY FORTH DEFINITIONS                                          
 3                                                                 
 4 \ These words require  DEVICE=ANSI.SYS to be in you CONFIG.SYS  
 5 \ file and the the ANSI.SYS driver to be on your boot disk.     
 6                                                                 
 7 : ESC[   27 EMIT ASCII [ EMIT ;                                 
 8 : CLS    ESC[ ." 2J" ;                                          
 9 : BRIGHT ESC[ ." 1m" ;                                          
10 : NORMAL ESC[ ." 0m" ;                                          
11 : BLUE   ESC[ ." 44m" ;                                         
12                                                                 
13 FROM HELP.BLK   1 LOAD  ( loads the HELP system )               
14                                                                 
15                                                                 


Screen 2 not modified     
 0 \ Entering and Exiting the FORTH System.       13:14JWB01/09/86 
 1 FORTH83 {name}.BLK    Enter F83 sytem with the enhanced editor  
 2                       called VEDIT.  The screen file {name}.BLK 
 3                       is opened.                                
 4 FORTH83 B:SAMPLE1.BLK Enter FORTH with this file attached.      
 5                                                                 
 6 BYE                   Exit the FORTH system and return to DOS   
 7                                                                 
 8 F83     {name}.BLK    Enter F83 sytem with using Laxen and Perry
 9                       screen editor. The screen file {name}.BLK 
10                       is opened.                                
11 F83     SAMPLE1.BLK   Enter FORTH with this file attached.      
12                                                                 
13 Note:  I have never used the Laxen and Perry editor, so you are 
14        on your own here.   See the file README.PC for help if   
15        you would like to try this out.                          


Screen 3 not modified     
 0 \  Elementary Word Definitions.                13:22JWB01/09/86 
 1                                                                 
 2 : {name}    word1  word2 . . . wordn  ;                         
 3                                                                 
 4 :       Begin a word definition.                                
 5 ;       End a word definition.                                  
 6 {name}  This is the name of the new word definition.            
 7                                                                 
 8 Example:                                                        
 9                                                                 
10 : FIRST   CR  ." This is my first FORTH program. "  ;           
11                                                                 
12 ."  {string}"   Compiles string,  when word is executed string  
13                 is displayed on the display or console device.  
14 CR              Start a new line. ( carriage return/linefeed )  
15                                                                 


Screen 4 not modified     
 0 \ Working with FORTHs word dictionary.         13:07JWB04/09/87 
 1                                                                 
 2 \ WORDS         List all words in the FORTH dictionary.         
 3 \ EMPTY         Remove all new words added since entering FORTH 
 4 \ FORGET {name} Remove {name} and all words defined since {name}
 5 \               from the FORTH dictionary.                      
 6                                                                 
 7                                                                 
 8                                                                 
 9                                                                 
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 5 not modified     
 0 \                                              13:07JWB04/09/87 
 1                                                                 
 2                                                                 
 3                                                                 
 4                                                                 
 5                                                                 
 6                                                                 
 7                                                                 
 8                                                                 
 9                                                                 
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 6 not modified     
 0 \ PHONE LIST                                   10:14jwb09/15/85 
 1                                                                 
 2 : JACK      ."  BROWN       596-9764"                           
 3             ."   or   434-5734 L5401" CR ;                      
 4 : GEORGE    ."  SMITH    999-1111   " CR ;  EXIT                
 5 \ EXIT above prevents the rest of this screen from compiling.   
 6 :           ."                      " CR ;                      
 7 :           ."                      " CR ;                      
 8 :           ."                      " CR ;                      
 9 :           ."                      " CR ;                      
10 :           ."                      " CR ;                      
11 :           ."                      " CR ;                      
12 :           ."                      " CR ;                      
13 :           ."                      " CR ;                      
14                                                                 
15                                                                 


Screen 7 not modified     
 0 \ CHECKER BOARD                                10:14jwb09/15/85 
 1                                                                 
 2 : BLACK   SPACE SPACE ;                                         
 3                                                                 
 4 : WHITE   177 EMIT 177 EMIT ;                                   
 5                                                                 
 6 : ROW1   CR BLACK WHITE BLACK WHITE BLACK WHITE BLACK WHITE ;   
 7                                                                 
 8 : ROW2   CR WHITE BLACK WHITE BLACK WHITE BLACK WHITE BLACK ;   
 9                                                                 
10 : BOARD  CR ROW1  ROW2  ROW1  ROW2  ROW1  ROW2  ROW1  ROW2  ;   
11                                                                 
12 : CHECKER_BOARD    BOARD  CR CR ;                               
13                                                                 
14                                                                 
15                                                                 


Screen 8 not modified     
 0 \ ANOTHER CHECKER BOARD                        10:14jwb09/15/85 
 1                                                                 
 2                                                                 
 3 : BLACK   SPACE SPACE ;                                         
 4                                                                 
 5 : WHITE   177 EMIT 177 EMIT ;                                   
 6                                                                 
 7 : ROW1   CR 4 0 DO  BLACK WHITE LOOP ;                          
 8                                                                 
 9 : ROW2   CR 4 0 DO  WHITE BLACK LOOP ;                          
10                                                                 
11 : BOARD  CR 4 0 DO  ROW1  ROW2  LOOP ;                          
12                                                                 
13 : CHECKER_BOARD    BOARD  CR CR ;                               
14                                                                 
15                                                                 


Screen 9 not modified     
 0 \ MQUIT                                        13:38JWB04/09/87 
 1 \ This stack print is more compact and uses unsigned for HEX #s.
 2 : .S ( --  -- )                                                 
 3      DEPTH ?DUP IF                                              
 4            0 ?DO DEPTH I - 1-  PICK                             
 5                  BASE @ 16 = IF U. ELSE . THEN  LOOP            
 6                 ELSE ." Empty" THEN ;                           
 7 \ My quit routine which displays stack after each operation.    
 8 : MQUIT  ( --  -- )                                             
 9         SP0 @  'TIB ! BLK OFF [COMPILE] [                       
10         BEGIN   RP0 @   RP!                                     
11                 STATE @ NOT                                     
12                 IF CR .S ASCII > EMIT SPACE THEN                
13                 QUERY  RUN                                      
14         AGAIN ;                                                 
15                                                                 


Screen 10 not modified     
 0 \       VEDIT CURSOR CONTROL                   10:50jwb09/15/85 
 1 up      arrow or control E      move cursor one position up     
 2 down    arrow or control X      move cursor one position down   
 3 left    arrow or control S      move cursor one position left   
 4 right   arrow or control D      move cursor one position right  
 5 tab     key   or control I      move cursor one tab stop right  
 6 shift tab     or control O      move cursor one tab stop left   
 7 control A or                                                    
 8 control left arrow              move cursor one word left       
 9 control F                                                       
10 control right arrow             move cursor one word right      
11 return  key     move to end of text on next line.               
12 home    key     move to start of text (upper left screen corner)
13 end     key     move to end of text (last character on screen). 
14 control home    move to the beginning of the current line.      
15 control end     move to the last character of the current line. 


Screen 11 not modified     
 0 \       VEDIT - DELETE, ERASE & INSERT         11:20jwb09/15/85 
 1 Del  key or                                                     
 2 control G       delete character under cursor and close gap.    
 3 back space      erase  character behind cursor leaving a blank. 
 4 control T       delete remainder of word and close gap.         
 5 control U       erase  current line leaving a line of blanks.   
 6 control Y       delete current line and close gap.              
 7 alt     U       erase  from cursor position to end of line.     
 8 F9              erase  entire screen to blanks.                 
 9 alt     F9      erase  from cursor position to end of screen.   
10 Ins  key        toggle between overstrike and insert mode.      
11 control N       insert a blank line at the current position.    
12 alt     N       split  line at current cursor position.         
13 control J       join   current line with one below.             
14 control W       insert a blank at current cursor position.      
15                                                                 


Screen 12 not modified     
 0 \       VEDIT - SEARCH REPLACE, LINE STACK     12:26jwb09/15/85 
 1                                                                 
 2 control Q       then press any character.  Find first occurance 
 3                 of character following cursor position.         
 4                                                                 
 5 F7              find first occurance of string.                 
 6 control L       repeat find for the current string.             
 7 F8              find and replace string (one replace).          
 8 F8              (answer prompts with return)  repeat with       
 9                 previous strings.                               
10                                                                 
11 F3              push current line to line stack without deleting
12 F5              pop  top of line stack to current line.         
13 F4              push current line to line stack and delete it.  
14 F7              insert top of line stack at current line.       
15                                                                 


Screen 13 not modified     
 0 \       VEDIT - SCREEN CONTROL                 12:17jwb09/15/85 
 1 PgUp    or control R    move back one screen.                   
 2 PgDn    or control C    move to next  screen.                   
 3 control PgUp            move to first screen in file.           
 4 control PgDn            move to last  screen in file.           
 5                                                                 
 6 F9                      erase current screen to blanks.         
 7 F10                     restore current screen disk copy.       
 8 control Z               prompt for new screen # and zip there.  
 9 alt     A               alternate between screen and its shadow.
10 control P               quick print of current screen.          
11 alt     C               copy one screen to another.             
12 alt     M               copy many screens to a new location.    
13 alt     I               quick screen index.                     
14                                                                 
15                                                                 


Screen 14 not modified     
 0 \       VEDIT - SPECIAL                        13:33JWB01/09/86 
 1 control J       join current line with one below.               
 2 control P       quick print of current screen.                  
 3 F1              display help screen.                            
 4 alt     B       choose better colors for screen display.        
 5 alt     C       copy one screen to another.                     
 6 alt     D       transpose character right.                      
 7 alt     G       get directory of disk drive.                    
 8 alt     I       quick screen index.                             
 9 alt     M       copy many screens to a new location.            
10 alt     O       open new screen file.                           
11 alt     S       transpose character left.                       
12 alt     T       change tab stops.                               
13 F10             restore current screen form copy on disk.       
14 ESC             exit the editor.                                
15                                                                 


Screen 15 not modified     
 0 \                                              12:24jwb09/15/85 
 1                                                                 
 2                                                                 
 3                                                                 
 4                                                                 
 5                                                                 
 6                                                                 
 7                                                                 
 8                                                                 
 9                                                                 
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 16 not modified     
 0 \ Looping words, I/O words, Stack operatio     13:40JWB01/09/86 
 1   last first   DO  ...  LOOP    ( Use within a colon def to )   
 2                                 ( loop from first to last.  )   
 3   last first  ?DO  ...  LOOP    ( Same as above except loop )   
 4                                 ( 0 times if   first=last   )   
 5     BEGIN  ....  AGAIN          ( Use within a colon def to )   
 6                                 ( create an infinite loop.  )   
 7     SPACE       ( --   -- )     ( Send a space to the display.) 
 8     SPACES      ( n    -- )     ( Send n spaces to display. )   
 9     CR          ( --   -- )     ( Start a new line on display.) 
10     EMIT        ( n    -- )     ( Display ASCII character n .)  
11     .           ( n    -- )     ( Send top of stack to display.)
12     +         ( m n   sum )     ( Leave sum:  sum = m + n      )
13     -         ( m n   dif )     ( Leave difference: dif = m - n)
14     *         ( m n   prod )    ( Leave product: prod = m * n  )
15     .S          ( --   -- )     ( Non destructive stack print. )


Screen 17 not modified     
 0 \ Stack, Directory, Screen access              13:45JWB01/09/86 
 1     MAX         ( m n   max )   ( Leave larger  of m and n )    
 2     MIN         ( m n   min )   ( Leave smaller of m and n )    
 3     DEPTH       ( --    n   )   ( Leave count of stack items.)  
 4     \                           ( Comment to end of line   )    
 5     (  this is a comment  )                                     
 6     A:          ( --   -- )     ( Make the current drive A )    
 7     B:          ( --   -- )     ( Make the current drive B )    
 8     DIR         ( --   -- )     ( List current drive directory.)
 9     LIST        ( n    -- )     ( List screen or block n .)     
10     LOAD        ( n    -- )     ( Compile screen n .)           
11     INDEX       ( m n  -- )     ( Index screens m through n .)  
12     L           ( --   -- )     ( List the current screen. )    
13     N L         ( --   -- )     ( List the next  screen. )      
14     B L         ( --   -- )     ( List the previous screen.)    
15                                                                 


Screen 18 not modified     
 0 \ Operations with screen files.                13:46JWB01/09/86 
 1     FILE?       ( --   -- )     ( Display current screen file.) 
 2     DEFAULT     ( --   -- )     ( Revert to default screen file)
 3                                 ( used when FORTH was started.) 
 4     OPEN  <name>.BLK            ( Open an existing screen file.)
 5 \  Create a new screen file  <name>.BLK  with n blank screens.) 
 6     CREATE-FILE <name>.BLK  ( n   -- )                          
 7     MORE        ( n    -- )    ( Add n blank screens to the    )
 8                                ( end of the current screen file)
 9     QUERY       ( --   -- )    ( Fetch a line of text from user)
10     INTERPRET   ( --   -- )    ( Interpret the text line word by
11                                ( word.)                         
12     VEDIT       ( n    -- )    ( Begin editing screen n )       
13     VED         ( --   -- )    ( Begin editing current screen ) 
14     CAPACITY    ( --   n  )    ( Leave number of screens in the 
15                                ( current screen file.)          


Screen 19 not modified     
 0                                                                 
 1                                                                 
 2                                                                 
 3                                                                 
 4                                                                 
 5                                                                 
 6                                                                 
 7                                                                 
 8                                                                 
 9                                                                 
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 20 not modified     
 0 \ Check book register.                         10:41JWB03/25/86 
 1 \ Print balance forward.                                        
 2 : BFWD  ( bal    bal )    5 SPACES DUP    .  CR ;               
 3 \ Display amount of next entry and the new subtotal.            
 4 : +.  ( s1 n   s2)                                              
 5       DUP     .   + DUP    .  CR ;                              
 6 \ Done with this months checks, print the new total.            
 7 : DONE ( s    -- )                                              
 8        CR  ." ====================================="            
 9        CR  ."  You have . . . . "  .  ."  dollars left." CR ;   
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 21 not modified     
 0 \ My checking account                          10:41JWB03/25/86 
 1 CR                                                              
 2 .( Balance forward )    1000   BFWD                             
 3 .( Pay Check       )    1200   +.                               
 4 .( Mortgage        )    -500   +.                               
 5 .( Hydro           )    -120   +.                               
 6 .( Food            )    -200   +.                               
 7 .( Telephone       )     -25   +.                               
 8 .( Entertainment   )     -15   +.                               
 9 .( Car Payment     )    -300   +.    DONE EXIT                  
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 22 not modified     
 0                                                                 
 1                                                                 
 2                                                                 
 3                                                                 
 4                                                                 
 5                                                                 
 6                                                                 
 7                                                                 
 8                                                                 
 9                                                                 
10                                                                 
11                                                                 
12                                                                 
13                                                                 
14                                                                 
15                                                                 


Screen 23 not modified     
 0 \ Hard copy screen documentation.              19:58JWB09/26/85 
 1                                                                 
 2 \ Print three screens starting with n on the printer.           
 3 : HTRIAD  ( n   -- )                                            
 4         PRINTING ON DUP 3 +  SWAP   27 EMIT 69 EMIT             
 5         DO CR I LIST LOOP  PRINTING OFF ;                       
 6                                                                 
 7 \ Send a top of page command to printer.                        
 8 : FFEED                                                         
 9         PRINTING ON 12 EMIT PRINTING OFF ;                      
10                                                                 
11 \ Print screens  first through last  on printer, three per page.
12 : DOC   ( first last   -- )                                     
13         1+ SWAP DO I HTRIAD FFEED 3 +LOOP ;                     
14                                                                 
15                                                                 
projects/sample1.blk.txt · Zuletzt geändert: 2013-06-06 21:27 (Externe Bearbeitung)