home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 3
/
FREEWARE.BIN
/
towns_os
/
look
/
source
/
graphic.c
next >
Wrap
Text File
|
1980-01-02
|
7KB
|
258 lines
#include <stdio.h>
#include <stdlib.h>
#include <mmi.h>
#include <egb.h>
#include <mos.h>
#include <snd.h>
#include <msdos.cf>
char *work;
char *swork;
static char *mwork;
static int cd_vol;
/*** Disk Pattn ****/
char diskptn[]={
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFE,
0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x1F, 0xF0, 0x02, 0x9F, 0xFF, 0xFF, 0xF2,
0x9F, 0xFF, 0xFF, 0xF2, 0x80, 0x1F, 0xF0, 0x02,
0x80, 0x1F, 0xF0, 0x02, 0x80, 0x00, 0x00, 0x02,
0x86, 0x00, 0x00, 0x02, 0x86, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00 };
/**** Exit Pattn ***/
char exitptn[]={
0x7F, 0xFC, 0x55, 0x04, 0x6B, 0x44, 0x55, 0x44,
0x6B, 0x04, 0x55, 0x04, 0x68, 0x84, 0x54, 0x44,
0x68, 0x24, 0x7F, 0xFC, 0x00, 0x00, 0x75, 0x5C,
0x45, 0x48, 0x72, 0x48, 0x45, 0x48, 0x75, 0x48 };
/**** sub Menu Pattn ****/
char subptn[]={
0x00, 0x00, 0x03, 0xE0, 0x0C, 0x18, 0x30, 0x06,
0x2C, 0x1A, 0x23, 0xE2, 0x20, 0x82, 0x30, 0x86,
0x0C, 0x98, 0x03, 0xE0, 0x00, 0x00, 0x56, 0xAA,
0x74, 0xEA, 0x76, 0xEA, 0x54, 0xEA, 0x56, 0xA4 };
/***** <- pattn *****/
char lftptn[]={
0xFF, 0xFF, 0x80, 0x01, 0x80, 0x01, 0x81, 0x01,
0x83, 0x01, 0x87, 0x01, 0x8F, 0xF9, 0x9F, 0xF9,
0x8F, 0xF9, 0x87, 0x01, 0x83, 0x01, 0x81, 0x01,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFF, 0xFF };
/***** -> pattn ****/
char ritptn[]={
0xFF, 0xFF, 0x80, 0x01, 0x80, 0x01, 0x80, 0x81,
0x80, 0xC1, 0x80, 0xE1, 0x9F, 0xF1, 0x9F, 0xF9,
0x9F, 0xF1, 0x80, 0xE1, 0x80, 0xC1, 0x80, 0x81,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFF, 0xFF };
/**** MOS 1 Pattn ****/
static char mosptn[5][66]={
{ 2, 16,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x60, 0x00,
0x30, 0x00, 0x58, 0x00, 0x3C, 0x00, 0x5E, 0x00,
0x2F, 0x00, 0x5F, 0x80, 0x2E, 0x00, 0x7C, 0x00,
0x66, 0x00, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00,
0x7F, 0xFF, 0x3F, 0xFF, 0x5F, 0xFF, 0x6F, 0xFF,
0x37, 0xFF, 0x5B, 0xFF, 0x3D, 0xFF, 0x5E, 0xFF,
0x2F, 0x7F, 0x5F, 0xBF, 0x2E, 0x7F, 0x7D, 0xFF,
0x66, 0xFF, 0x16, 0xFF, 0x7B, 0x7F, 0xF8, 0x7F },
{ 2, 16,
0x00, 0x00, 0x2F, 0xF4, 0x2F, 0xF4, 0x2F, 0xF4,
0x37, 0xEC, 0x39, 0x9C, 0x3C, 0x3C, 0x3E, 0x7C,
0x3E, 0x7C, 0x3D, 0xBC, 0x3B, 0xDC, 0x36, 0x6C,
0x2C, 0x34, 0x28, 0x14, 0x20, 0x04, 0x00, 0x00,
0x00, 0x00, 0xAF, 0xF5, 0xAF, 0xF5, 0xAF, 0xF5,
0xB7, 0xED, 0xB9, 0x9D, 0xBC, 0x3D, 0xBE, 0x7D,
0xBE, 0x7D, 0xBD,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xEA, 0x5F,
0xE1, 0x5F, 0xE5, 0x5F, 0xE2, 0x5F, 0xE8, 0x5F,
0xF4, 0xBF, 0xF7, 0x7F, 0xF0, 0x7F, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
void wrtmos(int tp)
{
MOS_type(1, 0, 0, mosptn[tp]);
}
int mosclip(int s,int x,int y)
{
int i;
int bs,bx,by;
i = 10000;
do {
MOS_rdpos(&bs,&bx,&by);
if ( --i == 5000 )
wrtmos(2);
} while ( i > 0 && bs == 0 &&
bx >= (x - 8) && bx <= (x + 8) &&
by >= (y - 8) && by <= (y + 8) );
wrtmos(0);
return (bs != 0 ? 1 : 0);
}
void grainit(void)
{
int i;
char *p;
if ( (p = work = malloc(2048)) == NULL )
exit(0);
for ( i=2048 ; i > 0 ; i-- ) *(p++) = 0;
if ( (p = mwork = malloc(2048)) == NULL )
exit(0);
for ( i=2048 ; i > 0 ; i-- ) *(p++) = 0;
if ( (swork = malloc(16384)) == NULL )
exit(0);
SND_elevol_read(1,&cd_vol,&cd_vol);
SND_init(swork);
MOS_start(mwork,2048);
MOS_resolution(0, 3);
MOS_writePage(0);
EGB_init(work,2048);
SND_elevol_mute(0x33);
SND_elevol_set(1,cd_vol,cd_vol);
EGB_resolution(work, 0, 3);
EGB_resolution(work, 1, 3);
EGB_displayPage(work, 0, 3);
EGB_pen(work,0);
EGB_penSize(work,1);
wrtmos(0);
}
void graend(void)
{
MOS_end();
SND_end();
SND_elevol_mute(0x30);
SND_elevol_set(1,cd_vol,cd_vol);
exit(0);
}
void line(int x1, int y1, int x2, int y2, int col, int mode)
{
char para[10];
MOS_disp(0);
EGB_writeMode(work,mode);
EGB_paintMode(work,0x002);
EGB_color(work,0,col);
WORD(para + 0) = 2;
WORD(para + 2) = x1;
WORD(para + 4) = y1;
WORD(para + 6) = x2;
WORD(para + 8) = y2;
EGB_connect(work,para);
MOS_disp(1);
}
void box(int x1, int y1, int x2, int y2, int col, int mode)
{
char para[8];
MOS_disp(0);
EGB_writeMode(work,mode);
EGB_paintMode(work,0x002);
EGB_color(work,0,col);
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle(work,para);
MOS_disp(1);
}
void fbox(int x1, int y1, int x2, int y2, int col, int bcol, int mode)
{
char para[8];
MOS_disp(0);
EGB_writeMode(work,mode);
EGB_paintMode(work,0x022);
EGB_color(work,0,col);
EGB_color(work,2,bcol);
WORD(para + 0) = x1;
WORD(para + 2) = y1;
WORD(para + 4) = x2;
WORD(para + 6) = y2;
EGB_rectangle(work,para);
MOS_disp(1);
}
char *getvram(int x1,int y1,int x2, int y2)
{
int i;
char *vram;
char para[14];
i = (((x2 - x1) + 8) / 8) * 4 * ((y2 - y1) + 1);
if ( (vram = malloc(i)) == NULL )
return NULL;
DWORD(para + 0) = (int)vram;
WORD(para + 4) = getds();
WORD(para + 6) = x1;
WORD(para + 8) = y1;
WORD(para + 10) = x2;
WORD(para + 12) = y2;
MOS_disp(0);
EGB_getBlock(work,para);
MOS_disp(1);
return vram;
}
void putvram(char *vram,int x1,int y1,int x2, int y2)
{
char para[14];
if ( vram == NULL )
return;
DWORD(para + 0) = (int)vram;
WORD(para + 4) = getds();
WORD(para + 6) = x1;
WORD(para + 8) = y1;
WORD(para + 10) = x2;
WORD(para + 12) = y2;
MOS_disp(0);
EGB_writeMode(work,0);
EGB_putBlock(work,0,para);
MOS_disp(1);
}
void wrtstrf(x,y,fnt,col,bak,frm,pa1,pa2,pa3,pa4,pa5)
int x,y,fnt,col,bak;
char *frm;
int pa1,pa2,pa3,pa4,pa5;
{
char tmp[256];
sprintf(tmp,frm,pa1,pa2,pa3,pa4,pa5);
VRAM_wrtstr(tmp,x,y,fnt == 0 ? 16 : 0x90,col,bak,0,0);
}
void wrtstr(char *str,int x,int y,int fnt,int col,int bak)
{
VRAM_wrtstr(str,x,y,fnt == 0 ? 16 : 0x90,col,bak,0,0);
}