Partial fix debugger for multithreaded environment

* Fixes crashing observed when trying to use debugger

    * Various refactoring whitespace fixes
This commit is contained in:
Aaron Culliney 2013-10-06 21:01:00 -07:00
parent 527c04e41f
commit c39bea9580
10 changed files with 244 additions and 319 deletions

View File

@ -12,6 +12,10 @@
#ifndef _COMMON_H_
#define _COMMON_H_
#if defined(__GNUC__)
# define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@ -22,6 +26,7 @@
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <ctype.h>
#ifndef NDEBUG
# if defined(__GNUC__)

View File

@ -82,7 +82,6 @@ static void initialize_code_tables(void)
}
}
void cpu65_set(int flags)
{
initialize_code_tables();
@ -115,3 +114,15 @@ void cpu65_interrupt(int reason)
cpu65__signal = reason;
}
void cpu65_set_stepping(int flag)
{
if (flag)
{
cpu65_interrupt(DebugStepSig);
}
else
{
cpu65_interrupt(0);
}
}

View File

@ -100,11 +100,11 @@
(,EffectiveAddr_E,8); \
#define Continue \
xorl %eax, %eax; \
orb SN(cpu65__signal), %ah; \
jnz exception; \
jmp continue;
/*
* Save CPU state when returning from being called from C
*/
#define SaveState \
movw EffectiveAddr, DebugCurrEA; \
movw PC_Reg, SN(cpu65_current); \
@ -114,7 +114,9 @@
movb Y_Reg, SN(cpu65_current)+5; \
movb SP_Reg_L, SN(cpu65_current)+6;
/* The xorls clear the high parts of the registers
/* Replace CPU state when being called from C.
*
* The xorls clear the high parts of the registers
* Note: dependent on register assignment
*
* The extra bit at the end points the stack pointer at the alternate
@ -2664,13 +2666,17 @@ op_UNK_XMA_imm:
Keep executing until we've executed >= cpu65_cycles_to_execute
------------------------------------------------------------------------- */
continue: xorl %eax, %eax
continue:
xorl %eax, %eax
movb DebugCurrOpcode, %al
movb SN(cpu65__opcycles)(,%eax,1), %al
addb DebugCycleCount, %al
addw %ax, SN(cpu65_cycle_count) // TODO: cycle counting is slightly incorrect, it should be done earlier per instruction ...
subw %ax, SN(cpu65_cycles_to_execute)
subw %ax, SN(cpu65_cycles_to_execute) // but in practice this may not matter ...
jle 1f
xorl %eax, %eax
orb SN(cpu65__signal), %ah
jnz exception
JumpNextInstruction
1: SaveState
popal
@ -2684,22 +2690,13 @@ exception: cmpb $RebootSig, %ah
jz ex_reboot
cmpb $ResetSig, %ah
jz ex_reset
cmpb $DebugStepSig, %ah
jz ex_step
jmp ex_enter
jmp ex_step
ex_step: SaveState
movb $0, SN(cpu65__signal)
popal // EXIT CPUSTEP
ret
ex_enter: SaveState
movb $0, SN(cpu65__signal)
pushal // ENTER CPUSTEP
call SN(enter_debugger)
popal
ex_step: movb $0, SN(cpu65__signal)
xorl %eax, %eax
SaveState
call SN(c_stepping_yield)
ReplaceState
xorb %ah, %ah
JumpNextInstruction
ex_reboot: movb $0, SN(cpu65__signal) // EXIT CPURUN
@ -2727,7 +2724,8 @@ E(cpu65_run)
/* Zero all registers, as well as the unused 32-bit parts
* of variables. (which may need to be kept 0)
*
* Note: dependent on assignment of registers */
* Note: dependent on assignment of registers
*/
xorl %eax, %eax
xorl %ebx, %ebx
xorl %ecx, %ecx
@ -2745,13 +2743,6 @@ E(cpu65_direct_write)
popl %edi
ret
// steps the simulation while remaining in the debugger's control
E(cpu65_step)
pushal
movb $DebugStepSig, SN(cpu65__signal)
ReplaceState
JumpNextInstruction
#pragma mark -
#pragma mark tables

View File

@ -54,8 +54,7 @@ struct cpu65_extra
#define CPU65_FAULT 0x100 /* Undoc. opcodes are BRK */
/* Set up the processor for a new run. Sets up opcode table.
*/
/* Set up the processor for a new run. Sets up opcode table. */
extern void cpu65_set(int flags);
/* Interrupt the processor */
@ -63,7 +62,7 @@ extern void cpu65_interrupt(int reason);
extern void cpu65_run(void);
extern void cpu65_step(void);
extern void cpu65_set_stepping(int flag);
extern void cpu65_direct_write(int ea,int data);
@ -83,7 +82,6 @@ extern uint8_t cpu65_do_reboot;
#define RebootSig 0x01
#define ResetSig 0x02
#define DebugStepSig 0x04
#define EnterDebugSig 0x08
/* Note: These are *not* the bit positions used for the flags in the P
* register of a real 6502. Rather, they have been distorted so that C,

View File

@ -1830,7 +1830,7 @@ YY_RULE_SETUP
/* step / step next instruction */
if (*debugtext == 'n') step_next = 1;
c_do_step(1);
do_step_or_next(1);
return STEP;
}
YY_BREAK
@ -1847,7 +1847,7 @@ YY_RULE_SETUP
arg1 = strtol(debugtext, (char**)NULL, 16);
if ((arg1 < 1) || (arg1 > 255)) arg1 = 255;
c_do_step(arg1);
do_step_or_next(arg1);
return STEP;
}
YY_BREAK
@ -1867,9 +1867,9 @@ YY_RULE_SETUP
if (op == 0x60) --step_frame; /* RTS */
if (!step_frame) break; /* finished */
cpu65_step();
begin_cpu_step();
}
end_step(); /* print location */
end_cpu_step(); /* print location */
return FINISH;
}
YY_BREAK
@ -1912,8 +1912,8 @@ YY_RULE_SETUP
arg1 = cpu65_current.pc + delta;
while ((cpu65_current.pc != arg1) && !at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return UNTIL;
}
YY_BREAK
@ -1928,8 +1928,8 @@ YY_RULE_SETUP
/* DANGEROUS! */
cpu65_current.pc = strtol(debugtext, (char**)NULL, 16);
while (!at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return GO;
}
YY_BREAK
@ -1940,8 +1940,8 @@ YY_RULE_SETUP
{
/* run while remaining in debugger console */
while (!at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return GO;
}
YY_BREAK

View File

@ -18,7 +18,7 @@
#ifndef A2_DEBUG_H
#define A2_DEBUG_H
#include <stdio.h>
#include "common.h"
/* debugger defines */
#define BUF_X 39
@ -87,18 +87,21 @@ void show_regs();
void display_help();
void show_lc_info();
void show_disk_info();
void c_do_step(int);
void do_step_or_next(int);
void begin_cpu_step();
void end_cpu_step();
int at_haltpt();
void end_step();
void set_halt_opcode(unsigned char opcode);
void set_halt_65c02();
void clear_halt_65c02();
void clear_halt_opcode(unsigned char opcode);
void show_opcode_breakpts();
void c_stepping_yield();
extern const struct opcode_struct opcodes_6502[256];
extern const struct opcode_struct opcodes_65c02[256];
extern const struct opcode_struct opcodes_undoc[256];
extern const char * const disasm_templates[15];
extern const char* const disasm_templates[15];
#endif

View File

@ -447,7 +447,7 @@ ADDRS [0-9a-fA-F]+
/* step / step next instruction */
if (*debugtext == 'n') step_next = 1;
c_do_step(1);
do_step_or_next(1);
return STEP;
}
@ -460,7 +460,7 @@ ADDRS [0-9a-fA-F]+
arg1 = strtol(debugtext, (char**)NULL, 16);
if ((arg1 < 1) || (arg1 > 255)) arg1 = 255;
c_do_step(arg1);
do_step_or_next(arg1);
return STEP;
}
@ -476,9 +476,9 @@ ADDRS [0-9a-fA-F]+
if (op == 0x60) --step_frame; /* RTS */
if (!step_frame) break; /* finished */
cpu65_step();
begin_cpu_step();
}
end_step(); /* print location */
end_cpu_step(); /* print location */
return FINISH;
}
@ -517,8 +517,8 @@ ADDRS [0-9a-fA-F]+
arg1 = cpu65_current.pc + delta;
while ((cpu65_current.pc != arg1) && !at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return UNTIL;
}
@ -529,16 +529,16 @@ ADDRS [0-9a-fA-F]+
/* DANGEROUS! */
cpu65_current.pc = strtol(debugtext, (char**)NULL, 16);
while (!at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return GO;
}
{BOS}go?{EOS} {
/* run while remaining in debugger console */
while (!at_haltpt() && (c_mygetch(0) == -1))
cpu65_step();
end_step(); /* print location */
begin_cpu_step();
end_cpu_step(); /* print location */
return GO;
}

View File

@ -23,11 +23,6 @@
#include "cpu.h"
#include "prefs.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
const struct opcode_struct *opcodes;
int step_next; /* stepping over instructions */
@ -241,9 +236,7 @@ void dump_mem(int addrs, int len, int lc, int do_ascii, int rambank) {
if (lc)
{
op = (addrs+j >= 0x1000) ? language_card[rambank][(addrs+j)-0x1000]
: (lc == 1) ? language_banks[rambank][addrs+j]
: language_banks[rambank][0x1000+addrs+j];
op = (addrs+j >= 0x1000) ? language_card[rambank][(addrs+j)-0x1000] : (lc == 1) ? language_banks[rambank][addrs+j] : language_banks[rambank][0x1000+addrs+j];
}
else
{
@ -267,8 +260,7 @@ void dump_mem(int addrs, int len, int lc, int do_ascii, int rambank) {
sprintf(second_buf[i], "%04X:%02X", orig_addrs+j, op);
if (do_ascii)
{
sprintf(second_buf[i]+23, "%c",
((op&0x7f) > 31) ? (op&0x7f) : '.');
sprintf(second_buf[i]+23, "%c", ((op&0x7f) > 31) ? (op&0x7f) : '.');
}
continue;
@ -277,8 +269,7 @@ void dump_mem(int addrs, int len, int lc, int do_ascii, int rambank) {
sprintf(second_buf[i]+5+mod*2, "%02X", op);
if (do_ascii)
{
sprintf(second_buf[i]+23+mod, "%c",
((op&0x7f) > 31) ? (op&0x7f) : '.');
sprintf(second_buf[i]+23+mod, "%c", ((op&0x7f) > 31) ? (op&0x7f) : '.');
}
}
@ -318,9 +309,7 @@ void search_mem(char *hexstr, int lc, int rambank) {
if (lc)
{
op = (i >= 0x1000) ? language_card[rambank][i-0x1000]
: (lc == 1) ? language_banks[rambank][i]
: language_banks[rambank][0x1000+i];
op = (i >= 0x1000) ? language_card[rambank][i-0x1000] : (lc == 1) ? language_banks[rambank][i] : language_banks[rambank][0x1000+i];
}
else
{
@ -332,8 +321,7 @@ void search_mem(char *hexstr, int lc, int rambank) {
++j; /* increment */
if (!isxdigit(*(hexstr+j))) /* end of bytes? */
{ /* then we found a match */
sprintf(second_buf[num_buffer_lines], "%04X: %s",
i-(j>>1), hexstr);
sprintf(second_buf[num_buffer_lines], "%04X: %s", i-(j>>1), hexstr);
num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2);
j = 0; continue;
}
@ -341,8 +329,7 @@ void search_mem(char *hexstr, int lc, int rambank) {
++j;
if (!isxdigit(*(hexstr+j))) /* end of bytes? */
{ /* then we found a match */
sprintf(second_buf[num_buffer_lines], "%04X: %s",
i-(j>>1)+1, hexstr);
sprintf(second_buf[num_buffer_lines], "%04X: %s", i-(j>>1)+1, hexstr);
num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2);
j = 0; continue;
}
@ -422,8 +409,7 @@ void set_lc_mem(int addrs, int lcbank, char *hexstr) {
{
language_card[0][addrs - 0x1000] = data;
}
else
if (lcbank)
else if (lcbank)
{
language_banks[0][addrs] = data;
}
@ -536,15 +522,12 @@ void disasm(int addrs, int len, int lc, int rambank) {
/* save hexdump in second_buf */
end = (lc) ? 0x3000 : 0x10000;
for (i = num_buffer_lines, j = addrs, k=orig_addrs;
((i<len) && (j<end)); i++, j++)
for (i = num_buffer_lines, j = addrs, k=orig_addrs; ((i<len) && (j<end)); i++, j++)
{
if (lc)
{
op = (j >= 0x1000) ? language_card[rambank][j-0x1000]
: (lc == 1) ? language_banks[rambank][j]
: language_banks[rambank][0x1000+j];
op = (j >= 0x1000) ? language_card[rambank][j-0x1000] : (lc == 1) ? language_banks[rambank][j] : language_banks[rambank][0x1000+j];
}
else
{
@ -555,9 +538,7 @@ void disasm(int addrs, int len, int lc, int rambank) {
{
case addr_implied:
case addr_accumulator: /* no arg */
sprintf(second_buf[i], "/%02X/%04X: %02X %s %s",
rambank, k++, op, opcodes[op].mnemonic,
disasm_templates[opcodes[op].mode]);
sprintf(second_buf[i], "/%02X/%04X: %02X %s %s", rambank, k++, op, opcodes[op].mnemonic, disasm_templates[opcodes[op].mode]);
break;
case addr_immediate:
@ -575,19 +556,14 @@ void disasm(int addrs, int len, int lc, int rambank) {
if (lc)
{
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000]
: (lc == 1) ? language_banks[rambank][++j]
: language_banks[rambank][++j+0x1000];
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000] : (lc == 1) ? language_banks[rambank][++j] : language_banks[rambank][++j+0x1000];
}
else
{
arg1 = apple_ii_64k[rambank][++j];
}
sprintf(fmt, "/%02X/%04X: %02X%02X %s %s",
rambank, k, op, (unsigned char)arg1,
opcodes[op].mnemonic,
disasm_templates[opcodes[op].mode]);
sprintf(fmt, "/%02X/%04X: %02X%02X %s %s", rambank, k, op, (unsigned char)arg1, opcodes[op].mnemonic, disasm_templates[opcodes[op].mode]);
sprintf(second_buf[i], fmt, (unsigned char)arg1);
k+=2;
@ -606,12 +582,8 @@ void disasm(int addrs, int len, int lc, int rambank) {
if (lc)
{
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000]
: (lc == 1) ? language_banks[rambank][++j]
: language_banks[rambank][++j+0x1000];
arg2 = (j >= 0x1000) ? language_card[rambank][++j-0x1000]
: (lc == 1) ? language_banks[rambank][++j]
: language_banks[rambank][++j+0x1000];
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000] : (lc == 1) ? language_banks[rambank][++j] : language_banks[rambank][++j+0x1000];
arg2 = (j >= 0x1000) ? language_card[rambank][++j-0x1000] : (lc == 1) ? language_banks[rambank][++j] : language_banks[rambank][++j+0x1000];
}
else
{
@ -619,12 +591,8 @@ void disasm(int addrs, int len, int lc, int rambank) {
arg2 = apple_ii_64k[rambank][++j];
}
sprintf(fmt, "/%02X/%04X: %02X%02X%02X %s %s",
rambank, k, op, (unsigned char)arg1, (unsigned char)arg2,
opcodes[op].mnemonic,
disasm_templates[opcodes[op].mode]);
sprintf(second_buf[i], fmt, (unsigned char)arg2,
(unsigned char)arg1);
sprintf(fmt, "/%02X/%04X: %02X%02X%02X %s %s", rambank, k, op, (unsigned char)arg1, (unsigned char)arg2, opcodes[op].mnemonic, disasm_templates[opcodes[op].mode]);
sprintf(second_buf[i], fmt, (unsigned char)arg2, (unsigned char)arg1);
k+=3;
break;
@ -637,28 +605,21 @@ void disasm(int addrs, int len, int lc, int rambank) {
if (lc)
{
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000]
: (lc == 1) ? language_banks[rambank][++j]
: language_banks[rambank][++j+0x1000];
arg1 = (j >= 0x1000) ? language_card[rambank][++j-0x1000] : (lc == 1) ? language_banks[rambank][++j] : language_banks[rambank][++j+0x1000];
}
else
{
arg1 = apple_ii_64k[rambank][++j];
}
sprintf(fmt, "/%02X/%04X: %02X%02X %s %s",
rambank, k, op, (unsigned char)arg1,
opcodes[op].mnemonic,
disasm_templates[opcodes[op].mode]);
sprintf(fmt, "/%02X/%04X: %02X%02X %s %s", rambank, k, op, (unsigned char)arg1, opcodes[op].mnemonic, disasm_templates[opcodes[op].mode]);
if (arg1 < 0)
{
sprintf(second_buf[i], fmt,
k + arg1 + 2, '-', (unsigned char)(-arg1));
sprintf(second_buf[i], fmt, k + arg1 + 2, '-', (unsigned char)(-arg1));
}
else
{
sprintf(second_buf[i], fmt,
k + arg1 + 2, '+', (unsigned char)arg1);
sprintf(second_buf[i], fmt, k + arg1 + 2, '+', (unsigned char)arg1);
}
k+=2;
@ -678,16 +639,8 @@ void disasm(int addrs, int len, int lc, int rambank) {
------------------------------------------------------------------------- */
void show_regs() {
sprintf(second_buf[num_buffer_lines++], "PC = %04X EA = %04X SP = %04X",
cpu65_current.pc,
cpu65_debug.ea,
cpu65_current.sp + 0x0100);
sprintf(second_buf[num_buffer_lines++],
"X = %02X Y = %02X A = %02X F = %02X",
cpu65_current.x,
cpu65_current.y,
cpu65_current.a,
cpu65_current.f);
sprintf(second_buf[num_buffer_lines++], "PC = %04X EA = %04X SP = %04X", cpu65_current.pc, cpu65_debug.ea, cpu65_current.sp + 0x0100);
sprintf(second_buf[num_buffer_lines++], "X = %02X Y = %02X A = %02X F = %02X", cpu65_current.x, cpu65_current.y, cpu65_current.a, cpu65_current.f);
memset(second_buf[num_buffer_lines], ' ', BUF_X);
if (cpu65_current.f & C_Flag)
@ -878,9 +831,7 @@ int at_haltpt() {
unsigned char op = get_current_opcode();
if (op_breakpoints[op])
{
sprintf(second_buf[num_buffer_lines++],
"stopped at %04X bank %d instruction %02X",
cpu65_current.pc, c_get_current_rambank(cpu65_current.pc), op);
sprintf(second_buf[num_buffer_lines++], "stopped at %04X bank %d instruction %02X", cpu65_current.pc, c_get_current_rambank(cpu65_current.pc), op);
}
for (i = 0; i < MAX_BRKPTS; i++)
@ -888,8 +839,7 @@ int at_haltpt() {
if (cpu65_current.pc == breakpoints[i])
{
sprintf(second_buf[num_buffer_lines++], "stopped at %04X bank %d",
breakpoints[i], c_get_current_rambank(cpu65_current.pc));
sprintf(second_buf[num_buffer_lines++], "stopped at %04X bank %d", breakpoints[i], c_get_current_rambank(cpu65_current.pc));
}
}
@ -901,14 +851,11 @@ int at_haltpt() {
{
if (cpu65_debug.rw & 2)
{
sprintf(second_buf[num_buffer_lines++],
"wrote: %04X: %02X",
watchpoints[i], cpu65_debug.d);
sprintf(second_buf[num_buffer_lines++], "wrote: %04X: %02X", watchpoints[i], cpu65_debug.d);
}
else
{
sprintf(second_buf[num_buffer_lines++],
"read: %04X", watchpoints[i]);
sprintf(second_buf[num_buffer_lines++], "read: %04X", watchpoints[i]);
}
cpu65_debug.rw = 0; /* only allow WP to trip once */
@ -929,21 +876,16 @@ void show_breakpts() {
{
if ((breakpoints[k] >= 0) && (watchpoints[k] >= 0))
{
sprintf(second_buf[i++], "break %02d at %04X watch %02d at %04X",
k+1, breakpoints[k], k+1, watchpoints[k]);
sprintf(second_buf[i++], "break %02d at %04X watch %02d at %04X", k+1, breakpoints[k], k+1, watchpoints[k]);
}
else
if (breakpoints[k] >= 0)
else if (breakpoints[k] >= 0)
{
sprintf(second_buf[i++], "break %02d at %04X",
k+1, breakpoints[k]);
sprintf(second_buf[i++], "break %02d at %04X", k+1, breakpoints[k]);
}
else
if (watchpoints[k] >= 0)
else if (watchpoints[k] >= 0)
{
memset(second_buf[i], ' ', BUF_X);
sprintf(second_buf[i++]+16, " watch %02d at %04X",
k+1, watchpoints[k]);
sprintf(second_buf[i++]+16, " watch %02d at %04X", k+1, watchpoints[k]);
}
}
@ -991,58 +933,28 @@ void show_opcode_breakpts() {
void show_lc_info() {
int i = num_buffer_lines;
sprintf(second_buf[i++], "lc bank = %d", 1 + !!(softswitches && SS_BANK2));
(softswitches & SS_LCWRT) ? sprintf(second_buf[i++], "write LC")
: sprintf(second_buf[i++], "LC write protected");
(softswitches & SS_LCRAM) ? sprintf(second_buf[i++], "read LC")
: sprintf(second_buf[i++], "read ROM");
(softswitches & SS_LCWRT) ? sprintf(second_buf[i++], "write LC") : sprintf(second_buf[i++], "LC write protected");
(softswitches & SS_LCRAM) ? sprintf(second_buf[i++], "read LC") : sprintf(second_buf[i++], "read ROM");
sprintf(second_buf[i++], "second = %d", !!(softswitches && SS_LCSEC));
num_buffer_lines = i;
}
void show_misc_info() {
int i = num_buffer_lines;
sprintf(second_buf[i++], "TEXT (%04X): %s",
SW_TEXT + !!(softswitches & SS_TEXT),
(softswitches & SS_TEXT) ? "on" : "off");
sprintf(second_buf[i++], "MIXED (%04X): %s",
SW_MIXED + !!(softswitches & SS_MIXED),
(softswitches & SS_MIXED) ? "on" : "off");
sprintf(second_buf[i++], "PAGE2 (%04X): %s",
SW_PAGE2 + !!(softswitches & SS_PAGE2),
(softswitches & SS_PAGE2) ? "on" : "off");
sprintf(second_buf[i++], "HIRES (%04X): %s",
SW_HIRES + !!(softswitches & SS_HIRES),
(softswitches & SS_HIRES) ? "on" : "off");
sprintf(second_buf[i++], "80STORE (%04X): %s",
SW_80STORE + !!(softswitches & SS_80STORE),
(softswitches & SS_80STORE) ? "on" : "off");
sprintf(second_buf[i++], "RAMRD (%04X): %s",
SW_RAMRD + !!(softswitches & SS_RAMRD),
(softswitches & SS_RAMRD) ? "on" : "off");
sprintf(second_buf[i++], "RAMWRT (%04X): %s",
SW_RAMWRT + !!(softswitches & SS_RAMWRT),
(softswitches & SS_RAMWRT) ? "on" : "off");
sprintf(second_buf[i++], "ALTZP (%04X): %s",
SW_ALTZP + !!(softswitches & SS_ALTZP),
(softswitches & SS_ALTZP) ? "on" : "off");
sprintf(second_buf[i++], "80COL (%04X): %s",
SW_80COL + !!(softswitches & SS_80COL),
(softswitches & SS_80COL) ? "on" : "off");
sprintf(second_buf[i++], "ALTCHAR (%04X): %s",
SW_ALTCHAR + !!(softswitches & SS_ALTCHAR),
(softswitches & SS_ALTCHAR) ? "on" : "off");
sprintf(second_buf[i++], "SLOTC3ROM (%04X): %s",
SW_SLOTC3ROM -/*anomaly*/ !!(softswitches & SS_C3ROM),
(softswitches & SS_C3ROM) ? "on" : "off");
sprintf(second_buf[i++], "SLOTCXROM (%04X): %s",
SW_SLOTCXROM + !!(softswitches & SS_CXROM),
(softswitches & SS_CXROM) ? "on" : "off");
sprintf(second_buf[i++], "DHIRES (%04X): %s",
SW_DHIRES + !!(softswitches && SS_DHIRES),
(softswitches & SS_DHIRES) ? "on" : "off");
sprintf(second_buf[i++], "IOUDIS (%04X): %s",
SW_IOUDIS + !!(softswitches && SS_IOUDIS),
(softswitches && SS_IOUDIS) ? "on" : "off");
sprintf(second_buf[i++], "TEXT (%04X): %s", SW_TEXT + !!(softswitches & SS_TEXT), (softswitches & SS_TEXT) ? "on" : "off");
sprintf(second_buf[i++], "MIXED (%04X): %s", SW_MIXED + !!(softswitches & SS_MIXED), (softswitches & SS_MIXED) ? "on" : "off");
sprintf(second_buf[i++], "PAGE2 (%04X): %s", SW_PAGE2 + !!(softswitches & SS_PAGE2), (softswitches & SS_PAGE2) ? "on" : "off");
sprintf(second_buf[i++], "HIRES (%04X): %s", SW_HIRES + !!(softswitches & SS_HIRES), (softswitches & SS_HIRES) ? "on" : "off");
sprintf(second_buf[i++], "80STORE (%04X): %s", SW_80STORE + !!(softswitches & SS_80STORE), (softswitches & SS_80STORE) ? "on" : "off");
sprintf(second_buf[i++], "RAMRD (%04X): %s", SW_RAMRD + !!(softswitches & SS_RAMRD), (softswitches & SS_RAMRD) ? "on" : "off");
sprintf(second_buf[i++], "RAMWRT (%04X): %s", SW_RAMWRT + !!(softswitches & SS_RAMWRT), (softswitches & SS_RAMWRT) ? "on" : "off");
sprintf(second_buf[i++], "ALTZP (%04X): %s", SW_ALTZP + !!(softswitches & SS_ALTZP), (softswitches & SS_ALTZP) ? "on" : "off");
sprintf(second_buf[i++], "80COL (%04X): %s", SW_80COL + !!(softswitches & SS_80COL), (softswitches & SS_80COL) ? "on" : "off");
sprintf(second_buf[i++], "ALTCHAR (%04X): %s", SW_ALTCHAR + !!(softswitches & SS_ALTCHAR), (softswitches & SS_ALTCHAR) ? "on" : "off");
sprintf(second_buf[i++], "SLOTC3ROM (%04X): %s", SW_SLOTC3ROM -/*anomaly*/ !!(softswitches & SS_C3ROM), (softswitches & SS_C3ROM) ? "on" : "off");
sprintf(second_buf[i++], "SLOTCXROM (%04X): %s", SW_SLOTCXROM + !!(softswitches & SS_CXROM), (softswitches & SS_CXROM) ? "on" : "off");
sprintf(second_buf[i++], "DHIRES (%04X): %s", SW_DHIRES + !!(softswitches && SS_DHIRES), (softswitches & SS_DHIRES) ? "on" : "off");
sprintf(second_buf[i++], "IOUDIS (%04X): %s", SW_IOUDIS + !!(softswitches && SS_IOUDIS), (softswitches && SS_IOUDIS) ? "on" : "off");
/* sprintf(second_buf[i++], "RDVBLBAR: %s", (SLOTCXROM & 0x80) */
/* ? "on" : "off"); */
@ -1092,35 +1004,21 @@ void show_disk_info() {
}
memset(second_buf[++i], ' ', BUF_X);
*(second_buf[i] + sprintf(second_buf[i],
"%s %d bytes",
(disk6.disk[0].nibblized) ? ".nib" : ".dsk",
(int)disk6.disk[0].file_size)) = ' ';
sprintf(second_buf[i++]+off, "%s %d bytes",
(disk6.disk[1].nibblized) ? ".nib" : ".dsk",
(int)disk6.disk[1].file_size);
*(second_buf[i] + sprintf(second_buf[i], "%s %d bytes", (disk6.disk[0].nibblized) ? ".nib" : ".dsk", (int)disk6.disk[0].file_size)) = ' ';
sprintf(second_buf[i++]+off, "%s %d bytes", (disk6.disk[1].nibblized) ? ".nib" : ".dsk", (int)disk6.disk[1].file_size);
memset(second_buf[i], ' ', BUF_X);
*(second_buf[i] + sprintf(second_buf[i], "write %s",
(disk6.disk[0].protected) ? "protected" : "enabled")) = ' ';
sprintf(second_buf[i++]+off, "write %s",
(disk6.disk[1].protected) ? "protected" : "enabled");
*(second_buf[i] + sprintf(second_buf[i], "write %s", (disk6.disk[0].protected) ? "protected" : "enabled")) = ' ';
sprintf(second_buf[i++]+off, "write %s", (disk6.disk[1].protected) ? "protected" : "enabled");
memset(second_buf[i], ' ', BUF_X);
*(second_buf[i] + sprintf(second_buf[i],
"phase %d %s",
disk6.disk[0].phase,
(disk6.disk[0].phase_change) ? "(new)" : "")) = ' ';
sprintf(second_buf[i++]+off,
"phase %d %s",
disk6.disk[1].phase,
(disk6.disk[1].phase_change) ? "(new)" : "");
*(second_buf[i] + sprintf(second_buf[i], "phase %d %s", disk6.disk[0].phase, (disk6.disk[0].phase_change) ? "(new)" : "")) = ' ';
sprintf(second_buf[i++]+off, "phase %d %s", disk6.disk[1].phase, (disk6.disk[1].phase_change) ? "(new)" : "");
memset(second_buf[i], ' ', BUF_X);
if (!disk6.disk[0].nibblized)
{
*(second_buf[i] + sprintf(second_buf[i], "sector %d",
disk6.disk[0].sector)) = ' ';
*(second_buf[i] + sprintf(second_buf[i], "sector %d", disk6.disk[0].sector)) = ' ';
if (disk6.disk[1].nibblized)
{
++i;
@ -1129,8 +1027,7 @@ void show_disk_info() {
if (!disk6.disk[1].nibblized)
{
sprintf(second_buf[i++]+off, "sector %d",
disk6.disk[1].sector);
sprintf(second_buf[i++]+off, "sector %d", disk6.disk[1].sector);
}
num_buffer_lines = i;
@ -1149,28 +1046,63 @@ void clear_debugger_screen() {
}
/* -------------------------------------------------------------------------
end_step () - finish a stepping command
end_cpu_step () - finish a stepping command
display the next instruction, and tell whether it will branch
------------------------------------------------------------------------- */
void end_step() {
int branch;
void end_cpu_step() {
cpu65_set_stepping(0);
clear_debugger_screen();
disasm(cpu65_current.pc, 1, 0, -1); /* show next instruction */
branch = will_branch(); /* test if it will branch */
disasm(cpu65_current.pc, 1, 0, -1);
int branch = will_branch();
if (branch == -1)
{
return; /* n/a */
return;
}
sprintf(second_buf[num_buffer_lines++], "%s",
(branch) ? "will branch" : "will not branch");
sprintf(second_buf[num_buffer_lines++], "%s", (branch) ? "will branch" : "will not branch");
}
/* -------------------------------------------------------------------------
begin_cpu_step() - step the CPU
set the CPU into stepping mode and yield to CPU thread
------------------------------------------------------------------------- */
void begin_cpu_step()
{
cpu65_set_stepping(1);
c_stepping_yield();
}
/* -------------------------------------------------------------------------
c_do_step () - step into or step over commands
c_stepping_yield()
called to yield execution between cpu and main threads when stepping
------------------------------------------------------------------------- */
void c_do_step(int step_count) {
void c_stepping_yield()
{
int err = 0;
if ((err = pthread_mutex_unlock(&interface_mutex)))
{
ERRLOG("pthread_mutex_unlock : %d", err);
}
// presumably other thread executes while we yield and sleep ...
if ((err = pthread_yield()))
{
ERRLOG("pthread_yield ; %d", err);
}
static struct timespec deltat = { .tv_sec=0, .tv_nsec=1 };
nanosleep(&deltat, NULL);
if ((err = pthread_mutex_lock(&interface_mutex)))
{
ERRLOG("pthread_mutex_lock : %d", err);
}
}
/* -------------------------------------------------------------------------
do_step_or_next () - step into or step over commands
------------------------------------------------------------------------- */
void do_step_or_next(int step_count) {
char ch;
unsigned char op;
int step_frame = 0;
@ -1195,16 +1127,16 @@ void c_do_step(int step_count) {
--step_frame; /* RTS */
}
cpu65_step();
begin_cpu_step();
} while (((ch = c_mygetch(0)) == -1) && !at_haltpt() && step_frame);
}
else
{
cpu65_step(); /* step one instruction */
begin_cpu_step();
}
} while (--step_count && !at_haltpt() && (c_mygetch(0) == -1));
end_step(); /* print location */
end_cpu_step();
}
/* -------------------------------------------------------------------------
@ -1212,7 +1144,7 @@ void c_do_step(int step_count) {
show quick reference command usage
------------------------------------------------------------------------- */
void display_help() {
/* "|||||||||||||||||||||||||||||||||||||" */
/* "|||||||||||||||||||||||||||||||||||||" */
int i = num_buffer_lines;
sprintf(second_buf[i++], "d{is} {lc1|lc2} {/bank/addr} {+}{len}");
sprintf(second_buf[i++], "m{em} {lc1|lc2} {/bank/addr} {+}{len}");
@ -1287,7 +1219,7 @@ void do_debug_command() {
++j;
}
memset(command_buf[i] + j, ' ', BUF_X - j - 1);
memset(command_buf[i] + j, ' ', BUF_X - j/* - 1*/);
command_buf[i++][BUF_X - 1] = '\0';
}
@ -1349,14 +1281,13 @@ void c_do_debugging() {
c_interface_print(0, i, 2, screen[ i ] );
}
for (;; )
for (;;)
{
/* print command line */
c_interface_print(1, 1+PROMPT_Y, 0, command_line);
/* highlight cursor */
video_plotchar(1+command_pos, 1+PROMPT_Y, 1,
command_line[command_pos]);
video_plotchar(1+command_pos, 1+PROMPT_Y, 1, command_line[command_pos]);
while ((ch = c_mygetch(1)) == -1)
{
@ -1370,23 +1301,19 @@ void c_do_debugging() {
else
{
/* backspace */
if ((ch == 127 || ch == 8) &&
(command_pos > PROMPT_X))
if ((ch == 127 || ch == 8) && (command_pos > PROMPT_X))
{
command_line[--command_pos] = ' ';
}
/* return */
else
if (ch == 13)
else if (ch == 13)
{
command_line[command_pos] = '\0';
do_debug_command();
command_pos = PROMPT_X;
}
/* normal character */
else
if ((ch >= ' ') && (ch < 127) &&
(command_pos < PROMPT_END_X))
else if ((ch >= ' ') && (ch < 127) && (command_pos < PROMPT_END_X))
{
command_line[command_pos++] = ch;
}

View File

@ -42,6 +42,7 @@ unsigned char joy_button0 = 0;
unsigned char joy_button1 = 0;
unsigned char joy_button2 = 0;
/* mutex used to synchronize between cpu and main threads */
pthread_mutex_t interface_mutex = PTHREAD_MUTEX_INITIALIZER;
#ifdef PC_JOYSTICK
@ -64,14 +65,14 @@ static int apple_ii_keymap_plain[128] =
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 32-39 */
8, -1, -1, 21, 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* (pause) */, /* 112-119 */
-1, -1, -1, -1, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* (pause) */,/* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_ii_keymap_ctrl[128] =
@ -82,14 +83,14 @@ static int apple_ii_keymap_ctrl[128] =
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
8, -1, -1, 21, 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, BOT, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, BOT, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_ii_keymap_shifted[128] =
@ -100,14 +101,14 @@ static int apple_ii_keymap_shifted[128] =
'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', /* 32-39 */
8, -1, -1, 21, 'Z', 'X', 'C', 'V', /* 40-47 */
'B', '^', 'M', '<', '>', '?', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, JB1, RST, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
/* ----------------------------------------------------
@ -121,14 +122,14 @@ static int apple_iie_keymap_plain[128] =
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 32-39 */
'\'', '`', -1,'\\', 'z', 'x', 'c', 'v', /* 40-47 */
'b', 'n', 'm', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_ctrl[128] =
@ -139,14 +140,14 @@ static int apple_iie_keymap_ctrl[128] =
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
'\'', '`', -1,'\\', 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, BOT, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, BOT, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_shifted[128] =
@ -157,14 +158,14 @@ static int apple_iie_keymap_shifted[128] =
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* 32-39 */
'"', '~', -1, '|', 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', '<', '>', '?', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_caps[128] =
@ -175,14 +176,14 @@ static int apple_iie_keymap_caps[128] =
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 32-39 */
'\'', '`', -1,'\\', 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_shift_ctrl[128] =
@ -193,23 +194,19 @@ static int apple_iie_keymap_shift_ctrl[128] =
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
'\'', '`', 28, -1, 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, BOT, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, BOT, JB1, RST, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kF4 /* pause */, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static char key_pressed[ 256 ];
/* ----------------------------------------------------
functions
---------------------------------------------------- */
/* -------------------------------------------------------------------------
* This routine is called periodically to update the state of the emulator.
* -handles switching to menus
@ -238,39 +235,48 @@ void c_periodic_update(int dummysig) {
case RST:
cpu65_interrupt(ResetSig);
break;
case BOT:
cpu65_interrupt(RebootSig);
break;
case J_C:
joy_x = joy_center_x;
joy_y = joy_center_y;
break;
case kF1:
pthread_mutex_lock(&interface_mutex);
c_interface_select_diskette( 0 );
pthread_mutex_unlock(&interface_mutex);
break;
case kF2:
pthread_mutex_lock(&interface_mutex);
c_interface_select_diskette( 1 );
pthread_mutex_unlock(&interface_mutex);
break;
case kF4:
pthread_mutex_lock(&interface_mutex);
while (c_mygetch(1) == -1)
{
struct timespec ts = { .tv_sec=0, .tv_nsec=1 };
nanosleep(&ts, NULL);
} /*busy loop*/
}
pthread_mutex_unlock(&interface_mutex);
break;
case kF5:
pthread_mutex_lock(&interface_mutex);
c_interface_keyboard_layout();
pthread_mutex_unlock(&interface_mutex);
break;
case kF7:
cpu65_interrupt(EnterDebugSig);
pthread_mutex_lock(&interface_mutex);
c_do_debugging();
pthread_mutex_unlock(&interface_mutex);
break;
#if 0
case kF8:
@ -396,14 +402,6 @@ void c_periodic_update(int dummysig) {
}
}
/* Called from cpu code. Perhaps should be moved to misc.c, but was
* abstracted from function above...
*/
void enter_debugger(void)
{
c_do_debugging();
}
/* -------------------------------------------------------------------------
void c_read_raw_key() : handle a scancode
------------------------------------------------------------------------- */
@ -419,41 +417,35 @@ void c_read_raw_key(int scancode, int pressed) {
caps_lock = !caps_lock;
}
if ((key_pressed[ SCODE_L_SHIFT ] || /* shift-ctrl */
key_pressed[ SCODE_R_SHIFT ]) &&
(key_pressed[ SCODE_L_CTRL ] ||
key_pressed[ SCODE_R_CTRL ]))
if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) && /* shift-ctrl */
(key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]))
{
keymap = apple_iie_keymap_shift_ctrl;
}
else if (key_pressed[ SCODE_L_CTRL ] || /* ctrl */
key_pressed[ SCODE_R_CTRL ])
else if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) /* ctrl */
{
keymap = apple_iie_keymap_ctrl;
}
else if (key_pressed[ SCODE_L_SHIFT ] || /* shift */
key_pressed[ SCODE_R_SHIFT ])
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) /* shift */
{
keymap = apple_iie_keymap_shifted;
}
else if (caps_lock) /* caps lock */
else if (caps_lock)
{
keymap = apple_iie_keymap_caps;
}
else /* plain */
else /* plain */
{
keymap = apple_iie_keymap_plain;
}
}
else
{
if (key_pressed[ SCODE_L_CTRL ] ||
key_pressed[ SCODE_R_CTRL ])
if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])
{
keymap = apple_ii_keymap_ctrl;
}
else if (key_pressed[ SCODE_L_SHIFT ] ||
key_pressed[ SCODE_R_SHIFT ])
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ])
{
keymap = apple_ii_keymap_shifted;
}

View File

@ -24,8 +24,6 @@
#define EXECUTION_PERIOD_NSECS 1000000 // AppleWin: nExecutionPeriodUsec
extern void cpu65_run();
double g_fCurrentCLK6502 = CLK_6502;
bool g_bFullSpeed = false; // HACK TODO FIXME : prolly shouldn't be global anymore -- don't think it's necessary for speaker/soundcore/etc anymore ...
uint64_t g_nCumulativeCycles = 0; // cumulative cycles since emulator (re)start
@ -167,7 +165,7 @@ void cpu_thread(void *dummyptr) {
{
g_nCumulativeCycles = 0;
static int16_t cycles_adjust = 0;
LOG("cpu_thread : entering cpu65_run()...");
LOG("cpu_thread : begin main loop ...");
clock_gettime(CLOCK_MONOTONIC, &t0);
do {