2021-10-25 20:18:02 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2024-04-26 07:44:43 +00:00
|
|
|
Copyright (C) 2018-24 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) emulation. */
|
|
|
|
|
2024-03-20 17:39:43 +00:00
|
|
|
#include <core/timermanager.h>
|
2022-07-11 23:01:43 +00:00
|
|
|
#include <devices/deviceregistry.h>
|
2022-05-07 19:38:27 +00:00
|
|
|
#include <devices/serial/chario.h>
|
|
|
|
#include <devices/serial/escc.h>
|
2024-04-26 23:55:37 +00:00
|
|
|
#include <devices/serial/z85c30.h>
|
2021-10-25 20:18:02 +00:00
|
|
|
#include <loguru.hpp>
|
2022-05-07 19:38:27 +00:00
|
|
|
#include <machines/machineproperties.h>
|
2021-10-25 20:18:02 +00:00
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <memory>
|
2022-05-07 19:38:27 +00:00
|
|
|
#include <string>
|
2022-07-11 23:01:43 +00:00
|
|
|
#include <vector>
|
2021-10-25 20:18:02 +00:00
|
|
|
|
2022-05-02 22:16:09 +00:00
|
|
|
/** Remap the compatible addressing scheme to MacRISC one. */
|
|
|
|
const uint8_t compat_to_macrisc[6] = {
|
|
|
|
EsccReg::Port_B_Cmd, EsccReg::Port_A_Cmd,
|
|
|
|
EsccReg::Port_B_Data, EsccReg::Port_A_Data,
|
|
|
|
EsccReg::Enh_Reg_B, EsccReg::Enh_Reg_A
|
|
|
|
};
|
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
EsccController::EsccController()
|
|
|
|
{
|
2022-05-07 19:38:27 +00:00
|
|
|
// allocate channels
|
2024-01-27 23:13:58 +00:00
|
|
|
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("ESCC_A"));
|
|
|
|
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("ESCC_B"));
|
2021-10-25 20:18:02 +00:00
|
|
|
|
2022-05-07 19:38:27 +00:00
|
|
|
// attach backends
|
|
|
|
std::string backend_name = GET_STR_PROP("serial_backend");
|
|
|
|
|
|
|
|
this->ch_a->attach_backend(
|
Add socket type for serial_backend
With the option --serial_backend=socket, input and output to a serial port will use a SOCK_STREAM type UNIX domain socket. This allows you to do Open Firmware in one window, while the first window can be used for dingusppc debugger.
Other fixes:
- Added SIGTERM handler so that if the user force quits dingusppc, the terminal settings are properly restored. A user needs to force quit when --serial_backend=stdio and Open Firmware is taking input from ttya. If terminal settings are not restored, then running dingusppc after a force quit will cause Control-C to not work when --serial_backend is not stdio.
- Added a couple numbers to rcv_char_available - 15 is the number of consecutive characters that can processed. 400 is the total number of calls to rcv_char_available after 15 consecutive characters have been read before additional characters can be read. This delay in processing additional characters allows pasting arbitrarily large amounts of text into Open Firmware. A real serial port terminal app might have a text pacing option to limit the number of output characters per second but that is not an option since the emulator is not limiting character data to a baud rate.
Related Notes:
The socket file is created when dingusppc starts.
The socket file is named dingusppcsocket and is created in the current working directory (usually where the executable is located and where the dingusppc.log, nvram.bin, and pram.bin files are created).
The socket file is not visible in the Finder. You can see it in the terminal using the ls command.
The socket file can be used with the following command in a new terminal window:
socat UNIX-CLIENT:dingussocket -,cs8,parenb=0,echo=0,icanon=0,isig=0,icrnl=0
When dingusppc quits, the socat command ends.
Other notes:
The dingusppc --debugger option causes dingusppc to enter the debugger before Open Firmware outputs anything. You can connect to the socket while dingusppc is in the debugger. Then enter the go command to leave the debugger and start Open Firmware. However, since the startup sound takes a long time, you can probably connect to the socket before Open Firmware starts even without the --debugger option. It's like with a real Power Mac - you have a few seconds to hold Command-Option-O-F except in this case you have a few seconds to press the up arrow and press enter (for executing the last command from the terminal command history) and if you do it too late you'll still get into Open Firmware if auto-boot? was previously set to false using the dingusppc debugger which is actually the only way to get into Open Firmware since a keyboard is currently not emulated?).
To set ttya as the input and output device in Open Firmware, you can use the setenv command in the dingusppc debugger. The device path needs to be longer than the current device path (because code for handling shortening of the paths is currently not implemented). For example, ttya can replace kbd for the input-device, but to replace screen for the output-device you need to add some extra characters like this: ttya,11 (I think the number is for baud but we're not using a real serial port so baud doesn't matter).
Future ideas:
- Have dingusppc execute the socat command for you so that it opens a terminal window before Open Firmware starts.
- Add another --serial_backend for the printer port (ttyb) since now we have more than one type of serial backend. If both serial ports use socket backend, then a different name for the second socket is required.
- Have an option to make dingusppc block until something connects to the socket (this means calling accept after listen instead of after select).
- Test compatibility with serial port socket created by Parallels Desktop virtual machines in macOS.
- Find a solution that works with Windows.
- Test with Linux.
- Create a serial_backend type for tty devices. I suppose maybe socat can pipe the file socket to tty but a direct connection might be easier to setup.
- Allow using a socket created by some other app (for example, socat UNIX-LISTEN). This means dingusppc will assume the client role and will call connect instead of accept.
2022-08-14 13:48:16 +00:00
|
|
|
(backend_name == "stdio") ? CHARIO_BE_STDIO :
|
|
|
|
#ifdef _WIN32
|
|
|
|
#else
|
|
|
|
(backend_name == "socket") ? CHARIO_BE_SOCKET :
|
|
|
|
#endif
|
|
|
|
CHARIO_BE_NULL
|
|
|
|
);
|
2022-05-07 19:38:27 +00:00
|
|
|
this->ch_b->attach_backend(CHARIO_BE_NULL);
|
|
|
|
|
2024-04-27 01:12:06 +00:00
|
|
|
this->master_int_cntrl = 0;
|
|
|
|
this->reset();
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 21:23:02 +00:00
|
|
|
void EsccController::reset()
|
|
|
|
{
|
2024-04-27 03:14:19 +00:00
|
|
|
this->master_int_cntrl &= (WR9_NO_VECTOR | WR9_VECTOR_INCLUDES_STATUS);
|
2024-04-26 23:55:37 +00:00
|
|
|
this->master_int_cntrl |= WR9_FORCE_HARDWARE_RESET;
|
2024-04-27 01:12:06 +00:00
|
|
|
this->reg_ptr = WR0; // or RR0
|
2022-02-23 21:23:02 +00:00
|
|
|
|
|
|
|
this->ch_a->reset(true);
|
|
|
|
this->ch_b->reset(true);
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
uint8_t EsccController::read(uint8_t reg_offset)
|
|
|
|
{
|
2024-04-20 10:52:04 +00:00
|
|
|
uint8_t value;
|
2022-02-26 09:55:30 +00:00
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
switch(reg_offset) {
|
|
|
|
case EsccReg::Port_B_Cmd:
|
2024-04-27 01:28:40 +00:00
|
|
|
value = this->read_internal(this->ch_b.get());
|
2021-10-25 20:18:02 +00:00
|
|
|
break;
|
|
|
|
case EsccReg::Port_A_Cmd:
|
2024-04-27 01:28:40 +00:00
|
|
|
value = this->read_internal(this->ch_a.get());
|
2021-10-25 20:18:02 +00:00
|
|
|
break;
|
2022-02-26 09:55:30 +00:00
|
|
|
case EsccReg::Port_B_Data:
|
2024-04-20 10:52:04 +00:00
|
|
|
value = this->ch_b->receive_byte();
|
|
|
|
break;
|
2022-02-26 09:55:30 +00:00
|
|
|
case EsccReg::Port_A_Data:
|
2024-04-20 10:52:04 +00:00
|
|
|
value = this->ch_a->receive_byte();
|
|
|
|
break;
|
|
|
|
case EsccReg::Enh_Reg_B:
|
2024-04-26 07:44:43 +00:00
|
|
|
value = this->ch_b->get_enh_reg();
|
2024-04-20 10:52:04 +00:00
|
|
|
break;
|
|
|
|
case EsccReg::Enh_Reg_A:
|
2024-04-26 07:44:43 +00:00
|
|
|
value = this->ch_a->get_enh_reg();
|
2024-04-20 10:52:04 +00:00
|
|
|
break;
|
2021-10-25 20:18:02 +00:00
|
|
|
default:
|
2024-04-20 10:52:04 +00:00
|
|
|
LOG_F(WARNING, "ESCC: reading from unimplemented register 0x%x", reg_offset);
|
|
|
|
value = 0;
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
2024-04-20 10:52:04 +00:00
|
|
|
return value;
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EsccController::write(uint8_t reg_offset, uint8_t value)
|
|
|
|
{
|
|
|
|
switch(reg_offset) {
|
|
|
|
case EsccReg::Port_B_Cmd:
|
|
|
|
this->write_internal(this->ch_b.get(), value);
|
|
|
|
break;
|
|
|
|
case EsccReg::Port_A_Cmd:
|
|
|
|
this->write_internal(this->ch_a.get(), value);
|
|
|
|
break;
|
2022-02-26 09:55:30 +00:00
|
|
|
case EsccReg::Port_B_Data:
|
|
|
|
this->ch_b->send_byte(value);
|
|
|
|
break;
|
|
|
|
case EsccReg::Port_A_Data:
|
|
|
|
this->ch_a->send_byte(value);
|
|
|
|
break;
|
2024-04-26 07:44:43 +00:00
|
|
|
case EsccReg::Enh_Reg_B:
|
|
|
|
this->ch_b->set_enh_reg(value);
|
|
|
|
break;
|
|
|
|
case EsccReg::Enh_Reg_A:
|
|
|
|
this->ch_a->set_enh_reg(value);
|
|
|
|
break;
|
2021-10-25 20:18:02 +00:00
|
|
|
default:
|
2022-08-22 10:09:52 +00:00
|
|
|
LOG_F(9, "ESCC: writing 0x%X to unimplemented register 0x%x", value, reg_offset);
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 01:28:40 +00:00
|
|
|
uint8_t EsccController::read_internal(EsccChannel *ch)
|
|
|
|
{
|
|
|
|
uint8_t value;
|
|
|
|
switch (this->reg_ptr) {
|
|
|
|
case RR2:
|
|
|
|
// TODO: implement interrupt vector modifications
|
|
|
|
value = this->int_vec;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = ch->read_reg(this->reg_ptr);
|
|
|
|
}
|
|
|
|
this->reg_ptr = RR0; // or WR0
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
|
|
|
{
|
2024-04-26 23:55:37 +00:00
|
|
|
switch (this->reg_ptr) {
|
|
|
|
// chip-specific registers
|
|
|
|
case WR0:
|
|
|
|
this->reg_ptr = value & WR0_REGISTER_SELECTION_CODE;
|
|
|
|
switch (value & WR0_COMMAND_CODES) {
|
|
|
|
case WR0_COMMAND_POINT_HIGH:
|
|
|
|
this->reg_ptr |= WR8; // or RR8
|
|
|
|
break;
|
2022-02-23 21:23:02 +00:00
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
return;
|
|
|
|
case WR2:
|
|
|
|
this->int_vec = value;
|
|
|
|
break;
|
|
|
|
case WR9:
|
|
|
|
// see if some reset is requested
|
|
|
|
switch (value & WR9_RESET_COMMAND_BITS) {
|
|
|
|
case WR9_CHANNEL_RESET_B:
|
|
|
|
this->master_int_cntrl &= ~WR9_INTERRUPT_MASKING_WITHOUT_INTACK;
|
|
|
|
this->ch_b->reset(false);
|
|
|
|
break;
|
|
|
|
case WR9_CHANNEL_RESET_A:
|
|
|
|
this->master_int_cntrl &= ~WR9_INTERRUPT_MASKING_WITHOUT_INTACK;
|
|
|
|
this->ch_a->reset(false);
|
|
|
|
break;
|
|
|
|
case WR9_FORCE_HARDWARE_RESET:
|
|
|
|
this->reset();
|
2021-10-25 20:18:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
|
|
|
|
this->master_int_cntrl = value & WR9_INTERRUPT_CONTROL_BITS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// channel-specific registers
|
|
|
|
ch->write_reg(this->reg_ptr, value);
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
this->reg_ptr = WR0; // or RR0
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 21:23:02 +00:00
|
|
|
// ======================== ESCC Channel methods ==============================
|
2022-05-07 19:38:27 +00:00
|
|
|
void EsccChannel::attach_backend(int id)
|
|
|
|
{
|
|
|
|
switch(id) {
|
|
|
|
case CHARIO_BE_NULL:
|
|
|
|
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
|
|
|
break;
|
|
|
|
case CHARIO_BE_STDIO:
|
|
|
|
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoStdin);
|
|
|
|
break;
|
Add socket type for serial_backend
With the option --serial_backend=socket, input and output to a serial port will use a SOCK_STREAM type UNIX domain socket. This allows you to do Open Firmware in one window, while the first window can be used for dingusppc debugger.
Other fixes:
- Added SIGTERM handler so that if the user force quits dingusppc, the terminal settings are properly restored. A user needs to force quit when --serial_backend=stdio and Open Firmware is taking input from ttya. If terminal settings are not restored, then running dingusppc after a force quit will cause Control-C to not work when --serial_backend is not stdio.
- Added a couple numbers to rcv_char_available - 15 is the number of consecutive characters that can processed. 400 is the total number of calls to rcv_char_available after 15 consecutive characters have been read before additional characters can be read. This delay in processing additional characters allows pasting arbitrarily large amounts of text into Open Firmware. A real serial port terminal app might have a text pacing option to limit the number of output characters per second but that is not an option since the emulator is not limiting character data to a baud rate.
Related Notes:
The socket file is created when dingusppc starts.
The socket file is named dingusppcsocket and is created in the current working directory (usually where the executable is located and where the dingusppc.log, nvram.bin, and pram.bin files are created).
The socket file is not visible in the Finder. You can see it in the terminal using the ls command.
The socket file can be used with the following command in a new terminal window:
socat UNIX-CLIENT:dingussocket -,cs8,parenb=0,echo=0,icanon=0,isig=0,icrnl=0
When dingusppc quits, the socat command ends.
Other notes:
The dingusppc --debugger option causes dingusppc to enter the debugger before Open Firmware outputs anything. You can connect to the socket while dingusppc is in the debugger. Then enter the go command to leave the debugger and start Open Firmware. However, since the startup sound takes a long time, you can probably connect to the socket before Open Firmware starts even without the --debugger option. It's like with a real Power Mac - you have a few seconds to hold Command-Option-O-F except in this case you have a few seconds to press the up arrow and press enter (for executing the last command from the terminal command history) and if you do it too late you'll still get into Open Firmware if auto-boot? was previously set to false using the dingusppc debugger which is actually the only way to get into Open Firmware since a keyboard is currently not emulated?).
To set ttya as the input and output device in Open Firmware, you can use the setenv command in the dingusppc debugger. The device path needs to be longer than the current device path (because code for handling shortening of the paths is currently not implemented). For example, ttya can replace kbd for the input-device, but to replace screen for the output-device you need to add some extra characters like this: ttya,11 (I think the number is for baud but we're not using a real serial port so baud doesn't matter).
Future ideas:
- Have dingusppc execute the socat command for you so that it opens a terminal window before Open Firmware starts.
- Add another --serial_backend for the printer port (ttyb) since now we have more than one type of serial backend. If both serial ports use socket backend, then a different name for the second socket is required.
- Have an option to make dingusppc block until something connects to the socket (this means calling accept after listen instead of after select).
- Test compatibility with serial port socket created by Parallels Desktop virtual machines in macOS.
- Find a solution that works with Windows.
- Test with Linux.
- Create a serial_backend type for tty devices. I suppose maybe socat can pipe the file socket to tty but a direct connection might be easier to setup.
- Allow using a socket created by some other app (for example, socat UNIX-LISTEN). This means dingusppc will assume the client role and will call connect instead of accept.
2022-08-14 13:48:16 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#else
|
|
|
|
case CHARIO_BE_SOCKET:
|
|
|
|
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoSocket);
|
|
|
|
break;
|
|
|
|
#endif
|
2022-05-07 19:38:27 +00:00
|
|
|
default:
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(ERROR, "%s: unknown backend ID %d, using NULL instead", this->name.c_str(), id);
|
2022-05-07 19:38:27 +00:00
|
|
|
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
|
|
|
}
|
|
|
|
}
|
2022-02-23 21:23:02 +00:00
|
|
|
|
|
|
|
void EsccChannel::reset(bool hw_reset)
|
|
|
|
{
|
2022-05-07 19:38:27 +00:00
|
|
|
this->chario->rcv_disable();
|
|
|
|
|
2024-04-26 23:55:37 +00:00
|
|
|
/*
|
|
|
|
We use hex values here instead of enums to more
|
|
|
|
easily compare with the z85c30 data sheet.
|
|
|
|
*/
|
2024-04-27 01:12:06 +00:00
|
|
|
|
|
|
|
this->write_regs[WR0] = 0;
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR1] &= 0x24;
|
|
|
|
this->write_regs[WR3] &= 0xFE;
|
|
|
|
this->write_regs[WR4] |= 0x04;
|
|
|
|
this->write_regs[WR5] &= 0x61;
|
|
|
|
this->write_regs[WR15] = 0xF8;
|
|
|
|
|
|
|
|
this->read_regs[RR0] &= 0x38;
|
|
|
|
this->read_regs[RR0] |= 0x44;
|
2024-04-27 01:32:17 +00:00
|
|
|
this->read_regs[RR1] = 0x06 | RR1_ALL_SENT; // HACK: also set ALL_SENT flag.
|
2024-04-26 23:55:37 +00:00
|
|
|
this->read_regs[RR3] = 0x00;
|
|
|
|
this->read_regs[RR10] = 0x00;
|
2022-02-23 21:23:02 +00:00
|
|
|
|
2022-02-26 09:55:30 +00:00
|
|
|
// initialize DPLL
|
|
|
|
this->dpll_active = 0;
|
|
|
|
this->dpll_mode = DpllMode::NRZI;
|
|
|
|
this->dpll_clock_src = 0;
|
|
|
|
|
|
|
|
// initialize Baud Rate Generator (BRG)
|
|
|
|
this->brg_active = 0;
|
|
|
|
this->brg_clock_src = 0;
|
|
|
|
|
2022-02-23 21:23:02 +00:00
|
|
|
if (hw_reset) {
|
2024-04-27 03:14:19 +00:00
|
|
|
this->write_regs[WR9] &= 0x03; // clear all except (WR9_NO_VECTOR | WR9_VECTOR_INCLUDES_STATUS)
|
|
|
|
this->write_regs[WR9] |= 0xC0; // set WR9_FORCE_HARDWARE_RESET
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR10] = 0;
|
|
|
|
this->write_regs[WR11] = 8;
|
|
|
|
this->write_regs[WR14] &= 0xC0;
|
2022-02-23 21:23:02 +00:00
|
|
|
} else {
|
2024-04-27 03:14:19 +00:00
|
|
|
this->write_regs[WR9] &= ~0x20; // clear WR9_INTERRUPT_MASKING_WITHOUT_INTACK
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR10] &= 0x60;
|
|
|
|
this->write_regs[WR14] &= 0xC3;
|
2022-02-23 21:23:02 +00:00
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR14] |= 0x20;
|
2022-02-23 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
|
|
|
{
|
2022-02-26 09:55:30 +00:00
|
|
|
switch (reg_num) {
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR3:
|
|
|
|
if ((this->write_regs[WR3] ^ value) & WR3_ENTER_HUNT_MODE) {
|
|
|
|
this->write_regs[WR3] |= WR3_ENTER_HUNT_MODE;
|
|
|
|
this->read_regs[RR0] |= RR0_SYNC_HUNT;
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(9, "%s: Hunt mode entered.", this->name.c_str());
|
2022-05-07 19:38:27 +00:00
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
if ((this->write_regs[WR3] ^ value) & WR3_RX_ENABLE) {
|
|
|
|
if (value & WR3_RX_ENABLE) {
|
|
|
|
this->write_regs[WR3] |= WR3_RX_ENABLE;
|
2022-05-07 19:38:27 +00:00
|
|
|
this->chario->rcv_enable();
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(9, "%s: receiver enabled.", this->name.c_str());
|
2022-05-07 19:38:27 +00:00
|
|
|
} else {
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR3] ^= WR3_RX_ENABLE;
|
2022-05-07 19:38:27 +00:00
|
|
|
this->chario->rcv_disable();
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(9, "%s: receiver disabled.", this->name.c_str());
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR3] |= WR3_ENTER_HUNT_MODE;
|
|
|
|
this->read_regs[RR0] |= RR0_SYNC_HUNT;
|
2022-02-26 09:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
this->write_regs[WR3] = (this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) | (value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
|
2022-02-26 09:55:30 +00:00
|
|
|
return;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR7:
|
|
|
|
if (this->write_regs[WR15] & WR15_SDLC_HDLC_ENHANCEMENT_ENABLE) {
|
2022-02-26 09:55:30 +00:00
|
|
|
this->wr7_enh = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2024-04-27 03:26:47 +00:00
|
|
|
case WR8:
|
|
|
|
this->send_byte(value);
|
|
|
|
return;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14:
|
|
|
|
switch (value & WR14_DPLL_COMMAND_BITS) {
|
|
|
|
case WR14_DPLL_NULL_COMMAND:
|
2022-05-07 19:38:27 +00:00
|
|
|
break;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_ENTER_SEARCH_MODE:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_active = 1;
|
2024-04-26 23:55:37 +00:00
|
|
|
this->read_regs[RR10] &= ~(RR10_TWO_CLOCKS_MISSING | RR10_ONE_CLOCK_MISSING);
|
2022-02-26 09:55:30 +00:00
|
|
|
break;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_RESET_MISSING_CLOCK:
|
|
|
|
this->read_regs[RR10] &= ~(RR10_TWO_CLOCKS_MISSING | RR10_ONE_CLOCK_MISSING);
|
|
|
|
break;
|
|
|
|
case WR14_DPLL_DISABLE_DPLL:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_active = 0;
|
|
|
|
// fallthrough
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_SET_SOURCE_BR_GENERATOR:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_clock_src = 0;
|
|
|
|
break;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_SET_SOURCE_RTXC:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_clock_src = 1;
|
|
|
|
break;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_SET_FM_MODE:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_mode = DpllMode::FM;
|
|
|
|
break;
|
2024-04-26 23:55:37 +00:00
|
|
|
case WR14_DPLL_SET_NRZI_MODE:
|
2022-02-26 09:55:30 +00:00
|
|
|
this->dpll_mode = DpllMode::NRZI;
|
|
|
|
break;
|
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
if (value & (WR14_LOCAL_LOOPBACK | WR14_AUTO_ECHO | WR14_DTR_REQUEST_FUNCTION)) {
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(WARNING, "%s: unexpected value in WR14 = 0x%X", this->name.c_str(), value);
|
2022-02-26 09:55:30 +00:00
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
if (this->brg_active ^ (value & WR14_BR_GENERATOR_ENABLE)) {
|
|
|
|
this->brg_active = value & WR14_BR_GENERATOR_ENABLE;
|
2024-01-27 23:13:58 +00:00
|
|
|
LOG_F(9, "%s: BRG %s", this->name.c_str(), this->brg_active ? "enabled" : "disabled");
|
2022-02-26 09:55:30 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:18:02 +00:00
|
|
|
this->write_regs[reg_num] = value;
|
2022-02-26 09:55:30 +00:00
|
|
|
}
|
2022-02-23 21:23:02 +00:00
|
|
|
|
2022-02-26 09:55:30 +00:00
|
|
|
uint8_t EsccChannel::read_reg(int reg_num)
|
|
|
|
{
|
2024-04-26 23:55:37 +00:00
|
|
|
switch (reg_num) {
|
|
|
|
case RR0:
|
2022-05-07 19:38:27 +00:00
|
|
|
if (this->chario->rcv_char_available()) {
|
2024-04-26 23:55:37 +00:00
|
|
|
this->read_regs[RR0] |= RR0_RX_CHARACTER_AVAILABLE;
|
2022-05-07 19:38:27 +00:00
|
|
|
}
|
2024-04-27 03:26:47 +00:00
|
|
|
break;
|
|
|
|
case RR8:
|
|
|
|
return this->receive_byte();
|
2022-05-07 19:38:27 +00:00
|
|
|
}
|
2022-02-26 09:55:30 +00:00
|
|
|
return this->read_regs[reg_num];
|
|
|
|
}
|
2022-02-23 21:23:02 +00:00
|
|
|
|
2022-02-26 09:55:30 +00:00
|
|
|
void EsccChannel::send_byte(uint8_t value)
|
|
|
|
{
|
2022-05-07 19:38:27 +00:00
|
|
|
// TODO: put one byte into the Data FIFO
|
|
|
|
|
2024-04-27 03:26:47 +00:00
|
|
|
this->write_regs[WR8] = value;
|
2022-05-07 19:38:27 +00:00
|
|
|
this->chario->xmit_char(value);
|
2022-02-23 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 09:55:30 +00:00
|
|
|
uint8_t EsccChannel::receive_byte()
|
2022-02-23 21:23:02 +00:00
|
|
|
{
|
2022-05-07 19:38:27 +00:00
|
|
|
// TODO: remove one byte from the Receive FIFO
|
|
|
|
|
|
|
|
uint8_t c;
|
|
|
|
|
2024-01-27 23:19:45 +00:00
|
|
|
if (this->chario->rcv_char_available_now()) {
|
|
|
|
this->chario->rcv_char(&c);
|
|
|
|
} else {
|
|
|
|
c = 0;
|
|
|
|
}
|
2024-04-26 23:55:37 +00:00
|
|
|
this->read_regs[RR0] &= ~RR0_RX_CHARACTER_AVAILABLE;
|
2024-04-27 03:26:47 +00:00
|
|
|
this->read_regs[RR8] = c;
|
2022-05-07 19:38:27 +00:00
|
|
|
return c;
|
2021-10-25 20:18:02 +00:00
|
|
|
}
|
2022-07-11 23:01:43 +00:00
|
|
|
|
2024-04-26 07:44:43 +00:00
|
|
|
uint8_t EsccChannel::get_enh_reg()
|
|
|
|
{
|
|
|
|
return this->enh_reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::set_enh_reg(uint8_t value)
|
|
|
|
{
|
|
|
|
uint8_t changed_bits = value ^ this->enh_reg;
|
|
|
|
if (changed_bits & 0x10) {
|
|
|
|
if (value & 0x10)
|
|
|
|
LOG_F(ERROR, "%s: CTS connected to GPIO; DCD connected to GND", this->name.c_str());
|
|
|
|
else
|
|
|
|
LOG_F(INFO, "%s: CTS connected to TRXC_In_l; DCD connected to GPIO", this->name.c_str());
|
|
|
|
this->enh_reg = value & 0x10;
|
|
|
|
} else if (changed_bits & ~0x10) {
|
|
|
|
if (value & ~0x10)
|
|
|
|
LOG_F(ERROR, "%s: Ignoring attempt to set Enh_Reg bits 0x%02x", this->name.c_str(), value & ~0x10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 17:39:43 +00:00
|
|
|
void EsccChannel::dma_start_tx()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_start_rx()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_stop_tx()
|
|
|
|
{
|
|
|
|
if (this->timer_id_tx) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->timer_id_tx);
|
|
|
|
this->timer_id_tx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_stop_rx()
|
|
|
|
{
|
|
|
|
if (this->timer_id_rx) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->timer_id_rx);
|
|
|
|
this->timer_id_rx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_in_tx()
|
|
|
|
{
|
|
|
|
LOG_F(ERROR, "%s: Unexpected DMA INPUT command for transmit.", this->name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_in_rx()
|
|
|
|
{
|
|
|
|
if (dma_ch[1]->get_push_data_remaining()) {
|
|
|
|
this->timer_id_rx = TimerManager::get_instance()->add_oneshot_timer(
|
|
|
|
0,
|
|
|
|
[this]() {
|
|
|
|
this->timer_id_rx = 0;
|
|
|
|
char c = receive_byte();
|
|
|
|
int xx = dma_ch[1]->push_data(&c, 1);
|
|
|
|
this->dma_in_rx();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_out_tx()
|
|
|
|
{
|
|
|
|
this->timer_id_tx = TimerManager::get_instance()->add_oneshot_timer(
|
|
|
|
10,
|
|
|
|
[this]() {
|
|
|
|
this->timer_id_tx = 0;
|
|
|
|
uint8_t *data;
|
|
|
|
uint32_t avail_len;
|
|
|
|
|
|
|
|
if (dma_ch[1]->pull_data(256, &avail_len, &data) == MoreData) {
|
|
|
|
while(avail_len) {
|
|
|
|
this->send_byte(*data++);
|
|
|
|
avail_len--;
|
|
|
|
}
|
|
|
|
this->dma_out_tx();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_out_rx()
|
|
|
|
{
|
|
|
|
LOG_F(ERROR, "%s: Unexpected DMA OUTPUT command for receive.", this->name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_flush_tx()
|
|
|
|
{
|
|
|
|
this->dma_stop_tx();
|
|
|
|
this->timer_id_tx = TimerManager::get_instance()->add_oneshot_timer(
|
|
|
|
10,
|
|
|
|
[this]() {
|
|
|
|
this->timer_id_tx = 0;
|
|
|
|
dma_ch[1]->end_pull_data();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EsccChannel::dma_flush_rx()
|
|
|
|
{
|
|
|
|
this->dma_stop_rx();
|
|
|
|
this->timer_id_rx = TimerManager::get_instance()->add_oneshot_timer(
|
|
|
|
10,
|
|
|
|
[this]() {
|
|
|
|
this->timer_id_rx = 0;
|
|
|
|
dma_ch[1]->end_push_data();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Add socket type for serial_backend
With the option --serial_backend=socket, input and output to a serial port will use a SOCK_STREAM type UNIX domain socket. This allows you to do Open Firmware in one window, while the first window can be used for dingusppc debugger.
Other fixes:
- Added SIGTERM handler so that if the user force quits dingusppc, the terminal settings are properly restored. A user needs to force quit when --serial_backend=stdio and Open Firmware is taking input from ttya. If terminal settings are not restored, then running dingusppc after a force quit will cause Control-C to not work when --serial_backend is not stdio.
- Added a couple numbers to rcv_char_available - 15 is the number of consecutive characters that can processed. 400 is the total number of calls to rcv_char_available after 15 consecutive characters have been read before additional characters can be read. This delay in processing additional characters allows pasting arbitrarily large amounts of text into Open Firmware. A real serial port terminal app might have a text pacing option to limit the number of output characters per second but that is not an option since the emulator is not limiting character data to a baud rate.
Related Notes:
The socket file is created when dingusppc starts.
The socket file is named dingusppcsocket and is created in the current working directory (usually where the executable is located and where the dingusppc.log, nvram.bin, and pram.bin files are created).
The socket file is not visible in the Finder. You can see it in the terminal using the ls command.
The socket file can be used with the following command in a new terminal window:
socat UNIX-CLIENT:dingussocket -,cs8,parenb=0,echo=0,icanon=0,isig=0,icrnl=0
When dingusppc quits, the socat command ends.
Other notes:
The dingusppc --debugger option causes dingusppc to enter the debugger before Open Firmware outputs anything. You can connect to the socket while dingusppc is in the debugger. Then enter the go command to leave the debugger and start Open Firmware. However, since the startup sound takes a long time, you can probably connect to the socket before Open Firmware starts even without the --debugger option. It's like with a real Power Mac - you have a few seconds to hold Command-Option-O-F except in this case you have a few seconds to press the up arrow and press enter (for executing the last command from the terminal command history) and if you do it too late you'll still get into Open Firmware if auto-boot? was previously set to false using the dingusppc debugger which is actually the only way to get into Open Firmware since a keyboard is currently not emulated?).
To set ttya as the input and output device in Open Firmware, you can use the setenv command in the dingusppc debugger. The device path needs to be longer than the current device path (because code for handling shortening of the paths is currently not implemented). For example, ttya can replace kbd for the input-device, but to replace screen for the output-device you need to add some extra characters like this: ttya,11 (I think the number is for baud but we're not using a real serial port so baud doesn't matter).
Future ideas:
- Have dingusppc execute the socat command for you so that it opens a terminal window before Open Firmware starts.
- Add another --serial_backend for the printer port (ttyb) since now we have more than one type of serial backend. If both serial ports use socket backend, then a different name for the second socket is required.
- Have an option to make dingusppc block until something connects to the socket (this means calling accept after listen instead of after select).
- Test compatibility with serial port socket created by Parallels Desktop virtual machines in macOS.
- Find a solution that works with Windows.
- Test with Linux.
- Create a serial_backend type for tty devices. I suppose maybe socat can pipe the file socket to tty but a direct connection might be easier to setup.
- Allow using a socket created by some other app (for example, socat UNIX-LISTEN). This means dingusppc will assume the client role and will call connect instead of accept.
2022-08-14 13:48:16 +00:00
|
|
|
static const vector<string> CharIoBackends = {"null", "stdio", "socket"};
|
2022-07-11 23:01:43 +00:00
|
|
|
|
|
|
|
static const PropMap Escc_Properties = {
|
|
|
|
{"serial_backend", new StrProperty("null", CharIoBackends)},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const DeviceDescription Escc_Descriptor = {
|
|
|
|
EsccController::create, {}, Escc_Properties
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_DEVICE(Escc, Escc_Descriptor);
|