home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / DevPatch / DevPatchII.asm < prev    next >
Assembly Source File  |  1990-04-10  |  4KB  |  170 lines

  1.           OPT c+,l-
  2.  
  3. ****************************************
  4. * DevPatch II                          *
  5. * © J.Tyberghein N.François P.Marivoet *
  6. * Dec 1989                             *
  7. ****************************************
  8.  
  9.    incdir  ":include/"
  10.    include "exec/types.i"
  11.    include "exec/memory.i"
  12.    include "exec/ports.i"
  13.    include "exec/exec_lib.i"
  14.  
  15.    ;IntuitionBase routines
  16. _LVOOpenWindow  equ   -204
  17.    ;DosBase
  18. _LVOOutput      equ   -60
  19. _LVOWrite       equ   -48
  20.  
  21. nw_Title        equ   $1a
  22. nw_Height       equ   6
  23. PRI             equ   0
  24.  
  25.    ;*** Start code ***
  26.  
  27.    ;IntuitionLibrary
  28.       lea IntLib(PC),a1
  29.       CALLEXEC   OldOpenLibrary
  30.       move.l d0,_IntBase
  31.    ;DosLibrary
  32.       lea DosLib(PC),a1
  33.       CALLEXEC   OldOpenLibrary
  34.       move.l d0,_DosBase
  35.    ;Say we exist
  36.       lea StartupMsg(PC),a2
  37.       moveq #StartupMsgLen,d2
  38.       bsr myPuts
  39.    ;Test if the MsgPort exists
  40.       lea StartBlock(PC),a1
  41.       lea PortName(a1),a1
  42.       CALLEXEC FindPort
  43.       tst.l d0
  44.       bne.s PortAlreadyExists
  45.  
  46.    ;Create MsgPort
  47.       move.l #BlockLen,d0
  48.       move.l #MEMF_CLEAR+MEMF_PUBLIC,d1
  49.       CALLEXEC AllocMem
  50.       tst.l d0
  51.       beq CloseLib
  52.       move.l d0,Port
  53.       lea StartBlock(PC),a0
  54.       move.l d0,a1
  55.       move.l #BlockLen,d0
  56.       CALLEXEC CopyMem
  57.       move.l Port(PC),a1
  58.       lea PortName(a1),a0
  59.       move.l a0,LN_NAME(a1)
  60.       CALLEXEC AddPort
  61.    ;Install patch
  62.       move.l Port(PC),a1
  63.       lea OpenPatch(a1),a0
  64.       move.l a0,d0
  65.       move.l _IntBase(PC),a1
  66.       move.l #_LVOOpenWindow,a0
  67.       CALLEXEC   SetFunction
  68.       move.l Port(PC),a1
  69.       move.l d0,JmpLab1(a1)
  70.       lea PatchedMsg(PC),a2
  71.       moveq #PatchedMsgLen,d2
  72.       bsr.s myPuts
  73.       bra.s CloseLib
  74.  
  75. PortAlreadyExists:
  76.       move.l d0,a2
  77.    ;Remove patch
  78.       move.l JmpLab1(a2),d0
  79.       move.l _IntBase(PC),a1
  80.       move.l #_LVOOpenWindow,a0
  81.       CALLEXEC   SetFunction
  82.    ;Remove Port
  83.       move.l a2,a1
  84.       CALLEXEC RemPort
  85.    ;Free Patch memory
  86.       move.l a2,a1
  87.       move.l #BlockLen,d0
  88.       CALLEXEC FreeMem
  89.    ;Say it's done
  90.       lea RemovedMsg(PC),a2
  91.       moveq #RemovedMsgLen,d2
  92.       bsr.s myPuts
  93. CloseLib:
  94.    ;Close libraries
  95.       move.l _DosBase(PC),a1
  96.       CALLEXEC   CloseLibrary
  97.       move.l _IntBase(PC),a1
  98.       CALLEXEC   CloseLibrary
  99.       rts
  100.  
  101. myPuts:
  102.       move.l _DosBase(PC),a6
  103.       jsr _LVOOutput(a6)
  104.       move.l d0,d1
  105.       move.l d2,d3
  106.       move.l a2,d2
  107.       jsr _LVOWrite(a6)
  108.       rts
  109.  
  110. *****************************************************************************
  111.  
  112.    ;This is our MsgPort followed by our patch function
  113.    ;this data and code will be copied in one block
  114. StartBlock:
  115.       dc.l   0,0
  116.       dc.b   NT_MSGPORT,PRI
  117.       dc.l   0                     ;Pointer to our MsgPort name
  118.       dc.b   0,0
  119.       dc.l   0,0,0,0
  120.       dc.b   0,0
  121.  
  122. OpenPatch equ *-StartBlock
  123.       movem.l   d7/a2-a3,-(a7)
  124.       move.l nw_Title(a0),a2
  125.       lea Assembling(PC),a3
  126.       moveq #13,d7
  127. CmpLoop:
  128.       cmp.b (a2)+,(a3)+
  129.       dbne d7,CmpLoop
  130.       addq.w #1,d7
  131.       beq.s PatchIt
  132.       move.l nw_Title(a0),a2
  133.       lea DefaultOutput(PC),a3
  134.       moveq #21,d7
  135. CmpLoop2:
  136.       cmp.b (a2)+,(a3)+
  137.       dbne d7,CmpLoop2
  138.       addq.w #1,d7
  139.       bne.s NotDevpac
  140. PatchIt:
  141.       move.w #45,nw_Height(a0)
  142. NotDevpac:
  143.       movem.l (a7)+,d7/a2-a3
  144. JmpLab1 equ *+2-StartBlock
  145.       jmp $0.l
  146.  
  147. PortName equ *-StartBlock
  148.                  dc.b "DevPatch.port",0
  149. Assembling:      dc.b "Assembling...",0
  150. DefaultOutput:   dc.b "Default Output Window",0
  151.  
  152. BlockLen equ *-StartBlock
  153.  
  154. *****************************************************************************
  155.  
  156. _IntBase:     dc.l 0
  157. _DosBase:     dc.l 0
  158. Port:         dc.l 0
  159. IntLib:       dc.b "intuition.library",0
  160. DosLib:       dc.b "dos.library",0
  161. StartupMsg:   dc.b 27,"[33mDevPatch II",27,"[0m by PowerPeak",10,0
  162. StartupMsgLen equ *-StartupMsg
  163. PatchedMsg:   dc.b "Patch installed.",10,0
  164. PatchedMsgLen equ *-PatchedMsg
  165. RemovedMsg:   dc.b "Patch removed.",10,0
  166. RemovedMsgLen equ *-RemovedMsg
  167.  
  168.    END
  169.  
  170.