--- hatari/src/falcon/nvram.c 2019/04/01 07:14:55 1.1.1.2 +++ hatari/src/falcon/nvram.c 2019/04/09 08:55:49 1.1.1.7 @@ -1,8 +1,8 @@ /* Hatari - nvram.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. This file is partly based on GPL code taken from the Aranym project. - Copyright (c) 2001-2004 Petr Stehlik of ARAnyM dev team @@ -15,7 +15,7 @@ Byte: Description: - 14-15 Prefered operating system (TOS, Unix) + 14-15 Preferred operating system (TOS, Unix) 20 Language 21 Keyboard layout 22 Format of date/time @@ -27,7 +27,7 @@ All other cells are reserved / unused. */ -const char NvRam_rcsid[] = "Hatari $Id: nvram.c,v 1.1.1.2 2019/04/01 07:14:55 root Exp $"; +const char NvRam_fileid[] = "Hatari nvram.c : " __DATE__ " " __TIME__; #include "main.h" #include "configuration.h" @@ -35,15 +35,8 @@ const char NvRam_rcsid[] = "Hatari $Id: #include "log.h" #include "nvram.h" #include "paths.h" -#include "araglue.h" +#include "vdi.h" -#define DEBUG 0 - -#if DEBUG -#define D(x) x -#else -#define D(x) -#endif // Defs for checksum #define CKS_RANGE_START 14 @@ -65,22 +58,11 @@ static char nvram_filename[FILENAME_MAX] /*-----------------------------------------------------------------------*/ /** - * NvRam_Reset: Called during init and reset, used for resetting the - * emulated chip. - */ -void NvRam_Reset(void) -{ - nvram_index = 0; -} - - -/*-----------------------------------------------------------------------*/ -/** * Load NVRAM data from file. */ static bool NvRam_Load(void) { - bool ret = FALSE; + bool ret = false; FILE *f = fopen(nvram_filename, "rb"); if (f != NULL) { @@ -88,10 +70,14 @@ static bool NvRam_Load(void) if (fread(fnvram, 1, NVRAM_LEN, f) == NVRAM_LEN) { memcpy(nvram+NVRAM_START, fnvram, NVRAM_LEN); - ret = TRUE; + LOG_TRACE(TRACE_NVRAM, "NVRAM: loaded from '%s'\n", nvram_filename); + ret = true; + } + else + { + Log_Printf(LOG_WARN, "ERROR: NVRAM loading from '%s' failed\n", nvram_filename); } fclose(f); - Log_Printf(LOG_DEBUG, "NVRAM loaded from '%s'\n", nvram_filename); } else { @@ -108,19 +94,24 @@ static bool NvRam_Load(void) */ static bool NvRam_Save(void) { - bool ret = FALSE; + bool ret = false; FILE *f = fopen(nvram_filename, "wb"); if (f != NULL) { if (fwrite(nvram+NVRAM_START, 1, NVRAM_LEN, f) == NVRAM_LEN) { - ret = TRUE; + LOG_TRACE(TRACE_NVRAM, "NVRAM: saved to '%s'\n", nvram_filename); + ret = true; + } + else + { + Log_Printf(LOG_WARN, "ERROR: storing NVRAM to '%s' failed\n", nvram_filename); } fclose(f); } else { - Log_Printf(LOG_WARN, "ERROR: cannot store NVRAM to '%s'\n", nvram_filename); + Log_Printf(LOG_WARN, "ERROR: storing NVRAM to '%s' failed\n", nvram_filename); } return ret; @@ -143,6 +134,59 @@ static void NvRam_SetChecksum(void) nvram[NVRAM_CHKSUM2] = sum; } +/*-----------------------------------------------------------------------*/ +/** + * NvRam_Reset: Called during init and reset, used for resetting the + * emulated chip. + */ +void NvRam_Reset(void) +{ + if (bUseVDIRes) + { + /* The objective is to start the TOS with a video mode similar + * to the requested one. This is important for the TOS to initialize + * the right font height and palette. */ + if (VDIHeight < 400) + { + /* This will select the 8x8 system font */ + switch(VDIPlanes) + { + /* The case 1 is not handled, because that would result in 0x0000 + * which is an invalide video mode. This does not matter, + * since any color palette is good for monochrome, anyway. */ + case 2: /* set 320x200x4 colors */ + nvram[NVRAM_VMODE1] = 0x00; + nvram[NVRAM_VMODE2] = 0x01; + break; + case 4: /* set 320x200x16 colors */ + default: + nvram[NVRAM_VMODE1] = 0x00; + nvram[NVRAM_VMODE2] = 0x02; + } + } + else + { + /* This will select the 8x16 system font */ + switch(VDIPlanes) + { + case 4: /* set 640x400x16 colors */ + nvram[NVRAM_VMODE1] = 0x01; + nvram[NVRAM_VMODE2] = 0x0a; + break; + case 2: /* set 640x400x4 colors */ + nvram[NVRAM_VMODE1] = 0x01; + nvram[NVRAM_VMODE2] = 0x09; + break; + case 1: /* set 640x400x2 colors */ + default: + nvram[NVRAM_VMODE1] = 0x01; + nvram[NVRAM_VMODE2] = 0x08; + } + } + NvRam_SetChecksum(); + } + nvram_index = 0; +} /*-----------------------------------------------------------------------*/ /** @@ -164,11 +208,15 @@ void NvRam_Init(void) { if (ConfigureParams.Screen.nMonitorType == MONITOR_TYPE_VGA) // VGA ? { - nvram[NVRAM_MONITOR] |= 32; // VGA mode + nvram[NVRAM_VMODE1] &= ~0x01; // No doublescan + nvram[NVRAM_VMODE2] |= 0x10; // VGA mode + nvram[NVRAM_VMODE2] &= ~0x20; // 60 Hz } else { - nvram[NVRAM_MONITOR] &= ~32; // TV/RGB mode + nvram[NVRAM_VMODE1] |= 0x01; // Interlaced + nvram[NVRAM_VMODE2] &= ~0x10; // TV/RGB mode + nvram[NVRAM_VMODE2] |= 0x20; // 50 Hz } NvRam_SetChecksum(); } @@ -259,8 +307,8 @@ void NvRam_Data_ReadByte(void) { value = nvram[nvram_index]; } - D(bug("Reading NVRAM data at %d = %d ($%02x)", nvram_index, value, value)); + LOG_TRACE(TRACE_NVRAM, "NVRAM: read data at %d = %d ($%02x)\n", nvram_index, value, value); IoMem_WriteByte(0xff8963, value); } @@ -273,7 +321,6 @@ void NvRam_Data_ReadByte(void) void NvRam_Data_WriteByte(void) { Uint8 value = IoMem_ReadByte(0xff8963); - D(bug("Writing NVRAM data at %d = %d ($%02x)", nvram_index, value, value)); + LOG_TRACE(TRACE_NVRAM, "NVRAM: write data at %d = %d ($%02x)\n", nvram_index, value, value); nvram[nvram_index] = value; } -