File: Joystick.cxx

package info (click to toggle)
stella 0.7-2
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 864 kB
  • ctags: 1,158
  • sloc: cpp: 6,615; ansic: 492; makefile: 224; asm: 31
file content (130 lines) | stat: -rw-r--r-- 3,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//============================================================================
//
//    SSSS    tt          lll  lll              
//   SS  SS   tt           ll   ll                
//   SS     tttttt  eeee   ll   ll   aaaa    "An Atari 2600 VCS Emulator"
//    SSSS    tt   ee  ee  ll   ll      aa      
//       SS   tt   eeeeee  ll   ll   aaaaa   Copyright (c) 1995,1996,1997
//   SS  SS   tt   ee      ll   ll  aa  aa         Bradford W. Mott
//    SSSS     ttt  eeeee llll llll  aaaaa    
//
//============================================================================

/**
  The 2600's joystick controller.

  @author  Bradford W. Mott
  @version $Id: Joystick.cxx,v 1.2 1997/05/17 19:00:05 bwmott Exp $
*/

#include "BasTerm.hxx"
#include "Joystick.hxx"
#include "System.hxx"

//============================================================================
// Constructor
//============================================================================
Joystick::Joystick(const System& system, Joystick::PhysicalPort port)
    : Controller(system),
      myPort(port)
{
}
 
//============================================================================
// Destructor
//============================================================================
Joystick::~Joystick()
{
}

//============================================================================
// Invoked before each frame is generated
//============================================================================
void Joystick::update()
{
  if(myPort == Zero)
  {
    if(mySystem.terminal().eventState(BasicTerminal::LeftJoystickFire))
    {
      // Clear the fire button bit
      myTIA &= 0x03;
    }
    else
    {
      // Set the fire button bit
      myTIA |= 0x04;
    }

    // Joystick Right
    if(mySystem.terminal().eventState(BasicTerminal::LeftJoystickRight))
      myPIA &= 0x07;
    else
      myPIA |= 0x08;

    // Joystick Left
    if(mySystem.terminal().eventState(BasicTerminal::LeftJoystickLeft))
      myPIA &= 0x0b;
    else
      myPIA |= 0x04;

    // Joystick Down
    if(mySystem.terminal().eventState(BasicTerminal::LeftJoystickDown))
      myPIA &= 0x0c;
    else
      myPIA |= 0x02;

    // Joystick Up
    if(mySystem.terminal().eventState(BasicTerminal::LeftJoystickUp))
      myPIA &= 0x0e;
    else
      myPIA |= 0x01;
  }
  else
  {
    if(mySystem.terminal().eventState(BasicTerminal::RightJoystickFire))
    {
      // Clear the fire button bit
      myTIA &= 0x03;
    }
    else
    {
      // Set the fire button bit
      myTIA |= 0x04;
    }

    // Joystick Right
    if(mySystem.terminal().eventState(BasicTerminal::RightJoystickRight))
      myPIA &= 0x07;
    else
      myPIA |= 0x08;

    // Joystick Left
    if(mySystem.terminal().eventState(BasicTerminal::RightJoystickLeft))
      myPIA &= 0x0b;
    else
      myPIA |= 0x04;

    // Joystick Down
    if(mySystem.terminal().eventState(BasicTerminal::RightJoystickDown))
      myPIA &= 0x0c;
    else
      myPIA |= 0x02;

    // Joystick Up
    if(mySystem.terminal().eventState(BasicTerminal::RightJoystickUp))
      myPIA &= 0x0e;
    else
      myPIA |= 0x01;
  }
}

//============================================================================
// Configure the TIA part of the controller
//============================================================================
void Joystick::configureTIA(Controller::TIACommand)
{
  // TODO: I guess we should really do something if we receive
  //       the latch enable or disable command
}