Category : Printer + Display Graphics
Archive   : CRITTER4.ZIP
Filename : CSG.C

 
Output of file : CSG.C contained in archive : CRITTER4.ZIP
/*
Program: CSG (Character Set Generator)
Version: 1.10 10-Aug-1989

Language: Zortech C v1.07e
Environ: MS-DOS, IBM-PC compatible

Purpose: Used to create bit-mapped character sets for use in graphics
programs. A total of 256 characters per set are available.

Written by: Scott Robert Ladd
705 West Virginia
Gunnison, CO 81230

MCI ID: srl
FidoNet: 1:104/45.2
*/

/* include header files */
#include "disp.h"
#include "conio.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

/* define char set types */
typedef unsigned char CHAR_DEF[8]; /* matrix to hold one character */
typedef CHAR_DEF CHAR_SET[256]; /* array of all characters in a set */

/* create working character set variables */
CHAR_DEF grid_char;
CHAR_SET cset;

/* variable to hold name of current character set */
char setname[64];

/* version number */
const char * version = "1.10";

/* function prototypes */
void main(int argc, char *argv[]); /* main program logic */
void show_screen(void); /* display the screen */
int edit_set(void); /* modify the current char set */
void norm_block(int l, int c); /* set a block to "off" */
void blink_block(int l, int c); /* blink a block to show cursor position */
void reverse_block(int l, int c); /* set a block to "on" */
void save_char(unsigned char); /* write a character to a character set */
unsigned char select_char(void); /* choose a character to edit */

void main(int argc, char *argv[])
{
FILE *csfile; /* character set file */
char reply; /* user input */
int i, l; /* loop variables */
int save_set;

printf("\nCSG (Character Set Generator) v%s %s %s\n",version,__DATE__,__TIME__);
printf("Written by Scott Robert Ladd.\n\n");

if (argc < 2)
{
printf("Enter a character set name: ");
gets(setname);
putchar('\n');

if (!strlen(setname))
{
printf("\7No set name entered. Program terminated.\n");
exit(1);
}
}
else
strcpy(setname,argv[1]);

if (NULL == (csfile = fopen(setname,"rb")))
{
printf("Character set %s not found. Create it (Y/N)? ",setname);

while (!kbhit()) ;

reply = (char)getche();
reply = toupper(reply);

putchar('\n');

if (reply == 'Y')
for (i = 0; i < 256; ++ i)
for (l = 0; l < 8; ++l)
cset[i][l] = 0;
else
{
printf("Program terminated.\n");
exit(2);
}
}
else
fread(cset,sizeof(cset),1,csfile);

fclose(csfile);

disp_open();
disp_setattr(7);

show_screen();

save_set = edit_set();

disp_move(0,0);
disp_eeop();

disp_close();

disp_move(0,0);

if (save_set)
if (NULL == (csfile = fopen(setname,"w+b")))
{
printf("Character set %s cannot be written. Saving as CHARSET.DAT.\n");
csfile = fopen("CHARSET.DAT","w+b");
}
else
fwrite(cset,sizeof(cset),1,csfile);

fclose(csfile);
}

void show_screen()
{
int i;

disp_move(0,0);
disp_eeop();

disp_move(1,1);
disp_printf("ÚÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄÂÄÄ¿");

disp_move(17,1);
disp_printf("ÀÄÄÁÄÄÁÄÄÁÄÄÁÄÄÁÄÄÁÄÄÁÄÄÙ");

for (i = 2; i < 17; i = i + 2)
{
disp_move(i,1);
disp_printf("³ ³ ³ ³ ³ ³ ³ ³ ³");
}

for (i = 3; i < 16; i = i + 2)
{
disp_move(i,1);
disp_printf("ÃÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄÅÄÄ´");
}

disp_move(3,31);
disp_printf("Cursor Keys move UP, DOWN, LEFT, and RIGHT");
disp_move(5,31);
disp_printf("X = Exit and Save");
disp_move(6,31);
disp_printf("Q = Quit (without Saving)");
disp_move(8,31);
disp_printf("Space Bar = Reverse Current Block");
disp_move(10,31);
disp_printf("S = Select Character to Edit");
}

int edit_set()
{
unsigned char key, fkey, curch;
int stop = 0;
int l, c;
int ret_val;

l = 0;
c = 0;
curch = select_char();
blink_block(l,c);

while (!stop)
{
while (!kbhit()) ;
key = (char)getch();
switch(toupper(key))
{
case 0 :
if (kbhit())
{
fkey = (char)getch();
switch (fkey)
{
case 72 : /* UP */
if (l > 0)
{
norm_block(l,c);
--l;
blink_block(l,c);
}
break;
case 75 : /* LEFT */
if (c > 0)
{
norm_block(l,c);
--c;
blink_block(l,c);
}
break;
case 77 : /* RIGHT */
if (c < 7)
{
norm_block(l,c);
++c;
blink_block(l,c);
}
break;
case 80 : /* DOWN */
if (l < 7)
{
norm_block(l,c);
++l;
blink_block(l,c);
}
break;
}
}
break;
case 'X' :
save_char(curch);
stop = 1;
ret_val = 1;
break;
case 'Q' :
stop = 1;
ret_val = 0;
break;
case 32 :
reverse_block(l,c);
break;
case 'S' :
save_char(curch);
curch = select_char();
l = 0;
c = 0;
blink_block(l,c);
break;
}
}

return ret_val;
}

void norm_block(int l, int c)
{
unsigned int val, cl, cc;

cl = (l * 2) + 2;
cc = (c * 3) + 2;

val = disp_peekw(cl,cc);
val = val & 0x7FFF;
disp_pokew(cl,cc,val);

++cc;
val = disp_peekw(cl,cc);
val = val & 0x7FFF;
disp_pokew(cl,cc,val);
}

void blink_block(int l,int c)
{
unsigned int val, cl, cc;

cl = (l * 2) + 2;
cc = (c * 3) + 2;

val = disp_peekw(cl,cc);
val = val | 0x8000;
disp_pokew(cl,cc,val);

++cc;
val = disp_peekw(cl,cc);
val = val | 0x8000;
disp_pokew(cl,cc,val);
}

void reverse_block(int l, int c)
{
unsigned char bit;
int cl, cc;

cl = (l * 2) + 2;
cc = (c * 3) + 2;
bit = 1 << (char)c;

if (grid_char[l] & bit)
{
grid_char[l] &= ~bit;
disp_pokew(cl,cc,0x87B0);
disp_pokew(cl,cc+1,0x87B0);
}
else
{
grid_char[l] |= bit;
disp_pokew(cl,cc,0x87DB);
disp_pokew(cl,cc+1,0x87DB);
}
}

void save_char(unsigned char no)
{
memcpy(cset[no],grid_char,sizeof(grid_char));
}

unsigned char select_char(void)
{
unsigned char sel, bit;
int l, c, cl, cc;

disp_move(19,31);
disp_printf("Enter a character to be defined: ");
disp_move(19,64);

while(!kbhit()) ;

sel = (char)getch();

disp_move(19,31);
disp_printf(" ");

memcpy(grid_char,cset[sel],sizeof(grid_char));

for (l = 0; l < 8; ++l)
for (c = 0; c < 8; ++c)
{
cl = (l * 2) + 2;
cc = (c * 3) + 2;
bit = 1 << (char)c;
if (grid_char[l] & bit)
{
disp_pokew(cl,cc,0x07DB);
disp_pokew(cl,cc+1,0x07DB);
}
else
{
disp_pokew(cl,cc,0x07B0);
disp_pokew(cl,cc+1,0x07B0);
}
}

return sel;
}


  3 Responses to “Category : Printer + Display Graphics
Archive   : CRITTER4.ZIP
Filename : CSG.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/