]> Shamusworld >> Repos - apple2/blob - src/mockingboard.cpp
Added initial emulator configuration window, cleanup of settings code.
[apple2] / src / mockingboard.cpp
1 //
2 // Mockingboard support
3 //
4 // by James Hammons
5 // (C) 2018 Underground Software
6 //
7 // NOTES:
8 // bit 7 = L/R channel select (AY chip 1 versus AY chip 2)
9 //         0 = Left, 1 = Right
10 //
11 // Reg. B is connected to BC1, BDIR, RST' (bits 0, 1, 2)
12 //
13 // Left VIA IRQ line is tied to 6502 IRQ line
14 // Rght VIA IRQ line is tied to 6502 NMI line
15 //
16
17
18 #include "mockingboard.h"
19 #include "apple2.h"
20 #include "mmu.h"
21
22
23 MOCKINGBOARD mb[2];
24
25
26 void MBReset(void)
27 {
28         mb[0].via[0].Reset();
29         mb[0].via[1].Reset();
30         mb[0].ay[0].Reset();
31         mb[0].ay[1].Reset();
32 }
33
34
35 void MBWrite(int chipNum, uint8_t reg, uint8_t byte)
36 {
37         V6522VIA * chip1 = &mb[0].via[chipNum];
38         chip1->Write(reg, byte);
39
40         if (reg == 0)
41                 mb[0].ay[chipNum].WriteControl(chip1->orb & chip1->ddrb);
42         else if (reg == 1)
43                 mb[0].ay[chipNum].WriteData(chip1->ora & chip1->ddra);
44 }
45
46
47 uint8_t MBRead(int chipNum, uint8_t reg)
48 {
49         return mb[0].via[chipNum].Read(reg);
50 }
51
52
53 void MBRun(uint16_t cycles)
54 {
55         if (mb[0].via[0].Run(cycles))
56                 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_IRQ;
57
58         if (mb[0].via[1].Run(cycles))
59                 mainCPU.cpuFlags |= V65C02_ASSERT_LINE_NMI;
60 }
61
62
63 void MBSaveState(FILE * file)
64 {
65         fwrite(&mb[0], 1, sizeof(struct MOCKINGBOARD), file);
66         fwrite(&mb[1], 1, sizeof(struct MOCKINGBOARD), file);
67 }
68
69
70 void MBLoadState(FILE * file)
71 {
72         fread(&mb[0], 1, sizeof(struct MOCKINGBOARD), file);
73         fread(&mb[1], 1, sizeof(struct MOCKINGBOARD), file);
74 }
75
76
77 static uint8_t SlotPageR(uint16_t address)
78 {
79         uint8_t regNum = address & 0x0F;
80         uint8_t chipNum = (address & 0x80) >> 7;
81
82         return MBRead(chipNum, regNum);
83 }
84
85
86 static void SlotPageW(uint16_t address, uint8_t byte)
87 {
88         uint8_t regNum = address & 0x0F;
89         uint8_t chipNum = (address & 0x80) >> 7;
90
91         MBWrite(chipNum, regNum, byte);
92 }
93
94
95 void InstallMockingboard(uint8_t slot)
96 {
97         SlotData mbDevice = { 0, 0, SlotPageR, SlotPageW, 0, 0 };
98         InstallSlotHandler(slot, &mbDevice);
99 }
100