--- hatari/src/falcon/videl.c 2019/04/09 08:52:09 1.1.1.8 +++ hatari/src/falcon/videl.c 2019/04/09 08:55:47 1.1.1.11 @@ -1,8 +1,8 @@ /* Hatari - videl.c - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. Falcon Videl emulation. The Videl is the graphics shifter chip of the Falcon. It supports free programmable resolutions with 1, 2, 4, 8 or 16 bits per @@ -76,7 +76,8 @@ const char VIDEL_fileid[] = "Hatari vide #include "screen.h" #include "stMemory.h" #include "videl.h" - +#include "video.h" /* for bUseHighRes variable, maybe unuseful (Laurent) */ +#include "vdi.h" /* for bUseVDIRes variable, maybe unuseful (Laurent) */ #define Atari2HostAddr(a) (&STRam[a]) #define VIDEL_COLOR_REGS_BEGIN 0xff9800 @@ -120,6 +121,7 @@ static void VIDEL_memset_uint32(Uint32 * static void VIDEL_memset_uint16(Uint16 *addr, Uint16 color, int count); static void VIDEL_memset_uint8(Uint8 *addr, Uint8 color, int count); + /** * Called upon startup and when CPU encounters a RESET instruction. */ @@ -145,7 +147,7 @@ void VIDEL_reset(void) videl.save_scrWidth = 640; videl.save_scrHeight = 480; videl.save_scrBpp = ConfigureParams.Screen.nForceBpp; - HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp); + HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp, false); /* Reset IO register (some are not initialized by TOS) */ IoMem_WriteWord(0xff820e, 0); /* Line offset */ @@ -162,15 +164,17 @@ void VIDEL_MemorySnapShot_Capture(bool b { /* Save/Restore details */ MemorySnapShot_Store(&videl, sizeof(videl)); - MemorySnapShot_Store(&videl_zoom, sizeof(videl_zoom)); MemorySnapShot_Store(&vfc_counter, sizeof(vfc_counter)); } /** - * Monitor write access to ST/E color palette registers + * Monitor write access to Falcon color palette registers */ -void VIDEL_ColorRegsWrite(void) +void VIDEL_FalconColorRegsWrite(void) { + uint32_t color = IoMem_ReadLong(IoAccessBaseAddress & ~3); + color &= 0xfcfc00fc; /* Unused bits have to be set to 0 */ + IoMem_WriteLong(IoAccessBaseAddress & ~3, color); videl.hostColorsSync = false; } @@ -251,9 +255,8 @@ void VIDEL_ScreenCounter_WriteByte(void) */ void VIDEL_LineOffset_WriteWord(void) { - Uint16 lineOffset = IoMem_ReadWord(0xff820e); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff820e Line Offset write: 0x%04x\n", lineOffset); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff820e Line Offset write: 0x%04x\n", + IoMem_ReadWord(0xff820e)); } /** @@ -263,9 +266,8 @@ void VIDEL_LineOffset_WriteWord(void) */ void VIDEL_Line_Width_WriteWord(void) { - Uint16 lineWidth = IoMem_ReadWord(0xff8210); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8210 Line Width write: 0x%04x\n", lineWidth); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8210 Line Width write: 0x%04x\n", + IoMem_ReadWord(0xff8210)); } /** @@ -275,17 +277,14 @@ void VIDEL_Line_Width_WriteWord(void) */ void VIDEL_ScreenBase_WriteByte(void) { - Uint32 screenBase; - if ((IoAccessCurrentAddress == 0xff8201) || (IoAccessCurrentAddress == 0xff8203)) { /* Reset screen base low register */ IoMem[0xff820d] = 0; } - - screenBase = (IoMem[0xff8201]<<16)+(IoMem[0xff8203]<<8)+IoMem[0xff820d]; - LOG_TRACE(TRACE_VIDEL, "Videl : $%04x Screen base write: 0x%02x\t (screen: 0x%04x)\n", - IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress], screenBase); + LOG_TRACE(TRACE_VIDEL, "Videl : $%04x Screen base write: 0x%02x\t (screen: 0x%04x)\n", + IoAccessCurrentAddress, IoMem[IoAccessCurrentAddress], + (IoMem[0xff8201]<<16) + (IoMem[0xff8203]<<8) + IoMem[0xff820d]); } /** @@ -362,8 +361,8 @@ void VIDEL_ST_ShiftModeWriteByte(void) */ void VIDEL_HorScroll64_WriteByte(void) { - Uint8 horScroll64 = IoMem_ReadWord(0xff8264); - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8264 Horizontal scroll 64 write: 0x%02x\n", horScroll64); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8264 Horizontal scroll 64 write: 0x%02x\n", + IoMem_ReadByte(0xff8264)); } /** @@ -375,8 +374,8 @@ void VIDEL_HorScroll64_WriteByte(void) */ void VIDEL_HorScroll65_WriteByte(void) { - Uint8 horScroll65 = IoMem_ReadWord(0xff8265); - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8265 Horizontal scroll 65 write: 0x%02x\n", horScroll65); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8265 Horizontal scroll 65 write: 0x%02x\n", + IoMem_ReadByte(0xff8265)); } /** @@ -401,9 +400,8 @@ void VIDEL_HorScroll65_WriteByte(void) */ void VIDEL_Falcon_ShiftMode_WriteWord(void) { - Uint16 falc_shiftMode = IoMem_ReadWord(0xff8266); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8266 Falcon Shift Mode (SPSHIFT) write: 0x%04x\n", falc_shiftMode); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8266 Falcon Shift Mode (SPSHIFT) write: 0x%04x\n", + IoMem_ReadWord(0xff8266)); videl.bUseSTShifter = false; } @@ -413,9 +411,8 @@ void VIDEL_Falcon_ShiftMode_WriteWord(vo */ void VIDEL_HHC_WriteWord(void) { - Uint16 hhc = IoMem_ReadWord(0xff8280); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8280 Horizontal Hold Counter (HHC) write: 0x%04x\n", hhc); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8280 Horizontal Hold Counter (HHC) write: 0x%04x\n", + IoMem_ReadWord(0xff8280)); } /** @@ -423,9 +420,8 @@ void VIDEL_HHC_WriteWord(void) */ void VIDEL_HHT_WriteWord(void) { - Uint16 hht = IoMem_ReadWord(0xff8282); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8282 Horizontal Hold Timer (HHT) write: 0x%04x\n", hht); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8282 Horizontal Hold Timer (HHT) write: 0x%04x\n", + IoMem_ReadWord(0xff8282)); } /** @@ -433,9 +429,8 @@ void VIDEL_HHT_WriteWord(void) */ void VIDEL_HBB_WriteWord(void) { - Uint16 hbb = IoMem_ReadWord(0xff8284); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8284 Horizontal Border Begin (HBB) write: 0x%04x\n", hbb); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8284 Horizontal Border Begin (HBB) write: 0x%04x\n", + IoMem_ReadWord(0xff8284)); } /** @@ -443,9 +438,8 @@ void VIDEL_HBB_WriteWord(void) */ void VIDEL_HBE_WriteWord(void) { - Uint16 hbe = IoMem_ReadWord(0xff8286); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8286 Horizontal Border End (HBE) write: 0x%04x\n", hbe); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8286 Horizontal Border End (HBE) write: 0x%04x\n", + IoMem_ReadWord(0xff8286)); } /** @@ -456,9 +450,8 @@ void VIDEL_HBE_WriteWord(void) */ void VIDEL_HDB_WriteWord(void) { - Uint16 hdb = IoMem_ReadWord(0xff8288); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8288 Horizontal Display Begin (HDB) write: 0x%04x\n", hdb); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8288 Horizontal Display Begin (HDB) write: 0x%04x\n", + IoMem_ReadWord(0xff8288)); } /** @@ -466,9 +459,8 @@ void VIDEL_HDB_WriteWord(void) */ void VIDEL_HDE_WriteWord(void) { - Uint16 hde = IoMem_ReadWord(0xff828a); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff828a Horizontal Display End (HDE) write: 0x%04x\n", hde); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff828a Horizontal Display End (HDE) write: 0x%04x\n", + IoMem_ReadWord(0xff828a)); } /** @@ -476,9 +468,8 @@ void VIDEL_HDE_WriteWord(void) */ void VIDEL_HSS_WriteWord(void) { - Uint16 hss = IoMem_ReadWord(0xff828c); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff828c Horizontal SS (HSS) write: 0x%04x\n", hss); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff828c Horizontal SS (HSS) write: 0x%04x\n", + IoMem_ReadWord(0xff828c)); } /** @@ -486,9 +477,8 @@ void VIDEL_HSS_WriteWord(void) */ void VIDEL_HFS_WriteWord(void) { - Uint16 hfs = IoMem_ReadWord(0xff828e); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff828e Horizontal FS (HFS) write: 0x%04x\n", hfs); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff828e Horizontal FS (HFS) write: 0x%04x\n", + IoMem_ReadWord(0xff828e)); } /** @@ -496,9 +486,8 @@ void VIDEL_HFS_WriteWord(void) */ void VIDEL_HEE_WriteWord(void) { - Uint16 hee = IoMem_ReadWord(0xff8290); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff8290 Horizontal EE (HEE) write: 0x%04x\n", hee); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff8290 Horizontal EE (HEE) write: 0x%04x\n", + IoMem_ReadWord(0xff8290)); } /** @@ -515,9 +504,8 @@ void VIDEL_VFC_ReadWord(void) */ void VIDEL_VFT_WriteWord(void) { - Uint16 vft = IoMem_ReadWord(0xff82a2); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a2 Vertical Frequency Timer (VFT) write: 0x%04x\n", vft); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a2 Vertical Frequency Timer (VFT) write: 0x%04x\n", + IoMem_ReadWord(0xff82a2)); } /** @@ -525,9 +513,8 @@ void VIDEL_VFT_WriteWord(void) */ void VIDEL_VBB_WriteWord(void) { - Uint16 vbb = IoMem_ReadWord(0xff82a4); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a4 Vertical Border Begin (VBB) write: 0x%04x\n", vbb); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a4 Vertical Border Begin (VBB) write: 0x%04x\n", + IoMem_ReadWord(0xff82a4)); } /** @@ -535,9 +522,8 @@ void VIDEL_VBB_WriteWord(void) */ void VIDEL_VBE_WriteWord(void) { - Uint16 vbe = IoMem_ReadWord(0xff82a6); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a6 Vertical Border End (VBE) write: 0x%04x\n", vbe); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a6 Vertical Border End (VBE) write: 0x%04x\n", + IoMem_ReadWord(0xff82a6)); } /** @@ -545,9 +531,8 @@ void VIDEL_VBE_WriteWord(void) */ void VIDEL_VDB_WriteWord(void) { - Uint16 vdb = IoMem_ReadWord(0xff82a8); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a8 Vertical Display Begin (VDB) write: 0x%04x\n", vdb); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82a8 Vertical Display Begin (VDB) write: 0x%04x\n", + IoMem_ReadWord(0xff82a8)); } /** @@ -555,9 +540,8 @@ void VIDEL_VDB_WriteWord(void) */ void VIDEL_VDE_WriteWord(void) { - Uint16 vde = IoMem_ReadWord(0xff82aa); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82aa Vertical Display End (VDE) write: 0x%04x\n", vde); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82aa Vertical Display End (VDE) write: 0x%04x\n", + IoMem_ReadWord(0xff82aa)); } /** @@ -565,9 +549,8 @@ void VIDEL_VDE_WriteWord(void) */ void VIDEL_VSS_WriteWord(void) { - Uint16 vss = IoMem_ReadWord(0xff82ac); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82ac Vertical SS (VSS) write: 0x%04x\n", vss); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82ac Vertical SS (VSS) write: 0x%04x\n", + IoMem_ReadWord(0xff82ac)); } /** @@ -575,9 +558,8 @@ void VIDEL_VSS_WriteWord(void) */ void VIDEL_VCO_WriteWord(void) { - Uint16 vco = IoMem_ReadWord(0xff82c0); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82c0 Video control (VCO) write: 0x%04x\n", vco); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82c0 Video control (VCO) write: 0x%04x\n", + IoMem_ReadWord(0xff82c0)); } /** @@ -585,9 +567,8 @@ void VIDEL_VCO_WriteWord(void) */ void VIDEL_VMD_WriteWord(void) { - Uint16 vdm = IoMem_ReadWord(0xff82c2); - - LOG_TRACE(TRACE_VIDEL, "Videl : $ff82c2 Video Mode (VDM) write: 0x%04x\n", vdm); + LOG_TRACE(TRACE_VIDEL, "Videl : $ff82c2 Video Mode (VDM) write: 0x%04x\n", + IoMem_ReadWord(0xff82c2)); } @@ -649,6 +630,10 @@ static Uint16 VIDEL_getScreenBpp(void) */ static int VIDEL_getScreenWidth(void) { + Uint16 hbb, hbe, hdb, hde, vdm, hht; + Uint16 cycPerPixel, divider; + Sint16 hdb_offset, hde_offset; + Sint16 leftBorder, rightBorder; Uint16 bpp = VIDEL_getScreenBpp(); /* X Size of the Display area */ @@ -670,16 +655,12 @@ static int VIDEL_getScreenWidth(void) return videl.XSize; } - Uint16 hbb = IoMem_ReadWord(0xff8284) & 0x01ff; - Uint16 hbe = IoMem_ReadWord(0xff8286) & 0x01ff; - Uint16 hdb = IoMem_ReadWord(0xff8288) & 0x01ff; - Uint16 hde = IoMem_ReadWord(0xff828a) & 0x01ff; - Uint16 vdm = IoMem_ReadWord(0xff82c2) & 0xc; - Uint16 hht = IoMem_ReadWord(0xff8282) & 0x1ff; - - Uint16 cycPerPixel, divider; - Sint16 hdb_offset, hde_offset; - Sint16 leftBorder, rightBorder; + hbb = IoMem_ReadWord(0xff8284) & 0x01ff; + hbe = IoMem_ReadWord(0xff8286) & 0x01ff; + hdb = IoMem_ReadWord(0xff8288) & 0x01ff; + hde = IoMem_ReadWord(0xff828a) & 0x01ff; + vdm = IoMem_ReadWord(0xff82c2) & 0xc; + hht = IoMem_ReadWord(0xff8282) & 0x1ff; /* Compute cycles per pixel */ if (vdm == 0) @@ -780,7 +761,13 @@ static int VIDEL_getScreenHeight(void) } /* Y Size of the Display area */ - videl.YSize = vde - vdb; + if (vde >= vdb) { + videl.YSize = vde - vdb; + } + else { + LOG_TRACE(TRACE_VIDEL, "WARNING: vde=0x%x is less than vdb=0x%x\n", + vde, vdb); + } /* If the user disabled the borders display from the gui, we suppress them */ if (ConfigureParams.Screen.bAllowOverscan == 0) { @@ -799,7 +786,7 @@ static int VIDEL_getScreenHeight(void) videl.upperBorderSize >>= 1; videl.lowerBorderSize >>= 1; } - + return videl.upperBorderSize + videl.YSize + videl.lowerBorderSize; } @@ -900,17 +887,17 @@ static void VIDEL_updateColors(void) } -void VIDEL_ZoomModeChanged(void) +void VIDEL_ZoomModeChanged(bool bForceChange) { /* User selected another zoom mode, so set a new screen resolution now */ - HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp == 16 ? 16 : ConfigureParams.Screen.nForceBpp); + HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, + videl.save_scrBpp == 16 ? 16 : ConfigureParams.Screen.nForceBpp, + bForceChange); } bool VIDEL_renderScreen(void) { - videl.videoBaseAddr = VIDEL_getVideoramAddress(); // Todo: to be removed when all code is in Videl - /* Atari screen infos */ int vw = VIDEL_getScreenWidth(); int vh = VIDEL_getScreenHeight(); @@ -918,9 +905,12 @@ bool VIDEL_renderScreen(void) int lineoffset = IoMem_ReadWord(0xff820e) & 0x01ff; /* 9 bits */ int linewidth = IoMem_ReadWord(0xff8210) & 0x03ff; /* 10 bits */ + int nextline; bool change = false; + videl.videoBaseAddr = VIDEL_getVideoramAddress(); // Todo: to be removed when all code is in Videl + if (vw > 0 && vw != videl.save_scrWidth) { LOG_TRACE(TRACE_VIDEL, "Videl : width change from %d to %d\n", videl.save_scrWidth, vw); videl.save_scrWidth = vw; @@ -938,7 +928,7 @@ bool VIDEL_renderScreen(void) } if (change) { LOG_TRACE(TRACE_VIDEL, "Videl : video mode change to %dx%d@%d\n", videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp); - HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp == 16 ? 16 : ConfigureParams.Screen.nForceBpp); + HostScreen_setWindowSize(videl.save_scrWidth, videl.save_scrHeight, videl.save_scrBpp == 16 ? 16 : ConfigureParams.Screen.nForceBpp, false); } if (!HostScreen_renderBegin()) @@ -960,11 +950,12 @@ bool VIDEL_renderScreen(void) for me at the moment (and my experiments on the Falcon don't help me). */ - int nextline = linewidth + lineoffset; + nextline = linewidth + lineoffset; - if ((vw<32) || (vh<32)) + if ((vw < 32) || (vh < 32)) { + LOG_TRACE(TRACE_VIDEL, "Videl : %dx%d screen size, not drawing\n", vw, vh); return false; - + } if (videl.save_scrBpp < 16 && videl.hostColorsSync == 0) VIDEL_updateColors(); @@ -974,9 +965,7 @@ bool VIDEL_renderScreen(void) VIDEL_ConvertScreenNoZoom(vw, vh, videl.save_scrBpp, nextline); } - - HostScreen_renderEnd(); - HostScreen_update1(false); + HostScreen_update1(HostScreen_renderEnd(), false); return true; } @@ -1119,10 +1108,13 @@ void VIDEL_ConvertScreenNoZoom(int vw, i int h, w, j; Uint16 *fvram = (Uint16 *) Atari2HostAddr(videl.videoBaseAddr); + Uint16 *fvram_line; Uint8 *hvram = HostScreen_getVideoramAddress(); SDL_PixelFormat *scrfmt = HostScreen_getFormat(); Uint16 lowBorderSize, rightBorderSize; + int scrwidth, scrheight; + int vw_clip, vh_clip; int hscrolloffset = IoMem_ReadByte(0xff8265) & 0x0f; @@ -1139,19 +1131,21 @@ void VIDEL_ConvertScreenNoZoom(int vw, i videl.upperBorderSize = 0; videl.lowerBorderSize = 0; fvram = (Uint16 *) Atari2HostAddr(VIDEL_getVideoramAddress()); + } else { + bTTSampleHold = false; } /* Clip to SDL_Surface dimensions */ - int scrwidth = HostScreen_getWidth(); - int scrheight = HostScreen_getHeight(); - int vw_clip = vw; - int vh_clip = vh; + scrwidth = HostScreen_getWidth(); + scrheight = HostScreen_getHeight(); + vw_clip = vw; + vh_clip = vh; if (vw>scrwidth) vw_clip = scrwidth; if (vh>scrheight) vh_clip = scrheight; /* If emulated computer is the FALCON, we must take : - * vw = X area display size and not all the X screen with the borders into account - * vh = Y area display size and not all the Y screen with the borders into account + * vw = display width without borders + * vh = display height without borders */ if (ConfigureParams.System.nMachineType == MACHINE_FALCON) { vw = videl.XSize; @@ -1191,7 +1185,7 @@ void VIDEL_ConvertScreenNoZoom(int vw, i hvram += ((scrheight-vh_clip)>>1)*scrpitch; hvram += ((scrwidth-vw_clip)>>1)*HostScreen_getBpp(); - Uint16 *fvram_line = fvram; + fvram_line = fvram; scrwidth = videl.leftBorderSize + vw + videl.rightBorderSize; /* render the graphic area */ @@ -1242,6 +1236,17 @@ void VIDEL_ConvertScreenNoZoom(int vw, i /* Right border */ VIDEL_memset_uint8 (hvram_column, HostScreen_getPaletteColor(0), rightBorderSize); + if (bTTSampleHold) { + Uint8 TMPPixel = 0; + for (w=0; w < (vw); w++) { + if (hvram_line[w] == 0) { + hvram_line[w] = TMPPixel; + } else { + TMPPixel = hvram_line[w]; + } + } + } + fvram_line += nextline; hvram_line += scrpitch; } @@ -1420,7 +1425,9 @@ void VIDEL_ConvertScreenNoZoom(int vw, i /* Render the graphical area */ for (h = 0; h < vh; h++) { Uint16 *hvram_column = hvram_line; - +#if SDL_BYTEORDER != SDL_BIG_ENDIAN + Uint16 *fvram_column; +#endif /* Left border first */ VIDEL_memset_uint16 (hvram_column, HostScreen_getPaletteColor(0), videl.leftBorderSize); hvram_column += videl.leftBorderSize; @@ -1432,7 +1439,7 @@ void VIDEL_ConvertScreenNoZoom(int vw, i memcpy(hvram_column, fvram_line, vw<<1); hvram_column += vw<<1; #else - Uint16 *fvram_column = fvram_line; + fvram_column = fvram_line; /* Graphical area */ for (w = 0; w < vw; w++) *hvram_column ++ = SDL_SwapBE16(*fvram_column++); @@ -1506,6 +1513,9 @@ void VIDEL_ConvertScreenZoom(int vw, int int coefx = 1; int coefy = 1; + int scrpitch, scrwidth, scrheight, scrbpp, hscrolloffset; + Uint8 *hvram; + SDL_PixelFormat *scrfmt; /* If emulated computer is the TT, we use the same rendering for display, but without the borders */ if (ConfigureParams.System.nMachineType == MACHINE_TT) { @@ -1516,17 +1526,19 @@ void VIDEL_ConvertScreenZoom(int vw, int videl.XSize = vw; videl.YSize = vh; fvram = (Uint16 *) Atari2HostAddr(VIDEL_getVideoramAddress()); + } else { + bTTSampleHold = false; } /* Host screen infos */ - int scrpitch = HostScreen_getPitch(); - int scrwidth = HostScreen_getWidth(); - int scrheight = HostScreen_getHeight(); - int scrbpp = HostScreen_getBpp(); - SDL_PixelFormat *scrfmt = HostScreen_getFormat(); - Uint8 *hvram = (Uint8 *) HostScreen_getVideoramAddress(); + scrpitch = HostScreen_getPitch(); + scrwidth = HostScreen_getWidth(); + scrheight = HostScreen_getHeight(); + scrbpp = HostScreen_getBpp(); + scrfmt = HostScreen_getFormat(); + hvram = (Uint8 *) HostScreen_getVideoramAddress(); - int hscrolloffset = IoMem_ReadByte(0xff8265) & 0x0f; + hscrolloffset = IoMem_ReadByte(0xff8265) & 0x0f; /* Horizontal scroll register set? */ if (hscrolloffset) { @@ -1576,10 +1588,16 @@ void VIDEL_ConvertScreenZoom(int vw, int /* We reuse the following values to compute the display area size in zoom mode */ /* scrwidth must not change */ if (ConfigureParams.System.nMachineType == MACHINE_FALCON) { + /* get values without borders */ vw = videl.XSize; vh = videl.YSize; scrheight = vh * coefy; } + if (vw < 16) { + Log_Printf(LOG_WARN, "ERROR: Videl <16 screen width (%dx%d without borders)\nIf this happens at TOS boot, remove hatari.nvram,\nNVRAM video settings in it are corrupted.\n", vw, vh); + /* prevent memory corruption */ + return; + } if (vbpp<16) { Uint8 color[16]; @@ -1644,6 +1662,18 @@ void VIDEL_ConvertScreenZoom(int vw, int /* Display the Right border */ VIDEL_memset_uint8 (hvram_column, HostScreen_getPaletteColor(0), videl.rightBorderSize * coefx); hvram_column += videl.rightBorderSize * coefx; + + if (bTTSampleHold) { + Uint8 TMPPixel = 0; + for (w=0; w < (vw*coefx); w++) { + if (hvram_line[w] == 0) { + hvram_line[w] = TMPPixel; + } else { + TMPPixel = hvram_line[w]; + } + } + } + } hvram_line += scrpitch; @@ -2003,3 +2033,191 @@ static void VIDEL_memset_uint8(Uint8 *ad { memset(addr, color, count); } + + + +/** + * Write to videl ST palette registers (0xff8240-0xff825e) + * + * [Laurent]: The following note should be verified on Falcon before being applied. + * + * Note that there's a special "strange" case when writing only to the upper byte + * of the color reg (instead of writing 16 bits at once with .W/.L). + * In that case, the byte written to address x is automatically written + * to address x+1 too (but we shouldn't copy x in x+1 after masking x ; we apply the mask at the end) + * Similarly, when writing a byte to address x+1, it's also written to address x + * So : move.w #0,$ff8240 -> color 0 is now $000 + * move.b #7,$ff8240 -> color 0 is now $707 ! + * move.b #$55,$ff8241 -> color 0 is now $555 ! + * move.b #$71,$ff8240 -> color 0 is now $171 (bytes are first copied, then masked) + */ +static void Videl_ColorReg_WriteWord(void) +{ + Uint16 col; + Uint32 addr = IoAccessCurrentAddress; + + videl.hostColorsSync = false; + + if (bUseHighRes || bUseVDIRes) /* Don't store if hi-res or VDI resolution */ + return; + + /* Note from laurent: The following special case should be verified on the real Falcon before uncommenting */ + /* Handle special case when writing only to the upper byte of the color reg */ +// if ( ( nIoMemAccessSize == SIZE_BYTE ) && ( ( IoAccessCurrentAddress & 1 ) == 0 ) ) +// col = ( IoMem_ReadByte(addr) << 8 ) + IoMem_ReadByte(addr); /* copy upper byte into lower byte */ + /* Same when writing only to the lower byte of the color reg */ +// else if ( ( nIoMemAccessSize == SIZE_BYTE ) && ( ( IoAccessCurrentAddress & 1 ) == 1 ) ) +// col = ( IoMem_ReadByte(addr) << 8 ) + IoMem_ReadByte(addr); /* copy lower byte into upper byte */ + /* Usual case, writing a word or a long (2 words) */ +// else + col = IoMem_ReadWord(addr); + + col &= 0xfff; /* Mask off to 4096 palette */ + + addr &= 0xfffffffe; /* Ensure addr is even to store the 16 bit color */ + + IoMem_WriteWord(addr, col); +} + +/* + * [NP] TODO : due to how .L accesses are handled in ioMem.c, we can't call directly + * Video_ColorReg_WriteWord from ioMemTabFalcon.c, we must use an intermediate + * function, else .L accesses will not change 2 .W color regs, but only one. + * This should be changed in ioMem.c to do 2 separate .W accesses, as would do a real 68000 + */ + +void Videl_Color0_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color1_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color2_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color3_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color4_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color5_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color6_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color7_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color8_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color9_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color10_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color11_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color12_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color13_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color14_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +void Videl_Color15_WriteWord(void) +{ + Videl_ColorReg_WriteWord(); +} + +/** + * display Videl registers values (for debugger info command) + */ +void Videl_Info(FILE *fp, Uint32 dummy) +{ + if (ConfigureParams.System.nMachineType != MACHINE_FALCON) { + fprintf(fp, "Not Falcon - no Videl!\n"); + return; + } + + fprintf(fp, "$FF8006.b : monitor type : %02x\n", IoMem_ReadByte(0xff8006)); + fprintf(fp, "$FF8201.b : Video Base Hi : %02x\n", IoMem_ReadByte(0xff8201)); + fprintf(fp, "$FF8203.b : Video Base Mi : %02x\n", IoMem_ReadByte(0xff8203)); + fprintf(fp, "$FF8205.b : Video Count Hi : %02x\n", IoMem_ReadByte(0xff8205)); + fprintf(fp, "$FF8207.b : Video Count Mi : %02x\n", IoMem_ReadByte(0xff8207)); + fprintf(fp, "$FF8209.b : Video Count Lo : %02x\n", IoMem_ReadByte(0xff8209)); + fprintf(fp, "$FF820A.b : Sync mode : %02x\n", IoMem_ReadByte(0xff820a)); + fprintf(fp, "$FF820D.b : Video Base Lo : %02x\n", IoMem_ReadByte(0xff820d)); + fprintf(fp, "$FF820E.w : offset to next line : %04x\n", IoMem_ReadWord(0xff820e)); + fprintf(fp, "$FF8210.w : VWRAP - line width : %04x\n", IoMem_ReadWord(0xff8210)); + fprintf(fp, "$FF8260.b : ST shift mode : %02x\n", IoMem_ReadByte(0xff8260)); + fprintf(fp, "$FF8264.w : Horizontal scroll register : %04x\n", IoMem_ReadWord(0xff8264)); + fprintf(fp, "$FF8266.w : Falcon shift mode : %04x\n", IoMem_ReadWord(0xff8266)); + fprintf(fp, "\n"); + fprintf(fp, "$FF8280.w : HHC - Horizontal Hold Counter : %04x\n", IoMem_ReadWord(0xff8280)); + fprintf(fp, "$FF8282.w : HHT - Horizontal Hold Timer : %04x\n", IoMem_ReadWord(0xff8282)); + fprintf(fp, "$FF8284.w : HBB - Horizontal Border Begin : %04x\n", IoMem_ReadWord(0xff8284)); + fprintf(fp, "$FF8286.w : HBE - Horizontal Border End : %04x\n", IoMem_ReadWord(0xff8286)); + fprintf(fp, "$FF8288.w : HDB - Horizontal Display Begin : %04x\n", IoMem_ReadWord(0xff8288)); + fprintf(fp, "$FF828A.w : HDE - Horizontal Display End : %04x\n", IoMem_ReadWord(0xff828a)); + fprintf(fp, "$FF828C.w : HSS - Horizontal SS : %04x\n", IoMem_ReadWord(0xff828c)); + fprintf(fp, "$FF828E.w : HFS - Horizontal FS : %04x\n", IoMem_ReadWord(0xff828e)); + fprintf(fp, "$FF8290.w : HEE - Horizontal EE : %04x\n", IoMem_ReadWord(0xff8290)); + fprintf(fp, "\n"); + fprintf(fp, "$FF82A0.w : VFC - Vertical Frequency Counter : %04x\n", IoMem_ReadWord(0xff82a0)); + fprintf(fp, "$FF82A2.w : VFT - Vertical Frequency Timer : %04x\n", IoMem_ReadWord(0xff82a2)); + fprintf(fp, "$FF82A4.w : VBB - Vertical Border Begin : %04x\n", IoMem_ReadWord(0xff82a4)); + fprintf(fp, "$FF82A6.w : VBE - Vertical Border End : %04x\n", IoMem_ReadWord(0xff82a6)); + fprintf(fp, "$FF82A8.w : VDB - Vertical Display Begin : %04x\n", IoMem_ReadWord(0xff82a8)); + fprintf(fp, "$FF82AA.w : VDE - Vertical Display End : %04x\n", IoMem_ReadWord(0xff82aa)); + fprintf(fp, "$FF82AC.w : VSS - Vertical SS : %04x\n", IoMem_ReadWord(0xff82ac)); + fprintf(fp, "\n"); + fprintf(fp, "$FF82C0.w : VCO - Video control : %04x\n", IoMem_ReadWord(0xff82c0)); + fprintf(fp, "$FF82C2.w : VMD - Video mode : %04x\n", IoMem_ReadWord(0xff82c2)); + fprintf(fp, "\n-------------------------\n"); + + fprintf(fp, "Video base : %08x\n", + (IoMem_ReadByte(0xff8201)<<16) + + (IoMem_ReadByte(0xff8203)<<8) + + IoMem_ReadByte(0xff820d)); + fprintf(fp, "Video count : %08x\n", + (IoMem_ReadByte(0xff8205)<<16) + + (IoMem_ReadByte(0xff8207)<<8) + + IoMem_ReadByte(0xff8209)); +}