flat assembler
Message board for the users of flat assembler.

Index > OS Construction > vga memory?

Author
Thread Post new topic Reply to topic
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 09 Nov 2010, 13:46
i do have few questions regarding display.

- when i write to a0000, i get the text mode. what code page is used to display code points?
- how do i access single pixel, (or multiple pixels if thats possible)?
Post 09 Nov 2010, 13:46
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 09 Nov 2010, 16:41
in vga programming, you first need to set the mode.

the VGA memory is just memory, it contains only bits, not the way to represent them on the screen.

it means that you didn't set the correct mode.

text modes will see bytes as character + attributes
graphics modes will see bytes as pixels, and depending on graphic mode used, one byte can encode from 8 to 1 pixel.
the black and white uses one bit for a pixel, the 13h ode uses 8 bytes to encode the index of a color in the palette.

yeah, i know, it looks like eating an elephant, but as stated here, eat it piece by piece.
Post 09 Nov 2010, 16:41
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Nov 2010, 22:53
edfed wrote:

yeah, i know, it looks like eating an elephant, but as stated here, eat it piece by piece.
The saying is "eat it byte by byte". Smile
Post 09 Nov 2010, 22:53
View user's profile Send private message Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 10 Nov 2010, 01:34
lol
Quote:
eat it byte by byte


I assume this is what you mean:
b1528932, to access a pixel first, you need to set the segment selector for graphics mode 13h (0A000h) into an extra segment such as es, fs or gs. But it's usually es
set es = 0A000h
remember, es cannot be accessed directly, so you can do either of the following:
push 0A000h
pop es

or
by setting an index register to 0A000h such as, bx, bp, di, si
mov di,0A000h
mov es,dii
xor di,di


you can now access any pixel on the screen by:
[es:di]
es is 0A000h and di points to any pixel on the screen
basically, for every 320 values in the segment represent 1 line.
Image

so if you want to access pixel 319 and put a colour there, you would write:
mov di,319
mov [es:di],0Fh
; puts white dot on screen


------
Lately, I thought about a formula to get the exact position on screen by using X and Y coordinates

the formula is:

    where,
    k = 319
    0 <= y <= 319
    0 <= x <= 199

    1. (k * y) x + y = offset position or
    2. y(k + 1) + x = offset position
    keep in mind for formula 2, that y is distributed over k and 1

    example:
    k = 319
    x = 21
    y = 3

    (k * y) + x + y = offset position
    (319 * 3) + 21 + 3 = 981

    982 is the black block in the grid.
    If you have the time try counting it, you'll see it works.

[/img]
I suppose thats what you mean by accessing a pixel


Description:
Filesize: 3.03 KB
Viewed: 6180 Time(s)

graph1.GIF




Last edited by adroit on 12 Nov 2010, 00:06; edited 1 time in total
Post 10 Nov 2010, 01:34
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 10 Nov 2010, 09:05
Quote:
(k * y) + x + y = offset position
(319 * 3) + 21 + 3 +1 = 982


Calculations that you used are very weird.

Try This..
Code:
;-------------
; Data
;-------------

Y       DW ?
X       DW ?
Color   DB ?

;-------------
; (320*y)+ x
;-------------

@VGA_Mode_13H:

        PUSH    0A000H
        POP     ES

        MOV     DL,[Color]
        MOV      CX,[X]
        MOV   AX,[Y]
        ROL     AX,8
        MOV     BX,AX
        ADD     AX,CX
        SHR     BX,2
        ADD     BX,AX
        MOV     [ES:BX],DL              ; Write Pixel

        RET
    

instead of
Code:
rol ax, 8    
you can use
Code:
mov ah, al
    

or
Code:
shl ax, 8
    

_________________
Nil Volentibus Arduum Razz
Post 10 Nov 2010, 09:05
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 10 Nov 2010, 14:49
with 32 bit instruction set (the one that i think 99,9% of running x86 PC supports), you can do it in a lot less instructions

Code:
pixel13h:
;eax=X
;ebx=Y
;ecx=color ; can be used in that case as a 32bpp value (with alpha), 
;and some seeker will find (or create) the closest entry in palette. 
;but there it will just be used as 8 bit value
;edi will be the index in video memory
lea edi,[ebx*4+ebx]
shl edi,6
lea,edi,[edi+eax]
push es word 0a000h
pop es
mov [es:edi],cl
pop es
ret
    
Post 10 Nov 2010, 14:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 10 Nov 2010, 14:59
I think you are all focussed on the wrong thing to optimise.

In all probability, the CPU can compute the pixel addresses (with most of the methods posted here, even the slow ones) faster than the graphics memory can be updated. So the bottleneck is not your instruction selection, but the external hardware memory bus. Optimise for memory bus transfers, not coordinate computations. Use the cache first then transfer to video memory by use of a back buffer. etc.

Also: Get it working, then get it fast. Wink
Post 10 Nov 2010, 14:59
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 11 Nov 2010, 07:17
b1528932 wrote:
when i write to a0000, i get the text mode. what code page is used to display code points?
In text mode, characters' shapes are defined by contents of selected character maps (sequencer, index 3; memory map 2). Most VBIOSes load codepage 437 character generator there; I've seen samples with codepage 850; several (at least) videocontrollers support reflashing their VBIOS (so you can't count on it).

BTW, for standard text modes graphics controller (3CEh/3CFh) is programmed so buffer is mapped to 0B8000h…0BFFFFh (or 0B0000h…0B7FFFh for monochrome mode 7).
b1528932 wrote:
how do i access single pixel, (or multiple pixels if thats possible)?
That depends on how videocontroller is programmed (chained/unchained memory mode, interlacing for 200-line modes and others). Read manual.
Post 11 Nov 2010, 07:17
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 11 Nov 2010, 19:41
the better i think is to just give you a link to some mode 13h demo.

click here to download mode13h life
Post 11 Nov 2010, 19:41
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 12 Nov 2010, 16:34
Okay, this may not directly be what he was asking, but since it's already been mentioned ...

http://technet.microsoft.com/en-us/library/bb490916.aspx

Quote:

Graftabl does not change the console input code page. Graftabl affects only the monitor display of extended characters of the code page you specify. To change the code page you are using, use the mode or chcp command.


Codepage? Which one: hardware, system, or display?

For instance, I'm pretty sure you can't change text-mode fonts without EGA or VGA or above. But FreeDOS' DISPLAY.EXE (once prepared and selected) shows 8-bit text in (for example) CGA gfx mode 4 (if you use the BIOS, not sure about other methods).
Post 12 Nov 2010, 16:34
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 13 Nov 2010, 11:17
rugxulo,

Original MDA/CGA didn't support chargen loading; HGC and later did (even variant of CGA in ES-1840). I mean hardware support in text modes.

In graphics modes 4…6 int10 BIOS video output services support custom 8×8 character bitmaps for upper half of code page through int1F vector that points to 1 KiB of those 8-byte bitmaps for 80h…0FFh codes. EGA and later add support for lower half through int43 vector (8×14 and 8×16 chargens for full range are pointed by this vector too in corresponding graphics modes).

In one BIOS listing I saw code that tried to match those custom shapes to implement int10/08 service (read char/attr at cursor). Primitive OCR?!
Post 13 Nov 2010, 11:17
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.