English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 30 June 2011, 18:43   #1
Djay
95th User
 
Djay's Avatar
 
Join Date: May 2001
Location: Brighton/UK
Age: 48
Posts: 3,120
AMOS timer/clock?

Fairly noob question i am sure but...

can you create a timer outside of a main loop so for example...

your loop is waiting for joystick inputs (or such like), if the joystick input is positive then some actions occur on screen, however how do you create a counter/clock that isnt effected by the main loop going off a doing something else... i am able to read the timer from the main loop and reset if needed

to put it another way a clock which is running in the background and is not effected by other actions which would slow the counter down?

i hope this makes sense to someone!
Djay is offline  
Old 30 June 2011, 19:38   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
I don't see anything in the manual about it but you could always try 'Exec "wait 5 secs" ' to use the AmigaDOS wait command from the CLI. Otherwise, you'll have to directly use timer.device from the 'Dev Open' and 'Dev Close' devices command along with the other devices commands listed in the manual. Using the AmigaDOS wait command would be much easier though.
Samurai_Crow is offline  
Old 30 June 2011, 19:58   #3
Djay
95th User
 
Djay's Avatar
 
Join Date: May 2001
Location: Brighton/UK
Age: 48
Posts: 3,120
if i wait 5 secs, then that also means i can not detect if the joystick has been moved for 5 seconds

for a really good example of what i mean check out this youtube clip...
[ Show youtube player ]

as you can see there is a counter which ticks down, it is not effected by what is being updated on the screen

now if i am detecting joystick position and updating, lets say some sprites on the screen, then that would effect the count of the clock which would (i imagine) be updated during the main loop?
Djay is offline  
Old 30 June 2011, 22:11   #4
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
I know nothing about AMOS or its capabilities so I'm not sure something similar is possible but I used this approach to fade in and fade out vector objects in an intro I did in assembler...

Say your main loop is executed once a frame (ie. once every 50th of a second on a PAL machine) at vertical blank and everything that gets executed by your main loop (checking the joystick, updating the screen, incrememting or decrementing your clock counter etc.) can be completed during the vertical blanking period.

In that case you would be sure that your clock counter would get updated 50 times for every second that passed. You can use that to count time.

That would be one way to wait a set number of seconds without everything else slowing down - just check your counter as part of your main loop and quit or do an action when the counter hits the right value for the amount of time you want to wait.
pmc is offline  
Old 30 June 2011, 22:41   #5
Djay
95th User
 
Djay's Avatar
 
Join Date: May 2001
Location: Brighton/UK
Age: 48
Posts: 3,120
so lets say... i need to update everything on every loop frame by frame, including the clock (timer)... i just need to get the frame (loop) to hold (wait) for one second


the kinda makes sense


awesome... just tried it out and it works great! i never thought before of treating each loop as a frame before... i would normally pack loads of stuff into a single set of instructions outside of the mainloop and the waits would be screwed

Last edited by Djay; 30 June 2011 at 22:57.
Djay is offline  
Old 29 December 2011, 21:24   #6
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,775
Quote:
Originally Posted by Samurai_Crow View Post
Otherwise, you'll have to directly use timer.device from the 'Dev Open' and 'Dev Close' devices command along with the other devices commands listed in the manual.
Do you realy think this possible? What about a smaller measurment like milliseconds?

Last edited by Retro1234; 30 December 2011 at 00:57.
Retro1234 is offline  
Old 30 December 2011, 18:50   #7
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
I think Timer.device's granularity was the same as the screen blank interrupts so just using Wait VBL repeatedly should do the job just as well.
Samurai_Crow is offline  
Old 30 December 2011, 20:51   #8
Anakirob
Unregistered User
 
Anakirob's Avatar
 
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
Djay:I don't think treating each loop as a frame is such a good idea at all, as this will only work if the code within the mainloop takes less than one frame.

And using the timer device would be a good idea for an application, or turn based game. But if timing is critical then it could be a bit slow.

Sounds to me like you want to attach your timer to the vertical blank interrupt (interrupt 5), so this piece of code is executed whenever the system performs a vertical blank.Take a look at this thread where a similar concept is discussed.

And you could surely put some joystick polling routines in the code attached to the interrupt too if you want to be sure that any joystick movments are registered even if the mainloop is not up to the point in the code where movements are of signifigance. Just remember to reset them in your mainloop once you're done with them.

Last edited by Anakirob; 30 December 2011 at 20:58.
Anakirob is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
f/s Amiga Amos Programming books / Disks / Easy Amos & other Books *mega collection!* fitzsteve MarketPlace 4 23 May 2012 04:35
Using timer.device in C (VBCC) DBAlex Coders. General 2 28 June 2011 22:10
First timer with Win UAE-how to get ROMS? RMK support.WinUAE 6 28 January 2011 21:44
Old timer, new member ! cyberknight Member Introductions 14 23 May 2009 11:07
Where's the amos.library on the 3-disk AMOS set? andreas support.Apps 0 15 November 2001 16:04

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:03.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10571 seconds with 13 queries