Path: blob/a-new-beginning/Cherry/Core/include/ColecoVisionIOPorts.h
2 views
/*1* Gearcoleco - ColecoVision Emulator2* Copyright (C) 2021 Ignacio Sanchez34* This program is free software: you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation, either version 3 of the License, or7* any later version.89* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.1314* You should have received a copy of the GNU General Public License15* along with this program. If not, see http://www.gnu.org/licenses/16*17*/1819#ifndef COLECOVISIONIOPORTS_H20#define COLECOVISIONIOPORTS_H2122#include "IOPorts.h"2324class Audio;25class Video;26class Input;27class Cartridge;28class CVMemory;29class Processor;3031class ColecoVisionIOPorts : public IOPorts32{33public:34ColecoVisionIOPorts(Audio* pAudio, Video* pVideo, Input* pInput, Cartridge* pCartridge, CVMemory* pMemory, Processor* pProcessor);35~ColecoVisionIOPorts();36void Reset();37u8 In(u8 port);38void Out(u8 port, u8 value);39private:40Audio* m_pAudio;41Video* m_pVideo;42Input* m_pInput;43Cartridge* m_pCartridge;44CVMemory* m_pMemory;45Processor* m_pProcessor;46};4748#include "Video.h"49#include "Audio.h"50#include "Input.h"51#include "Cartridge.h"52#include "CVMemory.h"53#include "Processor.h"5455inline u8 ColecoVisionIOPorts::In(u8 port)56{57switch(port & 0xE0) {58case 0xA0:59{60if (port & 0x01)61{62return m_pVideo->GetStatusFlags();63}64else65{66return m_pVideo->GetDataPort();67}68break;69}70case 0xE0:71{72return m_pInput->ReadInput(port);73}74default:75{76if (port == 0x52)77{78return m_pAudio->SGMRead();79}80return 0xFF;81}82}8384Debug("--> ** Attempting to read from port $%X", port);8586return 0xFF;87}8889inline void ColecoVisionIOPorts::Out(u8 port, u8 value)90{91switch(port & 0xE0) {92case 0x80:93{94m_pInput->SetInputSegment(Input::SegmentKeypadRightButtons);95break;96}97case 0xA0:98{99if (port & 0x01)100{101m_pVideo->WriteControl(value);102}103else104{105m_pVideo->WriteData(value);106}107break;108}109case 0xC0:110{111m_pInput->SetInputSegment(Input::SegmentJoystickLeftButtons);112break;113}114case 0xE0:115{116m_pAudio->WriteAudioRegister(value);117m_pProcessor->InjectTStates(32);118break;119}120default:121{122if (port == 0x50)123{124m_pAudio->SGMRegister(value);125break;126}127else if (port == 0x51)128{129m_pAudio->SGMWrite(value);130break;131}132else if (port == 0x53)133{134m_pMemory->EnableSGMUpper((value & 0x01) != 0);135}136else if (port == 0x7F)137{138m_pMemory->EnableSGMLower((~value & 0x02) != 0);139m_pMemory->EnableSGMUpper((value & 0x01) != 0);140}141else142{143Debug("--> ** Output to port $%X: %X", port, value);144}145}146}147}148149#endif /* COLECOVISIONIOPORTS_H */150151152