English Amiga Board Amiga Lore


Go Back   English Amiga Board > Coders > Coders. Language

 
 
Thread Tools
Old 11 September 2016, 17:11   #81
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,960
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;
}
drawtest.c

Quote:
Originally Posted by Zetr0 View Post
I used to use Dice / Lattice C as well as SAS - hmmm
SASC6.58 will give you Error 218: declaration in statement block if you try that.
Thorham is offline  
AdSense AdSense  
Old 11 September 2016, 17:22   #82
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 46
Posts: 358
Quote:
Originally Posted by Zetr0 View Post
hmmm I will test this later as I might be wrong but I do remember writing out the following syntax quite often.

for( int index =0; blah ; blah )

and if memory serves I would write this loop out a lot, when chunking data from FAST to CHIP

for( register int index =0; blah ; blah )

I used to use Dice / Lattice C as well as SAS - hmmm
Tested it. Doesn't work.

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
alkis is offline  
Old 11 September 2016, 17:44   #83
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 46
Posts: 358
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,
tells Intuition what messages you are interested for this window to receive.

You can delete mousebuttons and mousemove and make it
Code:
WA_IDCMP, IDCMP_CLOSEWINDOW,
So, only when user clicks the close window button we'll get a message.
Then you can replace the Delay line with
Code:
Wait(1 << myWindow->UserPort->mp_SigBit);
and now the program terminates whenever user closes the window.
alkis is offline  
Old 11 September 2016, 18:06   #84
Zetr0
Ya' like it Retr0?
Zetr0's Avatar
 
Join Date: Jul 2005
Location: United Kingdom
Age: 42
Posts: 9,769
@davideo

Quote:
Originally Posted by davideo View Post
@Zetr0

I found some of your coding at one point. I believe it was on Aminet but can't seem to locate it now!!
LOL, not sure I remember uploading any 'C' code to Aminet, but now you have me excited too =)

@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
Zetr0 is offline  
Old 12 September 2016, 01:19   #85
TroyWilkins
Registered User

TroyWilkins's Avatar
 
Join Date: Jan 2015
Location: Tasmania, Australia
Posts: 344
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.
TroyWilkins is offline  
Old 12 September 2016, 02:22   #86
TroyWilkins
Registered User

TroyWilkins's Avatar
 
Join Date: Jan 2015
Location: Tasmania, Australia
Posts: 344
This looks like a very handy site, I wish I'd found it sooner: http://www.pjhutchison.org/tutorial/amiga_c.html
TroyWilkins is offline  
Old 12 September 2016, 03:15   #87
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,960
Quote:
Originally Posted by TroyWilkins View Post
This looks like a very handy site, I wish I'd found it sooner: http://www.pjhutchison.org/tutorial/amiga_c.html
Don't forget general C sites. SASC6.58 is C89. Anything dealing with that will work (large parts of current C standard).
Thorham is offline  
Old 12 September 2016, 04:09   #88
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 42
Posts: 869
Send a message via Yahoo to Samurai_Crow
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?
Samurai_Crow is offline  
Old 12 September 2016, 05:38   #89
TroyWilkins
Registered User

TroyWilkins's Avatar
 
Join Date: Jan 2015
Location: Tasmania, Australia
Posts: 344
Quote:
Originally Posted by Samurai_Crow View Post
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?
I am somewhat literate in BASIC, although more literate in ancient dialects such as Atari BASIC on the 8-bits, and Commodore BASIC V2. I have meddled with Pascal (a long time ago), Java, and more modern BASIC versions, although I wouldn't consider myself anything more than a beginner using any of them.

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.
TroyWilkins is offline  
Old 12 September 2016, 05:45   #90
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,960
Quote:
Originally Posted by TroyWilkins View Post
I am somewhat literate in BASIC, although more literate in ancient dialects such as Atari BASIC on the 8-bits, and Commodore BASIC V2. I have meddled with Pascal (a long time ago), Java, and more modern BASIC versions, although I wouldn't consider myself anything more than a beginner using any of them.
Then stick with C. The knowledge gained will also be useful on the peecee, because C is C. There's no such thing as Amiga C or peecee C. Except for newer versions having more features than older versions, it's all the same (unless you go way back to the 80s or before). Of course all the system calls will be different, but that's pretty obvious.
Thorham is offline  
Old 12 September 2016, 08:28   #91
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 46
Posts: 358
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!
alkis is offline  
Old 12 September 2016, 10:09   #92
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 42
Posts: 869
Send a message via Yahoo to Samurai_Crow
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.
Samurai_Crow is offline  
Old 30 September 2016, 14:21   #93
Selur
Registered User
 
Join Date: Oct 2006
Location: Poznan/Poland
Age: 40
Posts: 91
On miggy I would chose Amos/Blitz and after that finally assembler, never C.
Selur is offline  
Old 30 September 2016, 14:41   #94
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,960
Quote:
Originally Posted by Selur View Post
never C
Why? C is great for utility software.
Thorham is offline  
AdSense AdSense  
 


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

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:50.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.20518 seconds with 13 queries