// Disable video interrupts
vgaIO.disableIRQ();
// Allocate the screen memory
final MemoryResource screen = claimDeviceMemory(bytesPerScreen, 4 * 1024);
// final MemoryResource screen = deviceRam;
log.debug("Screen at 0x" + NumberUtils.hex(screen.getOffset().toInt()) + ", size 0x" +
NumberUtils.hex(screen.getSize().toInt()));
// if (true) { throw new ResourceNotFreeException("TEST"); }
// Save the current state
oldVgaState.saveFromVGA(vgaIO);
log.debug("oldState:" + oldVgaState);
// Turn off the screen
final DpmsState dpmsState = getDpms();
setDpms(DpmsState.OFF);
try {
// Set the new configuration
currentState.restoreToVGA(vgaIO);
log.debug("NewState: " + currentState);
vgaIO.setReg32(CRTC_OFFSET, (int) screen.getOffset().toInt());
if (fbinfo.hasCRTC2) {
vgaIO.setReg32(CRTC2_OFFSET, (int) screen.getOffset().toInt());
}
// Set the 8-bit palette
setPalette(1.0f);
// Create the graphics helper & clear the screen
final BitmapGraphics bitmapGraphics;
switch (bitsPerPixel) {
case 8:
bitmapGraphics =
BitmapGraphics.create8bppInstance(screen, width, height, bytesPerLine,
0);
screen.setByte(0, (byte) 0, pixels);
break;
case 16:
bitmapGraphics =
BitmapGraphics.create16bppInstance(screen, width, height, bytesPerLine,
0);
screen.setShort(0, (byte) 0, pixels);
break;
case 24:
bitmapGraphics =
BitmapGraphics.create24bppInstance(screen, width, height, bytesPerLine,
0);
screen.setInt24(0, 0, pixels);
break;
case 32:
bitmapGraphics =
BitmapGraphics.create32bppInstance(screen, width, height, bytesPerLine,
0);
screen.setInt(0, 0, pixels);
break;
default:
throw new IllegalArgumentException("Invalid bits per pixel " + bitsPerPixel);
}
return new RadeonSurface(this, config, bitmapGraphics, screen, accel);