rem: static status_t exec_type1_script(uint8* rom, uint16 adress, int16* size)
add: static status_t exec_type1_script(uint8* rom, uint16 adress, int16* size, uint16 ram_tab)
context: static status_t exec_type1_script(uint8* rom, uint16 adress, int16* size){	status_t result = B_OK;	bool end = false;	bool exec = true;	uint8 index, byte, safe;	uint32 reg, data, data2, and_out, or_in, safe32;	LOG(8,("\nINFO: executing type1 script at adress $%04x...\n", adress));	while (!end)	{		LOG(8,("INFO: $%04x ($%02x); ", adress, rom[adress]));		//fixme: complete for NV10 and later (if possible) ...		switch (rom[adress])		{		case 0x59:			*size -= 7;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint16*)(&(rom[adress])));			adress += 2;			data2 = *((uint16*)(&(rom[data])));			LOG(8,("cmd 'calculate indirect and set PLL 32bit REG $%08x for %.3fMHz'\n",				reg, ((float)data2)));			if (exec)			{				//fixme: setup core and RAM PLL calc routine(s), now (mis)using DAC's...				display_mode target;				float calced_clk;				uint8 m, n, p;				target.timing.pixel_clock = (data2 * 1000);				nv_dac_pix_pll_find(target, &calced_clk, &m, &n, &p, 0);				NV_REG32(reg) = ((p << 16) | (n << 8) | m);//fixme?				/* program 2nd set N and M scalers if they exist (b31=1 enables them) *///				if ((si->ps.card_type == NV31) || (si->ps.card_type == NV36))//					DACW(PIXPLLC2, 0x80000401);			}			log_pll(reg);			break;		case 0x5a:			*size -= 7;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint16*)(&(rom[adress])));			adress += 2;			data2 = *((uint32*)(&(rom[data])));			LOG(8,("cmd 'WR indirect 32bit REG' $%08x = $%08x\n", reg, data2));			if (exec) NV_REG32(reg) = data2;			break;		case 0x63:			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			LOG(8,("cmd 'setup RAM config' (always done)\n"));			//fixme: setup_ram_config is also used on NV11 (at least), which means the			//       routine should function differently there!			/* always done */			setup_ram_config(rom);			break;		case 0x65:			*size -= 13;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint32*)(&(rom[adress])));			adress += 4;			data2 = *((uint32*)(&(rom[adress])));			adress += 4;			LOG(8,("cmd 'WR 32bit REG $%08x = $%08x, then = $%08x' (always done)\n",				reg, data, data2));			/* always done */			/* (alternate NV-specific access to PCI config space registers:) */			safe32 = NV_REG32(0x00001800 + NVCFG_AGPCMD);			NV_REG32(0x00001800 + NVCFG_AGPCMD) = 0x00000000;			NV_REG32(reg) = data;			NV_REG32(reg) = data2;			NV_REG32(0x00001800 + NVCFG_AGPCMD) = safe32;			NV_REG32(0x00001800 + NVCFG_ROMSHADOW) &= 0xfffffffe;			break;		case 0x66: /* new on NV11 */			LOG(8,("NV11+ xxx cmd, skipping...\n"));			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			adress += 1;			break;		case 0x67: /* new on NV11 */			LOG(8,("NV11+ xxx cmd, skipping...\n"));			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			adress += 1;			break;		case 0x68: /* new on NV11 */			LOG(8,("NV11+ xxx cmd, skipping...\n"));			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			adress += 1;			break;		case 0x69:			*size -= 5;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint16*)(&(rom[adress])));			adress += 2;			and_out = *((uint8*)(&(rom[adress])));			adress += 1;			or_in = *((uint8*)(&(rom[adress])));			adress += 1;			LOG(8,("cmd 'RD 8bit ISA I/O REG $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",				reg, and_out, or_in));			if (exec)			{				byte = ISARB(reg);				byte &= (uint8)and_out;				byte |= (uint8)or_in;				ISAWB(reg, byte);			}			break;		case 0x6d:			*size -= 3;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			//fixme: NV32_NV4STRAPINFO is a pre-NV10 specific register. How about NV11?			//       should this cmd 'exist' there?!? if, so: with different exec?			adress += 1;			data = NV_REG32(NV32_NV4STRAPINFO);			and_out = *((uint8*)(&(rom[adress])));			adress += 1;			byte = *((uint8*)(&(rom[adress])));			adress += 1;			data &= (uint32)and_out;			LOG(8,("cmd 'CHK bits AND-out $%02x RAMCFG for $%02x, stop PGM on no match'\n",				and_out, byte));			if (((uint8)data) != byte)			{				LOG(8,("INFO: ---No match: not executing following command(s):\n"));				exec = false;			}			else			{				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));			}			break;		case 0x6e:			*size -= 13;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			and_out = *((uint32*)(&(rom[adress])));			adress += 4;			or_in = *((uint32*)(&(rom[adress])));			adress += 4;			LOG(8,("cmd 'RD 32bit REG $%08x, AND-out = $%08x, OR-in = $%08x, WR-bk'\n",				reg, and_out, or_in));			if (exec)			{				data = NV_REG32(reg);				data &= and_out;				data |= or_in;				NV_REG32(reg) = data;			}			break;		case 0x71:			LOG(8,("cmd 'END', execution completed.\n\n"));			end = true;			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error!\n\n"));				result = B_ERROR;			}			break;		case 0x72:			*size -= 1;			if (*size < 0)			{				LOG(8,("script size error!\n\n"));				result = B_ERROR;			}			/* execute */			adress += 1;			LOG(8,("cmd 'PGM commands'\n"));			LOG(8,("INFO: ---Executing following command(s):'\n"));			exec = true;			break;		case 0x73:			*size -= 9;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			data = NV_REG32(NV32_NVSTRAPINFO2);			and_out = *((uint32*)(&(rom[adress])));			adress += 4;			data2 = *((uint32*)(&(rom[adress])));			adress += 4;			data &= and_out;			LOG(8,("cmd 'CHK bits AND-out $%08x STRAPCFG2 for $%08x, stop PGM on no match'\n",				and_out, data2));			if (data != data2)			{				LOG(8,("INFO: ---No match: not executing following command(s):\n"));				exec = false;			}			else			{				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));			}			break;		case 0x74:			*size -= 3;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			data = *((uint16*)(&(rom[adress])));			adress += 2;			LOG(8,("cmd 'SNOOZE for %d ($%04x) microSeconds' (always done)\n", data, data));			/* always done */			snooze(data);			break;		case 0x77:			*size -= 7;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint16*)(&(rom[adress])));			adress += 2;			LOG(8,("cmd 'WR 32bit REG' $%08x = $%08x (b31-16 = '0', b15-0 = data)\n",				reg, data));			if (exec) NV_REG32(reg) = data;			break;		case 0x78:			*size -= 6;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint16*)(&(rom[adress])));			adress += 2;			index = *((uint8*)(&(rom[adress])));			adress += 1;			and_out = *((uint8*)(&(rom[adress])));			adress += 1;			or_in = *((uint8*)(&(rom[adress])));			adress += 1;			LOG(8,("cmd 'RD 8bit idx ISA I/O REG $%02x via $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",				index, reg, and_out, or_in));			if (exec)			{				safe = ISARB(reg);				ISAWB(reg, index);				byte = ISARB(reg + 1);				byte &= (uint8)and_out;				byte |= (uint8)or_in;				ISAWB((reg + 1), byte);				ISAWB(reg, safe);			}			break;		case 0x79:			*size -= 7;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint16*)(&(rom[adress])));			adress += 2;			LOG(8,("cmd 'calculate and set PLL 32bit REG $%08x for %.3fMHz'\n", reg, (data / 100.0)));			if (exec)			{				//fixme: setup core and RAM PLL calc routine(s), now (mis)using DAC's...				display_mode target;				float calced_clk;				uint8 m, n, p;				target.timing.pixel_clock = (data * 10);				nv_dac_pix_pll_find(target, &calced_clk, &m, &n, &p, 0);				NV_REG32(reg) = ((p << 16) | (n << 8) | m);//fixme?				/* program 2nd set N and M scalers if they exist (b31=1 enables them) *///				if ((si->ps.card_type == NV31) || (si->ps.card_type == NV36))//					DACW(PIXPLLC2, 0x80000401);			}			log_pll(reg);			break;		case 0x7a:			*size -= 9;			if (*size < 0)			{				LOG(8,("script size error, aborting!\n\n"));				end = true;				result = B_ERROR;				break;			}			/* execute */			adress += 1;			reg = *((uint32*)(&(rom[adress])));			adress += 4;			data = *((uint32*)(&(rom[adress])));			adress += 4;			LOG(8,("cmd 'WR 32bit REG' $%08x = $%08x\n", reg, data));			if (exec) NV_REG32(reg) = data;			break;		default:			LOG(8,("unknown cmd, aborting!\n\n"));			end = true;			result = B_ERROR;			break;		}	}	return result;}