papierkorb:a-start-with-forth:start
                Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
| papierkorb:a-start-with-forth:start [2025-08-20 21:10] – ↷ Links angepasst, weil Seiten im Wiki verschoben wurden mka | papierkorb:a-start-with-forth:start [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== 35 Forth Words as First Entry Application ====== | ||
| - | |||
| - | ( part of the eBook **A Start With Forth** published by Juergen ) | ||
| - | |||
| - | **NEW**: for a quick test just download the [[https:// | ||
| - | See the [[papierkorb: | ||
| - | |||
| - | Try it out – no installation needed, showing the final result of what is described here. | ||
| - | |||
| - | --- | ||
| - | |||
| - | Write a simple Application using just 35 Forth Words.((ExMark - Juergen Pintaske Sept2016)) Set IO Bits and start a '' | ||
| - | |||
| - | Runs under [[http:// | ||
| - | |||
| - | First install VFX430LITE from the [[http:// | ||
| - | |||
| - | {{: | ||
| - | |||
| - | |||
| - | ===== Description ===== | ||
| - | |||
| - | This is the virtual IO implementation of the MicroBox (see links further down), which consists of a Micro, PWM LED, 3 Switches, 4 OUT LEDs, 4 IN LEDs. Here shows some of this functionality in SW: no chip, no LEDs, no resistors, no PCB, no soldering, execute it on the PC only. Modify the code as exercise, change times, send other code than SOS and more. | ||
| - | |||
| - | This " | ||
| - | |||
| - | |||
| - | ===== The Code ===== | ||
| - | |||
| - | This has been intentionally written by just using simple words and constructs, so anybody can use it as startig point. And as with all Forth programs, this application can be easily modified and extended – as it all can be done interactively.  | ||
| - | |||
| - | ==== Definitions for GUI ==== | ||
| - | All of the numbers are understood as [[https:// | ||
| - | |||
| - | HEX | ||
| - |   : LINE1 ." \ VFXTESTAPP - bit change ie. PWH / PWL <cr>, try COUNTER, 400 SCOUNTER, SOS, ???? plus < | ||
| - |   : LINE2 ." \ PWHL T3HL T2HL T1HL O3HL O2HL O1HL O0HL I3HL I2HL I1HL I0HL A3Hl A2HL A1HL A0HL h/l ???? " CR ;   | ||
| - |   : LINE3 ." \ PWM  T3___T2___T1  | ||
| - |   : LINE4 ."  | ||
| - |   : TEST  PAGE LINE1 LINE2 LINE3  LINE4  ( LINE5 ) CR ;  \ display lines of our  GUI Graphic User Interface,  | ||
| - | |||
| - | ==== Variables used ==== | ||
| - | |||
| - |   Variable PWM    ( 0 or 1                                    | ||
| - | Variable SWI ( Switches SW3 SW2 SW1 0 0 0 ) \ not used for now, as combined in Variable PSWI | ||
| - |   Variable PSWI   ( PSWI X t t t  4 bits PWM and 3 Switches  | ||
| - |   Variable OUTP   ( OUTP 3 2 1 0  7 6 5 4 of the 8 bits      )  \ the 4 " | ||
| - | Variable IN ( IN 3 2 1 0 3 2 1 0 of the 8 Bits ) \ 4 Input bits that can be set e.g. for AND OR XOR INVERT | ||
| - |   Variable ANI    ( ANI  3 2 1 0  4 more bits for test        | ||
| - |   Variable HOU    ( OUT as hexadecimal number 0 to F          | ||
| - | Variable ALL ( PWM SWI OUT INP ANI ) \ To be done, combining it all into one 16 bit Variable | ||
| - | |||
| - | ==== The Forth Program Code ==== | ||
| - | |||
| - |   : disbit4  | ||
| - |   : ds        | ||
| - | : dssp ds Space Space space space ; \ combine a bit with 4 Spaces, to be a block for display | ||
| - |   : 4dssp    dssp dssp dssp disbit4  | ||
| - |   : DV       3 spaces PSWI @ 4dssp  4 spaces OUTP @ 4dssp 4 spaces IN @ 4dssp  4 spaces  | ||
| - |   : SPACES  | ||
| - |   : MBV2     PAGE LINE1 LINE2 LINE3 LINE4 DV CR ;     \ MBV2 updates the “SCREEN”, | ||
| - |   : COUNTER  | ||
| - | : SCOUNTER Begin dup outp @ 1+ outp ! ms mbv2 key? until ; \ the same with programmable speed, for example 400 scounter <cr> | ||
| - | : SOS 07 emit 100 ms 07 emit 100 ms 07 emit 600 ms 07 emit 300 ms 07 emit 300 ms 07 emit 600 ms 07 emit 100 ms 07 emit 100 ms 07 emit ; | ||
| - |   : LINE5  ." PSWI OUT  IN    | ||
| - | |||
| - | ==== Debugging ==== | ||
| - | |||
| - | : ???? 3 spaces PSWI @ . OUTP @ . IN @ . ANI @ . 4 spaces >R >R >R >R >R >R >R >R R> DUP . R> DUP . R> DUP . R> DUP . R> DUP . R> DUP . R> DUP . R> DUP . ; \ ???? displays PSWI OUTP IN ANI and DSTACK 8 levels. Enter FFFF, sets lowest one visible as bottom, so 7 left | ||
| - | : ??? PSWI @ . OUTP @ . IN @ . ANI @ . base @ >r hex .S r> base ! ; \ Debug 2 - prints 4 variables + Data + Stack differently | ||
| - | |||
| - | ==== Preset Variables ==== | ||
| - | |||
| - |   0 PWM  !          | ||
| - |   0 SWI  !          | ||
| - | 9 PSWI ! \ Set this combined variable to 9 = 1001 this will show the PWM LED ON and T1 ON | ||
| - | 0 OUTP ! \ All bits LOW 0000 | ||
| - |   3 IN    | ||
| - | F ANI ! \ Set to F, so all bits HIGH, free for any use, e.g. program an extra counter, or for other tests | ||
| - | F HOU ! \ not used for now | ||
| - |   \ FFFF ALL  !      | ||
| - | |||
| - | ==== Control Words ==== | ||
| - | |||
| - | : PWH PSWI @ $8 OR PSWI ! MBV2 ; \ Get the variable onto stack, set bit 3 using OR, and store it back, now update the Display | ||
| - | : T3H PSWI @ $4 OR PSWI ! MBV2 ; \ Get the variable onto stack, set bit 2, and store it back, see above | ||
| - | : T2H PSWI @ $2 OR PSWI ! MBV2 ; \ And the same for setting all of the other bits | ||
| - | : T1H PSWI @ $1 OR PSWI ! MBV2 ; | ||
| - | : O3H OUTP @ $8 OR OUTP ! MBV2 ; \ x x x x 1 0 0 0 | ||
| - | : O2H OUTP @ $4 OR OUTP ! MBV2 ; \ 0 1 0 0 | ||
| - | : O1H OUTP @ $2 OR OUTP ! MBV2 ; \ 0 0 1 0 | ||
| - | : O0H OUTP @ $1 OR OUTP ! MBV2 ; \ 0 0 0 1 | ||
| - |   : I3H    | ||
| - |   : I2H    | ||
| - |   : I1H    | ||
| - |   : I0H    | ||
| - |   : A3H    | ||
| - |   : A2H    | ||
| - |   : A1H    | ||
| - |   : A0H    | ||
| - |   : PWL   PSWI @  $7 AND  PSWI !  MBV2 ;  \ x x x x    0 1 1 1       | ||
| - | : T3L PSWI @ $B AND PSWI ! MBV2 ; \ 1 0 1 1 | ||
| - | : T2L PSWI @ $D AND PSWI ! MBV2 ; \ 1 1 0 1 | ||
| - | : T1L PSWI @ $E AND PSWI ! MBV2 ; \ 1 1 1 0 | ||
| - | : O3L OUTP @ $7 AND OUTP ! MBV2 ; | ||
| - | : O2L OUTP @ $B AND OUTP ! MBV2 ; | ||
| - | : O1L OUTP @ $D AND OUTP ! MBV2 ; | ||
| - | : O0L OUTP @ $E AND OUTP ! MBV2 ; | ||
| - |   : I3L    | ||
| - |   : I2L    | ||
| - |   : I1L    | ||
| - |   : I0L    | ||
| - |   : A3L    | ||
| - |   : A2L    | ||
| - |   : A1L    | ||
| - |   : A0L    | ||
| - | |||
| - | ==== Logic Examples ==== | ||
| - | |||
| - | Set I1 and/or I0 of the INPUTs, then call AND01, OR01, XOR01, INVERT0 and see the result of the logic result in OUT0 | ||
| - | : AND01 IN @ DUP 1 RSHIFT AND 01 AND OUTP ! MBV2 ; \ Do an AND of IN bit0 and bit1, 00=>1 01=>0 10=>0 11=>1 | ||
| - | : OR01 IN @ DUP 1 RSHIFT OR 01 AND OUTP ! MBV2 ; \ Do an OR of IN bit0 and bit1, 00=>0 01=>1 10=>1 11=>1 | ||
| - | : XOR01 IN @ DUP 1 RSHIFT XOR 01 AND OUTP ! MBV2 ; \ Do an XOR of IN bit0 and bit1, 00=>0 01=>1 10=>1 11=>0 | ||
| - |   : INVERT0  | ||
| - | |||
| - | ==== Glossary ==== | ||
| - | |||
| - | \ Forth Words used - remember: Any Forth Word consists of a character sequence plus a space (not allowed in Words is Space ) | ||
| - |   \  0 INCLUDE  | ||
| - |   \  1 HEX        | ||
| - |   \  2 \         \ and a Space after it tells Forth, that the rest of the line is for documentation, | ||
| - |   \  3 :         : starts new Forth Word definition, is terminated by ;  see Number 6. Example  | ||
| - |   \  4 ."  | ||
| - | \ 5 CR CR defines a word that places the cursor to the beginning of the next line | ||
| - | \ 6 ; ; ends the definition started by : see number 3 | ||
| - | \ 7 TEST TEST is the name of a new word defined just to display the GUI - the Graphical User Interface | ||
| - |   \  8 Variable  | ||
| - | \ 9 DUP DUP takes the value on top of the stack and puts the same value on top as NEW TOS - Top of Stack | ||
| - | \ 10 $n $n - the $ ensures that VFX takes the number following as hexadecimal number | ||
| - | \ 11 AND AND is a logical operator. works on the two top numbers on the stack, on a bitwise basis, only leaves result | ||
| - | \ 12 IF IF is not zero do A - ELSE do B - THEN continue | ||
| - |   \ 13 ELSE       | ||
| - |   \ 14 THEN       | ||
| - |   \ 15 LSHIFT  | ||
| - | \ 16 SPACE SPACE sends a space to the screen | ||
| - | \ 17 DROP DROP does the opposite to DUP; DROP takes the TOS and deletes what was there, all values move up one position | ||
| - | \ 18 DV DV is a word that combines the 4x 4 bits of the variables for the screen, 16 Bit wide. | ||
| - | \ 19 @ @ stands for me for AT, for example with Variables - xx puts address of xx onto the stack, xx @ gets the value of it | ||
| - | \ 20 ?DO ?DO will start a DO word word LOOP, expects the number of loops on stack. ?DO checks if number on stack is 0. | ||
| - | \ 21 LOOP Goes back to ?DO until 0, then continues | ||
| - | \ 22 PAGE PAGE clears the screen, takes the cursor to the top left position and prints ok | ||
| - | \ 23 BEGIN BEGIN starts a loop of words which ends with UNTIL. UNTIL expects a flag on stack; not 0 then to BEGIN else continue | ||
| - | \ 24 1+ 1+ is put on stack, adds one to the number below and replaces it. Same function as 1 + as 2 words. | ||
| - | \ 25 ! ! is the opposite function to @, and stores the number on stack at a location on stack, e.g. 55 xx ! at Variable xx | ||
| - |   \ 26 MS        MS stands  | ||
| - | \ 27 KEY? Key? Checks, if a key has been pushed as this generates a flag. BEGIN xxxxxxxx KEY? UNTIL - flag stops the loop | ||
| - | \ 28 UNTIL UNTIL end the BEGIN … UNTIL loop, exit if flag true. | ||
| - | \ 29 EMIT (07 for Bell ) to get audible output from the PC - ( : ) BELL 07 BEL ( ; )sends the bell signal to the speaker | ||
| - |   \ 30 .S        .S is a non-destructive display of the stack,  | ||
| - | \ 31 . . is similar to .S, prints out the top item only and as well consumes it; an easy way to get rid of the top stack item | ||
| - | \ 32 >R >R takes an item from DSTACK and moves to the RSTACK; | ||
| - | \ 33 R> R> does the opposite: take item from RSTACK move it to the top of DSTACK | ||
| - | \ 34 ( and ) These 2 brackets are used to put explanations within the code, and this is ignored by Forth, similar to \ | ||
| - | \ ------ it seems this covers all of the words needed for this little sandbox application | ||
| - | |||
| - | We know this application is not programmed optimally - but this was not the target - beginner' | ||
| - |   sos      \ --    send  SOS       | ||
| - | and then | ||
| - |   counter  | ||
| - |   400 SCOUNTER  | ||
| - | |||
| - | ==== Make your own words: NAME example ==== | ||
| - | |||
| - | Add a new word, from | ||
| - | |||
| - | : Name ." Hello Forth World " ; | ||
| - | |||
| - | To | ||
| - | |||
| - | : NameP ." Hello, my name is XXXX, I am the next president of the United States " ; | ||
| - | |||
| - | Use it interactively, | ||
| - | |||
| - | NameP <cr> | ||
| - | |||
| - | Now use more interactive words. Clear the screen ( Page CR ) , print your word ( Name , wait 1000 ms ( 1000 ms ) , get OK from Forth | ||
| - | |||
| - | Page CR NameP 1000 ms | ||
| - | |||
| - | ===== The Forth Machine ===== | ||
| - | |||
| - | Data stream coming in on the left, THE_STACK, RETURN_STACK, | ||
| - | |||
| - | The Forth Machine looks very complicated – but people actually use a similar model every day at their desk: | ||
| - | work coming in --> store on stack1 or 2 if needed --> execute --> results out | ||
| - | |||
| - | |||
| - | | DIGITAL_IN| TOP_OF_STACK| TOP_OF_RS| | x7| DIGITAL_OUT| | ||
| - | | (for later)|DS-1|RS-1| |x6|(for later)| | ||
| - | | |DS-2|RS-2| |x5| | | ||
| - | | |DS-3|RS-3| |x4| | | ||
| - | | |DS-4|RS-4|PSWI|x3| | | ||
| - | | |DS-5|RS-5|OUTP|x2| | | ||
| - | | |DS-6|RS-6|IN|x1| | | ||
| - | |Token_n T7 T6 T5 T4 T3 T2 T1 T0|FFFF(-7)|FFFF|ANI|x0|Hello Forth World| | ||
| - | ||||||| | ||
| - | ^Terminal_Input_Buffer_Contents^DATA_STACK^RETURN_STACK^VARIABLES^MEMORY^TO_SCREEN^ | ||
| - | |||
| - | ExMark October 2016 | ||
| - | |||
| - | ====== To get Started ====== | ||
| - | |||
| - | Open the PDF File further down {{ : | ||
| - | |||
| - |   * Page 1-3  the VFXTESTAPP  | ||
| - | * Page 4 the Forth Machine – how data is processed internally | ||
| - |   * Page 5     the installation information, | ||
| - | * Page 6 the different parts of VFX – open the DFX Debug Console where the VFXTESTAPP will run in Utilities. | ||
| - | |||
| - | |||
| - | ====== VFX Manuals ====== | ||
| - | |||
| - | {{: | ||
| - | }}\\ | ||
| - | {{: | ||
| - | {{: | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | ====== Links ====== | ||
| - | |||
| - | The pure text file you have to put into the folder C: | ||
| - | {{ : | ||
| - | |||
| - | Further information: | ||
| - | {{ : | ||
| - | {{ : | ||
| - | as the code in the window | ||
| - | |||
| - | {{ : | ||
| - | {{ : | ||
| - | as a short version for own text addition | ||
| - | |||
| - | {{ : | ||
| - | in portrait format, all on just one page, to print and follow easily. | ||
| - | |||
| - | Other parts of this project, //designed for running on external hardware//, including MicroBox:\\ | ||
| - | [[en: | ||
| - | [[en: | ||
| - | |||
| - | Some eBooks for further reading at:\\ | ||
| - | [[https:// | ||
| - | |||
| - | And Starting Forth by Leo Brodie for download and print at:\\ | ||
| - | [[http:// | ||
| - | |||
| - | **And all of the Forth Words used [[various: | ||
| - | |||
| - | |||
| - | ====== Binary - Hexadecimal - Decimal Conversion Table ====== | ||
| - | |||
| - | 0000 - 0 - 00 | ||
| - | 0001 - 1 - 01 | ||
| - | 0011 - 2 - 02 | ||
| - | 0011 - 3 - 03 | ||
| - | 0100 - 4 - 04 | ||
| - | 0101 - 5 - 05 | ||
| - | 0110 - 6 - 06 | ||
| - | 0111 - 7 - 07 | ||
| - | 1000 - 8 - 08 | ||
| - | 1001 - 9 - 09 | ||
| - | 1010 - A - 10 | ||
| - | 1011 - B - 11 | ||
| - | 1100 - C - 12 | ||
| - | 1101 - D - 13 | ||
| - | 1110 - E - 14 | ||
| - | 1111 - F - 15 | ||
| - | |||
papierkorb/a-start-with-forth/start.1755717003.txt.gz · Zuletzt geändert: 2025-08-20 21:10 von mka