-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPIC.C
135 lines (120 loc) · 4.08 KB
/
PIC.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (C) 2002-2012 The DOSBox Team
* Copyright (C) 2013-2014 bjt
* Copyright (C) 2015 ab0tj
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* --------------------------------------------
* HardMPU by ab0tj - Hardware MPU-401 Emulator
* --------------------------------------------
*
* Based on pic.c from SoftMPU by bjt which was
* based on original pic.c from DOSBox
*
*/
/* SOFTMPU: Moved exported functions & types to header */
#include "export.h"
// HardMPU includes
#include "config.h"
//#include <util/delay.h>
#include <avr/interrupt.h>
void MPU401_Event(void);
void MPU401_ResetDone(void);
void MPU401_EOIHandler(void);
/* SOFTMPU: Event countdown timers */
static Bitu event_countdown[NUM_EVENTS];
extern Bitu MIDI_sysex_delaytime; /* SOFTMPU: Initialised in midi.c */
void PIC_AddEvent(EventID event, Bitu delay)
{
/* Dispatch event immediately on zero delay */
/* Watch out for blocking loops here... */
if (delay==0)
{
switch (event)
{
case MPU_EVENT:
/* Don't dispatch immediately as we'll enter an
infinite loop if tempo is high enough */
delay=1; /* Enforce minimum delay */
break;
case RESET_DONE:
MPU401_ResetDone();
break;
case EOI_HANDLER:
MPU401_EOIHandler();
break;
default:
break;
}
}
/* SOFTMPU: Set the countdown timer */
event_countdown[event]=delay;
}
void PIC_RemoveEvents(EventID event)
{
/* SOFTMPU: Zero the countdown timer (disable event) */
event_countdown[event]=0;
}
void PIC_Init(void)
{
Bit8u i;
/* SOFTMPU: Zero countdown timers */
for (i=0;i<NUM_EVENTS;i++)
{
PIC_RemoveEvents(i);
}
}
//void PIC_Update(bool blocking)
ISR(TIMER1_COMPA_vect)
{
Bit8u i;
/* if (blocking)
{
_delay_us(250);
} */
/* SOFTMPU: Decrement sysex delay used in midi.c */
if (MIDI_sysex_delaytime > 0)
{
MIDI_sysex_delaytime--;
}
/* SOFTMPU: Decrement countdown timers and dispatch as needed */
for (i=0;i<NUM_EVENTS;i++)
{
if (event_countdown[i] > 0)
{
event_countdown[i]--;
if (event_countdown[i]==0)
{
/* Dispatch */
switch (i)
{
case MPU_EVENT:
MPU401_Event();
break;
case RESET_DONE:
MPU401_ResetDone();
break;
case EOI_HANDLER:
MPU401_EOIHandler();
break;
default:
break;
}
}
}
}
}