]> git.sur5r.net Git - cc65/blob - samples/mousedemo.c
CBM510 update
[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    0xF400
29 #  define SPRITE0_PTR     0xF3F8
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 #ifdef __CBM510__
103     pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
104 #else
105     VIC.spr0_color = COLOR_WHITE;
106 #endif
107
108     /* Initialize the mouse */
109     mouse_init (MOUSE_CBM1351);
110
111 #elif defined(__ATARI__)
112
113     /* Initialize the mouse */
114     mouse_init (MOUSE_TRAKBALL);
115
116 #endif
117
118     /* Test loop */
119     Done = 0;
120     ShowState (Invisible = 1);
121     while (!Done) {
122         if (kbhit()) {
123             switch (cgetc()) {
124                 case 'd':
125                     BREAK();
126                     break;
127                 case 'h':
128                     ShowState (++Invisible);
129                     mouse_hide ();
130                     break;
131                 case 's':
132                     if (Invisible) {
133                         ShowState (--Invisible);
134                         mouse_show ();
135                     }
136                     break;
137                 case 'q':
138                     Done = 1;
139                     break;
140             }
141         }
142
143         /* Get the current mouse coordinates and button states and print them */
144         mouse_info (&info);
145         gotoxy (0, 2);
146         cprintf ("X  = %3d", info.pos.x);
147         gotoxy (0, 3);
148         cprintf ("Y  = %3d", info.pos.y);
149         gotoxy (0, 4);
150         cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
151         gotoxy (0, 5);
152         cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
153
154     }
155
156     mouse_done ();
157     clrscr ();
158     cputs ("Goodbye!\r\n");
159
160     return EXIT_SUCCESS;
161 }
162
163
164