src/mess/drivers/fm7.c
| r4867 | r4868 | |
| 31 | 31 | #include "cpu/m6809/m6809.h" |
| 32 | 32 | #include "sound/ay8910.h" |
| 33 | 33 | |
| 34 | // Interrupt flags |
| 35 | #define IRQ_FLAG_KEY 0x01 |
| 36 | #define IRQ_FLAG_PRINTER 0x02 |
| 37 | #define IRQ_FLAG_TIMER 0x04 |
| 38 | #define IRQ_FLAG_UNKNOWN 0x08 |
| 39 | // the following are not read in port 0xfd03 |
| 40 | #define IRQ_FLAG_MFD 0x10 |
| 41 | #define IRQ_FLAG_TXRDY 0x20 |
| 42 | #define IRQ_FLAG_RXRDY 0x40 |
| 43 | #define IRQ_FLAG_SYNDET 0x80 |
| 44 | |
| 34 | 45 | UINT8* shared_ram; |
| 46 | UINT8* fm7_video_ram; |
| 47 | static UINT8 irq_flags; // active IRQ flags |
| 48 | static UINT8 irq_mask; // IRQ mask |
| 49 | emu_timer* fm7_timer; // main timer, triggered every 2.0345ms? |
| 50 | static UINT8 sub_busy; |
| 51 | static UINT8 basic_rom_en; |
| 52 | static UINT8 fm7_attn_irq; |
| 35 | 53 | |
| 54 | /* |
| 55 | * I/O port 0xfd02 |
| 56 | * |
| 57 | * On read: returns cassette data (bit 7) and printer status (bits 0-5) |
| 58 | * On write: sets IRQ masks |
| 59 | * bit 0 - keypress |
| 60 | * bit 1 - printer |
| 61 | * bit 2 - timer |
| 62 | * bit 3 - not used |
| 63 | * bit 4 - MFD |
| 64 | * bit 5 - TXRDY |
| 65 | * bit 6 - RXRDY |
| 66 | * bit 7 - SYNDET |
| 67 | * |
| 68 | */ |
| 69 | WRITE8_HANDLER( fm7_irq_mask_w ) |
| 70 | { |
| 71 | irq_mask = data; |
| 72 | logerror("IRQ mask set: 0x%02x\n",irq_mask); |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * I/O port 0xfd03 |
| 77 | * |
| 78 | * On read: returns which IRQ is currently active (typically read by IRQ handler) |
| 79 | * bit 0 - keypress |
| 80 | * bit 1 - printer |
| 81 | * bit 2 - timer |
| 82 | * bit 3 - ??? |
| 83 | * On write: Buzzer/Speaker On/Off |
| 84 | * bit 0 - speaker on/off |
| 85 | * bit 1 - ??buzzer on/off |
| 86 | * bit 2 - ??buzzer on/off |
| 87 | */ |
| 88 | READ8_HANDLER( fm7_irq_cause_r ) |
| 89 | { |
| 90 | UINT8 ret = irq_flags; |
| 91 | |
| 92 | irq_flags = 0; // clear flags |
| 93 | logerror("IRQ flags read: 0x%02x\n",ret); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 36 | 97 | READ8_HANDLER( mainmem_r ) |
| 37 | 98 | { |
| 38 | 99 | UINT8* RAM = memory_region(space->machine,"maincpu"); |
| r4867 | r4868 | |
| 73 | 134 | |
| 74 | 135 | READ8_HANDLER( fm7_fd04_r ) |
| 75 | 136 | { |
| 137 | UINT8 ret = 0xff; |
| 138 | |
| 139 | if(fm7_attn_irq != 0) |
| 140 | { |
| 141 | ret &= ~0x01; |
| 142 | fm7_attn_irq = 0; |
| 143 | } |
| 144 | return ret; |
| 145 | } |
| 146 | /* |
| 147 | * Sub-CPU interface (port 0xfd05) |
| 148 | * |
| 149 | * Read: |
| 150 | * bit 7: Sub-CPU busy |
| 151 | * bit 0: EXTDET (?) |
| 152 | * Write: |
| 153 | * bit 7: Sub-CPU halt |
| 154 | * bit 6: Sub-CPU cancel IRQ |
| 155 | */ |
| 156 | |
| 157 | READ8_HANDLER( fm7_subintf_r ) |
| 158 | { |
| 159 | return sub_busy & 0x80; |
| 160 | } |
| 161 | |
| 162 | WRITE8_HANDLER( fm7_subintf_w ) |
| 163 | { |
| 164 | cputag_set_input_line(space->machine,"sub",INPUT_LINE_HALT,(data & 0x80) ? ASSERT_LINE : CLEAR_LINE); |
| 165 | if(data & 0x40) |
| 166 | cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,ASSERT_LINE); |
| 167 | } |
| 168 | |
| 169 | READ8_HANDLER( fm7_sub_busyflag_r ) |
| 170 | { |
| 171 | sub_busy = 0x00; |
| 172 | return 0x00; |
| 173 | } |
| 174 | |
| 175 | WRITE8_HANDLER( fm7_sub_busyflag_w ) |
| 176 | { |
| 177 | sub_busy = 0x80; |
| 178 | } |
| 179 | |
| 180 | READ8_HANDLER( fm7_rom_en_r ) |
| 181 | { |
| 182 | UINT8* RAM = memory_region(space->machine,"maincpu"); |
| 183 | |
| 184 | basic_rom_en = 1; |
| 185 | memory_set_bankptr(space->machine,1,RAM+0x38000); |
| 186 | logerror("BASIC ROM enabled\n"); |
| 187 | return 0x00; |
| 188 | } |
| 189 | |
| 190 | WRITE8_HANDLER( fm7_rom_en_w ) |
| 191 | { |
| 192 | UINT8* RAM = memory_region(space->machine,"maincpu"); |
| 193 | |
| 194 | basic_rom_en = 0; |
| 195 | memory_set_bankptr(space->machine,1,RAM+0x8000); |
| 196 | logerror("BASIC ROM disabled\n"); |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Sub-CPU port 0xd402 |
| 201 | * Read-only: Acknowledge Cancel IRQ |
| 202 | */ |
| 203 | READ8_HANDLER( fm7_cancel_ack ) |
| 204 | { |
| 205 | cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,CLEAR_LINE); |
| 206 | return 0x00; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Reading from 0xd404 (sub-CPU) causes an "Attention" FIRQ on the main CPU |
| 211 | */ |
| 212 | READ8_HANDLER( fm7_attn_irq_r ) |
| 213 | { |
| 214 | fm7_attn_irq = 1; |
| 215 | cputag_set_input_line(space->machine,"maincpu",M6809_FIRQ_LINE,ASSERT_LINE); |
| 76 | 216 | return 0xff; |
| 77 | 217 | } |
| 78 | 218 | |
| 219 | static TIMER_CALLBACK( fm7_timer_irq ) |
| 220 | { |
| 221 | if(~irq_mask & IRQ_FLAG_TIMER) |
| 222 | { |
| 223 | irq_flags |= IRQ_FLAG_TIMER; |
| 224 | cputag_set_input_line(machine,"maincpu",M6809_IRQ_LINE,ASSERT_LINE); |
| 225 | } |
| 226 | } |
| 79 | 227 | |
| 228 | static IRQ_CALLBACK(fm7_irq_ack) |
| 229 | { |
| 230 | cputag_set_input_line(device->machine,"maincpu",irqline,CLEAR_LINE); |
| 231 | return -1; |
| 232 | } |
| 233 | |
| 234 | static IRQ_CALLBACK(fm7_sub_irq_ack) |
| 235 | { |
| 236 | cputag_set_input_line(device->machine,"sub",irqline,CLEAR_LINE); |
| 237 | return -1; |
| 238 | } |
| 239 | |
| 80 | 240 | /* |
| 81 | 241 | 0000 - 7FFF: (RAM) BASIC working area, user's area |
| 82 | 242 | 8000 - FBFF: (ROM) F-BASIC ROM |
| r4867 | r4868 | |
| 88 | 248 | // The FM-7 has only 64kB RAM, so we'll worry about banking when we do the later models |
| 89 | 249 | static ADDRESS_MAP_START( fm7_mem, ADDRESS_SPACE_PROGRAM, 8 ) |
| 90 | 250 | AM_RANGE(0x0000,0x7fff) AM_READWRITE(mainmem_r,mainmem_w) |
| 91 | | AM_RANGE(0x8000,0xfbff) AM_ROM // also F-BASIC ROM, when enabled |
| 251 | AM_RANGE(0x8000,0xfbff) AM_RAMBANK(1) // also F-BASIC ROM, when enabled |
| 92 | 252 | AM_RANGE(0xfc00,0xfc7f) AM_RAM |
| 93 | 253 | AM_RANGE(0xfc80,0xfcff) AM_READWRITE(shared_r,shared_w) // shared RAM with sub-CPU |
| 94 | 254 | // I/O space (FD00-FDFF) |
| 255 | AM_RANGE(0xfd02,0xfd02) AM_WRITE(fm7_irq_mask_w) // IRQ mask |
| 256 | AM_RANGE(0xfd03,0xfd03) AM_READ(fm7_irq_cause_r) // IRQ flags |
| 95 | 257 | AM_RANGE(0xfd04,0xfd04) AM_READ(fm7_fd04_r) |
| 258 | AM_RANGE(0xfd05,0xfd05) AM_READWRITE(fm7_subintf_r,fm7_subintf_w) |
| 96 | 259 | AM_RANGE(0xfd0d,0xfd0d) AM_DEVWRITE("psg",ay8910_address_w) |
| 97 | 260 | AM_RANGE(0xfd0e,0xfd0e) AM_DEVREADWRITE("psg",ay8910_r,ay8910_data_w) |
| 261 | AM_RANGE(0xfd0f,0xfd0f) AM_READWRITE(fm7_rom_en_r,fm7_rom_en_w) |
| 98 | 262 | // Boot ROM |
| 99 | 263 | AM_RANGE(0xfe00,0xffef) AM_ROM AM_REGION("basic",0x0000) |
| 100 | 264 | AM_RANGE(0xfff0,0xffff) AM_READWRITE(vector_r,vector_w) |
| r4867 | r4868 | |
| 110 | 274 | FFF0 - FFFF: Interrupt vector table |
| 111 | 275 | */ |
| 112 | 276 | |
| 113 | | UINT8 *fm7_video_ram; |
| 114 | 277 | static ADDRESS_MAP_START( fm7_sub_mem, ADDRESS_SPACE_PROGRAM, 8 ) |
| 115 | 278 | AM_RANGE(0x0000,0xbfff) AM_RAM AM_BASE(&fm7_video_ram) // VRAM |
| 116 | 279 | AM_RANGE(0xc000,0xcfff) AM_RAM // Console RAM |
| 117 | 280 | AM_RANGE(0xd000,0xd37f) AM_RAM // Work RAM |
| 118 | 281 | AM_RANGE(0xd380,0xd3ff) AM_READWRITE(shared_r,shared_w) // shared RAM |
| 119 | 282 | // I/O space (D400-D7FF) |
| 283 | AM_RANGE(0xd402,0xd402) AM_READ(fm7_cancel_ack) |
| 284 | AM_RANGE(0xd404,0xd404) AM_READ(fm7_attn_irq_r) |
| 285 | AM_RANGE(0xd40a,0xd40a) AM_READWRITE(fm7_sub_busyflag_r,fm7_sub_busyflag_w) |
| 120 | 286 | AM_RANGE(0xd800,0xffff) AM_ROM |
| 121 | 287 | ADDRESS_MAP_END |
| 122 | 288 | |
| r4867 | r4868 | |
| 136 | 302 | static DRIVER_INIT(fm7) |
| 137 | 303 | { |
| 138 | 304 | shared_ram = auto_alloc_array(machine,UINT8,0x80); |
| 305 | fm7_timer = timer_alloc(machine,fm7_timer_irq,NULL); |
| 306 | cpu_set_irq_callback(cputag_get_cpu(machine,"maincpu"),fm7_irq_ack); |
| 307 | cpu_set_irq_callback(cputag_get_cpu(machine,"sub"),fm7_sub_irq_ack); |
| 139 | 308 | } |
| 140 | 309 | |
| 141 | 310 | static MACHINE_START(fm7) |
| r4867 | r4868 | |
| 152 | 321 | |
| 153 | 322 | static MACHINE_RESET(fm7) |
| 154 | 323 | { |
| 324 | UINT8* RAM = memory_region(machine,"maincpu"); |
| 325 | |
| 326 | timer_adjust_periodic(fm7_timer,attotime_zero,0,ATTOTIME_IN_USEC(2034)); |
| 327 | irq_mask = 0xff; |
| 328 | irq_flags = 0x00; |
| 329 | fm7_attn_irq = 0; |
| 330 | sub_busy = 0x80; // busy at reset |
| 331 | basic_rom_en = 1; // enabled at reset |
| 332 | memory_set_bankptr(machine,1,RAM+0x38000); |
| 155 | 333 | } |
| 156 | 334 | |
| 157 | 335 | static VIDEO_START( fm7 ) |
| r4867 | r4868 | |
| 265 | 443 | /* ROM definition */ |
| 266 | 444 | ROM_START( fm7 ) |
| 267 | 445 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 268 | | ROM_LOAD( "fbasic30.rom", 0x8000, 0x7c00, CRC(a96d19b6) SHA1(8d5f0cfe7e0d39bf2ab7e4c798a13004769c28b2) ) |
| 446 | ROM_LOAD( "fbasic30.rom", 0x38000, 0x7c00, CRC(a96d19b6) SHA1(8d5f0cfe7e0d39bf2ab7e4c798a13004769c28b2) ) |
| 269 | 447 | |
| 270 | 448 | ROM_REGION( 0x20000, "sub", 0 ) |
| 271 | 449 | ROM_LOAD( "subsys_c.rom", 0xd800, 0x2800, CRC(24cec93f) SHA1(50b7283db6fe1342c6063fc94046283f4feddc1c) ) |