Home
manual
Contents
1. Stack diagram nl n2 sum 19 old i Contents To output the results one writes Stack diagram n foots se fold The stack is now in the condition that it was in before the calculation 20 ABACUS Software FORTH 64 4 3 Examples We will now illustrate through the use of some short examples how one programs in Forth The first is a kind of a language translator which may be thought of as an English German dictionary We need only the two related words and as well as the definition delimiters required for every word and We define LOVE LIEBE I ICH QUEEN KOENIGIN MARY MARIA Note The space is an important delimiter in Forth At least one space must separate each Forth word from neighboring words a space is required after a quotation mark because it is a Forth word You can now ask for the translation of any learned word If you type QUEEN CR Forth answers with KOENIGIN You can also translate sentences though the translation will often be grammatically wrong I LOVE QUEEN MARY CR The name dictionary used to describe the list of Forth words takes on a literal meaning in this application Next we want to define a word called 2SORT which sorts two numbers according to size The stack diagram looks like this nl n2 min nl n2 max nl n2 At the end of 2SOR
2. Clears the stack b Exactly as LIT only works with a byte instead of a word CLIT executes faster than LIT nl n2 The device n2 addressed over channel nl with OPEN is closed 56 ABACUS Software FORTH 64 CLOSE SCREEN CMOVE COLD COLORAREA COMBINE COMPILE CONSTANT CONTEXT CONTROL COUNT Closes the file SCR see OPEN SCREEN addrl addr2 n Transfers n bytes from address addrl to address addr2 The transfer is done from the lowest address up meaning that the first address is addrl then addrl l and so on The cold start procedure in order to initialize the system COLD can be activated from the terminal in order to erase user programs and reinitialize the system n A variable it contains the start of the color memory for graphics bl b2 n Combines the two bytes bl low and b2 high into one word n Compiles the CFA code field address of the following word into the next free space in the dictionary n Serves to define constants Used in the form n CONSTANT cccc in order to define a word cccc with the value n cece is then equivalent to n addr U User variable Contains the pointer to the vocabulary in which searches for words will start n Returns the CONTROL code of the following character This corresponds to Commodore ASCII code Example CONTROL C places 3 on the stack addrl addr2n Places on the stack the add
3. Outputs an error message if the stack pointer does not agree with the value found in CSP see CSP 52 ABACUS Software FORTH 64 DISC ENOUGH ERROR EXEC LOADING PAIRS STACK TERMINAL ABORT ABS AGAIN Checks the condition of the disk drive and outputs this on the screen Called when the light on the drive flashes no se A check is made to see if at least n values can still be stored on the stack fn Outputs the error message n if the flag f is true Line n from SCR 4 is printed n may also be larger than 15 resulting in lines from the following screens being printed Outputs an error message if the system is not in execute mode Outputs an error message if loading is not currently going on nl n2 Outputs an error message if nl lt gt n2 This instruction checks to see if two structured language elements belong together or not Outputs an error message if a stack overflow occurs l f A test is made to see if the RUN STOP key is being pressed A false flag indicates that this is not the case addr n The contents of address addr are placed on the stack Initializes the two stacks and sets the execute mode The computer uses standard input and output and outputs the start up message n u The absolute value of n is generated Used in a definition in the form BEGIN sins AGAIN Jumps back to the corresponding BEGIN The stack rema
4. nl nl if nl lt gt 0 nl is duplicated if it is not zero The usual application is a DUP right before an IF so that no DROP instruction is necessary in the ELSE part nl n2 n3 n3 nl n2 Rotates the top three stack elements in the direction opposite that in which ROT works 49 ABACUS Software FIND TRAILING LINE MOD 012 3 0 lt FORTH 64 pfa b tf if found P ff if not found The next string delimited by spaces in the input is transferred to HERE The CONTEXT vocabulary and if not found the CURRENT vocabulary is searched for an identical name header If found the parameter field address the count byte and the true flag are placed on the stack else only the false indicator addr nl addr n2 The number of characters in a text string of length nl is shortened by the number of blanks found at the end Wes Outputs the value n in the current number BASE A space is printed after the output pronounced dot Used in the form cece Compiles the following string up to the delimiter This string is printed at run time line ser The line line of screen scr is printed on the terminal Blanks at the end of the text are suppressed nl a2 Outputs the number nl right justified in a field of length n2 Writes the entire stack contents without destroying them to the output device nl n2 quot quot nl n2 nl n2 rem quot Integer division with
5. Define the volume level 0 15 NOISE 129 The constant 129 is placed on the stack for creation of noise PULSE 65 The constant 65 is placed on the stack for the creation of a tone with a square wave SAWTOOTH 33 The constant 33 is placed on the stack for creation of a tone with a sawtooth wave TRIANGLE 17 The constant 17 is placed on the stack for creation of a tone with a triangle wave 25 ABACUS Software FORTH 64 SID D400 The address of the SID decimal 54272 is placed on the stack The command VOICE is to be given after the volume and waveform have been set 26 ABACUS Software FORTH 64 5 2 A first composition with sound With the words just described you can play a few tones on your C 64 Enter the following commands 15 VOLUME CR maximum volume for the new music 19 3 0 8 ENVELOPE CR these are the settings recommended for piano in the C64 user s guide and finally 1 7493 PULSE 255 1 2000 VOICE CR create the def tone You now hear the famous concert pitch A If you play around a bit with the settings for ENVELOPE and VOICE you will notice a greater or lesser change in the tone after VOICE in contrast to the last tone When you have discovered a combination which you want to keep you should define it as a new word You can recognize through these examples how easy it is to experiment with Forth and how Forth programs can be tested as the individual parts are writ
6. nl n2 n3 n4 n4 nl n2 n3 The 31 bit intermediate result nl n2 is divided by n3 The accuracy is therefore greater than the sequence nl n2 n3 nl n2 n3 n4 n5 n5 is the quotient n4 the remainder of the operation nl n2 n3 A 31 bit intermediate result allows higher accuracy nl n2 sum nl and n2 are added 48 ABACUS Software FORTH 64 BUF LOOP ORIGIN KEY DUP ROT n addr n is added to the value in addr The result is stored in addr pronounced plus store nl n2 n3 n3 SGN n2 ABS n1 addrl addr2 f Advances the disk buffer address addrl to the address of the next buffer addr2 The flag f has the value false if addr2 is the buffer which the variable PREV references nl Used in a definition in the form DO EP nl LOOP The loop counter is incremented or decremented by nl as appropriate The loop is left when the loop counter reaches or exceeds the end value If nl is negative the loop is left when the loop counter reaches or goes under the end value n addr Yields the address ORIGIN n The parameters for the Forth bootstrap begin at ORIGIN i See Saves n in the next word of the dictionary The dictionary pointer is incremented S h U A user variable It should contain the address of the routine KEY nl n2 diff diff nl n2 P Compilation of the input from the disk will be continued on the next page nl al if nl 0 nl
7. NOK re Turns Forth s OK message off NOP A routine which does nothing dummy routine NOTABLE addr Variable which should contain the value 0 Its address is saved in the variable FTABLE if no function keys are assigned NUMBER addr d The string which begins in address addr and whose length is immediately before the text is converted to a double precision word based on the current conversion base The placement of decimal point if any is stored in DPL Otherwise the decimal point has no function An error message will be given in the event of a conversion error OK Turns Forth s OK message on OPEN st n2 n3 A file with filename st is opened on device n2 over channel n3 OPEN SCREEN Opens file SCR containing the screens Usually need not be given by the user because Forth manages this file by itself OR nl n2 or The result is the logical ORing of nl and n2 ORANGE 8 Returns the constant 8 as the color value for orange OUT addr User variable Contains a value which is used and changed by EMIT The user can read or change the value in order to create formatted output OVER nl n2 nl n2 nl The second word on the stack is copied onto the top of the stack PAD addr Returns the address of the text output buffer PAPERCOLOR n A variable containing the color value of the paper for graphics 66 ABACUS Software FORTH 64 PEN PFA PICK PIXELAREA
8. dn Outputs the double word d as a signed number in an n character field d u Returns the absolute value of the double word Sets the I O conversion base to 10 58 ABACUS Software FORTH 64 DELI on A user variable which contains the delimiter used by the FIND and INSERT routines of the editor Normally this is the English pound sign DEPTH b Returns the depth number of elements of the stack DEFINITIONS Used in the form ccce DEFINITIONS Sets the CURRENT vocabulary to the CONTEXT vocabulary With this call the CONTEXT vocabulary is set to ccce DIGIT c nl n2 tf for valid conversion c nl ff for invalid conversion Converts the ASCII character c to its binary value n2 The conversion is supplemented with a flag If the conversion is unsuccessful only the flag is given DLITERAL d d run time P During compilation d is compiled as a literal When the definition is later executed the value is placed on the stack Nothing happens at run time DMINUS dl d2 Reverses the sign of dl DO nl n2 run time Used in a definition in the form DO 4 LOOP DO LOOP At run time the loop limit nl and the loop index n2 are removed from the stack and placed on the return stack After each pass through the loop n2 is incremented by l for LOOP by an arbitrary number for LOOP The limit and index are removed from the return stack when the loop is exited nl and n2 are
9. 15 ABACUS Software FORTH 64 as required If an empty string is entered for example INSERT CR the contents of the insert buffer are not changed and existing contents are then used If no delimiter is found in the text following the command the entire remainder of the input line is inserted Beware of length conflicts B il et The cursor is set back the number characters found in the search buffer DELETE T A search is made for the text following the command and enclosed in English pound signs starting at the current cursor position and deleted if found The text is placed in the search buffer The delimiter is found in the variable DELI and can be changed as required The same applies for empty strings or those not enclosed in delimiters as for FIND FS gt A search is made for the text following the command enclosed in English pound signs and if found this text is replaced by the text enclosed in the English pound signs following the first Both texts are placed in the search and insert buffers respectively The delimiter is once again found in the variable DELI and can be changed if desired The same applies as with DELETE and INSERT for empty strings or strings not enclosed in delimiters Example FS CATE DOGE FIND Like FIND but the text to be found is taken from the search buffer FIND is the actual search routine for FIND and can be used for multiple searches for the same target I
10. FORTH LANGUAGE for the Commodore 64 with Graphics Sound and Assembler A DATA BECKER PRODUCT 520994 Published by Abacus Hit COPYRIGHT NOTICE Abacus Software makes this pockage avoilable for use on a single computer only It is unlawful to copy any portion of this software package onto any medium for any purpose other than bockup It is unlawful to give away or resell copies of any port of this package Any unauthorized distribution of this product deprives the authors of their deserved royuolties For use on multiple computers please contact Abacus Software to make such arrangements WARRANTY Abacus Softwore makes no worranties expressed or implied as to the fitness of this softwore product for any porticulor purpose In no event will Abacus Softwore be liable for consequential damages Abacus Software will replace any copy of the software which is unreadable if returned within 90 doys of purchase Therecfter there will be a nominal charge For replacement First Printing Morch 1985 Printed in U S A Translated by G Dykema Copyright CI1985 Abacus Software Inc P O Box 7211 Grand Rapids MI 49510 Copyright C3Jisse8S DATA BECKER GmbH Merowingerstr 30 4000 Dusseldorf W Germany ISBN 0 916439 32 1 Table of Contents l Introduction Sits Sr Swe wea artes eters Whee Role Sista ENEE CAE Pe seed 2 Forth bensine dese cee 6 oe BME ae erie el one Bb a s eA eee ald a Anite ee 2 1 General ce eee w
11. in the case of Forth 64 can do graphics and make music with which memory dumps and program patches can be made and in which desired extensions can be made by the user which are then immediately resident in the system Forth consists of hundreds of words which all denote a program of their own which is immediately executed when called To be sure Forth is not a language which is very easy to understand since it is quite different from all other high level languages Normally Forth uses only the stack as an interface for parameter passing and performs no special parameter checking In addition Forth uses what is called Reverse Polish Notation or RPN for arithmetic RPN can take a while to get used to ABACUS Software FORTH 64 This page left blank intentionally ABACUS Software FORTH 64 2 Forth 64 2 1 General Forth 64 is based on the FIG FORTH standard of the Forth Interest Group FIG of San Carlos California Naturally current versions of Forth offer many more words just as this version offers some three times as many words in its basic vocabulary as does the standard In addition all of vocabulary of the second Forth standard Forth 79 has been included in this Forth Furthermore some words in the most recent generation of Forth Forth 83 have been included in Forth 64 Unfortunately some words in Forth 83 have different programs connected with them in contrast to earlier Forths and some words have been renamed Whe
12. A T wlece 29 6 2 Hi res with example ee See ele RG ee 2304 330 6 3 Descriptions of graphics commands 35 7 The Forth assembler E TEREA ARER EE 37 7 1 General P as aA E N aE n oud NE a e e e Taa TGAN SE E i 7 2 The assenbler vocabulary cece cece aeaa o 7 3 A small assembler program uae ste a ean Se eae 41 8 Miscellaneous eee0ee PE E E E Bien sola ET E 43 Appendix l Memory map ssesssssossssceroesepasssesee e s 44 Appendix 2 The entire Forth vocabulary Mea a 45 ABACUS Software FORTH 64 l Introduction Forth should be able to do what other programming languages can do only more elegantly This was the claim that Charles H Moore made about the language which he developed Forth As a matter of fact the steadily growing base of Forth enthusiasts seems never to tire of producing examples illustrating how programs can be realized faster and in less space and often more elegantly than in other languages For example compilers are written in Forth and also the famous turtle graphics in Logo have been implemented in Forth quickly and elegantly Forth is particularly well applied to the solution of real time problems since Forth is fast compact and efficient But Forth is not only a programming language but also an operating system With Forth a complete system is available to the user in which one can program assemble and edit with which one
13. PREV PURPLE QUERY QUIT R RO R W bite Sets the text color to b nfa pfa Converts a name field address of a definition to its parameter field address b n Copies the bth element on the stack to the top of the stack Example 1 PICK corresponds to DUP 2 PICK corresponds to OVER etc 1 D A variable which contains the start of the graphics memory addr A variable which contains the address of the disk block buffer last addressed The UPDATE instruction references this buffer 4 Returns the constant 4 as the color value for purple Reads a maximum of 80 characters from the terminal until a carriage return is encountered The text is placed in the field whose address is in TIB IN is set to zero Initializes the return stack ends the compile mode and switches the system back to terminal input sey n Copies the top word of the return stack to the data stack without changing the former R in many versions addr U User variable Used by the editor for the position of the cursor addr U Variable with which the return stack is intialized addr blk f The input output routine for a record Addr is the address of the block buffer to be transferred Blk is the number of the block and f is a flag f 0 for output f l for input 67 ABACUS Software FORTH 64 R gt READ RED REPEAT RND RNDNR ROLL ROT RP S so se
14. a comma is added after the mnemonic Example JMP INX The structured words BEGIN AGAIN UNTIL IF ELSE and ENDIF are similarly explained Their meanings are the same as those for the corresponding Forth vocabulary This leaves the Forth specific address modifiers as well as some global assembler labels IP Address of the I nterpretive P ointer W i Address of the code field pointer N Address of an 8 byte scratch area R Pointer to the return stack XSAVE 4 Address of the save register for X UP Address of an 8 byte area for the user parameters A Denotes the accumulator addressing mode Immediate addressing Indirect addressing xX Y 7 Indexed addressing x Y Indirect indexed addressing BOT Address of the low byte of a 16 bit quantity in X mode The X register points to the current data stack in the zero page BOT l Address of the high byte of a 16 bit quantity in X mode The X register points to the current data stack in the zero page SEC Address of the low byte of the second quantity on the data stack SEC 1 Address of the high byte of the second quantity on the data stack 39 ABACUS Software PUT PUSH SETUP BINARY POP POPTWO PUSHOA NEXT FORTH 64 Address of a routine which replaces the high byte of the data stack with the contents of the accumulator and the low byte with the top byte on the machine stack used by NEXT Like PUT but the w
15. given at run time The I instruction within a loop places the current value of the index on the stack see I LOOP LOOP LEAVE DOES gt Defines the run time behavior of a word defined through lt BUILDS yee DOES gt DONE Closes the editing session writes all edited screens and takes care of the default assignment of the function keys 9 ABACUS Software FORTH 64 DOS DP DPL DROP DUMP DUP EDIT ELOAD ELSE EMIT st Sends a disk command to device number 8 Example N DISKETTE O1 DOS The diskette in device 8 will be formatted careful addr U User variable Contains the address of the pointer which points to the next free space in the dictionary The value can be read with HERE and can be changed with ALLOT U User variable Contains the number of digits to the right of the decimal point in a double precision number It is also used to define the decimal point for formatted output The default for single precision numbers is l m 222 n is removed from the stack addrl addr2 Dumps the memory range from addrl to addr2 n nn Duplicates the top stack value Displays the screen last edited the number is in SCR n Displays screen n for editing n is placed into SCR The edit mode is enabled and the function keys are reassigned The page last edited number in SCR is loaded Used in a definition in the form IF ELSE ENDIF c Ou
16. in the screen being edited are made invalid in the disk buffer The last saved condition can be redisplayed for editing with the E command 13 ABACUS Software FORTH 64 3 4 2 Line commands Commands which manipulate one or more entire lines P Places the following text in the ith line of the current screen The internal cursor position is connected in series to the next page important for searching S i n Spreads the current screen at the ith line by n lines The lines behind n are lost R i Replaces the current line and the lines following with the contents of PAD PAD can be filled by the commands H or XH I in Inserts the contents of PAD at the ith line The last lines of the screen are lost H in Copies n lines at line i of the current screen to PAD K i is Erases n lines at line i on the current screen D i n Deletes n lines at line i on the current screen Lines are placed in PAD XH s in External Hold Copies n lines at line i of Screen s to PAD This allows you to use sections of other screens in the screen currently being edited without having to select the screen from which the extraction is made 14 ABACUS Software FORTH 64 3 4 3 Character commands The following commands operate on individual characters or on the internal cursor position R Search and delete commands operate at the cursor position saved in R The search and insert buffers are not initial
17. key assignments This produces an assignment of ASCII codes to Forth words Any word can be assigned to any key as desired with the limitation that the assigned word not require any values from the stack Perhaps you would like to make a small change in your system Let us assume that you do not like the color combination on the screen Simply enter the following sentence BLUE BORDER CYAN SCREEN BROWN PEN CR and everything looks much nicer right Forget BASIC forget POKEing values into addresses that no human can remember w ABACUS Software FORTH 64 In Forth 64 the color codes 0 to 9 are assigned to constants words Write BLACK when you mean BLACK instead of 0 You can even define a new word for your favorite color combination FCN BLACK BORDER RED SCREEN WHITE PEN CR ABACUS Software FORTH 64 2 3 Input from the terminal In Forth it was planned from the beginning to have the input operate in the KEY mode meaning that each character is accepted and processed as soon as it is typed This burdens Forth with a wholly unnecessary task which the operating system performs all by itself when the appropriate routine is called Forth 64 does not process input in the key mode The input of characters is done in the same way it is done in BASIC meaning that Forth does not see the line until you send it an edited line with CR A small modification to this input function has been made however with the result of greate
18. n Places the top word of the return stack on the data stack addr count nl n2 f count bytes are read from device n2 over channel nl at address addr error flag 0 OK 2 Returns the constant 2 as color value for red P C2 Used in a definition in the form BEGIN WHILE eee REPEAT At run time this results in an unconditional jump to the corresponding BEGIN nl n2 Returns a random number in the range 0 to nl l n A variable used for random number generation with RND bo lt lt lt Rotates the top b stack elements one position down and puts the former bth element on top ROLL is a generalization of ROT which is equivalent to 3 ROLL nl n2 n3 n2 n3 nl Rotates the three top words on the stack Initializes the return stack pointer bl b2 b3 Writes the ASCII value bl in line b2 column b3 of the text RAM address 1024 ff n d The top stack word is converted to a double precision value with the same sign and magnitude addr U Variable with which the data stack is initialized bl b2 b3 Returns the ASCII value in text RAM at line bl column b2 68 ABACUS Software FORTH 64 SCOPY SCR SCREEN SIGN SMUDGE SP spe SPACE SPACES SPLIT SREAD STATE nl n2 Copies SCR nl in the disk buffer to SCR n2 on disk The screen to be copied should be completely contained in the disk buffer This word can be used to copy single screens
19. s manual are also included on the disk The programs are useful and can be immediately loaded tried out and changed as desired ABACUS Software FORTH 64 2 2 First time using Forth 64 The Forth distribution diskette contains 3 files GFORTH The loader program FIG FORTH64 The Forth program SCR an included screen file Forth is loaded with LOAD GFORTH 8 1 NOTE Ste COVER PAGE Forth 64 starts itself meaning you don t have to type RUN or some similar command after the program has loaded Forth 64 announces itself with the usual initial message containing the version date of creation and program name The first commands which you can now give are such things as VLIST HELP or S VLIST generates a list of all the words in the current context and Forth vocabularies The context dictionary may be ASSEMBLER EDITOR GRAPHIC SOUND or FORTH itself After loading the context vocabulary is Forth If the command listing produced by VLIST takes too long for you you can interrupt it by pressing the STOP key This is true of the most of the commands which take a while to execute The command S returns the condition of the stack This is hopefully empty immediately after loading Forth When you enter a number such as 3 CR and then take a look at the stack you will see this number there until another Forth word such as CLEAR CR or CR retrieves it Enter the command HELP It shows you the current
20. to another disk in which the disk can be changed by using the instructions CLOSE SCREEN and I DOS to initialize the new diskette addr U User variable Contains the current screen number b oo Sets the background color to color b nd d Places an ASCII in the text of a numerical output conversion if n is negative N is removed from the stack May only be used between lt and gt Used in a definition in order to complement logical not the smudge bit in the name field This prevents an incomplete definition from being found before error free compilation addr Initializes the data stack pointer addr The stack pointer is placed on the stack For example the command sequence 12sPpe produces the output 2 2 1 OK Outputs an ASCII blank to the output device n Outputs n blanks to the output device n bl b2 Splits n into low bl and high bytes i s Reads screen n into the disk buffer addr U User variable Contains a flag which indicates whether the program is in the compile or run state 69 ABACUS Software FORTH 64 SWAP TEXT THEN TIB TOGGLE TO NKEY TRACEON TRACEOFF TRAVERSE TRIAD TYPE U nl n2 n2 nl Exchanges the two top words of the stack b a se Reads the text up to the next delimiter b an entire line if necessary into PAD P Synonym for ENDIF addr U User variable Contains the address of the Terminal
21. 4 6 2 Hi res Better quality pictures can be created in the hi res mode The words which you need to do this are found in the GRAPHIC vocabulary which is described in its entirety in the next section Enter the word GRAPHIC CR before you enter any graphics commands or Forth will not understand the following commands You can see what the high resolution screen looks like before you have drawn something on it by entering the command amp HI RES or simply by pressing the F3 key The picture which you see consists of many small multi colored squares Clear the screen with the command amp CLEAR You must enter this command blindly if you have not switched back to the text mode F4 meaning that the letters which you type will not appear on the screen Your input will be accepted and processed nevertheless The screen and writing colors can also be set in the hi res mode independent of the text screen with the graphics words amp PAPER and amp INK Enter GRAPHIC YELLOW amp PAPER BLACK amp INK amp CLEAR CR If you take a look at the graphics screen with F3 you will see that it looks much nicer than before If you want to put a very small point in the extreme lower left corner enter the following instruction 100 amp S CR If Forth communicates its lack of understanding with the message amp S 2 tell it that the word amp S is in the GRAPHIC vocabulary command GRAPHIC CR otherwise Forth will look in the SOUND vo
22. 4 P CRIGHT 1 0 RMOVE 5 P CLEFT 1 0 RMOVE 6 P CUP 0 1 RMOVE 7 P CDOWN 0 1 RMOVE 8 P 9 P gt 10 P 11 P CHECK FOR DIAGONAL 12 P MOVEMENT DEFINED 13 P UPRIGHT l1 1 RMOVE 14 P 15 P SCR 28 0 P PAINT PICTURE 4 CHG PS TOGGLEPIX 1 P FORTH DEFINITIONS DECIMAL 2 P 3 P PEN STATUS CHANGES 4 P CHG PS 5 P PS 6 P 7 P PS 8P 9 P PIXEL ERASE SET 10 P TOGGLEPIX 11 P GRAPHIC X0 Y0 12 P 2DUP amp S 13 P 0 ROT amp S 14 P 15 P gt SCR 29 0 P PAINT PICTURE 4 PEN UP 1 P FORTH DEFINITIONS DECIMAL 2P 3 P PEN RAISED UP 4 P PEN UP 5 P 1 PS 6 P 7 P 8 P 9 P 10 P 11 P 12 P 13 P 14 P 15 P 32 ABACUS Software FORTH 64 When you have compiled these screens 25 LOAD compiles all of them up to screen 29 or to screen 31 if you compile the programs on the distribution disk you can paint your first pictures by command For example set the starting position of your picture in the middle of the graphics screen with 160 X0 100 Y0 CR and then use CRIGHT to move to a position to the right CUP to move up etc A new point will be set or erased at the new location depending on the value of the variable PS If PS has the value 0 it works like an eraser and if PS is 1 like a writing pen and if PS 1 nothing happens the pen is off the paper Drawing with these relatively long words is naturally somewhat tiresome We will now draw wit
23. CK BLUE BMOVE BORDER BROWN BSAVE BUFFER addr User variable Contains the number of the block which is currently being compiled Zero indicates input from the terminal vaddr st n2 n3 Binary load of a file from disk vaddr is the start address at which the file is to be loaded st denotes the filename n2 and n3 indicate the channel 0 or 1 and the device number 8 of the file to be loaded Note When using channel 1 the file is placed at the original address The value of vaddr is then irrelevant but may not be omitted n addr Places on the stack the memory address addr of the block buffer which contains block n If block n is not currently in memory it will be written to the oldest buffer If the contents of this buffer are marked for UPDATE its contents are first written to disk see BUFFER R W UPDATE FLUSH 6 Returns the constant 6 as the color value for blue addr Moves a string from PAD to addr b Sets the color of the screen border to color b 9 Returns the constant 9 for the color value of brown addrl addr2 st n2 n3 Binary save of a file to disk addrl and addr2 indicate the range from to which is to be written to the file st denotes the filename n2 and n3 denote the channel 0 or 1 and device number 8 of the file to be saved n addr Finds the next disk block buffer and assigns it to block n If the current contents of
24. EPEAT During run time WHILE manages the course of the program If f is false execution continues after the REPEAT otherwise the loop is executed again 1 A color constant with the value 1 addr U User variable Contains the value 31 for the maximum length of a Forth word o vee Reads the next string from input up to delimiter c The string is placed at address HERE in the form first byte number of characters in string second byte the string following two blanks The leading character c is ignored addr nl n2 n3 f nl bytes at address addr are sent over channel n2 to device n3 f 0 indicates OK nl n2 xor Exclusive OR of nl and n2 a i A color constant with the value 7 P Used in a definition in the form xxx words words The instructions following are executed instead of being compiled The instruction allows calculations or the handling of special cases before compilation continues with the J instruction see LITERAL P Used in a definition in the form example xxx COMPILE FORTH COMPILE forces compilation of an immediate definition which would otherwise be executed In this example the vocabulary FORTH is called during the execution of the instruction instead of during the compilation The compilation suspended by a instruction is continued see 73 Required Reading for your ORTHE MMODORE THE GRAPHICS BOOK FOR
25. H 64 GREEN HELP HERE HEX HLD HOLD ID IF IMMEDIATE IN Sao eb Constant for the color value of green Returns the function key assignments addr The next free address in the dictionary is placed on the stack Sets the conversion base to 16 hexadecimal addr User variable which contains the last character of a string of numerical output conversion ewes Used between lt and gt Transfers the ASCII character to the string for numerical output conversion fn Used inside a DO LOOP in order to place the loop index on the stack addr Outputs the name of the word with NFA addr f run time Used in a definition in the form IF tf ENDIF IF tf eee ELSE ff eee ENDIF If f is true the commands immediately behind IF are executed if f is false a jump is made to ELSE if present or ENDIF Marks the last defined word as immediate This means that the word will be executed during compilation instead of being compiled The user can force the compilation of an immediate definition through a preceding COMPILE instruction addr User variable Contains the byte offset in the current input text buffer from which the next text will be fetched The instruction WORDS uses and changes the contents of IN 63 ABACUS Software FORTH 64 INDEX INKCOLOR INTERPRET LATEST LEAVE LFA LIMIT LIST LIT LITERAL nl n2 Re
26. H 64 LOAD LOOP M M M MOD MAX MESSAGE MIN MINUS MOD NFA NKEY i s Loads interprets screen n The loading can be stopped with the S instruction addr n P Used in a definition in the form DO LOOP and marks the end of a loop The loop counter is incremented by 1 and compared with the loop limit n The loop is left when the loop counter has reached the upper limit n nl n2 d The result d of nl n2 is a double precision word dnl n2 n3 n2 is the remainder n3 the quotient of the division d nl The remainder n2 has the sign of the dividend udl u2 u3 ud4 A mixed precision operation The dividend udl and the quotient are double precision words The divisor u2 and remainder u3 are 16 bit words nl n2 max The result is the maximum of nl and n2 D Text line n relative to screen 4 is printed on the output device The line may lie outside of screen 4 If WARNING has the value 0 only the value will be printed nl n2 min The result is the minimum of nl and n2 nl n2 Negates nl nl n2 n3 n3 nl modulo n2 n3 has the same sign as nl pfa nfa Converts the parameter field address of a definition to its name field address n An alternative KEY function which reads the function table and then returns only the ASCII value on the stack if the key pressed is not contained in the function table 65 ABACUS Software FORTH 64
27. IC BGO D015 A constant which returns the address of the VIC register which contains the normal background color VIDEOAREA n A variable which contains the address of the video area HEX 400 VOC LINK addr U User variable Contains the address of the vocabulary last used All vocabularies are chained though these fields A FORGET can therefore have effect on multiple vocabularies VOCABULARY E L A definition word Used in the form VOCABULARY cccc IMMEDIATE in order to define a new vocabulary cccc A later call of ccce makes it the CONTEXT vocabulary the first vocabulary searched for an INTERPRET instruction The instruction sequence cccce DEFINITIONS makes cccc the CURRENT vocabulary in which new definitions will be placed Vocabulary names are by convention declared as immediate VLIST Outputs all of the defined names in the dictionary starting with the CONTEXT vocabulary WARNING addr U User variable Contains a value for controlling the system messages where l error messages are output from disk screen 4 0 only error numbers are output 1 ABORT is executed WHERE amS WHERE is automatically initialized when an error occurs while loading screens The corresponding screen is automatically displayed for editing 72 ABACUS Software FORTH 64 WHILE WHITE WIDTH WORD WRITE XOR YELLOW COMPILE f Used in a definition in the form BEGIN WHILE tp R
28. Input Buffer addr b The set bits of byte b are complemented in the location at addr b m Saves the address of the key assignment table b in FTABLE and activates the alternative KEY function NKEY Turns on a very comprehensive trace function Note All following commands including TRACEOFF must be entered character by character only and must be concluded with CR Switches the trace mode off addrl n addr2 This instruction traverses a name field from one end to the other Addrl is either the address of the length byte of a name field or the address of the last character of the name If n l the transversal is done in ascending order of addresses whereas if n l a descending transversal is performed i oe Lists screen n n l and n 2 on the output device This output is well suited for documentation and contains the output of line 15 screen 4 as standard comment line addr count Outputs count characters at addr on the output device ul u2 ud Absolute calculation Result is the double precision product ul u2 70 ABACUS Software FORTH 64 U U lt UNTIL UPDATE USE USER VARIABLE vIc VICCRI1 ud ul u2 u3 Absolute calculation U2 is the remainder u3 the quotient of the division ud ul The dividend ud is double precision ul u2 f Sets the flag true if the absolute number ul is smaller than the absolute value of u2 otherwise false Outp
29. NSERT Like INSERT but the text in the insert buffer is inserted What was said about FIND applies here too FS Like FS but the strings are taken from the search and insert buffers DELETE Like DELETE but the text is taken from the search buffer ABACUS Software FORTH 64 3 4 4 Ending the editing DONE Switches to the Forth vocabulary The editing mode is exited First however lines which were not already saved are written to disk The OK message is reactivated and the editor function keys are deactivated 17 ABACUS Software FORTH 64 3 5 Editor function keys The function keys have special assignments in the Forth editor The assignments can be viewed through the HELP command CHR x Key Assignments 94 qt AE redisplays current screen 131 SHIFT RUN ELOAD loads the last edited screen 133 Fl EDIT edit next screen 137 F2 EDIT edit previous screen 134 F3 DELETE delete current search target 138 F4 WIPE erase current screen 135 F5 INSERT inserts the current INSERT buffer 139 F6 FIND searches for current target 136 F7 SSAVE saves edited screen 140 F8 DONE ends editing The function FS can be repeated as often desired by using F3 and F5 The search and insert buffers are also not cleared when screens are changed so that a substitution using function keys Fl F3 F5 and when done F7 can be performed for example 3 6 Notes If you want to edit but Forth does not accept th
30. PSEs pattern FILLing freehand DRAW COPY sections of screen ZOOM in and do detaii work Hard copy in two sizes to popular dot matrix printers ISBN 0 916439 18 5 49 95 CREATE SPREADSHEETS amp GRAPHS POWER PLAN 64 Coordinate C 1 not only a powerful a spreadsheet packages Seies available but with buit in Distributors graphics too The 275 Retailers page manual has tutorial section ahd HELP screens are always available Features field protection POWER PLAM AA Expenses 9 Materrals text formatting windowing Dace row and column copy 1 Shipping Advertising Paroli sort duplicate and delete ISBN 0 916439 22 4 49 95 FREE PEEKS amp POKES POSTER WITH SOFTWARE For name amp address of your nearest dealer call 616 241 5510 CHART YOUR OWN STOCKS TAS 64 oe Kiger in sophisticated technical ant i hy NS Hoy analysis charting ie yl ea Package for the serious ee aa stock market investor Capture data from za ane AI EI PZ78y7 DJN RS or Warner ser AAN na S vices or enter and edit data at keyboard 7 mov ing averages 3 oscillators trading bands least squares 5 vol ume indicators relative charts much more Hardcopy in two sizes most printers ISBN 0 916439 24 0 84 95 wet ier S zr Ssv DO YOUR OWN WORD PROCESSING TEXTOMAT 64 flexible worprocessing package supporting 40 or 80 columns with horizon tal scrolling Commands are clearly displayed on t
31. SET A routine which outputs screens first to the screen and then to the printer looks like this SCR 41 0 P PRINT ROUTINE PRINT ANALOG TO LIST 1 P FORTH DEFINITIONS DECIMAL 2 P PRINT SCR 3 P RESET 4 P DUP LIST FIRST TO SCREEN 5 P CMD LIST THEN PRINTER 6 P RESET 7 P 8 P s 9 P 10 P 11 P 12 P 13 P 14 P 15 P When you have loaded the word PRINT you can print the above FORTH screen with the command 41 PRINT CR 41 ABACUS Software FORTH 64 This page left blank itentionally 42 ABACUS Software 8 Miscellaneous A few suggestions when programming Forth Use short words Use the words CSP and CSP Check at the beginning of each word to see if enough space is left on the stack for the word to function properly word ENOUGH Most system crashes result from stack overflow or underflow Execute the BOOT parameters once you have tested your new words and want to keep them If your system should crash later then you can recover the complete system with RUN STOP RESTORE and a bit of luck The BOOT parameter can be set as follows HERE FENCE HERE 28 ORIGIN FENCE HERE 30 ORIGIN OP LATEST 12 ORIGIN TOP NFA If you have established a new vocabulary you must actualize it with the appropriate reference vocabulary name 6 32 ORIGIN The error message NO CHANNEL from the disk drive can be removed with the command CLOSE SCREEN If
32. T the larger of the two values will be at the top of the stack The word definition for this is 2SORT STACK nl n2 2DUP nl n2 nl n2 gt nl n2 f IF nl n2 SWAP n2 nl ENDIF nl n2 or n2 nl The two values nl and n2 must be duplicated once in the program because the comparison operator gt removes two values from the stack and leaves an indicator true 1 or false 0 depending on whether nl gt n2 or not The word IF removes the indicator from the stack The branch between IF and ENDIF is only executed if the indicator was true 21 ABACUS Software FORTH 64 This branch exchanges the top two values on the stack We will use this word in our next definition calculation of the greatest common denominator GCD of two numbers The Euclidean algorithm for determining the GCD of two positive integers is similar to the following subtract the smaller of the two numbers let us say n2 from the larger nl until the result n3 of the subtraction is less than n2 subtract the result n3 from n2 until the new result n4 is less than n3 and so on end the procedure when the difference is 0 The number last subtracted is the GCD The stack diagram for the word GCD nl n2 ged The word definition GCD nl n2 BEGIN The loop will be repeated until no remainder occurs from the division ZSORT we make sure of the right ordering OVER stack n2 nl n2 small large small MOD stack n2 n3 DUP w
33. THE COMMODORE TRICKS amp TIPS FOR YOUR C 64 treasure chest af easy to use programming techni ques Advanced graphics easy data input enhanced BASIC CP M character sets transferring data bet ween computers more ISBN 0 916439 03 8 GRAPHICS BOOK FOR C 64 trom fundamentals to advanced topics this is most cam plate reference available Sprite animation Hires Multicolor lightpen IRQ 30 graphics projections Dozens of samples SBN4 0 916439 05 4 350 pages 19 95 SCIENCE amp ENGINEERING ON THE C 64 starts by discussing variable types computational accuracy sort algorithms more Topics from chemistry physics biology astronomy electronics Many programs ISBN 0 916439 09 7 250 pagas 19 95 275 pagas 19 95 CO ON YOUR COMMODORE ANATOMY OF 1541 DISK DRIVE bestselling handbook available on using the floppy disk Clearly explains disk files with many examples and utilities Includes complete commented 1541 ROM listings ISBN 0 916439 01 1 320 pages 19 95 ANATOMY OF COMMODORE 64 insider s guide to the 64 internals Describes graphics sound synthesis 1 0 kernal routines more Includes complete commented ROM listings Fourth printing ISBN 0 916439 003 19 95 IDEAS FOR USE ON YOUR C 64 Wonder what to do with your 64 Dozens of useful ideas including complete listings for auto expenses electronic calculator store window advertising recipe file more ISBN 0 916439 07 0 300 pa
34. any possibilities not explained in the example here from the description of the EDITOR vocabulary in section 3 4 Description of the editor commands ABACUS Software FORTH 64 3 2 Simple editing We enter the following command to edit screen 4 4 EDIT CR Screen 4 with the corresponding error messages will be displayed SCR 4 0 P ERROR MESSAGES 1 P EMPTY STACK 2 P DICTIONARY FULL 3 P HAS INCORRECT ADDRESS MODE 4 P ISN T UNIQUE 5 P 6 P DISC RANGE 7 P FULL STACK 8 P DISC ERROR 9 P 10 P li P 12 P 13 P 14 P 15 P MASTER DISKETTE FORTH64 The line numbers are set from O to 15 and are not as in they are in BASIC freely chosen The P behind the line number means PUT or PLACE and has the function that the text behind it separated by a space will be written on the corresponding line You may have noticed that the usual OK message is not printed This makes sense because you can now position the cursor at the spot to be changed and make the appropriate changes By sending the P command with CR the start of the next line is not destroyed You can then continue to edit as usual If you do not want to move the cursor you can also write your lines directly without using the pattern If you have screens which contain more than 7 lines with over 35 characters the top lines will scroll away and you must edit the first lines in this manner At this point you should be strongly advised to alternat
35. aracter b n st st Yields the first n characters of the string st in PAD st b Returns current length of a string nl n2 st st Returns the characters nl to n2 of the string st in PAD st n Returns the maximum character length of the string variable st 46 ABACUS Software FORTH 64 RIGHT STR VAL VARIABLE LOOP ABORT DO n st st Returns all characters from the nth character on of the string st in PAD d st Converts d to a string placed in PAD st d Converts a string to an integer d b on Definition word used in the form b VARIABLE cccc A string variable with the maximum length b is defined Calling cccec places the address and length of the current string on the stack pfa P Used in the form pnnn The address of the parameter field of the word nnnn is placed on the stack The address is compiled as a literal in a definition Used in the form ccecce for writing comments which are closed on the same line with A space must follow the The run time procedure which outputs the following inline text on the output device Called by pn The run time procedure through which LOOP is compiled increments the loop counter by n and checks the exit condition see LOOP Called after an error if WARNING contains the value l The run time procedure compiled by the DO instruction transfers th
36. ator numerator nl d2 n2 d1 REDUCE n d divisor num reduced denom reduced The addition of fractions can then be formulated as follows 23 ABACUS Software ADDFRAC 3 PICK OVER gt R NUMERATOR R gt 2DUP GCD REDUCE FORTH 64 nl dl n2 d2 dl nl dl n2 dl d2 nl dl n2 d2 denominator nl dl n2 d2 denom saved on return stack numerator numerator denominator num denom num denom numerator denominator gcd num reduced denom reduced 24 ABACUS Software FORTH 64 5 Music with the sound vocabulary 5 1 Description of the sound commands Forth 64 contains a small vocabulary with which music or at least tones can be created The vocabulary is called SOUND and contains the following words VOICE VOLUME ENVELOPE NOISE PULSE SAWTOOTH TRIANGLE and SID Before you can call one of these words enter the command SOUND you must first ENVELOPE nl n2 n3 n4 n5 Definition of the waveform of the nlth voice nl voice 1l 3 n2 attack 1 15 n3 decay 1 15 n4 sustain 1 15 n5 release 1 15 VOICE nl n2 n3 n4 n5 n6 Creation of a tone in the nlth voice nl voice Iza 3 n2 frequency 0 685535 n3 wave type 17 33 65 129 n4 key relationship low 0 255 n5 key relationship high 0 15 The key relationship is relevant only for wave type 65 PULSE n6 duration 32768 32767 Duration of the created tone A dummy delay loop will be executed once per entity VOLUME n
37. c and Sound commands to your programs with this super avelopment package You can distribute tree RUN ISBN 9 916439 26 7 59 95 BASIC COMPILER 64 compiles the complete BASIC language into either fast 6510 machine language and or compact speedcode Get your programs into high gear and protect them by compiling ISONM 0 916439 17 8 39 95 MASTER 64 professional development package for serous applications Indexed file system full screen management programmer s aid BASIC extensions 100 commands ISBN 9 916439 21 6 39 95 PASCAL 64 tul Pascal with extensions tor graphics sprites file management more Compiles to 6510 machine code and can link to Assembler Monitor routines ISBN 0 916439 10 0 39 95 ADA TRAINING COURSE teaches you the language of the future Comprehensive subse of the language editor syntax checker compiler assembler disassembler 120 page guide ISBN 0 916439 15 1 59 95 FORTH 64 loaded with hires graphics com plete synthesizer control full screen editor pro gramming tools assembler ISBN 0 916439 32 1 39 95 C LANGUAGE COMPILER a tii c language compiler Conforms to the Kernighan amp Ritchie standard but without bit fields Package in cludes editor compiler and linker SBN 0 916439 28 3 79 95 ASSEMBLER MONITOR 64 a Macro assembler and extended monitor package Assembler supports floating point constants Monitor supports bank switching quick trace single ste
38. cabulary for the graphics words Note that in high resolution mode the origin 0 0 is the in the lower left hand corner and the coordinates in the x direction go up to 319 and up to 199 in the y direction Another graphics word which you will probably use quite often is amp LINE It draws or erases a line between two given points depending on whether or not the first parameter is zero if zero the line is erased Example amp HI RES 1 10 10 50 50 amp LINE CR You can save your current graphics screen to disk with the command amp SAVE or load it in with amp LOAD for example IST PICTURE 8 amp SAVE CR 30 w ABACUS Software FORTH 64 You can learn how to paint with the cursor and function keys in the following program SCR 25 0 P PAINT PICTURE 1 PS AMOVE 1 P FORTH DEFINITIONS DECIMAL 2 P 3 P 1 VARIABLE PS PEN STATUS 1 0 1 4 P PEN ABSOLUTE MOVEMENT 5 P COORDINATES X0 YO 6 P AMOVE 7 P GRAPHIC PS 8 P 0 lt O IF 9 P PS 10 P x0 11 P Y0 e 12 P amp S 13 P ENDIF 14 P gt 15 P SCR 26 0 P PAINT PICTURE 3 RMOVE 1 P FORTH DEFINITONS DECIMAL 2 P PEN AT DX DY MOVE 3 P RMOVE DX DY 4 P GRAPHIC 5 P 2 ENOUGH 6 P YO X0 7 P AMOVE SP 9 P gt 10 P 11 P 12 P 13 P 14 P 15 P 31 ABACUS Software FORTH 64 SCR 27 0 P PAINT PICTURE 3 CURSER MOVEMENTS P FORTH DEFINITIONS DECIMAL 2 P 3 P
39. d in order to stop the compilation of a screen at any location nli n2 f Sets the flag to true if nl lt n2 else false 1 ABACUS Software FORTH 64 lt lt BUILDS lt SHIFT gt CMOVE gt R gt SHIFT COMP CSP dl d2 Starting instruction of formatted numerical output lt S SIGN gt The double word on the stack is converted the created text placed in PAD c Used in a definition in the form cece lt BUILDS DOES gt eek When cccc is called a new high level word will be defined The call in the form ccecce nnnn causes the instructions behind lt BUILDS to be executed A new word with the name nnnn will be defined Run time procedures can be written in high level code with the lt BUILDS DOES gt construction nb Shifts the word n left by b bits Can be used for a fast multiplication by 2 nl n2 f Sets the flag true if nl n2 otherwise false nl n2 f Sets the flag true if nl gt n2 otherwise false nl n2 n3 Moves n3 bytes at address nl forward to address n2 Ranges may overlap in contrast to CMOVE no The top element on the data stack TOS is fetched and transferred to the return stack An R gt instruction should be present in the same definition nb Shifts the word n right by b bits addr Outputs the value in addr in the current base format free Outputs an error message if the system is not in compile mode
40. discovers an error while loading a screen such as a word it does not recognize you need only enter the word WHERE and the screen in question will be displayed for editing with a marker at the spot where the error occurred jll ABACUS Software FORTH 64 3 3 Overview of the editor buffer 85A1 85F 1 Search Buffer PADF Insert Buffer PADI 8A39 8640 INSERT FIND FIND DELETE BFS A INS FS F FS DEL 8A40 Disk Buffer Holds up to 80 lines e g the current screen 8 amp F80 All buffers up to PAD are used only by the editor and can be used for other purposes They are erased with EMPTY BUFFERS before using the editor 12 ABACUS Software FORTH 64 3 4 Description of editor commands 3 4 1 SCREEN commands The following commands operate on one or more screens EDIT n Selects the nth screen for editing OK is turned off Internal cursor position is set to the start of the Oth line variable R the screen is displayed and the cursor is Positioned on the first line Displayed screens can be edited E Foe The current screen number in SCR is displayed again as with EDIT EDIT s The next screen is displayed for editing EDIT The previous screen is displayed for editing WIPE T The current screen is erased only in the disk buffer After command E a blank screen is displayed SSAVE Eaa The current screen is saved on disk assuming it was changed SCRATCH The changes
41. e duplicate n3 only if n3 gt 0 Case l n3 gt 0 then stack n2 n3 n3 else n2 0 0 Case 1l n2 n3 0 else n2 1 UNTIL Case 1l n2 n3 and back to repeat else n2 The loop will be exited at UNTIL if a 0 is not found there The program is fast about 10 times faster than an equivalent BASIC program and can be used in any application just as any other Forth word 22 ABACUS Software FORTH 64 At the end of this chapter we will introduce a program which adds two fractions and also reduces the result This example will clearly illustrate the possibilities and dangers which Forth offers The stack diagram for the addition program for fractions is nl dl n2 d2 nsum dsum in which n and d stand for numerator and denominator The Forth program FRACTIONADD N1 D1 N2 D2 NSUM DSUM DUP N1 Dl N2 D2 D2 5 ROLL Dl N2 D2 D2 N1 D1 N2 D2 P 3 ROLL D1 D2 P1 AA 4 PICK D1 D2 Pl N2 D1 D1 D2 Pl P2 Dl D2 NSUM ROT NSUM N1 N2 NSUM DSUM 2DUP NSUM DSUM NSUM DSUM GCD NSUM DSUM GCD DUP NSUM DSUM GCD GCD ROT NSUM GCD DSUM GCD NSUM GCD REDUCED DENOMINATOR ROT REDUCED DEN NSUM GCD DENOMINATOR NUMERATOR SWAP The program FRACTIONADD works but it is difficult to read and follow Forth programs should not be written this way Programs become more readable if one breaks the problem down into smaller tasks and defines more words such as the following Function Stack diagram NUMERATOR nl dl n2 d2 numer
42. e edit commands entered you have probably exited the editor Enter the command i EDIT CR or E CR 18 ABACUS Software FORTH 64 4 Programming in Forth This Forth user s guide is not designed to teach Forth The user who wants to learn Forth and write more complex Forth programs should get a good tutorial book on Forth Starting Forth by Leo Brodie of FORTH Inc is an excellent book to start learning this unique language In this chapter we will clarify only the main characteristics of Forth We will include small example programs which in contrast to the programs in the following chapters are not contained on the program disk 4 1 General The Forth language consists of words as does any other language Each of these words corresponds so to speak to a command which has something to do with the program All of the words belonging to the basic Forth vocabulary are described in the appendix to this guide There are hundreds of them for the user to become acquainted with Some like HELP or VLIST have been described in the previous chapters Most of the words must have yet to be explained Just as you can t tell anyone Write without telling him what to write it is just as senseless to give Forth the corresponding command CR without telling it what should be displayed on the screen The instruction 5 CR on the other hand can be processed and Forth outputs the number 5 on the screen It should be noted that i
43. e lines when writing Forth programs with the exception of lines 0 contains screen information and 15 here it doesn t hurt anymore Otherwise Forth programs become very difficult to read and Forth programs which are difficult to read become hard for even the author the understand after a while ABACUS Software FORTH 64 Once you have changed screen 4 according to your tastes save the changes to disk with the command SSAVE FT You can get to the next or previous screen with the commands EDIT Fl and EDIT F2 accordingly When you are done editing enter the command DONE F8 This implicates among others SSAVE and even saves all changes in the disk buffer to disk if you forget SSAVE at the end of editing a screen To see if your changes were accepted take a look at the index of screens 4 and 5 with the INDEX command 4 5 INDEX CR The comment lines of screens 4 and 5 as well as the disk identification line will be displayed on the screen For additional practice you could define your favorite screen color combination on a screen and then load this screen after you have loaded Forth from the distribution diskette Screens can be loaded with the LOAD command For example 10 LOAD CR if your program is in screen 10 If screen 10 was the last screen to be edited or if the value 10 is contained in the variable SCR you need only press the RUN key on the computer This key is assigned the function ELOAD If Forth
44. e loop counter to the return stack see DO 47 ABACUS Software FORTH 64 FIND KEY LINE LOOP NUMBER SETFPA SETFNA MOD addrl addr2 pfa b tf if found addrl addr2 ff if not found The dictionary is searched starting at the name field address addr2 for the string at addrl If the string is found the address of the parameter field the length byte of the name field and the true indicator are all placed on the stack else only the false indicator is left on the stack This word is called by FIND and is normally used only by the system c Run time routine of KEY Returns the code of the next pressed key without waiting for CR nl n2 addr count Returns the length and internal buffer address of line nl on screen n2 a oe The run time procedure compiled by the LOOP instruction increments the loop counter by 1 and checks the exit condition system routine dl addrl d2 addr2 Converts the ASCII text at address addrl 1 to the current base The new value is constructed in dl and placed in d2 addr2 is the new address of the first unconverted character Used by NUMBER system routine chann dev Serves as label for assembler routines in order to set file parameters system routine st Serves as label for assembler routines in order to pass a new filename to the operating system nl n2 prod The result is the product of the top two stack values
45. eee ot evan cereus esaerahcatere ere re eras 2 2 First time using Forth 64 ld Seal Salecase aaeie wcena tere wo 2 3 Input from the terminal ane EA TR TR Mera G 2 4 The screen file SORT ease ceeeeeens aie TER E S totaal 3 Forth editor sastera rae e a bias Sse a ee Se a tee aa 9 3 1 General DIENEN T EE EE cers r EE SEE 9 3 2 Editing illustrated with a simple example 10 3 3 Overview of the editing buffer sssaessssse si 12 3 4 Description of editor commands eee ee EEA I 3 4 1 Screen commands gr es eet ee are aoe E 3 4 2 Line commands AETERNE ETE EELEE 14 3 4 3 Character commands cee rece serve eevee eee e ee l5 3 4 4 Ending the editing is ehh eta vete ena te brace Sheree 17 3 5 Editor function keys Dat ene eea E E Siete LO 3 6 Notes ape lstate Wh ok ayer ene Saas vapid Lelie E 7 18 4 Programming in Forth cece sec er eee e eee e cree eee e eee LG 4 1 General cee eee eee ah tes ise tobe eects Soe e ghey eae 19 452 The stacks erria aria eleven be dale Seite eM oveietee s 20 4 3 Examples saan Shy sig ceh ane Soeseae A te EA ET E s EEE A N 5 Music with the sound vocabulary Ea E sete 20D 5 1 Descriptions of sound commands ee eesercee 25 5 2 A first composition with sound ee en ee eet 6 Graphics with the graphics vocabulary Re re oe er 29 6 1 Lo res with example ater cocenieve fenek Ghee
46. ges 200 pagas 12 95 THE ADWANCED i MACHINE LANGUAGE BOOK FOR THE ADVENTURE GAMEWRITERS DBOOK FOR COMM DORE ot Vaa ty dee SOWA PEEKS amp POKES FOR THE C 64 programming quickies that will simply amaze you This guide s packed full of techniques for the BASIC programmer ISBN 0 916439 13 5 180 pagas 14 9F ADVANCED MACHINE LANquAG a FOR C 64 covers topics such as video con troller timer and real time clock seria and parallel VO extending BASIC commands interrupts Dozens of sample listings 14 95 ISBN 0 916439 06 2 210 pages ADVENTURE GAMEWRITER S HANDBOOK is a step by step guide to designing and writing your own adventure games Includes listing far an automated adventure game cenerator 14 95 ISBN 0 916439 14 3 200 pages Call today for the name of your nearest local dealer Phone 616 241 5510 Other titles are available call or write for a complete free catalog You Can Count On Abacus For postage and handling inciude 4 00 6 00 foreign per order Money order and checks in US doliars only Mastercard VISA and American Express accepted Michigan residents include 4 sales tax CANADA Book Center Montreal Phone 514 332 4154 Software bSL55599054 HHHH P O Box 7211 Grand Rapids MI 49510 Telex 709 101 Phone 616 241 5510 k Pegg ME version without paying royalties one Break the BAS language barrier VIDEO BASIC 64 ADD 50 graphi
47. h the cursor and function keys using the key assignment methods mentioned in chapter 2 To do this we must create a table we call it PTABLE SCR 30 0 P PAINT PICTURE 6 PRETURN PTABLE 1 P FORTH DEFINITIONS DECIMAL 2 P PRETURN SET LO RES AND STANDARD KEY TABLE 3 P GRAPHIC 4 P amp LO RES FFTABLE TO NKEY 5P 6 P O VARIABLE PTABLE 2 ALLOT 7 P 29 CAP CRIGHT ASSIGN CURSOR RIGHT 8 P 157 CAP CLEFT ASSIGN CURSOR LEFT 9 P 145 CAP CUP 10 P 17 CAP CDOWN 11 P 133 CAP CHG PS CHANGE PS IF Fl 12 P 134 CAP PEN UP PEN UP 13 P 135 CAP TOGGLEPIX 14 P 136 CAP PRETURN 15 P Oc gt END ENTERING OF KEY TABLE SCR 31 0 P PAINT PICTURE 7 OF 7 PSTART 1 P FORTH DEFINITIONS DECIMAL 2 P PSTART START PAINT 3 P GRAPHIC 4 P 160 X0 5 P 100 Y0 6 P PTABLE TO NKEY 7 P amp HI RES BP 3s 9 P 10 P 11 P FINISHED 12 P 13 P 14 P 15 P 33 ABACUS Software FORTH 64 Compile the screens 30 LOAD CR unless you have already compiled them with the 25 LOAD command enter the command PSTART CR and draw using the four cursor keys Note If you accidentally press a key to which a special function has not been assigned the key assignment is deactivated until you press RETURN see chapter 2 34 ABACUS Software FORTH 64 6 3 Descriptions of the graphics commands amp CLEAR amp HI RES amp INK amp LINE amp LO RES amp LOAD amp PAINT amp PAPER am
48. he command PLAY It plays until you press the STOP key probably quite soon 28 ABACUS Software FORTH 64 6 Graphics with the graphics vocabulary 6 1 Lo res You can not only make music with Forth 64 you can also create pictures and graphics The GRAPHIC vocabulary helps you with this in hi res while some words in the primary vocabulary of Forth help in lo res You have already become acquainted with some words for outputting to the screen in chapter 2 the colors and the words BORDER SCREEN and PEN If you want to write a character at an certain spot on the screen or you want to know what character is located there you need the words S and S Both words require the screen coordinates on the stack in the form line column sa l c a yields the code of the character in the lth line cth column S a l c writes pokes the character a in line l column c on the screen The following is a small program which tests the random number generator SCR 20 0 P RANDOM NUMBER TESTER RND 1 P FORTH DEFINITIONS DECIMAL 2 P RND 3 P INITIALIZE FIRST SCREEN 4 P 1024 1000 ASCII O FILL 5 P BEGIN 6 P 1000 RND RANDOM 0 999 7P 40 MOD COLUMN LINE 8 P SWAP EXCHANGE 9 P 2DUP Se CHARACTER 10 P 1 ROT ADD 1 11 P s SAVE 12 P TERMINAL UNTIL UNTIL STOP IS PRESSED 13 P 14 P HES 15 P You can load this program with LOAD 20 and execute it with RND CR 29 ABACUS Software FORTH 6
49. he screen awaiting your choice Quickly move from editing to formatting to merging to utilities Will work with virtually any prin ter ISBN 0 016439 12 7 20 gga ORGANIZE YOUR DATA DATAMAT 64 powerful yet easy to use data management 1 97 Naber Description package Free form Onnhand design of screen using up to 50 fields per Poeationy lt record Maximum of 2000 records per diskette Complete and Cost oo tlexible reporting Sort ing on multiple fields in any combination Select records for prin ting in desired format ISBN 0 916439 16 X 39 95 INVENTORY FILE Price Reord Pt Reord Otva Other Utles evellable For FREE CATALOG and name of nearest dealer write os coll 616 241 5510 For postage and handling include 4 00 6 00 foreign per order Money Order and checks in U S dollars only Mastercard VISA and Amencan Express accepted Michigan residents include 4 sales tax lt fox Bail CANADA Boch Center Montreal 514 332 4154 You Can Count On Li52599544 Abacus P O Box 7211 Grand Rapids M 49510 Telex 709 101 Phone 616 241 5510 Software w
50. hrough EXECUTE EXP2 b n Fast routine for calculating 2 to the power b where b is positive 6l ABACUS Software FORTH 64 EXPECT FENCE FFTABLE FILL FIRST FLD FTABLE FLIP FLUSH FORGET FORTH GTEXT addr count Transfers count characters from the terminal to address addr A carriage return ends the transfer prematurely Nulls are appended at the end of the string addr User variable Contains the address below which FORGET has no effect If FORGET is to be enabled below this address the contents of FENCE must be changed n Address of the assignment table for the Forth function keys addr quan b Fills quan bytes at address addr with byte b ft A constant Returns the address of the first disk block buffer addr User variable Contains the field width for formatted output Pointer to the current function key assignment table n n Exchanges the two bytes of word n Can be used at the end of an editing session in order to be sure that all text changes are saved on disk It is better to use DONE for this purpose though Used in the form FORGET ccecce All of the definitions after and including ccce are deleted from the dictionary P The name of the Forth language kernel The instruction sets FORTH as the CONTEXT vocabulary n _ The following text bounded by the delimiter defined in DELI is saved at n 62 ABACUS Software FORT
51. ins unchanged The loop can only be exited through the sequence R gt DROP 53 ABACUS Software FORTH 64 ALLOT AND ASCII B BUF B SCR BACK BASE BEGIN BL BLACK BLANKS n The integer n is added to the dictionary pointer This instruction is used to reserve space in the dictionary nl n2 n3 Bit wise logical AND n Returns the ASCII value of the first character of the following word Example ASCII A places 65 on the stack on The number of bytes per disk buffer 64 is placed on the stack n The number of disk buffers per screen 16 is Placed on the stack By definition one screen is 1024 bytes large It is then divided into 16 lines of 64 characters each addr The offset from HERE to addr for a backwards jump is calculated and compiled into the next free space in the dictionary addr U User variable which contains the current conversion base for input output a P Used in a definition in the form BEGIN ma UNTIL BEGIN ia AGAIN BEGIN E WHILE ron REPEAT BEGIN marks the start of a set of commands which can be repeated This point serves as a jump destination for the corresponding UNTIL AGAIN or REPEAT aa c The ASCII character BLANK is placed on the stack 0 Returns the constant 0 as the color value for black addr nl Overwrites nl bytes at addr with blanks 54 ABACUS Software FORTH 64 BLK ww BLOAD BLO
52. ized when the editor is called in order to preserve their contents over multiple editor calls The appropriate parameters must therefore be given for the first search or insert call TOP oa Sets the internal cursor position to 0 line 0 column 0 L i Sets the internal cursor position to the start of the ith line line i column 0 R n Sets the cursor pointer to n RE n Advances the cursor pointer n positions y pea Writes the line to which the cursor pointer points on the screen The cursor position is displayed through reverse output of the character in question X Erases the remainder of the line at the cursor position FIND a A search is made for the text enclosed in English pound signs following the command at the current cursor position The text is placed in the search buffer The delimiter can be found in the variable DELI and can be changed as desired If an empty string is specified for example FIND CR the search buffer does not change A search will be made for the string last given in a search command If no delimiters English pound signs are found in the following string the entire remainder of the input line will be used as the target string INSERT The text following the command and enclosed in English pound signs is inserted at the current cursor position The text is also placed in the insert buffer The delimiter is again in the variable DELI and can be changed
53. n Forth one first gives the operand s and then the operator therefore first the number 5 and then the instruction The same applies to arithmetic expressions The sum of the two numbers 7 and 12 is calculated in Forth through the expression 7 12 CR instead of 7 12 as usual Now we must explain how Forth words know what they are supposed to process To do so we must describe something called the stack 19 ABACUS Software FORTH 64 4 2 The stack In Forth all programs communicate over a single central location the stack Every Forth subroutine which requires parameters gets these parameters from the stack The user has the responsibility of making sure the appropriate parameters are on the stack before the subroutine is called Otherwise the called word will get some kind of garbage which can lead in the worst cases to a system crash A Forth word can best be described by representing the logical flow of the function and in addition clarifying the input and output parameters Stack Stack before Description of the function after The Forth words in the appendix are also to be understood in this manner Let us take a look at what happens to the stack when adding two number 7 12 CR 7 all number inputs are Fe en Placed on the stack H 7 H old i contents pes sl oS 12 as above PIESE i 12 i i 7 H told contents
54. n some places numbers will appear in the stack diagram instead of the above symbols These are constants which are to be used as synonyms of system address in the C 64 They are given in hexadecimal form Upper case letters on the right hand side indicate certain attributes of the definition P precedence bit set definition is immediate U user variable 45 ABACUS Software FORTH 64 CSP gt 8 2C C LEFT LEN MID MLEN n addr Stores the word n at addr pronounced store Stores stack pointer in CSP corresponds to CSP st Places the following text concluded with a quotation mark in the PAD buffer as a string constant dl d2 Creates the next character for output from a double length integer The result d2 is the quotient of the division by BASE Used between lt and gt see also S d addr count Ends the numeric conversion for output The result on the stack is the address and length in bytes of the string to be printed Can be directly accepted by TYPE dl d2 Creates ASCII text in the text output buffer by using until the double word d2 has the value zero Used between lt and gt stl st2 Store string stl in the string variable st2 stl st2 st Concatenation of two strings result in PAD st n st Lengthens the string st by the word n 2 characters st b st Lengthens the string st by the ch
55. ode in VIC addrl color range addr2 pixel range 36 FORTH 64 ABACUS Software FORTH 64 7 The Forth Assembler 7 1 General Forth 64 contains a complete assembler With this it is possible to program particularly time critical functions and to call these as any other Forth word The user will not know except through the speed with which a particular function is performed whether a word is written in Forth or in assembler The assembler need not be loaded separately it is always available The Forth assembler naturally contains all of the 6502 commands In addition it even makes a kind of structured programming possible with the help of the words BEGIN AGAIN UNTIL IF ELSE and ENDIF The words which return the conditions for the corresponding conditionals are called VS gt 0 lt O CS and NOT and checking the individual bits of the status bytes There are some deviations from normal assembly language programming For example all mnemonics are concluded with a comma in order to prevent name conflicts with other Forth words The same reverse Polish notation exists in the assembler which means that the operand is written first followed by the operator A modifying term may come between the two for immediate indexed or indirect addressing Some simple commands are 4 LDA LDA 4 XSAVE STX instead of STX XSAVE 50 JMP JMP 0050 If assembler programs are to be called as Forth words a few things mu
56. ord is pushed on the stack Address of a routine which transfers pops n 16 bit words from the stack to the temporary area N The number n is expected in the accumulator Address of a routine which removes the top word from the data stack and then executes PUT Address of a routine which removes a word from the data stack Like POP but removes two words Like PUSH but the high byte is not taken from the stack but is set to 0 Address of the inner interpreter All routines jump to NEXT directly NEXT JMP or indirectly such as PUSH PUT 40 ABACUS Software FORTH 64 7 3 A Small Assembly Language Program The C 64 user knows of the possibility to redirect output from the screen to some other device with the help of the CMD command OPEN 4 4 CMD 4 An assembly language routine in Forth which does something like this could look like the following SCR 40 0 P SCREEN OUTPUT TO PRINTER CMD 1 P FORTH DEFINITIONS HEX 2 P CODE CMD START OF AN ASSEMBLY LANGUAGE PROGRAM 3 P XSAVE STX SAVE STACK POINTER 4 P 4 LDA TAX 0 LDY 5 P FFBA JSR SETPAR 6 P O LDA FFBD JSR FFCO JSR 7 P 4 LDX FFC9 JSR CKOUT 8 P XSAVE LDX 9 P NEXT JMP 10 P END CODE ll P 12 P CODE RESET RESET SCREEN 13 P XSAVE STX FFCC JSR XSAVE LDX 14 P NEXT JMP 15 P END CODE DECIMAL You can now redirect output from the screen to the printer with the command CMD You can send it back to the screen with RE
57. p more ISBN 0 916439 11 9 39 95 XREF 64 indispensible tool for BASIC pro grammer cross references all references to variable and line numbers ISBN 0 916439 27 5 17 95 OTHER TITLES ALSO AVAIL ABLE WRITE OR CALL FOR A FREE COMPLETE CATALOG Call today for the name and address of your nearest local dealer PHONE 616 241 5510 For postage and handling include 4 00 8 00 foreign per order Money order and checks in U S dollars only Mastercard VISA and American Express accepted Michigan residents as a incl am sales tax ee abil FREE PEEKS amp POKES WALL POSTER INCLUDED WITH EVERY SOFTWARE PURCHASE You Can Count On Abacusii s25250906 TT P O Box 7211 Grand Rapids MI 49510 Telex 709 101 Phone 616 241 5510 Software Make your 64 work fulltime MAKE YOUR OWN CHARTS CHARTPAK 64 produces professional 7 khe quality charts and 156e graphs instantly from t ese your data 8 chart for mats Hardcopy in two sizes to popular dot matrix printers 39 95 gt see ISBN 0 916439 19 4 Ssl SALES COST TOTAL ENP A NET PROFIT orea QTR 2 aye 3 ore iver Also Available CHARTPLOT 64 for unsurpassed quality charts on plotters ISBN 0 916439 20 8 84 95 DETAIL YOUR DESIGNS CADPAK 64 superb lightpen design tool exact placement of object using our Accu Point positioning Has two complete screens Draw LINEs BOXes CIRCLEs ELLI
58. p SAVE amp S amp S amp ADD amp ECM amp CADD amp MASK Clear the graphics screen Switch to the HI RES mode no fee Set plotting color f xl yl x2 y2 Draw erase a line between xl yl and x2 y2 based on the condition of the flag f Switch to the lo res mode st dev Load hi res graphics from device dev disk 8 file st addr Initialize a byte with the paper and pen color at address addr in the graphics memory b pep Set background color st dev Save hi res graphics to device dev disk 8 file st Example PICTURE1 8 amp SAVE CR ky f Return the value of the pixel at x y fxy Set f TRUE or erase f FALSE a point at x y xy addr Return the relative pixel address in the graphics memory for the coordinates x and y Turn extended color mode on x y addr Return the relative address of the coordinates x and y in the color memory x ae m Return the mask of the xth bit of a byte in the graphics memory 35 ABACUS Software amp MCM amp SBM amp SCM amp TM DX DY x0 Y0 SET AREA Turn on multi color mode Set standard bit map Turn on single color mode Return to text mode addr Temporary variable addr Temporary variable addr Temporary variable for x coordinate addr Temporary variable for y coordinate addrl addr2 Set address range for graphic m
59. performs this operation The screen file is divided into individual logical pages screens A page contains 16 lines each of 64 characters A page is also the logical entity used in editing As we already said one can select any page at any time look at it and edit it Two screens are always reserved for error messages in Forth These are screens 4 and 5 When creating a new screen file do not forget to copy these pages to the new file If you don t do this you will not get any error messages when you encounter an error Before you edit your own programs get one of your own data disks for the sake of security This will also enable you to learn a couple of new Forth words insert original disk EMPTY BUFFERS 4 LIST 5 LIST CLOSE SCREEN CR insert new disk in drive N disk name id DOS CR Note The spaces behind the are relevant This command formats the disk erasing it CREATE SCREEN CR A screen file witk 2200 sentences is created and screens 4 and 5 which are in the disk buffer are copied to the disk It requires several minutes to create the file Now you have a Forth data disk which you can use right away You can of course make as many data disks as you like in this manner ABACUS Software FORTH 64 This page left blank intentionallly ABACUS Software FORTH 64 3 Forth Editor 3 1 General One of the peculiarities of Forth is that the user cannot divide his text and programs into files as de
60. r convenience for the user The first character the user enters after Forth responds with OK is checked to see if it is contained in an assignment table which creates a connection between input characters and Forth functions If this is the case then this function is performed and more input will be expected upon completion This continues until a key is pressed which is not contained in this table In this case the normal line input routine is called and the character first entered is of course retained An example of a key assignment can be found in Section 5 Music with the sound vocabulary w ABACUS Software FORTH 64 2 4 The screen file SCR Sooner or later it will no longer be any fun to enter your larger programs by hand each time You want to be able to write these to a file with the help of an editor in order to be able to load them again when required Forth recognizes only a single file This is called SCR in Forth 64 SCR is a relative file which can be of any desired size preferably on its own disk Forth manages this file virtually meaning that you can access random places in it page forwards and backwards and use them as you would memory in the computer without giving it any thought Forth takes care of the input and output transfer by itself You need only inform the computer when you are done with an editing session so that it can make sure that all of the memory has been saved on disk The word DONE
61. re such ambiguities exists for example the words PICK and ROLL have a slightly altered function and the old word 0 has been replaced with NOT in Forth 83 the old syntax and semantics have been retained in Forth 64 Independent of the standard Forth 64 contains a number of very useful words with which the SID Sound Interface Device and VIC Video Interface Controller can be addressed making it easier to use these devices for graphics and sound Forth 64 naturally includes the special Forth assembler with which one can create assembly language programs in the Forth notation and Forth has an easy to use editor We also haven t forgotten the words with which one can address external devices disk and process strings similar to BASIC and the many programming aids such as the DUMP HELP and TRACE commands Should the user still require additional words for his special needs these can be defined at any time and are as any other Forth word immediately available for use At this point we will only hint at the ability to assign strings Forth words to function keys or any other key Forth 64 makes use of the function keys itself and has assigned often used functions to the function keys in the editor and even standard modes The HELP command displays the current key assignments also when the assignments have been changed by the user One last feature of Forth 64 is the fact that all of the examples given in the user
62. remainder The remainder has the same sign as the dividend n These often used numbers are defined as constants in the dictionary f bi Sas Sets the flag true if n lt 0 else false f n Sets the flag true if n 0 else false 50 ABACUS Software FORTH 64 l 10 2 2e 2CONSTANT 2VARIABLE 2DROP 2DUP 2SWAP nl n2 Increments nl by 1 nl n2 Multiplies nl by 10 fast assembler mwultiplication d addr Store double word at address addr nl n2 Increment nl by 2 addr d Copy double word at address addr to the stack d A definition word Defined in the form d 2CONSTANT ccecce When ccce is called the double precision constant d is placed on the stack d aul A definition word Defined in the form d 2VARIABLE eccc When cccce is called the address of the variable which contains the double word is placed on the stack d Removes two words from the stack d dd Duplicates a double word on the stack dl d2 d2 dl Exchanges two double words on the stack Used in a ccecce 5 Defines a new word in the dictionary which is equivalent to the instructions represented here with The definition is ended with The context vocabulary is set to the current vocabulary words whose precedence bit is set are executed instead of compiled definition in the form P The definition and the compile mode are ended P Use
63. ress addr2 and the number of bytes n of the text which starts at addrl The text must be of the form such that the first byte at addrl contains the length of the string and the actual text starts at the second byte TYPE follows COUNT in typical applications 57 ABACUS Software FORTH 64 CR CREATE Causes a linefeed at the terminal A word with which one can construct new Forth words For example CREATE cccc This creates a header for the word to be defined cece The actions which this word is to execute must be compiled into the word with COMPILE for example The smudge bit is set The word cannot be addressed it will not be recognized until the smudge bit is cleared command SMUDGE CREATE SCREEN CSP CURRENT CYAN D DABS DECIMAL Establishes a file SCR with a length of 2200 sentences 137 records The message RECORD NOT PRESENT can be ignored here In addition the screens 4 and 5 error messages which should be in the disk buffers are copied into the file addr U User variable Contains the stack pointer addr User variable Contains an indirect reference to the name field address of the definition which was just defined see CONTEXT 3 Returns the constant 3 as the color code for cyan dl d2 dsum Adds the double words dsum dl d2 dl n d2 The double word dl contains the sign of n d aiaia Outputs a double word to the output device pronounced D dot
64. sired but must write these to a single virtual file called SCR in Forth 64 This virtual Forth storage is further divided into screens logical pages The user can select and work with desired pages of this file Just as screens can be selected at random for editing these same screens can be compiled in any order determined either through references at the end of each page or through a command page The processing entity is always such a screen The format of a Forth screen is standardized It always consists of 16 lines each of 64 characters The maximum number of screens depends on the amount of storage space available on the disk An additional standard is that screens 4 and 5 must contain error messages These screens should not be overwritten with programs or else no meaningful messages will be given when an error occurs If you take a look at these screens 4 LIST 5 LIST CR you will see that some lines are empty These lines can be filled with error messages as the user sees fit Line 15 on page 4 has another special significance It should contain a brief text identifying the disk perhaps its contents and the date of creation This line is evaluated by the documenting words TRIAD and INDEX The user can receive its message with the command 15 MESSAGE CR The following example will give you a look into how editing is done in Forth and how you you can change the disk identification line You can best learn about the m
65. st be taken into consideration Forth uses the X register as a stack pointer If the assembly language program makes use of the X register in other ways it must first save its value The variable XSAVE is used for this purpose It must naturally be restored at the end of the assembly language program Since the stack serves as an interface for passing parameters there are little aids for processing the information the words BOT and SEC for passing parameters and the jump labels PUSH PUSHO PUT PUTOA and NEXT The instructions BOT LDA and BOT 1 LDA return the top two bytes on the stack The second element on the stack can be obtained by indexing SEC instead of BOT 37 ABACUS Software FORTH 64 Assembly language programs can also begin with the word label They are not then addressable directly from Forth but can only be used as subroutines from other assembly language programs Finally there are certain return points to Forth to which a jump must be made with JMP at the end of the assembly language program If the stack is not to be changed one uses the symbolic address NEXT otherwise POP PUSH PUSHOA or PUT as required 38 ABACUS Software FORTH 64 7 2 The Assembler Vocabulary This list does not describe all of the actual assembler Mnemonics Their exact meaning can be found in a book about 6502 assembly language programming All of these commands are recognized by the Forth assembler provided
66. ten Try out the second and third voices in the same way 2 0 15 240 0 ENVELOPE CR and 3 96 10 0 10 ENVELOPE CR In the Commodore 64 User s Guide the second setting in combination with the waveform TRIANGLE and the third setting in combination with the waveform SAWTOOTH are valid parameters for organ and trumpet sounds Your own experiments will no doubt bring you still closer to this ideal 27 ABACUS Software FORTH 64 You can use the following program as a starting point to create a composition for piano organ and trumpet a combination seldom used today SCR 15 0 P CHAMBER MUSIC 1 PIANO ORGAN TRUMPET DEFINITIONS l P FORTH DEFINITIONS DECIMAL 2P ENVELOPE DEFINITIONS 3 P PIANO WAVE 4 P SOUND 1 9 3 50 8 ENVELOPE 5 P 6 P 7 P ORGAN WAVE 8 P SOUND 2 0 15 240 0 ENVELOPE 9P 10 P 11 P TRUMPET WAVE 12 P SOUND 3 96 0 0 5 ENVELOPE 13 P 14 P 15 P gt DEFINITION CONTINUED ON NEXT PAGE SCR 16 0 P CHAMBER MUSIC 2 PLAY 1 P FORTH DEFINITIONS DECIMAL 2P PLAY MAKE MUSIC 3 P 15 VOLUME FULL VOLUME 4 P PIANO ORGAN TRUMPET ENVELOPES 5 P BEGIN 6 P 3 RND 1 RANDOM VOICE 7 P CASE 8 P 1 OF 1 PULSE ENDOF 9 P 2 OF 2 TRIANGLE ENDOF 10 P 3 OF 3 SAWTOOTH ENDOF 11 P ENDCASE 12 P 5000 RND 5000 SWAP FREQUENCY 13 P 240 5 KEY RELATIONSHIP 14 P 16 RND 4 1000 VOICE 15 P 7TERMINAL UNTIL UNTIL STOP KEY PRESSED Load this program with 15 LOAD CR and start it with t
67. the buffer are marked as updated they will first be written to the disk before the next block is read The block is not read from the disk The address returned on the stack is the start address of the data to be read 55 ABACUS Software FORTH 64 c C CAP CASE C L ce CFA CIAl CIA2 CLEAR CLIT CLOSE b addr Stores the byte b in the address addr b es a Stores the byte b in the next free space in the dictionary The dictionary pointer is incremented by 1 b _ Writes a three byte entry of the form b 1 byte n the CFA of the following word in the dictionary Required for key assignment for example 133 CAP DISC n n CASE and ENDCASE together with OF and ENDOF offer the ability to execute case conditionals in Forth These words are used as in the following example CASE nl OF instruction for alternative 1 ENDOF n2 OF instruction for alternative 2 ENDOF nk OF instruction for alternative k ENDOF ENDCASE Alternative i is then executed if ni agrees with the value placed on the stack prior to execution of the CASE instruction n is removed from the stack by ENDCASE n Returns the number of characters per line 64 addr b Places 8 bits of addr on the stack see pfa cfa Converts the parameter field address to its code field address DCO0O Returns the address of the CIAL in the C 64 DDOO Returns the address of the CIA2 in the C 64
68. this doesn t work the assigned channel must be freed with a selective CLOSE Forth words may never contain characters with an ASCII value greater than 127 in particular no upper case letters in screen mode 2 of the C 64 upper lower case mode Strings such as This is text that works may contain such characters without difficulty 43 FORTH 64 ABACUS Software Appendix 1 Addresses 10 6A FF 100 1FF 800 8000 83FF 8620 8670 86CO SACO 9FFO A000 cooo Memory Map FORTH 64 Data stack Auxiliary variables Processor stack FORTH Work space Color Memory PADF PAD PADH Disk Buffer USER variable Bit map Memory All operating system routines are available without limitation provided they do not access the data stack in the zero page 44 ABACUS Software FORTH 64 Appendix 2 The Forth vocabulary The following list includes only words in the dictionary FORTH Words in the other vocabularies EDITOR SOUND GRAPHIC and ASSEMBLER have already been described in their own chapters k Symbols used addr memory address b 8 bit byte left byte 0 c 7 bit ASCII character right justified msb 0 d 32 bit double precision integer f logical indicator flag O false else true ff false flag 0 n integer 16 bit tf true flag lt gt 0 u unsigned 16 bit integer st string variable corresponds to n b for address and length of a string I
69. tputs the ASCII character c on the output device EMPTY BUFFERS Erases the entire disk buffer area 60 ABACUS Software FORTH 64 ENCLOSE addrl c addrl nl n2 n3 Used by WORD to separate a string The string begins at addrl C is the delimiter The parameters returned are 1 addrl as input 2 nl the byte offset to the first character different from the delimiter 3 n2 the byte offset to the first delimiter behind the string 4 n3 the byte offset to the first character different from the delimiter after the text end delimiter An ASCII zero in the text is handled as an absolute delimiter END Synonym for UNTIL P ENDCASE p s Used as the close to a CASE statement Gets the quantity to be checked from the stack see CASE ENDIF P Used in a definition in the form IF wes ENDIF IF ka ELSE ENDIF ENDIF is the destination of a forward jump from IF or ELSE THEN is a synonym for ENDIF see IF ELSE ENDOF P Used as the close to a variant in a CASE statement ERASE addr n Sets n memory words at address addr to zero ERROR line in blk Outputs error messages and functions as a system restart The exact error handling depends on the variable WARNING 1 Line n relative to screen 4 is output The line determined by n may lie outside screen 4 0 The value is output as a number 1l ABORT is called EXECUTE addr Addr is the code field address of the word to be executed t
70. turns a kind of index of the screens nl to n2 by writing the first line of each of the screens in this range on the screen In addition the disk information line line 15 of screen 4 is also printed n A variable which contains the plotting color for graphics The outer most text interpreter which executes or compiles input from terminal or disk The CONTEXT and CURRENT vocabularies are searched for the name If the name is not found the value is converted in the current base If a conversion error occurs the name is printed together with a addr The name field address of the last defined word in the CURRENT vocabulary is placed on the stack Exits a DO loop at the next LOOP or LOOP command pfa lfa Converts the parameter field address of a definition to its link field address n A constant Places the address which lies immediately above the last disk buffer address on the stack no Hes Screen n logical page n is listed on the terminal The variable SCR is not changed n LIT is inserted before a 16 bit literal when compiling When LIT is executed at run time it places the value on the stack n P Used in compilation mode in order to compile a calculated value into the dictionary The intended application is xxx calculation LITERAL Suspends the compilation mode performs a calculation and compiles the calculated value using LITERAL 64 ABACUS Software FORT
71. ut a sign less number on the output device f run time Used in a definition in the form BEGIN UNTIL The loop defined through BEGIN UNTIL is left if f true Marks the last addressed block indicated by PREV as changed This block will automatically be saved to disk when its buffer is required by another block addr A variable which contains the address of the block buffer to be used next i cas Definition word form n USER cccc This instruction defines a variable cccc in the USER area see appendix l N is the offset from the start of this area The user can define user variables with offsets from 64 to 127 The variable is initialized to 0 A defining word of the form n VARIABLE cccc When VARIABLE is executed cccc is defined and loaded with n When cccc is executed the variable address will be placed on the stack The value of the variable can be obtained with cccc D000 A constant which returns the address of the VIC in the C64 Doll A constant which returns the address of the first control register in the VIC 71 ABACUS Software FORTH 64 VICCR2 D016 A constant which returns the address of the second control register in the VIC VIC ADDPTR D018 A constant which returns the address of the address pointer register in the VIC VIC BORDER D014 A constant which returns the address of the VIC register which contains the border color of the screen V
Download Pdf Manuals
Related Search
manual manual manualslib manual car manuale digitale manually meaning manual timesheet manual transmission manual wheelchair manual arts high school manually update your device drivers windows manual definition manual for courts martial manual labor manual lawn mower manual muscle testing manually register devices with autopilot manual muscle testing grades manual transfer switch manualidades manual blood pressure cuff manual handling manual transmission cars for sale manual digital manual pdf manual autopilot enrollment
Related Contents
R O B I N C R Y L OWNER`S MANUAL - Royal Sovereign Kobe Range Hoods CH-191 User's Manual IR3100C-CN-Referenzhandbuch Dicota PerfectSkin CPI-WAM001 ユーザーズマニュアル "取扱説明書" Samsung CTI613EHST User Manual ジップチェーン アクチュエータ DNN9230DAB - Billiger.de Copyright © All rights reserved.
Failed to retrieve file