⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgbbasicvideo.java

📁 一个用java写成的gb模拟器的源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	byte[] getTileLineArray(int bank, int tilenum, int tileline) {
		byte[] tla = new byte[8];
		copyTileLineArray((bank * 0x2000) + (tilenum * 16) + (tileline * 2), tla, 0);
		return tla;
	}
	byte[] getTileLineArray(int bank, int tilenum, int tileline, boolean hflip, byte orwith) {
		byte[] tla = new byte[8];
		copyTileLineArray((bank * 0x2000) + (tilenum * 16) + (tileline * 2), hflip, orwith, tla, 0);
		return tla;
	}
	
	void copyTileLineArray(int tx, int ty, int tileline, boolean map_mode, byte[] dest, int dest_pos) {
		int tilenum = getTile(tx, ty, map_mode);
		if(PgbSettings.system == PgbSettings.SYS_GBC) {
			int attribute = getAttr(tx, ty, map_mode);
			copyTileLineArray(((attribute & 0x08) >> 3) * 0x2000 + tilenum * 16 + ((attribute & 0x40) == 0x40 ? (7 - tileline) : tileline) * 2, (attribute & 0x20) == 0x20, (byte)((attribute & 0x07) << 3), dest, dest_pos);
			return;
		} else {
			copyTileLineArray((tilenum * 16) + (tileline * 2), dest, dest_pos);
			return;
		}
	}

	
	void copyTileLineArray(int vram_pos, byte[] dest, int dest_pos) {
		byte td0 = vram[vram_pos];
		byte td1 = vram[vram_pos + 1];
		dest[dest_pos++] = (byte)((td0 >> 7 & 1) | (td1 >> 6 & 2));
		dest[dest_pos++] = (byte)((td0 >> 6 & 1) | (td1 >> 5 & 2));
		dest[dest_pos++] = (byte)((td0 >> 5 & 1) | (td1 >> 4 & 2));
		dest[dest_pos++] = (byte)((td0 >> 4 & 1) | (td1 >> 3 & 2));
		dest[dest_pos++] = (byte)((td0 >> 3 & 1) | (td1 >> 2 & 2));
		dest[dest_pos++] = (byte)((td0 >> 2 & 1) | (td1 >> 1 & 2));
		dest[dest_pos++] = (byte)((td0 >> 1 & 1) | (td1 >> 0 & 2));
		dest[dest_pos++] = (byte)((td0 >> 0 & 1) | (td1 << 1 & 2));
	}
	void copyTileLineArray(int vram_pos, boolean hflip, byte orwith, byte[] dest, int dest_pos) {
		byte td0 = vram[vram_pos];
		byte td1 = vram[vram_pos + 1];
		if(hflip) {
			dest_pos += 7;
			dest[dest_pos--] = (byte)(orwith | (td0 >> 7 & 1) | (td1 >> 6 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 6 & 1) | (td1 >> 5 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 5 & 1) | (td1 >> 4 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 4 & 1) | (td1 >> 3 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 3 & 1) | (td1 >> 2 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 2 & 1) | (td1 >> 1 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 1 & 1) | (td1 >> 0 & 2));
			dest[dest_pos--] = (byte)(orwith | (td0 >> 0 & 1) | (td1 << 1 & 2));
		} else {
			dest[dest_pos++] = (byte)(orwith | (td0 >> 7 & 1) | (td1 >> 6 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 6 & 1) | (td1 >> 5 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 5 & 1) | (td1 >> 4 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 4 & 1) | (td1 >> 3 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 3 & 1) | (td1 >> 2 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 2 & 1) | (td1 >> 1 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 1 & 1) | (td1 >> 0 & 2));
			dest[dest_pos++] = (byte)(orwith | (td0 >> 0 & 1) | (td1 << 1 & 2));
		}
	}

	
	public void doSgbPalette(int line) {
		byte b;
		int i, ls;
		for(i = 0; i < 5; i++) {
			b = sgbPaletteOverlay[(line / 8) * 5 + i];
			ls = line * 160 + i * 32;
			tileLineOr(screenMemory, ls + 0, (byte)((b & 0xC0) >> 2));
			tileLineOr(screenMemory, ls + 8, (byte)((b & 0x30) >> 0));
			tileLineOr(screenMemory, ls + 16, (byte)((b & 0x0C) << 2));
			tileLineOr(screenMemory, ls + 24, (byte)((b & 0x03) << 4));
		}
	}
	void tileLineOr(byte[] src, int position, byte orwith) {
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
		src[position++] |= orwith;
	}
	
	public void setBgPal(int pval) {
		super.setBgPal(pval);
		int i, j;
		// super gameboy
		if(PgbSettings.system == PgbSettings.SYS_SGB) {
			for(j = 0; j < 4; j++) {
				for(i = 0; i < 4; i++) {
					setScreenPalette(false, 0, j, i, sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 1], sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 0]);
				}
			}
			return;
		}
		// mono gameboy
		if(PgbSettings.system == PgbSettings.SYS_GB || PgbSettings.system == PgbSettings.SYS_GBP) {
			for(i = 0; i < 4; i++) {
				setScreenPalette(0x00 | i, PgbSettings.bgcolors[pval >> (i * 2) & 3]);
			}
		}
	}
	
	public void setObjPal0(int pval) {
		super.setObjPal0(pval);
		int i, j;
		objpal0 = pval;
		// super gameboy
		if(PgbSettings.system == PgbSettings.SYS_SGB) {
			for(j = 0; j < 4; j++) {
				for(i = 0; i < 4; i++) {
					setScreenPalette(true, 0, j, i, sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 1], sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 0]);
				}
			}
			return;
		}
		// mono gameboy
		if(PgbSettings.system == PgbSettings.SYS_GB || PgbSettings.system == PgbSettings.SYS_GBP) {
			for(i = 0; i < 4; i++) {
				setScreenPalette(0x04 | i, PgbSettings.obj0colors[pval >> (i * 2) & 3]);
			}
		}
	}
	
	public void setObjPal1(int pval) {
		super.setObjPal1(pval);
		int i, j;
		// super gameboy
		if(PgbSettings.system == PgbSettings.SYS_SGB) {
			for(j = 0; j < 4; j++) {
				for(i = 0; i < 4; i++) {
					setScreenPalette(true, 1, j, i, sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 1], sgbPalette[j * 8 + (pval >> (i * 2) & 3) * 2 + 0]);
				}
			}
			return;
		}
		// mono gameboy
		if(PgbSettings.system == PgbSettings.SYS_GB || PgbSettings.system == PgbSettings.SYS_GBP) {
			for(i = 0; i < 4; i++) {
				setScreenPalette(0x0D | i, PgbSettings.obj1colors[pval >> (i * 2) & 3]);
			}
		}
	}
	
	public void gbcSetBgpd(byte data) {
		int p = bgpi >> 3 & 0x07, c = bgpi >> 1 & 0x03;
		super.gbcSetBgpd(data);
		setScreenPalette(false, p, 0, c, gbcPalette[0x00 + p * 8 + c * 2 + 1], gbcPalette[0x00 + p * 8 + c * 2 + 0]);
	}
	public void gbcSetObpd(byte data) {
		int p = obpi >> 3 & 0x07, c = obpi >> 1 & 0x03;
		super.gbcSetObpd(data);
		setScreenPalette(true, p, 0, c, gbcPalette[0x40 + p * 8 + c * 2 + 1], gbcPalette[0x40 + p * 8 + c * 2 + 0]);
	}
	
	/**
	 * sets a color based off flags and two bytes
	 */
	void setScreenPalette(boolean obj, int pal, int sgbPal, int color, byte hi, byte low) {
		int cindex;
		cindex = ((sgbPal & 0x03) << 4) | (obj ? 0x04 : 0x00) | ((pal & 0x07) << 3) | (color & 0x03);
		setScreenPalette(cindex, getColor32(hi, low));
	}
	
	/**
	 * sets a color based off index and 32-bit AARRGGBB value
	 */
	void setScreenPalette(int cindex, int color) {
		int acolor = colorAdjust(color);
		screenPalette[cindex] = acolor;
		screenRPal[cindex] = (byte)(acolor >> 16);
		screenGPal[cindex] = (byte)(acolor >> 8);
		screenBPal[cindex] = (byte)(acolor >> 0);
	}
	
	/**
	 * returns a 32-bit color, given the hi and low bytes
	 * of a 15-bit one
	 */
	int getColor32(byte hi, byte low) {
		int color15, color32;
		color15 = (hi << 8) | (low & 0xFF);
		color32 = 0xFF000000 | ((color15 & 0x001F) << 19) | ((color15 & 0x03E0) << 6) | ((color15 & 0x7C00) >> 7);
		return color32;
	}
	
	int colorAdjust(int color) {
		int red, green , blue;
		if(PgbSettings.colormute) {
			red = color >> 16 & 0xFF;
			green = color >> 8 & 0xFF;
			blue = color >> 0 & 0xFF;
			red = (int)((red - 128) * .75 + 144);
			green = (int)((green - 128) * .75 + 144);
			blue = (int)((blue - 128) * .75 + 144);
			return 0xFF000000 | (red << 16) | (green << 8) | blue;
		} else {
			return color;
		}
	}
	
	public void sgbSetPalette(int pal, int color, byte hi, byte low) {
		super.sgbSetPalette(pal, color, hi, low);
		setBgPal(bgpal);
		setObjPal0(objpal0);
		setObjPal1(objpal1);
	}
	public void sgbSetPaletteIndirect(int pal0, int pal1, int pal2, int pal3, int atf) {
		super.sgbSetPaletteIndirect(pal0, pal1, pal2, pal3, atf);
		setBgPal(bgpal);
		setObjPal0(objpal0);
		setObjPal1(objpal1);
	}
	public void sgbPictureTransfer() {
		int i;
		super.sgbPictureTransfer();
		// duhhh... set the border screenPalette
		for(i = 0; i < 64; i++) {
			setBorderPalette(i + 64, getColor32(sgbPicture[2048 + i * 2 + 1], sgbPicture[2048 + i * 2 + 0]));
		}
		doSgbBorder();
		/*
		borderColorModel = new IndexColorModel(8, 256, borderRPal, borderGPal, borderBPal, 0);
		borderMISrc.newPixels(borderPixels, borderColorModel, 0, 256);
		*/
	}
	void setBorderPalette(int cindex, int color) {
		borderPalette[cindex] = color;
		/*
		borderRPal[cindex] = (byte)(colorAdjust(color) >> 16);
		borderGPal[cindex] = (byte)(colorAdjust(color) >> 8);
		borderBPal[cindex] = (byte)(colorAdjust(color) >> 0);
		*/
	}


	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -