~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/mess/machine/oric.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************************
2
 
 
3
 
    machine/oric.c
4
 
 
5
 
    Paul Cook
6
 
    Kev Thacker
7
 
 
8
 
    Thankyou to Fabrice Frances for his ORIC documentation which helped with this driver
9
 
    http://oric.ifrance.com/oric/
10
 
 
11
 
    TODO:
12
 
    - there are problems loading some .wav's. Try to fix these.
13
 
    - fix more graphics display problems
14
 
    - check the printer works
15
 
    - fix more disc drive/wd179x problems so more software will run
16
 
 
17
 
*********************************************************************/
18
 
 
19
 
 
20
 
#include <stdio.h>
21
 
#include "emu.h"
22
 
#include "includes/oric.h"
23
 
#include "machine/wd17xx.h"
24
 
#include "machine/6522via.h"
25
 
#include "machine/applefdc.h"
26
 
#include "machine/6551.h"
27
 
#include "machine/ctronics.h"
28
 
#include "imagedev/cassette.h"
29
 
#include "sound/ay8910.h"
30
 
#include "imagedev/flopdrv.h"
31
 
 
32
 
 
33
 
 
34
 
static const int enable_logging = 1;
35
 
 
36
 
 
37
 
/* ==0 if oric1 or oric atmos, !=0 if telestrat */
38
 
 
39
 
/* This does not exist in the real hardware. I have used it to
40
 
know which sources are interrupting */
41
 
/* bit 2 = telestrat 2nd via interrupt, 1 = microdisc interface,
42
 
0 = oric 1st via interrupt */
43
 
 
44
 
enum
45
 
{
46
 
        ORIC_FLOPPY_NONE,
47
 
        ORIC_FLOPPY_MFM_DISK,
48
 
        ORIC_FLOPPY_BASIC_DISK
49
 
};
50
 
 
51
 
/* type of disc interface connected to oric/oric atmos */
52
 
/* telestrat always has a microdisc interface */
53
 
enum
54
 
{
55
 
        ORIC_FLOPPY_INTERFACE_NONE = 0,
56
 
        ORIC_FLOPPY_INTERFACE_MICRODISC = 1,
57
 
        ORIC_FLOPPY_INTERFACE_JASMIN = 2,
58
 
        ORIC_FLOPPY_INTERFACE_APPLE2 = 3,
59
 
        ORIC_FLOPPY_INTERFACE_APPLE2_V2 = 4
60
 
};
61
 
 
62
 
/* called when ints are changed - cleared/set */
63
 
static void oric_refresh_ints(running_machine &machine)
64
 
{
65
 
        oric_state *state = machine.driver_data<oric_state>();
66
 
        /* telestrat has floppy hardware built-in! */
67
 
        if (state->m_is_telestrat==0)
68
 
        {
69
 
                /* oric 1 or oric atmos */
70
 
 
71
 
                /* if floppy disc hardware is disabled, do not allow interrupts from it */
72
 
                if ((input_port_read(machine, "FLOPPY") & 0x07) == ORIC_FLOPPY_INTERFACE_NONE)
73
 
                {
74
 
                        state->m_irqs &=~(1<<1);
75
 
                }
76
 
        }
77
 
 
78
 
        /* any irq set? */
79
 
        if ((state->m_irqs & 0x0f)!=0)
80
 
        {
81
 
                cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
82
 
        }
83
 
        else
84
 
        {
85
 
                cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
86
 
        }
87
 
}
88
 
 
89
 
 
90
 
 
91
 
/* index of keyboard line to scan */
92
 
/* sense result */
93
 
/* mask to read keys */
94
 
 
95
 
 
96
 
 
97
 
 
98
 
 
99
 
/* refresh keyboard sense */
100
 
static void oric_keyboard_sense_refresh(running_machine &machine)
101
 
{
102
 
        oric_state *state = machine.driver_data<oric_state>();
103
 
        /* The following assumes that if a 0 is written, it can be used to detect if any key
104
 
    has been pressed.. */
105
 
        /* for each bit that is 0, it combines it's pressed state with the pressed state so far */
106
 
 
107
 
        int i;
108
 
        unsigned char key_bit = 0;
109
 
 
110
 
        /* what if data is 0, can it sense if any of the keys on a line are pressed? */
111
 
        int input_port_data;
112
 
        static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" };
113
 
 
114
 
        input_port_data = input_port_read(machine, keynames[state->m_keyboard_line]);
115
 
 
116
 
        /* go through all bits in line */
117
 
        for (i=0; i<8; i++)
118
 
        {
119
 
                /* sense this bit? */
120
 
                if (((~state->m_keyboard_mask) & (1<<i)) != 0)
121
 
                {
122
 
                        /* is key pressed? */
123
 
                        if (input_port_data & (1<<i))
124
 
                        {
125
 
                                /* yes */
126
 
                                key_bit |= 1;
127
 
                        }
128
 
                }
129
 
        }
130
 
 
131
 
        /* clear sense result */
132
 
        state->m_key_sense_bit = 0;
133
 
        /* any keys pressed on this line? */
134
 
        if (key_bit!=0)
135
 
        {
136
 
                /* set sense result */
137
 
                state->m_key_sense_bit = (1<<3);
138
 
        }
139
 
}
140
 
 
141
 
 
142
 
/* this is executed when a write to psg port a is done */
143
 
WRITE8_HANDLER (oric_psg_porta_write)
144
 
{
145
 
        oric_state *state = space->machine().driver_data<oric_state>();
146
 
        state->m_keyboard_mask = data;
147
 
}
148
 
 
149
 
 
150
 
/* PSG control pins */
151
 
/* bit 1 = BDIR state */
152
 
/* bit 0 = BC1 state */
153
 
 
154
 
/* this port is also used to read printer data */
155
 
static READ8_DEVICE_HANDLER ( oric_via_in_a_func )
156
 
{
157
 
        oric_state *state = device->machine().driver_data<oric_state>();
158
 
        address_space *space = device->machine().device( "maincpu")->memory().space( AS_PROGRAM );
159
 
 
160
 
        /*logerror("port a read\r\n"); */
161
 
 
162
 
        /* access psg? */
163
 
        if (state->m_psg_control!=0)
164
 
        {
165
 
                /* if psg is in read register state return reg data */
166
 
                if (state->m_psg_control==0x01)
167
 
                {
168
 
                        return ay8910_r(space->machine().device("ay8912"), 0);
169
 
                }
170
 
 
171
 
                /* return high-impedance */
172
 
                return 0x0ff;
173
 
        }
174
 
 
175
 
        /* correct?? */
176
 
        return state->m_via_port_a_data;
177
 
}
178
 
 
179
 
static READ8_DEVICE_HANDLER ( oric_via_in_b_func )
180
 
{
181
 
        oric_state *state = device->machine().driver_data<oric_state>();
182
 
        int data;
183
 
 
184
 
        oric_keyboard_sense_refresh(device->machine());
185
 
 
186
 
        data = state->m_key_sense_bit;
187
 
        data |= state->m_keyboard_line & 0x07;
188
 
 
189
 
        return data;
190
 
}
191
 
 
192
 
 
193
 
/* read/write data depending on state of bdir, bc1 pins and data output to psg */
194
 
static void oric_psg_connection_refresh(running_machine &machine)
195
 
{
196
 
        oric_state *state = machine.driver_data<oric_state>();
197
 
        if (state->m_psg_control!=0)
198
 
        {
199
 
                switch (state->m_psg_control)
200
 
                {
201
 
                        /* PSG inactive */
202
 
                        case 0:
203
 
                        break;
204
 
                        /* read register data */
205
 
                        case 1:
206
 
                        {
207
 
                                //state->m_via_port_a_data = ay8910_read_port_0_r(space, 0);
208
 
                        }
209
 
                        break;
210
 
                        /* write register data */
211
 
                        case 2:
212
 
                        {
213
 
                                device_t *ay8912 = machine.device("ay8912");
214
 
                                ay8910_data_w(ay8912, 0, state->m_via_port_a_data);
215
 
                        }
216
 
                        break;
217
 
                        /* write register index */
218
 
                        case 3:
219
 
                        {
220
 
                                device_t *ay8912 = machine.device("ay8912");
221
 
                                ay8910_address_w(ay8912, 0, state->m_via_port_a_data);
222
 
                        }
223
 
                        break;
224
 
 
225
 
                        default:
226
 
                                break;
227
 
                }
228
 
 
229
 
                return;
230
 
        }
231
 
}
232
 
 
233
 
static WRITE8_DEVICE_HANDLER ( oric_via_out_a_func )
234
 
{
235
 
        oric_state *state = device->machine().driver_data<oric_state>();
236
 
        state->m_via_port_a_data = data;
237
 
 
238
 
        oric_psg_connection_refresh(device->machine());
239
 
 
240
 
 
241
 
        if (state->m_psg_control==0)
242
 
        {
243
 
                /* if psg not selected, write to printer */
244
 
                device_t *printer = device->machine().device("centronics");
245
 
                centronics_data_w(printer, 0, data);
246
 
        }
247
 
}
248
 
 
249
 
/*
250
 
PB0..PB2
251
 
 keyboard lines-demultiplexer line 7
252
 
 
253
 
PB3
254
 
 keyboard sense line 0
255
 
 
256
 
PB4
257
 
 printer strobe line 1
258
 
 
259
 
PB5
260
 
 (not connected) ?? 1
261
 
 
262
 
PB6
263
 
 tape connector motor control 0
264
 
 
265
 
PB7
266
 
 tape connector output high 1
267
 
 
268
 
 */
269
 
 
270
 
 
271
 
static cassette_image_device *cassette_device_image(running_machine &machine)
272
 
{
273
 
        return machine.device<cassette_image_device>(CASSETTE_TAG);
274
 
}
275
 
 
276
 
/* not called yet - this will update the via with the state of the tape data.
277
 
This allows the via to trigger on bit changes and issue interrupts */
278
 
static TIMER_CALLBACK(oric_refresh_tape)
279
 
{
280
 
        int data;
281
 
        int input_port_9;
282
 
        via6522_device *via_0 = machine.device<via6522_device>("via6522_0");
283
 
 
284
 
        data = 0;
285
 
 
286
 
        if ((cassette_device_image(machine))->input() > 0.0038)
287
 
                data |= 1;
288
 
 
289
 
        /* "A simple cable to catch the vertical retrace signal !
290
 
        This cable connects the video output for the television/monitor
291
 
    to the via cb1 input. Interrupts can be generated from the vertical
292
 
    sync, and flicker free games can be produced */
293
 
 
294
 
        input_port_9 = input_port_read(machine, "FLOPPY");
295
 
        /* cable is enabled? */
296
 
        if ((input_port_9 & 0x08)!=0)
297
 
        {
298
 
                /* return state of vsync */
299
 
                data = input_port_9>>4;
300
 
        }
301
 
 
302
 
        via_0->write_cb1(data);
303
 
}
304
 
 
305
 
static WRITE8_DEVICE_HANDLER ( oric_via_out_b_func )
306
 
{
307
 
        oric_state *state = device->machine().driver_data<oric_state>();
308
 
        device_t *printer = device->machine().device("centronics");
309
 
 
310
 
        /* KEYBOARD */
311
 
        state->m_keyboard_line = data & 0x07;
312
 
 
313
 
        /* CASSETTE */
314
 
        /* cassette motor control */
315
 
        if ((state->m_previous_portb_data^data) & (1<<6))
316
 
        {
317
 
                if (data & (1<<6))
318
 
                {
319
 
                        //enable_logging = 1;
320
 
                }
321
 
        }
322
 
 
323
 
 
324
 
                cassette_device_image(device->machine())->change_state(
325
 
                (data & 0x40) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED,
326
 
                CASSETTE_MOTOR_DISABLED);
327
 
 
328
 
        /* cassette data out */
329
 
        cassette_device_image(device->machine())->output((data & (1<<7)) ? -1.0 : +1.0);
330
 
 
331
 
        /* centronics STROBE is connected to PB4 */
332
 
        centronics_strobe_w(printer, BIT(data, 4));
333
 
 
334
 
        oric_psg_connection_refresh(device->machine());
335
 
        state->m_previous_portb_data = data;
336
 
}
337
 
 
338
 
 
339
 
static READ8_DEVICE_HANDLER ( oric_via_in_ca2_func )
340
 
{
341
 
        oric_state *state = device->machine().driver_data<oric_state>();
342
 
        return state->m_psg_control & 1;
343
 
}
344
 
 
345
 
static READ8_DEVICE_HANDLER ( oric_via_in_cb2_func )
346
 
{
347
 
        oric_state *state = device->machine().driver_data<oric_state>();
348
 
        return (state->m_psg_control>>1) & 1;
349
 
}
350
 
 
351
 
static WRITE8_DEVICE_HANDLER ( oric_via_out_ca2_func )
352
 
{
353
 
        oric_state *state = device->machine().driver_data<oric_state>();
354
 
        state->m_psg_control &=~1;
355
 
 
356
 
        if (data)
357
 
        {
358
 
                state->m_psg_control |=1;
359
 
        }
360
 
 
361
 
        oric_psg_connection_refresh(device->machine());
362
 
}
363
 
 
364
 
static WRITE8_DEVICE_HANDLER ( oric_via_out_cb2_func )
365
 
{
366
 
        oric_state *state = device->machine().driver_data<oric_state>();
367
 
        state->m_psg_control &=~2;
368
 
 
369
 
        if (data)
370
 
        {
371
 
                state->m_psg_control |=2;
372
 
        }
373
 
 
374
 
        oric_psg_connection_refresh(device->machine());
375
 
}
376
 
 
377
 
 
378
 
static void oric_via_irq_func(device_t *device, int state)
379
 
{
380
 
        oric_state *drvstate = device->machine().driver_data<oric_state>();
381
 
        drvstate->m_irqs &= ~(1<<0);
382
 
 
383
 
        if (state)
384
 
        {
385
 
                if (enable_logging)
386
 
                {
387
 
                        //logerror("oric via1 interrupt\r\n");
388
 
                }
389
 
 
390
 
                drvstate->m_irqs |=(1<<0);
391
 
        }
392
 
 
393
 
        oric_refresh_ints(device->machine());
394
 
}
395
 
 
396
 
 
397
 
/*
398
 
VIA Lines
399
 
 Oric usage
400
 
 
401
 
PA0..PA7
402
 
 PSG data bus, printer data lines
403
 
 
404
 
CA1
405
 
 printer acknowledge line
406
 
 
407
 
CA2
408
 
 PSG BC1 line
409
 
 
410
 
PB0..PB2
411
 
 keyboard lines-demultiplexer
412
 
 
413
 
PB3
414
 
 keyboard sense line
415
 
 
416
 
PB4
417
 
 printer strobe line
418
 
 
419
 
PB5
420
 
 (not connected)
421
 
 
422
 
PB6
423
 
 tape connector motor control
424
 
 
425
 
PB7
426
 
 tape connector output
427
 
 
428
 
CB1
429
 
 tape connector input
430
 
 
431
 
CB2
432
 
 PSG BDIR line
433
 
 
434
 
*/
435
 
 
436
 
const via6522_interface oric_6522_interface=
437
 
{
438
 
        DEVCB_HANDLER(oric_via_in_a_func),
439
 
        DEVCB_HANDLER(oric_via_in_b_func),
440
 
        DEVCB_NULL,                             /* printer acknowledge - handled by callback*/
441
 
        DEVCB_NULL,                             /* tape input - handled by timer */
442
 
        DEVCB_HANDLER(oric_via_in_ca2_func),
443
 
        DEVCB_HANDLER(oric_via_in_cb2_func),
444
 
        DEVCB_HANDLER(oric_via_out_a_func),
445
 
        DEVCB_HANDLER(oric_via_out_b_func),
446
 
        DEVCB_NULL,
447
 
        DEVCB_NULL,
448
 
        DEVCB_HANDLER(oric_via_out_ca2_func),
449
 
        DEVCB_HANDLER(oric_via_out_cb2_func),
450
 
        DEVCB_LINE(oric_via_irq_func),
451
 
};
452
 
 
453
 
 
454
 
 
455
 
 
456
 
/*********************/
457
 
/* APPLE 2 INTERFACE */
458
 
 
459
 
/*
460
 
apple2 disc drive accessed through 0x0310-0x031f (read/write)
461
 
oric via accessed through 0x0300-0x030f. (read/write)
462
 
disk interface rom accessed through 0x0320-0x03ff (read only)
463
 
 
464
 
CALL &320 to start, or use BOBY rom.
465
 
*/
466
 
 
467
 
static void oric_install_apple2_interface(running_machine &machine)
468
 
{
469
 
        oric_state *state = machine.driver_data<oric_state>();
470
 
        device_t *fdc = machine.device("fdc");
471
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
472
 
 
473
 
        if (state->m_is_telestrat)
474
 
                return;
475
 
 
476
 
        space->install_legacy_read_handler(0x0300, 0x030f, FUNC(oric_IO_r));
477
 
        space->install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
478
 
        space->install_read_bank(0x0320, 0x03ff, "bank4");
479
 
 
480
 
        space->install_legacy_write_handler(0x0300, 0x030f, FUNC(oric_IO_w));
481
 
        space->install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
482
 
        memory_set_bankptr(machine, "bank4",    machine.region("maincpu")->base() + 0x014000 + 0x020);
483
 
}
484
 
 
485
 
 
486
 
static void oric_enable_memory(running_machine &machine, int low, int high, int rd, int wr)
487
 
{
488
 
        oric_state *state = machine.driver_data<oric_state>();
489
 
        int i;
490
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
491
 
 
492
 
        if (state->m_is_telestrat)
493
 
                return;
494
 
        for (i = low; i <= high; i++)
495
 
        {
496
 
                switch(i) {
497
 
                case 1:
498
 
                        if (rd) {
499
 
                                space->install_read_bank(0xc000, 0xdfff, "bank1");
500
 
                        } else {
501
 
                                space->nop_read(0xc000, 0xdfff);
502
 
                        }
503
 
                        if (wr) {
504
 
                                space->install_write_bank(0xc000, 0xdfff, "bank5");
505
 
                        } else {
506
 
                                space->unmap_write(0xc000, 0xdfff);
507
 
                        }
508
 
                        break;
509
 
                case 2:
510
 
                        if (rd) {
511
 
                                space->install_read_bank(0xe000, 0xf7ff, "bank2");
512
 
                        } else {
513
 
                                space->nop_read(0xe000, 0xf7ff);
514
 
                        }
515
 
                        if (wr) {
516
 
                                space->install_write_bank(0xe000, 0xf7ff, "bank6");
517
 
                        } else {
518
 
                                space->unmap_write(0xe000, 0xf7ff);
519
 
                        }
520
 
                        break;
521
 
                case 3:
522
 
                        if (rd) {
523
 
                                space->install_read_bank(0xf800, 0xffff, "bank3");
524
 
                        } else {
525
 
                                space->nop_read(0xf800, 0xffff);
526
 
                        }
527
 
                        break;
528
 
                }
529
 
        }
530
 
}
531
 
 
532
 
 
533
 
 
534
 
/************************/
535
 
/* APPLE 2 INTERFACE V2 */
536
 
 
537
 
/*
538
 
apple2 disc drive accessed through 0x0310-0x031f (read/write)
539
 
oric via accessed through 0x0300-0x030f. (read/write)
540
 
disk interface rom accessed through 0x0320-0x03ff (read only)
541
 
v2 registers accessed through 0x0380-0x0383 (write only)
542
 
 
543
 
CALL &320 to start, or use BOBY rom.
544
 
*/
545
 
 
546
 
static WRITE8_HANDLER(apple2_v2_interface_w)
547
 
{
548
 
        oric_state *state = space->machine().driver_data<oric_state>();
549
 
        /* data is ignored, address is used to decode operation */
550
 
        if (state->m_is_telestrat)
551
 
                return;
552
 
 
553
 
/*  logerror("apple 2 interface v2 rom page: %01x\n",(offset & 0x02)>>1); */
554
 
 
555
 
        /* bit 0 is 0 for page 0, 1 for page 1 */
556
 
        memory_set_bankptr(space->machine(), "bank4", space->machine().region("maincpu")->base() + 0x014000 + 0x0100 + (((offset & 0x02)>>1)<<8));
557
 
 
558
 
        oric_enable_memory(space->machine(), 1, 3, TRUE, TRUE);
559
 
 
560
 
        /* bit 1 is 0, rom enabled, bit 1 is 1 ram enabled */
561
 
        if ((offset & 0x01)==0)
562
 
        {
563
 
                unsigned char *rom_ptr;
564
 
 
565
 
                /* logerror("apple 2 interface v2: rom enabled\n"); */
566
 
 
567
 
                /* enable rom */
568
 
                rom_ptr = space->machine().region("maincpu")->base() + 0x010000;
569
 
                memory_set_bankptr(space->machine(), "bank1", rom_ptr);
570
 
                memory_set_bankptr(space->machine(), "bank2", rom_ptr+0x02000);
571
 
                memory_set_bankptr(space->machine(), "bank3", rom_ptr+0x03800);
572
 
                memory_set_bankptr(space->machine(), "bank5", state->m_ram_0x0c000);
573
 
                memory_set_bankptr(space->machine(), "bank6", state->m_ram_0x0c000+0x02000);
574
 
                memory_set_bankptr(space->machine(), "bank7", state->m_ram_0x0c000+0x03800);
575
 
        }
576
 
        else
577
 
        {
578
 
                /*logerror("apple 2 interface v2: ram enabled\n"); */
579
 
 
580
 
                /* enable ram */
581
 
                memory_set_bankptr(space->machine(), "bank1", state->m_ram_0x0c000);
582
 
                memory_set_bankptr(space->machine(), "bank2", state->m_ram_0x0c000+0x02000);
583
 
                memory_set_bankptr(space->machine(), "bank3", state->m_ram_0x0c000+0x03800);
584
 
                memory_set_bankptr(space->machine(), "bank5", state->m_ram_0x0c000);
585
 
                memory_set_bankptr(space->machine(), "bank6", state->m_ram_0x0c000+0x02000);
586
 
                memory_set_bankptr(space->machine(), "bank7", state->m_ram_0x0c000+0x03800);
587
 
        }
588
 
}
589
 
 
590
 
 
591
 
/* APPLE 2 INTERFACE V2 */
592
 
static void oric_install_apple2_v2_interface(running_machine &machine)
593
 
{
594
 
        device_t *fdc = machine.device("fdc");
595
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
596
 
 
597
 
        space->install_legacy_read_handler(0x0300, 0x030f, FUNC(oric_IO_r));
598
 
        space->install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
599
 
        space->install_read_bank(0x0320, 0x03ff, "bank4");
600
 
 
601
 
        space->install_legacy_write_handler(0x0300, 0x030f, FUNC(oric_IO_w));
602
 
        space->install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
603
 
        space->install_legacy_write_handler(0x0380, 0x0383, FUNC(apple2_v2_interface_w));
604
 
 
605
 
        apple2_v2_interface_w(space, 0, 0);
606
 
}
607
 
 
608
 
/********************/
609
 
/* JASMIN INTERFACE */
610
 
 
611
 
 
612
 
/* bit 0: overlay ram access (1 means overlay ram enabled) */
613
 
 
614
 
/* bit 0: ROMDIS (1 means internal Basic rom disabled) */
615
 
 
616
 
 
617
 
static void oric_jasmin_set_mem_0x0c000(running_machine &machine)
618
 
{
619
 
        oric_state *state = machine.driver_data<oric_state>();
620
 
        /* assumption:
621
 
    1. It is possible to access all 16k overlay ram.
622
 
    2. If os is enabled, and overlay ram is enabled, all 16k can be accessed.
623
 
    3. if os is disabled, and overlay ram is enabled, jasmin rom takes priority.
624
 
    */
625
 
        if (state->m_is_telestrat)
626
 
                return;
627
 
 
628
 
        /* the ram is disabled in the jasmin rom which indicates that jasmin takes
629
 
    priority over the ram */
630
 
 
631
 
        /* basic rom disabled? */
632
 
        if ((state->m_port_3fb_w & 0x01)==0)
633
 
        {
634
 
                /* no, it is enabled! */
635
 
 
636
 
                /* overlay ram enabled? */
637
 
                if ((state->m_port_3fa_w & 0x01)==0)
638
 
                {
639
 
                        unsigned char *rom_ptr;
640
 
 
641
 
                        /* no it is disabled */
642
 
                        /*logerror("&c000-&ffff is os rom\n"); */
643
 
 
644
 
                        oric_enable_memory(machine, 1, 3, TRUE, FALSE);
645
 
 
646
 
                        rom_ptr = machine.region("maincpu")->base() + 0x010000;
647
 
                        memory_set_bankptr(machine, "bank1", rom_ptr);
648
 
                        memory_set_bankptr(machine, "bank2", rom_ptr+0x02000);
649
 
                        memory_set_bankptr(machine, "bank3", rom_ptr+0x03800);
650
 
                }
651
 
                else
652
 
                {
653
 
                        /*logerror("&c000-&ffff is ram\n"); */
654
 
 
655
 
                        oric_enable_memory(machine, 1, 3, TRUE, TRUE);
656
 
 
657
 
                        memory_set_bankptr(machine, "bank1", state->m_ram_0x0c000);
658
 
                        memory_set_bankptr(machine, "bank2", state->m_ram_0x0c000+0x02000);
659
 
                        memory_set_bankptr(machine, "bank3", state->m_ram_0x0c000+0x03800);
660
 
                        memory_set_bankptr(machine, "bank5", state->m_ram_0x0c000);
661
 
                        memory_set_bankptr(machine, "bank6", state->m_ram_0x0c000+0x02000);
662
 
                        memory_set_bankptr(machine, "bank7", state->m_ram_0x0c000+0x03800);
663
 
                }
664
 
        }
665
 
        else
666
 
        {
667
 
                /* yes, basic rom is disabled */
668
 
 
669
 
                if ((state->m_port_3fa_w & 0x01)==0)
670
 
                {
671
 
                        /* overlay ram disabled */
672
 
 
673
 
                        /*logerror("&c000-&f8ff is nothing!\n"); */
674
 
                        oric_enable_memory(machine, 1, 2, FALSE, FALSE);
675
 
                }
676
 
                else
677
 
                {
678
 
                        /*logerror("&c000-&f8ff is ram!\n"); */
679
 
                        oric_enable_memory(machine, 1, 2, TRUE, TRUE);
680
 
 
681
 
                        memory_set_bankptr(machine, "bank1", state->m_ram_0x0c000);
682
 
                        memory_set_bankptr(machine, "bank2", state->m_ram_0x0c000+0x02000);
683
 
                        memory_set_bankptr(machine, "bank5", state->m_ram_0x0c000);
684
 
                        memory_set_bankptr(machine, "bank6", state->m_ram_0x0c000+0x02000);
685
 
                }
686
 
 
687
 
                {
688
 
                        /* basic rom disabled */
689
 
                        unsigned char *rom_ptr;
690
 
 
691
 
                        /*logerror("&f800-&ffff is jasmin rom\n"); */
692
 
                        /* jasmin rom enabled */
693
 
                        oric_enable_memory(machine, 3, 3, TRUE, TRUE);
694
 
                        rom_ptr = machine.region("maincpu")->base() + 0x010000+0x04000+0x02000;
695
 
                        memory_set_bankptr(machine, "bank3", rom_ptr);
696
 
                        memory_set_bankptr(machine, "bank7", rom_ptr);
697
 
                }
698
 
        }
699
 
}
700
 
 
701
 
/* DRQ is connected to interrupt */
702
 
static WRITE_LINE_DEVICE_HANDLER( oric_jasmin_wd179x_drq_w )
703
 
{
704
 
        oric_state *drvstate = device->machine().driver_data<oric_state>();
705
 
        if (state)
706
 
                drvstate->m_irqs |= (1<<1);
707
 
        else
708
 
                drvstate->m_irqs &=~(1<<1);
709
 
 
710
 
        oric_refresh_ints(device->machine());
711
 
}
712
 
 
713
 
static READ8_HANDLER (oric_jasmin_r)
714
 
{
715
 
        via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
716
 
        device_t *fdc = space->machine().device("wd179x");
717
 
        unsigned char data = 0x0ff;
718
 
 
719
 
        switch (offset & 0x0f)
720
 
        {
721
 
                /* jasmin floppy disc interface */
722
 
                case 0x04:
723
 
                        data = wd17xx_status_r(fdc, 0);
724
 
                        break;
725
 
                case 0x05:
726
 
                        data =wd17xx_track_r(fdc, 0);
727
 
                        break;
728
 
                case 0x06:
729
 
                        data = wd17xx_sector_r(fdc, 0);
730
 
                        break;
731
 
                case 0x07:
732
 
                        data = wd17xx_data_r(fdc, 0);
733
 
                        break;
734
 
                default:
735
 
                        data = via_0->read(*space,offset & 0x0f);
736
 
                        //logerror("unhandled io read: %04x %02x\n", offset, data);
737
 
                        break;
738
 
 
739
 
        }
740
 
 
741
 
        return data;
742
 
}
743
 
 
744
 
static WRITE8_HANDLER(oric_jasmin_w)
745
 
{
746
 
        oric_state *state = space->machine().driver_data<oric_state>();
747
 
        via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
748
 
        device_t *fdc = space->machine().device("wd179x");
749
 
        switch (offset & 0x0f)
750
 
        {
751
 
                /* microdisc floppy disc interface */
752
 
                case 0x04:
753
 
                        wd17xx_command_w(fdc, 0, data);
754
 
                        break;
755
 
                case 0x05:
756
 
                        wd17xx_track_w(fdc, 0, data);
757
 
                        break;
758
 
                case 0x06:
759
 
                        wd17xx_sector_w(fdc, 0, data);
760
 
                        break;
761
 
                case 0x07:
762
 
                        wd17xx_data_w(fdc, 0, data);
763
 
                        break;
764
 
                /* bit 0 = side */
765
 
                case 0x08:
766
 
                        wd17xx_set_side(fdc,data & 0x01);
767
 
                        break;
768
 
                /* any write will cause wd179x to reset */
769
 
                case 0x09:
770
 
                        wd17xx_reset(fdc);
771
 
                        break;
772
 
                case 0x0a:
773
 
                        //logerror("jasmin overlay ram w: %02x PC: %04x\n", data, cpu_get_pc(space->machine().device("maincpu")));
774
 
                        state->m_port_3fa_w = data;
775
 
                        oric_jasmin_set_mem_0x0c000(space->machine());
776
 
                        break;
777
 
                case 0x0b:
778
 
                        //logerror("jasmin romdis w: %02x PC: %04x\n", data, cpu_get_pc(space->machine().device("maincpu")));
779
 
                        state->m_port_3fb_w = data;
780
 
                        oric_jasmin_set_mem_0x0c000(space->machine());
781
 
                        break;
782
 
                /* bit 0,1 of addr is the drive */
783
 
                case 0x0c:
784
 
                case 0x0d:
785
 
                case 0x0e:
786
 
                case 0x0f:
787
 
                        wd17xx_set_drive(fdc,offset & 0x03);
788
 
                        break;
789
 
 
790
 
                default:
791
 
                        via_0->write(*space,offset & 0x0f, data);
792
 
                        break;
793
 
        }
794
 
}
795
 
 
796
 
 
797
 
static void oric_install_jasmin_interface(running_machine &machine)
798
 
{
799
 
        oric_state *state = machine.driver_data<oric_state>();
800
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
801
 
        /* romdis */
802
 
        state->m_port_3fb_w = 1;
803
 
        oric_jasmin_set_mem_0x0c000(machine);
804
 
 
805
 
        space->install_legacy_read_handler(0x0300, 0x03ef, FUNC(oric_IO_r));
806
 
        space->install_legacy_read_handler(0x03f0, 0x03ff, FUNC(oric_jasmin_r));
807
 
 
808
 
        space->install_legacy_write_handler(0x0300, 0x03ef, FUNC(oric_IO_w));
809
 
        space->install_legacy_write_handler(0x03f0, 0x03ff, FUNC(oric_jasmin_w));
810
 
}
811
 
 
812
 
/*********************************/
813
 
/* MICRODISC INTERFACE variables */
814
 
 
815
 
/* used by Microdisc interfaces */
816
 
 
817
 
/* bit 7 is intrq state */
818
 
/* bit 7 is drq state (active low) */
819
 
/* bit 6,5: drive */
820
 
/* bit 4: side */
821
 
/* bit 3: double density enable */
822
 
/* bit 0: enable FDC IRQ to trigger IRQ on CPU */
823
 
 
824
 
 
825
 
static void oric_microdisc_refresh_wd179x_ints(running_machine &machine)
826
 
{
827
 
        oric_state *state = machine.driver_data<oric_state>();
828
 
        state->m_irqs &=~(1<<1);
829
 
 
830
 
        if ((state->m_wd179x_int_state) && (state->m_port_314_w & (1<<0)))
831
 
        {
832
 
                /*logerror("oric microdisc interrupt\n"); */
833
 
 
834
 
                state->m_irqs |=(1<<1);
835
 
        }
836
 
 
837
 
        oric_refresh_ints(machine);
838
 
}
839
 
 
840
 
static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_intrq_w )
841
 
{
842
 
        oric_state *drvstate = device->machine().driver_data<oric_state>();
843
 
        drvstate->m_wd179x_int_state = state;
844
 
 
845
 
        if (state)
846
 
                drvstate->m_port_314_r &= ~(1<<7);
847
 
        else
848
 
                drvstate->m_port_314_r |=(1<<7);
849
 
 
850
 
        oric_microdisc_refresh_wd179x_ints(device->machine());
851
 
}
852
 
 
853
 
static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_drq_w )
854
 
{
855
 
        oric_state *drvstate = device->machine().driver_data<oric_state>();
856
 
        if (state)
857
 
                drvstate->m_port_318_r &=~(1<<7);
858
 
        else
859
 
                drvstate->m_port_318_r |= (1<<7);
860
 
}
861
 
 
862
 
static void oric_microdisc_set_mem_0x0c000(running_machine &machine)
863
 
{
864
 
        oric_state *state = machine.driver_data<oric_state>();
865
 
        if (state->m_is_telestrat)
866
 
                return;
867
 
 
868
 
        /* for 0x0c000-0x0dfff: */
869
 
        /* if os disabled, ram takes priority */
870
 
        /* /ROMDIS */
871
 
        if ((state->m_port_314_w & (1<<1))==0)
872
 
        {
873
 
                /*logerror("&c000-&dfff is ram\n"); */
874
 
                /* rom disabled enable ram */
875
 
                oric_enable_memory(machine, 1, 1, TRUE, TRUE);
876
 
                memory_set_bankptr(machine, "bank1", state->m_ram_0x0c000);
877
 
                memory_set_bankptr(machine, "bank5", state->m_ram_0x0c000);
878
 
        }
879
 
        else
880
 
        {
881
 
                unsigned char *rom_ptr;
882
 
                /*logerror("&c000-&dfff is os rom\n"); */
883
 
                /* basic rom */
884
 
                oric_enable_memory(machine, 1, 1, TRUE, FALSE);
885
 
                rom_ptr = machine.region("maincpu")->base() + 0x010000;
886
 
                memory_set_bankptr(machine, "bank1", rom_ptr);
887
 
                memory_set_bankptr(machine, "bank5", rom_ptr);
888
 
        }
889
 
 
890
 
        /* for 0x0e000-0x0ffff */
891
 
        /* if not disabled, os takes priority */
892
 
        if ((state->m_port_314_w & (1<<1))!=0)
893
 
        {
894
 
                unsigned char *rom_ptr;
895
 
                /*logerror("&e000-&ffff is os rom\n"); */
896
 
                /* basic rom */
897
 
                oric_enable_memory(machine, 2, 3, TRUE, FALSE);
898
 
                rom_ptr = machine.region("maincpu")->base() + 0x010000;
899
 
                memory_set_bankptr(machine, "bank2", rom_ptr+0x02000);
900
 
                memory_set_bankptr(machine, "bank3", rom_ptr+0x03800);
901
 
                memory_set_bankptr(machine, "bank6", rom_ptr+0x02000);
902
 
                memory_set_bankptr(machine, "bank7", rom_ptr+0x03800);
903
 
 
904
 
        }
905
 
        else
906
 
        {
907
 
                /* if eprom is enabled, it takes priority over ram */
908
 
                if ((state->m_port_314_w & (1<<7))==0)
909
 
                {
910
 
                        unsigned char *rom_ptr;
911
 
                        /*logerror("&e000-&ffff is disk rom\n"); */
912
 
                        oric_enable_memory(machine, 2, 3, TRUE, FALSE);
913
 
                        /* enable rom of microdisc interface */
914
 
                        rom_ptr = machine.region("maincpu")->base() + 0x014000;
915
 
                        memory_set_bankptr(machine, "bank2", rom_ptr);
916
 
                        memory_set_bankptr(machine, "bank3", rom_ptr+0x01800);
917
 
                }
918
 
                else
919
 
                {
920
 
                        /*logerror("&e000-&ffff is ram\n"); */
921
 
                        /* rom disabled enable ram */
922
 
                        oric_enable_memory(machine, 2, 3, TRUE, TRUE);
923
 
                        memory_set_bankptr(machine, "bank2", state->m_ram_0x0c000+0x02000);
924
 
                        memory_set_bankptr(machine, "bank3", state->m_ram_0x0c000+0x03800);
925
 
                        memory_set_bankptr(machine, "bank6", state->m_ram_0x0c000+0x02000);
926
 
                        memory_set_bankptr(machine, "bank7", state->m_ram_0x0c000+0x03800);
927
 
                }
928
 
        }
929
 
}
930
 
 
931
 
 
932
 
 
933
 
READ8_HANDLER (oric_microdisc_r)
934
 
{
935
 
        oric_state *state = space->machine().driver_data<oric_state>();
936
 
        unsigned char data = 0x0ff;
937
 
        device_t *fdc = space->machine().device("wd179x");
938
 
 
939
 
        switch (offset & 0x0ff)
940
 
        {
941
 
                /* microdisc floppy disc interface */
942
 
                case 0x00:
943
 
                        data = wd17xx_status_r(fdc, 0);
944
 
                        break;
945
 
                case 0x01:
946
 
                        data =wd17xx_track_r(fdc, 0);
947
 
                        break;
948
 
                case 0x02:
949
 
                        data = wd17xx_sector_r(fdc, 0);
950
 
                        break;
951
 
                case 0x03:
952
 
                        data = wd17xx_data_r(fdc, 0);
953
 
                        break;
954
 
                case 0x04:
955
 
                        data = state->m_port_314_r | 0x07f;
956
 
/*          logerror("port_314_r: %02x\n",data); */
957
 
                        break;
958
 
                case 0x08:
959
 
                        data = state->m_port_318_r | 0x07f;
960
 
/*          logerror("port_318_r: %02x\n",data); */
961
 
                        break;
962
 
 
963
 
                default:
964
 
                        {
965
 
                                via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
966
 
                                data = via_0->read(*space, offset & 0x0f);
967
 
                        }
968
 
                        break;
969
 
 
970
 
        }
971
 
 
972
 
        return data;
973
 
}
974
 
 
975
 
WRITE8_HANDLER(oric_microdisc_w)
976
 
{
977
 
        oric_state *state = space->machine().driver_data<oric_state>();
978
 
        device_t *fdc = space->machine().device("wd179x");
979
 
        switch (offset & 0x0ff)
980
 
        {
981
 
                /* microdisc floppy disc interface */
982
 
                case 0x00:
983
 
                        wd17xx_command_w(fdc, 0, data);
984
 
                        break;
985
 
                case 0x01:
986
 
                        wd17xx_track_w(fdc, 0, data);
987
 
                        break;
988
 
                case 0x02:
989
 
                        wd17xx_sector_w(fdc, 0, data);
990
 
                        break;
991
 
                case 0x03:
992
 
                        wd17xx_data_w(fdc, 0, data);
993
 
                        break;
994
 
                case 0x04:
995
 
                {
996
 
                        state->m_port_314_w = data;
997
 
 
998
 
                        //logerror("port_314_w: %02x\n",data);
999
 
 
1000
 
                        /* bit 6,5: drive */
1001
 
                        /* bit 4: side */
1002
 
                        /* bit 3: double density enable */
1003
 
                        /* bit 0: enable FDC IRQ to trigger IRQ on CPU */
1004
 
                        wd17xx_set_drive(fdc,(data>>5) & 0x03);
1005
 
                        wd17xx_set_side(fdc,(data>>4) & 0x01);
1006
 
                        wd17xx_dden_w(fdc, !BIT(data, 3));
1007
 
 
1008
 
                        oric_microdisc_set_mem_0x0c000(space->machine());
1009
 
                        oric_microdisc_refresh_wd179x_ints(space->machine());
1010
 
                }
1011
 
                break;
1012
 
 
1013
 
                default:
1014
 
                        {
1015
 
                                via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
1016
 
                                via_0->write(*space, offset & 0x0f, data);
1017
 
                        }
1018
 
                        break;
1019
 
        }
1020
 
}
1021
 
 
1022
 
static void oric_install_microdisc_interface(running_machine &machine)
1023
 
{
1024
 
        oric_state *state = machine.driver_data<oric_state>();
1025
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1026
 
 
1027
 
        space->install_legacy_read_handler(0x0300, 0x030f, FUNC(oric_IO_r));
1028
 
        space->install_legacy_read_handler(0x0310, 0x031f, FUNC(oric_microdisc_r));
1029
 
        space->install_legacy_read_handler(0x0320, 0x03ff, FUNC(oric_IO_r));
1030
 
 
1031
 
        space->install_legacy_write_handler(0x0300, 0x030f, FUNC(oric_IO_w));
1032
 
        space->install_legacy_write_handler(0x0310, 0x031f, FUNC(oric_microdisc_w));
1033
 
        space->install_legacy_write_handler(0x0320, 0x03ff, FUNC(oric_IO_w));
1034
 
 
1035
 
        /* disable os rom, enable microdisc rom */
1036
 
        /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */
1037
 
        state->m_port_314_w = 0x0ff^((1<<7) | (1<<1));
1038
 
 
1039
 
        oric_microdisc_set_mem_0x0c000(machine);
1040
 
}
1041
 
 
1042
 
 
1043
 
 
1044
 
/*********************************************************/
1045
 
 
1046
 
static WRITE_LINE_DEVICE_HANDLER( oric_wd179x_intrq_w )
1047
 
{
1048
 
        if ((input_port_read(device->machine(), "FLOPPY") & 0x07) == ORIC_FLOPPY_INTERFACE_MICRODISC)
1049
 
                oric_microdisc_wd179x_intrq_w(device, state);
1050
 
}
1051
 
 
1052
 
static WRITE_LINE_DEVICE_HANDLER( oric_wd179x_drq_w )
1053
 
{
1054
 
        switch (input_port_read(device->machine(), "FLOPPY") &  0x07)
1055
 
        {
1056
 
                default:
1057
 
                case ORIC_FLOPPY_INTERFACE_NONE:
1058
 
                case ORIC_FLOPPY_INTERFACE_APPLE2:
1059
 
                        return;
1060
 
                case ORIC_FLOPPY_INTERFACE_MICRODISC:
1061
 
                        oric_microdisc_wd179x_drq_w(device, state);
1062
 
                        return;
1063
 
                case ORIC_FLOPPY_INTERFACE_JASMIN:
1064
 
                        oric_jasmin_wd179x_drq_w(device, state);
1065
 
                        return;
1066
 
        }
1067
 
}
1068
 
 
1069
 
const wd17xx_interface oric_wd17xx_interface =
1070
 
{
1071
 
        DEVCB_NULL,
1072
 
        DEVCB_LINE(oric_wd179x_intrq_w),
1073
 
        DEVCB_LINE(oric_wd179x_drq_w),
1074
 
        {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
1075
 
};
1076
 
 
1077
 
static void oric_common_init_machine(running_machine &machine)
1078
 
{
1079
 
        oric_state *state = machine.driver_data<oric_state>();
1080
 
        /* clear all irqs */
1081
 
        state->m_irqs = 0;
1082
 
        state->m_ram_0x0c000 = NULL;
1083
 
 
1084
 
        machine.scheduler().timer_pulse(attotime::from_hz(4800), FUNC(oric_refresh_tape));
1085
 
}
1086
 
 
1087
 
MACHINE_START( oric )
1088
 
{
1089
 
        oric_state *state = machine.driver_data<oric_state>();
1090
 
        oric_common_init_machine(machine);
1091
 
 
1092
 
        state->m_is_telestrat = 0;
1093
 
 
1094
 
        state->m_ram_0x0c000 = auto_alloc_array(machine, char, 16384);
1095
 
}
1096
 
 
1097
 
 
1098
 
MACHINE_RESET( oric )
1099
 
{
1100
 
        oric_state *state = machine.driver_data<oric_state>();
1101
 
        int disc_interface_id = input_port_read(machine, "FLOPPY") & 0x07;
1102
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1103
 
        if (state->m_is_telestrat)
1104
 
                return;
1105
 
 
1106
 
        switch (disc_interface_id)
1107
 
        {
1108
 
                default:
1109
 
 
1110
 
                case ORIC_FLOPPY_INTERFACE_APPLE2:
1111
 
                case ORIC_FLOPPY_INTERFACE_NONE:
1112
 
                {
1113
 
                        /* setup memory when there is no disc interface */
1114
 
                        unsigned char *rom_ptr;
1115
 
 
1116
 
                        /* os rom */
1117
 
                        oric_enable_memory(machine, 1, 3, TRUE, FALSE);
1118
 
                        rom_ptr = machine.region("maincpu")->base() + 0x010000;
1119
 
                        memory_set_bankptr(machine, "bank1", rom_ptr);
1120
 
                        memory_set_bankptr(machine, "bank2", rom_ptr+0x02000);
1121
 
                        memory_set_bankptr(machine, "bank3", rom_ptr+0x03800);
1122
 
                        memory_set_bankptr(machine, "bank5", rom_ptr);
1123
 
                        memory_set_bankptr(machine, "bank6", rom_ptr+0x02000);
1124
 
                        memory_set_bankptr(machine, "bank7", rom_ptr+0x03800);
1125
 
 
1126
 
 
1127
 
                        if (disc_interface_id==ORIC_FLOPPY_INTERFACE_APPLE2)
1128
 
                        {
1129
 
                                oric_install_apple2_interface(machine);
1130
 
                        }
1131
 
                        else
1132
 
                        {
1133
 
                                space->install_legacy_read_handler(0x0300, 0x03ff, FUNC(oric_IO_r));
1134
 
                                space->install_legacy_write_handler(0x0300, 0x03ff, FUNC(oric_IO_w));
1135
 
                        }
1136
 
                }
1137
 
                break;
1138
 
 
1139
 
                case ORIC_FLOPPY_INTERFACE_APPLE2_V2:
1140
 
                {
1141
 
                        oric_install_apple2_v2_interface(machine);
1142
 
                }
1143
 
                break;
1144
 
 
1145
 
 
1146
 
                case ORIC_FLOPPY_INTERFACE_MICRODISC:
1147
 
                {
1148
 
                        oric_install_microdisc_interface(machine);
1149
 
                }
1150
 
                break;
1151
 
 
1152
 
                case ORIC_FLOPPY_INTERFACE_JASMIN:
1153
 
                {
1154
 
                        oric_install_jasmin_interface(machine);
1155
 
                }
1156
 
                break;
1157
 
        }
1158
 
        machine.device("maincpu")->reset();
1159
 
}
1160
 
 
1161
 
 
1162
 
READ8_HANDLER ( oric_IO_r )
1163
 
{
1164
 
        via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
1165
 
        switch (input_port_read(space->machine(), "FLOPPY") & 0x07)
1166
 
        {
1167
 
                default:
1168
 
                case ORIC_FLOPPY_INTERFACE_NONE:
1169
 
                        break;
1170
 
 
1171
 
                case ORIC_FLOPPY_INTERFACE_MICRODISC:
1172
 
                {
1173
 
                        if ((offset>=0x010) && (offset<=0x01f))
1174
 
                        {
1175
 
                                return oric_microdisc_r(space, offset);
1176
 
                        }
1177
 
                }
1178
 
                break;
1179
 
 
1180
 
                case ORIC_FLOPPY_INTERFACE_JASMIN:
1181
 
                {
1182
 
                        if ((offset>=0x0f4) && (offset<=0x0ff))
1183
 
                        {
1184
 
                                return oric_jasmin_r(space, offset);
1185
 
                        }
1186
 
                }
1187
 
                break;
1188
 
        }
1189
 
        if (enable_logging)
1190
 
        {
1191
 
                if ((offset & 0x0f)!=0x0d)
1192
 
                {
1193
 
                        //logerror("via 0 r: %04x %04x\n",offset, (unsigned) cpu_get_reg(space->machine().device("maincpu"), STATE_GENPC));
1194
 
                }
1195
 
        }
1196
 
        /* it is repeated */
1197
 
        return via_0->read(*space, offset & 0x0f);
1198
 
}
1199
 
 
1200
 
WRITE8_HANDLER ( oric_IO_w )
1201
 
{
1202
 
        via6522_device *via_0 = space->machine().device<via6522_device>("via6522_0");
1203
 
        switch (input_port_read(space->machine(), "FLOPPY") & 0x07)
1204
 
        {
1205
 
                default:
1206
 
                case ORIC_FLOPPY_INTERFACE_NONE:
1207
 
                        break;
1208
 
 
1209
 
                case ORIC_FLOPPY_INTERFACE_MICRODISC:
1210
 
                {
1211
 
                        if ((offset >= 0x010) && (offset <= 0x01f))
1212
 
                        {
1213
 
                                oric_microdisc_w(space, offset, data);
1214
 
                                return;
1215
 
                        }
1216
 
                }
1217
 
                break;
1218
 
 
1219
 
                case ORIC_FLOPPY_INTERFACE_JASMIN:
1220
 
                {
1221
 
                        if ((offset >= 0x0f4) && (offset <= 0x0ff))
1222
 
                        {
1223
 
                                oric_jasmin_w(space, offset, data);
1224
 
                                return;
1225
 
                        }
1226
 
 
1227
 
                }
1228
 
                break;
1229
 
        }
1230
 
        if (enable_logging)
1231
 
        {
1232
 
                //logerror("via 0 w: %04x %02x %04x\n", offset, data,(unsigned) cpu_get_reg(space->machine().device("maincpu"), STATE_GENPC));
1233
 
        }
1234
 
 
1235
 
        via_0->write(*space, offset & 0x0f, data);
1236
 
}
1237
 
 
1238
 
 
1239
 
 
1240
 
/**** TELESTRAT ****/
1241
 
 
1242
 
/*
1243
 
VIA lines
1244
 
 Telestrat usage
1245
 
 
1246
 
PA0..PA2
1247
 
 Memory bank selection
1248
 
 
1249
 
PA3
1250
 
 "Midi" port pin 3
1251
 
 
1252
 
PA4
1253
 
 RS232/Minitel selection
1254
 
 
1255
 
PA5
1256
 
 Third mouse button (right joystick port pin 5)
1257
 
 
1258
 
PA6
1259
 
 "Midi" port pin 5
1260
 
 
1261
 
PA7
1262
 
 Second mouse button (right joystick port pin 9)
1263
 
 
1264
 
CA1
1265
 
 "Midi" port pin 1
1266
 
 
1267
 
CA2
1268
 
 not used ?
1269
 
 
1270
 
PB0..PB4
1271
 
 Joystick ports
1272
 
 
1273
 
PB5
1274
 
 Joystick doubler switch
1275
 
 
1276
 
PB6
1277
 
 Select Left Joystick port
1278
 
 
1279
 
PB7
1280
 
 Select Right Joystick port
1281
 
 
1282
 
CB1
1283
 
 Phone Ring detection
1284
 
 
1285
 
CB2
1286
 
 "Midi" port pin 4
1287
 
 
1288
 
*/
1289
 
 
1290
 
 
1291
 
static void telestrat_refresh_mem(running_machine &machine)
1292
 
{
1293
 
        oric_state *state = machine.driver_data<oric_state>();
1294
 
        address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1295
 
 
1296
 
        telestrat_mem_block *mem_block = &state->m_telestrat_blocks[state->m_telestrat_bank_selection];
1297
 
 
1298
 
        switch (mem_block->MemType)
1299
 
        {
1300
 
                case TELESTRAT_MEM_BLOCK_RAM:
1301
 
                {
1302
 
                        memory_set_bankptr(machine, "bank1", mem_block->ptr);
1303
 
                        memory_set_bankptr(machine, "bank2", mem_block->ptr);
1304
 
                        space->install_read_bank(0xc000, 0xffff, "bank1");
1305
 
                        space->install_write_bank(0xc000, 0xffff, "bank2");
1306
 
                }
1307
 
                break;
1308
 
 
1309
 
                case TELESTRAT_MEM_BLOCK_ROM:
1310
 
                {
1311
 
                        memory_set_bankptr(machine, "bank1", mem_block->ptr);
1312
 
                        space->install_read_bank(0xc000, 0xffff, "bank1");
1313
 
                        space->nop_write(0xc000, 0xffff);
1314
 
                }
1315
 
                break;
1316
 
 
1317
 
                default:
1318
 
                case TELESTRAT_MEM_BLOCK_UNDEFINED:
1319
 
                {
1320
 
                        space->nop_readwrite(0xc000, 0xffff);
1321
 
                }
1322
 
                break;
1323
 
        }
1324
 
}
1325
 
 
1326
 
static READ8_DEVICE_HANDLER(telestrat_via2_in_a_func)
1327
 
{
1328
 
        oric_state *state = device->machine().driver_data<oric_state>();
1329
 
        //logerror("via 2 - port a %02x\n",state->m_telestrat_via2_port_a_data);
1330
 
        return state->m_telestrat_via2_port_a_data;
1331
 
}
1332
 
 
1333
 
 
1334
 
static WRITE8_DEVICE_HANDLER(telestrat_via2_out_a_func)
1335
 
{
1336
 
        oric_state *state = device->machine().driver_data<oric_state>();
1337
 
        //logerror("via 2 - port a w: %02x\n",data);
1338
 
 
1339
 
        state->m_telestrat_via2_port_a_data = data;
1340
 
 
1341
 
        if (((data^state->m_telestrat_bank_selection) & 0x07)!=0)
1342
 
        {
1343
 
                state->m_telestrat_bank_selection = data & 0x07;
1344
 
 
1345
 
                telestrat_refresh_mem(device->machine());
1346
 
        }
1347
 
}
1348
 
 
1349
 
static READ8_DEVICE_HANDLER(telestrat_via2_in_b_func)
1350
 
{
1351
 
        oric_state *state = device->machine().driver_data<oric_state>();
1352
 
        unsigned char data = 0x01f;
1353
 
 
1354
 
        /* left joystick selected? */
1355
 
        if (state->m_telestrat_via2_port_b_data & (1<<6))
1356
 
        {
1357
 
                data &= input_port_read(device->machine(), "JOY0");
1358
 
        }
1359
 
 
1360
 
        /* right joystick selected? */
1361
 
        if (state->m_telestrat_via2_port_b_data & (1<<7))
1362
 
        {
1363
 
                data &= input_port_read(device->machine(), "JOY1");
1364
 
        }
1365
 
 
1366
 
        data |= state->m_telestrat_via2_port_b_data & ((1<<7) | (1<<6) | (1<<5));
1367
 
 
1368
 
        return data;
1369
 
}
1370
 
 
1371
 
static WRITE8_DEVICE_HANDLER(telestrat_via2_out_b_func)
1372
 
{
1373
 
        oric_state *state = device->machine().driver_data<oric_state>();
1374
 
        state->m_telestrat_via2_port_b_data = data;
1375
 
}
1376
 
 
1377
 
 
1378
 
static void telestrat_via2_irq_func(device_t *device, int state)
1379
 
{
1380
 
        oric_state *drvstate = device->machine().driver_data<oric_state>();
1381
 
        drvstate->m_irqs &=~(1<<2);
1382
 
 
1383
 
        if (state)
1384
 
        {
1385
 
                //logerror("telestrat via2 interrupt\n");
1386
 
 
1387
 
                drvstate->m_irqs |=(1<<2);
1388
 
        }
1389
 
 
1390
 
        oric_refresh_ints(device->machine());
1391
 
}
1392
 
 
1393
 
const via6522_interface telestrat_via2_interface=
1394
 
{
1395
 
        DEVCB_HANDLER(telestrat_via2_in_a_func),
1396
 
        DEVCB_HANDLER(telestrat_via2_in_b_func),
1397
 
        DEVCB_NULL,
1398
 
        DEVCB_NULL,
1399
 
        DEVCB_NULL,
1400
 
        DEVCB_NULL,
1401
 
        DEVCB_HANDLER(telestrat_via2_out_a_func),
1402
 
        DEVCB_HANDLER(telestrat_via2_out_b_func),
1403
 
        DEVCB_NULL,
1404
 
        DEVCB_NULL,
1405
 
        DEVCB_NULL,
1406
 
        DEVCB_NULL,
1407
 
        DEVCB_LINE(telestrat_via2_irq_func),
1408
 
};
1409
 
 
1410
 
#if 0
1411
 
/* interrupt state from acia6551 */
1412
 
static void telestrat_acia_callback(running_machine &machine, int irq_state)
1413
 
{
1414
 
        oric_state *state = machine.driver_data<oric_state>();
1415
 
        state->m_irqs&=~(1<<3);
1416
 
 
1417
 
        if (irq_state)
1418
 
        {
1419
 
                state->m_irqs |= (1<<3);
1420
 
        }
1421
 
 
1422
 
        oric_refresh_ints(machine);
1423
 
}
1424
 
#endif
1425
 
 
1426
 
MACHINE_START( telestrat )
1427
 
{
1428
 
        oric_state *state = machine.driver_data<oric_state>();
1429
 
        UINT8 *mem = machine.region("maincpu")->base();
1430
 
 
1431
 
        oric_common_init_machine(machine);
1432
 
 
1433
 
        state->m_is_telestrat = 1;
1434
 
 
1435
 
        /* initialise overlay ram */
1436
 
        state->m_telestrat_blocks[0].MemType = TELESTRAT_MEM_BLOCK_RAM;
1437
 
        state->m_telestrat_blocks[0].ptr = auto_alloc_array(machine, UINT8, 16384);
1438
 
 
1439
 
        state->m_telestrat_blocks[1].MemType = TELESTRAT_MEM_BLOCK_RAM;
1440
 
        state->m_telestrat_blocks[1].ptr = auto_alloc_array(machine, UINT8, 16384);
1441
 
        state->m_telestrat_blocks[2].MemType = TELESTRAT_MEM_BLOCK_RAM;
1442
 
        state->m_telestrat_blocks[2].ptr = auto_alloc_array(machine, UINT8, 16384);
1443
 
 
1444
 
        /* initialise default cartridge */
1445
 
        state->m_telestrat_blocks[3].MemType = TELESTRAT_MEM_BLOCK_ROM;
1446
 
        state->m_telestrat_blocks[3].ptr = mem+0x010000;
1447
 
 
1448
 
        state->m_telestrat_blocks[4].MemType = TELESTRAT_MEM_BLOCK_RAM;
1449
 
        state->m_telestrat_blocks[4].ptr = auto_alloc_array(machine, UINT8, 16384);
1450
 
 
1451
 
        /* initialise default cartridge */
1452
 
        state->m_telestrat_blocks[5].MemType = TELESTRAT_MEM_BLOCK_ROM;
1453
 
        state->m_telestrat_blocks[5].ptr = mem+0x014000;
1454
 
 
1455
 
        /* initialise default cartridge */
1456
 
        state->m_telestrat_blocks[6].MemType = TELESTRAT_MEM_BLOCK_ROM;
1457
 
        state->m_telestrat_blocks[6].ptr = mem+0x018000;
1458
 
 
1459
 
        /* initialise default cartridge */
1460
 
        state->m_telestrat_blocks[7].MemType = TELESTRAT_MEM_BLOCK_ROM;
1461
 
        state->m_telestrat_blocks[7].ptr = mem+0x01c000;
1462
 
 
1463
 
        state->m_telestrat_bank_selection = 7;
1464
 
        telestrat_refresh_mem(machine);
1465
 
 
1466
 
        /* disable os rom, enable microdisc rom */
1467
 
        /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */
1468
 
        state->m_port_314_w = 0x0ff^((1<<7) | (1<<1));
1469
 
}