Skip to content

Commit 7fcd95b

Browse files
authored
Merge pull request #39 from esp-cpp/fix/cart-destructor
fix(cart): made destructor virtual to be overridden by subclasses
2 parents ed1e189 + 3a117c5 commit 7fcd95b

File tree

22 files changed

+389
-1078
lines changed

22 files changed

+389
-1078
lines changed

CMakeLists.txt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,60 @@ set(GBC_COMPONENTS "gbc")
1818
### SMS ###
1919
# set(SMS_COMPONENTS "sms")
2020

21+
### SNES ###
22+
# set(SNES_COMPONENTS "snes")
23+
24+
### MSX ###
25+
# set(MSX_COMPONENTS "msx")
26+
27+
### DOOM ###
28+
# set(DOOM_COMPONENTS "doom")
29+
2130
add_compile_definitions(BOARD_HAS_PSRAM)
2231

32+
# if NES_COMPONENTS is set, add compile definitions for the NES
33+
if(NES_COMPONENTS)
34+
add_compile_definitions(ENABLE_NES)
35+
endif()
36+
37+
# if GBC_COMPONENTS is set, add compile definitions for the GBC
38+
if(GBC_COMPONENTS)
39+
add_compile_definitions(ENABLE_GBC)
40+
endif()
41+
42+
# if SMS_COMPONENTS is set, add compile definitions for the SMS
43+
if(SMS_COMPONENTS)
44+
add_compile_definitions(ENABLE_SMS)
45+
endif()
46+
47+
# if SNES_COMPONENTS is set, add compile definitions for the SNES
48+
if(SNES_COMPONENTS)
49+
add_compile_definitions(ENABLE_SNES)
50+
endif()
51+
52+
# if MSX_COMPONENTS is set, add compile definitions for the MSX
53+
if(MSX_COMPONENTS)
54+
add_compile_definitions(ENABLE_MSX)
55+
endif()
56+
57+
# if DOOM_COMPONENTS is set, add compile definitions for the DOOM
58+
if(DOOM_COMPONENTS)
59+
add_compile_definitions(ENABLE_DOOM)
60+
endif()
61+
62+
# make the components list for the emulators we want
63+
set(EMULATOR_COMPONENTS
64+
${NES_COMPONENTS}
65+
${GBC_COMPONENTS}
66+
${SMS_COMPONENTS}
67+
${SNES_COMPONENTS}
68+
${MSX_COMPONENTS}
69+
${DOOM_COMPONENTS}
70+
)
71+
2372
set(
2473
COMPONENTS
25-
"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"
74+
"main esptool_py esp_lcd esp_psram task format display display_drivers monitor esp-idf-cxx ${EMULATOR_COMPONENTS} box-emu-hal gui menu"
2675
CACHE STRING
2776
"List of components to include"
2877
)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ This project has the following features (still WIP):
5050
- [x] Runnable emulators (automatically selected by rom extension):
5151
- [x] NES emulator (~100 FPS running Legend of Zelda)
5252
- [x] GB/GBC emulator (~100 FPS running Link's Awakening DX (GBC))
53+
- [ ] MSX emulator
54+
- [ ] Sega Master System (SMS) / GameGear (GG) emulator
55+
- [ ] Sega Mega Drive / Genesis emulator
5356
- [ ] SNES emulator
54-
- [ ] SMS / Genesis emulator
57+
- [ ] Doom emulator
5558
- [x] uSD card (FAT) filesystem over SPI
5659
- [x] Memory mapping of selected rom data from storage into raw data partition
5760
(SPIFLASH)

components/box-emu-hal/src/spi_lcd.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using namespace box_hal;
1111

1212
static spi_device_handle_t spi;
13+
static spi_device_interface_config_t devcfg;
1314

1415
static constexpr size_t pixel_buffer_size = display_width*NUM_ROWS_IN_FRAME_BUFFER;
1516
std::shared_ptr<espp::Display> display;
@@ -27,7 +28,7 @@ static constexpr int DC_LEVEL_BIT = (1 << (int)espp::display_drivers::Flags::DC_
2728
// This function is called (in irq context!) just before a transmission starts.
2829
// It will set the D/C line to the value indicated in the user field
2930
// (DC_LEVEL_BIT).
30-
static void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
31+
static void IRAM_ATTR lcd_spi_pre_transfer_callback(spi_transaction_t *t)
3132
{
3233
uint32_t user_flags = (uint32_t)(t->user);
3334
bool dc_level = user_flags & DC_LEVEL_BIT;
@@ -37,7 +38,7 @@ static void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
3738
// This function is called (in irq context!) just after a transmission ends. It
3839
// will indicate to lvgl that the next flush is ready to be done if the
3940
// FLUSH_BIT is set.
40-
static void lcd_spi_post_transfer_callback(spi_transaction_t *t)
41+
static void IRAM_ATTR lcd_spi_post_transfer_callback(spi_transaction_t *t)
4142
{
4243
uint16_t user_flags = (uint32_t)(t->user);
4344
bool should_flush = user_flags & FLUSH_BIT;
@@ -46,20 +47,6 @@ static void lcd_spi_post_transfer_callback(spi_transaction_t *t)
4647
lv_disp_flush_ready(disp->driver);
4748
}
4849
}
49-
50-
extern "C" void lcd_write(const uint8_t *data, size_t length, uint32_t user_data) {
51-
if (length == 0) {
52-
return;
53-
}
54-
esp_err_t ret;
55-
static spi_transaction_t t;
56-
memset(&t, 0, sizeof(t));
57-
t.length = length * 8;
58-
t.tx_buffer = data;
59-
t.user = (void*)user_data;
60-
ret=spi_device_polling_transmit(spi, &t);
61-
}
62-
6350
// Transaction descriptors. Declared static so they're not allocated on the
6451
// stack; we need this memory even when this function is finished because the
6552
// SPI driver needs access to it even while we're already calculating the next
@@ -74,7 +61,7 @@ static void lcd_wait_lines() {
7461
// fmt::print("Waiting for {} queued transactions\n", num_queued_trans);
7562
// Wait for all transactions to be done and get back the results.
7663
while (num_queued_trans) {
77-
ret=spi_device_get_trans_result(spi, &rtrans, 10 / portTICK_PERIOD_MS);
64+
ret = spi_device_get_trans_result(spi, &rtrans, 10 / portTICK_PERIOD_MS);
7865
if (ret != ESP_OK) {
7966
fmt::print("Could not get trans result: {} '{}'\n", ret, esp_err_to_name(ret));
8067
}
@@ -83,6 +70,27 @@ static void lcd_wait_lines() {
8370
}
8471
}
8572

73+
74+
extern "C" void lcd_write(const uint8_t *data, size_t length, uint32_t user_data) {
75+
if (length == 0) {
76+
return;
77+
}
78+
lcd_wait_lines();
79+
esp_err_t ret;
80+
trans[0].length = length * 8;
81+
trans[0].user = (void*)user_data;
82+
trans[0].tx_buffer = data;
83+
trans[0].flags = 0; // maybe look at the length of data (<=32 bits) and see
84+
// if we should use SPI_TRANS_USE_TXDATA and copy the
85+
// data into the tx_data field
86+
ret = spi_device_queue_trans(spi, &trans[0], 10 / portTICK_PERIOD_MS);
87+
if (ret != ESP_OK) {
88+
fmt::print("Couldn't queue trans: {} '{}'\n", ret, esp_err_to_name(ret));
89+
} else {
90+
num_queued_trans++;
91+
}
92+
}
93+
8694
extern "C" void lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *data, uint32_t user_data) {
8795
// if we haven't waited by now, wait here...
8896
lcd_wait_lines();
@@ -119,7 +127,7 @@ extern "C" void lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *da
119127
trans[5].tx_buffer = data;
120128
trans[5].length = length*8;
121129
// undo SPI_TRANS_USE_TXDATA flag
122-
trans[5].flags = 0; // SPI_TRANS_DMA_BUFFER_ALIGN_MANUAL;
130+
trans[5].flags = SPI_TRANS_DMA_BUFFER_ALIGN_MANUAL;
123131
// we need to keep the dc bit set, but also add our flags
124132
trans[5].user = (void*)(DC_LEVEL_BIT | user_data);
125133
//Queue all transactions.
@@ -188,9 +196,8 @@ extern "C" void lcd_init() {
188196
buscfg.sclk_io_num = lcd_sclk;
189197
buscfg.quadwp_io_num = -1;
190198
buscfg.quadhd_io_num = -1;
191-
buscfg.max_transfer_sz = display_width * display_height * sizeof(lv_color_t) + 8;
199+
buscfg.max_transfer_sz = pixel_buffer_size * sizeof(lv_color_t) + 10;
192200

193-
static spi_device_interface_config_t devcfg;
194201
memset(&devcfg, 0, sizeof(devcfg));
195202
devcfg.mode = 0;
196203
// devcfg.flags = SPI_DEVICE_NO_RETURN_RESULT;
Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
#ifndef __GNUBOY_H__
2-
#define __GNUBOY_H__
3-
4-
#ifndef DIRSEP
5-
#ifdef DINGOO_NATIVE
6-
#define DIRSEP "\\"
7-
#define DIRSEP_CHAR '\\'
8-
#else /* DINGOO_NATIVE */
9-
/* define Unix style path seperator */
10-
/* probably could do this better with # string literal macro trick ... for now duplicate */
11-
#define DIRSEP "/"
12-
#define DIRSEP_CHAR '/'
13-
#endif /* DINGOO_NATIVE */
14-
#endif /* DIRSEP */
1+
#pragma once
152

163
void ev_poll();
174
void vid_close();
@@ -21,9 +8,6 @@ void vid_begin();
218
void vid_end();
229
void vid_setpal(int i, int r, int g, int b);
2310
void vid_settitle(char *title);
24-
#ifndef GNUBOY_NO_SCREENSHOT
25-
int vid_screenshot(char *filename);
26-
#endif /*GNUBOY_NO_SCREENSHOT */
2711

2812
void sys_sleep(int us);
2913
void *sys_timer();
@@ -33,27 +17,13 @@ int sys_elapsed(void *in_ptr);
3317
void pcm_init();
3418
int pcm_submit();
3519
void pcm_close();
36-
#ifdef GNUBOY_HARDWARE_VOLUME
37-
void pcm_volume(int volume); /* volume should be specified in percent 0-100 */
38-
#endif /* GNBOY_HARDWARE_VOLUME */
3920

4021
void sys_checkdir(char *path, int wr);
4122
void sys_sanitize(char *s);
4223
void sys_initpath(char *exe);
4324
void doevents();
4425
void die(char *fmt, ...);
4526

46-
#ifndef GNUBOY_NO_PRINTF
47-
#define debug_printf_init()
48-
#define debug_printf printf
49-
#else
50-
void debug_printf_init();
51-
void debug_printf(char *fmt, ...);
52-
#endif /* GNUBOY_HAVE_PRINTF */
53-
54-
/* FIXME this header files is a poor location for the following prototypes */
55-
/*------------------------------------------*/
56-
5727
/* emu.c */
5828
void emu_reset();
5929
void emu_run();
@@ -63,39 +33,7 @@ void emu_step();
6333
#include "gnuboy/defs.h" /* need byte for below */
6434
void hw_interrupt(byte i, byte mask);
6535

66-
/* palette.c */
67-
void pal_set332();
68-
void pal_expire();
69-
void pal_release(byte n);
70-
byte pal_getcolor(int c, int r, int g, int b);
71-
7236
/* save.c */
7337
#include <stdio.h> /* need FILE for below */
7438
void savestate(FILE *f);
7539
void loadstate(FILE *f);
76-
77-
/* inflate.c */
78-
int unzip (const unsigned char *data, long *p, void (* callback) (unsigned char d));
79-
80-
/* split.c */
81-
int splitline(char **argv, int max, char *line);
82-
83-
/* refresh.c */
84-
void refresh_1(byte *dest, byte *src, byte *pal, int cnt);
85-
void refresh_2(un16 *dest, byte *src, un16 *pal, int cnt);
86-
void refresh_3(byte *dest, byte *src, un32 *pal, int cnt);
87-
void refresh_4(un32 *dest, byte *src, un32 *pal, int cnt);
88-
void refresh_2_3x(un16 *dest, byte *src, un16 *pal, int cnt);
89-
void refresh_3_2x(byte *dest, byte *src, un32 *pal, int cnt);
90-
void refresh_3_3x(byte *dest, byte *src, un32 *pal, int cnt);
91-
void refresh_3_4x(byte *dest, byte *src, un32 *pal, int cnt);
92-
void refresh_4_2x(un32 *dest, byte *src, un32 *pal, int cnt);
93-
void refresh_4_3x(un32 *dest, byte *src, un32 *pal, int cnt);
94-
void refresh_4_4x(un32 *dest, byte *src, un32 *pal, int cnt);
95-
96-
/* path.c */
97-
char *path_search(char *name, char *mode, char *path);
98-
99-
/*------------------------------------------*/
100-
101-
#endif /* __GNUBOY_H__ */

components/gbc/gnuboy/include/gnuboy/mem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct mbc
3030

3131
struct rom
3232
{
33-
byte (* bank)[16384];
33+
byte (*bank)[16384];
3434
char name[20];
3535
int length;
3636
};

0 commit comments

Comments
 (0)