Problem with printing

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

Problem with printing

Post 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.
mystran

Re:Problem with printing

Post by mystran »

If you want them to print one at a time, then you obviously need to wait between printing the characters.
Dex4u

Re:Problem with printing

Post 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
srg_13

Re:Problem with printing

Post by srg_13 »

How can you time a delay in C

Thanks,

Stephen :)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Problem with printing

Post 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.
srg_13

Re:Problem with printing

Post 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. ;)
B.E

Re:Problem with printing

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