src/mess/machine/rriot.c
| r3297 | r3298 | |
| 1 | | /********************************************************************** |
| 2 | | * RIOT emulation |
| 3 | | * |
| 4 | | * MOS ROM RAM IO Timer 6530 |
| 5 | | * |
| 6 | | * TODO: |
| 7 | | * - test if it works ;) |
| 8 | | * - change kim1 driver to use it |
| 9 | | * |
| 10 | | * used in chess champion mk2 |
| 11 | | * rockwell aim65 ? |
| 12 | | **********************************************************************/ |
| 13 | | |
| 14 | | #include "driver.h" |
| 15 | | #include "rriot.h" |
| 16 | | |
| 17 | | |
| 18 | | #define VERBOSE 0 |
| 19 | | |
| 20 | | #define LOG(a) do { if (VERBOSE) logerror a; } while (0) |
| 21 | | |
| 22 | | /* |
| 23 | | riot 6530 |
| 24 | | |
| 25 | | a0,a1 divide select (1,8,64,1024) |
| 26 | | a3 set means irq on |
| 27 | | |
| 28 | | io, timer selected |
| 29 | | xx000 Port A data |
| 30 | | xx001 Port A direction |
| 31 | | xx010 Port B data |
| 32 | | xx010 Port B direction |
| 33 | | |
| 34 | | xx1xx timer selected, irq disable |
| 35 | | x11xx t |
| 36 | | |
| 37 | | 6530 |
| 38 | | offset R/W short purpose |
| 39 | | 0 X DRA Data register A |
| 40 | | 1 X DDRA Data direction register A |
| 41 | | 2 X DRB Data register B |
| 42 | | 3 X DDRB Data direction register B |
| 43 | | 4 W CNT1T Count down from value, divide by 1, disable IRQ |
| 44 | | 5 W CNT8T Count down from value, divide by 8, disable IRQ |
| 45 | | 6 W CNT64T Count down from value, divide by 64, disable IRQ |
| 46 | | R LATCH Read current counter value, disable IRQ |
| 47 | | 7 W CNT1KT Count down from value, divide by 1024, disable IRQ |
| 48 | | R STATUS Read counter statzs, bit 7 = 1 means counter overflow |
| 49 | | 8 X DRA Data register A |
| 50 | | 9 X DDRA Data direction register A |
| 51 | | A X DRB Data register B |
| 52 | | B X DDRB Data direction register B |
| 53 | | C W CNT1I Count down from value, divide by 1, enable IRQ |
| 54 | | D W CNT8I Count down from value, divide by 8, enable IRQ |
| 55 | | E W CNT64I Count down from value, divide by 64, enable IRQ |
| 56 | | R LATCH Read current counter value, enable IRQ |
| 57 | | F W CNT1KI Count down from value, divide by 1024, enable IRQ |
| 58 | | R STATUS Read counter statzs, bit 7 = 1 means counter overflow |
| 59 | | */ |
| 60 | | |
| 61 | | typedef struct { |
| 62 | | const RRIOT_CONFIG *config; |
| 63 | | struct { |
| 64 | | UINT8 in, out, ddr; |
| 65 | | } port_a, port_b; |
| 66 | | |
| 67 | | UINT8 irqen; /* IRQ enabled ? */ |
| 68 | | enum { Delay1, Delay8, Delay64, Delay1024, TimerShot } state; |
| 69 | | attotime shottime; |
| 70 | | int irq; |
| 71 | | emu_timer *timer; /* timer callback */ |
| 72 | | } RRIOT; |
| 73 | | |
| 74 | | static RRIOT rriot[MAX_RRIOTS]= { {0} }; |
| 75 | | |
| 76 | | static TIMER_CALLBACK(rriot_timer_cb); |
| 77 | | |
| 78 | | void rriot_init(int nr, const RRIOT_CONFIG *config) |
| 79 | | { |
| 80 | | memset(&rriot[nr], 0, sizeof(rriot[nr])); |
| 81 | | rriot[nr].config = config; |
| 82 | | rriot[nr].timer = timer_alloc(rriot_timer_cb, NULL); |
| 83 | | |
| 84 | | LOG(("RRIOT - successfully initialised\n")); |
| 85 | | } |
| 86 | | |
| 87 | | void rriot_reset(int nr) |
| 88 | | { |
| 89 | | rriot[nr].port_a.ddr=0; |
| 90 | | if (rriot[nr].config->port_a.output) |
| 91 | | rriot[nr].config->port_a.output(nr,0xff); |
| 92 | | rriot[nr].port_b.ddr=0; |
| 93 | | if (rriot[nr].config->port_b.output) |
| 94 | | rriot[nr].config->port_b.output(nr,0xff); |
| 95 | | |
| 96 | | rriot[nr].irq=0;rriot[nr].irqen=0; |
| 97 | | if (rriot[nr].config->irq_callback) |
| 98 | | rriot[nr].config->irq_callback(nr, 0); |
| 99 | | } |
| 100 | | |
| 101 | | int rriot_r(int chip, int offset) |
| 102 | | { |
| 103 | | int data = 0xff; |
| 104 | | |
| 105 | | offset&=0xf; |
| 106 | | if (!(offset&4)) { // io part of chip |
| 107 | | switch( offset&3 ) |
| 108 | | { |
| 109 | | case 0: /* Data register A */ |
| 110 | | if( rriot[chip].config->port_a.input ) |
| 111 | | data = (*rriot[chip].config->port_a.input)(chip); |
| 112 | | /* mask input bits and combine with output bits */ |
| 113 | | data = (data & ~rriot[chip].port_a.ddr) | (rriot[chip].port_a.out & rriot[chip].port_a.ddr); |
| 114 | | LOG(("rriot(%d) DRA read : $%02x\n", chip, data)); |
| 115 | | break; |
| 116 | | case 1: /* Data direction register A */ |
| 117 | | data = rriot[chip].port_a.ddr; |
| 118 | | LOG(("rriot(%d) DDRA read : $%02x\n", chip, data)); |
| 119 | | break; |
| 120 | | case 2: /* Data register B */ |
| 121 | | if( rriot[chip].config->port_b.input ) |
| 122 | | data = (*rriot[chip].config->port_b.input)(chip); |
| 123 | | /* mask input bits and combine with output bits */ |
| 124 | | data = (data & ~rriot[chip].port_b.ddr) | (rriot[chip].port_b.out & rriot[chip].port_b.ddr); |
| 125 | | // LOG(("rriot(%d) DRB read : $%02x\n", chip, data)); |
| 126 | | break; |
| 127 | | case 3: /* Data direction register B */ |
| 128 | | data = rriot[chip].port_b.ddr; |
| 129 | | LOG(("rriot(%d) DDRB read : $%02x\n", chip, data)); |
| 130 | | break; |
| 131 | | } |
| 132 | | } else { // timer part of chip |
| 133 | | switch (offset&1) { |
| 134 | | case 0: /* Timer count read */ |
| 135 | | switch (rriot[chip].state) { |
| 136 | | case Delay1: |
| 137 | | data = attotime_mul(timer_timeleft(rriot[chip].timer), rriot[chip].config->baseclock).seconds; |
| 138 | | break; |
| 139 | | case Delay8: |
| 140 | | data = attotime_mul(timer_timeleft(rriot[chip].timer), rriot[chip].config->baseclock).seconds>>3; |
| 141 | | break; |
| 142 | | case Delay64: |
| 143 | | data = attotime_mul(timer_timeleft(rriot[chip].timer), rriot[chip].config->baseclock).seconds>>6; |
| 144 | | break; |
| 145 | | case Delay1024: |
| 146 | | data = attotime_mul(timer_timeleft(rriot[chip].timer), rriot[chip].config->baseclock).seconds>>10; |
| 147 | | break; |
| 148 | | case TimerShot: |
| 149 | | data=255- attotime_mul(attotime_sub(timer_get_time(), rriot[chip].shottime), rriot[chip].config->baseclock).seconds; |
| 150 | | if (data <0 ) data=0; |
| 151 | | break; |
| 152 | | } |
| 153 | | if( rriot[chip].irqen&&rriot[chip].irq ) /* with IRQ? */ |
| 154 | | { |
| 155 | | if( rriot[chip].config->irq_callback ) |
| 156 | | (*rriot[chip].config->irq_callback)(chip, 0); |
| 157 | | } |
| 158 | | rriot[chip].irq=0; |
| 159 | | break; |
| 160 | | case 1: /* Timer status read */ |
| 161 | | data = rriot[chip].irq?0x80:0; |
| 162 | | LOG(("riot(%d) STAT read : $%02x%s\n", chip, data, (char*)((offset & 8) ? " (IRQ)":" "))); |
| 163 | | break; |
| 164 | | } |
| 165 | | // problem when restarting with read the timer!? |
| 166 | | rriot[chip].irqen = (offset & 8) ? 1 : 0; |
| 167 | | } |
| 168 | | return data; |
| 169 | | } |
| 170 | | |
| 171 | | static TIMER_CALLBACK(rriot_timer_cb) |
| 172 | | { |
| 173 | | int chip = param; |
| 174 | | LOG(("rriot(%d) timer expired\n", chip)); |
| 175 | | rriot[chip].irq=1; |
| 176 | | rriot[chip].state=TimerShot; |
| 177 | | rriot[chip].shottime=timer_get_time(); |
| 178 | | if( rriot[chip].irqen ) /* with IRQ? */ |
| 179 | | { |
| 180 | | if( rriot[chip].config->irq_callback ) |
| 181 | | (*rriot[chip].config->irq_callback)(chip, 1); |
| 182 | | } |
| 183 | | } |
| 184 | | |
| 185 | | void rriot_w(int chip, int offset, int data) |
| 186 | | { |
| 187 | | offset&=0xf; |
| 188 | | if (!(offset&4)) { |
| 189 | | switch( offset&3 ) |
| 190 | | { |
| 191 | | case 0: /* Data register A */ |
| 192 | | LOG(("rriot(%d) DRA write: $%02x\n", chip, data)); |
| 193 | | rriot[chip].port_a.out = data; |
| 194 | | if( rriot[chip].config->port_a.output ) |
| 195 | | (*rriot[chip].config->port_a.output)(chip,data); |
| 196 | | break; |
| 197 | | case 1: /* Data direction register A */ |
| 198 | | LOG(("rriot(%d) DDRA write: $%02x\n", chip, data)); |
| 199 | | rriot[chip].port_a.ddr = data; |
| 200 | | break; |
| 201 | | case 2: /* Data register B */ |
| 202 | | // LOG(("rriot(%d) DRB write: $%02x\n", chip, data)); |
| 203 | | rriot[chip].port_b.out = data; |
| 204 | | if( rriot[chip].config->port_b.output ) |
| 205 | | (*rriot[chip].config->port_b.output)(chip,data); |
| 206 | | break; |
| 207 | | case 3: /* Data direction register B */ |
| 208 | | LOG(("rriot(%d) DDRB write: $%02x\n", chip, data)); |
| 209 | | rriot[chip].port_b.ddr = data; |
| 210 | | break; |
| 211 | | } |
| 212 | | } else { |
| 213 | | if( rriot[chip].irqen&&rriot[chip].irq ) /* with IRQ? */ |
| 214 | | { |
| 215 | | if( rriot[chip].config->irq_callback ) |
| 216 | | (*rriot[chip].config->irq_callback)(chip, 0); |
| 217 | | } |
| 218 | | rriot[chip].irqen = (offset & 8) ? 1 : 0; |
| 219 | | rriot[chip].irq =0; |
| 220 | | |
| 221 | | switch (offset&3) { |
| 222 | | case 0: /* Timer 1 start */ |
| 223 | | LOG(("rriot(%d) TMR1 write: $%02x%s\n", chip, data, (char*)((offset & 8) ? " (IRQ)":" "))); |
| 224 | | timer_adjust_oneshot(rriot[chip].timer, attotime_mul(ATTOTIME_IN_HZ(rriot[chip].config->baseclock), (data+1) ), chip); |
| 225 | | rriot[chip].state=Delay1; |
| 226 | | break; |
| 227 | | case 1: /* Timer 8 start */ |
| 228 | | LOG(("rriot(%d) TMR8 write: $%02x%s\n", chip, data, (char*)((offset & 8) ? " (IRQ)":" "))); |
| 229 | | timer_adjust_oneshot(rriot[chip].timer, attotime_mul(ATTOTIME_IN_HZ(rriot[chip].config->baseclock), (data+1) * 8 ), chip); |
| 230 | | rriot[chip].state=Delay8; |
| 231 | | break; |
| 232 | | case 2: /* Timer 64 start */ |
| 233 | | LOG(("rriot(%d) TMR64 write: $%02x%s\n", chip, data, (char*)((offset & 8) ? " (IRQ)":" "))); |
| 234 | | // LOG(("rriot(%d) TMR64 write: time is $%f\n", chip, (double)(64.0 * (data + 1) / rriot[chip].clock))); |
| 235 | | timer_adjust_oneshot(rriot[chip].timer, attotime_mul(ATTOTIME_IN_HZ(rriot[chip].config->baseclock), (data+1) * 64 ), chip); |
| 236 | | rriot[chip].state=Delay64; |
| 237 | | break; |
| 238 | | case 3: /* Timer 1024 start */ |
| 239 | | LOG(("rriot(%d) TMR1K write: $%02x%s\n", chip, data, (char*)((offset & 8) ? " (IRQ)":" "))); |
| 240 | | timer_adjust_oneshot(rriot[chip].timer, attotime_mul(ATTOTIME_IN_HZ(rriot[chip].config->baseclock), (data+1) * 1024 ), chip); |
| 241 | | rriot[chip].state=Delay1024; |
| 242 | | break; |
| 243 | | } |
| 244 | | } |
| 245 | | } |
| 246 | | |
| 247 | | static int rriot_a_r(int chip) |
| 248 | | { |
| 249 | | int data; |
| 250 | | if (rriot[chip].config->port_a.input) |
| 251 | | data = rriot[chip].config->port_a.input(chip); |
| 252 | | else |
| 253 | | data = 0xff; |
| 254 | | data &= ~rriot[chip].port_a.ddr; |
| 255 | | data |= (rriot[chip].port_a.ddr&rriot[chip].port_a.out); |
| 256 | | return data; |
| 257 | | } |
| 258 | | |
| 259 | | static int rriot_b_r(int chip) |
| 260 | | { |
| 261 | | int data; |
| 262 | | if (rriot[chip].config->port_b.input) |
| 263 | | data = rriot[chip].config->port_b.input(chip); |
| 264 | | else |
| 265 | | data = 0xff; |
| 266 | | data &= ~rriot[chip].port_b.ddr; |
| 267 | | data |= (rriot[chip].port_b.ddr&rriot[chip].port_b.out); |
| 268 | | return data; |
| 269 | | } |
| 270 | | |
| 271 | | static void rriot_a_w(int chip, int data) |
| 272 | | { |
| 273 | | #if 0 |
| 274 | | rriot[chip].port_a.in = data; |
| 275 | | #endif |
| 276 | | } |
| 277 | | |
| 278 | | static void rriot_b_w(int chip, int data) |
| 279 | | { |
| 280 | | |
| 281 | | } |
| 282 | | |
| 283 | | READ8_HANDLER ( rriot_0_r ) { return rriot_r(0,offset); } |
| 284 | | WRITE8_HANDLER ( rriot_0_w ) { rriot_w(0,offset,data); } |
| 285 | | READ8_HANDLER ( rriot_1_r ) { return rriot_r(1,offset); } |
| 286 | | WRITE8_HANDLER ( rriot_1_w ) { rriot_w(1,offset,data); } |
| 287 | | READ8_HANDLER ( rriot_2_r ) { return rriot_r(2,offset); } |
| 288 | | WRITE8_HANDLER ( rriot_2_w ) { rriot_w(2,offset,data); } |
| 289 | | READ8_HANDLER ( rriot_3_r ) { return rriot_r(3,offset); } |
| 290 | | WRITE8_HANDLER ( rriot_3_w ) { rriot_w(3,offset,data); } |
| 291 | | |
| 292 | | READ8_HANDLER( rriot_0_a_r ) { return rriot_a_r(0); } |
| 293 | | READ8_HANDLER( rriot_1_a_r ) { return rriot_a_r(1); } |
| 294 | | READ8_HANDLER( rriot_2_a_r ) { return rriot_a_r(2); } |
| 295 | | READ8_HANDLER( rriot_3_a_r ) { return rriot_a_r(3); } |
| 296 | | |
| 297 | | READ8_HANDLER( rriot_0_b_r ) { return rriot_b_r(0); } |
| 298 | | READ8_HANDLER( rriot_1_b_r ) { return rriot_b_r(1); } |
| 299 | | READ8_HANDLER( rriot_2_b_r ) { return rriot_b_r(2); } |
| 300 | | READ8_HANDLER( rriot_3_b_r ) { return rriot_b_r(3); } |
| 301 | | |
| 302 | | WRITE8_HANDLER( rriot_0_a_w ) { rriot_a_w(0,data); } |
| 303 | | WRITE8_HANDLER( rriot_1_a_w ) { rriot_a_w(1,data); } |
| 304 | | WRITE8_HANDLER( rriot_2_a_w ) { rriot_a_w(2,data); } |
| 305 | | WRITE8_HANDLER( rriot_3_a_w ) { rriot_a_w(3,data); } |
| 306 | | |
| 307 | | WRITE8_HANDLER( rriot_0_b_w ) { rriot_b_w(0,data); } |
| 308 | | WRITE8_HANDLER( rriot_1_b_w ) { rriot_b_w(1,data); } |
| 309 | | WRITE8_HANDLER( rriot_2_b_w ) { rriot_b_w(2,data); } |
| 310 | | WRITE8_HANDLER( rriot_3_b_w ) { rriot_b_w(3,data); } |
| 311 | | |
| 312 | | |
src/mess/machine/rriot.h
| r3297 | r3298 | |
| 1 | | #ifndef RIOT_H |
| 2 | | #define RIOT_H |
| 3 | | |
| 4 | | /* mos rom ram io timer 6530 */ |
| 5 | | |
| 6 | | /* ram and rom areas are not handled in this rriot compoment */ |
| 7 | | |
| 8 | | /* |
| 9 | | internal 64 byte ram |
| 10 | | internal 1024 byte rom |
| 11 | | inputs and output |
| 12 | | timer |
| 13 | | interrupt logic |
| 14 | | logic to connect up to 7 6530 without additional address decoding logic |
| 15 | | |
| 16 | | 1kb rom selection |
| 17 | | a0..a9, |
| 18 | | rs0, cs1, cs2 mask programmed! |
| 19 | | |
| 20 | | 64byte ram selection |
| 21 | | a0..a5 |
| 22 | | rs0, cs1, cs2, a6, a7, a8, a9 mask programmed! |
| 23 | | |
| 24 | | io, timer selection |
| 25 | | a0..a3 (a4,a5 don't care) |
| 26 | | rs0, cs1, cs2, a6, a7, a8, a9 mask programmed! |
| 27 | | (a2=0 io, a3 don't care) |
| 28 | | a2=1 timer, a3 interrupt enable) |
| 29 | | |
| 30 | | standard configurations! CS2(a12) CS1(a11) rs0(a10) |
| 31 | | chip subtype 1: rom 0x0400, ram 0x000, io 0x200 |
| 32 | | chip subtype 2: rom 0x0800, ram 0x040, io 0x240 |
| 33 | | chip subtype 3: rom 0x0c00, ram 0x080, io 0x280 |
| 34 | | chip subtype 4: rom 0x1000, ram 0x0c0, io 0x2c0 |
| 35 | | chip subtype 5: rom 0x1400, ram 0x100, io 0x300 |
| 36 | | chip subtype 6: rom 0x1800, ram 0x140, io 0x340 |
| 37 | | chip subtype 7: rom 0x1c00, ram 0x180, io 0x380 |
| 38 | | |
| 39 | | 5V 1 40 PA1 |
| 40 | | PA0 2 39 PA2 |
| 41 | | CLK 3 38 PA3 |
| 42 | | RS0 4 37 PA4 |
| 43 | | A9 5 36 PA5 |
| 44 | | A8 6 35 PA6 |
| 45 | | A7 7 34 PA7 |
| 46 | | A6 8 33 D0 |
| 47 | | R /W 9 32 D1 |
| 48 | | A5 10 31 D2 |
| 49 | | A4 11 30 D3 |
| 50 | | A3 12 29 D4 |
| 51 | | A2 13 28 D5 |
| 52 | | A1 14 27 D6 |
| 53 | | A0 15 26 D7 |
| 54 | | /RES 16 25 PB0 |
| 55 | | PB7 17 24 PB1 |
| 56 | | PB6 18 23 PB2 |
| 57 | | PB5 19 22 PB3 |
| 58 | | GND 20 21 PB4 |
| 59 | | |
| 60 | | D0..7 data bus |
| 61 | | A0..9 address bus |
| 62 | | R /W read or /write |
| 63 | | RS0 rom select |
| 64 | | |
| 65 | | |
| 66 | | /RES reset |
| 67 | | CLK (phi2) clock for timer |
| 68 | | PA0..7, PB0..8 input or output (software selectable) |
| 69 | | |
| 70 | | PB7 could be configured as /IRQ line |
| 71 | | PB6,PB5 could be configured as CS1,CS2 (mask programmed with the rom!) |
| 72 | | |
| 73 | | dumping suggestions |
| 74 | | wire an adapter for an 2764 eprom, so it is readable with many eprom burners |
| 75 | | read the complete 8kbyte data |
| 76 | | extract the positions from the dump |
| 77 | | |
| 78 | | */ |
| 79 | | |
| 80 | | |
| 81 | | /* |
| 82 | | mos 6532 |
| 83 | | chip also contains 128 bytes ram (own chip select line) |
| 84 | | no rom |
| 85 | | separate irq output |
| 86 | | some significant differences, so unique component |
| 87 | | */ |
| 88 | | |
| 89 | | #ifdef __cplusplus |
| 90 | | extern "C" { |
| 91 | | #endif |
| 92 | | |
| 93 | | #define MAX_RRIOTS 4 |
| 94 | | |
| 95 | | typedef struct { |
| 96 | | int baseclock; |
| 97 | | struct { |
| 98 | | int (*input)(int chip); |
| 99 | | void (*output)(int chip, int value); |
| 100 | | } port_a, port_b; |
| 101 | | void (*irq_callback)(int chip, int level); |
| 102 | | } RRIOT_CONFIG; |
| 103 | | |
| 104 | | /* This has to be called from a driver at startup */ |
| 105 | | void rriot_init(int nr, const RRIOT_CONFIG *riot); |
| 106 | | |
| 107 | | int rriot_r(int chip, int offs); |
| 108 | | void rriot_w(int chip, int offs, int data); |
| 109 | | |
| 110 | | void rriot_reset(int nr); |
| 111 | | |
| 112 | | READ8_HANDLER ( rriot_0_r ); |
| 113 | | WRITE8_HANDLER ( rriot_0_w ); |
| 114 | | READ8_HANDLER ( rriot_1_r ); |
| 115 | | WRITE8_HANDLER ( rriot_1_w ); |
| 116 | | READ8_HANDLER ( rriot_2_r ); |
| 117 | | WRITE8_HANDLER ( rriot_2_w ); |
| 118 | | READ8_HANDLER ( rriot_3_r ); |
| 119 | | WRITE8_HANDLER ( rriot_3_w ); |
| 120 | | |
| 121 | | READ8_HANDLER( rriot_0_a_r ); |
| 122 | | READ8_HANDLER( rriot_1_a_r ); |
| 123 | | READ8_HANDLER( rriot_2_a_r ); |
| 124 | | READ8_HANDLER( rriot_3_a_r ); |
| 125 | | |
| 126 | | WRITE8_HANDLER( rriot_0_a_w ); |
| 127 | | WRITE8_HANDLER( rriot_1_a_w ); |
| 128 | | WRITE8_HANDLER( rriot_2_a_w ); |
| 129 | | WRITE8_HANDLER( rriot_3_a_w ); |
| 130 | | |
| 131 | | READ8_HANDLER( rriot_0_b_r ); |
| 132 | | READ8_HANDLER( rriot_1_b_r ); |
| 133 | | READ8_HANDLER( rriot_2_b_r ); |
| 134 | | READ8_HANDLER( rriot_3_b_r ); |
| 135 | | |
| 136 | | WRITE8_HANDLER( rriot_0_b_w ); |
| 137 | | WRITE8_HANDLER( rriot_1_b_w ); |
| 138 | | WRITE8_HANDLER( rriot_2_b_w ); |
| 139 | | WRITE8_HANDLER( rriot_3_b_w ); |
| 140 | | |
| 141 | | #ifdef __cplusplus |
| 142 | | } |
| 143 | | #endif |
| 144 | | |
| 145 | | #endif |