1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-01 11:49:58 +00:00

Attempts to simplify ADB bit parsing.

On-line output still looks reasonable, albeit that the microcontroller suddenly seems to be interested in devices F and 3 rather than 2 and 3.
This commit is contained in:
Thomas Harte 2021-02-08 22:08:49 -05:00
parent 3c7f9a43ad
commit 46bd20b5e0

View File

@ -172,25 +172,41 @@ void GLU::set_port_output(int port, uint8_t value) {
// 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);
const bool new_adb_level = value & 0x08; // Output is inverted respective to input; the microcontroller
if(new_adb_level != adb_level_) { // sets a value of '1' in order to pull the ADB bus low.
printf("."); const bool new_adb_level = !(value & 0x08);
if(!new_adb_level) {
// Transition to low.
constexpr float clock_rate = 894886.25;
const float seconds = float(total_period_.as<int>()) / clock_rate;
// Check for a valid bit length — 70 to 130 microseconds. // React to signal edges only.
// (Plus a little). if(new_adb_level != adb_level_) {
if(seconds >= 0.000'56 && seconds <= 0.001'04) { if(new_adb_level) {
// This was a transition to high; classify what just happened according to
// the duration of the low period.
const uint64_t low_microseconds = (low_period_.as<uint64_t>() * uint64_t(800000)) / uint64_t(715909);
// Low periods:
// (partly as adapted from the AN591 data sheet; otherwise from the IIgs reference manual)
//
// > 1040 µs reset
// 5601040 µs attention
// < 50 µs 1
// 5072 µs 0
// 300 µs service request
printf("%llu -> ", low_microseconds);
if(low_microseconds > 1040) {
printf("!!! Reset\n");
} else if(low_microseconds >= 560) {
printf("!!! Attention\n"); printf("!!! Attention\n");
} else if(seconds >= 0.000'06 && seconds <= 0.000'14) { } else if(low_microseconds < 50) {
printf("!!! bit: %d\n", (low_period_.as<int>() * 2) < total_period_.as<int>()); printf("!!! bit: 1\n");
// printf("tested: %0.2f\n", float(low_period_.as<int>()) / float(total_period_.as<int>())); } else if(low_microseconds < 72) {
printf("!!! bit: 0\n");
} else if(low_microseconds >= 291 && low_microseconds <= 309) {
printf("!!! SRQ\n");
} else { } else {
printf("!!! Rejected %d microseconds\n", int(seconds * 1'000'000.0f)); printf("!!! Rejected\n");
} }
// TODO: eliminate total_period_ ?
total_period_ = low_period_ = Cycles(0); total_period_ = low_period_ = Cycles(0);
} }
adb_level_ = new_adb_level; adb_level_ = new_adb_level;
@ -222,7 +238,7 @@ uint8_t GLU::get_port_input(int port) {
return 0x06; return 0x06;
case 2: case 2:
// printf("ADB data line input, etc\n"); // printf("ADB data line input, etc\n");
return adb_level_ ? 0x00 : 0x80; // Unclear on this; possibly ADB output is inverted? Or the input is somehow isolated from the output? return adb_level_ ? 0x80 : 0x00;
case 3: case 3:
// printf("ADB data line output, etc\n"); // printf("ADB data line output, etc\n");
return 0x00; return 0x00;