- [NEW] Implementats registres de lectura del TIA
- [NEW] Registres d'escritura del TIA: Implementats VSYNC, VBLANK, WSYNC i RSYNC
This commit is contained in:
1 parent
22fd027cff
commit
df7ba3a02a
3 files changed
+81
-2
No files matched your search
@@ -44,7 +44,11 @@ namespace atari2600
|
|||||||
// } else {
|
// } else {
|
||||||
bool instruction_done = false;
|
bool instruction_done = false;
|
||||||
while (!instruction_done) {
|
while (!instruction_done) {
|
||||||
|
if (!tia::is_rdy_low()) {
|
||||||
instruction_done = m6502::tick();
|
instruction_done = m6502::tick();
|
||||||
|
} else {
|
||||||
|
instruction_done = true;
|
||||||
|
}
|
||||||
tia::tick();
|
tia::tick();
|
||||||
tia::tick();
|
tia::tick();
|
||||||
tia::tick();
|
tia::tick();
|
||||||
|
|||||||
@@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
namespace tia
|
namespace tia
|
||||||
{
|
{
|
||||||
|
uint8_t collisions[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
float paddle_pos[4] { 0.5f, 0.5f, 0.5f, 0.5f };
|
||||||
|
uint32_t paddle_charge_cycles[4] { 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
bool joy0_button_pressed = false;
|
||||||
|
bool joy1_button_pressed = false;
|
||||||
|
|
||||||
|
uint32_t current_frame_cycles = 0;
|
||||||
|
|
||||||
|
bool vsync_set = false;
|
||||||
|
bool vblank_set = false;
|
||||||
|
bool vblank_latch = false;
|
||||||
|
bool vblank_dump = false;
|
||||||
|
|
||||||
|
uint16_t color_clock = 0;
|
||||||
|
bool rdy_low = false;
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -9,14 +27,41 @@ namespace tia
|
|||||||
|
|
||||||
void tick()
|
void tick()
|
||||||
{
|
{
|
||||||
|
if (!vblank_dump) current_frame_cycles++;
|
||||||
|
color_clock = (color_clock + 1) % 228;
|
||||||
|
|
||||||
|
if (color_clock == 0) rdy_low = false;
|
||||||
|
|
||||||
|
// [TODO] Pintar pixels
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t get_paddle_state(int index)
|
||||||
|
{
|
||||||
|
if (vblank_dump) return 0x00;
|
||||||
|
return (current_frame_cycles >= paddle_charge_cycles[index]) ? 0x80 : 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t read(uint16_t address)
|
uint8_t read(uint16_t address)
|
||||||
{
|
{
|
||||||
address &= 0x0f;
|
switch (address & 0x0f) {
|
||||||
|
case 0x00: return collisions[0];
|
||||||
|
case 0x01: return collisions[2];
|
||||||
|
case 0x02: return collisions[3];
|
||||||
|
case 0x03: return collisions[4];
|
||||||
|
case 0x04: return collisions[5];
|
||||||
|
case 0x05: return collisions[6];
|
||||||
|
case 0x06: return collisions[7];
|
||||||
|
case 0x07: return collisions[8];
|
||||||
|
|
||||||
// [TODO] Procesar segons l'adreça resultant
|
case 0x08: return get_paddle_state(0);
|
||||||
|
case 0x09: return get_paddle_state(1);
|
||||||
|
case 0x0A: return get_paddle_state(2);
|
||||||
|
case 0x0B: return get_paddle_state(3);
|
||||||
|
|
||||||
|
case 0x0C: return joy0_button_pressed ? 0x00 : 0x80;
|
||||||
|
case 0x0D: return joy1_button_pressed ? 0x00 : 0x80;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(uint16_t address, uint8_t value)
|
void write(uint16_t address, uint8_t value)
|
||||||
@@ -25,6 +70,34 @@ namespace tia
|
|||||||
if (address >= 0x2d) address -= 0x20;
|
if (address >= 0x2d) address -= 0x20;
|
||||||
|
|
||||||
// [TODO] Procesar segons l'adreça resultant
|
// [TODO] Procesar segons l'adreça resultant
|
||||||
|
switch (address) {
|
||||||
|
case 0x00: // VSYNC
|
||||||
|
vsync_set = value & 0x20;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x01: // VBLANK
|
||||||
|
bool prev_dump = vblank_dump;
|
||||||
|
vblank_set = value & 0x20;
|
||||||
|
vblank_latch = value & 0x40;
|
||||||
|
vblank_dump = value & 0x80;
|
||||||
|
if (prev_dump && !vblank_dump) {
|
||||||
|
current_frame_cycles = 0;
|
||||||
|
for (int i = 0; i < 4; ++i) paddle_charge_cycles[i] = static_cast<uint32_t>(paddle_pos[i] * 2400.0f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x02: // WSYNC
|
||||||
|
rdy_low = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x03: // RSYNC
|
||||||
|
color_clock = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_rdy_low()
|
||||||
|
{
|
||||||
|
return rdy_low;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user