flat assembler
Message board for the users of flat assembler.

Index > DOS > problem with a text displaying code....

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 06 Aug 2004, 17:40
I found this code on the forum somewhere....the problem is that it adds a space after the string you use. how would that be fixed

Code:
ORG 100H

TX = 80

; Some color names to use instead of raw numbers
BLACK = 0
BLUE = 1
GREEN = 2
PURPLE = 3
RED = 4
CYAN = 5
BROWN = 6
WHITE = 7
GREY = 8
BRIGHTBLUE = 9
BRIGHTGREEN = 10
BRIGHTPURPLE = 11
BRIGHTRED = 12
BRIGHTCYAN = 13
BRIGHTBROWN = 14
BRIGHTWHITE = 15

virtual at 0
   write:
        .x        dw   ?
        .y        dw   ?
        .back   db   ?
        .fore    db   ?
        .str    dw  ?
end virtual

macro mov a, b {
   local c, d
     if b eqtype ''
      jmp d
      label c
      display b
      db b,0
      label d
        mov ax, c
        mov [write.str], ax
     else
      move a, b
    end if
}
move fix mov

macro write_string text, x, y, fg, bg {
   mov [write.x], x
   mov [write.y], y
   mov [write.back], bg
   mov [write.fore], fg
   mov [write.str], text
   call WriteStr
}

push cs
pop ds
push $b800      ; Set ES here, unless you need to alter it later on
pop es          ; It'll save a little time when you call WriteStr

mov ax,03h
int 10h

   mov [write.x], 10
   mov [write.y], 10
   mov [write.back], GREY
   mov [write.fore], BLUE
   mov [write.str], 'this is a test'
   call WriteStr
; Or this way:
;  write_str 'this is a test', 10, 10, GREY, BLUE

xor ax,ax
int 16h
int 20h

WriteStr:
        mov   ax, [write.y]       ; THIS ROUTINE WAS FIXED
        dec   ax            ; THE OFFSET ONSCREEN
        mov   cx, TX        ; WAS CALCULATED WRONG/
        mul   cx            ; NOW THIS IS OK !
        add   ax, [write.x]       ;
        shl   ax, 1         ; optimised
        mov   di, ax

        mov   ah, [write.back]
        mov   al, [write.fore]
        shl   ah, 4
        or    ah, al

        mov   si, [write.str]
      Continue:
        mov al, byte [si]
        stosw
        inc si
        cmp al, 0
        jnz Continue
ret
    

_________________
----> * <---- My star, won HERE
Post 06 Aug 2004, 17:40
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 06 Aug 2004, 18:08
Easy enough. Just change the end of the WriteStr routine to:

Code:
      Continue:
        mov al, byte [si]
        stosw
        inc si
        cmp byte [si], 0
        jnz Continue
ret               
    


And all will be well Smile
Post 06 Aug 2004, 18:08
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 06 Aug 2004, 18:25
Thanks! Smile
Post 06 Aug 2004, 18:25
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 04 Sep 2004, 21:55
I give a sample code on how to write to screen by writing to memory mapped port @ $A000 segment

Code:
writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push ds
push si
push es
push di
push $b800
pop es
mov si,dx
mov ax,80
mul bh
xor bh,bh
add ax,bx
shl ax,1
mov di,ax
mov ah,cl
again:
lodsb
or al,al
jz done
stosw
cmp al,0
jmp again
done:
pop di
pop es
pop si
pop ds
ret
    


moderated myself ---


Last edited by Matrix on 29 Oct 2005, 01:37; edited 3 times in total
Post 04 Sep 2004, 21:55
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 05 Sep 2004, 01:21
windwakr wrote:
I found this code on the forum somewhere....the problem is that it adds a space after the string you use. how would that be fixed

Code:
ORG 100H

TX = 80

; Some color names to use instead of raw numbers
BLACK = 0
BLUE = 1
GREEN = 2
PURPLE = 3
RED = 4
CYAN = 5
BROWN = 6
WHITE = 7
GREY = 8
BRIGHTBLUE = 9
BRIGHTGREEN = 10
BRIGHTPURPLE = 11
BRIGHTRED = 12
BRIGHTCYAN = 13
BRIGHTBROWN = 14
BRIGHTWHITE = 15

virtual at 0
   write:
        .x        dw   ?
        .y        dw   ?
        .back   db   ?
        .fore    db   ?
        .str    dw  ?
end virtual

macro mov a, b {
   local c, d
     if b eqtype ''
      jmp d
      label c
      display b
      db b,0
      label d
        mov ax, c
        mov [write.str], ax
     else
      move a, b
    end if
}
move fix mov

macro write_string text, x, y, fg, bg {
   mov [write.x], x
   mov [write.y], y
   mov [write.back], bg
   mov [write.fore], fg
   mov [write.str], text
   call WriteStr
}

push cs
pop ds
push $b800      ; Set ES here, unless you need to alter it later on
pop es          ; It'll save a little time when you call WriteStr

mov ax,03h
int 10h

   mov [write.x], 10
   mov [write.y], 10
   mov [write.back], GREY
   mov [write.fore], BLUE
   mov [write.str], 'this is a test'
   call WriteStr
; Or this way:
;  write_str 'this is a test', 10, 10, GREY, BLUE

xor ax,ax
int 16h
int 20h

WriteStr:
        mov   ax, [write.y]       ; THIS ROUTINE WAS FIXED
        dec   ax            ; THE OFFSET ONSCREEN
        mov   cx, TX        ; WAS CALCULATED WRONG/
        mul   cx            ; NOW THIS IS OK !
        add   ax, [write.x]       ;
        shl   ax, 1         ; optimised
        mov   di, ax

        mov   ah, [write.back]
        mov   al, [write.fore]
        shl   ah, 4
        or    ah, al

        mov   si, [write.str]
      Continue:
        mov al, byte [si]
        stosw
        inc si
        cmp al, 0
        jnz Continue
ret
    


i think you have over complicated your code a bit,
you should see the problem first time looking at it, the first reason is because you wrote it Smile
moderated myself ---


Last edited by Matrix on 29 Oct 2005, 01:43; edited 1 time in total
Post 05 Sep 2004, 01:21
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 17:21
you might also want to see this topic:

http://board.flatassembler.net/topic.php?t=2186

MATRIX
Post 09 Sep 2004, 17:21
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.