public void AddCactus(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null) { byte height = (byte)Rand.Next(3, 6); ushort yy; for (yy = 0; yy <= height; yy++) { if (overwrite || Lvl.GetTile(z, (ushort)(y + yy), z) == Block.air) { if (blockChange) { if (p == null) { Lvl.Blockchange(x, (ushort)(y + yy), z, Block.green); } else { Lvl.Blockchange(p, x, (ushort)(y + yy), z, Block.green); } } else { Lvl.skipChange(x, (ushort)(y + yy), z, Block.green); } } } int inX = 0, inZ = 0; switch (Rand.Next(1, 3)) { case 1: inX = -1; break; case 2: default: inZ = -1; break; } for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++) { if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air) { if (blockChange) { if (p == null) { Lvl.Blockchange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); } else { Lvl.Blockchange(p, (ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); } } else { Lvl.skipChange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green); } } } for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++) { if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air) { if (blockChange) { if (p == null) { Lvl.Blockchange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); } else { Lvl.Blockchange(p, (ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); } } else { Lvl.skipChange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green); } } } }
public static extern int BX5MK_SendLatticeMessage(uint dwHand, byte BlockFlag, ushort BlockAddr, byte[] BlockData, ushort BlockDataLen);
public static extern int BX5MK_SetSpecialAppDynamic(int dwHand, ushort AreaX, ushort AreaY, ushort AreaW, ushort AreaH, byte DataType, byte Pagetotal, byte RunState, ushort Timeout, byte SingleLine, byte Lines_sizes, byte NewLine, ushort StayTime);
public static extern int CON_ReadScreenID(uint dwHand, ref ushort pScreenID);
public static extern int SCREEN_SendSoundDynamicArea(uint dwHand, bx_5k_area_header header, ushort TextLen, byte[] AreaText, byte SoundMode, byte SoundPerson, byte SoundVolume, byte SoundSpeed, int sound_len, byte[] sounddata);
public static extern int CON_CheckCurrentFont(uint dwHand, byte[] fontStatus, ref ushort len);
public static extern int CON_ReadScreen(uint dwHand, byte[] ScreenStatus, ref ushort len);
public static extern IntPtr /* PVOID */ ImageDirectoryEntryToData( IntPtr Base, // PVOID byte MappedAsImage, // BOOLEAN ushort DirectoryEntry, // USHORT out ulong Size // PULONG );
// Execute instructions public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable) { switch (cur_instr[instr_pntr++]) { case IDLE: // do nothing break; case OP: // Read the opcode of the next instruction if (EI_pending > 0 && !CB_prefix) { EI_pending--; if (EI_pending == 0) { interrupts_enabled = true; } } if (I_use && interrupts_enabled && !CB_prefix && !jammed) { interrupts_enabled = false; if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); } // call interrupt processor // lowest bit set is highest priority INTERRUPT_(); } else { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); FetchInstruction(ReadMemory(RegPC++)); } instr_pntr = 0; I_use = false; break; case RD: Read_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case WR: Write_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case TR: TR_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case ADD16: ADD16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case ADD8: ADD8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case SUB8: SUB8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case ADC8: ADC8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case SBC8: SBC8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case INC16: INC16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case INC8: INC8_Func(cur_instr[instr_pntr++]); break; case DEC16: DEC16_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case DEC8: DEC8_Func(cur_instr[instr_pntr++]); break; case RLC: RLC_Func(cur_instr[instr_pntr++]); break; case RL: RL_Func(cur_instr[instr_pntr++]); break; case RRC: RRC_Func(cur_instr[instr_pntr++]); break; case RR: RR_Func(cur_instr[instr_pntr++]); break; case CPL: CPL_Func(cur_instr[instr_pntr++]); break; case DA: DA_Func(cur_instr[instr_pntr++]); break; case SCF: SCF_Func(cur_instr[instr_pntr++]); break; case CCF: CCF_Func(cur_instr[instr_pntr++]); break; case AND8: AND8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case XOR8: XOR8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case OR8: OR8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case CP8: CP8_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case SLA: SLA_Func(cur_instr[instr_pntr++]); break; case SRA: SRA_Func(cur_instr[instr_pntr++]); break; case SRL: SRL_Func(cur_instr[instr_pntr++]); break; case SWAP: SWAP_Func(cur_instr[instr_pntr++]); break; case BIT: BIT_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case RES: RES_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case SET: SET_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case EI: if (EI_pending == 0) { EI_pending = 2; } break; case DI: interrupts_enabled = false; EI_pending = 0; break; case HALT: halted = true; bool temp = false; if (cur_instr[instr_pntr++] == 1) { temp = FlagI; } else { temp = I_use; } if (EI_pending > 0 && !CB_prefix) { EI_pending--; if (EI_pending == 0) { interrupts_enabled = true; } } // if the I flag is asserted at the time of halt, don't halt if (temp && interrupts_enabled && !CB_prefix && !jammed) { interrupts_enabled = false; if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====IRQ====", RegisterInfo = "" }); } halted = false; if (is_GBC) { // call the interrupt processor after 4 extra cycles if (!Halt_bug_3) { INTERRUPT_GBC_NOP(); } else { INTERRUPT_(); Halt_bug_3 = false; //Console.WriteLine("Hit INT"); } } else { // call interrupt processor INTERRUPT_(); Halt_bug_3 = false; } } else if (temp) { // even if interrupt servicing is disabled, any interrupt flag raised still resumes execution if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====un-halted====", RegisterInfo = "" }); } halted = false; if (is_GBC) { // extra 4 cycles for GBC if (Halt_bug_3) { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); RegPC++; FetchInstruction(ReadMemory(RegPC)); Halt_bug_3 = false; //Console.WriteLine("Hit un"); } else { cur_instr = new ushort[] {IDLE, IDLE, IDLE, OP }; } } else { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); if (Halt_bug_3) { //special variant of halt bug where RegPC also isn't incremented post fetch RegPC++; FetchInstruction(ReadMemory(RegPC)); Halt_bug_3 = false; } else { FetchInstruction(ReadMemory(RegPC++)); } } } else { if (skip_once) { cur_instr = new ushort[] {IDLE, IDLE, IDLE, HALT, 0 }; skip_once = false; } else { if (is_GBC) { cur_instr = new ushort[] {IDLE, IDLE, HALT_CHK, HALT, 0 }; } else { cur_instr = new ushort[] {HALT_CHK, IDLE, IDLE, HALT, 0 }; } } } I_use = false; instr_pntr = 0; break; case STOP: stopped = true; if (!stop_check) { stop_time = SpeedFunc(0); stop_check = true; } if (stop_time > 0) { stop_time--; if (stop_time == 0) { if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====un-stop====", RegisterInfo = "" }); } stopped = false; if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); FetchInstruction(ReadMemory(RegPC++)); instr_pntr = 0; stop_check = false; } else { instr_pntr = 0; cur_instr = new ushort[] {IDLE, IDLE, IDLE, STOP }; } } else if (interrupt_src.Bit(4)) // button pressed, not actually an interrupt though { if (TraceCallback != null) { TraceCallback(new TraceInfo { Disassembly = "====un-stop====", RegisterInfo = "" }); } stopped = false; if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); FetchInstruction(ReadMemory(RegPC++)); instr_pntr = 0; stop_check = false; } else { instr_pntr = 0; cur_instr = new ushort[] {IDLE, IDLE, IDLE, STOP }; } break; case PREFIX: CB_prefix = true; break; case ASGN: ASGN_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case ADDS: ADDS_Func(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case OP_G: if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null) TraceCallback(State()); if (CDLCallback != null) CDLCallback(RegPC, eCDLogMemFlags.FetchFirst); FetchInstruction(ReadMemory(RegPC)); // note no increment instr_pntr = 0; break; case JAM: jammed = true; instr_pntr--; break; case RD_F: Read_Func_F(cur_instr[instr_pntr++], cur_instr[instr_pntr++], cur_instr[instr_pntr++]); break; case EI_RETI: EI_pending = 1; break; case INT_GET: // check if any interrupts got cancelled along the way // interrupt src = 5 sets the PC to zero as observed // also the triggering interrupt seems like it is held low (i.e. annot trigger I flag) until the interrupt is serviced if (interrupt_src.Bit(0) && interrupt_enable.Bit(0)) { int_src = 0; int_clear = 1; } else if (interrupt_src.Bit(1) && interrupt_enable.Bit(1)) { int_src = 1; int_clear = 2; } else if (interrupt_src.Bit(2) && interrupt_enable.Bit(2)) { int_src = 2; int_clear = 4; } else if (interrupt_src.Bit(3) && interrupt_enable.Bit(3)) { int_src = 3; int_clear = 8; } else if (interrupt_src.Bit(4) && interrupt_enable.Bit(4)) { int_src = 4; int_clear = 16; } else { int_src = 5; int_clear = 0; } Regs[cur_instr[instr_pntr++]] = INT_vectors[int_src]; break; case HALT_CHK: I_use = FlagI; if (Halt_bug_2 && I_use) { RegPC--; Halt_bug_3 = true; //Console.WriteLine("Halt_bug_3"); //Console.WriteLine(TotalExecutedCycles); } Halt_bug_2 = false; break; case IRQ_CLEAR: if (interrupt_src.Bit(int_src)) { interrupt_src -= int_clear; } if ((interrupt_src & interrupt_enable) == 0) { FlagI = false; } break; } TotalExecutedCycles++; }
public string getString() { ushort stringLen = getU16(); string val = Encoding.ASCII.GetString(buffer, position, stringLen); position += stringLen; return val; }
void BufferAdd(List<Pos> list, ushort x, ushort y, ushort z) { Pos pos; pos.x = x; pos.y = y; pos.z = z; list.Add(pos); }
public ushort getU16() { ushort val = BitConverter.ToUInt16(buffer, position); position += 2; return val; }
public void Add(ushort keySize, HashAlgorithmName hashAlgorithmName) { Add(new KeyHashPair(keySize, hashAlgorithmName)); }
/// <summary> /// 获取ushort 数据 /// </summary> /// <param name="msb">高八位</param> /// <param name="lsb">低八位</param> /// <returns></returns> ushort UDigitTransform(byte msb, byte lsb) { ushort num = (ushort)((ushort)msb * 256 + (ushort)lsb); return(num); }
public static extern uint CreateComModbus(byte com, uint baudrate, serial_parity Parity, serial_databits DataBits, serial_stopbits StopBits, bx_5k_card_type card_type, ushort ScreenID);
public ImageWriter WriteBeUInt16(ushort us) { WriteByte((byte)(us >> 8)); WriteByte((byte)us); return(this); }
public static extern int CON_ControllerStatus(uint dwHand, byte[] pStatus, ref ushort len);
public abstract ImageWriter WriteUInt16(ushort us);
public static extern int CON_CheckCurrentCustomer(uint dwHand, byte[] CustomerStatus, ref ushort len);
public override ImageWriter WriteUInt16(ushort us) { return(WriteLeUInt16(us)); }
public static extern int CON_SetScreenID(uint dwHand, ushort newScreenID);
void FindGUIDTable() { using (var fs = File.OpenRead(filename)) { using (var str = new BinaryReader(fs)) { str.BaseStream.Position = 0; if (str.ReadByte() != 0x4d || str.ReadByte() != 0x5a) { return; // MZ header } str.BaseStream.Position = 0x80; if (str.ReadByte() != 'P' || str.ReadByte() != 'E' || str.ReadByte() != 0 || str.ReadByte() != 0) { return; // PE signature ("PE\0\0") } // Read the PE file header if (str.ReadByte() != 0x4c || str.ReadByte() != 0x01) { return; // PE file header -> Machine (always 0x014c) } ushort sectionCount = str.ReadUInt16(); str.BaseStream.Position += 12; ushort optionalHeaderSize = str.ReadUInt16(); if (optionalHeaderSize < 224) { return; // optional header is not big enough } str.BaseStream.Position += 2; // Read the optional PE header str.BaseStream.Position += 208; int cliHeaderRVA = str.ReadInt32(); /*int cliHeaderSize = */ str.ReadInt32(); str.BaseStream.Position += 8; // Read the sections, looking for the ".text" section. int sectionHeaderPosition = (int)str.BaseStream.Position; int textSectionPosition = -1; uint virtualAddress = uint.MaxValue; uint pointerToRawData = 0; for (int i = 0; i < sectionCount; i++) { str.BaseStream.Position = sectionHeaderPosition + 40 * i; if (str.ReadByte() != '.' || str.ReadByte() != 't' || str.ReadByte() != 'e' || str.ReadByte() != 'x' || str.ReadByte() != 't' || str.ReadByte() != 0) { continue; } textSectionPosition = sectionHeaderPosition + 40 * i; str.BaseStream.Position = textSectionPosition + 12; virtualAddress = str.ReadUInt32(); str.BaseStream.Position += 4; pointerToRawData = str.ReadUInt32(); break; } if (virtualAddress == uint.MaxValue) { return; } // Now we can calculate the file position of the CLI header str.BaseStream.Position = cliHeaderRVA - (virtualAddress - pointerToRawData); str.BaseStream.Position += 8; uint metadataRVA = str.ReadUInt32(); /*uint metadataSize = */ str.ReadUInt32(); // Find and read the metadata header uint metadataRootPosition = metadataRVA - (virtualAddress - pointerToRawData); str.BaseStream.Position = metadataRootPosition; if (str.ReadByte() != 0x42 || str.ReadByte() != 0x53 || str.ReadByte() != 0x4a || str.ReadByte() != 0x42) { return; // Invalid magic signature. } str.BaseStream.Position += 8; int dynamicLength = str.ReadInt32(); str.BaseStream.Position += dynamicLength; str.BaseStream.Position += 2; // flags ushort metadataStreams = str.ReadUInt16(); for (ushort i = 0; i < metadataStreams; i++) { uint offset = str.ReadUInt32(); uint size = str.ReadUInt32(); byte[] name = new byte [32]; for (int k = 0; k < 8; k++) { str.Read(name, k * 4, 4); if (name [k * 4 + 3] == 0) { break; } } if (name [0] == '#' && name [1] == 'G' && name [2] == 'U' && name [3] == 'I' && name [4] == 'D' && name [5] == 0) { // found the GUID table. guid_table_start = metadataRootPosition + offset; guid_table_length = size; return; } } } } }
public static extern int SCREEN_SendDynamicArea(uint dwHand, bx_5k_area_header header, ushort TextLen, byte[] AreaText);
/// <summary> /// Creates an instance of the dummy packet used to debug communication or /// to represent unknown packets. /// </summary> /// <param name="typeID">The type of the received packet.</param> /// <param name="buffer">The received data.</param> public CS_Disconnect(ushort typeID, byte[] buffer, int index, int count) : base(typeID, buffer, index, count) { }
public static extern int BX5MK_SendPageData(uint dwHand, byte PageNum, ushort PageDataLen, byte[] PageData);
public ThirdGenTag(StructureValueCollection values, ushort index, FileSegmentGroup metaArea, IList<ITagGroup> groupList, IPointerExpander expander) { Load(values, index, metaArea, groupList, expander); }
public static extern int BX5MK_SetIPAddress(uint dwHand, byte ConnnectMode, byte[] ip, byte[] SubnetMask, byte[] Gateway, ushort port, byte ServerMode, byte[] ServerIPAddress, ushort ServerPort, byte[] ServerAccessPassword, ushort HeartBeatInterval, byte[] NetID);
public static extern uint CreateComClient(byte com, uint baudrate, bx_5k_card_type card_type, int mode, ushort ScreenID);
public static extern int BX5MK_WebSearch(uint dwHand, ref ushort Status, ref ushort Error, byte[] IP, byte[] SubNetMask, byte[] Gate, ref ushort Port, byte[] Mac, byte[] NetID);
public void AddNotchSwampTree(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null) { byte dist, tile; byte height = (byte)Rand.Next(4, 8); byte top = (byte)(height - 2); short xx, yy, zz; ushort xxx, yyy, zzz; for (yy = 0; yy <= height; yy++) { yyy = (ushort)(y + yy); tile = Lvl.GetTile(x, yyy, z); if (overwrite || tile == Block.air || (yyy == y && tile == Block.shrub)) { if (blockChange) { if (p == null) { Lvl.Blockchange(x, yyy, z, Block.trunk); } else { Lvl.Blockchange(p, x, yyy, z, Block.trunk); } } else { Lvl.skipChange(x, yyy, z, Block.trunk); } } } for (yy = top; yy <= height + 1; yy++) { dist = yy > height - 1 ? (byte)2 : (byte)3; for (xx = (short)-dist; xx <= dist; xx++) { for (zz = (short)-dist; zz <= dist; zz++) { xxx = (ushort)(x + xx); yyy = (ushort)(y + yy); zzz = (ushort)(z + zz); tile = Lvl.GetTile(xxx, yyy, zzz); //Server.s.Log(String.Format("{0} {1} {2}", xxx, yyy, zzz)); if ((xxx == x && zzz == z && yy <= height) || (!overwrite && tile != Block.air)) { continue; } if (Math.Abs(xx) == dist && Math.Abs(zz) == dist) { if (yy > height) { continue; } if (Rand.Next(2) == 0) { if (blockChange) { if (p == null) { Lvl.Blockchange(xxx, yyy, zzz, Block.leaf); } else { Lvl.Blockchange(p, xxx, yyy, zzz, Block.leaf); } } else { Lvl.skipChange(xxx, yyy, zzz, Block.leaf); } } } else { if (blockChange) { if (p == null) { Lvl.Blockchange(xxx, yyy, zzz, Block.leaf); } else { Lvl.Blockchange(p, xxx, yyy, zzz, Block.leaf); } } else { Lvl.skipChange(xxx, yyy, zzz, Block.leaf); } } } } } }