1 /* disk access emulation
3 * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #define CIAAPRA 0xbfe000
28 #define CIABPRB 0xbfd100
29 #define DSKPTH 0xdff020
30 #define DSKPTL 0xdff022
31 #define DSKLEN 0xdff024
32 #define INTREQR 0xdff01e
34 static uint16_t ciabprb = 0xffff;
36 static uint32_t dskptr = 0;
37 static uint16_t dsklen = 0;
39 /* NOTE: all CIA access is WORD access, so we use bits 8..15 for CIA-B */
41 uint16_t emulate_disk_read(uint32_t address)
43 uint16_t value = 0xffff;
47 /* /RDY (bit 5) is always 0, so disk is ready! */
53 /* return current bits from CIA-A PRB */
57 /* if disk dma is not on, don't process read/write */
58 if (!(dsklen & 0x8000))
61 if ((dsklen & 0x4000))
62 disk_write(track, (ciabprb >> 10) & 1, dskptr, (dsklen & 0x3fff) << 1);
64 disk_read(track, (ciabprb >> 10) & 1, dskptr, (dsklen & 0x3fff) << 1);
66 printf("read from INTREQR: game asks for finished read/write\n");
68 /* keep bit 2 set, so it indicated finished read/write */
76 void emulate_disk_write(uint32_t address, uint16_t value)
81 printf("selected side %d\n", (value >> 10) & 1);
83 if (((ciabprb >> 8) & 1) && !((value >> 8) & 1)) {
84 if (!((value >> 9) & 1)) {
89 printf("step forward to track %d\n", track);
96 printf("step backwards to track %d\n", track);
103 dskptr = (dskptr & 0x0000ffff) | (value << 16);
106 dskptr = (dskptr & 0xffff0000) | value;
108 printf("disk pointer set to 0x%06x\n", dskptr);
114 printf("DSKLEN: disk length set to 0x%04x, mode set to '%s', dma set to '%s'\n", dsklen & 0x3fff, (dsklen & 0x4000) ? "write" : "read", (dsklen & 0x8000) ? "on" : "off");
120 int get_disk_track(void)
123 printf("disk drive is at track %d\n", track);