Previous 15994 Revisions Next

r8761 Wednesday 11th August, 2010 at 21:45:14 UTC by Angelo Salese
[JR-200]: Rewrote i/o and video routines
[src/mess/drivers]jr200.c

src/mess/drivers/jr200.c
r8760r8761
1818#include "sound/beep.h"
1919
2020static UINT8 *jr200_vram,*jr200_cram;
21static UINT8 *border;
22static UINT8 io_reg[0x20] = {
23   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24   0, 0, 0, 0, 0, 0, 0, 0, 0, 0
25};
21static UINT8 jr200_border_col;
2622
2723static const UINT8 jr200_keycodes[4][9][8] =
2824{
r8760r8761
8682
8783static VIDEO_UPDATE( jr200 )
8884{
89   int i,j;
85   int x,y,xi,yi,pen;
9086
91   bitmap_fill(bitmap, cliprect, border[0x0000] * 2 + 1);
87   bitmap_fill(bitmap, cliprect, jr200_border_col);
9288
93   for (i = 0; i < 0x02ff; i += 0x20)
89   for (y = 0; y < 24; y++)
9490   {
95      for (j = 0; j < 0x20; j++)
91      for (x = 0; x < 32; x++)
9692      {
97         UINT8 code = jr200_vram[0x000 + i + j];
98         UINT8 col = jr200_cram[0x000 + i + j];
93         UINT8 tile = jr200_vram[x + y*32];
94         UINT8 attr = jr200_cram[x + y*32];
9995
100         if (col & 0x80)
96         for(yi=0;yi<8;yi++)
10197         {
102            UINT8 pixel01 = (jr200_vram[0x0000 + i + j] >> 3) & 0x07;
103            UINT8 pixel00 = (jr200_vram[0x0000 + i + j] >> 0) & 0x07;
104            UINT8 pixel11 = (jr200_cram[0x0000 + i + j] >> 3) & 0x07;
105            UINT8 pixel10 = (jr200_cram[0x0000 + i + j] >> 0) & 0x07;
106            plot_box(bitmap, 16 + j * 8    , 16 + (i >> 5) * 8    , 4, 4, pixel00 * 2 + 1);
107            plot_box(bitmap, 16 + j * 8 + 4, 16 + (i >> 5) * 8    , 4, 4, pixel01 * 2 + 1);
108            plot_box(bitmap, 16 + j * 8    , 16 + (i >> 5) * 8 + 4, 4, 4, pixel10 * 2 + 1);
109            plot_box(bitmap, 16 + j * 8 + 4, 16 + (i >> 5) * 8 + 4, 4, 4, pixel11 * 2 + 1);
110         }
111         else
112         {
113            drawgfx_opaque(bitmap, cliprect, screen->machine->gfx[(col & 0x40) >> 6], code, col & 0x3f, 0, 0, 16 + j * 8, 16 + (i >> 5) * 8);
114         }
115      }
116   }
98            for(xi=0;xi<8;xi++)
99            {
100               UINT8 *gfx_data; //= memory_region(screen->machine, "gfx_ram");
117101
118   return 0;
119}
102               if(attr & 0x80) //bitmap mode
103               {
104                  /*
105                     this mode draws 4 x 4 dot blocks, by combining lower 6 bits of tile and attribute vram
120106
121#if 0
122static READ8_HANDLER( test_r )
123{
124   return 0x00;
125}
126#endif
107                     tile def
108                     --xx x--- up-right
109                     ---- -xxx up-left
110                     attr def
111                     --xx x--- down-right
112                     ---- -xxx down-left
113                  */
114                  int step;
127115
128static READ8_HANDLER( io_reg_r )
129{
130   UINT8 value = 0x00;
116                  step = ((xi & 4) ? 3 : 0);
117                  step+= ((yi & 4) ? 6 : 0);
131118
132   switch (offset)
133   {
134   case 0x01:
135      {
136         // hack
137         int row, col, table = 0;
138         int keydata = 0;
139         static UINT8 res;
140         static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8" };
141
142         if (input_port_read(space->machine, "ROW9") & 0x07)
143         {
144            /* shift, upper case */
145            table = 1;
146         }
147
148         /* scan keyboard */
149         for (row = 0; row < 9; row++)
150         {
151            UINT8 data = input_port_read(space->machine, keynames[row]);
152
153            for (col = 0; col < 8; col++)
154            {
155               if (!BIT(data, col))
119                  pen = ((((attr & 0x3f) << 6) | (tile & 0x3f)) >> (step)) & 0x07;
120               }
121               else
156122               {
157                  /* latch key data */
158                  keydata = jr200_keycodes[table][row][col];
123                  gfx_data = memory_region(screen->machine, attr & 0x40 ? "pcg" : "gfx_ram");
124
125                  pen = (gfx_data[(tile*8)+yi]>>(7-xi) & 1) ? (attr & 0x7) : ((attr & 0x38) >> 3);
159126               }
127
128               *BITMAP_ADDR16(bitmap, y*8+yi+16, x*8+xi+16) = screen->machine->pens[pen];
160129            }
161130         }
162
163         if(res == keydata)
164            return 0x00;
165
166         res = keydata;
167
168         return res;
131         //drawgfx_opaque(bitmap, cliprect, screen->machine->gfx[(col & 0x40) >> 6], code, col & 0x3f, 0, 0, 16 + j * 8, 16 + (i >> 5) * 8);
169132      }
170      break;
171   case 0x03:
172      //value = 0x73;
173      break;
174   case 0x07:
175      io_reg[offset] ^= 1;
176      if (io_reg[offset] & 1)
177         value = 0xe0;
178      else
179         value = 0x60;
180      break;
181   case 0x0a:
182      value = io_reg[offset] & 0xfe;
183      break;
184   case 0x0e:
185      value = 0;
186      break;
187   case 0x10:
188      value = io_reg[offset];
189      if ((value & 0x40) && (value & 1))
190      {
191         io_reg[offset] = 0;
192         value = 0;
193      }
194      break;
195   case 0x16:
196      value = 0x4e;
197      break;
198   case 0x1c:
199   {
200//      UINT8 vblank_bit = input_port_read(space->machine, "VBLANK") & 0x01;
201      value = (io_reg[offset]);
202      io_reg[offset] |= 0x01;
203      break;
133         //}
204134   }
205   default:
206      value = io_reg[offset];
207      break;
208   }
209135
210   return value;
136   return 0;
211137}
212138
213static WRITE8_HANDLER( io_reg_w )
214{
215   io_reg[offset] = data;
216
217   switch(offset)
218   {
219      case 0x03: //used in IRQ routine (0x01 -> 0x43)
220         //printf("%02x %02x\n",offset,data);
221         break;
222      case 0x06: //writes 0x78 there
223         break;
224      case 0x07: //bit 6 enables tape play
225         break;
226      /* set beeper active */
227      case 0x19:
228         beep_set_state(space->machine->device("beeper"),(data == 0x0e) ? 1 : 0);
229         break;
230      /* set beeper frequency (TODO: correct frequency algorhythm) */
231      case 0x1a:
232      case 0x1b:
233         {
234            UINT32 beep_freq;
235
236            beep_freq = ((io_reg[0x1a]<<8) | (io_reg[0x1b] & 0xff)) + 1;
237
238            beep_set_frequency(space->machine->device("beeper"),84000 / beep_freq);
239         }
240         break;
241      default:
242         printf("%02x %02x\n",offset,data);
243         break;
244   }
245}
246
247139static READ8_HANDLER( jr200_pcg_1_r )
248140{
249141   static UINT8 *pcg = memory_region(space->machine, "pcg");
r8760r8761
292184}
293185
294186/*
187
188I/O Device
189
190*/
191
192static READ8_HANDLER( mcu_keyb_r )
193{
194   int row, col, table = 0;
195   int keydata = 0;
196   static UINT8 res;
197   static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8" };
198
199   if (input_port_read(space->machine, "ROW9") & 0x07)
200   {
201      /* shift, upper case */
202      table = 1;
203   }
204
205   /* scan keyboard */
206   for (row = 0; row < 9; row++)
207   {
208      UINT8 data = input_port_read(space->machine, keynames[row]);
209
210      for (col = 0; col < 8; col++)
211      {
212         if (!BIT(data, col))
213         {
214            /* latch key data */
215            keydata = jr200_keycodes[table][row][col];
216         }
217      }
218   }
219
220   if(res == keydata)
221      return 0x00;
222
223   res = keydata;
224
225   return res;
226}
227
228static WRITE8_HANDLER( jr200_beep_w )
229{
230   /* writing 0x0e enables the beeper, writing anything else disables it */
231   beep_set_state(space->machine->device("beeper"),((data & 0xf) == 0x0e) ? 1 : 0);
232}
233
234static WRITE8_HANDLER( jr200_beep_freq_w )
235{
236   UINT32 beep_freq;
237   static UINT8 freq_reg[2];
238
239   freq_reg[offset] = data;
240
241   beep_freq = ((freq_reg[0]<<8) | (freq_reg[1] & 0xff)) + 1;
242
243   beep_set_frequency(space->machine->device("beeper"),84000 / beep_freq);
244}
245
246static WRITE8_HANDLER( jr200_border_col_w )
247{
248   jr200_border_col = data;
249}
250
251static READ8_HANDLER( jr200_system_latch_1_r )
252{
253   return 1; // needs this to be high otherwise system refuses to boot
254}
255
256/*
295257    0000-3fff RAM
296258    4000-4fff RAM ( 4k expansion)
297259    4000-7fff RAM (16k expansion)
r8760r8761
299261*/
300262
301263static ADDRESS_MAP_START(jr200_mem, ADDRESS_SPACE_PROGRAM, 8)
302   AM_RANGE(0x0000, 0x3fff) AM_RAM
264   AM_RANGE(0x0000, 0x7fff) AM_RAM
303265
304266   AM_RANGE(0xa000, 0xbfff) AM_ROM
305267
r8760r8761
309271   AM_RANGE(0xc500, 0xc7ff) AM_RAM AM_BASE(&jr200_cram)
310272
311273//   0xc800 - 0xcfff I / O area
312   AM_RANGE(0xc800, 0xc81f) AM_READWRITE(io_reg_r, io_reg_w)
313   AM_RANGE(0xca00, 0xca00) AM_RAM AM_BASE(&border)
274   AM_RANGE(0xc801, 0xc801) AM_READ(mcu_keyb_r)
275   AM_RANGE(0xc803, 0xc803) AM_WRITENOP //used in IRQ routine (0x01 -> 0x43)
276//   AM_RANGE(0xc806, 0xc806) //writes 0x78 there
277//   AM_RANGE(0xc807, 0xc807) //bit 6 enables tape play
278   AM_RANGE(0xc819, 0xc819) AM_WRITE(jr200_beep_w)
279   AM_RANGE(0xc81a, 0xc81b) AM_WRITE(jr200_beep_freq_w)
280   AM_RANGE(0xc81c, 0xc81c) AM_READ(jr200_system_latch_1_r)
281   AM_RANGE(0xc81d, 0xc81d) AM_READNOP //jr200_system_latch_2_r
282   AM_RANGE(0xca00, 0xca00) AM_WRITE(jr200_border_col_w)
314283
315284   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE(jr200_bios_char_r,jr200_bios_char_w) //BIOS PCG RAM area
316285   AM_RANGE(0xd800, 0xdfff) AM_ROM // cart space (header 0x7e)
317286   AM_RANGE(0xe000, 0xffff) AM_ROM
318287ADDRESS_MAP_END
319288
320static ADDRESS_MAP_START( jr200_io, ADDRESS_SPACE_IO, 8)
321ADDRESS_MAP_END
322
323289/* Input ports */
324290static INPUT_PORTS_START( jr200 )
325   PORT_START("VBLANK")
326   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_VBLANK )
291//   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_VBLANK )
327292
328293   PORT_START("ROW0")
329294   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("HELP") PORT_CODE(KEYCODE_TILDE)
r8760r8761
427392{
428393   int i;
429394
430   for (i = 0; i < 64; i++)
431   {
432      palette_set_color_rgb(machine, 2 * i + 1, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
433      palette_set_color_rgb(machine, 2 * i + 0, pal1bit(i >> 4), pal1bit(i >> 5), pal1bit(i >> 3));
434   }
395   for (i = 0; i < 8; i++)
396      palette_set_color_rgb(machine, i, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0));
435397}
436398
437399static const gfx_layout tiles8x8_layout =
r8760r8761
446408};
447409
448410static GFXDECODE_START( jr200 )
449   GFXDECODE_ENTRY( "gfx_ram", 0, tiles8x8_layout, 0, 64 )
450   GFXDECODE_ENTRY( "pcg", 0, tiles8x8_layout, 0, 64 )
411   GFXDECODE_ENTRY( "gfx_ram", 0, tiles8x8_layout, 0, 1 )
412   GFXDECODE_ENTRY( "pcg", 0, tiles8x8_layout, 0, 1 )
451413GFXDECODE_END
452414
453415
r8760r8761
485447   /* basic machine hardware */
486448   MDRV_CPU_ADD("maincpu", M6802, 890000) /* MN1800A */
487449   MDRV_CPU_PROGRAM_MAP(jr200_mem)
488   MDRV_CPU_IO_MAP(jr200_io)
489450   MDRV_CPU_VBLANK_INT("screen", jr200_irq)
490451   MDRV_CPU_PERIODIC_INT(jr200_nmi,20)
491452//   MDRV_CPU_PERIODIC_INT(jr200_irq,20)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team