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 96 users online: 1 member, 70 guests and 25 bots.
Members: None.
Bots: VoilaBot (1), VoilaBot (4), Googlebot (19), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
Spenceboy98


Super-Expert


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

Posted: 22 May 2012 08:56:49 pm    Post subject:

Still rebooted, but it displayed half of the pic this time! Yay for a little progress!

Yay! My new method works(I don't know why I didn't try it in the first place)!

Here's code:


Code:
int main() {
  while(1) {
    int key = PRGM_GetKey();
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }
    CopySprite(NyanCat1, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat2, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat3, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat4, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat5, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat6, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat7, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat8, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat9, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat10, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat11, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
    CopySprite(NyanCat12, 0, 0, 160, 160);
    Bdisp_PutDisp_DD();
    Bdisp_AllCr_VRAM();
  }
  return 0;
}
Back to top
Tari


Systems Integrator


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

Posted: 22 May 2012 09:43:45 pm    Post subject:

I think that explains why it was exploding before- you have a bunch of independent images and were assuming they were placed in memory in the same order as the source code, which was probably not the case.

Given the binaries I could verify this (mmm, objdump), but whatever.
_________________


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


Advanced Member


Joined: 07 Jul 2011
Posts: 199

Posted: 23 May 2012 02:04:37 pm    Post subject:

Hurray that it works! However, if I were you, I would put the pics in an array and make a loop. Maybe that's just a style preference, though.
_________________
-LincolnB

Back to top
Spenceboy98


Super-Expert


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

Posted: 23 May 2012 02:20:49 pm    Post subject:

I forgot to include the NyanCat.h in the zip file. Will re-upload it when I have time.
Back to top
Spenceboy98


Super-Expert


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

Posted: 15 Jun 2012 12:02:26 am    Post subject:

Okay, so, quick question. I'm trying to make the green ball move after making the red ball stop, but the green ball doesn't move for some reason. I can't find what went wrong. Can someone figure this out?


Code:
int main() {     
  struct Coord cur;   
  cur.x = 0;   
  cur.y = 92;
  int s = 16;
  int a = 176;
  int b = 0;
  int c = 0;
  while(1) {     
    int key = PRGM_GetKey();     
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }   
    CopySpriteMasked(Target, 142, 58, 100, 100, COLOR_RED); 
    CopySpriteMasked(RedBall, cur.x, cur.y, 32, 32, COLOR_RED);     
    CopySpriteMasked(GreenBall, a, b, 32, 32, COLOR_RED); 
    CopySpriteMasked(Arrow, 181, 146, 21, 70, COLOR_RED); 
    cur.x+=s;
    b+=c;
    if(cur.x >= 352 || cur.x <= 0)
    s = -s;
    if(b >= 184 || b <= 0)
    c = -c;   
    if(key == KEY_PRGM_SHIFT && (s == 16 || s == -16)){
    s = 0;
    c = 16;}
    if(key == KEY_PRGM_SHIFT && (c == 16 || c == -16))
    c = 0;
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();
  }     
  return 0;     
}


Edit: I fixed up the code a little, but it still gives me the same problem.
Back to top
KermMartian


Site Admin


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

Posted: 15 Jun 2012 12:08:54 pm    Post subject:

So a and b control the GreenBall, and cur (.x and .y) control the RedBall. Question: why did you not also use a Coord struct for the GreenBall...? That seems very inconsistent, and that sort of inconsistency is frowned on in programming. It looks like s is the x-velocity of the RedBall, and c is the y-velocity of the GreenBall (Pro Tip: long variable names in C don't cost you anything. Use descriptive variable names!). As makes sense, when you reach one of the edges of the screen, you reverse the direction of the RedBall, and the same with the GreenBall. When you press SHIFT and the RedBall is moving, the code should stop the RedBall and start the GreenBall moving. If you press SHIFT again, then the GreenBall stops too, and both are stopped. I see no particular problem; what happens when you press SHIFT? Does the RedBall stop, and the GreenBall fails to start? Or nothing happens?
_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 15 Jun 2012 01:26:41 pm    Post subject:

When I press SHIFT, the red ball stops, but the green ball doesn't start.

It starts fine without this:

Code:
    if(key == KEY_PRGM_SHIFT && (c == 16 || c == -16)) 
    c = 0;


But without it, it won't stop after pressing SHIFT again.
Back to top
KermMartian


Site Admin


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

Posted: 15 Jun 2012 08:57:10 pm    Post subject:

Ahhh, of course. Try this instead, and please try to puzzle over and figure out what you were doing wrong:


Code:
if (key == KEY_PRGM_SHIFT && (s == 16 || s == -16)) {
    s = 0;
    c = 16;
}
else if(key == KEY_PRGM_SHIFT && (c == 16 || c == -16)) {
    c = 0;
}

_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 15 Jun 2012 09:04:08 pm    Post subject:

Okay, it moves now, but it only moves 16 pixels down and then it stops. Any suggestions?
Back to top
KermMartian


Site Admin


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

Posted: 15 Jun 2012 09:05:03 pm    Post subject:

Spenceboy98 wrote:
Okay, it moves now, but it only moves 16 pixels down and then it stops. Any suggestions?
It's probably a debouncing issue. See if that helps.
_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 15 Jun 2012 09:08:47 pm    Post subject:

I'm not really getting a straight answer from Google, so can you tell me what debouncing is?

Edit: Never mind. I know what it is. I still don't know how to fix it though.

Edit2: Fixed it.
Back to top
KermMartian


Site Admin


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

Posted: 16 Jun 2012 06:25:55 am    Post subject:

Spenceboy98 wrote:
I'm not really getting a straight answer from Google, so can you tell me what debouncing is?

Edit: Never mind. I know what it is. I still don't know how to fix it though.

Edit2: Fixed it.
Great job, debouncing can actually be one of the harder things to get right for a beginner programmer. Glad to hear you managed to work it out on your own.
_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 22 Aug 2012 05:16:08 pm    Post subject:

Okay, new project.


Code:
int main() {
  while(1) {
    int key = PRGM_GetKey();
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }
    Bdisp_EnableColor(1);
    CopySprite(TTTVertical, 56, 0, 5, 56);
    CopySprite(TTTVeritcal, 56, 61, 5, 56);
    CopySprite(TTTVertical, 56, 122, 5, 56);
    CopySprite(TTTVertical, 117, 0, 5, 56);
    CopySprite(TTTVertical, 117, 61, 5, 56);
    CopySprite(TTTVertical, 117, 122, 5, 56);
    CopySprite(TTTHorizontal, 0, 56, 56, 5);
    CopySprite(TTTHorizontal, 61, 56, 56, 5);
    CopySprite(TTTHorizontal, 122, 56, 56, 5);
    CopySprite(TTTHorizontal, 0, 117, 56, 5);
    CopySprite(TTTHorizontal, 61, 117, 56, 5);
    CopySprite(TTTHorizontal, 122, 117, 56, 5);
    Bdisp_PutDisp_DD();   
    Bdisp_AllCr_VRAM();
  }
  return 0;
}


It keeps saying that TTTVertical is undeclared. I put it in the included "TTTData.h", but it still isn't working. Any suggestions?
Back to top
KermMartian


Site Admin


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

Posted: 22 Aug 2012 05:27:28 pm    Post subject:

Do you actually have '#include "TTTData.h"' at the top of that file somewhere? Can you paste us the source of the file, but omitting all of the sprite data for brevity?
_________________


Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 22 Aug 2012 06:21:36 pm    Post subject:

Also, put your data file under the data/ or include/ directory as specified in the Makefile; if you put it in src/ it may cause errors.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
Spenceboy98


Super-Expert


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

Posted: 22 Aug 2012 07:12:14 pm    Post subject:

Here is the full with includes:


Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.h"
#include "TTTData.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 main() {
  while(1) {
    int key = PRGM_GetKey();
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }
    Bdisp_EnableColor(1);
    CopySprite(TTTVertical, 56, 0, 5, 56);
    CopySprite(TTTVeritcal, 56, 61, 5, 56);
    CopySprite(TTTVertical, 56, 122, 5, 56);
    CopySprite(TTTVertical, 117, 0, 5, 56);
    CopySprite(TTTVertical, 117, 61, 5, 56);
    CopySprite(TTTVertical, 117, 122, 5, 56);
    CopySprite(TTTHorizontal, 0, 56, 56, 5);
    CopySprite(TTTHorizontal, 61, 56, 56, 5);
    CopySprite(TTTHorizontal, 122, 56, 56, 5);
    CopySprite(TTTHorizontal, 0, 117, 56, 5);
    CopySprite(TTTHorizontal, 61, 117, 56, 5);
    CopySprite(TTTHorizontal, 122, 117, 56, 5);
    Bdisp_PutDisp_DD();   
    Bdisp_AllCr_VRAM();
  }
  return 0;
}


Edit: I think I know why now. I think it is because I'm trying to use the same sprite over and over again.

Edit2: Can anyone help me with this?
Back to top
KermMartian


Site Admin


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

Posted: 22 Aug 2012 08:19:41 pm    Post subject:

That should not be a problem at all. Can you please post us the source of the sprites file, as I requested in my preceding post (but please omit the actual sprite contents)?
_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 22 Aug 2012 08:24:20 pm    Post subject:


Code:
const color_t TTTX[5000] = {

   };

const color_t TTTVertical[560] = {
      
   };

const color_t TTTO[5000] = {
      
   };

const color_t TTTHorizontal[560] = {
      
   };


Here is TTTData.h without sprite data.
Back to top
KermMartian


Site Admin


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

Posted: 22 Aug 2012 08:27:06 pm    Post subject:

That all looks fine to me. And it doesn't complain about TTTHorizontal being undefined? Are there any other errors, like it not being able to find TTTData.h?
_________________


Back to top
Spenceboy98


Super-Expert


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

Posted: 22 Aug 2012 08:28:52 pm    Post subject:


Code:
main.c: In function 'main':
main.c:30:16: error: 'TTTVeritcal' undeclared (first use in this function)
main.c:30:16: note: each undeclared identifier is reported only once for each fu
nction it appears in
make: *** [main.o] Error 1

That is what it says.
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, 5 ... 11, 12, 13  Next
» View previous topic :: View next topic  
Page 4 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.044643 seconds.