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

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

@ -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,15 +406,19 @@ 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);
}
}
/* -------------------------------------------------------------------------
c_write_normal_6() disk6.disk_byte contains the value
@ -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,41 +552,60 @@ 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)
{
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();
@ -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,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;
}
}

View File

@ -52,10 +52,15 @@ static int altdrive;
static void pad_string(char *s, char c, int len) {
char *p;
for (p = s; ((*p != '\0') && (p-s < len-1)); p++);
while (p-s < len-1) {
for (p = s; ((*p != '\0') && (p-s < len-1)); p++)
{
}
while (p-s < len-1)
{
*p++ = c;
}
*p = '\0';
}
@ -100,7 +105,9 @@ void c_interface_print( int x, int y, int cs, char *s )
int i;
for (i = x; *s; i++, s++)
{
video_plotchar( i, y, cs, *s );
}
}
@ -187,6 +194,7 @@ void c_interface_translate_screen( char screen[24][41] )
int x, y, i, j, k;
for (y = 0; y < 24; y++)
{
for (x = 0; x < 40; x++)
{
if (screen[ y ][ x ] == '|')
@ -198,22 +206,37 @@ void c_interface_translate_screen( char screen[24][41] )
flag = 1;
for (i = y - 1; flag && i <= y + 1; i++)
{
for (j = x - 1; flag && j <= x + 1; j++)
{
if (IsInside(j, i))
{
if (!(IsGraphic( screen[ i ][ j ])) &&
(map[k][ i - y + 1 ][ j - x + 1 ] == '|'))
{
flag = 0;
else;
}
else
{
}
}
else
if (map[k][ i - y + 1 ][ j - x + 1 ] == '|')
{
flag = 0;
}
}
}
}
if (flag)
{
screen[ y ][ x ] = 0x80 + k;
}
}
}
}
}
int c_interface_cut_name(char *name)
{
@ -226,7 +249,8 @@ int c_interface_cut_name(char *name)
if (p >= name && *p == 'g')
{
p--;
if (p >= name && *p == '.') {
if (p >= name && *p == '.')
{
*p-- = '\0';
is_gz = 1;
}
@ -256,8 +280,8 @@ int c_interface_is_gz(const char *name)
{
size_t len = strlen( name );
if (len > GZ_EXT_LEN) { /* shouldn't have a file called ".gz"... */
/*name += len - GZ_EXT_LEN;*/
if (len > GZ_EXT_LEN) /* shouldn't have a file called ".gz"... */
{ /*name += len - GZ_EXT_LEN;*/
return ((strcmp(name+len-GZ_EXT_LEN, GZ_EXT) == 0) ? 1 : 0);
}
@ -271,10 +295,14 @@ int c_interface_is_nibblized(const char *name)
size_t len = strlen( name );
if (c_interface_is_gz(name))
{
len -= GZ_EXT_LEN;
}
if (!strncmp(name + len - DISK_EXT_LEN, DISK_EXT2, DISK_EXT_LEN))
{
return 1;
}
return 0;
}
@ -292,26 +320,36 @@ int c_interface_disk_select(const struct dirent *e)
/* don't show disk in alternate drive */
if (!strcmp(cmp, disk6.disk[altdrive].file_name))
{
return 0;
}
/* show directories except '.' and '..' at toplevel. */
stat(cmp, &statbuf);
if (S_ISDIR(statbuf.st_mode) && strcmp(".", e->d_name) &&
!(!strcmp("..", e->d_name) && !strcmp(disk_path, "/")))
{
return 1;
}
p = e->d_name;
len = strlen(p);
if (len > GZ_EXT_LEN && (!strcmp(p + len - GZ_EXT_LEN, GZ_EXT))) {
if (len > GZ_EXT_LEN && (!strcmp(p + len - GZ_EXT_LEN, GZ_EXT)))
{
len -= GZ_EXT_LEN;
}
/* true if .dsk or .nib extension */
if (!strncmp(p + len - DISK_EXT_LEN, DISK_EXT, DISK_EXT_LEN))
{
return 1;
}
if (!strncmp(p + len - DISK_EXT_LEN, DISK_EXT2, DISK_EXT_LEN))
{
return 1;
}
return 0;
}
@ -381,17 +419,22 @@ void c_interface_select_diskette( int drive )
NEXTDIR:
for (i = 0; i < 24; i++)
{
c_interface_print( 0, i, 2, screen[ i ] );
}
altdrive = (drive == 0) ? 1 : 0;
if (!strcmp("", disk_path))
{
sprintf(disk_path, "/");
}
/* set to users privilege level for directory access */
entries = scandir(disk_path, &namelist,
c_interface_disk_select, alphasort);
if (entries <= 0) {
if (entries <= 0)
{
/* 1/17/97 NOTE: scandir (libc5.3.12) seems to freak on broken
symlinks. so you won't be able to read from some
legitimate directories... */
@ -403,40 +446,62 @@ void c_interface_select_diskette( int drive )
}
if (curpos >= entries)
{
curpos = entries - 1;
}
for (;;) {
for (i = 0; i < 17; i++) {
for (;; )
{
for (i = 0; i < 17; i++)
{
int ent_no = curpos - 8 + i, slen;
int in_drive = 0;
strcpy( temp, " " );
if (ent_no >= 0 && ent_no < entries) {
if (ent_no >= 0 && ent_no < entries)
{
snprintf(temp, TEMPSIZE, "%s/%s",
disk_path, namelist[ent_no]->d_name);
if (!strcmp(temp, disk6.disk[drive].file_name))
{
in_drive = 1;
}
stat(temp, &statbuf);
if (S_ISDIR(statbuf.st_mode))
{
snprintf(temp, TEMPSIZE, " %s/",
namelist[ ent_no ]->d_name );
}
else
{
snprintf(temp, TEMPSIZE, " %s",
namelist[ ent_no ]->d_name );
if (c_interface_cut_name(temp)) {
}
if (c_interface_cut_name(temp))
{
strncat(temp, " <gz>", TEMPSIZE-1);
}
/* write protected disk in drive? */
else if ((in_drive) && (disk6.disk[drive].protected))
else
if ((in_drive) && (disk6.disk[drive].protected))
{
strncat(temp, (drive == 0) ? " <r1>" : " <r2>", TEMPSIZE-1);
else if (in_drive)
}
else
if (in_drive)
{
strncat(temp, (drive == 0) ? " <rw1>" : " <rw2>", TEMPSIZE-1);
}
}
slen = strlen( temp );
while (slen < 38)
{
temp[ slen++ ] = ' ';
}
temp[ 38 ] = '\0';
c_interface_print(1, i + 3, ent_no == curpos, temp);
@ -449,38 +514,68 @@ void c_interface_select_diskette( int drive )
while (ch == -1);
if (ch == kUP) /* Arrow up */
{
if (curpos > 0)
{
curpos--;
else;
else if (ch == kDOWN) /* Arrow down */
}
else
{
}
}
else
if (ch == kDOWN) /* Arrow down */
{
if (curpos < entries - 1)
{
curpos++;
else;
else if (ch == kPGDN) /* Page down */
}
else
{
}
}
else
if (ch == kPGDN) /* Page down */
{
curpos += 16;
if (curpos > entries - 1)
{
curpos = entries - 1;
}
else if (ch == kPGUP) /* Page up */
}
else
if (ch == kPGUP) /* Page up */
{
curpos -= 16;
if (curpos < 0)
{
curpos = 0;
}
else if (ch == kHOME) /* Home */
}
else
if (ch == kHOME) /* Home */
{
curpos = 0;
else if (ch == kEND) /* End */
}
else
if (ch == kEND) /* End */
{
curpos = entries - 1;
else if (ch == kESC) /* ESC */
}
else
if (ch == kESC) /* ESC */
{
for (i = 0; i < entries; i++)
{
free(namelist[ i ]);
}
free(namelist);
c_interface_exit();
return;
}
else if ((ch == 13) || (toupper(ch) == 'W')) /* Return */
else
if ((ch == 13) || (toupper(ch) == 'W')) /* Return */
{
int len, cmpr = 0;
@ -489,9 +584,11 @@ void c_interface_select_diskette( int drive )
len = strlen(disk_path);
/* handle disk currently in the drive */
if (!strcmp(temp, disk6.disk[drive].file_name)) {
if (!strcmp(temp, disk6.disk[drive].file_name))
{
/* reopen disk, forcing write enabled */
if (toupper(ch) == 'W') {
if (toupper(ch) == 'W')
{
if (c_new_diskette_6(
drive,
temp,
@ -509,7 +606,10 @@ void c_interface_select_diskette( int drive )
}
for (i = 0; i < entries; i++)
{
free(namelist[ i ]); /* clean up */
}
free(namelist);
c_interface_exit(); /* resume emulation */
return;
@ -518,27 +618,48 @@ void c_interface_select_diskette( int drive )
/* eject the disk and start over */
c_eject_6(drive);
for (i = 0; i < entries; i++)
{
free(namelist[ i ]); /* clean up */
}
free(namelist);
goto NEXTDIR; /* I'm lazy */
}
/* read another directory */
stat(temp, &statbuf);
if (S_ISDIR(statbuf.st_mode)) {
if (toupper(ch) == 'W') continue;/* can't protect this */
if (S_ISDIR(statbuf.st_mode))
{
if (toupper(ch) == 'W')
{
continue; /* can't protect this */
if ((disk_path[len-1]) == '/') disk_path[--len] = '\0';
}
if (!strcmp("..", namelist[curpos]->d_name)) {
if ((disk_path[len-1]) == '/')
{
disk_path[--len] = '\0';
}
if (!strcmp("..", namelist[curpos]->d_name))
{
while (--len && (disk_path[len] != '/'))
{
disk_path[len] = '\0';
}
else if (strcmp(".", namelist[curpos]->d_name))
}
else
if (strcmp(".", namelist[curpos]->d_name))
{
snprintf(disk_path + len, DISKSIZE-len, "/%s",
namelist[curpos]->d_name);
}
for (i = 0; i < entries; i++)
{
free(namelist[ i ]); /* clean up */
}
free(namelist);
goto NEXTDIR; /* I'm lazy */
}
@ -546,12 +667,14 @@ void c_interface_select_diskette( int drive )
/* uncompress the gziped disk */
if (c_interface_is_gz(temp))
{
if ((pid = fork())) { /* parent process */
if ((pid = fork())) /* parent process */
{
c_interface_print( 1, 21, 0,
" Uncompressing... " );
c_interface_print( 1, 22, 0,
" " );
if (waitpid(pid, NULL, 0) == -1) {
if (waitpid(pid, NULL, 0) == -1)
{
c_interface_print( 1, 21, 0,
" Problem gunzip'ing " );
c_interface_print( 1, 22, 0,
@ -561,8 +684,10 @@ void c_interface_select_diskette( int drive )
c_interface_redo_diskette_bottom();
continue;
}
} 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",
"-d", temp, NULL) == -1)
{
@ -574,7 +699,9 @@ void c_interface_select_diskette( int drive )
c_usleep();
exit(-1);
}
} else {
}
else
{
snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]);
c_interface_print( 1, 21, 0,
" Cannot fork! " );
@ -590,16 +717,18 @@ void c_interface_select_diskette( int drive )
}
/* gzip the last disk */
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 */
c_interface_print( 1, 21, 0,
" Compressing old diskette... " );
c_interface_print( 1, 22, 0,
" " );
if (waitpid(pid, NULL, 0) == -1) {
if (waitpid(pid, NULL, 0) == -1)
{
c_interface_print( 1, 21, 0,
" Problem gzip'ing " );
c_interface_print( 1, 22, 0,
@ -609,8 +738,10 @@ void c_interface_select_diskette( int drive )
c_interface_redo_diskette_bottom();
continue;
}
} 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)
{
@ -620,7 +751,9 @@ void c_interface_select_diskette( int drive )
c_usleep();
exit(-1);
}
} else {
}
else
{
snprintf(temp, TEMPSIZE, "%s", sys_errlist[errno]);
c_interface_print( 1, 21, 0,
" Cannot fork! " );
@ -648,7 +781,10 @@ void c_interface_select_diskette( int drive )
}
for (i = 0; i < entries; i++)
{
free(namelist[ i ]); /* clean up */
}
free(namelist);
c_interface_exit(); /* resume emulation */
return;
@ -717,7 +853,9 @@ void c_interface_parameters()
int current_mode = apple_mode;
if (!iie_supported && (current_mode == 2))
{
current_mode = apple_mode = 0;
}
/* reset the x position, so we don't lose our cursor if path changes */
cur_x = 0;
@ -726,12 +864,19 @@ void c_interface_parameters()
c_interface_translate_screen( screen );
for (i = 0; i < 24; i++)
{
c_interface_print( 0, i, 2,screen[ i ] );
}
for (;;) {
for (i = 0; i < 9; i++) {
for (;; )
{
for (i = 0; i < 9; i++)
{
cur_off = option - 8;
if (cur_off < 0) cur_off = 0;
if (cur_off < 0)
{
cur_off = 0;
}
c_interface_print( 1, 5 + i, cur_y == i, options[ i + cur_off ] );
@ -806,11 +951,15 @@ void c_interface_parameters()
pad_string(temp, ' ', 26);
if (i+cur_off != 1)
{
c_interface_print(14, 5 + i, 0, temp);
else {
}
else
{
int j;
for (j = 0; j < 24; j++)
{
if (cur_x != j)
{
if (temp[ j ] == '\0')
@ -820,8 +969,10 @@ void c_interface_parameters()
break;
}
else
{
video_plotchar( 14 + j, 5+i, 0, temp[ j ] );
}
}
else
{
if (temp[ j ] == '\0')
@ -831,14 +982,20 @@ void c_interface_parameters()
break;
}
else
{
video_plotchar( 14 + j, 5+i, option==1,
temp[ j ]);
}
}
}
for (; j < 24; j++)
{
video_plotchar( 14 + j, 5+i, 0, ' ' );
}
}
}
do
{
@ -846,95 +1003,159 @@ void c_interface_parameters()
}
while (ch == -1);
if (ch == kUP) { /* Arrow up */
if (option > 8) {
if (ch == kUP) /* Arrow up */
{
if (option > 8)
{
option--; /* only dec option */
} else if (option > 0) {
}
else
if (option > 0)
{
option--; /* dec option */
cur_y--; /* and dec y position */
} else {
}
else
{
option = NUM_OPTIONS-1; /* wrap to last option */
cur_y = 8; /* wrap to last y position */
}
}
else if (ch == kDOWN) { /* Arrow down */
if (cur_y < 8) {
else
if (ch == kDOWN) /* Arrow down */
{
if (cur_y < 8)
{
option++; /* inc option */
cur_y++; /* and inc y position */
} else if (option < NUM_OPTIONS-1) {
}
else
if (option < NUM_OPTIONS-1)
{
option++; /* only inc option */
} else {
}
else
{
cur_y = option = 0; /* wrap both to first */
}
}
else if (ch == kLEFT) { /* Arrow left */
switch (option) {
else
if (ch == kLEFT) /* Arrow left */
{
switch (option)
{
case 0: /* inc speed */
if (cpu65_delay < MAX_APPLE_DELAY)
{
cpu65_delay++;
}
break;
case 1: /* path */
if (cur_x > 0)
{
cur_x--;
}
else
if (cur_pos > 0)
{
cur_pos--;
}
break;
case 2: /* apple mode */
apple_mode--;
if (apple_mode < 0)
{
apple_mode = 2;
}
if ((apple_mode == 2) && !iie_supported)
{
apple_mode = 1;
}
break;
case 3: /* color mode */
if (color_mode == 0)
{
color_mode = 4;
}
else
{
--color_mode;
}
break;
case 4: /* sound mode */
if (sound_mode == 0)
{
sound_mode = 1;
}
else
{
--sound_mode;
}
break;
case 5: /* joystick mode */
#ifdef PC_JOYSTICK
if (joy_mode == 0)
{
joy_mode = 3;
}
#else
if (joy_mode == 0)
{
joy_mode = 2;
}
#endif
else
{
--joy_mode;
}
break;
case 6: /* calibrate */
break;
case 7: /* range */
if (joy_range > 10) {
if (joy_range > 10)
{
--joy_range;
joy_center_x = joy_range/2;
joy_center_y = joy_range/2;
}
break;
case 8: /* origin x */
if (joy_center_x > 0)
{
joy_center_x--;
}
break;
case 9: /* origin y */
if (joy_center_y > 0)
{
joy_center_y--;
}
break;
case 10: /* sensitivity */
if (joy_step > 1)
{
joy_step--;
}
break;
case 11:
#ifdef PC_JOYSTICK
if (js_timelimit > 2) /* joystick sample rate */
{
--js_timelimit;
}
#endif
break;
case SAVE_SETTINGS: /* save settings */
@ -942,70 +1163,112 @@ void c_interface_parameters()
break;
}
}
else if (ch == kRIGHT) { /* Arrow right */
switch (option) {
else
if (ch == kRIGHT) /* Arrow right */
{
switch (option)
{
case 0: /* dec speed */
if (cpu65_delay > 1)
{
cpu65_delay--;
}
break;
case 1: /* path */
if (cur_x < 23)
{
if (disk_path[cur_pos + cur_x] != '\0')
{
cur_x++;
}
}
else
if (disk_path[cur_pos + cur_x] != '\0')
{
cur_pos++;
}
break;
case 2: /* apple mode */
apple_mode++;
if (apple_mode > 2)
{
apple_mode = 0;
}
if ((apple_mode == 2) && !iie_supported)
{
apple_mode = 0;
}
break;
case 3: /* color mode */
color_mode++;
if (color_mode > 4)
{
color_mode = 0;
}
break;
case 4: /* sound mode */
sound_mode++;
if (sound_mode > 1)
{
sound_mode = 0;
}
break;
case 5: /* joystick mode */
#ifdef PC_JOYSTICK
if (joy_mode == 3)
{
joy_mode = 0;
}
#else
if (joy_mode == 2)
{
joy_mode = 0;
}
#endif
else
{
++joy_mode;
}
break;
case 6: /* calibrate */
break;
case 7: /* range */
if (joy_range < 256) {
if (joy_range < 256)
{
++joy_range;
joy_center_x = joy_range/2;
joy_center_y = joy_range/2;
}
break;
case 8: /* origin x */
if (joy_center_x < joy_range-1)
{
joy_center_x++;
}
break;
case 9: /* origin y */
if (joy_center_y < joy_range-1)
{
joy_center_y++;
}
break;
case 10: /* sensitivity */
if (joy_step < 100)
{
joy_step++;
}
break;
case 11: /* joystick sample rate */
#ifdef PC_JOYSTICK
@ -1017,42 +1280,59 @@ void c_interface_parameters()
break;
}
}
else if (ch == kESC) { /* exit menu */
else
if (ch == kESC) /* exit menu */
{
c_initialize_sound();
video_set(0); /* redo colors */
#ifdef PC_JOYSTICK
if (joy_mode == JOY_PCJOY) {
if (joy_mode == JOY_PCJOY)
{
c_close_joystick(); /* close the joystick */
c_open_joystick(); /* reopen the joystick */
half_joy_range = joy_range/2;
c_calculate_joystick_parms();
} else {
}
else
{
c_close_joystick();
}
#endif
/* reboot machine if different */
if (current_mode != apple_mode)
{
cpu65_interrupt(RebootSig);
}
c_interface_exit();
return;
}
else {
else
{
/* got a normal character setting path */
if (ch >= ' ' && ch < 127 && option == PATH_OPTION) {
if (ch >= ' ' && ch < 127 && option == PATH_OPTION)
{
int i;
strncpy(temp, disk_path, TEMPSIZE);
for (i = strlen(temp); i >= cur_pos + cur_x; i--)
{
temp[ i + 1 ] = temp[ i ];
}
temp[ cur_pos + cur_x ] = ch;
strncpy(disk_path, temp, DISKSIZE);
if (cur_x < 23)
{
cur_x++;
}
else
if (disk_path[cur_pos + cur_x] != '\0')
{
cur_pos++;
}
}
/* Backspace or delete setting path */
if ((ch == 127 || ch == 8) && (cur_pos + cur_x - 1 >= 0) &&
@ -1061,32 +1341,46 @@ void c_interface_parameters()
int i;
for (i = cur_pos + cur_x - 1; disk_path[ i ] != '\0'; i++)
{
disk_path[ i ] = disk_path[ i + 1 ];
}
if (cur_x > 0)
{
cur_x--;
}
else
if (cur_pos > 0)
{
cur_pos--;
}
}
#ifdef PC_JOYSTICK
/* calibrate joystick */
if ((ch == 13) && (option == CALIBRATE_OPTION)) {
if ((ch == 13) && (option == CALIBRATE_OPTION))
{
c_calibrate_joystick();
}
#endif
/* save settings */
if ((ch == 13) && (option == SAVE_SETTINGS)) {
if ((ch == 13) && (option == SAVE_SETTINGS))
{
save_settings();
}
/* quit apple II simulator */
if (ch == 13 && option == QUIT_EMULATOR) {
if (ch == 13 && option == QUIT_EMULATOR)
{
int ch;
c_interface_print(
1, 22, 0, " Are you sure? (Y/N) " );
while ((ch = c_mygetch(1)) == -1) ;
while ((ch = c_mygetch(1)) == -1)
{
}
ch = toupper(ch);
if (ch == 'Y')
{
@ -1149,9 +1443,14 @@ void c_interface_words()
c_interface_translate_screen( screen );
for (i = 0; i < 24; i++)
{
c_interface_print( 0, i, 2, screen[ i ] );
}
while (c_mygetch(1) == -1)
{
}
while (c_mygetch(1) == -1) { }
c_interface_exit();
}
#endif /* if 0 */
@ -1221,18 +1520,27 @@ void c_interface_keyboard_layout()
video_setpage( 0 );
#ifdef APPLE_IIE
if (apple_mode == 2) {
if (apple_mode == 2)
{
c_interface_translate_screen(screen2);
for (i = 0; i < 24; i++)
{
c_interface_print( 0, i, 2, screen2[ i ] );
} else
}
}
else
#endif
{
c_interface_translate_screen(screen1);
for (i = 0; i < 24; i++)
{
c_interface_print( 0, i, 2, screen1[ i ] );
}
}
while (c_mygetch(1) == -1)
{
}
while (c_mygetch(1) == -1) { }
c_interface_exit();
}

View File

@ -49,17 +49,25 @@ float
c_open_joystick() - opens joystick device and sets timelimit value
------------------------------------------------------------------------- */
int c_open_joystick() {
if (js_fd < 0) {
if ((js_fd = open("/dev/js0", O_RDONLY)) < 0) {
if (js_fd < 0)
{
if ((js_fd = open("/dev/js0", O_RDONLY)) < 0)
{
/* try again with another name */
if ((js_fd = open("/dev/joystick", O_RDONLY)) < 0)
{
return 1; /* problem */
}
}
/* set timelimit value */
if (ioctl(js_fd, JS_SET_TIMELIMIT, &js_timelimit) == -1)
{
return 1; /* problem */
}
}
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;
}
@ -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(
@ -141,20 +154,35 @@ void c_calibrate_joystick () {
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,7 +216,8 @@ 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 +
@ -202,6 +231,7 @@ void c_calibrate_joystick () {
c_interface_print(1, 22, 0, temp);
video_sync(0);
}
c_interface_redo_bottom();
video_sync(0);
}

View File

@ -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,16 +374,27 @@ 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
* abstracted from function above...
@ -363,45 +412,71 @@ 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 */
break;
@ -416,11 +491,12 @@ void c_read_raw_key(int scancode, int pressed) {
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

@ -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,9 +685,11 @@ 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();
@ -716,14 +811,16 @@ void c_read_random() {
static void cpu_thread(void *dummyptr) {
do {
do
{
cpu65_run();
reinitialize();
} while (1);
}
static void main_thread(void *dummyptr) {
do {
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

@ -151,7 +151,10 @@ static int
match(const struct match_table *paradigm, const char *keyword)
{
while (paradigm->tag && strcasecmp(paradigm->tag, keyword))
{
paradigm++;
}
return paradigm->value;
}
@ -164,7 +167,10 @@ match (const struct match_table *paradigm, const char *keyword)
static const char *reverse_match(const struct match_table *paradigm, int key)
{
while (paradigm->tag && key != paradigm->value)
{
paradigm++;
}
return paradigm->tag;
}
@ -177,11 +183,17 @@ 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--] == ' ');
while (y && x[y--] == ' ')
{
}
x[y] = 0;
return x;
@ -251,12 +263,16 @@ load_settings (void)
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:
@ -282,37 +298,65 @@ load_settings (void)
case PRM_JOY_RANGE:
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);
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);
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:
@ -324,21 +368,33 @@ load_settings (void)
js_center_y = strtol(argument, &argument, 10);
js_max_x = strtol(argument, &argument, 10);
if (js_max_x < 0)
{
js_max_x = 0;
}
js_min_x = strtol(argument, &argument, 10);
if (js_min_x < 0)
{
js_min_x = 0;
}
js_max_y = strtol(argument, &argument, 10);
if (js_max_y < 0)
{
js_max_y = 0;
}
js_min_y = strtol(argument, &argument, 10);
if (js_min_y < 0)
{
js_min_y = 0;
}
js_timelimit = strtol(argument, &argument, 10);
if (js_timelimit < 2)
{
js_timelimit = 2;
}
c_open_joystick();
c_calculate_joystick_parms(); /* calculate the associated parms */
@ -347,9 +403,15 @@ load_settings (void)
case PRM_JOY_KYBD_SENSITIVITY:
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:
@ -357,6 +419,7 @@ load_settings (void)
break;
}
}
fclose(config_file);
}
}

View File

@ -39,10 +39,13 @@ static inline struct timespec timespec_diff (struct timespec start, struct times
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;
}
@ -78,7 +81,8 @@ void timing_throttle () {
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,19 +92,24 @@ 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);

View File

@ -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,13 +529,17 @@ 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;
@ -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;
}

View File

@ -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);
@ -174,17 +194,21 @@ static void c_initialize_colors() {
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;
@ -391,7 +417,10 @@ static int keysym_to_scancode(void) {
default:
if ((rc >= XK_space) && (rc <= XK_asciitilde))
{
rc = xevent.xkey.keycode - 8;
}
break;
}
@ -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:
@ -536,11 +588,14 @@ 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() {
XSetWindowAttributes attribs;
@ -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);
}
@ -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;
}
@ -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);
}
@ -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) {
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);
}