1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-23 03:29:39 +00:00
8bitworkshop/presets/c64/joymove.c

60 lines
1.8 KiB
C
Raw Normal View History

2019-12-21 21:06:25 +00:00
2022-08-09 19:39:27 +00:00
#include "common.h"
2019-12-21 21:06:25 +00:00
2022-08-09 14:47:55 +00:00
/*{w:24,h:21,bpp:1,brev:1,count:1}*/
const char SPRITE_DATA[64] = {
0x0f,0xff,0x80,0x17,0xff,0x40,0x2b,0xfe,
0xa0,0x7f,0xff,0xf0,0xff,0xc0,0x3f,0xe0,
0x3f,0xc0,0x17,0xbe,0xc0,0x2d,0x7f,0xf0,
0x2b,0x7f,0xf8,0x2a,0xff,0xf8,0x15,0xf6,
0x00,0x3f,0xf8,0x00,0xfd,0xfc,0x00,0xfd,
0xff,0x00,0xfe,0xff,0x80,0xff,0x7f,0xc0,
0xff,0xff,0xc0,0xff,0xff,0xc0,0x0a,0xa8,
0x00,0x0f,0xf8,0x00,0x0f,0xff,0x80,0x03,
2019-12-21 21:06:25 +00:00
};
2022-08-09 14:47:55 +00:00
void main(void) {
// variables
int x = 172; // sprite X position (16-bit)
2022-08-25 20:52:04 +00:00
byte y = 145; // sprite Y position (8-bit)
byte bgcoll; // sprite background collision flags
byte joy; // joystick flags
2019-12-21 21:06:25 +00:00
2022-08-09 14:47:55 +00:00
// copy sprite pattern to RAM address 0x3800
memcpy((char*)0x3800, SPRITE_DATA, sizeof(SPRITE_DATA));
// set sprite #0 shape entry (224)
2022-08-11 20:27:20 +00:00
POKE(0x400 + 0x3f8 + 0, 0x3800 / 64);
// set position and color
VIC.spr_pos[0].x = 172;
VIC.spr_pos[0].y = 145;
VIC.spr_color[0] = COLOR_GREEN;
2022-08-09 14:47:55 +00:00
// enable sprite #0
VIC.spr_ena = 0b00000001;
2022-08-11 20:27:20 +00:00
// install the joystick driver
joy_install (joy_static_stddrv);
2022-08-09 14:47:55 +00:00
// loop forever
2019-12-21 21:06:25 +00:00
while (1) {
// get joystick bits
2022-08-09 14:47:55 +00:00
joy = joy_read(0);
// move sprite based on joystick
2022-08-11 20:27:20 +00:00
if (JOY_LEFT(joy)) { x -= 1; } // move left 1 pixel
if (JOY_RIGHT(joy)) { x += 1; } // move right 1 pixel
if (JOY_UP(joy)) { y -= 1; } // move up 1 pixel
if (JOY_DOWN(joy)) { y += 1; } // move down 1 pixel
// wait for end of frame
waitvsync();
2022-08-09 14:47:55 +00:00
// set sprite registers based on position
2022-08-11 20:27:20 +00:00
VIC.spr_pos[0].x = x;
VIC.spr_pos[0].y = y;
// set X coordinate high bit
VIC.spr_hi_x = (x & 0x100) ? 1 : 0;
2022-08-09 14:47:55 +00:00
// grab and reset collision flags
2020-02-02 18:17:31 +00:00
bgcoll = VIC.spr_bg_coll;
2022-08-09 14:47:55 +00:00
// change color when we collide with background
2022-08-11 20:27:20 +00:00
VIC.spr_color[0] = (bgcoll & 1) ?
COLOR_LIGHTRED : COLOR_CYAN;
2020-02-02 18:17:31 +00:00
}
2019-12-21 21:06:25 +00:00
}