News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Guidance with 16bit MASM in directly write to video RAM using int 21h

Started by Shayaan_Mustafa, June 08, 2014, 01:48:13 AM

Previous topic - Next topic

Shayaan_Mustafa

Hello experts,

It is my first post to the forum.

I am very fond of Assembly Language and we have taught in university.
My problem is, I want a book or any document in which I could find information how to write directly to the VRAM using int 21h.

I am using MASM and Windows XP.

Here is the sample program about which I am asking:

.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


This program will write N directly to the VRAM, as our teacher said. But he never told us where to find more examples of VRAM access with int 21h. He recommended us two books, kip irvine book and the intel mircoprocessors by berry b. bray. But in both books I didn't see any example which my teacher had done in the computer laboratory.

I need your help guys.

Thank you all

ROBOSPOOK

Shayaan,
  You might try Ralph Browns Interrupt list.  I don't have the URL for it but you can use google to find it. If you cant find it let me know I will get a URL for you.  Also you can try to find a book called "Undocumented DOS" .. by.. of course Ralph Brown.

Hope this helps

ROBO

Wannabe

Quote from: Shayaan_Mustafa on June 08, 2014, 01:48:13 AM
Hello experts,

It is my first post to the forum.

I am very fond of Assembly Language and we have taught in university.
My problem is, I want a book or any document in which I could find information how to write directly to the VRAM using int 21h.

I am using MASM and Windows XP.

Here is the sample program about which I am asking:

.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


This program will write N directly to the VRAM, as our teacher said. But he never told us where to find more examples of VRAM access with int 21h. He recommended us two books, kip irvine book and the intel mircoprocessors by berry b. bray. But in both books I didn't see any example which my teacher had done in the computer laboratory.

I need your help guys.

Thank you all

Take a look here:
http://fleder44.net/312/notes/18Graphics/index.html
Basically ah=4ch,INT 21h is just a dos interrupt which in your case ends your program.
The write to VRAM happen just before that line.

Gunther

Hi Mustafa,

your application must first set the appropriate video mode. The link which Wannabe provided is a good starting point. For more sophisticated examples, check your local library for: Richard Wilton: Programmer's Guide to PC Video Systems. Second Edition. Microsoft Press, 1994. ISBN: 1-55615-641-3. If that book isn't available for you, try that link as a substitute. Please check out the topic: Synopsis for free book.

And welcome to the forum.

Gunther
You have to know the facts before you can distort them.

dedndave

that method also works for graphics modes
in fact, i used to use it for video mode 13h (256x200, 256 color), quite often

you can go beyond that, and use direct access for other graphics modes, as well
however, you must get into flipping memory pages of the graphics adapter

with some knowledge of VGA adapters, you can program unsupported or "X modes"
Michael Abrash was, i believe, the first to publish articles on "X" video modes, in his Black Book

http://twimgs.com/ddj/abrashblackbook/gpbb47.pdf
http://twimgs.com/ddj/abrashblackbook/gpbb48.pdf
http://twimgs.com/ddj/abrashblackbook/gpbb49.pdf

GameDev tutorial

http://web.archive.org/web/20070123192523/http://www.gamedev.net/reference/articles/article356.asp

Shayaan_Mustafa

Thank you for replies.

@ROBOSPOOK
I have searched Ralph Brown's interrupt list and seen. But it is not solution for what I am looking. By the way, is this the book are you talking about? http://www.amazon.ca/Undocumented-DOS-Programmers-Functions-Structures/dp/0201570645

Wannabe
You have given a very good link. It has basics. We have not been taught with all these basics. Just our teacher wrote a programming on the white board with marker and we type in the computer and compiled it and run it.
But I want more examples of it. Let me start here. I want to learn from here.

Guys, I want to learn this video programming from now and here.

Let's take this example.


.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


OK so let us start.
I know when access to data segment then we use ds, for example
mov ax, @data
mov ds, ax

but here we used es in the second line of the .code
Why?

FORTRANS

Quote from: Shayaan_Mustafa on June 08, 2014, 07:17:46 AM
OK so let us start.
I know when access to data segment then we use ds, for example
mov ax, @data
mov ds, ax

but here we used es in the second line of the .code
Why?

Hi,

   The string instructions like STOSW use the ES segment as
part of the destination (storing a word at the address specified
in ES:DI).  That is hard-wired into the instruction.  Even if you
were using a standard MOV, it is useful to use a ES segment
prefix as that leaves DS to point to your data.

Regards,

Steve N.

dedndave

the video buffer segment generally lies somewhere between 0A000h and 0C000h
it depends on the video card and video mode

for most graphics cards and modes
0B800h is the segment for text modes
0B000h is the segment for graphics modes

so, first, you set the video mode with INT 10h, AH = 0
i think when you start out, you are in mode 3
but, let's say we want mode 7
        mov     al,7
        mov     ah,0
        int     10h

that can be simplified to
        mov     ax,7
        int     10h


because mode 7 is a text mode, the buffer will start at B800:0000

MichaelW

I'm assuming that the target here is the default 16-color alphanumeric (text) mode.

As far as I can tell Ron Thomas' book deals with the graphics modes, and not the alphanumeric modes.

An HTML version of Ralf Brown's Interrupt List (RBIL) is available here, and the full version here.

To successfully write directly to the buffer you must understand the layout. From the programmer's point of view the buffer is a linear array of character-attribute pairs, where the first byte of the pair specifies the character code and the second byte the character attribute. The character code bytes are always at even addresses and the attribute bytes at odd addresses. So the layout, starting at offset 0 in the buffer is CACACA...

And you must also understand the layout of the attribute byte, here detailed only for the default configuration:

Bit   Description
7    background intensity
6    background red component
5    background green component
4    background blue component
3    foreground intensity
2    foreground red component
1    foreground green component
0    foreground blue component 


So the layout for each attribute byte is IRGBIRGB.

Dave, under Windows XP you do start out in mode 3, but in my tests I had to do a mode set to get any output.

Well Microsoft, here's another nice mess you've gotten us into.

Shayaan_Mustafa

@FORTRANS
Sorry sir. I am really sorry but I have to say here English is not my native language. I realize you have talked about something good but didn't get fully what you tried to say me. I will understand your words if you simplify your statement.

@dedndave
Sorry sir you too. I will find and I have many books in which I can study and find many many examples with int 10h to write VRAM. But I want to write directly to the VRAM without BIOS interrupt (int 10h). I didn't find any example without this that's why I searched and find masm32.com/board

@MichaelW
Thank you sir. I understand that buffer has character and attribute.
I know about the layout. Kindly, go ahead and teach me step by step.

Gunther

Dave,

Quote from: dedndave on June 08, 2014, 07:35:41 AM
for most graphics cards and modes
0B800h is the segment for text modes
0B000h is the segment for graphics modes

in most cases A000h is the segment address of the VGA graphics buffer.

Gunther
You have to know the facts before you can distort them.

dedndave

yah, that's correct, Gunther
0B000h is used for the CGA graphics modes
it's also used for mode 13h, as i remember

dedndave


hutch--

Long ago there was a trick if your DOS memory was not large enough to perform certain tasks, the one I had in mind was Norton Speedisk on what was then large drives. You ran it only in text mode then set the himem.sys option to use the full VGA video address range from A000h to B7FFh and then you could run Speedisk on larger drives. I remember chasing up all sorts of miniature drivers and the like to maximise DOS real mode memory.  :P

dedndave

i remember   :lol:

we used to jump through all sorts of hoops to squeeze the smallest improvement out of the machine
the V20 processor was about 12% faster than an 8086 with the same clock

i had a Juko motherboard that had a 10 MHz V20 (i even bought a 10 MHz 8087)
it boasted 1 Mb of RAM - you could page flip part of it
i also had a 2 Mb LIM memory board
i wrote a specialized device driver that treated the combined extra RAM as a single RAMDRIVE
at boot-time, i copied the most common external DOS commands and my favorite EXE's into the RAMDRIVE