Previous 15994 Revisions Next

r5144 Saturday 4th July, 2009 at 10:46:43 UTC by Barry Rodewald
[FM77AV] Implemented remaining ALU functions.
[src/mess/video]fm7.c

src/mess/video/fm7.c
r5143r5144
120120   fm7_video.vram_access = 0;
121121}
122122
123static void fm7_alu_function_compare(UINT32 offset)
124{
125   // COMPARE - compares which colors match those in the compare registers
126   // can be used on its own, or when bit 6 of the command register is high.
127   
128   UINT8 red,green,blue;
129   UINT8 dat = 0;
130   UINT8 colour;
131   UINT8 banks;
132   int x,y;
133   int match;
134   int page = 0;
135   
136   if(offset >= 0xc000)
137      page = 1;
138   
139   blue = fm7_video_ram[(offset & 0x3fff) + (page * 0xc000)];
140   red = fm7_video_ram[(offset & 0x3fff) + 0x4000 + (page * 0xc000)];
141   green = fm7_video_ram[(offset & 0x3fff) + 0x8000 + (page * 0xc000)];
142
143   banks = (~fm7_alu.bank_disable) & 0x07;
144   
145   for(x=0;x<8;x++) // loop through each pixel
146   {
147      colour = 0;
148      if(blue & (1 << x))
149         colour |= 1;
150      if(red & (1 << x))
151         colour |= 2;
152      if(green & (1 << x))
153         colour |= 4;
154         
155      match = 0;
156      for(y=0;y<8;y++)  // loop through each compare register
157      {
158         if(!(fm7_alu.compare[y] & 0x80)) // don't compare if register is masked
159         {
160            if((fm7_alu.compare[y] & banks) == (colour & banks))
161               match = 1;
162         }
163      }
164      if(match != 0)
165         dat |= (1 << x);
166   }
167   fm7_alu.compare_data = dat;
168}
169
123170static void fm7_alu_function_pset(UINT32 offset)
124171{
125172   // PSET - simply sets the pixels to the selected logical colour
r5143r5144
128175   int page = 0;
129176   UINT8 mask;
130177   
131   if(offset > 0xc000)
178   if(fm7_alu.command & 0x40)
179      fm7_alu_function_compare(offset);
180   
181   if(offset >= 0xc000)
132182      page = 1;
133183   
134184   for(x=0;x<3;x++) // cycle through banks
135185   {
136      if(fm7_alu.lcolour & (1 << x))
137         dat = 0xff;
138      else
139         dat = 0;
186      if(!(fm7_alu.bank_disable & (1 << x)))
187      {
188         if(fm7_alu.lcolour & (1 << x))
189            dat = 0xff;
190         else
191            dat = 0;
192   
193         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask;
194         dat &= ~fm7_alu.mask;
195         dat |= mask;
196         
197         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
198      }
199   }
200}
140201
141      mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask;
142      dat &= ~fm7_alu.mask;
143      dat |= mask;
202static void fm7_alu_function_or(UINT32 offset)
203{
204   int x;
205   UINT8 dat;
206   int page = 0;
207   UINT8 mask;
208   
209   if(fm7_alu.command & 0x40)
210      fm7_alu_function_compare(offset);
211   
212   if(offset >= 0xc000)
213      page = 1;
214   
215   for(x=0;x<3;x++) // cycle through banks
216   {
217      if(!(fm7_alu.bank_disable & (1 << x)))
218      {
219         if(fm7_alu.lcolour & (1 << x))
220            dat = 0xff;
221         else
222            dat = 0;
223   
224         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]);
225         dat |= mask;
144226         
145      fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
227         mask &= fm7_alu.mask;
228         dat &= ~fm7_alu.mask;
229         dat |= mask;
230           
231         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
232      }
146233   }
147234}
148235
236static void fm7_alu_function_and(UINT32 offset)
237{
238   int x;
239   UINT8 dat;
240   int page = 0;
241   UINT8 mask;
242   
243   if(fm7_alu.command & 0x40)
244      fm7_alu_function_compare(offset);
245   
246   if(offset >= 0xc000)
247      page = 1;
248   
249   for(x=0;x<3;x++) // cycle through banks
250   {
251      if(!(fm7_alu.bank_disable & (1 << x)))
252      {
253         if(fm7_alu.lcolour & (1 << x))
254            dat = 0xff;
255         else
256            dat = 0;
257   
258         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]);
259         dat &= mask;
260         
261         mask &= fm7_alu.mask;
262         dat &= ~fm7_alu.mask;
263         dat |= mask;
264           
265         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
266      }
267   }
268}
269
270static void fm7_alu_function_xor(UINT32 offset)
271{
272   int x;
273   UINT8 dat;
274   int page = 0;
275   UINT8 mask;
276   
277   if(fm7_alu.command & 0x40)
278      fm7_alu_function_compare(offset);
279   
280   if(offset >= 0xc000)
281      page = 1;
282   
283   for(x=0;x<3;x++) // cycle through banks
284   {
285      if(!(fm7_alu.bank_disable & (1 << x)))
286      {
287         if(fm7_alu.lcolour & (1 << x))
288            dat = 0xff;
289         else
290            dat = 0;
291   
292         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]);
293         dat ^= mask;
294         
295         mask &= fm7_alu.mask;
296         dat &= ~fm7_alu.mask;
297         dat |= mask;
298           
299         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
300      }
301   }
302}
303
304static void fm7_alu_function_not(UINT32 offset)
305{
306   int x;
307   UINT8 dat;
308   int page = 0;
309   UINT8 mask;
310   
311   if(fm7_alu.command & 0x40)
312      fm7_alu_function_compare(offset);
313   
314   if(offset >= 0xc000)
315      page = 1;
316   
317   for(x=0;x<3;x++) // cycle through banks
318   {
319      if(!(fm7_alu.bank_disable & (1 << x)))
320      {
321         if(fm7_alu.lcolour & (1 << x))
322            dat = 0xff;
323         else
324            dat = 0;
325   
326         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]);
327         dat = ~mask;
328         
329         mask &= fm7_alu.mask;
330         dat &= ~fm7_alu.mask;
331         dat |= mask;
332           
333         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
334      }
335   }
336}
337
149338static void fm7_alu_function_tilepaint(UINT32 offset)
150339{
151340   // TILEPAINT - writes to VRAM based on the tilepaint colour registers
r5143r5144
154343   int page = 0;
155344   UINT8 mask;
156345   
157   if(offset > 0xc000)
346   if(fm7_alu.command & 0x40)
347      fm7_alu_function_compare(offset);
348   
349   if(offset >= 0xc000)
158350      page = 1;
159351   
160352   for(x=0;x<3;x++) // cycle through banks
161353   {
162      switch(x)
354      if(!(fm7_alu.bank_disable & (1 << x)))
163355      {
164         case 0:
165            dat = fm7_alu.tilepaint_b;
166            break;
167         case 1:
168            dat = fm7_alu.tilepaint_r;
169            break;
170         case 2:
171            dat = fm7_alu.tilepaint_g;
172            break;
356         switch(x)
357         {
358            case 0:
359               dat = fm7_alu.tilepaint_b;
360               break;
361            case 1:
362               dat = fm7_alu.tilepaint_r;
363               break;
364            case 2:
365               dat = fm7_alu.tilepaint_g;
366               break;
367         }
368         dat &= ~fm7_alu.mask;
369         mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask;
370         dat |= mask;
371   
372         fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
173373      }
174      dat &= ~fm7_alu.mask;
175      mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask;
176      dat |= mask;
177
178      fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat;
179374   }   
180375}
181376
r5143r5144
186381      case 0x00: // PSET
187382         fm7_alu_function_pset(offset);
188383         break;
189      case 0x06: // TILEPAINT
190         fm7_alu_function_tilepaint(offset);
384      case 0x02: // OR
385         fm7_alu_function_or(offset);
191386         break;
192      case 0x02: // OR
193387      case 0x03: // AND
388         fm7_alu_function_and(offset);
389         break;
194390      case 0x04: // XOR
391         fm7_alu_function_xor(offset);
392         break;
195393      case 0x05: // NOT
394         fm7_alu_function_not(offset);
395         break;
396      case 0x06: // TILEPAINT
397         fm7_alu_function_tilepaint(offset);
398         break;
196399      case 0x07: // COMPARE
197         logerror("ALU: Unimplemented draw mode %i used\n",fm7_alu.command & 0x07);
400         fm7_alu_function_compare(offset);
198401         break;
199402      case 0x01:
200403      default:
201         logerror("ALU: Invalid draw mode %i used\n",fm7_alu.command & 0x07);
404         popmessage("ALU: Invalid draw mode %i used\n",fm7_alu.command & 0x07);
202405   }
203406}
204407
r5143r5144
210413   if(fm7_video.active_video_page != 0)
211414      page = 0xc000;
212415
213   if(fm7_alu.command & 0x80) // ALU active, writes to VRAM even when reading it (go figure)
214   {
215      fm7_alu_function(offset+page);
216   }
217   
218416   if(offset < 0x4000 && (fm7_video.multi_page & 0x01))
219417      return 0xff;
220418   if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02))
r5143r5144
222420   if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04))
223421      return 0xff;
224422   
423   if(fm7_alu.command & 0x80) // ALU active, writes to VRAM even when reading it (go figure)
424   {
425      fm7_alu_function(offset+page);
426   }
427   
225428   offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff);
226429   return fm7_video_ram[offs + page];
227430}
r5143r5144
234437   if(fm7_video.active_video_page != 0)
235438      page = 0xc000;
236439
237   if(fm7_alu.command & 0x80) // ALU active
238   {
239      fm7_alu_function(offset+page);
240      return;
241   }
242   
243440   if(offset < 0x4000 && (fm7_video.multi_page & 0x01))
244441      return;
245442   if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02))
246443      return;
247444   if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04))
248445      return;
446
447   if(fm7_alu.command & 0x80) // ALU active
448   {
449      fm7_alu_function(offset+page);
450      return;
451   }
249452     
250453   offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff);
251454   if(fm7_video.vram_access != 0)
r5143r5144
264467   if(fm7_video.active_video_page != 0)
265468      page = 0xc000;
266469
267   if(fm7_alu.command & 0x80) // ALU active
268   {
269      fm7_alu_function(offset+page);
270      return;
271   }
272   
273470   if(offset < 0x4000 && (fm7_video.multi_page & 0x01))
274471      return;
275472   if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02))
r5143r5144
277474   if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04))
278475      return;
279476     
477   if(fm7_alu.command & 0x80) // ALU active
478   {
479      fm7_alu_function(offset+page);
480      return;
481   }
482   
280483   offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff);
281484   fm7_video_ram[offs+page] = data;
282485}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team