home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / ZWDOS.ZIP / ZAPI.C < prev    next >
Text File  |  1993-03-02  |  6KB  |  190 lines

  1.  
  2. /********************************************************************
  3.     EXAMPLE.C  (C) Copyright Ya-Gui Wei 1993
  4.  
  5.     Example code for ZWDOS Application Program Interface (ZWAPI)
  6.     You're hereby permitted to incorporate all or part of the code
  7.     in file ZAPI.C and ZAPI.H into your programs without 
  8.     acknowledgement.
  9. ********************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include "zapi.h"
  14.  
  15. /********************************************************************/
  16. /* example using ZWDOS API calls from C */
  17. /* puts a little Chinese quote on row 4, column 31 of the screen */
  18.  
  19. #define YELLOW 0x0E
  20. #define ON_RED 0x40
  21.  
  22. /* uncomment this to compile test program: */
  23. /*  main () {zw_example();}   */
  24.  
  25. int zw_example (void)
  26. {
  27.    if (!zw_query())
  28.       { printf ("ZWDOS is not loaded.\n"); return (1); }
  29.  
  30.    zw_set_cc_mode();        /* turn on Chinese mode */
  31.  
  32.    zw_puts_asc (4, 31, YELLOW|ON_RED, "╔══════════════════╗");
  33.    zw_puts_cc  (5, 32, YELLOW|ON_RED,  ":C:CQ'O0#,LlLlOrIO");
  34.    zw_puts_asc (6, 31, YELLOW|ON_RED, "╚══════════════════╝");
  35.    zw_putc_asc (5, 31, YELLOW|ON_RED, '║');
  36.    zw_putc_asc (5, 50, YELLOW|ON_RED, '║');
  37.    zw_puts_mixed (9, 21, YELLOW|ON_RED, "hello╬║╤╟╣≡how are you");
  38.    return (0);
  39. }
  40.  
  41. /*******************************************************************
  42.   Query ZWDOS to see if loaded. Return 1 if yes, 0 if no. 
  43. *******************************************************************/
  44.  
  45. int zw_query (void)
  46. {
  47.    union REGS r;
  48.    r.x.ax = ZWAPI_MPX_N;
  49.    r.x.bx = ZWF_QUERYZW;
  50.    r.x.dx = 0x7a57;
  51.    int86 (0x2F, &r, &r);
  52.    return (r.x.ax==0x7a57);
  53. }
  54.  
  55. /********************************************************************
  56.  Return ZWDOS version in BCD format. For example, if version
  57.    2.20, then hex number 0x0220 is returned 
  58. ********************************************************************/
  59.  
  60. int zw_version (void)
  61. {
  62.    union REGS r;
  63.    r.x.ax = ZWAPI_MPX_N;
  64.    r.x.bx = ZWF_GETZWVER;
  65.    int86 (0x2F, &r, &r);
  66.    return (r.x.ax);
  67. }
  68.  
  69. /********************************************************************
  70.  zw_set_cc_mode() changes screen to Chinese mode 
  71.  zw_set_asc_mode() changes screen to ASCII mode 
  72.  zw_soft_flush()  Causes a "soft flush", which involves updating
  73.             the ASCII characters on screen, as well as 
  74.             chinese chars that are already in the font 
  75.             cache. This is normally called several times
  76.             a second by ZWDOS. 
  77.  zw_hard_flush()  Causes a "hard flush", which involves reading
  78.             font data from the disk and then update the
  79.             screen. This is called normally whenever DOS
  80.             is idle. Avoid calling this from TSRs. 
  81.  no need to call soft_flush and hard_flush normally unless
  82.    immediate updating of screen is desired. 
  83. ********************************************************************/
  84.  
  85. void zw_fn (int fnum);
  86. static void zw_fn (int fnum)
  87. {
  88.    union REGS r;
  89.    r.x.ax = ZWAPI_MPX_N;
  90.    r.x.bx = fnum;
  91.    int86 (0x2F, &r, &r);
  92. }
  93.  
  94. void zw_set_cc_mode (void) { zw_fn (ZWF_SET_CC); }
  95. void zw_set_asc_mode (void) { zw_fn (ZWF_SET_ASC); }
  96. void zw_soft_flush (void) { zw_fn (ZWF_SOFT_FLUSH); }
  97. void zw_hard_flush (void) { zw_fn (ZWF_HARD_FLUSH); }
  98.  
  99. /********************************************************************
  100.    zw_putc_cc()
  101.   puts a chinese character on screen at designated position.
  102.    attribute = (background_color * 16) + foreground_color + intensity
  103.       colors: 0 = black, 1 = blue, 2 = green, 3 = cyan;
  104.           4 = red,   5 = magenta, 6 = brown, 7 = white.
  105.       intensity: 0 = low intensity, 8 = bright, high intensity.
  106.    byte1, byte2 = chinese character data  
  107. ********************************************************************/
  108.  
  109. void zw_putc_cc (int row, int col, int attribute, int byte1, int byte2)
  110. {
  111.    union REGS r;
  112.    r.x.ax = ZWAPI_MPX_N;
  113.    r.x.bx = ZWF_WRT_CC;
  114.    r.x.cx = (row<<8)|col;
  115.    r.x.dx = ((byte1 & 0x7F) <<8) | (byte2 & 0x7F);
  116.    r.x.si = attribute;
  117.    int86 (0x2F, &r, &r);
  118. }
  119.  
  120. /********************************************************************
  121.   zw_putc_asc()
  122.  puts an ASCII character at designated position on screen. 
  123. ********************************************************************/
  124.  
  125. void zw_putc_asc (int row, int col, int attribute, int chr)
  126. {
  127.    union REGS r;
  128.    r.x.ax = ZWAPI_MPX_N;
  129.    r.x.bx = ZWF_WRT_ASC;
  130.    r.h.ch = row;
  131.    r.h.cl = col;
  132.    r.h.dh = attribute;
  133.    r.h.dl = chr;
  134.    int86 (0x2F, &r, &r);
  135. }
  136.  
  137. /********************************************************************
  138.    zw_puts_cc()
  139.   puts an Chinese string at designated position on screen.
  140.   The high bit of the characters are ignored.
  141.   Chinese string may be CCDOS-style modified GB 
  142.    or HZ-style pure GB (without the HZ escape sequences).
  143. ********************************************************************/
  144.  
  145. void zw_puts_cc (int row, int col, int attribute, char *s)
  146. {
  147.    int i;
  148.    for (i=0; s[i] && s[i+1]; i+=2, col+=2)
  149.       zw_putc_cc (row, col, attribute, s[i], s[i+1]);
  150. }
  151.  
  152. /********************************************************************
  153.    zw_puts_asc()
  154.   puts an ASCII string on screen.
  155.   ASCII string may have high bit set (graphic chars).
  156. ********************************************************************/
  157.  
  158. void zw_puts_asc (int row, int col, int attribute, char *s)
  159. {
  160.    int i;
  161.    for (i=0; s[i]; i++, col++)
  162.       zw_putc_asc (row, col, attribute, s[i]);
  163. }
  164.  
  165. /********************************************************************
  166.    zw_puts_mixed()
  167.   puts an ASCII-Chinese mixed string on screen.
  168.    Chinese chars must be with high-bit set (CCDOS style)
  169.    ASCII chars must be with high-bit cleared (no graphic chars).
  170. ********************************************************************/
  171.  
  172. void zw_puts_mixed (int row, int col, int attribute, char *s)
  173. {
  174.    int i;
  175.    for (i=0; s[i]; ) 
  176.       if ((s[i] & 0x80) && (s[i+1] & 0x80)) {
  177.      zw_putc_cc (row, col, attribute, s[i], s[i+1]);
  178.      i += 2;
  179.      col += 2;
  180.       }
  181.       else {
  182.      zw_putc_asc (row, col, attribute, s[i]);
  183.      i ++;
  184.      col ++;
  185.       }
  186. }
  187.  
  188. /********************************************************************/
  189.  
  190.