Fixed UNIX compilation

This commit is contained in:
2025-02-08 13:08:34 -07:00
parent 65e4dbadb5
commit fc67151bfa
613 changed files with 34 additions and 38 deletions

View File

@ -1,6 +1,5 @@
#include <audio.h>
#include <math.h>
#include <windows.h>
#include <emu.h>
#include <portaudio.h>
@ -875,4 +874,4 @@ void audio_write(u16 address, u8 value){
enable_noise();
}
}
}
}

View File

@ -1,5 +1,6 @@
#include <cart.h>
#include <common.h>
#include <string.h>
typedef struct {
char filename[1024];
@ -338,4 +339,4 @@ bool cart_battery_save(){
fwrite(ctx.ram_bank, 0x2000, 1, fp);
fclose(fp);
}
}

View File

@ -3,6 +3,9 @@
#include <bus.h>
#include <stack.h>
reg_type decode_reg(u8 reg);
//process CPU instructions...
void cpu_set_flags(cpu_context *ctx, int8_t z, int8_t n, int8_t h, int8_t c){
@ -543,4 +546,4 @@ IN_PROC processors[] = {
IN_PROC inst_get_processor(in_type type) {
return processors[type];
}
}

View File

@ -10,8 +10,7 @@
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef _UNIX
#else
#include <pthread.h>
#include <unistd.h>
#endif
@ -22,7 +21,11 @@ emu_context *emu_get_context() {
return &ctx;
}
#ifdef _WIN32
DWORD WINAPI cpu_run(void *p) {
#else
void *cpu_run(void *p) {
#endif
ppu_init();
timer_init();
cpu_init();
@ -40,7 +43,7 @@ DWORD WINAPI cpu_run(void *p) {
if (!cpu_step()) {
printf("CPU stopped\n");
return -3;
return 0;
}
}
@ -51,9 +54,8 @@ DWORD WINAPI cpu_run(void *p) {
void sleep_ms(int milis) {
#ifdef _WIN32
Sleep(milis);
#endif
#ifdef _UNIX
usleep(milis * 1000);
#else
usleep(milis * 1000);
#endif
}
@ -67,7 +69,7 @@ int emu_run(int argc, char **argv) {
printf("Failed to load ROM file: %s\n", argv[1]);
return -2;
}
printf("Cart loaded..\n");
ui_init();
@ -77,9 +79,8 @@ int emu_run(int argc, char **argv) {
fprintf(stderr, "Unable to create main CPU thread!\n");
return -1;
}
#endif
#ifdef _UNIX
pthread_t t1;
#else
pthread_t t1;
if(pthread_create(&t1, NULL, cpu_run, NULL)) {
fprintf(stderr, "Unable to create main CPU thread!\n");
return -1;
@ -110,4 +111,4 @@ void emu_cycles(int cpu_cycles) {
}
dma_tick();
}
}
}

View File

@ -1,5 +1,6 @@
#include <instructions.h>
#include <cpu.h>
#include <bus.h>
instruction instructions[0x100] = {
//0x0X
@ -442,4 +443,4 @@ void inst_to_str(cpu_context *ctx, char *str) {
fprintf(stderr, "INVALID AM: %d\n", inst->mode);
NO_IMPL
}
}
}

View File

@ -131,7 +131,7 @@ void ppu_mode_vblank() {
}
}
u32 target_frame_time = 1000/60;
static u32 target_frame_time = 1000/60;
static long prev_frame_time = 0;
static long start_timer = 0;
static long frame_count = 0;
@ -179,4 +179,4 @@ void ppu_mode_hblank() {
ppu_get_context()->line_ticks = 0;
}
}
}

View File

@ -1,29 +1,16 @@
#include <Windows.h>
#include <timer.h>
#include <interrupts.h>
#include <audio.h>
#include <profileapi.h>
static timer_context ctx = {0};
long long counts_per_cycle;
long long last;
long long now;
void timer_init() {
ctx.div = 0XAC00;
}
void timer_tick() {
//while(now - last < counts_per_cycle){
// LARGE_INTEGER current;
// QueryPerformanceCounter(&current);
// now = current.QuadPart;
//printf("Last-now: %lld, counts: %lld\n", now - last, counts_per_cycle);
//}
last = now;
u16 prev_div = ctx.div;
u16 prev_div = ctx.div;
ctx.div++;
bool timer_update = false;
switch(ctx.tac & 0b11) {
@ -107,4 +94,4 @@ u8 timer_read(u16 address) {
timer_context *timer_get_context() {
return &ctx;
}
}

View File

@ -2,6 +2,7 @@
#include <emu.h>
#include <ppu.h>
#include <gamepad.h>
#include <bus.h>
#include <SDL.h>
#include <SDL_ttf.h>
@ -186,4 +187,4 @@ void delay(u32 ms) {
u32 get_ticks() {
return SDL_GetTicks();
}
}