-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.c
More file actions
48 lines (38 loc) · 972 Bytes
/
Copy pathcpu.c
File metadata and controls
48 lines (38 loc) · 972 Bytes
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
#include "cpu.h"
#include <SDL2/SDL.h>
#define ONE_OVER_60_MS 1000.0/60
int DTthread(void *ptr) {
CPU *cpu = ptr;
while (cpu->regs.DT > 0) {
cpu->regs.DT--;
SDL_Delay(ONE_OVER_60_MS);
}
return 0;
}
int STthread(void *ptr) {
CPU *cpu = ptr;
SDL_AudioSpec wavSpec;
Uint32 wavLength;
Uint8 *wavBuffer;
SDL_LoadWAV("beep.wav", &wavSpec, &wavBuffer, &wavLength);
while (cpu->regs.ST > 0) {
cpu->regs.ST--;
SDL_Delay(ONE_OVER_60_MS);
}
SDL_AudioDeviceID deviceId = SDL_OpenAudioDevice(NULL, 0, &wavSpec, NULL, 0);
SDL_QueueAudio(deviceId, wavBuffer, wavLength);
SDL_PauseAudioDevice(deviceId, 0);
return 0;
}
CPU cpuInit(uint16_t startingAddress) {
CPU cpu = {
.regs = {
.ST=0,
.DT=0,
.PC = startingAddress,
.I =0,
.SP=0
},
};
return cpu;
}