c - CHIP-8 SDL rendering problems -
i have coded chip-8 emulator.whatever do, seems cannot show pixels on screen.the weird thing have checked code, top-bottom 2 days already, , there not seem problem.it reads .rom file memory, , fetches op code correctly.
here source code:
sdl_setrenderdrawcolor( renderer, 0, 0, 0, sdl_alpha_opaque ); sdl_renderclear(renderer); uint32_t pixels[(window_width / 10) * (window_height / 10)]; uint16_t i; for(i = 0; < 64*32; i++){ pixels[i] = (0x00ffffff * display[i]) | 0xff000000; } //upload pixels texture sdl_updatetexture(tex,null,pixels, 64 * sizeof(uint32_t)); //now texture screen sdl_rendercopy(renderer,tex,null,null); sdl_renderpresent(renderer); // update screen ch8.drawf = false; uint16_t x = ch8->v[((ch8->opcode & 0x0f00) >> 8)]; uint16_t y = ch8->v[((ch8->opcode & 0x00f0) >> 4)]; uint8_t n = (ch8->opcode & 0x000f); for(i = 0; < n; i++) { uint8_t pixel= memory[ch8->i.word + i]; for(j = 0; j < 8; j++) { if((pixel & (0x80 >> j)) != 0){ if(display[x + j + ((y + i) * 64)] == 1) { ch8->v[0xf] = 1; } display[x + j + ((y + i) * 64)] ^= 1; } } }
so basically, problem @ init() function.i using, sdl_createwindow , sdl_createrenderer,but i'm using ,sdl_createwindowandrenderer, takes pointers pointers of sdl_window , sdl_renderer instead of pointer char , pointer window.
also there 3 problems fixed. 1.i adding + 0x200 nnn opcodes,because @ firstly thought nnn in rom's relative 0, removed +0x200 each xnnn opcode.also forgot * @ sdl_texture* tex, supposed sdl_texture** tex, merely changing address local pointer poiting too... 2.at opcode 2nnn, instead of (ch8->sp) = ch8->opcode & 0x0fff; its(ch8->sp) = ch8->pc.word; 3.at opcode fx65 <= ((ch8->opcode & 0x0f00) >> 8)
basically, differences between sdl_createwindowandrenderer , sdl_createwindow&sdl_createrenderer had me confused, should had check'd documentation first.
now need make emulator redraw changed pixels, make emulator play sound.
Comments
Post a Comment