void M6532::poke()

in atari_py/ale_interface/src/emucore/M6532.cxx [221:320]


void M6532::poke(uInt16 addr, uInt8 value)
{
  if((addr & 0x07) == 0x00)         // Port A I/O Register (Joystick)
  {
    uInt8 a = value & myDDRA;

    myConsole.controller(Controller::Left).write(Controller::One, a & 0x10);
    myConsole.controller(Controller::Left).write(Controller::Two, a & 0x20);
    myConsole.controller(Controller::Left).write(Controller::Three, a & 0x40);
    myConsole.controller(Controller::Left).write(Controller::Four, a & 0x80);
    
    myConsole.controller(Controller::Right).write(Controller::One, a & 0x01);
    myConsole.controller(Controller::Right).write(Controller::Two, a & 0x02);
    myConsole.controller(Controller::Right).write(Controller::Three, a & 0x04);
    myConsole.controller(Controller::Right).write(Controller::Four, a & 0x08);
  }
  else if((addr & 0x07) == 0x01)    // Port A Data Direction Register 
  {
    myDDRA = value;
#ifdef ATARIVOX_SUPPORT
     /*
    20060608 bkw: Not the most elegant thing in the world...
     When a bit in the DDR is set as input, +5V is placed on its output
     pin. When it's set as output, either +5V or 0V (depending on the
     contents of SWCHA) will be placed on the output pin.
     The standard macros for the AtariVox use this fact to send data
     to the port.

     This code isn't 100% correct: it assumes the SWCHA bits are all 0.
     This is good enough to emulate the AtariVox, if the programmer is
     using SWACNT to do output (e.g. the SPKOUT macro from speakjet.inc)
     and if he's leaving SWCHA alone.

     The inaccuracy here means that wrongly-written code will still
     be able to drive the emulated AtariVox, even though it wouldn't
     work on real hardware.
     */
    Controller &c = myConsole.controller(Controller::Right);
     if(c.type() == Controller::AtariVox) {
      c.write(Controller::One, !(value & 0x01));
      c.write(Controller::Two, !(value & 0x02));
      c.write(Controller::Three, !(value & 0x04));
      c.write(Controller::Four, !(value & 0x08));
     }
#endif
  }
  else if((addr & 0x07) == 0x02)    // Port B I/O Register (Console switches)
  {
    return;
  }
  else if((addr & 0x07) == 0x03)    // Port B Data Direction Register
  {
//        myDDRB = value;
    return;
  }
  else if((addr & 0x17) == 0x14)    // Write timer divide by 1 
  {
    myTimer = value;
    myIntervalShift = 0;
    myCyclesWhenTimerSet = mySystem->cycles();
    myTimerReadAfterInterrupt = false;
  }
  else if((addr & 0x17) == 0x15)    // Write timer divide by 8
  {
    myTimer = value;
    myIntervalShift = 3;
    myCyclesWhenTimerSet = mySystem->cycles();
    myTimerReadAfterInterrupt = false;
  }
  else if((addr & 0x17) == 0x16)    // Write timer divide by 64
  {
    myTimer = value;
    myIntervalShift = 6;
    myCyclesWhenTimerSet = mySystem->cycles();
    myTimerReadAfterInterrupt = false;
  }
  else if((addr & 0x17) == 0x17)    // Write timer divide by 1024
  {
    myTimer = value;
    myIntervalShift = 10;
    myCyclesWhenTimerSet = mySystem->cycles();
    myTimerReadAfterInterrupt = false;
  }
  else if((addr & 0x14) == 0x04)    // Write Edge Detect Control
  {
#ifdef DEBUG_ACCESSES
    ale::Logger::Error << "M6532 Poke (Write Edge Detect): "
                       << ((addr & 0x02) ? "PA7 enabled" : "PA7 disabled")
                       << ", "
                       << ((addr & 0x01) ? "Positive edge" : "Negative edge")
                       << endl;
#endif
  }
  else
  {
#ifdef DEBUG_ACCESSES
    ale::Logger::Error << "BAD M6532 Poke: " << hex << addr << endl;
#endif
  }
}