home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / util / superdark-2.0a.lha / SuperDark-2.0a / docs / programmers.doc < prev    next >
Encoding:
Text File  |  1993-06-22  |  20.2 KB  |  579 lines

  1. @AUTHOR   "Thomas Landspurg"
  2.  
  3. ## $VER: SuperDark.guide v1.1 (12.2.93)
  4.  
  5. ----------------------------------------------------------------------------------
  6. Main "SuperDark prog"
  7. ----------------------------------------------------------------------------------
  8.  
  9.     Writing your own modules for superdark:
  10.  
  11.     'Overview'
  12.     'Info'
  13.     'Dark function'
  14.     'MyGadg'
  15.     'Sample code'
  16.     'Debug'
  17.     'The info text'
  18.     'More info'
  19.     'Writting ASM modules'
  20.     'Problems'
  21.  
  22. ----------------------------------------------------------------------------------
  23. Overview "Overview"
  24. ----------------------------------------------------------------------------------
  25. @Toc    "Main"
  26. I Overview:
  27.  
  28.     How to add modules to SuperDark.
  29.  
  30. - It is not very difficult to add your own module to Superdark, but
  31. you have to read carefuly this doc, because there is some important 
  32. things to understand!
  33.  
  34. You have to do   four things to add a new module in SuperDark:
  35.  
  36. * Create your own 'dark()' procedure, that's the procedure called at
  37.   screen blanking. That's the biggest part of the job.
  38. * Add the 'proc_init()','proc_save()','proc_end()' function. Usually, these
  39.   function are empty. But for special purpose, you could fill them, look
  40.   at the doc.
  41. * Add a 'my_gadg[]' array. This array is used to create the param window,
  42.   but also to read and save parameters. Very powerful, and easy to use
  43.   after you've read the doc!
  44. * Create an 'info' text. This should be easy,no?
  45.  
  46. * You can 'Debug' using SDprintf()
  47. Notes:
  48.     * YOU MUST link your module with the proc_main.o object. Proc_main
  49. will make some important initialisation, contain important function for
  50. you!
  51.     * I use some special keyword of the Lattice compile, like __saveds.
  52. If you don't have them, check your compiler's documentation.But if you
  53. don't use callback procedure with button, you don't need this.
  54.  
  55. The simplest way to add a new module is to take a look at the module named
  56. "rien.dark.c", this module does aboslutly nothing, but you can use it
  57. at a skeletton program.
  58.  
  59. Note: You should use the function DCloseScreen() instead of CloseScreen().
  60. This function will keep the last opening screen in random mode. So in
  61. this mode, the workbench screen will not appears between two modules.
  62.  
  63. ----------------------------------------------------------------------------------
  64. Info "Info"
  65. ----------------------------------------------------------------------------------
  66.  
  67. II What is a module for SuperDark ?
  68.  
  69. - It's an executable program, loaded by SuperDark.
  70. - You have link it with proc_main.o.
  71. - Proc_main.o will make initialisation and wait for a signal from
  72.   superdark, and then will call your 'dark' function.
  73.  
  74. But:
  75.  
  76. - You can't do ANY printf
  77. - You can't run it alone
  78. Except:
  79.    If you link it with 'proc_main_debug.o' instead of proc_main.o
  80.  
  81. ----------------------------------------------------------------------------------
  82. dark "Dark function"
  83. ----------------------------------------------------------------------------------
  84. III
  85.     The dark() function:
  86.  
  87. This function is called by proc_main when the screen should be blanked.
  88. You can ask for a copy of the frontmost screen. To do this, look at the
  89. 'proc_init()' function.
  90. So you can put what you want here, but remeber these limitations:
  91.  
  92. - Don't use any printf in your program
  93. - Don't make any global auto-initalised variable. This may be cause some
  94.   problems if you don't see exactly what happens. Because when your dark()
  95.   function is called two time, the global are not reset to her initial value.
  96.   So if you use global var and change their value, be careful.
  97. - Try to don't use the whole CPU time. Use WaitTOF(), Delay(), Wait()... But
  98.   you are a good programmer, so you know what to do!
  99.  
  100.  To test if your function have to exit, you have the tst_end() function.
  101. This function will return TRUE if you have to exit, or FALSE if you have to
  102. continue. 
  103.     Example:
  104.         while(tst_end()==FALSE){
  105.             do what you want...
  106.         }
  107.   The other function is wait_end(). This function will only return at the end of the
  108. blanking time.
  109.   A new function is available since superdark v2.0, this function is called
  110. SDWait() (like SuperDarkWait).
  111.  
  112.     ULONG  SDWait(ULONG sigmask);
  113.  
  114.     sigmask is mask of the signal you are waiting for. SDWait will return
  115. if one of your signal is availbale. It's exactly the same than the exec
  116. Wait() function, but this function also do some internal SD function
  117. (like CPU watchdog), so IF you want to use  a wait function, YOU HAVE to
  118. use this function.
  119.  
  120. Return code: Since SuperDark v2.0, the dark function allow a return code.
  121. This code is zero if evrything is ok, non zero otherwhise. This will be
  122. used by the main superdark function to give some information to the user.
  123. So try to give a return code with your module.
  124. ----------------------------------------------------------------------------------
  125. proc_init() "proc_init()"
  126. ----------------------------------------------------------------------------------
  127. IV proc_init(),proc_save() and proc_end()
  128.  
  129. proc_init() is called after your module have been loaded. You can do
  130. special initialisation here, but don't use too much memory.
  131. That's here that you told if you want a copy of the current frontmost screen
  132. be opened for you. To do this, you have to do this:
  133.  
  134.     p_data_proc->type_screen=SCR_GIVEN;
  135.  
  136. You can also tell to superdark that your module should only run with
  137. superdark for WB2.0 or higher.
  138.  
  139.     p_data_proc->code_ret=DARK_WB_20;
  140.  
  141. proc_save() is no more used, but is still here for compatibility...
  142.  
  143. proc_end() is called when the module have to be removed from memory. You can
  144. free what you've allocated in proc_init().
  145.  
  146. ----------------------------------------------------------------------------------
  147. MyGadg "MyGadg"
  148. ----------------------------------------------------------------------------------
  149.  
  150. V The my_gadg array....
  151.  
  152. This one of the most powerful of superdark. Each module can have a parameter
  153. window. To do this, you have to define this window, but in a special manner.
  154. This array is an array of type tom_gadget. This is the definition of the
  155. type tom_gadget (from includes/tom_gadget.h) :
  156.  
  157. typedef    struct    tom_gadget{
  158.     char    *GadgetText;        /* Text of the gadget on screen. */                
  159.     type_gadget    type_gadg;    /* The type of the gadget, see later */
  160.     short    int    LeftEdge,TopEdge;/* position            */
  161.     short    int    Width,Height;    /* size                */
  162.     short    int    value;        /* value !            */
  163.     short    int    d1,d2,d3;    /* Used for special purpose.... */
  164.     char    *p_data;        /* Used for special purpose.... */
  165.     struct    Gadget    *p_gadg;    /* Internal use only        */
  166.  
  167. };
  168.  
  169. Note that the four standart gadget "ok","test","cancel","help" are
  170. automaticly added!
  171.  
  172. Let's see these field:
  173.  
  174. char    *GadgetText:
  175.     So it's the text of your gadget in the configuration window, but also
  176. of the corrseponding value in the TOOL TYPE list. Yes, because SuperDark
  177. se these informations to save the configuration as ToolTypes in the .info of
  178. the module.
  179.     You can use shorcut, by using '_'. Example, a gadget named TEST can
  180. have the shortcut T if his name is:
  181.     "_TEST"
  182.  
  183. type_gadget type_gadg:
  184.     Define the type of the gadget. These type are availaible:
  185. (note that they are also availble on WB1.3 for the most of them)
  186.  
  187.     The following type are available(and look at the 'exemple':
  188.  
  189.     'END_LISTE'
  190.     'BUTTON'
  191.     'SLIDER'
  192.     'CHECKBOX'
  193.     'MX'
  194.     'CYCLE'
  195.     'LISTVIEW'
  196.     'OWN_GADGET'
  197.     'STRING'
  198.     'INTEGER'
  199.     'SCREEN'
  200.     'FONT'
  201.     'DATA_STRING'
  202.     'IMAGE'
  203.  
  204. LeftEdge,TopEdge,Width,Height:
  205.     Position and size of the gadget...nothing else to say!
  206. ----------------------------------------------------------------------------------
  207. END_LISTE 
  208. ----------------------------------------------------------------------------------
  209.     END_LISTE:
  210.  
  211.         This is not really a type, but each tom_gadget array should
  212.         end with this value! Remember it!!!
  213. ----------------------------------------------------------------------------------
  214. BUTTON
  215. ----------------------------------------------------------------------------------
  216.     BUTTON:
  217.         A simple button. You can define a function called when the 
  218.         button is pressed, by giving a pointer to this function
  219.         in the p_data field.
  220. ----------------------------------------------------------------------------------
  221. SLIDER
  222. ----------------------------------------------------------------------------------
  223.     SLIDER:
  224.         A normal slider. The direction of the slizer (horiz/vertical)
  225.         is defined by the ratio Width/Height. If Width is > Height,
  226.         this will be an horizontal slider, otherwhise it's an vertical
  227.         one.
  228.  
  229.         * value must contain the initial value of the slider,
  230.  
  231.         * d1 and d2 must contain the range of the slider
  232.  
  233.         * if p_data is not nul, it must contain a pointer to the
  234.         variable wich will receive a copy of the current value
  235.         of the slider.
  236. ----------------------------------------------------------------------------------
  237. CHECKBOX
  238. ----------------------------------------------------------------------------------
  239.  
  240.     CHECKBOX:
  241.         Checkbock gadget.
  242.  
  243.         * value contain the initial value, and will be re-actualised,
  244. ----------------------------------------------------------------------------------
  245. MX
  246. ----------------------------------------------------------------------------------
  247.     MX:
  248.         Multiple choice gadget.
  249.  
  250.         * p_data must contain a pointer to an array of char
  251.             example: p_data={"Choice1","Choice2","Choice3",NULL}
  252.  
  253.         * value contain the initial value, and will be re-actualised,
  254.  
  255. ----------------------------------------------------------------------------------
  256. CYCLE
  257. ----------------------------------------------------------------------------------
  258.     CYCLE:
  259.         Cycle gadget.
  260.         Same kind of configuration than the MX gadget.
  261.  
  262. ----------------------------------------------------------------------------------
  263. LISTVIEW
  264. ----------------------------------------------------------------------------------
  265.     LISTVIEW:
  266.         Listview gadget.
  267.  
  268.         * p_data must containt a pointer to a List structure. the
  269.         name of each node of the list will be be show on screen.
  270.  
  271.         * value contain the position of the initial selected value,
  272.         and will be re-actulised.
  273. ----------------------------------------------------------------------------------
  274. OWN_GADGET
  275. ----------------------------------------------------------------------------------
  276.     OWN_GADGET:
  277.         Very special purpose gadget!!!!
  278.         No time to describe it now...sorry.
  279.  
  280.         I just can say that it's used to create other type of
  281.         gadget than the current available.
  282. ----------------------------------------------------------------------------------
  283. STRING
  284. ----------------------------------------------------------------------------------
  285.     STRING:
  286.         String gadget
  287.  
  288.         * p_data must contain a pointer to a buffer of char. This buffer
  289.         will containt the value of the string gadget.
  290.  
  291.         * d1 MUST CONTAINT the size of the buffer.
  292. ----------------------------------------------------------------------------------
  293. INTEGER
  294. ----------------------------------------------------------------------------------
  295.     INTEGER:
  296.         Integer gadgt.
  297.  
  298.         *value contain the initial value, and will be re-actualised,
  299.  
  300.         *d1 contain the max number of digits for the number.
  301. ----------------------------------------------------------------------------------
  302. SCREEN
  303. ----------------------------------------------------------------------------------
  304.     SCREEN:
  305.         High level gadget....
  306.         This gadget will only be active if you have WB3.0, or if
  307.         reqtools.library v38 or higher is present on your system.
  308.         It allow you to choose a screen resolution, size, and overscan
  309.         value, by using the screen requester from the reqtools lib.
  310.  
  311.         * value contain the initial Overscan mode of the screen,
  312.         and will be re-actualised. Look at intuition/screens.h
  313.         * d1 contain the initial Width of the screen, and will be
  314.         re-actualised
  315.         * d2 contain the initial Height of the screen, and will be
  316.         re-actualised
  317.         * d2 contain the initial Depth of the screen, and will be
  318.         re-actualised
  319.         * p_data contain the initial Mode ID of the screen, and will be
  320.         re-actualised
  321.         Note:
  322.         If d3 (depth) is null, this mean that none of the value is
  323.         significative.
  324.  
  325. ----------------------------------------------------------------------------------
  326. FONT
  327. ----------------------------------------------------------------------------------
  328.     FONT:
  329.         The second high level gadget....
  330.         It allow you to choose a font, include size and attributes.
  331.  
  332.         * p_data is a pointer to a TextAttr structure.
  333.           IMPORTANT NOTE: This text attr must have the field ta_Name
  334.           initialized with a pointer to a string buffer, with enough
  335.           space to put the biggest name of the available font
  336.  
  337.  
  338. ----------------------------------------------------------------------------------
  339. DATA_STRING 
  340. ----------------------------------------------------------------------------------
  341.     DATA_STRING:
  342.         This data type is only used for configuration. I mean than
  343.         you won't see anything on configuration window, but a string
  344.         will be saved and loaded in the configuration file.
  345. ----------------------------------------------------------------------------------
  346. IMAGE
  347. ----------------------------------------------------------------------------------
  348.     IMAGE
  349.         With this data, you can include an image in your parameter
  350.         window. Just put a pointer to an image structure in the 
  351.         p_data field
  352. ----------------------------------------------------------------------------------
  353. INV_CHECKBOX
  354. ----------------------------------------------------------------------------------
  355.     INV_CHECKBOX:
  356.         This stand for "invisible checkbox". This type of gadget
  357.         IS NOT a gadget! This will do nothing on screen,but it's
  358.         just used to save/load a bool value. This value can only
  359.         be changed by user using the info menu of the workbench
  360.         on the superdark.info.
  361.  
  362. ----------------------------------------------------------------------------------
  363. EXEMPLE
  364. ----------------------------------------------------------------------------------
  365.  
  366.     Example: we want to make a parameter window, with three things:
  367.     - a checbox,
  368.     - a slider , wich can have value from -10 to 50
  369.     - a "screen" button.
  370.  
  371. struct    tom_gadget    my_gadg[]={
  372.     {"_Check it"    ,CHECKBOX  , 100, 10, 10,10,0,0,0,0,0},
  373.     {"_slide it"    ,SLIDER  ,   100, 25, 10,10,10,-10,50,0,0},
  374.     {"s_creen"      ,SCREEN  ,   200, 10, 50,10,0,0,0,0,0}};
  375.  
  376.     The parameter window will look like this:
  377.  
  378.     -------------------------------------------------
  379.     |                        |
  380.     |           _     ________        |
  381.     |   Check it  | |        |screen|        |
  382.     |           -         --------        |
  383.     |          ___________________        |
  384.     |   slide it  |          #      |        |
  385.     |             -------------------        |
  386.     |                        |
  387.     |        Ok      Test      Cancel      Info    |
  388.     |                        |
  389.     -------------------------------------------------
  390.  
  391. and when you press OK, you'll see in the tooltype of your module:
  392.  
  393.     CHECK IT=FALSE
  394.     SLIDE IT=20
  395.     SCREEN  =320 x 256 x 3 ID=21000 OVSCN=0
  396. Nice no?
  397.  
  398.  
  399. ----------------------------------------------------------------------------------
  400. Info_text "Info_text"
  401. ----------------------------------------------------------------------------------
  402.     The information text:
  403.  
  404.     It's the text show when you press the "Info" button. It's just an
  405. ascii string, named p_text_info. Example:
  406.  
  407. char *p_text_info=
  408. "   Hi evrybody    \n"
  409. "now I can do my   \n"
  410. "own module for the great\n"
  411. "    SUPERDARK!\n";
  412.  
  413.     Note the \n at the end of each line
  414. ----------------------------------------------------------------------------------
  415. EXAMPLE
  416. ----------------------------------------------------------------------------------
  417.    Sample code:
  418.    -----------
  419.    First, take a look at the sample blankers source code. This should give
  420. you some information. Here is a simple exemple of a blanker. This blanker
  421. do absolutly nothing!:
  422.  
  423. /* ---  start of code ---- */
  424.  
  425. #include    <exec/types.h>
  426. #include    <exec/ports.h>
  427. #include    <dos/dos.h>
  428. #include    "/includes/struct.h"
  429. #include    "/includes/tom_gadget.h"
  430.  
  431. extern    struct    RastPort    *rp;
  432. extern    struct    Screen        *s;
  433. extern    struct    appel_proc    *p_data_proc;
  434.  
  435. char    *name_module="vide.dark";
  436. char    *p_text_info=
  437. "Rien\n"
  438. "This programm do nothing\n"
  439. "It's a skeletton for your own\n"
  440. "purpose";
  441.  
  442. /* An empty list of gadget....*/
  443. struct    tom_gadget    my_gadg[]={
  444.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}};
  445.  
  446. /* Put here your own code */
  447.  
  448. void    dark()
  449. {
  450.     wait_end();
  451. }
  452.  
  453. /************************************************************************/
  454. /* These 3 function have to be here, even if they are empty         */
  455. /************************************************************************/
  456. void    proc_init()
  457. {
  458. }
  459. void    proc_save()
  460. {
  461. }
  462. void    proc_end()
  463. {
  464. }
  465.  
  466. /* ---  end of code ---- */
  467.  
  468. To create a module, do this, using lattice (suppose your file name is
  469. my_blanker.dark):
  470.  
  471. lc my_blanker.dark.c
  472. blink FROM LIB:c.o proc_main.o my_blanker.dark.o LIB $(LD_LIBS) SC SD TO my_blanker
  473.  
  474. Then, configure "Dark directory" in superdark to the directory
  475. where is this blanker. So you should see it in the file list modules.
  476. ----------------------------------------------------------------------------------
  477. DEBUG
  478. ----------------------------------------------------------------------------------
  479.     Now, a little help to debug your module....
  480.  
  481. - First, try to make your 'effect' alone, without using superdark. Then,
  482.   put it as a blanker.
  483.  
  484.   SHOW_INFO:
  485.   ---------
  486.   Usage:  show_info
  487.  
  488. - There is an utility program, called show_info. This program, open two
  489.   window. In the first window there is some not so interesting informations,
  490.   but the second window is a text window. And you can send text to this
  491.   window, by using a SDprintf() function, like this:
  492.  
  493.     SDprintf("Hello, I'm in my module, and the value is:%ld\n",toto);
  494.  
  495.   NOTE: DO NOT USE printf, use SDprintf
  496.  
  497.   NOTE: The function use the exec RawDoFmt, but this last function only
  498.         work with LONG value, so use %ld,%lx, instead of %d,%x, etc...
  499.  
  500. - proc_main_debug:
  501.  
  502.   Proc_main_debug is a replacment for proc_main.o. If you link with 
  503.   proc_main_debug.o, you can run your module alone, without superdark.
  504.   So you can use a debugger to test your module. But note that configuration
  505.   will not be loaded/saved!
  506.  
  507. ----------------------------------------------------------------------------------
  508. MORE
  509. ----------------------------------------------------------------------------------
  510. some more informations:
  511.  
  512. - CPU timeout:
  513.  
  514.    Since v2.0, there is a check to see if there is enough cpu time to
  515. run the blanker. This features will automaticly be added using the last
  516. version of proc_main.o. The older version (module which maybe are
  517. not recompiled) will not have this fetures, but will run correctly.
  518.    This function work fine if you use the tst_end() or wait_end()
  519. functions. If you don't use them (REALLY? Strange...) or IF YOUR PROGRAM
  520. SHOULD ABSOLUTLY NOT HAVE THIS "CPU TIMEOUT" WATCHDOG, add this line
  521. in your proc_init() function:
  522.     p_data_proc->enable_watchdog=FALSE;
  523.  
  524. - Version:
  525.  
  526.   Since V2.0 of superdark, there is a version number available for
  527. the module. This version can be found in p_data_proc->version (look
  528. at file "struct.h"), and revision number is in p_data_proc->revision.
  529. So first version available will be version 2, revision 0.
  530.   This prevent some module to use some features not available in older
  531. version of superdark.
  532.  
  533.  
  534.  
  535.  
  536. ----------------------------------------------------------------------------------
  537. asm "ASM"
  538. ----------------------------------------------------------------------------------
  539.  
  540.   I've just talk of C, but the module can be made in any langage.
  541. You can write an ASM module. But you still have to link it with
  542. proc_main.o. You can do this using the great devpac assembler.
  543. But there is no tom_gadget.i, only tom_gadget.h. That's why
  544. you could use the same method than me: make a c program where
  545. there is evrything except the dark() function, and then put
  546. the _dark() function in an asm program, and them link evrything!
  547.   Just take a look at the plasma sourcecode, in the full superdark
  548. distribution.
  549.  
  550. ----------------------------------------------------------------------------------
  551. Problems "Problems"
  552. ----------------------------------------------------------------------------------
  553.  
  554. VI If it doesn't work....
  555.  
  556. Hum....take a look at the other sourcecodes in the disk 
  557.  
  558. If this still doesn't work, you can send me you module and I'll try to
  559. make it work....
  560.  
  561. my  adress
  562.  
  563.     Thomas LANDSPURG
  564.     9, Place Alexandre 1er
  565.     78000 VERSAILLES
  566.     FRANCE
  567.  
  568.     FidoNet: 2:320/104.18
  569.     AMyNet:    39:180/1.18
  570.     UseNet:    Thomas.Landpsurg@ramses.gna.org
  571.  
  572.  SuperDark may not be included with any commercial product nor may it be
  573.  sold for profit either separately or as part of a compilation without
  574.  my permission. It may be included in non-profit disk collections such as the
  575.  Fred Fish collection. It may be archived & uploaded to electronic bulletin
  576.  board systems as long as all files remain together & unaltered.
  577.  
  578.  
  579.