OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 1:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 12:12 am 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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!

_________________
phillid - Newbie-ish operating system developer with a toy OS on the main burner


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 12:39 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 4:10 am 
Offline
Member
Member

Joined: Wed Oct 31, 2007 9:09 am
Posts: 1385
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


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 4:10 pm 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


_________________
phillid - Newbie-ish operating system developer with a toy OS on the main burner


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 4:43 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 7:14 pm 
Offline
Member
Member

Joined: Thu Aug 12, 2010 7:25 am
Posts: 99
correct me if im wrong, but using mmio to access video memory is undocumented method. Only avaiable option is int 10.


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 7:17 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
It is heavily documented if you know where to look. Seriously.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 8:24 pm 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
And it is far faster than Int 10h.

_________________
Programming is not about using a language to solve a problem, it's about using logic to find a solution !


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 9:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 9:38 pm 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
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.

_________________
Programming is not about using a language to solve a problem, it's about using logic to find a solution !


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Thu Mar 10, 2011 9:58 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Mon Mar 14, 2011 10:48 pm 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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)

_________________
phillid - Newbie-ish operating system developer with a toy OS on the main burner


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Tue Mar 15, 2011 1:09 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
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.

_________________
Programming is not about using a language to solve a problem, it's about using logic to find a solution !


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Mon Mar 21, 2011 8:06 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 09, 2011 2:21 am
Posts: 87
Location: Raipur, India
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


Top
 Profile  
 
 Post subject: Re: ClrScn Funtion not working
PostPosted: Mon Mar 21, 2011 9:45 am 
Offline
Member
Member

Joined: Wed Oct 31, 2007 9:09 am
Posts: 1385
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: TYDQSoft and 11 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group