![]() |
![]() |
#41 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Now, my next little project is to do the same as this old little BASIC program I did in Atari BASIC on the Atari 400, only in an Intuition window on the workbench screen. I'm thinking that using PolyDraw within a loop would be the best way to do this, with the window being a fixed size to begin with, then later adapt it to be re sizable and to clear itself when resized and then determine the internal size and draw it to suit the new window size.
[ Show youtube player ] It's not much, and it's certainly no megademo, but it would be a start at getting comfortable. |
![]() |
![]() |
#42 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,839
|
Quote:
![]() When you have it running, post the code. Beginners tend to not use language features properly, and we can help with that. Also, don't let your mind be polluted by people telling you that goto is evil, because it has it's uses in C. |
|
![]() |
![]() |
#43 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,379
|
Funny, I was just writing an article about an introduction to programming and was talking about Goto. It's certainly not evil, but I would say that 90% of the time there's a better way of doing it. That remaining 10% though? Absolutely, go for it. Sometimes it's the simplest, most efficient way of doing things. The important thing is to know what's best for a particular situation.
Edit: Oh, and nice work on the Atari! I used an 800XL for years, that blue screen and keyboard noise instantly brings me back and now I've got a craving for an Atari emulator... ![]() Last edited by Daedalus; 10 September 2016 at 01:12. |
![]() |
![]() |
#44 | ||
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Quote:
Quote:
Oh, and thank you about my little program on the Atari, I'm sure it could be written better, but it was just a quick thing I belted out in an emulator - I had to look up the exact syntax for the setcolor and drawto commands, as I didn't remember them exactly after all these years, and I stole the turning off DMA trick from another code listing I found online, but other than that, it was all my own crappy work belted out in maybe an hour, just to scratch the itch I had for doing some quick and dirty programming, and to show the missus and kids one of the things I used to do on computers before the internet, hahaha. I figure adapting it to run in C and run within a window, using the system to draw it, should help me not only understand C better, but also help adapt my way of thinking to the new language. Also, I have to admit to being curious to see how much faster it can do it on an A600 when compared to on the old Atari 8 bit, which as I'm sure you know, didn't exactly have a fast version of BASIC. |
||
![]() |
![]() |
#45 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,839
|
Quote:
![]() It's useful for exception handling and breaking out of nested loops. Keeps you from having to write annoying code. There are probably some other minor uses that occur (very) infrequently. |
|
![]() |
![]() |
#46 | ||||
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
Quote:
Its uses are not only limited but it better expressed without them. Quote:
Quote:
![]() Quote:
|
||||
![]() |
![]() |
#47 | |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Quote:
I've fiddled with the code I found here, made a few changes: http://amigacoder.x10.mx/tutorial/draw.html And here is a link to what I got up and running (yeah, there is a bug in it when you initially start drawing, as I have not set X_coord and Y_coord to have any initial values, but for learning purposes it does the job): https://dl.dropboxusercontent.com/u/22028650/drawdemo.c From what I've read (on http://wiki.amigaos.net/wiki/Graphic...Single_Command), to draw the squares required for my little pattern drawing program, PolyDraw with an appropriately setup array, with the array being altered during the main loop after each draw, looks to me to be the best method, not only for achieving my goal, but for enabling it to be flexable enough to allow changes to the window size to be taken into consideration later once I have this running the way I want, while helping me become more comfortable with the use and manipulation of arrays in C. After all, this journey is more about learning and getting comfortable, rather than the end product - after all, I freely admit that this will be completely pointless, but I'm enjoying the intellectual challenge. |
|
![]() |
![]() |
#48 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,839
|
|
![]() |
![]() |
#49 | ||||||
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,379
|
Quote:
Quote:
Quote:
![]() Quote:
![]() Quote:
Quote:
|
||||||
![]() |
![]() |
#50 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,379
|
True, they don't fit very well in a procedural language, and yes, there is always another method available than using Goto, but sometimes - just sometimes, that alternative method is longer, slower and actually harder to follow. It can be considered a hack and impure and what not, but at the end of the day, it works well and provided you don't do anything that makes the code harder to follow or do terrible thing like jumping out of constructs, it won't cause you any problems.
|
![]() |
![]() |
#51 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@Thorham / Daedalus
The fact that this "goto" expression exists in 'C' / C++ proves the point that it it shouldn't - it is legacy "ancient" thinking, and using this expression is utterly pointless and should only exist in a limited stack environment- in over 27 years of C programming (16 of them in a commercial sense) I have never had to use them, even when I am proving a point about run-time-polymorphism - which you can do in C. The only time I have seen "goto's" used is when a chap I worked with used "in line" assembly - and he used it this way because he couldn't be arsed to count in the program counter for his variables in his asm C wrapper functions. I am pretty confident in saying if someone can show me a use of the "goto" statement in 'C' I could write it better / faster in a function (even recursively). |
![]() |
![]() |
#52 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
|
Regarding goto, for exception handling look at setjmp.h in the runtimes for a better way to do it without goto. Regarding exiting loops, the exit command and continue command do just as well in most cases.
|
![]() |
![]() |
#53 | ||||
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,839
|
Quote:
Quote:
Quote:
Quote:
![]() All this goto hate is just ridiculous. I've never, ever, seen any good arguments against goto at all. Actually, I wish I hadn't brought it up ![]() |
||||
![]() |
![]() |
#54 | |
Rumpig
Join Date: Aug 2006
Location: The bottom of the bottle
Age: 93
Posts: 254
|
Quote:
All this 'anti-goto' nonsense is the result of fear mongering by Wirth and Dijkstra. |
|
![]() |
![]() |
#55 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
Oooookay, I think enough has been said about the merits (or lack thereof) of goto now...
I think I may have bitten off more than I can currently chew with regards to C, but in a way, that's intentional. I could easily convert that linedraw program from Atari basic to C if I was to use Move() and Draw() to replace plot and drawto, but that wouldn't really help advance my knowledge in the way that I am trying to do. Also, I'm not entirely sure how to replicate a for/next/step 10 basic loop in C, all the examples I've found deal in increments of +1, or do I have to go about that a different way? Ahh, I should have just googled this, t seems this may be a way: Code:
int i; for(i = 1; i < 10; i += 2) printf("%d\n", i); |
![]() |
![]() |
#56 | |
Amigan
![]() Join Date: Feb 2012
Location: London
Posts: 1,316
|
Quote:
Code:
if ((err = SSLHashSHA1.update(&hashCtx, &clientRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail; err = sslRawVerify(...); |
|
![]() |
![]() |
#57 |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@TroyWilkins
LOL indeed, goto's in 'C' generally cause a fuss - for the record I don't think there evil, just that they break the methodology of 'C' and is arguably only included as a legacy from other languages. you can also write you your expression as such - The For ( *declaration / initialization ; *condition ; *variable_change) { *statements } Code:
for(int i = 1; i < 10; i +=2) printf("%d\n", i); Here is another loop type The While ( condition ){ *statement } Loop Code:
int i = 1; while (i < 10 ) { i+=2; printf(%d\n", i ); } Do { *statement } While ( *condition ) Loop Code:
int i = 1; do { printf(%d\n",i ); i += 2; }while ( i < 10 ); The For Loop initializes what you want at the start of the loop, checks the condition, processes the statements and increments the loop counter - in the above case that is print i to the screen. it then checks condition and increments - this repeats until 'i' = 11 and prints to the screen - it then then stops as the condition of 'i' is ">10" For - Expected output Code:
1 3 5 7 9 11 While - Expected Output Code:
1 3 5 7 9 11 The Do While Loop is interesting as it always processes your statements once before checking the condition of variables - so in the above case the output would be different as the condition check happens after the increment - such that - Do While - Expected Output Code:
1 3 5 7 9 Code:
int i = 1; do { i += 2; printf("%d\n", i ); }while ( i < 10 ); Code:
3, 5, 7, 9, 11 Last edited by Zetr0; 11 September 2016 at 12:02. |
![]() |
![]() |
#58 |
Registered User
Join Date: Jan 2015
Location: Melbourne, Australia
Posts: 548
|
I've got this as the basis for the calculations for the points to put in the array that will be called:
Code:
for ( c = 0; c < 201; c +=10 ){ PLo[0] = 0; PLo[1] = c; PLo[2] = 200 - c; PLo[3] = 0; PLo[4] = 200; PLo[5] = 200 - c; PLo[6] = c; PLo[7] = 200; PLo[8] = 0; PLo[9] = c; /* use PolyDraw(&rastPort, 5, PLo); */ } |
![]() |
![]() |
#59 | ||||
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
@Thorham
You have made quite an assumption about my coding practices based on my dislike for "goto" statements in "C / C++", hardly seems fair Quote:
Quote:
Quote:
Quote:
Personally I think it is great that you have "mentioned" it as it highlights the "more than one way to skin a cat" in C/C++ - it also echo's to what my lecture said way back in 1993/4 - "As long as it works, there's no such thing as bad code - only better code" In my opinion (and it is just that, my opinion) 'C / C++' is a really beautiful language, it is a means of thought and more so a methodology of logic that is both elegant and expressive the use of a "goto" statement that is dependent on line number kinda fcuks that all up ![]() I can spend days coding (and have at that) - in this time I lose the ability to formulate English, and it can take me a good hour not not sound like "Yoda" from Star Wars =) Last edited by Zetr0; 11 September 2016 at 11:39. |
||||
![]() |
![]() |
#60 | |
Ya' like it Retr0?
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
|
Quote:
Code:
void main( void ) { int 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 (int 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 11:35. |
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
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 |
|
|