1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood
3 /* Poke Champ */
4 
5 #include "emu.h"
6 #include "includes/pokechmp.h"
7 
8 
pokechmp_videoram_w(offs_t offset,uint8_t data)9 void pokechmp_state::pokechmp_videoram_w(offs_t offset, uint8_t data)
10 {
11 	m_videoram[offset] = data;
12 	m_bg_tilemap->mark_tile_dirty(offset / 2);
13 }
14 
pokechmp_flipscreen_w(uint8_t data)15 void pokechmp_state::pokechmp_flipscreen_w(uint8_t data)
16 {
17 	if (flip_screen() != (data & 0x80))
18 	{
19 		flip_screen_set(data & 0x80);
20 		machine().tilemap().mark_all_dirty();
21 	}
22 }
23 
TILE_GET_INFO_MEMBER(pokechmp_state::get_bg_tile_info)24 TILE_GET_INFO_MEMBER(pokechmp_state::get_bg_tile_info)
25 {
26 	uint8_t *videoram = m_videoram;
27 	int code = videoram[tile_index*2+1] + ((videoram[tile_index*2] & 0x3f) << 8);
28 	int color = videoram[tile_index*2] >> 6;
29 
30 	tileinfo.set(0, code, color, 0);
31 }
32 
video_start()33 void pokechmp_state::video_start()
34 {
35 	m_bg_tilemap = &machine().tilemap().create(
36 			*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(pokechmp_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS,
37 			8, 8, 32, 32);
38 }
39 
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)40 void pokechmp_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
41 {
42 	uint8_t *spriteram = m_spriteram;
43 	int offs;
44 
45 	for (offs = 0;offs < m_spriteram.bytes();offs += 4)
46 	{
47 		if (spriteram[offs] != 0xf8)
48 		{
49 			int sx,sy,flipx,flipy;
50 
51 
52 			sx = 240 - spriteram[offs+2];
53 			sy = 240 - spriteram[offs];
54 
55 			flipx = spriteram[offs+1] & 0x04;
56 			flipy = spriteram[offs+1] & 0x02;
57 			if (flip_screen()) {
58 				sx=240-sx;
59 				sy=240-sy;
60 				if (flipx) flipx=0; else flipx=1;
61 				if (flipy) flipy=0; else flipy=1;
62 			}
63 			int tileno = spriteram[offs+3];
64 			if (spriteram[offs+1] & 0x01) tileno += 0x100;
65 			if (spriteram[offs+1] & 0x08) tileno += 0x200;
66 
67 			m_gfxdecode->gfx(1)->transpen(bitmap,cliprect,
68 					tileno,
69 					(spriteram[offs+1] & 0xf0) >> 4,
70 					flipx,flipy,
71 					sx,sy,0);
72 		}
73 	}
74 }
75 
screen_update_pokechmp(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)76 uint32_t pokechmp_state::screen_update_pokechmp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
77 {
78 	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
79 	draw_sprites(bitmap, cliprect);
80 	return 0;
81 }
82