summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Forsyth <charles.forsyth@gmail.com>2017-02-21 14:18:10 +0000
committerCharles Forsyth <charles.forsyth@gmail.com>2017-02-21 14:18:10 +0000
commit6e6ec18053fc212e0a58124162dbafc2c2c30aed (patch)
tree73b386481006d60687bf42c211c629b9c97bbd3c
parent2fd8fca57f985a360d40d2d10e99fcda2a1d99c4 (diff)
parent322254a191e29f4eabbe5dd05962f1212937a6d8 (diff)
Merged in yk/inferno-os (pull request #13)
emu: windows scroll wheel + 21-bit rune fixes Approved-by: Charles Forsyth
-rw-r--r--emu/Nt/r16.c90
-rw-r--r--emu/Nt/win.c21
-rw-r--r--emu/port/devpointer.c9
-rw-r--r--libinterp/runt.c2
4 files changed, 66 insertions, 56 deletions
diff --git a/emu/Nt/r16.c b/emu/Nt/r16.c
index 92a36521..ba0ceb0d 100644
--- a/emu/Nt/r16.c
+++ b/emu/Nt/r16.c
@@ -9,26 +9,16 @@
#include "error.h"
#include "r16.h"
-#define Bit(i) (7-(i))
-/* N 0's preceded by i 1's, T(Bit(2)) is 1100 0000 */
-#define T(i) (((1 << (Bit(i)+1))-1) ^ 0xFF)
-/* 0000 0000 0000 0111 1111 1111 */
-#define RuneX(i) ((1 << (Bit(i) + ((i)-1)*Bitx))-1)
-
enum
{
- Bitx = Bit(1),
-
- Tx = T(1), /* 1000 0000 */
- Rune1 = (1<<(Bit(0)+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */
-
- Maskx = (1<<Bitx)-1, /* 0011 1111 */
- Testx = Maskx ^ 0xFF, /* 1100 0000 */
+ Bits10 = 0x03ff, /* 0011 1111 1111 */
- SurrogateMin = 0xD800,
- SurrogateMax = 0xDFFF,
+ R16self = 0x10000,
- Bad = Runeerror,
+ HSurrogateMin = 0xd800,
+ HSurrogateMax = 0xdbff,
+ LSurrogateMin = 0xdc00,
+ LSurrogateMax = 0xdfff,
};
Rune16*
@@ -60,22 +50,27 @@ char*
runes16toutf(char *p, Rune16 *r, int nc)
{
char *op, *ep;
- int n, c;
- Rune rc;
+ int n;
+ Rune c, lc;
op = p;
ep = p + nc;
while(c = *r++) {
- n = 1;
- if(c >= Runeself)
- n = runelen(c);
+ if(c > Runemax)
+ c = Runeerror;
+ if(c >= LSurrogateMin && c <= LSurrogateMax)
+ c = Runeerror;
+ if(c >= HSurrogateMin && c<= HSurrogateMax){
+ lc = *r++;
+ if(lc >= LSurrogateMin || lc <= LSurrogateMax)
+ c = (c&Bits10)<<10 | (lc&Bits10) + R16self;
+ else
+ c = Runeerror;
+ }
+ n = runelen(c);
if(p + n >= ep)
break;
- rc = c;
- if(c < Runeself)
- *p++ = c;
- else
- p += runetochar(p, &rc);
+ p += runetochar(p, &c);
}
*p = '\0';
return op;
@@ -84,20 +79,18 @@ runes16toutf(char *p, Rune16 *r, int nc)
int
rune16nlen(Rune16 *r, int nrune)
{
- int nb, i;
+ int nb;
Rune c;
nb = 0;
while(nrune--) {
c = *r++;
- if(c <= Rune1){
- nb++;
- } else {
- for(i = 2; i < UTFmax + 1; i++)
- if(c <= RuneX(i) || i == UTFmax){
- nb += i;
- break;
- }
+ if(c < R16self)
+ nb += runelen(c);
+ else {
+ c -= R16self;
+ nb += runelen(HSurrogateMin | (c>>10));
+ nb += runelen(LSurrogateMin | (c&Bits10));
}
}
return nb;
@@ -113,7 +106,17 @@ utftorunes16(Rune16 *r, char *p, int nc)
er = r + nc;
while(*p != '\0' && r + 1 < er){
p += chartorune(&rc, p);
- *r++ = rc; /* we'll ignore surrogate pairs */
+ if(rc < R16self){
+ *r++ = rc;
+ continue;
+ }
+ if(rc > Runemax || er-r < 2){
+ *r++ = Runeerror;
+ continue;
+ }
+ rc -= R16self;
+ *r++ = HSurrogateMin | (rc>>10);
+ *r++ = LSurrogateMin | (rc&Bits10);
}
*r = '\0';
return or;
@@ -167,8 +170,17 @@ int
widebytes(wchar_t *ws)
{
int n = 0;
-
- while (*ws)
- n += runelen(*ws++);
+ wchar_t c;
+
+ while (*ws){
+ c = *ws++;
+ if(c < R16self)
+ n += runelen(c);
+ else {
+ c -= R16self;
+ n += runelen(HSurrogateMin | (c>>10));
+ n += runelen(LSurrogateMin | (c&Bits10));
+ }
+ }
return n+1;
}
diff --git a/emu/Nt/win.c b/emu/Nt/win.c
index c1bccfa7..b1480fd7 100644
--- a/emu/Nt/win.c
+++ b/emu/Nt/win.c
@@ -308,6 +308,7 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
LPMINMAXINFO mmi;
LONG x, y, w, h, b;
HCURSOR dcurs;
+ POINT m;
switch(msg) {
case WM_SETCURSOR:
@@ -320,6 +321,15 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
dcurs = LoadCursor(NULL, IDC_ARROW);
SetCursor(dcurs);
break;
+ case WM_MOUSEWHEEL:
+ if((int)wparam>0)
+ b = 8;
+ else
+ b = 16;
+ m.x = LOWORD(lparam);
+ m.y = HIWORD(lparam);
+ ScreenToClient(hwnd, &m);
+ goto mok;
case WM_LBUTTONDBLCLK:
b = (1<<8) | 1;
goto process;
@@ -338,8 +348,9 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
case WM_RBUTTONDOWN:
b = 0;
process:
- x = LOWORD(lparam);
- y = HIWORD(lparam);
+ m.x = LOWORD(lparam);
+ m.y = HIWORD(lparam);
+ mok:
if(wparam & MK_LBUTTON)
b |= 1;
if(wparam & MK_MBUTTON)
@@ -350,7 +361,7 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
else
b |= 4; //right button
}
- mousetrack(b, x, y, 0);
+ mousetrack(b, m.x, m.y, 0);
break;
case WM_SYSKEYDOWN:
if(gkscanq)
@@ -446,10 +457,6 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
gkbdputc(gkbdq, wparam);
break;
case WM_CLOSE:
- // no longer used?
- //m.b = 128;
- //m.modify = 1;
- //mousetrack(128, 0, 0, 1);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
diff --git a/emu/port/devpointer.c b/emu/port/devpointer.c
index 30bad028..0590c2cc 100644
--- a/emu/port/devpointer.c
+++ b/emu/port/devpointer.c
@@ -74,15 +74,6 @@ mousetrack(int b, int x, int y, int isdelta)
y += mouse.v.y;
}
msec = osmillisec();
- if(0 && b && (mouse.v.b ^ b)&0x1f){
- if(msec - mouse.v.msec < 300 && mouse.lastb == b
- && abs(mouse.v.x - x) < 12 && abs(mouse.v.y - y) < 12)
- b |= 1<<8;
- mouse.lastb = b & 0x1f;
- mouse.v.msec = msec;
- }
- if((b&(1<<8))==0 && x == mouse.v.x && y == mouse.v.y && mouse.v.b == b)
- return;
lastb = mouse.v.b;
mouse.v.x = x;
mouse.v.y = y;
diff --git a/libinterp/runt.c b/libinterp/runt.c
index 81a5490b..977d642c 100644
--- a/libinterp/runt.c
+++ b/libinterp/runt.c
@@ -376,7 +376,7 @@ Sys_char2byte(void *fp)
c = f->c;
if(a == H || (UWORD)n>=a->len)
error(exBounds);
- if(c<0 || c>=(1<<16))
+ if(c<0 || c>=Runemax)
c = Runeerror;
if(c < Runeself){
a->data[n] = c;