Reformatted all Kernel SerialDev files.

All Kernel files are now reformatted.
Also reverted Caps Lock functionality. Might alter behaviour on symbols in the future.
This commit is contained in:
TomAwezome 2020-09-15 02:27:17 -04:00
parent 7e0ce60071
commit 027648943f
6 changed files with 782 additions and 622 deletions

View File

@ -28,7 +28,6 @@ Changes include:
- HolyC -> CosmiC - HolyC -> CosmiC
- System-wide renaming for clarity - System-wide renaming for clarity
- Removed shift-space mechanism - Removed shift-space mechanism
- Caps Lock is reassigned as Backspace
- Reformatted code for readability - Reformatted code for readability
- Added comments and documentation - Added comments and documentation

View File

@ -146,4 +146,10 @@ StartOS.CC
MemPhysical.CC MemPhysical.CC
PageTables.CC PageTables.CC
SerialDev/
Keyboard.CC
MakeSerialDev.CC
Message.CC
Mouse.CC
$FG,7$-Tom$FG,0$ $FG,7$-Tom$FG,0$

View File

@ -1,32 +1,35 @@
asm { asm {
NORMAL_KEY_SCAN_DECODE_TABLE:: NORMAL_KEY_SCAN_DECODE_TABLE::
DU8 0,CH_ESC,"1234567890-=",CH_BACKSPACE,'\t'; DU8 0, CH_ESC, "1234567890-=", CH_BACKSPACE, '\t';
DU8 "qwertyuiop[]",'\n',0,"as"; DU8 "qwertyuiop[]", '\n', 0, "as";
DU8 "dfghjkl;'\`",0,"\\zxcv"; DU8 "dfghjkl;'\`", 0, "\\zxcv";
DU8 "bnm,./",0,'*',0,CH_SPACE,CH_BACKSPACE,0,0,0,0,0; 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; DU8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', 0;
SHIFT_KEY_SCAN_DECODE_TABLE:: SHIFT_KEY_SCAN_DECODE_TABLE::
DU8 0,CH_SHIFT_ESC,"!@#$$%^&*()_+",CH_BACKSPACE,'\t'; DU8 0, CH_SHIFT_ESC, "!@#$$%^&*()_+", CH_BACKSPACE, '\t';
DU8 "QWERTYUIOP{}",'\n',0,"AS"; DU8 "QWERTYUIOP{}", '\n', 0, "AS";
DU8 "DFGHJKL:\"~",0,"|ZXCV"; DU8 "DFGHJKL:\"~", 0, "|ZXCV";
DU8 "BNM<>?",0,'*',0,CH_SPACE,CH_BACKSPACE,0,0,0,0,0; 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; DU8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', 0;
CTRL_KEY_SCAN_DECODE_TABLE:: CTRL_KEY_SCAN_DECODE_TABLE::
DU8 0,CH_ESC,"1234567890-=",CH_BACKSPACE,'\t'; DU8 0, CH_ESC, "1234567890-=", CH_BACKSPACE, '\t';
DU8 CH_CTRLQ,CH_CTRLW,CH_CTRLE,CH_CTRLR,CH_CTRLT,CH_CTRLY,CH_CTRLU, DU8 CH_CTRLQ, CH_CTRLW, CH_CTRLE, CH_CTRLR, CH_CTRLT, CH_CTRLY, CH_CTRLU, CH_CTRLI, CH_CTRLO,
CH_CTRLI,CH_CTRLO,CH_CTRLP,"[]",'\n',0,CH_CTRLA,CH_CTRLS; CH_CTRLP, "[]", '\n', 0, CH_CTRLA, CH_CTRLS;
DU8 CH_CTRLD,CH_CTRLF,CH_CTRLG,CH_CTRLH,CH_CTRLJ,CH_CTRLK,CH_CTRLL, DU8 CH_CTRLD, CH_CTRLF, CH_CTRLG, CH_CTRLH, CH_CTRLJ, CH_CTRLK, CH_CTRLL,
";'\`",0,"\\",CH_CTRLZ,CH_CTRLX,CH_CTRLC,CH_CTRLV; ";'\`", 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 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; DU8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', 0;
} }
U0 KbdCmdSend(I64 port, U8 val) U0 KbdCmdSend(I64 port, U8 val)
{ {
F64 timeout=tS+0.125; F64 timeout = tS + 0.125;
while (tS<timeout) {
if (!(InU8(KBD_CTRL)&2)) { while (tS < timeout)
OutU8(port,val); {
if (!(InU8(KBD_CTRL) & 2))
{
OutU8(port, val);
return; return;
} }
} }
@ -35,49 +38,62 @@ U0 KbdCmdSend(I64 port, U8 val)
I64 KbdCmdRead() I64 KbdCmdRead()
{ {
F64 timeout=tS+0.125; F64 timeout = tS + 0.125;
while (tS<timeout)
if (InU8(KBD_CTRL)&1) while (tS < timeout)
if (InU8(KBD_CTRL) & 1)
return InU8(KBD_PORT); return InU8(KBD_PORT);
throw; throw;
} }
U0 KbdCmdFlush() U0 KbdCmdFlush()
{ {
F64 timeout=tS+0.03; F64 timeout = tS + 0.03;
while (tS<timeout)
while (tS < timeout)
InU8(KBD_PORT); InU8(KBD_PORT);
} }
U0 KbdLEDsSet(I64 sc) U0 KbdLEDsSet(I64 sc)
{ {
U8 v=0; U8 v = 0;
BEqual(&v,0,Bt(&sc,SCf_SCROLL));
BEqual(&v,1,Bt(&sc,SCf_NUM)); BEqual(&v, 0, Bt(&sc, SCf_SCROLL));
BEqual(&v,2,Bt(&sc,SCf_CAPS)); BEqual(&v, 1, Bt(&sc, SCf_NUM));
try { BEqual(&v, 2, Bt(&sc, SCf_CAPS));
KbdCmdSend(KBD_PORT,0xED); try
KbdCmdSend(KBD_PORT,v); {
} catch KbdCmdSend(KBD_PORT, 0xED);
Fs->catch_except=TRUE; KbdCmdSend(KBD_PORT, v);
}
catch
Fs->catch_except = TRUE;
} }
U0 KbdMouseCmdAck(...) U0 KbdMouseCmdAck(...)
{ {
I64 i,ack,timeout; I64 i, ack, timeout;
for (i=0;i<argc;i++) {
timeout=5; for (i = 0; i < argc; i++)
do { {
ack=0; timeout = 5;
try { do
KbdCmdSend(KBD_CTRL,0xD4); {
KbdCmdSend(KBD_PORT,argv[i]); ack = 0;
ack=KbdCmdRead; try
} catch { {
KbdCmdFlush; KbdCmdSend(KBD_CTRL, 0xD4);
Fs->catch_except=TRUE; KbdCmdSend(KBD_PORT, argv[i]);
ack = KbdCmdRead;
} }
} while (ack!=0xFA && --timeout); catch
{
KbdCmdFlush;
Fs->catch_except = TRUE;
}
}
while (ack != 0xFA && --timeout);
if (!timeout) if (!timeout)
throw; throw;
} }
@ -85,293 +101,330 @@ U0 KbdMouseCmdAck(...)
U0 KbdTypeMatic(U8 delay) U0 KbdTypeMatic(U8 delay)
{//Set speed of repeated keys. {//Set speed of repeated keys.
try { try
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse {
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard KbdCmdSend(KBD_CTRL, 0xA7); //Disable Mouse
KbdCmdSend(KBD_PORT,0xF3); KbdCmdSend(KBD_CTRL, 0xAE); //Enable Keyboard
KbdCmdSend(KBD_PORT,delay); //Typematic rate KbdCmdSend(KBD_PORT, 0xF3);
KbdCmdSend(KBD_CTRL,0xA8); //Enable Mouse KbdCmdSend(KBD_PORT, delay);//Typematic rate
} catch { KbdCmdSend(KBD_CTRL, 0xA8); //Enable Mouse
}
catch
{
KbdCmdFlush; KbdCmdFlush;
Fs->catch_except=TRUE; Fs->catch_except = TRUE;
} }
} }
I64 Char2ScanCode(I64 ch,I64 sc_flags=0) I64 Char2ScanCode(I64 ch, I64 sc_flags=0)
{//ASCII val to scan code (Slow). {//ASCII val to scan code (Slow).
I64 i; I64 i;
U8 *table; U8 *table;
if (sc_flags) {
table=NORMAL_KEY_SCAN_DECODE_TABLE; if (sc_flags)
if (sc_flags & SCF_CTRL || ch<26) {
table=CTRL_KEY_SCAN_DECODE_TABLE; table = NORMAL_KEY_SCAN_DECODE_TABLE;
else if (sc_flags & SCF_SHIFT || 'A'<=ch<='Z') { 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)) if (!(sc_flags & SCF_CAPS))
table=SHIFT_KEY_SCAN_DECODE_TABLE; table = SHIFT_KEY_SCAN_DECODE_TABLE;
} else {
if (sc_flags & SCF_CAPS)
table=SHIFT_KEY_SCAN_DECODE_TABLE;
} }
for (i=0;i<0x50;i++) else
if (table[i]==ch) {
return i|sc_flags; 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; return sc_flags;
} else { }
table=NORMAL_KEY_SCAN_DECODE_TABLE; else
for (i=0;i<0x50;i++) {
if (table[i]==ch) table = NORMAL_KEY_SCAN_DECODE_TABLE;
for (i = 0; i < 0x50; i++)
if (table[i] == ch)
return i; return i;
table=SHIFT_KEY_SCAN_DECODE_TABLE; table = SHIFT_KEY_SCAN_DECODE_TABLE;
for (i=0;i<0x50;i++) for (i = 0; i < 0x50; i++)
if (table[i]==ch) if (table[i] == ch)
return i|SCF_SHIFT; return i | SCF_SHIFT;
table=CTRL_KEY_SCAN_DECODE_TABLE; table = CTRL_KEY_SCAN_DECODE_TABLE;
for (i=0;i<0x50;i++) for (i = 0; i < 0x50; i++)
if (table[i]==ch) if (table[i] == ch)
return i|SCF_CTRL; return i | SCF_CTRL;
return 0; return 0;
} }
} }
U8 ScanCode2Char(I64 sc) U8 ScanCode2Char(I64 sc)
{//Scan code to ASCII val. {//Scan code to ASCII val.
U8 *table=NORMAL_KEY_SCAN_DECODE_TABLE; U8 *table = NORMAL_KEY_SCAN_DECODE_TABLE;
if (sc&SCF_E0_PREFIX)
if (sc & SCF_E0_PREFIX)
return 0; return 0;
if (sc&SCF_CTRL) if (sc & SCF_CTRL)
table=CTRL_KEY_SCAN_DECODE_TABLE; table = CTRL_KEY_SCAN_DECODE_TABLE;
else if (sc&SCF_SHIFT) { else if (sc & SCF_SHIFT)
if (!(sc&SCF_CAPS)) {
table=SHIFT_KEY_SCAN_DECODE_TABLE; if (!(sc & SCF_CAPS))
} else { table = SHIFT_KEY_SCAN_DECODE_TABLE;
if (sc&SCF_CAPS)
table=SHIFT_KEY_SCAN_DECODE_TABLE;
} }
sc&=0x7F; else
if (sc>=0x50) {
if (sc & SCF_CAPS)
table = SHIFT_KEY_SCAN_DECODE_TABLE;
}
sc &= 0x7F;
if (sc >= 0x50)
return 0; return 0;
else else
return table[sc]; return table[sc];
} }
U8 scan_code_map[0x100]={ 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,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, 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, 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, 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, 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, 0x35, 0, 0, SC_ALT, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,SC_HOME, 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_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,
SC_CURSOR_DOWN,SC_PAGE_DOWN,SC_INS,SC_DELETE,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_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,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
}; };
U8 num_lock_map[0x100]={ 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, 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,8,9,10,0,5,6,7,0,2, 0, 0, 0, 0, 0, 0, SC_SHIFT, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3,4,11,0x34,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,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 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,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, 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, 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, 0x35, 0, 0, SC_ALT, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,SC_HOME, 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_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,
SC_CURSOR_DOWN,SC_PAGE_DOWN,SC_INS,SC_DELETE,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_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,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
}; };
U8 *Char2KeyName(I64 ch,Bool include_ctrl=TRUE) U8 *Char2KeyName(I64 ch, Bool include_ctrl=TRUE)
{//ASCII val to key name. {//ASCII val to key name.
I64 i; I64 i;
U8 buf[STR_LEN]; U8 buf[STR_LEN];
if (ch<=CH_SPACE) {
switch [ch] { if (ch <= CH_SPACE)
{
switch [ch]
{
case '\n': case '\n':
StrCopy(buf,"ENTER"); StrCopy(buf, "ENTER");
break; break;
case CH_BACKSPACE: case CH_BACKSPACE:
StrCopy(buf,"BACKSPACE"); StrCopy(buf, "BACKSPACE");
break; break;
case '\t': case '\t':
StrCopy(buf,"TAB"); StrCopy(buf, "TAB");
break; break;
case CH_ESC: case CH_ESC:
StrCopy(buf,"ESC"); StrCopy(buf, "ESC");
break; break;
case CH_SHIFT_ESC: case CH_SHIFT_ESC:
StrCopy(buf,"SHIFT_ESC"); StrCopy(buf, "SHIFT_ESC");
break; break;
case 0: //nobound switch case 0: //nobound switch
case 29: case 29:
case 30: case 30:
*buf=0; *buf = 0;
break; break;
case CH_SPACE: case CH_SPACE:
StrCopy(buf,"SPACE"); StrCopy(buf, "SPACE");
break; break;
default: default:
if (include_ctrl) if (include_ctrl)
StrCopy(buf,"CTRL "); StrCopy(buf, "CTRL ");
buf[i=StrLen(buf)]=ch-1+'a'; buf[i = StrLen(buf)] = ch - 1 + 'a';
buf[i+1]=0; buf[i + 1] = 0;
break; break;
} }
} else if (Bt(char_bmp_printable,ch)) { }
*buf=ch; else if (Bt(char_bmp_printable, ch))
buf[1]=0; {
} else *buf = ch;
*buf=0; buf[1] = 0;
}
else
*buf = 0;
return StrNew(buf); return StrNew(buf);
} }
U8 *ScanCode2KeyName(I64 sc) U8 *ScanCode2KeyName(I64 sc)
{//Scan code to key name. {//Scan code to key name.
I64 ch; I64 ch;
U8 buf[STR_LEN],*st; U8 buf[STR_LEN], *st;
*buf=0;
if (sc&SCF_CTRL) *buf = 0;
CatPrint(buf,"CTRL "); if (sc & SCF_CTRL)
if (sc&SCF_ALT) CatPrint(buf, "CTRL ");
CatPrint(buf,"ALT "); if (sc & SCF_ALT)
if (sc&SCF_SHIFT) CatPrint(buf, "ALT ");
CatPrint(buf,"SHIFT "); if (sc & SCF_SHIFT)
if (sc&SCF_NO_SHIFT) CatPrint(buf, "SHIFT ");
CatPrint(buf," "); if (sc & SCF_NO_SHIFT)
if (ch=ScanCode2Char(sc&255)) { CatPrint(buf, " ");
st=Char2KeyName(ch,FALSE); if (ch = ScanCode2Char(sc & 255))
StrCopy(buf+StrLen(buf),st); {
st = Char2KeyName(ch, FALSE);
StrCopy(buf + StrLen(buf), st);
Free(st); Free(st);
} else { }
switch (sc&255) { else
case SC_BACKSPACE:CatPrint(buf,"BACK"); break; {
case SC_CAPS: CatPrint(buf,"CAPS"); break; switch (sc & 255)
case SC_NUM: CatPrint(buf,"NUM"); break; {
case SC_SCROLL: CatPrint(buf,"SCROLL"); break; case SC_BACKSPACE: CatPrint(buf, "BACK"); break;
case SC_CURSOR_UP:CatPrint(buf,"UP"); break; case SC_CAPS: CatPrint(buf, "CAPS"); break;
case SC_CURSOR_DOWN:CatPrint(buf,"DOWN"); break; case SC_NUM: CatPrint(buf, "NUM"); break;
case SC_CURSOR_LEFT:CatPrint(buf,"LEFT"); break; case SC_SCROLL: CatPrint(buf, "SCROLL"); break;
case SC_CURSOR_RIGHT:CatPrint(buf,"RIGHT"); break; case SC_CURSOR_UP: CatPrint(buf, "UP"); break;
case SC_PAGE_UP: CatPrint(buf,"PAGE_UP"); break; case SC_CURSOR_DOWN: CatPrint(buf, "DOWN"); break;
case SC_PAGE_DOWN:CatPrint(buf,"PAGE_DOWN");break; case SC_CURSOR_LEFT: CatPrint(buf, "LEFT"); break;
case SC_HOME: CatPrint(buf,"HOME"); break; case SC_CURSOR_RIGHT: CatPrint(buf, "RIGHT"); break;
case SC_END: CatPrint(buf,"END"); break; case SC_PAGE_UP: CatPrint(buf, "PAGE_UP"); break;
case SC_INS: CatPrint(buf,"INS"); break; case SC_PAGE_DOWN: CatPrint(buf, "PAGE_DOWN"); break;
case SC_DELETE: CatPrint(buf,"DELETE"); break; case SC_HOME: CatPrint(buf, "HOME"); break;
case SC_F1: CatPrint(buf,"F1"); break; case SC_END: CatPrint(buf, "END"); break;
case SC_F2: CatPrint(buf,"F2"); break; case SC_INS: CatPrint(buf, "INS"); break;
case SC_F3: CatPrint(buf,"F3"); break; case SC_DELETE: CatPrint(buf, "DELETE"); break;
case SC_F4: CatPrint(buf,"F4"); break; case SC_F1: CatPrint(buf, "F1"); break;
case SC_F5: CatPrint(buf,"F5"); break; case SC_F2: CatPrint(buf, "F2"); break;
case SC_F6: CatPrint(buf,"F6"); break; case SC_F3: CatPrint(buf, "F3"); break;
case SC_F7: CatPrint(buf,"F7"); break; case SC_F4: CatPrint(buf, "F4"); break;
case SC_F8: CatPrint(buf,"F8"); break; case SC_F5: CatPrint(buf, "F5"); break;
case SC_F9: CatPrint(buf,"F9"); break; case SC_F6: CatPrint(buf, "F6"); break;
case SC_F10: CatPrint(buf,"F10"); break; case SC_F7: CatPrint(buf, "F7"); break;
case SC_F11: CatPrint(buf,"F11"); break; case SC_F8: CatPrint(buf, "F8"); break;
case SC_F12: CatPrint(buf,"F12"); break; case SC_F9: CatPrint(buf, "F9"); break;
case SC_GUI: CatPrint(buf,"WINDOWS"); break; case SC_F10: CatPrint(buf, "F10"); break;
case SC_PRINTSCREEN1: CatPrint(buf,"PRINTSCREEN1"); break; case SC_F11: CatPrint(buf, "F11"); break;
case SC_PRINTSCREEN2: CatPrint(buf,"PRINTSCREEN2"); break; case SC_F12: CatPrint(buf, "F12"); break;
case SC_GUI: CatPrint(buf, "WINDOWS"); break;
case SC_PRINTSCREEN1: CatPrint(buf, "PRINTSCREEN1"); break;
case SC_PRINTSCREEN2: CatPrint(buf, "PRINTSCREEN2"); break;
} }
} }
return StrNew(buf); return StrNew(buf);
} }
U0 KbdBuildSC(U8 raw_byte,Bool in_irq,U8 *_last_raw_byte,I64 *_last_sc) U0 KbdBuildSC(U8 raw_byte, Bool in_irq, U8 *_last_raw_byte, I64 *_last_sc)
{ {
I64 ch,sc_flags,sc,sc2,sc_raw,new_key_f; I64 ch, sc_flags, sc, sc2, sc_raw, new_key_f;
Bool set_LEDs=FALSE; Bool set_LEDs = FALSE;
if (raw_byte==0xE0) {
*_last_sc&=~0x1FF; if (raw_byte == 0xE0)
*_last_raw_byte=raw_byte; {
*_last_sc &= ~0x1FF;
*_last_raw_byte = raw_byte;
return; return;
} }
sc=raw_byte; sc = raw_byte;
BEqual(&sc,SCf_E0_PREFIX,*_last_raw_byte==0xE0); BEqual(&sc, SCf_E0_PREFIX, *_last_raw_byte == 0xE0);
BEqual(&sc,SCf_KEY_UP,raw_byte & 0x80); BEqual(&sc, SCf_KEY_UP, raw_byte & 0x80);
*_last_raw_byte=raw_byte; *_last_raw_byte = raw_byte;
sc_flags=_last_sc->u32[0]&~0x1FF; sc_flags = _last_sc->u32[0] & ~0x1FF;
sc_raw=sc; sc_raw = sc;
if (sc_flags & SCF_NUM) { if (sc_flags & SCF_NUM)
if (sc2=num_lock_map[sc.u8[0]]) {
sc.u8[0]=sc2; if (sc2 = num_lock_map[sc.u8[0]])
} else { sc.u8[0] = sc2;
if (sc2=scan_code_map[sc.u8[0]])
sc.u8[0]=sc2;
}
new_key_f=SCF_NEW_KEY;
if (sc&SCF_KEY_UP)
switch (sc&~SCF_KEY_UP) {
case SC_SHIFT: sc_flags&=~SCF_SHIFT; break;
case SC_CTRL: sc_flags&=~SCF_CTRL; break;
case SC_ALT: sc_flags&=~SCF_ALT; break;
case SC_DELETE: sc_flags&=~SCF_DELETE; break;
case SC_INS: sc_flags&=~SCF_INS; break;
// case SC_CAPS: sc_flags^=SCF_CAPS; set_LEDs=TRUE; break;
case SC_NUM: sc_flags^=SCF_NUM; set_LEDs=TRUE; break;
case SC_SCROLL: sc_flags^=SCF_SCROLL; set_LEDs=TRUE; break;
} }
else else
switch (sc) { {
if (sc2 = scan_code_map[sc.u8[0]])
sc.u8[0] = sc2;
}
new_key_f = SCF_NEW_KEY;
if (sc & SCF_KEY_UP)
switch (sc & ~SCF_KEY_UP)
{
case SC_SHIFT: sc_flags &= ~SCF_SHIFT; break;
case SC_CTRL: sc_flags &= ~SCF_CTRL; break;
case SC_ALT: sc_flags &= ~SCF_ALT; break;
case SC_DELETE: sc_flags &= ~SCF_DELETE; break;
case SC_INS: sc_flags &= ~SCF_INS; break;
case SC_CAPS: sc_flags ^= SCF_CAPS; set_LEDs=TRUE; break;
case SC_NUM: sc_flags ^= SCF_NUM; set_LEDs=TRUE; break;
case SC_SCROLL: sc_flags ^= SCF_SCROLL; set_LEDs=TRUE; break;
}
else
switch (sc)
{
case SC_SHIFT: case SC_SHIFT:
if (Bts(&sc_flags,SCf_SHIFT)) new_key_f=0; if (Bts(&sc_flags, SCf_SHIFT))
new_key_f = 0;
break; break;
case SC_CTRL: case SC_CTRL:
if (Bts(&sc_flags,SCf_CTRL)) new_key_f=0; if (Bts(&sc_flags, SCf_CTRL))
new_key_f = 0;
break; break;
case SC_ALT: case SC_ALT:
if (Bts(&sc_flags,SCf_ALT)) new_key_f=0; if (Bts(&sc_flags, SCf_ALT))
new_key_f = 0;
break; break;
case SC_DELETE: case SC_DELETE:
sc_flags|=SCF_DELETE; sc_flags |= SCF_DELETE;
break; break;
case SC_INS: case SC_INS:
sc_flags|=SCF_INS; sc_flags |= SCF_INS;
break; break;
} }
sc_flags|=new_key_f; sc_flags |= new_key_f;
sc=sc_flags|sc|(sc_flags|sc_raw)<<32; sc = sc_flags | sc | (sc_flags | sc_raw) << 32;
if (sc_flags & SCF_CTRL && sc_flags & SCF_ALT) { if (sc_flags & SCF_CTRL && sc_flags & SCF_ALT)
if (!(sc&SCF_KEY_UP)) { {
if (sc&255==SC_DELETE && !(sc_flags & SCF_SHIFT)) if (!(sc & SCF_KEY_UP))
{
if (sc & 255 == SC_DELETE && !(sc_flags & SCF_SHIFT))
CtrlAltDel(sc); CtrlAltDel(sc);
else {
if (sc&255==SC_ESC)
ch='t';
else if (sc&255==SC_TAB)
ch='n';
else else
ch=ScanCode2Char(sc&255); {
if ('a'<=ch<='z') { if (sc & 255 == SC_ESC)
sc&=~(SCF_NEW_KEY|SCF_NEW_KEY<<32); ch = 't';
ch-='a'; else if (sc & 255 == SC_TAB)
kbd.last_down_scan_code=sc; ch = 'n';
else
ch = ScanCode2Char(sc & 255);
if ('a' <= ch <= 'z')
{
sc &= ~(SCF_NEW_KEY | SCF_NEW_KEY << 32);
ch -= 'a';
kbd.last_down_scan_code = sc;
if (keydev.fp_ctrl_alt_cbs[ch] && if (keydev.fp_ctrl_alt_cbs[ch] &&
Bt(&keydev.ctrl_alt_in_irq_flags,ch)==in_irq && Bt(&keydev.ctrl_alt_in_irq_flags, ch) == in_irq &&
(!(sc_flags & SCF_SHIFT)&&keydev.ctrl_alt_no_shift_descs[ch]) || (!(sc_flags & SCF_SHIFT) &&
sc_flags & SCF_SHIFT && keydev.ctrl_alt_shift_descs[ch]) keydev.ctrl_alt_no_shift_descs[ch]) || sc_flags & SCF_SHIFT && keydev.ctrl_alt_shift_descs[ch])
(*keydev.fp_ctrl_alt_cbs[ch])(sc); (*keydev.fp_ctrl_alt_cbs[ch])(sc);
} }
} }
@ -379,101 +432,121 @@ U0 KbdBuildSC(U8 raw_byte,Bool in_irq,U8 *_last_raw_byte,I64 *_last_sc)
} }
if (set_LEDs && !in_irq) if (set_LEDs && !in_irq)
KbdLEDsSet(sc); KbdLEDsSet(sc);
*_last_sc=sc; *_last_sc = sc;
} }
U0 KbdPacketRead() U0 KbdPacketRead()
{ {
static U8 last_raw_byte=0; static U8 last_raw_byte = 0;
static I64 last_sc=0; static I64 last_sc = 0;
U8 raw_byte; U8 raw_byte;
if (TSCGet>kbd.timestamp+counts.time_stamp_freq>>3)
if (TSCGet>kbd.timestamp + counts.time_stamp_freq >> 3)
FifoU8Flush(kbd.fifo); FifoU8Flush(kbd.fifo);
kbd.timestamp=TSCGet; kbd.timestamp = TSCGet;
raw_byte=InU8(KBD_PORT); raw_byte = InU8(KBD_PORT);
KbdBuildSC(raw_byte,TRUE,&last_raw_byte,&last_sc); KbdBuildSC(raw_byte, TRUE, &last_raw_byte, &last_sc);
if (!FifoU8Count(kbd.fifo)) { if (!FifoU8Count(kbd.fifo))
FifoU8Insert(kbd.fifo,raw_byte); {
if (raw_byte!=0xE0) { FifoU8Insert(kbd.fifo, raw_byte);
while (FifoU8Remove(kbd.fifo,&raw_byte)) if (raw_byte != 0xE0)
FifoU8Insert(kbd.fifo2,raw_byte); {
while (FifoU8Remove(kbd.fifo, &raw_byte))
FifoU8Insert(kbd.fifo2, raw_byte);
} }
} else { }
FifoU8Insert(kbd.fifo,raw_byte); else
while (FifoU8Remove(kbd.fifo,&raw_byte)) {
FifoU8Insert(kbd.fifo2,raw_byte); FifoU8Insert(kbd.fifo, raw_byte);
while (FifoU8Remove(kbd.fifo, &raw_byte))
FifoU8Insert(kbd.fifo2, raw_byte);
} }
} }
interrupt U0 IRQKbd() interrupt U0 IRQKbd()
{ {
CLD CLD
OutU8(PIC_1,PIC_EOI); OutU8(PIC_1, PIC_EOI);
kbd.irqs_working=TRUE; kbd.irqs_working = TRUE;
if (mouse_hard.install_in_progress) { if (mouse_hard.install_in_progress)
kbd.reset=TRUE; {
kbd.reset = TRUE;
return; return;
} }
keydev.ctrl_alt_ret_addr=RBPGet()(I64)+8; keydev.ctrl_alt_ret_addr = RBPGet()(I64) + 8;
KbdPacketRead; KbdPacketRead;
} }
U0 KbdInit() U0 KbdInit()
{ {
try { try
{
KbdCmdFlush; KbdCmdFlush;
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse KbdCmdSend(KBD_CTRL, 0xA7); //Disable Mouse
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard KbdCmdSend(KBD_CTRL, 0xAE); //Enable Keyboard
KbdCmdSend(KBD_PORT,0xF0); KbdCmdSend(KBD_PORT, 0xF0);
KbdCmdSend(KBD_PORT,0x02); KbdCmdSend(KBD_PORT, 0x02);
KbdLEDsSet(kbd.scan_code); KbdLEDsSet(kbd.scan_code);
} catch {
KbdCmdFlush;
Fs->catch_except=TRUE;
} }
IntEntrySet(0x21,&IRQKbd); catch
OutU8(PIC_1_DATA,InU8(PIC_1_DATA)&~2); {
KbdCmdFlush;
Fs->catch_except = TRUE;
}
IntEntrySet(0x21, &IRQKbd);
OutU8(PIC_1_DATA, InU8(PIC_1_DATA) & ~2);
} }
U0 KbdHandler() U0 KbdHandler()
{ {
static U8 last_raw_byte=0; static U8 last_raw_byte = 0;
U8 raw_byte; U8 raw_byte;
FifoU8Remove(kbd.fifo2,&raw_byte);
KbdBuildSC(raw_byte,FALSE,&last_raw_byte,&kbd.scan_code); FifoU8Remove(kbd.fifo2, &raw_byte);
if (raw_byte==0xE0) { KbdBuildSC(raw_byte, FALSE, &last_raw_byte, &kbd.scan_code);
FifoU8Remove(kbd.fifo2,&raw_byte); if (raw_byte == 0xE0)
KbdBuildSC(raw_byte,FALSE,&last_raw_byte,&kbd.scan_code); {
FifoU8Remove(kbd.fifo2, &raw_byte);
KbdBuildSC(raw_byte, FALSE, &last_raw_byte, &kbd.scan_code);
} }
if (Btr(&kbd.scan_code,SCf_NEW_KEY)) { if (Btr(&kbd.scan_code, SCf_NEW_KEY))
kbd.new_key_timestamp=kbd.timestamp; {
Btr(&kbd.scan_code,32+SCf_NEW_KEY); kbd.new_key_timestamp = kbd.timestamp;
FifoI64Ins(kbd.scan_code_fifo,kbd.scan_code); Btr(&kbd.scan_code, 32 + SCf_NEW_KEY);
FifoI64Ins(kbd.scan_code_fifo, kbd.scan_code);
kbd.count++; kbd.count++;
if (!(kbd.scan_code&SCF_KEY_UP)) { if (!(kbd.scan_code & SCF_KEY_UP))
kbd.last_down_scan_code=kbd.scan_code; {
Bts(kbd.down_bitmap,kbd.scan_code.u8[0]); kbd.last_down_scan_code = kbd.scan_code;
Bts(kbd.down_bitmap2,kbd.scan_code.u8[4]); Bts(kbd.down_bitmap, kbd.scan_code.u8[0]);
} else { Bts(kbd.down_bitmap2, kbd.scan_code.u8[4]);
Btr(kbd.down_bitmap,kbd.scan_code.u8[0]); }
Btr(kbd.down_bitmap2,kbd.scan_code.u8[4]); else
{
Btr(kbd.down_bitmap, kbd.scan_code.u8[0]);
Btr(kbd.down_bitmap2, kbd.scan_code.u8[4]);
} }
} }
} }
I64 KbdMessagesQueue() I64 KbdMessagesQueue()
{ {
I64 arg1,arg2,message_code=MESSAGE_NULL; I64 arg1, arg2, message_code = MESSAGE_NULL;
CTask *task_focus; CTask *task_focus;
if (task_focus=sys_focus_task) { if (task_focus = sys_focus_task)
while (FifoI64Remove(kbd.scan_code_fifo,&arg2)) { {
arg1=ScanCode2Char(arg2); while (FifoI64Remove(kbd.scan_code_fifo, &arg2))
if (arg2 & SCF_KEY_UP) { {
TaskMessage(task_focus,0,MESSAGE_KEY_UP,arg1,arg2,0); arg1 = ScanCode2Char(arg2);
message_code=MESSAGE_KEY_UP; if (arg2 & SCF_KEY_UP)
} else { {
TaskMessage(task_focus,0,MESSAGE_KEY_DOWN,arg1,arg2,0); TaskMessage(task_focus, 0, MESSAGE_KEY_UP, arg1, arg2, 0);
message_code=MESSAGE_KEY_DOWN; message_code = MESSAGE_KEY_UP;
}
else
{
TaskMessage(task_focus, 0, MESSAGE_KEY_DOWN, arg1, arg2, 0);
message_code = MESSAGE_KEY_DOWN;
} }
} }
} }
@ -482,7 +555,7 @@ I64 KbdMessagesQueue()
I64 KbdMouseEventTime() I64 KbdMouseEventTime()
{//Timestamp of last key or mouse event. {//Timestamp of last key or mouse event.
if (mouse_hard.timestamp>kbd.timestamp) if (mouse_hard.timestamp > kbd.timestamp)
return mouse_hard.timestamp; return mouse_hard.timestamp;
else else
return kbd.new_key_timestamp; return kbd.new_key_timestamp;

View File

@ -1,109 +1,127 @@
U0 InputFilterTask() U0 InputFilterTask()
{ {
CJob *tmpc,*tmpc1; CJob *tmpc, *tmpc1;
Bool old_filter; Bool old_filter;
I64 old_flags=RFlagsGet; I64 old_flags = RFlagsGet;
Fs->win_inhibit=WIG_USER_TASK_DEFAULT;
LBts(&Fs->task_flags,TASKf_INPUT_FILTER_TASK); Fs->win_inhibit = WIG_USER_TASK_DEFAULT;
old_filter=LBts(&Fs->last_input_filter_task->task_flags,TASKf_FILTER_INPUT); LBts(&Fs->task_flags, TASKf_INPUT_FILTER_TASK);
LBEqual(&Fs->task_flags,TASKf_FILTER_INPUT,old_filter); old_filter = LBts(&Fs->last_input_filter_task->task_flags, TASKf_FILTER_INPUT);
while (TRUE) { LBEqual(&Fs->task_flags, TASKf_FILTER_INPUT, old_filter);
while (TRUE)
{
CLI CLI
JobsHandler(old_flags); JobsHandler(old_flags);
tmpc1=&Fs->server_ctrl.next_waiting; tmpc1 = &Fs->server_ctrl.next_waiting;
tmpc=tmpc1->next; tmpc = tmpc1->next;
if (tmpc==tmpc1) if (tmpc == tmpc1)
break; break;
else { else
if (tmpc->job_code==JOBT_TEXT_INPUT) { {
if (tmpc->job_code == JOBT_TEXT_INPUT)
{
QueueRemove(tmpc); QueueRemove(tmpc);
RFlagsSet(old_flags); RFlagsSet(old_flags);
try try
ExePrint("%s",tmpc->aux_str); ExePrint("%s", tmpc->aux_str);
catch catch
Fs->catch_except=TRUE; Fs->catch_except = TRUE;
JobDel(tmpc); JobDel(tmpc);
} else }
else
break; break;
} }
} }
Fs->next_input_filter_task->last_input_filter_task=Fs->last_input_filter_task; 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; Fs->last_input_filter_task->next_input_filter_task = Fs->next_input_filter_task;
if (!old_filter) if (!old_filter)
LBtr(&Fs->last_input_filter_task->task_flags,TASKf_FILTER_INPUT); LBtr(&Fs->last_input_filter_task->task_flags, TASKf_FILTER_INPUT);
RFlagsSet(old_flags); RFlagsSet(old_flags);
} }
I64 MessageScan(I64 *_arg1=NULL,I64 *_arg2=NULL,I64 mask=~1,CTask *task=NULL) I64 MessageScan(I64 *_arg1=NULL, I64 *_arg2=NULL, I64 mask=~1, CTask *task=NULL)
{/*Check for a message of type specified by a one in the mask. {/*Check for a message of type specified by a one in the mask.
Throw-out messages not in mask. Throw-out messages not in mask.
If no message fit mask, return NULL immediately. If no message fit mask, return NULL immediately.
Remove desired message, return $LK,"message_code",A="MN:MESSAGE_CMD"$. Remove desired message, return $LK,"message_code",A="MN:MESSAGE_CMD"$.
Note: This delivers messages from parent down to pop-up. Note: This delivers messages from parent down to pop-up.
*/ */
I64 res,old_flags; I64 res, old_flags;
CJob *tmpc,*tmpc1; CJob *tmpc, *tmpc1;
if (!task) task=Fs;
old_flags=RFlagsGet; if (!task)
tmpc1=&task->server_ctrl.next_waiting; task = Fs;
while (TRUE) { old_flags = RFlagsGet;
tmpc1 =&task->server_ctrl.next_waiting;
while (TRUE)
{
CLI CLI
if (task==Fs) if (task == Fs)
JobsHandler(old_flags); JobsHandler(old_flags);
tmpc=tmpc1->next; tmpc = tmpc1->next;
if (tmpc==tmpc1) if (tmpc == tmpc1)
break; break;
else { else
if (tmpc->job_code==JOBT_MESSAGE) { {
if (tmpc->job_code == JOBT_MESSAGE)
{
QueueRemove(tmpc); QueueRemove(tmpc);
RFlagsSet(old_flags); RFlagsSet(old_flags);
res=tmpc->message_code; res = tmpc->message_code;
if (_arg1) if (_arg1)
*_arg1=tmpc->aux1; *_arg1 = tmpc->aux1;
if (_arg2) if (_arg2)
*_arg2=tmpc->aux2; *_arg2 = tmpc->aux2;
JobDel(tmpc); JobDel(tmpc);
if ((res!=MESSAGE_KEY_DOWN || !(tmpc->aux2&SCF_KEY_DESC) || if ((res != MESSAGE_KEY_DOWN || !(tmpc->aux2 & SCF_KEY_DESC) || !Bt(&task->win_inhibit, WIf_SELF_KEY_DESC)) &&
!Bt(&task->win_inhibit,WIf_SELF_KEY_DESC)) && Bt(&mask,res)) Bt(&mask, res))
goto sm_done; goto sm_done;
} }
} }
RFlagsSet(old_flags); RFlagsSet(old_flags);
} }
res=MESSAGE_NULL; res = MESSAGE_NULL;
if (_arg1) if (_arg1)
*_arg1=0; *_arg1 = 0;
if (_arg2) if (_arg2)
*_arg2=0; *_arg2 = 0;
if (task->parent_task&&task->parent_task->popup_task==task) { if (task->parent_task && task->parent_task->popup_task == task)
{
RFlagsSet(old_flags); RFlagsSet(old_flags);
return MessageScan(_arg1,_arg2,mask,task->parent_task); return MessageScan(_arg1, _arg2, mask, task->parent_task);
} }
sm_done: sm_done:
RFlagsSet(old_flags); RFlagsSet(old_flags);
return res; return res;
} }
I64 FlushMessages(CTask *task=NULL) I64 FlushMessages(CTask *task=NULL)
{//Throw away all messages. Return count. {//Throw away all messages. Return count.
I64 res=0,arg1,arg2; I64 res = 0, arg1, arg2;
while (MessageScan(&arg1,&arg2,~1,task))
while (MessageScan(&arg1, &arg2, ~1, task))
res++; res++;
return res; return res;
} }
I64 MessageGet(I64 *_arg1=NULL,I64 *_arg2=NULL,I64 mask=~1,CTask *task=NULL) I64 MessageGet(I64 *_arg1=NULL, I64 *_arg2=NULL, I64 mask=~1, CTask *task=NULL)
{//Wait for a message of type specified by a one in the mask. {//Wait for a message of type specified by a one in the mask.
//Throw-out all messages not in mask. //Throw-out all messages not in mask.
//Returns $LK,"message_code",A="MN:MESSAGE_CMD"$. See $LK,"::/Demo/MessageLoop.CC"$. //Returns $LK,"message_code",A="MN:MESSAGE_CMD"$. See $LK,"::/Demo/MessageLoop.CC"$.
I64 res; I64 res;
if (!task) task=Fs;
LBtr(&task->task_flags,TASKf_IDLE); if (!task)
while (!(res=MessageScan(_arg1,_arg2,mask,task))) { task = Fs;
LBts(&task->task_flags,TASKf_IDLE); LBtr(&task->task_flags, TASKf_IDLE);
while (!(res = MessageScan(_arg1, _arg2, mask, task)))
{
LBts(&task->task_flags, TASKf_IDLE);
Yield; Yield;
} }
LBtr(&task->task_flags,TASKf_IDLE); LBtr(&task->task_flags, TASKf_IDLE);
return res; return res;
} }
@ -111,92 +129,116 @@ I64 CharScan()
{//Checks for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ and returns 0 immediately if no key. {//Checks for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ and returns 0 immediately if no key.
//Waits for $LK,"MESSAGE_KEY_UP",A="MN:MESSAGE_KEY_UP"$ of non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key and returns $LK,"ASCII",A="MN:CH_CTRLA"$ if key. //Waits for $LK,"MESSAGE_KEY_UP",A="MN:MESSAGE_KEY_UP"$ of non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key and returns $LK,"ASCII",A="MN:CH_CTRLA"$ if key.
//$LK,"MessageScan",A="MN:MessageScan"$() throws away other message types. //$LK,"MessageScan",A="MN:MessageScan"$() throws away other message types.
I64 arg1a,arg2a,arg1b,arg2b; I64 arg1a, arg2a, arg1b, arg2b;
if (!MessageScan(&arg1a,&arg2a,1<<MESSAGE_KEY_DOWN)||!arg1a)
if (!MessageScan(&arg1a, &arg2a, 1 << MESSAGE_KEY_DOWN) || !arg1a)
return 0; return 0;
else else
do MessageGet(&arg1b,&arg2b,1<<MESSAGE_KEY_UP); do MessageGet(&arg1b, &arg2b, 1 << MESSAGE_KEY_UP);
while (!arg1b); //Be careful of $LK,"SC_SHIFT",A="MN:SC_SHIFT"$ and $LK,"SC_CTRL",A="MN:SC_CTRL"$, etc. while (!arg1b); //Be careful of $LK,"SC_SHIFT",A="MN:SC_SHIFT"$ and $LK,"SC_CTRL",A="MN:SC_CTRL"$, etc.
return arg1a; return arg1a;
} }
Bool KeyScan(I64 *_ch=NULL,I64 *_scan_code=NULL,Bool echo=FALSE) Bool KeyScan(I64 *_ch=NULL, I64 *_scan_code=NULL, Bool echo=FALSE)
{//Checks for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ and returns FALSE immediately if no key. {//Checks for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ and returns FALSE immediately if no key.
//Sets $LK,"ASCII",A="MN:CH_CTRLA"$ and $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$. //Sets $LK,"ASCII",A="MN:CH_CTRLA"$ and $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$.
//Removes key message and returns TRUE. //Removes key message and returns TRUE.
//$LK,"MessageScan",A="MN:MessageScan"$() throws away other message types. //$LK,"MessageScan",A="MN:MessageScan"$() throws away other message types.
I64 ch=0,sc=0; I64 ch = 0, sc = 0;
if (MessageScan(&ch,&sc,1<<MESSAGE_KEY_DOWN)) {
if (_ch) *_ch=ch; if (MessageScan(&ch, &sc, 1 << MESSAGE_KEY_DOWN))
if (_scan_code) *_scan_code=sc; {
if (_ch)
*_ch = ch;
if (_scan_code)
*_scan_code = sc;
if (echo) if (echo)
PutKey(ch,sc); PutKey(ch, sc);
return TRUE; return TRUE;
} else { }
if (_ch) *_ch=0; else
if (_scan_code) *_scan_code=0; {
if (_ch)
*_ch = 0;
if (_scan_code)
*_scan_code = 0;
return FALSE; return FALSE;
} }
} }
I64 KeyGet(I64 *_scan_code=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE) I64 KeyGet(I64 *_scan_code=NULL, Bool echo=FALSE, Bool raw_cursor=FALSE)
{//Waits for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ message and returns $LK,"ASCII",A="MN:CH_CTRLA"$. {//Waits for $LK,"MESSAGE_KEY_DOWN",A="MN:MESSAGE_KEY_DOWN"$ message and returns $LK,"ASCII",A="MN:CH_CTRLA"$.
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$. //Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$.
//$LK,"KeyScan",A="MN:KeyScan"$() throws away other message types. //$LK,"KeyScan",A="MN:KeyScan"$() throws away other message types.
I64 ch,sc; I64 ch, sc;
Bool cursor_on=FALSE; Bool cursor_on = FALSE;
while (!KeyScan(&ch,&sc,FALSE)) {
if (IsRaw && raw_cursor) { while (!KeyScan(&ch, &sc, FALSE))
if (!cursor_on && ToI64(TSCGet*5/counts.time_stamp_freq)&1) { {
if (IsRaw && raw_cursor)
{
if (!cursor_on && ToI64(TSCGet * 5 / counts.time_stamp_freq) & 1)
{
'Û'; 'Û';
cursor_on=TRUE; cursor_on = TRUE;
} else if (cursor_on && !(ToI64(TSCGet*5/counts.time_stamp_freq)&1)) { }
else if (cursor_on && !(ToI64(TSCGet * 5 / counts.time_stamp_freq) & 1))
{
'' CH_BACKSPACE; '' CH_BACKSPACE;
cursor_on=FALSE; cursor_on = FALSE;
} }
} }
LBts(&Fs->task_flags,TASKf_IDLE); LBts(&Fs->task_flags, TASKf_IDLE);
if (IsDebugMode) { if (IsDebugMode)
{
//We don't want interrupt-driven keyboard when in debugger //We don't want interrupt-driven keyboard when in debugger
//because that could have side-effects or crash, so we poll //because that could have side-effects or crash, so we poll
//keyboard when in debugger with interrupts off. //keyboard when in debugger with interrupts off.
PUSHFD PUSHFD
CLI CLI
KbdMouseHandler(TRUE,FALSE); KbdMouseHandler(TRUE, FALSE);
KbdMessagesQueue; KbdMessagesQueue;
POPFD POPFD
} else { }
LBts(&Fs->task_flags,TASKf_AWAITING_MESSAGE); else
{
LBts(&Fs->task_flags, TASKf_AWAITING_MESSAGE);
Yield; Yield;
} }
LBtr(&Fs->task_flags,TASKf_IDLE); LBtr(&Fs->task_flags, TASKf_IDLE);
} }
if (IsRaw && raw_cursor && cursor_on) if (IsRaw && raw_cursor && cursor_on)
'' CH_BACKSPACE; '' CH_BACKSPACE;
if (echo) if (echo)
PutKey(ch,sc); PutKey(ch, sc);
if (_scan_code) *_scan_code=sc; if (_scan_code)
*_scan_code = sc;
return ch; return ch;
} }
I64 CharGet(I64 *_scan_code=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE) I64 CharGet(I64 *_scan_code=NULL, Bool echo=TRUE, Bool raw_cursor=FALSE)
{//Waits for non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key. {//Waits for non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key.
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$. //Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.DD"$.
I64 ch1; I64 ch1;
do ch1=KeyGet(_scan_code,FALSE,raw_cursor);
do ch1 = KeyGet(_scan_code, FALSE, raw_cursor);
while (!ch1); while (!ch1);
if (echo) if (echo)
"$$PT$$%c$$FG$$",ch1; "$$PT$$%c$$FG$$", ch1;
return ch1; return ch1;
} }
U8 *StrGet(U8 *message=NULL,U8 *default=NULL,I64 flags=NONE) U8 *StrGet(U8 *message=NULL, U8 *default=NULL, I64 flags=NONE)
{//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string. See $LK,"Flags",A="MN:SGF_SHIFT_ESC_EXIT"$. {//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string. See $LK,"Flags",A="MN:SGF_SHIFT_ESC_EXIT"$.
U8 *st; U8 *st;
if (message) if (message)
"" message,default; "" message, default;
st=(*fp_getstr2)(flags); st = (*fp_getstr2)(flags);
if (!*st) { if (!*st)
{
Free(st); Free(st);
if (default) if (default)
return StrNew(default); return StrNew(default);
@ -206,39 +248,54 @@ U8 *StrGet(U8 *message=NULL,U8 *default=NULL,I64 flags=NONE)
return st; return st;
} }
I64 StrNGet(U8 *buf,I64 size,Bool allow_ext=TRUE) I64 StrNGet(U8 *buf, I64 size, Bool allow_ext=TRUE)
{//Prompt into fixed length string. Size must include terminator. {//Prompt into fixed length string. Size must include terminator.
U8 *st; U8 *st;
I64 ch,i=0; I64 ch, i=0;
if (!size || !buf) return 0;
if (allow_ext) { if (!size || !buf)
st=StrGet; return 0;
if (StrLen(st)>size-1) { if (allow_ext)
MemCopy(buf,st,size-1); {
buf[size-1]=0; st = StrGet;
} else if (StrLen(st) > size - 1)
StrCopy(buf,st); {
i=StrLen(buf); MemCopy(buf, st, size - 1);
buf[size - 1] = 0;
}
else
StrCopy(buf, st);
i = StrLen(buf);
Free(st); Free(st);
} else { }
while (TRUE) { else
ch=CharGet(,FALSE,IsDebugMode); {
if (ch=='\n') { while (TRUE)
{
ch = CharGet(, FALSE, IsDebugMode);
if (ch == '\n')
{
'' ch; '' ch;
break; break;
} else if (ch==CH_BACKSPACE) { }
if (i>0) { else if (ch == CH_BACKSPACE)
{
if (i > 0)
{
i--; i--;
'' ch; '' ch;
} }
} else { }
if (i<size-1) { else
buf[i++]=ch; {
if (i < size - 1)
{
buf[i++] = ch;
'' ch; '' ch;
} }
} }
} }
buf[i]=0; buf[i] = 0;
} }
return i; return i;
} }

View File

@ -1,100 +1,107 @@
U0 GridInit() U0 GridInit()
{//Init mouse grid struct. See $LK,"::/Demo/Graphics/Grid.CC"$. {//Init mouse grid struct. See $LK,"::/Demo/Graphics/Grid.CC"$.
mouse_grid.x=mouse_grid.y=mouse_grid.z=8; mouse_grid.x = mouse_grid.y = mouse_grid.z = 8;
mouse_grid.x_offset=mouse_grid.y_offset=mouse_grid.z_offset=0; mouse_grid.x_offset = mouse_grid.y_offset = mouse_grid.z_offset = 0;
mouse_grid.x_speed =mouse_grid.y_speed =mouse_grid.z_speed =1; mouse_grid.x_speed = mouse_grid.y_speed = mouse_grid.z_speed = 1;
mouse_grid.show=mouse_grid.snap=mouse_grid.coord=FALSE; mouse_grid.show = mouse_grid.snap = mouse_grid.coord = FALSE;
} }
U0 MouseUpdate(I64 x,I64 y,I64 z,Bool l,Bool r) U0 MouseUpdate(I64 x, I64 y, I64 z, Bool l, Bool r)
{ {
mouse.presnap.x=ToI64(mouse.scale.x*x)+mouse.offset.x; mouse.presnap.x = ToI64(mouse.scale.x * x) + mouse.offset.x;
mouse.presnap.y=ToI64(mouse.scale.y*y)+mouse.offset.y; mouse.presnap.y = ToI64(mouse.scale.y * y) + mouse.offset.y;
mouse.presnap.z=ToI64(mouse.scale.z*z)+mouse.offset.z; mouse.presnap.z = ToI64(mouse.scale.z * z) + mouse.offset.z;
if (mouse_grid.snap) { if (mouse_grid.snap)
mouse.pos.x=Trunc(mouse.presnap.x/mouse_grid.x)*mouse_grid.x+mouse_grid.x_offset; {
mouse.pos.y=Trunc(mouse.presnap.y/mouse_grid.y)*mouse_grid.y+mouse_grid.y_offset; mouse.pos.x = Trunc(mouse.presnap.x / mouse_grid.x) * mouse_grid.x + mouse_grid.x_offset;
mouse.pos.z=Trunc(mouse.presnap.z/mouse_grid.z)*mouse_grid.z+mouse_grid.z_offset; mouse.pos.y = Trunc(mouse.presnap.y / mouse_grid.y) * mouse_grid.y + mouse_grid.y_offset;
} else { mouse.pos.z = Trunc(mouse.presnap.z / mouse_grid.z) * mouse_grid.z + mouse_grid.z_offset;
mouse.pos.x=mouse.presnap.x; }
mouse.pos.y=mouse.presnap.y; else
mouse.pos.z=mouse.presnap.z; {
mouse.pos.x = mouse.presnap.x;
mouse.pos.y = mouse.presnap.y;
mouse.pos.z = mouse.presnap.z;
} }
mouse.pos.x=ClampI64(mouse.pos.x,0,sys_vbe_mode.width-1); mouse.pos.x = ClampI64(mouse.pos.x, 0, sys_vbe_mode.width - 1);
mouse.pos.y=ClampI64(mouse.pos.y,0,sys_vbe_mode.height-1); mouse.pos.y = ClampI64(mouse.pos.y, 0, sys_vbe_mode.height - 1);
mouse.pos_text.x=mouse.pos.x/FONT_WIDTH; mouse.pos_text.x = mouse.pos.x / FONT_WIDTH;
if (mouse.pos_text.x>=text.cols) { if (mouse.pos_text.x >= text.cols)
mouse.pos_text.x=text.cols-1; {
mouse.pos.x=text.cols*FONT_WIDTH-1; mouse.pos_text.x = text.cols - 1;
mouse.pos.x = text.cols * FONT_WIDTH - 1;
} }
mouse.pos_text.y=mouse.pos.y/FONT_HEIGHT; mouse.pos_text.y = mouse.pos.y / FONT_HEIGHT;
if (mouse.pos_text.y>=text.rows) { if (mouse.pos_text.y >= text.rows)
mouse.pos_text.y=text.rows-1; {
mouse.pos.y=text.rows*FONT_HEIGHT-1; mouse.pos_text.y = text.rows - 1;
mouse.pos.y = text.rows * FONT_HEIGHT - 1;
} }
mouse.lb=l; mouse.lb = l;
mouse.rb=r; mouse.rb = r;
LBEqual(&kbd.scan_code,SCf_MS_L_DOWN,mouse.lb); LBEqual(&kbd.scan_code, SCf_MS_L_DOWN, mouse.lb);
LBEqual(&kbd.scan_code,SCf_MS_R_DOWN,mouse.rb); LBEqual(&kbd.scan_code, SCf_MS_R_DOWN, mouse.rb);
} }
U0 MouseSet(I64 x=I64_MAX,I64 y=I64_MAX,I64 z=I64_MAX,I64 l=I64_MAX,I64 r=I64_MAX) U0 MouseSet(I64 x=I64_MAX, I64 y=I64_MAX, I64 z=I64_MAX, I64 l=I64_MAX, I64 r=I64_MAX)
{//Note: Generates a message. See $LK,"MouseSet",A="FF:::/Demo/Games/Zing.CC,MouseSet"$(). {//Note: Generates a message. See $LK,"MouseSet",A="FF:::/Demo/Games/Zing.CC,MouseSet"$().
if (!(0<=x<sys_vbe_mode.width)) if (!(0 <= x < sys_vbe_mode.width))
x=mouse.pos.x; x = mouse.pos.x;
if (!(0<=y<sys_vbe_mode.height)) if (!(0 <= y < sys_vbe_mode.height))
y=mouse.pos.y; y = mouse.pos.y;
if (z==I64_MAX) if (z == I64_MAX)
z=mouse.pos.z; z = mouse.pos.z;
if (!(FALSE<=l<=TRUE)) if (!(FALSE <= l <= TRUE))
l=mouse.lb; l = mouse.lb;
if (!(FALSE<=r<=TRUE)) if (!(FALSE <= r <= TRUE))
r=mouse.rb; r = mouse.rb;
x=(x-mouse.offset.x)/mouse.scale.x; x = (x - mouse.offset.x) / mouse.scale.x;
y=(y-mouse.offset.y)/mouse.scale.y; y = (y - mouse.offset.y) / mouse.scale.y;
z=(z-mouse.offset.z)/mouse.scale.z; z = (z - mouse.offset.z) / mouse.scale.z;
MouseUpdate(x,y,z,l,r); MouseUpdate(x, y, z, l, r);
MouseHardSet(x,y,z,l,r); MouseHardSet(x, y, z, l, r);
} }
U0 MouseInit() U0 MouseInit()
{ {
MemSet(&mouse,0,sizeof(CMouseStateGlobals)); MemSet(&mouse, 0, sizeof(CMouseStateGlobals));
MemSet(&mouse_last,0,sizeof(CMouseStateGlobals)); MemSet(&mouse_last, 0, sizeof(CMouseStateGlobals));
mouse.offset.x=mouse.offset.y=mouse.offset.z=0; mouse.offset.x = mouse.offset.y = mouse.offset.z = 0;
mouse.scale.x=mouse.scale.y=mouse.scale.z=1.0; mouse.scale.x = mouse.scale.y = mouse.scale.z = 1.0;
mouse.pos_text.x=mouse.pos_text.y=mouse.pos_text.z=0; mouse.pos_text.x = mouse.pos_text.y = mouse.pos_text.z = 0;
mouse.has_wheel=FALSE; mouse.has_wheel = FALSE;
mouse.show=TRUE; mouse.show = TRUE;
mouse.speed=0; mouse.speed = 0;
mouse.timestamp=TSCGet; mouse.timestamp = TSCGet;
mouse.dbl_time=0.350; mouse.dbl_time = 0.350;
GridInit; GridInit;
} }
U0 MouseHardPacketRead() U0 MouseHardPacketRead()
{ {
U8 j; U8 j;
if (TSCGet>mouse_hard.timestamp+counts.time_stamp_freq>>3)
if (TSCGet > mouse_hard.timestamp + counts.time_stamp_freq >> 3)
FifoU8Flush(mouse_hard.fifo); FifoU8Flush(mouse_hard.fifo);
mouse_hard.timestamp=TSCGet; mouse_hard.timestamp = TSCGet;
FifoU8Insert(mouse_hard.fifo,InU8(KBD_PORT)); FifoU8Insert(mouse_hard.fifo, InU8(KBD_PORT));
if (FifoU8Count(mouse_hard.fifo)==mouse_hard.pkt_size) if (FifoU8Count(mouse_hard.fifo) == mouse_hard.pkt_size)
while (FifoU8Remove(mouse_hard.fifo,&j)) while (FifoU8Remove(mouse_hard.fifo, &j))
FifoU8Insert(mouse_hard.fifo2,j); FifoU8Insert(mouse_hard.fifo2, j);
} }
interrupt U0 IRQMouseHard() interrupt U0 IRQMouseHard()
{ {
CLD CLD
OutU8(PIC_2,PIC_EOI); OutU8(PIC_2, PIC_EOI);
OutU8(PIC_1,PIC_EOI); OutU8(PIC_1, PIC_EOI);
mouse_hard.irqs_working=TRUE; mouse_hard.irqs_working = TRUE;
if (mouse_hard.install_in_progress || !mouse_hard.installed) { if (mouse_hard.install_in_progress || !mouse_hard.installed)
kbd.reset=TRUE; {
kbd.reset = TRUE;
return; return;
} }
MouseHardPacketRead; MouseHardPacketRead;
@ -103,146 +110,158 @@ interrupt U0 IRQMouseHard()
U0 MouseHardGetType() U0 MouseHardGetType()
{ {
I64 b; I64 b;
KbdMouseCmdAck(0xF2); KbdMouseCmdAck(0xF2);
b=KbdCmdRead; b = KbdCmdRead;
if (b==3) if (b == 3)
mouse_hard.has_wheel=TRUE; mouse_hard.has_wheel = TRUE;
else if (b==4) else if (b == 4)
mouse_hard.has_ext_bttns=TRUE; mouse_hard.has_ext_bttns = TRUE;
} }
Bool MouseHardReset() Bool MouseHardReset()
{ {
U8 b,*_b; U8 b, *_b;
F64 timeout; F64 timeout;
Bool res=FALSE; Bool res = FALSE;
mouse_hard.has_wheel=FALSE; mouse_hard.has_wheel = FALSE;
mouse_hard.has_ext_bttns=FALSE; mouse_hard.has_ext_bttns = FALSE;
if (*0x40E(U16 *)==0x9FC0) { if (*0x40E(U16 *) == 0x9FC0)
_b=0x9FC00+0x30; {
*_b=1; //This enables my mouse. It might be for one machine. _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? //USB DMA packets, set-up by BIOS to make legacy PS/2?
} }
try { try
{
KbdCmdFlush; KbdCmdFlush;
KbdCmdSend(KBD_CTRL,0xAD); //Disable Kbd KbdCmdSend(KBD_CTRL, 0xAD); //Disable Kbd
KbdCmdSend(KBD_CTRL,0xA8); //Enable Mouse KbdCmdSend(KBD_CTRL, 0xA8); //Enable Mouse
KbdMouseCmdAck(0xFF); //Reset KbdMouseCmdAck(0xFF); //Reset
timeout=tS+10.0; timeout = tS + 10.0;
do do
try { try
{
KbdCmdRead; KbdCmdRead;
timeout=0; //force exit timeout = 0; //force exit
} catch }
Fs->catch_except=TRUE; catch
while (tS<timeout); Fs->catch_except = TRUE;
while (tS < timeout);
try try
KbdCmdRead; KbdCmdRead;
catch catch
Fs->catch_except=TRUE; Fs->catch_except = TRUE;
KbdMouseCmdAck(0xF3,200,0xF3,100,0xF3,80); KbdMouseCmdAck(0xF3, 200, 0xF3, 100, 0xF3, 80);
MouseHardGetType; MouseHardGetType;
KbdMouseCmdAck(0xF3,10); KbdMouseCmdAck(0xF3, 10);
MouseHardGetType; MouseHardGetType;
KbdMouseCmdAck(0xE8,0x03,0xE6,0xF3,100,0xF4); KbdMouseCmdAck(0xE8, 0x03, 0xE6, 0xF3, 100, 0xF4);
res=TRUE; res = TRUE;
//Enable IRQ 12 //Enable IRQ 12
KbdCmdSend(KBD_CTRL,0x20); KbdCmdSend(KBD_CTRL, 0x20);
b=KbdCmdRead; b = KbdCmdRead;
KbdCmdSend(KBD_CTRL,0x60); KbdCmdSend(KBD_CTRL, 0x60);
KbdCmdSend(KBD_PORT,(b|2)&~0x20); KbdCmdSend(KBD_PORT, (b | 2) & ~0x20);
} catch }
Fs->catch_except=TRUE; catch
Fs->catch_except = TRUE;
//This is been added to override failure //This is been added to override failure
//because the mouse sometimes still works. //because the mouse sometimes still works.
res=TRUE; res = TRUE;
try try
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard KbdCmdSend(KBD_CTRL, 0xAE); //Enable Keyboard
catch catch
Fs->catch_except=TRUE; Fs->catch_except = TRUE;
if (mouse_hard.has_wheel || mouse_hard.has_ext_bttns) if (mouse_hard.has_wheel || mouse_hard.has_ext_bttns)
mouse_hard.pkt_size=4; mouse_hard.pkt_size = 4;
else else
mouse_hard.pkt_size=3; mouse_hard.pkt_size = 3;
if (!res) if (!res)
try try
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse KbdCmdSend(KBD_CTRL, 0xA7); //Disable Mouse
catch catch
Fs->catch_except=TRUE; Fs->catch_except = TRUE;
return res; return res;
} }
U0 MouseHardSpeedSet() U0 MouseHardSpeedSet()
{ {
I64 dd,tmp; I64 dd, tmp;
if ((dd=SqrI64(mouse_hard_last.pos.x-mouse_hard.pos.x)
+SqrI64(mouse_hard_last.pos.y-mouse_hard.pos.y)) && if ((dd = SqrI64(mouse_hard_last.pos.x - mouse_hard.pos.x) + SqrI64(mouse_hard_last.pos.y - mouse_hard.pos.y)) &&
(tmp=mouse_hard.timestamp-mouse_hard_last.timestamp)) (tmp = mouse_hard.timestamp - mouse_hard_last.timestamp))
mouse_hard.speed=Sqrt(dd)*counts.time_stamp_freq/tmp; mouse_hard.speed = Sqrt(dd) * counts.time_stamp_freq / tmp;
mouse_hard_last.timestamp=mouse_hard.timestamp; mouse_hard_last.timestamp = mouse_hard.timestamp;
} }
U0 MouseHardSetPre() U0 MouseHardSetPre()
{ {
I64 old_timestamp=mouse_hard_last.timestamp; I64 old_timestamp = mouse_hard_last.timestamp;
MemCopy(&mouse_hard_last,&mouse_hard,sizeof(CMouseHardStateGlobals));
mouse_hard_last.timestamp=old_timestamp; MemCopy(&mouse_hard_last, &mouse_hard, sizeof(CMouseHardStateGlobals));
mouse_hard_last.timestamp = old_timestamp;
} }
U0 MouseHardSetPost() U0 MouseHardSetPost()
{ {
I64 i; I64 i;
mouse_hard.pos.x=mouse_hard.prescale.x*mouse_hard.scale.x*mouse_grid.x_speed;
mouse_hard.pos.y=mouse_hard.prescale.y*mouse_hard.scale.y*mouse_grid.y_speed;
mouse_hard.pos.z=mouse_hard.prescale.z*mouse_hard.scale.z*mouse_grid.z_speed;
i=Trunc(mouse.scale.x*mouse_hard.pos.x/mouse_grid.x)*mouse_grid.x+mouse.offset.x; mouse_hard.pos.x = mouse_hard.prescale.x * mouse_hard.scale.x * mouse_grid.x_speed;
mouse_hard.pos.y = mouse_hard.prescale.y * mouse_hard.scale.y * mouse_grid.y_speed;
mouse_hard.pos.z = mouse_hard.prescale.z * mouse_hard.scale.z * mouse_grid.z_speed;
i = Trunc(mouse.scale.x * mouse_hard.pos.x / mouse_grid.x) * mouse_grid.x + mouse.offset.x;
//TODO mouse_grid.x_offset? //TODO mouse_grid.x_offset?
if (i<0) if (i < 0)
mouse.offset.x-=i; mouse.offset.x -= i;
else if (i>=sys_vbe_mode.width) else if (i >= sys_vbe_mode.width)
mouse.offset.x+=sys_vbe_mode.width-1-i; mouse.offset.x += sys_vbe_mode.width - 1 - i;
i=Trunc(mouse.scale.y*mouse_hard.pos.y/mouse_grid.y)*mouse_grid.y+mouse.offset.y; i = Trunc(mouse.scale.y * mouse_hard.pos.y / mouse_grid.y) * mouse_grid.y + mouse.offset.y;
if (i<0) if (i < 0)
mouse.offset.y-=i; mouse.offset.y -= i;
else if (i>=sys_vbe_mode.height) else if (i >= sys_vbe_mode.height)
mouse.offset.y+=sys_vbe_mode.height-1-i; mouse.offset.y += sys_vbe_mode.height - 1 - i;
if (mouse_hard.pos.x!=mouse_hard_last.pos.x || mouse_hard.pos.y!=mouse_hard_last.pos.y || if (mouse_hard.pos.x != mouse_hard_last.pos.x || mouse_hard.pos.y != mouse_hard_last.pos.y ||
mouse_hard.pos.z!=mouse_hard_last.pos.z) { mouse_hard.pos.z != mouse_hard_last.pos.z)
mouse_hard.event=TRUE; {
mouse_hard.event = TRUE;
MouseHardSpeedSet; MouseHardSpeedSet;
} else }
for (i=0;i<5;i++) else
if (mouse_hard.bttns[i]!=mouse_hard_last.bttns[i]) { for (i = 0; i < 5; i++)
mouse_hard.event=TRUE; if (mouse_hard.bttns[i] != mouse_hard_last.bttns[i])
{
mouse_hard.event = TRUE;
break; break;
} }
} }
U0 MouseHardHandler() U0 MouseHardHandler()
{ {
I64 i,dx,dy,dz; I64 i, dx, dy, dz;
U8 mouse_buf[4]; U8 mouse_buf[4];
MouseHardSetPre; MouseHardSetPre;
for (i=0;i<4;i++) for (i = 0; i < 4; i++)
mouse_buf[i]=0; mouse_buf[i] = 0;
for (i=0;i<mouse_hard.pkt_size;i++) for (i = 0; i < mouse_hard.pkt_size; i++)
if (!FifoU8Remove(mouse_hard.fifo2,&mouse_buf[i])) if (!FifoU8Remove(mouse_hard.fifo2, &mouse_buf[i]))
mouse_buf[i]=0; mouse_buf[i] = 0;
mouse_hard.bttns[0] = mouse_buf[0] & 1; mouse_hard.bttns[0] = mouse_buf[0] & 1;
mouse_hard.bttns[1] = (mouse_buf[0] & 2) >> 1; mouse_hard.bttns[1] = (mouse_buf[0] & 2) >> 1;
@ -250,34 +269,34 @@ U0 MouseHardHandler()
mouse_hard.bttns[3] = (mouse_buf[3] & 0x10) >> 4; mouse_hard.bttns[3] = (mouse_buf[3] & 0x10) >> 4;
mouse_hard.bttns[4] = (mouse_buf[3] & 0x20) >> 5; mouse_hard.bttns[4] = (mouse_buf[3] & 0x20) >> 5;
if (mouse_buf[0] & 0x10) if (mouse_buf[0] & 0x10)
dx=mouse_buf[1]-256; dx = mouse_buf[1]-256;
else else
dx=mouse_buf[1]; dx = mouse_buf[1];
if (mouse_buf[0] & 0x20) if (mouse_buf[0] & 0x20)
dy=256-mouse_buf[2]; dy = 256 - mouse_buf[2];
else else
dy=-mouse_buf[2]; dy = -mouse_buf[2];
if (mouse_buf[3] & 0x08) if (mouse_buf[3] & 0x08)
dz=mouse_buf[3]&7-8; dz = mouse_buf[3] & 7 - 8;
else else
dz=mouse_buf[3]&7; dz = mouse_buf[3] & 7;
mouse_hard.prescale.x+=dx; mouse_hard.prescale.x += dx;
mouse_hard.prescale.y+=dy; mouse_hard.prescale.y += dy;
mouse_hard.prescale.z+=dz; mouse_hard.prescale.z += dz;
MouseHardSetPost; MouseHardSetPost;
} }
U0 MouseHardSet(I64 x,I64 y,I64 z,I64 l,I64 r) U0 MouseHardSet(I64 x, I64 y, I64 z, I64 l, I64 r)
{ {
mouse_hard.timestamp=TSCGet; mouse_hard.timestamp = TSCGet;
MouseHardSetPre; MouseHardSetPre;
mouse_hard.prescale.x=x/mouse_hard.scale.x/mouse_grid.x_speed; mouse_hard.prescale.x = x / mouse_hard.scale.x / mouse_grid.x_speed;
mouse_hard.prescale.y=y/mouse_hard.scale.y/mouse_grid.y_speed; mouse_hard.prescale.y = y / mouse_hard.scale.y / mouse_grid.y_speed;
mouse_hard.prescale.z=z/mouse_hard.scale.z/mouse_grid.z_speed; mouse_hard.prescale.z = z / mouse_hard.scale.z / mouse_grid.z_speed;
mouse_hard.bttns[0]=l; mouse_hard.bttns[0] = l;
mouse_hard.bttns[1]=r; mouse_hard.bttns[1] = r;
MouseHardSetPost; MouseHardSetPost;
} }
@ -287,13 +306,14 @@ U0 KbdMouseReset()
FifoU8Flush(kbd.fifo2); FifoU8Flush(kbd.fifo2);
FifoU8Flush(mouse_hard.fifo2); FifoU8Flush(mouse_hard.fifo2);
FifoI64Flush(kbd.scan_code_fifo); FifoI64Flush(kbd.scan_code_fifo);
kbd.scan_code=0; kbd.scan_code = 0;
kbd.reset=FALSE; kbd.reset = FALSE;
} }
Bool MouseHardEnable(Bool val=TRUE) Bool MouseHardEnable(Bool val=TRUE)
{ {
Bool old_val = mouse_hard.enabled; Bool old_val = mouse_hard.enabled;
if (val) if (val)
{ {
KbdCmdSend(KBD_CTRL, KBDC_ENABLE_MS); KbdCmdSend(KBD_CTRL, KBDC_ENABLE_MS);
@ -311,45 +331,50 @@ Bool MouseHardDriverInstall(I64 dummy=0) //can be spawned
{ {
no_warn dummy; no_warn dummy;
I64 i; I64 i;
mouse_hard.install_in_progress=TRUE;
OutU8(PIC_2_DATA,InU8(PIC_2_DATA)|0x10); mouse_hard.install_in_progress = TRUE;
mouse_hard.installed=mouse_hard.irqs_working=FALSE; OutU8(PIC_2_DATA, InU8(PIC_2_DATA) | 0x10);
IntEntrySet(0x2C,&IRQMouseHard); mouse_hard.installed = mouse_hard.irqs_working = FALSE;
for(i=0;i<5;i++) IntEntrySet(0x2C, &IRQMouseHard);
mouse_hard.bttns[i]=0; for(i = 0; i < 5; i++)
if (i=MouseHardReset) mouse_hard.bttns[i] = 0;
OutU8(PIC_2_DATA,InU8(PIC_2_DATA)&~0x10); if (i = MouseHardReset)
OutU8(PIC_2_DATA, InU8(PIC_2_DATA) & ~0x10);
KbdMouseReset; KbdMouseReset;
mouse_hard.install_attempts++; mouse_hard.install_attempts++;
mouse_hard.installed=mouse_hard.event=i; mouse_hard.installed = mouse_hard.event=i;
mouse_hard.install_in_progress=FALSE; mouse_hard.install_in_progress = FALSE;
return mouse_hard.installed; return mouse_hard.installed;
} }
U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse) U0 KbdMouseHandler(Bool poll_kbd, Bool poll_mouse)
{ {
if (mouse_hard.install_in_progress) { if (mouse_hard.install_in_progress)
{
Yield; Yield;
return; return;
} }
if (kbd.reset) if (kbd.reset)
KbdMouseReset; KbdMouseReset;
else { else
if (poll_mouse && mouse_hard.installed && !mouse_hard.irqs_working) { {
if (poll_mouse && mouse_hard.installed && !mouse_hard.irqs_working)
{
PUSHFD PUSHFD
CLI CLI
while (InU8(KBD_CTRL)&1) while (InU8(KBD_CTRL) & 1)
MouseHardPacketRead; MouseHardPacketRead;
POPFD POPFD
} }
if (poll_kbd) if (poll_kbd)
while (InU8(KBD_CTRL)&1) while (InU8(KBD_CTRL) & 1)
KbdPacketRead; KbdPacketRead;
if (kbd.reset) if (kbd.reset)
KbdMouseReset; KbdMouseReset;
else { else
{
while (FifoU8Count(kbd.fifo2)) while (FifoU8Count(kbd.fifo2))
KbdHandler; KbdHandler;
while (FifoU8Count(mouse_hard.fifo2)) while (FifoU8Count(mouse_hard.fifo2))
@ -363,22 +388,22 @@ U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
U0 KbdMouseInit() U0 KbdMouseInit()
{ {
MemSet(&kbd,0,sizeof(CKbdStateGlobals)); MemSet(&kbd, 0, sizeof(CKbdStateGlobals));
kbd.fifo=FifoU8New(8); kbd.fifo = FifoU8New(8);
kbd.fifo2=FifoU8New(0x1000); kbd.fifo2 = FifoU8New(0x1000);
kbd.scan_code_fifo=FifoI64New(0x1000); kbd.scan_code_fifo = FifoI64New(0x1000);
kbd.irqs_working=FALSE; kbd.irqs_working = FALSE;
MemSet(&mouse_hard,0,sizeof(CMouseHardStateGlobals)); MemSet(&mouse_hard, 0, sizeof(CMouseHardStateGlobals));
mouse_hard.enabled=TRUE; mouse_hard.enabled = TRUE;
mouse_hard.fifo=FifoU8New(8); mouse_hard.fifo = FifoU8New(8);
mouse_hard.fifo2=FifoU8New(0x1000); mouse_hard.fifo2 = FifoU8New(0x1000);
mouse_hard.scale.x=0.5; mouse_hard.scale.x = 0.5;
mouse_hard.scale.y=0.5; mouse_hard.scale.y = 0.5;
mouse_hard.scale.z=1.0; mouse_hard.scale.z = 1.0;
mouse_hard.prescale.x=sys_vbe_mode.width/mouse_hard.scale.x/2.0; mouse_hard.prescale.x = sys_vbe_mode.width / mouse_hard.scale.x / 2.0;
mouse_hard.prescale.y=sys_vbe_mode.height/mouse_hard.scale.y/2.0; mouse_hard.prescale.y = sys_vbe_mode.height / mouse_hard.scale.y / 2.0;
mouse_hard.prescale.z=0/mouse_hard.scale.z; mouse_hard.prescale.z = 0 / mouse_hard.scale.z;
mouse_hard.pos.x=sys_vbe_mode.width>>1; mouse_hard.pos.x = sys_vbe_mode.width >> 1;
mouse_hard.pos.y=sys_vbe_mode.height>>1; mouse_hard.pos.y = sys_vbe_mode.height >> 1;
MemCopy(&mouse_hard_last,&mouse_hard,sizeof(CMouseHardStateGlobals)); MemCopy(&mouse_hard_last, &mouse_hard, sizeof(CMouseHardStateGlobals));
} }