--- title: "MacPaint File Printing" type: "article" slug: "macpaint-file-printing" url: "http://localhost/article/macpaint-file-printing/" markdown_url: "http://localhost/article/macpaint-file-printing.md" published_at: "2025-11-27T13:44:53+00:00" modified_at: "2026-06-21T23:23:48+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Don Walterman has sent a program that reads a MacPaint file and prints to an HP Deskjet printer. Don claims that this is his first C program. If so, it's very ambitious. Don did not send an article describing his program, so I'll present it as is. For formatting reasons, comments are below the lines…" category: - name: "QL Hacker's Journal" slug: "ql-hackers-journal" taxonomy: "category" url: "http://localhost/category/periodicals/ql-hackers-journal/" post_tag: - name: "C (programming language)" slug: "c-programming-language" taxonomy: "post_tag" url: "http://localhost/tag/c-programming-language/" - name: "Full Text" slug: "fulltext" taxonomy: "post_tag" url: "http://localhost/tag/fulltext/" - name: "QL" slug: "ql" taxonomy: "post_tag" url: "http://localhost/tag/ql/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Cambridge Z88" slug: "cambridge-z88" taxonomy: "model" url: "http://localhost/model/cambridge-z88/" - name: "Sinclair QL" slug: "sinclair-ql" taxonomy: "model" url: "http://localhost/model/sinclair-ql/" indiv: - name: "Don Walterman" slug: "don-walterman" taxonomy: "indiv" url: "http://localhost/indiv/don-walterman/" publication_r: id: 33686 title: "QL Hacker’s Journal" type: "periodical" url: "http://localhost/periodical/ql-hackers-journal/" authors_r: - name: "Don Walterman" slug: "don-walterman" taxonomy: "indiv" url: "http://localhost/indiv/don-walterman/" issue: "12" issues_articles: - id: 61548 title: "QL Hacker’s Journal 12" type: "issue" url: "http://localhost/issue/ql-hackers-journal-12/" pubdate: "January 1993" archive_link: true --- # MacPaint File Printing Don Walterman has sent a program that reads a MacPaint file and prints to an HP Deskjet printer. Don claims that this is his first C program. If so, it’s very ambitious. Don did not send an article describing his program, so I’ll present it as is. For formatting reasons, comments are below the lines that they apply to. I’ve inserted ^’s to emphasize the point. ``` /* Print_Mac305_c Author: Don Walterman */ char _PROG_NAME[] = "Print Mac"; #include #include #define ESC 27 #define FF 12 char macfile_name[50],answer,i; unsigned short int bits,repeat_count,single_count,byte; unsigned short int dot_column,single_byte,line_count; long tty_wait = 0; FILE *mac_file, *printer; main() { if((tty_wait = isatty( fileno( stdout ))) && !isnoclose( fileno(stdout ))) { struct QLRECT rect; rect.q_width = 512; rect.q_height =200; rect.q_x = rect.q_y = 0; tty_wait = getchid( fileno(stdout) ); sd_wdef( tty_wait, -1, RED_M4, 1, &rect); sd_clear( tty_wait, -1); } printf("Enter the readmac file to print \n(including the device name). "); scanf("%s" , macfile_name); if ((mac_file = fopen(macfile_name,"r")) == NULL) { puts("\ncan't find file...please check disk and try again\n "); printf("System error returned..... %d %s", _oserr," \n"); if(tty_wait) { printf("Press any key to continue\n"); io_fbyte( tty_wait, -1, &i); } main(); } fseek(mac_file,640,SEEK_SET); /* ^ set file pointer to start of picture data */ printer = fopen("SER1","w"); /* ^ open SER1_ for printing */ fprintf(printer,"%c%s", ESC, "*b0M"); /* ^ select full graphics mode */ fprintf(printer,"%c%s", ESC,"*t75R"); /* ^ select 75 dpi resolution */ fprintf(printer,"%c%s", ESC,"&a0C"); /* ^ set printer's cursor to leftmost position */ fprintf(printer,"%c%s", ESC,"&a+112H"); /* ^ center the image on the page */ fprintf(printer,"%c%s", ESC,"*r1A"); /* ^ start printing at current printer(cursor) position */ dot_column = 0; line_count = 0; fprintf(printer,"%c%s", ESC,"*b72W"); /* ^ print 576 dots per line (standard Mac screen width) */ /* 72 dot_columns x 8 bits per dot_column */ do { byte = fgetc(mac_file); if (byte > 184 && byte < 256) { repeat_count = 257 - byte; byte = fgetc(mac_file); do { fputc(byte , printer); /* ^ this routine prints out the repeating data bytes */ dot_column++; /* ^ the first byte tells how many times to repeat the */ if(dot_column > 71) /* ^ next byte */ { fprintf(printer,"%c%s", ESC,"*b72W"); dot_column = 0; line_count++; update(); } --repeat_count; } while (repeat_count > 0); } else { /* ^ this routine prints out the non-repeating */ if (byte < 128) /* ^ graphics bytes. the first byte tells how many */ { /* non-repeating bytes follow */ single_count = 0; do { single_byte = fgetc(mac_file); fputc(single_byte , printer); dot_column++; if(dot_column > 71) { fprintf(printer,"%c%s", ESC,"*b72W"); dot_column = 0; line_count++; update(); } single_count++; } while(single_count < (byte+1)); } } } while(!feof(mac_file) && (line_count < 720)); /* ^ jump out at end of file */ /* the screen is 720 lines so skip the garbage */ if(dot_column < 72) /* ^ the file may have appended from the file transfer */ { do { /* ^ this routine finishes off whatever graphics */ byte = 0; /* ^ line is started so that the next two commands */ fputc(byte , printer); /* ^ are not mistaken for graphics data */ dot_column++; } while(dot_column < 72); } fprintf(printer,"%c%s", ESC,"*rB"); /* ^ tell DeskJet end of graphics data */ fprintf(printer,"%c", FF); fclose(printer); fclose(mac_file); printf("\nPrint another Readmac file ? "); if(getchar() == 89 | getchar() == 121) /* ^ if 'y' or 'Y' start over */ { main(); } } update() { sd_pixp( tty_wait, -1,10,20); printf("printing line %d %s", line_count, "of 720 lines....\n"); } ```