Hello, I am trying to make a cursor move across the screen on C, but I have no idea on how to make the sprite move. I made it display the sprite at 0,0. I don't know what to do or what code to use to move it. Help is appreciated.
You can use this function for key-detection.
About "store variables properly", it depends on what you want, you can make a struct Coord { int x, y; };
with a function like
Code:
About "store variables properly", it depends on what you want, you can make a struct Coord { int x, y; };
with a function like
Code:
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
I suggest you go through a C tutorial somewhere to learn the basics of C, such as pointers, variables, loops, and such.
To answer your questions, you declare and store to variables like this:
Code:
Then, to read a keypress, use one of the key input syscalls/routines such as GetKey() and PRGM_GetKey().
Code:
To answer your questions, you declare and store to variables like this:
Code:
int key = 0;
Then, to read a keypress, use one of the key input syscalls/routines such as GetKey() and PRGM_GetKey().
Code:
GetKey(&key);
An additional note is that you need to erase the sprite before you move it, and redraw it afterwards. It would probably be way too slow to erase the the whole screen and re-drawing whatever you need.
How do I store the variables(x and y)? I'm not sure what code I should use. What order do I put the code?
Create the variables first, then use the function getkey.
It would be like:
Code:
I don't know C, but I got this much reading this topic already.
It would be like:
Code:
int key = 0;
int x = 0;
int y = 0;
Getkey(&key);
If(key) {
If up
X++;
...
}
I don't know C, but I got this much reading this topic already.
Kerm, how would I clear the space behind it without refreshing the whole screen?
This is the code I am using:
Code:
This is what it gives me:
Code:
What can I do to fix it?
This is the code I am using:
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.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 );
}
const char BigCursor[504] = {
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
};
int x = 0;
int y = 0;
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
int main() {
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BigCursor, x, y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
This is what it gives me:
Code:
../..//bin/sh3eb-elf-gcc.exe -c -m3 -mb -O3 -mhitachi -Wall -nostdlib -I../..//
include -lfxcg -lgcc -L../..//lib -std=c99 main.c -o main.o
main.c:49:24: warning: 'struct Coord' declared inside parameter list [enabled by
default]
main.c:49:24: warning: its scope is only this definition or declaration, which i
s probably not what you want [enabled by default]
main.c: In function 'moveCursor':
main.c:50:4: warning: implicit declaration of function 'keydown' [-Wimplicit-fun
ction-declaration]
main.c:50:38: error: dereferencing pointer to incomplete type
main.c:50:51: error: dereferencing pointer to incomplete type
main.c:51:40: error: dereferencing pointer to incomplete type
main.c:51:65: error: dereferencing pointer to incomplete type
main.c:52:40: error: dereferencing pointer to incomplete type
main.c:52:53: error: dereferencing pointer to incomplete type
main.c:53:41: error: dereferencing pointer to incomplete type
main.c:53:65: error: dereferencing pointer to incomplete type
make: *** [main.o] Error 1
What can I do to fix it?
1. you never copied over PierottLL's keydown function into your source.
2. You need to define a struct for Coord:
Code:
You can create a new one like:
Code:
And feed it into the moveCursor routine like:
Code:
3. You really need to read a general tutorial on C before attempting any further Prizm add-in development. I commonly suggest this one: http://www.cprogramming.com/tutorial/c/lesson1.html
2. You need to define a struct for Coord:
Code:
struct Coord {
int x;
int y;
};
You can create a new one like:
Code:
Coord xy;
xy.x = 0;
xy.y = 0;
And feed it into the moveCursor routine like:
Code:
moveCursor(&cursor);
3. You really need to read a general tutorial on C before attempting any further Prizm add-in development. I commonly suggest this one: http://www.cprogramming.com/tutorial/c/lesson1.html
I don't see PierottLL's keydown function. Where is it?
Edit: Nevermind. I found it.
Well, it compiled, but it doesn't move when I press the keys.
Code:
Edit: Nevermind. I found it.
Well, it compiled, but it doesn't move when I press the keys.
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.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 );
}
const char BigCursor[504] = {
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
};
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
int x = 0;
int y = 0;
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
int main() {
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BigCursor, x, y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
well, you still haven't declared a coordinate variable yet, and never call moveCursor. This should work:
Code:
EDIT: and please don't brush off that suggestion to visit and read that C tutorial set; you really need to.
Code:
int main() {
Coord cur;
cur.x = 0;
cur.y = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BigCursor, cur.x, cur.y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
EDIT: and please don't brush off that suggestion to visit and read that C tutorial set; you really need to.
It now says:
Code:
main.c:
Code:
Code:
../..//bin/sh3eb-elf-gcc.exe -c -m3 -mb -O3 -mhitachi -Wall -nostdlib -I../..//
include -lfxcg -lgcc -L../..//lib -std=c99 main.c -o main.o
main.c: In function 'main':
main.c:24:3: error: unknown type name 'Coord'
main.c:25:6: error: request for member 'x' in something not a structure or union
main.c:26:6: error: request for member 'y' in something not a structure or union
main.c:30:5: warning: implicit declaration of function 'moveCursor' [-Wimplicit-
function-declaration]
main.c:31:16: error: 'BigCursor' undeclared (first use in this function)
main.c:31:16: note: each undeclared identifier is reported only once for each fu
nction it appears in
main.c:31:30: error: request for member 'x' in something not a structure or unio
n
main.c:31:37: error: request for member 'y' in something not a structure or unio
n
main.c: At top level:
main.c:37:12: error: expected declaration specifiers or '...' before '&' token
main.c:88:6: warning: conflicting types for 'moveCursor' [enabled by default]
main.c:30:5: note: previous implicit declaration of 'moveCursor' was here
main.c:95:5: error: redefinition of 'main'
main.c:23:5: note: previous definition of 'main' was here
make: *** [main.o] Error 1
main.c:
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.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() {
Coord cur;
cur.x = 0;
cur.y = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BigCursor, cur.x, cur.y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
moveCursor(&cursor);
const char BigCursor[504] = {
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
};
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
int x = 0;
int y = 0;
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
int main() {
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BigCursor, x, y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
well, the problem is that... you copied my new main function, and put it above the existing one, instead of removing the old one and putting that one in place instead. Also I notice you copied "moveCursor(&cursor); " above the "const char BigCursor[504] = {" line -- that needs to go too. Correct code:
Code:
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.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 );
}
const char BigCursor[504] = {
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
};
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
int main() {
Coord cur;
cur.x = 0;
cur.y = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BigCursor, cur.x, cur.y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
Now it says:
Code:
This is with your code, Ashbad.
Code:
../..//bin/sh3eb-elf-gcc.exe -c -m3 -mb -O3 -mhitachi -Wall -nostdlib -I../..//
include -lfxcg -lgcc -L../..//lib -std=c99 main.c -o main.o
main.c: In function 'main':
main.c:80:3: error: unknown type name 'Coord'
main.c:81:6: error: request for member 'x' in something not a structure or union
main.c:82:6: error: request for member 'y' in something not a structure or union
main.c:86:5: warning: passing argument 1 of 'moveCursor' from incompatible point
er type [enabled by default]
main.c:72:6: note: expected 'struct Coord *' but argument is of type 'int *'
main.c:87:30: error: request for member 'x' in something not a structure or unio
n
main.c:87:37: error: request for member 'y' in something not a structure or unio
n
make: *** [main.o] Error 1
This is with your code, Ashbad.
Try this.
Code:
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.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 );
}
const char BigCursor[504] = {
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff
};
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_UP) && cursor->y>0) cursor->y--;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y++;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x--;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x++;
}
int main() {
struct Coord cur;
cur.x = 0;
cur.y = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BigCursor, cur.x, cur.y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
You'll have to clear the screen. The easy way to do it for now:
Code:
put it after this line:
Code:
Code:
Bdisp_AllCr_VRAM();
put it after this line:
Code:
Bdisp_PutDisp_DD();
If I wanted to add a background image behind it, where would I put the display code?
I know it would be inside of:
Code:
I know it would be inside of:
Code:
int main() {
struct Coord cur;
cur.x = 0;
cur.y = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BigCursor, cur.x, cur.y, 12, 21);
Bdisp_PutDisp_DD();
}
return 0;
}
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
» Go to Registration page
» Goto page 1, 2, 3, 4 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 1 of 4
» All times are UTC - 5 Hours
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
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
Advertisement