diff --git a/res/fluttershy.png b/res/fluttershy.png index 4ce4bc0..fa57a8a 100644 Binary files a/res/fluttershy.png and b/res/fluttershy.png differ diff --git a/res/pinkie_pie.png b/res/pinkie_pie.png new file mode 100644 index 0000000..f9fc9db Binary files /dev/null and b/res/pinkie_pie.png differ diff --git a/res/resources.h b/res/resources.h new file mode 100644 index 0000000..38436f0 --- /dev/null +++ b/res/resources.h @@ -0,0 +1,9 @@ +#include + +#ifndef _RES_RESOURCES_H_ +#define _RES_RESOURCES_H_ + +extern const SpriteDefinition FLUTTERSHY; +extern const SpriteDefinition PINKIE_PIE; + +#endif // _RES_RESOURCES_H_ diff --git a/res/resources.res b/res/resources.res new file mode 100644 index 0000000..79025da --- /dev/null +++ b/res/resources.res @@ -0,0 +1,2 @@ +SPRITE FLUTTERSHY "fluttershy.png" 2 2 NONE 0 +SPRITE PINKIE_PIE "pinkie_pie.png" 2 2 NONE 0 diff --git a/src/main.c b/src/main.c index f64fbb4..38e51eb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,21 +1,41 @@ #include "genesis.h" #include "mouse.h" +#include "resources.h" #define PORT1 ((volatile u8*)0xA10003) #define PORT2 ((volatile u8*)0xA10005) +Sprite* ptr1; +Sprite* ptr2; + int main() { VDP_setTextPlane(0); VDP_drawText("Sega Mega Mouse RAW reader", 7, 27); VDP_drawText("RAW nibbles:", 14,0); + + SPR_init(); + PAL_setPalette(PAL1, FLUTTERSHY.palette->data, DMA); s16 x1=0,y1=0, x2=0,y2=0; u8 frame = 0; char buf[40]; //буфер строки для вывода на экран + MouseData m1, m2; + + u8 code1[6] = {0}; + u8 code2[6] = {0}; + + u8 ptr_active1=0,ptr_active2=0; + while(TRUE) { - MouseData m1; + //считывание портов и вывод информации + u8 btnFront1=m1.buttons, btnFront2=m2.buttons; read_mouse(&m1, PORT1); + read_mouse(&m2, PORT2); + + btnFront1^=m1.buttons; + btnFront2^=m2.buttons; + 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], @@ -25,8 +45,20 @@ int main() { 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; + if(x1>304) x1=304; else if(x1<0) x1=0; + if(y1>208) y1=208; else if(y1<0) y1=0; + + if(!ptr_active1 && btnFront1) { + u8* code = code1; + for(int i=1;i<6;i++) code[i-1]=code[i]; + code[5]=btnFront1; + if(code[0]==0x4&&code[1]==0x1&&code[2]==0x1&&code[3]==0x2&&code[4]==0x2&&code[5]==0x4){ + ptr_active1=1; + ptr1 = SPR_addSprite(&FLUTTERSHY, 0, 0, TILE_ATTR(PAL1, TRUE, FALSE, TRUE)); + } + } + + if(ptr_active1) SPR_setPosition(ptr1, x1, 208-y1); sprintf(buf, "buttons: %c%c%c%c", ((m1.buttons>>3)&1)+'0', @@ -43,8 +75,6 @@ int main() { 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], @@ -54,9 +84,22 @@ int main() { 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; + if(x2>304) x2=304; else if(x2<0) x2=0; + if(y2>208) y2=208; else if(y2<0) y2=0; + + if(!ptr_active2 && btnFront2) { + u8* code = code2; + for(int i=1;i<6;i++) code[i-1]=code[i]; + code[5]=btnFront2; + if(code[0]==0x4&&code[1]==0x1&&code[2]==0x1&&code[3]==0x2&&code[4]==0x2&&code[5]==0x4){ + ptr_active2=1; + ptr2 = SPR_addSprite(&PINKIE_PIE, 0, 0, TILE_ATTR(PAL1, TRUE, FALSE, FALSE)); + } + } + + if(ptr_active2) SPR_setPosition(ptr2, x2, 208-y2); + sprintf(buf, "buttons: %c%c%c%c", ((m2.buttons>>3)&1)+'0', ((m2.buttons>>2)&1)+'0', @@ -71,12 +114,20 @@ int main() { VDP_clearTextArea(25,23,13,1); VDP_drawText(buf, 1, 25); } + + //спрайты + + SPR_update(); //счётчик кадров для вывода истории нибблов frame++; //конец кадра - VDP_waitVSync(); + + //Я не уверен почему, но SYS_doVBlankProcess в какой-то момент вызывал странное поведение. После добавления спрайтов, кажется, всё в порядке. + + //VDP_waitVSync(); + SYS_doVBlankProcess(); } return 0;