-
Notifications
You must be signed in to change notification settings - Fork 8
/
sync.go
71 lines (57 loc) · 1.9 KB
/
sync.go
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
package main
import (
"ndsemu/emu"
)
const (
cBusClock = int64(0x1FF61FE) // 33.513982 Mhz
cNds7Clock = cBusClock
cNds9Clock = cBusClock * 2
cEmuClock = cBusClock
)
const (
// Audio Frequency. In most games the exact frequency does not
// really matter (within some reasonable bounds), but a few games
// stream musics into a circular buffer, using VMatch IRQ to syncrhonize
// with audio; in those case, we need a perfect audio frequency
// otherwise we can hear statics in audio. Examples: Animal Crossing
// (title screen), Who Wants To Be A Millionaire (voices).
// This value is probably not precise, but it works for now
// (at least until we don't understand why the formula below
// requires a magic adjustment)
cAudioFreq = 32768
// Calculate how much the audio timers increment for every
// sound tick. Theoretically, the formula below is correct
// (modulo truncation) but we need to add a magic constant to mostly fix
// statics in some games, and it's still not perfect, so we're not
// fully understanding this yet.
cAudioBugAdjust = 2
cTimerStepPerSample = uint32((cEmuClock / 2 / cAudioFreq) + cAudioBugAdjust)
)
// NDS SYNC
var NdsLcdConfig = HwLcdConfig{
VBlankFirstLine: 192,
VBlankLastLine: 261,
HBlankFirstDot: 268,
}
var NdsSyncConfig = &emu.SyncConfig{
MainClock: cBusClock,
DotClockDivider: 6, // Dot Clock = 5.585664 MHz
HDots: 355,
VDots: 263,
// Sync at the beginning of each line, and at hblank
HSyncs: []int{0, NdsLcdConfig.HBlankFirstDot},
}
// GBA SYNC
var GbaLcdConfig = HwLcdConfig{
VBlankFirstLine: 160,
VBlankLastLine: 226,
HBlankFirstDot: 251,
}
var GbaSyncConfig = &emu.SyncConfig{
MainClock: cBusClock / 2, // this is what happens on NDS hardware
DotClockDivider: 4,
HDots: 308,
VDots: 228,
// Sync at the beginning of each line, and at hblank
HSyncs: []int{0, GbaLcdConfig.HBlankFirstDot},
}