1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-27 15:29:34 +00:00

Attempts GLU register latching, restoring expected startup sequence.

This commit is contained in:
Thomas Harte 2021-02-13 17:38:42 -05:00
parent 2c4dcf8843
commit 2ab3bba695
4 changed files with 58 additions and 23 deletions

View File

@ -13,6 +13,7 @@
#include <bitset> #include <bitset>
#include <cstddef> #include <cstddef>
#include <ostream>
#include <vector> #include <vector>
namespace Apple { namespace Apple {
@ -38,6 +39,26 @@ struct Command {
Command(Type type, uint8_t device, uint8_t reg) : type(type), device(device), reg(reg) {} Command(Type type, uint8_t device, uint8_t reg) : type(type), device(device), reg(reg) {}
}; };
inline std::ostream &operator <<(std::ostream &stream, Command::Type type) {
switch(type) {
case Command::Type::Reset: stream << "reset"; break;
case Command::Type::Flush: stream << "flush"; break;
case Command::Type::Listen: stream << "listen"; break;
case Command::Type::Talk: stream << "talk"; break;
default: stream << "reserved"; break;
}
return stream;
}
inline std::ostream &operator <<(std::ostream &stream, Command command) {
stream << "Command {";
if(command.device != 0xff) stream << "device " << int(command.device) << ", ";
if(command.reg != 0xff) stream << "register " << int(command.reg) << ", ";
stream << command.type;
stream << "}";
return stream;
}
/*! /*!
@returns The @c Command encoded in @c code. @returns The @c Command encoded in @c code.
*/ */

View File

@ -8,6 +8,9 @@
#include "Mouse.hpp" #include "Mouse.hpp"
#define LOG_PREFIX "[Mouse] "
#include "../../../Outputs/Log.hpp"
using namespace Apple::ADB; using namespace Apple::ADB;
Mouse::Mouse(Bus &bus) : ReactiveDevice(bus) {} Mouse::Mouse(Bus &bus) : ReactiveDevice(bus) {}
@ -21,6 +24,7 @@ void Mouse::adb_bus_did_observe_event(Bus::Event event, uint8_t value) {
next_is_command_ = false; next_is_command_ = false;
const auto command = decode_command(value); const auto command = decode_command(value);
LOG(command);
if(command.device != 3) { if(command.device != 3) {
return; return;
} }

View File

@ -149,25 +149,46 @@ void GLU::run_for(Cycles cycles) {
void GLU::set_port_output(int port, uint8_t value) { void GLU::set_port_output(int port, uint8_t value) {
switch(port) { switch(port) {
case 0: case 0:
// printf(" {R%d} ", register_address_); register_latch_ = value;
// printf("Set R%d: %02x\n", register_address_, value);
registers_[register_address_] = value;
switch(register_address_) {
default: break;
case 7: status_ |= uint8_t(CPUFlags::CommandDataIsValid); break;
}
break; break;
case 1: case 1:
// printf("Keyboard write: %02x???\n", value); // printf("Keyboard write: %02x???\n", value);
break; break;
case 2: case 2: {
// printf("ADB data line input: %d???\n", value >> 7); // printf("ADB data line input: %d???\n", value >> 7);
// printf("IIe keyboard reset line: %d\n", (value >> 6)&1); // printf("IIe keyboard reset line: %d\n", (value >> 6)&1);
// printf("IIgs reset line: %d\n", (value >> 5)&1); // printf("IIgs reset line: %d\n", (value >> 5)&1);
// printf("GLU strobe: %d\n", (value >> 4)&1); // printf("GLU strobe: %d\n", (value >> 4)&1);
// printf("Select GLU register: %d [%02x]\n", value & 0xf, value); // printf("Select GLU register: %d [%02x]\n", value & 0xf, value);
register_address_ = value & 0xf; register_address_ = value & 0xf;
// Check the strobe; I think:
//
// high -> low, read => fill latch from register;
// low -> high => fill register from latch.
const bool strobe = value & 0x10;
if(strobe != register_strobe_) {
register_strobe_ = strobe;
if(register_strobe_) {
registers_[register_address_] = register_latch_;
switch(register_address_) {
default: break;
case 7: status_ |= uint8_t(CPUFlags::CommandDataIsValid); break;
}
} else {
register_latch_ = registers_[register_address_];
switch(register_address_) {
default: break;
case 1:
registers_[4] &= ~uint8_t(MicrocontrollerFlags::CommandRegisterFull);
status_ &= ~uint8_t(CPUFlags::CommandRegisterFull);
break; break;
}
}
}
} break;
case 3: case 3:
// printf("IIe KWS: %d\n", (value >> 6)&3); // printf("IIe KWS: %d\n", (value >> 6)&3);
// printf("ADB data line output: %d\n", (value >> 3)&1); // printf("ADB data line output: %d\n", (value >> 3)&1);
@ -183,20 +204,7 @@ void GLU::set_port_output(int port, uint8_t value) {
uint8_t GLU::get_port_input(int port) { uint8_t GLU::get_port_input(int port) {
switch(port) { switch(port) {
case 0: case 0: return register_latch_;
// printf(" {R%d} ", register_address_);
switch(register_address_) {
default: break;
case 1:
registers_[4] &= ~uint8_t(MicrocontrollerFlags::CommandRegisterFull);
status_ &= ~uint8_t(CPUFlags::CommandRegisterFull);
break;
}
if(register_address_ == 1) {
printf("[C %02x]", registers_[1]);
}
return registers_[register_address_];
case 1: case 1:
// printf("IIe keyboard read\n"); // printf("IIe keyboard read\n");
return 0x06; return 0x06;

View File

@ -48,8 +48,10 @@ class GLU: public InstructionSet::M50740::PortHandler {
uint8_t get_port_input(int port) override; uint8_t get_port_input(int port) override;
uint8_t registers_[16]; uint8_t registers_[16];
uint8_t register_address_; uint8_t register_address_;
uint8_t register_latch_ = 0xff; uint8_t register_latch_ = 0xff;
bool register_strobe_ = false;
uint8_t status_ = 0x00; uint8_t status_ = 0x00;