diff --git a/src/apple2.h b/src/apple2.h index 32205995..289abf64 100644 --- a/src/apple2.h +++ b/src/apple2.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Common definitions * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,32 +7,32 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ #ifndef A2_H #define A2_H -#define BANK2 0x10000 +#define BANK2 0x10000 /* Code alignment */ #if defined(__i486__) || defined(__i586__) -#define ALIGN .balign 16 +#define ALIGN .balign 16 #else /* !(__i486__ || __i586__) */ -#define ALIGN .balign 4 +#define ALIGN .balign 4 #endif /* !(__i486__ || __i586__) */ /* Symbol naming issues */ #ifdef NO_UNDERSCORES -#define SN(foo) foo -#define E(foo) .globl foo ; ALIGN ; foo##: +#define SN(foo) foo +#define E(foo) .globl foo; ALIGN; foo##: #else /* !NO_UNDERSCORES */ -#define SN(foo) _##foo -#define E(foo) .globl _##foo ; ALIGN ; _##foo##: +#define SN(foo) _##foo +#define E(foo) .globl _##foo; ALIGN; _##foo##: #endif /* !NO_UNDERSCORES */ -#endif/* A2_H */ +#endif /* A2_H */ diff --git a/src/cpu-supp.c b/src/cpu-supp.c index d1f37858..19f1cbfa 100644 --- a/src/cpu-supp.c +++ b/src/cpu-supp.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: C support for 6502 on i386 * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -20,66 +20,94 @@ #include "cpu.h" /* different than in defs.h! */ -#define C_Flag_6502 0x1 -#define X_Flag_6502 0x20 -#define I_Flag_6502 0x4 -#define V_Flag_6502 0x40 -#define B_Flag_6502 0x10 -#define D_Flag_6502 0x8 -#define Z_Flag_6502 0x2 -#define N_Flag_6502 0x80 +#define C_Flag_6502 0x1 +#define X_Flag_6502 0x20 +#define I_Flag_6502 0x4 +#define V_Flag_6502 0x40 +#define B_Flag_6502 0x10 +#define D_Flag_6502 0x8 +#define Z_Flag_6502 0x2 +#define N_Flag_6502 0x80 static void initialize_code_tables(void) { - int i; + int i; for (i = 0; i < 256; i++) { - unsigned char val = 0; + unsigned char val = 0; - if (i & C_Flag) - val |= C_Flag_6502; - if (i & X_Flag) - val |= X_Flag_6502; - if (i & I_Flag) - val |= I_Flag_6502; - if (i & V_Flag) - val |= V_Flag_6502; - if (i & B_Flag) - val |= B_Flag_6502; - if (i & D_Flag) - val |= D_Flag_6502; - if (i & Z_Flag) - val |= Z_Flag_6502; - if (i & N_Flag) - val |= N_Flag_6502; + if (i & C_Flag) + { + val |= C_Flag_6502; + } - cpu65_flags_encode[ i ] = val | 0x20; - cpu65_flags_decode[ val ] = i; + if (i & X_Flag) + { + val |= X_Flag_6502; + } + + if (i & I_Flag) + { + val |= I_Flag_6502; + } + + if (i & V_Flag) + { + val |= V_Flag_6502; + } + + if (i & B_Flag) + { + val |= B_Flag_6502; + } + + if (i & D_Flag) + { + val |= D_Flag_6502; + } + + if (i & Z_Flag) + { + val |= Z_Flag_6502; + } + + if (i & N_Flag) + { + val |= N_Flag_6502; + } + + cpu65_flags_encode[ i ] = val | 0x20; + cpu65_flags_decode[ val ] = i; } } void cpu65_set(int flags) { - initialize_code_tables(); + initialize_code_tables(); - switch (flags & 0xf) - { - case CPU65_NMOS: - if (flags & CPU65_FAULT) - memcpy(cpu65__opcodes,cpu65__nmosbrk,1024); + switch (flags & 0xf) + { + case CPU65_NMOS: + if (flags & CPU65_FAULT) + { + memcpy(cpu65__opcodes,cpu65__nmosbrk,1024); + } else - memcpy(cpu65__opcodes,cpu65__nmos,1024); - break; - case CPU65_C02: + { + memcpy(cpu65__opcodes,cpu65__nmos,1024); + } + + break; + case CPU65_C02: memcpy(cpu65__opcodes,cpu65__cmos,1024); break; - default: + default: abort(); - } - - cpu65__signal = 0; + } + + cpu65__signal = 0; } void cpu65_interrupt(int reason) diff --git a/src/cpu.h b/src/cpu.h index e2aef8b0..5366472c 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Virtual 6502/65C02 interface * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -24,32 +24,32 @@ typedef void *RMEM; struct memory_vector { - RMEM r; - WMEM w; + RMEM r; + WMEM w; }; struct cpu65_state { - u_int16_t pc; /* Program counter */ - u_int8_t a; /* Accumulator */ - u_int8_t f; /* Flags (order not same as in real 6502) */ - u_int8_t x,y; /* Index register */ - u_int8_t sp; /* Stack Pointer */ + u_int16_t pc; /* Program counter */ + u_int8_t a; /* Accumulator */ + u_int8_t f; /* Flags (order not same as in real 6502) */ + u_int8_t x,y; /* Index register */ + u_int8_t sp; /* Stack Pointer */ }; -struct cpu65_extra /* for debugging */ +struct cpu65_extra /* for debugging */ { - u_int16_t ea; /* Last effective address */ - u_int8_t d; /* Last data byte written */ - u_int8_t op; /* 1 = read occured, 2 = write, 3 = both */ + u_int16_t ea; /* Last effective address */ + u_int8_t d; /* Last data byte written */ + u_int8_t op; /* 1 = read occured, 2 = write, 3 = both */ }; - -/* 6502 CPU models */ -#define CPU65_NMOS 0x0 -#define CPU65_C02 0x1 -#define CPU65_FAULT 0x100 /* Undoc. opcodes are BRK */ -#define CPU65_SYNCHRO 0x200 /* Synchronize speed, not imp. */ +/* 6502 CPU models */ +#define CPU65_NMOS 0x0 +#define CPU65_C02 0x1 + +#define CPU65_FAULT 0x100 /* Undoc. opcodes are BRK */ +#define CPU65_SYNCHRO 0x200 /* Synchronize speed, not imp. */ /* Set up the processor for a new run. Sets up opcode table. */ @@ -75,49 +75,49 @@ extern unsigned int cpu65_delay; #endif /* !__ASSEMBLER__ */ -#define RebootSig 0x01 -#define ResetSig 0x02 -#define DebugStepSig 0x04 -#define EnterDebugSig 0x08 +#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, - * N and Z match the analogous flags in the _80386_ flags register. +/* 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, + * N and Z match the analogous flags in the _80386_ flags register. * * Additionally, V matches the position of the overflow flag in the high byte * of the 80386 register. * */ -#define C_Flag 0x1 /* 6502 Carry */ -#define X_Flag 0x2 /* 6502 Xtra */ -#define I_Flag 0x4 /* 6502 Interrupt disable */ -#define V_Flag 0x8 /* 6502 Overflow */ -#define B_Flag 0x10 /* 6502 Break */ -#define D_Flag 0x20 /* 6502 Decimal mode */ -#define Z_Flag 0x40 /* 6502 Zero */ -#define N_Flag 0x80 /* 6502 Neg */ +#define C_Flag 0x1 /* 6502 Carry */ +#define X_Flag 0x2 /* 6502 Xtra */ +#define I_Flag 0x4 /* 6502 Interrupt disable */ +#define V_Flag 0x8 /* 6502 Overflow */ +#define B_Flag 0x10 /* 6502 Break */ +#define D_Flag 0x20 /* 6502 Decimal mode */ +#define Z_Flag 0x40 /* 6502 Zero */ +#define N_Flag 0x80 /* 6502 Neg */ -#define C_Flag_Bit 8 /* 6502 Carry */ -#define X_Flag_Bit 9 /* 6502 Xtra */ -#define I_Flag_Bit 10 /* 6502 Interrupt disable */ -#define V_Flag_Bit 11 /* 6502 Overflow */ -#define B_Flag_Bit 12 /* 6502 Break */ -#define D_Flag_Bit 13 /* 6502 Decimal mode */ -#define Z_Flag_Bit 14 /* 6502 Zero */ -#define N_Flag_Bit 15 /* 6502 Neg */ +#define C_Flag_Bit 8 /* 6502 Carry */ +#define X_Flag_Bit 9 /* 6502 Xtra */ +#define I_Flag_Bit 10 /* 6502 Interrupt disable */ +#define V_Flag_Bit 11 /* 6502 Overflow */ +#define B_Flag_Bit 12 /* 6502 Break */ +#define D_Flag_Bit 13 /* 6502 Decimal mode */ +#define Z_Flag_Bit 14 /* 6502 Zero */ +#define N_Flag_Bit 15 /* 6502 Neg */ -#define X_Reg %bl /* 6502 X register in %bl */ -#define Y_Reg %bh /* 6502 Y register in %bh */ -#define A_Reg %cl /* 6502 A register in %cl */ -#define F_Reg %ch /* 6502 flags in %ch */ -#define FF_Reg %ecx /* 6502 flags for bt */ -#define SP_Reg %edx /* 6502 Stack pointer */ -#define SP_Reg_L %dl /* 6502 Stack pointer low */ -#define SP_Reg_H %dh /* 6502 Stack pointer high */ -#define PC_Reg %si /* 6502 Program Counter */ -#define PC_Reg_E %esi /* 6502 Program Counter */ -#define EffectiveAddr %di /* Effective address */ -#define EffectiveAddr_E %edi /* Effective address */ +#define X_Reg %bl /* 6502 X register in %bl */ +#define Y_Reg %bh /* 6502 Y register in %bh */ +#define A_Reg %cl /* 6502 A register in %cl */ +#define F_Reg %ch /* 6502 flags in %ch */ +#define FF_Reg %ecx /* 6502 flags for bt */ +#define SP_Reg %edx /* 6502 Stack pointer */ +#define SP_Reg_L %dl /* 6502 Stack pointer low */ +#define SP_Reg_H %dh /* 6502 Stack pointer high */ +#define PC_Reg %si /* 6502 Program Counter */ +#define PC_Reg_E %esi /* 6502 Program Counter */ +#define EffectiveAddr %di /* Effective address */ +#define EffectiveAddr_E %edi /* Effective address */ #ifndef __ASSEMBLER__ /* Private data. */ @@ -128,4 +128,4 @@ extern void *const cpu65__cmos[256]; extern unsigned char cpu65__signal; #endif /* !__ASSEMBLER__ */ - + diff --git a/src/crusty.cfg b/src/crusty.cfg new file mode 100644 index 00000000..f98741cc --- /dev/null +++ b/src/crusty.cfg @@ -0,0 +1,412 @@ +# Uncrustify 0.59 +newlines = auto +input_tab_size = 8 +output_tab_size = 8 +string_escape_char = 92 +string_escape_char2 = 0 +tok_split_gte = false +utf8_bom = ignore +utf8_byte = false +utf8_force = false +indent_columns = 4 +indent_continue = 0 +indent_with_tabs = 0 +indent_cmt_with_tabs = false +indent_align_string = false +indent_xml_string = 0 +indent_brace = 0 +indent_braces = false +indent_braces_no_func = false +indent_braces_no_class = false +indent_braces_no_struct = false +indent_brace_parent = false +indent_namespace = true +indent_namespace_level = 4 +indent_namespace_limit = 0 +indent_extern = false +indent_class = true +indent_class_colon = false +indent_ctor_init = 0 +indent_else_if = false +indent_var_def_blk = 0 +indent_var_def_cont = false +indent_func_call_param = false +indent_func_def_param = false +indent_func_proto_param = false +indent_func_class_param = false +indent_func_ctor_var_param = false +indent_template_param = false +indent_func_param_double = false +indent_func_const = 0 +indent_func_throw = 0 +indent_member = 0 +indent_sing_line_comments = 0 +indent_relative_single_line_comments = false +indent_switch_case = 0 +indent_case_shift = 0 +indent_case_brace = 0 +indent_col1_comment = false +indent_label = 1 +indent_access_spec = 1 +indent_access_spec_body = false +indent_paren_nl = false +indent_paren_close = 0 +indent_comma_paren = false +indent_bool_paren = false +indent_first_bool_expr = false +indent_square_nl = false +indent_preserve_sql = false +indent_align_assign = true +sp_arith = ignore +sp_assign = ignore +sp_assign_default = ignore +sp_before_assign = ignore +sp_after_assign = ignore +sp_enum_assign = ignore +sp_enum_before_assign = ignore +sp_enum_after_assign = ignore +sp_pp_concat = add +sp_pp_stringify = add +sp_bool = ignore +sp_compare = ignore +sp_inside_paren = ignore +sp_paren_paren = ignore +sp_balance_nested_parens = false +sp_paren_brace = add +sp_before_ptr_star = ignore +sp_before_unnamed_ptr_star = ignore +sp_between_ptr_star = ignore +sp_after_ptr_star = ignore +sp_after_ptr_star_func = ignore +sp_before_ptr_star_func = ignore +sp_before_byref = ignore +sp_before_unnamed_byref = ignore +sp_after_byref = ignore +sp_after_byref_func = ignore +sp_before_byref_func = ignore +sp_after_type = force +sp_template_angle = ignore +sp_before_angle = ignore +sp_inside_angle = ignore +sp_after_angle = ignore +sp_angle_paren = ignore +sp_angle_word = ignore +sp_angle_shift = add +sp_before_sparen = add +sp_inside_sparen = ignore +sp_inside_sparen_close = ignore +sp_after_sparen = ignore +sp_sparen_brace = add +sp_invariant_paren = ignore +sp_after_invariant_paren = ignore +sp_special_semi = ignore +sp_before_semi = remove +sp_before_semi_for = ignore +sp_before_semi_for_empty = ignore +sp_after_semi = add +sp_after_semi_for = force +sp_after_semi_for_empty = ignore +sp_before_square = ignore +sp_before_squares = ignore +sp_inside_square = ignore +sp_after_comma = ignore +sp_before_comma = remove +sp_paren_comma = force +sp_before_ellipsis = ignore +sp_after_class_colon = ignore +sp_before_class_colon = ignore +sp_before_case_colon = remove +sp_after_operator = ignore +sp_after_operator_sym = ignore +sp_after_cast = ignore +sp_inside_paren_cast = ignore +sp_cpp_cast_paren = ignore +sp_sizeof_paren = ignore +sp_after_tag = ignore +sp_inside_braces_enum = add +sp_inside_braces_struct = add +sp_inside_braces = add +sp_inside_braces_empty = ignore +sp_type_func = ignore +sp_func_proto_paren = remove +sp_func_def_paren = remove +sp_inside_fparens = ignore +sp_inside_fparen = ignore +sp_square_fparen = ignore +sp_fparen_brace = add +sp_func_call_paren = remove +sp_func_call_paren_empty = remove +sp_func_call_user_paren = ignore +sp_func_class_paren = ignore +sp_return_paren = ignore +sp_attribute_paren = ignore +sp_defined_paren = ignore +sp_throw_paren = ignore +sp_catch_paren = ignore +sp_version_paren = ignore +sp_scope_paren = ignore +sp_macro = ignore +sp_macro_func = ignore +sp_else_brace = add +sp_brace_else = add +sp_brace_typedef = ignore +sp_catch_brace = ignore +sp_brace_catch = ignore +sp_finally_brace = ignore +sp_brace_finally = ignore +sp_try_brace = ignore +sp_getset_brace = ignore +sp_before_dc = ignore +sp_after_dc = ignore +sp_d_array_colon = ignore +sp_not = remove +sp_inv = remove +sp_addr = remove +sp_member = remove +sp_deref = remove +sp_sign = remove +sp_incdec = remove +sp_before_nl_cont = add +sp_after_oc_scope = ignore +sp_after_oc_colon = ignore +sp_before_oc_colon = ignore +sp_after_send_oc_colon = ignore +sp_before_send_oc_colon = ignore +sp_after_oc_type = ignore +sp_after_oc_return_type = ignore +sp_after_oc_at_sel = ignore +sp_after_oc_at_sel_parens = ignore +sp_inside_oc_at_sel_parens = ignore +sp_before_oc_block_caret = ignore +sp_after_oc_block_caret = ignore +sp_cond_colon = ignore +sp_cond_question = ignore +sp_case_label = ignore +sp_range = ignore +sp_cmt_cpp_start = ignore +sp_endif_cmt = ignore +sp_after_new = ignore +sp_before_tr_emb_cmt = ignore +sp_num_before_tr_emb_cmt = 0 +align_keep_tabs = false +align_with_tabs = false +align_on_tabstop = false +align_number_left = false +align_func_params = false +align_same_func_call_params = false +align_var_def_span = 0 +align_var_def_star_style = 0 +align_var_def_amp_style = 0 +align_var_def_thresh = 0 +align_var_def_gap = 0 +align_var_def_colon = false +align_var_def_attribute = false +align_var_def_inline = false +align_assign_span = 0 +align_assign_thresh = 0 +align_enum_equ_span = 0 +align_enum_equ_thresh = 0 +align_var_struct_span = 0 +align_var_struct_thresh = 0 +align_var_struct_gap = 0 +align_struct_init_span = 0 +align_typedef_gap = 0 +align_typedef_span = 0 +align_typedef_func = 0 +align_typedef_star_style = 0 +align_typedef_amp_style = 0 +align_right_cmt_span = 0 +align_right_cmt_mix = false +align_right_cmt_gap = 0 +align_right_cmt_at_col = 0 +align_func_proto_span = 0 +align_func_proto_gap = 0 +align_on_operator = false +align_mix_var_proto = false +align_single_line_func = false +align_single_line_brace = false +align_single_line_brace_gap = 0 +align_oc_msg_spec_span = 0 +align_nl_cont = false +align_pp_define_gap = 0 +align_pp_define_span = 0 +align_left_shift = true +align_oc_msg_colon_span = 0 +align_oc_decl_colon = false +nl_collapse_empty_body = false +nl_assign_leave_one_liners = false +nl_class_leave_one_liners = false +nl_enum_leave_one_liners = false +nl_getset_leave_one_liners = false +nl_func_leave_one_liners = false +nl_if_leave_one_liners = false +nl_start_of_file = ignore +nl_start_of_file_min = 0 +nl_end_of_file = ignore +nl_end_of_file_min = 0 +nl_assign_brace = ignore +nl_assign_square = ignore +nl_after_square_assign = ignore +nl_func_var_def_blk = 0 +nl_fcall_brace = ignore +nl_enum_brace = ignore +nl_struct_brace = ignore +nl_union_brace = ignore +nl_if_brace = add +nl_brace_else = add +nl_elseif_brace = add +nl_else_brace = add +nl_else_if = add +nl_brace_finally = add +nl_finally_brace = add +nl_try_brace = add +nl_getset_brace = ignore +nl_for_brace = add +nl_catch_brace = add +nl_brace_catch = ignore +nl_while_brace = add +nl_using_brace = ignore +nl_brace_brace = ignore +nl_do_brace = add +nl_brace_while = ignore +nl_switch_brace = add +nl_multi_line_cond = false +nl_multi_line_define = false +nl_before_case = false +nl_before_throw = ignore +nl_after_case = false +nl_case_colon_brace = ignore +nl_namespace_brace = ignore +nl_template_class = ignore +nl_class_brace = ignore +nl_class_init_args = ignore +nl_func_type_name = ignore +nl_func_type_name_class = ignore +nl_func_scope_name = ignore +nl_func_proto_type_name = ignore +nl_func_paren = ignore +nl_func_def_paren = ignore +nl_func_decl_start = ignore +nl_func_def_start = ignore +nl_func_decl_start_single = ignore +nl_func_def_start_single = ignore +nl_func_decl_args = ignore +nl_func_def_args = ignore +nl_func_decl_end = ignore +nl_func_def_end = ignore +nl_func_decl_end_single = ignore +nl_func_def_end_single = ignore +nl_func_decl_empty = ignore +nl_func_def_empty = ignore +nl_fdef_brace = ignore +nl_after_return = false +nl_return_expr = ignore +nl_after_semicolon = false +nl_after_brace_open = false +nl_after_brace_open_cmt = false +nl_after_vbrace_open = false +nl_after_vbrace_open_empty = false +nl_after_brace_close = false +nl_after_vbrace_close = false +nl_define_macro = false +nl_squeeze_ifdef = false +nl_before_if = ignore +nl_after_if = ignore +nl_before_for = ignore +nl_after_for = ignore +nl_before_while = ignore +nl_after_while = ignore +nl_before_switch = ignore +nl_after_switch = ignore +nl_before_do = ignore +nl_after_do = ignore +nl_ds_struct_enum_cmt = false +nl_ds_struct_enum_close_brace = false +nl_class_colon = ignore +nl_create_if_one_liner = false +nl_create_for_one_liner = false +nl_create_while_one_liner = false +pos_arith = ignore +pos_assign = ignore +pos_bool = ignore +pos_compare = ignore +pos_conditional = ignore +pos_comma = ignore +pos_class_comma = ignore +pos_class_colon = ignore +code_width = 0 +ls_for_split_full = false +ls_func_split_full = false +nl_max = 0 +nl_after_func_proto = 0 +nl_after_func_proto_group = 0 +nl_after_func_body = 0 +nl_after_func_body_class = 0 +nl_after_func_body_one_liner = 0 +nl_before_block_comment = 0 +nl_before_c_comment = 0 +nl_before_cpp_comment = 0 +nl_after_multiline_comment = false +nl_after_struct = 0 +nl_after_class = 0 +nl_before_access_spec = 0 +nl_after_access_spec = 0 +nl_comment_func_def = 0 +nl_after_try_catch_finally = 0 +nl_around_cs_property = 0 +nl_between_get_set = 0 +nl_property_brace = ignore +eat_blanks_after_open_brace = false +eat_blanks_before_close_brace = false +mod_full_brace_do = add +mod_full_brace_for = add +mod_full_brace_function = add +mod_full_brace_if = add +mod_full_brace_if_chain = add +mod_full_brace_nl = 0 +mod_full_brace_while = add +mod_full_brace_using = add +mod_paren_on_return = ignore +mod_pawn_semicolon = false +mod_full_paren_if_bool = false +mod_remove_extra_semicolon = true +mod_add_long_function_closebrace_comment = 0 +mod_add_long_switch_closebrace_comment = 0 +mod_add_long_ifdef_endif_comment = true +mod_add_long_ifdef_else_comment = true +mod_sort_import = false +mod_sort_using = false +mod_sort_include = false +mod_move_case_break = false +mod_case_brace = ignore +mod_remove_empty_return = false +cmt_width = 0 +cmt_reflow_mode = 0 +cmt_indent_multi = true +cmt_c_group = false +cmt_c_nl_start = false +cmt_c_nl_end = false +cmt_cpp_group = false +cmt_cpp_nl_start = false +cmt_cpp_nl_end = false +cmt_cpp_to_c = false +cmt_star_cont = false +cmt_sp_before_star_cont = 0 +cmt_sp_after_star_cont = 0 +cmt_multi_check_last = true +cmt_insert_file_header = "" +cmt_insert_file_footer = "" +cmt_insert_func_header = "" +cmt_insert_class_header = "" +cmt_insert_oc_msg_header = "" +cmt_insert_before_preproc = false +pp_indent = ignore +pp_indent_at_level = false +pp_indent_count = 1 +pp_space = ignore +pp_space_count = 0 +pp_indent_region = 0 +pp_region_indent_code = false +pp_indent_if = 0 +pp_if_indent_code = false +pp_define_at_level = false diff --git a/src/debug.h b/src/debug.h index 882496fe..fa6eb1d6 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,5 +1,5 @@ -/* - * Apple // emulator for Linux: Definitions for debugger +/* + * Apple // emulator for Linux: Definitions for debugger * * Copyright 1994 Alexander Jean-Claude Bottema * Copyright 1995 Stephen Lee @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -21,21 +21,21 @@ #include /* debugger defines */ -#define BUF_X 39 -#define BUF_Y 22 -#define MAX_BRKPTS 16 -#define SCREEN_X 41 -#define SCREEN_Y 24 -#define PROMPT_X 2 -#define PROMPT_Y BUF_Y - 1 -#define PROMPT_END_X BUF_X - 2 -#define command_line command_buf[PROMPT_Y] -#define uchar unsigned char +#define BUF_X 39 +#define BUF_Y 22 +#define MAX_BRKPTS 16 +#define SCREEN_X 41 +#define SCREEN_Y 24 +#define PROMPT_X 2 +#define PROMPT_Y BUF_Y - 1 +#define PROMPT_END_X BUF_X - 2 +#define command_line command_buf[PROMPT_Y] +#define uchar unsigned char /* debugger commands */ enum token_type { MEM, DIS, REGS, SETMEM, STEP, FINISH, UNTIL, GO, VM, - BREAK, WATCH, CLEAR, IGNORE, STATUS, OPCODES, LC, DRIVE, - SEARCH, HELP, LOG, BSAVE, BLOAD, SAVE, UNKNOWN }; + BREAK, WATCH, CLEAR, IGNORE, STATUS, OPCODES, LC, DRIVE, + SEARCH, HELP, LOG, BSAVE, BLOAD, SAVE, UNKNOWN }; enum addressing_mode { @@ -51,7 +51,7 @@ enum addressing_mode addr_indirect, addr_indirect_x, addr_indirect_y, - addr_j_indirect, /* non-zeropage indirects, used in JMP only */ + addr_j_indirect, /* non-zeropage indirects, used in JMP only */ addr_j_indirect_x, addr_relative }; @@ -64,12 +64,12 @@ struct opcode_struct extern const struct opcode_struct *opcodes; -extern int step_next; /* stepping over instructions */ -extern char second_buf[BUF_Y][BUF_X]; /* scratch buffer for output */ -extern int num_buffer_lines; /* num lines of output */ -extern int arg1, arg2, arg3; /* command arguments */ -extern int breakpoints[MAX_BRKPTS]; /* memory breakpoints */ -extern int watchpoints[MAX_BRKPTS]; /* memory watchpoints */ +extern int step_next; /* stepping over instructions */ +extern char second_buf[BUF_Y][BUF_X]; /* scratch buffer for output */ +extern int num_buffer_lines; /* num lines of output */ +extern int arg1, arg2, arg3; /* command arguments */ +extern int breakpoints[MAX_BRKPTS]; /* memory breakpoints */ +extern int watchpoints[MAX_BRKPTS]; /* memory watchpoints */ void clear_debugger_screen(); void bload(FILE*, char*, int); diff --git a/src/debugger.c b/src/debugger.c index 03cb44c7..7259b908 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -1,16 +1,16 @@ -/* +/* * Apple // emulator for Linux: Main debugger routines * - * Copyright 1994 Alexander Jean-Claude Bottema - * Copyright 1995 Stephen Lee - * Copyright 1997, 1998 Aaron Culliney + * Copyright 1997, 1998, 2013 Aaron Culliney * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. + * + * Originally added to emulator project in 1997 by Aaron Culliney * */ @@ -30,97 +30,105 @@ const struct opcode_struct *opcodes; -int step_next; /* stepping over instructions */ -char second_buf[BUF_Y][BUF_X]; /* scratch buffer for output */ -int num_buffer_lines; /* num lines of output */ -int arg1, arg2, arg3; /* command arguments */ -int breakpoints[MAX_BRKPTS]; /* memory breakpoints */ -int watchpoints[MAX_BRKPTS]; /* memory watchpoints */ +int step_next; /* stepping over instructions */ +char second_buf[BUF_Y][BUF_X]; /* scratch buffer for output */ +int num_buffer_lines; /* num lines of output */ +int arg1, arg2, arg3; /* command arguments */ +int breakpoints[MAX_BRKPTS]; /* memory breakpoints */ +int watchpoints[MAX_BRKPTS]; /* memory watchpoints */ /* debugger globals */ static char screen[SCREEN_Y][SCREEN_X] = - { "||||||||||||||||||||||||||||||||||||||||", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "||||||||||||||||||||||||||||||||||||||||" }; +{ "||||||||||||||||||||||||||||||||||||||||", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "||||||||||||||||||||||||||||||||||||||||" }; -static char command_buf[BUF_Y][BUF_X]; /* command line prompt */ -char lexbuf[BUF_X+2]; /* comman line to be flex'ed */ +static char command_buf[BUF_Y][BUF_X]; /* command line prompt */ +char lexbuf[BUF_X+2]; /* comman line to be flex'ed */ unsigned char current_opcode; -int op_breakpoints[256]; /* opcode breakpoints */ +int op_breakpoints[256]; /* opcode breakpoints */ /* in debug.l */ -extern int debuglex(); /* yylex() */ +extern int debuglex(); /* yylex() */ extern void init_lex(char *buf, int size); /* ------------------------------------------------------------------------- c_get_current_rambank (addrs) - return the current ram bank for addrs. - returns 0 = bank 0 - 1 = bank 1 + returns 0 = bank 0 + 1 = bank 1 ------------------------------------------------------------------------- */ int c_get_current_rambank(int addrs) { #ifdef APPLE_IIE - if ((addrs >= 0x200) && (addrs < 0xD000)) { + if ((addrs >= 0x200) && (addrs < 0xD000)) + { - /* SLOTROM */ - if ((addrs >= 0xC100) && (addrs < 0xD000)) { - /* expansion rom */ - if ((addrs >= 0xC800) && (addrs < 0xD000)) - return 1; /* always internal + /* SLOTROM */ + if ((addrs >= 0xC100) && (addrs < 0xD000)) + { + /* expansion rom */ + if ((addrs >= 0xC800) && (addrs < 0xD000)) + { + return 1; /* always internal * (the real rules are more complex, but * this'll suffice since the slot 3 pseudo-card * is the only one with c8 space) */ - /* if SLOTCXROM, then internal rom (regardless of + } + + /* if SLOTCXROM, then internal rom (regardless of SLOTC3ROM setting). */ - if (softswitches & SS_CXROM) - return 1; + if (softswitches & SS_CXROM) + { + return 1; + } - /* slot 3 rom */ - if ((addrs >= 0xC300) && (addrs < 0xC400)) { - return !!(softswitches & SS_C3ROM); - } + /* slot 3 rom */ + if ((addrs >= 0xC300) && (addrs < 0xC400)) + { + return !!(softswitches & SS_C3ROM); + } - return 0; /* peripheral rom */ - } + return 0; /* peripheral rom */ + } - /* text page 1 */ - if ((addrs >= 0x400) && (addrs < 0x800)) - { - return !!(softswitches & SS_TEXTRD); - } + /* text page 1 */ + if ((addrs >= 0x400) && (addrs < 0x800)) + { + return !!(softswitches & SS_TEXTRD); + } - /* hires page 1 with 80STORE and HIRES on */ - if ((addrs >= 0x2000) && (addrs < 0x4000)) - { - return !!(softswitches & SS_HGRRD); - } + /* hires page 1 with 80STORE and HIRES on */ + if ((addrs >= 0x2000) && (addrs < 0x4000)) + { + return !!(softswitches & SS_HGRRD); + } - /* otherwise return RAMRD flag */ - return !!(softswitches & SS_RAMRD); + /* otherwise return RAMRD flag */ + return !!(softswitches & SS_RAMRD); } /* executing in ALTZP space. */ @@ -134,100 +142,159 @@ int c_get_current_rambank(int addrs) { /* ------------------------------------------------------------------------- get_current_opcode () - returns the opcode from the address that the PC is currently reading from. - returns 0 = bank 0 - 1 = bank 1 + returns 0 = bank 0 + 1 = bank 1 ------------------------------------------------------------------------- */ unsigned char get_current_opcode() { int bank = c_get_current_rambank(cpu65_current.pc); int lcbank = 0; /* main RAM */ - if (cpu65_current.pc < 0xD000) { - return apple_ii_64k[bank][cpu65_current.pc]; + if (cpu65_current.pc < 0xD000) + { + return apple_ii_64k[bank][cpu65_current.pc]; } /* LC RAM */ - if (cpu65_current.pc >= 0xE000) { - if (softswitches & SS_LCRAM) - return language_card[bank][cpu65_current.pc-0xE000]; - else - return apple_ii_64k[bank][cpu65_current.pc]; + if (cpu65_current.pc >= 0xE000) + { + if (softswitches & SS_LCRAM) + { + return language_card[bank][cpu65_current.pc-0xE000]; + } + else + { + return apple_ii_64k[bank][cpu65_current.pc]; + } } /* LC BANK RAM */ if (softswitches & SS_BANK2) - lcbank = 0x1000; + { + lcbank = 0x1000; + } if (softswitches & SS_LCRAM) - return language_banks[bank][cpu65_current.pc-0xD000+lcbank]; + { + return language_banks[bank][cpu65_current.pc-0xD000+lcbank]; + } else - return apple_ii_64k[bank][cpu65_current.pc]; + { + return apple_ii_64k[bank][cpu65_current.pc]; + } } /* ------------------------------------------------------------------------- dump_mem () - hexdump of memory to debug console - we DO NOT wrap the display : 0xffff -> 0x0 (programs can't wrap) + we DO NOT wrap the display : 0xffff -> 0x0 (programs can't wrap) ------------------------------------------------------------------------- */ void dump_mem(int addrs, int len, int lc, int do_ascii, int rambank) { int i, j, mod, end; unsigned char op; - int orig_addrs = addrs; /* address for display */ + int orig_addrs = addrs; /* address for display */ /* check which rambank */ - if (rambank == -1) { - rambank = c_get_current_rambank(addrs); + if (rambank == -1) + { + rambank = c_get_current_rambank(addrs); } if (!lc && (softswitches & SS_LCRAM) && (addrs >= 0xd000)) + { /* read lc anyway */ - lc = 1 + !!(softswitches & SS_BANK2); - - if ((addrs < 0) || (addrs > 0xffff)) { - addrs = cpu65_current.pc; - orig_addrs = addrs; - } - if (lc) { - orig_addrs = addrs; - if ((addrs >= 0xd000) && (addrs <= 0xffff)) addrs -= 0xd000; - if ((addrs < 0) || (addrs > 0x2fff)) addrs = 0; + lc = 1 + !!(softswitches & SS_BANK2); } - if ((len < 1) || (len > 256)) len = 256; - if (do_ascii && (len > 128)) len = 128; + if ((addrs < 0) || (addrs > 0xffff)) + { + addrs = cpu65_current.pc; + orig_addrs = addrs; + } + + if (lc) + { + orig_addrs = addrs; + if ((addrs >= 0xd000) && (addrs <= 0xffff)) + { + addrs -= 0xd000; + } + + if ((addrs < 0) || (addrs > 0x2fff)) + { + addrs = 0; + } + } + + if ((len < 1) || (len > 256)) + { + len = 256; + } + + if (do_ascii && (len > 128)) + { + len = 128; + } /* save hexdump in second_buf */ end = (lc) ? 0x3000 : 0x10000; - for (i = num_buffer_lines-1, j = 0; ((j < len) && (addrs+j < end)); j++) { + for (i = num_buffer_lines-1, j = 0; ((j < len) && (addrs+j < end)); j++) + { - mod = j % (16 >> do_ascii); + mod = j % (16 >> do_ascii); - 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] ; - } - else op = apple_ii_64k[rambank][addrs+j]; + 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]; + } + else + { + op = apple_ii_64k[rambank][addrs+j]; + } - if (!mod) { - if (++i) { - for (mod=0; mod 31) ? (op&0x7f) : '.'); - continue; - } - sprintf(second_buf[i]+5+mod*2, "%02X", op); - if (do_ascii) sprintf(second_buf[i]+23+mod, "%c", - ((op&0x7f) > 31) ? (op&0x7f) : '.'); + if (!mod) + { + if (++i) + { + for (mod=0; mod 31) ? (op&0x7f) : '.'); + } + + continue; + } + + sprintf(second_buf[i]+5+mod*2, "%02X", op); + if (do_ascii) + { + sprintf(second_buf[i]+23+mod, "%c", + ((op&0x7f) > 31) ? (op&0x7f) : '.'); + } } + for (mod=0; mod= 0x1000) ? language_card[rambank][i-0x1000] - : (lc == 1) ? language_banks[rambank][i] - : language_banks[rambank][0x1000+i] ; - } - else op = apple_ii_64k[rambank][i]; + if (lc) + { + op = (i >= 0x1000) ? language_card[rambank][i-0x1000] + : (lc == 1) ? language_banks[rambank][i] + : language_banks[rambank][0x1000+i]; + } + else + { + op = apple_ii_64k[rambank][i]; + } - if (byte == op) { /* matched byte? */ - ++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); - num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2); - j = 0; continue; - } - ++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); - num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2); - j = 0; continue; - } - continue; - } - j = 0; + if (byte == op) /* matched byte? */ + { + ++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); + num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2); + j = 0; continue; + } + + ++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); + num_buffer_lines = (num_buffer_lines + 1) % (BUF_Y-2); + j = 0; continue; + } + + continue; + } + + j = 0; } } @@ -291,23 +368,32 @@ void set_mem(int addrs, char *hexstr) { static char scratch[3]; unsigned char data; - if ((addrs < 0) || (addrs > 0xffff)) { - sprintf(second_buf[num_buffer_lines++], "invalid address"); - return; + if ((addrs < 0) || (addrs > 0xffff)) + { + sprintf(second_buf[num_buffer_lines++], "invalid address"); + return; } - while (*hexstr) { - strncpy(scratch, hexstr, 2); - data = (unsigned char) strtol(scratch, (char**)NULL, 16); + while (*hexstr) + { + strncpy(scratch, hexstr, 2); + data = (unsigned char) strtol(scratch, (char**)NULL, 16); - /* call the set_memory routine, which knows how to route the + /* call the set_memory routine, which knows how to route the request */ - cpu65_direct_write(addrs,data); + cpu65_direct_write(addrs,data); - ++hexstr; - if (!*hexstr) break; - ++hexstr; - if (++addrs > 0xffff) return; /* don't overwrite memory */ + ++hexstr; + if (!*hexstr) + { + break; + } + + ++hexstr; + if (++addrs > 0xffff) + { + return; /* don't overwrite memory */ + } } } @@ -319,29 +405,49 @@ void set_lc_mem(int addrs, int lcbank, char *hexstr) { static char scratch[3]; unsigned char data; - if ((addrs >= 0xd000) && (addrs <= 0xffff)) addrs -= 0xd000; - if ((addrs < 0) || (addrs > 0x2fff)) { - sprintf(second_buf[num_buffer_lines++], "invalid LC address"); - return; + if ((addrs >= 0xd000) && (addrs <= 0xffff)) + { + addrs -= 0xd000; } - while (*hexstr) { - strncpy(scratch, hexstr, 2); - data = (unsigned char) strtol(scratch, (char**)NULL, 16); + if ((addrs < 0) || (addrs > 0x2fff)) + { + sprintf(second_buf[num_buffer_lines++], "invalid LC address"); + return; + } - /* ??? no way to write to aux LC banks */ + while (*hexstr) + { + strncpy(scratch, hexstr, 2); + data = (unsigned char) strtol(scratch, (char**)NULL, 16); - if (addrs >= 0x1000) + /* ??? no way to write to aux LC banks */ + + if (addrs >= 0x1000) + { language_card[0][addrs - 0x1000] = data; - else if (lcbank) - language_banks[0][addrs] = data; - else - language_banks[0][addrs + 0x1000] = data; + } + else + if (lcbank) + { + language_banks[0][addrs] = data; + } + else + { + language_banks[0][addrs + 0x1000] = data; + } - ++hexstr; - if (!*hexstr) break; - ++hexstr; - if (++addrs > 0x2fff) return; + ++hexstr; + if (!*hexstr) + { + break; + } + + ++hexstr; + if (++addrs > 0x2fff) + { + return; + } } } @@ -354,32 +460,39 @@ void bload(FILE *f, char *name, int addrs) { unsigned char *hexstr = NULL; int len = -1; unsigned char data; - - if ((addrs < 0) || (addrs > 0xffff)) { - sprintf(second_buf[num_buffer_lines++], "invalid address"); - return; + + if ((addrs < 0) || (addrs > 0xffff)) + { + sprintf(second_buf[num_buffer_lines++], "invalid address"); + return; } - while ((len = fread(temp, 1, TEMPSIZE, f))) { - hexstr = (unsigned char*)temp; - for (; len > 0; len--) { - data = *hexstr; - - /* call the set_memory routine, which knows how to route - the request */ - cpu65_direct_write(addrs,data); + while ((len = fread(temp, 1, TEMPSIZE, f))) + { + hexstr = (unsigned char*)temp; + for (; len > 0; len--) + { + data = *hexstr; - ++hexstr; - if (++addrs > 0xffff) return; /* don't overwrite memory */ - } + /* call the set_memory routine, which knows how to route + the request */ + cpu65_direct_write(addrs,data); + + ++hexstr; + if (++addrs > 0xffff) + { + return; /* don't overwrite memory */ + } + } } + sprintf(second_buf[num_buffer_lines++], "bloaded: %s", name); } /* ------------------------------------------------------------------------- disasm () - disassemble instructions - we DO NOT wrap the display : 0xffff -> 0x0 + we DO NOT wrap the display : 0xffff -> 0x0 ------------------------------------------------------------------------- */ void disasm(int addrs, int len, int lc, int rambank) { @@ -389,142 +502,179 @@ void disasm(int addrs, int len, int lc, int rambank) { int i, j, k, end, orig_addrs = addrs; /* check which rambank for cpu65_current.pc */ - if (rambank == -1) { - rambank = c_get_current_rambank(addrs); + if (rambank == -1) + { + rambank = c_get_current_rambank(addrs); } if (!lc && (softswitches & SS_LCRAM) && (addrs >= 0xd000)) + { /* read lc anyway */ - lc = 1 + !!(softswitches & SS_BANK2); + lc = 1 + !!(softswitches & SS_BANK2); + } /* handle invalid address request */ - if ((addrs < 0) || (addrs > 0xffff)) { - addrs = cpu65_current.pc; - orig_addrs = addrs; + if ((addrs < 0) || (addrs > 0xffff)) + { + addrs = cpu65_current.pc; + orig_addrs = addrs; } /* disassembling from language card */ - if (lc) { - if ((addrs >= 0xd000) && (addrs <= 0xffff)) addrs -= 0xd000; - if ((addrs < 0) || (addrs > 0x2fff)) addrs = 0; + if (lc) + { + if ((addrs >= 0xd000) && (addrs <= 0xffff)) + { + addrs -= 0xd000; + } + + if ((addrs < 0) || (addrs > 0x2fff)) + { + addrs = 0; + } } - if (len > BUF_Y - 2) len = BUF_Y - 2 - num_buffer_lines; + if (len > BUF_Y - 2) + { + len = BUF_Y - 2 - num_buffer_lines; + } /* save hexdump in second_buf */ end = (lc) ? 0x3000 : 0x10000; for (i = num_buffer_lines, j = addrs, k=orig_addrs; - ((i= 0x1000) ? language_card[rambank][j-0x1000] - : (lc == 1) ? language_banks[rambank][j] - : language_banks[rambank][0x1000+j]; - else - op = apple_ii_64k[rambank][j]; + if (lc) + { + op = (j >= 0x1000) ? language_card[rambank][j-0x1000] + : (lc == 1) ? language_banks[rambank][j] + : language_banks[rambank][0x1000+j]; + } + else + { + op = apple_ii_64k[rambank][j]; + } - switch (opcodes[op].mode) { - case addr_implied: - case addr_accumulator: /* no arg */ - sprintf(second_buf[i], "/%02X/%04X: %02X %s %s", - rambank, k++, op, opcodes[op].mnemonic, + switch (opcodes[op].mode) + { + 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]); - break; + break; - case addr_immediate: - case addr_zeropage: - case addr_zeropage_x: - case addr_zeropage_y: - case addr_indirect: - case addr_indirect_x: - case addr_indirect_y: /* byte arg */ - if (k == 0xffff) { - num_buffer_lines = i; - return; - } + case addr_immediate: + case addr_zeropage: + case addr_zeropage_x: + case addr_zeropage_y: + case addr_indirect: + case addr_indirect_x: + case addr_indirect_y: /* byte arg */ + if (k == 0xffff) + { + num_buffer_lines = i; + return; + } - if (lc) - 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]; + if (lc) + { + 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, + 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; - break; + sprintf(second_buf[i], fmt, (unsigned char)arg1); + k+=2; + break; - case addr_absolute: - case addr_absolute_x: - case addr_absolute_y: - case addr_j_indirect: - case addr_j_indirect_x: /* word arg */ - if (k >= 0xfffe) { - num_buffer_lines = i; - return; - } + case addr_absolute: + case addr_absolute_x: + case addr_absolute_y: + case addr_j_indirect: + case addr_j_indirect_x: /* word arg */ + if (k >= 0xfffe) + { + num_buffer_lines = i; + return; + } - 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]; - } - else { - arg1 = apple_ii_64k[rambank][++j]; - arg2 = apple_ii_64k[rambank][++j]; - } + 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]; + } + else + { + arg1 = apple_ii_64k[rambank][++j]; + 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, + 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; + sprintf(second_buf[i], fmt, (unsigned char)arg2, + (unsigned char)arg1); + k+=3; + break; - case addr_relative: /* offset */ - if (k == 0xffff) { - num_buffer_lines = i; - return; - } + case addr_relative: /* offset */ + if (k == 0xffff) + { + num_buffer_lines = i; + return; + } - if (lc) - 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]; + if (lc) + { + 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, + 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)); - } - else { - sprintf(second_buf[i], fmt, - k + arg1 + 2, '+', (unsigned char)arg1); - } - k+=2; - break; + if (arg1 < 0) + { + sprintf(second_buf[i], fmt, + k + arg1 + 2, '-', (unsigned char)(-arg1)); + } + else + { + sprintf(second_buf[i], fmt, + k + arg1 + 2, '+', (unsigned char)arg1); + } - default: /* shouldn't happen */ - sprintf(second_buf[i], "args to opcode incorrect!"); - break; - } + k+=2; + break; + + default: /* shouldn't happen */ + sprintf(second_buf[i], "args to opcode incorrect!"); + break; + } } + num_buffer_lines = i; } @@ -534,60 +684,92 @@ 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); + 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); + "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) second_buf[num_buffer_lines][0]='C'; - if (cpu65_current.f & X_Flag) second_buf[num_buffer_lines][1]='X'; - if (cpu65_current.f & I_Flag) second_buf[num_buffer_lines][2]='I'; - if (cpu65_current.f & V_Flag) second_buf[num_buffer_lines][3]='V'; - if (cpu65_current.f & B_Flag) second_buf[num_buffer_lines][4]='B'; - if (cpu65_current.f & D_Flag) second_buf[num_buffer_lines][5]='D'; - if (cpu65_current.f & Z_Flag) second_buf[num_buffer_lines][6]='Z'; - if (cpu65_current.f & N_Flag) second_buf[num_buffer_lines][7]='N'; - + if (cpu65_current.f & C_Flag) + { + second_buf[num_buffer_lines][0]='C'; + } + + if (cpu65_current.f & X_Flag) + { + second_buf[num_buffer_lines][1]='X'; + } + + if (cpu65_current.f & I_Flag) + { + second_buf[num_buffer_lines][2]='I'; + } + + if (cpu65_current.f & V_Flag) + { + second_buf[num_buffer_lines][3]='V'; + } + + if (cpu65_current.f & B_Flag) + { + second_buf[num_buffer_lines][4]='B'; + } + + if (cpu65_current.f & D_Flag) + { + second_buf[num_buffer_lines][5]='D'; + } + + if (cpu65_current.f & Z_Flag) + { + second_buf[num_buffer_lines][6]='Z'; + } + + if (cpu65_current.f & N_Flag) + { + second_buf[num_buffer_lines][7]='N'; + } + ++num_buffer_lines; } /* ------------------------------------------------------------------------- will_branch () = will instruction branch? - -1 - n/a - 0 - no it won't - >0 - yes it will + -1 - n/a + 0 - no it won't + >0 - yes it will ------------------------------------------------------------------------- */ static int will_branch() { unsigned char op = get_current_opcode(); - - switch (op) { - case 0x10: /* BPL */ - return (int) !(cpu65_current.f & N_Flag); - case 0x30: /* BMI */ - return (int) (cpu65_current.f & N_Flag); - case 0x50: /* BVC */ - return (int) !(cpu65_current.f & V_Flag); - case 0x70: /* BVS */ - return (int) (cpu65_current.f & V_Flag); + + switch (op) + { + case 0x10: /* BPL */ + return (int) !(cpu65_current.f & N_Flag); + case 0x30: /* BMI */ + return (int) (cpu65_current.f & N_Flag); + case 0x50: /* BVC */ + return (int) !(cpu65_current.f & V_Flag); + case 0x70: /* BVS */ + return (int) (cpu65_current.f & V_Flag); #ifdef APPLE_IIE - case 0x80: /* BRA */ - return 1; + case 0x80: /* BRA */ + return 1; #endif - case 0x90: /* BCC */ - return (int) !(cpu65_current.f & C_Flag); - case 0xb0: /* BCS */ - return (int) (cpu65_current.f & C_Flag); - case 0xd0: /* BNE */ - return (int) !(cpu65_current.f & Z_Flag); - case 0xf0: /* BEQ */ - return (int) (cpu65_current.f & Z_Flag); + case 0x90: /* BCC */ + return (int) !(cpu65_current.f & C_Flag); + case 0xb0: /* BCS */ + return (int) (cpu65_current.f & C_Flag); + case 0xd0: /* BNE */ + return (int) !(cpu65_current.f & Z_Flag); + case 0xf0: /* BEQ */ + return (int) (cpu65_current.f & Z_Flag); } return -1; @@ -596,35 +778,43 @@ static int will_branch() { /* ------------------------------------------------------------------------- set_halt () = set a breakpoint or watchpoint in memory - type = points to "watchpoints" or "breakpoints" array + type = points to "watchpoints" or "breakpoints" array ------------------------------------------------------------------------- */ void set_halt(int *type, int addrs) { int i; - for (i = 0; i < MAX_BRKPTS; i++) { - if (type[i] == -1) { - type[i] = addrs; - sprintf(second_buf[num_buffer_lines++], "set at %04X", addrs); - return; - } + for (i = 0; i < MAX_BRKPTS; i++) + { + if (type[i] == -1) + { + type[i] = addrs; + sprintf(second_buf[num_buffer_lines++], "set at %04X", addrs); + return; + } } + sprintf(second_buf[num_buffer_lines++], "too many!"); } /* ------------------------------------------------------------------------- clear_halt () = unset a critical breakpoint or watchpoint in memory - type = points to "watchpoints" or "breakpoints" array - pt = (pt - 1) into type. 0 indicates clear all. + type = points to "watchpoints" or "breakpoints" array + pt = (pt - 1) into type. 0 indicates clear all. ------------------------------------------------------------------------- */ void clear_halt(int *type, int pt) { int i; - if (!pt) { /* unset all */ - for (i = 0; i < MAX_BRKPTS; i++) - type[i] = -1; - return; + if (!pt) /* unset all */ + { + for (i = 0; i < MAX_BRKPTS; i++) + { + type[i] = -1; + } + + return; } - type[pt-1] = -1; /* unset single */ + + type[pt-1] = -1; /* unset single */ } /* ------------------------------------------------------------------------- @@ -686,9 +876,9 @@ void clear_halt_65c02() { /* ------------------------------------------------------------------------- at_haltpt () - tests if at haltpt - returns 0 = no breaks or watches - 1 = one break or watchpoint fired - n = two or more breaks and/or watches fired + returns 0 = no breaks or watches + 1 = one break or watchpoint fired + n = two or more breaks and/or watches fired ------------------------------------------------------------------------- */ int at_haltpt() { int i; @@ -696,36 +886,46 @@ int at_haltpt() { /* check op_breakpoints */ 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); - - for (i = 0; i < MAX_BRKPTS; i++) { - - 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)); - } - } - - if (cpu65_debug.op) /* only check watchpoints if read/write occured */ { - for (i = 0; i < MAX_BRKPTS; i++) { - if (cpu65_debug.ea == watchpoints[i]) { - if (cpu65_debug.op & 2) { - 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]); - } - cpu65_debug.op = 0; /* only allow WP to trip once */ - } - } + sprintf(second_buf[num_buffer_lines++], + "stopped at %04X bank %d instruction %02X", + cpu65_current.pc, c_get_current_rambank(cpu65_current.pc), op); } - return num_buffer_lines; /* 0 indicates nothing happened */ + + for (i = 0; i < MAX_BRKPTS; i++) + { + + 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)); + } + } + + if (cpu65_debug.op) /* only check watchpoints if read/write occured */ + { + for (i = 0; i < MAX_BRKPTS; i++) + { + if (cpu65_debug.ea == watchpoints[i]) + { + if (cpu65_debug.op & 2) + { + 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]); + } + + cpu65_debug.op = 0; /* only allow WP to trip once */ + } + } + } + + return num_buffer_lines; /* 0 indicates nothing happened */ } /* ------------------------------------------------------------------------- @@ -734,21 +934,28 @@ int at_haltpt() { void show_breakpts() { int i=num_buffer_lines, k; - for (k = 0; k < MAX_BRKPTS; k++) { - 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]); - } - else if (breakpoints[k] >= 0) { - sprintf(second_buf[i++], "break %02d at %04X", - k+1, breakpoints[k]); - } - else if (watchpoints[k] >= 0) { - memset(second_buf[i], ' ', BUF_X); - sprintf(second_buf[i++]+16, " watch %02d at %04X", - k+1, watchpoints[k]); - } + for (k = 0; k < MAX_BRKPTS; k++) + { + 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]); + } + else + if (breakpoints[k] >= 0) + { + sprintf(second_buf[i++], "break %02d at %04X", + k+1, breakpoints[k]); + } + else + if (watchpoints[k] >= 0) + { + memset(second_buf[i], ' ', BUF_X); + sprintf(second_buf[i++]+16, " watch %02d at %04X", + k+1, watchpoints[k]); + } } + num_buffer_lines = i; } @@ -760,26 +967,28 @@ void show_opcode_breakpts() { sprintf(second_buf[i++], " 0 1 2 3 4 5 6 7 8 9 A B C D E F"); sprintf(second_buf[i++], " |-------------------------------|"); - for (k = 0; k < 0x10; k++) { - sprintf(second_buf[i++], - " %X|%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s|", k, - op_breakpoints[k ] ? "x" : " ", - op_breakpoints[k+0x10] ? "x" : " ", - op_breakpoints[k+0x20] ? "x" : " ", - op_breakpoints[k+0x30] ? "x" : " ", - op_breakpoints[k+0x40] ? "x" : " ", - op_breakpoints[k+0x50] ? "x" : " ", - op_breakpoints[k+0x60] ? "x" : " ", - op_breakpoints[k+0x70] ? "x" : " ", - op_breakpoints[k+0x80] ? "x" : " ", - op_breakpoints[k+0x90] ? "x" : " ", - op_breakpoints[k+0xA0] ? "x" : " ", - op_breakpoints[k+0xB0] ? "x" : " ", - op_breakpoints[k+0xC0] ? "x" : " ", - op_breakpoints[k+0xD0] ? "x" : " ", - op_breakpoints[k+0xE0] ? "x" : " ", - op_breakpoints[k+0xF0] ? "x" : " "); + for (k = 0; k < 0x10; k++) + { + sprintf(second_buf[i++], + " %X|%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s|", k, + op_breakpoints[k ] ? "x" : " ", + op_breakpoints[k+0x10] ? "x" : " ", + op_breakpoints[k+0x20] ? "x" : " ", + op_breakpoints[k+0x30] ? "x" : " ", + op_breakpoints[k+0x40] ? "x" : " ", + op_breakpoints[k+0x50] ? "x" : " ", + op_breakpoints[k+0x60] ? "x" : " ", + op_breakpoints[k+0x70] ? "x" : " ", + op_breakpoints[k+0x80] ? "x" : " ", + op_breakpoints[k+0x90] ? "x" : " ", + op_breakpoints[k+0xA0] ? "x" : " ", + op_breakpoints[k+0xB0] ? "x" : " ", + op_breakpoints[k+0xC0] ? "x" : " ", + op_breakpoints[k+0xD0] ? "x" : " ", + op_breakpoints[k+0xE0] ? "x" : " ", + op_breakpoints[k+0xF0] ? "x" : " "); } + sprintf(second_buf[i++], " |-------------------------------|"); num_buffer_lines = i; @@ -792,60 +1001,60 @@ 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"); + : 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)); + : 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", + sprintf(second_buf[i++], "TEXT (%04X): %s", SW_TEXT + !!(softswitches & SS_TEXT), - (softswitches & SS_TEXT) ? "on" : "off"); - sprintf(second_buf[i++], "MIXED (%04X): %s", + (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", + (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", + (softswitches & SS_PAGE2) ? "on" : "off"); + sprintf(second_buf[i++], "HIRES (%04X): %s", SW_HIRES + !!(softswitches & SS_HIRES), - (softswitches & SS_HIRES) ? "on" : "off"); + (softswitches & SS_HIRES) ? "on" : "off"); #ifdef APPLE_IIE - sprintf(second_buf[i++], "80STORE (%04X): %s", + sprintf(second_buf[i++], "80STORE (%04X): %s", SW_80STORE + !!(softswitches & SS_80STORE), - (softswitches & SS_80STORE) ? "on" : "off"); - sprintf(second_buf[i++], "RAMRD (%04X): %s", + (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", + (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", + sprintf(second_buf[i++], "ALTZP (%04X): %s", SW_ALTZP + !!(softswitches & SS_ALTZP), - (softswitches & SS_ALTZP) ? "on" : "off"); - sprintf(second_buf[i++], "80COL (%04X): %s", + (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", + (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", + (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", + sprintf(second_buf[i++], "SLOTCXROM (%04X): %s", SW_SLOTCXROM + !!(softswitches & SS_CXROM), (softswitches & SS_CXROM) ? "on" : "off"); - sprintf(second_buf[i++], "DHIRES (%04X): %s", + sprintf(second_buf[i++], "DHIRES (%04X): %s", SW_DHIRES + !!(softswitches && SS_DHIRES), - (softswitches & SS_DHIRES) ? "on" : "off"); - sprintf(second_buf[i++], "IOUDIS (%04X): %s", + (softswitches & SS_DHIRES) ? "on" : "off"); + sprintf(second_buf[i++], "IOUDIS (%04X): %s", SW_IOUDIS + !!(softswitches && SS_IOUDIS), - (softswitches && SS_IOUDIS) ? "on" : "off"); + (softswitches && SS_IOUDIS) ? "on" : "off"); /* sprintf(second_buf[i++], "RDVBLBAR: %s", (SLOTCXROM & 0x80) */ -/* ? "on" : "off"); */ +/* ? "on" : "off"); */ #endif num_buffer_lines = i; @@ -863,61 +1072,77 @@ void show_disk_info() { sprintf(second_buf[i++], "motor %s", (disk6.motor) ? "off" : "on"); sprintf(second_buf[i++], "%s", (disk6.ddrw) ? "write" : "read"); sprintf(second_buf[i++], "byte = %02X", disk6.disk_byte); - if (!disk6.disk[disk6.drive].nibblized) { - sprintf(second_buf[i++], "volume = %d", disk6.volume); - sprintf(second_buf[i++], "checksum = %d", disk6.checksum); + if (!disk6.disk[disk6.drive].nibblized) + { + sprintf(second_buf[i++], "volume = %d", disk6.volume); + sprintf(second_buf[i++], "checksum = %d", disk6.checksum); } sprintf(second_buf[i++], "-------------------------------------"); /* drive / image specific information */ memset(second_buf[i], ' ', BUF_X); - if ((len = strlen(disk6.disk[0].file_name))) { - while ((--len) && (disk6.disk[0].file_name[len] != '/')); - strncpy(tmp, disk6.disk[0].file_name + len + 1, 31); - *(second_buf[i] + sprintf(second_buf[i], "%s", tmp)) = ' '; + if ((len = strlen(disk6.disk[0].file_name))) + { + while ((--len) && (disk6.disk[0].file_name[len] != '/')) + { + } + + strncpy(tmp, disk6.disk[0].file_name + len + 1, 31); + *(second_buf[i] + sprintf(second_buf[i], "%s", tmp)) = ' '; } - if ((len = strlen(disk6.disk[1].file_name))) { - while ((--len) && (disk6.disk[1].file_name[len] != '/')); - strncpy(tmp, disk6.disk[1].file_name + len + 1, 31); - sprintf(second_buf[i]+off, "%s", tmp); + if ((len = strlen(disk6.disk[1].file_name))) + { + while ((--len) && (disk6.disk[1].file_name[len] != '/')) + { + } + + strncpy(tmp, disk6.disk[1].file_name + len + 1, 31); + sprintf(second_buf[i]+off, "%s", tmp); } 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)) = ' '; + *(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", + (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")) = ' '; + (disk6.disk[0].protected) ? "protected" : "enabled")) = ' '; sprintf(second_buf[i++]+off, "write %s", - (disk6.disk[1].protected) ? "protected" : "enabled"); + (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", + *(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)" : ""); + (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)) = ' '; - if (disk6.disk[1].nibblized) ++i; + if (!disk6.disk[0].nibblized) + { + *(second_buf[i] + sprintf(second_buf[i], "sector %d", + disk6.disk[0].sector)) = ' '; + if (disk6.disk[1].nibblized) + { + ++i; + } } + if (!disk6.disk[1].nibblized) - sprintf(second_buf[i++]+off, "sector %d", + { + sprintf(second_buf[i++]+off, "sector %d", disk6.disk[1].sector); + } num_buffer_lines = i; } @@ -929,22 +1154,28 @@ void clear_debugger_screen() { int i; video_setpage( 0 ); for (i = 0; i < 24; i++) - c_interface_print(0, i, 2, screen[ i ] ); + { + c_interface_print(0, i, 2, screen[ i ] ); + } } /* ------------------------------------------------------------------------- end_step () - finish a stepping command - display the next instruction, and tell whether it will branch + display the next instruction, and tell whether it will branch ------------------------------------------------------------------------- */ void end_step() { int branch; clear_debugger_screen(); - disasm(cpu65_current.pc, 1, 0, -1); /* show next instruction */ - branch = will_branch(); /* test if it will branch */ - if (branch == -1) return; /* n/a */ + disasm(cpu65_current.pc, 1, 0, -1); /* show next instruction */ + branch = will_branch(); /* test if it will branch */ + if (branch == -1) + { + return; /* n/a */ + } + sprintf(second_buf[num_buffer_lines++], "%s", - (branch) ? "will branch" : "will not branch"); + (branch) ? "will branch" : "will not branch"); } /* ------------------------------------------------------------------------- @@ -956,26 +1187,40 @@ void c_do_step(int step_count) { int step_frame = 0; /* do step while step_count AND no breaks AND no keypress */ - do { - op = get_current_opcode(); + do + { + op = get_current_opcode(); - if (step_next && (op == 0x20)) { - do { - op = get_current_opcode(); - if (op == 0x20) ++step_frame;/* JSR */ - if (op == 0x60) --step_frame;/* RTS */ - cpu65_step(); - } while (((ch = c_mygetch(0)) == -1) && !at_haltpt() && step_frame); - } - else cpu65_step(); /* step one instruction */ + if (step_next && (op == 0x20)) + { + do + { + op = get_current_opcode(); + if (op == 0x20) + { + ++step_frame; /* JSR */ + } + + if (op == 0x60) + { + --step_frame; /* RTS */ + } + + cpu65_step(); + } while (((ch = c_mygetch(0)) == -1) && !at_haltpt() && step_frame); + } + else + { + cpu65_step(); /* step one instruction */ + } } while (--step_count && !at_haltpt() && (c_mygetch(0) == -1)); - end_step(); /* print location */ + end_step(); /* print location */ } /* ------------------------------------------------------------------------- display_help () - show quick reference command usage + show quick reference command usage ------------------------------------------------------------------------- */ void display_help() { /* "|||||||||||||||||||||||||||||||||||||" */ @@ -1006,12 +1251,12 @@ void display_help() { /* ------------------------------------------------------------------------- do_debug_command () - perform a debugger command + perform a debugger command ------------------------------------------------------------------------- */ void do_debug_command() { int i = 0, j = 0, k = 0; - + /* reset key local vars */ step_next = 0; num_buffer_lines = 0; @@ -1022,26 +1267,39 @@ void do_debug_command() { debuglex(); /* set up to copy results into main buffer */ - if (num_buffer_lines >= PROMPT_Y) { - k = BUF_Y - PROMPT_Y; - } else { - /* scroll buffer */ - for (i = 0, j = 0; i < PROMPT_Y - num_buffer_lines; i++, j = 0) { - memcpy(command_buf[i], command_buf[num_buffer_lines+1+i], BUF_X); - while ((j < BUF_X) && (command_buf[i][j] != '\0')) j++; - memset (command_buf[i] + j, ' ', BUF_X - j - 1); - command_buf[i][BUF_X - 1] = '\0'; - } + if (num_buffer_lines >= PROMPT_Y) + { + k = BUF_Y - PROMPT_Y; } - + else + { + /* scroll buffer */ + for (i = 0, j = 0; i < PROMPT_Y - num_buffer_lines; i++, j = 0) + { + memcpy(command_buf[i], command_buf[num_buffer_lines+1+i], BUF_X); + while ((j < BUF_X) && (command_buf[i][j] != '\0')) + { + j++; + } + + memset(command_buf[i] + j, ' ', BUF_X - j - 1); + command_buf[i][BUF_X - 1] = '\0'; + } + } + /* copy the debug results into debug console window. change '\0's to ' 's and cap with a single '\0' */ - while (i < PROMPT_Y) { - j = 0; - memcpy(command_buf[i], second_buf[k++], BUF_X); - while ((j < BUF_X) && (command_buf[i][j] != '\0')) ++j; - memset(command_buf[i] + j, ' ', BUF_X - j - 1); - command_buf[i++][BUF_X - 1] = '\0'; + while (i < PROMPT_Y) + { + j = 0; + memcpy(command_buf[i], second_buf[k++], BUF_X); + while ((j < BUF_X) && (command_buf[i][j] != '\0')) + { + ++j; + } + + memset(command_buf[i] + j, ' ', BUF_X - j - 1); + command_buf[i++][BUF_X - 1] = '\0'; } /* new prompt */ @@ -1050,8 +1308,9 @@ void do_debug_command() { command_line[BUF_X - 1] = '\0'; /* display the new information */ - for (i=0; i PROMPT_X)) { - command_line[--command_pos] = ' '; - } - /* return */ - 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)) { - command_line[command_pos++] = ch; - } - } + if (ch == kESC) + { + c_interface_exit(); + return; + } + else + { + /* backspace */ + if ((ch == 127 || ch == 8) && + (command_pos > PROMPT_X)) + { + command_line[--command_pos] = ' '; + } + /* return */ + 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)) + { + command_line[command_pos++] = ch; + } + } } } diff --git a/src/disk.c b/src/disk.c index a654a496..4bcf07e0 100644 --- a/src/disk.c +++ b/src/disk.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: C portion of Disk ][ emulation * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -36,44 +36,44 @@ static int slot6_rom_loaded = 0; struct drive disk6; -static int skew_table_6[16] = /* Sector skew table */ - { 0,7,14,6,13,5,12,4,11,3,10,2,9,1,8,15 }; +static int skew_table_6[16] = /* Sector skew table */ +{ 0,7,14,6,13,5,12,4,11,3,10,2,9,1,8,15 }; -static int translate_table_6[256] =/* Translation table */ - { - 0x96, 0x97, 0x9a, 0x9b, 0x9d, 0x9e, 0x9f, 0xa6, - 0xa7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb2, 0xb3, - 0xb4, 0xb5, 0xb6, 0xb7, 0xb9, 0xba, 0xbb, 0xbc, - 0xbd, 0xbe, 0xbf, 0xcb, 0xcd, 0xce, 0xcf, 0xd3, - 0xd6, 0xd7, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, - 0xdf, 0xe5, 0xe6, 0xe7, 0xe9, 0xea, 0xeb, 0xec, - 0xed, 0xee, 0xef, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, - 0xf7, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, - 0x80, 0x80, 0x02, 0x03, 0x80, 0x04, 0x05, 0x06, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x07, 0x08, - 0x80, 0x80, 0x80, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, - 0x80, 0x80, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, - 0x80, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x1b, 0x80, 0x1c, 0x1d, 0x1e, - 0x80, 0x80, 0x80, 0x1f, 0x80, 0x80, 0x20, 0x21, - 0x80, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x29, 0x2a, 0x2b, - 0x80, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, - 0x80, 0x80, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x80, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f - }; +static int translate_table_6[256] = /* Translation table */ +{ + 0x96, 0x97, 0x9a, 0x9b, 0x9d, 0x9e, 0x9f, 0xa6, + 0xa7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb9, 0xba, 0xbb, 0xbc, + 0xbd, 0xbe, 0xbf, 0xcb, 0xcd, 0xce, 0xcf, 0xd3, + 0xd6, 0xd7, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, + 0xdf, 0xe5, 0xe6, 0xe7, 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, + 0xf7, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x01, + 0x80, 0x80, 0x02, 0x03, 0x80, 0x04, 0x05, 0x06, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x07, 0x08, + 0x80, 0x80, 0x80, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x80, 0x80, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, + 0x80, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x1b, 0x80, 0x1c, 0x1d, 0x1e, + 0x80, 0x80, 0x80, 0x1f, 0x80, 0x80, 0x20, 0x21, + 0x80, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x29, 0x2a, 0x2b, + 0x80, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, + 0x80, 0x80, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x80, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f +}; /* ------------------------------------------------------------------------- c_init_6() @@ -84,8 +84,8 @@ void c_init_6() disk6.disk[0].phase = disk6.disk[1].phase = 42; disk6.disk[0].phase_change = disk6.disk[1].phase_change = 0; - disk6.motor = 1; /* motor on */ - disk6.drive = 0; /* first drive active */ + disk6.motor = 1; /* motor on */ + disk6.drive = 0; /* first drive active */ disk6.ddrw = 0; disk6.volume = 254; #if 0 /* BUGS!: */ @@ -101,29 +101,36 @@ void c_init_6() void c_eject_6(int drive) { pid_t pid; - if (disk6.disk[drive].compressed) { - /* gzip the last disk if it was compressed_6 */ - if ((pid = fork())) { /* parent process */ - /* privileged mode - gzip in place */ - waitpid(pid, NULL, 0); - } else if (!pid) { /* child process */ - /* privileged mode - gzip in place */ - if (execl("/bin/gzip", "/bin/gzip", - disk6.disk[drive].file_name, NULL) == -1) - { - perror("Problem exec'ing /bin/gzip"); - exit(-1); - } - } else { - perror("Problem calling fork" ); - } + if (disk6.disk[drive].compressed) + { + /* gzip the last disk if it was compressed_6 */ + if ((pid = fork())) /* parent process */ + { /* privileged mode - gzip in place */ + waitpid(pid, NULL, 0); + } + else + if (!pid) /* child process */ + { /* privileged mode - gzip in place */ + if (execl("/bin/gzip", "/bin/gzip", + disk6.disk[drive].file_name, NULL) == -1) + { + perror("Problem exec'ing /bin/gzip"); + exit(-1); + } + } + else + { + perror("Problem calling fork" ); + } } + disk6.disk[drive].compressed = 0; disk6.disk[drive].nibblized = 0; sprintf(disk6.disk[drive].file_name, "%s", ""); - if (disk6.disk[drive].fp) { - fclose(disk6.disk[drive].fp); - disk6.disk[drive].fp = NULL; + if (disk6.disk[drive].fp) + { + fclose(disk6.disk[drive].fp); + disk6.disk[drive].fp = NULL; } } @@ -135,71 +142,85 @@ void c_eject_6(int drive) { ------------------------------------------------------------------------- */ int c_new_diskette_6(int drive, char *file_name, int cmpr, int nib, int force) { - struct stat buf; + struct stat buf; strcpy(disk6.disk[drive].file_name, file_name); disk6.disk[drive].file_name[1023]='\0'; disk6.disk[drive].compressed = cmpr; disk6.disk[drive].nibblized = nib; - if (disk6.disk[drive].fp) { - fclose(disk6.disk[drive].fp); - disk6.disk[drive].fp = NULL; + if (disk6.disk[drive].fp) + { + fclose(disk6.disk[drive].fp); + disk6.disk[drive].fp = NULL; } + /* set to users privilege level for disk access */ - if (stat(disk6.disk[drive].file_name, &buf) < 0) { - disk6.disk[drive].fp = NULL; - c_eject_6(drive); - return 1; /* problem: disk unreadable */ + if (stat(disk6.disk[drive].file_name, &buf) < 0) + { + disk6.disk[drive].fp = NULL; + c_eject_6(drive); + return 1; /* problem: disk unreadable */ } - else { - disk6.disk[drive].file_size = buf.st_size; + else + { + disk6.disk[drive].file_size = buf.st_size; - if (!force) { - /* Open read only */ - disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r+"); - disk6.disk[drive].protected = 0; - } - if ((disk6.disk[drive].fp == NULL) || (force)) { - /* Open for read AND write */ - disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r"); - disk6.disk[drive].protected = 1; /* disk is write protected! */ - } - if (disk6.disk[drive].fp == NULL) { - /* Failed to open file. */ - c_eject_6(drive); - return 1; /* problem: disk unreadable */ - } - /* seek to current head position. */ - fseek(disk6.disk[drive].fp, PHASE_BYTES * disk6.disk[drive].phase, SEEK_SET); + if (!force) + { + /* Open read only */ + disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r+"); + disk6.disk[drive].protected = 0; + } + + if ((disk6.disk[drive].fp == NULL) || (force)) + { + /* Open for read AND write */ + disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r"); + disk6.disk[drive].protected = 1; /* disk is write protected! */ + } + + if (disk6.disk[drive].fp == NULL) + { + /* Failed to open file. */ + c_eject_6(drive); + return 1; /* problem: disk unreadable */ + } + + /* seek to current head position. */ + fseek(disk6.disk[drive].fp, PHASE_BYTES * disk6.disk[drive].phase, SEEK_SET); } disk6.disk[drive].sector = 0; disk6.disk[drive].run_byte = 0; - return 0; /* no problem */ + return 0; /* no problem */ } /* ------------------------------------------------------------------------- c_read_nibblized_6_6() - reads a standard .nib file of length 232960 bytes. - there are 70 phases positioned every 3328 bytes. + there are 70 phases positioned every 3328 bytes. ------------------------------------------------------------------------- */ unsigned char c_read_nibblized_6_6() { static unsigned char ch; - if (disk6.disk[disk6.drive].phase_change) { - fseek(disk6.disk[disk6.drive].fp, PHASE_BYTES * disk6.disk[disk6.drive].phase, SEEK_SET); - disk6.disk[disk6.drive].phase_change = 0; + if (disk6.disk[disk6.drive].phase_change) + { + fseek(disk6.disk[disk6.drive].fp, PHASE_BYTES * disk6.disk[disk6.drive].phase, SEEK_SET); + disk6.disk[disk6.drive].phase_change = 0; } + disk6.disk_byte = fgetc(disk6.disk[disk6.drive].fp); ch = disk6.disk_byte; /* track revolves... */ if (ftell(disk6.disk[disk6.drive].fp) == (PHASE_BYTES * (disk6.disk[disk6.drive].phase + 2))) - fseek(disk6.disk[disk6.drive].fp, -2 * PHASE_BYTES, SEEK_CUR); + { + fseek(disk6.disk[disk6.drive].fp, -2 * PHASE_BYTES, SEEK_CUR); + } return ch; } @@ -209,158 +230,167 @@ unsigned char c_read_nibblized_6_6() ------------------------------------------------------------------------- */ unsigned char c_read_normal_6() { - int position; - int old_value; + int position; + int old_value; - unsigned char value = 0; + unsigned char value = 0; /* The run byte tells what's to do */ switch (disk6.disk[disk6.drive].run_byte) { - case 0: case 1: case 2: case 3: case 4: case 5: - case 20: case 21: case 22: case 23: case 24: - /* Sync */ - value = 0xFF; - break; + case 0: case 1: case 2: case 3: case 4: case 5: + case 20: case 21: case 22: case 23: case 24: + /* Sync */ + value = 0xFF; + break; - case 6: case 25: - /* Prologue (first byte) */ - value = 0xD5; - break; + case 6: case 25: + /* Prologue (first byte) */ + value = 0xD5; + break; - case 7: case 26: - /* Prologue (second byte) */ - value = 0xAA; - break; + case 7: case 26: + /* Prologue (second byte) */ + value = 0xAA; + break; - case 8: - /* Prologue (third byte) */ - value = 0x96; - break; + case 8: + /* Prologue (third byte) */ + value = 0x96; + break; - case 9: - /* Volume (encoded) */ - value = (disk6.volume >> 1) | 0xAA; - disk6.checksum = disk6.volume; - break; + case 9: + /* Volume (encoded) */ + value = (disk6.volume >> 1) | 0xAA; + disk6.checksum = disk6.volume; + break; - case 10: - /* Volume (encoded) */ - value = disk6.volume | 0xAA; - break; + case 10: + /* Volume (encoded) */ + value = disk6.volume | 0xAA; + break; - case 11: - /* Track number (encoded) */ - disk6.checksum ^= (disk6.disk[disk6.drive].phase >> 1); - value = (disk6.disk[disk6.drive].phase >> 2) | 0xAA; - break; + case 11: + /* Track number (encoded) */ + disk6.checksum ^= (disk6.disk[disk6.drive].phase >> 1); + value = (disk6.disk[disk6.drive].phase >> 2) | 0xAA; + break; - case 12: - /* Track number (encoded) */ - value = (disk6.disk[disk6.drive].phase >> 1) | 0xAA; - break; + case 12: + /* Track number (encoded) */ + value = (disk6.disk[disk6.drive].phase >> 1) | 0xAA; + break; - case 13: - /* Sector number (encoded) */ - disk6.checksum ^= disk6.disk[disk6.drive].sector; - value = (disk6.disk[disk6.drive].sector >> 1) | 0xAA; - break; + case 13: + /* Sector number (encoded) */ + disk6.checksum ^= disk6.disk[disk6.drive].sector; + value = (disk6.disk[disk6.drive].sector >> 1) | 0xAA; + break; - case 14: - /* Sector number (encoded) */ - value = disk6.disk[disk6.drive].sector | 0xAA; - break; + case 14: + /* Sector number (encoded) */ + value = disk6.disk[disk6.drive].sector | 0xAA; + break; - case 15: - /* Checksum */ - value = (disk6.checksum >> 1) | 0xAA; - break; + case 15: + /* Checksum */ + value = (disk6.checksum >> 1) | 0xAA; + break; - case 16: - /* Checksum */ - value = disk6.checksum | 0xAA; - break; + case 16: + /* Checksum */ + value = disk6.checksum | 0xAA; + break; - case 17: case 371: - /* Epilogue (first byte) */ - value = 0xDE; - break; + case 17: case 371: + /* Epilogue (first byte) */ + value = 0xDE; + break; - case 18: case 372: - /* Epilogue (second byte) */ - value = 0xAA; - break; + case 18: case 372: + /* Epilogue (second byte) */ + value = 0xAA; + break; - case 19: case 373: - /* Epilogue (third byte) */ - value = 0xEB; - break; + case 19: case 373: + /* Epilogue (third byte) */ + value = 0xEB; + break; - case 27: - /* Data header */ - disk6.exor_value = 0; + case 27: + /* Data header */ + disk6.exor_value = 0; - /* Set file position variable */ - disk6.disk[disk6.drive].file_pos = 256 * 16 * (disk6.disk[disk6.drive].phase >> 1) + - 256 * skew_table_6[ disk6.disk[disk6.drive].sector ]; + /* Set file position variable */ + disk6.disk[disk6.drive].file_pos = 256 * 16 * (disk6.disk[disk6.drive].phase >> 1) + + 256 * skew_table_6[ disk6.disk[disk6.drive].sector ]; - /* File large enough? */ - if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size) - return 0xFF; + /* File large enough? */ + if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size) + { + return 0xFF; + } - /* Set position */ - fseek( disk6.disk[disk6.drive].fp, disk6.disk[disk6.drive].file_pos, SEEK_SET ); - - /* Read sector */ - if (fread( disk6.disk_data, 1, 256, disk6.disk[disk6.drive].fp ) != 256) { - // error - } - disk6.disk_data[ 256 ] = disk6.disk_data[ 257 ] = 0; - value = 0xAD; - break; + /* Set position */ + fseek( disk6.disk[disk6.drive].fp, disk6.disk[disk6.drive].file_pos, SEEK_SET ); - case 370: - /* Checksum */ - value = translate_table_6[disk6.exor_value & 0x3F]; + /* Read sector */ + if (fread( disk6.disk_data, 1, 256, disk6.disk[disk6.drive].fp ) != 256) + { + // error + } - /* Increment sector number (and wrap if necessary) */ - disk6.disk[disk6.drive].sector++; - if (disk6.disk[disk6.drive].sector == 16) - disk6.disk[disk6.drive].sector = 0; + disk6.disk_data[ 256 ] = disk6.disk_data[ 257 ] = 0; + value = 0xAD; + break; - break; + case 370: + /* Checksum */ + value = translate_table_6[disk6.exor_value & 0x3F]; - default: - position = disk6.disk[disk6.drive].run_byte - 28; - if (position >= 0x56) - { - position -= 0x56; - old_value = disk6.disk_data[ position ]; - old_value = old_value >> 2; - disk6.exor_value ^= old_value; - value = translate_table_6[disk6.exor_value & 0x3F]; - disk6.exor_value = old_value; - } - else - { - old_value = 0; - old_value |= (disk6.disk_data[position] & 0x1) << 1; - old_value |= (disk6.disk_data[position] & 0x2) >> 1; - old_value |= (disk6.disk_data[position+0x56] & 0x1) << 3; - old_value |= (disk6.disk_data[position+0x56] & 0x2) << 1; - old_value |= (disk6.disk_data[position+0xAC] & 0x1) << 5; - old_value |= (disk6.disk_data[position+0xAC] & 0x2) << 3; - disk6.exor_value ^= old_value; - value = translate_table_6[disk6.exor_value & 0x3F]; - disk6.exor_value = old_value; - } - break; + /* Increment sector number (and wrap if necessary) */ + disk6.disk[disk6.drive].sector++; + if (disk6.disk[disk6.drive].sector == 16) + { + disk6.disk[disk6.drive].sector = 0; + } + + break; + + default: + position = disk6.disk[disk6.drive].run_byte - 28; + if (position >= 0x56) + { + position -= 0x56; + old_value = disk6.disk_data[ position ]; + old_value = old_value >> 2; + disk6.exor_value ^= old_value; + value = translate_table_6[disk6.exor_value & 0x3F]; + disk6.exor_value = old_value; + } + else + { + old_value = 0; + old_value |= (disk6.disk_data[position] & 0x1) << 1; + old_value |= (disk6.disk_data[position] & 0x2) >> 1; + old_value |= (disk6.disk_data[position+0x56] & 0x1) << 3; + old_value |= (disk6.disk_data[position+0x56] & 0x2) << 1; + old_value |= (disk6.disk_data[position+0xAC] & 0x1) << 5; + old_value |= (disk6.disk_data[position+0xAC] & 0x2) << 3; + disk6.exor_value ^= old_value; + value = translate_table_6[disk6.exor_value & 0x3F]; + disk6.exor_value = old_value; + } + + break; } /* End switch */ /* Continue by increasing run byte value */ disk6.disk[disk6.drive].run_byte++; if (disk6.disk[disk6.drive].run_byte > 373) - disk6.disk[disk6.drive].run_byte = 0; + { + disk6.disk[disk6.drive].run_byte = 0; + } disk6.disk_byte = value; return value; @@ -371,19 +401,23 @@ unsigned char c_read_normal_6() /* ------------------------------------------------------------------------- c_write_nibblized_6_6() - writes a standard .nib file of length 232960 bytes. - there are 70 phases positioned every 3328 bytes. + there are 70 phases positioned every 3328 bytes. ------------------------------------------------------------------------- */ void c_write_nibblized_6_6() { - if (disk6.disk[disk6.drive].phase_change) { - fseek(disk6.disk[disk6.drive].fp, PHASE_BYTES * disk6.disk[disk6.drive].phase, SEEK_SET); - disk6.disk[disk6.drive].phase_change = 0; + if (disk6.disk[disk6.drive].phase_change) + { + fseek(disk6.disk[disk6.drive].fp, PHASE_BYTES * disk6.disk[disk6.drive].phase, SEEK_SET); + disk6.disk[disk6.drive].phase_change = 0; } + fputc(disk6.disk_byte, disk6.disk[disk6.drive].fp); /* track revolves... */ if (ftell(disk6.disk[disk6.drive].fp) == (PHASE_BYTES * (disk6.disk[disk6.drive].phase + 2))) - fseek(disk6.disk[disk6.drive].fp, -2 * PHASE_BYTES, SEEK_CUR); + { + fseek(disk6.disk[disk6.drive].fp, -2 * PHASE_BYTES, SEEK_CUR); + } } /* ------------------------------------------------------------------------- @@ -392,124 +426,141 @@ void c_write_nibblized_6_6() void c_write_normal_6() { - int position; + int position; int old_value; if (disk6.disk_byte == 0xD5) - disk6.disk[disk6.drive].run_byte = 6; /* Initialize run byte value */ + { + disk6.disk[disk6.drive].run_byte = 6; /* Initialize run byte value */ + + } /* The run byte tells what's to do */ switch (disk6.disk[disk6.drive].run_byte) { - case 0: case 1: case 2: case 3: case 4: case 5: - case 20: case 21: case 22: case 23: case 24: - /* Sync */ - break; + case 0: case 1: case 2: case 3: case 4: case 5: + case 20: case 21: case 22: case 23: case 24: + /* Sync */ + break; - case 6: case 25: - /* Prologue (first byte) */ - if (disk6.disk_byte == 0xFF) - disk6.disk[disk6.drive].run_byte--; - break; + case 6: case 25: + /* Prologue (first byte) */ + if (disk6.disk_byte == 0xFF) + { + disk6.disk[disk6.drive].run_byte--; + } - case 7: case 26: - /* Prologue (second byte) */ - break; + break; - case 8: - /* Prologue (third byte) */ - if (disk6.disk_byte == 0xAD) - disk6.exor_value = 0, disk6.disk[disk6.drive].run_byte = 27; - break; + case 7: case 26: + /* Prologue (second byte) */ + break; - case 9: case 10: - /* Volume */ - break; + case 8: + /* Prologue (third byte) */ + if (disk6.disk_byte == 0xAD) + { + disk6.exor_value = 0, disk6.disk[disk6.drive].run_byte = 27; + } - case 11: case 12: - /* Track */ - break; + break; - case 13: case 14: - /* Sector */ - break; + case 9: case 10: + /* Volume */ + break; - case 15: - /* Checksum */ - break; + case 11: case 12: + /* Track */ + break; - case 16: - /* Checksum */ - break; + case 13: case 14: + /* Sector */ + break; - case 17: case 371: - /* Epilogue (first byte) */ - break; + case 15: + /* Checksum */ + break; - case 18: case 372: - /* Epilogue (second byte) */ - break; + case 16: + /* Checksum */ + break; - case 19: case 373: - /* Epilogue (third byte) */ - break; + case 17: case 371: + /* Epilogue (first byte) */ + break; - case 27: - disk6.exor_value = 0; - break; + case 18: case 372: + /* Epilogue (second byte) */ + break; - case 370: - /* Set file position variable */ - disk6.disk[disk6.drive].file_pos = 256 * 16 * (disk6.disk[disk6.drive].phase >> 1) + - 256 * skew_table_6[ disk6.disk[disk6.drive].sector ]; + case 19: case 373: + /* Epilogue (third byte) */ + break; - /* Is the file large enough? */ - if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size) - return; + case 27: + disk6.exor_value = 0; + break; + + case 370: + /* Set file position variable */ + disk6.disk[disk6.drive].file_pos = 256 * 16 * (disk6.disk[disk6.drive].phase >> 1) + + 256 * skew_table_6[ disk6.disk[disk6.drive].sector ]; + + /* Is the file large enough? */ + if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size) + { + return; + } - /* Set position */ - fseek( disk6.disk[disk6.drive].fp, disk6.disk[disk6.drive].file_pos, SEEK_SET ); + /* Set position */ + fseek( disk6.disk[disk6.drive].fp, disk6.disk[disk6.drive].file_pos, SEEK_SET ); - /* Write sector */ - fwrite(disk6.disk_data, 1, 256, disk6.disk[disk6.drive].fp); - fflush( disk6.disk[disk6.drive].fp ); - /* Increment sector number (and wrap if necessary) */ - disk6.disk[disk6.drive].sector++; - if (disk6.disk[disk6.drive].sector == 16) - disk6.disk[disk6.drive].sector = 0; - break; + /* Write sector */ + fwrite(disk6.disk_data, 1, 256, disk6.disk[disk6.drive].fp); + fflush( disk6.disk[disk6.drive].fp ); + /* Increment sector number (and wrap if necessary) */ + disk6.disk[disk6.drive].sector++; + if (disk6.disk[disk6.drive].sector == 16) + { + disk6.disk[disk6.drive].sector = 0; + } - default: - position = disk6.disk[disk6.drive].run_byte - 28; - disk6.disk_byte = translate_table_6[ disk6.disk_byte ]; - if (position >= 0x56) - { - position -= 0x56; - disk6.disk_byte ^= disk6.exor_value; - old_value = disk6.disk_byte; - disk6.disk_data[position] |= (disk6.disk_byte << 2) & 0xFC; - disk6.exor_value = old_value; - } - else - { - disk6.disk_byte ^= disk6.exor_value; - old_value = disk6.disk_byte; - disk6.disk_data[position] = (disk6.disk_byte & 0x01) << 1; - disk6.disk_data[position] |= (disk6.disk_byte & 0x02) >> 1; - disk6.disk_data[position + 0x56] = (disk6.disk_byte & 0x04) >> 1; - disk6.disk_data[position + 0x56] |= (disk6.disk_byte & 0x08) >> 3; - disk6.disk_data[position + 0xAC] = (disk6.disk_byte & 0x10) >> 3; - disk6.disk_data[position + 0xAC] |= (disk6.disk_byte & 0x20) >> 5; - disk6.exor_value = old_value; - } - break; + break; + + default: + position = disk6.disk[disk6.drive].run_byte - 28; + disk6.disk_byte = translate_table_6[ disk6.disk_byte ]; + if (position >= 0x56) + { + position -= 0x56; + disk6.disk_byte ^= disk6.exor_value; + old_value = disk6.disk_byte; + disk6.disk_data[position] |= (disk6.disk_byte << 2) & 0xFC; + disk6.exor_value = old_value; + } + else + { + disk6.disk_byte ^= disk6.exor_value; + old_value = disk6.disk_byte; + disk6.disk_data[position] = (disk6.disk_byte & 0x01) << 1; + disk6.disk_data[position] |= (disk6.disk_byte & 0x02) >> 1; + disk6.disk_data[position + 0x56] = (disk6.disk_byte & 0x04) >> 1; + disk6.disk_data[position + 0x56] |= (disk6.disk_byte & 0x08) >> 3; + disk6.disk_data[position + 0xAC] = (disk6.disk_byte & 0x10) >> 3; + disk6.disk_data[position + 0xAC] |= (disk6.disk_byte & 0x20) >> 5; + disk6.exor_value = old_value; + } + + break; } /* End switch */ disk6.disk[disk6.drive].run_byte++; if (disk6.disk[disk6.drive].run_byte > 373) - disk6.disk[disk6.drive].run_byte = 0; + { + disk6.disk[disk6.drive].run_byte = 0; + } } GLUE_C_READ(disk_read_byte) @@ -517,31 +568,47 @@ GLUE_C_READ(disk_read_byte) if (disk6.ddrw) { if (disk6.disk[disk6.drive].fp == NULL) - return 0; /* Return if there is no disk in drive */ + { + return 0; /* Return if there is no disk in drive */ + } + if (disk6.disk[disk6.drive].protected) - return 0; /* Do not write if diskette is write protected */ + { + return 0; /* Do not write if diskette is write protected */ + + } if (disk6.disk_byte < 0x96) - return 0; /* Only byte values at least 0x96 are allowed */ + { + return 0; /* Only byte values at least 0x96 are allowed */ + + } (disk6.disk[disk6.drive].nibblized) ? c_write_nibblized_6_6() : c_write_normal_6(); - return 0; /* ??? */ + return 0; /* ??? */ } else { if (disk6.disk[disk6.drive].fp == NULL) - return 0xFF; /* Return FF if there is no disk in drive */ - - if (disk6.motor) /* Motor turned on? */ { - if (disk6.motor > 99) - return 0; - else - disk6.motor++; + return 0xFF; /* Return FF if there is no disk in drive */ + + } + + if (disk6.motor) /* Motor turned on? */ + { + if (disk6.motor > 99) + { + return 0; + } + else + { + disk6.motor++; + } } /* handle nibblized_6 or regular disks */ - return (disk6.disk[disk6.drive].nibblized) ? c_read_nibblized_6_6() : c_read_normal_6() ; + return (disk6.disk[disk6.drive].nibblized) ? c_read_nibblized_6_6() : c_read_normal_6(); } } @@ -559,15 +626,22 @@ GLUE_C_READ(disk_read_phase) switch (((ea >> 1) - disk6.disk[disk6.drive].phase) & 3) { case 1: - disk6.disk[disk6.drive].phase++; + disk6.disk[disk6.drive].phase++; break; case 3: - disk6.disk[disk6.drive].phase--; - break; + disk6.disk[disk6.drive].phase--; + break; } - if (disk6.disk[disk6.drive].phase<0) disk6.disk[disk6.drive].phase=0; - if (disk6.disk[disk6.drive].phase>69) disk6.disk[disk6.drive].phase=69; + if (disk6.disk[disk6.drive].phase<0) + { + disk6.disk[disk6.drive].phase=0; + } + + if (disk6.disk[disk6.drive].phase>69) + { + disk6.disk[disk6.drive].phase=69; + } disk6.disk[disk6.drive].phase_change = 1; @@ -577,47 +651,47 @@ GLUE_C_READ(disk_read_phase) GLUE_C_READ(disk_read_motor_off) { - disk6.motor = 1; - return disk6.drive; + disk6.motor = 1; + return disk6.drive; } GLUE_C_READ(disk_read_motor_on) { - disk6.motor = 0; - return disk6.drive; + disk6.motor = 0; + return disk6.drive; } GLUE_C_READ(disk_read_select_a) { - return disk6.drive = 0; + return disk6.drive = 0; } GLUE_C_READ(disk_read_select_b) { - return disk6.drive = 1; + return disk6.drive = 1; } GLUE_C_READ(disk_read_latch) { - return disk6.drive; + return disk6.drive; } GLUE_C_READ(disk_read_prepare_in) { - disk6.ddrw = 0; - return disk6.disk[disk6.drive].protected ? 0x80 : 0x00; + disk6.ddrw = 0; + return disk6.disk[disk6.drive].protected ? 0x80 : 0x00; } GLUE_C_READ(disk_read_prepare_out) { - disk6.ddrw = 1; - return disk6.drive; + disk6.ddrw = 1; + return disk6.drive; } GLUE_C_WRITE(disk_write_latch) { - disk6.disk_byte = d; + disk6.disk_byte = d; } void disk_install(int slot) @@ -628,51 +702,58 @@ void disk_install(int slot) assert(slot == 6); /* load Disk II rom */ - if (!slot6_rom_loaded) { - snprintf(temp, TEMPSIZE, "%s/slot6.rom", system_path); - if ((f = fopen( temp, "r" )) == NULL) { - printf("Cannot find file '%s'.\n",temp); - exit( 0 ); - } - if (fread(slot6_rom, 0x100, 1, f) != 0x100) { - // error - } - fclose(f); - slot6_rom_loaded = 1; + if (!slot6_rom_loaded) + { + snprintf(temp, TEMPSIZE, "%s/slot6.rom", system_path); + if ((f = fopen( temp, "r" )) == NULL) + { + printf("Cannot find file '%s'.\n",temp); + exit( 0 ); + } + + if (fread(slot6_rom, 0x100, 1, f) != 0x100) + { + // error + } + + fclose(f); + slot6_rom_loaded = 1; } + memcpy(apple_ii_64k[0] + 0xC600, slot6_rom, 0x100); /* disk softswitches */ cpu65_vmem[0xC0E0].r = cpu65_vmem[0xC0E2].r = - cpu65_vmem[0xC0E4].r = cpu65_vmem[0xC0E6].r = - ram_nop; + cpu65_vmem[0xC0E4].r = cpu65_vmem[0xC0E6].r = + ram_nop; cpu65_vmem[0xC0E1].r = cpu65_vmem[0xC0E3].r = - cpu65_vmem[0xC0E5].r = cpu65_vmem[0xC0E7].r = - disk_read_phase; + cpu65_vmem[0xC0E5].r = cpu65_vmem[0xC0E7].r = + disk_read_phase; cpu65_vmem[0xC0E8].r = - disk_read_motor_off; + disk_read_motor_off; cpu65_vmem[0xC0E9].r = - disk_read_motor_on; + disk_read_motor_on; cpu65_vmem[0xC0EA].r = - disk_read_select_a; + disk_read_select_a; cpu65_vmem[0xC0EB].r = - disk_read_select_b; + disk_read_select_b; cpu65_vmem[0xC0EC].r = - disk_read_byte; + disk_read_byte; cpu65_vmem[0xC0ED].r = - disk_read_latch; /* read latch */ + disk_read_latch; /* read latch */ cpu65_vmem[0xC0EE].r = - disk_read_prepare_in; + disk_read_prepare_in; cpu65_vmem[0xC0EF].r = - disk_read_prepare_out; + disk_read_prepare_out; - for (i = 0xC0E0; i < 0xC0F0; i++) { + for (i = 0xC0E0; i < 0xC0F0; i++) + { cpu65_vmem[i].w = - cpu65_vmem[i].r; + cpu65_vmem[i].r; } cpu65_vmem[0xC0ED].w = - disk_write_latch; /* write latch */ + disk_write_latch; /* write latch */ } diff --git a/src/disk.h b/src/disk.h index 47eadcc9..db4fa4cc 100644 --- a/src/disk.h +++ b/src/disk.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Defines for Disk ][ emulation * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -27,7 +27,7 @@ struct diskette int sector; long file_size; int phase; - int run_byte; + int run_byte; FILE *fp; int file_pos; }; @@ -47,22 +47,22 @@ struct drive extern struct drive disk6; -void c_init_6(); -int c_new_diskette_6(int, char*, int, int, int); -void c_eject_6(int); +void c_init_6(); +int c_new_diskette_6(int, char*, int, int, int); +void c_eject_6(int); void disk_install(int slot); -void disk_read_nop(), - disk_read_phase(), - disk_read_motor_off(), - disk_read_motor_on(), - disk_read_select_a(), - disk_read_select_b(), - disk_read_byte(), - disk_read_latch(), - disk_write_latch(), - disk_read_prepare_in(), - disk_read_prepare_out(); +void disk_read_nop(), +disk_read_phase(), +disk_read_motor_off(), +disk_read_motor_on(), +disk_read_select_a(), +disk_read_select_b(), +disk_read_byte(), +disk_read_latch(), +disk_write_latch(), +disk_read_prepare_in(), +disk_read_prepare_out(); #define A2_DISK_H #endif diff --git a/src/genfont.c b/src/genfont.c index d957017a..4bd0f05f 100644 --- a/src/genfont.c +++ b/src/genfont.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Font compiler * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -20,10 +20,10 @@ /* I'm not sure if this is the correct way to detect libc 5/4. I long * since removed it from my system. */ -#ifdef __GLIBC__ +#ifdef __GLIBC__ #if __GLIBC__ == 1 -/* Older Linux C libraries had getline removed (to humor programs that +/* Older Linux C libraries had getline removed (to humor programs that * used that name for their own functions), but kept getdelim */ #define getline(l,s,f) getdelim(l,s,'\n',f) @@ -39,7 +39,7 @@ int main(void) { unsigned char byte; - char *line = 0; + char *line = 0; size_t line_size = 0; int i,mx=0; @@ -48,28 +48,35 @@ int main(void) " * \n" " * THIS FILE IS AUTOMATICALLY GENERATED --- DO NOT EDIT\n" " */\n"); - + i = 0x100; while (getline(&line,&line_size,stdin) != -1) { - if (line[0] == ';') continue; + if (line[0] == ';') + { + continue; + } - if (line[0] == '=') + if (line[0] == '=') { char *name,*size; - name = line + 1; - while (isspace(*name)) name++; - size = strchr(name,','); + name = line + 1; + while (isspace(*name)) + { + name++; + } + + size = strchr(name,','); *size++ = 0; - mx = i = strtol(size,0,0); + mx = i = strtol(size,0,0); printf("\nconst unsigned char %s[%d] =\n{\n ",name,i*8); - - continue; - } - + + continue; + } + i--; if (line[0] == ':') @@ -80,9 +87,11 @@ int main(void) { int k; - if (getline(&line,&line_size,stdin) == -1) { + if (getline(&line,&line_size,stdin) == -1) + { // ERROR ... } + k = 8; byte = 0; while (k--) @@ -90,21 +99,31 @@ int main(void) byte <<= 1; byte += (line[k] == '#'); } - - if (j) - printf("0x%02x, ",byte); - else if (i) - printf("0x%02x,\n ",byte); /* last byte in glyph */ - else - printf("0x%02x\n};\n",byte); /* last item in array */ + + if (j) + { + printf("0x%02x, ",byte); + } + else + if (i) + { + printf("0x%02x,\n ",byte); /* last byte in glyph */ + } + else + { + printf("0x%02x\n};\n",byte); /* last item in array */ + } } } - else break; + else + { + break; + } } if (i) - { + { fprintf(stderr, "Trouble with font file at character 0x%02x\n", mx-i-1); diff --git a/src/interface.c b/src/interface.c index f880488e..e800d837 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,5 +1,5 @@ -/* - * Apple // emulator for Linux: Configuration Interface +/* + * Apple // emulator for Linux: Configuration Interface * * Copyright 1994 Alexander Jean-Claude Bottema * Copyright 1995 Stephen Lee @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -36,8 +36,8 @@ #include "cpu.h" #include "prefs.h" -static struct stat statbuf; -static int altdrive; +static struct stat statbuf; +static int altdrive; /*#define undoc_supported 1*/ /*#else*/ @@ -52,10 +52,15 @@ static int altdrive; static void pad_string(char *s, char c, int len) { char *p; - for (p = s; ((*p != '\0') && (p-s < len-1)); p++); - while (p-s < len-1) { - *p++ = c; + for (p = s; ((*p != '\0') && (p-s < len-1)); p++) + { } + + while (p-s < len-1) + { + *p++ = c; + } + *p = '\0'; } @@ -78,7 +83,7 @@ extern long js_timelimit; void c_load_interface_font() { - /* Only codes 0x20 -- 0x8A are actually used. But I feel safer + /* Only codes 0x20 -- 0x8A are actually used. But I feel safer * explicitly initializing all of them. */ @@ -97,11 +102,13 @@ void c_load_interface_font() ------------------------------------------------------------------------- */ void c_interface_print( int x, int y, int cs, char *s ) { - int i; + int i; for (i = x; *s; i++, s++) - video_plotchar( i, y, cs, *s ); - + { + video_plotchar( i, y, cs, *s ); + } + } /* ------------------------------------------------------------------------- @@ -109,13 +116,13 @@ void c_interface_print( int x, int y, int cs, char *s ) ------------------------------------------------------------------------- */ void c_interface_redo_bottom() { - + c_interface_print( 1, 21, 2, - " Use arrow keys (or Return) to modify " - ); + " Use arrow keys (or Return) to modify " + ); c_interface_print( 1, 22, 2, - " parameters. (Press ESC to exit menu) " - ); + " parameters. (Press ESC to exit menu) " + ); } /* ------------------------------------------------------------------------- @@ -124,11 +131,11 @@ void c_interface_redo_bottom() { void c_interface_redo_diskette_bottom() { c_interface_print( 1, 21, 2, - " Move: Arrows, PGUP, PGDN, HOME, END. " - ); + " Move: Arrows, PGUP, PGDN, HOME, END. " + ); c_interface_print( 1, 22, 2, - " Return and 'w' select, ESC cancels. " - ); + " Return and 'w' select, ESC cancels. " + ); } /* ------------------------------------------------------------------------- @@ -140,79 +147,95 @@ void c_interface_redo_diskette_bottom() { void c_interface_translate_screen( char screen[24][41] ) { - static char map[11][3][4] ={ { "...", - ".||", - ".|." }, + static char map[11][3][4] ={ { "...", + ".||", + ".|." }, - { "...", - "||.", - ".|." }, + { "...", + "||.", + ".|." }, - { ".|.", - ".||", - "..." }, + { ".|.", + ".||", + "..." }, - { ".|.", - "||.", - "..." }, + { ".|.", + "||.", + "..." }, - { ".|.", - ".|.", - ".|." }, + { ".|.", + ".|.", + ".|." }, - { "...", - "|||", - "..." }, + { "...", + "|||", + "..." }, - { ".|.", - ".||", - ".|." }, + { ".|.", + ".||", + ".|." }, - { ".|.", - "||.", - ".|." }, + { ".|.", + "||.", + ".|." }, - { "...", - "|||", - ".|." }, + { "...", + "|||", + ".|." }, - { ".|.", - "|||", - "..." }, + { ".|.", + "|||", + "..." }, - { ".|.", - "|||", - ".|." } }; + { ".|.", + "|||", + ".|." } }; - int x, y, i, j, k; + int x, y, i, j, k; for (y = 0; y < 24; y++) - for (x = 0; x < 40; x++) + { + for (x = 0; x < 40; x++) { - if (screen[ y ][ x ] == '|') - { - int flag = 0; + if (screen[ y ][ x ] == '|') + { + int flag = 0; - for (k = 10; !flag && k >= 0; flag ? : k--) - { - flag = 1; + for (k = 10; !flag && k >= 0; flag ? : k--) + { + flag = 1; - for (i = y - 1; flag && i <= y + 1; i++) - for (j = x - 1; flag && j <= x + 1; j++) - if (IsInside(j, i)) - if (!(IsGraphic( screen[ i ][ j ])) && - (map[k][ i - y + 1 ][ j - x + 1 ] == '|')) - flag = 0; - else; - else - if (map[k][ i - y + 1 ][ j - x + 1 ] == '|') - flag = 0; - } + for (i = y - 1; flag && i <= y + 1; i++) + { + for (j = x - 1; flag && j <= x + 1; j++) + { + if (IsInside(j, i)) + { + if (!(IsGraphic( screen[ i ][ j ])) && + (map[k][ i - y + 1 ][ j - x + 1 ] == '|')) + { + flag = 0; + } + else + { + } + } + else + if (map[k][ i - y + 1 ][ j - x + 1 ] == '|') + { + flag = 0; + } + } + } + } - if (flag) - screen[ y ][ x ] = 0x80 + k; - } - } + if (flag) + { + screen[ y ][ x ] = 0x80 + k; + } + } + } + } } int c_interface_cut_name(char *name) @@ -222,15 +245,16 @@ int c_interface_cut_name(char *name) if (p >= name && *p == 'z') { - p--; - if (p >= name && *p == 'g') - { - p--; - if (p >= name && *p == '.') { - *p-- = '\0'; - is_gz = 1; - } - } + p--; + if (p >= name && *p == 'g') + { + p--; + if (p >= name && *p == '.') + { + *p-- = '\0'; + is_gz = 1; + } + } } return is_gz; @@ -240,7 +264,7 @@ void c_interface_cut_gz(char *name) { char *p = name + strlen(name) - 1; - p--; + p--; p--; *p = '\0'; } @@ -256,11 +280,11 @@ int c_interface_is_gz(const char *name) { size_t len = strlen( name ); - if (len > GZ_EXT_LEN) { /* shouldn't have a file called ".gz"... */ - /*name += len - GZ_EXT_LEN;*/ - return ((strcmp(name+len-GZ_EXT_LEN, GZ_EXT) == 0) ? 1 : 0); + if (len > GZ_EXT_LEN) /* shouldn't have a file called ".gz"... */ + { /*name += len - GZ_EXT_LEN;*/ + return ((strcmp(name+len-GZ_EXT_LEN, GZ_EXT) == 0) ? 1 : 0); } - + return 0; } @@ -271,47 +295,61 @@ int c_interface_is_nibblized(const char *name) size_t len = strlen( name ); if (c_interface_is_gz(name)) - len -= GZ_EXT_LEN; + { + len -= GZ_EXT_LEN; + } if (!strncmp(name + len - DISK_EXT_LEN, DISK_EXT2, DISK_EXT_LEN)) - return 1; - + { + return 1; + } + return 0; } int c_interface_disk_select(const struct dirent *e) { - static char cmp[ DISKSIZE ]; + static char cmp[ DISKSIZE ]; size_t len; const char *p; strncpy( cmp, disk_path, DISKSIZE ); strncat( cmp, "/", DISKSIZE-1 ); - strncat( cmp, e -> d_name, DISKSIZE-1 ); + strncat( cmp, e->d_name, DISKSIZE-1 ); /* don't show disk in alternate drive */ if (!strcmp(cmp, disk6.disk[altdrive].file_name)) - return 0; + { + return 0; + } /* show directories except '.' and '..' at toplevel. */ stat(cmp, &statbuf); if (S_ISDIR(statbuf.st_mode) && strcmp(".", e->d_name) && - !(!strcmp("..", e->d_name) && !strcmp(disk_path, "/"))) - return 1; + !(!strcmp("..", e->d_name) && !strcmp(disk_path, "/"))) + { + return 1; + } p = e->d_name; len = strlen(p); - - if (len > GZ_EXT_LEN && (!strcmp(p + len - GZ_EXT_LEN, GZ_EXT))) { - len -= GZ_EXT_LEN; + + if (len > GZ_EXT_LEN && (!strcmp(p + len - GZ_EXT_LEN, GZ_EXT))) + { + len -= GZ_EXT_LEN; } /* true if .dsk or .nib extension */ if (!strncmp(p + len - DISK_EXT_LEN, DISK_EXT, DISK_EXT_LEN)) - return 1; + { + return 1; + } + if (!strncmp(p + len - DISK_EXT_LEN, DISK_EXT2, DISK_EXT_LEN)) - return 1; + { + return 1; + } return 0; } @@ -342,36 +380,36 @@ static void c_usleep() { void c_interface_select_diskette( int drive ) { static char screen[24][41] = - { "||||||||||||||||||||||||||||||||||||||||", - "| Insert diskette into Drive _, Slot 6 |", - "||||||||||||||||||||||||||||||||||||||||", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "||||||||||||||||||||||||||||||||||||||||", - "| Move: Arrows, PGUP, PGDN, HOME, END. |", - "| Return and 'w' select, ESC cancels. |", - "||||||||||||||||||||||||||||||||||||||||" }; + { "||||||||||||||||||||||||||||||||||||||||", + "| Insert diskette into Drive _, Slot 6 |", + "||||||||||||||||||||||||||||||||||||||||", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "||||||||||||||||||||||||||||||||||||||||", + "| Move: Arrows, PGUP, PGDN, HOME, END. |", + "| Return and 'w' select, ESC cancels. |", + "||||||||||||||||||||||||||||||||||||||||" }; - struct dirent **namelist; - int i, entries; - pid_t pid; - static int curpos=0; - int ch; + struct dirent **namelist; + int i, entries; + pid_t pid; + static int curpos=0; + int ch; screen[ 1 ][ 29 ] = (drive == 0) ? 'A' : 'B'; @@ -379,280 +417,378 @@ void c_interface_select_diskette( int drive ) c_interface_translate_screen( screen ); - NEXTDIR: +NEXTDIR: for (i = 0; i < 24; i++) - c_interface_print( 0, i, 2, screen[ i ] ); + { + c_interface_print( 0, i, 2, screen[ i ] ); + } altdrive = (drive == 0) ? 1 : 0; if (!strcmp("", disk_path)) - sprintf(disk_path, "/"); + { + sprintf(disk_path, "/"); + } /* set to users privilege level for directory access */ entries = scandir(disk_path, &namelist, - c_interface_disk_select, alphasort); + c_interface_disk_select, alphasort); - if (entries <= 0) { - /* 1/17/97 NOTE: scandir (libc5.3.12) seems to freak on broken + if (entries <= 0) + { + /* 1/17/97 NOTE: scandir (libc5.3.12) seems to freak on broken symlinks. so you won't be able to read from some legitimate directories... */ - c_interface_print( 6, 11, 0, "Problem reading directory!" ); - sprintf(disk_path, "/"); - c_usleep(); - c_interface_exit(); - return; + c_interface_print( 6, 11, 0, "Problem reading directory!" ); + sprintf(disk_path, "/"); + c_usleep(); + c_interface_exit(); + return; } if (curpos >= entries) - curpos = entries - 1; + { + curpos = entries - 1; + } - for (;;) { - for (i = 0; i < 17; i++) { - int ent_no = curpos - 8 + i, slen; - int in_drive = 0; + for (;; ) + { + for (i = 0; i < 17; i++) + { + int ent_no = curpos - 8 + i, slen; + int in_drive = 0; - strcpy( temp, " " ); - if (ent_no >= 0 && ent_no < entries) { - snprintf(temp, TEMPSIZE, "%s/%s", - disk_path, namelist[ent_no]->d_name); - if (!strcmp(temp, disk6.disk[drive].file_name)) - in_drive = 1; + strcpy( temp, " " ); + if (ent_no >= 0 && ent_no < entries) + { + snprintf(temp, TEMPSIZE, "%s/%s", + disk_path, namelist[ent_no]->d_name); + if (!strcmp(temp, disk6.disk[drive].file_name)) + { + in_drive = 1; + } - stat(temp, &statbuf); - if (S_ISDIR(statbuf.st_mode)) - snprintf(temp, TEMPSIZE, " %s/", - namelist[ ent_no ] -> d_name ); - else - snprintf(temp, TEMPSIZE, " %s", - namelist[ ent_no ] -> d_name ); - if (c_interface_cut_name(temp)) { - strncat(temp, " ", TEMPSIZE-1); - } - /* write protected disk in drive? */ - else if ((in_drive) && (disk6.disk[drive].protected)) - strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); - else if (in_drive) - strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); - } + stat(temp, &statbuf); + if (S_ISDIR(statbuf.st_mode)) + { + snprintf(temp, TEMPSIZE, " %s/", + namelist[ ent_no ]->d_name ); + } + else + { + snprintf(temp, TEMPSIZE, " %s", + namelist[ ent_no ]->d_name ); + } - slen = strlen( temp ); - while (slen < 38) - temp[ slen++ ] = ' '; - temp[ 38 ] = '\0'; + if (c_interface_cut_name(temp)) + { + strncat(temp, " ", TEMPSIZE-1); + } + /* write protected disk in drive? */ + else + if ((in_drive) && (disk6.disk[drive].protected)) + { + strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); + } + else + if (in_drive) + { + strncat(temp, (drive == 0) ? " " : " ", TEMPSIZE-1); + } + } - c_interface_print(1, i + 3, ent_no == curpos, temp); - } + slen = strlen( temp ); + while (slen < 38) + { + temp[ slen++ ] = ' '; + } - do - { - ch = c_mygetch(1); - } - while (ch == -1); + temp[ 38 ] = '\0'; - if (ch == kUP) /* Arrow up */ - if (curpos > 0) - curpos--; - else; - else if (ch == kDOWN) /* Arrow down */ - if (curpos < entries - 1) - curpos++; - else; - else if (ch == kPGDN) /* Page down */ - { - curpos += 16; - if (curpos > entries - 1) - curpos = entries - 1; - } - else if (ch == kPGUP) /* Page up */ - { - curpos -= 16; - if (curpos < 0) - curpos = 0; - } - else if (ch == kHOME) /* Home */ - curpos = 0; - else if (ch == kEND) /* End */ - curpos = entries - 1; - else if (ch == kESC) /* ESC */ - { - for (i = 0; i < entries; i++) - free(namelist[ i ]); - free(namelist); - c_interface_exit(); - return; - } - else if ((ch == 13) || (toupper(ch) == 'W')) /* Return */ - { - int len, cmpr = 0; + c_interface_print(1, i + 3, ent_no == curpos, temp); + } + + do + { + ch = c_mygetch(1); + } + while (ch == -1); + + if (ch == kUP) /* Arrow up */ + { + if (curpos > 0) + { + curpos--; + } + else + { + } + } + else + if (ch == kDOWN) /* Arrow down */ + { + if (curpos < entries - 1) + { + curpos++; + } + else + { + } + } + else + if (ch == kPGDN) /* Page down */ + { + curpos += 16; + if (curpos > entries - 1) + { + curpos = entries - 1; + } + } + else + if (ch == kPGUP) /* Page up */ + { + curpos -= 16; + if (curpos < 0) + { + curpos = 0; + } + } + else + if (ch == kHOME) /* Home */ + { + curpos = 0; + } + else + if (ch == kEND) /* End */ + { + curpos = entries - 1; + } + else + if (ch == kESC) /* ESC */ + { + for (i = 0; i < entries; i++) + { + free(namelist[ i ]); + } + + free(namelist); + c_interface_exit(); + return; + } + else + if ((ch == 13) || (toupper(ch) == 'W')) /* Return */ + { + int len, cmpr = 0; snprintf(temp, TEMPSIZE, "%s/%s", - disk_path, namelist[ curpos ] -> d_name ); - len = strlen(disk_path); + disk_path, namelist[ curpos ]->d_name ); + len = strlen(disk_path); - /* handle disk currently in the drive */ - if (!strcmp(temp, disk6.disk[drive].file_name)) { - /* reopen disk, forcing write enabled */ - if (toupper(ch) == 'W') { - if (c_new_diskette_6( - drive, - temp, - disk6.disk[drive].compressed, - disk6.disk[drive].nibblized, 0)) - { - c_interface_print( 1, 21, 0, - " Disk is read and write protected. " ); - c_interface_print( 1, 22, 0, - " " ); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } + /* handle disk currently in the drive */ + if (!strcmp(temp, disk6.disk[drive].file_name)) + { + /* reopen disk, forcing write enabled */ + if (toupper(ch) == 'W') + { + if (c_new_diskette_6( + drive, + temp, + disk6.disk[drive].compressed, + disk6.disk[drive].nibblized, 0)) + { + c_interface_print( 1, 21, 0, + " Disk is read and write protected. " ); + c_interface_print( 1, 22, 0, + " " ); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } - for (i = 0; i < entries; i++) - free(namelist[ i ]); /* clean up */ - free(namelist); - c_interface_exit(); /* resume emulation */ - return; - } + for (i = 0; i < entries; i++) + { + free(namelist[ i ]); /* clean up */ + } - /* eject the disk and start over */ - c_eject_6(drive); - for (i = 0; i < entries; i++) - free(namelist[ i ]); /* clean up */ - free(namelist); - goto NEXTDIR; /* I'm lazy */ - } + free(namelist); + c_interface_exit(); /* resume emulation */ + return; + } - /* read another directory */ - stat(temp, &statbuf); - if (S_ISDIR(statbuf.st_mode)) { - if (toupper(ch) == 'W') continue;/* can't protect this */ + /* eject the disk and start over */ + c_eject_6(drive); + for (i = 0; i < entries; i++) + { + free(namelist[ i ]); /* clean up */ + } - if ((disk_path[len-1]) == '/') disk_path[--len] = '\0'; + free(namelist); + goto NEXTDIR; /* I'm lazy */ + } - if (!strcmp("..", namelist[curpos]->d_name)) { - while (--len && (disk_path[len] != '/')) - disk_path[len] = '\0'; - } - else if (strcmp(".", namelist[curpos]->d_name)) - snprintf(disk_path + len, DISKSIZE-len, "/%s", - namelist[curpos]->d_name); - for (i = 0; i < entries; i++) - free(namelist[ i ]); /* clean up */ - free(namelist); - goto NEXTDIR; /* I'm lazy */ - } + /* read another directory */ + stat(temp, &statbuf); + if (S_ISDIR(statbuf.st_mode)) + { + if (toupper(ch) == 'W') + { + continue; /* can't protect this */ - /* uncompress the gziped disk */ - if (c_interface_is_gz(temp)) - { - if ((pid = fork())) { /* parent process */ - c_interface_print( 1, 21, 0, - " Uncompressing... " ); - c_interface_print( 1, 22, 0, - " " ); - if (waitpid(pid, NULL, 0) == -1) { - c_interface_print( 1, 21, 0, - " Problem gunzip'ing " ); - c_interface_print( 1, 22, 0, - " " ); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } - } else if (!pid) { /* child process */ - /* privileged mode - gzip in place */ - if (execl("/bin/gzip", "/bin/gzip", - "-d", temp, NULL) == -1) - { - snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); - perror("\tproblem"); - c_interface_print( 1, 21, 0, - " Problem exec'ing /bin/gzip -d " ); - c_interface_print( 1, 22, 0, temp); - c_usleep(); - exit(-1); - } - } else { - snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); - c_interface_print( 1, 21, 0, - " Cannot fork! " ); - c_interface_print( 1, 22, 0, temp); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } + } - c_interface_cut_gz( temp ); - cmpr = 1; - } + if ((disk_path[len-1]) == '/') + { + disk_path[--len] = '\0'; + } - /* gzip the last disk */ - if (disk6.disk[drive].compressed) { - /* gzip the last disk if it was compressed_6 */ + if (!strcmp("..", namelist[curpos]->d_name)) + { + while (--len && (disk_path[len] != '/')) + { + disk_path[len] = '\0'; + } + } + else + if (strcmp(".", namelist[curpos]->d_name)) + { + snprintf(disk_path + len, DISKSIZE-len, "/%s", + namelist[curpos]->d_name); + } - if ((pid = fork())) { /* parent process */ - /* privileged mode - gzip in place */ - c_interface_print( 1, 21, 0, - " Compressing old diskette... " ); - c_interface_print( 1, 22, 0, - " " ); - if (waitpid(pid, NULL, 0) == -1) { - c_interface_print( 1, 21, 0, - " Problem gzip'ing " ); - c_interface_print( 1, 22, 0, - " " ); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } - } else if (!pid) { /* child process */ - /* privileged mode - gzip in place */ - if (execl("/bin/gzip", "/bin/gzip", - disk6.disk[drive].file_name, NULL) == -1) - { - c_interface_print( 1, 21, 0, - " Problem exec'ing /bin/gzip " ); - c_interface_print( 1, 22, 0, temp); - c_usleep(); - exit(-1); - } - } else { - snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); - c_interface_print( 1, 21, 0, - " Cannot fork! " ); - c_interface_print( 1, 22, 0, temp); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } - } + for (i = 0; i < entries; i++) + { + free(namelist[ i ]); /* clean up */ + } - /* now try to change the disk */ - if (c_new_diskette_6( - drive, temp, cmpr, c_interface_is_nibblized(temp), - (toupper(ch) != 'W'))) - { - c_interface_print( 1, 21, 0, - " Disk is read and write protected. " ); - c_interface_print( 1, 22, 0, - " " ); - c_usleep(); - c_mygetch(1); - c_interface_redo_diskette_bottom(); - continue; - } + free(namelist); + goto NEXTDIR; /* I'm lazy */ + } - for (i = 0; i < entries; i++) - free(namelist[ i ]); /* clean up */ - free(namelist); - c_interface_exit(); /* resume emulation */ - return; - } + /* uncompress the gziped disk */ + if (c_interface_is_gz(temp)) + { + if ((pid = fork())) /* parent process */ + { + c_interface_print( 1, 21, 0, + " Uncompressing... " ); + c_interface_print( 1, 22, 0, + " " ); + if (waitpid(pid, NULL, 0) == -1) + { + c_interface_print( 1, 21, 0, + " Problem gunzip'ing " ); + c_interface_print( 1, 22, 0, + " " ); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } + } + else + if (!pid) /* child process */ + { /* privileged mode - gzip in place */ + if (execl("/bin/gzip", "/bin/gzip", + "-d", temp, NULL) == -1) + { + snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); + perror("\tproblem"); + c_interface_print( 1, 21, 0, + " Problem exec'ing /bin/gzip -d " ); + c_interface_print( 1, 22, 0, temp); + c_usleep(); + exit(-1); + } + } + else + { + snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); + c_interface_print( 1, 21, 0, + " Cannot fork! " ); + c_interface_print( 1, 22, 0, temp); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } + + c_interface_cut_gz( temp ); + cmpr = 1; + } + + /* gzip the last disk */ + if (disk6.disk[drive].compressed) + { + /* gzip the last disk if it was compressed_6 */ + + if ((pid = fork())) /* parent process */ + { /* privileged mode - gzip in place */ + c_interface_print( 1, 21, 0, + " Compressing old diskette... " ); + c_interface_print( 1, 22, 0, + " " ); + if (waitpid(pid, NULL, 0) == -1) + { + c_interface_print( 1, 21, 0, + " Problem gzip'ing " ); + c_interface_print( 1, 22, 0, + " " ); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } + } + else + if (!pid) /* child process */ + { /* privileged mode - gzip in place */ + if (execl("/bin/gzip", "/bin/gzip", + disk6.disk[drive].file_name, NULL) == -1) + { + c_interface_print( 1, 21, 0, + " Problem exec'ing /bin/gzip " ); + c_interface_print( 1, 22, 0, temp); + c_usleep(); + exit(-1); + } + } + else + { + snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]); + c_interface_print( 1, 21, 0, + " Cannot fork! " ); + c_interface_print( 1, 22, 0, temp); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } + } + + /* now try to change the disk */ + if (c_new_diskette_6( + drive, temp, cmpr, c_interface_is_nibblized(temp), + (toupper(ch) != 'W'))) + { + c_interface_print( 1, 21, 0, + " Disk is read and write protected. " ); + c_interface_print( 1, 22, 0, + " " ); + c_usleep(); + c_mygetch(1); + c_interface_redo_diskette_bottom(); + continue; + } + + for (i = 0; i < entries; i++) + { + free(namelist[ i ]); /* clean up */ + } + + free(namelist); + c_interface_exit(); /* resume emulation */ + return; + } } } @@ -669,55 +805,57 @@ void c_interface_select_diskette( int drive ) void c_interface_parameters() { static char screen[24][41] = - { "||||||||||||||||||||||||||||||||||||||||", - "| Apple II Emulator for Linux |", - "| Originally by |", - "| Alexander Jean-Claude Bottema |", - "||||||||||||||||||||||||||||||||||||||||", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "||||||||||||||||||||||||||||||||||||||||", - "| F1 F2: Slot6 Drive A, Drive B |", - "| F4 : Pause Emulation |", - "| F5 : Keyboard Layout |", - "| F9 : Toggle Max Speed |", - "| F10 : This Menu |", - "||||||||||||||||||||||||||||||||||||||||", - "| Use arrow keys (or Return) to modify |", - "| parameters. (Press ESC to exit menu) |", - "||||||||||||||||||||||||||||||||||||||||" }; + { "||||||||||||||||||||||||||||||||||||||||", + "| Apple II Emulator for Linux |", + "| Originally by |", + "| Alexander Jean-Claude Bottema |", + "||||||||||||||||||||||||||||||||||||||||", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "| |", + "||||||||||||||||||||||||||||||||||||||||", + "| F1 F2: Slot6 Drive A, Drive B |", + "| F4 : Pause Emulation |", + "| F5 : Keyboard Layout |", + "| F9 : Toggle Max Speed |", + "| F10 : This Menu |", + "||||||||||||||||||||||||||||||||||||||||", + "| Use arrow keys (or Return) to modify |", + "| parameters. (Press ESC to exit menu) |", + "||||||||||||||||||||||||||||||||||||||||" }; - static char *options[NUM_OPTIONS] = - { " Speed : ", /* 0 */ - " Path : ", - " Mode : ", - " Color : ", - " Sound : ", - " Joystick : ", /* 5 */ - " Calibrate ", - " JS Range : ", - " Origin X : ", - " Origin Y : ", - " JS Sens. : ", /* 10 */ - " JS Sample: ", - " Save ", - " Quit " }; + static char *options[NUM_OPTIONS] = + { " Speed : ", /* 0 */ + " Path : ", + " Mode : ", + " Color : ", + " Sound : ", + " Joystick : ", /* 5 */ + " Calibrate ", + " JS Range : ", + " Origin X : ", + " Origin Y : ", + " JS Sens. : ", /* 10 */ + " JS Sample: ", + " Save ", + " Quit " }; - int i; - int ch; - static int option = 0; - static int cur_y = 0, cur_off = 0, cur_x = 0, cur_pos = 0; - int current_mode = apple_mode; + int i; + int ch; + static int option = 0; + static int cur_y = 0, cur_off = 0, cur_x = 0, cur_pos = 0; + int current_mode = apple_mode; if (!iie_supported && (current_mode == 2)) - current_mode = apple_mode = 0; + { + current_mode = apple_mode = 0; + } /* reset the x position, so we don't lose our cursor if path changes */ cur_x = 0; @@ -726,385 +864,541 @@ void c_interface_parameters() c_interface_translate_screen( screen ); for (i = 0; i < 24; i++) - c_interface_print( 0, i, 2,screen[ i ] ); + { + c_interface_print( 0, i, 2,screen[ i ] ); + } - for (;;) { - for (i = 0; i < 9; i++) { - cur_off = option - 8; - if (cur_off < 0) cur_off = 0; + for (;; ) + { + for (i = 0; i < 9; i++) + { + cur_off = option - 8; + if (cur_off < 0) + { + cur_off = 0; + } - c_interface_print( 1, 5 + i, cur_y == i, options[ i + cur_off ] ); - - switch (i + cur_off) - { - case 0: - snprintf(temp, TEMPSIZE, "%03d", - MAX_APPLE_DELAY + 1 - cpu65_delay); - break; - case 1: - strncpy(temp, disk_path + cur_pos, 24); - temp[24] = '\0'; - break; - case 2: + c_interface_print( 1, 5 + i, cur_y == i, options[ i + cur_off ] ); + + switch (i + cur_off) + { + case 0: + snprintf(temp, TEMPSIZE, "%03d", + MAX_APPLE_DELAY + 1 - cpu65_delay); + break; + case 1: + strncpy(temp, disk_path + cur_pos, 24); + temp[24] = '\0'; + break; + case 2: #ifdef APPLE_IIE - sprintf(temp, "%s", (apple_mode == 0) ? "][+ " : - (apple_mode == 1) ? "][+ undocumented" : - "//e "); + sprintf(temp, "%s", (apple_mode == 0) ? "][+ " : + (apple_mode == 1) ? "][+ undocumented" : + "//e "); #else - sprintf(temp, "%s", (apple_mode == 0) ? "][+ " : - "][+ undocumented"); + sprintf(temp, "%s", (apple_mode == 0) ? "][+ " : + "][+ undocumented"); #endif - break; - case 3: - sprintf(temp, "%s", (color_mode == 0) ? "Black/White " : - (color_mode == 1) ? "Lazy Color " : - (color_mode == 2) ? "Color " : - (color_mode == 3) ? "Lazy Interp." : - "Interpolated"); - break; - case 4: - sprintf(temp, "%s", (sound_mode == 0) ? "Off " : - "PC speaker"); - break; - case 5: - sprintf(temp, "%s", (joy_mode == JOY_KYBD) ? "Linear " : - (joy_mode == JOY_DIGITAL) ? "Digital " : - (joy_mode == JOY_PCJOY) ? "PC Joystick" : - "Off "); - break; - case 6: /* calibrate joystick */ - strcpy( temp, "" ); - break; - case 7: - sprintf(temp, "%02x", joy_range); - break; - case 8: - sprintf(temp, "%02x", joy_center_x); - break; - case 9: - sprintf(temp, "%02x", joy_center_y); - break; - case 10: - sprintf(temp, "%03d%%", joy_step ); - break; - case 11: + break; + case 3: + sprintf(temp, "%s", (color_mode == 0) ? "Black/White " : + (color_mode == 1) ? "Lazy Color " : + (color_mode == 2) ? "Color " : + (color_mode == 3) ? "Lazy Interp." : + "Interpolated"); + break; + case 4: + sprintf(temp, "%s", (sound_mode == 0) ? "Off " : + "PC speaker"); + break; + case 5: + sprintf(temp, "%s", (joy_mode == JOY_KYBD) ? "Linear " : + (joy_mode == JOY_DIGITAL) ? "Digital " : + (joy_mode == JOY_PCJOY) ? "PC Joystick" : + "Off "); + break; + case 6: /* calibrate joystick */ + strcpy( temp, "" ); + break; + case 7: + sprintf(temp, "%02x", joy_range); + break; + case 8: + sprintf(temp, "%02x", joy_center_x); + break; + case 9: + sprintf(temp, "%02x", joy_center_y); + break; + case 10: + sprintf(temp, "%03d%%", joy_step ); + break; + case 11: #ifdef PC_JOYSTICK - sprintf(temp, "%ld", js_timelimit); + sprintf(temp, "%ld", js_timelimit); #else - sprintf(temp, "%s", ""); + sprintf(temp, "%s", ""); #endif - break; - case SAVE_SETTINGS: /* save settings */ - strcpy( temp, "" ); - break; - case QUIT_EMULATOR: /* quit emulator */ - strcpy( temp, "" ); - break; - default: - break; - } + break; + case SAVE_SETTINGS: /* save settings */ + strcpy( temp, "" ); + break; + case QUIT_EMULATOR: /* quit emulator */ + strcpy( temp, "" ); + break; + default: + break; + } - pad_string(temp, ' ', 26); - if (i+cur_off != 1) - c_interface_print(14, 5 + i, 0, temp); - else { - int j; + pad_string(temp, ' ', 26); + if (i+cur_off != 1) + { + c_interface_print(14, 5 + i, 0, temp); + } + else + { + int j; - for (j = 0; j < 24; j++) - if (cur_x != j) - { - if (temp[ j ] == '\0') - { - video_plotchar( 14 + j, 5+i, 0, ' ' ); - j++; - break; - } - else - video_plotchar( 14 + j, 5+i, 0, temp[ j ] ); - } - else - { - if (temp[ j ] == '\0') - { - video_plotchar( 14 + j, 5+i, option==1,' ' ); - j++; - break; - } - else - video_plotchar( 14 + j, 5+i, option==1, - temp[ j ]); - - } - for (; j < 24; j++) - video_plotchar( 14 + j, 5+i, 0, ' ' ); - } + for (j = 0; j < 24; j++) + { + if (cur_x != j) + { + if (temp[ j ] == '\0') + { + video_plotchar( 14 + j, 5+i, 0, ' ' ); + j++; + break; + } + else + { + video_plotchar( 14 + j, 5+i, 0, temp[ j ] ); + } + } + else + { + if (temp[ j ] == '\0') + { + video_plotchar( 14 + j, 5+i, option==1,' ' ); + j++; + break; + } + else + { + video_plotchar( 14 + j, 5+i, option==1, + temp[ j ]); + } + + } + } + + for (; j < 24; j++) + { + video_plotchar( 14 + j, 5+i, 0, ' ' ); + } + } } - do - { - ch = c_mygetch(1); - } - while (ch == -1); + do + { + ch = c_mygetch(1); + } + while (ch == -1); - if (ch == kUP) { /* Arrow up */ - if (option > 8) { - option--; /* only dec option */ - } else if (option > 0) { - option--; /* dec option */ - cur_y--; /* and dec y position */ - } else { - option = NUM_OPTIONS-1; /* wrap to last option */ - cur_y = 8; /* wrap to last y position */ - } - } - else if (ch == kDOWN) { /* Arrow down */ - if (cur_y < 8) { - option++; /* inc option */ - cur_y++; /* and inc y position */ - } else if (option < NUM_OPTIONS-1) { - option++; /* only inc option */ - } else { - cur_y = option = 0; /* wrap both to first */ - } - } - else if (ch == kLEFT) { /* Arrow left */ - switch (option) { - case 0: /* inc speed */ - if (cpu65_delay < MAX_APPLE_DELAY) - cpu65_delay++; - break; - case 1: /* path */ - if (cur_x > 0) - cur_x--; - else - if (cur_pos > 0) - cur_pos--; - break; - case 2: /* apple mode */ - apple_mode--; - if (apple_mode < 0) - apple_mode = 2; - if ((apple_mode == 2) && !iie_supported) - apple_mode = 1; - break; - case 3: /* color mode */ - if (color_mode == 0) - color_mode = 4; - else - --color_mode; - break; - case 4: /* sound mode */ - if (sound_mode == 0) - sound_mode = 1; - else - --sound_mode; - break; - case 5: /* joystick mode */ + if (ch == kUP) /* Arrow up */ + { + if (option > 8) + { + option--; /* only dec option */ + } + else + if (option > 0) + { + option--; /* dec option */ + cur_y--; /* and dec y position */ + } + else + { + option = NUM_OPTIONS-1; /* wrap to last option */ + cur_y = 8; /* wrap to last y position */ + } + } + else + if (ch == kDOWN) /* Arrow down */ + { + if (cur_y < 8) + { + option++; /* inc option */ + cur_y++; /* and inc y position */ + } + else + if (option < NUM_OPTIONS-1) + { + option++; /* only inc option */ + } + else + { + cur_y = option = 0; /* wrap both to first */ + } + } + else + if (ch == kLEFT) /* Arrow left */ + { + switch (option) + { + case 0: /* inc speed */ + if (cpu65_delay < MAX_APPLE_DELAY) + { + cpu65_delay++; + } + + break; + case 1: /* path */ + if (cur_x > 0) + { + cur_x--; + } + else + if (cur_pos > 0) + { + cur_pos--; + } + + break; + case 2: /* apple mode */ + apple_mode--; + if (apple_mode < 0) + { + apple_mode = 2; + } + + if ((apple_mode == 2) && !iie_supported) + { + apple_mode = 1; + } + + break; + case 3: /* color mode */ + if (color_mode == 0) + { + color_mode = 4; + } + else + { + --color_mode; + } + + break; + case 4: /* sound mode */ + if (sound_mode == 0) + { + sound_mode = 1; + } + else + { + --sound_mode; + } + + break; + case 5: /* joystick mode */ #ifdef PC_JOYSTICK - if (joy_mode == 0) - joy_mode = 3; + if (joy_mode == 0) + { + joy_mode = 3; + } + #else - if (joy_mode == 0) - joy_mode = 2; + if (joy_mode == 0) + { + joy_mode = 2; + } + #endif - else - --joy_mode; - break; - case 6: /* calibrate */ - break; - case 7: /* range */ - if (joy_range > 10) { - --joy_range; - joy_center_x = joy_range/2; - joy_center_y = joy_range/2; - } - break; - case 8: /* origin x */ - if (joy_center_x > 0) - joy_center_x--; - break; - case 9: /* origin y */ - if (joy_center_y > 0) - joy_center_y--; - break; - case 10: /* sensitivity */ - if (joy_step > 1) - joy_step--; - break; - case 11: + else + { + --joy_mode; + } + break; + case 6: /* calibrate */ + break; + case 7: /* range */ + if (joy_range > 10) + { + --joy_range; + joy_center_x = joy_range/2; + joy_center_y = joy_range/2; + } + + break; + case 8: /* origin x */ + if (joy_center_x > 0) + { + joy_center_x--; + } + + break; + case 9: /* origin y */ + if (joy_center_y > 0) + { + joy_center_y--; + } + + break; + case 10: /* sensitivity */ + if (joy_step > 1) + { + joy_step--; + } + + break; + case 11: #ifdef PC_JOYSTICK - if (js_timelimit > 2) /* joystick sample rate */ - --js_timelimit; + if (js_timelimit > 2) /* joystick sample rate */ + { + --js_timelimit; + } + #endif - break; - case SAVE_SETTINGS: /* save settings */ - case QUIT_EMULATOR: /* quit emulator */ - break; - } - } - else if (ch == kRIGHT) { /* Arrow right */ - switch (option) { - case 0: /* dec speed */ - if (cpu65_delay > 1) - cpu65_delay--; - break; - case 1: /* path */ - if (cur_x < 23) - { - if (disk_path[cur_pos + cur_x] != '\0') - cur_x++; - } - else - if (disk_path[cur_pos + cur_x] != '\0') - cur_pos++; - break; - case 2: /* apple mode */ - apple_mode++; - if (apple_mode > 2) - apple_mode = 0; - if ((apple_mode == 2) && !iie_supported) - apple_mode = 0; - break; - case 3: /* color mode */ - color_mode++; - if (color_mode > 4) - color_mode = 0; - break; - case 4: /* sound mode */ - sound_mode++; - if (sound_mode > 1) - sound_mode = 0; - break; - case 5: /* joystick mode */ + break; + case SAVE_SETTINGS: /* save settings */ + case QUIT_EMULATOR: /* quit emulator */ + break; + } + } + else + if (ch == kRIGHT) /* Arrow right */ + { + switch (option) + { + case 0: /* dec speed */ + if (cpu65_delay > 1) + { + cpu65_delay--; + } + + break; + case 1: /* path */ + if (cur_x < 23) + { + if (disk_path[cur_pos + cur_x] != '\0') + { + cur_x++; + } + } + else + if (disk_path[cur_pos + cur_x] != '\0') + { + cur_pos++; + } + + break; + case 2: /* apple mode */ + apple_mode++; + if (apple_mode > 2) + { + apple_mode = 0; + } + + if ((apple_mode == 2) && !iie_supported) + { + apple_mode = 0; + } + + break; + case 3: /* color mode */ + color_mode++; + if (color_mode > 4) + { + color_mode = 0; + } + + break; + case 4: /* sound mode */ + sound_mode++; + if (sound_mode > 1) + { + sound_mode = 0; + } + + break; + case 5: /* joystick mode */ #ifdef PC_JOYSTICK - if (joy_mode == 3) - joy_mode = 0; + if (joy_mode == 3) + { + joy_mode = 0; + } + #else - if (joy_mode == 2) - joy_mode = 0; + if (joy_mode == 2) + { + joy_mode = 0; + } + #endif - else - ++joy_mode; - break; - case 6: /* calibrate */ - break; - case 7: /* range */ - if (joy_range < 256) { - ++joy_range; - joy_center_x = joy_range/2; - joy_center_y = joy_range/2; - } - break; - case 8: /* origin x */ - if (joy_center_x < joy_range-1) - joy_center_x++; - break; - case 9: /* origin y */ - if (joy_center_y < joy_range-1) - joy_center_y++; - break; - case 10: /* sensitivity */ - if (joy_step < 100) - joy_step++; - break; - case 11: /* joystick sample rate */ + else + { + ++joy_mode; + } + break; + case 6: /* calibrate */ + break; + case 7: /* range */ + if (joy_range < 256) + { + ++joy_range; + joy_center_x = joy_range/2; + joy_center_y = joy_range/2; + } + + break; + case 8: /* origin x */ + if (joy_center_x < joy_range-1) + { + joy_center_x++; + } + + break; + case 9: /* origin y */ + if (joy_center_y < joy_range-1) + { + joy_center_y++; + } + + break; + case 10: /* sensitivity */ + if (joy_step < 100) + { + joy_step++; + } + + break; + case 11: /* joystick sample rate */ #ifdef PC_JOYSTICK - js_timelimit++; + js_timelimit++; #endif - break; - case SAVE_SETTINGS: /* save settings */ - case QUIT_EMULATOR: /* quit emulator */ - break; - } - } - else if (ch == kESC) { /* exit menu */ - c_initialize_sound(); - video_set(0); /* redo colors */ + break; + case SAVE_SETTINGS: /* save settings */ + case QUIT_EMULATOR: /* quit emulator */ + break; + } + } + else + if (ch == kESC) /* exit menu */ + { + c_initialize_sound(); + video_set(0); /* redo colors */ #ifdef PC_JOYSTICK - if (joy_mode == JOY_PCJOY) { - c_close_joystick(); /* close the joystick */ - c_open_joystick(); /* reopen the joystick */ - half_joy_range = joy_range/2; - c_calculate_joystick_parms(); - } else { - c_close_joystick(); - } + if (joy_mode == JOY_PCJOY) + { + c_close_joystick(); /* close the joystick */ + c_open_joystick(); /* reopen the joystick */ + half_joy_range = joy_range/2; + c_calculate_joystick_parms(); + } + else + { + c_close_joystick(); + } + #endif - /* reboot machine if different */ - if (current_mode != apple_mode) - cpu65_interrupt(RebootSig); + /* reboot machine if different */ + if (current_mode != apple_mode) + { + cpu65_interrupt(RebootSig); + } - c_interface_exit(); - return; - } - else { - /* got a normal character setting path */ - if (ch >= ' ' && ch < 127 && option == PATH_OPTION) { - int i; + c_interface_exit(); + return; + } + else + { + /* got a normal character setting path */ + if (ch >= ' ' && ch < 127 && option == PATH_OPTION) + { + int i; - strncpy(temp, disk_path, TEMPSIZE); - for (i = strlen(temp); i >= cur_pos + cur_x; i--) - temp[ i + 1 ] = temp[ i ]; - temp[ cur_pos + cur_x ] = ch; - strncpy(disk_path, temp, DISKSIZE); - if (cur_x < 23) - cur_x++; - else - if (disk_path[cur_pos + cur_x] != '\0') - cur_pos++; - } + strncpy(temp, disk_path, TEMPSIZE); + for (i = strlen(temp); i >= cur_pos + cur_x; i--) + { + temp[ i + 1 ] = temp[ i ]; + } - /* Backspace or delete setting path */ - if ((ch == 127 || ch == 8) && (cur_pos + cur_x - 1 >= 0) && - (option == 1)) - { - int i; + temp[ cur_pos + cur_x ] = ch; + strncpy(disk_path, temp, DISKSIZE); + if (cur_x < 23) + { + cur_x++; + } + else + if (disk_path[cur_pos + cur_x] != '\0') + { + cur_pos++; + } + } - for (i = cur_pos + cur_x - 1; disk_path[ i ] != '\0'; i++) - disk_path[ i ] = disk_path[ i + 1 ]; + /* Backspace or delete setting path */ + if ((ch == 127 || ch == 8) && (cur_pos + cur_x - 1 >= 0) && + (option == 1)) + { + int i; + + for (i = cur_pos + cur_x - 1; disk_path[ i ] != '\0'; i++) + { + disk_path[ i ] = disk_path[ i + 1 ]; + } + + if (cur_x > 0) + { + cur_x--; + } + else + if (cur_pos > 0) + { + cur_pos--; + } + } - if (cur_x > 0) - cur_x--; - else - if (cur_pos > 0) - cur_pos--; - } #ifdef PC_JOYSTICK - /* calibrate joystick */ - if ((ch == 13) && (option == CALIBRATE_OPTION)) { - c_calibrate_joystick(); - } + /* calibrate joystick */ + if ((ch == 13) && (option == CALIBRATE_OPTION)) + { + c_calibrate_joystick(); + } + #endif - /* save settings */ - if ((ch == 13) && (option == SAVE_SETTINGS)) { - save_settings(); - } + /* save settings */ + if ((ch == 13) && (option == SAVE_SETTINGS)) + { + save_settings(); + } - /* quit apple II simulator */ - if (ch == 13 && option == QUIT_EMULATOR) { - int ch; + /* quit apple II simulator */ + if (ch == 13 && option == QUIT_EMULATOR) + { + int ch; - c_interface_print( - 1, 22, 0, " Are you sure? (Y/N) " ); - while ((ch = c_mygetch(1)) == -1) ; - ch = toupper(ch); - if (ch == 'Y') - { + c_interface_print( + 1, 22, 0, " Are you sure? (Y/N) " ); + while ((ch = c_mygetch(1)) == -1) + { + } + + ch = toupper(ch); + if (ch == 'Y') + { c_eject_6( 0 ); c_eject_6( 1 ); #ifdef PC_JOYSTICK - c_close_joystick(); + c_close_joystick(); #endif - printf("Linux! ...and there were much rejoicing! " - "oyeeeeh...\n"); - video_shutdown(); - exit( 0 ); - } - - c_interface_print( 0, 22, 2, screen[ 22 ] ); - - } - } + printf("Linux! ...and there were much rejoicing! " + "oyeeeeh...\n"); + video_shutdown(); + exit( 0 ); + } + + c_interface_print( 0, 22, 2, screen[ 22 ] ); + + } + } } } @@ -1117,41 +1411,46 @@ void c_interface_parameters() void c_interface_words() { static char screen[24][41] = - { "||||||||||||||||||||||||||||||||||||||||", - "| Apple II+ Emulator Version 0.01 |", - "||||||||||||||||||||||||||||||||||||||||", - "| If you have problems with your |", - "| keyboard concerning the mapping of |", - "| various keys, please let me know. |", - "| I use a Swedish keyboard for myself |", - "| and the scancodes may differ from US |", - "| keyboards (or other countries as |", - "| well). Currently, my email address |", - "| is: d91a1bo@meryl.csd.uu.se. This |", - "| address is valid at least one more |", - "| year, i.e. as long as I am Computer |", - "| Science student at the University |", - "| of Uppsala. \"...and there were much |", - "| rejoicing! oyeeeeeh\" |", - "| |", - "| |", - "| |", - "| |", - "| / Alexander Oct 9 1994 |", - "||||||||||||||||||||||||||||||||||||||||", - "| (Press any key to exit) |", - "||||||||||||||||||||||||||||||||||||||||" }; + { "||||||||||||||||||||||||||||||||||||||||", + "| Apple II+ Emulator Version 0.01 |", + "||||||||||||||||||||||||||||||||||||||||", + "| If you have problems with your |", + "| keyboard concerning the mapping of |", + "| various keys, please let me know. |", + "| I use a Swedish keyboard for myself |", + "| and the scancodes may differ from US |", + "| keyboards (or other countries as |", + "| well). Currently, my email address |", + "| is: d91a1bo@meryl.csd.uu.se. This |", + "| address is valid at least one more |", + "| year, i.e. as long as I am Computer |", + "| Science student at the University |", + "| of Uppsala. \"...and there were much |", + "| rejoicing! oyeeeeeh\" |", + "| |", + "| |", + "| |", + "| |", + "| / Alexander Oct 9 1994 |", + "||||||||||||||||||||||||||||||||||||||||", + "| (Press any key to exit) |", + "||||||||||||||||||||||||||||||||||||||||" }; - int i; + int i; video_setpage( 0 ); c_interface_translate_screen( screen ); for (i = 0; i < 24; i++) - c_interface_print( 0, i, 2, screen[ i ] ); + { + c_interface_print( 0, i, 2, screen[ i ] ); + } + + while (c_mygetch(1) == -1) + { + } - while (c_mygetch(1) == -1) { } c_interface_exit(); } #endif /* if 0 */ @@ -1163,76 +1462,85 @@ void c_interface_words() void c_interface_keyboard_layout() { static char screen1[24][41] = - { "||||||||||||||||||||||||||||||||||||||||", - "| Apple II+ US Keyboard Layout |", - "||||||||||||||||||||||||||||||||||||||||", - "| |", - "| 1! 2\" 3# 4$ 5% 6& 7' 8( 9) 0 :* -= |", - "| Q W E R T Y U I O P@ CR |", - "| A S D F G H J K L ;+ <- ->|", - "| Z X C V B N^ M ,< .> /? |", - "| Where <- -> are the left and right |", - "| arrow keys respectively. |", - "| |", - "| Joystick emulation on numeric keypad |", - "| 7 8 9 for various directions. |", - "| 4 6 Press 5 to center linear |", - "| 1 2 3 joystick. |", - "| |", - "| Ctrl-PrintScrn/SysRq is REBOOT. |", - "| Ctrl-Pause/Break is RESET. |", - "| Pause/Break alone pauses emulation. |", - "| Alt Left and Alt Right are Apple |", - "| Keys (Joystick buttons 0 & 1). |", - "||||||||||||||||||||||||||||||||||||||||", - "| (Press any key to exit) |", - "||||||||||||||||||||||||||||||||||||||||" }; + { "||||||||||||||||||||||||||||||||||||||||", + "| Apple II+ US Keyboard Layout |", + "||||||||||||||||||||||||||||||||||||||||", + "| |", + "| 1! 2\" 3# 4$ 5% 6& 7' 8( 9) 0 :* -= |", + "| Q W E R T Y U I O P@ CR |", + "| A S D F G H J K L ;+ <- ->|", + "| Z X C V B N^ M ,< .> /? |", + "| Where <- -> are the left and right |", + "| arrow keys respectively. |", + "| |", + "| Joystick emulation on numeric keypad |", + "| 7 8 9 for various directions. |", + "| 4 6 Press 5 to center linear |", + "| 1 2 3 joystick. |", + "| |", + "| Ctrl-PrintScrn/SysRq is REBOOT. |", + "| Ctrl-Pause/Break is RESET. |", + "| Pause/Break alone pauses emulation. |", + "| Alt Left and Alt Right are Apple |", + "| Keys (Joystick buttons 0 & 1). |", + "||||||||||||||||||||||||||||||||||||||||", + "| (Press any key to exit) |", + "||||||||||||||||||||||||||||||||||||||||" }; #ifdef APPLE_IIE static char screen2[24][41] = - { "||||||||||||||||||||||||||||||||||||||||", - "| Apple //e US Keyboard Layout |", - "||||||||||||||||||||||||||||||||||||||||", - "| |", - "|1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ =+ dl|", - "| Q W E R T Y U I O P [{ ]} \\| |", - "|cp A S D F G H J K L ;: '\" CR |", - "|sh Z X C V B N M ,< .> /? sh |", - "|ctrl |", - "| |", - "| Where dl is DEL, cp is CAPS, CR is |", - "| RETURN, sh is SHIFT, ctrl is CONTROL.|", - "| Arrow keys are as is. |", - "| Joystick emulation is same as the |", - "| ][+. |", - "| |", - "| Ctrl-PrintScrn/SysRq is REBOOT. |", - "| Ctrl-Pause/Break is RESET. |", - "| Pause/Break alone pauses emulation. |", - "| Alt Left and Alt Right are Apple |", - "| Keys (Joystick buttons 0 & 1). |", - "||||||||||||||||||||||||||||||||||||||||", - "| (Press any key to exit) |", - "||||||||||||||||||||||||||||||||||||||||" }; + { "||||||||||||||||||||||||||||||||||||||||", + "| Apple //e US Keyboard Layout |", + "||||||||||||||||||||||||||||||||||||||||", + "| |", + "|1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ =+ dl|", + "| Q W E R T Y U I O P [{ ]} \\| |", + "|cp A S D F G H J K L ;: '\" CR |", + "|sh Z X C V B N M ,< .> /? sh |", + "|ctrl |", + "| |", + "| Where dl is DEL, cp is CAPS, CR is |", + "| RETURN, sh is SHIFT, ctrl is CONTROL.|", + "| Arrow keys are as is. |", + "| Joystick emulation is same as the |", + "| ][+. |", + "| |", + "| Ctrl-PrintScrn/SysRq is REBOOT. |", + "| Ctrl-Pause/Break is RESET. |", + "| Pause/Break alone pauses emulation. |", + "| Alt Left and Alt Right are Apple |", + "| Keys (Joystick buttons 0 & 1). |", + "||||||||||||||||||||||||||||||||||||||||", + "| (Press any key to exit) |", + "||||||||||||||||||||||||||||||||||||||||" }; #endif - int i; + int i; video_setpage( 0 ); #ifdef APPLE_IIE - if (apple_mode == 2) { - c_interface_translate_screen(screen2); - for (i = 0; i < 24; i++) - c_interface_print( 0, i, 2, screen2[ i ] ); - } else + if (apple_mode == 2) + { + c_interface_translate_screen(screen2); + for (i = 0; i < 24; i++) + { + c_interface_print( 0, i, 2, screen2[ i ] ); + } + } + else #endif { - c_interface_translate_screen(screen1); - for (i = 0; i < 24; i++) - c_interface_print( 0, i, 2, screen1[ i ] ); + c_interface_translate_screen(screen1); + for (i = 0; i < 24; i++) + { + c_interface_print( 0, i, 2, screen1[ i ] ); + } + } + + while (c_mygetch(1) == -1) + { } - while (c_mygetch(1) == -1) { } c_interface_exit(); } diff --git a/src/interface.h b/src/interface.h index f3c64114..fad68e3e 100644 --- a/src/interface.h +++ b/src/interface.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Exported menu routines * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,22 +7,22 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ #ifndef A2_INTERFACE_H #define A2_INTERFACE_H -void c_interface_print( int x, int y, int cs, char *s ); -void c_interface_redo_bottom();/* bit of a HACK? */ -void c_load_interface_font(); -void c_interface_keyboard_layout(); -void c_interface_parameters(); -void c_interface_exit(); -void c_interface_translate_screen(char screen[24][41]); -void c_interface_select_diskette(int); +void c_interface_print( int x, int y, int cs, char *s ); +void c_interface_redo_bottom(); /* bit of a HACK? */ +void c_load_interface_font(); +void c_interface_keyboard_layout(); +void c_interface_parameters(); +void c_interface_exit(); +void c_interface_translate_screen(char screen[24][41]); +void c_interface_select_diskette(int); #endif diff --git a/src/joystick.c b/src/joystick.c index 56fa66df..2fa51f59 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Joystick calibration routines * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -28,8 +28,8 @@ #include "misc.h" #include "prefs.h" -int js_fd = -1; /* joystick file descriptor */ -struct JS_DATA_TYPE js; /* joystick data struct */ +int js_fd = -1; /* joystick file descriptor */ +struct JS_DATA_TYPE js; /* joystick data struct */ int js_lowerrange_x, js_upperrange_x, @@ -49,18 +49,26 @@ float c_open_joystick() - opens joystick device and sets timelimit value ------------------------------------------------------------------------- */ int c_open_joystick() { - if (js_fd < 0) { - if ((js_fd = open("/dev/js0", O_RDONLY)) < 0) { + if (js_fd < 0) + { + if ((js_fd = open("/dev/js0", O_RDONLY)) < 0) + { - /* try again with another name */ - if ((js_fd = open("/dev/joystick", O_RDONLY)) < 0) - return 1;/* problem */ - } - /* set timelimit value */ - if (ioctl(js_fd, JS_SET_TIMELIMIT, &js_timelimit) == -1) - return 1;/* problem */ + /* try again with another name */ + if ((js_fd = open("/dev/joystick", O_RDONLY)) < 0) + { + return 1; /* problem */ + } + } + + /* set timelimit value */ + if (ioctl(js_fd, JS_SET_TIMELIMIT, &js_timelimit) == -1) + { + return 1; /* problem */ + } } - return 0;/* no problem */ + + return 0; /* no problem */ } /* ------------------------------------------------------------------------- @@ -68,7 +76,10 @@ int c_open_joystick() { ------------------------------------------------------------------------- */ void c_close_joystick() { if (js_fd < 0) - return; + { + return; + } + close(js_fd); js_fd = -1; } @@ -99,7 +110,7 @@ void c_calculate_joystick_parms() { and center coordinates. assumes that it can write to the interface screen. ------------------------------------------------------------------------- */ -void c_calibrate_joystick () { +void c_calibrate_joystick() { int almost_done, done; unsigned char x_val, y_val; @@ -110,50 +121,67 @@ void c_calibrate_joystick () { js_min_y = MAXINT; /* open joystick device if not open */ - if (js_fd < 0) { - if (c_open_joystick()) { /* problem opening device */ - c_interface_print( - 1, 21, 0, " " ); - c_interface_print( - 1, 22, 0, " cannot open joystick device. " ); - video_sync(0); - usleep(1500000); - c_interface_redo_bottom(); - return;/* problem */ - } + if (js_fd < 0) + { + if (c_open_joystick()) /* problem opening device */ + { + c_interface_print( + 1, 21, 0, " " ); + c_interface_print( + 1, 22, 0, " cannot open joystick device. " ); + video_sync(0); + usleep(1500000); + c_interface_redo_bottom(); + return; /* problem */ + } } c_interface_print( - 1, 21, 0, " Move joystick to all extremes then " ); + 1, 21, 0, " Move joystick to all extremes then " ); c_interface_print( - 1, 22, 0, " center it and press a button. " ); + 1, 22, 0, " center it and press a button. " ); video_sync(0); usleep(1500000); c_interface_print( - 1, 21, 0, " " ); + 1, 21, 0, " " ); c_interface_print( - 1, 22, 0, " " ); + 1, 22, 0, " " ); - almost_done = done = 0; /* not done calibrating */ + almost_done = done = 0; /* not done calibrating */ while ((read(js_fd, &js, JS_RETURN) > 0) && (!done)) { - sprintf (temp, " x = %04x, y = %04x", js.x, js.y); - c_interface_print(1, 22, 0, temp); - video_sync(0); - if (js_max_x < js.x) - js_max_x = js.x; - if (js_max_y < js.y) - js_max_y = js.y; + sprintf(temp, " x = %04x, y = %04x", js.x, js.y); + c_interface_print(1, 22, 0, temp); + video_sync(0); + if (js_max_x < js.x) + { + js_max_x = js.x; + } - if (js_min_x > js.x) - js_min_x = js.x; - if (js_min_y > js.y) - js_min_y = js.y; + if (js_max_y < js.y) + { + js_max_y = js.y; + } - if (js.buttons != 0x00) /* press */ - almost_done = 1; - if (almost_done && (js.buttons == 0x00)) /* release */ - done = 1; + if (js_min_x > js.x) + { + js_min_x = js.x; + } + + if (js_min_y > js.y) + { + js_min_y = js.y; + } + + if (js.buttons != 0x00) /* press */ + { + almost_done = 1; + } + + if (almost_done && (js.buttons == 0x00)) /* release */ + { + done = 1; + } } js_center_x = js.x; @@ -167,7 +195,7 @@ void c_calibrate_joystick () { printf("js_center_y = %d\n", js_center_y); printf("\n"); - c_calculate_joystick_parms(); /* determine the parms */ + c_calculate_joystick_parms(); /* determine the parms */ printf("js_lowerrange_x = %d\n", js_lowerrange_x); printf("js_lowerrange_y = %d\n", js_lowerrange_y); @@ -184,24 +212,26 @@ void c_calibrate_joystick () { printf("\n"); c_interface_print( - 1, 21, 0, " Press a button to continue. " ); + 1, 21, 0, " Press a button to continue. " ); video_sync(0); /* show the normalized values until user presses button */ - while ((read(js_fd, &js, JS_RETURN) > 0) && js.buttons == 0x00) { - x_val = (js.x < js_center_x) - ? (js.x - js_offset_x) * js_adjustlow_x - : (js.x - (js_center_x/*+js_offset_x*/)) * js_adjusthigh_x + - half_joy_range; + while ((read(js_fd, &js, JS_RETURN) > 0) && js.buttons == 0x00) + { + x_val = (js.x < js_center_x) + ? (js.x - js_offset_x) * js_adjustlow_x + : (js.x - (js_center_x /*+js_offset_x*/)) * js_adjusthigh_x + + half_joy_range; - y_val = (js.y < js_center_y) - ? (js.y - js_offset_y) * js_adjustlow_y - : (js.y - (js_center_y/*+js_offset_y*/)) * js_adjusthigh_y + - half_joy_range; - sprintf(temp, " x = %02x, y = %02x", x_val, y_val); - c_interface_print(1, 22, 0, temp); - video_sync(0); + y_val = (js.y < js_center_y) + ? (js.y - js_offset_y) * js_adjustlow_y + : (js.y - (js_center_y /*+js_offset_y*/)) * js_adjusthigh_y + + half_joy_range; + sprintf(temp, " x = %02x, y = %02x", x_val, y_val); + c_interface_print(1, 22, 0, temp); + video_sync(0); } + c_interface_redo_bottom(); video_sync(0); } diff --git a/src/keys.c b/src/keys.c index e6c662fa..688dd7cd 100644 --- a/src/keys.c +++ b/src/keys.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Keyboard handler * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -34,175 +34,175 @@ extern uid_t user, privileged; extern void c_do_debugging(); /* parameters for generic and keyboard-simulated joysticks */ -short joy_x = 127; -short joy_y = 127; -unsigned char joy_button0 = 0; -unsigned char joy_button1 = 0; -unsigned char joy_button2 = 0; +short joy_x = 127; +short joy_y = 127; +unsigned char joy_button0 = 0; +unsigned char joy_button1 = 0; +unsigned char joy_button2 = 0; #ifdef PC_JOYSTICK #include int x_val, y_val; #endif -static int next_key = -1; -static char caps_lock = 1; /* is enabled */ -static int in_mygetch = 0; +static int next_key = -1; +static char caps_lock = 1; /* is enabled */ +static int in_mygetch = 0; /* ---------------------------------------------------- Keymap. Mapping scancodes to Apple II+ US Keyboard ---------------------------------------------------- */ static int apple_ii_keymap_plain[128] = - { -1 , 27 , '1', '2', '3', '4', '5', '6', /* 00-07 */ - '7', '8', '9', '0', ':', '-', 8 , 27 , /* 08-15 */ - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ - 'O', 'P', -1 , 8 , 13 , -1 , 'A', 'S', /* 24-31 */ - '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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */ + '7', '8', '9', '0', ':', '-', 8, 27, /* 08-15 */ + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ + 'O', 'P', -1, 8, 13, -1, 'A', 'S', /* 24-31 */ + '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 */ + 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 */ + -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, -1, -1, -1, -1 }; /* 120-127 */ static int apple_ii_keymap_ctrl[128] = - { -1 , 027, '1', '2', '3', '4', '5', '6', /* 00-07 */ - '7', '8', '9', '0', ':', '-', 8 , 27 , /* 08-15 */ - 17 , 23 , 5 , 18 , 20 , 25 , 21 , 9 , /* 16-23 */ - 15 , 16 , -1 , 8 , 13 , -1 , 1 , 19 , /* 24-31 */ - 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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 027, '1', '2', '3', '4', '5', '6', /* 00-07 */ + '7', '8', '9', '0', ':', '-', 8, 27, /* 08-15 */ + 17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */ + 15, 16, -1, 8, 13, -1, 1, 19, /* 24-31 */ + 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 */ + 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 */ + -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, -1, -1, -1, -1, -1 }; /* 120-127 */ static int apple_ii_keymap_shifted[128] = - { -1 , 27 , '!', '"', '#', '$', '%', '&', /* 00-07 */ - 39 , '(', ')', '0', '*', '=', 8 , 27 , /* 08-15 */ - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ - 'O', '@', -1 , 8 , 13 , -1 , 'A', 'S', /* 24-31 */ - '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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '!', '"', '#', '$', '%', '&', /* 00-07 */ + 39, '(', ')', '0', '*', '=', 8, 27, /* 08-15 */ + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ + 'O', '@', -1, 8, 13, -1, 'A', 'S', /* 24-31 */ + '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 */ + 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 */ + -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, -1, -1, -1, -1 }; /* 120-127 */ #ifdef APPLE_IIE /* ---------------------------------------------------- //e Keymap. Mapping scancodes to Apple //e US Keyboard ---------------------------------------------------- */ static int apple_iie_keymap_plain[128] = - { -1 , 27 , '1', '2', '3', '4', '5', '6', /* 00-07 */ - '7', '8', '9', '0', '-', '=', 8 , 9 , /* 08-15 */ - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* 16-23 */ - 'o', 'p', '[', ']', 13 , -1 , 'a', 's', /* 24-31 */ - '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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */ + '7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */ + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* 16-23 */ + 'o', 'p', '[', ']', 13, -1, 'a', 's', /* 24-31 */ + '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 */ + 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 */ + -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, -1, -1, -1, -1 }; /* 120-127 */ static int apple_iie_keymap_ctrl[128] = - { -1 , 27 , '1', '2', '3', '4', '5', '6', /* 00-07 */ - '7', '8', '9', '0', '-', '=', 8 , 9 , /* 08-15 */ - 17 , 23 , 5 , 18 , 20 , 25 , 21 , 9 , /* 16-23 */ - 15 , 16 , 27 , 29 , 13 , -1 , 1 , 19 , /* 24-31 */ - 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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */ + '7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */ + 17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */ + 15, 16, 27, 29, 13, -1, 1, 19, /* 24-31 */ + 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 */ + 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 */ + -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, -1, -1, -1, -1, -1 }; /* 120-127 */ static int apple_iie_keymap_shifted[128] = - { -1 , 27 , '!', '@', '#', '$', '%', '^', /* 00-07 */ - '&', '*', '(', ')', '_', '+', 8 , 9 , /* 08-15 */ - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ - 'O', 'P', '{', '}', 13 , -1 , 'A', 'S', /* 24-31 */ - '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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '!', '@', '#', '$', '%', '^', /* 00-07 */ + '&', '*', '(', ')', '_', '+', 8, 9, /* 08-15 */ + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ + 'O', 'P', '{', '}', 13, -1, 'A', 'S', /* 24-31 */ + '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 */ + 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 */ + -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, -1, -1, -1, -1 }; /* 120-127 */ static int apple_iie_keymap_caps[128] = - { -1 , 27 , '1', '2', '3', '4', '5', '6', /* 00-07 */ - '7', '8', '9', '0', '-', '=', 8 , 9 , /* 08-15 */ - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ - 'O', 'P', '[', ']', 13 , -1 , 'A', 'S', /* 24-31 */ - '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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */ + '7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */ + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */ + 'O', 'P', '[', ']', 13, -1, 'A', 'S', /* 24-31 */ + '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 */ + 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 */ + -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, -1, -1, -1, -1 }; /* 120-127 */ static int apple_iie_keymap_shift_ctrl[128] = - { -1 , 27 , '1', 0 , '3', '4', '5', 30 , /* 00-07 */ - '7', '8', '9', '0', 31 , '=', 8 , 9 , /* 08-15 */ - 17 , 23 , 5 , 18 , 20 , 25 , 21 , 9 , /* 16-23 */ - 15 , 16 , 27 , 29 , 13 , -1 , 1 , 19 , /* 24-31 */ - 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 */ - 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 */ - -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 , -1 , -1 , -1 , -1 , -1 }; /* 120-127 */ +{ -1, 27, '1', 0, '3', '4', '5', 30, /* 00-07 */ + '7', '8', '9', '0', 31, '=', 8, 9, /* 08-15 */ + 17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */ + 15, 16, 27, 29, 13, -1, 1, 19, /* 24-31 */ + 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 */ + 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 */ + -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, -1, -1, -1, -1, -1 }; /* 120-127 */ #endif -static unsigned short max_speed = 0; -static char key_pressed[ 256 ]; +static unsigned short max_speed = 0; +static char key_pressed[ 256 ]; /* ---------------------------------------------------- @@ -211,9 +211,9 @@ static char key_pressed[ 256 ]; /* ------------------------------------------------------------------------- * This routine is called periodically to update the state of the emulator. - * -handles switching to menus - * -polls PC Joystick - * -update palette for flashing text + * -handles switching to menus + * -polls PC Joystick + * -update palette for flashing text * ------------------------------------------------------------------------- */ void c_periodic_update(int dummysig) { int current_key; @@ -221,138 +221,187 @@ void c_periodic_update(int dummysig) { video_sync(0); if (next_key >= 0) - { - current_key = next_key; - next_key = -1; + { + current_key = next_key; + next_key = -1; - if (current_key < 128) { - apple_ii_64k[0][0xC000] = current_key | 0x80; - apple_ii_64k[1][0xC000] = current_key | 0x80; - } else switch (current_key) { - 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: - c_interface_select_diskette( 0 ); - break; - case kF2: - c_interface_select_diskette( 1 ); - break; - case kF4: - while (c_mygetch(1) == -1) { }/*busy loop*/ - break; - case kF5: - c_interface_keyboard_layout(); - break; - case kF7: - cpu65_interrupt(EnterDebugSig); - break; + if (current_key < 128) + { + apple_ii_64k[0][0xC000] = current_key | 0x80; + apple_ii_64k[1][0xC000] = current_key | 0x80; + } + else + { + switch (current_key) + { + 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: + c_interface_select_diskette( 0 ); + break; + case kF2: + c_interface_select_diskette( 1 ); + break; + case kF4: + while (c_mygetch(1) == -1) + { + } /*busy loop*/ + + break; + case kF5: + c_interface_keyboard_layout(); + break; + case kF7: + cpu65_interrupt(EnterDebugSig); + break; #if 0 - case kF8: - c_interface_words(); - break; + case kF8: + c_interface_words(); + break; #endif - case kF9: - if (max_speed != 0) - cpu65_delay = max_speed, max_speed = 0; - else - max_speed = cpu65_delay, cpu65_delay = 1; - break; - case kF10: - if (max_speed != 0) - cpu65_delay = max_speed, max_speed = 0; - c_interface_parameters(); - break; - } + case kF9: + if (max_speed != 0) + { + cpu65_delay = max_speed, max_speed = 0; + } + else + { + max_speed = cpu65_delay, cpu65_delay = 1; + } + + break; + case kF10: + if (max_speed != 0) + { + cpu65_delay = max_speed, max_speed = 0; + } + + c_interface_parameters(); + break; + } + } } /* simulated joystick */ - if (joy_mode == JOY_KYBD) { - if (key_pressed[ SCODE_J_U ]) - { - if (joy_y > joy_step) - joy_y -= joy_step; - else - joy_y = 0; - } + if (joy_mode == JOY_KYBD) + { + if (key_pressed[ SCODE_J_U ]) + { + if (joy_y > joy_step) + { + joy_y -= joy_step; + } + else + { + joy_y = 0; + } + } - if (key_pressed[ SCODE_J_D ]) - { - if (joy_y < joy_range - joy_step) - joy_y += joy_step; - else - joy_y = joy_range-1; - } + if (key_pressed[ SCODE_J_D ]) + { + if (joy_y < joy_range - joy_step) + { + joy_y += joy_step; + } + else + { + joy_y = joy_range-1; + } + } - if (key_pressed[ SCODE_J_L ]) - { - if (joy_x > joy_step) - joy_x -= joy_step; - else - joy_x = 0; - } + if (key_pressed[ SCODE_J_L ]) + { + if (joy_x > joy_step) + { + joy_x -= joy_step; + } + else + { + joy_x = 0; + } + } - if (key_pressed[ SCODE_J_R ]) - { - if (joy_x < joy_range - joy_step) - joy_x += joy_step; - else - joy_x = joy_range-1; - } + if (key_pressed[ SCODE_J_R ]) + { + if (joy_x < joy_range - joy_step) + { + joy_x += joy_step; + } + else + { + joy_x = joy_range-1; + } + } } + #ifdef PC_JOYSTICK - else if ((joy_mode == JOY_PCJOY) && !(js_fd < 0)) { - if (read(js_fd, &js, JS_RETURN) == -1) { + else + if ((joy_mode == JOY_PCJOY) && !(js_fd < 0)) + { + if (read(js_fd, &js, JS_RETURN) == -1) + { // error } - x_val = (js.x < js_center_x) - ? (js.x - js_offset_x) * js_adjustlow_x - : (js.x - js_center_x) * js_adjusthigh_x + half_joy_range; + x_val = (js.x < js_center_x) + ? (js.x - js_offset_x) * js_adjustlow_x + : (js.x - js_center_x) * js_adjusthigh_x + half_joy_range; - y_val = (js.y < js_center_y) - ? (js.y - js_offset_y) * js_adjustlow_y - : (js.y - js_center_y) * js_adjusthigh_y + half_joy_range; + y_val = (js.y < js_center_y) + ? (js.y - js_offset_y) * js_adjustlow_y + : (js.y - js_center_y) * js_adjusthigh_y + half_joy_range; - joy_y = (y_val > 0xff) ? 0xff : (y_val < 0) ? 0 : y_val; - joy_x = (x_val > 0xff) ? 0xff : (x_val < 0) ? 0 : x_val; + joy_y = (y_val > 0xff) ? 0xff : (y_val < 0) ? 0 : y_val; + joy_x = (x_val > 0xff) ? 0xff : (x_val < 0) ? 0 : x_val; -/* almost_x = (x_val > 0xff) ? 0xff : (x_val < 0) ? 0 : x_val; */ -/* adj_x = (3-(joy_y/0x40)) + 10; */ -/* turnpt_x = joy_y + adj_x; */ -/* almost_x = (almost_x < turnpt_x) */ -/* ? almost_x */ -/* : (almost_x - turnpt_x) * adjusthigh_x; */ +/* almost_x = (x_val > 0xff) ? 0xff : (x_val < 0) ? 0 : x_val; */ +/* adj_x = (3-(joy_y/0x40)) + 10; */ +/* turnpt_x = joy_y + adj_x; */ +/* almost_x = (almost_x < turnpt_x) */ +/* ? almost_x */ +/* : (almost_x - turnpt_x) * adjusthigh_x; */ -/* joy_x = (almost_x > 0xff) ? 0xff : (almost_x < 0) ? 0 : almost_x; */ +/* joy_x = (almost_x > 0xff) ? 0xff : (almost_x < 0) ? 0 : almost_x; */ - /* sample buttons only if apple keys aren't pressed. keys get set to - * 0xff, and js buttons are set to 0x80. */ - if (!(joy_button0 & 0x7f)) - joy_button0 = (js.buttons & 0x01) ? 0x80 : 0x0; - if (!(joy_button1 & 0x7f)) - joy_button1 = (js.buttons & 0x02) ? 0x80 : 0x0; - if (!(joy_button2 & 0x7f)) - joy_button2 = (js.buttons & 0x03) ? 0x80 : 0x0; + /* sample buttons only if apple keys aren't pressed. keys get set to + * 0xff, and js buttons are set to 0x80. */ + if (!(joy_button0 & 0x7f)) + { + joy_button0 = (js.buttons & 0x01) ? 0x80 : 0x0; + } + + if (!(joy_button1 & 0x7f)) + { + joy_button1 = (js.buttons & 0x02) ? 0x80 : 0x0; + } + + if (!(joy_button2 & 0x7f)) + { + joy_button2 = (js.buttons & 0x03) ? 0x80 : 0x0; + } } #endif - else if (joy_mode == JOY_OFF) + else + if (joy_mode == JOY_OFF) + { joy_x = joy_y = 256; + } } -/* Called from cpu code. Perhaps should be moved to misc.c, but was +/* Called from cpu code. Perhaps should be moved to misc.c, but was * abstracted from function above... */ void enter_debugger(void) { - c_do_debugging(); + c_do_debugging(); } /* ------------------------------------------------------------------------- @@ -363,74 +412,101 @@ void c_read_raw_key(int scancode, int pressed) { /* determine which key mapping to use */ #ifdef APPLE_IIE - if (apple_mode == IIE_MODE || in_mygetch) { - /* set/reset caps lock */ - if (key_pressed[ SCODE_CAPS ]) - caps_lock = !caps_lock; + if (apple_mode == IIE_MODE || in_mygetch) + { + /* set/reset caps lock */ + if (key_pressed[ SCODE_CAPS ]) + { + 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 ])) - keymap = apple_iie_keymap_shift_ctrl; - else if (key_pressed[ SCODE_L_CTRL ] || /* ctrl */ - key_pressed[ SCODE_R_CTRL ]) - keymap = apple_iie_keymap_ctrl; - else if (key_pressed[ SCODE_L_SHIFT ] || /* shift */ - key_pressed[ SCODE_R_SHIFT ]) - keymap = apple_iie_keymap_shifted; - else if (caps_lock) /* caps lock */ - keymap = apple_iie_keymap_caps; - else /* plain */ - keymap = apple_iie_keymap_plain; - } else + if ((key_pressed[ SCODE_L_SHIFT ] || /* shift-ctrl */ + key_pressed[ SCODE_R_SHIFT ]) && + (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 ]) + { + keymap = apple_iie_keymap_ctrl; + } + else + if (key_pressed[ SCODE_L_SHIFT ] || /* shift */ + key_pressed[ SCODE_R_SHIFT ]) + { + keymap = apple_iie_keymap_shifted; + } + else + if (caps_lock) /* caps lock */ + { + keymap = apple_iie_keymap_caps; + } + else /* plain */ + { + keymap = apple_iie_keymap_plain; + } + } + else #endif { - 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 ]) - keymap = apple_ii_keymap_shifted; - else - keymap = apple_ii_keymap_plain; + 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 ]) + { + keymap = apple_ii_keymap_shifted; + } + else + { + keymap = apple_ii_keymap_plain; + } } /* key is pressed */ - if (pressed) { + if (pressed) + { - key_pressed[ scancode ] = 1; + key_pressed[ scancode ] = 1; - switch (keymap[ scancode ]) { - case JB0: - joy_button0 = 0xff;/* open apple */ - break; - case JB1: - joy_button1 = 0xff;/* closed apple */ - break; - case JB2: - joy_button2 = 0xff;/* unused? */ - break; - default: - next_key = keymap[scancode]; - break; - } + switch (keymap[ scancode ]) + { + case JB0: + joy_button0 = 0xff; /* open apple */ + break; + case JB1: + joy_button1 = 0xff; /* closed apple */ + break; + case JB2: + joy_button2 = 0xff; /* unused? */ + break; + default: + next_key = keymap[scancode]; + break; + } } - /* key is released */ - else { + else + { key_pressed[ scancode ] = 0; - switch (keymap[ scancode ]) { - case JB0: - joy_button0 = 0x00; - break; - case JB1: - joy_button1 = 0x00; - break; - case JB2: - joy_button2 = 0x00; - break; - } + switch (keymap[ scancode ]) + { + case JB0: + joy_button0 = 0x00; + break; + case JB1: + joy_button1 = 0x00; + break; + case JB2: + joy_button2 = 0x00; + break; + } } } @@ -440,10 +516,17 @@ int c_mygetch(int block) in_mygetch = 1; - if (block) while (next_key == -1) - video_sync(1); + if (block) + { + while (next_key == -1) + { + video_sync(1); + } + } else + { video_sync(0); + } in_mygetch = 0; diff --git a/src/keys.h b/src/keys.h index f6988b22..92a30f1f 100644 --- a/src/keys.h +++ b/src/keys.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Keyboard definitions * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,71 +7,71 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ #ifndef A2_KEYS_H #define A2_KEYS_H -#define SCODE_L_CTRL 29 -#define SCODE_R_CTRL 97 -#define SCODE_L_SHIFT 42 -#define SCODE_R_SHIFT 54 -#define SCODE_CAPS 58 -#define SCODE_J_U 72 -#define SCODE_J_D 80 -#define SCODE_J_L 75 -#define SCODE_J_R 77 -#define SCODE_J_C 76 +#define SCODE_L_CTRL 29 +#define SCODE_R_CTRL 97 +#define SCODE_L_SHIFT 42 +#define SCODE_R_SHIFT 54 +#define SCODE_CAPS 58 +#define SCODE_J_U 72 +#define SCODE_J_D 80 +#define SCODE_J_L 75 +#define SCODE_J_R 77 +#define SCODE_J_C 76 -#define kF1 128 -#define kF2 129 -#define kF3 130 -#define kF4 131 -#define kF5 132 -#define kF6 133 -#define kF7 134 -#define kF8 135 -#define kF9 136 -#define kF10 137 -#define kF11 138 -#define kF12 139 -#define kPRNT 140 -#define RST kPRNT +#define kF1 128 +#define kF2 129 +#define kF3 130 +#define kF4 131 +#define kF5 132 +#define kF6 133 +#define kF7 134 +#define kF8 135 +#define kF9 136 +#define kF10 137 +#define kF11 138 +#define kF12 139 +#define kPRNT 140 +#define RST kPRNT -#define J_U 141 -#define J_D 142 -#define J_L 143 -#define J_R 144 -#define JUL 145 -#define JUR 146 -#define JDL 147 -#define JDR 148 +#define J_U 141 +#define J_D 142 +#define J_L 143 +#define J_R 144 +#define JUL 145 +#define JUR 146 +#define JDL 147 +#define JDR 148 -#define JB0 149 -#define JB1 150 -#define JB2 151 +#define JB0 149 +#define JB1 150 +#define JB2 151 -#define S_D 152 -#define S_I 153 -#define J_C 154 -#define kPAUSE 155 +#define S_D 152 +#define S_I 153 +#define J_C 154 +#define kPAUSE 155 #define BOT kPAUSE -#define kLEFT 8 /* 157 */ -#define kRIGHT 21 /* 158 */ -#define kUP 11 /* 159 */ -#define kDOWN 10 /* 160 */ +#define kLEFT 8 /* 157 */ +#define kRIGHT 21 /* 158 */ +#define kUP 11 /* 159 */ +#define kDOWN 10 /* 160 */ -#define kESC 27 /* 161 */ -#define kPGUP 162 -#define kHOME 163 -#define kPGDN 164 -#define kEND 165 +#define kESC 27 /* 161 */ +#define kPGUP 162 +#define kHOME 163 +#define kPGDN 164 +#define kEND 165 #ifdef PC_JOYSTICK diff --git a/src/misc.c b/src/misc.c index b155950e..428de044 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Miscellaneous support * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -40,9 +40,9 @@ internal apple2 variables ---------------------------------- */ -static unsigned char apple_ii_rom[12288]; +static unsigned char apple_ii_rom[12288]; #ifdef APPLE_IIE -static unsigned char apple_iie_rom[32768]; /* //e */ +static unsigned char apple_iie_rom[32768]; /* //e */ #endif pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -91,24 +91,24 @@ void c_set_altchar() /* ------------------------------------------------------------------------- c_set_primary_char() - set primary character set ------------------------------------------------------------------------- */ -void c_set_primary_char() +void c_set_primary_char() { video_loadfont(0x40,0x40,ucase_glyphs,3); video_redraw(); } -#endif/* APPLE_IIE */ +#endif /* APPLE_IIE */ /* ------------------------------------------------------------------------- c_initialize_font(): Initialize ROM character table to primary char set ------------------------------------------------------------------------- */ void c_initialize_font() -{ +{ video_loadfont(0x00,0x40,ucase_glyphs,2); video_loadfont(0x40,0x40,ucase_glyphs,3); - video_loadfont(0x80,0x40,ucase_glyphs,0); + video_loadfont(0x80,0x40,ucase_glyphs,0); video_loadfont(0xC0,0x20,ucase_glyphs,0); video_loadfont(0xE0,0x20,lcase_glyphs,0); @@ -128,375 +128,423 @@ void c_initialize_tables() { pre_compact(); /* Prepare for VM compression */ /* reset everything */ - for (i = 0; i < 0x10000; i++) { + for (i = 0; i < 0x10000; i++) + { #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[i].r = iie_read_ram_default; - cpu65_vmem[i].w = iie_write_ram_default; - } else + if (apple_mode == IIE_MODE) + { + cpu65_vmem[i].r = iie_read_ram_default; + cpu65_vmem[i].w = iie_write_ram_default; + } + else #endif { - cpu65_vmem[i].r = read_ram_default; - cpu65_vmem[i].w = write_ram_default; - } + cpu65_vmem[i].r = read_ram_default; + cpu65_vmem[i].w = write_ram_default; + } } /* language card read/write area */ - for (i = 0xD000; i < 0xE000; i++) { - { - cpu65_vmem[i].w = - write_ram_bank; - cpu65_vmem[i].r = - read_ram_bank; - } + for (i = 0xD000; i < 0xE000; i++) + { + { + cpu65_vmem[i].w = + write_ram_bank; + cpu65_vmem[i].r = + read_ram_bank; + } } - for (i = 0xE000; i < 0x10000; i++) { - { - cpu65_vmem[i].w = - write_ram_lc; - cpu65_vmem[i].r = - read_ram_lc; - } + + for (i = 0xE000; i < 0x10000; i++) + { + { + cpu65_vmem[i].w = + write_ram_lc; + cpu65_vmem[i].r = + read_ram_lc; + } } + /* done common initialization */ #ifdef APPLE_IIE /* initialize zero-page, //e specific */ - if (apple_mode == IIE_MODE) { - for (i = 0; i < 0x200; i++) { - cpu65_vmem[i].r = - iie_read_ram_zpage_and_stack; - cpu65_vmem[i].w = - iie_write_ram_zpage_and_stack; - } + if (apple_mode == IIE_MODE) + { + for (i = 0; i < 0x200; i++) + { + cpu65_vmem[i].r = + iie_read_ram_zpage_and_stack; + cpu65_vmem[i].w = + iie_write_ram_zpage_and_stack; + } } + #endif #ifdef APPLE_IIE - /* initialize first text & hires page, which are specially bank switched + /* initialize first text & hires page, which are specially bank switched * - * video_set() substitutes it's own hooks for all visible write locations + * video_set() substitutes it's own hooks for all visible write locations * affect the display, leaving our write-functions in place only at the * `screen holes', hence the name. */ - for (i = 0x400; i < 0x800; i++) { - cpu65_vmem[i].r = - iie_read_ram_text_page0; - cpu65_vmem[i].w = - iie_write_screen_hole_text_page0; + for (i = 0x400; i < 0x800; i++) + { + cpu65_vmem[i].r = + iie_read_ram_text_page0; + cpu65_vmem[i].w = + iie_write_screen_hole_text_page0; } - for (i = 0x2000; i < 0x4000; i++) { - cpu65_vmem[i].r = - iie_read_ram_hires_page0; - cpu65_vmem[i].w = - iie_write_screen_hole_hires_page0; + + for (i = 0x2000; i < 0x4000; i++) + { + cpu65_vmem[i].r = + iie_read_ram_hires_page0; + cpu65_vmem[i].w = + iie_write_screen_hole_hires_page0; } + #endif /* softswich rom */ - for (i = 0xC000; i < 0xC100; i++) { - cpu65_vmem[i].r = - read_unmapped_softswitch; - cpu65_vmem[i].w = - write_unmapped_softswitch; + for (i = 0xC000; i < 0xC100; i++) + { + cpu65_vmem[i].r = + read_unmapped_softswitch; + cpu65_vmem[i].w = + write_unmapped_softswitch; } /* slot rom */ - for (i = 0xC100; i < 0xD000; i++) { - cpu65_vmem[i].r = + for (i = 0xC100; i < 0xD000; i++) + { + cpu65_vmem[i].r = #ifdef APPLE_IIE - iie_read_ram_default; + iie_read_ram_default; #else - read_ram_default; + read_ram_default; #endif - cpu65_vmem[i].w = - ram_nop; + cpu65_vmem[i].w = + ram_nop; } /* keyboard data and strobe (READ) */ - for (i = 0xC000; i < 0xC010; i++) { - cpu65_vmem[i].r = - read_keyboard; + for (i = 0xC000; i < 0xC010; i++) + { + cpu65_vmem[i].r = + read_keyboard; } - for (i = 0xC010; i < 0xC020; i++) { - cpu65_vmem[i].r = - cpu65_vmem[i].w = - read_keyboard_strobe; + + for (i = 0xC010; i < 0xC020; i++) + { + cpu65_vmem[i].r = + cpu65_vmem[i].w = + read_keyboard_strobe; } #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { + if (apple_mode == IIE_MODE) + { - /* RDBNK2 switch */ - cpu65_vmem[0xC011].r = - iie_check_bank; + /* RDBNK2 switch */ + cpu65_vmem[0xC011].r = + iie_check_bank; - /* RDLCRAM switch */ - cpu65_vmem[0xC012].r = - iie_check_lcram; + /* RDLCRAM switch */ + cpu65_vmem[0xC012].r = + iie_check_lcram; - /* 80STORE switch */ - cpu65_vmem[0xC000].w = iie_80store_off; - cpu65_vmem[0xC001].w = iie_80store_on; - cpu65_vmem[0xC018].r = iie_check_80store; + /* 80STORE switch */ + cpu65_vmem[0xC000].w = iie_80store_off; + cpu65_vmem[0xC001].w = iie_80store_on; + cpu65_vmem[0xC018].r = iie_check_80store; - /* RAMRD switch */ - cpu65_vmem[0xC002].w = iie_ramrd_main; - cpu65_vmem[0xC003].w = iie_ramrd_aux; - cpu65_vmem[0xC013].r = iie_check_ramrd; + /* RAMRD switch */ + cpu65_vmem[0xC002].w = iie_ramrd_main; + cpu65_vmem[0xC003].w = iie_ramrd_aux; + cpu65_vmem[0xC013].r = iie_check_ramrd; - /* RAMWRT switch */ - cpu65_vmem[0xC004].w = iie_ramwrt_main; - cpu65_vmem[0xC005].w = iie_ramwrt_aux; - cpu65_vmem[0xC014].r = iie_check_ramwrt; + /* RAMWRT switch */ + cpu65_vmem[0xC004].w = iie_ramwrt_main; + cpu65_vmem[0xC005].w = iie_ramwrt_aux; + cpu65_vmem[0xC014].r = iie_check_ramwrt; - /* ALTZP switch */ - cpu65_vmem[0xC008].w = iie_altzp_main; - cpu65_vmem[0xC009].w = iie_altzp_aux; - cpu65_vmem[0xC016].r = iie_check_altzp; + /* ALTZP switch */ + cpu65_vmem[0xC008].w = iie_altzp_main; + cpu65_vmem[0xC009].w = iie_altzp_aux; + cpu65_vmem[0xC016].r = iie_check_altzp; - /* 80COL switch */ - cpu65_vmem[0xC00C].w = iie_80col_off; - cpu65_vmem[0xC00D].w = iie_80col_on; - cpu65_vmem[0xC01F].r = iie_check_80col; + /* 80COL switch */ + cpu65_vmem[0xC00C].w = iie_80col_off; + cpu65_vmem[0xC00D].w = iie_80col_on; + cpu65_vmem[0xC01F].r = iie_check_80col; - /* ALTCHAR switch */ - cpu65_vmem[0xC00E].w = iie_altchar_off; - cpu65_vmem[0xC00F].w = iie_altchar_on; - cpu65_vmem[0xC01E].r = iie_check_altchar; + /* ALTCHAR switch */ + cpu65_vmem[0xC00E].w = iie_altchar_off; + cpu65_vmem[0xC00F].w = iie_altchar_on; + cpu65_vmem[0xC01E].r = iie_check_altchar; - /* SLOTC3ROM switch */ - cpu65_vmem[0xC00A].w = iie_c3rom_internal; - cpu65_vmem[0xC00B].w = iie_c3rom_peripheral; - cpu65_vmem[0xC017].r = iie_check_c3rom; + /* SLOTC3ROM switch */ + cpu65_vmem[0xC00A].w = iie_c3rom_internal; + cpu65_vmem[0xC00B].w = iie_c3rom_peripheral; + cpu65_vmem[0xC017].r = iie_check_c3rom; - /* SLOTCXROM switch */ - cpu65_vmem[0xC006].w = iie_cxrom_peripheral; - cpu65_vmem[0xC007].w = iie_cxrom_internal; - cpu65_vmem[0xC015].r = iie_check_cxrom; + /* SLOTCXROM switch */ + cpu65_vmem[0xC006].w = iie_cxrom_peripheral; + cpu65_vmem[0xC007].w = iie_cxrom_internal; + cpu65_vmem[0xC015].r = iie_check_cxrom; - /* RDVBLBAR switch */ - cpu65_vmem[0xC019].r = - iie_check_vbl; + /* RDVBLBAR switch */ + cpu65_vmem[0xC019].r = + iie_check_vbl; } + #endif - + /* random number generator */ for (i = 0xC020; i < 0xC030; i++) - cpu65_vmem[i].r = - cpu65_vmem[i].w = - read_random; + { + cpu65_vmem[i].r = + cpu65_vmem[i].w = + read_random; + } /* TEXT switch */ cpu65_vmem[0xC050].r = - cpu65_vmem[0xC050].w = - read_switch_graphics; + cpu65_vmem[0xC050].w = + read_switch_graphics; cpu65_vmem[0xC051].r = - cpu65_vmem[0xC051].w = - read_switch_text; + cpu65_vmem[0xC051].w = + read_switch_text; #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC01A].r = - iie_check_text; + if (apple_mode == IIE_MODE) + { + cpu65_vmem[0xC01A].r = + iie_check_text; } + #endif /* MIXED switch */ cpu65_vmem[0xC052].r = - cpu65_vmem[0xC052].w = - read_switch_no_mixed; + cpu65_vmem[0xC052].w = + read_switch_no_mixed; cpu65_vmem[0xC053].r = - cpu65_vmem[0xC053].w = - read_switch_mixed; + cpu65_vmem[0xC053].w = + read_switch_mixed; #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC01B].r = - iie_check_mixed; - } - /* PAGE2 switch */ - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC054].r = - cpu65_vmem[0xC054].w = - iie_page2_off; - } else -#endif + if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC054].r = - cpu65_vmem[0xC054].w = - read_switch_primary_page; + cpu65_vmem[0xC01B].r = + iie_check_mixed; } -#ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC01C].r = - iie_check_page2; - } /* PAGE2 switch */ - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC055].r = - cpu65_vmem[0xC055].w = - iie_page2_on; - } else -#endif + if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC055].r = - cpu65_vmem[0xC055].w = - read_switch_secondary_page; - } - - /* HIRES switch */ -#ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC01D].r = - iie_check_hires; - cpu65_vmem[0xC056].r = - cpu65_vmem[0xC056].w = - iie_hires_off; - cpu65_vmem[0xC057].r = - cpu65_vmem[0xC057].w = - iie_hires_on; + cpu65_vmem[0xC054].r = + cpu65_vmem[0xC054].w = + iie_page2_off; } else #endif { - cpu65_vmem[0xC056].r = - cpu65_vmem[0xC056].w = - read_switch_lores; - cpu65_vmem[0xC057].r = - cpu65_vmem[0xC057].w = - read_switch_hires; + cpu65_vmem[0xC054].r = + cpu65_vmem[0xC054].w = + read_switch_primary_page; + } + +#ifdef APPLE_IIE + if (apple_mode == IIE_MODE) + { + cpu65_vmem[0xC01C].r = + iie_check_page2; + } + + /* PAGE2 switch */ + if (apple_mode == IIE_MODE) + { + cpu65_vmem[0xC055].r = + cpu65_vmem[0xC055].w = + iie_page2_on; + } + else +#endif + { + cpu65_vmem[0xC055].r = + cpu65_vmem[0xC055].w = + read_switch_secondary_page; + } + + /* HIRES switch */ +#ifdef APPLE_IIE + if (apple_mode == IIE_MODE) + { + cpu65_vmem[0xC01D].r = + iie_check_hires; + cpu65_vmem[0xC056].r = + cpu65_vmem[0xC056].w = + iie_hires_off; + cpu65_vmem[0xC057].r = + cpu65_vmem[0xC057].w = + iie_hires_on; + } + else +#endif + { + cpu65_vmem[0xC056].r = + cpu65_vmem[0xC056].w = + read_switch_lores; + cpu65_vmem[0xC057].r = + cpu65_vmem[0xC057].w = + read_switch_hires; } /* game I/O switches */ cpu65_vmem[0xC061].r = - cpu65_vmem[0xC069].r = - read_button0; + cpu65_vmem[0xC069].r = + read_button0; cpu65_vmem[0xC062].r = - cpu65_vmem[0xC06A].r = - read_button1; + cpu65_vmem[0xC06A].r = + read_button1; cpu65_vmem[0xC063].r = - cpu65_vmem[0xC06B].r = - read_button2; + cpu65_vmem[0xC06B].r = + read_button2; cpu65_vmem[0xC064].r = - cpu65_vmem[0xC06C].r = - read_gc0; + cpu65_vmem[0xC06C].r = + read_gc0; cpu65_vmem[0xC065].r = - cpu65_vmem[0xC06D].r = - read_gc1; + cpu65_vmem[0xC06D].r = + read_gc1; #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[0xC066].r = - iie_read_gc2; - cpu65_vmem[0xC067].r = - iie_read_gc3; + if (apple_mode == IIE_MODE) + { + cpu65_vmem[0xC066].r = + iie_read_gc2; + cpu65_vmem[0xC067].r = + iie_read_gc3; } + #endif for (i = 0xC070; i < 0xC080; i++) - cpu65_vmem[i].r = - cpu65_vmem[i].w = - read_gc_strobe; + { + cpu65_vmem[i].r = + cpu65_vmem[i].w = + read_gc_strobe; + } #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - /* IOUDIS switch & read_gc_strobe */ - cpu65_vmem[0xC07E].w = - iie_ioudis_on; - cpu65_vmem[0xC07F].w = - iie_ioudis_off; - cpu65_vmem[0xC07E].r = - iie_check_ioudis; - cpu65_vmem[0xC07F].r = - iie_check_dhires; + if (apple_mode == IIE_MODE) + { + /* IOUDIS switch & read_gc_strobe */ + cpu65_vmem[0xC07E].w = + iie_ioudis_on; + cpu65_vmem[0xC07F].w = + iie_ioudis_off; + cpu65_vmem[0xC07E].r = + iie_check_ioudis; + cpu65_vmem[0xC07F].r = + iie_check_dhires; - /* DHIRES/Annunciator switches */ - cpu65_vmem[0xC05E].w = - cpu65_vmem[0xC05E].r = - iie_dhires_on; - cpu65_vmem[0xC05F].w = - cpu65_vmem[0xC05F].r = - iie_dhires_off; + /* DHIRES/Annunciator switches */ + cpu65_vmem[0xC05E].w = + cpu65_vmem[0xC05E].r = + iie_dhires_on; + cpu65_vmem[0xC05F].w = + cpu65_vmem[0xC05F].r = + iie_dhires_off; } + #endif -#ifdef APPLE_IIE +#ifdef APPLE_IIE /* language card softswitches */ cpu65_vmem[0xC080].r = cpu65_vmem[0xC080].w = - cpu65_vmem[0xC084].r = cpu65_vmem[0xC084].w = - (apple_mode == IIE_MODE) ? iie_c080 : lc_c080; + cpu65_vmem[0xC084].r = cpu65_vmem[0xC084].w = + (apple_mode == IIE_MODE) ? iie_c080 : lc_c080; cpu65_vmem[0xC081].r = cpu65_vmem[0xC081].w = - cpu65_vmem[0xC085].r = cpu65_vmem[0xC085].w = - (apple_mode == IIE_MODE) ? iie_c081 : lc_c081; + cpu65_vmem[0xC085].r = cpu65_vmem[0xC085].w = + (apple_mode == IIE_MODE) ? iie_c081 : lc_c081; cpu65_vmem[0xC082].r = cpu65_vmem[0xC082].w = - cpu65_vmem[0xC086].r = cpu65_vmem[0xC086].w = - lc_c082; + cpu65_vmem[0xC086].r = cpu65_vmem[0xC086].w = + lc_c082; cpu65_vmem[0xC083].r = cpu65_vmem[0xC083].w = - cpu65_vmem[0xC087].r = cpu65_vmem[0xC087].w = - (apple_mode == IIE_MODE) ? iie_c083 : lc_c083; + cpu65_vmem[0xC087].r = cpu65_vmem[0xC087].w = + (apple_mode == IIE_MODE) ? iie_c083 : lc_c083; cpu65_vmem[0xC088].r = cpu65_vmem[0xC088].w = - cpu65_vmem[0xC08C].r = cpu65_vmem[0xC08C].w = - (apple_mode == IIE_MODE) ? iie_c088 : lc_c088; + cpu65_vmem[0xC08C].r = cpu65_vmem[0xC08C].w = + (apple_mode == IIE_MODE) ? iie_c088 : lc_c088; cpu65_vmem[0xC089].r = cpu65_vmem[0xC089].w = - cpu65_vmem[0xC08D].r = cpu65_vmem[0xC08D].w = - (apple_mode == IIE_MODE) ? iie_c089 : lc_c089; + cpu65_vmem[0xC08D].r = cpu65_vmem[0xC08D].w = + (apple_mode == IIE_MODE) ? iie_c089 : lc_c089; cpu65_vmem[0xC08A].r = cpu65_vmem[0xC08A].w = - cpu65_vmem[0xC08E].r = cpu65_vmem[0xC08E].w = - lc_c08a; + cpu65_vmem[0xC08E].r = cpu65_vmem[0xC08E].w = + lc_c08a; cpu65_vmem[0xC08B].r = cpu65_vmem[0xC08B].w = - cpu65_vmem[0xC08F].r = cpu65_vmem[0xC08F].w = - (apple_mode == IIE_MODE) ? iie_c08b : lc_c08b; + cpu65_vmem[0xC08F].r = cpu65_vmem[0xC08F].w = + (apple_mode == IIE_MODE) ? iie_c08b : lc_c08b; #else /* !APPLE_IIE */ - /* language card softswitches */ + /* language card softswitches */ cpu65_vmem[0xC080].r = cpu65_vmem[0xC080].w = - cpu65_vmem[0xC084].r = cpu65_vmem[0xC084].w = - lc_c080; + cpu65_vmem[0xC084].r = cpu65_vmem[0xC084].w = + lc_c080; cpu65_vmem[0xC081].r = cpu65_vmem[0xC081].w = - cpu65_vmem[0xC085].r = cpu65_vmem[0xC085].w = - lc_c081; + cpu65_vmem[0xC085].r = cpu65_vmem[0xC085].w = + lc_c081; cpu65_vmem[0xC082].r = cpu65_vmem[0xC082].w = - cpu65_vmem[0xC086].r = cpu65_vmem[0xC086].w = - lc_c082; + cpu65_vmem[0xC086].r = cpu65_vmem[0xC086].w = + lc_c082; cpu65_vmem[0xC083].r = cpu65_vmem[0xC083].w = - cpu65_vmem[0xC087].r = cpu65_vmem[0xC087].w = - lc_c083; + cpu65_vmem[0xC087].r = cpu65_vmem[0xC087].w = + lc_c083; cpu65_vmem[0xC088].r = cpu65_vmem[0xC088].w = - cpu65_vmem[0xC08C].r = cpu65_vmem[0xC08C].w = - lc_c088; + cpu65_vmem[0xC08C].r = cpu65_vmem[0xC08C].w = + lc_c088; cpu65_vmem[0xC089].r = cpu65_vmem[0xC089].w = - cpu65_vmem[0xC08D].r = cpu65_vmem[0xC08D].w = - lc_c089; + cpu65_vmem[0xC08D].r = cpu65_vmem[0xC08D].w = + lc_c089; cpu65_vmem[0xC08A].r = cpu65_vmem[0xC08A].w = - cpu65_vmem[0xC08E].r = cpu65_vmem[0xC08E].w = - lc_c08a; + cpu65_vmem[0xC08E].r = cpu65_vmem[0xC08E].w = + lc_c08a; cpu65_vmem[0xC08B].r = cpu65_vmem[0xC08B].w = - cpu65_vmem[0xC08F].r = cpu65_vmem[0xC08F].w = - lc_c08b; + cpu65_vmem[0xC08F].r = cpu65_vmem[0xC08F].w = + lc_c08b; #endif /* !APPLE_IIE */ #ifdef APPLE_IIE /* slot i/o area */ - for (i = 0xC100; i < 0xC300; i++) { - cpu65_vmem[i].r = - iie_read_slotx; /* slots 1 & 2 (x) */ + for (i = 0xC100; i < 0xC300; i++) + { + cpu65_vmem[i].r = + iie_read_slotx; /* slots 1 & 2 (x) */ } - for (i = 0xC300; i < 0xC400; i++) { - cpu65_vmem[i].r = - iie_read_slot3; /* slot 3 (80col) */ + + for (i = 0xC300; i < 0xC400; i++) + { + cpu65_vmem[i].r = + iie_read_slot3; /* slot 3 (80col) */ } - for (i = 0xC400; i < 0xC800; i++) { - cpu65_vmem[i].r = - iie_read_slotx; /* slots 4 - 7 (x) */ + + for (i = 0xC400; i < 0xC800; i++) + { + cpu65_vmem[i].r = + iie_read_slotx; /* slots 4 - 7 (x) */ } - for (i = 0xC800; i < 0xD000; i++) { - cpu65_vmem[i].r = - iie_read_slot_expansion; /* expansion rom */ + + for (i = 0xC800; i < 0xD000; i++) + { + cpu65_vmem[i].r = + iie_read_slot_expansion; /* expansion rom */ } + cpu65_vmem[0xCFFF].r = - cpu65_vmem[0xCFFF].w = - iie_disable_slot_expansion; + cpu65_vmem[0xCFFF].w = + iie_disable_slot_expansion; #endif video_set(0); /* must be done here, between pre_compact & compact */ @@ -513,87 +561,119 @@ void c_initialize_tables() { void c_initialize_apple_ii_memory() { - FILE *f; - int i; - static int ii_rom_loaded = 0; + FILE *f; + int i; + static int ii_rom_loaded = 0; #ifdef APPLE_IIE - static int iie_rom_loaded = 0; + static int iie_rom_loaded = 0; #endif - for (i = 0; i < 0x10000; i++) { - apple_ii_64k[0][i] = 0; - apple_ii_64k[1][i] = 0; - } - for (i = 0; i < 8192; i++) - language_card[0][i] = language_card[1][i] = 0; - for (i = 0; i < 8192; i++) - language_banks[0][i] = language_banks[1][i] = 0; + for (i = 0; i < 0x10000; i++) + { + apple_ii_64k[0][i] = 0; + apple_ii_64k[1][i] = 0; + } - if (!ii_rom_loaded) - { - snprintf(temp, TEMPSIZE, "%s/apple_II.rom", system_path); - if ((f = fopen(temp, "r")) == NULL) { - printf("OOPS!\n"); - printf("Cannot find file '%s'.\n",temp); - exit(0); - } - if (fread(apple_ii_rom, 0x3000, 1, f) != 0x3000) { - // ERROR ... - } - fclose(f); - ii_rom_loaded = 1; - } + for (i = 0; i < 8192; i++) + { + language_card[0][i] = language_card[1][i] = 0; + } + + for (i = 0; i < 8192; i++) + { + language_banks[0][i] = language_banks[1][i] = 0; + } + + if (!ii_rom_loaded) + { + snprintf(temp, TEMPSIZE, "%s/apple_II.rom", system_path); + if ((f = fopen(temp, "r")) == NULL) + { + printf("OOPS!\n"); + printf("Cannot find file '%s'.\n",temp); + exit(0); + } + + if (fread(apple_ii_rom, 0x3000, 1, f) != 0x3000) + { + // ERROR ... + } + + fclose(f); + ii_rom_loaded = 1; + } #ifdef APPLE_IIE - if (!iie_rom_loaded) { - snprintf(temp, TEMPSIZE, "%s/apple_IIe.rom", system_path); - if ((f = fopen(temp, "r")) == NULL) { - printf("Cannot find file '%s'.\n",temp); - exit(0); - } - if (fread(apple_iie_rom, 32768, 1, f) != 32768) { - // ERROR ... - } - fclose(f); - iie_rom_loaded = 1; - } + if (!iie_rom_loaded) + { + snprintf(temp, TEMPSIZE, "%s/apple_IIe.rom", system_path); + if ((f = fopen(temp, "r")) == NULL) + { + printf("Cannot find file '%s'.\n",temp); + exit(0); + } + + if (fread(apple_iie_rom, 32768, 1, f) != 32768) + { + // ERROR ... + } + + fclose(f); + iie_rom_loaded = 1; + } + #endif - for (i = 0xD000; i < 0x10000; i++) - apple_ii_64k[0][i] = apple_ii_rom[i - 0xD000]; - for (i = 0; i < 0x1000; i++) - language_banks[0][i] = apple_ii_rom[i]; - for (i = 0; i < 0x2000; i++) - language_card[0][i] = apple_ii_rom[i + 0x1000]; + for (i = 0xD000; i < 0x10000; i++) + { + apple_ii_64k[0][i] = apple_ii_rom[i - 0xD000]; + } + + for (i = 0; i < 0x1000; i++) + { + language_banks[0][i] = apple_ii_rom[i]; + } + + for (i = 0; i < 0x2000; i++) + { + language_card[0][i] = apple_ii_rom[i + 0x1000]; + } #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - /* load the rom from 0xC000, slot rom main, internal rom aux */ - for (i = 0xC000; i < 0x10000; i++) { - apple_ii_64k[0][i] = apple_iie_rom[i - 0xC000]; - apple_ii_64k[1][i] = apple_iie_rom[i - 0x8000]; - } - for (i = 0; i < 0x1000; i++) { - language_banks[0][i] = apple_iie_rom[i + 0x1000]; - language_banks[1][i] = apple_iie_rom[i + 0x5000]; - } - for (i = 0; i < 0x2000; i++) { - language_card[0][i] = apple_iie_rom[i + 0x2000]; - language_card[1][i] = apple_iie_rom[i + 0x6000]; - } - } - else -#endif - /* softswitch memory HACK - why this? */ - { - for (i = 0xC100; i < 0xD000; i++) { - apple_ii_64k[0][i] = i & 0xFF; - apple_ii_64k[1][i] = i & 0xFF; - } - } + if (apple_mode == IIE_MODE) + { + /* load the rom from 0xC000, slot rom main, internal rom aux */ + for (i = 0xC000; i < 0x10000; i++) + { + apple_ii_64k[0][i] = apple_iie_rom[i - 0xC000]; + apple_ii_64k[1][i] = apple_iie_rom[i - 0x8000]; + } - apple_ii_64k[0][0xC000] = 0x00; - apple_ii_64k[1][0xC000] = 0x00; + for (i = 0; i < 0x1000; i++) + { + language_banks[0][i] = apple_iie_rom[i + 0x1000]; + language_banks[1][i] = apple_iie_rom[i + 0x5000]; + } + + for (i = 0; i < 0x2000; i++) + { + language_card[0][i] = apple_iie_rom[i + 0x2000]; + language_card[1][i] = apple_iie_rom[i + 0x6000]; + } + } + else +#endif + /* softswitch memory HACK - why this? */ + { + for (i = 0xC100; i < 0xD000; i++) + { + apple_ii_64k[0][i] = i & 0xFF; + apple_ii_64k[1][i] = i & 0xFF; + } + } + + apple_ii_64k[0][0xC000] = 0x00; + apple_ii_64k[1][0xC000] = 0x00; } /* ------------------------------------------------------------------------- @@ -605,8 +685,10 @@ void c_initialize_sound() int i; for (i = 0xC030; i < 0xC040; i++) + { cpu65_vmem[i].r = cpu65_vmem[i].w = - (sound_mode && soundAllowed) ? read_speaker_toggle_pc : ram_nop; + (sound_mode && soundAllowed) ? read_speaker_toggle_pc : ram_nop; + } } #ifdef APPLE_IIE @@ -628,9 +710,9 @@ void c_initialize_iie_switches() { base_hgrrd = apple_ii_64k[0]; base_hgrwrt= apple_ii_64k[0]; - base_c3rom = apple_ii_64k[1]; /* c3rom internal */ - c8rom_offset = 0x10000; /* c8rom internal */ - base_cxrom = apple_ii_64k[0]; /* cxrom peripheral */ + base_c3rom = apple_ii_64k[1]; /* c3rom internal */ + c8rom_offset = 0x10000; /* c8rom internal */ + base_cxrom = apple_ii_64k[0]; /* cxrom peripheral */ } #endif @@ -638,14 +720,14 @@ void c_initialize_iie_switches() { void c_initialize_vm() ------------------------------------------------------------------------- */ void c_initialize_vm() { - c_initialize_font(); /* font already read in */ - c_initialize_apple_ii_memory(); /* read in rom memory */ - c_initialize_tables(); /* read/write memory jump tables */ - c_initialize_sound(); /* sound system */ - c_init_6(); /* drive ][, slot 6 */ + c_initialize_font(); /* font already read in */ + c_initialize_apple_ii_memory(); /* read in rom memory */ + c_initialize_tables(); /* read/write memory jump tables */ + c_initialize_sound(); /* sound system */ + c_init_6(); /* drive ][, slot 6 */ #ifdef APPLE_IIE - c_initialize_iie_switches(); /* set the //e softswitches */ + c_initialize_iie_switches(); /* set the //e softswitches */ #endif #ifdef MOUSE_EMULATION @@ -661,45 +743,58 @@ static void reinitialize(void) { int i; - /* reset the watchpoints and breakpoints */ - for (i=0; i> 8); } -static void cpu_thread (void *dummyptr) { +static void cpu_thread(void *dummyptr) { - do { + do + { cpu65_run(); - reinitialize(); + reinitialize(); } while (1); } -static void main_thread (void *dummyptr) { - do { +static void main_thread(void *dummyptr) { + do + { // sleep waiting for the cpu thread to ping us that it's sleeping... pthread_mutex_lock(&mutex); pthread_cond_wait(&cond, &mutex); @@ -738,8 +835,8 @@ int main(int sargc, char *sargv[]) argc = sargc; argv = sargv; - load_settings(); /* user prefs */ - c_initialize_firsttime(); /* init svga graphics and vm */ + load_settings(); /* user prefs */ + c_initialize_firsttime(); /* init svga graphics and vm */ timing_initialize(); // spin off cpu thread diff --git a/src/misc.h b/src/misc.h index 4517cb6b..45c0f86f 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Miscellaneous defines * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -33,7 +33,7 @@ #define SW_ALTZP 0xC008 #define SW_80COL 0xC00C #define SW_ALTCHAR 0xC00E -#define SW_SLOTC3ROM 0xC00B /* anomaly */ +#define SW_SLOTC3ROM 0xC00B /* anomaly */ #define SW_SLOTCXROM 0xC006 #define SW_DHIRES 0xC05E #define SW_IOUDIS 0xC07E @@ -51,16 +51,16 @@ unsigned char apple_ii_64k[2][65536]; /* 128k memory */ unsigned char language_card[2][8192], language_banks[2][8192]; /* misc stuff */ -int soundAllowed; -unsigned char random_value; +int soundAllowed; +unsigned char random_value; /* global ref to commandline args */ -char **argv; -int argc; +char **argv; +int argc; /* misc arrays */ -#define TEMPSIZE 4096 -char temp[ TEMPSIZE ];/* should be >=4096 (stuff depends on this) */ +#define TEMPSIZE 4096 +char temp[ TEMPSIZE ]; /* should be >=4096 (stuff depends on this) */ #ifdef APPLE_IIE /* memory offsets from softswitches */ @@ -90,38 +90,38 @@ extern int softswitches; #endif /* !__ASSEMBLER__ */ -#define SS_TEXT 0x00000001 -#define SS_MIXED 0x00000002 -#define SS_HIRES 0x00000004 -#define SS_PAGE2 0x00000008 -#define SS_BANK2 0x00000010 -#define SS_LCRAM 0x00000020 -#define SS_LCSEC 0x00000040 /* check for double read */ -#define SS_LCWRT 0x00000080 /* LC write enable */ -#define SS_80STORE 0x00000100 -#define SS_80COL 0x00000200 -#define SS_RAMRD 0x00000400 -#define SS_RAMWRT 0x00000800 -#define SS_ALTZP 0x00001000 -#define SS_DHIRES 0x00002000 -#define SS_IOUDIS 0x00004000 -#define SS_CXROM 0x00008000 -#define SS_C3ROM 0x00010000 -#define SS_ALTCHAR 0x00020000 +#define SS_TEXT 0x00000001 +#define SS_MIXED 0x00000002 +#define SS_HIRES 0x00000004 +#define SS_PAGE2 0x00000008 +#define SS_BANK2 0x00000010 +#define SS_LCRAM 0x00000020 +#define SS_LCSEC 0x00000040 /* check for double read */ +#define SS_LCWRT 0x00000080 /* LC write enable */ +#define SS_80STORE 0x00000100 +#define SS_80COL 0x00000200 +#define SS_RAMRD 0x00000400 +#define SS_RAMWRT 0x00000800 +#define SS_ALTZP 0x00001000 +#define SS_DHIRES 0x00002000 +#define SS_IOUDIS 0x00004000 +#define SS_CXROM 0x00008000 +#define SS_C3ROM 0x00010000 +#define SS_ALTCHAR 0x00020000 /* Pseudo soft switches. These are actually functions of other SSes, but are - * tiresome to calculate as needed. + * tiresome to calculate as needed. * */ -#define SS_SCREEN 0x00040000 /* PAGE2 && !80STORE */ -#define SS_TEXTRD 0x00080000 /* (PAGE2 && 80STORE) || - (RAMRD && !80STORE) */ -#define SS_TEXTWRT 0x00100000 /* (PAGE2 && 80STORE) || - (RAMWRT && !80STORE) */ -#define SS_HGRRD 0x00200000 /* (PAGE2 && 80STORE && HIRES) || - (RAMRD && !(80STORE && HIRES) */ -#define SS_HGRWRT 0x00400000 /* (PAGE2 && 80STORE && HIRES) || - (RAMWRT && !(80STORE && HIRES)) */ +#define SS_SCREEN 0x00040000 /* PAGE2 && !80STORE */ +#define SS_TEXTRD 0x00080000 /* (PAGE2 && 80STORE) || + (RAMRD && !80STORE) */ +#define SS_TEXTWRT 0x00100000 /* (PAGE2 && 80STORE) || + (RAMWRT && !80STORE) */ +#define SS_HGRRD 0x00200000 /* (PAGE2 && 80STORE && HIRES) || + (RAMRD && !(80STORE && HIRES) */ +#define SS_HGRWRT 0x00400000 /* (PAGE2 && 80STORE && HIRES) || + (RAMWRT && !(80STORE && HIRES)) */ #ifndef __ASSEMBLER__ /* ------------------------------------------------------------------------- @@ -140,119 +140,119 @@ void compact(void); /* vm hooks */ -void ram_nop(), +void ram_nop(), - write_ram_default(), - write_unmapped_softswitch(), +write_ram_default(), +write_unmapped_softswitch(), - read_ram_default(), - read_random(), - read_unmapped_softswitch(), - read_keyboard(), - read_keyboard_strobe(), - read_speaker_toggle_pc(), - read_switch_primary_page(), - read_switch_secondary_page(), - read_switch_graphics(), - read_switch_text(), - read_switch_no_mixed(), - read_switch_mixed(), - read_switch_lores(), - read_switch_hires(), +read_ram_default(), +read_random(), +read_unmapped_softswitch(), +read_keyboard(), +read_keyboard_strobe(), +read_speaker_toggle_pc(), +read_switch_primary_page(), +read_switch_secondary_page(), +read_switch_graphics(), +read_switch_text(), +read_switch_no_mixed(), +read_switch_mixed(), +read_switch_lores(), +read_switch_hires(), - read_button0(), - read_button1(), - read_button2(), - read_gc0(), - read_gc1(), - read_gc_strobe(), - - lc_c080(), - lc_c081(), - lc_c082(), - lc_c083(), - lc_c088(), - lc_c089(), - lc_c08a(), - lc_c08b(), - write_ram_bank(), - read_ram_bank(), - write_ram_lc(), - read_ram_lc(); +read_button0(), +read_button1(), +read_button2(), +read_gc0(), +read_gc1(), +read_gc_strobe(), + +lc_c080(), +lc_c081(), +lc_c082(), +lc_c083(), +lc_c088(), +lc_c089(), +lc_c08a(), +lc_c08b(), +write_ram_bank(), +read_ram_bank(), +write_ram_lc(), +read_ram_lc(); #ifdef APPLE_IIE -void iie_write_ram_default(), - iie_read_ram_default(), +void iie_write_ram_default(), +iie_read_ram_default(), - /* //e text pages */ - iie_read_ram_text_page0(), - iie_write_screen_hole_text_page0(), +/* //e text pages */ +iie_read_ram_text_page0(), +iie_write_screen_hole_text_page0(), - /* //e hires page 0 */ - iie_read_ram_hires_page0(), - iie_write_screen_hole_hires_page0(), +/* //e hires page 0 */ +iie_read_ram_hires_page0(), +iie_write_screen_hole_hires_page0(), - /* //e zpage,stack, ram banks */ - iie_read_ram_zpage_and_stack(), - iie_write_ram_zpage_and_stack(), - iie_read_slot3(), - iie_read_slotx(), - iie_read_slot_expansion(), - iie_disable_slot_expansion(), - iie_read_gc2(), - iie_read_gc3(), +/* //e zpage,stack, ram banks */ +iie_read_ram_zpage_and_stack(), +iie_write_ram_zpage_and_stack(), +iie_read_slot3(), +iie_read_slotx(), +iie_read_slot_expansion(), +iie_disable_slot_expansion(), +iie_read_gc2(), +iie_read_gc3(), - iie_c080(), - iie_c081(), - iie_c083(), - iie_c088(), - iie_c089(), - iie_c08b(), +iie_c080(), +iie_c081(), +iie_c083(), +iie_c088(), +iie_c089(), +iie_c08b(), - /* //e toggle softswitches */ - iie_ramrd_main(), - iie_ramrd_aux(), - iie_ramwrt_main(), - iie_ramwrt_aux(), - iie_80store_off(), - iie_80store_on(), - iie_altzp_main(), - iie_altzp_aux(), - iie_80col_off(), - iie_80col_on(), - iie_altchar_off(), - iie_altchar_on(), - iie_c3rom_peripheral(), - iie_c3rom_internal(), - iie_cxrom_peripheral(), - iie_cxrom_internal(), - iie_ioudis_on(), - iie_ioudis_off(), - iie_dhires_on(), - iie_dhires_off(), - iie_hires_off(), - iie_hires_on(), - iie_page2_on(), - iie_page2_off(), +/* //e toggle softswitches */ +iie_ramrd_main(), +iie_ramrd_aux(), +iie_ramwrt_main(), +iie_ramwrt_aux(), +iie_80store_off(), +iie_80store_on(), +iie_altzp_main(), +iie_altzp_aux(), +iie_80col_off(), +iie_80col_on(), +iie_altchar_off(), +iie_altchar_on(), +iie_c3rom_peripheral(), +iie_c3rom_internal(), +iie_cxrom_peripheral(), +iie_cxrom_internal(), +iie_ioudis_on(), +iie_ioudis_off(), +iie_dhires_on(), +iie_dhires_off(), +iie_hires_off(), +iie_hires_on(), +iie_page2_on(), +iie_page2_off(), - /* //e check softswitche settings */ - iie_check_80store(), - iie_check_bank(), - iie_check_lcram(), - iie_check_ramrd(), - iie_check_ramwrt(), - iie_check_altzp(), - iie_check_c3rom(), - iie_check_cxrom(), - iie_check_80col(), - iie_check_altchar(), - iie_check_text(), - iie_check_mixed(), - iie_check_hires(), - iie_check_page2(), - iie_check_ioudis(), - iie_check_dhires(), - iie_check_vbl(); +/* //e check softswitche settings */ +iie_check_80store(), +iie_check_bank(), +iie_check_lcram(), +iie_check_ramrd(), +iie_check_ramwrt(), +iie_check_altzp(), +iie_check_c3rom(), +iie_check_cxrom(), +iie_check_80col(), +iie_check_altchar(), +iie_check_text(), +iie_check_mixed(), +iie_check_hires(), +iie_check_page2(), +iie_check_ioudis(), +iie_check_dhires(), +iie_check_vbl(); #endif /* APPLE_IIE */ #endif /* !__ASSEMBLER__ */ diff --git a/src/opcodes.c b/src/opcodes.c index e38cf508..b88eb541 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Opcode tables for debugger * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -18,803 +18,803 @@ const char * const disasm_templates[15] = { - "", - "A", - "#$%02X", - "$%02X", - "$%02X,X", - "$%02X,Y", - "$%02X%02X", - "$%02X%02X,X", - "$%02X%02X,Y", - "($%02X)", - "($%02X,X)", - "($%02X),Y", - "($%02X%02X)", - "($%02X%02X),X", - "$%04X (%c%02X)" + "", + "A", + "#$%02X", + "$%02X", + "$%02X,X", + "$%02X,Y", + "$%02X%02X", + "$%02X%02X,X", + "$%02X%02X,Y", + "($%02X)", + "($%02X,X)", + "($%02X),Y", + "($%02X%02X)", + "($%02X%02X),X", + "$%04X (%c%02X)" }; -const struct opcode_struct opcodes_6502[256] = +const struct opcode_struct opcodes_6502[256] = { - {"BRK", addr_implied}, - {"ORA", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ORA", addr_zeropage}, - {"ASL", addr_zeropage}, - {"???", addr_implied}, - {"PHP", addr_implied}, - {"ORA", addr_immediate}, - {"ASL", addr_accumulator}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ORA", addr_absolute}, - {"ASL", addr_absolute}, - {"???", addr_implied}, - {"BPL", addr_relative}, - {"ORA", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ORA", addr_zeropage_x}, - {"ASL", addr_zeropage_x}, - {"???", addr_implied}, - {"CLC", addr_implied}, - {"ORA", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ORA", addr_absolute_x}, - {"ASL", addr_absolute_x}, - {"???", addr_implied}, - {"JSR", addr_absolute}, - {"AND", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"BIT", addr_zeropage}, - {"AND", addr_zeropage}, - {"ROL", addr_zeropage}, - {"???", addr_implied}, - {"PLP", addr_implied}, - {"AND", addr_immediate}, - {"ROL", addr_accumulator}, - {"???", addr_implied}, - {"BIT", addr_absolute}, - {"AND", addr_absolute}, - {"ROL", addr_absolute}, - {"???", addr_implied}, - {"BMI", addr_relative}, - {"AND", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"AND", addr_zeropage_x}, - {"ROL", addr_zeropage_x}, - {"???", addr_implied}, - {"SEC", addr_implied}, - {"AND", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"AND", addr_absolute_x}, - {"ROL", addr_absolute_x}, - {"???", addr_implied}, - {"RTI", addr_implied}, - {"EOR", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_zeropage}, - {"LSR", addr_zeropage}, - {"???", addr_implied}, - {"PHA", addr_implied}, - {"EOR", addr_immediate}, - {"LSR", addr_accumulator}, - {"???", addr_implied}, - {"JMP", addr_absolute}, - {"EOR", addr_absolute}, - {"LSR", addr_absolute}, - {"???", addr_implied}, - {"BVC", addr_relative}, - {"EOR", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_zeropage_x}, - {"LSR", addr_zeropage_x}, - {"???", addr_implied}, - {"CLI", addr_implied}, - {"EOR", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_absolute_x}, - {"LSR", addr_absolute_x}, - {"???", addr_implied}, - {"RTS", addr_implied}, - {"ADC", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ADC", addr_zeropage}, - {"ROR", addr_zeropage}, - {"???", addr_implied}, - {"PLA", addr_implied}, - {"ADC", addr_immediate}, - {"ROR", addr_accumulator}, - {"???", addr_implied}, - {"JMP", addr_j_indirect}, - {"ADC", addr_absolute}, - {"ROR", addr_absolute}, - {"???", addr_implied}, - {"BVS", addr_relative}, - {"ADC", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ADC", addr_zeropage_x}, - {"ROR", addr_zeropage_x}, - {"???", addr_implied}, - {"SEI", addr_implied}, - {"ADC", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"ADC", addr_absolute_x}, - {"ROR", addr_absolute_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STA", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STY", addr_zeropage}, - {"STA", addr_zeropage}, - {"STX", addr_zeropage}, - {"???", addr_implied}, - {"DEY", addr_implied}, - {"???", addr_implied}, - {"TXA", addr_implied}, - {"???", addr_implied}, - {"STY", addr_absolute}, - {"STA", addr_absolute}, - {"STX", addr_absolute}, - {"???", addr_implied}, - {"BCC", addr_relative}, - {"STA", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STY", addr_zeropage_x}, - {"STA", addr_zeropage_x}, - {"STX", addr_zeropage_y}, - {"???", addr_implied}, - {"TYA", addr_implied}, - {"STA", addr_absolute_y}, - {"TXS", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STA", addr_absolute_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_immediate}, - {"LDA", addr_indirect_x}, - {"LDX", addr_immediate}, - {"???", addr_implied}, - {"LDY", addr_zeropage}, - {"LDA", addr_zeropage}, - {"LDX", addr_zeropage}, - {"???", addr_implied}, - {"TAY", addr_implied}, - {"LDA", addr_immediate}, - {"TAX", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_absolute}, - {"LDA", addr_absolute}, - {"LDX", addr_absolute}, - {"???", addr_implied}, - {"BCS", addr_relative}, - {"LDA", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_zeropage_x}, - {"LDA", addr_zeropage_x}, - {"LDX", addr_zeropage_y}, - {"???", addr_implied}, - {"CLV", addr_implied}, - {"LDA", addr_absolute_y}, - {"TSX", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_absolute_x}, - {"LDA", addr_absolute_x}, - {"LDX", addr_absolute_y}, - {"???", addr_implied}, - {"CPY", addr_immediate}, - {"CMP", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CPY", addr_zeropage}, - {"CMP", addr_zeropage}, - {"DEC", addr_zeropage}, - {"???", addr_implied}, - {"INY", addr_implied}, - {"CMP", addr_immediate}, - {"DEX", addr_implied}, - {"???", addr_implied}, - {"CPY", addr_absolute}, - {"CMP", addr_absolute}, - {"DEC", addr_absolute}, - {"???", addr_implied}, - {"BNE", addr_relative}, - {"CMP", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CMP", addr_zeropage_x}, - {"DEC", addr_zeropage_x}, - {"???", addr_implied}, - {"CLD", addr_implied}, - {"CMP", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CMP", addr_absolute_x}, - {"DEC", addr_absolute_x}, - {"???", addr_implied}, - {"CPX", addr_immediate}, - {"SBC", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CPX", addr_zeropage}, - {"SBC", addr_zeropage}, - {"INC", addr_zeropage}, - {"???", addr_implied}, - {"INX", addr_implied}, - {"SBC", addr_immediate}, - {"NOP", addr_implied}, - {"???", addr_implied}, - {"CPX", addr_absolute}, - {"SBC", addr_absolute}, - {"INC", addr_absolute}, - {"???", addr_implied}, - {"BEQ", addr_relative}, - {"SBC", addr_indirect_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"SBC", addr_zeropage_x}, - {"INC", addr_zeropage_x}, - {"???", addr_implied}, - {"SED", addr_implied}, - {"SBC", addr_absolute_y}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"SBC", addr_absolute_x}, - {"INC", addr_absolute_x}, - {"???", addr_implied}, + { "BRK", addr_implied }, + { "ORA", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ORA", addr_zeropage }, + { "ASL", addr_zeropage }, + { "???", addr_implied }, + { "PHP", addr_implied }, + { "ORA", addr_immediate }, + { "ASL", addr_accumulator }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ORA", addr_absolute }, + { "ASL", addr_absolute }, + { "???", addr_implied }, + { "BPL", addr_relative }, + { "ORA", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ORA", addr_zeropage_x }, + { "ASL", addr_zeropage_x }, + { "???", addr_implied }, + { "CLC", addr_implied }, + { "ORA", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ORA", addr_absolute_x }, + { "ASL", addr_absolute_x }, + { "???", addr_implied }, + { "JSR", addr_absolute }, + { "AND", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "BIT", addr_zeropage }, + { "AND", addr_zeropage }, + { "ROL", addr_zeropage }, + { "???", addr_implied }, + { "PLP", addr_implied }, + { "AND", addr_immediate }, + { "ROL", addr_accumulator }, + { "???", addr_implied }, + { "BIT", addr_absolute }, + { "AND", addr_absolute }, + { "ROL", addr_absolute }, + { "???", addr_implied }, + { "BMI", addr_relative }, + { "AND", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "AND", addr_zeropage_x }, + { "ROL", addr_zeropage_x }, + { "???", addr_implied }, + { "SEC", addr_implied }, + { "AND", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "AND", addr_absolute_x }, + { "ROL", addr_absolute_x }, + { "???", addr_implied }, + { "RTI", addr_implied }, + { "EOR", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_zeropage }, + { "LSR", addr_zeropage }, + { "???", addr_implied }, + { "PHA", addr_implied }, + { "EOR", addr_immediate }, + { "LSR", addr_accumulator }, + { "???", addr_implied }, + { "JMP", addr_absolute }, + { "EOR", addr_absolute }, + { "LSR", addr_absolute }, + { "???", addr_implied }, + { "BVC", addr_relative }, + { "EOR", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_zeropage_x }, + { "LSR", addr_zeropage_x }, + { "???", addr_implied }, + { "CLI", addr_implied }, + { "EOR", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_absolute_x }, + { "LSR", addr_absolute_x }, + { "???", addr_implied }, + { "RTS", addr_implied }, + { "ADC", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ADC", addr_zeropage }, + { "ROR", addr_zeropage }, + { "???", addr_implied }, + { "PLA", addr_implied }, + { "ADC", addr_immediate }, + { "ROR", addr_accumulator }, + { "???", addr_implied }, + { "JMP", addr_j_indirect }, + { "ADC", addr_absolute }, + { "ROR", addr_absolute }, + { "???", addr_implied }, + { "BVS", addr_relative }, + { "ADC", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ADC", addr_zeropage_x }, + { "ROR", addr_zeropage_x }, + { "???", addr_implied }, + { "SEI", addr_implied }, + { "ADC", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "ADC", addr_absolute_x }, + { "ROR", addr_absolute_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STA", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STY", addr_zeropage }, + { "STA", addr_zeropage }, + { "STX", addr_zeropage }, + { "???", addr_implied }, + { "DEY", addr_implied }, + { "???", addr_implied }, + { "TXA", addr_implied }, + { "???", addr_implied }, + { "STY", addr_absolute }, + { "STA", addr_absolute }, + { "STX", addr_absolute }, + { "???", addr_implied }, + { "BCC", addr_relative }, + { "STA", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STY", addr_zeropage_x }, + { "STA", addr_zeropage_x }, + { "STX", addr_zeropage_y }, + { "???", addr_implied }, + { "TYA", addr_implied }, + { "STA", addr_absolute_y }, + { "TXS", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STA", addr_absolute_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_immediate }, + { "LDA", addr_indirect_x }, + { "LDX", addr_immediate }, + { "???", addr_implied }, + { "LDY", addr_zeropage }, + { "LDA", addr_zeropage }, + { "LDX", addr_zeropage }, + { "???", addr_implied }, + { "TAY", addr_implied }, + { "LDA", addr_immediate }, + { "TAX", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_absolute }, + { "LDA", addr_absolute }, + { "LDX", addr_absolute }, + { "???", addr_implied }, + { "BCS", addr_relative }, + { "LDA", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_zeropage_x }, + { "LDA", addr_zeropage_x }, + { "LDX", addr_zeropage_y }, + { "???", addr_implied }, + { "CLV", addr_implied }, + { "LDA", addr_absolute_y }, + { "TSX", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_absolute_x }, + { "LDA", addr_absolute_x }, + { "LDX", addr_absolute_y }, + { "???", addr_implied }, + { "CPY", addr_immediate }, + { "CMP", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CPY", addr_zeropage }, + { "CMP", addr_zeropage }, + { "DEC", addr_zeropage }, + { "???", addr_implied }, + { "INY", addr_implied }, + { "CMP", addr_immediate }, + { "DEX", addr_implied }, + { "???", addr_implied }, + { "CPY", addr_absolute }, + { "CMP", addr_absolute }, + { "DEC", addr_absolute }, + { "???", addr_implied }, + { "BNE", addr_relative }, + { "CMP", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CMP", addr_zeropage_x }, + { "DEC", addr_zeropage_x }, + { "???", addr_implied }, + { "CLD", addr_implied }, + { "CMP", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CMP", addr_absolute_x }, + { "DEC", addr_absolute_x }, + { "???", addr_implied }, + { "CPX", addr_immediate }, + { "SBC", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CPX", addr_zeropage }, + { "SBC", addr_zeropage }, + { "INC", addr_zeropage }, + { "???", addr_implied }, + { "INX", addr_implied }, + { "SBC", addr_immediate }, + { "NOP", addr_implied }, + { "???", addr_implied }, + { "CPX", addr_absolute }, + { "SBC", addr_absolute }, + { "INC", addr_absolute }, + { "???", addr_implied }, + { "BEQ", addr_relative }, + { "SBC", addr_indirect_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "SBC", addr_zeropage_x }, + { "INC", addr_zeropage_x }, + { "???", addr_implied }, + { "SED", addr_implied }, + { "SBC", addr_absolute_y }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "SBC", addr_absolute_x }, + { "INC", addr_absolute_x }, + { "???", addr_implied }, }; -#ifdef APPLE_IIE +#ifdef APPLE_IIE -const struct opcode_struct opcodes_65c02[256] = +const struct opcode_struct opcodes_65c02[256] = { - {"BRK", addr_implied}, - {"ORA", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"TSB", addr_zeropage}, - {"ORA", addr_zeropage}, - {"ASL", addr_zeropage}, - {"???", addr_implied}, - {"PHP", addr_implied}, - {"ORA", addr_immediate}, - {"ASL", addr_accumulator}, - {"???", addr_implied}, - {"TSB", addr_absolute}, - {"ORA", addr_absolute}, - {"ASL", addr_absolute}, - {"???", addr_implied}, - {"BPL", addr_relative}, - {"ORA", addr_indirect_y}, - {"ORA", addr_indirect}, - {"???", addr_implied}, - {"TRB", addr_zeropage}, - {"ORA", addr_zeropage_x}, - {"ASL", addr_zeropage_x}, - {"???", addr_implied}, - {"CLC", addr_implied}, - {"ORA", addr_absolute_y}, - {"INC", addr_accumulator}, - {"???", addr_implied}, - {"TRB", addr_absolute}, - {"ORA", addr_absolute_x}, - {"ASL", addr_absolute_x}, - {"???", addr_implied}, - {"JSR", addr_absolute}, - {"AND", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"BIT", addr_zeropage}, - {"AND", addr_zeropage}, - {"ROL", addr_zeropage}, - {"???", addr_implied}, - {"PLP", addr_implied}, - {"AND", addr_immediate}, - {"ROL", addr_accumulator}, - {"???", addr_implied}, - {"BIT", addr_absolute}, - {"AND", addr_absolute}, - {"ROL", addr_absolute}, - {"???", addr_implied}, - {"BMI", addr_relative}, - {"AND", addr_indirect_y}, - {"AND", addr_indirect}, - {"???", addr_implied}, - {"BIT", addr_zeropage_x}, - {"AND", addr_zeropage_x}, - {"ROL", addr_zeropage_x}, - {"???", addr_implied}, - {"SEC", addr_implied}, - {"AND", addr_absolute_y}, - {"DEC", addr_accumulator}, - {"???", addr_implied}, - {"BIT", addr_absolute_x}, - {"AND", addr_absolute_x}, - {"ROL", addr_absolute_x}, - {"???", addr_implied}, - {"RTI", addr_implied}, - {"EOR", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_zeropage}, - {"LSR", addr_zeropage}, - {"???", addr_implied}, - {"PHA", addr_implied}, - {"EOR", addr_immediate}, - {"LSR", addr_accumulator}, - {"???", addr_implied}, - {"JMP", addr_absolute}, - {"EOR", addr_absolute}, - {"LSR", addr_absolute}, - {"???", addr_implied}, - {"BVC", addr_relative}, - {"EOR", addr_indirect_y}, - {"EOR", addr_indirect}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_zeropage_x}, - {"LSR", addr_zeropage_x}, - {"???", addr_implied}, - {"CLI", addr_implied}, - {"EOR", addr_absolute_y}, - {"PHY", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"EOR", addr_absolute_x}, - {"LSR", addr_absolute_x}, - {"???", addr_implied}, - {"RTS", addr_implied}, - {"ADC", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STZ", addr_zeropage}, - {"ADC", addr_zeropage}, - {"ROR", addr_zeropage}, - {"???", addr_implied}, - {"PLA", addr_implied}, - {"ADC", addr_immediate}, - {"ROR", addr_accumulator}, - {"???", addr_implied}, - {"JMP", addr_j_indirect}, - {"ADC", addr_absolute}, - {"ROR", addr_absolute}, - {"???", addr_implied}, - {"BVS", addr_relative}, - {"ADC", addr_indirect_y}, - {"ADC", addr_indirect}, - {"???", addr_implied}, - {"STZ", addr_zeropage_x}, - {"ADC", addr_zeropage_x}, - {"ROR", addr_zeropage_x}, - {"???", addr_implied}, - {"SEI", addr_implied}, - {"ADC", addr_absolute_y}, - {"PLY", addr_implied}, - {"???", addr_implied}, - {"JMP", addr_j_indirect_x}, - {"ADC", addr_absolute_x}, - {"ROR", addr_absolute_x}, - {"???", addr_implied}, - {"BRA", addr_relative}, - {"STA", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"STY", addr_zeropage}, - {"STA", addr_zeropage}, - {"STX", addr_zeropage}, - {"???", addr_implied}, - {"DEY", addr_implied}, - {"BIT", addr_immediate}, - {"TXA", addr_implied}, - {"???", addr_implied}, - {"STY", addr_absolute}, - {"STA", addr_absolute}, - {"STX", addr_absolute}, - {"???", addr_implied}, - {"BCC", addr_relative}, - {"STA", addr_indirect_y}, - {"STA", addr_indirect}, - {"???", addr_implied}, - {"STY", addr_zeropage_x}, - {"STA", addr_zeropage_x}, - {"STX", addr_zeropage_y}, - {"???", addr_implied}, - {"TYA", addr_implied}, - {"STA", addr_absolute_y}, - {"TXS", addr_implied}, - {"???", addr_implied}, - {"STZ", addr_absolute}, - {"STA", addr_absolute_x}, - {"STZ", addr_absolute_x}, - {"???", addr_implied}, - {"LDY", addr_immediate}, - {"LDA", addr_indirect_x}, - {"LDX", addr_immediate}, - {"???", addr_implied}, - {"LDY", addr_zeropage}, - {"LDA", addr_zeropage}, - {"LDX", addr_zeropage}, - {"???", addr_implied}, - {"TAY", addr_implied}, - {"LDA", addr_immediate}, - {"TAX", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_absolute}, - {"LDA", addr_absolute}, - {"LDX", addr_absolute}, - {"???", addr_implied}, - {"BCS", addr_relative}, - {"LDA", addr_indirect_y}, - {"LDA", addr_indirect}, - {"???", addr_implied}, - {"LDY", addr_zeropage_x}, - {"LDA", addr_zeropage_x}, - {"LDX", addr_zeropage_y}, - {"???", addr_implied}, - {"CLV", addr_implied}, - {"LDA", addr_absolute_y}, - {"TSX", addr_implied}, - {"???", addr_implied}, - {"LDY", addr_absolute_x}, - {"LDA", addr_absolute_x}, - {"LDX", addr_absolute_y}, - {"???", addr_implied}, - {"CPY", addr_immediate}, - {"CMP", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CPY", addr_zeropage}, - {"CMP", addr_zeropage}, - {"DEC", addr_zeropage}, - {"???", addr_implied}, - {"INY", addr_implied}, - {"CMP", addr_immediate}, - {"DEX", addr_implied}, - {"???", addr_implied}, - {"CPY", addr_absolute}, - {"CMP", addr_absolute}, - {"DEC", addr_absolute}, - {"???", addr_implied}, - {"BNE", addr_relative}, - {"CMP", addr_indirect_y}, - {"CMP", addr_indirect}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CMP", addr_zeropage_x}, - {"DEC", addr_zeropage_x}, - {"???", addr_implied}, - {"CLD", addr_implied}, - {"CMP", addr_absolute_y}, - {"PHX", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CMP", addr_absolute_x}, - {"DEC", addr_absolute_x}, - {"???", addr_implied}, - {"CPX", addr_immediate}, - {"SBC", addr_indirect_x}, - {"???", addr_implied}, - {"???", addr_implied}, - {"CPX", addr_zeropage}, - {"SBC", addr_zeropage}, - {"INC", addr_zeropage}, - {"???", addr_implied}, - {"INX", addr_implied}, - {"SBC", addr_immediate}, - {"NOP", addr_implied}, - {"???", addr_implied}, - {"CPX", addr_absolute}, - {"SBC", addr_absolute}, - {"INC", addr_absolute}, - {"???", addr_implied}, - {"BEQ", addr_relative}, - {"SBC", addr_indirect_y}, - {"SBC", addr_indirect}, - {"???", addr_implied}, - {"???", addr_implied}, - {"SBC", addr_zeropage_x}, - {"INC", addr_zeropage_x}, - {"???", addr_implied}, - {"SED", addr_implied}, - {"SBC", addr_absolute_y}, - {"PLX", addr_implied}, - {"???", addr_implied}, - {"???", addr_implied}, - {"SBC", addr_absolute_x}, - {"INC", addr_absolute_x}, - {"???", addr_implied}, + { "BRK", addr_implied }, + { "ORA", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "TSB", addr_zeropage }, + { "ORA", addr_zeropage }, + { "ASL", addr_zeropage }, + { "???", addr_implied }, + { "PHP", addr_implied }, + { "ORA", addr_immediate }, + { "ASL", addr_accumulator }, + { "???", addr_implied }, + { "TSB", addr_absolute }, + { "ORA", addr_absolute }, + { "ASL", addr_absolute }, + { "???", addr_implied }, + { "BPL", addr_relative }, + { "ORA", addr_indirect_y }, + { "ORA", addr_indirect }, + { "???", addr_implied }, + { "TRB", addr_zeropage }, + { "ORA", addr_zeropage_x }, + { "ASL", addr_zeropage_x }, + { "???", addr_implied }, + { "CLC", addr_implied }, + { "ORA", addr_absolute_y }, + { "INC", addr_accumulator }, + { "???", addr_implied }, + { "TRB", addr_absolute }, + { "ORA", addr_absolute_x }, + { "ASL", addr_absolute_x }, + { "???", addr_implied }, + { "JSR", addr_absolute }, + { "AND", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "BIT", addr_zeropage }, + { "AND", addr_zeropage }, + { "ROL", addr_zeropage }, + { "???", addr_implied }, + { "PLP", addr_implied }, + { "AND", addr_immediate }, + { "ROL", addr_accumulator }, + { "???", addr_implied }, + { "BIT", addr_absolute }, + { "AND", addr_absolute }, + { "ROL", addr_absolute }, + { "???", addr_implied }, + { "BMI", addr_relative }, + { "AND", addr_indirect_y }, + { "AND", addr_indirect }, + { "???", addr_implied }, + { "BIT", addr_zeropage_x }, + { "AND", addr_zeropage_x }, + { "ROL", addr_zeropage_x }, + { "???", addr_implied }, + { "SEC", addr_implied }, + { "AND", addr_absolute_y }, + { "DEC", addr_accumulator }, + { "???", addr_implied }, + { "BIT", addr_absolute_x }, + { "AND", addr_absolute_x }, + { "ROL", addr_absolute_x }, + { "???", addr_implied }, + { "RTI", addr_implied }, + { "EOR", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_zeropage }, + { "LSR", addr_zeropage }, + { "???", addr_implied }, + { "PHA", addr_implied }, + { "EOR", addr_immediate }, + { "LSR", addr_accumulator }, + { "???", addr_implied }, + { "JMP", addr_absolute }, + { "EOR", addr_absolute }, + { "LSR", addr_absolute }, + { "???", addr_implied }, + { "BVC", addr_relative }, + { "EOR", addr_indirect_y }, + { "EOR", addr_indirect }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_zeropage_x }, + { "LSR", addr_zeropage_x }, + { "???", addr_implied }, + { "CLI", addr_implied }, + { "EOR", addr_absolute_y }, + { "PHY", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "EOR", addr_absolute_x }, + { "LSR", addr_absolute_x }, + { "???", addr_implied }, + { "RTS", addr_implied }, + { "ADC", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STZ", addr_zeropage }, + { "ADC", addr_zeropage }, + { "ROR", addr_zeropage }, + { "???", addr_implied }, + { "PLA", addr_implied }, + { "ADC", addr_immediate }, + { "ROR", addr_accumulator }, + { "???", addr_implied }, + { "JMP", addr_j_indirect }, + { "ADC", addr_absolute }, + { "ROR", addr_absolute }, + { "???", addr_implied }, + { "BVS", addr_relative }, + { "ADC", addr_indirect_y }, + { "ADC", addr_indirect }, + { "???", addr_implied }, + { "STZ", addr_zeropage_x }, + { "ADC", addr_zeropage_x }, + { "ROR", addr_zeropage_x }, + { "???", addr_implied }, + { "SEI", addr_implied }, + { "ADC", addr_absolute_y }, + { "PLY", addr_implied }, + { "???", addr_implied }, + { "JMP", addr_j_indirect_x }, + { "ADC", addr_absolute_x }, + { "ROR", addr_absolute_x }, + { "???", addr_implied }, + { "BRA", addr_relative }, + { "STA", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "STY", addr_zeropage }, + { "STA", addr_zeropage }, + { "STX", addr_zeropage }, + { "???", addr_implied }, + { "DEY", addr_implied }, + { "BIT", addr_immediate }, + { "TXA", addr_implied }, + { "???", addr_implied }, + { "STY", addr_absolute }, + { "STA", addr_absolute }, + { "STX", addr_absolute }, + { "???", addr_implied }, + { "BCC", addr_relative }, + { "STA", addr_indirect_y }, + { "STA", addr_indirect }, + { "???", addr_implied }, + { "STY", addr_zeropage_x }, + { "STA", addr_zeropage_x }, + { "STX", addr_zeropage_y }, + { "???", addr_implied }, + { "TYA", addr_implied }, + { "STA", addr_absolute_y }, + { "TXS", addr_implied }, + { "???", addr_implied }, + { "STZ", addr_absolute }, + { "STA", addr_absolute_x }, + { "STZ", addr_absolute_x }, + { "???", addr_implied }, + { "LDY", addr_immediate }, + { "LDA", addr_indirect_x }, + { "LDX", addr_immediate }, + { "???", addr_implied }, + { "LDY", addr_zeropage }, + { "LDA", addr_zeropage }, + { "LDX", addr_zeropage }, + { "???", addr_implied }, + { "TAY", addr_implied }, + { "LDA", addr_immediate }, + { "TAX", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_absolute }, + { "LDA", addr_absolute }, + { "LDX", addr_absolute }, + { "???", addr_implied }, + { "BCS", addr_relative }, + { "LDA", addr_indirect_y }, + { "LDA", addr_indirect }, + { "???", addr_implied }, + { "LDY", addr_zeropage_x }, + { "LDA", addr_zeropage_x }, + { "LDX", addr_zeropage_y }, + { "???", addr_implied }, + { "CLV", addr_implied }, + { "LDA", addr_absolute_y }, + { "TSX", addr_implied }, + { "???", addr_implied }, + { "LDY", addr_absolute_x }, + { "LDA", addr_absolute_x }, + { "LDX", addr_absolute_y }, + { "???", addr_implied }, + { "CPY", addr_immediate }, + { "CMP", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CPY", addr_zeropage }, + { "CMP", addr_zeropage }, + { "DEC", addr_zeropage }, + { "???", addr_implied }, + { "INY", addr_implied }, + { "CMP", addr_immediate }, + { "DEX", addr_implied }, + { "???", addr_implied }, + { "CPY", addr_absolute }, + { "CMP", addr_absolute }, + { "DEC", addr_absolute }, + { "???", addr_implied }, + { "BNE", addr_relative }, + { "CMP", addr_indirect_y }, + { "CMP", addr_indirect }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CMP", addr_zeropage_x }, + { "DEC", addr_zeropage_x }, + { "???", addr_implied }, + { "CLD", addr_implied }, + { "CMP", addr_absolute_y }, + { "PHX", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CMP", addr_absolute_x }, + { "DEC", addr_absolute_x }, + { "???", addr_implied }, + { "CPX", addr_immediate }, + { "SBC", addr_indirect_x }, + { "???", addr_implied }, + { "???", addr_implied }, + { "CPX", addr_zeropage }, + { "SBC", addr_zeropage }, + { "INC", addr_zeropage }, + { "???", addr_implied }, + { "INX", addr_implied }, + { "SBC", addr_immediate }, + { "NOP", addr_implied }, + { "???", addr_implied }, + { "CPX", addr_absolute }, + { "SBC", addr_absolute }, + { "INC", addr_absolute }, + { "???", addr_implied }, + { "BEQ", addr_relative }, + { "SBC", addr_indirect_y }, + { "SBC", addr_indirect }, + { "???", addr_implied }, + { "???", addr_implied }, + { "SBC", addr_zeropage_x }, + { "INC", addr_zeropage_x }, + { "???", addr_implied }, + { "SED", addr_implied }, + { "SBC", addr_absolute_y }, + { "PLX", addr_implied }, + { "???", addr_implied }, + { "???", addr_implied }, + { "SBC", addr_absolute_x }, + { "INC", addr_absolute_x }, + { "???", addr_implied }, }; #endif /* APPLE_IIE */ -const struct opcode_struct opcodes_undoc[256] = +const struct opcode_struct opcodes_undoc[256] = { - {"BRK", addr_implied}, - {"ORA", addr_indirect_x}, - {"hang", addr_implied}, - {"lor", addr_indirect_x}, - {"nop", addr_zeropage}, - {"ORA", addr_zeropage}, - {"ASL", addr_zeropage}, - {"lor", addr_zeropage}, - {"PHP", addr_implied}, - {"ORA", addr_immediate}, - {"ASL", addr_accumulator}, - {"ana", addr_immediate}, - {"nop", addr_absolute}, - {"ORA", addr_absolute}, - {"ASL", addr_absolute}, - {"lor", addr_absolute}, - {"BPL", addr_relative}, - {"ORA", addr_indirect_y}, - {"hang", addr_implied}, - {"lor", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"ORA", addr_zeropage_x}, - {"ASL", addr_zeropage_x}, - {"lor", addr_zeropage_x}, - {"CLC", addr_implied}, - {"ORA", addr_absolute_y}, - {"nop", addr_implied}, - {"lor", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"ORA", addr_absolute_x}, - {"ASL", addr_absolute_x}, - {"lor", addr_absolute}, - {"JSR", addr_absolute}, - {"AND", addr_indirect_x}, - {"hang", addr_implied}, - {"lan", addr_indirect_x}, - {"BIT", addr_zeropage}, - {"AND", addr_zeropage}, - {"ROL", addr_zeropage}, - {"lan", addr_zeropage}, - {"PLP", addr_implied}, - {"AND", addr_immediate}, - {"ROL", addr_accumulator}, - {"anb", addr_immediate}, - {"BIT", addr_absolute}, - {"AND", addr_absolute}, - {"ROL", addr_absolute}, - {"lan", addr_absolute}, - {"BMI", addr_relative}, - {"AND", addr_indirect_y}, - {"hang", addr_implied}, - {"lan", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"AND", addr_zeropage_x}, - {"ROL", addr_zeropage_x}, - {"lan", addr_zeropage_x}, - {"SEC", addr_implied}, - {"AND", addr_absolute_y}, - {"nop", addr_implied}, - {"lan", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"AND", addr_absolute_x}, - {"ROL", addr_absolute_x}, - {"lan", addr_absolute_x}, - {"RTI", addr_implied}, - {"EOR", addr_indirect_x}, - {"hang", addr_implied}, - {"reo", addr_indirect_x}, - {"nop", addr_zeropage}, - {"EOR", addr_zeropage}, - {"LSR", addr_zeropage}, - {"reo", addr_zeropage}, - {"PHA", addr_implied}, - {"EOR", addr_immediate}, - {"LSR", addr_accumulator}, - {"ram", addr_immediate}, - {"JMP", addr_absolute}, - {"EOR", addr_absolute}, - {"LSR", addr_absolute}, - {"reo", addr_absolute}, - {"BVC", addr_relative}, - {"EOR", addr_indirect_y}, - {"hang", addr_implied}, - {"reo", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"EOR", addr_zeropage_x}, - {"LSR", addr_zeropage_x}, - {"reo", addr_zeropage_x}, - {"CLI", addr_implied}, - {"EOR", addr_absolute_y}, - {"nop", addr_implied}, - {"reo", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"EOR", addr_absolute_x}, - {"LSR", addr_absolute_x}, - {"reo", addr_absolute_x}, - {"RTS", addr_implied}, - {"ADC", addr_indirect_x}, - {"hang", addr_implied}, - {"rad", addr_indirect_x}, - {"nop", addr_zeropage}, - {"ADC", addr_zeropage}, - {"ROR", addr_zeropage}, - {"rad", addr_zeropage}, - {"PLA", addr_implied}, - {"ADC", addr_immediate}, - {"ROR", addr_accumulator}, - {"rbm", addr_immediate}, - {"JMP", addr_j_indirect}, - {"ADC", addr_absolute}, - {"ROR", addr_absolute}, - {"rad", addr_absolute}, - {"BVS", addr_relative}, - {"ADC", addr_indirect_y}, - {"hang", addr_implied}, - {"rad", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"ADC", addr_zeropage_x}, - {"ROR", addr_zeropage_x}, - {"rad", addr_zeropage_x}, - {"SEI", addr_implied}, - {"ADC", addr_absolute_y}, - {"nop", addr_implied}, - {"rad", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"ADC", addr_absolute_x}, - {"ROR", addr_absolute_x}, - {"rad", addr_absolute_x}, - {"nop", addr_immediate}, - {"STA", addr_indirect_x}, - {"nop", addr_immediate}, - {"aax", addr_indirect_x}, - {"STY", addr_zeropage}, - {"STA", addr_zeropage}, - {"STX", addr_zeropage}, - {"aax", addr_zeropage}, - {"DEY", addr_implied}, - {"nop", addr_immediate}, - {"TXA", addr_implied}, - {"xma", addr_immediate}, - {"STY", addr_absolute}, - {"STA", addr_absolute}, - {"STX", addr_absolute}, - {"aax", addr_absolute}, - {"BCC", addr_relative}, - {"STA", addr_indirect_y}, - {"hang", addr_implied}, - {"aax", addr_indirect_y}, - {"STY", addr_zeropage_x}, - {"STA", addr_zeropage_x}, - {"STX", addr_zeropage_y}, - {"aax", addr_zeropage_y}, - {"TYA", addr_implied}, - {"STA", addr_absolute_y}, - {"TXS", addr_implied}, - {"axs", addr_absolute_y}, - {"tey", addr_absolute_x}, - {"STA", addr_absolute_x}, - {"tex", addr_absolute_y}, - {"tea", addr_absolute_y}, - {"LDY", addr_immediate}, - {"LDA", addr_indirect_x}, - {"LDX", addr_immediate}, - {"lax", addr_indirect_x}, - {"LDY", addr_zeropage}, - {"LDA", addr_zeropage}, - {"LDX", addr_zeropage}, - {"lax", addr_zeropage}, - {"TAY", addr_implied}, - {"LDA", addr_immediate}, - {"TAX", addr_implied}, - {"ama", addr_immediate}, - {"LDY", addr_absolute}, - {"LDA", addr_absolute}, - {"LDX", addr_absolute}, - {"lax", addr_absolute}, - {"BCS", addr_relative}, - {"LDA", addr_indirect_y}, - {"hang", addr_implied}, - {"lax", addr_indirect_y}, - {"LDY", addr_zeropage_x}, - {"LDA", addr_zeropage_x}, - {"LDX", addr_zeropage_y}, - {"laz", addr_zeropage_y}, - {"CLV", addr_implied}, - {"LDA", addr_absolute_y}, - {"TSX", addr_implied}, - {"las", addr_absolute_y}, - {"LDY", addr_absolute_x}, - {"LDA", addr_absolute_x}, - {"LDX", addr_absolute_y}, - {"lax", addr_absolute_y}, - {"CPY", addr_immediate}, - {"CMP", addr_indirect_x}, - {"nop", addr_immediate}, - {"dcp", addr_indirect_x}, - {"CPY", addr_zeropage}, - {"CMP", addr_zeropage}, - {"DEC", addr_zeropage}, - {"dcp", addr_zeropage}, - {"INY", addr_implied}, - {"CMP", addr_immediate}, - {"DEX", addr_implied}, - {"axm", addr_immediate}, - {"CPY", addr_absolute}, - {"CMP", addr_absolute}, - {"DEC", addr_absolute}, - {"dcp", addr_absolute}, - {"BNE", addr_relative}, - {"CMP", addr_indirect_y}, - {"hang", addr_implied}, - {"dcp", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"CMP", addr_zeropage_x}, - {"DEC", addr_zeropage_x}, - {"dcp", addr_zeropage_x}, - {"CLD", addr_implied}, - {"CMP", addr_absolute_y}, - {"nop", addr_implied}, - {"dcp", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"CMP", addr_absolute_x}, - {"DEC", addr_absolute_x}, - {"dcp", addr_absolute_x}, - {"CPX", addr_immediate}, - {"SBC", addr_indirect_x}, - {"nop", addr_immediate}, - {"isb", addr_indirect_x}, - {"CPX", addr_zeropage}, - {"SBC", addr_zeropage}, - {"INC", addr_zeropage}, - {"isb", addr_zeropage}, - {"INX", addr_implied}, - {"SBC", addr_immediate}, - {"NOP", addr_implied}, - {"zbc", addr_immediate}, - {"CPX", addr_absolute}, - {"SBC", addr_absolute}, - {"INC", addr_absolute}, - {"isb", addr_absolute}, - {"BEQ", addr_relative}, - {"SBC", addr_indirect_y}, - {"hang", addr_implied}, - {"isb", addr_indirect_y}, - {"nop", addr_zeropage_x}, - {"SBC", addr_zeropage_x}, - {"INC", addr_zeropage_x}, - {"isb", addr_zeropage_x}, - {"SED", addr_implied}, - {"SBC", addr_absolute_y}, - {"nop", addr_implied}, - {"isb", addr_absolute_y}, - {"nop", addr_absolute_x}, - {"SBC", addr_absolute_x}, - {"INC", addr_absolute_x}, - {"isb", addr_absolute_x}, + { "BRK", addr_implied }, + { "ORA", addr_indirect_x }, + { "hang", addr_implied }, + { "lor", addr_indirect_x }, + { "nop", addr_zeropage }, + { "ORA", addr_zeropage }, + { "ASL", addr_zeropage }, + { "lor", addr_zeropage }, + { "PHP", addr_implied }, + { "ORA", addr_immediate }, + { "ASL", addr_accumulator }, + { "ana", addr_immediate }, + { "nop", addr_absolute }, + { "ORA", addr_absolute }, + { "ASL", addr_absolute }, + { "lor", addr_absolute }, + { "BPL", addr_relative }, + { "ORA", addr_indirect_y }, + { "hang", addr_implied }, + { "lor", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "ORA", addr_zeropage_x }, + { "ASL", addr_zeropage_x }, + { "lor", addr_zeropage_x }, + { "CLC", addr_implied }, + { "ORA", addr_absolute_y }, + { "nop", addr_implied }, + { "lor", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "ORA", addr_absolute_x }, + { "ASL", addr_absolute_x }, + { "lor", addr_absolute }, + { "JSR", addr_absolute }, + { "AND", addr_indirect_x }, + { "hang", addr_implied }, + { "lan", addr_indirect_x }, + { "BIT", addr_zeropage }, + { "AND", addr_zeropage }, + { "ROL", addr_zeropage }, + { "lan", addr_zeropage }, + { "PLP", addr_implied }, + { "AND", addr_immediate }, + { "ROL", addr_accumulator }, + { "anb", addr_immediate }, + { "BIT", addr_absolute }, + { "AND", addr_absolute }, + { "ROL", addr_absolute }, + { "lan", addr_absolute }, + { "BMI", addr_relative }, + { "AND", addr_indirect_y }, + { "hang", addr_implied }, + { "lan", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "AND", addr_zeropage_x }, + { "ROL", addr_zeropage_x }, + { "lan", addr_zeropage_x }, + { "SEC", addr_implied }, + { "AND", addr_absolute_y }, + { "nop", addr_implied }, + { "lan", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "AND", addr_absolute_x }, + { "ROL", addr_absolute_x }, + { "lan", addr_absolute_x }, + { "RTI", addr_implied }, + { "EOR", addr_indirect_x }, + { "hang", addr_implied }, + { "reo", addr_indirect_x }, + { "nop", addr_zeropage }, + { "EOR", addr_zeropage }, + { "LSR", addr_zeropage }, + { "reo", addr_zeropage }, + { "PHA", addr_implied }, + { "EOR", addr_immediate }, + { "LSR", addr_accumulator }, + { "ram", addr_immediate }, + { "JMP", addr_absolute }, + { "EOR", addr_absolute }, + { "LSR", addr_absolute }, + { "reo", addr_absolute }, + { "BVC", addr_relative }, + { "EOR", addr_indirect_y }, + { "hang", addr_implied }, + { "reo", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "EOR", addr_zeropage_x }, + { "LSR", addr_zeropage_x }, + { "reo", addr_zeropage_x }, + { "CLI", addr_implied }, + { "EOR", addr_absolute_y }, + { "nop", addr_implied }, + { "reo", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "EOR", addr_absolute_x }, + { "LSR", addr_absolute_x }, + { "reo", addr_absolute_x }, + { "RTS", addr_implied }, + { "ADC", addr_indirect_x }, + { "hang", addr_implied }, + { "rad", addr_indirect_x }, + { "nop", addr_zeropage }, + { "ADC", addr_zeropage }, + { "ROR", addr_zeropage }, + { "rad", addr_zeropage }, + { "PLA", addr_implied }, + { "ADC", addr_immediate }, + { "ROR", addr_accumulator }, + { "rbm", addr_immediate }, + { "JMP", addr_j_indirect }, + { "ADC", addr_absolute }, + { "ROR", addr_absolute }, + { "rad", addr_absolute }, + { "BVS", addr_relative }, + { "ADC", addr_indirect_y }, + { "hang", addr_implied }, + { "rad", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "ADC", addr_zeropage_x }, + { "ROR", addr_zeropage_x }, + { "rad", addr_zeropage_x }, + { "SEI", addr_implied }, + { "ADC", addr_absolute_y }, + { "nop", addr_implied }, + { "rad", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "ADC", addr_absolute_x }, + { "ROR", addr_absolute_x }, + { "rad", addr_absolute_x }, + { "nop", addr_immediate }, + { "STA", addr_indirect_x }, + { "nop", addr_immediate }, + { "aax", addr_indirect_x }, + { "STY", addr_zeropage }, + { "STA", addr_zeropage }, + { "STX", addr_zeropage }, + { "aax", addr_zeropage }, + { "DEY", addr_implied }, + { "nop", addr_immediate }, + { "TXA", addr_implied }, + { "xma", addr_immediate }, + { "STY", addr_absolute }, + { "STA", addr_absolute }, + { "STX", addr_absolute }, + { "aax", addr_absolute }, + { "BCC", addr_relative }, + { "STA", addr_indirect_y }, + { "hang", addr_implied }, + { "aax", addr_indirect_y }, + { "STY", addr_zeropage_x }, + { "STA", addr_zeropage_x }, + { "STX", addr_zeropage_y }, + { "aax", addr_zeropage_y }, + { "TYA", addr_implied }, + { "STA", addr_absolute_y }, + { "TXS", addr_implied }, + { "axs", addr_absolute_y }, + { "tey", addr_absolute_x }, + { "STA", addr_absolute_x }, + { "tex", addr_absolute_y }, + { "tea", addr_absolute_y }, + { "LDY", addr_immediate }, + { "LDA", addr_indirect_x }, + { "LDX", addr_immediate }, + { "lax", addr_indirect_x }, + { "LDY", addr_zeropage }, + { "LDA", addr_zeropage }, + { "LDX", addr_zeropage }, + { "lax", addr_zeropage }, + { "TAY", addr_implied }, + { "LDA", addr_immediate }, + { "TAX", addr_implied }, + { "ama", addr_immediate }, + { "LDY", addr_absolute }, + { "LDA", addr_absolute }, + { "LDX", addr_absolute }, + { "lax", addr_absolute }, + { "BCS", addr_relative }, + { "LDA", addr_indirect_y }, + { "hang", addr_implied }, + { "lax", addr_indirect_y }, + { "LDY", addr_zeropage_x }, + { "LDA", addr_zeropage_x }, + { "LDX", addr_zeropage_y }, + { "laz", addr_zeropage_y }, + { "CLV", addr_implied }, + { "LDA", addr_absolute_y }, + { "TSX", addr_implied }, + { "las", addr_absolute_y }, + { "LDY", addr_absolute_x }, + { "LDA", addr_absolute_x }, + { "LDX", addr_absolute_y }, + { "lax", addr_absolute_y }, + { "CPY", addr_immediate }, + { "CMP", addr_indirect_x }, + { "nop", addr_immediate }, + { "dcp", addr_indirect_x }, + { "CPY", addr_zeropage }, + { "CMP", addr_zeropage }, + { "DEC", addr_zeropage }, + { "dcp", addr_zeropage }, + { "INY", addr_implied }, + { "CMP", addr_immediate }, + { "DEX", addr_implied }, + { "axm", addr_immediate }, + { "CPY", addr_absolute }, + { "CMP", addr_absolute }, + { "DEC", addr_absolute }, + { "dcp", addr_absolute }, + { "BNE", addr_relative }, + { "CMP", addr_indirect_y }, + { "hang", addr_implied }, + { "dcp", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "CMP", addr_zeropage_x }, + { "DEC", addr_zeropage_x }, + { "dcp", addr_zeropage_x }, + { "CLD", addr_implied }, + { "CMP", addr_absolute_y }, + { "nop", addr_implied }, + { "dcp", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "CMP", addr_absolute_x }, + { "DEC", addr_absolute_x }, + { "dcp", addr_absolute_x }, + { "CPX", addr_immediate }, + { "SBC", addr_indirect_x }, + { "nop", addr_immediate }, + { "isb", addr_indirect_x }, + { "CPX", addr_zeropage }, + { "SBC", addr_zeropage }, + { "INC", addr_zeropage }, + { "isb", addr_zeropage }, + { "INX", addr_implied }, + { "SBC", addr_immediate }, + { "NOP", addr_implied }, + { "zbc", addr_immediate }, + { "CPX", addr_absolute }, + { "SBC", addr_absolute }, + { "INC", addr_absolute }, + { "isb", addr_absolute }, + { "BEQ", addr_relative }, + { "SBC", addr_indirect_y }, + { "hang", addr_implied }, + { "isb", addr_indirect_y }, + { "nop", addr_zeropage_x }, + { "SBC", addr_zeropage_x }, + { "INC", addr_zeropage_x }, + { "isb", addr_zeropage_x }, + { "SED", addr_implied }, + { "SBC", addr_absolute_y }, + { "nop", addr_implied }, + { "isb", addr_absolute_y }, + { "nop", addr_absolute_x }, + { "SBC", addr_absolute_x }, + { "INC", addr_absolute_x }, + { "isb", addr_absolute_x }, }; diff --git a/src/prefs.c b/src/prefs.c index 647c6162..6b81daed 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Preferences file maintenance * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -27,19 +27,19 @@ #include "interface.h" #include "cpu.h" -#define PRM_NONE 0 -#define PRM_SPEED 1 -#define PRM_MODE 2 -#define PRM_DISK_PATH 3 -#define PRM_HIRES_COLOR 4 -#define PRM_SOUND 5 -#define PRM_JOY_INPUT 6 -#define PRM_JOY_RANGE 7 -#define PRM_JOY_OX 8 -#define PRM_JOY_OY 9 -#define PRM_JOY_PC_CALIBRATE 10 -#define PRM_JOY_KYBD_SENSITIVITY 11 -#define PRM_ROM_PATH 12 +#define PRM_NONE 0 +#define PRM_SPEED 1 +#define PRM_MODE 2 +#define PRM_DISK_PATH 3 +#define PRM_HIRES_COLOR 4 +#define PRM_SOUND 5 +#define PRM_JOY_INPUT 6 +#define PRM_JOY_RANGE 7 +#define PRM_JOY_OX 8 +#define PRM_JOY_OY 9 +#define PRM_JOY_PC_CALIBRATE 10 +#define PRM_JOY_KYBD_SENSITIVITY 11 +#define PRM_ROM_PATH 12 char system_path[SYSSIZE]; @@ -68,345 +68,408 @@ int js_min_y; static char *config_filename; struct match_table - { +{ const char *tag; int value; - }; +}; static const struct match_table prefs_table[] = { - {"speed", PRM_SPEED}, - {"mode", PRM_MODE}, - {"path", PRM_DISK_PATH}, - {"disk path", PRM_DISK_PATH}, - {"disk_path", PRM_DISK_PATH}, - {"path", PRM_DISK_PATH}, - {"color", PRM_HIRES_COLOR}, - {"sound", PRM_SOUND}, - {"joystick", PRM_JOY_INPUT}, - {"joy range", PRM_JOY_RANGE}, - {"joystick range", PRM_JOY_RANGE}, - {"joy_range", PRM_JOY_RANGE}, - {"origin_x", PRM_JOY_OX}, - {"origin_y", PRM_JOY_OY}, - {"pc joystick parms", PRM_JOY_PC_CALIBRATE}, - {"pc_joystick_parms", PRM_JOY_PC_CALIBRATE}, - {"sensitivity", PRM_JOY_KYBD_SENSITIVITY}, - {"system path", PRM_ROM_PATH}, - {"system_path", PRM_ROM_PATH}, - {0, PRM_NONE} + { "speed", PRM_SPEED }, + { "mode", PRM_MODE }, + { "path", PRM_DISK_PATH }, + { "disk path", PRM_DISK_PATH }, + { "disk_path", PRM_DISK_PATH }, + { "path", PRM_DISK_PATH }, + { "color", PRM_HIRES_COLOR }, + { "sound", PRM_SOUND }, + { "joystick", PRM_JOY_INPUT }, + { "joy range", PRM_JOY_RANGE }, + { "joystick range", PRM_JOY_RANGE }, + { "joy_range", PRM_JOY_RANGE }, + { "origin_x", PRM_JOY_OX }, + { "origin_y", PRM_JOY_OY }, + { "pc joystick parms", PRM_JOY_PC_CALIBRATE }, + { "pc_joystick_parms", PRM_JOY_PC_CALIBRATE }, + { "sensitivity", PRM_JOY_KYBD_SENSITIVITY }, + { "system path", PRM_ROM_PATH }, + { "system_path", PRM_ROM_PATH }, + { 0, PRM_NONE } }; static const struct match_table modes_table[] = { - {"][+", II_MODE}, - {"][+ undocumented", IIU_MODE}, + { "][+", II_MODE }, + { "][+ undocumented", IIU_MODE }, #ifdef APPLE_IIE - {"//e", IIE_MODE}, - {0, IIE_MODE} + { "//e", IIE_MODE }, + { 0, IIE_MODE } #else /* !APPLE_IIE */ - {0, IIU_MODE} + { 0, IIU_MODE } #endif /* !APPLE_IIE */ }; static const struct match_table color_table[] = { - {"black/white", NO_COLOR}, - {"lazy color", LAZY_COLOR}, - {"color", COLOR}, - {"lazy interpolated", LAZY_INTERP}, - {"interpolated", INTERP}, - {"off", 0}, - {"on", COLOR}, - {0, COLOR} + { "black/white", NO_COLOR }, + { "lazy color", LAZY_COLOR }, + { "color", COLOR }, + { "lazy interpolated", LAZY_INTERP }, + { "interpolated", INTERP }, + { "off", 0 }, + { "on", COLOR }, + { 0, COLOR } }; static const struct match_table sound_table[] = { - {"off", 0}, - {"pc_speaker", 1}, - {"on", 1}, - {0, 1}, + { "off", 0 }, + { "pc_speaker", 1 }, + { "on", 1 }, + { 0, 1 }, }; static const struct match_table joy_input_table[] = { - {"off", JOY_OFF}, - {"keyboard", JOY_KYBD}, - {"linear", JOY_KYBD}, + { "off", JOY_OFF }, + { "keyboard", JOY_KYBD }, + { "linear", JOY_KYBD }, #ifdef PC_JOYSTICK - {"pc joystick", JOY_PCJOY}, - {"pc_joystick", JOY_PCJOY}, -#endif /* PC_JOYSTICK */ + { "pc joystick", JOY_PCJOY }, + { "pc_joystick", JOY_PCJOY }, +#endif /* PC_JOYSTICK */ #if 0 - {"digital", JOY_DIGITAL}, -#endif /* 0 */ - {0, JOY_KYBD} + { "digital", JOY_DIGITAL }, +#endif /* 0 */ + { 0, JOY_KYBD } }; /* Find the number assigned to KEYWORD in a match table PARADIGM. If no match, - * then the value associated with the terminating entry is used as a + * then the value associated with the terminating entry is used as a * default. */ -static int -match (const struct match_table *paradigm, const char *keyword) +static int +match(const struct match_table *paradigm, const char *keyword) { - while (paradigm->tag && strcasecmp (paradigm->tag, keyword)) - paradigm++; - return paradigm->value; + while (paradigm->tag && strcasecmp(paradigm->tag, keyword)) + { + paradigm++; + } + + return paradigm->value; } -/* Reverse match -- find a keyword associated with number KEY in - * PARADIGM. The first match is used -- synonym keywords appearing later +/* Reverse match -- find a keyword associated with number KEY in + * PARADIGM. The first match is used -- synonym keywords appearing later * in the table are not chosen. * - * A null is returned for no match. + * A null is returned for no match. */ -static const char *reverse_match (const struct match_table *paradigm, int key) +static const char *reverse_match(const struct match_table *paradigm, int key) { - while (paradigm->tag && key != paradigm->value) - paradigm++; - return paradigm->tag; + while (paradigm->tag && key != paradigm->value) + { + paradigm++; + } + + return paradigm->tag; } -/* Eat leading and trailing whitespace of string X. The old string is - * overwritten and a new pointer is returned. +/* Eat leading and trailing whitespace of string X. The old string is + * overwritten and a new pointer is returned. */ static char * -clean_string (char *x) +clean_string(char *x) { - size_t y; + size_t y; - /* Leading white space */ - while (isspace (*x)) x++; + /* Leading white space */ + while (isspace(*x)) + { + x++; + } - /* Trailing white space */ - y = strlen (x); - while (y && x[y--] == ' '); - x[y] = 0; + /* Trailing white space */ + y = strlen(x); + while (y && x[y--] == ' ') + { + } - return x; + x[y] = 0; + + return x; } /* Load the configuration. Must be called *once* at start. */ void -load_settings (void) +load_settings(void) { - /* set system defaults before user defaults. */ - strcpy (disk_path, "./disks"); - strcpy (system_path, "./rom"); + /* set system defaults before user defaults. */ + strcpy(disk_path, "./disks"); + strcpy(system_path, "./rom"); - { - const char *homedir; + { + const char *homedir; - homedir = getenv ("HOME"); - config_filename = malloc (strlen (homedir) + 9); - strcpy (config_filename, homedir); - strcat (config_filename, "/.apple2"); + homedir = getenv("HOME"); + config_filename = malloc(strlen(homedir) + 9); + strcpy(config_filename, homedir); + strcat(config_filename, "/.apple2"); - /* config_filename is left allocated for convinence in - * save_settings */ - } + /* config_filename is left allocated for convinence in + * save_settings */ + } - { - FILE *config_file; - char *buffer = 0; - size_t size = 0; + { + FILE *config_file; + char *buffer = 0; + size_t size = 0; - config_file = fopen (config_filename, "r"); - if (config_file == NULL) - { - printf ( - "Warning. Cannot open the .apple2 system defaults file.\n" - "Make sure it's readable in your home directory."); - printf ("Press RETURN to continue..."); - getchar (); - return; - } + config_file = fopen(config_filename, "r"); + if (config_file == NULL) + { + printf( + "Warning. Cannot open the .apple2 system defaults file.\n" + "Make sure it's readable in your home directory."); + printf("Press RETURN to continue..."); + getchar(); + return; + } - while (getline (&buffer, &size, config_file) != -1) - { - char *parameter; - char *argument; + while (getline(&buffer, &size, config_file) != -1) + { + char *parameter; + char *argument; - /* Split line between parameter and argument */ + /* Split line between parameter and argument */ - parameter = buffer; - argument = strchr (buffer, '='); - argument[0] = 0; - argument++; + parameter = buffer; + argument = strchr(buffer, '='); + argument[0] = 0; + argument++; - parameter = clean_string (parameter); - argument = clean_string (argument); + parameter = clean_string(parameter); + argument = clean_string(argument); - switch (match (prefs_table, parameter)) - { - case PRM_NONE: - fprintf (stderr, "Unrecognized config parameter `%s'", parameter); - break; + switch (match(prefs_table, parameter)) + { + case PRM_NONE: + fprintf(stderr, "Unrecognized config parameter `%s'", parameter); + break; - case PRM_SPEED: - { - int x; + case PRM_SPEED: + { + int x; - x = strtol (argument, 0, 0); + x = strtol(argument, 0, 0); - if (x < 0) - x = 0; + if (x < 0) + { + x = 0; + } - cpu65_delay = MAX_APPLE_DELAY - x + 1; - if (cpu65_delay < 1) - cpu65_delay = 1; - } - break; + cpu65_delay = MAX_APPLE_DELAY - x + 1; + if (cpu65_delay < 1) + { + cpu65_delay = 1; + } + } + break; - case PRM_MODE: - apple_mode = match (modes_table, argument); - break; + case PRM_MODE: + apple_mode = match(modes_table, argument); + break; - case PRM_DISK_PATH: - strncpy (disk_path, argument, DISKSIZE); - break; + case PRM_DISK_PATH: + strncpy(disk_path, argument, DISKSIZE); + break; - case PRM_HIRES_COLOR: - color_mode = match (color_table, argument); - break; + case PRM_HIRES_COLOR: + color_mode = match(color_table, argument); + break; - case PRM_SOUND: - sound_mode = match (sound_table, argument); - break; + case PRM_SOUND: + sound_mode = match(sound_table, argument); + break; - case PRM_JOY_INPUT: - joy_mode = match (joy_input_table, argument); - break; + case PRM_JOY_INPUT: + joy_mode = match(joy_input_table, argument); + break; - case PRM_JOY_RANGE: - joy_range = strtol (argument, 0, 0); - if (joy_range < 10) - joy_range = 10; - else if (joy_range > 256) - joy_range = 256; - half_joy_range = joy_range / 2; + case PRM_JOY_RANGE: + joy_range = strtol(argument, 0, 0); + if (joy_range < 10) + { + joy_range = 10; + } + else + if (joy_range > 256) + { + joy_range = 256; + } - if (joy_center_x > joy_range) - joy_center_x = half_joy_range; - if (joy_center_y > joy_range) - joy_center_y = half_joy_range; - break; + half_joy_range = joy_range / 2; - case PRM_JOY_OX: - joy_center_x = strtol (argument, 0, 0); - if (joy_center_x < 0) - joy_center_x = 0; - else if (joy_center_x > 255) - joy_center_x = 255; + if (joy_center_x > joy_range) + { + joy_center_x = half_joy_range; + } - if (joy_center_x > joy_range) - joy_center_x = half_joy_range; - break; + if (joy_center_y > joy_range) + { + joy_center_y = half_joy_range; + } - case PRM_JOY_OY: - joy_center_y = strtol (argument, 0, 0); - if (joy_center_y < 0) - joy_center_y = 0; - else if (joy_center_y > 255) - joy_center_y = 255; + break; - if (joy_center_y > joy_range) - joy_center_y = half_joy_range; - break; + case PRM_JOY_OX: + joy_center_x = strtol(argument, 0, 0); + if (joy_center_x < 0) + { + joy_center_x = 0; + } + else + if (joy_center_x > 255) + { + joy_center_x = 255; + } - case PRM_JOY_PC_CALIBRATE: + if (joy_center_x > joy_range) + { + joy_center_x = half_joy_range; + } + + break; + + case PRM_JOY_OY: + joy_center_y = strtol(argument, 0, 0); + if (joy_center_y < 0) + { + joy_center_y = 0; + } + else + if (joy_center_y > 255) + { + joy_center_y = 255; + } + + if (joy_center_y > joy_range) + { + joy_center_y = half_joy_range; + } + + break; + + case PRM_JOY_PC_CALIBRATE: #ifdef PC_JOYSTICK - /* pc joystick parms generated by the calibration routine - (shouldn't need to hand tweak these) = origin_x origin_y max_x - min_x max_y min_y js_timelimit */ - js_center_x = strtol (argument, &argument, 10); - js_center_y = strtol (argument, &argument, 10); - js_max_x = strtol (argument, &argument, 10); - if (js_max_x < 0) - js_max_x = 0; - js_min_x = strtol (argument, &argument, 10); - if (js_min_x < 0) - js_min_x = 0; + /* pc joystick parms generated by the calibration routine + (shouldn't need to hand tweak these) = origin_x origin_y max_x + min_x max_y min_y js_timelimit */ + js_center_x = strtol(argument, &argument, 10); + js_center_y = strtol(argument, &argument, 10); + js_max_x = strtol(argument, &argument, 10); + if (js_max_x < 0) + { + js_max_x = 0; + } - js_max_y = strtol (argument, &argument, 10); - if (js_max_y < 0) - js_max_y = 0; - js_min_y = strtol (argument, &argument, 10); - if (js_min_y < 0) - js_min_y = 0; + js_min_x = strtol(argument, &argument, 10); + if (js_min_x < 0) + { + js_min_x = 0; + } - js_timelimit = strtol (argument, &argument, 10); - if (js_timelimit < 2) - js_timelimit = 2; + js_max_y = strtol(argument, &argument, 10); + if (js_max_y < 0) + { + js_max_y = 0; + } - c_open_joystick (); - c_calculate_joystick_parms (); /* calculate the associated parms */ + js_min_y = strtol(argument, &argument, 10); + if (js_min_y < 0) + { + js_min_y = 0; + } + + js_timelimit = strtol(argument, &argument, 10); + if (js_timelimit < 2) + { + js_timelimit = 2; + } + + c_open_joystick(); + c_calculate_joystick_parms(); /* calculate the associated parms */ #endif - case PRM_JOY_KYBD_SENSITIVITY: - joy_step = strtol (argument, 0, 0); - if (joy_step < 1) - joy_step = 1; - else if (joy_step > 100) - joy_step = 100; - break; + case PRM_JOY_KYBD_SENSITIVITY: + joy_step = strtol(argument, 0, 0); + if (joy_step < 1) + { + joy_step = 1; + } + else + if (joy_step > 100) + { + joy_step = 100; + } - case PRM_ROM_PATH: - strncpy (system_path, argument, SYSSIZE); - break; - } - } - fclose (config_file); - } + break; + + case PRM_ROM_PATH: + strncpy(system_path, argument, SYSSIZE); + break; + } + } + + fclose(config_file); + } } /* Save the configuration */ -void -save_settings (void) +void +save_settings(void) { - FILE *config_file; + FILE *config_file; - config_file = fopen (config_filename, "w"); - if (config_file == NULL) + config_file = fopen(config_filename, "w"); + if (config_file == NULL) { - printf ( - "Cannot open the .apple2 system defaults file for writing.\n" - "Make sure it has rw permission in your home directory."); - return; + printf( + "Cannot open the .apple2 system defaults file for writing.\n" + "Make sure it has rw permission in your home directory."); + return; } - fprintf (config_file, - "speed = %d\n" - "mode = %s\n" - "disk path = %s\n" - "color = %s\n" - "sound = %s\n" - "joystick = %s\n" - "joystick range = %d\n" - "origin_x = %d\n" - "origin_y = %d\n" - "sensitivity = %d%%\n" - "system path = %s\n", - MAX_APPLE_DELAY + 1 - cpu65_delay, - reverse_match (modes_table, apple_mode), - disk_path, - reverse_match (color_table, color_mode), - reverse_match (sound_table, sound_mode), - reverse_match (joy_input_table, joy_mode), - joy_range, - joy_center_x, - joy_center_y, - joy_step, - system_path); + fprintf(config_file, + "speed = %d\n" + "mode = %s\n" + "disk path = %s\n" + "color = %s\n" + "sound = %s\n" + "joystick = %s\n" + "joystick range = %d\n" + "origin_x = %d\n" + "origin_y = %d\n" + "sensitivity = %d%%\n" + "system path = %s\n", + MAX_APPLE_DELAY + 1 - cpu65_delay, + reverse_match(modes_table, apple_mode), + disk_path, + reverse_match(color_table, color_mode), + reverse_match(sound_table, sound_mode), + reverse_match(joy_input_table, joy_mode), + joy_range, + joy_center_x, + joy_center_y, + joy_step, + system_path); #ifdef PC_JOYSTICK - fprintf (config_file, - "pc joystick parms = %d %d %d %d %d %d %ld\n", - js_center_x, js_center_y, js_max_x, js_min_x, - js_max_y, js_min_y, js_timelimit); + fprintf(config_file, + "pc joystick parms = %d %d %d %d %d %d %ld\n", + js_center_x, js_center_y, js_max_x, js_min_x, + js_max_y, js_min_y, js_timelimit); #endif - fclose (config_file); + fclose(config_file); } diff --git a/src/prefs.h b/src/prefs.h index d97da79e..5fb317a2 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Configuration defines * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -19,9 +19,9 @@ #ifndef __ASSEMBLER__ -#define SYSSIZE 4096 +#define SYSSIZE 4096 extern char system_path[SYSSIZE]; -#define DISKSIZE 4096 +#define DISKSIZE 4096 extern char disk_path[DISKSIZE]; extern int apple_mode; /* undocumented instructions or //e mode */ diff --git a/src/timing.c b/src/timing.c index e28e5389..bcee8cbf 100644 --- a/src/timing.c +++ b/src/timing.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux * * CPU Timing Support. @@ -7,7 +7,7 @@ * match a 1.02MHz Apple //e. * * Added 2013 by Aaron Culliney - * + * */ #include "timing.h" @@ -35,14 +35,17 @@ extern pthread_cond_t cond; // ----------------------------------------------------------------------------- // assuming end > start, returns end - start -static inline struct timespec timespec_diff (struct timespec start, struct timespec end) { +static inline struct timespec timespec_diff(struct timespec start, struct timespec end) { struct timespec t; // assuming time_t is signed ... - if (end.tv_nsec < start.tv_nsec) { + if (end.tv_nsec < start.tv_nsec) + { t.tv_sec = end.tv_sec - start.tv_sec - 1; t.tv_nsec = NANOSECONDS + end.tv_nsec - start.tv_nsec; - } else { + } + else + { t.tv_sec = end.tv_sec - start.tv_sec; t.tv_nsec = end.tv_nsec - start.tv_nsec; } @@ -50,20 +53,20 @@ static inline struct timespec timespec_diff (struct timespec start, struct times return t; } -static inline long timespec_nsecs (struct timespec t) { +static inline long timespec_nsecs(struct timespec t) { return t.tv_sec*NANOSECONDS + t.tv_nsec; } -void timing_initialize () { +void timing_initialize() { clock_gettime(CLOCK_MONOTONIC, &t0); ti=t0; } -void timing_set_cpu_target_hz (unsigned long hz) { +void timing_set_cpu_target_hz(unsigned long hz) { cpu_target_hz = hz; } -void timing_set_sleep_hz (unsigned int hz) { +void timing_set_sleep_hz(unsigned int hz) { sleep_hz = hz; } @@ -73,12 +76,13 @@ void timing_set_sleep_hz (unsigned int hz) { * * This is called from cpu65_run() on the cpu-thread */ -void timing_throttle () { +void timing_throttle() { ++cycle; static time_t severe_lag=0; - if ((cycle%cycles_interval) == 0) { + if ((cycle%cycles_interval) == 0) + { // wake render thread as we go to sleep pthread_mutex_lock(&mutex); @@ -88,27 +92,32 @@ void timing_throttle () { clock_gettime(CLOCK_MONOTONIC, &tj); deltat = timespec_diff(ti, tj); ti=tj; - if (deltat.tv_sec != 0) { + if (deltat.tv_sec != 0) + { // severely lagging, don't bother sleeping ... - if (severe_lag < time(NULL)) { + if (severe_lag < time(NULL)) + { severe_lag = time(NULL)+2; fprintf(stderr, "Severe lag detected...\n"); } - } else { + } + else + { deltat.tv_nsec = processing_interval - deltat.tv_nsec + sleep_adjust_inc; nanosleep(&deltat, NULL); // NOTE: spec says will return right away if deltat.tv_nsec value < 0 ... ti.tv_nsec += deltat.tv_nsec; } - if ((cycle%cpu_target_hz) == 0) { + if ((cycle%cpu_target_hz) == 0) + { clock_gettime(CLOCK_MONOTONIC, &tj); deltat = timespec_diff(t0, tj); - struct timespec t = (struct timespec){.tv_sec=1, .tv_nsec=0}; + struct timespec t = (struct timespec) {.tv_sec=1, .tv_nsec=0 }; long adj = (deltat.tv_sec == 0) - ? timespec_nsecs(timespec_diff(deltat, t)) - : -1 * timespec_nsecs(timespec_diff(t, deltat)); + ? timespec_nsecs(timespec_diff(deltat, t)) + : -1 * timespec_nsecs(timespec_diff(t, deltat)); sleep_adjust += adj; sleep_adjust_inc = sleep_adjust/sleep_hz; diff --git a/src/timing.h b/src/timing.h index 3a4b0206..ad093b3c 100644 --- a/src/timing.h +++ b/src/timing.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux * * CPU Timing Support. @@ -7,7 +7,7 @@ * match a 1.02MHz Apple //e. * * Added 2013 by Aaron Culliney - * + * */ #ifndef _TIMING_H_ @@ -16,12 +16,12 @@ #define APPLE2_HZ 1020000 #define NANOSECONDS 1000000000 -void timing_set_cpu_target_hz (unsigned long hz); +void timing_set_cpu_target_hz(unsigned long hz); -void timing_set_sleep_hz (unsigned int hz); +void timing_set_sleep_hz(unsigned int hz); -void timing_initialize (); +void timing_initialize(); -void timing_throttle (); +void timing_throttle(); #endif // whole file diff --git a/src/video.h b/src/video.h index 364ce397..48096d3e 100644 --- a/src/video.h +++ b/src/video.h @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Video definitions * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -19,35 +19,35 @@ #ifndef __ASSEMBLER__ -/* Prepare the video system, converting console to graphics mode, or - * opening X window, or whatever. This is called only once when the +/* Prepare the video system, converting console to graphics mode, or + * opening X window, or whatever. This is called only once when the * emulator is run */ void video_init(void); -/* Undo anything done by video_init. This is called before exiting the +/* Undo anything done by video_init. This is called before exiting the * emulator. */ void video_shutdown(void); -/* Setup the display. This may be called multiple times in a run, and is +/* Setup the display. This may be called multiple times in a run, and is * used when graphics parameters (II+ vs //e, hires color representation) may * have changed. * - * In future, all relevant information will be communicated through - * FLAGS. For now, however, it is ignored and global variables are used + * In future, all relevant information will be communicated through + * FLAGS. For now, however, it is ignored and global variables are used * instead. * - * This function is responsible for inserting any needed video-specific hooks - * into the 6502 memory indirection table. It should *not* hook the - * soft-switches. + * This function is responsible for inserting any needed video-specific hooks + * into the 6502 memory indirection table. It should *not* hook the + * soft-switches. * */ void video_set(int flags); -/* Set the font used by the display. QTY characters are loaded starting - * with FIRST, from DATA. DATA contains 8 bytes for each character, each - * byte representing a row (top-to-bottom). The row byte contains 7 +/* Set the font used by the display. QTY characters are loaded starting + * with FIRST, from DATA. DATA contains 8 bytes for each character, each + * byte representing a row (top-to-bottom). The row byte contains 7 * pixels in little-endian format. * * MODE selects the colors to use @@ -57,16 +57,16 @@ void video_set(int flags); * 2 - Inverse * 3 - Flash * - * The extra MouseText mode is in case we want to emulate certain RGB - * adaptors which color normal text and MouseText differently. I had one + * The extra MouseText mode is in case we want to emulate certain RGB + * adaptors which color normal text and MouseText differently. I had one * once for a //c. */ -void video_loadfont(int first, - int qty, +void video_loadfont(int first, + int qty, const unsigned char *data, int mode); -/* Redraw the display. This is called after exiting an interface display, +/* Redraw the display. This is called after exiting an interface display, * when changes have been made to the Apple's emulated framebuffer that * bypass the driver's hooks, or when the video mode has changed. */ @@ -83,10 +83,10 @@ void video_setpage(int page); */ void video_loadfont_int(int first, int qty, const unsigned char *data); -/* Plot a character to the text mode screen, *not* writing to apple +/* Plot a character to the text mode screen, *not* writing to apple * memory. This is used by the interface screens. * - * ROW, COL, and CODE are self-expanatory. COLOR gives the color scheme + * ROW, COL, and CODE are self-expanatory. COLOR gives the color scheme * to use: * * 0 - Green text on Black background @@ -95,11 +95,11 @@ void video_loadfont_int(int first, int qty, const unsigned char *data); */ void video_plotchar(int row, int col, int color, unsigned char code); -/* Called at about 30Hz (this may change in future), and when waiting in - * the interface screens. - * - * Should flush any video data to the real screen (if any kind of caching - * is in use), check for keyboard input (presently reported via +/* Called at about 30Hz (this may change in future), and when waiting in + * the interface screens. + * + * Should flush any video data to the real screen (if any kind of caching + * is in use), check for keyboard input (presently reported via * c_read_raw_key), and handle flashing text characters. */ void video_sync(int block); @@ -123,40 +123,40 @@ void video_sync(int block); #define SCANSTEP SCANWIDTH-6 #endif /* !_640x400 */ -#define COLOR_BLACK 0 +#define COLOR_BLACK 0 -#define COLOR_DARK_RED 35 -#define COLOR_MEDIUM_RED 36 -#define COLOR_LIGHT_RED 37 /* hgr used */ +#define COLOR_DARK_RED 35 +#define COLOR_MEDIUM_RED 36 +#define COLOR_LIGHT_RED 37 /* hgr used */ -#define COLOR_DARK_GREEN 38 -#define COLOR_MEDIUM_GREEN 39 -#define COLOR_LIGHT_GREEN 40 /* hgr used */ +#define COLOR_DARK_GREEN 38 +#define COLOR_MEDIUM_GREEN 39 +#define COLOR_LIGHT_GREEN 40 /* hgr used */ -#define COLOR_DARK_YELLOW 41 -#define COLOR_MEDIUM_YELLOW 42 -#define COLOR_LIGHT_YELLOW 43 +#define COLOR_DARK_YELLOW 41 +#define COLOR_MEDIUM_YELLOW 42 +#define COLOR_LIGHT_YELLOW 43 -#define COLOR_DARK_BLUE 44 -#define COLOR_MEDIUM_BLUE 45 -#define COLOR_LIGHT_BLUE 46 /* hgr used */ +#define COLOR_DARK_BLUE 44 +#define COLOR_MEDIUM_BLUE 45 +#define COLOR_LIGHT_BLUE 46 /* hgr used */ -#define COLOR_DARK_PURPLE 47 -#define COLOR_MEDIUM_PURPLE 48 -#define COLOR_LIGHT_PURPLE 49 /* hgr used */ +#define COLOR_DARK_PURPLE 47 +#define COLOR_MEDIUM_PURPLE 48 +#define COLOR_LIGHT_PURPLE 49 /* hgr used */ -#define COLOR_DARK_CYAN 50 -#define COLOR_MEDIUM_CYAN 51 -#define COLOR_LIGHT_CYAN 52 +#define COLOR_DARK_CYAN 50 +#define COLOR_MEDIUM_CYAN 51 +#define COLOR_LIGHT_CYAN 52 -#define COLOR_DARK_WHITE 53 -#define COLOR_MEDIUM_WHITE 54 -#define COLOR_LIGHT_WHITE 55 +#define COLOR_DARK_WHITE 53 +#define COLOR_MEDIUM_WHITE 54 +#define COLOR_LIGHT_WHITE 55 -#define COLOR_FLASHING_BLACK 56 -#define COLOR_FLASHING_WHITE 57 -#define COLOR_FLASHING_UNGREEN 58 -#define COLOR_FLASHING_GREEN 59 +#define COLOR_FLASHING_BLACK 56 +#define COLOR_FLASHING_WHITE 57 +#define COLOR_FLASHING_UNGREEN 58 +#define COLOR_FLASHING_GREEN 59 #ifndef __ASSEMBLER__ @@ -164,67 +164,67 @@ void video_sync(int block); generic graphics globals ---------------------------------- */ -/* Pointers to framebuffer (can be VGA memory or host buffer) +/* Pointers to framebuffer (can be VGA memory or host buffer) */ -extern unsigned char *video__fb1,*video__fb2; +extern unsigned char *video__fb1,*video__fb2; #ifdef _640x400 -extern unsigned char video__wider_hires_even[0x1000]; -extern unsigned char video__wider_hires_odd[0x1000]; +extern unsigned char video__wider_hires_even[0x1000]; +extern unsigned char video__wider_hires_odd[0x1000]; #endif /* _640x400 */ -extern unsigned char video__hires_even[0x800]; -extern unsigned char video__hires_odd[0x800]; +extern unsigned char video__hires_even[0x800]; +extern unsigned char video__hires_odd[0x800]; -extern unsigned char video__dhires1[256]; -extern unsigned char video__dhires2[256]; +extern unsigned char video__dhires1[256]; +extern unsigned char video__dhires2[256]; -extern int video__current_page; /* Current visual page */ +extern int video__current_page; /* Current visual page */ extern int video__strictcolors; #ifdef _640x400 -extern unsigned char video__wider_int_font[3][0x8000]; +extern unsigned char video__wider_int_font[3][0x8000]; #else /* _640x400 */ -extern unsigned char video__int_font[3][0x4000]; +extern unsigned char video__int_font[3][0x4000]; #endif /* _640x400 */ /* --- Precalculated hi-res page offsets given addr --- */ -extern unsigned int video__screen_addresses[8192]; -extern unsigned char video__columns[8192]; +extern unsigned int video__screen_addresses[8192]; +extern unsigned char video__columns[8192]; -extern unsigned char video__odd_colors[2]; -extern unsigned char video__even_colors[2]; +extern unsigned char video__odd_colors[2]; +extern unsigned char video__even_colors[2]; /* Hooks */ -void video__write_text0(), - video__write_text0_mixed(), - video__write_text1(), - video__write_text1_mixed(), - video__write_even0(), - video__write_odd0(), - video__write_even0_mixed(), - video__write_odd0_mixed(), - video__write_even1(), - video__write_odd1(), - video__write_even1_mixed(), - video__write_odd1_mixed(); +void video__write_text0(), +video__write_text0_mixed(), +video__write_text1(), +video__write_text1_mixed(), +video__write_even0(), +video__write_odd0(), +video__write_even0_mixed(), +video__write_odd0_mixed(), +video__write_even1(), +video__write_odd1(), +video__write_even1_mixed(), +video__write_odd1_mixed(); -#ifdef APPLE_IIE -void video__write_2e_text0(), - video__write_2e_text0_mixed(), - video__write_2e_text1(), - video__write_2e_text1_mixed(), - video__write_2e_odd0(), - video__write_2e_even0(), - video__write_2e_odd0_mixed(), - video__write_2e_even0_mixed(), - video__write_2e_odd1(), - video__write_2e_even1(), - video__write_2e_odd1_mixed(), - video__write_2e_even1_mixed(); +#ifdef APPLE_IIE +void video__write_2e_text0(), +video__write_2e_text0_mixed(), +video__write_2e_text1(), +video__write_2e_text1_mixed(), +video__write_2e_odd0(), +video__write_2e_even0(), +video__write_2e_odd0_mixed(), +video__write_2e_even0_mixed(), +video__write_2e_odd1(), +video__write_2e_even1(), +video__write_2e_odd1_mixed(), +video__write_2e_even1_mixed(); #endif /* APPLE_IIE */ #endif /* !__ASSEMBLER__ */ diff --git a/src/vidsup.c b/src/vidsup.c index bcb9b4b9..bb302e9e 100644 --- a/src/vidsup.c +++ b/src/vidsup.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: Video support * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -26,83 +26,83 @@ unsigned char video__wider_font[0x8000]; unsigned char video__font[0x4000]; /* --- Precalculated hi-res page offsets given addr --- */ -unsigned int video__screen_addresses[8192]; -unsigned char video__columns[8192]; +unsigned int video__screen_addresses[8192]; +unsigned char video__columns[8192]; -unsigned char *video__fb1,*video__fb2; +unsigned char *video__fb1,*video__fb2; #ifdef _640x400 -unsigned char video__wider_hires_even[0x1000]; -unsigned char video__wider_hires_odd[0x1000]; +unsigned char video__wider_hires_even[0x1000]; +unsigned char video__wider_hires_odd[0x1000]; #endif -unsigned char video__hires_even[0x800]; -unsigned char video__hires_odd[0x800]; +unsigned char video__hires_even[0x800]; +unsigned char video__hires_odd[0x800]; -unsigned char video__dhires1[256]; -unsigned char video__dhires2[256]; +unsigned char video__dhires1[256]; +unsigned char video__dhires2[256]; /* Interface font: - * (probably could be made static) + * (probably could be made static) * * Unlike the normal font, only one version is stored, since the interface * is always displayed in forty columns. */ #ifdef _640x400 -unsigned char video__wider_int_font[3][0x8000]; +unsigned char video__wider_int_font[3][0x8000]; #else /* _640x400 */ -unsigned char video__int_font[3][0x4000]; +unsigned char video__int_font[3][0x4000]; #endif /* _640x400 */ -int video__current_page; /* Current visual page */ +int video__current_page; /* Current visual page */ int video__strictcolors; -void video_loadfont(int first, - int quantity, +void video_loadfont(int first, + int quantity, const unsigned char *data, int mode) -{ +{ int i,j; unsigned char x,y,fg,bg; - switch(mode) + switch (mode) { case 2: - fg = COLOR_BLACK; bg = COLOR_LIGHT_WHITE; break; + fg = COLOR_BLACK; bg = COLOR_LIGHT_WHITE; break; case 3: - fg = COLOR_FLASHING_WHITE; bg = COLOR_FLASHING_BLACK; break; - default: - fg = COLOR_LIGHT_WHITE; bg = COLOR_BLACK; break; + fg = COLOR_FLASHING_WHITE; bg = COLOR_FLASHING_BLACK; break; + default: + fg = COLOR_LIGHT_WHITE; bg = COLOR_BLACK; break; } i = quantity * 8; - while (i--) + while (i--) { j = 8; x = data[i]; while (j--) { - y = (x & 128) ? fg : bg; + y = (x & 128) ? fg : bg; #ifdef _640x400 - video__wider_font[(first << 7) + (i << 4) + (j << 1)] = - video__wider_font[(first << 7) + (i << 4) + (j << 1) + 1] = -#endif /* _640x400 */ + video__wider_font[(first << 7) + (i << 4) + (j << 1)] = + video__wider_font[(first << 7) + (i << 4) + (j << 1) + 1] = +#endif /* _640x400 */ video__font[(first << 6) + (i << 3) + j] = y; - x <<= 1; + x <<= 1; } } } -unsigned char video__odd_colors[2] = {COLOR_LIGHT_PURPLE, COLOR_LIGHT_BLUE}; -unsigned char video__even_colors[2] = {COLOR_LIGHT_GREEN, COLOR_LIGHT_RED}; +unsigned char video__odd_colors[2] = { COLOR_LIGHT_PURPLE, COLOR_LIGHT_BLUE }; +unsigned char video__even_colors[2] = { COLOR_LIGHT_GREEN, COLOR_LIGHT_RED }; /* 40col/80col/lores/hires/dhires line offsets */ unsigned short video__line_offset[24] = - { 0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, - 0x028, 0x0A8, 0x128, 0x1A8, 0x228, 0x2A8, 0x328, 0x3A8, - 0x050, 0x0D0, 0x150, 0x1D0, 0x250, 0x2D0, 0x350, 0x3D0 }; +{ 0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, + 0x028, 0x0A8, 0x128, 0x1A8, 0x228, 0x2A8, 0x328, 0x3A8, + 0x050, 0x0D0, 0x150, 0x1D0, 0x250, 0x2D0, 0x350, 0x3D0 }; unsigned char video__dhires1[256] = { 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, @@ -138,23 +138,24 @@ static void c_initialize_dhires_values(void) { /* precalculate the colors for all the 256*8 bit combinations. */ /* for (value = 0x00, v = 0; value <= 0xFF; value++) { */ -/* locolor = (value & 0x0F) | 0x10; */ -/* hicolor = (value << 4) | 0x10; */ +/* locolor = (value & 0x0F) | 0x10; */ +/* hicolor = (value << 4) | 0x10; */ -/* dhires_colors[v++] = locolor; */ -/* dhires_colors[v++] = locolor; */ -/* dhires_colors[v++] = locolor; */ -/* dhires_colors[v++] = locolor; */ +/* dhires_colors[v++] = locolor; */ +/* dhires_colors[v++] = locolor; */ +/* dhires_colors[v++] = locolor; */ +/* dhires_colors[v++] = locolor; */ -/* dhires_colors[v++] = hicolor; */ -/* dhires_colors[v++] = hicolor; */ -/* dhires_colors[v++] = hicolor; */ -/* dhires_colors[v++] = hicolor; */ +/* dhires_colors[v++] = hicolor; */ +/* dhires_colors[v++] = hicolor; */ +/* dhires_colors[v++] = hicolor; */ +/* dhires_colors[v++] = hicolor; */ /* } */ - for (i = 0; i < 0x80; i++) { - video__dhires1[i+0x80] = video__dhires1[i]; - video__dhires2[i+0x80] = video__dhires2[i]; + for (i = 0; i < 0x80; i++) + { + video__dhires1[i+0x80] = video__dhires1[i]; + video__dhires2[i+0x80] = video__dhires2[i]; } } #endif @@ -165,58 +166,73 @@ static void c_initialize_dhires_values(void) { static void c_initialize_hires_values(void) { - int value, b, v, e, /*color_toggle,*/ last_not_black; + int value, b, v, e, /*color_toggle,*/ last_not_black; /* precalculate the colors for all the 256*8 bit combinations. */ - for (value = 0x00; value <= 0xFF; value++) { - for (e = value * 8, last_not_black = 0, v = value, b = 0; - b < 7; b++, v >>= 1, e++) - { - if (v & 1) - { - video__hires_even[ e ] = last_not_black ? - COLOR_LIGHT_WHITE : - ((b & 1) ? - ((value & 0x80) ? - COLOR_LIGHT_RED : - COLOR_LIGHT_GREEN) : - ((value & 0x80) ? - COLOR_LIGHT_BLUE : - COLOR_LIGHT_PURPLE)); + for (value = 0x00; value <= 0xFF; value++) + { + for (e = value * 8, last_not_black = 0, v = value, b = 0; + b < 7; b++, v >>= 1, e++) + { + if (v & 1) + { + video__hires_even[ e ] = last_not_black ? + COLOR_LIGHT_WHITE : + ((b & 1) ? + ((value & 0x80) ? + COLOR_LIGHT_RED : + COLOR_LIGHT_GREEN) : + ((value & 0x80) ? + COLOR_LIGHT_BLUE : + COLOR_LIGHT_PURPLE)); - video__hires_odd[ e ] = last_not_black ? - COLOR_LIGHT_WHITE : - ((b & 1) ? - ((value & 0x80) ? - COLOR_LIGHT_BLUE : - COLOR_LIGHT_PURPLE) : - ((value & 0x80) ? - COLOR_LIGHT_RED : - COLOR_LIGHT_GREEN)); + video__hires_odd[ e ] = last_not_black ? + COLOR_LIGHT_WHITE : + ((b & 1) ? + ((value & 0x80) ? + COLOR_LIGHT_BLUE : + COLOR_LIGHT_PURPLE) : + ((value & 0x80) ? + COLOR_LIGHT_RED : + COLOR_LIGHT_GREEN)); - if (last_not_black && b > 0) - video__hires_even[ e - 1 ] = COLOR_LIGHT_WHITE, - video__hires_odd[ e - 1 ] = COLOR_LIGHT_WHITE; + if (last_not_black && b > 0) + { + video__hires_even[ e - 1 ] = COLOR_LIGHT_WHITE, + video__hires_odd[ e - 1 ] = COLOR_LIGHT_WHITE; + } - last_not_black = 1; - } - else - video__hires_even[ e ] = COLOR_BLACK, - video__hires_odd[ e ] = COLOR_BLACK, - last_not_black = 0; - } + last_not_black = 1; + } + else + { + video__hires_even[ e ] = COLOR_BLACK, + video__hires_odd[ e ] = COLOR_BLACK, + last_not_black = 0; + } + } } - if (color_mode == 0) { /* Black and White */ - for (value = 0x00; value <= 0xFF; value++) { - for (b = 0, e = value * 8; b < 7; b++, e++) { - if (video__hires_even[ e ] != COLOR_BLACK) - video__hires_even[ e ] = COLOR_LIGHT_WHITE; - if (video__hires_odd[ e ] != COLOR_BLACK) - video__hires_odd[ e ] = COLOR_LIGHT_WHITE; - } - } + + if (color_mode == 0) /* Black and White */ + { + for (value = 0x00; value <= 0xFF; value++) + { + for (b = 0, e = value * 8; b < 7; b++, e++) + { + if (video__hires_even[ e ] != COLOR_BLACK) + { + video__hires_even[ e ] = COLOR_LIGHT_WHITE; + } + + if (video__hires_odd[ e ] != COLOR_BLACK) + { + video__hires_odd[ e ] = COLOR_LIGHT_WHITE; + } + } + } } - else if (color_mode == LAZY_INTERP) /* Lazy Interpolated color */ + else + if (color_mode == LAZY_INTERP) /* Lazy Interpolated color */ { for (value = 0x00; value <= 0xFF; value++) { @@ -225,206 +241,282 @@ static void c_initialize_hires_values(void) if (video__hires_even[ e ] == COLOR_BLACK && video__hires_even[ e - 1 ] != COLOR_BLACK && video__hires_even[ e + 1 ] != COLOR_BLACK) - video__hires_even[ e ] = - video__hires_even[ e - 1 ]; + { + video__hires_even[ e ] = + video__hires_even[ e - 1 ]; + } if (video__hires_odd[ e ] == COLOR_BLACK && video__hires_odd[ e - 1 ] != COLOR_BLACK && video__hires_odd[ e + 1 ] != COLOR_BLACK) - video__hires_odd[ e ] = - video__hires_odd[ e - 1 ]; + { + video__hires_odd[ e ] = + video__hires_odd[ e - 1 ]; + } } - for (b = 0, e = value * 8; b <= 6; b += 2, e += 2) { - if (video__hires_odd[ e ] == COLOR_BLACK) { - if (b > 0 && b < 6) { - if (video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_LIGHT_WHITE && - video__hires_even[e-1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e-1]; - } else if (b == 0) { - if (video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e+1]; - } else { - if (video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_LIGHT_WHITE) - video__hires_even[ e ] = - video__hires_even[ e - 1 ]; + for (b = 0, e = value * 8; b <= 6; b += 2, e += 2) + { + if (video__hires_odd[ e ] == COLOR_BLACK) + { + if (b > 0 && b < 6) + { + if (video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_LIGHT_WHITE && + video__hires_even[e-1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e-1]; + } + } + else + if (b == 0) + { + if (video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e+1]; + } + } + else + { + if (video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_LIGHT_WHITE) + { + video__hires_even[ e ] = + video__hires_even[ e - 1 ]; + } } } - if (video__hires_odd[ e ] == COLOR_BLACK) { - if (b > 0 && b < 6) { - if (video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE) + if (video__hires_odd[ e ] == COLOR_BLACK) + { + if (b > 0 && b < 6) + { + if (video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e-1]; + } + } + else + if (b == 0) + { + if (video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e+1]; + } + } + else + if + (video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE) + { video__hires_odd[e] = video__hires_odd[e-1]; } - else if (b == 0) { - if (video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e+1]; - } - else if - (video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e-1]; } } } } - else if (color_mode == INTERP) { /* Color and strict interpolation */ - for (value = 0x00; value <= 0xFF; value++) { - for (b = 1, e = value * 8 + 1; b <= 5; b += 2, e += 2) { - if (video__hires_even[e] == COLOR_BLACK) { - if (video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_LIGHT_WHITE && - video__hires_even[e+1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e-1]; + else + if (color_mode == INTERP) /* Color and strict interpolation */ + { + for (value = 0x00; value <= 0xFF; value++) + { + for (b = 1, e = value * 8 + 1; b <= 5; b += 2, e += 2) + { + if (video__hires_even[e] == COLOR_BLACK) + { + if (video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_LIGHT_WHITE && + video__hires_even[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e-1]; + } + else + if ( + video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_LIGHT_WHITE && + video__hires_even[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e-1]; + } + else + if ( + video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] == COLOR_LIGHT_WHITE && + video__hires_even[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e+1]; + } + else + if ( + video__hires_even[e-1] == COLOR_LIGHT_WHITE && + video__hires_even[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_even[e] = (value & 0x80) + ? COLOR_LIGHT_BLUE : COLOR_LIGHT_PURPLE; + } - else if ( - video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_LIGHT_WHITE && - video__hires_even[e+1] == COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e-1]; + } - else if ( - video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] == COLOR_LIGHT_WHITE && - video__hires_even[e+1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e+1]; + if (video__hires_odd[e] == COLOR_BLACK) + { + if (video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e-1]; + } + else + if ( + video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE && + video__hires_odd[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e-1]; + } + else + if ( + video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] == COLOR_LIGHT_WHITE && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e+1]; + } + else + if ( + video__hires_odd[e-1] == COLOR_LIGHT_WHITE && + video__hires_odd[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = (value & 0x80) + ? COLOR_LIGHT_RED : COLOR_LIGHT_GREEN; + } + } + } - else if ( - video__hires_even[e-1] == COLOR_LIGHT_WHITE && - video__hires_even[e+1] == COLOR_LIGHT_WHITE) - video__hires_even[e] = (value & 0x80) - ? COLOR_LIGHT_BLUE : COLOR_LIGHT_PURPLE; + for (b = 0, e = value * 8; b <= 6; b += 2, e += 2) + { + if (video__hires_even[ e ] == COLOR_BLACK) + { + if (b > 0 && b < 6) + { + if (video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_LIGHT_WHITE && + video__hires_even[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e-1]; + } + else + if ( + video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] != COLOR_LIGHT_WHITE && + video__hires_even[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e-1]; + } + else + if ( + video__hires_even[e-1] != COLOR_BLACK && + video__hires_even[e+1] != COLOR_BLACK && + video__hires_even[e-1] == COLOR_LIGHT_WHITE && + video__hires_even[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_even[e] = + video__hires_even[e+1]; + } + else + if ( + video__hires_even[e-1] == COLOR_LIGHT_WHITE && + video__hires_even[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_even[e] = (value & 0x80) + ? COLOR_LIGHT_RED : COLOR_LIGHT_GREEN; + } + } + } - } - if (video__hires_odd[e] == COLOR_BLACK) { - if (video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e-1]; - - else if ( - video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE && - video__hires_odd[e+1] == COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e-1]; - - else if ( - video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] == COLOR_LIGHT_WHITE && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e+1]; - - else if ( - video__hires_odd[e-1] == COLOR_LIGHT_WHITE && - video__hires_odd[e+1] == COLOR_LIGHT_WHITE) - video__hires_odd[e] = (value & 0x80) - ? COLOR_LIGHT_RED : COLOR_LIGHT_GREEN; - } - } - - for (b = 0, e = value * 8; b <= 6; b += 2, e += 2) { - if (video__hires_even[ e ] == COLOR_BLACK) { - if (b > 0 && b < 6) { - if (video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_LIGHT_WHITE && - video__hires_even[e+1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e-1]; - - else if ( - video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] != COLOR_LIGHT_WHITE && - video__hires_even[e+1] == COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e-1]; - - else if ( - video__hires_even[e-1] != COLOR_BLACK && - video__hires_even[e+1] != COLOR_BLACK && - video__hires_even[e-1] == COLOR_LIGHT_WHITE && - video__hires_even[e+1] != COLOR_LIGHT_WHITE) - video__hires_even[e] = - video__hires_even[e+1]; - - else if ( - video__hires_even[e-1] == COLOR_LIGHT_WHITE && - video__hires_even[e+1] == COLOR_LIGHT_WHITE) - video__hires_even[e] = (value & 0x80) - ? COLOR_LIGHT_RED : COLOR_LIGHT_GREEN; - } - } - - if (video__hires_odd[e] == COLOR_BLACK) { - if (b > 0 && b < 6) { - if (video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e-1]; - - else if ( - video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] != COLOR_LIGHT_WHITE && - video__hires_odd[e+1] == COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e-1]; - - else if ( - video__hires_odd[e-1] != COLOR_BLACK && - video__hires_odd[e+1] != COLOR_BLACK && - video__hires_odd[e-1] == COLOR_LIGHT_WHITE && - video__hires_odd[e+1] != COLOR_LIGHT_WHITE) - video__hires_odd[e] = - video__hires_odd[e+1]; - - else if ( - video__hires_odd[e-1] == COLOR_LIGHT_WHITE && - video__hires_odd[e+1] == COLOR_LIGHT_WHITE) - video__hires_odd[e] = (value & 0x80) - ? COLOR_LIGHT_BLUE : COLOR_LIGHT_PURPLE; - } - } - } - } + if (video__hires_odd[e] == COLOR_BLACK) + { + if (b > 0 && b < 6) + { + if (video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e-1]; + } + else + if ( + video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] != COLOR_LIGHT_WHITE && + video__hires_odd[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e-1]; + } + else + if ( + video__hires_odd[e-1] != COLOR_BLACK && + video__hires_odd[e+1] != COLOR_BLACK && + video__hires_odd[e-1] == COLOR_LIGHT_WHITE && + video__hires_odd[e+1] != COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = + video__hires_odd[e+1]; + } + else + if ( + video__hires_odd[e-1] == COLOR_LIGHT_WHITE && + video__hires_odd[e+1] == COLOR_LIGHT_WHITE) + { + video__hires_odd[e] = (value & 0x80) + ? COLOR_LIGHT_BLUE : COLOR_LIGHT_PURPLE; + } + } + } + } + } } + #ifdef _640x400 /* *2 for 640x400 */ - for (b=0, e=0; b<4096; b++, e++) { - video__wider_hires_even[b] = video__hires_even[e]; - video__wider_hires_odd[b] = video__hires_odd[e]; + for (b=0, e=0; b<4096; b++, e++) + { + video__wider_hires_even[b] = video__hires_even[e]; + video__wider_hires_odd[b] = video__hires_odd[e]; b++; - video__wider_hires_even[b] = video__hires_even[e]; - video__wider_hires_odd[b] = video__hires_odd[e]; + video__wider_hires_even[b] = video__hires_even[e]; + video__wider_hires_odd[b] = video__hires_odd[e]; } + #endif } @@ -437,144 +529,159 @@ static void c_initialize_row_col_tables(void) int x, y, off, i; /* hires page offsets. initialize to invalid values. */ - for (i = 0; i < 8192; i++) { - video__screen_addresses[i] = -1; + for (i = 0; i < 8192; i++) + { + video__screen_addresses[i] = -1; } - for (y = 0; y < 24; y++) { - for (off = 0; off < 8; off++) { - for (x = 0; x < 40; x++) { + for (y = 0; y < 24; y++) + { + for (off = 0; off < 8; off++) + { + for (x = 0; x < 40; x++) + { #ifdef _640x400 - video__screen_addresses[video__line_offset[y] + 0x400*off + x ] = - (y*16 + 2*off/* + 8*/) * SCANWIDTH + x*14 + 4; + video__screen_addresses[video__line_offset[y] + 0x400*off + x ] = + (y*16 + 2*off /* + 8*/) * SCANWIDTH + x*14 + 4; #else - video__screen_addresses[video__line_offset[y] + 0x400*off + x ] = - (y*8 + off + 4) * 320 + x*7 + 20; + video__screen_addresses[video__line_offset[y] + 0x400*off + x ] = + (y*8 + off + 4) * 320 + x*7 + 20; #endif - video__columns[video__line_offset[y] + 0x400*off + x] = - (unsigned char)x; - } - } + video__columns[video__line_offset[y] + 0x400*off + x] = + (unsigned char)x; + } + } } } static void c_initialize_tables_video(void) { - int x, y, i; + int x, y, i; /* initialize text/lores & hires graphics */ - for (y = 0; y < 24; y++) { /* 24 rows */ - for (x = 0; x < 40; x++) /* 40 cols */ - { + for (y = 0; y < 24; y++) /* 24 rows */ + { + for (x = 0; x < 40; x++) /* 40 cols */ + { #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - /* //e mode: text/lores page 0 */ - cpu65_vmem[ video__line_offset[ y ] + x + 0x400].w = - (y < 20) ? video__write_2e_text0 : - video__write_2e_text0_mixed; - } - else + if (apple_mode == IIE_MODE) + { + /* //e mode: text/lores page 0 */ + cpu65_vmem[ video__line_offset[ y ] + x + 0x400].w = + (y < 20) ? video__write_2e_text0 : + video__write_2e_text0_mixed; + } + else #endif - { - /* ][+ modes: text/lores page 0 */ - cpu65_vmem[ video__line_offset[ y ] + x + 0x400].w = - (y < 20) ? video__write_text0 : - video__write_text0_mixed; - } + { + /* ][+ modes: text/lores page 0 */ + cpu65_vmem[ video__line_offset[ y ] + x + 0x400].w = + (y < 20) ? video__write_text0 : + video__write_text0_mixed; + } #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[ video__line_offset[ y ] + x + 0x800].w = - (y < 20) ? video__write_2e_text1 : - video__write_2e_text1_mixed; - } - else + if (apple_mode == IIE_MODE) + { + cpu65_vmem[ video__line_offset[ y ] + x + 0x800].w = + (y < 20) ? video__write_2e_text1 : + video__write_2e_text1_mixed; + } + else #endif - { - /* ][+ modes: text/lores page 1 in main memory */ - cpu65_vmem[ video__line_offset[ y ] + x + 0x800].w = - (y < 20) ? video__write_text1 : - video__write_text1_mixed; - } + { + /* ][+ modes: text/lores page 1 in main memory */ + cpu65_vmem[ video__line_offset[ y ] + x + 0x800].w = + (y < 20) ? video__write_text1 : + video__write_text1_mixed; + } - for (i = 0; i < 8; i++) - { - /* //e mode: hires/double hires page 0 */ + for (i = 0; i < 8; i++) + { + /* //e mode: hires/double hires page 0 */ #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[ 0x2000 + video__line_offset[ y ] - + 0x400 * i + x ].w = - (y < 20) ? ((x & 1) ? video__write_2e_odd0 : - video__write_2e_even0) - : ((x & 1) ? video__write_2e_odd0_mixed : - video__write_2e_even0_mixed); - } - - /* ][+ modes: hires page 0 */ - else + if (apple_mode == IIE_MODE) + { + cpu65_vmem[ 0x2000 + video__line_offset[ y ] + + 0x400 * i + x ].w = + (y < 20) ? ((x & 1) ? video__write_2e_odd0 : + video__write_2e_even0) + : ((x & 1) ? video__write_2e_odd0_mixed : + video__write_2e_even0_mixed); + } + /* ][+ modes: hires page 0 */ + else #endif - { - cpu65_vmem[ 0x2000 + video__line_offset[ y ] - + 0x400 * i + x ].w = - (y < 20) ? ((x & 1) ? video__write_odd0 : - video__write_even0) - : ((x & 1) ? video__write_odd0_mixed : - video__write_even0_mixed); - } + { + cpu65_vmem[ 0x2000 + video__line_offset[ y ] + + 0x400 * i + x ].w = + (y < 20) ? ((x & 1) ? video__write_odd0 : + video__write_even0) + : ((x & 1) ? video__write_odd0_mixed : + video__write_even0_mixed); + } #ifdef APPLE_IIE - if (apple_mode == IIE_MODE) { - cpu65_vmem[ 0x4000 + video__line_offset[ y ] - + 0x400 * i + x ].w = - (y < 20) ? ((x & 1) ? video__write_2e_odd1 : - video__write_2e_even1) - : ((x & 1) ? video__write_2e_odd1_mixed : - video__write_2e_even1_mixed); - } - - /* ][+ modes: hires page 1 */ - else + if (apple_mode == IIE_MODE) + { + cpu65_vmem[ 0x4000 + video__line_offset[ y ] + + 0x400 * i + x ].w = + (y < 20) ? ((x & 1) ? video__write_2e_odd1 : + video__write_2e_even1) + : ((x & 1) ? video__write_2e_odd1_mixed : + video__write_2e_even1_mixed); + } + /* ][+ modes: hires page 1 */ + else #endif - { - cpu65_vmem[ 0x4000 + video__line_offset[ y ] - + 0x400 * i + x ].w = - (y < 20) ? ((x & 1) ? video__write_odd1 : - video__write_even1) - : ((x & 1) ? video__write_odd1_mixed : - video__write_even1_mixed); - } - } - } + { + cpu65_vmem[ 0x4000 + video__line_offset[ y ] + + 0x400 * i + x ].w = + (y < 20) ? ((x & 1) ? video__write_odd1 : + video__write_even1) + : ((x & 1) ? video__write_odd1_mixed : + video__write_even1_mixed); + } + } + } } } void video_set(int flags) { if (color_mode == COLOR) - video__strictcolors = 1; /* strict colors */ - else if (color_mode == INTERP) - video__strictcolors = 2; /* strict interpolation */ + { + video__strictcolors = 1; /* strict colors */ + } else - video__strictcolors = 0; /* lazy coloration */ + if (color_mode == INTERP) + { + video__strictcolors = 2; /* strict interpolation */ + } + else + { + video__strictcolors = 0; /* lazy coloration */ - c_initialize_hires_values(); /* precalculate hires values */ - c_initialize_row_col_tables(); /* precalculate hires offsets */ - c_initialize_tables_video(); /* memory jump tables for video */ + } + + c_initialize_hires_values(); /* precalculate hires values */ + c_initialize_row_col_tables(); /* precalculate hires offsets */ + c_initialize_tables_video(); /* memory jump tables for video */ #ifdef APPLE_IIE - c_initialize_dhires_values(); /* set up dhires colors */ + c_initialize_dhires_values(); /* set up dhires colors */ #endif } void video_loadfont_int(int first, int quantity, const unsigned char *data) -{ +{ int i,j; unsigned char x; int y; i = quantity * 8; - while (i--) + while (i--) { j = 8; x = data[i]; @@ -582,41 +689,43 @@ void video_loadfont_int(int first, int quantity, const unsigned char *data) { #ifdef _640x400 - y = (first << 7) + (i << 4) + (j << 1); - if (x & 128) + y = (first << 7) + (i << 4) + (j << 1); + if (x & 128) { - video__wider_int_font[0][y] = - video__wider_int_font[0][y+1] = - video__wider_int_font[1][y] = - video__wider_int_font[1][y+1] = COLOR_LIGHT_GREEN; - video__wider_int_font[2][y] = - video__wider_int_font[2][y+1] = COLOR_LIGHT_RED; - } + video__wider_int_font[0][y] = + video__wider_int_font[0][y+1] = + video__wider_int_font[1][y] = + video__wider_int_font[1][y+1] = COLOR_LIGHT_GREEN; + video__wider_int_font[2][y] = + video__wider_int_font[2][y+1] = COLOR_LIGHT_RED; + } else { - video__wider_int_font[0][y] = - video__wider_int_font[0][y+1] = - video__wider_int_font[2][y] = - video__wider_int_font[2][y+1] = COLOR_BLACK; - video__wider_int_font[1][y] = - video__wider_int_font[1][y+1] = COLOR_MEDIUM_BLUE; - } + video__wider_int_font[0][y] = + video__wider_int_font[0][y+1] = + video__wider_int_font[2][y] = + video__wider_int_font[2][y+1] = COLOR_BLACK; + video__wider_int_font[1][y] = + video__wider_int_font[1][y+1] = COLOR_MEDIUM_BLUE; + } + #else - y = (first << 6) + (i << 3) + j; - if (x & 128) - { - video__int_font[0][y] = - video__int_font[1][y] = COLOR_LIGHT_GREEN; - video__int_font[2][y] = COLOR_LIGHT_RED; - } + y = (first << 6) + (i << 3) + j; + if (x & 128) + { + video__int_font[0][y] = + video__int_font[1][y] = COLOR_LIGHT_GREEN; + video__int_font[2][y] = COLOR_LIGHT_RED; + } else - { - video__int_font[0][y] = - video__int_font[2][y] = COLOR_BLACK; - video__int_font[1][y] = COLOR_MEDIUM_BLUE; - } -#endif /* _640x400 */ - x <<= 1; + { + video__int_font[0][y] = + video__int_font[2][y] = COLOR_BLACK; + video__int_font[1][y] = COLOR_MEDIUM_BLUE; + } + +#endif /* _640x400 */ + x <<= 1; } } } @@ -624,31 +733,31 @@ void video_loadfont_int(int first, int quantity, const unsigned char *data) /* Should probably move this to assembly... */ static void c_interface_print_char40_line( - unsigned char **d, unsigned char **s) + unsigned char **d, unsigned char **s) { #ifdef _640x400 - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned short *)(*d)) = *((unsigned short *)(*s));/*16bits*/ + *((unsigned short *)(*d)) = *((unsigned short *)(*s)); /*16bits*/ *d += SCANSTEP, *s -= 12; - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned short *)(*d)) = *((unsigned short *)(*s));/*16bits*/ + *((unsigned short *)(*d)) = *((unsigned short *)(*s)); /*16bits*/ *d += SCANSTEP, *s += 4; #else - *((unsigned int *)(*d)) = *((unsigned int *)(*s));/*32bits*/ + *((unsigned int *)(*d)) = *((unsigned int *)(*s)); /*32bits*/ *d += 4, *s += 4; - *((unsigned short *)(*d)) = *((unsigned short *)(*s));/*16bits*/ + *((unsigned short *)(*d)) = *((unsigned short *)(*s)); /*16bits*/ *d += 2, *s += 2; - *((unsigned char *)(*d)) = *((unsigned char *)(*s));/*8bits*/ + *((unsigned char *)(*d)) = *((unsigned char *)(*s)); /*8bits*/ *d += SCANSTEP, *s += 2; #endif } diff --git a/src/xvideo.c b/src/xvideo.c index f582b25d..755ef6a2 100644 --- a/src/xvideo.c +++ b/src/xvideo.c @@ -1,4 +1,4 @@ -/* +/* * Apple // emulator for Linux: X-Windows graphics support * * Copyright 1994 Alexander Jean-Claude Bottema @@ -7,10 +7,10 @@ * Copyright 1998, 1999, 2000 Michael Deutschmann * * This software package is subject to the GNU General Public License - * version 2 or later (your choice) as published by the Free Software + * version 2 or later (your choice) as published by the Free Software * Foundation. * - * THERE ARE NO WARRANTIES WHATSOEVER. + * THERE ARE NO WARRANTIES WHATSOEVER. * */ @@ -28,20 +28,20 @@ #include #include #include -#include /* MITSHM! */ +#include /* MITSHM! */ #include "video.h" #include "misc.h" #include "keys.h" -static unsigned char vga_mem_page_0[SCANWIDTH*SCANHEIGHT]; /* page0 framebuffer */ -static unsigned char vga_mem_page_1[SCANWIDTH*SCANHEIGHT]; /* page1 framebuffer */ +static unsigned char vga_mem_page_0[SCANWIDTH*SCANHEIGHT]; /* page0 framebuffer */ +static unsigned char vga_mem_page_1[SCANWIDTH*SCANHEIGHT]; /* page1 framebuffer */ static Display *display; static Window win; static GC gc; -static unsigned int width, height; /* window size */ +static unsigned int width, height; /* window size */ static int screen_num; static XVisualInfo visualinfo; @@ -55,9 +55,9 @@ static uint32_t green_shift; static uint32_t blue_shift; static uint32_t alpha_shift; -int doShm = 1;/* assume true */ -XShmSegmentInfo xshminfo; -int xshmeventtype; +int doShm = 1; /* assume true */ +XShmSegmentInfo xshminfo; +int xshmeventtype; /* ------------------------------------------------------------------------- @@ -74,94 +74,114 @@ void video_setpage(int p) * (maybe due to an emulator crash) and tries to remove them or use them. */ static void getshm(int size) { - int key = ('a'<<24) | ('p'<<16) | ('p'<<8) | 'l'; - struct shmid_ds shminfo; - int id; - int rc; - int counter=5; + int key = ('a'<<24) | ('p'<<16) | ('p'<<8) | 'l'; + struct shmid_ds shminfo; + int id; + int rc; + int counter=5; /* Try to allocate shared memory segment. Use stale segments if any are * found. */ do { - id = shmget((key_t) key, 0, 0777); - if (id == -1) { - /* no stale ID's */ - id = shmget((key_t)key, size, IPC_CREAT|0777); - if (id == -1) { - perror("shmget"); - printf("Could not get shared memory\n"); - ++key; - } - break; - } else { - /* we got someone else's ID. check if it's stale. */ - printf("Found shared memory key=`%c%c%c%c', id=%d\n", (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); - rc=shmctl(id, IPC_STAT, &shminfo); /* get stats */ - if (rc) { - /* error. what to do now? */ - perror("shmctl"); - printf("Could not get stats on key=`%c%c%c%c', id=%d\n", (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); - ++key; - } else { - if (shminfo.shm_nattch) { - printf( "User uid=%d, key=`%c%c%c%c' appears to be running the emulator.\n", shminfo.shm_perm.cuid, (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff)); - ++key; /* increase the key count */ - } else { - if (getuid() == shminfo.shm_perm.cuid) { + id = shmget((key_t) key, 0, 0777); + if (id == -1) + { + /* no stale ID's */ + id = shmget((key_t)key, size, IPC_CREAT|0777); + if (id == -1) + { + perror("shmget"); + printf("Could not get shared memory\n"); + ++key; + } + + break; + } + else + { + /* we got someone else's ID. check if it's stale. */ + printf("Found shared memory key=`%c%c%c%c', id=%d\n", (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); + rc=shmctl(id, IPC_STAT, &shminfo); /* get stats */ + if (rc) + { + /* error. what to do now? */ + perror("shmctl"); + printf("Could not get stats on key=`%c%c%c%c', id=%d\n", (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); + ++key; + } + else + { + if (shminfo.shm_nattch) + { + printf( "User uid=%d, key=`%c%c%c%c' appears to be running the emulator.\n", shminfo.shm_perm.cuid, (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff)); + ++key; /* increase the key count */ + } + else + { + if (getuid() == shminfo.shm_perm.cuid) + { /* it's my stale ID */ - rc = shmctl(id, IPC_RMID, 0); - if (!rc) { - printf("Was able to kill my old shared memory\n"); - } else { - perror("shmctl"); - printf("Was NOT able to kill my old shared memory\n"); - } + rc = shmctl(id, IPC_RMID, 0); + if (!rc) + { + printf("Was able to kill my old shared memory\n"); + } + else + { + perror("shmctl"); + printf("Was NOT able to kill my old shared memory\n"); + } - id = shmget((key_t)key, size, IPC_CREAT|0777); - if (id == -1) { - perror("shmget"); - printf("Could not get shared memory\n"); - } + id = shmget((key_t)key, size, IPC_CREAT|0777); + if (id == -1) + { + perror("shmget"); + printf("Could not get shared memory\n"); + } - rc=shmctl(id, IPC_STAT, &shminfo); - if (rc) { - perror("shmctl"); - } + rc=shmctl(id, IPC_STAT, &shminfo); + if (rc) + { + perror("shmctl"); + } - break; - } + break; + } - if (size == shminfo.shm_segsz) { + if (size == shminfo.shm_segsz) + { /* not my ID, but maybe we can use it */ - printf("Will use stale shared memory of uid=%d\n", shminfo.shm_perm.cuid); - break; - } - - /* not my ID, and we can't use it */ - else { - printf("Can't use stale shared memory belonging to uid=%d, key=`%c%c%c%c', id=%d\n", shminfo.shm_perm.cuid, (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); - ++key; - } - } - } - } + printf("Will use stale shared memory of uid=%d\n", shminfo.shm_perm.cuid); + break; + } + /* not my ID, and we can't use it */ + else + { + printf("Can't use stale shared memory belonging to uid=%d, key=`%c%c%c%c', id=%d\n", shminfo.shm_perm.cuid, (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id); + ++key; + } + } + } + } } while (--counter); - if (!counter) { - printf( "System has too many stale/used shared memory segments!\n"); - } + if (!counter) + { + printf( "System has too many stale/used shared memory segments!\n"); + } xshminfo.shmid = id; /* attach to the shared memory segment */ image->data = xshminfo.shmaddr = shmat(id, 0, 0); - if ((int)(image->data) == -1) { - perror("shmat"); - printf("Could not attach to shared memory\n"); - exit(1); + if ((int)(image->data) == -1) + { + perror("shmat"); + printf("Could not attach to shared memory\n"); + exit(1); } printf("Using shared memory key=`%c%c%c%c', id=%d, addr=%p\n", (key & 0xff000000)>>24, (key & 0xff0000)>>16, (key & 0xff00)>>8, (key & 0xff), id, image->data); @@ -169,22 +189,26 @@ static void getshm(int size) { static void c_initialize_colors() { - static unsigned char col2[ 3 ] = {255,255,255}; - static int firstcall = 1; - int c,i,j; + static unsigned char col2[ 3 ] = { 255,255,255 }; + static int firstcall = 1; + int c,i,j; /* initialize the colormap */ - if (firstcall) { + if (firstcall) + { firstcall = 0; - for (i=0; i<256; i++) { + for (i=0; i<256; i++) + { colors[i].pixel = i; colors[i].flags = DoRed|DoGreen|DoBlue; } } /* align the palette for hires graphics */ - for (i = 0; i < 8; i++) { - for (j = 0; j < 3; j++) { + for (i = 0; i < 8; i++) + { + for (j = 0; j < 3; j++) + { c = (i & 1) ? col2[ j ] : 0; colors[ j+i*3+32].red = c; c = (i & 2) ? col2[ j ] : 0; @@ -193,6 +217,7 @@ static void c_initialize_colors() { colors[ j+i*3+32].blue = c; } } + colors[ COLOR_FLASHING_BLACK].red = 0; colors[ COLOR_FLASHING_BLACK].green = 0; colors[ COLOR_FLASHING_BLACK].blue = 0; @@ -272,7 +297,8 @@ static void c_initialize_colors() { colors[0x0f].red = 255; colors[0x0f].green = 255; colors[0x0f].blue = 255; /* White */ - for (i=0; i<16; i++) { + for (i=0; i<16; i++) + { colors[i].red = (colors[i].red<<8) | colors[i].red; colors[i].green = (colors[i].green<<8) | colors[i].green; colors[i].blue = (colors[i].blue<<8) | colors[i].blue; @@ -294,108 +320,111 @@ static void c_initialize_colors() { static int keysym_to_scancode(void) { static int rc = 0xFF; - switch(rc = XkbKeycodeToKeysym(display, xevent.xkey.keycode, 0, 0)) + switch (rc = XkbKeycodeToKeysym(display, xevent.xkey.keycode, 0, 0)) { - case XK_F1: - rc = 59; break; - case XK_F2: - rc = 60; break; - case XK_F3: - rc = 61; break; - case XK_F4: - rc = 62; break; - case XK_F5: - rc = 63; break; - case XK_F6: - rc = 64; break; - case XK_F7: - rc = 65; break; - case XK_F8: - rc = 66; break; - case XK_F9: - rc = 67; break; - case XK_F10: - rc = 68; break; - case XK_Left: - rc = 105; break; - case XK_Right: - rc = 106; break; - case XK_Down: - rc = 108; break; - case XK_Up: - rc = 103; break; - case XK_Escape: - rc = 1; break; - case XK_Return: - rc = 28; break; - case XK_Tab: - rc = 15; break; - case XK_Shift_L: - rc = SCODE_L_SHIFT; break; - case XK_Shift_R: - rc = SCODE_R_SHIFT; break; - case XK_Control_L: - rc = SCODE_L_CTRL; break; - case XK_Control_R: - rc = SCODE_R_CTRL; break; - case XK_Caps_Lock: - rc = SCODE_CAPS; break; - case XK_BackSpace: - rc = 14; break; - case XK_Insert: - rc = 110; break; - case XK_Pause: - rc = 119; break; - case XK_Break: - /* Pause and Break are the same key, but have different - * scancodes (on PC keyboards). Ctrl makes the difference. - * - * We assume the X server is passing along the distinction to us, - * rather than making us check Ctrl manually. - */ - rc = 101; break; - case XK_Print: - rc = 99; break; - case XK_Delete: - rc = 111; break; - case XK_End: - rc = 107; break; - case XK_Home: - rc = 102; break; - case XK_Page_Down: - rc = 109; break; - case XK_Page_Up: - rc = 104; break; + case XK_F1: + rc = 59; break; + case XK_F2: + rc = 60; break; + case XK_F3: + rc = 61; break; + case XK_F4: + rc = 62; break; + case XK_F5: + rc = 63; break; + case XK_F6: + rc = 64; break; + case XK_F7: + rc = 65; break; + case XK_F8: + rc = 66; break; + case XK_F9: + rc = 67; break; + case XK_F10: + rc = 68; break; + case XK_Left: + rc = 105; break; + case XK_Right: + rc = 106; break; + case XK_Down: + rc = 108; break; + case XK_Up: + rc = 103; break; + case XK_Escape: + rc = 1; break; + case XK_Return: + rc = 28; break; + case XK_Tab: + rc = 15; break; + case XK_Shift_L: + rc = SCODE_L_SHIFT; break; + case XK_Shift_R: + rc = SCODE_R_SHIFT; break; + case XK_Control_L: + rc = SCODE_L_CTRL; break; + case XK_Control_R: + rc = SCODE_R_CTRL; break; + case XK_Caps_Lock: + rc = SCODE_CAPS; break; + case XK_BackSpace: + rc = 14; break; + case XK_Insert: + rc = 110; break; + case XK_Pause: + rc = 119; break; + case XK_Break: + /* Pause and Break are the same key, but have different + * scancodes (on PC keyboards). Ctrl makes the difference. + * + * We assume the X server is passing along the distinction to us, + * rather than making us check Ctrl manually. + */ + rc = 101; break; + case XK_Print: + rc = 99; break; + case XK_Delete: + rc = 111; break; + case XK_End: + rc = 107; break; + case XK_Home: + rc = 102; break; + case XK_Page_Down: + rc = 109; break; + case XK_Page_Up: + rc = 104; break; - // keypad joystick movement - case XK_KP_5: - case XK_KP_Begin: - rc = SCODE_J_C; break; - case XK_KP_4: - case XK_KP_Left: - rc = SCODE_J_L; break; - case XK_KP_8: - case XK_KP_Up: - rc = SCODE_J_U; break; - case XK_KP_6: - case XK_KP_Right: - rc = SCODE_J_R; break; - case XK_KP_2: - case XK_KP_Down: - rc = SCODE_J_D; break; + // keypad joystick movement + case XK_KP_5: + case XK_KP_Begin: + rc = SCODE_J_C; break; + case XK_KP_4: + case XK_KP_Left: + rc = SCODE_J_L; break; + case XK_KP_8: + case XK_KP_Up: + rc = SCODE_J_U; break; + case XK_KP_6: + case XK_KP_Right: + rc = SCODE_J_R; break; + case XK_KP_2: + case XK_KP_Down: + rc = SCODE_J_D; break; - case XK_Alt_L: - rc = 56; break; - case XK_Alt_R: - rc = 100; break; + case XK_Alt_L: + rc = 56; break; + case XK_Alt_R: + rc = 100; break; - default: - if ((rc >= XK_space) && (rc <= XK_asciitilde)) - rc = xevent.xkey.keycode - 8; - break; + default: + if ((rc >= XK_space) && (rc <= XK_asciitilde)) + { + rc = xevent.xkey.keycode - 8; + } + + break; } - return rc & 0xFF;/* normalize */ + return rc & 0xFF; /* normalize */ } static void post_image() { @@ -404,65 +433,77 @@ static void post_image() { uint8_t index; unsigned int count = SCANWIDTH * SCANHEIGHT; - for (unsigned int i=0, j=0; idata + j) ) = (uint32_t)( - ((uint32_t)(colors[index].red) << red_shift) | - ((uint32_t)(colors[index].green) << green_shift) | - ((uint32_t)(colors[index].blue) << blue_shift) | - ((uint32_t)0xff /* alpha */ << alpha_shift) + ((uint32_t)(colors[index].red) << red_shift) | + ((uint32_t)(colors[index].green) << green_shift) | + ((uint32_t)(colors[index].blue) << blue_shift) | + ((uint32_t)0xff /* alpha */ << alpha_shift) ); } // post image... - if (doShm) { - if (!XShmPutImage( - display, - win, - gc, - image, - 0, 0, - 0, 0, - SCANWIDTH, SCANHEIGHT, - True)) - fprintf(stderr, "XShmPutImage() failed\n"); - } else { - if (XPutImage( - display, - win, - gc, - image, - 0, 0, - 0, 0, - SCANWIDTH, SCANHEIGHT - )) - fprintf(stderr, "XPutImage() failed\n"); + if (doShm) + { + if (!XShmPutImage( + display, + win, + gc, + image, + 0, 0, + 0, 0, + SCANWIDTH, SCANHEIGHT, + True)) + { + fprintf(stderr, "XShmPutImage() failed\n"); + } + } + else + { + if (XPutImage( + display, + win, + gc, + image, + 0, 0, + 0, 0, + SCANWIDTH, SCANHEIGHT + )) + { + fprintf(stderr, "XPutImage() failed\n"); + } } } static void c_flash_cursor(int on) { // flash only if it's text or mixed modes. - if (softswitches & (SS_TEXT|SS_MIXED)) { - if (!on) { - colors[ COLOR_FLASHING_BLACK].red = 0; - colors[ COLOR_FLASHING_BLACK].green = 0; - colors[ COLOR_FLASHING_BLACK].blue = 0; + if (softswitches & (SS_TEXT|SS_MIXED)) + { + if (!on) + { + colors[ COLOR_FLASHING_BLACK].red = 0; + colors[ COLOR_FLASHING_BLACK].green = 0; + colors[ COLOR_FLASHING_BLACK].blue = 0; - colors[ COLOR_FLASHING_WHITE].red = 0xffff; - colors[ COLOR_FLASHING_WHITE].green = 0xffff; - colors[ COLOR_FLASHING_WHITE].blue = 0xffff; - } else { - colors[ COLOR_FLASHING_WHITE].red = 0; - colors[ COLOR_FLASHING_WHITE].green = 0; - colors[ COLOR_FLASHING_WHITE].blue = 0; + colors[ COLOR_FLASHING_WHITE].red = 0xffff; + colors[ COLOR_FLASHING_WHITE].green = 0xffff; + colors[ COLOR_FLASHING_WHITE].blue = 0xffff; + } + else + { + colors[ COLOR_FLASHING_WHITE].red = 0; + colors[ COLOR_FLASHING_WHITE].green = 0; + colors[ COLOR_FLASHING_WHITE].blue = 0; - colors[ COLOR_FLASHING_BLACK].red = 0xffff; - colors[ COLOR_FLASHING_BLACK].green = 0xffff; - colors[ COLOR_FLASHING_BLACK].blue = 0xffff; - } + colors[ COLOR_FLASHING_BLACK].red = 0xffff; + colors[ COLOR_FLASHING_BLACK].green = 0xffff; + colors[ COLOR_FLASHING_BLACK].blue = 0xffff; + } - // store the colors to the current colormap - //XStoreColors(display, cmap, colors, 256); + // store the colors to the current colormap + //XStoreColors(display, cmap, colors, 256); } } @@ -473,39 +514,50 @@ void video_sync(int block) { // also process other input events post_image(); LOOP: - if (doShm) - XNextEvent( - display, - &xevent); - else if (!XCheckMaskEvent( - display, - KeyPressMask|KeyReleaseMask, - &xevent)) - goto POLL_FINISHED; - switch (xevent.type) { - case KeyPress: - c_read_raw_key(keysym_to_scancode(), 1); - break; - case KeyRelease: - c_read_raw_key(keysym_to_scancode(), 0); - break; - default: - if (xevent.type == xshmeventtype) - goto POLL_FINISHED; - break; - } - goto LOOP; + if (doShm) + { + XNextEvent( + display, + &xevent); + } + else + if (!XCheckMaskEvent( + display, + KeyPressMask|KeyReleaseMask, + &xevent)) + { + goto POLL_FINISHED; + } + + switch (xevent.type) + { + case KeyPress: + c_read_raw_key(keysym_to_scancode(), 1); + break; + case KeyRelease: + c_read_raw_key(keysym_to_scancode(), 0); + break; + default: + if (xevent.type == xshmeventtype) + { + goto POLL_FINISHED; + } + + break; + } + + goto LOOP; POLL_FINISHED: switch (++flash_count) { - case 6: + case 6: c_flash_cursor(1); break; - case 12: + case 12: c_flash_cursor(0); - flash_count = 0; + flash_count = 0; break; default: break; @@ -520,7 +572,7 @@ static Cursor hidecursor() { Cursor cursor; GC cursor_gc; - cursormask = XCreatePixmap(display, win, 1, 1, 1/*depth*/); + cursormask = XCreatePixmap(display, win, 1, 1, 1 /*depth*/); xgc.function = GXclear; cursor_gc = XCreateGC(display, cursormask, GCFunction, &xgc); XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); @@ -536,64 +588,72 @@ static Cursor hidecursor() { static void parseArgs() { int i; - for (i=0; i>shift) & 0xff) == (uint32_t)0xff) { - fprintf(stderr, "no such visual\n"); + red_shift = shift; + } + else + if ((((uint32_t)visualinfo.green_mask>>shift) & 0xff) == (uint32_t)0xff) + { + green_shift = shift; + } + else + if ((((uint32_t)visualinfo.blue_mask >>shift) & 0xff) == (uint32_t)0xff) + { + blue_shift = shift; + } + else + { + alpha_shift = shift; + } + + shift += 8; + } + + if ((!red_shift) && (!green_shift) && (!blue_shift)) + { + fprintf(stderr, "Could not calculate red/green/blue color masks...\n"); + exit(1); + } + + fprintf(stderr, "red mask:%08x green mask:%08x blue mask:%08x\n", (uint32_t)visualinfo.red_mask, (uint32_t)visualinfo.blue_mask, (uint32_t)visualinfo.green_mask); + fprintf(stderr, "redshift:%08d greenshift:%08d blueshift:%08d alphashift:%08d\n", red_shift, blue_shift, green_shift, alpha_shift); + + /* Note that in a real Xlib application, x and y would default to 0 + * but would be settable from the command line or resource database. + */ + x = y = 0; + width = SCANWIDTH, height = SCANHEIGHT; + + /* init MITSHM if we're doing it */ + if (doShm) + { + /* make sure we have it */ + doShm = XShmQueryExtension(display); + } + + displayname = getenv("DISPLAY"); + if (displayname) + { + if (*displayname != ':') + { + printf("NOTE: Sound not allowed for remote display \"%s\".\n", displayname); + if (doShm) + { + printf("NOTE: Cannot run MITSHM version of emulator with display \"%s\"\n" + "Try setting DISPLAY to something like \":0.0\"...Reverting to regular X.\n", + displayname); + } + + doShm=0; + soundAllowed=0; + } + } + + /* initialize colors */ + c_initialize_colors(); + + cmap = XCreateColormap(display, XDefaultRootWindow(display), visualinfo.visual, AllocNone); + //XStoreColors(display, cmap, colors, 256); + attribs.colormap = cmap; + attribs.border_pixel = 0; + + /* select event types wanted */ + attribmask = CWEventMask | CWColormap | CWBorderPixel; /* HACK CWBorderPixel? */ + attribs.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask; + + /* create opaque window */ + win = XCreateWindow(display, RootWindow(display, screen_num), + x, y, width, height, + 0, /* border_width */ + visualinfo.depth, /* depth */ + InputOutput, + visualinfo.visual, + attribmask, + &attribs); + + /* set size hints for window manager. We don't want the user to + * dynamically allocate window size since we won't do the right + * scaling in response. Whaddya want, performance or a snazzy gui? + */ + size_hints->flags = PPosition | PSize | PMinSize | PMaxSize; + size_hints->min_width = width; + size_hints->min_height = height; + size_hints->max_width = width; + size_hints->max_height = height; + + /* store window_name and icon_name for niceity. */ + if (XStringListToTextProperty(&window_name, 1, &windowName) == 0) + { + fprintf(stderr, "structure allocation for windowName failed.\n"); + exit(1); + } + + if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0) + { + fprintf(stderr, "structure allocation for iconName failed.\n"); + exit(1); + } + + // set up window manager hints... + wm_hints->initial_state = NormalState; + wm_hints->input = True; + wm_hints->flags = StateHint | IconPixmapHint /* | InputHint*/; + + class_hints->res_name = progname; + class_hints->res_class = "Apple2"; + + XSetWMProperties(display, win, &windowName, &iconName, + argv, argc, size_hints, wm_hints, + class_hints); + + // FIXME!!!!! hidecursor segfaults + //XDefineCursor(display, win, hidecursor(display, win)); + + /* create the GC */ + valuemask = GCGraphicsExposures; + xgcvalues.graphics_exposures = False; + gc = XCreateGC(display, win, valuemask, &xgcvalues); + + /* display window */ + XMapWindow(display, win); + + /* wait until it is OK to draw */ + drawingok = 0; + while (!drawingok) + { + XNextEvent(display, &xevent); + if ((xevent.type == Expose) && !xevent.xexpose.count) + { + drawingok = 1; + } + } + + // pad pixels to uint32_t boundaries + int bitmap_pad = sizeof(uint32_t); + int pixel_buffer_size = SCANWIDTH*SCANHEIGHT*bitmap_pad; + + xshmeventtype = XShmGetEventBase(display) + ShmCompletion; + + /* create the image */ + if (doShm) + { + image = XShmCreateImage(display, visualinfo.visual, visualinfo.depth, ZPixmap, NULL, &xshminfo, SCANWIDTH, SCANHEIGHT); + + if (!image) + { + fprintf(stderr, "XShmCreateImage failed\n"); exit(1); } - // determine mask bits ... - // red_mask: 00ff0000 - // green_mask: 0000ff00 - // blue_mask: 000000ff - // bits_per_rgb: 8 - unsigned int shift = 0; - for (unsigned int i=0; i<4; i++) { - if ((((uint32_t)visualinfo.red_mask >>shift) & 0xff) == (uint32_t)0xff) { - red_shift = shift; - } else if ((((uint32_t)visualinfo.green_mask>>shift) & 0xff) == (uint32_t)0xff) { - green_shift = shift; - } else if ((((uint32_t)visualinfo.blue_mask >>shift) & 0xff) == (uint32_t)0xff) { - blue_shift = shift; - } else { - alpha_shift = shift; - } - shift += 8; - } - if ((!red_shift) && (!green_shift) && (!blue_shift)) { - fprintf(stderr, "Could not calculate red/green/blue color masks...\n"); + printf("Allocating shared memory: bytes_per_line:%ds height:x%d (depth:%d) bitmap_pad:%d\n", + image->bytes_per_line, image->height, visualinfo.depth, bitmap_pad); + + getshm(pixel_buffer_size); + + /* get the X server to attach to it */ + if (!XShmAttach(display, &xshminfo)) + { + fprintf(stderr, "XShmAttach() failed in InitGraphics()\n"); exit(1); } - fprintf(stderr, "red mask:%08x green mask:%08x blue mask:%08x\n", (uint32_t)visualinfo.red_mask, (uint32_t)visualinfo.blue_mask, (uint32_t)visualinfo.green_mask); - fprintf(stderr, "redshift:%08d greenshift:%08d blueshift:%08d alphashift:%08d\n", red_shift, blue_shift, green_shift, alpha_shift); - - /* Note that in a real Xlib application, x and y would default to 0 - * but would be settable from the command line or resource database. - */ - x = y = 0; - width = SCANWIDTH, height = SCANHEIGHT; - - /* init MITSHM if we're doing it */ - if (doShm) { - /* make sure we have it */ - doShm = XShmQueryExtension(display); + } + else + { + void *data = malloc(pixel_buffer_size); // pad to uint32_t + if (!data) + { + fprintf(stderr, "no memory for image data!\n"); + exit(1); } - displayname = getenv("DISPLAY"); - if (displayname) { - if (*displayname != ':') { - printf("NOTE: Sound not allowed for remote display \"%s\".\n", displayname); - if (doShm) { - printf("NOTE: Cannot run MITSHM version of emulator with display \"%s\"\n" - "Try setting DISPLAY to something like \":0.0\"...Reverting to regular X.\n", - displayname); - } - doShm=0; - soundAllowed=0; - } + printf("Creating regular XImage\n"); + image = XCreateImage(display, visualinfo.visual, visualinfo.depth, ZPixmap, 0 /*offset*/, data, SCANWIDTH, SCANHEIGHT, 8, SCANWIDTH*bitmap_pad /*bytes_per_line*/); + + if (!image) + { + fprintf(stderr, "XCreateImage failed\n"); + exit(1); } + } - /* initialize colors */ - c_initialize_colors(); + video__fb1 = vga_mem_page_0; + video__fb2 = vga_mem_page_1; - cmap = XCreateColormap(display, XDefaultRootWindow(display), visualinfo.visual, AllocNone); - //XStoreColors(display, cmap, colors, 256); - attribs.colormap = cmap; - attribs.border_pixel = 0; - - /* select event types wanted */ - attribmask = CWEventMask | CWColormap | CWBorderPixel;/* HACK CWBorderPixel? */ - attribs.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask; - - /* create opaque window */ - win = XCreateWindow(display, RootWindow(display, screen_num), - x, y, width, height, - 0,/* border_width */ - visualinfo.depth,/* depth */ - InputOutput, - visualinfo.visual, - attribmask, - &attribs); - - /* set size hints for window manager. We don't want the user to - * dynamically allocate window size since we won't do the right - * scaling in response. Whaddya want, performance or a snazzy gui? - */ - size_hints->flags = PPosition | PSize | PMinSize | PMaxSize; - size_hints->min_width = width; - size_hints->min_height = height; - size_hints->max_width = width; - size_hints->max_height = height; - - /* store window_name and icon_name for niceity. */ - if (XStringListToTextProperty(&window_name, 1, &windowName) == 0) { - fprintf(stderr, "structure allocation for windowName failed.\n"); - exit(1); - } - - if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0) { - fprintf(stderr, "structure allocation for iconName failed.\n"); - exit(1); - } - - // set up window manager hints... - wm_hints->initial_state = NormalState; - wm_hints->input = True; - wm_hints->flags = StateHint | IconPixmapHint/* | InputHint*/; - - class_hints->res_name = progname; - class_hints->res_class = "Apple2"; - - XSetWMProperties(display, win, &windowName, &iconName, - argv, argc, size_hints, wm_hints, - class_hints); - - // FIXME!!!!! hidecursor segfaults - //XDefineCursor(display, win, hidecursor(display, win)); - - /* create the GC */ - valuemask = GCGraphicsExposures; - xgcvalues.graphics_exposures = False; - gc = XCreateGC(display, win, valuemask, &xgcvalues); - - /* display window */ - XMapWindow(display, win); - - /* wait until it is OK to draw */ - drawingok = 0; - while (!drawingok) - { - XNextEvent(display, &xevent); - if ((xevent.type == Expose) && !xevent.xexpose.count) - { - drawingok = 1; - } - } - - // pad pixels to uint32_t boundaries - int bitmap_pad = sizeof(uint32_t); - int pixel_buffer_size = SCANWIDTH*SCANHEIGHT*bitmap_pad; - - xshmeventtype = XShmGetEventBase(display) + ShmCompletion; - - /* create the image */ - if (doShm) { - image = XShmCreateImage(display, visualinfo.visual, visualinfo.depth, ZPixmap, NULL, &xshminfo, SCANWIDTH, SCANHEIGHT); - - if (!image) { - fprintf(stderr, "XShmCreateImage failed\n"); - exit(1); - } - - printf("Allocating shared memory: bytes_per_line:%ds height:x%d (depth:%d) bitmap_pad:%d\n", - image->bytes_per_line, image->height, visualinfo.depth, bitmap_pad); - - getshm(pixel_buffer_size); - - /* get the X server to attach to it */ - if (!XShmAttach(display, &xshminfo)) { - fprintf(stderr, "XShmAttach() failed in InitGraphics()\n"); - exit(1); - } - } else { - void *data = malloc(pixel_buffer_size); // pad to uint32_t - if (!data) { - fprintf(stderr, "no memory for image data!\n"); - exit(1); - } - printf("Creating regular XImage\n"); - image = XCreateImage(display, visualinfo.visual, visualinfo.depth, ZPixmap, 0/*offset*/, data, SCANWIDTH, SCANHEIGHT, 8, SCANWIDTH*bitmap_pad/*bytes_per_line*/); - - if (!image) { - fprintf(stderr, "XCreateImage failed\n"); - exit(1); - } - } - - video__fb1 = vga_mem_page_0; - video__fb2 = vga_mem_page_1; - - // reset Apple2 softframebuffers - memset(video__fb1,0,SCANWIDTH*SCANHEIGHT); - memset(video__fb2,0,SCANWIDTH*SCANHEIGHT); + // reset Apple2 softframebuffers + memset(video__fb1,0,SCANWIDTH*SCANHEIGHT); + memset(video__fb2,0,SCANWIDTH*SCANHEIGHT); } void video_shutdown(void) { - if (doShm) { - // Detach from X server - if (!XShmDetach(display, &xshminfo)) - fprintf(stderr,"XShmDetach() failed in video_shutdown()\n"); + if (doShm) + { + // Detach from X server + if (!XShmDetach(display, &xshminfo)) + { + fprintf(stderr,"XShmDetach() failed in video_shutdown()\n"); + } - // Release shared memory. - shmdt(xshminfo.shmaddr); - shmctl(xshminfo.shmid, IPC_RMID, 0); + // Release shared memory. + shmdt(xshminfo.shmaddr); + shmctl(xshminfo.shmid, IPC_RMID, 0); - // Paranoia. - image->data = NULL; - } else { - free(image->data); + // Paranoia. + image->data = NULL; + } + else + { + free(image->data); } exit(0);