1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-01 05:41:31 +00:00
8bitworkshop/presets/c64/scroll4.c

95 lines
2.3 KiB
C
Raw Normal View History

2022-07-20 19:32:47 +00:00
#include "common.h"
//#link "common.c"
2022-07-20 19:32:47 +00:00
#include "scrolling.h"
//#link "scrolling.c"
2022-07-20 19:32:47 +00:00
#include "sprites.h"
//#link "sprites.c"
2022-08-11 20:27:20 +00:00
#include <cbm_petscii_charmap.h>
2022-07-20 19:32:47 +00:00
static void draw_cell(word ofs, byte x, byte y) {
byte xx = x + origin_x;
byte yy = y + origin_y;
byte ch = xx ^ yy;
2022-07-20 19:32:47 +00:00
hidbuf[ofs] = ch; // character
colorbuf[ofs] = ch; // color
}
void scroll_draw_column(byte col) {
byte y;
2022-07-20 19:32:47 +00:00
word ofs = col;
for (y=0; y<ROWS; y++) {
2022-07-20 19:32:47 +00:00
draw_cell(ofs, col, y);
ofs += COLS;
}
}
void scroll_draw_row(byte row) {
byte x;
2022-07-20 19:32:47 +00:00
word ofs = row * COLS;
for (x=0; x<COLS; x++) {
2022-07-20 19:32:47 +00:00
draw_cell(ofs, x, row);
++ofs;
}
}
2022-07-20 19:32:47 +00:00
/*{w:24,h:21,bpp:1,brev:1}*/
const char SPRITE1[3*21] = {
2022-08-09 14:47:55 +00:00
0x80,0x7F,0x01,0x01,0xFF,0xC0,0x03,0xFF,0xE0,
2022-07-20 19:32:47 +00:00
0x03,0xE7,0xE0,0x07,0xD9,0xF0,0x07,0xDF,0xF0,
0x07,0xD9,0xF0,0x03,0xE7,0xE0,0x03,0xFF,0xE0,
0x03,0xFF,0xE0,0x02,0xFF,0xA0,0x01,0x7F,0x40,
0x01,0x3E,0x40,0x00,0x9C,0x80,0x00,0x9C,0x80,
0x00,0x49,0x00,0x00,0x49,0x00,0x00,0x3E,0x00,
2022-08-09 14:47:55 +00:00
0x00,0x3E,0x00,0x00,0x3E,0x00,0x80,0x1C,0x01
2022-07-20 19:32:47 +00:00
};
void main(void) {
2022-07-20 19:32:47 +00:00
byte n = 0;
clrscr();
printf("\r\n\r\n\r\n Hello World!");
printf("\r\n\r\n\r\n This is how we scroll");
printf("\r\n\r\n\r\n But color RAM can't move");
printf("\r\n\r\n\r\n So we have to use a temp buffer");
printf("\r\n\r\n\r\n And copy it just in time");
2022-07-20 19:32:47 +00:00
// setup scrolling library
scroll_setup();
2022-08-11 20:27:20 +00:00
VIC.bordercolor = 12;
2022-07-20 19:32:47 +00:00
// setup sprite library and copy sprite to VIC bank
sprite_clear();
2022-08-11 20:27:20 +00:00
sprite_set_shapes(SPRITE1, 192, 1);
2022-07-20 19:32:47 +00:00
// install the joystick driver
joy_install (joy_static_stddrv);
// infinite loop
while (1) {
2022-07-20 19:32:47 +00:00
static char speed = 1;
// get joystick bits
char joy = joy_read(0);
2022-07-20 19:32:47 +00:00
// speed up scrolling while button pressed
speed = JOY_BTN_1(joy) ? 2 : 1;
// move sprite based on arrow keys
2022-07-20 19:32:47 +00:00
if (JOY_LEFT(joy)) scroll_horiz(-speed);
if (JOY_UP(joy)) scroll_vert(-speed);
if (JOY_RIGHT(joy)) scroll_horiz(speed);
if (JOY_DOWN(joy)) scroll_vert(speed);
// animate sprite in shadow sprite ram
2022-08-09 14:47:55 +00:00
sprite_draw(0, n++, 70, 192);
sprite_draw(0, 172, 145, 192);
2023-11-29 17:15:55 +00:00
// wait for end of frame
wait_vblank();
2022-07-20 19:32:47 +00:00
// update scroll registers
// and swap screens if we must
scroll_update();
// then update sprite registers
sprite_update(visbuf);
}
}