flat assembler
Message board for the users of flat assembler.

Index > OS Construction > coloured print problem

Author
Thread Post new topic Reply to topic
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
hi i am in 16bit realmode, and in my kernel

Quote:

INT 10 - VIDEO - WRITE STRING (AT and later,EGA)
AH = 13h
AL = write mode
bit 0: update cursor after writing
bit 1: string contains alternating characters and attributes
bits 2-7: reserved (0)
BH = page number
BL = attribute if string contains only characters
CX = number of characters in string
DH,DL = row,column at which to start writing
ES:BP -> string to write


requires row/column, but will update it so..

Quote:

INT 10 - VIDEO - GET CURSOR POSITION AND SIZE
AH = 03h
BH = page number
0-3 in modes 2&3
0-7 in modes 0&1
0 in graphics modes
Return:
AX = 0000h (Phoenix BIOS)
CH = start scan line
CL = end scan line
DH = row (00h is top)
DL = column (00h is left)


so from that i made this procedure
Code:
;print coloured string, bp = offset of buffer (doesn't need to be zero terminated), cx = string length, bl = colour
@printcstr:
    mov ah, $03  ;service $03 (get cursor position and size)
    xor bh, bh   ;page 00
    int $10

    ;dh now holds the current row
    ;dl now holds the current column
    mov ah, $13  ;service $13 (write string)
    xor al, al   ;update cursor
    xor bh, bh   ;page 00
    int $10

    retn
;--- 
    


i am properly calling it
Code:
mov bp, _somebuf
mov bl, $code
mov cx, _somebuf.size
call @printcstr  
    


it will print a string, but will not update the cursor position, what am i doing wrong? (if i print a second it will just overwrite from 0, 0 again)

_________________
redghost.ca
Post 06 Jan 2006, 22:55
View user's profile Send private message AIM Address MSN Messenger Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
You should manually update cursor position with INT 0x10/AH=2
Post 06 Jan 2006, 23:49
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
Try this out (just as an example, don't learn to write code from it Smile ):
Code:
format MZ

push cs cs
pop  es ds
mov  si,aaaa
mov  al,0x40
call draw_text
mov  ax,0x4C00
int  0x21

aaaa db 'mike.dld',0

cur_pos:
  curx db 0
  cury db 0

; ES:SI - text to draw (null-terminated)
; AL - attribute (color)
draw_text:
        pusha
        mov     dl,al
        mov     dh,0
        cld
    @@: lodsb
        cmp     al,0
        je      @f
        push    dx si ds
        cmp     al,8
        jne     .lp0
        dec     [curx]
        jmp     .lp2
  .lp0: cmp     al,10
        jne     .lp1
        mov     [curx],0
        inc     [cury]
        jmp     .lp2
  .lp1: cmp     al,13
        je      .lp3
        mov     bx,dx
        mov     ah,9
        mov     cx,1
        int     0x10
        inc     [curx]
  .lp2: mov     ah,2
        mov     bh,0
        mov     dx,[cur_pos]
        int     0x10
  .lp3: pop     ds si dx
        jmp     @b
    @@: popa
        ret    
Post 06 Jan 2006, 23:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
thanks mike, but the problem is fixed, and it updates cursor for me

there was two problems

A)

it says to set bit 0 (index 0), for move cursor, not actually set the register to 0 (thanks daverr from fasm irc)

B)

since service $03 of int $10 returns with CL/CH i obviously should have thought it would modify cx (which contains the string length) (doh, cant believe i overlooked that)

working code:
Code:
;print coloured string, bp = offset of buffer (doesn't need to be zero terminated), cx = string length, bl = colour
@printcstr:
    push cx

    mov ah, $03  ;service $03 (get cursor position and size)
    xor bh, bh   ;page 00
    int $10

    pop cx

    ;dh now holds the current row
    ;dl now holds the current column
    mov ah, $13  ;service $13 (write string)
    xor al, al   ;clear al
    or al, $01   ;set the first bit index ($01), so it moves the cursor
    xor bh, bh   ;page 00
    int $10

    retn
;---    
    

_________________
redghost.ca
Post 07 Jan 2006, 00:40
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.