-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspu.c
110 lines (89 loc) · 3.25 KB
/
spu.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
/*
MIT License
Copyright (c) 2021 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <stdint.h>
#include "common/hardware/hwregs.h"
#include "common/syscalls/syscalls.h"
#include "modplayer/modplayer.h"
#define printf(...)
extern struct MODFileFormat _binary_blip_hit_start;
static uint16_t s_nextCounter = 0;
static uint16_t s_oldMode = 0;
static int s_idle = 1;
int spuIsIntro() { return MOD_CurrentPattern == 0; }
void initSPU() {
s_oldMode = COUNTERS[1].mode;
COUNTERS[1].mode = 0x0100;
MOD_Load(&_binary_blip_hit_start);
printf("(TS) SPU: Loaded %02d Channels, %02d Orders\n", MOD_Channels, MOD_SongLength);
s_nextCounter = COUNTERS[1].value + MOD_hblanks;
}
void checkSPU() {
if (((int16_t)(s_nextCounter - COUNTERS[1].value)) <= 0) {
MOD_Poll();
s_nextCounter += MOD_hblanks;
if (MOD_CurrentOrder != 0) {
if (MOD_CurrentRow == 60) {
MOD_CurrentRow = 59;
}
}
static unsigned row = 0xffffffff;
static unsigned order = 0xffffffff;
static unsigned pattern = 0xffffffff;
if (row != MOD_CurrentRow || order != MOD_CurrentOrder || pattern != MOD_CurrentPattern) {
row = MOD_CurrentRow;
order = MOD_CurrentOrder;
pattern = MOD_CurrentPattern;
printf("(TS) SPU: Row: %02d, Order: %02d, Pattern: %02d\n", row, order, pattern);
}
}
}
void uninitSPU() {
COUNTERS[1].mode = s_oldMode;
MOD_Silence();
}
void spuSchedulePing() {
printf("(TS) SPU: scheduling ping\n");
if (!s_idle) return;
if (MOD_CurrentOrder < 1) return;
if ((MOD_CurrentOrder == 1) && (MOD_CurrentRow < 31)) return;
MOD_ChangeOrderNextTick = 1;
MOD_NextOrder = 2;
}
void spuScheduleIdle() {
printf("(TS) SPU: scheduling idle\n");
if (s_idle) return;
s_idle = 1;
MOD_ChangeOrderNextTick = 1;
MOD_NextOrder = 2;
}
void spuScheduleOutro() {
printf("(TS) SPU: scheduling outro\n");
s_idle = 0;
if (MOD_CurrentOrder < 1) return;
if ((MOD_CurrentOrder == 1) && (MOD_CurrentRow < 31)) return;
MOD_ChangeOrderNextTick = 1;
MOD_NextOrder = 3;
}
void spuScheduleError() {
printf("(TS) SPU: scheduling error\n");
s_idle = 0;
MOD_ChangeOrderNextTick = 1;
MOD_NextOrder = 4;
}