Welcome, Guest. Please login or register.


Author Topic: Universal Mouse Driver (Read 78390 times)

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #135 on: 2016.October.12. 13:01:47 »
I think I got the motivation to do it ;)
By the way, should I correct the issue which remains the last read state of the buttons, after the disappearance of strobe signal (RTS) ?

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #136 on: 2016.October.12. 17:47:01 »
It is very easy to ignore the upper nibble of the wheel, but I thought there was no rush. I better want to implement the Horizontal wheel in the driver if Pear puts it on the EnterMice adapter.

The only "problem" to implement an Horizontal wheel is that its counter has to be put on a new system var, because 190 is complete. The next one free is 191. I can replicate it with the Vertical wheel code.
« Last Edit: 2016.October.17. 11:10:32 by gflorez »

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #137 on: 2016.October.12. 18:15:32 »
Horizontal wheel counter, it is an exaggeration :)
Most mices have only 3 states for the horizontal wheel (-1, 0, and +1).
So far I found only one, that has a full 7-bit counter.
Realy problem is that I do not have a hundred percent good way to distinguish mice models.

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #138 on: 2016.October.12. 19:05:34 »
Then both can suit, the first only admits increments of 1, 0, or -1 every cycle, and the other the full 4 bits.

But the counter acts the same. The application needs to know how many impulses have been sent since the last reset of the wheel counter. Wheel lecture cycles don't happen the same as mouse lecture cycles.

Every mouse reading cycle the wheel counter is actualised(added the increment), but is the application which decides when to read and immediately reset  the counter.

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #139 on: 2016.October.12. 19:33:43 »
On the Enterprise side actually not be a problem.
Unfortunately, each of these mices stores information about the horizontal wheel in another way.
Sometimes it is a separate register, and sometimes the same, in which is the information from a vertical wheel.
I do not have good way to distinguish.

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #140 on: 2016.October.12. 20:03:37 »
Then, I will wait to the next driver version to ignore that high nibble, or until you found a solution.

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #141 on: 2016.October.12. 22:37:09 »
I have achieved  a mouse pointer on WP only by commands, without hacks.

Surprisingly the PB command was needed to work with the Word Processor. I will return sometime  to fix the initialisation of the driver.

I have also a snapshot of a pointer on the lower screen. A mouse pointer transition between video pages is possible, like in Paintbox, as the internal coordinates of the pointer are the same on all video or text modes.

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #142 on: 2016.October.17. 00:40:10 »
I have fixed an error introduced with the last version. Scroll was only allowed on text pages, and then Paintbox hung when moving the pointer down on the edition area.

It will be added to the next version.
« Last Edit: 2016.October.17. 11:07:57 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #143 on: 2016.October.22. 09:55:41 »
Version 1.103 of the Mouse driver:

-Scroll is also allowed on graphics video pages as mentioned on the last post.
 
-The 'MOUSE' command has been replaced by the standard format command 'HELP MOUSE'.

-A new command, 'MOUSE ED'  has been added. It opens a mouse channel nr. 150 on an existing video page whose number channel has been stored on system var 180.

Then, a mouse pointer can be placed on every application that accepts EXOS commands. To close the mouse channel, the obsolete 'PB' command can be used, but as usual it will return an annoying error message. This is necessary  for a proper Painbox operation, Only after fixing the paint program will be possible to fix the error. In the Basic editor the mouse channel can be closed with CLOSE £150:

The procedure is: install the driver if not done before. :LOAD MOUSE.XR. The Epdos command :CHANS can be used to search for an open video channel. Then, the command :VAR 180 XXX is used to inform the Mouse driver  about the video channel number. Once done, the command :MOUSE ED will create the mouse channel number 150.

Some default video channels:

Basic 102
WR     206
EXDOS  0

It is planned to make the command automatic, the Mouse driver will search for the actual default video channel. The command hasn't practical use for now because still the click event is unimplemented.

-A new system variable has been created, number 191. It contains the counter of an horizontal wheel, but still it hasn't being implemented by Pear on the EnterMice protocol. It is stored on the lower four bits of the variable, just the same than the vertical wheel counter on system var 190.

-Some other little improvements have been made on the code.
« Last Edit: 2016.October.23. 20:49:05 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #144 on: 2016.October.24. 12:22:21 »
MOUSE ED automatic achieved.

To show how it works, load the snapshot and execute consecutively the already typed commands, only press Enter:

:var 180 0  ; but you can put another value, only to erase the initial setting

:mouse ed  ; will open the mouse channel and show the pointer, the mouse driver has found the default video channel

:var 180     ; we ask for the video channel number, it will return 102 for Basic

:PB             ; will close the mouse channel, giving us an annoying error that means 9000+segment where the mouse driver is installed.

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #145 on: 2016.October.25. 12:17:29 »
The MOUSE ED command will only work with Editor modes, while being the default channel the Editor channel.

For example, executed inside the EGI it will return "Call not supported by this device" because the default channel is a Video channel. I think the message is enough understandable.


Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #146 on: 2016.October.31. 02:07:21 »
The automatic MOUSE ED command, or every thing that involve to interact with channels, is not as easy as it may seem.

The problem is the addition of language Roms, because newer EDITOR and KEYBOARD modified device drivers where included on the BRD Rom and derivatives.

The stock drivers have the internal devices work area on fixed zones of segment FF, but on the newer versions, the work area is accessed entirely by indexation, allocating memory.

Is for this that I have used a mixed approach, checking if the EDITOR driver is accessed on Rom 0(old version), or not(new version. BRD.rom can be located on a lot of positions but not on 0).

--------------------

Hardware text modes are very reliable, but I have found an error on software text modes that is giving me a headache. It works perfectly until the pointer finds text on a colour combination different than green/black. Then the pointer is drawn sometimes on the right position, and others on the same column but 8 rows lower. 

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14733
  • Country: hu
    • http://enterprise.iko.hu/
Re: Universal Mouse Driver
« Reply #147 on: 2016.October.31. 08:28:59 »
Drivers work area are also it diferent locations in EXOS 2.0 and 2.1+

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #148 on: 2016.October.31. 10:06:30 »
True, but since its creation the Mouse driver has been incompatible with EXOS 2.0, only works with 2.1(and with your onward versions).


----------------

Here you can see the error when the pointer pass over the ruler line or the cursor.

Here is the routine that draws the pointer on text modes:

Code: [Select]
DRAW_TMODE:   ; first convert pixel coordinates to column-row coordinates
ld hl,(X1)
rr h;   we need two lower bits of h
rr l
rr h
rr l
srl l
ld a, (VIDEO_MODE)
cp 2
ld b,a
jr z, sigue8; text 80, X1/8
srl l;      ; text 40, X1/16
; dec l; it must start with 0
sigue8: ld a, l
ld (X1C),a; column stored

ld hl,(Y1); we have to divide Y1 by 18
; fast division by nine, by Ricardo Bittencourt, Brazilian MSX developer
; enter     HL = number from 0 to 1440
; exit      A = HL/9
; destroy   HL,DE
;                               
;DIV9:   
INC     HL             
        LD      D,H             
        LD      E,L             
        ADD     HL,HL           
        ADD     HL,HL           
        ADD     HL,HL           
        SBC     HL,DE           
        LD      E,0             
        LD      D,L             
        LD      A,H             
        ADD     HL,HL         
        ADD     HL,HL           
        ADD     HL,DE         
        ADC     A,E             
        XOR     H             
        AND     03FH           
        XOR     H               
        RLCA                   
        RLCA

        srl a ; we still need a division by 2
; dec a; it must start from 0
ld (Y1R),a; row stored
ld c,a

ld a,(LPT_line)
add a,c ; a holds the first line of the video page + row
ld h,0
ld l,a
add hl,hl; x2  ;multiply a*16 and add it to LPT_BASE in hl
add hl,hl; x4
add hl,hl; x8
add hl,hl; x16
ld de,(LPT_BASE)
add hl,de; byte 0 of the LPT line where the cursor has to be drawn
inc hl     ;add 4 to be just over the LPT_address
inc hl
inc hl
inc hl
ld e,(hl)
inc hl
ld d,(hl) ;load hl with the contained address. Remember Nick addressing
ld a,(X1C)
ld l,a
ld h,0
add hl,de ;add X1C to the line address buffer

ld a, 63             ; 00111111  we need this mask to compose the page
rl h
rla
rl h                 ; now we calculate the segment, taking the two last bits of the address
rla
srl h                ; the address is simplified and stored
srl h               
ld (POINTER_PAGE),a
ld (POINTER_ADDR),hl ; now a has the page and hl the address on page 0
push af
in a, (0B0h)        ; the segment is loaded on page-0 and the content is stored
ld (PAGE0), a
pop af
out (0B0h),a

ld a,b; B still contains the video mode;
cp 0
jr nz, SOFT_TEXT_DRAW
; Hard text mode draw
ld a,(hl)
ld (POINTER_CONT),a  ; the content is stored for later
; and 128              ; don't replace the cursor or red characters
; jr nz, siguek

ld a,(POINTER_COLOUR)
ld c,a
ld a,127
rla
rr c
rra                  ; The color bit is added to bit 7 of the arrow character
ld (hl),a            ; the arrow character is "drawn" on the same byte
siguek:
ld a,(PAGE0)
out (0B0h),a     ; The original B0 segment is restored
ret

SOFT_TEXT_DRAW:             ; hl already contains the address
ld a,(POINTER_PAGE)
ld c,a              ; c holds the starting segment of the LPT line
ld b,9              ; b counts the character lines
ld de,POINTER_CONTS ; The place where we store the character boundary content
push de             ; now POINTER_CONTS is on the Stack
ld de,0B4FFh        ; address of character 128 on the Font

buclef:
ld a,(hl);          ; content of the line is loaded on a
ex (sp),hl          ; pointer address goes to the Stack and POINTER_CONTS goes to hl
ld (hl),a           ; the content of the line is stored for later on POINTER_CONTS
inc hl;             ; prepare next byte of POINTER_CONTS
ex (sp),hl          ; pointer address goes to hl and POINTER_CONTS goes to Stack

ex de,hl            ; Font goes to hl and pointer address to de
ld a,(hl)     ; load a line of the character Font on a
push bc ; now we can use the Stack to store the two counters on bc
ld bc,128 ; Font lines are all at fixed increments on page-2
add hl,bc ; prepare next line of Font
ex de,hl            ; pointer address goes to hl and Font goes to de

ld c,a      ; here the colour is added
ld a,(POINTER_COLOUR) ; the system var  stores the pointer colour for all modes
rl c
rra                 ; only four colour combinations, one bit  on 7 and the other on 0
rr c
rr c
rra
rl c
ld a,c
ld (hl),a           ; a line of the arrow character is "drawn" with its color bits

;ld b,0             ; not needed, as b already contains 0
ld a,(COLUMNS) ; next line of the pointer is on the same column so, we add 
ld c,a  ; no. of columns of the actual video page
add hl,bc ; prepare next line of address pointer

pop bc ; we need again the counters
bit 6, h
jr z, siguev ; if the address pointer gets out of 16k then increase the segment
res 6, h
inc c
ld a,c
out (0B0h),a ; the rest of the pointer is on the next page, so we load it
siguev:
djnz buclef
pop de              ; de is no more needed, but we don't want to corrupt the stack
jr siguek

And here the erasing routine:

Code: [Select]
ERASE_TEXT:
ld b,a ; save video mode on b
in a, (0B0h)
ld (PAGE0), a
ld a,(POINTER_PAGE)
out (0B0h),a ;carga el segmento que hemos guardado al dibujar, en page-0
ld hl,(POINTER_ADDR)
ld a,b              ; B still contains the video mode;
cp 0
jr nz, SOFT_TEXT_ERASE

ld a,(POINTER_CONT)
ld (hl),a     ; load the saved content on the saved address
contk:
ld a,(PAGE0)
out (0B0h),a ; restore page-0
ret

SOFT_TEXT_ERASE:            ; hl already contains the address
ld a,(POINTER_PAGE)
ld c,a ; start page of the pointer
ld b,9 ; no. of character lines
ld de,POINTER_CONTS;

buclev:
ex de,hl            ; POINTER_CONTS goes to hl and pointer address goes to de
ld a,(hl)     ; load a line of the stored character  on a
inc hl              ; prepare  POINTER_CONTS for next cycle
ex de,hl            ; pointer address goes to hl and POINTER_CONTS goes to de
ld (hl),a           ; a line of arrow is "drawn"

push bc ; store the counters on the Stack
ld b,0
ld a,(COLUMNS) ; next line of the pointer is on the same column so, we add no. of columns
ld c,a
add hl,bc ; prepare next line of address pointer
pop bc ; we need again the counters
bit 6, h
jr z, siguex ; if the address pointer gets out of 16k then increase the video segment
res 6, h ; the address neds to be simplified
inc c
ld a,c
out (0B0h),a ; the rest of the pointer is on the next page, so we load it
siguex:
djnz buclev
jr contk
« Last Edit: 2016.October.31. 10:55:36 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3610
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #149 on: 2016.November.01. 20:51:06 »
Colour error fixed.

Like on many other times, a silly error...

At least the many tests have served to surface other faults that now I have the chance to fix.