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