From 9edd8087d350efdaef4370a4fc2ca7996a6687e4 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 13 Sep 2001 15:58:32 +0000 Subject: [PATCH] Added the mousedemo program, changed some makefile rules git-svn-id: svn://svn.cc65.org/cc65/trunk@904 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- samples/.cvsignore | 1 + samples/Makefile | 16 +++-- samples/c1541.rsp | 9 --- samples/mousedemo.c | 157 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 15 deletions(-) delete mode 100644 samples/c1541.rsp create mode 100644 samples/mousedemo.c diff --git a/samples/.cvsignore b/samples/.cvsignore index 65f1ae933..247064f3c 100644 --- a/samples/.cvsignore +++ b/samples/.cvsignore @@ -1,6 +1,7 @@ nachtm hello sieve +mousedemo *.map *.d64 *.s diff --git a/samples/Makefile b/samples/Makefile index b0124a3fd..2b627c528 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -18,7 +18,7 @@ C1541 = c1541 .c.o: @echo $< - @$(CC) -Oirs --codesize 500 -g -t $(SYS) -I../include/ $< + @$(CC) -Oirs -T --codesize 500 -g -t $(SYS) -I../include/ $< @$(AS) $(basename $<).s .s.o: @@ -27,7 +27,7 @@ C1541 = c1541 .PHONY: all -all: nachtm hello sieve +all: nachtm hello sieve mousedemo nachtm: $(CRT0) nachtm.o $(CLIB) @$(LD) -t $(SYS) -m nachtm.map -Ln nachtm.lbl -o $@ $^ @@ -38,11 +38,15 @@ hello: $(CRT0) hello.o $(CLIB) sieve: $(CRT0) sieve.o $(CLIB) @$(LD) -t $(SYS) -m sieve.map -Ln sieve.lbl -o $@ $^ +mousedemo: $(CRT0) mousedemo.o $(CLIB) + @$(LD) -t $(SYS) -m mousedemo.map -Ln mousedemo.lbl -o $@ $^ + .PHONY: disk -disk: c64.d64 +disk: samples.d64 -c64.d64: all - $(C1541) < c1541.rsp +samples.d64: all + $(C1541) -format samples,AA d64 $@ + $(C1541) -attach $@ -write nachtm -write hello -write sieve -write mousedemo .PHONY: clean clean: @@ -50,7 +54,7 @@ clean: .PHONY: zap zap: clean - rm -f nachtm hello + rm -f nachtm hello sieve mousedemo samples.d64 diff --git a/samples/c1541.rsp b/samples/c1541.rsp deleted file mode 100644 index 0c46decc9..000000000 --- a/samples/c1541.rsp +++ /dev/null @@ -1,9 +0,0 @@ -att c64.d64 - -delete nachtm -delete hello -write nachtm -write hello -quit - - diff --git a/samples/mousedemo.c b/samples/mousedemo.c new file mode 100644 index 000000000..07998f85f --- /dev/null +++ b/samples/mousedemo.c @@ -0,0 +1,157 @@ +/* + * Demo program for mouse usage. Will work for the C64/C128/Atari + * + * Ullrich von Bassewitz, 13.09.2001 + * + */ + + + +#include +#include +#include +#include +#include + + + +#if defined(__C64__) || defined(__C128__) + +/* Address of data for sprite 1 */ +#if defined(__C64__) +# define SPRITE0_DATA 0x340 +# define SPRITE0_PTR 0x7F8 +#elif defined(__C128__) +# define SPRITE0_DATA 0xE00 +# define SPRITE0_PTR 0x7F8 +#endif + +/* 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, 0x78, 0x00, + 0x00, 0x3C, 0x00, + 0x00, 0x1E, 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 /* __C64__ or __C128__ */ + + + +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_info info; + unsigned char Invisible; + unsigned char Done; + + /* Initialize the debugger */ + DbgInit (0); + + /* Clear the screen, set white on black */ + bordercolor (COLOR_BLACK); + bgcolor (COLOR_BLACK); + textcolor (COLOR_GRAY3); + cursor (0); + clrscr (); + + /* Print a help line */ + revers (1); + cputsxy (0, 0, "d: debug h: hide q: quit s: show "); + revers (0); + +#if defined(__C64__) || defined(__C128__) + /* Copy the sprite data */ + memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite)); + + /* Set the VIC sprite pointer */ + *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64; + + /* Set the color of sprite 0 */ + VIC.spr0_color = COLOR_WHITE; + + /* Initialize the mouse */ + mouse_init (MOUSE_C64); + +#elif defined(__ATARI__) + + /* Initialize the mouse */ + mouse_init (MOUSE_TRAKBALL); + +#endif + + /* Test loop */ + Done = 0; + ShowState (Invisible = 1); + while (!Done) { + if (kbhit()) { + switch (cgetc()) { + case 'd': + BREAK(); + break; + case 'h': + ShowState (++Invisible); + mouse_hide (); + break; + case 's': + if (Invisible) { + ShowState (--Invisible); + mouse_show (); + } + break; + case 'q': + Done = 1; + break; + } + } + + /* 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'); + + } + + mouse_done (); + clrscr (); + cputs ("Goodbye!\r\n"); + + return EXIT_SUCCESS; +} + + + -- 2.39.5