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

  1. *****************************************************************
  2. * General purpose screen blanking desk accessory - PRG part     *
  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/22                                    *
  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, 020, 030 and 040 processors   *
  46. *****************************************************************
  47. * 2.0.0 * 21/09/91 * Splitting of ST Blank into resident .PRG   *
  48. * and configuring ACC/PRG                                       *
  49. *****************************************************************
  50. * 2.0.1 * 22/01/93 * Fix bug that caused .PRG part to crash if  *
  51. * .INF file not found                                           *
  52. *****************************************************************
  53.  
  54.         INCLUDE "STBLANK.I"
  55.  
  56. *****************************************************************
  57. *             The "Permanent" code section                      *
  58. *****************************************************************
  59.  
  60. start:
  61.         bra     GO              Call the installation code
  62.  
  63. ******************** Interrupt handlers *************************
  64. *       IKBD interrupt handler
  65.  
  66. okhand  equ     *+8             Address of "old" IKBD handler
  67.         xblock                  insert XBRA block
  68.  
  69. khandler:
  70.         movem.l d0/a0,-(sp)     save regs
  71.         lea     KACIA,a0        Get address of keyboard ACIA
  72.         move.b  (a0),d0         Get ACIA status
  73.         btst    #7,d0           Interrupt request?
  74.         beq     not_kb          No
  75.         btst    #0,d0           Receiver buffer full?
  76.         beq     not_kb          No
  77.         
  78.         bsr     activity        There was keyboard activity
  79.  
  80. not_kb  movem.l (sp)+,d0/a0     retrieve regs
  81.         move.l  okhand,-(sp)
  82.         rts                     exec old routine
  83.  
  84.  
  85. *       New 200Hz interrupt handler
  86.  
  87. oh200   equ     *+8             To hold old 200Hz vector
  88.         xblock                  XBRA block
  89.  
  90. hz_200:
  91.         addq.w  #1,timer        Increment our timer
  92.         tst.w   active          Is blanker active?
  93.         beq     q_h200          quit if not
  94.  
  95.         tst.l   counter         Is countdown zero?
  96.         beq     q_h200          quit if is
  97.  
  98.         subq.l  #1,counter      else decrement counter
  99.  
  100. q_h200  
  101.         move.l  oh200,-(sp)
  102.         rts
  103.  
  104. *       BIOS TRAP vector handler
  105.  
  106. oldbios equ     *+8             To hold "old" BIOS vector
  107.         xblock                  XBRA header
  108.  
  109. bios:
  110.         move.l  a0,-(sp)        Save a0
  111.         btst    #13,4(sp)       Called from super mode?
  112.         beq     1$              jif not
  113.         
  114. *       Yes, called from SUPER
  115.  
  116.         move.l  sp,a0           a0=SSP+10
  117.         lea.l   10(a0),a0       (first parm is at SSP+10)
  118.         tst.w   longframe       68000 processor?
  119.         beq     2$              Fine if so
  120.         lea.l   2(a0),a0        Account for extra word
  121.         bra     2$
  122.  
  123. *       No, called from USER
  124.  
  125. 1$      move.l  USP,a0          USP points to first parameter
  126.  
  127. 2$      cmp.w   #Bconout,(a0)   Bconout function call?
  128.         bne     not_op          ignore if not
  129.         cmp.w   #ikbd,2(a0)     IKBD device
  130.         beq     not_op          Skip if IKBD output
  131.  
  132. op_act  bsr     activity        There was some activity
  133.  
  134. not_op  move.l  (sp)+,a0        Retreive a0
  135.         move.l  oldbios,-(sp)   stack old BIOS address
  136.         rts                     and call it.
  137.  
  138. activity:
  139.         move.l  timeout,counter  Reset the counter
  140.  
  141. *       Quick hack:
  142. *        addq.l  #1,$F8000       Show activity
  143. *       For testing!
  144.         rts
  145.  
  146.  
  147. *       Vertical blank interrupt handler
  148.  
  149.         xblock                  XBRA block
  150. blnk_vbl:
  151.         tst.w   active          Blanker active?
  152.         beq     q_vbl           jif not
  153.         tst.w   flock           Floppies active?
  154.         beq     tst_blnk        If not, check for blanking
  155. q_vbl   rts
  156.         
  157. tst_blnk
  158.         tst.l   counter         Is counter=0
  159.         beq     wait            If so, blank screen
  160.         bra     q_vbl
  161.  
  162. wait:
  163.         bsr     savscreen       Save screen
  164.         tst.w   star_disp       Stars enabled?
  165.         bne     3$
  166.         bsr     starsetup       prepare stars
  167. 1$      tst.w   star_disp       Stars On flag
  168.         bne     3$              If not, no stars
  169.         bsr     dostars         Do one frame of stars
  170. 3$      tst.l   counter         Check counter
  171.         beq     1$              if zero, keep doing stars
  172. 2$      bsr     restscreen      restore screen
  173.         move.l  timeout,counter restore countdown
  174.         bra     q_vbl           and continue normal processing
  175.  
  176. savscreen:
  177.         move.l  #membuff,a0     Get address of memory buffer
  178.         lea.l   col_pal,a1      Address of palette registers
  179.         moveq   #1,d0           two 16 byte blocks to a palette
  180.         bsr     cpy
  181.  
  182. colour  move.w  #$0FFF,col_pal+2 Colour 1=white (FFF for expanded palettes)
  183.  
  184. sav_s   move.l  _v_bas_ad,a1    and address of screen memory   
  185.         move.w  #1999,d0        2000 16 byte blocks to a screen
  186.         bsr     cpy
  187.         rts
  188.  
  189.         
  190. cpy     move.l  (a1),(a0)+      copy word
  191.         clr.l   (a1)+           and clear screen at same time
  192.         move.l  (a1),(a0)+
  193.         clr.l   (a1)+
  194.         move.l  (a1),(a0)+
  195.         clr.l   (a1)+
  196.         move.l  (a1),(a0)+
  197.         clr.l   (a1)+
  198.         dbf     d0,cpy          Until done
  199.         rts
  200.  
  201. restscreen:
  202.         lea     col_pal,a0      Get address of colour palette
  203.         move.l  #membuff,a1     and address of buffer
  204.         moveq   #1,d0           2 16 byte blocks in a palette
  205.         bsr     cpy             Restore palette
  206.         
  207.         move.l  _v_bas_ad,a0    Address of screen
  208.         move.w  #1999,d0        2000 16 byte blocks to a screen
  209.         bsr     cpy             Restore screen
  210.         rts
  211.  
  212. starsetup:
  213.         lea     sp_list(pc),a0  Initialise star pointer
  214.         move.l  #s1,(a0)+
  215.         move.l  #s2+8,(a0)+
  216.         move.l  #s3+16,(a0)+
  217.         move.l  #s4,(a0)+
  218.         move.l  #s5+4,(a0)+
  219.         move.l  #s6+12,(a0)+
  220.         move.l  #s7,(a0)+
  221.         move.l  #s8+20,(a0)+
  222.         move.l  #s9+4,(a0)+
  223.         move.l  #s10+24,(a0)+
  224.         move.l  #s11,(a0)+
  225.         move.l  #s12+4,(a0)+
  226.         move.l  #s13+12,(a0)+
  227.         move.l  #s14+28,(a0)+
  228.         move.l  #s15,(a0)+
  229.         move.l  #s16+20,(a0)+
  230.         move.l  #s17+8,(a0)+
  231.         move.l  #s18+4,(a0)
  232.         lea     sp_list(pc),a0  Back to start of list
  233.         moveq   #17,d2          18 sets of coords
  234. set_p   move.l  (a0)+,a1
  235.         move.w  (a1),d0
  236.         move.w  2(a1),d1
  237.         bsr     point           Plot first star of each
  238.         dbf     d2,set_p
  239.         rts
  240.  
  241. dostars:
  242.         lea     sp_list(pc),a1  Pointer to list of pointers to star coords
  243.         moveq   #17,d3          18 lists
  244. do_s    move.l  (a1),a0         Get star pointer
  245.         bsr     do_next         remove previous & draw new star
  246.         dbf     d3,do_s
  247.         bsr     delay                   
  248.         rts
  249.  
  250. do_next
  251.         move.w  (a0)+,d0        Get old x coord
  252.         move.w  (a0)+,d1        and y coord
  253.         tst.w   d0              is d0 negative?
  254.         bmi     wrap            handle end of table if so
  255. r_old   move.l  a0,(a1)+
  256.         bsr     point           Remove old point
  257.         move.w  (a0),d0         Get new x coord           
  258.         move.w  2(a0),d1        and y coord
  259.         bsr     point           plot it
  260.         rts
  261.  
  262. wrap    move.l  (a0),d2         Get next longword
  263.         move.l  d2,a0           it's the address of the start of the table
  264.         bra     r_old
  265.  
  266. delay:
  267.         clr.w   timer           Zero timer
  268. wait_timer:
  269.         move.w  timer,d0
  270.         cmp.w   star_delay,d0
  271.         blo     wait_timer
  272.         rts
  273.  
  274. point:
  275.         movem.l d0-d3/a0,-(sp)  Save regs
  276.         move.l  _v_bas_ad,a0    Base address of screen
  277.         move.b  res,d2          Get res from hardware
  278.         and.b   #3,d2           Isolate screen resolution
  279.         cmp.b   #2,d2           High res
  280.         beq     plot_hi         No prelim. action necessary
  281.  
  282.         lsr.w   #1,d1           divide y coord by 2
  283.         cmp.b   #1,d2           Med res?
  284.         beq     plot_med        That's all if so
  285.         
  286.         lsr.w   #1,d0           Else halve x coord too
  287.  
  288. plot_low:
  289.         mulu    #160,d1         160 bytes per row
  290.         move    d0,d3
  291.         lsr     #1,d3
  292.         and     #$FFF8,d3       Horiz offset
  293. comb_o  add     d3,d1           combine horiz+vert offsets
  294.         adda    d1,a0           add to screen base addr
  295.         and     #$F,d0          correct pixel
  296.         neg     d0
  297.         add     #15,d0
  298.         bchg    d0,(a0)         Toggle first bit plane (only
  299. *                               want to do colour one)
  300.  
  301. unstack:
  302.         movem.l (sp)+,d0-d3/a0  Restore regs
  303.         rts
  304.  
  305. plot_med:
  306.         mulu    #160,d1         160 bytes per row
  307.         move    d0,d3
  308.         lsr     #4,d3           /16 word offset per plane
  309.         lsl     #1,d3           2 planes
  310.         add     d3,d3           word offset -> byte offset
  311.         bra     comb_o          rest is common code
  312.  
  313. plot_hi:
  314.         mulu    #80,d1          80 bytes per row
  315.         move    d0,d2
  316.         lsr     #4,d2           /16 word offset on row
  317.         add     d2,d2           -> byte offset
  318.         add     d2,d1           combine v+h offsets
  319.         adda    d1,a0           add to screen base address
  320.         and     #$F,d0          d0 now holds correct pixel
  321.         neg     d0
  322.         add     #15,d0          correct bit
  323.         bchg    d0,(a0)
  324.         bra     unstack         unstack correct regs
  325.  
  326. ***********************************************************************
  327. *                 "PERMANENT" DATA SECTION                            *
  328. ***********************************************************************
  329.  
  330. * Data in this section is retained after the PRG terminates, and should
  331. * be used for stuff that the interrupt handlers or ST Blank ACC/PRG
  332. * references. Anything else can go in the "disposable" data section
  333.  
  334. ourdata:
  335. *       This data area is accessed by the ST Blank accessory/program
  336.  
  337.         cnop    0,4     Longword align
  338.  
  339. savestart equ   *       Stuff to save/load starts here
  340.  
  341. mins    ds.b    1       No. of minutes
  342. secs    ds.b    1       and secs to blankout
  343. timeout ds.l    1       Time constant for countdown, set by user
  344. star_delay:
  345.         dc.w    29      Delay as displayed to user
  346. active  dc.w    0       <>0 if blanking enabled
  347. filler  ds.w    1       Filler for backward compatibility
  348. star_disp:
  349.         dc.w    0       0 = Display stars
  350. *                       n = Don't display stars
  351. lselect ds.w    1       Last radio button selected
  352.  
  353. saveend equ     *       End of save block
  354.  
  355.  
  356. counter ds.l    1       Running countdown decremented by 200Hz interrupt
  357. timer   ds.w    1       Counter incremented by 200Hz interrupt
  358. khandl  ds.l    1       Address of IKBD interrupt vector
  359. sp_list ds.l    18      List of pointers to pointers of star coordinates
  360.  
  361.  
  362. *       Coordinates for stars
  363. m       equ     $80000000
  364. coords:
  365. s1      dc.w    308,196,290,191,263,184,220,170,159,151,075,127
  366.         dc.l    m,s1
  367. s2      dc.w    308,191,298,188,285,181,263,169,225,152,165,121
  368.         dc.w    087,081,003,039
  369.         dc.l    m,s2
  370. s3      dc.w    316,194,290,172,244,132,170,069,108,008
  371.         dc.l    m,s3
  372. s4      dc.w    318,194,314,183,302,157,284,112,259,051
  373.         dc.l    m,s4
  374. s5      dc.w    320,193,322,184,328,168,337,136,348,093,363,043
  375.         dc.l    m,s5
  376. s6      dc.w    322,195,327,188,337,182,351,166,371,148,399,119
  377.         dc.w    433,083,490,021
  378.         dc.l    m,s6
  379. s7      dc.w    325,195,347,184,381,163,429,135,494,100,569,053
  380.         dc.l    m,s7
  381. s8      dc.w    326,198,336,196,350,191,371,184,406,175,463,161
  382.         dc.w    531,142,623,119
  383.         dc.l    m,s8
  384. s9      dc.w    328,200,347,201,379,204,423,209,482,216,559,224
  385.         dc.l    m,s9
  386. s10     dc.w    330,204,339,209,354,215,373,223,397,235,435,251
  387.         dc.w    492,276,576,313
  388.         dc.l    m,s10
  389. s11     dc.w    328,206,339,215,357,231,385,253,430,289,494,340
  390.         dc.l    m,s11
  391. s12     dc.w    323,207,326,213,330,221,335,229,344,244,356,265
  392.         dc.w    372,295,395,335,423,385
  393.         dc.l    m,s12
  394. s13     dc.w    319,208,317,229,314,266,309,313,305,371
  395.         dc.l    m,s13
  396. s14     dc.w    311,209,308,216,300,226,288,242,272,265,249,296
  397.         dc.w    221,331,190,373
  398.         dc.l    m,s14
  399. s15     dc.w    304,210,286,224,249,254,189,292,115,349
  400.         dc.l    m,s15
  401. s16     dc.w    300,208,290,212,275,218,254,227,225,240,179,258
  402.         dc.w    123,283,057,311,000,336
  403.         dc.l    m,s16
  404. s17     dc.w    309,202,290,203,256,209,206,219,134,232,031,250
  405.         dc.l    m,s17
  406. s18     dc.w    302,197,293,197,279,196,257,194,227,191,182,187
  407.         dc.w    113,181,025,172 
  408.         dc.l    m,s18
  409.  
  410.  
  411. ************************************************************************
  412. *                     "DISPOSABLE" CODE SECTION                        *
  413. ************************************************************************
  414.  
  415. membuff ds.l    16
  416.  
  417. * Code in this area becomes part of the screen buffer after the PRG
  418. * terminates
  419.  
  420. GO:
  421.         move.l  4(a7),a5        Get address of basepage
  422.         move.l  a5,basepage     Save it
  423.         move.l  #USTK,a7        Install stack
  424.         move.l  basepage,d0     Address of base page
  425.         move.l  #membuff,d1     Address of end of useful code
  426.         sub.l   d0,d1           d1 := d1 - d0
  427.         add.l   #32032,d1       Add length of screen and palette buffer
  428.         move.l  d1,useful_len   Save it
  429.  
  430.         clr.w   active          Don't dare blank during installation
  431.  
  432.         bsr     installation    Install
  433.         bsr     file_load       Load parameters
  434.  
  435.         pea     installmsg(pc)  Address of text to be printed
  436.         move.w  #Cconws,-(sp)   Print it
  437.         trap    #dos
  438.         addq.l  #6,sp           Tidy stack
  439.         
  440. * All OK,so now must Terminate and Stay Resident
  441.  
  442.         move.w  sactive,active  Set activity word
  443.  
  444.         move.w  #0,-(sp)        No errors
  445.         move.l  useful_len,-(sp) No. of bytes to protect
  446.         move.w  #Ptermres,-(sp)
  447.         trap    #dos
  448.  
  449. file_load:
  450.         move.w  #1,-(sp)        Open file for reading
  451.         pea     save_name(pc)
  452.         move.w  #Fopen,-(sp)
  453.         trap    #dos
  454.         addq.l  #8,sp
  455.         
  456.         tst.w   d0              Errors?
  457.         bmi     l_err           Handle if so
  458.  
  459.         move.w  d0,f_handle     Make note of handle returned
  460.         
  461.         pea     savestart(pc)   Start of buffer to load
  462.         move.l  #savelen,-(sp)  Length of load info
  463.         move.w  f_handle,-(sp)  File handle
  464.         move.w  #Fread,-(sp)    Fread
  465.         trap    #dos
  466.         lea.l   12(sp),sp       tidy stack
  467.         
  468.         move.w  active,sactive
  469.         clr.w   active          Don't dare activate yet!
  470.         
  471.         tst.l   d0
  472.         bmi     l_err_r         load error
  473.         cmp.l   #savelen,d0     All information loaded?
  474.         bne     l_err_r         abort if not
  475.         
  476.         bsr     fclose
  477.         tst.w   d0              Error?
  478.         bmi     l_err
  479.         rts
  480. fclose:
  481.         move.w  f_handle,-(sp)    Close file
  482.         move.w  #Fclose,-(sp)
  483.         trap    #dos
  484.         addq.l  #4,sp           tidy
  485.         rts
  486.         
  487. l_err:
  488. *       Error opening/closing file
  489.         move.l  #lerrmsg,d0
  490.         bsr     printstg               Print access error message
  491.         bsr     set_defaults
  492.         rts
  493.  
  494. l_err_r:
  495. *       Error reading file
  496.         bsr     fclose                 Attempt to close file
  497.         move.l  #rerrmsg,d0
  498.         bsr     printstg               Print string
  499.         bsr     set_defaults
  500.         rts
  501.  
  502. set_defaults:
  503.         move.b  #2,mins         Default 2 mins
  504.         move.b  #0,secs         0 seconds
  505.         move.l  #24000,timeout  Equivalent in 5ms units
  506.         move.w  #14,star_delay
  507.         move.w  #1,active       Default is to be active
  508.         move.w  #1,sactive
  509.         clr.w   star_disp       With stars on
  510.         clr.w   lselect         No last button
  511.         rts
  512.  
  513.         
  514. **************************** Install handlers **************************
  515.         
  516. installation:
  517.         clr.w   ierror          No errors yet
  518.  
  519.         move.w  #34,-(sp)       kbdvbase funct
  520.         trap    #xbios
  521.         addq.l  #2,sp           tidy
  522.         add.l   #32,d0
  523.         move.l  d0,khandl       store IKBD interrupt vector
  524.  
  525.         pea     inst_crit(pc)   Install interrupt routines
  526.         move.w  #38,-(sp)       Supexec call
  527.         trap    #xbios
  528.         addq.l  #6,sp           tidy
  529.         rts                     All done
  530.         
  531. XBRAcheck:
  532. *       Checks vector addressed by a0,for installation with address
  533. *       in a1. Attempts to handle re-installation by virtue of XBRA
  534. *       protocol.
  535.  
  536.         move.l  (a0),a2         Get address from vector
  537.         tst.l   (a0)            Zero vectors are special
  538.         beq     xb_install      so just get on with it
  539.         cmp.l   #xb_magic,-12(a2) Something already installed with XBRA?
  540.         bne     xb_install      Straight XBRA installation if not
  541.         cmp.l   #xb_id,-8(a2)   Has XBRA installed program got our ID?
  542.         bne     xb_install      If not,can install in XBRA chain
  543.  
  544.         move.l  -4(a2),-4(a1)   Use old old vector
  545.         bra     xb_i2           And continue installation
  546.  
  547. xb_install:
  548.         move.l  a2,-4(a1)       Save old vector value in our XBRA block
  549. xb_i2   move.l  a1,(a0)         Install our new handler
  550.         rts                     Done
  551.         
  552.  
  553. inst_crit:
  554.         or.w    #$700,SR        Interrupts off
  555.  
  556. *       We're going to search the VBL queue backwards, because
  557. *       GEM always hijacks the first VBL entry, no matter what is
  558. *       already installed.
  559.  
  560.         bsr     inst_cookie     Install cookie
  561.  
  562.         move.w  _bootdev,d0     Determine boot device
  563.         add.b   #"A",d0         Turn into a drive name
  564.         move.b  d0,save_name    Insert in info file name 
  565.  
  566. inst_vbl:
  567.         move.l  _vblqueue,a0    Get address of VBL list
  568.         clr.l   d0
  569.         move.w  nvbls,d0        and no. of VBLs
  570.         subq.w  #1,d0
  571.         asl.w   #2,d0           convert to offset
  572.         
  573. fspace  move.l  0(a0,d0.w),d1   Get routine address
  574.         beq     free            if it's zero,we can use it
  575.         move.l  d1,a1           copy into a1
  576.         cmp.l   #xb_id,-8(a1)   Already installed?
  577.         beq     free            If so,reinstall
  578.         subq.l  #4,d0           else search next slot
  579.         bne     fspace          until d0=0
  580.  
  581. * No free slots,so expand VBL list
  582.  
  583.         clr.l   d0
  584.         move.w  nvbls,d0        No of VBLs
  585.         addq.l  #8,d0           Add another 8 slots
  586.         move.l  d0,-(sp)        Save d0
  587.         asl.l   #2,d0           Multiply d0 by 4
  588.         bsr     our_malloc      Allocate memory
  589.         move.l  d0,a0           Get address of new memory
  590.         move.l  _vblqueue,a1    Address of old VBL queue
  591.         move.w  nvbls,d1        No of entries
  592.         subq.w  #1,d1
  593. xfer_vbls:
  594.         move.l  (a1)+,(a0)+     Copy entry
  595.         dbf     d1,xfer_vbls    Until done
  596.         move.w  #8-1,d1         Zero extra 8 slots
  597. zap_vbl
  598.         clr.l   (a0)+
  599.         dbf     d1,zap_vbl
  600.         move.l  d0,_vblqueue    Install new queue
  601.         move.l  (sp)+,d0        Get no. of new VBL slots back
  602.         move.l  d0,nvbls        And install
  603.         bra     inst_vbl        Go back and try again
  604.  
  605. free    add.l   d0,a0           Calc target vector
  606.         lea     blnk_vbl(pc),a1 Aiming to install this addr.
  607.         bsr     XBRAcheck       now
  608.         
  609.         move.l  khandl,a0       IKBD handler vector
  610.         lea     khandler(pc),a1 Address of new handler
  611.         bsr     XBRAcheck       Test for XBRA & install
  612.         
  613. i_mfp   moveq.l #5,d0           5th MFP interrupt
  614.         asl.l   #2,d0           convert to offset
  615.         add.l   #$100,d0        MFP vector start address
  616.         move.l  d0,a0           is the target
  617.         lea     hz_200(pc),a1   want to install this
  618.         bsr     XBRAcheck       install
  619.  
  620.         move.l  #bios_trap,a0   Target vector
  621.         lea     bios(pc),a1     What we want to install
  622.         bsr     XBRAcheck       install
  623.         
  624. q_inst  and.w   #$F8FF,SR       Interrupts back on
  625.         rts                     Done!
  626.  
  627. printstg:
  628.         move.l  d0,-(sp)        Address of text to be printed
  629.         move.w  #Cconws,-(sp)   Cconws func
  630.         trap    #dos
  631.         addq.l  #6,sp           tidy
  632.         rts
  633.  
  634. ************************* Cookie jar stuff ************************
  635.  
  636. *       Must be executed in supervisor mode
  637.  
  638. inst_cookie:
  639.         move.l  _p_cookies,d0    Get cookie pointer
  640.         tst.l   d0              Is it zero?
  641.         beq     new_cookie      If so,must install cookie jar
  642.         
  643. * Otherwise, look for free cookie slot
  644.  
  645.         move.l  d0,a0           Address of cookie jar in A0
  646.         clr.l   d0              Zero counter
  647. srch_cookie:
  648.         move.l  (a0)+,d1        Get cookie
  649.         move.l  (a0)+,d2        Get value of cookie
  650.         addq.l  #1,d0           Increment counter
  651.         cmp.l   #ourcookie,d1   One of ours?
  652.         beq     our_cookie
  653.         tst.l   d1              Zero cookie?
  654.         bne     srch_cookie
  655.  
  656.         cmp.l   d0,d2           Jar full?
  657.         beq     full_jar
  658.         clr.l   (a0)            New end marker
  659.         addq.l  #1,d2
  660.         move.l  d2,4(a0)
  661.         move.l  #ourcookie,-8(a0)       Our cookie
  662.         move.l  #ourdata,-4(a0) Address of our data
  663.         rts                     Done
  664.  
  665. our_cookie:
  666. *       Already found our cookie
  667.         move.l  #ourdata,-4(a0) Update to point to our data area
  668.         rts                     Done
  669.  
  670.  
  671. new_cookie:
  672.         move.l  #8,d0           8 slots in new cookie jar
  673.         bsr     alloc_jar       Allocate memory
  674.         move.l  d0,a0
  675.         move.l  #'_CPU',(a0)+   CPU type
  676.         move.l  #0,(a0)+        Is 68000
  677.         move.l  #'_VDO',(a0)+   Video shifter
  678.         move.l  #0,(a0)+        Is standard ST version
  679.         move.l  #'_SND',(a0)+   Sound hardware
  680.         move.l  #0,(a0)+        Is standard Yamaha chip
  681.         move.l  #'_MCH',(a0)+   Machine cookie
  682.         move.l  #0,(a0)+        Is standard ST
  683.         move.l  #ourcookie,(a0)+ Our cookie
  684.         move.l  #ourdata,(a0)+  And data pointer
  685.         clr.l   (a0)+           End of cookie marker
  686.         move.l  #8,(a0)         Eight cookie slots in the jar
  687.         move.l  d0,_p_cookies    Install jar
  688.         rts                     Done
  689.  
  690.  
  691. full_jar:
  692.         addq.w  #8,d0           Add an extra 8 slots
  693.         move.w  d0,d2           Save new no. of slots
  694.         movem.l d1-d2,-(sp)     Save these regs
  695.         bsr     alloc_jar       Allocate memory
  696.         movem.l (sp)+,d1-d2     Retrieve d1 and d2
  697.         move.l  d0,a1           Address of new jar
  698.         move.l  _p_cookies,d0
  699.         move.l  d0,a0           Address of old jar
  700.         subq.w  #1,d1           Set up no. of cookies to transfer
  701. xfer_cookies:
  702.         move.l  (a0)+,(a1)+     Transfer cookie
  703.         move.l  (a0)+,(a1)+
  704.         dbra    d1,xfer_cookies
  705.         move.l  #ourcookie,(a1)+ Install our cookie
  706.         move.l  #ourdata,(a1)+  And pointer to our data
  707.         clr.l   (a1)+
  708.         move.l  d2,(a1)+        Total number of cookies in jar
  709.         rts                     Done
  710.  
  711. alloc_jar:
  712.         asl.l   #3,d0           Multiply d0 by 8
  713.  
  714. our_malloc:
  715.         move.l  useful_len,d1   Current useful prog length
  716.         move.l  basepage,d2     Address of base page
  717.         add.l   d1,d2           Calc end of useful mem
  718.         add.l   d0,d1           Add on size of new cookie jar
  719.         move.l  d1,useful_len   And assure its future
  720.         move.l  d2,d0           Address of new cookie jar
  721.         rts                     Done
  722.  
  723.  
  724. *************************************************************************
  725. ***                "DISPOSABLE" DATA SECTION                          ***
  726. *************************************************************************
  727.  
  728. * The data in this section of the program will become part of the screen
  729. * buffer when the .PRG terminates and therefore should not contain data
  730. * referenced by the interrupt handlers (which should be put in the
  731. * permanent data section)
  732.  
  733.  
  734. useful_len ds.l 1       No. of useful bytes to retain upon termination
  735. basepage ds.l   1       Address of basepage
  736. f_handle ds.w   1       File handle
  737. ierror  ds.w    1       Installation error
  738. sactive ds.w    1       Saved "active" word
  739.  
  740. installmsg:
  741.         dc.b    13,10
  742.         dc.b    27,'p        ST Blank 2.0.1 installed         '
  743.         dc.b    27,'q',13,10,0
  744. lerrmsg:
  745.         dc.b    7,13,10,'*** Error accessing STBLANK.INF ***',13,10,0
  746. rerrmsg:
  747.         dc.b    7,13,10,'*** Error reading STBLANK.INF ***',13,10,0
  748. save_name
  749.         dc.b    'A:\STBLANK.INF',0
  750.  
  751.         DS.L    99
  752. USTK    DS.L    1               Stack of 100 long_words
  753.  
  754. scratch_mem equ *               Scratch memory starts here
  755.  
  756.         END
  757.