ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» º Lesson 7 Part 050 F-PC 3.5 Tutorial by Jack Brown º ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Some Sound Problems. ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· º Problem 7.1 º ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ Create the SOUND vocabulary and add the SOUND words from Lesson 7 Part 4. Once you have SCALE working make an new word to play a simple tune! ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· º Problem 7.2 º ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ Write some Forth words to generate " sound effects". Make sure that you place them in the SOUND vocabulary. Try: : TEST S.ON 255 0 DO I TONE 1 TENTHS LOOP S.OFF ; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Vectored Execution ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \ Vectored execution reference: Brodie Ch 9 p 215 EXECUTE ( cfa -- ) Execute the word whose cfa is on stack. To get cfa, code field address, of a word we use ' : F.HELLO ( -- ) ." Hello, I speak FORTH " ; : B.HELLO ( -- ) ." Hello, I speak BASIC " ; : P.HELLO ( -- ) ." Hello, I speak PASCAL" ; VARIABLE INTRO : GREETING ( -- ) INTRO @ EXECUTE ; ' F.HELLO EXECUTE I speak FORTH ok ' F.HELLO INTRO ! ok GREETING I speak FORTH ok ' P.HELLO INTRO ! ok GREETING I speak PASCAL ok ' B.HELLO INTRO ! ok GREETING I speak BASIC ok The VARIABLE INTRO is called a vector. And the process of changing the cfa that is stored in INTRO is called revectoring. The concept of using variable to store a cfa and later fetching and executing it is called "Vectored Execution" PERFORM ( adr -- ) Equivalent to @ EXECUTE and will execute slightly faster. \ Try the above examples with GREETING1 below. : GREETING1 INTRO PERFORM ; The word IS is a state smart word that can be used to set the pfa of DEFERed words, CONSTANTs, or VARIABLEs. IS {word} ( adr -- ) Store adr in pfa of {word} Sample usage: ' F.HELLO IS INTRO etc , Repeat the above examples using IS In order to prevent unnecessary delays, F-PC has a special type of variable called a DEFERed word. A DEFERed word is like a variable in that it has a pfa that will hold one word, however this word is always the cfa of another word and when a DEFERed word executes it will automatically fetch the cfa stored in its pfa and execute it! DEFER {word} ( -- ) Like a variable except that it fetches its contents and executes them. Try the following: DEFER GREETING2 ok ' F.HELLO IS GREETING2 ok GREETING2 I speak FORTH ok ' P.HELLO IS GREETING2 ok GREETING2 I speak PASCAL ok ' B.HELLO IS GREETING2 ok GREETING2 I speak BASIC ok ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· º Problem 7.3 º ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ Have you used F-PC's FLOOK yet? Type: HELP FLOOK and then use your new knowledge to find some DEFERed words in F-PC. Give a list of those the Forth 83 standard words that are DEFERed in F-PC. Why do you think these words are DEFERed words? ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Please Move to Lesson 7 Part 060 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ