--- hatari/src/falcon/nvram.c 2019/04/01 07:13:46 1.1 +++ 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 @@ -27,7 +27,7 @@ All other cells are reserved / unused. */ -const char NvRam_rcsid[] = "Hatari $Id: nvram.c,v 1.1 2019/04/01 07:13:46 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 @@ -54,7 +47,7 @@ const char NvRam_rcsid[] = "Hatari $Id: #define NVRAM_START 14 #define NVRAM_LEN 50 -static uint8 nvram[64] = { 48,255,21,255,23,255,1,25,3,33,42,14,112,128, +static Uint8 nvram[64] = { 48,255,21,255,23,255,1,25,3,33,42,14,112,128, 0,0,0,0,0,0,0,0,17,46,32,1,255,0,1,10,135,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; @@ -65,33 +58,26 @@ 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) +static bool NvRam_Load(void) { - BOOL ret = FALSE; + bool ret = false; FILE *f = fopen(nvram_filename, "rb"); if (f != NULL) { - uint8 fnvram[NVRAM_LEN]; + Uint8 fnvram[NVRAM_LEN]; 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, "NVRAM loading from '%s' failed\n", nvram_filename); } fclose(f); - Log_Printf(LOG_DEBUG, "NVRAM loaded from '%s'\n", nvram_filename); } else { @@ -106,21 +92,26 @@ static BOOL NvRam_Load(void) /** * Save NVRAM data to file */ -static BOOL NvRam_Save(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, "Writing NVRAM to '%s' failed\n", nvram_filename); } fclose(f); } else { - Log_Printf(LOG_ERROR, "ERROR: cannot store NVRAM to '%s'\n", nvram_filename); + Log_Printf(LOG_WARN, "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; +} /*-----------------------------------------------------------------------*/ /** @@ -162,13 +206,17 @@ void NvRam_Init(void) if (!NvRam_Load()) // load NVRAM file automatically { - if (ConfigureParams.Screen.MonitorType == MONITOR_TYPE_VGA) // VGA ? + 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(); } @@ -222,7 +270,7 @@ void NvRam_Select_WriteByte(void) */ void NvRam_Data_ReadByte(void) { - uint8 value = 0; + Uint8 value = 0; if (nvram_index == NVRAM_SECONDS || nvram_index == NVRAM_MINUTES || nvram_index == NVRAM_HOURS || (nvram_index >=NVRAM_DAY && nvram_index <=NVRAM_YEAR) ) @@ -242,7 +290,7 @@ void NvRam_Data_ReadByte(void) } else if (nvram_index == 10) { - static BOOL rtc_uip = TRUE; + static bool rtc_uip = true; value = rtc_uip ? 0x80 : 0; rtc_uip = !rtc_uip; } @@ -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; } -