/****************************************************/ /* CASSETTE LABEL MAKER */ /* by David W. Douglass 12/24/87 */ /* Written & compiled with Megamax C */ /****************************************************/ /* IMPORTANT NOTE: This program is self-modifying! */ /* Any changes made in this program without making */ /* the appropriate changes to the first Fseek() call*/ /* in the Save_setup() routine will be disasterous! */ #include #include #include #include #include "tebox.h" #include "objects.h" /* standard GEM stuff */ int work_in[11], work_out[57], pxyarray[10], contrl[12], intin[128], ptsin[128], intout[128], ptsout[128]; /* Raster Operation Memory Form Definition Blocks (MFDBs) */ FDB VDIscr = {0x0L,0,0,0,0,0,0,0,0}; FDB VDIbfr = {0x0L,320,100,20,0,2,0,0,0}; /* Virtual Workstation handle */ int VDIhandle; /* Global variables */ int windowA,windowB, /* handles to sideA,sideB windows */ active, /* currently editable screen area */ xpos, /* objc_edit cursor position variable */ done, /* program exit flag */ pstat, /* printer error flag */ vres, /* vertical resolution: 0=LOW 1=MED 2=HI */ vmax; /* vertical max: LOW/MED=199 HI=399 */ /* List of window pointers for WhichBox() */ int Wlist[4] = {-1,-1,-1,-1}; /* Printer character pitch control codes */ char cpi5[7],cpi6[7],cpi85[7],cpi10[7],cpi12[7],cpi17[7]; /* values of the variable 'active' */ #define HEADER 1 #define WINDOWA 2 #define WINDOWB 3 #define FOOTER1 4 #define FOOTER2 5 GEM_init () { int i,temp,loaddr,hiaddr; VDIhandle = graf_handle(&temp,&temp,&temp,&temp); for (i=0; i<10; work_in[i++]=1); work_in[10] = 2; v_opnvwk(work_in,&VDIhandle,work_out); vres = Getrez(); vmax = 199; VDIbfr.fd_addr = Malloc(0x2000L); if (Getrez() == 2) { VDIbfr.fd_h = 200; VDIbfr.fd_nplanes = 1; vmax = 399; } TEbox_init(VDIhandle); } Screen_init () { graf_mouse(0,0); v_hide_c(VDIhandle); v_clrwk(VDIhandle); vsf_interior(VDIhandle,3); vsf_style(VDIhandle,2); vsf_color(VDIhandle,RED); pxyarray[0]=0; pxyarray[1]=0; pxyarray[2]=639; pxyarray[3]=vmax; vr_recfl(VDIhandle,pxyarray); v_show_c(VDIhandle,0); } Object_init () { int TEbox; v_hide_c(VDIhandle); objc_draw(header,ROOT,MAX_DEPTH,0,0,639,vmax); windowA = wind_create(NAME,15,37*vres,30*8+2,13*8*vres+4); wind_set(windowA,WF_NAME,"Side A",0,0); wind_open(windowA,15,37*vres,30*8+2,13*8*vres+4); TEbox = TEbox_create(30,12); TEbox_open(TEbox,16,48*vres-4*(vres-1)); Wlist[TEbox] = windowA; windowB = wind_create(NAME,47,45*vres,30*8+2,13*8*vres+4); wind_set(windowB,WF_NAME,"Side B",0,0); wind_open(windowB,47,45*vres,30*8+2,13*8*vres+4); TEbox = TEbox_create(30,12); TEbox_open(TEbox,48,56*vres-4*(vres-1)); Wlist[TEbox] = windowB; objc_draw(footer,ROOT,MAX_DEPTH,0,0,639,vmax); objc_draw(options,ROOT,MAX_DEPTH,0,0,639,vmax); vst_effects(VDIhandle,5); v_gtext(VDIhandle,390,60*vres,"CASSETTE LABEL MAKER"); vst_effects(VDIhandle,0); v_show_c(VDIhandle,0); active = HEADER; objc_edit(header,TITLE,0,&xpos,EDINIT); } Unhex (hex,ascii) char *hex,*ascii; { int pair; char c; pair = c = 0; for (; *hex!=0; hex++) { if ((*hex>='0') && (*hex<='9')) { c += (*hex-'0'); ++pair; } else if ((*hex>='A') && (*hex<='F')) { c += (*hex-'A'+10); ++pair; } else return(0); if (pair > 1) { *ascii = c; pair = c = 0; ascii++; } else c *= 16; } if (pair) return(0); *ascii = 0; return(1); } Print_init () { Unhex(set1,&cpi5); Unhex(set2,&cpi6); Unhex(set3,&cpi85); Unhex(set4,&cpi10); Unhex(set5,&cpi12); Unhex(set6,&cpi17); } WhichBox (window) int window; { int i; for (i=0; i<4; ++i) if (window == Wlist[i]) return(i); return(-1); } Deactivate (item) int item; { switch (item) { case HEADER: objc_edit(header,TITLE,0,&xpos,EDEND); break; case WINDOWA: TEbox_cursor(WhichBox(windowA),0); break; case WINDOWB: TEbox_cursor(WhichBox(windowB),0); break; case FOOTER1: objc_edit(footer,SBTTL1,0,&xpos,EDEND); break; case FOOTER2: objc_edit(footer,SBTTL2,0,&xpos,EDEND); break; } } Activate (item) int item; { switch (item) { case HEADER: objc_edit(header,TITLE,0,&xpos,EDINIT); break; case WINDOWA: TEbox_cursor(WhichBox(windowA),1); break; case WINDOWB: TEbox_cursor(WhichBox(windowB),1); break; case FOOTER1: objc_edit(footer,SBTTL1,0,&xpos,EDINIT); break; case FOOTER2: objc_edit(footer,SBTTL2,0,&xpos,EDINIT); break; } } Do_about () { Deactivate(active); form_alert(1,"[0][ CASSETTE LABEL MAKER |\ ½1987 David W. Douglass| | -public domain-][OK]"); Activate(active); } Cancel_setup (n) int n; { static char p[21],s1[13],s2[13],s3[13],s4[13],s5[13],s6[13]; int i; if (n == 0) { strcpy(&p,set0); strcpy(&s1,set1); strcpy(&s2,set2); strcpy(&s3,set3); strcpy(&s4,set4); strcpy(&s5,set5); strcpy(&s6,set6); } else { strcpy(set0,&p); strcpy(set1,&s1); strcpy(set2,&s2); strcpy(set3,&s3); strcpy(set4,&s4); strcpy(set5,&s5); strcpy(set6,&s6); } } Test_setup () { if (!Unhex(set1,&cpi5)) return(0); if (!Unhex(set2,&cpi6)) return(0); if (!Unhex(set3,&cpi85)) return(0); if (!Unhex(set4,&cpi10)) return(0); if (!Unhex(set5,&cpi12)) return(0); if (!Unhex(set6,&cpi17)) return(0); return(1); } Save_setup () { int handle; handle = Fopen("CASSLBL.PRG",1); if (handle >= 0) { graf_mouse(HOURGLASS,0); Fseek(0L,handle,0); /* OFFSET TO PRINTER NAME STRING */ Fwrite(handle,20L,set0); Fseek(46L,handle,1); Fwrite(handle,12L,set1); Fseek(30L,handle,1); Fwrite(handle,12L,set2); Fseek(30L,handle,1); Fwrite(handle,12L,set3); Fseek(30L,handle,1); Fwrite(handle,12L,set4); Fseek(30L,handle,1); Fwrite(handle,12L,set5); Fseek(30L,handle,1); Fwrite(handle,12L,set6); Fclose(handle); graf_mouse(ARROW,0); } else form_error(~handle+1); } Do_setup () { int x,y,w,h,button,ok; Deactivate(active); form_center(setup,&x,&y,&w,&h); pxyarray[0] = x; pxyarray[1] = y; pxyarray[2] = x+w+1; pxyarray[3] = y+h+1; pxyarray[4] = 0; pxyarray[5] = 0; pxyarray[6] = w+1; pxyarray[7] = h+1; v_hide_c(VDIhandle); vro_cpyfm(VDIhandle,S_ONLY,pxyarray,&VDIscr,&VDIbfr); form_dial(FMD_START,0,0,0,0,x,y,w,h); objc_draw(setup,ROOT,MAX_DEPTH,x,y,w,h); Cancel_setup(0); v_show_c(VDIhandle,0); do { button = form_do(setup,FIELD1); objc_change(setup,button,0,0,0,639,vmax,NORMAL,1); if (button == OK_BUTTON) { ok = Test_setup(); if (!ok) form_alert(0,"[3][ BAD HEX CODE! ][OK]"); else Save_setup(); } else { ok = 1; Cancel_setup(1); } } while (!ok); v_hide_c(VDIhandle); form_dial(FMD_FINISH,0,0,0,0,x,y,w,h); pxyarray[0] = 0; pxyarray[1] = 0; pxyarray[2] = w+1; pxyarray[3] = h+1; pxyarray[4] = x; pxyarray[5] = y; pxyarray[6] = x+w+1; pxyarray[7] = y+h+1; vro_cpyfm(VDIhandle,S_ONLY,pxyarray,&VDIbfr,&VDIscr); v_show_c(VDIhandle,0); Activate(active); } Length (str) char *str; { int n; for (n=0; *str!='\0'; str++) n++; return(n); } Print (str) char *str; { if (!pstat) return(0); for (; *str!='\0'; str++) if (!Cprnout((int)*str)) { pstat=0; return(0); } } PrintLF (str) char *str; { if (!pstat) return(0); Print(str); Print("\015\012"); } Setpitch (n) int n; { if (n <= 20) Print(&cpi5); if ((n>20) && (n<=24)) Print(&cpi6); if ((n>24) && (n<=34)) Print(&cpi85); if ((n>34) && (n<=40)) Print(&cpi10); if ((n>40) && (n<=48)) Print(&cpi12); if (n > 48) Print(&cpi17); } Center (n) int n; { int i,l; if (n <= 20) l = 20; if ((n>20) && (n<=24)) l = 24; if ((n>24) && (n<=34)) l = 34; if ((n>34) && (n<=40)) l = 40; if ((n>40) && (n<=48)) l = 48; if (n > 48) l = 68; for (i=0; i<((l-n)/2); ++i) Print(" "); } Do_print () { int i,j,l; char s[31]; char *a,*b; pstat = 1; l = Length(headstr); Setpitch(l); Center(l); PrintLF(headstr); Setpitch(40); PrintLF("========================================"); PrintLF("Side A Side B"); Setpitch(68); a = TEbox_get(WhichBox(windowA)); b = TEbox_get(WhichBox(windowB)); for (j=0; j<12; ++j) { Print(" "); for (i=0; i<30; ++i) s[i] = a[j*30+i]; s[30] = 0; Print(s); Print(" "); for (i=0; i<30; ++i) s[i] = b[j*30+i]; s[30] = 0; PrintLF(s); } PrintLF(" "); l = Length(footstr1); Setpitch(l); Center(l); PrintLF(footstr1); l = Length(footstr2); Setpitch(l); Center(l); PrintLF(footstr2); if (!pstat) form_alert(0,"[3][Printer is NOT|responding!][OK]"); } Do_keypress (key) int key; { int box; switch (active) { case HEADER: objc_edit(header,TITLE,key,&xpos,EDCHAR); break; case WINDOWA: box = WhichBox(windowA); TEbox_edit(box,key); break; case WINDOWB: box = WhichBox(windowB); TEbox_edit(box,key); break; case FOOTER1: objc_edit(footer,SBTTL1,key,&xpos,EDCHAR); break; case FOOTER2: objc_edit(footer,SBTTL2,key,&xpos,EDCHAR); break; } } Do_click (mouseX,mouseY) int mouseX,mouseY; { int choice,window,button,temp; do { vq_mouse(VDIhandle,&button,&temp,&temp); } while (button); choice = objc_find(header,ROOT,MAX_DEPTH,mouseX,mouseY); if (choice == TITLE) { Deactivate(active); active = HEADER; Activate(active); return(0); } choice = wind_find(mouseX,mouseY); if (choice == windowA) if (active == WINDOWA) TEbox_cursor(WhichBox(choice),2); else { Deactivate(active); active = WINDOWA; Activate(active); return(0); } if (choice == windowB) if (active == WINDOWB) TEbox_cursor(WhichBox(choice),2); else { Deactivate(active); active = WINDOWB; Activate(active); return(0); } choice = objc_find(footer,ROOT,MAX_DEPTH,mouseX,mouseY); if (choice == SBTTL1) { Deactivate(active); active = FOOTER1; Activate(active); return(0); } if (choice == SBTTL2) { Deactivate(active); active = FOOTER2; Activate(active); return(0); } choice = objc_find(options,ROOT,MAX_DEPTH,mouseX,mouseY); if (choice == CASSETTE) { objc_change(options,CASSETTE,0,330,47,32,16,1,1); Do_about(); objc_change(options,CASSETTE,0,330,47,32,16,0,1); return(0); } if (choice == SETUP_BUTTON) { objc_change(options,SETUP_BUTTON,0,0,0,639,vmax,0x11,1); Do_setup(); objc_change(options,SETUP_BUTTON,0,0,0,639,vmax,0,1); return(0); } if (choice == PRINT_BUTTON) { objc_change(options,PRINT_BUTTON,0,0,0,639,vmax,0x11,1); Do_print(); objc_change(options,PRINT_BUTTON,0,0,0,639,vmax,0,1); return(0); } if (choice == QUIT_BUTTON) { objc_change(options,QUIT_BUTTON,0,0,0,639,vmax,0x11,1); done = 1; return(0); } } Do_message (message,window) int message,window; { int top,temp; switch (message) { case WM_TOPPED: wind_get(0,WF_TOP,&top,&temp,&temp,&temp); if (top != window) { v_hide_c(VDIhandle); Deactivate(active); wind_set(window,WF_TOP,0,0,0,0); temp = WhichBox(window); TEbox_draw(temp); if (window == windowA) active = WINDOWA; else active = WINDOWB; TEbox_cursor(temp,1); v_show_c(VDIhandle,0); } break; } } Process () { int event,key,mouseX,mouseY,temp; static int msgbuff[8]; done = 0; while (!done) { event = evnt_multi(MU_TIMER|MU_MESAG|MU_BUTTON|MU_KEYBD,1,1,1, 0,0,0,0,0,0,0,0,0,0, &msgbuff,500,0, &mouseX,&mouseY,&temp, &temp,&key,&temp); if (event & MU_TIMER) TEbox_blink(); if (event & MU_MESAG) Do_message(msgbuff[0],msgbuff[3]); if (event & MU_BUTTON) Do_click(mouseX,mouseY); if (event & MU_KEYBD) Do_keypress(key); } } Screen_exit () { Mfree(VDIbfr.fd_addr); Deactivate(active); wind_close(windowA); wind_delete(windowA); wind_close(windowB); wind_delete(windowB); } main () { Bind_objects(); appl_init(); GEM_init(); Screen_init(); if (!vres) form_alert(1,"[3][ |MED/HI RES|ONLY!][OK]"); else { Object_init(); Print_init(); Process(); Screen_exit(); } v_clsvwk(VDIhandle); appl_exit(); }