Page 1 of 2

ClrScn Funtion not working

Posted: Thu Mar 10, 2011 12:12 am
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!

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 12:39 am
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

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 4:10 am
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

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 4:10 pm
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


Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 4:43 pm
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.

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 7:14 pm
by a5498828
correct me if im wrong, but using mmio to access video memory is undocumented method. Only avaiable option is int 10.

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 7:17 pm
by neon
It is heavily documented if you know where to look. Seriously.

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 8:24 pm
by Chandra
And it is far faster than Int 10h.

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 9:00 pm
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

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 9:38 pm
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.

Re: ClrScn Funtion not working

Posted: Thu Mar 10, 2011 9:58 pm
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

Re: ClrScn Funtion not working

Posted: Mon Mar 14, 2011 10:48 pm
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)

Re: ClrScn Funtion not working

Posted: Tue Mar 15, 2011 1:09 am
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.

Re: ClrScn Funtion not working

Posted: Mon Mar 21, 2011 8:06 am
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

Re: ClrScn Funtion not working

Posted: Mon Mar 21, 2011 9:45 am
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