From c7f395339f21ff8da675407f219763d87a65a95f Mon Sep 17 00:00:00 2001 From: DIvan2000 Date: Tue, 23 Sep 2025 15:56:13 +0400 Subject: [PATCH] v1.3.1 --- res/fluttershy.png | Bin 194 -> 202 bytes res/pinkie_pie.png | Bin 0 -> 198 bytes res/resources.h | 9 ++++++ res/resources.res | 2 ++ src/main.c | 67 +++++++++++++++++++++++++++++++++++++++------ 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 res/pinkie_pie.png create mode 100644 res/resources.h create mode 100644 res/resources.res diff --git a/res/fluttershy.png b/res/fluttershy.png index 4ce4bc0826b199ac632b9c42d3e956986df2369f..fa57a8a618d49c903bb86b0caaa6a6c2f22436a2 100644 GIT binary patch delta 63 zcmX@ac#3g?p{YcGPlzi61H<=sop0Ce2Qsd%V84|=_nK4LUgq!xw+cmoLL4PQe!&d? NA>it%5Tl84DF8AB9Ebn_ delta 55 zcmX@bc!+U=p{`JXPlzi61H<=sop0Ce2Qsd%V84|=ccr7wBOr&ZB*-tA;XepeRX+GP HF)alETH6?c diff --git a/res/pinkie_pie.png b/res/pinkie_pie.png new file mode 100644 index 0000000000000000000000000000000000000000..f9fc9dbd9183a34a7d3aba0ec3b6ac63d3489df7 GIT binary patch literal 198 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~i2$DvS0MfU zUFX|%`+f$A9++osOr4&1A6!Rj(eJNWsL)vmTRuKV2m l6U3!rL;jq4`}O=zMz1c$uSs*`B!Ol!c)I$ztaD0e0swa>MT7tV literal 0 HcmV?d00001 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;