Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - One more time: Paddle control (plus paddle detection, region detection)

Reply to topic
Author Message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
One more time: Paddle control (plus paddle detection, region detection)
Post Posted: Wed May 04, 2005 12:22 pm
Last edited by Maxim on Fri Jul 30, 2010 1:09 pm; edited 1 time in total
I was trying to write up a WIki page on this and just ended up totally confused as ever, by the difference between Japanese and Export systems' usage of it. It seems the paddle control was not released outside Japan (correct?); in which case, is the Handle Controller a paddle-like controller? That'd explain a lot.

So, I disassembled the first game I found that uses the paddle controller in both regions: Out Run 3D.

I'll post all the relevant bits. First up: region detection. I think we know this by now:
Quote
 ;=======================================================================
 ; Region detection
 ;=======================================================================
    ld     a,%11110101     ; Set both TH lines as outputs, value 1
    out    ($3f),a
    in     a,($dd)         ; Check inputs
    and    %11000000
    cp     %11000000       ; Are TH inputs 1?
    jr     nz,_Japanese    ; If not, it is not an export system
    ld     a,%01010101     ; Set both TH lines as outputs, value 0
    out    ($3f),a
    in     a,($dd)         ; Check inputs
    and    %11000000
    or     a               ; Are TH inputs zero?
    jr     nz,_Japanese    ; If not, it is not an export system

 _NotJapanese:
    ld     a,$ff           ; Reset all controls as inputs
    out    ($3f),a
    ; do something here for non-Japanese systems
    ret
 _Japanese:
    ; do something here for Japanese systems
    ret
 ;=======================================================================

What the game does is store 0 to RAM[c001] for Japanese systems, $ff for export. Next up: paddle detection. It does this differently depending on which region it's in.

Quote
 ;=======================================================================
 ; Paddle detection
 ;=======================================================================
    ; if region detected was Japanese, jump to _Japanese
    ; else jump to _NotJapanese
 _Japanese:
    ; Measure how much of the time the input from P1 TR is zero
    ; If it is strobing at a 50% duty cycle then it is probably
    ; from the paddle; a 12.5% margin of error is accepted
    ld     bc,$0000        ; b = 0 for 256 loops; c = 0 for counting
  -:in     a,($dc)
    bit    5,a             ; Get Player 1 TR input
    jr     nz,+            ; If 1, don't increment c
    inc    c
  +:djnz   -               ; repeat 256 times

    ld     a,c             ; inspect counter
    ; If the counter value is between $60 and $a0 (inclusive)
    ; then set b=$ff else set b=0
    ld     b,$00
    sub    $60
    jr     c,_DetectionEnd
    cp     $40
    jr     nc,_DetectionEnd
    dec    b
    jr     _DetectionEnd

 _NotJapanese:
    ; Check that TR input changes when TH output changes
    ld     a,%11011101     ; Output 0 to Player 1 TH
    out    ($3f),a
    ld     b,55            ; delay
  -:djnz   -
    in     a,($dc)         ; get Player 1 TR input
    and    %00100000
    ld     c,a             ; save in c
    ld     a,%11111101     ; Output 1 to Player 1 TH
    out    ($3f),a
    ld     b,13            ; delay
  -:djnz   -
    in     a,($dc)         ; get Player 1 TR input
    and    %00100000
    cp     c               ; check if it's the same as last time
    ld     b,$00           ; if it is, set b=0
    jr     z,_DetectionEnd
    dec    b               ; else set b=$ff
    ; fall through
 _DetectionEnd:
    ; do something with the result in b
    ; ($ff if a paddle was detected, 0 otherwise)
    ret
 ;=======================================================================

For Japanese systems, it counts how may times (out of 256) the input from TR (button 2) is zero; if it's roughly 50%, it means a paddle is there.

For Export systems, it outputs TH=0 and 1, and checks if TR (button 2) input changes between them. It also has some delays for the hardware to respond.

These two behaviours are completely different.

Next up: reading the paddle, and it's a big one.

Quote
 ;=======================================================================
 ; Paddle reading code
 ;=======================================================================
    ; if region detected was Japanese, jump to _Japanese
    ; else jump to _NotJapanese
 _Japanese:
    ; When TR is 0, the RLDU bits are the low 4 bits of the position.
    ; When TR is 1, the RLDU bits are the high 4 bits of the position.
  -:in     a,($dc)         ; Wait for TR input to be 0
    bit    5,a
    jr     nz,-
    and    $0f             ; Save UDLR bits in e
    ld     e,a
  -:in     a,($dc)         ; Wait for TR input to be 1
    bit    5,a
    jr     z,-
    ; fall through

 _CombineAandE:
    ; a contains the last input value with its low 4 bits containing the
    ;   high 4 bits of the paddle position.
    ; e contains just the low 4 bits of the paddle position.
    rrca                   ; Get low 4 bits into 4 high bits
    rrca
    rrca
    rrca
    and    $f0
    or     e               ; Merge with e

    ; We will add the current paddle position to the previous one and
    ; divide by 2, to help smooth out any noise
    ld     hl,LastPaddlePosition ; Get last position in e
    ld     e,(hl)
    ld     l,a
    xor    a
    ld     h,a
    ld     d,a
    add    hl,de
    srl    h
    rr     l
    ld     a,l             ; get averaged position
    ld     (LastPaddlePosition),a
    ret
    ; Result (paddle position) returned in a
 ;=======================================================================

 _NotJapanese:
    ld     a,%11011101     ; TH output 0
    out    ($3f),a
    ld     b,55            ; delay
  -:djnz   -
    in     a,($dc)         ; read input
    ld     c,a             ; save in c
    and    $0f             ;
    ld     e,a             ; save low 4 bits in e
    ld     a,%11111101     ; TH output 1
    out    ($3f),a
    ld     b,13            ; delay
  -:djnz   -
    in     a,($dc)         ; read input
    push   af              ; save on stack
      and    %00100000     ; examine TR input
      ld     b,a           ; if TR input was 1 both times, something is wrong
      ld     a,c
      and    %00100000
      and    b
      jr     nz,_TRInputUnchanged
    pop    af
    jp     _CombineAandE   ; else jump to _07ed

 _TRInputUnchanged:
    pop    af
    jp     _NotJapanese    ; Repeat forever
 ;=======================================================================

The Japanese paddle is simple: wait for TR (button 2) to be 0, and the RLDU lines are the low 4 bits of the poition. Wait for it to be 1, and they're the high 4 bits.

The export paddle is a different beast, because the system has to prompt it to change which four bits it returns. It also returns in TR to let you know it's done it, although whether it returns the TH value or its inverse is unclear (and apparently doesn't matter). It might also be an unreliable beast, since there is code there to explicitly keep trying until the output is correctly given (TR changes).

Here's the way I see it: the paddle schematic from Enri shows a clock crystal, no TH input and TR output being controlled by the chip. I'd venture a guess that the "export paddle" is exactly the same except that instead of the crystal, the TH line is used as the chip's "clock" input.

The reason: the Japanese Mark III has no capability to configure its controllers for output (it has no "port $3F"), so they had to make the paddle an output-only device. For the Export systems, they had that capability to save a few pennies on a single component (I see crystals costing 29p at Maplin, so they probably really cost about 2p) and they went for it.

If you plug a paddle into a non-paddle game you should see button 2 being pressed very fast (probably in the 10kHz range), which when sampled at 60Hz will give some aliased effects where the fraction of time for which it is pressed varies sinusoidally. Maybe someone can test this.

All this conjecture needs some real-world testing. Is there such a thing as an export paddle? Is the Handle Controller analogue? I read all the posts I could find, it seems it may even be dual-mode (with push/pull for up/down in regular mode so it works with After Burner). What do paddle games do on different regions' systems with a Japanese paddle?
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8114
  • Location: Paris, France
Reply with quote
Post Posted: Tue Apr 24, 2007 10:03 pm
Better late than never. I've been looking at trying to fix Woody Pop for it to work on an export system, so got back on this topic.

Answers:
- The Paddle Control was never released outside of Japan.
- I don't know about the Handle Controller on actual paddle games but I'll try to have it tested.
- I remember testing the Paddle with the test ROM on an export system, and button 2 was indeed being pushed repeatedly.

At first glance, Paddle games seems playable (apart from Woody Pop) on an export system, but as Phil mentionned under some fake identity ( http://www.smspower.org/forums/viewtopic.php?t=9917 ), it may be the case that the actual code on export system doesn't read the lower 4 bits on export systems - unconfirmed.

The way Woody Pop behave is that nibbles may be incorrect/inverted from time to time, which could be related to the clocked flip-flop.
I'll have a first patch of Woody Pop tested on an European/US system to see how it behave running the Japanese code.

I'm under the impression that only the japanese way of polling the paddle may be correct, the other one was made in preparation for another export paddle but actually not working with a japanese paddle.

Maxim, I can send you a Paddle Control if you want one.

PS: Thanks a lot for this post and information on the Wiki. They were invaluable, considering how confused I was by Paddle Control emulation and my old crappy Meka code.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Wed Apr 25, 2007 8:11 am
I think my first post is a little unclear. Basically:

- The Japanese paddle is internally clocked to alternate between the high and low nibbles and the mythical export version is not.
- The Japanese one signals its clock state on button 2, as soon as that changes the UDLR lines hold valid data and the state of button 2 tells you which nibble it is.
- The export one has to be told to change nibble by signalling on TH; the code thern has to poll for a change in the button 2 input before reading UDLR.
- For both, it seems common to apply some simple smoothing to the value read because it is likely to be noisy. Smoothing is typically [new state] = ([value read] + [last state]) / 2.

Any game that works with a Japanese paddle on a Japanese system but contains the export paddle reading code (as in my first post above with Out Run 3D) can be easily hacked by subverting the branch which chooses which paddle reading code to use. A game with only export paddle reading code can probably be patched by adding a stock paddle reading routine in place, or in empty space.[/list]
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8114
  • Location: Paris, France
Reply with quote
Post Posted: Wed Apr 25, 2007 9:19 am
Yes. The original post was clear enough for me.

What we yet have to confirm is which of both methods works on which systems/paddle combo. Obviously the japanese method works on japanese system with a japanese paddle, but other combination may or may not function.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Wed Apr 25, 2007 10:18 am
Well...

- A Japanese paddle would only work with export reading code if the code was coded to support it (either detect which nibble was returned and deal with it, or wait for the right one to be returned) - the Out Run 3D code above seems* not to (it seems to expect that the next time button 2's state changes, the next nibble read is the one expected based on the TH output).
- An "export paddle" would never work with Japanese paddle code because it never triggers a clock update.

* maybe it is though, it is doing some weird stuff that looks like it could be for that...
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8114
  • Location: Paris, France
Reply with quote
Post Posted: Thu Apr 26, 2007 7:01 pm
Based on this topic, two reports that the Japanese Paddle works on Export systems using Japanese polling code:
http://www.smspower.org/forums/viewtopic.php?t=9921
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Mon Jul 27, 2009 7:20 am
I couldn't find this elsewhere, but I'm assuming the handle controller :-



Is what Outrun is detecting, and that this is similar to the paddle except for the differences noted by Maxim. Having never used the Handle Controller, are those 2 buttons on the top of "sticks" button 1 and 2 in game? It's nice work you've done Maxim reversing the paddle info.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Mon Jul 27, 2009 12:54 pm
There are too many unanswered questions in this thread :( It has still not been confirmed whether the Handle Controller is analogue (returning position 0..255) or digital (just sending binary UDLR). This is partly because they are so rare, few people can answer the questions.

One bit of new information is documentation of its cable connector, which seems to suggest it's digital.

For games like Out Run, I believe the paddle position is directly tied to the car's position, as opposed to being steering wheel-like. This would make a steering wheel analogue controller very unnatural to use.
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Mon Jul 27, 2009 1:28 pm
Maxim wrote
There are too many unanswered questions in this thread :( It has still not been confirmed whether the Handle Controller is analogue (returning position 0..255) or digital (just sending binary UDLR). This is partly because they are so rare, few people can answer the questions.

For games like Out Run, I believe the paddle position is directly tied to the car's position, as opposed to being steering wheel-like. This would make a steering wheel analogue controller very unnatural to use.


Hmm, I thought this handle controller was bundled with Outrun for some reason and the look of it suggests paddle like behaviour, but after some further reading it seems to be targeted for general use in flight sims as well. So it must just be a typical controller input with a weird (read Sega realistic :) ) physical mechanism. Wikipedia does lists it as a paddle controller though.... so.... :)

I was hoping there would be a real "export" paddle out there, just hidden in the form of this handle controller, but oh well. These "extra" Sega controllers seem real gimmicky to me though, they don't really offer that much in the way of improving control, in fact it seems to take away control... maybe that was the purpose.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Mon Jul 27, 2009 4:16 pm
It seems the "export paddle" was coded for and possibly even tested, but never released; maybe people thought analogue control was outdated at the time. However, as a control method, paddles are an interesting and unique method that has yet to come full circle, with modern tilt and waggle a poor substitute for the precision of a simple variable resistor.
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Wed Jul 29, 2009 2:07 pm
Just some more thoughts

1) We need actual confirmation the Japanese paddle works with the export games. Someone holding up todays New York times and their drivers license whilst videoing themselves playing Outrun with a paddle in the presence of a lawyer will do.

2) I guess it's not possible the Japanese paddle had circuitry to toggle which just wasn't used on the Japanese consoles. TH Pin seems to be absent off the schematic on the WIKI so I guess it isn't connected?

3) In my emulator using the japanese paddle in export mode... the game thinks a paddle is there in Outrun in 10 runs out of 10 runs but the gameplay is a bit twitchy compared to playing in japanese mode. In Outrun 3D it doesn't, in 5 runs out of 5 runs. Maybe the two games have different code and this is what is leading to the confusion... ;)
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8114
  • Location: Paris, France
Reply with quote
Post Posted: Wed Jul 29, 2009 2:17 pm
Geez, I should have tested with the Handle Controller when I got it before leaving.
James Costello maybe can test with Out Run and Woody Pop ?
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Wed Jul 29, 2009 2:21 pm
Ok actually Outrun 3D and Outrun DO behave the same, it was an error on my part not enabling the paddle for Outrun 3D :P.

I think I need to improve my paddle emulation though as it doesn't "emulate" the paddle switching at ~10khz (looking at the cycle delays in the code), I should be getting some failures to detect the paddle but am not.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Wed Jul 29, 2009 5:47 pm
The switching rate of the Japanese paddle is unknown - the delays are for the export paddle, and are there to allow it time to "react" to the input signal. The Japanese one may presumably be considered to be instantaneous - the status bit and data bits change at the same instant - the code seems to assume this.

I can't imagine why paddle detection on a European system would work with a Japanese paddle, other than by dumb luck which ought to happen 50% of the time (50% of the time, the second paddle read will have a different status bit to the previous one, if the time interval is long compared to the switching rate). Are you sure it's going through the right bit of code?
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Wed Jul 29, 2009 10:46 pm
Maxim wrote
The switching rate of the Japanese paddle is unknown - the delays are for the export paddle, and are there to allow it time to "react" to the input signal.


It may be unknown, but we know the conservative lower end, there are only 4 instructions between each read in the code you show for detecting the paddle. So it is switching quite high. Presumably the upper end would likely be something like ~15 z80 cycles, lower end ~35 cycles, which is about 142khz when you average it.

My emulator was just being lazy with the paddle and switching its toggle on every read. So it's going to pass the test every time looking at that code. I'm going to have to log the Z80 cycles elapsed between each read and fudge the amount of iterations using ~25 z80 cycles or so. It might not be perfect, but it is a good kludge.

I'm still wondering whether I should add this export paddle or not to my input list (the rom format). Obviously the device existed at some stage so I'm thinking it should be in there and it's not hard to add it... just feels a bit mysterious though. Even though I'm emulating some devices I've never used, the idea of emulating something maybe only a few people ever used is interesting.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Thu Jul 30, 2009 8:07 am
PoorAussie wrote
Maxim wrote
The switching rate of the Japanese paddle is unknown

It may be unknown, but we know the conservative lower end, there are only 4 instructions between each read in the code you show for detecting the paddle. So it is switching quite high.

Well, we know it's probably fast - probably in the kHz, otherwise it'd waste too much time polling it. But the upper bound is impossible to infer - adding a wait before, or during, polling would gain nothing so it's not there. Optimising it to flip state each time it's read is a decent kludge (so long as no game somehow gets in perfect antiphase with that), else you're going to need to get hold of a paddle and a frequency meter, or failing that get someone to tell you the clock rate of that crystal and hope that's the answer.

The export paddle detection only checks for the state bit change, it doesn't check the actual value. It's almost as if that wasn't correctly documented. Thus this kludge will result in the nibble being transposed sometimes.

My guess is that a real Japanese paddle on an Export system will sometimes get detected (about 50% of the time) and it will then give results that are mixed up a lot of the time, making it unusable. As discussed elsewhere, hacking the region check to make it use the Japanese reading with a Japanese paddle works perfectly.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Oct 2009
  • Posts: 138
Reply with quote
Post Posted: Fri Jun 10, 2011 7:57 am
Haven't disassembled Alex Kidd BMX Trial to determine for sure, but it seems this game was also designed with Western Paddle in mind.

I get different behaviour in RetroCopy using the japanese paddle code on a western system. The game itself doesn't show the "Mark III" flashing title on export systems, so it's possible this game was going to be released in the West with the export paddle.

In Meka I notice in export mode it starts off left if you don't press anything, and right in Jap mode. Because there is no auto center in Meka (by default anyhow) it's a hard to notice issue.

So more evidence for the mysterious export paddle I guess. :)

*edit* And Woody Pop is the same too.
  View user's profile Send private message Visit poster's website
  • Joined: 11 Mar 2014
  • Posts: 89
  • Location: France
Reply with quote
Post Posted: Wed Jul 23, 2014 11:37 pm
3 years old bump.

I have modified my SMS2 to accept japanese cartridges. I own Megumi Rescue, Alex Kidd BMX Trial and Galactic Protector, along with the paddle. It kind of work but when not on the extreme positions the controlled character wobbles constantly between two fixed positions. It's described more easily with Galactic protector: I can access the eight directions but nothing in between, and when I'm not facing down the ship constantly blinks between two consecutive directions.

The console isn't modded with a Region swich. Somehow mine is resistant to the switch put on the SMSFM board and I haven't yet tried to figure out why or how I could make it work.

I don't know if the games expect a western paddle on a western console or if it's just my paddle malfunctioning (I only have one to test).
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Thu Jul 24, 2014 7:22 am
There aren't 8 positions, there are 256. The wobbling you see is due to the game misinterpreting the paddle data. I think you need to either patch the game to not try to use the "export paddle" (which doesn't exist), or do a region mod to make the game think it's a Japanese console, or make an export paddle (untested theory: remove the clock and connect to the SMS output line instead).
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2015
  • Posts: 1
  • Location: Montreal, Canada
Reply with quote
Post Posted: Sun Mar 29, 2015 3:39 pm
jarreboum wrote
I don't know if the games expect a western paddle on a western console or if it's just my paddle malfunctioning (I only have one to test).

I think your paddle is most likely working fine.

I recently built my own Paddle Control using a micro-controller, and tested it on a Japanese SMS console as well as a North-american Genesis console through an adapter. On my north american system, Galactic protector behaved exactly as you describe. The game seems to detect it's not running on a Japanese console and switches to "export paddle" mode.

Using the information in this thread, I also implemented an "Export paddle" mode in my firmware and was able to get it to work properly with Galactic protector on my non-Japanese system.

At this point I would gladly share the link to my DIY paddle project page, but I can't since I'm a new member... Search for raphnet dot net if you're interested and you should find it.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12974
  • Location: London
Reply with quote
Post Posted: Sun Mar 29, 2015 3:45 pm
http://www.raphnet.net/electronique/sms_paddle/index.php
http://www.raphnet.net/electronique/sms_paddle/index_en.php
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!