English Amiga Board


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

 
 
Thread Tools
Old 18 October 2014, 23:06   #1
Yesideez
(2b)||!(2b)
 
Yesideez's Avatar
 
Join Date: Mar 2007
Location: Cranbrook, Devon, UK
Age: 50
Posts: 241
Unable to use sin and cos

Attached is the full code as I've got it now.

All I want to do is open a screen and window and draw some lines around a circle but having immense difficulty in getting two maths functions to work.
Attached Files
File Type: c test.c (3.0 KB, 142 views)
Yesideez is offline  
Old 18 October 2014, 23:47   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Would probably be easier to #include <math.h> and use ANSI C math functions. You might need to add -lmieee or -lmsoft to the vbcc command line in this case.

The main mistake I see is j <= 10000 and sin(j). The sin function takes the angle in radians. Which means a number between 0 and 2*pi. To get radians from degrees you can use the formular rad = deg * pi / 180. pi is 3.14159265358979323846.

Also you let the compiler convert between int and float and vice versa. But mathtrans.library uses Motorola float format while the compiler most likely uses standard float format. I don't know the difference, but there are functions in mathtrans.library to convert between these two formats, so I assume that the difference matters. As mentioned above, you should use the compiler's math functions from math.h. Then you can be sure that it uses the right float format.

Furthermore you can make your live much easier if you omit all the OpenLibrary and CloseLibrary calls and instead add -lauto to the vbcc command line.
thomas is offline  
Old 18 October 2014, 23:47   #3
Yesideez
(2b)||!(2b)
 
Yesideez's Avatar
 
Join Date: Mar 2007
Location: Cranbrook, Devon, UK
Age: 50
Posts: 241
btw, this worked fine but I cant' seem to use math.h as I've had to use option -nostdlib ???

Code:
#include <stdio.h>
#include <math.h>

int main() {
  double i,offset1,offset2,temp; 
  int j;
  char *funky="sunspot2014";
  int funkylen=strlen(funky);
  while (1) {
    i+=0.1;
    offset1=sin(i)*36 + 36;
    offset2=cos(i*1.1)*36 + 36;
    if (offset2<offset1) {
      temp=offset1;
      offset1=offset2;
      offset2=temp;
    }
    for (j=0; j<offset1; j++) {
      printf(" ");
    }
    for (; j<offset2; j++) {
      printf("\x1b[3%cm%c",(char) ((((int)(10*sin(i*0.9)+10)+j)&7)+49),funky[j%funkylen]);
    }
    printf("\n");
  }
}
Yesideez is offline  
Old 18 October 2014, 23:50   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Who does force you to use -nostdlib ?
thomas is offline  
Old 19 October 2014, 00:05   #5
Yesideez
(2b)||!(2b)
 
Yesideez's Avatar
 
Join Date: Mar 2007
Location: Cranbrook, Devon, UK
Age: 50
Posts: 241
Not sure to be honest. I have no idea what I'm doing andI'm just going by presious examples I've found. It's worked so I've carried on with it

Thanks massively for the -lauto, it's made a huge diference

Attached is my latest program as-is and here's how I've compiled it:
Code:
vc -sc -sd -O2 -lmsoft -lauto //targets/m68k-amigaos/lib/minstart.o test.c -o test -nostdlib
Attached Files
File Type: c test.c (3.0 KB, 116 views)
Yesideez is offline  
Old 19 October 2014, 00:47   #6
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Just FYI, you may want to avoid -O1 and higher optimization modes with VBCC, as they are not entirely stable and will sometimes generate erroneous code. Only the default optimization mode seems to work correctly.
Leffmann is offline  
Old 19 October 2014, 00:54   #7
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Why don't you keep it simple? All the options you use are for experts. You are not yet an expert are you?

vc test.c -o test

undefined reference to math functions -> add -lmsoft
undefined reference to library bases -> add -lauto

vc test.c -o test -lmsoft -lauto

Done.

Don't use options which you don't understand.

BTW, undefined reference to OpenScreenTags, OpenWindowTags, Printf and the like -> add -lamiga
thomas is offline  
Old 19 October 2014, 02:12   #8
Yesideez
(2b)||!(2b)
 
Yesideez's Avatar
 
Join Date: Mar 2007
Location: Cranbrook, Devon, UK
Age: 50
Posts: 241
Thanks for the input so far but now it doesn't work :/

vc -lamiga -lauto test.c -o test

When it did compile without errors, it crashed the Amiga. I ran it through monam and it went from opening dos.library to tryign to use OpenScreenTagList without opening any other libraries :/
Attached Files
File Type: c test.c (1.9 KB, 113 views)
Yesideez is offline  
Old 19 October 2014, 08:58   #9
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
How could you compile it at all. I get an error about DOSBase being defined twice:

Code:
6> vc -lamiga -lauto test.c -o test
Error 19: T:t_6_0.o: Global symbol _DOSBase from t_6_0.o is already defined in startup.o.
vlink fehlgeschlagen Rückgabewert 20
vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -Lvlibos3: vlibos3:startup.o "T:t_6_0.o"   -lamiga -lauto -s -Rshort -lvc -o test failed
QNAS:Sources
6>
That's exactly your problem: you removed GfxBase, IntuitionBase and the other libraries, but why did you keep DOSBase?
thomas is offline  
Old 21 October 2014, 11:29   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Leffmann View Post
Just FYI, you may want to avoid -O1 and higher optimization modes with VBCC, as they are not entirely stable and will sometimes generate erroneous code. Only the default optimization mode seems to work correctly.
No software of this complexity is without any errors, but compiling with -O1 is as stable and as tested as compiling without optimization (maybe even more). -O2 and higher are less tested and also difficult to debug.
phx is offline  
Old 21 October 2014, 18:49   #11
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
I didn't mean to imply that VBCC was not a good compiler, it's all above my head and I'm impressed by how Volker and you have made a complete C99-capable tool-chain with such a small footprint. It was just a helpful advice since these kind of errors are very hard to debug.

I did send you a bug-report about it some time ago. You may have misinterpreted it as VBCC just generating a bit of inefficient code, but it's an actual case of erroneous code from using -O1. Let me know if you need me to resend the mail.
Leffmann is offline  
Old 23 October 2014, 10:05   #12
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Leffmann View Post
I did send you a bug-report about it some time ago. You may have misinterpreted it as VBCC just generating a bit of inefficient code, but it's an actual case of erroneous code from using -O1. Let me know if you need me to resend the mail.
Did I reply to it? It certainly doesn't hurt to remind me, when something takes too long. Although I guess that I already forwarded the bug to Volker, but I didn't hear anything from him since months... (which currently delays the planned V0.9c release).
phx 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
Commodore COS 32 Bit zeke1312 support.Other 7 22 February 2013 21:42
Apano Sin. Please help! viddi request.Old Rare Games 22 20 January 2012 22:42
OT but relevant cos i live in the hardware section Dimlow support.Hardware 23 02 September 2009 15:11
Apano Sin robotriot Games images which need to be WHDified 4 10 December 2004 17:58
[Fixed] SiN Korodny HOL data problems 3 02 January 2003 20:52

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 22:46.

Top

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