Previous 15994 Revisions Next

r4688 Wednesday 13th May, 2009 at 08:52:34 UTC by Curt Coder
[HD61830] Added instruction timing, reset behavior, set/clear bit instructions.
[src/mess/video]hd61830.c

src/mess/video/hd61830.c
r4687r4688
1111
1212   TODO:
1313
14   - clean up code
15   - clear/set bit instructions
16   - instruction timing
1714   - text mode
1815
1916*/
r4687r4688
2926
3027enum
3128{
32   HD61380_REGISTER_MODE_CONTROL = 0,
33   HD61380_REGISTER_CHARACTER_PITCH,
34   HD61380_REGISTER_NUMBER_OF_CHARACTERS,
35   HD61380_REGISTER_NUMBER_OF_TIME_DIVISIONS,
36   HD61380_REGISTER_CURSOR_POSITION,
37   HD61380_REGISTER_DISPLAY_START_LOW = 8,
38   HD61380_REGISTER_DISPLAY_START_HIGH,
39   HD61380_REGISTER_CURSOR_ADDRESS_LOW,
40   HD61380_REGISTER_CURSOR_ADDRESS_HIGH,
41   HD61380_REGISTER_DISPLAY_DATA_WRITE,
42   HD61380_REGISTER_DISPLAY_DATA_READ,
43   HD61380_REGISTER_CLEAR_BIT,                  /* not supported */
44   HD61380_REGISTER_SET_BIT                  /* not supported */
29   HD61380_INSTRUCTION_MODE_CONTROL = 0,
30   HD61380_INSTRUCTION_CHARACTER_PITCH,
31   HD61380_INSTRUCTION_NUMBER_OF_CHARACTERS,
32   HD61380_INSTRUCTION_NUMBER_OF_TIME_DIVISIONS,
33   HD61380_INSTRUCTION_CURSOR_POSITION,
34   HD61380_INSTRUCTION_DISPLAY_START_LOW = 8,
35   HD61380_INSTRUCTION_DISPLAY_START_HIGH,
36   HD61380_INSTRUCTION_CURSOR_ADDRESS_LOW,
37   HD61380_INSTRUCTION_CURSOR_ADDRESS_HIGH,
38   HD61380_INSTRUCTION_DISPLAY_DATA_WRITE,
39   HD61380_INSTRUCTION_DISPLAY_DATA_READ,
40   HD61380_INSTRUCTION_CLEAR_BIT,               /* not supported */
41   HD61380_INSTRUCTION_SET_BIT                  /* not supported */
4542};
4643
44static const HD61380_CYCLES[] = {
45   4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36
46};
47
4748#define HD61380_MODE_EXTERNAL_CG   0x01   /* not supported */
4849#define HD61380_MODE_GRAPHIC      0x02   /* text mode not supported */
4950#define HD61380_MODE_CURSOR         0x04   /* not supported */
r4687r4688
6162   devcb_resolved_read8      in_rd_func;
6263   devcb_resolved_write8      out_rd_func;
6364
64   int bf;                     /* busy flag, not supported */
65   int bf;                  /* busy flag */
6566
66   UINT8 ir;                  /* instruction register */
67   UINT8 mcr;                  /* mode control register */
68   UINT8 dir;                  /* data input register */
69   UINT8 dor;                  /* data output register */
70   UINT16 rac1;               /* refresh address counter 1 */
71   UINT16 rac2;               /* refresh address counter 2 */
72   UINT16 cac;                  /* cursor address counter */
73   UINT8 lac;                  /* line address counter */
67   UINT8 ir;               /* instruction register */
68   UINT8 mcr;               /* mode control register */
69   UINT8 dor;               /* data output register */
7470
75   UINT16 dsa;                  /* display start address */
71   UINT16 dsa;               /* display start address */
72   UINT16 cac;               /* cursor address counter */
7673
77   int vp;                     /* vertical character pitch */
78   int hp;                     /* horizontal character pitch */
79   int hn;                     /* horizontal number of characters */
80   int nx;                     /* number of time divisions */
81   int cp;                     /* cursor position */
74   int vp;                  /* vertical character pitch */
75   int hp;                  /* horizontal character pitch */
76   int hn;                  /* horizontal number of characters */
77   int nx;                  /* number of time divisions */
78   int cp;                  /* cursor position */
8279
83   const device_config *screen;   /* screen */
80   /* devices */
81   const device_config *screen;
82
83   /* timers */
84   emu_timer *busy_timer;
8485};
8586
8687/***************************************************************************
r4687r4688
106107***************************************************************************/
107108
108109/*-------------------------------------------------
110    TIMER_CALLBACK( busy_tick )
111-------------------------------------------------*/
112
113static TIMER_CALLBACK( busy_tick )
114{
115   const device_config *device = ptr;
116   hd61830_t *hd61830 = get_safe_token(device);
117
118   /* clear busy flag */
119   hd61830->bf = 0;
120}
121
122/*-------------------------------------------------
123    set_busy_flag - set busy flag and arm timer
124               to clear it later
125-------------------------------------------------*/
126
127static void set_busy_flag(hd61830_t *hd61830, int period)
128{
129   /* set busy flag */
130   hd61830->bf = 1;
131
132   /* adjust busy timer */
133   timer_adjust_oneshot(hd61830->busy_timer, ATTOTIME_IN_USEC(period), 0);
134}
135
136/*-------------------------------------------------
109137    hd61830_status_r - status read
110138-------------------------------------------------*/
111139
r4687r4688
113141{
114142   hd61830_t *hd61830 = get_safe_token(device);
115143
144   if (LOG) logerror("HD61380 '%s' Status Read: %s\n", device->tag, hd61830->bf ? "busy" : "ready");
145
116146   return hd61830->bf << 7;
117147}
118148
r4687r4688
156186
157187   switch (hd61830->ir)
158188   {
159   case HD61380_REGISTER_MODE_CONTROL:
189   case HD61380_INSTRUCTION_MODE_CONTROL:
160190      hd61830->mcr = data;
161191
162192      if (LOG)
r4687r4688
170200      }
171201      break;
172202   
173   case HD61380_REGISTER_CHARACTER_PITCH:
203   case HD61380_INSTRUCTION_CHARACTER_PITCH:
174204      hd61830->hp = (data & 0x07) + 1;
175205      hd61830->vp = (data >> 4) + 1;
176206
r4687r4688
178208      if (LOG) logerror("HD61380 '%s' Vertical Character Pitch: %u\n", device->tag, hd61830->vp);
179209      break;
180210
181   case HD61380_REGISTER_NUMBER_OF_CHARACTERS:
211   case HD61380_INSTRUCTION_NUMBER_OF_CHARACTERS:
182212      hd61830->hn = (data & 0x7f) + 1;
183213
184214      if (LOG) logerror("HD61380 '%s' Number of Characters: %u\n", device->tag, hd61830->hn);
185215      break;
186216
187   case HD61380_REGISTER_NUMBER_OF_TIME_DIVISIONS:
217   case HD61380_INSTRUCTION_NUMBER_OF_TIME_DIVISIONS:
188218      hd61830->nx = (data & 0x7f) + 1;
189219
190220      if (LOG) logerror("HD61380 '%s' Number of Time Divisions: %u\n", device->tag, hd61830->nx);
191221      break;
192222
193   case HD61380_REGISTER_CURSOR_POSITION:
223   case HD61380_INSTRUCTION_CURSOR_POSITION:
194224      hd61830->cp = (data & 0x7f) + 1;
195225
196226      if (LOG) logerror("HD61380 '%s' Cursor Position: %u\n", device->tag, hd61830->cp);
197227      break;
198228
199   case HD61380_REGISTER_DISPLAY_START_LOW:
229   case HD61380_INSTRUCTION_DISPLAY_START_LOW:
200230      hd61830->dsa = (hd61830->dsa & 0xff00) | data;
201231
202232      if (LOG) logerror("HD61380 '%s' Display Start Address Low %04x\n", device->tag, hd61830->dsa);
203233      break;
204234
205   case HD61380_REGISTER_DISPLAY_START_HIGH:
235   case HD61380_INSTRUCTION_DISPLAY_START_HIGH:
206236      hd61830->dsa = (data << 8) | (hd61830->dsa & 0xff);
207237
208238      if (LOG) logerror("HD61380 '%s' Display Start Address High %04x\n", device->tag, hd61830->dsa);
209239      break;
210240
211   case HD61380_REGISTER_CURSOR_ADDRESS_LOW:
241   case HD61380_INSTRUCTION_CURSOR_ADDRESS_LOW:
212242      if (BIT(hd61830->cac, 7) && !BIT(data, 7))
213243      {
214         hd61830->cac = ((((hd61830->cac & 0xff00) >> 8) + 1) << 8) | data;
244         hd61830->cac = (((hd61830->cac >> 8) + 1) << 8) | data;
215245      }
216246      else
217247      {
r4687r4688
221251      if (LOG) logerror("HD61380 '%s' Cursor Address Low %02x: %04x\n", device->tag, data, hd61830->cac);
222252      break;
223253
224   case HD61380_REGISTER_CURSOR_ADDRESS_HIGH:
254   case HD61380_INSTRUCTION_CURSOR_ADDRESS_HIGH:
225255      hd61830->cac = (data << 8) | (hd61830->cac & 0xff);
226256
227257      if (LOG) logerror("HD61380 '%s' Cursor Address High %02x: %04x\n", device->tag, data, hd61830->cac);
228258      break;
229259
230   case HD61380_REGISTER_DISPLAY_DATA_WRITE:
260   case HD61380_INSTRUCTION_DISPLAY_DATA_WRITE:
231261      devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data);
232262
233263      if (LOG) logerror("HD61380 '%s' Display Data Write %02x -> %04x row %u col %u\n", device->tag, data, hd61830->cac, hd61830->cac / 40, hd61830->cac % 40);
r4687r4688
235265      hd61830->cac++;
236266      break;
237267
238   case HD61380_REGISTER_CLEAR_BIT:
239      logerror("HD61380 '%s' Clear Bit not supported!\n", device->tag);
268   case HD61380_INSTRUCTION_CLEAR_BIT:
269      {
270      int nb = data & 0x07;
271      UINT8 data = devcb_call_read8(&hd61830->in_rd_func, hd61830->cac);
272
273      data &= ~(2 << nb);
274
275      if (LOG) logerror("HD61380 '%s' Clear Bit %u at %04x\n", device->tag, nb + 1, hd61830->cac);
276
277      devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data);
278
279      hd61830->cac++;
280      }
240281      break;
241282
242   case HD61380_REGISTER_SET_BIT:
243      logerror("HD61380 '%s' Set Bit not supported!\n", device->tag);
283   case HD61380_INSTRUCTION_SET_BIT:
284      {
285      int nb = data & 0x07;
286      UINT8 data = devcb_call_read8(&hd61830->in_rd_func, hd61830->cac);
287
288      data |= 2 << nb;
289
290      if (LOG) logerror("HD61380 '%s' Set Bit %u at %04x\n", device->tag, nb + 1, hd61830->cac);
291
292      devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data);
293
294      hd61830->cac++;
295      }
244296      break;
245297
246298   default:
247299      logerror("HD61830 '%s' Illegal Instruction %02x!\n", device->tag, hd61830->ir);
300      return;
248301   }
302
303   /* burn cycles */
304   set_busy_flag(hd61830, HD61380_CYCLES[hd61830->ir]);
249305}
250306
251307/*-------------------------------------------------
308    draw_scanline - draw one scanline
309-------------------------------------------------*/
310
311static void draw_scanline(hd61830_t *hd61830, bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra)
312{
313   int sx, x;
314
315   for (sx = 0; sx < hd61830->hn; sx++)
316   {
317      UINT8 data = devcb_call_read8(&hd61830->in_rd_func, ra++);
318
319      for (x = 0; x < hd61830->hp; x++)
320      {
321         *BITMAP_ADDR16(bitmap, y, (sx * hd61830->hp) + x) = BIT(data, 0);
322         data >>= 1;
323      }
324   }
325}
326
327/*-------------------------------------------------
328    update_graphics - draw graphics mode screen
329-------------------------------------------------*/
330
331static void update_graphics(hd61830_t *hd61830, bitmap_t *bitmap, const rectangle *cliprect)
332{
333   int y;
334
335   for (y = 0; y < hd61830->nx; y++)
336   {
337      UINT16 rac1 = hd61830->dsa + (y * hd61830->hn);
338      UINT16 rac2 = rac1 + (hd61830->nx * hd61830->hn);
339
340      /* draw upper half scanline */
341      draw_scanline(hd61830, bitmap, cliprect, y, rac1);
342
343      /* draw lower half scanline */
344      draw_scanline(hd61830, bitmap, cliprect, y + hd61830->nx, rac2);
345   }
346}
347
348/*-------------------------------------------------
252349    hd61830_update - update screen
253350-------------------------------------------------*/
254351
255352void hd61830_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect)
256353{
257354   hd61830_t *hd61830 = get_safe_token(device);
258   int y, sx, x;
259   UINT16 lac = hd61830->dsa;
260355
261   for (y = 0; y < (hd61830->nx * 2); y++)
356   if (hd61830->mcr & HD61380_MODE_GRAPHIC)
262357   {
263      for (sx = 0; sx < hd61830->hn; sx++)
264      {
265         UINT8 data = devcb_call_read8(&hd61830->in_rd_func, lac++);
266
267         for (x = 0; x < hd61830->hp; x++)
268         {
269            *BITMAP_ADDR16(bitmap, y, (sx * hd61830->hp) + x) = BIT(data, 0);
270            data >>= 1;
271         }
272      }
358      update_graphics(hd61830, bitmap, cliprect);
273359   }
274360}
275361
r4687r4688
290376   hd61830->screen = devtag_get_device(device->machine, intf->screen_tag);
291377   assert(hd61830->screen != NULL);
292378
379   /* create the busy timer */
380   hd61830->busy_timer = timer_alloc(device->machine, busy_tick, (void *)device);
381
293382   /* register for state saving */
294383   state_save_register_device_item(device, 0, hd61830->bf);
295384   state_save_register_device_item(device, 0, hd61830->ir);
296385   state_save_register_device_item(device, 0, hd61830->mcr);
297   state_save_register_device_item(device, 0, hd61830->dir);
298386   state_save_register_device_item(device, 0, hd61830->dor);
299   state_save_register_device_item(device, 0, hd61830->rac1);
300   state_save_register_device_item(device, 0, hd61830->rac2);
301387   state_save_register_device_item(device, 0, hd61830->cac);
302   state_save_register_device_item(device, 0, hd61830->lac);
303388   state_save_register_device_item(device, 0, hd61830->dsa);
304389   state_save_register_device_item(device, 0, hd61830->vp);
305390   state_save_register_device_item(device, 0, hd61830->hp);
r4687r4688
314399
315400static DEVICE_RESET( hd61830 )
316401{
317   //hd61830_t *hd61830 = get_safe_token(device);
402   hd61830_t *hd61830 = get_safe_token(device);
318403
404   hd61830->mcr = hd61830->mcr & ~(HD61380_MODE_MASTER | HD61380_MODE_DISPLAY_ON);
405   hd61830->hp = 6;
319406}
320407
321408/*-------------------------------------------------

Previous 15994 Revisions Next


© 1998-2018 The MESS Team