mirror of
https://github.com/cc65/cc65.git
synced 2025-01-10 19:29:45 +00:00
New loadable mouse drivers
git-svn-id: svn://svn.cc65.org/cc65/trunk@2851 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
7e43e5e0e1
commit
30d99a4d56
1
libsrc/mouse/.cvsignore
Normal file
1
libsrc/mouse/.cvsignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
mouse_load.s
|
36
libsrc/mouse/Makefile
Normal file
36
libsrc/mouse/Makefile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# Makefile for the mouse driver library
|
||||||
|
#
|
||||||
|
|
||||||
|
.SUFFIXES: .o .s .c
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
# Rules
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
@$(CC) $(CFLAGS) $<
|
||||||
|
@$(AS) -g -o $@ $(AFLAGS) $(*).s
|
||||||
|
|
||||||
|
%.o: %.s
|
||||||
|
@$(AS) -g -o $@ $(AFLAGS) $<
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
# Object files
|
||||||
|
|
||||||
|
C_OBJS = mouse_load.o
|
||||||
|
|
||||||
|
S_OBJS = mouse-kernel.o
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
# Targets
|
||||||
|
|
||||||
|
.PHONY: all clean zap
|
||||||
|
|
||||||
|
all: $(C_OBJS) $(S_OBJS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@$(RM) *~ $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS)
|
||||||
|
|
||||||
|
zap: clean
|
||||||
|
|
101
libsrc/mouse/mouse-kernel.s
Normal file
101
libsrc/mouse/mouse-kernel.s
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2003-12-28
|
||||||
|
;
|
||||||
|
; Common functions of the mouse driver API.
|
||||||
|
;
|
||||||
|
|
||||||
|
.import return0
|
||||||
|
.importzp ptr1
|
||||||
|
|
||||||
|
.include "mouse-kernel.inc"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; Variables
|
||||||
|
|
||||||
|
|
||||||
|
.bss
|
||||||
|
_mouse_drv: .res 2 ; Pointer to driver
|
||||||
|
|
||||||
|
; Jump table for the driver functions.
|
||||||
|
.data
|
||||||
|
mouse_vectors:
|
||||||
|
mouse_install: jmp return0
|
||||||
|
mouse_uninstall:jmp return0
|
||||||
|
mouse_hide: jmp return0
|
||||||
|
mouse_show: jmp return0
|
||||||
|
mouse_box: jmp return0
|
||||||
|
mouse_move: jmp return0
|
||||||
|
mouse_buttons: jmp return0
|
||||||
|
mouse_pos: jmp return0
|
||||||
|
mouse_info: jmp return0
|
||||||
|
|
||||||
|
; Driver header signature
|
||||||
|
.rodata
|
||||||
|
mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; unsigned char __fastcall__ mouse_install (void* driver);
|
||||||
|
; /* Install an already loaded driver. Returns an error code. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_mouse_install:
|
||||||
|
sta _mouse_drv
|
||||||
|
sta ptr1
|
||||||
|
stx _mouse_drv+1
|
||||||
|
stx ptr1+1
|
||||||
|
|
||||||
|
; Check the driver signature
|
||||||
|
|
||||||
|
ldy #.sizeof(mouse_sig)-1
|
||||||
|
@L0: lda (ptr1),y
|
||||||
|
cmp mouse_sig,y
|
||||||
|
bne inv_drv
|
||||||
|
dey
|
||||||
|
bpl @L0
|
||||||
|
|
||||||
|
; Copy the jump vectors
|
||||||
|
|
||||||
|
ldy #MOUSE_HDR::JUMPTAB
|
||||||
|
ldx #0
|
||||||
|
@L1: inx ; Skip the JMP opcode
|
||||||
|
jsr copy ; Copy one byte
|
||||||
|
jsr copy ; Copy one byte
|
||||||
|
cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
|
||||||
|
bne @L1
|
||||||
|
|
||||||
|
jmp mouse_install ; Call driver install routine
|
||||||
|
|
||||||
|
; Driver signature invalid
|
||||||
|
|
||||||
|
inv_drv:
|
||||||
|
lda #MOUSE_ERR_INV_DRIVER
|
||||||
|
ldx #0
|
||||||
|
rts
|
||||||
|
|
||||||
|
; Copy one byte from the jump vectors
|
||||||
|
|
||||||
|
copy: lda (ptr1),y
|
||||||
|
sta mouse_vectors,x
|
||||||
|
iny
|
||||||
|
inx
|
||||||
|
rts
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; unsigned char __fastcall__ mouse_uninstall (void);
|
||||||
|
; /* Uninstall the currently loaded driver. Returns an error code. */
|
||||||
|
|
||||||
|
_mouse_uninstall:
|
||||||
|
jsr mouse_uninstall ; Call driver routine
|
||||||
|
|
||||||
|
mouse_clear_ptr: ; External entry point
|
||||||
|
lda #0
|
||||||
|
sta _mouse_drv
|
||||||
|
sta _mouse_drv+1 ; Clear the driver pointer
|
||||||
|
|
||||||
|
tax
|
||||||
|
rts ; Return zero
|
||||||
|
|
82
libsrc/mouse/mouse_load.c
Normal file
82
libsrc/mouse/mouse_load.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* mouse_load.c */
|
||||||
|
/* */
|
||||||
|
/* Loader for mouse drivers modules */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2002-2003 Ullrich von Bassewitz */
|
||||||
|
/* Römerstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <modload.h>
|
||||||
|
#include <mouse.h>
|
||||||
|
#include <mouse/mouse-kernel.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char __fastcall__ mouse_load_driver (const char* name)
|
||||||
|
/* Load a mouse driver and return an error code */
|
||||||
|
{
|
||||||
|
static struct mod_ctrl ctrl = {
|
||||||
|
read /* Read from disk */
|
||||||
|
};
|
||||||
|
unsigned char Res;
|
||||||
|
|
||||||
|
/* Check if we do already have a driver loaded. If so, remove it. */
|
||||||
|
if (mouse_drv != 0) {
|
||||||
|
mouse_uninstall ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now open the file */
|
||||||
|
ctrl.callerdata = open (name, O_RDONLY);
|
||||||
|
if (ctrl.callerdata >= 0) {
|
||||||
|
|
||||||
|
/* Load the module */
|
||||||
|
Res = mod_load (&ctrl);
|
||||||
|
|
||||||
|
/* Close the input file */
|
||||||
|
close (ctrl.callerdata);
|
||||||
|
|
||||||
|
/* Check the return code */
|
||||||
|
if (Res == MLOAD_OK) {
|
||||||
|
|
||||||
|
/* Check the driver signature, install the driver */
|
||||||
|
return mouse_install (ctrl.module);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Error loading the driver */
|
||||||
|
return MOUSE_ERR_CANNOT_LOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user