PageRenderTime 26ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/vidhrdw/cinemat.cpp

https://github.com/zodttd/mame4iphone-private
C++ | 375 lines | 281 code | 66 blank | 28 comment | 46 complexity | 2f23ce8345f5782d2f27774e0b5e33e2 MD5 | raw file
  1. /***************************************************************************
  2. vidhrdw.c
  3. Generic functions used by the Cinematronics Vector games
  4. ***************************************************************************/
  5. #include "driver.h"
  6. #include "vector.h"
  7. #include "cpu/ccpu/ccpu.h"
  8. #define VEC_SHIFT 16
  9. #define RED 0x04
  10. #define GREEN 0x02
  11. #define BLUE 0x01
  12. #define WHITE RED|GREEN|BLUE
  13. static int cinemat_monitor_type;
  14. static int cinemat_overlay_req;
  15. static int cinemat_backdrop_req;
  16. static int cinemat_screenh;
  17. static struct artwork_element *cinemat_simple_overlay;
  18. static int color_display;
  19. static struct artwork *spacewar_panel;
  20. static struct artwork *spacewar_pressed_panel;
  21. struct artwork_element starcas_overlay[]=
  22. {
  23. {{ 0, 400-1, 0, 300-1},0x00, 61, 0xff, OVERLAY_DEFAULT_OPACITY},
  24. {{ 200, 49, 150, -2}, 0xff, 0x20, 0x20, OVERLAY_DEFAULT_OPACITY},
  25. {{ 200, 29, 150, -2}, 0xff, 0xff, 0xff, OVERLAY_DEFAULT_OPACITY}, /* punch hole in outer circle */
  26. {{ 200, 38, 150, -1}, 0xe0, 0xff, 0x00, OVERLAY_DEFAULT_OPACITY},
  27. {{-1,-1,-1,-1},0,0,0,0}
  28. };
  29. struct artwork_element tailg_overlay[]=
  30. {
  31. {{0, 400-1, 0, 300-1}, 0, 64, 64, OVERLAY_DEFAULT_OPACITY},
  32. {{-1,-1,-1,-1},0,0,0,0}
  33. };
  34. struct artwork_element sundance_overlay[]=
  35. {
  36. {{0, 400-1, 0, 300-1}, 0xff, 0xff, 0x20, OVERLAY_DEFAULT_OPACITY},
  37. {{-1,-1,-1,-1},0,0,0,0}
  38. };
  39. struct artwork_element solarq_overlay[]=
  40. {
  41. {{0, 400-1, 30, 300-1},0x20, 0x20, 0xff, OVERLAY_DEFAULT_OPACITY},
  42. {{ 0, 399, 0, 29}, 0xff, 0x20, 0x20, OVERLAY_DEFAULT_OPACITY},
  43. {{ 200, 12, 150, -2}, 0xff, 0xff, 0x20, OVERLAY_DEFAULT_OPACITY},
  44. {{-1,-1,-1,-1},0,0,0,0}
  45. };
  46. void CinemaVectorData (int fromx, int fromy, int tox, int toy, int color)
  47. {
  48. static int lastx, lasty;
  49. fromy = cinemat_screenh - fromy;
  50. toy = cinemat_screenh - toy;
  51. if (fromx != lastx || fromx != lasty)
  52. vector_add_point (fromx << VEC_SHIFT, fromy << VEC_SHIFT, 0, 0);
  53. if (color_display)
  54. vector_add_point (tox << VEC_SHIFT, toy << VEC_SHIFT, color & 0x07, color & 0x08 ? 0x80: 0x40);
  55. else
  56. vector_add_point (tox << VEC_SHIFT, toy << VEC_SHIFT, WHITE, color * 12);
  57. lastx = tox;
  58. lasty = toy;
  59. }
  60. /* This is called by the game specific init function and sets the local
  61. * parameters for the generic function cinemat_init_colors() */
  62. void cinemat_select_artwork (int monitor_type, int overlay_req, int backdrop_req, struct artwork_element *simple_overlay)
  63. {
  64. cinemat_monitor_type = monitor_type;
  65. cinemat_overlay_req = overlay_req;
  66. cinemat_backdrop_req = backdrop_req;
  67. cinemat_simple_overlay = simple_overlay;
  68. }
  69. static void shade_fill (unsigned char *palette, int rgb, int start_index, int end_index, int start_inten, int end_inten)
  70. {
  71. int i, inten, index_range, inten_range;
  72. index_range = end_index-start_index;
  73. inten_range = end_inten-start_inten;
  74. for (i = start_index; i <= end_index; i++)
  75. {
  76. inten = start_inten + (inten_range) * (i-start_index) / (index_range);
  77. palette[3*i ] = (rgb & RED )? inten : 0;
  78. palette[3*i+1] = (rgb & GREEN)? inten : 0;
  79. palette[3*i+2] = (rgb & BLUE )? inten : 0;
  80. }
  81. }
  82. void cinemat_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  83. {
  84. int i,j,k, nextcol;
  85. char filename[1024];
  86. int trcl1[] = { 0,0,2,2,1,1 };
  87. int trcl2[] = { 1,2,0,1,0,2 };
  88. int trcl3[] = { 2,1,1,0,2,0 };
  89. /* initialize the first 8 colors with the basic colors */
  90. for (i = 0; i < 8; i++)
  91. {
  92. palette[3*i ] = (i & RED ) ? 0xff : 0;
  93. palette[3*i+1] = (i & GREEN) ? 0xff : 0;
  94. palette[3*i+2] = (i & BLUE ) ? 0xff : 0;
  95. }
  96. shade_fill (palette, WHITE, 8, 23, 0, 255);
  97. nextcol = 24;
  98. /* fill the rest of the 256 color entries depending on the game */
  99. switch (cinemat_monitor_type)
  100. {
  101. case CCPU_MONITOR_BILEV:
  102. case CCPU_MONITOR_16LEV:
  103. color_display = FALSE;
  104. /* Attempt to load backdrop if requested */
  105. if (cinemat_backdrop_req)
  106. {
  107. sprintf (filename, "%sb.png", Machine->gamedrv->name );
  108. backdrop_load(filename, nextcol, Machine->drv->total_colors-nextcol);
  109. if (artwork_backdrop!=NULL)
  110. {
  111. memcpy (palette+3*artwork_backdrop->start_pen, artwork_backdrop->orig_palette, 3*artwork_backdrop->num_pens_used);
  112. if (Machine->scrbitmap->depth == 8)
  113. nextcol += artwork_backdrop->num_pens_used;
  114. }
  115. }
  116. /* Attempt to load overlay if requested */
  117. if (cinemat_overlay_req)
  118. {
  119. if (cinemat_simple_overlay != NULL)
  120. {
  121. /* use simple overlay */
  122. artwork_elements_scale(cinemat_simple_overlay,
  123. Machine->scrbitmap->width,
  124. Machine->scrbitmap->height);
  125. overlay_create(cinemat_simple_overlay, nextcol,Machine->drv->total_colors-nextcol);
  126. }
  127. else
  128. {
  129. /* load overlay from file */
  130. sprintf (filename, "%so.png", Machine->gamedrv->name );
  131. overlay_load(filename, nextcol, Machine->drv->total_colors-nextcol);
  132. }
  133. if ((Machine->scrbitmap->depth == 8) || (artwork_backdrop == 0))
  134. overlay_set_palette (palette, (Machine->drv->total_colors > 256 ? 256 : Machine->drv->total_colors) - nextcol);
  135. }
  136. break;
  137. case CCPU_MONITOR_WOWCOL:
  138. color_display = TRUE;
  139. /* TODO: support real color */
  140. /* put in 40 shades for red, blue and magenta */
  141. shade_fill (palette, RED , 8, 47, 10, 250);
  142. shade_fill (palette, BLUE , 48, 87, 10, 250);
  143. shade_fill (palette, RED|BLUE , 88, 127, 10, 250);
  144. /* put in 20 shades for yellow and green */
  145. shade_fill (palette, GREEN , 128, 147, 10, 250);
  146. shade_fill (palette, RED|GREEN , 148, 167, 10, 250);
  147. /* and 14 shades for cyan and white */
  148. shade_fill (palette, BLUE|GREEN, 168, 181, 10, 250);
  149. shade_fill (palette, WHITE , 182, 194, 10, 250);
  150. /* Fill in unused gaps with more anti-aliasing colors. */
  151. /* There are 60 slots available. .ac JAN2498 */
  152. i=195;
  153. for (j=0; j<6; j++)
  154. {
  155. for (k=7; k<=16; k++)
  156. {
  157. palette[3*i+trcl1[j]] = ((256*k)/16)-1;
  158. palette[3*i+trcl2[j]] = ((128*k)/16)-1;
  159. palette[3*i+trcl3[j]] = 0;
  160. i++;
  161. }
  162. }
  163. break;
  164. }
  165. }
  166. void spacewar_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  167. {
  168. int width, height, i, nextcol;
  169. color_display = FALSE;
  170. /* initialize the first 8 colors with the basic colors */
  171. for (i = 0; i < 8; i++)
  172. {
  173. palette[3*i ] = (i & RED ) ? 0xff : 0;
  174. palette[3*i+1] = (i & GREEN) ? 0xff : 0;
  175. palette[3*i+2] = (i & BLUE ) ? 0xff : 0;
  176. }
  177. for (i = 0; i < 16; i++)
  178. palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
  179. spacewar_pressed_panel = NULL;
  180. width = Machine->scrbitmap->width;
  181. height = 0.16 * width;
  182. nextcol = 24;
  183. artwork_load_size(&spacewar_panel, "spacewr1.png", nextcol, Machine->drv->total_colors - nextcol, width, height);
  184. if (spacewar_panel != NULL)
  185. {
  186. if (Machine->scrbitmap->depth == 8)
  187. nextcol += spacewar_panel->num_pens_used;
  188. artwork_load_size(&spacewar_pressed_panel, "spacewr2.png", nextcol, Machine->drv->total_colors - nextcol, width, height);
  189. if (spacewar_pressed_panel == NULL)
  190. {
  191. artwork_free(&spacewar_panel);
  192. return ;
  193. }
  194. }
  195. else
  196. return;
  197. memcpy (palette+3*spacewar_panel->start_pen, spacewar_panel->orig_palette,
  198. 3*spacewar_panel->num_pens_used);
  199. if (Machine->scrbitmap->depth == 8)
  200. memcpy (palette+3*spacewar_pressed_panel->start_pen, spacewar_pressed_panel->orig_palette,
  201. 3*spacewar_pressed_panel->num_pens_used);
  202. }
  203. /***************************************************************************
  204. Start the video hardware emulation.
  205. ***************************************************************************/
  206. int cinemat_vh_start (void)
  207. {
  208. vector_set_shift (VEC_SHIFT);
  209. if (artwork_backdrop)
  210. {
  211. backdrop_refresh (artwork_backdrop);
  212. backdrop_refresh_tables (artwork_backdrop);
  213. }
  214. cinemat_screenh = Machine->visible_area.max_y - Machine->visible_area.min_y;
  215. return vector_vh_start();
  216. }
  217. int spacewar_vh_start (void)
  218. {
  219. vector_set_shift (VEC_SHIFT);
  220. if (spacewar_panel) backdrop_refresh(spacewar_panel);
  221. if (spacewar_pressed_panel) backdrop_refresh(spacewar_pressed_panel);
  222. cinemat_screenh = Machine->visible_area.max_y - Machine->visible_area.min_y;
  223. return vector_vh_start();
  224. }
  225. void cinemat_vh_stop (void)
  226. {
  227. vector_vh_stop();
  228. }
  229. void spacewar_vh_stop (void)
  230. {
  231. if (spacewar_panel != NULL)
  232. artwork_free(&spacewar_panel);
  233. if (spacewar_pressed_panel != NULL)
  234. artwork_free(&spacewar_pressed_panel);
  235. vector_vh_stop();
  236. }
  237. void cinemat_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
  238. {
  239. vector_vh_screenrefresh(bitmap, full_refresh);
  240. vector_clear_list ();
  241. }
  242. void spacewar_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
  243. {
  244. int tk[] = {3, 8, 4, 9, 1, 6, 2, 7, 5, 0};
  245. int i, pwidth, pheight, key, row, col, sw_option;
  246. float scale;
  247. struct osd_bitmap vector_bitmap;
  248. struct rectangle rect;
  249. static int sw_option_change;
  250. if (spacewar_panel == NULL)
  251. {
  252. vector_vh_screenrefresh(bitmap, full_refresh);
  253. vector_clear_list ();
  254. return;
  255. }
  256. pwidth = spacewar_panel->artwork->width;
  257. pheight = spacewar_panel->artwork->height;
  258. vector_bitmap.width = bitmap->width;
  259. vector_bitmap.height = bitmap->height - pheight;
  260. vector_bitmap._private = bitmap->_private;
  261. vector_bitmap.line = bitmap->line;
  262. vector_vh_screenrefresh(&vector_bitmap,full_refresh);
  263. vector_clear_list ();
  264. if (full_refresh)
  265. copybitmap(bitmap,spacewar_panel->artwork,0,0,
  266. 0,bitmap->height - pheight, 0,TRANSPARENCY_NONE,0);
  267. scale = pwidth/1024.0;
  268. sw_option = input_port_1_r(0);
  269. /* move bits 10-11 to position 8-9, so we can just use a simple 'for' loop */
  270. sw_option = (sw_option & 0xff) | ((sw_option >> 2) & 0x0300);
  271. sw_option_change ^= sw_option;
  272. for (i = 0; i < 10; i++)
  273. {
  274. if (sw_option_change & (1 << i) || full_refresh)
  275. {
  276. key = tk[i];
  277. col = key % 5;
  278. row = key / 5;
  279. rect.min_x = scale * (465 + 20 * col);
  280. rect.max_x = scale * (465 + 20 * col + 18);
  281. rect.min_y = scale * (39 + 20 * row) + vector_bitmap.height;
  282. rect.max_y = scale * (39 + 20 * row + 18) + vector_bitmap.height;
  283. if (sw_option & (1 << i))
  284. {
  285. copybitmap(bitmap,spacewar_panel->artwork,0,0,
  286. 0, vector_bitmap.height, &rect,TRANSPARENCY_NONE,0);
  287. }
  288. else
  289. {
  290. copybitmap(bitmap,spacewar_pressed_panel->artwork,0,0,
  291. 0, vector_bitmap.height, &rect,TRANSPARENCY_NONE,0);
  292. }
  293. osd_mark_dirty (rect.min_x, rect.min_y,
  294. rect.max_x, rect.max_y, 0);
  295. }
  296. }
  297. sw_option_change = sw_option;
  298. }
  299. int cinemat_clear_list(void)
  300. {
  301. if (osd_skip_this_frame())
  302. vector_clear_list ();
  303. return ignore_interrupt();
  304. }