Skip to content

Commit 693e378

Browse files
committed
Fix LCD for newer esp-idfs, save memory by sharing main buffer
1 parent 7684a1a commit 693e378

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

components/nofrendo-esp32/spi_lcd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "soc/spi_reg.h"
2525
#include "freertos/FreeRTOS.h"
2626
#include "freertos/task.h"
27+
#include "driver/periph_ctrl.h"
2728
#include "spi_lcd.h"
2829

2930
#define PIN_NUM_MISO CONFIG_HW_LCD_MISO_GPIO
@@ -305,6 +306,9 @@ static void ili_gpio_init()
305306

306307
static void spi_master_init()
307308
{
309+
periph_module_enable(PERIPH_VSPI_MODULE);
310+
periph_module_enable(PERIPH_SPI_DMA_MODULE);
311+
308312
ets_printf("lcd spi pin mux init ...\r\n");
309313
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U,2);
310314
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO23_U,2);

components/nofrendo-esp32/video_audio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static uint16_t *audio_frame;
7070
#endif
7171

7272
static void do_audio_frame() {
73+
7374
#if CONFIG_SOUND_ENA
7475
int left=DEFAULT_SAMPLERATE/NES_REFRESH_RATE;
7576
while(left) {
@@ -250,7 +251,7 @@ static void videoTask(void *arg) {
250251
x = (320-DEFAULT_WIDTH)/2;
251252
y = ((240-DEFAULT_HEIGHT)/2);
252253
while(1) {
253-
xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30
254+
// xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30
254255
xQueueReceive(vidQueue, &bmp, portMAX_DELAY);
255256
ili9341_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line);
256257
}

components/nofrendo/gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void gui_savesnap(void)
7474
if (osd_makesnapname(filename, PATH_MAX) < 0)
7575
return;
7676

77-
if (pcx_write(filename, nes->vidbuf, nes->ppu->curpal))
77+
if (pcx_write(filename, vid_getbuffer(), nes->ppu->curpal))
7878
return;
7979

8080
gui_sendmsg(GUI_GREEN, "Screen saved to %s", filename);

components/nofrendo/nes/nes.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ static void build_address_handlers(nes_t *machine)
250250
void nes_irq(void)
251251
{
252252
#ifdef NOFRENDO_DEBUG
253-
if (nes.scanline <= NES_SCREEN_HEIGHT)
254-
memset(nes.vidbuf->line[nes.scanline - 1], GUI_RED, NES_SCREEN_WIDTH);
253+
// if (nes.scanline <= NES_SCREEN_HEIGHT)
254+
// memset(nes.vidbuf->line[nes.scanline - 1], GUI_RED, NES_SCREEN_WIDTH);
255255
#endif /* NOFRENDO_DEBUG */
256256

257257
nes6502_irq();
@@ -301,7 +301,8 @@ static void nes_renderframe(bool draw_flag)
301301

302302
while (262 != nes.scanline)
303303
{
304-
ppu_scanline(nes.vidbuf, nes.scanline, draw_flag);
304+
// ppu_scanline(nes.vidbuf, nes.scanline, draw_flag);
305+
ppu_scanline(vid_getbuffer(), nes.scanline, draw_flag);
305306

306307
if (241 == nes.scanline)
307308
{
@@ -342,8 +343,8 @@ static void system_video(bool draw)
342343
}
343344

344345
/* blit the NES screen to our video surface */
345-
vid_blit(nes.vidbuf, 0, (NES_SCREEN_HEIGHT - NES_VISIBLE_HEIGHT) / 2,
346-
0, 0, NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT);
346+
// vid_blit(nes.vidbuf, 0, (NES_SCREEN_HEIGHT - NES_VISIBLE_HEIGHT) / 2,
347+
// 0, 0, NES_SCREEN_WIDTH, NES_VISIBLE_HEIGHT);
347348

348349
/* overlay our GUI on top of it */
349350
gui_frame(true);
@@ -437,7 +438,7 @@ void nes_destroy(nes_t **machine)
437438
mmc_destroy(&(*machine)->mmc);
438439
ppu_destroy(&(*machine)->ppu);
439440
apu_destroy(&(*machine)->apu);
440-
bmp_destroy(&(*machine)->vidbuf);
441+
// bmp_destroy(&(*machine)->vidbuf);
441442
if ((*machine)->cpu)
442443
{
443444
if ((*machine)->cpu->mem_page[0])
@@ -516,9 +517,9 @@ nes_t *nes_create(void)
516517

517518
/* bitmap */
518519
/* 8 pixel overdraw */
519-
machine->vidbuf = bmp_create(NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, 8);
520-
if (NULL == machine->vidbuf)
521-
goto _fail;
520+
// machine->vidbuf = bmp_create(NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, 8);
521+
// if (NULL == machine->vidbuf)
522+
// goto _fail;
522523

523524
machine->autoframeskip = true;
524525

components/nofrendo/nes/nes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ typedef struct nes_s
7070
rominfo_t *rominfo;
7171

7272
/* video buffer */
73-
bitmap_t *vidbuf;
73+
/* For the ESP32, it costs too much memory to render to a separate buffer and blit that to the main buffer.
74+
Instead, the code has been modified to directly grab the primary buffer from the video subsystem and render
75+
there, saving us about 64K of memory. */
76+
// bitmap_t *vidbuf;
7477

7578
bool fiq_occurred;
7679
uint8 fiq_state;

0 commit comments

Comments
 (0)