From e246af996d3bcb9c62613d0b1477f856dcbc0d9b Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 20 Mar 2019 23:24:11 +0800 Subject: [PATCH 01/73] import from M5Stack-nesemu --- components/nofrendo-esp32/Kconfig.projbuild | 39 +- components/nofrendo-esp32/spi_lcd.c | 544 ++++++++------------ components/nofrendo-esp32/spi_lcd.h | 4 +- components/nofrendo-esp32/video_audio.c | 48 +- components/nofrendo/nes/nes_ppu.c | 2 +- flashrom.sh | 4 +- sdkconfig | 281 ---------- sdkconfig.defaults | 265 ++++++++++ 8 files changed, 534 insertions(+), 653 deletions(-) delete mode 100644 sdkconfig create mode 100644 sdkconfig.defaults diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index bd18b15..013baea 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "Nofrendo ESP32-specific configuration" choice NOFRENDO_HARDWARE prompt "Hardware to run on" - default ESP_WROVER_KIT_V2_ILI + default ESP_WROVER_KIT_V2 help This emulator can run on various types of hardware. Select what you have here. @@ -12,6 +12,9 @@ config HW_WROVERKIT_V1 config HW_WROVERKIT_V2 bool "ESP_Wrover_Kit v2 (black PCB)" +config HW_M5STACK + bool "M5Stack" + config HW_CUSTOM bool "Custom hardware" @@ -41,43 +44,49 @@ config HW_LCD_TYPE default 0 if HW_WROVERKIT_V1 default 0 if HW_LCD_TYPE_ILI default 1 if HW_LCD_TYPE_ST + default 2 if HW_M5STACK +config HW_LCD_MISO_GPIO_CUST + int "LCD MISO pin" + depends on HW_CUSTOM + range 1 35 + default 19 config HW_LCD_MOSI_GPIO_CUST int "LCD MOSI pin" depends on HW_CUSTOM range 1 35 - default 25 + default 23 config HW_LCD_CLK_GPIO_CUST int "LCD CLK pin" depends on HW_CUSTOM range 1 35 - default 23 + default 18 config HW_LCD_CS_GPIO_CUST int "LCD CS pin" depends on HW_CUSTOM range 1 35 - default 19 + default 14 config HW_LCD_DC_GPIO_CUST int "LCD DC pin" depends on HW_CUSTOM range 1 35 - default 22 + default 27 -config HW_LCD_RESET_GPIO_CUST - int "LCD RESET pin" +config HW_LCD_RST_GPIO_CUST + int "LCD RST pin" depends on HW_CUSTOM range 1 35 - default 21 + default 33 config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" depends on HW_CUSTOM range 1 35 - default 5 + default 32 config HW_INV_BL_CUST bool "Invert backlight output" @@ -90,41 +99,49 @@ config HW_INV_BL default HW_INBV_BL_CUST if HW_CUSTOM default n if HW_WROVERKIT_V1 default y if HW_WROVERKIT_V2 + default n if HW_M5STACK config HW_LCD_MISO_GPIO int default HW_LCD_MISO_GPIO_CUST if HW_CUSTOM default 25 if HW_WROVERKIT + default 19 if HW_M5STACK config HW_LCD_MOSI_GPIO int default HW_LCD_MOSI_GPIO_CUST if HW_CUSTOM default 23 if HW_WROVERKIT + default 23 if HW_M5STACK config HW_LCD_CLK_GPIO int default HW_LCD_CLK_GPIO_CUST if HW_CUSTOM default 19 if HW_WROVERKIT + default 18 if HW_M5STACK config HW_LCD_CS_GPIO int default HW_LCD_CS_GPIO_CUST if HW_CUSTOM default 22 if HW_WROVERKIT + default 14 if HW_M5STACK config HW_LCD_DC_GPIO int default HW_LCD_DC_GPIO_CUST if HW_CUSTOM default 21 if HW_WROVERKIT + default 27 if HW_M5STACK -config HW_LCD_RESET_GPIO +config HW_LCD_RST_GPIO int - default HW_LCD_RESET_GPIO_CUST if HW_CUSTOM + default HW_LCD_RST_GPIO_CUST if HW_CUSTOM default 18 if HW_WROVERKIT + default 33 if HW_M5STACK config HW_LCD_BL_GPIO int default HW_LCD_BL_GPIO_CUST if HW_CUSTOM default 5 if HW_WROVERKIT + default 32 if HW_M5STACK config SOUND_ENA diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 048e32c..ac87286 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -24,411 +24,289 @@ #include "soc/spi_reg.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "driver/gpio.h" #include "driver/periph_ctrl.h" #include "spi_lcd.h" +#include "driver/spi_master.h" +#include "driver/ledc.h" #define PIN_NUM_MISO CONFIG_HW_LCD_MISO_GPIO #define PIN_NUM_MOSI CONFIG_HW_LCD_MOSI_GPIO -#define PIN_NUM_CLK CONFIG_HW_LCD_CLK_GPIO -#define PIN_NUM_CS CONFIG_HW_LCD_CS_GPIO -#define PIN_NUM_DC CONFIG_HW_LCD_DC_GPIO -#define PIN_NUM_RST CONFIG_HW_LCD_RESET_GPIO -#define PIN_NUM_BCKL CONFIG_HW_LCD_BL_GPIO -#define LCD_SEL_CMD() GPIO.out_w1tc = (1 << PIN_NUM_DC) // Low to send command -#define LCD_SEL_DATA() GPIO.out_w1ts = (1 << PIN_NUM_DC) // High to send data -#define LCD_RST_SET() GPIO.out_w1ts = (1 << PIN_NUM_RST) -#define LCD_RST_CLR() GPIO.out_w1tc = (1 << PIN_NUM_RST) - -#if CONFIG_HW_INV_BL -#define LCD_BKG_ON() GPIO.out_w1tc = (1 << PIN_NUM_BCKL) // Backlight ON -#define LCD_BKG_OFF() GPIO.out_w1ts = (1 << PIN_NUM_BCKL) //Backlight OFF -#else -#define LCD_BKG_ON() GPIO.out_w1ts = (1 << PIN_NUM_BCKL) // Backlight ON -#define LCD_BKG_OFF() GPIO.out_w1tc = (1 << PIN_NUM_BCKL) //Backlight OFF -#endif - -#define SPI_NUM 0x3 +#define PIN_NUM_CLK CONFIG_HW_LCD_CLK_GPIO +#define PIN_NUM_CS CONFIG_HW_LCD_CS_GPIO +#define PIN_NUM_DC CONFIG_HW_LCD_DC_GPIO +#define PIN_NUM_RST CONFIG_HW_LCD_RST_GPIO +#define PIN_NUM_BL CONFIG_HW_LCD_BL_GPIO + +#define SPI_NUM 0x3 #define LCD_TYPE_ILI 0 #define LCD_TYPE_ST 1 +#define LCD_SEL_CMD() gpio_set_level(PIN_NUM_DC, 0) // Low to send command +#define LCD_SEL_DATA() gpio_set_level(PIN_NUM_DC, 1) // High to send data +#define LCD_RST_SET() gpio_set_level(PIN_NUM_RST, 1) +#define LCD_RST_CLR() gpio_set_level(PIN_NUM_RST, 0) -static void spi_write_byte(const uint8_t data){ - SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 0x7, SPI_USR_MOSI_DBITLEN_S); - WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), data); - SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR); - while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR); -} - -static void LCD_WriteCommand(const uint8_t cmd) +/* + The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. +*/ +typedef struct { - LCD_SEL_CMD(); - spi_write_byte(cmd); + uint8_t cmd; + uint8_t data[16]; + uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds. +} lcd_init_cmd_t; + +spi_device_handle_t spi; + +DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[] = { + {0xEF, {0x03, 0x80, 0x02}, 3}, + {0xCF, {0x00, 0XC1, 0X30}, 3}, + {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, + {0xE8, {0x85, 0x00, 0x78}, 3}, + {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, + {0xF7, {0x20}, 1}, + {0xEA, {0x00, 0x00}, 2}, + {0xC0, {0x23}, 1}, + {0xC1, {0x10}, 1}, + {0xC5, {0x3e, 0x28}, 2}, + {0xC7, {0x86}, 1}, + // {0x36, {0x48}, 1}, + {0x36, {0x08}, 1}, + {0x3A, {0x55}, 1}, + // {0xB1, {0x00, 0x18}, 2}, + {0xB1, {0x00, 0x1B}, 2}, + {0xB6, {0x08, 0x82, 0x27}, 3}, + {0xF2, {0x00}, 1}, + {0x26, {0x01}, 1}, + {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, + {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, + + // {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, + // {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, + // {0x2C, {0}, 0}, + // {0xB7, {0x07}, 1}, + {0x11, {0}, 0x80}, + {0x29, {0}, 0x80}, + {0, {0}, 0xff}, +}; + +//Send a command to the LCD. Uses spi_device_transmit, which waits until the transfer is complete. +void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd) +{ + esp_err_t ret; + spi_transaction_t t; + memset(&t, 0, sizeof(t)); //Zero out the transaction + t.length = 8; //Command is 8 bits + t.tx_buffer = &cmd; //The data is the cmd itself + t.user = (void *)0; //D/C needs to be set to 0 + ret = spi_device_transmit(spi, &t); //Transmit! + assert(ret == ESP_OK); //Should have had no issues. } -static void LCD_WriteData(const uint8_t data) +//Send data to the LCD. Uses spi_device_transmit, which waits until the transfer is complete. +void lcd_data(spi_device_handle_t spi, const uint8_t *data, int len) { - LCD_SEL_DATA(); - spi_write_byte(data); + esp_err_t ret; + spi_transaction_t t; + if (len == 0) + return; //no need to send anything + memset(&t, 0, sizeof(t)); //Zero out the transaction + t.length = len * 8; //Len is in bytes, transaction length is in bits. + t.tx_buffer = data; //Data + t.user = (void *)1; //D/C needs to be set to 1 + ret = spi_device_transmit(spi, &t); //Transmit! + assert(ret == ESP_OK); //Should have had no issues. } +//------ -static void ILI9341_INITIAL () +//Initialize the display +void lcd_gpio_init() { - LCD_BKG_ON(); - //------------------------------------Reset Sequence-----------------------------------------// - - LCD_RST_SET(); - ets_delay_us(100000); + //Initialize non-SPI GPIOs + gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT); + gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT); + //Reset the display LCD_RST_CLR(); - ets_delay_us(200000); - + vTaskDelay(100 / portTICK_RATE_MS); LCD_RST_SET(); - ets_delay_us(200000); - - -#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ILI) - //************* Start Initial Sequence **********// - LCD_WriteCommand(0xCF); - LCD_WriteData(0x00); - LCD_WriteData(0x83); - LCD_WriteData(0X30); - - LCD_WriteCommand(0xED); - LCD_WriteData(0x64); - LCD_WriteData(0x03); - LCD_WriteData(0X12); - LCD_WriteData(0X81); - - LCD_WriteCommand(0xE8); - LCD_WriteData(0x85); - LCD_WriteData(0x01); //i - LCD_WriteData(0x79); //i - - LCD_WriteCommand(0xCB); - LCD_WriteData(0x39); - LCD_WriteData(0x2C); - LCD_WriteData(0x00); - LCD_WriteData(0x34); - LCD_WriteData(0x02); - - LCD_WriteCommand(0xF7); - LCD_WriteData(0x20); - - LCD_WriteCommand(0xEA); - LCD_WriteData(0x00); - LCD_WriteData(0x00); - - LCD_WriteCommand(0xC0); //Power control - LCD_WriteData(0x26); //i //VRH[5:0] - - LCD_WriteCommand(0xC1); //Power control - LCD_WriteData(0x11); //i //SAP[2:0];BT[3:0] - - LCD_WriteCommand(0xC5); //VCM control - LCD_WriteData(0x35); //i - LCD_WriteData(0x3E); //i - - LCD_WriteCommand(0xC7); //VCM control2 - LCD_WriteData(0xBE); //i //»òÕß B1h - - LCD_WriteCommand(0x36); // Memory Access Control - LCD_WriteData(0x28); //i //was 0x48 - - LCD_WriteCommand(0x3A); - LCD_WriteData(0x55); - - LCD_WriteCommand(0xB1); - LCD_WriteData(0x00); - LCD_WriteData(0x1B); //18 - - LCD_WriteCommand(0xF2); // 3Gamma Function Disable - LCD_WriteData(0x08); - - LCD_WriteCommand(0x26); //Gamma curve selected - LCD_WriteData(0x01); - - LCD_WriteCommand(0xE0); //Set Gamma - LCD_WriteData(0x1F); - LCD_WriteData(0x1A); - LCD_WriteData(0x18); - LCD_WriteData(0x0A); - LCD_WriteData(0x0F); - LCD_WriteData(0x06); - LCD_WriteData(0x45); - LCD_WriteData(0X87); - LCD_WriteData(0x32); - LCD_WriteData(0x0A); - LCD_WriteData(0x07); - LCD_WriteData(0x02); - LCD_WriteData(0x07); - LCD_WriteData(0x05); - LCD_WriteData(0x00); - - LCD_WriteCommand(0XE1); //Set Gamma - LCD_WriteData(0x00); - LCD_WriteData(0x25); - LCD_WriteData(0x27); - LCD_WriteData(0x05); - LCD_WriteData(0x10); - LCD_WriteData(0x09); - LCD_WriteData(0x3A); - LCD_WriteData(0x78); - LCD_WriteData(0x4D); - LCD_WriteData(0x05); - LCD_WriteData(0x18); - LCD_WriteData(0x0D); - LCD_WriteData(0x38); - LCD_WriteData(0x3A); - LCD_WriteData(0x1F); - - LCD_WriteCommand(0x2A); - LCD_WriteData(0x00); - LCD_WriteData(0x00); - LCD_WriteData(0x00); - LCD_WriteData(0xEF); - - LCD_WriteCommand(0x2B); - LCD_WriteData(0x00); - LCD_WriteData(0x00); - LCD_WriteData(0x01); - LCD_WriteData(0x3f); - LCD_WriteCommand(0x2C); - - LCD_WriteCommand(0xB7); - LCD_WriteData(0x07); - - LCD_WriteCommand(0xB6); // Display Function Control - LCD_WriteData(0x0A); //8 82 27 - LCD_WriteData(0x82); - LCD_WriteData(0x27); - LCD_WriteData(0x00); - - //LCD_WriteCommand(0xF6); //not there - //LCD_WriteData(0x01); - //LCD_WriteData(0x30); - -#endif -#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST) - -//212 -//122 - LCD_WriteCommand(0x36); - LCD_WriteData((1<<5)|(1<<6)); //MV 1, MX 1 - - LCD_WriteCommand(0x3A); - LCD_WriteData(0x55); - - LCD_WriteCommand(0xB2); - LCD_WriteData(0x0c); - LCD_WriteData(0x0c); - LCD_WriteData(0x00); - LCD_WriteData(0x33); - LCD_WriteData(0x33); - - LCD_WriteCommand(0xB7); - LCD_WriteData(0x35); - - LCD_WriteCommand(0xBB); - LCD_WriteData(0x2B); - - LCD_WriteCommand(0xC0); - LCD_WriteData(0x2C); - - LCD_WriteCommand(0xC2); - LCD_WriteData(0x01); - LCD_WriteData(0xFF); - - LCD_WriteCommand(0xC3); - LCD_WriteData(0x11); - - LCD_WriteCommand(0xC4); - LCD_WriteData(0x20); - - LCD_WriteCommand(0xC6); - LCD_WriteData(0x0f); - - LCD_WriteCommand(0xD0); - LCD_WriteData(0xA4); - LCD_WriteData(0xA1); - - LCD_WriteCommand(0xE0); - LCD_WriteData(0xD0); - LCD_WriteData(0x00); - LCD_WriteData(0x05); - LCD_WriteData(0x0E); - LCD_WriteData(0x15); - LCD_WriteData(0x0D); - LCD_WriteData(0x37); - LCD_WriteData(0x43); - LCD_WriteData(0x47); - LCD_WriteData(0x09); - LCD_WriteData(0x15); - LCD_WriteData(0x12); - LCD_WriteData(0x16); - LCD_WriteData(0x19); - - LCD_WriteCommand(0xE1); - LCD_WriteData(0xD0); - LCD_WriteData(0x00); - LCD_WriteData(0x05); - LCD_WriteData(0x0D); - LCD_WriteData(0x0C); - LCD_WriteData(0x06); - LCD_WriteData(0x2D); - LCD_WriteData(0x44); - LCD_WriteData(0x40); - LCD_WriteData(0x0E); - LCD_WriteData(0x1C); - LCD_WriteData(0x18); - LCD_WriteData(0x16); - LCD_WriteData(0x19); - -#endif - - - LCD_WriteCommand(0x11); //Exit Sleep - ets_delay_us(100000); - LCD_WriteCommand(0x29); //Display on - ets_delay_us(100000); - + vTaskDelay(100 / portTICK_RATE_MS); +} +void lcd_init_seq(spi_device_handle_t spi) +{ + int cmd = 0; + const lcd_init_cmd_t *lcd_init_cmds; + + lcd_init_cmds = ili_init_cmds; + + //Send all the commands + while (lcd_init_cmds[cmd].databytes != 0xff) + { + lcd_cmd(spi, lcd_init_cmds[cmd].cmd); + lcd_data(spi, lcd_init_cmds[cmd].data, lcd_init_cmds[cmd].databytes & 0x1F); + if (lcd_init_cmds[cmd].databytes & 0x80) + { + vTaskDelay(100 / portTICK_RATE_MS); + } + cmd++; + } } -//.............LCD API END---------- -static void ili_gpio_init() +void lcd_spi_pre_transfer_callback(spi_transaction_t *t) { - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U,2); //DC PIN - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO18_U,2); //RESET PIN - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U,2); //BKL PIN - WRITE_PERI_REG(GPIO_ENABLE_W1TS_REG, BIT21|BIT18|BIT5); + int dc = (int)t->user; + gpio_set_level(PIN_NUM_DC, dc); } -static void spi_master_init() +void lcd_setBrightness(int duty) { - periph_module_enable(PERIPH_VSPI_MODULE); - periph_module_enable(PERIPH_SPI_DMA_MODULE); - - ets_printf("lcd spi pin mux init ...\r\n"); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U,2); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO23_U,2); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U,2); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO25_U,2); - WRITE_PERI_REG(GPIO_ENABLE_W1TS_REG, BIT19|BIT23|BIT22); - - ets_printf("lcd spi signal init\r\n"); - gpio_matrix_in(PIN_NUM_MISO, VSPIQ_IN_IDX,0); - gpio_matrix_out(PIN_NUM_MOSI, VSPID_OUT_IDX,0,0); - gpio_matrix_out(PIN_NUM_CLK, VSPICLK_OUT_IDX,0,0); - gpio_matrix_out(PIN_NUM_CS, VSPICS0_OUT_IDX,0,0); - ets_printf("Hspi config\r\n"); - - CLEAR_PERI_REG_MASK(SPI_SLAVE_REG(SPI_NUM), SPI_TRANS_DONE << 5); - SET_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_CS_SETUP); - CLEAR_PERI_REG_MASK(SPI_PIN_REG(SPI_NUM), SPI_CK_IDLE_EDGE); - CLEAR_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_CK_OUT_EDGE); - CLEAR_PERI_REG_MASK(SPI_CTRL_REG(SPI_NUM), SPI_WR_BIT_ORDER); - CLEAR_PERI_REG_MASK(SPI_CTRL_REG(SPI_NUM), SPI_RD_BIT_ORDER); - CLEAR_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_DOUTDIN); - WRITE_PERI_REG(SPI_USER1_REG(SPI_NUM), 0); - SET_PERI_REG_BITS(SPI_CTRL2_REG(SPI_NUM), SPI_MISO_DELAY_MODE, 0, SPI_MISO_DELAY_MODE_S); - CLEAR_PERI_REG_MASK(SPI_SLAVE_REG(SPI_NUM), SPI_SLAVE_MODE); - - WRITE_PERI_REG(SPI_CLOCK_REG(SPI_NUM), (1 << SPI_CLKCNT_N_S) | (1 << SPI_CLKCNT_L_S));//40MHz - //WRITE_PERI_REG(SPI_CLOCK_REG(SPI_NUM), SPI_CLK_EQU_SYSCLK); // 80Mhz - - SET_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_CS_SETUP | SPI_CS_HOLD | SPI_USR_MOSI); - SET_PERI_REG_MASK(SPI_CTRL2_REG(SPI_NUM), ((0x4 & SPI_MISO_DELAY_NUM) << SPI_MISO_DELAY_NUM_S)); - CLEAR_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_USR_COMMAND); - SET_PERI_REG_BITS(SPI_USER2_REG(SPI_NUM), SPI_USR_COMMAND_BITLEN, 0, SPI_USR_COMMAND_BITLEN_S); - CLEAR_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_USR_ADDR); - SET_PERI_REG_BITS(SPI_USER1_REG(SPI_NUM), SPI_USR_ADDR_BITLEN, 0, SPI_USR_ADDR_BITLEN_S); - CLEAR_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_USR_MISO); - SET_PERI_REG_MASK(SPI_USER_REG(SPI_NUM), SPI_USR_MOSI); - char i; - for (i = 0; i < 16; ++i) { - WRITE_PERI_REG((SPI_W0_REG(SPI_NUM) + (i << 2)), 0); - } +#define LEDC_HS_TIMER LEDC_TIMER_0 +#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE +#define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0 +#define LEDC_TEST_DUTY (10) + + ledc_timer_config_t ledc_timer = { + .bit_num = LEDC_TIMER_10_BIT, // resolution of PWM duty + .freq_hz = 5000, // frequency of PWM signal + .speed_mode = LEDC_HS_MODE, // timer mode + .timer_num = LEDC_HS_TIMER // timer index + }; + // Set configuration of timer0 for high speed channels + ledc_timer_config(&ledc_timer); + + ledc_channel_config_t ledc_channel = + { + .channel = LEDC_HS_CH0_CHANNEL, + .duty = 0, + .gpio_num = PIN_NUM_BL, + .speed_mode = LEDC_HS_MODE, + .timer_sel = LEDC_HS_TIMER}; + ledc_channel_config(&ledc_channel); + + ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, duty); + ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel); } -#define U16x2toU32(m,l) ((((uint32_t)(l>>8|(l&0xFF)<<8))<<16)|(m>>8|(m&0xFF)<<8)) +#define U16x2toU32(m, l) ((((uint32_t)(l >> 8 | (l & 0xFF) << 8)) << 16) | (m >> 8 | (m & 0xFF) << 8)) extern uint16_t myPalette[]; -void ili9341_write_frame(const uint16_t xs, const uint16_t ys, const uint16_t width, const uint16_t height, const uint8_t * data[]){ +void lcd_write_frame(const uint16_t xs, const uint16_t ys, const uint16_t width, const uint16_t height, const uint8_t *data[]) +{ int x, y; int i; uint16_t x1, y1; uint32_t xv, yv, dc; uint32_t temp[16]; dc = (1 << PIN_NUM_DC); - - for (y=0; y 32-bit (16 bit r+l) for (int i=n-1; i>=0; i--) { - audio_frame[i*2+1]=audio_frame[i]; - audio_frame[i*2]=audio_frame[i]; + audio_frame[i] = audio_frame[i] + 0x8000; + // audio_frame[i*2+1] = audio_frame[i] + 0x8000; + // audio_frame[i*2] = audio_frame[i] + 0x8000; } - i2s_write_bytes(0, audio_frame, 4*n, portMAX_DELAY); + i2s_write_bytes(0, (const char *)audio_frame, 2*n, portMAX_DELAY); left-=n; } #endif @@ -103,26 +105,26 @@ static void osd_stopsound(void) static int osd_init_sound(void) { #if CONFIG_SOUND_ENA - audio_frame=malloc(4*DEFAULT_FRAGSIZE); - i2s_config_t cfg={ - .mode=I2S_MODE_DAC_BUILT_IN|I2S_MODE_TX|I2S_MODE_MASTER, - .sample_rate=DEFAULT_SAMPLERATE, - .bits_per_sample=I2S_BITS_PER_SAMPLE_16BIT, - .channel_format=I2S_CHANNEL_FMT_RIGHT_LEFT, - .communication_format=I2S_COMM_FORMAT_I2S_MSB, - .intr_alloc_flags=0, - .dma_buf_count=4, - .dma_buf_len=512 + audio_frame = malloc(2 * DEFAULT_FRAGSIZE); + i2s_config_t cfg = { + .mode = I2S_MODE_DAC_BUILT_IN | I2S_MODE_TX | I2S_MODE_MASTER, + .sample_rate = DEFAULT_SAMPLERATE, + .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, + .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, + .communication_format = I2S_COMM_FORMAT_I2S_MSB, + .intr_alloc_flags = 0, + .dma_buf_count = 2, + .dma_buf_len = 512 }; - i2s_driver_install(0, &cfg, 4, &queue); + i2s_driver_install(0, &cfg, 2, &queue); i2s_set_pin(0, NULL); - i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN); + // i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN); + i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); //I2S enables *both* DAC channels; we only need DAC1. //ToDo: still needed now I2S supports set_dac_mode? - CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_DAC_XPD_FORCE_M); - CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC_M); - + // CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_DAC_XPD_FORCE_M); + // CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_XPD_DAC_M); #endif audio_callback = NULL; @@ -253,7 +255,7 @@ static void videoTask(void *arg) { while(1) { // xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30 xQueueReceive(vidQueue, &bmp, portMAX_DELAY); - ili9341_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line); + lcd_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line); } } @@ -279,7 +281,7 @@ void osd_getinput(void) int x; oldb=b; event_t evh; -// printf("Input: %x\n", b); + // printf("Input: %x\n", b); for (x=0; x<16; x++) { if (chg&1) { evh=event_get(ev[x]); @@ -325,8 +327,8 @@ int osd_init() if (osd_init_sound()) return -1; - ili9341_init(); - ili9341_write_frame(0,0,320,240,NULL); + lcd_init(); + lcd_write_frame(0,0,320,240,NULL); vidQueue=xQueueCreate(1, sizeof(bitmap_t *)); xTaskCreatePinnedToCore(&videoTask, "videoTask", 2048, NULL, 5, NULL, 1); osd_initinput(); diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 9a6875b..65af465 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -787,7 +787,7 @@ typedef struct obj_s static void ppu_renderoam(uint8 *vidbuf, int scanline) { uint8 *buf_ptr; - uint32 vram_offset, savecol[2]; + uint32 vram_offset, savecol[2] = {0}; int sprite_num, spritecount; obj_t *sprite_ptr; uint8 sprite_height; diff --git a/flashrom.sh b/flashrom.sh index ad760e2..dc5dfb6 100755 --- a/flashrom.sh +++ b/flashrom.sh @@ -1,3 +1,3 @@ #!/bin/bash -. ${IDF_PATH}/add_path.sh -esptool.py --chip esp32 --port "/dev/ttyUSB1" --baud $((230400*4)) write_flash -fs 4MB 0x100000 "$1" +# . ${IDF_PATH}/add_path.sh +esptool.py --chip esp32 --port "/dev/cu.SLAB_USBtoUART" --baud $((230400*4)) write_flash -fs 4MB 0x100000 "$1" diff --git a/sdkconfig b/sdkconfig deleted file mode 100644 index 70f420f..0000000 --- a/sdkconfig +++ /dev/null @@ -1,281 +0,0 @@ -# -# Automatically generated file; DO NOT EDIT. -# Espressif IoT Development Framework Configuration -# - -# -# SDK tool configuration -# -CONFIG_TOOLPREFIX="xtensa-esp32-elf-" -CONFIG_PYTHON="python" - -# -# Bootloader config -# -# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set -CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y -# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set -CONFIG_LOG_BOOTLOADER_LEVEL=2 - -# -# Security features -# -# CONFIG_SECURE_BOOT_ENABLED is not set -# CONFIG_FLASH_ENCRYPTION_ENABLED is not set - -# -# Serial flasher config -# -CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB1" -# CONFIG_ESPTOOLPY_BAUD_115200B is not set -# CONFIG_ESPTOOLPY_BAUD_230400B is not set -CONFIG_ESPTOOLPY_BAUD_921600B=y -# CONFIG_ESPTOOLPY_BAUD_2MB is not set -# CONFIG_ESPTOOLPY_BAUD_OTHER is not set -CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 -CONFIG_ESPTOOLPY_BAUD=921600 -CONFIG_ESPTOOLPY_COMPRESSED=y -# CONFIG_FLASHMODE_QIO is not set -# CONFIG_FLASHMODE_QOUT is not set -CONFIG_FLASHMODE_DIO=y -# CONFIG_FLASHMODE_DOUT is not set -CONFIG_ESPTOOLPY_FLASHMODE="dio" -# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set -CONFIG_ESPTOOLPY_FLASHFREQ_40M=y -# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set -# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set -CONFIG_ESPTOOLPY_FLASHFREQ="40m" -# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set -CONFIG_ESPTOOLPY_FLASHSIZE="4MB" -CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y -CONFIG_ESPTOOLPY_BEFORE_RESET=y -# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set -CONFIG_ESPTOOLPY_BEFORE="default_reset" -CONFIG_ESPTOOLPY_AFTER_RESET=y -# CONFIG_ESPTOOLPY_AFTER_NORESET is not set -CONFIG_ESPTOOLPY_AFTER="hard_reset" -# CONFIG_MONITOR_BAUD_9600B is not set -# CONFIG_MONITOR_BAUD_57600B is not set -CONFIG_MONITOR_BAUD_115200B=y -# CONFIG_MONITOR_BAUD_230400B is not set -# CONFIG_MONITOR_BAUD_921600B is not set -# CONFIG_MONITOR_BAUD_2MB is not set -# CONFIG_MONITOR_BAUD_OTHER is not set -CONFIG_MONITOR_BAUD_OTHER_VAL=115200 -CONFIG_MONITOR_BAUD=115200 - -# -# Nofrendo ESP32-specific configuration -# -# CONFIG_HW_WROVERKIT_V1 is not set -CONFIG_HW_WROVERKIT_V2=y -# CONFIG_HW_CUSTOM is not set -CONFIG_HW_LCD_TYPE_ILI=y -# CONFIG_HW_LCD_TYPE_ST is not set -CONFIG_HW_WROVERKIT=y -CONFIG_HW_LCD_TYPE=0 -CONFIG_HW_INV_BL=y -CONFIG_HW_LCD_MISO_GPIO=25 -CONFIG_HW_LCD_MOSI_GPIO=23 -CONFIG_HW_LCD_CLK_GPIO=19 -CONFIG_HW_LCD_CS_GPIO=22 -CONFIG_HW_LCD_DC_GPIO=21 -CONFIG_HW_LCD_RESET_GPIO=18 -CONFIG_HW_LCD_BL_GPIO=5 -# CONFIG_SOUND_ENA is not set -CONFIG_HW_PSX_ENA=y -CONFIG_HW_PSX_CLK=14 -CONFIG_HW_PSX_DAT=27 -CONFIG_HW_PSX_ATT=16 -CONFIG_HW_PSX_CMD=2 - -# -# Partition Table -# -# CONFIG_PARTITION_TABLE_SINGLE_APP is not set -# CONFIG_PARTITION_TABLE_TWO_OTA is not set -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 -CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" -CONFIG_APP_OFFSET=0x10000 -CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set - -# -# Component config -# -# CONFIG_AWS_IOT_SDK is not set -# CONFIG_BT_ENABLED is not set -CONFIG_BT_RESERVE_DRAM=0 - -# -# ESP32-specific -# -# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set -# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set -CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y -CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 -CONFIG_MEMMAP_SMP=y -# CONFIG_MEMMAP_TRACEMEM is not set -# CONFIG_MEMMAP_TRACEMEM_TWOBANKS is not set -# CONFIG_ESP32_TRAX is not set -CONFIG_TRACEMEM_RESERVE_DRAM=0x0 -# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set -# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set -CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y -# CONFIG_ESP32_ENABLE_COREDUMP is not set -# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set -# CONFIG_ESP32_APPTRACE_DEST_UART is not set -CONFIG_ESP32_APPTRACE_DEST_NONE=y -# CONFIG_ESP32_APPTRACE_ENABLE is not set -# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set -CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y -CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 -CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 -CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 -CONFIG_MAIN_TASK_STACK_SIZE=12240 -CONFIG_NEWLIB_STDOUT_ADDCR=y -# CONFIG_NEWLIB_NANO_FORMAT is not set -CONFIG_CONSOLE_UART_DEFAULT=y -# CONFIG_CONSOLE_UART_CUSTOM is not set -# CONFIG_CONSOLE_UART_NONE is not set -CONFIG_CONSOLE_UART_NUM=0 -CONFIG_CONSOLE_UART_BAUDRATE=115200 -# CONFIG_ULP_COPROC_ENABLED is not set -CONFIG_ULP_COPROC_RESERVE_MEM=0 -# CONFIG_ESP32_PANIC_PRINT_HALT is not set -CONFIG_ESP32_PANIC_PRINT_REBOOT=y -# CONFIG_ESP32_PANIC_SILENT_REBOOT is not set -# CONFIG_ESP32_PANIC_GDBSTUB is not set -CONFIG_ESP32_DEBUG_OCDAWARE=y -# CONFIG_INT_WDT is not set -# CONFIG_TASK_WDT is not set -# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set -# CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 is not set -# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set -CONFIG_ESP32_TIME_SYSCALL_USE_NONE=y -CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y -# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set -CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 -CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0 -# CONFIG_ESP32_XTAL_FREQ_40 is not set -# CONFIG_ESP32_XTAL_FREQ_26 is not set -CONFIG_ESP32_XTAL_FREQ_AUTO=y -CONFIG_ESP32_XTAL_FREQ=0 -# CONFIG_WIFI_ENABLED is not set -# CONFIG_ETHERNET is not set - -# -# FAT Filesystem support -# -CONFIG_FATFS_CODEPAGE_ASCII=y -# CONFIG_FATFS_CODEPAGE_437 is not set -# CONFIG_FATFS_CODEPAGE_720 is not set -# CONFIG_FATFS_CODEPAGE_737 is not set -# CONFIG_FATFS_CODEPAGE_771 is not set -# CONFIG_FATFS_CODEPAGE_775 is not set -# CONFIG_FATFS_CODEPAGE_850 is not set -# CONFIG_FATFS_CODEPAGE_852 is not set -# CONFIG_FATFS_CODEPAGE_855 is not set -# CONFIG_FATFS_CODEPAGE_857 is not set -# CONFIG_FATFS_CODEPAGE_860 is not set -# CONFIG_FATFS_CODEPAGE_861 is not set -# CONFIG_FATFS_CODEPAGE_862 is not set -# CONFIG_FATFS_CODEPAGE_863 is not set -# CONFIG_FATFS_CODEPAGE_864 is not set -# CONFIG_FATFS_CODEPAGE_865 is not set -# CONFIG_FATFS_CODEPAGE_866 is not set -# CONFIG_FATFS_CODEPAGE_869 is not set -# CONFIG_FATFS_CODEPAGE_932 is not set -# CONFIG_FATFS_CODEPAGE_936 is not set -# CONFIG_FATFS_CODEPAGE_949 is not set -# CONFIG_FATFS_CODEPAGE_950 is not set -CONFIG_FATFS_CODEPAGE=1 -CONFIG_FATFS_MAX_LFN=255 - -# -# FreeRTOS -# -# CONFIG_FREERTOS_UNICORE is not set -CONFIG_FREERTOS_CORETIMER_0=y -# CONFIG_FREERTOS_CORETIMER_1 is not set -CONFIG_FREERTOS_HZ=1000 -CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set -CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y -# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set -CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3 -CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y -# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set -# CONFIG_FREERTOS_ASSERT_DISABLE is not set -CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y -# CONFIG_ENABLE_MEMORY_DEBUG is not set -CONFIG_FREERTOS_ISR_STACKSIZE=1536 -# CONFIG_FREERTOS_LEGACY_HOOKS is not set -CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 -# CONFIG_SUPPORT_STATIC_ALLOCATION is not set -CONFIG_TIMER_TASK_PRIORITY=1 -CONFIG_TIMER_TASK_STACK_DEPTH=2048 -CONFIG_TIMER_QUEUE_LENGTH=10 -# CONFIG_FREERTOS_DEBUG_INTERNALS is not set - -# -# Log output -# -# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set -# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set -# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set -CONFIG_LOG_DEFAULT_LEVEL_INFO=y -# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set -# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set -CONFIG_LOG_DEFAULT_LEVEL=3 -CONFIG_LOG_COLORS=y - -# -# LWIP -# -# CONFIG_L2_TO_L3_COPY is not set -CONFIG_LWIP_MAX_SOCKETS=4 -CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0 -# CONFIG_LWIP_SO_REUSE is not set -# CONFIG_LWIP_SO_RCVBUF is not set -CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 -# CONFIG_LWIP_IP_FRAG is not set -# CONFIG_LWIP_IP_REASSEMBLY is not set -CONFIG_TCP_MAXRTX=12 -CONFIG_TCP_SYNMAXRTX=6 -# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set -CONFIG_TCPIP_TASK_STACK_SIZE=2560 -# CONFIG_PPP_SUPPORT is not set - -# -# mbedTLS -# -CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 -# CONFIG_MBEDTLS_DEBUG is not set -CONFIG_MBEDTLS_HARDWARE_AES=y -CONFIG_MBEDTLS_HARDWARE_MPI=y -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y -CONFIG_MBEDTLS_HARDWARE_SHA=y - -# -# OpenSSL -# -# CONFIG_OPENSSL_DEBUG is not set -CONFIG_OPENSSL_ASSERT_DO_NOTHING=y -# CONFIG_OPENSSL_ASSERT_EXIT is not set - -# -# SPI Flash driver -# -# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set -CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..bb11b29 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,265 @@ +# +# Automatically generated file; DO NOT EDIT. +# Espressif IoT Development Framework Configuration +# + +# +# SDK tool configuration +# + +# +# Application manager +# + +# +# Bootloader config +# +CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y +CONFIG_LOG_BOOTLOADER_LEVEL_INFO= +CONFIG_LOG_BOOTLOADER_LEVEL=2 + +# +# Security features +# + +# +# Serial flasher config +# +CONFIG_ESPTOOLPY_PORT="/dev/cu.SLAB_USBtoUART" +CONFIG_ESPTOOLPY_BAUD_115200B= +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_FLASHSIZE_2MB= +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# +# Nofrendo ESP32-specific configuration +# + +# +# Partition Table +# +CONFIG_PARTITION_TABLE_SINGLE_APP= +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" + +# +# Compiler options +# + +# +# Component config +# + +# +# Application Level Tracing +# + +# +# Bluetooth +# + +# +# Driver configurations +# + +# +# ADC configuration +# + +# +# SPI configuration +# + +# +# eFuse Bit Manager +# + +# +# ESP32-specific +# +CONFIG_ESP32_DEFAULT_CPU_FREQ_160= +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 +CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 +CONFIG_MAIN_TASK_STACK_SIZE=12240 +CONFIG_TIMER_TASK_STACK_SIZE=4096 +CONFIG_INT_WDT= +CONFIG_TASK_WDT= +CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1= +CONFIG_ESP32_TIME_SYSCALL_USE_NONE=y +CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0 +CONFIG_ESP32_XTAL_FREQ_40= +CONFIG_ESP32_XTAL_FREQ_AUTO=y +CONFIG_ESP32_XTAL_FREQ=0 + +# +# Wi-Fi +# +CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER= +CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 +CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 + +# +# PHY +# + +# +# Power Management +# + +# +# ADC-Calibration +# + +# +# Event Loop Library +# + +# +# ESP HTTP client +# + +# +# HTTP Server +# + +# +# ESP HTTPS OTA +# + +# +# Core dump +# + +# +# Ethernet +# + +# +# FAT Filesystem support +# + +# +# Modbus configuration +# + +# +# FreeRTOS +# +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3 +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 + +# +# Heap memory debugging +# + +# +# libsodium +# + +# +# Log output +# + +# +# LWIP +# +CONFIG_LWIP_MAX_SOCKETS=4 +CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y + +# +# DHCP server +# + +# +# TCP +# + +# +# UDP +# +CONFIG_TCPIP_TASK_STACK_SIZE=2560 + +# +# ICMP +# + +# +# LWIP RAW API +# + +# +# mbedTLS +# +CONFIG_MBEDTLS_HARDWARE_MPI=y +CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y +CONFIG_MBEDTLS_HARDWARE_SHA=y + +# +# TLS Key Exchange Methods +# + +# +# Symmetric Ciphers +# + +# +# Certificates +# + +# +# mDNS +# + +# +# ESP-MQTT Configurations +# + +# +# NVS +# + +# +# OpenSSL +# + +# +# PThreads +# +CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 + +# +# SPI Flash driver +# + +# +# SPIFFS Configuration +# + +# +# SPIFFS Cache Configuration +# + +# +# Debug Configuration +# + +# +# TCP/IP Adapter +# + +# +# Unity unit testing library +# + +# +# Virtual file system +# + +# +# Wear Levelling +# From 992c1a92359739edbfa8f830ae21ae4048c4022b Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 21 Mar 2019 00:18:58 +0800 Subject: [PATCH 02/73] ignore sdkconfig --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f688810..b705f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build/ +sdkconfig sdkconfig.old *.nes - From 622e9c31cab3aa132e7450ed9747b0cceeb0fccc Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 21 Mar 2019 00:26:18 +0800 Subject: [PATCH 03/73] various LCD init commands --- components/nofrendo-esp32/spi_lcd.c | 54 +++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index ac87286..574d3a6 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -42,6 +42,7 @@ #define LCD_TYPE_ILI 0 #define LCD_TYPE_ST 1 +#define LCD_TYPE_M5STACK 2 #define LCD_SEL_CMD() gpio_set_level(PIN_NUM_DC, 0) // Low to send command #define LCD_SEL_DATA() gpio_set_level(PIN_NUM_DC, 1) // High to send data @@ -60,7 +61,47 @@ typedef struct spi_device_handle_t spi; -DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[] = { +DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ILI) + {0xCF, {0x00, 0x83, 0X30}, 3}, + {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, + {0xE8, {0x85, 0x01, 0x79}, 3}, + {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, + {0xF7, {0x20}, 1}, + {0xEA, {0x00, 0x00}, 2}, + {0xC0, {0x26}, 1}, // Power control, VRH[5:0] + {0xC1, {0x11}, 1}, // Power control, SAP[2:0];BT[3:0] + {0xC5, {0x35, 0x3E}, 2}, // VCM control + {0xC7, {0xBE}, 1}, // VCM control2, was B1h + {0x36, {0x28}, 1}, // Memory Access Control, was 0x48 + {0x3A, {0x55}, 1}, + {0xB1, {0x00, 0x1B}, 2}, + {0xF2, {0x08}, 1}, // 3Gamma Function Disable + {0x26, {0x01}, 1}, // Gamma curve selected + {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15}, // Set Gamma + {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15}, // Set Gamma + {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, + {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, + {0x2C, {0}, 0}, + {0xB7, {0x07}, 1}, + {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, // Display Function Control, 8 82 27 +#endif +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST) + {0x36, {(1<<5)|(1<<6)}, 1}, // MV 1, MX 1 + {0x3A, {0x55}, 1}, + {0xB2, {0x0c, 0x0c, 0x00, 0x33, 0x33}, 5}, + {0xB7, {0x35}, 1}, + {0xBB, {0x2B}, 1}, + {0xC0, {0x2C}, 1}, + {0xC2, {0x01, 0xFF}, 2}, + {0xC3, {0x11}, 1}, + {0xC4, {0x20}, 1}, + {0xC6, {0x0f}, 1}, + {0xD0, {0xA4, 0xA1}, 2}, + {0xE0, {0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19}, 14}, + {0xE1, {0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19}, 14}, +#endif +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_M5STACK) {0xEF, {0x03, 0x80, 0x02}, 3}, {0xCF, {0x00, 0XC1, 0X30}, 3}, {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, @@ -72,21 +113,15 @@ DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[] = { {0xC1, {0x10}, 1}, {0xC5, {0x3e, 0x28}, 2}, {0xC7, {0x86}, 1}, - // {0x36, {0x48}, 1}, {0x36, {0x08}, 1}, {0x3A, {0x55}, 1}, - // {0xB1, {0x00, 0x18}, 2}, {0xB1, {0x00, 0x1B}, 2}, {0xB6, {0x08, 0x82, 0x27}, 3}, {0xF2, {0x00}, 1}, {0x26, {0x01}, 1}, {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, - - // {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, - // {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4}, - // {0x2C, {0}, 0}, - // {0xB7, {0x07}, 1}, +#endif {0x11, {0}, 0x80}, {0x29, {0}, 0x80}, {0, {0}, 0xff}, @@ -138,9 +173,6 @@ void lcd_gpio_init() void lcd_init_seq(spi_device_handle_t spi) { int cmd = 0; - const lcd_init_cmd_t *lcd_init_cmds; - - lcd_init_cmds = ili_init_cmds; //Send all the commands while (lcd_init_cmds[cmd].databytes != 0xff) From d0dc6095f4261647aa1c1e78b54358149bd044ce Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 22 Mar 2019 00:46:17 +0800 Subject: [PATCH 04/73] add IPS and SPI clock speed config --- components/nofrendo-esp32/Kconfig.projbuild | 16 ++++++++++++++++ components/nofrendo-esp32/spi_lcd.c | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 013baea..40ec166 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -93,6 +93,17 @@ config HW_INV_BL_CUST default n depends on HW_CUSTOM +config HW_LCD_IPS_CUST + bool "IPS type LCD (inverted color)" + default n + depends on HW_CUSTOM + +config HW_LCD_CLOCK_SPEED_CUST + int "LCD Backlight Enable pin" + depends on HW_CUSTOM + range 10 40 + default 27 + config HW_INV_BL bool @@ -143,6 +154,11 @@ config HW_LCD_BL_GPIO default 5 if HW_WROVERKIT default 32 if HW_M5STACK +config HW_LCD_CLOCK_SPEED + int + default HW_LCD_CLOCK_SPEED_CUST if HW_CUSTOM + default 27 if HW_WROVERKIT + default 40 if HW_M5STACK config SOUND_ENA bool "Analog audio on GPIO26" diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 574d3a6..6ed5197 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -37,6 +37,7 @@ #define PIN_NUM_DC CONFIG_HW_LCD_DC_GPIO #define PIN_NUM_RST CONFIG_HW_LCD_RST_GPIO #define PIN_NUM_BL CONFIG_HW_LCD_BL_GPIO +#define SPI_SPD CONFIG_HW_LCD_CLOCK_SPEED #define SPI_NUM 0x3 @@ -121,6 +122,9 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0x26, {0x01}, 1}, {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, +#endif +#ifdef CONFIG_HW_LCD_IPS_CUST + {0x21, {0}, 0x80}, #endif {0x11, {0}, 0x80}, {0x29, {0}, 0x80}, @@ -319,8 +323,7 @@ void lcd_init() .quadwp_io_num = -1, .quadhd_io_num = -1}; spi_device_interface_config_t devcfg = { - // .clock_speed_hz=10*1000*1000, //Clock out at 10 MHz - .clock_speed_hz = 40 * 1000 * 1000, //Clock out at 10 MHz + .clock_speed_hz = SPI_SPD * 1000 * 1000, //Clock out at 10 MHz .mode = 0, //SPI mode 0 .spics_io_num = PIN_NUM_CS, //CS pin .queue_size = 7, //We want to be able to queue 7 transactions at a time From 9fd99be0cf3f2da04bbf65d3baa26d458a939bf5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 22 Mar 2019 23:27:58 +0800 Subject: [PATCH 05/73] set default custom pins to native SPI pins --- .gitignore | 1 + components/nofrendo-esp32/Kconfig.projbuild | 14 +++++++------- components/nofrendo-esp32/spi_lcd.c | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b705f0f..3f1c04f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ sdkconfig sdkconfig.old *.nes +.* \ No newline at end of file diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 40ec166..5acbb61 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -68,25 +68,25 @@ config HW_LCD_CS_GPIO_CUST int "LCD CS pin" depends on HW_CUSTOM range 1 35 - default 14 + default 5 config HW_LCD_DC_GPIO_CUST int "LCD DC pin" depends on HW_CUSTOM range 1 35 - default 27 + default 16 config HW_LCD_RST_GPIO_CUST int "LCD RST pin" depends on HW_CUSTOM range 1 35 - default 33 + default 17 config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" depends on HW_CUSTOM - range 1 35 - default 32 + range 0 35 + default 0 config HW_INV_BL_CUST bool "Invert backlight output" @@ -101,8 +101,8 @@ config HW_LCD_IPS_CUST config HW_LCD_CLOCK_SPEED_CUST int "LCD Backlight Enable pin" depends on HW_CUSTOM - range 10 40 - default 27 + range 10 80 + default 40 config HW_INV_BL diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 6ed5197..2669241 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -199,6 +199,7 @@ void lcd_spi_pre_transfer_callback(spi_transaction_t *t) void lcd_setBrightness(int duty) { +#if (PIN_NUM_BL > 0) #define LEDC_HS_TIMER LEDC_TIMER_0 #define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE #define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0 @@ -222,8 +223,13 @@ void lcd_setBrightness(int duty) .timer_sel = LEDC_HS_TIMER}; ledc_channel_config(&ledc_channel); +#ifdef HW_INV_BL + ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, 1023 - duty); +#else ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, duty); +#endif ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel); +#endif } #define U16x2toU32(m, l) ((((uint32_t)(l >> 8 | (l & 0xFF) << 8)) << 16) | (m >> 8 | (m & 0xFF) << 8)) From e9392bbfc36d3acb74644864a11d95368cb28365 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 22 Mar 2019 23:38:01 +0800 Subject: [PATCH 06/73] fix config description --- components/nofrendo-esp32/Kconfig.projbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 5acbb61..2cef5c8 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -99,7 +99,7 @@ config HW_LCD_IPS_CUST depends on HW_CUSTOM config HW_LCD_CLOCK_SPEED_CUST - int "LCD Backlight Enable pin" + int "LCD SPI clock speed" depends on HW_CUSTOM range 10 80 default 40 From 839461ac56b3e26639b2cf40cb38bd17e26b569c Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 23 Mar 2019 00:30:36 +0800 Subject: [PATCH 07/73] avoid PSRAM pins --- components/nofrendo-esp32/Kconfig.projbuild | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 2cef5c8..06e9b64 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -74,13 +74,13 @@ config HW_LCD_DC_GPIO_CUST int "LCD DC pin" depends on HW_CUSTOM range 1 35 - default 16 + default 21 config HW_LCD_RST_GPIO_CUST int "LCD RST pin" depends on HW_CUSTOM range 1 35 - default 17 + default 22 config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" From afad8235256d9572475452e4f9951cc18fe14989 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sun, 24 Mar 2019 00:39:45 +0800 Subject: [PATCH 08/73] add GPIO controller --- components/nofrendo-esp32/Kconfig.projbuild | 78 ++++++++++++++++++--- components/nofrendo-esp32/gpiocontroller.c | 68 ++++++++++++++++++ components/nofrendo-esp32/gpiocontroller.h | 7 ++ components/nofrendo-esp32/psxcontroller.c | 5 +- components/nofrendo-esp32/spi_lcd.c | 2 +- components/nofrendo-esp32/video_audio.c | 12 ++++ 6 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 components/nofrendo-esp32/gpiocontroller.c create mode 100644 components/nofrendo-esp32/gpiocontroller.h diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 06e9b64..42c4c64 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -85,8 +85,8 @@ config HW_LCD_RST_GPIO_CUST config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" depends on HW_CUSTOM - range 0 35 - default 0 + range -1 35 + default -1 config HW_INV_BL_CUST bool "Invert backlight output" @@ -167,35 +167,93 @@ config SOUND_ENA ESP32 will output 0-3.3V analog audio signal on GPIO26. -config HW_PSX_ENA - bool "Enable PSX controller input" - default y +choice HW_CONTROLLER_SEL + prompt "Controller type" + default HW_CONTROLLER_GPIO help - If you connect a PSX/PS2 controller to the following GPIOs, you can control the NES. + Connect buttons to the following GPIOs to control the NES; + Or connect a PSX/PS2 controller to the following GPIOs. + +config HW_CONTROLLER_GPIO + bool "GPIO controller" + +config HW_CONTROLLER_PSX + bool "PSX controller" + +endchoice config HW_PSX_CLK int "PSX controller CLK GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 14 config HW_PSX_DAT int "PSX controller DATa GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 27 config HW_PSX_ATT int "PSX controller ATTention GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 16 config HW_PSX_CMD int "PSX controller CoMmanD GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 2 + +config HW_GPIO_UP + int "GPIO controller UP button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 12 + +config HW_GPIO_DOWN + int "GPIO controller DOWN button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 13 + +config HW_GPIO_LEFT + int "GPIO controller LEFT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 14 + +config HW_GPIO_RIGHT + int "GPIO controller RIGHT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 15 + +config HW_GPIO_SELECT + int "GPIO controller SELECT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 4 + +config HW_GPIO_START + int "GPIO controller START button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 27 + +config HW_GPIO_A + int "GPIO controller A button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 32 + +config HW_GPIO_B + int "GPIO controller B button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 33 + endmenu \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c new file mode 100644 index 0000000..079b6ab --- /dev/null +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -0,0 +1,68 @@ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "driver/gpio.h" +#include +#include "sdkconfig.h" + +// Set buttons with pins +#define UP CONFIG_HW_GPIO_UP +#define DOWN CONFIG_HW_GPIO_DOWN +#define LEFT CONFIG_HW_GPIO_LEFT +#define RIGHT CONFIG_HW_GPIO_RIGHT +#define SELECT CONFIG_HW_GPIO_SELECT +#define START CONFIG_HW_GPIO_START +#define A CONFIG_HW_GPIO_A +#define B CONFIG_HW_GPIO_B + +#ifdef CONFIG_HW_CONTROLLER_GPIO + +int gpioReadInput() +{ + return 0xFFFF ^ ( + (!gpio_get_level(UP) << 4) + | (!gpio_get_level(DOWN) << 6) + | (!gpio_get_level(LEFT) << 7) + | (!gpio_get_level(RIGHT) << 5) + | (!gpio_get_level(SELECT) << 0) + | (!gpio_get_level(START) << 3) + | (!gpio_get_level(A) << 13) + | (!gpio_get_level(B) << 14) + ); +} + +void gpiocontrollerInit() +{ + //Configure button + gpio_config_t btn_config; + btn_config.intr_type = GPIO_INTR_ANYEDGE; //Enable interrupt on both rising and falling edges + btn_config.mode = GPIO_MODE_INPUT; //Set as Input + btn_config.pin_bit_mask = (uint64_t) //Bitmask + ( + ((uint64_t) 1 << UP) + | ((uint64_t) 1 << DOWN) + | ((uint64_t) 1 << LEFT) + | ((uint64_t) 1 << RIGHT) + | ((uint64_t) 1 << SELECT) + | ((uint64_t) 1 << START) + | ((uint64_t) 1 << A) + | ((uint64_t) 1 << B) + ); + btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup + btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown + gpio_config(&btn_config); +} + +#else + +int gpioReadInput() { + return 0xFFFF; +} + + +void gpiocontrollerInit() { + printf("GPIO controller disabled in menuconfig; no input enabled.\n"); +} + +#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.h b/components/nofrendo-esp32/gpiocontroller.h new file mode 100644 index 0000000..6e0ac41 --- /dev/null +++ b/components/nofrendo-esp32/gpiocontroller.h @@ -0,0 +1,7 @@ +#ifndef GAMEPAD_H +#define GAMEPAD_H + +int gpioReadInput(); +void gpiocontrollerInit(); + +#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index e466296..9262bec 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -31,8 +31,7 @@ #define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") - -#if CONFIG_HW_PSX_ENA +#ifdef CONFIG_HW_CONTROLLER_PSX /* Sends and receives a byte from/to the PSX controller using SPI */ static int psxSendRecv(int send) { @@ -128,14 +127,12 @@ void psxcontrollerInit() { } } - #else int psxReadInput() { return 0xFFFF; } - void psxcontrollerInit() { printf("PSX controller disabled in menuconfig; no input enabled.\n"); } diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 2669241..a90e201 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -199,7 +199,7 @@ void lcd_spi_pre_transfer_callback(spi_transaction_t *t) void lcd_setBrightness(int duty) { -#if (PIN_NUM_BL > 0) +#if (PIN_NUM_BL >= 0) #define LEDC_HS_TIMER LEDC_TIMER_0 #define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE #define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0 diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index dde7c7b..ed7b10e 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -39,7 +39,11 @@ #include "sdkconfig.h" #include +#ifdef CONFIG_HW_CONTROLLER_GPIO +#include +#else #include +#endif #define DEFAULT_SAMPLERATE 22100 #define DEFAULT_FRAGSIZE 128 @@ -266,7 +270,11 @@ static void videoTask(void *arg) { static void osd_initinput() { +#ifdef CONFIG_HW_CONTROLLER_GPIO + gpiocontrollerInit(); +#else psxcontrollerInit(); +#endif } void osd_getinput(void) @@ -276,7 +284,11 @@ void osd_getinput(void) 0,0,0,0,event_soft_reset,event_joypad1_a,event_joypad1_b,event_hard_reset }; static int oldb=0xffff; +#ifdef CONFIG_HW_CONTROLLER_GPIO + int b=gpioReadInput(); +#else int b=psxReadInput(); +#endif int chg=b^oldb; int x; oldb=b; From 9fb52cbdba9aad8a5061ccc76789040dd3bca6b8 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sun, 24 Mar 2019 00:41:10 +0800 Subject: [PATCH 09/73] add GPIO controller --- components/nofrendo-esp32/Kconfig.projbuild | 78 ++++++++++++++++++--- components/nofrendo-esp32/gpiocontroller.c | 68 ++++++++++++++++++ components/nofrendo-esp32/gpiocontroller.h | 7 ++ components/nofrendo-esp32/psxcontroller.c | 5 +- components/nofrendo-esp32/spi_lcd.c | 2 +- components/nofrendo-esp32/video_audio.c | 12 ++++ 6 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 components/nofrendo-esp32/gpiocontroller.c create mode 100644 components/nofrendo-esp32/gpiocontroller.h diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 06e9b64..42c4c64 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -85,8 +85,8 @@ config HW_LCD_RST_GPIO_CUST config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" depends on HW_CUSTOM - range 0 35 - default 0 + range -1 35 + default -1 config HW_INV_BL_CUST bool "Invert backlight output" @@ -167,35 +167,93 @@ config SOUND_ENA ESP32 will output 0-3.3V analog audio signal on GPIO26. -config HW_PSX_ENA - bool "Enable PSX controller input" - default y +choice HW_CONTROLLER_SEL + prompt "Controller type" + default HW_CONTROLLER_GPIO help - If you connect a PSX/PS2 controller to the following GPIOs, you can control the NES. + Connect buttons to the following GPIOs to control the NES; + Or connect a PSX/PS2 controller to the following GPIOs. + +config HW_CONTROLLER_GPIO + bool "GPIO controller" + +config HW_CONTROLLER_PSX + bool "PSX controller" + +endchoice config HW_PSX_CLK int "PSX controller CLK GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 14 config HW_PSX_DAT int "PSX controller DATa GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 27 config HW_PSX_ATT int "PSX controller ATTention GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 16 config HW_PSX_CMD int "PSX controller CoMmanD GPIO pin" - depends on HW_PSX_ENA + depends on HW_CONTROLLER_PSX range 1 35 default 2 + +config HW_GPIO_UP + int "GPIO controller UP button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 12 + +config HW_GPIO_DOWN + int "GPIO controller DOWN button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 13 + +config HW_GPIO_LEFT + int "GPIO controller LEFT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 14 + +config HW_GPIO_RIGHT + int "GPIO controller RIGHT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 15 + +config HW_GPIO_SELECT + int "GPIO controller SELECT button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 4 + +config HW_GPIO_START + int "GPIO controller START button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 27 + +config HW_GPIO_A + int "GPIO controller A button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 32 + +config HW_GPIO_B + int "GPIO controller B button" + depends on HW_CONTROLLER_GPIO + range 0 33 + default 33 + endmenu \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c new file mode 100644 index 0000000..079b6ab --- /dev/null +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -0,0 +1,68 @@ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "driver/gpio.h" +#include +#include "sdkconfig.h" + +// Set buttons with pins +#define UP CONFIG_HW_GPIO_UP +#define DOWN CONFIG_HW_GPIO_DOWN +#define LEFT CONFIG_HW_GPIO_LEFT +#define RIGHT CONFIG_HW_GPIO_RIGHT +#define SELECT CONFIG_HW_GPIO_SELECT +#define START CONFIG_HW_GPIO_START +#define A CONFIG_HW_GPIO_A +#define B CONFIG_HW_GPIO_B + +#ifdef CONFIG_HW_CONTROLLER_GPIO + +int gpioReadInput() +{ + return 0xFFFF ^ ( + (!gpio_get_level(UP) << 4) + | (!gpio_get_level(DOWN) << 6) + | (!gpio_get_level(LEFT) << 7) + | (!gpio_get_level(RIGHT) << 5) + | (!gpio_get_level(SELECT) << 0) + | (!gpio_get_level(START) << 3) + | (!gpio_get_level(A) << 13) + | (!gpio_get_level(B) << 14) + ); +} + +void gpiocontrollerInit() +{ + //Configure button + gpio_config_t btn_config; + btn_config.intr_type = GPIO_INTR_ANYEDGE; //Enable interrupt on both rising and falling edges + btn_config.mode = GPIO_MODE_INPUT; //Set as Input + btn_config.pin_bit_mask = (uint64_t) //Bitmask + ( + ((uint64_t) 1 << UP) + | ((uint64_t) 1 << DOWN) + | ((uint64_t) 1 << LEFT) + | ((uint64_t) 1 << RIGHT) + | ((uint64_t) 1 << SELECT) + | ((uint64_t) 1 << START) + | ((uint64_t) 1 << A) + | ((uint64_t) 1 << B) + ); + btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup + btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown + gpio_config(&btn_config); +} + +#else + +int gpioReadInput() { + return 0xFFFF; +} + + +void gpiocontrollerInit() { + printf("GPIO controller disabled in menuconfig; no input enabled.\n"); +} + +#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.h b/components/nofrendo-esp32/gpiocontroller.h new file mode 100644 index 0000000..6e0ac41 --- /dev/null +++ b/components/nofrendo-esp32/gpiocontroller.h @@ -0,0 +1,7 @@ +#ifndef GAMEPAD_H +#define GAMEPAD_H + +int gpioReadInput(); +void gpiocontrollerInit(); + +#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index e466296..9262bec 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -31,8 +31,7 @@ #define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") - -#if CONFIG_HW_PSX_ENA +#ifdef CONFIG_HW_CONTROLLER_PSX /* Sends and receives a byte from/to the PSX controller using SPI */ static int psxSendRecv(int send) { @@ -128,14 +127,12 @@ void psxcontrollerInit() { } } - #else int psxReadInput() { return 0xFFFF; } - void psxcontrollerInit() { printf("PSX controller disabled in menuconfig; no input enabled.\n"); } diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 2669241..8d848bd 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -199,7 +199,7 @@ void lcd_spi_pre_transfer_callback(spi_transaction_t *t) void lcd_setBrightness(int duty) { -#if (PIN_NUM_BL > 0) +#if (PIN_NUM_BL > -1) #define LEDC_HS_TIMER LEDC_TIMER_0 #define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE #define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0 diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index dde7c7b..ed7b10e 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -39,7 +39,11 @@ #include "sdkconfig.h" #include +#ifdef CONFIG_HW_CONTROLLER_GPIO +#include +#else #include +#endif #define DEFAULT_SAMPLERATE 22100 #define DEFAULT_FRAGSIZE 128 @@ -266,7 +270,11 @@ static void videoTask(void *arg) { static void osd_initinput() { +#ifdef CONFIG_HW_CONTROLLER_GPIO + gpiocontrollerInit(); +#else psxcontrollerInit(); +#endif } void osd_getinput(void) @@ -276,7 +284,11 @@ void osd_getinput(void) 0,0,0,0,event_soft_reset,event_joypad1_a,event_joypad1_b,event_hard_reset }; static int oldb=0xffff; +#ifdef CONFIG_HW_CONTROLLER_GPIO + int b=gpioReadInput(); +#else int b=psxReadInput(); +#endif int chg=b^oldb; int x; oldb=b; From dc7e05f92d18da7b2071b433c6f8c4b5bdc45172 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 3 Apr 2019 23:16:36 +0800 Subject: [PATCH 10/73] avoid TTGO SD card pins --- components/nofrendo-esp32/Kconfig.projbuild | 20 ++++++++++---------- components/nofrendo-esp32/gpiocontroller.c | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 42c4c64..f0d564e 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -49,8 +49,8 @@ config HW_LCD_TYPE config HW_LCD_MISO_GPIO_CUST int "LCD MISO pin" depends on HW_CUSTOM - range 1 35 - default 19 + range -1 35 + default -1 config HW_LCD_MOSI_GPIO_CUST int "LCD MOSI pin" @@ -212,48 +212,48 @@ config HW_GPIO_UP int "GPIO controller UP button" depends on HW_CONTROLLER_GPIO range 0 33 - default 12 + default 33 config HW_GPIO_DOWN int "GPIO controller DOWN button" depends on HW_CONTROLLER_GPIO range 0 33 - default 13 + default 32 config HW_GPIO_LEFT int "GPIO controller LEFT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 14 + default 27 config HW_GPIO_RIGHT int "GPIO controller RIGHT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 15 + default 22 config HW_GPIO_SELECT int "GPIO controller SELECT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 4 + default 19 config HW_GPIO_START int "GPIO controller START button" depends on HW_CONTROLLER_GPIO range 0 33 - default 27 + default 12 config HW_GPIO_A int "GPIO controller A button" depends on HW_CONTROLLER_GPIO range 0 33 - default 32 + default 4 config HW_GPIO_B int "GPIO controller B button" depends on HW_CONTROLLER_GPIO range 0 33 - default 33 + default 0 endmenu \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c index 079b6ab..da510bd 100644 --- a/components/nofrendo-esp32/gpiocontroller.c +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -40,14 +40,14 @@ void gpiocontrollerInit() btn_config.mode = GPIO_MODE_INPUT; //Set as Input btn_config.pin_bit_mask = (uint64_t) //Bitmask ( - ((uint64_t) 1 << UP) - | ((uint64_t) 1 << DOWN) - | ((uint64_t) 1 << LEFT) - | ((uint64_t) 1 << RIGHT) - | ((uint64_t) 1 << SELECT) - | ((uint64_t) 1 << START) - | ((uint64_t) 1 << A) - | ((uint64_t) 1 << B) + ((uint64_t)(((uint64_t)1) << UP)) + | ((uint64_t)(((uint64_t)1) << DOWN)) + | ((uint64_t)(((uint64_t)1) << LEFT)) + | ((uint64_t)(((uint64_t)1) << RIGHT)) + | ((uint64_t)(((uint64_t)1) << SELECT)) + | ((uint64_t)(((uint64_t)1) << START)) + | ((uint64_t)(((uint64_t)1) << A)) + | ((uint64_t)(((uint64_t)1) << B)) ); btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown From cee205dbdc46e3089a0681f53a777fda4c37821c Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 8 Apr 2019 21:04:50 +0800 Subject: [PATCH 11/73] added I2C device support --- components/nofrendo-esp32/Kconfig.projbuild | 12 ++- components/nofrendo-esp32/gpiocontroller.c | 13 ++- components/nofrendo-esp32/i2c_gpcontroller.c | 85 +++++++++++++++ components/nofrendo-esp32/i2c_gpcontroller.h | 10 ++ components/nofrendo-esp32/i2c_kbcontroller.c | 104 +++++++++++++++++++ components/nofrendo-esp32/i2c_kbcontroller.h | 10 ++ components/nofrendo-esp32/psxcontroller.c | 8 +- components/nofrendo-esp32/video_audio.c | 24 +++-- 8 files changed, 246 insertions(+), 20 deletions(-) create mode 100644 components/nofrendo-esp32/i2c_gpcontroller.c create mode 100644 components/nofrendo-esp32/i2c_gpcontroller.h create mode 100644 components/nofrendo-esp32/i2c_kbcontroller.c create mode 100644 components/nofrendo-esp32/i2c_kbcontroller.h diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index f0d564e..4156118 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "Nofrendo ESP32-specific configuration" choice NOFRENDO_HARDWARE prompt "Hardware to run on" - default ESP_WROVER_KIT_V2 + default HW_M5STACK help This emulator can run on various types of hardware. Select what you have here. @@ -162,14 +162,14 @@ config HW_LCD_CLOCK_SPEED config SOUND_ENA bool "Analog audio on GPIO26" - default n + default y help ESP32 will output 0-3.3V analog audio signal on GPIO26. choice HW_CONTROLLER_SEL prompt "Controller type" - default HW_CONTROLLER_GPIO + default HW_CONTROLLER_I2C_GP help Connect buttons to the following GPIOs to control the NES; Or connect a PSX/PS2 controller to the following GPIOs. @@ -180,6 +180,12 @@ config HW_CONTROLLER_GPIO config HW_CONTROLLER_PSX bool "PSX controller" +config HW_CONTROLLER_I2C_GP + bool "I2C Gamepad" + +config HW_CONTROLLER_I2C_KB + bool "I2C Keyboard" + endchoice diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c index da510bd..0b75341 100644 --- a/components/nofrendo-esp32/gpiocontroller.c +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -6,6 +6,8 @@ #include #include "sdkconfig.h" +#ifdef CONFIG_HW_CONTROLLER_GPIO + // Set buttons with pins #define UP CONFIG_HW_GPIO_UP #define DOWN CONFIG_HW_GPIO_DOWN @@ -16,8 +18,6 @@ #define A CONFIG_HW_GPIO_A #define B CONFIG_HW_GPIO_B -#ifdef CONFIG_HW_CONTROLLER_GPIO - int gpioReadInput() { return 0xFFFF ^ ( @@ -56,13 +56,12 @@ void gpiocontrollerInit() #else -int gpioReadInput() { - return 0xFFFF; -} - - void gpiocontrollerInit() { printf("GPIO controller disabled in menuconfig; no input enabled.\n"); } +int gpioReadInput() { + return 0xFFFF; +} + #endif \ No newline at end of file diff --git a/components/nofrendo-esp32/i2c_gpcontroller.c b/components/nofrendo-esp32/i2c_gpcontroller.c new file mode 100644 index 0000000..75a24ad --- /dev/null +++ b/components/nofrendo-esp32/i2c_gpcontroller.c @@ -0,0 +1,85 @@ +#include "sdkconfig.h" +#include "i2c_gpcontroller.h" + +#ifdef CONFIG_HW_CONTROLLER_I2C_GP + +#define I2C_GAMEPAD_SCL_IO 22 /*!< gpio number for I2C master clock */ +#define I2C_GAMEPAD_SDA_IO 21 /*!< gpio number for I2C master data */ +#define I2C_GAMEPAD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ +#define I2C_GAMEPAD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_GAMEPAD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_GAMEPAD_FREQ_HZ 100000 /*!< I2C master clock frequency */ +#define I2C_GAMEPAD_ADDR 0x08 + +#define READ_BIT I2C_MASTER_READ /*!< I2C master read */ +#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ +#define NACK_VAL 0x1 /*!< I2C nack value */ + +void i2c_gpcontrollerInit() +{ + int i2c_master_port = I2C_GAMEPAD_NUM; + i2c_config_t conf; + conf.mode = I2C_MODE_MASTER; + conf.sda_io_num = I2C_GAMEPAD_SDA_IO; + conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + conf.scl_io_num = I2C_GAMEPAD_SCL_IO; + conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + conf.master.clk_speed = I2C_GAMEPAD_FREQ_HZ; + i2c_param_config(i2c_master_port, &conf); + i2c_driver_install(i2c_master_port, conf.mode, + I2C_GAMEPAD_RX_BUF_DISABLE, + I2C_GAMEPAD_TX_BUF_DISABLE, 0); +} + +/** + * @brief test code to write esp-i2c-slave + * + * 1. set mode + * _________________________________________________________________ + * | start | slave_addr + wr_bit + ack | write 1 byte + ack | stop | + * --------|---------------------------|---------------------|------| + * 2. wait more than 24 ms + * 3. read data + * ______________________________________________________________________________________ + * | start | slave_addr + rd_bit + ack | read 1 byte + ack | read 1 byte + nack | stop | + * --------|---------------------------|--------------------|--------------------|------| + */ +int i2c_gpReadInput() +{ + uint8_t data; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (I2C_GAMEPAD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); + i2c_master_read_byte(cmd, &data, NACK_VAL); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_GAMEPAD_NUM, cmd, 1000 / portTICK_RATE_MS); + i2c_cmd_link_delete(cmd); + if (ret == 0) { + printf("I2C read %d, return %d\n", data, ret); + + return 0xFFFF ^ ( + (((0x01 & data) > 0) << 4) + | (((0x02 & data) > 0) << 6) + | (((0x04 & data) > 0) << 7) + | (((0x08 & data) > 0) << 5) + | (((0x10 & data) > 0) << 0) + | (((0x20 & data) > 0) << 3) + | (((0x40 & data) > 0) << 13) + | (((0x80 & data) > 0) << 14) + ); + } else { + return 0xFFFF; + } +} + +#else + +void i2c_gpcontrollerInit() { + printf("I2C Gamepad disabled in menuconfig; no input enabled.\n"); +} + +int i2c_gpReadInput() { + return 0xFFFF; +} + +#endif diff --git a/components/nofrendo-esp32/i2c_gpcontroller.h b/components/nofrendo-esp32/i2c_gpcontroller.h new file mode 100644 index 0000000..1090e19 --- /dev/null +++ b/components/nofrendo-esp32/i2c_gpcontroller.h @@ -0,0 +1,10 @@ +#ifndef _I2C_KEYBOARD_H_ +#define _I2C_KEYBOARD_H_ + +#include +#include "driver/i2c.h" + +void i2c_gpcontrollerInit(); +int i2c_gpReadInput(); + +#endif diff --git a/components/nofrendo-esp32/i2c_kbcontroller.c b/components/nofrendo-esp32/i2c_kbcontroller.c new file mode 100644 index 0000000..9fd5cf4 --- /dev/null +++ b/components/nofrendo-esp32/i2c_kbcontroller.c @@ -0,0 +1,104 @@ +#include "sdkconfig.h" +#include "i2c_kbcontroller.h" + +#ifdef CONFIG_HW_CONTROLLER_I2C_KB + +#define I2C_KEYBOARD_SCL_IO 22 /*!< gpio number for I2C master clock */ +#define I2C_KEYBOARD_SDA_IO 21 /*!< gpio number for I2C master data */ +#define I2C_KEYBOARD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ +#define I2C_KEYBOARD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_KEYBOARD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_KEYBOARD_FREQ_HZ 100000 /*!< I2C master clock frequency */ +#define I2C_KEYBOARD_ADDR 0x5f + +#define READ_BIT I2C_MASTER_READ /*!< I2C master read */ +#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ +#define NACK_VAL 0x1 /*!< I2C nack value */ + +void i2c_kbcontrollerInit() +{ + int i2c_master_port = I2C_KEYBOARD_NUM; + i2c_config_t conf; + conf.mode = I2C_MODE_MASTER; + conf.sda_io_num = I2C_KEYBOARD_SDA_IO; + conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + conf.scl_io_num = I2C_KEYBOARD_SCL_IO; + conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + conf.master.clk_speed = I2C_KEYBOARD_FREQ_HZ; + i2c_param_config(i2c_master_port, &conf); + i2c_driver_install(i2c_master_port, conf.mode, + I2C_KEYBOARD_RX_BUF_DISABLE, + I2C_KEYBOARD_TX_BUF_DISABLE, 0); +} + +/** + * @brief test code to write esp-i2c-slave + * + * 1. set mode + * _________________________________________________________________ + * | start | slave_addr + wr_bit + ack | write 1 byte + ack | stop | + * --------|---------------------------|---------------------|------| + * 2. wait more than 24 ms + * 3. read data + * ______________________________________________________________________________________ + * | start | slave_addr + rd_bit + ack | read 1 byte + ack | read 1 byte + nack | stop | + * --------|---------------------------|--------------------|--------------------|------| + */ +int i2c_kbReadInput() +{ + uint8_t data; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (I2C_KEYBOARD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); + i2c_master_read_byte(cmd, &data, NACK_VAL); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_KEYBOARD_NUM, cmd, 1000 / portTICK_RATE_MS); + i2c_cmd_link_delete(cmd); + if ((ret == 0) && (data > 0)) { + printf("I2C read %d, return %d\n", data, ret); + + switch (data) + { + case 181: // up + return 0xFFFF ^ (1 << 4); + break; + case 182: // down + return 0xFFFF ^ (1 << 6); + break; + case 180: // left + return 0xFFFF ^ (1 << 7); + break; + case 183: // right + return 0xFFFF ^ (1 << 5); + break; + case 32: // space -> select + return 0xFFFF ^ (1 << 0); + break; + case 13: // enter -> start + return 0xFFFF ^ (1 << 3); + break; + case 108: // L -> A + return 0xFFFF ^ (1 << 13); + break; + case 107: // K -> B + return 0xFFFF ^ (1 << 14); + break; + } + } + + return 0xFFFF; +} + +#else + +void i2c_kbcontrollerInit() +{ + printf("I2C Keyboard disabled in menuconfig; no input enabled.\n"); +} + +int i2c_kbReadInput() +{ + return 0xFFFF; +} + +#endif diff --git a/components/nofrendo-esp32/i2c_kbcontroller.h b/components/nofrendo-esp32/i2c_kbcontroller.h new file mode 100644 index 0000000..fbff4b2 --- /dev/null +++ b/components/nofrendo-esp32/i2c_kbcontroller.h @@ -0,0 +1,10 @@ +#ifndef _I2C_KEYBOARD_H_ +#define _I2C_KEYBOARD_H_ + +#include +#include "driver/i2c.h" + +void i2c_kbcontrollerInit(); +int i2c_kbReadInput(); + +#endif diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index 9262bec..83c4d6d 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -129,12 +129,12 @@ void psxcontrollerInit() { #else -int psxReadInput() { - return 0xFFFF; -} - void psxcontrollerInit() { printf("PSX controller disabled in menuconfig; no input enabled.\n"); } +int psxReadInput() { + return 0xFFFF; +} + #endif \ No newline at end of file diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index ed7b10e..727bd0d 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -39,10 +39,14 @@ #include "sdkconfig.h" #include -#ifdef CONFIG_HW_CONTROLLER_GPIO +#if defined CONFIG_HW_CONTROLLER_GPIO #include -#else +#elif defined CONFIG_HW_CONTROLLER_PSX #include +#elif defined CONFIG_HW_CONTROLLER_I2C_GP +#include +#elif defined CONFIG_HW_CONTROLLER_I2C_KB +#include #endif #define DEFAULT_SAMPLERATE 22100 @@ -270,10 +274,14 @@ static void videoTask(void *arg) { static void osd_initinput() { -#ifdef CONFIG_HW_CONTROLLER_GPIO +#if defined CONFIG_HW_CONTROLLER_GPIO gpiocontrollerInit(); -#else +#elif defined CONFIG_HW_CONTROLLER_PSX psxcontrollerInit(); +#elif defined CONFIG_HW_CONTROLLER_I2C_GP + i2c_gpcontrollerInit(); +#elif defined CONFIG_HW_CONTROLLER_I2C_KB + i2c_kbcontrollerInit(); #endif } @@ -284,10 +292,14 @@ void osd_getinput(void) 0,0,0,0,event_soft_reset,event_joypad1_a,event_joypad1_b,event_hard_reset }; static int oldb=0xffff; -#ifdef CONFIG_HW_CONTROLLER_GPIO +#if defined CONFIG_HW_CONTROLLER_GPIO int b=gpioReadInput(); -#else +#elif defined CONFIG_HW_CONTROLLER_PSX int b=psxReadInput(); +#elif defined CONFIG_HW_CONTROLLER_I2C_GP + int b=i2c_gpReadInput(); +#elif defined CONFIG_HW_CONTROLLER_I2C_KB + int b=i2c_kbReadInput(); #endif int chg=b^oldb; int x; From 2950703d34ab1be16d9c70cad3cb2b360095c0ce Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 15 Apr 2019 22:44:52 +0800 Subject: [PATCH 12/73] avoid LCD used I2C pins --- components/nofrendo-esp32/Kconfig.projbuild | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 4156118..009e2b2 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -73,14 +73,14 @@ config HW_LCD_CS_GPIO_CUST config HW_LCD_DC_GPIO_CUST int "LCD DC pin" depends on HW_CUSTOM - range 1 35 - default 21 + range 1 32 + default 27 config HW_LCD_RST_GPIO_CUST int "LCD RST pin" depends on HW_CUSTOM range 1 35 - default 22 + default 33 config HW_LCD_BL_GPIO_CUST int "LCD Backlight Enable pin" @@ -218,48 +218,48 @@ config HW_GPIO_UP int "GPIO controller UP button" depends on HW_CONTROLLER_GPIO range 0 33 - default 33 + default 22 config HW_GPIO_DOWN int "GPIO controller DOWN button" depends on HW_CONTROLLER_GPIO range 0 33 - default 32 + default 21 config HW_GPIO_LEFT int "GPIO controller LEFT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 27 + default 19 config HW_GPIO_RIGHT int "GPIO controller RIGHT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 22 + default 4 config HW_GPIO_SELECT int "GPIO controller SELECT button" depends on HW_CONTROLLER_GPIO range 0 33 - default 19 + default 0 config HW_GPIO_START int "GPIO controller START button" depends on HW_CONTROLLER_GPIO range 0 33 - default 12 + default 2 config HW_GPIO_A int "GPIO controller A button" depends on HW_CONTROLLER_GPIO range 0 33 - default 4 + default 12 config HW_GPIO_B int "GPIO controller B button" depends on HW_CONTROLLER_GPIO range 0 33 - default 0 + default 32 endmenu \ No newline at end of file From 94296ea5298edf81fc6c70fd688724add768aef5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 20 Apr 2019 22:46:21 +0800 Subject: [PATCH 13/73] lower I2C frequency to support ATtiny controller --- components/nofrendo-esp32/i2c_gpcontroller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/i2c_gpcontroller.c b/components/nofrendo-esp32/i2c_gpcontroller.c index 75a24ad..90ae850 100644 --- a/components/nofrendo-esp32/i2c_gpcontroller.c +++ b/components/nofrendo-esp32/i2c_gpcontroller.c @@ -8,7 +8,7 @@ #define I2C_GAMEPAD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ #define I2C_GAMEPAD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ #define I2C_GAMEPAD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ -#define I2C_GAMEPAD_FREQ_HZ 100000 /*!< I2C master clock frequency */ +#define I2C_GAMEPAD_FREQ_HZ 50000 /*!< I2C master clock frequency */ #define I2C_GAMEPAD_ADDR 0x08 #define READ_BIT I2C_MASTER_READ /*!< I2C master read */ From f79e839b5c373fb993ab04f829101cf28830c745 Mon Sep 17 00:00:00 2001 From: Leung CHAN Date: Fri, 9 Aug 2019 11:12:51 +0800 Subject: [PATCH 14/73] add Odroid-Go support --- components/nofrendo-esp32/Kconfig.projbuild | 80 +++++++++++++++------ components/nofrendo-esp32/spi_lcd.c | 20 ++++-- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 009e2b2..0ae14d8 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "Nofrendo ESP32-specific configuration" choice NOFRENDO_HARDWARE prompt "Hardware to run on" - default HW_M5STACK + default HW_ODROID_GO help This emulator can run on various types of hardware. Select what you have here. @@ -15,6 +15,9 @@ config HW_WROVERKIT_V2 config HW_M5STACK bool "M5Stack" +config HW_ODROID_GO + bool "Odroid-Go" + config HW_CUSTOM bool "Custom hardware" @@ -22,7 +25,7 @@ endchoice choice HW_LCD_TYPE_SEL prompt "LCD type" - depends on HW_CUSTOM || HW_WROVERKIT_V2 + depends on HW_CUSTOM || HW_WROVERKIT_V2 || HW_ODROID_GO config HW_LCD_TYPE_ILI bool "ILI9341 LCD" @@ -32,6 +35,11 @@ config HW_LCD_TYPE_ST endchoice +config HW_LCD_IPS + bool "IPS type LCD (inverted color)" + depends on HW_CUSTOM || HW_WROVERKIT_V2 || HW_ODROID_GO + default n + config HW_WROVERKIT bool default n if HW_CUSTOM @@ -93,8 +101,8 @@ config HW_INV_BL_CUST default n depends on HW_CUSTOM -config HW_LCD_IPS_CUST - bool "IPS type LCD (inverted color)" +config HW_LCD_ROTATE_180_CUST + bool "Rotate LCD 180 degree" default n depends on HW_CUSTOM @@ -105,60 +113,77 @@ config HW_LCD_CLOCK_SPEED_CUST default 40 -config HW_INV_BL - bool - default HW_INBV_BL_CUST if HW_CUSTOM - default n if HW_WROVERKIT_V1 - default y if HW_WROVERKIT_V2 - default n if HW_M5STACK - config HW_LCD_MISO_GPIO int default HW_LCD_MISO_GPIO_CUST if HW_CUSTOM default 25 if HW_WROVERKIT default 19 if HW_M5STACK + default 19 if HW_ODROID_GO config HW_LCD_MOSI_GPIO int default HW_LCD_MOSI_GPIO_CUST if HW_CUSTOM default 23 if HW_WROVERKIT default 23 if HW_M5STACK + default 23 if HW_ODROID_GO config HW_LCD_CLK_GPIO int default HW_LCD_CLK_GPIO_CUST if HW_CUSTOM default 19 if HW_WROVERKIT default 18 if HW_M5STACK + default 18 if HW_ODROID_GO config HW_LCD_CS_GPIO int default HW_LCD_CS_GPIO_CUST if HW_CUSTOM default 22 if HW_WROVERKIT default 14 if HW_M5STACK + default 5 if HW_ODROID_GO config HW_LCD_DC_GPIO int default HW_LCD_DC_GPIO_CUST if HW_CUSTOM default 21 if HW_WROVERKIT default 27 if HW_M5STACK + default 21 if HW_ODROID_GO config HW_LCD_RST_GPIO int default HW_LCD_RST_GPIO_CUST if HW_CUSTOM default 18 if HW_WROVERKIT default 33 if HW_M5STACK + default -1 if HW_ODROID_GO config HW_LCD_BL_GPIO int default HW_LCD_BL_GPIO_CUST if HW_CUSTOM default 5 if HW_WROVERKIT default 32 if HW_M5STACK + default 14 if HW_ODROID_GO + +config HW_INV_BL + bool + default HW_INBV_BL_CUST if HW_CUSTOM + default n if HW_WROVERKIT_V1 + default y if HW_WROVERKIT_V2 + default n if HW_M5STACK + default n if HW_ODROID_GO + +config HW_LCD_ROTATE_180 + bool + default HW_LCD_ROTATE_180_CUST if HW_CUSTOM + default n if HW_WROVERKIT_V1 + default n if HW_WROVERKIT_V2 + default n if HW_M5STACK + default n if HW_ODROID_GO config HW_LCD_CLOCK_SPEED int default HW_LCD_CLOCK_SPEED_CUST if HW_CUSTOM default 27 if HW_WROVERKIT default 40 if HW_M5STACK + default 40 if HW_ODROID_GO config SOUND_ENA bool "Analog audio on GPIO26" @@ -169,6 +194,7 @@ config SOUND_ENA choice HW_CONTROLLER_SEL prompt "Controller type" + default HW_CONTROLLER_GPIO if HW_ODROID_GO default HW_CONTROLLER_I2C_GP help Connect buttons to the following GPIOs to control the NES; @@ -192,74 +218,82 @@ endchoice config HW_PSX_CLK int "PSX controller CLK GPIO pin" depends on HW_CONTROLLER_PSX - range 1 35 + range 1 39 default 14 config HW_PSX_DAT int "PSX controller DATa GPIO pin" depends on HW_CONTROLLER_PSX - range 1 35 + range 1 39 default 27 config HW_PSX_ATT int "PSX controller ATTention GPIO pin" depends on HW_CONTROLLER_PSX - range 1 35 + range 1 39 default 16 config HW_PSX_CMD int "PSX controller CoMmanD GPIO pin" depends on HW_CONTROLLER_PSX - range 1 35 + range 1 39 default 2 config HW_GPIO_UP int "GPIO controller UP button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 35 if HW_ODROID_GO default 22 config HW_GPIO_DOWN int "GPIO controller DOWN button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 35 if HW_ODROID_GO default 21 config HW_GPIO_LEFT int "GPIO controller LEFT button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 34 if HW_ODROID_GO default 19 config HW_GPIO_RIGHT int "GPIO controller RIGHT button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 34 if HW_ODROID_GO default 4 config HW_GPIO_SELECT int "GPIO controller SELECT button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 27 if HW_ODROID_GO default 0 config HW_GPIO_START int "GPIO controller START button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 39 if HW_ODROID_GO default 2 config HW_GPIO_A int "GPIO controller A button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 32 if HW_ODROID_GO default 12 config HW_GPIO_B int "GPIO controller B button" depends on HW_CONTROLLER_GPIO - range 0 33 + range 0 39 + default 33 if HW_ODROID_GO default 32 endmenu \ No newline at end of file diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 8d848bd..3534a1d 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -74,7 +74,11 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC1, {0x11}, 1}, // Power control, SAP[2:0];BT[3:0] {0xC5, {0x35, 0x3E}, 2}, // VCM control {0xC7, {0xBE}, 1}, // VCM control2, was B1h - {0x36, {0x28}, 1}, // Memory Access Control, was 0x48 +#ifdef HW_LCD_ROTATE_180 + {0x36, {(1<<7)|(1<<6)|(1<<5)|(1<<3)}, 1}, // MY | MX | MV | BGR +#else + {0x36, {(1<<5)|(1<<3)}, 1}, // MV | BGR +#endif {0x3A, {0x55}, 1}, {0xB1, {0x00, 0x1B}, 2}, {0xF2, {0x08}, 1}, // 3Gamma Function Disable @@ -88,7 +92,11 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, // Display Function Control, 8 82 27 #endif #if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST) - {0x36, {(1<<5)|(1<<6)}, 1}, // MV 1, MX 1 +#ifdef HW_LCD_ROTATE_180 + {0x36, {(1<<6)|(1<<5)}, 1}, // MX | MV | RGB +#else + {0x36, {(1<<7)|(1<<5)}, 1}, // MY | MV | RGB +#endif {0x3A, {0x55}, 1}, {0xB2, {0x0c, 0x0c, 0x00, 0x33, 0x33}, 5}, {0xB7, {0x35}, 1}, @@ -114,7 +122,11 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC1, {0x10}, 1}, {0xC5, {0x3e, 0x28}, 2}, {0xC7, {0x86}, 1}, - {0x36, {0x08}, 1}, +#ifdef HW_LCD_ROTATE_180 + {0x36, {(1<<7)|(1<<6)|(1<<3)}, 1}, // MY | MX | BGR +#else + {0x36, {(1<<3)}, 1}, // BGR +#endif {0x3A, {0x55}, 1}, {0xB1, {0x00, 0x1B}, 2}, {0xB6, {0x08, 0x82, 0x27}, 3}, @@ -123,7 +135,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, #endif -#ifdef CONFIG_HW_LCD_IPS_CUST +#ifdef CONFIG_HW_LCD_IPS {0x21, {0}, 0x80}, #endif {0x11, {0}, 0x80}, From 21ae80484ff334e8002f5725872a00c7c20347a9 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 8 Nov 2019 17:41:01 +0800 Subject: [PATCH 15/73] fix #ifdef CONFIG_HW_LCD_ROTATE_180 --- components/nofrendo-esp32/spi_lcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 3534a1d..e9c3c8c 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -74,7 +74,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC1, {0x11}, 1}, // Power control, SAP[2:0];BT[3:0] {0xC5, {0x35, 0x3E}, 2}, // VCM control {0xC7, {0xBE}, 1}, // VCM control2, was B1h -#ifdef HW_LCD_ROTATE_180 +#ifdef CONFIG_HW_LCD_ROTATE_180 {0x36, {(1<<7)|(1<<6)|(1<<5)|(1<<3)}, 1}, // MY | MX | MV | BGR #else {0x36, {(1<<5)|(1<<3)}, 1}, // MV | BGR @@ -92,7 +92,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, // Display Function Control, 8 82 27 #endif #if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST) -#ifdef HW_LCD_ROTATE_180 +#ifdef CONFIG_HW_LCD_ROTATE_180 {0x36, {(1<<6)|(1<<5)}, 1}, // MX | MV | RGB #else {0x36, {(1<<7)|(1<<5)}, 1}, // MY | MV | RGB @@ -122,7 +122,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC1, {0x10}, 1}, {0xC5, {0x3e, 0x28}, 2}, {0xC7, {0x86}, 1}, -#ifdef HW_LCD_ROTATE_180 +#ifdef CONFIG_HW_LCD_ROTATE_180 {0x36, {(1<<7)|(1<<6)|(1<<3)}, 1}, // MY | MX | BGR #else {0x36, {(1<<3)}, 1}, // BGR From c57fe9b6388745b84f0068f34fe7c8237e9a6ac5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 28 Nov 2019 19:37:53 +0800 Subject: [PATCH 16/73] support esp-idf v4.0 --- components/nofrendo-esp32/video_audio.c | 5 +- components/nofrendo/libsnss/libsnss.c | 356 ++++++++++++------------ components/nofrendo/nes/nes_rom.c | 99 ++++--- 3 files changed, 230 insertions(+), 230 deletions(-) diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index 727bd0d..061053d 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -92,8 +92,9 @@ static void do_audio_frame() { // audio_frame[i*2+1] = audio_frame[i] + 0x8000; // audio_frame[i*2] = audio_frame[i] + 0x8000; } - i2s_write_bytes(0, (const char *)audio_frame, 2*n, portMAX_DELAY); - left-=n; + size_t i2s_bytes_write; + i2s_write(0, (const char *)audio_frame, 2*n, &i2s_bytes_write, portMAX_DELAY); + left -= i2s_bytes_write / 2; } #endif } diff --git a/components/nofrendo/libsnss/libsnss.c b/components/nofrendo/libsnss/libsnss.c index 5541d24..f5e786c 100644 --- a/components/nofrendo/libsnss/libsnss.c +++ b/components/nofrendo/libsnss/libsnss.c @@ -19,33 +19,33 @@ /**************************************************************************/ static unsigned int -swap32 (unsigned int source) +swap32(unsigned int source) { #ifdef USE_LITTLE_ENDIAN char buffer[4]; - - buffer[0] = ((char *) &source)[3]; - buffer[1] = ((char *) &source)[2]; - buffer[2] = ((char *) &source)[1]; - buffer[3] = ((char *) &source)[0]; - - return *((unsigned int *) buffer); -#else /* !USE_LITTLE_ENDIAN */ + + buffer[0] = ((char *)&source)[3]; + buffer[1] = ((char *)&source)[2]; + buffer[2] = ((char *)&source)[1]; + buffer[3] = ((char *)&source)[0]; + + return *((unsigned int *)buffer); +#else /* !USE_LITTLE_ENDIAN */ return source; #endif /* !USE_LITTLE_ENDIAN */ } static unsigned short -swap16 (unsigned short source) +swap16(unsigned short source) { #ifdef USE_LITTLE_ENDIAN char buffer[2]; - - buffer[0] = ((char *) &source)[1]; - buffer[1] = ((char *) &source)[0]; - return *((unsigned short *) buffer); -#else /* !USE_LITTLE_ENDIAN */ + buffer[0] = ((char *)&source)[1]; + buffer[1] = ((char *)&source)[0]; + + return *((unsigned short *)buffer); +#else /* !USE_LITTLE_ENDIAN */ return source; #endif /* !USE_LITTLE_ENDIAN */ } @@ -54,26 +54,26 @@ swap16 (unsigned short source) /* support functions */ /**************************************************************************/ -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) /**************************************************************************/ static SNSS_RETURN_CODE -SNSS_ReadBlockHeader (SnssBlockHeader *header, SNSS_FILE *snssFile) +SNSS_ReadBlockHeader(SnssBlockHeader *header, SNSS_FILE *snssFile) { char headerBytes[12]; - if (fread (headerBytes, 12, 1, snssFile->fp) != 1) + if (fread(headerBytes, 12, 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } - strncpy (header->tag, &headerBytes[0], TAG_LENGTH); + strncpy(header->tag, &headerBytes[0], TAG_LENGTH); header->tag[4] = '\0'; - header->blockVersion = *((unsigned int *) &headerBytes[4]); - header->blockVersion = swap32 (header->blockVersion); - header->blockLength = *((unsigned int *) &headerBytes[8]); - header->blockLength = swap32 (header->blockLength); + header->blockVersion = *((unsigned int *)&headerBytes[4]); + header->blockVersion = swap32(header->blockVersion); + header->blockLength = *((unsigned int *)&headerBytes[8]); + header->blockLength = swap32(header->blockLength); return SNSS_OK; } @@ -81,26 +81,26 @@ SNSS_ReadBlockHeader (SnssBlockHeader *header, SNSS_FILE *snssFile) /**************************************************************************/ static SNSS_RETURN_CODE -SNSS_WriteBlockHeader (SnssBlockHeader *header, SNSS_FILE *snssFile) +SNSS_WriteBlockHeader(SnssBlockHeader *header, SNSS_FILE *snssFile) { char headerBytes[12]; unsigned int tempInt; - strncpy (&headerBytes[0], header->tag, TAG_LENGTH); + strncpy(&headerBytes[0], header->tag, TAG_LENGTH); - tempInt = swap32 (header->blockVersion); - headerBytes[4] = ((char *) &tempInt)[0]; - headerBytes[5] = ((char *) &tempInt)[1]; - headerBytes[6] = ((char *) &tempInt)[2]; - headerBytes[7] = ((char *) &tempInt)[3]; + tempInt = swap32(header->blockVersion); + headerBytes[4] = ((char *)&tempInt)[0]; + headerBytes[5] = ((char *)&tempInt)[1]; + headerBytes[6] = ((char *)&tempInt)[2]; + headerBytes[7] = ((char *)&tempInt)[3]; - tempInt = swap32 (header->blockLength); - headerBytes[8] = ((char *) &tempInt)[0]; - headerBytes[9] = ((char *) &tempInt)[1]; - headerBytes[10] = ((char *) &tempInt)[2]; - headerBytes[11] = ((char *) &tempInt)[3]; + tempInt = swap32(header->blockLength); + headerBytes[8] = ((char *)&tempInt)[0]; + headerBytes[9] = ((char *)&tempInt)[1]; + headerBytes[10] = ((char *)&tempInt)[2]; + headerBytes[11] = ((char *)&tempInt)[3]; - if (fwrite (headerBytes, 12, 1, snssFile->fp) != 1) + if (fwrite(headerBytes, 12, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -111,7 +111,7 @@ SNSS_WriteBlockHeader (SnssBlockHeader *header, SNSS_FILE *snssFile) /**************************************************************************/ const char * -SNSS_GetErrorString (SNSS_RETURN_CODE code) +SNSS_GetErrorString(SNSS_RETURN_CODE code) { switch (code) { @@ -148,48 +148,48 @@ SNSS_GetErrorString (SNSS_RETURN_CODE code) /* functions for reading and writing SNSS file headers */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadFileHeader (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadFileHeader(SNSS_FILE *snssFile) { - if (fread (snssFile->headerBlock.tag, 4, 1, snssFile->fp) != 1) + if (fread(snssFile->headerBlock.tag, 4, 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } - - if (0 != strncmp(snssFile->headerBlock.tag, "SNSS", 4)) + + if (0 != strncmp(snssFile->headerBlock.tag, "SNSS", 5)) { return SNSS_BAD_FILE_TAG; } - + snssFile->headerBlock.tag[4] = '\0'; - if (fread (&snssFile->headerBlock.numberOfBlocks, sizeof (unsigned int), 1, snssFile->fp) != 1) + if (fread(&snssFile->headerBlock.numberOfBlocks, sizeof(unsigned int), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } - snssFile->headerBlock.numberOfBlocks = swap32 (snssFile->headerBlock.numberOfBlocks); + snssFile->headerBlock.numberOfBlocks = swap32(snssFile->headerBlock.numberOfBlocks); return SNSS_OK; } /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteFileHeader (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteFileHeader(SNSS_FILE *snssFile) { unsigned int tempInt; char writeBuffer[8]; /* always place the SNSS tag in this field */ - strncpy (&writeBuffer[0], "SNSS", 4); - tempInt = swap32 (snssFile->headerBlock.numberOfBlocks); - writeBuffer[4] = ((char *) &tempInt)[0]; - writeBuffer[5] = ((char *) &tempInt)[1]; - writeBuffer[6] = ((char *) &tempInt)[2]; - writeBuffer[7] = ((char *) &tempInt)[3]; + strncpy(&writeBuffer[0], "SNSS", 5); + tempInt = swap32(snssFile->headerBlock.numberOfBlocks); + writeBuffer[4] = ((char *)&tempInt)[0]; + writeBuffer[5] = ((char *)&tempInt)[1]; + writeBuffer[6] = ((char *)&tempInt)[2]; + writeBuffer[7] = ((char *)&tempInt)[3]; - if (fwrite (writeBuffer, 8, 1, snssFile->fp) != 1) + if (fwrite(writeBuffer, 8, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -201,26 +201,26 @@ SNSS_WriteFileHeader (SNSS_FILE *snssFile) /* general file manipulation functions */ /**************************************************************************/ SNSS_RETURN_CODE -SNSS_OpenFile (SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) +SNSS_OpenFile(SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) { *snssFile = malloc(sizeof(SNSS_FILE)); if (NULL == *snssFile) { return SNSS_OUT_OF_MEMORY; } - + /* zero the memory */ - memset (*snssFile, 0, sizeof(SNSS_FILE)); + memset(*snssFile, 0, sizeof(SNSS_FILE)); (*snssFile)->mode = mode; if (SNSS_OPEN_READ == mode) { - (*snssFile)->fp = fopen (filename, "rb"); + (*snssFile)->fp = fopen(filename, "rb"); } else { - (*snssFile)->fp = fopen (filename, "wb"); + (*snssFile)->fp = fopen(filename, "wb"); (*snssFile)->headerBlock.numberOfBlocks = 0; } @@ -244,7 +244,7 @@ SNSS_OpenFile (SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) /**************************************************************************/ SNSS_RETURN_CODE -SNSS_CloseFile (SNSS_FILE **snssFile) +SNSS_CloseFile(SNSS_FILE **snssFile) { int prevLoc; SNSS_RETURN_CODE code; @@ -269,7 +269,7 @@ SNSS_CloseFile (SNSS_FILE **snssFile) fseek((*snssFile)->fp, prevLoc, SEEK_SET); } - if (fclose ((*snssFile)->fp) != 0) + if (fclose((*snssFile)->fp) != 0) { return SNSS_CLOSE_FAILED; } @@ -282,45 +282,45 @@ SNSS_CloseFile (SNSS_FILE **snssFile) /**************************************************************************/ -SNSS_RETURN_CODE -SNSS_GetNextBlockType (SNSS_BLOCK_TYPE *blockType, SNSS_FILE *snssFile) +SNSS_RETURN_CODE +SNSS_GetNextBlockType(SNSS_BLOCK_TYPE *blockType, SNSS_FILE *snssFile) { char tagBuffer[TAG_LENGTH + 1]; - if (fread (tagBuffer, TAG_LENGTH, 1, snssFile->fp) != 1) + if (fread(tagBuffer, TAG_LENGTH, 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } tagBuffer[TAG_LENGTH] = '\0'; /* reset the file pointer to the start of the block */ - if (fseek (snssFile->fp, -TAG_LENGTH, SEEK_CUR) != 0) + if (fseek(snssFile->fp, -TAG_LENGTH, SEEK_CUR) != 0) { return SNSS_READ_FAILED; } /* figure out which type of block it is */ - if (strcmp (tagBuffer, "BASR") == 0) + if (strcmp(tagBuffer, "BASR") == 0) { *blockType = SNSS_BASR; } - else if (strcmp (tagBuffer, "VRAM") == 0) + else if (strcmp(tagBuffer, "VRAM") == 0) { *blockType = SNSS_VRAM; } - else if (strcmp (tagBuffer, "SRAM") == 0) + else if (strcmp(tagBuffer, "SRAM") == 0) { *blockType = SNSS_SRAM; } - else if (strcmp (tagBuffer, "MPRD") == 0) + else if (strcmp(tagBuffer, "MPRD") == 0) { *blockType = SNSS_MPRD; } - else if (strcmp (tagBuffer, "CNTR") == 0) + else if (strcmp(tagBuffer, "CNTR") == 0) { *blockType = SNSS_CNTR; } - else if (strcmp (tagBuffer, "SOUN") == 0) + else if (strcmp(tagBuffer, "SOUN") == 0) { *blockType = SNSS_SOUN; } @@ -334,26 +334,26 @@ SNSS_GetNextBlockType (SNSS_BLOCK_TYPE *blockType, SNSS_FILE *snssFile) /**************************************************************************/ -SNSS_RETURN_CODE -SNSS_SkipNextBlock (SNSS_FILE *snssFile) +SNSS_RETURN_CODE +SNSS_SkipNextBlock(SNSS_FILE *snssFile) { unsigned int blockLength; /* skip the block's tag and version */ - if (fseek (snssFile->fp, TAG_LENGTH + sizeof (unsigned int), SEEK_CUR) != 0) + if (fseek(snssFile->fp, TAG_LENGTH + sizeof(unsigned int), SEEK_CUR) != 0) { return SNSS_READ_FAILED; } /* get the block data length */ - if (fread (&blockLength, sizeof (unsigned int), 1, snssFile->fp) != 1) + if (fread(&blockLength, sizeof(unsigned int), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } - blockLength = swap32 (blockLength); + blockLength = swap32(blockLength); /* skip over the block data */ - if (fseek (snssFile->fp, blockLength, SEEK_CUR) != 0) + if (fseek(snssFile->fp, blockLength, SEEK_CUR) != 0) { return SNSS_READ_FAILED; } @@ -365,18 +365,18 @@ SNSS_SkipNextBlock (SNSS_FILE *snssFile) /* functions for reading and writing base register blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadBaseBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadBaseBlock(SNSS_FILE *snssFile) { char blockBytes[BASE_BLOCK_LENGTH]; SnssBlockHeader header; - if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK) + if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) { return SNSS_READ_FAILED; } - if (fread (blockBytes, MIN (header.blockLength, BASE_BLOCK_LENGTH), 1, snssFile->fp) != 1) + if (fread(blockBytes, MIN(header.blockLength, BASE_BLOCK_LENGTH), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } @@ -386,17 +386,17 @@ SNSS_ReadBaseBlock (SNSS_FILE *snssFile) snssFile->baseBlock.regY = blockBytes[0x2]; snssFile->baseBlock.regFlags = blockBytes[0x3]; snssFile->baseBlock.regStack = blockBytes[0x4]; - snssFile->baseBlock.regPc = *((unsigned short *) &blockBytes[0x5]); - snssFile->baseBlock.regPc = swap16 (snssFile->baseBlock.regPc); + snssFile->baseBlock.regPc = *((unsigned short *)&blockBytes[0x5]); + snssFile->baseBlock.regPc = swap16(snssFile->baseBlock.regPc); snssFile->baseBlock.reg2000 = blockBytes[0x7]; snssFile->baseBlock.reg2001 = blockBytes[0x8]; - memcpy (&snssFile->baseBlock.cpuRam, &blockBytes[0x9], 0x800); - memcpy (&snssFile->baseBlock.spriteRam, &blockBytes[0x809], 0x100); - memcpy (&snssFile->baseBlock.ppuRam, &blockBytes[0x909], 0x1000); - memcpy (&snssFile->baseBlock.palette, &blockBytes[0x1909], 0x20); - memcpy (&snssFile->baseBlock.mirrorState, &blockBytes[0x1929], 0x4); - snssFile->baseBlock.vramAddress = *((unsigned short *) &blockBytes[0x192D]); - snssFile->baseBlock.vramAddress = swap16 (snssFile->baseBlock.vramAddress); + memcpy(&snssFile->baseBlock.cpuRam, &blockBytes[0x9], 0x800); + memcpy(&snssFile->baseBlock.spriteRam, &blockBytes[0x809], 0x100); + memcpy(&snssFile->baseBlock.ppuRam, &blockBytes[0x909], 0x1000); + memcpy(&snssFile->baseBlock.palette, &blockBytes[0x1909], 0x20); + memcpy(&snssFile->baseBlock.mirrorState, &blockBytes[0x1929], 0x4); + snssFile->baseBlock.vramAddress = *((unsigned short *)&blockBytes[0x192D]); + snssFile->baseBlock.vramAddress = swap16(snssFile->baseBlock.vramAddress); snssFile->baseBlock.spriteRamAddress = blockBytes[0x192F]; snssFile->baseBlock.tileXOffset = blockBytes[0x1930]; @@ -405,19 +405,19 @@ SNSS_ReadBaseBlock (SNSS_FILE *snssFile) /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteBaseBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteBaseBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; char blockBytes[BASE_BLOCK_LENGTH]; unsigned short tempShort; - strcpy (header.tag, "BASR"); + strcpy(header.tag, "BASR"); header.blockVersion = SNSS_BLOCK_VERSION; header.blockLength = BASE_BLOCK_LENGTH; - if ((returnCode = SNSS_WriteBlockHeader (&header, snssFile)) != SNSS_OK) + if ((returnCode = SNSS_WriteBlockHeader(&header, snssFile)) != SNSS_OK) { return returnCode; } @@ -427,23 +427,23 @@ SNSS_WriteBaseBlock (SNSS_FILE *snssFile) blockBytes[0x2] = snssFile->baseBlock.regY; blockBytes[0x3] = snssFile->baseBlock.regFlags; blockBytes[0x4] = snssFile->baseBlock.regStack; - tempShort = swap16 (snssFile->baseBlock.regPc); - blockBytes[0x5] = ((char *) &tempShort)[0]; - blockBytes[0x6] = ((char *) &tempShort)[1]; + tempShort = swap16(snssFile->baseBlock.regPc); + blockBytes[0x5] = ((char *)&tempShort)[0]; + blockBytes[0x6] = ((char *)&tempShort)[1]; blockBytes[0x7] = snssFile->baseBlock.reg2000; blockBytes[0x8] = snssFile->baseBlock.reg2001; - memcpy (&blockBytes[0x9], &snssFile->baseBlock.cpuRam, 0x800); - memcpy (&blockBytes[0x809], &snssFile->baseBlock.spriteRam, 0x100); - memcpy (&blockBytes[0x909], &snssFile->baseBlock.ppuRam, 0x1000); - memcpy (&blockBytes[0x1909], &snssFile->baseBlock.palette, 0x20); - memcpy (&blockBytes[0x1929], &snssFile->baseBlock.mirrorState, 0x4); - tempShort = swap16 (snssFile->baseBlock.vramAddress); - blockBytes[0x192D] = ((char *) &tempShort)[0]; - blockBytes[0x192E] = ((char *) &tempShort)[1]; + memcpy(&blockBytes[0x9], &snssFile->baseBlock.cpuRam, 0x800); + memcpy(&blockBytes[0x809], &snssFile->baseBlock.spriteRam, 0x100); + memcpy(&blockBytes[0x909], &snssFile->baseBlock.ppuRam, 0x1000); + memcpy(&blockBytes[0x1909], &snssFile->baseBlock.palette, 0x20); + memcpy(&blockBytes[0x1929], &snssFile->baseBlock.mirrorState, 0x4); + tempShort = swap16(snssFile->baseBlock.vramAddress); + blockBytes[0x192D] = ((char *)&tempShort)[0]; + blockBytes[0x192E] = ((char *)&tempShort)[1]; blockBytes[0x192F] = snssFile->baseBlock.spriteRamAddress; blockBytes[0x1930] = snssFile->baseBlock.tileXOffset; - if (fwrite (blockBytes, BASE_BLOCK_LENGTH, 1, snssFile->fp) != 1) + if (fwrite(blockBytes, BASE_BLOCK_LENGTH, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -457,17 +457,17 @@ SNSS_WriteBaseBlock (SNSS_FILE *snssFile) /* functions for reading and writing VRAM blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadVramBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadVramBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; - if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK) + if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) { return SNSS_READ_FAILED; } - if (fread (snssFile->vramBlock.vram, MIN (header.blockLength, VRAM_16K), 1, snssFile->fp) != 1) + if (fread(snssFile->vramBlock.vram, MIN(header.blockLength, VRAM_16K), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } @@ -479,22 +479,22 @@ SNSS_ReadVramBlock (SNSS_FILE *snssFile) /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteVramBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteVramBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; - strcpy (header.tag, "VRAM"); + strcpy(header.tag, "VRAM"); header.blockVersion = SNSS_BLOCK_VERSION; header.blockLength = snssFile->vramBlock.vramSize; - if ((returnCode = SNSS_WriteBlockHeader (&header, snssFile)) != SNSS_OK) + if ((returnCode = SNSS_WriteBlockHeader(&header, snssFile)) != SNSS_OK) { return returnCode; } - if (fwrite (snssFile->vramBlock.vram, snssFile->vramBlock.vramSize, 1, snssFile->fp) != 1) + if (fwrite(snssFile->vramBlock.vram, snssFile->vramBlock.vramSize, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -508,23 +508,23 @@ SNSS_WriteVramBlock (SNSS_FILE *snssFile) /* functions for reading and writing SRAM blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadSramBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadSramBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; - if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK) + if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) { return SNSS_READ_FAILED; } - if (fread (&snssFile->sramBlock.sramEnabled, 1, 1, snssFile->fp) != 1) + if (fread(&snssFile->sramBlock.sramEnabled, 1, 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } /* read blockLength - 1 bytes to get all of the SRAM */ - if (fread (&snssFile->sramBlock.sram, MIN (header.blockLength - 1, SRAM_8K), 1, snssFile->fp) != 1) + if (fread(&snssFile->sramBlock.sram, MIN(header.blockLength - 1, SRAM_8K), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } @@ -537,27 +537,27 @@ SNSS_ReadSramBlock (SNSS_FILE *snssFile) /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteSramBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteSramBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; - strcpy (header.tag, "SRAM"); + strcpy(header.tag, "SRAM"); header.blockVersion = SNSS_BLOCK_VERSION; /* length of block is size of SRAM plus SRAM enabled byte */ header.blockLength = snssFile->sramBlock.sramSize + 1; - if ((returnCode = SNSS_WriteBlockHeader (&header, snssFile)) != SNSS_OK) + if ((returnCode = SNSS_WriteBlockHeader(&header, snssFile)) != SNSS_OK) { return returnCode; } - if (fwrite (&snssFile->sramBlock.sramEnabled, 1, 1, snssFile->fp) != 1) + if (fwrite(&snssFile->sramBlock.sramEnabled, 1, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } - if (fwrite (snssFile->sramBlock.sram, snssFile->sramBlock.sramSize, 1, snssFile->fp) != 1) + if (fwrite(snssFile->sramBlock.sram, snssFile->sramBlock.sramSize, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -571,24 +571,24 @@ SNSS_WriteSramBlock (SNSS_FILE *snssFile) /* functions for reading and writing mapper data blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadMapperBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadMapperBlock(SNSS_FILE *snssFile) { char *blockBytes; int i; SnssBlockHeader header; - if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK) + if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) { return SNSS_READ_FAILED; } - if ((blockBytes = (char *) malloc (0x8 + 0x10 + 0x80)) == NULL) + if ((blockBytes = (char *)malloc(0x8 + 0x10 + 0x80)) == NULL) { return SNSS_OUT_OF_MEMORY; } - if (fread (blockBytes, MIN (0x8 + 0x10 + 0x80, header.blockLength), 1, snssFile->fp) != 1) + if (fread(blockBytes, MIN(0x8 + 0x10 + 0x80, header.blockLength), 1, snssFile->fp) != 1) { free(blockBytes); return SNSS_READ_FAILED; @@ -596,27 +596,27 @@ SNSS_ReadMapperBlock (SNSS_FILE *snssFile) for (i = 0; i < 4; i++) { - snssFile->mapperBlock.prgPages[i] = *((unsigned short *) &blockBytes[i * 2]); - snssFile->mapperBlock.prgPages[i] = swap16 (snssFile->mapperBlock.prgPages[i]); + snssFile->mapperBlock.prgPages[i] = *((unsigned short *)&blockBytes[i * 2]); + snssFile->mapperBlock.prgPages[i] = swap16(snssFile->mapperBlock.prgPages[i]); } for (i = 0; i < 8; i++) { - snssFile->mapperBlock.chrPages[i] = *((unsigned short *) &blockBytes[0x8 + (i * 2)]); - snssFile->mapperBlock.chrPages[i] = swap16 (snssFile->mapperBlock.chrPages[i]); + snssFile->mapperBlock.chrPages[i] = *((unsigned short *)&blockBytes[0x8 + (i * 2)]); + snssFile->mapperBlock.chrPages[i] = swap16(snssFile->mapperBlock.chrPages[i]); } - memcpy (&snssFile->mapperBlock.extraData.mapperData, &blockBytes[0x18], 0x80); + memcpy(&snssFile->mapperBlock.extraData.mapperData, &blockBytes[0x18], 0x80); - free (blockBytes); + free(blockBytes); return SNSS_OK; } /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteMapperBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteMapperBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; char blockBytes[MAPPER_BLOCK_LENGTH]; @@ -624,32 +624,32 @@ SNSS_WriteMapperBlock (SNSS_FILE *snssFile) int i; SNSS_RETURN_CODE returnCode; - strcpy (header.tag, "MPRD"); + strcpy(header.tag, "MPRD"); header.blockVersion = SNSS_BLOCK_VERSION; header.blockLength = MAPPER_BLOCK_LENGTH; - if ((returnCode = SNSS_WriteBlockHeader (&header, snssFile)) != SNSS_OK) + if ((returnCode = SNSS_WriteBlockHeader(&header, snssFile)) != SNSS_OK) { return returnCode; } for (i = 0; i < 4; i++) { - tempShort = swap16 (snssFile->mapperBlock.prgPages[i]); - blockBytes[(i * 2) + 0] = ((char *) &tempShort)[0]; - blockBytes[(i * 2) + 1] = ((char *) &tempShort)[1]; + tempShort = swap16(snssFile->mapperBlock.prgPages[i]); + blockBytes[(i * 2) + 0] = ((char *)&tempShort)[0]; + blockBytes[(i * 2) + 1] = ((char *)&tempShort)[1]; } for (i = 0; i < 8; i++) { - tempShort = swap16 (snssFile->mapperBlock.chrPages[i]); - blockBytes[0x8 + (i * 2) + 0] = ((char *) &tempShort)[0]; - blockBytes[0x8 + (i * 2) + 1] = ((char *) &tempShort)[1]; + tempShort = swap16(snssFile->mapperBlock.chrPages[i]); + blockBytes[0x8 + (i * 2) + 0] = ((char *)&tempShort)[0]; + blockBytes[0x8 + (i * 2) + 1] = ((char *)&tempShort)[1]; } - memcpy (&blockBytes[0x18], &snssFile->mapperBlock.extraData.mapperData, 0x80); + memcpy(&blockBytes[0x18], &snssFile->mapperBlock.extraData.mapperData, 0x80); - if (fwrite (blockBytes, MAPPER_BLOCK_LENGTH, 1, snssFile->fp) != 1) + if (fwrite(blockBytes, MAPPER_BLOCK_LENGTH, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -663,8 +663,8 @@ SNSS_WriteMapperBlock (SNSS_FILE *snssFile) /* functions for reading and writing controller data blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadControllersBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadControllersBlock(SNSS_FILE *snssFile) { /* quell warnings */ snssFile = snssFile; @@ -674,8 +674,8 @@ SNSS_ReadControllersBlock (SNSS_FILE *snssFile) /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteControllersBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteControllersBlock(SNSS_FILE *snssFile) { /* quell warnings */ snssFile = snssFile; @@ -687,17 +687,17 @@ SNSS_WriteControllersBlock (SNSS_FILE *snssFile) /* functions for reading and writing sound blocks */ /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_ReadSoundBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_ReadSoundBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; - if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK) + if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) { return SNSS_READ_FAILED; } - if (fread (snssFile->soundBlock.soundRegisters, MIN (header.blockLength, 0x16), 1, snssFile->fp) != 1) + if (fread(snssFile->soundBlock.soundRegisters, MIN(header.blockLength, 0x16), 1, snssFile->fp) != 1) { return SNSS_READ_FAILED; } @@ -707,22 +707,22 @@ SNSS_ReadSoundBlock (SNSS_FILE *snssFile) /**************************************************************************/ -static SNSS_RETURN_CODE -SNSS_WriteSoundBlock (SNSS_FILE *snssFile) +static SNSS_RETURN_CODE +SNSS_WriteSoundBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; - strcpy (header.tag, "SOUN"); + strcpy(header.tag, "SOUN"); header.blockVersion = SNSS_BLOCK_VERSION; header.blockLength = SOUND_BLOCK_LENGTH; - if ((returnCode = SNSS_WriteBlockHeader (&header, snssFile)) != SNSS_OK) + if ((returnCode = SNSS_WriteBlockHeader(&header, snssFile)) != SNSS_OK) { return returnCode; } - if (fwrite (snssFile->soundBlock.soundRegisters, SOUND_BLOCK_LENGTH, 1, snssFile->fp) != 1) + if (fwrite(snssFile->soundBlock.soundRegisters, SOUND_BLOCK_LENGTH, 1, snssFile->fp) != 1) { return SNSS_WRITE_FAILED; } @@ -737,62 +737,62 @@ SNSS_WriteSoundBlock (SNSS_FILE *snssFile) /**************************************************************************/ SNSS_RETURN_CODE -SNSS_ReadBlock (SNSS_FILE *snssFile, SNSS_BLOCK_TYPE blockType) +SNSS_ReadBlock(SNSS_FILE *snssFile, SNSS_BLOCK_TYPE blockType) { switch (blockType) { case SNSS_BASR: - return SNSS_ReadBaseBlock (snssFile); + return SNSS_ReadBaseBlock(snssFile); case SNSS_VRAM: - return SNSS_ReadVramBlock (snssFile); + return SNSS_ReadVramBlock(snssFile); case SNSS_SRAM: - return SNSS_ReadSramBlock (snssFile); + return SNSS_ReadSramBlock(snssFile); case SNSS_MPRD: - return SNSS_ReadMapperBlock (snssFile); + return SNSS_ReadMapperBlock(snssFile); case SNSS_CNTR: - return SNSS_ReadControllersBlock (snssFile); + return SNSS_ReadControllersBlock(snssFile); case SNSS_SOUN: - return SNSS_ReadSoundBlock (snssFile); + return SNSS_ReadSoundBlock(snssFile); case SNSS_UNKNOWN_BLOCK: default: - return SNSS_UNSUPPORTED_BLOCK; + return SNSS_UNSUPPORTED_BLOCK; } } /**************************************************************************/ SNSS_RETURN_CODE -SNSS_WriteBlock (SNSS_FILE *snssFile, SNSS_BLOCK_TYPE blockType) +SNSS_WriteBlock(SNSS_FILE *snssFile, SNSS_BLOCK_TYPE blockType) { switch (blockType) { case SNSS_BASR: - return SNSS_WriteBaseBlock (snssFile); + return SNSS_WriteBaseBlock(snssFile); case SNSS_VRAM: - return SNSS_WriteVramBlock (snssFile); + return SNSS_WriteVramBlock(snssFile); case SNSS_SRAM: - return SNSS_WriteSramBlock (snssFile); + return SNSS_WriteSramBlock(snssFile); case SNSS_MPRD: - return SNSS_WriteMapperBlock (snssFile); + return SNSS_WriteMapperBlock(snssFile); case SNSS_CNTR: - return SNSS_WriteControllersBlock (snssFile); + return SNSS_WriteControllersBlock(snssFile); case SNSS_SOUN: - return SNSS_WriteSoundBlock (snssFile); + return SNSS_WriteSoundBlock(snssFile); case SNSS_UNKNOWN_BLOCK: default: - return SNSS_UNSUPPORTED_BLOCK; + return SNSS_UNSUPPORTED_BLOCK; } } diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index 08580f0..2b780a2 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -40,47 +40,45 @@ extern char *osd_getromdata(); /* Max length for displayed filename */ -#define ROM_DISP_MAXLEN 20 - +#define ROM_DISP_MAXLEN 20 #ifdef ZLIB #include -#define _fopen gzopen -#define _fclose gzclose -#define _fread(B,N,L,F) gzread((F),(B),(L)*(N)) +#define _fopen gzopen +#define _fclose gzclose +#define _fread(B, N, L, F) gzread((F), (B), (L) * (N)) #else -#define _fopen fopen -#define _fclose fclose -#define _fread(B,N,L,F) fread((B),(N),(L),(F)) +#define _fopen fopen +#define _fclose fclose +#define _fread(B, N, L, F) fread((B), (N), (L), (F)) #endif -#define ROM_FOURSCREEN 0x08 -#define ROM_TRAINER 0x04 -#define ROM_BATTERY 0x02 -#define ROM_MIRRORTYPE 0x01 -#define ROM_INES_MAGIC "NES\x1A" +#define ROM_FOURSCREEN 0x08 +#define ROM_TRAINER 0x04 +#define ROM_BATTERY 0x02 +#define ROM_MIRRORTYPE 0x01 +#define ROM_INES_MAGIC "NES\x1A" //ToDo: packed - JD typedef struct inesheader_s { - uint8 ines_magic[4] ; - uint8 rom_banks ; - uint8 vrom_banks ; - uint8 rom_type ; - uint8 mapper_hinybble ; - uint8 reserved[8] ; + uint8 ines_magic[4]; + uint8 rom_banks; + uint8 vrom_banks; + uint8 rom_type; + uint8 mapper_hinybble; + uint8 reserved[8]; } inesheader_t; +#define TRAINER_OFFSET 0x1000 +#define TRAINER_LENGTH 0x200 +#define VRAM_LENGTH 0x2000 -#define TRAINER_OFFSET 0x1000 -#define TRAINER_LENGTH 0x200 -#define VRAM_LENGTH 0x2000 - -#define ROM_BANK_LENGTH 0x4000 -#define VROM_BANK_LENGTH 0x2000 +#define ROM_BANK_LENGTH 0x4000 +#define VROM_BANK_LENGTH 0x2000 -#define SRAM_BANK_LENGTH 0x0400 -#define VRAM_BANK_LENGTH 0x2000 +#define SRAM_BANK_LENGTH 0x0400 +#define VRAM_BANK_LENGTH 0x2000 /* Save battery-backed RAM */ static void rom_savesram(rominfo_t *rominfo) @@ -152,9 +150,9 @@ static void rom_loadtrainer(unsigned char **rom, rominfo_t *rominfo) if (rominfo->flags & ROM_FLAG_TRAINER) { -// fread(rominfo->sram + TRAINER_OFFSET, TRAINER_LENGTH, 1, fp); + // fread(rominfo->sram + TRAINER_OFFSET, TRAINER_LENGTH, 1, fp); memcpy(rominfo->sram + TRAINER_OFFSET, *rom, TRAINER_LENGTH); - rom+=TRAINER_LENGTH; + rom += TRAINER_LENGTH; log_printf("Read in trainer at $7000\n"); } } @@ -165,7 +163,7 @@ static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) ASSERT(rominfo); /* Allocate ROM space, and load it up! */ -/* + /* rominfo->rom = malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); if (NULL == rominfo->rom) { @@ -174,14 +172,13 @@ static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) } _fread(rominfo->rom, ROM_BANK_LENGTH, rominfo->rom_banks, fp); */ - rominfo->rom=*rom; - *rom+=ROM_BANK_LENGTH*rominfo->rom_banks; - + rominfo->rom = *rom; + *rom += ROM_BANK_LENGTH * rominfo->rom_banks; /* If there's VROM, allocate and stuff it in */ if (rominfo->vrom_banks) { -/* + /* rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); if (NULL == rominfo->vrom) { @@ -190,9 +187,8 @@ static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) } _fread(rominfo->vrom, VROM_BANK_LENGTH, rominfo->vrom_banks, fp); */ - rominfo->vrom=*rom; - *rom+=VROM_BANK_LENGTH*rominfo->vrom_banks; - + rominfo->vrom = *rom; + *rom += VROM_BANK_LENGTH * rominfo->vrom_banks; } else { @@ -270,7 +266,7 @@ static FILE *rom_findrom(const char *filename, rominfo_t *rominfo) static int rom_adddirty(char *filename) { #ifdef NOFRENDO_DEBUG -#define MAX_BUFFER_LENGTH 255 +#define MAX_BUFFER_LENGTH 255 char buffer[MAX_BUFFER_LENGTH + 1]; bool found = false; @@ -325,7 +321,7 @@ int rom_checkmagic(const char *filename) static int rom_getheader(unsigned char **rom, rominfo_t *rominfo) { -#define RESERVED_LENGTH 8 +#define RESERVED_LENGTH 8 inesheader_t head; uint8 reserved[RESERVED_LENGTH]; bool header_dirty; @@ -335,10 +331,10 @@ static int rom_getheader(unsigned char **rom, rominfo_t *rominfo) ASSERT(rominfo); /* Read in the header */ -// _fread(&head, 1, sizeof(head), fp); - printf("Head: %p (%x %x %x %x)\n", *rom, (*rom)[0], (*rom)[1], (*rom)[2], (*rom)[3]); - memcpy(&head, *rom, sizeof(head)); - *rom+=sizeof(head); + // _fread(&head, 1, sizeof(head), fp); + printf("Head: %p (%x %x %x %x)\n", *rom, (*rom)[0], (*rom)[1], (*rom)[2], (*rom)[3]); + memcpy(&head, *rom, sizeof(head)); + *rom += sizeof(head); if (memcmp(head.ines_magic, ROM_INES_MAGIC, 4)) { @@ -421,7 +417,7 @@ char *rom_getinfo(rominfo_t *rominfo) sprintf(temp, " [%d] %dk/%dk %c", rominfo->mapper_number, rominfo->rom_banks * 16, rominfo->vrom_banks * 8, (rominfo->mirror == MIRROR_VERT) ? 'V' : 'H'); - + /* Stick it on there! */ strncat(info, temp, PATH_MAX - strlen(info)); @@ -438,7 +434,7 @@ char *rom_getinfo(rominfo_t *rominfo) /* Load a ROM image into memory */ rominfo_t *rom_load(const char *filename) { - unsigned char *rom=(unsigned char*)osd_getromdata(); + unsigned char *rom = (unsigned char *)osd_getromdata(); rominfo_t *rominfo; rominfo = malloc(sizeof(rominfo_t)); @@ -448,7 +444,7 @@ rominfo_t *rom_load(const char *filename) memset(rominfo, 0, sizeof(rominfo_t)); /* Get the header and stick it into rominfo struct */ - if (rom_getheader(&rom, rominfo)) + if (rom_getheader(&rom, rominfo)) goto _fail; /* Make sure we really support the mapper */ @@ -463,17 +459,20 @@ rominfo_t *rom_load(const char *filename) ** UNIF, TAKE ME AWAY! AAAAAAAAAA!!! */ if (rom_allocsram(rominfo)) + { goto _fail; + } + rom_loadtrainer(&rom, rominfo); - rom_loadtrainer(&rom, rominfo); - - if (rom_loadrom(&rom, rominfo)) + if (rom_loadrom(&rom, rominfo)) + { goto _fail; + } rom_loadsram(rominfo); /* See if there's a palette we can load up */ -// rom_checkforpal(rominfo); + // rom_checkforpal(rominfo); gui_sendmsg(GUI_GREEN, "ROM loaded: %s", rom_getinfo(rominfo)); From 0c8acd42ae14bf7c7c399ccee0b232388b47746d Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 11 Feb 2020 08:54:47 +0800 Subject: [PATCH 17/73] expose IPS settings to all hardware --- components/nofrendo-esp32/Kconfig.projbuild | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 0ae14d8..800efc4 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -37,14 +37,19 @@ endchoice config HW_LCD_IPS bool "IPS type LCD (inverted color)" - depends on HW_CUSTOM || HW_WROVERKIT_V2 || HW_ODROID_GO - default n + default n if HW_WROVERKIT_V1 + default n if HW_WROVERKIT_V2 + default n if HW_M5STACK + default n HW_ODROID_GO + default n if HW_CUSTOM config HW_WROVERKIT bool - default n if HW_CUSTOM default y if HW_WROVERKIT_V1 default y if HW_WROVERKIT_V2 + default n if HW_M5STACK + default n HW_ODROID_GO + default n if HW_CUSTOM config HW_LCD_TYPE @@ -53,6 +58,7 @@ config HW_LCD_TYPE default 0 if HW_LCD_TYPE_ILI default 1 if HW_LCD_TYPE_ST default 2 if HW_M5STACK + default 0 if HW_CUSTOM config HW_LCD_MISO_GPIO_CUST int "LCD MISO pin" From 8333874e1e12b30a30d3634f973ffafe81fec8c4 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 11 Feb 2020 09:22:32 +0800 Subject: [PATCH 18/73] fix check CONFIG_HW_LCD_IPS logic --- components/nofrendo-esp32/spi_lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index e9c3c8c..7eb5a16 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -135,7 +135,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, #endif -#ifdef CONFIG_HW_LCD_IPS +#if (CONFIG_HW_LCD_IPS == 'Y') {0x21, {0}, 0x80}, #endif {0x11, {0}, 0x80}, From 5be67c439ac424803da5d99f06d0c060f3dea579 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 7 Mar 2020 22:32:58 +0800 Subject: [PATCH 19/73] typo --- components/nofrendo-esp32/Kconfig.projbuild | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 800efc4..96f1948 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -40,7 +40,7 @@ config HW_LCD_IPS default n if HW_WROVERKIT_V1 default n if HW_WROVERKIT_V2 default n if HW_M5STACK - default n HW_ODROID_GO + default n if HW_ODROID_GO default n if HW_CUSTOM config HW_WROVERKIT @@ -48,7 +48,7 @@ config HW_WROVERKIT default y if HW_WROVERKIT_V1 default y if HW_WROVERKIT_V2 default n if HW_M5STACK - default n HW_ODROID_GO + default n if HW_ODROID_GO default n if HW_CUSTOM From 8128bef67016100f56d58f5838a8acd7069001cd Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 7 Mar 2020 22:51:08 +0800 Subject: [PATCH 20/73] typo --- components/nofrendo-esp32/spi_lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 7eb5a16..21f173d 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -135,7 +135,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, #endif -#if (CONFIG_HW_LCD_IPS == 'Y') +#if (CONFIG_HW_LCD_IPS == 1) {0x21, {0}, 0x80}, #endif {0x11, {0}, 0x80}, From 101bbc0b7d118024e84dea2e4e800b92ee841658 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sun, 5 Apr 2020 00:29:40 +0800 Subject: [PATCH 21/73] support ST7796 --- components/nofrendo-esp32/Kconfig.projbuild | 15 ++-- components/nofrendo-esp32/spi_lcd.c | 80 +++++++++++++++------ 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 96f1948..9c3d92c 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -27,12 +27,15 @@ choice HW_LCD_TYPE_SEL prompt "LCD type" depends on HW_CUSTOM || HW_WROVERKIT_V2 || HW_ODROID_GO -config HW_LCD_TYPE_ILI +config HW_LCD_TYPE_ILI9341 bool "ILI9341 LCD" -config HW_LCD_TYPE_ST +config HW_LCD_TYPE_ST7789 bool "ST7789V LCD" +config HW_LCD_TYPE_ST7796 + bool "ST7796 LCD" + endchoice config HW_LCD_IPS @@ -55,10 +58,10 @@ config HW_WROVERKIT config HW_LCD_TYPE int default 0 if HW_WROVERKIT_V1 - default 0 if HW_LCD_TYPE_ILI - default 1 if HW_LCD_TYPE_ST - default 2 if HW_M5STACK - default 0 if HW_CUSTOM + default 0 if HW_LCD_TYPE_ILI9341 + default 1 if HW_M5STACK + default 2 if HW_LCD_TYPE_ST7789 + default 3 if HW_LCD_TYPE_ST7796 config HW_LCD_MISO_GPIO_CUST int "LCD MISO pin" diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 21f173d..f6218ec 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -41,9 +41,10 @@ #define SPI_NUM 0x3 -#define LCD_TYPE_ILI 0 -#define LCD_TYPE_ST 1 -#define LCD_TYPE_M5STACK 2 +#define LCD_TYPE_ILI9341 0 +#define LCD_TYPE_M5STACK 1 +#define LCD_TYPE_ST7789 2 +#define LCD_TYPE_ST7796 3 #define LCD_SEL_CMD() gpio_set_level(PIN_NUM_DC, 0) // Low to send command #define LCD_SEL_DATA() gpio_set_level(PIN_NUM_DC, 1) // High to send data @@ -63,7 +64,7 @@ typedef struct spi_device_handle_t spi; DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { -#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ILI) +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ILI9341) {0xCF, {0x00, 0x83, 0X30}, 3}, {0xED, {0x64, 0x03, 0X12, 0X81}, 4}, {0xE8, {0x85, 0x01, 0x79}, 3}, @@ -91,25 +92,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xB7, {0x07}, 1}, {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4}, // Display Function Control, 8 82 27 #endif -#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST) -#ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1<<6)|(1<<5)}, 1}, // MX | MV | RGB -#else - {0x36, {(1<<7)|(1<<5)}, 1}, // MY | MV | RGB -#endif - {0x3A, {0x55}, 1}, - {0xB2, {0x0c, 0x0c, 0x00, 0x33, 0x33}, 5}, - {0xB7, {0x35}, 1}, - {0xBB, {0x2B}, 1}, - {0xC0, {0x2C}, 1}, - {0xC2, {0x01, 0xFF}, 2}, - {0xC3, {0x11}, 1}, - {0xC4, {0x20}, 1}, - {0xC6, {0x0f}, 1}, - {0xD0, {0xA4, 0xA1}, 2}, - {0xE0, {0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19}, 14}, - {0xE1, {0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19}, 14}, -#endif + #if (CONFIG_HW_LCD_TYPE == LCD_TYPE_M5STACK) {0xEF, {0x03, 0x80, 0x02}, 3}, {0xCF, {0x00, 0XC1, 0X30}, 3}, @@ -135,6 +118,57 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15}, {0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15}, #endif + +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST7789) +#ifdef CONFIG_HW_LCD_ROTATE_180 + {0x36, {(1<<6)|(1<<5)}, 1}, // MX | MV | RGB +#else + {0x36, {(1<<7)|(1<<5)}, 1}, // MY | MV | RGB +#endif + {0x3A, {0x55}, 1}, + {0xB2, {0x0c, 0x0c, 0x00, 0x33, 0x33}, 5}, + {0xB7, {0x35}, 1}, + {0xBB, {0x2B}, 1}, + {0xC0, {0x2C}, 1}, + {0xC2, {0x01, 0xFF}, 2}, + {0xC3, {0x11}, 1}, + {0xC4, {0x20}, 1}, + {0xC6, {0x0f}, 1}, + {0xD0, {0xA4, 0xA1}, 2}, + {0xE0, {0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19}, 14}, + {0xE1, {0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19}, 14}, +#endif + +#if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST7796) +#ifdef CONFIG_HW_LCD_ROTATE_180 + {0x36, {(1<<5)|(1<<3)}, 1}, // MV | BGR +#else + {0x36, {(1<<7)|(1<<6)|(1<<5)|(1<<3)}, 1}, // MY | MX | MV | BGR +#endif + {0xF0, {0xC3}, 1}, + {0xF0, {0x96}, 1}, + {0x3A, {0x05}, 1}, + {0xB0, {0x80}, 1}, + {0xB6, {0x00, 0x02}, 2}, + {0xB5, {0x02, 0x03, 0x00, 0x04}, 4}, + {0xB1, {0x80, 0x10}, 2}, + {0xB4, {0x00}, 1}, + {0xB7, {0xC6}, 1}, + {0xC5, {0x24}, 1}, + {0xE4, {0x31}, 1}, + {0xE8, {0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33}, 8}, + {0xC2, {0}, 0}, + {0xA7, {0}, 0}, + + {0xE0, {0xF0, 0x09, 0x13, 0x12, 0x12, 0x2B, 0x3C, 0x44, 0x4B, 0x1B, 0x18, 0x17, 0x1D, 0x21}, 14}, + + {0XE1, {0xF0, 0x09, 0x13, 0x0C, 0x0D, 0x27, 0x3B, 0x44, 0x4D, 0x0B, 0x17, 0x17, 0x1D, 0x21}, 14}, + + {0xF0, {0xC3}, 1}, + {0xF0, {0x69}, 1}, + {0X13, {0}, 0}, +#endif + #if (CONFIG_HW_LCD_IPS == 1) {0x21, {0}, 0x80}, #endif From c4d60fb388b2be6855af049db638705d5d63321b Mon Sep 17 00:00:00 2001 From: moononournation Date: Sun, 5 Apr 2020 00:30:00 +0800 Subject: [PATCH 22/73] support latest esp-idf --- components/nofrendo-esp32/video_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index 061053d..b48e31c 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -120,7 +120,7 @@ static int osd_init_sound(void) .sample_rate = DEFAULT_SAMPLERATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, - .communication_format = I2S_COMM_FORMAT_I2S_MSB, + .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, .intr_alloc_flags = 0, .dma_buf_count = 2, .dma_buf_len = 512 From c8c870afa03b4607b9ebf4411e58fedec129a9f3 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 6 Apr 2020 18:14:54 +0800 Subject: [PATCH 23/73] handle no reset pin --- components/nofrendo-esp32/spi_lcd.c | 108 ++++++++------- components/nofrendo-esp32/video_audio.c | 171 ++++++++++++------------ 2 files changed, 141 insertions(+), 138 deletions(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index f6218ec..0402740 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -48,8 +48,13 @@ #define LCD_SEL_CMD() gpio_set_level(PIN_NUM_DC, 0) // Low to send command #define LCD_SEL_DATA() gpio_set_level(PIN_NUM_DC, 1) // High to send data +#if (PIN_NUM_RST > -1) #define LCD_RST_SET() gpio_set_level(PIN_NUM_RST, 1) #define LCD_RST_CLR() gpio_set_level(PIN_NUM_RST, 0) +#else +#define LCD_RST_SET() +#define LCD_RST_CLR() +#endif /* The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. @@ -71,19 +76,19 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5}, {0xF7, {0x20}, 1}, {0xEA, {0x00, 0x00}, 2}, - {0xC0, {0x26}, 1}, // Power control, VRH[5:0] - {0xC1, {0x11}, 1}, // Power control, SAP[2:0];BT[3:0] + {0xC0, {0x26}, 1}, // Power control, VRH[5:0] + {0xC1, {0x11}, 1}, // Power control, SAP[2:0];BT[3:0] {0xC5, {0x35, 0x3E}, 2}, // VCM control - {0xC7, {0xBE}, 1}, // VCM control2, was B1h + {0xC7, {0xBE}, 1}, // VCM control2, was B1h #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1<<7)|(1<<6)|(1<<5)|(1<<3)}, 1}, // MY | MX | MV | BGR + {0x36, {(1 << 7) | (1 << 6) | (1 << 5) | (1 << 3)}, 1}, // MY | MX | MV | BGR #else - {0x36, {(1<<5)|(1<<3)}, 1}, // MV | BGR + {0x36, {(1 << 5) | (1 << 3)}, 1}, // MV | BGR #endif {0x3A, {0x55}, 1}, {0xB1, {0x00, 0x1B}, 2}, - {0xF2, {0x08}, 1}, // 3Gamma Function Disable - {0x26, {0x01}, 1}, // Gamma curve selected + {0xF2, {0x08}, 1}, // 3Gamma Function Disable + {0x26, {0x01}, 1}, // Gamma curve selected {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15}, // Set Gamma {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15}, // Set Gamma {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4}, @@ -106,9 +111,9 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC5, {0x3e, 0x28}, 2}, {0xC7, {0x86}, 1}, #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1<<7)|(1<<6)|(1<<3)}, 1}, // MY | MX | BGR + {0x36, {(1 << 7) | (1 << 6) | (1 << 3)}, 1}, // MY | MX | BGR #else - {0x36, {(1<<3)}, 1}, // BGR + {0x36, {(1 << 3)}, 1}, // BGR #endif {0x3A, {0x55}, 1}, {0xB1, {0x00, 0x1B}, 2}, @@ -121,9 +126,9 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { #if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST7789) #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1<<6)|(1<<5)}, 1}, // MX | MV | RGB + {0x36, {(1 << 6) | (1 << 5)}, 1}, // MX | MV | RGB #else - {0x36, {(1<<7)|(1<<5)}, 1}, // MY | MV | RGB + {0x36, {(1 << 7) | (1 << 5)}, 1}, // MY | MV | RGB #endif {0x3A, {0x55}, 1}, {0xB2, {0x0c, 0x0c, 0x00, 0x33, 0x33}, 5}, @@ -141,32 +146,32 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { #if (CONFIG_HW_LCD_TYPE == LCD_TYPE_ST7796) #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1<<5)|(1<<3)}, 1}, // MV | BGR + {0x36, {(1 << 5) | (1 << 3)}, 1}, // MV | BGR #else - {0x36, {(1<<7)|(1<<6)|(1<<5)|(1<<3)}, 1}, // MY | MX | MV | BGR + {0x36, {(1 << 7) | (1 << 6) | (1 << 5) | (1 << 3)}, 1}, // MY | MX | MV | BGR #endif - {0xF0, {0xC3}, 1}, - {0xF0, {0x96}, 1}, - {0x3A, {0x05}, 1}, - {0xB0, {0x80}, 1}, - {0xB6, {0x00, 0x02}, 2}, - {0xB5, {0x02, 0x03, 0x00, 0x04}, 4}, - {0xB1, {0x80, 0x10}, 2}, - {0xB4, {0x00}, 1}, - {0xB7, {0xC6}, 1}, - {0xC5, {0x24}, 1}, - {0xE4, {0x31}, 1}, - {0xE8, {0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33}, 8}, - {0xC2, {0}, 0}, - {0xA7, {0}, 0}, - - {0xE0, {0xF0, 0x09, 0x13, 0x12, 0x12, 0x2B, 0x3C, 0x44, 0x4B, 0x1B, 0x18, 0x17, 0x1D, 0x21}, 14}, - - {0XE1, {0xF0, 0x09, 0x13, 0x0C, 0x0D, 0x27, 0x3B, 0x44, 0x4D, 0x0B, 0x17, 0x17, 0x1D, 0x21}, 14}, - - {0xF0, {0xC3}, 1}, - {0xF0, {0x69}, 1}, - {0X13, {0}, 0}, + {0xF0, {0xC3}, 1}, + {0xF0, {0x96}, 1}, + {0x3A, {0x05}, 1}, + {0xB0, {0x80}, 1}, + {0xB6, {0x00, 0x02}, 2}, + {0xB5, {0x02, 0x03, 0x00, 0x04}, 4}, + {0xB1, {0x80, 0x10}, 2}, + {0xB4, {0x00}, 1}, + {0xB7, {0xC6}, 1}, + {0xC5, {0x24}, 1}, + {0xE4, {0x31}, 1}, + {0xE8, {0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33}, 8}, + {0xC2, {0}, 0}, + {0xA7, {0}, 0}, + + {0xE0, {0xF0, 0x09, 0x13, 0x12, 0x12, 0x2B, 0x3C, 0x44, 0x4B, 0x1B, 0x18, 0x17, 0x1D, 0x21}, 14}, + + {0XE1, {0xF0, 0x09, 0x13, 0x0C, 0x0D, 0x27, 0x3B, 0x44, 0x4D, 0x0B, 0x17, 0x17, 0x1D, 0x21}, 14}, + + {0xF0, {0xC3}, 1}, + {0xF0, {0x69}, 1}, + {0X13, {0}, 0}, #endif #if (CONFIG_HW_LCD_IPS == 1) @@ -211,7 +216,9 @@ void lcd_gpio_init() { //Initialize non-SPI GPIOs gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT); +#if (PIN_NUM_RST > -1) gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT); +#endif //Reset the display LCD_RST_CLR(); @@ -246,35 +253,34 @@ void lcd_spi_pre_transfer_callback(spi_transaction_t *t) void lcd_setBrightness(int duty) { #if (PIN_NUM_BL > -1) +#if (CONFIG_HW_INV_BL == 1) + duty = 1023 - duty; +#endif #define LEDC_HS_TIMER LEDC_TIMER_0 #define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE -#define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0 +#define LEDC_HS_CHANNEL LEDC_CHANNEL_0 #define LEDC_TEST_DUTY (10) ledc_timer_config_t ledc_timer = { - .bit_num = LEDC_TIMER_10_BIT, // resolution of PWM duty - .freq_hz = 5000, // frequency of PWM signal - .speed_mode = LEDC_HS_MODE, // timer mode - .timer_num = LEDC_HS_TIMER // timer index + .speed_mode = LEDC_HS_MODE, // timer mode + .duty_resolution = LEDC_TIMER_10_BIT, // resolution of PWM duty + .timer_num = LEDC_HS_TIMER, // timer index + .freq_hz = 5000, // frequency of PWM signal + .clk_cfg = LEDC_USE_APB_CLK, }; // Set configuration of timer0 for high speed channels ledc_timer_config(&ledc_timer); ledc_channel_config_t ledc_channel = { - .channel = LEDC_HS_CH0_CHANNEL, - .duty = 0, + .channel = LEDC_HS_CHANNEL, + .duty = duty, .gpio_num = PIN_NUM_BL, .speed_mode = LEDC_HS_MODE, .timer_sel = LEDC_HS_TIMER}; ledc_channel_config(&ledc_channel); - -#ifdef HW_INV_BL - ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, 1023 - duty); -#else - ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, duty); -#endif - ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel); + // ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, duty); + // ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel); #endif } @@ -383,11 +389,11 @@ void lcd_init() }; //Initialize the SPI bus ret = spi_bus_initialize(VSPI_HOST, &buscfg, 1); - assert(ret==ESP_OK); + assert(ret == ESP_OK); //Attach the LCD to the SPI bus ret = spi_bus_add_device(VSPI_HOST, &devcfg, &spi); - assert(ret==ESP_OK); + assert(ret == ESP_OK); //Initialize GPIO lcd_gpio_init(); diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index b48e31c..e2d5193 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -21,7 +21,6 @@ #undef true #undef bool - #include #include #include @@ -49,12 +48,11 @@ #include #endif -#define DEFAULT_SAMPLERATE 22100 -#define DEFAULT_FRAGSIZE 128 - -#define DEFAULT_WIDTH 256 -#define DEFAULT_HEIGHT NES_VISIBLE_HEIGHT +#define DEFAULT_SAMPLERATE 22100 +#define DEFAULT_FRAGSIZE 128 +#define DEFAULT_WIDTH 256 +#define DEFAULT_HEIGHT NES_VISIBLE_HEIGHT TimerHandle_t timer; @@ -62,12 +60,11 @@ TimerHandle_t timer; int osd_installtimer(int frequency, void *func, int funcsize, void *counter, int countersize) { printf("Timer install, freq=%d\n", frequency); - timer=xTimerCreate("nes",configTICK_RATE_HZ/frequency, pdTRUE, NULL, func); + timer = xTimerCreate("nes", configTICK_RATE_HZ / frequency, pdTRUE, NULL, func); xTimerStart(timer, 0); - return 0; + return 0; } - /* ** Audio */ @@ -77,23 +74,26 @@ QueueHandle_t queue; static int16_t *audio_frame; #endif - -static void do_audio_frame() { +static void do_audio_frame() +{ #if CONFIG_SOUND_ENA - int left=DEFAULT_SAMPLERATE/NES_REFRESH_RATE; - while(left) { - int n=DEFAULT_FRAGSIZE; - if (n>left) n=left; + int left = DEFAULT_SAMPLERATE / NES_REFRESH_RATE; + while (left) + { + int n = DEFAULT_FRAGSIZE; + if (n > left) + n = left; audio_callback(audio_frame, n); //get more data //16 bit mono -> 32-bit (16 bit r+l) - for (int i=n-1; i>=0; i--) { + for (int i = n - 1; i >= 0; i--) + { audio_frame[i] = audio_frame[i] + 0x8000; // audio_frame[i*2+1] = audio_frame[i] + 0x8000; // audio_frame[i*2] = audio_frame[i] + 0x8000; } size_t i2s_bytes_write; - i2s_write(0, (const char *)audio_frame, 2*n, &i2s_bytes_write, portMAX_DELAY); + i2s_write(0, (const char *)audio_frame, 2 * n, &i2s_bytes_write, portMAX_DELAY); left -= i2s_bytes_write / 2; } #endif @@ -101,16 +101,15 @@ static void do_audio_frame() { void osd_setsound(void (*playfunc)(void *buffer, int length)) { - //Indicates we should call playfunc() to get more data. - audio_callback = playfunc; + //Indicates we should call playfunc() to get more data. + audio_callback = playfunc; } static void osd_stopsound(void) { - audio_callback = NULL; + audio_callback = NULL; } - static int osd_init_sound(void) { #if CONFIG_SOUND_ENA @@ -123,12 +122,12 @@ static int osd_init_sound(void) .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, .intr_alloc_flags = 0, .dma_buf_count = 2, - .dma_buf_len = 512 + .dma_buf_len = 512, }; i2s_driver_install(0, &cfg, 2, &queue); i2s_set_pin(0, NULL); - // i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN); - i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); + // i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN); + i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); //I2S enables *both* DAC channels; we only need DAC1. //ToDo: still needed now I2S supports set_dac_mode? @@ -143,8 +142,8 @@ static int osd_init_sound(void) void osd_getsoundinfo(sndinfo_t *info) { - info->sample_rate = DEFAULT_SAMPLERATE; - info->bps = 16; + info->sample_rate = DEFAULT_SAMPLERATE; + info->bps = 16; } /* @@ -164,27 +163,26 @@ static char fb[1]; //dummy QueueHandle_t vidQueue; viddriver_t sdlDriver = -{ - "Simple DirectMedia Layer", /* name */ - init, /* init */ - shutdown, /* shutdown */ - set_mode, /* set_mode */ - set_palette, /* set_palette */ - clear, /* clear */ - lock_write, /* lock_write */ - free_write, /* free_write */ - custom_blit, /* custom_blit */ - false /* invalidate flag */ + { + "Simple DirectMedia Layer", /* name */ + init, /* init */ + shutdown, /* shutdown */ + set_mode, /* set_mode */ + set_palette, /* set_palette */ + clear, /* clear */ + lock_write, /* lock_write */ + free_write, /* free_write */ + custom_blit, /* custom_blit */ + false /* invalidate flag */ }; - bitmap_t *myBitmap; void osd_getvideoinfo(vidinfo_t *info) { - info->default_width = DEFAULT_WIDTH; - info->default_height = DEFAULT_HEIGHT; - info->driver = &sdlDriver; + info->default_width = DEFAULT_WIDTH; + info->default_height = DEFAULT_HEIGHT; + info->driver = &sdlDriver; } /* flip between full screen and windowed */ @@ -205,7 +203,7 @@ static void shutdown(void) /* set a video mode */ static int set_mode(int width, int height) { - return 0; + return 0; } uint16 myPalette[256]; @@ -215,60 +213,57 @@ static void set_palette(rgb_t *pal) { uint16 c; - int i; - - for (i = 0; i < 256; i++) - { - c=(pal[i].b>>3)+((pal[i].g>>2)<<5)+((pal[i].r>>3)<<11); - //myPalette[i]=(c>>8)|((c&0xff)<<8); - myPalette[i]=c; - } + int i; + for (i = 0; i < 256; i++) + { + c = (pal[i].b >> 3) + ((pal[i].g >> 2) << 5) + ((pal[i].r >> 3) << 11); + //myPalette[i]=(c>>8)|((c&0xff)<<8); + myPalette[i] = c; + } } /* clear all frames to a particular color */ static void clear(uint8 color) { -// SDL_FillRect(mySurface, 0, color); + // SDL_FillRect(mySurface, 0, color); } - - /* acquire the directbuffer for writing */ static bitmap_t *lock_write(void) { -// SDL_LockSurface(mySurface); - myBitmap = bmp_createhw((uint8*)fb, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH*2); - return myBitmap; + // SDL_LockSurface(mySurface); + myBitmap = bmp_createhw((uint8 *)fb, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 2); + return myBitmap; } /* release the resource */ static void free_write(int num_dirties, rect_t *dirty_rects) { - bmp_destroy(&myBitmap); + bmp_destroy(&myBitmap); } - -static void custom_blit(bitmap_t *bmp, int num_dirties, rect_t *dirty_rects) { +static void custom_blit(bitmap_t *bmp, int num_dirties, rect_t *dirty_rects) +{ xQueueSend(vidQueue, &bmp, 0); do_audio_frame(); } - //This runs on core 1. -static void videoTask(void *arg) { +static void videoTask(void *arg) +{ int x, y; - bitmap_t *bmp=NULL; - x = (320-DEFAULT_WIDTH)/2; - y = ((240-DEFAULT_HEIGHT)/2); - while(1) { -// xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30 + bitmap_t *bmp = NULL; + x = (320 - DEFAULT_WIDTH) / 2; + y = ((240 - DEFAULT_HEIGHT) / 2); + while (1) + { + // xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30 xQueueReceive(vidQueue, &bmp, portMAX_DELAY); lcd_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line); } } - /* ** Input */ @@ -288,32 +283,34 @@ static void osd_initinput() void osd_getinput(void) { - const int ev[16]={ - event_joypad1_select,0,0,event_joypad1_start,event_joypad1_up,event_joypad1_right,event_joypad1_down,event_joypad1_left, - 0,0,0,0,event_soft_reset,event_joypad1_a,event_joypad1_b,event_hard_reset - }; - static int oldb=0xffff; + const int ev[16] = { + event_joypad1_select, 0, 0, event_joypad1_start, event_joypad1_up, event_joypad1_right, event_joypad1_down, event_joypad1_left, + 0, 0, 0, 0, event_soft_reset, event_joypad1_a, event_joypad1_b, event_hard_reset}; + static int oldb = 0xffff; #if defined CONFIG_HW_CONTROLLER_GPIO - int b=gpioReadInput(); + int b = gpioReadInput(); #elif defined CONFIG_HW_CONTROLLER_PSX - int b=psxReadInput(); + int b = psxReadInput(); #elif defined CONFIG_HW_CONTROLLER_I2C_GP - int b=i2c_gpReadInput(); + int b = i2c_gpReadInput(); #elif defined CONFIG_HW_CONTROLLER_I2C_KB - int b=i2c_kbReadInput(); + int b = i2c_kbReadInput(); #endif - int chg=b^oldb; + int chg = b ^ oldb; int x; - oldb=b; + oldb = b; event_t evh; // printf("Input: %x\n", b); - for (x=0; x<16; x++) { - if (chg&1) { - evh=event_get(ev[x]); - if (evh) evh((b&1)?INP_STATE_BREAK:INP_STATE_MAKE); + for (x = 0; x < 16; x++) + { + if (chg & 1) + { + evh = event_get(ev[x]); + if (evh) + evh((b & 1) ? INP_STATE_BREAK : INP_STATE_MAKE); } - chg>>=1; - b>>=1; + chg >>= 1; + b >>= 1; } } @@ -338,7 +335,7 @@ void osd_shutdown() static int logprint(const char *string) { - return printf("%s", string); + return printf("%s", string); } /* @@ -353,8 +350,8 @@ int osd_init() return -1; lcd_init(); - lcd_write_frame(0,0,320,240,NULL); - vidQueue=xQueueCreate(1, sizeof(bitmap_t *)); + lcd_write_frame(0, 0, 320, 240, NULL); + vidQueue = xQueueCreate(1, sizeof(bitmap_t *)); xTaskCreatePinnedToCore(&videoTask, "videoTask", 2048, NULL, 5, NULL, 1); osd_initinput(); return 0; From 0f17a1b933f9f114c7d4696a16e79cc65af40e12 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 7 Apr 2020 09:52:31 +0800 Subject: [PATCH 24/73] fix audio --- components/nofrendo-esp32/video_audio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index e2d5193..7cf5a4f 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -119,10 +119,11 @@ static int osd_init_sound(void) .sample_rate = DEFAULT_SAMPLERATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, - .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, + .communication_format = I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_I2S_MSB, .intr_alloc_flags = 0, .dma_buf_count = 2, .dma_buf_len = 512, + .use_apll = false }; i2s_driver_install(0, &cfg, 2, &queue); i2s_set_pin(0, NULL); From 3f7370c8cf7f6dcf32e6ffc93b4aedcad59bbb8b Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 7 Apr 2020 17:39:12 +0800 Subject: [PATCH 25/73] support analog joystick --- components/nofrendo-esp32/Kconfig.projbuild | 14 ++ components/nofrendo-esp32/gpiocontroller.c | 196 +++++++++++++++----- 2 files changed, 165 insertions(+), 45 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 9c3d92c..e5002c0 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -277,6 +277,20 @@ config HW_GPIO_RIGHT default 34 if HW_ODROID_GO default 4 +config HW_GPIO_MENU + int "GPIO controller MENU button" + depends on HW_CONTROLLER_GPIO + range 0 39 + default 13 if HW_ODROID_GO + default -1 + +config HW_GPIO_AUDIO + int "GPIO controller AUDIO button" + depends on HW_CONTROLLER_GPIO + range 0 39 + default 0 if HW_ODROID_GO + default -1 + config HW_GPIO_SELECT int "GPIO controller SELECT button" depends on HW_CONTROLLER_GPIO diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c index 0b75341..0aa6067 100644 --- a/components/nofrendo-esp32/gpiocontroller.c +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -1,67 +1,173 @@ #include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_system.h" -#include "driver/gpio.h" + +#include +#include +#include #include -#include "sdkconfig.h" +#include +#include +#include +#include + +#include #ifdef CONFIG_HW_CONTROLLER_GPIO // Set buttons with pins -#define UP CONFIG_HW_GPIO_UP -#define DOWN CONFIG_HW_GPIO_DOWN -#define LEFT CONFIG_HW_GPIO_LEFT -#define RIGHT CONFIG_HW_GPIO_RIGHT -#define SELECT CONFIG_HW_GPIO_SELECT -#define START CONFIG_HW_GPIO_START -#define A CONFIG_HW_GPIO_A -#define B CONFIG_HW_GPIO_B +#define UP CONFIG_HW_GPIO_UP +#define DOWN CONFIG_HW_GPIO_DOWN +#define LEFT CONFIG_HW_GPIO_LEFT +#define RIGHT CONFIG_HW_GPIO_RIGHT +#define MENU CONFIG_HW_GPIO_MENU +#define AUDIO CONFIG_HW_GPIO_AUDIO +#define SELECT CONFIG_HW_GPIO_SELECT +#define START CONFIG_HW_GPIO_START +#define A CONFIG_HW_GPIO_A +#define B CONFIG_HW_GPIO_B + +#if (LEFT == RIGHT) && (UP == DOWN) +#define ANALOG_JOYSTICK + +#if (LEFT == ADC1_CHANNEL_0_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_0 +#endif +#if (LEFT == ADC1_CHANNEL_1_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_1 +#endif +#if (LEFT == ADC1_CHANNEL_2_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_2 +#endif +#if (LEFT == ADC1_CHANNEL_3_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_3 +#endif +#if (LEFT == ADC1_CHANNEL_4_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_4 +#endif +#if (LEFT == ADC1_CHANNEL_5_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_5 +#endif +#if (LEFT == ADC1_CHANNEL_6_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_6 +#endif +#if (LEFT == ADC1_CHANNEL_7_GPIO_NUM) +#define X_CHANNEL ADC1_CHANNEL_7 +#endif + +#if (UP == ADC1_CHANNEL_0_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_0 +#endif +#if (UP == ADC1_CHANNEL_1_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_1 +#endif +#if (UP == ADC1_CHANNEL_2_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_2 +#endif +#if (UP == ADC1_CHANNEL_3_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_3 +#endif +#if (UP == ADC1_CHANNEL_4_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_4 +#endif +#if (UP == ADC1_CHANNEL_5_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_5 +#endif +#if (UP == ADC1_CHANNEL_6_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_6 +#endif +#if (UP == ADC1_CHANNEL_7_GPIO_NUM) +#define Y_CHANNEL ADC1_CHANNEL_7 +#endif + +#define DEFAULT_VREF 1100 +static esp_adc_cal_characteristics_t characteristics; +#endif int gpioReadInput() { - return 0xFFFF ^ ( - (!gpio_get_level(UP) << 4) - | (!gpio_get_level(DOWN) << 6) - | (!gpio_get_level(LEFT) << 7) - | (!gpio_get_level(RIGHT) << 5) - | (!gpio_get_level(SELECT) << 0) - | (!gpio_get_level(START) << 3) - | (!gpio_get_level(A) << 13) - | (!gpio_get_level(B) << 14) - ); + int u, d, l, r, s, t, a, b; +#ifdef ANALOG_JOYSTICK + int joyX = adc1_get_raw(X_CHANNEL); + int joyY = adc1_get_raw(Y_CHANNEL); + if (joyX > 2048 + 1024) + { + l = 0; + r = 1; + } + else if (joyX > 1024) + { + l = 1; + r = 0; + } + else + { + l = 1; + r = 1; + } + if (joyY > 2048 + 1024) + { + u = 0; + d = 1; + } + else if (joyY > 1024) + { + u = 1; + d = 0; + } + else + { + u = 1; + d = 1; + } +#else + l = gpio_get_level(LEFT); + r = gpio_get_level(RIGHT); + u = gpio_get_level(UP); + d = gpio_get_level(DOWN); +#endif + + s = gpio_get_level(SELECT); + t = gpio_get_level(START); + a = gpio_get_level(A); + b = gpio_get_level(B); + + return 0xFFFF ^ ((!u << 4) | (!d << 6) | (!l << 7) | (!r << 5) | (!s << 0) | (!t << 3) | (!a << 13) | (!b << 14)); } void gpiocontrollerInit() { - //Configure button - gpio_config_t btn_config; - btn_config.intr_type = GPIO_INTR_ANYEDGE; //Enable interrupt on both rising and falling edges - btn_config.mode = GPIO_MODE_INPUT; //Set as Input - btn_config.pin_bit_mask = (uint64_t) //Bitmask - ( - ((uint64_t)(((uint64_t)1) << UP)) - | ((uint64_t)(((uint64_t)1) << DOWN)) - | ((uint64_t)(((uint64_t)1) << LEFT)) - | ((uint64_t)(((uint64_t)1) << RIGHT)) - | ((uint64_t)(((uint64_t)1) << SELECT)) - | ((uint64_t)(((uint64_t)1) << START)) - | ((uint64_t)(((uint64_t)1) << A)) - | ((uint64_t)(((uint64_t)1) << B)) - ); - btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup - btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown - gpio_config(&btn_config); + //Configure button + gpio_config_t btn_config; + btn_config.intr_type = GPIO_INTR_ANYEDGE; //Enable interrupt on both rising and falling edges + btn_config.mode = GPIO_MODE_INPUT; //Set as Input +#ifdef ANALOG_JOYSTICK + adc1_config_width(ADC_WIDTH_12Bit); + adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_11db); + esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_11db, ADC_WIDTH_BIT_12, DEFAULT_VREF, &characteristics); + + btn_config.pin_bit_mask = (uint64_t) //Bitmask + (((uint64_t)(((uint64_t)1) << MENU)) | ((uint64_t)(((uint64_t)1) << AUDIO)) | ((uint64_t)(((uint64_t)1) << SELECT)) | ((uint64_t)(((uint64_t)1) << START)) | ((uint64_t)(((uint64_t)1) << A)) | ((uint64_t)(((uint64_t)1) << B))); + btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup + btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown + gpio_config(&btn_config); +#else + btn_config.pin_bit_mask = (uint64_t) //Bitmask + (((uint64_t)(((uint64_t)1) << UP)) | ((uint64_t)(((uint64_t)1) << DOWN)) | ((uint64_t)(((uint64_t)1) << LEFT)) | ((uint64_t)(((uint64_t)1) << RIGHT)) | ((uint64_t)(((uint64_t)1) << MENU)) | ((uint64_t)(((uint64_t)1) << AUDIO)) | ((uint64_t)(((uint64_t)1) << SELECT)) | ((uint64_t)(((uint64_t)1) << START)) | ((uint64_t)(((uint64_t)1) << A)) | ((uint64_t)(((uint64_t)1) << B))); + btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup + btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown + gpio_config(&btn_config); +#endif } #else -void gpiocontrollerInit() { - printf("GPIO controller disabled in menuconfig; no input enabled.\n"); +void gpiocontrollerInit() +{ + printf("GPIO controller disabled in menuconfig; no input enabled.\n"); } -int gpioReadInput() { - return 0xFFFF; +int gpioReadInput() +{ + return 0xFFFF; } #endif \ No newline at end of file From 5a6733526a47eed1c4243722514dc78b348dde08 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sun, 12 Apr 2020 23:43:23 +0800 Subject: [PATCH 26/73] stereo audio --- components/nofrendo-esp32/Kconfig.projbuild | 4 +-- components/nofrendo-esp32/video_audio.c | 33 +++++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index e5002c0..4df3194 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -195,10 +195,10 @@ config HW_LCD_CLOCK_SPEED default 40 if HW_ODROID_GO config SOUND_ENA - bool "Analog audio on GPIO26" + bool "Analog audio" default y help - ESP32 will output 0-3.3V analog audio signal on GPIO26. + ESP32 will output 0-3.3V analog audio signal on GPIO 25 and 26. choice HW_CONTROLLER_SEL diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index 7cf5a4f..14bfb70 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -48,7 +48,7 @@ #include #endif -#define DEFAULT_SAMPLERATE 22100 +#define DEFAULT_SAMPLERATE 32000 #define DEFAULT_FRAGSIZE 128 #define DEFAULT_WIDTH 256 @@ -88,13 +88,14 @@ static void do_audio_frame() //16 bit mono -> 32-bit (16 bit r+l) for (int i = n - 1; i >= 0; i--) { - audio_frame[i] = audio_frame[i] + 0x8000; - // audio_frame[i*2+1] = audio_frame[i] + 0x8000; - // audio_frame[i*2] = audio_frame[i] + 0x8000; + // audio_frame[i] = audio_frame[i] + 0x8000; + int16_t a = (audio_frame[i] >> 3); + audio_frame[i*2+1] = 0x8000 + a; + audio_frame[i*2] = 0x8000 - a; } size_t i2s_bytes_write; - i2s_write(0, (const char *)audio_frame, 2 * n, &i2s_bytes_write, portMAX_DELAY); - left -= i2s_bytes_write / 2; + i2s_write(I2S_NUM_0, (const char *)audio_frame, 4 * n, &i2s_bytes_write, portMAX_DELAY); + left -= i2s_bytes_write / 4; } #endif } @@ -115,25 +116,19 @@ static int osd_init_sound(void) #if CONFIG_SOUND_ENA audio_frame = malloc(2 * DEFAULT_FRAGSIZE); i2s_config_t cfg = { - .mode = I2S_MODE_DAC_BUILT_IN | I2S_MODE_TX | I2S_MODE_MASTER, + .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, .sample_rate = DEFAULT_SAMPLERATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, + .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, .communication_format = I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_I2S_MSB, - .intr_alloc_flags = 0, - .dma_buf_count = 2, + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, + .dma_buf_count = 6, .dma_buf_len = 512, .use_apll = false }; - i2s_driver_install(0, &cfg, 2, &queue); - i2s_set_pin(0, NULL); - // i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN); - i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); - - //I2S enables *both* DAC channels; we only need DAC1. - //ToDo: still needed now I2S supports set_dac_mode? - // CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_DAC_XPD_FORCE_M); - // CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_XPD_DAC_M); + i2s_driver_install(I2S_NUM_0, &cfg, 2, &queue); + i2s_set_pin(I2S_NUM_0, NULL); + i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); #endif audio_callback = NULL; From 6790aefef11f1e474f580829feb3304f80463999 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 29 Sep 2020 17:35:17 +0800 Subject: [PATCH 27/73] default flashmode --- sdkconfig.defaults | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdkconfig.defaults b/sdkconfig.defaults index bb11b29..a3aa700 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -29,6 +29,8 @@ CONFIG_ESPTOOLPY_PORT="/dev/cu.SLAB_USBtoUART" CONFIG_ESPTOOLPY_BAUD_115200B= CONFIG_ESPTOOLPY_BAUD_921600B=y CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_FLASHMODE_QIO=y +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_ESPTOOLPY_FLASHSIZE_2MB= CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_ESPTOOLPY_FLASHSIZE="4MB" From f95e8bafe509a51f2f3e6d9b0004a4eb4eb7b9d6 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 29 Sep 2020 17:35:53 +0800 Subject: [PATCH 28/73] #pragma GCC optimize ("O3") --- components/nofrendo/cpu/nes6502.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/nofrendo/cpu/nes6502.c b/components/nofrendo/cpu/nes6502.c index 72be869..9484290 100644 --- a/components/nofrendo/cpu/nes6502.c +++ b/components/nofrendo/cpu/nes6502.c @@ -1,3 +1,5 @@ +#pragma GCC optimize ("O3") + /* ** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com) ** From a76bde598164e3ba6f61f09aff09ec085ea76807 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 29 Sep 2020 17:36:22 +0800 Subject: [PATCH 29/73] odroid-go mapper --- components/nofrendo/mappers/map002.c | 10 +- components/nofrendo/mappers/map004.c | 5 + components/nofrendo/mappers/map010.c | 161 +++++++++++++++++++++++++++ components/nofrendo/nes/mmclist.c | 1 + 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 components/nofrendo/mappers/map010.c diff --git a/components/nofrendo/mappers/map002.c b/components/nofrendo/mappers/map002.c index 1281d50..7e5518a 100644 --- a/components/nofrendo/mappers/map002.c +++ b/components/nofrendo/mappers/map002.c @@ -27,6 +27,14 @@ #include /* mapper 2: UNROM */ +static void map2_init() +{ + int last_bank = mmc_getinfo()->rom_banks - 1; + printf("map2_init. last_bank=%d\n", last_bank); + mmc_bankrom(16, 0xc000, last_bank); + mmc_bankrom(16, 0x8000, 0); +} + static void map2_write(uint32 address, uint8 value) { UNUSED(address); @@ -44,7 +52,7 @@ mapintf_t map2_intf = { 2, /* mapper number */ "UNROM", /* mapper name */ - NULL, /* init routine */ + map2_init, /* init routine */ NULL, /* vblank callback */ NULL, /* hblank callback */ NULL, /* get state (snss) */ diff --git a/components/nofrendo/mappers/map004.c b/components/nofrendo/mappers/map004.c index 36c6ca4..2505cad 100644 --- a/components/nofrendo/mappers/map004.c +++ b/components/nofrendo/mappers/map004.c @@ -138,6 +138,11 @@ static void map4_write(uint32 address, uint8 value) break; default: + //printf("map004: unhandled write: address=%p, value=0x%x\n", (void*)address, value); + __asm__("nop"); + __asm__("nop"); + __asm__("nop"); + __asm__("nop"); break; } diff --git a/components/nofrendo/mappers/map010.c b/components/nofrendo/mappers/map010.c new file mode 100644 index 0000000..d2b2300 --- /dev/null +++ b/components/nofrendo/mappers/map010.c @@ -0,0 +1,161 @@ +/* +** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com) +** +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of version 2 of the GNU Library General +** Public License as published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Library General Public License for more details. To obtain a +** copy of the GNU Library General Public License, write to the Free +** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +** +** Any permitted reproduction of these routines, in whole or in part, +** must bear this legend. +** +** +** map010.c +** +** mapper 10 interface +** $Id: map010.c,v 1.0 2018/07/07 +*/ + +#include +#include +#include +#include +#include + +static uint8 latch[2]; +static uint8 regs[4]; + +/* Used when tile $FD/$FE is accessed */ +static void mmc10_latchfunc(uint32 address, uint8 value) +{ + if (0xFD == value || 0xFE == value) + { + int reg; + + if (address) + { + latch[1] = value; + reg = 2 + (value - 0xFD); + } + else + { + latch[0] = value; + reg = value - 0xFD; + } + + mmc_bankvrom(4, address, regs[reg]); + } +} + +/* mapper 10: MMC4 */ +/* MMC4: Fire Emblem */ +static void map10_write(uint32 address, uint8 value) +{ + switch ((address & 0xF000) >> 12) + { + case 0xA: + mmc_bankrom(16, 0x8000, value); + break; + + case 0xB: + regs[0] = value; + if (0xFD == latch[0]) + mmc_bankvrom(4, 0x0000, value); + break; + + case 0xC: + regs[1] = value; + if (0xFE == latch[0]) + mmc_bankvrom(4, 0x0000, value); + break; + + case 0xD: + regs[2] = value; + if (0xFD == latch[1]) + mmc_bankvrom(4, 0x1000, value); + break; + + case 0xE: + regs[3] = value; + if (0xFE == latch[1]) + mmc_bankvrom(4, 0x1000, value); + break; + + case 0xF: + if (value & 1) + ppu_mirror(0, 0, 1, 1); /* horizontal */ + else + ppu_mirror(0, 1, 0, 1); /* vertical */ + break; + + default: + break; + } +} + +static void map10_init(void) +{ + memset(regs, 0, sizeof(regs)); + + mmc_bankrom(16, 0x8000, 0); + mmc_bankrom(16, 0xC000, (mmc_getinfo()->rom_banks) - 1); + + latch[0] = 0xFE; + latch[1] = 0xFE; + + ppu_setlatchfunc(mmc10_latchfunc); +} + +static void map10_getstate(SnssMapperBlock *state) +{ + state->extraData.mapper10.latch[0] = latch[0]; + state->extraData.mapper10.latch[1] = latch[1]; + state->extraData.mapper10.lastB000Write = regs[0]; + state->extraData.mapper10.lastC000Write = regs[1]; + state->extraData.mapper10.lastD000Write = regs[2]; + state->extraData.mapper10.lastE000Write = regs[3]; +} + +static void map10_setstate(SnssMapperBlock *state) +{ + latch[0] = state->extraData.mapper10.latch[0]; + latch[1] = state->extraData.mapper10.latch[1]; + regs[0] = state->extraData.mapper10.lastB000Write; + regs[1] = state->extraData.mapper10.lastC000Write; + regs[2] = state->extraData.mapper10.lastD000Write; + regs[3] = state->extraData.mapper10.lastE000Write; +} + +static map_memwrite map10_memwrite[] = +{ + { 0x8000, 0xFFFF, map10_write }, + { -1, -1, NULL } +}; + +mapintf_t map10_intf = +{ + 10, /* mapper number */ + "MMC4", /* mapper name */ + map10_init, /* init routine */ + NULL, /* vblank callback */ + NULL, /* hblank callback */ + map10_getstate, /* get state (snss) */ + map10_setstate, /* set state (snss) */ + NULL, /* memory read structure */ + map10_memwrite, /* memory write structure */ + NULL /* external sound device */ +}; + +/* +** $Log: map010.c,v $ +** Revision 1.0 2018/07/07 +** initial revision based on map009.c +** +*/ diff --git a/components/nofrendo/nes/mmclist.c b/components/nofrendo/nes/mmclist.c index 0542e34..c4e4557 100644 --- a/components/nofrendo/nes/mmclist.c +++ b/components/nofrendo/nes/mmclist.c @@ -36,6 +36,7 @@ extern mapintf_t map5_intf; extern mapintf_t map7_intf; extern mapintf_t map8_intf; extern mapintf_t map9_intf; +extern mapintf_t map10_intf; extern mapintf_t map11_intf; extern mapintf_t map15_intf; extern mapintf_t map16_intf; From ac2c3a5eadba1e235fddf393c0478060695363c0 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 29 Sep 2020 17:36:40 +0800 Subject: [PATCH 30/73] fix LCD rotation --- components/nofrendo-esp32/spi_lcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/nofrendo-esp32/spi_lcd.c b/components/nofrendo-esp32/spi_lcd.c index 0402740..b64978c 100644 --- a/components/nofrendo-esp32/spi_lcd.c +++ b/components/nofrendo-esp32/spi_lcd.c @@ -81,9 +81,9 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC5, {0x35, 0x3E}, 2}, // VCM control {0xC7, {0xBE}, 1}, // VCM control2, was B1h #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1 << 7) | (1 << 6) | (1 << 5) | (1 << 3)}, 1}, // MY | MX | MV | BGR -#else {0x36, {(1 << 5) | (1 << 3)}, 1}, // MV | BGR +#else + {0x36, {(1 << 7) | (1 << 6) | (1 << 5) | (1 << 3)}, 1}, // MY | MX | MV | BGR #endif {0x3A, {0x55}, 1}, {0xB1, {0x00, 0x1B}, 2}, From c81c4e1d2010f8cede5d97bb95ce3e383e875ca8 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 30 Sep 2020 17:03:50 +0800 Subject: [PATCH 31/73] align to arduino-esp32 default partition schema --- main/main.c | 27 +++++++++++++-------------- partitions.csv | 12 ++++++------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/main/main.c b/main/main.c index a6f1019..83e8f6c 100644 --- a/main/main.c +++ b/main/main.c @@ -8,26 +8,26 @@ #include "nofrendo.h" #include "esp_partition.h" - - -char *osd_getromdata() { - char* romdata; - const esp_partition_t* part; +char *osd_getromdata() +{ + char *romdata; + const esp_partition_t *part; spi_flash_mmap_handle_t hrom; esp_err_t err; nvs_flash_init(); - part=esp_partition_find_first(0x40, 1, NULL); - if (part==0) printf("Couldn't find rom part!\n"); - err=esp_partition_mmap(part, 0, 3*1024*1024, SPI_FLASH_MMAP_DATA, (const void**)&romdata, &hrom); - if (err!=ESP_OK) printf("Couldn't map rom part!\n"); + part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); + if (part == 0) + printf("Couldn't find rom part!\n"); + err = esp_partition_mmap(part, 0, 0x140000, SPI_FLASH_MMAP_DATA, (const void **)&romdata, &hrom); + if (err != ESP_OK) + printf("Couldn't map rom part!\n"); printf("Initialized. ROM@%p\n", romdata); - return (char*)romdata; + return (char *)romdata; } - esp_err_t event_handler(void *ctx, system_event_t *event) { - return ESP_OK; + return ESP_OK; } int app_main(void) @@ -36,6 +36,5 @@ int app_main(void) nofrendo_main(0, NULL); printf("NoFrendo died? WtF?\n"); asm("break.n 1"); - return 0; + return 0; } - diff --git a/partitions.csv b/partitions.csv index 9b85441..e9772b6 100644 --- a/partitions.csv +++ b/partitions.csv @@ -1,6 +1,6 @@ -# Name, Type, SubType, Offset, Size -# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild -nvs, data, nvs, 0x9000, 0x6000 -phy_init, data, phy, 0xf000, 0x1000 -factory, app, factory, 0x10000, 0x0E0000 -nesgame, 0x40, 0x01, 0x100000, 0x300000 +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x140000, +app1, app, ota_1, 0x150000,0x140000, +spiffs, data, spiffs, 0x290000,0x170000, From 72401689a8c516aa9963d7760da5443233a7114b Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 30 Sep 2020 17:12:19 +0800 Subject: [PATCH 32/73] implement status save and load --- components/nofrendo-esp32/gpiocontroller.c | 6 ++-- components/nofrendo-esp32/video_audio.c | 2 +- components/nofrendo/nes/nesstate.c | 22 ++++++------ main/main.c | 40 +++++++++++++++++++++- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c index 0aa6067..cd3e744 100644 --- a/components/nofrendo-esp32/gpiocontroller.c +++ b/components/nofrendo-esp32/gpiocontroller.c @@ -84,7 +84,7 @@ static esp_adc_cal_characteristics_t characteristics; int gpioReadInput() { - int u, d, l, r, s, t, a, b; + int u, d, l, r, s, t, a, b, m, i; #ifdef ANALOG_JOYSTICK int joyX = adc1_get_raw(X_CHANNEL); int joyY = adc1_get_raw(Y_CHANNEL); @@ -129,8 +129,10 @@ int gpioReadInput() t = gpio_get_level(START); a = gpio_get_level(A); b = gpio_get_level(B); + m = gpio_get_level(MENU); + i = gpio_get_level(AUDIO); - return 0xFFFF ^ ((!u << 4) | (!d << 6) | (!l << 7) | (!r << 5) | (!s << 0) | (!t << 3) | (!a << 13) | (!b << 14)); + return 0xFFFF ^ ((!u << 4) | (!d << 6) | (!l << 7) | (!r << 5) | (!s << 0) | (!t << 3) | (!a << 13) | (!b << 14) | (!m << 1) | (!i << 2)); } void gpiocontrollerInit() diff --git a/components/nofrendo-esp32/video_audio.c b/components/nofrendo-esp32/video_audio.c index 14bfb70..f5c0141 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/components/nofrendo-esp32/video_audio.c @@ -280,7 +280,7 @@ static void osd_initinput() void osd_getinput(void) { const int ev[16] = { - event_joypad1_select, 0, 0, event_joypad1_start, event_joypad1_up, event_joypad1_right, event_joypad1_down, event_joypad1_left, + event_joypad1_select, event_state_save, event_state_load, event_joypad1_start, event_joypad1_up, event_joypad1_right, event_joypad1_down, event_joypad1_left, 0, 0, 0, 0, event_soft_reset, event_joypad1_a, event_joypad1_b, event_hard_reset}; static int oldb = 0xffff; #if defined CONFIG_HW_CONTROLLER_GPIO diff --git a/components/nofrendo/nes/nesstate.c b/components/nofrendo/nes/nesstate.c index c010f56..e399ef3 100644 --- a/components/nofrendo/nes/nesstate.c +++ b/components/nofrendo/nes/nesstate.c @@ -341,7 +341,7 @@ int state_save(void) { SNSS_FILE *snssFile; SNSS_RETURN_CODE status; - char fn[PATH_MAX + 1], ext[5]; + // char fn[PATH_MAX + 1], ext[5]; nes_t *machine; /* get the pointer to our NES machine context */ @@ -349,11 +349,12 @@ int state_save(void) ASSERT(machine); /* build our filename using the image's name and the slot number */ - strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); + // strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); - ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); - sprintf(ext, ".ss%d", state_slot); - osd_newextension(fn, ext); + // ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); + // sprintf(ext, ".ss%d", state_slot); + // osd_newextension(fn, ext); + char *fn = "/spiffs/state.sav"; /* open our state file for writing */ status = SNSS_OpenFile(&snssFile, fn, SNSS_OPEN_WRITE); @@ -415,7 +416,7 @@ int state_load(void) SNSS_FILE *snssFile; SNSS_RETURN_CODE status; SNSS_BLOCK_TYPE block_type; - char fn[PATH_MAX + 1], ext[5]; + // char fn[PATH_MAX + 1], ext[5]; unsigned int i; nes_t *machine; @@ -424,11 +425,12 @@ int state_load(void) ASSERT(machine); /* build the state name using the ROM's name and the slot number */ - strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); + // strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); - ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); - sprintf(ext, ".ss%d", state_slot); - osd_newextension(fn, ext); + // ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); + // sprintf(ext, ".ss%d", state_slot); + // osd_newextension(fn, ext); + char *fn = "/spiffs/state.sav"; /* open our file for writing */ status = SNSS_OpenFile(&snssFile, fn, SNSS_OPEN_READ); diff --git a/main/main.c b/main/main.c index 83e8f6c..a2ad89b 100644 --- a/main/main.c +++ b/main/main.c @@ -8,6 +8,9 @@ #include "nofrendo.h" #include "esp_partition.h" +#include "esp_log.h" +#include "esp_spiffs.h" + char *osd_getromdata() { char *romdata; @@ -30,11 +33,46 @@ esp_err_t event_handler(void *ctx, system_event_t *event) return ESP_OK; } +void spiffs_init(void) +{ + esp_vfs_spiffs_conf_t conf = { + .base_path = "/spiffs", + .partition_label = NULL, + .max_files = 5, + .format_if_mount_failed = true + }; + + // Use settings defined above to initialize and mount SPIFFS filesystem. + // Note: esp_vfs_spiffs_register is an all-in-one convenience function. + esp_err_t ret = esp_vfs_spiffs_register(&conf); + + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + printf("Failed to mount or format filesystem"); + } else if (ret == ESP_ERR_NOT_FOUND) { + printf("Failed to find SPIFFS partition"); + } else { + printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); + } + return; + } + + size_t total = 0, used = 0; + ret = esp_spiffs_info(NULL, &total, &used); + if (ret != ESP_OK) { + printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); + } else { + printf("Partition size: total: %d, used: %d", total, used); + } +} + int app_main(void) { + spiffs_init(); + printf("NoFrendo start!\n"); nofrendo_main(0, NULL); - printf("NoFrendo died? WtF?\n"); + printf("NoFrendo died? Oh no!\n"); asm("break.n 1"); return 0; } From 6cfd97194fbc8109e1e85e41ae403b27f1ab75cb Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 30 Sep 2020 17:15:23 +0800 Subject: [PATCH 33/73] reduce output log --- components/nofrendo/gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo/gui.c b/components/nofrendo/gui.c index 317229d..6259f66 100644 --- a/components/nofrendo/gui.c +++ b/components/nofrendo/gui.c @@ -360,7 +360,7 @@ static void gui_tickdec(void) if (hertz_ticks >= (10 * gui_refresh)) { hertz_ticks -= (10 * gui_refresh); - mem_checkblocks(); + // mem_checkblocks(); } #endif From 2de36692f45569670a4496f67acb623d1460c2c8 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 30 Sep 2020 22:24:19 +0800 Subject: [PATCH 34/73] align to arduino-esp32 default partition schema --- flashrom.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flashrom.sh b/flashrom.sh index dc5dfb6..a2636dd 100755 --- a/flashrom.sh +++ b/flashrom.sh @@ -1,3 +1,3 @@ #!/bin/bash # . ${IDF_PATH}/add_path.sh -esptool.py --chip esp32 --port "/dev/cu.SLAB_USBtoUART" --baud $((230400*4)) write_flash -fs 4MB 0x100000 "$1" +esptool.py --chip esp32 --port "/dev/cu.SLAB_USBtoUART" --baud $((230400*4)) write_flash -fs 4MB 0x150000 "$1" From 820435d22397676a6f25034e9e2b6f761136d00a Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 30 Sep 2020 23:21:40 +0800 Subject: [PATCH 35/73] simplify folder structure --- components/nofrendo-esp32/component.mk | 12 - components/nofrendo-esp32/gpiocontroller.c | 175 ------- components/nofrendo-esp32/gpiocontroller.h | 7 - components/nofrendo-esp32/i2c_gpcontroller.c | 85 ---- components/nofrendo-esp32/i2c_gpcontroller.h | 10 - components/nofrendo-esp32/i2c_kbcontroller.c | 104 ---- components/nofrendo-esp32/i2c_kbcontroller.h | 10 - components/nofrendo-esp32/psxcontroller.c | 140 ------ components/nofrendo-esp32/psxcontroller.h | 7 - .../nofrendo-esp32 => main}/Kconfig.projbuild | 4 +- main/controller.c | 453 ++++++++++++++++++ main/controller.h | 7 + {components/nofrendo-esp32 => main}/osd.c | 0 {components/nofrendo-esp32 => main}/spi_lcd.c | 0 {components/nofrendo-esp32 => main}/spi_lcd.h | 0 .../nofrendo-esp32 => main}/video_audio.c | 36 +- 16 files changed, 468 insertions(+), 582 deletions(-) delete mode 100644 components/nofrendo-esp32/component.mk delete mode 100644 components/nofrendo-esp32/gpiocontroller.c delete mode 100644 components/nofrendo-esp32/gpiocontroller.h delete mode 100644 components/nofrendo-esp32/i2c_gpcontroller.c delete mode 100644 components/nofrendo-esp32/i2c_gpcontroller.h delete mode 100644 components/nofrendo-esp32/i2c_kbcontroller.c delete mode 100644 components/nofrendo-esp32/i2c_kbcontroller.h delete mode 100644 components/nofrendo-esp32/psxcontroller.c delete mode 100644 components/nofrendo-esp32/psxcontroller.h rename {components/nofrendo-esp32 => main}/Kconfig.projbuild (99%) create mode 100644 main/controller.c create mode 100644 main/controller.h rename {components/nofrendo-esp32 => main}/osd.c (100%) rename {components/nofrendo-esp32 => main}/spi_lcd.c (100%) rename {components/nofrendo-esp32 => main}/spi_lcd.h (100%) rename {components/nofrendo-esp32 => main}/video_audio.c (89%) diff --git a/components/nofrendo-esp32/component.mk b/components/nofrendo-esp32/component.mk deleted file mode 100644 index c0c11f3..0000000 --- a/components/nofrendo-esp32/component.mk +++ /dev/null @@ -1,12 +0,0 @@ -# -# Component Makefile -# -# This Makefile can be left empty. By default, it will take the sources in the -# src/ directory, compile them and link them into lib(subdirectory_name).a -# in the build directory. This behaviour is entirely configurable, -# please read the ESP-IDF documents if you need to do this. -# - -COMPONENT_DEPENDS := nofrendo -COMPONENT_ADD_INCLUDEDIRS := . - diff --git a/components/nofrendo-esp32/gpiocontroller.c b/components/nofrendo-esp32/gpiocontroller.c deleted file mode 100644 index cd3e744..0000000 --- a/components/nofrendo-esp32/gpiocontroller.c +++ /dev/null @@ -1,175 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifdef CONFIG_HW_CONTROLLER_GPIO - -// Set buttons with pins -#define UP CONFIG_HW_GPIO_UP -#define DOWN CONFIG_HW_GPIO_DOWN -#define LEFT CONFIG_HW_GPIO_LEFT -#define RIGHT CONFIG_HW_GPIO_RIGHT -#define MENU CONFIG_HW_GPIO_MENU -#define AUDIO CONFIG_HW_GPIO_AUDIO -#define SELECT CONFIG_HW_GPIO_SELECT -#define START CONFIG_HW_GPIO_START -#define A CONFIG_HW_GPIO_A -#define B CONFIG_HW_GPIO_B - -#if (LEFT == RIGHT) && (UP == DOWN) -#define ANALOG_JOYSTICK - -#if (LEFT == ADC1_CHANNEL_0_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_0 -#endif -#if (LEFT == ADC1_CHANNEL_1_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_1 -#endif -#if (LEFT == ADC1_CHANNEL_2_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_2 -#endif -#if (LEFT == ADC1_CHANNEL_3_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_3 -#endif -#if (LEFT == ADC1_CHANNEL_4_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_4 -#endif -#if (LEFT == ADC1_CHANNEL_5_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_5 -#endif -#if (LEFT == ADC1_CHANNEL_6_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_6 -#endif -#if (LEFT == ADC1_CHANNEL_7_GPIO_NUM) -#define X_CHANNEL ADC1_CHANNEL_7 -#endif - -#if (UP == ADC1_CHANNEL_0_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_0 -#endif -#if (UP == ADC1_CHANNEL_1_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_1 -#endif -#if (UP == ADC1_CHANNEL_2_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_2 -#endif -#if (UP == ADC1_CHANNEL_3_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_3 -#endif -#if (UP == ADC1_CHANNEL_4_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_4 -#endif -#if (UP == ADC1_CHANNEL_5_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_5 -#endif -#if (UP == ADC1_CHANNEL_6_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_6 -#endif -#if (UP == ADC1_CHANNEL_7_GPIO_NUM) -#define Y_CHANNEL ADC1_CHANNEL_7 -#endif - -#define DEFAULT_VREF 1100 -static esp_adc_cal_characteristics_t characteristics; -#endif - -int gpioReadInput() -{ - int u, d, l, r, s, t, a, b, m, i; -#ifdef ANALOG_JOYSTICK - int joyX = adc1_get_raw(X_CHANNEL); - int joyY = adc1_get_raw(Y_CHANNEL); - if (joyX > 2048 + 1024) - { - l = 0; - r = 1; - } - else if (joyX > 1024) - { - l = 1; - r = 0; - } - else - { - l = 1; - r = 1; - } - if (joyY > 2048 + 1024) - { - u = 0; - d = 1; - } - else if (joyY > 1024) - { - u = 1; - d = 0; - } - else - { - u = 1; - d = 1; - } -#else - l = gpio_get_level(LEFT); - r = gpio_get_level(RIGHT); - u = gpio_get_level(UP); - d = gpio_get_level(DOWN); -#endif - - s = gpio_get_level(SELECT); - t = gpio_get_level(START); - a = gpio_get_level(A); - b = gpio_get_level(B); - m = gpio_get_level(MENU); - i = gpio_get_level(AUDIO); - - return 0xFFFF ^ ((!u << 4) | (!d << 6) | (!l << 7) | (!r << 5) | (!s << 0) | (!t << 3) | (!a << 13) | (!b << 14) | (!m << 1) | (!i << 2)); -} - -void gpiocontrollerInit() -{ - //Configure button - gpio_config_t btn_config; - btn_config.intr_type = GPIO_INTR_ANYEDGE; //Enable interrupt on both rising and falling edges - btn_config.mode = GPIO_MODE_INPUT; //Set as Input -#ifdef ANALOG_JOYSTICK - adc1_config_width(ADC_WIDTH_12Bit); - adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_11db); - esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_11db, ADC_WIDTH_BIT_12, DEFAULT_VREF, &characteristics); - - btn_config.pin_bit_mask = (uint64_t) //Bitmask - (((uint64_t)(((uint64_t)1) << MENU)) | ((uint64_t)(((uint64_t)1) << AUDIO)) | ((uint64_t)(((uint64_t)1) << SELECT)) | ((uint64_t)(((uint64_t)1) << START)) | ((uint64_t)(((uint64_t)1) << A)) | ((uint64_t)(((uint64_t)1) << B))); - btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup - btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown - gpio_config(&btn_config); -#else - btn_config.pin_bit_mask = (uint64_t) //Bitmask - (((uint64_t)(((uint64_t)1) << UP)) | ((uint64_t)(((uint64_t)1) << DOWN)) | ((uint64_t)(((uint64_t)1) << LEFT)) | ((uint64_t)(((uint64_t)1) << RIGHT)) | ((uint64_t)(((uint64_t)1) << MENU)) | ((uint64_t)(((uint64_t)1) << AUDIO)) | ((uint64_t)(((uint64_t)1) << SELECT)) | ((uint64_t)(((uint64_t)1) << START)) | ((uint64_t)(((uint64_t)1) << A)) | ((uint64_t)(((uint64_t)1) << B))); - btn_config.pull_up_en = GPIO_PULLUP_ENABLE; //Disable pullup - btn_config.pull_down_en = GPIO_PULLDOWN_DISABLE; //Enable pulldown - gpio_config(&btn_config); -#endif -} - -#else - -void gpiocontrollerInit() -{ - printf("GPIO controller disabled in menuconfig; no input enabled.\n"); -} - -int gpioReadInput() -{ - return 0xFFFF; -} - -#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/gpiocontroller.h b/components/nofrendo-esp32/gpiocontroller.h deleted file mode 100644 index 6e0ac41..0000000 --- a/components/nofrendo-esp32/gpiocontroller.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef GAMEPAD_H -#define GAMEPAD_H - -int gpioReadInput(); -void gpiocontrollerInit(); - -#endif \ No newline at end of file diff --git a/components/nofrendo-esp32/i2c_gpcontroller.c b/components/nofrendo-esp32/i2c_gpcontroller.c deleted file mode 100644 index 90ae850..0000000 --- a/components/nofrendo-esp32/i2c_gpcontroller.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "sdkconfig.h" -#include "i2c_gpcontroller.h" - -#ifdef CONFIG_HW_CONTROLLER_I2C_GP - -#define I2C_GAMEPAD_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_GAMEPAD_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_GAMEPAD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ -#define I2C_GAMEPAD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ -#define I2C_GAMEPAD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ -#define I2C_GAMEPAD_FREQ_HZ 50000 /*!< I2C master clock frequency */ -#define I2C_GAMEPAD_ADDR 0x08 - -#define READ_BIT I2C_MASTER_READ /*!< I2C master read */ -#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ -#define NACK_VAL 0x1 /*!< I2C nack value */ - -void i2c_gpcontrollerInit() -{ - int i2c_master_port = I2C_GAMEPAD_NUM; - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - conf.sda_io_num = I2C_GAMEPAD_SDA_IO; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.scl_io_num = I2C_GAMEPAD_SCL_IO; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = I2C_GAMEPAD_FREQ_HZ; - i2c_param_config(i2c_master_port, &conf); - i2c_driver_install(i2c_master_port, conf.mode, - I2C_GAMEPAD_RX_BUF_DISABLE, - I2C_GAMEPAD_TX_BUF_DISABLE, 0); -} - -/** - * @brief test code to write esp-i2c-slave - * - * 1. set mode - * _________________________________________________________________ - * | start | slave_addr + wr_bit + ack | write 1 byte + ack | stop | - * --------|---------------------------|---------------------|------| - * 2. wait more than 24 ms - * 3. read data - * ______________________________________________________________________________________ - * | start | slave_addr + rd_bit + ack | read 1 byte + ack | read 1 byte + nack | stop | - * --------|---------------------------|--------------------|--------------------|------| - */ -int i2c_gpReadInput() -{ - uint8_t data; - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (I2C_GAMEPAD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); - i2c_master_read_byte(cmd, &data, NACK_VAL); - i2c_master_stop(cmd); - esp_err_t ret = i2c_master_cmd_begin(I2C_GAMEPAD_NUM, cmd, 1000 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if (ret == 0) { - printf("I2C read %d, return %d\n", data, ret); - - return 0xFFFF ^ ( - (((0x01 & data) > 0) << 4) - | (((0x02 & data) > 0) << 6) - | (((0x04 & data) > 0) << 7) - | (((0x08 & data) > 0) << 5) - | (((0x10 & data) > 0) << 0) - | (((0x20 & data) > 0) << 3) - | (((0x40 & data) > 0) << 13) - | (((0x80 & data) > 0) << 14) - ); - } else { - return 0xFFFF; - } -} - -#else - -void i2c_gpcontrollerInit() { - printf("I2C Gamepad disabled in menuconfig; no input enabled.\n"); -} - -int i2c_gpReadInput() { - return 0xFFFF; -} - -#endif diff --git a/components/nofrendo-esp32/i2c_gpcontroller.h b/components/nofrendo-esp32/i2c_gpcontroller.h deleted file mode 100644 index 1090e19..0000000 --- a/components/nofrendo-esp32/i2c_gpcontroller.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _I2C_KEYBOARD_H_ -#define _I2C_KEYBOARD_H_ - -#include -#include "driver/i2c.h" - -void i2c_gpcontrollerInit(); -int i2c_gpReadInput(); - -#endif diff --git a/components/nofrendo-esp32/i2c_kbcontroller.c b/components/nofrendo-esp32/i2c_kbcontroller.c deleted file mode 100644 index 9fd5cf4..0000000 --- a/components/nofrendo-esp32/i2c_kbcontroller.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "sdkconfig.h" -#include "i2c_kbcontroller.h" - -#ifdef CONFIG_HW_CONTROLLER_I2C_KB - -#define I2C_KEYBOARD_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_KEYBOARD_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_KEYBOARD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ -#define I2C_KEYBOARD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ -#define I2C_KEYBOARD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ -#define I2C_KEYBOARD_FREQ_HZ 100000 /*!< I2C master clock frequency */ -#define I2C_KEYBOARD_ADDR 0x5f - -#define READ_BIT I2C_MASTER_READ /*!< I2C master read */ -#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ -#define NACK_VAL 0x1 /*!< I2C nack value */ - -void i2c_kbcontrollerInit() -{ - int i2c_master_port = I2C_KEYBOARD_NUM; - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - conf.sda_io_num = I2C_KEYBOARD_SDA_IO; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.scl_io_num = I2C_KEYBOARD_SCL_IO; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = I2C_KEYBOARD_FREQ_HZ; - i2c_param_config(i2c_master_port, &conf); - i2c_driver_install(i2c_master_port, conf.mode, - I2C_KEYBOARD_RX_BUF_DISABLE, - I2C_KEYBOARD_TX_BUF_DISABLE, 0); -} - -/** - * @brief test code to write esp-i2c-slave - * - * 1. set mode - * _________________________________________________________________ - * | start | slave_addr + wr_bit + ack | write 1 byte + ack | stop | - * --------|---------------------------|---------------------|------| - * 2. wait more than 24 ms - * 3. read data - * ______________________________________________________________________________________ - * | start | slave_addr + rd_bit + ack | read 1 byte + ack | read 1 byte + nack | stop | - * --------|---------------------------|--------------------|--------------------|------| - */ -int i2c_kbReadInput() -{ - uint8_t data; - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (I2C_KEYBOARD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); - i2c_master_read_byte(cmd, &data, NACK_VAL); - i2c_master_stop(cmd); - esp_err_t ret = i2c_master_cmd_begin(I2C_KEYBOARD_NUM, cmd, 1000 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if ((ret == 0) && (data > 0)) { - printf("I2C read %d, return %d\n", data, ret); - - switch (data) - { - case 181: // up - return 0xFFFF ^ (1 << 4); - break; - case 182: // down - return 0xFFFF ^ (1 << 6); - break; - case 180: // left - return 0xFFFF ^ (1 << 7); - break; - case 183: // right - return 0xFFFF ^ (1 << 5); - break; - case 32: // space -> select - return 0xFFFF ^ (1 << 0); - break; - case 13: // enter -> start - return 0xFFFF ^ (1 << 3); - break; - case 108: // L -> A - return 0xFFFF ^ (1 << 13); - break; - case 107: // K -> B - return 0xFFFF ^ (1 << 14); - break; - } - } - - return 0xFFFF; -} - -#else - -void i2c_kbcontrollerInit() -{ - printf("I2C Keyboard disabled in menuconfig; no input enabled.\n"); -} - -int i2c_kbReadInput() -{ - return 0xFFFF; -} - -#endif diff --git a/components/nofrendo-esp32/i2c_kbcontroller.h b/components/nofrendo-esp32/i2c_kbcontroller.h deleted file mode 100644 index fbff4b2..0000000 --- a/components/nofrendo-esp32/i2c_kbcontroller.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _I2C_KEYBOARD_H_ -#define _I2C_KEYBOARD_H_ - -#include -#include "driver/i2c.h" - -void i2c_kbcontrollerInit(); -int i2c_kbReadInput(); - -#endif diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c deleted file mode 100644 index 83c4d6d..0000000 --- a/components/nofrendo-esp32/psxcontroller.c +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "freertos/queue.h" - - -#include "driver/gpio.h" -#include "soc/gpio_struct.h" -#include "psxcontroller.h" -#include "sdkconfig.h" - -#define PSX_CLK CONFIG_HW_PSX_CLK -#define PSX_DAT CONFIG_HW_PSX_DAT -#define PSX_ATT CONFIG_HW_PSX_ATT -#define PSX_CMD CONFIG_HW_PSX_CMD - -#define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") - -#ifdef CONFIG_HW_CONTROLLER_PSX - -/* Sends and receives a byte from/to the PSX controller using SPI */ -static int psxSendRecv(int send) { - int x; - int ret=0; - volatile int delay; - -#if 0 - while(1) { - GPIO.out_w1ts=(1<>=1; - send>>=1; - if (GPIO.in&(1< 2048 + 1024) + { + l = 0; + r = 1; + } + else if (joyX > 1024) + { + l = 1; + r = 0; + } + else + { + l = 1; + r = 1; + } + if (joyY > 2048 + 1024) + { + u = 0; + d = 1; + } + else if (joyY > 1024) + { + u = 1; + d = 0; + } + else + { + u = 1; + d = 1; + } +#else + l = gpio_get_level(LEFT); + r = gpio_get_level(RIGHT); + u = gpio_get_level(UP); + d = gpio_get_level(DOWN); +#endif + + s = gpio_get_level(SELECT); + t = gpio_get_level(START); + a = gpio_get_level(A); + b = gpio_get_level(B); + m = gpio_get_level(MENU); + i = gpio_get_level(AUDIO); + + return 0xFFFF ^ ((!u << 4) | (!d << 6) | (!l << 7) | (!r << 5) | (!s << 0) | (!t << 3) | (!a << 13) | (!b << 14) | (!m << 1) | (!i << 2)); +} + +#elif defined(CONFIG_HW_CONTROLLER_PSX) + +#define PSX_CLK CONFIG_HW_PSX_CLK +#define PSX_DAT CONFIG_HW_PSX_DAT +#define PSX_ATT CONFIG_HW_PSX_ATT +#define PSX_CMD CONFIG_HW_PSX_CMD + +#define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") + +/* Sends and receives a byte from/to the PSX controller using SPI */ +static int psxSendRecv(int send) { + int x; + int ret=0; + volatile int delay; + +#if 0 + while(1) { + GPIO.out_w1ts=(1<>=1; + send>>=1; + if (GPIO.in&(1< 0) << 4) + | (((0x02 & data) > 0) << 6) + | (((0x04 & data) > 0) << 7) + | (((0x08 & data) > 0) << 5) + | (((0x10 & data) > 0) << 0) + | (((0x20 & data) > 0) << 3) + | (((0x40 & data) > 0) << 13) + | (((0x80 & data) > 0) << 14) + ); + } else { + return 0xFFFF; + } +} + +#elif defined(CONFIG_HW_CONTROLLER_I2C_M5KB) + + +#define I2C_KEYBOARD_SCL_IO 22 /*!< gpio number for I2C master clock */ +#define I2C_KEYBOARD_SDA_IO 21 /*!< gpio number for I2C master data */ +#define I2C_KEYBOARD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ +#define I2C_KEYBOARD_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_KEYBOARD_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ +#define I2C_KEYBOARD_FREQ_HZ 100000 /*!< I2C master clock frequency */ +#define I2C_KEYBOARD_ADDR 0x5f + +#define READ_BIT I2C_MASTER_READ /*!< I2C master read */ +#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ +#define NACK_VAL 0x1 /*!< I2C nack value */ + +void controller_init() +{ + int i2c_master_port = I2C_KEYBOARD_NUM; + i2c_config_t conf; + conf.mode = I2C_MODE_MASTER; + conf.sda_io_num = I2C_KEYBOARD_SDA_IO; + conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + conf.scl_io_num = I2C_KEYBOARD_SCL_IO; + conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + conf.master.clk_speed = I2C_KEYBOARD_FREQ_HZ; + i2c_param_config(i2c_master_port, &conf); + i2c_driver_install(i2c_master_port, conf.mode, + I2C_KEYBOARD_RX_BUF_DISABLE, + I2C_KEYBOARD_TX_BUF_DISABLE, 0); +} + +/** + * @brief test code to write esp-i2c-slave + * + * 1. set mode + * _________________________________________________________________ + * | start | slave_addr + wr_bit + ack | write 1 byte + ack | stop | + * --------|---------------------------|---------------------|------| + * 2. wait more than 24 ms + * 3. read data + * ______________________________________________________________________________________ + * | start | slave_addr + rd_bit + ack | read 1 byte + ack | read 1 byte + nack | stop | + * --------|---------------------------|--------------------|--------------------|------| + */ +int controller_read_input() +{ + uint8_t data; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (I2C_KEYBOARD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); + i2c_master_read_byte(cmd, &data, NACK_VAL); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_KEYBOARD_NUM, cmd, 1000 / portTICK_RATE_MS); + i2c_cmd_link_delete(cmd); + if ((ret == 0) && (data > 0)) { + printf("I2C read %d, return %d\n", data, ret); + + switch (data) + { + case 181: // up + return 0xFFFF ^ (1 << 4); + break; + case 182: // down + return 0xFFFF ^ (1 << 6); + break; + case 180: // left + return 0xFFFF ^ (1 << 7); + break; + case 183: // right + return 0xFFFF ^ (1 << 5); + break; + case 32: // space -> select + return 0xFFFF ^ (1 << 0); + break; + case 13: // enter -> start + return 0xFFFF ^ (1 << 3); + break; + case 108: // L -> A + return 0xFFFF ^ (1 << 13); + break; + case 107: // K -> B + return 0xFFFF ^ (1 << 14); + break; + } + } + + return 0xFFFF; +} + +#else + +void controller_gpio_init() +{ + printf("GPIO controller disabled in menuconfig; no input enabled.\n"); +} + +int controller_gpio_read_input() +{ + return 0xFFFF; +} + +#endif \ No newline at end of file diff --git a/main/controller.h b/main/controller.h new file mode 100644 index 0000000..2926c3a --- /dev/null +++ b/main/controller.h @@ -0,0 +1,7 @@ +#ifndef _CONTROLLER_H_ +#define _CONTROLLER_H_ + +int controller_read_input(); +void controller_init(); + +#endif // _CONTROLLER_H_ diff --git a/components/nofrendo-esp32/osd.c b/main/osd.c similarity index 100% rename from components/nofrendo-esp32/osd.c rename to main/osd.c diff --git a/components/nofrendo-esp32/spi_lcd.c b/main/spi_lcd.c similarity index 100% rename from components/nofrendo-esp32/spi_lcd.c rename to main/spi_lcd.c diff --git a/components/nofrendo-esp32/spi_lcd.h b/main/spi_lcd.h similarity index 100% rename from components/nofrendo-esp32/spi_lcd.h rename to main/spi_lcd.h diff --git a/components/nofrendo-esp32/video_audio.c b/main/video_audio.c similarity index 89% rename from components/nofrendo-esp32/video_audio.c rename to main/video_audio.c index f5c0141..43891e1 100644 --- a/components/nofrendo-esp32/video_audio.c +++ b/main/video_audio.c @@ -34,19 +34,11 @@ #include #include #include -#include "driver/i2s.h" +#include #include "sdkconfig.h" -#include - -#if defined CONFIG_HW_CONTROLLER_GPIO -#include -#elif defined CONFIG_HW_CONTROLLER_PSX -#include -#elif defined CONFIG_HW_CONTROLLER_I2C_GP -#include -#elif defined CONFIG_HW_CONTROLLER_I2C_KB -#include -#endif +#include "spi_lcd.h" + +#include "controller.h" #define DEFAULT_SAMPLERATE 32000 #define DEFAULT_FRAGSIZE 128 @@ -266,15 +258,7 @@ static void videoTask(void *arg) static void osd_initinput() { -#if defined CONFIG_HW_CONTROLLER_GPIO - gpiocontrollerInit(); -#elif defined CONFIG_HW_CONTROLLER_PSX - psxcontrollerInit(); -#elif defined CONFIG_HW_CONTROLLER_I2C_GP - i2c_gpcontrollerInit(); -#elif defined CONFIG_HW_CONTROLLER_I2C_KB - i2c_kbcontrollerInit(); -#endif + controller_init(); } void osd_getinput(void) @@ -283,15 +267,7 @@ void osd_getinput(void) event_joypad1_select, event_state_save, event_state_load, event_joypad1_start, event_joypad1_up, event_joypad1_right, event_joypad1_down, event_joypad1_left, 0, 0, 0, 0, event_soft_reset, event_joypad1_a, event_joypad1_b, event_hard_reset}; static int oldb = 0xffff; -#if defined CONFIG_HW_CONTROLLER_GPIO - int b = gpioReadInput(); -#elif defined CONFIG_HW_CONTROLLER_PSX - int b = psxReadInput(); -#elif defined CONFIG_HW_CONTROLLER_I2C_GP - int b = i2c_gpReadInput(); -#elif defined CONFIG_HW_CONTROLLER_I2C_KB - int b = i2c_kbReadInput(); -#endif + int b = controller_read_input(); int chg = b ^ oldb; int x; oldb = b; From 92d33f58c3f790288a39cf8b7901eebc601bdb22 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 1 Oct 2020 00:36:55 +0800 Subject: [PATCH 36/73] format --- main/controller.c | 376 +++++++++++++++++++++++---------------------- main/main.c | 96 ++++++------ main/osd.c | 29 ++-- main/spi_lcd.c | 35 +++-- main/video_audio.c | 39 ++--- 5 files changed, 297 insertions(+), 278 deletions(-) diff --git a/main/controller.c b/main/controller.c index 1355e53..082f2aa 100644 --- a/main/controller.c +++ b/main/controller.c @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "stdio.h" - -#include "driver/adc.h" -#include "driver/gpio.h" -#include "esp_adc_cal.h" -#include "esp_log.h" -#include "esp_system.h" -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" -#include "freertos/task.h" -#include "soc/adc_channel.h" -#include "soc/gpio_struct.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "sdkconfig.h" @@ -187,11 +187,12 @@ int controller_read_input() #define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") /* Sends and receives a byte from/to the PSX controller using SPI */ -static int psxSendRecv(int send) { - int x; - int ret=0; - volatile int delay; - +static int psxSendRecv(int send) +{ + int x; + int ret = 0; + volatile int delay; + #if 0 while(1) { GPIO.out_w1ts=(1<>=1; - send>>=1; - if (GPIO.in&(1<>= 1; + send >>= 1; + if (GPIO.in & (1 << PSX_DAT)) + ret |= 128; + } + return ret; } -static void psxDone() { - DELAY(); - GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, (1< 0) << 4) - | (((0x02 & data) > 0) << 6) - | (((0x04 & data) > 0) << 7) - | (((0x08 & data) > 0) << 5) - | (((0x10 & data) > 0) << 0) - | (((0x20 & data) > 0) << 3) - | (((0x40 & data) > 0) << 13) - | (((0x80 & data) > 0) << 14) - ); - } else { - return 0xFFFF; - } + uint8_t data; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (I2C_GAMEPAD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); + i2c_master_read_byte(cmd, &data, NACK_VAL); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_GAMEPAD_NUM, cmd, 1000 / portTICK_RATE_MS); + i2c_cmd_link_delete(cmd); + if (ret == 0) + { + printf("I2C read %d, return %d\n", data, ret); + + return 0xFFFF ^ ((((0x01 & data) > 0) << 4) | (((0x02 & data) > 0) << 6) | (((0x04 & data) > 0) << 7) | (((0x08 & data) > 0) << 5) | (((0x10 & data) > 0) << 0) | (((0x20 & data) > 0) << 3) | (((0x40 & data) > 0) << 13) | (((0x80 & data) > 0) << 14)); + } + else + { + return 0xFFFF; + } } #elif defined(CONFIG_HW_CONTROLLER_I2C_M5KB) - #define I2C_KEYBOARD_SCL_IO 22 /*!< gpio number for I2C master clock */ #define I2C_KEYBOARD_SDA_IO 21 /*!< gpio number for I2C master data */ #define I2C_KEYBOARD_NUM I2C_NUM_0 /*!< I2C port number for master dev */ @@ -366,18 +371,18 @@ int controller_read_input() void controller_init() { - int i2c_master_port = I2C_KEYBOARD_NUM; - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - conf.sda_io_num = I2C_KEYBOARD_SDA_IO; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.scl_io_num = I2C_KEYBOARD_SCL_IO; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = I2C_KEYBOARD_FREQ_HZ; - i2c_param_config(i2c_master_port, &conf); - i2c_driver_install(i2c_master_port, conf.mode, - I2C_KEYBOARD_RX_BUF_DISABLE, - I2C_KEYBOARD_TX_BUF_DISABLE, 0); + int i2c_master_port = I2C_KEYBOARD_NUM; + i2c_config_t conf; + conf.mode = I2C_MODE_MASTER; + conf.sda_io_num = I2C_KEYBOARD_SDA_IO; + conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + conf.scl_io_num = I2C_KEYBOARD_SCL_IO; + conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + conf.master.clk_speed = I2C_KEYBOARD_FREQ_HZ; + i2c_param_config(i2c_master_port, &conf); + i2c_driver_install(i2c_master_port, conf.mode, + I2C_KEYBOARD_RX_BUF_DISABLE, + I2C_KEYBOARD_TX_BUF_DISABLE, 0); } /** @@ -395,47 +400,48 @@ void controller_init() */ int controller_read_input() { - uint8_t data; - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (I2C_KEYBOARD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); - i2c_master_read_byte(cmd, &data, NACK_VAL); - i2c_master_stop(cmd); - esp_err_t ret = i2c_master_cmd_begin(I2C_KEYBOARD_NUM, cmd, 1000 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if ((ret == 0) && (data > 0)) { - printf("I2C read %d, return %d\n", data, ret); - - switch (data) - { - case 181: // up - return 0xFFFF ^ (1 << 4); - break; - case 182: // down - return 0xFFFF ^ (1 << 6); - break; - case 180: // left - return 0xFFFF ^ (1 << 7); - break; - case 183: // right - return 0xFFFF ^ (1 << 5); - break; - case 32: // space -> select - return 0xFFFF ^ (1 << 0); - break; - case 13: // enter -> start - return 0xFFFF ^ (1 << 3); - break; - case 108: // L -> A - return 0xFFFF ^ (1 << 13); - break; - case 107: // K -> B - return 0xFFFF ^ (1 << 14); - break; - } + uint8_t data; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (I2C_KEYBOARD_ADDR << 1) | READ_BIT, ACK_CHECK_EN); + i2c_master_read_byte(cmd, &data, NACK_VAL); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_KEYBOARD_NUM, cmd, 1000 / portTICK_RATE_MS); + i2c_cmd_link_delete(cmd); + if ((ret == 0) && (data > 0)) + { + printf("I2C read %d, return %d\n", data, ret); + + switch (data) + { + case 181: // up + return 0xFFFF ^ (1 << 4); + break; + case 182: // down + return 0xFFFF ^ (1 << 6); + break; + case 180: // left + return 0xFFFF ^ (1 << 7); + break; + case 183: // right + return 0xFFFF ^ (1 << 5); + break; + case 32: // space -> select + return 0xFFFF ^ (1 << 0); + break; + case 13: // enter -> start + return 0xFFFF ^ (1 << 3); + break; + case 108: // L -> A + return 0xFFFF ^ (1 << 13); + break; + case 107: // K -> B + return 0xFFFF ^ (1 << 14); + break; } + } - return 0xFFFF; + return 0xFFFF; } #else diff --git a/main/main.c b/main/main.c index a2ad89b..3960394 100644 --- a/main/main.c +++ b/main/main.c @@ -1,78 +1,86 @@ -#include "freertos/FreeRTOS.h" -#include "esp_wifi.h" -#include "esp_system.h" -#include "esp_event.h" -#include "esp_event_loop.h" -#include "nvs_flash.h" -#include "driver/gpio.h" -#include "nofrendo.h" -#include "esp_partition.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "esp_log.h" -#include "esp_spiffs.h" +#include "nofrendo.h" char *osd_getromdata() { - char *romdata; - const esp_partition_t *part; - spi_flash_mmap_handle_t hrom; - esp_err_t err; - nvs_flash_init(); - part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); - if (part == 0) - printf("Couldn't find rom part!\n"); - err = esp_partition_mmap(part, 0, 0x140000, SPI_FLASH_MMAP_DATA, (const void **)&romdata, &hrom); - if (err != ESP_OK) - printf("Couldn't map rom part!\n"); - printf("Initialized. ROM@%p\n", romdata); - return (char *)romdata; + char *romdata; + const esp_partition_t *part; + spi_flash_mmap_handle_t hrom; + esp_err_t err; + nvs_flash_init(); + part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); + if (part == 0) + printf("Couldn't find rom part!\n"); + err = esp_partition_mmap(part, 0, 0x140000, SPI_FLASH_MMAP_DATA, (const void **)&romdata, &hrom); + if (err != ESP_OK) + printf("Couldn't map rom part!\n"); + printf("Initialized. ROM@%p\n", romdata); + return (char *)romdata; } esp_err_t event_handler(void *ctx, system_event_t *event) { - return ESP_OK; + return ESP_OK; } void spiffs_init(void) { esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = NULL, - .max_files = 5, - .format_if_mount_failed = true - }; - + .base_path = "/spiffs", + .partition_label = NULL, + .max_files = 5, + .format_if_mount_failed = true}; + // Use settings defined above to initialize and mount SPIFFS filesystem. // Note: esp_vfs_spiffs_register is an all-in-one convenience function. esp_err_t ret = esp_vfs_spiffs_register(&conf); - if (ret != ESP_OK) { - if (ret == ESP_FAIL) { + if (ret != ESP_OK) + { + if (ret == ESP_FAIL) + { printf("Failed to mount or format filesystem"); - } else if (ret == ESP_ERR_NOT_FOUND) { + } + else if (ret == ESP_ERR_NOT_FOUND) + { printf("Failed to find SPIFFS partition"); - } else { + } + else + { printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); } return; } - + size_t total = 0, used = 0; ret = esp_spiffs_info(NULL, &total, &used); - if (ret != ESP_OK) { + if (ret != ESP_OK) + { printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); - } else { + } + else + { printf("Partition size: total: %d, used: %d", total, used); } } int app_main(void) { - spiffs_init(); + spiffs_init(); - printf("NoFrendo start!\n"); - nofrendo_main(0, NULL); - printf("NoFrendo died? Oh no!\n"); - asm("break.n 1"); - return 0; + printf("NoFrendo start!\n"); + nofrendo_main(0, NULL); + printf("NoFrendo died? Oh no!\n"); + asm("break.n 1"); + return 0; } diff --git a/main/osd.c b/main/osd.c index fc0c1ca..606b15c 100644 --- a/main/osd.c +++ b/main/osd.c @@ -6,29 +6,30 @@ ** ** $Id: osd.c,v 1.2 2001/04/27 14:37:11 neil Exp $ ** + */ -#include -#include -#include -#include #include #include #include + #include #include #include -#include - -#include -#include -#include -#include -#include - -#include -char configfilename[]="na"; +#include "errno.h" +#include "fcntl.h" +#include "limits.h" +#include "log.h" +#include "nofconfig.h" +#include "nofrendo.h" +#include "noftypes.h" +#include "osd.h" +#include "signal.h" +#include "unistd.h" +#include "version.h" + +char configfilename[] = "na"; /* This is os-specific part of main() */ int osd_main(int argc, char *argv[]) diff --git a/main/spi_lcd.c b/main/spi_lcd.c index b64978c..4e75fc2 100644 --- a/main/spi_lcd.c +++ b/main/spi_lcd.c @@ -12,23 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include "sdkconfig.h" -#include "rom/ets_sys.h" -#include "rom/gpio.h" -#include "soc/gpio_reg.h" -#include "soc/gpio_sig_map.h" -#include "soc/gpio_struct.h" -#include "soc/io_mux_reg.h" -#include "soc/spi_reg.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "driver/gpio.h" -#include "driver/periph_ctrl.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "spi_lcd.h" -#include "driver/spi_master.h" -#include "driver/ledc.h" + +#include "sdkconfig.h" #define PIN_NUM_MISO CONFIG_HW_LCD_MISO_GPIO #define PIN_NUM_MOSI CONFIG_HW_LCD_MOSI_GPIO @@ -81,7 +84,7 @@ DRAM_ATTR static const lcd_init_cmd_t lcd_init_cmds[] = { {0xC5, {0x35, 0x3E}, 2}, // VCM control {0xC7, {0xBE}, 1}, // VCM control2, was B1h #ifdef CONFIG_HW_LCD_ROTATE_180 - {0x36, {(1 << 5) | (1 << 3)}, 1}, // MV | BGR + {0x36, {(1 << 5) | (1 << 3)}, 1}, // MV | BGR #else {0x36, {(1 << 7) | (1 << 6) | (1 << 5) | (1 << 3)}, 1}, // MY | MX | MV | BGR #endif diff --git a/main/video_audio.c b/main/video_audio.c index 43891e1..d039948 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + +#include #include #include #include @@ -21,25 +25,23 @@ #undef true #undef bool -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sdkconfig.h" +#include "bitmap.h" +#include "event.h" +#include "noftypes.h" +#include "nofconfig.h" +#include "gui.h" +#include "log.h" +#include "nes.h" +#include "nes_pal.h" +#include "nesinput.h" +#include "osd.h" +#include "stdint.h" #include "spi_lcd.h" #include "controller.h" +#include "sdkconfig.h" + #define DEFAULT_SAMPLERATE 32000 #define DEFAULT_FRAGSIZE 128 @@ -82,8 +84,8 @@ static void do_audio_frame() { // audio_frame[i] = audio_frame[i] + 0x8000; int16_t a = (audio_frame[i] >> 3); - audio_frame[i*2+1] = 0x8000 + a; - audio_frame[i*2] = 0x8000 - a; + audio_frame[i * 2 + 1] = 0x8000 + a; + audio_frame[i * 2] = 0x8000 - a; } size_t i2s_bytes_write; i2s_write(I2S_NUM_0, (const char *)audio_frame, 4 * n, &i2s_bytes_write, portMAX_DELAY); @@ -116,8 +118,7 @@ static int osd_init_sound(void) .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, .dma_buf_count = 6, .dma_buf_len = 512, - .use_apll = false - }; + .use_apll = false}; i2s_driver_install(I2S_NUM_0, &cfg, 2, &queue); i2s_set_pin(I2S_NUM_0, NULL); i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); From 0015c14076246ee4bb6c6d8ec3c1e5ab673d9ce6 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 1 Oct 2020 00:41:05 +0800 Subject: [PATCH 37/73] format --- main/osd.c | 3 ++- main/video_audio.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/main/osd.c b/main/osd.c index 606b15c..9dd16cf 100644 --- a/main/osd.c +++ b/main/osd.c @@ -21,7 +21,6 @@ #include "fcntl.h" #include "limits.h" #include "log.h" -#include "nofconfig.h" #include "nofrendo.h" #include "noftypes.h" #include "osd.h" @@ -29,6 +28,8 @@ #include "unistd.h" #include "version.h" +#include "nofconfig.h" + char configfilename[] = "na"; /* This is os-specific part of main() */ diff --git a/main/video_audio.c b/main/video_audio.c index d039948..deabc25 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -28,7 +28,6 @@ #include "bitmap.h" #include "event.h" #include "noftypes.h" -#include "nofconfig.h" #include "gui.h" #include "log.h" #include "nes.h" @@ -40,6 +39,7 @@ #include "controller.h" +#include "nofconfig.h" #include "sdkconfig.h" #define DEFAULT_SAMPLERATE 32000 From 02031b7f795b0964442754f24f0bc7fc1494bcd5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 1 Oct 2020 12:26:22 +0800 Subject: [PATCH 38/73] #include --- main/controller.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main/controller.c b/main/controller.c index 082f2aa..6f0a4f1 100644 --- a/main/controller.c +++ b/main/controller.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include From caed33e5a9f4ec73af935a31ba31c30b5cf16173 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 5 Oct 2020 21:25:08 +0800 Subject: [PATCH 39/73] keep nofrendo original design --- .gitignore | 2 +- components/nofrendo/log.c | 7 ++- components/nofrendo/nes/nes_ppu.c | 4 +- components/nofrendo/nes/nes_rom.c | 70 +++++++++++++++--------------- components/nofrendo/nes/nesstate.c | 22 +++++----- components/nofrendo/nofconfig.h | 3 ++ flashrom.sh | 3 -- main/controller.c | 9 ++-- main/main.c | 28 ++---------- main/osd.c | 2 +- main/spi_lcd.c | 5 ++- main/video_audio.c | 4 +- 12 files changed, 70 insertions(+), 89 deletions(-) delete mode 100755 flashrom.sh diff --git a/.gitignore b/.gitignore index 3f1c04f..dd5a3dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -build/ +build sdkconfig sdkconfig.old *.nes diff --git a/components/nofrendo/log.c b/components/nofrendo/log.c index d69b304..77342a1 100644 --- a/components/nofrendo/log.c +++ b/components/nofrendo/log.c @@ -62,8 +62,7 @@ int log_print(const char *string) log_func(string); /* Log it to disk, as well */ -// fputs(string, errorlog); -// printf("%s\n", string); + // fputs(string, errorlog); return 0; } @@ -82,7 +81,7 @@ int log_printf(const char *format, ... ) log_func(buffer); } -// vfprintf(errorlog, format, arg); + // vfprintf(errorlog, format, arg); va_end(arg); return 0; /* should be number of chars written */ @@ -130,7 +129,7 @@ void log_assert(int expr, int line, const char *file, char *msg) log_printf("ASSERT: line %d of %s\n", line, file); asm("break.n 1"); -// exit(-1); + // exit(-1); } diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 65af465..37dc191 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -372,8 +372,8 @@ uint8 ppu_read(uint32 address) if ((ppu.bg_on || ppu.obj_on) && !ppu.vram_accessible) { ppu.vdata_latch = 0xFF; - log_printf("VRAM read at $%04X, scanline %d\n", - ppu.vaddr, nes_getcontextptr()->scanline); + // log_printf("VRAM read at $%04X, scanline %d\n", + // ppu.vaddr, nes_getcontextptr()->scanline); } else { diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index 2b780a2..8ffe0e2 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -37,8 +37,6 @@ #include #include -extern char *osd_getromdata(); - /* Max length for displayed filename */ #define ROM_DISP_MAXLEN 20 @@ -59,7 +57,6 @@ extern char *osd_getromdata(); #define ROM_MIRRORTYPE 0x01 #define ROM_INES_MAGIC "NES\x1A" -//ToDo: packed - JD typedef struct inesheader_s { uint8 ines_magic[4]; @@ -68,7 +65,7 @@ typedef struct inesheader_s uint8 rom_type; uint8 mapper_hinybble; uint8 reserved[8]; -} inesheader_t; +} __attribute__((packed)) inesheader_t; #define TRAINER_OFFSET 0x1000 #define TRAINER_LENGTH 0x200 @@ -143,27 +140,24 @@ static int rom_allocsram(rominfo_t *rominfo) } /* If there's a trainer, load it in at $7000 */ -static void rom_loadtrainer(unsigned char **rom, rominfo_t *rominfo) +static void rom_loadtrainer(FILE *fp, rominfo_t *rominfo) { - ASSERT(rom); + ASSERT(fp); ASSERT(rominfo); if (rominfo->flags & ROM_FLAG_TRAINER) { - // fread(rominfo->sram + TRAINER_OFFSET, TRAINER_LENGTH, 1, fp); - memcpy(rominfo->sram + TRAINER_OFFSET, *rom, TRAINER_LENGTH); - rom += TRAINER_LENGTH; + fread(rominfo->sram + TRAINER_OFFSET, TRAINER_LENGTH, 1, fp); log_printf("Read in trainer at $7000\n"); } } -static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) +static int rom_loadrom(FILE *fp, rominfo_t *rominfo) { - ASSERT(rom); + ASSERT(fp); ASSERT(rominfo); /* Allocate ROM space, and load it up! */ - /* rominfo->rom = malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); if (NULL == rominfo->rom) { @@ -171,14 +165,10 @@ static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) return -1; } _fread(rominfo->rom, ROM_BANK_LENGTH, rominfo->rom_banks, fp); -*/ - rominfo->rom = *rom; - *rom += ROM_BANK_LENGTH * rominfo->rom_banks; /* If there's VROM, allocate and stuff it in */ if (rominfo->vrom_banks) { - /* rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); if (NULL == rominfo->vrom) { @@ -186,9 +176,6 @@ static int rom_loadrom(unsigned char **rom, rominfo_t *rominfo) return -1; } _fread(rominfo->vrom, VROM_BANK_LENGTH, rominfo->vrom_banks, fp); -*/ - rominfo->vrom = *rom; - *rom += VROM_BANK_LENGTH * rominfo->vrom_banks; } else { @@ -232,7 +219,7 @@ static void rom_checkforpal(rominfo_t *rominfo) /* TODO: this should really be a *SYSTEM* flag */ rominfo->flags |= ROM_FLAG_VERSUS; /* TODO: bad, BAD idea, calling nes_getcontextptr... */ - ppu_setpal(nes_getcontextptr()->ppu, vs_pal); + // ppu_setpal(nes_getcontextptr()->ppu, vs_pal); log_printf("Game specific palette found -- assuming VS. UniSystem\n"); } @@ -319,22 +306,19 @@ int rom_checkmagic(const char *filename) return -1; } -static int rom_getheader(unsigned char **rom, rominfo_t *rominfo) +static int rom_getheader(FILE *fp, rominfo_t *rominfo) { #define RESERVED_LENGTH 8 inesheader_t head; uint8 reserved[RESERVED_LENGTH]; bool header_dirty; - ASSERT(rom); - ASSERT(*rom); + ASSERT(fp); ASSERT(rominfo); /* Read in the header */ - // _fread(&head, 1, sizeof(head), fp); - printf("Head: %p (%x %x %x %x)\n", *rom, (*rom)[0], (*rom)[1], (*rom)[2], (*rom)[3]); - memcpy(&head, *rom, sizeof(head)); - *rom += sizeof(head); + _fread(&head, sizeof(head), 1, fp); + if (memcmp(head.ines_magic, ROM_INES_MAGIC, 4)) { @@ -434,7 +418,7 @@ char *rom_getinfo(rominfo_t *rominfo) /* Load a ROM image into memory */ rominfo_t *rom_load(const char *filename) { - unsigned char *rom = (unsigned char *)osd_getromdata(); + FILE *fp; rominfo_t *rominfo; rominfo = malloc(sizeof(rominfo_t)); @@ -443,8 +427,15 @@ rominfo_t *rom_load(const char *filename) memset(rominfo, 0, sizeof(rominfo_t)); + fp = rom_findrom(filename, rominfo); + + if (NULL == fp) + gui_sendmsg(GUI_RED, "%s not found, will use default ROM", filename); + /* Get the header and stick it into rominfo struct */ - if (rom_getheader(&rom, rominfo)) + if (NULL == fp) + intro_get_header(rominfo); + else if (rom_getheader(fp, rominfo)) goto _fail; /* Make sure we really support the mapper */ @@ -459,26 +450,35 @@ rominfo_t *rom_load(const char *filename) ** UNIF, TAKE ME AWAY! AAAAAAAAAA!!! */ if (rom_allocsram(rominfo)) - { goto _fail; - } - rom_loadtrainer(&rom, rominfo); - if (rom_loadrom(&rom, rominfo)) + if (NULL != fp) + rom_loadtrainer(fp, rominfo); + + if (NULL == fp) { - goto _fail; + if (intro_get_rom(rominfo)) + goto _fail; } + else if (rom_loadrom(fp, rominfo)) + goto _fail; + + /* Close the file */ + if (NULL != fp) + _fclose(fp); rom_loadsram(rominfo); /* See if there's a palette we can load up */ - // rom_checkforpal(rominfo); + rom_checkforpal(rominfo); gui_sendmsg(GUI_GREEN, "ROM loaded: %s", rom_getinfo(rominfo)); return rominfo; _fail: + if (NULL != fp) + _fclose(fp); rom_free(&rominfo); return NULL; } diff --git a/components/nofrendo/nes/nesstate.c b/components/nofrendo/nes/nesstate.c index e399ef3..c010f56 100644 --- a/components/nofrendo/nes/nesstate.c +++ b/components/nofrendo/nes/nesstate.c @@ -341,7 +341,7 @@ int state_save(void) { SNSS_FILE *snssFile; SNSS_RETURN_CODE status; - // char fn[PATH_MAX + 1], ext[5]; + char fn[PATH_MAX + 1], ext[5]; nes_t *machine; /* get the pointer to our NES machine context */ @@ -349,12 +349,11 @@ int state_save(void) ASSERT(machine); /* build our filename using the image's name and the slot number */ - // strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); + strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); - // ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); - // sprintf(ext, ".ss%d", state_slot); - // osd_newextension(fn, ext); - char *fn = "/spiffs/state.sav"; + ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); + sprintf(ext, ".ss%d", state_slot); + osd_newextension(fn, ext); /* open our state file for writing */ status = SNSS_OpenFile(&snssFile, fn, SNSS_OPEN_WRITE); @@ -416,7 +415,7 @@ int state_load(void) SNSS_FILE *snssFile; SNSS_RETURN_CODE status; SNSS_BLOCK_TYPE block_type; - // char fn[PATH_MAX + 1], ext[5]; + char fn[PATH_MAX + 1], ext[5]; unsigned int i; nes_t *machine; @@ -425,12 +424,11 @@ int state_load(void) ASSERT(machine); /* build the state name using the ROM's name and the slot number */ - // strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); + strncpy(fn, machine->rominfo->filename, PATH_MAX - 4); - // ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); - // sprintf(ext, ".ss%d", state_slot); - // osd_newextension(fn, ext); - char *fn = "/spiffs/state.sav"; + ASSERT(state_slot >= FIRST_STATE_SLOT && state_slot <= LAST_STATE_SLOT); + sprintf(ext, ".ss%d", state_slot); + osd_newextension(fn, ext); /* open our file for writing */ status = SNSS_OpenFile(&snssFile, fn, SNSS_OPEN_READ); diff --git a/components/nofrendo/nofconfig.h b/components/nofrendo/nofconfig.h index 961a017..1676e13 100644 --- a/components/nofrendo/nofconfig.h +++ b/components/nofrendo/nofconfig.h @@ -12,6 +12,9 @@ #define CONFIG_FILE "nofrendo.cfg" #endif +#define FSROOT "/spiffs" +#define ROM_FILE FSROOT "/rom.nes" + typedef struct config_s { /* open loads from the disk the saved configuration. diff --git a/flashrom.sh b/flashrom.sh deleted file mode 100755 index a2636dd..0000000 --- a/flashrom.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# . ${IDF_PATH}/add_path.sh -esptool.py --chip esp32 --port "/dev/cu.SLAB_USBtoUART" --baud $((230400*4)) write_flash -fs 4MB 0x150000 "$1" diff --git a/main/controller.c b/main/controller.c index 6f0a4f1..10b59be 100644 --- a/main/controller.c +++ b/main/controller.c @@ -14,16 +14,17 @@ #include +#include +#include +#include +#include + #include #include #include #include #include #include -#include -#include -#include -#include #include #include diff --git a/main/main.c b/main/main.c index 3960394..f3454d5 100644 --- a/main/main.c +++ b/main/main.c @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -6,37 +8,15 @@ #include #include #include -#include #include +#include "nofconfig.h" #include "nofrendo.h" -char *osd_getromdata() -{ - char *romdata; - const esp_partition_t *part; - spi_flash_mmap_handle_t hrom; - esp_err_t err; - nvs_flash_init(); - part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); - if (part == 0) - printf("Couldn't find rom part!\n"); - err = esp_partition_mmap(part, 0, 0x140000, SPI_FLASH_MMAP_DATA, (const void **)&romdata, &hrom); - if (err != ESP_OK) - printf("Couldn't map rom part!\n"); - printf("Initialized. ROM@%p\n", romdata); - return (char *)romdata; -} - -esp_err_t event_handler(void *ctx, system_event_t *event) -{ - return ESP_OK; -} - void spiffs_init(void) { esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", + .base_path = FSROOT, .partition_label = NULL, .max_files = 5, .format_if_mount_failed = true}; diff --git a/main/osd.c b/main/osd.c index 9dd16cf..7a350c5 100644 --- a/main/osd.c +++ b/main/osd.c @@ -37,7 +37,7 @@ int osd_main(int argc, char *argv[]) { config.filename = configfilename; - return main_loop("rom", system_autodetect); + return main_loop(ROM_FILE, system_autodetect); } /* File system interface */ diff --git a/main/spi_lcd.c b/main/spi_lcd.c index 4e75fc2..4cd3d3d 100644 --- a/main/spi_lcd.c +++ b/main/spi_lcd.c @@ -15,12 +15,13 @@ #include #include +#include +#include + #include #include #include #include -#include -#include #include #include #include diff --git a/main/video_audio.c b/main/video_audio.c index deabc25..c8aa5bc 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -15,11 +15,13 @@ #include #include -#include #include #include #include #include + +#include + //Nes stuff wants to define this as well... #undef false #undef true From 110cc52cd0ef46f98be129c60ed4ca878513377f Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 5 Oct 2020 22:28:27 +0800 Subject: [PATCH 40/73] enable PSRAM --- components/nofrendo/nes/nes_rom.c | 13 +++++++++++-- sdkconfig.defaults | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index 8ffe0e2..0aa838b 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -27,6 +27,13 @@ #include #include + +#include +//Nes stuff wants to define this as well... +#undef false +#undef true +#undef bool + #include #include #include @@ -158,7 +165,8 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) ASSERT(rominfo); /* Allocate ROM space, and load it up! */ - rominfo->rom = malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); + // rominfo->rom = malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); + rominfo->rom = heap_caps_malloc((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); if (NULL == rominfo->rom) { gui_sendmsg(GUI_RED, "Could not allocate space for ROM image"); @@ -169,7 +177,8 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* If there's VROM, allocate and stuff it in */ if (rominfo->vrom_banks) { - rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); + // rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); + rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); if (NULL == rominfo->vrom) { gui_sendmsg(GUI_RED, "Could not allocate space for VROM"); diff --git a/sdkconfig.defaults b/sdkconfig.defaults index a3aa700..b5d8480 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -84,6 +84,9 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_ESP32_DEFAULT_CPU_FREQ_160= CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 +CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_SPIRAM_BOOT_INIT=y +CONFIG_SPIRAM_IGNORE_NOTFOUND=y CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 CONFIG_MAIN_TASK_STACK_SIZE=12240 CONFIG_TIMER_TASK_STACK_SIZE=4096 @@ -96,6 +99,12 @@ CONFIG_ESP32_XTAL_FREQ_40= CONFIG_ESP32_XTAL_FREQ_AUTO=y CONFIG_ESP32_XTAL_FREQ=0 +# +# SPI RAM config +# +CONFIG_SPIRAM_USE_CAPS_ALLOC=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y + # # Wi-Fi # From a8658d8aafab6c3c34a9d19cb9966c1c6d7522b3 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 5 Oct 2020 22:29:02 +0800 Subject: [PATCH 41/73] dirty implement osd_newextension --- main/osd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/osd.c b/main/osd.c index 7a350c5..895142c 100644 --- a/main/osd.c +++ b/main/osd.c @@ -49,6 +49,12 @@ void osd_fullname(char *fullname, const char *shortname) /* This gives filenames for storage of saves */ char *osd_newextension(char *string, char *ext) { + // dirty: assume extension is 3 characters + size_t l = strlen(string); + string[l - 3] = ext[1]; + string[l - 2] = ext[2]; + string[l - 1] = ext[3]; + return string; } From 9aa608479c05a261c29ea9fbc694c48f61ae78b5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 19:33:13 +0800 Subject: [PATCH 42/73] relative include path and avoid undef --- components/nofrendo/bitmap.c | 23 +++--- components/nofrendo/bitmap.h | 4 +- components/nofrendo/config.c | 54 ++++++------- components/nofrendo/cpu/dis6502.c | 3 +- components/nofrendo/cpu/nes6502.c | 13 ++-- components/nofrendo/cpu/nes6502.h | 4 +- components/nofrendo/event.c | 19 ++--- components/nofrendo/event.h | 2 +- components/nofrendo/gui.c | 95 +++++++++++------------ components/nofrendo/gui.h | 4 +- components/nofrendo/gui_elem.c | 7 +- components/nofrendo/intro.c | 9 ++- components/nofrendo/intro.h | 2 +- components/nofrendo/libsnss/libsnss.c | 15 ++-- components/nofrendo/libsnss/libsnss.h | 2 + components/nofrendo/log.c | 4 +- components/nofrendo/mappers/map000.c | 4 +- components/nofrendo/mappers/map001.c | 6 +- components/nofrendo/mappers/map002.c | 4 +- components/nofrendo/mappers/map003.c | 4 +- components/nofrendo/mappers/map004.c | 24 +++--- components/nofrendo/mappers/map005.c | 22 +++--- components/nofrendo/mappers/map007.c | 8 +- components/nofrendo/mappers/map008.c | 4 +- components/nofrendo/mappers/map009.c | 8 +- components/nofrendo/mappers/map010.c | 8 +- components/nofrendo/mappers/map011.c | 4 +- components/nofrendo/mappers/map015.c | 6 +- components/nofrendo/mappers/map016.c | 14 ++-- components/nofrendo/mappers/map018.c | 8 +- components/nofrendo/mappers/map019.c | 8 +- components/nofrendo/mappers/map024.c | 12 +-- components/nofrendo/mappers/map032.c | 6 +- components/nofrendo/mappers/map033.c | 6 +- components/nofrendo/mappers/map034.c | 4 +- components/nofrendo/mappers/map040.c | 18 ++--- components/nofrendo/mappers/map041.c | 10 +-- components/nofrendo/mappers/map042.c | 16 ++-- components/nofrendo/mappers/map046.c | 10 +-- components/nofrendo/mappers/map050.c | 16 ++-- components/nofrendo/mappers/map064.c | 26 +++---- components/nofrendo/mappers/map065.c | 12 +-- components/nofrendo/mappers/map066.c | 4 +- components/nofrendo/mappers/map070.c | 6 +- components/nofrendo/mappers/map073.c | 20 ++--- components/nofrendo/mappers/map075.c | 6 +- components/nofrendo/mappers/map078.c | 6 +- components/nofrendo/mappers/map079.c | 4 +- components/nofrendo/mappers/map085.c | 16 ++-- components/nofrendo/mappers/map087.c | 10 +-- components/nofrendo/mappers/map093.c | 6 +- components/nofrendo/mappers/map094.c | 4 +- components/nofrendo/mappers/map099.c | 6 +- components/nofrendo/mappers/map160.c | 26 +++---- components/nofrendo/mappers/map229.c | 10 +-- components/nofrendo/mappers/map231.c | 4 +- components/nofrendo/mappers/mapvrc.c | 10 +-- components/nofrendo/memguard.c | 47 ++++++------ components/nofrendo/memguard.h | 30 ++++---- components/nofrendo/nes/mmclist.c | 4 +- components/nofrendo/nes/mmclist.h | 2 +- components/nofrendo/nes/nes.c | 85 ++++++++++----------- components/nofrendo/nes/nes.h | 24 +++--- components/nofrendo/nes/nes_mmc.c | 27 +++---- components/nofrendo/nes/nes_mmc.h | 8 +- components/nofrendo/nes/nes_pal.c | 8 +- components/nofrendo/nes/nes_ppu.c | 91 +++++++++++----------- components/nofrendo/nes/nes_ppu.h | 20 ++--- components/nofrendo/nes/nes_rom.c | 60 +++++++-------- components/nofrendo/nes/nes_rom.h | 5 +- components/nofrendo/nes/nesinput.c | 6 +- components/nofrendo/nes/nesstate.c | 31 ++++---- components/nofrendo/nes/nesstate.h | 2 +- components/nofrendo/nofconfig.h | 10 ++- components/nofrendo/nofrendo.c | 45 +++++------ components/nofrendo/noftypes.h | 12 +-- components/nofrendo/osd.h | 4 +- components/nofrendo/pcx.c | 7 +- components/nofrendo/pcx.h | 4 +- components/nofrendo/sndhrdw/fds_snd.c | 6 +- components/nofrendo/sndhrdw/fds_snd.h | 2 +- components/nofrendo/sndhrdw/mmc5_snd.c | 33 ++++---- components/nofrendo/sndhrdw/mmc5_snd.h | 2 +- components/nofrendo/sndhrdw/nes_apu.c | 100 ++++++++++++------------- components/nofrendo/sndhrdw/nes_apu.h | 34 ++++----- components/nofrendo/sndhrdw/vrcvisnd.c | 18 ++--- components/nofrendo/sndhrdw/vrcvisnd.h | 2 +- components/nofrendo/vid_drv.c | 23 +++--- components/nofrendo/vid_drv.h | 6 +- main/video_audio.c | 11 +-- 90 files changed, 720 insertions(+), 715 deletions(-) diff --git a/components/nofrendo/bitmap.c b/components/nofrendo/bitmap.c index 58d32e2..7cb6805 100644 --- a/components/nofrendo/bitmap.c +++ b/components/nofrendo/bitmap.c @@ -25,15 +25,16 @@ #include #include -#include -#include + +#include "noftypes.h" +#include "bitmap.h" void bmp_clear(const bitmap_t *bitmap, uint8 color) { memset(bitmap->data, color, bitmap->pitch * bitmap->height); } -static bitmap_t *_make_bitmap(uint8 *data_addr, bool hw, int width, +static bitmap_t *_make_bitmap(uint8 *data_addr, nofrendo_bool hw, int width, int height, int pitch, int overdraw) { bitmap_t *bitmap; @@ -44,7 +45,7 @@ static bitmap_t *_make_bitmap(uint8 *data_addr, bool hw, int width, return NULL; /* Make sure to add in space for line pointers */ - bitmap = malloc(sizeof(bitmap_t) + (sizeof(uint8 *) * height)); + bitmap = nofrendo_malloc(sizeof(bitmap_t) + (sizeof(uint8 *) * height)); if (NULL == bitmap) return NULL; @@ -58,7 +59,7 @@ static bitmap_t *_make_bitmap(uint8 *data_addr, bool hw, int width, /* we want to make some 32-bit aligned adjustment ** if we haven't been given a hardware bitmap */ - if (false == bitmap->hardware) + if (nofrendo_false == bitmap->hardware) { bitmap->pitch = (bitmap->pitch + 3) & ~3; bitmap->line[0] = (uint8 *) (((uint32) bitmap->data + overdraw + 3) & ~3); @@ -81,17 +82,17 @@ bitmap_t *bmp_create(int width, int height, int overdraw) int pitch; pitch = width + (overdraw * 2); /* left and right */ - addr = malloc((pitch * height) + 3); /* add max 32-bit aligned adjustment */ + addr = nofrendo_malloc((pitch * height) + 3); /* add max 32-bit aligned adjustment */ if (NULL == addr) return NULL; - return _make_bitmap(addr, false, width, height, width, overdraw); + return _make_bitmap(addr, nofrendo_false, width, height, width, overdraw); } /* allocate and initialize a hardware bitmap */ bitmap_t *bmp_createhw(uint8 *addr, int width, int height, int pitch) { - return _make_bitmap(addr, true, width, height, pitch, 0); /* zero overdraw */ + return _make_bitmap(addr, nofrendo_true, width, height, pitch, 0); /* zero overdraw */ } /* Deallocate space for a bitmap structure */ @@ -99,9 +100,9 @@ void bmp_destroy(bitmap_t **bitmap) { if (*bitmap) { - if ((*bitmap)->data && false == (*bitmap)->hardware) - free((*bitmap)->data); - free(*bitmap); + if ((*bitmap)->data && nofrendo_false == (*bitmap)->hardware) + nofrendo_free((*bitmap)->data); + nofrendo_free(*bitmap); *bitmap = NULL; } } diff --git a/components/nofrendo/bitmap.h b/components/nofrendo/bitmap.h index fe3c624..2a37908 100644 --- a/components/nofrendo/bitmap.h +++ b/components/nofrendo/bitmap.h @@ -26,7 +26,7 @@ #ifndef _BITMAP_H_ #define _BITMAP_H_ -#include +#include "noftypes.h" /* a bitmap rectangle */ typedef struct rect_s @@ -43,7 +43,7 @@ typedef struct rgb_s typedef struct bitmap_s { int width, height, pitch; - bool hardware; /* is data a hardware region? */ + nofrendo_bool hardware; /* is data a hardware region? */ uint8 *data; /* protected */ uint8 *line[ZERO_LENGTH]; /* will hold line pointers */ } bitmap_t; diff --git a/components/nofrendo/config.c b/components/nofrendo/config.c index 1739575..009475a 100644 --- a/components/nofrendo/config.c +++ b/components/nofrendo/config.c @@ -8,11 +8,11 @@ #include #include -#include -#include -#include -#include -#include +#include "noftypes.h" +#include "log.h" +#include "osd.h" +#include "nofconfig.h" +#include "version.h" typedef struct myvar_s { @@ -21,7 +21,7 @@ typedef struct myvar_s } myvar_t; static myvar_t *myVars = NULL; -static bool mySaveNeeded = false; +static nofrendo_bool mySaveNeeded = nofrendo_false; static void my_destroy(myvar_t **var) @@ -29,19 +29,19 @@ static void my_destroy(myvar_t **var) ASSERT(*var); if ((*var)->group) - free((*var)->group); + nofrendo_free((*var)->group); if ((*var)->key) - free((*var)->key); + nofrendo_free((*var)->key); if ((*var)->value) - free((*var)->value); - free(*var); + nofrendo_free((*var)->value); + nofrendo_free(*var); } static myvar_t *my_create(const char *group, const char *key, const char *value) { myvar_t *var; - var = malloc(sizeof(*var)); + var = nofrendo_malloc(sizeof(*var)); if (NULL == var) { return 0; @@ -50,9 +50,9 @@ static myvar_t *my_create(const char *group, const char *key, const char *value) var->less = var->greater = NULL; var->group = var->key = var->value = NULL; - if ((var->group = malloc(strlen(group) + 1)) - && (var->key = malloc(strlen(key) + 1)) - && (var->value = malloc(strlen(value) + 1))) + if ((var->group = nofrendo_malloc(strlen(group) + 1)) + && (var->key = nofrendo_malloc(strlen(key) + 1)) + && (var->value = nofrendo_malloc(strlen(value) + 1))) { strcpy(var->group, group); strcpy(var->key, key); @@ -146,13 +146,13 @@ static char *my_getline(FILE *stream) if (NULL == (fgets(buf, sizeof(buf), stream))) { if (dynamic) - free(dynamic); + nofrendo_free(dynamic); return 0; } if (NULL == dynamic) { - dynamic = malloc(strlen(buf) + 1); + dynamic = nofrendo_malloc(strlen(buf) + 1); if (NULL == dynamic) { return 0; @@ -163,12 +163,12 @@ static char *my_getline(FILE *stream) { /* a mini-version of realloc that works with our memory manager */ char *temp = NULL; - temp = malloc(strlen(dynamic) + strlen(buf) + 1); + temp = nofrendo_malloc(strlen(dynamic) + strlen(buf) + 1); if (NULL == temp) return 0; strcpy(temp, dynamic); - free(dynamic); + nofrendo_free(dynamic); dynamic = temp; strcat(dynamic, buf); @@ -194,7 +194,7 @@ static int load_config(char *filename) char *line; char *group = NULL, *key = NULL, *value = NULL; - mySaveNeeded = true; + mySaveNeeded = nofrendo_true; while ((line = my_getline(config_file))) { char *s; @@ -220,7 +220,7 @@ static int load_config(char *filename) case '[': if (group) - free(group); + nofrendo_free(group); group = ++s; @@ -235,7 +235,7 @@ static int load_config(char *filename) *s++ = '\0'; } - if ((value = malloc(strlen(group) + 1))) + if ((value = nofrendo_malloc(strlen(group) + 1))) { strcpy(value, group); } @@ -278,11 +278,11 @@ static int load_config(char *filename) } } while (*s); - free(line); + nofrendo_free(line); } if (group) - free(group); + nofrendo_free(group); fclose(config_file); } @@ -311,14 +311,14 @@ static int save_config(char *filename) return 0; } -static bool open_config(void) +static nofrendo_bool open_config(void) { return load_config(config.filename); } static void close_config(void) { - if (true == mySaveNeeded) + if (nofrendo_true == mySaveNeeded) { save_config(config.filename); } @@ -342,7 +342,7 @@ static void write_int(const char *group, const char *key, int value) } my_insert(var); - mySaveNeeded = true; + mySaveNeeded = nofrendo_true; } /* read_int loads an integer from the configuration into "value" @@ -376,7 +376,7 @@ static void write_string(const char *group, const char *key, const char *value) } my_insert(var); - mySaveNeeded = true; + mySaveNeeded = nofrendo_true; } /* read_string copies a string from the configuration into "value" diff --git a/components/nofrendo/cpu/dis6502.c b/components/nofrendo/cpu/dis6502.c index 197b425..e77e3e0 100644 --- a/components/nofrendo/cpu/dis6502.c +++ b/components/nofrendo/cpu/dis6502.c @@ -24,7 +24,8 @@ */ #include -#include + +#include "../noftypes.h" #include "nes6502.h" #include "dis6502.h" diff --git a/components/nofrendo/cpu/nes6502.c b/components/nofrendo/cpu/nes6502.c index 9484290..7d863d8 100644 --- a/components/nofrendo/cpu/nes6502.c +++ b/components/nofrendo/cpu/nes6502.c @@ -26,7 +26,6 @@ */ -#include #include "nes6502.h" #include "dis6502.h" @@ -244,7 +243,7 @@ ** flag variables, and mask out the irrelevant data when ** we need to check them (branches, etc). This makes the ** zero flag only really be 'set' when z_flag == 0. -** The rest of the flags are stored as true booleans. +** The rest of the flags are stored as nofrendo_true booleans. */ /* Scatter flags to separate variables */ @@ -686,7 +685,7 @@ #define JAM() \ { \ PC--; \ - cpu.jammed = true; \ + cpu.jammed = nofrendo_true; \ cpu.int_pending = 0; \ ADD_CYCLES(2); \ } @@ -1303,7 +1302,7 @@ uint8 nes6502_getbyte(uint32 address) } /* get number of elapsed cycles */ -uint32 nes6502_getcycles(bool reset_flag) +uint32 nes6502_getcycles(nofrendo_bool reset_flag) { uint32 cycles = cpu.total_cycles; @@ -2411,7 +2410,7 @@ void nes6502_reset(void) cpu.int_latency = 0; /* No latent interrupts */ cpu.pc_reg = bank_readword(RESET_VECTOR); /* Fetch reset vector */ cpu.burn_cycles = RESET_CYCLES; - cpu.jammed = false; + cpu.jammed = nofrendo_false; } /* following macro is used for below 2 functions */ @@ -2426,7 +2425,7 @@ void nes6502_nmi(void) { DECLARE_LOCAL_REGS - if (false == cpu.jammed) + if (nofrendo_false == cpu.jammed) { GET_GLOBAL_REGS(); NMI_PROC(); @@ -2440,7 +2439,7 @@ void nes6502_irq(void) { DECLARE_LOCAL_REGS - if (false == cpu.jammed) + if (nofrendo_false == cpu.jammed) { GET_GLOBAL_REGS(); if (0 == i_flag) diff --git a/components/nofrendo/cpu/nes6502.h b/components/nofrendo/cpu/nes6502.h index c2245a1..5d87b56 100644 --- a/components/nofrendo/cpu/nes6502.h +++ b/components/nofrendo/cpu/nes6502.h @@ -29,7 +29,7 @@ #ifndef _NES6502_H_ #define _NES6502_H_ -#include +#include "../noftypes.h" /* Define this to enable decimal mode in ADC / SBC (not needed in NES) */ /*#define NES6502_DECIMAL*/ @@ -105,7 +105,7 @@ extern int nes6502_execute(int total_cycles); extern void nes6502_nmi(void); extern void nes6502_irq(void); extern uint8 nes6502_getbyte(uint32 address); -extern uint32 nes6502_getcycles(bool reset_flag); +extern uint32 nes6502_getcycles(nofrendo_bool reset_flag); extern void nes6502_burn(int cycles); extern void nes6502_release(void); diff --git a/components/nofrendo/event.c b/components/nofrendo/event.c index 2bad388..4e12ca3 100644 --- a/components/nofrendo/event.c +++ b/components/nofrendo/event.c @@ -24,17 +24,18 @@ */ #include -#include -#include -#include -#include -#include + +#include "noftypes.h" +#include "event.h" +#include "nofrendo.h" +#include "gui.h" +#include "osd.h" /* TODO: put system specific stuff in their own files... */ -#include -#include -#include -#include +#include "nes/nes.h" +#include "nes/nesinput.h" +#include "nes/nes_pal.h" +#include "nes/nesstate.h" /* pointer to our current system's event handler table */ static event_t *system_events = NULL; diff --git a/components/nofrendo/event.h b/components/nofrendo/event.h index 929c60b..9710412 100644 --- a/components/nofrendo/event.h +++ b/components/nofrendo/event.h @@ -27,7 +27,7 @@ #ifndef _EVENT_H_ #define _EVENT_H_ -#include +#include "nofrendo.h" enum { diff --git a/components/nofrendo/gui.c b/components/nofrendo/gui.c index 6259f66..02491a0 100644 --- a/components/nofrendo/gui.c +++ b/components/nofrendo/gui.c @@ -26,19 +26,20 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "noftypes.h" +#include "nes/nes_ppu.h" +#include "sndhrdw/nes_apu.h" +#include "nes/nesinput.h" +#include "nes/nes.h" +#include "log.h" +#include "osd.h" -#include -#include -#include +#include "bitmap.h" + +#include "gui.h" +#include "gui_elem.h" +#include "vid_drv.h" /* TODO: oh god */ /* 8-bit GUI color table */ @@ -61,9 +62,9 @@ rgb_t gui_pal[GUI_TOTALCOLORS] = }; /**************************************************************/ -#include -#include -static bool option_drawsprites = true; +#include "pcx.h" +#include "nes/nesstate.h" +static nofrendo_bool option_drawsprites = nofrendo_true; /* save a PCX snapshot */ void gui_savesnap(void) @@ -83,7 +84,7 @@ void gui_savesnap(void) /* Show/hide sprites (hiding sprites useful for making maps) */ void gui_togglesprites(void) { - option_drawsprites ^= true; + option_drawsprites ^= nofrendo_true; ppu_displaysprites(option_drawsprites); gui_sendmsg(GUI_GREEN, "Sprites %s", option_drawsprites ? "displayed" : "hidden"); } @@ -93,7 +94,7 @@ void gui_togglefs(void) { nes_t *machine = nes_getcontextptr(); - machine->autoframeskip ^= true; + machine->autoframeskip ^= nofrendo_true; if (machine->autoframeskip) gui_sendmsg(GUI_YELLOW, "automatic frameskip"); else @@ -110,9 +111,9 @@ void gui_toggle_chan(int chan) { #define FILL_CHAR 0x7C /* ASCII 124 '|' */ #define BLANK_CHAR 0x7F /* ASCII 127 [delta] */ - static bool chan_enabled[6] = { true, true, true, true, true, true }; + static nofrendo_bool chan_enabled[6] = { nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true }; - chan_enabled[chan] ^= true; + chan_enabled[chan] ^= nofrendo_true; apu_setchan(chan, chan_enabled[chan]); gui_sendmsg(GUI_ORANGE, "%ca %cb %cc %cd %ce %cext", @@ -156,15 +157,15 @@ enum /* TODO: roll options into a structure */ static message_t msg; -static bool option_showfps = false; -static bool option_showgui = false; +static nofrendo_bool option_showfps = nofrendo_true; +static nofrendo_bool option_showgui = nofrendo_false; static int option_wavetype = GUI_WAVENONE; -static bool option_showpattern = false; -static bool option_showoam = false; +static nofrendo_bool option_showpattern = nofrendo_false; +static nofrendo_bool option_showoam = nofrendo_false; static int pattern_col = 0; /* timimg variables */ -static bool gui_fpsupdate = false; +static nofrendo_bool gui_fpsupdate = nofrendo_false; static int gui_ticks = 0; static int gui_fps = 0; static int gui_refresh = 60; /* default to 60Hz */ @@ -175,26 +176,26 @@ static bitmap_t *gui_surface; /* Put a pixel on our bitmap- just for GUI use */ -INLINE void gui_putpixel(int x_pos, int y_pos, uint8 color) +INLINE void gui_putpixel(int x_pos, int y_pos, uint8_t color) { gui_surface->line[y_pos][x_pos] = color; } /* Line drawing */ -static void gui_hline(int x_pos, int y_pos, int length, uint8 color) +static void gui_hline(int x_pos, int y_pos, int length, uint8_t color) { while (length--) gui_putpixel(x_pos++, y_pos, color); } -static void gui_vline(int x_pos, int y_pos, int height, uint8 color) +static void gui_vline(int x_pos, int y_pos, int height, uint8_t color) { while (height--) gui_putpixel(x_pos, y_pos++, color); } /* Rectangles */ -static void gui_rect(int x_pos, int y_pos, int width, int height, uint8 color) +static void gui_rect(int x_pos, int y_pos, int width, int height, uint8_t color) { gui_hline(x_pos, y_pos, width, color); gui_hline(x_pos, y_pos + height - 1, width, color); @@ -202,16 +203,16 @@ static void gui_rect(int x_pos, int y_pos, int width, int height, uint8 color) gui_vline(x_pos + width - 1, y_pos + 1, height - 2, color); } -static void gui_rectfill(int x_pos, int y_pos, int width, int height, uint8 color) +static void gui_rectfill(int x_pos, int y_pos, int width, int height, uint8_t color) { while (height--) gui_hline(x_pos, y_pos++, width, color); } /* Draw the outline of a button */ -static void gui_buttonrect(int x_pos, int y_pos, int width, int height, bool down) +static void gui_buttonrect(int x_pos, int y_pos, int width, int height, nofrendo_bool down) { - uint8 color1, color2; + uint8_t color1, color2; if (down) { @@ -231,7 +232,7 @@ static void gui_buttonrect(int x_pos, int y_pos, int width, int height, bool dow } /* Text blitting */ -INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8 color) +INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8_t color) { int count = 8; while (count--) @@ -242,7 +243,7 @@ INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8 color) } } -static void gui_putchar(const uint8 *dat, int height, int x_pos, int y_pos, uint8 color) +static void gui_putchar(const uint8_t *dat, int height, int x_pos, int y_pos, uint8_t color) { while (height--) gui_charline(*dat++, x_pos, y_pos++, color); @@ -261,7 +262,7 @@ static int gui_textlen(char *str, font_t *font) } /* Simple textout() type function */ -static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8 color) +static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8_t color) { int x_new; int num_chars = strlen(str); @@ -286,7 +287,7 @@ static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8 colo /* Draw bar-/button-type text */ static int gui_textbar(char *str, int x_pos, int y_pos, font_t *font, - uint8 color, uint8 bgcolor, bool buttonstate) + uint8_t color, uint8_t bgcolor, nofrendo_bool buttonstate) { int width = gui_textlen(str, &small); @@ -337,7 +338,7 @@ void gui_tick(int ticks) if (fps_counter >= gui_refresh) { fps_counter -= gui_refresh; - gui_fpsupdate = true; + gui_fpsupdate = nofrendo_true; } } @@ -379,11 +380,11 @@ static void gui_updatefps(void) static char fpsbuf[20]; /* Check to see if we need to do an sprintf or not */ - if (true == gui_fpsupdate) + if (nofrendo_true == gui_fpsupdate) { sprintf(fpsbuf, "%4d FPS /%4d%%", gui_fps, (gui_fps * 100) / gui_refresh); gui_fps = 0; - gui_fpsupdate = false; + gui_fpsupdate = nofrendo_false; } gui_textout(fpsbuf, gui_surface->width - 1 - 90, 1, &small, GUI_GREEN); @@ -392,13 +393,13 @@ static void gui_updatefps(void) /* Turn FPS on/off */ void gui_togglefps(void) { - option_showfps ^= true; + option_showfps ^= nofrendo_true; } /* Turn GUI on/off */ void gui_togglegui(void) { - option_showgui ^= true; + option_showgui ^= nofrendo_true; } void gui_togglewave(void) @@ -408,13 +409,13 @@ void gui_togglewave(void) void gui_toggleoam(void) { - option_showoam ^= true; + option_showoam ^= nofrendo_true; } /* TODO: hack! */ void gui_togglepattern(void) { - option_showpattern ^= true; + option_showpattern ^= nofrendo_true; } /* TODO: hack! */ @@ -445,7 +446,7 @@ static void gui_updatewave(int wave_type) int loop, xofs, yofs; int difference, offset; float scale; - uint8 val, oldval; + uint8_t val, oldval; int vis_length = 0; void *vis_buffer = NULL; int vis_bps; @@ -476,7 +477,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) oldval = 0x40 - (((((uint16 *) vis_buffer)[0] >> 8) ^ 0x80) >> 2); else - oldval = 0x40 - (((uint8 *) vis_buffer)[0] >> 2); + oldval = 0x40 - (((uint8_t *) vis_buffer)[0] >> 2); for (loop = 1; loop < WAVEDISP_WIDTH; loop++) { @@ -484,7 +485,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) val = 0x40 - (((((uint16 *) vis_buffer)[(uint32) (loop * scale)] >> 8) ^ 0x80) >> 2); else - val = 0x40 - (((uint8 *) vis_buffer)[(uint32) (loop * scale)] >> 2); + val = 0x40 - (((uint8_t *) vis_buffer)[(uint32) (loop * scale)] >> 2); if (oldval < val) { offset = oldval; @@ -509,7 +510,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) val = ((((uint16 *) vis_buffer)[(uint32) (loop * scale)] >> 8) ^ 0x80) >> 2; else - val = ((uint8 *) vis_buffer)[(uint32) (loop * scale)] >> 2; + val = ((uint8_t *) vis_buffer)[(uint32) (loop * scale)] >> 2; if (val == 0x20) gui_putpixel(xofs + loop, yofs + 0x20, GUI_GREEN); else if (val < 0x20) @@ -548,10 +549,10 @@ static void gui_updateoam(void) /* The GUI overlay */ -void gui_frame(bool draw) +void gui_frame(nofrendo_bool draw) { gui_fps++; - if (false == draw) + if (nofrendo_false == draw) return; gui_surface = vid_getbuffer(); diff --git a/components/nofrendo/gui.h b/components/nofrendo/gui.h index 4875e77..af40288 100644 --- a/components/nofrendo/gui.h +++ b/components/nofrendo/gui.h @@ -52,7 +52,7 @@ enum #define GUI_TOTALCOLORS (GUI_LASTENTRY - GUI_FIRSTENTRY) /* TODO: bleh */ -#include +#include "bitmap.h" extern rgb_t gui_pal[GUI_TOTALCOLORS]; #define MAX_MSG_LENGTH 256 @@ -72,7 +72,7 @@ extern void gui_sendmsg(int color, char *format, ...); extern int gui_init(void); extern void gui_shutdown(void); -extern void gui_frame(bool draw); +extern void gui_frame(nofrendo_bool draw); extern void gui_togglefps(void); extern void gui_togglegui(void); diff --git a/components/nofrendo/gui_elem.c b/components/nofrendo/gui_elem.c index 5592b6c..ad294b3 100644 --- a/components/nofrendo/gui_elem.c +++ b/components/nofrendo/gui_elem.c @@ -24,9 +24,10 @@ */ #include -#include -#include -#include + +#include "noftypes.h" +#include "gui.h" +#include "gui_elem.h" #define SMALL_FONT_KERN 6 #define SMALL_FONT_HEIGHT 6 diff --git a/components/nofrendo/intro.c b/components/nofrendo/intro.c index 73cf5a6..2d219cb 100644 --- a/components/nofrendo/intro.c +++ b/components/nofrendo/intro.c @@ -25,8 +25,9 @@ #include #include -#include -#include + +#include "noftypes.h" +#include "intro.h" #define CODE_SIZE 0x4000 #define VROM_SIZE 0x2000 @@ -326,7 +327,7 @@ static uint8 *intro_getrom(void) { uint8 *rom; - rom = malloc(CODE_SIZE); + rom = nofrendo_malloc(CODE_SIZE); if (NULL != rom) { /* good measure */ @@ -346,7 +347,7 @@ static uint8 *intro_getvrom(void) { uint8 *vrom; - vrom = malloc(VROM_SIZE); + vrom = nofrendo_malloc(VROM_SIZE); if (NULL != vrom) { memcpy(vrom, intro_vrom, sizeof(intro_vrom)); diff --git a/components/nofrendo/intro.h b/components/nofrendo/intro.h index 79575d7..5db801b 100644 --- a/components/nofrendo/intro.h +++ b/components/nofrendo/intro.h @@ -26,7 +26,7 @@ #ifndef _INTRO_H_ #define _INTRO_H_ -#include +#include "nes/nes_rom.h" extern void intro_get_header(rominfo_t *rominfo); extern int intro_get_rom(rominfo_t *rominfo); diff --git a/components/nofrendo/libsnss/libsnss.c b/components/nofrendo/libsnss/libsnss.c index f5e786c..3bf6073 100644 --- a/components/nofrendo/libsnss/libsnss.c +++ b/components/nofrendo/libsnss/libsnss.c @@ -12,7 +12,8 @@ #include #include #include -#include + +#include "libsnss.h" /**************************************************************************/ /* This section deals with endian-specific code. */ @@ -203,7 +204,7 @@ SNSS_WriteFileHeader(SNSS_FILE *snssFile) SNSS_RETURN_CODE SNSS_OpenFile(SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) { - *snssFile = malloc(sizeof(SNSS_FILE)); + *snssFile = nofrendo_malloc(sizeof(SNSS_FILE)); if (NULL == *snssFile) { return SNSS_OUT_OF_MEMORY; @@ -226,7 +227,7 @@ SNSS_OpenFile(SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) if (NULL == (*snssFile)->fp) { - free(*snssFile); + nofrendo_free(*snssFile); *snssFile = NULL; return SNSS_OPEN_FAILED; } @@ -274,7 +275,7 @@ SNSS_CloseFile(SNSS_FILE **snssFile) return SNSS_CLOSE_FAILED; } - free(*snssFile); + nofrendo_free(*snssFile); *snssFile = NULL; return SNSS_OK; @@ -583,14 +584,14 @@ SNSS_ReadMapperBlock(SNSS_FILE *snssFile) return SNSS_READ_FAILED; } - if ((blockBytes = (char *)malloc(0x8 + 0x10 + 0x80)) == NULL) + if ((blockBytes = (char *)nofrendo_malloc(0x8 + 0x10 + 0x80)) == NULL) { return SNSS_OUT_OF_MEMORY; } if (fread(blockBytes, MIN(0x8 + 0x10 + 0x80, header.blockLength), 1, snssFile->fp) != 1) { - free(blockBytes); + nofrendo_free(blockBytes); return SNSS_READ_FAILED; } @@ -608,7 +609,7 @@ SNSS_ReadMapperBlock(SNSS_FILE *snssFile) memcpy(&snssFile->mapperBlock.extraData.mapperData, &blockBytes[0x18], 0x80); - free(blockBytes); + nofrendo_free(blockBytes); return SNSS_OK; } diff --git a/components/nofrendo/libsnss/libsnss.h b/components/nofrendo/libsnss/libsnss.h index 576227c..39c3d59 100644 --- a/components/nofrendo/libsnss/libsnss.h +++ b/components/nofrendo/libsnss/libsnss.h @@ -14,6 +14,8 @@ #include +#include "../memguard.h" + /**************************************************************************/ /* endian customization */ /**************************************************************************/ diff --git a/components/nofrendo/log.c b/components/nofrendo/log.c index 77342a1..d487e57 100644 --- a/components/nofrendo/log.c +++ b/components/nofrendo/log.c @@ -26,9 +26,9 @@ #include #include #include -#include -#include +#include "noftypes.h" +#include "log.h" //static FILE *errorlog = NULL; static int (*log_func)(const char *string) = NULL; diff --git a/components/nofrendo/mappers/map000.c b/components/nofrendo/mappers/map000.c index 5e9660c..93cb177 100644 --- a/components/nofrendo/mappers/map000.c +++ b/components/nofrendo/mappers/map000.c @@ -23,8 +23,8 @@ ** $Id: map000.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" mapintf_t map0_intf = { diff --git a/components/nofrendo/mappers/map001.c b/components/nofrendo/mappers/map001.c index 6b62336..5f6c949 100644 --- a/components/nofrendo/mappers/map001.c +++ b/components/nofrendo/mappers/map001.c @@ -24,9 +24,9 @@ */ #include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* TODO: WRAM enable ala Mark Knibbs: ================================== diff --git a/components/nofrendo/mappers/map002.c b/components/nofrendo/mappers/map002.c index 7e5518a..9e49450 100644 --- a/components/nofrendo/mappers/map002.c +++ b/components/nofrendo/mappers/map002.c @@ -23,8 +23,8 @@ ** $Id: map002.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 2: UNROM */ static void map2_init() diff --git a/components/nofrendo/mappers/map003.c b/components/nofrendo/mappers/map003.c index f24f0d8..8799e57 100644 --- a/components/nofrendo/mappers/map003.c +++ b/components/nofrendo/mappers/map003.c @@ -23,8 +23,8 @@ ** $Id: map003.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 3: CNROM */ static void map3_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map004.c b/components/nofrendo/mappers/map004.c index 2505cad..3f36a13 100644 --- a/components/nofrendo/mappers/map004.c +++ b/components/nofrendo/mappers/map004.c @@ -23,15 +23,15 @@ ** $Id: map004.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" static struct { int counter, latch; - bool enabled, reset; + nofrendo_bool enabled, reset; } irq; static uint8 reg; @@ -121,18 +121,18 @@ static void map4_write(uint32 address, uint8 value) break; case 0xC001: - irq.reset = true; + irq.reset = nofrendo_true; irq.counter = irq.latch; break; case 0xE000: - irq.enabled = false; + irq.enabled = nofrendo_false; // if (irq.reset) // irq.counter = irq.latch; break; case 0xE001: - irq.enabled = true; + irq.enabled = nofrendo_true; // if (irq.reset) // irq.counter = irq.latch; break; @@ -146,7 +146,7 @@ static void map4_write(uint32 address, uint8 value) break; } - if (true == irq.reset) + if (nofrendo_true == irq.reset) irq.counter = irq.latch; } @@ -159,14 +159,14 @@ static void map4_hblank(int vblank) { if (irq.counter >= 0) { - irq.reset = false; + irq.reset = nofrendo_false; irq.counter--; if (irq.counter < 0) { if (irq.enabled) { - irq.reset = true; + irq.reset = nofrendo_true; nes_irq(); } } @@ -193,7 +193,7 @@ static void map4_setstate(SnssMapperBlock *state) static void map4_init(void) { irq.counter = irq.latch = 0; - irq.enabled = irq.reset = false; + irq.enabled = irq.reset = nofrendo_false; reg = command = 0; vrombase = 0x0000; } diff --git a/components/nofrendo/mappers/map005.c b/components/nofrendo/mappers/map005.c index 82d765d..28ea225 100644 --- a/components/nofrendo/mappers/map005.c +++ b/components/nofrendo/mappers/map005.c @@ -23,11 +23,11 @@ ** $Id: map005.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include -#include "mmc5_snd.h" +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../log.h" +#include "../sndhrdw/mmc5_snd.h" /* TODO: there's lots of info about this mapper now; ** let's implement it correctly/completely @@ -46,13 +46,13 @@ static void map5_hblank(int vblank) if (irq.counter == nes_getcontextptr()->scanline) { - if (true == irq.enabled) + if (nofrendo_true == irq.enabled) { nes_irq(); - irq.reset = true; + irq.reset = nofrendo_true; } //else - // irq.reset = false; + // irq.reset = nofrendo_false; irq.counter = irq.latch; } } @@ -191,12 +191,12 @@ static void map5_write(uint32 address, uint8 value) case 0x5203: irq.counter = value; irq.latch = value; -// irq.reset = false; +// irq.reset = nofrendo_false; break; case 0x5204: - irq.enabled = (value & 0x80) ? true : false; -// irq.reset = false; + irq.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; +// irq.reset = nofrendo_false; break; default: diff --git a/components/nofrendo/mappers/map007.c b/components/nofrendo/mappers/map007.c index b4db7df..1ac2352 100644 --- a/components/nofrendo/mappers/map007.c +++ b/components/nofrendo/mappers/map007.c @@ -23,10 +23,10 @@ ** $Id: map007.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" +#include "../log.h" /* mapper 7: AOROM */ static void map7_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map008.c b/components/nofrendo/mappers/map008.c index 30dffc0..962a5c4 100644 --- a/components/nofrendo/mappers/map008.c +++ b/components/nofrendo/mappers/map008.c @@ -23,8 +23,8 @@ ** $Id: map008.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 8: FFE F3xxx -- what the hell uses this? */ static void map8_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map009.c b/components/nofrendo/mappers/map009.c index eab131e..d89400b 100644 --- a/components/nofrendo/mappers/map009.c +++ b/components/nofrendo/mappers/map009.c @@ -24,10 +24,10 @@ */ #include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" +#include "../libsnss/libsnss.h" static uint8 latch[2]; static uint8 regs[4]; diff --git a/components/nofrendo/mappers/map010.c b/components/nofrendo/mappers/map010.c index d2b2300..6fe958c 100644 --- a/components/nofrendo/mappers/map010.c +++ b/components/nofrendo/mappers/map010.c @@ -24,10 +24,10 @@ */ #include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" +#include "../libsnss/libsnss.h" static uint8 latch[2]; static uint8 regs[4]; diff --git a/components/nofrendo/mappers/map011.c b/components/nofrendo/mappers/map011.c index fc4a2fc..7d77b31 100644 --- a/components/nofrendo/mappers/map011.c +++ b/components/nofrendo/mappers/map011.c @@ -23,8 +23,8 @@ ** $Id: map011.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 11: Color Dreams, Wisdom Tree */ static void map11_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map015.c b/components/nofrendo/mappers/map015.c index fef6f9c..1228140 100644 --- a/components/nofrendo/mappers/map015.c +++ b/components/nofrendo/mappers/map015.c @@ -23,9 +23,9 @@ ** $Id: map015.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* mapper 15: Contra 100-in-1 */ static void map15_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map016.c b/components/nofrendo/mappers/map016.c index 487c4b6..5e74f78 100644 --- a/components/nofrendo/mappers/map016.c +++ b/components/nofrendo/mappers/map016.c @@ -23,15 +23,15 @@ ** $Id: map016.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" +#include "../nes/nes.h" static struct { int counter; - bool enabled; + nofrendo_bool enabled; } irq; /* mapper 16: Bandai */ @@ -41,7 +41,7 @@ static void map16_init(void) mmc_bankrom(16, 0x8000, 0); mmc_bankrom(16, 0xC000, MMC_LASTBANK); irq.counter = 0; - irq.enabled = false; + irq.enabled = nofrendo_false; } static void map16_write(uint32 address, uint8 value) @@ -82,7 +82,7 @@ static void map16_write(uint32 address, uint8 value) break; case 0xA: - irq.enabled = (value & 1) ? true : false; + irq.enabled = (value & 1) ? nofrendo_true : nofrendo_false; break; case 0xB: diff --git a/components/nofrendo/mappers/map018.c b/components/nofrendo/mappers/map018.c index 6c878b4..b50c8a7 100644 --- a/components/nofrendo/mappers/map018.c +++ b/components/nofrendo/mappers/map018.c @@ -23,9 +23,9 @@ ** $Id: map018.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* mapper 18: Jaleco SS8806 */ #define VRC_PBANK(bank, value, high) \ @@ -119,7 +119,7 @@ static void map18_write(uint32 address, uint8 value) if(irq.counter>15) irq.counter-=16; break; case 0xF000: - if(value&0x01) irq.enabled=true; + if(value&0x01) irq.enabled=nofrendo_true; break; case 0xF001: irq.enabled=value&0x01; diff --git a/components/nofrendo/mappers/map019.c b/components/nofrendo/mappers/map019.c index 14a93b4..447f019 100644 --- a/components/nofrendo/mappers/map019.c +++ b/components/nofrendo/mappers/map019.c @@ -23,9 +23,9 @@ ** $Id: map019.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* TODO: shouldn't there be an h-blank IRQ handler??? */ @@ -62,7 +62,7 @@ static void map19_write(uint32 address, uint8 value) case 0xB: irq.counter = ((value & 0x7F) << 8) | (irq.counter & 0xFF); - irq.enabled = (value & 0x80) ? true : false; + irq.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; break; case 0x10: diff --git a/components/nofrendo/mappers/map024.c b/components/nofrendo/mappers/map024.c index d6aea3c..48492a4 100644 --- a/components/nofrendo/mappers/map024.c +++ b/components/nofrendo/mappers/map024.c @@ -23,11 +23,11 @@ ** $Id: map024.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../log.h" +#include "../sndhrdw/vrcvisnd.h" static struct { @@ -51,7 +51,7 @@ static void map24_hblank(int vblank) { irq.counter = irq.latch; nes_irq(); - //irq.enabled = false; + //irq.enabled = nofrendo_false; irq.enabled = irq.wait_state; } } diff --git a/components/nofrendo/mappers/map032.c b/components/nofrendo/mappers/map032.c index cc22acf..11ff5ce 100644 --- a/components/nofrendo/mappers/map032.c +++ b/components/nofrendo/mappers/map032.c @@ -23,9 +23,9 @@ ** $Id: map032.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" static int select_c000 = 0; diff --git a/components/nofrendo/mappers/map033.c b/components/nofrendo/mappers/map033.c index ba2a575..e089ee9 100644 --- a/components/nofrendo/mappers/map033.c +++ b/components/nofrendo/mappers/map033.c @@ -23,9 +23,9 @@ ** $Id: map033.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* mapper 33: Taito TC0190*/ static void map33_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map034.c b/components/nofrendo/mappers/map034.c index 6333e17..8116b57 100644 --- a/components/nofrendo/mappers/map034.c +++ b/components/nofrendo/mappers/map034.c @@ -23,8 +23,8 @@ ** $Id: map034.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" static void map34_init(void) { diff --git a/components/nofrendo/mappers/map040.c b/components/nofrendo/mappers/map040.c index a6fc4d6..44b23b9 100644 --- a/components/nofrendo/mappers/map040.c +++ b/components/nofrendo/mappers/map040.c @@ -23,11 +23,11 @@ ** $Id: map040.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" #define MAP40_IRQ_PERIOD (4096 / 113.666666) @@ -44,7 +44,7 @@ static void map40_init(void) mmc_bankrom(8, 0xA000, 5); mmc_bankrom(8, 0xE000, 7); - irq.enabled = false; + irq.enabled = nofrendo_false; irq.counter = (int) MAP40_IRQ_PERIOD; } @@ -58,7 +58,7 @@ static void map40_hblank(int vblank) if (0 == irq.counter) { nes_irq(); - irq.enabled = false; + irq.enabled = nofrendo_false; } } } @@ -70,12 +70,12 @@ static void map40_write(uint32 address, uint8 value) switch (range) { case 0: /* 0x8000-0x9FFF */ - irq.enabled = false; + irq.enabled = nofrendo_false; irq.counter = (int) MAP40_IRQ_PERIOD; break; case 1: /* 0xA000-0xBFFF */ - irq.enabled = true; + irq.enabled = nofrendo_true; break; case 3: /* 0xE000-0xFFFF */ diff --git a/components/nofrendo/mappers/map041.c b/components/nofrendo/mappers/map041.c index 25d44b9..2fdda79 100644 --- a/components/nofrendo/mappers/map041.c +++ b/components/nofrendo/mappers/map041.c @@ -26,11 +26,11 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" static uint8 register_low; static uint8 register_high; diff --git a/components/nofrendo/mappers/map042.c b/components/nofrendo/mappers/map042.c index a675771..dc44357 100644 --- a/components/nofrendo/mappers/map042.c +++ b/components/nofrendo/mappers/map042.c @@ -26,15 +26,15 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" static struct { - bool enabled; + nofrendo_bool enabled; uint32 counter; } irq; @@ -44,7 +44,7 @@ static struct static void map42_irq_reset (void) { /* Turn off IRQs */ - irq.enabled = false; + irq.enabled = nofrendo_false; irq.counter = 0x0000; /* Done */ @@ -114,7 +114,7 @@ static void map42_write (uint32 address, uint8 value) break; /* Register 2: IRQ */ - case 0x02: if (value & 0x02) irq.enabled = true; + case 0x02: if (value & 0x02) irq.enabled = nofrendo_true; else map42_irq_reset (); break; diff --git a/components/nofrendo/mappers/map046.c b/components/nofrendo/mappers/map046.c index 9c11dff..b07be58 100644 --- a/components/nofrendo/mappers/map046.c +++ b/components/nofrendo/mappers/map046.c @@ -26,11 +26,11 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" static uint8 prg_low_bank; static uint8 chr_low_bank; diff --git a/components/nofrendo/mappers/map050.c b/components/nofrendo/mappers/map050.c index 6cb7e03..c6b7631 100644 --- a/components/nofrendo/mappers/map050.c +++ b/components/nofrendo/mappers/map050.c @@ -26,15 +26,15 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" static struct { - bool enabled; + nofrendo_bool enabled; uint32 counter; } irq; @@ -44,7 +44,7 @@ static struct static void map50_irq_reset (void) { /* Turn off IRQs */ - irq.enabled = false; + irq.enabled = nofrendo_false; irq.counter = 0x0000; /* Done */ @@ -112,7 +112,7 @@ static void map50_write (uint32 address, uint8 value) if (address & 0x100) { /* IRQ settings */ - if (value & 0x01) irq.enabled = true; + if (value & 0x01) irq.enabled = nofrendo_true; else map50_irq_reset (); } else diff --git a/components/nofrendo/mappers/map064.c b/components/nofrendo/mappers/map064.c index 9188815..8413c29 100644 --- a/components/nofrendo/mappers/map064.c +++ b/components/nofrendo/mappers/map064.c @@ -23,15 +23,15 @@ ** $Id: map064.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../log.h" static struct { int counter, latch; - bool enabled, reset; + nofrendo_bool enabled, reset; } irq; static uint8 command = 0; @@ -42,7 +42,7 @@ static void map64_hblank(int vblank) if (vblank) return; - irq.reset = false; + irq.reset = nofrendo_false; if (ppu_enabled()) { @@ -50,10 +50,10 @@ static void map64_hblank(int vblank) { irq.counter = irq.latch; - if (true == irq.enabled) + if (nofrendo_true == irq.enabled) nes_irq(); - irq.reset = true; + irq.reset = nofrendo_true; } } } @@ -139,16 +139,16 @@ static void map64_write(uint32 address, uint8 value) case 0xC001: //irq.latch = value; - irq.reset = true; + irq.reset = nofrendo_true; break; case 0xE000: //irq.counter = irq.latch; - irq.enabled = false; + irq.enabled = nofrendo_false; break; case 0xE001: - irq.enabled = true; + irq.enabled = nofrendo_true; break; default: @@ -158,7 +158,7 @@ static void map64_write(uint32 address, uint8 value) break; } - if (true == irq.reset) + if (nofrendo_true == irq.reset) irq.counter = irq.latch; } @@ -170,7 +170,7 @@ static void map64_init(void) mmc_bankrom(8, 0xE000, MMC_LASTBANK); irq.counter = irq.latch = 0; - irq.reset = irq.enabled = false; + irq.reset = irq.enabled = nofrendo_false; } static map_memwrite map64_memwrite[] = diff --git a/components/nofrendo/mappers/map065.c b/components/nofrendo/mappers/map065.c index d9925c0..5db4b90 100644 --- a/components/nofrendo/mappers/map065.c +++ b/components/nofrendo/mappers/map065.c @@ -23,14 +23,14 @@ ** $Id: map065.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" static struct { int counter; - bool enabled; + nofrendo_bool enabled; int cycles; uint8 low, high; } irq; @@ -38,7 +38,7 @@ static struct static void map65_init(void) { irq.counter = 0; - irq.enabled = false; + irq.enabled = nofrendo_false; irq.low = irq.high = 0; irq.cycles = 0; } @@ -67,7 +67,7 @@ static void map65_write(uint32 address, uint8 value) switch (reg) { case 4: - irq.enabled = (value & 0x01) ? false : true; + irq.enabled = (value & 0x01) ? nofrendo_false : nofrendo_true; break; case 5: diff --git a/components/nofrendo/mappers/map066.c b/components/nofrendo/mappers/map066.c index f8f8ba7..54edd9c 100644 --- a/components/nofrendo/mappers/map066.c +++ b/components/nofrendo/mappers/map066.c @@ -23,8 +23,8 @@ ** $Id: map066.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 66: GNROM */ static void map66_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map070.c b/components/nofrendo/mappers/map070.c index 51c612a..0e9580c 100644 --- a/components/nofrendo/mappers/map070.c +++ b/components/nofrendo/mappers/map070.c @@ -23,9 +23,9 @@ ** $Id: map070.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* mapper 70: Arkanoid II, Kamen Rider Club, etc. */ /* ($8000-$FFFF) D6-D4 = switch $8000-$BFFF */ diff --git a/components/nofrendo/mappers/map073.c b/components/nofrendo/mappers/map073.c index 9fd53d9..48e4ebe 100644 --- a/components/nofrendo/mappers/map073.c +++ b/components/nofrendo/mappers/map073.c @@ -25,15 +25,15 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" static struct { - bool enabled; + nofrendo_bool enabled; uint32 counter; } irq; @@ -43,7 +43,7 @@ static struct static void map73_init (void) { /* Turn off IRQs */ - irq.enabled = false; + irq.enabled = nofrendo_false; irq.counter = 0x0000; /* Done */ @@ -76,7 +76,7 @@ static void map73_hblank (int vblank) nes_irq (); /* Shut off IRQ counter */ - irq.enabled = false; + irq.enabled = nofrendo_false; } } } @@ -100,8 +100,8 @@ static void map73_write (uint32 address, uint8 value) case 0xB000: irq.counter &= 0x0FFF; irq.counter |= (uint32) (value << 12); break; - case 0xC000: if (value & 0x02) irq.enabled = true; - else irq.enabled = false; + case 0xC000: if (value & 0x02) irq.enabled = nofrendo_true; + else irq.enabled = nofrendo_false; break; case 0xF000: mmc_bankrom (16, 0x8000, value); default: break; diff --git a/components/nofrendo/mappers/map075.c b/components/nofrendo/mappers/map075.c index 2e31023..21ae6ec 100644 --- a/components/nofrendo/mappers/map075.c +++ b/components/nofrendo/mappers/map075.c @@ -23,9 +23,9 @@ ** $Id: map075.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" static uint8 latch[2]; diff --git a/components/nofrendo/mappers/map078.c b/components/nofrendo/mappers/map078.c index 172d1ed..c8cf3d2 100644 --- a/components/nofrendo/mappers/map078.c +++ b/components/nofrendo/mappers/map078.c @@ -23,9 +23,9 @@ ** $Id: map078.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* mapper 78: Holy Diver, Cosmo Carrier */ /* ($8000-$FFFF) D2-D0 = switch $8000-$BFFF */ diff --git a/components/nofrendo/mappers/map079.c b/components/nofrendo/mappers/map079.c index e9a8d6a..9e972f9 100644 --- a/components/nofrendo/mappers/map079.c +++ b/components/nofrendo/mappers/map079.c @@ -23,8 +23,8 @@ ** $Id: map079.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 79: NINA-03/06 */ static void map79_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map085.c b/components/nofrendo/mappers/map085.c index 68a86e5..f8e9013 100644 --- a/components/nofrendo/mappers/map085.c +++ b/components/nofrendo/mappers/map085.c @@ -23,16 +23,16 @@ ** $Id: map085.c,v 1.3 2001/05/06 01:42:03 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../log.h" static struct { int counter, latch; int wait_state; - bool enabled; + nofrendo_bool enabled; } irq; /* mapper 85: Konami VRC7 */ @@ -119,8 +119,8 @@ static void map85_write(uint32 address, uint8 value) else { irq.wait_state = value & 0x01; - irq.enabled = (value & 0x02) ? true : false; - if (true == irq.enabled) + irq.enabled = (value & 0x02) ? nofrendo_true : nofrendo_false; + if (nofrendo_true == irq.enabled) irq.counter = irq.latch; } break; @@ -165,7 +165,7 @@ static void map85_init(void) irq.counter = irq.latch = 0; irq.wait_state = 0; - irq.enabled = false; + irq.enabled = nofrendo_false; } mapintf_t map85_intf = diff --git a/components/nofrendo/mappers/map087.c b/components/nofrendo/mappers/map087.c index 1de1a0a..5ae7c0b 100644 --- a/components/nofrendo/mappers/map087.c +++ b/components/nofrendo/mappers/map087.c @@ -25,11 +25,11 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" /******************************************/ /* Mapper #87 write handler ($6000-$7FFF) */ diff --git a/components/nofrendo/mappers/map093.c b/components/nofrendo/mappers/map093.c index 8986eca..ec9489d 100644 --- a/components/nofrendo/mappers/map093.c +++ b/components/nofrendo/mappers/map093.c @@ -23,9 +23,9 @@ ** $Id: map093.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" static void map93_write(uint32 address, uint8 value) { diff --git a/components/nofrendo/mappers/map094.c b/components/nofrendo/mappers/map094.c index b01ef6b..5081d30 100644 --- a/components/nofrendo/mappers/map094.c +++ b/components/nofrendo/mappers/map094.c @@ -23,8 +23,8 @@ ** $Id: map094.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 94: Senjou no Ookami */ static void map94_write(uint32 address, uint8 value) diff --git a/components/nofrendo/mappers/map099.c b/components/nofrendo/mappers/map099.c index 1ef5833..8aa19c9 100644 --- a/components/nofrendo/mappers/map099.c +++ b/components/nofrendo/mappers/map099.c @@ -23,9 +23,9 @@ ** $Id: map099.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" /* Switch VROM for VS games */ static void map99_vromswitch(uint8 value) diff --git a/components/nofrendo/mappers/map160.c b/components/nofrendo/mappers/map160.c index f5775d7..42b2e86 100644 --- a/components/nofrendo/mappers/map160.c +++ b/components/nofrendo/mappers/map160.c @@ -23,14 +23,14 @@ ** $Id: map160.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes_ppu.h" +#include "../nes/nes.h" static struct { - bool enabled, expired; + nofrendo_bool enabled, expired; int counter; int latch_c005, latch_c003; } irq; @@ -47,19 +47,19 @@ static void map160_write(uint32 address, uint8 value) } else if (0xC002 == address) { - irq.enabled = false; + irq.enabled = nofrendo_false; irq.latch_c005 = irq.latch_c003; } else if (0xC003 == address) { - if (false == irq.expired) + if (nofrendo_false == irq.expired) { irq.counter = value; } else { - irq.expired = false; - irq.enabled = true; + irq.expired = nofrendo_false; + irq.enabled = nofrendo_true; irq.counter = irq.latch_c005; } } @@ -82,9 +82,9 @@ static void map160_hblank(int vblank) { if (ppu_enabled() && irq.enabled) { - if (0 == irq.counter && false == irq.expired) + if (0 == irq.counter && nofrendo_false == irq.expired) { - irq.expired = true; + irq.expired = nofrendo_true; nes_irq(); } else @@ -97,8 +97,8 @@ static void map160_hblank(int vblank) static void map160_init(void) { - irq.enabled = false; - irq.expired = false; + irq.enabled = nofrendo_false; + irq.expired = nofrendo_false; irq.counter = 0; irq.latch_c003 = irq.latch_c005 = 0; } diff --git a/components/nofrendo/mappers/map229.c b/components/nofrendo/mappers/map229.c index 3f17b1b..c583aed 100644 --- a/components/nofrendo/mappers/map229.c +++ b/components/nofrendo/mappers/map229.c @@ -26,11 +26,11 @@ ** */ -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../libsnss/libsnss.h" +#include "../log.h" /************************/ /* Mapper #229: 31 in 1 */ diff --git a/components/nofrendo/mappers/map231.c b/components/nofrendo/mappers/map231.c index 9abf559..c2bf50d 100644 --- a/components/nofrendo/mappers/map231.c +++ b/components/nofrendo/mappers/map231.c @@ -23,8 +23,8 @@ ** $Id: map231.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" /* mapper 231: NINA-07, used in Wally Bear and the NO! Gang */ diff --git a/components/nofrendo/mappers/mapvrc.c b/components/nofrendo/mappers/mapvrc.c index 37c6c0c..127d9e9 100644 --- a/components/nofrendo/mappers/mapvrc.c +++ b/components/nofrendo/mappers/mapvrc.c @@ -23,10 +23,10 @@ ** $Id: mapvrc.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include -#include +#include "../noftypes.h" +#include "../nes/nes_mmc.h" +#include "../nes/nes.h" +#include "../log.h" #define VRC_VBANK(bank, value, high) \ { \ @@ -311,7 +311,7 @@ static void vrc_hblank(int vblank) { irq.counter = irq.latch; nes_irq(); - //irq.enabled = false; + //irq.enabled = nofrendo_false; irq.enabled = irq.wait_state; } } diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index df30211..576bba0 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -25,18 +25,13 @@ ** $Id: memguard.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include - -/* undefine macro definitions, so we get real calls */ -#undef malloc -#undef free -#undef strdup +#include "noftypes.h" +#include "memguard.h" #include #include -#include +#include "log.h" /* Maximum number of allocated blocks at any one time */ #define MAX_BLOCKS 4096 @@ -51,7 +46,7 @@ typedef struct memblock_s } memblock_t; /* debugging flag */ -bool mem_debug = true; +nofrendo_bool mem_debug = nofrendo_true; #ifdef NOFRENDO_DEBUG @@ -248,18 +243,19 @@ static void mem_deleteblock(void *data, char *file, int line) #ifdef NOFRENDO_DEBUG /* allocates memory and clears it */ -void *_my_malloc(int size, char *file, int line) +void *_my_nofrendo_malloc(int size, char *file, int line) { void *temp; char fail[256]; - if (NULL == mem_record && false != mem_debug) + if (NULL == mem_record && nofrendo_false != mem_debug) mem_init(); - if (false != mem_debug) + if (nofrendo_false != mem_debug) temp = mem_guardalloc(size, GUARD_LENGTH); else temp = malloc(size); + // temp = heap_caps_malloc(size, MALLOC_CAP_DEFAULT); printf("Malloc: %d at %s:%d\n", size, file, line); if (NULL == temp) @@ -269,7 +265,7 @@ void *_my_malloc(int size, char *file, int line) ASSERT_MSG(fail); } - if (false != mem_debug) + if (nofrendo_false != mem_debug) mem_addblock(temp, size, file, line); mem_blockcount++; @@ -278,7 +274,7 @@ void *_my_malloc(int size, char *file, int line) } /* free a pointer allocated with my_malloc */ -void _my_free(void **data, char *file, int line) +void _my_nofrendo_free(void **data, char *file, int line) { char fail[256]; @@ -297,7 +293,7 @@ void _my_free(void **data, char *file, int line) mem_blockcount--; /* dec our block count */ - if (false != mem_debug) + if (nofrendo_false != mem_debug) { mem_deleteblock(*data, file, line); mem_freeguardblock(*data, GUARD_LENGTH); @@ -310,14 +306,14 @@ void _my_free(void **data, char *file, int line) *data = NULL; /* NULL our source */ } -char *_my_strdup(const char *string, char *file, int line) +char *_my_nofrendo_strdup(const char *string, char *file, int line) { char *temp; if (NULL == string) return NULL; - temp = (char *) _my_malloc(strlen(string) + 1, file, line); + temp = (char *) _my_nofrendo_malloc(strlen(string) + 1, file, line); if (NULL == temp) return NULL; @@ -329,12 +325,13 @@ char *_my_strdup(const char *string, char *file, int line) #else /* !NOFRENDO_DEBUG */ /* allocates memory and clears it */ -void *_my_malloc(int size) +void *_my_nofrendo_malloc(int size) { void *temp; char fail[256]; - temp = malloc(size); + // temp = malloc(size); + temp = heap_caps_malloc(size, MALLOC_CAP_INTERNAL); if (NULL == temp) { @@ -346,7 +343,7 @@ void *_my_malloc(int size) } /* free a pointer allocated with my_malloc */ -void _my_free(void **data) +void _my_nofrendo_free(void **data) { char fail[256]; @@ -360,7 +357,7 @@ void _my_free(void **data) *data = NULL; /* NULL our source */ } -char *_my_strdup(const char *string) +char *_my_nofrendo_strdup(const char *string) { char *temp; @@ -368,7 +365,7 @@ char *_my_strdup(const char *string) return NULL; /* will ASSERT for us */ - temp = (char *) _my_malloc(strlen(string) + 1); + temp = (char *) _my_nofrendo_malloc(strlen(string) + 1); if (NULL == temp) return NULL; @@ -385,7 +382,7 @@ void mem_checkleaks(void) #ifdef NOFRENDO_DEBUG int i; - if (false == mem_debug || NULL == mem_record) + if (nofrendo_false == mem_debug || NULL == mem_record) return; if (mem_blockcount) @@ -417,7 +414,7 @@ void mem_checkblocks(void) #ifdef NOFRENDO_DEBUG int i; - if (false == mem_debug || NULL == mem_record) + if (nofrendo_false == mem_debug || NULL == mem_record) return; for (i = 0; i < MAX_BLOCKS; i++) @@ -485,7 +482,7 @@ void mem_checkblocks(void) ** block manager space itself wasn't being freed - d'oh! ** ** Revision 1.10 2000/07/06 17:15:43 matt -** false isn't NULL, Neil... =) +** nofrendo_false isn't NULL, Neil... =) ** ** Revision 1.9 2000/07/05 23:10:01 neil ** It's a shame if the memguard segfaults diff --git a/components/nofrendo/memguard.h b/components/nofrendo/memguard.h index 55b99da..e77c7c0 100644 --- a/components/nofrendo/memguard.h +++ b/components/nofrendo/memguard.h @@ -26,30 +26,28 @@ #ifndef _MEMGUARD_H_ #define _MEMGUARD_H_ -#ifdef strdup -#undef strdup -#endif +#include "noftypes.h" #ifdef NOFRENDO_DEBUG -#define malloc(s) _my_malloc((s), __FILE__, __LINE__) -#define free(d) _my_free((void **) &(d), __FILE__, __LINE__) -#define strdup(s) _my_strdup((s), __FILE__, __LINE__) +#define nofrendo_malloc(s) _my_nofrendo_malloc((s), __FILE__, __LINE__) +#define nofrendo_free(d) _my_nofrendo_free((void **) &(d), __FILE__, __LINE__) +#define nofrendo_strdup(s) _my_nofrendo_strdup((s), __FILE__, __LINE__) -extern void *_my_malloc(int size, char *file, int line); -extern void _my_free(void **data, char *file, int line); -extern char *_my_strdup(const char *string, char *file, int line); +extern void *_my_nofrendo_malloc(int size, char *file, int line); +extern void _my_nofrendo_free(void **data, char *file, int line); +extern char *_my_nofrendo_strdup(const char *string, char *file, int line); #else /* !NORFRENDO_DEBUG */ /* Non-debugging versions of calls */ -#define malloc(s) _my_malloc((s)) -#define free(d) _my_free((void **) &(d)) -#define strdup(s) _my_strdup((s)) +#define nofrendo_malloc(s) _my_nofrendo_malloc((s)) +#define nofrendo_free(d) _my_nofrendo_free((void **) &(d)) +#define nofrendo_strdup(s) _my_nofrendo_strdup((s)) -extern void *_my_malloc(int size); -extern void _my_free(void **data); -extern char *_my_strdup(const char *string); +extern void *_my_nofrendo_malloc(int size); +extern void _my_nofrendo_free(void **data); +extern char *_my_nofrendo_strdup(const char *string); #endif /* !NOFRENDO_DEBUG */ @@ -58,7 +56,7 @@ extern void mem_cleanup(void); extern void mem_checkblocks(void); extern void mem_checkleaks(void); -extern bool mem_debug; +extern nofrendo_bool mem_debug; #endif /* _MEMGUARD_H_ */ diff --git a/components/nofrendo/nes/mmclist.c b/components/nofrendo/nes/mmclist.c index c4e4557..dd9c8b2 100644 --- a/components/nofrendo/nes/mmclist.c +++ b/components/nofrendo/nes/mmclist.c @@ -23,8 +23,8 @@ ** $Id: mmclist.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include +#include "../noftypes.h" +#include "nes_mmc.h" /* mapper interfaces */ extern mapintf_t map0_intf; diff --git a/components/nofrendo/nes/mmclist.h b/components/nofrendo/nes/mmclist.h index e7fa9f7..da2ac93 100644 --- a/components/nofrendo/nes/mmclist.h +++ b/components/nofrendo/nes/mmclist.h @@ -26,7 +26,7 @@ #ifndef _MMCLIST_H_ #define _MMCLIST_H_ -#include +#include "nes_mmc.h" extern mapintf_t *mappers[]; diff --git a/components/nofrendo/nes/nes.c b/components/nofrendo/nes/nes.c index 4055d08..6839d6e 100644 --- a/components/nofrendo/nes/nes.c +++ b/components/nofrendo/nes/nes.c @@ -26,18 +26,19 @@ #include #include #include -#include -#include "nes6502.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#include "../noftypes.h" +#include "../cpu/nes6502.h" +#include "../log.h" +#include "../osd.h" +#include "../gui.h" +#include "nes.h" +#include "../sndhrdw/nes_apu.h" +#include "nes_ppu.h" +#include "nes_rom.h" +#include "nes_mmc.h" +#include "../vid_drv.h" +#include "../nofrendo.h" #define NES_CLOCK_DIVIDER 12 @@ -261,7 +262,7 @@ static uint8 nes_clearfiq(void) { if (nes.fiq_occurred) { - nes.fiq_occurred = false; + nes.fiq_occurred = nofrendo_false; return 0x40; } @@ -282,7 +283,7 @@ static void nes_checkfiq(int cycles) nes.fiq_cycles += (int) NES_FIQ_PERIOD; if (0 == (nes.fiq_state & 0xC0)) { - nes.fiq_occurred = true; + nes.fiq_occurred = nofrendo_true; nes6502_irq(); } } @@ -293,7 +294,7 @@ void nes_nmi(void) nes6502_nmi(); } -static void nes_renderframe(bool draw_flag) +static void nes_renderframe(nofrendo_bool draw_flag) { int elapsed_cycles; mapintf_t *mapintf = nes.mmc->intf; @@ -333,12 +334,12 @@ static void nes_renderframe(bool draw_flag) nes.scanline = 0; } -static void system_video(bool draw) +static void system_video(nofrendo_bool draw) { /* TODO: hack */ - if (false == draw) + if (nofrendo_false == draw) { - gui_frame(false); + gui_frame(nofrendo_false); return; } @@ -347,7 +348,7 @@ static void system_video(bool draw) // 0, 0, NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT); /* overlay our GUI on top of it */ - gui_frame(true); + gui_frame(nofrendo_true); /* blit to screen */ vid_flush(); @@ -368,7 +369,7 @@ void nes_emulate(void) nes.scanline_cycles = 0; nes.fiq_cycles = (int) NES_FIQ_PERIOD; - while (false == nes.poweroff) + while (nofrendo_false == nes.poweroff) { if (nofrendo_ticks != last_ticks) { @@ -379,24 +380,24 @@ void nes_emulate(void) last_ticks = nofrendo_ticks; } - if (true == nes.pause) + if (nofrendo_true == nes.pause) { /* TODO: dim the screen, and pause/silence the apu */ - system_video(true); + system_video(nofrendo_true); frames_to_render = 0; } else if (frames_to_render > 1) { frames_to_render--; - nes_renderframe(false); - system_video(false); + nes_renderframe(nofrendo_false); + system_video(nofrendo_false); } - else if ((1 == frames_to_render && true == nes.autoframeskip) - || false == nes.autoframeskip) + else if ((1 == frames_to_render && nofrendo_true == nes.autoframeskip) + || nofrendo_false == nes.autoframeskip) { frames_to_render = 0; - nes_renderframe(true); - system_video(true); + nes_renderframe(nofrendo_true); + system_video(nofrendo_true); } } } @@ -434,7 +435,7 @@ void nes_destroy(nes_t **machine) { if (*machine) { - rom_free(&(*machine)->rominfo); + rom_nofrendo_free(&(*machine)->rominfo); mmc_destroy(&(*machine)->mmc); ppu_destroy(&(*machine)->ppu); apu_destroy(&(*machine)->apu); @@ -442,23 +443,23 @@ void nes_destroy(nes_t **machine) if ((*machine)->cpu) { if ((*machine)->cpu->mem_page[0]) - free((*machine)->cpu->mem_page[0]); - free((*machine)->cpu); + nofrendo_free((*machine)->cpu->mem_page[0]); + nofrendo_free((*machine)->cpu); } - free(*machine); + nofrendo_free(*machine); *machine = NULL; } } void nes_poweroff(void) { - nes.poweroff = true; + nes.poweroff = nofrendo_true; } void nes_togglepause(void) { - nes.pause ^= true; + nes.pause ^= nofrendo_true; } /* insert a cart into the NES */ @@ -485,7 +486,7 @@ int nes_insertcart(const char *filename, nes_t *machine) /* if there's VRAM, let the PPU know */ if (NULL != machine->rominfo->vram) - machine->ppu->vram_present = true; + machine->ppu->vram_present = nofrendo_true; apu_setext(machine->apu, machine->mmc->intf->sound_ext); @@ -509,7 +510,7 @@ nes_t *nes_create(void) sndinfo_t osd_sound; int i; - machine = malloc(sizeof(nes_t)); + machine = nofrendo_malloc(sizeof(nes_t)); if (NULL == machine) return NULL; @@ -521,17 +522,17 @@ nes_t *nes_create(void) // if (NULL == machine->vidbuf) // goto _fail; - machine->autoframeskip = true; + machine->autoframeskip = nofrendo_true; /* cpu */ - machine->cpu = malloc(sizeof(nes6502_context)); + machine->cpu = nofrendo_malloc(sizeof(nes6502_context)); if (NULL == machine->cpu) goto _fail; memset(machine->cpu, 0, sizeof(nes6502_context)); /* allocate 2kB RAM */ - machine->cpu->mem_page[0] = malloc(NES_RAMSIZE); + machine->cpu->mem_page[0] = nofrendo_malloc(NES_RAMSIZE); if (NULL == machine->cpu->mem_page[0]) goto _fail; @@ -558,8 +559,8 @@ nes_t *nes_create(void) if (NULL == machine->ppu) goto _fail; - machine->poweroff = false; - machine->pause = false; + machine->poweroff = nofrendo_false; + machine->pause = nofrendo_false; return machine; @@ -592,7 +593,7 @@ nes_t *nes_create(void) ** scanline emulation simplifications/timing fixes ** ** Revision 1.13 2000/11/25 01:53:42 matt -** bool stinks sometimes +** nofrendo_bool stinks sometimes ** ** Revision 1.12 2000/11/21 13:28:40 matt ** take care to zero allocated mem diff --git a/components/nofrendo/nes/nes.h b/components/nofrendo/nes/nes.h index 1b080a7..5a53dff 100644 --- a/components/nofrendo/nes/nes.h +++ b/components/nofrendo/nes/nes.h @@ -26,13 +26,13 @@ #ifndef _NES_H_ #define _NES_H_ -#include -#include -#include -#include -#include -#include "nes6502.h" -#include +#include "../noftypes.h" +#include "../sndhrdw/nes_apu.h" +#include "nes_mmc.h" +#include "nes_ppu.h" +#include "nes_rom.h" +#include "../cpu/nes6502.h" +#include "../bitmap.h" /* Visible (NTSC) screen height */ #ifndef NES_VISIBLE_HEIGHT @@ -75,7 +75,7 @@ typedef struct nes_s there, saving us about 64K of memory. */ // bitmap_t *vidbuf; - bool fiq_occurred; + nofrendo_bool fiq_occurred; uint8 fiq_state; int fiq_cycles; @@ -83,11 +83,11 @@ typedef struct nes_s /* Timing stuff */ float scanline_cycles; - bool autoframeskip; + nofrendo_bool autoframeskip; /* control */ - bool poweroff; - bool pause; + nofrendo_bool poweroff; + nofrendo_bool pause; } nes_t; @@ -132,7 +132,7 @@ extern void nes_togglepause(void); ** scanline emulation simplifications/timing fixes ** ** Revision 1.6 2000/11/25 01:52:17 matt -** bool stinks sometimes +** nofrendo_bool stinks sometimes ** ** Revision 1.5 2000/11/09 14:07:28 matt ** state load fixed, state save mostly fixed diff --git a/components/nofrendo/nes/nes_mmc.c b/components/nofrendo/nes/nes_mmc.c index 12c434d..421988d 100644 --- a/components/nofrendo/nes/nes_mmc.c +++ b/components/nofrendo/nes/nes_mmc.c @@ -24,14 +24,15 @@ */ #include -#include -#include "nes6502.h" -#include -#include -#include -#include -#include -#include + +#include "../noftypes.h" +#include "../cpu/nes6502.h" +#include "nes_mmc.h" +#include "nes_ppu.h" +#include "../libsnss/libsnss.h" +#include "../log.h" +#include "mmclist.h" +#include "nes_rom.h" #define MMC_8KROM (mmc.cart->rom_banks * 2) #define MMC_16KROM (mmc.cart->rom_banks) @@ -160,18 +161,18 @@ void mmc_bankrom(int size, uint32 address, int bank) } /* Check to see if this mapper is supported */ -bool mmc_peek(int map_num) +nofrendo_bool mmc_peek(int map_num) { mapintf_t **map_ptr = mappers; while (NULL != *map_ptr) { if ((*map_ptr)->number == map_num) - return true; + return nofrendo_true; map_ptr++; } - return false; + return nofrendo_false; } static void mmc_setpages(void) @@ -224,7 +225,7 @@ void mmc_reset(void) void mmc_destroy(mmc_t **nes_mmc) { if (*nes_mmc) - free(*nes_mmc); + nofrendo_free(*nes_mmc); } mmc_t *mmc_create(rominfo_t *rominfo) @@ -238,7 +239,7 @@ mmc_t *mmc_create(rominfo_t *rominfo) return NULL; /* Should *never* happen */ } - temp = malloc(sizeof(mmc_t)); + temp = nofrendo_malloc(sizeof(mmc_t)); if (NULL == temp) return NULL; diff --git a/components/nofrendo/nes/nes_mmc.h b/components/nofrendo/nes/nes_mmc.h index a8f6a10..f30d9fc 100644 --- a/components/nofrendo/nes/nes_mmc.h +++ b/components/nofrendo/nes/nes_mmc.h @@ -26,8 +26,8 @@ #ifndef _NES_MMC_H_ #define _NES_MMC_H_ -#include -#include +#include "../libsnss/libsnss.h" +#include "../sndhrdw/nes_apu.h" #define MMC_LASTBANK -1 @@ -59,7 +59,7 @@ typedef struct mapintf_s } mapintf_t; -#include +#include "nes_rom.h" typedef struct mmc_s { mapintf_t *intf; @@ -78,7 +78,7 @@ extern void mmc_destroy(mmc_t **nes_mmc); extern void mmc_getcontext(mmc_t *dest_mmc); extern void mmc_setcontext(mmc_t *src_mmc); -extern bool mmc_peek(int map_num); +extern nofrendo_bool mmc_peek(int map_num); extern void mmc_reset(void); diff --git a/components/nofrendo/nes/nes_pal.c b/components/nofrendo/nes/nes_pal.c index 5756ba5..f5566ec 100644 --- a/components/nofrendo/nes/nes_pal.c +++ b/components/nofrendo/nes/nes_pal.c @@ -24,9 +24,9 @@ */ #include -#include -#include -#include +#include "../noftypes.h" +#include "../bitmap.h" +#include "nes_pal.h" #ifndef PI #define PI 3.1415926535897932384626433832795 @@ -67,7 +67,7 @@ rgb_t nes_palette[64]; static float hue = 334.0f; static float tint = 0.4f; -#include +#include "../gui.h" void pal_dechue(void) { diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 37dc191..9eefb8c 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -25,18 +25,19 @@ #include #include -#include -#include -#include -#include -#include "nes6502.h" -#include -#include -#include -#include -#include -#include +#include "../noftypes.h" +#include "nes_ppu.h" +#include "nes.h" +#include "../gui.h" +#include "../cpu/nes6502.h" +#include "../log.h" +#include "nes_mmc.h" + +#include "../bitmap.h" +#include "../vid_drv.h" +#include "nes_pal.h" +#include "nesinput.h" /* PPU access */ @@ -56,7 +57,7 @@ static ppu_t ppu; -void ppu_displaysprites(bool display) +void ppu_displaysprites(nofrendo_bool display) { ppu.drawsprites = display; } @@ -122,10 +123,10 @@ void ppu_getcontext(ppu_t *dest_ppu) ppu_t *ppu_create(void) { - static bool pal_generated = false; + static nofrendo_bool pal_generated = nofrendo_false; ppu_t *temp; - temp = malloc(sizeof(ppu_t)); + temp = nofrendo_malloc(sizeof(ppu_t)); if (NULL == temp) return NULL; @@ -133,14 +134,14 @@ ppu_t *ppu_create(void) temp->latchfunc = NULL; temp->vromswitch = NULL; - temp->vram_present = false; - temp->drawsprites = true; + temp->vram_present = nofrendo_false; + temp->drawsprites = nofrendo_true; /* TODO: probably a better way to do this... */ - if (false == pal_generated) + if (nofrendo_false == pal_generated) { pal_generate(); - pal_generated = true; + pal_generated = nofrendo_true; } ppu_setdefaultpal(temp); @@ -152,7 +153,7 @@ void ppu_destroy(ppu_t **src_ppu) { if (*src_ppu) { - free(*src_ppu); + nofrendo_free(*src_ppu); *src_ppu = NULL; } } @@ -228,7 +229,7 @@ void ppu_reset(int reset_type) ppu.tile_xofs = 0; ppu.latch = 0; - ppu.vram_accessible = true; + ppu.vram_accessible = nofrendo_true; } /* we render a scanline of graphics first so we know exactly @@ -237,12 +238,12 @@ void ppu_reset(int reset_type) */ static void ppu_setstrike(int x_loc) { - if (false == ppu.strikeflag) + if (nofrendo_false == ppu.strikeflag) { - ppu.strikeflag = true; + ppu.strikeflag = nofrendo_true; /* 3 pixels per cpu cycle */ - ppu.strike_cycle = nes6502_getcycles(false) + (x_loc / 3); + ppu.strike_cycle = nes6502_getcycles(nofrendo_false) + (x_loc / 3); } } @@ -355,7 +356,7 @@ uint8 ppu_read(uint32 address) if (ppu.strikeflag) { - if (nes6502_getcycles(false) >= ppu.strike_cycle) + if (nes6502_getcycles(nofrendo_false) >= ppu.strike_cycle) value |= PPU_STATF_STRIKE; } @@ -426,10 +427,10 @@ void ppu_write(uint32 address, uint8 value) case PPU_CTRL1: ppu.ctrl1 = value; - ppu.obj_on = (value & PPU_CTRL1F_OBJON) ? true : false; - ppu.bg_on = (value & PPU_CTRL1F_BGON) ? true : false; - ppu.obj_mask = (value & PPU_CTRL1F_OBJMASK) ? false : true; - ppu.bg_mask = (value & PPU_CTRL1F_BGMASK) ? false : true; + ppu.obj_on = (value & PPU_CTRL1F_OBJON) ? nofrendo_true : nofrendo_false; + ppu.bg_on = (value & PPU_CTRL1F_BGON) ? nofrendo_true : nofrendo_false; + ppu.obj_mask = (value & PPU_CTRL1F_OBJMASK) ? nofrendo_false : nofrendo_true; + ppu.bg_mask = (value & PPU_CTRL1F_BGMASK) ? nofrendo_false : nofrendo_true; break; case PPU_OAMADDR: @@ -493,7 +494,7 @@ void ppu_write(uint32 address, uint8 value) { uint32 addr = ppu.vaddr; - if (false == ppu.vram_present && addr >= 0x3000) + if (nofrendo_false == ppu.vram_present && addr >= 0x3000) ppu.vaddr -= 0x1000; PPU_MEM(addr) = value; @@ -593,7 +594,7 @@ INLINE void draw_bgtile(uint8 *surface, uint8 pat1, uint8 pat2, } INLINE int draw_oamtile(uint8 *surface, uint8 attrib, uint8 pat1, - uint8 pat2, const uint8 *col_tbl, bool check_strike) + uint8 pat2, const uint8 *col_tbl, nofrendo_bool check_strike) { int strike_pixel = -1; uint32 color = ((pat2 & 0xAA) << 8) | ((pat2 & 0x55) << 1) @@ -702,7 +703,7 @@ static void ppu_renderbg(uint8 *vidbuf) uint8 col_high, attrib, attrib_shift; /* draw a line of transparent background color if bg is disabled */ - if (false == ppu.bg_on) + if (nofrendo_false == ppu.bg_on) { memset(vidbuf, FULLBG, NES_SCREEN_WIDTH); return; @@ -792,7 +793,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) obj_t *sprite_ptr; uint8 sprite_height; - if (false == ppu.obj_on) + if (nofrendo_false == ppu.obj_on) return; /* Get our buffer pointer */ @@ -818,7 +819,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) int y_offset; uint8 tile_index, attrib, col_high; uint8 sprite_y, sprite_x; - bool check_strike; + nofrendo_bool check_strike; int strike_pixel; sprite_y = sprite_ptr->y_loc + 1; @@ -873,7 +874,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) /* if we're on sprite 0 and sprite 0 strike flag isn't set, ** check for a strike */ - check_strike = (0 == sprite_num) && (false == ppu.strikeflag); + check_strike = (0 == sprite_num) && (nofrendo_false == ppu.strikeflag); strike_pixel = draw_oamtile(bmp_ptr, attrib, data_ptr[0], data_ptr[8], ppu.palette + 16 + col_high, check_strike); if (strike_pixel >= 0) ppu_setstrike(strike_pixel); @@ -908,7 +909,7 @@ static void ppu_fakeoam(int scanline) /* we don't need to be here if strike flag is set */ - if (false == ppu.obj_on || ppu.strikeflag) + if (nofrendo_false == ppu.obj_on || ppu.strikeflag) return; sprite_height = ppu.obj_height; @@ -1004,12 +1005,12 @@ static void ppu_fakeoam(int scanline) } } -bool ppu_enabled(void) +nofrendo_bool ppu_enabled(void) { return (ppu.bg_on || ppu.obj_on); } -static void ppu_renderscanline(bitmap_t *bmp, int scanline, bool draw_flag) +static void ppu_renderscanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag) { uint8 *buf = bmp->line[scanline]; @@ -1031,7 +1032,7 @@ static void ppu_renderscanline(bitmap_t *bmp, int scanline, bool draw_flag) ppu_renderbg(buf); /* TODO: fetch obj data 1 scanline before */ - if (true == ppu.drawsprites && true == draw_flag) + if (nofrendo_true == ppu.drawsprites && nofrendo_true == draw_flag) ppu_renderoam(buf, scanline); else ppu_fakeoam(scanline); @@ -1078,7 +1079,7 @@ void ppu_checknmi(void) nes_nmi(); } -void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag) +void ppu_scanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag) { if (scanline < 240) { @@ -1089,27 +1090,27 @@ void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag) else if (241 == scanline) { ppu.stat |= PPU_STATF_VBLANK; - ppu.vram_accessible = true; + ppu.vram_accessible = nofrendo_true; } else if (261 == scanline) { ppu.stat &= ~PPU_STATF_VBLANK; - ppu.strikeflag = false; + ppu.strikeflag = nofrendo_false; ppu.strike_cycle = (uint32) -1; - ppu.vram_accessible = false; + ppu.vram_accessible = nofrendo_false; } } /* -bool ppu_checkzapperhit(bitmap_t *bmp, int x, int y) +nofrendo_bool ppu_checkzapperhit(bitmap_t *bmp, int x, int y) { uint8 pixel = bmp->line[y][x] & 0x3F; if (0x20 == pixel || 0x30 == pixel) - return true; + return nofrendo_true; - return false; + return nofrendo_false; } */ diff --git a/components/nofrendo/nes/nes_ppu.h b/components/nofrendo/nes/nes_ppu.h index ab020f3..dd824e9 100644 --- a/components/nofrendo/nes/nes_ppu.h +++ b/components/nofrendo/nes/nes_ppu.h @@ -26,7 +26,7 @@ #ifndef _NES_PPU_H_ #define _NES_PPU_H_ -#include +#include "../bitmap.h" /* PPU register defines */ #define PPU_CTRL0 0x2000 @@ -91,13 +91,13 @@ typedef struct ppu_s uint8 obj_height; uint32 obj_base, bg_base; - bool bg_on, obj_on; - bool obj_mask, bg_mask; + nofrendo_bool bg_on, obj_on; + nofrendo_bool obj_mask, bg_mask; uint8 latch, vdata_latch; uint8 strobe; - bool strikeflag; + nofrendo_bool strikeflag; uint32 strike_cycle; /* callbacks for naughty mappers */ @@ -107,10 +107,10 @@ typedef struct ppu_s /* copy of our current palette */ rgb_t curpal[256]; - bool vram_accessible; + nofrendo_bool vram_accessible; - bool vram_present; - bool drawsprites; + nofrendo_bool vram_present; + nofrendo_bool drawsprites; } ppu_t; @@ -133,8 +133,8 @@ extern uint8 *ppu_getpage(int page); /* control */ extern void ppu_reset(int reset_type); -extern bool ppu_enabled(void); -extern void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag); +extern nofrendo_bool ppu_enabled(void); +extern void ppu_scanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag); extern void ppu_endscanline(int scanline); extern void ppu_checknmi(); @@ -154,7 +154,7 @@ extern void ppu_setdefaultpal(ppu_t *src_ppu); /* bleh */ extern void ppu_dumppattern(bitmap_t *bmp, int table_num, int x_loc, int y_loc, int col); extern void ppu_dumpoam(bitmap_t *bmp, int x_loc, int y_loc); -extern void ppu_displaysprites(bool display); +extern void ppu_displaysprites(nofrendo_bool display); #endif /* _NES_PPU_H_ */ diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index 0aa838b..995a92b 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -29,20 +29,16 @@ #include #include -//Nes stuff wants to define this as well... -#undef false -#undef true -#undef bool - -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#include "../noftypes.h" +#include "nes_rom.h" +#include "../intro.h" +#include "nes_mmc.h" +#include "nes_ppu.h" +#include "nes.h" +#include "../gui.h" +#include "../log.h" +#include "../osd.h" /* Max length for displayed filename */ #define ROM_DISP_MAXLEN 20 @@ -134,7 +130,7 @@ static void rom_loadsram(rominfo_t *rominfo) static int rom_allocsram(rominfo_t *rominfo) { /* Load up SRAM */ - rominfo->sram = malloc(SRAM_BANK_LENGTH * rominfo->sram_banks); + rominfo->sram = nofrendo_malloc(SRAM_BANK_LENGTH * rominfo->sram_banks); if (NULL == rominfo->sram) { gui_sendmsg(GUI_RED, "Could not allocate space for battery RAM"); @@ -165,7 +161,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) ASSERT(rominfo); /* Allocate ROM space, and load it up! */ - // rominfo->rom = malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); + // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); rominfo->rom = heap_caps_malloc((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); if (NULL == rominfo->rom) { @@ -177,7 +173,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* If there's VROM, allocate and stuff it in */ if (rominfo->vrom_banks) { - // rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); + // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); if (NULL == rominfo->vrom) { @@ -188,7 +184,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) } else { - rominfo->vram = malloc(VRAM_LENGTH); + rominfo->vram = nofrendo_malloc(VRAM_LENGTH); if (NULL == rominfo->vram) { gui_sendmsg(GUI_RED, "Could not allocate space for VRAM"); @@ -264,7 +260,7 @@ static int rom_adddirty(char *filename) #ifdef NOFRENDO_DEBUG #define MAX_BUFFER_LENGTH 255 char buffer[MAX_BUFFER_LENGTH + 1]; - bool found = false; + bool found = nofrendo_false; FILE *fp = fopen("dirtyrom.txt", "rt"); if (NULL == fp) @@ -274,12 +270,12 @@ static int rom_adddirty(char *filename) { if (0 == strncmp(filename, buffer, strlen(filename))) { - found = true; + found = nofrendo_true; break; } } - if (false == found) + if (nofrendo_false == found) { /* close up the file, open it back up for writing */ fclose(fp); @@ -356,12 +352,12 @@ static int rom_getheader(FILE *fp, rominfo_t *rominfo) if (0 == memcmp(head.reserved, reserved, RESERVED_LENGTH)) { /* We were clean */ - header_dirty = false; + header_dirty = nofrendo_false; rominfo->mapper_number |= (head.mapper_hinybble & 0xF0); } else { - header_dirty = true; + header_dirty = nofrendo_true; /* @!?#@! DiskDude. */ if (('D' == head.mapper_hinybble) && (0 == memcmp(head.reserved, "iskDude!", 8))) @@ -430,7 +426,7 @@ rominfo_t *rom_load(const char *filename) FILE *fp; rominfo_t *rominfo; - rominfo = malloc(sizeof(rominfo_t)); + rominfo = nofrendo_malloc(sizeof(rominfo_t)); if (NULL == rominfo) return NULL; @@ -448,7 +444,7 @@ rominfo_t *rom_load(const char *filename) goto _fail; /* Make sure we really support the mapper */ - if (false == mmc_peek(rominfo->mapper_number)) + if (nofrendo_false == mmc_peek(rominfo->mapper_number)) { gui_sendmsg(GUI_RED, "Mapper %d not yet implemented", rominfo->mapper_number); goto _fail; @@ -488,12 +484,12 @@ rominfo_t *rom_load(const char *filename) _fail: if (NULL != fp) _fclose(fp); - rom_free(&rominfo); + rom_nofrendo_free(&rominfo); return NULL; } /* Free a ROM */ -void rom_free(rominfo_t **rominfo) +void rom_nofrendo_free(rominfo_t **rominfo) { if (NULL == *rominfo) { @@ -512,15 +508,15 @@ void rom_free(rominfo_t **rominfo) rom_savesram(*rominfo); if ((*rominfo)->sram) - free((*rominfo)->sram); + nofrendo_free((*rominfo)->sram); if ((*rominfo)->rom) - free((*rominfo)->rom); + nofrendo_free((*rominfo)->rom); if ((*rominfo)->vrom) - free((*rominfo)->vrom); + nofrendo_free((*rominfo)->vrom); if ((*rominfo)->vram) - free((*rominfo)->vram); + nofrendo_free((*rominfo)->vram); - free(*rominfo); + nofrendo_free(*rominfo); gui_sendmsg(GUI_GREEN, "ROM freed"); } diff --git a/components/nofrendo/nes/nes_rom.h b/components/nofrendo/nes/nes_rom.h index ba86d2f..6fdb74d 100644 --- a/components/nofrendo/nes/nes_rom.h +++ b/components/nofrendo/nes/nes_rom.h @@ -27,7 +27,8 @@ #define _NES_ROM_H_ #include -#include + +#include "../osd.h" typedef enum { @@ -63,7 +64,7 @@ typedef struct rominfo_s extern int rom_checkmagic(const char *filename); extern rominfo_t *rom_load(const char *filename); -extern void rom_free(rominfo_t **rominfo); +extern void rom_nofrendo_free(rominfo_t **rominfo); extern char *rom_getinfo(rominfo_t *rominfo); diff --git a/components/nofrendo/nes/nesinput.c b/components/nofrendo/nes/nesinput.c index d425f9c..5a55dbc 100644 --- a/components/nofrendo/nes/nesinput.c +++ b/components/nofrendo/nes/nesinput.c @@ -23,9 +23,9 @@ ** $Id: nesinput.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "nesinput.h" +#include "../log.h" /* TODO: make a linked list of inputs sources, so they ** can be removed if need be diff --git a/components/nofrendo/nes/nesstate.c b/components/nofrendo/nes/nesstate.c index c010f56..62fdf32 100644 --- a/components/nofrendo/nes/nesstate.c +++ b/components/nofrendo/nes/nesstate.c @@ -25,14 +25,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include "nes6502.h" + +#include "../noftypes.h" +#include "nesstate.h" +#include "../gui.h" +#include "nes.h" +#include "../log.h" +#include "../osd.h" +#include "../libsnss/libsnss.h" +#include "../cpu/nes6502.h" #define FIRST_STATE_SLOT 0 #define LAST_STATE_SLOT 9 @@ -90,7 +91,7 @@ static int save_baseblock(nes_t *state, SNSS_FILE *snssFile) return 0; } -static bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) +static nofrendo_bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) { ASSERT(state); @@ -112,7 +113,7 @@ static bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) { int i; - bool written = false; + nofrendo_bool written = nofrendo_false; int sram_length; ASSERT(state); @@ -124,12 +125,12 @@ static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) { if (state->rominfo->sram[i]) { - written = true; + written = nofrendo_true; break; } } - if (false == written) + if (nofrendo_false == written) return -1; if (state->rominfo->sram_banks > 8) @@ -140,8 +141,8 @@ static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) snssFile->sramBlock.sramSize = SRAM_1K * state->rominfo->sram_banks; - /* TODO: this should not always be true!! */ - snssFile->sramBlock.sramEnabled = true; + /* TODO: this should not always be nofrendo_true!! */ + snssFile->sramBlock.sramEnabled = nofrendo_true; memcpy(snssFile->sramBlock.sram, state->rominfo->sram, snssFile->sramBlock.sramSize); @@ -259,7 +260,7 @@ static void load_baseblock(nes_t *state, SNSS_FILE *snssFile) /* do some extra handling */ state->ppu->flipflop = 0; - state->ppu->strikeflag = false; + state->ppu->strikeflag = nofrendo_false; nes6502_setcontext(state->cpu); ppu_setcontext(state->ppu); diff --git a/components/nofrendo/nes/nesstate.h b/components/nofrendo/nes/nesstate.h index 387d8d7..cae51e8 100644 --- a/components/nofrendo/nes/nesstate.h +++ b/components/nofrendo/nes/nesstate.h @@ -26,7 +26,7 @@ #ifndef _NESSTATE_H_ #define _NESSTATE_H_ -#include +#include "nes.h" extern void state_setslot(int slot); extern int state_load(); diff --git a/components/nofrendo/nofconfig.h b/components/nofrendo/nofconfig.h index 1676e13..0e44904 100644 --- a/components/nofrendo/nofconfig.h +++ b/components/nofrendo/nofconfig.h @@ -5,8 +5,8 @@ ** $Id: nofconfig.h,v 1.1 2001/04/27 14:37:11 neil Exp $ */ -#ifndef _CONFIG_H_ -#define _CONFIG_H_ +#ifndef _NOFCONFIG_H_ +#define _NOFCONFIG_H_ #ifndef CONFIG_FILE #define CONFIG_FILE "nofrendo.cfg" @@ -15,15 +15,17 @@ #define FSROOT "/spiffs" #define ROM_FILE FSROOT "/rom.nes" +#include "noftypes.h" + typedef struct config_s { /* open loads from the disk the saved configuration. ** ** open must be the first config function called. ** - ** open returns true on success, false otherwise. + ** open returns nofrendo_true on success, nofrendo_false otherwise. */ - bool (*open)(void); + nofrendo_bool (*open)(void); /* close saves the current configuration to disk. ** diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index 52de685..3af685b 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -26,17 +26,18 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include + +#include "noftypes.h" +#include "nofrendo.h" +#include "event.h" +#include "nofconfig.h" +#include "log.h" +#include "osd.h" +#include "gui.h" +#include "vid_drv.h" /* emulated system includes */ -#include +#include "nes/nes.h" /* our global machine structure */ static struct @@ -51,7 +52,7 @@ static struct int refresh_rate; - bool quit; + nofrendo_bool quit; } console; /* our happy little timer ISR */ @@ -67,12 +68,12 @@ static void shutdown_everything(void) { if (console.filename) { - free(console.filename); + nofrendo_free(console.filename); console.filename = NULL; } if (console.nextfilename) { - free(console.nextfilename); + nofrendo_free(console.nextfilename); console.nextfilename = NULL; } @@ -99,7 +100,7 @@ void main_eject(void) if (NULL != console.filename) { - free(console.filename); + nofrendo_free(console.filename); console.filename = NULL; } console.type = system_unknown; @@ -108,14 +109,14 @@ void main_eject(void) /* Act on the user's quit requests */ void main_quit(void) { - console.quit = true; + console.quit = nofrendo_true; main_eject(); /* if there's a pending filename / system, clear */ if (NULL != console.nextfilename) { - free(console.nextfilename); + nofrendo_free(console.nextfilename); console.nextfilename = NULL; } console.nexttype = system_unknown; @@ -149,7 +150,7 @@ static int internal_insert(const char *filename, system_t type) if (system_autodetect == type) type = detect_systemtype(filename); - console.filename = strdup(filename); + console.filename = nofrendo_strdup(filename); console.type = type; /* set up the event system for this system type */ @@ -182,7 +183,7 @@ static int internal_insert(const char *filename, system_t type) default: log_printf("system type unknown, playing nofrendo NES intro.\n"); if (NULL != console.filename) - free(console.filename); + nofrendo_free(console.filename); /* oooh, recursion */ return internal_insert(filename, system_nes); @@ -194,7 +195,7 @@ static int internal_insert(const char *filename, system_t type) /* This tells main_loop to load this next image */ void main_insert(const char *filename, system_t type) { - console.nextfilename = strdup(filename); + console.nextfilename = nofrendo_strdup(filename); console.nexttype = type; main_eject(); @@ -208,7 +209,7 @@ int nofrendo_main(int argc, char *argv[]) console.type = system_unknown; console.nexttype = system_unknown; console.refresh_rate = 0; - console.quit = false; + console.quit = nofrendo_false; if (log_init()) return -1; @@ -240,10 +241,10 @@ int main_loop(const char *filename, system_t type) return -1; printf("vid_init done\n"); - console.nextfilename = strdup(filename); + console.nextfilename = nofrendo_strdup(filename); console.nexttype = type; - while (false == console.quit) + while (nofrendo_false == console.quit) { if (internal_insert(console.nextfilename, console.nexttype)) return 1; @@ -270,7 +271,7 @@ int main_loop(const char *filename, system_t type) ** removed fds "system" ** ** Revision 1.46 2000/11/25 01:51:53 matt -** bool stinks sometimes +** nofrendo_bool stinks sometimes ** ** Revision 1.45 2000/11/20 13:22:12 matt ** standardized timer ISR, added nofrendo_ticks diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 4ea0b2f..372986f 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -53,22 +53,22 @@ typedef unsigned int uint32; #ifndef __cplusplus typedef enum { - false = 0, - true = 1 -} bool; + nofrendo_false = 0, + nofrendo_true = 1 +} nofrendo_bool; #ifndef NULL #define NULL ((void *) 0) #endif #endif /* !__cplusplus */ -#include -#include +#include "memguard.h" +#include "log.h" #ifdef NOFRENDO_DEBUG #define ASSERT(expr) log_assert((int) (expr), __LINE__, __FILE__, NULL) -#define ASSERT_MSG(msg) log_assert(false, __LINE__, __FILE__, (msg)) +#define ASSERT_MSG(msg) log_assert(nofrendo_false, __LINE__, __FILE__, (msg)) #else /* !NOFRENDO_DEBUG */ diff --git a/components/nofrendo/osd.h b/components/nofrendo/osd.h index b30d0fc..06d2677 100644 --- a/components/nofrendo/osd.h +++ b/components/nofrendo/osd.h @@ -57,8 +57,8 @@ extern void osd_setsound(void (*playfunc)(void *buffer, int size)); #ifndef NSF_PLAYER -#include -#include +#include "noftypes.h" +#include "vid_drv.h" typedef struct vidinfo_s { diff --git a/components/nofrendo/pcx.c b/components/nofrendo/pcx.c index c723cba..7302e0a 100644 --- a/components/nofrendo/pcx.c +++ b/components/nofrendo/pcx.c @@ -25,9 +25,10 @@ #include #include -#include -#include -#include + +#include "noftypes.h" +#include "bitmap.h" +#include "pcx.h" /* Save a PCX snapshot from a given NES bitmap */ int pcx_write(char *filename, bitmap_t *bmp, rgb_t *pal) diff --git a/components/nofrendo/pcx.h b/components/nofrendo/pcx.h index 7dd9a99..8509090 100644 --- a/components/nofrendo/pcx.h +++ b/components/nofrendo/pcx.h @@ -26,8 +26,8 @@ #ifndef _PCX_H_ #define _PCX_H_ -#include -#include +#include "osd.h" +#include "bitmap.h" /* Got these out of ZSoft's document */ typedef struct pcxheader_s diff --git a/components/nofrendo/sndhrdw/fds_snd.c b/components/nofrendo/sndhrdw/fds_snd.c index 7c68574..c41327a 100644 --- a/components/nofrendo/sndhrdw/fds_snd.c +++ b/components/nofrendo/sndhrdw/fds_snd.c @@ -23,9 +23,9 @@ ** $Id: fds_snd.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "nes_apu.h" +#include "fds_snd.h" static int32 fds_incsize = 0; diff --git a/components/nofrendo/sndhrdw/fds_snd.h b/components/nofrendo/sndhrdw/fds_snd.h index eb2cf54..89250f5 100644 --- a/components/nofrendo/sndhrdw/fds_snd.h +++ b/components/nofrendo/sndhrdw/fds_snd.h @@ -26,7 +26,7 @@ #ifndef _FDS_SND_H_ #define _FDS_SND_H_ -#include +#include "nes_apu.h" extern apuext_t fds_ext; diff --git a/components/nofrendo/sndhrdw/mmc5_snd.c b/components/nofrendo/sndhrdw/mmc5_snd.c index 60e8c9b..ce0f4ae 100644 --- a/components/nofrendo/sndhrdw/mmc5_snd.c +++ b/components/nofrendo/sndhrdw/mmc5_snd.c @@ -24,9 +24,10 @@ */ #include -#include + +#include "../noftypes.h" #include "mmc5_snd.h" -#include +#include "nes_apu.h" /* TODO: encapsulate apu/mmc5 rectangle */ @@ -69,13 +70,13 @@ typedef struct mmc5rectangle_s { uint8 regs[4]; - bool enabled; + nofrendo_bool enabled; float accum; int32 freq; int32 output_vol; - bool fixed_envelope; - bool holdnote; + nofrendo_bool fixed_envelope; + nofrendo_bool holdnote; uint8 volume; int32 env_phase; @@ -90,7 +91,7 @@ typedef struct mmc5rectangle_s typedef struct mmc5dac_s { int32 output; - bool enabled; + nofrendo_bool enabled; } mmc5dac_t; @@ -121,11 +122,11 @@ static int32 mmc5_rectangle(mmc5rectangle_t *chan) APU_VOLUME_DECAY(chan->output_vol); - if (false == chan->enabled || 0 == chan->vbl_length) + if (nofrendo_false == chan->enabled || 0 == chan->vbl_length) return MMC5_RECTANGLE_OUTPUT; /* vbl length counter */ - if (false == chan->holdnote) + if (nofrendo_false == chan->holdnote) chan->vbl_length--; /* envelope decay at a rate of (env_delay + 1) / 240 secs */ @@ -235,8 +236,8 @@ static void mmc5_write(uint32 address, uint8 value) mmc5.rect[chan].volume = value & 0x0F; mmc5.rect[chan].env_delay = decay_lut[value & 0x0F]; - mmc5.rect[chan].holdnote = (value & 0x20) ? true : false; - mmc5.rect[chan].fixed_envelope = (value & 0x10) ? true : false; + mmc5.rect[chan].holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; + mmc5.rect[chan].fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; mmc5.rect[chan].duty_flip = duty_lut[value >> 6]; break; @@ -269,21 +270,21 @@ static void mmc5_write(uint32 address, uint8 value) case MMC5_SMASK: if (value & 0x01) { - mmc5.rect[0].enabled = true; + mmc5.rect[0].enabled = nofrendo_true; } else { - mmc5.rect[0].enabled = false; + mmc5.rect[0].enabled = nofrendo_false; mmc5.rect[0].vbl_length = 0; } if (value & 0x02) { - mmc5.rect[1].enabled = true; + mmc5.rect[1].enabled = nofrendo_true; } else { - mmc5.rect[1].enabled = false; + mmc5.rect[1].enabled = nofrendo_false; mmc5.rect[1].vbl_length = 0; } @@ -291,9 +292,9 @@ static void mmc5_write(uint32 address, uint8 value) case 0x5010: if (value & 0x01) - mmc5.dac.enabled = true; + mmc5.dac.enabled = nofrendo_true; else - mmc5.dac.enabled = false; + mmc5.dac.enabled = nofrendo_false; break; case 0x5011: diff --git a/components/nofrendo/sndhrdw/mmc5_snd.h b/components/nofrendo/sndhrdw/mmc5_snd.h index 996496f..938237e 100644 --- a/components/nofrendo/sndhrdw/mmc5_snd.h +++ b/components/nofrendo/sndhrdw/mmc5_snd.h @@ -26,7 +26,7 @@ #ifndef _MMC5_SND_H_ #define _MMC5_SND_H_ -#include +#include "nes_apu.h" extern apuext_t mmc5_ext; diff --git a/components/nofrendo/sndhrdw/nes_apu.c b/components/nofrendo/sndhrdw/nes_apu.c index 0fc0e8e..57bd7f2 100644 --- a/components/nofrendo/sndhrdw/nes_apu.c +++ b/components/nofrendo/sndhrdw/nes_apu.c @@ -24,11 +24,11 @@ */ #include -#include -#include -#include -#include "nes6502.h" - + +#include "../noftypes.h" +#include "../log.h" +#include "nes_apu.h" +#include "../cpu/nes6502.h" #define APU_OVERSAMPLE #define APU_VOLUME_DECAY(x) ((x) -= ((x) >> 7)) @@ -111,7 +111,7 @@ void apu_getcontext(apu_t *dest_apu) *dest_apu = apu; } -void apu_setchan(int chan, bool enabled) +void apu_setchan(int chan, nofrendo_bool enabled) { if (enabled) apu.mix_enable |= (1 << chan); @@ -186,11 +186,11 @@ static int32 apu_rectangle_##ch(void) \ \ APU_VOLUME_DECAY(apu.rectangle[ch].output_vol); \ \ - if (false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ + if (nofrendo_false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* vbl length counter */ \ - if (false == apu.rectangle[ch].holdnote) \ + if (nofrendo_false == apu.rectangle[ch].holdnote) \ apu.rectangle[ch].vbl_length--; \ \ /* envelope decay at a rate of (env_delay + 1) / 240 secs */ \ @@ -205,9 +205,9 @@ static int32 apu_rectangle_##ch(void) \ apu.rectangle[ch].env_vol++; \ } \ \ - /* TODO: find true relation of freq_limit to register values */ \ + /* TODO: find nofrendo_true relation of freq_limit to register values */ \ if (apu.rectangle[ch].freq < 8 \ - || (false == apu.rectangle[ch].sweep_inc \ + || (nofrendo_false == apu.rectangle[ch].sweep_inc \ && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ return APU_RECTANGLE_OUTPUT(ch); \ \ @@ -269,11 +269,11 @@ static int32 apu_rectangle_##ch(void) \ \ APU_VOLUME_DECAY(apu.rectangle[ch].output_vol); \ \ - if (false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ + if (nofrendo_false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* vbl length counter */ \ - if (false == apu.rectangle[ch].holdnote) \ + if (nofrendo_false == apu.rectangle[ch].holdnote) \ apu.rectangle[ch].vbl_length--; \ \ /* envelope decay at a rate of (env_delay + 1) / 240 secs */ \ @@ -288,8 +288,8 @@ static int32 apu_rectangle_##ch(void) \ apu.rectangle[ch].env_vol++; \ } \ \ - /* TODO: find true relation of freq_limit to register values */ \ - if (apu.rectangle[ch].freq < 8 || (false == apu.rectangle[ch].sweep_inc && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ + /* TODO: find nofrendo_true relation of freq_limit to register values */ \ + if (apu.rectangle[ch].freq < 8 || (nofrendo_false == apu.rectangle[ch].sweep_inc && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* frequency sweeping at a rate of (sweep_delay + 1) / 120 secs */ \ @@ -354,20 +354,20 @@ static int32 apu_triangle(void) { APU_VOLUME_DECAY(apu.triangle.output_vol); - if (false == apu.triangle.enabled || 0 == apu.triangle.vbl_length) + if (nofrendo_false == apu.triangle.enabled || 0 == apu.triangle.vbl_length) return APU_TRIANGLE_OUTPUT; if (apu.triangle.counter_started) { if (apu.triangle.linear_length > 0) apu.triangle.linear_length--; - if (apu.triangle.vbl_length && false == apu.triangle.holdnote) + if (apu.triangle.vbl_length && nofrendo_false == apu.triangle.holdnote) apu.triangle.vbl_length--; } - else if (false == apu.triangle.holdnote && apu.triangle.write_latency) + else if (nofrendo_false == apu.triangle.holdnote && apu.triangle.write_latency) { if (--apu.triangle.write_latency == 0) - apu.triangle.counter_started = true; + apu.triangle.counter_started = nofrendo_true; } if (0 == apu.triangle.linear_length || apu.triangle.freq < 4) /* inaudible */ @@ -411,11 +411,11 @@ static int32 apu_noise(void) APU_VOLUME_DECAY(apu.noise.output_vol); - if (false == apu.noise.enabled || 0 == apu.noise.vbl_length) + if (nofrendo_false == apu.noise.enabled || 0 == apu.noise.vbl_length) return APU_NOISE_OUTPUT; /* vbl length counter */ - if (false == apu.noise.holdnote) + if (nofrendo_false == apu.noise.holdnote) apu.noise.vbl_length--; /* envelope decay at a rate of (env_delay + 1) / 240 secs */ @@ -519,7 +519,7 @@ INLINE void apu_dmcreload(void) { apu.dmc.address = apu.dmc.cached_addr; apu.dmc.dma_length = apu.dmc.cached_dmalength; - apu.dmc.irq_occurred = false; + apu.dmc.irq_occurred = nofrendo_false; } /* DELTA MODULATION CHANNEL @@ -572,13 +572,13 @@ static int32 apu_dmc(void) /* check to see if we should generate an irq */ if (apu.dmc.irq_gen) { - apu.dmc.irq_occurred = true; + apu.dmc.irq_occurred = nofrendo_true; if (apu.irq_callback) apu.irq_callback(); } /* bodge for timestamp queue */ - apu.dmc.enabled = false; + apu.dmc.enabled = nofrendo_false; break; } } @@ -621,8 +621,8 @@ void apu_write(uint32 address, uint8 value) apu.rectangle[chan].regs[0] = value; apu.rectangle[chan].volume = value & 0x0F; apu.rectangle[chan].env_delay = decay_lut[value & 0x0F]; - apu.rectangle[chan].holdnote = (value & 0x20) ? true : false; - apu.rectangle[chan].fixed_envelope = (value & 0x10) ? true : false; + apu.rectangle[chan].holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; + apu.rectangle[chan].fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; apu.rectangle[chan].duty_flip = duty_flip[value >> 6]; break; @@ -630,10 +630,10 @@ void apu_write(uint32 address, uint8 value) case APU_WRB1: chan = (address & 4) >> 2; apu.rectangle[chan].regs[1] = value; - apu.rectangle[chan].sweep_on = (value & 0x80) ? true : false; + apu.rectangle[chan].sweep_on = (value & 0x80) ? nofrendo_true : nofrendo_false; apu.rectangle[chan].sweep_shifts = value & 7; apu.rectangle[chan].sweep_delay = decay_lut[(value >> 4) & 7]; - apu.rectangle[chan].sweep_inc = (value & 0x08) ? true : false; + apu.rectangle[chan].sweep_inc = (value & 0x08) ? nofrendo_true : nofrendo_false; apu.rectangle[chan].freq_limit = freq_limit[value & 7]; break; @@ -657,9 +657,9 @@ void apu_write(uint32 address, uint8 value) /* triangle */ case APU_WRC0: apu.triangle.regs[0] = value; - apu.triangle.holdnote = (value & 0x80) ? true : false; + apu.triangle.holdnote = (value & 0x80) ? nofrendo_true : nofrendo_false; - if (false == apu.triangle.counter_started && apu.triangle.vbl_length) + if (nofrendo_false == apu.triangle.counter_started && apu.triangle.vbl_length) apu.triangle.linear_length = trilength_lut[value & 0x7F]; break; @@ -687,7 +687,7 @@ void apu_write(uint32 address, uint8 value) apu.triangle.write_latency = (int) (228 / apu.cycle_rate); apu.triangle.freq = (((value & 7) << 8) + apu.triangle.regs[1]) + 1; apu.triangle.vbl_length = vbl_lut[value >> 3]; - apu.triangle.counter_started = false; + apu.triangle.counter_started = nofrendo_false; apu.triangle.linear_length = trilength_lut[apu.triangle.regs[0] & 0x7F]; break; @@ -695,8 +695,8 @@ void apu_write(uint32 address, uint8 value) case APU_WRD0: apu.noise.regs[0] = value; apu.noise.env_delay = decay_lut[value & 0x0F]; - apu.noise.holdnote = (value & 0x20) ? true : false; - apu.noise.fixed_envelope = (value & 0x10) ? true : false; + apu.noise.holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; + apu.noise.fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; apu.noise.volume = value & 0x0F; break; @@ -708,13 +708,13 @@ void apu_write(uint32 address, uint8 value) apu.noise.xor_tap = (value & 0x80) ? 0x40: 0x02; #else /* !REALTIME_NOISE */ /* detect transition from long->short sample */ - if ((value & 0x80) && false == apu.noise.short_sample) + if ((value & 0x80) && nofrendo_false == apu.noise.short_sample) { /* recalculate short noise buffer */ shift_register15(noise_short_lut, APU_NOISE_93); apu.noise.cur_pos = 0; } - apu.noise.short_sample = (value & 0x80) ? true : false; + apu.noise.short_sample = (value & 0x80) ? nofrendo_true : nofrendo_false; #endif /* !REALTIME_NOISE */ break; @@ -728,16 +728,16 @@ void apu_write(uint32 address, uint8 value) case APU_WRE0: apu.dmc.regs[0] = value; apu.dmc.freq = dmc_clocks[value & 0x0F]; - apu.dmc.looping = (value & 0x40) ? true : false; + apu.dmc.looping = (value & 0x40) ? nofrendo_true : nofrendo_false; if (value & 0x80) { - apu.dmc.irq_gen = true; + apu.dmc.irq_gen = nofrendo_true; } else { - apu.dmc.irq_gen = false; - apu.dmc.irq_occurred = false; + apu.dmc.irq_gen = nofrendo_false; + apu.dmc.irq_occurred = nofrendo_false; } break; @@ -762,42 +762,42 @@ void apu_write(uint32 address, uint8 value) case APU_SMASK: /* bodge for timestamp queue */ - apu.dmc.enabled = (value & 0x10) ? true : false; + apu.dmc.enabled = (value & 0x10) ? nofrendo_true : nofrendo_false; apu.enable_reg = value; for (chan = 0; chan < 2; chan++) { if (value & (1 << chan)) { - apu.rectangle[chan].enabled = true; + apu.rectangle[chan].enabled = nofrendo_true; } else { - apu.rectangle[chan].enabled = false; + apu.rectangle[chan].enabled = nofrendo_false; apu.rectangle[chan].vbl_length = 0; } } if (value & 0x04) { - apu.triangle.enabled = true; + apu.triangle.enabled = nofrendo_true; } else { - apu.triangle.enabled = false; + apu.triangle.enabled = nofrendo_false; apu.triangle.vbl_length = 0; apu.triangle.linear_length = 0; - apu.triangle.counter_started = false; + apu.triangle.counter_started = nofrendo_false; apu.triangle.write_latency = 0; } if (value & 0x08) { - apu.noise.enabled = true; + apu.noise.enabled = nofrendo_true; } else { - apu.noise.enabled = false; + apu.noise.enabled = nofrendo_false; apu.noise.vbl_length = 0; } @@ -811,7 +811,7 @@ void apu_write(uint32 address, uint8 value) apu.dmc.dma_length = 0; } - apu.dmc.irq_occurred = false; + apu.dmc.irq_occurred = nofrendo_false; break; /* unused, but they get hit in some mem-clear loops */ @@ -999,7 +999,7 @@ apu_t *apu_create(double base_freq, int sample_rate, int refresh_rate, int sampl apu_t *temp_apu; int channel; - temp_apu = malloc(sizeof(apu_t)); + temp_apu = nofrendo_malloc(sizeof(apu_t)); if (NULL == temp_apu) return NULL; @@ -1018,7 +1018,7 @@ apu_t *apu_create(double base_freq, int sample_rate, int refresh_rate, int sampl apu_setparams(base_freq, sample_rate, refresh_rate, sample_bits); for (channel = 0; channel < 6; channel++) - apu_setchan(channel, true); + apu_setchan(channel, nofrendo_true); apu_setfilter(APU_FILTER_WEIGHTED); @@ -1033,7 +1033,7 @@ void apu_destroy(apu_t **src_apu) { if ((*src_apu)->ext && NULL != (*src_apu)->ext->shutdown) (*src_apu)->ext->shutdown(); - free(*src_apu); + nofrendo_free(*src_apu); *src_apu = NULL; } } diff --git a/components/nofrendo/sndhrdw/nes_apu.h b/components/nofrendo/sndhrdw/nes_apu.h index 523c969..c5690ca 100644 --- a/components/nofrendo/sndhrdw/nes_apu.h +++ b/components/nofrendo/sndhrdw/nes_apu.h @@ -67,21 +67,21 @@ typedef struct rectangle_s { uint8 regs[4]; - bool enabled; + nofrendo_bool enabled; float accum; int32 freq; int32 output_vol; - bool fixed_envelope; - bool holdnote; + nofrendo_bool fixed_envelope; + nofrendo_bool holdnote; uint8 volume; int32 sweep_phase; int32 sweep_delay; - bool sweep_on; + nofrendo_bool sweep_on; uint8 sweep_shifts; uint8 sweep_length; - bool sweep_inc; + nofrendo_bool sweep_inc; /* this may not be necessary in the future */ int32 freq_limit; @@ -98,7 +98,7 @@ typedef struct triangle_s { uint8 regs[3]; - bool enabled; + nofrendo_bool enabled; float accum; int32 freq; @@ -106,8 +106,8 @@ typedef struct triangle_s uint8 adder; - bool holdnote; - bool counter_started; + nofrendo_bool holdnote; + nofrendo_bool counter_started; /* quasi-hack */ int write_latency; @@ -120,7 +120,7 @@ typedef struct noise_s { uint8 regs[3]; - bool enabled; + nofrendo_bool enabled; float accum; int32 freq; @@ -129,8 +129,8 @@ typedef struct noise_s int32 env_phase; int32 env_delay; uint8 env_vol; - bool fixed_envelope; - bool holdnote; + nofrendo_bool fixed_envelope; + nofrendo_bool holdnote; uint8 volume; @@ -139,7 +139,7 @@ typedef struct noise_s #ifdef REALTIME_NOISE uint8 xor_tap; #else - bool short_sample; + nofrendo_bool short_sample; int cur_pos; #endif /* REALTIME_NOISE */ } noise_t; @@ -149,7 +149,7 @@ typedef struct dmc_s uint8 regs[4]; /* bodge for timestamp queue */ - bool enabled; + nofrendo_bool enabled; float accum; int32 freq; @@ -161,9 +161,9 @@ typedef struct dmc_s int cached_dmalength; uint8 cur_byte; - bool looping; - bool irq_gen; - bool irq_occurred; + nofrendo_bool looping; + nofrendo_bool irq_gen; + nofrendo_bool irq_occurred; } dmc_t; @@ -245,7 +245,7 @@ extern void apu_reset(void); extern void apu_setext(apu_t *apu, apuext_t *ext); extern void apu_setfilter(int filter_type); -extern void apu_setchan(int chan, bool enabled); +extern void apu_setchan(int chan, nofrendo_bool enabled); extern uint8 apu_read(uint32 address); extern void apu_write(uint32 address, uint8 value); diff --git a/components/nofrendo/sndhrdw/vrcvisnd.c b/components/nofrendo/sndhrdw/vrcvisnd.c index d7108ef..5afdcd0 100644 --- a/components/nofrendo/sndhrdw/vrcvisnd.c +++ b/components/nofrendo/sndhrdw/vrcvisnd.c @@ -23,13 +23,13 @@ ** $Id: vrcvisnd.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include -#include -#include +#include "../noftypes.h" +#include "vrcvisnd.h" +#include "nes_apu.h" typedef struct vrcvirectangle_s { - bool enabled; + nofrendo_bool enabled; uint8 reg[3]; @@ -43,7 +43,7 @@ typedef struct vrcvirectangle_s typedef struct vrcvisawtooth_s { - bool enabled; + nofrendo_bool enabled; uint8 reg[3]; @@ -81,7 +81,7 @@ static int32 vrcvi_rectangle(vrcvirectangle_t *chan) } /* return if not enabled */ - if (false == chan->enabled) + if (nofrendo_false == chan->enabled) return 0; if (chan->adder < chan->duty_flip) @@ -113,7 +113,7 @@ static int32 vrcvi_sawtooth(vrcvisawtooth_t *chan) } /* return if not enabled */ - if (false == chan->enabled) + if (nofrendo_false == chan->enabled) return 0; return (chan->output_acc >> 3) << 9; @@ -155,7 +155,7 @@ static void vrcvi_write(uint32 address, uint8 value) case 0xA002: vrcvi.rectangle[chan].reg[2] = value; vrcvi.rectangle[chan].freq = ((value & 0x0F) << 8) + vrcvi.rectangle[chan].reg[1] + 1; - vrcvi.rectangle[chan].enabled = (value & 0x80) ? true : false; + vrcvi.rectangle[chan].enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; break; case 0xB000: @@ -171,7 +171,7 @@ static void vrcvi_write(uint32 address, uint8 value) case 0xB002: vrcvi.saw.reg[2] = value; vrcvi.saw.freq = (((value & 0x0F) << 8) + vrcvi.saw.reg[1] + 1) << 1; - vrcvi.saw.enabled = (value & 0x80) ? true : false; + vrcvi.saw.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; break; default: diff --git a/components/nofrendo/sndhrdw/vrcvisnd.h b/components/nofrendo/sndhrdw/vrcvisnd.h index f1c431a..136cbc2 100644 --- a/components/nofrendo/sndhrdw/vrcvisnd.h +++ b/components/nofrendo/sndhrdw/vrcvisnd.h @@ -26,7 +26,7 @@ #ifndef _VRCVISND_H_ #define _VRCVISND_H_ -#include +#include "nes_apu.h" extern apuext_t vrcvi_ext; diff --git a/components/nofrendo/vid_drv.c b/components/nofrendo/vid_drv.c index 4699019..13dcf4a 100644 --- a/components/nofrendo/vid_drv.c +++ b/components/nofrendo/vid_drv.c @@ -24,12 +24,13 @@ */ #include -#include -#include -#include -#include -#include -#include + +#include "noftypes.h" +#include "log.h" +#include "bitmap.h" +#include "vid_drv.h" +#include "gui.h" +#include "osd.h" /* hardware surface */ static bitmap_t *screen = NULL; @@ -297,7 +298,7 @@ INLINE int calc_dirties(rect_t *list) for (i = 0; i < iterations; i++) { - dirty = false; + dirty = nofrendo_false; j = line_offset; DUFFS_DEVICE( @@ -305,14 +306,14 @@ INLINE int calc_dirties(rect_t *list) if (vid_memcmp(back_buffer->line[j], primary_buffer->line[j], CHUNK_WIDTH)) { - dirty = true; + dirty = nofrendo_true; break; } j++; }, CHUNK_HEIGHT); - if (true == dirty) + if (nofrendo_true == dirty) { list->h = CHUNK_HEIGHT; list->w = CHUNK_WIDTH; @@ -340,9 +341,9 @@ void vid_flush(void) ASSERT(driver); - if (true == driver->invalidate) + if (nofrendo_true == driver->invalidate) { - driver->invalidate = false; + driver->invalidate = nofrendo_false; num_dirties = -1; } else diff --git a/components/nofrendo/vid_drv.h b/components/nofrendo/vid_drv.h index ef0187e..d293318 100644 --- a/components/nofrendo/vid_drv.h +++ b/components/nofrendo/vid_drv.h @@ -26,7 +26,7 @@ #ifndef _VID_DRV_H_ #define _VID_DRV_H_ -#include +#include "bitmap.h" typedef struct viddriver_s { @@ -41,7 +41,7 @@ typedef struct viddriver_s /* set up a palette */ void (*set_palette)(rgb_t *palette); /* custom bitmap clear (can be NULL) */ - void (*clear)(uint8 color); + void (*clear)(uint8_t color); /* lock surface for writing (required) */ bitmap_t *(*lock_write)(void); /* free a locked surface (can be NULL) */ @@ -50,7 +50,7 @@ typedef struct viddriver_s void (*custom_blit)(bitmap_t *primary, int num_dirties, rect_t *dirty_rects); /* immediately invalidate the buffer, i.e. full redraw */ - bool invalidate; + nofrendo_bool invalidate; } viddriver_t; /* TODO: filth */ diff --git a/main/video_audio.c b/main/video_audio.c index c8aa5bc..318c595 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -22,11 +22,6 @@ #include -//Nes stuff wants to define this as well... -#undef false -#undef true -#undef bool - #include "bitmap.h" #include "event.h" #include "noftypes.h" @@ -110,7 +105,7 @@ static void osd_stopsound(void) static int osd_init_sound(void) { #if CONFIG_SOUND_ENA - audio_frame = malloc(2 * DEFAULT_FRAGSIZE); + audio_frame = nofrendo_malloc(2 * DEFAULT_FRAGSIZE); i2s_config_t cfg = { .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, .sample_rate = DEFAULT_SAMPLERATE, @@ -120,7 +115,7 @@ static int osd_init_sound(void) .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, .dma_buf_count = 6, .dma_buf_len = 512, - .use_apll = false}; + .use_apll = nofrendo_false}; i2s_driver_install(I2S_NUM_0, &cfg, 2, &queue); i2s_set_pin(I2S_NUM_0, NULL); i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); @@ -164,7 +159,7 @@ viddriver_t sdlDriver = lock_write, /* lock_write */ free_write, /* free_write */ custom_blit, /* custom_blit */ - false /* invalidate flag */ + nofrendo_false /* invalidate flag */ }; bitmap_t *myBitmap; From 3d40dca34f869d1b91853254f128c331cbef9fff Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 21:37:08 +0800 Subject: [PATCH 43/73] print configTICK_RATE_HZ --- main/video_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/video_audio.c b/main/video_audio.c index 318c595..a0174c4 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -50,7 +50,7 @@ TimerHandle_t timer; //Seemingly, this will be called only once. Should call func with a freq of frequency, int osd_installtimer(int frequency, void *func, int funcsize, void *counter, int countersize) { - printf("Timer install, freq=%d\n", frequency); + printf("Timer install, configTICK_RATE_HZ=%d, freq=%d\n", configTICK_RATE_HZ, frequency); timer = xTimerCreate("nes", configTICK_RATE_HZ / frequency, pdTRUE, NULL, func); xTimerStart(timer, 0); return 0; From 5ebd2613da29613f99b28101e986e19d81d836e8 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 21:38:12 +0800 Subject: [PATCH 44/73] memguard use only MALLOC_CAP_INTERNAL --- components/nofrendo/memguard.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 576bba0..e868d19 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -25,12 +25,13 @@ ** $Id: memguard.c,v 1.2 2001/04/27 14:37:11 neil Exp $ */ -#include "noftypes.h" -#include "memguard.h" - #include #include +#include + +#include "noftypes.h" +#include "memguard.h" #include "log.h" /* Maximum number of allocated blocks at any one time */ @@ -122,7 +123,8 @@ static void *mem_guardalloc(int alloc_size, int guard_size) alloc_size = (alloc_size + 3) & ~3; /* allocate memory */ - orig = malloc(alloc_size + (guard_size * 2)); + // orig = malloc(alloc_size + (guard_size * 2)); + orig = heap_caps_malloc(alloc_size + (guard_size * 2), MALLOC_CAP_INTERNAL); if (NULL == orig) return NULL; @@ -185,7 +187,9 @@ static void mem_init(void) mem_blockcount = 0; - mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); + // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); + mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_INTERNAL); + ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); } @@ -254,8 +258,8 @@ void *_my_nofrendo_malloc(int size, char *file, int line) if (nofrendo_false != mem_debug) temp = mem_guardalloc(size, GUARD_LENGTH); else - temp = malloc(size); - // temp = heap_caps_malloc(size, MALLOC_CAP_DEFAULT); + // temp = malloc(size); + temp = heap_caps_malloc(size, MALLOC_CAP_INTERNAL); printf("Malloc: %d at %s:%d\n", size, file, line); if (NULL == temp) From cc1a4ee58246223d21277734af856050a1998ca5 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 21:38:41 +0800 Subject: [PATCH 45/73] only keep effective sdkconfig --- sdkconfig.defaults | 266 --------------------------------------------- 1 file changed, 266 deletions(-) diff --git a/sdkconfig.defaults b/sdkconfig.defaults index b5d8480..29f8b91 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,276 +1,10 @@ -# -# Automatically generated file; DO NOT EDIT. -# Espressif IoT Development Framework Configuration -# - -# -# SDK tool configuration -# - -# -# Application manager -# - -# -# Bootloader config -# -CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y -CONFIG_LOG_BOOTLOADER_LEVEL_INFO= -CONFIG_LOG_BOOTLOADER_LEVEL=2 - -# -# Security features -# - -# -# Serial flasher config -# -CONFIG_ESPTOOLPY_PORT="/dev/cu.SLAB_USBtoUART" -CONFIG_ESPTOOLPY_BAUD_115200B= -CONFIG_ESPTOOLPY_BAUD_921600B=y -CONFIG_ESPTOOLPY_BAUD=921600 -CONFIG_FLASHMODE_QIO=y -CONFIG_ESPTOOLPY_FLASHFREQ_80M=y -CONFIG_ESPTOOLPY_FLASHSIZE_2MB= CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -CONFIG_ESPTOOLPY_FLASHSIZE="4MB" - -# -# Nofrendo ESP32-specific configuration -# - -# -# Partition Table -# -CONFIG_PARTITION_TABLE_SINGLE_APP= CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" - -# -# Compiler options -# - -# -# Component config -# - -# -# Application Level Tracing -# - -# -# Bluetooth -# - -# -# Driver configurations -# - -# -# ADC configuration -# - -# -# SPI configuration -# - -# -# eFuse Bit Manager -# - -# -# ESP32-specific -# -CONFIG_ESP32_DEFAULT_CPU_FREQ_160= CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 CONFIG_ESP32_SPIRAM_SUPPORT=y CONFIG_SPIRAM_BOOT_INIT=y CONFIG_SPIRAM_IGNORE_NOTFOUND=y -CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 -CONFIG_MAIN_TASK_STACK_SIZE=12240 -CONFIG_TIMER_TASK_STACK_SIZE=4096 -CONFIG_INT_WDT= CONFIG_TASK_WDT= -CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1= -CONFIG_ESP32_TIME_SYSCALL_USE_NONE=y -CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0 -CONFIG_ESP32_XTAL_FREQ_40= -CONFIG_ESP32_XTAL_FREQ_AUTO=y -CONFIG_ESP32_XTAL_FREQ=0 - -# -# SPI RAM config -# -CONFIG_SPIRAM_USE_CAPS_ALLOC=y -CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y - -# -# Wi-Fi -# -CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER= -CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 -CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 - -# -# PHY -# - -# -# Power Management -# - -# -# ADC-Calibration -# - -# -# Event Loop Library -# - -# -# ESP HTTP client -# - -# -# HTTP Server -# - -# -# ESP HTTPS OTA -# - -# -# Core dump -# - -# -# Ethernet -# - -# -# FAT Filesystem support -# - -# -# Modbus configuration -# - -# -# FreeRTOS -# CONFIG_FREERTOS_HZ=1000 -CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3 -CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 - -# -# Heap memory debugging -# - -# -# libsodium -# - -# -# Log output -# - -# -# LWIP -# -CONFIG_LWIP_MAX_SOCKETS=4 -CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y - -# -# DHCP server -# - -# -# TCP -# - -# -# UDP -# -CONFIG_TCPIP_TASK_STACK_SIZE=2560 - -# -# ICMP -# - -# -# LWIP RAW API -# - -# -# mbedTLS -# -CONFIG_MBEDTLS_HARDWARE_MPI=y -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y -CONFIG_MBEDTLS_HARDWARE_SHA=y - -# -# TLS Key Exchange Methods -# - -# -# Symmetric Ciphers -# - -# -# Certificates -# - -# -# mDNS -# - -# -# ESP-MQTT Configurations -# - -# -# NVS -# - -# -# OpenSSL -# - -# -# PThreads -# -CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 - -# -# SPI Flash driver -# - -# -# SPIFFS Configuration -# - -# -# SPIFFS Cache Configuration -# - -# -# Debug Configuration -# - -# -# TCP/IP Adapter -# - -# -# Unity unit testing library -# - -# -# Virtual file system -# - -# -# Wear Levelling -# From dfe39078bb6781aa83bcaaab6778cf6ef4f4b287 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 22:18:23 +0800 Subject: [PATCH 46/73] replace nofrendo_bool with bool --- components/nofrendo/bitmap.c | 10 +-- components/nofrendo/bitmap.h | 2 +- components/nofrendo/config.c | 12 ++-- components/nofrendo/cpu/nes6502.c | 12 ++-- components/nofrendo/cpu/nes6502.h | 2 +- components/nofrendo/gui.c | 68 ++++++++++---------- components/nofrendo/gui.h | 2 +- components/nofrendo/mappers/map004.c | 16 ++--- components/nofrendo/mappers/map005.c | 12 ++-- components/nofrendo/mappers/map016.c | 6 +- components/nofrendo/mappers/map018.c | 2 +- components/nofrendo/mappers/map019.c | 2 +- components/nofrendo/mappers/map024.c | 2 +- components/nofrendo/mappers/map040.c | 8 +-- components/nofrendo/mappers/map042.c | 6 +- components/nofrendo/mappers/map050.c | 6 +- components/nofrendo/mappers/map064.c | 18 +++--- components/nofrendo/mappers/map065.c | 6 +- components/nofrendo/mappers/map073.c | 10 +-- components/nofrendo/mappers/map085.c | 8 +-- components/nofrendo/mappers/map160.c | 18 +++--- components/nofrendo/mappers/mapvrc.c | 2 +- components/nofrendo/memguard.c | 16 ++--- components/nofrendo/memguard.h | 2 +- components/nofrendo/nes/nes.c | 46 +++++++------- components/nofrendo/nes/nes.h | 10 +-- components/nofrendo/nes/nes_mmc.c | 6 +- components/nofrendo/nes/nes_mmc.h | 2 +- components/nofrendo/nes/nes_ppu.c | 64 +++++++++---------- components/nofrendo/nes/nes_ppu.h | 18 +++--- components/nofrendo/nes/nes_rom.c | 12 ++-- components/nofrendo/nes/nesstate.c | 14 ++--- components/nofrendo/nofconfig.h | 4 +- components/nofrendo/nofrendo.c | 10 +-- components/nofrendo/noftypes.h | 20 ++---- components/nofrendo/sndhrdw/mmc5_snd.c | 28 ++++----- components/nofrendo/sndhrdw/nes_apu.c | 86 +++++++++++++------------- components/nofrendo/sndhrdw/nes_apu.h | 34 +++++----- components/nofrendo/sndhrdw/vrcvisnd.c | 12 ++-- components/nofrendo/vid_drv.c | 10 +-- components/nofrendo/vid_drv.h | 4 +- main/video_audio.c | 4 +- 42 files changed, 311 insertions(+), 321 deletions(-) diff --git a/components/nofrendo/bitmap.c b/components/nofrendo/bitmap.c index 7cb6805..46f7fb9 100644 --- a/components/nofrendo/bitmap.c +++ b/components/nofrendo/bitmap.c @@ -34,7 +34,7 @@ void bmp_clear(const bitmap_t *bitmap, uint8 color) memset(bitmap->data, color, bitmap->pitch * bitmap->height); } -static bitmap_t *_make_bitmap(uint8 *data_addr, nofrendo_bool hw, int width, +static bitmap_t *_make_bitmap(uint8 *data_addr, bool hw, int width, int height, int pitch, int overdraw) { bitmap_t *bitmap; @@ -59,7 +59,7 @@ static bitmap_t *_make_bitmap(uint8 *data_addr, nofrendo_bool hw, int width, /* we want to make some 32-bit aligned adjustment ** if we haven't been given a hardware bitmap */ - if (nofrendo_false == bitmap->hardware) + if (false == bitmap->hardware) { bitmap->pitch = (bitmap->pitch + 3) & ~3; bitmap->line[0] = (uint8 *) (((uint32) bitmap->data + overdraw + 3) & ~3); @@ -86,13 +86,13 @@ bitmap_t *bmp_create(int width, int height, int overdraw) if (NULL == addr) return NULL; - return _make_bitmap(addr, nofrendo_false, width, height, width, overdraw); + return _make_bitmap(addr, false, width, height, width, overdraw); } /* allocate and initialize a hardware bitmap */ bitmap_t *bmp_createhw(uint8 *addr, int width, int height, int pitch) { - return _make_bitmap(addr, nofrendo_true, width, height, pitch, 0); /* zero overdraw */ + return _make_bitmap(addr, true, width, height, pitch, 0); /* zero overdraw */ } /* Deallocate space for a bitmap structure */ @@ -100,7 +100,7 @@ void bmp_destroy(bitmap_t **bitmap) { if (*bitmap) { - if ((*bitmap)->data && nofrendo_false == (*bitmap)->hardware) + if ((*bitmap)->data && false == (*bitmap)->hardware) nofrendo_free((*bitmap)->data); nofrendo_free(*bitmap); *bitmap = NULL; diff --git a/components/nofrendo/bitmap.h b/components/nofrendo/bitmap.h index 2a37908..4e3ce7a 100644 --- a/components/nofrendo/bitmap.h +++ b/components/nofrendo/bitmap.h @@ -43,7 +43,7 @@ typedef struct rgb_s typedef struct bitmap_s { int width, height, pitch; - nofrendo_bool hardware; /* is data a hardware region? */ + bool hardware; /* is data a hardware region? */ uint8 *data; /* protected */ uint8 *line[ZERO_LENGTH]; /* will hold line pointers */ } bitmap_t; diff --git a/components/nofrendo/config.c b/components/nofrendo/config.c index 009475a..41440b8 100644 --- a/components/nofrendo/config.c +++ b/components/nofrendo/config.c @@ -21,7 +21,7 @@ typedef struct myvar_s } myvar_t; static myvar_t *myVars = NULL; -static nofrendo_bool mySaveNeeded = nofrendo_false; +static bool mySaveNeeded = false; static void my_destroy(myvar_t **var) @@ -194,7 +194,7 @@ static int load_config(char *filename) char *line; char *group = NULL, *key = NULL, *value = NULL; - mySaveNeeded = nofrendo_true; + mySaveNeeded = true; while ((line = my_getline(config_file))) { char *s; @@ -311,14 +311,14 @@ static int save_config(char *filename) return 0; } -static nofrendo_bool open_config(void) +static bool open_config(void) { return load_config(config.filename); } static void close_config(void) { - if (nofrendo_true == mySaveNeeded) + if (true == mySaveNeeded) { save_config(config.filename); } @@ -342,7 +342,7 @@ static void write_int(const char *group, const char *key, int value) } my_insert(var); - mySaveNeeded = nofrendo_true; + mySaveNeeded = true; } /* read_int loads an integer from the configuration into "value" @@ -376,7 +376,7 @@ static void write_string(const char *group, const char *key, const char *value) } my_insert(var); - mySaveNeeded = nofrendo_true; + mySaveNeeded = true; } /* read_string copies a string from the configuration into "value" diff --git a/components/nofrendo/cpu/nes6502.c b/components/nofrendo/cpu/nes6502.c index 7d863d8..ff5fd31 100644 --- a/components/nofrendo/cpu/nes6502.c +++ b/components/nofrendo/cpu/nes6502.c @@ -243,7 +243,7 @@ ** flag variables, and mask out the irrelevant data when ** we need to check them (branches, etc). This makes the ** zero flag only really be 'set' when z_flag == 0. -** The rest of the flags are stored as nofrendo_true booleans. +** The rest of the flags are stored as true booleans. */ /* Scatter flags to separate variables */ @@ -685,7 +685,7 @@ #define JAM() \ { \ PC--; \ - cpu.jammed = nofrendo_true; \ + cpu.jammed = true; \ cpu.int_pending = 0; \ ADD_CYCLES(2); \ } @@ -1302,7 +1302,7 @@ uint8 nes6502_getbyte(uint32 address) } /* get number of elapsed cycles */ -uint32 nes6502_getcycles(nofrendo_bool reset_flag) +uint32 nes6502_getcycles(bool reset_flag) { uint32 cycles = cpu.total_cycles; @@ -2410,7 +2410,7 @@ void nes6502_reset(void) cpu.int_latency = 0; /* No latent interrupts */ cpu.pc_reg = bank_readword(RESET_VECTOR); /* Fetch reset vector */ cpu.burn_cycles = RESET_CYCLES; - cpu.jammed = nofrendo_false; + cpu.jammed = false; } /* following macro is used for below 2 functions */ @@ -2425,7 +2425,7 @@ void nes6502_nmi(void) { DECLARE_LOCAL_REGS - if (nofrendo_false == cpu.jammed) + if (false == cpu.jammed) { GET_GLOBAL_REGS(); NMI_PROC(); @@ -2439,7 +2439,7 @@ void nes6502_irq(void) { DECLARE_LOCAL_REGS - if (nofrendo_false == cpu.jammed) + if (false == cpu.jammed) { GET_GLOBAL_REGS(); if (0 == i_flag) diff --git a/components/nofrendo/cpu/nes6502.h b/components/nofrendo/cpu/nes6502.h index 5d87b56..a11fa89 100644 --- a/components/nofrendo/cpu/nes6502.h +++ b/components/nofrendo/cpu/nes6502.h @@ -105,7 +105,7 @@ extern int nes6502_execute(int total_cycles); extern void nes6502_nmi(void); extern void nes6502_irq(void); extern uint8 nes6502_getbyte(uint32 address); -extern uint32 nes6502_getcycles(nofrendo_bool reset_flag); +extern uint32 nes6502_getcycles(bool reset_flag); extern void nes6502_burn(int cycles); extern void nes6502_release(void); diff --git a/components/nofrendo/gui.c b/components/nofrendo/gui.c index 02491a0..0ee454f 100644 --- a/components/nofrendo/gui.c +++ b/components/nofrendo/gui.c @@ -64,7 +64,7 @@ rgb_t gui_pal[GUI_TOTALCOLORS] = /**************************************************************/ #include "pcx.h" #include "nes/nesstate.h" -static nofrendo_bool option_drawsprites = nofrendo_true; +static bool option_drawsprites = true; /* save a PCX snapshot */ void gui_savesnap(void) @@ -84,7 +84,7 @@ void gui_savesnap(void) /* Show/hide sprites (hiding sprites useful for making maps) */ void gui_togglesprites(void) { - option_drawsprites ^= nofrendo_true; + option_drawsprites ^= true; ppu_displaysprites(option_drawsprites); gui_sendmsg(GUI_GREEN, "Sprites %s", option_drawsprites ? "displayed" : "hidden"); } @@ -94,7 +94,7 @@ void gui_togglefs(void) { nes_t *machine = nes_getcontextptr(); - machine->autoframeskip ^= nofrendo_true; + machine->autoframeskip ^= true; if (machine->autoframeskip) gui_sendmsg(GUI_YELLOW, "automatic frameskip"); else @@ -111,9 +111,9 @@ void gui_toggle_chan(int chan) { #define FILL_CHAR 0x7C /* ASCII 124 '|' */ #define BLANK_CHAR 0x7F /* ASCII 127 [delta] */ - static nofrendo_bool chan_enabled[6] = { nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true, nofrendo_true }; + static bool chan_enabled[6] = { true, true, true, true, true, true }; - chan_enabled[chan] ^= nofrendo_true; + chan_enabled[chan] ^= true; apu_setchan(chan, chan_enabled[chan]); gui_sendmsg(GUI_ORANGE, "%ca %cb %cc %cd %ce %cext", @@ -157,15 +157,15 @@ enum /* TODO: roll options into a structure */ static message_t msg; -static nofrendo_bool option_showfps = nofrendo_true; -static nofrendo_bool option_showgui = nofrendo_false; +static bool option_showfps = false; +static bool option_showgui = false; static int option_wavetype = GUI_WAVENONE; -static nofrendo_bool option_showpattern = nofrendo_false; -static nofrendo_bool option_showoam = nofrendo_false; +static bool option_showpattern = false; +static bool option_showoam = false; static int pattern_col = 0; /* timimg variables */ -static nofrendo_bool gui_fpsupdate = nofrendo_false; +static bool gui_fpsupdate = false; static int gui_ticks = 0; static int gui_fps = 0; static int gui_refresh = 60; /* default to 60Hz */ @@ -176,26 +176,26 @@ static bitmap_t *gui_surface; /* Put a pixel on our bitmap- just for GUI use */ -INLINE void gui_putpixel(int x_pos, int y_pos, uint8_t color) +INLINE void gui_putpixel(int x_pos, int y_pos, uint8 color) { gui_surface->line[y_pos][x_pos] = color; } /* Line drawing */ -static void gui_hline(int x_pos, int y_pos, int length, uint8_t color) +static void gui_hline(int x_pos, int y_pos, int length, uint8 color) { while (length--) gui_putpixel(x_pos++, y_pos, color); } -static void gui_vline(int x_pos, int y_pos, int height, uint8_t color) +static void gui_vline(int x_pos, int y_pos, int height, uint8 color) { while (height--) gui_putpixel(x_pos, y_pos++, color); } /* Rectangles */ -static void gui_rect(int x_pos, int y_pos, int width, int height, uint8_t color) +static void gui_rect(int x_pos, int y_pos, int width, int height, uint8 color) { gui_hline(x_pos, y_pos, width, color); gui_hline(x_pos, y_pos + height - 1, width, color); @@ -203,16 +203,16 @@ static void gui_rect(int x_pos, int y_pos, int width, int height, uint8_t color) gui_vline(x_pos + width - 1, y_pos + 1, height - 2, color); } -static void gui_rectfill(int x_pos, int y_pos, int width, int height, uint8_t color) +static void gui_rectfill(int x_pos, int y_pos, int width, int height, uint8 color) { while (height--) gui_hline(x_pos, y_pos++, width, color); } /* Draw the outline of a button */ -static void gui_buttonrect(int x_pos, int y_pos, int width, int height, nofrendo_bool down) +static void gui_buttonrect(int x_pos, int y_pos, int width, int height, bool down) { - uint8_t color1, color2; + uint8 color1, color2; if (down) { @@ -232,7 +232,7 @@ static void gui_buttonrect(int x_pos, int y_pos, int width, int height, nofrendo } /* Text blitting */ -INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8_t color) +INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8 color) { int count = 8; while (count--) @@ -243,7 +243,7 @@ INLINE void gui_charline(char ch, int x_pos, int y_pos, uint8_t color) } } -static void gui_putchar(const uint8_t *dat, int height, int x_pos, int y_pos, uint8_t color) +static void gui_putchar(const uint8 *dat, int height, int x_pos, int y_pos, uint8 color) { while (height--) gui_charline(*dat++, x_pos, y_pos++, color); @@ -262,7 +262,7 @@ static int gui_textlen(char *str, font_t *font) } /* Simple textout() type function */ -static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8_t color) +static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8 color) { int x_new; int num_chars = strlen(str); @@ -287,7 +287,7 @@ static int gui_textout(char *str, int x_pos, int y_pos, font_t *font, uint8_t co /* Draw bar-/button-type text */ static int gui_textbar(char *str, int x_pos, int y_pos, font_t *font, - uint8_t color, uint8_t bgcolor, nofrendo_bool buttonstate) + uint8 color, uint8 bgcolor, bool buttonstate) { int width = gui_textlen(str, &small); @@ -338,7 +338,7 @@ void gui_tick(int ticks) if (fps_counter >= gui_refresh) { fps_counter -= gui_refresh; - gui_fpsupdate = nofrendo_true; + gui_fpsupdate = true; } } @@ -380,11 +380,11 @@ static void gui_updatefps(void) static char fpsbuf[20]; /* Check to see if we need to do an sprintf or not */ - if (nofrendo_true == gui_fpsupdate) + if (true == gui_fpsupdate) { sprintf(fpsbuf, "%4d FPS /%4d%%", gui_fps, (gui_fps * 100) / gui_refresh); gui_fps = 0; - gui_fpsupdate = nofrendo_false; + gui_fpsupdate = false; } gui_textout(fpsbuf, gui_surface->width - 1 - 90, 1, &small, GUI_GREEN); @@ -393,13 +393,13 @@ static void gui_updatefps(void) /* Turn FPS on/off */ void gui_togglefps(void) { - option_showfps ^= nofrendo_true; + option_showfps ^= true; } /* Turn GUI on/off */ void gui_togglegui(void) { - option_showgui ^= nofrendo_true; + option_showgui ^= true; } void gui_togglewave(void) @@ -409,13 +409,13 @@ void gui_togglewave(void) void gui_toggleoam(void) { - option_showoam ^= nofrendo_true; + option_showoam ^= true; } /* TODO: hack! */ void gui_togglepattern(void) { - option_showpattern ^= nofrendo_true; + option_showpattern ^= true; } /* TODO: hack! */ @@ -446,7 +446,7 @@ static void gui_updatewave(int wave_type) int loop, xofs, yofs; int difference, offset; float scale; - uint8_t val, oldval; + uint8 val, oldval; int vis_length = 0; void *vis_buffer = NULL; int vis_bps; @@ -477,7 +477,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) oldval = 0x40 - (((((uint16 *) vis_buffer)[0] >> 8) ^ 0x80) >> 2); else - oldval = 0x40 - (((uint8_t *) vis_buffer)[0] >> 2); + oldval = 0x40 - (((uint8 *) vis_buffer)[0] >> 2); for (loop = 1; loop < WAVEDISP_WIDTH; loop++) { @@ -485,7 +485,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) val = 0x40 - (((((uint16 *) vis_buffer)[(uint32) (loop * scale)] >> 8) ^ 0x80) >> 2); else - val = 0x40 - (((uint8_t *) vis_buffer)[(uint32) (loop * scale)] >> 2); + val = 0x40 - (((uint8 *) vis_buffer)[(uint32) (loop * scale)] >> 2); if (oldval < val) { offset = oldval; @@ -510,7 +510,7 @@ static void gui_updatewave(int wave_type) if (16 == vis_bps) val = ((((uint16 *) vis_buffer)[(uint32) (loop * scale)] >> 8) ^ 0x80) >> 2; else - val = ((uint8_t *) vis_buffer)[(uint32) (loop * scale)] >> 2; + val = ((uint8 *) vis_buffer)[(uint32) (loop * scale)] >> 2; if (val == 0x20) gui_putpixel(xofs + loop, yofs + 0x20, GUI_GREEN); else if (val < 0x20) @@ -549,10 +549,10 @@ static void gui_updateoam(void) /* The GUI overlay */ -void gui_frame(nofrendo_bool draw) +void gui_frame(bool draw) { gui_fps++; - if (nofrendo_false == draw) + if (false == draw) return; gui_surface = vid_getbuffer(); diff --git a/components/nofrendo/gui.h b/components/nofrendo/gui.h index af40288..c8c1e5a 100644 --- a/components/nofrendo/gui.h +++ b/components/nofrendo/gui.h @@ -72,7 +72,7 @@ extern void gui_sendmsg(int color, char *format, ...); extern int gui_init(void); extern void gui_shutdown(void); -extern void gui_frame(nofrendo_bool draw); +extern void gui_frame(bool draw); extern void gui_togglefps(void); extern void gui_togglegui(void); diff --git a/components/nofrendo/mappers/map004.c b/components/nofrendo/mappers/map004.c index 3f36a13..dac567d 100644 --- a/components/nofrendo/mappers/map004.c +++ b/components/nofrendo/mappers/map004.c @@ -31,7 +31,7 @@ static struct { int counter, latch; - nofrendo_bool enabled, reset; + bool enabled, reset; } irq; static uint8 reg; @@ -121,18 +121,18 @@ static void map4_write(uint32 address, uint8 value) break; case 0xC001: - irq.reset = nofrendo_true; + irq.reset = true; irq.counter = irq.latch; break; case 0xE000: - irq.enabled = nofrendo_false; + irq.enabled = false; // if (irq.reset) // irq.counter = irq.latch; break; case 0xE001: - irq.enabled = nofrendo_true; + irq.enabled = true; // if (irq.reset) // irq.counter = irq.latch; break; @@ -146,7 +146,7 @@ static void map4_write(uint32 address, uint8 value) break; } - if (nofrendo_true == irq.reset) + if (true == irq.reset) irq.counter = irq.latch; } @@ -159,14 +159,14 @@ static void map4_hblank(int vblank) { if (irq.counter >= 0) { - irq.reset = nofrendo_false; + irq.reset = false; irq.counter--; if (irq.counter < 0) { if (irq.enabled) { - irq.reset = nofrendo_true; + irq.reset = true; nes_irq(); } } @@ -193,7 +193,7 @@ static void map4_setstate(SnssMapperBlock *state) static void map4_init(void) { irq.counter = irq.latch = 0; - irq.enabled = irq.reset = nofrendo_false; + irq.enabled = irq.reset = false; reg = command = 0; vrombase = 0x0000; } diff --git a/components/nofrendo/mappers/map005.c b/components/nofrendo/mappers/map005.c index 28ea225..4497224 100644 --- a/components/nofrendo/mappers/map005.c +++ b/components/nofrendo/mappers/map005.c @@ -46,13 +46,13 @@ static void map5_hblank(int vblank) if (irq.counter == nes_getcontextptr()->scanline) { - if (nofrendo_true == irq.enabled) + if (true == irq.enabled) { nes_irq(); - irq.reset = nofrendo_true; + irq.reset = true; } //else - // irq.reset = nofrendo_false; + // irq.reset = false; irq.counter = irq.latch; } } @@ -191,12 +191,12 @@ static void map5_write(uint32 address, uint8 value) case 0x5203: irq.counter = value; irq.latch = value; -// irq.reset = nofrendo_false; +// irq.reset = false; break; case 0x5204: - irq.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; -// irq.reset = nofrendo_false; + irq.enabled = (value & 0x80) ? true : false; +// irq.reset = false; break; default: diff --git a/components/nofrendo/mappers/map016.c b/components/nofrendo/mappers/map016.c index 5e74f78..0439654 100644 --- a/components/nofrendo/mappers/map016.c +++ b/components/nofrendo/mappers/map016.c @@ -31,7 +31,7 @@ static struct { int counter; - nofrendo_bool enabled; + bool enabled; } irq; /* mapper 16: Bandai */ @@ -41,7 +41,7 @@ static void map16_init(void) mmc_bankrom(16, 0x8000, 0); mmc_bankrom(16, 0xC000, MMC_LASTBANK); irq.counter = 0; - irq.enabled = nofrendo_false; + irq.enabled = false; } static void map16_write(uint32 address, uint8 value) @@ -82,7 +82,7 @@ static void map16_write(uint32 address, uint8 value) break; case 0xA: - irq.enabled = (value & 1) ? nofrendo_true : nofrendo_false; + irq.enabled = (value & 1) ? true : false; break; case 0xB: diff --git a/components/nofrendo/mappers/map018.c b/components/nofrendo/mappers/map018.c index b50c8a7..defdcd5 100644 --- a/components/nofrendo/mappers/map018.c +++ b/components/nofrendo/mappers/map018.c @@ -119,7 +119,7 @@ static void map18_write(uint32 address, uint8 value) if(irq.counter>15) irq.counter-=16; break; case 0xF000: - if(value&0x01) irq.enabled=nofrendo_true; + if(value&0x01) irq.enabled=true; break; case 0xF001: irq.enabled=value&0x01; diff --git a/components/nofrendo/mappers/map019.c b/components/nofrendo/mappers/map019.c index 447f019..a031675 100644 --- a/components/nofrendo/mappers/map019.c +++ b/components/nofrendo/mappers/map019.c @@ -62,7 +62,7 @@ static void map19_write(uint32 address, uint8 value) case 0xB: irq.counter = ((value & 0x7F) << 8) | (irq.counter & 0xFF); - irq.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; + irq.enabled = (value & 0x80) ? true : false; break; case 0x10: diff --git a/components/nofrendo/mappers/map024.c b/components/nofrendo/mappers/map024.c index 48492a4..d5916ed 100644 --- a/components/nofrendo/mappers/map024.c +++ b/components/nofrendo/mappers/map024.c @@ -51,7 +51,7 @@ static void map24_hblank(int vblank) { irq.counter = irq.latch; nes_irq(); - //irq.enabled = nofrendo_false; + //irq.enabled = false; irq.enabled = irq.wait_state; } } diff --git a/components/nofrendo/mappers/map040.c b/components/nofrendo/mappers/map040.c index 44b23b9..bd002d5 100644 --- a/components/nofrendo/mappers/map040.c +++ b/components/nofrendo/mappers/map040.c @@ -44,7 +44,7 @@ static void map40_init(void) mmc_bankrom(8, 0xA000, 5); mmc_bankrom(8, 0xE000, 7); - irq.enabled = nofrendo_false; + irq.enabled = false; irq.counter = (int) MAP40_IRQ_PERIOD; } @@ -58,7 +58,7 @@ static void map40_hblank(int vblank) if (0 == irq.counter) { nes_irq(); - irq.enabled = nofrendo_false; + irq.enabled = false; } } } @@ -70,12 +70,12 @@ static void map40_write(uint32 address, uint8 value) switch (range) { case 0: /* 0x8000-0x9FFF */ - irq.enabled = nofrendo_false; + irq.enabled = false; irq.counter = (int) MAP40_IRQ_PERIOD; break; case 1: /* 0xA000-0xBFFF */ - irq.enabled = nofrendo_true; + irq.enabled = true; break; case 3: /* 0xE000-0xFFFF */ diff --git a/components/nofrendo/mappers/map042.c b/components/nofrendo/mappers/map042.c index dc44357..b99fb74 100644 --- a/components/nofrendo/mappers/map042.c +++ b/components/nofrendo/mappers/map042.c @@ -34,7 +34,7 @@ static struct { - nofrendo_bool enabled; + bool enabled; uint32 counter; } irq; @@ -44,7 +44,7 @@ static struct static void map42_irq_reset (void) { /* Turn off IRQs */ - irq.enabled = nofrendo_false; + irq.enabled = false; irq.counter = 0x0000; /* Done */ @@ -114,7 +114,7 @@ static void map42_write (uint32 address, uint8 value) break; /* Register 2: IRQ */ - case 0x02: if (value & 0x02) irq.enabled = nofrendo_true; + case 0x02: if (value & 0x02) irq.enabled = true; else map42_irq_reset (); break; diff --git a/components/nofrendo/mappers/map050.c b/components/nofrendo/mappers/map050.c index c6b7631..0371aab 100644 --- a/components/nofrendo/mappers/map050.c +++ b/components/nofrendo/mappers/map050.c @@ -34,7 +34,7 @@ static struct { - nofrendo_bool enabled; + bool enabled; uint32 counter; } irq; @@ -44,7 +44,7 @@ static struct static void map50_irq_reset (void) { /* Turn off IRQs */ - irq.enabled = nofrendo_false; + irq.enabled = false; irq.counter = 0x0000; /* Done */ @@ -112,7 +112,7 @@ static void map50_write (uint32 address, uint8 value) if (address & 0x100) { /* IRQ settings */ - if (value & 0x01) irq.enabled = nofrendo_true; + if (value & 0x01) irq.enabled = true; else map50_irq_reset (); } else diff --git a/components/nofrendo/mappers/map064.c b/components/nofrendo/mappers/map064.c index 8413c29..ad568ca 100644 --- a/components/nofrendo/mappers/map064.c +++ b/components/nofrendo/mappers/map064.c @@ -31,7 +31,7 @@ static struct { int counter, latch; - nofrendo_bool enabled, reset; + bool enabled, reset; } irq; static uint8 command = 0; @@ -42,7 +42,7 @@ static void map64_hblank(int vblank) if (vblank) return; - irq.reset = nofrendo_false; + irq.reset = false; if (ppu_enabled()) { @@ -50,10 +50,10 @@ static void map64_hblank(int vblank) { irq.counter = irq.latch; - if (nofrendo_true == irq.enabled) + if (true == irq.enabled) nes_irq(); - irq.reset = nofrendo_true; + irq.reset = true; } } } @@ -139,16 +139,16 @@ static void map64_write(uint32 address, uint8 value) case 0xC001: //irq.latch = value; - irq.reset = nofrendo_true; + irq.reset = true; break; case 0xE000: //irq.counter = irq.latch; - irq.enabled = nofrendo_false; + irq.enabled = false; break; case 0xE001: - irq.enabled = nofrendo_true; + irq.enabled = true; break; default: @@ -158,7 +158,7 @@ static void map64_write(uint32 address, uint8 value) break; } - if (nofrendo_true == irq.reset) + if (true == irq.reset) irq.counter = irq.latch; } @@ -170,7 +170,7 @@ static void map64_init(void) mmc_bankrom(8, 0xE000, MMC_LASTBANK); irq.counter = irq.latch = 0; - irq.reset = irq.enabled = nofrendo_false; + irq.reset = irq.enabled = false; } static map_memwrite map64_memwrite[] = diff --git a/components/nofrendo/mappers/map065.c b/components/nofrendo/mappers/map065.c index 5db4b90..ef28f3f 100644 --- a/components/nofrendo/mappers/map065.c +++ b/components/nofrendo/mappers/map065.c @@ -30,7 +30,7 @@ static struct { int counter; - nofrendo_bool enabled; + bool enabled; int cycles; uint8 low, high; } irq; @@ -38,7 +38,7 @@ static struct static void map65_init(void) { irq.counter = 0; - irq.enabled = nofrendo_false; + irq.enabled = false; irq.low = irq.high = 0; irq.cycles = 0; } @@ -67,7 +67,7 @@ static void map65_write(uint32 address, uint8 value) switch (reg) { case 4: - irq.enabled = (value & 0x01) ? nofrendo_false : nofrendo_true; + irq.enabled = (value & 0x01) ? false : true; break; case 5: diff --git a/components/nofrendo/mappers/map073.c b/components/nofrendo/mappers/map073.c index 48e4ebe..5e2ebf0 100644 --- a/components/nofrendo/mappers/map073.c +++ b/components/nofrendo/mappers/map073.c @@ -33,7 +33,7 @@ static struct { - nofrendo_bool enabled; + bool enabled; uint32 counter; } irq; @@ -43,7 +43,7 @@ static struct static void map73_init (void) { /* Turn off IRQs */ - irq.enabled = nofrendo_false; + irq.enabled = false; irq.counter = 0x0000; /* Done */ @@ -76,7 +76,7 @@ static void map73_hblank (int vblank) nes_irq (); /* Shut off IRQ counter */ - irq.enabled = nofrendo_false; + irq.enabled = false; } } } @@ -100,8 +100,8 @@ static void map73_write (uint32 address, uint8 value) case 0xB000: irq.counter &= 0x0FFF; irq.counter |= (uint32) (value << 12); break; - case 0xC000: if (value & 0x02) irq.enabled = nofrendo_true; - else irq.enabled = nofrendo_false; + case 0xC000: if (value & 0x02) irq.enabled = true; + else irq.enabled = false; break; case 0xF000: mmc_bankrom (16, 0x8000, value); default: break; diff --git a/components/nofrendo/mappers/map085.c b/components/nofrendo/mappers/map085.c index f8e9013..d928efe 100644 --- a/components/nofrendo/mappers/map085.c +++ b/components/nofrendo/mappers/map085.c @@ -32,7 +32,7 @@ static struct { int counter, latch; int wait_state; - nofrendo_bool enabled; + bool enabled; } irq; /* mapper 85: Konami VRC7 */ @@ -119,8 +119,8 @@ static void map85_write(uint32 address, uint8 value) else { irq.wait_state = value & 0x01; - irq.enabled = (value & 0x02) ? nofrendo_true : nofrendo_false; - if (nofrendo_true == irq.enabled) + irq.enabled = (value & 0x02) ? true : false; + if (true == irq.enabled) irq.counter = irq.latch; } break; @@ -165,7 +165,7 @@ static void map85_init(void) irq.counter = irq.latch = 0; irq.wait_state = 0; - irq.enabled = nofrendo_false; + irq.enabled = false; } mapintf_t map85_intf = diff --git a/components/nofrendo/mappers/map160.c b/components/nofrendo/mappers/map160.c index 42b2e86..c35085a 100644 --- a/components/nofrendo/mappers/map160.c +++ b/components/nofrendo/mappers/map160.c @@ -30,7 +30,7 @@ static struct { - nofrendo_bool enabled, expired; + bool enabled, expired; int counter; int latch_c005, latch_c003; } irq; @@ -47,19 +47,19 @@ static void map160_write(uint32 address, uint8 value) } else if (0xC002 == address) { - irq.enabled = nofrendo_false; + irq.enabled = false; irq.latch_c005 = irq.latch_c003; } else if (0xC003 == address) { - if (nofrendo_false == irq.expired) + if (false == irq.expired) { irq.counter = value; } else { - irq.expired = nofrendo_false; - irq.enabled = nofrendo_true; + irq.expired = false; + irq.enabled = true; irq.counter = irq.latch_c005; } } @@ -82,9 +82,9 @@ static void map160_hblank(int vblank) { if (ppu_enabled() && irq.enabled) { - if (0 == irq.counter && nofrendo_false == irq.expired) + if (0 == irq.counter && false == irq.expired) { - irq.expired = nofrendo_true; + irq.expired = true; nes_irq(); } else @@ -97,8 +97,8 @@ static void map160_hblank(int vblank) static void map160_init(void) { - irq.enabled = nofrendo_false; - irq.expired = nofrendo_false; + irq.enabled = false; + irq.expired = false; irq.counter = 0; irq.latch_c003 = irq.latch_c005 = 0; } diff --git a/components/nofrendo/mappers/mapvrc.c b/components/nofrendo/mappers/mapvrc.c index 127d9e9..18c41bb 100644 --- a/components/nofrendo/mappers/mapvrc.c +++ b/components/nofrendo/mappers/mapvrc.c @@ -311,7 +311,7 @@ static void vrc_hblank(int vblank) { irq.counter = irq.latch; nes_irq(); - //irq.enabled = nofrendo_false; + //irq.enabled = false; irq.enabled = irq.wait_state; } } diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index e868d19..e6464ca 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -47,7 +47,7 @@ typedef struct memblock_s } memblock_t; /* debugging flag */ -nofrendo_bool mem_debug = nofrendo_true; +bool mem_debug = true; #ifdef NOFRENDO_DEBUG @@ -252,10 +252,10 @@ void *_my_nofrendo_malloc(int size, char *file, int line) void *temp; char fail[256]; - if (NULL == mem_record && nofrendo_false != mem_debug) + if (NULL == mem_record && false != mem_debug) mem_init(); - if (nofrendo_false != mem_debug) + if (false != mem_debug) temp = mem_guardalloc(size, GUARD_LENGTH); else // temp = malloc(size); @@ -269,7 +269,7 @@ void *_my_nofrendo_malloc(int size, char *file, int line) ASSERT_MSG(fail); } - if (nofrendo_false != mem_debug) + if (false != mem_debug) mem_addblock(temp, size, file, line); mem_blockcount++; @@ -297,7 +297,7 @@ void _my_nofrendo_free(void **data, char *file, int line) mem_blockcount--; /* dec our block count */ - if (nofrendo_false != mem_debug) + if (false != mem_debug) { mem_deleteblock(*data, file, line); mem_freeguardblock(*data, GUARD_LENGTH); @@ -386,7 +386,7 @@ void mem_checkleaks(void) #ifdef NOFRENDO_DEBUG int i; - if (nofrendo_false == mem_debug || NULL == mem_record) + if (false == mem_debug || NULL == mem_record) return; if (mem_blockcount) @@ -418,7 +418,7 @@ void mem_checkblocks(void) #ifdef NOFRENDO_DEBUG int i; - if (nofrendo_false == mem_debug || NULL == mem_record) + if (false == mem_debug || NULL == mem_record) return; for (i = 0; i < MAX_BLOCKS; i++) @@ -486,7 +486,7 @@ void mem_checkblocks(void) ** block manager space itself wasn't being freed - d'oh! ** ** Revision 1.10 2000/07/06 17:15:43 matt -** nofrendo_false isn't NULL, Neil... =) +** false isn't NULL, Neil... =) ** ** Revision 1.9 2000/07/05 23:10:01 neil ** It's a shame if the memguard segfaults diff --git a/components/nofrendo/memguard.h b/components/nofrendo/memguard.h index e77c7c0..db726d0 100644 --- a/components/nofrendo/memguard.h +++ b/components/nofrendo/memguard.h @@ -56,7 +56,7 @@ extern void mem_cleanup(void); extern void mem_checkblocks(void); extern void mem_checkleaks(void); -extern nofrendo_bool mem_debug; +extern bool mem_debug; #endif /* _MEMGUARD_H_ */ diff --git a/components/nofrendo/nes/nes.c b/components/nofrendo/nes/nes.c index 6839d6e..9ad05fc 100644 --- a/components/nofrendo/nes/nes.c +++ b/components/nofrendo/nes/nes.c @@ -262,7 +262,7 @@ static uint8 nes_clearfiq(void) { if (nes.fiq_occurred) { - nes.fiq_occurred = nofrendo_false; + nes.fiq_occurred = false; return 0x40; } @@ -283,7 +283,7 @@ static void nes_checkfiq(int cycles) nes.fiq_cycles += (int) NES_FIQ_PERIOD; if (0 == (nes.fiq_state & 0xC0)) { - nes.fiq_occurred = nofrendo_true; + nes.fiq_occurred = true; nes6502_irq(); } } @@ -294,7 +294,7 @@ void nes_nmi(void) nes6502_nmi(); } -static void nes_renderframe(nofrendo_bool draw_flag) +static void nes_renderframe(bool draw_flag) { int elapsed_cycles; mapintf_t *mapintf = nes.mmc->intf; @@ -334,12 +334,12 @@ static void nes_renderframe(nofrendo_bool draw_flag) nes.scanline = 0; } -static void system_video(nofrendo_bool draw) +static void system_video(bool draw) { /* TODO: hack */ - if (nofrendo_false == draw) + if (false == draw) { - gui_frame(nofrendo_false); + gui_frame(false); return; } @@ -348,7 +348,7 @@ static void system_video(nofrendo_bool draw) // 0, 0, NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT); /* overlay our GUI on top of it */ - gui_frame(nofrendo_true); + gui_frame(true); /* blit to screen */ vid_flush(); @@ -369,7 +369,7 @@ void nes_emulate(void) nes.scanline_cycles = 0; nes.fiq_cycles = (int) NES_FIQ_PERIOD; - while (nofrendo_false == nes.poweroff) + while (false == nes.poweroff) { if (nofrendo_ticks != last_ticks) { @@ -380,24 +380,24 @@ void nes_emulate(void) last_ticks = nofrendo_ticks; } - if (nofrendo_true == nes.pause) + if (true == nes.pause) { /* TODO: dim the screen, and pause/silence the apu */ - system_video(nofrendo_true); + system_video(true); frames_to_render = 0; } else if (frames_to_render > 1) { frames_to_render--; - nes_renderframe(nofrendo_false); - system_video(nofrendo_false); + nes_renderframe(false); + system_video(false); } - else if ((1 == frames_to_render && nofrendo_true == nes.autoframeskip) - || nofrendo_false == nes.autoframeskip) + else if ((1 == frames_to_render && true == nes.autoframeskip) + || false == nes.autoframeskip) { frames_to_render = 0; - nes_renderframe(nofrendo_true); - system_video(nofrendo_true); + nes_renderframe(true); + system_video(true); } } } @@ -454,12 +454,12 @@ void nes_destroy(nes_t **machine) void nes_poweroff(void) { - nes.poweroff = nofrendo_true; + nes.poweroff = true; } void nes_togglepause(void) { - nes.pause ^= nofrendo_true; + nes.pause ^= true; } /* insert a cart into the NES */ @@ -486,7 +486,7 @@ int nes_insertcart(const char *filename, nes_t *machine) /* if there's VRAM, let the PPU know */ if (NULL != machine->rominfo->vram) - machine->ppu->vram_present = nofrendo_true; + machine->ppu->vram_present = true; apu_setext(machine->apu, machine->mmc->intf->sound_ext); @@ -522,7 +522,7 @@ nes_t *nes_create(void) // if (NULL == machine->vidbuf) // goto _fail; - machine->autoframeskip = nofrendo_true; + machine->autoframeskip = true; /* cpu */ machine->cpu = nofrendo_malloc(sizeof(nes6502_context)); @@ -559,8 +559,8 @@ nes_t *nes_create(void) if (NULL == machine->ppu) goto _fail; - machine->poweroff = nofrendo_false; - machine->pause = nofrendo_false; + machine->poweroff = false; + machine->pause = false; return machine; @@ -593,7 +593,7 @@ nes_t *nes_create(void) ** scanline emulation simplifications/timing fixes ** ** Revision 1.13 2000/11/25 01:53:42 matt -** nofrendo_bool stinks sometimes +** bool stinks sometimes ** ** Revision 1.12 2000/11/21 13:28:40 matt ** take care to zero allocated mem diff --git a/components/nofrendo/nes/nes.h b/components/nofrendo/nes/nes.h index 5a53dff..4a616b3 100644 --- a/components/nofrendo/nes/nes.h +++ b/components/nofrendo/nes/nes.h @@ -75,7 +75,7 @@ typedef struct nes_s there, saving us about 64K of memory. */ // bitmap_t *vidbuf; - nofrendo_bool fiq_occurred; + bool fiq_occurred; uint8 fiq_state; int fiq_cycles; @@ -83,11 +83,11 @@ typedef struct nes_s /* Timing stuff */ float scanline_cycles; - nofrendo_bool autoframeskip; + bool autoframeskip; /* control */ - nofrendo_bool poweroff; - nofrendo_bool pause; + bool poweroff; + bool pause; } nes_t; @@ -132,7 +132,7 @@ extern void nes_togglepause(void); ** scanline emulation simplifications/timing fixes ** ** Revision 1.6 2000/11/25 01:52:17 matt -** nofrendo_bool stinks sometimes +** bool stinks sometimes ** ** Revision 1.5 2000/11/09 14:07:28 matt ** state load fixed, state save mostly fixed diff --git a/components/nofrendo/nes/nes_mmc.c b/components/nofrendo/nes/nes_mmc.c index 421988d..d32d404 100644 --- a/components/nofrendo/nes/nes_mmc.c +++ b/components/nofrendo/nes/nes_mmc.c @@ -161,18 +161,18 @@ void mmc_bankrom(int size, uint32 address, int bank) } /* Check to see if this mapper is supported */ -nofrendo_bool mmc_peek(int map_num) +bool mmc_peek(int map_num) { mapintf_t **map_ptr = mappers; while (NULL != *map_ptr) { if ((*map_ptr)->number == map_num) - return nofrendo_true; + return true; map_ptr++; } - return nofrendo_false; + return false; } static void mmc_setpages(void) diff --git a/components/nofrendo/nes/nes_mmc.h b/components/nofrendo/nes/nes_mmc.h index f30d9fc..4b8372a 100644 --- a/components/nofrendo/nes/nes_mmc.h +++ b/components/nofrendo/nes/nes_mmc.h @@ -78,7 +78,7 @@ extern void mmc_destroy(mmc_t **nes_mmc); extern void mmc_getcontext(mmc_t *dest_mmc); extern void mmc_setcontext(mmc_t *src_mmc); -extern nofrendo_bool mmc_peek(int map_num); +extern bool mmc_peek(int map_num); extern void mmc_reset(void); diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 9eefb8c..16f3d82 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -57,7 +57,7 @@ static ppu_t ppu; -void ppu_displaysprites(nofrendo_bool display) +void ppu_displaysprites(bool display) { ppu.drawsprites = display; } @@ -123,7 +123,7 @@ void ppu_getcontext(ppu_t *dest_ppu) ppu_t *ppu_create(void) { - static nofrendo_bool pal_generated = nofrendo_false; + static bool pal_generated = false; ppu_t *temp; temp = nofrendo_malloc(sizeof(ppu_t)); @@ -134,14 +134,14 @@ ppu_t *ppu_create(void) temp->latchfunc = NULL; temp->vromswitch = NULL; - temp->vram_present = nofrendo_false; - temp->drawsprites = nofrendo_true; + temp->vram_present = false; + temp->drawsprites = true; /* TODO: probably a better way to do this... */ - if (nofrendo_false == pal_generated) + if (false == pal_generated) { pal_generate(); - pal_generated = nofrendo_true; + pal_generated = true; } ppu_setdefaultpal(temp); @@ -229,7 +229,7 @@ void ppu_reset(int reset_type) ppu.tile_xofs = 0; ppu.latch = 0; - ppu.vram_accessible = nofrendo_true; + ppu.vram_accessible = true; } /* we render a scanline of graphics first so we know exactly @@ -238,12 +238,12 @@ void ppu_reset(int reset_type) */ static void ppu_setstrike(int x_loc) { - if (nofrendo_false == ppu.strikeflag) + if (false == ppu.strikeflag) { - ppu.strikeflag = nofrendo_true; + ppu.strikeflag = true; /* 3 pixels per cpu cycle */ - ppu.strike_cycle = nes6502_getcycles(nofrendo_false) + (x_loc / 3); + ppu.strike_cycle = nes6502_getcycles(false) + (x_loc / 3); } } @@ -356,7 +356,7 @@ uint8 ppu_read(uint32 address) if (ppu.strikeflag) { - if (nes6502_getcycles(nofrendo_false) >= ppu.strike_cycle) + if (nes6502_getcycles(false) >= ppu.strike_cycle) value |= PPU_STATF_STRIKE; } @@ -427,10 +427,10 @@ void ppu_write(uint32 address, uint8 value) case PPU_CTRL1: ppu.ctrl1 = value; - ppu.obj_on = (value & PPU_CTRL1F_OBJON) ? nofrendo_true : nofrendo_false; - ppu.bg_on = (value & PPU_CTRL1F_BGON) ? nofrendo_true : nofrendo_false; - ppu.obj_mask = (value & PPU_CTRL1F_OBJMASK) ? nofrendo_false : nofrendo_true; - ppu.bg_mask = (value & PPU_CTRL1F_BGMASK) ? nofrendo_false : nofrendo_true; + ppu.obj_on = (value & PPU_CTRL1F_OBJON) ? true : false; + ppu.bg_on = (value & PPU_CTRL1F_BGON) ? true : false; + ppu.obj_mask = (value & PPU_CTRL1F_OBJMASK) ? false : true; + ppu.bg_mask = (value & PPU_CTRL1F_BGMASK) ? false : true; break; case PPU_OAMADDR: @@ -494,7 +494,7 @@ void ppu_write(uint32 address, uint8 value) { uint32 addr = ppu.vaddr; - if (nofrendo_false == ppu.vram_present && addr >= 0x3000) + if (false == ppu.vram_present && addr >= 0x3000) ppu.vaddr -= 0x1000; PPU_MEM(addr) = value; @@ -594,7 +594,7 @@ INLINE void draw_bgtile(uint8 *surface, uint8 pat1, uint8 pat2, } INLINE int draw_oamtile(uint8 *surface, uint8 attrib, uint8 pat1, - uint8 pat2, const uint8 *col_tbl, nofrendo_bool check_strike) + uint8 pat2, const uint8 *col_tbl, bool check_strike) { int strike_pixel = -1; uint32 color = ((pat2 & 0xAA) << 8) | ((pat2 & 0x55) << 1) @@ -703,7 +703,7 @@ static void ppu_renderbg(uint8 *vidbuf) uint8 col_high, attrib, attrib_shift; /* draw a line of transparent background color if bg is disabled */ - if (nofrendo_false == ppu.bg_on) + if (false == ppu.bg_on) { memset(vidbuf, FULLBG, NES_SCREEN_WIDTH); return; @@ -793,7 +793,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) obj_t *sprite_ptr; uint8 sprite_height; - if (nofrendo_false == ppu.obj_on) + if (false == ppu.obj_on) return; /* Get our buffer pointer */ @@ -819,7 +819,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) int y_offset; uint8 tile_index, attrib, col_high; uint8 sprite_y, sprite_x; - nofrendo_bool check_strike; + bool check_strike; int strike_pixel; sprite_y = sprite_ptr->y_loc + 1; @@ -874,7 +874,7 @@ static void ppu_renderoam(uint8 *vidbuf, int scanline) /* if we're on sprite 0 and sprite 0 strike flag isn't set, ** check for a strike */ - check_strike = (0 == sprite_num) && (nofrendo_false == ppu.strikeflag); + check_strike = (0 == sprite_num) && (false == ppu.strikeflag); strike_pixel = draw_oamtile(bmp_ptr, attrib, data_ptr[0], data_ptr[8], ppu.palette + 16 + col_high, check_strike); if (strike_pixel >= 0) ppu_setstrike(strike_pixel); @@ -909,7 +909,7 @@ static void ppu_fakeoam(int scanline) /* we don't need to be here if strike flag is set */ - if (nofrendo_false == ppu.obj_on || ppu.strikeflag) + if (false == ppu.obj_on || ppu.strikeflag) return; sprite_height = ppu.obj_height; @@ -1005,12 +1005,12 @@ static void ppu_fakeoam(int scanline) } } -nofrendo_bool ppu_enabled(void) +bool ppu_enabled(void) { return (ppu.bg_on || ppu.obj_on); } -static void ppu_renderscanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag) +static void ppu_renderscanline(bitmap_t *bmp, int scanline, bool draw_flag) { uint8 *buf = bmp->line[scanline]; @@ -1032,7 +1032,7 @@ static void ppu_renderscanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_f ppu_renderbg(buf); /* TODO: fetch obj data 1 scanline before */ - if (nofrendo_true == ppu.drawsprites && nofrendo_true == draw_flag) + if (true == ppu.drawsprites && true == draw_flag) ppu_renderoam(buf, scanline); else ppu_fakeoam(scanline); @@ -1079,7 +1079,7 @@ void ppu_checknmi(void) nes_nmi(); } -void ppu_scanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag) +void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag) { if (scanline < 240) { @@ -1090,27 +1090,27 @@ void ppu_scanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag) else if (241 == scanline) { ppu.stat |= PPU_STATF_VBLANK; - ppu.vram_accessible = nofrendo_true; + ppu.vram_accessible = true; } else if (261 == scanline) { ppu.stat &= ~PPU_STATF_VBLANK; - ppu.strikeflag = nofrendo_false; + ppu.strikeflag = false; ppu.strike_cycle = (uint32) -1; - ppu.vram_accessible = nofrendo_false; + ppu.vram_accessible = false; } } /* -nofrendo_bool ppu_checkzapperhit(bitmap_t *bmp, int x, int y) +bool ppu_checkzapperhit(bitmap_t *bmp, int x, int y) { uint8 pixel = bmp->line[y][x] & 0x3F; if (0x20 == pixel || 0x30 == pixel) - return nofrendo_true; + return true; - return nofrendo_false; + return false; } */ diff --git a/components/nofrendo/nes/nes_ppu.h b/components/nofrendo/nes/nes_ppu.h index dd824e9..fff5e31 100644 --- a/components/nofrendo/nes/nes_ppu.h +++ b/components/nofrendo/nes/nes_ppu.h @@ -91,13 +91,13 @@ typedef struct ppu_s uint8 obj_height; uint32 obj_base, bg_base; - nofrendo_bool bg_on, obj_on; - nofrendo_bool obj_mask, bg_mask; + bool bg_on, obj_on; + bool obj_mask, bg_mask; uint8 latch, vdata_latch; uint8 strobe; - nofrendo_bool strikeflag; + bool strikeflag; uint32 strike_cycle; /* callbacks for naughty mappers */ @@ -107,10 +107,10 @@ typedef struct ppu_s /* copy of our current palette */ rgb_t curpal[256]; - nofrendo_bool vram_accessible; + bool vram_accessible; - nofrendo_bool vram_present; - nofrendo_bool drawsprites; + bool vram_present; + bool drawsprites; } ppu_t; @@ -133,8 +133,8 @@ extern uint8 *ppu_getpage(int page); /* control */ extern void ppu_reset(int reset_type); -extern nofrendo_bool ppu_enabled(void); -extern void ppu_scanline(bitmap_t *bmp, int scanline, nofrendo_bool draw_flag); +extern bool ppu_enabled(void); +extern void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag); extern void ppu_endscanline(int scanline); extern void ppu_checknmi(); @@ -154,7 +154,7 @@ extern void ppu_setdefaultpal(ppu_t *src_ppu); /* bleh */ extern void ppu_dumppattern(bitmap_t *bmp, int table_num, int x_loc, int y_loc, int col); extern void ppu_dumpoam(bitmap_t *bmp, int x_loc, int y_loc); -extern void ppu_displaysprites(nofrendo_bool display); +extern void ppu_displaysprites(bool display); #endif /* _NES_PPU_H_ */ diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index 995a92b..b73760b 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -260,7 +260,7 @@ static int rom_adddirty(char *filename) #ifdef NOFRENDO_DEBUG #define MAX_BUFFER_LENGTH 255 char buffer[MAX_BUFFER_LENGTH + 1]; - bool found = nofrendo_false; + bool found = false; FILE *fp = fopen("dirtyrom.txt", "rt"); if (NULL == fp) @@ -270,12 +270,12 @@ static int rom_adddirty(char *filename) { if (0 == strncmp(filename, buffer, strlen(filename))) { - found = nofrendo_true; + found = true; break; } } - if (nofrendo_false == found) + if (false == found) { /* close up the file, open it back up for writing */ fclose(fp); @@ -352,12 +352,12 @@ static int rom_getheader(FILE *fp, rominfo_t *rominfo) if (0 == memcmp(head.reserved, reserved, RESERVED_LENGTH)) { /* We were clean */ - header_dirty = nofrendo_false; + header_dirty = false; rominfo->mapper_number |= (head.mapper_hinybble & 0xF0); } else { - header_dirty = nofrendo_true; + header_dirty = true; /* @!?#@! DiskDude. */ if (('D' == head.mapper_hinybble) && (0 == memcmp(head.reserved, "iskDude!", 8))) @@ -444,7 +444,7 @@ rominfo_t *rom_load(const char *filename) goto _fail; /* Make sure we really support the mapper */ - if (nofrendo_false == mmc_peek(rominfo->mapper_number)) + if (false == mmc_peek(rominfo->mapper_number)) { gui_sendmsg(GUI_RED, "Mapper %d not yet implemented", rominfo->mapper_number); goto _fail; diff --git a/components/nofrendo/nes/nesstate.c b/components/nofrendo/nes/nesstate.c index 62fdf32..000510c 100644 --- a/components/nofrendo/nes/nesstate.c +++ b/components/nofrendo/nes/nesstate.c @@ -91,7 +91,7 @@ static int save_baseblock(nes_t *state, SNSS_FILE *snssFile) return 0; } -static nofrendo_bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) +static bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) { ASSERT(state); @@ -113,7 +113,7 @@ static nofrendo_bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) { int i; - nofrendo_bool written = nofrendo_false; + bool written = false; int sram_length; ASSERT(state); @@ -125,12 +125,12 @@ static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) { if (state->rominfo->sram[i]) { - written = nofrendo_true; + written = true; break; } } - if (nofrendo_false == written) + if (false == written) return -1; if (state->rominfo->sram_banks > 8) @@ -141,8 +141,8 @@ static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) snssFile->sramBlock.sramSize = SRAM_1K * state->rominfo->sram_banks; - /* TODO: this should not always be nofrendo_true!! */ - snssFile->sramBlock.sramEnabled = nofrendo_true; + /* TODO: this should not always be true!! */ + snssFile->sramBlock.sramEnabled = true; memcpy(snssFile->sramBlock.sram, state->rominfo->sram, snssFile->sramBlock.sramSize); @@ -260,7 +260,7 @@ static void load_baseblock(nes_t *state, SNSS_FILE *snssFile) /* do some extra handling */ state->ppu->flipflop = 0; - state->ppu->strikeflag = nofrendo_false; + state->ppu->strikeflag = false; nes6502_setcontext(state->cpu); ppu_setcontext(state->ppu); diff --git a/components/nofrendo/nofconfig.h b/components/nofrendo/nofconfig.h index 0e44904..50ac385 100644 --- a/components/nofrendo/nofconfig.h +++ b/components/nofrendo/nofconfig.h @@ -23,9 +23,9 @@ typedef struct config_s ** ** open must be the first config function called. ** - ** open returns nofrendo_true on success, nofrendo_false otherwise. + ** open returns true on success, false otherwise. */ - nofrendo_bool (*open)(void); + bool (*open)(void); /* close saves the current configuration to disk. ** diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index 3af685b..01b6a19 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -52,7 +52,7 @@ static struct int refresh_rate; - nofrendo_bool quit; + bool quit; } console; /* our happy little timer ISR */ @@ -109,7 +109,7 @@ void main_eject(void) /* Act on the user's quit requests */ void main_quit(void) { - console.quit = nofrendo_true; + console.quit = true; main_eject(); @@ -209,7 +209,7 @@ int nofrendo_main(int argc, char *argv[]) console.type = system_unknown; console.nexttype = system_unknown; console.refresh_rate = 0; - console.quit = nofrendo_false; + console.quit = false; if (log_init()) return -1; @@ -244,7 +244,7 @@ int main_loop(const char *filename, system_t type) console.nextfilename = nofrendo_strdup(filename); console.nexttype = type; - while (nofrendo_false == console.quit) + while (false == console.quit) { if (internal_insert(console.nextfilename, console.nexttype)) return 1; @@ -271,7 +271,7 @@ int main_loop(const char *filename, system_t type) ** removed fds "system" ** ** Revision 1.46 2000/11/25 01:51:53 matt -** nofrendo_bool stinks sometimes +** bool stinks sometimes ** ** Revision 1.45 2000/11/20 13:22:12 matt ** standardized timer ISR, added nofrendo_ticks diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 372986f..b86fcb6 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -23,8 +23,10 @@ ** $Id: noftypes.h,v 1.1 2001/04/27 14:37:11 neil Exp $ */ -#ifndef _TYPES_H_ -#define _TYPES_H_ +#ifndef _NOFTYPES_H_ +#define _NOFTYPES_H_ + +#include /* Define this if running on little-endian (x86) systems */ #define HOST_LITTLE_ENDIAN @@ -50,25 +52,13 @@ typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; -#ifndef __cplusplus -typedef enum -{ - nofrendo_false = 0, - nofrendo_true = 1 -} nofrendo_bool; - -#ifndef NULL -#define NULL ((void *) 0) -#endif -#endif /* !__cplusplus */ - #include "memguard.h" #include "log.h" #ifdef NOFRENDO_DEBUG #define ASSERT(expr) log_assert((int) (expr), __LINE__, __FILE__, NULL) -#define ASSERT_MSG(msg) log_assert(nofrendo_false, __LINE__, __FILE__, (msg)) +#define ASSERT_MSG(msg) log_assert(false, __LINE__, __FILE__, (msg)) #else /* !NOFRENDO_DEBUG */ diff --git a/components/nofrendo/sndhrdw/mmc5_snd.c b/components/nofrendo/sndhrdw/mmc5_snd.c index ce0f4ae..63754b6 100644 --- a/components/nofrendo/sndhrdw/mmc5_snd.c +++ b/components/nofrendo/sndhrdw/mmc5_snd.c @@ -70,13 +70,13 @@ typedef struct mmc5rectangle_s { uint8 regs[4]; - nofrendo_bool enabled; + bool enabled; float accum; int32 freq; int32 output_vol; - nofrendo_bool fixed_envelope; - nofrendo_bool holdnote; + bool fixed_envelope; + bool holdnote; uint8 volume; int32 env_phase; @@ -91,7 +91,7 @@ typedef struct mmc5rectangle_s typedef struct mmc5dac_s { int32 output; - nofrendo_bool enabled; + bool enabled; } mmc5dac_t; @@ -122,11 +122,11 @@ static int32 mmc5_rectangle(mmc5rectangle_t *chan) APU_VOLUME_DECAY(chan->output_vol); - if (nofrendo_false == chan->enabled || 0 == chan->vbl_length) + if (false == chan->enabled || 0 == chan->vbl_length) return MMC5_RECTANGLE_OUTPUT; /* vbl length counter */ - if (nofrendo_false == chan->holdnote) + if (false == chan->holdnote) chan->vbl_length--; /* envelope decay at a rate of (env_delay + 1) / 240 secs */ @@ -236,8 +236,8 @@ static void mmc5_write(uint32 address, uint8 value) mmc5.rect[chan].volume = value & 0x0F; mmc5.rect[chan].env_delay = decay_lut[value & 0x0F]; - mmc5.rect[chan].holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; - mmc5.rect[chan].fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; + mmc5.rect[chan].holdnote = (value & 0x20) ? true : false; + mmc5.rect[chan].fixed_envelope = (value & 0x10) ? true : false; mmc5.rect[chan].duty_flip = duty_lut[value >> 6]; break; @@ -270,21 +270,21 @@ static void mmc5_write(uint32 address, uint8 value) case MMC5_SMASK: if (value & 0x01) { - mmc5.rect[0].enabled = nofrendo_true; + mmc5.rect[0].enabled = true; } else { - mmc5.rect[0].enabled = nofrendo_false; + mmc5.rect[0].enabled = false; mmc5.rect[0].vbl_length = 0; } if (value & 0x02) { - mmc5.rect[1].enabled = nofrendo_true; + mmc5.rect[1].enabled = true; } else { - mmc5.rect[1].enabled = nofrendo_false; + mmc5.rect[1].enabled = false; mmc5.rect[1].vbl_length = 0; } @@ -292,9 +292,9 @@ static void mmc5_write(uint32 address, uint8 value) case 0x5010: if (value & 0x01) - mmc5.dac.enabled = nofrendo_true; + mmc5.dac.enabled = true; else - mmc5.dac.enabled = nofrendo_false; + mmc5.dac.enabled = false; break; case 0x5011: diff --git a/components/nofrendo/sndhrdw/nes_apu.c b/components/nofrendo/sndhrdw/nes_apu.c index 57bd7f2..af61fc6 100644 --- a/components/nofrendo/sndhrdw/nes_apu.c +++ b/components/nofrendo/sndhrdw/nes_apu.c @@ -111,7 +111,7 @@ void apu_getcontext(apu_t *dest_apu) *dest_apu = apu; } -void apu_setchan(int chan, nofrendo_bool enabled) +void apu_setchan(int chan, bool enabled) { if (enabled) apu.mix_enable |= (1 << chan); @@ -186,11 +186,11 @@ static int32 apu_rectangle_##ch(void) \ \ APU_VOLUME_DECAY(apu.rectangle[ch].output_vol); \ \ - if (nofrendo_false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ + if (false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* vbl length counter */ \ - if (nofrendo_false == apu.rectangle[ch].holdnote) \ + if (false == apu.rectangle[ch].holdnote) \ apu.rectangle[ch].vbl_length--; \ \ /* envelope decay at a rate of (env_delay + 1) / 240 secs */ \ @@ -205,9 +205,9 @@ static int32 apu_rectangle_##ch(void) \ apu.rectangle[ch].env_vol++; \ } \ \ - /* TODO: find nofrendo_true relation of freq_limit to register values */ \ + /* TODO: find true relation of freq_limit to register values */ \ if (apu.rectangle[ch].freq < 8 \ - || (nofrendo_false == apu.rectangle[ch].sweep_inc \ + || (false == apu.rectangle[ch].sweep_inc \ && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ return APU_RECTANGLE_OUTPUT(ch); \ \ @@ -269,11 +269,11 @@ static int32 apu_rectangle_##ch(void) \ \ APU_VOLUME_DECAY(apu.rectangle[ch].output_vol); \ \ - if (nofrendo_false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ + if (false == apu.rectangle[ch].enabled || 0 == apu.rectangle[ch].vbl_length) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* vbl length counter */ \ - if (nofrendo_false == apu.rectangle[ch].holdnote) \ + if (false == apu.rectangle[ch].holdnote) \ apu.rectangle[ch].vbl_length--; \ \ /* envelope decay at a rate of (env_delay + 1) / 240 secs */ \ @@ -288,8 +288,8 @@ static int32 apu_rectangle_##ch(void) \ apu.rectangle[ch].env_vol++; \ } \ \ - /* TODO: find nofrendo_true relation of freq_limit to register values */ \ - if (apu.rectangle[ch].freq < 8 || (nofrendo_false == apu.rectangle[ch].sweep_inc && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ + /* TODO: find true relation of freq_limit to register values */ \ + if (apu.rectangle[ch].freq < 8 || (false == apu.rectangle[ch].sweep_inc && apu.rectangle[ch].freq > apu.rectangle[ch].freq_limit)) \ return APU_RECTANGLE_OUTPUT(ch); \ \ /* frequency sweeping at a rate of (sweep_delay + 1) / 120 secs */ \ @@ -354,20 +354,20 @@ static int32 apu_triangle(void) { APU_VOLUME_DECAY(apu.triangle.output_vol); - if (nofrendo_false == apu.triangle.enabled || 0 == apu.triangle.vbl_length) + if (false == apu.triangle.enabled || 0 == apu.triangle.vbl_length) return APU_TRIANGLE_OUTPUT; if (apu.triangle.counter_started) { if (apu.triangle.linear_length > 0) apu.triangle.linear_length--; - if (apu.triangle.vbl_length && nofrendo_false == apu.triangle.holdnote) + if (apu.triangle.vbl_length && false == apu.triangle.holdnote) apu.triangle.vbl_length--; } - else if (nofrendo_false == apu.triangle.holdnote && apu.triangle.write_latency) + else if (false == apu.triangle.holdnote && apu.triangle.write_latency) { if (--apu.triangle.write_latency == 0) - apu.triangle.counter_started = nofrendo_true; + apu.triangle.counter_started = true; } if (0 == apu.triangle.linear_length || apu.triangle.freq < 4) /* inaudible */ @@ -411,11 +411,11 @@ static int32 apu_noise(void) APU_VOLUME_DECAY(apu.noise.output_vol); - if (nofrendo_false == apu.noise.enabled || 0 == apu.noise.vbl_length) + if (false == apu.noise.enabled || 0 == apu.noise.vbl_length) return APU_NOISE_OUTPUT; /* vbl length counter */ - if (nofrendo_false == apu.noise.holdnote) + if (false == apu.noise.holdnote) apu.noise.vbl_length--; /* envelope decay at a rate of (env_delay + 1) / 240 secs */ @@ -519,7 +519,7 @@ INLINE void apu_dmcreload(void) { apu.dmc.address = apu.dmc.cached_addr; apu.dmc.dma_length = apu.dmc.cached_dmalength; - apu.dmc.irq_occurred = nofrendo_false; + apu.dmc.irq_occurred = false; } /* DELTA MODULATION CHANNEL @@ -572,13 +572,13 @@ static int32 apu_dmc(void) /* check to see if we should generate an irq */ if (apu.dmc.irq_gen) { - apu.dmc.irq_occurred = nofrendo_true; + apu.dmc.irq_occurred = true; if (apu.irq_callback) apu.irq_callback(); } /* bodge for timestamp queue */ - apu.dmc.enabled = nofrendo_false; + apu.dmc.enabled = false; break; } } @@ -621,8 +621,8 @@ void apu_write(uint32 address, uint8 value) apu.rectangle[chan].regs[0] = value; apu.rectangle[chan].volume = value & 0x0F; apu.rectangle[chan].env_delay = decay_lut[value & 0x0F]; - apu.rectangle[chan].holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; - apu.rectangle[chan].fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; + apu.rectangle[chan].holdnote = (value & 0x20) ? true : false; + apu.rectangle[chan].fixed_envelope = (value & 0x10) ? true : false; apu.rectangle[chan].duty_flip = duty_flip[value >> 6]; break; @@ -630,10 +630,10 @@ void apu_write(uint32 address, uint8 value) case APU_WRB1: chan = (address & 4) >> 2; apu.rectangle[chan].regs[1] = value; - apu.rectangle[chan].sweep_on = (value & 0x80) ? nofrendo_true : nofrendo_false; + apu.rectangle[chan].sweep_on = (value & 0x80) ? true : false; apu.rectangle[chan].sweep_shifts = value & 7; apu.rectangle[chan].sweep_delay = decay_lut[(value >> 4) & 7]; - apu.rectangle[chan].sweep_inc = (value & 0x08) ? nofrendo_true : nofrendo_false; + apu.rectangle[chan].sweep_inc = (value & 0x08) ? true : false; apu.rectangle[chan].freq_limit = freq_limit[value & 7]; break; @@ -657,9 +657,9 @@ void apu_write(uint32 address, uint8 value) /* triangle */ case APU_WRC0: apu.triangle.regs[0] = value; - apu.triangle.holdnote = (value & 0x80) ? nofrendo_true : nofrendo_false; + apu.triangle.holdnote = (value & 0x80) ? true : false; - if (nofrendo_false == apu.triangle.counter_started && apu.triangle.vbl_length) + if (false == apu.triangle.counter_started && apu.triangle.vbl_length) apu.triangle.linear_length = trilength_lut[value & 0x7F]; break; @@ -687,7 +687,7 @@ void apu_write(uint32 address, uint8 value) apu.triangle.write_latency = (int) (228 / apu.cycle_rate); apu.triangle.freq = (((value & 7) << 8) + apu.triangle.regs[1]) + 1; apu.triangle.vbl_length = vbl_lut[value >> 3]; - apu.triangle.counter_started = nofrendo_false; + apu.triangle.counter_started = false; apu.triangle.linear_length = trilength_lut[apu.triangle.regs[0] & 0x7F]; break; @@ -695,8 +695,8 @@ void apu_write(uint32 address, uint8 value) case APU_WRD0: apu.noise.regs[0] = value; apu.noise.env_delay = decay_lut[value & 0x0F]; - apu.noise.holdnote = (value & 0x20) ? nofrendo_true : nofrendo_false; - apu.noise.fixed_envelope = (value & 0x10) ? nofrendo_true : nofrendo_false; + apu.noise.holdnote = (value & 0x20) ? true : false; + apu.noise.fixed_envelope = (value & 0x10) ? true : false; apu.noise.volume = value & 0x0F; break; @@ -708,13 +708,13 @@ void apu_write(uint32 address, uint8 value) apu.noise.xor_tap = (value & 0x80) ? 0x40: 0x02; #else /* !REALTIME_NOISE */ /* detect transition from long->short sample */ - if ((value & 0x80) && nofrendo_false == apu.noise.short_sample) + if ((value & 0x80) && false == apu.noise.short_sample) { /* recalculate short noise buffer */ shift_register15(noise_short_lut, APU_NOISE_93); apu.noise.cur_pos = 0; } - apu.noise.short_sample = (value & 0x80) ? nofrendo_true : nofrendo_false; + apu.noise.short_sample = (value & 0x80) ? true : false; #endif /* !REALTIME_NOISE */ break; @@ -728,16 +728,16 @@ void apu_write(uint32 address, uint8 value) case APU_WRE0: apu.dmc.regs[0] = value; apu.dmc.freq = dmc_clocks[value & 0x0F]; - apu.dmc.looping = (value & 0x40) ? nofrendo_true : nofrendo_false; + apu.dmc.looping = (value & 0x40) ? true : false; if (value & 0x80) { - apu.dmc.irq_gen = nofrendo_true; + apu.dmc.irq_gen = true; } else { - apu.dmc.irq_gen = nofrendo_false; - apu.dmc.irq_occurred = nofrendo_false; + apu.dmc.irq_gen = false; + apu.dmc.irq_occurred = false; } break; @@ -762,42 +762,42 @@ void apu_write(uint32 address, uint8 value) case APU_SMASK: /* bodge for timestamp queue */ - apu.dmc.enabled = (value & 0x10) ? nofrendo_true : nofrendo_false; + apu.dmc.enabled = (value & 0x10) ? true : false; apu.enable_reg = value; for (chan = 0; chan < 2; chan++) { if (value & (1 << chan)) { - apu.rectangle[chan].enabled = nofrendo_true; + apu.rectangle[chan].enabled = true; } else { - apu.rectangle[chan].enabled = nofrendo_false; + apu.rectangle[chan].enabled = false; apu.rectangle[chan].vbl_length = 0; } } if (value & 0x04) { - apu.triangle.enabled = nofrendo_true; + apu.triangle.enabled = true; } else { - apu.triangle.enabled = nofrendo_false; + apu.triangle.enabled = false; apu.triangle.vbl_length = 0; apu.triangle.linear_length = 0; - apu.triangle.counter_started = nofrendo_false; + apu.triangle.counter_started = false; apu.triangle.write_latency = 0; } if (value & 0x08) { - apu.noise.enabled = nofrendo_true; + apu.noise.enabled = true; } else { - apu.noise.enabled = nofrendo_false; + apu.noise.enabled = false; apu.noise.vbl_length = 0; } @@ -811,7 +811,7 @@ void apu_write(uint32 address, uint8 value) apu.dmc.dma_length = 0; } - apu.dmc.irq_occurred = nofrendo_false; + apu.dmc.irq_occurred = false; break; /* unused, but they get hit in some mem-clear loops */ @@ -1018,7 +1018,7 @@ apu_t *apu_create(double base_freq, int sample_rate, int refresh_rate, int sampl apu_setparams(base_freq, sample_rate, refresh_rate, sample_bits); for (channel = 0; channel < 6; channel++) - apu_setchan(channel, nofrendo_true); + apu_setchan(channel, true); apu_setfilter(APU_FILTER_WEIGHTED); diff --git a/components/nofrendo/sndhrdw/nes_apu.h b/components/nofrendo/sndhrdw/nes_apu.h index c5690ca..523c969 100644 --- a/components/nofrendo/sndhrdw/nes_apu.h +++ b/components/nofrendo/sndhrdw/nes_apu.h @@ -67,21 +67,21 @@ typedef struct rectangle_s { uint8 regs[4]; - nofrendo_bool enabled; + bool enabled; float accum; int32 freq; int32 output_vol; - nofrendo_bool fixed_envelope; - nofrendo_bool holdnote; + bool fixed_envelope; + bool holdnote; uint8 volume; int32 sweep_phase; int32 sweep_delay; - nofrendo_bool sweep_on; + bool sweep_on; uint8 sweep_shifts; uint8 sweep_length; - nofrendo_bool sweep_inc; + bool sweep_inc; /* this may not be necessary in the future */ int32 freq_limit; @@ -98,7 +98,7 @@ typedef struct triangle_s { uint8 regs[3]; - nofrendo_bool enabled; + bool enabled; float accum; int32 freq; @@ -106,8 +106,8 @@ typedef struct triangle_s uint8 adder; - nofrendo_bool holdnote; - nofrendo_bool counter_started; + bool holdnote; + bool counter_started; /* quasi-hack */ int write_latency; @@ -120,7 +120,7 @@ typedef struct noise_s { uint8 regs[3]; - nofrendo_bool enabled; + bool enabled; float accum; int32 freq; @@ -129,8 +129,8 @@ typedef struct noise_s int32 env_phase; int32 env_delay; uint8 env_vol; - nofrendo_bool fixed_envelope; - nofrendo_bool holdnote; + bool fixed_envelope; + bool holdnote; uint8 volume; @@ -139,7 +139,7 @@ typedef struct noise_s #ifdef REALTIME_NOISE uint8 xor_tap; #else - nofrendo_bool short_sample; + bool short_sample; int cur_pos; #endif /* REALTIME_NOISE */ } noise_t; @@ -149,7 +149,7 @@ typedef struct dmc_s uint8 regs[4]; /* bodge for timestamp queue */ - nofrendo_bool enabled; + bool enabled; float accum; int32 freq; @@ -161,9 +161,9 @@ typedef struct dmc_s int cached_dmalength; uint8 cur_byte; - nofrendo_bool looping; - nofrendo_bool irq_gen; - nofrendo_bool irq_occurred; + bool looping; + bool irq_gen; + bool irq_occurred; } dmc_t; @@ -245,7 +245,7 @@ extern void apu_reset(void); extern void apu_setext(apu_t *apu, apuext_t *ext); extern void apu_setfilter(int filter_type); -extern void apu_setchan(int chan, nofrendo_bool enabled); +extern void apu_setchan(int chan, bool enabled); extern uint8 apu_read(uint32 address); extern void apu_write(uint32 address, uint8 value); diff --git a/components/nofrendo/sndhrdw/vrcvisnd.c b/components/nofrendo/sndhrdw/vrcvisnd.c index 5afdcd0..e748061 100644 --- a/components/nofrendo/sndhrdw/vrcvisnd.c +++ b/components/nofrendo/sndhrdw/vrcvisnd.c @@ -29,7 +29,7 @@ typedef struct vrcvirectangle_s { - nofrendo_bool enabled; + bool enabled; uint8 reg[3]; @@ -43,7 +43,7 @@ typedef struct vrcvirectangle_s typedef struct vrcvisawtooth_s { - nofrendo_bool enabled; + bool enabled; uint8 reg[3]; @@ -81,7 +81,7 @@ static int32 vrcvi_rectangle(vrcvirectangle_t *chan) } /* return if not enabled */ - if (nofrendo_false == chan->enabled) + if (false == chan->enabled) return 0; if (chan->adder < chan->duty_flip) @@ -113,7 +113,7 @@ static int32 vrcvi_sawtooth(vrcvisawtooth_t *chan) } /* return if not enabled */ - if (nofrendo_false == chan->enabled) + if (false == chan->enabled) return 0; return (chan->output_acc >> 3) << 9; @@ -155,7 +155,7 @@ static void vrcvi_write(uint32 address, uint8 value) case 0xA002: vrcvi.rectangle[chan].reg[2] = value; vrcvi.rectangle[chan].freq = ((value & 0x0F) << 8) + vrcvi.rectangle[chan].reg[1] + 1; - vrcvi.rectangle[chan].enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; + vrcvi.rectangle[chan].enabled = (value & 0x80) ? true : false; break; case 0xB000: @@ -171,7 +171,7 @@ static void vrcvi_write(uint32 address, uint8 value) case 0xB002: vrcvi.saw.reg[2] = value; vrcvi.saw.freq = (((value & 0x0F) << 8) + vrcvi.saw.reg[1] + 1) << 1; - vrcvi.saw.enabled = (value & 0x80) ? nofrendo_true : nofrendo_false; + vrcvi.saw.enabled = (value & 0x80) ? true : false; break; default: diff --git a/components/nofrendo/vid_drv.c b/components/nofrendo/vid_drv.c index 13dcf4a..5e95fe7 100644 --- a/components/nofrendo/vid_drv.c +++ b/components/nofrendo/vid_drv.c @@ -298,7 +298,7 @@ INLINE int calc_dirties(rect_t *list) for (i = 0; i < iterations; i++) { - dirty = nofrendo_false; + dirty = false; j = line_offset; DUFFS_DEVICE( @@ -306,14 +306,14 @@ INLINE int calc_dirties(rect_t *list) if (vid_memcmp(back_buffer->line[j], primary_buffer->line[j], CHUNK_WIDTH)) { - dirty = nofrendo_true; + dirty = true; break; } j++; }, CHUNK_HEIGHT); - if (nofrendo_true == dirty) + if (true == dirty) { list->h = CHUNK_HEIGHT; list->w = CHUNK_WIDTH; @@ -341,9 +341,9 @@ void vid_flush(void) ASSERT(driver); - if (nofrendo_true == driver->invalidate) + if (true == driver->invalidate) { - driver->invalidate = nofrendo_false; + driver->invalidate = false; num_dirties = -1; } else diff --git a/components/nofrendo/vid_drv.h b/components/nofrendo/vid_drv.h index d293318..e97ed03 100644 --- a/components/nofrendo/vid_drv.h +++ b/components/nofrendo/vid_drv.h @@ -41,7 +41,7 @@ typedef struct viddriver_s /* set up a palette */ void (*set_palette)(rgb_t *palette); /* custom bitmap clear (can be NULL) */ - void (*clear)(uint8_t color); + void (*clear)(uint8 color); /* lock surface for writing (required) */ bitmap_t *(*lock_write)(void); /* free a locked surface (can be NULL) */ @@ -50,7 +50,7 @@ typedef struct viddriver_s void (*custom_blit)(bitmap_t *primary, int num_dirties, rect_t *dirty_rects); /* immediately invalidate the buffer, i.e. full redraw */ - nofrendo_bool invalidate; + bool invalidate; } viddriver_t; /* TODO: filth */ diff --git a/main/video_audio.c b/main/video_audio.c index a0174c4..1727171 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -115,7 +115,7 @@ static int osd_init_sound(void) .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, .dma_buf_count = 6, .dma_buf_len = 512, - .use_apll = nofrendo_false}; + .use_apll = false}; i2s_driver_install(I2S_NUM_0, &cfg, 2, &queue); i2s_set_pin(I2S_NUM_0, NULL); i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); @@ -159,7 +159,7 @@ viddriver_t sdlDriver = lock_write, /* lock_write */ free_write, /* free_write */ custom_blit, /* custom_blit */ - nofrendo_false /* invalidate flag */ + false /* invalidate flag */ }; bitmap_t *myBitmap; From b1624079d51d3d967fba11f2b7ed693bbf8dc935 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 22:24:10 +0800 Subject: [PATCH 47/73] _NOFTYPES_H_ --- components/nofrendo/noftypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index b86fcb6..8ce205e 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -67,7 +67,7 @@ typedef unsigned int uint32; #endif /* !NOFRENDO_DEBUG */ -#endif /* _TYPES_H_ */ +#endif /* _NOFTYPES_H_ */ /* ** $Log: noftypes.h,v $ From bad8d305a9f335c44540e2dd4ff963c6048fa487 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 7 Oct 2020 22:34:38 +0800 Subject: [PATCH 48/73] print return --- main/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index f3454d5..aaed294 100644 --- a/main/main.c +++ b/main/main.c @@ -50,7 +50,7 @@ void spiffs_init(void) } else { - printf("Partition size: total: %d, used: %d", total, used); + printf("Partition size: total: %d, used: %d\n", total, used); } } From 44554be4577fe82875a902628a40b4806ffd4690 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 8 Oct 2020 13:51:17 +0800 Subject: [PATCH 49/73] MALLOC_CAP_8BIT --- components/nofrendo/memguard.c | 92 ++++++++++++++++------------------ 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index e6464ca..c7b708b 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -35,29 +35,27 @@ #include "log.h" /* Maximum number of allocated blocks at any one time */ -#define MAX_BLOCKS 4096 +#define MAX_BLOCKS 4096 /* Memory block structure */ typedef struct memblock_s { - void *block_addr; - int block_size; - char *file_name; - int line_num; + void *block_addr; + int block_size; + char *file_name; + int line_num; } memblock_t; /* debugging flag */ bool mem_debug = true; - #ifdef NOFRENDO_DEBUG -static int mem_blockcount = 0; /* allocated block count */ +static int mem_blockcount = 0; /* allocated block count */ static memblock_t *mem_record = NULL; -#define GUARD_STRING "GgUuAaRrDdSsTtRrIiNnGgBbLlOoCcKk" -#define GUARD_LENGTH 256 /* before and after allocated block */ - +#define GUARD_STRING "GgUuAaRrDdSsTtRrIiNnGgBbLlOoCcKk" +#define GUARD_LENGTH 256 /* before and after allocated block */ /* ** Check the memory guard to make sure out of bounds writes have not @@ -69,11 +67,11 @@ static int mem_checkguardblock(void *data, int guard_size) int i, alloc_size; /* get the original pointer */ - block = ((char *) data) - guard_size; + block = ((char *)data) - guard_size; /* get the size */ - alloc_size = *((uint32 *) block); - block+=4; + alloc_size = *((uint32 *)block); + block += 4; /* check leading guard string */ check = GUARD_STRING; @@ -82,14 +80,14 @@ static int mem_checkguardblock(void *data, int guard_size) /* wrap */ if ('\0' == *check) check = GUARD_STRING; - + if (*block++ != *check++) return -1; } /* check end of block */ check = GUARD_STRING; - block = ((char *) data) + alloc_size; + block = ((char *)data) + alloc_size; for (i = 0; i < guard_size; i++) { /* wrap */ @@ -106,7 +104,7 @@ static int mem_checkguardblock(void *data, int guard_size) /* free a guard block */ static void mem_freeguardblock(void *data, int guard_size) { - char *orig = ((char *) data) - guard_size; + char *orig = ((char *)data) - guard_size; free(orig); } @@ -124,23 +122,23 @@ static void *mem_guardalloc(int alloc_size, int guard_size) /* allocate memory */ // orig = malloc(alloc_size + (guard_size * 2)); - orig = heap_caps_malloc(alloc_size + (guard_size * 2), MALLOC_CAP_INTERNAL); + orig = heap_caps_malloc(alloc_size + (guard_size * 2), MALLOC_CAP_8BIT); if (NULL == orig) return NULL; - block = (char *) orig; - + block = (char *)orig; + /* get it to the pointer we will actually return */ - orig = (void *) ((char *) orig + guard_size); + orig = (void *)((char *)orig + guard_size); /* trash it all */ - ptr = (uint32 *) orig; + ptr = (uint32 *)orig; for (i = alloc_size / 4; i; i--) *ptr++ = 0xDEADBEEF; - + /* store the size of the newly allocated block*/ - *((uint32 *) block) = alloc_size; - block+=4; + *((uint32 *)block) = alloc_size; + block += 4; /* put guard string at beginning of block */ check = GUARD_STRING; @@ -155,20 +153,19 @@ static void *mem_guardalloc(int alloc_size, int guard_size) /* put at end of block */ check = GUARD_STRING; - block = (char *) orig + alloc_size; + block = (char *)orig + alloc_size; for (i = 0; i < guard_size; i++) { /* wrap */ if ('\0' == *check) check = GUARD_STRING; - + *block++ = *check++; } return orig; } - /* Free up the space used by the memory block manager */ void mem_cleanup(void) { @@ -179,7 +176,6 @@ void mem_cleanup(void) } } - /* Allocate a bunch of memory to keep track of all memory blocks */ static void mem_init(void) { @@ -188,13 +184,12 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_INTERNAL); + mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_8BIT); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); } - /* add a block of memory to the master record */ static void mem_addblock(void *data, int block_size, char *file, int line) { @@ -228,7 +223,7 @@ static void mem_deleteblock(void *data, char *file, int line) if (mem_checkguardblock(mem_record[i].block_addr, GUARD_LENGTH)) { sprintf(fail, "mem_deleteblock 0x%08X at line %d of %s -- block corrupt", - (uint32) data, line, file); + (uint32)data, line, file); ASSERT_MSG(fail); } @@ -238,7 +233,7 @@ static void mem_deleteblock(void *data, char *file, int line) } sprintf(fail, "mem_deleteblock 0x%08X at line %d of %s -- block not found", - (uint32) data, line, file); + (uint32)data, line, file); ASSERT_MSG(fail); } #endif /* NOFRENDO_DEBUG */ @@ -259,7 +254,7 @@ void *_my_nofrendo_malloc(int size, char *file, int line) temp = mem_guardalloc(size, GUARD_LENGTH); else // temp = malloc(size); - temp = heap_caps_malloc(size, MALLOC_CAP_INTERNAL); + temp = heap_caps_malloc(size, MALLOC_CAP_8BIT); printf("Malloc: %d at %s:%d\n", size, file, line); if (NULL == temp) @@ -317,7 +312,7 @@ char *_my_nofrendo_strdup(const char *string, char *file, int line) if (NULL == string) return NULL; - temp = (char *) _my_nofrendo_malloc(strlen(string) + 1, file, line); + temp = (char *)_my_nofrendo_malloc(strlen(string) + 1, file, line); if (NULL == temp) return NULL; @@ -335,7 +330,7 @@ void *_my_nofrendo_malloc(int size) char fail[256]; // temp = malloc(size); - temp = heap_caps_malloc(size, MALLOC_CAP_INTERNAL); + temp = heap_caps_malloc(size, MALLOC_CAP_8BIT); if (NULL == temp) { @@ -369,7 +364,7 @@ char *_my_nofrendo_strdup(const char *string) return NULL; /* will ASSERT for us */ - temp = (char *) _my_nofrendo_malloc(strlen(string) + 1); + temp = (char *)_my_nofrendo_malloc(strlen(string) + 1); if (NULL == temp) return NULL; @@ -391,20 +386,21 @@ void mem_checkleaks(void) if (mem_blockcount) { - log_printf("memory leak - %d unfreed block%s\n\n", mem_blockcount, - mem_blockcount == 1 ? "" : "s"); + log_printf("memory leak - %d unfreed block%s\n\n", mem_blockcount, + mem_blockcount == 1 ? "" : "s"); for (i = 0; i < MAX_BLOCKS; i++) { if (mem_record[i].block_addr) { log_printf("addr: 0x%08X, size: %d, line %d of %s%s\n", - (uint32) mem_record[i].block_addr, - mem_record[i].block_size, - mem_record[i].line_num, - mem_record[i].file_name, - (mem_checkguardblock(mem_record[i].block_addr, GUARD_LENGTH)) - ? " -- block corrupt" : ""); + (uint32)mem_record[i].block_addr, + mem_record[i].block_size, + mem_record[i].line_num, + mem_record[i].file_name, + (mem_checkguardblock(mem_record[i].block_addr, GUARD_LENGTH)) + ? " -- block corrupt" + : ""); } } } @@ -428,10 +424,10 @@ void mem_checkblocks(void) if (mem_checkguardblock(mem_record[i].block_addr, GUARD_LENGTH)) { log_printf("addr: 0x%08X, size: %d, line %d of %s -- block corrupt\n", - (uint32) mem_record[i].block_addr, - mem_record[i].block_size, - mem_record[i].line_num, - mem_record[i].file_name); + (uint32)mem_record[i].block_addr, + mem_record[i].block_size, + mem_record[i].line_num, + mem_record[i].file_name); } } } From 11198e6cc3e78db984a7ba95665d7987702e96e9 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 8 Oct 2020 23:31:58 +0800 Subject: [PATCH 50/73] NOFRENDO_DEBUG comments --- components/nofrendo/gui.c | 6 +++--- components/nofrendo/mappers/map005.c | 2 +- components/nofrendo/mappers/map024.c | 2 +- components/nofrendo/mappers/map064.c | 4 ++-- components/nofrendo/mappers/mapvrc.c | 4 ++-- components/nofrendo/memguard.h | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/nofrendo/gui.c b/components/nofrendo/gui.c index 0ee454f..e89278b 100644 --- a/components/nofrendo/gui.c +++ b/components/nofrendo/gui.c @@ -347,7 +347,7 @@ static void gui_tickdec(void) { #ifdef NOFRENDO_DEBUG static int hertz_ticks = 0; -#endif +#endif /* !NOFRENDO_DEBUG */ int ticks = gui_ticks; if (0 == ticks) @@ -363,7 +363,7 @@ static void gui_tickdec(void) hertz_ticks -= (10 * gui_refresh); // mem_checkblocks(); } -#endif +#endif /* !NOFRENDO_DEBUG */ /* TODO: bleh */ if (msg.ttl > 0) @@ -593,7 +593,7 @@ void gui_sendmsg(int color, char *format, ...) log_print("GUI: "); log_print(msg.text); log_print("\n"); -#endif +#endif /* !NOFRENDO_DEBUG */ va_end(arg); diff --git a/components/nofrendo/mappers/map005.c b/components/nofrendo/mappers/map005.c index 4497224..60ab8b8 100644 --- a/components/nofrendo/mappers/map005.c +++ b/components/nofrendo/mappers/map005.c @@ -219,7 +219,7 @@ static uint8 map5_read(uint32 address) { #ifdef NOFRENDO_DEBUG log_printf("invalid MMC5 read: $%04X", address); -#endif +#endif /* !NOFRENDO_DEBUG */ return 0xFF; } } diff --git a/components/nofrendo/mappers/map024.c b/components/nofrendo/mappers/map024.c index d5916ed..f8e7512 100644 --- a/components/nofrendo/mappers/map024.c +++ b/components/nofrendo/mappers/map024.c @@ -148,7 +148,7 @@ static void map24_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG log_printf("invalid VRC6 write: $%02X to $%04X", value, address); -#endif +#endif /* !NOFRENDO_DEBUG */ break; } } diff --git a/components/nofrendo/mappers/map064.c b/components/nofrendo/mappers/map064.c index ad568ca..e6dc053 100644 --- a/components/nofrendo/mappers/map064.c +++ b/components/nofrendo/mappers/map064.c @@ -120,7 +120,7 @@ static void map64_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG log_printf("mapper 64: unknown command #%d", command & 0xF); -#endif +#endif /* !NOFRENDO_DEBUG */ break; } break; @@ -154,7 +154,7 @@ static void map64_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG log_printf("mapper 64: Wrote $%02X to $%04X", value, address); -#endif +#endif /* !NOFRENDO_DEBUG */ break; } diff --git a/components/nofrendo/mappers/mapvrc.c b/components/nofrendo/mappers/mapvrc.c index 18c41bb..b009051 100644 --- a/components/nofrendo/mappers/mapvrc.c +++ b/components/nofrendo/mappers/mapvrc.c @@ -152,7 +152,7 @@ static void map21_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG log_printf("wrote $%02X to $%04X", value, address); -#endif +#endif /* !NOFRENDO_DEBUG */ break; } } @@ -296,7 +296,7 @@ static void map23_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG log_printf("wrote $%02X to $%04X",value,address); -#endif +#endif /* !NOFRENDO_DEBUG */ break; } } diff --git a/components/nofrendo/memguard.h b/components/nofrendo/memguard.h index db726d0..33e3e86 100644 --- a/components/nofrendo/memguard.h +++ b/components/nofrendo/memguard.h @@ -38,7 +38,7 @@ extern void *_my_nofrendo_malloc(int size, char *file, int line); extern void _my_nofrendo_free(void **data, char *file, int line); extern char *_my_nofrendo_strdup(const char *string, char *file, int line); -#else /* !NORFRENDO_DEBUG */ +#else /* !NOFRENDO_DEBUG */ /* Non-debugging versions of calls */ #define nofrendo_malloc(s) _my_nofrendo_malloc((s)) From d4c12a26610be21a0c76d44dc9791e55d1d46ef3 Mon Sep 17 00:00:00 2001 From: moononournation Date: Thu, 8 Oct 2020 23:54:57 +0800 Subject: [PATCH 51/73] mem_init use MALLOC_CAP_SPIRAM --- components/nofrendo/memguard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index c7b708b..240976e 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -184,7 +184,7 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_8BIT); + mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); From adf192d85aa9f9a8fe76f1bae7058f2ac63b0596 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 9 Oct 2020 22:19:49 +0800 Subject: [PATCH 52/73] ESPTOOLPY_BAUD_921600B --- sdkconfig.defaults | 1 + 1 file changed, 1 insertion(+) diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 29f8b91..07cdfe3 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,3 +1,4 @@ +CONFIG_ESPTOOLPY_BAUD_921600B=y CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" From 07dfd296f22cd0116411cf1c00eb432bd5c78366 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 9 Oct 2020 22:20:52 +0800 Subject: [PATCH 53/73] relocate NOFRENDO_DEBUG to noftypes.h --- components/nofrendo/component.mk | 2 +- components/nofrendo/noftypes.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/nofrendo/component.mk b/components/nofrendo/component.mk index 0d213e5..eb5f5f2 100644 --- a/components/nofrendo/component.mk +++ b/components/nofrendo/component.mk @@ -10,4 +10,4 @@ COMPONENT_ADD_INCLUDEDIRS := cpu libsnss nes sndhrdw . COMPONENT_SRCDIRS := cpu libsnss nes sndhrdw mappers . -CFLAGS += -Wno-error=char-subscripts -Wno-error=attributes -DNOFRENDO_DEBUG +CFLAGS += -Wno-error=char-subscripts -Wno-error=attributes diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 8ce205e..7cfc498 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -28,6 +28,8 @@ #include +#define NOFRENDO_DEBUG + /* Define this if running on little-endian (x86) systems */ #define HOST_LITTLE_ENDIAN From d181aa792581b32061becfca3743a1ccbf33ddc7 Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 9 Oct 2020 22:21:42 +0800 Subject: [PATCH 54/73] remove duplicate vid_init done log --- components/nofrendo/vid_drv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/components/nofrendo/vid_drv.c b/components/nofrendo/vid_drv.c index 5e95fe7..ee4c33d 100644 --- a/components/nofrendo/vid_drv.c +++ b/components/nofrendo/vid_drv.c @@ -429,7 +429,6 @@ int vid_init(int width, int height, viddriver_t *osd_driver) osd_driver->name, width, height); return -1; } - log_printf("vid_init done\n"); return 0; } From f134507fb545aea2db7da7586fc0806ac44e0d2d Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 9 Oct 2020 22:23:18 +0800 Subject: [PATCH 55/73] debug memory access over bound --- components/nofrendo/nes/nes.h | 4 ---- components/nofrendo/nes/nes_ppu.c | 3 ++- components/nofrendo/noftypes.h | 2 ++ main/video_audio.c | 30 ++++++++++++++++-------------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/components/nofrendo/nes/nes.h b/components/nofrendo/nes/nes.h index 4a616b3..aa8a9cb 100644 --- a/components/nofrendo/nes/nes.h +++ b/components/nofrendo/nes/nes.h @@ -34,10 +34,6 @@ #include "../cpu/nes6502.h" #include "../bitmap.h" -/* Visible (NTSC) screen height */ -#ifndef NES_VISIBLE_HEIGHT -#define NES_VISIBLE_HEIGHT 224 -#endif /* !NES_VISIBLE_HEIGHT */ #define NES_SCREEN_WIDTH 256 #define NES_SCREEN_HEIGHT 240 diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 16f3d82..cff6147 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -1081,7 +1081,8 @@ void ppu_checknmi(void) void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag) { - if (scanline < 240) + // if (scanline < 240) + if (scanline < NES_VISIBLE_HEIGHT) { /* Lower the Max Sprite per scanline flag */ ppu.stat &= ~PPU_STATF_MAXSPRITE; diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 7cfc498..966427f 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -29,6 +29,8 @@ #include #define NOFRENDO_DEBUG +#define NES_VISIBLE_WIDTH 256 +#define NES_VISIBLE_HEIGHT 240 /* Define this if running on little-endian (x86) systems */ #define HOST_LITTLE_ENDIAN diff --git a/main/video_audio.c b/main/video_audio.c index 1727171..025d7f0 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -42,9 +42,6 @@ #define DEFAULT_SAMPLERATE 32000 #define DEFAULT_FRAGSIZE 128 -#define DEFAULT_WIDTH 256 -#define DEFAULT_HEIGHT NES_VISIBLE_HEIGHT - TimerHandle_t timer; //Seemingly, this will be called only once. Should call func with a freq of frequency, @@ -76,14 +73,19 @@ static void do_audio_frame() if (n > left) n = left; audio_callback(audio_frame, n); //get more data + //16 bit mono -> 32-bit (16 bit r+l) - for (int i = n - 1; i >= 0; i--) + int16_t *mono_ptr = audio_frame + n; + int16_t *stereo_ptr = audio_frame + n + n; + int i = n; + while (i--) { // audio_frame[i] = audio_frame[i] + 0x8000; - int16_t a = (audio_frame[i] >> 3); - audio_frame[i * 2 + 1] = 0x8000 + a; - audio_frame[i * 2] = 0x8000 - a; + int16_t a = (*(--mono_ptr) >> 3); + *(--stereo_ptr) = 0x8000 + a; + *(--stereo_ptr) = 0x8000 - a; } + size_t i2s_bytes_write; i2s_write(I2S_NUM_0, (const char *)audio_frame, 4 * n, &i2s_bytes_write, portMAX_DELAY); left -= i2s_bytes_write / 4; @@ -105,7 +107,7 @@ static void osd_stopsound(void) static int osd_init_sound(void) { #if CONFIG_SOUND_ENA - audio_frame = nofrendo_malloc(2 * DEFAULT_FRAGSIZE); + audio_frame = nofrendo_malloc(4 * DEFAULT_FRAGSIZE); i2s_config_t cfg = { .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, .sample_rate = DEFAULT_SAMPLERATE, @@ -166,8 +168,8 @@ bitmap_t *myBitmap; void osd_getvideoinfo(vidinfo_t *info) { - info->default_width = DEFAULT_WIDTH; - info->default_height = DEFAULT_HEIGHT; + info->default_width = NES_VISIBLE_WIDTH; + info->default_height = NES_VISIBLE_HEIGHT; info->driver = &sdlDriver; } @@ -219,7 +221,7 @@ static void clear(uint8 color) static bitmap_t *lock_write(void) { // SDL_LockSurface(mySurface); - myBitmap = bmp_createhw((uint8 *)fb, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 2); + myBitmap = bmp_createhw((uint8 *)fb, NES_VISIBLE_WIDTH, NES_VISIBLE_HEIGHT, NES_VISIBLE_WIDTH * 2); return myBitmap; } @@ -240,13 +242,13 @@ static void videoTask(void *arg) { int x, y; bitmap_t *bmp = NULL; - x = (320 - DEFAULT_WIDTH) / 2; - y = ((240 - DEFAULT_HEIGHT) / 2); + x = (320 - NES_VISIBLE_WIDTH) / 2; + y = ((240 - NES_VISIBLE_HEIGHT) / 2); while (1) { // xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30 xQueueReceive(vidQueue, &bmp, portMAX_DELAY); - lcd_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line); + lcd_write_frame(x, y, NES_VISIBLE_WIDTH, NES_VISIBLE_HEIGHT, (const uint8_t **)bmp->line); } } From b2bbee8e65d7a9f70aa5e2981781a154ca60df4c Mon Sep 17 00:00:00 2001 From: moononournation Date: Fri, 9 Oct 2020 22:58:45 +0800 Subject: [PATCH 56/73] align all printf to log_printf --- components/nofrendo/mappers/map002.c | 2 +- components/nofrendo/nofrendo.c | 2 +- main/controller.c | 10 +++++----- main/main.c | 14 +++++++------- main/osd.c | 10 +++++----- main/video_audio.c | 9 ++++----- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/components/nofrendo/mappers/map002.c b/components/nofrendo/mappers/map002.c index 9e49450..2b112ba 100644 --- a/components/nofrendo/mappers/map002.c +++ b/components/nofrendo/mappers/map002.c @@ -30,7 +30,7 @@ static void map2_init() { int last_bank = mmc_getinfo()->rom_banks - 1; - printf("map2_init. last_bank=%d\n", last_bank); + log_printf("map2_init. last_bank=%d\n", last_bank); mmc_bankrom(16, 0xc000, last_bank); mmc_bankrom(16, 0x8000, 0); } diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index 01b6a19..3d769e3 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -239,7 +239,7 @@ int main_loop(const char *filename, system_t type) osd_getvideoinfo(&video); if (vid_init(video.default_width, video.default_height, video.driver)) return -1; - printf("vid_init done\n"); + log_printf("vid_init done\n"); console.nextfilename = nofrendo_strdup(filename); console.nexttype = type; diff --git a/main/controller.c b/main/controller.c index 10b59be..fca02fe 100644 --- a/main/controller.c +++ b/main/controller.c @@ -271,11 +271,11 @@ void controller_init() psxDone(); if (t == 0 || t == 0xff) { - printf("No PSX/PS2 controller detected (0x%X). You will not be able to control the game.\n", t); + log_printf("No PSX/PS2 controller detected (0x%X). You will not be able to control the game.\n", t); } else { - printf("PSX controller type 0x%X\n", t); + log_printf("PSX controller type 0x%X\n", t); } } @@ -347,7 +347,7 @@ int controller_read_input() i2c_cmd_link_delete(cmd); if (ret == 0) { - printf("I2C read %d, return %d\n", data, ret); + log_printf("I2C read %d, return %d\n", data, ret); return 0xFFFF ^ ((((0x01 & data) > 0) << 4) | (((0x02 & data) > 0) << 6) | (((0x04 & data) > 0) << 7) | (((0x08 & data) > 0) << 5) | (((0x10 & data) > 0) << 0) | (((0x20 & data) > 0) << 3) | (((0x40 & data) > 0) << 13) | (((0x80 & data) > 0) << 14)); } @@ -412,7 +412,7 @@ int controller_read_input() i2c_cmd_link_delete(cmd); if ((ret == 0) && (data > 0)) { - printf("I2C read %d, return %d\n", data, ret); + log_printf("I2C read %d, return %d\n", data, ret); switch (data) { @@ -450,7 +450,7 @@ int controller_read_input() void controller_gpio_init() { - printf("GPIO controller disabled in menuconfig; no input enabled.\n"); + log_printf("GPIO controller disabled in menuconfig; no input enabled.\n"); } int controller_gpio_read_input() diff --git a/main/main.c b/main/main.c index aaed294..84b24c5 100644 --- a/main/main.c +++ b/main/main.c @@ -29,15 +29,15 @@ void spiffs_init(void) { if (ret == ESP_FAIL) { - printf("Failed to mount or format filesystem"); + log_printf("Failed to mount or format filesystem"); } else if (ret == ESP_ERR_NOT_FOUND) { - printf("Failed to find SPIFFS partition"); + log_printf("Failed to find SPIFFS partition"); } else { - printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); + log_printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); } return; } @@ -46,11 +46,11 @@ void spiffs_init(void) ret = esp_spiffs_info(NULL, &total, &used); if (ret != ESP_OK) { - printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); + log_printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); } else { - printf("Partition size: total: %d, used: %d\n", total, used); + log_printf("Partition size: total: %d, used: %d\n", total, used); } } @@ -58,9 +58,9 @@ int app_main(void) { spiffs_init(); - printf("NoFrendo start!\n"); + log_printf("NoFrendo start!\n"); nofrendo_main(0, NULL); - printf("NoFrendo died? Oh no!\n"); + log_printf("NoFrendo died? Oh no!\n"); asm("break.n 1"); return 0; } diff --git a/main/osd.c b/main/osd.c index 895142c..748f856 100644 --- a/main/osd.c +++ b/main/osd.c @@ -16,16 +16,16 @@ #include #include #include +#include +#include +#include +#include +#include -#include "errno.h" -#include "fcntl.h" -#include "limits.h" #include "log.h" #include "nofrendo.h" #include "noftypes.h" #include "osd.h" -#include "signal.h" -#include "unistd.h" #include "version.h" #include "nofconfig.h" diff --git a/main/video_audio.c b/main/video_audio.c index 025d7f0..97fb667 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include @@ -31,9 +32,8 @@ #include "nes_pal.h" #include "nesinput.h" #include "osd.h" -#include "stdint.h" -#include "spi_lcd.h" +#include "spi_lcd.h" #include "controller.h" #include "nofconfig.h" @@ -47,7 +47,7 @@ TimerHandle_t timer; //Seemingly, this will be called only once. Should call func with a freq of frequency, int osd_installtimer(int frequency, void *func, int funcsize, void *counter, int countersize) { - printf("Timer install, configTICK_RATE_HZ=%d, freq=%d\n", configTICK_RATE_HZ, frequency); + log_printf("Timer install, configTICK_RATE_HZ=%d, freq=%d\n", configTICK_RATE_HZ, frequency); timer = xTimerCreate("nes", configTICK_RATE_HZ / frequency, pdTRUE, NULL, func); xTimerStart(timer, 0); return 0; @@ -64,7 +64,6 @@ static int16_t *audio_frame; static void do_audio_frame() { - #if CONFIG_SOUND_ENA int left = DEFAULT_SAMPLERATE / NES_REFRESH_RATE; while (left) @@ -272,7 +271,7 @@ void osd_getinput(void) int x; oldb = b; event_t evh; - // printf("Input: %x\n", b); + // log_printf("Input: %x\n", b); for (x = 0; x < 16; x++) { if (chg & 1) From 2ce32e5f6176765f6c32dd6269247523e6cd0801 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 10 Oct 2020 01:01:53 +0800 Subject: [PATCH 57/73] CONFIG_MAIN_TASK_STACK_SIZE=12240 for state_save() --- sdkconfig.defaults | 1 + 1 file changed, 1 insertion(+) diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 07cdfe3..c3775f8 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -7,5 +7,6 @@ CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 CONFIG_ESP32_SPIRAM_SUPPORT=y CONFIG_SPIRAM_BOOT_INIT=y CONFIG_SPIRAM_IGNORE_NOTFOUND=y +CONFIG_MAIN_TASK_STACK_SIZE=12240 CONFIG_TASK_WDT= CONFIG_FREERTOS_HZ=1000 From 57f1fe0a113839d3a116de779402bcad9f65a3e9 Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 10 Oct 2020 01:13:44 +0800 Subject: [PATCH 58/73] use nofrendo_malloc in SNSS_WriteBaseBlock --- components/nofrendo/libsnss/libsnss.c | 2 +- sdkconfig.defaults | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/components/nofrendo/libsnss/libsnss.c b/components/nofrendo/libsnss/libsnss.c index 3bf6073..7c2d4a6 100644 --- a/components/nofrendo/libsnss/libsnss.c +++ b/components/nofrendo/libsnss/libsnss.c @@ -411,7 +411,7 @@ SNSS_WriteBaseBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; - char blockBytes[BASE_BLOCK_LENGTH]; + char *blockBytes = nofrendo_malloc(BASE_BLOCK_LENGTH); unsigned short tempShort; strcpy(header.tag, "BASR"); diff --git a/sdkconfig.defaults b/sdkconfig.defaults index c3775f8..07cdfe3 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -7,6 +7,5 @@ CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 CONFIG_ESP32_SPIRAM_SUPPORT=y CONFIG_SPIRAM_BOOT_INIT=y CONFIG_SPIRAM_IGNORE_NOTFOUND=y -CONFIG_MAIN_TASK_STACK_SIZE=12240 CONFIG_TASK_WDT= CONFIG_FREERTOS_HZ=1000 From 3d294733816640b313fdc41f93f944e1b4a0608b Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 10 Oct 2020 01:20:02 +0800 Subject: [PATCH 59/73] use nofrendo_malloc in SNSS_ReadBaseBlock --- components/nofrendo/libsnss/libsnss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo/libsnss/libsnss.c b/components/nofrendo/libsnss/libsnss.c index 7c2d4a6..9eeb06f 100644 --- a/components/nofrendo/libsnss/libsnss.c +++ b/components/nofrendo/libsnss/libsnss.c @@ -369,7 +369,7 @@ SNSS_SkipNextBlock(SNSS_FILE *snssFile) static SNSS_RETURN_CODE SNSS_ReadBaseBlock(SNSS_FILE *snssFile) { - char blockBytes[BASE_BLOCK_LENGTH]; + char *blockBytes = nofrendo_malloc(BASE_BLOCK_LENGTH); SnssBlockHeader header; if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) From 92ac1f0d186f96123f8508f8697499b081ce24ac Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 10 Oct 2020 23:45:55 +0800 Subject: [PATCH 60/73] resolve conflict of log_printf() --- components/nofrendo/config.c | 12 ++++++------ components/nofrendo/cpu/dis6502.c | 2 +- components/nofrendo/cpu/dis6502.h | 2 +- components/nofrendo/cpu/nes6502.c | 4 ++-- components/nofrendo/log.c | 8 ++++---- components/nofrendo/log.h | 2 +- components/nofrendo/mappers/map002.c | 2 +- components/nofrendo/mappers/map005.c | 4 ++-- components/nofrendo/mappers/map024.c | 2 +- components/nofrendo/mappers/map064.c | 4 ++-- components/nofrendo/mappers/map085.c | 2 +- components/nofrendo/mappers/map160.c | 2 +- components/nofrendo/mappers/mapvrc.c | 4 ++-- components/nofrendo/memguard.c | 8 ++++---- components/nofrendo/nes/nes_mmc.c | 10 +++++----- components/nofrendo/nes/nes_ppu.c | 4 ++-- components/nofrendo/nes/nes_rom.c | 14 +++++++------- components/nofrendo/nes/nesstate.c | 6 +++--- components/nofrendo/nofrendo.c | 6 +++--- components/nofrendo/vid_drv.c | 4 ++-- main/controller.c | 10 +++++----- main/main.c | 14 +++++++------- main/video_audio.c | 4 ++-- 23 files changed, 65 insertions(+), 65 deletions(-) diff --git a/components/nofrendo/config.c b/components/nofrendo/config.c index 41440b8..5d31e62 100644 --- a/components/nofrendo/config.c +++ b/components/nofrendo/config.c @@ -227,7 +227,7 @@ static int load_config(char *filename) s = strchr(s, ']'); if (NULL == s) { - log_printf("load_config: missing ']' after group\n"); + nofrendo_log_printf("load_config: missing ']' after group\n"); s = group + strlen(group); } else @@ -247,7 +247,7 @@ static int load_config(char *filename) s = strchr(s, '='); if (NULL == s) { - log_printf("load_config: missing '=' after key\n"); + nofrendo_log_printf("load_config: missing '=' after key\n"); s = key + strlen(key); } else @@ -268,7 +268,7 @@ static int load_config(char *filename) myvar_t *var = my_create(group ? group : "", key, s); if (NULL == var) { - log_printf("load_config: my_create failed\n"); + nofrendo_log_printf("load_config: my_create failed\n"); return -1; } @@ -299,7 +299,7 @@ static int save_config(char *filename) config_file = fopen(filename, "w"); if (NULL == config_file) { - log_printf("save_config failed\n"); + nofrendo_log_printf("save_config failed\n"); return -1; } @@ -337,7 +337,7 @@ static void write_int(const char *group, const char *key, int value) var = my_create(group, key, buf); if (NULL == var) { - log_printf("write_int failed\n"); + nofrendo_log_printf("write_int failed\n"); return; } @@ -371,7 +371,7 @@ static void write_string(const char *group, const char *key, const char *value) var = my_create(group, key, value); if (NULL == var) { - log_printf("write_string failed\n"); + nofrendo_log_printf("write_string failed\n"); return; } diff --git a/components/nofrendo/cpu/dis6502.c b/components/nofrendo/cpu/dis6502.c index e77e3e0..9e8eda1 100644 --- a/components/nofrendo/cpu/dis6502.c +++ b/components/nofrendo/cpu/dis6502.c @@ -519,7 +519,7 @@ char *nes6502_disasm(uint32 PC, uint8 P, uint8 A, uint8 X, uint8 Y, uint8 S) ** made sure last line of all source files is a newline ** ** Revision 1.7 2000/07/11 04:26:23 matt -** rewrote to fill up a static buffer, rather than use log_printf +** rewrote to fill up a static buffer, rather than use nofrendo_log_printf ** ** Revision 1.6 2000/07/10 05:15:58 matt ** fixed a bug in indirect x/y disassembly diff --git a/components/nofrendo/cpu/dis6502.h b/components/nofrendo/cpu/dis6502.h index 83f0abf..58f7a5e 100644 --- a/components/nofrendo/cpu/dis6502.h +++ b/components/nofrendo/cpu/dis6502.h @@ -50,7 +50,7 @@ extern char *nes6502_disasm(uint32 PC, uint8 P, uint8 A, uint8 X, uint8 Y, uint8 ** made sure last line of all source files is a newline ** ** Revision 1.5 2000/07/11 04:26:23 matt -** rewrote to fill up a static buffer, rather than use log_printf +** rewrote to fill up a static buffer, rather than use nofrendo_log_printf ** ** Revision 1.4 2000/06/09 15:12:25 matt ** initial revision diff --git a/components/nofrendo/cpu/nes6502.c b/components/nofrendo/cpu/nes6502.c index ff5fd31..5f2a4b9 100644 --- a/components/nofrendo/cpu/nes6502.c +++ b/components/nofrendo/cpu/nes6502.c @@ -1342,7 +1342,7 @@ uint32 nes6502_getcycles(bool reset_flag) #define OPCODE_END \ if (remaining_cycles <= 0) \ goto end_execute; \ - log_printf(nes6502_disasm(PC, COMBINE_FLAGS(), A, X, Y, S)); \ + nofrendo_log_printf(nes6502_disasm(PC, COMBINE_FLAGS(), A, X, Y, S)); \ goto *opcode_table[bank_readbyte(PC++)]; #else /* !NES6520_DISASM */ @@ -1452,7 +1452,7 @@ int nes6502_execute(int timeslice_cycles) while (remaining_cycles > 0) { #ifdef NES6502_DISASM - log_printf(nes6502_disasm(PC, COMBINE_FLAGS(), A, X, Y, S)); + nofrendo_log_printf(nes6502_disasm(PC, COMBINE_FLAGS(), A, X, Y, S)); #endif /* NES6502_DISASM */ /* Fetch and execute instruction */ diff --git a/components/nofrendo/log.c b/components/nofrendo/log.c index d487e57..97638c6 100644 --- a/components/nofrendo/log.c +++ b/components/nofrendo/log.c @@ -67,7 +67,7 @@ int log_print(const char *string) return 0; } -int log_printf(const char *format, ... ) +int nofrendo_log_printf(const char *format, ... ) { /* don't allocate on stack every call */ static char buffer[1024 + 1]; @@ -105,7 +105,7 @@ int log_print(const char *string) return 0; } -int log_printf(const char *format, ... ) +int nofrendo_log_printf(const char *format, ... ) { UNUSED(format); @@ -124,9 +124,9 @@ void log_assert(int expr, int line, const char *file, char *msg) return; if (NULL != msg) - log_printf("ASSERT: line %d of %s, %s\n", line, file, msg); + nofrendo_log_printf("ASSERT: line %d of %s, %s\n", line, file, msg); else - log_printf("ASSERT: line %d of %s\n", line, file); + nofrendo_log_printf("ASSERT: line %d of %s\n", line, file); asm("break.n 1"); // exit(-1); diff --git a/components/nofrendo/log.h b/components/nofrendo/log.h index 58d93c7..72047ea 100644 --- a/components/nofrendo/log.h +++ b/components/nofrendo/log.h @@ -31,7 +31,7 @@ extern int log_init(void); extern void log_shutdown(void); extern int log_print(const char *string); -extern int log_printf(const char *format, ...); +extern int nofrendo_log_printf(const char *format, ...); extern void log_chain_logfunc(int (*logfunc)(const char *string)); extern void log_assert(int expr, int line, const char *file, char *msg); diff --git a/components/nofrendo/mappers/map002.c b/components/nofrendo/mappers/map002.c index 2b112ba..dade025 100644 --- a/components/nofrendo/mappers/map002.c +++ b/components/nofrendo/mappers/map002.c @@ -30,7 +30,7 @@ static void map2_init() { int last_bank = mmc_getinfo()->rom_banks - 1; - log_printf("map2_init. last_bank=%d\n", last_bank); + nofrendo_log_printf("map2_init. last_bank=%d\n", last_bank); mmc_bankrom(16, 0xc000, last_bank); mmc_bankrom(16, 0x8000, 0); } diff --git a/components/nofrendo/mappers/map005.c b/components/nofrendo/mappers/map005.c index 60ab8b8..1f2ffab 100644 --- a/components/nofrendo/mappers/map005.c +++ b/components/nofrendo/mappers/map005.c @@ -201,7 +201,7 @@ static void map5_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("unknown mmc5 write: $%02X to $%04X\n", value, address); + nofrendo_log_printf("unknown mmc5 write: $%02X to $%04X\n", value, address); #endif /* NOFRENDO_DEBUG */ break; } @@ -218,7 +218,7 @@ static uint8 map5_read(uint32 address) else { #ifdef NOFRENDO_DEBUG - log_printf("invalid MMC5 read: $%04X", address); + nofrendo_log_printf("invalid MMC5 read: $%04X", address); #endif /* !NOFRENDO_DEBUG */ return 0xFF; } diff --git a/components/nofrendo/mappers/map024.c b/components/nofrendo/mappers/map024.c index f8e7512..388ba87 100644 --- a/components/nofrendo/mappers/map024.c +++ b/components/nofrendo/mappers/map024.c @@ -147,7 +147,7 @@ static void map24_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("invalid VRC6 write: $%02X to $%04X", value, address); + nofrendo_log_printf("invalid VRC6 write: $%02X to $%04X", value, address); #endif /* !NOFRENDO_DEBUG */ break; } diff --git a/components/nofrendo/mappers/map064.c b/components/nofrendo/mappers/map064.c index e6dc053..d7bda69 100644 --- a/components/nofrendo/mappers/map064.c +++ b/components/nofrendo/mappers/map064.c @@ -119,7 +119,7 @@ static void map64_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("mapper 64: unknown command #%d", command & 0xF); + nofrendo_log_printf("mapper 64: unknown command #%d", command & 0xF); #endif /* !NOFRENDO_DEBUG */ break; } @@ -153,7 +153,7 @@ static void map64_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("mapper 64: Wrote $%02X to $%04X", value, address); + nofrendo_log_printf("mapper 64: Wrote $%02X to $%04X", value, address); #endif /* !NOFRENDO_DEBUG */ break; } diff --git a/components/nofrendo/mappers/map085.c b/components/nofrendo/mappers/map085.c index d928efe..d9d8e7f 100644 --- a/components/nofrendo/mappers/map085.c +++ b/components/nofrendo/mappers/map085.c @@ -127,7 +127,7 @@ static void map85_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("unhandled vrc7 write: $%02X to $%04X\n", value, address); + nofrendo_log_printf("unhandled vrc7 write: $%02X to $%04X\n", value, address); #endif /* NOFRENDO_DEBUG */ break; } diff --git a/components/nofrendo/mappers/map160.c b/components/nofrendo/mappers/map160.c index c35085a..92b23a7 100644 --- a/components/nofrendo/mappers/map160.c +++ b/components/nofrendo/mappers/map160.c @@ -71,7 +71,7 @@ static void map160_write(uint32 address, uint8 value) #ifdef NOFRENDO_DEBUG else { - log_printf("mapper 160: untrapped write $%02X to $%04X\n", value, address); + nofrendo_log_printf("mapper 160: untrapped write $%02X to $%04X\n", value, address); } #endif /* NOFRENDO_DEBUG */ } diff --git a/components/nofrendo/mappers/mapvrc.c b/components/nofrendo/mappers/mapvrc.c index b009051..1a36801 100644 --- a/components/nofrendo/mappers/mapvrc.c +++ b/components/nofrendo/mappers/mapvrc.c @@ -151,7 +151,7 @@ static void map21_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("wrote $%02X to $%04X", value, address); + nofrendo_log_printf("wrote $%02X to $%04X", value, address); #endif /* !NOFRENDO_DEBUG */ break; } @@ -295,7 +295,7 @@ static void map23_write(uint32 address, uint8 value) default: #ifdef NOFRENDO_DEBUG - log_printf("wrote $%02X to $%04X",value,address); + nofrendo_log_printf("wrote $%02X to $%04X",value,address); #endif /* !NOFRENDO_DEBUG */ break; } diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 240976e..9a8183f 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -386,14 +386,14 @@ void mem_checkleaks(void) if (mem_blockcount) { - log_printf("memory leak - %d unfreed block%s\n\n", mem_blockcount, + nofrendo_log_printf("memory leak - %d unfreed block%s\n\n", mem_blockcount, mem_blockcount == 1 ? "" : "s"); for (i = 0; i < MAX_BLOCKS; i++) { if (mem_record[i].block_addr) { - log_printf("addr: 0x%08X, size: %d, line %d of %s%s\n", + nofrendo_log_printf("addr: 0x%08X, size: %d, line %d of %s%s\n", (uint32)mem_record[i].block_addr, mem_record[i].block_size, mem_record[i].line_num, @@ -405,7 +405,7 @@ void mem_checkleaks(void) } } else - log_printf("no memory leaks\n"); + nofrendo_log_printf("no memory leaks\n"); #endif /* NOFRENDO_DEBUG */ } @@ -423,7 +423,7 @@ void mem_checkblocks(void) { if (mem_checkguardblock(mem_record[i].block_addr, GUARD_LENGTH)) { - log_printf("addr: 0x%08X, size: %d, line %d of %s -- block corrupt\n", + nofrendo_log_printf("addr: 0x%08X, size: %d, line %d of %s -- block corrupt\n", (uint32)mem_record[i].block_addr, mem_record[i].block_size, mem_record[i].line_num, diff --git a/components/nofrendo/nes/nes_mmc.c b/components/nofrendo/nes/nes_mmc.c index d32d404..9b87ba4 100644 --- a/components/nofrendo/nes/nes_mmc.c +++ b/components/nofrendo/nes/nes_mmc.c @@ -102,7 +102,7 @@ void mmc_bankvrom(int size, uint32 address, int bank) break; default: - log_printf("invalid VROM bank size %d\n", size); + nofrendo_log_printf("invalid VROM bank size %d\n", size); } } @@ -153,7 +153,7 @@ void mmc_bankrom(int size, uint32 address, int bank) break; default: - log_printf("invalid ROM bank size %d\n", size); + nofrendo_log_printf("invalid ROM bank size %d\n", size); break; } @@ -177,7 +177,7 @@ bool mmc_peek(int map_num) static void mmc_setpages(void) { - log_printf("setting up mapper %d\n", mmc.intf->number); + nofrendo_log_printf("setting up mapper %d\n", mmc.intf->number); /* Switch ROM into CPU space, set VROM/VRAM (done for ALL ROMs) */ mmc_bankrom(16, 0x8000, 0); @@ -218,7 +218,7 @@ void mmc_reset(void) if (mmc.intf->init) mmc.intf->init(); - log_printf("reset memory mapper\n"); + nofrendo_log_printf("reset memory mapper\n"); } @@ -250,7 +250,7 @@ mmc_t *mmc_create(rominfo_t *rominfo) mmc_setcontext(temp); - log_printf("created memory mapper: %s\n", (*map_ptr)->name); + nofrendo_log_printf("created memory mapper: %s\n", (*map_ptr)->name); return temp; } diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index cff6147..3db7c5c 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -373,7 +373,7 @@ uint8 ppu_read(uint32 address) if ((ppu.bg_on || ppu.obj_on) && !ppu.vram_accessible) { ppu.vdata_latch = 0xFF; - // log_printf("VRAM read at $%04X, scanline %d\n", + // nofrendo_log_printf("VRAM read at $%04X, scanline %d\n", // ppu.vaddr, nes_getcontextptr()->scanline); } else @@ -486,7 +486,7 @@ void ppu_write(uint32 address, uint8 value) /* VRAM only accessible during scanlines 241-260 */ if ((ppu.bg_on || ppu.obj_on) && !ppu.vram_accessible) { - log_printf("VRAM write to $%04X, scanline %d\n", + nofrendo_log_printf("VRAM write to $%04X, scanline %d\n", ppu.vaddr, nes_getcontextptr()->scanline); PPU_MEM(ppu.vaddr) = 0xFF; /* corrupt */ } diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index b73760b..f186198 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -98,7 +98,7 @@ static void rom_savesram(rominfo_t *rominfo) { fwrite(rominfo->sram, SRAM_BANK_LENGTH, rominfo->sram_banks, fp); fclose(fp); - log_printf("Wrote battery RAM to %s.\n", fn); + nofrendo_log_printf("Wrote battery RAM to %s.\n", fn); } } } @@ -121,7 +121,7 @@ static void rom_loadsram(rominfo_t *rominfo) { fread(rominfo->sram, SRAM_BANK_LENGTH, rominfo->sram_banks, fp); fclose(fp); - log_printf("Read battery RAM from %s.\n", fn); + nofrendo_log_printf("Read battery RAM from %s.\n", fn); } } } @@ -151,7 +151,7 @@ static void rom_loadtrainer(FILE *fp, rominfo_t *rominfo) if (rominfo->flags & ROM_FLAG_TRAINER) { fread(rominfo->sram + TRAINER_OFFSET, TRAINER_LENGTH, 1, fp); - log_printf("Read in trainer at $7000\n"); + nofrendo_log_printf("Read in trainer at $7000\n"); } } @@ -225,7 +225,7 @@ static void rom_checkforpal(rominfo_t *rominfo) rominfo->flags |= ROM_FLAG_VERSUS; /* TODO: bad, BAD idea, calling nes_getcontextptr... */ // ppu_setpal(nes_getcontextptr()->ppu, vs_pal); - log_printf("Game specific palette found -- assuming VS. UniSystem\n"); + nofrendo_log_printf("Game specific palette found -- assuming VS. UniSystem\n"); } static FILE *rom_findrom(const char *filename, rominfo_t *rominfo) @@ -361,10 +361,10 @@ static int rom_getheader(FILE *fp, rominfo_t *rominfo) /* @!?#@! DiskDude. */ if (('D' == head.mapper_hinybble) && (0 == memcmp(head.reserved, "iskDude!", 8))) - log_printf("`DiskDude!' found in ROM header, ignoring high mapper nybble\n"); + nofrendo_log_printf("`DiskDude!' found in ROM header, ignoring high mapper nybble\n"); else { - log_printf("ROM header dirty, possible problem\n"); + nofrendo_log_printf("ROM header dirty, possible problem\n"); rominfo->mapper_number |= (head.mapper_hinybble & 0xF0); } @@ -502,7 +502,7 @@ void rom_nofrendo_free(rominfo_t **rominfo) { /* TODO: bad idea calling nes_getcontextptr... */ ppu_setdefaultpal(nes_getcontextptr()->ppu); - log_printf("Default NES palette restored\n"); + nofrendo_log_printf("Default NES palette restored\n"); } rom_savesram(*rominfo); diff --git a/components/nofrendo/nes/nesstate.c b/components/nofrendo/nes/nesstate.c index 000510c..c461172 100644 --- a/components/nofrendo/nes/nesstate.c +++ b/components/nofrendo/nes/nesstate.c @@ -100,7 +100,7 @@ static bool save_vramblock(nes_t *state, SNSS_FILE *snssFile) if (state->rominfo->vram_banks > 2) { - log_printf("too many VRAM banks: %d\n", state->rominfo->vram_banks); + nofrendo_log_printf("too many VRAM banks: %d\n", state->rominfo->vram_banks); return -1; } @@ -135,7 +135,7 @@ static int save_sramblock(nes_t *state, SNSS_FILE *snssFile) if (state->rominfo->sram_banks > 8) { - log_printf("Unsupported number of SRAM banks: %d\n", state->rominfo->sram_banks); + nofrendo_log_printf("Unsupported number of SRAM banks: %d\n", state->rominfo->sram_banks); return -1; } @@ -475,7 +475,7 @@ int state_load(void) case SNSS_UNKNOWN_BLOCK: default: - log_printf("unknown SNSS block type\n"); + nofrendo_log_printf("unknown SNSS block type\n"); break; } } diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index 3d769e3..d443176 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -164,7 +164,7 @@ static int internal_insert(const char *filename, system_t type) console.machine.nes = nes_create(); if (NULL == console.machine.nes) { - log_printf("Failed to create NES instance.\n"); + nofrendo_log_printf("Failed to create NES instance.\n"); return -1; } @@ -181,7 +181,7 @@ static int internal_insert(const char *filename, system_t type) case system_unknown: default: - log_printf("system type unknown, playing nofrendo NES intro.\n"); + nofrendo_log_printf("system type unknown, playing nofrendo NES intro.\n"); if (NULL != console.filename) nofrendo_free(console.filename); @@ -239,7 +239,7 @@ int main_loop(const char *filename, system_t type) osd_getvideoinfo(&video); if (vid_init(video.default_width, video.default_height, video.driver)) return -1; - log_printf("vid_init done\n"); + nofrendo_log_printf("vid_init done\n"); console.nextfilename = nofrendo_strdup(filename); console.nexttype = type; diff --git a/components/nofrendo/vid_drv.c b/components/nofrendo/vid_drv.c index ee4c33d..ea3538b 100644 --- a/components/nofrendo/vid_drv.c +++ b/components/nofrendo/vid_drv.c @@ -414,7 +414,7 @@ static int vid_findmode(int width, int height, viddriver_t *osd_driver) if (driver->free_write) driver->free_write(-1, NULL); - log_printf("video driver: %s at %dx%d\n", driver->name, + nofrendo_log_printf("video driver: %s at %dx%d\n", driver->name, screen->width, screen->height); return 0; @@ -425,7 +425,7 @@ int vid_init(int width, int height, viddriver_t *osd_driver) { if (vid_findmode(width, height, osd_driver)) { - log_printf("video initialization failed for %s at %dx%d\n", + nofrendo_log_printf("video initialization failed for %s at %dx%d\n", osd_driver->name, width, height); return -1; } diff --git a/main/controller.c b/main/controller.c index fca02fe..85fc162 100644 --- a/main/controller.c +++ b/main/controller.c @@ -271,11 +271,11 @@ void controller_init() psxDone(); if (t == 0 || t == 0xff) { - log_printf("No PSX/PS2 controller detected (0x%X). You will not be able to control the game.\n", t); + nofrendo_log_printf("No PSX/PS2 controller detected (0x%X). You will not be able to control the game.\n", t); } else { - log_printf("PSX controller type 0x%X\n", t); + nofrendo_log_printf("PSX controller type 0x%X\n", t); } } @@ -347,7 +347,7 @@ int controller_read_input() i2c_cmd_link_delete(cmd); if (ret == 0) { - log_printf("I2C read %d, return %d\n", data, ret); + nofrendo_log_printf("I2C read %d, return %d\n", data, ret); return 0xFFFF ^ ((((0x01 & data) > 0) << 4) | (((0x02 & data) > 0) << 6) | (((0x04 & data) > 0) << 7) | (((0x08 & data) > 0) << 5) | (((0x10 & data) > 0) << 0) | (((0x20 & data) > 0) << 3) | (((0x40 & data) > 0) << 13) | (((0x80 & data) > 0) << 14)); } @@ -412,7 +412,7 @@ int controller_read_input() i2c_cmd_link_delete(cmd); if ((ret == 0) && (data > 0)) { - log_printf("I2C read %d, return %d\n", data, ret); + nofrendo_log_printf("I2C read %d, return %d\n", data, ret); switch (data) { @@ -450,7 +450,7 @@ int controller_read_input() void controller_gpio_init() { - log_printf("GPIO controller disabled in menuconfig; no input enabled.\n"); + nofrendo_log_printf("GPIO controller disabled in menuconfig; no input enabled.\n"); } int controller_gpio_read_input() diff --git a/main/main.c b/main/main.c index 84b24c5..cbd15cd 100644 --- a/main/main.c +++ b/main/main.c @@ -29,15 +29,15 @@ void spiffs_init(void) { if (ret == ESP_FAIL) { - log_printf("Failed to mount or format filesystem"); + nofrendo_log_printf("Failed to mount or format filesystem"); } else if (ret == ESP_ERR_NOT_FOUND) { - log_printf("Failed to find SPIFFS partition"); + nofrendo_log_printf("Failed to find SPIFFS partition"); } else { - log_printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); + nofrendo_log_printf("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); } return; } @@ -46,11 +46,11 @@ void spiffs_init(void) ret = esp_spiffs_info(NULL, &total, &used); if (ret != ESP_OK) { - log_printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); + nofrendo_log_printf("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); } else { - log_printf("Partition size: total: %d, used: %d\n", total, used); + nofrendo_log_printf("Partition size: total: %d, used: %d\n", total, used); } } @@ -58,9 +58,9 @@ int app_main(void) { spiffs_init(); - log_printf("NoFrendo start!\n"); + nofrendo_log_printf("NoFrendo start!\n"); nofrendo_main(0, NULL); - log_printf("NoFrendo died? Oh no!\n"); + nofrendo_log_printf("NoFrendo died? Oh no!\n"); asm("break.n 1"); return 0; } diff --git a/main/video_audio.c b/main/video_audio.c index 97fb667..f4a8711 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -47,7 +47,7 @@ TimerHandle_t timer; //Seemingly, this will be called only once. Should call func with a freq of frequency, int osd_installtimer(int frequency, void *func, int funcsize, void *counter, int countersize) { - log_printf("Timer install, configTICK_RATE_HZ=%d, freq=%d\n", configTICK_RATE_HZ, frequency); + nofrendo_log_printf("Timer install, configTICK_RATE_HZ=%d, freq=%d\n", configTICK_RATE_HZ, frequency); timer = xTimerCreate("nes", configTICK_RATE_HZ / frequency, pdTRUE, NULL, func); xTimerStart(timer, 0); return 0; @@ -271,7 +271,7 @@ void osd_getinput(void) int x; oldb = b; event_t evh; - // log_printf("Input: %x\n", b); + // nofrendo_log_printf("Input: %x\n", b); for (x = 0; x < 16; x++) { if (chg & 1) From 9e8da96ab5be1a80fdb40fe584c19bd514147b6b Mon Sep 17 00:00:00 2001 From: moononournation Date: Sat, 10 Oct 2020 23:46:27 +0800 Subject: [PATCH 61/73] add fork version description --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index ca2a031..bab595d 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,8 @@ +Arduino Compatible Version +========================== + +This is a special fork version of esp32-nesemu aim for revise source code compatible to Arduino as much as possible. + ESP32-NESEMU, a Nintendo Entertainment System emulator for the ESP32 ==================================================================== From 6e77bf52b556c1adb522d96d00ffd582a960cea9 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 09:27:20 +0800 Subject: [PATCH 62/73] #include "noftypes.h" --- main/controller.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main/controller.c b/main/controller.c index 85fc162..c1548d5 100644 --- a/main/controller.c +++ b/main/controller.c @@ -28,6 +28,7 @@ #include #include +#include "noftypes.h" #include "sdkconfig.h" #if defined(CONFIG_HW_CONTROLLER_GPIO) From 2e0586dd29166d57f5d307e997f6ec1d2514b119 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 09:27:37 +0800 Subject: [PATCH 63/73] use heap_caps_malloc_prefer --- components/nofrendo/memguard.c | 2 +- components/nofrendo/nes/nes_rom.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 9a8183f..07c6afb 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -184,7 +184,7 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM); + mem_record = heap_caps_malloc_prefer(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index f186198..61bf05d 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -162,7 +162,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* Allocate ROM space, and load it up! */ // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); - rominfo->rom = heap_caps_malloc((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->rom = heap_caps_malloc_prefer((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); if (NULL == rominfo->rom) { gui_sendmsg(GUI_RED, "Could not allocate space for ROM image"); @@ -174,7 +174,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) if (rominfo->vrom_banks) { // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); - rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_DEFAULT); if (NULL == rominfo->vrom) { gui_sendmsg(GUI_RED, "Could not allocate space for VROM"); From acc8de024853059ad0dae70e1ae77230d5561cdb Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 09:50:21 +0800 Subject: [PATCH 64/73] use heap_caps_malloc_prefer --- components/nofrendo/memguard.c | 2 +- components/nofrendo/nes/nes_rom.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 9a8183f..07c6afb 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -184,7 +184,7 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM); + mem_record = heap_caps_malloc_prefer(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index f186198..afc07df 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -162,7 +162,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* Allocate ROM space, and load it up! */ // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); - rominfo->rom = heap_caps_malloc((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->rom = heap_caps_malloc_prefer((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); if (NULL == rominfo->rom) { gui_sendmsg(GUI_RED, "Could not allocate space for ROM image"); @@ -174,7 +174,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) if (rominfo->vrom_banks) { // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); - rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->vrom = heap_caps_malloc_prefer((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); if (NULL == rominfo->vrom) { gui_sendmsg(GUI_RED, "Could not allocate space for VROM"); From 10bafae12619935c3642ff5e40bc63ee25681891 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 09:59:52 +0800 Subject: [PATCH 65/73] use heap_caps_malloc_prefer --- components/nofrendo/memguard.c | 2 +- components/nofrendo/nes/nes_rom.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 9a8183f..07c6afb 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -184,7 +184,7 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM); + mem_record = heap_caps_malloc_prefer(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index f186198..afc07df 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -162,7 +162,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* Allocate ROM space, and load it up! */ // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); - rominfo->rom = heap_caps_malloc((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->rom = heap_caps_malloc_prefer((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); if (NULL == rominfo->rom) { gui_sendmsg(GUI_RED, "Could not allocate space for ROM image"); @@ -174,7 +174,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) if (rominfo->vrom_banks) { // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); - rominfo->vrom = heap_caps_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM); + rominfo->vrom = heap_caps_malloc_prefer((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); if (NULL == rominfo->vrom) { gui_sendmsg(GUI_RED, "Could not allocate space for VROM"); From 3660e54b4b056dccd003a07c8137daf68f55a834 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 11:16:22 +0800 Subject: [PATCH 66/73] debug MALLOC_CAP_8BIT free --- components/nofrendo/memguard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 07c6afb..0b2eefa 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -256,7 +256,7 @@ void *_my_nofrendo_malloc(int size, char *file, int line) // temp = malloc(size); temp = heap_caps_malloc(size, MALLOC_CAP_8BIT); - printf("Malloc: %d at %s:%d\n", size, file, line); + nofrendo_log_printf("MALLOC_CAP_8BIT free: %d, malloc: %d at %s:%d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT), size, file, line); if (NULL == temp) { sprintf(fail, "malloc: out of memory at line %d of %s. block size: %d\n", From 1e9a80fedb455203b20077b9daf05705b8d0e049 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 11:45:51 +0800 Subject: [PATCH 67/73] Create FUNDING.yml --- .github/FUNDING.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ea43558 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: moononournation +custom: "https://paypal.me/moononournation" From dd989f849d723679d960092e5544e1a027f7d3a6 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 18:49:29 +0800 Subject: [PATCH 68/73] remove NES_VISIBLE_* --- components/nofrendo/nes/nes.c | 4 ++-- components/nofrendo/nes/nes_ppu.c | 2 +- components/nofrendo/nofrendo.c | 2 +- components/nofrendo/noftypes.h | 2 -- main/video_audio.c | 12 ++++++------ 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/components/nofrendo/nes/nes.c b/components/nofrendo/nes/nes.c index 9ad05fc..383446b 100644 --- a/components/nofrendo/nes/nes.c +++ b/components/nofrendo/nes/nes.c @@ -344,8 +344,8 @@ static void system_video(bool draw) } /* blit the NES screen to our video surface */ -// vid_blit(nes.vidbuf, 0, (NES_SCREEN_HEIGHT - NES_VISIBLE_HEIGHT) / 2, -// 0, 0, NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT); +// vid_blit(nes.vidbuf, 0, (NES_SCREEN_HEIGHT - NES_SCREEN_HEIGHT) / 2, +// 0, 0, NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT); /* overlay our GUI on top of it */ gui_frame(true); diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 3db7c5c..4a1ea10 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -1082,7 +1082,7 @@ void ppu_checknmi(void) void ppu_scanline(bitmap_t *bmp, int scanline, bool draw_flag) { // if (scanline < 240) - if (scanline < NES_VISIBLE_HEIGHT) + if (scanline < NES_SCREEN_HEIGHT) { /* Lower the Max Sprite per scanline flag */ ppu.stat &= ~PPU_STATF_MAXSPRITE; diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index d443176..d90460c 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -171,7 +171,7 @@ static int internal_insert(const char *filename, system_t type) if (nes_insertcart(console.filename, console.machine.nes)) return -1; - vid_setmode(NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT); + vid_setmode(NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT); if (install_timer(NES_REFRESH_RATE)) return -1; diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 966427f..7cfc498 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -29,8 +29,6 @@ #include #define NOFRENDO_DEBUG -#define NES_VISIBLE_WIDTH 256 -#define NES_VISIBLE_HEIGHT 240 /* Define this if running on little-endian (x86) systems */ #define HOST_LITTLE_ENDIAN diff --git a/main/video_audio.c b/main/video_audio.c index f4a8711..3013b58 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -167,8 +167,8 @@ bitmap_t *myBitmap; void osd_getvideoinfo(vidinfo_t *info) { - info->default_width = NES_VISIBLE_WIDTH; - info->default_height = NES_VISIBLE_HEIGHT; + info->default_width = NES_SCREEN_WIDTH; + info->default_height = NES_SCREEN_HEIGHT; info->driver = &sdlDriver; } @@ -220,7 +220,7 @@ static void clear(uint8 color) static bitmap_t *lock_write(void) { // SDL_LockSurface(mySurface); - myBitmap = bmp_createhw((uint8 *)fb, NES_VISIBLE_WIDTH, NES_VISIBLE_HEIGHT, NES_VISIBLE_WIDTH * 2); + myBitmap = bmp_createhw((uint8 *)fb, NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, NES_SCREEN_WIDTH * 2); return myBitmap; } @@ -241,13 +241,13 @@ static void videoTask(void *arg) { int x, y; bitmap_t *bmp = NULL; - x = (320 - NES_VISIBLE_WIDTH) / 2; - y = ((240 - NES_VISIBLE_HEIGHT) / 2); + x = (320 - NES_SCREEN_WIDTH) / 2; + y = ((240 - NES_SCREEN_HEIGHT) / 2); while (1) { // xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30 xQueueReceive(vidQueue, &bmp, portMAX_DELAY); - lcd_write_frame(x, y, NES_VISIBLE_WIDTH, NES_VISIBLE_HEIGHT, (const uint8_t **)bmp->line); + lcd_write_frame(x, y, NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, (const uint8_t **)bmp->line); } } From 694de70ececc43dc1d070ad9cb53bca625b6bd67 Mon Sep 17 00:00:00 2001 From: moononournation Date: Mon, 12 Oct 2020 18:51:27 +0800 Subject: [PATCH 69/73] NOFRENDO_MEM_DEBUG --- components/nofrendo/memguard.c | 2 +- components/nofrendo/noftypes.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index 0b2eefa..b23d855 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -47,7 +47,7 @@ typedef struct memblock_s } memblock_t; /* debugging flag */ -bool mem_debug = true; +bool mem_debug = NOFRENDO_MEM_DEBUG; #ifdef NOFRENDO_DEBUG diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 7cfc498..5801a0d 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -29,6 +29,7 @@ #include #define NOFRENDO_DEBUG +#define NOFRENDO_MEM_DEBUG true /* Define this if running on little-endian (x86) systems */ #define HOST_LITTLE_ENDIAN From 81c679bdb443686a82e82592f1a827033962bd1a Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 20 Oct 2020 17:52:25 +0800 Subject: [PATCH 70/73] fix name --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3281d01..6283749 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # project subdirectory. # -PROJECT_NAME := nesemu +PROJECT_NAME := esp32-nesemu include $(IDF_PATH)/make/project.mk From 48437160d53cc812d33810af9c107b25560d62b4 Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 20 Oct 2020 17:52:43 +0800 Subject: [PATCH 71/73] fix config name --- sdkconfig.defaults | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 07cdfe3..2f3da83 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -7,5 +7,5 @@ CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 CONFIG_ESP32_SPIRAM_SUPPORT=y CONFIG_SPIRAM_BOOT_INIT=y CONFIG_SPIRAM_IGNORE_NOTFOUND=y -CONFIG_TASK_WDT= +CONFIG_ESP_TASK_WDT=n CONFIG_FREERTOS_HZ=1000 From d71496343a5e3e9c954726399ce6c4cecd5bee8e Mon Sep 17 00:00:00 2001 From: moononournation Date: Tue, 20 Oct 2020 17:55:25 +0800 Subject: [PATCH 72/73] decouple ESP32 function --- components/nofrendo/memguard.c | 12 +++++------- components/nofrendo/nes/nes_rom.c | 6 ++---- components/nofrendo/noftypes.h | 2 ++ main/main.c | 13 +++++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index b23d855..d3e0eeb 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -28,8 +28,6 @@ #include #include -#include - #include "noftypes.h" #include "memguard.h" #include "log.h" @@ -122,7 +120,7 @@ static void *mem_guardalloc(int alloc_size, int guard_size) /* allocate memory */ // orig = malloc(alloc_size + (guard_size * 2)); - orig = heap_caps_malloc(alloc_size + (guard_size * 2), MALLOC_CAP_8BIT); + orig = mem_alloc(alloc_size + (guard_size * 2), true); if (NULL == orig) return NULL; @@ -184,7 +182,7 @@ static void mem_init(void) mem_blockcount = 0; // mem_record = malloc(MAX_BLOCKS * sizeof(memblock_t)); - mem_record = heap_caps_malloc_prefer(MAX_BLOCKS * sizeof(memblock_t), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); + mem_record = mem_alloc(MAX_BLOCKS * sizeof(memblock_t), false); ASSERT(mem_record); memset(mem_record, 0, MAX_BLOCKS * sizeof(memblock_t)); @@ -254,9 +252,9 @@ void *_my_nofrendo_malloc(int size, char *file, int line) temp = mem_guardalloc(size, GUARD_LENGTH); else // temp = malloc(size); - temp = heap_caps_malloc(size, MALLOC_CAP_8BIT); + temp = mem_alloc(size, true); - nofrendo_log_printf("MALLOC_CAP_8BIT free: %d, malloc: %d at %s:%d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT), size, file, line); + nofrendo_log_printf("MALLOC_CAP_8BIT malloc: %d at %s:%d\n", size, file, line); if (NULL == temp) { sprintf(fail, "malloc: out of memory at line %d of %s. block size: %d\n", @@ -330,7 +328,7 @@ void *_my_nofrendo_malloc(int size) char fail[256]; // temp = malloc(size); - temp = heap_caps_malloc(size, MALLOC_CAP_8BIT); + temp = mem_alloc(size, true); if (NULL == temp) { diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index afc07df..e2b70a4 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -28,8 +28,6 @@ #include #include -#include - #include "../noftypes.h" #include "nes_rom.h" #include "../intro.h" @@ -162,7 +160,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* Allocate ROM space, and load it up! */ // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); - rominfo->rom = heap_caps_malloc_prefer((rominfo->rom_banks * ROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); + rominfo->rom = mem_alloc(rominfo->rom_banks * ROM_BANK_LENGTH, false); if (NULL == rominfo->rom) { gui_sendmsg(GUI_RED, "Could not allocate space for ROM image"); @@ -174,7 +172,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) if (rominfo->vrom_banks) { // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); - rominfo->vrom = heap_caps_malloc_prefer((rominfo->vrom_banks * VROM_BANK_LENGTH), MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); + rominfo->vrom = mem_alloc(rominfo->vrom_banks * VROM_BANK_LENGTH, false); if (NULL == rominfo->vrom) { gui_sendmsg(GUI_RED, "Could not allocate space for VROM"); diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index 5801a0d..a50f44f 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -70,6 +70,8 @@ typedef unsigned int uint32; #endif /* !NOFRENDO_DEBUG */ +extern void *mem_alloc(int size, bool speedy); + #endif /* _NOFTYPES_H_ */ /* diff --git a/main/main.c b/main/main.c index cbd15cd..b42e38d 100644 --- a/main/main.c +++ b/main/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,18 @@ #include "nofconfig.h" #include "nofrendo.h" +void *mem_alloc(int size, bool fast_mem) +{ + if (fast_mem) + { + return heap_caps_malloc(size, MALLOC_CAP_8BIT); + } + else + { + return heap_caps_malloc_prefer(size, MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT); + } +} + void spiffs_init(void) { esp_vfs_spiffs_conf_t conf = { From 9661648ededfd79f2bee41448d14bcbae1f1c8e4 Mon Sep 17 00:00:00 2001 From: moononournation Date: Wed, 21 Oct 2020 23:47:46 +0800 Subject: [PATCH 73/73] #define to ALLCAPS --- components/nofrendo/bitmap.c | 8 +++---- components/nofrendo/config.c | 32 +++++++++++++-------------- components/nofrendo/intro.c | 4 ++-- components/nofrendo/libsnss/libsnss.c | 16 +++++++------- components/nofrendo/memguard.c | 16 +++++++------- components/nofrendo/memguard.h | 27 +++++++++++----------- components/nofrendo/nes/nes.c | 14 ++++++------ components/nofrendo/nes/nes_mmc.c | 4 ++-- components/nofrendo/nes/nes_ppu.c | 4 ++-- components/nofrendo/nes/nes_rom.c | 24 ++++++++++---------- components/nofrendo/nes/nes_rom.h | 2 +- components/nofrendo/nofconfig.h | 5 +---- components/nofrendo/nofrendo.c | 18 +++++++-------- components/nofrendo/noftypes.h | 2 -- components/nofrendo/sndhrdw/nes_apu.c | 4 ++-- main/config.h | 7 ++++++ main/main.c | 1 + main/osd.c | 1 + main/video_audio.c | 2 +- 19 files changed, 98 insertions(+), 93 deletions(-) create mode 100644 main/config.h diff --git a/components/nofrendo/bitmap.c b/components/nofrendo/bitmap.c index 46f7fb9..97d44ad 100644 --- a/components/nofrendo/bitmap.c +++ b/components/nofrendo/bitmap.c @@ -45,7 +45,7 @@ static bitmap_t *_make_bitmap(uint8 *data_addr, bool hw, int width, return NULL; /* Make sure to add in space for line pointers */ - bitmap = nofrendo_malloc(sizeof(bitmap_t) + (sizeof(uint8 *) * height)); + bitmap = NOFRENDO_MALLOC(sizeof(bitmap_t) + (sizeof(uint8 *) * height)); if (NULL == bitmap) return NULL; @@ -82,7 +82,7 @@ bitmap_t *bmp_create(int width, int height, int overdraw) int pitch; pitch = width + (overdraw * 2); /* left and right */ - addr = nofrendo_malloc((pitch * height) + 3); /* add max 32-bit aligned adjustment */ + addr = NOFRENDO_MALLOC((pitch * height) + 3); /* add max 32-bit aligned adjustment */ if (NULL == addr) return NULL; @@ -101,8 +101,8 @@ void bmp_destroy(bitmap_t **bitmap) if (*bitmap) { if ((*bitmap)->data && false == (*bitmap)->hardware) - nofrendo_free((*bitmap)->data); - nofrendo_free(*bitmap); + NOFRENDO_FREE((*bitmap)->data); + NOFRENDO_FREE(*bitmap); *bitmap = NULL; } } diff --git a/components/nofrendo/config.c b/components/nofrendo/config.c index 5d31e62..29a5307 100644 --- a/components/nofrendo/config.c +++ b/components/nofrendo/config.c @@ -29,19 +29,19 @@ static void my_destroy(myvar_t **var) ASSERT(*var); if ((*var)->group) - nofrendo_free((*var)->group); + NOFRENDO_FREE((*var)->group); if ((*var)->key) - nofrendo_free((*var)->key); + NOFRENDO_FREE((*var)->key); if ((*var)->value) - nofrendo_free((*var)->value); - nofrendo_free(*var); + NOFRENDO_FREE((*var)->value); + NOFRENDO_FREE(*var); } static myvar_t *my_create(const char *group, const char *key, const char *value) { myvar_t *var; - var = nofrendo_malloc(sizeof(*var)); + var = NOFRENDO_MALLOC(sizeof(*var)); if (NULL == var) { return 0; @@ -50,9 +50,9 @@ static myvar_t *my_create(const char *group, const char *key, const char *value) var->less = var->greater = NULL; var->group = var->key = var->value = NULL; - if ((var->group = nofrendo_malloc(strlen(group) + 1)) - && (var->key = nofrendo_malloc(strlen(key) + 1)) - && (var->value = nofrendo_malloc(strlen(value) + 1))) + if ((var->group = NOFRENDO_MALLOC(strlen(group) + 1)) + && (var->key = NOFRENDO_MALLOC(strlen(key) + 1)) + && (var->value = NOFRENDO_MALLOC(strlen(value) + 1))) { strcpy(var->group, group); strcpy(var->key, key); @@ -146,13 +146,13 @@ static char *my_getline(FILE *stream) if (NULL == (fgets(buf, sizeof(buf), stream))) { if (dynamic) - nofrendo_free(dynamic); + NOFRENDO_FREE(dynamic); return 0; } if (NULL == dynamic) { - dynamic = nofrendo_malloc(strlen(buf) + 1); + dynamic = NOFRENDO_MALLOC(strlen(buf) + 1); if (NULL == dynamic) { return 0; @@ -163,12 +163,12 @@ static char *my_getline(FILE *stream) { /* a mini-version of realloc that works with our memory manager */ char *temp = NULL; - temp = nofrendo_malloc(strlen(dynamic) + strlen(buf) + 1); + temp = NOFRENDO_MALLOC(strlen(dynamic) + strlen(buf) + 1); if (NULL == temp) return 0; strcpy(temp, dynamic); - nofrendo_free(dynamic); + NOFRENDO_FREE(dynamic); dynamic = temp; strcat(dynamic, buf); @@ -220,7 +220,7 @@ static int load_config(char *filename) case '[': if (group) - nofrendo_free(group); + NOFRENDO_FREE(group); group = ++s; @@ -235,7 +235,7 @@ static int load_config(char *filename) *s++ = '\0'; } - if ((value = nofrendo_malloc(strlen(group) + 1))) + if ((value = NOFRENDO_MALLOC(strlen(group) + 1))) { strcpy(value, group); } @@ -278,11 +278,11 @@ static int load_config(char *filename) } } while (*s); - nofrendo_free(line); + NOFRENDO_FREE(line); } if (group) - nofrendo_free(group); + NOFRENDO_FREE(group); fclose(config_file); } diff --git a/components/nofrendo/intro.c b/components/nofrendo/intro.c index 2d219cb..ee72189 100644 --- a/components/nofrendo/intro.c +++ b/components/nofrendo/intro.c @@ -327,7 +327,7 @@ static uint8 *intro_getrom(void) { uint8 *rom; - rom = nofrendo_malloc(CODE_SIZE); + rom = NOFRENDO_MALLOC(CODE_SIZE); if (NULL != rom) { /* good measure */ @@ -347,7 +347,7 @@ static uint8 *intro_getvrom(void) { uint8 *vrom; - vrom = nofrendo_malloc(VROM_SIZE); + vrom = NOFRENDO_MALLOC(VROM_SIZE); if (NULL != vrom) { memcpy(vrom, intro_vrom, sizeof(intro_vrom)); diff --git a/components/nofrendo/libsnss/libsnss.c b/components/nofrendo/libsnss/libsnss.c index 9eeb06f..d58a28e 100644 --- a/components/nofrendo/libsnss/libsnss.c +++ b/components/nofrendo/libsnss/libsnss.c @@ -204,7 +204,7 @@ SNSS_WriteFileHeader(SNSS_FILE *snssFile) SNSS_RETURN_CODE SNSS_OpenFile(SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) { - *snssFile = nofrendo_malloc(sizeof(SNSS_FILE)); + *snssFile = NOFRENDO_MALLOC(sizeof(SNSS_FILE)); if (NULL == *snssFile) { return SNSS_OUT_OF_MEMORY; @@ -227,7 +227,7 @@ SNSS_OpenFile(SNSS_FILE **snssFile, const char *filename, SNSS_OPEN_MODE mode) if (NULL == (*snssFile)->fp) { - nofrendo_free(*snssFile); + NOFRENDO_FREE(*snssFile); *snssFile = NULL; return SNSS_OPEN_FAILED; } @@ -275,7 +275,7 @@ SNSS_CloseFile(SNSS_FILE **snssFile) return SNSS_CLOSE_FAILED; } - nofrendo_free(*snssFile); + NOFRENDO_FREE(*snssFile); *snssFile = NULL; return SNSS_OK; @@ -369,7 +369,7 @@ SNSS_SkipNextBlock(SNSS_FILE *snssFile) static SNSS_RETURN_CODE SNSS_ReadBaseBlock(SNSS_FILE *snssFile) { - char *blockBytes = nofrendo_malloc(BASE_BLOCK_LENGTH); + char *blockBytes = NOFRENDO_MALLOC(BASE_BLOCK_LENGTH); SnssBlockHeader header; if (SNSS_ReadBlockHeader(&header, snssFile) != SNSS_OK) @@ -411,7 +411,7 @@ SNSS_WriteBaseBlock(SNSS_FILE *snssFile) { SnssBlockHeader header; SNSS_RETURN_CODE returnCode; - char *blockBytes = nofrendo_malloc(BASE_BLOCK_LENGTH); + char *blockBytes = NOFRENDO_MALLOC(BASE_BLOCK_LENGTH); unsigned short tempShort; strcpy(header.tag, "BASR"); @@ -584,14 +584,14 @@ SNSS_ReadMapperBlock(SNSS_FILE *snssFile) return SNSS_READ_FAILED; } - if ((blockBytes = (char *)nofrendo_malloc(0x8 + 0x10 + 0x80)) == NULL) + if ((blockBytes = (char *)NOFRENDO_MALLOC(0x8 + 0x10 + 0x80)) == NULL) { return SNSS_OUT_OF_MEMORY; } if (fread(blockBytes, MIN(0x8 + 0x10 + 0x80, header.blockLength), 1, snssFile->fp) != 1) { - nofrendo_free(blockBytes); + NOFRENDO_FREE(blockBytes); return SNSS_READ_FAILED; } @@ -609,7 +609,7 @@ SNSS_ReadMapperBlock(SNSS_FILE *snssFile) memcpy(&snssFile->mapperBlock.extraData.mapperData, &blockBytes[0x18], 0x80); - nofrendo_free(blockBytes); + NOFRENDO_FREE(blockBytes); return SNSS_OK; } diff --git a/components/nofrendo/memguard.c b/components/nofrendo/memguard.c index d3e0eeb..3a5dace 100644 --- a/components/nofrendo/memguard.c +++ b/components/nofrendo/memguard.c @@ -240,7 +240,7 @@ static void mem_deleteblock(void *data, char *file, int line) #ifdef NOFRENDO_DEBUG /* allocates memory and clears it */ -void *_my_nofrendo_malloc(int size, char *file, int line) +void *_my_malloc(int size, char *file, int line) { void *temp; char fail[256]; @@ -271,7 +271,7 @@ void *_my_nofrendo_malloc(int size, char *file, int line) } /* free a pointer allocated with my_malloc */ -void _my_nofrendo_free(void **data, char *file, int line) +void _my_free(void **data, char *file, int line) { char fail[256]; @@ -303,14 +303,14 @@ void _my_nofrendo_free(void **data, char *file, int line) *data = NULL; /* NULL our source */ } -char *_my_nofrendo_strdup(const char *string, char *file, int line) +char *_my_strdup(const char *string, char *file, int line) { char *temp; if (NULL == string) return NULL; - temp = (char *)_my_nofrendo_malloc(strlen(string) + 1, file, line); + temp = (char *)_my_malloc(strlen(string) + 1, file, line); if (NULL == temp) return NULL; @@ -322,7 +322,7 @@ char *_my_nofrendo_strdup(const char *string, char *file, int line) #else /* !NOFRENDO_DEBUG */ /* allocates memory and clears it */ -void *_my_nofrendo_malloc(int size) +void *_my_malloc(int size) { void *temp; char fail[256]; @@ -340,7 +340,7 @@ void *_my_nofrendo_malloc(int size) } /* free a pointer allocated with my_malloc */ -void _my_nofrendo_free(void **data) +void _my_free(void **data) { char fail[256]; @@ -354,7 +354,7 @@ void _my_nofrendo_free(void **data) *data = NULL; /* NULL our source */ } -char *_my_nofrendo_strdup(const char *string) +char *_my_strdup(const char *string) { char *temp; @@ -362,7 +362,7 @@ char *_my_nofrendo_strdup(const char *string) return NULL; /* will ASSERT for us */ - temp = (char *)_my_nofrendo_malloc(strlen(string) + 1); + temp = (char *)_my_malloc(strlen(string) + 1); if (NULL == temp) return NULL; diff --git a/components/nofrendo/memguard.h b/components/nofrendo/memguard.h index 33e3e86..294e8bb 100644 --- a/components/nofrendo/memguard.h +++ b/components/nofrendo/memguard.h @@ -30,34 +30,35 @@ #ifdef NOFRENDO_DEBUG -#define nofrendo_malloc(s) _my_nofrendo_malloc((s), __FILE__, __LINE__) -#define nofrendo_free(d) _my_nofrendo_free((void **) &(d), __FILE__, __LINE__) -#define nofrendo_strdup(s) _my_nofrendo_strdup((s), __FILE__, __LINE__) +#define NOFRENDO_MALLOC(s) _my_malloc((s), __FILE__, __LINE__) +#define NOFRENDO_FREE(d) _my_free((void **) &(d), __FILE__, __LINE__) +#define NOFRENDO_STRDUP(s) _my_strdup((s), __FILE__, __LINE__) -extern void *_my_nofrendo_malloc(int size, char *file, int line); -extern void _my_nofrendo_free(void **data, char *file, int line); -extern char *_my_nofrendo_strdup(const char *string, char *file, int line); +extern void *_my_malloc(int size, char *file, int line); +extern void _my_free(void **data, char *file, int line); +extern char *_my_strdup(const char *string, char *file, int line); #else /* !NOFRENDO_DEBUG */ /* Non-debugging versions of calls */ -#define nofrendo_malloc(s) _my_nofrendo_malloc((s)) -#define nofrendo_free(d) _my_nofrendo_free((void **) &(d)) -#define nofrendo_strdup(s) _my_nofrendo_strdup((s)) +#define NOFRENDO_MALLOC(s) _my_malloc((s)) +#define NOFRENDO_FREE(d) _my_free((void **) &(d)) +#define NOFRENDO_STRDUP(s) _my_strdup((s)) -extern void *_my_nofrendo_malloc(int size); -extern void _my_nofrendo_free(void **data); -extern char *_my_nofrendo_strdup(const char *string); +extern void *_my_malloc(int size); +extern void _my_free(void **data); +extern char *_my_strdup(const char *string); #endif /* !NOFRENDO_DEBUG */ - extern void mem_cleanup(void); extern void mem_checkblocks(void); extern void mem_checkleaks(void); extern bool mem_debug; +extern void *mem_alloc(int size, bool prefer_fast_memory); + #endif /* _MEMGUARD_H_ */ /* diff --git a/components/nofrendo/nes/nes.c b/components/nofrendo/nes/nes.c index 383446b..aaa063a 100644 --- a/components/nofrendo/nes/nes.c +++ b/components/nofrendo/nes/nes.c @@ -435,7 +435,7 @@ void nes_destroy(nes_t **machine) { if (*machine) { - rom_nofrendo_free(&(*machine)->rominfo); + rom_free(&(*machine)->rominfo); mmc_destroy(&(*machine)->mmc); ppu_destroy(&(*machine)->ppu); apu_destroy(&(*machine)->apu); @@ -443,11 +443,11 @@ void nes_destroy(nes_t **machine) if ((*machine)->cpu) { if ((*machine)->cpu->mem_page[0]) - nofrendo_free((*machine)->cpu->mem_page[0]); - nofrendo_free((*machine)->cpu); + NOFRENDO_FREE((*machine)->cpu->mem_page[0]); + NOFRENDO_FREE((*machine)->cpu); } - nofrendo_free(*machine); + NOFRENDO_FREE(*machine); *machine = NULL; } } @@ -510,7 +510,7 @@ nes_t *nes_create(void) sndinfo_t osd_sound; int i; - machine = nofrendo_malloc(sizeof(nes_t)); + machine = NOFRENDO_MALLOC(sizeof(nes_t)); if (NULL == machine) return NULL; @@ -525,14 +525,14 @@ nes_t *nes_create(void) machine->autoframeskip = true; /* cpu */ - machine->cpu = nofrendo_malloc(sizeof(nes6502_context)); + machine->cpu = NOFRENDO_MALLOC(sizeof(nes6502_context)); if (NULL == machine->cpu) goto _fail; memset(machine->cpu, 0, sizeof(nes6502_context)); /* allocate 2kB RAM */ - machine->cpu->mem_page[0] = nofrendo_malloc(NES_RAMSIZE); + machine->cpu->mem_page[0] = NOFRENDO_MALLOC(NES_RAMSIZE); if (NULL == machine->cpu->mem_page[0]) goto _fail; diff --git a/components/nofrendo/nes/nes_mmc.c b/components/nofrendo/nes/nes_mmc.c index 9b87ba4..92e2f7c 100644 --- a/components/nofrendo/nes/nes_mmc.c +++ b/components/nofrendo/nes/nes_mmc.c @@ -225,7 +225,7 @@ void mmc_reset(void) void mmc_destroy(mmc_t **nes_mmc) { if (*nes_mmc) - nofrendo_free(*nes_mmc); + NOFRENDO_FREE(*nes_mmc); } mmc_t *mmc_create(rominfo_t *rominfo) @@ -239,7 +239,7 @@ mmc_t *mmc_create(rominfo_t *rominfo) return NULL; /* Should *never* happen */ } - temp = nofrendo_malloc(sizeof(mmc_t)); + temp = NOFRENDO_MALLOC(sizeof(mmc_t)); if (NULL == temp) return NULL; diff --git a/components/nofrendo/nes/nes_ppu.c b/components/nofrendo/nes/nes_ppu.c index 4a1ea10..8ed0590 100644 --- a/components/nofrendo/nes/nes_ppu.c +++ b/components/nofrendo/nes/nes_ppu.c @@ -126,7 +126,7 @@ ppu_t *ppu_create(void) static bool pal_generated = false; ppu_t *temp; - temp = nofrendo_malloc(sizeof(ppu_t)); + temp = NOFRENDO_MALLOC(sizeof(ppu_t)); if (NULL == temp) return NULL; @@ -153,7 +153,7 @@ void ppu_destroy(ppu_t **src_ppu) { if (*src_ppu) { - nofrendo_free(*src_ppu); + NOFRENDO_FREE(*src_ppu); *src_ppu = NULL; } } diff --git a/components/nofrendo/nes/nes_rom.c b/components/nofrendo/nes/nes_rom.c index e2b70a4..c482860 100644 --- a/components/nofrendo/nes/nes_rom.c +++ b/components/nofrendo/nes/nes_rom.c @@ -128,7 +128,7 @@ static void rom_loadsram(rominfo_t *rominfo) static int rom_allocsram(rominfo_t *rominfo) { /* Load up SRAM */ - rominfo->sram = nofrendo_malloc(SRAM_BANK_LENGTH * rominfo->sram_banks); + rominfo->sram = NOFRENDO_MALLOC(SRAM_BANK_LENGTH * rominfo->sram_banks); if (NULL == rominfo->sram) { gui_sendmsg(GUI_RED, "Could not allocate space for battery RAM"); @@ -159,7 +159,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) ASSERT(rominfo); /* Allocate ROM space, and load it up! */ - // rominfo->rom = nofrendo_malloc((rominfo->rom_banks * ROM_BANK_LENGTH)); + // rominfo->rom = malloc(rominfo->rom_banks * ROM_BANK_LENGTH); rominfo->rom = mem_alloc(rominfo->rom_banks * ROM_BANK_LENGTH, false); if (NULL == rominfo->rom) { @@ -171,7 +171,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) /* If there's VROM, allocate and stuff it in */ if (rominfo->vrom_banks) { - // rominfo->vrom = nofrendo_malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); + // rominfo->vrom = malloc((rominfo->vrom_banks * VROM_BANK_LENGTH)); rominfo->vrom = mem_alloc(rominfo->vrom_banks * VROM_BANK_LENGTH, false); if (NULL == rominfo->vrom) { @@ -182,7 +182,7 @@ static int rom_loadrom(FILE *fp, rominfo_t *rominfo) } else { - rominfo->vram = nofrendo_malloc(VRAM_LENGTH); + rominfo->vram = NOFRENDO_MALLOC(VRAM_LENGTH); if (NULL == rominfo->vram) { gui_sendmsg(GUI_RED, "Could not allocate space for VRAM"); @@ -424,7 +424,7 @@ rominfo_t *rom_load(const char *filename) FILE *fp; rominfo_t *rominfo; - rominfo = nofrendo_malloc(sizeof(rominfo_t)); + rominfo = NOFRENDO_MALLOC(sizeof(rominfo_t)); if (NULL == rominfo) return NULL; @@ -482,12 +482,12 @@ rominfo_t *rom_load(const char *filename) _fail: if (NULL != fp) _fclose(fp); - rom_nofrendo_free(&rominfo); + rom_free(&rominfo); return NULL; } /* Free a ROM */ -void rom_nofrendo_free(rominfo_t **rominfo) +void rom_free(rominfo_t **rominfo) { if (NULL == *rominfo) { @@ -506,15 +506,15 @@ void rom_nofrendo_free(rominfo_t **rominfo) rom_savesram(*rominfo); if ((*rominfo)->sram) - nofrendo_free((*rominfo)->sram); + NOFRENDO_FREE((*rominfo)->sram); if ((*rominfo)->rom) - nofrendo_free((*rominfo)->rom); + NOFRENDO_FREE((*rominfo)->rom); if ((*rominfo)->vrom) - nofrendo_free((*rominfo)->vrom); + NOFRENDO_FREE((*rominfo)->vrom); if ((*rominfo)->vram) - nofrendo_free((*rominfo)->vram); + NOFRENDO_FREE((*rominfo)->vram); - nofrendo_free(*rominfo); + NOFRENDO_FREE(*rominfo); gui_sendmsg(GUI_GREEN, "ROM freed"); } diff --git a/components/nofrendo/nes/nes_rom.h b/components/nofrendo/nes/nes_rom.h index 6fdb74d..dad1f97 100644 --- a/components/nofrendo/nes/nes_rom.h +++ b/components/nofrendo/nes/nes_rom.h @@ -64,7 +64,7 @@ typedef struct rominfo_s extern int rom_checkmagic(const char *filename); extern rominfo_t *rom_load(const char *filename); -extern void rom_nofrendo_free(rominfo_t **rominfo); +extern void rom_free(rominfo_t **rominfo); extern char *rom_getinfo(rominfo_t *rominfo); diff --git a/components/nofrendo/nofconfig.h b/components/nofrendo/nofconfig.h index 50ac385..dcb44e6 100644 --- a/components/nofrendo/nofconfig.h +++ b/components/nofrendo/nofconfig.h @@ -12,9 +12,6 @@ #define CONFIG_FILE "nofrendo.cfg" #endif -#define FSROOT "/spiffs" -#define ROM_FILE FSROOT "/rom.nes" - #include "noftypes.h" typedef struct config_s @@ -52,7 +49,7 @@ typedef struct config_s extern config_t config; -#endif /* !_CONFIG_H_ */ +#endif /* _NOFCONFIG_H_ */ /* ** $Log: nofconfig.h,v $ diff --git a/components/nofrendo/nofrendo.c b/components/nofrendo/nofrendo.c index d90460c..cc369bf 100644 --- a/components/nofrendo/nofrendo.c +++ b/components/nofrendo/nofrendo.c @@ -68,12 +68,12 @@ static void shutdown_everything(void) { if (console.filename) { - nofrendo_free(console.filename); + NOFRENDO_FREE(console.filename); console.filename = NULL; } if (console.nextfilename) { - nofrendo_free(console.nextfilename); + NOFRENDO_FREE(console.nextfilename); console.nextfilename = NULL; } @@ -100,7 +100,7 @@ void main_eject(void) if (NULL != console.filename) { - nofrendo_free(console.filename); + NOFRENDO_FREE(console.filename); console.filename = NULL; } console.type = system_unknown; @@ -116,7 +116,7 @@ void main_quit(void) /* if there's a pending filename / system, clear */ if (NULL != console.nextfilename) { - nofrendo_free(console.nextfilename); + NOFRENDO_FREE(console.nextfilename); console.nextfilename = NULL; } console.nexttype = system_unknown; @@ -150,7 +150,7 @@ static int internal_insert(const char *filename, system_t type) if (system_autodetect == type) type = detect_systemtype(filename); - console.filename = nofrendo_strdup(filename); + console.filename = NOFRENDO_STRDUP(filename); console.type = type; /* set up the event system for this system type */ @@ -183,7 +183,7 @@ static int internal_insert(const char *filename, system_t type) default: nofrendo_log_printf("system type unknown, playing nofrendo NES intro.\n"); if (NULL != console.filename) - nofrendo_free(console.filename); + NOFRENDO_FREE(console.filename); /* oooh, recursion */ return internal_insert(filename, system_nes); @@ -195,7 +195,7 @@ static int internal_insert(const char *filename, system_t type) /* This tells main_loop to load this next image */ void main_insert(const char *filename, system_t type) { - console.nextfilename = nofrendo_strdup(filename); + console.nextfilename = NOFRENDO_STRDUP(filename); console.nexttype = type; main_eject(); @@ -239,9 +239,9 @@ int main_loop(const char *filename, system_t type) osd_getvideoinfo(&video); if (vid_init(video.default_width, video.default_height, video.driver)) return -1; - nofrendo_log_printf("vid_init done\n"); + printf("vid_init done\n"); - console.nextfilename = nofrendo_strdup(filename); + console.nextfilename = NOFRENDO_STRDUP(filename); console.nexttype = type; while (false == console.quit) diff --git a/components/nofrendo/noftypes.h b/components/nofrendo/noftypes.h index a50f44f..5801a0d 100644 --- a/components/nofrendo/noftypes.h +++ b/components/nofrendo/noftypes.h @@ -70,8 +70,6 @@ typedef unsigned int uint32; #endif /* !NOFRENDO_DEBUG */ -extern void *mem_alloc(int size, bool speedy); - #endif /* _NOFTYPES_H_ */ /* diff --git a/components/nofrendo/sndhrdw/nes_apu.c b/components/nofrendo/sndhrdw/nes_apu.c index af61fc6..57d8606 100644 --- a/components/nofrendo/sndhrdw/nes_apu.c +++ b/components/nofrendo/sndhrdw/nes_apu.c @@ -999,7 +999,7 @@ apu_t *apu_create(double base_freq, int sample_rate, int refresh_rate, int sampl apu_t *temp_apu; int channel; - temp_apu = nofrendo_malloc(sizeof(apu_t)); + temp_apu = NOFRENDO_MALLOC(sizeof(apu_t)); if (NULL == temp_apu) return NULL; @@ -1033,7 +1033,7 @@ void apu_destroy(apu_t **src_apu) { if ((*src_apu)->ext && NULL != (*src_apu)->ext->shutdown) (*src_apu)->ext->shutdown(); - nofrendo_free(*src_apu); + NOFRENDO_FREE(*src_apu); *src_apu = NULL; } } diff --git a/main/config.h b/main/config.h new file mode 100644 index 0000000..bd6845f --- /dev/null +++ b/main/config.h @@ -0,0 +1,7 @@ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#define FSROOT "/spiffs" +#define ROM_FILE FSROOT "/rom.nes" + +#endif /* _CONFIG_H_ */ diff --git a/main/main.c b/main/main.c index b42e38d..daf15ad 100644 --- a/main/main.c +++ b/main/main.c @@ -13,6 +13,7 @@ #include "nofconfig.h" #include "nofrendo.h" +#include "config.h" void *mem_alloc(int size, bool fast_mem) { diff --git a/main/osd.c b/main/osd.c index 748f856..6c50d92 100644 --- a/main/osd.c +++ b/main/osd.c @@ -29,6 +29,7 @@ #include "version.h" #include "nofconfig.h" +#include "config.h" char configfilename[] = "na"; diff --git a/main/video_audio.c b/main/video_audio.c index 3013b58..8e423c7 100644 --- a/main/video_audio.c +++ b/main/video_audio.c @@ -106,7 +106,7 @@ static void osd_stopsound(void) static int osd_init_sound(void) { #if CONFIG_SOUND_ENA - audio_frame = nofrendo_malloc(4 * DEFAULT_FRAGSIZE); + audio_frame = NOFRENDO_MALLOC(4 * DEFAULT_FRAGSIZE); i2s_config_t cfg = { .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, .sample_rate = DEFAULT_SAMPLERATE,