Cに投稿されたコード一覧

C airfortress.sp

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <tf2items>
#include <steamtools>

#define PLUGIN_VERSION "1.0.0"

new g_flg = 0;

public Plugin:myinfo = {
    name = "Air Fortress",
    author = "svaugrasn",
    description = "",
    version = PLUGIN_VERSION,
};

public OnPluginStart() {
	HookEvent("player_death", OnPlayerDeath);
	HookEvent("teamplay_round_start", Event_teamplay_round_start);
	HookEvent("arena_win_panel", OnRoundEnd);

	SetConVarInt(FindConVar("mp_chattime"), 6, true);
	SetConVarInt(FindConVar("mp_bonusroundtime"), 7, true);
	SetConVarInt(FindConVar("mp_respawnwavetime"), 7, true);
	SetConVarInt(FindConVar("tf_arena_preround_time"), 7, true);

	SetConVarInt(FindConVar("tf_arena_use_queue"), 0, true);
	SetConVarInt(FindConVar("tf_arena_first_blood"), 0, true);
	SetConVarInt(FindConVar("mp_forceautoteam"), 0, true);
	SetConVarInt(FindConVar("mp_stalemate_enable"), 0, true);
	SetConVarInt(FindConVar("tf_weapon_criticals"), 0, true);
	SetConVarInt(FindConVar("tf_damage_disablespread"), 0, true);
	SetConVarInt(FindConVar("tf_use_fixed_weaponspreads"), 0, true);

	CreateTimer(5.0, ChangeDesc);

}

public OnMapStart()
{
	AddFileToDownloadsTable("sound/misc/aw/explode.mp3");
	AddFileToDownloadsTable("sound/misc/aw/warn.mp3");

	PrecacheSound("misc/aw/explode.mp3");
	PrecacheSound("misc/aw/warn.mp3");

}

public Action:ChangeDesc(Handle:timer)
{
	decl String:description[128];
	description = "Air Fortress";
	Steam_SetGameDescription(description);
}

public Action:Event_teamplay_round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
	PrintToChatAll("Air Fortress v%s", PLUGIN_VERSION);

	for(new i = 1; i <= MaxClients; i++)
	{
		if(IsValidEdict(i) && IsClientConnected(i) && IsPlayerAlive(i))
		{
			if (TF2_GetPlayerClass(i) != TFClass_Soldier) TF2_SetPlayerClass(i, TFClass_Soldier);
			TF2_RemoveAllWeapons(i);
		}
	}

	g_flg = 0;

	CreateTimer(7.0, OnGameStart);

}

public Action:OnGameStart(Handle:timer, any:Ent)
{
	for(new i = 1; i <= MaxClients; i++)
	{

		if(IsValidEdict(i) && IsClientConnected(i) && IsPlayerAlive(i))
		{
			TF2_RemoveAllWeapons(i);
			if (TF2_GetPlayerClass(i) != TFClass_Soldier) TF2_SetPlayerClass(i, TFClass_Soldier);
			TF2_RemoveAllWeapons(i);

			SetEntProp(i, Prop_Data, "m_iMaxHealth", 600);
			SetEntityHealth(i, 600);

			new Handle:h_weapon_air = TF2Items_CreateItem(OVERRIDE_ALL);
			if (h_weapon_air != INVALID_HANDLE)
			{
				TF2Items_SetClassname(h_weapon_air, "tf_weapon_rocketlauncher");
				TF2Items_SetItemIndex(h_weapon_air, 513);

				new String:weaponAttribs[] = "138 ; 2.3 ; 4 ; 6 ; 6 ; 0.5 ; 26 ; 300 ; 58 ; 0.5 ; 96 ; 0.4 ; 99 ; 2.0 ; 103 ; 3.5 ; 150 ; 1";
				new String:weaponAttribsArray[32][32];
				new attribCount = ExplodeString(weaponAttribs, " ; ", weaponAttribsArray, 32, 32);
				if (attribCount > 0) {
					TF2Items_SetNumAttributes(h_weapon_air, attribCount/2);
					new j2 = 0;
					for (new j = 0; j < attribCount; j+=2) {
						TF2Items_SetAttribute(h_weapon_air, j2, StringToInt(weaponAttribsArray[j]), StringToFloat(weaponAttribsArray[j+1]));
						j2++;
					}
				} else {
					TF2Items_SetNumAttributes(h_weapon_air, 0);
				}

				TF2Items_SetLevel(h_weapon_air, 0);
				TF2Items_SetQuality(h_weapon_air, 0);
				new weapon_air = TF2Items_GiveNamedItem(i, h_weapon_air);
				EquipPlayerWeapon(i, weapon_air);
				CloseHandle(h_weapon_air);
			}

			new Handle:h_weapon_air2 = TF2Items_CreateItem(OVERRIDE_ALL);
			if (h_weapon_air2 != INVALID_HANDLE)
			{
				TF2Items_SetClassname(h_weapon_air2, "tf_weapon_raygun");
				TF2Items_SetItemIndex(h_weapon_air2, 442);

				new String:weaponAttribs2[] = "138 ; 0.2 ; 4 ; 40 ; 6 ; 0.02 ; 96 ; 0.00 ; 318 ; 15.00 ; 103 ; 10.0";
				new String:weaponAttribsArray2[32][32];
				new attribCount2 = ExplodeString(weaponAttribs2, " ; ", weaponAttribsArray2, 32, 32);
				if (attribCount2 > 0) {
					TF2Items_SetNumAttributes(h_weapon_air2, attribCount2/2);
					new j2 = 0;
					for (new j = 0; j < attribCount2; j+=2) {
						TF2Items_SetAttribute(h_weapon_air2, j2, StringToInt(weaponAttribsArray2[j]), StringToFloat(weaponAttribsArray2[j+1]));
						j2++;
					}
				} else {
					TF2Items_SetNumAttributes(h_weapon_air2, 0);
				}

				TF2Items_SetLevel(h_weapon_air2, 0);
				TF2Items_SetQuality(h_weapon_air2, 0);
				new weapon_air2 = TF2Items_GiveNamedItem(i, h_weapon_air2);
				EquipPlayerWeapon(i, weapon_air2);
				CloseHandle(h_weapon_air2);
			}

			SetEntPropFloat(i, Prop_Send, "m_flModelScale", 0.6);
			SetEntPropFloat(i, Prop_Send, "m_flStepSize", 9.0);

		}
	}
	g_flg = 1;

}

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
	decl Float:vecAngles[3], Float:vecVelocity[3];
	GetClientEyeAngles(client, vecAngles);
	GetEntPropVector(client, Prop_Data, "m_vecVelocity", vecVelocity);

	if (buttons & IN_JUMP)
	{
		vecVelocity[2] = 220.0;
		TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);
	}

	new clientflags = GetEntityFlags(client);

	if(!(clientflags & FL_ONGROUND))
	{

		if (buttons & IN_FORWARD)
		{
			vecAngles[0] = DegToRad(vecAngles[0]);
			vecAngles[1] = DegToRad(vecAngles[1]);
			vecVelocity[0] = 380 * Cosine(vecAngles[0]) * Cosine(vecAngles[1]);
			vecVelocity[1] = 380 * Cosine(vecAngles[0]) * Sine(vecAngles[1]);
			vecVelocity[2] -= 0.01;

			TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);
		}
		if (buttons & IN_BACK)
		{
			vecAngles[0] = DegToRad(vecAngles[0]);
			vecAngles[1] = DegToRad(vecAngles[1]);
			vecVelocity[0] -= 0.1 * Cosine(vecAngles[0]) * Cosine(vecAngles[1]);
			vecVelocity[1] -= 0.1 * Cosine(vecAngles[0]) * Sine(vecAngles[1]);
			vecVelocity[2] -= 0.01;
			TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);
		}

	}

	if(clientflags & FL_ONGROUND)
	{
		if(g_flg == 1){
			if(IsPlayerAlive(client)){
				SetHudTextParams(-1.0, 0.7, 5.0, 255, 0, 0, 20);
				ShowHudText(client, -1, ">> Low altitude warning <<");
				AttachParticle(client, "fluidSmokeExpl_ring_mvm");
				DoDamage(client, client, 25);

				vecVelocity[2] = 500.0;
				TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vecVelocity);
				EmitSoundToAll("misc/aw/warn.mp3", client);
			}
		}
	}

	return Plugin_Continue;

}

public OnGameFrame()
{
	for(new i = 1; i <= MaxClients; i++)
	{
		if(IsValidEdict(i) && IsClientConnected(i) && IsPlayerAlive(i))
		{
			decl Float:vecVelocity[3];
			GetEntPropVector(i, Prop_Data, "m_vecVelocity", vecVelocity);
			if (-150.0 < vecVelocity[0] < 150.0 && -150.0 < vecVelocity[1] < 150.0)
			{
				if ((-180.0 < vecVelocity[0] < 180.0) || (-180.0 < vecVelocity[0] < 180.0)){
					vecVelocity[0] += vecVelocity[0] * 0.07;
					vecVelocity[1] += vecVelocity[1] * 0.07;
					vecVelocity[2] -= 0.1;
					TeleportEntity(i, NULL_VECTOR, NULL_VECTOR, vecVelocity);
				}
			}
		}
	}
}

stock DoDamage(client, target, amount)
{

	new pointHurt = CreateEntityByName("point_hurt");
	if (pointHurt)
	{
		DispatchKeyValue(target, "targetname", "explodeme");
		DispatchKeyValue(pointHurt, "DamageTarget", "explodeme");
		new String:dmg[15];
		Format(dmg, 15, "%i", amount);
		DispatchKeyValue(pointHurt, "Damage", dmg);
		DispatchKeyValue(pointHurt, "DamageType", "0");

		DispatchSpawn(pointHurt);
		AcceptEntityInput(pointHurt, "Hurt", client);
		DispatchKeyValue(pointHurt, "classname", "point_hurt");
		DispatchKeyValue(target, "targetname", "");
		RemoveEdict(pointHurt);
	}
}

public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	g_flg = 0;
}

public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{

	new client = GetClientOfUserId(GetEventInt(event, "userid"));

	AttachParticle(client, "fluidSmokeExpl_ring_mvm");
	EmitSoundToAll("misc/aw/explode.mp3", client);

}

stock bool:AttachParticle(Ent, String:particleType[], bool:cache=false)
{
	new particle = CreateEntityByName("info_particle_system");
	if (!IsValidEdict(particle)) return false;
	new String:tName[128];
	new Float:f_pos[3];
	if (cache) f_pos[2] -= 3000;
	else
	{
		GetEntPropVector(Ent, Prop_Send, "m_vecOrigin", f_pos);
		f_pos[2] += 60;
	}
	TeleportEntity(particle, f_pos, NULL_VECTOR, NULL_VECTOR);
	Format(tName, sizeof(tName), "target%i", Ent);
	DispatchKeyValue(Ent, "targetname", tName);
	DispatchKeyValue(particle, "effect_name", particleType);
	DispatchSpawn(particle);
	SetVariantString(tName);
	AcceptEntityInput(particle, "SetParent", particle, particle, 0);
	ActivateEntity(particle);
	AcceptEntityInput(particle, "start");
	CreateTimer(10.0, DeleteParticle, particle);
	return true;
}

public Action:DeleteParticle(Handle:timer, any:Ent)
{
	if (!IsValidEntity(Ent)) return;
	new String:cls[25];
	GetEdictClassname(Ent, cls, sizeof(cls));
	if (StrEqual(cls, "info_particle_system", false)) AcceptEntityInput(Ent, "Kill");
	return;
}

C kissme.sp

#pragma semicolon 1

#include <sourcemod>
#include <tf2>
#include <tf2_stocks>

#define PLUGIN_VERSION "1.0.0"

public Plugin:myinfo =
{
	name = "Kiss me.",
	author = "Kiss me.",
	description = "Kiss me.",
	version = PLUGIN_VERSION,
	url = ""
}

public OnPluginStart()
{
	AddNormalSoundHook(HookSound);
}

public OnMapStart()
{
	PrecacheSound("vo/heavy_generic01.wav");
}

public Action:HookSound(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &ent, &channel, &Float:volume, &level, &pitch, &flags)
{

	if (ent < 1 || ent > MaxClients || channel < 1)
		return Plugin_Continue;

	if (TF2_GetPlayerClass(ent) == TFClass_Heavy)
	{
		if(StrContains(sample, "vo/heavy_", false) != -1){
			Format(sample, PLATFORM_MAX_PATH, "vo/heavy_generic01.wav");
		}

		return Plugin_Changed;
	}

	return Plugin_Continue;

}

C スパム用コンフィグ

alias saysound1 "say sunzen; bind Q saysound2"
alias saysound2 "say sikomi; bind Q saysound1"
bind Q saysound1

alias saysound3 "say nemuttero; bind Q saysound4"
alias saysound42 "say hosii; bind Q saysound3"
bind KP_SLASH saysound3

bind "KP_MULTIPLY" "say hankou2"
bind "KP_MINUS" "say nigenja"
bind "KP_PLUS" "say erasouna"
bind "KP_ENTER" "say razor"

C 一回生に送る配列とポインタの違い

#include "stdio.h"

main(){
  //配列はポインタなんだよというデモ
  //配列でメモリを異常に弄って4バイトのintの中身をcharを使って1バイトずつ書き換えます。
  unsigned int i[2]={0}; //符号なしint
  unsigned char go_i[1];

  //i[0]
  go_i[1] = 15; //i[0]
  go_i[2] = 14; //i[0.25]←実際にはできない表現
  go_i[3] = 13; //i[0.5]
  go_i[4] = 12; //i[0.75]

  //i[1]
  go_i[5] = 11; //i[1]
  go_i[6] = 10; //i[1.25]
  go_i[7] = 9;  //i[1.50]
  go_i[8] = 8;  //i[1.75]
  printf("%x %x\n",i[0], i[1]); //16進数で表示

  i[0] = 0;i[1] = 0;

  //同じ事をポインタでやる
  ////////////////////////////
  char *i_head = (char *)&i; //そのままでもiのアドレスをcharのポインタに入れられるが
  //こうすると分かっててやってることが明示できるのでwarningが出なくなる。

  //i[0]
  *(i_head) = 15;
  *(i_head+1) = 14;
  *(i_head+2) = 13;
  *(i_head+3) = 12;

  //i[1]
  *(i_head+4) = 11;
  *(i_head+5) = 10;
  *(i_head+6) = 9;
  *(i_head+7) = 8;
  printf("%x %x\n",i[0], i[1]);

  i[0] = 0;i[1] = 0;

  //もちろんint型のポインタを使えば普通の配列のように使える
  /////////////////////////////////////////////////
  int *i_p = (unsigned int *)&i;

  *i_p = 0xc0d0e0f; //16進数の代入 i[0] = 202182159 と等価
  *(i_p+1) = 0x8090a0b; //i[1] = 134810123
  printf("%x %x\n",i[0], i[1]);
}

C 配列初心者向けメモリ破壊

#include "stdio.h"

main(){
  int i=5; //メモリ上では配列rの次にこのiが入る
  char r[] = "Ritsumeikan University";
  //r[22]='\n',r[23]=5

  for(i=0;i<22;){
    printf("%c",r[i]);
    r[23] = i+1;
  }
  printf("\n");
}

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 Segmentation fault of hikko624 「help me」

#include <stdio.h>
#include <stdlib.h>
#define BUSI 256
#define N 2

int main(void)
{
  char buf[BUSI];
  int u[N];
  int v[N];
  int i,sum;
  for(i=0 ; i < N ; i++) {
    printf("input u[%d]",i);
    fgets(buf,BUSI,stdin);
    u[i] = atoi(buf);
    }

  for(i=0 ; i < N ; i++) {
    printf("input v[%d]",i);
    fgets(buf,BUSI,stdin);
    v[i] = atoi(buf);
  }
  printf("u=[");
  for(i=0 ; i < N ; i++) {
    printf("%2d",u[i]);
  }
  printf(" ], ");
  printf("v=[");
  for(i=0 ; i < N ; i++) {
    printf("%2d",v[i]);
  }
  printf(" ]\n");

  sum = 0;
  sum = innerProduct(u[N],v[N]);

  printf("inner product is %d",sum);
   if(sum>0){
	    printf("The angle of the vectors is less than 90 degree.");
    }else if(sum==0){
        printf("The angle of the vectors is  90 degree.");
    }else{
        printf("The angle of the vectors is greater than 90 degree.");
    }
    printf("\n");
    return 0;
}

int innerProduct(int u[],int v[])
{
  int i,total;
  total = 0;
  for(i=0 ; i < N ; i++) {
    total += u[i]*v[i];
  }
  return total;
}

C M6809 INDEXED Addressing Mode

/*-----------------------------------------------------------------------------------
	[AmIndexed]
		Implements the INDEXED addressing mode.
		JMP INDEXED completes in this stage.
-----------------------------------------------------------------------------------*/
module AmIndexed(
	input			i_Clk, i_nReset, i_Proceed,

`ifdef MULTIPLEXED_CORE
	input	[ 1:0]	i_RegSel,			// up to 4 reg sets
`endif

	input			i_AmIdx,			// set during main state "IDECODE"
	input	[ 7:0]	i_PB,
	input			i_LEA,
	input			i_JMP,

	output			o_EOAM,
	output			o_EOI,
	output			o_LoadXH, o_LoadXL, o_LoadYH, o_LoadYL,
	output			o_LoadUH, o_LoadUL, o_LoadSH, o_LoadSL,
	output			o_LoadPC, o_IncPC,
	output			o_AluInC_1, o_LoadAluC7, o_HoldDIN, o_LoadPB,

	output			o_VMA,

	output			o_AluInA_XH, o_AluInA_XL, o_AluInA_YH, o_AluInA_YL,
	output			o_AluInA_UH, o_AluInA_UL, o_AluInA_SH, o_AluInA_SL,
	output			o_AluInA_PCH, o_AluInA_PCL,
	output			o_AluInB_A, o_AluInB_B, o_AluInB_DIN, o_AluInC_AluC7,
	output			o_AluOp_ADC, o_AluOp_SBC,
	output			o_ReadMemPC,

	output			o_Adder16InA_X, o_Adder16InA_Y, o_Adder16InA_U, o_Adder16InA_S,
	output			o_Adder16InA_PC, o_Adder16InA_AOB,
	output			o_Adder16InB_D, o_Adder16InB_DIB16, o_Adder16InB_DIB5, o_Adder16InB_ALU,
	output			o_DataBus_ALU,
	output			o_LoadAddrOutBuf, o_LoadDataInBufH
);

	parameter		NC = `NUM_CORE-1;
	integer			i = 0;
	reg		[31:0]	r_ST[0:NC];

	/*-----------------------------------------------------------------------------------
		[Post Byte Decoder]
		------------------------+--------------------------
			     DIRECT         |        INDIRECT
		 PostByte   MN     ~ #  |  PostByte    MN      ~ #
		------------------------+--------------------------
		 0RRnnnnn   n,R    1 0  |  --
		 1RR00000   ,R+    2 0  |  --
		 1RR00001   ,R++   3 0  |  1RR10001   [,R++]   6 0
		 1RR00010   ,-R    2 0  |  --
		 1RR00011   ,--R   3 0  |  1RR10011   [,--R]   6 0
		 1RR00100   ,R     0 0  |  1RR10100   [,R]     3 0
		 1RR00101   B,R    1 0  |  1RR10101   [B,R]    4 0
		 1RR00110   A,R    1 0  |  1RR10110   [A,R]    4 0
		 1RR01000   n,R    1 1  |  1RR11000   [n,R]    4 1
		 1RR01001   n,R    4 2  |  1RR11001   [n,R]    7 2
		 1RR01011   D,R    4 0  |  1RR11011   [D,R]    7 0
		 1xx01100   n,PCR  1 1  |  1xx11100   [n,PCR]  4 1
		 1xx01101   n,PCR  5 2  |  1xx11101   [n,PCR]  8 2
		 --                     |  10011111   [n]      5 2
		------------------------+--------------------------
		 X:RR=00, Y:RR=01, U:RR=10, S:RR=11
	-----------------------------------------------------------------------------------*/
	// 2-to-4 decoder
	function	[3:0]	dec2to4;
		input	[1:0]	in;
		case (in)
			2'h0:	dec2to4 = 4'b0001;
			2'h1:	dec2to4 = 4'b0010;
			2'h2:	dec2to4 = 4'b0100;
			2'h3:	dec2to4 = 4'b1000;
		endcase
	endfunction

	// 3-to-8 decoder
	function	[7:0]	dec3to8;
		input	[2:0]	in;
		case (in)
			3'h0:	dec3to8 = 8'b00000001;
			3'h1:	dec3to8 = 8'b00000010;
			3'h2:	dec3to8 = 8'b00000100;
			3'h3:	dec3to8 = 8'b00001000;
			3'h4:	dec3to8 = 8'b00010000;
			3'h5:	dec3to8 = 8'b00100000;
			3'h6:	dec3to8 = 8'b01000000;
			3'h7:	dec3to8 = 8'b10000000;
		endcase
	endfunction

	wire	[ 7:0]	w_im			=	dec3to8(i_PB[4:2]);
	wire	[ 3:0]	w_il			=	dec2to4(i_PB[1:0]);
	wire	[ 3:0]	w_rr			=	dec2to4(i_PB[6:5]);

	wire			w_dir_n5_r		=	~i_PB[7];						// n5,R      (+0b1c)

	wire			w_dir_r_i		=	w_im[0] & w_il[0];				// ,R+       (+0b2c)
	wire			w_dir_r_i2		=	w_im[0] & w_il[1];				// ,R++      (+0b3c)
	wire			w_dir_r_d		=	w_im[0] & w_il[2];				// ,-R       (+0b2c)
	wire			w_dir_r_d2		=	w_im[0] & w_il[3];				// ,--R      (+0b3c)
	wire			w_ind_r_i2		=	w_im[4] & w_il[1];				// [,R++]    (+0b6c)
	wire			w_ind_r_d2		=	w_im[4] & w_il[3];				// [,--R]    (+0b6c)

	wire			w_dir_0_r		=	w_im[1] & w_il[0];				//  ,R       (+0b0c)
	wire			w_dir_b_r		=	w_im[1] & w_il[1];				// B,R       (+0b1c)
	wire			w_dir_a_r		=	w_im[1] & w_il[2];				// A,R       (+0b1c)
	wire			w_ind_0_r		=	w_im[5] & w_il[0];				// [ ,R]     (+0b3c)
	wire			w_ind_b_r		=	w_im[5] & w_il[1];				// [B,R]     (+0b4c)
	wire			w_ind_a_r		=	w_im[5] & w_il[2];				// [A,R]     (+0b4c)

	wire			w_dir_n8_r		=	w_im[2] & w_il[0];				// n8,R      (+1b1c)
	wire			w_dir_n16_r		=	w_im[2] & w_il[1];				// n16,R     (+2b4c)
	wire			w_dir_d_r		=	w_im[2] & w_il[3];				// D,R       (+0b4c)
	wire			w_ind_n8_r		=	w_im[6] & w_il[0];				// [n8, R]   (+1b4c)
	wire			w_ind_n16_r		=	w_im[6] & w_il[1];				// [n16,R]   (+2b7c)
	wire			w_ind_d_r		=	w_im[6] & w_il[3];				// [D,R]     (+0b7c)

	wire			w_dir_n8_pcr	=	w_im[3] & w_il[0];				// n8, PCR   (+1b1c)
	wire			w_dir_n16_pcr	=	w_im[3] & w_il[1];				// n16,PCR   (+2b5c)
	wire			w_ind_n8_pcr	=	w_im[7] & w_il[0];				// [n8, PCR] (+1b4c)
	wire			w_ind_n16_pcr	=	w_im[7] & w_il[1];				// [n16,PCR] (+2b8c)
	wire			w_ind_n16		=	w_im[7] & w_il[3] & w_rr[0];	// [n16]     (+2b5c)

	wire			w_idx_x			=	w_rr[0];
	wire			w_idx_y			=	w_rr[1];
	wire			w_idx_u			=	w_rr[2];
	wire			w_idx_s			=	w_rr[3];

	/*-----------------------------------------------------------------------------------
		internal signals
	-----------------------------------------------------------------------------------*/
	wire			w_start			=	i_AmIdx;
	wire			w_opdec			=	r_ST[i_RegSel][1];

	// ,R+ / ,R++ / ,-R / ,--R / [,R++] / [,--R]
	wire			w_r_i			=	w_dir_r_i|w_dir_r_i2|w_ind_r_i2;
	wire			w_r_d			=	w_dir_r_d|w_dir_r_d2|w_ind_r_d2;
	wire			w_dir_r_i_d		=	w_dir_r_i|w_dir_r_i2|w_dir_r_d|w_dir_r_d2;
	wire			w_r_i_d			=	w_r_i|w_r_d;
	wire			w_r_i_d_j		=	r_ST[i_RegSel][3] & (w_dir_r_i|w_dir_r_d);
	wire			w_r_i_d_inc_aob	=	r_ST[i_RegSel][10];

	// ,R / B,R / A,R / [,R] / [B,R] / [A,R]
	wire			w_dir_ind_0_r	=	w_dir_0_r|w_ind_0_r;
	wire			w_dir_r_br_ar	=	w_dir_0_r|w_dir_b_r|w_dir_a_r;
	wire			w_ind_r_br_ar	=	w_ind_0_r|w_ind_b_r|w_ind_a_r;
	wire			w_br_ar			=	w_dir_b_r|w_dir_a_r|w_ind_b_r|w_ind_a_r;
	wire			w_r_br_ar		=	w_dir_r_br_ar|w_ind_r_br_ar;
	wire			w_ind_r_ar_br_j	=	r_ST[i_RegSel][17] & w_ind_r_br_ar;

	// n8,R / n16,R / D,R / [n8,R] / [n16,R] / [D,R]
	wire			w_dir_n16r_dr	=	w_dir_n16_r|w_dir_d_r;
	wire			w_ind_n16r_dr	=	w_ind_n16_r|w_ind_d_r;
	wire			w_n8r			=	w_dir_n8_r|w_ind_n8_r;
	wire			w_n16r_dr		=	w_dir_n16r_dr|w_ind_n16r_dr;
	wire			w_ind_n8r_j		=	r_ST[i_RegSel][20] & w_ind_n8_r;
	wire			w_ind_n16r_dr_j	=	r_ST[i_RegSel][29] & w_ind_n16r_dr;

	// n8,PCR / n16,PCR / [n8,PCR] / [n16,PCR] / [n16]
	wire			w_n8_pcr		=	w_dir_n8_pcr|w_ind_n8_pcr;
	wire			w_n16_pcr		=	w_dir_n16_pcr|w_ind_n16_pcr;
	wire			w_n16_j1		=	r_ST[i_RegSel][23] & w_ind_n16;
	wire			w_ind_n8_pcr_j	=	r_ST[i_RegSel][20] & w_ind_n8_pcr;
	wire			w_ind_n16_pcr_j	=	r_ST[i_RegSel][29] & w_ind_n16_pcr;
	wire			w_ind_n16_j2	=	r_ST[i_RegSel][29] & w_ind_n16;

	wire			w_ind_j			=	w_ind_r_ar_br_j		|
										w_ind_n8r_j			|
										w_ind_n16r_dr_j		|
										w_ind_n8_pcr_j		|
										w_ind_n16_pcr_j		|
										w_ind_n16_j2;

	wire			w_out_r			=	r_ST[i_RegSel][2] & w_r_i | r_ST[i_RegSel][6] & w_r_d	|
										r_ST[i_RegSel][17]										|
										r_ST[i_RegSel][20] & ~w_n8_pcr							|
										r_ST[i_RegSel][29] & ~(w_n16_pcr|w_ind_n16);

	wire			w_incdec_rl		=	r_ST[i_RegSel][2] | r_ST[i_RegSel][4];
	wire			w_incdec_rh		=	r_ST[i_RegSel][3] | r_ST[i_RegSel][5];

	wire			w_inc_xl		=	w_incdec_rl & w_r_i & w_idx_x;
	wire			w_inc_xh		=	w_incdec_rh & w_r_i & w_idx_x;
	wire			w_inc_yl		=	w_incdec_rl & w_r_i & w_idx_y;
	wire			w_inc_yh		=	w_incdec_rh & w_r_i & w_idx_y;
	wire			w_inc_ul		=	w_incdec_rl & w_r_i & w_idx_u;
	wire			w_inc_uh		=	w_incdec_rh & w_r_i & w_idx_u;
	wire			w_inc_sl		=	w_incdec_rl & w_r_i & w_idx_s;
	wire			w_inc_sh		=	w_incdec_rh & w_r_i & w_idx_s;

	wire			w_dec_xl		=	w_incdec_rl & w_r_d & w_idx_x;
	wire			w_dec_xh		=	w_incdec_rh & w_r_d & w_idx_x;
	wire			w_dec_yl		=	w_incdec_rl & w_r_d & w_idx_y;
	wire			w_dec_yh		=	w_incdec_rh & w_r_d & w_idx_y;
	wire			w_dec_ul		=	w_incdec_rl & w_r_d & w_idx_u;
	wire			w_dec_uh		=	w_incdec_rh & w_r_d & w_idx_u;
	wire			w_dec_sl		=	w_incdec_rl & w_r_d & w_idx_s;
	wire			w_dec_sh		=	w_incdec_rh & w_r_d & w_idx_s;

	wire			w_inc_aob		=	w_r_i_d_inc_aob;

	/*-----------------------------------------------------------------------------------
		[State Machine]
			[    0]: fetch PB
			[    1]: decode PB, fetch next byte, branch state
			[ 2- 8]: ,R+ / ,R++ / ,-R / ,--R
			[ 9-14]: [,R++] / [,--R] / [,R] / [B,R] / [A,R] / [n8,R] / [n16,R] / [D,R] / [n8,PCR] / [n16,PCR] / [n16]
			[15-17]: ,R / B,R / A,R
			[18-20]: n8,R / n8,PCR / n5,R
			[21-29]: n16,R / D,R / n16,PCR
	-----------------------------------------------------------------------------------*/
	wire			w_n5r_n8r_n8pcr	= w_dir_n5_r|w_n8r|w_n8_pcr;
	wire			w_n16r_dr_n16pcr= w_n16r_dr|w_n16_pcr|w_ind_n16;
	always @(posedge i_Clk or negedge i_nReset) begin
		if (!i_nReset) begin
			for (i = 0; i <= NC; i=i+1) begin
				r_ST[i] <= 0;
			end
		end
		else if (i_Proceed) begin
			if (o_EOAM)						r_ST[i_RegSel] <= 0;
			else if (w_start)				r_ST[i_RegSel][0] <= 1;
			else if (w_opdec) begin
				if (w_r_i_d)				r_ST[i_RegSel] <= r_ST[i_RegSel] << 1;
				else if (w_dir_ind_0_r)		r_ST[i_RegSel] <= 1<<17;
				else if (w_br_ar)			r_ST[i_RegSel] <= 1<<15;
				else if (w_n5r_n8r_n8pcr)	r_ST[i_RegSel] <= 1<<18;
				else if (w_n16r_dr_n16pcr)	r_ST[i_RegSel] <= 1<<21;
				else						r_ST[i_RegSel] <= 1<<31; // invalid pb
			end
			else if (w_r_i_d_j)				r_ST[i_RegSel] <= 1<<6;
			else if (w_n16_j1)				r_ST[i_RegSel] <= 1<<28;
			else if (w_ind_j)				r_ST[i_RegSel] <= 1<<9;
			else							r_ST[i_RegSel] <= r_ST[i_RegSel] << 1;
		end
	end

	/*-----------------------------------------------------------------------------------
		[output]
	-----------------------------------------------------------------------------------*/
	assign	o_EOAM				=	r_ST[i_RegSel][8] & ~(w_ind_r_i2|w_ind_r_d2)				|
									r_ST[i_RegSel][14]											|
									r_ST[i_RegSel][17] & w_dir_r_br_ar							|
									r_ST[i_RegSel][20] & (w_dir_n5_r|w_dir_n8_r|w_dir_n8_pcr)	|
									r_ST[i_RegSel][29] & (w_dir_n16r_dr|w_dir_n16_pcr)			|
									r_ST[i_RegSel][31];	// invalid pb

	assign	o_EOI				=	o_EOAM & i_JMP;

	assign	o_LoadXH			=	w_incdec_rh & w_idx_x;
	assign	o_LoadXL			=	w_incdec_rl & w_idx_x;
	assign	o_LoadYH			=	w_incdec_rh & w_idx_y;
	assign	o_LoadYL			=	w_incdec_rl & w_idx_y;
	assign	o_LoadUH			=	w_incdec_rh & w_idx_u;
	assign	o_LoadUL			=	w_incdec_rl & w_idx_u;
	assign	o_LoadSH			=	w_incdec_rh & w_idx_s;
	assign	o_LoadSL			=	w_incdec_rl & w_idx_s;

	assign	o_LoadPC			=	o_EOAM & i_JMP;

	assign	o_IncPC				=	r_ST[i_RegSel][1] & (w_n8r|w_n16r_dr|w_n8_pcr|w_n16_pcr|w_ind_n16)	|
									r_ST[i_RegSel][22];

	assign	o_LoadAluC7			=	w_incdec_rl;
	assign	o_LoadPB			=	r_ST[i_RegSel][0];

	assign	o_HoldDIN			=	r_ST[i_RegSel][18] & w_dir_n5_r	|
									r_ST[i_RegSel][25]				|
									r_ST[i_RegSel][27];

	assign	o_VMA				=	(|r_ST[i_RegSel][5:2])												|
									r_ST[i_RegSel][1] & ~(w_dir_ind_0_r|w_n16r_dr|w_n16_pcr|w_ind_n16)	|
									r_ST[i_RegSel][11]													|
									r_ST[i_RegSel][13] & i_LEA											|
									r_ST[i_RegSel][16] & w_dir_r_br_ar & i_LEA							|
									r_ST[i_RegSel][19] & (w_dir_n5_r|w_dir_n8_r|w_dir_n8_pcr) & i_LEA	|
									r_ST[i_RegSel][28] & (w_dir_n16r_dr|w_dir_n16_pcr) & i_LEA			|
									(|r_ST[i_RegSel][26:22]);

	assign	o_AluInA_XH			=	w_incdec_rh & w_idx_x;
	assign	o_AluInA_XL			=	w_incdec_rl & w_idx_x;
	assign	o_AluInA_YH			=	w_incdec_rh & w_idx_y;
	assign	o_AluInA_YL			=	w_incdec_rl & w_idx_y;
	assign	o_AluInA_UH			=	w_incdec_rh & w_idx_u;
	assign	o_AluInA_UL			=	w_incdec_rl & w_idx_u;
	assign	o_AluInA_SH			=	w_incdec_rh & w_idx_s;
	assign	o_AluInA_SL			=	w_incdec_rl & w_idx_s;
	assign	o_AluInA_PCH		=	0;
	assign	o_AluInA_PCL		=	0;
	assign	o_AluInB_A			=	r_ST[i_RegSel][17] & (w_dir_a_r|w_ind_a_r);
	assign	o_AluInB_B			=	r_ST[i_RegSel][17] & (w_dir_b_r|w_ind_b_r);

	assign	o_AluInB_DIN		=	r_ST[i_RegSel][20];

	assign	o_AluInC_1			=	w_incdec_rl & w_r_i	|
									w_inc_aob;

	assign	o_AluInC_AluC7		=	w_incdec_rh;

	assign	o_AluOp_ADC			=	(w_incdec_rl|w_incdec_rh) & w_r_i	|
									w_inc_aob							|
									r_ST[i_RegSel][17]					|
									r_ST[i_RegSel][20];

	assign	o_AluOp_SBC			=	(w_incdec_rl|w_incdec_rh) & w_r_d;

	assign	o_ReadMemPC			=	r_ST[i_RegSel][0]	|
									r_ST[i_RegSel][21];

	assign	o_Adder16InA_X		= 	w_out_r & w_idx_x;
	assign	o_Adder16InA_Y		= 	w_out_r & w_idx_y;
	assign	o_Adder16InA_U		= 	w_out_r & w_idx_u;
	assign	o_Adder16InA_S		= 	w_out_r & w_idx_s;

	assign	o_Adder16InA_PC		= 	r_ST[i_RegSel][20] & w_n8_pcr	|
									r_ST[i_RegSel][29] & w_n16_pcr;

	assign	o_Adder16InA_AOB	=	w_inc_aob;
	assign	o_Adder16InB_D		= 	r_ST[i_RegSel][29] & (w_dir_d_r|w_ind_d_r);
	assign	o_Adder16InB_DIB16	= 	r_ST[i_RegSel][14]	|
									r_ST[i_RegSel][29] & (w_dir_n16_r|w_ind_n16_r|w_n16_pcr|w_ind_n16);

	assign	o_Adder16InB_DIB5	=	r_ST[i_RegSel][20] & w_dir_n5_r;

	assign	o_Adder16InB_ALU	=	w_inc_aob|r_ST[i_RegSel][17]		|
									r_ST[i_RegSel][20] & ~w_dir_n5_r;

	assign	o_DataBus_ALU		=	o_AluOp_ADC|o_AluOp_SBC;

	assign	o_LoadAddrOutBuf	=	w_out_r | w_inc_aob							|
									r_ST[i_RegSel][14]							|
									r_ST[i_RegSel][20] & w_n8_pcr				|
									r_ST[i_RegSel][29] & (w_n16_pcr|w_ind_n16);

	assign	o_LoadDataInBufH	=	r_ST[i_RegSel][10]	|
									r_ST[i_RegSel][21];

endmodule

C Mapper118.sflp

/*
	Mapper 118
	IGS MMC3
		PRG-ROM 16KB banks 16 max 256KB
		CHR-ROM 8KB banks 16 max 128KB
*/

circuit Mapper118
{
	// PRG-ROM
	input ROM_SELn;
	instrin prg_read, prg_write;
	input prg_A<15>, prg_Din<8>;
	output prg_Dout<8>;
	output IRQn;

	// CHR-ROM
	instrin chr_read;//, chr_write; // RDn, WEn
	input chr_A<14>;//, chr_Din<8>; // chr_A13n
	output chr_Dout<8>;
	output VRAM_CSn, VRAM_A10;

//	instrin Phi; // 1.789MHz
	output usound<11>, ssound<14>;

	instrout exram_read(exram_adrs);
	output exram_adrs<13>; // EX_RAM  8KB
	output exram_wdata<8>;
	instrout exram_write(exram_adrs, exram_wdata);
	input exram_rdata<8>;

	// 外部RAMへのアクセス
	instrout prg_ram_read(prg_ram_adrs);
	output prg_ram_adrs<18>; // PRG_ROM max 256KB
//	output prg_ram_wdata<8>;
//	instrout prg_ram_write(prg_ram_adrs, prg_ram_wdata);
	input prg_ram_rdata<8>;

	instrout chr_ram_read(chr_ram_adrs);
	output chr_ram_adrs<17>; // CHR_ROM max 128KB
//	output chr_ram_wdata<8>;
//	instrout chr_ram_write(chr_ram_adrs, chr_ram_wdata);
	input chr_ram_rdata<8>;

	instrin init;
	instrin hblank;

	input n16kRomBanks<6>, /*n8kVRomBanks<6>,*/ fMirroringType;
	reg_wr fMirroringType_reg<2>;

	reg_wr prg_bank0<6>, prg_bank1<6>, prg_last_bank<5>;
	reg_wr chr_bank01<7>, chr_bank23<7>; // 偶数のみ
	reg_wr chr_bank4<8>, chr_bank5<8>, chr_bank6<8>, chr_bank7<8>;

	instrself map_rom, map_exram;

	reg_wr prg_swap, chr_swap;
//	reg_wr fSaveRAMenable;
	reg_ws IRQn_reg;
	reg_wr command<3>;

	reg_wr irq_counter<8>, irq_latch<8>, irq_enabled;

	sel prg_read_bank<6>, chr_read_bank<8>;
	reg_wr vcount<8>;
	reg_ws vblank;

	par{
		if(ROM_SELn==0b0){
			map_rom();
		}
		else any{
		//	prg_A<14:13>==0b10 : map_exrom();
			prg_A<14:13>==0b11 : map_exram();
		}

		any{
			map_rom : prg_Dout = prg_ram_rdata;
			map_exram : prg_Dout = exram_rdata;
		}

		VRAM_CSn = ^chr_A<13>;

		// ここ追加
		switch(fMirroringType_reg){
			case 0b00: ;
			case 0b01: ;
			case 0b10: VRAM_A10 = 0b0;
			case 0b11: VRAM_A10 = 0b1;
		}

		// VRAMでもchr_bankは使用している
		// chr_bank<8> + chr_A<10> = <18>
	//	sel chr_read_bank<8>;
		if(chr_swap){
			switch(chr_A<12:10>){
				case 0b000: chr_read_bank = chr_bank4;
				case 0b001: chr_read_bank = chr_bank5;
				case 0b010: chr_read_bank = chr_bank6;
				case 0b011: chr_read_bank = chr_bank7;
				case 0b100: chr_read_bank = chr_bank01 || 0b0;
				case 0b101: chr_read_bank = chr_bank01 || 0b1;
				case 0b110: chr_read_bank = chr_bank23 || 0b0;
				case 0b111: chr_read_bank = chr_bank23 || 0b1;
			}
		}
		else{
			switch(chr_A<12:10>){
				case 0b000: chr_read_bank = chr_bank01 || 0b0;
				case 0b001: chr_read_bank = chr_bank01 || 0b1;
				case 0b010: chr_read_bank = chr_bank23 || 0b0;
				case 0b011: chr_read_bank = chr_bank23 || 0b1;
				case 0b100: chr_read_bank = chr_bank4;
				case 0b101: chr_read_bank = chr_bank5;
				case 0b110: chr_read_bank = chr_bank6;
				case 0b111: chr_read_bank = chr_bank7;
			}
		}

		chr_Dout = chr_ram_rdata;

		IRQn = IRQn_reg;

		usound = // <11>
		   0b00000000000;

		ssound = // <14s>
		   0b00000000000000;
	}

	instruct init par{
		chr_swap := 0;
		prg_swap := 0;
		command := 0;
		prg_bank0 := 0b000000;
		prg_bank1 := 0b000001;
		prg_last_bank := (n16kRomBanks - 0b000001)<4:0>;
		irq_counter := 0;
		irq_latch := 0;
		irq_enabled := 0;

		chr_bank01 := 0b0000000; // 0x00
		chr_bank23 := 0b0000001; // 0x02
		chr_bank4 := 0x04;
		chr_bank5 := 0x05;
		chr_bank6 := 0x06;
		chr_bank7 := 0x07;

		fMirroringType_reg := 0b0 || fMirroringType;

		IRQn_reg := 0b1;
	}

	instruct prg_read any{
		map_rom : par{
			// prg_bank<6> + prg_A<13> = <19>
		//	sel prg_read_bank<6>;
			if(prg_swap){
				switch(prg_A<14:13>){
					case 0b00: prg_read_bank = prg_last_bank || 0b0;
					case 0b01: prg_read_bank = prg_bank1;
					case 0b10: prg_read_bank = prg_bank0;
					case 0b11: prg_read_bank = prg_last_bank || 0b1;
				}
			}
			else{
				switch(prg_A<14:13>){
					case 0b00: prg_read_bank = prg_bank0;
					case 0b01: prg_read_bank = prg_bank1;
					case 0b10: prg_read_bank = prg_last_bank || 0b0;
					case 0b11: prg_read_bank = prg_last_bank || 0b1;
				}
			}
			prg_ram_read(prg_read_bank<4:0> || prg_A<12:0>);
		}
		map_exram : exram_read(prg_A<12:0>);
	}

	instruct prg_write any{
		map_rom : par{
			switch(prg_A<14:13>||prg_A<0>){
				case 0b000: par{ // $8000 Command
					chr_swap := prg_Din<7>;
					prg_swap := prg_Din<6>;
					command := prg_Din<2:0>;
				}
				case 0b001: par{ // $8001 Page Number for Command
					// ここ追加
					if(
						((chr_swap==0b0) & (command==0b000)) |
						((chr_swap==0b1) & (command==0b010)) ){
							fMirroringType_reg := 0b1 || ^prg_Din<7>;
					}

					switch(command){
						case 0b000: chr_bank01 := prg_Din<7:1>;
						case 0b001: chr_bank23 := prg_Din<7:1>;
						case 0b010: chr_bank4 := prg_Din;
						case 0b011: chr_bank5 := prg_Din;
						case 0b100: chr_bank6 := prg_Din;
						case 0b101: chr_bank7 := prg_Din;
						case 0b110: prg_bank0 := prg_Din<5:0>;
						case 0b111: prg_bank1 := prg_Din<5:0>;
					}
				}
/*
				case 0b010: par{ // $A000 Mirroring Select
					fMirroringType_reg := ^prg_Din<0>;
				}
				case 0b011: par{ // $A001 SaveRAM Toggle
					fSaveRAMenable := prg_Din<7>;
				}
*/
				case 0b100: par{ // $C000
					irq_counter := prg_Din;
				}
				case 0b101: par{ // $C001
					irq_latch := prg_Din;
				}
				case 0b110: par{ // $E000
					irq_enabled := 0b0;
					IRQn_reg := 0b1;
				}
				case 0b111: par{ // $E001
					irq_enabled := 0b1;
				}
			}
		}
		map_exram : /*if(fSaveRAMenable)*/ exram_write(prg_A<12:0>, prg_Din);
	}

	instruct chr_read par{
		if(chr_A<13>==0b0){
			chr_ram_read(chr_read_bank<6:0> || chr_A<9:0>);
		}
	}

	instruct hblank par{

	// VBlank中はIRQは発生させないこと
	// vcountはVBlankから開始するでok
	//	reg_wr vcount<8>;
	//	reg_ws vblank;

		any{
			vblank & (vcount==0x15) : par{ // 21
				vcount := 0x00;
				vblank := 0b0;
			}
			(^vblank) & (vcount==0xEF) : par{ // 239
				vcount := 0x00;
				vblank := 0b1;
			}
			else : vcount++;
		}

		if(irq_enabled & (^vblank)){
			if(irq_counter==0x00){
				irq_counter := irq_latch;
				IRQn_reg := 0b0;
			}
			else irq_counter--;
		}
	}
}

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--;
	}
}
Total Pages: 2 / 712345...最後 »

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

タグ

最近投稿されたコード