Skip to content

Commit

Permalink
Merge pull request #39 from esp-cpp/fix/cart-destructor
Browse files Browse the repository at this point in the history
fix(cart): made destructor virtual to be overridden by subclasses
  • Loading branch information
finger563 authored Dec 1, 2023
2 parents ed1e189 + 3a117c5 commit 7fcd95b
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 1,078 deletions.
51 changes: 50 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,60 @@ set(GBC_COMPONENTS "gbc")
### SMS ###
# set(SMS_COMPONENTS "sms")

### SNES ###
# set(SNES_COMPONENTS "snes")

### MSX ###
# set(MSX_COMPONENTS "msx")

### DOOM ###
# set(DOOM_COMPONENTS "doom")

add_compile_definitions(BOARD_HAS_PSRAM)

# if NES_COMPONENTS is set, add compile definitions for the NES
if(NES_COMPONENTS)
add_compile_definitions(ENABLE_NES)
endif()

# if GBC_COMPONENTS is set, add compile definitions for the GBC
if(GBC_COMPONENTS)
add_compile_definitions(ENABLE_GBC)
endif()

# if SMS_COMPONENTS is set, add compile definitions for the SMS
if(SMS_COMPONENTS)
add_compile_definitions(ENABLE_SMS)
endif()

# if SNES_COMPONENTS is set, add compile definitions for the SNES
if(SNES_COMPONENTS)
add_compile_definitions(ENABLE_SNES)
endif()

# if MSX_COMPONENTS is set, add compile definitions for the MSX
if(MSX_COMPONENTS)
add_compile_definitions(ENABLE_MSX)
endif()

# if DOOM_COMPONENTS is set, add compile definitions for the DOOM
if(DOOM_COMPONENTS)
add_compile_definitions(ENABLE_DOOM)
endif()

# make the components list for the emulators we want
set(EMULATOR_COMPONENTS
${NES_COMPONENTS}
${GBC_COMPONENTS}
${SMS_COMPONENTS}
${SNES_COMPONENTS}
${MSX_COMPONENTS}
${DOOM_COMPONENTS}
)

set(
COMPONENTS
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor esp-idf-cxx ${NES_COMPONENTS} ${GBC_COMPONENTS} ${SMS_COMPONENTS} box-emu-hal gui menu"
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor esp-idf-cxx ${EMULATOR_COMPONENTS} box-emu-hal gui menu"
CACHE STRING
"List of components to include"
)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ This project has the following features (still WIP):
- [x] Runnable emulators (automatically selected by rom extension):
- [x] NES emulator (~100 FPS running Legend of Zelda)
- [x] GB/GBC emulator (~100 FPS running Link's Awakening DX (GBC))
- [ ] MSX emulator
- [ ] Sega Master System (SMS) / GameGear (GG) emulator
- [ ] Sega Mega Drive / Genesis emulator
- [ ] SNES emulator
- [ ] SMS / Genesis emulator
- [ ] Doom emulator
- [x] uSD card (FAT) filesystem over SPI
- [x] Memory mapping of selected rom data from storage into raw data partition
(SPIFLASH)
Expand Down
47 changes: 27 additions & 20 deletions components/box-emu-hal/src/spi_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using namespace box_hal;

static spi_device_handle_t spi;
static spi_device_interface_config_t devcfg;

static constexpr size_t pixel_buffer_size = display_width*NUM_ROWS_IN_FRAME_BUFFER;
std::shared_ptr<espp::Display> display;
Expand All @@ -27,7 +28,7 @@ static constexpr int DC_LEVEL_BIT = (1 << (int)espp::display_drivers::Flags::DC_
// This function is called (in irq context!) just before a transmission starts.
// It will set the D/C line to the value indicated in the user field
// (DC_LEVEL_BIT).
static void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
static void IRAM_ATTR lcd_spi_pre_transfer_callback(spi_transaction_t *t)
{
uint32_t user_flags = (uint32_t)(t->user);
bool dc_level = user_flags & DC_LEVEL_BIT;
Expand All @@ -37,7 +38,7 @@ static void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
// This function is called (in irq context!) just after a transmission ends. It
// will indicate to lvgl that the next flush is ready to be done if the
// FLUSH_BIT is set.
static void lcd_spi_post_transfer_callback(spi_transaction_t *t)
static void IRAM_ATTR lcd_spi_post_transfer_callback(spi_transaction_t *t)
{
uint16_t user_flags = (uint32_t)(t->user);
bool should_flush = user_flags & FLUSH_BIT;
Expand All @@ -46,20 +47,6 @@ static void lcd_spi_post_transfer_callback(spi_transaction_t *t)
lv_disp_flush_ready(disp->driver);
}
}

extern "C" void lcd_write(const uint8_t *data, size_t length, uint32_t user_data) {
if (length == 0) {
return;
}
esp_err_t ret;
static spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = length * 8;
t.tx_buffer = data;
t.user = (void*)user_data;
ret=spi_device_polling_transmit(spi, &t);
}

// Transaction descriptors. Declared static so they're not allocated on the
// stack; we need this memory even when this function is finished because the
// SPI driver needs access to it even while we're already calculating the next
Expand All @@ -74,7 +61,7 @@ static void lcd_wait_lines() {
// fmt::print("Waiting for {} queued transactions\n", num_queued_trans);
// Wait for all transactions to be done and get back the results.
while (num_queued_trans) {
ret=spi_device_get_trans_result(spi, &rtrans, 10 / portTICK_PERIOD_MS);
ret = spi_device_get_trans_result(spi, &rtrans, 10 / portTICK_PERIOD_MS);
if (ret != ESP_OK) {
fmt::print("Could not get trans result: {} '{}'\n", ret, esp_err_to_name(ret));
}
Expand All @@ -83,6 +70,27 @@ static void lcd_wait_lines() {
}
}


extern "C" void lcd_write(const uint8_t *data, size_t length, uint32_t user_data) {
if (length == 0) {
return;
}
lcd_wait_lines();
esp_err_t ret;
trans[0].length = length * 8;
trans[0].user = (void*)user_data;
trans[0].tx_buffer = data;
trans[0].flags = 0; // maybe look at the length of data (<=32 bits) and see
// if we should use SPI_TRANS_USE_TXDATA and copy the
// data into the tx_data field
ret = spi_device_queue_trans(spi, &trans[0], 10 / portTICK_PERIOD_MS);
if (ret != ESP_OK) {
fmt::print("Couldn't queue trans: {} '{}'\n", ret, esp_err_to_name(ret));
} else {
num_queued_trans++;
}
}

extern "C" void lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *data, uint32_t user_data) {
// if we haven't waited by now, wait here...
lcd_wait_lines();
Expand Down Expand Up @@ -119,7 +127,7 @@ extern "C" void lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *da
trans[5].tx_buffer = data;
trans[5].length = length*8;
// undo SPI_TRANS_USE_TXDATA flag
trans[5].flags = 0; // SPI_TRANS_DMA_BUFFER_ALIGN_MANUAL;
trans[5].flags = SPI_TRANS_DMA_BUFFER_ALIGN_MANUAL;
// we need to keep the dc bit set, but also add our flags
trans[5].user = (void*)(DC_LEVEL_BIT | user_data);
//Queue all transactions.
Expand Down Expand Up @@ -188,9 +196,8 @@ extern "C" void lcd_init() {
buscfg.sclk_io_num = lcd_sclk;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.max_transfer_sz = display_width * display_height * sizeof(lv_color_t) + 8;
buscfg.max_transfer_sz = pixel_buffer_size * sizeof(lv_color_t) + 10;

static spi_device_interface_config_t devcfg;
memset(&devcfg, 0, sizeof(devcfg));
devcfg.mode = 0;
// devcfg.flags = SPI_DEVICE_NO_RETURN_RESULT;
Expand Down
64 changes: 1 addition & 63 deletions components/gbc/gnuboy/include/gnuboy/gnuboy.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
#ifndef __GNUBOY_H__
#define __GNUBOY_H__

#ifndef DIRSEP
#ifdef DINGOO_NATIVE
#define DIRSEP "\\"
#define DIRSEP_CHAR '\\'
#else /* DINGOO_NATIVE */
/* define Unix style path seperator */
/* probably could do this better with # string literal macro trick ... for now duplicate */
#define DIRSEP "/"
#define DIRSEP_CHAR '/'
#endif /* DINGOO_NATIVE */
#endif /* DIRSEP */
#pragma once

void ev_poll();
void vid_close();
Expand All @@ -21,9 +8,6 @@ void vid_begin();
void vid_end();
void vid_setpal(int i, int r, int g, int b);
void vid_settitle(char *title);
#ifndef GNUBOY_NO_SCREENSHOT
int vid_screenshot(char *filename);
#endif /*GNUBOY_NO_SCREENSHOT */

void sys_sleep(int us);
void *sys_timer();
Expand All @@ -33,27 +17,13 @@ int sys_elapsed(void *in_ptr);
void pcm_init();
int pcm_submit();
void pcm_close();
#ifdef GNUBOY_HARDWARE_VOLUME
void pcm_volume(int volume); /* volume should be specified in percent 0-100 */
#endif /* GNBOY_HARDWARE_VOLUME */

void sys_checkdir(char *path, int wr);
void sys_sanitize(char *s);
void sys_initpath(char *exe);
void doevents();
void die(char *fmt, ...);

#ifndef GNUBOY_NO_PRINTF
#define debug_printf_init()
#define debug_printf printf
#else
void debug_printf_init();
void debug_printf(char *fmt, ...);
#endif /* GNUBOY_HAVE_PRINTF */

/* FIXME this header files is a poor location for the following prototypes */
/*------------------------------------------*/

/* emu.c */
void emu_reset();
void emu_run();
Expand All @@ -63,39 +33,7 @@ void emu_step();
#include "gnuboy/defs.h" /* need byte for below */
void hw_interrupt(byte i, byte mask);

/* palette.c */
void pal_set332();
void pal_expire();
void pal_release(byte n);
byte pal_getcolor(int c, int r, int g, int b);

/* save.c */
#include <stdio.h> /* need FILE for below */
void savestate(FILE *f);
void loadstate(FILE *f);

/* inflate.c */
int unzip (const unsigned char *data, long *p, void (* callback) (unsigned char d));

/* split.c */
int splitline(char **argv, int max, char *line);

/* refresh.c */
void refresh_1(byte *dest, byte *src, byte *pal, int cnt);
void refresh_2(un16 *dest, byte *src, un16 *pal, int cnt);
void refresh_3(byte *dest, byte *src, un32 *pal, int cnt);
void refresh_4(un32 *dest, byte *src, un32 *pal, int cnt);
void refresh_2_3x(un16 *dest, byte *src, un16 *pal, int cnt);
void refresh_3_2x(byte *dest, byte *src, un32 *pal, int cnt);
void refresh_3_3x(byte *dest, byte *src, un32 *pal, int cnt);
void refresh_3_4x(byte *dest, byte *src, un32 *pal, int cnt);
void refresh_4_2x(un32 *dest, byte *src, un32 *pal, int cnt);
void refresh_4_3x(un32 *dest, byte *src, un32 *pal, int cnt);
void refresh_4_4x(un32 *dest, byte *src, un32 *pal, int cnt);

/* path.c */
char *path_search(char *name, char *mode, char *path);

/*------------------------------------------*/

#endif /* __GNUBOY_H__ */
2 changes: 1 addition & 1 deletion components/gbc/gnuboy/include/gnuboy/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct mbc

struct rom
{
byte (* bank)[16384];
byte (*bank)[16384];
char name[20];
int length;
};
Expand Down
Loading

0 comments on commit 7fcd95b

Please sign in to comment.