home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 6 / Sonderheft_6-96.iso / pd / libraries / patchlibv4 / examples / cpuclr / cpuclrv4.asm < prev    next >
Assembly Source File  |  1996-11-03  |  7KB  |  265 lines

  1. ;!OPT -m
  2. ;!CPY LCP:CPUClr
  3. ;
  4. ;CpuClr V4.0
  5. ;Based on my CpuClr V2.5 and CpuClear V3.100 by Peter Simons
  6. ;
  7. ;
  8. ;-------------------------------------- Includes -----------
  9.     include "patchtags.i"
  10.  
  11. ;-------------------------------------- Exec ---------------
  12. eb_AttnFlags    equ     $0128
  13. lib_Version     equ     $0014
  14.  
  15. AF_68020        equ     1
  16.  
  17. ;-------------------------------------- Labels -------------
  18. execbase    equ    4
  19. _DOSBase        equr    A5
  20. _PATCHBase      equr    A4
  21.  
  22. _LVOFindPatch        equ    -48    ;patch.library
  23. _LVOInstallPatchTagsA    equ    -54
  24. _LVORemovePatchTagsA    equ    -60
  25.  
  26. _LVOBltClear        equ    -300    ;graphics.library
  27. _LVOWaitBlit        equ    -228
  28.  
  29. _LVOCacheClearU        equ    -636    ;exec.library
  30. _LVOOpenLibrary        equ    -552
  31. _LVOCloseLibrary    equ    -414
  32.  
  33. ;-------------------------------------- Macros -------------
  34. REVISION        MACRO
  35.                 dc.b "4.0"
  36.                 ENDM
  37. REVDATE         MACRO
  38.                 dc.b "23.03.94"
  39.                 ENDM
  40.  
  41.  
  42. Main:
  43.     sub.l    _DOSBase,_DOSBase
  44.     sub.l    _PATCHBase,_PATCHBase
  45.     move.l    execbase,a6
  46.     btst    #AF_68020,eb_AttnFlags+1(a6)   ; 68020+ ?
  47.     beq    CPUFailed
  48.  
  49.     lea.l    dosname(pc),a1        ;Open Dos Library
  50.     moveq.l    #0,d0
  51.     jsr    _LVOOpenLibrary(a6)
  52.     tst.l    d0
  53.     beq    DosFailed
  54.     move.l    d0,_DOSBase
  55.  
  56.     lea.l    Header(pc),a0        ;Print Title Text
  57.     bsr    TextOutput
  58.  
  59.     lea.l    patchname(pc),a1    ;Open Patch Library Version 2
  60.     moveq.l    #2,d0
  61.     jsr    _LVOOpenLibrary(a6)
  62.     tst.l    d0
  63.     beq    PatchFailed
  64.     move.l    d0,_PATCHBase
  65.  
  66.     lea.l    IDString(pc),a0        ;Is Patch Installed
  67.     move.l    _PATCHBase,a6
  68.     jsr    _LVOFindPatch(a6)
  69.     tst.l    d0
  70.     beq    install            ;No ->install
  71.  
  72.     move.l    d0,a0            ;Remove Patch
  73.     lea.l    RemoveTags(pc),a1
  74.     jsr    _LVORemovePatchTagsA(a6)
  75.     lea.l    RemoveText(pc),a0
  76.     tst.l    d0
  77.     beq    exit
  78.     lea.l    RemoveFailText(pc),a0
  79.     bra    exit
  80.  
  81. install:
  82.     lea.l    InstallTags(pc),a1
  83.  
  84.     lea.l    gfxname(pc),a0
  85.     move.l    a0,4(a1)
  86.     lea.l    IDString(pc),a0
  87.     move.l    a0,12(a1)
  88.  
  89.     lea.l    NewBltClr(pc),a0
  90.     move.l    #_LVOBltClear,d0
  91.     jsr    _LVOInstallPatchTagsA(a6)
  92.     lea.l    InstalledText(pc),a0
  93.     tst.l    d0
  94.     bne    exit
  95.     lea.l    InstallFailText(pc),a0
  96.  
  97. exit:
  98.     bsr    TextOutput
  99.     move.l    execbase,a6
  100.     move.l    _PATCHBase,a1
  101.     jsr    _LVOCloseLibrary(a6)        ;Close patch Library
  102.  
  103. PatchFailed:
  104.     cmp.l    #0,_PATCHBase
  105.     bne    PatchFailedSkip
  106.     lea.l    ReqPatchLib(pc),a0
  107.     bsr    TextOutput
  108.  
  109. PatchFailedSkip:
  110.     move.l    execbase,a6
  111.     move.l    _DOSBase,a1
  112.     jsr    _LVOCloseLibrary(a6)        ;Close dos Library
  113. DosFailed:
  114. CPUFailed:
  115.     rts
  116. ******************************************************************V1.3*
  117. * Name:        TextOutput
  118. * Function:    Writes a C-string to std output (CLI,PRT,...)
  119. * Version:    V1.2    (works)
  120. * Assembler:    MasterSeka V1.75 & OMA V1.81
  121. * Copyright:    1991 Stefan Fuchs
  122. *
  123. * Inputs:    a0 = Pointer to a C-string
  124. * Assumptions:    DosBase
  125. * Results:    
  126. * Destroyed registers:
  127. * Code:        pc-relative
  128. * Known bugs:    
  129. * See also:    
  130. * Notes:    Exits without any output,
  131. *        if the Outputhandle or a0 is null
  132. ***********************************************************************
  133. TextOutput:
  134.     movem.l d0-d3/a0/a1/a6,-(sp)
  135.     moveq.l #0,d3
  136.     move.l a0,d2
  137.     beq.s TextOutputExit
  138. TextOutputLoop:
  139.     addq.l #1,d3
  140.     tst.b (a0)+
  141.     bne.S TextOutputLoop
  142.     move.l _DOSBase,a6
  143.     jsr -60(a6)    ;OutPut
  144.     move.l d0,d1
  145.     beq.s TextOutputExit
  146.     jsr -48(a6)    ;Write
  147. TextOutputExit:
  148.     movem.l (sp)+,d0-d3/a0/a1/a6
  149.     rts
  150. ;------------------------------------------------------------------------
  151. NewBltClr:                      ; A1=&MemBlock A6=&GraphicsLibraryBase
  152.                                 ; D0=bytecount D1=flags
  153.  
  154.                 move.l  d2,a0                   ; save register
  155.                 btst    #1,d1                   ; bytes per row?
  156.                 beq     ByteSize                ; Nope -> length is alright
  157.                 move.l  d0,d2                   ; Yep  -> calc size of block
  158.                 swap    d2
  159.                 mulu.w  d2,d0
  160. ByteSize:    bclr    #0,d0                   ; only even number of bytes
  161.                 tst.l   d0                      ; bytecount > 0 ?
  162.                 beq    Finished                ; Nope -> Exit!
  163.  
  164.                 moveq   #0,d2                   ; clear memory or fill with
  165.                 btst    #2,d1                   ; pattern??
  166.                 beq    DataOK
  167.                 move.l  d1,d2
  168.                 swap    d1                      ; --> fill with pattern
  169.                 move.w  d1,d2
  170. DataOK:         jsr    _LVOWaitBlit(a6)        ; syncronisation!
  171.  
  172.         cmp.l     #100,d0
  173.         bhi    FewStuffSkip
  174.  
  175.  
  176. ;This routine will only be called, if only a few bytes have to be cleared (NO Overhead!)
  177.         lsr.l    #1,d0
  178.         subq.l    #1,d0
  179. Loop0:        move.w    d2,(a1)+
  180.         dbra    d0,Loop0
  181.         bra    Finished
  182.  
  183.  
  184. FewStuffSkip:
  185.         add.l    d0,a1
  186.                 move.w  a1,d1
  187.                 btst    #1,d1            ; Longword aligned?
  188.                 beq    LongAlignSkip
  189.         move.w    d2,-(a1)        ; No -> Clear a word
  190.         subq.l    #2,d0
  191.         beq    Finished
  192.  
  193. LongAlignSkip:    move.l    d0,d1
  194.         cmp.l     #400,d0
  195.         blo    LotsOfStuffSkip
  196.  
  197.  
  198. ;This routine will only be called, if lots of bytes have to be cleared (Overhead!)
  199.                 movem.l    d3-d5,-(SP)
  200.         move.l    d2,d3
  201.         move.l    d2,d4
  202.         move.l    d2,d5
  203.         lsr.l     #4,d0
  204.         subq.l    #1,d0
  205. Loop2:        movem.l    d2-d5,-(a1)        ; ClearLoop
  206.         dbra    d0,Loop2        ; dbra limits the max size to clear
  207.                         ; to 1MB, but i don't think that's
  208.                         ; a problem
  209.                 movem.l    (SP)+,d3-d5
  210.         move.l    d1,d0
  211.         and.l    #%1100,d0
  212.         beq    LastWord
  213.  
  214.  
  215. LotsOfStuffSkip:
  216.         lsr.l    #2,d0            ; calculate number of LWs
  217.         subq.l    #1,d0
  218. Loop:        move.l    d2,-(a1)        ; ClearLoop
  219.         dbra    d0,Loop
  220.  
  221. LastWord:    btst    #1,d1            ; Still a Word to clear?
  222.                 beq    LongAlignSkip2
  223.         move.w    d2,-(a1)        ; Clear it
  224.  
  225. LongAlignSkip2:
  226. Finished:       move.l  a0,d2
  227.                 pea     (a6)
  228.         move.l    execbase,a6
  229.                 cmp.w   #37,lib_Version(a6)    ; Kickstart 2.04+ ?
  230.                 bmi     Exit
  231.                 jsr    _LVOCacheClearU(a6)     ; write back memory on '40
  232. Exit:        move.l  (SP)+,a6
  233.                 rts
  234.  
  235. NewBltClr_len   equ     (*-NewBltClr)           ; length of routine
  236.  
  237. ;----------------------------------------------------------------------
  238. InstallTags:    dc.l PATT_LibraryName,0
  239.         dc.l PATT_PatchName,0
  240.         dc.l PATT_NewCodeSize,NewBltClr_len
  241.         dc.l 0
  242. RemoveTags:    dc.l PATT_TimeOut,50
  243.         dc.l 0
  244.  
  245. gfxname         dc.b    "graphics.library",0
  246. dosname         dc.b    "dos.library",0
  247. patchname    dc.b    "patch.library",0
  248. Header          dc.b    $9B,"1;33",$6D
  249.                 dc.b    "$VER: CPUClr"
  250.                 dc.b    " "
  251.                 REVISION
  252.                 dc.b    " ("
  253.                 REVDATE
  254.                 dc.b    ")"
  255.                 dc.b    $9B,$6D
  256.                 dc.b    " by Stefan Fuchs",10,0
  257. ReqPatchLib:    dc.b "*** Requires patch.library V2+ in libs:",10,0
  258. InstalledText:    dc.b "Patch successfully installed",10,0
  259. InstallFailText:dc.b "*** Failed to install patch",10,0
  260. RemoveText:    dc.b "Patch successfully removed",10,0
  261. RemoveFailText:    dc.b "*** Failed to remove patch",10,0
  262. IDString:    dc.b "CPUClr",0
  263.  
  264.                 END
  265.