1
0
mirror of https://github.com/jscrane/r65emu.git synced 2025-01-17 18:29:55 +00:00

debugging via and pia + some small bugfixes

This commit is contained in:
steve 2024-11-26 18:23:28 +00:00
parent 7625e1613a
commit c3a82b7d7a
5 changed files with 110 additions and 65 deletions

View File

@ -71,7 +71,7 @@ void hardware_init(CPU &cpu) {
_cpu = &cpu;
cpu.memory().begin();
#if defined(DEBUGGING) || defined(CPU_DEBUG) || defined(USE_SERIAL)
#if defined(DEBUGGING) || defined(CPU_DEBUG) || defined(PIA_DEBUG) || defined(VIA_DEBUG) || defined(USE_SERIAL)
Serial.begin(TERMINAL_SPEED);
while (!Serial);
delay(800);
@ -93,7 +93,7 @@ void hardware_init(CPU &cpu) {
}
#if defined(CPU_DEBUG)
bool cpu_debug = CPU_DEBUG;
static bool cpu_debug = CPU_DEBUG;
#endif
bool hardware_debug_cpu() {

View File

@ -1,8 +1,4 @@
/*
* The hardware configuration of the machine.
*/
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
#pragma once
#if defined(HARDWARE_H)
#include HARDWARE_H
@ -31,10 +27,9 @@ int hardware_oneshot_timer(uint32_t ms, std::function<void(void)> cb);
extern class spiram sram;
#endif
//#define DEBUGGING
#if defined(DEBUGGING)
#define DBG(x) Serial.x
#else
#define DBG(x)
#endif
#endif

View File

@ -1,5 +1,11 @@
#include <Arduino.h>
#include <memory.h>
#if defined(PIA_DEBUG)
#define DEBUGGING
#endif
#include <hardware.h>
#include "pia.h"
// see: https://github.com/mamedev/mame/blob/master/src/devices/machine/6821pia.cpp
@ -20,13 +26,13 @@ inline bool c2_high_to_low(uint8_t cr) { return !c2_low_to_high(cr); }
inline bool output_selected(uint8_t cr) { return cr & 0x04; }
void PIA::write(Memory::address a, uint8_t b) {
#if defined(DEBUG_PIA)
Serial.print(millis());
Serial.print(" > ");
Serial.print(a, 16);
Serial.print(' ');
Serial.println(b, 16);
#endif
DBG(print(millis()));
DBG(print(F(" pia > ")));
DBG(print(a, 16));
DBG(print(' '));
DBG(println(b, 16));
switch(a & 3) {
case 0:
output_selected(cra)? write_porta(b): write_ddra(b);
@ -44,22 +50,30 @@ void PIA::write(Memory::address a, uint8_t b) {
}
uint8_t PIA::read(Memory::address a) {
#if defined(DEBUG_PIA)
Serial.print(millis());
Serial.print(" < ");
Serial.println(a, 16);
#endif
uint8_t b = 0xff;
switch (a & 3) {
case 0:
return output_selected(cra)? read_porta(): read_ddra();
b = output_selected(cra)? read_porta(): read_ddra();
break;
case 1:
return read_cra();
b = read_cra();
break;
case 2:
return output_selected(crb)? read_portb(): read_ddrb();
b = output_selected(crb)? read_portb(): read_ddrb();
break;
case 3:
return read_crb();
b = read_crb();
break;
}
return 0xff;
DBG(print(millis()));
DBG(print(F(" pia < ")));
DBG(print(a, 16));
DBG(print(' '));
DBG(println(b, 16));
return b;
}
void PIA::checkpoint(Stream &s) {

View File

@ -35,7 +35,7 @@ static uint8_t fn(uint8_t key) {
case PS2_F7: return 7;
case PS2_F8: return 8;
case PS2_F9: return 9;
case PS2_F10: return 01;
case PS2_F10: return 10;
case PS2_F11: return 11;
case PS2_F12: return 12;
}

View File

@ -2,24 +2,36 @@
#include <memory.h>
#include <via.h>
#define PORTB 0x00
#define PORTA 0x01
#define DDRB 0x02
#define DDRA 0x03
#define T1LO 0x04
#define T1HI 0x05
#define T1LLO 0x06
#define T1LHI 0x07
#define T2LO 0x08
#define T2HI 0x09
#define SHIFT 0x0a
#define ACR 0x0b
#define PCR 0x0c
#define IFR 0x0d
#define IER 0x0e
#if defined(VIA_DEBUG)
#define DEBUGGING
#endif
#include <hardware.h>
#define PORTB 0x00
#define PORTA 0x01
#define DDRB 0x02
#define DDRA 0x03
#define T1LO 0x04
#define T1HI 0x05
#define T1LLO 0x06
#define T1LHI 0x07
#define T2LO 0x08
#define T2HI 0x09
#define SHIFT 0x0a
#define ACR 0x0b
#define PCR 0x0c
#define IFR 0x0d
#define IER 0x0e
#define PORTA_NH 0x0f
void VIA::write(Memory::address a, uint8_t b) {
DBG(print(millis()));
DBG(print(F(" via > ")));
DBG(print(a, 16));
DBG(print(' '));
DBG(println(b, 16));
switch (a & 0x0f) {
case PORTB:
write_portb(b);
@ -133,7 +145,7 @@ void VIA::write_acr(uint8_t b) {
void VIA::write_ier(uint8_t b) {
if (b & INT_MASTER)
_ier |= b & 0x7f;
_ier |= (b & 0x7f);
else
_ier &= ~(b & 0x7f);
}
@ -143,40 +155,64 @@ void VIA::write_porta_nh(uint8_t b) {
}
uint8_t VIA::read(Memory::address a) {
uint8_t b = 0x00;
switch (a & 0x0f) {
case PORTB:
return read_portb();
b = read_portb();
break;
case PORTA:
return read_porta();
b = read_porta();
break;
case DDRB:
return read_ddrb();
b = read_ddrb();
break;
case DDRA:
return read_ddra();
b = read_ddra();
break;
case T1LO:
return read_t1lo();
b = read_t1lo();
break;
case T1HI:
return read_t1hi();
b = read_t1hi();
break;
case T1LLO:
return read_t1llo();
b = read_t1llo();
break;
case T1LHI:
return read_t1lhi();
b = read_t1lhi();
break;
case T2LO:
return read_t2lo();
b = read_t2lo();
break;
case T2HI:
return read_t2hi();
b = read_t2hi();
break;
case SHIFT:
return read_sr();
b = read_sr();
break;
case ACR:
return read_acr();
b = read_acr();
break;
case PCR:
return read_pcr();
b = read_pcr();
break;
case IFR:
return read_ifr();
b = read_ifr();
break;
case IER:
return read_ier();
b = read_ier();
break;
case PORTA_NH:
return read_porta_nh();
b = read_porta_nh();
break;
}
DBG(print(millis()));
DBG(print(F(" via < ")));
DBG(print(a, 16));
DBG(print(' '));
DBG(println(b, 16));
return 0x00;
}
@ -211,25 +247,25 @@ void VIA::tick() {
uint32_t now = millis();
if (_timer1) {
uint32_t interval = now - _t1_tick;
if (_t1 < interval) {
uint32_t elapsed = now - _t1_tick;
if (_t1 < elapsed) {
_t1 = 0;
_timer1 = false;
set_int(INT_TIMER1);
} else {
_t1 -= interval;
_t1 -= elapsed;
_t1_tick = now;
}
}
if (_timer2) {
uint32_t interval = now - _t1_tick;
if (_t2 < interval) {
uint32_t elapsed = now - _t2_tick;
if (_t2 < elapsed) {
_t2 = 0;
_timer2 = false;
set_int(INT_TIMER2);
} else {
_t2 -= interval;
_t2 -= elapsed;
_t2_tick = now;
}
}