home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / reqchang.run / ReqChange / Extra / SignalRC.a < prev    next >
Encoding:
Text File  |  1992-08-05  |  3.9 KB  |  200 lines

  1.  
  2. *********************************************************************
  3. *
  4. *  Small program to send any SIGBREAKF_CTRL_? signal to ReqChange
  5. *  (these signals are also know as break c, d, e and f). Works on
  6. *  both OS 1.2/1.3 and OS 2.0.
  7. *  Should assemble ok with most assemblers.
  8. *
  9. *  Public Domain 1992. Written by Magnus Holmgren.
  10. *
  11. *********************************************************************
  12.  
  13.     IFD    __G2
  14.         OPT    O+        ; Optimizing on
  15.     ENDC
  16.  
  17.  
  18.     INCDIR    INC:
  19.     INCLUDE    exec/types.i
  20.     INCLUDE    exec/exec_lib.i        ; _LVO definitions for exec.library
  21.     INCLUDE    exec/execbase.i
  22.     INCLUDE    exec/ports.i
  23.     INCLUDE    dos/dos.i
  24.     INCLUDE    dos/dosextens.i
  25.     INCLUDE    dos/dos_lib.i        ; _LVO definitions for dos.library
  26.     INCLUDE    workbench/icon_lib.i    ; _LVO definitions for icon.library
  27.     INCLUDE    workbench/startup.i
  28.     INCLUDE    workbench/workbench.i
  29.  
  30.  
  31. ;
  32. ; Macro for calling library routines. Parameter 1 is the offset to the
  33. ; routine.
  34. ;
  35.  
  36. SYS    MACRO    ; _LVO
  37.     IFC    "\1",""
  38.     FAIL    "SYS macro: No _LVO"
  39.     ENDC
  40.  
  41.     jsr    _LVO\1(a6)              ; Call library routine
  42.     ENDM
  43.  
  44.  
  45. ;
  46. ; Macro to clear data register. "CLD x" clears data register x.
  47. ;
  48.  
  49. CLD    MACRO    ; Registernumber
  50.  
  51.     IFC    "\1",""
  52.     FAIL    "CLD macro: No registernumber"
  53.     ENDC
  54.  
  55.     moveq    #0,d\1
  56.     ENDM
  57.  
  58.  
  59. Start    CLD    7
  60.     CLD    6
  61.     CLD    5
  62.     move.l    Default(pc),d3        ; Default signal
  63.     move.l    4.w,a6            ; Get ExecBase
  64.     move.l    ThisTask(a6),a5        ; Current process
  65.     tst.l    pr_CLI(a5)        ; CLI start?
  66.     bne    .cli            ; Yep
  67.  
  68.     lea    pr_MsgPort(a5),a2    ; Otherwise get message port
  69.     move.l    a2,a0
  70.     SYS    WaitPort        ; And wait for message
  71.     move.l    a2,a0
  72.     SYS    GetMsg            ; Get message
  73.     move.l    d0,d7            ; And save it
  74.  
  75.     lea    IconName_Msg(pc),a1    ; We need icon.library
  76.     CLD    0
  77.     SYS    OpenLibrary
  78.     move.l    d0,d6
  79.     beq.b    .wb            ; No library around...
  80.  
  81.     lea    DosName_Msg(pc),a1    ; Also need dos.library
  82.     CLD    0
  83.     SYS    OpenLibrary
  84.     move.l    d0,d5
  85.     beq.b    .no_dos            ; No library around...
  86.  
  87.     move.l    d7,a2
  88.     move.l    sm_ArgList(a2),a3    ; Get startup arguments
  89.     move.l    wa_Lock(a3),d1        ; Dir for this program
  90.     move.l    d5,a6            ; Get DOSBase
  91.     SYS    CurrentDir        ; CD there
  92.     move.l    d0,d4
  93.  
  94.     move.l    wa_Name(a3),a0        ; Name of our program
  95.     move.l    d6,a6            ; Get IconBase
  96.     SYS    GetDiskObject        ; Get icon
  97.     move.l    d0,d2
  98.     beq.b    .icon_done        ; No icon available
  99.  
  100.     move.l    d0,a0
  101.     move.l    do_ToolTypes(a0),a0    ; Tooltypes array
  102.     lea    Signal_Msg(pc),a1    ; Tooltype to search for
  103.     SYS    FindToolType        ; Try to find it
  104.     tst.l    d0
  105.     beq.b    .icon_ok        ; No tooltype found
  106.  
  107.     move.l    d0,a0
  108.     bsr.b    GetBreakBit        ; Get appropriate signal
  109.  
  110. .icon_ok
  111.     move.l    d2,a0
  112.     SYS    FreeDiskObject        ; And free icon
  113.  
  114. .icon_done
  115.     move.l    d4,d0
  116.     move.l    d5,a6            ; Get DOSBase
  117.     SYS    CurrentDir        ; CD back to original dir
  118.     move.l    4.w,a6            ; Get SysBase
  119.  
  120.     move.l    d5,a1
  121.     SYS    CloseLibrary        ; Close dos.library
  122. .no_dos    move.l    d6,a1
  123.     SYS    CloseLibrary        ; Close icon.library
  124.     bra.b    .wb            ; Skip to "main"
  125.  
  126. .cli    clr.b    -1(a0,d0.l)        ; Null terminate argument string
  127.     bsr.b    GetBreakBit
  128.  
  129. .wb    SYS    Forbid
  130.     lea    PortName_Msg(pc),a1
  131.     SYS    FindPort        ; Try to locate port
  132.     tst.l    d0
  133.     beq.b    .skip            ; No port
  134.  
  135.     move.l    d0,a0
  136.     move.l    MP_SIGTASK(a0),a1    ; Task to signal
  137.     move.l    d3,d0            ; Signal to send
  138.     SYS    Signal            ; And do it
  139.  
  140. .skip    move.l    d7,d0            ; Any WBMsg?
  141.     beq.b    .cli_end        ; No
  142.  
  143.     move.l    d7,a1
  144.     SYS    ReplyMsg        ; Otherwise reply it
  145.     rts
  146.  
  147. .cli_end
  148.     SYS    Permit            ; Re-enable other tasks
  149.     rts
  150.  
  151. ;
  152. ; Checks null-terminated string at a0 for the breakbit to send.
  153. ; Skips leading tabs and spaces.
  154. ;
  155.  
  156. GetBreakBit
  157.     CLD    0
  158. .scan    move.b    (a0)+,d0        ; Get next char
  159.     beq.b    .end            ; End of string
  160.  
  161.     cmp.b    #" ",d0            ; Skip space
  162.     beq.b    .scan
  163.  
  164.     cmp.b    #9,d0            ; Skip tabs
  165.     beq.b    .scan
  166.  
  167.     bclr    #5,d0            ; Make it upper case
  168.     sub.b    #"C",d0
  169.     bmi.b    .end            ; Out of range
  170.  
  171.     cmp.b    #4,d0
  172.     bgt.b    .end            ; Out of range
  173.  
  174.     lsl.l    #2,d0            ; To index longwords
  175.     move.l    BreakBits(pc,d0.w),d3    ; Get value
  176. .end    rts                ; All done
  177.  
  178.  
  179. BreakBits
  180.     dc.l    SIGBREAKF_CTRL_C
  181.     dc.l    SIGBREAKF_CTRL_D
  182. Default    dc.l    SIGBREAKF_CTRL_E
  183.     dc.l    SIGBREAKF_CTRL_F
  184.  
  185.     dc.b    "$VER: SignalRC 1.0 (4.8.92)",0
  186.  
  187. PortName_Msg
  188.     dc.b    "ReqChange",0
  189.  
  190. DosName_Msg
  191.     dc.b    "dos.library",0
  192.  
  193. IconName_Msg
  194.     dc.b    "icon.library",0
  195.  
  196. Signal_Msg
  197.     dc.b    "SIGNAL",0
  198.  
  199.     END
  200.