]> git.sur5r.net Git - cc65/blob - samples/geos/vector-demo.c
Latest versions of startup code and config by Karri Kaksonen. Citing: The new
[cc65] / samples / geos / vector-demo.c
1
2 #include <geos.h>
3 #include <conio.h>
4 #include <stdlib.h>
5
6 unsigned char x,y;
7
8 void_func oldMouseVector, oldKeyVector;
9
10 void foo1 (void) {
11     // do something on mouse press/release
12     gotoxy(x,y);
13     ++x;
14     cputc('A');
15     // call previous routine
16     oldMouseVector();
17 }
18
19 void foo2 (void) {
20     // do something on key press/release
21     gotoxy(x,y);
22     ++y;
23     cputc('B');
24     // call previous routine
25     oldKeyVector();
26 }
27
28 void hook_into_system(void) {
29     // hook into system vectors - preserve old value
30     oldMouseVector = mouseVector;
31     mouseVector = foo1;
32     oldKeyVector = keyVector;
33     keyVector = foo2;
34 }
35
36 void remove_hooks(void) {
37     mouseVector = oldMouseVector;
38     keyVector = oldKeyVector;
39 }
40
41 int main(void) {
42
43     x = 0;
44     y = 0;
45
46 /*
47     To make cc65 do something for you before exiting you might register
48     a function to be called using atexit call. #include <stdlib.h> then and
49     write:
50 */
51     atexit(&remove_hooks);
52
53     clrscr();
54     cputsxy(0,1, CBOLDON "Just" COUTLINEON  "a " CITALICON "string." CPLAINTEXT );
55
56     hook_into_system();
57
58 /* This program will loop forever though */
59
60     MainLoop();
61
62 /*
63     If not using atexit() you have to remember about restoring system vectors
64     right before exiting your application. Otherwise the system will most
65     likely crash.
66
67     remove_hooks();
68 */
69     return 0;
70 }