home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d543 / td.lha / TD / TD.asm < prev    next >
Assembly Source File  |  1991-09-20  |  12KB  |  450 lines

  1. *    TD
  2. *    By Preben Nielsen
  3. *
  4. *    Based on 'TrackDisplay' on Fish-disk 399 by Olaf Barthel.
  5. *
  6. *      TD is a program that continuously monitors and displays
  7. *    the current track for each connected floppy disk.
  8. *
  9. *      The size of the window and the use of colors in it depends on
  10. *    the version of the Kickstart/Workbench (1.2/1.3 vs. 2.?).
  11. *
  12. *    NOTE:    There's no need to 'RUN' or 'RUNBACK' this program from the
  13. *        CLI. It is auto-detaching.
  14. *
  15. *HISTORY
  16. *          Made with Hisoft V2.12
  17. *           January: Recieved 'Trackdisplay' on Fish-disk 399.
  18. *                    Nice program Olaf. Thanks.
  19. *
  20. *  V1.0   03-Mar-91: First working version.
  21. *         04-Mar-91: Added auto-detaching code.
  22. *         07-Mar-91: Uses 'PrintIText' instead of 'Move'/'Text'. Because of
  23. *                    this, my version used nearly twice the amount of
  24. *                    processor-time as the original (according to Xoper).
  25. *         15-Mar-91: Now uses 'Move'/'Text'. Code is now larger but faster.
  26. *         19-Apr-91: Made some modifications to make it look better
  27. *                    under WB2.0 (haven't actually tried it yet)
  28. *  V1.1   02-Aug-91: Damned - why didn't anyone tell me that TD looked
  29. *                    awful (strange) under kickstart 1.3. It thought it
  30. *                    it was running under kickstart 2.x, and therefore
  31. *                    changed its own appearance ! Not only didn't it look
  32. *                    good - it also didn't work correctly as a trackdisplay
  33. *                    because of differences between 1.3 and 2.x. Well, all
  34. *                    that has been fixed now. TD looks a lot better than the
  35. *                    original 'TrackDisplay' when running under 2.x.
  36. *         08-Aug-91: Now the opened window is as high as the dragbar of
  37. *                    all the other windows on the WB-screen.
  38. *  V2.0   09-Aug-91: Now TD only shows the drives which are available.
  39. *         22-Aug-91: Now TD can perfecty emulate the 2.x way of using
  40. *                    colors in windows.
  41.  
  42.     OPT O+
  43.     OPT O1+            ; Tells when a branch could be optimised to short
  44.     OPT i+            ; Tells when '#' is probably missing
  45.  
  46.         incdir        "AsmInc:"
  47.         include        "P.i"
  48.         include        "Detach.i"
  49.         include        "relMacros.i"
  50.         include        "exec/exec_lib.i"
  51.         include        "exec/memory.i"
  52.         include        "exec/interrupts.i"
  53.         include        "exec/ports.i"
  54.         include        "intuition/intuition.i"
  55.         include        "intuition/intuitionbase.i"
  56.         include        "intuition/intuition_lib.i"
  57.         include        "graphics/graphics_lib.i"
  58.         include        "libraries/dos_lib.i"
  59.         include        "libraries/dos.i"
  60.         include        "libraries/dosextens.i"
  61.         include        "hardware/intbits.i"
  62.         include        "devices/trackdisk.i"
  63.  
  64. * My Unit structure
  65. MU_Unit        =0            ; Address of drive-unit
  66. MU_Number    =4            ; Track number
  67. MU_SIZE        =6
  68.  
  69. DB        EQUR        A4
  70.  
  71.  dcDeclare    A4
  72.  dcAPtr        TDProcess        ; This process 
  73.  dcAPtr        WBenchMsg        ; Message from Workbench
  74.  dcAPtr        GraphBase
  75.  dcAPtr        IntuiBase
  76.  dcAPtr        DWindow            ; APtr to Window
  77.  dcAPtr        Rp            ; APtr to RastPort
  78.  dcAPtr        Up            ; APtr to UserPort
  79.  dcAPtr        Font            ; APtr to Topaz-80
  80.  dcWord        StrLength
  81.  dcArea        IOExtTD,IOTD_SIZE    ; IOExtTD structure
  82.  dcArea        TDPort,MP_SIZE        ; MessagePort structure
  83.  dcArea        TDInterrupt,IS_SIZE    ; Interrupt structure
  84.  dcArea        Drive0,MU_SIZE
  85.  dcArea        Drive1,MU_SIZE
  86.  dcArea        Drive2,MU_SIZE
  87.  dcArea        Drive3,MU_SIZE
  88.  dcWord        yPos            ; y-position of text in window
  89.  dcWord        Height            ; Height of window
  90.  dcWord        xPos            ; x-position of text in window
  91.  dcWord        Width            ; Width of window
  92.  dcWord        UOffset            ; Offset into unit structure (to get to track indicator)
  93.  dcWord        Version            ; Kickstart version ID
  94.  dcArea        TDDrives,32        ; Yes, 32.
  95.  dcEnd
  96.  
  97. Start        DetachSingle    <'TD'>,4000,0
  98.         dcAlloc                    ; Allocate memory for variables
  99.         dcReset                    ; Clear the memory
  100.         lea        TxtAttr(PC),A0        ; To avoid reloc32 hunks
  101.         lea        FontName(PC),A1
  102.         move.l        A1,(A0)
  103.         Prepare        Exec_Call
  104.         lea        Settings1.3H(PC),A0
  105.         cmp.w        #34,LIB_VERSION(A6)
  106.         ble.S        1$
  107.         lea        Settings2.0H(PC),A0
  108. 1$        movem.l        (A0),D0-D1
  109.         movem.l        D0-D1,Version(DB)    ; Initialize variables
  110.         suba.l        A1,A1
  111.         CallLib        FindTask        ; Find us
  112.         move.l        D0,TDProcess(DB)
  113.         move.l        D0,A2
  114.         tst.l        pr_CLI(A2)
  115.         bne.S        GetLibs            ; Also works after segment-splitting
  116.         lea        pr_MsgPort(A2),A0
  117.         CallLib        WaitPort        ; wait for a message
  118.         lea        pr_MsgPort(A2),A0
  119.         CallLib        GetMsg            ; then get it
  120.         move.l        D0,WBenchMsg(DB)    ; save it for later reply
  121. GetLibs        lea        GfxName(PC),A1
  122.         CallLib        OldOpenLibrary
  123.         move.l        D0,GraphBase(DB)
  124.         beq        Error
  125.         lea        IntuiName(PC),A1
  126.         CallLib        OldOpenLibrary
  127.         move.l        D0,IntuiBase(DB)
  128.         beq        Error
  129. GetIOExtTD    moveq        #-1,D0
  130.         CallLib        AllocSignal
  131.         cmpi.b        #-1,D0
  132.         beq        Error
  133.         lea        TDPort(DB),A0
  134.         clr.b        MP+LN_PRI(A0)            ; MsgPort->mp_Node.ln_Pri =Pri
  135.         move.b        #NT_MSGPORT,MP+LN_TYPE(A0)    ; MsgPort->mp_Node.ln_Type=NT_MSGPORT
  136.         move.b        #PA_SIGNAL,MP_FLAGS(A0)        ; MsgPort->mp_Flags      =PA_SIGNAL
  137.         move.b        D0,MP_SIGBIT(A0)        ; MsgPort->mp_SigBit      =MPSigBit
  138.         lea        TDPort(DB),A1
  139.         move.l        TDProcess(DB),MP_SIGTASK(A1)    ; MsgPort->mp_SigTask     =FindTask(0)
  140.         CallLib        AddPort
  141.         lea        IOExtTD(DB),A1
  142.         move.b        #NT_MESSAGE,IO+MN+LN_TYPE(A1)    ; IOExtTD->io_Message.mn_Node.ln_Type=NT_MESSAGE
  143.         clr.b        IO+MN+LN_PRI(A1)        ; IOExtTD->io_Message.mn_Node.ln_Pri =0
  144.         lea        TDPort(DB),A0
  145.         move.l        A0,IO+MN_REPLYPORT(A1)        ; IOExtTD->io_Message.mn_ReplyPort   =Rep
  146. GetUnits    lea        Drive0(DB),A2        ; See which drives are available
  147.         lea        TDDrives(DB),A3
  148.         moveq        #0,D2
  149.         moveq        #0,D3
  150. 1$;        clr.l        MU_Unit(A2)
  151.         not.w        MU_Number(A2)        ; Was 0, now -1
  152.         move.l        D2,D0
  153.         moveq        #0,D1
  154.         lea        TrackName(PC),A0
  155.         lea        IOExtTD(DB),A1
  156.         CallLib        OpenDevice
  157.         tst.l        D0
  158.         bne.S        2$
  159.         move.b        #'D',(A3)+        ; Create 'DFx: ?? '
  160.         move.b        #'F',(A3)+
  161.         move.b        #'0',(A3)
  162.         add.b        D2,(A3)+
  163.         move.b        #':',(A3)+
  164.         move.b        #' ',(A3)+
  165.         addq.l        #2,A3
  166.         move.b        #' ',(A3)+
  167.         addq.w        #1,D3
  168.         lea        IOExtTD(DB),A1        ; Oh yeah, drive is available
  169.         move.l        IO_UNIT(A1),MU_Unit(A2)    ; Store address of unit-structure
  170.         CallLib        CloseDevice        ; Close Unit again
  171. 2$        subq.l        #MU_SIZE,A2
  172.         addq.l        #1,D2
  173.         cmp.w        #4,D2
  174.         blt.S        1$
  175.         move.w        D3,D0
  176.         mulu        #7,D3
  177.         subq.w        #1,D0
  178.         bmi        Error
  179.         add.w        D0,D3
  180.         move.w        D3,StrLength(DB)
  181.         mulu        #8,D3
  182.         add.w        D3,Width(DB)
  183. GetWindow    Prepare        Intuition_Call
  184.         CallLib        OpenWorkBench
  185.         tst.l        D0
  186.         beq        Error
  187.         move.l        D0,A1
  188.         move.w        sc_Width(A1),D0
  189.         sub.w        Width(DB),D0
  190.         lsr.w        #1,D0
  191.         lea        NW(PC),A0
  192.         move.w        D0,nw_LeftEdge(A0)    ; Center the window
  193.         moveq        #0,D1
  194.         move.b        sc_BarHeight(A1),D1
  195.         tst.w        Version(DB)
  196.         beq.S        1$
  197.         addq.w        #1,D1            ; Because of newlook
  198. 1$        move.w        D1,Height(DB)
  199.         subq.w        #7,D1
  200.         lsr.w        #1,D1
  201.         addq.w        #6,D1
  202.         move.w        D1,yPos(DB)
  203.         move.w        Width(DB),nw_Width(A0)
  204.         move.w        Height(DB),nw_Height(A0)
  205.         CallLib        OpenWindow
  206.         move.l        D0,DWindow(DB)
  207.         beq        Error
  208.         move.l        D0,A0
  209.         move.l        wd_RPort(A0),Rp(DB)
  210.         move.l        wd_UserPort(A0),Up(DB)    ; UserPort
  211.         move.l        DWindow(DB),A0
  212.         suba.l        A1,A1
  213.         lea        ScrTitle(PC),A2
  214.         CallLib        SetWindowTitles
  215.         Prepare        Gfx_Call
  216.         move.l        Rp(DB),A2
  217.         moveq        #0,D0            ; Assume 1.3 colors
  218.         moveq        #1,D2
  219.         tst.w        Version(DB)
  220.         beq.S        2$
  221.         exg        D0,D2            ; Well, use 2.0 colors
  222. 2$        move.l        A2,A1
  223.         CallLib        SetAPen
  224.         move.l        A2,A1
  225.         move.w        D2,D0
  226.         CallLib        SetBPen
  227.         move.l        A2,A1
  228.         moveq        #RP_JAM2,D0
  229.         CallLib        SetDrMd
  230.         lea        TxtAttr(PC),A0
  231.         CallLib        OpenFont
  232.         move.l        D0,Font(DB)
  233.         beq.S        Error
  234.         move.l        D0,A0
  235.         move.l        A2,A1
  236.         CallLib        SetFont
  237. SetInterrupt    Prepare        Exec_Call
  238.         lea        TDInterrupt(DB),A1        ; Start vertical-blanking interrupt-server
  239.         move.b        #NT_INTERRUPT,LN_TYPE(A1)    ; TDInterrupt->is_Node.ln_Type=NT_INTERRUPT
  240.         lea        TDIntName(PC),A0
  241.         move.l        A0,LN_NAME(A1)            ; TDInterrupt->is_Node.ln_Name=TDIntName
  242.         lea        TDIntServer(PC),A0
  243.         move.l        A0,IS_CODE(A1)            ; TDInterrupt->is_Code          =TDIntServer
  244.         move.l        DB,IS_DATA(A1)            ; TDInterrupt->is_Data          =DB
  245.         moveq        #INTB_VERTB,D0
  246.         CallLib        AddIntServer
  247.         bra        Main
  248.  
  249. Exit
  250. Error
  251. FreeInterrupt    Prepare        Exec_Call
  252.         lea        TDInterrupt(DB),A1
  253.         tst.l        IS_CODE(A1)        ; If this is set then server has been added
  254.         beq.S        FreeFont
  255.         moveq        #INTB_VERTB,D0
  256.         CallLib        RemIntServer
  257. FreeFont    Prepare        Gfx_Call
  258.         move.l        Font(DB),D0
  259.         beq.S        FreeWindow
  260.         move.l        D0,A1
  261.         CallLib        CloseFont
  262. FreeWindow    Prepare        Intuition_Call
  263.         move.l        DWindow(DB),D0
  264.         beq.S        FreePort
  265.         move.l        D0,A0
  266.         CallLib        CloseWindow
  267. FreePort    Prepare        Exec_Call
  268.         lea        TDPort(DB),A2
  269.         tst.b        MP_SIGBIT(A2)        ; If we have bit we also have port
  270.         beq.S        FreeIntui
  271.         move.l        A2,A1
  272.         CallLib        RemPort
  273.         moveq        #0,D0
  274.         move.b        MP_SIGBIT(A2),D0
  275.         CallLib        FreeSignal
  276. FreeIntui    move.l        IntuiBase(DB),D0
  277.         beq.S        FreeGfx
  278.         move.l        D0,A1
  279.         CallLib        CloseLibrary
  280. FreeGfx        move.l        GraphBase(DB),D0
  281.         beq.S        ReplyWB
  282.         move.l        D0,A1
  283.         CallLib        CloseLibrary
  284. ReplyWB        move.l        WBenchMsg(DB),D2
  285.         beq.S        AllDone
  286.         CallLib        Forbid
  287.         move.l        D2,A1
  288.         CallLib        ReplyMsg        ; Reply WBenchMessage if we are started from WB
  289. AllDone        dcFree
  290.         moveq        #0,D0
  291.         rts
  292.  
  293. Main
  294. EventLoop    move.l        Up(DB),A0
  295.         moveq        #0,D0
  296.         moveq        #0,D1
  297.         move.b        MP_SIGBIT(A0),D1
  298.         bset        D1,D0
  299.         bset        #SIGBREAKB_CTRL_D,D0
  300.         Prepare        Exec_Call
  301.         CallLib        Wait
  302.         btst        #SIGBREAKB_CTRL_D,D0
  303.         beq.S        GetNextMsg
  304.         lea        TDDrives+5(DB),A1
  305.         lea        Drive0(DB),A0
  306.         moveq        #'0',D2
  307.         moveq        #0,D1
  308. 1$        move.w        MU_Number(A0),D0
  309.         bmi.S        2$
  310.         ext.l        D0
  311.         divu        #10,D0
  312.         add.w        D2,D0
  313.         move.b        D0,(A1)
  314.         swap        D0
  315.         add.w        D2,D0
  316.         move.b        D0,1(A1)
  317.         addq.l        #8,A1
  318. 2$        subq.l        #MU_SIZE,A0
  319.         addq.w        #1,D1
  320.         cmp.w        #4,D1
  321.         blt.S        1$
  322.         Call        UpdateDisplay
  323.         bra.S        EventLoop
  324.  
  325. GetNextMsg    move.l        Up(DB),A0
  326.         Prepare        Exec_Call
  327.         CallLib        GetMsg
  328.         tst.l        D0
  329.         beq.S        EventLoop
  330.         move.l        D0,A1
  331.         move.l        im_Class(A1),D2
  332.         CallLib        ReplyMsg
  333.         cmp.l        #CLOSEWINDOW,D2
  334.         beq        Exit
  335.         tst.w        Version(DB)        ; No need to change color
  336.         beq.S        3$            ; under 1.2/1.3
  337.         cmp.l        #ACTIVEWINDOW,D2
  338.         bne.S        1$
  339.         Call        GetBackColor
  340.         move.w        D0,D2
  341.         Call        GetFrontColor
  342.         bra.S        2$
  343. 1$        cmp.l        #INACTIVEWINDOW,D2
  344.         bne.S        3$
  345.         moveq        #0,D2
  346.         moveq        #1,D0
  347. 2$        Prepare        Gfx_Call
  348.         move.l        Rp(DB),A1
  349.         CallLib        SetAPen
  350.         move.w        D2,D0
  351.         move.l        Rp(DB),A1
  352.         CallLib        SetBPen
  353. 3$        Call        UpdateDisplay        ; Do some refreshing
  354.         bra.S        GetNextMsg
  355.  
  356. UpdateDisplay    Prepare        Gfx_Call
  357.         move.l        Rp(DB),A1
  358.         move.w        xPos(DB),D0
  359.         move.w        yPos(DB),D1
  360.         CallLib        Move
  361.         lea        TDDrives(DB),A0
  362.         move.l        Rp(DB),A1
  363.         move.w        StrLength(DB),D0
  364.         CallLib        Text
  365.         rts
  366.  
  367. *»»» Call:    A1 = DB
  368. *»»» Inside the server the registers D0-D1/A0-A1/A5-A6 can be used
  369. *»»» without restoring them on exit
  370. TDIntServer    Push        D2/DB
  371.         move.l        A1,DB
  372.         moveq        #0,D2            ; Don't signal
  373.         lea        Drive3(DB),A0
  374.         moveq        #3,D1
  375. 1$        move.l        MU_Unit(A0),D0
  376.         beq.S        2$            ; Does drive exist
  377.         move.l        D0,A1
  378.         add.w        UOffset(DB),A1
  379.         move.w        (A1),D0
  380.         asr.w        #1,D0
  381.         cmp.w        MU_Number(A0),D0
  382.         beq.S        2$
  383.         move.w        D0,MU_Number(A0)
  384.         moveq        #1,D2            ; Do signal
  385. 2$        addq.l        #MU_SIZE,A0
  386.         dbf        D1,1$
  387.         tst.w        D2
  388.         beq.S        3$
  389.         move.l        TDProcess(DB),A1
  390.         move.l        #SIGBREAKF_CTRL_D,D0
  391.         Prepare        Exec_Call
  392.         CallLib        Signal
  393. 3$        Pop        D2/DB
  394.         rts
  395.  
  396.  
  397. *»»» These routines return the colors that Kickstart 2.x uses for
  398. *»»» title-text and window-frames in active windows. Perhaps I
  399. *»»» am using system-private values here - I didn't have access
  400. *»»» Kickstart 2.x includes and autodocs when I wrote this.
  401. *»»»
  402. *»»» Return:    D0 = Color used for title-text in active windows.
  403. GetFrontColor    moveq        #12,D0
  404.         bra.S        GetColor
  405. *»»» Return:    D0 = Color used for window-frames in active windows.
  406. GetBackColor    moveq        #10,D0
  407. GetColor    move.l        DWindow(DB),A0
  408.         move.l        wd_WScreen(A0),A0
  409.         move.l        $1DE+4(A0),A0
  410.         move.w        0(A0,D0.W),D0
  411.         rts
  412.  
  413. GfxName        dc.b        'graphics.library',0
  414. IntuiName    dc.b        'intuition.library',0
  415. TrackName    dc.b        'trackdisk.device',0
  416. TDIntName    dc.b        'TD Interrupt',0
  417. ScrTitle    dc.b        'TD V2.0 1991 by Preben Nielsen.',0
  418.         EVEN
  419.  
  420. Kick1        =0
  421. *»»» Defines for hires under kickstart 1.2-1.3 (and below ?)
  422. Offset1.3    =74
  423. Width1.3H    =85        ; Gadget size
  424. xPos1.3H    =30
  425.  
  426. Kick2        =1
  427. *»»» Defines for hires under kickstart 2.0 (and up ?)
  428. Offset2.0    =54
  429. Width2.0H    =51        ; Gadget size
  430. xPos2.0H    =23
  431.  
  432. Settings1.3H    dc.w        Kick1,Offset1.3,Width1.3H,xPos1.3H
  433. Settings2.0H    dc.w        Kick2,Offset2.0,Width2.0H,xPos2.0H
  434.  
  435. IDCMP_Flags    =        CLOSEWINDOW|INACTIVEWINDOW|ACTIVEWINDOW
  436. Other_Flags    =        RMBTRAP|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG
  437. NW        dc.w        0,0,0,0
  438.         dc.b        0,1
  439.         dc.l        IDCMP_Flags,Other_Flags
  440.         dc.l        0,0,0,0,0
  441.         dc.w        0,0,0,0,WBENCHSCREEN
  442.  
  443. TxtAttr        dc.l        0
  444.         dc.w        TOPAZ_EIGHTY
  445.         dc.b        FS_NORMAL,FPB_ROMFONT
  446. FontName    dc.b        'topaz.font',0
  447.         END
  448.  
  449.