CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 123 users online: 5 members, 93 guests and 25 bots.
Members: Ashbad, cvsoft, parrotgeek1, Qwerty.55.
Bots: VoilaBot (1), Spinn3r (1), Magpie Crawler (3), Googlebot (18), MSN/Bing (2).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
zeldaking


Power User


Joined: 31 Jul 2011
Posts: 474
Location: Utah

Posted: 01 May 2012 10:58:25 pm    Post subject:

I agree with Lincoln, the best way is to understand what you are doing. Figure out what is wrong, brainstorm and fix it. How I learned was starting very small asking questions and moved on from there. You might want to understand C a bit more before trying these things. Good luck.
Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 02 May 2012 10:49:17 pm    Post subject:

So, now I know it's called a segfault, but I still don't know how to fix it. There is no errors when compiling. I have no clue what's wrong.
Back to top
PierrotLL


Advanced Newbie


Joined: 29 Nov 2011
Posts: 72
Location: France

Posted: 03 May 2012 05:33:07 am    Post subject:

You must be familiar with the concepts of pointer and memory address.

It's simple, just read your code with brain turned on. If frames==0, you read a 160*160 bitmap at address NyanCat1. If frames==4 (maximum value in your code), you read a 160*160 bitmap at address 4*160*160+NyanCat1. Therefore NyanCat1 is an array of 5 bitmaps 160*160, 16bpp ? NyanCat1 is really an array of 256000 bytes ? If not, you inevitably obtain an error.

I saw you edited your post. Why do you wrote "frames%12" if frames can't be upper than 4 ?
_________________
My fx-9860G & Prizm games
My fx-9860G graphic library, MonochromeLib
Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 03 May 2012 10:31:46 am    Post subject:

I thought the "4" was the amount of frames, so I changed it to "12" because there arre 12 frames.
Back to top
LincolnB


Advanced Member


Joined: 07 Jul 2011
Posts: 199

Posted: 03 May 2012 06:37:23 pm    Post subject:

Why do you need to do frames modulo anything if the max position in the frame variable is exactly equal to the number of frame animations?
_________________
-LincolnB

Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 03 May 2012 06:49:06 pm    Post subject:

I'm not sure what you are saying.
Back to top
LincolnB


Advanced Member


Joined: 07 Jul 2011
Posts: 199

Posted: 03 May 2012 06:51:06 pm    Post subject:

% is the operator for Modulus Division, or a modulo operation. http://lmgtfy.com/?q=modulo will bring up some results if you don't know what the operator does. As far as I can tell, in your code, it's doing absolutely nothing.
_________________
-LincolnB

Back to top
Ashbad


I am governor Jerry Brown


Joined: 01 Dec 2010
Posts: 2423
Location: There lived a certain man in Russia long ago

Posted: 03 May 2012 07:03:37 pm    Post subject:

Basically, Spence, that mod operator has no use there because you're also resetting the value of "frames" every time it hits 4. Since you're doing both, one of them can be taken out (I would say to take out the part where you reset it, since that frames variables will be useful to mod off of for different animations with different amounts of frames and speeds of animation)
_________________
-Ashbad
Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 21 May 2012 06:00:10 pm    Post subject:

Does anyone know what's wrong with this code?


Code:
    #include "stdio.h"
    #include "keyboard.hpp"
    #include "display.h"
    #include "keyboard_syscalls.h"
    #include "stdlib.h"
     
    FILE *fopen(const char *filename, const char *mode);
     
    int PRGM_GetKey(){
      unsigned char buffer[12];
      PRGM_GetKey_OS( buffer );
      return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
    }
     
        FILE *fp;
    int fclose(FILE *a_file);
    int main() {
      while(1) {
        int key = PRGM_GetKey();
        if(key == KEY_PRGM_MENU) {  GetKey(&key); }
        Bdisp_EnableColor(1);
        fp=fopen("test.txt", "r");
        Bdisp_PutDisp_DD();
      }
      fclose(fp);
      return 0;
    }


It keeps giving me this:


Code:
main.o: In function `_main':
main.c:(.text.startup+0x78): undefined reference to `_fopen'
collect2: ld returned 1 exit status
make: *** [TxtEdit.bin] Error 1
Back to top
Tari


Systems Integrator


Joined: 03 Jul 2006
Posts: 2121
Location: Always-winter, Michigan

Posted: 21 May 2012 06:15:55 pm    Post subject:

We don't have much of anything from the standard library (yet). You'll either need to use the Bfile_* family of functions or live on the bleeding edge with the (largely untested) pycompat branch of libfxcg.

The latter choice is more desirable from my viewpoint (as it gets somebody using and testing this new code), but will involve chasing down bugs and some additional manual setup.
_________________


Ask questions the smart way · タリ
Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 21 May 2012 07:07:55 pm    Post subject:

Okay. So I changed some of the stuff in the Nyan Cat addin again, but it still is crashing my calculator. It compiles perfectly though...


Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.h"
#include "NyanCat.h"

void CopySprite(const void* datar, int x, int y, int width, int height) {
   color_t*data = (color_t*) datar;
   color_t* VRAM = (color_t*)0xA8000000;
   VRAM += LCD_WIDTH_PX*y + x;
   for(int j=y; j<y+height; j++) {
      for(int i=x; i<x+width; i++) {
         *(VRAM++) = *(data++);
     }
     VRAM += LCD_WIDTH_PX-width;
   }
}
int PRGM_GetKey(){
  unsigned char buffer[12];
  PRGM_GetKey_OS( buffer );
  return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
int f = 1;
int main() {
  while(1) {
    int key = PRGM_GetKey();
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }
    CopySprite(f%12*160*160+(color_t*)NyanCat1, 0, 0, 160, 160);
    f++;
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
  }
  return 0;
}
Back to top
LincolnB


Advanced Member


Joined: 07 Jul 2011
Posts: 199

Posted: 22 May 2012 04:00:15 pm    Post subject:

It crashes? You're probably going to need to be more specific. What exactly happens when you run the application?
_________________
-LincolnB

Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55882
Location: Earth, Sol, Milky Way

Posted: 22 May 2012 07:35:27 pm    Post subject:

LincolnB wrote:
It crashes? You're probably going to need to be more specific. What exactly happens when you run the application?
Seconded. You also need to learn to do some debugging on your own. For example, comment out the sprite-drawing routine and see if it still crashes. If so, comment out more stuff. When it stops crashing, you can then gradually add stuff back in until it starts crashing again. Voila.
_________________


Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 22 May 2012 07:38:41 pm    Post subject:

LincolnB wrote:
It crashes? You're probably going to need to be more specific. What exactly happens when you run the application?


Well, when I run the addin, it displays a white screen, then it displays the reboot menu.

KermMartian wrote:
LincolnB wrote:
It crashes? You're probably going to need to be more specific. What exactly happens when you run the application?
Seconded. You also need to learn to do some debugging on your own. For example, comment out the sprite-drawing routine and see if it still crashes. If so, comment out more stuff. When it stops crashing, you can then gradually add stuff back in until it starts crashing again. Voila.


Comment it out? I'm not sure what you mean.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55882
Location: Earth, Sol, Milky Way

Posted: 22 May 2012 07:43:51 pm    Post subject:

When you comment out code, it means you wrap it in /* */, or you put //s before it, turning it into comments so that it doesn't run that part of the program. By removing bits of the program, you can narrow down where bugs are occurring.
_________________


Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 22 May 2012 07:45:26 pm    Post subject:

Okay. I might try that. I wish there were an easier way. Like running it though a program or something.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55882
Location: Earth, Sol, Milky Way

Posted: 22 May 2012 07:46:45 pm    Post subject:

Spenceboy98 wrote:
Okay. I might try that. I wish there were an easier way. Like running it though a program or something.
If programs could fix programs, then we wouldn't need programmers. Wink Actually, when you're testing on a more mature platform, there's a program called GDB (the GNU DeBugger). It will show you the exact line number where a segmentation fault occurred when you get a seg-fault, which makes debugging this kind of problem much, much easier. Sadly, we have no gdb for the Prizm yet.
_________________


Back to top
Spenceboy98


Super-Expert


Joined: 06 Jan 2012
Posts: 855
Location: In the TARDIS

Posted: 22 May 2012 07:57:10 pm    Post subject:

Okay. It's the "CopySprite(f%12*160*160+(color_t*)NyanCat1, 0, 0, 160, 160);" line. I still don't understand what's wrong though.
Back to top
LincolnB


Advanced Member


Joined: 07 Jul 2011
Posts: 199

Posted: 22 May 2012 08:46:03 pm    Post subject:

A seg fault occurs when you try to access a memory location that doesn't exist. This means you have a pointer that went wrong somewhere. (You do know about pointers, right?) So, somewhere in that CopySprite line, you are trying to access a memory location that is somehow invalid (or nonexistent)
_________________
-LincolnB

Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 22 May 2012 08:51:33 pm    Post subject:

Hmm, maybe you could add a bunch of parentheses so that you know for sure it isn't a math error:

Code:
CopySprite((color_t*)(NyanCat1+(f%12)*(160*160)), 0, 0, 160, 160);

I don't really see anything wrong with your code, though. :/
_________________
CALCnet Tournament-38%


deviantArt
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page Previous  1, 2, 3, 4 ... 11, 12, 13  Next
» View previous topic :: View next topic  
Page 3 of 13 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.043539 seconds.