1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-27 00:30:26 +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 <cstddef>
#include <ostream>
#include <vector>
namespace Apple {
@ -38,6 +39,26 @@ struct Command {
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.
*/

View File

@ -8,6 +8,9 @@
#include "Mouse.hpp"
#define LOG_PREFIX "[Mouse] "
#include "../../../Outputs/Log.hpp"
using namespace Apple::ADB;
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;
const auto command = decode_command(value);
LOG(command);
if(command.device != 3) {
return;
}

View File

@ -149,25 +149,46 @@ void GLU::run_for(Cycles cycles) {
void GLU::set_port_output(int port, uint8_t value) {
switch(port) {
case 0:
// printf(" {R%d} ", register_address_);
// 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;
}
register_latch_ = value;
break;
case 1:
// printf("Keyboard write: %02x???\n", value);
break;
case 2:
case 2: {
// printf("ADB data line input: %d???\n", value >> 7);
// printf("IIe keyboard reset line: %d\n", (value >> 6)&1);
// printf("IIgs reset line: %d\n", (value >> 5)&1);
// printf("GLU strobe: %d\n", (value >> 4)&1);
// printf("Select GLU register: %d [%02x]\n", value & 0xf, value);
register_address_ = value & 0xf;
break;
// 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;
case 3:
// printf("IIe KWS: %d\n", (value >> 6)&3);
// 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) {
switch(port) {
case 0:
// 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 0: return register_latch_;
case 1:
// printf("IIe keyboard read\n");
return 0x06;

View File

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