C Mahjong Clinic video static emulator

このエントリーをはてなブックマークに追加このエントリのはてなブックマーク数このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをつぶやく

/* Mahjong Clinic video static emulator */ class raster_image{ width = null; height = null; data = null; funct [...]

/*
Mahjong Clinic video static emulator
*/
class raster_image{
	width = null; height = null; data = null;
	function image_init(w, h)
	{
		width = w;
		height = h;
		data = array(w * h, 0x7f7f7f7f)
	}
	function put(x, y, rgb)
	{
		data[y * width + x] = rgb
	}
	function save(outfile)
	{
		png_save(outfile, this)
	}
	function transback_draw()
	{
		local dest = 0
		for(local y = 0; y < height; y += 16, dest += width * 16){
		for(local x = y & 0x10; x < width; x += 32){
		for(local i = 0; i < 16; i++){
		for(local j = 0; j < 16*width; j+=width){
			data[dest + x + i + j] = 0x7f3f3f3f
		}}}}
	}
	function image_add_height(s)
	{
		if(this.width != s.width){
			return false;
		}
		this.height += s.height
		this.data.extend(s.data)
		return true;
	}
}
class homedata_layer0 extends raster_image{
	m_color = null; m_charcter = null; m_map = null; m_bank = null;

	function colorpart(v, bit4_1, bit0)
	{
		local ret = (v >>> bit4_1) & 0x0f
		return (ret << 1) | onebit_move(v, bit0, 0)
	}
	constructor(pal, c, m, b){
		image_init(512, 256)
		m_charcter = c
		m_map = m
		m_bank = b
		m_color = []
		foreach(v in pal){
			local r = colorpart(v, 12, 2) << 3
			local g = colorpart(v, 8, 1) << 3
			local b = colorpart(v, 4, 0) << 3
			m_color.append((0xff << 24) | (r << 16) | (g << 8) | b)
		}
	}
	function pixel_put(x, y, color_index, d)
	{
		put(x, y, m_color[color_index | d])
	}
	function render_chip(x, y, char_index, color_index)
	{
		char_index = char_index << 3
		color_index = color_index << 4
		for(local yy = 0; yy < 8; yy+=1){
			local chardata = m_charcter[char_index];
			char_index += 1
			for(local xx = 0; xx < 8; xx+=1){
				chardata = (chardata << 4) | (chardata >>> 28)
				local d = chardata & 0x0f
				pixel_put(x + xx, y, color_index, d)
			}
			y += 1
		}
	}
	function render_screen()
	{
		local i = 0, y = 0;
		for(local y = 0; y < height; y += 8){
			for(local x = 0; x < width; x += 8){
				local char_index = m_map[i] & 0x03ff
				char_index = char_index | (m_bank << 10)
				local color_index = m_map[i] >>> 10
				render_chip(x, y, char_index, color_index | (m_bank << 6));
				i += 1
			}
		}
	}
}
class homedata_layer1 extends homedata_layer0{
	function render_screen()
	{
		transback_draw();
		local i = 0, y = 0;
		for(local y = 0; y < height; y += 8){
			for(local x = 0; x < width; x += 8){
				local char_index = m_map[i] & 0x07ff
				char_index = char_index | (m_bank << 11)
				local color_index = m_map[i] >>> 11
				render_chip(x, y, char_index, color_index | ((m_bank & 3) << 6));
				i += 1
			}
		}
	}
	function pixel_put(x, y, color_index, d)
	{
		if(d == 0){
			return;
		}
		put(x, y, m_color[color_index | d])
	}
}
function tile_render(rompath, outfile)
{
	local color = fileio_load_be16(rompath + "colorrom.bin")
	local charcter = fileio_load_be32(rompath + "x80_a03.1g")
	local map = fileio_load_be16("tilemap.bin")
	local bank = 5
	local screen0 = homedata_layer0(
		color.slice(0x6000, 0x7000),
		fileio_load_be32(rompath + "x80_a03.1g"),
		map.slice(0, 0x0800),
		bank & 0x3
	)
	screen0.render_screen()

	local screen1 = homedata_layer1(
		color.slice(0x7000),
		fileio_load_be32(rompath + "tilechar.bin"),
		map.slice(0x0800, 0x1000),
		(bank >>> 3) & 0x7
	)
	screen1.render_screen()

	screen0.image_add_height(screen1)
	screen0.save(outfile)
}

Posted by at 2015/1/10 20:16

よく投稿されているコード

タグ

最近投稿されたコード