Пример #1
0
//create a new nes object
void nes_init()
{
	//clear out the nes structure (but dont clear input device/bios pointers...HACK)
	memset(nes,0,sizeof(nes_t) - (sizeof(inputdev_t*) * 3 + sizeof(u8*) * 3));

	//palette info
	nes->hue = config.hue;
	nes->sat = config.sat;

	//initialize the 6502
	dead6502_init();

	//initialize the ppu event system
	ppu_event_init();

	//set up the apu
	nes->apu = apu_create(0,SOUND_HZ,60,16,dead6502_irq);

	//enable sound channels
	nes->apu->mix_enable = config.soundenabled ? config.soundchannels : 0;

	//set the 6502 data pointer
	dead6502_setdata(&nes->cpu);

	apu_setcontext(nes->apu);

	//generate a kevin horton palette for the video
	palette_generate(nes->hue,nes->sat);
}
Пример #2
0
int main(int argc, char *argv[]) {
    int sy, sx;
    
    if(argc != 4) {
      usage(argv[0]);
      return 1;
    }

    Config conf = { atoi(argv[1]), atoi(argv[2]), atoi(argv[3]) };

    if(conf.screenX == 0 || conf.screenY == 0 || conf.iterations == 0) {
      usage(argv[0]);
      return 1;
    }

    Color palette[COLORS];
    palette_generate(palette);
    init_ppm(conf);
   
    float xrange = MAX_X - MIN_X;
    float yrange = MAX_Y - MIN_Y;
    
    for(sy = 1; sy <= conf.screenY; sy++) {
        for(sx = 1; sx <= conf.screenX; sx++) {
            float x, y;
            x = 0.0;
            y = 0.0;
            
            float x0 = sx / (float)conf.screenX * xrange + MIN_X; 
            float y0 = sy / (float)conf.screenY * yrange + MIN_Y; 
        
            int i = 0;
            while(((x*x - y*y) < (2*2)) && i < conf.iterations) {
                float xtmp;
                xtmp = x*x - y*y + x0;
                y = 2*x*y + y0;
                x = xtmp;
                i++;
            }
            
            Color c = { 0, 0, 0 };
            if((x*x + y*y) > (2*2)) {
                c = palette[i % COLORS];
            }
            plot(sx, sy, c);
        }

        printf("\n");
    }
    
    return 0;
}