<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=US-ASCII"> <meta name="generator" content="ZealOS V1.01"> <style type="text/css"> body {background-color:#fef1f0;} .cF0{color:#000000;background-color:#fef1f0;} .cF1{color:#0148a4;background-color:#fef1f0;} .cF2{color:#3b7901;background-color:#fef1f0;} .cF3{color:#057c7e;background-color:#fef1f0;} .cF4{color:#bb2020;background-color:#fef1f0;} .cF5{color:#9e42ae;background-color:#fef1f0;} .cF6{color:#b57901;background-color:#fef1f0;} .cF7{color:#b2b6af;background-color:#fef1f0;} .cF8{color:#555753;background-color:#fef1f0;} .cF9{color:#678fbb;background-color:#fef1f0;} .cFA{color:#82bc49;background-color:#fef1f0;} .cFB{color:#0097a2;background-color:#fef1f0;} .cFC{color:#e26a6a;background-color:#fef1f0;} .cFD{color:#c671bc;background-color:#fef1f0;} .cFE{color:#c7ab00;background-color:#fef1f0;} .cFF{color:#fef1f0;background-color:#fef1f0;} </style> </head> <body> <pre style="font-family:monospace;font-size:12pt"> <a name="l1"></a><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>GridInit</span><span class=cF0>() <a name="l2"></a>{</span><span class=cF2>//Init mouse grid struct. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/Graphics/Grid.CC.html#l1"><span class=cF4>::/Demo/Graphics/Grid.CC</span></a><span class=cF2>.</span><span class=cF0> <a name="l3"></a> </span><span class=cFB>mouse_grid</span><span class=cF0>.x = </span><span class=cFB>mouse_grid</span><span class=cF0>.y = </span><span class=cFB>mouse_grid</span><span class=cF0>.z = </span><span class=cFE>8</span><span class=cF0>; <a name="l4"></a> </span><span class=cFB>mouse_grid</span><span class=cF0>.x_offset = </span><span class=cFB>mouse_grid</span><span class=cF0>.y_offset = </span><span class=cFB>mouse_grid</span><span class=cF0>.z_offset = </span><span class=cFE>0</span><span class=cF0>; <a name="l5"></a> </span><span class=cFB>mouse_grid</span><span class=cF0>.x_speed = </span><span class=cFB>mouse_grid</span><span class=cF0>.y_speed = </span><span class=cFB>mouse_grid</span><span class=cF0>.z_speed = </span><span class=cFE>1</span><span class=cF0>; <a name="l6"></a> </span><span class=cFB>mouse_grid</span><span class=cF0>.show = </span><span class=cFB>mouse_grid</span><span class=cF0>.snap = </span><span class=cFB>mouse_grid</span><span class=cF0>.coord = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l7"></a>} <a name="l8"></a> <a name="l9"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MouseUpdate</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF9>I64</span><span class=cF0> z, </span><span class=cF1>Bool</span><span class=cF0> l, </span><span class=cF1>Bool</span><span class=cF0> r) <a name="l10"></a>{ <a name="l11"></a> </span><span class=cFB>mouse</span><span class=cF0>.presnap.x = </span><span class=cF5>ToI64</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.scale.x * x) + </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x; <a name="l12"></a> </span><span class=cFB>mouse</span><span class=cF0>.presnap.y = </span><span class=cF5>ToI64</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.scale.y * y) + </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y; <a name="l13"></a> </span><span class=cFB>mouse</span><span class=cF0>.presnap.z = </span><span class=cF5>ToI64</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.scale.z * z) + </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.z; <a name="l14"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_grid</span><span class=cF0>.snap) <a name="l15"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l16"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.x = </span><span class=cF5>Trunc</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.presnap.x / </span><span class=cFB>mouse_grid</span><span class=cF0>.x) * </span><span class=cFB>mouse_grid</span><span class=cF0>.x + </span><span class=cFB>mouse_grid</span><span class=cF0>.x_offset; <a name="l17"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.y = </span><span class=cF5>Trunc</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.presnap.y / </span><span class=cFB>mouse_grid</span><span class=cF0>.y) * </span><span class=cFB>mouse_grid</span><span class=cF0>.y + </span><span class=cFB>mouse_grid</span><span class=cF0>.y_offset; <a name="l18"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.z = </span><span class=cF5>Trunc</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.presnap.z / </span><span class=cFB>mouse_grid</span><span class=cF0>.z) * </span><span class=cFB>mouse_grid</span><span class=cF0>.z + </span><span class=cFB>mouse_grid</span><span class=cF0>.z_offset; <a name="l19"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l20"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l21"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l22"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.x = </span><span class=cFB>mouse</span><span class=cF0>.presnap.x; <a name="l23"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.y = </span><span class=cFB>mouse</span><span class=cF0>.presnap.y; <a name="l24"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.z = </span><span class=cFB>mouse</span><span class=cF0>.presnap.z; <a name="l25"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l26"></a> <a name="l27"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.x = </span><span class=cF5>ClampI64</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.pos.x, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width - </span><span class=cFE>1</span><span class=cF0>); <a name="l28"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.y = </span><span class=cF5>ClampI64</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.pos.y, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height - </span><span class=cFE>1</span><span class=cF0>); <a name="l29"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos_text.x = </span><span class=cFB>mouse</span><span class=cF0>.pos.x / </span><span class=cF3>FONT_WIDTH</span><span class=cF0>; <a name="l30"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse</span><span class=cF0>.pos_text.x >= </span><span class=cFB>text</span><span class=cF0>.cols) <a name="l31"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l32"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos_text.x = </span><span class=cFB>text</span><span class=cF0>.cols - </span><span class=cFE>1</span><span class=cF0>; <a name="l33"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.x = </span><span class=cFB>text</span><span class=cF0>.cols * </span><span class=cF3>FONT_WIDTH</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>; <a name="l34"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l35"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos_text.y = </span><span class=cFB>mouse</span><span class=cF0>.pos.y / </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>; <a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse</span><span class=cF0>.pos_text.y >= </span><span class=cFB>text</span><span class=cF0>.rows) <a name="l37"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l38"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos_text.y = </span><span class=cFB>text</span><span class=cF0>.rows - </span><span class=cFE>1</span><span class=cF0>; <a name="l39"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos.y = </span><span class=cFB>text</span><span class=cF0>.rows * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>; <a name="l40"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l41"></a> </span><span class=cFB>mouse</span><span class=cF0>.lb = l; <a name="l42"></a> </span><span class=cFB>mouse</span><span class=cF0>.rb = r; <a name="l43"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&</span><span class=cFB>kbd</span><span class=cF0>.scan_code, </span><span class=cF3>SCf_MS_L_DOWN</span><span class=cF0>, </span><span class=cFB>mouse</span><span class=cF0>.lb); <a name="l44"></a> </span><span class=cF5>LBEqual</span><span class=cF0>(&</span><span class=cFB>kbd</span><span class=cF0>.scan_code, </span><span class=cF3>SCf_MS_R_DOWN</span><span class=cF0>, </span><span class=cFB>mouse</span><span class=cF0>.rb); <a name="l45"></a>} <a name="l46"></a> <a name="l47"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MouseSet</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> x=</span><span class=cF3>I64_MAX</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> y=</span><span class=cF3>I64_MAX</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> z=</span><span class=cF3>I64_MAX</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> l=</span><span class=cF3>I64_MAX</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> r=</span><span class=cF3>I64_MAX</span><span class=cF0>) <a name="l48"></a>{</span><span class=cF2>//Note: Generates a message. See </span><a href="https://zeal-operating-system.github.io/ZealOS/Demo/Games/Zing.CC.html#l94"><span class=cF4>MouseSet</span></a><span class=cF2>().</span><span class=cF0> <a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cFE>0</span><span class=cF0> <= x < </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width</span><span class=cF7>)</span><span class=cF0>) <a name="l50"></a> x = </span><span class=cFB>mouse</span><span class=cF0>.pos.x; <a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cFE>0</span><span class=cF0> <= y < </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height</span><span class=cF7>)</span><span class=cF0>) <a name="l52"></a> y = </span><span class=cFB>mouse</span><span class=cF0>.pos.y; <a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (z == </span><span class=cF3>I64_MAX</span><span class=cF0>) <a name="l54"></a> z = </span><span class=cFB>mouse</span><span class=cF0>.pos.z; <a name="l55"></a> <a name="l56"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF3>FALSE</span><span class=cF0> <= l <= </span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>) <a name="l57"></a> l = </span><span class=cFB>mouse</span><span class=cF0>.lb; <a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF3>FALSE</span><span class=cF0> <= r <= </span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>) <a name="l59"></a> r = </span><span class=cFB>mouse</span><span class=cF0>.rb; <a name="l60"></a> <a name="l61"></a> x = (x - </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x) / </span><span class=cFB>mouse</span><span class=cF0>.scale.x; <a name="l62"></a> y = (y - </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y) / </span><span class=cFB>mouse</span><span class=cF0>.scale.y; <a name="l63"></a> z = (z - </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.z) / </span><span class=cFB>mouse</span><span class=cF0>.scale.z; <a name="l64"></a> </span><span class=cF5>MouseUpdate</span><span class=cF0>(x, y, z, l, r); <a name="l65"></a> </span><span class=cFD>MouseHardSet</span><span class=cF0>(x, y, z, l, r); <a name="l66"></a>} <a name="l67"></a> <a name="l68"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>MouseInit</span><span class=cF0>() <a name="l69"></a>{ <a name="l70"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&</span><span class=cFB>mouse</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMouseStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l71"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&</span><span class=cFB>mouse_last</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMouseStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l72"></a> </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x = </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y = </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.z = </span><span class=cFE>0</span><span class=cF0>; <a name="l73"></a> </span><span class=cFB>mouse</span><span class=cF0>.scale.x = </span><span class=cFB>mouse</span><span class=cF0>.scale.y = </span><span class=cFB>mouse</span><span class=cF0>.scale.z = </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>; <a name="l74"></a> </span><span class=cFB>mouse</span><span class=cF0>.pos_text.x = </span><span class=cFB>mouse</span><span class=cF0>.pos_text.y = </span><span class=cFB>mouse</span><span class=cF0>.pos_text.z = </span><span class=cFE>0</span><span class=cF0>; <a name="l75"></a> </span><span class=cFB>mouse</span><span class=cF0>.has_wheel = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l76"></a> </span><span class=cFB>mouse</span><span class=cF0>.show = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l77"></a> </span><span class=cFB>mouse</span><span class=cF0>.speed = </span><span class=cFE>0</span><span class=cF0>; <a name="l78"></a> </span><span class=cFB>mouse</span><span class=cF0>.timestamp = </span><span class=cF5>TSCGet</span><span class=cF0>; <a name="l79"></a> </span><span class=cFB>mouse</span><span class=cF0>.dbl_time = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>175</span><span class=cF0>; <a name="l80"></a> </span><span class=cF5>GridInit</span><span class=cF0>; <a name="l81"></a>} <a name="l82"></a> <a name="l83"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardPacketRead</span><span class=cF0>() <a name="l84"></a>{ <a name="l85"></a> </span><span class=cF1>U8</span><span class=cF0> j; <a name="l86"></a> <a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>TSCGet</span><span class=cF0> > </span><span class=cFB>mouse_hard</span><span class=cF0>.timestamp + </span><span class=cFB>counts</span><span class=cF0>.time_stamp_freq >> </span><span class=cFE>3</span><span class=cF0>) <a name="l88"></a> </span><span class=cF5>FifoU8Flush</span><span class=cF0>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo); <a name="l89"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.timestamp = </span><span class=cF5>TSCGet</span><span class=cF0>; <a name="l90"></a> </span><span class=cF5>FifoU8Insert</span><span class=cF0>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo, </span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF3>KBD_PORT</span><span class=cF7>)</span><span class=cF0>); <a name="l91"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FifoU8Count</span><span class=cF7>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFB>mouse_hard</span><span class=cF0>.pkt_size) <a name="l92"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>FifoU8Remove</span><span class=cF7>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo, &j</span><span class=cF7>)</span><span class=cF0>) <a name="l93"></a> </span><span class=cF5>FifoU8Insert</span><span class=cF0>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo2, j); <a name="l94"></a>} <a name="l95"></a> <a name="l96"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>IRQMouseHard</span><span class=cF0>() <a name="l97"></a>{ <a name="l98"></a> </span><span class=cF1>CLD</span><span class=cF0> <a name="l99"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2</span><span class=cF0>, </span><span class=cF3>PIC_EOI</span><span class=cF0>); <a name="l100"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_1</span><span class=cF0>, </span><span class=cF3>PIC_EOI</span><span class=cF0>); <a name="l101"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.irqs_working = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.install_in_progress || !</span><span class=cFB>mouse_hard</span><span class=cF0>.installed) <a name="l103"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l104"></a> </span><span class=cFB>kbd</span><span class=cF0>.reset = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l105"></a> </span><span class=cF1>return</span><span class=cF0>; <a name="l106"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l107"></a> </span><span class=cFD>MouseHardPacketRead</span><span class=cF0>; <a name="l108"></a>} <a name="l109"></a> <a name="l110"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardGetType</span><span class=cF0>() <a name="l111"></a>{ <a name="l112"></a> </span><span class=cF9>I64</span><span class=cF0> b; <a name="l113"></a> <a name="l114"></a> </span><span class=cFD>KbdMouseCmdAck</span><span class=cF0>(</span><span class=cFE>0xF2</span><span class=cF0>); <a name="l115"></a> b = </span><span class=cFD>KbdCmdRead</span><span class=cF0>; <a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (b == </span><span class=cFE>3</span><span class=cF0>) <a name="l117"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.has_wheel = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l118"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (b == </span><span class=cFE>4</span><span class=cF0>) <a name="l119"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.has_ext_bttns = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l120"></a>} <a name="l121"></a> <a name="l122"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>MouseHardReset</span><span class=cF0>() <a name="l123"></a>{ <a name="l124"></a> </span><span class=cF1>U8</span><span class=cF0> b, *_b; <a name="l125"></a> </span><span class=cF1>F64</span><span class=cF0> timeout; <a name="l126"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l127"></a> <a name="l128"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.has_wheel = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l129"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.has_ext_bttns = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l130"></a> <a name="l131"></a> </span><span class=cF1>if</span><span class=cF0> (*</span><span class=cFE>0x40E</span><span class=cF7>(</span><span class=cF9>U16</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0x9FC0</span><span class=cF0>) <a name="l132"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l133"></a> _b = </span><span class=cFE>0x9FC00</span><span class=cF0>+</span><span class=cFE>0x30</span><span class=cF0>; <a name="l134"></a> *_b = </span><span class=cFE>1</span><span class=cF0>; </span><span class=cF2>//This enables Terry's mouse. It might be for one machine.</span><span class=cF0> <a name="l135"></a></span><span class=cF2>//USB DMA packets, set-up by BIOS to make legacy PS/2?</span><span class=cF0> <a name="l136"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l137"></a> <a name="l138"></a> </span><span class=cF1>try</span><span class=cF0> <a name="l139"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l140"></a> </span><span class=cFD>KbdCmdFlush</span><span class=cF0>; <a name="l141"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0xAD</span><span class=cF0>); </span><span class=cF2>//Disable Kbd</span><span class=cF0> <a name="l142"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0xA8</span><span class=cF0>); </span><span class=cF2>//Enable Mouse</span><span class=cF0> <a name="l143"></a> <a name="l144"></a> </span><span class=cFD>KbdMouseCmdAck</span><span class=cF0>(</span><span class=cFE>0xFF</span><span class=cF0>); </span><span class=cF2>//Reset</span><span class=cF0> <a name="l145"></a> <a name="l146"></a> timeout = </span><span class=cF5>tS</span><span class=cF0> + </span><span class=cFE>10</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>; <a name="l147"></a> </span><span class=cF1>do</span><span class=cF0> <a name="l148"></a> </span><span class=cF1>try</span><span class=cF0> <a name="l149"></a> { <a name="l150"></a> </span><span class=cFD>KbdCmdRead</span><span class=cF0>; <a name="l151"></a> timeout = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>//force exit</span><span class=cF0> <a name="l152"></a> } <a name="l153"></a> </span><span class=cF1>catch</span><span class=cF0> <a name="l154"></a> </span><span class=cF5>Fs</span><span class=cF0>->catch_except = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l155"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>tS</span><span class=cF0> < timeout); <a name="l156"></a> <a name="l157"></a> </span><span class=cF1>try</span><span class=cF0> <a name="l158"></a> </span><span class=cFD>KbdCmdRead</span><span class=cF0>; <a name="l159"></a> </span><span class=cF1>catch</span><span class=cF0> <a name="l160"></a> </span><span class=cF5>Fs</span><span class=cF0>->catch_except = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l161"></a> <a name="l162"></a> </span><span class=cFD>KbdMouseCmdAck</span><span class=cF0>(</span><span class=cFE>0xF3</span><span class=cF0>, </span><span class=cFE>200</span><span class=cF0>, </span><span class=cFE>0xF3</span><span class=cF0>, </span><span class=cFE>100</span><span class=cF0>, </span><span class=cFE>0xF3</span><span class=cF0>, </span><span class=cFE>80</span><span class=cF0>); <a name="l163"></a> </span><span class=cFD>MouseHardGetType</span><span class=cF0>; <a name="l164"></a> </span><span class=cFD>KbdMouseCmdAck</span><span class=cF0>(</span><span class=cFE>0xF3</span><span class=cF0>, </span><span class=cFE>10</span><span class=cF0>); <a name="l165"></a> </span><span class=cFD>MouseHardGetType</span><span class=cF0>; <a name="l166"></a> </span><span class=cFD>KbdMouseCmdAck</span><span class=cF0>(</span><span class=cFE>0xE8</span><span class=cF0>, </span><span class=cFE>0x03</span><span class=cF0>, </span><span class=cFE>0xE6</span><span class=cF0>, </span><span class=cFE>0xF3</span><span class=cF0>, </span><span class=cFE>100</span><span class=cF0>, </span><span class=cFE>0xF4</span><span class=cF0>); <a name="l167"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l168"></a> <a name="l169"></a> </span><span class=cF2>//Enable IRQ 12</span><span class=cF0> <a name="l170"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0x20</span><span class=cF0>); <a name="l171"></a> b = </span><span class=cFD>KbdCmdRead</span><span class=cF0>; <a name="l172"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0x60</span><span class=cF0>); <a name="l173"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_PORT</span><span class=cF0>, </span><span class=cF7>(</span><span class=cF0>b | </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0> & ~</span><span class=cFE>0x20</span><span class=cF0>); <a name="l174"></a> <a name="l175"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l176"></a> </span><span class=cF1>catch</span><span class=cF0> <a name="l177"></a> </span><span class=cF5>Fs</span><span class=cF0>->catch_except = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l178"></a> <a name="l179"></a> </span><span class=cF2>//This is been added to override failure</span><span class=cF0> <a name="l180"></a> </span><span class=cF2>//because the mouse sometimes still works.</span><span class=cF0> <a name="l181"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l182"></a> <a name="l183"></a> </span><span class=cF1>try</span><span class=cF0> <a name="l184"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0xAE</span><span class=cF0>); </span><span class=cF2>//Enable Keyboard</span><span class=cF0> <a name="l185"></a> </span><span class=cF1>catch</span><span class=cF0> <a name="l186"></a> </span><span class=cF5>Fs</span><span class=cF0>->catch_except = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.has_wheel || </span><span class=cFB>mouse_hard</span><span class=cF0>.has_ext_bttns) <a name="l188"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pkt_size = </span><span class=cFE>4</span><span class=cF0>; <a name="l189"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l190"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pkt_size = </span><span class=cFE>3</span><span class=cF0>; <a name="l191"></a> </span><span class=cF1>if</span><span class=cF0> (!res) <a name="l192"></a> </span><span class=cF1>try</span><span class=cF0> <a name="l193"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cFE>0xA7</span><span class=cF0>); </span><span class=cF2>//Disable Mouse</span><span class=cF0> <a name="l194"></a> </span><span class=cF1>catch</span><span class=cF0> <a name="l195"></a> </span><span class=cF5>Fs</span><span class=cF0>->catch_except = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l196"></a> <a name="l197"></a> </span><span class=cF1>return</span><span class=cF0> res; <a name="l198"></a>} <a name="l199"></a> <a name="l200"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardSpeedSet</span><span class=cF0>() <a name="l201"></a>{ <a name="l202"></a> </span><span class=cF9>I64</span><span class=cF0> dd, tmp; <a name="l203"></a> <a name="l204"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>dd = </span><span class=cF5>SqrI64</span><span class=cF0>(</span><span class=cFB>mouse_hard_last</span><span class=cF0>.pos.x - </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.x) + </span><span class=cF5>SqrI64</span><span class=cF0>(</span><span class=cFB>mouse_hard_last</span><span class=cF0>.pos.y - </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.y)</span><span class=cF7>)</span><span class=cF0> && <a name="l205"></a> </span><span class=cF7>(</span><span class=cF0>tmp = </span><span class=cFB>mouse_hard</span><span class=cF0>.timestamp - </span><span class=cFB>mouse_hard_last</span><span class=cF0>.timestamp</span><span class=cF7>)</span><span class=cF0>) <a name="l206"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.speed = </span><span class=cF5>Sqrt</span><span class=cF0>(dd) * </span><span class=cFB>counts</span><span class=cF0>.time_stamp_freq / tmp; <a name="l207"></a> </span><span class=cFB>mouse_hard_last</span><span class=cF0>.timestamp = </span><span class=cFB>mouse_hard</span><span class=cF0>.timestamp; <a name="l208"></a>} <a name="l209"></a> <a name="l210"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardSetPre</span><span class=cF0>() <a name="l211"></a>{ <a name="l212"></a> </span><span class=cF9>I64</span><span class=cF0> old_timestamp = </span><span class=cFB>mouse_hard_last</span><span class=cF0>.timestamp; <a name="l213"></a> <a name="l214"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&</span><span class=cFB>mouse_hard_last</span><span class=cF0>, &</span><span class=cFB>mouse_hard</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMouseHardStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l215"></a> </span><span class=cFB>mouse_hard_last</span><span class=cF0>.timestamp = old_timestamp; <a name="l216"></a>} <a name="l217"></a> <a name="l218"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardSetPost</span><span class=cF0>() <a name="l219"></a>{ <a name="l220"></a> </span><span class=cF9>I64</span><span class=cF0> i; <a name="l221"></a> <a name="l222"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.x = </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.x * </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.x * </span><span class=cFB>mouse_grid</span><span class=cF0>.x_speed; <a name="l223"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.y = </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.y * </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.y * </span><span class=cFB>mouse_grid</span><span class=cF0>.y_speed; <a name="l224"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.z = </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.z * </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.z * </span><span class=cFB>mouse_grid</span><span class=cF0>.z_speed; <a name="l225"></a> <a name="l226"></a> i = </span><span class=cF5>Trunc</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.scale.x * </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.x / </span><span class=cFB>mouse_grid</span><span class=cF0>.x) * </span><span class=cFB>mouse_grid</span><span class=cF0>.x + </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x; <a name="l227"></a></span><span class=cF2>//TODO mouse_grid.x_offset?</span><span class=cF0> <a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (i < </span><span class=cFE>0</span><span class=cF0>) <a name="l229"></a> </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x -= i; <a name="l230"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (i >= </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width) <a name="l231"></a> </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.x += </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width - </span><span class=cFE>1</span><span class=cF0> - i; <a name="l232"></a> <a name="l233"></a> i = </span><span class=cF5>Trunc</span><span class=cF0>(</span><span class=cFB>mouse</span><span class=cF0>.scale.y * </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.y / </span><span class=cFB>mouse_grid</span><span class=cF0>.y) * </span><span class=cFB>mouse_grid</span><span class=cF0>.y + </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y; <a name="l234"></a> </span><span class=cF1>if</span><span class=cF0> (i < </span><span class=cFE>0</span><span class=cF0>) <a name="l235"></a> </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y -= i; <a name="l236"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (i >= </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height) <a name="l237"></a> </span><span class=cFB>mouse</span><span class=cF0>.</span><span class=cF1>offset</span><span class=cF0>.y += </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height - </span><span class=cFE>1</span><span class=cF0> - i; <a name="l238"></a> <a name="l239"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.pos.x != </span><span class=cFB>mouse_hard_last</span><span class=cF0>.pos.x || </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.y != </span><span class=cFB>mouse_hard_last</span><span class=cF0>.pos.y || <a name="l240"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.z != </span><span class=cFB>mouse_hard_last</span><span class=cF0>.pos.z) <a name="l241"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l242"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.event = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l243"></a> </span><span class=cFD>MouseHardSpeedSet</span><span class=cF0>; <a name="l244"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l245"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l246"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>5</span><span class=cF0>; i++) <a name="l247"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[i] != </span><span class=cFB>mouse_hard_last</span><span class=cF0>.bttns[i]) <a name="l248"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l249"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.event = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l250"></a> </span><span class=cF1>break</span><span class=cF0>; <a name="l251"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l252"></a>} <a name="l253"></a> <a name="l254"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardHandler</span><span class=cF0>() <a name="l255"></a>{ <a name="l256"></a> </span><span class=cF9>I64</span><span class=cF0> i, dx, dy, dz; <a name="l257"></a> </span><span class=cF1>U8</span><span class=cF0> mouse_buf[</span><span class=cFE>4</span><span class=cF0>]; <a name="l258"></a> <a name="l259"></a> </span><span class=cFD>MouseHardSetPre</span><span class=cF0>; <a name="l260"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>4</span><span class=cF0>; i++) <a name="l261"></a> mouse_buf[i] = </span><span class=cFE>0</span><span class=cF0>; <a name="l262"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFB>mouse_hard</span><span class=cF0>.pkt_size; i++) <a name="l263"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FifoU8Remove</span><span class=cF7>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo2, &mouse_buf[i]</span><span class=cF7>)</span><span class=cF0>) <a name="l264"></a> mouse_buf[i] = </span><span class=cFE>0</span><span class=cF0>; <a name="l265"></a> <a name="l266"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>0</span><span class=cF0>] = mouse_buf[</span><span class=cFE>0</span><span class=cF0>] & </span><span class=cFE>1</span><span class=cF0>; <a name="l267"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>1</span><span class=cF0>] = (mouse_buf[</span><span class=cFE>0</span><span class=cF0>] & </span><span class=cFE>2</span><span class=cF0>) >> </span><span class=cFE>1</span><span class=cF0>; <a name="l268"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>2</span><span class=cF0>] = (mouse_buf[</span><span class=cFE>0</span><span class=cF0>] & </span><span class=cFE>4</span><span class=cF0>) >> </span><span class=cFE>2</span><span class=cF0>; <a name="l269"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>3</span><span class=cF0>] = (mouse_buf[</span><span class=cFE>3</span><span class=cF0>] & </span><span class=cFE>0x10</span><span class=cF0>) >> </span><span class=cFE>4</span><span class=cF0>; <a name="l270"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>4</span><span class=cF0>] = (mouse_buf[</span><span class=cFE>3</span><span class=cF0>] & </span><span class=cFE>0x20</span><span class=cF0>) >> </span><span class=cFE>5</span><span class=cF0>; <a name="l271"></a> </span><span class=cF1>if</span><span class=cF0> (mouse_buf[</span><span class=cFE>0</span><span class=cF0>] & </span><span class=cFE>0x10</span><span class=cF0>) <a name="l272"></a> dx = mouse_buf[</span><span class=cFE>1</span><span class=cF0>]-</span><span class=cFE>256</span><span class=cF0>; <a name="l273"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l274"></a> dx = mouse_buf[</span><span class=cFE>1</span><span class=cF0>]; <a name="l275"></a> </span><span class=cF1>if</span><span class=cF0> (mouse_buf[</span><span class=cFE>0</span><span class=cF0>] & </span><span class=cFE>0x20</span><span class=cF0>) <a name="l276"></a> dy = </span><span class=cFE>256</span><span class=cF0> - mouse_buf[</span><span class=cFE>2</span><span class=cF0>]; <a name="l277"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l278"></a> dy = -mouse_buf[</span><span class=cFE>2</span><span class=cF0>]; <a name="l279"></a> </span><span class=cF1>if</span><span class=cF0> (mouse_buf[</span><span class=cFE>3</span><span class=cF0>] & </span><span class=cFE>0x08</span><span class=cF0>) <a name="l280"></a> dz = mouse_buf[</span><span class=cFE>3</span><span class=cF0>] & </span><span class=cFE>7</span><span class=cF0> - </span><span class=cFE>8</span><span class=cF0>; <a name="l281"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l282"></a> dz = mouse_buf[</span><span class=cFE>3</span><span class=cF0>] & </span><span class=cFE>7</span><span class=cF0>; <a name="l283"></a> <a name="l284"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.x += dx; <a name="l285"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.y += dy; <a name="l286"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.z += dz; <a name="l287"></a> <a name="l288"></a> </span><span class=cFD>MouseHardSetPost</span><span class=cF0>; <a name="l289"></a>} <a name="l290"></a> <a name="l291"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>MouseHardSet</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y, </span><span class=cF9>I64</span><span class=cF0> z, </span><span class=cF9>I64</span><span class=cF0> l, </span><span class=cF9>I64</span><span class=cF0> r) <a name="l292"></a>{ <a name="l293"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.timestamp = </span><span class=cF5>TSCGet</span><span class=cF0>; <a name="l294"></a> </span><span class=cFD>MouseHardSetPre</span><span class=cF0>; <a name="l295"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.x = x / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.x / </span><span class=cFB>mouse_grid</span><span class=cF0>.x_speed; <a name="l296"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.y = y / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.y / </span><span class=cFB>mouse_grid</span><span class=cF0>.y_speed; <a name="l297"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.z = z / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.z / </span><span class=cFB>mouse_grid</span><span class=cF0>.z_speed; <a name="l298"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>0</span><span class=cF0>] = l; <a name="l299"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[</span><span class=cFE>1</span><span class=cF0>] = r; <a name="l300"></a> </span><span class=cFD>MouseHardSetPost</span><span class=cF0>; <a name="l301"></a>} <a name="l302"></a> <a name="l303"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>KbdMouseReset</span><span class=cF0>() <a name="l304"></a>{ <a name="l305"></a> </span><span class=cFD>KbdCmdFlush</span><span class=cF0>; <a name="l306"></a> </span><span class=cF5>FifoU8Flush</span><span class=cF0>(</span><span class=cFB>kbd</span><span class=cF0>.fifo2); <a name="l307"></a> </span><span class=cF5>FifoU8Flush</span><span class=cF0>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo2); <a name="l308"></a> </span><span class=cF5>FifoI64Flush</span><span class=cF0>(</span><span class=cFB>kbd</span><span class=cF0>.scan_code_fifo); <a name="l309"></a> </span><span class=cFB>kbd</span><span class=cF0>.scan_code = </span><span class=cFE>0</span><span class=cF0>; <a name="l310"></a> </span><span class=cFB>kbd</span><span class=cF0>.reset = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l311"></a>} <a name="l312"></a> <a name="l313"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>MouseHardEnable</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val=</span><span class=cF3>TRUE</span><span class=cF0>) <a name="l314"></a>{ <a name="l315"></a> </span><span class=cF1>Bool</span><span class=cF0> old_val = </span><span class=cFB>mouse_hard</span><span class=cF0>.enabled; <a name="l316"></a> <a name="l317"></a> </span><span class=cF1>if</span><span class=cF0> (val) <a name="l318"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l319"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cF3>KBDC_ENABLE_MS</span><span class=cF0>); <a name="l320"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.enabled = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l321"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l322"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l323"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l324"></a> </span><span class=cFD>KbdCmdSend</span><span class=cF0>(</span><span class=cF3>KBD_CTRL</span><span class=cF0>, </span><span class=cF3>KBDC_DISABLE_MS</span><span class=cF0>); <a name="l325"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.enabled = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l326"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l327"></a> </span><span class=cF1>return</span><span class=cF0> old_val; <a name="l328"></a>} <a name="l329"></a> <a name="l330"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>MouseHardDriverInstall</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> dummy=</span><span class=cFE>0</span><span class=cF0>) </span><span class=cF2>//can be spawned</span><span class=cF0> <a name="l331"></a>{ <a name="l332"></a> </span><span class=cF1>no_warn</span><span class=cF0> dummy; <a name="l333"></a> </span><span class=cF9>I64</span><span class=cF0> i; <a name="l334"></a> <a name="l335"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.install_in_progress = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l336"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF3>PIC_2_DATA</span><span class=cF7>)</span><span class=cF0> | </span><span class=cFE>0x10</span><span class=cF0>); <a name="l337"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.installed = </span><span class=cFB>mouse_hard</span><span class=cF0>.irqs_working = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l338"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(</span><span class=cFE>0x2C</span><span class=cF0>, &</span><span class=cFD>IRQMouseHard</span><span class=cF0>); <a name="l339"></a> </span><span class=cF1>for</span><span class=cF0>(i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cFE>5</span><span class=cF0>; i++) <a name="l340"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.bttns[i] = </span><span class=cFE>0</span><span class=cF0>; <a name="l341"></a> </span><span class=cF1>if</span><span class=cF0> (i = </span><span class=cFD>MouseHardReset</span><span class=cF0>) <a name="l342"></a> </span><span class=cF5>OutU8</span><span class=cF0>(</span><span class=cF3>PIC_2_DATA</span><span class=cF0>, </span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF3>PIC_2_DATA</span><span class=cF7>)</span><span class=cF0> & ~</span><span class=cFE>0x10</span><span class=cF0>); <a name="l343"></a> </span><span class=cFD>KbdMouseReset</span><span class=cF0>; <a name="l344"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.install_attempts++; <a name="l345"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.installed = </span><span class=cFB>mouse_hard</span><span class=cF0>.event=i; <a name="l346"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.install_in_progress = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l347"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFB>mouse_hard</span><span class=cF0>.installed; <a name="l348"></a>} <a name="l349"></a> <a name="l350"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>KbdMouseHandler</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> poll_kbd, </span><span class=cF1>Bool</span><span class=cF0> poll_mouse) <a name="l351"></a>{ <a name="l352"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.install_in_progress) <a name="l353"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l354"></a> </span><span class=cF5>Yield</span><span class=cF0>; <a name="l355"></a> </span><span class=cF1>return</span><span class=cF0>; <a name="l356"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l357"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>kbd</span><span class=cF0>.reset) <a name="l358"></a> </span><span class=cFD>KbdMouseReset</span><span class=cF0>; <a name="l359"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l360"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l361"></a> </span><span class=cF1>if</span><span class=cF0> (poll_mouse && </span><span class=cFB>mouse_hard</span><span class=cF0>.installed && !</span><span class=cFB>mouse_hard</span><span class=cF0>.irqs_working) <a name="l362"></a> { <a name="l363"></a> </span><span class=cF1>PUSHFD</span><span class=cF0> <a name="l364"></a> </span><span class=cF1>CLI</span><span class=cF0> <a name="l365"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF3>KBD_CTRL</span><span class=cF7>)</span><span class=cF0> & </span><span class=cFE>1</span><span class=cF0>) <a name="l366"></a> </span><span class=cFD>MouseHardPacketRead</span><span class=cF0>; <a name="l367"></a> </span><span class=cF1>POPFD</span><span class=cF0> <a name="l368"></a> } <a name="l369"></a> <a name="l370"></a> </span><span class=cF1>if</span><span class=cF0> (poll_kbd) <a name="l371"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF3>KBD_CTRL</span><span class=cF7>)</span><span class=cF0> & </span><span class=cFE>1</span><span class=cF0>) <a name="l372"></a> </span><span class=cFD>KbdPacketRead</span><span class=cF0>; <a name="l373"></a> <a name="l374"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>kbd</span><span class=cF0>.reset) <a name="l375"></a> </span><span class=cFD>KbdMouseReset</span><span class=cF0>; <a name="l376"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l377"></a> { <a name="l378"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>FifoU8Count</span><span class=cF7>(</span><span class=cFB>kbd</span><span class=cF0>.fifo2</span><span class=cF7>)</span><span class=cF0>) <a name="l379"></a> </span><span class=cFD>KbdHandler</span><span class=cF0>; <a name="l380"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>FifoU8Count</span><span class=cF7>(</span><span class=cFB>mouse_hard</span><span class=cF0>.fifo2</span><span class=cF7>)</span><span class=cF0>) <a name="l381"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>mouse_hard</span><span class=cF0>.installed) <a name="l382"></a> </span><span class=cFD>MouseHardHandler</span><span class=cF0>; <a name="l383"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l384"></a> </span><span class=cFD>KbdMouseReset</span><span class=cF0>; <a name="l385"></a> } <a name="l386"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l387"></a>} <a name="l388"></a> <a name="l389"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>KbdMouseInit</span><span class=cF0>() <a name="l390"></a>{ <a name="l391"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&</span><span class=cFB>kbd</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CKbdStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l392"></a> </span><span class=cFB>kbd</span><span class=cF0>.fifo = </span><span class=cF5>FifoU8New</span><span class=cF0>(</span><span class=cFE>8</span><span class=cF0>); <a name="l393"></a> </span><span class=cFB>kbd</span><span class=cF0>.fifo2 = </span><span class=cF5>FifoU8New</span><span class=cF0>(</span><span class=cFE>0x1000</span><span class=cF0>); <a name="l394"></a> </span><span class=cFB>kbd</span><span class=cF0>.scan_code_fifo = </span><span class=cF5>FifoI64New</span><span class=cF0>(</span><span class=cFE>0x1000</span><span class=cF0>); <a name="l395"></a> </span><span class=cFB>kbd</span><span class=cF0>.irqs_working = </span><span class=cF3>FALSE</span><span class=cF0>; <a name="l396"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&</span><span class=cFB>mouse_hard</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMouseHardStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l397"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.enabled = </span><span class=cF3>TRUE</span><span class=cF0>; <a name="l398"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.fifo = </span><span class=cF5>FifoU8New</span><span class=cF0>(</span><span class=cFE>8</span><span class=cF0>); <a name="l399"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.fifo2 = </span><span class=cF5>FifoU8New</span><span class=cF0>(</span><span class=cFE>0x1000</span><span class=cF0>); <a name="l400"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.x = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0>; <a name="l401"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.y = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>5</span><span class=cF0>; <a name="l402"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.z = </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>; <a name="l403"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.x = </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.x / </span><span class=cFE>2</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>; <a name="l404"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.y = </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.y / </span><span class=cFE>2</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>; <a name="l405"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.prescale.z = </span><span class=cFE>0</span><span class=cF0> / </span><span class=cFB>mouse_hard</span><span class=cF0>.scale.z; <a name="l406"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.x = </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.width >> </span><span class=cFE>1</span><span class=cF0>; <a name="l407"></a> </span><span class=cFB>mouse_hard</span><span class=cF0>.pos.y = </span><span class=cFB>sys_vbe_mode</span><span class=cF0>.height >> </span><span class=cFE>1</span><span class=cF0>; <a name="l408"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&</span><span class=cFB>mouse_hard_last</span><span class=cF0>, &</span><span class=cFB>mouse_hard</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMouseHardStateGlobals</span><span class=cF7>)</span><span class=cF0>); <a name="l409"></a>} </span></pre></body> </html>