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.
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.
; 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]
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
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:
/* 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.
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.