Skip to content

Commit

Permalink
update:优化打印信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Dozingfiretruck committed Jul 4, 2024
1 parent a12d6b1 commit ae4ddc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion inc/nes_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ typedef struct nes_cpu{
uint8_t A; /* Accumulator */
uint8_t X; /* Indexes X */
uint8_t Y; /* Indexes Y */
uint16_t PC; /* Program Counter */
uint8_t SP; /* Stack Pointer */
uint16_t PC; /* Program Counter */
union {
struct {
uint8_t C:1; /* carry flag (1 on unsigned overflow) */
Expand Down
13 changes: 8 additions & 5 deletions src/nes.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,19 @@ static void nes_render_sprite_line(nes_t* nes,uint16_t scanline,nes_color_t* dra


void nes_run(nes_t* nes){
// nes_printf("mapper:%03d\n",nes->nes_rom.mapper_number);
// nes_printf("prg_rom_size:%d*16kb\n",nes->nes_rom.prg_rom_size);
// nes_printf("chr_rom_size:%d*8kb\n",nes->nes_rom.chr_rom_size);
nes_printf("mapper:%03d\n",nes->nes_rom.mapper_number);
nes_printf("prg_rom_size:%d*16kb\n",nes->nes_rom.prg_rom_size);
nes_printf("chr_rom_size:%d*8kb\n",nes->nes_rom.chr_rom_size);
nes_printf("mirroring_type:%d\n",nes->nes_rom.mirroring_type);
nes_printf("four_screen:%d\n",nes->nes_rom.four_screen);
// nes_printf("save_ram:%d\n",nes->nes_rom.save_ram);

nes_cpu_reset(nes);
// nes->nes_cpu.PC = 0xC000;
// printf("nes->nes_cpu.PC %02X",nes->nes_cpu.PC);
uint64_t frame_cnt = 0;
uint16_t scanline = 0;

while (!nes->nes_quit){
// nes_printf("frame_cnt:%d\n",frame_cnt);
frame_cnt++;
nes_palette_generate(nes);

Expand Down
17 changes: 5 additions & 12 deletions src/nes_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,13 @@ static uint8_t nes_read_cpu(nes_t* nes,uint16_t address){

static inline const uint8_t* nes_get_dma_address(nes_t* nes,uint8_t data) {
switch (data >> 5){
case 1:
nes_printf("PPU REG!");
return 0;
case 2:
nes_printf("TODO");
return 0;
case 0:
return nes->nes_cpu.cpu_ram + ((uint16_t)(data & 0x07) << 8);
#if (NES_USE_SRAM == 1)
// case 3:
// return famicom->save_ram + ((uint16_t)(data & 0x1f) << 8);
#endif
case 4: case 5: case 6: case 7:// 高一位为1, [$8000, $10000) PRG-ROM
return nes->nes_cpu.prg_banks[data >> 4] + ((uint16_t)(data & 0x0f) << 8);
return nes->nes_cpu.prg_banks[(data >> 4)&0x03] + ((uint16_t)(data & 0x0f) << 8);
default:
nes_printf("nes_get_dma_address error %02X\n",data);
return 0;
return NULL;
}
}

Expand Down Expand Up @@ -1498,6 +1488,9 @@ static nes_opcode_t nes_opcode_table[] = {

void nes_opcode(nes_t* nes,uint16_t ticks){
while (ticks > nes->nes_cpu.cycles){
// nes_printf("A:0x%02X X:0x%02X SP:0x%02X PC:0x%04X \nP:0x%02X \nC:0x%02X Z:0x%02X I:0x%02X D:0x%02X B:0x%02X V:0x%02X N:0x%02X \n",
// nes->nes_cpu.A,nes->nes_cpu.X,nes->nes_cpu.Y,nes->nes_cpu.SP,nes->nes_cpu.PC,
// nes->nes_cpu.P,nes->nes_cpu.C,nes->nes_cpu.Z,nes->nes_cpu.I,nes->nes_cpu.D,nes->nes_cpu.B,nes->nes_cpu.V,nes->nes_cpu.N);
nes->nes_cpu.opcode = nes_read_cpu(nes,nes->nes_cpu.PC++);
nes_opcode_table[nes->nes_cpu.opcode].instruction(nes);
nes->nes_cpu.cycles += nes_opcode_table[nes->nes_cpu.opcode].ticks;
Expand Down

0 comments on commit ae4ddc3

Please sign in to comment.