home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / lang / J4thDemo.lha / Tutorials / More_Commands < prev    next >
Encoding:
Text File  |  1992-10-06  |  5.4 KB  |  184 lines

  1.  
  2. \ This file is filled with more example commands for you
  3. \ to try out.
  4. \
  5. \ Type them in, as displayed, and observe the results.
  6. \ After some commands is a short description of the
  7. \ action the command performs.  (Remember, JForth is
  8. \ NOT case-sensitive, so the text may be entered in
  9. \ either upper- or lower-case.)
  10. \
  11. \ NOTE: some of the following include command SEQUENCES.
  12. \       This means that those lines which do not have at least
  13. \       one blank line between then need to be typed in
  14. \       in order.  (Remember, text after '\' characters or
  15. \       between a single parentheses and its 'mate' are
  16. \       comments and need not be typed in, like this text.
  17. \
  18. \ TIME-SAVERS...
  19. \
  20. \ Don't forget that the F1 key will save you the trouble of having
  21. \ to type in INCLUDE each time.  Also, remember that SHIFT-UP-ARROW
  22. \ is how to use JForth's COMMAND LINE HISTORY to recall a previous
  23. \ line to the screen for another entry with or without editing.
  24. \
  25. \ NOTE: It IS possible to INCLUDE this file, but for purposes of
  26. \       learning, it is much better to follow through the commands
  27. \       by hand.
  28.  
  29.  
  30.  
  31. \ In the programs directory is the source for an IFF picture viewer
  32. \ using JForth's IFF support files.  These command compile it, then
  33. \ display a lo-res IFF picture we've put in the Tutorials directory.
  34.  
  35. INCLUDE PROGRAMS/SHOW_IFF
  36. JSHOW TUTORIALS/STORM.IFF
  37. \ Click in the top-left corner of the picture to close it.
  38. \ When you're done experimenting with LINES, enter:
  39. FORGET TASK-SHOW_IFF
  40.  
  41.  
  42.  
  43. : ADD3  16 32 +  64 +  .  ;
  44. ADD3
  45. DEF ADD3
  46.  
  47. \ The above compiles a word which adds 3 numbers and prints the answer.
  48. \ It then executes the word.
  49. \ The 3rd line displays the code the compiler put together.
  50.  
  51.  
  52.  
  53. FORGET ADD3
  54. DEBUG{
  55. : ADD3  16 32 +  64 +  .  ;
  56. }DEBUG
  57. DEBUG ADD3
  58. \ then press the SPACE BAR repeatedly, until the Debugger window goes away.
  59.  
  60. \ The above compiled ADD3 again, this time with DEBUG turned on.
  61. \ The last line executed ADD3, using the 'single-step' function of
  62. \ the Debugger.
  63. \ The user then presses the SPACE BAR to single-step the program.  Note
  64. \ the data stack manipulations are displayed with each action.
  65. \ Note that pressing the '?' key will display a list of debugger commands
  66. \ (while inside the debugger) and that any key will pause the list, then
  67. \ any key will continue.
  68.  
  69.  
  70.  
  71. TYPEFILE S:STARTUP-SEQUENCE
  72.  
  73. \ Pause with SPACE-BAR, then RETURN to continue.  Many JForth display
  74. \ words pause like this... provided by the word ?PAUSE.  For example...
  75.  
  76. : JUSTHELLO
  77.   100 0
  78.   DO
  79.       ." HELLO"  ?PAUSE CR
  80.   LOOP
  81. ;
  82. JUSTHELLO
  83.  
  84. \ Before the above word finishes, hit the SPACE-BAR and the stream
  85. \ of HELLOs will stop.  Hit RETURN to continue.  Enter JUSTHELLO again
  86. \ if it finishes before you have a chance to try the PAUSE feature.
  87.  
  88.  
  89.  
  90. INCLUDE PROGRAMS/QUARTERS.F
  91. 8239 QUARTERS
  92. \ When you're done experimenting with Quarters, enter:
  93. FORGET TASK-QUARTERS.F
  94.  
  95.  
  96.  
  97. INCLUDE PROGRAMS/DEMO_LINES
  98. LINES
  99. \ This demo runs until you click the lines windows closebox.
  100. \ When you're done experimenting with LINES, enter:
  101. FORGET TASK-DEMO_LINES
  102.  
  103.  
  104.  
  105. \ Interactive graphics example...
  106.  
  107. GR.INIT
  108. GR.OPENTEST
  109. 20 20 GR.MOVE
  110. 80 20 GR.DRAW
  111. 20 30 GR.MOVE
  112. " HERE IS SOME TEXT" GR.TEXT
  113. 40 40 120 60 GR.RECT
  114. GR.CLOSECURW
  115.  
  116.  
  117. \ That's about if for the example commands, unless you're interested
  118. \ in JForth's assembler interface.  If so, continue...
  119.  
  120. \ Assembly examples
  121.  
  122. ASM PUSH.5.ON.STACK   ( -- 5 )
  123.     MOVE.L  D7,-(A6)    \ push current top-of-stack out
  124.     MOVEQ.L #5,D7       \ put a '5' in the top-of-stack register
  125. END-CODE
  126.  
  127. \ The above word illustrates JForth's "cached data stack"...
  128. \ The topmost "item on the stack" is really kept in data reg 7,
  129. \ and the memory for the "rest of the stack" is pointed to by
  130. \ addr reg 6.
  131.  
  132. \ JForth allows these registers to be specified with names more
  133. \ descriptive of these functions.  Data reg 7 can be called TOS
  134. \ and addr reg 6's other name is DSP (for Data Stack Pointer)
  135. \ So the following word is identical to the previous one.
  136.  
  137. ASM PUSH.ANOTHER.5   ( -- 5 )
  138.     MOVE.L  TOS,-(DSP)    \ push current top-of-stack out
  139.     MOVEQ.L #5,TOS        \ put a '5' in the top-of-stack register
  140. END-CODE
  141.  
  142. \ NOTE: You can tell the disassembler to display either standard
  143. \ Motorola register names, or JForth's custom names, by setting
  144. \ a variable called DISM-NAMES.  Entering:  DISM-NAMES OFF
  145. \ will tell the disassembler to use standard names,  DISM-NAMES ON
  146. \ will cause the custom names to appear.
  147.  
  148. \ NOTE:  All assembly words have to start with ASM and the name
  149. \ of the function, and end with the single statement END-CODE in
  150. \ the first column.
  151.  
  152. \ The following assembly word illustrates some common
  153. \ assembly operations such as:
  154. \
  155. \ 1. defining and branching to a local label
  156. \ 2. Interactively referencing JForth words (like constant values)
  157. \ 3. CALLing other high-level words.
  158.  
  159. ASM EXAMPLE.CODE  ( n -- n*2 , just a bunch of example code, double 'n' )
  160.     ASL.L    TOS  \ do the 'real work and double the passed in parameter
  161.     \
  162.     \ the rest is just example.   First let's DUP the answer then
  163.     \ print its value (with .HEX)
  164.     \
  165.     CALLCFA   DUP   \ we'll see what the compiler puts together later
  166.     CALLCFA   .HEX  \   by using DEF
  167.     \
  168.     \ zero the value if it is negative or equal to MEMF_CHIP
  169.     \
  170.     TST.L     TOS
  171.     BPL       2$
  172. 1$: MOVEQ.L   #0,TOS
  173.     BRA       3$
  174. 2$: CMP.L     #[MEMF_CHIP],TOS
  175.     BEQ       1$
  176. 3$: RTS
  177.     \
  178.     \ That's it!
  179.     \
  180. END-CODE
  181.  
  182. 6 EXAMPLE.CODE .  ( should print double )
  183. DEF EXAMPLE.CODE
  184.