home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d03xx / d0302.lha / ProgUtils / Trace.asm < prev    next >
Assembly Source File  |  1990-01-15  |  6KB  |  320 lines

  1.             opt        c+,l-
  2.  
  3.     incdir    include/
  4.     include    intuition/intuitionbase.i
  5.     include    intuition/intuition.i
  6.  
  7. ;******************************
  8. ;* Trace Open and LoadSeg        *
  9. ;* ⌐ J.Tyberghein 29 sep 89    *
  10. ;******************************
  11.  
  12. SysBase            equ    4
  13.     ;ExecBase routines
  14. _LVOOldOpenLibrary    equ    -408
  15. _LVOCloseLibrary        equ    -414
  16. _LVOForbid                equ    -132
  17. _LVOPermit                equ    -138
  18. _LVOWaitPort            equ    -384
  19. _LVOGetMsg                equ    -372
  20. _LVOReplyMsg            equ    -378
  21.     ;DosBase routines
  22. _LVOOpen                    equ    -30
  23. _LVOOutput                equ    -60
  24. _LVOWrite                equ    -48
  25. _LVOLoadSeg                equ    -150
  26.     ;IntuitionBase routines
  27. _LVOOpenWindow            equ    -204
  28. _LVOCloseWindow        equ    -72
  29. _LVOSetWindowTitles    equ    -276
  30.     ;Graphics routines
  31. _LVOText                    equ    -60
  32. _LVOMove                    equ    -240
  33. _LVOScrollRaster        equ    -396
  34. _LVOSetAPen                equ    -342
  35.  
  36. CALLEXEC    macro
  37.             move.l (SysBase).w,a6
  38.             jsr _LVO\1(a6)
  39.             endm
  40.  
  41. CALLGRAF    macro
  42.             move.l GfxBase,a6
  43.             jsr _LVO\1(a6)
  44.             endm
  45.  
  46. CALLINT    macro
  47.             move.l IntBase,a6
  48.             jsr _LVO\1(a6)
  49.             endm
  50.  
  51. CALLDOS    macro
  52.             move.l DosBase,a6
  53.             jsr _LVO\1(a6)
  54.             endm
  55.  
  56.     ;*** Start code ***
  57.  
  58.         move.l    a0,ComLin
  59.         move.l    d0,ComLinLen
  60.     ;DosLibrary
  61.         lea        DosLib,a1
  62.         CALLEXEC    OldOpenLibrary
  63.         move.l    d0,DosBase
  64.     ;IntuitionLibrary
  65.         lea        IntLib,a1
  66.         CALLEXEC    OldOpenLibrary
  67.         move.l    d0,IntBase
  68.     ;GfxLibrary
  69.         lea        GfxLib,a1
  70.         CALLEXEC    OldOpenLibrary
  71.         move.l    d0,GfxBase
  72.  
  73.     ;Get current OutputHandle
  74.         CALLDOS    Output
  75.         move.l    d0,OutputHandle
  76.  
  77.     ;Check arguments
  78.         move.b    #0,SmallWin
  79.         lea        NWin,a0
  80.         move.w    #300,nw_Width(a0)
  81.         cmp.l        #3,ComLinLen
  82.         blt.s        NoSmallWin
  83.         move.w    #350,nw_Width(a0)
  84.         move.l    ComLin,a0
  85.         cmp.b        #'s',2(a0)
  86.         bne.s        ErrorArg
  87.         move.b    #1,SmallWin
  88.         lea        NWin,a0
  89.         move.w    #10,nw_Height(a0)
  90.         move.l    #0,nw_FirstGadget(a0)
  91. NoSmallWin:
  92.         move.l    ComLin,a0
  93.         cmp.b        #'o',(a0)
  94.         beq.s        OpenTrace
  95.         cmp.b        #'l',(a0)
  96.         beq.s        LoadSegTrace
  97. ErrorArg:
  98.         move.l    OutputHandle,d1
  99.         move.l    #UsageString,d2
  100.         move.l    #UsageStringLen,d3
  101.         CALLDOS    Write
  102.         bra        ErrorOW
  103. OpenTrace:
  104.         move.l    #_LVOOpen,Offset
  105.         move.l    #WoTitle,WinTitle
  106.         move.l    #-1,DosNum
  107.         bra.s        Continue
  108. LoadSegTrace:
  109.         move.l    #_LVOLoadSeg,Offset
  110.         move.l    #WlTitle,WinTitle
  111.         move.l    #-19,DosNum
  112.  
  113. Continue:
  114.         tst.b        SmallWin
  115.         beq.s        NoSmW
  116.         move.l    #0,WinTitle
  117. NoSmW:
  118.         bsr        OpenWin
  119.         tst.l        d0
  120.         beq        ErrorOW
  121.  
  122.     ;Install Patch
  123.         CALLEXEC    Forbid
  124.         move.l    DosBase,a0
  125.         move.l    Offset,d0
  126.         move.w    (a0,d0),SaveSetF
  127.         move.l    2(a0,d0),SaveSetF+2
  128.         move.w    #$4ef9,(a0,d0)
  129.         move.l    #Patch,2(a0,d0)
  130.         move.l    DosBase,d0
  131.         add.l        #$4e,d0
  132.         move.l    d0,LabelJmp+2
  133.         CALLEXEC    Permit
  134.  
  135.     ;Wait for windowclose or gadget
  136. WaitUser:
  137.         move.l    UserPort,a0
  138.         CALLEXEC    WaitPort
  139.         move.l    UserPort,a0
  140.         CALLEXEC    GetMsg
  141.         move.l    d0,a0
  142.         move.l    im_Class(a0),d2
  143.         move.w    im_Code(a0),d3
  144.         move.l    a0,a1
  145.         CALLEXEC    ReplyMsg
  146.         and.l        #MOUSEBUTTONS,d2
  147.         beq.s        TheEnd
  148.         cmp.w        #MENUUP,d3
  149.         bne.s        WaitUser
  150.     ;The user pressed the right mouse button, so move the window to the first screen
  151.         move.l    Win,a0
  152.         CALLINT    CloseWindow
  153.         bsr        OpenWin
  154.         tst.l        d0
  155.         bne.s        WaitUser
  156.         bsr        EndPatch
  157.         bra.s        ErrorOW
  158.  
  159. TheEnd:
  160.         bsr        EndPatch
  161.         move.l    Win,a0
  162.         CALLINT    CloseWindow
  163.  
  164. ErrorOW:
  165.         move.l    GfxBase,a1
  166.         CALLEXEC    CloseLibrary
  167.         move.l    DosBase,a1
  168.         CALLEXEC    CloseLibrary
  169.         move.l    IntBase,a1
  170.         CALLEXEC    CloseLibrary
  171.         rts
  172.  
  173.     ;*** Restore patch ***
  174. EndPatch:
  175.         CALLEXEC    Forbid
  176.         move.l    DosBase,a0
  177.         move.l    Offset,d0
  178.         move.w    SaveSetF,(a0,d0)
  179.         move.l    SaveSetF+2,2(a0,d0)
  180.         CALLEXEC    Permit
  181.         rts
  182.  
  183.     ;*** Open window on first screen ***
  184.     ;-> d0 = 0 if error
  185.     ;***
  186. OpenWin:
  187.         move.l    IntBase,a1
  188.         lea        NWin,a0
  189.         move.l    ib_FirstScreen(a1),nw_Screen(a0)
  190.         move.l    WinTitle,nw_Title(a0)
  191.         CALLINT    OpenWindow
  192.         tst.l        d0
  193.         beq.s        ErrorOWi
  194.         move.l    d0,Win
  195.         move.l    d0,a0
  196.         move.l    wd_RPort(a0),rp
  197.         move.l    wd_UserPort(a0),UserPort
  198.         moveq        #1,d0
  199. ErrorOWi:
  200.         rts
  201.  
  202.     ;*** New patch function ***
  203.     ;Print file name
  204.     ;***
  205. Patch:
  206.         movem.l    a6/d1-d5,-(a7)
  207.         tst.b        SmallWin
  208.         bne.s        SkipDraw
  209.         move.l    d1,-(a7)                ;We have a large window
  210.         move.l    rp,a1
  211.         moveq        #0,d0
  212.         moveq        #10,d1
  213.         moveq        #2,d2
  214.         moveq        #12,d3
  215.         move.l    #286,d4
  216.         move.l    #51,d5
  217.         CALLGRAF    ScrollRaster        ;Scroll window one line up
  218.         move.l    rp,a1
  219.         moveq        #1,d0                    ;White
  220.         CALLGRAF    SetAPen
  221.         move.l    rp,a1
  222.         moveq        #10,d0
  223.         moveq        #0,d1
  224.         move.w    #50,d1
  225.         CALLGRAF    Move
  226.         move.l    (a7)+,d1                ;Restore string ptr (argument in d1)
  227.         move.l    rp,a1
  228.         move.l    d1,a0
  229.         bsr        StrLen
  230.         cmp.l        #34,d0
  231.         ble.s        AllRight
  232.         moveq        #34,d0
  233. AllRight:
  234.         move.l    d1,a0
  235.         CALLGRAF    Text
  236.         bra.s        ContPatch
  237. SkipDraw:
  238.         move.l    Win,a0
  239.         moveq        #32,d0
  240.         move.l    d1,a1
  241.         lea        String,a2
  242. LoopSWT:
  243.         move.b    (a1),(a2)+
  244.         tst.b        (a1)+
  245.         beq.s        TheEndSWT
  246.         subq.l    #1,d0
  247.         bne.s        LoopSWT
  248.         move.b    #0,(a2)+
  249. TheEndSWT:
  250.         lea        String,a1
  251.         move.l    #0,a2
  252.         CALLINT    SetWindowTitles
  253. ContPatch:
  254.         movem.l    (a7)+,a6/d1-d5
  255.         move.l    DosNum,d0
  256. LabelJmp:
  257.         jmp        $00000000
  258.  
  259.     ;*** String length ***
  260.     ;a0 = string address
  261.     ;-> d0 = length
  262.     ;***
  263. StrLen:
  264.         moveq        #-1,d0
  265. LoopSL:
  266.         addq.l    #1,d0
  267.         tst.b        (a0)+
  268.         bne.s        LoopSL
  269.         rts
  270.  
  271.     EVEN
  272. DosBase:            dc.l    0
  273. IntBase:            dc.l    0
  274. GfxBase:            dc.l    0
  275.     ;Old SetFunction address
  276. SaveSetF:        dc.w    0
  277.                     dc.l    0
  278. rp:                dc.l    0                ;RastPort
  279. Win:                dc.l    0                ;Window
  280. UserPort:        dc.l    0                ;Window user port
  281. OutputHandle:    dc.l    0
  282. Offset:            dc.l    0                ;Offset of function
  283. WinTitle:        dc.l    0                ;Current window title
  284. DosNum:            dc.l    0                ;Number for dos.library (intern)
  285. ComLin:            dc.l    0                ;Address of arguments to this command
  286. ComLinLen:        dc.l    0                ;Length of argumentstring
  287. SmallWin:        dc.b    0                ;1 if a small window is required
  288.  
  289. String:            ds.b    35                ;Space for windowtitle
  290.  
  291.  
  292.     ;Library names
  293. DosLib:            dc.b    "dos.library",0
  294. IntLib:            dc.b    "intuition.library",0
  295. GfxLib:            dc.b    "graphics.library",0
  296.  
  297. WoTitle:            dc.b    "Open trace",0
  298. WlTitle:            dc.b    "LoadSeg trace",0
  299.  
  300. UsageString:    dc.b    "Usage: Trace o | l [s]",10,0
  301. UsageStringLen    equ    *-UsageString
  302.  
  303.     EVEN
  304.     ;Window
  305. NWin:
  306.         dc.w        0,0,300,58
  307.         dc.b        2,1
  308.         dc.l        CLOSEWINDOW+MOUSEBUTTONS
  309.         dc.l        WINDOWDEPTH+WINDOWDRAG+WINDOWCLOSE+RMBTRAP+REPORTMOUSE
  310.         dc.l        0
  311.         dc.l        0
  312.         dc.l        0
  313.         dc.l        0,0
  314.         dc.w        0,0,0,0
  315.         dc.w        CUSTOMSCREEN
  316.  
  317.     END
  318.  
  319.  
  320.