home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 249.lha / BrBox_v1.0 / BrBox.asm < prev    next >
Assembly Source File  |  1989-06-05  |  10KB  |  310 lines

  1. ;  Breakout Box V1.0
  2. ;    Displays a little window which shows the status of the serial
  3. ;    port bits:  Clear to Send (CTS), Ready to Send (RTS), Carrier
  4. ;    Detect (CD), Data Set Ready (DSR), Data Terminal Ready (DTR).
  5. ;    The program runs constantly, updating the display 5 times per
  6. ;    second.  It also monitors for a Close-gadget message from
  7. ;    intuition.
  8. ;
  9. ;    To execute:  From CLI,        BRBOX or RUN BRBOX or RUNBACK BRBOX
  10. ;             From WorkBench,    just double-click the icon
  11. ;
  12. ;    The monitor window has a drag bar hidden under the status
  13. ;    indicators, which means you can move it around on the WorkBench
  14. ;    window and get it out of your way.
  15. ;
  16. ;
  17. ****************************************************************************
  18. *
  19. *                   INCLUDE FILES
  20. *
  21. ****************************************************************************
  22.  
  23.     NOLIST                    ; don't list included files
  24.     INCLUDE    "exec/types.i"            ; for following includes
  25.     INCLUDE    "exec/alerts.i"            ; to access ALERT macro
  26.     INCLUDE "exec/ports.i"            ; to access message structure
  27.     INCLUDE    "libraries/dosextens.i"        ; to access process structure
  28.     INCLUDE    "intuition/intuition.i"        ; to access intuition structures
  29.  
  30. ****************************************************************************
  31. *
  32. *              External References
  33. *
  34. ****************************************************************************
  35.  
  36.     XREF    _AbsExecBase
  37.  
  38.     XREF    _LVOAlert
  39.     XREF    _LVOCloseLibrary
  40.     XREF    _LVOCloseWindow
  41.     XREF    _LVODelay
  42.     XREF    _LVOFindTask
  43.     XREF    _LVOForbid
  44.     XREF    _LVOGetMsg
  45.     XREF    _LVOOpenLibrary
  46.     XREF    _LVOOpenWindow
  47.     XREF    _LVOPrintIText
  48.     XREF    _LVOReplyMsg
  49.     XREF    _LVOWaitPort
  50.     XREF    _LVOWrite
  51.  
  52.     LIST                    ; turn on program listing
  53.  
  54.  
  55. ***************************************************************************
  56. *
  57. *                         Program Startup Code
  58. *
  59. ***************************************************************************
  60.  
  61. Begin:
  62.     move.l        #0,returnMsg        ; zap return message hold
  63.     move.l        sp,initialSP        ; initial task stack pointer
  64.     movea.l        _AbsExecBase,a6        ; get exec base
  65.     move.l        a6,ExecBase        ; save it off somewhere close
  66.     bsr        openDOS            ; attempt to open DOS library
  67.     bsr        openINT            ; open Intuition library
  68.  
  69.     suba.l        a1,a1            ; zero task name pointer
  70.     jsr        _LVOFindTask(a6)    ; get the address of this task
  71.     movea.l        d0,a4            ; task address in a4
  72.  
  73.     tst.l        pr_CLI(a4)        ; are we running in WB?
  74.     bne        DoMain            ; no, skip WB-specific stuff
  75.  
  76.     
  77. ***************************************************************************
  78. *
  79. *                  Workbench Startup Code
  80. *
  81. ***************************************************************************
  82.  
  83.     bsr        waitmsg            ; wait for start message
  84.     move.l        d0,returnMsg        ; save message for later
  85.  
  86. ***************************************************************************
  87. *
  88. *                      Main Program
  89. *
  90. ***************************************************************************
  91. DoMain:
  92.     bsr        DrawWind        ; draw display window
  93. check:
  94.     move.b        $BFD000,d3        ; grab CIAB data reg. 1 contents
  95.     lea        IText1,a1        ; get address of IntuiText 1
  96. chkbit:
  97.     move.l        a1,d0            ; is the address in a1 0?
  98.     beq        outofit            ; yes, end of loop
  99.     moveq        #3,d0            ; put a color 3 into d0
  100.     moveq        #0,d2            ; put a 0 into d2
  101.     asl.b        #1,d3            ; push top bit into Xtend flag
  102.     subx.b        d2,d0            ; sub d2(0) and X bit from d2(3)
  103.     move.b        d0,it_FrontPen(a1)    ; make foreground pen 2 or 3
  104.     movea.l        it_NextText(a1),a1    ; get address of next IntuiText
  105.     bra        chkbit            ; now check again
  106. outofit:
  107.     movea.l        windptr,a0        ; grab window pointer
  108.     movea.l        wd_RPort(a0),a0        ; get the RasterPort of window
  109.     lea        IText1,a1        ; snatch up the IText struct
  110.     moveq.l        #0,d0            ; set up left offset
  111.     moveq.l        #0,d1            ; ditto for top offset
  112.     movea.l        IntBase,a6        ; grab base of intuition lib.
  113.     jsr        _LVOPrintIText(a6)    ; print the texts
  114.     movea.l        windptr,a0        ; grab window pointer
  115.     movea.l        wd_UserPort(a0),a0    ; get UserPort from window
  116.     movea.l        ExecBase,a6        ; get Execbase
  117.     jsr        _LVOGetMsg(a6)        ; grab any messages pending
  118.     tst.l        d0            ; was there anything?
  119.     beq        endloop            ; no, just do it again
  120.     movea.l        d0,a1            ; message waiting: set up...
  121.     move.l        im_Class(a1),d4        ; to reply to it
  122.     move.w        im_Code(a1),d5        ; 
  123.     movea.l        im_IAddress(a1),a2    ;
  124.     jsr        _LVOReplyMsg(a6)    ; reply to message
  125.     cmpi.l        #CLOSEWINDOW,d4        ; was the message CLOSEWINDOW?
  126.     beq        bye            ; yep, we gotta go now!
  127. endloop:                    ; no CLOSEWINDOW message, loop!
  128.     movea.l        DOSBase,a6        ; DOS pointer
  129.     move.l        #10,d1            ; 10 20 ms clock ticks delay
  130.     jsr        _LVODelay(a6)        ; delay 1/5 second
  131.     bra        check            ; and check again
  132. ;
  133. ; termination code
  134. ;
  135. bye    movea.l        IntBase,a6        ; get intuition library base
  136.     movea.l        windptr,a0        ; set up to close the window
  137.     jsr        _LVOCloseWindow(a6)    ; shut that window!
  138.     moveq.l        #0,d0            ; sucess return code for CLI
  139.  
  140. exit
  141.     movea.l        initialSP,sp        ; restore stack pointer
  142.     move.l        d0,-(sp)        ; push return code
  143.     movea.l        ExecBase,a6        ; use exec library pointer
  144.     move.l        DOSBase,d0        ; get dos.library pointer
  145.     beq.s        1$            ; skip close if DOS.lib not open
  146.     movea.l        d0,a1            ; move lib base into a1
  147.     jsr        _LVOCloseLibrary(a6)    ; close dos.library
  148. 1$
  149.     move.l        IntBase,d0        ; now grab intuition.library ptr
  150.     beq.s        2$            ; zero, so no need to close
  151.     movea.l        d0,a1            ; put it where we can use it
  152.     jsr        _LVOCloseLibrary(a6)    ; close intuition.library
  153. 2$
  154.     move.l        returnMsg,d0        ; grab returnMsg
  155.     beq.s        3$            ; if zero, no need to return msg
  156.     jsr        _LVOForbid(a6)        ; so WB won't UnloadSeg us
  157.     movea.l        returnMsg,a1        ; startup message
  158.     jsr        _LVOReplyMsg(a6)    ; many happy returns!
  159. 3$
  160.     move.l        (sp)+,d0        ; pop result code from stack
  161.     rts                    ; this oughta take us home
  162.  
  163. *************************END OF NORMAL PROCESSING***************************
  164. *
  165. *            There be subroutines here! 
  166. *
  167. ****************************************************************************
  168. * This routine gets the message that Workbench will send to us
  169. *    - Called with task id in a4
  170. waitmsg
  171.     lea        pr_MsgPort(a4),a0    ; our process base
  172.     jsr        _LVOWaitPort(a6)    ; wait for a message
  173.     lea        pr_MsgPort(a4),a0    ; same old process base
  174.     jsr        _LVOGetMsg(a6)        ; get the message
  175.     rts
  176. ****************************************************************************
  177. * This routine draws the little monitor window.
  178. *
  179. DrawWind
  180.     movea.l        IntBase,a6        ; get Intuition base
  181.     lea        NewWind,a0        ; point to NewWindow struct
  182.     jsr        _LVOOpenWindow(a6)    ; open the puppy
  183.     move.l        d0,windptr        ; save the window pointer
  184.     rts
  185. ****************************************************************************
  186. * This routine opens the dos.library and saves its base pointer
  187. *
  188. openDOS
  189.     lea        DOS_Lib,a1        ; grab dos.library name
  190.     move.l        #LIBRARY_VERSION,d0    ; get library version
  191.     jsr        _LVOOpenLibrary(a6)    ; open dos.library
  192.     move.l        d0,DOSBase        ; save dos base
  193.     beq        noDOS            ; no dos.library, ALERT!
  194.     rts                    ; everything's cool.
  195. ****************************************************************************
  196. * Open the intuition.library and save its base pointer
  197. *
  198. openINT
  199.     lea        INT_Lib,a1        ; grab intuition.library name
  200.     moveq.l        #0,d0            ; version is irrelevant
  201.     jsr        _LVOOpenLibrary(a6)    ; open the library
  202.     move.l        d0,IntBase        ; save the base
  203.     rts
  204. ****************************************************************************
  205. * noDOS:  not no-DOZE, No-DOS!
  206. *
  207. noDOS:
  208.     ALERT        (AG_OpenLib!AO_DOSLib)    ; this wasn't my idea!
  209.     move.l        #100,d0            ; make like a hockey player &
  210.     bra        exit            ; get the puck out of here
  211.  
  212. ****************************************************************************
  213. *
  214. *        Program's DATA area
  215. *
  216. ****************************************************************************
  217.  
  218.         CNOP    0,2            ; even-out to word boundary
  219.     
  220. ExecBase    DC.L    0
  221. DOSBase        DC.L    0
  222. IntBase        DC.L    0
  223.  
  224. initialSP    DC.L    0
  225. returnMsg    DC.L    0
  226.  
  227. windptr        DC.L    0
  228.  
  229. NewWind        EQU    *
  230. LeftEdge    DC.W    0
  231. TopEdge        DC.W    0
  232. Width        DC.W    276
  233. Height        DC.W    10
  234. DetailPen    DC.B    -1        ; default forground
  235. BlockPen    DC.B    -1        ; default background
  236. IDCMPFlags    DC.L    CLOSEWINDOW
  237. Flags        DC.L    WINDOWCLOSE!SMART_REFRESH!WINDOWDRAG!WINDOWDEPTH
  238. FirstGadget    DC.L    0
  239. CheckMark    DC.L    0
  240. Title        DC.L    wtitle
  241. Scren        DC.L    0
  242. BitMp        DC.L    0
  243. MinWidth    DC.W    0
  244. MinHeight    DC.W    0
  245. MaxWidth    DC.W    0
  246. MaxHeight    DC.W    0
  247. Type        DC.W    WBENCHSCREEN
  248. *    end of NewWindow structure
  249.  
  250. IText1        EQU    *            ; IntuiText structure
  251.         DC.B    3            ; foreground pen
  252.         DC.B    1            ; background pen
  253.         DC.B    RP_JAM2            ; JAM2 drawing mode
  254.         DC.W    30            ; left edge offset
  255.         DC.W    1            ; top edge offset
  256.         DC.L    0            ; font structure pointer (def)
  257.         DC.L    text1            ; pointer to text
  258.         DC.L    IText2            ; pointer to next IntuiText
  259.  
  260. IText2        EQU    *            ; IntuiText structure
  261.         DC.B    2            ; foreground pen
  262.         DC.B    1            ; background pen
  263.         DC.B    RP_JAM2            ; JAM2 drawing mode
  264.         DC.W    70            ; left edge offset
  265.         DC.W    1            ; top edge offset
  266.         DC.L    0            ; font structure pointer (def)
  267.         DC.L    text2            ; pointer to text
  268.         DC.L    IText3            ; pointer to next IntuiText
  269.  
  270. IText3        EQU    *            ; IntuiText structure
  271.         DC.B    2            ; foreground pen
  272.         DC.B    1            ; background pen
  273.         DC.B    RP_JAM2            ; JAM2 drawing mode
  274.         DC.W    110            ; left edge offset
  275.         DC.W    1            ; top edge offset
  276.         DC.L    0            ; font structure pointer (def)
  277.         DC.L    text3            ; pointer to text
  278.         DC.L    IText4            ; pointer to next IntuiText
  279.  
  280. IText4        EQU    *            ; IntuiText structure
  281.         DC.B    2            ; foreground pen
  282.         DC.B    1            ; background pen
  283.         DC.B    RP_JAM2            ; JAM2 drawing mode
  284.         DC.W    140            ; left edge offset
  285.         DC.W    1            ; top edge offset
  286.         DC.L    0            ; font structure pointer (def)
  287.         DC.L    text4            ; pointer to text
  288.         DC.L    IText5            ; pointer to next IntuiText
  289.  
  290. IText5        EQU    *            ; IntuiText structure
  291.         DC.B    2            ; foreground pen
  292.         DC.B    1            ; background pen
  293.         DC.B    RP_JAM2            ; JAM2 drawing mode
  294.         DC.W    180            ; left edge offset
  295.         DC.W    1            ; top edge offset
  296.         DC.L    0            ; font structure pointer (def)
  297.         DC.L    text5            ; pointer to text
  298.         DC.L    0            ; pointer to next IntuiText
  299.  
  300. wtitle        DC.B    'Breakout Box V1.0',0
  301. text1        DC.B    ' DTR ',0
  302. text2        DC.B    ' RTS ',0
  303. text3        DC.B    ' CD ',0
  304. text4        DC.B    ' CTS ',0
  305. text5        DC.B    ' DSR ',0
  306. INT_Lib        DC.B    'intuition.library',0
  307. DOS_Lib        DC.B    'dos.library',0
  308.  
  309.         END
  310.