forgot to implement mouse calls for djgpp. moved it to mouse.asm
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 19 Feb 2018 10:06:32 +0000 (12:06 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 19 Feb 2018 10:06:32 +0000 (12:06 +0200)
Makefile.dj
src/dos/main.c
src/dos/mouse.asm [new file with mode: 0644]
src/dos/mouse.c [deleted file]
src/dos/mouse.h

index 764ad9d..575308c 100644 (file)
@@ -1,6 +1,6 @@
 src = $(wildcard src/*.c) $(wildcard src/dos/*.c)
-asmsrc = $(wildcard src/*.asm)
-obj = $(src:.c=.cof)
+asmsrc = $(wildcard src/*.asm) $(wildcard src/dos/*.asm)
+obj = $(src:.c=.cof) $(asmsrc:.asm=.cof)
 dep = $(obj:.cof=.dep)
 bin = demo.exe
 
index 92f765d..018ed51 100644 (file)
@@ -40,6 +40,7 @@ int main(int argc, char **argv)
 #endif
 
        if((use_mouse = have_mouse())) {
+               printf("initializing mouse input\n");
                set_mouse_limits(0, 0, fb_width, fb_height);
                set_mouse(fb_width / 2, fb_height / 2);
        }
diff --git a/src/dos/mouse.asm b/src/dos/mouse.asm
new file mode 100644 (file)
index 0000000..c82e7fd
--- /dev/null
@@ -0,0 +1,193 @@
+; vi:set filetype=nasm:
+; foo_ are watcom functions, _foo are djgpp functions
+
+QUERY equ 0
+SHOW equ 1
+HIDE equ 2
+READ equ 3
+WRITE equ 4
+PIXRATE equ 15
+XLIM equ 7
+YLIM equ 8
+
+PUSHA_EAX_OFFS equ 28
+PUSHA_ECX_OFFS equ 20
+PUSHA_EDX_OFFS equ 16
+
+       section .text
+       bits 32
+
+; int have_mouse(void)
+       global have_mouse_
+       global _have_mouse
+have_mouse_:
+_have_mouse:
+       pusha
+       mov ax, QUERY
+       int 0x33
+       and eax, 0xffff
+       mov [esp + PUSHA_EAX_OFFS], eax
+       popa
+       ret
+
+; void show_mouse(int show)
+       global show_mouse_
+show_mouse_:
+       pusha
+       test ax, ax
+       mov ax, HIDE
+       jz .skip
+       mov ax, SHOW
+.skip: int 0x33
+       popa
+       ret
+
+       global _show_mouse
+_show_mouse:
+       push ebp
+       mov ebp, esp
+       push ebx
+       push esi
+       push edi
+       mov ax, [ebp + 8]
+       test ax, ax
+       mov ax, HIDE
+       jz .skip
+       mov ax, SHOW
+.skip: int 0x33
+       pop edi
+       pop esi
+       pop ebx
+       pop ebp
+       ret
+
+; int read_mouse(int *xp, int *yp)
+       global read_mouse_
+read_mouse_:
+       pusha
+       mov esi, eax    ; xp
+       mov edi, edx    ; yp
+       mov ax, READ
+       int 0x33
+       xor eax, eax
+       and ecx, 0xffff
+       and edx, 0xffff
+       mov ax, bx
+       mov [esp + PUSHA_EAX_OFFS], eax
+       mov [esi], ecx
+       mov [edi], edx
+       popa
+       ret
+
+       global _read_mouse
+_read_mouse:
+       push ebp
+       mov ebp, esp
+       push ebx
+       push esi
+       push edi
+       mov ax, READ
+       int 0x33
+       xor eax, eax
+       mov ax, bx
+       and ecx, 0xffff
+       mov ebx, [ebp + 8]
+       mov [ebx], ecx
+       and edx, 0xffff
+       mov ebx, [ebp + 12]
+       mov [ebx], edx
+       pop edi
+       pop esi
+       pop ebx
+       pop ebp
+       ret
+
+; void set_mouse(int x, int y)
+       global set_mouse_
+set_mouse_:
+       pusha
+       mov cx, ax
+       mov ax, WRITE
+       int 0x33
+       popa
+       ret
+       
+       global _set_mouse
+_set_mouse:
+       push ebp
+       mov ebp, esp
+       push ebx
+       push esi
+       push edi
+       mov ax, WRITE
+       mov cx, [ebp + 8]
+       mov dx, [ebp + 12]
+       int 0x33
+       pop edi
+       pop esi
+       pop ebx
+       pop ebp
+       ret
+
+; void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
+       global set_mouse_limits_
+set_mouse_limits_:
+       pusha
+       mov cx, ax
+       mov dx, bx
+       mov ax, XLIM
+       int 0x33
+       mov ax, YLIM
+       mov cx, [esp + PUSHA_EDX_OFFS]
+       mov dx, [esp + PUSHA_ECX_OFFS]
+       int 0x33
+       popa
+       ret
+
+       global _set_mouse_limits
+_set_mouse_limits:
+       push ebp
+       mov ebp, esp
+       push ebx
+       push esi
+       push edi
+       mov ax, XLIM
+       mov cx, [ebp + 8]
+       mov dx, [ebp + 16]
+       int 0x33
+       mov ax, YLIM
+       mov cx, [ebp + 12]
+       mov dx, [ebp + 20]
+       int 0x33
+       pop edi
+       pop esi
+       pop ebx
+       pop ebp
+       ret
+
+; void set_mouse_rate(int xrate, int yrate)
+       global set_mouse_rate_
+set_mouse_rate_:
+       pusha
+       mov cx, ax
+       mov ax, PIXRATE
+       int 0x33
+       popa
+       ret
+
+       global _set_mouse_rate
+_set_mouse_rate:
+       push ebp
+       mov ebp, esp
+       push ebx
+       push esi
+       push edi
+       mov ax, PIXRATE
+       mov cx, [esp + 4]
+       mov dx, [esp + 8]
+       int 0x33
+       pop edi
+       pop esi
+       pop ebx
+       pop ebp
+       ret
diff --git a/src/dos/mouse.c b/src/dos/mouse.c
deleted file mode 100644 (file)
index 0033130..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-#include "mouse.h"
-
-typedef unsigned short uint16_t;
-
-#define INTR   0x33
-
-#define QUERY  0
-#define SHOW   1
-#define HIDE   2
-#define READ   3
-#define WRITE  4
-#define PIXRATE        0xf
-
-#define XLIM   7
-#define YLIM   8
-
-int have_mouse(void)
-{
-       uint16_t res = 0;
-#ifdef __WATCOMC__
-       _asm {
-               mov eax, QUERY
-               int INTR
-               mov res, ax
-       }
-#endif
-       return res;
-}
-
-void show_mouse(int show)
-{
-       uint16_t cmd = show ? SHOW : HIDE;
-#ifdef __WATCOMC__
-       _asm {
-               mov ax, cmd
-               int INTR
-       }
-#endif
-}
-
-int read_mouse(int *xp, int *yp)
-{
-       uint16_t x, y, state;
-#ifdef __WATCOMC__
-       _asm {
-               mov eax, READ
-               int INTR
-               mov state, bx
-               mov x, cx
-               mov y, dx
-       }
-#endif
-#ifdef __DJGPP__
-       x = y = state = 0;
-#endif
-
-       if(xp) *xp = x;
-       if(yp) *yp = y;
-       return state;
-}
-
-void set_mouse(int x, int y)
-{
-#ifdef __WATCOMC__
-       _asm {
-               mov eax, WRITE
-               mov ecx, x
-               mov edx, y
-               int INTR
-       }
-#endif
-}
-
-void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
-{
-#ifdef __WATCOMC__
-       _asm {
-               mov eax, XLIM
-               mov ecx, xmin
-               mov edx, xmax
-               int INTR
-               mov eax, YLIM
-               mov ecx, ymin
-               mov edx, ymax
-               int INTR
-       }
-#endif
-}
-
-void set_mouse_rate(int xrate, int yrate)
-{
-#ifdef __WATCOMC__
-       _asm {
-               mov ax, PIXRATE
-               mov ecx, xrate
-               mov edx, yrate
-               int INTR
-       }
-#endif
-}
-
-void set_mouse_mode(enum mouse_mode mode)
-{
-       if(mode == MOUSE_GFX) {
-               set_mouse_rate(1, 1);
-       } else {
-               set_mouse_rate(8, 16);
-       }
-}
index 7dd17b8..b54f6a9 100644 (file)
@@ -7,11 +7,6 @@ enum {
        MOUSE_MIDDLE    = 4
 };
 
-enum mouse_mode {
-       MOUSE_GFX,
-       MOUSE_TEXT
-};
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -22,7 +17,6 @@ int read_mouse(int *xp, int *yp);
 void set_mouse(int x, int y);
 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax);
 void set_mouse_rate(int xrate, int yrate);
-void set_mouse_mode(enum mouse_mode mode);
 
 #ifdef __cplusplus
 }