home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
GRAPHX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-27
|
7KB
|
431 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <doslib.h>
#include <iocslib.h>
#include "graph.h"
int Cols, Lines ;
int FontH = 8, FontV = 16 ;
extern void TextLine( int, int, int, int, int );
extern void TextFill( int, int, int, int, int );
void graph_init()
{
int i ;
CRTMOD( 16 );
B_CLR_AL();
C_WIDTH( 0 );
C_FNKMOD( 0 );
LEDMOD( 4, 1 );
G_CLR_ON();
Lines = 32 ;
Cols = 96 ;
for (i = 0; i < 8; ++i) {
graph_palet(i, (i&4) ? 255 : 0, (i&2) ? 255 : 0, (i&1) ? 255 : 0);
}
}
void graph_exit()
{
}
void graph_line( x1, y1, x2, y2, color )
int x1 ;
int y1 ;
int x2 ;
int y2 ;
int color ;
{
struct LINEPTR lbuf ;
if ( color < 16 )
{
lbuf.x1 = x1 ;
lbuf.x2 = x2 ;
lbuf.y1 = y1 ;
lbuf.y2 = y2 ;
lbuf.color = color ;
lbuf.linestyle = 0xffff ;
LINE( &lbuf );
}
else
{
TextLine( x1, y1, x2, y2, color-16 );
}
}
void graph_dashline( x1, y1, x2, y2, color )
int x1 ;
int y1 ;
int x2 ;
int y2 ;
int color ;
{
struct LINEPTR lbuf ;
if ( color < 16 )
{
lbuf.x1 = x1 ;
lbuf.x2 = x2 ;
lbuf.y1 = y1 ;
lbuf.y2 = y2 ;
lbuf.color = color ;
lbuf.linestyle = 0xcccc ;
LINE( &lbuf );
}
else
{
TextLine( x1, y1, x2, y2, color-16 );
}
}
void graph_cls( color )
int color ;
{
graph_fill( 0, 0, 768, 512, color );
}
void graph_fill( x1, y1, x2, y2, color )
int x1 ;
int y1 ;
int x2 ;
int y2 ;
int color ;
{
struct FILLPTR fbuf ;
if ( color < 16 )
{
fbuf.x1 = x1 ;
fbuf.x2 = x2 ;
fbuf.y1 = y1 ;
fbuf.y2 = y2 ;
fbuf.color = color ;
FILL( &fbuf );
}
else
{
TextFill( x1, y1, x2, y2, color-16 );
}
}
void graph_palet( paletmode, g, r, b )
int paletmode ;
int g, r, b ;
{
int color ;
color = ( ( g >> 3 ) << 11 ) | ( ( r >> 3 ) << 6 ) | ( ( b >> 3 ) << 1 );
GPALET( paletmode, color );
}
void graph_puts( str, x, y, atr )
char *str ;
int x, y ;
int atr ;
{
int len ;
int i, j, k ;
char *src ;
short *dst ;
int fg, bg, pat ;
int sp ;
len = strlen( str );
if ( len <= 0 )
return ;
B_PUTMES( 3, 0, 63, len-1, (UBYTE*)str );
if ( len <= 0 )
return ;
fg = atr & 0xf ;
bg = ( atr >> 4 ) & 0x0f;
dummy_label1:
sp = SUPER( 0 );
dummy_label2:
for( i = 0 ; i < 16 ; i++ )
{
src = (char*)0xE00000 + ( 63 * 16 + i ) * ( 1024 / 8 ) ;
dst = (short*)0xC00000 + ( y + i ) * 1024 + x ;
for( j = 0 ; j < len ; j++ )
{
pat = *src++ ;
for( k = 0 ; k < 8 ; k++ )
{
if ( pat & 0x80 )
*dst++ = fg ;
else if ((atr & 0x100) == 0)
*dst++ = bg ;
else
dst++;
pat <<= 1 ;
}
}
}
dummy_label3:
SUPER( sp );
}
void graph_pattern( x, y, color, pat, h, v )
int x, y ;
int color ;
short *pat ;
int h, v ;
{
int i, j, k ;
int a, hh, hword ;
int fg, bg ;
short *gram ;
int sp ;
fg = color & 0xf ;
bg = ( color >> 4 );
hword = ( h + 15 ) / 16 ;
dummy_label1:
sp = SUPER( 0 );
dummy_label2:
for( i = 0 ; i < v ; i++ )
{
gram = (short*)0xC00000 + ( y + i ) * 1024 + x ;
hh = h ;
for( j = 0 ; j < hword ; j++ )
{
a = *pat++ ;
for( k = 0 ; k < 16 && k < hh ; k++ )
{
if ( a & 0x8000 )
*gram++ = fg ;
else
*gram++ = bg ;
a <<= 1 ;
}
hh -= 16 ;
}
}
dummy_label3:
SUPER( sp );
}
/* ボタン表示 */
void graph_box( x1, y1, x2, y2, sw )
int x1, y1, x2, y2 ;
int sw ;
{
if ( sw )
{
graph_line( x1, y1, x2, y1, 7 );
graph_fill( x1, y1, x1+1, y2, 7 );
graph_line( x1, y2, x2, y2, 0 );
graph_line( x2, y1, x2, y2, 0 );
}
else
{
graph_line( x1, y1, x2, y1, 0 );
graph_line( x1, y1, x1, y2, 0 );
graph_line( x1, y2, x2, y2, 7 );
graph_fill( x2, y1, x2+1, y2, 7 );
}
}
#if 0
static unsigned char *ap;
static int xpos, ypos, xlen, ylen ;
int graph_push(int xp, int yp, int xl, int yl)
{
int sz, sp, x, y, n=0 ;
unsigned short *gram = ((unsigned short *)(0xc00000)) + yp * 1024 + xp;
unsigned char *buf;
xpos = xp;
ypos = yp;
xlen = xl;
ylen = yl;
sz = xlen * ylen;
if (ap != NULL) {
free(ap);
}
ap = malloc(sz) ;
if (ap != NULL) {
buf = ap;
dummy_label_1:
sp = SUPER(0) ;
dummy_label_2:
for (y = ylen ; y > 0 ; --y) {
for(x = xlen ; x > 0; --x) {
*buf++ = *gram++;
}
gram += 1024 - xlen;
}
dummy_label_3:
SUPER(sp) ;
dummy_label_4:
return TRUE;
}
return FALSE;
}
int graph_pop(void)
{
int sz, sp, x, y, n=0 ;
unsigned short *gram = ((unsigned short *)(0xc00000)) + ypos * 1024 + xpos;
unsigned char *buf;
if (ap != NULL) {
buf = ap;
dummy_label_1:
sp = SUPER(0) ;
dummy_label_2:
for (y = ylen ; y > 0 ; --y) {
for(x = xlen ; x > 0; --x) {
*gram++ = (unsigned short)*buf++;
}
gram += 1024 - xlen;
}
dummy_label_3:
SUPER(sp) ;
dummy_label_4:
free(ap);
ap = NULL;
return TRUE;
}
return FALSE;
}
#endif
static unsigned char *gp;
static int xpos, ypos, xlen, ylen ;
static unsigned long *tp;
static int txpos, txlen;
int graph_push(int xp, int yp, int xl, int yl)
{
int sz, sp, x, y, n=0, i ;
unsigned short *gram = ((unsigned short *)(0xc00000)) + yp * 1024 + xp;
unsigned char *buf;
unsigned long *tram, *tbuf;
txpos = xp / 32;
txlen = ((xp+xl) / 32) - txpos + 1;
xpos = xp;
ypos = yp;
xlen = xl;
ylen = yl;
sz = xlen * ylen;
if (gp != NULL) {
free(gp);
}
if (tp != NULL) {
free(tp);
}
gp = malloc(sz) ;
tp = malloc(4 * txlen * ylen * sizeof(long));
if (gp != NULL && tp != NULL) {
dummy_label_1:
sp = SUPER(0) ;
dummy_label_2:
buf = gp;
for (y = ylen ; y > 0 ; --y) {
for(x = xlen ; x > 0; --x) {
*buf++ = *gram++;
}
gram += 1024 - xlen;
}
MS_CUROF();
tbuf = tp;
for (i = 0; i < 4; ++i) {
tram = ((unsigned long*)(0xe00000)) + i * 32 * 1024 + ypos * 32 + txpos;
for (y = ylen; y > 0; --y) {
for (x = txlen; x > 0; --x) {
*tbuf++ = *tram++;
}
tram += 32 - txlen;
}
}
MS_CURON();
dummy_label_3:
SUPER(sp) ;
dummy_label_4:
return TRUE;
}
return FALSE;
}
int graph_pop(void)
{
int sz, sp, x, y, n=0, i ;
unsigned short *gram = ((unsigned short *)(0xc00000)) + ypos * 1024 + xpos;
unsigned long *tram = ((unsigned long*)(0xe00000)) + ypos * 32 + txpos;
unsigned char *buf;
unsigned long *tbuf;
if (gp != NULL && tp != NULL) {
dummy_label_1:
sp = SUPER(0) ;
dummy_label_2:
buf = gp;
for (y = ylen ; y > 0 ; --y) {
for(x = xlen ; x > 0; --x) {
*gram++ = (unsigned short)*buf++;
}
gram += 1024 - xlen;
}
MS_CUROF();
tbuf = tp;
/*printf("begin tp = %08x\n", tp);*/
for (i = 0; i < 4; ++i) {
tram = ((unsigned long*)(0xe00000)) + i * 32 * 1024 + ypos * 32 + txpos;
/*printf("(%d,%d):(%d,%d)-> %d:%d : %08x\n", xpos, ypos, xlen, ylen, txpos, txlen, tram);*/
for (y = ylen; y > 0; --y) {
for (x = txlen; x > 0; --x) {
*tram++ = *tbuf++;
}
tram += 32 - txlen;
}
}
MS_CURON();
dummy_label_3:
SUPER(sp) ;
dummy_label_4:
free(gp);
gp = NULL;
free(tp);
tp = NULL;
return TRUE;
}
return FALSE;
}
int graph_buffer_start(void)
{
return FALSE;
}
void graph_buffer_end(void)
{
}