saleae-iec-analyser/source/C64SerialAnalyzerResults.cpp

104 lines
3.5 KiB
C++

#include "C64SerialAnalyzerResults.h"
#include "C64SerialAnalyzer.h"
#include "C64SerialAnalyzerSettings.h"
#include <AnalyzerHelpers.h>
#include <fstream>
#include <iostream>
C64SerialAnalyzerResults::C64SerialAnalyzerResults(
C64SerialAnalyzer *analyzer, C64SerialAnalyzerSettings *settings)
: AnalyzerResults(), mSettings(settings), mAnalyzer(analyzer) {}
C64SerialAnalyzerResults::~C64SerialAnalyzerResults() {}
void ControlCodeName(char *buffer, U8 code) {
if (code >= 0x20 && code <= 0x3E) {
sprintf(buffer, "Listen %d", code - 0x20);
} else if (code == 0x3F) {
sprintf(buffer, "Unlisten");
} else if (code >= 0x40 && code <= 0x5E) {
sprintf(buffer, "Talk %d", code - 0x40);
} else if (code == 0x5F) {
sprintf(buffer, "Untalk");
} else if (code >= 0x60 && code <= 0x6F) {
sprintf(buffer, "Reopen ch. %d", code & 0x0F);
} else if (code >= 0xE0 && code <= 0xEF) {
sprintf(buffer, "Close ch. %d", code & 0x0F);
} else if (code >= 0xF0 && code <= 0xFF) {
sprintf(buffer, "Open ch. %d", code & 0x0F);
}
}
void C64SerialAnalyzerResults::GenerateBubbleText(U64 frame_index,
Channel &channel,
DisplayBase display_base) {
ClearResultStrings();
Frame frame = GetFrame(frame_index);
char buffer[128];
if (frame.mType == static_cast<U8>(C64SerialAnalyzer::State::Attention)) {
ControlCodeName(buffer, frame.mData1);
} else {
AnalyzerHelpers::GetNumberString(frame.mData1, display_base, 8, buffer,
sizeof(buffer));
}
AddResultString(buffer);
}
void C64SerialAnalyzerResults::GenerateExportFile(const char *file,
DisplayBase display_base,
U32 export_type_user_id) {
std::ofstream file_stream(file, std::ios::out);
U64 trigger_sample = mAnalyzer->GetTriggerSample();
U32 sample_rate = mAnalyzer->GetSampleRate();
file_stream << "Time [s],Value" << std::endl;
U64 num_frames = GetNumFrames();
for (U32 i = 0; i < num_frames; i++) {
Frame frame = GetFrame(i);
char time_str[128];
AnalyzerHelpers::GetTimeString(frame.mStartingSampleInclusive,
trigger_sample, sample_rate, time_str,
128);
char number_str[128];
AnalyzerHelpers::GetNumberString(frame.mData1, display_base, 8,
number_str, 128);
file_stream << time_str << "," << number_str << std::endl;
if (UpdateExportProgressAndCheckForCancel(i, num_frames) == true) {
file_stream.close();
return;
}
}
file_stream.close();
}
void C64SerialAnalyzerResults::GenerateFrameTabularText(
U64 frame_index, DisplayBase display_base) {
#ifdef SUPPORTS_PROTOCOL_SEARCH
Frame frame = GetFrame(frame_index);
ClearTabularText();
char number_str[128];
AnalyzerHelpers::GetNumberString(frame.mData1, display_base, 8, number_str,
128);
AddTabularText(number_str);
#endif
}
void C64SerialAnalyzerResults::GeneratePacketTabularText(
U64 packet_id, DisplayBase display_base) {
// not supported
}
void C64SerialAnalyzerResults::GenerateTransactionTabularText(
U64 transaction_id, DisplayBase display_base) {
// not supported
}