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 void *snd_click;
40 extern int snd_click_size;
44 int i, j, nmodes, mx, my;
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(!(framebuf = set_video_mode(find_video_mode(640, 480, 16)))) {
66 get_color_bits(&vi.rbits, &vi.gbits, &vi.bbits);
67 get_color_shift(&vi.rshift, &vi.gshift, &vi.bshift);
68 get_color_mask(&vi.rmask, &vi.gmask, &vi.bmask);
71 for(i=0; i<480; i++) {
72 for(j=0; j<640; j++) {
74 uint16_t r = xor & 0xff;
75 uint16_t g = (xor << 1) & 0xff;
76 uint16_t b = (xor << 2) & 0xff;
82 *fbptr++ = ((r << vi.rshift) & vi.rmask) | ((g << vi.gshift) & vi.gmask) |
83 ((b << vi.bshift) & vi.bmask);
87 set_mouse_bounds(0, 0, 639, 479);
89 audio_set_callback(click_sound_callback, 0);
91 /* empty the kb queue */
92 while(kb_getkey() != -1);
95 if(kb_getkey() != -1) {
99 st = mouse_state(&mx, &my);
102 unsigned int bit = 1 << i;
103 if(((st & bit) ^ (prev_st & bit)) & (st & bit)) {
109 audio_play(22050, 1);
114 draw_cursor(mx, my, st & 1 ? 0xf800 : (st & 2 ? 0x7e0 : (st & 4 ? 0x00ff : 0)));
124 static void draw_cursor(int x, int y, uint16_t col)
126 static uint16_t saved[CURSOR_XSZ * CURSOR_YSZ];
127 static int saved_x = -1, saved_y, saved_w, saved_h;
130 uint16_t *dest, *src, *savp;
133 dest = framebuf + saved_y * 640 + saved_x;
136 for(i=0; i<saved_h; i++) {
137 for(j=0; j<saved_w; j++) {
140 src += CURSOR_XSZ - saved_w;
141 dest += 640 - saved_w;
145 dest = framebuf + y * 640 + x;
150 if(w > CURSOR_XSZ) w = CURSOR_XSZ;
152 if(h > CURSOR_YSZ) h = CURSOR_YSZ;
169 src += CURSOR_XSZ - w;
171 savp += CURSOR_XSZ - w;
175 /* snd_click_size is < 65536 so we can just throw it all at once in there */
176 static int click_sound_callback(void *buffer, int size, void *cls)
179 memcpy(buffer, snd_click, snd_click_size);
181 return snd_click_size;