]> git.sur5r.net Git - cc65/blob - testcode/lib/mousetest.c
Added the mousedemo program, changed some makefile rules
[cc65] / testcode / lib / mousetest.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <mouse.h>
4 #include <conio.h>
5
6
7
8 #if defined(__C64__) || defined(__C128__)
9
10 /* Address of data for sprite 1 */
11 #define SPRITE1_DATA    0x340
12
13 /* The mouse sprite (an arrow) */
14 static const unsigned char MouseSprite[64] = {
15     0x00, 0x00, 0x00,
16     0x00, 0x00, 0x00,
17     0x00, 0x00, 0x00,
18     0x0F, 0xE0, 0x00,
19     0x0F, 0xC0, 0x00,
20     0x0F, 0x80, 0x00,
21     0x0F, 0xC0, 0x00,
22     0x0D, 0xE0, 0x00,
23     0x08, 0xF0, 0x00,
24     0x00,  120, 0x00,
25     0x00,   60, 0x00,
26     0x00,   30, 0x00,
27     0x00, 0x0F, 0x00,
28     0x00, 0x07, 0x80,
29     0x00, 0x03, 0x80,
30     0x00, 0x00, 0x00,
31     0x00, 0x00, 0x00,
32     0x00, 0x00, 0x00,
33     0x00, 0x00, 0x00,
34     0x00, 0x00, 0x00,
35     0x00, 0x00, 0x00,
36     0x00
37 };
38
39 #endif
40
41
42 static void ShowState (unsigned char Invisible)
43 /* Display cursor visibility */
44 {
45     gotoxy (0, 6);
46     cclear (40);
47     gotoxy (0, 6);
48     cprintf ("Mouse cursor %svisible", Invisible? "in" : "");
49 }
50
51
52
53 int main (void)
54 {
55     struct mouse_info info;
56     unsigned char Invisible;
57
58     /* Clear the screen, set white on black */
59     bordercolor (COLOR_BLACK);
60     bgcolor (COLOR_BLACK);
61     textcolor (COLOR_GRAY3);
62     cursor (0);
63     clrscr ();
64
65     /* Print a help line */
66     cputsxy (0, 0, "s = show    h = hide    q = quit");
67
68 #if defined(__C64__) || defined(__C128__)
69     /* Copy the sprite data */
70     memcpy ((void*) SPRITE1_DATA, MouseSprite, sizeof (MouseSprite));
71
72     /* Set the VIC sprite pointer */
73     *(unsigned char*)0x7F8 = SPRITE1_DATA / 64;
74
75     /* Set the color of sprite 0 */
76     VIC.spr0_color = COLOR_WHITE;
77
78     /* Initialize the mouse */
79     mouse_init (0, 1, MOUSE_C64);
80 #endif
81
82     /* Move the mouse to the center of the screen */
83     mouse_move (160, 100);
84
85     /* Test loop */
86     ShowState (Invisible = 1);
87     while (1) {
88         if (kbhit()) {
89             switch (cgetc()) {
90                 case 's':
91                     if (Invisible) {
92                         ShowState (--Invisible);
93                         mouse_show ();
94                     }
95                     break;
96                 case 'h':
97                     ShowState (++Invisible);
98                     mouse_hide ();
99                     break;
100                 case 'q':
101                     mouse_done ();
102                     exit (0);
103             }
104         }
105
106         /* Get the current mouse coordinates and button states and print them */
107         mouse_info (&info);
108         gotoxy (0, 2);
109         cprintf ("X  = %3d", info.pos.x);
110         gotoxy (0, 3);
111         cprintf ("Y  = %3d", info.pos.y);
112         gotoxy (0, 4);
113         cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
114         gotoxy (0, 5);
115         cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
116
117     }
118     return 0;
119 }
120
121
122
123