}
+static void sb_dsp_reply (CPU8086 *cpu, uint8_t value) {
+
+ if (cpu->sb_dsp_reply_count < sizeof (cpu->sb_dsp_reply)) {
+
+ unsigned tail = (cpu->sb_dsp_reply_head + cpu->sb_dsp_reply_count) % sizeof (cpu->sb_dsp_reply);
+
+ cpu->sb_dsp_reply[tail] = value;
+ cpu->sb_dsp_reply_count++;
+
+ }
+
+}
+
static uint8_t io_read8 (CPU8086 *cpu, uint16_t port) {
switch (port) {
return 0xFF;
+ case 0x226: /* Sound Blaster DSP reset (write-only) */
+
+ return 0xFF;
+
+ case 0x22A: /* Sound Blaster DSP read data */
+
+ if (cpu->sb_dsp_reply_count) {
+
+ uint8_t result = cpu->sb_dsp_reply[cpu->sb_dsp_reply_head];
+
+ cpu->sb_dsp_reply_head = (uint8_t) ((cpu->sb_dsp_reply_head + 1) % sizeof (cpu->sb_dsp_reply));
+ cpu->sb_dsp_reply_count--;
+
+ return result;
+
+ }
+
+ return 0xFF;
+
+ case 0x22C: /* Sound Blaster DSP write-buffer status */
+
+ return 0x7F; /* DSP command port ready */
+
+ case 0x22E: /* Sound Blaster DSP read-buffer status */
+
+ return cpu->sb_dsp_reply_count ? 0x80 : 0x00;
+
case 0x388: case 0x389: /* AdLib OPL2: not installed */
return 0xFF;
/* No joysticks are connected, so there are no timers to reset. */
break;
+ case 0x226: /* Sound Blaster DSP reset */
+
+ if (value & 1) {
+
+ cpu->sb_dsp_reset = 1;
+ cpu->sb_dsp_reply_head = 0;
+ cpu->sb_dsp_reply_count = 0;
+ cpu->sb_dsp_speaker = 0;
+
+ } else if (cpu->sb_dsp_reset) {
+
+ cpu->sb_dsp_reset = 0;
+ sb_dsp_reply (cpu, 0xAA);
+
+ }
+
+ break;
+
+ case 0x22C: /* Sound Blaster DSP command */
+
+ switch (value) {
+
+ case 0xD1: /* Enable DSP speaker */
+
+ cpu->sb_dsp_speaker = 1;
+ break;
+
+ case 0xD3: /* Disable DSP speaker */
+
+ cpu->sb_dsp_speaker = 0;
+ break;
+
+ case 0xD8: /* Read DSP speaker status */
+
+ sb_dsp_reply (cpu, cpu->sb_dsp_speaker ? 0xFF : 0x00);
+ break;
+
+ case 0xE1: /* Get DSP version: Sound Blaster 2.01 */
+
+ sb_dsp_reply (cpu, 2);
+ sb_dsp_reply (cpu, 1);
+
+ break;
+
+ default:
+
+ fprintf (stderr, "unhandled Sound Blaster DSP command %02X at %04X:%08X\n", value, cpu->cs, cpu->ip);
+ exit (1);
+
+ }
+
+ break;
+
case 0x388: case 0x389: /* AdLib OPL2: no device installed */
/* Writes to an unpopulated I/O port have no effect. */
uint8_t cmos_index, cmos_regs[128];
uint8_t port61, port92, a20_enabled, vga_status_flip;
+ uint8_t sb_dsp_reset, sb_dsp_speaker;
+ uint8_t sb_dsp_reply[4], sb_dsp_reply_head, sb_dsp_reply_count;
+
PITCounter pit[3];
PIC8259 pic[2];