- Rename DEBUG to NESE_DEBUG - Split out allocators for internal RAM - SDL flushing (GPU compat) - Porting notesv2
| @@ -2,10 +2,11 @@ | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "cart.h" | #include "cart.h" | ||||
| #include "port.h" | |||||
| #ifdef DEBUG_CART | #ifdef DEBUG_CART | ||||
| #define DEBUG "Cart" | |||||
| #define NESE_DEBUG "Cart" | |||||
| #endif | #endif | ||||
| #include "log.h" | #include "log.h" | ||||
| @@ -64,7 +65,7 @@ int nes_cart_load_mem(void* data, int size, nes* sys) { | |||||
| if (hdr->chr_size_lsb <= 0) { | if (hdr->chr_size_lsb <= 0) { | ||||
| int chr_size = mapper->max_chr_banks * | int chr_size = mapper->max_chr_banks * | ||||
| NES_CHR_ROM_PAGE_SIZE; | NES_CHR_ROM_PAGE_SIZE; | ||||
| mem->ppu.chr_ram = calloc(1, chr_size); | |||||
| mem->ppu.chr_ram = nese_alloc_gpu(chr_size); | |||||
| LOGI("CHR RAM: %d kB", chr_size / 1024); | LOGI("CHR RAM: %d kB", chr_size / 1024); | ||||
| mem->ppu.chr = mem->ppu.chr_ram; | mem->ppu.chr = mem->ppu.chr_ram; | ||||
| mem->ppu.n_chr_banks = chr_size / | mem->ppu.n_chr_banks = chr_size / | ||||
| @@ -75,7 +76,7 @@ int nes_cart_load_mem(void* data, int size, nes* sys) { | |||||
| mem->mapper = *mapper; | mem->mapper = *mapper; | ||||
| mem->mapper.irq_arg = &sys->core; | mem->mapper.irq_arg = &sys->core; | ||||
| mem->mapper.irq_callback = (void(*)(void*, bool))f6502_set_IRQ; | mem->mapper.irq_callback = (void(*)(void*, bool))f6502_set_IRQ; | ||||
| mem->mapper.data = calloc(1, mapper->data_size); | |||||
| mem->mapper.data = nese_alloc(mapper->data_size); | |||||
| if (NULL == mem->mapper.data) { | if (NULL == mem->mapper.data) { | ||||
| LOGE("Failed to allocate mapper data"); | LOGE("Failed to allocate mapper data"); | ||||
| status = -1; | status = -1; | ||||
| @@ -16,7 +16,7 @@ | |||||
| (type *)((char *)__mptr - offsetof(type,member));}) | (type *)((char *)__mptr - offsetof(type,member));}) | ||||
| #endif | #endif | ||||
| //#define DEBUG "Core" | |||||
| //#define NESE_DEBUG "Core" | |||||
| #include "log.h" | #include "log.h" | ||||
| @@ -15,6 +15,10 @@ | |||||
| #include "log.h" | #include "log.h" | ||||
| /* OS-specific file operations | |||||
| * Memory mapping specifically needs to be ported for each OS | |||||
| */ | |||||
| static void* nese_map_file(FILE* file, int size) { | static void* nese_map_file(FILE* file, int size) { | ||||
| void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, | void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, | ||||
| fileno(file), 0); | fileno(file), 0); | ||||
| @@ -38,6 +42,29 @@ static int nese_file_size(FILE* file) { | |||||
| } | } | ||||
| /* Platform-specific allocation | |||||
| * GPU and CPU refer to emulator memory spaces | |||||
| * Note: GPU (and possibly CPU) regions may need | |||||
| * to be placed into internal ram for performance | |||||
| */ | |||||
| void* nese_alloc_gpu(int size) { | |||||
| return calloc(1, size); | |||||
| } | |||||
| void* nese_alloc_cpu(int size) { | |||||
| return calloc(1, size); | |||||
| } | |||||
| void* nese_alloc(int size) { | |||||
| return calloc(1, size); | |||||
| } | |||||
| /* SDL-specific init and entry point | |||||
| * This should be maximally reusable across platforms | |||||
| */ | |||||
| typedef struct { | typedef struct { | ||||
| const char* filename; | const char* filename; | ||||
| FILE* file; | FILE* file; | ||||
| @@ -137,6 +164,8 @@ int nese_frame_start(void* plat_data, uint8_t background) { | |||||
| platform_data* plat = (platform_data*)plat_data; | platform_data* plat = (platform_data*)plat_data; | ||||
| SDL_Color ext = nes_palette[background]; | SDL_Color ext = nes_palette[background]; | ||||
| // TODO: Compose color according to GPU format? | |||||
| // Why are R/B reversed on STM32? | |||||
| SDL_FillRect(plat->target, NULL, ((int)ext.r << 16) | | SDL_FillRect(plat->target, NULL, ((int)ext.r << 16) | | ||||
| ((int)ext.g << 8) | ext.b); | ((int)ext.g << 8) | ext.b); | ||||
| @@ -218,6 +247,7 @@ int nese_frame_ready(void* plat_data) { | |||||
| } | } | ||||
| putc('\n', stdout); | putc('\n', stdout); | ||||
| */ | */ | ||||
| SDL_RenderFlush(plat->renderer); | |||||
| SDL_BlitSurface(plat->screen, NULL, plat->target, NULL); | SDL_BlitSurface(plat->screen, NULL, plat->target, NULL); | ||||
| @@ -1,15 +1,15 @@ | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #ifdef DEBUG | |||||
| #ifdef NESE_DEBUG | |||||
| #define LOG(l, f, ...) fprintf(stderr, l ": " DEBUG ": " f "\n" __VA_OPT__(,) __VA_ARGS__) | |||||
| #define LOG(l, f, ...) fprintf(stderr, l ": " NESE_DEBUG ": " f "\n" __VA_OPT__(,) __VA_ARGS__) | |||||
| #else // !DEBUG | |||||
| #else // !NESE_DEBUG | |||||
| #define LOG(...) | #define LOG(...) | ||||
| #endif // DEBUG | |||||
| #endif // NESE_DEBUG | |||||
| #define LOGE(f, ...) LOG("E", f, __VA_ARGS__) | #define LOGE(f, ...) LOG("E", f, __VA_ARGS__) | ||||
| @@ -1,6 +1,6 @@ | |||||
| #include "memory.h" | #include "memory.h" | ||||
| //#define DEBUG "MMC1" | |||||
| //#define NESE_DEBUG "MMC1" | |||||
| #include "log.h" | #include "log.h" | ||||
| @@ -1,6 +1,6 @@ | |||||
| #include "memory.h" | #include "memory.h" | ||||
| #define DEBUG "MMC3" | |||||
| #define NESE_DEBUG "MMC3" | |||||
| #include "log.h" | #include "log.h" | ||||
| @@ -3,7 +3,7 @@ | |||||
| #include "nes.h" | #include "nes.h" | ||||
| #include "port.h" | #include "port.h" | ||||
| //#define DEBUG "NES" | |||||
| //#define NESE_DEBUG "NES" | |||||
| #include "log.h" | #include "log.h" | ||||
| @@ -11,5 +11,9 @@ int nese_line_ready(void*, uint8_t* buffer, int line); | |||||
| int nese_frame_ready(void*); | int nese_frame_ready(void*); | ||||
| int nese_update_input(void*, nes_Input*); | int nese_update_input(void*, nes_Input*); | ||||
| void* nese_alloc_gpu(int); | |||||
| void* nese_alloc_cpu(int); | |||||
| void* nese_alloc(int); | |||||
| #endif // NESE_PORT_H_ | #endif // NESE_PORT_H_ | ||||
| @@ -2,7 +2,7 @@ | |||||
| #include "ppu.h" | #include "ppu.h" | ||||
| //#define DEBUG "PPU" | |||||
| //#define NESE_DEBUG "PPU" | |||||
| #include "log.h" | #include "log.h" | ||||