satonofitoさんが投稿したコード一覧

C s

/*
Super Real Marjong P3 static video emulator
*/
class p3_sprite_1 extends raster_image{
	m_visible_area = {x = 511, y = 28 - 1, width = 384 + 1, height = 224 + 1}
	m_charcter = null; m_map = null; m_color = null;
	function map_init(vram, charbank){
		local map = []
		for(local i = 0; i < 0x200; i++){
			local attr = {y_pos = 0, y_flip = 0, x_pos = 0, x_flip = 0, color = 0, charcter = 0, bank = 0}
			attr.y_pos = vram[i] ^ 0xff
			attr.charcter = vram[0x1000 + i]
			attr.x_pos = vram[0x1200 + i]
			attr.x_flip = vram[0x3000 + i] & 0x80 ? 0x1ff : 0
			attr.y_flip = vram[0x3000 + i] & 0x40 ? 0xff : 0
			attr.bank = onebit_move(vram[0x3000 + i], 5, 0)
			attr.charcter = attr.charcter | ((vram[0x3000 + i] & 0x1f) << 8)
			if(attr.bank != 0){
				attr.charcter = attr.charcter | ((charbank +1) << 13)
			}
			attr.color = vram[0x3200 + i] >>> 3
			attr.x_pos = attr.x_pos | onebit_move(vram[0x3200 + i], 0, 8)
			map.append(attr)
		}
		map.reverse() //render higher -> lower address
		return map
	}

	function color_init(rom){
		local color = []
		foreach(v in rom){
			local r = (v & 0x1f) << 3
			v = v >>> 5
			local g = (v & 0x1f) << 3
			v = v >>> 5
			local b = (v & 0x1f) << 3
			color.append(0xff000000 | (r << 16) | (g << 8) | b)
		}
		return color
	}
	constructor(pal, charcter, m, charbank){
		image_init(1<<9, 1<<8, 0x7f7f7f7f);
		transback_draw(0x7f3f3f3f)
		m_map = map_init(m, charbank)
		m_color = color_init(pal)
		m_charcter = charcter
	}
	function render16x16(s){
		for(local y = 0, d = 0; y < 16; y++){
		for(local x = 0; x < 16; x++){
			if(x == 0 || x == 8){
				d = m_charcter[s.charcter]
				s.charcter += 1
			}
			d = (d << 4) | (d >>> 28)
			if((d & 0xf) != 0){
				put(
					(s.x_pos + (x ^ s.x_flip)) & 0x1ff,
					(s.y_pos + (y ^ s.y_flip)) & 0xff,
					m_color[s.color | (d & 0xf)]
				)
			}
		}}
	}
	function render(){
		foreach(attr in m_map){
			local s = clone attr
			s.charcter = s.charcter << (3 + 2)
			s.color = s.color << 4
			render16x16(s)
		}
		rect_draw(m_visible_area)
	}
}
/*
pseudo nametable style sprite.

- 横2x縦16個のスプライトを並べて描画する。
- 描画開始番号から0までを順番に描画する。
- 描画座標は1単位で1つ設定し、他のスプライトは順番に並べる。
- バンクは設定できないらしい。
並べる順番:
 0  1
 2  3
 4  5
 (中略)
30 31

b200h + (unit number) << 4
7:0 描画単位開始 position x bit 7:0

b204h + (unit number) << 4
7:0 描画単位開始 position y bit 7:0

b301h
3:0 描画単位開始番号 (1:15, 0:disable, other:num - 1)

b302h
7:0 描画単位 x position bit8 for bit7:0 (bit number == unit number)

b303h
7:0 b302h の対象 bit15:8

c400h-c5ffh
7:0 charcter index bit 7:0

e400h-e5ffh
7   x flip
6   y flip
4:0 charcter index bit 12:8

e600h-e7ffh
7:3 color index

atrribute RAM address bit
m:9 each attribute table
8:5 2x16 block unit number
4:0 internal sprite number
*/
class p3_sprite_2x16 extends p3_sprite_1{
	m_visible_area = {x = 511, y = 13 - 1, width = 384 + 1, height = 224 + 1} //?
	function map_init(vram, charbank){
		local map = []
		local unitindex = vram[0x0301] & 0xf
		local unit_x_bit8 = vram[0x302] | (vram[0x303] << 8)
		if(unitindex == 1){
			unitindex = 15
		}else{
			unitindex--
		}

		local global_xy_a = 0x0200 | (unitindex << 4)
		while(unitindex >= 0){
			local global_y = vram[global_xy_a + 0] ^ 0xff
			local global_x = vram[global_xy_a + 4] | onebit_move(unit_x_bit8, unitindex, 8)
			//print(format("i:%d x:%03x y:%02x\n", unitindex, global_x, global_y))
			for(local i = 0, attr_base_a = unitindex << 5; i < 0x20; i++, attr_base_a++){
				local attr = {y_pos = global_y, y_flip = 0, x_pos = global_x, x_flip = 0, color = 0, charcter = 0, bank = 0}
				attr.x_flip = vram[attr_base_a + 0x3400] & 0x80 ? 0x1ff : 0
				attr.y_flip = vram[attr_base_a + 0x3400] & 0x40 ? 0xff : 0
				attr.charcter = (vram[attr_base_a + 0x3400] & 0x1f) << 8
				attr.charcter = attr.charcter | vram[attr_base_a + 0x1400]
				attr.color = (vram[attr_base_a + 0x3600] >>> 3)
				map.append(attr)
				if(i & 1){
					global_y += 16
					global_y = global_y & 0xff
					attr.x_pos += 16
					attr.x_pos = attr.x_pos & 0x1ff
				}
			}
			unitindex--;
			global_xy_a -= (1<<4)
		}
		return map
	}
}
/*
VRAM image is Z80 memory b000h-ffffh
*/
function p3_render(rompath, outfile)
{
	local color = fileio_load_be16(rompath + "color.bin")
	local charcter = fileio_load_be32(rompath + "spritechar.bin")
	local vram = fileio_load_8(rompath + "vram.bin")
	local v1 = p3_sprite_1(
		color, charcter, vram,
		(0x70 >>> 6) & 0x3 //ioport 0x40
	)
	v1.render()
	local v32 = p3_sprite_2x16(
		color, charcter, vram,
		0 //bank is not used
	)
	v32.render()
	v1.image_add_height(v32)
	v1.save(outfile)
}
/*
charcter ROM data bit
     bit3   2  1  0
set0 za0-08 06 04 02
set1 za0-07 05 03 01

charcter ROM address は set0 -> set1 の順番

charcter size 16x16
address assignments  -> reorder address
msb:5 charcter index |msb:5 charcter index
4   y.offset 3       |4:1 y.offset 3:0
3   x.offset 3       |0   x.offset 3
2:0 y.offset 2:0     |
*/
function p3_charrom_decode(infile0, infile1, outfile)
{
	local chardata = romio_bit_8x4to32(infile0)
	chardata.extend(romio_bit_8x4to32(infile1))
	local dest = array(chardata.len(), 0)
	for(local index = 0; index < chardata.len() >>> 5; index++){
	for(local y = 0; y < 16; y++){
	for(local x = 0; x < 16; x += 8){
		local src_a = (
			(index << 5) |
			onebit_move(y, 3, 4) | onebit_move(x, 3, 3) |
			(y & 0x7)
		)
		local dest_a = (
			(index << 5) |
			(y << 1) | onebit_move(x, 3, 0)
		)
		dest[dest_a] = chardata[src_a]
	}}}
	fileio_save_be32(outfile, dest)
}

C Mahjong Clinic video static emulator

/*
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)
}

C bit slice

static inline uint32_t bitmask(int msb, int lsb)
{
	if((msb - lsb) >= 32){
		return ~0UL;
	}

	int shift = msb - lsb + 1;
	return (1 << shift) - 1;
}
/*
27:0 -> offset 0 27:0
47:28 -> offset 1 19:0
*/

static inline uint32_t slice48(const uint32_t *c, int msb, int lsb)
{
#define BN (28) //bitcount / word
	uint32_t v = 0;
	if(msb < BN && lsb < BN){
		v = (c[0] >> lsb) & bitmask(msb, lsb);
	}else if(msb >= BN && lsb < BN){
		uint32_t high = c[1] & bitmask(msb, BN);
		uint32_t low = (c[0] >> lsb) & bitmask(lsb, 0);
		high <<= (BN - lsb);
		v = high | low;
	}else{ //msb >= 28 && lsb >= 28
		msb -= BN;
		lsb -= BN;
		v = (c[1] >> lsb) & bitmask(msb, lsb);
	}
	return v;
#undef BN
}

C DE1 flash 書き込み

/*
S29AL032D 70TFI 04, 4Mx8bit, 2Mx16bit
address bus 20:0:-1, data bus 15:0
0-0x1f_ffff/0x3f_ffff x16/x8
byte access mode only.
*/
#include "stdint.h"
#include "tilemap.h"
enum{
	TEST = 0
};
/*
sector address
sector A[20:12] sizeK x8 range-
 0 0_0000_0000  8 0        | 8 0_0000_1xxx 64 0x010000
 1 0_0000_0001  8 0x002000 | 9 0_0001_0xxx 64 0x020000
 2 0_0000_0010  8 0x004000 |10 0_0001_1xxx 64 0x030000
 3 0_0000_0011  8 0x006000 |11 0_0010_0xxx 64 0x040000
 4 0_0000_0100  8 0x008000 |
 5 0_0000_0101  8 0x00a000 |
 6 0_0000_0110  8 0x00c000 |69 1_1111_0xxx 64 0x3e0000
 7 0_0000_0111  8 0x00e000 |70 1_1111_1xxx 64 0x3f0000-0x3fffff
*/
static void erase(volatile uint8_t *command, volatile uint8_t *dest, uint32_t offset)
{
	switch(offset){
	case 0x0000: case 0x2000: case 0x4000: case 0x6000:
	case 0x8000: case 0xa000: case 0xc000: case 0xe000:
		break;
	default:
		if((offset & 0xffff) != 0){
			return;
		}
		break;
	}
	if(TEST == 0){
		const int m = 2;
		command[0xaaa * m] = 0xaa;
		command[0x555 * m] = 0x55;
		command[0xaaa * m] = 0x80;
		command[0xaaa * m] = 0xaa;
		command[0x555 * m] = 0x55;
		*dest = 0x30;
	}
//	string_print("ERASE NOW  ", tileaxis(14, 0));
//	long_print(offset, tileaxis(14, 12));
	tty_print("ERASE NOW   ");
	tty_long(offset);
	tty_adjust(0, -20);
	if(TEST == 1){
		return;
	}
	do{
		asm("nop;nop;nop;nop;");
	}while(*dest != 0xff);
}
static void toggle_bit(volatile const uint8_t *dest)
{
	uint8_t d0 = *dest;
	uint8_t d1 = *dest;
	while((d0 & 0x40) != (d1 & 0x40)){
		d0 = d1;
		d1 = *dest;
	};
}

/*
command definitions
Reset        XXX:F0
Program      AAA:AA 555:55 AAA:A0 PA:PD
Chip Erase   AAA:AA 555:55 AAA:80 AAA:AA 555:55 AAA:10
Sector Erase AAA:AA 555:55 AAA:80 AAA:AA 555:55 SA:30

Notes:
4.Data bits DQ15-DQ8 are don't cares for unlock and command cycles.
5.Address bits A19-A11 are don't cares for unlock and command cycles,
unless SA or PA required. ##A19? A20?

progrmming oreration   9/11us byte/word
sector erase operation 0.7 sec
tws   0 ns
tcp  35 ns
tcph 30 ns
*/

void flash_program(const uint8_t *src, uint32_t offset, uint32_t length)
{
	volatile uint8_t *const command = (uint8_t *) 0x01000001;
	volatile uint8_t *dest = (uint8_t *) 0x01000001;
	const int m = 2;
	dest += offset * m;
	while(length != 0){
		erase(command, dest, offset);

		if(TEST == 0){
			command[0xaaa * m] = 0xaa;
			command[0x555 * m] = 0x55;
			command[0xaaa * m] = 0xa0;
			*dest = *src;
		}

		//string_print("PROGRAMMING", tileaxis(14, 0));
		//long_print(offset++, tileaxis(14, 12));
		tty_print("PROGRAMMING ");
		tty_long(offset);
		tty_adjust(0, -20);
		if(TEST == 0){
			toggle_bit(dest);
		}
		offset += 1;
		dest += m;
		src++;
		length--;
	}
}

C sdcard_spiport

declare sdcard_spiport{
	input select, rd, wr, bytemask[2];
	input d[16]; output q[16], cpu_wait;
	input spi_do; output spi_clk, spi_di;
}

//spi clock frequency is 64MHz / 4 って書いてたけど 64MHz / 8 になってる
module sdcard_spiport
{
	proc_name spi_read, spi_write;
	reg spi_clock = 0, r_wait = 0;
	reg serial_count[4], divide_count[2];
	reg writedata[16], readdata[16];

	if(select && rd == 1'b0){
		spi_read();
	}else if(select && wr == 1'b0){
		spi_write();
	}

	spi_clk = spi_clock;
	spi_di = writedata[15];
	q = readdata;
	cpu_wait = r_wait;

	proc spi_read{
		state_name read_init, read_l, read_h, read_end;
		state read_init{
			writedata := 16'hffff;
			divide_count := 0;
			spi_clock := 0;
			if(bytemask == 2'b00){
				serial_count := 15;
				goto read_l;
			}else if(bytemask == 2'b11){
				r_wait := 1;
				goto read_end;
			}else{
				serial_count := 7;
				goto read_l;
			}
		}
		state read_l{
			divide_count := divide_count + 1;
			if(divide_count == 2'b11){
				readdata := {readdata[14:0], spi_do};
				spi_clock := 1;
				goto read_h;
			}
		}
		state read_h{
			divide_count := divide_count + 1;
			if(divide_count == 2'b11){
				spi_clock := 0;
				if(serial_count == 0){
					r_wait := 1;
					goto read_end;
				}else{
					serial_count := serial_count - 1;
					goto read_l;
				}
			}
		}
		state read_end{
			if(rd == 1'b1){
				r_wait := 0;
				finish();
				goto read_init;
			}
		}
	}

	proc spi_write{
		state_name write_init, write_wait_0, write_wait_1, write_l, write_h, write_end;
		state write_init{
			divide_count := 0;
			spi_clock := 0;
			if(bytemask == 2'b00){
				serial_count := 15;
				goto write_wait_0;
			}else if(bytemask == 2'b11){
				r_wait := 1;
				goto write_end;
			}else{
				serial_count := 7;
				goto write_wait_0;
			}
		}
		//databus 確定のため2clock待つ
		state write_wait_0{
			goto write_wait_1;
		}
		state write_wait_1{
			if(bytemask == 2'b00){
				writedata := d;
			}else{
				writedata := {d[7:0], 8'h00};
			}
			goto write_l;
		}
		state write_l{
			divide_count := divide_count + 1;
			if(divide_count == 2'b11){
				spi_clock := 1;
				goto write_h;
			}
		}
		state write_h{
			divide_count := divide_count + 1;
			if(divide_count == 2'b11){
				writedata := {writedata[14:0], 1'b1};
				spi_clock := 0;
				if(serial_count == 0){
					r_wait := 1;
					goto write_end;
				}else{
					serial_count := serial_count - 1;
					goto write_l;
				}
			}
		}
		state write_end{
			if(wr == 1){
				r_wait := 0;
				finish();
				goto write_init;
			}
		}
	}
}

C シフト演算すると0が入るんですよ

void segcopy(int index, const void *src, uint16_t length);

static void font_trans(uint16_t destseg)
{
#define FONT1BPPSIZE (4 * 0x40)
	static const uint16_t font1bpp [] = {
		#include "font1bpp.inc"
	};
	const uint16_t *f1 = font1bpp;
	uint16_t font4bpp[FONT1BPPSIZE * 4];
	uint16_t *f4 = font4bpp;
	int length = FONT1BPPSIZE;

	while(length != 0){
		uint16_t pt1 = *f1++;
		uint16_t pt4 = 0; //初期化しなくていいけど warning がでる
		int i;
		for(i = 0; i < 16; i++){
			pt4 <<= 4;
			if(pt1 & 0x8000){
				pt4 |= 2;
			}
			pt1 <<= 1;

			if((i & 3) == 3){
				*f4++ = pt4;
			}
		}
		length--;
	}
	segcopy(destseg/*ax*/, font4bpp/*bx*/, FONT1BPPSIZE * 4 /*cx*/);
#undef FONT1BPPSIZE
}

C sprite renderer の一部

		state pattern_load{
			if(vram_ready == 1'b0){
				vram_read := 1;
				if(x_axis[0] == 1'b0 && x_flip == 1'b0){
					lb0_d := vram_d[31:28];
					lb1_d := vram_d[27:24];
					pattern := {vram_d[23:0], 4'h0};
				}else if(x_axis[0] == 1'b0 && x_flip == 1'b1){
					lb0_d := vram_d[3:0];
					lb1_d := vram_d[7:4];
					pattern := {vram_d[11:8], vram_d[15:12], vram_d[19:16], vram_d[23:20], vram_d[27:24], vram_d[31:28], 4'h0};
				}else if(x_axis[0] == 1'b1 && x_flip == 1'b0){
					lb0_d := pattern[27:24];
					lb1_d := vram_d[31:28];

					pattern := vram_d[27:0];
				}if(x_axis[0] == 1'b1 && x_flip == 1'b1){
					lb0_d := pattern[27:24];
					lb1_d := vram_d[3:0];

					pattern := {vram_d[7:4], vram_d[11:8], vram_d[15:12], vram_d[19:16], vram_d[23:20], vram_d[27:24], vram_d[31:28]};
				}
/* この不定値設定が悪かったみたい
				else{
					pattern := 28'hx;
				}*/
				goto render_next;
			}
		}

C++ SystemC で RAM, ROM もどき

#include <systemc.h>

template <typename datarange, typename addressrange>
class SimROM : public sc_module
{
protected:
	datarange *const m_data;
	const int m_size;
	sc_in<bool> w_reset, w_clock;
	sc_in<addressrange> w_a;
	sc_out<datarange> w_q;

	void qout(void)
	{
		uint32_t a = w_a.read();
		assert(a < m_size);
		w_q.write(m_data[a]);
	}
	virtual void thread()
	{
		while(true){
			wait(w_clock.posedge_event());
			qout();
		}
	}
public:
	SC_HAS_PROCESS(SimROM);
	void Assign(sc_signal<bool> reset, sc_signal<bool> clock, sc_signal<addressrange> a, sc_signal<datarange> q)
	{
		w_reset(reset);
		w_clock(clock);
		w_a(a);
		w_q(q);
	}
	SimROM(sc_module_name n, int size)
		: sc_module(n), m_data(new datarange [size]), m_size(size),
		w_reset("p_reset"), w_clock("m_clock"),
		w_a("a"), w_q("q")
	{
		SC_THREAD(thread);
	}
	virtual ~SimROM()
	{
		delete [] m_data;
	}
};

template <typename D, typename A>
class SimRAM : public SimROM <D, A>
{
protected:
	sc_in<D> w_d;
	sc_in<bool> w_we;

	void thread(void)
	{
		while(true){
			wait(SimROM<D, A>::w_clock.posedge_event());
			SimROM<D, A>::qout();
			if(w_we.read() == 1){
				SimROM<D, A>::m_data[SimROM<D, A>::w_a.read()] = w_d.read();
			}
		}
	}
public:
	SC_HAS_PROCESS(SimRAM);
	SimRAM(sc_module_name n, int size)
	 : SimROM<D, A>::SimROM(n, size), w_d("d"), w_we("we")
	{
	}
};

C++ verilog named block

`default_nettype none

module hoge;
	reg clock;
	initial begin
		clock = 1'b0;

		forever begin
			#4 clock <= ~clock;
		end
	end

	always @(posedge clock) begin: increment //label を付けると
		reg [3:0] count; //局所配線宣言が可能
		//always の中で wire 宣言はエラーになる
		//wire [2:0] dd = {clock, clock, clock}; 

		//parameter は宣言可能
		parameter SEQ_INIT = 4'd0;
		parameter SEQ_II = 4'd1;
		if(count === 4'hx) begin
			count <= 4'h0;
		end else begin
			count <= count + 4'd1;
		end
	end

	//これはスコープを抜けるのでエラーになる。
	//wire [3:0] decrement = ~count;
	//label.regname とすると使えるようだ
	wire [3:0] decrement = ~increment.count;
	wire [3:0] ss = increment.SEQ_II;

	begin: nanmo //単なる begin - end では局所 wire 宣言が利用可能
		wire [7:0] dd = {decrement, ss};
		//parameter はどちらでも使えるようだ。
		parameter XOR = 8'hee;
	end

	wire [7:0] rr = nanmo.dd ^ nanmo.XOR;
endmodule

JavaFX always の中の reg 宣言

`default_nettype none

module hoge;
	reg clock;
	initial begin
		clock = 1'b0;

		forever begin
			#4 clock <= ~clock;
		end
	end

	always @(posedge clock) begin: increment //label を付けると
		reg [3:0] count; //局所配線宣言が可能
		if(count === 4'hx) begin
			count <= 4'h0;
		end else begin
			count <= count + 4'd1;
		end
	end

	//これはスコープを抜けるのでエラーになる。
	//wire [3:0] decrement = ~count;
	//label.regname とすると使えるようだ
	wire [3:0] decrement = ~increment.count;
endmodule
Total Pages: 1 / 212

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

タグ

最近投稿されたコード