Jump to content
  • Advertisement
Sign in to follow this  
directNoob

[asm 80x86] Clear Screen.

This topic is 4001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I tryed find a propper way to clear the screen on the console. But, unfortunately, I havent. I tryed some code but I cant handle it. It is supposed to clear a screen within a c++ console app, so I put the code into the __asm section. And this goes like this. (I writes directly onto the vram.)

void cls( void )
{
	__asm
	{
		push ax
		push es
		push di

		mov ax,0
		mov es,ax
		mov di,0

		mov ax,0B800h 	; segment of video buffer
		mov es,ax 	; put this into es
		xor di,di 	; clear di, ES:DI points to video memory
		mov ah,4 	; attribute - red
		mov al,'G' 	; character to put there
		mov cx,4000 	; amount of times to put it there 
		cld 		; direction - forwards
		rep stosw 	; output character at ES:[DI]

		pop di
		pop es
		pop ax
	}
}

Here the code is from the internet and should draw G's onto the screen! But I get a mem violation at the second mov es, ax. I need some help please. This code should work on the x86 platform. Much thanks Alex

Share this post


Link to post
Share on other sites
Advertisement
You're OS may not be allowing you to access vram directly. Modern OS's run your programs in protected mode, so you would be accessing virtual memory, not physical memory.

Share this post


Link to post
Share on other sites
I doubt that code will work. It looks like it assumes you are running in DOS mode (which is bot the same as running a console program). Have you tried something like this. First result from a google of "winapi clear console".

Share this post


Link to post
Share on other sites
Hi, and thanks.

I dont want to use os specific functions like System( "cls" ).
This wont work under other compilers or OSs like windows.

So you havent any idea how this could work.

I mean, this can be a hard task to achieve, it is simply accessing
the vram and override it completely. But my asm knowledge isnt as strong to
handle this task.
Or is there any chance to do it via a bios interrupt?
No, VRAM sounds better.

Alex

Share this post


Link to post
Share on other sites
Quote:
Original post by directNoob
Hi, and thanks.

I dont want to use os specific functions like System( "cls" ).
This wont work under other compilers or OSs like windows.

So you havent any idea how this could work.

I mean, this can be a hard task to achieve, it is simply accessing
the vram and override it completely. But my asm knowledge isnt as strong to
handle this task.
Or is there any chance to do it via a bios interrupt?
No, VRAM sounds better.

Alex


You are not writing an operating system, so you cannot write directly to video memory. You will have to go through the OS to do this.

Share this post


Link to post
Share on other sites
modern multitasking operating systems do not give you direct access to hardware resources (not their memory map, not their ports, not their dma channels, not their irq's.. nothing)

this is unconditional in these OS's .. if they let you slam around with the hardware directly, then you can easily destabilize the system

even with directx, which gives "direct" access to video memory, you have to alert the operating system that you are about to do so ("locking" the "surface") and then notify it when you are finished .. while your process is doing that, no other process may access that "surface" .. period .. unconditional

Share this post


Link to post
Share on other sites
But with an ordinary assembled program, I can access these regions...
You mean, I cant do it with __asm?

But what should I do then?

Alex

Share this post


Link to post
Share on other sites
Quote:
Original post by directNoob
@Rockoon1:

P.S.
I dont want to access memory on the graphics card but the vram from the dos console!
Because you wrote about dx...


It was a case-in-point.

Now onto your real issue..

..are you saying that in C you can access segment B800h?

A) exactly what C compiler is this that lets you use segment:offset pairs (is this a 16-bit compiler??)
B) exactly what OS are you doing this from

Share this post


Link to post
Share on other sites
I suspect that your "orginary assembled program" is 16-bit, but you are now trying to use a 32-bit C compiler to emit the same assembly statements .. it doesnt work like that at all

a 16-bit program runs under a real mode emulation layer
a 32-bit program runs under protected mode

segment:offset pairs like the ones you are using are for real (16-bit) mode only

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!