Welcome, Guest. Please login or register.


Author Topic: Universal Mouse Driver (Read 16019 times)

Online BruceTanner

  • EP user
  • *
  • Posts: 406
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 58.0.3029.110 Chrome 58.0.3029.110
    • View Profile
Re: Universal Mouse Driver
« Reply #165 on: 2017.June.12. 20:51:56 »
Not easy I know, but perhaps what the EP really needs to move into the world of mice is a replacement editor: device, so that it can behave as modern computer use would expect (click and highlight a block, press DEL to erase etc), and avoid all your interrupt problems altogether :smt021 . No, I am not putting my hand up...:roll: :roll: :roll: :mrgreen:

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 53.0 Firefox 53.0
    • View Profile
Re: Universal Mouse Driver
« Reply #166 on: 2017.June.13. 00:52:17 »
I don't raise my arm either, a new enhanced Editor like you describe overcome my poor Z80 and EXOS knowledge.... I only can reach to modify the actual Editor device.

What I want is a total backward compatibility of the Mouse driver, at least with EXOS 2.1 and the BRD.Rom(HUN, ESP etc). The two share similar versions of the Editor, having the Language.Rom Editor a totally relocatable variable area. But English keyboard Enterprises lack the Language Rom.


A solution can be to create a  new Language.Rom for English keyboard Enterprises, then they also can benefit from the added content of the BRD.Rom, the VDUMP, VLOAD and VSAVE commands.

This can be made blocking the switching between idioms on the BRD.Rom, always UK mode. Once created the UK.Rom, I can modify the Editor for all the Language Roms, adding the Mouse click and more functions inside the modified Editor device. May be scroll? There is an unused zone on the Rom, from 3D00h to 3FF9h, 249 bytes.

But for this first I should precisely learn how the editor device works....
« Last Edit: 2017.June.13. 10:28:24 by gflorez »

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #167 on: 2017.June.20. 11:07:57 »
I am meditating aloud about how to implement the click event on the Editor driver.

Some information has to be passed to the Editor, but other is already available on the mouse system vars.

Important data is the number of Editor channel, always the default, or to know if effectively a mouse-editor channel has been opened.

And other data actually calculated inside the mouse driver, now should be calculated inside the Editor driver, like for example the translation from graphics coordinates to text coordinates.
« Last Edit: 2017.June.20. 11:13:23 by gflorez »

Offline geco

  • EP addict
  • *
  • Posts: 4400
  • Country: hu
  • OS:
  • Linux Linux
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #168 on: 2017.June.20. 13:49:56 »
Did you check how the cursor position is calculated by jostick movement, if it uses coordinates then the it's variables could be patched by mouse coordinates.

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #169 on: 2017.June.20. 15:09:39 »
Yes, text coordinates are calculated on the "new mouse text" mode from the graphics coordinates, but I've not created system vars for it as I intended to do the key-click inside the Mouse driver. Now It will be done remotely on this new approach:

A flag(a bit on one of the mouse system vars) will indicate the editor driver that the Editor+Mouse mode is active. If not, the Editor returns to its normal tasks. 

Then, if in Editor+Mouse mode, a branch in the code will be executed, much like when I inserted the mouse routine on a game.

But there are a lot of information needed, information that I have stored and already calculated inside the mouse driver:


Code: [Select]
ARROW db 96,112,120,124,126,120,72,8,0; constant
EDITOR_PAGE db 0
EDITOR_INDEX DW  0
EDITOR_CHN db 0
EDITOR_FLAG db 0
VAR_1 db 0
VAR_2 db 0
EDITOR_MODE db 0
LAST_FIRE  db 0
POINTER_ADDR dw 0
POINTER_PAGE  db 0
POINTER_CONT db 0,0,0,0,0,0,0,0,0
LPT_BASE  dw 0
LPT_line  db 0                  ;Line where the video page starts on the LPT
LPT_ADDR  dw 0                  ;Address where the first LPT line of the video page is
LPT_cont  db 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ;  line content
BUFF_LEN  dw 0
BUFFER_END dw 0
VIDEO_ADDRESS dw 0 ;
COLUMNS   db 0
VIDEOX dw 0 ;
VIDEOY      dw 0
VIDEOXx2 dw 0 ;
VIDEO_MODE db 0 ;
;
VIDEO_COLOUR db 0 ;
SCR_SAVE db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;
;
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
POINTER_ADDRESS dw 0 ;
HALF_VIDEOY dw 0 ;
;Modification here
HELPTXT     db "MOUSE version 1.10D",0Dh
MODEWRD         db "Control: "
MODE0TXT db "0 Internal Joystick   ",0Dh,0Dh
MODE1TXT db "1 External Joystick 1 ",0Dh,0Dh
MODE2TXT db "2 External Joystick 2 ",0Dh,0Dh
MODE3TXT db "3 Boxsoft interface   ",0Dh,0Dh
MODE4TXT db "4 Entermice interface ",0Dh,0Dh
MODE5TXT db "5 Serial Mouse Systems",0Dh,0Dh
MODE6TXT db "6 Serial Microsoft    ",0Dh,0Dh
MODE7TXT db "  Not defined         ",0Dh,0Dh
ENTERMICETXT db 0Dh,"Entermice by Pear",0Dh
EMVERSIONTXT db "Mouse Id. X Hw ver. X.X Sw ver. X.X",0Dh,0Dh
EM_EXISTS db 2             ; 0= not found, 1= found, 2= requested. Always requested at initialization, but afterwards only requested by :MOUSE command
EM_BUFF     db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;0-15 bytes, the max that can be counted with a nibble
;end
VIDEO_CHN db 101 ;
; INIOPEN
; EXOS Variable 180
STATUS_POS db 30 ;
; EXOS Variable 181
STATUS_DISP db 0 ;
; EXOS Variable 182
; 0 OFF, 1 ON
POINTER_COLOUR db 0FFh ;
; EXOS Variable 183
X_LOW db 0 ;
;
; EXOS Variable 184
X_HIGH db    0 ; EXOS Variable 185
Y_LOW db 0 ;
; EXOS Variable 186
Y_HIGH db    0 ; EXOS Variable 187
FIRE_STATUS db 0 ;
; EXOS Variable 188
INPUT_DEVICE db 0 ;
; EXOS Variable 189
SW_Z_STATUS db 0 ;
; EXOS Variable 190
H_WHEEL     db 0    ; ready for var 191
X1 dw 0 ;
Y1 dw 0 ;
CLICK db 0
SET_CURSOR   db 27,61,33,33      ; escape sequence set cursor
Y1R     db 0 ; row for text modes
X1C     db 0 ; column for text modes

X_REL db 0 ;
Y_REL db 0 ;
CHN_FLAG db 255 ;
CHN_COUNT   db 0 ;
POS_RD db 0 ;
POS_COUNT db 0 ;
;
X1_EXOS dw 0 ;
;
; X1*2
Y1_EXOS dw 0 ;
; Y1*2
POINTER_DISP db 1 ;
; 0 OFF, 1 ON
PAGE0 db 0 ;
POINTER_ROWS db 0 ;

I think it would be better to access directly the data from the mouse driver if I store the segment and address of the table on two system vars. Then in the future, if the Mouse driver is put on a ROM, the address will point to an allocated Ram with the same information.

Online BruceTanner

  • EP user
  • *
  • Posts: 406
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 58.0.3029.110 Chrome 58.0.3029.110
    • View Profile
Re: Universal Mouse Driver
« Reply #170 on: 2017.June.20. 16:19:52 »
But for this first I should precisely learn how the editor device works....
zozo now has the source code...do you have a copy to refer to? I'm not saying it's simple to understand though...:roll:

Forgive me if you have gone through all of this, I've lost track where you have got to, but...

When editor: is just sitting flashing the cursor it is doing repeated "read channel status" calls to the keyboard channel (EXOS 9) and when a character is ready it does a "read character" (EXOS 5). It knows the keyboard channel because it saved it in a fixed RAM location from the EXOS variable when the editor: channel was opened. So if you found its fixed location, somewhere in the system segment, (might depend on EXOS version), saved it, and changed it to, say, a mouse channel, then it would be doing "read channel status" and "read character" calls to your mouse driver, which could either return a character eg a pretend cursor movement "key", or pass the call on to the keyboard channel which you have saved. Your interrupt routine would then just queue mouse events in a little buffer and your "read channel status" code would remove them from the queue and convert them to fake key presses. So no calling EXOS in interrupts!

Sorry if you've been through all of this, as I say I've lost track where you have got to, but I just thought I would mention it in case there's anything there you haven't tried yet...

B.

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #171 on: 2017.June.20. 18:30:28 »
I have not started yet, thanks, I am a slow programmer... First I have to imagine what to do.

Your ideas are warmly welcomed, don't worry. It is an honour...
« Last Edit: 2017.June.20. 18:36:04 by gflorez »

Online BruceTanner

  • EP user
  • *
  • Posts: 406
  • Country: gb
  • OS:
  • Windows NT 6.3 Windows NT 6.3
  • Browser:
  • Chrome 58.0.3029.110 Chrome 58.0.3029.110
    • View Profile
Re: Universal Mouse Driver
« Reply #172 on: 2017.June.20. 20:58:49 »
I have just thought: rather than poking around in editor:'s variables you might be able to use a little-used (never-used? :twisted:) EXOS feature: Capture Channel (EXOS 17). You might be able to use this to cause "read status" and "read character" calls to the keyboard channel to go instead to your mouse channel. The problem might then be doing keyboard calls yourself - you might have to turn off the capture, do the call, and then turn the capture back on again :roll:

I haven't tried it...:mrgreen:

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #173 on: 2017.June.20. 22:24:41 »
You have reminded me of an easier way to make transfers between the two devices. The Mouse: channel can be written and read, with strictly legal EXOS calls:

(From the "Boxsoft" and "EnterMice" instructions)
Code: [Select]
Commands issued by printing characters to Mouse channel:

O Turn pointer on
o Turn pointer off
P Request X & Y position

Results or status obtained by reading a character from Mouse channel:

Only read after sending "P":
X Low byte
X High byte
Y Low byte
Y High byte

Always readable:

Fire = "1" if main button depressed, "0" if not.

I can implement, for example, a "p"(lower) command that would return text coordinates on a text-mouse screen, much like the "P"(capital) command does for mouse-graphics screens. This can be useful even for other applications, like Basic.
« Last Edit: 2017.June.20. 22:52:14 by gflorez »

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #174 on: 2017.June.20. 22:33:47 »
And I can also use your idea of a redirect call, because once the clock-event would be operative I will need to inject a carriage return(exactly like a keyboard press) to execute the clicked line.

But let's face only one difficult task each time....

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #175 on: 2017.July.10. 02:36:56 »
I have found the Keyboard reading loop inside the Editor: device on the language Rom.

Code: [Select]
.
.
.
  D14A  3E 3F        LD    A, 63      ; 00111111b cursor display control, but also counter
  D14C  F5           PUSH  AF         ; A register is saved on the stack
        08           EX    AF, AF'    ; and swapped with A'
        CD D5 DC     CALL  DCD5h      ; if an error code was stored in  (IY+35), the cursor is redrawn
        F1           POP   AF         ; A is restored and replicated on A'
        07           RLCA
        CD 0F DD     CALL  DD0Fh      ; Cursor display on/off depending on Carry
        3A F2 BF     LD    A, (BFF2h) ; FLG_SOFT_IRQ User Interrupt Code in A
        FE 20        CP    32         ; Test
        3E E5        LD    A, 229     ; .STOP 'STOP button pressed' - error message code
        C8           RET   Z          ; STOP error message
        FD 7E 0D     LD    A, (IY+13) ; Editor: Keyboard channel number, 105 on Basic
        F7 09        EXOS  09         ; Read keyboard channel status

        20 18        JR    NZ, D17Dh  ; Jump if error
        B9           CP    C          ; Status test
        28 10        JR    Z, D178h   ; Skip if a character is ready to be read

  D168  08           EX    AF, AF'    ; Number in A' is retrieved to A
        3D           DEC   A          ; and decreased
        20 E0        JR    NZ, D14Ch  ; Loop if still not zero

        08           EX    AF, AF'    ; swap A and A' again
        FD B6 14     OR    (IY+20)    ; Right margin
        C4 53 DB     CALL  NZ, DB53h  ; Clear margins
        CD 08 DC     CALL  DC08h      ; I still don't know what this call does
        18 F0        JR    D168h

  D178  FD 7E 0D     LD    A, (IY+13) ; Editor: Keyboard channel, 105 on Basic
        F7 05        EXOS  05         ; read character

  D17D  FE E5        CP    229        ; .STOP 'STOP button pressed' - error code detected
        C8           RET   Z          ; Return if STOP pressed
        B7           OR    A          ; Detect error code
        28 07        JR    Z, D18Ah   ; Jump if there is no error
        FD CB 28 FE  SET   7, (IY+40) ; Keyboard error indication
        3E D3        LD    A, 221     ; .EKEY 'EDITOR keyboard channel error' - error message code
        C9           RET

  D18A  FD 77 32     LD    (IY+50), A ; A=0
        FD CB 2F 56  BIT   2, (IY+47) ; Modified FLG_EDIT test
        FD CB 2F 96  RES   2, (IY+47) ; Clear AUTO_ERA
.
.
.

Probably I will put the CLICK hook on one of the two CALLs inside the minimum non-pressed-key loop.

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

Also, it seems that the pattern/counter at D14Bh  governs the behaviour of the cursor flickering, the two "0s" are the cycles it is OFF, and the  six "1s" the cycles it is ON, i. e. 2/8 OFF against 6/8 ON. This seems to me like a "heavy" blinking.
« Last Edit: 2017.July.10. 05:34:42 by gflorez »

Online BruceTanner

  • EP user
  • *
  • Posts: 406
  • Country: gb
  • OS:
  • Windows NT 6.3 Windows NT 6.3
  • Browser:
  • Chrome 59.0.3071.115 Chrome 59.0.3071.115
    • View Profile
Re: Universal Mouse Driver
« Reply #176 on: 2017.July.10. 07:42:42 »
Hi gflorez,

Here's the same code from the actual source with MrL's comments:
Code: [Select]
ld a,63 ;Loop count and cursor flash
; flag (bit-7)
scan_loop: push af
ex af,af'
call TRUE_CURSOR ;Ensure cursor is in correct
pop af ; place and turn it on or
rlca ; off as necessary.
call CURSOR_ON_OFF
;
ld a,(FLAG_SOFT_IRQ##) ;If STOP key has been pressed
cp ?STOP## ; then return with .STOP error
ld a,.STOP## ; to BASIC.
ret z
;
ld a,(RAM_ED+key_channel) ;Poll the keyboard and jump
EROS @RSTAT## ; if an error occured (NZ).
jr nz,key_error
cp c ;Exit if key is ready (C=0)
jr z,key_ready
scan_loop_2: ex af,af' ;Upadte the screen on 63rd time
dec a ; round the loop
jr nz,scan_loop
ex af,af'
;
or (IY+ruler_valid) ;Display ruler line if it
call nz,DISPLAY_RULER ; needs updating.
;
call REDRAW_LINE ;Update cursor line if needed
;
jr scan_loop_2 ;Must get A' back into A to
; keep flashing regular
;
;
;
key_ready: ld a,(RAM_ED+key_channel) ;Read a key from the keyboard.
EROS @RDCH##
key_error: cp .STOP## ;If STOP key pressed then
ret z ; return this error to BASIC
or a
jr z,no_key_error ;Any other error then return
set 7,(IY+error_flag) ; .EKEY error and set the
ld a,.EKEY## ; keyboard error flag.
ret
;
;
no_key_error: ld (RAM_ED+word_flags),a ;Initialise flags for TEST_WORD
;
bit auto_era,(IY+sending_flag)   ;Set Z' depending on
res auto_era,(IY+sending_flag)   ; whether AUTO_ERASE was
ex af,af'      ; set and clear it.
.
.
.

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #177 on: 2017.July.10. 10:25:40 »
Thanks! I just took the disassembly from the Ep128emu  Debugger, and translated the Hungarians comments from the Segment 0 Rom Disassembly book.

Then I added some more of what I understood.

Of course yours is the only complete and correct.....

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

The original Editor device in the 0 segment is exactly the same, but some addresses of the device buffer are accessed directly without indexing because the buffer was put at a fixed position on the FF segment(and probably to gain some free space in the Rom as they saved a byte in some direct addressing). Later with more room, on the Language ROMs they(you) decided to make the Editor, Video and Keyboard buffers relocatable as originally planned, rewriting new bi-lingual devices, and then all the accesses to the buffer addresses are made by indexing.
« Last Edit: 2017.July.10. 11:03:29 by gflorez »

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #178 on: 2017.July.10. 10:55:49 »
Here you can see how they(you) mixed the direct and indexed addressing on the first Editor version:

18198-0

Online gflorez

  • EP addict
  • *
  • Posts: 1978
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 52.0 Firefox 52.0
    • View Profile
Re: Universal Mouse Driver
« Reply #179 on: 2017.July.30. 19:28:57 »
At last  I have again a work code. After almost a year trying a lot of ways to do the click event inside the interrupt routine, several parts of the code retained a lot of rubbish  that I needed to clean before attempting the definitive one outside the Mouse driver....

But first I had to found how to communicate the code injected on the Editor driver and the Mouse driver.

It could be made rearranging the Mouse  system variables, but that is incompatible with older apps. After all I only had space for 2 more new Vars, 190 and 191. The first is totally populated of information(4 buttons and Z wheel), but the 191 still has the high nibble free, because on the lower one I have put definitively the Horizontal Wheel counter, just in case it would be implemented.

At the end I have better selected writing the Mouse channel, because once studied that part of the code, it is very simple to add a new command to P, O and o. For better flexibility I have implemented the "A" command, that returns three bytes, the segment and address on page 01 where the Mouse variable zone starts. I plan to access the Mouse data with an index register. This approach can have also its benefit if a Rom version of the Mouse driver is made on a "near" future...  For this purpose I have displaced all the variables to the end of the code, leaving the constants at their original place.

Then, as a way of communication, I will use that four upper bits on the 191 system var as flags. For example, if a Mouse-Editor video page has been opened, I will set bit 7, a click not finished will set bit 6, and the other spare two for other events,(imagine a scroll event with the wheel displacement...).
« Last Edit: 2017.July.30. 20:37:14 by gflorez »