summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/fantland.c
blob: b39f331e30a3b2907a7ac6367625f0170c0a6f0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************************

                      -= Electronic Devices / International Games =-

                    driver by   Luca Elia (l.elia@tin.it)

    This game has sprites only:

    tiles are 16 x 16 x 6. There are 0x400 sprites, each one is allotted
    8 bytes of memory (but only 5 are used) in spriteram (0x54000):

    Offset:     Bits:           Value:

        0                       X (low bits)

        1       7--- ----       X (high bit)
                -6-- ----       Y (high bit)
                --5- ----       Flip X
                ---4 ----       Flip Y
                ---- 32--
                ---- --10       Color

        2                       Code (high bits)

        3                       Code (low bits)

        4                       Y (low bits)

    Then 2 tables follow, 0x400 bytes each:

    - the first table  (0x56000) contains 1 byte per sprite: an index in the second table
    - the second table (0x56400) is either an x,y offset or an index in spriteram_2 (0x60000):

        0                       X offset (low bits)

        1                       Y offset (low bits)

        2       7--- ----       If 1, the following bits are an index in spriteram_2 for the real X&Y & Code offsets
                -654 321-
                ---- ---0       X offset (high bit)

        3       7654 321-
                ---- ---0       Y offset (high bit)


    Spriteram_2 contains 0x4000 X&Y & Code offsets:

        0                       Y offset (low bits)

        1       7--- ----       Flip X (xor with that in spriteram)
				-6-- ----       Flip Y ""
				--54 321-       Code offset
                ---- ---0       Y offset (high bit)

        2                       X offset (low bits)

        3                       X offset (high bit)

***************************************************************************************/

#include "driver.h"

static void draw_sprites(running_machine *machine, mame_bitmap *bitmap,const rectangle *cliprect)
{
	UINT8	*indx_ram	=	spriteram + 0x2000,	// this ram contains indexes into offs_ram
			*offs_ram	=	spriteram + 0x2400,	// this ram contains x,y offsets or indexes into spriteram_2
			*ram		=	spriteram,			// current sprite pointer in spriteram
			*ram2		=	indx_ram;			// current sprite pointer in indx_ram

	// wheelrun is the only game with a smaller visible area
	int special = (machine->screen[0].visarea.max_y - machine->screen[0].visarea.min_y + 1) < 0x100;

	for ( ; ram < indx_ram; ram += 8,ram2++)
	{
		int attr,code,color, x,y,xoffs,yoffs,flipx,flipy, idx;

		attr	=	ram[1];

		x		=	ram[0];
		code	=	ram[3] + (ram[2] << 8);
		y		=	ram[4];

		color	=	(attr & 0x03);
		flipy	=	(attr & 0x10) ? 1 : 0;
		flipx	=	(attr & 0x20) ? 1 : 0;

		y		+=	(attr & 0x40) << 2;
		x		+=	(attr & 0x80) << 1;

		// Index in the table of offsets

		idx		=	ram2[0] * 4;

		// Fetch the offsets

		if (offs_ram[idx + 2] & 0x80)
		{
			// x,y & code offset is in spriteram_2, this is its index

			idx		=	(((offs_ram[idx + 2] << 8) + offs_ram[idx + 3]) & 0x3fff) * 4;

			yoffs	=	spriteram_2[idx + 0] + (spriteram_2[idx + 1] << 8);
			xoffs	=	spriteram_2[idx + 2] + (spriteram_2[idx + 3] << 8);

			code	+=	(yoffs & 0x3e00) >> 9;
			flipy	^=	(yoffs & 0x4000) ? 1 : 0;
			flipx	^=	(yoffs & 0x8000) ? 1 : 0;
		}
		else
		{
			// this is an x,y offset

			yoffs	=	((offs_ram[idx + 3] & 0x01) << 8) + offs_ram[idx + 1];
			xoffs	=	((offs_ram[idx + 2] & 0x01) << 8) + offs_ram[idx + 0];
		}

		yoffs	=	(yoffs & 0xff) - (yoffs & 0x100);
		xoffs	=	(xoffs & 0x1ff);

		if (xoffs >= 0x180)		xoffs -= 0x200;

		y		+=	yoffs;
		x		+=	xoffs;

		// wheelrun needs y=0xf0 & yoffs=0x50 to be rendered at screen y 0x40
		if (special && y > 0)
			y &= 0xff;

		y		=	(y & 0xff) - (y & 0x100);
		x		=	(x & 0x1ff);

		if (x >= 0x180)		x -= 0x200;

		drawgfx(bitmap,machine->gfx[0], code,color, flipx,flipy, x,y, cliprect,TRANSPARENCY_PEN,0);
	}
}

VIDEO_UPDATE( fantland )
{
	fillbitmap(bitmap,machine->pens[0],cliprect);
	draw_sprites(machine,bitmap,cliprect);

	return 0;
}