15#include "SubComponent.h"
27#define VIACountA0 (1ULL << 0)
28#define VIACountA1 (1ULL << 1)
29#define VIACountB0 (1ULL << 2)
30#define VIACountB1 (1ULL << 3)
31#define VIAReloadA0 (1ULL << 4)
32#define VIAReloadA1 (1ULL << 5)
33#define VIAReloadA2 (1ULL << 6)
34#define VIAReloadB0 (1ULL << 7)
35#define VIAReloadB1 (1ULL << 8)
36#define VIAReloadB2 (1ULL << 9)
37#define VIAPostOneShotA0 (1ULL << 10)
38#define VIAPostOneShotB0 (1ULL << 11)
39#define VIAInterrupt0 (1ULL << 12)
40#define VIAInterrupt1 (1ULL << 13)
41#define VIASetCA1out0 (1ULL << 14)
42#define VIASetCA1out1 (1ULL << 15)
43#define VIAClearCA1out0 (1ULL << 16)
44#define VIAClearCA1out1 (1ULL << 17)
45#define VIASetCA2out0 (1ULL << 18)
46#define VIASetCA2out1 (1ULL << 19)
47#define VIAClearCA2out0 (1ULL << 20)
48#define VIAClearCA2out1 (1ULL << 21)
49#define VIASetCB2out0 (1ULL << 22)
50#define VIASetCB2out1 (1ULL << 23)
51#define VIAClearCB2out0 (1ULL << 24)
52#define VIAClearCB2out1 (1ULL << 25)
53#define VIAPB7out0 (1ULL << 26)
54#define VIAClrInterrupt0 (1ULL << 27)
55#define VIAClrInterrupt1 (1ULL << 28)
57#define VIAClearBits ~((1ULL << 29) | VIACountA0 | VIACountB0 | VIAReloadA0 | VIAReloadB0 | VIAPostOneShotA0 | VIAPostOneShotB0 | VIAInterrupt0 | VIASetCA1out0 | VIAClearCA1out0 | VIASetCA2out0 | VIAClearCA2out0 | VIASetCB2out0 | VIAClearCB2out0 | VIAPB7out0 | VIAClrInterrupt0)
59class VIA6522 :
public SubComponent {
61 Descriptions descriptions = {{
64 .description =
"VIA 6522"
68 friend class ParCable;
228 VIA6522(C64 &ref, Drive &drvref);
229 virtual bool isVia1()
const = 0;
231 VIA6522& operator= (
const VIA6522& other) {
272 void serialize(T& worker)
304 } SERIALIZERS(serialize);
313 const Descriptions &getDescriptions()
const override {
return descriptions; }
314 void prefix()
const override;
318 void _dump(Category category, std::ostream& os)
const override;
319 void _reset(
bool hard)
override;
332 u8 getDDRA()
const {
return ddra; }
333 u8 getDDRB()
const {
return ddrb; }
336 u8 getPA()
const {
return pa; }
337 u8 getPB()
const {
return pb; }
340 bool getCA2()
const {
return ca2; }
341 bool getCB2()
const {
return cb2; }
349 void executeTimer1();
350 void executeTimer2();
357 virtual u8 peek(u16 addr);
365 virtual u8 peekORA(
bool handshake);
373 u8 spypeek(u16 addr)
const;
378 void poke(u16 addr, u8 value);
386 virtual void pokeORA(u8 value,
bool handshake);
389 void pokeORB(u8 value);
392 void pokePCR(u8 value);
400 bool freeRun()
const {
return (acr & 0x40) != 0; }
403 bool countPulses()
const {
return (acr & 0x20) != 0; }
406 bool PB7OutputEnabled()
const {
return (acr & 0x80) != 0; }
409 bool inputLatchingEnabledA()
const {
return (GET_BIT(acr,0)); }
410 bool inputLatchingEnabledB()
const {
return (GET_BIT(acr,1)); }
420 u8 ca1Control()
const {
return pcr & 0x01; }
421 u8 ca2Control()
const {
return (pcr >> 1) & 0x07; }
422 u8 cb1Control()
const {
return (pcr >> 4) & 0x01; }
423 u8 cb2Control()
const {
return (pcr >> 5) & 0x07; }
433 u8 portAinternal()
const;
436 virtual u8 portAexternal()
const = 0;
439 virtual void updatePA();
442 u8 portBinternal()
const;
445 virtual u8 portBexternal()
const = 0;
448 virtual void updatePB();
458 void CA1action(
bool value);
463 void setCA1(
bool value);
473 virtual void pullDownIrqLine() = 0;
474 virtual void releaseIrqLine() = 0;
479 void releaseIrqLineIfNeeded() {
if ((ifr & ier) == 0) delay |= VIAClrInterrupt0; }
504 void setInterruptFlag_T1() {
505 if (!GET_BIT(ifr, 6) && GET_BIT(ier, 6)) delay |= VIAInterrupt0;
508 void clearInterruptFlag_T1() { CLR_BIT(ifr, 6); releaseIrqLineIfNeeded(); }
511 void setInterruptFlag_T2() {
512 if (!GET_BIT(ifr, 5) && GET_BIT(ier, 5)) delay |= VIAInterrupt0;
515 void clearInterruptFlag_T2() { CLR_BIT(ifr, 5); releaseIrqLineIfNeeded(); }
518 void setInterruptFlag_CB1() {
519 if (!GET_BIT(ifr, 4) && GET_BIT(ier, 4)) delay |= VIAInterrupt0;
522 void clearInterruptFlag_CB1() { CLR_BIT(ifr, 4); releaseIrqLineIfNeeded(); }
525 void clearInterruptFlag_CB2() { CLR_BIT(ifr, 3); releaseIrqLineIfNeeded(); }
528 void clearInterruptFlag_SR() { CLR_BIT(ifr, 2); releaseIrqLineIfNeeded(); }
531 void clearInterruptFlag_CA1() { CLR_BIT(ifr, 1); releaseIrqLineIfNeeded(); }
534 void clearInterruptFlag_CA2() { CLR_BIT(ifr, 0); releaseIrqLineIfNeeded(); }
552class VIA1 final :
public VIA6522 {
556 VIA1(C64 &ref, Drive &drvref) : VIA6522(ref, drvref) { }
558 bool isVia1()
const override {
return true; }
560 u8 peekORA(
bool handshake)
override;
561 void pokeORA(u8 value,
bool handshake)
override;
562 u8 portAexternal()
const override;
563 u8 portBexternal()
const override;
564 void updatePA()
override;
565 void updatePB()
override;
566 void pullDownIrqLine()
override;
567 void releaseIrqLine()
override;
573class VIA2 final :
public VIA6522 {
577 VIA2(C64 &ref, Drive &drvref) : VIA6522(ref, drvref) { }
579 bool isVia1()
const override {
return false; }
581 u8 portAexternal()
const override;
582 u8 portBexternal()
const override;
583 void updatePB()
override;
584 void pullDownIrqLine()
override;
585 void releaseIrqLine()
override;
VirtualC64 project namespace.
Definition CmdQueue.cpp:16