BIOS 13h video mode draw pixels

This commit is contained in:
Ciro Santilli
2015-09-20 12:16:43 +02:00
parent 3fa034d5b8
commit 1f8c00ec8f
6 changed files with 126 additions and 8 deletions

View File

@@ -17,6 +17,8 @@ Hello world programs that run without an operating system.
1. [background](bios_background.S)
1. [scroll](bios_scroll.S)
1. [clear screen](bios_clear_screen.S)
1. [pixel](bios_pixel.S)
1. [pixel line](bios_pixel_line.S)
1. APM
1. [APM shutdown](apm_shutdown.S)
1. [APM shutdown 2](apm_shutdown2.S)

23
TODO.md
View File

@@ -1,20 +1,35 @@
# TODO
- Segment registers: http://stackoverflow.com/questions/30549526/c-kernel-works-fine-on-vm-but-not-actual-computer?rq=1
- 32 bit mode. Answer http://stackoverflow.com/questions/7130726/writing-a-hello-world-kernel
- http://stackoverflow.com/questions/4903906/assembly-using-the-data-segment-register-ds answer with minimal example and mention QEMU vs real hardwre http://wiki.osdev.org/Segmentation
- http://stackoverflow.com/questions/3819699/what-does-ds40207a-mean-in-assembly
- move to 32 bit mode. Answer http://stackoverflow.com/questions/7130726/writing-a-hello-world-kernel
- load a second stage from disk into memory
- BIOS
- pages
- ACPI
- reboot computer. Would put QEMU into an infinite reboot loop. Awesome.
- multithreading: http://stackoverflow.com/questions/7308391/how-is-concurrency-done-in-intel-x86-assembly || http://stackoverflow.com/questions/980999/what-does-multicore-assembly-language-look-like || http://stackoverflow.com/questions/714905/threads-in-x86-assembler-using-the-gnu-assember-as || https://github.com/cirosantilli/oszur11-operating-system-examples/tree/1af6451852887fac3d7206d4d09714c181c81d1e/Chapter_07_Threads
- transition to protected mode
- test the paging circuit
- play with hardware
- set a pixel on screen
- http://wiki.osdev.org/How_do_I_set_a_graphics_mode
- http://stackoverflow.com/questions/14419088/assembly-draw-a-pixel-on-the-screen-in-protected-mode
- set a pixel on screen in protected mode http://stackoverflow.com/questions/14419088/assembly-draw-a-pixel-on-the-screen-in-protected-mode
- USB
- networking
- GPU...
- outb inb instructions
- POST https://en.wikipedia.org/wiki/Power-on_self-test

25
bios.md
View File

@@ -18,6 +18,31 @@ Does any documentation or portability exist??
<http://www.scs.stanford.edu/nyu/04fa/lab/specsbbs101.pdf> says little about interrupts, I don't understand it's scope.
## Video mode
There are several video modes.
Modes determine what interrupt functions can be used.
There are 2 main types of modes:
- text, where we operate character-wise
- video, operate byte-wise
Modes can be set with `int 0x10` and `AH = 0x00`, and get with `AH = 0x0F`
The most common modes seem to be:
- 0x01: 40x25 Text, 16 colors, 8 pages
- 0x03: 80x25 Text, 16 colors, 8 pages
- 0x13: 320x200 Graphics, 256 colors, 1 page
You can add 128 to the modes to avoid clearing the screen.
Taken from: <https://courses.engr.illinois.edu/ece390/books/labmanual/graphics-int10h.html>
A larger list: <http://www.columbia.edu/~em36/wpdos/videomodes.txt>
## Colors
## Text properties

View File

@@ -4,18 +4,20 @@
BEGIN
/*
Print one 'a' char to ensure that something will be claered.
Print one 'a' char to ensure that something will be cleared.
On some systems, BIOS messages get automatically cleared. Not the case for QEMU 2.0.0.
*/
PUTC(61)
/* Scroll 0 is magic, and scrolls the entire selected rectangle. */
mov $0x0600, %ax
mov $0xA4, %bh
/*
Act on the entire screen.
Bottom right is at (24,79) == (0x18,0x4F)
Pick the entire screen.
Bottom right is at (24,79) == (0x18,0x4F),
since we are on the default mode.
*/
mov $0x0000, %cx
mov $0X184F, %dx

52
bios_pixel.S Normal file
View File

@@ -0,0 +1,52 @@
/*
Set pixel at position (1, 1) to a clear red color (0Ch) in 13h video mode.
You have to look a bit hard to see it.
Mode 13h has: 320x200 Graphics, 256 colors, 1 page.
https://en.wikipedia.org/wiki/Mode_13h describes it a bit.
TODO Color encoding: is there any logic?
Shown on wiki page: https://en.wikipedia.org/wiki/Mode_13h
Does not seem to be R R R G G G B B mentioned at: https://en.wikipedia.org/wiki/8-bit_color
Asked at: http://stackoverflow.com/questions/14233437/convert-normal-256-color-to-mode-13h-version-color
Things get much more involved from protected mode:
http://stackoverflow.com/questions/14419088/how-to-draw-a-pixel-on-the-screen-in-protected-mode-in-x86-assembly
TODO do it!
And for hardware accelaration, you need to make real drivers
(to semi-documented complex GPU hardware :-) )
http://wiki.osdev.org/How_do_I_set_a_graphics_mode
*/
#include "common.h"
BEGIN
/* Enter video mode 13h: */
mov $0x0013, %ax
int $0x10
start:
/*
Draw the pixel pixel.
AH = 0Ch
AL = Color
BH = Page Number
CX = x
DX = y
*/
mov $0x0C0C, %ax
mov $0x01, %bh
mov $0x0001, %cx
mov $0x0001, %dx
int $0x10
inc %cx
inc %dx
cmp $201, %dx
jz end
jmp start
end:
hlt
END

22
bios_pixel_line.S Normal file
View File

@@ -0,0 +1,22 @@
/*
Draw a 45 degree line of pixels to the screen on 13h video mode.
*/
#include "common.h"
BEGIN
mov $0x0013, %ax
int $0x10
mov $0x0000, %cx
mov $0x0000, %dx
start:
mov $0x0C88, %ax
mov $0x01, %bh
int $0x10
inc %cx
inc %dx
cmp $201, %dx
jz end
jmp start
end:
hlt
END