dev #1
65
src/main.c
65
src/main.c
@ -5,34 +5,43 @@
|
|||||||
|
|
||||||
#define MOUSE_DELAY 32
|
#define MOUSE_DELAY 32
|
||||||
|
|
||||||
static inline void delay() {
|
static inline void delay(void) {
|
||||||
for(int i=0;i<MOUSE_DELAY;i++) asm volatile("nop");
|
__asm__ volatile (
|
||||||
|
"move.w %0,%%d0\n\t"
|
||||||
|
"1: subq.w #1,%%d0\n\t"
|
||||||
|
"bne.s 1b"
|
||||||
|
:
|
||||||
|
: "i"(MOUSE_DELAY)
|
||||||
|
: "d0"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
VDP_setTextPlane(0);
|
VDP_setTextPlane(0);
|
||||||
VDP_drawText("Sega Mega Mouse RAW reader", 2, 16);
|
VDP_drawText("Sega Mega Mouse RAW reader", 7, 27);
|
||||||
|
VDP_drawText("RAW nibbles:", 14,0);
|
||||||
|
u8 nibbles[16] = {0};
|
||||||
|
s16 x = 0;
|
||||||
|
s16 y = 0;
|
||||||
|
|
||||||
u8 nibbles[16];
|
char buf[40]; //буфер строки для вывода на экран
|
||||||
int x = 0;
|
|
||||||
int y = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
|
|
||||||
SYS_doVBlankProcess();
|
SYS_doVBlankProcess();
|
||||||
|
|
||||||
VDP_clearTextArea(0, 0, 40, 13);
|
|
||||||
|
|
||||||
// считываем нибблы напрямую
|
VDP_clearTextArea(0, 1, 40, 13);
|
||||||
|
|
||||||
|
|
||||||
|
//опрос мыши
|
||||||
Z80_HALT = 0x0100;
|
Z80_HALT = 0x0100;
|
||||||
*MOUSE_PORT = 0x60; delay();
|
*MOUSE_PORT = 0x60; delay();
|
||||||
*MOUSE_PORT = 0x60; delay();
|
|
||||||
|
nibbles[0] = *MOUSE_PORT & 0x0F;
|
||||||
|
|
||||||
|
|
||||||
for(int i=1;i<10;i++) {
|
for(int i=1;i<10;i++) {
|
||||||
*MOUSE_PORT = (i&1)?0x00:0x20;
|
*MOUSE_PORT = (i&1)?0x20:0x00;
|
||||||
delay();
|
delay();
|
||||||
nibbles[i] = *MOUSE_PORT & 0x0F;
|
nibbles[i] = *MOUSE_PORT & 0x0F;
|
||||||
delay();
|
delay();
|
||||||
@ -40,29 +49,29 @@ int main() {
|
|||||||
|
|
||||||
*MOUSE_PORT = 0x60; delay();
|
*MOUSE_PORT = 0x60; delay();
|
||||||
Z80_HALT = 0x0000;
|
Z80_HALT = 0x0000;
|
||||||
|
//конец опроса мыши
|
||||||
|
|
||||||
// выводим нибблы на экран
|
// выводим нибблы на экран
|
||||||
char buf[64];
|
sprintf(buf, "%X%X%X%X %X %X %X%X %X%X", nibbles[0],nibbles[1],nibbles[2],nibbles[3],nibbles[4],nibbles[5],nibbles[6],nibbles[7],nibbles[8],nibbles[9]);
|
||||||
int dx = (nibbles[6] << 4) | nibbles[7];
|
VDP_drawText(buf, 13,1);
|
||||||
int dy = (nibbles[8] << 4) | nibbles[9];
|
|
||||||
|
|
||||||
if (nibbles[3]&8) dy = 255;
|
|
||||||
if (nibbles[3]&4) dx = 255;
|
|
||||||
if (nibbles[3]&2) dy = -dy;
|
|
||||||
if (nibbles[3]&1) dx = -dx;
|
|
||||||
|
|
||||||
|
//считаем dx dy
|
||||||
|
s16 dx = (nibbles[6] << 4) | nibbles[7];
|
||||||
|
s16 dy = (nibbles[8] << 4) | nibbles[9];
|
||||||
|
if (nibbles[4]&8) dy = 255;
|
||||||
|
if (nibbles[4]&4) dx = 255;
|
||||||
|
if (nibbles[4]&2) dy = dy|0xFF00; //sign-extend to 16-bit
|
||||||
|
if (nibbles[4]&1) dx = dx|0xFF00;
|
||||||
x+=dx;
|
x+=dx;
|
||||||
y+=dy;
|
y+=dy;
|
||||||
|
|
||||||
|
//выводим на экран полезные данные
|
||||||
sprintf(buf, "dx: %+04d dy: %+04d x: %+04d y: %+04d", dx,dy,x/64,y/64);
|
sprintf(buf, "buttons: %c%c%c%c", (nibbles[5]&8&&1)+'0',(nibbles[5]&4&&1)+'0',(nibbles[5]&2&&1)+'0',(nibbles[5]&1&&1)+'0');
|
||||||
VDP_drawText(buf, 2, 12);
|
|
||||||
sprintf(buf, "buttons: %c%c%c%c", (nibbles[4]&8&&1)+'0',(nibbles[4]&4&&1)+'0',(nibbles[4]&2&&1)+'0',(nibbles[4]&1&&1)+'0');
|
|
||||||
VDP_drawText(buf, 2, 10);
|
VDP_drawText(buf, 2, 10);
|
||||||
|
sprintf(buf, "dx: %+04d dy: %+04d x: %+04d y: %+04d", dx,dy,x,y);
|
||||||
|
VDP_drawText(buf, 2, 12);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user