home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
ZWDOS.ZIP
/
ZAPI.C
< prev
next >
Wrap
Text File
|
1993-03-02
|
6KB
|
190 lines
/********************************************************************
EXAMPLE.C (C) Copyright Ya-Gui Wei 1993
Example code for ZWDOS Application Program Interface (ZWAPI)
You're hereby permitted to incorporate all or part of the code
in file ZAPI.C and ZAPI.H into your programs without
acknowledgement.
********************************************************************/
#include <stdio.h>
#include <dos.h>
#include "zapi.h"
/********************************************************************/
/* example using ZWDOS API calls from C */
/* puts a little Chinese quote on row 4, column 31 of the screen */
#define YELLOW 0x0E
#define ON_RED 0x40
/* uncomment this to compile test program: */
/* main () {zw_example();} */
int zw_example (void)
{
if (!zw_query())
{ printf ("ZWDOS is not loaded.\n"); return (1); }
zw_set_cc_mode(); /* turn on Chinese mode */
zw_puts_asc (4, 31, YELLOW|ON_RED, "╔══════════════════╗");
zw_puts_cc (5, 32, YELLOW|ON_RED, ":C:CQ'O0#,LlLlOrIO");
zw_puts_asc (6, 31, YELLOW|ON_RED, "╚══════════════════╝");
zw_putc_asc (5, 31, YELLOW|ON_RED, '║');
zw_putc_asc (5, 50, YELLOW|ON_RED, '║');
zw_puts_mixed (9, 21, YELLOW|ON_RED, "hello╬║╤╟╣≡how are you");
return (0);
}
/*******************************************************************
Query ZWDOS to see if loaded. Return 1 if yes, 0 if no.
*******************************************************************/
int zw_query (void)
{
union REGS r;
r.x.ax = ZWAPI_MPX_N;
r.x.bx = ZWF_QUERYZW;
r.x.dx = 0x7a57;
int86 (0x2F, &r, &r);
return (r.x.ax==0x7a57);
}
/********************************************************************
Return ZWDOS version in BCD format. For example, if version
2.20, then hex number 0x0220 is returned
********************************************************************/
int zw_version (void)
{
union REGS r;
r.x.ax = ZWAPI_MPX_N;
r.x.bx = ZWF_GETZWVER;
int86 (0x2F, &r, &r);
return (r.x.ax);
}
/********************************************************************
zw_set_cc_mode() changes screen to Chinese mode
zw_set_asc_mode() changes screen to ASCII mode
zw_soft_flush() Causes a "soft flush", which involves updating
the ASCII characters on screen, as well as
chinese chars that are already in the font
cache. This is normally called several times
a second by ZWDOS.
zw_hard_flush() Causes a "hard flush", which involves reading
font data from the disk and then update the
screen. This is called normally whenever DOS
is idle. Avoid calling this from TSRs.
no need to call soft_flush and hard_flush normally unless
immediate updating of screen is desired.
********************************************************************/
void zw_fn (int fnum);
static void zw_fn (int fnum)
{
union REGS r;
r.x.ax = ZWAPI_MPX_N;
r.x.bx = fnum;
int86 (0x2F, &r, &r);
}
void zw_set_cc_mode (void) { zw_fn (ZWF_SET_CC); }
void zw_set_asc_mode (void) { zw_fn (ZWF_SET_ASC); }
void zw_soft_flush (void) { zw_fn (ZWF_SOFT_FLUSH); }
void zw_hard_flush (void) { zw_fn (ZWF_HARD_FLUSH); }
/********************************************************************
zw_putc_cc()
puts a chinese character on screen at designated position.
attribute = (background_color * 16) + foreground_color + intensity
colors: 0 = black, 1 = blue, 2 = green, 3 = cyan;
4 = red, 5 = magenta, 6 = brown, 7 = white.
intensity: 0 = low intensity, 8 = bright, high intensity.
byte1, byte2 = chinese character data
********************************************************************/
void zw_putc_cc (int row, int col, int attribute, int byte1, int byte2)
{
union REGS r;
r.x.ax = ZWAPI_MPX_N;
r.x.bx = ZWF_WRT_CC;
r.x.cx = (row<<8)|col;
r.x.dx = ((byte1 & 0x7F) <<8) | (byte2 & 0x7F);
r.x.si = attribute;
int86 (0x2F, &r, &r);
}
/********************************************************************
zw_putc_asc()
puts an ASCII character at designated position on screen.
********************************************************************/
void zw_putc_asc (int row, int col, int attribute, int chr)
{
union REGS r;
r.x.ax = ZWAPI_MPX_N;
r.x.bx = ZWF_WRT_ASC;
r.h.ch = row;
r.h.cl = col;
r.h.dh = attribute;
r.h.dl = chr;
int86 (0x2F, &r, &r);
}
/********************************************************************
zw_puts_cc()
puts an Chinese string at designated position on screen.
The high bit of the characters are ignored.
Chinese string may be CCDOS-style modified GB
or HZ-style pure GB (without the HZ escape sequences).
********************************************************************/
void zw_puts_cc (int row, int col, int attribute, char *s)
{
int i;
for (i=0; s[i] && s[i+1]; i+=2, col+=2)
zw_putc_cc (row, col, attribute, s[i], s[i+1]);
}
/********************************************************************
zw_puts_asc()
puts an ASCII string on screen.
ASCII string may have high bit set (graphic chars).
********************************************************************/
void zw_puts_asc (int row, int col, int attribute, char *s)
{
int i;
for (i=0; s[i]; i++, col++)
zw_putc_asc (row, col, attribute, s[i]);
}
/********************************************************************
zw_puts_mixed()
puts an ASCII-Chinese mixed string on screen.
Chinese chars must be with high-bit set (CCDOS style)
ASCII chars must be with high-bit cleared (no graphic chars).
********************************************************************/
void zw_puts_mixed (int row, int col, int attribute, char *s)
{
int i;
for (i=0; s[i]; )
if ((s[i] & 0x80) && (s[i+1] & 0x80)) {
zw_putc_cc (row, col, attribute, s[i], s[i+1]);
i += 2;
col += 2;
}
else {
zw_putc_asc (row, col, attribute, s[i]);
i ++;
col ++;
}
}
/********************************************************************/