Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/linker fragments #91

Merged
merged 10 commits into from
Dec 1, 2024
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
Binary file added boxart/metal_gear_solid_gbc.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/shantae.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/metal_gear_solid_gbc.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/shantae.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/star_wars_arcade_32x_genesis.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/super_mario_bros_deluxe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/toy-story-genesis.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/star_wars_arcade_32x_genesis.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/super_mario_bros_deluxe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/toy-story-genesis.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions components/box-emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ idf_component_register(
"hal"
"usb"
"esp_tinyusb"
"spi_flash"
"nvs_flash"
"codec"
"adc"
"aw9523"
Expand Down
8 changes: 3 additions & 5 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <sdkconfig.h>

#include <esp_err.h>
#include <nvs_flash.h>
#include <spi_flash_mmap.h>
#include <esp_partition.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
Expand Down Expand Up @@ -155,7 +153,7 @@ class BoxEmu : public espp::BaseComponent {
int x_offset() const;
int y_offset() const;
const uint16_t *palette() const;
bool video_task_callback(std::mutex &m, std::condition_variable &cv);
bool video_task_callback(std::mutex &m, std::condition_variable &cv, bool &task_notified);

class InputBase {
public:
Expand Down Expand Up @@ -279,7 +277,7 @@ class BoxEmu : public espp::BaseComponent {
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
static constexpr auto sdcard_spi_num = SPI3_HOST;

static constexpr int num_rows_in_framebuffer = 50;
static constexpr int num_rows_in_framebuffer = 30;

Version version_{Version::UNKNOWN};

Expand Down Expand Up @@ -315,7 +313,7 @@ class BoxEmu : public espp::BaseComponent {

// video
std::atomic<VideoSetting> video_setting_{VideoSetting::FIT};
std::shared_ptr<espp::Task> video_task_{nullptr};
std::unique_ptr<espp::Task> video_task_{nullptr};
QueueHandle_t video_queue_{nullptr};

size_t display_width_{espp::EspBox::lcd_width()};
Expand Down
17 changes: 10 additions & 7 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,15 @@ bool BoxEmu::initialize_video() {
logger_.info("initializing video task");

video_queue_ = xQueueCreate(1, sizeof(uint16_t*));
video_task_ = std::make_shared<espp::Task>(espp::Task::Config{
.name = "video task",
.callback = std::bind(&BoxEmu::video_task_callback, this, std::placeholders::_1, std::placeholders::_2),
.stack_size_bytes = 4*1024,
.priority = 20,
.core_id = 1
using namespace std::placeholders;
video_task_ = espp::Task::make_unique({
.callback = std::bind(&BoxEmu::video_task_callback, this, _1, _2, _3),
.task_config = {
.name = "video task",
.stack_size_bytes = 4*1024,
.priority = 20,
.core_id = 1
},
});
video_task_->start();

Expand Down Expand Up @@ -715,7 +718,7 @@ const uint16_t* BoxEmu::palette() const {
return palette_;
}

bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv) {
bool BoxEmu::video_task_callback(std::mutex &m, std::condition_variable& cv, bool &task_notified) {
const void *_frame_ptr;
if (xQueueReceive(video_queue_, &_frame_ptr, portMAX_DELAY) != pdTRUE) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion components/espp
Submodule espp updated 185 files
1 change: 1 addition & 0 deletions components/gbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src" "gnuboy/src"
PRIV_INCLUDE_DIRS "gnuboy/include"
# LDFRAGMENTS "linker.lf"
REQUIRES "box-emu" "statistics"
)

Expand Down
12 changes: 6 additions & 6 deletions components/gbc/gnuboy/src/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void cpu_reset()
/* FIXME: employ common unit to drive whatever_advance(),
(double-speed machine cycles (2MHz) is a good candidate)
handle differences in place */
void IRAM_ATTR div_advance(int cnt)
void div_advance(int cnt)
{
cpu.div += (cnt<<1);
if (cpu.div >= 256)
Expand All @@ -295,7 +295,7 @@ void IRAM_ATTR div_advance(int cnt)
/* FIXME: employ common unit to drive whatever_advance(),
(double-speed machine cycles (2MHz) is a good candidate)
handle differences in place */
void IRAM_ATTR timer_advance(int cnt)
void timer_advance(int cnt)
{
int unit, tima;

Expand Down Expand Up @@ -336,7 +336,7 @@ inline void sound_advance(int cnt)
}

/* cnt - time to emulate, expressed in 2MHz units */
void IRAM_ATTR cpu_timers(int cnt)
void cpu_timers(int cnt)
{
div_advance(cnt << cpu.speed);
timer_advance(cnt << cpu.speed);
Expand All @@ -351,7 +351,7 @@ void IRAM_ATTR cpu_timers(int cnt)
returns number of cycles skipped
*/
/* FIXME: bring cpu_timers() out, make caller advance system */
int IRAM_ATTR cpu_idle(int max)
int cpu_idle(int max)
{
int cnt, unit;

Expand Down Expand Up @@ -397,7 +397,7 @@ int IRAM_ATTR cpu_idle(int max)
Might emulate up to cycles+(11) time units (longest op takes 12
cycles in single-speed mode)
*/
int IRAM_ATTR cpu_emulate(int cycles)
int cpu_emulate(int cycles)
{
int i;
byte op, cbop;
Expand Down Expand Up @@ -970,7 +970,7 @@ int IRAM_ATTR cpu_emulate(int cycles)

#ifndef ASM_CPU_STEP
/* Outdated equivalent of emu.c:emu_step() probably? Doesn't seem to be used. */
int IRAM_ATTR cpu_step(int max)
int cpu_step(int max)
{
int cnt;
if ((cnt = cpu_idle(max))) return cnt;
Expand Down
10 changes: 5 additions & 5 deletions components/gbc/gnuboy/src/hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct hw hw;
* lines that transition from low to high.
*/

void IRAM_ATTR hw_interrupt(byte i, byte mask)
void hw_interrupt(byte i, byte mask)
{
byte oldif = R_IF;
i &= 0x1F & mask;
Expand All @@ -47,7 +47,7 @@ void IRAM_ATTR hw_interrupt(byte i, byte mask)
* stall the cpu are necessary.
*/

void IRAM_ATTR hw_dma(byte b)
void hw_dma(byte b)
{
int i;
addr a;
Expand All @@ -59,7 +59,7 @@ void IRAM_ATTR hw_dma(byte b)



void IRAM_ATTR hw_hdma_cmd(byte c)
void hw_hdma_cmd(byte c)
{
int cnt;
addr sa;
Expand Down Expand Up @@ -90,7 +90,7 @@ void IRAM_ATTR hw_hdma_cmd(byte c)
}


void IRAM_ATTR hw_hdma()
void hw_hdma()
{
int cnt;
addr sa;
Expand All @@ -116,7 +116,7 @@ void IRAM_ATTR hw_hdma()
* interrupt line) if a transition has been made.
*/

void IRAM_ATTR pad_refresh()
void pad_refresh()
{
byte oldp1;
oldp1 = R_P1;
Expand Down
26 changes: 13 additions & 13 deletions components/gbc/gnuboy/src/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static byte *vdest;
static byte pix[8];

__attribute__((optimize("unroll-loops")))
static const byte* IRAM_ATTR get_patpix(int i, int x)
static const byte* get_patpix(int i, int x)
{
const int index = i & 0x3ff; // 1024 entries
const int rotation = i >> 10; // / 1024;
Expand Down Expand Up @@ -151,7 +151,7 @@ static const short DRAM_ATTR wraptable[64] =
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,-32
};

static void IRAM_ATTR tilebuf()
static void tilebuf()
{
int i, cnt;
int base;
Expand Down Expand Up @@ -245,7 +245,7 @@ static void IRAM_ATTR tilebuf()
}


static void IRAM_ATTR bg_scan()
static void bg_scan()
{
int cnt;
byte *src, *dest;
Expand Down Expand Up @@ -309,7 +309,7 @@ static void IRAM_ATTR bg_scan()
*(dest++) = *(src++);
}

static void IRAM_ATTR wnd_scan()
static void wnd_scan()
{
int cnt;
byte *src, *dest;
Expand Down Expand Up @@ -352,7 +352,7 @@ inline static int priused(void *attr)
return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080);
}

static void IRAM_ATTR bg_scan_pri()
static void bg_scan_pri()
{
int cnt, i;
byte *src, *dest;
Expand Down Expand Up @@ -382,7 +382,7 @@ static void IRAM_ATTR bg_scan_pri()
memset(dest, src[i&31]&128, cnt);
}

static void IRAM_ATTR wnd_scan_pri()
static void wnd_scan_pri()
{
int cnt, i;
byte *src, *dest;
Expand All @@ -409,7 +409,7 @@ static void IRAM_ATTR wnd_scan_pri()
}

#ifndef ASM_BG_SCAN_COLOR
static void IRAM_ATTR bg_scan_color()
static void bg_scan_color()
{
int cnt;
byte *src, *dest;
Expand Down Expand Up @@ -437,7 +437,7 @@ static void IRAM_ATTR bg_scan_color()
}
#endif

static void IRAM_ATTR wnd_scan_color()
static void wnd_scan_color()
{
int cnt;
byte *src, *dest;
Expand All @@ -464,7 +464,7 @@ inline static void recolor(byte *buf, byte fill, int cnt)
while (cnt--) *(buf++) |= fill;
}

static void IRAM_ATTR spr_count()
static void spr_count()
{
int i;
struct obj *o;
Expand All @@ -487,7 +487,7 @@ static void IRAM_ATTR spr_count()

static struct vissprite ts[16];

static void IRAM_ATTR spr_enum()
static void spr_enum()
{
int i, j;
struct obj *o;
Expand Down Expand Up @@ -569,7 +569,7 @@ static void IRAM_ATTR spr_enum()

static byte bgdup[256];

static void IRAM_ATTR spr_scan()
static void spr_scan()
{
int i, x;
byte pal, b, ns = NS;
Expand Down Expand Up @@ -647,7 +647,7 @@ extern int frame;
extern uint16_t* displayBuffer[2];
int lastLcdDisabled = 0;

void IRAM_ATTR lcd_refreshline()
void lcd_refreshline()
{
byte *dest;

Expand Down Expand Up @@ -751,7 +751,7 @@ inline void pal_write(int i, byte b)
}
}

void IRAM_ATTR pal_write_dmg(int i, int mapnum, byte d)
void pal_write_dmg(int i, int mapnum, byte d)
{
int j;
int * const cmap = dmg_pal[mapnum & 0x3];
Expand Down
10 changes: 5 additions & 5 deletions components/gbc/gnuboy/src/lcdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* stat_trigger also updates bit 2 of R_STAT to reflect whether LY=LYC.
*/

void IRAM_ATTR stat_trigger()
void stat_trigger()
{
static const int condbits[4] = { 0x08, 0x10, 0x20, 0x00 };
int flag = 0;
Expand All @@ -44,7 +44,7 @@ void IRAM_ATTR stat_trigger()
hw_interrupt(flag, IF_STAT);
}

void IRAM_ATTR stat_write(byte b)
void stat_write(byte b)
{
R_STAT = (R_STAT & 0x07) | (b & 0x78);
if (!hw.cgb && !(R_STAT & 2)) /* DMG STAT write bug => interrupt */
Expand All @@ -61,7 +61,7 @@ void IRAM_ATTR stat_write(byte b)
*/
/* FIXME: function now will only lower vblank interrupt, description
does not match anymore */
static void IRAM_ATTR stat_change(int stat)
static void stat_change(int stat)
{
stat &= 3;
R_STAT = (R_STAT & 0x7C) | stat;
Expand All @@ -72,7 +72,7 @@ static void IRAM_ATTR stat_change(int stat)
}


void IRAM_ATTR lcdc_change(byte b)
void lcdc_change(byte b)
{
byte old = R_LCDC;
R_LCDC = b;
Expand Down Expand Up @@ -122,7 +122,7 @@ void IRAM_ATTR lcdc_change(byte b)
/* lcdc_trans()
Main LCDC emulation routine
*/
void IRAM_ATTR lcdc_trans()
void lcdc_trans()
{
/* FIXME: lacks clarity;
try and break into two switch() blocks
Expand Down
1 change: 0 additions & 1 deletion components/gbc/gnuboy/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <time.h>
#include <ctype.h>

#include "nvs_flash.h"
#include "esp_partition.h"
#include "esp_system.h"
#include "esp_heap_caps.h"
Expand Down
Loading