From 6bca0424e4800f0cb1d6bd94ca5051aa3dd0effb Mon Sep 17 00:00:00 2001 From: Yu-Ming Chang Date: Tue, 19 May 2020 17:50:32 +0800 Subject: [PATCH 1/3] Add vt100 support to windows port. --- ports/windows/windows_mphal.c | 24 ++++++++++++++++++++++++ ports/windows/windows_mphal.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 8ed087358f567..ae06516afba7a 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -44,6 +44,7 @@ STATIC void assure_stdin_handle() { } } +#if !MICROPY_HAL_HAS_VT100 STATIC void assure_conout_handle() { if (!con_out) { con_out = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, @@ -52,6 +53,7 @@ STATIC void assure_conout_handle() { assert(con_out != INVALID_HANDLE_VALUE); } } +#endif void mp_hal_stdio_mode_raw(void) { assure_stdin_handle(); @@ -60,6 +62,9 @@ void mp_hal_stdio_mode_raw(void) { mode &= ~ENABLE_ECHO_INPUT; mode &= ~ENABLE_LINE_INPUT; mode &= ~ENABLE_PROCESSED_INPUT; +#if MICROPY_HAL_HAS_VT100 + mode |= ENABLE_VIRTUAL_TERMINAL_INPUT; +#endif SetConsoleMode(std_in, mode); } @@ -105,6 +110,7 @@ void mp_hal_set_interrupt_char(char c) { } } +#if !MICROPY_HAL_HAS_VT100 void mp_hal_move_cursor_back(uint pos) { if (!pos) { return; @@ -184,8 +190,25 @@ STATIC int esc_seq_chr() { } return 0; } +#endif int mp_hal_stdin_rx_chr(void) { +#if MICROPY_HAL_HAS_VT100 + assure_stdin_handle(); + DWORD num_read; + char inchar; + LPVOID buf = &inchar; + for (;;) { + BOOL read_ok; + read_ok = ReadFile(std_in, buf, 1, &num_read, NULL); + if (!read_ok || !num_read) { + continue; + } + else { + return inchar; + } + } +#else // currently processing escape seq? const int ret = esc_seq_chr(); if (ret) { @@ -218,6 +241,7 @@ int mp_hal_stdin_rx_chr(void) { return c; } } +#endif } void mp_hal_stdout_tx_strn(const char *str, size_t len) { diff --git a/ports/windows/windows_mphal.h b/ports/windows/windows_mphal.h index 2b7aab44a0fd4..846d624615108 100644 --- a/ports/windows/windows_mphal.h +++ b/ports/windows/windows_mphal.h @@ -29,8 +29,10 @@ #define MICROPY_HAL_HAS_VT100 (0) +#if !MICROPY_HAL_HAS_VT100 void mp_hal_move_cursor_back(unsigned int pos); void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase); +#endif #undef mp_hal_ticks_cpu mp_uint_t mp_hal_ticks_cpu(void); From a003ec4c819242ef84d5c58b16308a56f2594e0f Mon Sep 17 00:00:00 2001 From: Yu-Ming Chang Date: Wed, 20 May 2020 15:22:54 +0800 Subject: [PATCH 2/3] Fix code format. --- ports/windows/windows_mphal.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index ae06516afba7a..90a1e42bef49c 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -62,9 +62,9 @@ void mp_hal_stdio_mode_raw(void) { mode &= ~ENABLE_ECHO_INPUT; mode &= ~ENABLE_LINE_INPUT; mode &= ~ENABLE_PROCESSED_INPUT; -#if MICROPY_HAL_HAS_VT100 + #if MICROPY_HAL_HAS_VT100 mode |= ENABLE_VIRTUAL_TERMINAL_INPUT; -#endif + #endif SetConsoleMode(std_in, mode); } @@ -193,13 +193,13 @@ STATIC int esc_seq_chr() { #endif int mp_hal_stdin_rx_chr(void) { -#if MICROPY_HAL_HAS_VT100 + #if MICROPY_HAL_HAS_VT100 assure_stdin_handle(); + BOOL read_ok; DWORD num_read; char inchar; LPVOID buf = &inchar; for (;;) { - BOOL read_ok; read_ok = ReadFile(std_in, buf, 1, &num_read, NULL); if (!read_ok || !num_read) { continue; @@ -208,7 +208,7 @@ int mp_hal_stdin_rx_chr(void) { return inchar; } } -#else + #else // currently processing escape seq? const int ret = esc_seq_chr(); if (ret) { @@ -241,7 +241,7 @@ int mp_hal_stdin_rx_chr(void) { return c; } } -#endif + #endif } void mp_hal_stdout_tx_strn(const char *str, size_t len) { From e207c95de7593b14765864e2eb0ccbaa1efcf574 Mon Sep 17 00:00:00 2001 From: Yu-Ming Chang Date: Wed, 20 May 2020 15:27:59 +0800 Subject: [PATCH 3/3] Fix else format. --- ports/windows/windows_mphal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 90a1e42bef49c..50db47968d79c 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -203,8 +203,7 @@ int mp_hal_stdin_rx_chr(void) { read_ok = ReadFile(std_in, buf, 1, &num_read, NULL); if (!read_ok || !num_read) { continue; - } - else { + } else { return inchar; } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy