Video Memory Map?

  • Follow


I stumbled across the code below from emu8086. The final mov goes to
video memory. Is there a map that defines where each video memory
address is on a console screen? For instance, if I wanted to send a
character to row 5, column 18, what video memory address would I use?

Also, what is the purpose of "MOV AX, 0B800h" and "MOV DS, AX" in the
code below? I don't understand why that is there? Thanks.

ORG 100h           ; this directive required for a simple 1 segment
..com program.
MOV AX, 0B800h     ; set AX to hexadecimal value of B800h.
MOV DS, AX         ; copy value of AX to DS.
MOV CL, 'A'        ; set CL to ASCII code of 'A', it is 41h.
MOV CH, 1101_1111b ; set CH to binary value.
MOV BX, 15Eh       ; set BX to 15Eh.
MOV [BX], CX       ; copy contents of CX to memory at B800:015E
RET                ; returns to operating system.

0
Reply spamtrap2 (1628) 7/30/2006 7:45:06 PM

In article <1154288706.899057.308980@m79g2000cwm.googlegroups.com>, 
spamtrap@crayne.org says...
> I stumbled across the code below from emu8086. The final mov goes to
> video memory. Is there a map that defines where each video memory
> address is on a console screen?

Sort of. The first two bytes of video memory are the first character 
cell at the TL corner of the screen. The character to display comes 
from the first byte, and the display attributes (color possibly 
blinking) are in the second byte. The next two bytes are for the next 
character cell, and so from left to right and top to bottom.

> For instance, if I wanted to send a
> character to row 5, column 18, what video memory address would I use?

That depends on the display mode you're using, and particularly on 
the number of columns in that display mode. Here's some code (MASM 
format) to figure an address from a row/column:

; address = base + 2 * (y * columns + x)
; where base = 
; 	b000h for monochrome
;	b800h for color
;
    mov cx,0b000h
    mov ah, 0fh
    int 10h
    mov columns,ah
    cmp al, 7
    jz @f
    mov cx, 0b800h
@@:
    mov es,cx
    mov al,y_coord
    mov dl,ah
    mul dl
    mov di,ax
    mov al,x_coord
    cbw
    add di,ax
    shl di, 1

-- 
    Later,
    Jerry.

The universe is a figment of its own imagination.

0
Reply Jerry 7/30/2006 9:43:06 PM


Sam wrote:
> I stumbled across the code below from emu8086. The final mov goes to
> video memory. Is there a map that defines where each video memory
> address is on a console screen?

Google "VGA programming" or something like that.  The standard that
defines how to access video memory is discussed in the VGA
specification, created by IBM.  The poster above has given you a good
start to understanding, but if you want to know more (such as how to
use graphics mode) look this up.


> Also, what is the purpose of "MOV AX, 0B800h" and "MOV DS, AX" in the
> code below? I don't understand why that is there? Thanks.

The DS register holds a pointer to the data segment.  All memory
references by default are relative to the data segment.  The author
needs to explicitly set this up to point to video memory, so that they
can write to it.  DS is set to 0xB800.  Segments must start on 16 byte
boundaries, which is why the lower four bits are ignored.  This is how
a segment start address can be stored in a 16 bit register.  The MOV
uses the offset stored in BX, which is 0x15E.  This will then do the
MOV to 0xB800:0x15E, which is 0xB815E.

0
Reply MQ 7/30/2006 11:50:46 PM

On 30 Jul 2006 12:45:06 -0700, "Sam"  <spamtrap@crayne.org> wrote:

>I stumbled across the code below from emu8086. The final mov goes to
>video memory. Is there a map that defines where each video memory
>address is on a console screen? For instance, if I wanted to send a
>character to row 5, column 18, what video memory address would I use?
>
>Also, what is the purpose of "MOV AX, 0B800h" and "MOV DS, AX" in the
>code below? I don't understand why that is there? Thanks.
>
>ORG 100h           ; this directive required for a simple 1 segment
>.com program.
>MOV AX, 0B800h     ; set AX to hexadecimal value of B800h.
>MOV DS, AX         ; copy value of AX to DS.
>MOV CL, 'A'        ; set CL to ASCII code of 'A', it is 41h.
>MOV CH, 1101_1111b ; set CH to binary value.
>MOV BX, 15Eh       ; set BX to 15Eh.
>MOV [BX], CX       ; copy contents of CX to memory at B800:015E
>RET                ; returns to operating system.
>

Note that the above code and the advice in the other posts
are only for *text* mode.  Graphics modes don't have the simple
character, attribute, character, attribute layout of test modes.
Different graphics modes have different mappings to get from
data to pixels.  Most (EGA, VGA, and above) use A000 as the
start address.  Some modes use a byte or word to set the color
of each pixel, but many of the EGA and VGA modes use "bit
planes" where you write a byte with bits set for each of 8 adjacent
pixels.  Since color requires more than 1 bit per pixel, you have to
tell the E/VGA hardware what plane you are writing to.  With 4
planes you get 4 bits per color, which are use to select one ot
16 colors from a palette of all the possible colors, which depends on
the mode and the video capabilities.

This area can get *extremely* complicated, and everything changes
when you change modes. Oh, and with SVGA there were (are?) a
whole bunch of vendor-specific modes.  Despite the complexity of
Windows GDI, it really makes life a lot easier compared to the old
mess.

Best regards,





Bob Masta
dqatechATdaqartaDOTcom
 
            D A Q A R T A
Data AcQuisition And Real-Time Analysis
           www.daqarta.com
Home of DaqGen, the FREEWARE signal generator

0
Reply NoSpam 7/31/2006 11:58:27 AM

3 Replies
191 Views

(page loaded in 0.034 seconds)

Similiar Articles:













7/15/2012 7:14:52 AM


Reply: