ClrScn Funtion not working

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

ClrScn Funtion not working

Post by phillid »

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: Select all

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

Re: ClrScn Funtion not working

Post by Brendan »

Hi,

Code: Select all

	mov	cx, 0x1920	; # of chars on the screen (80x24)
0x1920 = 6432, which is completely different to 1920.

Code: Select all

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

Re: ClrScn Funtion not working

Post by jal »

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

Re: ClrScn Funtion not working

Post by phillid »

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: Select all

; -----------------------------------------------------
; 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ClrScn Funtion not working

Post by Combuster »

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 ]
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

Re: ClrScn Funtion not working

Post by a5498828 »

correct me if im wrong, but using mmio to access video memory is undocumented method. Only avaiable option is int 10.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: ClrScn Funtion not working

Post by neon »

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();}
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: ClrScn Funtion not working

Post by Chandra »

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

Re: ClrScn Funtion not working

Post by Brendan »

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

Re: ClrScn Funtion not working

Post by Chandra »

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

Re: ClrScn Funtion not working

Post by Brendan »

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

Re: ClrScn Funtion not working

Post by phillid »

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

Re: ClrScn Funtion not working

Post by Chandra »

All you need, to reset the cursor, is this:

Code: Select all

// 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 !
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: ClrScn Funtion not working

Post by trinopoty »

You have to replace

Code: Select all

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: Select all

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

Re: ClrScn Funtion not working

Post by jal »

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
Post Reply