30 June 2011, 18:43 | #1 |
95th User
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! |
30 June 2011, 19:38 | #2 |
Total Chaos forever!
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.
|
30 June 2011, 19:58 | #3 |
95th User
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? |
30 June 2011, 22:11 | #4 |
gone
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. |
30 June 2011, 22:41 | #5 |
95th User
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. |
29 December 2011, 21:24 | #6 | |
Phone Homer
Join Date: Jun 2006
Location: 5150
Posts: 5,775
|
Quote:
Last edited by Retro1234; 30 December 2011 at 00:57. |
|
30 December 2011, 18:50 | #7 |
Total Chaos forever!
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.
|
30 December 2011, 20:51 | #8 |
Unregistered User
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. |
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 |
|
|