Previous 15994 Revisions Next

r14277 Tuesday 31st January, 2012 at 07:10:56 UTC by Miodrag Milanović
-lynx: timer changes (fixes a palette change bug in viking child) [Huygens]
xor sprites check if collision processing is enabled (fixes todd's adventures intro
flicker and xenophobe)
added rendering to a secondary bitmap to fix tearing (there's probably a better way to do this)
[src/mess/drivers]lynx.c
[src/mess/includes]lynx.h
[src/mess/machine]lynx.c

src/mess/machine/lynx.c
r14276r14277
3636This whole part will be eventually moved to video/ once I'm satisfied (or I give up).
3737*/
3838
39#define GET_WORD(mem, index) ((mem)[(index)]|((mem)[(index)+1]<<8))
40
4139/* modes from blitter command */
4240enum {
4341   BACKGROUND = 0,
r14276r14277
5048   SHADOW
5149};
5250
51static UINT8 lynx_read_ram(lynx_state *state, UINT16 address)
52{
53   UINT8 result = 0x00;
54   if (address <= 0xfbff)
55      result = state->m_mem_0000[address - 0x0000];
56   else if (address <= 0xfcff)
57      result = state->m_mem_fc00[address - 0xfc00];
58   else if (address <= 0xfdff)
59      result = state->m_mem_fd00[address - 0xfd00];
60   else if (address <= 0xfff7)
61      result = state->m_mem_fe00[address - 0xfe00];
62   else if (address >= 0xfffa)
63      result = state->m_mem_fffa[address - 0xfffa];
64   return result;
65}
5366
67static void lynx_write_ram(lynx_state *state, UINT16 address, UINT8 data)
68{
69   if (address <= 0xfbff)
70      state->m_mem_0000[address - 0x0000] = data;
71   else if (address <= 0xfcff)
72      state->m_mem_fc00[address - 0xfc00] = data;
73   else if (address <= 0xfdff)
74      state->m_mem_fd00[address - 0xfd00] = data;
75   else if (address <= 0xfff7)
76      state->m_mem_fe00[address - 0xfe00] = data;
77   else if (address >= 0xfffa)
78      state->m_mem_fffa[address - 0xfffa] = data;
79}
80
5481/* The pen numbers range from '0' to 'F. Pen numbers '1' through 'D' are always collidable and opaque. The other
5582ones have different behavior depending on the sprite type: there are 8 types of sprites, each has different
5683characteristics relating to some or all of their pen numbers.
r14276r14277
82109INLINE void lynx_plot_pixel(lynx_state *state, const int mode, const INT16 x, const int y, const int color)
83110{
84111   UINT8 back;
85   UINT8 *screen;
86   UINT8 *colbuf;
112   UINT16 screen;
113   UINT16 colbuf;
87114
88115   state->m_blitter.everon = TRUE;
89   screen = state->m_blitter.mem + state->m_blitter.screen + y * 80 + x / 2;
90   colbuf = state->m_blitter.mem + state->m_blitter.colbuf + y * 80 + x / 2;
116   screen = state->m_blitter.screen + y * 80 + x / 2;
117   colbuf = state->m_blitter.colbuf + y * 80 + x / 2;
91118
92119   switch (mode&0x7)
93120   {
r14276r14277
98125            break;
99126         if (!(x & 0x01))      /* Upper nibble */
100127         {
101            *screen = (*screen & 0x0f) | (color << 4);
128            back = lynx_read_ram(state, screen);
129            lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
102130
103131            if(state->m_sprite_collide)
104132            {
105               back = *colbuf;
106               *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4);
107               if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos])
108                  state->m_blitter.mem[state->m_blitter.colpos] = back >> 4;
133               back = lynx_read_ram(state, colbuf);
134               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
135               if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
136                  lynx_write_ram(state, state->m_blitter.colpos, back >> 4);
109137               state->m_blitter.memory_accesses += 2;
110138            }
111139         }
112140         else               /* Lower nibble */
113141         {
114            *screen = (*screen & 0xf0) | color;
142            back = lynx_read_ram(state, screen);
143            lynx_write_ram(state, screen, (back & 0xf0) | color);
115144
116145            if(state->m_sprite_collide)
117146            {
118               back = *colbuf;
119               *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr);
120               if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos])
121                  state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f;
147               back = lynx_read_ram(state, colbuf);
148               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
149               if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
150                  lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f);
122151               state->m_blitter.memory_accesses += 2;
123152            }
124153         }
r14276r14277
134163         {
135164            if (color != 0x0f)
136165            {
137               *screen = (*screen & 0x0f) | (color << 4);
166               back = lynx_read_ram(state, screen);
167               lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
138168               state->m_blitter.memory_accesses++;
139169            }
140170            if(state->m_sprite_collide)
141171            {
142               back = *colbuf;
143               *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4);
144               if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos])
145                  state->m_blitter.mem[state->m_blitter.colpos] = back >> 4;
172               back = lynx_read_ram(state, colbuf);
173               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
174               if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
175                  lynx_write_ram(state, state->m_blitter.colpos, back >> 4);
146176               state->m_blitter.memory_accesses += 2;
147177            }
148178         }
r14276r14277
150180         {
151181            if (color != 0x0f)
152182            {
153               *screen = (*screen & 0xf0) | color;
183               back = lynx_read_ram(state, screen);
184               lynx_write_ram(state, screen, (back & 0xf0) | color);
154185               state->m_blitter.memory_accesses++;
155186            }
156187            if(state->m_sprite_collide)
157188            {
158               back = *colbuf;
159               *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr);
160               if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos])
161                  state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f;
189               back = lynx_read_ram(state, colbuf);
190               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
191               if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
192                  lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f);
162193               state->m_blitter.memory_accesses += 2;
163194            }
164195         }
r14276r14277
171202            break;
172203         if (!(x & 0x01))      /* Upper nibble */
173204         {
174            *screen = (*screen & 0x0f) | (color << 4);
205            back = lynx_read_ram(state, screen);
206            lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
175207
176208            if (state->m_sprite_collide && (color != 0x0e))
177209            {
178               back = *colbuf;
179               *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4);
180               if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos])
181                  state->m_blitter.mem[state->m_blitter.colpos] = back >> 4;
210               back = lynx_read_ram(state, colbuf);
211               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
212               if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
213                  lynx_write_ram(state, state->m_blitter.colpos, back >> 4);
182214               state->m_blitter.memory_accesses += 2;
183215            }
184216         }
185217         else               /* Lower nibble */
186218         {
187            *screen = (*screen & 0xf0) | color;
219            back = lynx_read_ram(state, screen);
220            lynx_write_ram(state, screen, (back & 0xf0) | color);
188221
189222            if (state->m_sprite_collide && (color != 0x0e))
190223            {
191               back = *colbuf;
192               *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr);
193               if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos])
194                  state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f;
224               back = lynx_read_ram(state, colbuf);
225               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
226               if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
227                  lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f);
195228               state->m_blitter.memory_accesses += 2;
196229            }
197230         }
r14276r14277
208241         {
209242            if (color != 0x0f)
210243            {
211               *screen = (*screen & 0x0f) | (color << 4);
244               back = lynx_read_ram(state, screen);
245               lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
212246               state->m_blitter.memory_accesses++;
213247            }
214248            if (state->m_sprite_collide && (color != 0x0e))
215249            {
216               back = *colbuf;
217               *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4);
218               if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos])
219                  state->m_blitter.mem[state->m_blitter.colpos] = back >> 4;
250               back = lynx_read_ram(state, colbuf);
251               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
252               if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
253                  lynx_write_ram(state, state->m_blitter.colpos, back >> 4);
220254               state->m_blitter.memory_accesses += 2;
221255            }
222256         }
r14276r14277
224258         {
225259            if (color != 0x0f)
226260            {
227               *screen = (*screen & 0xf0) | color;
261               back = lynx_read_ram(state, screen);
262               lynx_write_ram(state, screen, (back & 0xf0) | color);
228263               state->m_blitter.memory_accesses++;
229264            }
230265            if (state->m_sprite_collide && (color != 0x0e))
231266            {
232               back = *colbuf;
233               *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr);
234               if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos])
235                  state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f;
267               back = lynx_read_ram(state, colbuf);
268               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
269               if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
270                  lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f);
236271               state->m_blitter.memory_accesses += 2;
237272            }
238273         }
r14276r14277
246281        and therefore not clear the collision buffer */
247282         if (!(x & 0x01))      /* Upper nibble */
248283         {
249            *screen = (*screen & 0x0f) | (color << 4);
284            back = lynx_read_ram(state, screen);
285            lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
250286
251287            if (state->m_sprite_collide && (color != 0x0e))
252288            {
253               *colbuf = (*colbuf & ~0xf0) | (state->m_blitter.spritenr << 4);
289               back = lynx_read_ram(state, colbuf);
290               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
254291               state->m_blitter.memory_accesses++;
255292            }
256293         }
257294         else               /* Lower nibble */
258295         {
259            *screen = (*screen & 0xf0) | color;
296            back = lynx_read_ram(state, screen);
297            lynx_write_ram(state, screen, (back & 0xf0) | color);
260298
261299            if (state->m_sprite_collide && (color != 0x0e))
262300            {
263               *colbuf = (*colbuf & ~0x0f) | (state->m_blitter.spritenr);
301               back = lynx_read_ram(state, colbuf);
302               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
264303               state->m_blitter.memory_accesses++;
265304            }
266305         }
r14276r14277
270309      case BACKGROUND_NO_COLL:
271310      /* This is a 'background' sprite with the exception that no activity occurs in the collision buffer */
272311         if (!(x & 0x01))      /* Upper nibble */
273            *screen = (*screen & 0x0f) | (color << 4);
312         {
313            back = lynx_read_ram(state, screen);
314            lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
315         }
274316         else               /* Lower nibble */
275            *screen = (*screen & 0xf0) | color;
317         {
318            back = lynx_read_ram(state, screen);
319            lynx_write_ram(state, screen, (back & 0xf0) | color);
320         }
276321         state->m_blitter.memory_accesses++;
277322         break;
278323
r14276r14277
282327         if (color == 0)
283328            break;
284329         if (!(x & 0x01))      /* Upper nibble */
285            *screen = (*screen & 0x0f) | (color << 4);
330         {
331            back = lynx_read_ram(state, screen);
332            lynx_write_ram(state, screen, (back & 0x0f) | (color << 4));
333         }
286334         else               /* Lower nibble */
287            *screen = (*screen & 0xf0) | color;
335         {
336            back = lynx_read_ram(state, screen);
337            lynx_write_ram(state, screen, (back & 0xf0) | color);
338         }
288339         state->m_blitter.memory_accesses++;
289340         break;
290341
r14276r14277
297348            break;
298349         if (!(x & 0x01))      /* Upper nibble */
299350         {
300            *screen = (*screen)^(color<<4);
301            if (color != 0x0e)
351            back = lynx_read_ram(state, screen);
352            lynx_write_ram(state, screen, back^(color << 4));
353            if (state->m_sprite_collide && (color != 0x0e))
302354            {
303               back = *colbuf;
304               *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4);
305               if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos])
306                  state->m_blitter.mem[state->m_blitter.colpos] = back >> 4;
355               back = lynx_read_ram(state, colbuf);
356               lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4));
357               if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
358                  lynx_write_ram(state, state->m_blitter.colpos, back >> 4);
307359               state->m_blitter.memory_accesses += 2;
308360            }
309361         }
310362         else               /* Lower nibble */
311363         {
312            *screen = (*screen)^color;
313            if (color != 0x0e)
364            back = lynx_read_ram(state, screen);
365            lynx_write_ram(state, screen, back^color);
366            if (state->m_sprite_collide && (color != 0x0e))
314367            {
315               back = *colbuf;
316               *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr);
317               if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos])
318                  state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f;
368               back = lynx_read_ram(state, colbuf);
369               lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr));
370               if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f))
371                  lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f);
319372               state->m_blitter.memory_accesses += 2;
320373            }
321374         }
r14276r14277
330383   int xi, bits, color;
331384   UINT16 width_accum, buffer;
332385
333   next_line_addr = state->m_blitter.mem[state->m_blitter.bitmap]; // offset to second sprite line
386   next_line_addr = lynx_read_ram(state, state->m_blitter.bitmap); // offset to second sprite line
334387   width_accum = (xdir == 1) ? state->m_blitter.width_offset : 0;
335388   state->m_blitter.memory_accesses++;
336389
337390   for (xi = state->m_blitter.x_pos - state->m_blitter.xoff, bits = 0, buffer = 0, j = 1; j < next_line_addr;j++)
338391   {
339      buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j];
392      buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j);
340393      bits += 8; // current bits in buffer
341394      state->m_blitter.memory_accesses++;
342395
r14276r14277
356409   }
357410}
358411
412static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 1, 0x01);}
413static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 2, 0x03);}
414static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 3, 0x07);}
415static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 4, 0x0f);}
359416
360static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir)
361{
362   const int bits = 1;
363   const int mask = 0x01;
364
365   lynx_blit_do_work(state, y, xdir, bits, mask);
366}
367static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir)
368{
369   const int bits = 2;
370   const int mask = 0x03;
371
372   lynx_blit_do_work(state, y, xdir, bits, mask);
373}
374static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir)
375{
376   const int bits = 3;
377   const int mask = 0x07;
378
379   lynx_blit_do_work(state, y, xdir, bits, mask);
380}
381static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir)
382{
383   const int bits = 4;
384   const int mask = 0x0f;
385
386   lynx_blit_do_work(state, y, xdir, bits, mask);
387}
388
389/*
3902 color rle: ??
391 0, 4 bit repeat count-1, 1 bit color
392 1, 4 bit count of values-1, 1 bit color, ....
393*/
394
395/*
3964 color rle:
397 0, 4 bit repeat count-1, 2 bit color
398 1, 4 bit count of values-1, 2 bit color, ....
399*/
400
401/*
4028 color rle:
403 0, 4 bit repeat count-1, 3 bit color
404 1, 4 bit count of values-1, 3 bit color, ....
405*/
406
407/*
40816 color rle:
409 0, 4 bit repeat count-1, 4 bit color
410 1, 4 bit count of values-1, 4 bit color, ....
411*/
412
413417static void lynx_blit_rle_do_work( lynx_state *state, const INT16 y, const int xdir, const int bits_per_pixel, const int mask )
414418{
415419   int i;
r14276r14277
424428      if (bits < 5 + bits_per_pixel) /* under 7 bits no complete entry */
425429      {
426430         j++;
427         if (j >= state->m_blitter.mem[state->m_blitter.bitmap])
431         if (j >= lynx_read_ram(state, state->m_blitter.bitmap))
428432            return;
429433
430434         bits += 8;
431         buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j];
435         buffer = (buffer << 8) | lynx_read_ram(state,state->m_blitter.bitmap + j);
432436         state->m_blitter.memory_accesses++;
433437      }
434438
r14276r14277
444448            if (bits < bits_per_pixel)
445449            {
446450               j++;
447               if (j >= state->m_blitter.mem[state->m_blitter.bitmap])
451               if (j >= lynx_read_ram(state, state->m_blitter.bitmap))
448452                  return;
449453               bits += 8;
450               buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j];
454               buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j);
451455               state->m_blitter.memory_accesses++;
452456            }
453457
r14276r14277
470474         if (bits < bits_per_pixel)
471475         {
472476            j++;
473            if (j >= state->m_blitter.mem[state->m_blitter.bitmap])
477            if (j >= lynx_read_ram(state, state->m_blitter.bitmap))
474478               return;
475479            bits += 8;
476            buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j];
480            buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j);
477481            state->m_blitter.memory_accesses++;
478482         }
479483
r14276r14277
494498   }
495499}
496500
497static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir)
498{
499   const int bits = 1;
500   const int mask = 0x01;
501static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 1, 0x01);}
502static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 2, 0x03);}
503static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 3, 0x07);}
504static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 4, 0x0f);}
501505
502   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
503}
504static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir)
505{
506   const int bits = 2;
507   const int mask = 0x03;
508
509   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
510}
511static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir)
512{
513   const int bits = 3;
514   const int mask = 0x07;
515
516   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
517}
518static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir)
519{
520   const int bits = 4;
521   const int mask = 0x0f;
522
523   lynx_blit_rle_do_work(state, y, xdir, bits, mask);
524}
525
526
527506static void lynx_blit_lines(lynx_state *state)
528507{
529508   int i;
r14276r14277
560539   if (state->m_blitter.spr_ctl0 & 0x20)   /* Horizontal Flip */
561540   {
562541      xdir *= -1;
563      //state->m_blitter.x_pos -= xdir; // causes blank lines in todds adventures, klax, etc
564542   }
565543
566544   if (state->m_blitter.spr_ctl0 & 0x10)   /* Vertical Flip */
567545   {
568546      ydir *= -1;
569      //state->m_blitter.y_pos -= ydir; // causes blank lines in todds adventures, klax, etc
570547   }
571548
572549   // Set height accumulator based on drawing direction
573550   state->m_blitter.height_accumulator = (ydir == 1) ? state->m_blitter.height_offset : 0x00;
574551
575   for (y = state->m_blitter.y_pos - state->m_blitter.yoff; (i = state->m_blitter.mem[state->m_blitter.bitmap]); state->m_blitter.bitmap += i)
552   for (y = state->m_blitter.y_pos - state->m_blitter.yoff; (i = lynx_read_ram(state, state->m_blitter.bitmap)); state->m_blitter.bitmap += i)
576553   {
577554      state->m_blitter.memory_accesses++;
578555
r14276r14277
598575         continue;
599576      }
600577
601      INT16 x = state->m_blitter.x_pos - state->m_blitter.xoff;
602      // superclipping
603      if (((x > 159) && (xdir == 1)) || ((x < 0) && (xdir == -1)) || ((y > 101) && (ydir == 1)) || ((y < 0) && (ydir == -1)))
604         continue;
605578
606579      state->m_blitter.height_accumulator += state->m_blitter.height;
607580      for (int i=0; i < (state->m_blitter.height_accumulator>>8); i++, y += ydir)
r14276r14277
609582         if (y >= 0 && y < 102)
610583            state->m_blitter.line_function(state, y, xdir);
611584         state->m_blitter.width += (INT16)state->m_blitter.stretch;
612         if (state->m_suzy.data[SPRSYS] & 0x10) // Vertical stretch enabled (doesn't seem to be used)
585         if (state->m_blitter.vstretch) // doesn't seem to be used
613586         {
614587            state->m_blitter.height += (INT16)state->m_blitter.stretch;
615588            logerror("vertical stretch enabled");
r14276r14277
633606static TIMER_CALLBACK(lynx_blitter_timer)
634607{
635608   lynx_state *state = machine.driver_data<lynx_state>();
636   state->m_suzy.data[SPRSYS] &= ~0x01; //state->m_blitter finished
609   state->m_blitter.busy=0; // blitter finished
637610}
638611
639612/*
r14276r14277
728701   lynx_blit_8color_rle_line,
729702   lynx_blit_16color_rle_line
730703   };
704   
731705   int i; int colors;
732706
733707   state->m_blitter.memory_accesses = 0;
r14276r14277
735709
736710   // these might be never set by the state->m_blitter hardware
737711   state->m_sprite_collide  = 0;
712   
713   //state->m_blitter.busy = 1; // blitter working (there's a bug somewhere that's causing slowdown when this is enabled)
738714
739   state->m_blitter.memory_accesses += 2;
740
741715   // Last SCB is indicated by zero in the high byte of SCBNEXT
742716   while (state->m_blitter.scb_next & 0xff00)
743717   {
r14276r14277
745719      state->m_blitter.tilt    = 0;
746720      state->m_blitter.tilt_accumulator = 0;
747721
748      state->m_blitter.memory_accesses += 1;
749
750722      // move to load_scb() function
751723      state->m_blitter.scb = state->m_blitter.scb_next; // current scb
752      state->m_blitter.scb_next = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SCBNEXT); // next scb
724      state->m_blitter.scb_next = lynx_read_ram(state, state->m_blitter.scb + SCB_SCBNEXT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SCBNEXT + 1) << 8); // next scb
725      state->m_blitter.spr_ctl0 = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCTL0);
726      state->m_blitter.spr_ctl1 = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCTL1);
727      state->m_blitter.spr_coll = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCOLL);
728      state->m_blitter.memory_accesses += 8;
753729
754      state->m_blitter.spr_ctl0 = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCTL0];
755      state->m_blitter.spr_ctl1 = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCTL1];
756      state->m_blitter.spr_coll = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCOLL];
757
758730      if(!(state->m_blitter.spr_ctl1 & 0x04)) // sprite will be processed (if sprite is skipped first 5 bytes are still copied to suzy)
759731      {
760         state->m_blitter.bitmap = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRDLINE);
761         state->m_blitter.x_pos = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_HPOSSTRT);
762         state->m_blitter.y_pos = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_VPOSSTRT);
732         state->m_blitter.bitmap = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRDLINE) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRDLINE + 1) << 8);
733         state->m_blitter.x_pos = lynx_read_ram(state, state->m_blitter.scb + SCB_HPOSSTRT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_HPOSSTRT + 1) << 8);
734         state->m_blitter.y_pos = lynx_read_ram(state, state->m_blitter.scb + SCB_VPOSSTRT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_VPOSSTRT + 1) << 8);
735         state->m_blitter.memory_accesses += 6;
763736
764737         switch(state->m_blitter.spr_ctl1 & 0x30) // reload sprite scaling
765738         {
766739            case 0x30: // width, height, tilt, stretch
767               state->m_blitter.tilt = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_TILT);
740               state->m_blitter.tilt = lynx_read_ram(state, state->m_blitter.scb + SCB_TILT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_TILT + 1) << 8);
741               state->m_blitter.memory_accesses+=2;
768742            case 0x20: // width, height, stretch
769               state->m_blitter.stretch = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_STRETCH);
743               state->m_blitter.stretch = lynx_read_ram(state, state->m_blitter.scb + SCB_STRETCH) | (lynx_read_ram(state, state->m_blitter.scb + SCB_STRETCH + 1) << 8);
744               state->m_blitter.memory_accesses+=2;
770745            case 0x10: // width, height
771               state->m_blitter.width = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRHSIZ);
772               state->m_blitter.height = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRVSIZ);
746               state->m_blitter.width = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRHSIZ) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRHSIZ + 1) << 8);
747               state->m_blitter.height = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRVSIZ) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRVSIZ + 1) << 8);
748               state->m_blitter.memory_accesses+=4;
773749         }
774750
775751         if(!(state->m_blitter.spr_ctl1 & 0x08)) // reload palette
r14276r14277
783759
784760            for (i = 0; i < colors / 2; i++)
785761            {
786               state->m_blitter.color[i * 2]      = state->m_blitter.mem[state->m_blitter.scb + palette_offset + i] >> 4;
787               state->m_blitter.color[i * 2 + 1 ] = state->m_blitter.mem[state->m_blitter.scb + palette_offset + i] & 0x0f;
762               state->m_blitter.color[i * 2]      = lynx_read_ram(state, state->m_blitter.scb + palette_offset + i) >> 4;
763               state->m_blitter.color[i * 2 + 1 ] = lynx_read_ram(state, state->m_blitter.scb + palette_offset + i) & 0x0f;
788764               state->m_blitter.memory_accesses++;
789765            }
790766         }
r14276r14277
793769
794770      if (!(state->m_blitter.spr_ctl1 & 0x04))      // if 0, we skip this sprite
795771      {
796         state->m_blitter.colpos = state->m_blitter.scb + GET_WORD(state->m_suzy.data, COLLOFFL);
797         state->m_blitter.memory_accesses += 6;
798
772         state->m_blitter.colpos = state->m_blitter.scb + (state->m_suzy.data[COLLOFFL] | (state->m_suzy.data[COLLOFFH]<<8));
799773         state->m_blitter.mode = state->m_blitter.spr_ctl0 & 0x07;
800774
801775         if (state->m_blitter.spr_ctl1 & 0x80) // totally literal sprite
r14276r14277
803777         else
804778            state->m_blitter.line_function = blit_rle_line[state->m_blitter.spr_ctl0 >> 6];
805779
806         if (!(state->m_blitter.spr_coll & 0x20) && !(state->m_suzy.data[SPRSYS] & 0x20))
780         if (!(state->m_blitter.spr_coll & 0x20) && !(state->m_blitter.no_collide))
807781         {
808782            switch (state->m_blitter.mode)
809783            {
r14276r14277
813787               case XOR_SPRITE:
814788               case SHADOW:
815789                  state->m_sprite_collide = 1;
816                  state->m_blitter.mem[state->m_blitter.colpos] = 0;
790                  lynx_write_ram(state, state->m_blitter.colpos, 0);
817791                  state->m_blitter.spritenr = state->m_blitter.spr_coll & 0x0f;
818792               break;
819793               case BACKGROUND:
r14276r14277
825799         /* Draw Sprites */
826800         lynx_blit_lines(state);
827801      }
828      state->m_blitter.memory_accesses += 2;
829802   }
830
831   if (0)
832      machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(state->m_blitter.memory_accesses*20), FUNC(lynx_blitter_timer));
803   
804   if (0) // turned off for now as it cuases slowdown in some games due to a bug somewhere
805   {
806      if (state->m_blitter.memory_accesses != 0)
807         machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(state->m_blitter.memory_accesses), FUNC(lynx_blitter_timer));
808      else
809         state->m_blitter.busy = 0; // blitter done
810   }
833811}
834812
835813
r14276r14277
910888
911889   res = left * right;
912890
913   if (state->m_suzy.data[SPRSYS] & 0x80)      /* signed math */
891   if (state->m_suzy.signed_math)
914892   {
915893      if (!(state->m_sign_AB + state->m_sign_CD))   /* different signs */
916894         res = (res ^ 0xffffffff) + 1;
r14276r14277
921899   state->m_suzy.data[MATH_F] = res >> 16;
922900   state->m_suzy.data[MATH_E] = res >> 24;
923901
924   if (state->m_suzy.data[SPRSYS] & 0x40)      /* is accumulation allowed? */
902   if (state->m_suzy.accumulate)
925903   {
926904      accu = state->m_suzy.data[MATH_M] | state->m_suzy.data[MATH_L] << 8 | state->m_suzy.data[MATH_K] << 16 | state->m_suzy.data[MATH_J] << 24;
927905      accu += res;
r14276r14277
1017995      //case PROCADRL:
1018996      case SUZYHREV:
1019997         return 0x01; // must not be 0 for correct power up
1020      case SPRSYS:   /* Better check this with docs! */
1021         if (state->m_blitter.time==attotime::zero)
1022         {
1023            if (space->machine().device<cpu_device>("maincpu")->attotime_to_cycles(space->machine().time() - state->m_blitter.time) > state->m_blitter.memory_accesses * 20)
1024            {
1025               state->m_suzy.data[offset] &= ~0x01; //state->m_blitter finished
1026               state->m_blitter.time = attotime::zero;
1027            }
1028         }
1029         value = state->m_suzy.data[offset];
1030         value &= ~0x80; // math finished
1031         value &= ~0x40;
998      case SPRSYS:
999         // math busy, last carry, unsafe access, and stop on current sprite bits not implemented.
10321000         if (state->m_suzy.accumulate_overflow)
10331001            value |= 0x40;
1002         if (state->m_blitter.vstretch)
1003            value |= 0x10;
1004         if (state->m_blitter.lefthanded)
1005            value |= 0x08;
1006         if (state->m_blitter.busy)
1007            value |= 0x01;
10341008         break;
10351009      case JOYSTICK:
10361010         input = input_port_read(space->machine(), "JOY");
r14276r14277
10531027               if (value & PAD_LEFT) input |= PAD_UP;
10541028               break;
10551029         }
1056         if (state->m_suzy.data[SPRSYS] & 0x08) /* Left handed controls */
1030         if (state->m_blitter.lefthanded)
10571031         {
10581032            value = input & 0x0f;
10591033            if (input & PAD_UP) value |= PAD_DOWN;
r14276r14277
10761050      case SPRCTL1:
10771051      case SPRCOLL:
10781052      case SPRINIT:
1079      //case SUZYBUSEN:
1053      case SUZYBUSEN:
10801054      case SPRGO:
10811055         logerror("read from write only register %x\n", offset);
10821056         value = 0;
r14276r14277
10921066{
10931067   lynx_state *state = space->machine().driver_data<lynx_state>();
10941068   state->m_suzy.data[offset] = data;
1095
1069   //logerror("suzy write %.2x %.2x\n",offset,data);
10961070   /* Additional effects of a write */
10971071   /* Even addresses are the LSB. Any CPU write to an LSB in 0x00-0x7f will set the MSB to 0. */
10981072   /* This in particular holds for math quantities:  Writing to B (0x54), D (0x52),
r14276r14277
12321206      case MATH_C:
12331207         /* If we are going to perform a signed multiplication, we store the sign and convert the number
12341208            to an unsigned one */
1235         if (state->m_suzy.data[SPRSYS] & 0x80)      /* signed math */
1209         if (state->m_suzy.signed_math)
12361210         {
12371211            UINT16 factor, temp;
12381212            factor = state->m_suzy.data[MATH_D] | (state->m_suzy.data[MATH_C] << 8);
r14276r14277
12511225      /* If we are going to perform a signed multiplication, we also store the sign and convert the
12521226        number to an unsigned one */
12531227      case MATH_A:
1254         if (state->m_suzy.data[SPRSYS] & 0x80)      /* signed math */
1228         if (state->m_suzy.signed_math)
12551229         {
12561230            UINT16 factor, temp;
12571231            factor = state->m_suzy.data[MATH_B] | (state->m_suzy.data[MATH_A] << 8);
r14276r14277
12801254      case SPRCOLL:
12811255         state->m_blitter.spr_coll = data;
12821256         break;
1257      case SUZYBUSEN:
1258         logerror("write to SUSYBUSEN %x \n", data);
1259         break;
1260      case SPRSYS:
1261            state->m_suzy.signed_math = data & 0x80;
1262            state->m_suzy.accumulate = data & 0x40;
1263            state->m_blitter.no_collide = data & 0x20;
1264            state->m_blitter.vstretch = data & 0x10;
1265            state->m_blitter.lefthanded = data & 0x08;
1266            // unsafe access clear and sprite engine stop request are not enabled
1267            break;
12831268      case SPRGO:
1284         if (data & 0x01)
1269         if ((data & 0x01) && state->m_suzy.data[SUZYBUSEN])
12851270         {
1286            state->m_blitter.time = space->machine().time();
1271            //state->m_blitter.time = space->machine().time();
12871272            lynx_blitter(space->machine());
12881273         }
12891274         break;
r14276r14277
13141299*/
13151300
13161301
1317
1318static UINT8 lynx_read_vram(lynx_state *state, UINT16 address)
1319{
1320   UINT8 result = 0x00;
1321   if (address <= 0xfbff)
1322      result = state->m_mem_0000[address - 0x0000];
1323   else if (address <= 0xfcff)
1324      result = state->m_mem_fc00[address - 0xfc00];
1325   else if (address <= 0xfdff)
1326      result = state->m_mem_fd00[address - 0xfd00];
1327   else if (address <= 0xfff7)
1328      result = state->m_mem_fe00[address - 0xfe00];
1329   else if (address >= 0xfffa)
1330      result = state->m_mem_fffa[address - 0xfffa];
1331   return result;
1332}
1333
1334
13351302/*
13361303DISPCTL EQU $FD92       ; set to $D by INITMIKEY
13371304
r14276r14277
13411308; B1    1 EQU flip screen
13421309; B0    1 EQU video DMA enabled
13431310*/
1344static void lynx_draw_lines(running_machine &machine, int newline)
1311
1312static void lynx_draw_line(running_machine &machine)
13451313{
13461314   lynx_state *state = machine.driver_data<lynx_state>();
1347   int x, yend;
1315   int x, y;
13481316   UINT16 j; // clipping needed!
13491317   UINT8 byte;
13501318   UINT16 *line;
1351
1352   if (newline == -1)
1353      yend = 102;
1354   else
1355      yend = newline;
1356
1357   if (yend > 102)
1358      yend = 102;
1359
1360   if (yend == state->m_line_y)
1361   {
1362      if (newline == -1)
1363         state->m_line_y = 0;
1364      return;
1365   }
1366
1319   
1320   
1321   // calculate y: first three lines are vblank, 
1322   y = 101-state->m_timer[2].counter;
13671323   // Documentation states lower two bits of buffer address are ignored (thus 0xfffc mask)
1368   j = (state->m_mikey.disp_addr & 0xfffc) + state->m_line_y * 160 / 2;
1324   j = (state->m_mikey.disp_addr & 0xfffc) + y * 160 / 2;
13691325
13701326   if (state->m_mikey.data[0x92] & 0x02)
13711327   {
13721328      j -= 160 * 102 / 2 - 1;
1373      for ( ; state->m_line_y < yend; state->m_line_y++)
1329      line = &state->m_bitmap_temp.pix16(102 - 1 - y);
1330      for (x = 160 - 2; x >= 0; j++, x -= 2)
13741331      {
1375         line = &state->m_bitmap.pix16(102 - 1 - state->m_line_y);
1376         for (x = 160 - 2; x >= 0; j++, x -= 2)
1377         {
1378            byte = lynx_read_vram(state, j);
1379            line[x + 1] = state->m_palette[(byte >> 4) & 0x0f];
1380            line[x + 0] = state->m_palette[(byte >> 0) & 0x0f];
1381         }
1332         byte = lynx_read_ram(state, j);
1333         line[x + 1] = state->m_palette[(byte >> 4) & 0x0f];
1334         line[x + 0] = state->m_palette[(byte >> 0) & 0x0f];
13821335      }
13831336   }
13841337   else
13851338   {
1386      for ( ; state->m_line_y < yend; state->m_line_y++)
1339      line = &state->m_bitmap_temp.pix16(y);
1340      for (x = 0; x < 160; j++, x += 2)
13871341      {
1388         line = &state->m_bitmap.pix16(state->m_line_y);
1389         for (x = 0; x < 160; j++, x += 2)
1390         {
1391            byte = lynx_read_vram(state, j);
1392            line[x + 0] = state->m_palette[(byte >> 4) & 0x0f];
1393            line[x + 1] = state->m_palette[(byte >> 0) & 0x0f];
1394         }
1342         byte = lynx_read_ram(state, j);
1343         line[x + 0] = state->m_palette[(byte >> 4) & 0x0f];
1344         line[x + 1] = state->m_palette[(byte >> 0) & 0x0f];
13951345      }
13961346   }
13971347}
13981348
1399
14001349/****************************************
14011350
14021351    Timers
r14276r14277
14601409   switch ( which ) // count down linked timers
14611410   {
14621411   case 0:
1463      if ((state->m_line == 2) || (state->m_line == 3) || (state->m_line == 4))
1412      switch (state->m_timer[2].counter)
14641413      {
1465         //state->m_mikey.vb_rest = 1;
1414         case 104:
1415         case 103:
1416            state->m_mikey.vb_rest = 1;
1417            break;
1418         case 102:
1419            state->m_mikey.disp_addr = state->m_mikey.data[0x94] | (state->m_mikey.data[0x95] << 8);
1420            break;
1421         case 101:
1422            state->m_mikey.vb_rest = 0;
1423            lynx_draw_line( machine );
1424            break;
1425         default:
1426            lynx_draw_line( machine );
14661427      }
1467      else
1468         state->m_mikey.vb_rest = 0;
1469      if (state->m_line == 3)
1470      {
1471         state->m_mikey.disp_addr = state->m_mikey.data[0x94] | (state->m_mikey.data[0x95] << 8);
1472         lynx_draw_lines( machine, -1 );
1473      }
14741428      lynx_timer_count_down( machine, 2 );
1475      state->m_line++;
14761429      break;
1477   case 2:
1430   case 2:   
1431      copybitmap(state->m_bitmap, state->m_bitmap_temp, 0, 0, 0, 0, machine.primary_screen->cliprect());
14781432      lynx_timer_count_down( machine, 4 );
1479      lynx_draw_lines( machine, -1 );
1480      state->m_line=0;
14811433      break;
14821434   case 1:
14831435      lynx_timer_count_down( machine, 3 );
r14276r14277
15021454      if ( state->m_timer[which].counter > 0 )
15031455      {
15041456         state->m_timer[which].counter--;
1457         //state->m_timer[which].borrow_in = 1;
15051458         return;
15061459      }
15071460      if ( state->m_timer[which].counter == 0 )
15081461      {
1509         state->m_timer[which].cntrl2 |= 8; // set timer done
1462         if (state->m_timer[which].cntrl2 & 0x01) // borrow out
1463         {
15101464            lynx_timer_signal_irq(machine, which);
15111465            if ( state->m_timer[which].cntrl1 & 0x10 ) // if reload enabled
15121466            {
15131467               state->m_timer[which].counter = state->m_timer[which].bakup;
1514            // should we unset timer done?
15151468            }
15161469            else
15171470            {
1518            state->m_timer[which].counter--; // Is this correct or should it stop at zero?
1471               state->m_timer[which].cntrl2 |= 8; // set timer done
15191472            }
1473            state->m_timer[which].cntrl2 &= ~0x01; // clear borrow out
1474         }
1475         else
1476            state->m_timer[which].cntrl2 |= 0x01; // set borrow out
15201477         return;
15211478      }
15221479   }
1480   else
1481   {
1482      //state->m_timer[which].borrow_in = 0;
1483      state->m_timer[which].cntrl2 &= ~0x01;
1484   }
15231485}
15241486
15251487static UINT32 lynx_time_factor(int val)
r14276r14277
15401502static TIMER_CALLBACK(lynx_timer_shot)
15411503{
15421504   lynx_state *state = machine.driver_data<lynx_state>();
1543   state->m_timer[param].cntrl2 |= 8; // set timer done
15441505   lynx_timer_signal_irq( machine, param );
15451506   if ( ! ( state->m_timer[param].cntrl1 & 0x10 ) ) // if reload not enabled
1507   {
15461508      state->m_timer[param].timer_active = 0;
1509      state->m_timer[param].cntrl2 |= 8; // set timer done
1510   }
15471511   else
15481512   {
15491513      attotime t = (attotime::from_hz(lynx_time_factor(state->m_timer[param].cntrl1 & 0x07)) * (state->m_timer[param].bakup + 1));
r14276r14277
15711535         else
15721536         {
15731537            if ( state->m_timer[which].timer_active )
1574               //value = (UINT8) ( state->m_timer[which].bakup - (state->m_timer[which].timer->remaining() * lynx_time_factor( state->m_timer[which].cntrl1 & 0x07 )).seconds);
1575               value = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07))); // aren't we just returning the remaining time?
1538            {
1539               state->m_timer[which].counter = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07)));
1540               state->m_timer[which].counter -= (state->m_timer[which].counter) ? 1 : 0;
1541            }
15761542         }
15771543         break;
15781544
r14276r14277
15861552
15871553static void lynx_timer_write(lynx_state *state, int which, int offset, UINT8 data)
15881554{
1589   // logerror("timer %d write %x %.2x\n", which, offset, data);
1555   //logerror("timer %d write %x %.2x\n", which, offset, data);
15901556   attotime t;
1557   
1558   if ( state->m_timer[which].timer_active && ((state->m_timer[which].cntrl1 & 0x07) != 0x07))
1559   {
1560      state->m_timer[which].counter = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07)));
1561      state->m_timer[which].counter -= (state->m_timer[which].counter) ? 1 : 0;
1562   }
1563
15911564   switch (offset)
15921565   {
15931566      case 0:
r14276r14277
16071580   }
16081581
16091582   /* Update timers */
1610   if ( offset < 3 )
1611   {
1583   //if ( offset < 3 )
1584   //{
16121585      state->m_timer[which].timer->reset();
16131586      state->m_timer[which].timer_active = 0;
1614      if ((state->m_timer[which].cntrl1 & 0x08))      // if enable count
1587      if ((state->m_timer[which].cntrl1 & 0x08) && !(state->m_timer[which].cntrl2 & 0x08))      // if enable count
16151588      {
1616         if ((state->m_timer[which].cntrl1 & 0x07) != 0x07) // if not set to link mode
1589         if ((state->m_timer[which].cntrl1 & 0x07) != 0x07) // if not set to link mode
16171590         {
1618            if (state->m_timer[which].cntrl1 & 0x10) // reload enabled
1619               t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].bakup + 1));
1620            else
1621               t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].counter + 1));
1591            t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].counter + 1));
16221592            state->m_timer[which].timer->adjust(t, which);
16231593            state->m_timer[which].timer_active = 1;
16241594         }
16251595      }
1626   }
1596   //}
16271597}
16281598
16291599
r14276r14277
16781648         value = state->m_uart.data_received;
16791649         break;
16801650   }
1681   // logerror("uart read %.2x %.2x\n", offset, value);
1651   logerror("uart read %.2x %.2x\n", offset, value);
16821652   return value;
16831653}
16841654
16851655static WRITE8_HANDLER(lynx_uart_w)
16861656{
16871657   lynx_state *state = space->machine().driver_data<lynx_state>();
1688   // logerror("uart write %.2x %.2x\n", offset, data);
1658   logerror("uart write %.2x %.2x\n", offset, data);
16891659   switch (offset)
16901660   {
16911661      case 0x8c:
r14276r14277
18131783   case 0x80:
18141784      state->m_mikey.data[0x81] &= ~data; // clear interrupt source
18151785      // logerror("mikey write %.2x %.2x\n", offset, data);
1816      if (!state->m_mikey.data[0x81])
1786      if (!(state->m_mikey.data[0x81] & ~0x10))
18171787         cputag_set_input_line(space->machine(), "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE);
18181788      break;
18191789
18201790   /* Is this correct? */ // Notes say writing to register will result in interupt being triggered.
18211791   case 0x81:
18221792      state->m_mikey.data[0x81] |= data;
1823      if (data)
1793      if (data & ~0x10)
18241794         cputag_set_input_line(space->machine(), "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE);
18251795      break;
18261796
r14276r14277
18531823   case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
18541824   case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
18551825      state->m_mikey.data[offset] = data;
1856      lynx_draw_lines(space->machine(), state->m_line);
18571826
18581827      /* RED = 0xb- & 0x0f, GREEN = 0xa- & 0x0f, BLUE = (0xb- & 0xf0) >> 4 */
18591828      state->m_palette[offset & 0x0f] = space->machine().pens[
r14276r14277
19711940*/
19721941
19731942   lynx_uart_reset(state);
1974
1943   
19751944   // hack to allow current object loading to work
1976#if 1
1945#if
19771946   lynx_timer_write( state, 0, 0, 160 ); // set backup value (hpos) = 160
19781947   lynx_timer_write( state, 0, 1, 0x10 | 0x8 | 0 ); // enable count, enable reload, 1us period
1979   lynx_timer_write( state, 2, 0, 102 ); // set backup value (vpos) = 102
1948   lynx_timer_write( state, 2, 0, 105 ); // set backup value (vpos) = 102
19801949   lynx_timer_write( state, 2, 1, 0x10 | 0x8 | 7 ); // enable count, enable reload, link
19811950#endif
19821951}
r14276r14277
19891958MACHINE_START( lynx )
19901959{
19911960   lynx_state *state = machine.driver_data<lynx_state>();
1961   state->m_bitmap_temp.allocate(160,102,0,0);
1962   
19921963   int i;
19931964   state->save_item(NAME(state->m_memory_config));
19941965   state->save_pointer(NAME(state->m_mem_fe00), state->m_mem_fe00_size);
src/mess/includes/lynx.h
r14276r14277
4545   int everon;
4646   int memory_accesses;
4747   attotime time;
48   
49   int no_collide;
50   int vstretch;
51   int lefthanded;
52   int busy;
4853} BLITTER;
4954
5055typedef struct
r14276r14277
6065typedef struct
6166{
6267   UINT8 data[0x100];
63   int accumulate_overflow;
6468   UINT8 high;
6569   int low;
70   int signed_math;
71   int accumulate;
72   int accumulate_overflow;
6673} SUZY;
6774
6875typedef struct
r14276r14277
101108   UINT8 *m_mem_fffa;
102109   size_t m_mem_fe00_size;
103110   UINT16 m_granularity;
104   int m_line;
105   int m_line_y;
106111   int m_sign_AB;
107112   int m_sign_CD;
108113   UINT32 m_palette[0x10];
r14276r14277
116121   LYNX_TIMER m_timer[NR_LYNX_TIMERS];
117122   UART m_uart;
118123   bitmap_ind16 m_bitmap;
124   bitmap_ind16 m_bitmap_temp;
119125};
120126
121127
r14276r14277
218224
219225#define SUZYHREV   0x88 // Suzy Hardware Revision (R) = '01'
220226
227#define SUZYBUSEN   0x90 // Suzy Bus Enable (W)
221228#define SPRGO      0x91 // Sprite Process Start Bit (W)
222229#define SPRSYS      0x92 // System Control Bits (R/W)
223230
src/mess/drivers/lynx.c
r14276r14277
111111#endif
112112
113113/* these 2 dumps are saved from an running machine,
114   and therefor the rom byte at 0xff09 is not readable!
114   and therefor the rom byte at 0xfff9 is not readable!
115115   (memory configuration)
116116   these 2 dumps differ only in this byte!
117117*/

Previous 15994 Revisions Next


© 1998-2018 The MESS Team