[comp.sys.m6809] crsrmkr.shar

jimomura@lsuc.uucp (Jim Omura) (05/25/88)

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	ReadMe
#	crsrmkr.c
# This archive created: 
# By:	Jim Omura ()
cat << \SHAR_EOF > ReadMe
88/05/24
'crsrmkr'

    This program isn't really finished.  Enough is working that
I have used it to make 2 cursors for an application which is my
main concern at this time.  I have just made arrangements to
distribute some of my utilities commercially, so even if I
get around to finishing this one, there's a chance that the
at some point, future versions may not be public domain.  But
this one is, and being source code, you can finish it as you
wish.
 
Cheers! -- Jim O.
SHAR_EOF
cat << \SHAR_EOF > crsrmkr.c
/* crsrmkr.c */

/* CoCo3 OS-9 Windows Cursors module */

/* This Version Public Domain
 * May 1988 By Jim Omura,
 * 2A King George's Drive
 * Toronto, Ontario, Canada
 *
 * NOTES:  A buffer can't hold more than 8K bytes.  Therefore,
 *         try to keep data under 8000 bytes.
 */

#include <stdio.h>
#include <modes.h>
#include <sgstat.h>

#define ERROR   -1

#define FALSE   0

#define STDIN   0
#define STDOUT  1
#define STDERR  2

#define TRUE    1

typedef struct scrnmat {
    char fmtcode;
    int  pixwd;
    int  pixhi;
    int  clrs;
    } SCRNMAT ;

/* Globals: */

/* Embedded Constants: */

char bckspcs[] = {0x08,0x08,0x08};

char ldhdr[] = {
    0x1b,
    0x2b
    };

char    curhome = 0x01;  /* Home Cursor */
char    scrnclr = 0x0c;  /* Clr screen & Home */

/* Screen Formats: */

SCRNMAT cocomats[] = {
    { 0x05, 640, 192, 2}, /* high mono */
    { 0x06, 320, 192, 4}, /* low 4 color */
    { 0x07, 640, 192, 4}, /* high 4 color */
    { 0x08, 320, 192, 16} /* low 16 color */
    };

/* Variables: */
char bufnum;          /* Buffer Number */
char databuf[0x0100]; /* 4K big enough? */
int  dimx;            /* X size of array */
int  dimy;            /* Y size of array */
int  fllen;           /* No. bytes of data */
char grpnum;          /* Buffer Group Number */
char hdrbuf[11];      /* Holds Existing Header */
char inbuf[5];        /* Input buffer */
char pathname[80];

main(argc,argv)
int argc;
char **argv;
{

/* Declare Local Variables */

    int  choice;
    int  dtoffst; /* Data Pointer offset */
    char format;  /* Screen format */
    int  flpath;  /* File path */
    int  itnum;   /* current item within buffer */
    int  report;


/* Set Defaults */

    bufnum  = 1;
    dtoffst = 0;
    fllen   = 0;
    flpath  = STDIN;
    format  = cocomats[3].fmtcode; /* low 16 color */
    grpnum  = 1;
    dimx    = 8;
    dimy    = 8;

    for( ;argc > 1;)

    {
        ++argv;
        --argc;
        if(**argv == '-')
        {

            for (;;)
            {
                ++*argv;
                switch((int) **argv) 
                {
                    case '\0':
                        break;
                    case '?':
                        shorthelp();
                        exit(0);
                    default:
                        continue;
                }   /* Endswitch */

             }   /* Endloop more chars */
             continue;

         }   /* Endif dash handler */

         if (flpath == STDIN)  /* Unix type file openning */
         {
            flpath = open(*argv,3);

            if (flpath == ERROR)
            {
                fprintf(stderr,"CRSRMKR: File openning error\n");
                exit(0);
            }   /* Endif open error */

            continue;

        }   /* Endif open input file */

    }   /* Endloop arghandler */

/* Clear the Screen: */

    putc(scrnclr,stdout);
    fflush(stdout);       /* Be sure it goes out! */

/* Main Loop: */

    for(;;)
    {
        choice = showmenu();
        switch(choice)
        {
        case 0: /*  Help */
        case 1: /*  Select Group/Buffer/item */
            itnum = gbichange(itnum);
            continue;
        case 2: /*  Edit Pattern */
            putc(scrnclr,stdout);
            editpat(format);
            putc(scrnclr,stdout);
            continue;
        case 3: /*  Change Format */
        case 4: /*  Load File */
        /* 2. choice -- load file or separate file
         * into individual files */
        /* One Group per file -- else abort load */
            fprintf(stderr,"Not implimented\n");
            continue;
        case 5: /*  Save File */
            report = filesave(flpath,format);
            continue;
        case 6: /*  Exit Program */
            printf("Are you sure [yn]?:");
            fflush(stdout);
            if (getchar != 'y')
            {
                continue;
            }
            break;
        default:
            continue;
        }   /* Endswitch choice */
        break;
    }   /* Endloop main loop */

    exit(0);

}   /* End of main() */

/* --------------------------- */
gbichange(itnum)
int itnum;
{
    extern char bufnum;
    extern char grpnum;
    char        tempval;

    for (;;)
    {
printf("Group %3d Buffer %3d Item %3d\n",(grpnum & 0xff),(bufnum & 0xff),itnum);
        printf("New Group (q = quit, 0 = unchanged)?     ");
        fwrite(bckspcs,1,3,stdout);
        fflush(stdout);
        fgets(inbuf,3,stdin);
        if (*inbuf == 'q')
        {
            break;
        }
        tempval = (char) atoi(inbuf);
        if (tempval != 0)
        {
            grpnum = tempval;
            printf("New Group %3d\n",(grpnum & 0xff));
        }
        printf("New Buffer (q = quit, 0 = unchanged)?     ");
        fwrite(bckspcs,1,3,stdout);
        fflush(stdout);
        fgets(inbuf,3,stdin);
        if (*inbuf == 'q')
        {
            break;
        }
        tempval = (char) atoi(inbuf);
        if (tempval != 0)
        {
            bufnum = tempval;
        }
    }
    return (itnum);
}
/* ----------------------------- */

editpat(format)
char format;
{
    extern char bckspcs[];
    extern char curhome;
    extern char databuf[0x0100]; /* 4K big enough? */
    extern int  dimx;
    extern int  dimy;
    int         edoffst; /* offset of char to edit */
    extern int  fllen;
    char        newval;
    extern char scrnclr;
    int         pixnum;
    int         pixval;
    int         ppbyte;  /* pixels per byte */
    int         xcntr;
    int         ycntr;

    ppbyte = 2;  /* For 16 color modes */

    putc(scrnclr,stdout);
    fllen = dimx * dimy / ppbyte;

    for(;;)
    {
    /* Show Pattern */
        fflush(stdout);
        putc(curhome,stdout);
        ycntr = 0;
        printf("px#    0  1  2  3  4  5  6  7\n"); /* Change later */
        for(;;) /* Y loop */
        {
            if (ycntr == dimy)
            {
                break;
            }
            xcntr = 0;
            printf("\n %4d",(ycntr * dimx));
            for(;;) /* X loop */
            {
                if (xcntr == dimx)
                {
                    break;
                }
                pixnum = (ycntr * dimx) + xcntr;
                pixval = getpixel(pixnum,format);
                printf(" %2x",(pixval & 0xff));
                ++xcntr;
            }
            ++ycntr;
        }
        /* Request Change */
        printf("\nPixels / byte = %1d\n", ppbyte);
        printf("q to quit or Byte to change?    ");
        fwrite(bckspcs,1,3,stdout);
        fflush(stdout);
        fgets(inbuf,5,stdin);
        if (*inbuf == 'q')
        {
            break;
        }
        edoffst = atoi(inbuf);
        printf("Change to?    ");
        fwrite(bckspcs,1,3,stdout);
        fflush(stdout);
        fgets(inbuf,5,stdin);
        newval = (char) atoi(inbuf);
        databuf[edoffst] = newval;
    /* Make Change */
        continue;
    }
}

int
getpixel(pixnum,format)
int pixnum;
char format;
{
    extern char databuf[0x0100]; /* 4K big enough? */
    int         pixval;
    int         ppbyte;          /* pixels per byte */
    int         pixoffst;

    ppbyte = 2; /* for 16 color */

    pixval = (int) databuf[pixnum / ppbyte];
    pixoffst = ((ppbyte - 1) - (pixnum - ((pixnum / ppbyte) * ppbyte)));
    pixval = pixval >> ((8 / ppbyte) * pixoffst);
    pixval = pixval & (0xff >> (8 / ppbyte));
    return(pixval);
}

/* ------------------------------ */

int
filesave(flpath,format)
int flpath;
char format;
{
    extern char bufnum;
    extern char databuf[0x100];
    extern int  dimx;
    extern int  dimy;
    extern int  fllen;
    extern char grpnum;
    extern char ldhdr[2];
    extern char pathname[80];
    int report;

    if (flpath == STDIN)
    {
        printf("Filename?");
        fflush(stdout);
        fgets(pathname,80,stdin);
        if(strlen(pathname) == 0)
        {
            printf("No path give\n");
            return(0);
        }
        report = creat(pathname,3);
        if (report == ERROR)
        {
            printf("Cannot open path\n");
            return(0);
        }
        flpath = report;
        write(flpath,ldhdr,2);
        write(flpath,&grpnum,1);
        write(flpath,&bufnum,1);
        write(flpath,&format,1);
        write(flpath,&dimx,2);
        write(flpath,&dimy,2);
        write(flpath,&fllen,2);
        write(flpath,databuf,fllen);
        printf("Done\n");
        return(0);
    }
}

int
showmenu()
{
    extern char inbuf[5];

    putc(curhome,stdout);
    fflush(stdout);
    printf(" 0.  Help\n");
    printf(" 1.  Select Group/Buffer/Item\n");
    printf(" 2.  Edit Pattern\n");
    printf(" 3.  Change Format\n");
    printf(" 4.  Load File\n");
    printf(" 5.  Save File\n");
    printf(" 6.  Exit Program\n");
    printf("\n ?");
    fflush(stdout);
    fgets(inbuf,5,stdin);
    return(atoi(inbuf));

}

shorthelp()
{
    fprintf(stderr,"CRSRMKR: [-?] [filename]\n");
    fprintf(stderr,"Cursor editor\n");
    fprintf(stderr,"   default: filename will be requested later\n");
    fprintf(stderr," ? Short help\n");
    fprintf(stderr," filename is an existing file\n");
}   /* End of shorthelp() */

/* End of crsrmkr.c */
SHAR_EOF
#	End of shell archive
exit 0
-- 
Jim Omura, 2A King George's Drive, Toronto, (416) 652-3880
ihnp4!utzoo!lsuc!jimomura
Byte Information eXchange: jimomura