1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-28 23:49:20 +00:00
8bitworkshop/presets/c64/scroll2.c

59 lines
1.4 KiB
C
Raw Normal View History

2022-08-09 19:39:27 +00:00
#include "common.h"
//#link "common.c"
2022-08-11 20:27:20 +00:00
#include <cbm_petscii_charmap.h>
2022-08-11 20:27:20 +00:00
#define BUFFER_0 0x400
#define BUFFER_1 0x3c00
byte scroll_x = 0; // x scroll position
byte* scrnbuf[2]; // screen buffer(s)
byte visbuf; // which buffer is visible? 0 or 1
void scroll_one_pixel_left() {
byte* src;
byte* dst;
2022-08-11 20:27:20 +00:00
// scroll left
scroll_x--;
// set scroll registers
SET_SCROLL_X(scroll_x);
// calculate frame pointers
// source = visible buffer
src = scrnbuf[visbuf] + (scroll_x & 7) * 128;
// destination = hidden buffer
dst = scrnbuf[visbuf ^ 1] + (scroll_x & 7) * 128;
// wait for vsync
waitvsync();
// scroll hidden buffer
memcpy(dst, src+1, 128);
// every 8 pixels, switch visible and hidden buffers
// and set VIC to point to other buffer
if ((scroll_x & 7) == 0) {
visbuf ^= 1;
SET_VIC_SCREEN(visbuf ? BUFFER_1 : BUFFER_0);
}
}
void main(void) {
clrscr();
2022-08-11 20:27:20 +00:00
printf("\n\n\n Hello Scrolling World!");
printf("\n\n\n We scroll in one direction");
printf("\n\n\n And now we have two buffers");
printf("\n\n\n And copy hidden -> visible");
printf("\n\n\n 128 bytes (of 1024) per frame");
VIC.ctrl1 = 0x10; // 24 lines
VIC.ctrl2 = 0x00; // 38 columns
2022-08-11 20:27:20 +00:00
VIC.bordercolor = COLOR_GRAY1;
// get screen buffer addresses
2022-08-11 20:27:20 +00:00
scrnbuf[0] = (byte*) BUFFER_0;
scrnbuf[1] = (byte*) BUFFER_1;
// infinite loop
while (1) {
2022-08-11 20:27:20 +00:00
scroll_one_pixel_left();
}
}