aboutsummaryrefslogtreecommitdiff
ModeNameSize
-rw-r--r--.gitignore61logplain
-rw-r--r--README.md3692logplain
-rw-r--r--dlog.h2358logplain
-rw-r--r--dosmain.c8019logplain
-rw-r--r--dosmouse.lnk256logplain
-rw-r--r--dostsr.c28726logplain
-rw-r--r--dostsr.h5400logplain
-rw-r--r--int10vga.h1882logplain
-rw-r--r--int2fwin.h3793logplain
-rw-r--r--int33.h7133logplain
-rw-r--r--makefile1621logplain
-rw-r--r--oemsetup.inf174logplain
-rw-r--r--pci.h3302logplain
-rw-r--r--ps2.h6190logplain
-rw-r--r--utils.h3321logplain
-rw-r--r--vbox.c3198logplain
-rw-r--r--vbox.h4780logplain
-rw-r--r--vboxdev.h19021logplain
-rw-r--r--vboxlog.h254logplain
-rw-r--r--vds.h4665logplain
-rw-r--r--w16mouse.c4803logplain
-rw-r--r--w16mouse.h1725logplain
-rw-r--r--w16mouse.lnk365logplain
round-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * VBSF - Unicode conversion routines
 * Copyright (C) 2011-2022 Eduardo Casino
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General License for more details.
 *
 * You should have received a copy of the GNU General License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef UNICODE_H
#define UNICODE_H

#include <stdint.h>
#include "sftsr.h"


#ifdef __IN_SFTSR__
#define TSRDATAPTR PTSRDATA
#else
#define TSRDATAPTR LPTSRDATA
#endif

static inline uint8_t lookup_codepage( TSRDATAPTR data, uint16_t cp )
{
	uint8_t i;
	
	for ( i = 0; i < 128 && data->unicode_table[i] != cp; ++i );
	
	return ( i < 128 ? (uint8_t) i + 128 : '\0' );
}

// dst and src CAN'T BE THE SAME !!!!
// Returns resulting length or -1 if buffer overflow
//
static uint16_t local_to_utf8_n( TSRDATAPTR data, uint8_t *dst, const char far *src, uint16_t buflen, uint16_t count )
{
	uint16_t len = 0;	// Resulting length
	uint16_t cp;	// Unicode Code Point

	while ( *src && count )
	{
		// UTF-8 bytes: 0xxxxxxx
		// Binary CP:   0xxxxxxx
		// CP range:    U+0000 to U+007F (Direct ASCII translation)
		//
		if ( ! (*src & 0x80) )
		{	
			if ( buflen > len )
			{
				*dst++ = *src;
				++len;
				goto cont;
			}
			else
			{
				return -1;
			}
		} 

		cp = data->unicode_table[*src - 128];
		
		// UTF-8 bytes: 110yyyyy 10xxxxxx
		// Binary CP:   00000yyy yyxxxxxx
		// CP range:    U+0080 to U+07FF
		//		
		if ( ! (cp & 0xF000) )
		{
			if ( buflen > len + 1 )
			{
				*dst++ = (uint8_t)( cp >> 6 ) | 0xC0;
				*dst++ = (uint8_t)( cp & 0x3f ) | 0x80;
				len += 2;
			}
			else
			{
				return -1;
			}
		}
				
		// UTF-8 bytes: 1110zzzz 10yyyyyy 10xxxxxx
		// Binary CP:   zzzzyyyy yyxxxxxx
		// CP range:    U+0800 to U+FFFF
		//
		else
		{
			if ( buflen > len +2 )
			{
				*dst++ = (uint8_t)( cp >> 12 ) | 0xE0;
				*dst++ = (uint8_t)( (cp >> 6) & 0x3F ) | 0x80;
				*dst++ = (uint8_t)( cp & 0x3F ) | 0x80;
				len += 3;
			}
			else
			{
				return -1;
			}
		}
cont:
		++src, --count;
	};

	// Terminate string
	//
	*dst = '\0';
	
	return len;
	
}

static inline uint16_t local_to_utf8( TSRDATAPTR data, uint8_t *dst, const char far *src, uint16_t buflen )
{
	return local_to_utf8_n( data, dst, src, buflen, buflen );
}

// Returns true on success, false if any unsupported char is found
//
static bool utf8_to_local( TSRDATAPTR data, char *dst, char *src, uint16_t *len )
{
	bool ret = true;	// Return code
	uint16_t cp;		// Unicode Code point
	uint16_t l = 0;

	while ( *src )
	{
		// UTF-8 bytes: 0xxxxxxx
		// Binary CP:   0xxxxxxx
		// CP range:    U+0000 to U+007F (Direct ASCII translation)
		//
		if ( ! (*src & 0x80) )
		{	
			*dst = *src;
			++src;
			goto cont;
		} 
		
		// UTF-8 bytes: 110yyyyy 10xxxxxx
		// Binary CP:   00000yyy yyxxxxxx
		// CP range:    U+0080 to U+07FF
		//
		if ( ! (*src & 0x20) ) 
		{
			cp = ( (uint16_t)(*src & 0x1F) << 6 ) | *(src+1) & 0x3F;
			*dst = lookup_codepage( data, cp );
			if ( *dst == '\0' )
			{
				*dst = '_';
				ret = false;
			}
			src += 2;
			goto cont;
		}
		
		// UTF-8 bytes: 1110zzzz 10yyyyyy 10xxxxxx
		// Binary CP:   zzzzyyyy yyxxxxxx
		// CP range:    U+0800 to U+FFFF
		//
		if ( ! (*src & 0x10) )
		{
			cp = ( (uint16_t)(*src & 0xF) << 12 ) | ( (uint16_t)(*(src+1) & 0x3F) << 6 ) | *(src+2) & 0x3F;
			*dst = lookup_codepage( data, cp );
			if ( *dst == '\0' )
			{
				*dst = '_';
				ret = false;
			}
			src += 3;
			goto cont;
		}
		
		// UTF-8 bytes: 11110www 10zzzzzz 10yyyyyy 10xxxxxx
		// Binary CP:   000wwwzz zzzzyyyy yyxxxxxx
		// CP range:    U+010000 to U+10FFFF
		//
		if ( ! (*src & 0x08) )
		{
			*dst = '_';		// Currently unsupported
			ret = false;
			src += 4;
			goto cont;
		}
		
		// Should not reach here
		//
		*dst = '_';
		ret = false;
		++src;
cont:
		++dst, ++l;
		
	};
	
	// Terminate string
	//
	*dst = '\0';

	if (len) *len = l;

	return ret;

}

// Returns true on success, false if any unsupported char is found
//
static bool utf16_to_local( TSRDATAPTR data, uint8_t *dst, uint16_t *src, uint16_t len )
{
	bool ret = true;
	int i;
	uint16_t cp;
	uint8_t c;
	
	for ( i = 0; i < len; ++i )
	{
		cp = src[i];
		
		if ( cp < 0x80 )
		{
			*dst++ = ( uint8_t ) cp;
		}
		else
		{
			c = lookup_codepage( data, cp );
			if ( c == '\0' )
			{
				c = '_';
				ret = false;
			}
			*dst++ = c;
		}
	}

	*dst = '\0';

	return ret;
	
}

#endif // UNICODE_H