From b62b14b3922e4223bf073d92d609712ab2613ac4 Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Sun, 9 Jan 2011 23:19:39 +0000 Subject: [PATCH] Let everyone print text. This is a particularly bad hack of the printer code, with ifdefs all over printer.cpp for SDL. I removed HAVE_PARALLEL, since every one has it now; but HAVE_SDL is now a switch that defines if a platform has the graphics library available instead. --- src/Makefile | 7 +++--- src/moremem.c | 8 ------ src/printer.cpp | 42 +++++++++++++++++++++++++++++--- src/printer.h | 65 ++++++++++++++++++++++++++++++++++--------------- src/sim65816.c | 8 ------ 5 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/Makefile b/src/Makefile index fce5ab7..d4dc278 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,9 @@ # GSport central makefile - you need a 'vars' file linked/copied from a 'vars_xxx' template to build. OBJECTS1 = adb.o clock.o config.o dis.o engine_c.o scc.o iwm.o \ - joystick_driver.o moremem.o paddles.o sim65816.o smartport.o \ - sound.o sound_driver.o video.o scc_socket_driver.o + joystick_driver.o moremem.o paddles.o parallel.o printer.o \ + sim65816.o smartport.o sound.o sound_driver.o video.o \ + scc_socket_driver.o include vars @@ -31,7 +32,7 @@ specials_clean: # Mac builds: gsportmac: $(OBJECTS) compile_time.o - $(CC) $(CCOPTS) $(LDOPTS) -arch $(ARCH) $(OBJECTS) compile_time.o $(LDFLAGS) -o gsport $(EXTRA_LIBS) -prebind -framework Carbon -framework Quicktime + g++ $(CCOPTS) $(LDOPTS) -arch $(ARCH) $(OBJECTS) compile_time.o $(LDFLAGS) -o gsport $(EXTRA_LIBS) -prebind -framework Carbon -framework Quicktime mkdir -p ../GSport.app/Contents/Resources/English.lproj/main.nib mkdir -p ../GSport.app/Contents/MacOS mv gsport ../GSport.app/Contents/MacOS/GSport diff --git a/src/moremem.c b/src/moremem.c index f3933cc..14604ae 100644 --- a/src/moremem.c +++ b/src/moremem.c @@ -1594,7 +1594,6 @@ io_read(word32 loc, double *cyc_ptr) case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: -#ifdef HAVE_PARALLEL if (g_parallel) { return parallel_read((word16)loc & 0xf); @@ -1603,9 +1602,6 @@ io_read(word32 loc, double *cyc_ptr) { UNIMPL_READ; } -#else - UNIMPL_READ; -#endif /* 0xc0a0 - 0xc0af */ case 0xa0: case 0xa1: case 0xa2: case 0xa3: @@ -2333,7 +2329,6 @@ io_write(word32 loc, int val, double *cyc_ptr) case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: -#ifdef HAVE_PARALLEL if (g_parallel) { return parallel_write((word16)loc & 0xf, (byte)val); @@ -2342,9 +2337,6 @@ io_write(word32 loc, int val, double *cyc_ptr) { UNIMPL_WRITE; } -#else - UNIMPL_WRITE; -#endif /* 0xc0a0 - 0xc0af */ case 0xa0: case 0xa1: case 0xa3: diff --git a/src/printer.cpp b/src/printer.cpp index 500519f..8576a40 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -76,6 +76,7 @@ Bit8u paramc = '0'; #include "printer_charmaps.h" +#ifdef HAVE_SDL void CPrinter::FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u colorID, SDL_Palette* pal) { float red=redmax/30.9; @@ -90,9 +91,11 @@ void CPrinter::FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u co pal->colors[i+colormask].b=255-(blue*(float)i); } } +#endif // HAVE_SDL CPrinter::CPrinter(Bit16u dpi, Bit16u width, Bit16u height, char* output, bool multipageOutput) { +#ifdef HAVE_SDL if (FT_Init_FreeType(&FTlib)) { page = NULL; @@ -186,19 +189,27 @@ CPrinter::CPrinter(Bit16u dpi, Bit16u width, Bit16u height, char* output, bool m PrintDlg(&pd); // TODO: what if user presses cancel? printerDC = pd.hDC; -#endif +#endif // WIN32 } } +#endif // HAVE_SDL +#ifndef HAVE_SDL + this->output = output; + this->multipageOutput = multipageOutput; +#endif // !HAVE_SDL }; void CPrinter::resetPrinterHard() { +#ifdef HAVE_SDL charRead = false; resetPrinter(); +#endif // HAVE_SDL } void CPrinter::resetPrinter() { +#ifdef HAVE_SDL color=COLOR_BLACK; curX = curY = 0.0; ESCSeen = false; @@ -235,7 +246,9 @@ void CPrinter::resetPrinter() updateFont(); +#endif // HAVE_SDL newPage(false,true); +#ifdef HAVE_SDL // Default tabs => Each eight characters for (Bitu i=0;i<32;i++) @@ -243,11 +256,13 @@ void CPrinter::resetPrinter() numHorizTabs = 32; numVertTabs = 255; +#endif // HAVE_SDL } CPrinter::~CPrinter(void) { +#ifdef HAVE_SDL finishMultipage(); if (page != NULL) { @@ -255,11 +270,13 @@ CPrinter::~CPrinter(void) page = NULL; FT_Done_FreeType(FTlib); } +#endif // HAVE_SDL #if defined (WIN32) DeleteDC(printerDC); #endif }; +#ifdef HAVE_SDL void CPrinter::selectCodepage(Bit16u cp) { Bit16u *mapToUse = NULL; @@ -314,7 +331,9 @@ void CPrinter::selectCodepage(Bit16u cp) for (int i=0; i<256; i++) curMap[i] = mapToUse[i]; } +#endif // HAVE_SDL +#ifdef HAVE_SDL void CPrinter::updateFont() { // char buffer[1000]; @@ -432,7 +451,9 @@ void CPrinter::updateFont() FT_Set_Transform(curFont, &matrix, 0); } } +#endif HAVE_SDL +#ifdef HAVE_SDL bool CPrinter::processCommandChar(Bit8u ch) { if (ESCSeen || FSSeen) @@ -1244,14 +1265,16 @@ bool CPrinter::processCommandChar(Bit8u ch) return false; } +#endif // HAVE_SDL -static void PRINTER_EventHandler(Bitu param); +//static void PRINTER_EventHandler(Bitu param); void CPrinter::newPage(bool save, bool resetx) { //PIC_RemoveEvents(PRINTER_EventHandler); if(printer_timout) timeout_dirty=false; +#ifdef HAVE_SDL if (save) outputPage(); @@ -1269,6 +1292,7 @@ void CPrinter::newPage(bool save, bool resetx) { *((Bit8u*)page->pixels+i)=i; }*/ +#endif // HAVE_SDL if (strcasecmp(output, "text") == 0) { /* Text file */ if (textPrinterFile) { fclose(textPrinterFile); @@ -1279,8 +1303,11 @@ void CPrinter::newPage(bool save, bool resetx) void CPrinter::printChar(Bit8u ch) { +#ifdef HAVE_SDL + charRead = true; if (page == NULL) return; +#endif // HAVE_SDL // Don't think that DOS programs uses this but well: Apply MSB if desired if (msb != 255) { if (msb == 0) ch &= 0x7F; @@ -1294,6 +1321,8 @@ void CPrinter::printChar(Bit8u ch) fflush(textPrinterFile); return; } +#ifdef HAVE_SDL + // Are we currently printing a bit graphic? if (bitGraph.remBytes > 0) { printBitGraph(ch); @@ -1382,8 +1411,10 @@ void CPrinter::printChar(Bit8u ch) curY += lineSpacing; if (curY > bottomMargin) newPage(true,false); } +#endif // HAVE_SDL } +#ifdef HAVE_SDL void CPrinter::blitGlyph(FT_Bitmap bitmap, Bit16u destx, Bit16u desty, bool add) { for (Bitu y=0; ypixels + (num % page->w) + ((num / page->w) * page->pitch)); return *((Bit8u*)page->pixels + (num % page->w) + ((num / page->w) * page->pitch)); } +#endif // HAVE_SDL //Interfaces to C code diff --git a/src/printer.h b/src/printer.h index 7bf7812..dee8e62 100644 --- a/src/printer.h +++ b/src/printer.h @@ -1,3 +1,24 @@ +/* + GSport - an Apple //gs Emulator + Copyright (C) 2010 - 2011 by GSport contributors + + Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + /* * Copyright (C) 2002-2004 The DOSBox Team * @@ -19,8 +40,6 @@ //#include //#include "config.h" - - #if !defined __PRINTER_H #define __PRINTER_H #ifdef __cplusplus @@ -28,10 +47,12 @@ #include #endif +#ifdef HAVE_SDL #include "SDL.h" #include #include FT_FREETYPE_H +#endif #if defined (WIN32) #include @@ -129,28 +150,37 @@ public: // Manual formfeed void formFeed(); +#ifdef HAVE_SDL // Returns true if the current page is blank bool isBlank(); +#endif // HAVE_SDL private: - // used to fill the color "sub-pallettes" - void FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u colorID, - SDL_Palette* pal); - - // Checks if given char belongs to a command and process it. If false, the character - // should be printed - bool processCommandChar(Bit8u ch); - // Resets the printer to the factory settings void resetPrinter(); - // Reload font. Must be called after changing dpi, style or cpi - void updateFont(); - // Clears page. If save is true, saves the current page to a bitmap void newPage(bool save, bool resetx); + // Closes a multipage document + void finishMultipage(); + + // Output current page + void outputPage(); + +#ifdef HAVE_SDL + // used to fill the color "sub-pallettes" + void FillPalette(Bit8u redmax, Bit8u greenmax, Bit8u bluemax, Bit8u colorID, + SDL_Palette* pal); + + // Checks if given char belongs to a command and process it. If false, the character + // should be printed + bool processCommandChar(Bit8u ch); + + // Reload font. Must be called after changing dpi, style or cpi + void updateFont(); + // Blits the given glyph on the page surface. If add is true, the values of bitmap are // added to the values of the pixels in the page void blitGlyph(FT_Bitmap bitmap, Bit16u destx, Bit16u desty, bool add); @@ -167,15 +197,9 @@ private: // Copies the codepage mapping from the constant array to CurMap void selectCodepage(Bit16u cp); - // Output current page - void outputPage(); - // Prints out a byte using ASCII85 encoding (only outputs something every four bytes). When b>255, closes the ASCII85 string void fprintASCII85(FILE* f, Bit16u b); - // Closes a multipage document - void finishMultipage(); - // Returns value of the num-th pixel (couting left-right, top-down) in a safe way Bit8u getPixel(Bit32u num); @@ -251,6 +275,9 @@ private: HDC printerDC; // Win32 printer device #endif +#endif // HAVE_SDL + Bit8u msb; // MSB mode + char* output; // Output method selected by user void* outputHandle; // If not null, additional pages will be appended to the given handle bool multipageOutput; // If true, all pages are combined to one file/print job etc. until the "eject page" button is pressed diff --git a/src/sim65816.c b/src/sim65816.c index 17ce1bd..c377846 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -26,9 +26,7 @@ #include "tfe/tfesupp.h" #include "tfe/protos_tfe.h" #endif -#ifdef HAVE_PARALLEL #include "printer.h" -#endif #ifdef UNDER_CE #define vsnprintf _vsnprintf @@ -719,9 +717,7 @@ void quitEmulator() void my_exit(int ret) { end_screen(); -#ifdef HAVE_PARALLEL printer_close(); -#endif printf("exiting (ret=%d)\n",ret); fatalExit(ret); } @@ -1061,9 +1057,7 @@ gsportmain(int argc, char **argv) // If the final argument was not a switch, then treat it like a disk image filename to insert if (final_arg) cfg_inspect_maybe_insert_file(final_arg); -#ifdef HAVE_PARALLEL printer_init(g_printer_dpi,85,110,g_printer_output,g_printer_multipage); -#endif //If ethernet is enabled in config.gsport, lets initialize it #ifdef HAVE_TFE if (g_ethernet == 1) @@ -2346,13 +2340,11 @@ update_60hz(double dcycs, double dtime_now) sound_update(dcycs); clock_update(); scc_update(dcycs); - #ifdef HAVE_PARALLEL //Check and see if virtual printer timeout has been reached. if (g_printer_timeout) { printer_update(); } - #endif paddle_update_buttons(); }