Skip to content

Commit

Permalink
Snapshots (#38)
Browse files Browse the repository at this point in the history
* Add Olimex Joystick

* Fix extra warnings

* z80 load and save

* First running version

* Sound support

* Store sound and display state state

* Maintain program specific data

* Update Readme

* Add version to load

* Build checks

* Build improvements

* version error

* Save complete sound state

* Select resolution

* Tidy F8 exit

* Unnecessary cast

* uf2 and excludes

* DEscribe snapshot file format

* Snall Readme changes

* Clarify the effect of F1

* Reduce cursor speed in menu

* Clean directory

* Missing uf2

* Update build and info

* add comma

---------

Co-authored-by: ikjordan <[email protected]>
  • Loading branch information
ikjordan and ikjordan authored Jan 19, 2025
1 parent 2d374c2 commit b69d523
Show file tree
Hide file tree
Showing 50 changed files with 1,066 additions and 117 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ build/*

# Allow example file
!examples/ZX80-4K/simple.o

# Exclude extra build directories
build_2040/*
build_2350/*

#Code counter
.VSCodeCounter/*
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ else()
endif()

# Determine video system and name uf2
set (EXTRA_CHECK "-Wextra")
if ((${PICO_BOARD} STREQUAL "dviboard") OR (${PICO_BOARD} STREQUAL "olimexpcboard") OR (${PICO_BOARD} STREQUAL "wspizeroboard"))
target_compile_definitions(${PROJECT} PUBLIC
-DDVI_1BPP_BIT_REVERSE=1
Expand Down Expand Up @@ -221,6 +222,7 @@ else()
target_link_libraries(${PROJECT} mod_scanvideo_dpi)
else ()
target_link_libraries(${PROJECT} pico_scanvideo_dpi)
set (EXTRA_CHECK "")
endif()
endif()

Expand All @@ -244,7 +246,7 @@ endif()
# always support Chroma
target_compile_definitions(${PROJECT} PRIVATE -DSUPPORT_CHROMA -DLOAD_AND_SAVE)

target_compile_options(${PROJECT} PRIVATE -Wall)
target_compile_options(${PROJECT} PRIVATE -Wall ${EXTRA_CHECK})

target_link_libraries(${PROJECT}
pico_multicore
Expand Down
2 changes: 1 addition & 1 deletion PicoDVI
84 changes: 68 additions & 16 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions boards/olimexpcboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
#define PICO_AUDIO_PWM_R_PIN OLIMEXPCBOARD_PWM_R_PIN
#endif

#define NINEPIN_JOYSTICK

#define NINEPIN_UP 20 // UEXT1 Pin 3
#define NINEPIN_DOWN 21 // UEXT1 Pin 4
#define NINEPIN_LEFT 8 // UEXT1 Pin 6
#define NINEPIN_RIGHT 9 // UEXT1 Pin 5
#define NINEPIN_BUTTON 5 // UEXT1 Pin 10
// UEXT1 Pin 2 is Ground

#define PICO_OLIMEXPC_BOARD

Expand Down
31 changes: 22 additions & 9 deletions buildall
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
#!/bin/bash
# Get the build type - in case different build types are needed for Pico and Pico 2 in the future
build_type()
{
if [[ $1 == "rp2040" ]]
then
echo "Release"
else
echo "Release"
fi
}

#build a board type
build_uf2()
{
board=$1"board .."
uf2="picozx81_"$1"_"$2".uf2"
type=$(build_type $2)

cmake -DHDMI_SOUND=OFF -DPICOZX_LCD=OFF -DCMAKE_BUILD_TYPE=Release -DTIME_SPARE=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
cmake -DHDMI_SOUND=OFF -DPICOZX_LCD=OFF -DCMAKE_BUILD_TYPE=${type} -DTIME_SPARE=OFF -DFLASH_LED=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
make -j4
cp ./${uf2} ../uf2/${uf2}
}

build_uf2_hdmi()
{
board=$1"board .."
mcu=$2
uf2="picozx81_"$1"_hdmi_sound_"$2".uf2"
type=$(build_type $2)

cmake -DHDMI_SOUND=ON -DPICOZX_LCD=OFF -DCMAKE_BUILD_TYPE=Release -DTIME_SPARE=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
cmake -DHDMI_SOUND=ON -DPICOZX_LCD=OFF -DCMAKE_BUILD_TYPE=${type} -DTIME_SPARE=OFF -DFLASH_LED=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
make -j4
cp ./${uf2} ../uf2/${uf2}
}

build_uf2_lcd()
{
board=$1"board .."
mcu=$2
uf2="picozx81_"$1"_lcd_"$2".uf2"
type=$(build_type $2)

cmake -DHDMI_SOUND=OFF -DPICOZX_LCD=ON -DCMAKE_BUILD_TYPE=Release -DTIME_SPARE=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
cmake -DHDMI_SOUND=OFF -DPICOZX_LCD=ON -DCMAKE_BUILD_TYPE=${type} -DTIME_SPARE=OFF -DFLASH_LED=OFF -DPICO_BOARD=${board} -DPICO_MCU=$2
make -j4
cp ./${uf2} ../uf2/${uf2}
}

# Create the directories
mkdir -p build_2040
mkdir -p build_2350
# Create the directories from scratch
rm -rf build_2040
rm -rf build_2350
mkdir build_2040
mkdir build_2350
mkdir -p uf2

# Build all PicoZX81 variants for rp2040
cd build_2040

build_uf2 vga rp2040
build_uf2 vga rp2040
build_uf2 dvi rp2040
build_uf2 picomitevga rp2040
build_uf2 olimexpc rp2040
Expand Down
23 changes: 23 additions & 0 deletions display/display_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "display_priv.h"
#include "zx80bmp.h"
#include "zx81bmp.h"
#include "../src/emusnap.h"

#ifdef SUPPORT_CHROMA
// Structure for chroma buffers
Expand Down Expand Up @@ -423,6 +424,28 @@ void __not_in_flash_func(newFrame)(void)
mutex_exit(&next_frame_mutex);
}

bool display_save_snap(void)
{
if (!emu_FileWriteBytes(&blank, sizeof(blank))) return false;
if (!emu_FileWriteBytes(&blank_colour, sizeof(blank_colour))) return false;
if (!emu_FileWriteBytes(&keyboard, sizeof(keyboard))) return false;
if (!emu_FileWriteBytes(&showKeyboard, sizeof(showKeyboard))) return false;
if (!emu_FileWriteBytes(&interlace, sizeof(interlace))) return false;
if (!emu_FileWriteBytes(&no_skip, sizeof(no_skip))) return false;
return true;
}

bool display_load_snap(void)
{
if (!emu_FileReadBytes(&blank, sizeof(blank))) return false;
if (!emu_FileReadBytes(&blank_colour, sizeof(blank_colour))) return false;
if (!emu_FileReadBytes(&keyboard, sizeof(keyboard))) return false;
if (!emu_FileReadBytes(&showKeyboard, sizeof(showKeyboard))) return false;
if (!emu_FileReadBytes(&interlace, sizeof(interlace))) return false;
if (!emu_FileReadBytes(&no_skip, sizeof(no_skip))) return false;
return true;
}

//
// Private functions
//
Expand Down
6 changes: 4 additions & 2 deletions display/display_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static void __not_in_flash_func(render_loop)()
}

// 256 pixels of keyboard, 2 bits per pixel
for (int i=0; i<(keyboard->width >> 2); ++i)
for (unsigned int i=0; i<(keyboard->width >> 2); ++i)
{
uint8_t byte = keyboard->pixel_data[(y - keyboard_y) * (keyboard->width>>2) + i];
for (int x=6; x>=2; x-=4)
Expand Down Expand Up @@ -372,7 +372,7 @@ static void __not_in_flash_func(render_loop)()
}

// 256 pixels of keyboard, 2 bits per pixel
for (int i=0; i<(keyboard->width >> 2); ++i)
for (unsigned int i=0; i<(keyboard->width >> 2); ++i)
{
uint8_t byte = keyboard->pixel_data[(y - keyboard_y) * (keyboard->width>>2) + i];
for (int x=6; x>=2; x-=4)
Expand Down Expand Up @@ -512,6 +512,8 @@ void core1_main(void)

static bool __not_in_flash_func(timer_callback)(repeating_timer_t *rt)
{
(void)rt;

// Trigger new frame
sem_release(&frame_sync);
return true;
Expand Down
22 changes: 18 additions & 4 deletions scanvideo/pico_scanvideo_dpi/scanvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ inline static void list_remove(full_scanline_buffer_t **phead, full_scanline_buf
static inline uint32_t scanline_id_after(uint32_t scanline_id) {
uint32_t tmp = scanline_id & 0xffffu;

if (tmp < video_mode.height - 1) {
if (tmp < (uint32_t)(video_mode.height - 1)) {
return scanline_id + 1;
} else {
return scanline_id + 0x10000u - tmp;
Expand Down Expand Up @@ -570,15 +570,19 @@ static inline void abort_all_dma_channels_assuming_no_irq_preemption() {
// work around it in software, but we want to suppress the IRQ afterwards anyway, so
// as long as the spurious IRQ doesn't get taken here, then the h/w issue is of no problem
dma_hw->abort = PICO_SCANVIDEO_SCANLINE_DMA_CHANNELS_MASK;
// note that relying on the abort bits is no longer safe, as it may get cleared before the spurious IRQ happens
// // wait for abort(s) to complete
// while (dma_hw->abort & PICO_SCANVIDEO_SCANLINE_DMA_CHANNELS_MASK) tight_loop_contents();
// note that relying on the abort bits is not safe on RP2040, as it may get cleared before the spurious IRQ happens
// wait for abort(s) to complete
#if !PICO_RP2040
// fixed after RP2040
while (dma_hw->abort & PICO_SCANVIDEO_SCANLINE_DMA_CHANNELS_MASK) tight_loop_contents();
#else
while (dma_channel_is_busy(PICO_SCANVIDEO_SCANLINE_DMA_CHANNEL)) tight_loop_contents();
#if PICO_SCANVIDEO_PLANE_COUNT > 1
while (dma_channel_is_busy(PICO_SCANVIDEO_SCANLINE_DMA_CHANNEL2)) tight_loop_contents();
#if PICO_SCANVIDEO_PLANE_COUNT > 2
while (dma_channel_is_busy(PICO_SCANVIDEO_SCANLINE_DMA_CHANNEL3)) tight_loop_contents();
#endif
#endif
#endif
// we don't want any pending completion IRQ which may have happened in the interim
dma_hw->ints0 = PICO_SCANVIDEO_SCANLINE_DMA_CHANNELS_MASK;
Expand Down Expand Up @@ -739,6 +743,7 @@ void __video_most_time_critical_func(prepare_for_active_scanline_irqs_enabled)()
pio_sm_clear_fifos(video_pio, PICO_SCANVIDEO_SCANLINE_SM);
}
if (video_pio->sm[PICO_SCANVIDEO_SCANLINE_SM].instr != PIO_WAIT_IRQ4) {
// we don't know where we were, so me should also make sure OSR is empty, we certainly haven't sent any data yet
// hmm the problem here is we don't know if we should wait or not, because that is purely based on timing..
// - if irq not posted, and we wait: GOOD
// - if irq not posted and we don't wait: BAD. early line
Expand Down Expand Up @@ -1068,6 +1073,7 @@ extern bool scanvideo_in_vblank() {
}

static uint __no_inline_not_in_flash_func(default_scanvideo_scanline_repeat_count_fn)(uint32_t scanline_id) {
(void)scanline_id;
return 1;
}

Expand Down Expand Up @@ -1697,6 +1703,8 @@ bool scanvideo_setup_with_timing(const scanvideo_mode_t *mode, const scanvideo_t
bool video_24mhz_composable_adapt_for_mode(const scanvideo_pio_program_t *program, const scanvideo_mode_t *mode,
scanvideo_scanline_buffer_t *missing_scanline_buffer,
uint16_t *modifiable_instructions) {
(void)program;

int delay0 = 2 * mode->xscale - 2;
int delay1 = delay0 + 1;
valid_params_if(SCANVIDEO_DPI, delay0 <= 31);
Expand Down Expand Up @@ -1752,10 +1760,16 @@ bool video_24mhz_composable_adapt_for_mode(const scanvideo_pio_program_t *progra

bool video_default_adapt_for_mode(const scanvideo_pio_program_t *program, const scanvideo_mode_t *mode,
uint16_t *modifiable_instructions) {
(void)program;
(void)mode;
(void)modifiable_instructions;

return true;
}

void scanvideo_default_configure_pio(pio_hw_t *pio, uint sm, uint offset, pio_sm_config *config, bool overlay) {
(void)offset;

pio_sm_set_consecutive_pindirs(pio, sm, PICO_SCANVIDEO_COLOR_PIN_BASE, PICO_SCANVIDEO_COLOR_PIN_COUNT, true);
sm_config_set_out_pins(config, PICO_SCANVIDEO_COLOR_PIN_BASE, PICO_SCANVIDEO_COLOR_PIN_COUNT);
sm_config_set_out_shift(config, true, true, 32); // autopull
Expand Down
Loading

0 comments on commit b69d523

Please sign in to comment.