From 950f5b1691249d5439c58b9d17dd1233b92a66bc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 26 Nov 2020 19:56:42 -0500 Subject: [PATCH] Closes the loop on interrupts. --- Machines/Apple/AppleIIgs/Sound.cpp | 24 +++++++++++++++++++----- Machines/Apple/AppleIIgs/Sound.hpp | 1 - 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Machines/Apple/AppleIIgs/Sound.cpp b/Machines/Apple/AppleIIgs/Sound.cpp index 98956fbec..7e5dbf36e 100644 --- a/Machines/Apple/AppleIIgs/Sound.cpp +++ b/Machines/Apple/AppleIIgs/Sound.cpp @@ -88,7 +88,6 @@ void GLU::EnsoniqState::set_register(uint16_t address, uint8_t value) { switch(address & 0xff) { case 0xe0: /* Does setting the interrupt register really make any sense? */ - interrupt_state = value; break; case 0xe1: oscillator_count = 1 + ((value >> 1) & 31); @@ -118,10 +117,18 @@ uint8_t GLU::get_data() { default: switch(address & 0xff) { - case 0xe0: - /* TODO: generate the actual interrupt state. */ - return local_.interrupt_state; - break; + case 0xe0: { + // Find the first enabled oscillator that is signalling an interrupt and has interrupts enabled. + for(int c = 0; c < local_.oscillator_count; c++) { + if(local_.oscillators[c].interrupt_request && (local_.oscillators[c].control & 0x08)) { + local_.oscillators[c].interrupt_request = false; + return uint8_t(0x41 | (c << 1)); + } + } + + // No interrupt found. + return 0xc1; + } break; case 0xe1: return uint8_t((local_.oscillator_count - 1) << 1); // TODO: should other bits be 0 or 1? case 0xe2: return 128; // Input audio. Unimplemented! } @@ -132,6 +139,13 @@ uint8_t GLU::get_data() { } bool GLU::get_interrupt_line() { + // Return @c true if any oscillator currently has its interrupt request + // set, and has interrupts enabled. + for(int c = 0; c < local_.oscillator_count; c++) { + if(local_.oscillators[c].interrupt_request && (local_.oscillators[c].control & 0x08)) { + return true; + } + } return false; } diff --git a/Machines/Apple/AppleIIgs/Sound.hpp b/Machines/Apple/AppleIIgs/Sound.hpp index c08421605..a8b8e4e88 100644 --- a/Machines/Apple/AppleIIgs/Sound.hpp +++ b/Machines/Apple/AppleIIgs/Sound.hpp @@ -90,7 +90,6 @@ class GLU: public Outputs::Speaker::SampleSource { // Some of these aren't actually needed on both threads. uint8_t control; - uint8_t interrupt_state; int oscillator_count; void set_register(uint16_t address, uint8_t value);