Shenzhen I/O – Wireless Game Controller

Every hotel in Japan wants it only gaming console. And guess who is to make the wireless game controller for that! We are of course. The challenge here is to listen to the radio, and if there is a signal that we should send a reading back on the radio. We should read the two analogue joysticks (x and y) and send each value back as well as a value for the combination of a & b input 1 if a is active, 2 if b is active and 3 if both are active.

So all in all we need to send the following package on an xbus

x y 0 if a=0 and b=0
1 if a=100 and b=0
2 if a=0 and b=100
3 if a=100 and b=100

The verification signals look like

Shenzhen IO - Wireless Game Controller - signals

Structure of the wireless game controller solution

If we look at it straight up we need 4 simple inputs and 2 xbus inputs. Which means that we need multiple micro processors. However, I do think that it could be possible to combine a & b with a dx300 and thereby convert two simple inputs to 1 xbus input. That trick would put us within the range of using an MC6000 microcontroller and thereby make a cheaper solution than mulitple microcontrollers.

I therefore think we can wire the solution up as here

Shenzhen IO - Wireless Game Controller - structure

Coding a solution

The flow of the code should be something along the lines

  1. Did we receieve a signal to send a reading
  2. If not sleep and goto 1 – otherwise continue
  3. Send the x1, y1 and the combination of a and b to the output
  4. sleep

The pseudo code was simple enough to write and arrive at. But there are a few things that needs to be worked out. Let us start by tackling the a&b combination. When we read the x2 port we have the following possible readings

0 if a=0 and b=0
1 if a=100 and b=0
10 if a=0 and b=100
11 if a=100 and b=100

The first two options are good! The second two should be lower. However, as we can see if b is 100 we should add 2 to the output, we add 10. so if we read the solution and subtract 8 in the latter two solutions we would have something that worked.

With that part solved I believe we can code the full solution up

  teq x0 -999
+ jmp end

  mov x2 acc
  tgt acc 8
+ sub 8

  mov p1 x1
  mov p0 x1
  mov acc x1

end: slp 1

First we check if the wireless game controller needs to send a reading. Otherwise we will sleep and try again. If we need a reading we start by sorting out the a&b combination and then send all of it through the radio.

The final solution looks like

Shenzhen IO - Wireless Game Controller - solution

and ends up with the following stats

Cost: 6
Energy: 244
Lines of code: 9

And that is my conclusion to this problem. I can see that some manage to solve it using less power or fewer lines of code. I am not sure you can optimize this solution to have both. If you want to see all my solutions to Shenzhen I/O problems take a look at the solutions page.

Posted by Kristian


Sleeping 4 turns after sending data improves power consumption by a lot (energy: 130).

read: teq x0 -999
+ slp 1
+ jmp read

mov x2 acc
tgt acc 8
+ sub 8
mov p1 x1
mov p0 x1
mov acc x1
slp 4

One more DX300, lines of code: 8

teq x0 -1
+ mov x2 acc
+ add x3
+ add x3
+ mov p1 x1
+ mov p0 x1
+ mov acc x1
slp 1

Leave a Reply