Here is the CHR I've made: Here is the code I've written:
Code: Select all
#define PPUCTRL (*(unsigned char*)0x2000)
#define PPUMASK (*(unsigned char*)0x2001)
#define PPUSTAT (*(unsigned char*)0x2002)
#define PPUADDR (*(unsigned char*)0x2006)
#define PPUDATA (*(unsigned char*)0x2007)
static const unsigned char bg_palette[16] = {0x0F, 0x00, 0x10, 0x20, 0x01, 0x11, 0x21, 0x31, 0x05, 0x15, 0x25, 0x35, 0x0A, 0x1A, 0x2A, 0x3A};
static const unsigned char spr_palette[16] = {0x0F, 0x13, 0x23, 0x33, 0x01, 0x71, 0x27, 0x37, 0x05, 0x1C, 0x2C, 0x3C, 0x0A, 0x19, 0x29, 0x39};
void isr_NMI(void);
static void waitForVblank(void){
while((PPUSTAT & 0x80) != 0);
}
static void drawScreen_C(void){
unsigned char i = 0, j = 0;
unsigned char idx = 0;
for(i=0;i<16;++i){
unsigned short addr = (unsigned short)(0x2000 + i * 32);
PPUCTRL = (unsigned char)0x80;
PPUADDR = (unsigned char)((addr >> 8) & 0xFF);
PPUADDR = (unsigned char)((addr >> 0) & 0xFF);
for(j=0;j<16;++j){
PPUDATA = idx++;
}
}
idx = 0;
for(i=16;i<30;++i){
unsigned short addr = (unsigned short)(0x2000 + i * 32);
PPUCTRL = (unsigned char)0x90;
PPUADDR = (unsigned char)((addr >> 8) & 0xFF);
PPUADDR = (unsigned char)((addr >> 0) & 0xFF);
for(j=0;j<16;++j){
PPUDATA = idx++;
}
}
}
void isr_NMI(){
//drawScreen_C();
}
void main(void){
unsigned char i;
// enable vblank
PPUCTRL = (unsigned char)0x80;
// change palette during vblank
waitForVblank();
// set palette
PPUADDR = (unsigned char)0x3F;
PPUADDR = (unsigned char)0x00;
for (i = 0; i < 16; ++i){
PPUDATA = *(bg_palette + i);
}
for (i = 0; i < 16; ++i){
PPUDATA = *(spr_palette + i);
}
drawScreen_C();
// turn on rendering
PPUMASK = (unsigned char)0x0E;
while(1){
}
}