home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / midas / vgatext.asm < prev    next >
Assembly Source File  |  1994-08-06  |  6KB  |  260 lines

  1. ;*    VGATEXT.ASM
  2. ;*
  3. ;* VGA text output routines for MIDAS Module Player
  4. ;*
  5. ;* Copyright 1994 Petteri Kangaslampi and Jarno Paananen
  6. ;*
  7. ;* This file is part of the MIDAS Sound System, and may only be
  8. ;* used, modified and distributed under the terms of the MIDAS
  9. ;* Sound System license, LICENSE.TXT. By continuing to use,
  10. ;* modify or distribute this file you indicate that you have
  11. ;* read the license and understand and accept it fully.
  12. ;*
  13.  
  14.  
  15. IDEAL
  16. P386
  17.  
  18. INCLUDE "lang.inc"
  19. INCLUDE "vgatext.inc"
  20.  
  21.  
  22.  
  23. IDATASEG
  24.  
  25.  
  26. hextable    DB    "0123456789ABCDEF"
  27.  
  28.  
  29. CODESEG
  30.  
  31.  
  32.  
  33. ;/***************************************************************************\
  34. ;*
  35. ;* Function:     void vgaWriteText(int x, int y, char *txt);
  36. ;*
  37. ;* Description:  Writes text on the screen
  38. ;*
  39. ;* Input:     int x             X coordinate of string (up-left
  40. ;*                     corner is (1,1))
  41. ;*         int y             Y coordinate
  42. ;*         char *txt         pointer to null-terminated text
  43. ;*                     string, which may contain also the
  44. ;*                     following special characters:
  45. ;*                         \xFF - next char is attribute
  46. ;*                         \x7F - next char is RLE count for
  47. ;*                         the character following it
  48. ;*
  49. ;\***************************************************************************/
  50.  
  51. PROC    vgaWriteText    FAR    x : word, y : word, txt : dword
  52. USES    ds,si,di
  53.  
  54.     mov    ax,160
  55.     mov    bx,[y]
  56.     dec    bx
  57.     mul    bx
  58.     mov    di,[x]            ; point di to destination in display
  59.     dec    di            ; memory (160*y + 2*x)
  60.     shl    di,1
  61.     add    di,ax
  62.  
  63.     mov    ax,0B800h        ; point es to display memory - es:di
  64.     mov    es,ax            ; points to destination
  65.  
  66.     lds    si,[txt]        ; point ds:si to string
  67.  
  68.     mov    ah,07h            ; default attribute is 07h - white
  69.                     ; on black
  70.  
  71. @@lp:    mov    al,[ds:si]        ; get byte from string
  72.     inc    si
  73.     or    al,al            ; zero? (string termination)
  74.     jz    @@done
  75.  
  76.     cmp    al,0FFh         ; is next byte attribute?
  77.     je    @@attr
  78.  
  79.     cmp    al,07Fh         ; is next byte RLE count?
  80.     je    @@rle
  81.  
  82.     mov    [es:di],ax        ; normal character - write to screen
  83.     add    di,2
  84.     jmp    @@lp            ; and get next character
  85.  
  86. @@attr:
  87.     mov    ah,[ds:si]        ; get next attribute
  88.     inc    si
  89.     jmp    @@lp            ; get next character
  90.  
  91. @@rle:
  92.     movzx    cx,[ds:si]        ; get RLE count
  93.     mov    al,[ds:si+1]        ; get RLE byte
  94.     add    si,2
  95.     rep    stosw            ; draw characters
  96.     jmp    @@lp            ; get next character
  97.  
  98. @@done:
  99.     ret
  100. ENDP
  101.  
  102.  
  103.  
  104.  
  105. ;/***************************************************************************\
  106. ;*
  107. ;* Function:     void vgaWriteStr(int x, int y, char *str, char attr);
  108. ;*
  109. ;* Description:  Writes a string on the screen
  110. ;*
  111. ;* Input:     int x             X coordinate of the string
  112. ;*         int y             Y coordinate
  113. ;*         char *str         pointer to a ASCIIZ string
  114. ;*         char attr         attribute for the string
  115. ;*         int txtlen         number of characters to be printed on
  116. ;*                     screen - padded with spaces
  117. ;*
  118. ;\***************************************************************************/
  119.  
  120. PROC    vgaWriteStr    FAR    x : word, y : word, str : dword, attr : byte,\
  121.                 maxlen : word
  122. USES    ds,si,di
  123.  
  124.     mov    ax,160
  125.     mov    bx,[y]
  126.     dec    bx
  127.     mul    bx
  128.     mov    di,[x]            ; point di to destination in display
  129.     dec    di            ; memory (160*y + 2*x)
  130.     shl    di,1
  131.     add    di,ax
  132.  
  133.     mov    ax,0B800h        ; point es to display memory - es:di
  134.     mov    es,ax            ; points to destination
  135.  
  136.     lds    si,[txt]        ; point ds:si to string
  137.  
  138.     mov    ah,[attr]        ; attribute
  139.     mov    cx,[maxlen]        ; maximum number of characters
  140.  
  141. @@lp:    lodsb                ; get character
  142.     or    al,al            ; zero? (end of string)
  143.     jz    @@send            ; if is, stop
  144.     stosw                ; write character and attribute
  145.     loop    @@lp            ; and get next character
  146.     jmp    @@done
  147.  
  148. @@send: mov    al,' '                  ; string end - pad with spaces
  149.     rep    stosw
  150.  
  151. @@done:
  152.     ret
  153. ENDP
  154.  
  155.  
  156.  
  157.  
  158. ;/***************************************************************************\
  159. ;*
  160. ;* Function:     void vgaWriteByte(int x, int y, uchar byte, char attr);
  161. ;*
  162. ;* Description:  Writes a hex byte on the screen
  163. ;*
  164. ;* Input:     int x             X coordinate
  165. ;*         int y             Y coordinate
  166. ;*         uchar byte         byte to be written
  167. ;*         char attr         attribute for the byte
  168. ;*
  169. ;\***************************************************************************/
  170.  
  171. PROC    vgaWriteByte    FAR    x : word, y : word, b : byte, attr : byte
  172. USES    di
  173.  
  174.     mov    ax,160
  175.     mov    bx,[y]
  176.     dec    bx
  177.     mul    bx
  178.     mov    di,[x]            ; point di to destination in display
  179.     dec    di            ; memory (160*y + 2*x)
  180.     shl    di,1
  181.     add    di,ax
  182.  
  183.     mov    ax,0B800h        ; point es to display memory - es:di
  184.     mov    es,ax            ; points to destination
  185.  
  186.     mov    ah,[attr]        ; attribute
  187.     mov    bl,[b]
  188.     shr    bx,4            ; upper nybble
  189.     and    bx,0Fh
  190.     mov    al,[hextable+bx]    ; upper nybble character
  191.     mov    [es:di],ax        ; write upper nybble
  192.  
  193.     mov    bl,[b]
  194.     and    bx,0Fh            ; lower nybble
  195.     mov    al,[hextable+bx]    ; lower nybble character
  196.     mov    [es:di+2],ax        ; write lower nybble
  197.  
  198.     ret
  199. ENDP
  200.  
  201.  
  202.  
  203. ;/***************************************************************************\
  204. ;*
  205. ;* Function:     void vgaDrawMeter(int x, int y, int val, int max, char mchr,
  206. ;*         char hlattr, char nattr);
  207. ;*
  208. ;* Description:  Draws a meter on the screen
  209. ;*
  210. ;* Input:     int x             X coordinate
  211. ;*         int y             Y coordinate
  212. ;*         int val         meter value
  213. ;*         int max         meter max. value (length)
  214. ;*         char mchr         character used for meter
  215. ;*         char hlattr         attribute for highlighted characters
  216. ;*         char nattr         attribute for normal characters
  217. ;*
  218. ;\***************************************************************************/
  219.  
  220. PROC    vgaDrawMeter    FAR    x : word, y : word, val : word, max : word, \
  221.                 mchr : byte, hlattr : byte, nattr : byte
  222. USES    di
  223.  
  224.     cld
  225.  
  226.     mov    ax,160
  227.     mov    bx,[y]
  228.     dec    bx
  229.     mul    bx
  230.     mov    di,[x]            ; point di to destination in display
  231.     dec    di            ; memory (160*y + 2*x)
  232.     shl    di,1
  233.     add    di,ax
  234.  
  235.     mov    ax,0B800h        ; point es to display memory - es:di
  236.     mov    es,ax            ; points to destination
  237.  
  238.     mov    bx,[max]        ; total number of charaters to draw
  239.     mov    cx,[val]        ; number of highlighted characters
  240.     cmp    cx,bx            ; too many highlighted characters?
  241.     jbe    @@ok
  242.     mov    cx,bx
  243.  
  244. @@ok:    sub    bx,cx            ; number of non-highlighted characters
  245.     mov    al,[mchr]        ; meter character
  246.     mov    ah,[hlattr]        ; draw highlighted characters
  247.     rep    stosw
  248.  
  249.     mov    cx,bx            ; number of non-highlighted characters
  250.     mov    ah,[nattr]
  251.     rep    stosw            ; draw non-highlighted characters
  252.  
  253.     ret
  254. ENDP
  255.  
  256.  
  257.  
  258.  
  259. END
  260.