diff --git a/CMakeLists.txt b/CMakeLists.txt index fc1f169..f84b8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,10 @@ project(RP2040_GBS C CXX) # Initialize the Raspberry Pi Pico SDK 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_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_sync hardware_pll hardware_spi hardware_irq pico_binary_info) @@ -22,11 +22,11 @@ target_compile_definitions(RP2040_GBS PRIVATE PICO_STDIO_DEFAULT_CRLF=0 PICO_PRINTF_SUPPORT_FLOAT=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_set_binary_type(manager copy_to_ram) -#pico_set_binary_type(manager no_flash) +pico_set_binary_type(RP2040_GBS copy_to_ram) +#pico_set_binary_type(RP2040_GBS no_flash) pico_enable_stdio_usb(RP2040_GBS 1) pico_enable_stdio_uart(RP2040_GBS 0) pico_add_bin_output(RP2040_GBS) diff --git a/src/main.c b/src/main.c index 6ad3dc9..86c8fe4 100644 --- a/src/main.c +++ b/src/main.c @@ -6,17 +6,21 @@ /* RP2040 Headers */ #include +#include +#include +#include +#include /* Project headers */ #include "hedley.h" #include "peanut_gb.h" -static unsigned char rom[32768] = { 0 }; +extern const unsigned char hello_world_gb[]; struct priv_t { /* Pointer to allocated memory holding GB file. */ - uint8_t *rom; + const uint8_t *rom; /* Pointer to allocated memory holding save file. */ 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) { - const struct priv_t * const p = gb->direct.priv; - return p->rom[addr]; + //const struct priv_t * const p = gb->direct.priv; + 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) { - const struct priv_t * const p = gb->direct.priv; - return p->cart_ram[addr]; + return 0xFF; + //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, const uint8_t val) { - const struct priv_t * const p = gb->direct.priv; - p->cart_ram[addr] = val; + return; + //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; - 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) @@ -86,14 +93,27 @@ enum gb_serial_rx_ret_e gb_serial_rx(struct gb_s *gb, uint8_t *rx) int main(void) { static struct gb_s gb; - static struct priv_t priv = { .rom = rom, .cart_ram = NULL }; 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. */ 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) {