Page 1 of 1

Problem with printing

Posted: Tue Feb 08, 2005 2:48 pm
by beyondsociety
Ive been brushing up on my assembly language skills and I am in the process of trying to get a character to print multiple times as though it looks like its loading.

I can print the character a certain number of times, but it gets displayed all at once. Any help or tips would be appreciated.

This is what I have so far, two different versions. Ive even tryed adding a loop but couldnt get it to work.

Code: Select all

; Print dots      
mov ah, 0x09    ; AH = write character function
mov al, '.'     ; AL = character to display                    
mov bx, 0x0007  ; BH = video page number, BL = attribute 
mov cx, 0x0010  ; CX = number of times to write character 
int 0x10        ; Bios video function

; Print a character using the video memory
mov ax, 0x0b800   ; Segment of video buffer in real mode
mov es, ax        ; Put this into es
xor di, di        ; Clear di, ES:DI points to video memory
mov ah, 4        ; Attribute - red
mov al, "G"       ; Character to put there
mov cx, 1         ; Amount of times to put it there
cld               ; Direction - forwards
rep stosw        ; Output character at ES:[DI]
Thanks in advance.

Re:Problem with printing

Posted: Tue Feb 08, 2005 4:52 pm
by mystran
If you want them to print one at a time, then you obviously need to wait between printing the characters.

Re:Problem with printing

Posted: Tue Feb 08, 2005 8:03 pm
by Dex4u
Yes as mystran said it needs a delay, this code in nasm, Works for none critical delay, 70 = 1 second.

Code: Select all

BITS 16
ORG 100h

SECTION .text

START:
        xor ah,ah
        int 16h
        mov  word[count],0
ddf:
        call FullVertWait
        cmp word [count],70
        jne  ddf

   ;Do some thing in here

        xor ah, ah
        int 16h

        ret
;**************************

FullVertWait:

        MOV    DX,3DAh
Vr:
        IN      AL,DX
        TEST    AL,8
        JNZ    Vr          ;wait until Verticle Retrace starts
Nvr:
        IN      AL,DX
        TEST    AL,8
        JZ      Nvr        ;wait until Verticle Retrace Ends
        ADD    word[count],1
        RET

;**************************

SECTION .data

count    dw 0

It use the Verticle Retrace for timer.

Dex4u

Re:Problem with printing

Posted: Thu Feb 10, 2005 4:31 am
by srg_13
How can you time a delay in C

Thanks,

Stephen :)

Re:Problem with printing

Posted: Thu Feb 10, 2005 4:37 am
by Pype.Clicker
Stephen wrote: How can you time a delay in C
By calling a function :P

Nah, seriously, doing *anything* in C means calling a function. Once you have "inb/outb" in your C runtime, you can use the same trick as dex4u showed in asm:

Code: Select all

/* wait for the screen to retrace. That occurs every 1/70th of seconds on a 70Hz screen, every 1/100th of second on a 100Hz screen, etc.
*/ 
while (! (inb(0x3da)&8));
// the screen is now retracing
while (inb(0x3da)&8);
If you need *precise* timing, you should consider polling a PIT counter or set up an handler for IRQ0.

Re:Problem with printing

Posted: Thu Feb 10, 2005 4:46 am
by srg_13
Thanks for that.
If you need *precise* timing, you should consider polling a PIT counter or set up an handler for IRQ0.


Well, its only for a splash screen, so i don't really need it to be all that precise. ;)

Re:Problem with printing

Posted: Thu Feb 10, 2005 7:23 am
by B.E
You could you the CPU timer to print a dot every say 1 second.
That way all you have to do is set it up and then let the CPU worry about the rest. but rember to "turn it off" once you have finish.