From a4e47b5b99362268dc01fa02cd33f22e95d5e56f Mon Sep 17 00:00:00 2001 From: nidud Date: Sat, 14 Dec 2024 22:37:07 +0100 Subject: [PATCH] 2.36.10 --- include/conio.inc | 5 +- include/libc.inc | 2 +- include/stdio.inc | 13 +- source/libc/conio/_getcursor.asm | 2 +- source/libc/conio/_readansi.asm | 132 ++++++++++-------- source/libc/conio/_treadinput.asm | 2 +- source/libc/conio/ttyapi.asm | 2 +- source/libc/stdio/_fflushb.asm | 18 +-- source/libc/stdio/_fgetb.asm | 18 +-- source/libc/stdio/_fputb.asm | 14 +- source/libc/stdio/ftbuf.asm | 12 +- source/libc/stdio/getst.asm | 2 +- source/libc/stdio/stbuf.asm | 2 - .../test/libc/conio/_terminal/_terminal.asm | 37 +++-- 14 files changed, 153 insertions(+), 108 deletions(-) diff --git a/include/conio.inc b/include/conio.inc index 19f96b08..1732835b 100644 --- a/include/conio.inc +++ b/include/conio.inc @@ -620,7 +620,7 @@ rsmodal proto __cdecl :PIDD ;;; -.template AnsiEscapeCode +.template CINPUT final db ? ; (0x40–0x7E) count db ? ; (0x30–0x39) -> 1;2;3 @@ -628,8 +628,9 @@ rsmodal proto __cdecl :PIDD inter db ? ; (0x20–0x2F) n dd 7 dup(?) .ends + PCINPUT typedef ptr CINPUT -_readansi proto __cdecl :ptr AnsiEscapeCode +_readansi proto __cdecl :PCINPUT _readinputA proto __cdecl :PINPUT_RECORD _readinputW proto __cdecl :PINPUT_RECORD _kbflushA proto __cdecl diff --git a/include/libc.inc b/include/libc.inc index d31215c0..7524ddf2 100644 --- a/include/libc.inc +++ b/include/libc.inc @@ -5,7 +5,7 @@ define __LIBC_INC ; Master include file for the Asmc Run Time library. ; define __STDC__ -define __LIBC__ 234 +define __LIBC__ 236 ifdef __ASMC__ if ( __ASMC__ LT __LIBC__ ) .err diff --git a/include/stdio.inc b/include/stdio.inc index 15db10bd..cecfcd20 100644 --- a/include/stdio.inc +++ b/include/stdio.inc @@ -45,6 +45,7 @@ define EOF (-1) ifndef _FILE_DEFINED define _FILE_DEFINED _iobuf struct size_t +ifdef _MSVCRT _ptr LPTSTR ? _cnt int_t ? _base string_t ? @@ -59,9 +60,15 @@ _ungotten dw ? else _tmpfname LPTSTR ? endif -ifdef _CRTBLD -_bk dd ? -_bb dd ? +else +_ptr string_t ? +_base string_t ? +_cnt int_t ? +_flag int_t ? +_file int_t ? +_bufsiz int_t ? +_charbuf int_t ? +_bitcnt int_t ? endif _iobuf ends FILE typedef _iobuf diff --git a/source/libc/conio/_getcursor.asm b/source/libc/conio/_getcursor.asm index 514438a4..8ee6dede 100644 --- a/source/libc/conio/_getcursor.asm +++ b/source/libc/conio/_getcursor.asm @@ -13,7 +13,7 @@ _getcursor proc uses rbx p:PCURSOR .new cu:CONSOLE_CURSOR_INFO ifdef __TTY__ - .new a:AnsiEscapeCode + .new a:CINPUT else .new ci:CONSOLE_SCREEN_BUFFER_INFO endif diff --git a/source/libc/conio/_readansi.asm b/source/libc/conio/_readansi.asm index f091a608..1fdc0669 100644 --- a/source/libc/conio/_readansi.asm +++ b/source/libc/conio/_readansi.asm @@ -9,12 +9,14 @@ include stdlib.inc .code - assume rbx:ptr AnsiEscapeCode + assume rbx:PCINPUT -_readansi proc uses rbx csi:ptr AnsiEscapeCode +_readansi proc uses rbx csi:PCINPUT .new value:int_t .new count:int_t + .new radix:int_t + .new final[2]:byte ldr rbx,csi @@ -89,72 +91,92 @@ _readansi proc uses rbx csi:ptr AnsiEscapeCode .endif _getch() - mov count,2 - - .if ( al == '[' ) + .if ( al != '[' && al != ']' ) - .while 1 + mov [rbx].param,al + _getch() + mov [rbx].final,al + .return( 3 ) + .endif - _getch() - inc count + mov count,2 + mov ecx,0x5C5C + .if ( al == '[' ) + mov ecx,0x7E40 + .endif + mov final[0],cl + mov final[1],ch + mov radix,10 - .if ( al >= 0x40 && al <= 0x7E ) + .while 1 - mov [rbx].final,al + _getch() + inc count + mov cl,final[0] + mov ch,final[1] + + .switch + .case al >= cl && al <= ch + mov [rbx].final,al + .case eax == -1 + .break + .case al == '/' + .if ( cl != '\' ) + mov [rbx].inter,al + .endc + .endif + .case al == ';' + inc [rbx].count + movzx ecx,[rbx].count + mov [rbx+rcx*4].n,0 + mov value,1 + .endc + .case al >= 0x20 && al <= 0x2F + mov [rbx].inter,al + .endc + .case al >= 'a' && al <= 'f' + .endc .if ( radix == 10 ) + sub al,'a'-10-'0' + .case al >= '0' && al <= '9' + sub al,'0' + movzx ecx,[rbx].count + mov edx,[rbx].n[rcx*4] + imul edx,radix + add eax,edx + mov [rbx].n[rcx*4],eax + mov value,1 + .endc + .case al == 0x1B + .if ( cl != '\' ) + _ungetch( eax ) + dec count .break .endif - - .if ( al >= 0x30 && al <= 0x3F ) - - .if ( al <= '9' ) - - sub al,'0' - movzx ecx,[rbx].count - imul edx,[rbx].n[rcx*4],10 - add eax,edx - mov [rbx].n[rcx*4],eax - mov value,1 - - .elseif ( al == ';' ) - - inc [rbx].count - movzx ecx,[rbx].count - mov [rbx+rcx*4].n,0 - mov value,1 - .else - mov [rbx].param,al - .endif - - .elseif ( al >= 0x20 || al <= 0x2F ) - mov [rbx].inter,al - .else - .break + .endc + .case al == ':' ; \e]d;d;rgb:xxxx/xxxx/xxxx\e\\ + .if ( cl == '\' ) + mov radix,16 + .endc .endif - .endw - mov ecx,value - add [rbx].count,cl - - .if ( [rbx].final == 'M' ) - - _getch() + .default mov [rbx].param,al - _getch() - sub eax,0x21 - mov [rbx].n[0],eax - _getch() - sub eax,0x21 - mov [rbx].n[4],eax - add count,3 - .endif + .endsw + .endw - .else + mov ecx,value + add [rbx].count,cl + .if ( [rbx].final == 'M' ) + _getch() mov [rbx].param,al _getch() - inc count - mov [rbx].final,al + sub eax,0x21 + mov [rbx].n[0],eax + _getch() + sub eax,0x21 + mov [rbx].n[4],eax + add count,3 .endif - mov eax,count ret diff --git a/source/libc/conio/_treadinput.asm b/source/libc/conio/_treadinput.asm index 9bb783ae..5b6b7b7f 100644 --- a/source/libc/conio/_treadinput.asm +++ b/source/libc/conio/_treadinput.asm @@ -39,7 +39,7 @@ ifdef __TTY__ _readinput proc uses rsi rdi rbx Input:PINPUT_RECORD - .new a:AnsiEscapeCode + .new a:CINPUT .while 1 diff --git a/source/libc/conio/ttyapi.asm b/source/libc/conio/ttyapi.asm index ed91340c..7b74d24a 100644 --- a/source/libc/conio/ttyapi.asm +++ b/source/libc/conio/ttyapi.asm @@ -71,7 +71,7 @@ _setconsolecursorposition endp _getconsolescreenbufferinfo proc WINAPI uses rbx fh:HANDLE, pc:PCONSOLE_SCREEN_BUFFER_INFO - .new a:AnsiEscapeCode + .new a:CINPUT ldr rbx,pc diff --git a/source/libc/stdio/_fflushb.asm b/source/libc/stdio/_fflushb.asm index fc0929ef..85820fcd 100644 --- a/source/libc/stdio/_fflushb.asm +++ b/source/libc/stdio/_fflushb.asm @@ -14,27 +14,27 @@ _fflushb proc uses rbx fp:LPFILE ldr rbx,fp - .while ( [rbx]._bk >= 8 ) + .while ( [rbx]._bitcnt >= 8 ) - movzx ecx,byte ptr [rbx]._bb + movzx ecx,byte ptr [rbx]._charbuf .ifd ( fputc(ecx, rbx) == -1 ) .return .endif - sub [rbx]._bk,8 - shr [rbx]._bb,8 + sub [rbx]._bitcnt,8 + shr [rbx]._charbuf,8 .endw - .if ( [rbx]._bk ) + .if ( [rbx]._bitcnt ) mov eax,1 - mov ecx,[rbx]._bk + mov ecx,[rbx]._bitcnt shl eax,cl dec eax - and eax,[rbx]._bb + and eax,[rbx]._charbuf fputc(eax, rbx) .endif - mov [rbx]._bb,0 - mov [rbx]._bk,0 + mov [rbx]._charbuf,0 + mov [rbx]._bitcnt,0 ret _fflushb endp diff --git a/source/libc/stdio/_fgetb.asm b/source/libc/stdio/_fgetb.asm index 1d96e0c6..b00a781e 100644 --- a/source/libc/stdio/_fgetb.asm +++ b/source/libc/stdio/_fgetb.asm @@ -17,14 +17,14 @@ _fgetb proc uses rbx fp:LPFILE, count:int_t .while 1 mov ecx,count - .if ( [rbx]._bk >= ecx ) + .if ( [rbx]._bitcnt >= ecx ) mov eax,1 ; create mask shl eax,cl dec eax - and eax,[rbx]._bb ; bits to EAX - sub [rbx]._bk,ecx ; dec bit count - shr [rbx]._bb,cl ; dump used bits + and eax,[rbx]._charbuf ; bits to EAX + sub [rbx]._bitcnt,ecx ; dec bit count + shr [rbx]._charbuf,cl ; dump used bits .break .endif @@ -32,16 +32,16 @@ _fgetb proc uses rbx fp:LPFILE, count:int_t .ifd ( fgetc(rbx) == -1 ) - .if ( [rbx]._bk ) - mov count,[rbx]._bk + .if ( [rbx]._bitcnt ) + mov count,[rbx]._bitcnt .else .break .endif .else - mov ecx,[rbx]._bk + mov ecx,[rbx]._bitcnt shl eax,cl - or [rbx]._bb,eax - add [rbx]._bk,8 + or [rbx]._charbuf,eax + add [rbx]._bitcnt,8 .endif .endw ret diff --git a/source/libc/stdio/_fputb.asm b/source/libc/stdio/_fputb.asm index 510d0e06..46159e43 100644 --- a/source/libc/stdio/_fputb.asm +++ b/source/libc/stdio/_fputb.asm @@ -14,23 +14,23 @@ _fputb proc uses rbx fp:LPFILE, bits:uint_t, count:int_t ldr rbx,fp - .while ( [rbx]._bk >= 8 ) + .while ( [rbx]._bitcnt >= 8 ) - movzx ecx,byte ptr [rbx]._bb + movzx ecx,byte ptr [rbx]._charbuf .ifd ( fputc(ecx, rbx) == -1 ) .return .endif - sub [rbx]._bk,8 - shr [rbx]._bb,8 + sub [rbx]._bitcnt,8 + shr [rbx]._charbuf,8 .endw - mov ecx,[rbx]._bk + mov ecx,[rbx]._bitcnt mov edx,bits mov eax,count shl edx,cl - or [rbx]._bb,edx - add [rbx]._bk,eax + or [rbx]._charbuf,edx + add [rbx]._bitcnt,eax ret _fputb endp diff --git a/source/libc/stdio/ftbuf.asm b/source/libc/stdio/ftbuf.asm index aa467383..b273f36e 100644 --- a/source/libc/stdio/ftbuf.asm +++ b/source/libc/stdio/ftbuf.asm @@ -18,13 +18,13 @@ _ftbuf proc uses rbx flag:int_t, fp:LPFILE mov edx,[rbx]._flag .if ( ecx && edx & _IOFLRTN ) - fflush( rbx ) + fflush( rbx ) - and [rbx]._flag,not (_IOYOURBUF or _IOFLRTN) - xor eax,eax - mov [rbx]._ptr,rax - mov [rbx]._base,rax - mov [rbx]._bufsiz,eax + and [rbx]._flag,not (_IOYOURBUF or _IOFLRTN) + xor eax,eax + mov [rbx]._ptr,rax + mov [rbx]._base,rax + mov [rbx]._bufsiz,eax .endif ret diff --git a/source/libc/stdio/getst.asm b/source/libc/stdio/getst.asm index 8a75a62c..6082e067 100644 --- a/source/libc/stdio/getst.asm +++ b/source/libc/stdio/getst.asm @@ -18,7 +18,7 @@ _getst proc mov [rcx]._cnt,eax mov [rcx]._flag,eax - mov [rcx]._bk,eax + mov [rcx]._bitcnt,eax mov [rcx]._ptr,rax mov [rcx]._base,rax dec eax diff --git a/source/libc/stdio/stbuf.asm b/source/libc/stdio/stbuf.asm index ccd7a801..9e9eebf2 100644 --- a/source/libc/stdio/stbuf.asm +++ b/source/libc/stdio/stbuf.asm @@ -49,13 +49,11 @@ _stbuf proc uses rbx fp:LPFILE .endif mov ecx,_INTIOBUF -if defined(_WIN64) or not defined(__UNIX__) .if ( rax == NULL ) lea rax,[rbx]._charbuf mov ecx,4 .endif -endif mov [rbx]._ptr,rax mov [rbx]._base,rax mov [rbx]._bufsiz,ecx diff --git a/source/test/libc/conio/_terminal/_terminal.asm b/source/test/libc/conio/_terminal/_terminal.asm index f4c69a1d..504501b2 100644 --- a/source/test/libc/conio/_terminal/_terminal.asm +++ b/source/test/libc/conio/_terminal/_terminal.asm @@ -5,6 +5,8 @@ ; include io.inc +include stdio.inc +include stdlib.inc include fcntl.inc include conio.inc include tchar.inc @@ -69,21 +71,35 @@ paint endp _tmain proc .new y:byte = 0 - .new a:AnsiEscapeCode = {0} + .new a:CINPUT = {0} .new s:ptr = _conpush() + .new v:int_t = 100 paint() _write(_confd, CSI "c", 3) ; read terminal identity - _readansi(&a) - .if ( a.param == '?' && a.n[4] != 0 ) + _readansi( &a ) + + mov eax,a.n + mov edx,a.n[4] + + .if ( eax == 1 ) + + .if ( edx == 0 ) + mov v,101 + .endif + + .elseif ( eax == 6 ) + + mov v,102 + + .elseif ( eax >= 60 ) + + mov v,220 mov y,5 .endif - mov eax,a.n - .while ( eax < 100 ) - imul eax,eax,10 - .endw - _scputf(2, 2, "Terminal type: VT%03d", eax) + + _scputf(2, 2, "Terminal type: VT%03d", v) _scputs(3, 4, "Supported features:") .if ( y ) @@ -115,12 +131,13 @@ _tmain proc dec al mov y,al + _write(_confd, "\e]4;1;?\e\\", 9) _write(_confd, SET_ANY_EVENT_MOUSE, 8) .whiled ( _readansi( &a ) ) .break .if ( a.final == VK_ESCAPE || a.final == VK_RETURN ) - _scputf(13, y, "%c %d %d %d %3d %3d %3d %3d", - a.final, a.count, a.param, a.inter, a.n[0x0], a.n[0x4], a.n[0x8], a.n[0xC]) + _scputf(13, y, "%c %d %2d %2d %04X %04X %04X %04X %04X %04X %04X", + a.final, a.count, a.param, a.inter, a.n, a.n[4], a.n[8], a.n[12], a.n[16], a.n[20], a.n[24]) .endw _write(_confd, RST_ANY_EVENT_MOUSE, 8) _conpop(s)