papierkorb:4th_lesson_8
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:4th_lesson_8 [2025-08-16 19:10] – ↷ Seite von projects:4th_lesson_8 nach papierkorb:4th_lesson_8 verschoben mka | papierkorb:4th_lesson_8 [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === Lesson 8 === | ||
| - | < | ||
| - | \ | ||
| - | \ The Forth Course | ||
| - | \ by Richard E. Haskell | ||
| - | \ Dept. of Computer Science and Engineering | ||
| - | \ Oakland University, Rochester, MI 48309 | ||
| - | |||
| - | comment: | ||
| - | |||
| - | |||
| - | |||
| - | Lesson 8 | ||
| - | |||
| - | | ||
| - | |||
| - | |||
| - | 8.1 CREATE...DOES> | ||
| - | |||
| - | 8.2 A SIMPLE JUMP TABLE 8-4 | ||
| - | |||
| - | 8.3 JUMP TABLE WITH ARBITRARY STACK VALUES | ||
| - | |||
| - | 8.4 JUMP TABLE WITH FORTH WORDS 8-8 | ||
| - | |||
| - | 8.5 POP-UP MENUS 8-10 | ||
| - | |||
| - | 8.6 EXERCISES | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | 8.1 CREATE...DOES> | ||
| - | |||
| - | The Forth word pair CREATE...DOES> | ||
| - | words", | ||
| - | thing about defining words is that at the time they are defined | ||
| - | the run-time behavior is specified for all future words that may | ||
| - | be defined using this defining word. We will illustrate the use | ||
| - | of CREATE...DOES> | ||
| - | ' | ||
| - | comment; | ||
| - | |||
| - | : table ( list n +++ ) | ||
| - | CREATE | ||
| - | 0 DO | ||
| - | C, | ||
| - | LOOP | ||
| - | DOES> | ||
| - | + C@ ; | ||
| - | |||
| - | \ This word can be used to define the new word " | ||
| - | |||
| - | 3 15 7 2 4 table junk | ||
| - | comment: | ||
| - | |||
| - | When the word ' | ||
| - | and DOES> in the definition of ' | ||
| - | cause the word ' | ||
| - | values stored in the pfa of ' | ||
| - | |||
| - | junk | ||
| - | ______________ | ||
| - | CFA | CALL ^DOES | <------| | ||
| - | |------------| | ||
| - | PFA | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | 15 | ix = 2 | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | Code Segment ?CS: | ||
| - | |||
| - | The code field of ' | ||
| - | which will cause the Forth words following DOES> in the definition | ||
| - | of ' | ||
| - | PFA of ' | ||
| - | are executed. | ||
| - | ix on the stack, this index will be added to the PFA and then | ||
| - | C@ will fetch the byte at that location. | ||
| - | |||
| - | 2 junk . | ||
| - | |||
| - | will print 15. | ||
| - | |||
| - | The way CREATE...DOES> | ||
| - | ' | ||
| - | |||
| - | table | ||
| - | _____________ | ||
| - | CFA |JMP NEST | <------| | ||
| - | |-----------| | ||
| - | PFA | | ||
| - | |-----------| | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | | ||
| - | | ||
| - | | ||
| - | | | ||
| - | | ||
| - | | ||
| - | | ||
| - | |------------| | ||
| - | PFA | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | 15 | ix = 2 | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | Code Segment ?CS: | ||
| - | |||
| - | |||
| - | Note that the code field of ' | ||
| - | to the instruction CALL DODOES following the PFA of ' | ||
| - | (This CALL ^DOES instruction in inserted into the code field | ||
| - | of ' | ||
| - | This has two effects. | ||
| - | stack, and second it executes the statement CALL DODOES which | ||
| - | executes the Forth words whose CFAs are in the list segment | ||
| - | pointed to by LSO2. These are just the statements that were | ||
| - | defined following DOES> in the definition of ' | ||
| - | important to note that these same Forth words will be executed | ||
| - | each time ANY word defined by ' | ||
| - | very powerful feature that we will exploit in the following sections | ||
| - | to define various types of jump tables. | ||
| - | |||
| - | |||
| - | |||
| - | 8.2 A SIMPLE JUMP TABLE | ||
| - | |||
| - | As an example of using a defining word, suppose you want to | ||
| - | create a jump table called ' | ||
| - | |||
| - | do.key | ||
| - | ______________ | ||
| - | CFA | CODE | <------| | ||
| - | |------------| | ||
| - | PFA | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | Code Segment ?CS: | ||
| - | |||
| - | This might be used, for example, if you had a keypad with five | ||
| - | keys labeled 0 - 5 which returned the values 0 - 5 on the stack | ||
| - | when the corresponding key was pressed. | ||
| - | the Forth words 0word, 1word, ... , 4word when the corresponding | ||
| - | key is pressed. | ||
| - | jump table. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | We will define a defining word called JUMP.TABLE that can be used | ||
| - | to produce ' | ||
| - | ' | ||
| - | |||
| - | 5 JUMP.TABLE do.key | ||
| - | 0word | ||
| - | 1word | ||
| - | 2word | ||
| - | 3word | ||
| - | 4word | ||
| - | |||
| - | The following definition of JUMP.TABLE will do the job: | ||
| - | comment; | ||
| - | |||
| - | : JUMP.TABLE | ||
| - | CREATE | ||
| - | DUP , | ||
| - | 0 ?DO | ||
| - | ' , | ||
| - | LOOP | ||
| - | DOES> | ||
| - | SWAP 1+ SWAP \ n+1 pfa | ||
| - | 2DUP @ > \ n+1 pfa (n+1)> | ||
| - | IF | ||
| - | 2DROP | ||
| - | ELSE | ||
| - | SWAP \ pfa n+1 | ||
| - | 2* + \ addr = pfa + 2(n+1) | ||
| - | PERFORM | ||
| - | THEN ; | ||
| - | |||
| - | comment: | ||
| - | In this definition the word PERFORM will execute the word whose | ||
| - | CFA is stored at the address on top of the stack. | ||
| - | |||
| - | In the DO loop following CREATE the words ' , (tick comma) are | ||
| - | used to store in the jump table the CFAs of the words listed | ||
| - | after executing JUMP.TABLE do.key. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | 8.3 JUMP TABLE WITH ARBITRARY STACK VALUES | ||
| - | |||
| - | A limitation of the jump table described in the previous section | ||
| - | is that the index into the table must be consecutive integers | ||
| - | starting at zero. Often the value one knows is an ASCII code | ||
| - | corresponding to a key that has been pressed. | ||
| - | jump table would involve a key value (e.g. an ASCII code) plus | ||
| - | a CFA value for each entry as shown in the following table. | ||
| - | |||
| - | do.key | ||
| - | ______________ | ||
| - | CFA | CODE | <------| | ||
| - | |------------| | ||
| - | PFA | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | bkspace | ||
| - | |------------| | ||
| - | | 17 | | ||
| - | |------------| | ||
| - | | | ||
| - | |------------| | ||
| - | | 27 | | ||
| - | |------------| | ||
| - | | escape | ||
| - | |------------| | ||
| - | | chrout | ||
| - | |------------| | ||
| - | Code Segment ?CS: | ||
| - | |||
| - | This table might be used in an editor where the ASCII code 8 | ||
| - | would cause the Forth word ' | ||
| - | code 17 (control-Q) would cause the word ' | ||
| - | and the ASCII code 27 would cause the word ' | ||
| - | The default word ' | ||
| - | in the jump table. | ||
| - | screen. | ||
| - | pairs. | ||
| - | MAKE.TABLE as follows: | ||
| - | |||
| - | MAKE.TABLE do.key | ||
| - | 8 bkspace | ||
| - | 17 quit | ||
| - | 27 escape | ||
| - | -1 chrout | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | A definition of MAKE.TABLE that will do this is as follows: | ||
| - | comment; | ||
| - | |||
| - | : MAKE.TABLE | ||
| - | CREATE | ||
| - | HERE 0 , 0 \ pfa 0 | ||
| - | BEGIN | ||
| - | BL WORD NUMBER DROP \ pfa 0 n | ||
| - | DUP 1+ \ pfa 0 n n+1 | ||
| - | | ||
| - | , ' , \ pfa 0 | ||
| - | 1+ \ pfa cnt | ||
| - | | ||
| - | DROP ' , \ pfa cnt | ||
| - | SWAP ! | ||
| - | DOES> | ||
| - | DUP 2+ \ n pfa pfa+2 | ||
| - | SWAP @ \ n pfa+2 cnt | ||
| - | 0 DO \ n code.addr | ||
| - | 2DUP @ = \ n addr (n=code) | ||
| - | IF \ n addr | ||
| - | NIP 2+ LEAVE \ -> CFA | ||
| - | THEN | ||
| - | 4 + \ n addr | ||
| - | LOOP | ||
| - | | ||
| - | |||
| - | comment: | ||
| - | Note that a -1 is used to identify the default word. The DUP 1+ | ||
| - | before the WHILE statement will cause this -1 to become 0 when the | ||
| - | default word is reached and exit the BEGIN...WHILE...REPEAT loop. | ||
| - | When ' | ||
| - | DOES> part of the above definition is executed which will execute | ||
| - | either the CFA of an ASCII code match or the default word. Note | ||
| - | that if the default word is executed, the ASCII code will still | ||
| - | be on the stack so that it can be displayed on the screen. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | 8.4 JUMP TABLE WITH FORTH WORDS | ||
| - | |||
| - | A disadvantage of using the defining word MAKE.TABLE in the previous | ||
| - | section is that the value of the ASCII code must be known when | ||
| - | making the table. | ||
| - | Forth words ASCII and CONTROL to find these ASCII codes. | ||
| - | For example, | ||
| - | |||
| - | ASCII A | ||
| - | |||
| - | will return the value 65 (hex 41) on the stack. | ||
| - | |||
| - | CONTROL Q | ||
| - | |||
| - | will return the value 17 (hex 11) on the stack. | ||
| - | nice to be able in include parentheses comments when making the | ||
| - | jump table. | ||
| - | define a new defining word called EXEC.TABLE that will allow us | ||
| - | to make the same jump table as shown in the previous section as | ||
| - | by typing | ||
| - | |||
| - | EXEC.TABLE do.key | ||
| - | CONTROL H | bkspace | ||
| - | CONTROL Q | quit ( quit to DOS ) | ||
| - | HEX 2B | ||
| - | DEFAULT| | ||
| - | |||
| - | The definition of the word EXEC.TABLE that will do this is as | ||
| - | follows: | ||
| - | comment; | ||
| - | |||
| - | : EXEC.TABLE | ||
| - | CREATE | ||
| - | HERE 0 , \ pfa | ||
| - | DOES> | ||
| - | DUP 2+ \ n pfa pfa+2 | ||
| - | SWAP @ \ n pfa+2 cnt | ||
| - | 0 DO \ n code.addr | ||
| - | 2DUP @ = \ n addr (n=code) | ||
| - | IF \ n addr | ||
| - | NIP 2+ LEAVE \ -> CFA | ||
| - | THEN | ||
| - | 4 + \ n addr | ||
| - | LOOP | ||
| - | | ||
| - | |||
| - | comment: | ||
| - | Note that the DOES> part of this definition is the same as that | ||
| - | in the definition of MAKE.TABLE. | ||
| - | much simpler. | ||
| - | PFA of the defined word (do.key) and leaves this PFA value on the | ||
| - | stack. | ||
| - | Forth word CONTROL H. This will leave the value 8 on the stack. | ||
| - | Thus, at this point the stack contains the values PFA 8. | ||
| - | |||
| - | The vertical bar | is a Forth word with the following definition: | ||
| - | comment; | ||
| - | |||
| - | : | ( addr n -- addr ) | ||
| - | , ' , \ store n and CFA in table | ||
| - | 1 OVER +! ; \ increment count at PFA | ||
| - | |||
| - | comment: | ||
| - | Note the the first line , ' , (comma-tick-comma) will comma the | ||
| - | value of n (the ASCII code) into the table being created and then | ||
| - | the tick (') will get the CFA of the Forth word following the | ||
| - | vertical bar | and comma it into the table. | ||
| - | on the same line such as ( or DECIMAL will just be executed. | ||
| - | |||
| - | The word DEFAULT| is defined as follows: | ||
| - | comment; | ||
| - | |||
| - | : DEFAULT| | ||
| - | DROP ' , ; | ||
| - | |||
| - | comment: | ||
| - | It just drops the PFA, gets the CFA of the default word (chrout) | ||
| - | and commas it into the jump table. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | 8.5 POP-UP MENUS | ||
| - | |||
| - | This section will use the defining word EXEC.TABLE to define the | ||
| - | action to take in response to various key pressings in pop-up | ||
| - | menus. | ||
| - | a nice menu-driven program. | ||
| - | |||
| - | The following key ASCII codes are useful to have on hand: | ||
| - | comment; | ||
| - | |||
| - | 200 | ||
| - | 208 | ||
| - | 203 | ||
| - | 205 | ||
| - | 199 | ||
| - | 207 | ||
| - | 201 | ||
| - | 209 | ||
| - | 210 | ||
| - | 211 | ||
| - | 8 | ||
| - | 9 | ||
| - | 13 CONSTANT 'enter | ||
| - | 27 CONSTANT 'esc | ||
| - | 187 | ||
| - | 188 | ||
| - | 189 | ||
| - | 190 | ||
| - | 191 | ||
| - | 192 | ||
| - | 193 | ||
| - | 194 | ||
| - | 195 | ||
| - | 196 | ||
| - | |||
| - | \ The following common variables are used for each menu: | ||
| - | VARIABLE row_start | ||
| - | VARIABLE col_start | ||
| - | VARIABLE row_select | ||
| - | VARIABLE no_items | ||
| - | |||
| - | PREFIX | ||
| - | |||
| - | \ Read the character and attribute at the current cursor position | ||
| - | CODE ? | ||
| - | MOV BH, # 0 | ||
| - | MOV AH, # 8 | ||
| - | INT | ||
| - | MOV BL, AH | ||
| - | MOV BH, # 0 | ||
| - | AND AH, # 0 | ||
| - | PUSH BX | ||
| - | PUSH AX | ||
| - | NEXT | ||
| - | END-CODE | ||
| - | |||
| - | \ Write the character and attribute at the current cursor position | ||
| - | CODE .char/ | ||
| - | POP AX | ||
| - | POP BX | ||
| - | MOV AH, # 9 | ||
| - | MOV CX, # 1 | ||
| - | MOV BH, # 0 | ||
| - | INT | ||
| - | NEXT | ||
| - | END-CODE | ||
| - | |||
| - | \ | ||
| - | CODE .n.chars | ||
| - | POP AX | ||
| - | POP BX | ||
| - | POP CX | ||
| - | MOV AH, # 9 | ||
| - | MOV BH, # 0 | ||
| - | INT | ||
| - | NEXT | ||
| - | END-CODE | ||
| - | |||
| - | \ Get the current video mode | ||
| - | CODE get.vmode | ||
| - | MOV AH, # 15 | ||
| - | INT | ||
| - | MOV AH, # 0 | ||
| - | PUSH AX | ||
| - | NEXT | ||
| - | END-CODE | ||
| - | |||
| - | : UNUSED ; | ||
| - | |||
| - | \ | ||
| - | : inc.curs | ||
| - | IBM-AT? SWAP 1+ SWAP AT ; | ||
| - | |||
| - | \ Plot character with the opposite attribute | ||
| - | : .char.bar | ||
| - | SWAP DUP 2/ 2/ 2/ 2/ 7 AND \ swap foreground | ||
| - | SWAP 7 AND 8* 2* OR \ and background | ||
| - | SWAP .char/attr ; | ||
| - | |||
| - | : togatt | ||
| - | ? | ||
| - | .char.bar ; \ at current cursor location | ||
| - | |||
| - | : invatt | ||
| - | BEGIN | ||
| - | ?char/attr DUP 32 = NOT | ||
| - | WHILE | ||
| - | REPEAT 2DROP ; | ||
| - | |||
| - | |||
| - | : invline | ||
| - | BEGIN | ||
| - | | ||
| - | | ||
| - | | ||
| - | ? | ||
| - | NIP | ||
| - | 32 = | ||
| - | UNTIL ; | ||
| - | |||
| - | : movcur | ||
| - | col_start @ row_select @ | ||
| - | 2* row_start @ + AT ; | ||
| - | |||
| - | : inv.first.chars | ||
| - | no_items @ 0 DO | ||
| - | I row_select ! | ||
| - | | ||
| - | LOOP ; | ||
| - | |||
| - | : select.first.item | ||
| - | 0 row_select ! | ||
| - | movcur invline ; | ||
| - | |||
| - | : inv.field | ||
| - | movcur | ||
| - | invline | ||
| - | row_select ! \ invert line n | ||
| - | movcur | ||
| - | invline ; | ||
| - | |||
| - | \ The up and down cursor keys will change the selected item. | ||
| - | |||
| - | : down.curs | ||
| - | movcur | ||
| - | invline | ||
| - | row_select @ 1+ DUP no_items @ = | ||
| - | IF | ||
| - | DROP 0 | ||
| - | THEN | ||
| - | row_select ! | ||
| - | movcur | ||
| - | invline ; | ||
| - | |||
| - | : up.curs | ||
| - | movcur | ||
| - | invline | ||
| - | row_select @ 1- DUP 0< | ||
| - | IF | ||
| - | DROP no_items @ 1- | ||
| - | THEN | ||
| - | row_select ! | ||
| - | movcur | ||
| - | invline ; | ||
| - | |||
| - | \ Every defined menu has the following values stored in its | ||
| - | \ | ||
| - | \ | upper.left.col | upper.left.row | width | no.items | | ||
| - | |||
| - | \ The following constants are the offsets into the parameter field: | ||
| - | |||
| - | 0 | ||
| - | 2 | ||
| - | 4 | ||
| - | 6 | ||
| - | |||
| - | comment: | ||
| - | To define a menu of a certain size you would type | ||
| - | |||
| - | { 25 [upper.left.col] | ||
| - | 15 [upper.left.row] | ||
| - | 20 [width] | ||
| - | 3 [no.items] } | ||
| - | define.menu menu1 | ||
| - | |||
| - | The defining word " | ||
| - | comment; | ||
| - | |||
| - | : define.menu | ||
| - | CREATE | ||
| - | HERE 8 ALLOT SWAP \ list pfa n | ||
| - | 2/ 0 DO \ v1 ix1 v2 ix2 v3 ix3 pfa | ||
| - | SWAP OVER + \ v1 ix1 v2 ix2 v3 pfa addr | ||
| - | ROT SWAP ! \ v1 ix1 v2 ix2 pfa | ||
| - | LOOP | ||
| - | DROP | ||
| - | DOES> | ||
| - | DUP [upper.left.col] + @ 1+ col_start ! | ||
| - | DUP [upper.left.row] + @ 1+ row_start ! | ||
| - | DUP [no.items] + @ no_items ! ; | ||
| - | |||
| - | comment: | ||
| - | Note that this will define the word " | ||
| - | 25, 15, 20, and 3 associated with the size of the menu stored | ||
| - | in the parameter field. | ||
| - | { ... } will leave the number of items between the brackets on | ||
| - | top of the stack. | ||
| - | FLOAD LESSON8 in order to have the brackets { and } defined. | ||
| - | |||
| - | When the word " | ||
| - | field will be used to store values in col_start, row_start and | ||
| - | no_items appropriate for this particular menu. | ||
| - | comment; | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | \ This word prepares the stack for the F-PC word BOX& | ||
| - | \ See the file BOXTEXT.SEQ for a description of BOX& | ||
| - | |||
| - | : ul.br ( pfa -- ul.col ul.row br.col br.row ) | ||
| - | DUP [upper.left.col] + @ \ pfa ul.col | ||
| - | OVER [upper.left.row] + @ \ pfa ul.col ul.row | ||
| - | 2 PICK [width] + @ 1- 2 PICK + \ pfa ul.col ul.row br.col | ||
| - | 3 ROLL [no.items] + @ 2* 2 PICK + ; | ||
| - | |||
| - | \ | ||
| - | |||
| - | { 25 [upper.left.col] | ||
| - | 8 [upper.left.row] | ||
| - | 20 [width] | ||
| - | 3 [no.items] } | ||
| - | define.menu main.menu | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | \ First menu ------------------------ | ||
| - | |||
| - | { 30 [upper.left.col] | ||
| - | 10 [upper.left.row] | ||
| - | 20 [width] | ||
| - | 2 [no.items] } | ||
| - | define.menu first.menu | ||
| - | |||
| - | : first.menu.display | ||
| - | 0 inv.field | ||
| - | SAVESCR | ||
| - | first.menu | ||
| - | ul.br BOX& | ||
| - | ." First sub1 item" | ||
| - | bcr bcr ." Second sub1 item" | ||
| - | inv.first.chars | ||
| - | select.first.item ; | ||
| - | |||
| - | : first.sub1 ; | ||
| - | |||
| - | : second.sub1 ; | ||
| - | |||
| - | : escape.first | ||
| - | RESTSCR | ||
| - | main.menu DROP | ||
| - | 0 row_select ! | ||
| - | 2R> 2DROP | ||
| - | 2R> 2DROP | ||
| - | EXIT ; | ||
| - | |||
| - | : enttbl.first | ||
| - | EXEC: | ||
| - | first.sub1 | ||
| - | second.sub1 ; | ||
| - | |||
| - | : enter.first | ||
| - | row_select @ enttbl.first ; | ||
| - | |||
| - | EXEC.TABLE do.key.first | ||
| - | ' | ||
| - | ' | ||
| - | ASCII F | ||
| - | ASCII f | ||
| - | ASCII S | ||
| - | ASCII s | ||
| - | ' | ||
| - | CONTROL M | enter.first | ||
| - | | ||
| - | |||
| - | : first.item | ||
| - | first.menu.display | ||
| - | BEGIN | ||
| - | KEY do.key.first | ||
| - | AGAIN ; | ||
| - | |||
| - | \ | ||
| - | |||
| - | { 30 [upper.left.col] | ||
| - | 12 [upper.left.row] | ||
| - | 20 [width] | ||
| - | 2 [no.items] } | ||
| - | define.menu second.menu | ||
| - | |||
| - | : second.menu.display | ||
| - | 1 inv.field | ||
| - | SAVESCR | ||
| - | second.menu | ||
| - | ul.br BOX& | ||
| - | ." First sub2 item" | ||
| - | bcr bcr ." Second sub2 item" | ||
| - | inv.first.chars | ||
| - | select.first.item ; | ||
| - | |||
| - | : first.sub2 ; | ||
| - | : second.sub2 ; | ||
| - | |||
| - | : escape.second | ||
| - | RESTSCR | ||
| - | main.menu | ||
| - | 1 row_select ! | ||
| - | 2R> 2DROP | ||
| - | 2R> 2DROP | ||
| - | EXIT ; | ||
| - | |||
| - | : enttbl.second | ||
| - | EXEC: | ||
| - | first.sub2 | ||
| - | second.sub2 ; | ||
| - | |||
| - | : enter.second | ||
| - | row_select @ enttbl.second ; | ||
| - | |||
| - | EXEC.TABLE do.key.second | ||
| - | ' | ||
| - | ' | ||
| - | ASCII F | ||
| - | ASCII f | ||
| - | ASCII S | ||
| - | ASCII s | ||
| - | ' | ||
| - | CONTROL M | enter.second | ||
| - | | ||
| - | |||
| - | : second.item | ||
| - | second.menu.display | ||
| - | BEGIN | ||
| - | KEY do.key.second | ||
| - | AGAIN ; | ||
| - | |||
| - | |||
| - | \ Main menu -------------------- | ||
| - | |||
| - | : main.menu.display | ||
| - | DARK | ||
| - | main.menu | ||
| - | ul.br BOX& | ||
| - | ." First item" | ||
| - | bcr bcr ." Second item" | ||
| - | bcr bcr ." Quit" | ||
| - | inv.first.chars | ||
| - | select.first.item | ||
| - | CURSOR-OFF ; | ||
| - | |||
| - | : quit.main | ||
| - | CURSOR-ON DARK ABORT ; | ||
| - | |||
| - | : enttbl.main | ||
| - | EXEC: | ||
| - | first.item | ||
| - | second.item | ||
| - | quit.main ; | ||
| - | |||
| - | : enter.main | ||
| - | row_select @ enttbl.main ; | ||
| - | |||
| - | EXEC.TABLE do.key.main | ||
| - | ' | ||
| - | ' | ||
| - | ASCII F | ||
| - | ASCII f | ||
| - | ASCII S | ||
| - | ASCII s | ||
| - | ASCII Q | ||
| - | ASCII q | ||
| - | CONTROL M | enter.main | ||
| - | | ||
| - | |||
| - | : main ( -- ) | ||
| - | main.menu.display | ||
| - | BEGIN | ||
| - | KEY do.key.main | ||
| - | AGAIN ; | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | comment: | ||
| - | 8-6 EXERCISES | ||
| - | |||
| - | | ||
| - | words for specific bases. | ||
| - | |||
| - | 16 BASED. HEX. | ||
| - | |||
| - | would define HEX. to be a word which prints the top of the stack | ||
| - | in hex but does not permanently change BASE. That is, typing | ||
| - | |||
| - | DECIMAL | ||
| - | 17 DUP HEX. . | ||
| - | |||
| - | would print out | ||
| - | |||
| - | 11 17 ok | ||
| - | |||
| - | |||
| - | | ||
| - | that will print the following messages in response to the | ||
| - | indicated key pressings: | ||
| - | |||
| - | Key pressed | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | | ||
| - | |||
| - | |||
| - | Pressing any other key should produce a beep (CONTROL G EMIT). | ||
| - | |||
| - | comment; | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | </ | ||
papierkorb/4th_lesson_8.1755364236.txt.gz · Zuletzt geändert: 2025-08-16 19:10 von mka