73 lines
1.4 KiB
C
73 lines
1.4 KiB
C
/**
|
|
* @file main.c
|
|
* @author giomba@glgprograms.it
|
|
* @brief
|
|
*
|
|
* @copyright Copyright Retrofficina GLG Programs (c) 2022
|
|
*
|
|
*/
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "draw_demo.h"
|
|
#include "framebuffer.h"
|
|
#include "vga.h"
|
|
#include "crtc.h"
|
|
|
|
extern int crtc_frame_counter;
|
|
extern int dma_counter;
|
|
|
|
int main()
|
|
{
|
|
stdio_init_all();
|
|
sleep_ms(5000);
|
|
|
|
// draw_demo();
|
|
// horizontal lines
|
|
draw_line(0, 0, 640 - 1, 0, true);
|
|
draw_line(0, 240 - 1, 640 - 1, 240 - 1, true);
|
|
draw_line(0, 480 - 1, 640 - 1, 480 - 1, true);
|
|
|
|
// vertical lines
|
|
draw_line(0, 0, 0, 480 - 1, true);
|
|
draw_line(320 - 1, 0, 320 - 1, 480 - 1, true);
|
|
draw_line(638, 0, 638, 480 - 1, true); // last pixel of a line can't be set, see set_pixel()
|
|
|
|
vga_machines_init();
|
|
|
|
sleep_ms(10);
|
|
|
|
crtc_machines_init();
|
|
|
|
printf("All ready: OK\n");
|
|
|
|
for (;;)
|
|
{
|
|
printf("CRTC frames: %d\n", crtc_frame_counter);
|
|
printf("DMA counter: %d\n", dma_counter);
|
|
sleep_ms(1000);
|
|
}
|
|
|
|
for (;;)
|
|
{
|
|
// moving sine
|
|
const uint16_t fc = vga_get_frame_counter();
|
|
const uint16_t x = fc % 640;
|
|
const uint16_t y = 380 + 100 * (abs(320 - x) / 640.0) * sin((fc % 640) / 12.738);
|
|
|
|
set_pixel(x, y);
|
|
|
|
// 13 ms <=> 75 Hz
|
|
// Actually, there is a point in going in sync with vertical refresh,
|
|
// but let's just forget this for the demo.
|
|
sleep_ms(13);
|
|
|
|
clear_pixel(x, y);
|
|
}
|
|
}
|