OK, did that, now the canvas is one px too small, and I still have all kinds of different colors instead of all black.
bump...
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
flyingfisch wrote:
OK, did that, now the canvas is one px too small, and I still have all kinds of different colors instead of all black.
Forgive me if I'm wrong, but since black = 0x0000, doesn't: Code:
if (canvas[i][j]) {
fillArea(i*zoom+x, j*zoom+y, zoom, zoom, canvas[i][j]);
}
KermMartian wrote:
flyingfisch wrote:
OK, did that, now the canvas is one px too small, and I still have all kinds of different colors instead of all black.
Forgive me if I'm wrong, but since black = 0x0000, doesn't: Code:
if (canvas[i][j]) {
fillArea(i*zoom+x, j*zoom+y, zoom, zoom, canvas[i][j]);
}
OK, I just used COLOR_WHITE instead, and now I get a system error:
Code:
System ERROR
REBOOT: [EXIT]
INITIALIZE: [EXE]
ADDRESS (R)
TARGET=FFFFFFFF
PC =0000000
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
Can you Pastebin your current code so we can take a look? Just in case something went wrong with the off-by-one fixes.
KermMartian wrote:
Can you Pastebin your current code so we can take a look? Just in case something went wrong with the off-by-one fixes.
Sure:
main.c: http://pastebin.com/m5pxLbWd
routines.h: http://pastebin.com/L8ZFi3Pn
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
bump.... this problem is really weird.
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
bump.
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
Ok, I'll try that sometime soon when I get time
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
OK, new project, new problems, weird errors....
main.c
Code:
routines.c
Code:
sprites.h
Code:
Error message
Code:
Any ideas?
EDIT:
Figured it out... apparently c files should not be included.
main.c
Code:
#include <color.h>
#include <display.h>
#include <display_syscalls.h>
#include <keyboard.hpp>
#include <keyboard_syscalls.h>
#include "sprites.h"
#include "routines.c"
void draw_cursor(int x, int y) {
// a simple crosshair cursor
drawLine(x-3, y, x+3, y, COLOR_BLACK);
drawLine(x, y-3, x, y+3, COLOR_BLACK);
}
void draw_copter(int x, int y) {
// center copter on x,y
CopySpriteNbit(copter, x-33, y-10, 66, 19, copter_palette, 1);
}
int main() {
/* VARIABLES */
int key;
int copter_pos[2];
copter_pos[0] = 1;
copter_pos[1] = 1;
int cursor_pos[2];
cursor_pos[0] = LCD_WIDTH_PX;
cursor_pos[1] = LCD_HEIGHT_PX;
/* MAIN LOOP, DO NOT BREAK */
while (1) {
/* GETKEY */
// handle [menu]
if (PRGM_GetKey()==48) {
GetKey(&key);
}
switch (PRGM_GetKey()) {
case 38:
cursor_pos[0] -= 2;
break;
case 27:
cursor_pos[0] += 2;
break;
case 28:
cursor_pos[1] -= 2;
break;
case 37:
cursor_pos[1] += 2;
break;
}
/* OPERATIONS */
if (cursor_pos[0] > copter_pos[0]) {
copter_pos[0]++;
} else if (cursor_pos[0] < copter_pos[0]) {
copter_pos[0]--;
} else if (cursor_pos[1] > copter_pos[1]) {
copter_pos[1]++;
} else if (cursor_pos[1] < copter_pos[1]) {
copter_pos[1]--;
}
/* GRAPHICS */
// clear screen
Bdisp_AllClr_VRAM();
// display functions
draw_cursor(cursor_pos[0], cursor_pos[1]);
draw_copter(copter_pos[0], copter_pos[1]);
// copy VRAM to screen
Bdisp_PutDisp_DD();
}
return 1;
}
routines.c
Code:
#include <color.h>
#include <display.h>
#include <display_syscalls.h>
#include <keyboard.hpp>
#include <keyboard_syscalls.h>
void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, unsigned int bitwidth) {
color_t* VRAM = (color_t*)0xA8000000;
VRAM += (LCD_WIDTH_PX*y + x);
int offset = 0;
unsigned char buf;
for(int j=y; j<y+height; j++) {
int availbits = 0;
for(int i=x; i<x+width; i++) {
if (!availbits) {
buf = data[offset++];
availbits = 8;
}
color_t this = ((color_t)buf>>(8-bitwidth));
*VRAM = palette[(color_t)this];
VRAM++;
buf<<=bitwidth;
availbits-=bitwidth;
}
VRAM += (LCD_WIDTH_PX-width);
}
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
//draws a point of color color at (x0, y0)
void plot(int x0, int y0, int color) {
char* VRAM = (char*)0xA8000000;
VRAM += 2*(y0*LCD_WIDTH_PX + x0);
*(VRAM++) = (color&0x0000FF00)>>8;
*(VRAM++) = (color&0x000000FF);
return;
}
//Uses the Bresenham line algorithm
void drawLine(int x1, int y1, int x2, int y2, int color) {
signed char ix;
signed char iy;
// if x1 == x2 or y1 == y2, then it does not matter what we set here
int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
plot(x1, y1, color);
if (delta_x >= delta_y) {
int error = delta_y - (delta_x >> 1); // error may go below zero
while (x1 != x2) {
if (error >= 0) {
if (error || (ix > 0)) {
y1 += iy;
error -= delta_x;
} // else do nothing
} // else do nothing
x1 += ix;
error += delta_y;
plot(x1, y1, color);
}
} else {
int error = delta_x - (delta_y >> 1); // error may go below zero
while (y1 != y2) {
if (error >= 0) {
if (error || (iy > 0)) {
x1 += ix;
error -= delta_y;
} // else do nothing
} // else do nothing
y1 += iy;
error += delta_x;
plot(x1, y1, color);
}
}
}
sprites.h
Code:
/* COPTER SPRITE
* size: width=66, height=19
*/
const color_t copter_palette[2] = {0xffff, 0x0000};
const unsigned char copter[171] = {
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,
0x00,0x00,0x00,0x00,0x02,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xff,0xf0,0x00,0x00,0x00,
0x00,0x00,0x00,0x3f,0x80,0x0c,0x00,0x00,0x00,
0x00,0x00,0x00,0x22,0xaa,0xab,0x00,0x00,0x00,
0xfb,0xe0,0x00,0x24,0x00,0x01,0xc0,0x00,0x00,
0x06,0x00,0x00,0x38,0x15,0x50,0xa0,0x00,0x00,
0x03,0x00,0x00,0x20,0x00,0xa8,0x50,0x00,0x00,
0x01,0xff,0xff,0xc8,0x10,0x50,0xa8,0x00,0x00,
0x01,0x15,0x40,0x00,0x00,0xa8,0x56,0x00,0x00,
0x00,0xe0,0x3f,0xf8,0x10,0x00,0x01,0x80,0x00,
0x00,0x00,0x00,0x08,0x00,0x80,0x00,0x40,0x00,
0x00,0x00,0x00,0x08,0x10,0x00,0x00,0x40,0x00,
0x00,0x00,0x00,0x06,0x00,0x80,0x00,0x80,0x00,
0x00,0x00,0x00,0x01,0xff,0xff,0xff,0x00,0x00,
0x00,0x00,0x00,0x00,0x08,0x00,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0xff,0xff,0xf8,0x00,0x00
};
Error message
Code:
flyingfisch@Office-Optiplex-745:~/Desktop/PrizmSDK-0.3/projects/stunt-copter$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/build/main.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/main.c -o main.o
In file included from /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/main.c:8:0:
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/routines.c: In function 'CopySpriteNbit':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/routines.c:19:38: warning: 'buf' may be used uninitialized in this function [-Wuninitialized]
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/build/routines.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/routines.c -o routines.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/routines.c: In function 'CopySpriteNbit':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/src/routines.c:19:38: warning: 'buf' may be used uninitialized in this function [-Wuninitialized]
/usr/local/cross/bin/sh3eb-elf-gcc main.o routines.o -mb -m4a-nofpu -mhitachi -nostdlib -T/home/flyingfisch/Desktop/PrizmSDK-0.3/common/prizm.ld -Wl,-static -Wl,-gc-sections -L/home/flyingfisch/Desktop/PrizmSDK-0.3/lib -lfxcg -lgcc -o /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/stunt-copter.bin
routines.o: In function `_CopySpriteNbit':
routines.c:(.text+0x0): multiple definition of `_CopySpriteNbit'
main.o:main.c:(.text+0x0): first defined here
routines.o: In function `_PRGM_GetKey':
routines.c:(.text+0xc8): multiple definition of `_PRGM_GetKey'
main.o:main.c:(.text+0xc8): first defined here
routines.o: In function `_plot':
routines.c:(.text+0xfc): multiple definition of `_plot'
main.o:main.c:(.text+0xfc): first defined here
routines.o: In function `_drawLine':
routines.c:(.text+0x120): multiple definition of `_drawLine'
main.o:main.c:(.text+0x120): first defined here
collect2: ld returned 1 exit status
make[1]: *** [/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/stunt-copter/stunt-copter.bin] Error 1
make: *** [build] Error 2
Any ideas?
EDIT:
Figured it out... apparently c files should not be included.
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
It's a problem with the includes.
Code:
You should not include *.c files directly, instead you must include headers (*.h) corresponding to the .c/.cpp files you want to include. You'll need to manually build the .h yourself, from the definitions of the your functions on the *.c file (there are tools that automate this but I haven't had such a great experience using them... I guess using a IDE for developing makes the whole headers thing easier).
EDIT:
Yes, it's this, didn't see your edit (blames browser cache).
Code:
include "routines.c"
You should not include *.c files directly, instead you must include headers (*.h) corresponding to the .c/.cpp files you want to include. You'll need to manually build the .h yourself, from the definitions of the your functions on the *.c file (there are tools that automate this but I haven't had such a great experience using them... I guess using a IDE for developing makes the whole headers thing easier).
EDIT:
flyingfisch wrote:
EDIT:
Figured it out... apparently c files should not be included.
Figured it out... apparently c files should not be included.
Yes, it's this, didn't see your edit (blames browser cache).
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 Previous 1, 2
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 2 of 2
» 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