Fix reading from ROM
Signed-off-by: Mahyar Koshkouei <mk@deltabeard.com>
This commit is contained in:
+5
-5
@@ -8,10 +8,10 @@ project(RP2040_GBS C CXX)
|
|||||||
# Initialize the Raspberry Pi Pico SDK
|
# Initialize the Raspberry Pi Pico SDK
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
add_executable(RP2040_GBS src/main.c)
|
add_executable(RP2040_GBS src/main.c src/hello-world.c)
|
||||||
target_include_directories(RP2040_GBS PRIVATE inc)
|
target_include_directories(RP2040_GBS PRIVATE inc)
|
||||||
target_link_libraries(RP2040_GBS
|
target_link_libraries(RP2040_GBS
|
||||||
pico_stdlib pico_stdio pico_bootrom pico_multicore
|
pico_stdlib pico_stdio pico_bootrom pico_multicore pico_stdio
|
||||||
hardware_clocks hardware_pio hardware_vreg hardware_pio
|
hardware_clocks hardware_pio hardware_vreg hardware_pio
|
||||||
hardware_sync hardware_pll hardware_spi hardware_irq
|
hardware_sync hardware_pll hardware_spi hardware_irq
|
||||||
pico_binary_info)
|
pico_binary_info)
|
||||||
@@ -22,11 +22,11 @@ target_compile_definitions(RP2040_GBS PRIVATE
|
|||||||
PICO_STDIO_DEFAULT_CRLF=0
|
PICO_STDIO_DEFAULT_CRLF=0
|
||||||
PICO_PRINTF_SUPPORT_FLOAT=0
|
PICO_PRINTF_SUPPORT_FLOAT=0
|
||||||
PICO_PRINTF_SUPPORT_EXPONENTIAL=0
|
PICO_PRINTF_SUPPORT_EXPONENTIAL=0
|
||||||
PICO_PRINTF_SUPPORT_LONG_LONG=0
|
PICO_PRINTF_SUPPORT_LONG_LONG=1
|
||||||
PICO_PRINTF_SUPPORT_PTRDIFF_T=0)
|
PICO_PRINTF_SUPPORT_PTRDIFF_T=0)
|
||||||
|
|
||||||
#pico_set_binary_type(manager copy_to_ram)
|
pico_set_binary_type(RP2040_GBS copy_to_ram)
|
||||||
#pico_set_binary_type(manager no_flash)
|
#pico_set_binary_type(RP2040_GBS no_flash)
|
||||||
pico_enable_stdio_usb(RP2040_GBS 1)
|
pico_enable_stdio_usb(RP2040_GBS 1)
|
||||||
pico_enable_stdio_uart(RP2040_GBS 0)
|
pico_enable_stdio_uart(RP2040_GBS 0)
|
||||||
pico_add_bin_output(RP2040_GBS)
|
pico_add_bin_output(RP2040_GBS)
|
||||||
|
|||||||
+32
-12
@@ -6,17 +6,21 @@
|
|||||||
|
|
||||||
/* RP2040 Headers */
|
/* RP2040 Headers */
|
||||||
#include <hardware/sync.h>
|
#include <hardware/sync.h>
|
||||||
|
#include <pico/stdio.h>
|
||||||
|
#include <hardware/timer.h>
|
||||||
|
#include <hardware/vreg.h>
|
||||||
|
#include <pico/stdlib.h>
|
||||||
|
|
||||||
/* Project headers */
|
/* Project headers */
|
||||||
#include "hedley.h"
|
#include "hedley.h"
|
||||||
#include "peanut_gb.h"
|
#include "peanut_gb.h"
|
||||||
|
|
||||||
static unsigned char rom[32768] = { 0 };
|
extern const unsigned char hello_world_gb[];
|
||||||
|
|
||||||
struct priv_t
|
struct priv_t
|
||||||
{
|
{
|
||||||
/* Pointer to allocated memory holding GB file. */
|
/* Pointer to allocated memory holding GB file. */
|
||||||
uint8_t *rom;
|
const uint8_t *rom;
|
||||||
/* Pointer to allocated memory holding save file. */
|
/* Pointer to allocated memory holding save file. */
|
||||||
uint8_t *cart_ram;
|
uint8_t *cart_ram;
|
||||||
};
|
};
|
||||||
@@ -26,8 +30,8 @@ struct priv_t
|
|||||||
*/
|
*/
|
||||||
uint8_t gb_rom_read(struct gb_s *gb, const uint_fast32_t addr)
|
uint8_t gb_rom_read(struct gb_s *gb, const uint_fast32_t addr)
|
||||||
{
|
{
|
||||||
const struct priv_t * const p = gb->direct.priv;
|
//const struct priv_t * const p = gb->direct.priv;
|
||||||
return p->rom[addr];
|
return hello_world_gb[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,8 +39,9 @@ uint8_t gb_rom_read(struct gb_s *gb, const uint_fast32_t addr)
|
|||||||
*/
|
*/
|
||||||
uint8_t gb_cart_ram_read(struct gb_s *gb, const uint_fast32_t addr)
|
uint8_t gb_cart_ram_read(struct gb_s *gb, const uint_fast32_t addr)
|
||||||
{
|
{
|
||||||
const struct priv_t * const p = gb->direct.priv;
|
return 0xFF;
|
||||||
return p->cart_ram[addr];
|
//const struct priv_t * const p = gb->direct.priv;
|
||||||
|
//return p->cart_ram[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +50,9 @@ uint8_t gb_cart_ram_read(struct gb_s *gb, const uint_fast32_t addr)
|
|||||||
void gb_cart_ram_write(struct gb_s *gb, const uint_fast32_t addr,
|
void gb_cart_ram_write(struct gb_s *gb, const uint_fast32_t addr,
|
||||||
const uint8_t val)
|
const uint8_t val)
|
||||||
{
|
{
|
||||||
const struct priv_t * const p = gb->direct.priv;
|
return;
|
||||||
p->cart_ram[addr] = val;
|
//const struct priv_t * const p = gb->direct.priv;
|
||||||
|
//p->cart_ram[addr] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +79,8 @@ void gb_error(struct gb_s *gb, const enum gb_error_e gb_err, const uint16_t val)
|
|||||||
void gb_serial_tx(struct gb_s *gb, const uint8_t tx)
|
void gb_serial_tx(struct gb_s *gb, const uint8_t tx)
|
||||||
{
|
{
|
||||||
(void) gb;
|
(void) gb;
|
||||||
printf("0x%02X ", tx);
|
putchar_raw(tx);
|
||||||
|
//printf("0x%02X ", tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum gb_serial_rx_ret_e gb_serial_rx(struct gb_s *gb, uint8_t *rx)
|
enum gb_serial_rx_ret_e gb_serial_rx(struct gb_s *gb, uint8_t *rx)
|
||||||
@@ -86,14 +93,27 @@ enum gb_serial_rx_ret_e gb_serial_rx(struct gb_s *gb, uint8_t *rx)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
static struct gb_s gb;
|
static struct gb_s gb;
|
||||||
static struct priv_t priv = { .rom = rom, .cart_ram = NULL };
|
|
||||||
enum gb_init_error_e ret;
|
enum gb_init_error_e ret;
|
||||||
|
|
||||||
puts("Hello World!");
|
{
|
||||||
|
/* The value for VCO set here is meant for least power
|
||||||
|
* consumption. */
|
||||||
|
const unsigned vco = 532000000; /* 266MHz/133MHz */
|
||||||
|
const unsigned div1 = 2, div2 = 1;
|
||||||
|
|
||||||
|
vreg_set_voltage(VREG_VOLTAGE_1_15);
|
||||||
|
sleep_ms(2);
|
||||||
|
set_sys_clock_pll(vco, div1, div2);
|
||||||
|
sleep_ms(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
stdio_init_all();
|
||||||
|
(void)getchar();
|
||||||
|
puts("Starting");
|
||||||
|
|
||||||
/* Initialise context. */
|
/* Initialise context. */
|
||||||
ret = gb_init(&gb, &gb_rom_read, &gb_cart_ram_read,
|
ret = gb_init(&gb, &gb_rom_read, &gb_cart_ram_read,
|
||||||
&gb_cart_ram_write, &gb_error, &priv);
|
&gb_cart_ram_write, &gb_error, NULL);
|
||||||
|
|
||||||
if(ret != GB_INIT_NO_ERROR)
|
if(ret != GB_INIT_NO_ERROR)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user