home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 487.lha / ButtonAsk / ButtonAsk.s < prev    next >
Encoding:
Text File  |  1991-03-11  |  2.5 KB  |  104 lines

  1. **************************************
  2. *                                    *
  3. *           ButtonAsk v1.0           *
  4. *                                    *
  5. *        (c) 1990 Chris Simpson      *
  6. *                                    *
  7. * USAGE: ButtonAsk <prompt>          *
  8. *                                    *
  9. * This program is a replacement for  *
  10. * the AmigaDOS ASK command except    *
  11. * that the mouse buttons are used    *
  12. * rather than entering 'y' or 'n'    *
  13. * For this program to work, some     *
  14. * text for the prompt must be given  *
  15. * in the command line. This text is  *
  16. * echoed to stdout and then a mouse  *
  17. * button is waited for. Pressing the *
  18. * left button returns a return code  *
  19. * of 5(WARN) and pressing the right  *
  20. * button returns a return code of 0. *
  21. *                                    *
  22. **************************************
  23.  
  24.         SECTION ButtonAsk,code_c    ; Put into chip ram
  25.  
  26.         INCDIR    include:        ; Read include files
  27.         INCLUDE    exec/exec_lib.i
  28.         INCLUDE libraries/dos_lib.i
  29.  
  30. LeftReg        equ    $bfe001            ; Set up button registers
  31. RightReg    equ    $dff016
  32.  
  33.         move.l    d0,Length        ; Store length of CLI line
  34.         move.l    a0,Address        ; Store address of CLI line
  35.  
  36.         move.l    #100,ReturnCode        ; Default return code
  37.  
  38.         lea    DOSName,a1        ; Try to open dos library
  39.         clr.l    d0
  40.         CALLEXEC OpenLibrary
  41.         tst.l    d0            ; Quit if not opened
  42.         beq    Error
  43.         move.l    d0,_DOSBase        ; Else store dos base
  44.  
  45.         CALLDOS    Output            ; Find standard output
  46.         move.l    d0,OutHandle        ; Store handle address
  47.  
  48.         move.l    Length,d0        ; Get back length
  49.         move.l    Address,a0        ; Get back address
  50.  
  51.         cmp.l    #1,Length        ; Make sure not just linefeed
  52.         bgt    GotPrompt
  53.  
  54.         move.l    OutHandle,d1        ; Write USAGE text
  55.         move.l    #Usage,d2
  56.         move.l    #UsageEnd-Usage,d3
  57.         CALLDOS Write
  58.         bra    CloseDOS
  59.  
  60.         
  61. GotPrompt    move.l    OutHandle,d1        ; Write the prompt out
  62.         move.l    a0,d2
  63.         move.l    d0,d3        
  64.         CALLDOS Write
  65.  
  66. WaitForButton      btst    #6,$bfe001
  67.         beq    LeftPressed
  68.  
  69.         btst    #10,$dff016
  70.         beq    RightPressed
  71.  
  72.         bra    WaitForButton
  73.  
  74. LeftPressed    move.l    #5,ReturnCode
  75.         bra    CloseDOS
  76.  
  77. RightPressed    move.l    #0,ReturnCode
  78.         
  79. CloseDOS    move.l    _DOSBase,a1        ; Close dos library
  80.         CALLEXEC CloseLibrary
  81.  
  82.         move.l    ReturnCode,d0        ; Exit with return code
  83. Error        rts
  84.  
  85. *** Data ***
  86.  
  87. DOSName        dc.b    "dos.library",0
  88.         even
  89. _DOSBase    dc.l    0
  90.  
  91. OutHandle    dc.l    0
  92.  
  93. Usage        dc.b     "ButtonAsk v1.0   (c) 1990 Chris Simpson",13,10,13,10
  94.         dc.b    "USAGE: ButtonAsk <prompt>",13,10,13,10
  95.         dc.b    "Return code will be ... 5 if left button pressed",13,10
  96.         dc.b    "                        0 if right button pressed",13,10,0
  97. UsageEnd    even
  98.  
  99. Address        dc.l    0
  100. Length        dc.l    0
  101.  
  102. ReturnCode    dc.l    0
  103.  
  104.