1 /* Mednafen - Multi-system Emulator
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 
18 #include "../shared.h"
19 #include "cd.h"
20 #include "interrupt.h"
21 
22 /* SegaCD interrupt levels:
23 	6 - Sub-channel buffering completed
24 	5 - CDC, error correction or buffer completed
25 	4 - CDD, command reception is completed?
26 	3 - Timer
27 	2 - Software int from main CPU
28 	1 - Graphics operation is completed
29 */
30 
31 
32 static uint32 asserted;
33 static uint32 InterruptMask;
34 
Rebuild(void)35 static void Rebuild(void)
36 {
37  int pending_level = 0;
38  uint32 awm = asserted & InterruptMask;
39 
40  // Level 0 doesn't exist per-se.
41  // Level 7 doesn't seem to be used on the SegaCD
42  for(int i = 6; i > 0; i--)
43  {
44   if(awm & (1 << i))
45   {
46    pending_level = i;
47    break;
48   }
49  }
50 
51  Sub68K.SetIPL(pending_level);
52 }
53 
MDCD_InterruptRead(void)54 uint8 MDCD_InterruptRead(void)
55 {
56  return(InterruptMask);
57 }
58 
MDCD_InterruptGetMask(int level)59 bool MDCD_InterruptGetMask(int level)
60 {
61  return((InterruptMask >> level) & 1);
62 }
63 
MDCD_InterruptGetAsserted(int level)64 bool MDCD_InterruptGetAsserted(int level)
65 {
66  return((asserted >> level) & 1);
67 }
68 
MDCD_InterruptWrite(uint8 V)69 void MDCD_InterruptWrite(uint8 V)
70 {
71  InterruptMask = V & 0x7E;
72  Rebuild();
73 }
74 
MDCD_InterruptAck(int level)75 int MDCD_InterruptAck(int level)
76 {
77  printf("Interrupt: %d\n", level);
78 
79  asserted &= ~(1 << level);
80  Rebuild();
81 
82  return M68K::BUS_INT_ACK_AUTO;
83 }
84 
MDCD_InterruptAssert(int level,bool status)85 void MDCD_InterruptAssert(int level, bool status)
86 {
87  assert(status == 0 || status == 1);
88 
89  asserted &= ~(1 << level);
90  asserted |= status << level;
91  Rebuild();
92 }
93 
MDCD_InterruptReset(void)94 void MDCD_InterruptReset(void)
95 {
96  asserted = 0;
97  Rebuild();
98 }
99 
MDCD_InterruptInit(void)100 void MDCD_InterruptInit(void)
101 {
102 
103 
104 }
105