11 September 2016, 17:11 | #81 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,891
|
Here's a cleaned up version of your test program. The example program you based your program on uses global variables (this is often not good), and it opens libraries needlessly (for system libraries it's not needed). There's also no need for declaring prototypes for programs like this. Just have functions appear in the order in which they are used, with the main function appearing last.
Code:
#include <stdio.h> #include <exec/types.h> #include <graphics/gfx.h> #include <intuition/intuition.h> #include <dos/dos.h> /* Prototypes for system functions. */ #include <proto/exec.h> #include <proto/graphics.h> #include <proto/intuition.h> #include <proto/dos.h> void drawGfx(struct Window *win) { int c; for (c = 0; c < 201; c += 5) { Move(win->RPort, 0, c); Draw(win->RPort, 200 - c, 0); Draw(win->RPort, 200, 200 - c); Draw(win->RPort, c, 200); Draw(win->RPort, 0, c); } } int main(void) { struct Window *myWindow; /* Open wiwndow. */ myWindow = OpenWindowTags(NULL, WA_Left, 20, WA_Top, 20, WA_Width, 210, WA_Height, 214, WA_Title, (ULONG)"Troys Draw Demo Win", WA_DepthGadget, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, FALSE, WA_DragBar, TRUE, WA_GimmeZeroZero, TRUE, WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE, TAG_END); /* Print error message and exit if window couldn't be opened. */ if (myWindow == NULL) { printf("Couldn't open window.\n"); return 0; } drawGfx(myWindow); Delay(500); CloseWindow(myWindow); return 0; } SASC6.58 will give you Error 218: declaration in statement block if you try that. |
11 September 2016, 17:22 | #82 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 727
|
Quote:
Code:
#include <stdio.h> int main(int argc, char **argv) { for(int i=0; i<10; ++i) printf("%d\n"); return 0; } SAS/C Amiga Compiler 6.58 Copyright (c) 1988-1995 SAS Institute Inc. ==================== for(int i=0; i<10; ++i) foo.c 5 Error 218: declaration found in statement block |
|
11 September 2016, 17:44 | #83 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 727
|
Ok, one design issue I'd change. (I'll use Thorham's cleaned up version as reference)
This line on your OpenWindow Code:
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE, You can delete mousebuttons and mousemove and make it Code:
WA_IDCMP, IDCMP_CLOSEWINDOW, Then you can replace the Delay line with Code:
Wait(1 << myWindow->UserPort->mp_SigBit); |
11 September 2016, 18:06 | #84 | |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@davideo
Quote:
@alkis Thanks for testing, I don't remember having a later version of SAS, possible SAS 2 or 3 at the most on the Amiga, I did use Dice/Lattice a lot before SAS - and then Storm C 3.0 about a year afterwards. Its entirely possible this is a habbit I have picked up programming on PC's |
|
12 September 2016, 01:19 | #85 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Thank you everyone for the great input, I'm learning and I really honestly appreciate everyones suggestions and help.
It seems to me that there are some fairly large differences between the sort of BASIC I'm used to and C - which is to be expected, but which does make the learning curve just that bit steeper. And no, I'm not talking about line numbers or (dare I mention it hehe) goto, I'm talking about reserved words and handling of variables. I mean, BASIC is pretty darn easy, A (numeric variable), B$ (string variable), and C(10) one dimensional array of numeric variables. It feels like C is a lot more complex here, but also offers a lot more flexibility once you get your head around it. And from what I've read looking around on the internet, it's not just me, this is one of the stumbling blocks for most people new to C, particularly when it comes to pointers and so forth. With reserved words, it seems to me that there are less reserved words than I am used to in basic, but that words can be reserved as functions rather easily, and often are in what you #include, so it can easily and quickly become virtually unlimited, depending on the includes? I'll certainly be coming back to this little exercise, for one I want to try to work out why I can't get PolyDraw to work for this, and for another learning exercise, I want to make the window re-sizable and have it redraw to suit when it is resized. Obviously this will mean getting rid of the fixed numbers and replacing them with variables obtained from the size of the window, as well as listening for a resize event - in the correct order of course. Also, I can use this for learning about menus - perhaps add a menu for line drawing style and colour, as well as a menu option to quit. |
12 September 2016, 02:22 | #86 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
This looks like a very handy site, I wish I'd found it sooner: http://www.pjhutchison.org/tutorial/amiga_c.html
|
12 September 2016, 03:15 | #87 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,891
|
Quote:
|
|
12 September 2016, 04:09 | #88 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,213
|
The Amiga operating system uses many pointer-based operations. If you learn them well, it will help later on.
C, however, is a really unforgiving language. IMO it should not be a first language and is unsuitable for beginners. My suggestion is to learn an easier language first and then come back to it. What is your goal? |
12 September 2016, 05:38 | #89 | |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Quote:
My goal is to learn and write system legal code that works with, and takes advantage of, intuition, mainly as a learning tool to help me understand the software side of the Amiga better. If that means I can then, later on, write my own programs to use and maybe even release to Aminet for others to use if they so desire, even better, but for now, it's mainly a learning tool. |
|
12 September 2016, 05:45 | #90 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,891
|
Quote:
|
|
12 September 2016, 08:28 | #91 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 727
|
I agree with Thorham.
If you want to learn something that you can use everywhere, stick with C. If you choose to make your objective to learn C, then I'd suggest to put amiga specific programming in the background and focus on the language itself. Find (google) the "the c programming language by kernighan and ritchie". Go through it. Write the included programs on your amiga. Compile them. Run. Make yourself familiar. Writting a 'wc' (word count) program feels good for a newbie! At least it did for me! Whatever you do, just have fun! |
12 September 2016, 10:09 | #92 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,213
|
If, on the other hand, you want to make Amiga coding your focus then pick an Amiga-specific language like AmigaE or Blitz BASIC 2.1. That way you'll know it will work on a 25 year old computer like yours without a new compiler.
|
30 September 2016, 14:21 | #93 |
Registered User
Join Date: Oct 2006
Location: Poznan/Poland
Age: 47
Posts: 116
|
On miggy I would chose Amos/Blitz and after that finally assembler, never C.
|
30 September 2016, 14:41 | #94 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,891
|
|
14 September 2020, 11:39 | #95 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Sorry for digging up an old thread, but I'm coming back to this after a few years, and now am trying a different approach, using my Windows 10 machine to write and cross-compile using VCC, using the VBCC tool chain as found here on EAB: http://eab.abime.net/showthread.php?t=83113
I'm probably doing something stupid, but when I attempt to compile the cleaned up version by Thorham it doesn't compile and gives the following output: Code:
D:\Amiga>vc -o Test1 Test1.c \Users\thema\AppData\Local\Temp\vbcc068c.o: In "_drawGfx": Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x16): Reference to undefined symbol _GfxBase. Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x2e): Reference to undefined symbol _GfxBase. Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x4c): Reference to undefined symbol _GfxBase. Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x62): Reference to undefined symbol _GfxBase. Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x74): Reference to undefined symbol _GfxBase. \Users\thema\AppData\Local\Temp\vbcc068c.o: In "_main": Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x106): Reference to undefined symbol _IntuitionBase. \Users\thema\AppData\Local\Temp\vbcc068c.o: In "l14": Error 21: \Users\thema\AppData\Local\Temp\vbcc068c.o (CODE+0x14a): Reference to undefined symbol _IntuitionBase. vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -mrel "C:\Users\thema\OneDrive\Desktop\vbcc\targets\m68k-amigaos\lib\startup.o" "C:\Users\thema\AppData\Local\Temp\vbcc068c.o" -s -Rshort -L"C:\Users\thema\OneDrive\Desktop\vbcc\targets\m68k-amigaos\lib" -L"C:\Users\thema\OneDrive\Desktop\vbcc\ndk39\include\linker_libs" -lvc -o Test1 failed D:\Amiga> |
14 September 2020, 16:37 | #96 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,213
|
Those are linker errors. Try linking Amiga.lib.
|
14 September 2020, 20:02 | #97 |
Registered User
Join Date: Sep 2014
Location: Poland
Posts: 175
|
Add -lauto option to vlink.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Amiga Coding: where to begin? | Mr Softy | Coders. General | 27 | 01 March 2017 11:32 |
Amiga Emulation Beginner: Questions | beaglelover | New to Emulation or Amiga scene | 1 | 18 February 2016 04:11 |
Got new amiga, some questions about coding | defcon8 | Coders. Asm / Hardware | 2 | 06 April 2015 08:37 |
Any of you Coding on Amiga? | Amiga Forever | Coders. General | 42 | 31 January 2012 02:58 |
Interested in coding on the amiga. | Gandalf | Coders. General | 7 | 16 August 2011 10:30 |
|
|