home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / DIR / TDIR92.ZIP / CONIO.ASM next >
Encoding:
Assembly Source File  |  1992-03-05  |  12.8 KB  |  247 lines

  1. ;
  2. ;  Name:             CONIO.ASM
  3. ;  Purpose:          keyboard & text video functions
  4. ;  Calling Language: Borland Turbo Pascal 5.50
  5. ;  Date:             December 8, 1989
  6. ;  Assembler:        Borland Turbo Assembler 1.00
  7. ;  Author:           J. Rockford Cogar
  8. ;  Company:          Nucleus Inc. 761 Emory Valley Road, Oak Ridge TN 37830
  9. ;  Rights:           You MAY use this code for ANY purpose private or commercial
  10. ;
  11.         .MODEL  TPASCAL
  12.         .CODE
  13. ; prototype: void near cursorxy(byte col, byte row);
  14.         PUBLIC cursorxy
  15. ;***********************************************************************
  16. cursorxy proc   near col: BYTE, row: BYTE
  17.          mov    ah,02                           ; set cursor position function
  18.          mov    bh,0                            ; page zero
  19.          mov    dh,row                          ; set glyph row number
  20.          mov    dl,col                          ; set glyph column number
  21.          int    010h                            ; do BIOS video interrupt call
  22.          ret
  23. cursorxy        ENDP
  24. ;***********************************************************************
  25.  
  26. ; prototype: int near cgets(char *strg);
  27. ; purpose:   emulate the Turbo C cgets() function
  28. ;            *strg is the string to input into
  29. ;
  30.         PUBLIC cgets
  31. ;***********************************************************************
  32. cgets    proc   near strg: DWORD
  33.          push   ds
  34.          lds    si,dword ptr strg;      ; load the pointer
  35.          mov    dx,si                   ; PASS ptr in DS:DX
  36.          mov    ah,10;                  ; DOS bufferd KBD input function
  37.          int    21h                     ; call DOS
  38.          mov    si,dx
  39.          inc    si                      ; point to the next (strg[1]) byte
  40.          cld
  41.          lodsb                          ; fetch strg[1]
  42.          mov    ah,0                    ; zero the hi byte
  43.          pop    ds
  44.          ret
  45. cgets    ENDP
  46. ;***********************************************************************
  47.  
  48. ;       Function Name:        getscode
  49. ;       Function Prototype:   integer getscode(void);
  50. ;       Calling Language:     Turbo Pascal 5.50
  51. ;       Purpose:              Read the current scan code
  52. ;       External Code:        None
  53. ;       Returns:              scan code in 'AH'. Ascii Code in 'AL', zero if no key was ready
  54. ;
  55.         PUBLIC getscode
  56. ;***********************************************************************
  57. getscode proc near
  58.         mov     ah,1
  59.         int     016h                    ; bios kbd int service
  60.         jnz     kready                  ; jmp to get the key that is ready
  61.                                         ; top of key not ready block
  62.         xor     ax,ax                   ; set AX to say no key was ready
  63.         jmp     retgsc                  ; return to calling function
  64. kready:
  65.         mov     ah,0
  66.         int     016h                    ; bios kbd int service
  67. retgsc:
  68.         ret
  69. getscode endp
  70. ;***********************************************************************
  71.  
  72. ;       Function Name:        readkbd
  73. ;       Function Prototype:   integer readkbd(void);
  74. ;       Calling Language:     Turbo Pascal 5.50
  75. ;       Purpose:              Pause and Read the current scan code
  76. ;       External Code:        None
  77. ;       Returns:              scan code in AX register
  78. ;
  79.         PUBLIC readkbd
  80. ;***********************************************************************
  81. readkbd proc near
  82.         mov     ah,0
  83.         int     016h                    ; bios kbd int service
  84.         int     016h                    ; bios kbd int service
  85.         xchg    al,ah                   ; puts scan code in AL
  86.         mov     ah,0                    ; zero out the ascii code
  87.         ret
  88. readkbd endp
  89. ;***********************************************************************
  90.  
  91. ; integer near getvmode(void)
  92. ;  used to get the current BIOS video mode
  93. ;
  94.        PUBLIC getvmode
  95. ;***********************************************************************
  96. getvmode proc near
  97.          mov    ah,0fh                          ; BIOS service to get the current video mode
  98.          int    010h                            ; call BIOS
  99.          mov    ah,0                            ; zero out width of text mode screen
  100.          ret
  101. getvmode endp
  102. ;***********************************************************************
  103. ;
  104. ;   void near snowwrite(int col, int row, char color, char *strg, int soff, int maxchars, int clrchar);
  105. ;   col      : int      ;  CRT column
  106. ;   row      : int      ;  CRT row
  107. ;   color    : byte     ;  color to write the string in
  108. ;   strg     : *char    ;  string to write
  109. ;   soff     : int      ;  position of (array index) of first char to write
  110. ;   maxchars : int      ;  maximum number of chars to write
  111. ;   clrchar  : int      ;  number of chars to clear (field width)
  112. ; Write a string to the CRT and clear the specified nunber of spaces
  113. ; providing the string does not fill the entire field
  114. ; also start the write from sourceof and only write maxchars
  115. ; * for text modes only!
  116. ;
  117.            PUBLIC snowwrite
  118. ;***********************************************************************
  119. snowwrite   proc near col:WORD, row:WORD, color:BYTE, strg:DWORD, soff:WORD, maxchars:WORD, clrchar:WORD
  120.             LOCAL strlen:WORD, toclear:WORD=AUTO_SIZE
  121.             push    ds
  122.             cld                         ; clear direction flag
  123.             les     di,strg             ; load seg & off dor large data models
  124.             mov     al,byte ptr es:[di] ; fetch length byte
  125.             mov     ah,0                ; limit length to 255 bytes
  126.             mov     bx,word ptr soff    ; sourceof.  get the string source offset
  127.             cmp     ax,bx               ; compare str length (AX) with str offset (BX)
  128.             jg      itsok               ; jump to assignment if string offset < string length
  129.             jmp     SHORT notok         ; if string offset > string length goto notok:
  130. itsok:      sub     ax,bx               ; adjust the string length for the new offset
  131.             jmp     SHORT assgn         ; jump dowm to assgn
  132. notok:      mov     ax,0000H            ; zero out AX (string length) cause the specified string offset was too big
  133. assgn:      mov     [strlen],ax         ; store the string length in strlen (vaiable)
  134.             sub     ax,ax               ; zero out AX
  135.             mov     es,ax               ; put zero in for extra segment
  136.             mov     al,es:[0449h]       ; offset of 449h is needed
  137.             cmp     al,7                ; is value in al 7 ?
  138.             je      mdabase             ; if 7 then its monochrome
  139.             mov     ax,0b800h           ; if not then use CGA for base address
  140.             jmp     SHORT assign        ; goto assign: label
  141. mdabase:                                ; label: where MDA address is put in AX
  142.             mov     ax,0b000h           ; MDA adapter
  143. assign:                                 ; label: where extra seg is assigned
  144.             mov     es,ax               ; point to start of video buffer
  145.             lds     si,dword ptr strg   ; load seg & off for large data models
  146.             inc     si                  ; jump past the length byte
  147.             add     si,bx               ; add the string source offset to SI
  148.             mov     bl,byte ptr color   ; color. get the attribute value
  149.             mov     cx,word ptr col     ; col  . column address
  150.             mov     ax,word ptr row     ; row  . row address
  151.             mov     dx,160              ; bytes per line in CGA
  152.             mul     dx                  ; 160 * row number
  153.             add     ax,cx               ; add column number to offset in CGA buffer
  154.             add     ax,cx               ; add column number to offset in CGA: again
  155.             mov     di,ax               ; put address in CGA into DI
  156.             mov     cx,[strlen]         ; count of chars to write
  157.             cmp     cx,0000h            ; is CX set to zero
  158.             je      gclrchar            ; jump to gclrchar: if CX is zero (there are only chars to clear. none to write)
  159.             mov     ax,word ptr maxchars; maxchars.  get the maximum number of chars to write parameter
  160.             cmp     cx,ax               ; compare string length with maxchars (max allowed chars to write)
  161.             jg      toolong             ; make the string length shorter (it exceeds the max)
  162.             jmp     SHORT gclrchar      ; jump around the next assignment instruction
  163. toolong:    mov     cx,ax               ; set string length to maxchars
  164. gclrchar:   mov     dx,word ptr clrchar ; clrchar. get the number of chars to clear (parameter)
  165.             sub     dx,cx               ; subtract chars to write from clrchar (causes extra work in rare cases)
  166.             cmp     dx,1                ; compare the difference with one
  167.             jl      tooshort            ; if DX is less than one goto tooshort:
  168.             jmp     SHORT alright       ; else goto alright:
  169. tooshort:   mov     dx,0000h            ; set DX to zero (there are no chars to clear)
  170. alright:    mov     [toclear],dx        ; set toclear to the value of DX
  171. oklength:   mov     ah,bl               ; put in an attribute byte in AH (one time !)
  172.             cmp     cx,0000h            ; compare CX to zero. if (cx == 0) goto mdaclear:
  173.             je      mdaclear            ; goto mdaclear: (if cx == 0)
  174. monotop:
  175.             lodsb                       ; get one character put in AL
  176.             stosw                       ; move the word NOW! into the CRT
  177.             loop    monotop             ; bottom of loop
  178. mdaclear:   mov     cx,[toclear]        ; length of field to clear
  179.             cmp     cx,1                ; compare toclear to one
  180.             jl      endfast             ; no spaces need clearing so EXIT
  181.             mov     al,20h              ; put a space char into AL
  182.             rep     stosw               ; zing em all now! (clear the rest of the field)
  183. endfast:                                ; end of effective code
  184.             pop     ds
  185.             ret
  186. snowwrite endp
  187. ;***********************************************************************
  188. ;
  189. ;  SNOWPUTC.ASM  write a char(s) to the textmode screen
  190. ;                no 'snow' checking is done
  191. ;
  192. ; prototype: void far snowputc(int col, int row, char color, char outch, int numb);
  193. ;
  194.         PUBLIC snowputc
  195. snowputc proc    near col: WORD, row: WORD, color: BYTE, outch: BYTE, numb: WORD
  196.         cld                         ; clear direction flag
  197.         sub     ax,ax               ; zero out AX
  198.         mov     es,ax               ; put zero in for extra segment
  199.         mov     al,es:[0449h]       ; offset of 449h is needed
  200.         cmp     al,7                ; is value in al 7 ?
  201.         je      short mdabasepc     ; if 7 then its monochrome
  202.         mov     ax,0b800h           ; if not then use CGA for base address
  203.         jmp     short assignpc      ; goto assign: label
  204. mdabasepc:                          ; label: where MDA address is put in AX
  205.         mov     ax,0b000h           ; MDA adapter
  206. assignpc:                           ; label: where extra seg is assigned
  207.         mov     es,ax               ; point to address in video buffer
  208.         mov     bl,byte ptr outch   ; get the character
  209.         mov     bh, byte ptr color  ; get the attribute
  210.         mov     cx,col              ; column address
  211.         mov     ax,row              ; row address
  212.         mov     dx,160              ; bytes per line in CGA
  213.         mul     dx                  ; 160 * row number
  214.         add     ax,cx               ; add column number to offset in CGA buffer
  215.         add     ax,cx               ; add column number to offset in CGA: again
  216.         mov     di,ax               ; put address in CGA into DI
  217.         mov     cx,numb             ; get the count of chars to write
  218.         mov     ax,bx               ; put in an attribute byte in AX (one time !)
  219.         rep     stosw               ; move the number of char+atribb pairs
  220.         ret
  221. snowputc       ENDP
  222.  
  223. ; prototype: void near puts(char *strg);
  224. ; purpose:   emulate the Turbo C puts() function (text output (slow) in any video mode }
  225. ;            *strg is the string to output to STDOUT
  226. ;
  227.         PUBLIC puts
  228. ;***********************************************************************
  229. puts    proc   near strg: DWORD
  230.          push   ds
  231.          cld
  232.          lds    si,dword ptr strg;      ; load the pointer
  233.          lodsb                          ; load length byte inc pointer
  234.          mov    cx,ax                   ; copy length
  235.          mov    ch,0                    ; max output is 255 bytes
  236.          mov    dx,si                   ; PASS ptr in DS:DX
  237.          mov    bx,1;                   ; STDOUT
  238.          mov    ah,40h;                 ; DOS write file
  239.          int    21h                     ; call DOS
  240.          pop    ds
  241.          ret
  242. puts    ENDP
  243. ;***********************************************************************
  244.  
  245.  
  246.         END
  247.