X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Ftest%2Fvbetest.c;h=7dd2bada24e6d531fe980a7e5944ba76f664429f;hp=1133decb769ddbb18a778d3c32691efc9326b295;hb=81c11bdd80190ec319a82b0402173cfb65fcbf72;hpb=5e8cc93aaf1173688852acaa0825698c2dc0cb3f diff --git a/src/test/vbetest.c b/src/test/vbetest.c index 1133dec..7dd2bad 100644 --- a/src/test/vbetest.c +++ b/src/test/vbetest.c @@ -5,8 +5,10 @@ #include "keyb.h" #include "psaux.h" #include "contty.h" +#include "audio.h" static void draw_cursor(int x, int y, uint16_t col); +static int click_sound_callback(void *buffer, int size, void *cls); static uint16_t *framebuf; @@ -31,10 +33,16 @@ static uint16_t cursor[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; +static int click; + +/* defined in sndsamples.s */ +extern signed char snd_click[]; +extern int snd_click_size; + int vbetest(void) { - int i, j, nmodes, mx, my; - unsigned int st; + int i, j, nmodes, mx, my, idx; + unsigned int st, prev_st = 0; struct video_mode vi; uint16_t *fbptr; @@ -52,7 +60,12 @@ int vbetest(void) } } - if(!(framebuf = set_video_mode(find_video_mode(640, 480, 16)))) { + if((idx = find_video_mode_idx(640, 480, 16)) == -1) { + return -1; + } + video_mode_info(idx, &vi); + + if(!(framebuf = set_video_mode(vi.mode))) { return -1; } get_color_bits(&vi.rbits, &vi.gbits, &vi.bbits); @@ -78,6 +91,8 @@ int vbetest(void) set_mouse_bounds(0, 0, 639, 479); + audio_set_callback(click_sound_callback, 0); + /* empty the kb queue */ while(kb_getkey() != -1); @@ -87,6 +102,19 @@ int vbetest(void) } st = mouse_state(&mx, &my); + + for(i=0; i<3; i++) { + unsigned int bit = 1 << i; + if(((st & bit) ^ (prev_st & bit)) & (st & bit)) { + click = 1; + } + } + if(click) { + audio_play(22050, 1); + } + + prev_st = st; + draw_cursor(mx, my, st & 1 ? 0xf800 : (st & 2 ? 0x7e0 : (st & 4 ? 0x00ff : 0))); halt_cpu(); @@ -147,3 +175,14 @@ static void draw_cursor(int x, int y, uint16_t col) savp += CURSOR_XSZ - w; } } + +/* snd_click_size is < 65536 so we can just throw it all at once in there */ +static int click_sound_callback(void *buffer, int size, void *cls) +{ + if(click) { + memcpy(buffer, snd_click, snd_click_size); + click = 0; + return snd_click_size; + } + return 0; +}