--- hatari/src/falcon/nvram.c 2019/04/09 08:50:32 1.1.1.5 +++ hatari/src/falcon/nvram.c 2019/04/09 08:59:32 1.1.1.8 @@ -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 @@ -35,13 +35,7 @@ const char NvRam_fileid[] = "Hatari nvra #include "log.h" #include "nvram.h" #include "paths.h" - -#define DEBUG 0 -#if DEBUG -#define Dprintf(a) printf a -#else -#define Dprintf(a) -#endif +#include "vdi.h" // Defs for checksum @@ -64,17 +58,6 @@ 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) @@ -87,10 +70,14 @@ static bool NvRam_Load(void) if (fread(fnvram, 1, NVRAM_LEN, f) == NVRAM_LEN) { memcpy(nvram+NVRAM_START, fnvram, NVRAM_LEN); + LOG_TRACE(TRACE_NVRAM, "NVRAM: loaded from '%s'\n", nvram_filename); ret = true; } + else + { + Log_Printf(LOG_WARN, "NVRAM loading from '%s' failed\n", nvram_filename); + } fclose(f); - Log_Printf(LOG_DEBUG, "NVRAM loaded from '%s'\n", nvram_filename); } else { @@ -113,13 +100,18 @@ static bool NvRam_Save(void) { if (fwrite(nvram+NVRAM_START, 1, NVRAM_LEN, f) == NVRAM_LEN) { + LOG_TRACE(TRACE_NVRAM, "NVRAM: saved to '%s'\n", nvram_filename); ret = true; } + else + { + Log_Printf(LOG_WARN, "Writing 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, "Storing NVRAM to '%s' failed\n", nvram_filename); } return ret; @@ -142,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; +} /*-----------------------------------------------------------------------*/ /** @@ -262,8 +307,8 @@ void NvRam_Data_ReadByte(void) { value = nvram[nvram_index]; } - Dprintf(("Reading NVRAM data at %d = %d ($%02x)\n", nvram_index, value, value)); + LOG_TRACE(TRACE_NVRAM, "NVRAM: read data at %d = %d ($%02x)\n", nvram_index, value, value); IoMem_WriteByte(0xff8963, value); } @@ -276,6 +321,6 @@ void NvRam_Data_ReadByte(void) void NvRam_Data_WriteByte(void) { Uint8 value = IoMem_ReadByte(0xff8963); - Dprintf(("Writing NVRAM data at %d = %d ($%02x)\n", nvram_index, value, value)); + LOG_TRACE(TRACE_NVRAM, "NVRAM: write data at %d = %d ($%02x)\n", nvram_index, value, value); nvram[nvram_index] = value; }