TempleOSCD_140715.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:09 +02:00
1 parent 7ef616a20e
commit 64f679eeb9
1095 files changed
+24814 -221011

No files matched your search

+54 -67
View File
@@ -1,70 +1,67 @@
U0 GridInit()
{
{//Init input pointer grid struct.
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)
U0 IPVarsUpdate(I64 x,I64 y,I64 z,Bool l,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;
ip.presnap.x=ToI64(ip.scale.x*x)+ip.offset.x;
ip.presnap.y=ToI64(ip.scale.y*y)+ip.offset.y;
ip.presnap.z=ToI64(ip.scale.z*z)+ip.offset.z;
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;
ip.pos.x=Trunc(ip.presnap.x/ip_grid.x)*ip_grid.x+ip_grid.x_offset;
ip.pos.y=Trunc(ip.presnap.y/ip_grid.y)*ip_grid.y+ip_grid.y_offset;
ip.pos.z=Trunc(ip.presnap.z/ip_grid.z)*ip_grid.z+ip_grid.z_offset;
} else {
ipx=ipx_presnap;
ipy=ipy_presnap;
ipz=ipz_presnap;
ip.pos.x=ip.presnap.x;
ip.pos.y=ip.presnap.y;
ip.pos.z=ip.presnap.z;
}
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;
ip.pos.x=ClampI64(ip.pos.x,0,GR_WIDTH-1);
ip.pos.y=ClampI64(ip.pos.y,0,GR_HEIGHT-1);
ip.throttle=ClampI64(ip.throttle,MIN_I32,MAX_I32);
ip.pos_text.x=ip.pos.x/FONT_WIDTH;
if (ip.pos_text.x>=text.cols) {
ip.pos_text.x=text.cols-1;
ip.pos.x=text.cols*FONT_WIDTH-1;
}
ipty=ipy/FONT_HEIGHT;
if (ipty>=text_rows) {
ipty=text_rows-1;
ipy=text_rows*FONT_HEIGHT-1;
ip.pos_text.y=ip.pos.y/FONT_HEIGHT;
if (ip.pos_text.y>=text.rows) {
ip.pos_text.y=text.rows-1;
ip.pos.y=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);
ip.lb=l;
ip.rb=r;
LBEqu(&kbd.scan_code,SCf_IP_L_DOWN,ip.lb);
LBEqu(&kbd.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.
U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=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 (!(0<=x<GR_WIDTH))
x=ip.pos.x;
if (!(0<=y<GR_HEIGHT))
y=ip.pos.y;
if (z==MAX_I64)
z=ipz;
z=ip.pos.z;
if (!(FALSE<=l<=TRUE))
l=ip_lb;
if (!(FALSE<=c<=TRUE))
c=ip_cb;
l=ip.lb;
if (!(FALSE<=r<=TRUE))
r=ip_rb;
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) {
x=(x-ip.offset.x)/ip.scale.x;
y=(y-ip.offset.y)/ip.scale.y;
z=(z-ip.offset.z)/ip.scale.z;
IPVarsUpdate(x,y,z,l,r);
switch (ip.dev) {
case IP_MOUSE:
SetMouseIP(x,y,z,l,c,r);
SetMouseIP(x,y,z,l,r);
break;
}
Preempt(old_preempt);
@@ -72,28 +69,18 @@ U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=MAX_I64,I
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;
MemSet(&ip,0,sizeof(CIPStateGlbls));
MemSet(&ip_last,0,sizeof(CIPStateGlbls));
ip.throttle=0;
ip.throttle_step=(MAX_I32+1)>>3;
ip.offset.x=ip.offset.y=ip.offset.z=0;
ip.scale.x=ip.scale.y=ip.scale.z=1.0;
ip.dev=IP_NULL;
ip.pos_text.x=ip.pos_text.y=ip.pos_text.z=0;
ip.has_wheel=FALSE;
ip.show=TRUE;
ip.speed=0;
ip.timestamp=GetTSC;
ip.dbl_time=0.350;
GridInit;
}
+85 -78
View File
@@ -81,7 +81,7 @@ U0 KbdMouseCmdAck(U8 val)
}
U0 SetTypeMatic(U8 delay)
{
{//Set speed of repeated keys.
try {
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
@@ -94,8 +94,8 @@ U0 SetTypeMatic(U8 delay)
}
}
I64 A2ScanCode(I64 ch,I64 sc_flags=0)
{ //ASCII val to scan code (Slow)
I64 Char2ScanCode(I64 ch,I64 sc_flags=0)
{//ASCII val to scan code (Slow).
I64 i;
U8 *table;
if (sc_flags) {
@@ -130,9 +130,8 @@ I64 A2ScanCode(I64 ch,I64 sc_flags=0)
}
}
U8 ScanCode2A(I64 sc)
{//Scan Code to ASCII val
U8 ScanCode2Char(I64 sc)
{//Scan code to ASCII val.
U8 *table=NORMAL_KEY_SCAN_DECODE_TABLE;
if (sc & SCF_E0_PREFIX)
return 0;
@@ -172,7 +171,6 @@ U8 scan_code_map[0x100]={
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,
@@ -193,8 +191,8 @@ U8 num_lock_map[0x100]={
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
U8 *Char2KeyName(I64 ch,Bool include_ctrl=TRUE)
{//ASCII val to key name.
I64 i;
U8 buf[136];
if (ch<=CH_SPACE) {
@@ -241,7 +239,7 @@ U8 *A2KeyName(I64 ch,Bool include_ctrl=TRUE)
}
U8 *ScanCode2KeyName(I64 sc)
{
{//Scan code to key name.
I64 ch;
U8 buf[136],*st;
*buf=0;
@@ -251,8 +249,8 @@ U8 *ScanCode2KeyName(I64 sc)
CatPrint(buf,"ALT ");
if (sc&SCF_SHIFT)
CatPrint(buf,"SHIFT ");
if (ch=ScanCode2A(sc&255)) {
st=A2KeyName(ch,FALSE);
if (ch=ScanCode2Char(sc&255)) {
st=Char2KeyName(ch,FALSE);
StrCpy(buf+StrLen(buf),st);
Free(st);
} else {
@@ -319,41 +317,41 @@ I64 KbdBuildSC(U8 raw_byte,U8 *_last_raw_byte,I64 *_last_sc,
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_SHIFT: sc_flags&=~SCF_SHIFT; goto kb_new_key_done;
case SC_CTRL: sc_flags&=~SCF_CTRL; goto kb_new_key_done;
case SC_ALT: sc_flags&=~SCF_ALT; goto kb_new_key_done;
case SC_DELETE: sc_flags&=~SCF_DELETE; goto kb_new_key_done;
case SC_INS: sc_flags&=~SCF_INS; goto kb_new_key_done;
case SC_CAPS:
sc_flags^=SCF_CAPS;
*_set_LEDs=TRUE;
goto new_key_done;
goto kb_new_key_done;
case SC_NUM:
sc_flags^=SCF_NUM;
*_set_LEDs=TRUE;
goto new_key_done;
goto kb_new_key_done;
case SC_SCROLL:
sc_flags^=SCF_SCROLL;
*_set_LEDs=TRUE;
goto new_key_done;
goto kb_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;
case SC_SHIFT: sc_flags|=SCF_SHIFT; goto kb_new_key_done;
case SC_CTRL: sc_flags|=SCF_CTRL; goto kb_new_key_done;
case SC_ALT: sc_flags|=SCF_ALT; goto kb_new_key_done;
case SC_DELETE: sc_flags|=SCF_DELETE; goto kb_new_key_done;
case SC_INS: sc_flags|=SCF_INS; goto kb_new_key_done;
case SC_CAPS: goto kb_new_key_done;
case SC_NUM: goto kb_new_key_done;
case SC_SCROLL: goto kb_new_key_done;
}
if (sc_flags & SCF_CTRL && sc_flags & SCF_ALT) {
sc_flags&=~SCF_NEW_KEY;
*_ctrl_alt=TRUE;
} else {
new_key_done:
kb_new_key_done:
sc_flags|=SCF_NEW_KEY;
}
return *_last_sc=sc_flags|sc|(sc_flags|sc_raw)<<32;
@@ -367,9 +365,9 @@ U0 KbdPktRead()
I64 ch,sc;
Bool set_LEDs,ctrl_alt;
if (GetTSC>kbd_evt_time+time_stamp_freq>>3)
FifoU8Flush(kbd_fifo);
kbd_evt_time=GetTSC;
if (GetTSC>kbd.timestamp+cnts.time_stamp_freq>>3)
FifoU8Flush(kbd.fifo);
kbd.timestamp=GetTSC;
raw_byte=InU8(KBD_PORT);
sc=KbdBuildSC(raw_byte,&last_raw_byte,&last_sc,&set_LEDs,&ctrl_alt);
if (ctrl_alt && sc) {
@@ -382,25 +380,25 @@ U0 KbdPktRead()
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);
ch=ScanCode2Char(sc&255);
if ('a'<=ch<='z' && keydev.fp_ctrl_alt_let_cbs[ch-'a'] &&
Bt(&keydev.ctrl_alt_let_in_irq_flags,ch-'a')) {
(*keydev.fp_ctrl_alt_let_cbs[ch-'a'])(last_sc);
return;
}
}
}
}
if (!FifoU8Cnt(kbd_fifo)) {
FifoU8Ins(kbd_fifo,raw_byte);
if (!FifoU8Cnt(kbd.fifo)) {
FifoU8Ins(kbd.fifo,raw_byte);
if (raw_byte!=0xE0) {
while (FifoU8Rem(kbd_fifo,&raw_byte))
FifoU8Ins(kbd2_fifo,raw_byte);
while (FifoU8Rem(kbd.fifo,&raw_byte))
FifoU8Ins(kbd.fifo2,raw_byte);
}
} else {
FifoU8Ins(kbd_fifo,raw_byte);
while (FifoU8Rem(kbd_fifo,&raw_byte))
FifoU8Ins(kbd2_fifo,raw_byte);
FifoU8Ins(kbd.fifo,raw_byte);
while (FifoU8Rem(kbd.fifo,&raw_byte))
FifoU8Ins(kbd.fifo2,raw_byte);
}
}
@@ -408,15 +406,26 @@ interrupt U0 KbdIntHandler()
{
CLD
OutU8(0x20,0x20);
kbd_irqs_working=TRUE;
if (mouse_install_attempt_in_progress) {
kbdmouse_rst=TRUE;
kbd.irqs_working=TRUE;
if (mouse.install_in_progress) {
kbd.rst=TRUE;
return;
}
ctrl_alt_let_ret_addr=GetRBP()(I64)+8;
keydev.ctrl_alt_let_ret_addr=GetRBP()(I64)+8;
KbdPktRead;
}
U0 SetCtrlAltLetCB(U8 ch,U0 (*fp_handler)(I64 sc),U8 *desc,Bool in_irq=FALSE)
{//Set callback for <CTRL-ALT-letter>.
ch=ToUpper(ch)-'A';
if (ch<26) {
keydev.fp_ctrl_alt_let_cbs[ch]=fp_handler;
Free(keydev.ctrl_alt_let_descs[ch]);
keydev.ctrl_alt_let_descs[ch]=AStrNew(desc);
BEqu(&keydev.ctrl_alt_let_in_irq_flags,ch,in_irq);
}
}
U0 KbdInit()
{
try {
@@ -425,7 +434,7 @@ U0 KbdInit()
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
KbdCmdSend(KBD_PORT,0xF0);
KbdCmdSend(KBD_PORT,0x02);
KbdSetLEDs(sys_cur_scan_code);
KbdSetLEDs(kbd.scan_code);
} catch {
KbdCmdFlush;
Fs->catch_except=TRUE;
@@ -449,13 +458,13 @@ U0 KbdHandler()
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);
FifoU8Rem(kbd.fifo2,&raw_byte);
sc=KbdBuildSC(raw_byte,&last_raw_byte,&kbd.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);
FifoU8Rem(kbd.fifo2,&raw_byte);
sc=KbdBuildSC(raw_byte,&last_raw_byte,&kbd.scan_code,&set_LEDs,&ctrl_alt);
if (set_LEDs)
KbdSetLEDs(sc);
}
@@ -466,42 +475,40 @@ U0 KbdHandler()
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);
ch=ScanCode2Char(sc&255);
if ('a'<=ch<='z' && keydev.fp_ctrl_alt_let_cbs[ch-'a'] &&
!Bt(&keydev.ctrl_alt_let_in_irq_flags,ch-'a'))
(*keydev.fp_ctrl_alt_let_cbs[ch-'a'])(kbd.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]);
if (Btr(&kbd.scan_code,SCf_NEW_KEY)) {
Btr(&kbd.scan_code,32+SCf_NEW_KEY);
FifoI64Ins(kbd.scan_code_fifo,kbd.scan_code);
kbd.cnt++;
if (!(kbd.scan_code&SCF_KEY_UP)) {
kbd.last_down_scan_code=kbd.scan_code;
Bts(kbd.down_bitmap,kbd.scan_code.u8[0]);
Bts(kbd.down_bitmap2,kbd.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]);
Btr(kbd.down_bitmap,kbd.scan_code.u8[0]);
Btr(kbd.down_bitmap2,kbd.scan_code.u8[4]);
}
}
}
I64 KbdMsgsQue()
{
I64 p1,p2,msg_code=MSG_NULL;
I64 a1,a2,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);
while (FifoI64Rem(kbd.scan_code_fifo,&a2)) {
a1=ScanCode2Char(a2);
if (a2 & SCF_KEY_UP) {
TaskMsg(task_focus,0,MSG_KEY_UP,a1,a2,0);
msg_code=MSG_KEY_UP;
} else {
TaskMsg(task_focus,0,
MSG_KEY_DOWN,p1,p2,0);
TaskMsg(task_focus,0,MSG_KEY_DOWN,a1,a2,0);
msg_code=MSG_KEY_DOWN;
}
}
@@ -510,9 +517,9 @@ I64 KbdMsgsQue()
}
I64 KbdMouseEvtTime()
{
if (mouse_evt_time>kbd_evt_time)
return mouse_evt_time;
{//Timestamp of last key or mouse event.
if (mouse.timestamp>kbd.timestamp)
return mouse.timestamp;
else
return kbd_evt_time;
return kbd.timestamp;
}
+66 -42
View File
@@ -36,8 +36,13 @@ U0 InputFilterTask()
SetRFlags(old_flags);
}
I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
{
I64 ScanMsg(I64 *_a1=NULL,I64 *_a2=NULL,I64 mask=~1,CTask *task=NULL)
{/*Check for a message of type specified by a one in the mask.
Throw-out messages not in mask.
If no message fit mask, return NULL immediately.
Remove desired message, return $LK,"msg_code",A="MN:MSG_CMD"$.
Note: This delivers messages from parent down to pop-up.
*/
I64 result,old_flags;
CSrvCmd *tempc,*tempc1;
if (!task) task=Fs;
@@ -55,10 +60,10 @@ I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
QueRem(tempc);
SetRFlags(old_flags);
result=tempc->msg_code;
if (_p1)
*_p1=tempc->aux1;
if (_p2)
*_p2=tempc->aux2;
if (_a1)
*_a1=tempc->aux1;
if (_a2)
*_a2=tempc->aux2;
SrvCmdDel(tempc);
if ((result!=MSG_KEY_DOWN || !(tempc->aux2&SCF_KEY_DESC) ||
Bt(&mask,MSGF_ALLOW_KEY_DESC)) && Bt(&mask,result))
@@ -68,13 +73,13 @@ I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
SetRFlags(old_flags);
}
result=MSG_NULL;
if (_p1)
*_p1=0;
if (_p2)
*_p2=0;
if (_a1)
*_a1=0;
if (_a2)
*_a2=0;
if (task->parent_task&&task->parent_task->popup_task==task) {
SetRFlags(old_flags);
return ScanMsg(_p1,_p2,mask,task->parent_task);
return ScanMsg(_a1,_a2,mask,task->parent_task);
}
sm_done:
SetRFlags(old_flags);
@@ -82,20 +87,22 @@ sm_done:
}
I64 FlushMsgs(CTask *task=NULL)
{
I64 result=0,p1,p2;
while (ScanMsg(&p1,&p2,~1,task))
{//Throw away all messages. Return count.
I64 result=0,a1,a2;
while (ScanMsg(&a1,&a2,~1,task))
result++;
return result;
}
I64 GetMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
{
I64 GetMsg(I64 *_a1=NULL,I64 *_a2=NULL,I64 mask=~1,CTask *task=NULL)
{//Wait for a message of type specified by a one in the mask.
//Throw-out all messages not in mask.
//Returns $LK,"msg_code",A="MN:MSG_CMD"$. See $LK,"::/Demo/MsgLoop.CPP"$.
I64 result;
Bool old_preempt=Preempt(OFF);
if (!task) task=Fs;
LBtr(&task->task_flags,TASKf_IDLE);
while (!(result=ScanMsg(_p1,_p2,mask,task))) {
while (!(result=ScanMsg(_a1,_a2,mask,task))) {
LBts(&task->task_flags,TASKf_IDLE);
Yield;
}
@@ -105,42 +112,49 @@ I64 GetMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
}
I64 ScanChar()
{
I64 p1a,p2a,p1b,p2b;
if (!ScanMsg(&p1a,&p2a,1<<MSG_KEY_DOWN)||!p1a)
{//Checks for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ and returns 0 immediately if no key.
//Waits for $LK,"MSG_KEY_UP",A="MN:MSG_KEY_UP"$ of non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key and returns $LK,"ASCII",A="MN:CH_CTRLA"$ if key.
//$LK,"ScanMsg",A="MN:ScanMsg"$() throws away other message types.
I64 a1a,a2a,a1b,a2b;
if (!ScanMsg(&a1a,&a2a,1<<MSG_KEY_DOWN)||!a1a)
return 0;
else
do GetMsg(&p1b,&p2b,1<<MSG_KEY_UP);
while (!p1b);
return p1a;
do GetMsg(&a1b,&a2b,1<<MSG_KEY_UP);
while (!a1b); //Be careful of $LK,"SC_SHIFT",A="MN:SC_SHIFT"$ and $LK,"SC_CTRL",A="MN:SC_CTRL"$, etc.
return a1a;
}
Bool ScanKey(I64 *_ch=NULL,I64 *_scancode=NULL,Bool echo=FALSE)
{
Bool ScanKey(I64 *_ch=NULL,I64 *_scan_code=NULL,Bool echo=FALSE)
{//Checks for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ and returns FALSE immediately if no key.
//Sets $LK,"ASCII",A="MN:CH_CTRLA"$ and $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
//Removes key message and returns TRUE.
//$LK,"ScanMsg",A="MN:ScanMsg"$() throws away other message types.
I64 ch=0,sc=0;
if (ScanMsg(&ch,&sc,1<<MSG_KEY_DOWN)) {
if (_ch) *_ch=ch;
if (_scancode) *_scancode=sc;
if (_scan_code) *_scan_code=sc;
if (echo)
PutKey(ch,sc);
return TRUE;
} else {
if (_ch) *_ch=0;
if (_scancode) *_scancode=0;
if (_scan_code) *_scan_code=0;
return FALSE;
}
}
I64 GetKey(I64 *_scancode=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
{
I64 GetKey(I64 *_scan_code=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
{//Waits for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ message and returns $LK,"ASCII",A="MN:CH_CTRLA"$.
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
//$LK,"ScanKey",A="MN:ScanKey"$() throws away other message types.
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) {
if (!cursor_on && ToI64(GetTSC*5/cnts.time_stamp_freq)&1) {
'Û';
cursor_on=TRUE;
} else if (cursor_on && !(ToI64(GetTSC*5/time_stamp_freq)&1)) {
} else if (cursor_on && !(ToI64(GetTSC*5/cnts.time_stamp_freq)&1)) {
'' CH_BACKSPACE;
cursor_on=FALSE;
}
@@ -168,34 +182,44 @@ I64 GetKey(I64 *_scancode=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
Preempt(old_preempt);
if (echo)
PutKey(ch,sc);
if (_scancode) *_scancode=sc;
if (_scan_code) *_scan_code=sc;
return ch;
}
I64 GetChar(I64 *_scancode=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE)
{
I64 GetChar(I64 *_scan_code=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE)
{//Waits for non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key.
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
I64 ch1;
do ch1=GetKey(_scancode,FALSE,raw_cursor);
do ch1=GetKey(_scan_code,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);
U8 *GetStr(U8 *msg=NULL,U8 *dft=NULL,I64 flags=0)
{//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string. See $LK,"Flags",A="MN:GSF_SHIFT_ESC_EXIT"$.
U8 *st;
if (msg)
"" msg,dft;
st=(*fp_getstr2)(flags);
if (!*st) {
Free(st);
if (dft)
return StrNew(dft);
else
return StrNew("");
}
return st;
}
I64 GetS(U8 *buf,I64 size,Bool allow_ext=TRUE)
{
{//Prompt into fixed length string. Size must include terminator.
U8 *st;
I64 ch,i=0;
if (!size || !buf) return 0;
if (allow_ext) {
st=MGetS;
st=GetStr;
if (StrLen(st)>size-1) {
MemCpy(buf,st,size-1);
buf[size-1]=0;
+99 -120
View File
@@ -1,13 +1,13 @@
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);
if (GetTSC>mouse.timestamp+cnts.time_stamp_freq>>3)
FifoU8Flush(mouse.fifo);
mouse.timestamp=GetTSC;
FifoU8Ins(mouse.fifo,InU8(KBD_PORT));
if (FifoU8Cnt(mouse.fifo)==mouse.pkt_size)
while (FifoU8Rem(mouse.fifo,&j))
FifoU8Ins(mouse.fifo2,j);
}
interrupt U0 MouseIntHandler()
@@ -15,9 +15,9 @@ 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;
mouse.irqs_working=TRUE;
if (mouse.install_in_progress || !mouse.installed) {
kbd.rst=TRUE;
return;
}
MousePktRead;
@@ -29,9 +29,9 @@ U0 MouseGetDevType()
KbdMouseCmdAck(0xF2);
b=KbdCmdRead;
if (b==3)
mouse_has_wheel=TRUE;
mouse.has_wheel=TRUE;
else if (b==4)
mouse_has_ext_buttons=TRUE;
mouse.has_ext_buttons=TRUE;
}
Bool MouseRst()
@@ -41,8 +41,8 @@ Bool MouseRst()
F64 timeout;
Bool result=FALSE,present;
mouse_has_wheel=FALSE;
mouse_has_ext_buttons=FALSE;
mouse.has_wheel=FALSE;
mouse.has_ext_buttons=FALSE;
_w=0x40E;
present=MemPagePresentMark(_w,TRUE);
@@ -115,10 +115,10 @@ Bool MouseRst()
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
catch
Fs->catch_except=TRUE;
if (mouse_has_wheel || mouse_has_ext_buttons)
mouse_pkt_size=4;
if (mouse.has_wheel || mouse.has_ext_buttons)
mouse.pkt_size=4;
else
mouse_pkt_size=3;
mouse.pkt_size=3;
if (!result)
try
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
@@ -127,50 +127,48 @@ Bool MouseRst()
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;
if ((dd=SqrI64(mouse_last.pos.x-mouse.pos.x)+SqrI64(mouse_last.pos.y-mouse.pos.y)) &&
(temp=mouse.timestamp-mouse_last.timestamp))
mouse.speed=Sqrt(dd)*cnts.time_stamp_freq/temp;
mouse_last.timestamp=mouse.timestamp;
}
U0 MouseUpdatePre(Bool *old_buttons)
U0 MouseUpdatePre()
{
I64 i;
old_mxx=mxx; old_myy=myy; old_mzz=mzz;
for (i=0;i<5;i++)
old_buttons[i]=mouse_buttons[i];
I64 old_timestamp=mouse_last.timestamp;
MemCpy(&mouse_last,&mouse,sizeof(CMouseStateGlbls));
mouse_last.timestamp=old_timestamp;
}
U0 MouseUpdatePost(Bool *old_buttons)
U0 MouseUpdatePost()
{
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;
mouse.pos.x=mouse.prescale.x*mouse.scale.x*ip_grid.x_speed;
mouse.pos.y=mouse.prescale.y*mouse.scale.y*ip_grid.y_speed;
mouse.pos.z=mouse.prescale.z*mouse.scale.z*ip_grid.z_speed;
i=Trunc(ipx_scale*mxx/ip_grid.x)*ip_grid.x+ipx_offset; //TODO ip_grid.x_offset?
i=Trunc(ip.scale.x*mouse.pos.x/ip_grid.x)*ip_grid.x+ip.offset.x; //TODO ip_grid.x_offset?
if (i<0)
ipx_offset-=i;
else if (i>=gr_width)
ipx_offset+=gr_width-1-i;
ip.offset.x-=i;
else if (i>=GR_WIDTH)
ip.offset.x+=GR_WIDTH-1-i;
i=Trunc(ipy_scale*myy/ip_grid.y)*ip_grid.y+ipy_offset;
i=Trunc(ip.scale.y*mouse.pos.y/ip_grid.y)*ip_grid.y+ip.offset.y;
if (i<0)
ipy_offset-=i;
else if (i>=gr_height)
ipy_offset+=gr_height-1-i;
ip.offset.y-=i;
else if (i>=GR_HEIGHT)
ip.offset.y+=GR_HEIGHT-1-i;
if (mxx!=old_mxx||myy!=old_myy||mzz!=old_mzz) {
mouse_evt=TRUE;
if (mouse.pos.x!=mouse_last.pos.x || mouse.pos.y!=mouse_last.pos.y || mouse.pos.z!=mouse_last.pos.z) {
mouse.evt=TRUE;
SetMouseSpeed;
} else
for (i=0;i<5;i++)
if (mouse_buttons[i]!=old_buttons[i]) {
mouse_evt=TRUE;
if (mouse.buttons[i]!=mouse_last.buttons[i]) {
mouse.evt=TRUE;
break;
}
}
@@ -179,21 +177,19 @@ U0 MouseHandler()
{
I64 i,dx,dy,dz;
U8 mouse_buf[4];
Bool old_buttons[5];
MouseUpdatePre(old_buttons);
MouseUpdatePre;
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]))
for (i=0;i<mouse.pkt_size;i++)
if (!FifoU8Rem(mouse.fifo2,&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;
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
@@ -207,35 +203,33 @@ U0 MouseHandler()
else
dz=mouse_buf[3]&7;
mxx_prescale+=dx;
myy_prescale+=dy;
mzz_prescale+=dz;
mouse.prescale.x+=dx;
mouse.prescale.y+=dy;
mouse.prescale.z+=dz;
MouseUpdatePost(old_buttons);
MouseUpdatePost;
}
U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r,I64 c)
U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r)
{
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);
mouse.timestamp=GetTSC;
MouseUpdatePre;
mouse.prescale.x=x/mouse.scale.x/ip_grid.x_speed;
mouse.prescale.y=y/mouse.scale.y/ip_grid.y_speed;
mouse.prescale.z=z/mouse.scale.z/ip_grid.z_speed;
mouse.buttons[0]=l;
mouse.buttons[1]=r;
MouseUpdatePost;
}
U0 KbdMouseRst()
{
KbdCmdFlush;
FifoU8Flush(kbd2_fifo);
FifoU8Flush(mouse2_fifo);
FifoI64Flush(scan_code_fifo);
sys_cur_scan_code=0;
kbdmouse_rst=FALSE;
FifoU8Flush(kbd.fifo2);
FifoU8Flush(mouse.fifo2);
FifoI64Flush(kbd.scan_code_fifo);
kbd.scan_code=0;
kbd.rst=FALSE;
}
Bool MouseDriverInstall(I64 dummy=0) //can be spawned
@@ -244,34 +238,34 @@ Bool MouseDriverInstall(I64 dummy=0) //can be spawned
I64 i;
Bool old_preempt=IsPreempt;
Preempt(ON);
mouse_install_attempt_in_progress=TRUE;
mouse.install_in_progress=TRUE;
OutU8(0xA1,InU8(0xA1)|0x10);
mouse_installed=mouse_irqs_working=FALSE;
mouse.installed=mouse.irqs_working=FALSE;
IntEntrySet(0x2C,&MouseIntHandler);
for(i=0;i<5;i++)
mouse_buttons[i]=0;
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;
mouse.install_attempts++;
mouse.installed=mouse.evt=i;
mouse.install_in_progress=FALSE;
Preempt(old_preempt);
return mouse_installed;
return mouse.installed;
}
U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
{
if (mouse_install_attempt_in_progress) {
if (mouse.install_in_progress) {
Yield;
return;
}
if (kbdmouse_rst)
if (kbd.rst)
KbdMouseRst;
else {
if (poll_mouse &&
mouse_installed &&
!mouse_irqs_working) {
mouse.installed &&
!mouse.irqs_working) {
PUSHFD
CLI
while (InU8(KBD_CTRL)&1)
@@ -283,13 +277,13 @@ U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
while (InU8(KBD_CTRL)&1)
KbdPktRead;
if (kbdmouse_rst)
if (kbd.rst)
KbdMouseRst;
else {
while (FifoU8Cnt(kbd2_fifo))
while (FifoU8Cnt(kbd.fifo2))
KbdHandler;
while (FifoU8Cnt(mouse2_fifo))
if (mouse_installed)
while (FifoU8Cnt(mouse.fifo2))
if (mouse.installed)
MouseHandler;
else
KbdMouseRst;
@@ -299,36 +293,21 @@ U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
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;
MemSet(&kbd,0,sizeof(CKbdStateGlbls));
kbd.fifo=FifoU8New(8);
kbd.fifo2=FifoU8New(64);
kbd.scan_code_fifo=FifoI64New(128);
kbd.irqs_working=FALSE;
MemSet(&mouse,0,sizeof(CMouseStateGlbls));
mouse.fifo=FifoU8New(8);
mouse.fifo2=FifoU8New(64);
mouse.scale.x=0.5;
mouse.scale.y=0.5;
mouse.scale.z=1.0;
mouse.prescale.x=GR_WIDTH/mouse.scale.x/2.0;
mouse.prescale.y=GR_HEIGHT/mouse.scale.y/2.0;
mouse.prescale.z=0/mouse.scale.z;
mouse.pos.x=GR_WIDTH>>1;
mouse.pos.y=GR_HEIGHT>>1;
MemCpy(&mouse_last,&mouse,sizeof(CMouseStateGlbls));
}