Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ set(EXTRA_COMPONENT_DIRS
set(NES_COMPONENTS "nofrendo nofrendo-esp32")

### GBC ###
# set(GBC_COMPONENTS "gameboycore")
# set(GBC_COMPONENTS "gnuboy")
set(GBC_COMPONENTS "gnuboy")

### SMS ###
# set(SMS_COMPONENTS "smsplus")
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu-hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES "driver" "esp_lcd" "spi_flash" "nvs_flash" "codec" "display" "display_drivers" "controller" "ads1x15" "qwiicnes" "input_drivers" "ft5x06" "tt21100"
REQUIRES "driver" "heap" "esp_lcd" "esp_psram" "spi_flash" "nvs_flash" "codec" "display" "display_drivers" "controller" "ads1x15" "qwiicnes" "input_drivers" "ft5x06" "tt21100"
)
2 changes: 2 additions & 0 deletions components/box-emu-hal/include/i2s_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ extern "C" {
#endif

void audio_init();
int16_t* get_audio_buffer();
void audio_play_frame(uint8_t *data, uint32_t num_bytes);
void set_audio_volume(int percent);

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions components/box-emu-hal/include/spi_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include <stdint.h>
#include <stddef.h>

//*****************************************************************************
//
Expand All @@ -32,6 +33,7 @@ uint16_t make_color(uint8_t r, uint8_t g, uint8_t b);
void set_pixel(const uint16_t x, const uint16_t y, const uint16_t color);
uint16_t* get_vram0();
uint16_t* get_vram1();
uint8_t* get_frame_buffer();
void delay_us(size_t num_us);
uint16_t reorder_color(uint16_t color);
void lcd_set_drawing_frame(const uint16_t xs, const uint16_t ys, const uint16_t width, const uint16_t height);
Expand Down
14 changes: 14 additions & 0 deletions components/box-emu-hal/src/i2s_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
static i2s_chan_handle_t tx_handle = NULL;
static i2s_chan_handle_t rx_handle = NULL;

static const int AUDIO_BUFFER_SIZE = EXAMPLE_SAMPLE_RATE / 3 + 1;
static int16_t *audio_buffer;

int16_t *get_audio_buffer() {
return audio_buffer;
}

void set_audio_volume(int percent) {
es8311_codec_set_voice_volume(percent);
}

static esp_err_t i2s_driver_init(void)
{
printf("initializing i2s driver...\n");
Expand Down Expand Up @@ -178,6 +189,9 @@ void audio_init() {
i2c_driver_init();
es7210_init_default();
es8311_init_default();

audio_buffer = (int16_t*)heap_caps_malloc(AUDIO_BUFFER_SIZE, MALLOC_CAP_8BIT | MALLOC_CAP_DMA);

initialized = true;
}

Expand Down
89 changes: 25 additions & 64 deletions components/box-emu-hal/src/spi_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,8 @@ static constexpr size_t display_height = 240;
static constexpr size_t pixel_buffer_size = display_width*NUM_ROWS_IN_FRAME_BUFFER;
std::shared_ptr<espp::Display> display;

// for gnuboy
uint16_t* displayBuffer[2];
struct fb
{
uint8_t *ptr;
int w, h;
int pelsize;
int pitch;
int indexed;
struct
{
int l, r;
} cc[4];
int yuv;
int enabled;
int dirty;
};
struct fb fb;
struct obj
{
uint8_t y;
uint8_t x;
uint8_t pat;
uint8_t flags;
};
struct lcd
{
uint8_t vbank[2][8192];
union
{
uint8_t mem[256];
struct obj obj[40];
} oam;
uint8_t pal[128];
};
static struct lcd lcd;
int frame = 0;

static constexpr size_t frame_buffer_size = (256 * 240 * 2);
static uint8_t *frame_buffer;

//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.
Expand All @@ -74,25 +38,29 @@ void lcd_spi_post_transfer_callback(spi_transaction_t *t)
}


// TODO: see if IRAM_ATTR improves the display refresh frequency
// create the lcd_write function
extern "C" void lcd_write(const uint8_t *data, size_t length, uint16_t user_data) {
static const int spi_queue_size = 10;
static spi_transaction_t ts_[spi_queue_size];
static size_t ts_index = 0;
extern "C" void IRAM_ATTR lcd_write(const uint8_t *data, size_t length, uint16_t user_data) {
if (length == 0) {
// oddly the esp-idf-cxx spi driver asserts if we try to send 0 data...
return;
}
esp_err_t ret;
spi_transaction_t t; // declared static so spi driver can still access it
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length=length*8; //Length is in bytes, transaction length is in bits.
t.tx_buffer=data; //Data
t.user=(void*)user_data; //whether or not to flush
ret=spi_device_polling_transmit(spi, &t); //Transmit!
// ret=spi_device_queue_trans(spi, &t, portMAX_DELAY); //Transmit!
// assert(ret==ESP_OK); //Should have had no issues.
//spi_transaction_t t; // declared static so spi driver can still access it
spi_transaction_t *t = &ts_[ts_index];
memset(t, 0, sizeof(*t)); //Zero out the transaction
t->length=length*8; //Length is in bytes, transaction length is in bits.
t->tx_buffer=data; //Data
t->user=(void*)user_data; //whether or not to flush
ret=spi_device_polling_transmit(spi, t); //Transmit!
// ret=spi_device_queue_trans(spi, t, portMAX_DELAY); //Transmit!
if (ret != ESP_OK) {
fmt::print("Could not write to lcd: {} '{}'\n", ret, esp_err_to_name(ret));
}
ts_index++;
if (ts_index >= spi_queue_size) ts_index = 0;
}

#define U16x2toU32(m,l) ((((uint32_t)(l>>8|(l&0xFF)<<8))<<16)|(m>>8|(m&0xFF)<<8))
Expand Down Expand Up @@ -120,11 +88,15 @@ extern "C" void set_pixel(const uint16_t x, const uint16_t y, const uint16_t col
}

extern "C" uint16_t* get_vram0() {
return displayBuffer[0];
return display->vram0();
}

extern "C" uint16_t* get_vram1() {
return displayBuffer[1];
return display->vram1();
}

extern "C" uint8_t* get_frame_buffer() {
return frame_buffer;
}

extern "C" void delay_us(size_t num_us) {
Expand Down Expand Up @@ -182,7 +154,7 @@ extern "C" void lcd_init() {
.mode=0, //SPI mode 0
.clock_speed_hz=60*1000*1000, //Clock out at 60 MHz
.spics_io_num=GPIO_NUM_5, //CS pin
.queue_size=7, //We want to be able to queue 7 transactions at a time
.queue_size=spi_queue_size, //We want to be able to queue 7 transactions at a time
.pre_cb=lcd_spi_pre_transfer_callback,
.post_cb=lcd_spi_post_transfer_callback,
};
Expand Down Expand Up @@ -217,18 +189,7 @@ extern "C" void lcd_init() {
.rotation = espp::Display::Rotation::LANDSCAPE,
.software_rotation_enabled = true,
});

frame_buffer = (uint8_t*)heap_caps_malloc(frame_buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
initialized = true;
// for gnuboy
displayBuffer[0] = display->vram0();
displayBuffer[1] = display->vram1();
memset(&fb, 0, sizeof(fb));
// got these from https://github.com/OtherCrashOverride/go-play/blob/master/gnuboy-go/main/main.c
fb.w = 160;
fb.h = 144;
fb.pelsize = 2;
fb.pitch = fb.w * fb.pelsize;
fb.indexed = 0;
fb.ptr = (uint8_t*)displayBuffer[0];
fb.enabled = 1;
fb.dirty = 0;
}
12 changes: 0 additions & 12 deletions components/gameboycore/CMakeLists.txt

This file was deleted.

82 changes: 0 additions & 82 deletions components/gameboycore/include/gameboycore/alu.h

This file was deleted.

83 changes: 0 additions & 83 deletions components/gameboycore/include/gameboycore/apu.h

This file was deleted.

Loading