annotate src/main.c @ 10:889227ec630c

cursor and input code added.
author William Morgan <bill@mrgn.org>
date Sun, 12 Jan 2014 16:13:49 -0800
parents 3ed112d64b1b
children 1ee4a5c23c95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <genesis.h>
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "creep.h"
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3
10
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
4 const u32 cursor_tiles[4*8] = {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
5 0x21100000, // top left
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
6 0x10000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
7 0x10000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
8 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
9 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
10 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
11 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
12 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
13
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
14 0x00000000, // bottom left
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
15 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
16 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
17 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
18 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
19 0x10000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
20 0x10000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
21 0x21100000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
22
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
23 0x00000112, // top right
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
24 0x00000001,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
25 0x00000001,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
26 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
27 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
28 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
29 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
30 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
31
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
32 0x00000000, // bottom right
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
33 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
34 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
35 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
36 0x00000000,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
37 0x00000001,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
38 0x00000001,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
39 0x00000112,
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
40
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
41 };
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
42
4
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
43 u16 tilemap[40*28];
7
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
44 u16 countdown;
4
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
45
10
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
46 int cursor_x = 0;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
47 int cursor_y = 0;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
48 const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
49
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
50 void joy_event_handler(u16 joy, u16 changed, u16 state) {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
51 u16 went_down = changed & state;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
52 if (went_down & BUTTON_UP) {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
53 cursor_y -= cursor_size_px;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
54 }
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
55 if (went_down & BUTTON_DOWN) {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
56 cursor_y += cursor_size_px;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
57 }
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
58 if (went_down & BUTTON_LEFT) {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
59 cursor_x -= cursor_size_px;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
60 }
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
61 if (went_down & BUTTON_RIGHT) {
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
62 cursor_x += cursor_size_px;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
63 }
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
64 }
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
65
2
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 int main(void)
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 {
10
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
68 JOY_init();
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
69 JOY_setEventHandler(&joy_event_handler);
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
70
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
71 u8 cursor_tile_index = 1;
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
72 VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0);
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
73
4
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
74 u16 i;
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
75 VDP_setPlanSize(64, 32);
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
76 for (i = 6; i < 40*28; i += 4)
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
77 if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38)
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
78 {
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
79 tilemap[i] = 'O' + TILE_FONTINDEX;
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
80 tilemap[i+1] = 'O' + TILE_FONTINDEX;
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
81 }
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
82
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
83 tilemap[38 + 13*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
84 tilemap[39 + 13*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
85 tilemap[38 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
86 tilemap[39 + 14*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
2
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 for (;;)
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 {
10
889227ec630c cursor and input code added.
William Morgan <bill@mrgn.org>
parents: 7
diff changeset
89 VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), 0);
2
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 VDP_waitVSync();
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 VDP_updateSprites();
4
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
92 for (i = 0; i < 28; i++)
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
93 {
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
94 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0);
d73f53857e5f Add placeholder walls and goal
Mike Pavone <pavone@retrodev.com>
parents: 2
diff changeset
95 }
7
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
96 if (cur_creeps < 4)
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
97 {
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
98 if (countdown)
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
99 --countdown;
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
100 else
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
101 {
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
102 spawn_creep(CREEP_NORMAL, 4, 122);
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
103 countdown = 300;
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
104 }
3ed112d64b1b Added basic creep spawning code
Mike Pavone <pavone@retrodev.com>
parents: 4
diff changeset
105 }
2
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 return 0;
8f23be2db808 Movec creep.h into the src folder. Added main loop
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 }