kopia lustrzana https://github.com/Wren6991/PicoDVI
Add tiles parallax demo
rodzic
561ecbd0d6
commit
6a2ae03021
|
@ -8,6 +8,7 @@ add_subdirectory(moon)
|
|||
add_subdirectory(sprite_bounce)
|
||||
add_subdirectory(terminal)
|
||||
add_subdirectory(tiles)
|
||||
add_subdirectory(tiles_parallax)
|
||||
add_subdirectory(vista)
|
||||
add_subdirectory(vista-palette)
|
||||
add_subdirectory(mandel-full)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
add_executable(tiles_parallax
|
||||
main.c
|
||||
)
|
||||
|
||||
target_compile_options(tiles_parallax PRIVATE -Wall)
|
||||
|
||||
target_compile_definitions(tiles_parallax PRIVATE
|
||||
DVI_DEFAULT_SERIAL_CONFIG=${DVI_DEFAULT_SERIAL_CONFIG}
|
||||
)
|
||||
|
||||
target_link_libraries(tiles_parallax
|
||||
pico_stdlib
|
||||
pico_multicore
|
||||
pico_util
|
||||
libdvi
|
||||
libsprite
|
||||
)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(tiles_parallax)
|
|
@ -0,0 +1,166 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "hardware/irq.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/vreg.h"
|
||||
#include "pico/sem.h"
|
||||
|
||||
#include "dvi.h"
|
||||
#include "dvi_serialiser.h"
|
||||
#include "common_dvi_pin_configs.h"
|
||||
#include "sprite.h"
|
||||
#include "tile.h"
|
||||
|
||||
#include "platformer_in_the_forest_rgab5515.h"
|
||||
#include "tilemap_foreground.h"
|
||||
#include "tilemap_background.h"
|
||||
|
||||
// Pick one:
|
||||
#define MODE_640x480_60Hz
|
||||
// #define MODE_800x480_60Hz
|
||||
// #define MODE_800x600_60Hz
|
||||
// #define MODE_960x540p_60Hz
|
||||
// #define MODE_1280x720_30Hz
|
||||
|
||||
#if defined(MODE_640x480_60Hz)
|
||||
// DVDD 1.2V (1.1V seems ok too)
|
||||
#define FRAME_WIDTH 320
|
||||
#define FRAME_HEIGHT 240
|
||||
#define VREG_VSEL VREG_VOLTAGE_1_20
|
||||
#define DVI_TIMING dvi_timing_640x480p_60hz
|
||||
|
||||
#elif defined(MODE_800x480_60Hz)
|
||||
#define FRAME_WIDTH 400
|
||||
#define FRAME_HEIGHT 240
|
||||
#define VREG_VSEL VREG_VOLTAGE_1_20
|
||||
#define DVI_TIMING dvi_timing_800x480p_60hz
|
||||
|
||||
#elif defined(MODE_800x600_60Hz)
|
||||
// DVDD 1.3V, going downhill with a tailwind
|
||||
#define FRAME_WIDTH 400
|
||||
#define FRAME_HEIGHT 300
|
||||
#define VREG_VSEL VREG_VOLTAGE_1_30
|
||||
#define DVI_TIMING dvi_timing_800x600p_60hz
|
||||
|
||||
#elif defined(MODE_960x540p_60Hz)
|
||||
// DVDD 1.25V (slower silicon may need the full 1.3, or just not work)
|
||||
// Frame resolution is almost the same as a PSP :)
|
||||
#define FRAME_WIDTH 480
|
||||
#define FRAME_HEIGHT 270
|
||||
#define VREG_VSEL VREG_VOLTAGE_1_25
|
||||
#define DVI_TIMING dvi_timing_960x540p_60hz
|
||||
|
||||
#elif defined(MODE_1280x720_30Hz)
|
||||
// 1280x720p 30 Hz (nonstandard)
|
||||
// DVDD 1.25V (slower silicon may need the full 1.3, or just not work)
|
||||
#define FRAME_WIDTH 640
|
||||
#define FRAME_HEIGHT 360
|
||||
#define VREG_VSEL VREG_VOLTAGE_1_25
|
||||
#define DVI_TIMING dvi_timing_1280x720p_30hz
|
||||
|
||||
#else
|
||||
#error "Select a video mode!"
|
||||
#endif
|
||||
|
||||
#define LED_PIN 21
|
||||
|
||||
struct dvi_inst dvi0;
|
||||
|
||||
void core1_main() {
|
||||
dvi_register_irqs_this_core(&dvi0, DMA_IRQ_0);
|
||||
while (queue_is_empty(&dvi0.q_colour_valid))
|
||||
__wfe();
|
||||
dvi_start(&dvi0);
|
||||
dvi_scanbuf_main_16bpp(&dvi0);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
static inline int clip(int x, int min, int max) {
|
||||
return x < min ? min : x > max ? max : x;
|
||||
}
|
||||
|
||||
#define N_SCANLINE_BUFFERS 4
|
||||
uint16_t static_scanbuf[N_SCANLINE_BUFFERS][FRAME_WIDTH];
|
||||
|
||||
void __not_in_flash("render") render_loop() {
|
||||
uint heartbeat = 0;
|
||||
uint frame_ctr = 0;
|
||||
|
||||
uint16_t bg_colour = 13u << 11 | 36u << 5 | 17u;
|
||||
|
||||
tilebg_t bg0 = {
|
||||
.xscroll = 0,
|
||||
.yscroll = 0,
|
||||
.tileset = platformer_in_the_forest,
|
||||
.tilemap = tilemap_background,
|
||||
.log_size_x = 9,
|
||||
.log_size_y = 8,
|
||||
.tilesize = TILESIZE_16,
|
||||
.fill_loop = (tile_loop_t)tile16_16px_alpha_loop
|
||||
};
|
||||
|
||||
tilebg_t bg1 = {
|
||||
.xscroll = 0,
|
||||
.yscroll = 0,
|
||||
.tileset = platformer_in_the_forest,
|
||||
.tilemap = tilemap_foreground,
|
||||
.log_size_x = 10,
|
||||
.log_size_y = 8,
|
||||
.tilesize = TILESIZE_16,
|
||||
.fill_loop = (tile_loop_t)tile16_16px_alpha_loop
|
||||
};
|
||||
|
||||
while (1) {
|
||||
if (++heartbeat >= 30) {
|
||||
heartbeat = 0;
|
||||
gpio_xor_mask(1u << LED_PIN);
|
||||
}
|
||||
for (uint y = 0; y < FRAME_HEIGHT; ++y) {
|
||||
uint16_t *pixbuf;
|
||||
queue_remove_blocking(&dvi0.q_colour_free, &pixbuf);
|
||||
sprite_fill16(pixbuf, bg_colour, FRAME_WIDTH);
|
||||
tile16(pixbuf, &bg0, y, FRAME_WIDTH);
|
||||
tile16(pixbuf, &bg1, y, FRAME_WIDTH);
|
||||
queue_add_blocking(&dvi0.q_colour_valid, &pixbuf);
|
||||
}
|
||||
bg0.xscroll += 1;
|
||||
bg1.xscroll += 2;
|
||||
++frame_ctr;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
vreg_set_voltage(VREG_VSEL);
|
||||
sleep_ms(10);
|
||||
set_sys_clock_khz(DVI_TIMING.bit_clk_khz, true);
|
||||
|
||||
setup_default_uart();
|
||||
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
|
||||
printf("Configuring DVI\n");
|
||||
|
||||
dvi0.timing = &DVI_TIMING;
|
||||
dvi0.ser_cfg = DVI_DEFAULT_SERIAL_CONFIG;
|
||||
dvi_init(&dvi0, next_striped_spin_lock_num(), next_striped_spin_lock_num());
|
||||
|
||||
printf("Core 1 start\n");
|
||||
multicore_launch_core1(core1_main);
|
||||
|
||||
printf("Allocating scanline buffers\n");
|
||||
for (int i = 0; i < N_SCANLINE_BUFFERS; ++i) {
|
||||
void *bufptr = &static_scanbuf[i];
|
||||
queue_add_blocking((void*)&dvi0.q_colour_free, &bufptr);
|
||||
}
|
||||
|
||||
// Core 1 will fire up the DVI once it sees the first colour buffer has been rendered
|
||||
printf("Start rendering\n");
|
||||
render_loop();
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
static const unsigned char tilemap_background[] = {
|
||||
97,97,111,97,97,97,97,97,97,97,97,97,111,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,111,97,97,97,
|
||||
97,97,97,97,97,97,111,97,97,97,77,114,114,114,114,78,97,111,97,97,97,111,97,97,97,77,114,114,114,78,97,97,
|
||||
78,111,97,97,97,111,97,97,97,77,115,51,51,51,51,113,114,114,114,114,114,114,114,114,114,115,0,0,0,113,114,114,
|
||||
113,114,114,114,114,114,114,78,97,98,51,51,51,51,51,51,51,51,2,3,4,5,6,51,51,51,51,51,51,51,51,51,
|
||||
51,51,2,3,4,5,6,113,114,115,51,51,51,51,51,51,51,51,19,20,21,22,23,51,51,51,51,51,51,51,51,51,
|
||||
51,51,19,20,21,22,23,51,0,1,51,51,51,51,51,51,51,51,36,37,38,39,40,51,51,51,51,51,51,51,51,51,
|
||||
51,51,36,37,38,39,40,51,17,18,51,51,51,51,51,51,51,51,53,54,55,56,57,51,51,51,51,51,51,51,51,51,
|
||||
51,51,53,54,55,56,57,51,51,51,51,51,51,51,51,51,51,51,19,71,72,73,74,51,51,51,51,51,51,51,51,51,
|
||||
51,51,70,71,72,73,74,51,51,51,51,51,51,51,51,51,51,51,53,88,89,90,91,51,51,51,51,51,51,51,51,51,
|
||||
51,51,87,88,89,90,91,51,51,51,51,51,51,51,51,51,51,51,104,88,89,107,108,51,51,51,51,51,51,51,51,51,
|
||||
51,51,104,105,106,107,108,51,51,51,51,51,51,51,51,51,51,51,104,105,106,68,125,51,51,51,51,51,51,51,51,51,
|
||||
51,51,121,122,123,124,125,51,51,51,51,51,51,51,51,74,74,74,121,122,123,74,74,74,74,74,74,74,74,74,51,51,
|
||||
93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,93,
|
||||
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
|
||||
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
|
||||
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
static const unsigned char tilemap_foreground[] = {
|
||||
51,51,96,97,112,98,51,51,51,96,97,97,97,97,97,97,97,97,98,51,51,51,96,97,97,97,97,77,114,78,97,97,97,97,98,51,51,51,51,51,51,51,51,51,51,51,51,51,51,96,97,97,97,97,94,80,80,80,80,95,97,97,98,51,
|
||||
51,51,96,97,97,98,51,51,51,96,97,111,97,97,77,114,78,112,98,51,51,51,96,112,97,111,97,98,108,96,97,97,97,97,98,51,51,51,51,51,51,51,51,51,51,82,62,51,51,113,114,114,114,114,114,114,114,114,114,114,114,114,115,51,
|
||||
51,51,96,97,97,98,51,51,51,96,97,97,97,97,98,38,96,97,98,51,51,51,113,114,114,114,78,94,80,95,97,97,97,97,98,51,51,51,51,51,51,51,51,51,79,80,80,81,51,51,51,51,51,51,51,0,1,51,51,51,51,51,51,51,
|
||||
51,51,96,111,97,98,51,51,51,96,112,97,111,97,94,80,95,97,98,51,51,51,51,51,51,51,96,97,111,97,77,114,78,112,98,51,51,51,51,51,51,51,75,79,95,112,97,94,80,81,51,51,51,51,51,51,18,51,51,51,51,51,51,51,
|
||||
51,51,96,97,97,98,51,51,51,113,114,114,114,114,114,114,114,114,115,51,51,51,51,51,51,51,96,97,97,97,98,0,96,97,98,51,51,51,51,51,51,51,92,96,111,97,97,112,97,98,51,51,51,51,51,51,51,51,51,51,51,10,11,12,
|
||||
51,51,113,114,114,115,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,96,112,97,97,94,80,95,97,98,51,51,51,51,51,51,51,92,96,97,112,97,97,112,98,51,51,51,51,51,51,51,51,51,51,10,24,28,29,
|
||||
51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,113,114,114,114,114,114,114,114,115,51,51,51,51,51,51,51,92,113,114,114,114,114,114,115,51,51,51,51,51,51,51,51,51,51,27,28,28,29,
|
||||
51,51,51,14,51,51,51,51,51,51,51,51,51,48,49,49,49,49,49,49,49,49,51,51,51,101,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,92,51,51,51,51,51,51,51,51,51,51,51,51,51,25,26,75,51,27,28,28,29,
|
||||
51,10,11,12,51,51,51,51,51,51,75,10,11,12,51,51,51,51,51,51,51,10,11,11,11,11,11,11,11,11,11,12,51,51,51,51,51,51,51,51,51,51,92,51,51,51,51,51,51,51,51,51,51,51,51,25,28,29,92,51,27,28,24,29,
|
||||
51,27,28,29,51,51,51,51,51,51,92,27,28,29,51,51,51,51,51,51,51,27,28,28,28,28,28,28,28,28,24,29,51,51,51,51,51,51,51,51,51,51,92,51,51,51,51,51,51,51,51,51,51,51,25,28,28,63,92,51,61,28,28,29,
|
||||
51,27,28,29,51,51,51,51,76,51,109,27,28,29,51,51,51,51,51,51,51,27,28,28,51,51,51,51,51,28,28,29,51,51,47,51,47,51,51,51,51,51,92,51,51,51,51,51,51,51,51,51,51,25,28,28,28,63,92,51,51,51,61,29,
|
||||
51,27,24,29,51,51,51,25,8,8,26,27,28,29,51,51,51,51,51,51,51,27,24,28,118,82,84,82,51,28,28,29,51,51,64,51,64,51,51,47,51,51,109,116,51,99,51,51,51,51,51,51,25,28,28,28,28,63,109,101,51,82,61,29,
|
||||
51,27,28,29,51,51,51,27,28,24,28,27,28,29,51,51,51,51,51,51,51,27,28,28,45,45,45,45,45,28,28,29,51,51,64,51,64,51,51,64,51,25,8,8,8,8,8,7,8,8,26,51,27,28,28,28,28,28,45,45,45,45,45,29,
|
||||
51,27,28,29,51,51,51,27,28,28,28,27,28,29,51,51,51,51,51,51,51,27,28,28,28,28,28,28,28,28,28,29,51,51,64,51,64,51,51,64,51,27,28,28,28,24,28,28,28,28,29,51,27,58,28,28,58,28,28,28,28,28,58,28,
|
||||
51,27,28,29,51,51,51,27,28,28,28,27,24,29,51,51,51,51,51,51,51,27,28,28,28,28,24,28,28,28,28,29,51,51,64,51,64,51,51,64,51,27,24,28,28,28,28,28,28,28,29,51,27,28,28,28,28,28,28,28,58,28,28,28,
|
||||
51,27,28,29,51,51,51,27,28,28,28,27,28,29,51,51,51,51,51,51,51,27,28,28,28,28,28,28,28,28,28,29,51,51,64,51,64,51,51,64,51,27,28,28,28,28,28,28,28,28,29,51,27,28,58,28,28,28,28,28,28,28,28,28,
|
||||
};
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 10 KiB |
Plik diff jest za duży
Load Diff
Ładowanie…
Reference in New Issue