瀏覽代碼

ARM/STM32 Compatability improvements

- Rename DEBUG to NESE_DEBUG
 - Split out allocators for internal RAM
 - SDL flushing (GPU compat)
 - Porting notes
v2
Nathaniel Walizer 9 月之前
父節點
當前提交
ae22606f81
共有 9 個檔案被更改,包括 47 行新增12 行删除
  1. +4
    -3
      src/cart.c
  2. +1
    -1
      src/f6502.c
  3. +30
    -0
      src/linux/port.c
  4. +4
    -4
      src/log.h
  5. +1
    -1
      src/map/map001.c
  6. +1
    -1
      src/map/map004.c
  7. +1
    -1
      src/nes.c
  8. +4
    -0
      src/port.h
  9. +1
    -1
      src/ppu.c

+ 4
- 3
src/cart.c 查看文件

@@ -2,10 +2,11 @@
#include <string.h>

#include "cart.h"
#include "port.h"


#ifdef DEBUG_CART
#define DEBUG "Cart"
#define NESE_DEBUG "Cart"
#endif
#include "log.h"

@@ -64,7 +65,7 @@ int nes_cart_load_mem(void* data, int size, nes* sys) {
if (hdr->chr_size_lsb <= 0) {
int chr_size = mapper->max_chr_banks *
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);
mem->ppu.chr = mem->ppu.chr_ram;
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.irq_arg = &sys->core;
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) {
LOGE("Failed to allocate mapper data");
status = -1;


+ 1
- 1
src/f6502.c 查看文件

@@ -16,7 +16,7 @@
(type *)((char *)__mptr - offsetof(type,member));})
#endif

//#define DEBUG "Core"
//#define NESE_DEBUG "Core"
#include "log.h"




+ 30
- 0
src/linux/port.c 查看文件

@@ -15,6 +15,10 @@
#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) {
void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED,
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 {
const char* filename;
FILE* file;
@@ -137,6 +164,8 @@ int nese_frame_start(void* plat_data, uint8_t background) {
platform_data* plat = (platform_data*)plat_data;

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) |
((int)ext.g << 8) | ext.b);

@@ -218,6 +247,7 @@ int nese_frame_ready(void* plat_data) {
}
putc('\n', stdout);
*/
SDL_RenderFlush(plat->renderer);

SDL_BlitSurface(plat->screen, NULL, plat->target, NULL);



+ 4
- 4
src/log.h 查看文件

@@ -1,15 +1,15 @@
#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(...)

#endif // DEBUG
#endif // NESE_DEBUG


#define LOGE(f, ...) LOG("E", f, __VA_ARGS__)


+ 1
- 1
src/map/map001.c 查看文件

@@ -1,6 +1,6 @@
#include "memory.h"

//#define DEBUG "MMC1"
//#define NESE_DEBUG "MMC1"
#include "log.h"




+ 1
- 1
src/map/map004.c 查看文件

@@ -1,6 +1,6 @@
#include "memory.h"

#define DEBUG "MMC3"
#define NESE_DEBUG "MMC3"
#include "log.h"




+ 1
- 1
src/nes.c 查看文件

@@ -3,7 +3,7 @@
#include "nes.h"
#include "port.h"

//#define DEBUG "NES"
//#define NESE_DEBUG "NES"
#include "log.h"




+ 4
- 0
src/port.h 查看文件

@@ -11,5 +11,9 @@ int nese_line_ready(void*, uint8_t* buffer, int line);
int nese_frame_ready(void*);
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_

+ 1
- 1
src/ppu.c 查看文件

@@ -2,7 +2,7 @@

#include "ppu.h"

//#define DEBUG "PPU"
//#define NESE_DEBUG "PPU"
#include "log.h"




Loading…
取消
儲存