~rabbits/public-inbox

uxn: Use UTF8 as default console code page in Windows. v1 PROPOSED

~ismael-vc: 1
 Use UTF8 as default console code page in Windows.

 2 files changed, 25 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rabbits/public-inbox/patches/54950/mbox | git am -3
Learn more about email & git

[PATCH uxn 1/1] Use UTF8 as default console code page in Windows. Export this patch

From: Ismael Venegas Castelló <ismael.vc1337@gmail.com>

---
 src/uxncli.c | 15 +++++++++++++++
 src/uxnemu.c | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/uxncli.c b/src/uxncli.c
index 859fa2d..1fab9be 100644
--- a/src/uxncli.c
+++ b/src/uxncli.c
@@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>

#ifdef _WIN32
#include <windows.h>
#endif

#include "uxn.h"
#include "devices/system.h"
#include "devices/console.h"
@@ -20,6 +24,10 @@ WITH REGARD TO THIS SOFTWARE.

Uxn uxn;

#ifdef _WIN32
UINT originalCP;
#endif

Uint8
emu_dei(Uint8 addr)
{
@@ -58,6 +66,9 @@ emu_run(void)
static int
emu_end(void)
{
#ifdef _WIN32
	SetConsoleOutputCP(originalCP);
#endif
	free(uxn.ram);
	return uxn.dev[0x0f] & 0x7f;
}
@@ -74,6 +85,10 @@ main(int argc, char **argv)
	rom = i == argc ? "boot.rom" : argv[i++];
	if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom))
		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
#ifdef _WIN32
	originalCP = GetConsoleOutputCP();
	SetConsoleOutputCP(CP_UTF8);
#endif
	/* Event Loop */
	uxn.dev[0x17] = argc - i;
	if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10))
diff --git a/src/uxnemu.c b/src/uxnemu.c
index 7fa6317..aee285f 100644
--- a/src/uxnemu.c
+++ b/src/uxnemu.c
@@ -19,6 +19,7 @@
#include "devices/datetime.h"
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT > 0x0602
#include <processthreadsapi.h>
#include <windows.h>
#elif defined(_WIN32)
#include <windows.h>
#include <string.h>
@@ -48,6 +49,10 @@ WITH REGARD TO THIS SOFTWARE.

Uxn uxn;

#ifdef _WIN32
UINT originalCP;
#endif

static SDL_Window *emu_window;
static SDL_Texture *emu_texture;
static SDL_Renderer *emu_renderer;
@@ -448,6 +453,7 @@ emu_end(void)
{
	SDL_CloseAudioDevice(audio_id);
#ifdef _WIN32
	SetConsoleOutputCP(originalCP);
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
	TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0);
#elif !defined(__APPLE__)
@@ -481,6 +487,10 @@ main(int argc, char **argv)
		return system_error("usage:", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]");
	if(!emu_init())
		return system_error("Init", "Failed to initialize varvara.");
#ifdef _WIN32
	originalCP = GetConsoleOutputCP();
	SetConsoleOutputCP(CP_UTF8);
#endif
	/* loop */
	uxn.dev[0x17] = argc - i;
	if(uxn_eval(PAGE_PROGRAM)) {
-- 
2.45.2