How do you achieve VGA graphics WITHOUT RealMode/BIOS calls?
Posted: Thu Apr 26, 2018 11:49 pm
My OS is at the stage where it can dynamically load and link drivers from PE format data into the kernel.
So it's time for a graphics driver to keep me motivated, because I want a "proper" OS. I know I could set the graphics during the Real Mode stages but I really don't like that solution.
Obviously if some 16-bit BIOS routine can properly initialise the video device, what's really stopping me from doing the same with IO ports in protected mode?
Really I only plan to run my OS in virtual machines (QEMU/Bochs/VirtualBox) and they all seem to simulate the same graphics device, similar to Cirrus Logic devices (please correct me if I'm wrong).
So I'd be more than happy to write the best Cirrus driver I can, and share the code here if I can get some pointers on what I need to do to:
1. Properly switch modes from the default 80x25 textmode to at least 320x200 256 colours using IO ports only
2. Plot specific pixels on the screen
Here's my current code which gets QEMU to a pure black screen, Bochs to an almost solid grey but with some corrupt pixels at the bottom and VirtualBox to a black background with grey lines and rectangles all over the place (seems like a textmode hang over).
Note: I memset locations 0xA000 and 0xA0000 to 0xFF after this is executed, also I have little idea what I'm doing I just tried different registers to achieve a different result than my first attempt (random pixels/rectangles/lines everywhere).
So it's time for a graphics driver to keep me motivated, because I want a "proper" OS. I know I could set the graphics during the Real Mode stages but I really don't like that solution.
Obviously if some 16-bit BIOS routine can properly initialise the video device, what's really stopping me from doing the same with IO ports in protected mode?
Really I only plan to run my OS in virtual machines (QEMU/Bochs/VirtualBox) and they all seem to simulate the same graphics device, similar to Cirrus Logic devices (please correct me if I'm wrong).
So I'd be more than happy to write the best Cirrus driver I can, and share the code here if I can get some pointers on what I need to do to:
1. Properly switch modes from the default 80x25 textmode to at least 320x200 256 colours using IO ports only
2. Plot specific pixels on the screen
Here's my current code which gets QEMU to a pure black screen, Bochs to an almost solid grey but with some corrupt pixels at the bottom and VirtualBox to a black background with grey lines and rectangles all over the place (seems like a textmode hang over).
Note: I memset locations 0xA000 and 0xA0000 to 0xFF after this is executed, also I have little idea what I'm doing I just tried different registers to achieve a different result than my first attempt (random pixels/rectangles/lines everywhere).
Code: Select all
WRITEREG VGA_MISC_WRITE, 0x03
; Plane mask
WRITEREG VGA_SEQ_INDEX, 2
WRITEREG VGA_SEQ_DATA, 0
; Extended memory
WRITEREG VGA_SEQ_INDEX, 4
WRITEREG VGA_SEQ_DATA, 2
;
; CRTC crap, horizontal total and end, vertical total
WRITEREG VGA_CRTC_INDEX, 0
WRITEREG VGA_CRTC_DATA, 0
WRITEREG VGA_CRTC_INDEX, 1
WRITEREG VGA_CRTC_DATA, 1
WRITEREG VGA_CRTC_INDEX, 6
WRITEREG VGA_CRTC_DATA, 0
; Screen start address
WRITEREG VGA_CRTC_INDEX, 0xC
WRITEREG VGA_CRTC_DATA, 0xA0
WRITEREG VGA_CRTC_INDEX, 0xD
WRITEREG VGA_CRTC_DATA, 0x00
WRITEREG VGA_GC_INDEX, 6
WRITEREG VGA_GC_DATA, 00000001b