Exemplo n.º 1
0
status_t
Rage128_SetDisplayMode(const DisplayModeEx& mode)
{
	// The code to actually configure the display.
	// All the error checking must be done in ProposeDisplayMode(),
	// and assume that the mode values we get here are acceptable.

	DisplayParams params;		// where computed parameters are saved

	if (gInfo.sharedInfo->displayType == MT_VGA) {
		// Chip is connected to a monitor via a VGA connector.

		if ( ! CalculateCrtcRegisters(mode, params))
			return B_BAD_VALUE;

		if ( ! CalculatePLLRegisters(mode, params))
			return B_BAD_VALUE;

		if ( ! CalculateDDARegisters(mode, params))
			return B_BAD_VALUE;

		SetRegisters(params);

	} else {
		// Chip is connected to a laptop LCD monitor; or via a DVI interface.

		uint16 vesaMode = GetVesaModeNumber(display_mode(mode), mode.bitsPerPixel);
		if (vesaMode == 0)
			return B_BAD_VALUE;

		if (ioctl(gInfo.deviceFileDesc, ATI_SET_VESA_DISPLAY_MODE,
				&vesaMode, sizeof(vesaMode)) != B_OK)
			return B_ERROR;
	}

	Rage128_AdjustFrame(mode);

	// Initialize the palette so that color depths > 8 bits/pixel will display
	// the correct colors.

	// Select primary monitor and enable 8-bit color.
	OUTREGM(R128_DAC_CNTL, R128_DAC_8BIT_EN,
		R128_DAC_PALETTE_ACC_CTL | R128_DAC_8BIT_EN);
	OUTREG8(R128_PALETTE_INDEX, 0);		// set first color index

	for (int i = 0; i < 256; i++)
		OUTREG(R128_PALETTE_DATA, (i << 16) | (i << 8) | i );

	Rage128_EngineInit(mode);

	return B_OK;
}
/**
 * Handles the setregisters sub-command.
 *
 * @returns Suitable exit code.
 * @param   pArgs               The handler arguments.
 * @param   pDebugger           Pointer to the debugger interface.
 */
static RTEXITCODE handleDebugVM_SetRegisters(HandlerArg *pArgs, IMachineDebugger *pDebugger)
{
    /*
     * We take a list of register assignments, that is register=value.
     */
    ULONG                       idCpu = 0;
    com::SafeArray<IN_BSTR>     aBstrNames;
    com::SafeArray<IN_BSTR>     aBstrValues;

    RTGETOPTSTATE               GetState;
    RTGETOPTUNION               ValueUnion;
    static const RTGETOPTDEF    s_aOptions[] =
    {
        { "--cpu", 'c', RTGETOPT_REQ_UINT32 },
    };
    int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    AssertRCReturn(rc, RTEXITCODE_FAILURE);

    while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
    {
        switch (rc)
        {
            case 'c':
                idCpu = ValueUnion.u32;
                break;

            case VINF_GETOPT_NOT_OPTION:
            {
                const char *pszEqual = strchr(ValueUnion.psz, '=');
                if (!pszEqual)
                    return errorSyntax("setregisters expects input on the form 'register=value' got '%s'", ValueUnion.psz);
                try
                {
                    com::Bstr bstrName(ValueUnion.psz, pszEqual - ValueUnion.psz);
                    com::Bstr bstrValue(pszEqual + 1);
                    if (   !aBstrNames.push_back(bstrName.raw())
                        || !aBstrValues.push_back(bstrValue.raw()))
                        throw std::bad_alloc();
                }
                catch (std::bad_alloc)
                {
                    RTMsgError("Out of memory\n");
                    return RTEXITCODE_FAILURE;
                }
                break;
            }

            default:
                return errorGetOpt(rc, &ValueUnion);
        }
    }

    if (!aBstrNames.size())
        return errorSyntax("The setregisters sub-command takes at least one register name");

    /*
     * If it is only one register, use the single register method just so
     * we expose it and can test it from the command line.
     */
    if (aBstrNames.size() == 1)
    {
        CHECK_ERROR2I_RET(pDebugger, SetRegister(idCpu, aBstrNames[0], aBstrValues[0]), RTEXITCODE_FAILURE);
        RTPrintf("Successfully set %ls\n", aBstrNames[0]);
    }
    else
    {
        CHECK_ERROR2I_RET(pDebugger, SetRegisters(idCpu, ComSafeArrayAsInParam(aBstrNames), ComSafeArrayAsInParam(aBstrValues)),
                          RTEXITCODE_FAILURE);
        RTPrintf("Successfully set %u registers\n", aBstrNames.size());
    }

    return RTEXITCODE_SUCCESS;
}