Previous 15994 Revisions Next

r5931 Wednesday 30th September, 2009 at 23:20:35 UTC by Fabio Priuli
[PC8801] removed macros which only made the code harder to read and understand
[src/mess/drivers]pc8801.c
[src/mess/includes]pc8801.h
[src/mess/video]pc8801.c

src/mess/video/pc8801.c
r5930r5931
55***************************************************************************/
66
77/* NOTE: The palette and colortable have been fixed after the changes in the 0.123-0.124 cycle,
8   but the pen colours may be wrong. This needs to be tested. */
8    but the pen colours may be wrong. This needs to be tested. */
99
1010#include "driver.h"
1111#include "machine/i8255a.h"
r5930r5931
1414/* NPW 23-Oct-2001 - Adding this so that it compiles */
1515#define palette_transparent_pen   0
1616
17unsigned char *pc88sr_textRAM=NULL;
17unsigned char *pc88sr_textRAM = NULL;
1818int pc8801_is_24KHz;
19static unsigned char *gVRAM=NULL;
19static unsigned char *gVRAM = NULL;
2020static int selected_vram;
21static int crtcON,textON,text_width=40,text_height=20,text_invert,text_color;
22static int text_cursor,text_cursorX,text_cursorY;
23static int blink_period=24;
21static int crtc_on, text_on, text_width = 40, text_height = 20, text_invert, text_color;
22static int text_cursor, text_cursorX, text_cursorY;
23static int blink_period = 24;
2424static int analog_palette;
25static int ALU1,ALU2,ALUON;
26static unsigned char ALU_save0,ALU_save1,ALU_save2;
25static int alu_1, alu_2, alu_on;
26static unsigned char alu_save0, alu_save1, alu_save2;
2727
28static int dmac_FL;
29static UINT16 dmac_addr[3],dmac_size[3];
30static UINT8 dmac_flag,dmac_status;
28static int dmac_fl;
29static UINT16 dmac_addr[3], dmac_size[3];
30static UINT8 dmac_flag, dmac_status;
3131
3232static enum
3333{
r5930r5931
7777#define TX_WID_MASK   0x0300
7878#define TX_WID_SHIFT   8
7979
80static char *graph_dirty=NULL;
81static unsigned short *attr_tmp=NULL,*attr_old=NULL,*text_old=NULL;
82static bitmap_t *wbm1,*wbm2;
80static char *graph_dirty = NULL;
81static unsigned short *attr_tmp = NULL, *attr_old = NULL, *text_old = NULL;
82static bitmap_t *wbm1, *wbm2;
8383
8484#define TRAM(x,y) (pc88sr_is_highspeed ? \
8585   pc88sr_textRAM[(dmac_addr[2]+(x)+(y)*120)&0xfff] : \
r5930r5931
8989#define ATTR_OLD(x,y) (attr_old[(x)+(y)*80])
9090#define GRP_DIRTY(x,y) (graph_dirty[(x)+(y)*80])
9191
92INLINE void pc8801_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
92INLINE void pc8801_plot_pixel( bitmap_t *bitmap, int x, int y, UINT32 color )
9393{
9494   *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color;
9595}
9696
97void pc8801_video_init (running_machine *machine, int hireso)
97void pc8801_video_init( running_machine *machine, int hireso )
9898{
9999   const device_config *screen = video_screen_first(machine->config);
100100   int width = video_screen_get_width(screen);
r5930r5931
102102
103103   wbm1 = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
104104   wbm2 = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
105   pc8801_is_24KHz=hireso;
106   crtcON=0;
107   textON=1;
105   pc8801_is_24KHz = hireso;
106   crtc_on = 0;
107   text_on = 1;
108108
109   dmac_FL=0;
110   dmac_addr[0]=dmac_size[0]=0;
111   dmac_addr[1]=dmac_size[1]=0;
112   dmac_addr[2]=dmac_size[2]=0;
113   dmac_flag=dmac_status=0;
109   dmac_fl = 0;
110   dmac_addr[0] = dmac_size[0] = 0;
111   dmac_addr[1] = dmac_size[1] = 0;
112   dmac_addr[2] = dmac_size[2] = 0;
113   dmac_flag = dmac_status = 0;
114114
115115   gVRAM = auto_alloc_array(machine, UINT8, 0xc000);
116116   pc88sr_textRAM = auto_alloc_array(machine, UINT8, 0x1000);
r5930r5931
119119   text_old = auto_alloc_array(machine, UINT16, 80*100);
120120   graph_dirty = auto_alloc_array(machine, char, 80*100);
121121
122   memset(gVRAM,0,0xc000);
123   memset(pc88sr_textRAM,0,0x1000);
124   selected_vram=0;
125   ALUON=0;
126   analog_palette=0;
122   memset(gVRAM, 0, 0xc000);
123   memset(pc88sr_textRAM, 0, 0x1000);
124   selected_vram = 0;
125   alu_on = 0;
126   analog_palette = 0;
127127}
128128
129static WRITE8_HANDLER(write_gvram)
129static WRITE8_HANDLER( write_gvram )
130130{
131  int x,y;
131   int x, y;
132132
133  if(gVRAM[offset]!=data) {
134    gVRAM[offset]=data;
135    switch(gmode) {
136    case GRAPH_200_COL:
137    case GRAPH_200_BW:
138      x=(offset&0x3fff)%80;
139      y=(offset&0x3fff)/80/2;
140      break;
141    case GRAPH_400_BW:
142      x=(offset&0x3fff)%80;
143      y=(offset&0x3fff)/80/4+(offset/0x4000)*50;
144      break;
145    case GRAPH_NO:
146    default:
147      return;
148    }
149    if(y<100) GRP_DIRTY(x,y)=1;
150  }
133   if (gVRAM[offset] != data)
134   {
135      gVRAM[offset] = data;
136      switch (gmode)
137      {
138      case GRAPH_200_COL:
139      case GRAPH_200_BW:
140         x = (offset & 0x3fff) % 80;
141         y = (offset & 0x3fff) / 80 / 2;
142         break;
143      case GRAPH_400_BW:
144         x = (offset & 0x3fff) % 80;
145         y = (offset & 0x3fff) / 80 / 4 + (offset / 0x4000) * 50;
146         break;
147      case GRAPH_NO:
148      default:
149         return;
150      }
151      if (y < 100)
152         GRP_DIRTY(x, y) = 1;
153   }
151154}
152155
153/* NPW 8-Feb-2004 - This pseudo template stuff is an abomination.  Whomever wrote this should be shot */
154156
155#define VVV \
156   XXX(0) \
157   XXX(1) \
158   XXX(2)
157static WRITE8_HANDLER(write_gvram0_bank5){write_gvram(space, offset + 0x4000 * 0, data);}
158static WRITE8_HANDLER(write_gvram0_bank6){write_gvram(space, offset + 0x4000 * 0 + 0x3000, data);}
159static WRITE8_HANDLER(write_gvram1_bank5){write_gvram(space, offset + 0x4000 * 1, data);}
160static WRITE8_HANDLER(write_gvram1_bank6){write_gvram(space, offset + 0x4000 * 1 + 0x3000, data);}
161static WRITE8_HANDLER(write_gvram2_bank5){write_gvram(space, offset + 0x4000 * 2, data);}
162static WRITE8_HANDLER(write_gvram2_bank6){write_gvram(space, offset + 0x4000 * 2 + 0x3000, data);}
159163
160#define XXX(n) \
161static WRITE8_HANDLER(write_gvram##n##_bank5){write_gvram(space, offset+0x4000*n,data);} \
162static WRITE8_HANDLER(write_gvram##n##_bank6){write_gvram(space, offset+0x4000*n+0x3000,data);}
163   VVV
164#undef XXX
165164
166#define YYY \
167   XXX(0) \
168   XXX(1) \
169   XXX(2) \
170   XXX(3) \
171   XXX(4) \
172   XXX(5) \
173   XXX(6) \
174   XXX(7)
165static UINT8 read_save_alu( int x, UINT32 offset )
166{
167   alu_save0 = gVRAM[offset + 0x0000];
168   alu_save1 = gVRAM[offset + 0x4000];
169   alu_save2 = gVRAM[offset + 0x8000];
175170
176#define ZZZ \
177   XXX(0) \
178   XXX(1) \
179   XXX(2) \
180   XXX(3)
171   return (x & 1 ? gVRAM[offset + 0x0000] : ~gVRAM[offset + 0x0000]) &
172         (x & 2 ? gVRAM[offset + 0x4000] : ~gVRAM[offset + 0x4000]) &
173         (x & 4 ? gVRAM[offset + 0x8000] : ~gVRAM[offset + 0x8000]);
174}
181175
182#define XXX(x) \
183static  READ8_HANDLER(read_gvram_alu##x) \
184{ \
185  ALU_save0 = gVRAM[offset+0x0000]; \
186  ALU_save1 = gVRAM[offset+0x4000]; \
187  ALU_save2 = gVRAM[offset+0x8000]; \
188  return \
189    (x & 1 ? gVRAM[offset+0x0000] : ~gVRAM[offset+0x0000]) & \
190    (x & 2 ? gVRAM[offset+0x4000] : ~gVRAM[offset+0x4000]) & \
191    (x & 4 ? gVRAM[offset+0x8000] : ~gVRAM[offset+0x8000]); \
192} \
193static  READ8_HANDLER(read_gvram_alu##x##_bank5){return read_gvram_alu##x(space, offset);} \
194static  READ8_HANDLER(read_gvram_alu##x##_bank6){return read_gvram_alu##x(space, offset+0x3000);}
176static READ8_HANDLER(read_gvram_alu0_bank5){return read_save_alu(0, offset);}
177static READ8_HANDLER(read_gvram_alu0_bank6){return read_save_alu(0, offset + 0x3000);}
178static READ8_HANDLER(read_gvram_alu1_bank5){return read_save_alu(1, offset);}
179static READ8_HANDLER(read_gvram_alu1_bank6){return read_save_alu(1, offset + 0x3000);}
180static READ8_HANDLER(read_gvram_alu2_bank5){return read_save_alu(2, offset);}
181static READ8_HANDLER(read_gvram_alu2_bank6){return read_save_alu(2, offset + 0x3000);}
182static READ8_HANDLER(read_gvram_alu3_bank5){return read_save_alu(3, offset);}
183static READ8_HANDLER(read_gvram_alu3_bank6){return read_save_alu(3, offset + 0x3000);}
184static READ8_HANDLER(read_gvram_alu4_bank5){return read_save_alu(4, offset);}
185static READ8_HANDLER(read_gvram_alu4_bank6){return read_save_alu(4, offset + 0x3000);}
186static READ8_HANDLER(read_gvram_alu5_bank5){return read_save_alu(5, offset);}
187static READ8_HANDLER(read_gvram_alu5_bank6){return read_save_alu(5, offset + 0x3000);}
188static READ8_HANDLER(read_gvram_alu6_bank5){return read_save_alu(6, offset);}
189static READ8_HANDLER(read_gvram_alu6_bank6){return read_save_alu(6, offset + 0x3000);}
190static READ8_HANDLER(read_gvram_alu7_bank5){return read_save_alu(7, offset);}
191static READ8_HANDLER(read_gvram_alu7_bank6){return read_save_alu(7, offset + 0x3000);}
195192
196YYY
197193
198#undef XXX
199
200194static WRITE8_HANDLER(write_gvram_alu0)
201195{
202#define WWW(x) \
203  switch(ALU1&(0x11<<x)) { \
204  case 0x00<<x: \
205    write_gvram(space, offset+x*0x4000,gVRAM[offset+x*0x4000]&(~data)); \
206    break; \
207  case 0x01<<x: \
208    write_gvram(space, offset+x*0x4000,gVRAM[offset+x*0x4000]|data); \
209    break; \
210  case 0x10<<x: \
211    write_gvram(space, offset+x*0x4000,gVRAM[offset+x*0x4000]^data); \
212    break; \
213  case 0x11<<x: \
214    break; \
215  }
196   switch (alu_1 & 0x11)
197   {
198   case 0x00:
199      write_gvram(space, offset, gVRAM[offset] & ~data);
200      break;
201   case 0x01:
202      write_gvram(space, offset, gVRAM[offset] | data);
203      break;
204   case 0x10:
205      write_gvram(space, offset, gVRAM[offset] ^ data);
206      break;
207   case 0x11:
208      break;
209   }
216210
217  WWW(0)
218  WWW(1)
219  WWW(2)
211   switch (alu_1 & (0x11 << 1))
212   {
213   case 0x00 << 1:
214      write_gvram(space, offset + 0x4000, gVRAM[offset + 0x4000] & ~data);
215      break;
216   case 0x01 << 1:
217      write_gvram(space, offset + 0x4000, gVRAM[offset + 0x4000] | data);
218      break;
219   case 0x10 << 1:
220      write_gvram(space, offset + 0x4000, gVRAM[offset + 0x4000] ^ data);
221      break;
222   case 0x11 << 1:
223      break;
224   }
220225
221#undef WWW
226   switch (alu_1 & (0x11 << 2))
227   {
228   case 0x00 << 2:
229      write_gvram(space, offset + 0x8000, gVRAM[offset + 0x8000] & ~data);
230      break;
231   case 0x01 << 2:
232      write_gvram(space, offset + 0x8000, gVRAM[offset + 0x8000] | data);
233      break;
234   case 0x10 << 2:
235      write_gvram(space, offset + 0x8000, gVRAM[offset + 0x8000] ^ data);
236      break;
237   case 0x11 << 2:
238      break;
239   }
222240}
241
223242static WRITE8_HANDLER(write_gvram_alu1)
224243{
225  write_gvram(space, offset+0x0000 , ALU_save0);
226  write_gvram(space, offset+0x4000 , ALU_save1);
227  write_gvram(space, offset+0x8000 , ALU_save2);
244   write_gvram(space, offset + 0x0000 , alu_save0);
245   write_gvram(space, offset + 0x4000 , alu_save1);
246   write_gvram(space, offset + 0x8000 , alu_save2);
228247}
229static WRITE8_HANDLER(write_gvram_alu2){write_gvram(space, offset+0x0000,ALU_save1);}
230static WRITE8_HANDLER(write_gvram_alu3){write_gvram(space, offset+0x4000,ALU_save0);}
231248
232#define XXX(x) \
233static WRITE8_HANDLER(write_gvram_alu##x##_bank5){write_gvram_alu##x(space, offset,data);} \
234static WRITE8_HANDLER(write_gvram_alu##x##_bank6){write_gvram_alu##x(space, offset+0x3000,data);}
249static WRITE8_HANDLER(write_gvram_alu2){write_gvram(space, offset + 0x0000, alu_save1);}
235250
236ZZZ
251static WRITE8_HANDLER(write_gvram_alu3){write_gvram(space, offset + 0x4000, alu_save0);}
237252
238#undef XXX
239253
240int is_pc8801_vram_select(running_machine *machine)
254static WRITE8_HANDLER(write_gvram_alu0_bank5){write_gvram_alu0(space, offset,data);}
255static WRITE8_HANDLER(write_gvram_alu0_bank6){write_gvram_alu0(space, offset + 0x3000,data);}
256static WRITE8_HANDLER(write_gvram_alu1_bank5){write_gvram_alu1(space, offset,data);}
257static WRITE8_HANDLER(write_gvram_alu1_bank6){write_gvram_alu1(space, offset + 0x3000,data);}
258static WRITE8_HANDLER(write_gvram_alu2_bank5){write_gvram_alu2(space, offset,data);}
259static WRITE8_HANDLER(write_gvram_alu2_bank6){write_gvram_alu2(space, offset + 0x3000,data);}
260static WRITE8_HANDLER(write_gvram_alu3_bank5){write_gvram_alu3(space, offset,data);}
261static WRITE8_HANDLER(write_gvram_alu3_bank6){write_gvram_alu3(space, offset + 0x3000,data);}
262
263
264int is_pc8801_vram_select( running_machine *machine )
241265{
242266   read8_space_func rh5 = NULL, rh6 = NULL;
243267   write8_space_func wh5 = NULL, wh6 = NULL;
244268
245  if(ALUON) {
246    /* ALU mode */
247    if(ALU2&0x80) {
248      /* ALU VRAM */
249      switch(ALU2&0x07) {
250#define XXX(x) \
251      case x: \
252   rh5 = read_gvram_alu##x##_bank5; \
253   rh6 = read_gvram_alu##x##_bank6; \
254   break;
269   if (alu_on)
270   {
271      /* ALU mode */
272      if (alu_2 & 0x80)
273      {
274         /* ALU VRAM */
275         switch (alu_2 & 0x07)
276         {
277         case 0:
278            rh5 = read_gvram_alu0_bank5;
279            rh6 = read_gvram_alu0_bank6;
280            break;
281         case 1:
282            rh5 = read_gvram_alu1_bank5;
283            rh6 = read_gvram_alu1_bank6;
284            break;
285         case 2:
286            rh5 = read_gvram_alu2_bank5;
287            rh6 = read_gvram_alu2_bank6;
288            break;
289         case 3:
290            rh5 = read_gvram_alu3_bank5;
291            rh6 = read_gvram_alu3_bank6;
292            break;
293         case 4:
294            rh5 = read_gvram_alu4_bank5;
295            rh6 = read_gvram_alu4_bank6;
296            break;
297         case 5:
298            rh5 = read_gvram_alu5_bank5;
299            rh6 = read_gvram_alu5_bank6;
300            break;
301         case 6:
302            rh5 = read_gvram_alu6_bank5;
303            rh6 = read_gvram_alu6_bank6;
304            break;
305         case 7:
306            rh5 = read_gvram_alu7_bank5;
307            rh6 = read_gvram_alu7_bank6;
308            break;
309            }
255310
256   YYY
311         switch (alu_2 & 0x30)
312         {
313         case 0x00:
314            wh5 = write_gvram_alu0_bank5;
315            wh6 = write_gvram_alu0_bank6;
316            break;
317         case 0x10:
318            wh5 = write_gvram_alu1_bank5;
319            wh6 = write_gvram_alu1_bank6;
320            break;
321         case 0x20:
322            wh5 = write_gvram_alu2_bank5;
323            wh6 = write_gvram_alu2_bank6;
324            break;
325         case 0x30:
326            wh5 = write_gvram_alu3_bank5;
327            wh6 = write_gvram_alu3_bank6;
328            break;
329              }
330            return 1;
331      }
332      else
333      {
334         /* MAIN RAM */
335         return 0;
336      }
337   }
338   else
339   {
340      /* old mode */
341      switch (selected_vram)
342      {
343      case 1:
344         rh5 = SMH_BANK(5);
345         rh6 = SMH_BANK(6);
346         wh5 = write_gvram0_bank5;
347         wh6 = write_gvram0_bank6;
348         memory_set_bankptr(machine, 5, gVRAM );
349         memory_set_bankptr(machine, 6, gVRAM + 0x3000 );
350         return 1;
257351
258#undef XXX
259#undef YYY
260      }
261      switch(ALU2&0x30) {
262#define XXX(x) \
263      case x<<4: \
264   wh5 = write_gvram_alu##x##_bank5; \
265   wh6 = write_gvram_alu##x##_bank6; \
266   break;
352      case 2:
353         rh5 = SMH_BANK(5);
354         rh6 = SMH_BANK(6);
355         wh5 = write_gvram1_bank5;
356         wh6 = write_gvram1_bank6;
357         memory_set_bankptr(machine, 5, gVRAM + 0x4000 );
358         memory_set_bankptr(machine, 6, gVRAM + 0x4000 + 0x3000 );
359         return 1;
267360
268   ZZZ
361      case 3:
362         rh5 = SMH_BANK(5);
363         rh6 = SMH_BANK(6);
364         wh5 = write_gvram2_bank5;
365         wh6 = write_gvram2_bank6;
366         memory_set_bankptr(machine, 5, gVRAM + 0x8000 );
367         memory_set_bankptr(machine, 6, gVRAM + 0x8000 + 0x3000 );
368         return 1;
269369
270#undef XXX
271#undef ZZZ
272      }
273      return 1;
274    } else {
275      return 0; /* MAIN RAM */
276    }
277  } else {
278    /* old mode */
279    switch(selected_vram) {
280#define XXX(n) \
281    case (n+1): \
282      rh5 = SMH_BANK(5); \
283      rh6 = SMH_BANK(6); \
284      wh5 = write_gvram##n##_bank5; \
285      wh6 = write_gvram##n##_bank6; \
286      memory_set_bankptr(machine, 5, gVRAM + 0x4000*n ); \
287      memory_set_bankptr(machine, 6, gVRAM + 0x4000*n + 0x3000 ); \
288      return 1;
370      default:
371         return 0; /* MAIN RAM */
372      }
373   }
289374
290      VVV
291
292#undef XXX
293#undef VVV
294
295    default:
296      return 0; /* MAIN RAM */
297    }
298  }
299
300
301375   if (rh5) memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc000, 0xefff, 0, 0, rh5);
302376   if (wh5) memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc000, 0xefff, 0, 0, wh5);
303377   if (rh6) memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xf000, 0xffff, 0, 0, rh6);
304378   if (wh6) memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xf000, 0xffff, 0, 0, wh6);
305379}
306380
307WRITE8_HANDLER(pc88sr_disp_32)
381WRITE8_HANDLER( pc88sr_disp_32 )
308382{
309  analog_palette=((data & 0x20) != 0x00);
310  ALUON=((data & 0x40) != 0x00);
311  pc8801_update_bank(space->machine);
383   analog_palette = ((data & 0x20) != 0x00);
384   alu_on = ((data & 0x40) != 0x00);
385   pc8801_update_bank(space->machine);
312386}
313387
314WRITE8_HANDLER(pc88sr_ALU)
388WRITE8_HANDLER( pc88sr_alu )
315389{
316  switch(offset) {
317  case 0:
318    ALU1=data;
319    break;
320  case 1:
321    ALU2=data;
322    break;
323  }
324  pc8801_update_bank(space->machine);
390   switch (offset)
391   {
392   case 0:
393      alu_1 = data;
394      break;
395   case 1:
396      alu_2 = data;
397      break;
398   }
399   pc8801_update_bank(space->machine);
325400}
326401
327WRITE8_HANDLER(pc8801_vramsel)
402WRITE8_HANDLER( pc8801_vramsel )
328403{
329  if(offset==3) {
330    selected_vram=0;
331  } else {
332    selected_vram=offset+1;
333  }
334  pc8801_update_bank(space->machine);
404   if (offset == 3)
405      selected_vram = 0;
406   else
407      selected_vram = offset + 1;
408
409   pc8801_update_bank(space->machine);
335410}
336411
337 READ8_HANDLER(pc8801_vramtest)
412READ8_HANDLER( pc8801_vramtest )
338413{
339  switch(selected_vram) {
340  case 1: return 0xf9;
341  case 2: return 0xfa;
342  case 3: return 0xfc;
343  default: return 0xf8;
344  }
414   switch (selected_vram)
415   {
416   case 1:  return 0xf9;
417   case 2:  return 0xfa;
418   case 3:  return 0xfc;
419   default: return 0xf8;
420   }
345421}
346422
347423VIDEO_START( pc8801 )
r5930r5931
352428
353429VIDEO_UPDATE( pc8801 )
354430{
355  int x,y,attr_new,text_new,i,a,tx,ty,oy,gx,gy,ct,cg;
356  static int blink_count;
357  int full_refresh = 1;
431   int x, y, attr_new, text_new, i, a, tx, ty, oy, gx, gy, ct, cg;
432   static int blink_count;
433   int full_refresh = 1;
358434
359  blink_count=(blink_count+1)%(blink_period*4);
360  /* attribute expand */
361  for(y=0;y<25;y++) {
362    x=0;
363    attr_new=7 << TX_COL_SHIFT;
364    for(i=0;i<=20;i++) {
365      a=TRAM(80+i*2+1,y);
366      if(text_color) {
367   /* color mode */
368   if(a&0x08) {
369     /* color */
370     attr_new=(attr_new&0x00ff)|((a&0xf0)<<8);
371   } else {
372       /* attr */
373     attr_new=(attr_new&0xff00)|(a&37);
435   blink_count = (blink_count + 1) % (blink_period * 4);
436   /* attribute expand */
437   for (y = 0; y < 25; y++)
438   {
439      x = 0;
440      attr_new = 7 << TX_COL_SHIFT;
441      for (i = 0; i <= 20; i++)
442      {
443         a = TRAM(80 + i * 2 + 1, y);
444         if (text_color)
445         {
446            /* color mode */
447            if (a & 0x08)
448            {
449               /* color */
450               attr_new = (attr_new & 0x00ff) | ((a & 0xf0) << 8);
451            }
452            else
453            {
454               /* attr */
455               attr_new = (attr_new & 0xff00)|(a & 37);
456            }
457         }
458         else
459         {
460            /* B/W mode */
461            attr_new = (a & 0x37) | ((a & 0x80) << 5) | (7 << TX_COL_SHIFT);
462         }
463         if (TRAM(118, y) == 0x80)
464         {
465            while (x < TRAM(80 + i * 2, y) && x < 80)
466            {
467               ATTR_TMP(x, y) = attr_new;
468               x++;
469            };
470         }
471         else
472         {
473            while (x < TRAM(80 + i * 2 + 2, y) && x < 80)
474            {
475               ATTR_TMP(x, y) = attr_new;
476               x++;
477            };
478         }
479      }
480      while (x < 80)
481      {
482         ATTR_TMP(x, y) = attr_new;
483         x++;
484      };
374485   }
375      } else {
376   /* B/W mode */
377   attr_new=(a&0x37)|((a&0x80)<<5)|(7 << TX_COL_SHIFT);
378      }
379      if(TRAM(118,y)==0x80) {
380   while(x<TRAM(80+i*2,y) && x<80) {
381     ATTR_TMP(x,y)=attr_new;
382     x++;
383   };
384      } else {
385   while(x<TRAM(80+i*2+2,y) && x<80) {
386     ATTR_TMP(x,y)=attr_new;
387     x++;
388   };
389      }
390    }
391    while(x<80) {
392      ATTR_TMP(x,y)=attr_new;
393      x++;
394    };
395  }
396  if(text_cursor &&
397     (text_cursorX>=0 || text_cursorX<80) &&
398     (text_cursorY>=0 || text_cursorY<25)) {
399    ATTR_TMP(text_cursorX,text_cursorY)|=TX_CUR;
400  }
401
402  /* display draw */
403  for(y=0;y<100;y++)
404  {
405    ty=y/(100/text_height);
406    oy=y%(100/text_height);
407    for(x=0;x<80;x++) {
408      /* text */
409      if(text_width==40) {
410   tx=x&(~1);
411      } else {
412   tx=x;
413      }
414      attr_new=ATTR_TMP(tx,ty);
415      if(oy<4) {
416   text_new=TRAM(tx,ty)*4+oy;
417      } else {
418   text_new=0;
419      }
420      if(attr_new&TX_SEC) {
421   text_new=0;
422   attr_new&=~TX_SEC;
423      }
424      if(attr_new&TX_BL) {
425   attr_new&=~TX_BL;
426   if((blink_count/blink_period)&1) attr_new^=TX_REV;
427      }
428      if(attr_new&TX_CUR) {
429   attr_new&=~TX_CUR;
430   switch(cursor_mode) {
431   case noblink_underline:
432     attr_new^=TX_UL;
433     break;
434   case blink_underline:
435     if(blink_count/blink_period) attr_new^=TX_UL;
436     break;
437   case noblink_block:
438     attr_new^=TX_REV;
439     break;
440   case blink_block:
441     if(blink_count/blink_period) attr_new^=TX_REV;
442     break;
486   if (text_cursor && (text_cursorX >= 0 || text_cursorX < 80) && (text_cursorY >= 0 || text_cursorY < 25))
487   {
488      ATTR_TMP(text_cursorX, text_cursorY) |= TX_CUR;
443489   }
444      }
445      if((attr_new&TX_UL) && oy!=3) {
446   attr_new&=~TX_UL;
447      }
448      if((attr_new&TX_OL) && oy!=0) {
449   attr_new&=~TX_OL;
450      }
451      if(text_invert) {
452   attr_new^=TX_REV;
453      }
454      if(!crtcON || ((dmac_flag&0x04)==0x00) || !textON) {
455   text_new=0;
456   attr_new=7 << TX_COL_SHIFT;
457      }
458      if(text_width==40) {
459   if(x&1) {
460     attr_new|=TX_40R;
461   } else {
462     attr_new|=TX_40L;
463   }
464      } else {
465   attr_new|=TX_80;
466      }
467      if(text_new!=TEXT_OLD(x,y) ||
468    attr_new!=ATTR_OLD(x,y) ||
469    GRP_DIRTY(x,y) ||
470    full_refresh) {
471   plot_box(wbm2,x*8,y*BLOCK_YSIZE,8,BLOCK_YSIZE,palette_transparent_pen);
472   ct=((attr_new&TX_COL_MASK)>>TX_COL_SHIFT)+8;
473   TEXT_OLD(x,y)=text_new;
474   ATTR_OLD(x,y)=attr_new;
475   if(attr_new&TX_GL) {
476     /* low resolution(N-BASIC mode) graphics */
477     text_new>>=(text_new&3);
478     if(attr_new&TX_REV) {
479       text_new=~text_new;
480     }
481     switch(attr_new&TX_WID_MASK) {
482     case TX_80:
483       if(text_new&0x04) plot_box(wbm2,x*8,y*BLOCK_YSIZE,4,BLOCK_YSIZE,ct);
484       if(text_new&0x40) plot_box(wbm2,x*8+4,y*BLOCK_YSIZE,4,BLOCK_YSIZE,ct);
485       break;
486     case TX_40L:
487       if(text_new&0x04) plot_box(wbm2,x*8,y*BLOCK_YSIZE,8,BLOCK_YSIZE,ct);
488       break;
489     case TX_40R:
490       if(text_new&0x40) plot_box(wbm2,x*8,y*BLOCK_YSIZE,8,BLOCK_YSIZE,ct);
491       break;
492     }
493   } else {
494     /* normal text */
495     drawgfx_transpen(wbm2,NULL,screen->machine->gfx
496        [((attr_new&TX_WID_MASK)>>TX_WID_SHIFT)+
497        (pc8801_is_24KHz ? 3 : 0)],
498        text_new,
499        ((attr_new&TX_REV) ? 8 : 0)
500        + ((attr_new&TX_COL_MASK)>>TX_COL_SHIFT),
501        0,0,x*8,y*BLOCK_YSIZE,
502        (attr_new&TX_REV) ? 1 : 0);
503   }
504   if(attr_new&TX_UL) {
505     plot_box(wbm2,x*8,y*BLOCK_YSIZE+(pc8801_is_24KHz ? 3 : 1),8,1,
506         (attr_new&TX_REV) ? palette_transparent_pen : ct);
507   }
508   if(attr_new&TX_OL) {
509     plot_box(wbm2,x*8,y*BLOCK_YSIZE,8,1,
510         (attr_new&TX_REV) ? palette_transparent_pen : ct);
511   }
512490
513      /* graphics */
514   GRP_DIRTY(x,y)=0;
515   if(pc8801_is_24KHz) {
516     switch(gmode) {
517     case GRAPH_200_COL:
518       for(gy=0;gy<2;gy++) {
519         for(gx=0;gx<8;gx++) {
520      cg=
521        (((gVRAM[0x0000+x+y*2*80+gy*80] << gx) & 0x80) >> 7) |
522        (((gVRAM[0x4000+x+y*2*80+gy*80] << gx) & 0x80) >> 6) |
523        (((gVRAM[0x8000+x+y*2*80+gy*80] << gx) & 0x80) >> 5);
524      pc8801_plot_pixel(wbm1,x*8+gx,y*4+gy*2,cg);
525      pc8801_plot_pixel(wbm1,x*8+gx,y*4+gy*2+1,17);
526         }
527       }
528       break;
529     case GRAPH_200_BW:
530       for(gy=0;gy<2;gy++) {
531         for(gx=0;gx<8;gx++) {
532      cg=
533        (((gVRAM[0x0000+x+y*2*80+gy*80] << gx) & 0x80) &&
534         disp_plane[0]) ||
535        (((gVRAM[0x4000+x+y*2*80+gy*80] << gx) & 0x80) &&
536         disp_plane[1]) ||
537        (((gVRAM[0x8000+x+y*2*80+gy*80] << gx) & 0x80) &&
538         disp_plane[2]) ?
539        ((attr_new&TX_COL_MASK)>>TX_COL_SHIFT)+8 : 16;
540      pc8801_plot_pixel(wbm1,x*8+gx,y*4+gy*2,cg);
541      pc8801_plot_pixel(wbm1,x*8+gx,y*4+gy*2+1,17);
542         }
543       }
544       break;
545     case GRAPH_400_BW:
546       for(gy=0;gy<4;gy++) {
547         for(gx=0;gx<8;gx++) {
548      cg=
549        ((gVRAM[(y<50 ? 0x0000 : 0x4000)+x+(y%50)*4*80+gy*80] << gx)
550         & 0x80) &&
551        disp_plane[y<200 ? 0 : 1] ?
552        ((attr_new&TX_COL_MASK)>>TX_COL_SHIFT)+8 : 16;
553      pc8801_plot_pixel(wbm1,x*8+gx,y*4+gy,cg);
554         }
555       }
556       break;
557     case GRAPH_NO:
558     default:
559       plot_box(wbm1,x*8,y*4,8,4,16);
560       break;
561     }
562   } else {
563     switch(gmode) {
564     case GRAPH_200_COL:
565       for(gy=0;gy<2;gy++) {
566         for(gx=0;gx<8;gx++) {
567      cg=
568        (((gVRAM[0x0000+x+y*2*80+gy*80] << gx) & 0x80) >> 7) |
569        (((gVRAM[0x4000+x+y*2*80+gy*80] << gx) & 0x80) >> 6) |
570        (((gVRAM[0x8000+x+y*2*80+gy*80] << gx) & 0x80) >> 5);
571      pc8801_plot_pixel(wbm1,x*8+gx,y*2+gy,cg);
572         }
573       }
574       break;
575     case GRAPH_200_BW:
576       for(gy=0;gy<2;gy++) {
577         for(gx=0;gx<8;gx++) {
578      cg=
579        (((gVRAM[0x0000+x+y*2*80+gy*80] << gx) & 0x80) &&
580         disp_plane[0]) ||
581        (((gVRAM[0x4000+x+y*2*80+gy*80] << gx) & 0x80) &&
582         disp_plane[1]) ||
583        (((gVRAM[0x8000+x+y*2*80+gy*80] << gx) & 0x80) &&
584         disp_plane[2]) ?
585        ((attr_new&TX_COL_MASK)>>TX_COL_SHIFT)+8 : 16;
586      pc8801_plot_pixel(wbm1,x*8+gx,y*2+gy,cg);
587         }
588       }
589       break;
590     case GRAPH_NO:
591     default:
592       plot_box(wbm1,x*8,y*2,8,2,16);
593       break;
594     }
491   /* display draw */
492   for (y = 0; y < 100; y++)
493   {
494      ty = y / (100 / text_height);
495      oy = y % (100 / text_height);
496      for (x = 0; x < 80; x++)
497      {
498         /* text */
499         if (text_width == 40)
500            tx = x & (~1);
501         else
502            tx = x;
503
504         attr_new = ATTR_TMP(tx, ty);
505
506         if (oy < 4)
507            text_new = TRAM(tx, ty) * 4 + oy;
508         else
509            text_new = 0;
510
511         if (attr_new & TX_SEC)
512         {
513            text_new = 0;
514            attr_new &= ~TX_SEC;
515         }
516
517         if (attr_new & TX_BL)
518         {
519            attr_new &= ~TX_BL;
520            if ((blink_count / blink_period) & 1)
521               attr_new ^= TX_REV;
522            }
523
524         if (attr_new & TX_CUR)
525         {
526            attr_new &= ~TX_CUR;
527            switch (cursor_mode)
528            {
529            case noblink_underline:
530               attr_new ^= TX_UL;
531               break;
532            case blink_underline:
533               if (blink_count / blink_period)
534                  attr_new ^= TX_UL;
535               break;
536            case noblink_block:
537               attr_new ^= TX_REV;
538               break;
539            case blink_block:
540               if (blink_count / blink_period)
541                  attr_new ^= TX_REV;
542               break;
543            }
544         }
545
546         if ((attr_new & TX_UL) && oy != 3)
547            attr_new &= ~TX_UL;
548
549         if ((attr_new & TX_OL) && oy != 0)
550            attr_new &= ~TX_OL;
551
552         if (text_invert)
553            attr_new ^= TX_REV;
554
555         if (!crtc_on || ((dmac_flag & 0x04) == 0x00) || !text_on)
556         {
557            text_new = 0;
558            attr_new = 7 << TX_COL_SHIFT;
559         }
560         if (text_width == 40)
561         {
562            if (x & 1)
563               attr_new |= TX_40R;
564            else
565               attr_new |= TX_40L;
566         }
567         else
568         {
569            attr_new |= TX_80;
570         }
571
572         if (text_new != TEXT_OLD(x, y) || attr_new != ATTR_OLD(x, y) || GRP_DIRTY(x, y) || full_refresh)
573         {
574            plot_box(wbm2, x * 8, y * BLOCK_YSIZE, 8, BLOCK_YSIZE, palette_transparent_pen);
575            ct = ((attr_new & TX_COL_MASK) >> TX_COL_SHIFT) + 8;
576            TEXT_OLD(x, y) = text_new;
577            ATTR_OLD(x, y) = attr_new;
578            if (attr_new & TX_GL)
579            {
580               /* low resolution(N-BASIC mode) graphics */
581               text_new >>= (text_new & 3);
582               if (attr_new & TX_REV)
583                  text_new = ~text_new;
584
585               switch (attr_new & TX_WID_MASK)
586               {
587               case TX_80:
588                  if (text_new & 0x04)
589                     plot_box(wbm2, x * 8, y * BLOCK_YSIZE, 4, BLOCK_YSIZE, ct);
590                  if (text_new & 0x40)
591                     plot_box(wbm2, x * 8 + 4,y * BLOCK_YSIZE, 4, BLOCK_YSIZE, ct);
592                  break;
593               case TX_40L:
594                  if (text_new & 0x04)
595                     plot_box(wbm2, x * 8, y * BLOCK_YSIZE, 8, BLOCK_YSIZE, ct);
596                  break;
597               case TX_40R:
598                  if (text_new & 0x40)
599                     plot_box(wbm2, x * 8, y * BLOCK_YSIZE, 8, BLOCK_YSIZE, ct);
600                  break;
601               }
602            }
603            else
604            {
605               /* normal text */
606               drawgfx_transpen(wbm2, NULL, screen->machine->gfx[((attr_new & TX_WID_MASK) >> TX_WID_SHIFT) + (pc8801_is_24KHz ? 3 : 0)], text_new,
607               ((attr_new & TX_REV) ? 8 : 0) + ((attr_new & TX_COL_MASK) >> TX_COL_SHIFT), 0, 0, x * 8, y * BLOCK_YSIZE, (attr_new & TX_REV) ? 1 : 0);
608            }
609            if (attr_new & TX_UL)
610                plot_box(wbm2, x * 8, y * BLOCK_YSIZE + (pc8801_is_24KHz ? 3 : 1), 8, 1, (attr_new & TX_REV) ? palette_transparent_pen : ct);
611
612            if (attr_new & TX_OL)
613               plot_box(wbm2, x * 8, y * BLOCK_YSIZE, 8, 1, (attr_new & TX_REV) ? palette_transparent_pen : ct);
614
615            /* graphics */
616            GRP_DIRTY(x, y) = 0;
617            if (pc8801_is_24KHz)
618            {
619               switch (gmode)
620               {
621               case GRAPH_200_COL:
622                  for (gy = 0; gy < 2; gy++)
623                  {
624                     for (gx = 0; gx < 8; gx++)
625                     {
626                        cg = (((gVRAM[0x0000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 7) |
627                           (((gVRAM[0x4000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 6) |
628                           (((gVRAM[0x8000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 5);
629                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 4 + gy * 2, cg);
630                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 4 + gy * 2 + 1, 17);
631                     }
632                  }
633                  break;
634               case GRAPH_200_BW:
635                  for (gy = 0; gy < 2; gy++)
636                  {
637                     for (gx = 0; gx < 8; gx++)
638                     {
639                        cg = (((gVRAM[0x0000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[0]) ||
640                           (((gVRAM[0x4000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[1]) ||
641                           (((gVRAM[0x8000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[2]) ?
642                           ((attr_new & TX_COL_MASK) >> TX_COL_SHIFT) + 8 : 16;
643                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 4 + gy * 2, cg);
644                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 4 + gy * 2 + 1, 17);
645                     }
646                  }
647                  break;
648               case GRAPH_400_BW:
649                  for (gy = 0; gy < 4; gy++)
650                  {
651                     for (gx = 0; gx < 8; gx++)
652                     {
653                        cg = ((gVRAM[(y < 50 ? 0x0000 : 0x4000) + x + (y % 50) * 4 * 80 + gy * 80] << gx) & 0x80)
654                           && disp_plane[y < 200 ? 0 : 1] ? ((attr_new&TX_COL_MASK) >> TX_COL_SHIFT) + 8 : 16;
655                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 4 + gy, cg);
656                     }
657                  }
658                  break;
659               case GRAPH_NO:
660               default:
661                  plot_box(wbm1, x * 8, y * 4, 8, 4, 16);
662                  break;
663               }
664            }
665            else
666            {
667               switch (gmode)
668               {
669               case GRAPH_200_COL:
670                  for (gy = 0; gy < 2; gy++)
671                  {
672                     for (gx = 0; gx < 8; gx++)
673                     {
674                        cg = (((gVRAM[0x0000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 7) |
675                           (((gVRAM[0x4000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 6) |
676                           (((gVRAM[0x8000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) >> 5);
677                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 2 + gy, cg);
678                     }
679                  }
680                  break;
681               case GRAPH_200_BW:
682                  for (gy = 0; gy < 2; gy++)
683                  {
684                     for (gx = 0; gx < 8; gx++)
685                     {
686                        cg = (((gVRAM[0x0000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[0]) ||
687                           (((gVRAM[0x4000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[1]) ||
688                           (((gVRAM[0x8000 + x + y * 2 * 80 + gy * 80] << gx) & 0x80) && disp_plane[2]) ?
689                           ((attr_new & TX_COL_MASK) >> TX_COL_SHIFT) + 8 : 16;
690                        pc8801_plot_pixel(wbm1, x * 8 + gx, y * 2 + gy, cg);
691                     }
692                  }
693                  break;
694               case GRAPH_NO:
695               default:
696                  plot_box(wbm1, x * 8, y * 2, 8, 2, 16);
697                  break;
698               }
699            }
700         }
701      }
595702   }
596      }
597    }
598  }
599703
600   copyscrollbitmap_trans(wbm1,wbm2,0,0,0,0,
601      NULL,palette_transparent_pen);
602   copybitmap(bitmap,wbm1,0,0,0,0,
603      NULL);
704   copyscrollbitmap_trans(wbm1, wbm2, 0, 0, 0, 0, NULL, palette_transparent_pen);
705   copybitmap(bitmap, wbm1, 0, 0, 0, 0, NULL);
604706   return 0;
605707}
606708
r5930r5931
610712
611713   machine->colortable = colortable_alloc(machine, 18);
612714
613   for ( i = 0; i < 8; i++ )   /* for graphics */
715   for (i = 0; i < 8; i++)      /* for graphics */
614716      colortable_palette_set_color(machine->colortable, i, RGB_BLACK);
615717
616718
617719   for (i = 0; i < 8; i++)      /* standard colours */
618      colortable_palette_set_color(machine->colortable, i+8,
720      colortable_palette_set_color(machine->colortable, i + 8,
619721         MAKE_RGB((i & 2) ? 0xff : 0, (i & 4) ? 0xff : 0, (i & 1) ? 0xff : 0));
620722
621723   /* for background and scanline */
r5930r5931
623725   colortable_palette_set_color(machine->colortable, 17, RGB_BLACK);
624726
625727
626   for ( i = 0; i < 8; i++ )
728   for (i = 0; i < 8; i++)
627729   {
628      colortable_entry_set_value(machine->colortable, i*2, 0);
629      colortable_entry_set_value(machine->colortable, i*2+1, i+8);
630      colortable_entry_set_value(machine->colortable, i*2+16, i+8);
631      colortable_entry_set_value(machine->colortable, i*2+17, 0);
730      colortable_entry_set_value(machine->colortable, i * 2, 0);
731      colortable_entry_set_value(machine->colortable, i * 2 + 1, i + 8);
732      colortable_entry_set_value(machine->colortable, i * 2 + 16, i + 8);
733      colortable_entry_set_value(machine->colortable, i * 2 + 17, 0);
632734   }
633735}
634736
635WRITE8_HANDLER(pc8801_crtc_write)
737WRITE8_HANDLER( pc8801_crtc_write )
636738{
637  if(offset==1) {
638    /* command */
639    switch(data&0xe0) {
640    case 0x00:
641      /* disp stop / initilize */
642      crtcON=0;
643      crtc_state=parameter0;
644      return;
645    case 0x20:
646      /* disp on */
647      crtcON=1;
648      text_invert=((data&1)!=0x00);
649      return;
650    case 0x40:
651      /* case 0x43: */
652      /* interupt mask */
653      return;
654    case 0x60:
655      /* get light pen point */
656      crtc_state=lpenx;
657      return;    case 0x80:
658      /* set cursor */
659      crtc_state=cursorx;
660      text_cursor=((data&1)!=0x00);
661      return;
662    default:
663      logerror("pc8801:illegal crtc command 0x%.2x.\n",data);
664      return;
665    }
666  } else {
667    /* parameter */
668    switch(crtc_state) {
669    case parameter0:
670      crtc_state=parameter1;
671      if(data==0xce) return;
672      logerror("pc8801:illegal crtc parameter0 0x%.2x.\n",data);
673      return;
674    case parameter1:
675      crtc_state=parameter2;
676      switch(data&0xc0) {
677      case 0x00:
678   blink_period=8;
679   break;
680      case 0x40:
681   blink_period=16;
682   break;
683      case 0x80:
684   blink_period=24;
685   break;
686      case 0xc0:
687   blink_period=32;
688   break;
689      }
690      if((data&0x3f)==0x13) {
691   text_height=20;
692   return;
693      } else if((data&0x3f)==0x18) {
694   text_height=25;
695   return;
696      }
697      logerror("pc8801:illegal crtc parameter1 0x%.2x.\n",data);
698      return;
699    case parameter2:
700      crtc_state=parameter3;
701      switch(data&0x60) {
702      case 0x00:
703   cursor_mode=noblink_underline;
704   break;
705      case 0x20:
706   cursor_mode=blink_underline;
707   break;
708      case 0x40:
709   cursor_mode=noblink_block;
710   break;
711      case 0x60:
712   cursor_mode=blink_block;
713   break;
714      }
715      if(!pc8801_is_24KHz && (data&0x9f)==0x09 && text_height==20) {
716   return;
717      } else if(!pc8801_is_24KHz && (data&0x9f)==0x07 && text_height==25) {
718   return;
719      } else if(pc8801_is_24KHz && (data&0x9f)==0x13 && text_height==20) {
720   return;
721      } else if(pc8801_is_24KHz && (data&0x9f)==0x0f && text_height==25) {
722   return;
723      }
724      logerror("pc8801:illegal crtc parameter2 0x%.2x.\n",data);
725      return;
726    case parameter3:
727      crtc_state=parameter4;
728      if(!pc8801_is_24KHz && data==0xbe && text_height==20) {
729   return;
730      } else if(!pc8801_is_24KHz && data==0xde && text_height==25) {
731   return;
732      } else if(pc8801_is_24KHz && data==0x38 && text_height==20) {
733   return;
734      } else if(pc8801_is_24KHz && data==0x58 && text_height==25) {
735   return;
736      }
737      logerror("pc8801:illegal crtc parameter3 0x%.2x.\n",data);
738      return;
739    case parameter4:
740      crtc_state=other;
741      if(data==0x13) {
742   text_color=0;
743   return;
744      } else if(data==0x53) {
745   text_color=1;
746   return;
747      }
748      logerror("pc8801:illegal crtc parameter4 0x%.2x.\n",data);
749      return;
750    case cursorx:
751      crtc_state=cursory;
752      text_cursorX=data;
753      return;
754    case cursory:
755      crtc_state=other;
756      text_cursorY=data;
757      return;
758    default:
759      logerror("pc8801:illegal crtc parameter 0x%.2x.\n",data);
760      return;
761    }
762  }
739   if (offset == 1)
740   {
741      /* command */
742      switch (data & 0xe0)
743      {
744      case 0x00:
745         /* disp stop / initilize */
746         crtc_on = 0;
747         crtc_state = parameter0;
748         return;
749      case 0x20:
750         /* disp on */
751         crtc_on = 1;
752         text_invert = ((data & 1) != 0x00);
753         return;
754      case 0x40:
755      /* case 0x43: */
756         /* interupt mask */
757         return;
758      case 0x60:
759         /* get light pen point */
760         crtc_state = lpenx;
761         return;
762      case 0x80:
763         /* set cursor */
764         crtc_state = cursorx;
765         text_cursor = ((data & 1) != 0x00);
766         return;
767      default:
768         logerror("pc8801: illegal crtc command 0x%.2x.\n", data);
769         return;
770          }
771   }
772   else
773   {
774      /* parameter */
775      switch (crtc_state)
776      {
777      case parameter0:
778         crtc_state = parameter1;
779         if (data == 0xce)
780            return;
781         logerror("pc8801: illegal crtc parameter0 0x%.2x.\n", data);
782         return;
783
784      case parameter1:
785         crtc_state = parameter2;
786         switch (data & 0xc0)
787         {
788         case 0x00:
789            blink_period = 8;
790            break;
791         case 0x40:
792            blink_period = 16;
793            break;
794         case 0x80:
795            blink_period = 24;
796            break;
797         case 0xc0:
798            blink_period = 32;
799            break;
800         }
801         if ((data & 0x3f) == 0x13)
802         {
803            text_height = 20;
804            return;
805         }
806         else if ((data & 0x3f) == 0x18)
807         {
808            text_height = 25;
809            return;
810         }
811         logerror("pc8801: illegal crtc parameter1 0x%.2x.\n", data);
812         return;
813
814      case parameter2:
815         crtc_state = parameter3;
816         switch (data & 0x60)
817         {
818         case 0x00:
819            cursor_mode = noblink_underline;
820            break;
821         case 0x20:
822            cursor_mode = blink_underline;
823            break;
824         case 0x40:
825            cursor_mode = noblink_block;
826            break;
827         case 0x60:
828            cursor_mode = blink_block;
829            break;
830         }
831         if (!pc8801_is_24KHz && (data & 0x9f) == 0x09 && text_height == 20)
832            return;
833         else if (!pc8801_is_24KHz && (data & 0x9f) == 0x07 && text_height == 25)
834            return;
835         else if (pc8801_is_24KHz && (data & 0x9f) == 0x13 && text_height == 20)
836            return;
837         else if (pc8801_is_24KHz && (data & 0x9f) == 0x0f && text_height == 25)
838            return;
839         logerror("pc8801: illegal crtc parameter2 0x%.2x.\n", data);
840         return;
841
842      case parameter3:
843         crtc_state = parameter4;
844         if (!pc8801_is_24KHz && data == 0xbe && text_height == 20)
845            return;
846         else if (!pc8801_is_24KHz && data == 0xde && text_height == 25)
847            return;
848         else if (pc8801_is_24KHz && data == 0x38 && text_height == 20)
849            return;
850         else if (pc8801_is_24KHz && data == 0x58 && text_height == 25)
851            return;
852         logerror("pc8801: illegal crtc parameter3 0x%.2x.\n", data);
853         return;
854
855      case parameter4:
856         crtc_state = other;
857         if (data == 0x13)
858         {
859            text_color = 0;
860            return;
861         }
862         else if (data == 0x53)
863         {
864            text_color = 1;
865            return;
866         }
867         logerror("pc8801: illegal crtc parameter4 0x%.2x.\n", data);
868         return;
869
870      case cursorx:
871         crtc_state = cursory;
872         text_cursorX = data;
873         return;
874
875      case cursory:
876         crtc_state = other;
877         text_cursorY = data;
878         return;
879
880      default:
881         logerror("pc8801: illegal crtc parameter 0x%.2x.\n", data);
882         return;
883      }
884   }
763885}
764886
765 READ8_HANDLER(pc8801_crtc_read)
887READ8_HANDLER( pc8801_crtc_read )
766888{
767  if(offset==0) {
768    /* light pen point */
769    switch(crtc_state) {
770    case lpenx:
771      crtc_state=lpeny;
772      return 0xff;
773    case lpeny:
774      crtc_state=other;
775      return 0xff;
776    default:
777      logerror("pc8801:illegal light pen read\n");
778      return 0xff;
779    }
780  } else {
781    /* status */
782    return crtcON ? 0x10 : 0x00;
783  }
889   if (offset == 0)
890   {
891      /* light pen point */
892      switch (crtc_state)
893      {
894      case lpenx:
895         crtc_state = lpeny;
896         return 0xff;
897      case lpeny:
898         crtc_state = other;
899         return 0xff;
900      default:
901         logerror("pc8801:illegal light pen read\n");
902         return 0xff;
903      }
904   }
905   else
906   {
907      /* status */
908      return crtc_on ? 0x10 : 0x00;
909   }
784910}
785911
786WRITE8_HANDLER(pc8801_dmac_write)
912WRITE8_HANDLER( pc8801_dmac_write )
787913{
788  switch(offset) {
789  case 8:
790    dmac_FL=0;
791    dmac_flag=data;
792    return;
793  case 1:
794  case 3:
795  case 5:
796  case 7:
797    if(dmac_FL==0) {
798      dmac_FL=1;
799      dmac_size[offset/2]=(dmac_size[offset/2]&0xff00)|(data&0x00ff);
800      return;
801    } else {
802      dmac_FL=0;
803      dmac_size[offset/2]=(dmac_size[offset/2]&0x00ff)|((data<<8)&0xff00);
804      return;
805    }
806  case 0:
807  case 2:
808  case 4:
809  case 6:
810    if(dmac_FL==0) {
811      dmac_FL=1;
812      dmac_addr[offset/2]=(dmac_addr[offset/2]&0xff00)|(data&0x00ff);
813      return;
814    } else {
815      dmac_FL=0;
816      dmac_addr[offset/2]=(dmac_addr[offset/2]&0x00ff)|((data<<8)&0xff00);
817      return;
818    }
819  }
914   switch (offset)
915   {
916   case 8:
917      dmac_fl = 0;
918      dmac_flag = data;
919      return;
920   case 1:
921   case 3:
922   case 5:
923   case 7:
924      if (dmac_fl == 0)
925      {
926         dmac_fl = 1;
927         dmac_size[offset / 2] = (dmac_size[offset / 2] & 0xff00) | (data & 0x00ff);
928         return;
929      }
930      else
931      {
932         dmac_fl = 0;
933         dmac_size[offset / 2] = (dmac_size[offset / 2] & 0x00ff) | ((data << 8) & 0xff00);
934         return;
935      }
936   case 0:
937   case 2:
938   case 4:
939   case 6:
940      if (dmac_fl == 0)
941      {
942         dmac_fl = 1;
943         dmac_addr[offset / 2] = (dmac_addr[offset / 2] & 0xff00) | (data & 0x00ff);
944         return;
945      }
946      else
947      {
948         dmac_fl = 0;
949         dmac_addr[offset / 2] = (dmac_addr[offset / 2] & 0x00ff) | ((data << 8) & 0xff00);
950         return;
951      }
952   }
820953}
821954
822 READ8_HANDLER(pc8801_dmac_read)
955READ8_HANDLER( pc8801_dmac_read )
823956{
824  switch(offset) {
825  case 8:
826    return dmac_status;
827  case 1:
828  case 3:
829  case 5:
830  case 7:
831    if(dmac_FL==0) {
832      dmac_FL=1;
833      return(dmac_size[offset/2]&0x00ff);
834    } else {
835      dmac_FL=0;
836      return((dmac_size[offset/2]>>8)&0x00ff);
837    }
838  case 0:
839  case 2:
840  case 4:
841  case 6:
842    if(dmac_FL==0) {
843      dmac_FL=1;
844      return(dmac_addr[offset/2]&0x00ff);
845    } else {
846      dmac_FL=0;
847      return((dmac_addr[offset/2]>>8)&0x00ff);
848    }
849  }
850  return 0;
957   switch (offset)
958   {
959   case 8:
960      return dmac_status;
961   case 1:
962   case 3:
963   case 5:
964   case 7:
965      if (dmac_fl == 0)
966      {
967         dmac_fl = 1;
968         return (dmac_size[offset / 2] & 0x00ff);
969      }
970      else
971      {
972         dmac_fl = 0;
973         return ((dmac_size[offset / 2] >> 8) & 0x00ff);
974      }
975   case 0:
976   case 2:
977   case 4:
978   case 6:
979      if (dmac_fl == 0)
980      {
981         dmac_fl = 1;
982         return (dmac_addr[offset / 2] & 0x00ff);
983      }
984      else
985      {
986         dmac_fl = 0;
987         return ((dmac_addr[offset / 2] >> 8) & 0x00ff);
988      }
989   }
990   return 0;
851991}
852992
853WRITE8_HANDLER(pc88sr_disp_30)
993WRITE8_HANDLER( pc88sr_disp_30 )
854994{
855  text_width=((data&0x01)==0x00) ? 40 : 80;
995   text_width = ((data & 0x01) == 0x00) ? 40 : 80;
856996}
857997
858WRITE8_HANDLER(pc88sr_disp_31)
998WRITE8_HANDLER( pc88sr_disp_31 )
859999{
860  GMODE gmode_new;
1000   GMODE gmode_new = GRAPH_NO;
8611001
862  gmode_new=GRAPH_NO;
863  switch(data&0x19) {
864  case 0x00:
865  case 0x01:
866  case 0x10:
867  case 0x11:
868    gmode_new=GRAPH_NO;
869    break;
870  case 0x08:
871    gmode_new=pc8801_is_24KHz ? GRAPH_400_BW : GRAPH_200_BW;
872    break;
873  case 0x09:
874    gmode_new=GRAPH_200_BW;
875    break;
876  case 0x18:
877  case 0x19:
878    gmode_new=GRAPH_200_COL;
879    break;
880  }
881  if(gmode!=gmode_new) {
882    gmode=gmode_new;
883  }
1002   switch (data & 0x19)
1003   {
1004   case 0x00:
1005   case 0x01:
1006   case 0x10:
1007   case 0x11:
1008      gmode_new = GRAPH_NO;
1009      break;
1010   case 0x08:
1011      gmode_new = pc8801_is_24KHz ? GRAPH_400_BW : GRAPH_200_BW;
1012      break;
1013   case 0x09:
1014      gmode_new = GRAPH_200_BW;
1015      break;
1016   case 0x18:
1017   case 0x19:
1018      gmode_new = GRAPH_200_COL;
1019      break;
1020   }
1021
1022   if (gmode != gmode_new)
1023      gmode = gmode_new;
8841024}
8851025
8861026WRITE8_HANDLER(pc8801_palette_out)
8871027{
888  int palno;
889  int i;
890  static int r[10],g[10],b[10];
1028   int palno;
1029   int i;
1030   static int r[10],g[10],b[10];
8911031
892  if(offset==0) {
893    palno=16;
894  } else if(offset==1) {
895    textON = (data&1)==0x00;
896    for(i=0;i<3;i++) {
897      if(disp_plane[i] != ((data&(2<<i))==0x00)) {
898   disp_plane[i] = (data&(2<<i))==0x00;
899      }
900    }
901    return;
902  } else {
903    palno=offset-2;
904  }
905  if(analog_palette) {
906    if((data&0x40)==0x00) {
907      b[offset] =
908   ((data << 5) & 0xe0) |
909   ((data << 2) & 0x1c) |
910   ((data >> 1) & 0x03);
911      r[offset] =
912   ((data << 2) & 0xe0) |
913   ((data >> 1) & 0x1c) |
914   ((data >> 4) & 0x03);
915    } else {
916      g[offset] =
917   ((data << 5) & 0xe0) |
918   ((data << 2) & 0x1c) |
919   ((data >> 1) & 0x03);
920    }
921  } else {
922   b[offset] = (data & 1) ? 0xff : 0x00;
923   r[offset] = (data & 2) ? 0xff : 0x00;
924   g[offset] = (data & 4) ? 0xff : 0x00;
925  }
926  colortable_palette_set_color(space->machine->colortable, palno, MAKE_RGB(r[offset],g[offset],b[offset]));
1032   if (offset == 0)
1033      palno = 16;
1034   else if (offset == 1)
1035   {
1036      text_on = (data & 1) == 0x00;
1037
1038      for (i = 0; i < 3; i++)
1039      {
1040         if (disp_plane[i] != ((data & (2 << i)) == 0x00))
1041            disp_plane[i] = (data & (2<<i)) == 0x00;
1042      }
1043      return;
1044   }
1045   else
1046      palno = offset - 2;
1047
1048   if (analog_palette)
1049   {
1050      if ((data & 0x40) == 0x00)
1051      {
1052         b[offset] = ((data << 5) & 0xe0) | ((data << 2) & 0x1c) | ((data >> 1) & 0x03);
1053         r[offset] = ((data << 2) & 0xe0) | ((data >> 1) & 0x1c) | ((data >> 4) & 0x03);
1054      }
1055      else
1056      {
1057         g[offset] = ((data << 5) & 0xe0) | ((data << 2) & 0x1c) | ((data >> 1) & 0x03);
1058      }
1059   }
1060   else
1061   {
1062      b[offset] = (data & 1) ? 0xff : 0x00;
1063      r[offset] = (data & 2) ? 0xff : 0x00;
1064      g[offset] = (data & 4) ? 0xff : 0x00;
1065   }
1066   colortable_palette_set_color(space->machine->colortable, palno, MAKE_RGB(r[offset], g[offset], b[offset]));
9271067}
src/mess/includes/pc8801.h
r5930r5931
7070WRITE8_HANDLER(pc88sr_disp_30);
7171WRITE8_HANDLER(pc88sr_disp_31);
7272WRITE8_HANDLER(pc88sr_disp_32);
73WRITE8_HANDLER(pc88sr_ALU);
73WRITE8_HANDLER(pc88sr_alu);
7474WRITE8_HANDLER(pc8801_palette_out);
7575
7676
src/mess/drivers/pc8801.c
r5930r5931
492492   AM_RANGE(0x30, 0x30) AM_READWRITE( pc88sr_inport_30, pc88sr_outport_30 )   /* DIP-SW1 */
493493   AM_RANGE(0x31, 0x31) AM_READWRITE( pc88sr_inport_31, pc88sr_outport_31 )   /* DIP-SW2 */
494494   AM_RANGE(0x32, 0x32) AM_READWRITE( pc88sr_inport_32, pc88sr_outport_32 )
495   AM_RANGE(0x34, 0x35) AM_WRITE( pc88sr_ALU )
495   AM_RANGE(0x34, 0x35) AM_WRITE( pc88sr_alu )
496496   AM_RANGE(0x40, 0x40) AM_READWRITE( pc88sr_inport_40, pc88sr_outport_40 )
497497   AM_RANGE(0x44, 0x45) AM_DEVREAD( "ym2203", ym2203_r )
498498   AM_RANGE(0x46, 0x47) AM_NOP                              /* OPNA extra port (not yet) */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team