10 static void draw_cursor(int x, int y, uint16_t col);
11 static int click_sound_callback(void *buffer, int size, void *cls);
13 static uint16_t *framebuf;
17 static uint16_t cursor[] = {
18 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
19 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
20 0xffff, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
21 0xffff, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
22 0xffff, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
23 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
24 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
25 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000,
26 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000,
27 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000,
28 0xffff, 0x0001, 0x0001, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
29 0xffff, 0x0001, 0x0001, 0xffff, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
30 0xffff, 0x0001, 0xffff, 0xffff, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
31 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000,
32 0xffff, 0x0000, 0x0000, 0x0000, 0xffff, 0x0001, 0x0001, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000,
33 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
38 /* defined in sndsamples.s */
39 extern signed char snd_click[];
40 extern int snd_click_size;
44 int i, j, nmodes, mx, my, idx;
45 unsigned int st, prev_st = 0;
49 nmodes = video_mode_count();
50 printf("%d video modes found:\n", nmodes);
51 for(i=0; i<nmodes; i++) {
52 if(video_mode_info(i, &vi) == -1) {
55 printf(" %04x: %dx%d %d bpp", vi.mode, vi.width, vi.height, vi.bpp);
57 printf(" (%d%d%d)\n", vi.rbits, vi.gbits, vi.bbits);
63 if((idx = find_video_mode_idx(640, 480, 16)) == -1) {
66 video_mode_info(idx, &vi);
68 if(!(framebuf = set_video_mode(vi.mode))) {
71 get_color_bits(&vi.rbits, &vi.gbits, &vi.bbits);
72 get_color_shift(&vi.rshift, &vi.gshift, &vi.bshift);
73 get_color_mask(&vi.rmask, &vi.gmask, &vi.bmask);
76 for(i=0; i<480; i++) {
77 for(j=0; j<640; j++) {
79 uint16_t r = xor & 0xff;
80 uint16_t g = (xor << 1) & 0xff;
81 uint16_t b = (xor << 2) & 0xff;
87 *fbptr++ = ((r << vi.rshift) & vi.rmask) | ((g << vi.gshift) & vi.gmask) |
88 ((b << vi.bshift) & vi.bmask);
92 set_mouse_bounds(0, 0, 639, 479);
94 audio_set_callback(click_sound_callback, 0);
96 /* empty the kb queue */
97 while(kb_getkey() != -1);
100 if(kb_getkey() != -1) {
104 st = mouse_state(&mx, &my);
107 unsigned int bit = 1 << i;
108 if(((st & bit) ^ (prev_st & bit)) & (st & bit)) {
113 audio_play(22050, 1);
118 draw_cursor(mx, my, st & 1 ? 0xf800 : (st & 2 ? 0x7e0 : (st & 4 ? 0x00ff : 0)));
128 static void draw_cursor(int x, int y, uint16_t col)
130 static uint16_t saved[CURSOR_XSZ * CURSOR_YSZ];
131 static int saved_x = -1, saved_y, saved_w, saved_h;
134 uint16_t *dest, *src, *savp;
137 dest = framebuf + saved_y * 640 + saved_x;
140 for(i=0; i<saved_h; i++) {
141 for(j=0; j<saved_w; j++) {
144 src += CURSOR_XSZ - saved_w;
145 dest += 640 - saved_w;
149 dest = framebuf + y * 640 + x;
154 if(w > CURSOR_XSZ) w = CURSOR_XSZ;
156 if(h > CURSOR_YSZ) h = CURSOR_YSZ;
173 src += CURSOR_XSZ - w;
175 savp += CURSOR_XSZ - w;
179 /* snd_click_size is < 65536 so we can just throw it all at once in there */
180 static int click_sound_callback(void *buffer, int size, void *cls)
183 memcpy(buffer, snd_click, snd_click_size);
185 return snd_click_size;