]> git.sur5r.net Git - cc65/blob - samples/mousedemo.c
Fix mouse type
[cc65] / samples / mousedemo.c
1 /*
2  * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari
3  *
4  * Ullrich von Bassewitz, 13.09.2001
5  *
6  */
7
8
9
10 #include <stdlib.h>
11 #include <string.h>
12 #include <mouse.h>
13 #include <conio.h>
14 #include <dbg.h>
15
16
17
18 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
19
20 /* Address of data for sprite 0 */
21 #if defined(__C64__)
22 #  define SPRITE0_DATA    0x0340
23 #  define SPRITE0_PTR     0x07F8
24 #elif defined(__C128__)
25 #  define SPRITE0_DATA    0x0E00
26 #  define SPRITE0_PTR     0x07F8
27 #elif defined(__CBM510__)
28 #  define SPRITE0_DATA    0xF800
29 #  define SPRITE0_PTR     0xF7F8
30 #endif
31
32 /* The mouse sprite (an arrow) */
33 static const unsigned char MouseSprite[64] = {
34     0x00, 0x00, 0x00,
35     0x00, 0x00, 0x00,
36     0x00, 0x00, 0x00,
37     0x0F, 0xE0, 0x00,
38     0x0F, 0xC0, 0x00,
39     0x0F, 0x80, 0x00,
40     0x0F, 0xC0, 0x00,
41     0x0D, 0xE0, 0x00,
42     0x08, 0xF0, 0x00,
43     0x00, 0x78, 0x00,
44     0x00, 0x3C, 0x00,
45     0x00, 0x1E, 0x00,
46     0x00, 0x0F, 0x00,
47     0x00, 0x07, 0x80,
48     0x00, 0x03, 0x80,
49     0x00, 0x00, 0x00,
50     0x00, 0x00, 0x00,
51     0x00, 0x00, 0x00,
52     0x00, 0x00, 0x00,
53     0x00, 0x00, 0x00,
54     0x00, 0x00, 0x00,
55     0x00
56 };
57
58 #endif  /* __C64__ or __C128__ */
59
60
61
62 static void ShowState (unsigned char Invisible)
63 /* Display cursor visibility */
64 {
65     gotoxy (0, 6);
66     cclear (40);
67     gotoxy (0, 6);
68     cprintf ("Mouse cursor %svisible", Invisible? "in" : "");
69 }
70
71
72
73 int main (void)
74 {
75     struct mouse_info info;
76     unsigned char Invisible;
77     unsigned char Done;
78
79     /* Initialize the debugger */
80     DbgInit (0);
81
82     /* Clear the screen, set white on black */
83     bordercolor (COLOR_BLACK);
84     bgcolor (COLOR_BLACK);
85     textcolor (COLOR_GRAY3);
86     cursor (0);
87     clrscr ();
88
89     /* Print a help line */
90     revers (1);
91     cputsxy (0, 0, "d: debug   h: hide   q: quit   s: show  ");
92     revers (0);
93
94 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
95     /* Copy the sprite data */
96     memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
97
98     /* Set the VIC sprite pointer */
99     *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
100
101     /* Set the color of sprite 0 */
102     VIC.spr0_color = COLOR_WHITE;
103
104     /* Initialize the mouse */
105     mouse_init (MOUSE_CBM1351);
106
107 #elif defined(__ATARI__)
108
109     /* Initialize the mouse */
110     mouse_init (MOUSE_TRAKBALL);
111
112 #endif
113
114     /* Test loop */
115     Done = 0;
116     ShowState (Invisible = 1);
117     while (!Done) {
118         if (kbhit()) {
119             switch (cgetc()) {
120                 case 'd':
121                     BREAK();
122                     break;
123                 case 'h':
124                     ShowState (++Invisible);
125                     mouse_hide ();
126                     break;
127                 case 's':
128                     if (Invisible) {
129                         ShowState (--Invisible);
130                         mouse_show ();
131                     }
132                     break;
133                 case 'q':
134                     Done = 1;
135                     break;
136             }
137         }
138
139         /* Get the current mouse coordinates and button states and print them */
140         mouse_info (&info);
141         gotoxy (0, 2);
142         cprintf ("X  = %3d", info.pos.x);
143         gotoxy (0, 3);
144         cprintf ("Y  = %3d", info.pos.y);
145         gotoxy (0, 4);
146         cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
147         gotoxy (0, 5);
148         cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
149
150     }
151
152     mouse_done ();
153     clrscr ();
154     cputs ("Goodbye!\r\n");
155
156     return EXIT_SUCCESS;
157 }
158
159
160