dingusppc/devices/serial/escc.h

147 lines
3.9 KiB
C
Raw Normal View History

2021-10-25 20:18:02 +00:00
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
2022-05-02 22:16:09 +00:00
Copyright (C) 2018-22 divingkatae and maximum
2021-10-25 20:18:02 +00:00
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Enhanced Serial Communications Controller (ESCC) definitions. */
#ifndef ESCC_H
#define ESCC_H
#include <devices/common/hwcomponent.h>
2022-05-07 19:38:27 +00:00
#include <devices/serial/chario.h>
2021-10-25 20:18:02 +00:00
#include <cinttypes>
#include <memory>
#include <string>
2022-02-26 09:55:30 +00:00
/** ESCC register positions */
/* Please note that the registers below are provided
2022-05-02 22:16:09 +00:00
by the Apple I/O controllers for accessing ESCC
in a more convenient way. Actual physical addresses
are controller dependent.
The registers are ordered according with the MacRISC
scheme used in the PCI Power Macintosh models.
Pre-PCI Macs uses the so-called compatibility
addressing. Please use compat_to_macrisc table
below for converting from compat to MacRISC.
*/
2021-10-25 20:18:02 +00:00
enum EsccReg : uint8_t {
Port_B_Cmd = 0,
2022-05-02 22:16:09 +00:00
Port_B_Data = 1, // direct access to WR8/RR8
Port_A_Cmd = 2,
2022-02-26 09:55:30 +00:00
Port_A_Data = 3, // direct access to WR8/RR8
Enh_Reg_B = 4, // undocumented Apple extension
Enh_Reg_A = 5, // undocumented Apple extension
2021-10-25 20:18:02 +00:00
};
2022-05-02 22:16:09 +00:00
extern const uint8_t compat_to_macrisc[6];
2022-02-26 09:55:30 +00:00
/** LocalTalk LTPC registers provided by a MacIO controller. */
2021-10-25 20:18:02 +00:00
enum LocalTalkReg : uint8_t {
Rec_Count = 8,
Start_A = 9,
Start_B = 0xA,
Detect_AB = 0xB,
};
enum WR0Cmd : uint8_t {
Point_High = 1,
};
2022-02-23 21:23:02 +00:00
/** ESCC reset commands. */
enum {
RESET_ESCC = 0xC0,
RESET_CH_A = 0x80,
RESET_CH_B = 0x40
};
2022-02-26 09:55:30 +00:00
/** DPLL commands in WR14. */
enum {
2022-05-07 19:38:27 +00:00
DPLL_NULL_CMD = 0,
2022-02-26 09:55:30 +00:00
DPLL_ENTER_SRC_MODE = 1,
DPLL_RST_MISSING_CLK = 2,
DPLL_DISABLE = 3,
DPLL_SET_SRC_BGR = 4,
DPLL_SET_SRC_RTXC = 5,
DPLL_SET_FM_MODE = 6,
DPLL_SET_NRZI_MODE = 7
};
enum DpllMode : uint8_t {
NRZI = 0,
FM = 1
};
2021-10-25 20:18:02 +00:00
/** ESCC Channel class. */
class EsccChannel {
public:
EsccChannel(std::string name) { this->name = name; };
~EsccChannel() = default;
2022-05-07 19:38:27 +00:00
void attach_backend(int id);
2022-02-23 21:23:02 +00:00
void reset(bool hw_reset);
uint8_t read_reg(int reg_num);
2021-10-25 20:18:02 +00:00
void write_reg(int reg_num, uint8_t value);
2022-02-26 09:55:30 +00:00
void send_byte(uint8_t value);
uint8_t receive_byte();
2021-10-25 20:18:02 +00:00
private:
std::string name;
2022-02-23 21:23:02 +00:00
uint8_t read_regs[16];
2021-10-25 20:18:02 +00:00
uint8_t write_regs[16];
2022-02-26 09:55:30 +00:00
uint8_t wr7_enh;
uint8_t dpll_active;
uint8_t dpll_mode;
uint8_t dpll_clock_src;
uint8_t brg_active;
uint8_t brg_clock_src;
2022-05-07 19:38:27 +00:00
std::unique_ptr<CharIoBackEnd> chario;
2021-10-25 20:18:02 +00:00
};
/** ESCC Controller class. */
class EsccController : public HWComponent {
2021-10-25 20:18:02 +00:00
public:
EsccController();
~EsccController() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<EsccController>(new EsccController());
}
// ESCC registers access
2021-10-25 20:18:02 +00:00
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
private:
2022-02-23 21:23:02 +00:00
void reset();
2021-10-25 20:18:02 +00:00
void write_internal(EsccChannel* ch, uint8_t value);
std::unique_ptr<EsccChannel> ch_a;
std::unique_ptr<EsccChannel> ch_b;
int reg_ptr; // register pointer for reading/writing (same for both channels)
2022-02-26 09:55:30 +00:00
2022-02-23 21:23:02 +00:00
uint8_t master_int_cntrl;
uint8_t int_vec;
2021-10-25 20:18:02 +00:00
};
#endif // ESCC_H