changeset 12:1ee4a5c23c95

Merge
author Mike Pavone <pavone@retrodev.com>
date Sun, 12 Jan 2014 17:07:43 -0800
parents c0bb53eaa6f4 (current diff) 889227ec630c (diff)
children d118fe8fb1db
files src/main.c
diffstat 1 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.c	Sun Jan 12 17:05:53 2014 -0800
+++ b/src/main.c	Sun Jan 12 17:07:43 2014 -0800
@@ -1,11 +1,76 @@
 #include <genesis.h>
 #include "creep.h"
 
+const u32 cursor_tiles[4*8] = {
+	0x21100000, // top left
+	0x10000000,
+	0x10000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+
+	0x00000000, // bottom left
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x10000000,
+	0x10000000,
+	0x21100000,
+
+	0x00000112, // top right
+	0x00000001,
+	0x00000001,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+
+	0x00000000, // bottom right
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000000,
+	0x00000001,
+	0x00000001,
+	0x00000112,
+
+};
+
 u16 tilemap[40*28];
 u16 countdown;
 
+int cursor_x = 0;
+int cursor_y = 0;
+const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each
+
+void joy_event_handler(u16 joy, u16 changed, u16 state) {
+	u16 went_down = changed & state;
+	if (went_down & BUTTON_UP) {
+		cursor_y -= cursor_size_px;
+	}
+	if (went_down & BUTTON_DOWN) {
+		cursor_y += cursor_size_px;
+	}
+	if (went_down & BUTTON_LEFT) {
+		cursor_x -= cursor_size_px;
+	}
+	if (went_down & BUTTON_RIGHT) {
+		cursor_x += cursor_size_px;
+	}
+}
+
 int main(void)
 {
+	JOY_init();
+	JOY_setEventHandler(&joy_event_handler);
+
+	u8 cursor_tile_index = 1;
+	VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0);
+
 	u16 i;
 	VDP_setPlanSize(64, 32);
 	for (i = 6; i < 40*28; i += 4)
@@ -23,6 +88,7 @@
 	//print_distances();
 	for (;;)
 	{
+		VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), 0);
 		VDP_waitVSync();
 		VDP_updateSprites();
 		for (i = 0; i < 28; i++)