home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / DEBUG / ENTRY.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-04-08  |  3.2 KB  |  147 lines

  1.     .386p
  2.     .model small
  3.  
  4. include  prints.ase 
  5. include  input.ase 
  6. include  mtrap.ase 
  7.  
  8.     PUBLIC    entry
  9.     extrn get_char : proc, put_char : proc, put_msg : proc
  10.     .code
  11. ;
  12. ; Input function for a number
  13. ;
  14. InputNumber    PROC    
  15.     push    edx
  16.     push    ecx
  17.     push    ebx
  18.     sub    ecx,ecx         ; Number of digits = 0
  19.     sub    ebx,ebx            ; Data = 0
  20. lp:
  21.     call    get_char
  22.     cmp    al,60h
  23.     jc    notlower
  24.     and    al,NOT 20h
  25. notlower:
  26.     mov    ah,al            ; AH = data
  27.     cmp    al,' '            ; Space, data is complete
  28.     jz    short space        ;
  29.     cmp    al,13            ;
  30.     jz    short isenter        ; ENTER = quit entering data
  31.     cmp    al,8            ; BACKSPACE or RUBOUT, handle it
  32.     jz    short bckspc        ;
  33.     cmp    al,7fh            ;
  34.     jz    short bckspc        ;
  35.     sub    al,'0'            ; Convert to binary, ignore if not valid
  36.     jc    lp            ;
  37.     cmp    al,10            ;
  38.     jc    short gotdigit        ;
  39.     sub    al,7            ;
  40.     cmp    al,10            ;
  41.     jc    lp            ;
  42.     cmp    al,16            ;
  43.     jnc    lp            ;
  44. gotdigit:
  45.     cmp    cl,2            ; If got two digits don't accept
  46.     jz    lp
  47.     shl    bl,4            ; Add in the digit
  48.     or    bl,al            ;
  49.     inc    ecx            ; Inc digit count
  50.     jmp    lp            ; Next digit
  51. bckspc:
  52.     or    ecx,ecx            ; Get next digit if nothing in buffer
  53.     jz    lp            ;
  54.     mov    dl,' '            ;
  55.     call    put_char
  56.     mov    dl,8            ; Point at next echo space
  57.     call    put_char
  58.     dec    ecx            ; Dec digit count
  59.     jmp    lp
  60. isenter:
  61.     or    ecx,ecx            ; Enter key, set carry and get out
  62.     stc                ;
  63.     jmp    getout
  64. space:
  65.     or    ecx,ecx            ; Space key, clear carry and get out
  66. getout:
  67.     pushfd
  68.     mov    al,3            ; Space to line up in columns
  69.     sub    al,cl            ;
  70.     mov    cl,al            ;
  71. pslp:            
  72.     call    printspace        ;
  73.     loop    pslp            ;
  74.     popfd                ;
  75.     mov    eax,ebx            ; AX = number input
  76.     pop    ebx
  77.     pop    ecx
  78.     pop    edx
  79.     ret
  80. InputNumber    ENDP    
  81. ;
  82. ; Number entry with prompt
  83. ;
  84. entry    PROC    
  85.     call    PageTrapErr        ; Trap if no page
  86.     call    WadeSpace        ; Wade through commad spaces
  87.     inc    esi            ; Point at first non-space
  88.     cmp    al,13            ; Error if no address given
  89.     jz    enterr
  90.     dec    esi            ;
  91.     call    ReadAddress        ; Read the address
  92.     jc    enterr            ; Bad address ,error
  93.     mov    ecx,-1            ;
  94.     mov    edi,ebx
  95.     call    WadeSpace        ; Wade through spaces
  96.     cmp    al,13            ; If no values specified
  97.     jz    short prompt        ; Go do prompt version
  98. readlp:
  99.     call    ReadNumber        ; Else read number off command line
  100.     jc    enterr2            ; Quit if error
  101.     mov    [edi],al        ; Save value
  102.     inc    edi            ; Point to next input pos
  103.     call    WadeSpace        ; Wade through spaces
  104.     cmp    al,13            ; Quit if CR
  105.     jz    short retok        ;
  106.     jmp    readlp            ; Else get next value
  107. prompt:
  108.     push    ebx            ; CR/LF
  109.     mov    ebx,offset CRLF
  110.     call    put_msg
  111.     pop    ebx            ;
  112.     mov    eax,ebx                 ;
  113.     call    printdword              ; Print offset
  114. elp:
  115.     call    printspace        ; Space over two spaces
  116.     call    printspace        ;
  117.     mov    al,[edi]        ; Print current value
  118.     call    printbyte        ;
  119.     mov    dl,'.'            ; Print '.'
  120.     call    put_char
  121.     push    ecx
  122.     call    InputNumber        ; Get a number
  123.     pop    ecx
  124.     jz    short nextitem        ; No number, go do next
  125.     mov    [edi],al        ; Save value
  126. nextitem:
  127.     jc    short retok        ; Quit if ENTER key pressed
  128.     dec    ecx            ; Quit if end of segment
  129.     jz    short retok        ;
  130.     inc    edi            ; Point at next value
  131.     inc    ebx            ; Next address
  132.     test    ebx,7            ; If address mod 7 = 0
  133.     jz    prompt            ; Do another prompt
  134.     jmp    elp
  135. retok:
  136.     clc                ; No errors
  137.     jmp    dudone            ;
  138. enterr2:
  139. enterr:        
  140.     stc                 ; Errors
  141. dudone:
  142.     pushfd                ; Restore user page trap
  143.     call    PageTrapUnerr        ;
  144.     popfd                ;
  145.     ret
  146. entry    ENDP    
  147. END