• What do you need help with? V4 (January 2012)
    966 replies, posted
I was wondering if there is a cheatsheet or good reference for x86 and x64 asm opcodes? I'm learning the mips 86 architecture in class and was curious.
Guys, we are doing Arduino programming in an afterschool competition to build an autonomous robot. One of the prerequisites is for us to program a section of code that allows it to avoid obstacles and steer around them. I understand most of the code, but some parts I don't understand. I will post them here in the hope that you guys can tell me what the hell the code is saying. I really want to be able to actually [I]understand[/I] what I am writing. Here goes; [CODE] noInterrupts(); if((fwdsn = getPing(5)) ! = 0) front = frontc; interrupts(); delay(15); noInterrupts();[/CODE] What are the function of the Interrupts commands? I don't quite understand [CODE]while ( ((millis()-starttime<1000) || front<5500 ) && ((digitalRead(13)==1) && (digitalRead(12)==1))) { front = getPing(5); delay(5); } [/CODE] What the bloody hell is the millis command. And why the funny lines and ampersands? I am so lost, please help me! Thanks
Read this: [url]http://arduino.cc/en/Reference/HomePage[/url] Anyway, trying to work with pdcurses but I can't seem to draw a window on the screen. I have a 50 by 25 "image" on the left, and I am trying to draw a box on the right with this: [cpp]WINDOW * sidebar = newwin(25,25,0,50); wattron(sidebar,COLOR_PAIR(2)); wborder(sidebar, '?', '?', '?', '?', 'X', 'x', 'X', 'x'); wattroff(sidebar, COLOR_PAIR(2)); wrefresh(sidebar);[/cpp] Doesn't work though. The example does, but mine does not.
[QUOTE=paindoc;34472414][CODE]noInterrupts(); if((fwdsn = getPing(5)) ! = 0) front = frontc; interrupts(); delay(15); noInterrupts();[/CODE] [CODE]while ( ((millis()-starttime<1000) || front<5500 ) && ((digitalRead(13)==1) && (digitalRead(12)==1))) { front = getPing(5); delay(5); } [/CODE][/QUOTE] the problem here is most of the code is written really concisely so it's hard to read. In general, it's easy to write code and difficult to read it. I'm going to try and guess what's going on here and comment it a bit so you can understand it, but bear in mind I have no experience with arduino programming so a lot of it will be guesswork. [cpp] // Turn interrupts off noInterrupts(); // if((fwdsn = getPing(5)) ! = 0) front = frontc; // is the same as fwdsn = getPing(5); // Set "fwdsn" to getPing(5); if(fwdsn != 0) // if getPing(5) returned zero front = frontc; // set front to frontc // Re-enable interrupt processing interrupts(); // Delay for 15 milliseconds delay(15); // Turn interrupt processing back off noInterrupts(); [/cpp] I assume the "interrupts" commands enable\disable interrupt processing. If interrupts are disabled, I assume processing of the next part will happen regardless. If interrupts are enabled, I assume that critical events that occur such as touching a wall or something like that will take priority. And then for the second part [cpp] /* While digital pins 12 and 13 are both recieving input, AND either: - front is less than 5500, OR - less than one second has elapsed */ while(((millis()-starttime<1000) || front<5500 ) && ((digitalRead(13)==1) && (digitalRead(12)==1))) { // Set "front" to getPing(5); front = getPing(5); // Delay processing for 5 milliseconds delay(5); } [/cpp] That's what I interpret the code as. Your question regarding the "millis" command I assume to be "milliseconds", a function returning the milliseconds since some arbitrary origin. The 'funny lines': There are line breaks inserted into the large block in an attempt to make it easier to read. The 'ampersands': The && is the logical "and" operator, just like || is the logical "or" operator.
Bit of a cross post, but I'm trying to get the size and position of all open windows in C#. [img_thumb]http://i.imgur.com/njLa4.jpg[/img_thumb] As you can see, it isn't exactly working. I'm first getting a list of each window handle via [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx]EnumWindows[/url], then cycle through each handle with [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519%28v=vs.85%29.aspx]GetWindowRect[/url]. I don't see any room for error here, I even force fed my drawing functions an example window and it worked flawlessly. Anyone else experienced with this?
[QUOTE=Sprite;34464985]How does google index all that data and access it so fast? I mean... If I stored everything in a MySQL database, there is no way in the actual fuck I could pull 10 top results in science. Like really. How do they even? I need to know for my project.[/QUOTE] I don't know about Google, but Reddit uses [URL="http://memcached.org/"]memcached[/URL] and [URL="http://en.wikipedia.org/wiki/Apache_Cassandra"]Cassandra[/URL]
I'm currently in a class teaching programming in C and have an assignment to develop a particular program that does various calculations such as summing numbers in an array, conditionals within for loops, etc. I did most of the dirty work at home and decided to compile and test it in class today (our computers in class use nano and compile with gcc). Everything worked perfectly and I figured I'd go back home to clean up the code a little so it's more presentable for turning in. Unfortunately, when I re-ran the exact same code at home using a different compiler program (Code blocks, but still compiling with gcc), the program was returning different results for the same inputs, which caused test cases to fail and essentially makes it seem like my program doesn't actually work properly. Just out of curiosity, I downloaded a different program that compiles with gcc and it makes it so that all of the results are off by just one. So three different compilers are giving three different results for the exact same code. Any reason for this or how to deal with this kind of problem? I'm not sure which one to trust and whether or not to turn in my code since my teacher might run it and it won't work on his computer. I don't want to necessarily post the code since I'm not supposed to get outside help on developing it, but I figure it's okay to ask about something like this. Actually here's just a small snippet of the code that's having problems all by itself: [code]void sum_odds(int cnum[], int osum[]) { int i; for(i=1; i<=13; i+=2) { osum[0] += cnum[i]; } }[/code] The program is made to take in exactly 16 integers, and this particular function wants to add the odd integers given (where the input is integer0, integer1, integer2, etc.) together except for what would be the final integer. If I give the program cnum[16] = {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; : - In class it produces 0, as it should. - At home on Codeblocks it produces 49152, which is way off and I have no idea how it could even get that. - At home on cygwin it produces 1, which is one more than it should be.
[QUOTE=DSG;34474425]I'm currently in a class teaching programming in C and have an assignment to develop a particular program that does various calculations such as summing numbers in an array, conditionals within for loops, etc. I did most of the dirty work at home and decided to compile and test it in class today (our computers in class use nano and compile with gcc). Everything worked perfectly and I figured I'd go back home to clean up the code a little so it's more presentable for turning in. Unfortunately, when I re-ran the exact same code at home using a different compiler program (Code blocks, but still compiling with gcc), the program was returning different results for the same inputs, which caused test cases to fail and essentially makes it seem like my program doesn't actually work properly. Just out of curiosity, I downloaded a different program that compiles with gcc and it makes it so that all of the results are off by just one. So three different compilers are giving three different results for the exact same code. Any reason for this or how to deal with this kind of problem? I'm not sure which one to trust and whether or not to turn in my code since my teacher might run it and it won't work on his computer. I don't want to necessarily post the code since I'm not supposed to get outside help on developing it, but I figure it's okay to ask about something like this. Actually here's just a small snippet of the code that's having problems all by itself: [code]void sum_odds(int cnum[], int osum[]) { int i; for(i=1; i<=13; i+=2) { osum[0] += cnum[i]; } }[/code] The program is made to take in exactly 16 integers, and this particular function wants to add the odd integers given (where the input is integer0, integer1, integer2, etc.) together except for what would be the final integer. If I give the program cnum[16] = {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; : - In class it produces 0, as it should. - At home on Codeblocks it produces 49152, which is way off and I have no idea how it could even get that. - At home on cygwin it produces 1, which is one more than it should be.[/QUOTE] You should initialize osum to 0. You can use an int * too instead of an array
[QUOTE=DSG;34474425]- In class it produces 0, as it should. - At home on Codeblocks it produces 49152, which is way off and I have no idea how it could even get that. - At home on cygwin it produces 1, which is one more than it should be.[/QUOTE] You're accessing an uninitialized variable, which means you're accessing random memory. This random memory can have [i]any[/i] value, depending on the version of the compiler, the OS, and the specific computer you're running on. Initialize the variable to zero first.
I fixed my PDCurses problem by moving the refresh command to be after the main screens.
[QUOTE=DesolateGrun;34471037]How can I convert .swf files to .png's?[/QUOTE] prnt scrn [editline]31st January 2012[/editline] [QUOTE=Topgamer7;34470511]Like the guy above said, they store some data in memory, and if I recall they dump it to a database of sorts every once in a while. They use an algorithm that's commonly referred to as map-reduce for parsing data. They also have a section about it: [URL="http://code.google.com/edu/parallel/mapreduce-tutorial.html"]clickyidy clack.[/URL][/QUOTE] thanks for this btw
In curses, would it be smart to use multiple windows to create layers? Like an underyling map layer, a GUI layer ontop of that, an entity layer (so that I can move characters without having to redraw the map), and a pop up layer(for conversations etc.).
[QUOTE=FoohyAB;34474195]Bit of a cross post, but I'm trying to get the size and position of all open windows in C#. [img_thumb]http://i.imgur.com/njLa4.jpg[/img_thumb] As you can see, it isn't exactly working. I'm first getting a list of each window handle via [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx]EnumWindows[/url], then cycle through each handle with [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519%28v=vs.85%29.aspx]GetWindowRect[/url]. I don't see any room for error here, I even force fed my drawing functions an example window and it worked flawlessly. Anyone else experienced with this?[/QUOTE] Looks to me like it's getting old/non-active windows. Can you check if a window has the Minimized flag?
I'm learning C++ off of a book from 1997, is this going to hurt my learning of the language?
[QUOTE=Octave;34474956]You should initialize osum to 0. You can use an int * too instead of an array[/QUOTE] [QUOTE=shill le 2nd;34475358]You're accessing an uninitialized variable, which means you're accessing random memory. This random memory can have [i]any[/i] value, depending on the version of the compiler, the OS, and the specific computer you're running on. Initialize the variable to zero first.[/QUOTE] I tried setting osum[0] = 0 and it gave me a ton of errors when compiling. Then I tried setting osum = 0 and it compiled, but when I ran it the program immediately stopped working. If I use int * instead of an array for osum, would the data type for things like printf still be %d or is it something different? (we haven't really gone much over pointers in my class)
[QUOTE=chonks;34479100]I'm learning C++ off of a book from 1997, is this going to hurt my learning of the language?[/QUOTE] Depends on what the exact book is. There have been numerous new standards of C++ since 1997. Simpler stuff hasn't changed, but more advanced things have gotten some changes.
[QUOTE=FoohyAB;34474195]Bit of a cross post, but I'm trying to get the size and position of all open windows in C#. [img_thumb]http://i.imgur.com/njLa4.jpg[/img_thumb] As you can see, it isn't exactly working. I'm first getting a list of each window handle via [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx]EnumWindows[/url], then cycle through each handle with [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519%28v=vs.85%29.aspx]GetWindowRect[/url]. I don't see any room for error here, I even force fed my drawing functions an example window and it worked flawlessly. Anyone else experienced with this?[/QUOTE] EnumWindows gets all windows even minimized and invisible ones. You need to check if the window is actually visible. You can use GetWindowInfo for that.
[QUOTE=sim642;34479507]Depends on what the exact book is. There have been numerous new standards of C++ since 1997. Simpler stuff hasn't changed, but more advanced things have gotten some changes.[/QUOTE] The book is Sam's Teach Yourself C++ in 21 Days, Second Edition. The only thing going through the basic hello world function that it's missing so far is "std::" before cout. Don't know if that's a critical concept, I might be able to just fill in the blanks looking through documentation on it.
[QUOTE=chonks;34480434]The book is Sam's Teach Yourself C++ in 21 Days, Second Edition. The only thing going through the basic hello world function that it's missing so far is "std::" before cout. Don't know if that's a critical concept, I might be able to just fill in the blanks looking through documentation on it.[/QUOTE] That means they will have used [code] using namespace std; [/code] at the start, which just means that you don't have to type std:: every time you use something from it. It's pretty much personal preference whether you do it or not.
Can some kind soul help me with bloody trigonometry? If I have an equlateral triangle and I know its center call it Or.x Or.y I also know the length of the side sL I know the height from botom to top: sL * Math.sin(60.0) and thus the position of the first point: Or.x, Or.y - height/2 But how do I gt the other 2 points?
[QUOTE=Richy19;34480830]Can some kind soul help me with bloody trigonometry? If I have an equlateral triangle and I know its center call it Or.x Or.y I also know the length of the side sL I know the height from botom to top: sL * Math.sin(60.0) and thus the position of the first point: Or.x, Or.y - height/2 But how do I gt the other 2 points?[/QUOTE] Assuming you're using degrees and 0 degrees points straight up: [code] float rad = 0.5f sL * Math.sin(60); vec2 p1 = Or + vec2(cos(0), sin(0)) * rad; vec2 p2 = Or + vec2(cos(60), sin(60)) * rad; vec2 p3 = Or + vec2(cos(120), sin(120)) * rad; [/code]
[QUOTE=NovembrDobby;34480947]Assuming you're using degrees and 0 degrees points straight up: [code] float rad = 0.5f sL * Math.sin(60); vec2 p1 = Or + vec2(cos(0), sin(0)) * rad; vec2 p2 = Or + vec2(cos(60), sin(60)) * rad; vec2 p3 = Or + vec2(cos(120), sin(120)) * rad; [/code][/QUOTE] Just to make sure float rad = 0.5f sL * Math.sin(60); is that meant to be 0.5 * sL * Math.sin(60)
[QUOTE=NovembrDobby;34480477]That means they will have used [code] using namespace std; [/code] at the start, which just means that you don't have to type std:: every time you use something from it. It's pretty much personal preference whether you do it or not.[/QUOTE] Personal preference to the point where you don't name your functions anything that's already in the standard library namespace.
[QUOTE=NovembrDobby;34480947]Assuming you're using degrees and 0 degrees points straight up: [code] float rad = 0.5f sL * Math.sin(60); vec2 p1 = Or + vec2(cos(0), sin(0)) * rad; vec2 p2 = Or + vec2(cos(60), sin(60)) * rad; vec2 p3 = Or + vec2(cos(120), sin(120)) * rad; [/code][/QUOTE] Using this: [code]double rad = 0.5 * sL * Math.sin(60); int pointsX = (int)(x + Math.cos(0) * rad); int pointsY = (int)(y + Math.sin(0) * rad); polygon.addPoint(pointsX, pointsY); pointsX = (int)(x + Math.cos(60) * rad); pointsY = (int)(y + Math.sin(60) * rad); polygon.addPoint(pointsX, pointsY); pointsX = (int)(x + Math.cos(120) * rad); pointsY = (int)(y + Math.sin(120) * rad); polygon.addPoint(pointsX, pointsY);[/code] I get this: [IMG]http://i.imgur.com/g5hKf.png[/IMG] But using this(which i find easier to understand): [code]double height = sL * (Math.sqrt(3.0)/2.0); int pointsXo = x; int pointsYo = (int)Math.round(y - (height/2.0)); polygon.addPoint(pointsXo, pointsYo); int pointsX = (int)Math.round(x + (sL/2.0)); int pointsY = (int)Math.round(pointsYo + height); polygon.addPoint(pointsX, pointsY); pointsX = (int)Math.round(x - (sL/2.0)); pointsY = (int)Math.round(pointsYo + height); polygon.addPoint(pointsX, pointsY); [/code] I get this(which still isnt correct as the top point is more sepperated than the 2 bottom ones). The windows window in the background is what its meant to look like [IMG]http://i.imgur.com/RgYoV.png[/IMG] [editline]31st January 2012[/editline] BTW this is the triangle creation: [code]new Circle(250, 150, 100, red), new Circle(250, 150, 70, yellow), new EQTriangle(250, 150, 80, black)[/code]
[QUOTE=DSG;34479488]I tried setting osum[0] = 0 and it gave me a ton of errors when compiling. Then I tried setting osum = 0 and it compiled, but when I ran it the program immediately stopped working. If I use int * instead of an array for osum, would the data type for things like printf still be %d or is it something different? (we haven't really gone much over pointers in my class)[/QUOTE] The format strings stay the same, but when you access the value you must [i]dereference[/i] it with *. So: [code]*osum = 50; ... printf("%d\n", *osum);[/code]
[QUOTE=DSG;34479488]I tried setting osum[0] = 0 and it gave me a ton of errors when compiling. [/QUOTE] Like what errors?
Can anybody please post an example of php code that loads an image from a URL and outputs it when opened in a browser, similar to how the OIFY banner/icon scripts work? I can't get it to stop trying to download the php as a text file. [editline]e[/editline] Okay, after a very long time I have found this: [code]<? $img="example.gif"; header ('content-type: image/gif'); readfile($img); ?> [/code] But when targeted with a browser it just tries to download the php file rather than display the image! Can anybody explain what I'm doing wrong?
Is your server properly configured? Because if it's downloading the PHP file as a text file it's most likely an issue with your server not having php installed or something.
[QUOTE=shill le 2nd;34487853]Like what errors?[/QUOTE] Doesn't matter anymore since I fixed it by just stating "int osum[1] = {0};" but when I did "osum[0] = 0;" it gave me: warning: ISO C forbids zero-size array 'osum' error: 'osum' redeclared as different kind of symbol note: previous definition of 'osum' was here error: invalid initializer
[QUOTE=DSG;34489102]Doesn't matter anymore since I fixed it by just stating "int osum[1] = {0};" but when I did "osum[0] = 0;" it gave me: warning: ISO C forbids zero-size array 'osum' error: 'osum' redeclared as different kind of symbol note: previous definition of 'osum' was here error: invalid initializer[/QUOTE] When you declare an 'array' in C++, you have to also declare the size of it. Like so [code] int array[256]; [/code] That array can hold 256 integer objects.
Sorry, you need to Log In to post a reply to this thread.