1 #include "driver.h"
2
3 unsigned char *macross_workram;
4 unsigned char *macross_spriteram;
5 unsigned char *macross_txvideoram;
6 unsigned char *macross_videocontrol;
7 size_t macross_txvideoram_size;
8
9 static unsigned char * dirtybuffer;
10 static struct osd_bitmap *tmpbitmap;
11 static int flipscreen = 0;
12
13
macross_vh_start(void)14 int macross_vh_start(void)
15 {
16 dirtybuffer = (unsigned char*)malloc(macross_txvideoram_size/2);
17 tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height);
18
19 if (!dirtybuffer || !tmpbitmap)
20 {
21 if (tmpbitmap) bitmap_free(tmpbitmap);
22 if (dirtybuffer) free(dirtybuffer);
23 return 1;
24 }
25
26 macross_spriteram = macross_workram + 0x8000;
27
28 return 0;
29 }
30
macross_vh_stop(void)31 void macross_vh_stop(void)
32 {
33 bitmap_free(tmpbitmap);
34 free(dirtybuffer);
35
36 dirtybuffer = 0;
37 tmpbitmap = 0;
38 }
39
40
READ_HANDLER(macross_txvideoram_r)41 READ_HANDLER( macross_txvideoram_r )
42 {
43 return READ_WORD(¯oss_txvideoram[offset]);
44 }
45
WRITE_HANDLER(macross_txvideoram_w)46 WRITE_HANDLER( macross_txvideoram_w )
47 {
48 int oldword = READ_WORD(¯oss_txvideoram[offset]);
49 int newword = COMBINE_WORD(oldword,data);
50
51 if (oldword != newword)
52 {
53 WRITE_WORD(¯oss_txvideoram[offset],newword);
54 dirtybuffer[offset/2] = 1;
55 }
56 }
57
58
59
macross_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)60 void macross_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
61 {
62 int offs;
63
64 palette_init_used_colors();
65
66 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
67 {
68 int color = (READ_WORD(¯oss_txvideoram[offs*2]) >> 12);
69 memset(&palette_used_colors[512 + 16 * color],PALETTE_COLOR_USED,16);
70 }
71
72 for (offs = 0; offs < 256*16; offs += 16)
73 {
74 if (READ_WORD(¯oss_spriteram[offs]) != 0)
75 memset(&palette_used_colors[256 + 16*READ_WORD(¯oss_spriteram[offs+14])],PALETTE_COLOR_USED,16);
76 }
77
78 if (palette_recalc())
79 {
80 memset(dirtybuffer, 1, macross_txvideoram_size/2);
81 }
82
83 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
84 {
85 if (dirtybuffer[offs])
86 {
87 int sx = offs / 32;
88 int sy = offs % 32;
89
90 int tilecode = READ_WORD(¯oss_txvideoram[offs*2]);
91
92 if (flipscreen)
93 {
94 sx = 47-sx;
95 sy = 31-sy;
96 }
97
98 drawgfx(tmpbitmap,Machine->gfx[0],
99 tilecode & 0xfff,
100 tilecode >> 12,
101 flipscreen, flipscreen,
102 8*sx,8*sy,
103 0,TRANSPARENCY_NONE,0);
104
105 dirtybuffer[offs] = 0;
106 }
107 }
108
109 /* copy the character mapped graphics */
110 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
111
112 for (offs = 0; offs < 256*16; offs += 16)
113 {
114 if (READ_WORD(¯oss_spriteram[offs]) != 0)
115 {
116 int sx = (READ_WORD(¯oss_spriteram[offs+8]) & 0x1ff);
117 int sy = (READ_WORD(¯oss_spriteram[offs+12]) & 0x1ff);
118 int tilecode = READ_WORD(¯oss_spriteram[offs+6]);
119 int xx = (READ_WORD(¯oss_spriteram[offs+2]) & 0x0f) + 1;
120 int yy = (READ_WORD(¯oss_spriteram[offs+2]) >> 4) + 1;
121 int width = xx;
122 int delta = 16;
123 int startx = sx;
124
125 if (flipscreen)
126 {
127 sx = 367 - sx;
128 sy = 239 - sy;
129 delta = -16;
130 startx = sx;
131 }
132
133 do
134 {
135 do
136 {
137 drawgfx(bitmap,Machine->gfx[2],
138 tilecode & 0x3fff,
139 READ_WORD(¯oss_spriteram[offs+14]),
140 flipscreen, flipscreen,
141 sx & 0x1ff,sy & 0x1ff,
142 &Machine->visible_area,TRANSPARENCY_PEN,15);
143
144 tilecode++;
145 sx += delta;
146 } while (--xx);
147
148 sy += delta;
149 sx = startx;
150 xx = width;
151 } while (--yy);
152 }
153 }
154 }
155