Help again with printing a message in protected mode

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

Help again with printing a message in protected mode

Post by beyondsociety »

[attachment deleted by admin]
beyondsociety

Re:Help again with printing a message in protected mode

Post by beyondsociety »

How come nobodys replying to my post?
dronkit

Re:Help again with printing a message in protected mode

Post by dronkit »

I have several theories:
1.- because you already post it like three or four times (at least)...and you *got* answers, including code.

2.- on the other hand, posting the code every time you can't do anything sounds too lacy for an os coder.

3.- you asked "How come nobodys replying to my post?" twice.

4.- You start several threads in this forum with the same question.

don't be sad. people has a lot of more important things to do nowadays with all this globalization, internet and stuff ;)
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

I know the problem! I had the same one...

here is the fixed code ;D

hardware_move_cursor:

pushad ; Save registers

mov ebx,0
mov bl,[yposition] ; Get x offset

mov eax,0
mov al,[xposition]
mov edx,80
mul edx ; Calculate y offset

add ebx,eax ; Calculate index

; select to write low byte of index

mov al,0xf
mov dx,0x03d4
out dx,al

; write it

mov al,bl
mov dx,0x03d5
out dx,al

; select to write high byte of index

mov al,0xe
mov dx,0x03d4
out dx,al

; write it

mov al,bh
mov dx,0x03d5
out dx,al

popad ; restore registers

ret

tell me If i made a bug
beyondsociety

Re:Help again with printing a message in protected mode

Post by beyondsociety »

Thanks for the help tom, but I still have a problem with it. I now have no cursor at all. What could be the problem, I am using what you posted?
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

i'll get the C code to you later...I know C more than ASM, so i'll let you translate it ;)
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

int cur_cursorX, cur_cursorY;

static unsigned scrwidth, scrheight;

typedef unsigned char UCHAR;
typedef unsigned short USHORT;

void start_textmode()
{
   cur_cursorX = 0;
   cur_cursorY = 0;

   scrwidth = 80;
   scrheight = 25;
}
void gotoxy( int x, int y )
{
USHORT   position = ( y * scrwidth + x );

// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( UCHAR ) ( position & 0xFF ) );

// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
   outportb( 0x3D5, ( UCHAR ) ( ( position >> 8 ) & 0xFF ) );

   cur_cursorX = x;
   cur_cursorY = y;
}
beyondsociety

Re:Help again with printing a message in protected mode

Post by beyondsociety »

Does anybody know how to translate this c code into assembly language?

If you do, then please translate it for me in intel syntax assembly.
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

here:

outportb:
   push %ebp
   mov %esp,%ebp
   mov 0x8(%ebp),%edx
   mov 0xc(%ebp),%eax
   out %al,(%dx)
   pop %ebp
   ret
   lea 0x0(%esi,1),%esi

init:
   push %ebp
   mov %esp,%ebp
   movl $0x0,0x0

   movl $0x0,0x0

   movl $0x0,0x0

movl $0x0,0x0

   pop %ebp
   ret
   lea 0x0(%esi),%esi

gotoxy:
   push %ebp
   mov %esp,%ebp
   sub $0x8,%esp
   mov 0xc(%ebp),%eax
   imul 0x0,%eax
   add 0x8(%ebp),%eax
   mov %ax,0xfffffffe(%ebp)
   sub $0x8,%esp
   push $0xf
   push $0x3d4
   call 82 <gotoxy+0x22>
   add $0x10,%esp
   sub $0x8,%esp
   mov $0x0,%eax
   mov 0xfffffffe(%ebp),%al
   push %eax
   push $0x3d5
   call 9b <gotoxy+0x3b>
   add $0x10,%esp
   sub $0x8,%esp
   push $0xe
   push $0x3d4
   call ad <gotoxy+0x4d>
   add $0x10,%esp
   sub $0x8,%esp
   mov 0xfffffffe(%ebp),%ax
   shr $0x8,%ax
   and $0xff,%eax
   push %eax
   push $0x3d5
   call cb <gotoxy+0x6b>
   add $0x10,%esp
   mov 0x8(%ebp),%eax
   mov %eax,0x0
   mov 0xc(%ebp),%eax
   mov %eax,0x0
   mov %ebp,%esp
   pop %ebp
   ret
   lea 0x0(%esi),%esi
   lea 0x0(%edi,1),%edi
use as to assemble a object file to link into you NASM object file. It was hard enough to make it GAS syntax and I don't know a way to translate it to INTEL
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

outportb:
; just use out

init:

cur_cursorX db 0
cur_cursorX db 0
scrwidth dw 80
scwheight dw 25

gotoxy:

pushad ; Save registers

mov ebx,0
mov bl,[cur_cursorX] ; Get x offset

mov eax,0
mov al,[cur_cursorY]; !!!!!!!!!!!!!!!you know asm more so YOU do a y * scrwidth + x
mov edx,80
mul edx ; Calculate y offset

add ebx,eax ; Calculate index

; select to write low byte of index

mov al,0xf
mov dx,0x03d4
out dx,al

; write it

mov al,bl
mov dx,0x03d5
out dx,al

; select to write high byte of index

mov al,0xe
mov dx,0x03d4
out dx,al

; write it

mov al,bh
mov dx,0x03d5
out dx,al

popad ; restore registers

ret
Tom

Re:Help again with printing a message in protected mode

Post by Tom »

tell me if that helps
beyondsociety

Re:Help again with printing a message in protected mode

Post by beyondsociety »

I never tried it. I got the original code to work. I re-wrote my bootsector and now the original code works.

I don't know what was happening. It might of been a compatibliity issue.

Thanks for the help!
Schol-R-LEA

Re:Help again with printing a message in protected mode

Post by Schol-R-LEA »

BTW, there's one thing your code doesn't address yet: scrolling. However, at this point it probably is a bit early to worry about that.
Post Reply