TempleOSTS_140317.ISO
This commit is contained in:
1 parent
2d2a65d572
commit
7ef616a20e
1416 files changed
+223873
-53917
No files matched your search
@@ -0,0 +1,99 @@
|
||||
U0 GridInit()
|
||||
{
|
||||
ip_grid.x=ip_grid.y=ip_grid.z=8;
|
||||
ip_grid.x_offset=ip_grid.y_offset=ip_grid.z_offset=0;
|
||||
ip_grid.x_speed =ip_grid.y_speed =ip_grid.z_speed =1;
|
||||
ip_grid.show=ip_grid.snap=FALSE;
|
||||
}
|
||||
|
||||
U0 IPVarsUpdate(I64 x,I64 y,I64 z,Bool l,Bool c,Bool r)
|
||||
{
|
||||
ipx_presnap=ToI64(ipx_scale*x)+ipx_offset;
|
||||
ipy_presnap=ToI64(ipy_scale*y)+ipy_offset;
|
||||
ipz_presnap=ToI64(ipz_scale*z)+ipz_offset;
|
||||
if (ip_grid.snap) {
|
||||
ipx=Trunc(ipx_presnap/ip_grid.x)*ip_grid.x+ip_grid.x_offset;
|
||||
ipy=Trunc(ipy_presnap/ip_grid.y)*ip_grid.y+ip_grid.y_offset;
|
||||
ipz=Trunc(ipz_presnap/ip_grid.z)*ip_grid.z+ip_grid.z_offset;
|
||||
} else {
|
||||
ipx=ipx_presnap;
|
||||
ipy=ipy_presnap;
|
||||
ipz=ipz_presnap;
|
||||
}
|
||||
|
||||
ipx=ClampI64(ipx,0,gr_width-1);
|
||||
ipy=ClampI64(ipy,0,gr_height-1);
|
||||
ip_throttle=ClampI64(ip_throttle,MIN_I32,MAX_I32);
|
||||
iptx=ipx/FONT_WIDTH;
|
||||
if (iptx>=text_cols) {
|
||||
iptx=text_cols-1;
|
||||
ipx=text_cols*FONT_WIDTH-1;
|
||||
}
|
||||
ipty=ipy/FONT_HEIGHT;
|
||||
if (ipty>=text_rows) {
|
||||
ipty=text_rows-1;
|
||||
ipy=text_rows*FONT_HEIGHT-1;
|
||||
}
|
||||
ip_lb=l;
|
||||
ip_cb=c;
|
||||
ip_rb=r;
|
||||
LBEqu(&sys_cur_scan_code,SCf_IP_L_DOWN,ip_lb);
|
||||
LBEqu(&sys_cur_scan_code,SCf_IP_R_DOWN,ip_rb);
|
||||
}
|
||||
|
||||
U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=MAX_I64,I64 c=MAX_I64)
|
||||
{ //Note: Generates a message.
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (!(0<=x<gr_width))
|
||||
x=ipx;
|
||||
if (!(0<=y<gr_height))
|
||||
y=ipy;
|
||||
if (z==MAX_I64)
|
||||
z=ipz;
|
||||
|
||||
if (!(FALSE<=l<=TRUE))
|
||||
l=ip_lb;
|
||||
if (!(FALSE<=c<=TRUE))
|
||||
c=ip_cb;
|
||||
if (!(FALSE<=r<=TRUE))
|
||||
r=ip_rb;
|
||||
|
||||
x=(x-ipx_offset)/ipx_scale;
|
||||
y=(y-ipy_offset)/ipy_scale;
|
||||
z=(z-ipz_offset)/ipz_scale;
|
||||
IPVarsUpdate(x,y,z,l,c,r);
|
||||
switch (ip_dev) {
|
||||
case IP_MOUSE:
|
||||
SetMouseIP(x,y,z,l,c,r);
|
||||
break;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
U0 IPVarsInit()
|
||||
{
|
||||
ipx=0;
|
||||
ipy=0;
|
||||
ipz=0;
|
||||
ip_throttle=0;
|
||||
ip_throttle_step=(MAX_I32+1)>>3;
|
||||
ipx_offset=0;
|
||||
ipy_offset=0;
|
||||
ipz_offset=0;
|
||||
ipx_scale=1.0;
|
||||
ipy_scale=1.0;
|
||||
ipz_scale=1.0;
|
||||
ip_speed=0;
|
||||
ip_dev=IP_NULL;
|
||||
iptx=ipx/FONT_WIDTH;
|
||||
ipty=ipy/FONT_HEIGHT;
|
||||
ip_on=TRUE;
|
||||
ip_lb_last=FALSE;
|
||||
ip_rb_last=FALSE;
|
||||
ip_lb=FALSE;
|
||||
ip_cb=FALSE;
|
||||
ip_rb=FALSE;
|
||||
ip_has_wheel=FALSE;
|
||||
ip_last_move_time=tS;
|
||||
GridInit;
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
asm {
|
||||
NORMAL_KEY_SCAN_DECODE_TABLE::
|
||||
DU8 0,CH_ESC,"1234567890-=",CH_BACKSPACE,'\t';
|
||||
DU8 "qwertyuiop[]",'\n',0,"as";
|
||||
DU8 "dfghjkl;'\`",0,"\\zxcv";
|
||||
DU8 "bnm,./",0,'*',0,CH_SPACE,0,0,0,0,0,0;
|
||||
DU8 0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0;
|
||||
SHIFT_KEY_SCAN_DECODE_TABLE::
|
||||
DU8 0,CH_SHIFT_ESC,"!@#$$%^&*()_+",CH_BACKSPACE,'\t';
|
||||
DU8 "QWERTYUIOP{}",'\n',0,"AS";
|
||||
DU8 "DFGHJKL:\"~",0,"|ZXCV";
|
||||
DU8 "BNM<>?",0,'*',0,CH_SHIFT_SPACE,0,0,0,0,0,0;
|
||||
DU8 0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0;
|
||||
CTRL_KEY_SCAN_DECODE_TABLE::
|
||||
DU8 0,CH_ESC,"1234567890-=",CH_BACKSPACE,'\t';
|
||||
DU8 CH_CTRLQ,CH_CTRLW,CH_CTRLE,CH_CTRLR,CH_CTRLT,CH_CTRLY,CH_CTRLU,CH_CTRLI,CH_CTRLO,CH_CTRLP,"[]",'\n',0,CH_CTRLA,CH_CTRLS;
|
||||
DU8 CH_CTRLD,CH_CTRLF,CH_CTRLG,CH_CTRLH,CH_CTRLJ,CH_CTRLK,CH_CTRLL,";'\`",0,"\\",CH_CTRLZ,CH_CTRLX,CH_CTRLC,CH_CTRLV;
|
||||
DU8 CH_CTRLB,CH_CTRLN,CH_CTRLM,",./",0,'*',0,CH_SPACE,0,0,0,0,0,0;
|
||||
DU8 0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0;
|
||||
}
|
||||
|
||||
U0 KbdCmdSend(I64 port, U8 val)
|
||||
{
|
||||
F64 timeout=tS+0.125;
|
||||
while (tS<timeout) {
|
||||
if (!(InU8(KBD_CTRL)&2)) {
|
||||
OutU8(port,val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
I64 KbdCmdRead()
|
||||
{
|
||||
F64 timeout=tS+0.125;
|
||||
while (tS<timeout)
|
||||
if (InU8(KBD_CTRL)&1)
|
||||
return InU8(KBD_PORT);
|
||||
throw;
|
||||
}
|
||||
|
||||
U0 KbdCmdFlush()
|
||||
{
|
||||
F64 timeout=tS+0.03;
|
||||
while (tS<timeout)
|
||||
InU8(KBD_PORT);
|
||||
}
|
||||
|
||||
U0 KbdSetLEDs(I64 sc)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
U8 v=0;
|
||||
BEqu(&v,0,Bt(&sc,SCf_SCROLL));
|
||||
BEqu(&v,1,Bt(&sc,SCf_NUM));
|
||||
BEqu(&v,2,Bt(&sc,SCf_CAPS));
|
||||
try {
|
||||
KbdCmdSend(KBD_PORT,0xED);
|
||||
KbdCmdSend(KBD_PORT,v);
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
U0 KbdMouseCmdAck(U8 val)
|
||||
{
|
||||
I64 ack,timeout=5;
|
||||
do {
|
||||
ack=0;
|
||||
try {
|
||||
KbdCmdSend(KBD_CTRL,0xD4);
|
||||
KbdCmdSend(KBD_PORT,val);
|
||||
ack=KbdCmdRead;
|
||||
} catch {
|
||||
KbdCmdFlush;
|
||||
Fs->catch_except=TRUE;
|
||||
}
|
||||
} while (ack!=0xFA && --timeout);
|
||||
if (!timeout)
|
||||
throw;
|
||||
}
|
||||
|
||||
U0 SetTypeMatic(U8 delay)
|
||||
{
|
||||
try {
|
||||
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
KbdCmdSend(KBD_PORT,0xF3);
|
||||
KbdCmdSend(KBD_PORT,delay); //Typematic rate
|
||||
KbdCmdSend(KBD_CTRL,0xA8); //Enable Mouse
|
||||
} catch {
|
||||
KbdCmdFlush;
|
||||
Fs->catch_except=TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
I64 A2ScanCode(I64 ch,I64 sc_flags=0)
|
||||
{ //ASCII val to scan code (Slow)
|
||||
I64 i;
|
||||
U8 *table;
|
||||
if (sc_flags) {
|
||||
table=NORMAL_KEY_SCAN_DECODE_TABLE;
|
||||
if (sc_flags & SCF_CTRL || ch<26)
|
||||
table=CTRL_KEY_SCAN_DECODE_TABLE;
|
||||
else if (sc_flags & SCF_SHIFT || 'A'<=ch<='Z') {
|
||||
if (!(sc_flags & SCF_CAPS))
|
||||
table=SHIFT_KEY_SCAN_DECODE_TABLE;
|
||||
} else {
|
||||
if (sc_flags & SCF_CAPS)
|
||||
table=SHIFT_KEY_SCAN_DECODE_TABLE;
|
||||
}
|
||||
for (i=0;i<0x50;i++)
|
||||
if (table[i]==ch)
|
||||
return i|sc_flags;
|
||||
return sc_flags;
|
||||
} else {
|
||||
table=NORMAL_KEY_SCAN_DECODE_TABLE;
|
||||
for (i=0;i<0x50;i++)
|
||||
if (table[i]==ch)
|
||||
return i;
|
||||
table=SHIFT_KEY_SCAN_DECODE_TABLE;
|
||||
for (i=0;i<0x50;i++)
|
||||
if (table[i]==ch)
|
||||
return i|SCF_SHIFT;
|
||||
table=CTRL_KEY_SCAN_DECODE_TABLE;
|
||||
for (i=0;i<0x50;i++)
|
||||
if (table[i]==ch)
|
||||
return i|SCF_CTRL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U8 ScanCode2A(I64 sc)
|
||||
{//Scan Code to ASCII val
|
||||
U8 *table=NORMAL_KEY_SCAN_DECODE_TABLE;
|
||||
if (sc & SCF_E0_PREFIX)
|
||||
return 0;
|
||||
if (sc & SCF_CTRL)
|
||||
table=CTRL_KEY_SCAN_DECODE_TABLE;
|
||||
else if (sc & SCF_SHIFT) {
|
||||
if (!(sc & SCF_CAPS))
|
||||
table=SHIFT_KEY_SCAN_DECODE_TABLE;
|
||||
} else {
|
||||
if (sc & SCF_CAPS)
|
||||
table=SHIFT_KEY_SCAN_DECODE_TABLE;
|
||||
}
|
||||
sc&=0x7F;
|
||||
if (sc>=0x50)
|
||||
return 0;
|
||||
else
|
||||
return table[sc];
|
||||
}
|
||||
|
||||
U8 scan_code_map[0x100]={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,SC_SHIFT,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,SC_ENTER,SC_CTRL,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0x35,0,0,SC_ALT,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,SC_HOME,SC_CURSOR_UP,SC_PAGE_UP,0,SC_CURSOR_LEFT,0,SC_CURSOR_RIGHT,0,SC_END,
|
||||
SC_CURSOR_DOWN,SC_PAGE_DOWN,SC_INS,SC_DELETE,0,0,0,0,0,0,0,0,SC_GUI,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
|
||||
U8 num_lock_map[0x100]={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,8,9,10,0,5,6,7,0,2,
|
||||
3,4,11,0x34,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,SC_ENTER,SC_CTRL,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0x35,0,0,SC_ALT,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,SC_HOME,SC_CURSOR_UP,SC_PAGE_UP,0,SC_CURSOR_LEFT,0,SC_CURSOR_RIGHT,0,SC_END,
|
||||
SC_CURSOR_DOWN,SC_PAGE_DOWN,SC_INS,SC_DELETE,0,0,0,0,0,0,0,0,SC_GUI,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
U8 *A2KeyName(I64 ch,Bool include_ctrl=TRUE)
|
||||
{//ASCII val to key name
|
||||
I64 i;
|
||||
U8 buf[136];
|
||||
if (ch<=CH_SPACE) {
|
||||
nobound_switch (ch) {
|
||||
case '\n':
|
||||
StrCpy(buf,"ENTER");
|
||||
break;
|
||||
case CH_BACKSPACE:
|
||||
StrCpy(buf,"BACKSPACE");
|
||||
break;
|
||||
case '\t':
|
||||
StrCpy(buf,"TAB");
|
||||
break;
|
||||
case CH_ESC:
|
||||
StrCpy(buf,"ESC");
|
||||
break;
|
||||
case CH_SHIFT_ESC:
|
||||
StrCpy(buf,"SHIFT_ESC");
|
||||
break;
|
||||
case 0: //nobound_switch
|
||||
case 29:
|
||||
case 30:
|
||||
*buf=0;
|
||||
break;
|
||||
case CH_SHIFT_SPACE:
|
||||
StrCpy(buf,"SHIFT_SPACE");
|
||||
break;
|
||||
case CH_SPACE:
|
||||
StrCpy(buf,"SPACE");
|
||||
break;
|
||||
default:
|
||||
if (include_ctrl)
|
||||
StrCpy(buf,"CTRL ");
|
||||
buf[i=StrLen(buf)]=ch-1+'a';
|
||||
buf[i+1]=0;
|
||||
break;
|
||||
}
|
||||
} else if (Bt(chars_bitmap_printable,ch)) {
|
||||
*buf=ch;
|
||||
buf[1]=0;
|
||||
} else
|
||||
*buf=0;
|
||||
return StrNew(buf);
|
||||
}
|
||||
|
||||
U8 *ScanCode2KeyName(I64 sc)
|
||||
{
|
||||
I64 ch;
|
||||
U8 buf[136],*st;
|
||||
*buf=0;
|
||||
if (sc&SCF_CTRL)
|
||||
CatPrint(buf,"CTRL ");
|
||||
if (sc&SCF_ALT)
|
||||
CatPrint(buf,"ALT ");
|
||||
if (sc&SCF_SHIFT)
|
||||
CatPrint(buf,"SHIFT ");
|
||||
if (ch=ScanCode2A(sc&255)) {
|
||||
st=A2KeyName(ch,FALSE);
|
||||
StrCpy(buf+StrLen(buf),st);
|
||||
Free(st);
|
||||
} else {
|
||||
switch (sc&255) {
|
||||
case SC_BACKSPACE:CatPrint(buf,"BACK"); break;
|
||||
case SC_CAPS: CatPrint(buf,"CAPS"); break;
|
||||
case SC_NUM: CatPrint(buf,"NUM"); break;
|
||||
case SC_SCROLL: CatPrint(buf,"SCROLL"); break;
|
||||
case SC_CURSOR_UP:CatPrint(buf,"UP"); break;
|
||||
case SC_CURSOR_DOWN:CatPrint(buf,"DOWN"); break;
|
||||
case SC_CURSOR_LEFT:CatPrint(buf,"LEFT"); break;
|
||||
case SC_CURSOR_RIGHT:CatPrint(buf,"RIGHT"); break;
|
||||
case SC_PAGE_UP: CatPrint(buf,"PAGE_UP"); break;
|
||||
case SC_PAGE_DOWN:CatPrint(buf,"PAGE_DOWN");break;
|
||||
case SC_HOME: CatPrint(buf,"HOME"); break;
|
||||
case SC_END: CatPrint(buf,"END"); break;
|
||||
case SC_INS: CatPrint(buf,"INS"); break;
|
||||
case SC_DELETE: CatPrint(buf,"DELETE"); break;
|
||||
case SC_F1: CatPrint(buf,"F1"); break;
|
||||
case SC_F2: CatPrint(buf,"F2"); break;
|
||||
case SC_F3: CatPrint(buf,"F3"); break;
|
||||
case SC_F4: CatPrint(buf,"F4"); break;
|
||||
case SC_F5: CatPrint(buf,"F5"); break;
|
||||
case SC_F6: CatPrint(buf,"F6"); break;
|
||||
case SC_F7: CatPrint(buf,"F7"); break;
|
||||
case SC_F8: CatPrint(buf,"F8"); break;
|
||||
case SC_F9: CatPrint(buf,"F9"); break;
|
||||
case SC_F10: CatPrint(buf,"F10"); break;
|
||||
case SC_F11: CatPrint(buf,"F11"); break;
|
||||
case SC_F12: CatPrint(buf,"F12"); break;
|
||||
case SC_GUI: CatPrint(buf,"WINDOWS"); break;
|
||||
case SC_PRTSCRN1: CatPrint(buf,"PRTSCRN1"); break;
|
||||
case SC_PRTSCRN2: CatPrint(buf,"PRTSCRN2"); break;
|
||||
}
|
||||
}
|
||||
return StrNew(buf);
|
||||
}
|
||||
|
||||
I64 KbdBuildSC(U8 raw_byte,U8 *_last_raw_byte,I64 *_last_sc,
|
||||
Bool *_set_LEDs,Bool *_ctrl_alt)
|
||||
{
|
||||
I64 sc_flags,sc,sc2,sc_raw;
|
||||
*_set_LEDs=FALSE;
|
||||
*_ctrl_alt=FALSE;
|
||||
if (raw_byte==0xE0) {
|
||||
*_last_raw_byte=raw_byte;
|
||||
return 0;
|
||||
} else {
|
||||
sc=raw_byte;
|
||||
BEqu(&sc,SCf_E0_PREFIX,*_last_raw_byte==0xE0);
|
||||
BEqu(&sc,SCf_KEY_UP,raw_byte & 0x80);
|
||||
*_last_raw_byte=raw_byte;
|
||||
}
|
||||
sc_flags=_last_sc->u32[0]&~0x1FF;
|
||||
sc_raw=sc;
|
||||
|
||||
if (sc_flags & SCF_NUM) {
|
||||
if (sc2=num_lock_map[sc.u8[0]])
|
||||
sc.u8[0]=sc2;
|
||||
} else {
|
||||
if (sc2=scan_code_map[sc.u8[0]])
|
||||
sc.u8[0]=sc2;
|
||||
}
|
||||
|
||||
if (sc&SCF_KEY_UP)
|
||||
switch (sc&~SCF_KEY_UP) {
|
||||
case SC_SHIFT: sc_flags&=~SCF_SHIFT; goto new_key_done;
|
||||
case SC_CTRL: sc_flags&=~SCF_CTRL; goto new_key_done;
|
||||
case SC_ALT: sc_flags&=~SCF_ALT; goto new_key_done;
|
||||
case SC_DELETE: sc_flags&=~SCF_DELETE; goto new_key_done;
|
||||
case SC_INS: sc_flags&=~SCF_INS; goto new_key_done;
|
||||
case SC_CAPS:
|
||||
sc_flags^=SCF_CAPS;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
case SC_NUM:
|
||||
sc_flags^=SCF_NUM;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
case SC_SCROLL:
|
||||
sc_flags^=SCF_SCROLL;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
}
|
||||
else
|
||||
switch (sc) {
|
||||
case SC_SHIFT: sc_flags|=SCF_SHIFT; goto new_key_done;
|
||||
case SC_CTRL: sc_flags|=SCF_CTRL; goto new_key_done;
|
||||
case SC_ALT: sc_flags|=SCF_ALT; goto new_key_done;
|
||||
case SC_DELETE: sc_flags|=SCF_DELETE; goto new_key_done;
|
||||
case SC_INS: sc_flags|=SCF_INS; goto new_key_done;
|
||||
case SC_CAPS: goto new_key_done;
|
||||
case SC_NUM: goto new_key_done;
|
||||
case SC_SCROLL: goto new_key_done;
|
||||
}
|
||||
|
||||
if (sc_flags & SCF_CTRL && sc_flags & SCF_ALT) {
|
||||
sc_flags&=~SCF_NEW_KEY;
|
||||
*_ctrl_alt=TRUE;
|
||||
} else {
|
||||
new_key_done:
|
||||
sc_flags|=SCF_NEW_KEY;
|
||||
}
|
||||
return *_last_sc=sc_flags|sc|(sc_flags|sc_raw)<<32;
|
||||
}
|
||||
|
||||
U0 KbdPktRead()
|
||||
{
|
||||
static U8 last_raw_byte=0;
|
||||
static I64 last_sc=0;
|
||||
U8 raw_byte;
|
||||
I64 ch,sc;
|
||||
Bool set_LEDs,ctrl_alt;
|
||||
|
||||
if (GetTSC>kbd_evt_time+time_stamp_freq>>3)
|
||||
FifoU8Flush(kbd_fifo);
|
||||
kbd_evt_time=GetTSC;
|
||||
raw_byte=InU8(KBD_PORT);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&last_sc,&set_LEDs,&ctrl_alt);
|
||||
if (ctrl_alt && sc) {
|
||||
if (!(sc & SCF_KEY_UP)) {
|
||||
if (sc&255==SC_DELETE)
|
||||
CtrlAltDel(last_sc);
|
||||
else {
|
||||
if (sc&255==SC_ESC)
|
||||
ch='e';
|
||||
else if (sc&255==SC_TAB)
|
||||
ch='t';
|
||||
else
|
||||
ch=ScanCode2A(sc&255);
|
||||
if ('a'<=ch<='z' && fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
Bt(&ctrl_alt_let_in_irq_flags,ch-'a')) {
|
||||
(*fp_ctrl_alt_let_cbs[ch-'a'])(last_sc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!FifoU8Cnt(kbd_fifo)) {
|
||||
FifoU8Ins(kbd_fifo,raw_byte);
|
||||
if (raw_byte!=0xE0) {
|
||||
while (FifoU8Rem(kbd_fifo,&raw_byte))
|
||||
FifoU8Ins(kbd2_fifo,raw_byte);
|
||||
}
|
||||
} else {
|
||||
FifoU8Ins(kbd_fifo,raw_byte);
|
||||
while (FifoU8Rem(kbd_fifo,&raw_byte))
|
||||
FifoU8Ins(kbd2_fifo,raw_byte);
|
||||
}
|
||||
}
|
||||
|
||||
interrupt U0 KbdIntHandler()
|
||||
{
|
||||
CLD
|
||||
OutU8(0x20,0x20);
|
||||
kbd_irqs_working=TRUE;
|
||||
if (mouse_install_attempt_in_progress) {
|
||||
kbdmouse_rst=TRUE;
|
||||
return;
|
||||
}
|
||||
ctrl_alt_let_ret_addr=GetRBP()(I64)+8;
|
||||
KbdPktRead;
|
||||
}
|
||||
|
||||
U0 KbdInit()
|
||||
{
|
||||
try {
|
||||
KbdCmdFlush;
|
||||
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
KbdCmdSend(KBD_PORT,0xF0);
|
||||
KbdCmdSend(KBD_PORT,0x02);
|
||||
KbdSetLEDs(sys_cur_scan_code);
|
||||
} catch {
|
||||
KbdCmdFlush;
|
||||
Fs->catch_except=TRUE;
|
||||
}
|
||||
IntEntrySet(0x21,&KbdIntHandler);
|
||||
OutU8(0x21,InU8(0x21)&~2);
|
||||
|
||||
SetCtrlAltLetCB('C',&CtrlAltC,"Sys/Break Execution",TRUE);
|
||||
SetCtrlAltLetCB('D',&CtrlAltD,"Sys/Enter Debugger",TRUE);
|
||||
SetCtrlAltLetCB('E',&CtrlAltE,"Sys/Spawn New User Task");
|
||||
SetCtrlAltLetCB('F',&CtrlAltF,"Sys/VGA Flush",TRUE);
|
||||
SetCtrlAltLetCB('M',&CtrlAltM,"Sys/Toggle Mute");
|
||||
SetCtrlAltLetCB('T',&CtrlAltT,"Sys/Switch Focus to Next Task",TRUE);
|
||||
SetCtrlAltLetCB('X',&CtrlAltX,"Sys/Kill Focused Task",TRUE);
|
||||
}
|
||||
|
||||
U0 KbdHandler()
|
||||
{
|
||||
static U8 last_raw_byte=0;
|
||||
U8 raw_byte;
|
||||
Bool set_LEDs,ctrl_alt;
|
||||
I64 ch,sc;
|
||||
|
||||
FifoU8Rem(kbd2_fifo,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&sys_cur_scan_code,&set_LEDs,&ctrl_alt);
|
||||
if (set_LEDs)
|
||||
KbdSetLEDs(sc);
|
||||
if (raw_byte==0xE0) {
|
||||
FifoU8Rem(kbd2_fifo,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&sys_cur_scan_code,&set_LEDs,&ctrl_alt);
|
||||
if (set_LEDs)
|
||||
KbdSetLEDs(sc);
|
||||
}
|
||||
if (ctrl_alt) {
|
||||
if (!(sc & SCF_KEY_UP)) {
|
||||
if (sc&255==SC_ESC)
|
||||
ch='e';
|
||||
else if (sc&255==SC_TAB)
|
||||
ch='t';
|
||||
else
|
||||
ch=ScanCode2A(sc&255);
|
||||
if ('a'<=ch<='z' && fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
!Bt(&ctrl_alt_let_in_irq_flags,ch-'a'))
|
||||
(*fp_ctrl_alt_let_cbs[ch-'a'])(sys_cur_scan_code);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Btr(&sys_cur_scan_code,SCf_NEW_KEY)) {
|
||||
Btr(&sys_cur_scan_code,32+SCf_NEW_KEY);
|
||||
FifoI64Ins(scan_code_fifo,sys_cur_scan_code);
|
||||
sys_key_cnt++;
|
||||
if (!(sys_cur_scan_code&SCF_KEY_UP)) {
|
||||
sys_last_down_scan_code=sys_cur_scan_code;
|
||||
Bts(key_down_bitmap,sys_cur_scan_code.u8[0]);
|
||||
Bts(key_down_bitmap2,sys_cur_scan_code.u8[4]);
|
||||
} else {
|
||||
Btr(key_down_bitmap,sys_cur_scan_code.u8[0]);
|
||||
Btr(key_down_bitmap2,sys_cur_scan_code.u8[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
I64 KbdMsgsQue()
|
||||
{
|
||||
I64 p1,p2,msg_code=MSG_NULL;
|
||||
CTask *task_focus;
|
||||
if (task_focus=sys_focus_task) {
|
||||
while (FifoI64Rem(scan_code_fifo,&p2)) {
|
||||
p1=ScanCode2A(p2);
|
||||
if (p2 & SCF_KEY_UP) {
|
||||
TaskMsg(task_focus,0,
|
||||
MSG_KEY_UP,p1,p2,0);
|
||||
msg_code=MSG_KEY_UP;
|
||||
} else {
|
||||
TaskMsg(task_focus,0,
|
||||
MSG_KEY_DOWN,p1,p2,0);
|
||||
msg_code=MSG_KEY_DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
return msg_code;
|
||||
}
|
||||
|
||||
I64 KbdMouseEvtTime()
|
||||
{
|
||||
if (mouse_evt_time>kbd_evt_time)
|
||||
return mouse_evt_time;
|
||||
else
|
||||
return kbd_evt_time;
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
U0 InputFilterTask()
|
||||
{
|
||||
CSrvCmd *tempc,*tempc1;
|
||||
Bool old_filter;
|
||||
I64 old_flags=GetRFlags;
|
||||
Fs->win_inhibit=WIG_USER_TASK_DFT;
|
||||
LBts(&Fs->task_flags,TASKf_INPUT_FILTER_TASK);
|
||||
old_filter=LBts(&Fs->last_input_filter_task->task_flags,TASKf_FILTER_INPUT);
|
||||
LBEqu(&Fs->task_flags,TASKf_FILTER_INPUT,old_filter);
|
||||
while (TRUE) {
|
||||
SrvCmdsHandler;
|
||||
CLI
|
||||
tempc1=&Fs->srv_ctrl.next_waiting;
|
||||
tempc=tempc1->next;
|
||||
if (tempc==tempc1)
|
||||
break;
|
||||
else {
|
||||
if (tempc->cmd_code==SVCT_TEXT_INPUT) {
|
||||
QueRem(tempc);
|
||||
SetRFlags(old_flags);
|
||||
Preempt(ON);
|
||||
try
|
||||
ExePrint("%s",tempc->aux_str);
|
||||
catch
|
||||
Fs->catch_except=TRUE;
|
||||
Preempt(OFF);
|
||||
SrvCmdDel(tempc);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
Fs->next_input_filter_task->last_input_filter_task=Fs->last_input_filter_task;
|
||||
Fs->last_input_filter_task->next_input_filter_task=Fs->next_input_filter_task;
|
||||
if (!old_filter)
|
||||
LBtr(&Fs->last_input_filter_task->task_flags,TASKf_FILTER_INPUT);
|
||||
SetRFlags(old_flags);
|
||||
}
|
||||
|
||||
I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{
|
||||
I64 result,old_flags;
|
||||
CSrvCmd *tempc,*tempc1;
|
||||
if (!task) task=Fs;
|
||||
old_flags=GetRFlags;
|
||||
tempc1=&task->srv_ctrl.next_waiting;
|
||||
while (TRUE) {
|
||||
if (task==Fs)
|
||||
SrvCmdsHandler;
|
||||
CLI
|
||||
tempc=tempc1->next;
|
||||
if (tempc==tempc1)
|
||||
break;
|
||||
else {
|
||||
if (tempc->cmd_code==SVCT_MSG) {
|
||||
QueRem(tempc);
|
||||
SetRFlags(old_flags);
|
||||
result=tempc->msg_code;
|
||||
if (_p1)
|
||||
*_p1=tempc->aux1;
|
||||
if (_p2)
|
||||
*_p2=tempc->aux2;
|
||||
SrvCmdDel(tempc);
|
||||
if ((result!=MSG_KEY_DOWN || !(tempc->aux2&SCF_KEY_DESC) ||
|
||||
Bt(&mask,MSGF_ALLOW_KEY_DESC)) && Bt(&mask,result))
|
||||
goto sm_done;
|
||||
}
|
||||
}
|
||||
SetRFlags(old_flags);
|
||||
}
|
||||
result=MSG_NULL;
|
||||
if (_p1)
|
||||
*_p1=0;
|
||||
if (_p2)
|
||||
*_p2=0;
|
||||
if (task->parent_task&&task->parent_task->popup_task==task) {
|
||||
SetRFlags(old_flags);
|
||||
return ScanMsg(_p1,_p2,mask,task->parent_task);
|
||||
}
|
||||
sm_done:
|
||||
SetRFlags(old_flags);
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 FlushMsgs(CTask *task=NULL)
|
||||
{
|
||||
I64 result=0,p1,p2;
|
||||
while (ScanMsg(&p1,&p2,~1,task))
|
||||
result++;
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 GetMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{
|
||||
I64 result;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (!task) task=Fs;
|
||||
LBtr(&task->task_flags,TASKf_IDLE);
|
||||
while (!(result=ScanMsg(_p1,_p2,mask,task))) {
|
||||
LBts(&task->task_flags,TASKf_IDLE);
|
||||
Yield;
|
||||
}
|
||||
LBtr(&task->task_flags,TASKf_IDLE);
|
||||
Preempt(old_preempt);
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 ScanChar()
|
||||
{
|
||||
I64 p1a,p2a,p1b,p2b;
|
||||
if (!ScanMsg(&p1a,&p2a,1<<MSG_KEY_DOWN)||!p1a)
|
||||
return 0;
|
||||
else
|
||||
do GetMsg(&p1b,&p2b,1<<MSG_KEY_UP);
|
||||
while (!p1b);
|
||||
return p1a;
|
||||
}
|
||||
|
||||
Bool ScanKey(I64 *_ch=NULL,I64 *_scancode=NULL,Bool echo=FALSE)
|
||||
{
|
||||
I64 ch=0,sc=0;
|
||||
if (ScanMsg(&ch,&sc,1<<MSG_KEY_DOWN)) {
|
||||
if (_ch) *_ch=ch;
|
||||
if (_scancode) *_scancode=sc;
|
||||
if (echo)
|
||||
PutKey(ch,sc);
|
||||
return TRUE;
|
||||
} else {
|
||||
if (_ch) *_ch=0;
|
||||
if (_scancode) *_scancode=0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
I64 GetKey(I64 *_scancode=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
|
||||
{
|
||||
I64 ch,sc;
|
||||
Bool old_preempt=Preempt(OFF),cursor_on=FALSE;
|
||||
while (!ScanKey(&ch,&sc,FALSE)) {
|
||||
if (IsRaw && raw_cursor) {
|
||||
if (!cursor_on && ToI64(GetTSC*5/time_stamp_freq)&1) {
|
||||
'Û';
|
||||
cursor_on=TRUE;
|
||||
} else if (cursor_on && !(ToI64(GetTSC*5/time_stamp_freq)&1)) {
|
||||
'' CH_BACKSPACE;
|
||||
cursor_on=FALSE;
|
||||
}
|
||||
}
|
||||
LBts(&Fs->task_flags,TASKf_IDLE);
|
||||
if (IsDbg) {
|
||||
//We don't want interrupt-driven keyboard when in debugger
|
||||
//because that could have side-effects or crash, so we poll
|
||||
//keyboard when in debugger with interrupts off.
|
||||
PUSHFD
|
||||
CLI
|
||||
KbdMouseHandler(TRUE,FALSE);
|
||||
KbdMsgsQue;
|
||||
POPFD
|
||||
if (old_preempt && GetRFlags&1<<RFLAGf_INT)
|
||||
Yield;
|
||||
} else {
|
||||
LBts(&Fs->task_flags,TASKf_AWAITING_MSG);
|
||||
Yield;
|
||||
}
|
||||
LBtr(&Fs->task_flags,TASKf_IDLE);
|
||||
}
|
||||
if (IsRaw && raw_cursor && cursor_on)
|
||||
'' CH_BACKSPACE;
|
||||
Preempt(old_preempt);
|
||||
if (echo)
|
||||
PutKey(ch,sc);
|
||||
if (_scancode) *_scancode=sc;
|
||||
return ch;
|
||||
}
|
||||
|
||||
I64 GetChar(I64 *_scancode=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE)
|
||||
{
|
||||
I64 ch1;
|
||||
do ch1=GetKey(_scancode,FALSE,raw_cursor);
|
||||
while (!ch1);
|
||||
if (echo)
|
||||
"$$PT$$%c$$FG$$",ch1;
|
||||
return ch1;
|
||||
}
|
||||
|
||||
U8 *MGetS(I64 flags=0)
|
||||
//$LK,"Flags",A="MN:GETSF_SHIFT_ESC_EXIT"$
|
||||
{
|
||||
//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string.
|
||||
return (*fp_mgets)(flags);
|
||||
}
|
||||
|
||||
I64 GetS(U8 *buf,I64 size,Bool allow_ext=TRUE)
|
||||
{
|
||||
U8 *st;
|
||||
I64 ch,i=0;
|
||||
if (!size || !buf) return 0;
|
||||
if (allow_ext) {
|
||||
st=MGetS;
|
||||
if (StrLen(st)>size-1) {
|
||||
MemCpy(buf,st,size-1);
|
||||
buf[size-1]=0;
|
||||
} else
|
||||
StrCpy(buf,st);
|
||||
i=StrLen(buf);
|
||||
Free(st);
|
||||
} else {
|
||||
while (TRUE) {
|
||||
ch=GetChar(,FALSE,IsDbg);
|
||||
if (ch=='\n') {
|
||||
'' ch;
|
||||
break;
|
||||
} else if (ch==CH_BACKSPACE) {
|
||||
if (i>0) {
|
||||
i--;
|
||||
'' ch;
|
||||
}
|
||||
} else {
|
||||
if (i<size-1) {
|
||||
buf[i++]=ch;
|
||||
'' ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
buf[i]=0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
U0 MousePktRead()
|
||||
{
|
||||
U8 j;
|
||||
if (GetTSC>mouse_evt_time+time_stamp_freq>>3)
|
||||
FifoU8Flush(mouse_fifo);
|
||||
mouse_evt_time=GetTSC;
|
||||
FifoU8Ins(mouse_fifo,InU8(KBD_PORT));
|
||||
if (FifoU8Cnt(mouse_fifo)==mouse_pkt_size)
|
||||
while (FifoU8Rem(mouse_fifo,&j))
|
||||
FifoU8Ins(mouse2_fifo,j);
|
||||
}
|
||||
|
||||
interrupt U0 MouseIntHandler()
|
||||
{
|
||||
CLD
|
||||
OutU8(0xA0,0x20);
|
||||
OutU8(0x20,0x20);
|
||||
mouse_irqs_working=TRUE;
|
||||
if (mouse_install_attempt_in_progress || !mouse_installed) {
|
||||
kbdmouse_rst=TRUE;
|
||||
return;
|
||||
}
|
||||
MousePktRead;
|
||||
}
|
||||
|
||||
U0 MouseGetDevType()
|
||||
{
|
||||
I64 b;
|
||||
KbdMouseCmdAck(0xF2);
|
||||
b=KbdCmdRead;
|
||||
if (b==3)
|
||||
mouse_has_wheel=TRUE;
|
||||
else if (b==4)
|
||||
mouse_has_ext_buttons=TRUE;
|
||||
}
|
||||
|
||||
Bool MouseRst()
|
||||
{
|
||||
U8 b,*_b;
|
||||
U16 *_w;
|
||||
F64 timeout;
|
||||
Bool result=FALSE,present;
|
||||
|
||||
mouse_has_wheel=FALSE;
|
||||
mouse_has_ext_buttons=FALSE;
|
||||
|
||||
_w=0x40E;
|
||||
present=MemPagePresentMark(_w,TRUE);
|
||||
if (*_w==0x9FC0) {
|
||||
_b=0x9FC00+0x30;
|
||||
*_b=1; //This enables my mouse. It might be for one machine.
|
||||
//USB DMA packets, set-up by BIOS to make legacy PS/2?
|
||||
}
|
||||
if (!present)
|
||||
MemPagePresentMark(_w,FALSE);
|
||||
|
||||
try {
|
||||
KbdCmdFlush;
|
||||
KbdCmdSend(KBD_CTRL,0xAD); //Disable Kbd
|
||||
KbdCmdSend(KBD_CTRL,0xA8); //Enable Mouse
|
||||
|
||||
KbdMouseCmdAck(0xFF); //Rst
|
||||
|
||||
timeout=tS+10.0;
|
||||
do
|
||||
try {
|
||||
KbdCmdRead;
|
||||
timeout=0; //force exit
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
while (tS<timeout);
|
||||
|
||||
try
|
||||
KbdCmdRead;
|
||||
catch
|
||||
Fs->catch_except=TRUE;
|
||||
|
||||
KbdMouseCmdAck(0xF3);
|
||||
KbdMouseCmdAck(200);
|
||||
KbdMouseCmdAck(0xF3); // enable Mouse
|
||||
KbdMouseCmdAck(100); // Set Rate
|
||||
KbdMouseCmdAck(0xF3);
|
||||
KbdMouseCmdAck(80); //Resolution
|
||||
|
||||
MouseGetDevType; // enable Mouse
|
||||
|
||||
KbdMouseCmdAck(0xF3);
|
||||
KbdMouseCmdAck(10);
|
||||
MouseGetDevType; // enable Mouse
|
||||
|
||||
KbdMouseCmdAck(0xE8); //Resolution
|
||||
KbdMouseCmdAck(0x03);
|
||||
KbdMouseCmdAck(0xE6);
|
||||
|
||||
KbdMouseCmdAck(0xF3); // Set Rate
|
||||
KbdMouseCmdAck(100);
|
||||
|
||||
KbdMouseCmdAck(0xF4); // enable Mouse
|
||||
result=TRUE;
|
||||
|
||||
//Enable IRQ 12
|
||||
KbdCmdSend(KBD_CTRL,0x20);
|
||||
b=KbdCmdRead;
|
||||
KbdCmdSend(KBD_CTRL,0x60);
|
||||
KbdCmdSend(KBD_PORT,(b|2)&~0x20);
|
||||
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
|
||||
//This is been added to override failure
|
||||
//because the mouse sometimes still works.
|
||||
result=TRUE;
|
||||
|
||||
try
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
catch
|
||||
Fs->catch_except=TRUE;
|
||||
if (mouse_has_wheel || mouse_has_ext_buttons)
|
||||
mouse_pkt_size=4;
|
||||
else
|
||||
mouse_pkt_size=3;
|
||||
if (!result)
|
||||
try
|
||||
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
|
||||
catch
|
||||
Fs->catch_except=TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U0 SetMouseSpeed()
|
||||
{
|
||||
I64 dd,temp;
|
||||
if ((dd=SqrI64(old_mxx-mxx)+SqrI64(old_myy-myy)) &&
|
||||
(temp=mouse_evt_time-mouse_last_evt_time))
|
||||
mouse_speed=Sqrt(dd)*time_stamp_freq/temp;
|
||||
mouse_last_evt_time=mouse_evt_time;
|
||||
}
|
||||
|
||||
U0 MouseUpdatePre(Bool *old_buttons)
|
||||
{
|
||||
I64 i;
|
||||
old_mxx=mxx; old_myy=myy; old_mzz=mzz;
|
||||
for (i=0;i<5;i++)
|
||||
old_buttons[i]=mouse_buttons[i];
|
||||
}
|
||||
|
||||
U0 MouseUpdatePost(Bool *old_buttons)
|
||||
{
|
||||
I64 i;
|
||||
mxx=mxx_prescale*mxx_scale*ip_grid.x_speed;
|
||||
myy=myy_prescale*myy_scale*ip_grid.y_speed;
|
||||
mzz=mzz_prescale*mzz_scale*ip_grid.z_speed;
|
||||
|
||||
i=Trunc(ipx_scale*mxx/ip_grid.x)*ip_grid.x+ipx_offset; //TODO ip_grid.x_offset?
|
||||
if (i<0)
|
||||
ipx_offset-=i;
|
||||
else if (i>=gr_width)
|
||||
ipx_offset+=gr_width-1-i;
|
||||
|
||||
i=Trunc(ipy_scale*myy/ip_grid.y)*ip_grid.y+ipy_offset;
|
||||
if (i<0)
|
||||
ipy_offset-=i;
|
||||
else if (i>=gr_height)
|
||||
ipy_offset+=gr_height-1-i;
|
||||
|
||||
if (mxx!=old_mxx||myy!=old_myy||mzz!=old_mzz) {
|
||||
mouse_evt=TRUE;
|
||||
SetMouseSpeed;
|
||||
} else
|
||||
for (i=0;i<5;i++)
|
||||
if (mouse_buttons[i]!=old_buttons[i]) {
|
||||
mouse_evt=TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
U0 MouseHandler()
|
||||
{
|
||||
I64 i,dx,dy,dz;
|
||||
U8 mouse_buf[4];
|
||||
Bool old_buttons[5];
|
||||
|
||||
MouseUpdatePre(old_buttons);
|
||||
|
||||
for (i=0;i<4;i++)
|
||||
mouse_buf[i]=0;
|
||||
for (i=0;i<mouse_pkt_size;i++)
|
||||
if (!FifoU8Rem(mouse2_fifo,&mouse_buf[i]))
|
||||
mouse_buf[i]=0;
|
||||
|
||||
mouse_buttons[0] = mouse_buf[0] & 1;
|
||||
mouse_buttons[1] = (mouse_buf[0] & 2) >> 1;
|
||||
mouse_buttons[2] = (mouse_buf[0] & 4) >> 2;
|
||||
mouse_buttons[3] = (mouse_buf[3] & 0x10) >> 4;
|
||||
mouse_buttons[4] = (mouse_buf[3] & 0x20) >> 5;
|
||||
if (mouse_buf[0] & 0x10)
|
||||
dx=mouse_buf[1]-256;
|
||||
else
|
||||
dx=mouse_buf[1];
|
||||
if (mouse_buf[0] & 0x20)
|
||||
dy=256-mouse_buf[2];
|
||||
else
|
||||
dy=-mouse_buf[2];
|
||||
if (mouse_buf[3] & 0x08)
|
||||
dz=mouse_buf[3]&7-8;
|
||||
else
|
||||
dz=mouse_buf[3]&7;
|
||||
|
||||
mxx_prescale+=dx;
|
||||
myy_prescale+=dy;
|
||||
mzz_prescale+=dz;
|
||||
|
||||
MouseUpdatePost(old_buttons);
|
||||
}
|
||||
|
||||
U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r,I64 c)
|
||||
{
|
||||
Bool old_buttons[5];
|
||||
mouse_evt_time=GetTSC;
|
||||
MouseUpdatePre(old_buttons);
|
||||
mxx_prescale=x/mxx_scale/ip_grid.x_speed;
|
||||
myy_prescale=y/myy_scale/ip_grid.y_speed;
|
||||
mzz_prescale=z/mzz_scale/ip_grid.z_speed;
|
||||
mouse_buttons[0]=l;
|
||||
mouse_buttons[1]=r;
|
||||
mouse_buttons[2]=c; //unsure which one
|
||||
MouseUpdatePost(old_buttons);
|
||||
}
|
||||
|
||||
U0 KbdMouseRst()
|
||||
{
|
||||
KbdCmdFlush;
|
||||
FifoU8Flush(kbd2_fifo);
|
||||
FifoU8Flush(mouse2_fifo);
|
||||
FifoI64Flush(scan_code_fifo);
|
||||
sys_cur_scan_code=0;
|
||||
kbdmouse_rst=FALSE;
|
||||
}
|
||||
|
||||
Bool MouseDriverInstall(I64 dummy=0) //can be spawned
|
||||
{
|
||||
nounusedwarn dummy;
|
||||
I64 i;
|
||||
Bool old_preempt=IsPreempt;
|
||||
Preempt(ON);
|
||||
mouse_install_attempt_in_progress=TRUE;
|
||||
OutU8(0xA1,InU8(0xA1)|0x10);
|
||||
mouse_installed=mouse_irqs_working=FALSE;
|
||||
IntEntrySet(0x2C,&MouseIntHandler);
|
||||
for(i=0;i<5;i++)
|
||||
mouse_buttons[i]=0;
|
||||
if (i=MouseRst)
|
||||
OutU8(0xA1,InU8(0xA1)&~0x10);
|
||||
KbdMouseRst;
|
||||
mouse_install_attempts++;
|
||||
mouse_installed=mouse_evt=i;
|
||||
mouse_install_attempt_in_progress=FALSE;
|
||||
Preempt(old_preempt);
|
||||
return mouse_installed;
|
||||
}
|
||||
|
||||
U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
|
||||
{
|
||||
if (mouse_install_attempt_in_progress) {
|
||||
Yield;
|
||||
return;
|
||||
}
|
||||
if (kbdmouse_rst)
|
||||
KbdMouseRst;
|
||||
else {
|
||||
if (poll_mouse &&
|
||||
mouse_installed &&
|
||||
!mouse_irqs_working) {
|
||||
PUSHFD
|
||||
CLI
|
||||
while (InU8(KBD_CTRL)&1)
|
||||
MousePktRead;
|
||||
POPFD
|
||||
}
|
||||
|
||||
if (poll_kbd)
|
||||
while (InU8(KBD_CTRL)&1)
|
||||
KbdPktRead;
|
||||
|
||||
if (kbdmouse_rst)
|
||||
KbdMouseRst;
|
||||
else {
|
||||
while (FifoU8Cnt(kbd2_fifo))
|
||||
KbdHandler;
|
||||
while (FifoU8Cnt(mouse2_fifo))
|
||||
if (mouse_installed)
|
||||
MouseHandler;
|
||||
else
|
||||
KbdMouseRst;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 KbdMouseVarsInit()
|
||||
{
|
||||
sys_key_cnt=0;
|
||||
scan_code_fifo=FifoI64New(128);
|
||||
kbd_fifo=FifoU8New(8);
|
||||
kbd2_fifo=FifoU8New(64);
|
||||
mouse_fifo=FifoU8New(8);
|
||||
mouse2_fifo=FifoU8New(64);
|
||||
MemSet(key_down_bitmap,0,256/8);
|
||||
MemSet(key_down_bitmap2,0,256/8);
|
||||
sys_last_down_scan_code=0;
|
||||
sys_cur_scan_code=0;
|
||||
kbdmouse_rst=FALSE;
|
||||
kbd_irqs_working=FALSE;
|
||||
mouse_irqs_working=FALSE;
|
||||
mxx_scale=0.5;
|
||||
myy_scale=0.5;
|
||||
mzz_scale=1.0;
|
||||
mxx_prescale=gr_width/mxx_scale/2.0;
|
||||
myy_prescale=gr_height/myy_scale/2.0;
|
||||
mzz_prescale=0/mzz_scale;
|
||||
mxx=gr_width>>1;
|
||||
myy=gr_height>>1;
|
||||
mzz=0;
|
||||
mouse_speed=0.0;
|
||||
old_mxx=mxx;
|
||||
old_myy=myy;
|
||||
old_mzz=mzz;
|
||||
mouse_installed=FALSE;
|
||||
mouse_install_attempts=0;
|
||||
mouse_last_evt_time=0;
|
||||
mouse_has_wheel=FALSE;
|
||||
mouse_has_ext_buttons=FALSE;
|
||||
mouse_evt=FALSE;
|
||||
}
|
||||
Reference in new issue
Block a user