an uncrustify pass and uncrustify config file

This commit is contained in:
Aaron Culliney 2013-07-05 21:37:13 -07:00
parent 18c3f5f698
commit e919718b73
24 changed files with 6550 additions and 4943 deletions

View File

@ -29,10 +29,10 @@
/* Symbol naming issues */
#ifdef NO_UNDERSCORES
#define SN(foo) foo
#define E(foo) .globl foo ; ALIGN ; foo##:
#define E(foo) .globl foo; ALIGN; foo##:
#else /* !NO_UNDERSCORES */
#define SN(foo) _##foo
#define E(foo) .globl _##foo ; ALIGN ; _##foo##:
#define E(foo) .globl _##foo; ALIGN; _##foo##:
#endif /* !NO_UNDERSCORES */
#endif/* A2_H */
#endif /* A2_H */

View File

@ -38,21 +38,44 @@ static void initialize_code_tables(void)
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;
}
cpu65_flags_encode[ i ] = val | 0x20;
cpu65_flags_decode[ val ] = i;
@ -68,9 +91,14 @@ void cpu65_set(int flags)
{
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__cmos,1024);

412
src/crusty.cfg Normal file
View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -37,10 +37,10 @@ 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 };
{ 0,7,14,6,13,5,12,4,11,3,10,2,9,1,8,15 };
static int translate_table_6[256] =/* Translation table */
{
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,
@ -73,7 +73,7 @@ static int translate_table_6[256] =/* Translation table */
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()
@ -101,27 +101,34 @@ void c_init_6()
void c_eject_6(int drive) {
pid_t pid;
if (disk6.disk[drive].compressed) {
if (disk6.disk[drive].compressed)
{
/* gzip the last disk if it was compressed_6 */
if ((pid = fork())) { /* parent process */
/* privileged mode - gzip in place */
if ((pid = fork())) /* parent process */
{ /* privileged mode - gzip in place */
waitpid(pid, NULL, 0);
} else if (!pid) { /* child process */
/* privileged mode - gzip in place */
}
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 {
}
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) {
if (disk6.disk[drive].fp)
{
fclose(disk6.disk[drive].fp);
disk6.disk[drive].fp = NULL;
}
@ -141,35 +148,45 @@ int c_new_diskette_6(int drive, char *file_name, int cmpr, int nib, int force) {
disk6.disk[drive].file_name[1023]='\0';
disk6.disk[drive].compressed = cmpr;
disk6.disk[drive].nibblized = nib;
if (disk6.disk[drive].fp) {
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) {
if (stat(disk6.disk[drive].file_name, &buf) < 0)
{
disk6.disk[drive].fp = NULL;
c_eject_6(drive);
return 1; /* problem: disk unreadable */
}
else {
else
{
disk6.disk[drive].file_size = buf.st_size;
if (!force) {
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)) {
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) {
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);
}
@ -191,15 +208,19 @@ unsigned char c_read_nibblized_6_6()
{
static unsigned char ch;
if (disk6.disk[disk6.drive].phase_change) {
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);
}
return ch;
}
@ -306,15 +327,19 @@ unsigned char c_read_normal_6()
/* 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) {
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;
@ -326,7 +351,9 @@ unsigned char c_read_normal_6()
/* 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;
@ -354,13 +381,16 @@ unsigned char c_read_normal_6()
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_byte = value;
return value;
@ -376,14 +406,18 @@ unsigned char c_read_normal_6()
void c_write_nibblized_6_6()
{
if (disk6.disk[disk6.drive].phase_change) {
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);
}
}
/* -------------------------------------------------------------------------
@ -396,8 +430,11 @@ void c_write_normal_6()
int old_value;
if (disk6.disk_byte == 0xD5)
{
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)
@ -410,7 +447,10 @@ void c_write_normal_6()
case 6: case 25:
/* Prologue (first byte) */
if (disk6.disk_byte == 0xFF)
{
disk6.disk[disk6.drive].run_byte--;
}
break;
case 7: case 26:
@ -420,7 +460,10 @@ void c_write_normal_6()
case 8:
/* Prologue (third byte) */
if (disk6.disk_byte == 0xAD)
{
disk6.exor_value = 0, disk6.disk[disk6.drive].run_byte = 27;
}
break;
case 9: case 10:
@ -466,7 +509,9 @@ void c_write_normal_6()
/* Is the file large enough? */
if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size)
{
return;
}
/* Set position */
@ -478,7 +523,10 @@ void c_write_normal_6()
/* 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:
@ -504,12 +552,15 @@ void c_write_normal_6()
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;
}
}
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 */
}
if (disk6.disk[disk6.drive].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 */
}
(disk6.disk[disk6.drive].nibblized) ? c_write_nibblized_6_6() : c_write_normal_6();
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++;
}
}
/* 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();
}
}
@ -566,8 +633,15 @@ GLUE_C_READ(disk_read_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;
@ -628,18 +702,24 @@ void disk_install(int slot)
assert(slot == 6);
/* load Disk II rom */
if (!slot6_rom_loaded) {
if (!slot6_rom_loaded)
{
snprintf(temp, TEMPSIZE, "%s/slot6.rom", system_path);
if ((f = fopen( temp, "r" )) == NULL) {
if ((f = fopen( temp, "r" )) == NULL)
{
printf("Cannot find file '%s'.\n",temp);
exit( 0 );
}
if (fread(slot6_rom, 0x100, 1, f) != 0x100) {
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 */
@ -668,7 +748,8 @@ void disk_install(int slot)
cpu65_vmem[0xC0EF].r =
disk_read_prepare_out;
for (i = 0xC0E0; i < 0xC0F0; i++) {
for (i = 0xC0E0; i < 0xC0F0; i++)
{
cpu65_vmem[i].w =
cpu65_vmem[i].r;
}

View File

@ -53,16 +53,16 @@ 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();
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

View File

@ -53,14 +53,21 @@ int main(void)
while (getline(&line,&line_size,stdin) != -1)
{
if (line[0] == ';') continue;
if (line[0] == ';')
{
continue;
}
if (line[0] == '=')
{
char *name,*size;
name = line + 1;
while (isspace(*name)) name++;
while (isspace(*name))
{
name++;
}
size = strchr(name,',');
*size++ = 0;
mx = i = strtol(size,0,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--)
@ -92,14 +101,24 @@ int main(void)
}
if (j)
{
printf("0x%02x, ",byte);
else if (i)
printf("0x%02x,\n ",byte); /* last byte in glyph */
}
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;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
#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_interface_redo_bottom(); /* bit of a HACK? */
void c_load_interface_font();
void c_interface_keyboard_layout();
void c_interface_parameters();

View File

@ -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 */
{
return 1; /* problem */
}
}
/* set timelimit value */
if (ioctl(js_fd, JS_SET_TIMELIMIT, &js_timelimit) == -1)
return 1;/* problem */
{
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;
}
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,8 +121,10 @@ 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 */
if (js_fd < 0)
{
if (c_open_joystick()) /* problem opening device */
{
c_interface_print(
1, 21, 0, " " );
c_interface_print(
@ -119,7 +132,7 @@ void c_calibrate_joystick () {
video_sync(0);
usleep(1500000);
c_interface_redo_bottom();
return;/* problem */
return; /* problem */
}
}
@ -137,24 +150,39 @@ void c_calibrate_joystick () {
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);
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;
}
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;
js_center_y = js.y;
@ -188,20 +216,22 @@ void c_calibrate_joystick () {
video_sync(0);
/* show the normalized values until user presses button */
while ((read(js_fd, &js, JS_RETURN) > 0) && js.buttons == 0x00) {
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 +
: (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 +
: (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);
}

View File

@ -53,152 +53,152 @@ 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 */
{ -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 */
'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 */
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 */
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 */
{ -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 */
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 */
{ -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 */
'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 */
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 */
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 */
{ -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 */
'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 */
'\'', '`', -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 */
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 */
{ -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 */
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 */
{ -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 */
'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 */
'"', '~', -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 */
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 */
{ -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 */
'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 */
'\'', '`', -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 */
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 */
{ -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 */
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;
@ -225,10 +225,15 @@ void c_periodic_update(int dummysig) {
current_key = next_key;
next_key = -1;
if (current_key < 128) {
if (current_key < 128)
{
apple_ii_64k[0][0xC000] = current_key | 0x80;
apple_ii_64k[1][0xC000] = current_key | 0x80;
} else switch (current_key) {
}
else
{
switch (current_key)
{
case RST:
cpu65_interrupt(ResetSig);
break;
@ -246,7 +251,10 @@ void c_periodic_update(int dummysig) {
c_interface_select_diskette( 1 );
break;
case kF4:
while (c_mygetch(1) == -1) { }/*busy loop*/
while (c_mygetch(1) == -1)
{
} /*busy loop*/
break;
case kF5:
c_interface_keyboard_layout();
@ -261,55 +269,85 @@ void c_periodic_update(int dummysig) {
#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;
}
}
}
/* simulated joystick */
if (joy_mode == JOY_KYBD) {
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_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;
}
}
}
#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
}
@ -336,15 +374,26 @@ void c_periodic_update(int dummysig) {
/* 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
@ -363,64 +412,91 @@ 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) {
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 */
}
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 */
}
else
if (key_pressed[ SCODE_L_SHIFT ] || /* shift */
key_pressed[ SCODE_R_SHIFT ])
{
keymap = apple_iie_keymap_shifted;
else if (caps_lock) /* caps lock */
}
else
if (caps_lock) /* caps lock */
{
keymap = apple_iie_keymap_caps;
}
else /* plain */
{
keymap = apple_iie_keymap_plain;
} else
}
}
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
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;
switch (keymap[ scancode ]) {
switch (keymap[ scancode ])
{
case JB0:
joy_button0 = 0xff;/* open apple */
joy_button0 = 0xff; /* open apple */
break;
case JB1:
joy_button1 = 0xff;/* closed apple */
joy_button1 = 0xff; /* closed apple */
break;
case JB2:
joy_button2 = 0xff;/* unused? */
joy_button2 = 0xff; /* unused? */
break;
default:
next_key = keymap[scancode];
break;
}
}
/* key is released */
else {
else
{
key_pressed[ scancode ] = 0;
switch (keymap[ scancode ]) {
switch (keymap[ scancode ])
{
case JB0:
joy_button0 = 0x00;
break;
@ -440,10 +516,17 @@ int c_mygetch(int block)
in_mygetch = 1;
if (block) while (next_key == -1)
if (block)
{
while (next_key == -1)
{
video_sync(1);
}
}
else
{
video_sync(0);
}
in_mygetch = 0;

View File

@ -98,7 +98,7 @@ void c_set_primary_char()
video_redraw();
}
#endif/* APPLE_IIE */
#endif /* APPLE_IIE */
/* -------------------------------------------------------------------------
@ -128,12 +128,15 @@ 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) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[i].r = iie_read_ram_default;
cpu65_vmem[i].w = iie_write_ram_default;
} else
}
else
#endif
{
cpu65_vmem[i].r = read_ram_default;
@ -142,7 +145,8 @@ void c_initialize_tables() {
}
/* language card read/write area */
for (i = 0xD000; i < 0xE000; i++) {
for (i = 0xD000; i < 0xE000; i++)
{
{
cpu65_vmem[i].w =
write_ram_bank;
@ -150,7 +154,9 @@ void c_initialize_tables() {
read_ram_bank;
}
}
for (i = 0xE000; i < 0x10000; i++) {
for (i = 0xE000; i < 0x10000; i++)
{
{
cpu65_vmem[i].w =
write_ram_lc;
@ -158,18 +164,22 @@ void c_initialize_tables() {
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++) {
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
@ -179,22 +189,27 @@ void c_initialize_tables() {
* affect the display, leaving our write-functions in place only at the
* `screen holes', hence the name.
*/
for (i = 0x400; i < 0x800; i++) {
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++) {
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++) {
for (i = 0xC000; i < 0xC100; i++)
{
cpu65_vmem[i].r =
read_unmapped_softswitch;
cpu65_vmem[i].w =
@ -202,7 +217,8 @@ void c_initialize_tables() {
}
/* slot rom */
for (i = 0xC100; i < 0xD000; i++) {
for (i = 0xC100; i < 0xD000; i++)
{
cpu65_vmem[i].r =
#ifdef APPLE_IIE
iie_read_ram_default;
@ -214,18 +230,22 @@ void c_initialize_tables() {
}
/* keyboard data and strobe (READ) */
for (i = 0xC000; i < 0xC010; i++) {
for (i = 0xC000; i < 0xC010; i++)
{
cpu65_vmem[i].r =
read_keyboard;
}
for (i = 0xC010; i < 0xC020; i++) {
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 =
@ -279,13 +299,16 @@ void c_initialize_tables() {
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;
}
/* TEXT switch */
cpu65_vmem[0xC050].r =
@ -296,10 +319,12 @@ void c_initialize_tables() {
read_switch_text;
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC01A].r =
iie_check_text;
}
#endif
/* MIXED switch */
@ -311,16 +336,20 @@ void c_initialize_tables() {
read_switch_mixed;
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC01B].r =
iie_check_mixed;
}
/* PAGE2 switch */
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC054].r =
cpu65_vmem[0xC054].w =
iie_page2_off;
} else
}
else
#endif
{
cpu65_vmem[0xC054].r =
@ -329,16 +358,20 @@ void c_initialize_tables() {
}
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC01C].r =
iie_check_page2;
}
/* PAGE2 switch */
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC055].r =
cpu65_vmem[0xC055].w =
iie_page2_on;
} else
}
else
#endif
{
cpu65_vmem[0xC055].r =
@ -348,7 +381,8 @@ void c_initialize_tables() {
/* HIRES switch */
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[0xC01D].r =
iie_check_hires;
cpu65_vmem[0xC056].r =
@ -386,20 +420,25 @@ void c_initialize_tables() {
cpu65_vmem[0xC06D].r =
read_gc1;
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
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;
}
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
/* IOUDIS switch & read_gc_strobe */
cpu65_vmem[0xC07E].w =
iie_ioudis_on;
@ -418,6 +457,7 @@ void c_initialize_tables() {
cpu65_vmem[0xC05F].r =
iie_dhires_off;
}
#endif
#ifdef APPLE_IIE
@ -478,22 +518,30 @@ void c_initialize_tables() {
#ifdef APPLE_IIE
/* slot i/o area */
for (i = 0xC100; i < 0xC300; i++) {
for (i = 0xC100; i < 0xC300; i++)
{
cpu65_vmem[i].r =
iie_read_slotx; /* slots 1 & 2 (x) */
}
for (i = 0xC300; i < 0xC400; i++) {
for (i = 0xC300; i < 0xC400; i++)
{
cpu65_vmem[i].r =
iie_read_slot3; /* slot 3 (80col) */
}
for (i = 0xC400; i < 0xC800; i++) {
for (i = 0xC400; i < 0xC800; i++)
{
cpu65_vmem[i].r =
iie_read_slotx; /* slots 4 - 7 (x) */
}
for (i = 0xC800; i < 0xD000; i++) {
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;
@ -520,64 +568,95 @@ void c_initialize_apple_ii_memory()
static int iie_rom_loaded = 0;
#endif
for (i = 0; i < 0x10000; i++) {
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;
}
if (!ii_rom_loaded)
{
snprintf(temp, TEMPSIZE, "%s/apple_II.rom", system_path);
if ((f = fopen(temp, "r")) == NULL) {
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) {
if (fread(apple_ii_rom, 0x3000, 1, f) != 0x3000)
{
// ERROR ...
}
fclose(f);
ii_rom_loaded = 1;
}
#ifdef APPLE_IIE
if (!iie_rom_loaded) {
if (!iie_rom_loaded)
{
snprintf(temp, TEMPSIZE, "%s/apple_IIe.rom", system_path);
if ((f = fopen(temp, "r")) == NULL) {
if ((f = fopen(temp, "r")) == NULL)
{
printf("Cannot find file '%s'.\n",temp);
exit(0);
}
if (fread(apple_iie_rom, 32768, 1, f) != 32768) {
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];
}
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
/* load the rom from 0xC000, slot rom main, internal rom aux */
for (i = 0xC000; i < 0x10000; i++) {
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++) {
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++) {
for (i = 0; i < 0x2000; i++)
{
language_card[0][i] = apple_iie_rom[i + 0x2000];
language_card[1][i] = apple_iie_rom[i + 0x6000];
}
@ -586,7 +665,8 @@ void c_initialize_apple_ii_memory()
#endif
/* softswitch memory HACK - why this? */
{
for (i = 0xC100; i < 0xD000; i++) {
for (i = 0xC100; i < 0xD000; i++)
{
apple_ii_64k[0][i] = i & 0xFF;
apple_ii_64k[1][i] = i & 0xFF;
}
@ -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;
}
}
#ifdef APPLE_IIE
@ -662,11 +744,14 @@ static void reinitialize(void)
int i;
/* reset the watchpoints and breakpoints */
for (i=0; i<MAX_BRKPTS; i++) {
for (i=0; i<MAX_BRKPTS; i++)
{
breakpoints[i] = -1;
watchpoints[i] = -1;
}
for (i=0; i<0x100; i++) {
for (i=0; i<0x100; i++)
{
op_breakpoints[(unsigned char)i] = 0;
}
@ -680,26 +765,36 @@ static void reinitialize(void)
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE)
{
cpu65_set(CPU65_C02);
}
else
#endif
if (apple_mode == IIU_MODE)
{
cpu65_set(CPU65_NMOS);
}
else
{
cpu65_set(CPU65_NMOS|CPU65_FAULT);
}
}
static void c_initialize_firsttime()
{
/* get IO permission for speaker port. */
if (/*ioperm(0x42, 1, 1) ||*/ ioperm(0x61, 1, 1)) {
if (/*ioperm(0x42, 1, 1) ||*/ ioperm(0x61, 1, 1))
{
perror("ioperm");
printf("cannot get port access to PC speaker.\n");
printf("sound will not be used.\n");
soundAllowed=0;
} else
}
else
{
soundAllowed=1;
}
/* read in system files and calculate system defaults */
c_load_interface_font();
@ -714,16 +809,18 @@ void c_read_random() {
random_value = (unsigned char)(rand() >> 8);
}
static void cpu_thread (void *dummyptr) {
static void cpu_thread(void *dummyptr) {
do {
do
{
cpu65_run();
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);

View File

@ -60,7 +60,7 @@ int argc;
/* misc arrays */
#define TEMPSIZE 4096
char temp[ TEMPSIZE ];/* should be >=4096 (stuff depends on this) */
char temp[ TEMPSIZE ]; /* should be >=4096 (stuff depends on this) */
#ifdef APPLE_IIE
/* memory offsets from softswitches */
@ -142,117 +142,117 @@ void compact(void);
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(),
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();
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(),
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__ */

File diff suppressed because it is too large Load Diff

View File

@ -68,90 +68,93 @@ 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},
{ "pc joystick", JOY_PCJOY },
{ "pc_joystick", JOY_PCJOY },
#endif /* PC_JOYSTICK */
#if 0
{"digital", JOY_DIGITAL},
{ "digital", JOY_DIGITAL },
#endif /* 0 */
{0, JOY_KYBD}
{ 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
* default. */
static int
match (const struct match_table *paradigm, const char *keyword)
match(const struct match_table *paradigm, const char *keyword)
{
while (paradigm->tag && strcasecmp (paradigm->tag, keyword))
while (paradigm->tag && strcasecmp(paradigm->tag, keyword))
{
paradigm++;
}
return paradigm->value;
}
@ -161,10 +164,13 @@ match (const struct match_table *paradigm, const char *keyword)
*
* 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;
}
@ -172,16 +178,22 @@ static const char *reverse_match (const struct match_table *paradigm, int key)
* overwritten and a new pointer is returned.
*/
static char *
clean_string (char *x)
clean_string(char *x)
{
size_t y;
/* Leading white space */
while (isspace (*x)) x++;
while (isspace(*x))
{
x++;
}
/* Trailing white space */
y = strlen (x);
while (y && x[y--] == ' ');
y = strlen(x);
while (y && x[y--] == ' ')
{
}
x[y] = 0;
return x;
@ -189,19 +201,19 @@ clean_string (char *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");
strcpy(disk_path, "./disks");
strcpy(system_path, "./rom");
{
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 */
@ -212,18 +224,18 @@ load_settings (void)
char *buffer = 0;
size_t size = 0;
config_file = fopen (config_filename, "r");
config_file = fopen(config_filename, "r");
if (config_file == NULL)
{
printf (
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 ();
printf("Press RETURN to continue...");
getchar();
return;
}
while (getline (&buffer, &size, config_file) != -1)
while (getline(&buffer, &size, config_file) != -1)
{
char *parameter;
char *argument;
@ -231,88 +243,120 @@ load_settings (void)
/* Split line between parameter and argument */
parameter = buffer;
argument = strchr (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))
switch (match(prefs_table, parameter))
{
case PRM_NONE:
fprintf (stderr, "Unrecognized config parameter `%s'", parameter);
fprintf(stderr, "Unrecognized config parameter `%s'", parameter);
break;
case PRM_SPEED:
{
int x;
x = strtol (argument, 0, 0);
x = strtol(argument, 0, 0);
if (x < 0)
{
x = 0;
}
cpu65_delay = MAX_APPLE_DELAY - x + 1;
if (cpu65_delay < 1)
{
cpu65_delay = 1;
}
}
break;
case PRM_MODE:
apple_mode = match (modes_table, argument);
apple_mode = match(modes_table, argument);
break;
case PRM_DISK_PATH:
strncpy (disk_path, argument, DISKSIZE);
strncpy(disk_path, argument, DISKSIZE);
break;
case PRM_HIRES_COLOR:
color_mode = match (color_table, argument);
color_mode = match(color_table, argument);
break;
case PRM_SOUND:
sound_mode = match (sound_table, argument);
sound_mode = match(sound_table, argument);
break;
case PRM_JOY_INPUT:
joy_mode = match (joy_input_table, argument);
joy_mode = match(joy_input_table, argument);
break;
case PRM_JOY_RANGE:
joy_range = strtol (argument, 0, 0);
joy_range = strtol(argument, 0, 0);
if (joy_range < 10)
{
joy_range = 10;
else if (joy_range > 256)
}
else
if (joy_range > 256)
{
joy_range = 256;
}
half_joy_range = joy_range / 2;
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;
case PRM_JOY_OX:
joy_center_x = strtol (argument, 0, 0);
joy_center_x = strtol(argument, 0, 0);
if (joy_center_x < 0)
{
joy_center_x = 0;
else if (joy_center_x > 255)
}
else
if (joy_center_x > 255)
{
joy_center_x = 255;
}
if (joy_center_x > joy_range)
{
joy_center_x = half_joy_range;
}
break;
case PRM_JOY_OY:
joy_center_y = strtol (argument, 0, 0);
joy_center_y = strtol(argument, 0, 0);
if (joy_center_y < 0)
{
joy_center_y = 0;
else if (joy_center_y > 255)
}
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:
@ -320,64 +364,83 @@ load_settings (void)
/* 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);
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);
}
js_min_x = strtol(argument, &argument, 10);
if (js_min_x < 0)
{
js_min_x = 0;
}
js_max_y = strtol (argument, &argument, 10);
js_max_y = strtol(argument, &argument, 10);
if (js_max_y < 0)
{
js_max_y = 0;
js_min_y = strtol (argument, &argument, 10);
}
js_min_y = strtol(argument, &argument, 10);
if (js_min_y < 0)
{
js_min_y = 0;
}
js_timelimit = strtol (argument, &argument, 10);
js_timelimit = strtol(argument, &argument, 10);
if (js_timelimit < 2)
{
js_timelimit = 2;
}
c_open_joystick ();
c_calculate_joystick_parms (); /* calculate the associated parms */
c_open_joystick();
c_calculate_joystick_parms(); /* calculate the associated parms */
#endif
case PRM_JOY_KYBD_SENSITIVITY:
joy_step = strtol (argument, 0, 0);
joy_step = strtol(argument, 0, 0);
if (joy_step < 1)
{
joy_step = 1;
else if (joy_step > 100)
}
else
if (joy_step > 100)
{
joy_step = 100;
}
break;
case PRM_ROM_PATH:
strncpy (system_path, argument, SYSSIZE);
strncpy(system_path, argument, SYSSIZE);
break;
}
}
fclose (config_file);
fclose(config_file);
}
}
/* Save the configuration */
void
save_settings (void)
save_settings(void)
{
FILE *config_file;
config_file = fopen (config_filename, "w");
config_file = fopen(config_filename, "w");
if (config_file == NULL)
{
printf (
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,
fprintf(config_file,
"speed = %d\n"
"mode = %s\n"
"disk path = %s\n"
@ -390,11 +453,11 @@ save_settings (void)
"sensitivity = %d%%\n"
"system path = %s\n",
MAX_APPLE_DELAY + 1 - cpu65_delay,
reverse_match (modes_table, apple_mode),
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),
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,
@ -402,11 +465,11 @@ save_settings (void)
system_path);
#ifdef PC_JOYSTICK
fprintf (config_file,
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);
}

View File

@ -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,23 +92,28 @@ 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))

View File

@ -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

View File

@ -200,31 +200,31 @@ 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();
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();
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__ */

View File

@ -65,7 +65,7 @@ void video_loadfont(int first,
int i,j;
unsigned char x,y,fg,bg;
switch(mode)
switch (mode)
{
case 2:
fg = COLOR_BLACK; bg = COLOR_LIGHT_WHITE; break;
@ -95,12 +95,12 @@ void video_loadfont(int first,
}
}
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,
{ 0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380,
0x028, 0x0A8, 0x128, 0x1A8, 0x228, 0x2A8, 0x328, 0x3A8,
0x050, 0x0D0, 0x150, 0x1D0, 0x250, 0x2D0, 0x350, 0x3D0 };
@ -152,7 +152,8 @@ static void c_initialize_dhires_values(void) {
/* dhires_colors[v++] = hicolor; */
/* } */
for (i = 0; i < 0x80; i++) {
for (i = 0; i < 0x80; i++)
{
video__dhires1[i+0x80] = video__dhires1[i];
video__dhires2[i+0x80] = video__dhires2[i];
}
@ -168,7 +169,8 @@ static void c_initialize_hires_values(void)
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 (value = 0x00; value <= 0xFF; value++)
{
for (e = value * 8, last_not_black = 0, v = value, b = 0;
b < 7; b++, v >>= 1, e++)
{
@ -195,28 +197,42 @@ static void c_initialize_hires_values(void)
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;
}
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 (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,190 +241,262 @@ 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 ];
}
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 ];
}
}
for (b = 0, e = value * 8; b <= 6; b += 2, e += 2) {
if (video__hires_odd[ e ] == COLOR_BLACK) {
if (b > 0 && b < 6) {
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) {
}
}
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 {
}
}
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 ] == 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) {
}
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
}
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) {
}
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 (
}
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 (
}
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 (
}
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;
}
}
if (video__hires_odd[e] == COLOR_BLACK) {
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 (
}
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 (
}
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 (
}
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) {
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 (
}
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 (
}
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 (
}
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] == 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 (
}
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 (
}
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 (
}
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;
}
@ -416,15 +504,19 @@ static void c_initialize_hires_values(void)
}
}
}
}
#ifdef _640x400
/* *2 for 640x400 */
for (b=0, e=0; b<4096; b++, 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];
}
#endif
}
@ -437,16 +529,20 @@ 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++) {
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;
(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;
@ -463,11 +559,13 @@ static void c_initialize_tables_video(void) {
int x, y, i;
/* initialize text/lores & hires graphics */
for (y = 0; y < 24; y++) { /* 24 rows */
for (y = 0; y < 24; y++) /* 24 rows */
{
for (x = 0; x < 40; x++) /* 40 cols */
{
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
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 :
@ -483,7 +581,8 @@ static void c_initialize_tables_video(void) {
}
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
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;
@ -501,7 +600,8 @@ static void c_initialize_tables_video(void) {
{
/* //e mode: hires/double hires page 0 */
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[ 0x2000 + video__line_offset[ y ]
+ 0x400 * i + x ].w =
(y < 20) ? ((x & 1) ? video__write_2e_odd0 :
@ -509,7 +609,6 @@ static void c_initialize_tables_video(void) {
: ((x & 1) ? video__write_2e_odd0_mixed :
video__write_2e_even0_mixed);
}
/* ][+ modes: hires page 0 */
else
#endif
@ -523,7 +622,8 @@ static void c_initialize_tables_video(void) {
}
#ifdef APPLE_IIE
if (apple_mode == IIE_MODE) {
if (apple_mode == IIE_MODE)
{
cpu65_vmem[ 0x4000 + video__line_offset[ y ]
+ 0x400 * i + x ].w =
(y < 20) ? ((x & 1) ? video__write_2e_odd1 :
@ -531,7 +631,6 @@ static void c_initialize_tables_video(void) {
: ((x & 1) ? video__write_2e_odd1_mixed :
video__write_2e_even1_mixed);
}
/* ][+ modes: hires page 1 */
else
#endif
@ -551,12 +650,20 @@ static void c_initialize_tables_video(void) {
void video_set(int flags)
{
if (color_mode == COLOR)
{
video__strictcolors = 1; /* strict colors */
else if (color_mode == INTERP)
video__strictcolors = 2; /* strict interpolation */
}
else
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 */
@ -601,6 +708,7 @@ void video_loadfont_int(int first, int quantity, const unsigned char *data)
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)
@ -615,6 +723,7 @@ void video_loadfont_int(int first, int quantity, const unsigned char *data)
video__int_font[2][y] = COLOR_BLACK;
video__int_font[1][y] = COLOR_MEDIUM_BLUE;
}
#endif /* _640x400 */
x <<= 1;
}
@ -627,28 +736,28 @@ static void c_interface_print_char40_line(
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
}

View File

@ -28,7 +28,7 @@
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XShm.h>/* MITSHM! */
#include <X11/extensions/XShm.h> /* MITSHM! */
#include "video.h"
@ -55,7 +55,7 @@ static uint32_t green_shift;
static uint32_t blue_shift;
static uint32_t alpha_shift;
int doShm = 1;/* assume true */
int doShm = 1; /* assume true */
XShmSegmentInfo xshminfo;
int xshmeventtype;
@ -86,61 +86,79 @@ static void getshm(int size) {
do
{
id = shmget((key_t) key, 0, 0777);
if (id == -1) {
if (id == -1)
{
/* no stale ID's */
id = shmget((key_t)key, size, IPC_CREAT|0777);
if (id == -1) {
if (id == -1)
{
perror("shmget");
printf("Could not get shared memory\n");
++key;
}
break;
} else {
}
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) {
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) {
}
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) {
}
else
{
if (getuid() == shminfo.shm_perm.cuid)
{
/* it's my stale ID */
rc = shmctl(id, IPC_RMID, 0);
if (!rc) {
if (!rc)
{
printf("Was able to kill my old shared memory\n");
} else {
}
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) {
if (id == -1)
{
perror("shmget");
printf("Could not get shared memory\n");
}
rc=shmctl(id, IPC_STAT, &shminfo);
if (rc) {
if (rc)
{
perror("shmctl");
}
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 {
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;
}
@ -149,7 +167,8 @@ static void getshm(int size) {
}
} while (--counter);
if (!counter) {
if (!counter)
{
printf( "System has too many stale/used shared memory segments!\n");
}
@ -158,7 +177,8 @@ static void getshm(int size) {
/* attach to the shared memory segment */
image->data = xshminfo.shmaddr = shmat(id, 0, 0);
if ((int)(image->data) == -1) {
if ((int)(image->data) == -1)
{
perror("shmat");
printf("Could not attach to shared memory\n");
exit(1);
@ -169,22 +189,26 @@ static void getshm(int size) {
static void c_initialize_colors() {
static unsigned char col2[ 3 ] = {255,255,255};
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,7 +320,7 @@ 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;
@ -391,11 +417,14 @@ static int keysym_to_scancode(void) {
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,7 +433,8 @@ static void post_image() {
uint8_t index;
unsigned int count = SCANWIDTH * SCANHEIGHT;
for (unsigned int i=0, j=0; i<count; i++, j+=4) {
for (unsigned int i=0, j=0; i<count; i++, j+=4)
{
index = *(fb + i);
*( (uint32_t*)(image->data + j) ) = (uint32_t)(
((uint32_t)(colors[index].red) << red_shift) |
@ -415,7 +445,8 @@ static void post_image() {
}
// post image...
if (doShm) {
if (doShm)
{
if (!XShmPutImage(
display,
win,
@ -425,8 +456,12 @@ static void post_image() {
0, 0,
SCANWIDTH, SCANHEIGHT,
True))
{
fprintf(stderr, "XShmPutImage() failed\n");
} else {
}
}
else
{
if (XPutImage(
display,
win,
@ -436,14 +471,18 @@ static void post_image() {
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) {
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;
@ -451,7 +490,9 @@ static void c_flash_cursor(int on) {
colors[ COLOR_FLASHING_WHITE].red = 0xffff;
colors[ COLOR_FLASHING_WHITE].green = 0xffff;
colors[ COLOR_FLASHING_WHITE].blue = 0xffff;
} else {
}
else
{
colors[ COLOR_FLASHING_WHITE].red = 0;
colors[ COLOR_FLASHING_WHITE].green = 0;
colors[ COLOR_FLASHING_WHITE].blue = 0;
@ -474,15 +515,22 @@ void video_sync(int block) {
post_image();
LOOP:
if (doShm)
{
XNextEvent(
display,
&xevent);
else if (!XCheckMaskEvent(
}
else
if (!XCheckMaskEvent(
display,
KeyPressMask|KeyReleaseMask,
&xevent))
{
goto POLL_FINISHED;
switch (xevent.type) {
}
switch (xevent.type)
{
case KeyPress:
c_read_raw_key(keysym_to_scancode(), 1);
break;
@ -491,9 +539,13 @@ LOOP:
break;
default:
if (xevent.type == xshmeventtype)
{
goto POLL_FINISHED;
}
break;
}
goto LOOP;
POLL_FINISHED:
@ -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,10 +588,13 @@ static Cursor hidecursor() {
static void parseArgs() {
int i;
for (i=0; i<argc; i++) {
for (i=0; i<argc; i++)
{
if (strstr(argv[i], "-noshm"))
{
doShm=0;
}
}
}
void video_init() {
@ -557,7 +612,7 @@ void video_init() {
XClassHint *class_hints;
XTextProperty windowName, iconName;
//GC gc;
char *progname;/* name this program was invoked by */
char *progname; /* name this program was invoked by */
char *displayname = NULL;
progname = argv[0];
@ -568,15 +623,20 @@ void video_init() {
parseArgs();
if (!(size_hints = XAllocSizeHints())) {
if (!(size_hints = XAllocSizeHints()))
{
fprintf(stderr, "cannot allocate memory for SizeHints\n");
exit(1);
}
if (!(wm_hints = XAllocWMHints())) {
if (!(wm_hints = XAllocWMHints()))
{
fprintf(stderr, "cannot allocate memory for WMHints\n");
exit(1);
}
if (!(class_hints = XAllocClassHint())) {
if (!(class_hints = XAllocClassHint()))
{
fprintf(stderr, "cannot allocate memory for ClassHints\n");
exit(1);
}
@ -606,7 +666,7 @@ void video_init() {
exit(1);
}
XFree(visuals_list);
*/
*/
if (!XMatchVisualInfo(display, XDefaultScreen(display), 32, TrueColor, &visualinfo))
{
fprintf(stderr, "no such visual\n");
@ -619,22 +679,36 @@ void video_init() {
// 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) {
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) {
}
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) {
}
else
if ((((uint32_t)visualinfo.blue_mask >>shift) & 0xff) == (uint32_t)0xff)
{
blue_shift = shift;
} else {
}
else
{
alpha_shift = shift;
}
shift += 8;
}
if ((!red_shift) && (!green_shift) && (!blue_shift)) {
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);
@ -645,20 +719,25 @@ void video_init() {
width = SCANWIDTH, height = SCANHEIGHT;
/* init MITSHM if we're doing it */
if (doShm) {
if (doShm)
{
/* make sure we have it */
doShm = XShmQueryExtension(display);
}
displayname = getenv("DISPLAY");
if (displayname) {
if (*displayname != ':') {
if (displayname)
{
if (*displayname != ':')
{
printf("NOTE: Sound not allowed for remote display \"%s\".\n", displayname);
if (doShm) {
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;
}
@ -673,14 +752,14 @@ void video_init() {
attribs.border_pixel = 0;
/* select event types wanted */
attribmask = CWEventMask | CWColormap | CWBorderPixel;/* HACK CWBorderPixel? */
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 */
0, /* border_width */
visualinfo.depth, /* depth */
InputOutput,
visualinfo.visual,
attribmask,
@ -697,12 +776,14 @@ void video_init() {
size_hints->max_height = height;
/* store window_name and icon_name for niceity. */
if (XStringListToTextProperty(&window_name, 1, &windowName) == 0) {
if (XStringListToTextProperty(&window_name, 1, &windowName) == 0)
{
fprintf(stderr, "structure allocation for windowName failed.\n");
exit(1);
}
if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0) {
if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0)
{
fprintf(stderr, "structure allocation for iconName failed.\n");
exit(1);
}
@ -710,7 +791,7 @@ void video_init() {
// set up window manager hints...
wm_hints->initial_state = NormalState;
wm_hints->input = True;
wm_hints->flags = StateHint | IconPixmapHint/* | InputHint*/;
wm_hints->flags = StateHint | IconPixmapHint /* | InputHint*/;
class_hints->res_name = progname;
class_hints->res_class = "Apple2";
@ -748,10 +829,12 @@ void video_init() {
xshmeventtype = XShmGetEventBase(display) + ShmCompletion;
/* create the image */
if (doShm) {
if (doShm)
{
image = XShmCreateImage(display, visualinfo.visual, visualinfo.depth, ZPixmap, NULL, &xshminfo, SCANWIDTH, SCANHEIGHT);
if (!image) {
if (!image)
{
fprintf(stderr, "XShmCreateImage failed\n");
exit(1);
}
@ -762,20 +845,26 @@ void video_init() {
getshm(pixel_buffer_size);
/* get the X server to attach to it */
if (!XShmAttach(display, &xshminfo)) {
if (!XShmAttach(display, &xshminfo))
{
fprintf(stderr, "XShmAttach() failed in InitGraphics()\n");
exit(1);
}
} else {
}
else
{
void *data = malloc(pixel_buffer_size); // pad to uint32_t
if (!data) {
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) {
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);
}
@ -791,10 +880,13 @@ void video_init() {
void video_shutdown(void)
{
if (doShm) {
if (doShm)
{
// Detach from X server
if (!XShmDetach(display, &xshminfo))
{
fprintf(stderr,"XShmDetach() failed in video_shutdown()\n");
}
// Release shared memory.
shmdt(xshminfo.shmaddr);
@ -802,7 +894,9 @@ void video_shutdown(void)
// Paranoia.
image->data = NULL;
} else {
}
else
{
free(image->data);
}