From 522d0aafc73e4412439921e2dcd10f698984a94f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 22 Apr 2025 04:49:35 +0300 Subject: DOS: implemented console size detection This is done via 10h interrupts and special memory regions. The alternative would have been to use set the cursor to 9999,9999 and query the cursor position via ANSI escape sequences. --- Makefile.wcc | 3 ++- teco.h | 4 ++++ tecterm.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Makefile.wcc b/Makefile.wcc index 21d1b8e..ffee78c 100644 --- a/Makefile.wcc +++ b/Makefile.wcc @@ -24,7 +24,8 @@ LDFLAGS += format dos option map option stack=16k & set WCC_DEFS=-dSTDC_HEADERS=1 -dHAVE_STDIO_H -dHAVE_CTYPE_H -dHAVE_ERRNO_H & -dHAVE_STRING_H -dHAVE_STRINGS_H -dHAVE_FCNTL_H -dHAVE_IO_H & -dHAVE_SYS_STAT_H -dHAVE_SIGNAL_H -dHAVE_STDLIB_H -dHAVE_UNISTD_H & - -dHAVE_STDINT_H -dHAVE_DIRECT_H -dHAVE_SBRK -dHAVE_STRCHR -dTERMCAP + -dHAVE_STDINT_H -dHAVE_DIRECT_H -dHAVE_I86_H & + -dHAVE_SBRK -dHAVE_STRCHR -dTERMCAP all : teco.exe .SYMBOLIC diff --git a/teco.h b/teco.h index c72fb03..c5cc417 100644 --- a/teco.h +++ b/teco.h @@ -477,6 +477,10 @@ typedef unsigned long teco_ptrint_t; #include #endif +#if HAVE_I86_H +#include +#endif + #if HAVE_SYS_WAIT_H # include #endif diff --git a/tecterm.c b/tecterm.c index 5b5d116..c1c9220 100644 --- a/tecterm.c +++ b/tecterm.c @@ -1069,6 +1069,32 @@ term_flush() }/* End Routine */ +#ifdef MSDOS + +#define VIDEO 0x10 + +static int +term_isvga(void) +{ + union REGS regs; + regs.x.ax = 0x1a00; + int86(VIDEO, ®s, ®s); + return regs.h.al == 0x1a && regs.h.bl > 6; +} + +static int +term_isega(void) +{ + union REGS regs; + if(term_isvga()) return 0; + regs.h.ah = 0x12; + regs.h.bl = 0x10; + int86(VIDEO, ®s, ®s); + return regs.h.bl != 0x10; +} + +#endif + /** @@ -1115,6 +1141,15 @@ init_term_description( void ) * really knows the size of the terminal window, and in this case, we will * leave it alone. */ +#ifdef MSDOS + /* + * NOTE: It could also be done generically with + * term_goto(9999,9999), followed by \e[6n + */ + if(!term_columns) term_columns = *(uint8_t*)MK_FP(0x40,0x4a) & 255; + if(!term_lines && (term_isvga() || term_isega())) term_lines = *(uint8_t*)MK_FP(0x40,0x84) + 1; +#endif + #ifdef TERMCAP if(!term_columns) term_columns = tgetnum("co"); if(!term_lines) term_lines = tgetnum("li"); -- cgit v1.2.3