/src/mame/video/brkthru.c

https://github.com/groovybits/groovymame · C · 275 lines · 161 code · 52 blank · 62 comment · 16 complexity · 9ff80902babf253ddc827fd64b51d46b MD5 · raw file

  1. /***************************************************************************
  2. video/brkthru.c
  3. ***************************************************************************/
  4. #include "emu.h"
  5. #include "includes/brkthru.h"
  6. /***************************************************************************
  7. Convert the color PROMs into a more useable format.
  8. Break Thru has one 256x8 and one 256x4 palette PROMs.
  9. I don't know for sure how the palette PROMs are connected to the RGB
  10. output, but it's probably the usual:
  11. bit 7 -- 220 ohm resistor -- GREEN
  12. -- 470 ohm resistor -- GREEN
  13. -- 1 kohm resistor -- GREEN
  14. -- 2.2kohm resistor -- GREEN
  15. -- 220 ohm resistor -- RED
  16. -- 470 ohm resistor -- RED
  17. -- 1 kohm resistor -- RED
  18. bit 0 -- 2.2kohm resistor -- RED
  19. bit 3 -- 220 ohm resistor -- BLUE
  20. -- 470 ohm resistor -- BLUE
  21. -- 1 kohm resistor -- BLUE
  22. bit 0 -- 2.2kohm resistor -- BLUE
  23. ***************************************************************************/
  24. PALETTE_INIT( brkthru )
  25. {
  26. int i;
  27. for (i = 0; i < machine.total_colors(); i++)
  28. {
  29. int bit0, bit1, bit2, bit3, r, g, b;
  30. bit0 = (color_prom[0] >> 0) & 0x01;
  31. bit1 = (color_prom[0] >> 1) & 0x01;
  32. bit2 = (color_prom[0] >> 2) & 0x01;
  33. bit3 = (color_prom[0] >> 3) & 0x01;
  34. r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  35. bit0 = (color_prom[0] >> 4) & 0x01;
  36. bit1 = (color_prom[0] >> 5) & 0x01;
  37. bit2 = (color_prom[0] >> 6) & 0x01;
  38. bit3 = (color_prom[0] >> 7) & 0x01;
  39. g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  40. bit0 = (color_prom[machine.total_colors()] >> 0) & 0x01;
  41. bit1 = (color_prom[machine.total_colors()] >> 1) & 0x01;
  42. bit2 = (color_prom[machine.total_colors()] >> 2) & 0x01;
  43. bit3 = (color_prom[machine.total_colors()] >> 3) & 0x01;
  44. b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  45. palette_set_color(machine, i, MAKE_RGB(r,g,b));
  46. color_prom++;
  47. }
  48. }
  49. /***************************************************************************
  50. Start the video hardware emulation.
  51. ***************************************************************************/
  52. static TILE_GET_INFO( get_bg_tile_info )
  53. {
  54. brkthru_state *state = machine.driver_data<brkthru_state>();
  55. /* BG RAM format
  56. 0 1
  57. ---- -c-- ---- ---- = Color
  58. ---- --xx xxxx xxxx = Code
  59. */
  60. int code = (state->m_videoram[tile_index * 2] | ((state->m_videoram[tile_index * 2 + 1]) << 8)) & 0x3ff;
  61. int region = 1 + (code >> 7);
  62. int colour = state->m_bgbasecolor + ((state->m_videoram[tile_index * 2 + 1] & 0x04) >> 2);
  63. SET_TILE_INFO(region, code & 0x7f, colour,0);
  64. }
  65. WRITE8_HANDLER( brkthru_bgram_w )
  66. {
  67. brkthru_state *state = space->machine().driver_data<brkthru_state>();
  68. state->m_videoram[offset] = data;
  69. tilemap_mark_tile_dirty(state->m_bg_tilemap, offset / 2);
  70. }
  71. static TILE_GET_INFO( get_fg_tile_info )
  72. {
  73. brkthru_state *state = machine.driver_data<brkthru_state>();
  74. UINT8 code = state->m_fg_videoram[tile_index];
  75. SET_TILE_INFO(0, code, 0, 0);
  76. }
  77. WRITE8_HANDLER( brkthru_fgram_w )
  78. {
  79. brkthru_state *state = space->machine().driver_data<brkthru_state>();
  80. state->m_fg_videoram[offset] = data;
  81. tilemap_mark_tile_dirty(state->m_fg_tilemap,offset);
  82. }
  83. VIDEO_START( brkthru )
  84. {
  85. brkthru_state *state = machine.driver_data<brkthru_state>();
  86. state->m_fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
  87. state->m_bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_cols, 16, 16, 32, 16);
  88. tilemap_set_transparent_pen(state->m_fg_tilemap, 0);
  89. tilemap_set_transparent_pen(state->m_bg_tilemap, 0);
  90. }
  91. WRITE8_HANDLER( brkthru_1800_w )
  92. {
  93. brkthru_state *state = space->machine().driver_data<brkthru_state>();
  94. if (offset == 0) /* low 8 bits of scroll */
  95. state->m_bgscroll = (state->m_bgscroll & 0x100) | data;
  96. else if (offset == 1)
  97. {
  98. /* bit 0-2 = ROM bank select */
  99. memory_set_bank(space->machine(), "bank1", data & 0x07);
  100. /* bit 3-5 = background tiles color code */
  101. if (((data & 0x38) >> 2) != state->m_bgbasecolor)
  102. {
  103. state->m_bgbasecolor = (data & 0x38) >> 2;
  104. tilemap_mark_all_tiles_dirty(state->m_bg_tilemap);
  105. }
  106. /* bit 6 = screen flip */
  107. if (state->m_flipscreen != (data & 0x40))
  108. {
  109. state->m_flipscreen = data & 0x40;
  110. tilemap_set_flip(state->m_bg_tilemap, state->m_flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  111. tilemap_set_flip(state->m_fg_tilemap, state->m_flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  112. }
  113. /* bit 7 = high bit of scroll */
  114. state->m_bgscroll = (state->m_bgscroll & 0xff) | ((data & 0x80) << 1);
  115. }
  116. }
  117. #if 0
  118. static void show_register( bitmap_t *bitmap, int x, int y, UINT32 data )
  119. {
  120. char buf[5];
  121. sprintf(buf, "%04X", data);
  122. ui_draw_text(y, x, buf);
  123. }
  124. #endif
  125. static void draw_sprites( running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect, int prio )
  126. {
  127. brkthru_state *state = machine.driver_data<brkthru_state>();
  128. int offs;
  129. /* Draw the sprites. Note that it is important to draw them exactly in this */
  130. /* order, to have the correct priorities. */
  131. /* Sprite RAM format
  132. 0 1 2 3
  133. ccc- ---- ---- ---- ---- ---- ---- ---- = Color
  134. ---d ---- ---- ---- ---- ---- ---- ---- = Double Size
  135. ---- p--- ---- ---- ---- ---- ---- ---- = Priority
  136. ---- -bb- ---- ---- ---- ---- ---- ---- = Bank
  137. ---- ---e ---- ---- ---- ---- ---- ---- = Enable/Disable
  138. ---- ---- ssss ssss ---- ---- ---- ---- = Sprite code
  139. ---- ---- ---- ---- yyyy yyyy ---- ---- = Y position
  140. ---- ---- ---- ---- ---- ---- xxxx xxxx = X position
  141. */
  142. for (offs = 0;offs < state->m_spriteram_size; offs += 4)
  143. {
  144. if ((state->m_spriteram[offs] & 0x09) == prio) /* Enable && Low Priority */
  145. {
  146. int sx, sy, code, color;
  147. sx = 240 - state->m_spriteram[offs + 3];
  148. if (sx < -7)
  149. sx += 256;
  150. sy = 240 - state->m_spriteram[offs + 2];
  151. code = state->m_spriteram[offs + 1] + 128 * (state->m_spriteram[offs] & 0x06);
  152. color = (state->m_spriteram[offs] & 0xe0) >> 5;
  153. if (state->m_flipscreen)
  154. {
  155. sx = 240 - sx;
  156. sy = 240 - sy;
  157. }
  158. if (state->m_spriteram[offs] & 0x10) /* double height */
  159. {
  160. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  161. code & ~1,
  162. color,
  163. state->m_flipscreen, state->m_flipscreen,
  164. sx, state->m_flipscreen ? sy + 16 : sy - 16,0);
  165. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  166. code | 1,
  167. color,
  168. state->m_flipscreen, state->m_flipscreen,
  169. sx,sy,0);
  170. /* redraw with wraparound */
  171. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  172. code & ~1,
  173. color,
  174. state->m_flipscreen, state->m_flipscreen,
  175. sx,(state->m_flipscreen ? sy + 16 : sy - 16) + 256,0);
  176. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  177. code | 1,
  178. color,
  179. state->m_flipscreen, state->m_flipscreen,
  180. sx,sy + 256,0);
  181. }
  182. else
  183. {
  184. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  185. code,
  186. color,
  187. state->m_flipscreen, state->m_flipscreen,
  188. sx,sy,0);
  189. /* redraw with wraparound */
  190. drawgfx_transpen(bitmap,cliprect,machine.gfx[9],
  191. code,
  192. color,
  193. state->m_flipscreen, state->m_flipscreen,
  194. sx,sy + 256,0);
  195. }
  196. }
  197. }
  198. }
  199. SCREEN_UPDATE( brkthru )
  200. {
  201. brkthru_state *state = screen->machine().driver_data<brkthru_state>();
  202. tilemap_set_scrollx(state->m_bg_tilemap, 0, state->m_bgscroll);
  203. tilemap_draw(bitmap, cliprect, state->m_bg_tilemap, TILEMAP_DRAW_OPAQUE, 0);
  204. /* low priority sprites */
  205. draw_sprites(screen->machine(), bitmap, cliprect, 0x01);
  206. /* draw background over low priority sprites */
  207. tilemap_draw(bitmap, cliprect, state->m_bg_tilemap, 0, 0);
  208. /* high priority sprites */
  209. draw_sprites(screen->machine(), bitmap, cliprect, 0x09);
  210. /* fg layer */
  211. tilemap_draw(bitmap, cliprect, state->m_fg_tilemap, 0, 0);
  212. /* show_register(bitmap, 8, 8, (UINT32)state->m_flipscreen); */
  213. return 0;
  214. }