home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / libs / cpuclr2.lha / sources / CPUClr.asm next >
Encoding:
Assembly Source File  |  1992-08-05  |  11.3 KB  |  308 lines

  1. ;****** Auto-Revision Header (do not edit) *******************************
  2. ;*
  3. ;* © This is Freeware (All rights are reserved by Peter Simons!)
  4. ;*
  5. ;* Filename         : CpuClr.asm
  6. ;* Created on       : 23-Jul-92
  7. ;* Created by       : Oliver Wagner & Peter Simons
  8. ;* Current revision : V2.000
  9. ;*
  10. ;*
  11. ;* Purpose: This program replaces the system-routine BltClear() with a
  12. ;*          highly optimized 68020/30/40 routine.
  13. ;*
  14. ;*
  15. ;* V2.000 : Final version! (??)        released: Peter Simons (24-Jul-02)
  16. ;*
  17. ;* V1.042 : fixed bug in CPU-recognition
  18. ;*
  19. ;* V1.040 : Changed addressing mode in clear-loop! Again saved a few
  20. ;*          bytes and cyles...
  21. ;*
  22. ;* V1.034 : I corrected a few typing-errors in the sourcecode
  23. ;*
  24. ;* V1.033 : I called SetFunction() with wrong parameters, which caused
  25. ;*          the machine to crash immediately. (I'll never find out why it
  26. ;*          worked on my Amiga all the time?? Don't ask! It's magic!)
  27. ;*
  28. ;* V1.032 : Added secure/unsecure switch
  29. ;*
  30. ;* V1.031 : released: Peter Simons (24-Jul-02)
  31. ;*
  32. ;* V1.030 : saved again 4 bytes by changing the addressing mode in the
  33. ;*          clear loop
  34. ;*
  35. ;* V1.028 : NewBltClr won't crash the machine any longer if a blocksize
  36. ;*          of ZERO is specified
  37. ;*
  38. ;* V1.027 : NewBltClr has only one exit-point now --> saves some bytes
  39. ;*
  40. ;* V1.026 : saved one swap-command in long-align-routine
  41. ;*
  42. ;* V1.025 : fixed minor bug: SIZE % 4 = 0 was NOT recognized by NewBltClr
  43. ;*
  44. ;* V1.020 : deleted opcodes in size-calculation: clearing the upper word
  45. ;*          was a waste, because MULU works only on WORD-size
  46. ;*
  47. ;* V1.011 : optimized output-routines and saved some bytes
  48. ;*
  49. ;* V1.010 : the way how the patch is installed, has been completely re-
  50. ;*          written and is shorter and, in my eyes, system-friendlier...
  51. ;*
  52. ;* V1.006 : program won't crash, if no standard-output is available!
  53. ;*          (for example, if started out of DME...)
  54. ;*
  55. ;* V1.005 : program checks for at least OS 2.04 and 68020 or higher
  56. ;*
  57. ;* V1.004 : changed program-output and added OS 2.0-version-string
  58. ;*
  59. ;* V1.003 : minor changes to the source-code
  60. ;*          revision header added
  61. ;*          changed to Macro68k-Assembler
  62. ;*
  63. ;* V1.002 : merged hunks --> program is position independent
  64. ;*
  65. ;* V1.001 : I continue development: Peter Simons (23-Jul-92)
  66. ;*
  67. ;* V1.000 : written by Oliver Wagner
  68. ;*
  69. ;* V0.000 : --- Initial release ---
  70. ;*
  71. ;*************************************************************************
  72. ;
  73. ;
  74.  
  75. ;***************************************************************************
  76. ;*                                                                         *
  77. ;* SEKTION: Labels, Macros, Switches, Structures                           *
  78. ;*                                                                         *
  79. ;***************************************************************************
  80.  
  81. ;-------------------------------------- Switches -----------
  82.                 MC68000
  83.                 EXEOBJ
  84.                 OBJFILE "ram:CPUClr"
  85.                 NEWSYNTAX
  86.  
  87. SECURECODE      set     1       ; test everything that could possibly
  88.                                 ; crash the machine
  89. ;-------------------------------------- Exec ---------------
  90. eb_AttnFlags    equ     $0128
  91. lib_Version     equ     $0014
  92.  
  93. MEMF_PUBLIC     equ     1<<0
  94. AF_68020        equ     1
  95.  
  96. ;-------------------------------------- Labels -------------
  97.                 MACLIB  "DATAS:Offsets.preass"
  98. KICKVERSION     equ     37
  99.  
  100. _DOSBase        equr    A5
  101. _GfxBase        equr    A4
  102. _NewBltClr      equr    A3
  103. _OutputHandle   equr    D7
  104.  
  105. ;-------------------------------------- Macros -------------
  106. REVISION        MACRO
  107.                 dc.b "2.000"
  108.                 ENDM
  109. REVDATE         MACRO
  110.                 dc.b "24-Jul-02"
  111.                 ENDM
  112.  
  113.  
  114. ;***************************************************************************
  115. ;*                                                                         *
  116. ;* SEKTION: Program                                                        *
  117. ;*                                                                         *
  118. ;***************************************************************************
  119.  
  120. START:          move.l  ($4).W,a6
  121.         IFNE SECURECODE
  122.                 cmp.w   #KICKVERSION,(lib_Version,a6)   ; Kickstart 2.04+ ?
  123.                 bmi     .ErrorExit
  124.                 btst    #AF_68020,(eb_AttnFlags+1,a6)     ; 68020+ ?
  125.                 beq     .ErrorExit
  126.         ENDC
  127.                 lea     (dosname,PC),a1
  128.                 jsr     (_LVOOldOpenLibrary,a6)         ; open Dos-Library
  129.         IFNE SECURECODE
  130.                 tst.l   d0
  131.                 beq     .ErrorExit
  132.         ENDC
  133.                 move.l  d0,_DOSBase
  134.  
  135.                 lea     (gfxname,PC),a1
  136.                 jsr     (_LVOOldOpenLibrary,a6)         ; open Graphics-Lib
  137.         IFNE SECURECODE
  138.                 tst.l   d0
  139.                 beq     .CloseDosLib
  140.         ENDC
  141.                 move.l  d0,_GfxBase
  142.  
  143.                 move.l  _DOSBase,a6
  144.                 jsr     (_LVOOutput,a6)                 ; get standard-
  145.                 move.l  d0,_OutputHandle                ; outputhandle
  146.  
  147.                 move.l  _OutputHandle,d1
  148.         IFNE SECURECODE
  149.                 beq.s   .SkipWrite
  150.         ENDC
  151.                 lea     (Header,PC),a0                  ; write standard-
  152.                 move.l  a0,d2                           ; header
  153.                 moveq   #Header_len,d3
  154.                 jsr     (_LVOWrite,a6)
  155.  
  156. .SkipWrite      move.l  (_LVOBltClear+2,_GfxBase),_NewBltClr ; is the patch
  157.                 cmp.l   #'FAST',(new_ID,_NewBltClr)     ; already installed?
  158.                 beq.s   .RemovePatch                    ; Yep->remove
  159.  
  160. ;-------------------------------------- install patch ------
  161.  
  162.                 moveq   #NewBltClr_len,d0
  163.                 moveq   #MEMF_PUBLIC,d1
  164.                 move.l  ($4).W,a6
  165.                 jsr     (_LVOAllocVec,a6)
  166.         IFNE SECURECODE
  167.                 tst.l   d0
  168.                 beq.s   .CloseGfxLib                    ; Can't allocate
  169.         ENDC
  170.                 move.l  d0,_NewBltClr                   ; memory
  171.  
  172.                 lea     (NewBltClr,PC),a0
  173.                 move.l  _NewBltClr,a1                   ; copy patch into
  174.                 moveq   #NewBltClr_len,d0               ; reserved buffer
  175.                 jsr     (_LVOCopyMem,a6)
  176.  
  177.                 move.l  _GfxBase,a1
  178.                 move.w  #_LVOBltClear,a0                ; patch OS-function
  179.                 move.l  _NewBltClr,d0
  180.                 jsr     (_LVOSetFunction,a6)
  181.                 move.l  d0,(new_OldBltClr,_NewBltClr)   ; save old vector
  182.  
  183.                 lea     (Install,PC),a0                 ; give feedback :-)
  184.                 moveq   #Install_len,d3
  185.                 bra.s   .exit
  186.  
  187. ;-------------------------------------- remove patch -------
  188. .RemovePatch    move.l  _GfxBase,a1
  189.                 move.w  #_LVOBltClear,a0
  190.                 move.l  (new_OldBltClr,_NewBltClr),d0
  191.                 move.l  ($4).W,a6
  192.                 jsr     (_LVOSetFunction,a6)            ; replace old
  193.                 move.l  d0,a1                           ; function and
  194.                 jsr     (_LVOFreeVec,a6)                ; release memory
  195.  
  196.                 move.l  _DOSBase,a6
  197.                 lea     (Remove,PC),a0
  198.                 moveq   #Remove_len,d3
  199.  
  200. ;-------------------------------------- exit gracefully ----
  201.  
  202. .exit           move.l  _OutputHandle,d1
  203.         IFNE SECURECODE
  204.                 beq.s   .CloseGfxLib
  205.         ENDC
  206.                 move.l  a0,d2
  207.                 move.l  _DOSBase,a6
  208.                 jsr     (_LVOWrite,a6)
  209.  
  210.                 move.l  _OutputHandle,d1
  211.                 lea     (Returns,PC),a0
  212.                 move.l  a0,d2
  213.                 moveq   #Returns_len,d3
  214.                 jsr     (_LVOWrite,a6)
  215.  
  216. .CloseGfxLib    move.l  _GfxBase,a1
  217.                 move.l  ($4).W,a6                       ; close resources
  218.                 jsr     (_LVOCloseLibrary,a6)           ; and leave
  219.  
  220. .CloseDosLib    move.l  _DOSBase,a1
  221.                 jsr     (_LVOCloseLibrary,a6)
  222.  
  223. .ErrorExit      moveq   #0,d0
  224.                 rts
  225.  
  226.  
  227. ;***************************************************************************
  228. ;*                                                                         *
  229. ;* SEKTION: new BltClear()-Routine                                         *
  230. ;*                                                                         *
  231. ;***************************************************************************
  232. NewBltClr:                      ; A1=&memBlock
  233.                                 ; D0=bytecount
  234.                                 ; D1=flags
  235.                 move.l  d2,a0                   ; save register
  236.                 tst.l   d0                      ; bytecount > 0 ?
  237.                 beq.s   .finished               ; Nope -> Exit!
  238.                 btst    #1,d1                   ; bytes per row?
  239.                 beq.s   .bytesize               ; Nope -> length is alright
  240.                 move.l  d0,d2                   ; Yep  -> calc size of
  241.                 swap    d2                      ;         memBlock
  242.                 mulu    d2,d0
  243. .bytesize       moveq   #0,d2                   ; clear memory or fill with
  244.                 btst    #2,d1                   ; pattern??
  245.                 beq.s   .dataok
  246.                 swap    d1                      ; --> fill with pattern
  247.                 move.w  d1,d2
  248. .dataok         btst    #1,d0                   ; --> clear
  249.                 beq.s   .LongAlign
  250.                 subq.l  #2,d0
  251. .loop1          move.w  d2,(a1)+
  252.                 subq.l  #2,d0
  253.                 bcc.s   .loop1
  254. .finished       move.l  a0,d2
  255.                 rts
  256.  
  257. .LongAlign      move.w  d2,d1                   ; more efficient routine
  258.                 swap    d2                      ; if size of mem-block is:
  259.                 move.w  d1,d2                   ; SIZE % 4 = 0
  260.                 subq.l  #4,d0
  261. .loop2          move.l  d2,(a1)+
  262.                 subq.l  #4,d0
  263.                 bcc.s   .loop2
  264.                 bra.s   .finished
  265.  
  266.                 cnop    0,4
  267. new_ID          equ     (*-NewBltClr)           ; Offsets for routine-ID and
  268. .ID             dc.l    "FAST"                  ; buffer for OldBltClr
  269. new_OldBltClr   equ     (*-NewBltClr)
  270. .OldBltClr      dc.l    0
  271.  
  272. NewBltClr_len   equ     (*-NewBltClr)           ; length of routine
  273.  
  274. ;***************************************************************************
  275. ;*                                                                         *
  276. ;* SEKTION: Daten, Zeiger                                                  *
  277. ;*                                                                         *
  278. ;***************************************************************************
  279.  
  280. gfxname         dc.b    "graphics.library",0
  281. dosname         dc.b    "dos.library",0
  282.         IFNE SECURECODE
  283. Header          dc.b    $9B,"1;33",$6D
  284.                 dc.b    "$VER: CPUClr "
  285.                 REVISION
  286.                 dc.b    " ("
  287.                 REVDATE
  288.                 dc.b    ")"
  289.                 dc.b    $9B,$6D
  290.                 dc.b    " coding by Peter Simons",$0A
  291. Header_len      equ     (*-Header)
  292.         ELSE
  293.                 dc.b    "$VER: "
  294. Header          dc.b    "CPUClr "
  295.                 REVISION
  296.                 dc.b    ": "
  297. Header_len      equ     (*-Header)
  298.         ENDC
  299.  
  300. Install         dc.b    "Installed"
  301. Install_len     equ     (*-Install)
  302. Remove          dc.b    "Removed"
  303. Remove_len      equ     (*-Remove)
  304. Returns         dc.b    "...",$0A,$0A
  305. Returns_len     equ     (*-Returns)
  306.  
  307.                 END
  308.