From: Toni Wilen Date: Sat, 3 Apr 2010 15:23:17 +0000 (+0300) Subject: 2100b20 X-Git-Tag: 2100~8 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=9e4a0b5d94278e4f6da72eb51c524d0120d1bc91;p=francis%2Fwinuae.git 2100b20 --- diff --git a/akiko.cpp b/akiko.cpp index 3724215e..0c4a252f 100644 --- a/akiko.cpp +++ b/akiko.cpp @@ -1675,6 +1675,7 @@ void akiko_reset (void) akiko_thread_running = 0; } akiko_cdrom_free (); + mediacheckcounter = 0; } diff --git a/cfgfile.cpp b/cfgfile.cpp index 6b58f433..46840a62 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -1837,7 +1837,7 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, TCHAR *option, TCHAR *va } if (strcasecmp (option, L"quickstart") == 0) { - int model = -1; + int model = 0; TCHAR *tmpp = _tcschr (value, ','); if (tmpp) { *tmpp++ = 0; diff --git a/cia.cpp b/cia.cpp index 3109ab77..01cf41e4 100644 --- a/cia.cpp +++ b/cia.cpp @@ -643,7 +643,7 @@ static uae_u8 ReadCIAA (unsigned int addr) #endif } else if (currprefs.win32_samplersoundcard >= 0) { - tmp = sampler_getsample (); + tmp = sampler_getsample ((ciabpra & 4) ? 1 : 0); } else #endif diff --git a/custom.cpp b/custom.cpp index 185900fb..92635675 100644 --- a/custom.cpp +++ b/custom.cpp @@ -5066,6 +5066,8 @@ static void vsync_handler (void) } if ((beamcon0 & (0x20 | 0x80)) != (new_beamcon0 & (0x20 | 0x80)) || (abs (vpos_count - vpos_count_prev) > 1)) init_hz (); + if (lof_changed) + compute_vsynctime (); vpos_count_prev = vpos_count; lof_changed = 0; diff --git a/epsonprinter.cpp b/epsonprinter.cpp index 2afd205f..9b4f2c37 100644 --- a/epsonprinter.cpp +++ b/epsonprinter.cpp @@ -18,41 +18,50 @@ /* * Converted to WinUAE by Toni Wilen 2009 +* +* Freetype to Win32 CreateFont() conversion by TW in 2010 */ #include "sysconfig.h" #include "sysdeps.h" #include "uae.h" -#ifndef CPU_64_BIT - +#define WINFONT #define C_LIBPNG -#define FREETYPE2_STATIC #include "epsonprinter.h" #include "win32.h" #include "parser.h" +#include "threaddep/thread.h" #include +//#define DEBUGPRINT +static int pngprint = 0; + #ifdef C_LIBPNG #include #endif #define PARAM16(I) (params[I+1]*256+params[I]) -#define PIXX ((Bitu)floor(curX*dpi+0.5)) -#define PIXY ((Bitu)floor(curY*dpi+0.5)) +#define PIXX ((Bitu)floor(curX*dpiX+0.5)) +#define PIXY ((Bitu)floor(curY*dpiY+0.5)) #define true 1 #define false 0 -static Bit16u confdpi, confwidth, confheight; -static TCHAR confoutputDevice[50]; -static int confmultipageOutput; +#ifdef WINFONT +static HFONT curFont; +static float curFontHorizPoints, curFontVertPoints; +static TCHAR *curFontName; +static HDC memHDC; +static LPOUTLINETEXTMETRIC otm; +#else static FT_Library FTlib; static FT_Face curFont; +#endif static Real64 curX, curY; -static Bit16u dpi, ESCCmd; +static Bit16u dpiX, dpiY, ESCCmd; static int ESCSeen; static Bit8u numParam, neededParam; static Bit8u params[20]; @@ -83,10 +92,13 @@ static int multipoint; static Real64 multiPointSize, multicpi, hmi; static Bit8u msb; static Bit16u numPrintAsChar; -static TCHAR *output; static void *outputHandle; static Bit16u multipageOutput, multiPageCounter; static HDC printerDC; +static int justification; +#define CHARBUFFERSIZE 1000 +static int charcnt; +static Bit8u charbuffer[CHARBUFFERSIZE]; static uae_u8 *page; static int page_w, page_h, page_pitch; @@ -94,6 +106,9 @@ static int pagesize; static HMODULE ft; static int pins = 24; +static void printCharBuffer(void); + + // Various ASCII codepage to unicode maps static const Bit16u cp437Map[256] = { @@ -388,53 +403,53 @@ static const Bit16u intCharSets[15][12] = static void selectCodepage(Bit16u cp) { int i; - Bit16u *mapToUse = NULL; + const Bit16u *mapToUse = NULL; switch(cp) { case 0: // Italics, use cp437 case 437: - mapToUse = (Bit16u*)&cp437Map; + mapToUse = cp437Map; break; case 737: - mapToUse = (Bit16u*)&cp737Map; + mapToUse = cp737Map; break; case 775: - mapToUse = (Bit16u*)&cp775Map; + mapToUse = cp775Map; break; case 850: - mapToUse = (Bit16u*)&cp850Map; + mapToUse = cp850Map; break; case 852: - mapToUse = (Bit16u*)&cp852Map; + mapToUse = cp852Map; break; case 855: - mapToUse = (Bit16u*)&cp855Map; + mapToUse = cp855Map; break; case 857: - mapToUse = (Bit16u*)&cp857Map; + mapToUse = cp857Map; break; case 860: - mapToUse = (Bit16u*)&cp860Map; + mapToUse = cp860Map; break; case 861: - mapToUse = (Bit16u*)&cp861Map; + mapToUse = cp861Map; break; case 863: - mapToUse = (Bit16u*)&cp863Map; + mapToUse = cp863Map; break; case 864: - mapToUse = (Bit16u*)&cp864Map; + mapToUse = cp864Map; break; case 865: - mapToUse = (Bit16u*)&cp865Map; + mapToUse = cp865Map; break; case 866: - mapToUse = (Bit16u*)&cp866Map; + mapToUse = cp866Map; break; default: write_log(L"Unsupported codepage %i. Using CP437 instead.\n", cp); - mapToUse = (Bit16u*)&cp437Map; + mapToUse = cp437Map; } for (i=0; i<256; i++) @@ -442,37 +457,108 @@ static void selectCodepage(Bit16u cp) } +static int selectfont(Bit16u style) +{ + static TCHAR *thisFontName; + static float thisFontHorizPoints; + static float thisFontVertPoints; + static Bit16u thisStyle; + + if (curFont) { + for (;;) { + if (thisFontName != curFontName) + break; + if (thisFontHorizPoints != curFontHorizPoints) + break; + if (thisFontVertPoints != curFontVertPoints) + break; + if (thisStyle != style) + break; + // still using same font + return 1; + } + DeleteObject (curFont); + curFont = NULL; + xfree (thisFontName); + thisFontName = NULL; + xfree (otm); + otm = NULL; + } + thisFontHorizPoints = curFontHorizPoints; + thisFontVertPoints = curFontVertPoints; + thisStyle = style; + thisFontName = curFontName; + + int ly = GetDeviceCaps (memHDC, LOGPIXELSY); + int lx = GetDeviceCaps (memHDC, LOGPIXELSX); + int rounds = 0; + while (rounds < 2) { + curFont = CreateFont (thisFontVertPoints * dpiY / ly + 0.5, thisFontHorizPoints * dpiX / lx + 0.5, + 0, 0, + FW_NORMAL, + (style & STYLE_ITALICS) ? TRUE : FALSE, + FALSE, + FALSE, + DEFAULT_CHARSET, + OUT_TT_PRECIS, + CLIP_DEFAULT_PRECIS, + PROOF_QUALITY, + ((style & STYLE_PROP) ? VARIABLE_PITCH : FIXED_PITCH) | FF_DONTCARE, + thisFontName); + if (curFont) + break; + rounds++; + if (style & STYLE_PROP) + thisFontName = curFontName = L"Times New Roman"; + else + thisFontName = curFontName = L"Courier New"; + } + if (curFont) { + SelectObject (memHDC, curFont); + int size = GetOutlineTextMetrics (memHDC, 0, NULL); + if (size > 0) { + otm = (LPOUTLINETEXTMETRIC)xmalloc (uae_u8, size); + GetOutlineTextMetrics (memHDC, size, otm); + } + } + return curFont ? 1 : 0; +} + static void updateFont(void) { Real64 horizPoints = 10.5; Real64 vertPoints = 10.5; - char* fontName; + TCHAR *fontName; if (curFont != NULL) +#ifdef WINFONT + DeleteObject (curFont); +#else FT_Done_Face(curFont); +#endif + curFont = NULL; + int prop = style & STYLE_PROP; switch (LQtypeFace) { case roman: - fontName = "roman.ttf"; + default: + if (prop) + fontName = L"Times New Roman"; + else + fontName = L"Courier New"; break; case sansserif: - fontName = "sansserif.ttf"; - break; - case courier: - fontName = "courier.ttf"; - break; - case script: - fontName = "script.ttf"; - break; - case ocra: - case ocrb: - fontName = "ocra.ttf"; + if (prop) + fontName = L"Arial"; + else + fontName = L"Lucida Console"; break; - default: - fontName = "roman.ttf"; } +#ifdef WINFONT + curFontName = fontName; +#else if (!ft) { write_log(L"EPSONPRINTER: No freetype6.dll, unable to load font %s\n", fontName); curFont = NULL; @@ -492,7 +578,7 @@ static void updateFont(void) } } } - +#endif if (!multipoint) { actcpi = cpi; @@ -548,12 +634,17 @@ static void updateFont(void) actcpi /= (Real64)2/(Real64)3; } - +#ifdef WINFONT + curFontHorizPoints = horizPoints; + curFontVertPoints = vertPoints; +#else if (curFont) - FT_Set_Char_Size(curFont, (Bit16u)horizPoints*64, (Bit16u)vertPoints*64, dpi, dpi); + FT_Set_Char_Size(curFont, (Bit16u)horizPoints*64, (Bit16u)vertPoints*64, dpiX, dpiY); +#endif if (style & STYLE_ITALICS || charTables[curCharTable] == 0) { +#ifndef WINFONT FT_Matrix matrix; matrix.xx = 0x10000L; matrix.xy = (FT_Fixed)(0.20 * 0x10000L); @@ -561,6 +652,7 @@ static void updateFont(void) matrix.yy = 0x10000L; if (curFont) FT_Set_Transform(curFont, &matrix, 0); +#endif } } @@ -580,86 +672,77 @@ static void getfname (TCHAR *fname) } } -static void outputPage(void) +static int volatile prt_thread_mode; + +static void *prt_thread (void *p) { Bit16u x, y; - - if (strcasecmp(output, L"printer") == 0) + HDC TprinterDC = printerDC; + HDC TmemHDC = memHDC; + int Tpage_w = page_w; + int Tpage_h = page_h; + int Tpage_pitch = page_pitch; + uae_u8 *Tpage = page; + + write_log (L"EPSONPRINTER: background print thread started\n"); + prt_thread_mode = 1; + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_BELOW_NORMAL); + + if (TprinterDC) { -#if defined (WIN32) - Bit16u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH); - Bit16u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT); - HDC memHDC; - HBITMAP bitmap; - - Real64 scaleW, scaleH; - Bit32u topX, topY; - - if (page_w > physW) - scaleW = (Real64)page_w / (Real64)physW; - else - scaleW = (Real64)physW / (Real64)page_w; + int hz = GetDeviceCaps (TprinterDC, PHYSICALWIDTH); + int vz = GetDeviceCaps (TprinterDC, PHYSICALHEIGHT); + int topmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETX); + int leftmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETY); - if (page_h > physH) - scaleH = (Real64)page_h / (Real64)physH; - else - scaleH = (Real64)physH / (Real64)page_h; + write_log (L"EPSONPRINTER: HP=%d WP=%d TM=%d LM=%d W=%d H=%d\n", + hz, vz, topmargin, leftmargin, Tpage_w, Tpage_h); - memHDC = CreateCompatibleDC(printerDC); - bitmap = CreateCompatibleBitmap(memHDC, page_w, page_h); - SelectObject(memHDC, bitmap); + HBITMAP bitmap = CreateCompatibleBitmap (memHDC, Tpage_w, Tpage_h); + SelectObject (TmemHDC, bitmap); + BitBlt (TmemHDC, 0, 0, Tpage_w, Tpage_h, NULL, 0, 0, WHITENESS); // Start new printer job? if (outputHandle == NULL) { DOCINFO docinfo; - docinfo.cbSize = sizeof(docinfo); - docinfo.lpszDocName = L"WinUAE Printer"; + docinfo.cbSize = sizeof (docinfo); + docinfo.lpszDocName = L"WinUAE Epson Printer"; docinfo.lpszOutput = NULL; docinfo.lpszDatatype = NULL; docinfo.fwType = 0; - StartDoc(printerDC, &docinfo); + StartDoc (TprinterDC, &docinfo); multiPageCounter = 1; } - StartPage(printerDC); + StartPage (TprinterDC); - for (y=0; y Each eight characters - for (i=0;i<32;i++) - horiztabs[i] = i*8*(1/(Real64)cpi); + for (i = 0; i < 32; i++) + horiztabs[i] = i * 8 * (1.0 / (Real64)cpi); numHorizTabs = 32; numVertTabs = 255; @@ -794,85 +899,105 @@ static void resetPrinter(void) static void resetPrinterHard(void) { charRead = false; - resetPrinter(); + initPrinter(); } -static int printer_init(Bit16u dpi2, Bit16u width, Bit16u height, TCHAR* output2, int multipageOutput2, int numpins) +static int printer_init(Bit16u dpi2, Bit16u width, Bit16u height, const TCHAR *printername, int multipageOutput2, int numpins) { pins = numpins; +#ifndef WINFONT if (ft == NULL || FT_Init_FreeType(&FTlib)) { write_log(L"EPSONPRINTER: Unable to init Freetype2. ASCII printing disabled\n"); + return 0; } - { - Bitu i; - dpi = dpi2; - output = output2; - multipageOutput = multipageOutput2; - - defaultPageWidth = (Real64)width/(Real64)10; - defaultPageHeight = (Real64)height/(Real64)10; - - // Create page - page_w = (Bitu)(defaultPageWidth*dpi); - page_h = (Bitu)(defaultPageHeight*dpi); - pagesize = page_w * page_h; - page_pitch = page_w; - page = xcalloc (uae_u8, pagesize); - curFont = NULL; - charRead = false; - autoFeed = false; - outputHandle = NULL; +#endif + dpiX = dpiY = dpi2; + multipageOutput = multipageOutput2; - resetPrinter(); + defaultPageWidth = (Real64)width/(Real64)10; + defaultPageHeight = (Real64)height/(Real64)10; - if (strcasecmp(output, L"printer") == 0) - { -#if defined (WIN32) - // Show Print dialog to obtain a printer device context - - PRINTDLG pd; - pd.lStructSize = sizeof(PRINTDLG); - pd.hDevMode = (HANDLE) NULL; - pd.hDevNames = (HANDLE) NULL; - pd.Flags = PD_RETURNDC; - pd.hwndOwner = NULL; - pd.hDC = (HDC) NULL; - pd.nFromPage = 1; - pd.nToPage = 1; - pd.nMinPage = 0; - pd.nMaxPage = 0; - pd.nCopies = 1; - pd.hInstance = NULL; - pd.lCustData = 0L; - pd.lpfnPrintHook = (LPPRINTHOOKPROC) NULL; - pd.lpfnSetupHook = (LPSETUPHOOKPROC) NULL; - pd.lpPrintTemplateName = (LPWSTR) NULL; - pd.lpSetupTemplateName = (LPWSTR) NULL; - pd.hPrintTemplate = (HANDLE) NULL; - pd.hSetupTemplate = (HANDLE) NULL; - PrintDlg(&pd); - printerDC = pd.hDC; + if (printername) + { +#if 0 + // Show Print dialog to obtain a printer device context + PRINTDLG pd; + pd.lStructSize = sizeof(PRINTDLG); + pd.hDevMode = (HANDLE) NULL; + pd.hDevNames = (HANDLE) NULL; + pd.Flags = PD_RETURNDC; + pd.hwndOwner = NULL; + pd.hDC = (HDC) NULL; + pd.nFromPage = 1; + pd.nToPage = 1; + pd.nMinPage = 0; + pd.nMaxPage = 0; + pd.nCopies = 1; + pd.hInstance = NULL; + pd.lCustData = 0L; + pd.lpfnPrintHook = (LPPRINTHOOKPROC) NULL; + pd.lpfnSetupHook = (LPSETUPHOOKPROC) NULL; + pd.lpPrintTemplateName = (LPWSTR) NULL; + pd.lpSetupTemplateName = (LPWSTR) NULL; + pd.hPrintTemplate = (HANDLE) NULL; + pd.hSetupTemplate = (HANDLE) NULL; + PrintDlg(&pd); + printerDC = pd.hDC; #endif - } + printerDC = CreateDC (NULL, printername, NULL, NULL); + if (!printerDC) + return 0; + + dpiX = GetDeviceCaps(printerDC, LOGPIXELSX); + dpiY = GetDeviceCaps(printerDC, LOGPIXELSY); + defaultPageWidth = (Real64)GetDeviceCaps(printerDC, HORZRES) / dpiX; + defaultPageHeight = (Real64)GetDeviceCaps(printerDC, VERTRES) / dpiY; } + + // Create page + page_w = (Bitu)(defaultPageWidth*dpiX); + page_h = (Bitu)(defaultPageHeight*dpiY); + pagesize = page_w * page_h; + page_pitch = page_w; + page = xcalloc (uae_u8, pagesize); + curFont = NULL; + charRead = false; + autoFeed = false; + outputHandle = NULL; + write_log (L"EPSONPRINTER: Page size: %dx%d DPI: %dx%d\n", + page_w, page_h, dpiX, dpiY); + + initPrinter(); + + memHDC = CreateCompatibleDC (NULL); + return 1; }; static void printer_close(void) { - if (page != NULL) - { + if (page != NULL) { xfree (page); page = NULL; +#ifndef WINFONT if (ft) FT_Done_FreeType(FTlib); +#endif write_log (L"EPSONPRINTER: end\n"); } -#if defined (WIN32) - DeleteDC(printerDC); -#endif + xfree (otm); + otm = NULL; + if (curFont) + DeleteObject (curFont); + curFont = NULL; + if (printerDC) + DeleteDC(printerDC); + printerDC = NULL; + if (memHDC) + DeleteDC(memHDC); + memHDC = NULL; }; @@ -1011,6 +1136,9 @@ static int processCommandChar(Bit8u ch) ESCSeen = false; numParam = 0; + if (ESCCmd != 0x78) + printCharBuffer (); + switch (ESCCmd) { case 0x02: // Undocumented @@ -1317,7 +1445,7 @@ static int processCommandChar(Bit8u ch) densz = params[1]; break; case 0x40: // Initialize printer (ESC @) - resetPrinter(); + initPrinter(); break; case 0x41: // Set n/60-inch line spacing lineSpacing = (Real64)params[0]/60; @@ -1380,6 +1508,10 @@ static int processCommandChar(Bit8u ch) break; case 0x51: // Set right margin rightMargin = (Real64)(params[0]-1.0) / (Real64)cpi; + if (rightMargin < 0) + rightMargin = 0; + if (rightMargin < leftMargin) + rightMargin = leftMargin; break; case 0x52: // Select an international character set (ESC R) if (params[0] <= 13 || params[0] == 64) @@ -1460,7 +1592,14 @@ static int processCommandChar(Bit8u ch) } break; case 0x61: // Select justification (ESC a) - // Ignore + printCharBuffer (); + justification = JUST_LEFT; + if (params[0] == 1 || params[0] == 31) + justification = JUST_CENTER; + if (params[0] == 2 || params[0] == 32) + justification = JUST_RIGHT; + if (params[0] == 3 || params[0] == 33) + justification = JUST_FULL; break; case 0x63: // Set horizontal motion index (HMI) (ESC c) hmi = (Real64)PARAM16(0) / (Real64)360.0; @@ -1479,6 +1618,8 @@ static int processCommandChar(Bit8u ch) break; case 0x6c: // Set left margin (ESC 1) leftMargin = (Real64)(params[0]-1.0) / (Real64)cpi; + if (leftMargin < 0) + leftMargin = 0; if (curX < leftMargin) curX = leftMargin; break; @@ -1689,10 +1830,12 @@ static int processCommandChar(Bit8u ch) newPage(true); return true; case 0x0d: // Carriage Return (CR) + printCharBuffer (); curX = leftMargin; if (!autoFeed) return true; case 0x0a: // Line feed + printCharBuffer (); if (style & STYLE_DOUBLEWIDTHONELINE) { style &= 0xFFFF - STYLE_DOUBLEWIDTHONELINE; @@ -1762,8 +1905,8 @@ static void printBitGraph(Bit8u ch) return; // When page dpi is greater than graphics dpi, the drawn pixels get "bigger" - pixsizeX = dpi/bitGraph.horizDens > 0?dpi/bitGraph.horizDens:1; - pixsizeY = dpi/bitGraph.vertDens > 0?dpi/bitGraph.vertDens:1; + pixsizeX = dpiX/bitGraph.horizDens > 0?dpiX/bitGraph.horizDens:1; + pixsizeY = dpiY/bitGraph.vertDens > 0?dpiY/bitGraph.vertDens:1; for (i=0; i= 0) && (desty+y >= 0)) { Bit8u* target = (Bit8u*)page + (x+destx) + (y+desty)*page_pitch; + Bit8u b = *source; + if (b >= 64) { + b = 255; + } else if (b == 0) { + b = 0; + } else { + b = (b << 2) | (b >> 4); + } if (add) { - if (*target + *source > 255) + if (*target + b > 255) *target = 255; else - *target += *source; + *target += b; } else - *target = *source; + *target = b; } } } } -static void drawLine(Bit8u fromx, Bit8u tox, Bit8u y, int broken) +static void drawLine(int fromx, int tox, int y, int broken) { - Bitu x; + int x; - Bitu breakmod = dpi / 15; - Bitu gapstart = (breakmod * 4)/5; + int breakmod = dpiX / 15; + int gapstart = (breakmod * 4) / 5; // Draw anti-aliased line for (x=fromx; x<=tox; x++) { // Skip parts if broken line or going over the border - if ((!broken || (x%breakmod <= gapstart)) && (x < page_w)) + if ((!broken || (x%breakmod <= gapstart)) && (x < page_w) && (x >= 0)) { + if (y < 0) + continue; if (y > 0 && (y-1) < page_h) *((Bit8u*)page + x + (y-1)*page_pitch) = 120; if (y < page_h) @@ -1850,44 +2003,32 @@ static void drawLine(Bit8u fromx, Bit8u tox, Bit8u y, int broken) } } -static void printChar(Bit8u ch) +static void printSingleChar(Bit8u ch, int doprint) { - FT_UInt index; - Bit16u penX; - Bit16u penY; + int penX; + int penY; Bit16u lineStart; - charRead = true; - - if (page == NULL) - return; - - // Don't think that DOS programs uses this but well: Apply MSB if desired - if (msb != 255) - { - if (msb == 0) - ch &= 0x7F; - if (msb == 1) - ch |= 0x80; - } - - // Are we currently printing a bit graphic? - if (bitGraph.remBytes > 0) - { - printBitGraph(ch); - return; - } - - // Print everything? - if (numPrintAsChar > 0) - numPrintAsChar--; - else if (processCommandChar(ch)) - return; - + int bitmap_left = 0; + int bitmap_top = 0; + int ascender = 0; + int width = 0; + int rows = 0; + int height = 0; + int pitch = 0; + int advancex = 0; + uae_u8 *gbitmap = NULL; +#ifndef WINFONT // Do not print if no font is available if (!curFont) return; + bitmap_left = curFont->glyph->bitmap_left; + bitmap_top = curFont->glyph->bitmap_top; + ascender = curFont->size->metrics.ascender / 64; + rows = curFont->glyph->bitmap.rows; + advancex = curFont->glyph->advance.x / 64; + // Find the glyph for the char to render index = FT_Get_Char_Index(curFont, curMap[ch]); @@ -1896,34 +2037,60 @@ static void printChar(Bit8u ch) // Render a high-quality bitmap FT_Render_Glyph(curFont->glyph, FT_RENDER_MODE_NORMAL); + gbitmap = curFont->glyph->bitmap; +#else + if (!selectfont (style)) + return; + MAT2 m2 = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; + GLYPHMETRICS metrics; + int bufsize = GetGlyphOutline (memHDC, curMap[ch], GGO_GRAY8_BITMAP, &metrics, 0, NULL, &m2); + if (bufsize >= 0) { + if (bufsize == 0) + bufsize = 4; + gbitmap = xcalloc (uae_u8, bufsize); + GetGlyphOutline (memHDC, curMap[ch], GGO_GRAY8_BITMAP, &metrics, bufsize, gbitmap, &m2); + + bitmap_left = metrics.gmptGlyphOrigin.x; + bitmap_top = metrics.gmptGlyphOrigin.y; + width = metrics.gmBlackBoxX; + rows = metrics.gmBlackBoxY; + advancex = metrics.gmCellIncX; + height = otm->otmTextMetrics.tmHeight; + ascender = otm->otmAscent; + pitch = (width + 3) & ~3; + } +#endif - penX = PIXX + curFont->glyph->bitmap_left; - penY = PIXY - curFont->glyph->bitmap_top + curFont->size->metrics.ascender/64; - - if (style & STYLE_SUBSCRIPT) - penY += curFont->glyph->bitmap.rows / 2; + if (gbitmap) { + penX = PIXX + bitmap_left; + penY = PIXY - bitmap_top + ascender; - // Copy bitmap into page + if (style & STYLE_SUBSCRIPT) + penY += rows / 2; - blitGlyph(curFont->glyph->bitmap, penX, penY, false); + if (doprint) { + // Copy bitmap into page + blitGlyph(gbitmap, width, rows, pitch, penX, penY, false); - // Doublestrike => Print the glyph a second time one pixel below - if (style & STYLE_DOUBLESTRIKE) - blitGlyph(curFont->glyph->bitmap, penX, penY+1, true); + // Doublestrike => Print the glyph a second time one pixel below + if (style & STYLE_DOUBLESTRIKE) + blitGlyph(gbitmap, width, rows, pitch, penX, penY+1, true); - // Bold => Print the glyph a second time one pixel to the right - if (style & STYLE_BOLD) - blitGlyph(curFont->glyph->bitmap, penX+1, penY, true); + // Bold => Print the glyph a second time one pixel to the right + if (style & STYLE_BOLD) + blitGlyph(gbitmap, width, rows, pitch, penX+1, penY, true); + } + } // For line printing lineStart = PIXX; if (style & STYLE_PROP) - curX += (Real64)((Real64)(curFont->glyph->advance.x)/(Real64)(dpi*64)); + curX += (Real64)((Real64)(advancex)/(Real64)(dpiX)); else { if (hmi < 0) - curX += 1/(Real64)actcpi; + curX += 1.0/(Real64)actcpi; else curX += hmi; } @@ -1931,22 +2098,109 @@ static void printChar(Bit8u ch) curX += extraIntraSpace; // Draw lines if desired - if (score != SCORE_NONE && (style & (STYLE_UNDERLINE|STYLE_STRIKETHROUGH|STYLE_OVERSCORE))) + if (doprint && score != SCORE_NONE && (style & (STYLE_UNDERLINE|STYLE_STRIKETHROUGH|STYLE_OVERSCORE))) { // Find out where to put the line Bit16u lineY = PIXY; if (style & STYLE_UNDERLINE) - lineY = penY + 5 + curFont->glyph->bitmap.rows; + lineY = PIXY + height - 1; if (style & STYLE_STRIKETHROUGH) - lineY = PIXY + curFont->size->metrics.ascender/128; + lineY = PIXY + ascender / 2; if (style & STYLE_OVERSCORE) - lineY = PIXY - ((score == SCORE_DOUBLE || score == SCORE_DOUBLEBROKEN)?5:0); + lineY = PIXY - ((score == SCORE_DOUBLE || score == SCORE_DOUBLEBROKEN) ? 5 : 0); - drawLine(penX, PIXX, lineY, score==SCORE_SINGLEBROKEN || score==SCORE_DOUBLEBROKEN); + drawLine(penX - 1, PIXX + 1, lineY, score==SCORE_SINGLEBROKEN || score==SCORE_DOUBLEBROKEN); if (score == SCORE_DOUBLE || score == SCORE_DOUBLEBROKEN) - drawLine(lineStart, PIXX, lineY + 5, score==SCORE_SINGLEBROKEN || score==SCORE_DOUBLEBROKEN); + drawLine(lineStart, PIXX + 1, lineY + 5, score==SCORE_SINGLEBROKEN || score==SCORE_DOUBLEBROKEN); + } +#ifdef WINFONT + xfree (gbitmap); +#endif +} + +static void printCharBuffer(void) +{ + if (justification != JUST_LEFT) { + curX = 0; + for (int i = 0; i < charcnt; i++) { + printSingleChar (charbuffer[i], false); + } + switch (justification) + { + case JUST_RIGHT: + curX = rightMargin - curX; + break; + case JUST_CENTER: + curX = leftMargin + (rightMargin - leftMargin) / 2 - curX / 2; + break; + case JUST_FULL: + { + float width = rightMargin - leftMargin; + if (curX > width * 50 / 100) { + float extraw = (width - curX) / charcnt; + curX = leftMargin; + for (int i = 0; i < charcnt; i++) { + printSingleChar (charbuffer[i], true); + curX += extraw; + } + charcnt = 0; + return; + } else { + curX = leftMargin; + } + } + break; + default: + curX = leftMargin; + break; + } + } + for (int i = 0; i < charcnt; i++) { + printSingleChar(charbuffer[i], true); + } + charcnt = 0; +} + +static void printChar(Bit8u ch) +{ +#ifndef WINFONT + FT_UInt index; +#endif + + charRead = true; + + if (page == NULL) + return; + + // Don't think that DOS programs uses this but well: Apply MSB if desired + if (msb != 255) + { + if (msb == 0) + ch &= 0x7F; + if (msb == 1) + ch |= 0x80; + } + + // Are we currently printing a bit graphic? + if (bitGraph.remBytes > 0) + { + printBitGraph(ch); + return; + } + + // Print everything? + if (numPrintAsChar > 0) { + numPrintAsChar--; + } else if (processCommandChar(ch)) { + printCharBuffer (); + return; + } + + charbuffer[charcnt++] = ch; + if (charcnt >= CHARBUFFERSIZE) { + printCharBuffer (); } } @@ -1965,42 +2219,57 @@ static int isBlank(void) static int epson_ft (void) { +#ifndef WINFONT if (!ft) ft = WIN32_LoadLibrary (L"freetype6.dll"); if (!ft) { write_log (L"EPSONPRINTER: freetype6.dll not found. Text output disabled."); return 0; } +#endif return 1; } + +#ifdef DEBUGPRINT +#include "zfile.h" +static int printed; #endif void epson_printchar(uae_u8 c) { -#ifndef CPU_64_BIT +#ifdef DEBUGPRINT + if (printed) + return; + printed = 1; + struct zfile *zf = zfile_fopen (L"c:\\d\\data_epsonq_raw.bin", L"rb", ZFD_ALL); + for (;;) { + int v = zfile_getc (zf); + if (v < 0) + break; + printChar (v); + } + zfile_fclose (zf); +#else printChar (c); #endif } -int epson_init(int type) +int epson_init(const TCHAR *printername, int type) { -#ifndef CPU_64_BIT if (type == PARALLEL_MATRIX_EPSON9) pins = 9; else pins = 48; epson_ft (); write_log (L"EPSONPRINTER%d: start\n", pins); - return printer_init(300, 83, 117, L"png", 0, pins); -#else - return 0; -#endif + return printer_init(600, 83, 117, pngprint ? NULL : printername, 0, pins); } void epson_close(void) { -#ifndef CPU_64_BIT if (page && !isBlank ()) { outputPage(); } printer_close(); +#ifdef DEBUGPRINT + printed = 0; #endif } diff --git a/include/epsonprinter.h b/include/epsonprinter.h index 880f3317..4c51f592 100644 --- a/include/epsonprinter.h +++ b/include/epsonprinter.h @@ -58,6 +58,11 @@ #define QUALITY_DRAFT 0x01 #define QUALITY_LQ 0x02 +#define JUST_LEFT 0 +#define JUST_CENTER 1 +#define JUST_RIGHT 2 +#define JUST_FULL 3 + enum Typeface { roman = 0, diff --git a/include/inputdevice.h b/include/inputdevice.h index ad2b22ce..97879632 100644 --- a/include/inputdevice.h +++ b/include/inputdevice.h @@ -72,6 +72,7 @@ extern int input_get_default_mouse (struct uae_input_device *uid, int num, int p extern int input_get_default_lightpen (struct uae_input_device *uid, int num, int port); extern int input_get_default_joystick (struct uae_input_device *uid, int num, int port, int cd32); extern int input_get_default_joystick_analog (struct uae_input_device *uid, int num, int port); +extern int input_get_default_keyboard (int num); #define DEFEVENT(A, B, C, D, E, F) INPUTEVENT_ ## A, enum inputevents { diff --git a/include/sampler.h b/include/sampler.h index 3b863212..471ecb1b 100644 --- a/include/sampler.h +++ b/include/sampler.h @@ -1,5 +1,5 @@ -extern uae_u8 sampler_getsample (void); +extern uae_u8 sampler_getsample (int); extern int sampler_init (void); extern void sampler_free (void); extern void sampler_vsync (void); diff --git a/inputdevice.cpp b/inputdevice.cpp index 792b967b..51cd9942 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -3678,7 +3678,7 @@ void inputdevice_devicechange (struct uae_prefs *prefs) config_changed = 1; } -static void set_kbr_default (struct uae_prefs *p, int index, int num) +static void set_kbr_default (struct uae_prefs *p, int index) { int i, j, k, l; struct uae_input_device_kbr_default *trans = keyboard_default; @@ -3695,10 +3695,10 @@ static void set_kbr_default (struct uae_prefs *p, int index, int num) kbr->extra[i][0] = -1; } if (j < id->get_num ()) { - if (j == 0) + if (input_get_default_keyboard (j)) kbr->enabled = 1; - for (i = 0; i < id->get_widget_num (num); i++) { - id->get_widget_type (num, i, 0, &scancode); + for (i = 0; i < id->get_widget_num (j); i++) { + id->get_widget_type (j, i, 0, &scancode); kbr->extra[i][0] = scancode; l = 0; while (trans[l].scancode >= 0) { @@ -3737,7 +3737,7 @@ void inputdevice_default_prefs (struct uae_prefs *p) p->input_mouse_speed = 100; p->input_autofire_framecnt = 10; for (i = 0; i <= MAX_INPUT_SETTINGS; i++) { - set_kbr_default (p, i, 0); + set_kbr_default (p, i); for (j = 0; j < MAX_INPUT_DEVICES; j++) { if (input_get_default_mouse (p->mouse_settings[i], j, j & 1)) p->mouse_settings[i]->enabled = 1; @@ -4653,6 +4653,7 @@ int inputdevice_joyport_config (struct uae_prefs *p, TCHAR *value, int portnum, p->jports[portnum].id = idnum + i; if (mode >= 0) p->jports[portnum].mode = mode; + config_changed = 1; return 1; } } @@ -4694,6 +4695,7 @@ int inputdevice_joyport_config (struct uae_prefs *p, TCHAR *value, int portnum, p->jports[portnum].id = start; if (mode >= 0) p->jports[portnum].mode = mode; + config_changed = 1; return 1; } } diff --git a/od-win32/dinput.cpp b/od-win32/dinput.cpp index 9b52b64b..312b666c 100644 --- a/od-win32/dinput.cpp +++ b/od-win32/dinput.cpp @@ -104,7 +104,7 @@ static int oldleds, oldusedleds, newleds, oldusbleds; static int normalmouse, supermouse, rawmouse, winmouse, winmousenumber, winmousemode, winmousewheelbuttonstart; static int normalkb, superkb, rawkb; -int rawkeyboard; +int rawkeyboard = -1; int no_rawinput; int dinput_enum_all; @@ -896,11 +896,11 @@ static int initialize_rawinput (void) } else { int j; PRID_DEVICE_INFO_KEYBOARD rdik = &rdi->keyboard; - write_log (L"type=%d sub=%d mode=%d fkeys=%d indicators=%d tkeys=%d", + write_log (L"type=%d sub=%d mode=%d fkeys=%d indicators=%d tkeys=%d\n", rdik->dwType, rdik->dwSubType, rdik->dwKeyboardMode, rdik->dwNumberOfFunctionKeys, rdik->dwNumberOfIndicators, rdik->dwNumberOfKeysTotal); j = 0; - for (i = 0; i < 254; i++) { + for (int k = 0; k < 254; k++) { TCHAR tmp[100]; tmp[0] = 0; if (rawkeyboardlabels[j] != NULL) { @@ -912,10 +912,10 @@ static int initialize_rawinput (void) j++; } if (!tmp[0]) - _stprintf (tmp, L"Key %02X", i + 1); - did->buttonname[i] = my_strdup (tmp); - did->buttonmappings[i] = i + 1; - did->buttonsort[i] = i + 1; + _stprintf (tmp, L"Key %02X", k + 1); + did->buttonname[k] = my_strdup (tmp); + did->buttonmappings[k] = k + 1; + did->buttonsort[k] = k + 1; did->buttons++; } } @@ -1067,17 +1067,15 @@ static void handle_rawinput_2 (RAWINPUT *raw) if (scancode == 0xaa) return; -#if 0 +#if 1 for (num = 0; num < num_keyboard; num++) { did = &di_keyboard[num]; - if ((did->acquired || rawkeyboard > 0) && did->rawinput == raw->header.hDevice) + if (did->acquired && did->rawinput == raw->header.hDevice) break; } if (num == num_keyboard) { - if (scancode == DIK_F12 && pressed) { + if (scancode == DIK_F12 && pressed) inputdevice_add_inputcode (AKS_ENTERGUI, 1); - return; - } return; } #endif @@ -1330,7 +1328,7 @@ static BOOL CALLBACK EnumObjectsCallback (const DIDEVICEOBJECTINSTANCE* pdidoi, if (pdidoi->dwType & DIDFT_BUTTON) { if (did->buttons >= MAX_MAPPINGS) return DIENUM_CONTINUE; - did->buttonname[did->buttons] = my_strdup (pdidoi->tszName); + TCHAR *bname = did->buttonname[did->buttons] = my_strdup (pdidoi->tszName); if (did->type == DID_JOYSTICK) { //did->buttonmappings[did->buttons] = DIJOFS_BUTTON(DIDFT_GETINSTANCE (pdidoi->dwType)); did->buttonmappings[did->buttons] = DIJOFS_BUTTON(did->buttons); @@ -1339,9 +1337,15 @@ static BOOL CALLBACK EnumObjectsCallback (const DIDEVICEOBJECTINSTANCE* pdidoi, //did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + DIDFT_GETINSTANCE (pdidoi->dwType); did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + did->buttons; did->buttonsort[did->buttons] = makesort_mouse (&pdidoi->guidType, &did->buttonmappings[did->buttons]); - } else { + } else if (did->type == DID_KEYBOARD) { //did->buttonmappings[did->buttons] = pdidoi->dwOfs; did->buttonmappings[did->buttons] = DIDFT_GETINSTANCE (pdidoi->dwType); + if (rawkeyboard && (!_tcsicmp (bname, L"kana") || 0)) { // buggy layout? + if (rawkeyboard != 2) { + write_log (L"Possible buggy directinput keyboard layout detected, switching to raw keyboard mode\n"); + rawkeyboard = 2; + } + } } did->buttons++; } @@ -1481,10 +1485,8 @@ static int di_do_init (void) write_log (L"DirectInput enumeration..\n"); g_lpdi->EnumDevices (DI8DEVCLASS_ALL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); } else { - if (rawkeyboard <= 0) { - write_log (L"DirectInput enumeration.. Keyboards..\n"); - g_lpdi->EnumDevices (DI8DEVCLASS_KEYBOARD, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); - } + write_log (L"DirectInput enumeration.. Keyboards..\n"); + g_lpdi->EnumDevices (DI8DEVCLASS_KEYBOARD, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); write_log (L"DirectInput enumeration.. Pointing devices..\n"); g_lpdi->EnumDevices (DI8DEVCLASS_POINTER, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); write_log (L"DirectInput enumeration.. Game controllers..\n"); @@ -2532,6 +2534,19 @@ int dinput_wmkey (uae_u32 key) return 0; } +int input_get_default_keyboard (int i) +{ + if (rawkeyboard > 0) { + if (i == 0) + return 0; + return 1; + } else { + if (i == 0) + return 1; + return 0; + } +} + int input_get_default_mouse (struct uae_input_device *uid, int i, int port) { struct didata *did; diff --git a/od-win32/direct3d.cpp b/od-win32/direct3d.cpp index 45c4bdfd..3912605b 100644 --- a/od-win32/direct3d.cpp +++ b/od-win32/direct3d.cpp @@ -1498,7 +1498,7 @@ static int restoredeviceobjects (void) write_log (L"%s: LED D3DXSprite failed: %s\n", D3DHEAD, D3D_ErrorString (hr)); } - int curw = 64, curh = 64; + int curw = CURSORMAXWIDTH, curh = CURSORMAXHEIGHT; cursorsurfaced3d = createtext (curw, curh, D3DFMT_A8R8G8B8); cursor_v = 0; diff --git a/od-win32/direct3d.h b/od-win32/direct3d.h index de041714..4f5c3a6e 100644 --- a/od-win32/direct3d.h +++ b/od-win32/direct3d.h @@ -16,3 +16,6 @@ extern int D3D_canshaders (void); extern int D3D_goodenough (void); extern void D3D_setcursor (int x, int y, int visible); extern LPDIRECT3DTEXTURE9 cursorsurfaced3d; + +#define CURSORMAXWIDTH 64 +#define CURSORMAXHEIGHT 64 diff --git a/od-win32/parser.cpp b/od-win32/parser.cpp index 9bcff25d..2850ed0d 100644 --- a/od-win32/parser.cpp +++ b/od-win32/parser.cpp @@ -262,7 +262,7 @@ static void flushprtbuf (void) if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { int i; if (!prtopen) { - if (epson_init (currprefs.parallel_matrix_emulation)) + if (epson_init (currprefs.prtname, currprefs.parallel_matrix_emulation)) prtopen = 1; } for (i = 0; i < prtbufbytes; i++) @@ -472,7 +472,7 @@ static void openprinter (void) prtopen = 1; return; } else if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { - epson_init (currprefs.parallel_matrix_emulation); + epson_init (currprefs.prtname, currprefs.parallel_matrix_emulation); } else if (hPrt == INVALID_HANDLE_VALUE) { flushprtbuf (); if (OpenPrinter (currprefs.prtname, &hPrt, NULL)) { diff --git a/od-win32/parser.h b/od-win32/parser.h index c65e3386..0204fa3b 100644 --- a/od-win32/parser.h +++ b/od-win32/parser.h @@ -47,7 +47,7 @@ extern void sernametodev (TCHAR*); extern void serdevtoname (TCHAR*); extern void epson_printchar(uae_u8 c); -extern int epson_init(int pins); +extern int epson_init(const TCHAR *printername, int pins); extern void epson_close(void); #define PARALLEL_MATRIX_TEXT 1 diff --git a/od-win32/picasso96_win.cpp b/od-win32/picasso96_win.cpp index 31cd571e..949aacd8 100644 --- a/od-win32/picasso96_win.cpp +++ b/od-win32/picasso96_win.cpp @@ -62,6 +62,8 @@ #define NOBLITTER 0 #define NOBLITTER_BLIT 0 +#define P96TRACING_ENABLED 0 +#define P96SPRTRACING_ENABLED 0 static int hwsprite = 0; static int picasso96_BT = BT_uaegfx; @@ -71,9 +73,6 @@ static int picasso96_PCT = PCT_Unknown; int mman_GetWriteWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID *lpAddresses, PULONG_PTR lpdwCount, PULONG lpdwGranularity); void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize); -#define P96TRACING_ENABLED 0 -#define P96SPRTRACING_ENABLED 0 - int p96refresh_active; int have_done_picasso = 1; /* For the JIT compiler */ static int p96syncrate; @@ -580,14 +579,22 @@ static void setupcursor (void) HRESULT hr; setupcursor_needed = 1; - if (cursorsurfaced3d && cursordata && cursorwidth && cursorheight) { + if (cursorsurfaced3d) { if (SUCCEEDED (hr = cursorsurfaced3d->LockRect (0, &locked, NULL, 0))) { dptr = (uae_u8*)locked.pBits; pitch = locked.Pitch; - for (int y = 0; y < cursorheight; y++) { - uae_u8 *p1 = cursordata + cursorwidth * bpp * y; + for (int y = 0; y < CURSORMAXHEIGHT; y++) { uae_u8 *p2 = dptr + pitch * y; - memcpy (p2, p1, cursorwidth * bpp); + memset (p2, 0, CURSORMAXWIDTH * bpp); + } + if (cursordata && cursorwidth && cursorheight) { + dptr = (uae_u8*)locked.pBits; + pitch = locked.Pitch; + for (int y = 0; y < cursorheight; y++) { + uae_u8 *p1 = cursordata + cursorwidth * bpp * y; + uae_u8 *p2 = dptr + pitch * y; + memcpy (p2, p1, cursorwidth * bpp); + } } cursorsurfaced3d->UnlockRect (0); setupcursor_needed = 0; @@ -1608,7 +1615,11 @@ static uae_u32 setspriteimage (uaecptr bi) } cursorwidth = w; + if (cursorwidth > CURSORMAXWIDTH) + cursorwidth = CURSORMAXWIDTH; cursorheight = h; + if (cursorheight > CURSORMAXHEIGHT) + cursorheight = CURSORMAXHEIGHT; setupcursor (); ret = 1; diff --git a/od-win32/rp.cpp b/od-win32/rp.cpp index a1b05ac5..e9db9aad 100644 --- a/od-win32/rp.cpp +++ b/od-win32/rp.cpp @@ -110,6 +110,7 @@ static const TCHAR *getmsg (int msg) case RPIPCHM_PING: return L"RPIPCHM_PING"; case RPIPCHM_SAVESTATE: return L"RPIPCHM_SAVESTATE"; case RPIPCHM_LOADSTATE: return L"RPIPCHM_LOADSTATE"; + case RPIPCHM_FLUSH: return L"RPIPCHM_FLUSH"; default: return L"UNKNOWN"; } @@ -303,7 +304,7 @@ static void get_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) int m; int full = 0; int vres = 0; - int totalhdbl, totalvdbl; + int totalhdbl = -1, totalvdbl = -1; hres = p->gfx_resolution; if (p->gfx_filter && p->gfx_filter_horiz_zoom_mult) @@ -339,9 +340,9 @@ static void get_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) if (log_rp) write_log (L"GET_RPSM: hres=%d (%d) vres=%d (%d) full=%d xcpos=%d ycpos=%d w=%d h=%d\n", - totalhdbl, hres, totalvdbl, vres, full, - p->gfx_xcenter_pos, p->gfx_ycenter_pos, - p->gfx_size_win.width, p->gfx_size_win.height); + totalhdbl, hres, totalvdbl, vres, full, + p->gfx_xcenter_pos, p->gfx_ycenter_pos, + p->gfx_size_win.width, p->gfx_size_win.height); sm->lClipLeft = p->gfx_xcenter_pos <= 0 ? -1 : p->gfx_xcenter_pos; sm->lClipTop = p->gfx_ycenter_pos <= 0 ? -1 : p->gfx_ycenter_pos; if (full) { @@ -369,8 +370,8 @@ static void get_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) if (log_rp) write_log (L"GET_RPSM: %08X %dx%d %dx%d hres=%d (%d) vres=%d (%d) disp=%d fs=%d\n", - sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, - totalhdbl, hres, totalvdbl, vres, p->gfx_display, full); + sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, + totalhdbl, hres, totalvdbl, vres, p->gfx_display, full); } static void set_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) diff --git a/od-win32/sounddep/sound.cpp b/od-win32/sounddep/sound.cpp index 77568615..75784fe0 100644 --- a/od-win32/sounddep/sound.cpp +++ b/od-win32/sounddep/sound.cpp @@ -171,8 +171,12 @@ void update_sound (int freq, int longframe, int linetoggle) lines += 1.0; hpos = maxhpos_short; } +#if 0 + write_log (L"%d.%d %d.%d\n", + maxhpos_short, linetoggle ? 5 : 0, + maxvpos_nom + (lines == 1.0 ? 1 : 0), lines > 0 && lines < 1 ? 5 : 0); +#endif lines += maxvpos_nom; - scaled_sample_evtime_orig = hpos * lines * freq * CYCLE_UNIT / (float)sdp->obtainedfreq; scaled_sample_evtime = scaled_sample_evtime_orig; } diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 8337231b..6c567009 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -4347,12 +4347,12 @@ static int PASCAL WinMain2 (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR enumerate_sound_devices (); for (i = 0; sound_devices[i].name; i++) { int type = sound_devices[i].type; - write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), sound_devices[i].name); + write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : (type == SOUND_DEVICE_WASAPI ? L"WA" : L"PA")), sound_devices[i].name); } write_log (L"Enumerating recording devices:\n"); for (i = 0; record_devices[i].name; i++) { int type = record_devices[i].type; - write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), record_devices[i].name); + write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : (type == SOUND_DEVICE_WASAPI ? L"WA" : L"PA")), record_devices[i].name); } write_log (L"done\n"); memset (&devmode, 0, sizeof (devmode)); diff --git a/od-win32/win32.h b/od-win32/win32.h index 79f0cdf8..3bb971cb 100644 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -18,8 +18,8 @@ #define WINUAEPUBLICBETA 1 #define LANG_DLL 1 -#define WINUAEBETA L"19" -#define WINUAEDATE MAKEBD(2010, 3, 27) +#define WINUAEBETA L"20" +#define WINUAEDATE MAKEBD(2010, 4, 3) #define WINUAEEXTRA L"" #define WINUAEREV L"" diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index ac8f182c..550774ea 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -49,6 +49,7 @@ #include "gfxfilter.h" #include "parser.h" #include "lcd.h" +#include "sampler.h" #ifdef RETROPLATFORM #include "rp.h" #endif @@ -317,20 +318,22 @@ static int set_ddraw_2 (void) for (;;) { int i, j, got = FALSE; HRESULT olderr; - struct MultiDisplay *md = getdisplay (&currprefs); - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - struct PicassoResolution *pr = &md->DisplayModes[i]; - if (pr->res.width == width && pr->res.height == height) { - for (j = 0; pr->refresh[j] > 0; j++) { - if (pr->refresh[j] == freq) - got = TRUE; + if (freq > 0) { + struct MultiDisplay *md = getdisplay (&currprefs); + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + struct PicassoResolution *pr = &md->DisplayModes[i]; + if (pr->res.width == width && pr->res.height == height) { + for (j = 0; pr->refresh[j] > 0; j++) { + if (pr->refresh[j] == freq) + got = TRUE; + } + break; } - break; } - } - if (got == FALSE) { - write_log (L"set_ddraw: refresh rate %d not supported\n", freq); - freq = 0; + if (got == FALSE) { + write_log (L"set_ddraw: refresh rate %d not supported\n", freq); + freq = 0; + } } write_log (L"set_ddraw: trying %dx%d, bits=%d, refreshrate=%d\n", width, height, bits, freq); ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); @@ -1474,6 +1477,11 @@ int check_prefs_changed_gfx (void) return 1; } + if (currprefs.win32_samplersoundcard != changed_prefs.win32_samplersoundcard) { + currprefs.win32_samplersoundcard = changed_prefs.win32_samplersoundcard; + sampler_free (); + } + if (_tcscmp (currprefs.prtname, changed_prefs.prtname) || currprefs.parallel_autoflush_time != changed_prefs.parallel_autoflush_time || currprefs.parallel_matrix_emulation != changed_prefs.parallel_matrix_emulation || diff --git a/od-win32/winuae_msvc10/winuae_msvc.vcxproj b/od-win32/winuae_msvc10/winuae_msvc.vcxproj index 62ca8fa2..2ae37dd2 100644 --- a/od-win32/winuae_msvc10/winuae_msvc.vcxproj +++ b/od-win32/winuae_msvc10/winuae_msvc.vcxproj @@ -163,7 +163,7 @@ d:\amiga\winuae.exe true LIBCMT;%(IgnoreSpecificDefaultLibraries) - wpcap.dll;packet.dll;d3dx9_42.dll;openal32.dll;wintab32.dll;portaudio_x86.dll;freetype6.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;avrt.dll;%(DelayLoadDLLs) + wpcap.dll;packet.dll;d3dx9_42.dll;openal32.dll;wintab32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;%(DelayLoadDLLs) true .\Debug/winuae.pdb Windows @@ -289,7 +289,7 @@ %(AdditionalLibraryDirectories) %(AdditionalManifestDependencies) %(IgnoreSpecificDefaultLibraries) - wpcap.dll;packet.dll;d3dx9_42.dll;openal32.dll;wintab32.dll;portaudio_x86.dll;freetype6.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;avrt.dll;wininet.dll;%(DelayLoadDLLs) + wpcap.dll;packet.dll;d3dx9_42.dll;openal32.dll;wintab32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;%(DelayLoadDLLs) true .\Release/winuae.pdb Windows diff --git a/sampler.cpp b/sampler.cpp index d5590305..7bbc44a3 100644 --- a/sampler.cpp +++ b/sampler.cpp @@ -18,8 +18,9 @@ #include "win32.h" -#define RECORDBUFFER (10000 * 4) -#define SAMPLEBUFFER (2048 * 4) +#define SAMPLESIZE 4 +#define RECORDBUFFER 40000 +#define SAMPLEBUFFER 4000 static LPDIRECTSOUNDCAPTURE lpDS2r = NULL; static LPDIRECTSOUNDCAPTUREBUFFER lpDSBprimary2r = NULL; @@ -51,7 +52,7 @@ static int capture_init (void) } memset (&sound_buffer_rec, 0, sizeof (DSCBUFFERDESC)); sound_buffer_rec.dwSize = sizeof (DSCBUFFERDESC); - sound_buffer_rec.dwBufferBytes = RECORDBUFFER; + sound_buffer_rec.dwBufferBytes = RECORDBUFFER * SAMPLESIZE; sound_buffer_rec.lpwfxFormat = &wavfmt; sound_buffer_rec.dwFlags = 0 ; @@ -66,7 +67,7 @@ static int capture_init (void) write_log (L"SAMPLER: DirectSoundCaptureBuffer_Start failed: %s\n", DXError (hr)); return 0; } - samplebuffer = xcalloc (uae_u8, SAMPLEBUFFER); + samplebuffer = xcalloc (uae_u8, SAMPLEBUFFER * SAMPLESIZE); write_log (L"SAMPLER: Parallel port sampler initialized\n"); return 1; } @@ -89,17 +90,20 @@ static void capture_free (void) static evt oldcycles; static int oldoffset; -uae_u8 sampler_getsample (void) +uae_u8 sampler_getsample (int channel) { HRESULT hr; - DWORD t, cur_pos, cap_pos; + static DWORD cap_pos; + DWORD t, cur_pos; void *p1, *p2; DWORD len1, len2; evt cycles; int offset; int sample, samplecnt, diff; - int channel = 0; - uae_s16 *sbuf = (uae_s16*)samplebuffer; + +// if (channel) +// return 0; + channel = 0; if (!inited) { if (!capture_init ()) { @@ -115,6 +119,8 @@ uae_u8 sampler_getsample (void) return 0; } } + uae_s16 *sbuf = (uae_s16*)samplebuffer; + vsynccnt = 0; sample = 0; samplecnt = 0; @@ -123,52 +129,59 @@ uae_u8 sampler_getsample (void) if (oldoffset < 0 || offset >= SAMPLEBUFFER || offset < 0) { if (oldoffset >= 0 && offset >= SAMPLEBUFFER) { while (oldoffset < SAMPLEBUFFER) { - sample += sbuf[oldoffset * 2 + channel]; + sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel]; oldoffset++; samplecnt++; } } - oldcycles = cycles; - cap_pos = 0; + //write_log (L"%d\n", cur_pos - cap_pos); + hr = lpDSB2r->Lock (cap_pos, SAMPLEBUFFER * SAMPLESIZE, &p1, &len1, &p2, &len2, 0); + if (FAILED (hr)) + return 0; + memcpy (samplebuffer, p1, len1); + if (p2) + memcpy (samplebuffer + len1, p2, len2); + lpDSB2r->Unlock (p1, len1, p2, len2); + cap_pos += SAMPLEBUFFER * SAMPLESIZE; + hr = lpDSB2r->GetCurrentPosition (&t, &cur_pos); if (FAILED (hr)) return 0; - write_log (L"%d\n", cur_pos - cap_pos); if (cur_pos >= cap_pos) diff = cur_pos - cap_pos; else - diff = RECORDBUFFER - cap_pos + cur_pos; - if (diff > SAMPLEBUFFER * 4) { + diff = RECORDBUFFER * SAMPLESIZE - cap_pos + cur_pos; + if (diff > RECORDBUFFER * SAMPLESIZE - 4 * SAMPLEBUFFER * SAMPLESIZE) { + write_log (L"!"); + diff -= RECORDBUFFER * SAMPLESIZE; + } else if (diff > RECORDBUFFER * SAMPLESIZE / 2) { cap_pos = cur_pos; - oldoffset = 0; - oldcycles = get_cycles (); + write_log (L"*"); + diff = 0; } - hr = lpDSB2r->Lock (cap_pos, SAMPLEBUFFER, &p1, &len1, &p2, &len2, 0); - if (FAILED (hr)) - return 0; - memcpy (samplebuffer, p1, len1); - if (p2) - memcpy (samplebuffer + len1, p2, len2); - lpDSB2r->Unlock (p1, len1, p2, len2); - cap_pos += SAMPLEBUFFER; + cap_pos += diff; - if (cap_pos >= RECORDBUFFER) - cap_pos -= RECORDBUFFER; if (cap_pos < 0) - cap_pos = 0; - offset = 0; - if (oldoffset < 0) - oldoffset = 0; + cap_pos += RECORDBUFFER * SAMPLESIZE; + if (cap_pos >= RECORDBUFFER * SAMPLESIZE) + cap_pos -= RECORDBUFFER * SAMPLESIZE; + + if (offset < 0) + offset = 0; + if (offset >= SAMPLEBUFFER) + offset -= SAMPLEBUFFER; + oldoffset = 0; + oldcycles = get_cycles (); } while (oldoffset <= offset) { - sample += ((uae_s16*)samplebuffer)[oldoffset * 2 + channel]; - oldoffset++; + sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel]; samplecnt++; + oldoffset++; } oldoffset = offset; if (samplecnt > 0) sample /= samplecnt; - return sample >> 8; + return (sample / 256) - 128; } int sampler_init (void)