Announcement

Collapse
No announcement yet.

PB/DOS - Reading a line from STDIN using DOSKEY or INT21

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB/DOS - Reading a line from STDIN using DOSKEY or INT21

    Code:
    '-------------------------------------------------------------------------------
    '                                                                 (C) M.Hoffmann
    '      Unit: dinput1.pbl
    '     Zweck: Zeileneingabe unter Nutzung von DOSKEY oder DOS21/0A
    '   Version: 1.00
    '     Stand: 30.10.98
    '   Sprache: PowerBASIC 3.2
    '     Autor: (C) M.Hoffmann, Wedeler Landstr.139, 22559 Hamburg.
    '  Benötigt: (wahlweise [img]http://www.powerbasic.com/support/forums/smile.gif[/img] MSDOS-TSR DOSKEY
    '  Historie:
    '      1.00: Erste Version, 29.-30.10.98.
    '   Notizen: Der Prompt wird auf STDOUT ausgegeben!
    '
    ' c: dinput1 .pbu      1361  30.10.98   0:02  v1.00
    '
    
    '---Compiler--------------------------------------------------------------------
    
    $compile  unit
    $cpu      80386
    $debug    map-,pbdebug-,path-,unit-
    $dim      all
    $error    all-
    $event    off
    $float    emulate
    $lib      all-
    $optimize size
    $static
    $option   gosub-,signed-
    
    defint a-z
    
    '---Deklarationen---------------------------------------------------------------
    
    %cr = 13  ' CR-Taste = ASCII 13
    %ax =  1  ' CPU-Register
    %dx =  4  ' CPU-Register
    %ds =  8  ' CPU-Register
    
    type buf_type
         maxLen as byte
         curLen as byte
         buf    as string*128
    end type
    
    '---Routinen--------------------------------------------------------------------
    
    function DInputCheckDosKey() local public as integer
    
       ! mov ax,&h4800 ; ' AL(00)=Installations-Prüfung (AL(<>00)->installiert)
       ! int &h2f
       ! mov function,al
    
    end function
    
    function DInput (Prompt as string, Default as string) local public as string
    
       ' Zeigt wahlweise einen Prompt direkt vor der Eingabe an (selbe Zeile)
       ' Wird nur ENTER gedrückt, wird Default zurückgegeben
    
       dim buf as local buf_type
       dim cv  as local byte
    
       function   = Default
       cv         = pbvCursorVis ' Cursor an/aus sichern
       buf.maxLen = 128 ' &h80 zwingend erforderlich bei DOSKEY, daher beschränkt
       reg %ds    , varseg(buf)
       reg %dx    , varptr(buf)
    
       locate ,,1
       stdout Prompt;
    
       if DInputCheckDosKey() then
    
          reg %ax,&h4810   ' AL(10)=Eingabe_lesen
          call interrupt &h2f
          if (reg(%ax) and &h00ff) then ' Fehler
             exit function
          end if
    
       else
    
          ' hier könnte auch INPUT benutzt werden!
          reg %ax,&h0a00   ' DOS-Funktion 'Bufferd-Keyboard-Input'
          call interrupt &h21
    
       end if
    
       if buf.curLen then
          function = left$(buf.buf,buf.curLen)
       end if
    
       stdout
       locate ,,cv
    
    end function
    
    '===============================================================================
    ------------------
Working...
X