Negative Return SCREEN

Started by Robert, November 18, 2025, 01:49:05 AM

Previous topic - Next topic

MrBcx

Thank you Robert

I've applied your change to 8.3.1.

When building your example using the Hebrew codepage, I now get this output:

          בגד
ב has a code point value of  225
ג has a code point value of  226
ד has a code point value of  227

Press any key to continue . . .

Robert

The SCREEN function returns a negative code point value for characters above the Basic Latin (ASCII) block.

This affects coding when using the following and possibly more code pages

874  – Windows Thai
1250 – Windows Central Europe
1251 – Windows Cyrillic
1252 – Windows Western
1253 – Windows Greek
1254 – Windows Turkish
1255 – Windows Hebrew
1256 – Windows Arabic
1257 – Windows Baltic
1258 – Windows Vietnamese


A positive value can be returned by SCREEN for characters above the Basic Latin (ASCII) block by changing, in BCX 8.3.0., line 33700

from

      FPRINT FP_OUTPUT, "  return  Char[0];"    
to either

      FPRINT FP_OUTPUT, "  return  (unsigned char)Char[0];"
or
    
      FPRINT FP_OUTPUT, "  return  (Char[0] + 256) % 256;"   
 
Example code:

DIM AS UINT OEMCodePage
OEMCodePage = GetOEMCP()
PRINT "Current OEM Code Page (OEMCP): ", STR$(OEMCodePage)

DIM AS UINT ANSICodePage
ANSICodePage = GetACP()
PRINT "Current ANSI Code Page (ACP): ", STR$(ANSICodePage)

DIM AS UINT OriginalConsoleOutputCodePage
OriginalConsoleOutputCodePage = GetConsoleOutputCP()
PRINT "Current Console Code Page: ", STR$(OriginalConsoleOutputCodePage)

DIM AS UINT NewConsoleOutputCodePage
$COMMENT
Set the code page argument value in SetConsoleOutputCP, below,
to any of the following code pages.
874  – Windows Thai
1250 – Windows Central Europe
1251 – Windows Cyrillic
1252 – Windows Western
1253 – Windows Greek
1254 – Windows Turkish
1255 – Windows Hebrew
1256 – Windows Arabic
1257 – Windows Baltic
1258 – Windows Vietnamese
$COMMENT
SetConsoleOutputCP(1255)
NewConsoleOutputCodePage = GetConsoleOutputCP()
PRINT "New Current Console Code Page: ", STR$(NewConsoleOutputCodePage)

PAUSE

DIM a$, b%, c%, d$

CLS

COLOR 15, 4
a$ = CHR$(225)
LOCATE 2, 11, 0
PRINT a$
COLOR 4,  7
a$ = CHR$(226)
LOCATE 2, 12, 0
PRINT a$
COLOR 15, 4
a$ = CHR$(227)
LOCATE 2, 13, 0
PRINT a$
COLOR 7, 0
a$ = " "
LOCATE 2, 14, 0
PRINT a$

FOR INTEGER Loopt = 11 TO 13
b% = SCREEN(2, Loopt)

d$ = CHR$(b%) & " has a code point value of " & STR$(b%)
PRINT d$
NEXT Loopt

PAUSE

SetConsoleOutputCP(OriginalConsoleOutputCodePage)

END

Result:

          בגד
ב has a code point value of -31
ג has a code point value of -30
ד has a code point value of -29