0

我编写了一个chip-8模拟器。无论我做什么,似乎我都无法在屏幕上显示任何像素。奇怪的是我已经检查了代码,上下已经2天了,似乎没有有任何问题。它将 .rom 文件读入内存,并正确获取 OP 代码。

这是源代码:

                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; i < 64*32; i++){
                    pixels[i] = (0x00FFFFFF * display[i]) | 0xFF000000;
                }
                //upload the pixels to the texture
                SDL_UpdateTexture(tex,NULL,pixels, 64 * sizeof(uint32_t));
                //Now get the texture to the 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; i < 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;
                        }
                    }
                }
4

1 回答 1

0

所以基本上,问题出在 init() 函数上。我最初使用的是 SDL_CreateWindow 和 SDL_CreateRenderer,但现在我使用的是 SDL_CreateWindowAndRenderer,它采用指向 SDL_Window 和 SDL_Renderer 指针的指针,而不是指向 char 的指针和指向一个窗口。

我还修复了 3 个问题。1.我在 NNN 操作码中添加了 + 0x200,因为起初我认为 ROM 中的 NNN 是相对于 0 的,所以我从每个 XNNN 操作码中删除了 +0x200。另外我在 SDL_Texture* tex 上忘记了一个 *,它应该是SDL_Texture** tex,我只是更改了本地指针指向的地址... 2.at opcode 2NNN,而不是 (ch8->SP) = ch8->opcode & 0x0FFF; 它的(ch8->SP) = ch8->PC.word; 3.在操作码 FX65 它的 i <= ((ch8->opcode & 0x0F00) >> 8)

基本上,SDL_CreateWindowAndRenderer 和 SDL_CreateWindow&SDL_CreateRenderer 之间的差异让我感到困惑,我应该先检查文档。

现在我只需要让模拟器只重绘改变的像素,然后让模拟器播放声音。

于 2017-09-12T16:32:23.490 回答