static int rvec_out_of_memory( int dummy_rvec, int err ) { printm("Unrecoverable out of memory condition. Exiting\n"); quit_emulation(); return 0; }
static int rvec_bad_vector( int rvec ) { printm("Uninitialized rvector %d occured (%X)\n", rvec & RVEC_MASK, rvec ); quit_emulation(); return 0; }
static int rvec_internal_error( int dummy_rvec, int err ) { if( err == 0x1700 ) { printm("==================================================\n" "A problem related to TAU-interrupts has occured.\n" "This is a hardware problem - please turn off the\n" "kernel config option\n" " Interrupt driven TAU driver (CONFIG_TAU_INT)\n" "\nor\n" " Thermap Management Support (CONFIG_TAU)\n" "(a kernel recompilation is necessary...)\n" "==================================================\n"); } printm("RVEC Internal Error %x\n", err ); quit_emulation(); return 0; }
static int rvec_unexpected_mmu_cond( int rvec, int param1, int param2 ) { switch( rvec ) { case RVEC_UNUSUAL_DSISR_BITS: /* dar, dsisr */ printm("RVEC_UNUSUAL_DSISR_BITS: dar %08X, dsisr %08X\n", param1, param2 ); break; case RVEC_MMU_IO_SEG_ACCESS: printm("RVEC_MMU_IO_SEG_ACCESS\n"); break; case RVEC_BAD_NIP: /* nip_phys */ printm("Instruction Pointer not in ROM/RAM (nip %08lX, nip_phys %08X)\n", mregs->nip, param1 ); if( !debugger_enabled() ) quit_emulation(); stop_emulation(); break; default: printm("rvec_unexpected_mmu_cond, unimplemented vector %d\n", rvec ); break; } return 0; }
void poll_buttons(void) { SDL_Event event; while(SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_DOWN: #ifdef PAD_DEBUG printf("debug [%d]: DOWN key (down) press detected\n",debug_cnt); #endif set_input(1); break; case SDLK_UP: #ifdef PAD_DEBUG printf("debug [%d]: UP key press (down) detected\n",debug_cnt); #endif set_input(2); break; case SDLK_LEFT: #ifdef PAD_DEBUG printf("debug [%d]: LEFT key press (down) detected\n",debug_cnt); #endif set_input(3); break; case SDLK_RIGHT: #ifdef PAD_DEBUG printf("debug [%d]: RIGHT key press (down) detected\n",debug_cnt); #endif set_input(4); break; case SDLK_LCTRL: #ifdef PAD_DEBUG printf("debug [%d]: LCTRL (NES -> start) key (down) press detected\n",debug_cnt); #endif set_input(5); break; case SDLK_LSHIFT: #ifdef PAD_DEBUG printf("debug [%d]: LSHIFT (NES -> select) key (down) press detected\n",debug_cnt); #endif set_input(6); break; case SDLK_p: if(pause_emulation) { printf("[*] LameNES continue emulation!\n"); CPU_is_running = 1; pause_emulation = 0; } else if(!pause_emulation) { printf("[*] LameNES paused!\n"); CPU_is_running = 0; pause_emulation = 1; } break; case SDLK_x: #ifdef PAD_DEBUG printf("debug [%d]: Z (NES -> A) key (down) press detected\n",debug_cnt); #endif set_input(7); break; case SDLK_z: #ifdef PAD_DEBUG printf("debug [%d]: X (NES -> B) key (down) press detected\n",debug_cnt); #endif set_input(8); break; case SDLK_q: #ifdef PAD_DEBUG printf("debug [%d]: Q (quit lamenes) key (down) press detected\n",debug_cnt); #endif quit_emulation(); break; case SDLK_ESCAPE: #ifdef PAD_DEBUG printf("debug [%d]: ESC (quit lamenes) key (down) press detected\n",debug_cnt); #endif quit_emulation(); break; case SDLK_F1: /* reset */ reset_emulation(); break; case SDLK_F3: /* load state */ load_state(); break; case SDLK_F6: /* save state */ save_state(); break; case SDLK_F10: if(enable_background == 1) { enable_background = 0; } else { enable_background = 1; } break; case SDLK_F11: if(enable_sprites == 1) { enable_sprites = 0; } else { enable_sprites = 1; } break; case SDLK_F12: if(startdebugger > 0) { disassemble = 1; hit_break = 1; debugger(); } break; default: break; } } if(event.type == SDL_KEYUP) { switch(event.key.keysym.sym){ case SDLK_DOWN: #ifdef PAD_DEBUG printf("debug [%d]: DOWN key (up) press detected\n",debug_cnt); #endif clear_input(1); break; case SDLK_UP: #ifdef PAD_DEBUG printf("debug [%d]: UP key (up) press detected\n",debug_cnt); #endif clear_input(2); break; case SDLK_LEFT: #ifdef PAD_DEBUG printf("debug [%d]: LEFT key (up) press detected\n",debug_cnt); #endif clear_input(3); break; case SDLK_RIGHT: #ifdef PAD_DEBUG printf("debug [%d]: RIGHT key (up) press detected\n",debug_cnt); #endif clear_input(4); break; case SDLK_LCTRL: #ifdef PAD_DEBUG printf("debug [%d]: LCTRL (NES -> start) key (up) press detected\n",debug_cnt); #endif clear_input(5); break; case SDLK_LSHIFT: #ifdef PAD_DEBUG printf("debug [%d]: LSHIFT (NES -> select) key (up) press detected\n",debug_cnt); #endif clear_input(6); break; case SDLK_x: #ifdef PAD_DEBUG printf("debug [%d]: Z (NES -> A) key (up) press detected\n",debug_cnt); #endif clear_input(7); break; case SDLK_z: #ifdef PAD_DEBUG printf("debug [%d]: X (NES -> B) key (up) press detected\n",debug_cnt); #endif clear_input(8); break; default: break; } } } }
void debugger() { char cmd[8]; char subcmd[256]; char *subopt1; char *subopt2; int chr_check_result; int sublen; int opt = 0; int menu = 1; while(menu) { memset(cmd,0,sizeof(cmd)); memset(subcmd,0,sizeof(subcmd)); printf("\n"); printf("LameNES debugger command>"); if(fgets(cmd, 5,stdin) != NULL) { if(cmd[0] != '\0' && cmd[strlen(cmd) - 1] == '\n') cmd[strlen(cmd) - 1] = '\0'; } switch(cmd[0]) { case 'b': printf("\nenter breakpoint: 0x"); if(fgets(subcmd, 7,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 5) { printf("error: address range must be between 0x0000 and 0xFFFF\n"); } else { chr_check_result = str_chrchk(subcmd,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subcmd) == chr_check_result)) { breakpoint = strtoul(subcmd, NULL, 16); } else { printf("error: unknown memory address given!\n"); } } break; case 'c': printf("continue with emulation!\n"); hit_break = 0; disassemble = 0; menu = 0; break; case 'd': if(stackdebug == 1) { printf("stack debugging disabled!\n"); stackdebug = 0; } else { printf("stack debugging enabled!\n"); stackdebug = 1; } break; case 'f': printf("[%d] ppu_control1: %x\n",debug_cnt,ppu_control1); printf("[%d] ppu_control2: %x\n",debug_cnt,ppu_control2); printf("[%d] ppu_status: %x\n",debug_cnt,ppu_status); printf("[%d] ppu_status_ret: %x\n",debug_cnt,(ppu_status & 0xE0) | (ppu_addr_tmp & 0x1F)); printf("[%d] current scanline: %d\n",debug_cnt,current_scanline); printf("[%d] current nametable: %x\n",debug_cnt,0x2000 + (loopyV & 0x0fff)); printf("[%d] loopyT: %x\n",debug_cnt,loopyT); printf("[%d] loopyV: %x\n",debug_cnt,loopyV); printf("[%d] loopyX: %x\n",debug_cnt,loopyX); printf("[%d] exec_nmi_on_vblank: %x\n",debug_cnt,exec_nmi_on_vblank); printf("[%d] sprite_16: %d\n",debug_cnt,sprite_16); printf("[%d] background_addr_hi: %x\n",debug_cnt,background_addr_hi); printf("[%d] sprite_addr_hi: %d\n",debug_cnt,sprite_addr_hi); printf("[%d] increment_32: %d\n",debug_cnt,increment_32); printf("[%d] sprite_on: %d\n",debug_cnt,sprite_on); printf("[%d] background_on: %d\n",debug_cnt,background_on); printf("[%d] sprite_clipping_off: %d\n",debug_cnt,sprite_clipping_off); printf("[%d] background_clipping_off: %d\n",debug_cnt,background_clipping_off); printf("[%d] monochrome_on: %d\n",debug_cnt,monochrome_on); printf("[%d] vblank_on: %d\n",debug_cnt,vblank_on); printf("[%d] sprite_zero: %d\n",debug_cnt,sprite_zero); printf("[%d] scanline_sprite_count: %d\n",debug_cnt,scanline_sprite_count); printf("[%d] vram_write_flag: %d\n",debug_cnt,vram_write_flag); break; case 'h': printf("------------------------------\n"); printf("LameNES debugger command list:\n"); printf("------------------------------\n"); printf("(b)reakpoint -> set breakpoint\n"); printf("(c)ontinue -> continue emulation\n"); printf("(d)ebug stack operations -> enable/disable stack debugging\n"); printf("(i)nstruction counter break -> set instruction counter breakpoint\n"); printf("(f)lags states -> show all states of current flags\n"); printf("(h)elp -> this screen\n"); printf("(l)oad state -> loads emulation state\n"); printf("(m)emorydump -> show or dump the complete nes memory\n"); printf("(p)pu status -> show ppu status\n"); printf("(q)uit -> quit LameNES\n"); printf("(s)ave state -> saves emulation state\n"); printf("(u)pdate controller io -> send joypad1 io\n"); printf("(anything else) -> executes the next instruction\n"); break; case 'i': printf("\nenter instruction counter breakpoint: "); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 255) { printf("error: counter too large!\n"); } else { stop_at_debug_cnt = atoi(subcmd); } break; case 'l': load_state(); break; case 'm': printf("memory options:\n" "m <memory address> -> display main ram from given address + next 100 bytes\n" "p <memory address> -> display ppu ram from given address + next 100 bytes\n" "s <memory address> -> display sprite ram from given address + next 100 bytes\n" "a -> dump all memory registers to bin files\n" "enter option: " ); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 10) { printf("error: option string too large\n"); break; } switch(subcmd[0]) { case 'a': printf("dumping main memory to: lamenes_nesmem.bin\n"); dump_mem("lamenes_nesmem.bin"); printf("dumping ppu memory to: lamenes_ppumem.bin\n"); dump_ppu_mem("lamenes_ppumem.bin"); printf("dumping sprite memory to: lamenes_spritemem.bin\n"); dump_sprite_mem("lamenes_spritemem.bin"); printf("dumping nametables to: lamenes_nametables.bin\n"); dump_ppu_nam("lamenes_nametables.bin"); printf("dumping palette to: lamenes_palette.bin\n"); dump_ppu_palette("lamenes_palette.bin"); printf("dumping main ram to: lamenes_nesram.bin\n"); dump_nesram("lamenes_nesram.bin"); printf("dumping ppu ram to: lamenes_ppuram.bin\n"); dump_ppuram("lamenes_ppuram.bin"); printf("dumping stack to: lamenes_stackdump.bin\n"); dump_stack("lamenes_stackdump.bin"); break; case 'm': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("main",opt); } else { printf("error: unknown memory address given!\n"); } break; case 'p': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("ppu",opt); } else { printf("error: unknown memory address given!\n"); } break; case 's': subopt1 = str_cut(subcmd," "); subopt2 = str_cut(NULL," "); chr_check_result = str_chrchk(subopt2,"0123456789abcdef"); if((chr_check_result > 0) && (strlen(subopt2) == chr_check_result)) { opt = strtoul(subopt2, NULL, 16); show_mem("sprite",opt); } else { printf("error: unknown memory address given!\n"); } break; default: break; } break; case 'p': printf("ppu status options:\n" "(s)prite attributes -> display current sprite attributes\n" "enter option: " ); if(fgets(subcmd, 255,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 10) { printf("error: option string too large\n"); break; } switch(subcmd[0]) { case 's': show_sprite_attribs(); break; default: break; } break; case 'q': quit_emulation(); break; case 's': save_state(); break; case 'u': printf("\nchoose the following joypad1 oi command to send:\n" "1 -> down\n" "2 -> up\n" "3 -> left\n" "4 -> right\n" "5 -> start\n" "6 -> select\n" "7 -> A\n" "8 -> B\n" "enter selection: "); if(fgets(subcmd, 2,stdin) != NULL) { if(subcmd[0] != '\0' && subcmd[strlen(subcmd) - 1] == '\n') subcmd[strlen(subcmd) - 1] = '\0'; } sublen = strlen(subcmd); if(sublen > 2) { printf("error: too many arguments!\n"); break; } chr_check_result = str_chrchk(subcmd,"12345678"); if((chr_check_result > 0) && (strlen(subcmd) == chr_check_result)) { opt = atoi(subcmd); switch(opt) { /* down */ case 1: printf("sending joypad1 [down] to io.\n"); set_input(1); break; /* up */ case 2: printf("sending joypad1 [up] to io.\n"); set_input(2); break; /* left */ case 3: printf("sending joypd1 [left] to io.\n"); set_input(3); break; /* right */ case 4: printf("sending joypad1 [right] to io.\n"); set_input(4); break; /* start */ case 5: printf("sending joypad1 [start] to io.\n"); set_input(5); break; /* select */ case 6: printf("sending joypad1 [select] to io.\n"); set_input(6); break; /* A */ case 7: printf("sending joypad1 [A] to io.\n"); set_input(7); break; /* B */ case 8: printf("sending joypad1 [B] to io.\n"); set_input(8); break; default: printf("error: unknown option!\n"); break; } } else { printf("error: wrong argument!\n"); } break; case 'v': printf("interrupt vectors:\n\n"); printf("INIT [0xfffc] -> 0x%x\n",(memory[0xfffd] << 8) | memory[0xfffc]); printf("IRQ [0xfffe] -> 0x%x\n",(memory[0xffff] << 8) | memory[0xfffe]); printf("NMI [0xfffa] -> 0x%x\n",(memory[0xfffb] << 8) | memory[0xfffa]); break; default: printf("executing next instruction!\n"); menu = 0; break; } } }