1 // license:BSD-3-Clause
2 // copyright-holders:David Graves
3 #include "emu.h"
4 #include "includes/warriorb.h"
5 #include "screen.h"
6
7 /************************************************************
8 SPRITE DRAW ROUTINE
9 ************************************************************/
10
draw_sprites(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect,int x_offs,int y_offs,int chip)11 void warriorb_state::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int x_offs, int y_offs, int chip)
12 {
13 u32 pri_mask;
14
15 #ifdef MAME_DEBUG
16 int unknown = 0;
17 #endif
18
19 /* pdrawgfx() needs us to draw sprites front to back */
20 for (int offs = 0; offs < m_spriteram.bytes() / 2; offs += 4)
21 {
22 int data = m_spriteram[offs + 1];
23 const u32 tilenum = data & 0x7fff;
24
25 data = m_spriteram[offs + 0];
26 int y = (-(data & 0x1ff) - 24) & 0x1ff; /* (inverted y adjusted for vis area) */
27 const bool flipy = (data & 0x200) >> 9;
28
29 const u16 data2 = m_spriteram[offs + 2];
30 /* 8,4 also seen in msbyte */
31 const int priority = (data2 & 0x0100) >> 8; // 1 = low
32
33 if(priority)
34 pri_mask = 0xfffe;
35 else
36 pri_mask = 0;
37
38 const u32 color = (data2 & 0x7f);
39
40 data = m_spriteram[offs + 3];
41 int x = (data & 0x3ff);
42 const bool flipx = (data & 0x400) >> 10;
43
44 #ifdef MAME_DEBUG
45 if (data2 & 0xf280) unknown |= (data2 &0xf280);
46 #endif
47
48 x -= x_offs;
49 y += y_offs;
50
51 /* sprite wrap: coords become negative at high values */
52 if (x > 0x3c0) x -= 0x400;
53 if (y > 0x180) y -= 0x200;
54
55 m_gfxdecode[chip]->gfx(0)->prio_transpen(bitmap,cliprect,
56 tilenum,
57 color,
58 flipx,flipy,
59 x,y,
60 screen.priority(),pri_mask,0);
61 }
62
63 #ifdef MAME_DEBUG
64 if (unknown)
65 popmessage("unknown sprite bits: %04x",unknown);
66 #endif
67 }
68
69
70 /**************************************************************
71 SCREEN REFRESH
72 **************************************************************/
73
update_screen(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect,int xoffs,int chip)74 u32 warriorb_state::update_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int xoffs, int chip)
75 {
76 tc0100scn_device *tc0100scn = m_tc0100scn[chip];
77 u8 layer[3];
78
79 tc0100scn->tilemap_update();
80
81 layer[0] = tc0100scn->bottomlayer();
82 layer[1] = layer[0] ^ 1;
83 layer[2] = 2;
84
85 /* Clear priority bitmap */
86 screen.priority().fill(0, cliprect);
87
88 /* chip 0 does tilemaps on the left, chip 1 does the ones on the right */
89 // draw bottom layer
90 const u8 nodraw = tc0100scn->tilemap_draw(screen, bitmap, cliprect, layer[0], TILEMAP_DRAW_OPAQUE, 0); /* left */
91
92 /* Ensure screen blanked even when bottom layers not drawn due to disable bit */
93 if (nodraw)
94 bitmap.fill(m_tc0110pcr[chip]->black_pen(), cliprect);
95
96 // draw middle layer
97 tc0100scn->tilemap_draw(screen, bitmap, cliprect, layer[1], 0, 1);
98
99 /* Sprites can be under/over the layer below text layer */
100 draw_sprites(screen, bitmap, cliprect, xoffs * chip, 8, chip); // draw sprites
101
102 // draw top(text) layer
103 tc0100scn->tilemap_draw(screen, bitmap, cliprect, layer[2], 0, 0);
104 return 0;
105 }
106
screen_update_left(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)107 u32 warriorb_state::screen_update_left(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect){ return update_screen(screen, bitmap, cliprect, 40 * 8, 0); }
screen_update_right(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)108 u32 warriorb_state::screen_update_right(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect){ return update_screen(screen, bitmap, cliprect, 40 * 8, 1); }
109