Previous 15994 Revisions Next

r5052 Saturday 20th June, 2009 at 00:24:49 UTC by Barry Rodewald
[FM7] Split video functions into separate source file.
[src/mess]mess.mak
[src/mess/drivers]fm7.c
[src/mess/includes]fm7.h*
[src/mess/video]fm7.c*

src/mess/video/fm7.c
r0r5052
1/*
2 *
3 *  Fujitsu Micro 7 Video functions
4 *
5 */
6
7#include "driver.h"
8#include "cpu/m6809/m6809.h"
9#include "includes/fm7.h"
10
11struct fm7_video_flags fm7_video;
12
13extern UINT8* fm7_video_ram;
14extern emu_timer* fm7_subtimer;
15
16/*
17 * Main CPU: Sub-CPU interface (port 0xfd05)
18 *
19 * Read:
20 *   bit 7: Sub-CPU busy (or halted)
21 *   bit 0: EXTDET (?)
22 * Write:
23 *   bit 7: Sub-CPU halt
24 *   bit 6: Sub-CPU cancel IRQ
25 */
26
27READ8_HANDLER( fm7_subintf_r )
28{
29   UINT8 ret = 0x00;
30   
31   if(fm7_video.sub_busy != 0 || fm7_video.sub_halt != 0)
32      ret |= 0x80;
33     
34   ret |= 0x7e;
35   //ret |= 0x01; // EXTDET (not implemented yet)
36   
37   return ret;
38}
39
40WRITE8_HANDLER( fm7_subintf_w )
41{
42   fm7_video.sub_halt = data & 0x80;
43   if(data & 0x80)
44      fm7_video.sub_busy = data & 0x80;
45
46   cputag_set_input_line(space->machine,"sub",INPUT_LINE_HALT,(data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
47   if(data & 0x40)
48      cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,ASSERT_LINE);
49   //popmessage("Sub CPU Interface write: %02x\n",data);
50}
51
52READ8_HANDLER( fm7_sub_busyflag_r )
53{
54   if(fm7_video.sub_halt == 0)
55      fm7_video.sub_busy = 0x00;
56   return 0x00;
57}
58
59WRITE8_HANDLER( fm7_sub_busyflag_w )
60{
61   fm7_video.sub_busy = 0x80;
62}
63
64/*
65 * Sub-CPU port 0xd402
66 *   Read-only: Acknowledge Cancel IRQ
67 */
68READ8_HANDLER( fm7_cancel_ack )
69{
70   cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,CLEAR_LINE);
71   return 0x00;
72}
73
74/*
75 * Reading from 0xd404 (sub-CPU) causes an "Attention" FIRQ on the main CPU
76 */
77READ8_HANDLER( fm7_attn_irq_r )
78{
79   fm7_video.attn_irq = 1;
80   cputag_set_input_line(space->machine,"maincpu",M6809_FIRQ_LINE,ASSERT_LINE);
81   return 0xff;
82}
83
84/*
85 *  Sub CPU: I/O port 0xd409
86 *
87 *  On read, enables VRAM access
88 *  On write, disables VRAM access
89 */
90READ8_HANDLER( fm7_vram_access_r )
91{
92   fm7_video.vram_access = 1;
93   return 0xff;
94}
95
96WRITE8_HANDLER( fm7_vram_access_w )
97{
98   fm7_video.vram_access = 0;
99}
100
101READ8_HANDLER( fm7_vram_r )
102{
103   int offs;
104   
105   offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff);
106   return fm7_video_ram[offs];
107}
108
109WRITE8_HANDLER( fm7_vram_w )
110{
111   int offs;
112   
113   offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff);
114   if(fm7_video.vram_access != 0)
115      fm7_video_ram[offs] = data;
116}
117
118/*
119 *  Sub CPU: I/O port 0xd408
120 *
121 *  On read, enables the CRT display
122 *  On write, disables the CRT display
123 */
124READ8_HANDLER( fm7_crt_r )
125{
126   fm7_video.crt_enable = 1;
127   return 0xff;
128}
129
130WRITE8_HANDLER( fm7_crt_w )
131{
132   fm7_video.crt_enable = 0;
133}
134
135/*
136 *  Sub CPU: I/O ports 0xd40e - 0xd40f
137 *
138 *  0xd40e: bits 0-6 - offset in bytes (high byte) (bit 6 is used for 400 line video only)
139 *  0xd40f: bits 0-7 - offset in bytes (low byte)
140 */
141WRITE8_HANDLER( fm7_vram_offset_w )
142{
143   UINT16 new_offset = 0;
144   
145   switch(offset)
146   {
147      case 0:
148         new_offset = (data << 8) | (fm7_video.vram_offset & 0x00ff);
149         break;
150      case 1:  // low 5 bits are used on FM-77AV and later only
151         new_offset = (fm7_video.vram_offset & 0xff00) | (data & 0xe0);
152         break;
153   }
154   
155   fm7_video.vram_offset = new_offset;
156}
157
158/*
159 *  Main CPU: I/O ports 0xfd38-0xfd3f
160 *  Colour palette.
161 *  Each port represents one of eight colours.  Palette is 3-bit.
162 *  bit 2 = Green
163 *  bit 1 = Red
164 *  bit 0 = Blue
165 */
166READ8_HANDLER( fm7_palette_r )
167{
168   return fm7_video.fm7_pal[offset];
169}
170
171WRITE8_HANDLER( fm7_palette_w )
172{
173   UINT8 r = 0,g = 0,b = 0;
174   
175   if(data & 0x04)
176      g = 0xff;
177   if(data & 0x02)
178      r = 0xff;
179   if(data & 0x01)
180      b = 0xff;
181     
182   palette_set_color(space->machine,offset,MAKE_RGB(r,g,b));
183   fm7_video.fm7_pal[offset] = data & 0x07;
184}
185
186VIDEO_START( fm7 )
187{
188}
189
190VIDEO_UPDATE( fm7 )
191{
192    UINT8 code_r,code_g,code_b;
193    UINT8 col;
194    int y, x, b;
195
196   if(fm7_video.crt_enable == 0)
197      return 0;
198
199    for (y = 0; y < 200; y++)
200    {
201       for (x = 0; x < 80; x++)
202       {
203            code_r = fm7_video_ram[0x8000 + ((y*80 + x + fm7_video.vram_offset) & 0x3fff)];
204            code_g = fm7_video_ram[0x4000 + ((y*80 + x + fm7_video.vram_offset) & 0x3fff)];
205            code_b = fm7_video_ram[0x0000 + ((y*80 + x + fm7_video.vram_offset) & 0x3fff)];
206            for (b = 0; b < 8; b++)
207            {
208                col = (((code_r >> b) & 0x01) ? 4 : 0) + (((code_g >> b) & 0x01) ? 2 : 0) + (((code_b >> b) & 0x01) ? 1 : 0);
209                *BITMAP_ADDR16(bitmap, y,  x*8+(7-b)) =  col;
210            }
211        }
212    }
213   return 0;
214}
215
216static const rgb_t fm7_initial_palette[8] = {
217   MAKE_RGB(0x00, 0x00, 0x00), // 0
218   MAKE_RGB(0x00, 0x00, 0xff), // 1
219   MAKE_RGB(0xff, 0x00, 0x00), // 2
220   MAKE_RGB(0xff, 0x00, 0xff), // 3
221   MAKE_RGB(0x00, 0xff, 0x00), // 4
222   MAKE_RGB(0x00, 0xff, 0xff), // 5
223   MAKE_RGB(0xff, 0xff, 0x00), // 6
224   MAKE_RGB(0xff, 0xff, 0xff), // 7
225};
226
227PALETTE_INIT( fm7 )
228{
229   int x;
230   
231   palette_set_colors(machine, 0, fm7_initial_palette, ARRAY_LENGTH(fm7_initial_palette));
232   for(x=0;x<8;x++)
233      fm7_video.fm7_pal[x] = x;
234}
235
src/mess/includes/fm7.h
r0r5052
1/*
2 *
3 *  FM-7 header file
4 *
5 */
6
7#ifndef FM7_H_
8#define FM7_H_
9
10// Interrupt flags
11#define IRQ_FLAG_KEY      0x01
12#define IRQ_FLAG_PRINTER  0x02
13#define IRQ_FLAG_TIMER    0x04
14#define IRQ_FLAG_UNKNOWN  0x08
15// the following are not read in port 0xfd03
16#define IRQ_FLAG_MFD      0x10
17#define IRQ_FLAG_TXRDY    0x20
18#define IRQ_FLAG_RXRDY    0x40
19#define IRQ_FLAG_SYNDET   0x80
20
21struct fm7_video_flags
22{
23   UINT8 sub_busy;
24   UINT8 sub_halt;
25   UINT8 attn_irq;
26   UINT8 vram_access;  // VRAM access flag
27   UINT8 crt_enable;
28   UINT16 vram_offset;
29   UINT8 fm7_pal[8];
30};
31
32READ8_HANDLER( fm7_subintf_r );
33WRITE8_HANDLER( fm7_subintf_w );
34READ8_HANDLER( fm7_sub_busyflag_r );
35WRITE8_HANDLER( fm7_sub_busyflag_w );
36
37READ8_HANDLER( fm7_cancel_ack );
38READ8_HANDLER( fm7_attn_irq_r );
39
40READ8_HANDLER( fm7_vram_access_r );
41WRITE8_HANDLER( fm7_vram_access_w );
42READ8_HANDLER( fm7_vram_r );
43WRITE8_HANDLER( fm7_vram_w );
44READ8_HANDLER( fm7_crt_r );
45WRITE8_HANDLER( fm7_crt_w );
46WRITE8_HANDLER( fm7_vram_offset_w );
47
48READ8_HANDLER( fm7_palette_r );
49WRITE8_HANDLER( fm7_palette_w );
50
51VIDEO_START( fm7 );
52VIDEO_UPDATE( fm7 );
53PALETTE_INIT( fm7 );
54
55#endif /*FM7_H_*/
src/mess/mess.mak
r5051r5052
14071407   $(MESS_DRIVERS)/qx10.o \
14081408   $(MESS_DRIVERS)/fk1.o \
14091409   $(MESS_DRIVERS)/fm7.o \
1410   $(MESS_VIDEO)/fm7.o \
14101411   $(MESS_FORMATS)/fm7_cas.o \
14111412   $(MESS_FORMATS)/fm7_dsk.o \
14121413   $(MESS_DRIVERS)/fmtowns.o \
src/mess/drivers/fm7.c
r5051r5052
3939#include "formats/fm7_dsk.h"
4040#include "machine/ctronics.h"
4141
42// Interrupt flags
43#define IRQ_FLAG_KEY      0x01
44#define IRQ_FLAG_PRINTER  0x02
45#define IRQ_FLAG_TIMER    0x04
46#define IRQ_FLAG_UNKNOWN  0x08
47// the following are not read in port 0xfd03
48#define IRQ_FLAG_MFD      0x10
49#define IRQ_FLAG_TXRDY    0x20
50#define IRQ_FLAG_RXRDY    0x40
51#define IRQ_FLAG_SYNDET   0x80
42#include "includes/fm7.h"
5243
53UINT8* shared_ram;
5444UINT8* fm7_video_ram;
45UINT8* shared_ram;
5546static UINT8 irq_flags;  // active IRQ flags
5647static UINT8 irq_mask;  // IRQ mask
57emu_timer* fm7_timer;  // main timer, triggered every 2.0345ms?
58emu_timer* fm7_subtimer;  // sub-CPU timer, every 1 second?
48emu_timer* fm7_timer;  // main timer, triggered every 2.0345ms
49emu_timer* fm7_subtimer;  // sub-CPU timer, triggered every 20ms
5950emu_timer* fm7_keyboard_timer;
60static UINT8 sub_busy;
61static UINT8 sub_halt;
6251static UINT8 basic_rom_en;
63static UINT8 attn_irq;
64static UINT8 vram_access;  // VRAM access flag
65static UINT8 crt_enable;
6652unsigned int key_delay;
6753unsigned int key_repeat;
6854static UINT16 current_scancode;
6955static UINT32 key_data[4];
70static UINT16 vram_offset;
7156static UINT8 break_flag;
72static UINT8 fm7_pal[8];
7357static UINT8 fm7_psg_regsel;
7458static UINT8 psg_data;
7559static UINT8 fdc_side;
r5051r5052
7761static UINT8 fdc_irq_flag;
7862static UINT8 fdc_drq_flag;
7963
64extern struct fm7_video_flags fm7_video;
65
8066/* key scancode conversion table
8167 * The FM-7 expects different scancodes when shift,ctrl or graph is held, or
8268 * when kana is active.
r5051r5052
251237{
252238   UINT8 ret = 0xff;
253239   
254   if(attn_irq != 0)
240   if(fm7_video.attn_irq != 0)
255241   {
256242      ret &= ~0x01;
257      attn_irq = 0;
243      fm7_video.attn_irq = 0;
258244   }
259245   if(break_flag != 0)
260246   {
r5051r5052
263249   return ret;
264250}
265251
266/*
267 * Main CPU: Sub-CPU interface (port 0xfd05)
268 *
269 * Read:
270 *   bit 7: Sub-CPU busy (or halted)
271 *   bit 0: EXTDET (?)
272 * Write:
273 *   bit 7: Sub-CPU halt
274 *   bit 6: Sub-CPU cancel IRQ
275 */
276
277READ8_HANDLER( fm7_subintf_r )
278{
279   UINT8 ret = 0x00;
280   
281   if(sub_busy != 0 || sub_halt != 0)
282      ret |= 0x80;
283     
284   ret |= 0x7e;
285   //ret |= 0x01; // EXTDET (not implemented yet)
286   
287   return ret;
288}
289
290WRITE8_HANDLER( fm7_subintf_w )
291{
292   sub_halt = data & 0x80;
293   if(data & 0x80)
294      sub_busy = data & 0x80;
295
296   cputag_set_input_line(space->machine,"sub",INPUT_LINE_HALT,(data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
297   if(data & 0x40)
298      cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,ASSERT_LINE);
299   //popmessage("Sub CPU Interface write: %02x\n",data);
300}
301
302READ8_HANDLER( fm7_sub_busyflag_r )
303{
304   if(sub_halt == 0)
305      sub_busy = 0x00;
306   return 0x00;
307}
308
309WRITE8_HANDLER( fm7_sub_busyflag_w )
310{
311   sub_busy = 0x80;
312}
313
314252/*
315253 *  Main CPU: I/O port 0xfd0f
316254 *
r5051r5052
337275}
338276
339277/*
340 * Sub-CPU port 0xd402
341 *   Read-only: Acknowledge Cancel IRQ
342 */
343READ8_HANDLER( fm7_cancel_ack )
344{
345   cputag_set_input_line(space->machine,"sub",M6809_IRQ_LINE,CLEAR_LINE);
346   return 0x00;
347}
348
349/*
350 * Reading from 0xd404 (sub-CPU) causes an "Attention" FIRQ on the main CPU
351 */
352READ8_HANDLER( fm7_attn_irq_r )
353{
354   attn_irq = 1;
355   cputag_set_input_line(space->machine,"maincpu",M6809_FIRQ_LINE,ASSERT_LINE);
356   return 0xff;
357}
358
359/*
360 *  Sub CPU: I/O port 0xd409
361 *
362 *  On read, enables VRAM access
363 *  On write, disables VRAM access
364 */
365READ8_HANDLER( fm7_vram_access_r )
366{
367   vram_access = 1;
368   return 0xff;
369}
370
371WRITE8_HANDLER( fm7_vram_access_w )
372{
373   vram_access = 0;
374}
375
376READ8_HANDLER( fm7_vram_r )
377{
378   int offs;
379   
380   offs = (offset & 0xc000) | ((offset + vram_offset) & 0x3fff);
381   return fm7_video_ram[offs];
382}
383
384WRITE8_HANDLER( fm7_vram_w )
385{
386   int offs;
387   
388   offs = (offset & 0xc000) | ((offset + vram_offset) & 0x3fff);
389   if(vram_access != 0)
390      fm7_video_ram[offs] = data;
391}
392
393/*
394 *  Sub CPU: I/O port 0xd408
395 *
396 *  On read, enables the CRT display
397 *  On write, disables the CRT display
398 */
399READ8_HANDLER( fm7_crt_r )
400{
401   crt_enable = 1;
402   return 0xff;
403}
404
405WRITE8_HANDLER( fm7_crt_w )
406{
407   crt_enable = 0;
408}
409
410/*
411278 *  Main CPU: I/O ports 0xfd18 - 0xfd1f
412279 *  Floppy Disk Controller (MB8877A)
413280 */
r5051r5052
512379}
513380
514381/*
515 *  Sub CPU: I/O ports 0xd40e - 0xd40f
516 *
517 *  0xd40e: bits 0-6 - offset in bytes (high byte) (bit 6 is used for 400 line video only)
518 *  0xd40f: bits 0-7 - offset in bytes (low byte)
519 */
520WRITE8_HANDLER( fm7_vram_offset_w )
521{
522   UINT16 new_offset = 0;
523   
524   switch(offset)
525   {
526      case 0:
527         new_offset = (data << 8) | (vram_offset & 0x00ff);
528         break;
529      case 1:  // low 5 bits are used on FM-77AV and later only
530         new_offset = (vram_offset & 0xff00) | (data & 0xe0);
531         break;
532   }
533   
534   vram_offset = new_offset;
535}
536
537/*
538382 *  Main CPU: I/O ports 0xfd00-0xfd01
539383 *  Sub CPU: I/O ports 0xd400-0xd401
540384 *
r5051r5052
651495}
652496
653497/*
654 *  Main CPU: I/O ports 0xfd38-0xfd3f
655 *  Colour palette.
656 *  Each port represents one of eight colours.  Palette is 3-bit.
657 *  bit 2 = Green
658 *  bit 1 = Red
659 *  bit 0 = Blue
660 */
661static READ8_HANDLER( fm7_palette_r )
662{
663   return fm7_pal[offset];
664}
665
666static WRITE8_HANDLER( fm7_palette_w )
667{
668   UINT8 r = 0,g = 0,b = 0;
669   
670   if(data & 0x04)
671      g = 0xff;
672   if(data & 0x02)
673      r = 0xff;
674   if(data & 0x01)
675      b = 0xff;
676     
677   palette_set_color(space->machine,offset,MAKE_RGB(r,g,b));
678   fm7_pal[offset] = data & 0x07;
679}
680
681/*
682498 *  Main CPU: I/O ports 0xfd0d-0xfd0e
683499 *  PSG (AY-3-891x)
684500 *  0xfd0d - function select (bit 1 = BDIR, bit 0 = BC1)
r5051r5052
735551// Shared RAM is only usable on the main CPU if the sub CPU is halted
736552static READ8_HANDLER( fm7_main_shared_r )
737553{
738   if(sub_halt != 0)
554   if(fm7_video.sub_halt != 0)
739555      return shared_ram[offset];
740556   else
741557      return 0xff;
r5051r5052
743559
744560static WRITE8_HANDLER( fm7_main_shared_w )
745561{
746   if(sub_halt != 0)
562   if(fm7_video.sub_halt != 0)
747563      shared_ram[offset] = data;
748564}
749565
r5051r5052
1123939   timer_adjust_periodic(fm7_keyboard_timer,attotime_zero,0,ATTOTIME_IN_MSEC(10));
1124940   irq_mask = 0xff;
1125941   irq_flags = 0x00;
1126   attn_irq = 0;
1127   sub_busy = 0x80;  // busy at reset
942   fm7_video.attn_irq = 0;
943   fm7_video.sub_busy = 0x80;  // busy at reset
1128944   basic_rom_en = 1;  // enabled at reset
1129   vram_access = 0;
1130   crt_enable = 0;
945   fm7_video.vram_access = 0;
946   fm7_video.crt_enable = 0;
1131947   memory_set_bankptr(machine,1,RAM+0x38000);
1132948   key_delay = 700;  // 700ms on FM-7
1133949   key_repeat = 70;  // 70ms on FM-7
1134   vram_offset = 0x0000;
950   fm7_video.vram_offset = 0x0000;
1135951   break_flag = 0;
1136952   fm7_psg_regsel = 0;
1137953   fdc_side = 0;
r5051r5052
1148964   }
1149965}
1150966
1151static VIDEO_START( fm7 )
1152{
1153}
1154
1155static VIDEO_UPDATE( fm7 )
1156{
1157    UINT8 code_r,code_g,code_b;
1158    UINT8 col;
1159    int y, x, b;
1160
1161   if(crt_enable == 0)
1162      return 0;
1163
1164    for (y = 0; y < 200; y++)
1165    {
1166       for (x = 0; x < 80; x++)
1167       {
1168            code_r = fm7_video_ram[0x8000 + ((y*80 + x + vram_offset) & 0x3fff)];
1169            code_g = fm7_video_ram[0x4000 + ((y*80 + x + vram_offset) & 0x3fff)];
1170            code_b = fm7_video_ram[0x0000 + ((y*80 + x + vram_offset) & 0x3fff)];
1171            for (b = 0; b < 8; b++)
1172            {
1173                col = (((code_r >> b) & 0x01) ? 4 : 0) + (((code_g >> b) & 0x01) ? 2 : 0) + (((code_b >> b) & 0x01) ? 1 : 0);
1174                *BITMAP_ADDR16(bitmap, y,  x*8+(7-b)) =  col;
1175            }
1176        }
1177    }
1178   return 0;
1179}
1180
1181static const rgb_t fm7_initial_palette[8] = {
1182   MAKE_RGB(0x00, 0x00, 0x00), // 0
1183   MAKE_RGB(0x00, 0x00, 0xff), // 1
1184   MAKE_RGB(0xff, 0x00, 0x00), // 2
1185   MAKE_RGB(0xff, 0x00, 0xff), // 3
1186   MAKE_RGB(0x00, 0xff, 0x00), // 4
1187   MAKE_RGB(0x00, 0xff, 0xff), // 5
1188   MAKE_RGB(0xff, 0xff, 0x00), // 6
1189   MAKE_RGB(0xff, 0xff, 0xff), // 7
1190};
1191
1192PALETTE_INIT( fm7 )
1193{
1194   int x;
1195   
1196   palette_set_colors(machine, 0, fm7_initial_palette, ARRAY_LENGTH(fm7_initial_palette));
1197   for(x=0;x<8;x++)
1198      fm7_pal[x] = x;
1199}
1200
1201//static DEVICE_IMAGE_LOAD( fm7_floppy )
1202//{
1203//   if (device_load_basicdsk_floppy(image)==INIT_PASS)
1204//   {
1205      /* drive, tracks, heads, sectors per track, sector length, first sector id */
1206//      basicdsk_set_geometry(image, 40, 2, 16, 256, 0x01, 0x2c0, FALSE);
1207//      return INIT_PASS;
1208//   }
1209
1210//   return INIT_FAIL;
1211//}
1212
1213967static const wd17xx_interface fm7_mb8877a_interface =
1214968{
1215969   fm7_fdc_irq,

Previous 15994 Revisions Next


© 1998-2018 The MESS Team