Mercurial > repos > blastem
comparison blastem.c @ 523:450c7745379a
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 11 Feb 2014 21:52:15 -0800 |
parents | 0b21a1a73fb7 |
children | fb39534b6604 |
comparison
equal
deleted
inserted
replaced
522:6a14c5a95648 | 523:450c7745379a |
---|---|
8 #include "z80_to_x86.h" | 8 #include "z80_to_x86.h" |
9 #include "mem.h" | 9 #include "mem.h" |
10 #include "vdp.h" | 10 #include "vdp.h" |
11 #include "render.h" | 11 #include "render.h" |
12 #include "blastem.h" | 12 #include "blastem.h" |
13 #include "gdb_remote.h" | |
13 #include "gst.h" | 14 #include "gst.h" |
14 #include "util.h" | 15 #include "util.h" |
15 #include <stdio.h> | 16 #include <stdio.h> |
16 #include <stdlib.h> | 17 #include <stdlib.h> |
17 #include <string.h> | 18 #include <string.h> |
1408 debugging = 0; | 1409 debugging = 0; |
1409 break; | 1410 break; |
1410 case 'd': | 1411 case 'd': |
1411 param = find_param(input_buf); | 1412 param = find_param(input_buf); |
1412 if (!param) { | 1413 if (!param) { |
1413 fputs("b command requires a parameter\n", stderr); | 1414 fputs("d command requires a parameter\n", stderr); |
1414 break; | 1415 break; |
1415 } | 1416 } |
1416 value = atoi(param); | 1417 value = atoi(param); |
1417 this_bp = find_breakpoint_idx(&breakpoints, value); | 1418 this_bp = find_breakpoint_idx(&breakpoints, value); |
1418 if (!*this_bp) { | 1419 if (!*this_bp) { |
1462 break; | 1463 break; |
1463 } | 1464 } |
1464 printf(format, param, value); | 1465 printf(format, param, value); |
1465 break; | 1466 break; |
1466 case 'n': | 1467 case 'n': |
1467 //TODO: Deal with jmp, dbcc, rtr and rte | |
1468 if (inst.op == M68K_RTS) { | 1468 if (inst.op == M68K_RTS) { |
1469 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); | 1469 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); |
1470 } else if(inst.op == M68K_BCC && inst.extra.cond != COND_FALSE) { | 1470 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { |
1471 if (inst.extra.cond = COND_TRUE) { | 1471 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); |
1472 after = inst.address + 2 + inst.src.params.immed; | 1472 } else if(m68k_is_noncall_branch(&inst)) { |
1473 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { | |
1474 branch_f = after; | |
1475 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1476 insert_breakpoint(context, branch_t, (uint8_t *)debugger); | |
1477 } else if(inst.op == M68K_DBCC) { | |
1478 if ( inst.extra.cond == COND_FALSE) { | |
1479 if (context->dregs[inst.dst.params.regs.pri] & 0xFFFF) { | |
1480 after = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1481 } | |
1482 } else { | |
1483 branch_t = after; | |
1484 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1485 insert_breakpoint(context, branch_f, (uint8_t *)debugger); | |
1486 } | |
1473 } else { | 1487 } else { |
1488 after = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1489 } | |
1490 } | |
1491 insert_breakpoint(context, after, (uint8_t *)debugger); | |
1492 debugging = 0; | |
1493 break; | |
1494 case 'o': | |
1495 if (inst.op == M68K_RTS) { | |
1496 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); | |
1497 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { | |
1498 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); | |
1499 } else if(m68k_is_noncall_branch(&inst)) { | |
1500 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { | |
1501 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1502 if (branch_t < after) { | |
1503 branch_t = 0; | |
1504 } else { | |
1505 branch_f = after; | |
1506 insert_breakpoint(context, branch_t, (uint8_t *)debugger); | |
1507 } | |
1508 } else if(inst.op == M68K_DBCC) { | |
1509 uint32_t target = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1510 if (target > after) { | |
1511 if (inst.extra.cond == COND_FALSE) { | |
1512 after = target; | |
1513 } else { | |
1514 branch_f = target; | |
1515 branch_t = after; | |
1516 insert_breakpoint(context, branch_f, (uint8_t *)debugger); | |
1517 } | |
1518 } | |
1519 } else { | |
1520 after = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1521 } | |
1522 } | |
1523 insert_breakpoint(context, after, (uint8_t *)debugger); | |
1524 debugging = 0; | |
1525 break; | |
1526 case 's': | |
1527 if (inst.op == M68K_RTS) { | |
1528 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); | |
1529 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { | |
1530 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); | |
1531 } else if(m68k_is_branch(&inst)) { | |
1532 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { | |
1474 branch_f = after; | 1533 branch_f = after; |
1475 branch_t = inst.address + 2 + inst.src.params.immed; | 1534 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs); |
1476 insert_breakpoint(context, branch_t, (uint8_t *)debugger); | 1535 insert_breakpoint(context, branch_t, (uint8_t *)debugger); |
1536 } else if(inst.op == M68K_DBCC && inst.extra.cond != COND_FALSE) { | |
1537 branch_t = after; | |
1538 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1539 insert_breakpoint(context, branch_f, (uint8_t *)debugger); | |
1540 } else { | |
1541 after = m68k_branch_target(&inst, context->dregs, context->aregs); | |
1477 } | 1542 } |
1478 } | 1543 } |
1479 insert_breakpoint(context, after, (uint8_t *)debugger); | 1544 insert_breakpoint(context, after, (uint8_t *)debugger); |
1480 debugging = 0; | 1545 debugging = 0; |
1481 break; | 1546 break; |
1583 fwrite(genesis->save_ram, 1, size, f); | 1648 fwrite(genesis->save_ram, 1, size, f); |
1584 fclose(f); | 1649 fclose(f); |
1585 printf("Saved SRAM to %s\n", sram_filename); | 1650 printf("Saved SRAM to %s\n", sram_filename); |
1586 } | 1651 } |
1587 | 1652 |
1588 void init_run_cpu(genesis_context * gen, int debug, FILE * address_log, char * statefile) | 1653 void init_run_cpu(genesis_context * gen, FILE * address_log, char * statefile, uint8_t * debugger) |
1589 { | 1654 { |
1590 m68k_context context; | 1655 m68k_context context; |
1591 x86_68k_options opts; | 1656 x86_68k_options opts; |
1592 gen->m68k = &context; | 1657 gen->m68k = &context; |
1593 memmap_chunk memmap[MAX_MAP_CHUNKS]; | 1658 memmap_chunk memmap[MAX_MAP_CHUNKS]; |
1704 if (!pc) { | 1769 if (!pc) { |
1705 fprintf(stderr, "Failed to load save state %s\n", statefile); | 1770 fprintf(stderr, "Failed to load save state %s\n", statefile); |
1706 exit(1); | 1771 exit(1); |
1707 } | 1772 } |
1708 printf("Loaded %s\n", statefile); | 1773 printf("Loaded %s\n", statefile); |
1709 if (debug) { | 1774 if (debugger) { |
1710 insert_breakpoint(&context, pc, (uint8_t *)debugger); | 1775 insert_breakpoint(&context, pc, debugger); |
1711 } | 1776 } |
1712 adjust_int_cycle(gen->m68k, gen->vdp); | 1777 adjust_int_cycle(gen->m68k, gen->vdp); |
1713 gen->z80->native_pc = z80_get_native_address_trans(gen->z80, gen->z80->pc); | 1778 gen->z80->native_pc = z80_get_native_address_trans(gen->z80, gen->z80->pc); |
1714 start_68k_context(&context, pc); | 1779 start_68k_context(&context, pc); |
1715 } else { | 1780 } else { |
1716 if (debug) { | 1781 if (debugger) { |
1717 insert_breakpoint(&context, address, (uint8_t *)debugger); | 1782 insert_breakpoint(&context, address, debugger); |
1718 } | 1783 } |
1719 m68k_reset(&context); | 1784 m68k_reset(&context); |
1720 } | 1785 } |
1721 } | 1786 } |
1722 | 1787 |
1806 int loaded = 0; | 1871 int loaded = 0; |
1807 uint8_t force_version = 0; | 1872 uint8_t force_version = 0; |
1808 char * romfname = NULL; | 1873 char * romfname = NULL; |
1809 FILE *address_log = NULL; | 1874 FILE *address_log = NULL; |
1810 char * statefile = NULL; | 1875 char * statefile = NULL; |
1876 uint8_t * debuggerfun = NULL; | |
1811 uint8_t fullscreen = 0, use_gl = 1; | 1877 uint8_t fullscreen = 0, use_gl = 1; |
1812 for (int i = 1; i < argc; i++) { | 1878 for (int i = 1; i < argc; i++) { |
1813 if (argv[i][0] == '-') { | 1879 if (argv[i][0] == '-') { |
1814 switch(argv[i][1]) { | 1880 switch(argv[i][1]) { |
1815 case 'b': | 1881 case 'b': |
1820 } | 1886 } |
1821 headless = 1; | 1887 headless = 1; |
1822 exit_after = atoi(argv[i]); | 1888 exit_after = atoi(argv[i]); |
1823 break; | 1889 break; |
1824 case 'd': | 1890 case 'd': |
1825 debug = 1; | 1891 debuggerfun = (uint8_t *)debugger; |
1892 break; | |
1893 case 'D': | |
1894 gdb_remote_init(); | |
1895 debuggerfun = (uint8_t *)gdb_debug_enter; | |
1826 break; | 1896 break; |
1827 case 'f': | 1897 case 'f': |
1828 fullscreen = 1; | 1898 fullscreen = 1; |
1829 break; | 1899 break; |
1830 case 'g': | 1900 case 'g': |
1978 if (i < 0) { | 2048 if (i < 0) { |
1979 strcpy(sram_filename + fname_size, ".sram"); | 2049 strcpy(sram_filename + fname_size, ".sram"); |
1980 } | 2050 } |
1981 set_keybindings(); | 2051 set_keybindings(); |
1982 | 2052 |
1983 init_run_cpu(&gen, debug, address_log, statefile); | 2053 init_run_cpu(&gen, address_log, statefile, debuggerfun); |
1984 return 0; | 2054 return 0; |
1985 } | 2055 } |