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