]> git.sur5r.net Git - cc65/commitdiff
small demo of system vectors interception
authorizydorst <izydorst@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 15 Aug 2003 23:07:20 +0000 (23:07 +0000)
committerizydorst <izydorst@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 15 Aug 2003 23:07:20 +0000 (23:07 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2338 b7a2c559-68d2-44c3-8de9-860c34a00d81

samples/geos/appvector-demo.grc [new file with mode: 0644]
samples/geos/vector-demo.c [new file with mode: 0644]

diff --git a/samples/geos/appvector-demo.grc b/samples/geos/appvector-demo.grc
new file mode 100644 (file)
index 0000000..57547fb
--- /dev/null
@@ -0,0 +1,8 @@
+
+; this is resource file for yesno.c, a GEOS application example
+
+HEADER APPLICATION "vectordemo" "VectorDemo" "V1.0" {
+dostype USR
+author "Maciej Witkowiak"
+info "This is C prog compiled with cc65 and GEOSLib."
+}
diff --git a/samples/geos/vector-demo.c b/samples/geos/vector-demo.c
new file mode 100644 (file)
index 0000000..a558e1f
--- /dev/null
@@ -0,0 +1,71 @@
+
+#include <geos.h>
+#include <conio.h>
+#include <stdlib.h>
+
+unsigned char x,y;
+
+void (*oldMouseVector)();
+void (*oldKeyVector)();
+
+void foo1 (void) {
+    // do something on mouse press/release
+    gotoxy(x,y);
+    ++x;
+    cputc('A');
+    // call previous routine
+    oldMouseVector();
+}
+
+void foo2 (void) {
+    // do something on key press/release
+    gotoxy(x,y);
+    ++y;
+    cputc('B');
+    // call previous routine
+    oldKeyVector();
+}
+
+void hook_into_system(void) {
+    // hook into system vectors - preserve old value
+    oldMouseVector = (void (*)())mouseVector;
+    mouseVector = (int)foo1;
+    oldKeyVector = (void (*)())keyVector;
+    keyVector = (int)foo2;
+}
+
+void remove_hooks(void) {
+    mouseVector = (int)oldMouseVector;
+    keyVector = (int)oldKeyVector;
+}
+
+int main(void) {
+
+    x = 0;
+    y = 0;
+
+/*
+    To make cc65 do something for you before exiting you might register
+    a function to be called using atexit call. #include <stdlib.h> then and
+    write:
+*/
+    atexit(&remove_hooks);
+
+    clrscr();
+    cputsxy(0,1, CBOLDON "Just" COUTLINEON  "a " CITALICON "string." CPLAINTEXT );
+
+    hook_into_system();
+
+/* This program will loop forever though */
+
+    MainLoop();
+
+/*
+    If not using atexit() you have to remember about restoring system vectors
+    right before exiting your application. Otherwise the system will most
+    likely crash.
+
+    remove_hooks();
+*/
+    return 0;
+}