/// <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); }
private string getFileName(Getable src, int addr) { string name = getstring(src, addr); if (!name.StartsWith("/")) { name = workDir + name; } return(name); }
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 bool makeDir(Getable source, int addr) { string dir = getFileName(source, addr); bool result = fileSys.makeDir(dir); if (result && isParent(workDir, dir)) { workDirInf = fileSys.getFileInf(workDir); } return(result); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="addr"></param> /// <returns></returns> public bool deleteFile(Getable source, int addr) { string file = getFileName(source, addr); bool result = fileSys.deleteFile(file); //如果当前目录信息被修改,重置之 if (result && isParent(workDir, file)) { workDirInf = fileSys.getFileInf(workDir); } return(result); }
/// <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); }
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 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; } }
/// <summary> /// 设置用于显示的ScreenModel,并作适当的初始化 /// </summary> /// <param name="screen"></param> public void setScreenModel(ScreenModel screen) { if (screen == null) { //throw new IllegalArgumentException("Screen must't be null!"); } if (this.screen != screen) { this.screen = screen; this.buffer = new sbyte[(screen.getWidth() / 6) * (screen.getHeight() / 13)]; this.getter = new ByteArrayGetter(buffer); this.ram = new ByteArrayRam(buffer, screen); this.render = screen.getRender(); } else { ram.Clear(); } this.curCol = this.curRow = 0; this.isBigMode = true; this.maxCol = screen.getWidth() / 8; this.maxRow = screen.getHeight() / 16; }
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 int fopen(Getable source, int fileName, int openMode) { int num = -1; //指示文件指针位置,true开头,false为结尾 bool pointer = true; //是否清除原有文件 bool clear = false; for (int index = 0; index < MAX_FILE_COUNT; index++) { if (usable[index]) { num = index; break; } } if (num == -1) { return(0); } string name = getFileName(source, fileName); string mode = getstring(source, openMode); FileSystemInfo inf = fileSys.getFileInf(name); if (READ_MODE == mode || READ_B_MODE == mode) { if (!(inf.isFile() && inf.canRead())) { return(0); } canRead[num] = true; canWrite[num] = false; } else if (READ_PLUS_MODE == mode || READ_B_PLUS_MODE == mode) { if (!(inf.isFile() && inf.canRead() && inf.canWrite())) { return(0); } canRead[num] = true; canWrite[num] = true; } else if (WRITE_MODE == mode || WRITE_B_MODE == mode) { if (inf.isFile() && !inf.canWrite()) { return(0); } clear = true; canRead[num] = false; canWrite[num] = true; } else if (WRITE_PLUS_MODE == mode || WRITE_B_PLUS_MODE == mode) { if (inf.isFile() && !inf.canWrite()) { return(0); } clear = true; canRead[num] = true; canWrite[num] = true; } else if (APPEND_MODE == mode || APPEND_B_MODE == mode) { if (!(inf.isFile() && inf.canWrite())) { return(0); } canRead[num] = false; canWrite[num] = true; pointer = false; } else if (APPEND_PLUS_MODE == mode || APPEND_B_PLUS_MODE == mode) { if (!(inf.isFile() && inf.canRead() && inf.canWrite())) { return(0); } canRead[num] = true; canWrite[num] = true; pointer = false; } else { return(0); } VirtualFile file = files[num]; if (clear) { file.refresh(); } else { int length = 0; try { //InputStream in = fileSys.getInputStream(name); FileStream inputStream = fileSys.getInputStream(name); //file.readFromStream(in); file.readFromStream(inputStream); length = file.limit(); //in.close(); inputStream.Close(); } catch (Exception ex) { return(0); } file.position(pointer ? 0 : length); } fileNames[num] = name; usable[num] = false; return(num | 0x80); }
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; } }