I made a peripheral of Megadrive and it is a photodetector.
Virtua Roaching is a software for the photodetector.
The photodetector connect to controller port 2.
Play with roaches all you want by Virtua Roaching.
This controller contain three main devices. LDR, op-amp and A/D converter.
I used a breadboard for simplicity.
ADC0804 have 8bits resolution but this circuit is using higher 4bits only.
Sample code is as follows.
/* 初期化 */ void initAD(){ /* ポート2の入出力方向を設定する */ *(uchar *)0xA1000B = 0xE0; /* photodetector is connected to port 2 */ } /* ADコンバータアクセス時のウェイト */ void waitAD{ asm("nop"); } /* ADデータの読み取り */ uint readAD(){ register d; /* A/D変換を開始する */ *(uchar *)0xA10005 = 0x20; /* write enable = start the A/D convertion */ waitAD; *(uchar *)0xA10005 = 0x60; /* write disable */ waitAD; /* A/D変換が完了するまで待つ */ do{ waitAD; }while(*(uchar *)0xA10005 & 0x10); /* if complete, this bit is zero. */ /* 変換結果を読む */ *(uchar *)0xA10005 = 0x40; /* read enable */ waitAD; d = *(uchar *)0xA10005 & 0x0F; /* read value */ *(uchar *)0xA10005 = 0x60; /* read disable */ waitAD; return d; /* d = 0 to 15 */ }