2020-01-31 23:45:16 +00:00
|
|
|
|
2022-08-09 19:39:27 +00:00
|
|
|
#include "common.h"
|
|
|
|
//#link "common.c"
|
2020-01-31 23:45:16 +00:00
|
|
|
|
2022-08-11 20:27:20 +00:00
|
|
|
#include <cbm_petscii_charmap.h>
|
|
|
|
|
2020-01-31 23:45:16 +00:00
|
|
|
sbyte scroll_fine_x = 0;
|
|
|
|
sbyte scroll_fine_y = 0;
|
|
|
|
byte* scrnbuf[2]; // screen buffer(s)
|
2022-08-11 20:27:20 +00:00
|
|
|
byte hidbuf = 0;
|
2020-01-31 23:45:16 +00:00
|
|
|
|
|
|
|
void scroll_update_regs() {
|
2022-08-11 20:27:20 +00:00
|
|
|
SET_SCROLL_X(scroll_fine_x);
|
|
|
|
SET_SCROLL_Y(scroll_fine_y);
|
2020-01-31 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_swap() {
|
|
|
|
// swap hidden and visible buffers
|
2022-08-11 20:27:20 +00:00
|
|
|
hidbuf ^= 1;
|
2023-11-29 17:15:55 +00:00
|
|
|
// wait for end of frame and update registers
|
|
|
|
wait_vblank();
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_update_regs();
|
2022-08-11 20:27:20 +00:00
|
|
|
SET_VIC_SCREEN(hidbuf ? 0x8000 : 0x8400);
|
2020-01-31 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_left() {
|
2022-08-11 20:27:20 +00:00
|
|
|
memcpy(scrnbuf[hidbuf], scrnbuf[hidbuf^1]+1, COLS*ROWS-1);
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_swap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_right() {
|
2022-08-11 20:27:20 +00:00
|
|
|
memcpy(scrnbuf[hidbuf]+1, scrnbuf[hidbuf^1], COLS*ROWS-1);
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_swap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_up() {
|
2022-08-11 20:27:20 +00:00
|
|
|
memcpy(scrnbuf[hidbuf], scrnbuf[hidbuf^1]+COLS, COLS*(ROWS-1));
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_swap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_down() {
|
2022-08-11 20:27:20 +00:00
|
|
|
memcpy(scrnbuf[hidbuf]+COLS, scrnbuf[hidbuf^1], COLS*(ROWS-1));
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_swap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_horiz(sbyte delta_x) {
|
|
|
|
scroll_fine_x += delta_x;
|
|
|
|
while (scroll_fine_x < 0) {
|
|
|
|
scroll_fine_x += 8;
|
|
|
|
scroll_left();
|
|
|
|
}
|
|
|
|
while (scroll_fine_x >= 8) {
|
|
|
|
scroll_fine_x -= 8;
|
|
|
|
scroll_right();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_vert(sbyte delta_y) {
|
|
|
|
scroll_fine_y += delta_y;
|
|
|
|
while (scroll_fine_y < 0) {
|
|
|
|
scroll_fine_y += 8;
|
|
|
|
scroll_up();
|
|
|
|
}
|
|
|
|
while (scroll_fine_y >= 8) {
|
|
|
|
scroll_fine_y -= 8;
|
|
|
|
scroll_down();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void scroll_setup() {
|
|
|
|
// get screen buffer addresses
|
|
|
|
scrnbuf[0] = (byte*) 0x8000;
|
|
|
|
scrnbuf[1] = (byte*) 0x8400;
|
2022-08-11 20:27:20 +00:00
|
|
|
|
2020-01-31 23:45:16 +00:00
|
|
|
// copy existing text to screen 0
|
|
|
|
memcpy(scrnbuf[0], (byte*)0x400, COLS*ROWS);
|
|
|
|
// copy screen 1 to screen 0
|
|
|
|
memcpy(scrnbuf[1], scrnbuf[0], COLS*ROWS);
|
|
|
|
|
2022-08-11 20:27:20 +00:00
|
|
|
// set VIC bank
|
2020-01-31 23:45:16 +00:00
|
|
|
// https://www.c64-wiki.com/wiki/VIC_bank
|
2022-08-11 20:27:20 +00:00
|
|
|
SET_VIC_BANK(0x8000);
|
|
|
|
|
|
|
|
VIC.ctrl1 &= ~0x08; // 24 lines
|
|
|
|
VIC.ctrl2 &= ~0x08; // 38 columns
|
2020-01-31 23:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main(void) {
|
|
|
|
|
|
|
|
clrscr();
|
2022-08-11 20:27:20 +00:00
|
|
|
printf("\n\n\n Hello World!");
|
|
|
|
printf("\n\n\n This is how we scroll");
|
|
|
|
printf("\n\n\n And now we have two buffers");
|
|
|
|
printf("\n\n\n And can go in any direction");
|
|
|
|
printf("\n\n\n But we are not incremental");
|
|
|
|
printf("\n\n\n And have to pause to scroll and copy");
|
2020-01-31 23:45:16 +00:00
|
|
|
|
|
|
|
scroll_setup();
|
2022-08-11 20:27:20 +00:00
|
|
|
VIC.bordercolor = COLOR_GRAY1;
|
2020-01-31 23:45:16 +00:00
|
|
|
|
|
|
|
// install the joystick driver
|
|
|
|
joy_install (joy_static_stddrv);
|
|
|
|
|
|
|
|
// infinite loop
|
|
|
|
while (1) {
|
|
|
|
// get joystick bits
|
2024-10-30 18:58:10 +00:00
|
|
|
char joy = joy_read(1);
|
2020-01-31 23:45:16 +00:00
|
|
|
// move sprite based on arrow keys
|
|
|
|
if (JOY_LEFT(joy)) scroll_horiz(-1);
|
|
|
|
if (JOY_UP(joy)) scroll_vert(-1);
|
|
|
|
if (JOY_RIGHT(joy)) scroll_horiz(1);
|
|
|
|
if (JOY_DOWN(joy)) scroll_vert(1);
|
|
|
|
// update regs
|
2022-08-09 19:39:27 +00:00
|
|
|
waitvsync();
|
2020-01-31 23:45:16 +00:00
|
|
|
scroll_update_regs();
|
|
|
|
}
|
|
|
|
}
|