home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / s / stblsrc.zip / STBLACC.ASM < prev    next >
Assembly Source File  |  1989-04-06  |  33KB  |  952 lines

  1. *****************************************************************
  2. * ST Blank - A general purpose screen blanking accessory/program*
  3. *****************************************************************
  4. * Language      : 68000 assembler                               *
  5. * Assembler     : Metacomco (Version 12.0)                      *
  6. * Version       : 2.0.1                                         *
  7. * Date created  : 1989/08/24                                    *
  8. * Last modified : 1993/01/27                                    *
  9. *****************************************************************
  10. *                           HISTORY                             *
  11. *****************************************************************
  12. *  Ver  * Date     * Comments                                   *
  13. *****************************************************************
  14. * 1.0.0 * 01/09/89 * First release                              *
  15. *****************************************************************
  16. * 1.0.1 * 01/09/89 * All A-Line variables are now saved and     *
  17. * restored to prevent crashes in applications software          *
  18. *****************************************************************
  19. * 1.0.2 * 02/09/89 * A-Line code replaced by own plotting code  *
  20. * and stack size increased, both to prevent application crashes *
  21. *****************************************************************
  22. * 1.1.0 * 01/12/89 * Star table changed so that it will work on *
  23. * ST's with a 32-bit address bus (i.e. TT machine). Stars ON/OFF*
  24. * option added to dialogue, along with star speed selector. Full*
  25. * version information appears on accessory menu slot            *
  26. *****************************************************************
  27. * 1.2.0 * 03/04/90 * Improved XBRA installation, and BIOS output*
  28. * to PRT, AUX, CON or MIDI is counted as "activity"             *
  29. *****************************************************************
  30. * 1.2.1 * 03/04/90 * All key presses now detected by virtue of  *
  31. * and IKBD interrupt handler. Since this same routine also      *
  32. * handles mouse packets, the old mouse handler is not required, *
  33. * and button presses are now recognised, as is joystick movement*
  34. *****************************************************************
  35. * 1.2.2 * 04/04/90 * Error messages now output when ST Blank    *
  36. * fails to install                                              *
  37. *****************************************************************
  38. * 1.2.3 * 21/05/90 * Bug fixed in BIOS intercept that caused    *
  39. * G+PLUS to crash                                               *
  40. *****************************************************************
  41. * 1.3.0 * 24/09/90 * Save / Load config option added, some code *
  42. * reorganisation                                                *
  43. *****************************************************************
  44. * 1.3.1 * 20/10/90 * BIOS TRAP handler modified to cope with the*
  45. * longer stack frame of the '010+ processors.                   *
  46. *****************************************************************
  47. * 2.0.0 * 28/09/91 * Split AUTO program and ACC/PRG version for *
  48. * greater flexibility and to fix crashes on TT                  *
  49. *****************************************************************
  50. * 2.0.1 * 22/01/93 * Fix bug that caused .PRG part to crash if  *
  51. * .INF file not found. Show the user an about dialogue if they  *
  52. * click on the ST Blank title bar                               *
  53. *****************************************************************
  54.  
  55.         INCLUDE "STBLANK.I"     ST Blank resource definitions
  56.  
  57. GO:
  58.         move.l  a7,a5
  59.         move.l  #USTK,a7
  60.         move.l  a0,prgtype      A0 = 0 for programs, /= 0 for DAs
  61.         tst.l   prgtype
  62.         bne     acc_go          Skip memory shrink if accessory
  63.  
  64. prg_shrink:
  65.         MOVE.L  4(A5),A5
  66.         MOVE.L  $C(A5),D0
  67.         ADD.L   $14(A5),D0
  68.         ADD.L   $14(A5),D0
  69.         ADD.L   #$100,D0
  70.         MOVE.L  D0,-(SP)
  71.         MOVE.L  A5,-(SP)
  72.         MOVE.W  D0,-(SP)
  73.         MOVE.W  #$4A,-(SP)
  74.         TRAP    #dos
  75.         lea.l   12(sp),sp
  76.  
  77. acc_go:
  78.         pea     inst_crit(pc)   Do super mode installation bits
  79.         move.w  #38,-(sp)
  80.         trap    #xbios
  81.         addq.l  #6,sp           tidy
  82.  
  83.         jsr     appl_init       Set up AES and
  84.         move.l  d0,appid        store application ID
  85.         
  86.         bsr     find_cookie     Look for our cookie
  87.         move.l  shared,d0
  88.         beq     noshared        If zero, no PRG part!
  89.         bsr     load_rsrc       Load resource file & find tree addrs
  90.         tst.l   treeaddr        errors?
  91.         beq     no_rsc          Handle
  92.         
  93.         tst.l   prgtype         Accessory?
  94.         beq     cont_prg        Skip this bit if not
  95.  
  96.         pea     accname(pc)     Name to appear on Desk menu
  97.         move.l  appid,-(sp)     and application ID
  98.         jsr     menu_register   put us on the Desk menu
  99.         addq.l  #8,sp           tidy stack and ignore errors
  100.         move.w  d0,accid        retrieve the accessory ID
  101.         
  102.         
  103. *       Set up evnt_mesag call
  104.  
  105. loop:
  106.         clr.l   -(sp)
  107.         clr.l   -(sp)           Set arrow mouse
  108.         jsr     graf_mouse
  109.         addq.l  #8,sp
  110.  
  111.         move.l  #2,-(sp)        END_MCTRL
  112.         jsr     wind_update     now
  113.         addq.l  #4,sp           tidy
  114.         
  115.         tst.l   prgtype         Accessory?
  116.         bne     acc_loop        Skip this if so
  117.  
  118.         jsr     appl_exit       Clear up AES
  119.         move.w  #0,-(sp)
  120.         trap    #dos            Terminate
  121.  
  122. acc_loop:
  123.         pea     msgbuff(pc)     message buffer loc
  124.         jsr     evnt_mesag      wait for message event
  125.         addq.l  #4,sp           tidy stack
  126.  
  127.         lea     msgbuff(pc),a0  get message buffer
  128.         move    (a0),d0         retrieve message code
  129.         cmpi.w  #40,d0          is it 'Open accessory' message?
  130.         bne     loop            jif not
  131.  
  132.         move.w  8(a0),d0        get accessory that was opened
  133.         cmp.w   accid,d0        is it us?
  134.         bne     loop            jif not so
  135.  
  136. *       We have been selected !
  137.  
  138. cont_prg:
  139.         move.l  #3,-(sp)        BEG_MCTRL
  140.         jsr     wind_update     now
  141.         addq.l  #4,sp           tidy
  142.  
  143.         lea     infosave(pc),a1 Info save area
  144.         move.l  shared,a0
  145.         moveq   #6,d0           move 7 long words
  146.         bsr     move_them       In case "Cancel" is clicked
  147.         bsr     reconfig        Set up dialogue correctly
  148.         clr.l   -(sp)
  149.         move.l  #3,-(sp)        Set pointed hand mouse
  150.         jsr     graf_mouse
  151.         addq.l  #8,sp
  152.  
  153. main_loop:
  154.         bsr     handle_dialogue
  155. dloop:
  156.         bsr     do_form         Let AES handle form
  157. *       Object selected is returned in d0
  158.         and.w   #$7FFF,d0       Ensure d0 is +ve
  159.         cmp.w   #STARON,d0      Stars ON button
  160.         beq     stars_on
  161.         cmp.w   #STAROFF,d0     Stars off button
  162.         beq     stars_off
  163.  
  164.         bsr     deselect_object All other buttons deselected straight away
  165.         cmp.w   #TITLE,d0
  166.         beq     show_about      Show author info.
  167.         cmp.w   #OFF,d0         Turn off blank
  168.         beq     blank_off       jif so
  169.         cmp.w   #OK,d0          Finished?
  170.         beq     ok              set up blanking
  171.         cmp.w   #BNOW,d0        Blank now?
  172.         beq     blank_now
  173.         cmp.w   #TEST,d0        Test star speed?
  174.         beq     test_stars
  175.         cmp.w   #CANCEL,d0      Cancel
  176.         beq     use_old
  177.         cmp.w   #SDN,d0         - secs
  178.         beq     decsecs
  179.         cmp.w   #SUP,d0         + secs
  180.         beq     incsecs
  181.         cmp.w   #MDN,d0         - mins
  182.         beq     decmins
  183.         cmp.w   #MUP,d0         + mins
  184.         beq     incmins
  185.         cmp.w   #DLDEC,d0       Decrease star delay
  186.         beq     d_dec
  187.         cmp.w   #DLINC,d0       Increase star delay
  188.         beq     d_inc
  189.         cmp.w   #LOAD,d0
  190.         beq     load_config
  191.         cmp.w   #SAVE,d0
  192.         beq     save_config
  193.         bra     dloop           and continue
  194.  
  195.  
  196. show_about:
  197.         move.l  abouttree,treeaddr Show about dialogue
  198.         bsr     handle_dialogue
  199.         bsr     do_form
  200.         bsr     deselect_object
  201.         bsr     remove_dialogue
  202.         move.l  maintree,treeaddr Back to main dialogue
  203.         bra     main_loop
  204.  
  205. ok      move.l  shared,a6
  206.         move.w  #1,active(a6)   Blanker active
  207.         bra     recalc
  208.  
  209. inst_crit:
  210.         move.w  _bootdev,d0     Determine boot device
  211.         add.b   #"A",d0         Turn into a drive name
  212.         move.b  d0,save_name    Insert in info file name 
  213.         rts
  214.  
  215. save_config:
  216.         bsr     tick_cal
  217.         move.l  shared,a6
  218.         move.w  #1,active(a6)   Install current defaults
  219.  
  220.         move.w  #0,-(sp)        Ordinary file
  221.         pea     save_name(pc)   Name of file
  222.         move.w  #$3c,-(sp)
  223.         trap    #dos            Create it
  224.         addq.l  #8,sp
  225.         
  226.         tst.w   d0              Error?
  227.         bmi     s_err           Abort if so
  228.         beq     s_err
  229.  
  230.         move.w  d0,save_h       Make note of handle returned
  231.  
  232.         move.l  shared,-(sp)    Start of buffer to save
  233.         move.l  #savelen,-(sp)  Length of save info
  234.         move.w  save_h,-(sp)    File handle
  235.         move.w  #$40,-(sp)      Fwrite
  236.         trap    #dos
  237.         lea.l   12(sp),sp       tidy stack
  238.         tst.l   d0
  239.         bmi     s_err           Save error
  240.         cmp.l   #savelen,d0     All information saved?
  241.         bne     s_err_r         abort if not
  242.         
  243.         move.w  save_h,-(sp)    Close file
  244.         move.w  #$3E,-(sp)
  245.         trap    #dos
  246.         addq.l  #4,sp           tidy
  247.         tst.w   d0              Error?
  248.         bmi     s_err
  249.         
  250.         pea     save_ok(pc)     File error alert
  251.         move.l  #1,-(sp)        Cancel is default
  252.         jsr     form_alert
  253.         addq.l  #8,sp           tidy
  254.         
  255.         move.w  #MAIN,d0        Redraw whole dialogue
  256.         bsr     redraw
  257.         bra     dloop           Continue dialogue loop
  258.  
  259. s_err_r:
  260. *       Get here when an error occurs, but file is still open
  261.         
  262.         bsr     open_file_err
  263.         pea     save_name(pc)   Name of file
  264.         move.w  #$41,-(sp)      Delete it
  265.         trap    #dos
  266.         addq.l  #6,sp           tidy
  267.  
  268. s_err
  269.         bsr     closed_file_err
  270.         bra     dloop
  271.  
  272.  
  273. load_config:
  274.         bsr     file_load       Try to load file
  275.         move.w  #MAIN,d0        Redraw the lot
  276.         bsr     redraw
  277.         bra     dloop           Continue dialogue interaction
  278.  
  279. file_load:
  280.         move.w  #1,-(sp)        Open file for reading
  281.         pea     save_name(pc)
  282.         move.w  #$3D,-(sp)
  283.         trap    #dos
  284.         addq.l  #8,sp
  285.         
  286.         tst.w   d0              Errors?
  287.         bmi     l_err           Handle if so
  288.         move.w  d0,save_h       Make note of handle returned
  289.         move.l  shared,-(sp)    Start of buffer to load
  290.         move.l  #savelen,-(sp)  Length of load info
  291.         move.w  save_h,-(sp)    File handle
  292.         move.w  #$3F,-(sp)      Fread
  293.         trap    #dos
  294.         lea.l   12(sp),sp       tidy stack
  295.         tst.l   d0
  296.         bmi     l_err_r         load error
  297.         cmp.l   #savelen,d0     All information saved?
  298.         bne     l_err_r         abort if not
  299.         
  300.         move.w  save_h,-(sp)    Close file
  301.         move.w  #$3E,-(sp)
  302.         trap    #dos
  303.         addq.l  #4,sp           tidy
  304.         tst.w   d0              Error?
  305.         bmi     l_err_r
  306.  
  307. reconfig:
  308.         move.w  #STARON,d0      Stars on button
  309.         bsr     select_object
  310.         move.w  #STAROFF,d0     Stars off button
  311.         bsr     deselect_object
  312.         lea     enable_object(pc),a5
  313.         bsr     delay_set       Enable all star delay buttons
  314.         bsr     delay_remake
  315.         bsr     time_remake
  316.         bsr     tick_cal
  317.         move.l  shared,a6
  318.         move.w  star_disp(a6),d0 Star display flag
  319.         bne     stars_are_off
  320.         rts
  321.  
  322. stars_are_off:
  323.         move.w  #STAROFF,d0
  324.         bsr     select_object
  325.         move.w  #STARON,d0
  326.         bsr     deselect_object
  327.         lea     disable_object(pc),a5
  328.         bsr     delay_set
  329.         rts
  330.  
  331. l_err
  332. *       Get here if file open failed
  333.  
  334.         bsr     closed_file_err   Tell user
  335.         bra     install_defaults
  336.  
  337. l_err_r
  338. *       Get here if file read failed
  339.         bsr     open_file_err   Tell user
  340.  
  341. install_defaults:
  342.         move.l  shared,a6
  343.         move.b  #2,mins(a6)     Default 2 mins
  344.         move.b  #0,secs(a6)     0 seconds
  345.         move.l  #24000,timeout(a6)  Equivalent in 5ms units
  346.         move.w  #14,star_delay(a6)
  347.         move.w  #1,active(a6)   Default is to be active
  348.         clr.w   star_disp(a6)   With stars on
  349.         clr.w   lselect(a6)     No last button
  350.         bra     reconfig
  351.  
  352. open_file_err:
  353.         move.w  save_h,-(sp)    Close save file
  354.         move.w  #$3E,-(sp)
  355.         trap    #dos
  356.         addq.l  #4,sp           ignore errors
  357.  
  358. closed_file_err:
  359. *       Get here when file error occurs, but file is not open
  360.  
  361.         pea     save_error(pc)  File error alert
  362.         move.l  #1,-(sp)        Cancel is default
  363.         jsr     form_alert
  364.         addq.l  #8,sp           tidy
  365.         rts
  366.  
  367. test_stars:
  368.         bsr     tick_cal
  369.         move.l  shared,a6
  370.         move.w  #1,active(a6)
  371.         clr.l   counter(a6)     Should blank screen now
  372.         move.w  #TEST,d0
  373.         bsr     redraw          Redraw button
  374.         bra     dloop
  375.  
  376. blank_now:
  377.         bsr     tick_cal        Calculate ticks
  378.         bsr     remove_dialogue
  379.         move.l  shared,a6
  380.         move.w  #1,active(a6)
  381.         clr.l   counter(a6)     Should blank screen now
  382.         bra     loop
  383.  
  384. use_old
  385. *       Cancel clicked
  386.         lea     infosave(pc),a0
  387.         move.l  shared,a1
  388.         moveq   #6,d0           Move 7 longs
  389.         bsr     move_them
  390.         bsr     remove_dialogue
  391.         bra     loop        
  392.  
  393. move_them:
  394.         move.l  (a0)+,(a1)+
  395.         dbf     d0,move_them
  396.         rts
  397.  
  398. stars_on:
  399.         move.l  shared,a6
  400.         clr.w   star_disp(a6)   Zap star display flag
  401.         lea     enable_object(pc),a5
  402.         bsr     delay_set       Set status of buttons
  403.  
  404. rdrw:
  405.         move.w  #DUPDATE,d0     Object to redraw (IBOX containing above)
  406.         bsr     redraw
  407.         bra     dloop
  408.  
  409. stars_off:
  410.         move.l  shared,a6
  411.         bset    #3,star_disp(a6) Set star disp flag
  412.         lea     disable_object(pc),a5
  413.         bsr     delay_set
  414.         bra     rdrw
  415.  
  416. delay_set:
  417. *       A5 holds address of routine to call for each object
  418.         move.w  #DLDEC,d0       Enable various GEM objects
  419.         jsr     (a5)
  420.         move.w  #DLINC,d0
  421.         jsr     (a5)
  422.         move.w  #DELAY,d0
  423.         jsr     (a5)
  424.         move.w  #TEST,d0
  425.         jsr     (a5)
  426.         rts
  427.  
  428. d_dec
  429.         bsr     object_enabled
  430.         bne     dloop           If object is disabled, ignore request
  431.         move.l  shared,a6
  432.         move.w  star_delay(a6),d0   get delay
  433.         subq.w  #1,d0           Subtract one
  434.         beq     dloop           If zero, ignore request
  435.         move.w  d0,star_delay(a6) Otherwise, resave
  436.         bra     d_redraw        and display
  437.  
  438. d_inc
  439.         bsr     object_enabled  Object disabled?
  440.         bne     dloop           If so, ignore request
  441.         move.l  shared,a6
  442.         move.w  star_delay(a6),d0   get delay
  443.         addq.w  #1,d0           Add one
  444.         cmp.w   #100,d0         Upper limit ?
  445.         beq     dloop           Ignore request if so
  446.         move.w  d0,star_delay(a6)   Otherwise resave
  447. *                               and fall through to ...
  448.  
  449. d_redraw
  450.         bsr     delay_remake    Convert to decimal string
  451.         move.w  #DELAY,d0       and redraw
  452.         bsr     redraw
  453.         bra     dloop           
  454.         
  455. delay_remake:
  456.         move.l  shared,a6
  457.         move.w  star_delay(a6),d0 Get delay value
  458.         move.l  tdelay,a0       Address of delay string
  459.         bsr     makenum         convert d0 to number
  460.         clr.b   (a0)+           Zero terminate
  461.         rts
  462.         
  463. decsecs:
  464.         move.l  shared,a6
  465.         move.b  secs(a6),d0     Get seconds
  466.         tst.b   d0              Seconds=0 ?
  467.         beq     prop_d          Propogate if so
  468.         subq.b  #1,d0           Decrement seconds
  469.         subq.b  #1,secs(a6)
  470.         tst.b   mins(a6)        Minutes zero as well?
  471.         beq     chk_secs
  472. touch_s move.b  d0,secs(a6)     Save it
  473.         bsr     touch           Redisplay
  474.         bra     dloop
  475.  
  476. prop_d
  477.         tst.b   mins(a6)        Minutes=0?
  478.         beq     touch_s         If so, can't propogate
  479.         move.b  #59,secs(a6)    59 seconds
  480.         bra     decmins
  481.  
  482. incsecs
  483.         move.l  shared,a6
  484.         move.b  secs(a6),d0     Get seconds
  485.         addq.b  #1,d0           increment
  486.         cmp.b   #60,d0          60 secs?
  487.         bhs     prop            handle it
  488.         bra     touch_s         save secs + redraw
  489.  
  490. prop    clr.b   secs(a6)        Zero seconds
  491.         bra     incmins         
  492.  
  493. decmins move.l  shared,a6
  494.         move.b  mins(a6),d0     Get minutes
  495.         tst.b   d0              Zero minutes?
  496.         beq     touch_m
  497.         subq.b  #1,d0           Decrement mins
  498.         beq     chk_secs        If zero minutes, check seconds too
  499. touch_m move.b  d0,mins(a6)
  500.         bsr     touch
  501.         bra     dloop
  502.  
  503. incmins:
  504.         move.l  shared,a6
  505.         move.b  mins(a6),d0     Get minutes
  506.         cmp.b   #99,d0          99 mins
  507.         bhs     touch_m         Can't increment if so
  508.         addq.b  #1,d0           Else increment
  509.         bra     touch_m
  510.  
  511. chk_secs
  512.         clr.b   d0              Zero minutes
  513.         move.b  secs(a6),d1     Get seconds
  514.         cmp.b   #base_secs,d1   Below 10 seconds?
  515.         blo     set_10          sort it out if so
  516.         bra     touch_m         Otherwise, all OK
  517.  
  518. set_10
  519.         move.b  #base_secs,secs(a6) Set seconds to one
  520.         bra     touch_m
  521.  
  522. time_remake:
  523.         clr.l   d0
  524.         move.l  shared,a6
  525.         move.b  secs(a6),d0
  526.         move.l  tsecs,a0        Get address of seconds display
  527.         bsr     makenum         Convert to number
  528.         clr.b   (a0)            Zero terminate
  529.         clr.l   d0
  530.         move.b  mins(a6),d0
  531.         move.l  tmins,a0
  532.         bsr     makenum
  533.         clr.b   (a0)
  534.         rts
  535.        
  536. touch:
  537.         bsr     time_remake 
  538.         move.w  #UPDATE,d0      Object to start redrawing from
  539.  
  540. *       Fall through to ...
  541.  
  542. redraw:
  543.  
  544. *       Entered with the object to start redrawing from in d0
  545.  
  546.         move.w  d0,-(sp)        Save d0
  547.         move.w  #37,-(sp)       Vsync
  548.         trap    #xbios
  549.         addq.l  #2,sp           tidy
  550.         move.w  (sp)+,d0        Get d0 back
  551.  
  552. *       Re-display seconds+mins + return
  553.         move.l  h,-(sp)
  554.         move.l  w,-(sp)
  555.         move.l  y,-(sp)
  556.         move.l  x,-(sp)
  557.         move.l  #2,-(sp)        Depth of two
  558.         move.l  d0,-(sp)        Update object
  559.         move.l  treeaddr,-(sp)  Address of tree
  560.         jsr     objc_draw
  561.         lea     28(sp),sp       tidy stack
  562.         rts
  563.  
  564. blank_off
  565.         move.l  shared,a6
  566.         clr.w   active(a6)
  567.         bsr     remove_dialogue
  568.         bra     loop
  569.         
  570. recalc:
  571.         bsr     tick_cal
  572.         bsr     remove_dialogue
  573.         bra     loop            All done
  574.  
  575. tick_cal:
  576.         move.l  shared,a6
  577.         clr.l   d0              Ensure d0 zero
  578.         move.b  mins(a6),d0     Number of minutes
  579.         mulu    #60,d0          Convert to seconds
  580.         move.b  secs(a6),d1     get seconds
  581.         ext.w   d1              make into a word
  582.         add.w   d1,d0           Add seconds
  583.         mulu    #200,d0         convert to timer ticks
  584.         move.l  d0,timeout(a6)  save it
  585. *                               Fall through to
  586.  
  587. activity:
  588.         move.l  shared,a6
  589.         move.l  timeout(a6),counter(a6)  Reset the counter
  590.         rts
  591.  
  592. noshared
  593.         pea     noprgpart(pc)   No PRG part!
  594.         move.l  #1,-(sp)        Default button
  595.         jsr     form_alert
  596.         addq.l  #8,sp
  597.         bra     fatal           Can't continue
  598.  
  599. no_rsc:
  600.         pea     rsrc_errmsg(pc)
  601.         move.l  #1,-(sp)
  602.         jsr     form_alert      Tell user there's no RSC
  603.         addq.l  #8,sp
  604.  
  605. fatal:        
  606.         tst.l   prgtype
  607.         beq     loop            If program, terminate
  608.         
  609. *       For accessory, fall through to endless loop
  610.         
  611. endless pea     msgbuff(pc)
  612.         jsr     evnt_mesag      Call evnt_mesag
  613.         addq.l  #4,sp
  614.         bra     endless         endlessly.
  615.  
  616. *       This is the only safe way to terminate a desk accessory
  617.  
  618. calcaddr:
  619.         move.l  treeaddr,a0     Get address of tree
  620.         moveq   #ob_size,d1     Size of each object
  621.         mulu    d1,d0           Calcuate offset into tree
  622.         lea     12(a0,d0.w),a0  Get address of pointer to TEDINFO
  623.         move.l  (a0),a0         Get address of TEDINFO
  624.         move.l  (a0),d0         Get address of text from TEDINFO
  625.         rts                     All done
  626.  
  627. handle_dialogue:
  628.         pea     h+2             width, height, x and y coords
  629.         pea     w+2             of dialogue box
  630.         pea     y+2
  631.         pea     x+2
  632.         move.l  treeaddr,-(sp)  Address of tree
  633.         jsr     form_center     centre form
  634.         lea.l   20(sp),sp       tidy stack
  635.  
  636.         move.l  h,-(sp)         Final height,
  637.         move.l  w,-(sp)         width,
  638.         move.l  y,-(sp)         y,
  639.         move.l  x,-(sp)         and x
  640.         move.l  #10,-(sp)        From unit height
  641.         move.l  #10,-(sp)        and width,
  642.         move.l  #10,-(sp)        top left hand start
  643.         move.l  #10,-(sp)
  644.         jsr     graf_growbox    Do it
  645.         lea     32(sp),sp       tidy stack
  646.  
  647.         move.l  h,-(sp)         Final height,
  648.         move.l  w,-(sp)         width,
  649.         move.l  y,-(sp)         y,
  650.         move.l  x,-(sp)         and x
  651.         move.l  h,-(sp)         Final height,
  652.         move.l  w,-(sp)         width,
  653.         move.l  y,-(sp)         y,
  654.         move.l  x,-(sp)         and x
  655.         move.l  #0,-(sp)        FMD_START
  656.         jsr     form_dial       Reserve screen portion
  657.         lea     36(sp),sp       tidy stack
  658.  
  659.         move.l  h,-(sp)         Final height,
  660.         move.l  w,-(sp)         width,
  661.         move.l  y,-(sp)         y,
  662.         move.l  x,-(sp)         and x
  663.         move.l  #4,-(sp)        Depth of 4
  664.         move.l  #0,-(sp)        Start with object zero
  665.         move.l  treeaddr,-(sp)  Address of tree
  666.         jsr     objc_draw       Display our form
  667.         lea     28(sp),sp       tidy stack
  668.         rts
  669.  
  670. do_form:
  671.         clr.l   -(sp)           No editable objects
  672.         move.l  treeaddr,-(sp)  Address of tree
  673.         jsr     form_do         interact with form
  674.         addq.l  #8,sp           tidy
  675.         rts
  676.  
  677. deselect_object:
  678.         move.l  d0,-(sp)        Save d0
  679.         bsr     get_button_status
  680.         bclr    #0,d1           Deselect object
  681.         move.w  d1,10(a0,d0.w)  and save
  682.         move.l  (sp)+,d0        Get d0 back
  683.         rts
  684.  
  685. select_object:
  686.         move.l  d0,-(sp)        Save d0
  687.         bsr     get_button_status
  688.         bset    #0,d1           Select object
  689.         move.w  d1,10(a0,d0.w)  and save
  690.         move.l  (sp)+,d0        Get d0 back
  691.         rts
  692.         
  693. get_button_status:
  694.         moveq   #ob_size,d1     Size of objects
  695.         move.l  treeaddr,a0     Start of form
  696.         mulu    d1,d0           Calc offset of object
  697.         move.w  10(a0,d0.w),d1  Get object status
  698.         rts
  699.  
  700. remove_dialogue:
  701.         move.l  h,-(sp)         From height,
  702.         move.l  w,-(sp)         width,
  703.         move.l  y,-(sp)         y,
  704.         move.l  x,-(sp)         and x
  705.         move.l  #10,-(sp)        To unit height
  706.         move.l  #10,-(sp)        and width,
  707.         move.l  #10,-(sp)        top left hand start
  708.         move.l  #10,-(sp)
  709.         jsr     graf_shrinkbox  Do it
  710.         lea     32(sp),sp       tidy stack
  711.  
  712.  
  713.         move.l  h,-(sp)         Final height,
  714.         move.l  w,-(sp)         width,
  715.         move.l  y,-(sp)         y,
  716.         move.l  x,-(sp)         and x
  717.         move.l  h,-(sp)         Final height,
  718.         move.l  w,-(sp)         width,
  719.         move.l  y,-(sp)         y,
  720.         move.l  x,-(sp)         and x
  721.         move.l  #3,-(sp)        FMD_FINISH
  722.         jsr     form_dial       Reserve screen portion
  723.         lea     36(sp),sp       tidy stack
  724.  
  725.         rts                     All done!
  726.                  
  727. enable_object:
  728.         bsr     get_button_status
  729.         bclr    #3,d1           Clear disabled bit
  730.         move.w  d1,10(a0,d0.w)
  731.         rts
  732.  
  733. disable_object:
  734.         bsr     get_button_status
  735.         bset    #3,d1
  736.         move.w  d1,10(a0,d0.w)
  737.         rts
  738.         
  739. object_enabled:
  740. *       GEM object in d0 enabled?
  741.         moveq   #ob_size,d1     Size of objects
  742.         move.l  treeaddr,a0     Start of form
  743.         mulu    d1,d0           Calc offset of object
  744.         move.w  10(a0,d0.w),d1  Get object status
  745.         btst    #3,d1           Disabled?
  746.         rts
  747.  
  748.  
  749. makenum:        
  750.  
  751. *       Convert word in d0 into string of decimal digits. A0 should
  752. *       point to the buffer the digits are to be placed in. Afterwards
  753. *       a0 will point to the next free location in the buffer.
  754.  
  755. *       d0,d1,d2,a0 corrupted
  756.  
  757.         tst.w   d0              Check for zero
  758.         beq     zero            special case
  759.         move.l  #100000,d1      Start with 100000
  760. 3$      divu    #10,d1          divide by ten
  761.         cmp.w   d1,d0           is d0<d1?
  762.         blo     3$              jifso
  763. 1$      bsr     f_digit         convert to digit & store
  764.         cmp.w   #1,d1           was that the units just converted?
  765.         beq     2$              if so, we're done
  766.         divu    #10,d1          next digit
  767.         bra     1$              and do it all again
  768.         
  769. 2$      rts                     return
  770.  
  771. zero    moveq.l #1,d1           divisor
  772.         bra     f_digit         convert to digit & return
  773.  
  774. f_digit:
  775.         move.b  #"0",d2         set d2 digit to 0
  776. 1$      cmp.w   d1,d0           is d0 smaller than d1?
  777.         blo     cvted           if so, this digit converted
  778.         sub.w   d1,d0           take d1 from d0
  779.         addq.l  #1,d2           Increment digit
  780.         bra     1$              do again
  781.         
  782. cvted:  move.b  d2,(a0)+        stuff in buffer
  783.         rts                     return
  784.  
  785. load_rsrc:
  786.         clr.l   treeaddr        Default to failure
  787.         pea     rsrc_name(pc)   filename of our resource
  788.         jsr     rsrc_load       Try to load it
  789.         addq.l  #4,sp           tidy stack
  790.         tst.w   d0              Error
  791.         beq     rerror          jif so
  792.         
  793.         pea     maintree(pc)
  794.         move.l  #MAIN,-(sp)     MAIN dialogue box
  795.         move.l  #0,-(sp)        It's a tree
  796.         jsr     rsrc_gaddr      get address
  797.         lea.l   12(sp),sp       tidy stack
  798.         move.l  maintree,treeaddr
  799.         
  800.         pea     abouttree(pc)   Address of about tree
  801.         move.l  #ABOUT,-(sp)
  802.         move.l  #0,-(sp)        It's a tree
  803.         jsr     rsrc_gaddr      Get address
  804.         lea.l   12(sp),sp       tidy stack
  805.         
  806.         
  807.         move.l  shared,a6       Pointer to shared memory
  808.         move.w  #MINS,d0        Minutes index
  809.         bsr     calcaddr        Calculate addr of TEDINFO string
  810.         move.l  d0,tmins        save pointer
  811.         move.l  d0,a0
  812.         clr.w   d0
  813.         move.b  mins(a6),d0
  814.         bsr     makenum
  815.         clr.b   (a0)
  816.         
  817.         move.w  #SECS,d0        Seconds index
  818.         bsr     calcaddr        Calculate addr of TEDINFO
  819.         move.l  d0,tsecs        save pointer
  820.         move.l  d0,a0
  821.         clr.w   d0
  822.         move.b  secs(a6),d0
  823.         bsr     makenum
  824.         clr.b   (a0)
  825.         
  826.         move.w  #DELAY,d0       Delay counter
  827.         bsr     calcaddr        find TEDINFO address
  828.         move.l  d0,tdelay       save
  829.         move.l  d0,a0
  830.         clr.w   d0
  831.         move.w  star_delay(a6),d0
  832.         bsr     makenum
  833.         clr.b   (a0)
  834.         
  835.         move.w  #STARON,lselect(a6)
  836.         rts                     All done
  837.  
  838. rerror  clr.l   treeaddr        Signal RSC load fail
  839.         rts
  840.         
  841. find_cookie:
  842. *       Search cookie jar to find our shared memory
  843.         clr.l   shared          Default to not found
  844.         pea     search_jar(pc)
  845.         move.w  #supexec,-(sp)
  846.         trap    #xbios
  847.         addq.l  #6,sp
  848.         rts
  849.         
  850. search_jar:
  851.         move.l  _p_cookies,d0   Get pointer to cookie jar
  852.         beq     noshare         If no jar, no shared memory
  853.         move.l  d0,a0
  854. check_cookie:
  855.         move.l  (a0)+,d0
  856.         move.l  (a0)+,d1
  857.         tst.l   d0
  858.         beq     noshare         If end of jar found, no shared mem
  859.         cmp.l   #ourcookie,d0      Found our cookie?
  860.         bne     check_cookie
  861.         move.l  d1,shared       Found our shared memory
  862. noshare:
  863.         rts
  864.         
  865.         
  866. *************************************************************************
  867. ***                            DATA SECTION                           ***
  868. *************************************************************************
  869.  
  870. * External GEM references for the GEMLIB.BIN file
  871.  
  872.         XREF    appl_init,appl_exit,menu_register,evnt_mesag
  873.         XREF    form_do,form_dial,objc_draw,wind_update
  874.         XREF    rsrc_load,rsrc_gaddr,form_center,graf_mouse
  875.         XREF    graf_growbox,graf_shrinkbox,form_alert
  876.  
  877. accname dc.b    '  ST Blank V2.0.1 ',0         Name for desk menu 
  878. rsrc_name
  879.         dc.b    'STBLANK.RSC',0
  880. save_name:
  881.         dc.b    'A:\STBLANK.INF',0
  882. save_h:
  883.         ds.w    1                               File handle for save/load
  884. save_error:
  885.         dc.b    '[3][ |      ST Blank error:      |'
  886.         dc.b          'Error accessing config file]'
  887.         dc.b          '[ OK ]',0
  888. rsrc_errmsg:
  889.         dc.b    '[3][ |      ST Blank error:      |'
  890.         dc.b          '  Could not load RSC file  ]'
  891.         dc.b          '[ Shame! ]',0
  892. noprgpart:
  893.         dc.b    '[3][ | The memory resident AUTO  |'
  894.         dc.b          'folder part of ST Blank has|'
  895.         dc.b          '    not been installed.    ]'
  896.         dc.b          '[ Shame! ]',0
  897. save_ok dc.b    '[1][ |   Current configuration   |'
  898.         dc.b          '    installed and saved.   ]'
  899.         dc.b          '[ OK ]',0
  900.  
  901. appid   ds.l    1       Application ID
  902. accid   ds.w    1       Desk accessory ID tag
  903. msgbuff ds.w    16      Message buffer
  904.  
  905. shared  ds.l    1       Pointer to shared data
  906. prgtype ds.l    1       Program type
  907.  
  908. base_secs equ   1       Smallest no. of seconds to allow before blanking
  909.  
  910. * Shared data offsets
  911. mins    equ     0       No. of minutes
  912. secs    equ     1       and secs to blankout
  913. timeout equ     2       Time constant for countdown, set by user
  914. star_delay equ  6       Delay as displayed to user
  915. active  equ     8       <>0 if blanking enabled
  916. filler  equ     10      Filler for backward compatibility
  917. star_disp equ   12      0 = Display stars
  918. *                       n = Don't display stars
  919. lselect equ     14      Last radio button selected
  920.  
  921. counter equ     16      Running countdown decremented by 200Hz interrupt
  922. timer   equ     20      Counter incremented by 200Hz interrupt
  923. khandl  equ     22      Address of IKBD interrupt vector
  924. sp_list equ     26      List of pointers to pointers of star coordinates
  925.  
  926. omins   ds.b    1       Saved versions of mins and secs, in case
  927. osecs   ds.b    1       of cancel by user
  928.  
  929. ierror  ds.w    1       Initialisation error flag
  930.  
  931. tmins   ds.l    1       Pointer to minutes display
  932. tsecs   ds.l    1       Pointer to seconds display
  933.  
  934. tdelay  ds.l    1       Pointer to delay text display
  935. odelay  dc.w    29      Place to save star_delay in case of cancel
  936.  
  937. maintree ds.l   1       Main tree
  938. abouttree ds.l  1       About tree
  939. treeaddr ds.l   1       pointer to object tree
  940. x       dc.l    0       x,y and size of dialogue box
  941. y       dc.l    0
  942. w       dc.l    0
  943. h       dc.l    0
  944.  
  945.  
  946. infosave ds.l   13      13 word save area
  947.         ds.l    55
  948. USTK    ds.l    1               Stack of 56 long_words
  949.  
  950.         END
  951.  
  952.