OSDev.org
https://forum.osdev.org/

ClrScn Funtion not working
https://forum.osdev.org/viewtopic.php?f=1&t=23283
Page 1 of 2

Author:  phillid [ Thu Mar 10, 2011 12:12 am ]
Post subject:  ClrScn Funtion not working

Hiya, again I have a problem with my OS. I have a ClrScn program that clears the screen by putting multiple spaces, 1920 (24 lines x 80 columns) to be exact, onto the screen.

Here's the code:
Code:
clearscr:
   push   cx
   push   es
   push   di
   push   ax
   mov   cx, 0xb800   ; set up the video memory segment
   mov   es, cx
   mov   di, 0      ; starting location (upper left corner)
   mov   ax, 0x0720   ; ASCII <space> character
   mov   cx, 0x1920   ; # of chars on the screen (80x24)
   rep   stosw
   mov   byte [cursor],0   ; move cursor to the top of the screen
   call   set_hwcursor
   pop   ax
   pop   di
   pop   es
   pop   cx
   ret


(set_hwcursor is a function that sets the hardware cursor)

However, it doesn't work. It clears the screen alright, but it doesn't reset the cursor's position, even though it calls set_hwcursor to reset it. I know that set_hwcursor works because I use it in my video driver.

Any help would be appreciated.

Thanks!

Author:  Brendan [ Thu Mar 10, 2011 12:39 am ]
Post subject:  Re: ClrScn Funtion not working

Hi,

Code:
   mov   cx, 0x1920   ; # of chars on the screen (80x24)


0x1920 = 6432, which is completely different to 1920.

Code:
   mov   byte [cursor],0   ; move cursor to the top of the screen


How can the cursor (both the row and the column) fit in a single byte?


Cheers,

Brendan

Author:  jal [ Thu Mar 10, 2011 4:10 am ]
Post subject:  Re: ClrScn Funtion not working

phillid wrote:
However, it doesn't work. It clears the screen alright, but it doesn't reset the cursor's position


Let me get this straight: you name your post "ClrScn Funtion not working", while clearing the screen works fine, then tell us it's the positioning of the cursor that goes wrong, while not showing the cursor positioning code but instead the, working, clear screen code????? Jeez...


JAL

Author:  phillid [ Thu Mar 10, 2011 4:10 pm ]
Post subject:  Re: ClrScn Funtion not working

Sorry, here's the code for the cursor positioning, which by the way I didn't write, I'm just using it until I write my own.

Code:
; -----------------------------------------------------
; Set the hardware cursor position
;


set_hwcursor:
   push   ax
   push   dx

   mov   dx, 0x3D4

   cli         ; disable interrupts
   mov   al, 14      ; register 14-15 set the cursor pos
   out   dx, al      ; video controller

   mov   ax, [cursor]   ; get our s/w cursor position
   shr   ax, 1      ; / by 2 to get cursor position
   shr   ax, 8      ; get the high byte
;   and   ax, 0xFF
   add   dx, 1
   out   dx, al

   mov   al, 15
   sub   dx, 1
   out   dx, al

   mov   ax, [cursor]
   shr   ax, 1      ; / by 2 to get cursor position
;   and   ax, 0xFF   ; get the low byte
   add   dx, 1
   out   dx, al
   sti

   pop   dx
   pop   ax
   ret


Author:  Combuster [ Thu Mar 10, 2011 4:43 pm ]
Post subject:  Re: ClrScn Funtion not working

That's what you get for stealing code and not using it correctly. [cursor] is 16 bits, you write 8 which is wrong as Brendan already guessed.

Author:  a5498828 [ Thu Mar 10, 2011 7:14 pm ]
Post subject:  Re: ClrScn Funtion not working

correct me if im wrong, but using mmio to access video memory is undocumented method. Only avaiable option is int 10.

Author:  neon [ Thu Mar 10, 2011 7:17 pm ]
Post subject:  Re: ClrScn Funtion not working

It is heavily documented if you know where to look. Seriously.

Author:  Chandra [ Thu Mar 10, 2011 8:24 pm ]
Post subject:  Re: ClrScn Funtion not working

And it is far faster than Int 10h.

Author:  Brendan [ Thu Mar 10, 2011 9:00 pm ]
Post subject:  Re: ClrScn Funtion not working

Hi,

neon wrote:
It is heavily documented if you know where to look. Seriously.


It's heavily documented, if you're willing to make the assumption that the hardware is VGA compatible (rather than just having "VGA compatible int 0x10" and no hardware compatibility).

I look forward to the day that video card manufacturers are free to implement nice, clean/elegant hardware; without any market pressure to mangle their design to emulate obsolete crud. Unfortunately, getting rid of the crusty old crud is very difficult for hardware manufacturers to do, especially when people are still writing new software that relies on compatibility with something that hasn't made sense for a few decades. ;)


Cheers,

Brendan

Author:  Chandra [ Thu Mar 10, 2011 9:38 pm ]
Post subject:  Re: ClrScn Funtion not working

Brendan wrote:
It's heavily documented, if you're willing to make the assumption that the hardware is VGA compatible (rather than just having "VGA compatible int 0x10" and no hardware compatibility).

I look forward to the day that video card manufacturers are free to implement nice, clean/elegant hardware; without any market pressure to mangle their design to emulate obsolete crud. Unfortunately, getting rid of the crusty old crud is very difficult for hardware manufacturers to do, especially when people are still writing new software that relies on compatibility with something that hasn't made sense for a few decades. ;)


Cheers,

Brendan

In those days, BIOS manufacturers too will start dropping VGA support and probably implement some new standard.

Author:  Brendan [ Thu Mar 10, 2011 9:58 pm ]
Post subject:  Re: ClrScn Funtion not working

Hi,

Chandra wrote:
In those days, BIOS manufacturers too will start dropping VGA support and probably implement some new standard.


I'm still hoping that one day everyone will switch to something like UEFI, and everyone can get rid of a lot of stupid legacy crud (A20 gate!) after that. Then we'd only need to worry about stupid modern crud... :)


Cheers,

Brendan

Author:  phillid [ Mon Mar 14, 2011 10:48 pm ]
Post subject:  Re: ClrScn Funtion not working

Combuster wrote:
That's what you get for stealing code and not using it correctly. [cursor] is 16 bits, you write 8 which is wrong as Brendan already guessed.

I didn't steal the code, it was givien to me with the intentions of temporary use.
Noob question: how would I write 16 bits to [cursor]? (this could have been said in an earlier post)

Author:  Chandra [ Tue Mar 15, 2011 1:09 am ]
Post subject:  Re: ClrScn Funtion not working

All you need, to reset the cursor, is this:
Code:
// Set cursor position to 0,0
  out(0x3D4, 14);
  out(0x3D5, 0);
  out(0x3D4, 15);
  out(0x3D5, 0);

I'm not going to give you an assembly code. Just dig your way out.

Author:  trinopoty [ Mon Mar 21, 2011 8:06 am ]
Post subject:  Re: ClrScn Funtion not working

You have to replace
Code:
clearscr:
   push   cx
   push   es
   push   di
   push   ax
   mov   cx, 0xb800   ; set up the video memory segment
   mov   es, cx
   mov   di, 0      ; starting location (upper left corner)
   mov   ax, 0x0720   ; ASCII <space> character
   mov   cx, 0x1920   ; # of chars on the screen (80x24)
   rep   stosw
   mov   byte [cursor],0   ; move cursor to the top of the screen
   call   set_hwcursor
   pop   ax
   pop   di
   pop   es
   pop   cx
   ret


with

Code:
clearscr:
   push   cx
   push   es
   push   di
   push   ax
   mov   cx, 0xb800   ; set up the video memory segment
   mov   es, cx
   mov   di, 0      ; starting location (upper left corner)
   mov   ax, 0x0720   ; ASCII <space> character
   mov   cx, 0x0780   ; # of chars on the screen (80x24)
   rep   stosw
   mov   word [cursor], 0   ; move cursor to the top of the screen
   call   set_hwcursor
   pop   ax
   pop   di
   pop   es
   pop   cx
   ret

Author:  jal [ Mon Mar 21, 2011 9:45 am ]
Post subject:  Re: ClrScn Funtion not working

trinopoty wrote:
You have to replace [some code] with [some code]


Apart from the fact that there's only a single change, in a single line that could easily have been communicated in a better format than a copy/paste of an entire routine with one change, this doesn't teach anyone anything.


JAL

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/