home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 199_01 / gedio.asm < prev    next >
Assembly Source File  |  1987-12-17  |  29KB  |  1,016 lines

  1. ;------------------------------------------------------------------
  2. ; Gedio.asm: Screen and keyboard interface routines for the PC
  3. ;
  4. ; For GED WordStar-like screen editor
  5. ; DeSmet C implementation by Mel Tearle - 08/06/86
  6. ;
  7. ; Microsoft Macroassembler implementation by Michael Yokoyama - 12/06/86
  8. ; Revised by Mel Tearle - 07/25/87
  9. ;
  10. ; data starts here
  11. ;------------------------------------------------------------------
  12.  
  13. _data segment word public 'data'
  14. const segment word public 'const'
  15. const ends
  16.  
  17. _bss segment word public 'bss'
  18. _bss ends
  19.  
  20.  dgroup group const,_bss,_data
  21.  assume cs: _text, ds: dgroup, ss: dgroup, es: dgroup
  22.  
  23. ; In this implementation, all special and function keys are translated
  24. ; to the following values.
  25. ; control key translations
  26.  
  27.  
  28. ; control key translations - mapped into cursor-pad.
  29.  
  30. up_char         equ   5     ;arrow up
  31. down_char       equ  24     ;arrow down
  32. left_char       equ  19     ;arrow left
  33. right_char      equ   4     ;arrow right
  34. bol_char        equ  15     ;Home
  35. eol_char        equ  16     ;End
  36. pageup_char     equ  18     ;PgUp
  37. pagedown_char   equ   3     ;PgDn
  38. Del_char        equ   7     ;Del
  39.  
  40. ; function key definitions
  41.  
  42. M1      equ 128
  43. M2      equ 129
  44. M3      equ 130
  45. M4      equ 145
  46. M5      equ 132
  47. M6      equ 133
  48. M7      equ 134
  49. M8      equ 135
  50. M9      equ 136
  51. M10     equ 137
  52.  
  53. ; special keys - toggles and keypress
  54.  
  55. Insert_key      equ 138
  56. Caps_Lock_on    equ 139
  57. Caps_Lock_off   equ 140
  58. Alt_key         equ 146
  59.  
  60. grey_minus      equ 142
  61. grey_plus       equ 143
  62.  
  63.  
  64. ; the table that is used to make the translation
  65. ; note - not all used
  66.  
  67. convert db  72,  up_char
  68.         db  80,  down_char
  69.         db  75,  left_char
  70.         db  77,  right_char
  71.         db  71,  bol_char
  72.         db  79,  eol_char
  73.         db  73,  pageup_char
  74.         db  81,  pagedown_char
  75. ;       db  78,  grey_plus
  76. ;       db  74,  grey_minus
  77.         db  82,  Insert_key
  78.         db  83,  Del_char
  79.  
  80.         db  59, M1
  81.         db  60, M2
  82.         db  61, M3
  83.         db  62, M4
  84.         db  63, M5
  85.         db  64, M6
  86.         db  65, M7
  87.         db  66, M8
  88.         db  67, M9
  89.         db  68, M10
  90.         db   0, 255     ;illegal character
  91.  
  92.  
  93. ; equates for bios interface.
  94. ; the interrupt and codes for the screen interface interrupt.
  95.  
  96. video       equ 10h     ;interrupt for dealing with screen
  97.  
  98. mode        equ 0       ;code for setting new screen mode
  99. curtype     equ 1       ;code for setting new cursor type
  100. setcur      equ 2       ;code for addressing cursor
  101. readcur     equ 3       ;code for reading cursor location
  102. readlp      equ 4       ;code for reading light pen position
  103. setpage     equ 5       ;code to select active page
  104. scrollup    equ 6       ;code to scroll screen up
  105. scrolldn    equ 7       ;code to scroll screen nown
  106. readch      equ 8       ;code to read a character from screen
  107. writeach    equ 9       ;code to write char and attributes
  108. writech     equ 10      ;code to write character only
  109. setpal      equ 11      ;code to set new setpal or border
  110. wdot        equ 12      ;code to write a dot
  111. rdot        equ 13      ;code to read a dot
  112. wtty        equ 14      ;code to write as if teletype
  113. state       equ 15      ;code to find current screen status
  114.  
  115. ; used in set_video
  116.  
  117. mono_adr     equ  0b000h   ;mono adapter
  118. graph_adr    equ  0b800h   ;graphics adapter*
  119.  
  120. vadrs        dw  0
  121.  
  122. ; the interrupt and codes for the keyboard interface.
  123.  
  124. keyboard     equ 16h     ;interrupt 16 to deal with keyboard
  125.  
  126. cicode       equ 0       ;code for reading a character
  127. cstscode     equ 1       ;reports if character is ready
  128. kbstatus     equ 2       ;get keyboard status - shifts, caplocks
  129.  
  130. kbset        db  0
  131.  
  132. ; caution: must change column number if 40 column mode
  133.  
  134. crt_cols     equ 80
  135.  
  136. ; Note: 25 for MS-DOS, 24 for CP/M as cp/m steals the bottom line.
  137.  
  138. _scr_rows dw 24           ; current number of rows, for ged, was 25
  139. _scr_cols dw crt_cols     ; current number of columns
  140. _scr_mode db 0            ; current screen mode
  141. _scr_page db 0            ; current page
  142. _scr_attr db 7            ; current attributes for screen
  143.                           ; 7 is white letters on black
  144. _scr_window_top db 1      ; first line to scroll, was 0
  145.  
  146. _data ends
  147.  
  148. ;------------------------------------------------------------------
  149. ;  code starts here
  150. ;------------------------------------------------------------------
  151.  
  152.  _text segment byte public 'code'
  153.  assume cs:_text
  154.  
  155. ; Variables available to C programs
  156.  
  157.  public _scr_cols,    _scr_rows,     _scr_xy,      _scr_clr
  158.  public _scr_mode,    _scr_page,     _scr_attr,    _scr_window_top
  159.  public _scr_setup,   _scr_term,     _scr_csts,    _scr_setmode
  160.  public _scr_clrl,    _scr_cls,      _scr_scup,    _scr_scrup
  161.  public _scr_scrdn,   _scr_co,       _scr_ci,      _get_graphic
  162.  public _scr_sinp,    _scr_cursoff,  _scr_curson,  _scr_mark
  163.  public _scr_putch,   _scr_delete,   _get_mode,    _calc_video
  164.  public _scr_putstr,  _scr_aputch,   _get_kbstat,  _caps_on
  165.  public _scr_scdn,    _scr_aputs,    _set_video
  166.  
  167.  
  168. ;-------------------------------------------------------------------------
  169. ;  _scr_setup   Call _scr_setup before using any other routine unless the
  170. ;               starting mode is 80X25 character mode (3,4, or 7).
  171. ;               This routine must be called for monochrome (mode 7)
  172. ;               for _scr_curson to set a proper cursor.
  173. ;
  174. ;  Usage: mode = _scr_setup();
  175. ;-------------------------------------------------------------------------
  176.  
  177. _scr_setup proc near
  178.     push  bp
  179.     mov   bp, sp
  180.  
  181.     mov   ah,state           ; get current state
  182.     int   video
  183.     mov   _scr_mode, al      ; current mode
  184.     mov   cl,ah              ; make cols a word
  185.     mov   ch,0
  186.     mov   _scr_cols, cx      ; 40 or 80 columns
  187.     mov   _scr_page, bh
  188.     mov   _scr_attr, 7       ; set to white chars on black
  189.     cmp   al, 4              ; see if a character mode
  190.     jc    got_attr
  191.     cmp   al, 7              ; 7 is for graphics mode
  192.     jz    got_attr
  193.     mov   _scr_attr, 0       ; attribute is zero in graphics
  194. got_attr:
  195.     mov   ah,0               ; return int containing mode
  196.     push  ax                 ; slight detour
  197.     call  _set_video         ; get display address
  198.     pop   ax
  199.  
  200.     pop   bp
  201.     ret
  202. _scr_setup endp
  203.  
  204.  
  205. ;-------------------------------------------------------
  206. ; _scr_term   Do any required termination.
  207. ;
  208. ;  Usage:     _scr_term();
  209. ;-------------------------------------------------------
  210.  
  211. _scr_term proc near
  212.     ret
  213. _scr_term endp
  214.  
  215.  
  216. ;-------------------------------------------------------
  217. ;  _scr_setmode    Set a new screen mode.
  218. ;  Usage:          _scr_setmode(new mode);
  219. ;-------------------------------------------------------
  220.  
  221. _scr_setmode proc near
  222.     push  bp
  223.     mov   bp, sp
  224.  
  225.     mov   al, [bp+4]  ; new mode value
  226.     mov   ah, mode
  227.     int   video       ; set new mode
  228.     call  _scr_setup  ; remember new values
  229.  
  230.     pop   bp
  231.     ret
  232. _scr_setmode endp
  233.  
  234.  
  235. ;-------------------------------------------------------
  236. ;  _scr_xy   Sets cursor at any location.
  237. ;
  238. ;  Usage:    _scr_xy( col, row );
  239. ;-------------------------------------------------------
  240.  
  241. _scr_xy  proc near
  242.     push  bp
  243.     mov   bp, sp
  244.  
  245.     mov   dx, [bp+4]          ; col
  246.     mov   ax, [bp+6]          ; row
  247.     mov   dh, al
  248.     mov   bh, _scr_page       ; force page zero
  249.     mov   ah, setcur          ; set cursor location
  250.     int   video               ; call BIOS
  251.  
  252.     pop   bp
  253.     ret
  254. _scr_xy endp
  255.  
  256.  
  257. ;-------------------------------------------------------
  258. ;  _scr_clr   Clear entire screen
  259. ;
  260. ;  Usage:     _scr_clr();
  261. ;-------------------------------------------------------
  262.  
  263. _scr_clr proc near
  264.     push  bp
  265.     mov   bp, sp
  266.  
  267.     mov   al, 0              ; ask for a clear window
  268.     xor   cx, cx             ; start at 0,0
  269.     mov   dh, byte ptr _scr_rows     ;last line
  270.     dec   dh
  271.     mov   dl, byte ptr _scr_cols     ;clear entire width
  272.     dec   dl                 ; last column is width-1
  273.     mov   bh, _scr_attr      ; attributes for new blanks
  274.     mov   ah, scrollup       ; ask for a scrollup to clear
  275.     int   video              ; do the clear
  276.  
  277.     pop   bp
  278.     ret
  279. _scr_clr endp
  280.  
  281.  
  282. ;-------------------------------------------------------
  283. ;  _scr_clrl    Clear rest of line.
  284. ;
  285. ;  Usage:       _scr_clrl();
  286. ;-------------------------------------------------------
  287.  
  288. _scr_clrl proc near
  289.     push  bp
  290.     mov   bp, sp
  291.  
  292.     mov   bh, _scr_page
  293.     mov   ah, readcur         ; see where we are
  294.     int   video
  295.  
  296.     mov   cl, byte ptr _scr_cols     ; calc how many chars left in line
  297.     sub   cl, dl              ; number left
  298.     mov   ch, 0               ; number of blanks needed
  299.     mov   al, ' '             ; write blanks
  300.     mov   bl, _scr_attr       ; normal attributes
  301.     mov   bh, _scr_page       ; page number
  302.     mov   ah, writeach        ; write the blanks
  303.     int   video
  304.  
  305.     pop   bp
  306.     ret
  307. _scr_clrl endp
  308.  
  309.  
  310. ;-------------------------------------------------------
  311. ;  _scr_cls     Clear rest of screen starting at y
  312. ;               set line pointer, clear screen, reset line pointer
  313. ;
  314. ;  Usage:      _scr_cls(y);
  315. ;-------------------------------------------------------
  316.  
  317. _scr_cls proc near
  318.     push  bp
  319.     mov   bp, sp
  320.  
  321.     mov   dx, 0               ; hard-code column at 0
  322.     mov   ax, [bp+4]          ; get row
  323.     mov   dh, al
  324.  
  325.     mov   bh, _scr_page       ; force page zero
  326.     mov   ah, setcur          ; set cursor location
  327.     int   video               ; call bios
  328.  
  329.     call  _scr_clrl           ; clear rest of line
  330.  
  331.     mov   al, 0               ; ask for a clear window
  332.     mov   ch, [bp+4]          ; re-use row
  333.  
  334.     inc   ch                  ; bump row
  335.     cmp   ch, byte ptr _scr_rows   ; see if in last line
  336.     jz    cleared             ; all done
  337.     mov   cl, 0               ; first column
  338.     mov   dh, byte ptr _scr_rows   ; 24 is the last line
  339.     dec   dh
  340.     mov   dl, byte ptr _scr_cols   ; clear entire width
  341.     dec   dl                  ; last column is width-1
  342.     mov   bh, _scr_attr       ; attributes for new blanks
  343.     mov   ah, scrollup        ; ask for a scrollup to clear
  344.     int   video               ; do the clear
  345. cleared:
  346.     mov   dx, 0               ; set column again
  347.     mov   ax, [bp+4]          ; get row
  348.     mov   dh, al
  349.  
  350.     mov   bh, _scr_page       ; force page zero
  351.     mov   ah, setcur          ; set cursor location
  352.     int   video               ; call bios
  353.  
  354.     pop   bp
  355.     ret
  356. _scr_cls endp
  357.  
  358.  
  359. ;--------------------------------------------------------
  360. ;  _scr_delete    Clears rest of line starting at x,y.
  361. ;
  362. ;  Usage:         _scr_delete(x,y);
  363. ;--------------------------------------------------------
  364.  
  365. _scr_delete proc near
  366.     push  bp
  367.     mov   bp, sp
  368.  
  369.     mov   dx, [bp+4]          ; col
  370.     mov   ax, [bp+6]          ; row
  371.     mov   dh, al
  372.  
  373.     mov   bh, _scr_page       ; force page zero
  374.     mov   ah, setcur          ; set cursor location
  375.     int   video               ; call BIOS
  376.  
  377.     mov   cl, byte ptr _scr_cols        ; calc how many chars left in line
  378.     sub   cl, dl              ; number left
  379.     mov   ch, 0               ; number of blanks needed
  380.     mov   al, ' '             ; write blanks
  381.     mov   bl, _scr_attr       ; normal attributes
  382.     mov   bh, _scr_page       ; page number
  383.     mov   ah, writeach        ; write the blanks
  384.  
  385.     int   video
  386.     pop   bp
  387.     ret
  388. _scr_delete endp
  389.  
  390.  
  391. ;--------------------------------------------------------
  392. ;  _scr_scup    Scroll text up from last line to
  393. ;               _scr_window_top, leaving top lines alone.
  394. ;
  395. ;  Usage:      _scr_scup();
  396. ;--------------------------------------------------------
  397.  
  398. _scr_scup proc near
  399.  
  400.     mov   ax, _scr_cols        ; need last column of screen
  401.     dec   ax
  402.     push  ax
  403.     mov   ax, _scr_rows        ; scroll through last line
  404.     dec   ax
  405.     push  ax
  406.     xor   ax, ax               ; from column 0
  407.     push  ax
  408.     mov   al, _scr_window_top  ;leave top line alone
  409.     push  ax
  410.     mov   al, 1
  411.     push  ax                   ; scroll by 1
  412.     call  _scr_scrup           ; do the scroll
  413.     add   sp, 10               ; clear arge
  414.  
  415.     ret
  416. _scr_scup endp
  417.  
  418.  
  419. ;---------------------------------------------------------------
  420. ;  _scr_scrup      Scroll the screen up. The window is scrolled
  421. ;                  up nline lines. A zero nline will clear the
  422. ;                  window. Top left of the screen in 0,0.
  423. ;
  424. ;  Usage:          _scr_scrup(nline,fromrow,fromcol,torow,tocol);
  425. ;---------------------------------------------------------------
  426.  
  427. _scr_scrup proc near
  428.     push bp
  429.     mov  bp, sp
  430.  
  431.     mov  al, [bp+4]          ; number of lines
  432.     mov  ch, [bp+6]          ; starting row
  433.     mov  cl, [bp+8]          ; starting column
  434.     mov  dh, [bp+10]         ; ending row
  435.     mov  dl, [bp+12]         ; ending column
  436.     mov  bh, _scr_attr       ; current attribute
  437.     mov  ah, scrollup
  438.     int  video               ; do the scroll
  439.  
  440.     pop  bp
  441.     ret
  442. _scr_scrup endp
  443.  
  444.  
  445. ;-------------------------------------------------------------
  446. ;  _scr_scdn    Scroll all but the top lines down one.
  447. ;
  448. ;  Usage:      _scr_scdn();
  449. ;-------------------------------------------------------------
  450.  
  451. _scr_scdn proc near
  452.  
  453.     mov   ax, _scr_cols         ; need last column of screen
  454.     dec   ax
  455.     push  ax
  456.     mov   ax, _scr_rows         ; scroll through last line
  457.     dec   ax
  458.     push  ax
  459.     xor   ax, ax                ; from column 0
  460.     push  ax
  461.     mov   al, _scr_window_top   ; leave top lines alone
  462.     push  ax
  463.     mov   al, 1
  464.     push  ax                    ; scroll by 1
  465.     call  _scr_scrdn            ; do the scroll
  466.     add   sp, 10                ; clear arge
  467.  
  468.     ret
  469. _scr_scdn endp
  470.  
  471.  
  472. ;---------------------------------------------------------------
  473. ;  _scr_scrdn    Scroll the screen down. the window is scrolled
  474. ;                down nline lines. A zero nline will clear the
  475. ;                window. Top left of the screen in 0,0.
  476. ;
  477. ;  Usage:        _scr_scrdn(nline,fromrow,fromcol,torow,tocol);
  478. ;---------------------------------------------------------------
  479.  
  480. _scr_scrdn proc near
  481.     push  bp
  482.     mov   bp, sp
  483.  
  484.     mov   al, [bp+4]          ; number of lines
  485.     mov   ch, [bp+6]          ; starting row
  486.     mov   cl, [bp+8]          ; starting column
  487.     mov   dh, [bp+10]         ; ending row
  488.     mov   dl, [bp+12]         ; ending column
  489.     mov   bh, _scr_attr       ; current attribute
  490.     mov   ah, scrolldn
  491.     int   video               ; do the scroll
  492.  
  493.     pop   bp
  494.     ret
  495. _scr_scrdn endp
  496.  
  497.  
  498. ;---------------------------------------------------------------
  499. ;  _scr_co     Write a character to the screen TTY style. This
  500. ;              routine increments the cursor position
  501. ;              after writing.
  502. ;
  503. ;  Usage:      _scr_co(character);
  504. ;---------------------------------------------------------------
  505.  
  506. _scr_co proc near
  507.     push  bp
  508.     mov   bp, sp
  509.  
  510.     mov   al, [bp+4]          ; character to write
  511.     mov   bh, _scr_page
  512.     mov   ah, wtty            ; use tty write routine
  513.     int   video
  514.  
  515.     pop bp
  516.     ret
  517. _scr_co endp
  518.  
  519.  
  520. ;---------------------------------------------------------------
  521. ;  _scr_ci        Keyboard input. function and soft keys are
  522. ;                 translated. see equates for values.
  523. ;
  524. ;  Usage:         character = _scr_ci();
  525. ;---------------------------------------------------------------
  526.  
  527. _scr_ci proc near
  528.     push  bp
  529.     mov   ah, cicode          ; ask for a keyboard character
  530.     int   keyboard            ; do interrupt
  531.  
  532.     cmp   ax, 4a2dh           ; test for grey keys
  533.     je    minus_grey
  534.  
  535.     cmp   ax, 4e2bh           ; grep plus by default
  536.     jne   continue
  537.  
  538.     mov   al, grey_plus
  539.     jmp   not_special
  540.  
  541. minus_grey:
  542.     mov   al, grey_minus
  543.     jmp   not_special
  544.  
  545. continue:
  546.     cmp   al, 0               ; is low byte equal to zero?
  547.     jne   not_special         ; it's not - must be ascii so return it
  548.     mov   bx, ds:[offset convert]  ; else convert to special key
  549. ci_loop:
  550.     cmp   byte ptr [bx], 0    ; are we done?
  551.     jz    got_it              ; it's zero - so end routine
  552.     cmp   ah, byte ptr [bx]   ; else does it equal the high byte?
  553.     je    got_it              ; got a hit - finish up
  554.     add   bx, 2               ; else bump bx
  555.     jmp   ci_loop
  556. got_it:
  557.     inc   bx                  ; get return value from convert
  558.     mov   al, byte ptr [bx]   ; put it in low byte
  559. not_special:
  560.     mov   ah, 0               ; normal return
  561.  
  562.     pop   bp
  563.     ret
  564. _scr_ci endp
  565.  
  566.  
  567. ;---------------------------------------------------------------
  568. ;  _scr_csts     Returns character if available, otherwise zero.
  569. ;
  570. ;  Usage:        character = _scr_csts();
  571. ;---------------------------------------------------------------
  572.  
  573. _scr_csts proc near
  574.     push  bp
  575.     mov   ah, cstscode
  576.     int   keyboard
  577.  
  578.     mov   ax, 0
  579.     jz    kbstat
  580.     call  _scr_ci             ; get the coded character
  581.     jmp   fin
  582. kbstat:
  583.     call  _get_kbstat
  584. fin:
  585.     pop bp
  586.     ret
  587. _scr_csts endp
  588.  
  589.  
  590. ;---------------------------------------------------------------
  591. ; _get_kbstat   check status of insert key, capslock and alt key
  592. ;               return special value or zero.
  593. ;
  594. ; Usage:        internal routine used by scr_csts();
  595. ;---------------------------------------------------------------
  596.  
  597. _get_kbstat  proc near
  598.     push  bp
  599.  
  600.     mov   ah, kbstatus      ; get keyboard status
  601.     int   keyboard
  602.  
  603.     cmp   al, kbset         ; set if keyboard status is changed
  604.     je    return_0          ; if same - return 0
  605.  
  606.     mov   kbset, al         ; new keyboard toggle - save it
  607.  
  608.     test  al, 08h           ; test for alt press
  609.     jnz   alt_pressed
  610.  
  611.     test  al, 40h           ; test for caps lock on
  612.     jnz   caps_on
  613.  
  614.     and   al, 40h           ; reverse bits
  615.     test  al, 40h           ; test if caps lock off
  616.     jz    caps_off          ; if zero then toggled off
  617.  
  618. return_0:
  619.     mov   al, 0             ; return 0 - no hits
  620.     jmp   fin3
  621. alt_pressed:
  622.     mov   al, Alt_key
  623.     jmp   fin3
  624. caps_on:
  625.     mov   al, Caps_Lock_on
  626.     jmp   fin3
  627. caps_off:
  628.     mov   al, Caps_Lock_off
  629. fin3:
  630.     mov   ah, 0
  631.  
  632.     pop   bp
  633.     ret
  634. _get_kbstat endp
  635.  
  636.  
  637. ;---------------------------------------------------------------
  638. ; _caps_on     check status of capslock only
  639. ;              if on then return CAPSLKON
  640. ;
  641. ; Usage:       if ( caps_on() )  do something
  642. ;---------------------------------------------------------------
  643.  
  644. _caps_on proc near
  645.      push  bp
  646.  
  647.      mov   ah, kbstatus      ; get keyboard status
  648.      int   keyboard
  649.  
  650.      test  al, 40h           ; test for caps lock on
  651.      jnz   caps_on1
  652.  
  653.      mov   al, 0             ; return 0 - no hits
  654.      jmp   fin4
  655. caps_on1:
  656.      mov   al, Caps_Lock_on
  657. fin4:
  658.      mov   ah, 0
  659.  
  660.      pop   bp
  661.      ret
  662. _caps_on  endp
  663.  
  664.  
  665. ;---------------------------------------------------------------
  666. ;  _get_graphic   return the next char in buffer - unfiltered
  667. ;
  668. ;  Usage:         character = get_graphic();
  669. ;---------------------------------------------------------------
  670.  
  671. _get_graphic proc near
  672.     push  bp
  673.  
  674.     mov   ah, cicode          ; ask for a keyboard character
  675.     int   keyboard            ; do interrupt
  676.     mov   ah, 0               ; normal return
  677.  
  678.     pop   bp
  679.     ret
  680. _get_graphic endp
  681.  
  682.  
  683. ;---------------------------------------------------------------
  684. ;  _scr_cursoff       Turns cursor off.
  685. ;
  686. ;  Usage:            _scr_cursoff();
  687. ;---------------------------------------------------------------
  688.  
  689. _scr_cursoff proc near
  690.     push  bp                 ; save registers
  691.     cmp   _scr_mode, 4       ; see if graphics
  692.     jc    text_coff
  693.     cmp   _scr_mode, 7
  694.     jnz   no_cur
  695. text_coff:
  696.     mov   cx, 0f00h          ; should turn cursor off
  697. new_cur:
  698.     mov   ah, curtype        ; set a new cursor type
  699.     int   video
  700. no_cur:
  701.  
  702.     pop bp
  703.     ret
  704. _scr_cursoff endp
  705.  
  706.  
  707. ;---------------------------------------------------------------
  708. ;  _scr_curson       Turns cursor on.
  709. ;
  710. ;  Usage:           _scr_curson();
  711. ;---------------------------------------------------------------
  712.  
  713. _scr_curson proc near
  714.     push  bp
  715.     mov   cx, 0c0dh           ; assume monocrome
  716.     cmp   _scr_mode, 7        ; true is mono
  717.     jz    new_cur             ; set it
  718.     mov   cx,0607h            ; assume color card in text mode
  719.     cmp   _scr_mode,4         ; color text is 0 to 3
  720.     jc    new_cur
  721.  
  722.     pop   bp                  ; do nothing if in graphics mode
  723.     ret
  724. _scr_curson endp
  725.  
  726.  
  727. ;---------------------------------------------------------------
  728. ;  _scr_aputs     Writes a string and attributes to the screen.
  729. ;                 The cursor is moved normally.
  730. ;                 Standard Bios write.
  731. ;
  732. ;  Usage:        _scr_aputs( x,y, "Print This", attribute );
  733. ;---------------------------------------------------------------
  734.  
  735. _scr_aputs proc near
  736.     push  bp
  737.     mov   bp, sp
  738.  
  739.     mov   dx, [bp+4]       ; col
  740.     mov   ax, [bp+6]       ; row
  741.     mov   dh, al
  742.  
  743.     mov   bh, _scr_page    ; force page
  744.     mov   ah, setcur       ; set cursor location
  745.     int   video            ; dx is cursor location, bh is page
  746.  
  747.     mov   si, [bp+8]       ; string pointer
  748.     mov   cx, 1            ; number of characters to write
  749.     mov   bl, [bp+10]      ; attribute
  750. naputs:
  751.     cld
  752.     lodsb                  ; next character to write
  753.     or    al, al           ; zero at end
  754.     jz    eaputs
  755.     cmp   al, 10           ; look for LF
  756.     jnz   normal_ap
  757. ap_scroll:
  758.     mov   bp, sp           ; reset pointer to next char
  759.     mov   [bp+4], si
  760.     mov   al, 13           ; use tty output to scroll screen
  761.     mov   ah, wtty
  762.     int   video            ; write cr,lf
  763.     mov   ah, wtty
  764.     mov   al, 10
  765.     int   video
  766.     pop   bp
  767.     jmp   _scr_aputs       ; start over
  768. normal_ap:
  769.     mov   bh, _scr_page    ; page number
  770.     mov   ah, writeach     ; write char and attr
  771.     int   video            ; write character and attributes
  772.     inc   dl               ; next column
  773.     cmp   dl, byte ptr crt_cols     ; see if wrapping around
  774.     jc    set_loc
  775.     mov   dl, 0            ; at start of column
  776.     inc   dh               ; at next row
  777.     cmp   dh, byte ptr _scr_rows    ; see if need a scroll
  778.     jc    set_loc
  779.     jmp   ap_scroll        ; do a scroll up
  780. set_loc:
  781.     mov   ah, setcur       ; move the cursor
  782.     int   video
  783.     jmp   naputs
  784. eaputs:
  785.  
  786.     pop bp
  787.     ret
  788. _scr_aputs endp
  789.  
  790.  
  791. ;-------------------------------------------------------------------
  792. ;  _scr_putch     Write a character to the screen with attribute set.
  793. ;                 standard Bios write
  794. ;
  795. ;  Usage:        _scr_putch( character, attribute );
  796. ;-------------------------------------------------------------------
  797.  
  798. _scr_putch proc near
  799.     push  bp
  800.     mov   bp, sp
  801.  
  802.     mov   ah, readcur        ; see where we are
  803.     mov   bh, _scr_page
  804.     int   video              ; dx is cursor location, bh is page
  805.  
  806.     mov   al, [bp+4]         ; character to write
  807.     mov   bl, [bp+6]         ; attribute of char
  808.     mov   bh, _scr_page      ; set page number
  809.     mov   cx, 1              ; write just one char
  810.     mov   ah, writeach       ; write char and attr
  811.     int   video
  812.  
  813.     inc   dl                 ; move to next column
  814.     mov   ah, setcur         ; move the cursor
  815.     int   video
  816.  
  817.     pop   bp
  818.     ret
  819. _scr_putch endp
  820.  
  821.  
  822. ;--------------------------------------------------------------
  823. ;
  824. ;   The following routines _get_mode, _calc_video, _set_video
  825. ;   and _scr_putstr were adapted from
  826. ;   Computer Language Magazine - January 1986
  827. ;   "Assembly Video Routines for your P.C.",  Thomas Webb
  828. ;
  829. ;--------------------------------------------------------------
  830.  
  831.  
  832. ;--------------------------------------------------------------
  833. ;  _get_mode       get video mode
  834. ;
  835. ;  Usage:          internal subroutine used in _scr_putstr
  836. ;--------------------------------------------------------------
  837.  
  838. _get_mode  proc near
  839.     push bp
  840.  
  841.     mov  ax, 0
  842.     mov  ah, 15
  843.     int  10h
  844.  
  845.     pop  bp
  846.     ret
  847. _get_mode endp
  848.  
  849.  
  850. ;----------------------------------------------------------
  851. ;  _calc_video    calculate offset into video buffer
  852. ;                 set begining location and attribute
  853. ;
  854. ;  Usage:         internal subroutine used in _scr_putstr
  855. ;----------------------------------------------------------
  856.  
  857. _calc_video  proc near
  858.     mov  ax, byte ptr crt_cols
  859.     mul  dx
  860.     add  ax, cx
  861.     shl  ax, 1
  862.  
  863.     ret
  864. _calc_video endp
  865.  
  866.  
  867. ;-------------------------------------------------------
  868. ;  _set_video     set video address
  869. ;
  870. ;  Usage:         internal subroutine used in _scr_putstr
  871. ;-------------------------------------------------------
  872.  
  873. _set_video  proc near
  874.     call  _get_mode
  875.     cmp   al,  7h
  876.     jne   adp_graphics
  877.     mov   ax, mono_adr
  878.     jmp   return
  879. adp_graphics:
  880.     mov   ax, graph_adr
  881. return:
  882.     mov   vadrs, ax
  883.  
  884.     ret
  885. _set_video endp
  886.  
  887.  
  888. ;----------------------------------------------------------
  889. ;  _scr_putstr      Writes a string directly to video buffer,
  890. ;                   given the (x,y) location and attribute.
  891. ;
  892. ;  Usage:           _scr_putstr(x, y, string, attribute);
  893. ;----------------------------------------------------------
  894.  
  895. _scr_putstr proc near
  896.     push  es
  897.     push  bp
  898.     mov   bp, sp
  899.  
  900.     mov   dx, [bp+8]       ; get col
  901.     mov   cx, [bp+6]       ; get row
  902.  
  903. ; locate position in video buffer - calc video moved to save a call
  904.  
  905.     mov   ax, crt_cols     ; calc video routine
  906.     mul   dx               ; moved here
  907.     add   ax, cx           ; to save a call
  908.     shl   ax, 1
  909.     mov   di, ax           ; return position
  910.  
  911.     mov   si, [bp+10]      ; get string
  912.     mov   dh, [bp+12]      ; get attribute
  913.     mov   es, vadrs        ; get display address from setup
  914.  
  915. str_loop:
  916.     mov   dl, byte ptr [si]    ; move the cursor
  917.     cmp   dl, 0                ; if end then exit
  918.     je    str_exit
  919.  
  920.     mov   es:word ptr [di], dx   ; move word into screen display
  921.     add   di, 2h             ; bump string pointer
  922.     inc   si
  923.     jmp   str_loop
  924.  
  925. str_exit:
  926.  
  927.     pop   bp
  928.     pop   es
  929.     ret
  930. _scr_putstr endp
  931.  
  932.  
  933. ;---------------------------------------------------------------
  934. ;  _scr_aputch         Writes a character to the screen with
  935. ;                      attribute set.  See _scr_aputs and _scr_co
  936. ;
  937. ;  Usage: _scr_aputch(x,y,char,attribute);
  938. ;
  939. ;  After getting this to work found that it isn't that fast.
  940. ;  However, it's a good replacement for gotoxy() _scr_putch()
  941. ;  if you're only writing one char to a specific location.
  942. ;
  943. ;---------------------------------------------------------------
  944.  
  945. _scr_aputch proc near
  946.     push  es
  947.     push  bp
  948.     mov   bp, sp
  949.  
  950.     mov   dx, [bp+8]         ; get col
  951.     mov   cx, [bp+6]         ; get row
  952.     call  _calc_video        ; locate position in video buffer
  953.     mov   di, ax             ; return position
  954.     mov   dl, [bp+10]        ; get char
  955.     mov   dh, [bp+12]        ; get attribute
  956.     mov   ax, vadrs          ; get video address
  957.     mov   es, ax             ; move buffer address to es
  958.     mov   es:word ptr [di], dx
  959.  
  960.     pop   bp
  961.     pop   es
  962.     ret
  963. _scr_aputch endp
  964.  
  965.  
  966. ;---------------------------------------------------------------
  967. ;  _scr_sinp    Screen input (read character from the screen).
  968. ;
  969. ;  Usage:       character = _scr_sinp();   not used
  970. ;---------------------------------------------------------------
  971.  
  972. _scr_sinp proc near
  973.     push  bp               ; save the registers
  974.     mov   bh, _scr_page
  975.     mov   ah, readch       ; Code to read a character
  976.     int   video            ; al is letter, ah=attributes
  977.     or    al, al           ; zero returned instead of blank in
  978.                            ; graphics mode
  979.     jnz   ret_ch
  980.     mov   al, ' '
  981. ret_ch:
  982.     mov   ah, 0            ; kill the attributes
  983.  
  984.     pop   bp
  985.     ret
  986. _scr_sinp endp
  987.  
  988.  
  989. ;---------------------------------------------------------------
  990. ;  _scr_mark       Marks the current character on the screen.
  991. ;                  Used to delimit block.
  992. ;
  993. ;   Usage: _scr_mark(current character)   not used
  994. ;---------------------------------------------------------------
  995.  
  996. ;mark the passed char, cursor does not advance
  997. _scr_mark proc near
  998.     push bp
  999.     mov  al, 219             ; just write a block character
  1000.     mov  bl, _scr_attr       ; normal attributes
  1001.     mov  cx, 1               ; one character
  1002.     mov  bh, _scr_page       ; page number
  1003.     mov  ah, writeach        ; write char and attr
  1004.     int  video               ; write character and attributes
  1005.  
  1006.     pop  bp
  1007.     ret
  1008. _scr_mark endp
  1009.  
  1010. _text ends
  1011.  
  1012. ; That's all!
  1013.  
  1014. end
  1015.