New Problem with Screen
-
PlayOS
Re:New Problem with Screen
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.
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.
-
Matze2002
Re:New Problem with Screen
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
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
-
Whatever5k
Re:New Problem with Screen
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...
-
Whatever5k
Re:New Problem with Screen
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...
-
Matze2003
Re:New Problem with Screen
Hi,
where can i find the function memcpy() ?
header files ???
Matze
where can i find the function memcpy() ?
header files ???
Matze
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:New Problem with Screen
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 ...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...
-
Whatever5k
Re:New Problem with Screen
That's right, then you'll have to use memmove()...
Matze: You'll need to write your own memcpy() function...
This is pretty easy...
Matze: You'll need to write your own memcpy() function...
This is pretty easy...
-
Matze2002
Re:New Problem with Screen
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
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
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:New Problem with Screen
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...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
-
Matze2002
Re:New Problem with Screen
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);
}
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);
}