home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 224b.lha / hello.world < prev    next >
Text File  |  1989-04-08  |  12KB  |  1 lines

  1. \ hello.world example.                                01Oct88pJa                                                                Opens it's own screen and a window in it.  Prints a string      in the window and waits for closure of the window.                                                                              Example from chapter 1, Intuition manual.                                                                                       -include.blk must be loaded for include file support and         Amiga C structure support.                                     -A Graphics vocabulary and the graphics.library must be opened.  (Normally done by Utilities.blk)                                                                                               ( see screen 5 for some hints and comments )                                                                                                                                                                                                                    \ Load screen for hello.world                         01Oct88pJacr .( loading include files )                                   only forth also Exec definitions                                   tload i:exec/ports                                              tload i:exec/tasks                                           Intuition definitions                                              tload i:intuition/screen                                        tload i:intuition/window                                        tload i:intuition/intuimessage                               Graphics definitions                                               tload i:graphics/rastport                                    only forth Exec also forth Graphics also forth Intuition also       forth also definitions                                      cr .( loading program.)                                         2 4 thru                                                                                                                        \ Define the screen                                   30Jul88pJavariable sp                                                                                                                     NewScreen ns   ns sizeoff NewScreen erase                                                                                                320 ns Width    s!                                              200 ns Height   s!                                              2   ns Depth    s!                                              1   ns BlockPen s!                                     CUSTOMSCREEN ns Type     s!    a" My Own Screen"                             ns DefaultTitle   s!                                                                                                                                                                                                                                                                                                                                                               \ Define the window                                   30Jul88pJavariable wp                                                                                                                     NewWindow nw   nw sizeoff NewWindow erase                                                                                       a" A Simple Window."               nw Title     s!               20 nw LeftEdge s!             300 nw Width     s!               20 nw TopEdge  s!             100 nw Height    s!              320 nw MaxWidth s!             200 nw MaxHeight s!              100 nw MinWidth s!              25 nw MinHeight s!                1 nw BlockPen s!    CUSTOMSCREEN nw Type      s!              CLOSEWINDOW   nw IDCMPFlags s!                                  WINDOWCLOSE   SMART_REFRESH or  WINDOWSIZING  or  ACTIVATE or   WINDOWDRAG or WINDOWDEPTH   or  NOCAREREFRESH or  nw Flags s!                                                                                                                                   \  Open screen and window                             30Jul88pJa                                                                ns OpenScreen dup sp !   nw Screen s!                                                                                           nw OpenWindow wp !                                                                                                              wp @ { Window RPort s@  20 20  Move                                                                                             : hi   wp @ { Window RPort s@  " Hello  World" 1-  Text drop  ;                                                                 : test    wp @  { Window UserPort s@   { MsgPort                   mp_SigBit s@    1 swap  <<   Wait drop                          wp @ CloseWindow   sp @ CloseScreen  ;                                                                                       ( See next screen for more comments )                                                                                           \ More comments.                                      01Oct88pJaWhen you load screen 4, the Intuition screen and window are opened.  You will be staring at them. Depth arrange them and/or     drag this forth window, so you can enter 'hi' to display the    message in the window.                                          After that type 'test' which will wait for you to close the     window by clicking on the close gadget.                                                                                                                                                         ( see also on shadow screen )                                                                                                                                                                                                                                                                                                                                                                                                                                   \ hello.world example.                                01Oct88pJa                                                                Look at the include files to see how structures are declared.   Only one level is used. That is no two files depend on each     other ( with the exception of dos ). Makes for a more compact   form. I have included references in comments, to files that     contain the structures referred to and their size in bytes.     For instance in i/exec/memory, MemHeader has an included struct  of 14 bytes, a Node, declared in i/exec/nodes. To use it:                                                                       MemHeader myhead   myhead mh_Node { Node ln_Pri s@                                                                             After you have loaded both include files.                                                                                                                                                                                                                       \ Load screen for hello.world                         30Jul88pJa  Don't forget to have include.blk loaded.                      First load in the include files for Exec                                                                                                                                                        Next load in the definitions for Intuition.                                                                                                                                                                                                                     And the graphic definitions for text printing.                                                                                  This sets the search order to:                                  Context: forth forth Intuition Graphics Exec root               Current: forth                                                  Which allows access to all required definitions.                                                                                \ Define the screen                                   01Oct88pJasp   Is a pointer to the screen, where we keep the address of         the structure returned by Intuition.                      ns   Is the newscreen structure. NewScreen creates it. ns is          like a variable. Zero the ns, only set the fields required      Note how the individual fields are set. No knowledge of         the field size is required. CUSTOMSCREEN is defined in          intuition vocabulary.  The word a" returns an address for       a string terminated by a 0, without a length byte, the          way intuition wants to see them.                                                                                                                                                                                                                                                                                                                                                                                                                          \ Define the window                                   30Jul88pJawp   Is the window pointer after it is created.                                                                                 nw   Is the newwindow structure. Similar to newscreen, first          zero out the structure, then set only what needs to be.         It is not required to do it in any order.  The use of nw        leaves the address of the structure, and the field name         modifies the address, also sets a few deferred word to          make s! and s@ work properly.                                   Only CLOSEWINDOW is asked for from Intuition. We must do        explicit or's on the flags.                                                                                                                                                                                                                                                                                                                                                               \  Open screen and window                             30Jul88pJaThis sequence opens the screen and sets the pointer in the      window structure to the screen. I don't do any error checking!                                                                  Now open the window and save the pointer also.                                                                                  Fetch the window pointer and get the RastPort, move gr_cursor.                                                                  hi   prints the message in the window.                                                                                          test   Gets the signal bit# from the window and Wait's for         Intuition to give us a message, it will be a close message.     Close the window and screen.  That's it..                                                                                                                                                                                                                    \ More comments.                                      01Oct88pJaThe way { works is to reveal the field definitions for the      structure definition following it.  Thus entering _{ Window_    will allow access to the Window structure fields, until another structure word is used, e.g. ns above, or until another { is    used.  Inside colon definitions { is immediate, it compiles     nothing, but allows access the the field name, which is compiled                                                                Note that wp is not a structure so it does not reveal the field names.  Try a 'see' on the word hi, Window is not there but      RPort is. Yet if you do a 'words' on Intuition, you will not   see RPort. It is hidden and is 'attached' to Window, and any    structure defined as a Window. (not pointers)                   You can type _{ Window swords_ to see the field names.          Or _.{ Window_ will show a little more.