|
|
1.1 root 1: /*
2: Hatari - clocks_timings.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Clocks Timings for the hardware components in each supported machine type,
8: as well as functions taking into account the exact length of a VBL to
9: precisely emulate video/audio parts (number of VBL per sec, number of
10: audio samples per VBL, ...)
11:
1.1.1.2 ! root 12:
1.1 root 13:
14:
15:
16: ST :
17: MCLK = 32 MHz
18: SHIFTER IN = 32 MHz OUT = 16 MHz
19: MMU IN = 16 MHz OUT = 8 MHz, 4 MHz
20: GLUE IN = 8 MHz OUT = 2 MHz, 500 kHz
21: BUS = 8 MHz
22:
23: CPU 68000 IN = 8 MHz
24: DMA IN = 8 MHz
25: MFP 68901 IN = 4 MHz, 2.4576 MHz (external clock)
26: FDC WD1772 IN = 8 MHz
27: BLITTER IN = 8 MHz
28: YM2149 IN = 2 MHz
29: ACIA MC6850 IN = 500 kHz
30: IKBD HD6301 IN = 1 MHZ (local clock)
31:
32:
33:
34: */
35:
36:
37: const char ClocksTimings_fileid[] = "Hatari clocks_timings.c : " __DATE__ " " __TIME__;
38:
39: #include <SDL.h>
40: #include <SDL_endian.h>
41:
42: #include "main.h"
43: #include "configuration.h"
44: #include "log.h"
45: #include "clocks_timings.h"
46:
47:
48:
49: /* The possible master frequencies used in the different machines */
50: /* depending on PAL/NTSC version. */
51:
52: #define ATARI_STF_PAL_MCLK 32084988 /* CPU_Freq = 8.021247 MHz */
53: #define ATARI_STF_NTSC_MCLK 32042400 /* CPU_Freq = 8.010600 MHz */
54: #define ATARI_STF_CYCLES_PER_VBL_PAL 160256 /* 512 cycles * 313 lines */
55: #define ATARI_STF_CYCLES_PER_VBL_NTSC 133604 /* 508 cycles * 263 lines */
56: #define ATARI_STF_CYCLES_PER_VBL_HI 112224 /* 224 cycles * 501 lines */
57:
58: #define ATARI_STE_PAL_MCLK 32084988 /* CPU_Freq = 8.021247 MHz */
59: #define ATARI_STE_NTSC_MCLK 32215905 /* CPU_Freq = 8.05397625 MHz */
60: #define ATARI_STE_EXT_OSC 8010613 /* OSC U303 */
61: #define ATARI_STE_CYCLES_PER_VBL_PAL 160256 /* 512 cycles * 313 lines */
62: #define ATARI_STE_CYCLES_PER_VBL_NTSC 133604 /* 508 cycles * 263 lines */
63: #define ATARI_STE_CYCLES_PER_VBL_HI 112224 /* 224 cycles * 501 lines */
64:
65: #define ATARI_MEGA_STE_PAL_MCLK 32084988 /* CPU_Freq = 16.042494 MHz */
66: #define ATARI_MEGA_STE_NTSC_MCLK 32215905 /* CPU_Freq = 16.1079525 MHz */
67: #define ATARI_MEGA_STE_EXT_OSC 16021226 /* OSC U408 */
68:
69: #define ATARI_TT_PAL_MCLK 32084988 /* CPU_Freq = 32.084988 MHz */
70: #define ATARI_TT_NTSC_MCLK 32215905 /* CPU_Freq = 32.215905 MHz */
71:
72: #define ATARI_FALCON_PAL_MCLK 32084988 /* CPU_Freq = 16.042494 MHz */
73: #define ATARI_FALCON_NTSC_MCLK 32215905 /* CPU_Freq = 16.1079525 MHz */
74: #define ATARI_FALCON_25M_CLK 25175000
75:
76: #define ATARI_MFP_XTAL 2457600 /* external clock for the MFP */
77: #define ATARI_IKBD_CLK 1000000 /* clock of the HD6301 ikbd cpu */
78:
79:
80:
81: CLOCKS_STRUCT MachineClocks;
82:
83:
84: bool RoundVBLPerSec = false; /* if false, don't round number of VBL to 50/60 Hz */
85: /* but compute the exact value based on cpu/video clocks */
86:
87:
88:
89:
90: /*--------------------------------------------------------------------------*/
91: /**
92: * Initialize all the clocks informations related to a specific machine type.
93: * We consider the machine is running with PAL clocks.
94: */
95:
96: void ClocksTimings_InitMachine ( MACHINETYPE MachineType )
97: {
98: memset ( (void *)&MachineClocks , 0 , sizeof ( MachineClocks ) );
99:
1.1.1.2 ! root 100:
1.1 root 101: int CLK16, CLK8, CLK4, CLK2, CLK500;
102:
103: MachineClocks.MCLK_Freq = ATARI_STF_PAL_MCLK; /* 32.084988 MHz */
104:
105: MachineClocks.SHIFTER_Freq = MachineClocks.MCLK_Freq; /* 32 MHz */
106: CLK16 = MachineClocks.SHIFTER_Freq / 2;
107:
108: MachineClocks.MMU_Freq = CLK16; /* 16 MHz */
109: CLK8 = MachineClocks.MMU_Freq / 2;
110: CLK4 = MachineClocks.MMU_Freq / 4;
111:
112: MachineClocks.GLUE_Freq = CLK8; /* 8 MHz */
113: CLK2 = MachineClocks.GLUE_Freq / 4;
114: CLK500 = MachineClocks.GLUE_Freq / 16;
115:
116: MachineClocks.BUS_Freq = CLK8; /* 8 MHz */
117:
1.1.1.2 ! root 118: MachineClocks.CPU_Freq = 33000000; /* 33 MHz */
1.1 root 119: MachineClocks.DMA_Freq = CLK8; /* 8 MHz */
120: MachineClocks.MFP_Freq = CLK4; /* 4 MHz */
121: MachineClocks.MFP_Timer_Freq = ATARI_MFP_XTAL; /* 2.4576 MHz (XTAL)*/
122: MachineClocks.FDC_Freq = CLK8; /* 8 MHz */
123: MachineClocks.BLITTER_Freq = CLK8; /* 8 MHz */
124: MachineClocks.YM_Freq = CLK2; /* 2 MHz */;
125: MachineClocks.ACIA_Freq = CLK500; /* 500 kHz */
126: MachineClocks.IKBD_Freq = ATARI_IKBD_CLK; /* 1 MHz */
127:
128:
129: }
130:
131:
132:
133:
134:
135: /*-----------------------------------------------------------------------------------------*/
136: /**
137: * Return the number of VBL per second, depending on the video settings and the cpu freq.
138: * This value is only known for STF/STE running at 50, 60 or 71 Hz.
139: * For the other machines, we return CPU_Freq / ScreenRefreshRate
140: */
141:
142: Uint32 ClocksTimings_GetCyclesPerVBL ( MACHINETYPE MachineType , int ScreenRefreshRate )
143: {
144: Uint32 CyclesPerVBL;
145:
146:
147: CyclesPerVBL = MachineClocks.CPU_Freq / ScreenRefreshRate; /* default value */
148: return CyclesPerVBL;
149: }
150:
151:
152:
153:
154: /*-----------------------------------------------------------------------------------------*/
155: /**
156: * Return the number of VBL per second, depending on the video settings and the cpu freq.
157: * Since the cpu freq is not an exact multiple of the number of cycles per VBL, the real
158: * value slightly differs from the usual 50/60 Hz.
159: * Precise values are needed in STE mode to synchronize cpu and dma sound (as they both use
160: * 2 different clocks).
161: * example for STF/STE :
162: * PAL STF/STE video PAL : 50.053 VBL/sec
163: * PAL STF/STE video NTSC : 60.037 VBL/sec
164: * NTSC STF/STE video PAL : 49.986 VBL/sec
165: * NTSC STF/STE video NTSC : 59.958 VBL/sec
166: *
167: * The returned number of VBL per sec is << 24 (=CLOCKS_TIMINGS_SHIFT_VBL) to simulate floating point using Uint32.
168: */
169:
170: Uint32 ClocksTimings_GetVBLPerSec ( MACHINETYPE MachineType , int ScreenRefreshRate )
171: {
172: Uint32 VBLPerSec; /* Upper 8 bits are for int part, 24 lower bits for float part */
173:
174:
175: VBLPerSec = ScreenRefreshRate << CLOCKS_TIMINGS_SHIFT_VBL; /* default rounded value */
176: return VBLPerSec;
177: }
178:
179:
180:
181:
182: /*-----------------------------------------------------------------------------------------*/
183: /**
184: * Return the length in microsec of a VBL (opposite function of ClocksTimings_GetVBLPerSec)
185: * We use precise values only in STF/STE mode, else we use 1000000 / ScreenRefreshRate.
186: * example for STF/STE :
187: * PAL STF/STE video PAL : 19979 micro sec (instead of 20000 for 50 Hz)
188: * PAL STF/STE video NTSC : 16656 micro sec (instead of 16667 for 60 Hz)
189: */
190:
191: Uint32 ClocksTimings_GetVBLDuration_micro ( MACHINETYPE MachineType , int ScreenRefreshRate )
192: {
193: Uint32 VBLDuration_micro;
194:
1.1.1.2 ! root 195: VBLDuration_micro = (Uint32) (33000000.0 / ScreenRefreshRate + 0.5); /* default rounded value, round to closest integer */
1.1 root 196: return VBLDuration_micro;
197: }
198:
199:
200:
201:
202: /*-----------------------------------------------------------------------------------------*/
203: /**
204: * Return the number of samples needed to emulate the sound that was produced during one VBL.
205: * This depends on the chosen audio output frequency, as well as the VBL's duration,
206: *
207: * We use precise values only in STF/STE mode, else we use AudioFreq/ScreenRefreshRate.
208: *
209: * The returned number of samples per VBL is << 28 to simulate maximum precision using
210: * 64 bits integers (lower 28 bits are for the floating point part).
211: * example for STF/STE with emulation's audio freq = 44100 :
212: * PAL STF/STE video PAL : 881.07 samples per VBL (instead of 882 for 50 Hz)
213: * 44053.56 samples for 50 VBLs (instead of 44100 for 1 sec at 50 Hz)
214: */
215:
216: Sint64 ClocksTimings_GetSamplesPerVBL ( MACHINETYPE MachineType , int ScreenRefreshRate , int AudioFreq )
217: {
218: Sint64 SamplesPerVBL;
219:
220:
221: SamplesPerVBL = ( ((Sint64)AudioFreq) << 28 ) / ScreenRefreshRate; /* default value */
222:
223: return SamplesPerVBL;
224: }
225:
226:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.