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.a < prev    next >
Text File  |  1987-12-17  |  30KB  |  983 lines

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