Previous 15994 Revisions Next

r4868 Thursday 28th May, 2009 at 11:11:43 UTC by Barry Rodewald
[FM7] Added basic implementation of some IRQs, and some I/O ports.
[src/mess/drivers]fm7.c

src/mess/drivers/fm7.c
r4867r4868
3131#include "cpu/m6809/m6809.h"
3232#include "sound/ay8910.h"
3333
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
3445UINT8* shared_ram;
46UINT8* fm7_video_ram;
47static UINT8 irq_flags;  // active IRQ flags
48static UINT8 irq_mask;  // IRQ mask
49emu_timer* fm7_timer;  // main timer, triggered every 2.0345ms?
50static UINT8 sub_busy;
51static UINT8 basic_rom_en;
52static UINT8 fm7_attn_irq;
3553
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 */
69WRITE8_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 */
88READ8_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
3697READ8_HANDLER( mainmem_r )
3798{
3899   UINT8* RAM = memory_region(space->machine,"maincpu");
r4867r4868
73134
74135READ8_HANDLER( fm7_fd04_r )
75136{
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
157READ8_HANDLER( fm7_subintf_r )
158{
159   return sub_busy & 0x80;
160}
161
162WRITE8_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
169READ8_HANDLER( fm7_sub_busyflag_r )
170{
171   sub_busy = 0x00;
172   return 0x00;
173}
174
175WRITE8_HANDLER( fm7_sub_busyflag_w )
176{
177   sub_busy = 0x80;
178}
179
180READ8_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
190WRITE8_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 */
203READ8_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 */
212READ8_HANDLER( fm7_attn_irq_r )
213{
214   fm7_attn_irq = 1;
215   cputag_set_input_line(space->machine,"maincpu",M6809_FIRQ_LINE,ASSERT_LINE);
76216   return 0xff;
77217}
78218
219static 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}
79227
228static IRQ_CALLBACK(fm7_irq_ack)
229{
230   cputag_set_input_line(device->machine,"maincpu",irqline,CLEAR_LINE);
231   return -1;
232}
233
234static IRQ_CALLBACK(fm7_sub_irq_ack)
235{
236   cputag_set_input_line(device->machine,"sub",irqline,CLEAR_LINE);
237   return -1;
238}
239
80240/*
81241   0000 - 7FFF: (RAM) BASIC working area, user's area
82242   8000 - FBFF: (ROM) F-BASIC ROM
r4867r4868
88248// The FM-7 has only 64kB RAM, so we'll worry about banking when we do the later models
89249static ADDRESS_MAP_START( fm7_mem, ADDRESS_SPACE_PROGRAM, 8 )
90250   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
92252   AM_RANGE(0xfc00,0xfc7f) AM_RAM
93253   AM_RANGE(0xfc80,0xfcff) AM_READWRITE(shared_r,shared_w) // shared RAM with sub-CPU
94254   // 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
95257   AM_RANGE(0xfd04,0xfd04) AM_READ(fm7_fd04_r)
258   AM_RANGE(0xfd05,0xfd05) AM_READWRITE(fm7_subintf_r,fm7_subintf_w)
96259   AM_RANGE(0xfd0d,0xfd0d) AM_DEVWRITE("psg",ay8910_address_w)
97260   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)
98262   // Boot ROM
99263   AM_RANGE(0xfe00,0xffef) AM_ROM AM_REGION("basic",0x0000)
100264   AM_RANGE(0xfff0,0xffff) AM_READWRITE(vector_r,vector_w)
r4867r4868
110274   FFF0 - FFFF: Interrupt vector table
111275*/
112276
113UINT8 *fm7_video_ram;
114277static ADDRESS_MAP_START( fm7_sub_mem, ADDRESS_SPACE_PROGRAM, 8 )
115278   AM_RANGE(0x0000,0xbfff) AM_RAM AM_BASE(&fm7_video_ram) // VRAM
116279   AM_RANGE(0xc000,0xcfff) AM_RAM // Console RAM
117280   AM_RANGE(0xd000,0xd37f) AM_RAM // Work RAM
118281   AM_RANGE(0xd380,0xd3ff) AM_READWRITE(shared_r,shared_w) // shared RAM
119282   // 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)
120286   AM_RANGE(0xd800,0xffff) AM_ROM
121287ADDRESS_MAP_END
122288
r4867r4868
136302static DRIVER_INIT(fm7)
137303{
138304   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);
139308}
140309
141310static MACHINE_START(fm7)
r4867r4868
152321
153322static MACHINE_RESET(fm7)
154323{
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);
155333}
156334
157335static VIDEO_START( fm7 )
r4867r4868
265443/* ROM definition */
266444ROM_START( fm7 )
267445   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) )
269447
270448   ROM_REGION( 0x20000, "sub", 0 )
271449   ROM_LOAD( "subsys_c.rom", 0xd800,  0x2800, CRC(24cec93f) SHA1(50b7283db6fe1342c6063fc94046283f4feddc1c) )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team