flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Pause...

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Jun 2011, 20:54
Hi! I recently started learning about OS construction things.. I need something to pause my code for like 5 seconds.. How to do that can anyone suggest me ? Thanky you.
Post 17 Jun 2011, 20:54
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 17 Jun 2011, 23:19
Post 17 Jun 2011, 23:19
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 18 Jun 2011, 10:20
Dex4u
Thank you.
Also, can you tell me what "in" and "out" instructions does ? I read documentation but I can't understand much.. Is there some tutorial for beginners ? Thanks.
How about this one, it should work under dos right ?
Code:
mov ah,0x86
mov cx,microseconds
int 0x15    


eh.... why this code doesn't work ?..
Code:
format binary
start:
mov ax,0x07C0
mov ds,ax
mov si,text_string
call print_string
jmp $
text_string db "Hello World Wink",0
delays:
;DL=DeLay in second 
mov ax,0 
out 70h,al 
in al,71h 
;al = seconds of time 
ror ax,8 
@@: 
out 70h,al 
in al,71h 
sub al,ah 
je @b 
dec dl 
jne delays 
ret
print_string:
mov ah,0eh
.repeat:
lodsb
cmp al,0
je .done
int 10h
mov dl,3
call delays
jmp .repeat
.done:
ret
times 510-($-$$) db 0
dw 0xAA55    

Trying to print characters with delays like
H (after 3 seconds).. e (after 3 seconds).. l.. and so on..
Post 18 Jun 2011, 10:20
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 18 Jun 2011, 10:52
Overflowz wrote:
Also, can you tell me what "in" and "out" instructions does ? I read documentation but I can't understand much..

In short, in/out is how you communicate with ports: out writes data, in reads data.
If you have anything more specific to ask, then please do. But I'm pretty sure it's all there in great details in the Intel manuals.

Overflowz wrote:


How about this one, it should work under dos right ?
Code:
mov ah,0x86
mov cx,microseconds
int 0x15    


It's a BIOS interrupt. It should work under DOS but I can't tell for sure. Why are you asking this here and not in the DOS subforum?
Post 18 Jun 2011, 10:52
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 18 Jun 2011, 11:06
I'm trying to write simple OS.. not graphics and things like that cause I'm just totally newbie about that. I read up some tutorial and understood these and worked fine when booted from VMware:
Code:
format binary
start:
mov ax,0x07C0 ;BIOS reads boot loader from this address
mov ds,ax ;moving it into data segments (I guess, whole my code is in data section)
mov si,text_string ; print characters..
call print_string  ;
jmp $              ;infinite loop
text_string db "Hello World Wink",0
print_string:
mov ah,0eh
.repeat:
lodsb
cmp al,0
je .done
int 10h
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ;fill 0s to be 512 bytes
dw 0xAA55 ;boot sig    

Can you tell me which interrupts wont work there ? I know only int 21h won't work.
Post 18 Jun 2011, 11:06
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 18 Jun 2011, 12:54
with very little code overhead, it is possible to use PIT to do delays.
and you know what? this kind of delay is less CPU consuming than RTC or DEC reg method.

just use an over int8 handler to update some counter, compared to some value in the application, and just do a

Code:
mov [delay.time],value
call delay
    


like ever, this function is easy to use, but behind the call delay, there will be a fully halted system.

only irqs will update the execution of this function.
then, type a key, move the mouse, or just the 18.2 interrupt.

but only the pit interrupt will be effective for this function.

means that even if an irq wakes the function (because of hlt instruction inside the delay loop), it will do nothing else than a value compare with 0, and a jne .loop.

the int8 over handler is responsible of the counter update, that is passed with the value in delay.time.

means that in fact, you implement a timer in the machine, exactlly like if you connect a timer component on a digital electronic board.

the way to install a handler over a handler is easy, just save somewhere the far pointer to the original handler taken from the IVT, put your handler's far pointer in the IVT, and in the over handler, don't forget to do a jmp to the far pointer to old handler. the old handler is responsible of the iret, then, your code will be simple like

Code:
newint8:
dec [delay.time]
jmp far dword[delay.oldint8]
    


int 8 vector is the 32 bits far pointer at linear 8*4
the first word is the 16 bits offset.
the second is the 16 bits segment.
Post 18 Jun 2011, 12:54
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 18 Jun 2011, 16:40
If you just want a delay so people can read some text on screen.
Your can use the Vertical retrace of the monitor.

In a bare metal environment, it would be refreshed 60 times a second
Once you know that you can use it in some code to delay for any number of seconds.
Example: if you want a 10 second delay, simply multiply 10 by 60 move the result in to ecx and do a loop that number of times, in between the loops calling the below function.
Code:
FullVertWait:
      pushad
      mov   dx,0x03da
Vr:
  in    al,dx
 test  al,8
  jnz   Vr                                              
Nvr:
  in    al,dx
 test  al,8
  jz    Nvr                                             
      popad
       ret
    
Post 18 Jun 2011, 16:40
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 18 Jun 2011, 18:36
damn.. you guys know very much )) I'd better learn first what is IRQ or PIT or things like that.. Can someone suggest me some tutorials on it ? Thank you Smile
Post 18 Jun 2011, 18:36
View user's profile Send private message Reply with quote
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 18 Jun 2011, 18:46
Here's the Best tutorial around: http://www.intel.com/products/processor/manuals/

_________________
The person you don't know is the person that could help you the most... or rape you, whichever they prefer.
Post 18 Jun 2011, 18:46
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 18 Jun 2011, 22:14
Quote:
just use an over int8 handler to update some counter, compared to some value in the application
It's possible to use BIOS counter like in one my boot loader:
Code:
        mov ax,[46Ch]
        mov [base],ax
wait:
        hlt
        mov ax,[46Ch]
        sub ax,[base]
        cmp ax,91 ; 5*18.2
        jb short wait
    
Post 18 Jun 2011, 22:14
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 02 Jul 2011, 21:01
xleelz
Which one should I download from there can you tell me please ? Because of I've downloaded these two files http://board.flatassembler.net/topic.php?p=55709#55709 but there is nothing information about IRQ or things like that.. Where should I start ? Smile
Post 02 Jul 2011, 21:01
View user's profile Send private message 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.