Omnimaga
Calculator Community => TI Calculators => Calculator C => Topic started by: shrear on December 27, 2010, 10:34:03 am
-
So I tried writing a program without writing of half the code.
Result: nothing happens, not even a crash :(
Can someone tell me where my stupid beginner error is?
Here is the code:
#include <os.h>
//addresses
#define SCREEN_ADDRESS 0xA4000100 ;
//prototyps
void set_screen (void) ;
void set_value(int address, unsigned int value) ;
void clear_screen(void) ;
//global variables
int screen_cords[240][180] ;
int main(void)
{
set_screen() ;
clear_screen() ;
while ( !isKeyPressed ( KEY_NSPIRE_ESC) )
{
set_value( screen_cords[100][100] , 0x00 ) ;
set_value( screen_cords[100][101] , 0x00 ) ;
set_value( screen_cords[100][102] , 0x00 ) ;
set_value( screen_cords[101][100] , 0x00 ) ;
set_value( screen_cords[101][101] , 0x00 ) ;
set_value( screen_cords[101][102] , 0x00 ) ;
set_value( screen_cords[102][100] , 0x0F ) ;
set_value( screen_cords[102][101] , 0xFF ) ;
set_value( screen_cords[102][102] , 0x00 ) ;
set_value( screen_cords[103][100] , 0xF0 ) ;
set_value( screen_cords[103][101] , 0x00 ) ;
set_value( screen_cords[103][102] , 0xF0 ) ;
set_value( screen_cords[104][100] , 0xF0 ) ;
set_value( screen_cords[104][101] , 0x00 ) ;
set_value( screen_cords[104][102] , 0xF0 ) ;
set_value( screen_cords[105][100] , 0xFF ) ;
set_value( screen_cords[105][101] , 0xFF ) ;
set_value( screen_cords[105][102] , 0xF0 ) ;
set_value( screen_cords[106][100] , 0xF0 ) ;
set_value( screen_cords[106][101] , 0x00 ) ;
set_value( screen_cords[106][102] , 0xF0 ) ;
set_value( screen_cords[107][100] , 0xF0 ) ;
set_value( screen_cords[107][101] , 0x00 ) ;
set_value( screen_cords[107][102] , 0xF0 ) ;
set_value( screen_cords[108][100] , 0xF0 ) ;
set_value( screen_cords[108][101] , 0x00 ) ;
set_value( screen_cords[108][102] , 0xF0 ) ;
set_value( screen_cords[110][100] , 0xFF ) ;
set_value( screen_cords[110][101] , 0xFF ) ;
set_value( screen_cords[110][102] , 0xFF ) ;
}
return 0;
}
void set_screen(void)
{
int ycordinate, xcordinate ;
int screen_address = SCREEN_ADDRESS ;
for ( ycordinate = 1 ; ycordinate == 240 ; ycordinate++ )
{
for ( xcordinate = 1 ; xcordinate == 180 ; xcordinate++ )
{
screen_cords[ycordinate][xcordinate] = (screen_address + (xcordinate-1) + (ycordinate-1)*180) ;
}
}
}
void set_value(int address, unsigned int value)
{
(*(volatile unsigned*)address) = value ;
}
void clear_screen(void)
{
int ycordinate, xcordinate ;
for ( ycordinate = 1 ; ycordinate == 240 ; ycordinate++ )
{
for ( xcordinate = 1 ; xcordinate == 180 ; xcordinate++ )
{
set_value(screen_cords[ycordinate][xcordinate] , 0x00 ) ;
}
}
}
-
Each byte of the screen buffer contains 2 bits.
int (of screen_cords) is 4 bytes long.
The screen width is 320 (see SCREEN_WIDTH in Ndless's common.h).
240*180=43200 > SCREEN_BYTES_SIZE (38400), so your code probably fails with a buffer overflow.
-
320/2=160... :banghead:
what was I thinking...
but there has to be another error.
*shrear tries to find the error*
*wonders why
(*(volatile unsigned*)0xA4005200) = 0xFF ;
(*(volatile unsigned*)0xA4005201) = 0xFF ;
(*(volatile unsigned*)0xA4005202) = 0xFF ;
(*(volatile unsigned*)0xA4005203) = 0xFF ;
(*(volatile unsigned*)0xA4005204) = 0xFF ;
(*(volatile unsigned*)0xA4005205) = 0xFF ;
(*(volatile unsigned*)0xA4005206) = 0xFF ;
a)works b)causes a reboot.*
-
"unsigned" (or unsigned int) means 4 bytes (i.e. a word). word writes must be "aligned", i.e. to an address multiple of 4.
Use instead something like:
(*(volatile unsigned*)0xA4005200) = 0xFFFFFFFF;
(*(volatile unsigned short*)0xA4005204) = 0xFFFFF;
(*(volatile unsigned char*)0xA4005206) = 0xFF;
By the way here is a more simple clear screen, which will be included in Ndless 2.0:
void clrscr(void) {
memset(SCREEN_BASE_ADDRESS, 0xFF, SCREEN_BYTES_SIZE);
}
-
(*(volatile unsigned*)0xA4005200) = 0xFFFFFFFF;
(*(volatile unsigned char*)0xA4005206) = 0xFF;
do nothing
just to be safe
(*(volatile unsigned*)b) = a;
puts the value a into the address "b" or?
-
You only need "volatile" when writing to memory-mapped I/O ports. In this case, it will suffice to use *(unsigned*)b = a;
And 0xF is actually a white pixel, might you have been expecting black?
-
You only need "volatile" when writing to memory-mapped I/O ports. In this case, it will suffice to use *(unsigned*)b = a;
its listed under memory-mapped I/O ports at hackspire
And 0xF is actually a white pixel, might you have been expecting black?
OK that could be it
-
0x00 or 0x01 will give you black. :)
-
Well big thanks to those who helped me.
I got my screen clean :)