home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / bootcache_418.lzh / BootCACHE / BootCACHE.asm < prev    next >
Assembly Source File  |  1990-12-17  |  8KB  |  333 lines

  1.     OPT c+,l-,o+
  2.  
  3. *********************
  4. *                   *
  5. *  BootCACHE 1.0    *
  6. *                   *
  7. *  by Nico François *
  8. *********************
  9.  
  10.     incdir "INCLUDE:"
  11.     include "exec/types.i"
  12.     include "exec/funcdef.i"
  13.     include "exec/execbase.i"
  14.     include "exec/memory.i"
  15.     include "exec/resident.i"
  16.     include "exec/exec_lib.i"
  17.     include "graphics/gfxbase.i"
  18.     include "libraries/dos_lib.i"
  19.  
  20.      IFND _LVOCacheControl
  21. _LVOCacheControl    equ  -$288
  22.      ENDC
  23.  
  24. NULL    equ    0
  25.  
  26.     movem.l d0/a0,-(a7)
  27.     move.l ($4).w,a6
  28.     lea DosName(PC),a1
  29.     jsr _LVOOldOpenLibrary(a6)                ; open DOS
  30.     lea DOSBase(PC),a1
  31.     move.l d0,(a1)
  32.     move.l d0,a6
  33.     jsr _LVOOutput(a6)                        ; get stdout
  34.     lea stdout(PC),a1
  35.     move.l d0,(a1)
  36.     lea header.txt(PC),a0                    ; print header to console
  37.     move.l #header.len,d3
  38.     bsr puts
  39.     movem.l (a7)+,d0/a0                        ; get command line back
  40.  
  41.     move.l ($4).w,a6
  42.     move.b #0,0(a0,d0.w)                        ; zero terminated
  43. cmdloop:
  44.     move.b (a0)+,d0                            ; look for 'I' or 'R'
  45.     beq.s template
  46.     cmp.b #'i',d0
  47.     beq.s install
  48.     cmp.b #'I',d0
  49.     beq.s install
  50.     cmp.b #'r',d0
  51.     beq quit
  52.     cmp.b #'R',d0
  53.     beq quit
  54.     cmp.b #'b',d0
  55.     beq.s bbinstall
  56.     cmp.b #'B',d0
  57.     beq.s bbinstall
  58.     bra.s cmdloop
  59.  
  60. template:                                        ; print usage line
  61.     lea usage.txt(PC),a0
  62.     move.l #usage.len,d3
  63.     bra putsandexit
  64.  
  65. bbinstall:
  66.     moveq #0,d7
  67.     bra.s installrt
  68. install:
  69.     moveq #1,d7
  70. installrt:
  71.     move.l ($4).w,a6
  72.     move.w LIB_VERSION(a6),d0
  73.     cmp.w #36,d0
  74.     blo.s Kickstart13
  75.     tst.l d7
  76.     beq.s Kickstart13
  77.     move.b #-37,rtpri
  78.     move.b #RTF_AFTERDOS,rtflags
  79. Kickstart13:
  80.     lea PortName(PC),a1
  81.     jsr _LVOFindPort(a6)                        ; find our port
  82.     tst.l d0
  83.     beq.s allocit
  84.     lea already.txt(PC),a0                    ; found, so already installed
  85.     move.l #already.len,d3
  86.     bra putsandexit
  87.  
  88. allocit:
  89.     move.l #BlockLen,d0
  90.     moveq #MEMF_CHIP,d1                        ; allocate memory for reset code
  91.     jsr _LVOAllocMem(a6)                        ; must be in CHIP !!
  92.     tst.l d0
  93.     bne.s memok
  94.     lea nomem.txt(PC),a0                        ; out of memory ???
  95.     move.l #nomem.len,d3
  96.     bra putsandexit
  97.  
  98. memok:
  99.     move.l d0,a5                                ; a5 holds address of copy
  100.     lea StartBlock(PC),a0
  101.     move.l d0,a1
  102.     move.l #BlockLen,d0
  103.     jsr _LVOCopyMem(a6)                        ; copy block to allocated memory
  104.     move.w #$4000,$DFF09A                    ; DISABLE
  105.     addq.b #1,IDNestCnt(a6)
  106.     lea RomTagPtrs-StartBlock(a5),a0
  107.     move.l KickTagPtr(a6),4(a0)            ; old romtag pointer in array
  108.     beq.s yestag
  109.     bset #7,4(a0)                                ; set bit if there are more
  110. yestag:
  111.     move.l a0,KickTagPtr(a6)                ; pointer to our array
  112.     lea RomTag-StartBlock(a5),a1
  113.     move.l a1,(a0)                                ; fill in our romtag pointer
  114.  
  115.     lea myMemList-StartBlock(a5),a1        ; init memlist and put in
  116.     move.l a5,ML_SIZE+ME_ADDR(a1)            ; KickMemPtr list to protect
  117.     move.l KickMemPtr(a6),d0                ; our memory
  118.     move.l d0,LN_SUCC(a1)
  119.     move.l a1,KickMemPtr(a6)
  120. inittag:
  121.     lea RomTag-StartBlock(a5),a1            ; init romtag
  122.     move.l a1,RT_MATCHTAG(a1)
  123.     lea RT_SIZE(a1),a2
  124.     move.l a2,RT_ENDSKIP(a1)
  125.     lea TagName-StartBlock(a5),a2
  126.     move.l a2,RT_NAME(a1)
  127.     move.l a5,RT_INIT(a1)
  128.     jsr _LVOSumKickData(a6)                    ; calculate checksum
  129.     move.l d0,KickCheckSum(a6)
  130.     lea Port-StartBlock(a5),a1                ; init and add our port
  131.     moveq #0,d0
  132.     move.l d0,(a1)
  133.     move.l d0,LN_PRED(a1)
  134.     lea PortName-StartBlock(a5),a0
  135.     move.l a0,LN_NAME(a1)
  136.     jsr _LVOAddPort(a6)
  137.     subq.b #1,IDNestCnt(a6)                    ; ENABLE
  138.     bge.s noenable
  139.     move.w #$C000,$DFF09A
  140. noenable:
  141.     lea installed.txt(PC),a0                ; inform user of installation
  142.     move.l #installed.len,d3
  143.     move.w LIB_VERSION(a6),d0
  144.     cmp.w #36,d0
  145.     blo putsandexit
  146.     tst.l d7
  147.     bne putsandexit
  148.     bsr puts
  149.     lea bootinstalled.txt(PC),a0
  150.     move.l #bootinstalled.len,d3
  151.     bra.s putsandexit
  152.  
  153. quit:
  154.     lea PortName(PC),a1                        ; are we already installed ?
  155.     jsr _LVOFindPort(a6)
  156.     tst.l d0
  157.     bne.s portfound
  158.     lea nohandler.txt(PC),a0                ; no, can't quit then
  159.     move.l #nohandler.len,d3
  160.     bra.s putsandexit
  161.  
  162. portfound:
  163.     move.l d0,a4                                ; we found our port, so remove it
  164.     move.l a4,a1
  165.     jsr _LVORemPort(a6)
  166.  
  167.     move.w #$4000,$DFF09A                    ; DISABLE
  168.     addq.b #1,IDNestCnt(a6)
  169.  
  170.     lea myMemList-Port(a4),a1                ; remove our memlist from
  171.     lea KickMemPtr(a6),a0                    ; KickMemPtr list.
  172. nextnode:
  173.     move.l LN_SUCC(a0),d0
  174.     cmp.l d0,a1
  175.     beq.s foundmylist
  176.     move.l d0,a0
  177.     bra.s nextnode
  178. foundmylist:
  179.     move.l LN_SUCC(a1),d0
  180.     move.l d0,LN_SUCC(a0)    ; LN_SUCC = 0, so this also works for KickMemPtr
  181.  
  182.     move.l RomTagPtrs-Port+4(a4),KickTagPtr(a6)    ; old RomTag back
  183.     bclr #7,KickTagPtr(a6)
  184.     jsr _LVOSumKickData(a6)                    ; calculate checksum
  185.     move.l d0,KickCheckSum(a6)
  186.     subq.b #1,IDNestCnt(a6)                    ; ENABLE
  187.     bge.s noenable2
  188.     move.w #$C000,$DFF09A
  189. noenable2:
  190.     lea StartBlock-Port(a4),a1                ; free our copied block
  191.     move.l #BlockLen,d0
  192.     jsr _LVOFreeMem(a6)
  193.     lea removed.txt(PC),a0                    ; and inform the user
  194.     move.l #removed.len,d3
  195.  
  196. putsandexit:
  197.     bsr.s puts                                    ; print string in A0, length D3
  198.     move.l DOSBase(PC),a1
  199.     jsr _LVOCloseLibrary(a6)                ; close DOS and exit
  200.     moveq #0,d0
  201.     rts
  202.  
  203. * text-ptr in A0, length in D3
  204. puts:
  205.     move.l a6,-(a7)
  206.     move.l a0,d2
  207.     move.l stdout(PC),d1
  208.     move.l DOSBase(PC),a6
  209.     jsr _LVOWrite(a6)
  210.     move.l (a7)+,a6
  211.     rts
  212.  
  213. header.txt:
  214.     dc.b $9b,'1mBootCACHE 1.0 ',$9b,'0m',$9b,'33mby Nico François',$9b,'0m',10
  215. header.len equ *-header.txt
  216. already.txt:
  217.     dc.b 'CACHE RomTag already installed !',10
  218. already.len equ *-already.txt
  219. usage.txt:
  220.     dc.b 'Usage: BootCACHE [I=INSTALL|B=BOOTBLOCK|R=REMOVE]',10
  221.     dc.b '  Use BOOTBLOCK on Kickstart 2.0 for programs that',10
  222.     dc.b '  boot from the bootblock (mostly games).',10
  223. usage.len equ *-usage.txt
  224. installed.txt:
  225.     dc.b 'CACHE RomTag installed, reset to disable all caches!',10
  226. installed.len equ *-installed.txt
  227. bootinstalled.txt:
  228.     dc.b 'NOTE: Cache will only be disabled for programs that boot from the bootblock!'
  229.     dc.b 10
  230. bootinstalled.len equ *-bootinstalled.txt
  231. nomem.txt:
  232.     dc.b 'No memory for RomTag (I only need about 200 bytes) !?!',10
  233. nomem.len equ *-nomem.txt
  234. nohandler.txt:
  235.     dc.b 'CACHE RomTag not installed !',10
  236. nohandler.len equ *-nohandler.txt
  237. removed.txt:
  238.     dc.b 'CACHE RomTag removed !',10
  239. removed.len equ *-removed.txt
  240. DosName:
  241.     dc.b 'dos.library',0
  242.     EVEN
  243. DOSBase:
  244.     dc.l 0
  245. stdout:
  246.     dc.l 0
  247.  
  248. *****************************************************************************
  249.  
  250. StartBlock:                                        ; this is the routine that will
  251.     movem.l d0-d7/a0-a6,-(a7)                ; be executed when we reset
  252.     move.l ($4).w,a6
  253.     lea Port(PC),a1                            ; add our port to the system list
  254.     moveq #0,d0
  255.     move.l d0,(a1)
  256.     move.l d0,LN_PRED(a1)
  257.     lea PortName(PC),a0
  258.     move.l a0,LN_NAME(a1)
  259.     jsr _LVOAddPort(a6)
  260.  
  261.     move.w LIB_VERSION(a6),d0
  262.     cmp.w #36,d0
  263.     blo.s Kick13
  264.  
  265. Kick20:
  266.     move.l #$2000,d0
  267.     moveq #-1,d1
  268.     jsr _LVOCacheControl(a6)
  269.     bra.s endtag
  270.  
  271. Kick13:
  272.     jsr _LVODisable(a6)
  273.     lea DisableCache,a5
  274.     jsr _LVOSupervisor(a6)
  275.     jsr _LVOEnable(a6)
  276.  
  277. endtag:
  278.     movem.l (a7)+,d0-d7/a0-a6                ; back to rom boot code
  279.     move.w #$0f0,$DFF180                        ; green screen
  280.     rts
  281.  
  282.     cnop 0,4
  283. DisableCache:
  284.     move.l #$2000,d0
  285.     dc.w $4e7b,$0002                            ; movec d0,CACR
  286.     rte
  287.  
  288. RomTagPtrs:
  289.     dc.l 0,0                                        ; array of RomTag pointers
  290. PortName:
  291.     dc.b 'BootCACHE.port',0                    ; port name
  292. TagName:
  293.     dc.b 'CACHE-boot',0                        ; tag name
  294.     EVEN
  295.  
  296. myMemList:                                        ; memory list for reset protection
  297.     ds.b LN_SIZE
  298.     dc.w 1
  299.     dc.l NULL
  300.     dc.l BlockLen
  301.  
  302. Port:                                                ; our port structure
  303.     dc.l NULL
  304.     dc.l NULL
  305.     dc.b NT_MSGPORT
  306.     dc.b 0
  307.     dc.l NULL
  308.     dc.b 0
  309.     dc.b 0
  310.     dc.l NULL
  311.     ds.b 14
  312.  
  313. RomTag:                                            ; the RomTag to inform kickstart
  314.     dc.w RTC_MATCHWORD                        ; of what we want
  315.     dc.l NULL
  316.     dc.l NULL
  317. rtflags:
  318.     dc.b RTF_COLDSTART                        ; RTF_AFTERDOS in Kick 2.0
  319.     dc.b 1
  320.     dc.b 0
  321. rtpri:
  322.     dc.b -10                                        ; -37 in Kick 2.0
  323.     dc.l NULL
  324.     dc.l NULL
  325.     dc.l NULL
  326.  
  327. BlockLen equ *-StartBlock                    ; length of block to be copied
  328.  
  329. *****************************************************************************
  330.  
  331.     END
  332.  
  333.