Reputation: 2321
Some programs on the net seem to do the same job without even using the int
instruction, such as writing directly to bx800
. In this case, how exactly does BIOS know if some texts should be written to console? Is it that the initial interrupt is guaranteed to occur? If so, exactly when, and what's the equivalent assembly line (or a combination of a interrupt vector and ah
) that does the same job?
Upvotes: 0
Views: 868
Reputation: 44056
The BIOS services are there to abstract the hardware.
If you have sufficient knowledge of the underlying video card you can program it directly.
The VGA has been extensively documented [1]
[2] [3], though the topic is not easy and the learning curve is quite steep due to a general lack of a proper introduction.
An introduction that is out of topic for an answer on this site but a short version on why the BIOS can be bypassed can be presented.
The VGA card has an internal memory that is read cyclically (drawing is a cyclic business) to generate the analogue signals to drive the CRT compatible display.
If we know how to put the right data into that memory we will be able to draw a character.
Not all the addresses in the address space of the CPU are reclaimed by the system memory (subsystem), the range 0xb8000 - 0xbffff
is assigned to the VGA card internal memory - writing into that range will put data into the card's internal memory.
Knowing how to put some data into the card's memory we must still know what to put into it.
Luckily the VGA supports text modes that allow the programmer to specify a character code instead of drawing each glyph pixel by pixel.
Each code (in jargon, code point - which coincide with the code unit for the encoding used) is associated with a glyph by the means of the charset setup by IBM at the time (CP437).
Along with the code point, the programmer can specify the character attributes such as the foreground and background colours.
For example, once text mode is enabled, to draw a blue A on the first row at the first column just write:
mov WORD [es:0], 0941h ;Assuming ES = 0b800h
;09 = Attributes (Blue on black)
;41h = Code point of the glyph A
Each character takes two bytes (a word), the first one is the code point, the second one is the attributes.
Due to the x86 endianness the 41h (code point) will end at address 0 while the attributes will go at address 1.
Internally the matter is more complicated: see the memory layout and odd/even mode.
This is what programming the hardware effectively is: moving data into contexts of different semantics.
Upvotes: 7
Reputation: 37
What I'm understanding is you're having trouble writing to the screen. When in real mode, you can't really access any interrupts at all. You can only write to video memory. Here is some code I quickly typed up for you. Hopefully, this works
mov edi, 0xB8000 ; This will point to the location in ram (b8000 = video mem.)
mov BYTE [edi], 'H' ; First we declar we are moving a byte, then we move 'H' into video memory.
mov BYTE [edi+1], 0Fh ; The second byte is always color. This is White on black
mov BYTE [edi+2], 'i' ; Next print the i
mov BYTE [edi+3], 0Fh
What we can see here is we first move edi (memory pointer) to the location in video memory. \
Upvotes: 0