/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="addr"></param> /// <param name="size"></param> /// <param name="fp"></param> /// <returns></returns> public int fwrite(Getable source, int addr, int size, int fp) { if ((fp & 0x80) == 0) { return(0); } fp &= 0x7f; if (fp >= MAX_FILE_COUNT) { return(0); } if (usable[fp] || !canWrite[fp]) { return(0); } VirtualFile file = files[fp]; int count = 0, b; while (count < size) { b = source.getByte(addr++); if (file.putc(b & 0xff) == -1) { break; } count++; } return(count); }
/// <summary> /// 得到src从addr开始的length个字节的crc16码 /// </summary> /// <param name="src"></param> /// <param name="addr"></param> /// <param name="length"></param> /// <returns></returns> public static UInt16 getCrc16Value(Getable src, int addr, int length) { UInt16 crc = 0, tmp; while (--length >= 0) { tmp = (UInt16)((crc >> 8) & 0xff); crc <<= 4; crc ^= CRC16_TAB[(tmp >> 4) ^ ((src.getByte(addr) & 0xff) >> 4)]; tmp = (UInt16)((crc >> 8) & 0xff); crc <<= 4; crc ^= CRC16_TAB[(tmp >> 4) ^ (src.getByte(addr) & 0x0f)]; addr++; } return(crc); }
public void drawString(int x, int y, Getable source, int addr) { int length = 0; while (source.getByte(addr + length) != 0) { length++; } drawString(x, y, source, addr, length); }
public void drawString(int x, int y, Getable source, int addr, int length) { //这个调用drawRegion时会修改区域,所以这儿不需要再修改区域 sbyte[] data = isBig ? new sbyte[32] : new sbyte[24]; int h = isBig ? 16 : 12; Getable getter = Util.asAccessable(data); while (length > 0) { UInt16 c = (UInt16)(source.getByte(addr++) & 0xff); length--; if (c >= 0x80 && length > 0) { //c |= source.getByte(addr++) << 8; c |= (UInt16)(source.getByte(addr++) << 8); length--; } int w = (isBig ? Util.getGB16Data(c, data) : Util.getGB12Data(c, data)) / 2; drawRegion(x, y, w, h, getter, 0); x += w; } }
private string getstring(Getable src, int addr) { int length = 0; sbyte b; while ((b = src.getByte(addr++)) != 0) { strBuf[length++] = b; } //try //{ // return new string(strBuf, 0, length, "gb2312"); //} //catch (UnsupportedEncodingException uee) //{ // return new string(strBuf, 0, length); //} return(Util.NewString(strBuf, 0, length, Encoding.GetEncoding("gb2312"))); }
public bool changeDir(Getable source, int addr) { int pre = -2; int length = 0; sbyte b = 0; while ((b = source.getByte(addr)) != 0) { if (b == '/') { if (pre != addr - 1) { strBuf[length++] = b; } pre = addr; addr++; } else { strBuf[length++] = b; addr++; } } string newDir = null; try { //newDir = new string(strBuf, 0, length, "gb2312"); newDir = Util.NewString(strBuf, 0, length, Encoding.GetEncoding("gb2312")); } catch (Exception uee) { newDir = Util.NewString(strBuf, 0, length); } if (newDir == "..") { if (workDir == "/") { return(false); } int pos = workDir.LastIndexOf('/', workDir.Length - 2) + 1; workDir = workDir.Substring(0, pos); workDirInf = fileSys.getFileInf(workDir); return(true); } else { if (!newDir.StartsWith("/")) { newDir = workDir + newDir; } if (!newDir.EndsWith("/")) { newDir += "/"; } if (workDir == newDir) { return(true); } FileSystemInfo inf = fileSys.getFileInf(newDir); if (inf.isDirectory()) { workDir = newDir; workDirInf = inf; return(true); } else { return(false); } } }
public void drawRegion(int x, int y, int width, int height, Getable source, int addr) { if (width <= 0 || height <= 0) { return; } if (x >= WIDTH || y >= HEIGHT || x + width < 0 || y + height < 0) { return; } //每行数据占用byte数 //int bytePerLine = (width + 7) >>> 3; int bytePerLine = TypeConverter.UnsignedRightMove((width + 7), 3); //每行开始第一个数据前无用的bit数 int unuseDataBits = 0; if (x < 0) { addr += (-x) / 8; unuseDataBits = (-x) % 8; width += x; x = 0; } if (y < 0) { addr += -bytePerLine * y; height += y; y = 0; } if (x + width > WIDTH) { width -= x + width - WIDTH; } if (y + height > HEIGHT) { height -= y + height - HEIGHT; } //如果是屏幕绘图,添加到修改区域 if (isGraph) { addPoint(x, y); addPoint(x + width - 1, y + height - 1); } //绘制处前无用的bit数 int unuseScreenBits = x % 8; //绘制开始地址 int offset = BYTES_PER_LINE * y + x / 8; //实际每行用到数据的byte数 int count = (unuseDataBits + width + 7) / 8; //实际绘制影响到的byte数 int size = (unuseScreenBits + width + 7) / 8; //绘制结尾剩下的bit数 int remain = size * 8 - unuseScreenBits - width; //用于存储图像数据 sbyte[] mapData = new sbyte[count + 1]; while (height-- > 0) { for (int index = 0; index < count; index++) { mapData[index] = source.getByte(addr + index); } addr += bytePerLine; adjustData(mapData, 0, mapData.Length, unuseDataBits - unuseScreenBits); for (int index = 0; index < size; index++) { int s = mapData[index], d = currData[offset + index]; int mask = 0; if (index == 0) { mask |= maskH[unuseScreenBits]; } if (index == size - 1) { mask |= maskT[remain]; } if ((drawMode & 0x08) != 0) { s ^= 0xff; if ((drawMode & 0x07) == 2) { drawMode &= ~0x07; } } s &= ~mask; d &= ~mask; //currData[offset + index] &= mask;//vliu注释掉的 switch (drawMode & 0x07) { case 2: s ^= ~mask; break; case 3: s |= d; break; case 4: s &= d; break; case 5: s ^= d; break; } //currData[offset + index] |= s;//vliu注释掉的 }//for offset += BYTES_PER_LINE; } }