#include "genesis.h" #include "mouse.h" #define PORT1 ((volatile u8*)0xA10003) #define PORT2 ((volatile u8*)0xA10005) int main() { VDP_setTextPlane(0); VDP_drawText("Sega Mega Mouse RAW reader", 7, 27); VDP_drawText("RAW nibbles:", 14,0); s16 x1=0,y1=0, x2=0,y2=0; u8 frame = 0; char buf[40]; //буфер строки для вывода на экран while(TRUE) { MouseData m1; read_mouse(&m1, PORT1); sprintf(buf, "+%X%X%X%X %X %X %X%X %X%X", m1.nibbles[0], m1.nibbles[1], m1.nibbles[2], m1.nibbles[3], m1.nibbles[4], m1.nibbles[5], m1.nibbles[6], m1.nibbles[7], m1.nibbles[8], m1.nibbles[9]); VDP_clearTextArea(1,2,1,20); VDP_drawText(buf, 1, 2 + frame%20); if(m1.valid) { x1 += m1.dx; y1 += m1.dy; if(x1>9999) x1=-9999; else if(x1<-9999) x1=9999; if(y1>9999) y1=-9999; else if(y1<-9999) y1=9999; sprintf(buf, "buttons: %c%c%c%c", ((m1.buttons>>3)&1)+'0', ((m1.buttons>>2)&1)+'0', ((m1.buttons>>1)&1)+'0', ((m1.buttons>>0)&1)+'0'); VDP_drawText(buf, 2, 23); sprintf(buf, "PORT1: dx:%+04d dy:%+04d x:%+05d y:%+05d", m1.dx,m1.dy,x1,y1); VDP_drawText(buf, 1, 24); } else { VDP_clearTextArea(2,23,13,1); sprintf(buf, "PORT1: Mouse not recognized"); VDP_drawText(buf, 1, 24); } MouseData m2; read_mouse(&m2, PORT2); sprintf(buf, "%X%X%X%X %X %X %X%X %X%X+", m2.nibbles[0], m2.nibbles[1], m2.nibbles[2], m2.nibbles[3], m2.nibbles[4], m2.nibbles[5], m2.nibbles[6], m2.nibbles[7], m2.nibbles[8], m2.nibbles[9]); VDP_clearTextArea(38,2,1,20); VDP_drawText(buf, 24, 2 + frame%20); if(m2.valid) { x2 += m2.dx; y2 += m2.dy; if(x2>9999) x2=-9999; else if(x2<-9999) x2=9999; if(y2>9999) y2=-9999; else if(y2<-9999) y2=9999; sprintf(buf, "buttons: %c%c%c%c", ((m2.buttons>>3)&1)+'0', ((m2.buttons>>2)&1)+'0', ((m2.buttons>>1)&1)+'0', ((m2.buttons>>0)&1)+'0'); VDP_drawText(buf, 25, 23); sprintf(buf, "PORT2: dx:%+04d dy:%+04d x:%+05d y:%+05d", m2.dx,m2.dy,x2,y2); VDP_drawText(buf, 1, 25); } else { sprintf(buf, "PORT2: Mouse not recognized"); VDP_clearTextArea(25,23,13,1); VDP_drawText(buf, 1, 25); } //счётчик кадров для вывода истории нибблов frame++; //конец кадра VDP_waitVSync(); } return 0; }