Re: [hatari-devel] Setting TOS language / keyboard (was: which version of emutos for next Hatari )

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

Attached is implementation for what I proposed.

Comments?

	- Eero

On 8.5.2022 20.12, Eero Tamminen wrote:
On 7.5.2022 12.46, Thomas Huth wrote:
Am Sat, 7 May 2022 10:35:46 +0200
schrieb Christian Zietz <czietz@xxxxxxx>:
Nicolas Pomarède schrieb:
for a next EmuTOS version, could there be a way to choose language from
the boot screen too ? This would make it easier for people using stf/ste
mode where there's no nvram to choose a different language from english
at boot.

Funny, I intended to ask *you* a similar question in my previous mail --
but I forgot to include it.

Could a future Hatari release offer a way to choose the language via its
configuration options?

FYI: new Hatari version has "nLanguage" and "nKbdLayout" settings in the configuration "Keyboard" section, which can be set to desired country code (-1=unset).

One can use "--language" and "--layout" command line options to set them (before saving config):
---------------------------------
$ hatari --language foo
Unrecognized language code 'foo'!

TOS v4 supports:
- us : USA
- de : Germany
- fr : France
- uk : United Kingdom
- es : Spain
- it : Italy
- se : Sweden

EmuTOS 1024k (v1.1.x) supports also:
- ch_fr : Switzerland (French)
- ch_de : Switzerland (German)
- tr : Turkey
- fi : Finland
- no : Norway
- dk : Denmark
- sa : Saudi Arabia
- nl : Holland
- cs : Czech Republic
- hu : Hungary
- ru : Russia
- gr : Greece
---------------------------------


Basically, the 1024k ROM is an "emulator-only" version of EmuTOS [1], as
no Atari machine supports 1024k ROMs. And we created this multi-language
ROM mainly for the benefit of emulators not having to ship N different
language versions.

Anyway, I'm Cc'ing your question to the EmuTOS list, since I'm not sure
if EmuTOS would even support a language change at runtime. As soon as
the boot screen is shown, one language has obviously already been selected.

I think the best way would be to patch the ROM header of EmuTOS in Hatari
according to the LANG environment variable. IIRC EmuTOS honors the language setting in the ROM header, too, so that would be an easy solution as far as
I can tell.

As there's already Hatari config & CLI options support for the NVRAM setting and 2-letter country code => TOS country code value mapping code, adding LANG parsing + setting TOS header value should not be much additional code.

The problem with the OS header country code is that it affects *both* language and keyboard layout, but:
* LANG env var is only about language
* quite a few people want keyboard setting different from language setting

IMHO clearest would be to:
* Default Keyboard.nLanguage to a country code  based on LANG i.e. it would normally just affect NVRAM setting * Set OS header country code only when both Keyboard.nLanguage and Keyboard.nKbdLayout values match


     - Eero

From 0e9eb2417adeea40c5906baad667636a7586245f Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Thu, 12 May 2022 21:45:09 +0300
Subject: [PATCH 2/2] Take language option default from the LANG environment
 variable

---
 doc/hatari.1          |  2 +-
 doc/manual.html       |  3 ++-
 doc/release-notes.txt |  1 +
 src/includes/tos.h    |  1 +
 src/main.c            |  2 ++
 src/tos.c             | 32 ++++++++++++++++++++++++++++++--
 6 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/doc/hatari.1 b/doc/hatari.1
index 61c35fff..f35b91eb 100644
--- a/doc/hatari.1
+++ b/doc/hatari.1
@@ -73,7 +73,7 @@ layouts
 .B \-\-language <x>
 Set NVRAM language value. While both TT and Falcon machines have
 NVRAM, only TOS v4 and EmuTOS 1024k ROM versions support multiple
-languages.
+languages.  Default is taken from the LANG environment variable.
 
 On machines without NVRAM, and a TOS image with country code 127 (=
 multi-language support), TOS country code is overriden when both
diff --git a/doc/manual.html b/doc/manual.html
index b448356b..4e6b98f4 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -576,7 +576,8 @@ While both TT and Falcon machines have NVRAM, only TOS v4 and EmuTOS
 <p class="parameter">--language &lt;x&gt;</p>
 <p class="paramdesc">Set NVRAM language value.
 While both TT and Falcon machines have NVRAM, only TOS v4 and EmuTOS
-1024k ROM versions support multiple languages.
+1024k ROM versions support multiple languages.  Default is taken from
+the LANG environment variable.
 </p><p class="parameter">
 On machines without NVRAM, and a TOS image with country code 127 (=
 multi-language support), TOS country code is overriden when both
diff --git a/doc/release-notes.txt b/doc/release-notes.txt
index a4801a60..8de81d56 100644
--- a/doc/release-notes.txt
+++ b/doc/release-notes.txt
@@ -76,6 +76,7 @@ Emulator improvements:
     and language values at start.  Setting both language and keyboard
     layout options to same value, allows also (multi-language) TOS
     country code to be overridden (useful on machines without NVRAM)
+  - Language default is taken from the LANG environment variable
 - TT/Falcon:
   - Increase max TT-RAM amount to 1024 MiB
 - Falcon:
diff --git a/src/includes/tos.h b/src/includes/tos.h
index 8a5fce43..9c8904c1 100644
--- a/src/includes/tos.h
+++ b/src/includes/tos.h
@@ -51,6 +51,7 @@ extern void TOS_MemorySnapShot_Capture(bool bSave);
 extern int TOS_InitImage(void);
 extern void TOS_SetTestPrgName(const char *testprg);
 
+extern int TOS_DefaultLanguage(void);
 extern int TOS_ParseCountryCode(const char *code, const char *info);
 extern const char *TOS_LanguageName(int code);
 
diff --git a/src/main.c b/src/main.c
index 680c089e..c68edb95 100644
--- a/src/main.c
+++ b/src/main.c
@@ -839,6 +839,8 @@ static void Main_LoadInitialConfig(void)
 
 	/* Now try the users configuration file */
 	Configuration_Load(NULL);
+	if (ConfigureParams.Keyboard.nLanguage == TOS_LANG_UNKNOWN)
+		ConfigureParams.Keyboard.nLanguage = TOS_DefaultLanguage();
 }
 
 /*-----------------------------------------------------------------------*/
diff --git a/src/tos.c b/src/tos.c
index 83618b1b..d930fc02 100644
--- a/src/tos.c
+++ b/src/tos.c
@@ -1271,8 +1271,8 @@ static const struct {
 
 /**
  * TOS_ValidCountryCode: returns parsed country code if
- * it's recognized, otherwise valid ones are shown and
- * TOS_LANG_UNKNOWN is returned
+ * it's recognized, otherwise TOS_LANG_UNKNOWN is returned.
+ * If info is set, valid ones are shown in latter case
  */
 int TOS_ParseCountryCode(const char *code, const char *info)
 {
@@ -1281,6 +1281,9 @@ int TOS_ParseCountryCode(const char *code, const char *info)
 			return countries[i].value;
 		}
 	}
+	if (!info) {
+		return TOS_LANG_UNKNOWN;
+	}
 	fprintf(stderr, "Unrecognized %s code '%s'!\n", info, code);
 
 	fprintf(stderr, "\nTOS v4 supports:\n");
@@ -1293,6 +1296,31 @@ int TOS_ParseCountryCode(const char *code, const char *info)
 	return TOS_LANG_UNKNOWN;
 }
 
+/**
+ * TOS_DefaultLanguage: return TOS country code matching LANG
+ * environment variable. Supports LANG formats: "uk", "en_UK.*"
+ */
+int TOS_DefaultLanguage(void)
+{
+	int len;
+	const char *lang = getenv("LANG");
+	if (!lang)
+		return TOS_LANG_UNKNOWN;
+
+	len = strlen(lang);
+	if (len == 2)
+		return TOS_ParseCountryCode(lang, NULL);
+
+	if (len >= 5 && lang[2] == '_') {
+		char cc[3];
+		cc[0] = tolower(lang[3]);
+		cc[1] = tolower(lang[4]);
+		cc[2] = '\0';
+		return TOS_ParseCountryCode(cc, NULL);
+	}
+	return TOS_LANG_UNKNOWN;
+}
+
 /**
  * TOS_LanguageName: return name for given country code
  */
-- 
2.30.2

From fe37a3b6e0932458eab5fcd7dd5f574cccd0c18e Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Thu, 12 May 2022 21:29:43 +0300
Subject: [PATCH 1/2] Override TOS country code when language + layout set to
 same value

---
 doc/hatari.1          |  6 +++++-
 doc/manual.html       |  6 +++++-
 doc/release-notes.txt |  4 +++-
 src/tos.c             | 20 ++++++++++++++++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/hatari.1 b/doc/hatari.1
index 89d3ead3..61c35fff 100644
--- a/doc/hatari.1
+++ b/doc/hatari.1
@@ -73,7 +73,11 @@ layouts
 .B \-\-language <x>
 Set NVRAM language value. While both TT and Falcon machines have
 NVRAM, only TOS v4 and EmuTOS 1024k ROM versions support multiple
-languages
+languages.
+
+On machines without NVRAM, and a TOS image with country code 127 (=
+multi-language support), TOS country code is overriden when both
+layout and language options are set to same value
 .TP
 .B \-\-fast\-forward <bool>
 Fast-forward through the boring parts by running emulator at maximum
diff --git a/doc/manual.html b/doc/manual.html
index 0ea2da37..b448356b 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -576,7 +576,11 @@ While both TT and Falcon machines have NVRAM, only TOS v4 and EmuTOS
 <p class="parameter">--language &lt;x&gt;</p>
 <p class="paramdesc">Set NVRAM language value.
 While both TT and Falcon machines have NVRAM, only TOS v4 and EmuTOS
-1024k ROM versions support multiple languages</p>
+1024k ROM versions support multiple languages.
+</p><p class="parameter">
+On machines without NVRAM, and a TOS image with country code 127 (=
+multi-language support), TOS country code is overriden when both
+layout and language options are set to same value</p>
 <p class="parameter">--fast-forward
 &lt;bool&gt;</p>
 <p class="paramdesc">On fast machine helps skipping (fast
diff --git a/doc/release-notes.txt b/doc/release-notes.txt
index 33207946..a4801a60 100644
--- a/doc/release-notes.txt
+++ b/doc/release-notes.txt
@@ -73,7 +73,9 @@ Emulator improvements:
     there's no exact full match
 - NVRAM:
   - Config settings + CLI options to override NVRAM keyboard layout
-    and language values at start
+    and language values at start.  Setting both language and keyboard
+    layout options to same value, allows also (multi-language) TOS
+    country code to be overridden (useful on machines without NVRAM)
 - TT/Falcon:
   - Increase max TT-RAM amount to 1024 MiB
 - Falcon:
diff --git a/src/tos.c b/src/tos.c
index df0f21bf..83618b1b 100644
--- a/src/tos.c
+++ b/src/tos.c
@@ -1103,6 +1103,7 @@ int TOS_InitImage(void)
 {
 	uint8_t *pTosFile = NULL;
 	Uint32 logopatch_addr = 0;
+	Uint16 osconf, countrycode;
 
 	bTosImageLoaded = false;
 
@@ -1179,6 +1180,25 @@ int TOS_InitImage(void)
 		Log_Printf(LOG_DEBUG, "Skipped TOS patches.\n");
 	}
 
+	/* if TOS supports multiple languages, override its
+	 * country code when both Hatari language & KBD layout
+	 * settings match (otherwise those affect just NVRAM)
+	 */
+	osconf = STMemory_ReadWord(TosAddress+0x1C);
+	countrycode = osconf >> 1;
+	if (countrycode == TOS_LANG_ALL &&
+	    ConfigureParams.Keyboard.nLanguage != TOS_LANG_UNKNOWN &&
+	    ConfigureParams.Keyboard.nLanguage == ConfigureParams.Keyboard.nKbdLayout)
+	{
+		countrycode = ConfigureParams.Keyboard.nLanguage;
+		/* low bit: us -> NTSC (0), any other -> PAL (1) */
+		osconf = (countrycode << 1) | (countrycode?1:0);
+		STMemory_WriteWord(TosAddress+0x1C, osconf);
+		Log_Printf(LOG_WARN, "=> TOS country code: %d (%s), %s\n",
+			   countrycode, TOS_LanguageName(countrycode),
+			   (osconf & 1) ? "PAL" : "NTSC");
+	}
+
 	/*
 	 * patch some values into the "Draw logo" patch.
 	 * Needs to be called after final VDI resolution has been determined.
-- 
2.30.2



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/