From 46b8cd8fbf457ddf580100d232afd340b94b158f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 16 Aug 2025 11:18:12 -0500 Subject: [PATCH] WIP core1 gets to "DVHSTX started" but the gfx_dma_handler is never reached so no video is generated. and I don't know why not. --- .gitmodules | 3 ++ 3rdparty/dvhstx | 1 + fruitjam_cflags.h | 3 +- src/i_main.c | 3 ++ src/pico/CMakeLists.txt | 19 ++++++++-- src/pico/i_input.c | 6 +-- src/pico/i_video.c | 81 +++++++++++++++++++++++++++++++++++++++-- src/w_file_memory.c | 4 +- 8 files changed, 104 insertions(+), 16 deletions(-) create mode 160000 3rdparty/dvhstx diff --git a/.gitmodules b/.gitmodules index fcbaee81..96492b3b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rdparty/tinyusb"] path = 3rdparty/tinyusb url = https://github.com/liamfraser/tinyusb.git +[submodule "3rdparty/dvhstx"] + path = 3rdparty/dvhstx + url = https://github.com/jepler/dvhstx diff --git a/3rdparty/dvhstx b/3rdparty/dvhstx new file mode 160000 index 00000000..6ae02e64 --- /dev/null +++ b/3rdparty/dvhstx @@ -0,0 +1 @@ +Subproject commit 6ae02e64cfe022e79439c9fa848e89936f5ac2a8 diff --git a/fruitjam_cflags.h b/fruitjam_cflags.h index b30fd983..ba5a9d08 100644 --- a/fruitjam_cflags.h +++ b/fruitjam_cflags.h @@ -8,12 +8,12 @@ #define PICO_SCANVIDEO_PIXEL_GSHIFT 1 #define PICO_SCANVIDEO_PIXEL_BSHIFT 2 #define PICO_SCANVIDEO_SYNC_PIN_BASE 6 -#define USE_HSTX 1 #define SD_TX 35 #define SD_RX 36 #define SD_SCK 34 #define SD_CS 39 #define USE_SD 1 +#define USE_HSTX 1 #define PICO_DEFAULT_UART 0 #define PICO_DEFAULT_UART_TX_PIN 44 #define PICO_DEFAULT_UART_RX_PIN 45 @@ -23,7 +23,6 @@ #define HSTX_D0P 13 #define HSTX_D1P 15 #define HSTX_D2P 17 -#define SD_MHZ 16 // Move the WAD base address way up since we have plenty of flash // Original builds were as low as 0x10040000, this gives an extra 256kB for code since we're chunky diff --git a/src/i_main.c b/src/i_main.c index 0ac24f5a..4672170a 100644 --- a/src/i_main.c +++ b/src/i_main.c @@ -312,10 +312,13 @@ int main(int argc, char **argv) fruitjam_init_i2s(); #endif #endif +#if !USE_HSTX + // hstx is in charge of all clocking vreg_set_voltage(VREG_VOLTAGE_1_30); busy_wait_us(1000); // todo pause? is this the cause of the cold start issue? set_sys_clock_khz(270000, true); +#endif #if !USE_PICO_NET // debug ? // gpio_debug_pins_init(); diff --git a/src/pico/CMakeLists.txt b/src/pico/CMakeLists.txt index 4c470b0f..b5ff001e 100644 --- a/src/pico/CMakeLists.txt +++ b/src/pico/CMakeLists.txt @@ -38,10 +38,23 @@ target_compile_definitions(common_pico INTERFACE PICO_USE_STACK_GUARDS=0 # todo we can actually use these sensibly, but right now we do overflow! ) -pico_generate_pio_header(common_pico ${CMAKE_CURRENT_LIST_DIR}/video_doom.pio) -target_link_libraries(common_pico INTERFACE pico_stdlib pico_multicore pico_scanvideo_dpi) +target_link_libraries(common_pico INTERFACE pico_stdlib pico_multicore) + +if (USE_HSTX) + set(PIMORONI_PICO_PATH ${CMAKE_CURRENT_LIST_DIR}/../../3rdparty/pimoroni-pico) + target_sources(common_pico INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/dvhstx_shim.cpp) + include(${PIMORONI_PICO_PATH}/pimoroni_pico_import.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/../../3rdparty/dvhstx/drivers/dvhstx/dvhstx.cmake) + target_link_libraries(common_pico INTERFACE dvhstx) + target_compile_definitions(common_pico INTERFACE USE_HSTX=1) +else() + pico_generate_pio_header(common_pico ${CMAKE_CURRENT_LIST_DIR}/video_doom.pio) + target_link_libraries(common_pico INTERFACE pico_scanvideo_dpi) + target_compile_definitions(common_pico INTERFACE USE_HSTX=0) +endif() add_library(pico_cd INTERFACE) if (TARGET tinyusb_host) target_link_libraries(pico_cd INTERFACE tinyusb_host) -endif() \ No newline at end of file +endif() diff --git a/src/pico/i_input.c b/src/pico/i_input.c index 1ac1e1f1..b58363c7 100644 --- a/src/pico/i_input.c +++ b/src/pico/i_input.c @@ -465,11 +465,7 @@ void I_BindInputVariables(void) M_BindIntVariable("novert", &novert); } -#if PICO_NO_HARDWARE -#include "pico/scanvideo.h" -#else #define WITH_SHIFT 0x8000 -#endif static void pico_key_down(int scancode, int keysym, int modifiers) { event_t event; @@ -822,4 +818,4 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c } } -#endif \ No newline at end of file +#endif diff --git a/src/pico/i_video.c b/src/pico/i_video.c index 15bb9d7c..17b81ba1 100644 --- a/src/pico/i_video.c +++ b/src/pico/i_video.c @@ -43,22 +43,36 @@ #include "w_wad.h" #include "z_zone.h" +#if USE_HSTX +#if !PICO_ON_DEVICE +#error Do not set USE_HSTX when !ON_DEVICE (only scanvideo is implemented) +#endif +#else #include "pico/scanvideo.h" #include "pico/scanvideo/composable_scanline.h" +#endif #include "pico/multicore.h" #include "pico/sync.h" #include "pico/time.h" #include "hardware/gpio.h" #include "picodoom.h" -#include "video_doom.pio.h" #include "image_decoder.h" #if PICO_ON_DEVICE #include "hardware/dma.h" #include "hardware/structs/xip_ctrl.h" #endif -#define YELLOW_SUBMARINE 0 +#if USE_HSTX +#include "dvhstx_shim.h" +#undef SUPPORT_TEXT +#define SUPPORT_TEXT 0 +#define PICO_SCANVIDEO_PIXEL_FROM_RGB8(r,g,b) (((r) << 16) | ((g) << 8) | (b)) +#else +#include "video_doom.pio.h" #define SUPPORT_TEXT 1 +#endif + +#define YELLOW_SUBMARINE 0 #if SUPPORT_TEXT typedef struct __packed { const char * const name; @@ -91,7 +105,7 @@ static uint16_t ega_colors[] = { // todo temproarly turned this off because it causes a seeming bug in scanvideo (perhaps only with the new callback stuff) where the last repeated scanline of a pixel line is freed while shown // note it may just be that this happens anyway, but usually we are writing slower than the beam? -#define USE_INTERP PICO_ON_DEVICE +#define USE_INTERP PICO_ON_DEVICE && !USE_HSTX #if USE_INTERP #include "hardware/interp.h" #endif @@ -141,6 +155,7 @@ static uint32_t *text_scanline_buffer_start; static uint8_t *text_screen_cpy; static uint8_t *text_font_cpy; +#if !USE_HSTX #if USE_1280x1024x60 //static uint32_t missing_scanline_data[] = { // video_doom_offset_raw_1p | (0 << 16u), @@ -267,6 +282,7 @@ static inline void interp_restore_static(interp_hw_t *interp, interp_hw_save_t * interp->ctrl[1] = saver->ctrl[1]; } #endif +#endif void I_ShutdownGraphics(void) { @@ -980,6 +996,56 @@ void __no_inline_not_in_flash_func(new_frame_stuff)() { } } + +#if USE_HSTX +void __scratch_x("scanlines") gen_line(void *cb_data, int scanline, uint32_t *dest) { + if(scanline == 0) { + new_frame_stuff(); + } + + DEBUG_PINS_SET(scanline_copy, 1); + if (display_video_type != VIDEO_TYPE_TEXT) { + scanline_funcs[display_video_type](dest, scanline); + if (display_video_type >= FIRST_VIDEO_TYPE_WITH_OVERLAYS) { + assert(scanline < count_of(vpatchlists->vpatch_starters)); + int prev = 0; + for (int vp = vpatchlists->vpatch_starters[scanline]; vp;) { + int next = vpatchlists->vpatch_next[vp]; + while (vpatchlists->vpatch_next[prev] && vpatchlists->vpatch_next[prev] < vp) { + prev = vpatchlists->vpatch_next[prev]; + } + assert(prev != vp); + assert(vpatchlists->vpatch_next[prev] != vp); + vpatchlists->vpatch_next[vp] = vpatchlists->vpatch_next[prev]; + vpatchlists->vpatch_next[prev] = vp; + prev = vp; + vp = next; + } + vpatchlist_t *overlays = vpatchlists->overlays[display_overlay_index]; + prev = 0; + for (int vp = vpatchlists->vpatch_next[prev]; vp; vp = vpatchlists->vpatch_next[prev]) { + patch_t *patch = resolve_vpatch_handle(overlays[vp].entry.patch_handle); + int yoff = scanline - overlays[vp].entry.y; + if (yoff < vpatch_height(patch)) { + vpatchlists->vpatch_doff[vp] = draw_vpatch((uint16_t*)(dest), patch, &overlays[vp], + vpatchlists->vpatch_doff[vp]); + prev = vp; + } else { + vpatchlists->vpatch_next[prev] = vpatchlists->vpatch_next[vp]; + } + } + } + } else { +#if 0 // SUPPORT_TEXT doesn't work with dvhstx + render_text_mode_scanline(buffer, scanline); +#else + memset(dest, 0, SCREENWIDTH * 2); +#endif + } + DEBUG_PINS_CLR(scanline_copy, 1); +} + +#else void __scratch_x("scanlines") fill_scanlines() { #if SUPPORT_TEXT struct scanvideo_scanline_buffer *buffer = scanvideo_begin_scanline_generation_linked(display_video_type == VIDEO_TYPE_TEXT ? 2 : 1, false); @@ -1069,6 +1135,7 @@ void __scratch_x("scanlines") fill_scanlines() { } #endif } +#endif #pragma GCC pop_options #if PICO_ON_DEVICE @@ -1088,6 +1155,9 @@ static void __not_in_flash_func(free_buffer_callback)() { //static semaphore_t init_sem; static void core1() { +#if USE_HSTX + hstx_setup(gen_line); +#else #if !PICO_ON_DEVICE void simulate_video_pio_video_doom(const uint32_t *dma_data, uint32_t dma_data_size, uint16_t *pixel_buffer, int32_t max_pixels, int32_t expected_width, bool overlay); @@ -1113,6 +1183,7 @@ static void core1() { fill_scanlines(); #endif } +#endif } #if PICO_RP2350 @@ -1386,6 +1457,7 @@ void I_DisplayFPSDots(boolean dots_on) { } +#if !USE_HSTX #if PICO_ON_DEVICE bool video_doom_adapt_for_mode(const struct scanvideo_pio_program *program, const struct scanvideo_mode *mode, struct scanvideo_scanline_buffer *missing_scanvideo_scanline_buffer, uint16_t *modifiable_instructions) { @@ -1516,5 +1588,6 @@ void simulate_video_pio_video_doom(const uint32_t *dma_data, uint32_t dma_data_s assert(last_was_black); } #endif +#endif -#endif \ No newline at end of file +#endif diff --git a/src/w_file_memory.c b/src/w_file_memory.c index 812823af..49db43e6 100644 --- a/src/w_file_memory.c +++ b/src/w_file_memory.c @@ -90,7 +90,7 @@ static wad_file_t *W_Memory_OpenFile(const char *path) } #endif #endif - return &fileo; + return (wad_file_t *)&fileo; } static void W_Memory_CloseFile(wad_file_t *wad) @@ -114,4 +114,4 @@ const wad_file_class_t memory_wad_file = W_Memory_CloseFile, W_Memory_Read, }; -#endif \ No newline at end of file +#endif