Annotation of sbbs/lciol/lciol.asm, revision 1.1.1.1

1.1       root        1:         .xlist
                      2:        include mdef
                      3: ;************************************************************************
                      4: ;*                                                                     *
                      5: ;*         lclol: direct BIOS interface console output for C           *
                      6: ;*                                                                     *
                      7: ;*    prototypes: int  lclini(int);         initialize                 *
                      8: ;*               int  lclatr(int);         set attributes              *
                      9: ;*               void lclxy(int,int);      set cursor position         *
                     10: ;*               int  lclwx(void);         get current column          *
                     11: ;*               int  lclwy(void);         get current line            *
                     12: ;*               void lputc(int);          put character               *
                     13: ;*               long lputs(char far *);   put string                  *
                     14: ;*                                                                     *
                     15: ;************************************************************************
                     16: 
                     17:        setmod  %mm
                     18:        .data
                     19: wid    db      79              ;columns per screen (zero based)
                     20: lps    db      24              ;lines per screen (zero based)
                     21: col    db      0               ;current column
                     22: lin    db      0               ;current line
                     23: atr    db      7               ;current attribute
                     24: pag    db      0               ;current display page
                     25: xla    db      0               ;tab expansion (bit 1), lf->cr/lf (bit 0)
                     26: 
                     27:        .code
                     28:        public  _lputc,_lputs,_lclini,_lclxy,_lclwx,_lclwy,_lclatr
                     29: 
                     30: ; Initialize
                     31: ; Gets current cursor position, attribute, and display page
                     32: ; from BIOS.  Integer argument defines the size of the screen.
                     33: 
                     34: _lclini        proc
                     35:        push    bp
                     36:        mov     bp,sp
                     37:        mov     ax,pb[bp]       ;fetch parameter 1 (16-bit int)
                     38:        or      ah,ah
                     39:        jz      noxla           ;no translation change
                     40: 
                     41:        shr     ah,1
                     42:        mov     xla,ah          ;set new translation flags
                     43: noxla: dec     al
                     44:        jns     clps            ;lines specified
                     45: 
                     46:        push    ds
                     47:        xor     ax,ax
                     48:        mov     ds,ax
                     49:        mov     al,ds:[484h]    ;get parameter from BIOS
                     50:        or      al,al
                     51:        jnz     blps            ;use BIOS value if non-zero
                     52:        mov     al,24           ;else 25 assume lines
                     53: blps:  pop     ds
                     54: clps:  mov     lps,al          ;set lines per screen
                     55:        mov     ah,0fh
                     56:        int     10h             ;get video mode
                     57:        dec     ah
                     58:        mov     wid,ah          ;set screen width
                     59:        mov     pag,bh          ;set current display page
                     60:        mov     ah,3
                     61:        int     10h             ;get cursor position
                     62:        cmp     dh,lps
                     63:        jc      cuupd           ;current line within range
                     64:        mov     dh,lps          ;else set to maximum
                     65: cuupd: mov     ah,2            ;set cursor and update current pointers
                     66:        int     10h             ;move cursor to last line
                     67:        mov     col,dx          ;set current column and line
                     68:        xor     ah,ah
                     69:        mov     al,lps
                     70:        inc     al              ;return number of lines set
                     71:        pop     bp
                     72:        ret
                     73: _lclini        endp
                     74: 
                     75: ; Set current cursor position
                     76: 
                     77: _lclxy proc
                     78:        push    bp
                     79:        mov     bp,sp
                     80:        mov     dx,pb[bp]       ;get parameter 1, x (column)
                     81:        dec     dl
                     82:        mov     col,dl
                     83:        mov     ax,pb[bp+2]     ;get parameter 2, y (line)
                     84:        dec     al
                     85:        mov     lin,al
                     86:        mov     dh,al
                     87:        mov     bh,pag
                     88:        mov     ah,2
                     89:        int     10h             ;set cursor
                     90:        xor     ax,ax
                     91:        pop     bp
                     92:        ret
                     93: _lclxy endp
                     94: 
                     95: ; Get current cursor position (x,y)
                     96: 
                     97: _lclwx proc
                     98:        xor     ah,ah
                     99:        mov     al,col          ;return x (column)
                    100:        inc     al
                    101:        ret
                    102: _lclwx endp
                    103: 
                    104: _lclwy proc
                    105:        xor     ah,ah
                    106:        mov     al,lin          ;return y (line)
                    107:        inc     al
                    108:        ret
                    109: _lclwy endp
                    110: 
                    111: ; Set local attributes
                    112: 
                    113: _lclatr        proc
                    114:        push    bp
                    115:        mov     bp,sp
                    116:        xor     ah,ah
                    117:        mov     al,atr          ;get old attribute in ax
                    118:        mov     dx,pb[bp]       ;fetch parameter 1 (16-bit int)
                    119:        mov     atr,dl          ;set current attribute
                    120:        pop     bp
                    121:        ret
                    122: _lclatr endp
                    123: 
                    124: ; Put character to console (local)
                    125: 
                    126: _lputc proc
                    127:        push    bp
                    128:        mov     bp,sp
                    129:        mov     ax,pb[bp]       ;fetch parameter 1 (16-bit int)
                    130: 
                    131:        cmp     ax,100h
                    132:        jz      clreol          ;clear to end of line
                    133:        cmp     al,7
                    134:        jnz     notbl           ;bell
                    135: 
                    136:        mov     ax,0e07h        ;write in tty mode (ah) bell (al)
                    137:        mov     bx,atr          ;get page (bh) and attribute (bl)
                    138:        int     10h             ;beep
                    139:        jmp     updc            ;make sure cursor is not changed
                    140: 
                    141: notbl: cmp     al,8
                    142:        jnz     notbs           ;backspace
                    143: 
                    144:        mov     al,col
                    145:        or      al,al
                    146:        jz      pexitj          ;at column zero, no action
                    147:        dec     col
                    148:        jmp     updc            ;move cursor back one column
                    149: 
                    150: notbs: cmp     al,9
                    151:        jz      outtb           ;horizontal tab
                    152:        cmp     al,12
                    153:        jz      outcs           ;screen clear
                    154:        cmp     al,10
                    155:        jz      outlf           ;line feed
                    156:        cmp     al,13
                    157:        jnz     nonctl          ;carriage return
                    158:        mov     col,0           ;set column zero
                    159:        jmp     updc
                    160: 
                    161: clreol:        mov     ax,920h
                    162:        mov     bx,atr          ;get page (bh) and attribute (bl)
                    163:        mov     cl,wid          ;line length
                    164:        sub     cl,col          ;get remainder
                    165:        inc     cl              ;include current position
                    166:        xor     ch,ch           ;replication factor in cx
                    167:        int     10h             ;clear to end of line
                    168: pexitj:        jmp     pexit
                    169: 
                    170: outtb: test    xla,2
                    171:        jz      nonctl          ;no tab expansion
                    172:        mov     al,col
                    173:        and     al,7
                    174:        mov     cl,8
                    175:        sub     cl,al
                    176:        xor     ch,ch           ;number of spaces in cx
                    177:        mov     al,20h
                    178: tbexp: push    cx
                    179:        push    ax              ;parameter 1
                    180:        call    _lputc
                    181:        pop     ax
                    182:        pop     cx
                    183:        cmp     col,0
                    184:        loopnz  tbexp           ;stop if cursor wraps
                    185:        jmp     pexit
                    186: 
                    187: outcs: mov     ax,600h         ;scroll (clear screen)
                    188:        mov     bh,atr          ;current attribute
                    189:        xor     cx,cx           ;upper left corner of window (0,0)
                    190:        mov     dx,wid          ;lower right corner of window (wid,lps)
                    191:        int     10h             ;scroll window up one line      
                    192:        mov     col,cx          ;new cursor
                    193:        jmp     updc
                    194: 
                    195: nonctl:        mov     ah,9
                    196:        mov     bx,atr          ;get page (bh) and attribute (bl)
                    197:        mov     cx,1
                    198:        int     10h             ;write char and attr at cursor position
                    199:        mov     ah,col
                    200:        inc     col             ;advance cursor on line
                    201:        cmp     ah,wid
                    202:        jc      updc            ;not at end of line, update cursor and exit
                    203: 
                    204:        mov     col,0           ;set column zero (cr)
                    205: outlf: test    xla,1
                    206:        jz      nocrlf          ;send lf alone
                    207:        mov     col,0
                    208: nocrlf:        mov     ah,lin
                    209:        cmp     ah,lps
                    210:        jc      upda            ;not at end of screen, update cursor and exit
                    211:        jnz     updn            ;past end of screen, cr only
                    212: 
                    213:        mov     ax,601h         ;scroll (ah) number of lines (al)
                    214:        mov     bh,atr          ;current attribute
                    215:        xor     cx,cx           ;upper left corner of window (0,0)
                    216:        mov     dx,wid          ;lower right corner of window (wid,lps)
                    217:        int     10h             ;scroll window up one line      
                    218: 
                    219: updn:  dec     lin             ;leave current line number unchanged
                    220: upda:  inc     lin             ;advance to next line
                    221: updc:  mov     ah,2
                    222:        mov     bh,pag
                    223:        mov     dx,col
                    224:        int     10h             ;update cursor position
                    225: 
                    226: pexit: xor     ax,ax           ;return zero
                    227:        pop     bp
                    228:        ret
                    229: _lputc endp
                    230: 
                    231: ; Put string to console (uses _lputc for each character)
                    232: 
                    233: _lputs proc
                    234:        push    bp
                    235:        mov     bp,sp
                    236:        push    es
                    237:        mov     ax,pb[bp+2]     ;string segment
                    238:        mov     bx,pb[bp]       ;string offset
                    239:        mov     es,ax
                    240:        xor     dh,dh
                    241: nxtch: mov     dl,es:[bx]      ;character to output
                    242:        or      dl,dl
                    243:        jz      sexit
                    244: 
                    245:        inc     bx              ;address next character
                    246:        jnz     nowrap
                    247:        mov     ax,es
                    248:        add     ax,100h         ;add 64k to segment pointer
                    249:        mov     es,ax
                    250: nowrap:        push    bx              ;save offset
                    251:        push    dx              ;arg 1
                    252:        call    _lputc          ;put character
                    253:        pop     dx
                    254:        pop     bx
                    255:        jmp     nxtch
                    256: 
                    257: sexit: mov     ax,pb[bp]
                    258:        mov     dx,pb[bp+2]
                    259:        pop     es
                    260:        pop     bp
                    261:        ret
                    262: _lputs endp
                    263: 
                    264:        end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.