11 September 2016, 11:50 | #61 | |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Quote:
Now, I'm almost at my wits end, I can't work out what I';m doing wrong with PolyDraw, I keep getting: Code:
argument type incorrect; expecting "WORD *", found "int *" |
|
11 September 2016, 12:16 | #62 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
*double post*
Last edited by Zetr0; 11 September 2016 at 13:06. |
11 September 2016, 12:17 | #63 | |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
This is the point of C/C++ it gets you to have a process of thinking - modularization, implementation then continual refinement
Quote:
try the following - Code:
WORD ppoints[ 9 ]; ppoints[ 0 ] = 0; // since these are assigns ppoints[ 3 ] = 0; // and do not change in the code ppoints[ 4 ] = 200; // its worthless to repeat the assign ppoints[ 7 ] = 200; // better to assign then first ppoints[ 8 ] = 0; // and take only those that change into the loop // = 100 less commands ;) for (WORD candy=0 ; candy < 201; candy +=10 ) { ppoints[ 1 ] = candy; ppoints[ 2 ] = (200 - candy); ppoints[ 5 ] = (200 - candy); ppoints[ 6 ] = candy; ppoints[ 9 ] = candy; PolyDraw( &rastPort, 5, ppoints); } } Last edited by Zetr0; 11 September 2016 at 12:24. |
|
11 September 2016, 12:38 | #64 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Ahh, thank you. Now it builds correctly, without errors, but hangs straight after opening the window. Hmm...
|
11 September 2016, 12:57 | #65 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
|
@The Goto argument
Look, this argument breaks out all over the internet (and in the pub too if your friends are so inclined) whenever Goto is mentioned, and rarely, if ever, reaches an agreement. To be fair, I can't remember ever using it to break out of nested loops - I see how it would make the code simpler but I don't think I've needed to get out of such heavy nesting in such a critical hurry as to warrant it. I'm trying to remember the last time I actually used a Goto, but probably when trying to write super tight timing in an interrupt while developing firmware. ASM might've been a better choice there, but then you're back to using JMP, effectively what Goto compiles to. Also, for me anyway, line numbers went out with the 8-bits. Using Goto with a label is of course totally different readability- and maintenance-wise than a line number, similar to constants versus magic numbers and not dissimilar to calling a function by name. Not sure where line numbers come into it at all. At the end of the day, it's heavily discouraged but it works fine. It's up to the individual programmer whether they want to get into it or not. Use it provided you're happy with the potential consequences, or don't if you want to follow best practices. |
11 September 2016, 13:18 | #66 | ||||
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
Quote:
Code:
void main( void ) { WORD point_array[] = {4, 4, 19, 4, 19,19, 4,19, 4, 4 }; PolyDraw( &rastPort, 5, point_array); } Quote:
Quote:
Quote:
In a nut shell, the use of "goto" is just poor methodology - there are better ways to do it. |
||||
11 September 2016, 13:24 | #67 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
I decided to do it with move and draw instead, and got it working.
I'll come back to PolyDraw and work out what is going on there another day. |
11 September 2016, 13:33 | #68 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@TroyWilkins
I am assuming you have set the raster port and pens? [edit] Yes you have - well done indeed! here's some code that "should work" - its been a while since I have Amiga Coded Code:
#define BLACK 1 int main ( void ) { WORD ppoints[ 9 ]; struct BitMap bitMap = {0}; struct RastPort rastPort = {0}; /* Initialize the RastPort and link the BitMap to it. */ InitRastPort(&rastPort); rastPort.BitMap = &bitMap; SetAPen(&rastPort, BLACK) ppoints[ 0 ] = 0; // since these are assigns ppoints[ 3 ] = 0; // and do not change in the code ppoints[ 4 ] = 200; // its worthless to repeat the assign ppoints[ 7 ] = 200; // better to assign then first ppoints[ 8 ] = 0; // and take only those that change into the loop // = 100 less commands ;) for (WORD candy=0 ; candy < 201; candy +=10 ) { ppoints[ 1 ] = candy; ppoints[ 2 ] = (200 - candy); ppoints[ 5 ] = (200 - candy); ppoints[ 6 ] = candy; ppoints[ 9 ] = candy; PolyDraw( &rastPort, 5, ppoints); } // Dump data to CLI for( peter = 0; peter < 10; peter ++) print("point[%d] = %d\n", peter, ppoints[ peter ]); return 0; } Last edited by Zetr0; 11 September 2016 at 13:44. |
11 September 2016, 13:47 | #69 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
This is what I've got:
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> /* Prototypes for our functions. */ int program_init(void); void program_loop(void); void clean_up(void); /* Global variables. */ struct GfxBase *GfxBase = NULL; struct IntuitionBase *IntuitionBase = NULL; struct Window *MyWindow = NULL; int c; int main(void) { int error; error = program_init(); /* Open needed libraries and the main window. */ if ( !error ) { program_loop(); /* If everything was initialized, execute the main program code. */ } clean_up(); /* We must clean up before we exit. */ return 0; } int program_init(void) { int result = 0; /* First open the graphics.library. */ GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0L ); if ( GfxBase != NULL) { /* Second open the intuition.library. */ IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0L ); /* Was the library opened? */ if ( IntuitionBase != NULL ) { /* Since the library was opened, we can open a window. */ MyWindow = (struct Window *)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 ); /* Was the window opened? */ if ( MyWindow == NULL ) { /* The window was not opened so display a message. */ printf( "Unable to open the window!\n" ); result = -1; } } else { /* The intuition.library was not opened so display a message. */ printf( "Unable to open the intuition.library!\n" ); result = -2; } } else { /* The graphics.library was not opened so display a message. */ printf( "Unable to open the graphics.library!\n" ); result = -3; } return result; } void clean_up(void) { /* If the window is open, close it. */ if ( MyWindow != NULL ) { CloseWindow( MyWindow ); } /* If the intuition.library is open, close it. */ if ( IntuitionBase != NULL ) { CloseLibrary( (struct Library *)IntuitionBase ); } /* If the graphics.library is open, close it. */ if ( GfxBase != NULL ) { CloseLibrary( (struct Library *)GfxBase ); } return; } void program_loop(void) { /* Main program loop. */ for ( c = 0; c < 201; c +=5 ){ Move(MyWindow->RPort, 0, c); Draw(MyWindow->RPort, 200-c,0); Draw(MyWindow->RPort, 200,200-c); Draw(MyWindow->RPort, c,200); Draw(MyWindow->RPort, 0,c); } Delay( 500L ); } |
11 September 2016, 14:00 | #70 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
I found this while trying to find examples of PolyDraw actually being used, which looks interesting:
http://www.memphisamigagroup.net/dis....c?noconvert=1 |
11 September 2016, 14:01 | #71 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@TroyWilkins
I see you are coding under the power of darkness - this is how nature intended such dark arts sir Code:
void program_loop( void ) { /* Main program loop. */ WORD ppoints[ 9 ]; ppoints[ 0 ] = 0; // since these are assigns ppoints[ 3 ] = 0; // and do not change in the code ppoints[ 4 ] = 200; // its worthless to repeat the assign ppoints[ 7 ] = 200; // better to assign then first ppoints[ 8 ] = 0; // and take only those that change into the loop // = 100 less commands ;) for (WORD candy=0 ; candy < 201; candy +=10 ) { ppoints[ 1 ] = candy; ppoints[ 2 ] = (200 - candy); ppoints[ 5 ] = (200 - candy); ppoints[ 6 ] = candy; ppoints[ 9 ] = candy; // lets try this dereference -> Mmmm Pointers ;) PolyDraw(MyWindow->RPort, 5, ppoints); } /* Dump data to CLI for( fred = 0; fred < 10; fred ++) print("%d", ppoints[ fred ]);*/ } |
11 September 2016, 14:10 | #72 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
|
11 September 2016, 14:15 | #73 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@TroyWilkins
In Tasmania / Australia it must be about 10pm ? Yes my mistake, I dereferenced the RastPort pointer incorrectly. |
11 September 2016, 14:16 | #74 | |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Quote:
I've been threatening to quit this since about 7pm, I think I should do so soon, hahaha |
|
11 September 2016, 14:25 | #75 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@TroyWilkins
Fear not I do most of my best work under the power of darkness Lets try this - Code:
void program_loop( void ) { /* Main program loop. */ WORD ppoints[ 9 ]; ppoints[ 0 ] = 0; // since these are assigns ppoints[ 3 ] = 0; // and do not change in the code ppoints[ 4 ] = 200; // its worthless to repeat the assign ppoints[ 7 ] = 200; // better to assign then first ppoints[ 8 ] = 0; // and take only those that change into the loop // = 100 less commands ;) Move (&RPort, 0, 0 ); // make sure we are in the right place for (WORD candy=0 ; candy < 201; candy +=10 ) { ppoints[ 1 ] = candy; ppoints[ 2 ] = (200 - candy); ppoints[ 5 ] = (200 - candy); ppoints[ 6 ] = candy; ppoints[ 9 ] = candy; PolyDraw(&RPort, 5, ppoints); } // I think the data was initially outside either the X/Y boundary // of the Raster Port and or BitMap } |
11 September 2016, 15:50 | #76 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
I am pretty sure SAS C doesn't accept the C99 feature of declaring a 'for' index inside the 'for'.
Just keep your declarations on top of the function. On your working example, bring the declaration of 'c' variable inside the void program_loop(void). It's good practise to keep it local if you can. |
11 September 2016, 15:51 | #77 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,866
|
|
11 September 2016, 16:25 | #78 | |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
Quote:
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 |
|
11 September 2016, 16:58 | #79 |
Amiga Tomcat
Join Date: Sep 2007
Location: Boston Lincs
Posts: 1,502
|
@Zetr0
I found some of your coding at one point. I believe it was on Aminet but can't seem to locate it now!! |
11 September 2016, 16:58 | #80 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,207
|
In C89 you have to start a new code block to declare a new local variable. Of course you can just use a set of curly braces to do that...
|
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 |
|
|