home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 331_01 / pcio.asm < prev    next >
Assembly Source File  |  1990-06-12  |  34KB  |  1,229 lines

  1. ; pcio
  2.  
  3. ; Most of these routines should not be called directly by the application.
  4. ; Routines are being added in term.c which relay the call to here.  In that
  5. ; way terminal specific functions will be consolidated in term.c.  By
  6. ; changing just term.c the program can be adapted to a different host,
  7. ; resulting in better portability.  Many of the routines contained here
  8. ; are unused, but may be useful for other applications.  Many of these
  9. ; functions could also be implemented mostly in C.  Some assembly language
  10. ; is essential for speed on slow systems, but it becomes less important
  11. ; on fast processors, and may eventually have to go away altogether for
  12. ; better portability.  The standard BIOS video calls are incredibly slow,
  13. ; and are mostly unused here.  On an 80386 system the screen refresh time
  14. ; is less than the keyboard autorepeat time with the interface in this
  15. ; file.
  16. ;
  17. ;                                 May 87 G. Osborn
  18.  
  19.  
  20.  
  21. ; Converted from DeSmet to the Microsoft version  3.0 macro
  22. ; assembler format.  Microsoft does not follow data labels
  23. ; by a colon.  Code segment labels are followed by a colon, though.
  24. ; Changed "byte" to "byte ptr" throughout.
  25.  
  26. ; Changed calling sequence to that of Microsoft C compiler version 3.0.
  27. ; Same as DeSmet except SI and DI must be saved in case register
  28. ; variables are used, so the new sequence is compatible with both compilers.
  29.  
  30. ; publics are defined two ways for compiler compatibility.  Each is
  31. ; defined as _LABEL (Microsoft) and LABEL_ (DeSmet).
  32.  
  33. ; Effort required to reconvert to DeSmet is minor
  34.  
  35. ;                                            2-18-87 G. Osborn
  36.  
  37.  
  38.  
  39. _TEXT SEGMENT  BYTE PUBLIC 'CODE'
  40. ; instructions
  41. _TEXT ENDS
  42.  
  43. CONST SEGMENT  WORD PUBLIC 'CONST'
  44. ; read only constants.  not constant strings.
  45. CONST ENDS
  46.  
  47. _BSS SEGMENT  WORD PUBLIC 'BSS'
  48. ; uninitialized static data
  49. _BSS ENDS
  50.  
  51. _DATA SEGMENT  WORD PUBLIC 'DATA'
  52. ; initialized global and static data
  53. _DATA ENDS
  54.  
  55. DGROUP GROUP CONST, _BSS, _DATA
  56.    ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  57.  
  58.  
  59.  
  60. ;------------------------------------------------------------------
  61. ; pcio.a  --  Screen and keyboard interface routines for the PC
  62. ;             Specific to DeSmet C
  63. ;
  64. ; last modified - 08/06/86
  65. ;
  66. ;
  67. ;                        !!! PLEASE NOTE !!!
  68. ;     This is not quite the same as pcio.a from DeSmet -
  69. ;     I've made some changes here and there for use with ged.
  70. ;     Am slowly changing all Desmet functions that use x,y co-ords
  71. ;     to work as col,row - but have not finished
  72. ;                                                    Mel Tearle
  73. ;------------------------------------------------------------------
  74.  
  75. ;------------------------------------------------------------------
  76. ;                         data starts here
  77. ;------------------------------------------------------------------
  78.  
  79. _DATA SEGMENT
  80.  
  81. ; In this implementation, all special and function keys are translated
  82. ; to the following values.
  83.  
  84. ; control key translations.  would be better done in C, because the
  85. ; convesion time is not critical.
  86.  
  87. up_char         equ   5    ;equ 196   mapped into cursor-pad
  88. down_char       equ  24    ;equ 197
  89. left_char       equ  19    ;equ 198
  90. right_char      equ   4    ;equ 199
  91. bol_char        equ  15    ;equ 200
  92. eol_char        equ  16    ;equ 201
  93. pageup_char     equ  18    ;equ 202
  94. pagedown_char   equ   3    ;equ 203
  95. Del_char        equ   7    ;equ 207
  96. Ins_char        equ  16h
  97.  
  98. ;  bof_char     equ 204      not used
  99. ;  eof_char     equ 205      not used
  100. ;  NextWord_char   equ 208   not used
  101. ;  PrevWord_char   equ 209   not used
  102.  
  103. M1      equ 210
  104. M2      equ 211
  105. M3      equ 212
  106. M4      equ 213
  107. M5      equ 214
  108. M6      equ 215
  109. M7      equ 216
  110. M8      equ 217
  111. M9      equ 218
  112. M10     equ 219
  113. M11     equ 220
  114. M12     equ 221
  115.  
  116. ; the table that is used to make the translation
  117. ; note - not all used
  118.  
  119. convert db  72, up_char
  120.         db  80, down_char
  121.         db  75, left_char
  122.         db  77, right_char
  123.         db  71, 220      ; <home> becomes beginning of file
  124.         db  79, 221      ; <end> becomes end of file
  125.         db  73, pageup_char
  126.         db  81, pagedown_char
  127.         db  113, 222    ; ^<up arrow> .. cursor to top of window
  128.         db  118, 223    ; cursor to bottom of window
  129.         db  82, Ins_char ; <ins> becomes ^V
  130.         db  83, Del_char
  131.         db  115, 15h      ; ^<left arrow> becomes ^U = cursor full left
  132.         db  116, 1Dh      ; ^<right arrow> becomes ^] = cursor full right
  133.         db  59, M1
  134.         db  60, M2
  135.         db  61, M3
  136.         db  62, M4
  137.         db  63, M5
  138.         db  64, M6
  139.         db  65, M7
  140.         db  66, M8
  141.         db  67, M9
  142.         db  68, M10
  143.         db  69, M11
  144.         db  70, M12
  145.         db   0, 255 ; illegal character
  146.  
  147.  
  148. ; equates for bios interface.
  149. ; the interrupt and codes for the screen interface interrupt.
  150.  
  151. video       equ 10h     ;interrupt for dealing with screen
  152.  
  153. mode        equ 0       ;code for setting new screen mode
  154. curtype     equ 1       ;code for setting new cursor type
  155. setcur      equ 2       ;code for addressing cursor
  156. readcur     equ 3       ;code for reading cursor location
  157. readlp      equ 4       ;code for reading light pen position
  158. setpage     equ 5       ;code to select active page
  159. scrollup    equ 6       ;code to scroll screen up
  160. scrolldn    equ 7       ;code to scroll screen nown
  161. readch      equ 8       ;code to read a character from screen
  162. writeach    equ 9       ;code to write char and attributes
  163. writech     equ 10      ;code to write character only
  164. setpal      equ 11      ;code to set new setpal or border
  165. wdot        equ 12      ;code to write a dot
  166. rdot        equ 13      ;code to read a dot
  167. wtty        equ 14      ;code to write as if teletype
  168. state       equ 15      ;code to find current screen status
  169.  
  170. ; int 10 (video) changes all registers except cs,ss,ds,es,bx,cx,dx
  171.  
  172. ; used in set_video
  173.  
  174. mono_adr     equ  0b000h   ;mono adapter
  175. graph_adr    equ  0b800h   ;graphics adapter*
  176.  
  177. vadrs        dw  0
  178.  
  179.  
  180. ; the interrupt and codes for the keyboard interface.
  181.  
  182. keyboard     equ 16h     ;interrupt 16 to deal with keyboard
  183.  
  184. cicode       equ 0       ;code for reading a character
  185. cstscode     equ 1       ;code for keyboard status
  186.  
  187.  
  188. ; caution: must change column number if 40 column mode
  189.  
  190. crt_cols    equ 80
  191.  
  192. ; variables available to a C88 program
  193.  
  194.         public  scr_cols_, scr_rows_, scr_scrollup_, scr_scrolldown_
  195.         public  scr_mode_, scr_page_, scr_attr_, scr_window_top_
  196.  
  197.         public  _scr_cols, _scr_rows, _scr_scrollup, _scr_scrolldown
  198.         public  _scr_mode, _scr_page, _scr_attr, _scr_window_top
  199.  
  200.  
  201. _scr_cols  label byte
  202. scr_cols_ db  crt_cols    ;current number of columns
  203.  
  204.  
  205. ; note- make 25 for ms-dos and 24 for cp/m as cp/m steals the bottom
  206. ; line.
  207.  
  208. scr_rows    equ  25
  209. _scr_rows   label byte
  210. scr_rows_   db  scr_rows     ;current number of rows, for ged, was 25
  211.  
  212. _scr_mode   label byte
  213. scr_mode_   db  0       ;current screen mode
  214.  
  215. _scr_page   label byte
  216. scr_page_   db  0       ;current page
  217.  
  218. _scr_attr   label byte
  219. scr_attr_   db  7       ;current attributes for screen
  220.                         ;7 is white letters on black
  221.  
  222. _scr_window_top label byte
  223. scr_window_top_ db  1   ;first line to scroll, was 0
  224.  
  225. ; variables needed by SEE. Not used here.
  226.  
  227. _scr_scrollup   label byte
  228. scr_scrollup_   db  0       ;zero if scrollup leaves top line alone
  229.  
  230. _scr_scrolldown label byte
  231. scr_scrolldown_ db  0       ;zero if scroll down supported
  232.  
  233. _DATA      ENDS
  234.  
  235. ;------------------------------------------------------------------
  236. ;                          code starts here
  237. ;------------------------------------------------------------------
  238.  
  239. _TEXT       SEGMENT
  240.             PUBLIC    _scr_setup
  241.  
  242. ;-------------------------------------------------------------------------
  243. ; SCR_SETUP_  scr_setup must be called before any use of any
  244. ;             other routine unless the starting mode is 80X25
  245. ;             character mode (3,4 or 7). Must be called for monochrome
  246. ;             (mode 7) for scr_curson to set a proper cursor.
  247. ;
  248. ; Usage:      mode = scr_setup();
  249. ;-------------------------------------------------------------------------
  250. scr_setup_:
  251. _scr_setup:
  252. scrsetup:
  253.         push  bp
  254.         mov   bp,sp
  255.         push  di
  256.         push  si
  257.         mov   ah,state        ;get current state
  258.         int   video
  259.         mov   scr_mode_,al    ;current mode
  260.         mov   cl,ah           ;make cols a word
  261.         mov   ch,0
  262.         mov   scr_cols_,cl    ;40 or 80 columns
  263.         mov   scr_page_,bh
  264.         mov   scr_attr_,7     ;set to white chars on black
  265.         cmp   al,4            ;see if a character mode
  266.         jc    got_attr
  267.         cmp   al,7            ;7 is for graphics mode
  268.         jz    got_attr
  269.         mov   scr_attr_,0     ;attribute is zero in graphics
  270. got_attr:
  271.         mov   ah,0            ;return int containing mode
  272.         push  ax              ;slight detour
  273.         call  set_video_      ;get display address
  274.  
  275.         pop   ax
  276.         pop   si
  277.         pop   di
  278.         pop   bp
  279.         ret
  280.  
  281.  
  282.  
  283. ;-------------------------------------------------------
  284. ; SCR_TERM_     do any required termination.
  285. ;
  286. ; Usage:        scr_term();
  287. ;-------------------------------------------------------
  288.  
  289. public  scr_term_
  290. public  _scr_term
  291. _scr_term:
  292. scr_term_:
  293.        ret
  294.  
  295.  
  296.  
  297. ;-------------------------------------------------------
  298. ; SCR_SETMODE_    set a new screen mode
  299. ;
  300. ; Usage:          scr_setmode(new mode);
  301. ;-------------------------------------------------------
  302.  
  303. public  scr_setmode_
  304. public  _scr_setmode
  305. _scr_setmode:
  306. scr_setmode_:
  307.         push  bp
  308.         mov   bp,sp
  309.         push  di
  310.         push  si
  311.         mov   al,[bp+4]    ;new mode value
  312.         mov   ah,mode
  313.         int   video        ;set new mode
  314.         call  scrsetup     ;remember new values
  315.         pop   si
  316.         pop   di
  317.         pop   bp
  318.         ret
  319.  
  320.  
  321.  
  322. ;-------------------------------------------------------
  323. ; SCR_ROWCOL_    sets cursor at any location.
  324. ;
  325. ; Usage:         scr_rowcol(new row, new column);
  326. ; Note!:         wil be changed to col,row
  327. ;-------------------------------------------------------
  328.  
  329. public  scr_rowcol_
  330. public  _scr_rowcol
  331. _scr_rowcol:
  332. scr_rowcol_:
  333.         push  bp           ;save from bios
  334.         mov   bp,sp
  335.         push  di
  336.         push  si
  337.         mov   dx,[bp+6]    ;column
  338.         mov   ax,[bp+4]    ;row
  339.         mov   dh,al
  340.         mov   bh,scr_page_ ;force page zero
  341.         mov   ah,setcur    ;set cursor location
  342.         int   video        ;call bios
  343.         pop   si
  344.         pop   di
  345.         pop   bp
  346.         ret
  347.  
  348.  
  349.  
  350. ;-------------------------------------------------------
  351. ; SCR_CLR_      clear entire screen
  352. ;
  353. ; Usage:       scr_clr();
  354. ;-------------------------------------------------------
  355.  
  356. public  scr_clr_
  357. public  _scr_clr
  358. _scr_clr:
  359. scr_clr_:
  360.         push  bp                 ;save from video call
  361.         mov   bp,sp
  362.         push  di
  363.         push  si
  364.         mov   al,0               ;ask for a clear window
  365.         xor   cx,cx              ;start at 0,0
  366.         mov   dl,scr_cols_       ;clear entire width
  367.         dec   dl                 ;last column is width-1
  368.         mov   dh,scr_rows_       ;last line
  369.         dec   dh
  370.         mov   bh,scr_attr_       ;attributes for new blanks
  371.         mov   ah,scrollup        ;ask for a scrollup to clear
  372.         int   video              ;do the clear
  373.         pop   si
  374.         pop   di
  375.         pop   bp
  376.         ret
  377.  
  378.  
  379.  
  380. ;-------------------------------------------------------
  381. ; SCR_CLRL_     clear rest of line.
  382. ;
  383. ; Usage:        scr_clrl();
  384. ;-------------------------------------------------------
  385.  
  386. public  scr_clrl_
  387. public  _scr_clrl
  388. _scr_clrl:
  389. scr_clrl_:
  390.         push  bp
  391.         mov   bp,sp
  392.         push  di
  393.         push  si
  394.         mov   bh,scr_page_
  395.         mov   ah,readcur          ;see where we are
  396.         int   video
  397.  
  398.         mov   cl,scr_cols_   ;calc how many chars left in line
  399.         sub   cl,dl               ;number left
  400.         mov   ch,0                ;number of blanks needed
  401.         mov   al,' '              ;write blanks
  402.         mov   bl,scr_attr_        ;normal attributes
  403.         mov   bh,scr_page_        ;page number
  404.         mov   ah,writeach         ;write the blanks
  405.         int   video
  406.         pop   si
  407.         pop   di
  408.         pop   bp
  409.         ret
  410.  
  411.  
  412.  
  413. ;-------------------------------------------------------
  414. ; SCR_CLS_     clear rest of screen.
  415. ;
  416. ; Usage:       scr_cls();
  417. ;-------------------------------------------------------
  418.  
  419. public  scr_cls_
  420. public  _scr_cls
  421. _scr_cls:
  422. scr_cls_:
  423.         push  bp
  424.         mov   bp,sp
  425.         push  di
  426.         push  si
  427.         call  scr_clrl_          ;clear rest of line
  428.         mov   ah,readcur         ;see where we are
  429.         mov   bh,scr_page_
  430.         int   video
  431.  
  432.         mov   al,0               ;ask for a clear window
  433.         mov   ch,dh              ;current row
  434.         inc   ch                 ;+1
  435.         cmp   ch,scr_rows_  ;see if in last line
  436.         jz    cleared            ;all done
  437.         mov   cl,0               ;first column
  438.         mov   dh,scr_rows_  ;24 is the last line
  439.         dec   dh
  440.         mov   dl,scr_cols_  ;clear entire width
  441.         dec   dl                 ;last column is width-1
  442.         mov   bh,scr_attr_       ;attributes for new blanks
  443.         mov   ah,scrollup        ;ask for a scrollup to clear
  444.         int   video              ;do the clear
  445. cleared:
  446.         pop   si
  447.         pop   di
  448.         pop   bp
  449.         ret
  450.  
  451.  
  452.  
  453. ;--------------------------------------------------------
  454. ; SCR_SCUP_     scroll text up leaving top lines alone.
  455. ;
  456. ; Usage:        scr_scup();
  457. ;--------------------------------------------------------
  458.  
  459. public  scr_scup_
  460. public  _scr_scup
  461. _scr_scup:
  462. scr_scup_:
  463.                               ;scroll last line, screen from line
  464.                               ;scr_windor_top to end
  465.         push  bp
  466.         mov   bp,sp
  467.         push  di
  468.         push  si
  469.  
  470.         mov   al,scr_cols_    ;need last column of screen
  471.         dec   al
  472.         xor   ah,ah
  473.         push  ax
  474.         mov   al,scr_rows_    ;scroll through last line
  475.         dec   al
  476.         xor   ah,ah
  477.         push  ax
  478.         xor   ax,ax           ;from column 0
  479.         push  ax
  480.         mov   al,scr_window_top_  ;leave top line alone
  481.         push  ax
  482.         mov   al,1
  483.         push  ax              ;scroll by 1
  484.         call  scr_scrup_      ;do the scroll
  485.         add   sp,10           ;clear arge
  486.         pop   si
  487.         pop   di
  488.         pop   bp
  489.         ret
  490.  
  491.  
  492.  
  493. ;---------------------------------------------------------------
  494. ; SCR_SCRUP_     Scroll the screen up. The window is scrolled
  495. ;                up nline lines. A zero nline will clear the
  496. ;                window. Top left of the screen in 0,0.
  497. ;
  498. ; Usage:         scr_scrup(nline,fromrow,fromcol,torow,tocol);
  499. ;---------------------------------------------------------------
  500.  
  501. public  scr_scrup_
  502. public  _scr_scrup
  503. _scr_scrup:
  504. scr_scrup_:
  505.         push  bp
  506.         mov   bp,sp
  507.         push  di
  508.         push  si
  509.  
  510.         mov   al,[bp+4]   ;number of lines
  511.         mov   ch,[bp+6]   ;starting row
  512.         mov   cl,[bp+8]   ;starting column
  513.         mov   dh,[bp+10]  ;ending row
  514.         mov   dl,[bp+12]  ;ending column
  515.         mov   bh,scr_attr_   ;current attribute
  516.         mov   ah,scrollup
  517.         int   video          ;do the scroll
  518.         pop   si
  519.         pop   di
  520.         pop   bp
  521.         ret
  522.  
  523.  
  524.  
  525. ;-------------------------------------------------------------
  526. ; SCR_SCDN_     scroll all but the top lines down one.
  527. ;
  528. ; Usage:        scr_scdn();
  529. ;-------------------------------------------------------------
  530.  
  531. public  scr_scdn_
  532. public  _scr_scdn
  533. _scr_scdn:
  534. scr_scdn_:
  535.         push  bp
  536.         mov   bp,sp
  537.         push  di
  538.         push  si
  539.  
  540.         mov   al,scr_cols_  ;need last column of screen
  541.         dec   al
  542.         xor   ah,ah
  543.         push  ax
  544.         mov   al,scr_rows_  ;scroll through last line
  545.         dec   al
  546.         xor   ah,ah
  547.         push  ax
  548.         xor   ax,ax         ;from column 0
  549.         push  ax
  550.         mov   al,scr_window_top_  ;leave top lines alone
  551.         push  ax
  552.         mov   al,1
  553.         push  ax            ;scroll by 1
  554.         call  scr_scrdn_    ;do the scroll
  555.         add   sp,10         ;clear arge
  556.         pop   si
  557.         pop   di
  558.         pop   bp
  559.         ret
  560.  
  561.  
  562.  
  563. ;---------------------------------------------------------------
  564. ; SCR_SCRDN_    scroll the screen down. the window is scrolled
  565. ;               down nline lines. A zero nline will clear the
  566. ;               window. Top left of the screen in 0,0.
  567. ;
  568. ; Usage:        scr_scrdn(nline,fromrow,fromcol,torow,tocol);
  569. ;---------------------------------------------------------------
  570.  
  571. public  scr_scrdn_
  572. public  _scr_scrdn
  573. _scr_scrdn:
  574. scr_scrdn_:
  575.         push  bp
  576.         mov   bp,sp
  577.         push  di
  578.         push  si
  579.  
  580.         mov   al,[bp+4]   ;number of lines
  581.         mov   ch,[bp+6]   ;starting row
  582.         mov   cl,[bp+8]   ;starting column
  583.         mov   dh,[bp+10]  ;ending row
  584.         mov   dl,[bp+12]  ;ending column
  585.         mov   bh,scr_attr_    ;current attribute
  586.         mov   ah,scrolldn
  587.         int   video       ;do the scroll
  588.         pop   si
  589.         pop   di
  590.         pop   bp
  591.         ret
  592.  
  593.  
  594.  
  595. ;---------------------------------------------------------------
  596. ; SCR_CO_     write a character to the screen. this
  597. ;             routine increments the cursor position
  598. ;             after writing. normal C88 puts and printf
  599. ;             statements can also be used to write to the
  600. ;             screen.
  601. ;
  602. ; Usage:      scr_co(character);
  603. ;---------------------------------------------------------------
  604.  
  605. public  scr_co_
  606. public  _scr_co
  607. _scr_co:
  608. scr_co_:
  609.         push  bp
  610.         mov   bp,sp
  611.         push  di
  612.         push  si
  613.  
  614.         mov   al,[bp+4]    ;character to write
  615.         mov   bh,scr_page_
  616.         mov   ah,wtty      ;use tty write routine
  617.         int   video
  618.  
  619.         pop   si
  620.         pop   di
  621.         pop   bp
  622.         ret
  623.  
  624.  
  625.  
  626. ;---------------------------------------------------------------
  627. ; SCR_CI_     keyboard input. function and soft keys are
  628. ;             translated. see equates for values.
  629. ;
  630. ; Usage:      character = scr_ci();
  631. ;---------------------------------------------------------------
  632.  
  633. public  scr_ci_
  634. public  _scr_ci
  635. _scr_ci:
  636. scr_ci_:
  637.         push  bp
  638.         mov   bp,sp
  639.         push  di
  640.         push  si
  641.  
  642.         mov   ah,cicode           ;ask for a keyboard character
  643.         int   keyboard
  644.         cmp   al,0
  645.         jne   not_special
  646.         mov   bx, offset dgroup:convert  ;convert special key
  647. ci_loop:
  648.         cmp   byte ptr[bx],0
  649.         jne    ci1   ; not end of list
  650.  
  651.         and   ah,ah
  652.         js    ci2    ; pass codes 80h - ffh through (eg. alt-160)
  653.         xor   ah,ah
  654. ci2:
  655.         mov al,ah
  656.         jmp   not_special
  657. ci1:
  658.         cmp   ah,[bx]
  659.         je    got_it    ; char matches table
  660.         add   bx,2
  661.         jmp   ci_loop
  662. got_it:
  663.         inc   bx
  664.         mov   al,[bx]
  665. not_special:
  666.         mov   ah,0
  667. cix:    pop   si
  668.         pop   di
  669.         pop   bp
  670.         ret
  671.  
  672.  
  673.  
  674. ;---------------------------------------------------------------
  675. ; SCR_CSTS_   return character if any available. otherwise
  676. ;             return zero.
  677. ;
  678. ; Usage:      character = scr_csts();
  679. ;---------------------------------------------------------------
  680.  
  681. public  scr_csts_
  682. public  _scr_csts
  683. _scr_csts:
  684. scr_csts_:
  685.         push  bp
  686.         mov   bp,sp
  687.         push  di
  688.         push  si
  689.  
  690.         mov   ah,cstscode
  691.         int   keyboard
  692.         mov   ax,0
  693.         jz    csts_over
  694.         call  scr_ci_     ;get the coded character
  695. csts_over:
  696.         pop   si
  697.         pop   di
  698.         pop   bp
  699.         ret
  700.  
  701.  
  702.  
  703. ;---------------------------------------------------------------
  704. ; SCR_SET_CURSOR_     does nothing. needed by SEE.
  705. ;
  706. ;---------------------------------------------------------------
  707.  
  708. public  scr_set_cursor_
  709. public  _scr_set_cursor
  710. _scr_set_cursor:
  711. scr_set_cursor_:        ;set the visible cursor to the
  712.                         ;current position
  713.         ret
  714.  
  715.  
  716.  
  717. ;---------------------------------------------------------------
  718. ; SCR_SINP_   screen input (read character from the screen).
  719. ;
  720. ; Usage:      character = scr_sinp();
  721. ;---------------------------------------------------------------
  722.  
  723. public  scr_sinp_
  724. public  _scr_sinp
  725. _scr_sinp:
  726. scr_sinp_:
  727.         push  bp          ;save the registers
  728.         mov   bp,sp
  729.         push  di
  730.         push  si
  731.  
  732.         mov   bh,scr_page_
  733.         mov   ah,readch   ;code to read a character
  734.         int   video       ;al is letter, ah=attributes
  735.         or    al,al       ;zero returned instead of blank in
  736.                           ;graphics mode
  737.         jnz   ret_ch
  738.         mov   al,' '
  739. ret_ch:
  740.         mov ah,0          ;kill the attributes
  741.         pop  si
  742.         pop  di
  743.         pop  bp
  744.         ret
  745.  
  746.  
  747.  
  748. ;---------------------------------------------------------------
  749. ; SCR_CURSOFF_    turn cursor off.
  750. ;
  751. ; Usage:          scr_cursoff();
  752. ;
  753. ; This routing must not be called directly.  See curson() in term.c.
  754. ;---------------------------------------------------------------
  755.  
  756. public  scr_cursoff_
  757. public  _scr_cursoff
  758. _scr_cursoff:
  759. scr_cursoff_:
  760.         push  bp            ;save registers
  761.         mov   bp,sp
  762.         push  di
  763.         push  si
  764.  
  765.         cmp   scr_mode_,4   ;see if graphics
  766.         jc    text_coff
  767.         cmp   scr_mode_,7
  768.         jnz   no_cur
  769. text_coff:
  770.         mov   cx,0f00h      ;should turn cursor off
  771. new_cur:
  772.         mov   ah,curtype    ;set a new cursor type
  773.         int   video
  774. no_cur:
  775.         pop  si
  776.         pop  di
  777.         pop  bp
  778.         ret
  779.  
  780.  
  781.  
  782. ;---------------------------------------------------------------
  783. ; SCR_CURSON_     turn cursor back on.
  784. ;
  785. ; Usage:          scr_curson();
  786. ;
  787. ; This routine must not be called directly.  See curson() in term.c
  788. ;---------------------------------------------------------------
  789.  
  790. public  scr_curson_
  791. public  _scr_curson
  792. _scr_curson:
  793. scr_curson_:
  794.         push  bp
  795.         mov   bp,sp
  796.         push  di
  797.         push  si
  798.  
  799.         mov   cx,0c0dh    ;assume monocrome
  800.         cmp   scr_mode_,7 ;true is mono
  801.         jz    new_cur     ;set it
  802.         mov   cx,0607h    ;assume color card in text mode
  803.         cmp   scr_mode_,4 ;color text is 0 to 3
  804.         jc    new_cur
  805.         pop   si
  806.         pop   di
  807.         pop   bp          ;do nothing if in graphics mode
  808.         ret
  809.  
  810.  
  811.  
  812. ;---------------------------------------------------------------
  813. ; SCR_MARK   mark the current character on the screen.
  814. ;            Used to delimit block areas in SEE. Just write
  815. ;            an X or something if reverse video is not available.
  816. ;
  817. ; Usage:     scr_mark(current character);
  818. ;---------------------------------------------------------------
  819.  
  820. public  scr_mark_
  821. public  _scr_mark
  822. _scr_mark:
  823. scr_mark_:               ;mark the passed char, cursor does not advance
  824.         push  bp
  825.         mov   bp,sp
  826.         push  di
  827.         push  si
  828.  
  829.         mov   al,219          ;just write a block character
  830.         mov   bl,scr_attr_    ;normal attributes
  831.         mov   cx,1            ;one character
  832.         mov   bh,scr_page_    ;page number
  833.         mov   ah,writeach     ;write char and attr
  834.         int   video           ;write character and attributes
  835.  
  836.         pop   si
  837.         pop   di
  838.         pop   bp
  839.         ret
  840.  
  841.  
  842.  
  843. ;---------------------------------------------------------------
  844. ; SCR_APUTS_  write a string and attributes to the screen.
  845. ;             goto col, row first. the cursor is moved normally
  846. ;
  847. ; Usage:      scr_aputs(x,y,"Print This",attribute);
  848. ;---------------------------------------------------------------
  849.  
  850. ; the following routine is not used by either SEE or D88.
  851.  
  852. public scr_aputs_
  853. public _scr_aputs
  854. _scr_aputs:
  855. scr_aputs_:
  856.         push  bp
  857.         mov   bp,sp
  858.         push  di
  859.         push  si
  860.         mov   di,sp
  861.  
  862.         mov   dx,[bp+4]    ;col
  863.         mov   ax,[bp+6]    ;row
  864.         mov   dh,al
  865.  
  866.         mov   bh,scr_page_ ;force page
  867.         mov   ah,setcur    ;set cursor location
  868.         push  bp
  869.         int   video        ;dx is cursor location, bh is page
  870.         pop   bp
  871.         mov   si,[bp+8]    ;string pointer
  872.         mov   cx,1         ;number of characters to write
  873.         mov   bl,[bp+10]   ;attribute
  874. naputs:
  875.         cld
  876.         lodsb             ;next character to write
  877.         or    al,al       ;zero at end
  878.         jz    eaputs
  879.         cmp   al,10       ;look for LF
  880.         jnz   normal_ap
  881. ap_scroll:
  882.         mov   bp,sp       ;reset pointer to next char
  883.         mov   [bp+4],si
  884.         mov   al,13       ;use tty output to scroll screen
  885.         mov   ah,wtty
  886.         int   video       ;write cr,lf
  887.         mov   ah,wtty
  888.         mov   al,10
  889.         int   video
  890.         pop   bp
  891.         jmp   scr_aputs_      ;start over
  892. normal_ap:
  893.         mov   bh,scr_page_    ;page number
  894.         mov   ah,writeach     ;write char and attr
  895.         int   video           ;write character and attributes
  896.         inc   dl              ;next column
  897.         cmp   dl,crt_cols     ;see if wrapping around
  898.         jc    set_loc
  899.         mov   dl,0            ;at start of column
  900.         inc   dh              ;at next row
  901.         cmp   dh,scr_rows_  ;see if need a scroll
  902.         jc    set_loc
  903.         jmp   ap_scroll       ;do a scroll up
  904. set_loc:
  905.         mov   ah,setcur       ;move the cursor
  906.         int   video
  907.         jmp   naputs
  908. eaputs:
  909.         mov   sp,di
  910.         pop   si
  911.         pop   di
  912.         pop   bp
  913.         ret
  914.  
  915.  
  916.  
  917.  
  918. ;-------------------------------------------------------------------
  919. ; SCR_PUTCH_  write a character to the screen with attribute set.
  920. ;             see scr_aputs and scr_co
  921. ;
  922. ; Usage:      scr_putch( character, attribute );
  923. ;-------------------------------------------------------------------
  924.  
  925. public  scr_putch_
  926. public  _scr_putch
  927. _scr_putch:
  928. scr_putch_:
  929.         push  bp
  930.         mov   bp,sp
  931.         push  di
  932.         push  si
  933.  
  934.         push  bp
  935.         mov   ah,readcur      ;see where we are
  936.         mov   bh,scr_page_
  937.         int   video           ;dx is cursor location, bh is page
  938.         pop   bp
  939.         mov   al,[bp+4]       ;character to write
  940.         mov   bl,[bp+6]       ;attribute of char
  941.         mov   bh,scr_page_    ;set page number
  942.         mov   cx,1            ;write just one char
  943.         mov   ah,writeach     ;write char and attr
  944.         int   video
  945.  
  946.         inc   dl              ;move to next column
  947.         mov   ah,setcur       ;move the cursor
  948.         int   video
  949.         pop   si
  950.         pop   di
  951.         pop   bp
  952.         ret
  953.  
  954.  
  955.  
  956. ;--------------------------------------------------------
  957. ; SCR_DELETE_   clear rest of line starting at column, row.
  958. ;
  959. ; Usage:        scr_delete(x,y);
  960. ;--------------------------------------------------------
  961.  
  962. public  scr_delete_
  963. public  _scr_delete
  964. _scr_delete:
  965. scr_delete_:
  966.         push  bp
  967.         mov   bp,sp
  968.         push  di
  969.         push  si
  970.  
  971.         mov   dx,[bp+4]       ;col
  972.         mov   ax,[bp+6]       ;row
  973.         mov   dh,al
  974.         mov   bh,scr_page_    ;force page zero
  975.         mov   ah,setcur       ;set cursor location
  976.         int   video           ;call bios
  977.  
  978.         mov   cl,scr_cols_   ;calc how many chars left in line
  979.         sub   cl,dl           ;number left
  980.         mov   ch,0            ;number of blanks needed
  981.         mov   al,' '          ;write blanks
  982.         mov   bl,scr_attr_    ;normal attributes
  983.         mov   bh,scr_page_    ;page number
  984.         mov   ah,writeach     ;write the blanks
  985.         int   video
  986.         pop   si
  987.         pop   di
  988.         pop   bp
  989.         ret
  990.  
  991.  
  992.  
  993. ;----------------------------------------------------------
  994. ;  The following routines get_mode_, calc_video_,
  995. ;  set_video_ and scr_putstr were adapted from
  996. ;  Computer Language Magazine - January 1986
  997. ;  "Assembly Video Routines for your P.C.", Thomas Webb
  998. ;----------------------------------------------------------
  999.  
  1000.  
  1001. ;----------------------------------------------------------
  1002. ; GET_MODE_    get video mode
  1003. ;
  1004. ; Usage:       internal subroutine used in scr_putstr
  1005. ;----------------------------------------------------------
  1006.  
  1007. public  get_mode_
  1008. public  _get_mode
  1009. _get_mode:
  1010. get_mode_:
  1011.       push  bp
  1012.       mov   bp,sp
  1013.       push  di
  1014.       push  si
  1015.  
  1016.       mov   ax,0
  1017.       mov   ah,15
  1018.       int   video
  1019.       pop   si
  1020.       pop   di
  1021.       pop   bp
  1022.       ret
  1023.  
  1024.  
  1025.  
  1026. ;----------------------------------------------------------
  1027. ; CALC_VIDEO_   calculate offset into video buffer
  1028. ;               set begining location and attribute
  1029. ;
  1030. ; Usage:        internal subroutine used in scr_putstr
  1031. ;----------------------------------------------------------
  1032.  
  1033. public  calc_video_
  1034. public  _calc_video
  1035. _calc_video:
  1036. calc_video_:
  1037.         mov   ax,crt_cols
  1038.         mul   dx
  1039.         add   ax,cx
  1040.         shl   ax,1
  1041.         ret
  1042.  
  1043.  
  1044.  
  1045. ;-------------------------------------------------------
  1046. ; SET_VIDEO_    set video address
  1047. ;
  1048. ; Usage:        internal subroutine used in scr_setup
  1049. ;-------------------------------------------------------
  1050.  
  1051. public  set_video_
  1052. public  _set_video
  1053. _set_video:
  1054. set_video_:
  1055.         call  get_mode_
  1056.         cmp   al,7h
  1057.         jne   adp_graphics
  1058.         mov   ax,mono_adr
  1059.         jmp   return
  1060. adp_graphics:
  1061.         mov   ax,graph_adr
  1062. return:
  1063.         mov   vadrs,ax
  1064.         ret
  1065.  
  1066.  
  1067.  
  1068. ;----------------------------------------------------------
  1069. ; SCR_PUTSTR_   write a string directly to video buffer
  1070. ;               at col, row location with attribute.
  1071. ;               Doesn't change cursor position.
  1072. ;
  1073. ; Usage:        scr_putstr( x, y, string, attribute );
  1074. ;----------------------------------------------------------
  1075.  
  1076. public  scr_putstr_
  1077. public  _scr_putstr
  1078. _scr_putstr:
  1079. scr_putstr_:
  1080.         push  bp
  1081.         mov   bp,sp
  1082.         push  di
  1083.         push  si
  1084.         push  es
  1085.  
  1086.         mov   dx,[bp+6]     ;get row
  1087.         mov   cx,[bp+4]     ;get col
  1088.         mov   ax,crt_cols   ;calc video routine
  1089.         mul   dx            ;moved here
  1090.         add   ax,cx         ;to save a call
  1091.         shl   ax,1
  1092.         mov   di,ax         ;return position
  1093.  
  1094.         mov   si,[bp+8]    ;get string pointer
  1095.         mov   dh,[bp+10]    ;get attribute
  1096.  
  1097.         mov   ax,vadrs      ;get display address from setup
  1098.         mov   es,ax         ;move absolute display address to es
  1099.         mov   cl,0          ;used to test for end of string
  1100.  
  1101. str_loop:
  1102.         mov   dl,[si]        ;get the next byte from the string
  1103.         cmp   dl,cl          ;if end of string then exit
  1104.         je    str_exit
  1105.         mov   es:[di],dx     ;move a word into screen display
  1106.  
  1107.         add   di,2h          ;bump display index
  1108.         inc   si             ;bump index to string
  1109.         jmp   str_loop
  1110. str_exit:
  1111.         pop   es
  1112.         pop   si
  1113.         pop   di
  1114.         pop   bp
  1115.         ret
  1116.  
  1117.  
  1118.  
  1119. ;---------------------------------------------------------------
  1120. ; SCR_APUTCH_  write a character to the screen with
  1121. ;              attribute set. see scr_aputs and scr_co
  1122. ;
  1123. ; Usage:       scr_aputch(x,y,char,attribute);
  1124. ;
  1125. ;     After getting this to work found that it isn't that fast.
  1126. ;     However, it's a good replacement for gotoxy() scr_putch()
  1127. ;     if you're only writing one char to a specific location.
  1128. ;---------------------------------------------------------------
  1129.  
  1130. public  scr_aputch_
  1131. public  _scr_aputch
  1132. _scr_aputch:
  1133. scr_aputch_:
  1134.         push  bp
  1135.         mov   bp,sp
  1136.         push  di
  1137.         push  si
  1138.         push  es
  1139.  
  1140.         mov   dx,[bp+6]     ;get col
  1141.         mov   cx,[bp+4]     ;get row
  1142.         call  calc_video_   ;locate position in video buffer
  1143.         mov   di,ax         ;return position
  1144.  
  1145.         mov   dl,[bp+8]    ;get char
  1146.         mov   dh,[bp+10]    ;get attribute
  1147.  
  1148.         mov   ax,vadrs      ;get video address
  1149.         mov   es,ax         ;move buffer address to es
  1150.  
  1151.         mov   es:[di],dx
  1152.  
  1153.         pop   es
  1154.         pop   si
  1155.         pop   di
  1156.         pop   bp
  1157.         ret
  1158.  
  1159.  
  1160. ;  write a graphics dot
  1161. ; plot(color,horz,vert)
  1162. ; int color,horz,vert;
  1163.  
  1164. public plot_
  1165. public _plot
  1166. _plot:
  1167. plot_:
  1168.    push  bp
  1169.    mov   bp,sp
  1170.    push  di
  1171.    push  si
  1172.  
  1173.    call  setdot
  1174.    mov   ah,12
  1175.    int   video
  1176.    pop   si
  1177.    pop   di
  1178.    pop   bp
  1179.    ret
  1180.  
  1181. setdot:
  1182.    mov   bp,sp
  1183.    mov   ax,[bp+4]    ;color
  1184.    mov   cx,[bp+6]    ;horiz
  1185.    mov   dx,[bp+8]   ;vert
  1186.    ret
  1187.  
  1188. ; *** *** *** *** *** *** *** *** ***
  1189. ;
  1190. ; Mixed memory model string move.  Programmed in assembly language for
  1191. ; speed.  The string must not cross a 64 k boundary. Equivalent C code:
  1192. ;
  1193. ; movesf(sptr,fptr)
  1194. ; char far *fptr;
  1195. ; char near *sptr;
  1196. ; {
  1197. ;     while (*sptr++ = *fptr++)
  1198. ;         ;
  1199. ;     return;
  1200. ; }
  1201. ;
  1202.  
  1203.         PUBLIC  _movesf
  1204. _movesf  PROC NEAR
  1205.          push  bp
  1206.          mov   bp,sp
  1207.          push  si
  1208.          mov  si,[bp+4]  ;sptr
  1209.          les  bx,[bp+6]  ;fptr
  1210.  
  1211. msp1:    mov  al,es:[bx]
  1212.          mov  [si],al
  1213.          inc  si
  1214.          inc  bx
  1215.          or  al,al
  1216.          jne  msp1
  1217.  
  1218.          pop  si
  1219.          mov  sp,bp
  1220.          pop  bp
  1221.          ret
  1222.  
  1223. _movesf  ENDP
  1224.  
  1225. ; that's all
  1226.  
  1227. _TEXT ENDS
  1228. END
  1229.