home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / misc / dtmf / dtmf.asm < prev    next >
Assembly Source File  |  1995-03-01  |  9KB  |  562 lines

  1. ; DTMF Dialer
  2. ; (c) 1995 Martin Mares, MJSoft System Software
  3.  
  4. ;DEBUG    set    1
  5. _GlobVec    set    1
  6.  
  7.     include    "ssmac.h"
  8.     include    "val/mui.equ"
  9.  
  10. MUITags    equ    $80420000
  11.  
  12.     start
  13.  
  14.     dv.l    ratems
  15.     moveq    #100,d2
  16.     get.l    rate,d0
  17.     beq.s    DefRate
  18.     move.l    d0,a0
  19.     move.l    (a0),d2
  20.     moveq    #10,d0
  21.     cmp.l    d0,d2
  22.     bcs.s    BadRate
  23.     cmp.l    #5000,d2
  24.     bcs.s    DefRate
  25. BadRate    dtl    <Invalid rate>,a0
  26.     jump    ExitError
  27. DefRate    put.l    d2,ratems
  28.  
  29.     get.l    number,d0
  30.     beq.s    TryFile
  31.     move.l    d0,a4
  32.     bra    Dial
  33.  
  34. TryFile    get.l    file,d0
  35.     beq.s    UseGUI
  36.     move.l    d0,a0
  37.     moveq    #OPEN_OLD,d0
  38.     moveq    #0,d1
  39.     call    TrackOpenBuf
  40.     move.l    d0,a2
  41.     clr.l    -(sp)
  42. File1    call    ss,BGetByte
  43.     tst.l    d0
  44.     bmi.s    ret1
  45.     move.b    d0,(sp)
  46.     move.l    sp,a4
  47.     push    a2
  48.     lea    Dial(pc),a0
  49.     moveq    #0,d0
  50.     call    CallBlock
  51.     pop    a2
  52.     tst.l    d0
  53.     beq.s    File1
  54. ret1    addq.l    #4,sp
  55.     rts
  56.  
  57. UseGUI    dtl    <muimaster.library>,a0
  58.     moveq    #MUIMASTER_VMIN,d0
  59.     call    TrackLibrary
  60.     put.l    d0,muimasterbase
  61.     dv.l    muimasterbase
  62.  
  63.     bsetv    #svfb_errorreq,sv_flags+3
  64.  
  65.     moveq    #32,d7            ; Button array
  66.     clr.l    -(sp)
  67.     dv.l    buttxt
  68.     moveq    #0,d4
  69. GenButt    subq.w    #2,d7
  70.     bmi.s    GBE
  71.     lea    names(pc,d7.w),a0
  72.     put.l    a0,buttxt
  73.     lea    Button(pc),a3
  74.     bsr    GenerateMUI
  75.     push    d0
  76.     pea    MUIA_Group_Child
  77.     bra.s    GenButt
  78.  
  79. names    dc.b    '1',0,'2',0,'3',0,'A',0,'4',0,'5',0,'6',0,'B',0,'7',0,'8',0
  80.     dc.b    '9',0,'C',0,'*',0,'0',0,'#',0,'D',0,0
  81.     even
  82.  
  83. GBE    pea    4.w            ; Matrix
  84.     pea    MUIA_Group_Columns
  85.     pea    -1.w
  86.     pea    MUIA_Group_SameSize
  87.     move.l    sp,a1
  88. ;    dt    STR_Group,<Group.mui>
  89.     gett    STR_Group,a0
  90.     call    muimaster,MUI_NewObject
  91.     put.l    d0,matrix
  92.     dv.l    matrix
  93.  
  94.     bsr    TrackMUI        ; Main window etc
  95.     lea    UserInterface(pc),a3
  96.     bsr    GenerateMUI
  97.  
  98.     lea    16(sp),sp        ; !!!
  99.     moveq    #100,d2            ; Button notifications
  100. SetGBNot    pop    d0
  101.     beq.s    SetGBNE
  102.     pop    a2
  103.     push    d2
  104.     pea    MUIM_Application_ReturnID
  105.     pea    2.w
  106.     vpush    appl
  107.     clr.l    -(sp)
  108.     pea    MUIA_Pressed
  109.     pea    MUIM_Notify
  110.     move.l    sp,a1
  111.     bsr    DoMethod
  112.     lea    28(sp),sp
  113.     addq.w    #1,d2
  114.     bra.s    SetGBNot
  115.  
  116. SetGBNE    move.w    #MUIA_Window_Open-MUITags,d0
  117.     moveq    #1,d1
  118.     get.l    window,a0
  119.     bsr    SetAttr
  120.     move.w    #MUIA_Window_Open-MUITags,d0
  121.     get.l    window,a0
  122.     bsr    GetAttr
  123.     tst.l    d0
  124.     errc.ne    <Unable to open window>
  125.  
  126.     lea    Notifications(pc),a3
  127.     bsr    SetRCs
  128.     bsr    ActivateString
  129.  
  130. MainLoop    clr.l    -(sp)
  131.     move.l    sp,d7
  132.     clr.l    -(sp)
  133.     push    d7
  134.     pea    MUIM_Application_Input
  135.     get.l    appl,a2
  136.     move.l    sp,a1
  137.     bsr    DoMethod
  138.     move.l    d7,sp
  139.     pop    d2
  140.     moveq    #-1,d1
  141.     cmp.l    d1,d0
  142.     beq.s    MainEnd
  143.     moveq    #(LastCode-Codes)/2,d1
  144.     cmp.l    d1,d0
  145.     bcc.s    MayBeButt
  146.     push    d2
  147.     add.w    d0,d0
  148.     move.w    Codes(pc,d0.w),d0
  149.     jsr    Codes(pc,d0.w)
  150.     pop    d2
  151. Waiting    move.l    d2,d0
  152.     beq.s    MainLoop
  153.     call    exec,Wait
  154.     bra.s    MainLoop
  155.  
  156. MayBeButt    moveq    #100,d1
  157.     sub.l    d1,d0
  158.     bcs.s    Waiting
  159.     moveq    #16,d1
  160.     cmp.l    d1,d0
  161.     bcc.s    Waiting
  162.     bsr.s    DoButton
  163.     bra.s    Waiting
  164.  
  165. Codes    dc.w    Return-Codes        ; Do Nothing
  166.     dc.w    MainEnd-Codes        ; Close Gadget
  167.     dc.w    StringAccept-Codes
  168. LastCode
  169.  
  170. MainEnd    jump    ss,ExitCleanup
  171. Return    rts
  172.  
  173. DoButton    push    d2
  174.     lea    names(pc),a4
  175.     add.w    d0,a4
  176.     add.w    d0,a4
  177.     bsr.s    DoDialing
  178.     pop    d2
  179.     rts
  180.  
  181. StringAccept    move.w    #MUIA_String_Acknowledge-MUITags,d0
  182.     get.l    strg,a0
  183.     bsr    GetAttr
  184.     move.l    d0,a4
  185.     bsr.s    DoDialing
  186. ActivateString    move.w    #MUIA_Window_ActiveObject-MUITags,d0
  187.     get.l    strg,d1
  188.     get.l    window,a0
  189.     bra    SetAttr
  190.  
  191. DoDialing    move.w    #MUIA_Application_Sleep-MUITags,d0
  192.     moveq    #1,d1
  193.     get.l    appl,a0
  194.     bsr    SetAttr
  195.  
  196.     lea    Dial(pc),a0
  197.     moveq    #0,d0
  198.     call    ss,CallBlock
  199.  
  200.     move.w    #MUIA_Application_Sleep-MUITags,d0
  201.     moveq    #0,d1
  202.     get.l    appl,a0
  203.     bra    SetAttr
  204.  
  205. DoMethod    move.l    -4(a2),a0
  206.     move.l    8(a0),a6
  207.     jmp    (a6)
  208.  
  209. TrackMUI    lea    FreeObj(pc),a0
  210.     sub.l    a1,a1
  211.     call    ss,TrackRoutine
  212.     move.l    a1,d4
  213.     rts
  214.  
  215. GenerateMUI    move.l    #MUITags,d2
  216.     gett    __BaseText,a2
  217.     get.l    muimasterbase,a6
  218.     bra.s    .loopnext
  219.  
  220. .loop    push    d2
  221. .loop2    move.w    (a3)+,d2
  222.     beq.s    .end
  223. .loopnext    moveq    #0,d3
  224.     move.w    (a3)+,d3
  225.     bmi.s    .subobj
  226.     bclr    #14,d3
  227.     bne.s    .numb
  228.     add.l    a2,d3        ; String
  229.     push    d3
  230.     bra.s    .loop
  231.  
  232. .numb    cmp.w    #$2000,d3    ; Number
  233.     beq.s    .long
  234.     bcs.s    .plus
  235.     or.l    #$FFFFE000,d3
  236. .plus    push    d3
  237.     bra.s    .loop
  238. .long    push    (a3)+
  239.     bra.s    .loop
  240.  
  241. .subobj    bclr    #15,d3
  242.     bclr    #14,d3
  243.     bne.s    .var
  244.     add.l    a2,d3
  245.     link    a4,#0
  246.     push    d3
  247.     move.w    (a3)+,-(sp)
  248.     push    d2
  249.     clr.l    -(sp)
  250.     bra.s    .loop2
  251.  
  252. .var    move.l    (a5,d3.w),-(sp)
  253.     bra.s    .loop
  254.  
  255. .end    move.l    -4(a4),a0
  256.     move.l    sp,a1
  257.     call    MUI_NewObject
  258.     move.w    -6(a4),d3
  259.     move.l    d0,(a5,d3.w)
  260.     move.l    -10(a4),d2
  261.     unlk    a4
  262.     tst.w    d2
  263.     beq.s    .finish
  264.     push    d0
  265.     bra.s    .loop
  266.  
  267. .finish    dtl    <Unable to create user interface>,a0
  268.     tst.l    d0
  269.     beq.s    ExitErr
  270.     tst.l    d4
  271.     beq.s    1$
  272.     move.l    d4,a0
  273.     move.l    d0,(a0)
  274. 1$    rts
  275. ExitErr    jump    ss,ExitError
  276.  
  277. FreeObj    jump    muimaster,MUI_DisposeObject
  278.  
  279. SetRCs    move.l    sp,d3
  280.     pea    1.w                ; 24
  281.     pea    MUIM_Application_ReturnID    ; 20
  282.     pea    2.w                ; 16
  283.     vpush    appl                ; 12
  284.     clr.l    -(sp)                ; 8
  285.     pea    MUITags                ; 4
  286.     pea    MUIM_Notify            ; 0
  287. 1$    move.w    (a3)+,d0
  288.     beq.s    2$
  289.     move.l    (a5,d0.w),a2
  290.     move.w    (a3)+,6(sp)
  291.     move.w    (a3)+,d0
  292.     cmp.w    #$8000,d0
  293.     bne.s    3$
  294.     move.l    #MUIV_EveryTime,d0
  295.     bra.s    4$
  296. 3$    ext.l    d0
  297. 4$    move.l    d0,8(sp)
  298.     move.l    sp,a1
  299.     bsr    DoMethod
  300.     addq.l    #1,24(sp)
  301.     bra.s    1$
  302. 2$    move.l    d3,sp
  303.     rts
  304.  
  305. SetAttr    clr.l    -(sp)
  306.     push    d1
  307.     move.w    d0,-(sp)
  308.     move.w    #MUITags>>16,-(sp)
  309.     move.l    sp,a1
  310.     call    intuition,SetAttrsA
  311.     lea    12(sp),sp
  312.     rts
  313.  
  314. GetAttr    move.l    #MUITags,d1
  315.     move.w    d0,d1
  316.     move.l    d1,d0
  317.     clr.l    -(sp)
  318.     move.l    sp,a1
  319.     call    intuition,GetAttr
  320.     pop    d0
  321.     rts
  322.  
  323. MTag    macro
  324.     dc.w    \1-MUITags
  325.     endm
  326.  
  327. MOffs    macro
  328.     dc.w    \1+\2-__BaseText
  329.     endm
  330.  
  331. MObj    macro
  332.     ifne    \1
  333.     MTag    \1
  334.     endc
  335.     ifnd    STREX_\2
  336. STREX_\2    set    1
  337.     dt    STR_\2,<\2.mui>
  338.     endc
  339.     MOffs    $8000,STR_\2
  340.     ifgt    NARG-2
  341.     dc.w    \3
  342.     dv.l    \3
  343.     elseif
  344.     dc.w    __Trash
  345.     endc
  346.     endm
  347.  
  348. MText    macro
  349.     MTag    \1
  350.     dt    STR_\@a,<\2>
  351.     MOffs    0,STR_\@a
  352.     endm
  353.  
  354. MNum    macro
  355.     MTag    \1
  356.     ifge    \2-$2000
  357.     dc.w    $6000
  358.     dc.l    \2
  359.     elseif
  360.     ifle    \2+$2000
  361.     dc.w    $6000
  362.     dc.l    \2
  363.     elseif
  364.     dc.w    $4000+(\2&$3FFF)
  365.     endc
  366.     endc
  367.     endm
  368.  
  369. MVar    macro
  370.     MTag    \1
  371.     ifge    \2-$4000
  372.     fail
  373.     endc
  374.     dc.w    \2+$C000
  375.     endm
  376.  
  377. MEnd    macro
  378.     dc.w    0
  379.     endm
  380.  
  381. Notify    macro
  382.     dc.w    \1,MUIA_\2-MUITags,\3
  383.     endm
  384.  
  385. NAny    macro
  386.     dc.w    \1,MUIA_\2-MUITags,$8000
  387.     endm
  388.  
  389.     dv.l    __Trash
  390.     dt.c    __BaseText,<>
  391.  
  392. UserInterface
  393.  MObj    0,Application,appl
  394.   MText    MUIA_Application_Title,<DTMF>
  395.   MText    MUIA_Application_Version,<$VER: DTMF 1.2 (10.2.95)>
  396.   MText    MUIA_Application_Copyright,<© 1995 MJSoft System Software>
  397.   MText    MUIA_Application_Author,<Martin Mares>
  398.   MText    MUIA_Application_Description,<Tone Dialer>
  399.   MText    MUIA_Application_Base,<DTMF>
  400. ;;;  MNum    MUIA_Application_SingleTask,TRUE
  401.   MObj    MUIA_Application_Window,Window,window
  402.    MText    MUIA_Window_Title,<DTMF Dialer 1.2>
  403.    MObj    MUIA_Window_RootObject,Group
  404.     MVar    MUIA_Group_Child,matrix
  405.     MObj    MUIA_Group_Child,String,strg
  406.      MText    MUIA_String_Accept,<0123456789*#aAbBcCdD ,-.>
  407.      MNum    MUIA_Frame,MUIV_FrameString
  408.      MEnd
  409.     MEnd
  410.    MEnd
  411.   MEnd
  412.  
  413. Button
  414.  MObj    0,Text
  415.   MNum    MUIA_Frame,MUIV_FrameButton
  416.   MVar    MUIA_Text_Contents,buttxt
  417.   MText    MUIA_Text_PreParse,<',27,'c>
  418.   MNum    MUIA_InputMode,MUIV_InputModeRelVerify
  419.   MNum    MUIA_Background,MUII_ButtonBack
  420.   MEnd
  421.  
  422. Notifications    Notify    window,Window_CloseRequest,TRUE        ; 1
  423.     NAny    strg,String_Acknowledge            ; 2
  424.     MEnd
  425.  
  426. ; ### DIALING ROUTINES ###
  427.  
  428.     dbuf    ior1,ioa_SIZEOF
  429.     dbuf    ior2,ioa_SIZEOF
  430.     dbuf    ior3,ioa_SIZEOF
  431.  
  432. Dial    geta    ior1,a0
  433.     move.w    #(ior2-ior1)/2-1,d0
  434. 1$    clr.w    (a0)+
  435.     dbf    d0,1$
  436.  
  437.     call    ss,TrackPort
  438.     move.l    d0,d4
  439.     dtl    <audio.device>,a0
  440.     geta    ior1,a1
  441.     move.l    d4,MN_REPLYPORT(a1)
  442.     moveq    #0,d0
  443.     moveq    #0,d1
  444.     sub.l    a2,a2
  445.     call    TrackDevice
  446.     move.l    d1,a1
  447.     geta    ior1,a2
  448.     lea    combin(pc),a0
  449.     move.l    a0,ioa_Data(a2)
  450.     addq.b    #1,3+ioa_Length(a2)
  451.     move.w    #ADCMD_ALLOCATE,IO_COMMAND(a2)
  452.     move.b    #127,LN_PRI(a2)
  453.     dtl    <Unable to allocate audio channels>,a0
  454.     call    ChkDoIO
  455.  
  456.     move.l    IO_DEVICE(a2),d1
  457.     move.w    ioa_AllocKey(a2),d3
  458.     moveq    #1,d2
  459.     move.l    d2,IO_UNIT(a2)
  460.     geta    ior2,a0
  461.     moveq    #8,d2
  462.     movem.l    d1-d2,IO_DEVICE(a0)
  463.     move.w    d3,ioa_AllocKey(a0)
  464.     move.l    d4,MN_REPLYPORT(a0)
  465.     geta    ior3,a0
  466.     move.l    d1,IO_DEVICE(a0)
  467.  
  468.     get.l    ratems,d2
  469. num0    call    ss,TestBreak
  470.     move.b    (a4)+,d0
  471.     beq.s    done1
  472.     call    utility,ToUpper
  473.     lea    recode(pc),a0
  474.     moveq    #15,d3
  475. num1    cmp.b    (a0)+,d0
  476.     dbeq    d3,num1
  477.     bne.s    numspac
  478.     bsr.s    OneTone
  479.     bra.s    num0
  480.  
  481. numspac    bsr.s    OneSpace
  482.     bra.s    num0
  483.  
  484. done1    rts
  485.  
  486. recode    dc.b    'D#0*C987B654A321'
  487.  
  488. ; D3=Code, D2=Duration (ms)
  489.  
  490. OneTone    geta    ior3,a1
  491.     move.w    #CMD_STOP,IO_COMMAND(a1)
  492.     call    exec,SendIO
  493.     divu    #4,d3
  494.     geta    ior1,a1
  495.     lea    freqshi(pc),a0
  496.     bsr.s    SetIO
  497.     swap    d3
  498.     geta    ior2,a1
  499.     lea    freqslo(pc),a0
  500.     bsr.s    SetIO
  501.     geta    ior3,a1
  502.     move.w    #CMD_START,IO_COMMAND(a1)
  503.     call    exec,SendIO
  504.     geta    ior1,a1
  505.     call    WaitIO
  506.     geta    ior2