English Amiga Board


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

 
 
Thread Tools
Old 08 November 2015, 05:39   #1
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Starting out

Hi Guys,
It’s taken me about a year to complete my Amiga hardware.
So I have CD32 + SX-1 with 6 Mb RAM total. The last thing I got was the keyboard.

I want suggestions for an easy way to get started with C,
and wanting to draw primitive shapes, text, and lines on a screen.
What compiler should I use? I don’t care about an IDE, but prefer easy setup.
Ok to type into an editor such as Ced, and compile from a shell.

Samples would also be handy to show what to do about different screen resolutions, how to know how big the window was made,etc.

I could be using an Amiga or WinUAE. Any tips?
Cheers, Art.
xArtx is offline  
Old 08 November 2015, 07:57   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,207
Samples can be found on Aminet.org in dev/c directory.
Samurai_Crow is offline  
Old 08 November 2015, 10:22   #3
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,035
Quote:
What compiler should I use?
vbcc is great, but 6 MB RAM is a bit tight.

Perhaps Dice C is better for your machine. Installation instructions: http://eab.abime.net/showpost.php?p=874957&postcount=2



Quote:
Originally Posted by Samurai_Crow View Post
Samples can be found on Aminet.org in dev/c directory.
aminet.net, not .org

http://aminet.net/dev/c
thomas is offline  
Old 08 November 2015, 10:50   #4
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Yes I already figured out the first address is dead.
A lot of things I googled: CubicIDE, StormV4, etc. I cannot find free on the net.
I will try Dice C then, cheers

Thomas, I notice you made the tutorial, If I compile the test program successfully,
would it be too much to ask for you to do a source that:
Draws a line or some pixels and writes a Hello World on the same graphics screen?

Last edited by xArtx; 08 November 2015 at 11:00.
xArtx is offline  
Old 08 November 2015, 13:34   #5
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Stand back, I’m an Amiga programmer now
xArtx is offline  
Old 08 November 2015, 14:51   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,035
Quote:
Originally Posted by xArtx View Post
would it be too much to ask for you to do a source that:
Draws a line or some pixels and writes a Hello World on the same graphics screen?
See attachment.

To (re)build it, cd into either demo1 or demo2 directory and enter dmake.
Attached Files
File Type: lha demo.lha (12.4 KB, 101 views)
thomas is offline  
Old 08 November 2015, 15:58   #7
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Thanks Thomas,
It takes burning a CD for me to get it to the Amiga hardware (I skipped UAE),
but my Mac can extract .lha, and I see the first example is a pong ball
and the variable size of a resizable window is accounted for.

Done for tonight, but will start again tomorrow

I have a 40Mb HDD with 1.4Mb free after the Dice C install.
...had to delete the previous owners game directory and some other stuff.
I’ll have a look for more room I can possible make.

Quote:
Originally Posted by thomas View Post
See attachment.

To (re)build it, cd into either demo1 or demo2 directory and enter dmake.
xArtx is offline  
Old 08 November 2015, 16:33   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,035
To save some space you can delete the directories

doc
editors
examples
l
libs
rexx

from Dice as well as all files in the main Dice directory.

The NDK_3.9 can be deleted entirely after you copied the includes and linker_libs to Dice. However, you might want to retain the autodocs.
thomas is offline  
Old 08 November 2015, 18:03   #9
duga
Registered User
 
Join Date: Nov 2010
Location: Sweden
Posts: 528
Good luck. What will you focus on; OS 3.1 or 3.9?

Trying to learn C for OS 4.1 here.
duga is offline  
Old 09 November 2015, 03:54   #10
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Hi, It would be OS 3.1 for a CD32 yeah? CD32 is my only real hardware.
I have ideas rather than solid goals for end programs, but fairly proficient with C,
so hopefully will gain momentum with more understanding of the Amiga.

Quote:
Originally Posted by duga View Post
Good luck. What will you focus on; OS 3.1 or 3.9?

Trying to learn C for OS 4.1 here.
xArtx is offline  
Old 10 November 2015, 15:14   #11
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Hi again Guys I have reached a problem.

I want to use the C sin() and cos() functions that are normally in math library.

I’ve tried including mathtrans.h and mathieeesingtrans.h, and if I call their respective
sine or cosine functions:
Code:
SPSin(theta);
IEEESPSin(theta);
The program compiles, but when run it crashes with error #8000000B,
which I Googled to mean the program requires a hardware floating point unit.

Is there a way to use sin/cos without the FPU hardware?
Cheers, Art.
xArtx is offline  
Old 10 November 2015, 17:08   #12
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 763
I don't know but <math.h> have sin() and cos()? Linked with -lm ofcourse.
tolkien is offline  
Old 10 November 2015, 17:27   #13
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
There is no math.h in the SDK. I was talking about a math.h I use on other platforms.

I was talking about this kind of thing.
Supposed to use FPU hardware if it exists, CPU otherwise.
Code:
struct Library *MathBase;
 
VOID main()
{
float f1;
long i1;
 
if (MathBase = OpenLibrary("mathffp.library", 0)) {
    i1 = SPFix(f1);     // copy float to integer long
    CloseLibrary(MathBase);
} else {
printf("Can't open mathffp.library\n");
}
Can a float be given a value when it is declared like this?
Code:
float pi = 3.14159;
or is it more complicated than that?
xArtx is offline  
Old 10 November 2015, 17:38   #14
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 763
But <math.h> is part of any C compiler no platform specific.

Yes, you declared a float in that form and the example seems ok. Perhaps you need to tweak some compiler option?
tolkien is offline  
Old 10 November 2015, 17:40   #15
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,035
Quote:
Originally Posted by xArtx View Post
The program compiles, but when run it crashes with error #8000000B
You need an updated SetPatch: http://aminet.net/package/util/boot/SetPatch_43.6b

Actually the math#?.library's should hide the need for an FPU and switch to software floating point routines automatically. But for some reason the proper libs didn't make it into the A1200/CD32 ROM.


Quote:
Originally Posted by xArtx View Post
There is no math.h in the SDK.
math.h is part of the compiler's include files. It should be in DINCLUDE: along with stdio.h and the like.

You don't need the SDK to compile an ANSI C program.

Last edited by thomas; 10 November 2015 at 17:46.
thomas is offline  
Old 10 November 2015, 17:46   #16
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Oh ok.. I couldn’t find it in the NDK_3.9 directory, and then Googled how to use what was there.

I’m trying to rotate a point about an origin and this simple thing has turned into a monster using that mathtrans thing.

Code:
theta = rotation;
thetab = (3.141592 / 180) * theta;

    xx = 160;
    yy = 200;
    x = xx - 160;
    y = yy - 140;
    xnew = cos(thetab)*x - sin(thetab)*y;
    ynew = sin(thetab)*x + cos(thetab)*y;
    xnew = xnew + 160;
    ynew = ynew + 140;
xArtx is offline  
Old 10 November 2015, 18:06   #17
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,035
There is an example which mixes math.h with AmigaOS functions: http://thomas-rapp.homepage.t-online...les/piechart.c
thomas is offline  
Old 10 November 2015, 18:17   #18
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Ok, thanks again
Will have to be a job for tomorrow. It’s past 3am here!
Just the SetPatch file requires burning another CD,
but I’ll try to put more on it this time, like as much of my own C code I can fit on it.
xArtx is offline  
Old 11 November 2015, 07:36   #19
xArtx
Registered User
 
Join Date: Jun 2013
Location: Australia
Posts: 685
Success!
The updated SetPatch file was required.
The same source I posted above crashes while compiling with my old version.
I wish I’d known that. Now the code I posted above compiles as it is written.
Though for the Amiga I’m probably going to want to pre-calculate this:
Code:
3.141592 / 180
and both of these since the result is used twice:
Code:
sin(thetab)
cos(thetab)
lol.
xArtx is offline  
Old 11 November 2015, 08:18   #20
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 763
For sure It's better to precalculate al sin() cos() you can. They are expensive CPU functions.
tolkien 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 16:31.

Top

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