Page 2 of 2

Re:New Problem with Screen

Posted: Mon Sep 16, 2002 6:50 pm
by PlayOS
Hi,

I am not sure what you thought I meant, however I have written this function in assembly and you will need to assemble it with NASM and then link it in with your c code, you will then need to declare it as 'extern' in any c file you want to use it in, the prototype will be this

   extern void ScrollScreen(int);
   
and you will call it as a normal c function like so,

   ScroolScreen( 5 );

this will scroll the display up by 5 lines. If you do not know how to link assembly code with c code, then you will be best to drop a line to Tim Robinson, he is a moderator of this site and he will be able to tell you how to do this properly. http://www.mega-tokyo.com/forum/index.p ... e;user=Tim just send him a private message and ask him.

; =======================================
; void ScrollScreen(int);
; =======================================
_ScrollScreen:
   push   ebp
   mov      ebp, esp
   mov      eax, dword [ebp + 8]
   mov      cx, 160
   mul      cx
   mov      ebx, 0xb8000
   add      ebx, eax
   mov      ecx, 0xb8000
.ScrollLoop:
   mov      eax, dword [ebx]
   mov      dword [ecx], eax
   add      ebx, 4
   add      ecx, 4
   cmp      ebx, 0xb8fa0
   je      .ScrollDone
   jmp      .ScrollLoop
.ScrollDone:
   mov      dword [ecx], 0x00070007
   add      ecx, 4
   cmp      ecx, 0xb8fa0
   jl      .ScrollDone
   pop      ebp
   ret

NOTE: C will remove any parameters from the stack automatically, if you call this from within another assembly file it will leave the parameters on the stack, to use this function from another assembly file simply change the

ret

instruction to

ret 4

and it will work as expected. Or you can 'pop' it off after the call like C does.

Hope this helps.

Re:New Problem with Screen

Posted: Tue Sep 17, 2002 9:09 am
by Matze2002
Hi,
can i write this function in my C File (with inline asm() ) ?

I think there is a error in the function, in the header of the function ( void Scrollscreen(int) ) there is no name for the lines. There is only int.

mfg
Matze

Re:New Problem with Screen

Posted: Tue Sep 17, 2002 9:32 am
by Whatever5k
No, it's no inline asm. You are supposed to write this text in a separate asm-file (i.e. scroll.asm), compile it with nasm, and link it with your other objects...

Re:New Problem with Screen

Posted: Tue Sep 17, 2002 9:33 am
by Whatever5k
By the way, instead of using this function, you could use memcpy() to move all lines one line up, and memset() to clear the last line. This is probably better since you can use memcpy() and memset() not only for screen scrolling...

Re:New Problem with Screen

Posted: Tue Sep 17, 2002 10:07 am
by Matze2003
Hi,
where can i find the function memcpy() ?
header files ???

Matze

Re:New Problem with Screen

Posted: Tue Sep 17, 2002 11:59 pm
by Pype.Clicker
Whatever5k wrote: By the way, instead of using this function, you could use memcpy() to move all lines one line up, and memset() to clear the last line. This is probably better since you can use memcpy() and memset() not only for screen scrolling...
Keep in mind that memcpy can't handle all the cases of overlapping areas! this is probably not a problem when scrolling down, but if you want to scroll up ...

Re:New Problem with Screen

Posted: Wed Sep 18, 2002 5:50 am
by Whatever5k
That's right, then you'll have to use memmove()...

Matze: You'll need to write your own memcpy() function...
This is pretty easy...

Re:New Problem with Screen

Posted: Wed Sep 18, 2002 11:57 am
by Matze2002
Hi,
i have found the source to the function (memcpy).
How must i use this function ?
Does anyone have a example source code for me.

matze

Re:New Problem with Screen

Posted: Thu Sep 19, 2002 1:27 am
by Pype.Clicker
Matze2002 wrote: Hi,
i have found the source to the function (memcpy).
How must i use this function ?
Does anyone have a example source code for me.

matze
hmmm ... do not take an offense, but if you plan to write an O.S., i think you should better write your own memcpy function...

Re:New Problem with Screen

Posted: Sat Sep 21, 2002 10:23 am
by Matze2002
Hi,
i have write my own function to scroll down. The problem is, that the function works 5 times and then the system reboots. Here is the function:


void movedata(unsigned ssel, unsigned s, unsigned dsel, unsigned d, unsigned len)
{
asm(
"pushw %%ds\n"
"pushw %%ax\n"
"popw %%ds\n"
"pushw %%es\n"
"pushw %%bx\n"
"popw %%es\n"
"moveloop: \n"
"lodsb \n"
"stosb \n"
"loop moveloop\n"
"popw %%es\n"
"popw %%ds"
::"a" (ssel), "b" (dsel), "D" (d), "S" (s), "c" (len));
}

void scrollscreen()
{
BYTE i;
movedata(SYS_SCREEN_SEL, (unsigned)screen.resx*4, SYS_SCREEN_SEL, screen.resx*2, (screen.resy-2) * screen.resx * 2);
for(i = 0; i < screen.resx; i++)
      {
         putchar(i, screen.resy, ' ');
         
      }
screen.y--;
setCursor(screen.x, screen.y);
}