From cf4555f1015fdd728b84611c571a6f4bad7e1047 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 9 Sep 2001 16:47:34 +0000 Subject: [PATCH] Module checked in last time was wrong version git-svn-id: svn://svn.cc65.org/cc65/trunk@884 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- testcode/lib/mousetest.c | 113 +++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 11 deletions(-) diff --git a/testcode/lib/mousetest.c b/testcode/lib/mousetest.c index d230b51c7..7b031f0ac 100644 --- a/testcode/lib/mousetest.c +++ b/testcode/lib/mousetest.c @@ -1,32 +1,123 @@ #include +#include #include #include +#if defined(__C64__) || defined(__C128__) + +/* Address of data for sprite 1 */ +#define SPRITE1_DATA 0x340 + +/* The mouse sprite (an arrow) */ +static const unsigned char MouseSprite[64] = { + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x0F, 0xE0, 0x00, + 0x0F, 0xC0, 0x00, + 0x0F, 0x80, 0x00, + 0x0F, 0xC0, 0x00, + 0x0D, 0xE0, 0x00, + 0x08, 0xF0, 0x00, + 0x00, 120, 0x00, + 0x00, 60, 0x00, + 0x00, 30, 0x00, + 0x00, 0x0F, 0x00, + 0x00, 0x07, 0x80, + 0x00, 0x03, 0x80, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00 +}; + +#endif + + +static void ShowState (unsigned char Invisible) +/* Display cursor visibility */ +{ + gotoxy (0, 6); + cclear (40); + gotoxy (0, 6); + cprintf ("Mouse cursor %svisible", Invisible? "in" : ""); +} + + + int main (void) { - struct mouse_pos pos; + struct mouse_info info; + unsigned char Invisible; + /* Clear the screen, set white on black */ + bordercolor (COLOR_BLACK); + bgcolor (COLOR_BLACK); + textcolor (COLOR_GRAY3); + cursor (0); clrscr (); - mouse_init (1, 1, MOUSE_C64); -/* mouse_box (0, 29, 344, 250); */ + + /* Print a help line */ + cputsxy (0, 0, "s = show h = hide q = quit"); + +#if defined(__C64__) || defined(__C128__) + /* Copy the sprite data */ + memcpy ((void*) SPRITE1_DATA, MouseSprite, sizeof (MouseSprite)); + + /* Set the VIC sprite pointer */ + *(unsigned char*)0x7F8 = SPRITE1_DATA / 64; + + /* Set the color of sprite 0 */ + VIC.spr0_color = COLOR_WHITE; + + /* Initialize the mouse */ + mouse_init (0, 1, MOUSE_C64); +#endif + + /* Move the mouse to the center of the screen */ + mouse_move (160, 100); + + /* Test loop */ + ShowState (Invisible = 1); while (1) { if (kbhit()) { switch (cgetc()) { - case 's': mouse_show (); break; - case 'h': mouse_hide (); break; - case 'q': mouse_done (); exit (0); + case 's': + if (Invisible) { + ShowState (--Invisible); + mouse_show (); + } + break; + case 'h': + ShowState (++Invisible); + mouse_hide (); + break; + case 'q': + mouse_done (); + exit (0); } } - mouse_pos (&pos); - gotoxy (0, 0); - cprintf ("%04X", pos.x); - gotoxy (0, 1); - cprintf ("%04X", pos.y); + + /* Get the current mouse coordinates and button states and print them */ + mouse_info (&info); + gotoxy (0, 2); + cprintf ("X = %3d", info.pos.x); + gotoxy (0, 3); + cprintf ("Y = %3d", info.pos.y); + gotoxy (0, 4); + cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0'); + gotoxy (0, 5); + cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0'); + } return 0; } + -- 2.39.2