home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP7 / ROMIO.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-03  |  2.5 KB  |  148 lines

  1.     page    78,132
  2.     title    BIOS ROM I/O driver for Monitor
  3.  
  4. LineLen    =    132
  5.  
  6.     .model    small
  7.     .code
  8.     .data
  9.  
  10.     public    LineBuf
  11.  
  12. LineBuf        db    LineLen dup(0)
  13.  
  14. DGroup    group    _TEXT,_DATA
  15.  
  16.     .code
  17.  
  18.     public    InBuf, OutCh, InCh, CrLf
  19.  
  20.     extrn    Backup:near, Command:near
  21.  
  22. ;Get input line
  23.     assume    cs:DGroup,ds:DGroup
  24.  
  25. INBUF:
  26.     MOV    DI,offset DGroup:LINEBUF    ;Next empty buffer location
  27.     XOR    CX,CX        ;Character count
  28. GETCH:
  29.     CALL    InCh        ;Get input character
  30.     CMP    AL,20H        ;Check for control characters
  31.     JC    CONTROL
  32.     CMP    AL,7FH        ;RUBOUT is a backspace
  33.     JZ    BACKSP
  34.     CALL    OutCh        ;Echo character
  35.     STOSB            ;Put in input buffer
  36.     INC    CX        ;Bump character count
  37.     CMP    CX,LineLen    ;Buffer full?
  38.     JBE    GETCH        ;Drop in to backspace if full
  39. BACKSP:
  40.     JCXZ    GETCH        ;Can't backspace over nothing
  41.     DEC    DI        ;Drop pointer
  42.     DEC    CX        ;and character count
  43.     CALL    BACKUP        ;Send physical backspace
  44.     jmp    GETCH        ;Get next char.
  45.  
  46. CONTROL:
  47.     CMP    AL,3        ;Ctrl-C?
  48.     JZ    KILL
  49.     cmp    al,1BH        ;ESC?
  50.     jz    Kill
  51.     CMP    AL,8        ;Check for backspace
  52.     JZ    BACKSP
  53.     CMP    AL,13        ;Check for carriage return
  54.     JNZ    GETCH        ;Ignore all other control char.
  55.     STOSB            ;Put the car. ret. in buffer
  56. ;Convert unquoted input to upper case
  57.     MOV    SI,offset DGroup:LINEBUF
  58.     mov    di,si
  59. CaseChk:
  60.     lodsb
  61.     cmp    al,"a"
  62.     jb    NoConv
  63.     cmp    al,"z"
  64.     ja    NoConv
  65.     sub    al,"a"-"A"        ;Convert to upper case
  66. NoConv:
  67.     stosb                ;Put it back where we got it
  68.     cmp    al,13            ;End of line?
  69.     jz    InDone
  70.     cmp    al,'"'
  71.     jz    QuotScan
  72.     cmp    al,"'"
  73.     jnz    CaseChk
  74. QuotScan:
  75.     mov    ah,al            ;Remember which quote mark
  76. KillStr:
  77.     lodsb
  78.     stosb
  79.     cmp    al,13
  80.     jz    InDone
  81.     cmp    al,ah
  82.     jnz    KillStr
  83.     jmp    CaseChk
  84.  
  85. InDone:
  86.     mov    si,offset DGroup:LINEBUF ;Set up SI for command processing
  87.  
  88. ;Output CR/LF sequence
  89.  
  90. CRLF:
  91.     MOV    AL,13
  92.     CALL    OutCh
  93.     MOV    AL,10
  94.     jmp    short OutCh
  95.  
  96. ;Cancel input line
  97.  
  98. KILL:
  99.     CALL    CRLF
  100. CommandJ:
  101.     JMP    COMMAND
  102.  
  103. ;Character input routine
  104.  
  105. InCh:
  106.     MOV    AH,0
  107.     INT    16H        ;Call ROM BIOS for a character
  108.     RET
  109.  
  110.  
  111. ;Console output of character in AL
  112.     assume    ds:nothing,es:nothing,ss:nothing
  113.  
  114. OutCh:
  115.     push    ax        ;Character to output on stack
  116.     push    bx
  117.     push    bp
  118.     mov    bx,7
  119.     and    al,7FH
  120.     cmp    al,9            ;Tab character?
  121.     jz    RomTab
  122.     mov    ah,14            ;TTY output
  123.     int    10H
  124. TabDone:
  125.     pop    bp
  126.     pop    bx
  127.     pop    ax
  128.     ret
  129.  
  130. RomTab:
  131.     push    cx
  132.     push    dx
  133.     mov    ah,3            ;Get cursor position
  134.     int    10H
  135.     and    dx,7            ;Look at low 3 bits of column
  136.     mov    cx,8
  137.     sub    cx,dx            ;cx = no. of char to move
  138. ;We don't just do a cursor position in case of screen wrap (40 col. mode)
  139. TabLoop:
  140.     mov    ax,14*100H + " "    ;TTY output of blank
  141.     int    10H
  142.     loop    TabLoop
  143.     pop    dx
  144.     pop    cx
  145.     jmp    TabDone
  146.  
  147.     end
  148.