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