mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-10 22:37:30 +00:00
Continued slow migration of shader ownership to CRT. Attempted to start debugging the tape interface.
This commit is contained in:
parent
96c946b8af
commit
adc6838ba0
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#include "Electron.hpp"
|
||||
#include "TapeUEF.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -85,6 +86,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
{
|
||||
if((address & 0xff00) == 0xfe00)
|
||||
{
|
||||
cycles += (_frameCycles&1)^1;
|
||||
// printf("%c: %02x: ", isReadOperation(operation) ? 'r' : 'w', *value);
|
||||
|
||||
switch(address&0xf)
|
||||
@ -639,12 +641,34 @@ inline void Tape::push_tape_bit(uint16_t bit)
|
||||
evaluate_interrupts();
|
||||
}
|
||||
|
||||
inline void Tape::reset_tape_input()
|
||||
{
|
||||
_bits_since_start = 0;
|
||||
// _interrupt_status &= ~(Interrupt::ReceiveDataFull | Interrupt::TransmitDataEmpty | Interrupt::HighToneDetect);
|
||||
//
|
||||
// if(_last_posted_interrupt_status != _interrupt_status)
|
||||
// {
|
||||
// _last_posted_interrupt_status = _interrupt_status;
|
||||
// if(_delegate) _delegate->tape_did_change_interrupt_status(this);
|
||||
// }
|
||||
}
|
||||
|
||||
extern uint8_t dr;
|
||||
|
||||
inline void Tape::evaluate_interrupts()
|
||||
{
|
||||
if((_data_register&0x3) == 0x1)
|
||||
if(!_bits_since_start)
|
||||
{
|
||||
_interrupt_status |= Interrupt::ReceiveDataFull;
|
||||
_bits_since_start = 9;
|
||||
if((_data_register&0x3) == 0x1)
|
||||
{
|
||||
if(dr != ((_data_register >> 2)&0xff))
|
||||
{
|
||||
printf("Mismatch\n");
|
||||
}
|
||||
|
||||
_interrupt_status |= Interrupt::ReceiveDataFull;
|
||||
if(_is_in_input_mode) _bits_since_start = 9;
|
||||
}
|
||||
}
|
||||
|
||||
if(_data_register == 0x3ff)
|
||||
@ -699,6 +723,11 @@ inline void Tape::run_for_cycles(unsigned int number_of_cycles)
|
||||
{
|
||||
get_next_tape_pulse();
|
||||
|
||||
// if(_crossings[0] != Tape::Recognised)
|
||||
// {
|
||||
// reset_tape_input();
|
||||
// }
|
||||
|
||||
_crossings[0] = _crossings[1];
|
||||
_crossings[1] = _crossings[2];
|
||||
_crossings[2] = _crossings[3];
|
||||
@ -707,23 +736,30 @@ inline void Tape::run_for_cycles(unsigned int number_of_cycles)
|
||||
if(_current_pulse.type != Storage::Tape::Pulse::Zero)
|
||||
{
|
||||
float pulse_length = (float)_current_pulse.length.length / (float)_current_pulse.length.clock_rate;
|
||||
if(pulse_length > 0.4 / 2400.0 && pulse_length < 0.6 / 2400.0) _crossings[3] = Tape::Short;
|
||||
if(pulse_length > 0.4 / 1200.0 && pulse_length < 0.6 / 1200.0) _crossings[3] = Tape::Long;
|
||||
if(pulse_length >= 0.35 / 2400.0 && pulse_length < 0.7 / 2400.0) _crossings[3] = Tape::Short;
|
||||
if(pulse_length >= 0.35 / 1200.0 && pulse_length < 0.7 / 1200.0) _crossings[3] = Tape::Long;
|
||||
|
||||
if(_crossings[3] == Tape::Unrecognised)
|
||||
{
|
||||
printf("Wah wah?\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(_crossings[0] == Tape::Long && _crossings[1] == Tape::Long)
|
||||
{
|
||||
push_tape_bit(0);
|
||||
_crossings[1] = Tape::Unrecognised;
|
||||
_crossings[0] = _crossings[1] = Tape::Recognised;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_crossings[0] == Tape::Short && _crossings[1] == Tape::Short && _crossings[2] == Tape::Short && _crossings[3] == Tape::Short)
|
||||
{
|
||||
push_tape_bit(1);
|
||||
_crossings[3] = Tape::Unrecognised;
|
||||
_crossings[0] = _crossings[1] =
|
||||
_crossings[2] = _crossings[3] = Tape::Recognised;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ class Tape {
|
||||
|
||||
private:
|
||||
inline void push_tape_bit(uint16_t bit);
|
||||
inline void reset_tape_input(void);
|
||||
inline void get_next_tape_pulse();
|
||||
|
||||
std::shared_ptr<Storage::Tape> _tape;
|
||||
@ -104,7 +105,7 @@ class Tape {
|
||||
Delegate *_delegate;
|
||||
|
||||
enum {
|
||||
Long, Short, Unrecognised
|
||||
Long, Short, Unrecognised, Recognised
|
||||
} _crossings[4];
|
||||
};
|
||||
|
||||
|
@ -539,15 +539,15 @@ char *CRT::get_vertex_shader()
|
||||
"srcCoordinatesVarying[1] = srcCoordinatesVarying[0] - vec2(0.125 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[0] = srcCoordinatesVarying[0] - vec2(0.325 / textureSize.x, 0.0);\n";
|
||||
|
||||
const char *const rgbVertexShaderGlobals =
|
||||
"out vec2 srcCoordinatesVarying[5];\n";
|
||||
// const char *const rgbVertexShaderGlobals =
|
||||
// "out vec2 srcCoordinatesVarying[5];\n";
|
||||
|
||||
const char *const rgbVertexShaderBody =
|
||||
"srcCoordinatesVarying[2] = vec2(srcCoordinates.x / textureSize.x, (srcCoordinates.y + 0.5) / textureSize.y);\n"
|
||||
"srcCoordinatesVarying[0] = srcCoordinatesVarying[1] - vec2(1.0 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[1] = srcCoordinatesVarying[1] - vec2(0.5 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[3] = srcCoordinatesVarying[1] + vec2(0.5 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[4] = srcCoordinatesVarying[1] + vec2(1.0 / textureSize.x, 0.0);\n";
|
||||
// const char *const rgbVertexShaderBody =
|
||||
// "srcCoordinatesVarying[2] = vec2(srcCoordinates.x / textureSize.x, (srcCoordinates.y + 0.5) / textureSize.y);\n"
|
||||
// "srcCoordinatesVarying[0] = srcCoordinatesVarying[1] - vec2(1.0 / textureSize.x, 0.0);\n"
|
||||
// "srcCoordinatesVarying[1] = srcCoordinatesVarying[1] - vec2(0.5 / textureSize.x, 0.0);\n"
|
||||
// "srcCoordinatesVarying[3] = srcCoordinatesVarying[1] + vec2(0.5 / textureSize.x, 0.0);\n"
|
||||
// "srcCoordinatesVarying[4] = srcCoordinatesVarying[1] + vec2(1.0 / textureSize.x, 0.0);\n";
|
||||
|
||||
const char *const vertexShader =
|
||||
"#version 150\n"
|
||||
@ -588,3 +588,78 @@ char *CRT::get_vertex_shader()
|
||||
// case CSCathodeRayViewSignalTypeRGB: return [NSString stringWithFormat:vertexShader, rgbVertexShaderGlobals, rgbVertexShaderBody];
|
||||
// }
|
||||
}
|
||||
|
||||
char *CRT::get_fragment_shader(const char *sample_function)
|
||||
{
|
||||
// assumes y = [0, 1], i and q = [-0.5, 0.5]; therefore i components are multiplied by 1.1914 versus standard matrices, q by 1.0452
|
||||
const char *const yiqToRGB = "const mat3 yiqToRGB = mat3(1.0, 1.0, 1.0, 1.1389784, -0.3240608, -1.3176884, 0.6490692, -0.6762444, 1.7799756);";
|
||||
|
||||
// assumes y = [0,1], u and v = [-0.5, 0.5]; therefore u components are multiplied by 1.14678899082569, v by 0.8130081300813
|
||||
const char *const yuvToRGB = "const mat3 yiqToRGB = mat3(1.0, 1.0, 1.0, 0.0, -0.75213899082569, 2.33040137614679, 0.92669105691057, -0.4720325203252, 0.0);";
|
||||
|
||||
const char *const fragmentShader =
|
||||
"#version 150\n"
|
||||
"\n"
|
||||
"in float lateralVarying;\n"
|
||||
"in vec2 shadowMaskCoordinates;\n"
|
||||
"out vec4 fragColour;\n"
|
||||
"\n"
|
||||
"uniform sampler2D texID;\n"
|
||||
"uniform sampler2D shadowMaskTexID;\n"
|
||||
"uniform float alpha;\n"
|
||||
"\n"
|
||||
"in vec2 srcCoordinatesVarying[4];\n"
|
||||
"in float phase;\n"
|
||||
"%@\n"
|
||||
"%@\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
"%@\n"
|
||||
"}\n";
|
||||
|
||||
const char *const ntscFragmentShaderGlobals =
|
||||
"in vec2 srcCoordinatesVarying[4];\n"
|
||||
"in float phase;\n"
|
||||
"\n"
|
||||
"// for conversion from i and q are in the range [-0.5, 0.5] (so i needs to be multiplied by 1.1914 and q by 1.0452)\n"
|
||||
"const mat3 yiqToRGB = mat3(1.0, 1.0, 1.0, 1.1389784, -0.3240608, -1.3176884, 0.6490692, -0.6762444, 1.7799756);\n";
|
||||
|
||||
const char *const ntscFragmentShaderBody =
|
||||
"vec4 angles = vec4(phase) + vec4(-2.35619449019234, -0.78539816339745, 0.78539816339745, 2.35619449019234);\n"
|
||||
"vec4 samples = vec4("
|
||||
" sample(srcCoordinatesVarying[0], angles.x),"
|
||||
" sample(srcCoordinatesVarying[1], angles.y),"
|
||||
" sample(srcCoordinatesVarying[2], angles.z),"
|
||||
" sample(srcCoordinatesVarying[3], angles.w)"
|
||||
");\n"
|
||||
"\n"
|
||||
"float y = dot(vec4(0.25), samples);\n"
|
||||
"samples -= vec4(y);\n"
|
||||
"\n"
|
||||
"float i = dot(cos(angles), samples);\n"
|
||||
"float q = dot(sin(angles), samples);\n"
|
||||
"\n"
|
||||
"fragColour = 5.0 * texture(shadowMaskTexID, shadowMaskCoordinates) * vec4(yiqToRGB * vec3(y, i, q), 1.0);//sin(lateralVarying));\n";
|
||||
|
||||
// const char *const rgbFragmentShaderGlobals =
|
||||
// "in vec2 srcCoordinatesVarying[5];\n"; // texture(shadowMaskTexID, shadowMaskCoordinates) *
|
||||
|
||||
// const char *const rgbFragmentShaderBody =
|
||||
// "fragColour = sample(srcCoordinatesVarying[2]);";
|
||||
// @"fragColour = (sample(srcCoordinatesVarying[0]) * -0.1) + \
|
||||
// (sample(srcCoordinatesVarying[1]) * 0.3) + \
|
||||
// (sample(srcCoordinatesVarying[2]) * 0.6) + \
|
||||
// (sample(srcCoordinatesVarying[3]) * 0.3) + \
|
||||
// (sample(srcCoordinatesVarying[4]) * -0.1);";
|
||||
|
||||
// dot(vec3(1.0/6.0, 2.0/3.0, 1.0/6.0), vec3(sample(srcCoordinatesVarying[0]), sample(srcCoordinatesVarying[0]), sample(srcCoordinatesVarying[0])));//sin(lateralVarying));\n";
|
||||
|
||||
return nullptr;
|
||||
|
||||
// switch(_signalType)
|
||||
// {
|
||||
// case CSCathodeRayViewSignalTypeNTSC: return [NSString stringWithFormat:fragmentShader, ntscFragmentShaderGlobals, ntscFragmentShaderBody];
|
||||
// case CSCathodeRayViewSignalTypeRGB: return [NSString stringWithFormat:fragmentShader, rgbFragmentShaderGlobals, rgbFragmentShaderBody];
|
||||
// }
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ class CRT {
|
||||
of the supplied sampling function.
|
||||
|
||||
@param sample_function A GLSL fragent including a function with the signature
|
||||
`vec3 sample(vec2 coordinate)` that evaluates to an RGB colour as a function of
|
||||
`vec3 rgb_sample(vec2 coordinate)` that evaluates to an RGB colour as a function of
|
||||
the source buffer sampling location.
|
||||
|
||||
@returns A complete fragment shader.
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "TapeUEF.hpp"
|
||||
#include <string.h>
|
||||
|
||||
uint8_t dr;
|
||||
|
||||
Storage::UEF::UEF(const char *file_name) :
|
||||
_chunk_id(0), _chunk_length(0), _chunk_position(0),
|
||||
_time_base(1200)
|
||||
@ -178,7 +180,7 @@ bool Storage::UEF::get_next_bit()
|
||||
_chunk_position++;
|
||||
if(!bit_position)
|
||||
{
|
||||
_current_byte = (uint8_t)gzgetc(_file);
|
||||
dr = _current_byte = (uint8_t)gzgetc(_file);
|
||||
}
|
||||
if(bit_position == 0) return false;
|
||||
if(bit_position == 9) return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user