Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Reading C1531 Mouse from both ports
2010-06-08 12:18
TWW

Registered: Jul 2009
Posts: 545
Reading C1531 Mouse from both ports

In the C64 & C128, the SID POT lines are connected to both joystick ports. A 4066 analog switch is used to switch the POT lines between the two ports based on one of the keyboard scan lines. This means that the normal keyscan interrupt temporarily affects the values returned in the POT registers. Therefore, in order to perform reliable conversions, the POT lines must be connected to the mouse for a period >1.6 millisecond before the value in the POT register is valid.


I tried reading the POTs as follows:

lda #$80 // select Joyport #2
sta $dc00

waste 512 cycles

lda $d419
-doshit
lda $d41a
-doshit

lda #$40 // select Joyport #1
sta $dc00

waste 512 cycles

lda $d419
-doshit
lda $d41a
-doshit

rts


From the referance manual:

DC00 56320 Data Port A (Keyboard, Joystick, Paddles, Light-Pen)
7-0 Write Keyboard Column Values for Keyboard Scan
7-6 Read Paddles on Port A / B (01 = Port A, 10 = Port B)
4 Joystick A Fire Button: 1 = Fire
3-2 Paddle Fire Buttons
3-0 Joystick A Direction (0-15)


On both vice & ccs64 this gives funny readings. Have I gotten this all wrong or is it simply not emulated good enough?

-TWW
2010-06-10 07:24
TWW

Registered: Jul 2009
Posts: 545
Let me rephrase:

I am currently working on a IO-Driver which automatically detects if it's a mouse or a joystick (Or even two mice or joysticks or combination mouse & joystick) and at the same time handles the Keyboard in a 'correct' manner. But I am limited to working with emus and hence the nag...


IF a routine looks as follows:
(DDR's set to default)

:IRQInit

irq:

lda $d419  // Read PotX
sta $0400

lda $d41a  // Read PotY
sta $0401

pla
tax
pla
tay
pla
rti



In VICE I get readings regardless of which mouse port i "plug" the c1531 mouse into while on CCS64 it will only react if I "plug" the mouse into Port #1 (which is the way it should be if I understand the documentation correctly).

However the mouse emulation on CCS64 messes up the bits (ASL them) for some strage reason (as mentioned in another post)..

Conclution: Mouse emulation is flawed on both emulators.

IMO: The POT input should be flip-flopped between port A or Port B depending on the 2 MSBs of $dc00 (#$40 or #$80). And Mouse buttons should be read from Bit #5 & 1 of the corresponding port.

Are there someone who has any experience regarding this or perhaps the chance to test this on a real C64 ad a C1531 mouse (I will happily provide some "test-software" if you need it)...
2010-06-10 07:28
JackAsser

Registered: Jun 2002
Posts: 2014
I came to the same conclusion for my mouse driver in Eye of the Beholder. More over, VICE only send the mouse buttons to port 1, but port values to both iirc. Or something like that... :) It was a while ago I coded it so my memory isn't exactly fresh.
2010-06-10 08:00
zyga
Account closed

Registered: Mar 2009
Posts: 6
Long time ago, I've found strange behavior in 2 versions of Lemmings (crack) on real machine (C128DCR).

While this game supports mouse1531 in proportional mode and cursor moves smoothly, mouse buttons doesn't have any effect !
Instead of it, joystick button in opposite port works well !

But it seems little uncomfortable to move cursor by mouse, and click by joystick :) Of course joystick emulation mode was working as expected.

I don't know if this is crack "feature", my machine failure (although AmicaPaint an Geos works fine), or bug in game itself.
2010-06-10 08:40
enthusi

Registered: May 2004
Posts: 677
I noticed the x/y and button issue between port 1/2 in vice.
Confuses people in ManiacMansion Gold sometimes.
I can run a test-prg on real thing with 1351 if needed.
Joy+mouse in MM was a mess. In the end I decided to add the 'mouse toggle' key (for numerous reasons).

2010-06-10 09:00
Nafcom

Registered: Apr 2002
Posts: 588
Quote: Long time ago, I've found strange behavior in 2 versions of Lemmings (crack) on real machine (C128DCR).

While this game supports mouse1531 in proportional mode and cursor moves smoothly, mouse buttons doesn't have any effect !
Instead of it, joystick button in opposite port works well !

But it seems little uncomfortable to move cursor by mouse, and click by joystick :) Of course joystick emulation mode was working as expected.

I don't know if this is crack "feature", my machine failure (although AmicaPaint an Geos works fine), or bug in game itself.


I own the original version of Lemmings, in fact the buttons of the Commmodore 1531 mouse do work, (all port 1 only).
And I have tried it with different 1531 mice clones but no chance, there the movements do not work
(I have tried a CMD SmartMouse and a Scantronik mouse). So it only works wth the originals even though claimed to be 100% compatible clones.

Tried on different C64s, too.
2010-06-10 09:09
zyga
Account closed

Registered: Mar 2009
Posts: 6
I have had original 1531 (original Commodore box with Geos driver and book), but Lemmings was not original.

Sadly, I do not have this C128DCR nor 1531 anymore...
2010-06-11 11:28
TWW

Registered: Jul 2009
Posts: 545
Quote: I noticed the x/y and button issue between port 1/2 in vice.
Confuses people in ManiacMansion Gold sometimes.
I can run a test-prg on real thing with 1351 if needed.
Joy+mouse in MM was a mess. In the end I decided to add the 'mouse toggle' key (for numerous reasons).



Alright. I'll send you a .prg file and I am very curious what you find out

aspect of my code might be screwed too so I hope we can come up with a full-good solution which works on the real thing the nag the emu-people untill they get it right :)

brgds!
2010-06-11 18:11
rattus
Account closed

Registered: Oct 2002
Posts: 14
Not really related, but Interpaint version with support for amiga mouse works like a charm with amiga mouse... Everyone has 1 amiga mouse stored somewhere, so... :)
2010-06-11 19:52
TWW

Registered: Jul 2009
Posts: 545
Update:

Tested under hoxs64 emu but couldn't figgure out how to enable c1351 mouse emulation.....
2010-06-12 07:39
enthusi

Registered: May 2004
Posts: 677
TWW, thx - will test today and post here. cool
2010-06-12 11:05
enthusi

Registered: May 2004
Posts: 677
TWW,
c1351 in port2:
CARRY becomes set
ACC becomes %11111111
movement caused 'change' in $fe,$ff
both buttons have no effect

port1:
CARRY clear
ACC %00111111
movements show in $fc (green?!),$fd

left button: Y-REg = %10000000
right button: Y-REg = %01000000

PADDLES:
one plug, 2 paddles
@port2: change in $fe,$ff
button - nothing
Same for both paddels

@port1:
change in $fc,$fd

button changes Y to %1000000
for both paddles!

ACC and CARRY same as for mouse depending on port-connection.

Hope, this helps :)
Would be nicer to have an actual pointer in your test-code as well.
And why is the irq that unstable?
No SEI?
RESTORE changes $fb at least...

Cheers,
enthusi

2010-06-12 11:39
TWW

Registered: Jul 2009
Posts: 545
Quote: TWW,
c1351 in port2:
CARRY becomes set
ACC becomes %11111111
movement caused 'change' in $fe,$ff
both buttons have no effect

port1:
CARRY clear
ACC %00111111
movements show in $fc (green?!),$fd

left button: Y-REg = %10000000
right button: Y-REg = %01000000

PADDLES:
one plug, 2 paddles
@port2: change in $fe,$ff
button - nothing
Same for both paddels

@port1:
change in $fc,$fd

button changes Y to %1000000
for both paddles!

ACC and CARRY same as for mouse depending on port-connection.

Hope, this helps :)
Would be nicer to have an actual pointer in your test-code as well.
And why is the irq that unstable?
No SEI?
RESTORE changes $fb at least...

Cheers,
enthusi



Interesting...

The change you are experiencing on $fc, fd, fe & ff is the X & Y change in signed byte from the 2 ports (Meaning bit #7 = 1 means negative direcition change and 0 means positive direction change(for the mice)). AFAICT this is then working as it should do. I'll include a "pointer" to check this properly and make you happpy at the same time aswell ;]


The green you get is a confirmed detection of mouse in Port #1 (However I have not made that for port #2 yet so i'll include that in next driver ^^) However it is strange that the Carry isn't set in this case but then again I need to re-evaluate my code here a little bit...

LMB/RMB from mouse-port #2 should be shown in the 2 MSB of the Accumulator so I need to re-think that one aswell...

plan:

Recode known bugs and map up $dc00 while reading mousebuttons from port #2 to figgure out what is going on there. Also I'll add more green depending on detection or not :) and ofcourse the pointer (I'll set up different collours aswell depending on Mouse port #1 or 2^^)

If we can make this SW work properly I'll upload it here as a "test-program" which emu-ppl and other with real HW can use for testing purposes AND hopefully it can also serve as a standard IO driver for those who don't want to use the KERNA/EL.

Ignore IRQ/NMI stuff as this isn't set up to do nothing except call the routine each frame and display data.

Thanx for your prompt response and Hopefully I'll have something new to try during the weekend.

cheers TWW/CTR
2010-06-12 21:58
TWW

Registered: Jul 2009
Posts: 545
Alright A new version is ready. I have uploaded it here on CSDB: C1351 Mouse Driver / Test Software

Eagerly awaiting test results C",)

TWW/CTR
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Sokrates
The Human Co../Maste..
t0m3000/hf^boom!^ibx
fieserWolF/Abyss-Con..
kbs/Pht/Lxt
iAN CooG/HVSC
Alakran_64
MWR/Visdom
Andy/AEG
Guests online: 100
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.7)
4 Acidchild  (9.7)
5 Cash  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.046 sec.