English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 11 November 2015, 09:11   #21
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Funny that, I have an iOS App that does the same code section up to thousands of times,
rotating thousands of points, and a few years later can make it much faster


[ Show youtube player ]



Quote:
Originally Posted by tolkien View Post
For sure It's better to precalculate al sin() cos() you can. They are expensive CPU functions.
xArtx is offline  
Old 12 November 2015, 14:55   #22
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Hi Guys
Well I have got the clock read and write working from this example:
http://amigadev.elowar.com/read/ADCD.../node01A1.html

Where the library is opened and closed (with a potential error if the library failed to open),
If you want to constantly display the time such as Amiga Workbench clock does,
is there anything nasty happening for repeated iterations the same code to update seconds?

If I understand correctly, the use of this will open a library file from disk.
Is the library kept in RAM after opening and closing it the first time?
Cheers, Art.
xArtx is offline  
Old 12 November 2015, 15:12   #23
davideo
Amiga Tomcat
 
davideo's Avatar
 
Join Date: Sep 2007
Location: Boston Lincs
Posts: 1,500
Quote:
Originally Posted by xArtx View Post
If I understand correctly, the use of this will open a library file from disk.
Is the library kept in RAM after opening and closing it the first time?
Cheers, Art.
AFAIR

Once opened all libraries remain in memory unless you flush them with "Avail flush" or your Amiga starts to run out of memory.

Also if you open the same library twice in the same program it does not open it twice but increases a counter and decreases it once closed. Only when the counter is at Zero will it close the library if required.
davideo is offline  
Old 12 November 2015, 15:33   #24
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Ok, thanks that makes sense. It’s not like my HDD LED is flashing or anything like that,
more that I don’t want to do something stupid, and then keep going on that program.
xArtx is offline  
Old 12 November 2015, 15:42   #25
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by xArtx View Post
Where the library is opened and closed (with a potential error if the library failed to open),
If you want to constantly display the time such as Amiga Workbench clock does,
is there anything nasty happening for repeated iterations the same code to update seconds?
You should not use the ReadBattClock function unless you really want to read the battery backed up clock.

To get the system time there is GetSysTime in timer.device (number of seconds since 1978 and number of microseconds since last second) or DateStamp in dos.library (number of days since 1978, number of minutes since midnight and number of 50Hz ticks since last minute).

Quote:
If I understand correctly, the use of this will open a library file from disk.
Is the library kept in RAM after opening and closing it the first time?
Cheers, Art.
First of all the library is kept in memory only once, no matter how many programs use it concurrently.

Yes, the library remains in memory after CloseLibrary. It maintains an open counter and if the counter is higher than 0, the library remains fixed in memory. Only if the use count is 0 it may be expunged by the memory system. (You can cause it for example by AllocMem(0xffffffff,MEMF_ANY); )
thomas is offline  
Old 12 November 2015, 15:49   #26
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Here is an example which prints the current date and time:

Code:
#include <proto/dos.h>

int main (void)

{
struct DateTime dt;
char day[LEN_DATSTRING];
char date[LEN_DATSTRING];
char time[LEN_DATSTRING];

DateStamp (&dt.dat_Stamp);

dt.dat_Format = FORMAT_DOS;
dt.dat_Flags  = 0;
dt.dat_StrDay = day;
dt.dat_StrDate = date;
dt.dat_StrTime = time;

DateToStr (&dt);

Printf ("%s, %s %s\n",day,date,time);

return (RETURN_OK);
}
thomas is offline  
Old 12 November 2015, 16:39   #27
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Ok thanks again that answers my questions.
It appears I am tending to do things the hard way

Quote:
Originally Posted by thomas View Post
You should not use the ReadBattClock function unless you really want to read the battery backed up clock.
I assume I read the system clock which in turn, got the time from the real time clock hardware if it was present.
I really do want to write a new time to the clock though (be able to update it),
so I’ll see if that also updates the system time.

Where are you getting these samples that are ready for Dice-C?
xArtx is offline  
Old 12 November 2015, 18:07   #28
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
I assume I read the system clock which in turn, got the time from the real time clock hardware if it was present.
ReadBattClock does not read the system time, it only reads the RTC.

The system time is maintained by timer.device. It is synchronized with the RTC once at boot time by the SetClock command in startup-sequence. After that it runs independently from the RTC.

You can set the system time by sending a TR_SETSYSTIME command to timer.device.

The RTC can be set by the WriteBattClock function.

Quote:
Where are you getting these samples that are ready for Dice-C?
I develop them myself. I've been using Dice C since it became freely available and only recently switched to vbcc.

However, the examples you get from me are not specific to Dice C, they compile with all Amiga compilers.
thomas is offline  
Old 15 November 2015, 07:42   #29
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Hi again Guys
I have kept things in this thread rather than clutter the place.
So far I’ve tried to use a new device/library each sitting, and the last one was narrator.

This problem I have was present from the beginning, and don’t know how to deal with it.
Even present when running DEMO1 and DEMO2 Pong samples supplied by Thomas.
I see the difference between the two is the second waits for vertical draw time,
and possibly the second one uses bitter to draw the rectangles.

There’s screen flicker at a certain horizontal area of the screen around where the
mouse pointer is sitting in the video. It flickers in an area about 1 or 2 inches of the screen,
and I haven’t worked out how to get rid of it. It stops flickering if I stop drawing of course.

I presume something to do with raster not synchronised with drawing?
Is there a way to perhaps draw every second frame to avoid this even if the program runs slower?

[ Show youtube player ]
xArtx is offline  
Old 15 November 2015, 17:02   #30
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by xArtx View Post
I see the difference between the two is the second waits for vertical draw time,
and possibly the second one uses bitter to draw the rectangles.

There are only two differences between the two demos. The first one is obvious: while demo1 consists of only one source file with one big main routine, demo2 uses a more modular approach. It is divided into several smaller routines and the routines are grouped by topic into several source files keeping each file as simple as possible. This is also the base for object oriented programming, keeping the data structures private and using functions (a.k.a. methods) to access them.

The second and main difference is the source for the timing. Demo1 uses INTUITICKS which only arrive ten times a second. Demo2 uses timer.device UNIT_VBLANK which occurs 50 or 60 times a second, making movement a lot more smooth.


Quote:
There’s screen flicker at a certain horizontal area of the screen around where the
mouse pointer is sitting in the video. It flickers in an area about 1 or 2 inches of the screen,
and I haven’t worked out how to get rid of it. It stops flickering if I stop drawing of course.
The problem is that neither timing method is synchronized with the display. Both are based on the vertical blank pulse of course, but the interrupt routine first handles all the system needs before it calls the user program.

There is no easy way to syncronize the display with AmigaOS functions. If you look at the double buffering example in the graphics.library manual you'll become scared.

But there are some tricks to at least avoid flickering. For example if you draw the changed area of the screen first into an off-screen bitmap and then blit the finished bitmap into the screen, it does no longer flicker. It still shows some tearing effects, though.

I've changed the demo2 source accordingly.
Attached Files
File Type: lha demo2.lha (10.1 KB, 95 views)
thomas is offline  
Old 16 November 2015, 07:48   #31
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Thanks again Thomas
That does explain it well. I’ve been looking at this manual for graphics drawing,
but the samples for primitives don’t animate anything. They just draw something.
http://www.pjhutchison.org/tutorial/amiga_c.html
Would you please link to the manual/example for double buffering?
I’ve Googled a few results, but don’t know what to try. Is is something like this?
http://wiki.amigaos.net/wiki/Intuiti...doublebuffer.c
It does actually animate something which is helpful.

For the video I posted with talking time, if I stopped moving the time in a circle
and only updated the time display on seconds change, then I assume the issue
would be all but gone, and then suitable for some non-graphics oriented programs.

I’ve decided to hold off a little till I get a Gotek or some other way to get files into the Amiga easily.

Last edited by xArtx; 16 November 2015 at 08:06.
xArtx is offline  
Old 16 November 2015, 18:57   #32
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Yes, I think this is the example or at least a similar one. I used the one from the older OS3 manual. This one is for OS4.

Basically it gives you two signals: IIRC one when you may switch screen buffers and another when the current buffer has been displayed so that you may reuse it. It was a bit difficulty to understand why these occasions are not the same and I don't remember the details.

I found an example of mine but it flickers like hell and corrupts Workbench, so it's obviously not correct. Maybe I find some time to develop a new one later this week.
thomas is offline  
Old 17 November 2015, 08:32   #33
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
OS4 specific is something I should watch out for, as not good for the CD32 if OS4 is required.
Maybe something to do with the small time in vertical blanking?
I ordered the Gotek today so should be back into it soon.
Thanks for your help again, any time you do invest in samples,
I don’t tend to get frustrated and run away, but usually do dig in and finish things
xArtx is offline  
Old 18 November 2015, 15:50   #34
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
I have a dodgy fix, it could be applied to the Pong game, but not a screen packed with graphics.
To refrain drawing each item (text feild) if the VBeamPos is around the position you want to draw it,
but you could still move the object. For each object you might occasionally drop a frame.

I programmed both game and demo for the Digic CPU in Canon camera and didn’t have to do this.
Maybe because it’s LCD not CRT, so the scanline is really just imaginary.

There’s some problems from capturing with iPhone and uploading to YouTube,
but the CRT screen I see here is smooth always.
[ Show youtube player ]
xArtx is offline  
Old 19 November 2015, 11:58   #35
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Took a closer look at the example you linked and found that it is completely different from what I used. It's much more advanced and actually a complete program and not only an excerpt.

I changed the OS4 code so that it compiles on OS3 (see attachment).

Hint: you have to select "run" from the menu to see something move.
Attached Files
File Type: c doublebuffer.c (18.8 KB, 88 views)
thomas is offline  
Old 19 November 2015, 13:34   #36
Bastich
Registered User
 
Bastich's Avatar
 
Join Date: Jul 2011
Location: UK
Posts: 341
Quote:
Originally Posted by tolkien View Post
For sure It's better to precalculate al sin() cos() you can. They are expensive CPU functions.
Very good advice
Bastich is offline  
Old 19 November 2015, 17:04   #37
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Thanks
Going further without fixing the graphics is a bit of putting the cart before the horse,
but I started importing some local Astronomy algorithms ported to C long ago.
[ Show youtube player ]

Last edited by xArtx; 20 November 2015 at 07:04.
xArtx is offline  
Old 22 November 2015, 16:58   #38
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Hi Guys,
I have not run the double buffer sample.. still waiting for the Gotek,
but made a bit of a start. It’s supposed to be the user selects a location on a world map.
This one just plots a hard coded point, and the Astronomy information is correct for the point.
[ Show youtube player ]
xArtx is offline  
Old 29 December 2015, 12:34   #39
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Back again
This time I want to use the serial port for GPS. Is this document still relevant?
http://amigadev.elowar.com/read/ADCD.../node009A.html

I have the GPS working with NComm so I know it’s electrically ok:
[ Show youtube player ]
It’s a 5Hz model, so most of it I’ll be trying to ignore to just get one $GPRMC sentence per second.
The idea is to set the Amiga’s clock and to display the location on the map.
Particularly where the bare CD32 unit has no battery backup clock, but the Garmin unit does.
Cheers, Art.
xArtx 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
Starting out xArtx Coders. General 4 13 February 2015 03:55
Starting out in C xArtx Coders. C/C++ 2 24 June 2013 04:35
Help starting with Minimig v1.1 lolafg support.Hardware 17 04 May 2010 06:48
Starting a program BippyM Coders. Tutorials 10 10 February 2006 15:35
Starting again Bad Mr Frosty support.Apps 0 24 September 2004 21:48

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 10:33.

Top

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