Skip to content

Commit

Permalink
split mouse code to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Mar 19, 2024
1 parent b6023f7 commit cba0959
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 227 deletions.
4 changes: 2 additions & 2 deletions 32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ C_OPT = -Wall -O2 -Wmissing-declarations -Wwrite-strings -I $(SRCDIR) -I .
# avoid CMOVxx instructions
C_OPT += -march=i386
LINK_OPT =
SRCS = $(SRCDIR)/command.c $(SRCDIR)/cmdbuf.c $(SRCDIR)/version.c \
memmem.c fmemcpy.c
SRCS = $(SRCDIR)/command.c $(SRCDIR)/cmdbuf.c $(SRCDIR)/ms.c \
$(SRCDIR)/version.c memmem.c fmemcpy.c
ASSRCS = $(SRCDIR)/asm.S $(SRCDIR)/int23.S $(SRCDIR)/int0.S $(SRCDIR)/mouse.S
OBJS = $(notdir $(SRCS:.c=.o)) $(notdir $(ASSRCS:.S=.o))
CMD = comcom32.exe
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ C_OPT = -Wall -Og -Wmissing-declarations -Wwrite-strings -fpic \
LINK_OPT = $(shell pkg-config --libs dj64) -shared -Wl,-Bsymbolic \
-Wl,-rpath=/usr/local/i386-pc-dj64/lib64 \
-Wl,-rpath=/usr/i386-pc-dj64/lib64
SRCS = command.c cmdbuf.c version.c thunks_a.c thunks_c.c
SRCS = command.c cmdbuf.c ms.c version.c thunks_a.c thunks_c.c
OBJS = $(SRCS:.c=.o)
ASSRCS = int23.S int0.S asm.S plt.S mouse.S
ASOBJS = $(ASSRCS:.S=.o)
Expand Down
225 changes: 1 addition & 224 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
#include <process.h>
#include <sys/segments.h>
#include <sys/farptr.h>
#include <sys/nearptr.h>
#include <go32.h>

#include "cmdbuf.h"
Expand All @@ -85,6 +84,7 @@
#endif
#include "asm.h"
#include "version.h"
#include "ms.h"
#include "command.h"

/*
Expand Down Expand Up @@ -229,9 +229,6 @@ static void set_break(int on);
static void get_env(void);
static int compl_cmds(const char *prefix, int print, int *r_len, char *r_p);
static int compl_fname(const char *prefix, int print, int *r_len, char *r_p);
static void mouse_show(void);
static void mouse_hide(void);
static void mouse_reset(void);

struct built_in_cmd
{
Expand Down Expand Up @@ -4803,226 +4800,6 @@ void do_int0(void)
__dpmi_set_real_mode_interrupt_vector(0, &int0_vec);
}

#ifdef DJ64
static unsigned mouse_regs;
#else
static __dpmi_regs *mouse_regs;
#define djaddr2ptr(a) ((unsigned char *)((a) - __djgpp_base_address))
#endif
static __dpmi_meminfo mregs = { .size = sizeof(__dpmi_regs) };
static __dpmi_raddr newm;
static __dpmi_raddr oldm;
static unsigned old_mask;
#define MEV_MASK 0xab

static unsigned short popw(__dpmi_regs *r)
{
unsigned lina = (r->x.ss << 4) + r->x.sp;
unsigned short ret = _farpeekw(_dos_ds, lina);
r->x.sp += 2;
return ret;
}

static void do_retf(__dpmi_regs *r)
{
r->x.ip = popw(r);
r->x.cs = popw(r);
}

static void mvxl(int d)
{
__dpmi_regs r = {};

while (d--)
{
r.x.ax = 0x500;
r.x.cx = 0x4BE0;
__dpmi_int(0x16, &r);
}
}

static void mvxr(int d)
{
__dpmi_regs r = {};

while (d--)
{
r.x.ax = 0x500;
r.x.cx = 0x4DE0;
__dpmi_int(0x16, &r);
}
}

static void mlb(int alt_fn, int x, int y)
{
__dpmi_regs r = {};
short c;

if (alt_fn)
{
int cx = wherex();
if (cx == x)
return;
if (x < cx)
mvxl(cx - x);
else
mvxr(x - cx);
return;
}

_conio_gettext(x, y, x, y, &c);

r.x.ax = 0x500;
r.x.cx = c & 0xff;
__dpmi_int(0x16, &r);
}

static void mrb(int alt_fn)
{
__dpmi_regs r = {};

r.x.ax = 0x500;
r.x.cx = alt_fn ? 0x3 : 0x0F09; // ^C or TAB
__dpmi_int(0x16, &r);
}

static void mmb(int alt_fn)
{
__dpmi_regs r = {};

r.x.ax = 0x500;
r.x.cx = alt_fn ? 0x0E08 : 0x1c0d; // BkSp or ENTER
__dpmi_int(0x16, &r);
}

static void mw(int delta)
{
__dpmi_regs r = {};

r.x.ax = 0x500;
if (delta < 0)
r.x.cx = 0x48E0; // UP
else
r.x.cx = 0x50E0; // DOWN
__dpmi_int(0x16, &r);
}

void do_mouse(void)
{
__dpmi_regs *r;
unsigned char rows = _farpeekb(_dos_ds, 0x484) + 1;
static unsigned char prev_col, prev_row;
unsigned char col, row;
int dragged;

#ifndef DJ64
__djgpp_nearptr_enable();
#endif
r = (__dpmi_regs *)djaddr2ptr(mregs.address);
do_retf(r);

col = r->x.cx / 8 + 1;
row = r->x.dx / 8 + 1;
dragged = (r->x.ax & r->x.bx & 1) && (col != prev_col || row != prev_row);

if ((r->x.ax & 2) || dragged)
mlb(row == rows, col, row);
if (r->x.ax & 8)
mrb(row == rows);
if (r->x.ax & 0x20)
mmb(row == rows);
if (r->x.ax & 0x80)
mw((char)r->h.bh);

prev_col = r->x.cx / 8 + 1;
prev_row = r->x.dx / 8 + 1;

#ifndef DJ64
__djgpp_nearptr_disable();
#endif
}

static int mouse_init(void)
{
__dpmi_regs r = {};

__dpmi_int(0x33, &r);
if ((r.x.flags & CF) || r.x.ax != 0xffff || r.x.bx != 3)
{
puts("mouse not detected");
return 0;
}
/* check the wheel */
r.x.ax = 0x11;
__dpmi_int(0x33, &r);
if ((r.x.flags & CF) || r.x.ax != 0x574d || (r.x.cx & 1) == 0)
{
puts("mouse wheel not supported");
// return 0;
}

__dpmi_allocate_memory(&mregs);
#ifdef DJ64
mouse_regs = mregs.address - __djgpp_base_address;
#else
mouse_regs = (__dpmi_regs *)djaddr2ptr(mregs.address);
#endif
__dpmi_allocate_real_mode_callback(my_mouse_handler, mouse_regs, &newm);
r.x.ax = 0x14;
r.x.cx = MEV_MASK;
r.x.es = newm.segment;
r.x.dx = newm.offset16;
__dpmi_int(0x33, &r);
oldm.segment = r.x.es;
oldm.offset16 = r.x.dx;
old_mask = r.x.cx;

mouse_show();
return 1;
}

static void mouse_reset(void)
{
__dpmi_regs r = {};

r.x.ax = 0x0c;
r.x.cx = MEV_MASK;
r.x.es = newm.segment;
r.x.dx = newm.offset16;
__dpmi_int(0x33, &r);
}

static void mouse_done(void)
{
__dpmi_regs r = {};

mouse_hide();

r.x.ax = 0x0c;
r.x.cx = old_mask;
r.x.es = oldm.segment;
r.x.dx = oldm.offset16;
__dpmi_int(0x33, &r);
__dpmi_free_real_mode_callback(&newm);
__dpmi_free_memory(mregs.handle);
}

static void mouse_show(void)
{
__dpmi_regs r = {};

r.x.ax = 1;
__dpmi_int(0x33, &r);
}

static void mouse_hide(void)
{
__dpmi_regs r = {};

r.x.ax = 2;
__dpmi_int(0x33, &r);
}

int main(int argc, const char *argv[], const char *envp[])
{
int a;
Expand Down
Loading

0 comments on commit cba0959

Please sign in to comment.