SummerCart64/sw/bootloader/src/display.c

173 lines
4.8 KiB
C
Raw Normal View History

[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19) * isv support + usb/dd improvements * make room for saves * update offset * fixed debug address * idk * exception * ironed out all broken stuff * cleanup * return epc fix * better * more cleanup * even more cleanup * mooore cleanup * fixed printf * no assert * improved docker build, pyft232 instead of pyserial * fixed displaying long message strings description test * just straight cleanup * smallest cleanup * PAL * cpu buffer * n64 bootloader done * super slow usb storage reading implemented * reduced buffer size * usb gets fast * little cleanup * double buffered reads * removed separate event id * ISV in hardware finally * small exception changes * mac testing * py spacing * fsd write, rtc, isv and reset fixes * fixxx * good stopping point * usb fixed? * pretend we have 128 MB sdram * backup * chmod * test * test done * more tests * user rm * help * final fix * updated component values * nice asset names * cic 64dd support * ddipl enable separation * pre DMA rewrite, created dedicated buffer memory space, simplified code * dma rewrite, needs testing * moved xml * dd basics * timing * 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite * added usb read functionality, general cleanup * changed mem addressing * added fpga flash update access * added mcu update * chmod * little cleanup * update format and stuff * fixes * uninitialized fix * small fixes * update fixes * update stuff done * fpga update tested * build time fix * boot fix * test timing * readme test * test 2 * reports * testseet * final * build test * forgot * button and naming * General cleanup And multiline commit message test * Exception screen UI touch ups * display separation and tests beginning * pc software update * pc software done * timing test * delete launch.json * sw fixes * fixed button hole diameter in shell * small cleanup, rpi testing * shell fillet fix, pc rtc printing * added cfg lock mechanism * moved lock to cfg address space * extended ROM and ISV fixes * preliminary sd card support * little sd card cleanup * sd menu fixes * 5 second limit * reduced shell thickness * basic led act blinking * faster sd menu loading * inst cache invalidate * sd card writing is working * SD card CSD and CID registers * wait for previous command * led error codes * fixed cfg_translate_address use * 64dd from sd card working * 64dd speedup and button handling * delayed address latching cycle - might break other builds, needs testing * bootloader improvements * small fixes * return previous cfg when setting new * cache stuff * unfloader debug protocol support * UNFLoader style debug command line support * requirements.txt * shell groove fillet * reset state inside controller * fixed fast PI read, added PI R/W fifo debug info * PI access prioritize * SD clock stop when RX FIFO is more than half full * flash erase method change * CFG error handling, TLOZ MM debug ISV support * CIC5167 support * general fixes * USB unplugged cable handling * turn off led when changing between error/act modes * rtc 2 bit clock stop support * line endings * Revert "line endings" This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb. * PI address debug * readme test * diagram update * diagram background * diagram background * diagram background * updated readme
2022-11-10 11:46:54 +01:00
#include <stdio.h>
#include "display.h"
#include "font.h"
#include "io.h"
#define SCREEN_WIDTH (640)
#define SCREEN_HEIGHT (240)
#define BORDER_WIDTH (64)
#define BORDER_HEIGHT (24)
#define BACKGROUND_COLOR (0x00000000UL)
#define TEXT_COLOR (0xFFFFFFFFUL)
#define LINE_SPACING (2)
static io32_t display_framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT] __attribute__((section(".framebuffer")));
static int char_x;
static int char_y;
static const vi_regs_t vi_config[] = {{
.CR = (
VI_CR_PIXEL_ADVANCE_1 |
VI_CR_PIXEL_ADVANCE_0 |
VI_CR_ANTIALIAS_1 |
VI_CR_ANTIALIAS_0 |
VI_CR_TYPE_32
),
.H_WIDTH = SCREEN_WIDTH,
.V_INTR = 0x000003FF,
.CURR_LINE = 0x00000000,
.TIMING = 0x0404233A,
.V_SYNC = 0x00000271,
.H_SYNC = 0x00150C69,
.H_SYNC_LEAP = 0x0C6F0C6E,
.H_LIMITS = 0x00800300,
.V_LIMITS = 0x005D023D,
.COLOR_BURST = 0x00090268,
.H_SCALE = 0x00000400,
.V_SCALE = 0x00000400,
}, {
.CR = (
VI_CR_PIXEL_ADVANCE_1 |
VI_CR_PIXEL_ADVANCE_0 |
VI_CR_ANTIALIAS_1 |
VI_CR_ANTIALIAS_0 |
VI_CR_TYPE_32
),
.H_WIDTH = SCREEN_WIDTH,
.V_INTR = 0x000003FF,
.CURR_LINE = 0x00000000,
.TIMING = 0x03E52239,
.V_SYNC = 0x0000020D,
.H_SYNC = 0x00000C15,
.H_SYNC_LEAP = 0x0C150C15,
.H_LIMITS = 0x006C02EC,
.V_LIMITS = 0x00230203,
.COLOR_BURST = 0x000E0204,
.H_SCALE = 0x00000400,
.V_SCALE = 0x00000400,
}};
static void display_decompress_background (uint32_t *background) {
uint32_t pixel_count = ((*background++) / sizeof(uint32_t));
uint32_t pixels_painted = 0;
uint8_t *background_data = (uint8_t *) (background);
uint32_t *framebuffer = (uint32_t *) (display_framebuffer);
while (pixels_painted < pixel_count) {
int pixel_repeat = ((background_data[0]) + 1);
uint32_t pixel_value = (
((background_data[1]) << 24) |
((background_data[2]) << 16) |
((background_data[3]) << 8) |
(background_data[4])
);
for (int i = 0; i < pixel_repeat; i++) {
io_write(framebuffer++, pixel_value);
}
pixels_painted += pixel_repeat;
background_data += 5;
}
}
static void display_clear_background (void) {
for (int i = 0; i < (SCREEN_WIDTH * SCREEN_HEIGHT); i++) {
io_write(&display_framebuffer[i], BACKGROUND_COLOR);
}
}
[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19) * isv support + usb/dd improvements * make room for saves * update offset * fixed debug address * idk * exception * ironed out all broken stuff * cleanup * return epc fix * better * more cleanup * even more cleanup * mooore cleanup * fixed printf * no assert * improved docker build, pyft232 instead of pyserial * fixed displaying long message strings description test * just straight cleanup * smallest cleanup * PAL * cpu buffer * n64 bootloader done * super slow usb storage reading implemented * reduced buffer size * usb gets fast * little cleanup * double buffered reads * removed separate event id * ISV in hardware finally * small exception changes * mac testing * py spacing * fsd write, rtc, isv and reset fixes * fixxx * good stopping point * usb fixed? * pretend we have 128 MB sdram * backup * chmod * test * test done * more tests * user rm * help * final fix * updated component values * nice asset names * cic 64dd support * ddipl enable separation * pre DMA rewrite, created dedicated buffer memory space, simplified code * dma rewrite, needs testing * moved xml * dd basics * timing * 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite * added usb read functionality, general cleanup * changed mem addressing * added fpga flash update access * added mcu update * chmod * little cleanup * update format and stuff * fixes * uninitialized fix * small fixes * update fixes * update stuff done * fpga update tested * build time fix * boot fix * test timing * readme test * test 2 * reports * testseet * final * build test * forgot * button and naming * General cleanup And multiline commit message test * Exception screen UI touch ups * display separation and tests beginning * pc software update * pc software done * timing test * delete launch.json * sw fixes * fixed button hole diameter in shell * small cleanup, rpi testing * shell fillet fix, pc rtc printing * added cfg lock mechanism * moved lock to cfg address space * extended ROM and ISV fixes * preliminary sd card support * little sd card cleanup * sd menu fixes * 5 second limit * reduced shell thickness * basic led act blinking * faster sd menu loading * inst cache invalidate * sd card writing is working * SD card CSD and CID registers * wait for previous command * led error codes * fixed cfg_translate_address use * 64dd from sd card working * 64dd speedup and button handling * delayed address latching cycle - might break other builds, needs testing * bootloader improvements * small fixes * return previous cfg when setting new * cache stuff * unfloader debug protocol support * UNFLoader style debug command line support * requirements.txt * shell groove fillet * reset state inside controller * fixed fast PI read, added PI R/W fifo debug info * PI access prioritize * SD clock stop when RX FIFO is more than half full * flash erase method change * CFG error handling, TLOZ MM debug ISV support * CIC5167 support * general fixes * USB unplugged cable handling * turn off led when changing between error/act modes * rtc 2 bit clock stop support * line endings * Revert "line endings" This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb. * PI address debug * readme test * diagram update * diagram background * diagram background * diagram background * updated readme
2022-11-10 11:46:54 +01:00
static void display_draw_character (char c) {
if (c == '\n') {
char_x = BORDER_WIDTH;
char_y += FONT_HEIGHT + LINE_SPACING;
return;
}
if ((char_x + FONT_WIDTH) > (SCREEN_WIDTH - BORDER_WIDTH)) {
char_x = BORDER_WIDTH;
char_y += FONT_HEIGHT + LINE_SPACING;
}
if ((c < ' ') || (c > '~')) {
c = '\x7F';
}
for (int i = 0; i < (FONT_WIDTH * FONT_HEIGHT); i++) {
int c_x = char_x + (i % FONT_WIDTH);
int c_y = char_y + (i / FONT_WIDTH);
if ((c_x >= (SCREEN_WIDTH - BORDER_WIDTH)) || (c_y >= (SCREEN_HEIGHT - BORDER_HEIGHT))) {
break;
}
if (font_data[c - ' '][i / 8] & (1 << (i % 8))) {
int screen_offset = c_x + (c_y * SCREEN_WIDTH);
io_write(&display_framebuffer[screen_offset], TEXT_COLOR);
}
}
char_x += FONT_WIDTH;
}
static void display_draw_string (const char *s) {
while (*s != '\0') {
display_draw_character(*s++);
}
}
void display_init (uint32_t *background) {
const vi_regs_t *cfg = &vi_config[OS_INFO->tv_type];
char_x = BORDER_WIDTH;
char_y = BORDER_HEIGHT;
if (background != NULL) {
display_decompress_background(background);
[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19) * isv support + usb/dd improvements * make room for saves * update offset * fixed debug address * idk * exception * ironed out all broken stuff * cleanup * return epc fix * better * more cleanup * even more cleanup * mooore cleanup * fixed printf * no assert * improved docker build, pyft232 instead of pyserial * fixed displaying long message strings description test * just straight cleanup * smallest cleanup * PAL * cpu buffer * n64 bootloader done * super slow usb storage reading implemented * reduced buffer size * usb gets fast * little cleanup * double buffered reads * removed separate event id * ISV in hardware finally * small exception changes * mac testing * py spacing * fsd write, rtc, isv and reset fixes * fixxx * good stopping point * usb fixed? * pretend we have 128 MB sdram * backup * chmod * test * test done * more tests * user rm * help * final fix * updated component values * nice asset names * cic 64dd support * ddipl enable separation * pre DMA rewrite, created dedicated buffer memory space, simplified code * dma rewrite, needs testing * moved xml * dd basics * timing * 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite * added usb read functionality, general cleanup * changed mem addressing * added fpga flash update access * added mcu update * chmod * little cleanup * update format and stuff * fixes * uninitialized fix * small fixes * update fixes * update stuff done * fpga update tested * build time fix * boot fix * test timing * readme test * test 2 * reports * testseet * final * build test * forgot * button and naming * General cleanup And multiline commit message test * Exception screen UI touch ups * display separation and tests beginning * pc software update * pc software done * timing test * delete launch.json * sw fixes * fixed button hole diameter in shell * small cleanup, rpi testing * shell fillet fix, pc rtc printing * added cfg lock mechanism * moved lock to cfg address space * extended ROM and ISV fixes * preliminary sd card support * little sd card cleanup * sd menu fixes * 5 second limit * reduced shell thickness * basic led act blinking * faster sd menu loading * inst cache invalidate * sd card writing is working * SD card CSD and CID registers * wait for previous command * led error codes * fixed cfg_translate_address use * 64dd from sd card working * 64dd speedup and button handling * delayed address latching cycle - might break other builds, needs testing * bootloader improvements * small fixes * return previous cfg when setting new * cache stuff * unfloader debug protocol support * UNFLoader style debug command line support * requirements.txt * shell groove fillet * reset state inside controller * fixed fast PI read, added PI R/W fifo debug info * PI access prioritize * SD clock stop when RX FIFO is more than half full * flash erase method change * CFG error handling, TLOZ MM debug ISV support * CIC5167 support * general fixes * USB unplugged cable handling * turn off led when changing between error/act modes * rtc 2 bit clock stop support * line endings * Revert "line endings" This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb. * PI address debug * readme test * diagram update * diagram background * diagram background * diagram background * updated readme
2022-11-10 11:46:54 +01:00
} else {
display_clear_background();
[SC64][FW][HW][SW] New version based on LCMXO2 FPGA (#19) * isv support + usb/dd improvements * make room for saves * update offset * fixed debug address * idk * exception * ironed out all broken stuff * cleanup * return epc fix * better * more cleanup * even more cleanup * mooore cleanup * fixed printf * no assert * improved docker build, pyft232 instead of pyserial * fixed displaying long message strings description test * just straight cleanup * smallest cleanup * PAL * cpu buffer * n64 bootloader done * super slow usb storage reading implemented * reduced buffer size * usb gets fast * little cleanup * double buffered reads * removed separate event id * ISV in hardware finally * small exception changes * mac testing * py spacing * fsd write, rtc, isv and reset fixes * fixxx * good stopping point * usb fixed? * pretend we have 128 MB sdram * backup * chmod * test * test done * more tests * user rm * help * final fix * updated component values * nice asset names * cic 64dd support * ddipl enable separation * pre DMA rewrite, created dedicated buffer memory space, simplified code * dma rewrite, needs testing * moved xml * dd basics * timing * 64dd working yet again, isv brought back, dma fixes, usb path rewrite, pc code rewrite * added usb read functionality, general cleanup * changed mem addressing * added fpga flash update access * added mcu update * chmod * little cleanup * update format and stuff * fixes * uninitialized fix * small fixes * update fixes * update stuff done * fpga update tested * build time fix * boot fix * test timing * readme test * test 2 * reports * testseet * final * build test * forgot * button and naming * General cleanup And multiline commit message test * Exception screen UI touch ups * display separation and tests beginning * pc software update * pc software done * timing test * delete launch.json * sw fixes * fixed button hole diameter in shell * small cleanup, rpi testing * shell fillet fix, pc rtc printing * added cfg lock mechanism * moved lock to cfg address space * extended ROM and ISV fixes * preliminary sd card support * little sd card cleanup * sd menu fixes * 5 second limit * reduced shell thickness * basic led act blinking * faster sd menu loading * inst cache invalidate * sd card writing is working * SD card CSD and CID registers * wait for previous command * led error codes * fixed cfg_translate_address use * 64dd from sd card working * 64dd speedup and button handling * delayed address latching cycle - might break other builds, needs testing * bootloader improvements * small fixes * return previous cfg when setting new * cache stuff * unfloader debug protocol support * UNFLoader style debug command line support * requirements.txt * shell groove fillet * reset state inside controller * fixed fast PI read, added PI R/W fifo debug info * PI access prioritize * SD clock stop when RX FIFO is more than half full * flash erase method change * CFG error handling, TLOZ MM debug ISV support * CIC5167 support * general fixes * USB unplugged cable handling * turn off led when changing between error/act modes * rtc 2 bit clock stop support * line endings * Revert "line endings" This reverts commit d0ddfe5ec716d2db7c72561703f51a94bf34e6bb. * PI address debug * readme test * diagram update * diagram background * diagram background * diagram background * updated readme
2022-11-10 11:46:54 +01:00
}
io_write(&VI->MADDR, (uint32_t) (display_framebuffer));
io_write(&VI->H_WIDTH, cfg->H_WIDTH);
io_write(&VI->V_INTR, cfg->V_INTR);
io_write(&VI->CURR_LINE, cfg->CURR_LINE);
io_write(&VI->TIMING, cfg->TIMING);
io_write(&VI->V_SYNC, cfg->V_SYNC);
io_write(&VI->H_SYNC, cfg->H_SYNC);
io_write(&VI->H_SYNC_LEAP, cfg->H_SYNC_LEAP);
io_write(&VI->H_LIMITS, cfg->H_LIMITS);
io_write(&VI->V_LIMITS, cfg->V_LIMITS);
io_write(&VI->COLOR_BURST, cfg->COLOR_BURST);
io_write(&VI->H_SCALE, cfg->H_SCALE);
io_write(&VI->V_SCALE, cfg->V_SCALE);
io_write(&VI->CR, cfg->CR);
}
void display_vprintf (const char *fmt, va_list args) {
char line[256];
vsniprintf(line, sizeof(line), fmt, args);
display_draw_string(line);
}
void display_printf (const char* fmt, ...) {
va_list args;
va_start(args, fmt);
display_vprintf(fmt, args);
va_end(args);
}