diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..126882a --- /dev/null +++ b/.clang-format @@ -0,0 +1,59 @@ +--- +Language: Cpp +ColumnLimit: 140 +IndentWidth: 4 +PPIndentWidth: 2 +UseTab: Never + +AlignArrayOfStructures: Left + +IndentCaseBlocks: true +IndentCaseLabels: true +IndentGotoLabels: false +IndentPPDirectives: AfterHash +IndentWrappedFunctionNames: true + +InsertBraces: false +InsertNewlineAtEOF: true + +MaxEmptyLinesToKeep: 1 + +PointerAlignment: Left +ReferenceAlignment: Left +QualifierAlignment: Left + +SortIncludes: false + +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesInAngles: true +SpacesInCStyleCastParentheses: true +SpacesInContainerLiterals: true +SpacesInParentheses: true +SpacesInSquareBrackets: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false + +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +... diff --git a/Makefile b/Makefile index da245b3..29f7db2 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ clean-all: mrproper # Formatting pretty-code: - clang-format -i src/*.c src/*.h + clang-format -i src/*.c src/*.h src/libChf/*.c src/libChf/*.h # Dependencies get-roms: diff --git a/src/args.h b/src/args.h index 4eac969..1b351e8 100644 --- a/src/args.h +++ b/src/args.h @@ -45,7 +45,7 @@ This header declares a global data structure containing the emulator invocation arguments; this data structure is initialized before startup, either by means of argc/argv or in other ways. - + .include : config.h .notes : @@ -74,27 +74,25 @@ .- */ /*--------------------------------------------------------------------------- - Data type definitions - require config.h + Data type definitions - require config.h ---------------------------------------------------------------------------*/ -struct Args -{ - int reset; /* 2.1: Force emulator reset */ - int monitor; /* 2.1: Call monitor() on startup */ - int batchXfer; /* 3.15: Non-interactive file transfers */ - char *mod_file_name; - char *cpu_file_name; - char *hdw_file_name; - char *rom_file_name; - char *ram_file_name; - char *port_1_file_name; - char *port_2_file_name; - char *hw; /* 2.1: Hardware configuration (unused) */ +struct Args { + int reset; /* 2.1: Force emulator reset */ + int monitor; /* 2.1: Call monitor() on startup */ + int batchXfer; /* 3.15: Non-interactive file transfers */ + char* mod_file_name; + char* cpu_file_name; + char* hdw_file_name; + char* rom_file_name; + char* ram_file_name; + char* port_1_file_name; + char* port_2_file_name; + char* hw; /* 2.1: Hardware configuration (unused) */ }; - /*--------------------------------------------------------------------------- - Global variables + Global variables ---------------------------------------------------------------------------*/ extern struct Args args; diff --git a/src/config.h b/src/config.h index 58a52f1..84601ce 100644 --- a/src/config.h +++ b/src/config.h @@ -121,27 +121,24 @@ .- */ - /* CHF_EXTENDED_INFO: Define this symbol if extended information is desired during condition handling; this is usually useful only for debugging purposes. */ /* #define CHF_EXTENDED_INFO */ - /* DEBUG: Define this symbol to include the debugging code for all source modules in the executable image. - + At run-time, the debug level can be set using the function SetDebugLevel(); the initial debug level is set to the value of the symbol DEBUG_LEVEL, if it is defined, otherwise it is set to zero. */ /* #define DEBUG */ - /* DEBUG_LEVEL: - When this symbol is defined and the debugging code has been included + When this symbol is defined and the debugging code has been included in the executable image (DEBUG symbol set), the initial debug level is set to its value. @@ -149,8 +146,7 @@ DEBUG_C_<> defined in debug.h; each of them corresponds to a class of debugging conditions that can be individually enabled or disabled. */ -#define DEBUG_LEVEL DEBUG_C_REVISION - +#define DEBUG_LEVEL DEBUG_C_REVISION /* CPU_SPIN_SHUTDN If this symbol is defined, the cpu module implements the SHUTDN @@ -176,7 +172,6 @@ */ /* #define CPU_SPIN_SHUTDN */ - /* 2.1: FORCE_NONMODAL If this symbol is defined, nonmodal navigation is forced in the OSF/Motif GUI, by setting navigationType to XmNONE and traversalOn @@ -184,15 +179,13 @@ */ /* #define FORCE_NONMODAL */ - /* 2.4: N_PORT_2_BANK This symbol is used to dimension the HP48GX Port_2: it denotes the number of 128 Kbyte banks the port must have and must be a power of 2 between 1 and 32, inclusive. When undefined, Port_2 is not emulated at all. The default value is 8, that is, Port_2 is emulated and its size is 1Mbyte. */ -#define N_PORT_2_BANK 8 - +#define N_PORT_2_BANK 8 /* 2.5: SERIAL_FORCE_OPENPTY, SERIAL_FORCE_STREAMSPTY Optionally define exactly one of these symbols to force the use of a @@ -203,7 +196,6 @@ /* #define SERIAL_FORCE_OPENPTY */ /* #define SERIAL_FORCE_STREAMSPTY */ - /* 3.2: HP49_SUPPORT Define this symbol to enable HP49-specific support code in the emulator; it does not harm if this symbol is defined when emulating @@ -211,7 +203,6 @@ */ #define HP49_SUPPORT - /* 3.13: REAL_CPU_SPEED Define this symbol (recommended) to force the emulated CPU to run no faster than a software-controlled limit; by default, the limit @@ -219,7 +210,6 @@ */ #define REAL_CPU_SPEED - /* 3.14: CPU_SLOW_IN Define this symbol (recommended) to slow down the A=IN and C=IN instructions depending on the current emulated CPU speed. @@ -227,8 +217,7 @@ The value of the macro determines the gain of the relation between CPU speed and slow down ratio. */ -#define CPU_SLOW_IN 16 - +#define CPU_SLOW_IN 16 /* 4.1.1.1: LCD_MAG This symbol represents the magnification ratio of the emulated LCD pixels @@ -236,32 +225,29 @@ default. Currently, the value cannot be set at runtime for performance reasons. */ -#define LCD_MAG 2 - +#define LCD_MAG 2 /* 4.1.1.1: When defined, this symbol represents the threshold of the long key pression. When the mouse button is kept pressed on a calculator's key for more than LONG_PRESS_THR milliseconds, the key stays pressed after release. */ -#define LONG_PRESS_THR 1000 - +#define LONG_PRESS_THR 1000 /* Chf Module Identifiers: Each main module of the emulator has its own Chf Module Identifier; the values defined here must match those actually used in the message catalogs. */ -#define MAIN_CHF_MODULE_ID 10 -#define CPU_CHF_MODULE_ID 11 -#define MOD_CHF_MODULE_ID 12 -#define DISK_IO_CHF_MODULE_ID 13 -#define X11_CHF_MODULE_ID 14 -#define SERIAL_CHF_MODULE_ID 15 /* 2.5 */ -#define FLASH_CHF_MODULE_ID 16 /* 3.3 */ -#define UTIL_CHF_MODULE_ID 17 /* 3.6 */ -#define X_FUNC_CHF_MODULE_ID 18 /* 3.13 */ -#define DEBUG_CHF_MODULE_ID 30 - +#define MAIN_CHF_MODULE_ID 10 +#define CPU_CHF_MODULE_ID 11 +#define MOD_CHF_MODULE_ID 12 +#define DISK_IO_CHF_MODULE_ID 13 +#define X11_CHF_MODULE_ID 14 +#define SERIAL_CHF_MODULE_ID 15 /* 2.5 */ +#define FLASH_CHF_MODULE_ID 16 /* 3.3 */ +#define UTIL_CHF_MODULE_ID 17 /* 3.6 */ +#define X_FUNC_CHF_MODULE_ID 18 /* 3.13 */ +#define DEBUG_CHF_MODULE_ID 30 /* 3.16: Include automatic exceptions to user configuration */ #include "config_x.h" diff --git a/src/config_x.h b/src/config_x.h index 335e0cf..e5fdb1d 100644 --- a/src/config_x.h +++ b/src/config_x.h @@ -58,8 +58,7 @@ .- */ - /* REAL_CPU_SPEED is not supported on ultrix, because there is no usleep() */ #ifdef ultrix -#undef REAL_CPU_SPEED +# undef REAL_CPU_SPEED #endif diff --git a/src/cpu.c b/src/cpu.c index 5b6bc85..09e7ff5 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -113,2407 +113,2343 @@ static char rcs_id[] = "$Id: cpu.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "cpu.h" #include "modules.h" #include "keyb.h" -#include "disk_io.h" /* 3.1: ReadStructFromFile/WriteStructToFile */ +#include "disk_io.h" /* 3.1: ReadStructFromFile/WriteStructToFile */ #include "args.h" #include "debug.h" -#define CHF_MODULE_ID CPU_CHF_MODULE_ID +#define CHF_MODULE_ID CPU_CHF_MODULE_ID #include -#define GetNibble FetchNibble - +#define GetNibble FetchNibble /*--------------------------------------------------------------------------- - Global variables + Global variables ---------------------------------------------------------------------------*/ struct CpuStatus cpu_status; - /*--------------------------------------------------------------------------- - Private variables + Private variables ---------------------------------------------------------------------------*/ - /* Field selector indexes, lo/hi nibble. NOTE: The P and WP elements of the array must be dynamically adjusted - since they depend on the current value of the P CPU register + since they depend on the current value of the P CPU register */ -static const int fs_idx_lo[N_FS] = -/* P, WP, XS, X, S, M, B, W - ??, ??, ??, ??, ??, ??, ??, A -*/ -{ 0, 0, 2, 0, 15, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -static const int fs_idx_hi[N_FS] = -/* P, WP, XS, X, S, M, B, W - ??, ??, ??, ??, ??, ??, ??, A -*/ -{ 0, 0, 2, 2, 15, 14, 1, 15, - 0, 0, 0, 0, 0, 0, 0, 4 -}; +static const int fs_idx_lo[ N_FS ] = + /* P, WP, XS, X, S, M, B, W + ??, ??, ??, ??, ??, ??, ??, A + */ + { 0, 0, 2, 0, 15, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static const int fs_idx_hi[ N_FS ] = + /* P, WP, XS, X, S, M, B, W + ??, ??, ??, ??, ??, ??, ??, A + */ + { 0, 0, 2, 2, 15, 14, 1, 15, 0, 0, 0, 0, 0, 0, 0, 4 }; /* Register Pair pointers */ -static Nibble *const reg_pair_0[] = -/* AB, BC, CA, DC */ -{ cpu_status.A, cpu_status.B, cpu_status.C, cpu_status.D }; - -static Nibble *const reg_pair_1[] = -/* AB, BC, CA, DC */ -{ cpu_status.B, cpu_status.C, cpu_status.A, cpu_status.C }; +static Nibble* const reg_pair_0[] = + /* AB, BC, CA, DC */ + { cpu_status.A, cpu_status.B, cpu_status.C, cpu_status.D }; +static Nibble* const reg_pair_1[] = + /* AB, BC, CA, DC */ + { cpu_status.B, cpu_status.C, cpu_status.A, cpu_status.C }; /* Nibble bit masks */ -static const Nibble nibble_bit_mask[] = -{ 0x1, 0x2, 0x4, 0x8 }; - +static const Nibble nibble_bit_mask[] = { 0x1, 0x2, 0x4, 0x8 }; /* ProgramStatusRegister bit masks */ -static const ProgramStatusRegister st_bit_mask[] = -{ 0x0001, 0x0002, 0x0004, 0x0008, - 0x0010, 0x0020, 0x0040, 0x0080, - 0x0100, 0x0200, 0x0400, 0x0800, - 0x1000, 0x2000, 0x4000, 0x8000 -}; +static const ProgramStatusRegister st_bit_mask[] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000 }; /* Decimal sum/carry tables, range 0..31 */ -static const int dec_sum[] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1 -}; - -static const int dec_carry[] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1 -}; +static const int dec_sum[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }; +static const int dec_carry[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; /* Decimal sub/borrow tables, range -10..15 */ -static const int dec_sub_t[] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5 -}; +static const int dec_sub_t[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }; -static const int dec_borrow_t[] = -{ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 -}; - -static const int *const dec_sub = dec_sub_t + 10; -static const int *const dec_borrow = dec_borrow_t + 10; +static const int dec_borrow_t[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static const int* const dec_sub = dec_sub_t + 10; +static const int* const dec_borrow = dec_borrow_t + 10; /* Decimal one's complement table */ -static const int dec_one_c[] = -{ - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, - 0, 0, 0, 0, 0 -}; - +static const int dec_one_c[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0 }; /*--------------------------------------------------------------------------- - Private functions: return stack handling + Private functions: return stack handling ---------------------------------------------------------------------------*/ /* PushRSTK */ -static void PushRSTK(const Address r) +static void PushRSTK( const Address r ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "PushRSTK"); - cpu_status.return_stack[cpu_status.return_sp] = r; - cpu_status.return_sp = (cpu_status.return_sp+1) & RETURN_SP_MASK; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "PushRSTK" ); + cpu_status.return_stack[ cpu_status.return_sp ] = r; + cpu_status.return_sp = ( cpu_status.return_sp + 1 ) & RETURN_SP_MASK; } /* PopRSTK */ -static Address PopRSTK(void) +static Address PopRSTK( void ) { - Address r; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "PopRSTK"); - cpu_status.return_sp = (cpu_status.return_sp-1) & RETURN_SP_MASK; - r = cpu_status.return_stack[cpu_status.return_sp]; - cpu_status.return_stack[cpu_status.return_sp] = (Address)0; - return r; + Address r; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "PopRSTK" ); + cpu_status.return_sp = ( cpu_status.return_sp - 1 ) & RETURN_SP_MASK; + r = cpu_status.return_stack[ cpu_status.return_sp ]; + cpu_status.return_stack[ cpu_status.return_sp ] = ( Address )0; + return r; } - /*--------------------------------------------------------------------------- - Private functions: interrupt handling + Private functions: interrupt handling ---------------------------------------------------------------------------*/ /* RTI */ -static void ExecRTI(void) +static void ExecRTI( void ) { - debug1(DEBUG_C_TRACE|DEBUG_C_INT, CPU_I_CALLED, "ExecRTI"); + debug1( DEBUG_C_TRACE | DEBUG_C_INT, CPU_I_CALLED, "ExecRTI" ); - if(cpu_status.int_pending != INT_REQUEST_NONE) - { - debug1(DEBUG_C_INT, CPU_I_RTI_LOOP, - (cpu_status.int_pending == INT_REQUEST_NMI ? "NMI" : "IRQ")); + if ( cpu_status.int_pending != INT_REQUEST_NONE ) { + debug1( DEBUG_C_INT, CPU_I_RTI_LOOP, ( cpu_status.int_pending == INT_REQUEST_NMI ? "NMI" : "IRQ" ) ); - /* Service immediately any pending interrupt request */ - cpu_status.int_service = 1; - cpu_status.int_pending = INT_REQUEST_NONE; - cpu_status.PC = INT_HANDLER_PC; - } + /* Service immediately any pending interrupt request */ + cpu_status.int_service = 1; + cpu_status.int_pending = INT_REQUEST_NONE; + cpu_status.PC = INT_HANDLER_PC; + } - else - { - /* Reenable interrupts and return */ - debug0(DEBUG_C_INT, CPU_I_RTI_END); + else { + /* Reenable interrupts and return */ + debug0( DEBUG_C_INT, CPU_I_RTI_END ); - cpu_status.int_service = 0; - cpu_status.PC = PopRSTK(); - } + cpu_status.int_service = 0; + cpu_status.PC = PopRSTK(); + } } /* RSI */ -static void ExecRSI(void) +static void ExecRSI( void ) { - debug1(DEBUG_C_TRACE|DEBUG_C_INT, CPU_I_CALLED, "ExecRSI"); + debug1( DEBUG_C_TRACE | DEBUG_C_INT, CPU_I_CALLED, "ExecRSI" ); - /* Discard last nibble of RSI opcode */ - cpu_status.PC++; + /* Discard last nibble of RSI opcode */ + cpu_status.PC++; - KeybRSI(); + KeybRSI(); } /* INTON */ -static void ExecINTON(void) +static void ExecINTON( void ) { - debug1(DEBUG_C_TRACE|DEBUG_C_INT, CPU_I_CALLED, "ExecINTON"); + debug1( DEBUG_C_TRACE | DEBUG_C_INT, CPU_I_CALLED, "ExecINTON" ); - /* Enable maskable interrupts */ - cpu_status.int_enable = 1; + /* Enable maskable interrupts */ + cpu_status.int_enable = 1; } /* INTOFF */ -static void ExecINTOFF(void) +static void ExecINTOFF( void ) { - debug1(DEBUG_C_TRACE|DEBUG_C_INT, CPU_I_CALLED, "ExecINTOFF"); + debug1( DEBUG_C_TRACE | DEBUG_C_INT, CPU_I_CALLED, "ExecINTOFF" ); - cpu_status.int_enable = 0; + cpu_status.int_enable = 0; } - /*--------------------------------------------------------------------------- - Private functions: bus input/output + Private functions: bus input/output ---------------------------------------------------------------------------*/ /* BUSCB */ -static void ExecBUSCB(void) +static void ExecBUSCB( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCB"); - ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCB" ChfEnd; - ChfSignal(); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCB" ); + ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCB" ChfEnd; + ChfSignal(); } /* BUSCC */ -static void ExecBUSCC(void) +static void ExecBUSCC( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCC"); - ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCC" ChfEnd; - ChfSignal(); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCC" ); + ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCC" ChfEnd; + ChfSignal(); } /* BUSCD */ -static void ExecBUSCD(void) +static void ExecBUSCD( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCD"); - ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCD" ChfEnd; - ChfSignal(); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecBUSCD" ); + ChfCondition CPU_F_INTERR, CHF_WARNING, "BUSCD" ChfEnd; + ChfSignal(); } /* SREQ */ -static void ExecSREQ(void) +static void ExecSREQ( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecSREQ"); - ChfCondition CPU_F_INTERR, CHF_WARNING, "SREQ" ChfEnd; - ChfSignal(); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecSREQ" ); + ChfCondition CPU_F_INTERR, CHF_WARNING, "SREQ" ChfEnd; + ChfSignal(); } /* OUTC */ -static void ExecOUTC(void) +static void ExecOUTC( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecOUTC"); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecOUTC" ); - cpu_status.OUT = - ((OutputRegister)cpu_status.C[0]) | - ((OutputRegister)cpu_status.C[1] << 4) | - ((OutputRegister)cpu_status.C[2] << 8); + cpu_status.OUT = ( ( OutputRegister )cpu_status.C[ 0 ] ) | ( ( OutputRegister )cpu_status.C[ 1 ] << 4 ) | + ( ( OutputRegister )cpu_status.C[ 2 ] << 8 ); } /* OUTCS */ -static void ExecOUTCS(void) +static void ExecOUTCS( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecOUTCS"); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecOUTCS" ); - cpu_status.OUT = - ((OutputRegister)cpu_status.C[0]) | (cpu_status.OUT & 0xFF0); + cpu_status.OUT = ( ( OutputRegister )cpu_status.C[ 0 ] ) | ( cpu_status.OUT & 0xFF0 ); } /* IN */ -static void ExecIN(Nibble *r) +static void ExecIN( Nibble* r ) { - /* In */ - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecIN"); + /* In */ + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecIN" ); #ifdef CPU_SLOW_IN - /* We must slow the A=IN and C=IN instruction down a bit, depending - on the emulated CPU speed. This is necessary because the HP firmware - uses an active loop instead of a timer to determine the keyboard - automatic repeat rate. + /* We must slow the A=IN and C=IN instruction down a bit, depending + on the emulated CPU speed. This is necessary because the HP firmware + uses an active loop instead of a timer to determine the keyboard + automatic repeat rate. - Since implementing a precise, tiny (~ 1 microsecond), passive delay - in unix is almost impossible, we chose to execute the same - instruction (A=IN or C=IN) multiple times by artificially resetting - the PC as appropriate. + Since implementing a precise, tiny (~ 1 microsecond), passive delay + in unix is almost impossible, we chose to execute the same + instruction (A=IN or C=IN) multiple times by artificially resetting + the PC as appropriate. - The number of repetions depends linearly, with gain CPU_SLOW_IN, - from the current value of cpu_status.inner_loop: - cpu_status.inner_loop==INNER_LOOP_MAX corresponds to the nominal - CPU speed of 4MHz and to a repetition rate of 1 (instructions are - executed once as usual). - */ - { - static int count_down = 0; - - /* Decrement counter; set PC back and return immediately if counter - was not zero (counter not expired yet). + The number of repetions depends linearly, with gain CPU_SLOW_IN, + from the current value of cpu_status.inner_loop: + cpu_status.inner_loop==INNER_LOOP_MAX corresponds to the nominal + CPU speed of 4MHz and to a repetition rate of 1 (instructions are + executed once as usual). */ - if(count_down-- != 0) { - cpu_status.PC -= 3; - return; + static int count_down = 0; + + /* Decrement counter; set PC back and return immediately if counter + was not zero (counter not expired yet). + */ + if ( count_down-- != 0 ) { + cpu_status.PC -= 3; + return; + } + + /* Counter expired; reset counter and execute the instruction */ + count_down = ( ( cpu_status.inner_loop + ( INNER_LOOP_MAX / 2 ) ) / INNER_LOOP_MAX ) * CPU_SLOW_IN; } - - /* Counter expired; reset counter and execute the instruction */ - count_down = ((cpu_status.inner_loop + (INNER_LOOP_MAX/2)) - / INNER_LOOP_MAX) * CPU_SLOW_IN; - } #endif - cpu_status.IN = KeybIN(cpu_status.OUT); + cpu_status.IN = KeybIN( cpu_status.OUT ); - r[0] = (Nibble)(cpu_status.IN & NIBBLE_MASK); - r[1] = (Nibble)((cpu_status.IN) >> 4 & NIBBLE_MASK); - r[2] = (Nibble)((cpu_status.IN) >> 8 & NIBBLE_MASK); - r[3] = (Nibble)((cpu_status.IN) >> 12 & NIBBLE_MASK); + r[ 0 ] = ( Nibble )( cpu_status.IN & NIBBLE_MASK ); + r[ 1 ] = ( Nibble )( ( cpu_status.IN ) >> 4 & NIBBLE_MASK ); + r[ 2 ] = ( Nibble )( ( cpu_status.IN ) >> 8 & NIBBLE_MASK ); + r[ 3 ] = ( Nibble )( ( cpu_status.IN ) >> 12 & NIBBLE_MASK ); } - /*--------------------------------------------------------------------------- - Private functions: CPU control + Private functions: CPU control ---------------------------------------------------------------------------*/ -static void ExecSHUTDN(void) +static void ExecSHUTDN( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "SHUTDN"); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "SHUTDN" ); #ifdef CPU_SPIN_SHUTDN - /* If the CPU_SPIN_SHUTDN symbol is defined, the CPU module implements - SHUTDN as a spin loop; the program counter is reset to the starting - nibble of the SHUTDN opcode. - */ - cpu_status.PC -= 3; + /* If the CPU_SPIN_SHUTDN symbol is defined, the CPU module implements + SHUTDN as a spin loop; the program counter is reset to the starting + nibble of the SHUTDN opcode. + */ + cpu_status.PC -= 3; #endif - /* Set shutdown flag */ - cpu_status.shutdn = 1; + /* Set shutdown flag */ + cpu_status.shutdn = 1; #ifndef CPU_SPIN_SHUTDN - /* If the CPU_SPIN_SHUTDN symbol is not defined, the CPU module implements - SHUTDN signalling the condition CPU_I_SHUTDN - */ - ChfCondition CPU_I_SHUTDN, CHF_INFO ChfEnd; - ChfSignal(); + /* If the CPU_SPIN_SHUTDN symbol is not defined, the CPU module implements + SHUTDN signalling the condition CPU_I_SHUTDN + */ + ChfCondition CPU_I_SHUTDN, CHF_INFO ChfEnd; + ChfSignal(); #endif } - /*--------------------------------------------------------------------------- - Private functions: data type conversions + Private functions: data type conversions ---------------------------------------------------------------------------*/ /* Copies the A field of a DataRegister into an Address; this is not a loop to achieve greater execution speed. */ -static Address R2Addr(const Nibble *r) +static Address R2Addr( const Nibble* r ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "R2Addr"); - return( - ((Address)r[0] ) | - ((Address)r[1] << 4) | - ((Address)r[2] << 8) | - ((Address)r[3] << 12) | - ((Address)r[4] << 16) - ); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "R2Addr" ); + return ( ( ( Address )r[ 0 ] ) | ( ( Address )r[ 1 ] << 4 ) | ( ( Address )r[ 2 ] << 8 ) | ( ( Address )r[ 3 ] << 12 ) | + ( ( Address )r[ 4 ] << 16 ) ); } /* Returns the nibs 0-3 of a DataRegister into an Address; this is not a loop to achieve greater execution speed. */ -static Address R2AddrS(const Nibble *r) +static Address R2AddrS( const Nibble* r ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "R2AddrS"); - return( - ((Address)r[0] ) | - ((Address)r[1] << 4) | - ((Address)r[2] << 8) | - ((Address)r[3] << 12) - ); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "R2AddrS" ); + return ( ( ( Address )r[ 0 ] ) | ( ( Address )r[ 1 ] << 4 ) | ( ( Address )r[ 2 ] << 8 ) | ( ( Address )r[ 3 ] << 12 ) ); } /* Copies an Address into the A field of a register; this is not a loop to achieve grater execution speed */ -static void Addr2R(Nibble *d, Address a) +static void Addr2R( Nibble* d, Address a ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "Addr2R"); - d[0] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[1] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[2] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[3] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[4] = (Nibble)(a & NIBBLE_MASK); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "Addr2R" ); + d[ 0 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 1 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 2 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 3 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 4 ] = ( Nibble )( a & NIBBLE_MASK ); } /* Copies an Address into nibs 0-3 of a register; this is not a loop to achieve grater execution speed */ -static void Addr2RS(Nibble *d, Address a) +static void Addr2RS( Nibble* d, Address a ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "Addr2RS"); - d[0] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[1] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[2] = (Nibble)(a & NIBBLE_MASK); a >>= 4; - d[3] = (Nibble)(a & NIBBLE_MASK); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "Addr2RS" ); + d[ 0 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 1 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 2 ] = ( Nibble )( a & NIBBLE_MASK ); + a >>= 4; + d[ 3 ] = ( Nibble )( a & NIBBLE_MASK ); } /* Copy the 12 low-order bits of ST into C */ -static void St2C(void) +static void St2C( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "St2C"); - cpu_status.C[0] = (Nibble)(cpu_status.ST & NIBBLE_MASK); - cpu_status.C[1] = (Nibble)((cpu_status.ST >> 4) & NIBBLE_MASK); - cpu_status.C[2] = (Nibble)((cpu_status.ST >> 8) & NIBBLE_MASK); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "St2C" ); + cpu_status.C[ 0 ] = ( Nibble )( cpu_status.ST & NIBBLE_MASK ); + cpu_status.C[ 1 ] = ( Nibble )( ( cpu_status.ST >> 4 ) & NIBBLE_MASK ); + cpu_status.C[ 2 ] = ( Nibble )( ( cpu_status.ST >> 8 ) & NIBBLE_MASK ); } /* Copy the 12 low-order bits of C into ST */ -static void C2St(void) +static void C2St( void ) { - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "C2St"); - cpu_status.ST = - (ProgramStatusRegister)cpu_status.C[0] | - ((ProgramStatusRegister)cpu_status.C[1] << 4) | - ((ProgramStatusRegister)cpu_status.C[2] << 8) | - (cpu_status.ST & CLRST_MASK); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "C2St" ); + cpu_status.ST = ( ProgramStatusRegister )cpu_status.C[ 0 ] | ( ( ProgramStatusRegister )cpu_status.C[ 1 ] << 4 ) | + ( ( ProgramStatusRegister )cpu_status.C[ 2 ] << 8 ) | ( cpu_status.ST & CLRST_MASK ); } /* Exchange the 12 low-order bits of C with the 12 low-order bits of ST */ -static void CStExch(void) +static void CStExch( void ) { - ProgramStatusRegister tst = cpu_status.ST; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "CStExch"); - cpu_status.ST = - (ProgramStatusRegister)cpu_status.C[0] | - ((ProgramStatusRegister)cpu_status.C[1] << 4) | - ((ProgramStatusRegister)cpu_status.C[2] << 8) | - (cpu_status.ST & CLRST_MASK); + ProgramStatusRegister tst = cpu_status.ST; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "CStExch" ); + cpu_status.ST = ( ProgramStatusRegister )cpu_status.C[ 0 ] | ( ( ProgramStatusRegister )cpu_status.C[ 1 ] << 4 ) | + ( ( ProgramStatusRegister )cpu_status.C[ 2 ] << 8 ) | ( cpu_status.ST & CLRST_MASK ); - cpu_status.C[0] = (Nibble)(tst & NIBBLE_MASK); - cpu_status.C[1] = (Nibble)((tst >> 4) & NIBBLE_MASK); - cpu_status.C[2] = (Nibble)((tst >> 8) & NIBBLE_MASK); + cpu_status.C[ 0 ] = ( Nibble )( tst & NIBBLE_MASK ); + cpu_status.C[ 1 ] = ( Nibble )( ( tst >> 4 ) & NIBBLE_MASK ); + cpu_status.C[ 2 ] = ( Nibble )( ( tst >> 8 ) & NIBBLE_MASK ); } - /*--------------------------------------------------------------------------- - Private functions: data memory read/write + Private functions: data memory read/write ---------------------------------------------------------------------------*/ /* Read a field of a DataRegister from memory */ -void ReadDAT(Nibble *d, Address s, int fs) +void ReadDAT( Nibble* d, Address s, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - for(n=lo; n<=hi; n++) - d[n] = ReadNibble(s++); + for ( n = lo; n <= hi; n++ ) + d[ n ] = ReadNibble( s++ ); } /* Read a field of a DataRegister from memory, with immediate fs */ -void ReadDATImm(Nibble *d, Address s, int imm_fs) +void ReadDATImm( Nibble* d, Address s, int imm_fs ) { - register int n; + register int n; - for(n=0; n<=imm_fs; n++) - d[n] = ReadNibble(s++); + for ( n = 0; n <= imm_fs; n++ ) + d[ n ] = ReadNibble( s++ ); } /* Write a field of a DataRegister into memory */ -void WriteDAT(Address d, const Nibble *r, int fs) +void WriteDAT( Address d, const Nibble* r, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - for(n=lo; n<=hi; n++) - WriteNibble(d++, r[n]); + for ( n = lo; n <= hi; n++ ) + WriteNibble( d++, r[ n ] ); } /* Write a field of a DataRegister into memory, with immediate fs */ -void WriteDATImm(Address d, const Nibble *r, int imm_fs) +void WriteDATImm( Address d, const Nibble* r, int imm_fs ) { - register int n; + register int n; - for(n=0; n<=imm_fs; n++) - WriteNibble(d++, r[n]); + for ( n = 0; n <= imm_fs; n++ ) + WriteNibble( d++, r[ n ] ); } - /*--------------------------------------------------------------------------- - Private functions: instruction fetch/immediate register load + Private functions: instruction fetch/immediate register load ---------------------------------------------------------------------------*/ /* Read two nibbles in two-complement form, starting from pc */ -static Address Get2Nibbles2C(Address pc) +static Address Get2Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ); - return (v & 0x80) ? v - 0x100 : v; + return ( v & 0x80 ) ? v - 0x100 : v; } /* Read three nibbles in two-complement form, starting from pc */ -static Address Get3Nibbles2C(Address pc) +static Address Get3Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ); - return (v & 0x800) ? v - 0x1000 : v; + return ( v & 0x800 ) ? v - 0x1000 : v; } /* Read four nibbles in two-complement form, starting from pc */ -static Address Get4Nibbles2C(Address pc) +static Address Get4Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) | + ( ( Address )GetNibble( pc + 3 ) << 12 ); - return (v & 0x8000) ? v - 0x10000 : v; + return ( v & 0x8000 ) ? v - 0x10000 : v; } /* Read four nibbles in absolute form, starting from pc */ -static Address Get5NibblesAbs(Address pc) +static Address Get5NibblesAbs( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12) | - ((Address)GetNibble(pc+4) << 16); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) | + ( ( Address )GetNibble( pc + 3 ) << 12 ) | ( ( Address )GetNibble( pc + 4 ) << 16 ); - return v; + return v; } /* Fetch the lower 'n' nibbles of the D register pointed by 'd' from the current instruction body */ -void FetchD(Address *d, register int n) +void FetchD( Address* d, register int n ) { - register Address mask = ADDRESS_MASK; - register Address v = 0x00000; - register int shift = 0; - register int i; + register Address mask = ADDRESS_MASK; + register Address v = 0x00000; + register int shift = 0; + register int i; - for(i=0; i= NIBBLE_PER_REGISTER) p=0; - } + for ( i = 0; i <= n; i++ ) { + r[ p++ ] = GetNibble( cpu_status.PC++ ); + if ( p >= NIBBLE_PER_REGISTER ) + p = 0; + } } - /*--------------------------------------------------------------------------- - Private functions: P register setting + Private functions: P register setting ---------------------------------------------------------------------------*/ -void SetP(Nibble n) +void SetP( Nibble n ) { - cpu_status.P = n; + cpu_status.P = n; - cpu_status.fs_idx_lo[FS_P] = n; - cpu_status.fs_idx_hi[FS_P] = n; - cpu_status.fs_idx_hi[FS_WP] = n; + cpu_status.fs_idx_lo[ FS_P ] = n; + cpu_status.fs_idx_hi[ FS_P ] = n; + cpu_status.fs_idx_hi[ FS_WP ] = n; } - /*--------------------------------------------------------------------------- - Private functions: DataRegister tests + Private functions: DataRegister tests ---------------------------------------------------------------------------*/ /* ?r=s */ -static void TestRREq(int rp, int fs) +static void TestRREq( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register const Nibble *const s = reg_pair_1[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register const Nibble* const s = reg_pair_1[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRREq"); - for(n=lo; n<=hi; n++) - if(r[n] != s[n]) { cpu_status.carry = 0; return; }; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRREq" ); + for ( n = lo; n <= hi; n++ ) + if ( r[ n ] != s[ n ] ) { + cpu_status.carry = 0; + return; + }; - cpu_status.carry = 1; + cpu_status.carry = 1; } /* ?r=0 */ -static void TestRZ(int rp, int fs) +static void TestRZ( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRZ"); - for(n=lo; n<=hi; n++) - if(r[n] != (Nibble)0) { cpu_status.carry = 0; return; }; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRZ" ); + for ( n = lo; n <= hi; n++ ) + if ( r[ n ] != ( Nibble )0 ) { + cpu_status.carry = 0; + return; + }; - cpu_status.carry = 1; + cpu_status.carry = 1; } /* ?r#s */ -static void TestRRNe(int rp, int fs) +static void TestRRNe( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register const Nibble *const s = reg_pair_1[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register const Nibble* const s = reg_pair_1[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRRNe"); - for(n=lo; n<=hi; n++) - if(r[n] != s[n]) { cpu_status.carry = 1; return; }; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRRNe" ); + for ( n = lo; n <= hi; n++ ) + if ( r[ n ] != s[ n ] ) { + cpu_status.carry = 1; + return; + }; - cpu_status.carry = 0; + cpu_status.carry = 0; } /* ?r#0 */ -static void TestRNZ(int rp, int fs) +static void TestRNZ( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRNZ"); - for(n=lo; n<=hi; n++) - if(r[n] != (Nibble)0) { cpu_status.carry = 1; return; }; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRNZ" ); + for ( n = lo; n <= hi; n++ ) + if ( r[ n ] != ( Nibble )0 ) { + cpu_status.carry = 1; + return; + }; - cpu_status.carry = 0; + cpu_status.carry = 0; } /* ?r>s */ -static void TestRRGt(int rp, int fs) +static void TestRRGt( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register const Nibble *const s = reg_pair_1[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register const Nibble* const s = reg_pair_1[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRRGt"); - for(n=hi; n>=lo; n--) - { - if(r[n] > s[n]) { cpu_status.carry = 1; return; }; - if(r[n] < s[n]) { cpu_status.carry = 0; return; }; - } + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRRGt" ); + for ( n = hi; n >= lo; n-- ) { + if ( r[ n ] > s[ n ] ) { + cpu_status.carry = 1; + return; + }; + if ( r[ n ] < s[ n ] ) { + cpu_status.carry = 0; + return; + }; + } - cpu_status.carry = 0; + cpu_status.carry = 0; } /* ?r>=s */ -static void TestRRGe(int rp, int fs) +static void TestRRGe( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register const Nibble *const s = reg_pair_1[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register const Nibble* const s = reg_pair_1[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRRGe"); - for(n=hi; n>=lo; n--) - { - if(r[n] > s[n]) { cpu_status.carry = 1; return; }; - if(r[n] < s[n]) { cpu_status.carry = 0; return; }; - } + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRRGe" ); + for ( n = hi; n >= lo; n-- ) { + if ( r[ n ] > s[ n ] ) { + cpu_status.carry = 1; + return; + }; + if ( r[ n ] < s[ n ] ) { + cpu_status.carry = 0; + return; + }; + } - cpu_status.carry = 1; + cpu_status.carry = 1; } /* ?r=lo; n--) - { - if(r[n] < s[n]) { cpu_status.carry = 1; return; }; - if(r[n] > s[n]) { cpu_status.carry = 0; return; }; - } + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRRLt" ); + for ( n = hi; n >= lo; n-- ) { + if ( r[ n ] < s[ n ] ) { + cpu_status.carry = 1; + return; + }; + if ( r[ n ] > s[ n ] ) { + cpu_status.carry = 0; + return; + }; + } - cpu_status.carry = 0; + cpu_status.carry = 0; } /* ?r<=s */ -static void TestRRLe(int rp, int fs) +static void TestRRLe( int rp, int fs ) { - register const Nibble *const r = reg_pair_0[rp]; - register const Nibble *const s = reg_pair_1[rp]; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register const Nibble* const r = reg_pair_0[ rp ]; + register const Nibble* const s = reg_pair_1[ rp ]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "TestRRLe"); - for(n=hi; n>=lo; n--) - { - if(r[n] < s[n]) { cpu_status.carry = 1; return; }; - if(r[n] > s[n]) { cpu_status.carry = 0; return; }; - } + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "TestRRLe" ); + for ( n = hi; n >= lo; n-- ) { + if ( r[ n ] < s[ n ] ) { + cpu_status.carry = 1; + return; + }; + if ( r[ n ] > s[ n ] ) { + cpu_status.carry = 0; + return; + }; + } - cpu_status.carry = 1; + cpu_status.carry = 1; } - /*--------------------------------------------------------------------------- - Private functions: DataRegister operations + Private functions: DataRegister operations ---------------------------------------------------------------------------*/ /* r=r+r */ -static void AddRR(register Nibble *d, - register const Nibble *a, register const Nibble *b, int fs) +static void AddRR( register Nibble* d, register const Nibble* a, register const Nibble* b, int fs ) { - register int carry; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - register int s; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "AddRR"); - carry = 0; + register int carry; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + register int s; - if(cpu_status.hexmode) - { - for(n=lo; n<=hi; n++) - { - s = a[n] + b[n] + carry; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "AddRR" ); + carry = 0; - d[n] = (Nibble)(s & NIBBLE_MASK); - carry = ((s & ~NIBBLE_MASK) != 0); + if ( cpu_status.hexmode ) { + for ( n = lo; n <= hi; n++ ) { + s = a[ n ] + b[ n ] + carry; + + d[ n ] = ( Nibble )( s & NIBBLE_MASK ); + carry = ( ( s & ~NIBBLE_MASK ) != 0 ); + } } - } - else - { - for(n=lo; n<=hi; n++) - { - s = a[n] + b[n] + carry; - d[n] = dec_sum[s]; - carry = dec_carry[s]; + else { + for ( n = lo; n <= hi; n++ ) { + s = a[ n ] + b[ n ] + carry; + d[ n ] = dec_sum[ s ]; + carry = dec_carry[ s ]; + } } - } - cpu_status.carry = carry; + cpu_status.carry = carry; } /* r=r+1 */ -static void IncrR(register Nibble *d, int fs) +static void IncrR( register Nibble* d, int fs ) { - register int carry; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - register int s; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "IncrR"); - carry = 1; + register int carry; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + register int s; - if(cpu_status.hexmode) - { - for(n=lo; n<=hi; n++) - { - s = d[n] + carry; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "IncrR" ); + carry = 1; - d[n] = (Nibble)(s & NIBBLE_MASK); - carry = ((s & ~NIBBLE_MASK) != 0); + if ( cpu_status.hexmode ) { + for ( n = lo; n <= hi; n++ ) { + s = d[ n ] + carry; + + d[ n ] = ( Nibble )( s & NIBBLE_MASK ); + carry = ( ( s & ~NIBBLE_MASK ) != 0 ); + } } - } - else - { - for(n=lo; n<=hi; n++) - { - s = d[n] + carry; - d[n] = dec_sum[s]; - carry = dec_carry[s]; + else { + for ( n = lo; n <= hi; n++ ) { + s = d[ n ] + carry; + d[ n ] = dec_sum[ s ]; + carry = dec_carry[ s ]; + } } - } - cpu_status.carry = carry; + cpu_status.carry = carry; } /* r=r-r */ -static void SubRR(register Nibble *d, - register Nibble *a, register Nibble *b, int fs) +static void SubRR( register Nibble* d, register Nibble* a, register Nibble* b, int fs ) { - register int carry; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - register int s; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "SubRR"); - carry = 0; + register int carry; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + register int s; - if(cpu_status.hexmode) - { - for(n=lo; n<=hi; n++) - { - s = a[n] - b[n] - carry; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "SubRR" ); + carry = 0; - d[n] = (Nibble)(s & NIBBLE_MASK); - carry = ((s & ~NIBBLE_MASK) != 0); + if ( cpu_status.hexmode ) { + for ( n = lo; n <= hi; n++ ) { + s = a[ n ] - b[ n ] - carry; + + d[ n ] = ( Nibble )( s & NIBBLE_MASK ); + carry = ( ( s & ~NIBBLE_MASK ) != 0 ); + } } - } - else - { - for(n=lo; n<=hi; n++) - { - s = a[n] - b[n] - carry; - d[n] = dec_sub[s]; - carry = dec_borrow[s]; + else { + for ( n = lo; n <= hi; n++ ) { + s = a[ n ] - b[ n ] - carry; + d[ n ] = dec_sub[ s ]; + carry = dec_borrow[ s ]; + } } - } - cpu_status.carry = carry; + cpu_status.carry = carry; } /* r=r-1 */ -static void DecrR(register Nibble *d, int fs) +static void DecrR( register Nibble* d, int fs ) { - register int carry; - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - register int s; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "DecrR"); - carry = 1; + register int carry; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + register int s; - if(cpu_status.hexmode) - { - for(n=lo; n<=hi; n++) - { - s = d[n] - carry; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "DecrR" ); + carry = 1; - d[n] = (Nibble)(s & NIBBLE_MASK); - carry = ((s & ~NIBBLE_MASK) != 0); + if ( cpu_status.hexmode ) { + for ( n = lo; n <= hi; n++ ) { + s = d[ n ] - carry; + + d[ n ] = ( Nibble )( s & NIBBLE_MASK ); + carry = ( ( s & ~NIBBLE_MASK ) != 0 ); + } } - } - else - { - for(n=lo; n<=hi; n++) - { - s = d[n] - carry; - d[n] = dec_sub[s]; - carry = dec_borrow[s]; + else { + for ( n = lo; n <= hi; n++ ) { + s = d[ n ] - carry; + d[ n ] = dec_sub[ s ]; + carry = dec_borrow[ s ]; + } } - } - cpu_status.carry = carry; + cpu_status.carry = carry; } /* r=0 */ -static void ClearR(register Nibble *d, int fs) +static void ClearR( register Nibble* d, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ClearR"); - for(n=lo; n<=hi; n++) - { - d[n] = (Nibble)0; - } + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ClearR" ); + for ( n = lo; n <= hi; n++ ) { + d[ n ] = ( Nibble )0; + } } /* r=r */ -static void CopyRR(register Nibble *d, register Nibble *s, int fs) +static void CopyRR( register Nibble* d, register Nibble* s, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "CopyRR"); - for(n=lo; n<=hi; n++) - { - d[n] = s[n]; - } + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; + + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "CopyRR" ); + for ( n = lo; n <= hi; n++ ) { + d[ n ] = s[ n ]; + } } /* rrEX */ -static void ExchRR(register Nibble *d, register Nibble *s, int fs) +static void ExchRR( register Nibble* d, register Nibble* s, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register Nibble t; - register int n; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExchRR"); - for(n=lo; n<=hi; n++) - { - t = d[n]; d[n] = s[n]; s[n] = t; - } + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register Nibble t; + register int n; + + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExchRR" ); + for ( n = lo; n <= hi; n++ ) { + t = d[ n ]; + d[ n ] = s[ n ]; + s[ n ] = t; + } } /* rSL */ -static void ShiftLeftR(register Nibble *d, int fs) +static void ShiftLeftR( register Nibble* d, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ShiftLeftR"); - for(n=hi; n>lo; n--) - d[n] = d[n-1]; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - d[lo] = (Nibble)0; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ShiftLeftR" ); + for ( n = hi; n > lo; n-- ) + d[ n ] = d[ n - 1 ]; + + d[ lo ] = ( Nibble )0; } /* rSR */ -static void ShiftRightR(register Nibble *d, int fs) +static void ShiftRightR( register Nibble* d, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register int n; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ShiftRightR"); - if(d[lo] != (Nibble)0) cpu_status.HST |= HST_SB_MASK; - - for(n=lo; n>= 1; - d[n] |= ((d[n+1] & nibble_bit_mask[0]) ? nibble_bit_mask[3] : 0); - } + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ShiftRightBitR" ); + if ( ( d[ lo ] & nibble_bit_mask[ 0 ] ) != ( Nibble )0 ) + cpu_status.HST |= HST_SB_MASK; - d[hi] >>= 1; + for ( n = lo; n < hi; n++ ) { + d[ n ] >>= 1; + d[ n ] |= ( ( d[ n + 1 ] & nibble_bit_mask[ 0 ] ) ? nibble_bit_mask[ 3 ] : 0 ); + } + + d[ hi ] >>= 1; } /* rSLC */ -static void ShiftLeftCircR(register Nibble *d, int fs) +static void ShiftLeftCircR( register Nibble* d, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register Nibble s; - register int n; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register Nibble s; + register int n; - - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ShiftLeftCircR"); - s = d[hi]; - for(n=hi; n>lo; n--) - d[n] = d[n-1]; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ShiftLeftCircR" ); + s = d[ hi ]; + for ( n = hi; n > lo; n-- ) + d[ n ] = d[ n - 1 ]; - d[lo] = s; + d[ lo ] = s; } /* rSRC */ -static void ShiftRightCircR(register Nibble *d, int fs) +static void ShiftRightCircR( register Nibble* d, int fs ) { - register int lo = cpu_status.fs_idx_lo[fs]; - register int hi = cpu_status.fs_idx_hi[fs]; - register Nibble s; - register int n; + register int lo = cpu_status.fs_idx_lo[ fs ]; + register int hi = cpu_status.fs_idx_hi[ fs ]; + register Nibble s; + register int n; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ShiftRightCircR"); - if((s=d[lo]) != (Nibble)0) cpu_status.HST |= HST_SB_MASK; - - for(n=lo; n cpu_status.D0 ); + cpu_status.D0 = ta; + break; + + case 9: + /* D0=(2) nn */ + FetchD( &cpu_status.D0, 2 ); + break; + + case 0xA: + /* D0=(4) nn */ + FetchD( &cpu_status.D0, 4 ); + break; + + case 0xB: + /* D0=(5) nn */ + FetchD( &cpu_status.D0, 5 ); + break; + + case 0xC: + /* D1=D1-(n+1) */ + n = GetNibble( cpu_status.PC++ ); + ta = ( cpu_status.D1 - n - 1 ) & ADDRESS_MASK; + cpu_status.carry = ( ta > cpu_status.D1 ); + cpu_status.D1 = ta; + break; + + case 0xD: + /* D1=(2) nn */ + FetchD( &cpu_status.D1, 2 ); + break; + + case 0xE: + /* D1=(4) nn */ + FetchD( &cpu_status.D1, 4 ); + break; + + case 0xF: + /* D1=(5) nn */ + FetchD( &cpu_status.D1, 5 ); + break; default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } - break; - - case 6: - /* D0=D0+n+1 */ - n = GetNibble(cpu_status.PC++); - ta = (cpu_status.D0 + n + 1) & ADDRESS_MASK; - cpu_status.carry = (ta < cpu_status.D0); - cpu_status.D0 = ta; - break; - - case 7: - /* D1=D1+n+1 */ - n = GetNibble(cpu_status.PC++); - ta = (cpu_status.D1 + n + 1) & ADDRESS_MASK; - cpu_status.carry = (ta < cpu_status.D1); - cpu_status.D1 = ta; - break; - - case 8: - /* D0=D0-(n+1) */ - n = GetNibble(cpu_status.PC++); - ta = (cpu_status.D0 - n - 1) & ADDRESS_MASK; - cpu_status.carry = (ta > cpu_status.D0); - cpu_status.D0 = ta; - break; - - case 9: - /* D0=(2) nn */ - FetchD(&cpu_status.D0, 2); - break; - - case 0xA: - /* D0=(4) nn */ - FetchD(&cpu_status.D0, 4); - break; - - case 0xB: - /* D0=(5) nn */ - FetchD(&cpu_status.D0, 5); - break; - - case 0xC: - /* D1=D1-(n+1) */ - n = GetNibble(cpu_status.PC++); - ta = (cpu_status.D1 - n - 1) & ADDRESS_MASK; - cpu_status.carry = (ta > cpu_status.D1); - cpu_status.D1 = ta; - break; - - case 0xD: - /* D1=(2) nn */ - FetchD(&cpu_status.D1, 2); - break; - - case 0xE: - /* D1=(4) nn */ - FetchD(&cpu_status.D1, 4); - break; - - case 0xF: - /* D1=(5) nn */ - FetchD(&cpu_status.D1, 5); - break; - - default: - /* Unknown opcode */ - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } + /* Unknown opcode */ + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; + } } /* Instruction Group_808 */ -static void ExecGroup_808(void) +static void ExecGroup_808( void ) { - Nibble n = GetNibble(cpu_status.PC++); + Nibble n = GetNibble( cpu_status.PC++ ); - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_808"); - switch(n) - { - case 0: /* INTON */ - ExecINTON(); - break; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_808" ); + switch ( n ) { + case 0: /* INTON */ + ExecINTON(); + break; - case 1: /* RSI */ - ExecRSI(); - break; + case 1: /* RSI */ + ExecRSI(); + break; - case 2: /* LA(m) n..n */ - FetchR(cpu_status.A, GetNibble(cpu_status.PC++)); - break; + case 2: /* LA(m) n..n */ + FetchR( cpu_status.A, GetNibble( cpu_status.PC++ ) ); + break; - case 3: /* BUSCB */ - ExecBUSCB(); - break; + case 3: /* BUSCB */ + ExecBUSCB(); + break; - case 4: /* ABIT=0 d */ - ExecBIT0(cpu_status.A, GetNibble(cpu_status.PC++)); - break; + case 4: /* ABIT=0 d */ + ExecBIT0( cpu_status.A, GetNibble( cpu_status.PC++ ) ); + break; - case 5: /* ABIT=1 d */ - ExecBIT1(cpu_status.A, GetNibble(cpu_status.PC++)); - break; - - case 6: /* ?ABIT=0 d */ - TestBIT0(cpu_status.A, GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 7: /* ?ABIT=1 d */ - TestBIT1(cpu_status.A, GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 8: /* CBIT=0 d */ - ExecBIT0(cpu_status.C, GetNibble(cpu_status.PC++)); - break; + case 5: /* ABIT=1 d */ + ExecBIT1( cpu_status.A, GetNibble( cpu_status.PC++ ) ); + break; - case 9: /* CBIT=1 d */ - ExecBIT1(cpu_status.C, GetNibble(cpu_status.PC++)); - break; - - case 0xA: /* ?CBIT=0 d */ - TestBIT0(cpu_status.C, GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 0xB: /* ?CBIT=1 d */ - TestBIT1(cpu_status.C, GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 0xC: /* PC=(A) */ - cpu_status.PC = Get5NibblesAbs(R2Addr(cpu_status.A)); - break; + case 6: /* ?ABIT=0 d */ + TestBIT0( cpu_status.A, GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; - case 0xD: - /* BUSCD */ - ExecBUSCD(); - break; + case 7: /* ?ABIT=1 d */ + TestBIT1( cpu_status.A, GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; - case 0xE: - /* PC=(C) */ - cpu_status.PC = Get5NibblesAbs(R2Addr(cpu_status.C)); - break; + case 8: /* CBIT=0 d */ + ExecBIT0( cpu_status.C, GetNibble( cpu_status.PC++ ) ); + break; - case 0xF: - /* INTOFF */ - ExecINTOFF(); - break; + case 9: /* CBIT=1 d */ + ExecBIT1( cpu_status.C, GetNibble( cpu_status.PC++ ) ); + break; - default: - /* Unknown opcode */ - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } + case 0xA: /* ?CBIT=0 d */ + TestBIT0( cpu_status.C, GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; + + case 0xB: /* ?CBIT=1 d */ + TestBIT1( cpu_status.C, GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; + + case 0xC: /* PC=(A) */ + cpu_status.PC = Get5NibblesAbs( R2Addr( cpu_status.A ) ); + break; + + case 0xD: + /* BUSCD */ + ExecBUSCD(); + break; + + case 0xE: + /* PC=(C) */ + cpu_status.PC = Get5NibblesAbs( R2Addr( cpu_status.C ) ); + break; + + case 0xF: + /* INTOFF */ + ExecINTOFF(); + break; + + default: + /* Unknown opcode */ + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; + } } /* Instruction Group_80 */ -static void ExecGroup_80(void) +static void ExecGroup_80( void ) { - Nibble n = GetNibble(cpu_status.PC++); + Nibble n = GetNibble( cpu_status.PC++ ); - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_80"); - switch(n) - { - case 0: /* OUT=CS */ - ExecOUTCS(); - break; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_80" ); + switch ( n ) { + case 0: /* OUT=CS */ + ExecOUTCS(); + break; - case 1: /* OUT=C */ - ExecOUTC(); - break; + case 1: /* OUT=C */ + ExecOUTC(); + break; - case 2: /* A=IN */ - ExecIN(cpu_status.A); - break; + case 2: /* A=IN */ + ExecIN( cpu_status.A ); + break; - case 3: /* C=IN */ - ExecIN(cpu_status.C); - break; + case 3: /* C=IN */ + ExecIN( cpu_status.C ); + break; - case 4: /* UNCNFG */ - ModUnconfig(R2Addr(cpu_status.C)); - break; + case 4: /* UNCNFG */ + ModUnconfig( R2Addr( cpu_status.C ) ); + break; - case 5: /* CONFIG */ - ModConfig(R2Addr(cpu_status.C)); - break; + case 5: /* CONFIG */ + ModConfig( R2Addr( cpu_status.C ) ); + break; - case 6: /* C=ID */ - Addr2R(cpu_status.C, ModGetID()); - break; + case 6: /* C=ID */ + Addr2R( cpu_status.C, ModGetID() ); + break; - case 7: /* SHUTDN */ - ExecSHUTDN(); - break; + case 7: /* SHUTDN */ + ExecSHUTDN(); + break; - case 8: /* Group 808 */ - ExecGroup_808(); - break; + case 8: /* Group 808 */ + ExecGroup_808(); + break; - case 9: /* C+P+1 */ - AddRImm(cpu_status.C, FS_A, cpu_status.P); - break; + case 9: /* C+P+1 */ + AddRImm( cpu_status.C, FS_A, cpu_status.P ); + break; - case 0xA: /* RESET */ - ModReset(); - break; + case 0xA: /* RESET */ + ModReset(); + break; - case 0xB: /* BUSCC */ - ExecBUSCC(); - break; + case 0xB: /* BUSCC */ + ExecBUSCC(); + break; - case 0xE: /* SREQ? */ - ExecSREQ(); - break; + case 0xE: /* SREQ? */ + ExecSREQ(); + break; - case 0xC: /* C=P n */ - cpu_status.C[(int)GetNibble(cpu_status.PC++)] = cpu_status.P; - break; + case 0xC: /* C=P n */ + cpu_status.C[ ( int )GetNibble( cpu_status.PC++ ) ] = cpu_status.P; + break; - case 0xD: /* P=C n */ - SetP(cpu_status.C[(int)GetNibble(cpu_status.PC++)]); - break; + case 0xD: /* P=C n */ + SetP( cpu_status.C[ ( int )GetNibble( cpu_status.PC++ ) ] ); + break; - case 0xF: /* CPEX */ - { - Nibble t; - n = GetNibble(cpu_status.PC++); - t = cpu_status.P; - SetP(cpu_status.C[(int)n]); - cpu_status.C[(int)n] = t; - break; + case 0xF: /* CPEX */ + { + Nibble t; + n = GetNibble( cpu_status.PC++ ); + t = cpu_status.P; + SetP( cpu_status.C[ ( int )n ] ); + cpu_status.C[ ( int )n ] = t; + break; + } + + default: + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; } - - default: - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } } /* Special functions Group_81 */ -static void ExecSpecialGroup_81(int rp) +static void ExecSpecialGroup_81( int rp ) { - Nibble n, f, m; - int rn, ac; + Nibble n, f, m; + int rn, ac; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecSpecialGroup_81"); - switch(rp) - { - case 0: /* r=r+-CON fs, d */ - f = GetNibble(cpu_status.PC++); - n = GetNibble(cpu_status.PC++); - m = GetNibble(cpu_status.PC++); - rp = GetRP(n); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecSpecialGroup_81" ); + switch ( rp ) { + case 0: /* r=r+-CON fs, d */ + f = GetNibble( cpu_status.PC++ ); + n = GetNibble( cpu_status.PC++ ); + m = GetNibble( cpu_status.PC++ ); + rp = GetRP( n ); - if(GetAS(n)) /* Subtract */ - SubRImm(reg_pair_0[rp], f, m); - else /* Add */ - AddRImm(reg_pair_0[rp], f, m); - break; - - case 1: /* rSRB.f fs */ - f = GetNibble(cpu_status.PC++); - n = GetNibble(cpu_status.PC++); - rp = GetRP(n); - ShiftRightBitR(reg_pair_0[rp], f); - break; + if ( GetAS( n ) ) /* Subtract */ + SubRImm( reg_pair_0[ rp ], f, m ); + else /* Add */ + AddRImm( reg_pair_0[ rp ], f, m ); + break; - case 2: /* Rn=r.F fs, r=R0.F fs, rRnEX.F fs */ - f = GetNibble(cpu_status.PC++); - n = GetNibble(cpu_status.PC++); - m = GetNibble(cpu_status.PC++); - rn = GetRn(m); - ac = GetAC(m); + case 1: /* rSRB.f fs */ + f = GetNibble( cpu_status.PC++ ); + n = GetNibble( cpu_status.PC++ ); + rp = GetRP( n ); + ShiftRightBitR( reg_pair_0[ rp ], f ); + break; - switch(n) - { - case 0: /* Rn=r.F fs */ - CopyRR(cpu_status.R[rn], (ac ? cpu_status.C : cpu_status.A), f); - break; + case 2: /* Rn=r.F fs, r=R0.F fs, rRnEX.F fs */ + f = GetNibble( cpu_status.PC++ ); + n = GetNibble( cpu_status.PC++ ); + m = GetNibble( cpu_status.PC++ ); + rn = GetRn( m ); + ac = GetAC( m ); - case 1: /* r=R0.F fs */ - CopyRR((ac ? cpu_status.C : cpu_status.A), cpu_status.R[rn], f); - break; + switch ( n ) { + case 0: /* Rn=r.F fs */ + CopyRR( cpu_status.R[ rn ], ( ac ? cpu_status.C : cpu_status.A ), f ); + break; - case 2: /* rRnEX.F fs */ - ExchRR((ac ? cpu_status.C : cpu_status.A), cpu_status.R[rn], f); - break; + case 1: /* r=R0.F fs */ + CopyRR( ( ac ? cpu_status.C : cpu_status.A ), cpu_status.R[ rn ], f ); + break; + + case 2: /* rRnEX.F fs */ + ExchRR( ( ac ? cpu_status.C : cpu_status.A ), cpu_status.R[ rn ], f ); + break; + + default: + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; + } + break; + + case 3: /* Group 81B */ + switch ( n = GetNibble( cpu_status.PC++ ) ) { + case 2: /* PC=A */ + cpu_status.PC = R2Addr( cpu_status.A ); + break; + + case 3: /* PC=C */ + cpu_status.PC = R2Addr( cpu_status.C ); + break; + + case 4: /* A=PC */ + Addr2R( cpu_status.A, cpu_status.PC ); + break; + + case 5: /* C=PC */ + Addr2R( cpu_status.C, cpu_status.PC ); + break; + + case 6: /* APCEX */ + { + Address t; + t = R2Addr( cpu_status.A ); + Addr2R( cpu_status.A, cpu_status.PC ); + cpu_status.PC = t; + break; + } + + case 7: /* CPCEX */ + { + Address t; + t = R2Addr( cpu_status.C ); + Addr2R( cpu_status.C, cpu_status.PC ); + cpu_status.PC = t; + break; + } + + default: + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; + } + break; default: - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } - break; - - case 3: /* Group 81B */ - switch(n = GetNibble(cpu_status.PC++)) - { - case 2: /* PC=A */ - cpu_status.PC = R2Addr(cpu_status.A); - break; - - case 3: /* PC=C */ - cpu_status.PC = R2Addr(cpu_status.C); - break; - - case 4: /* A=PC */ - Addr2R(cpu_status.A, cpu_status.PC); - break; - - case 5: /* C=PC */ - Addr2R(cpu_status.C, cpu_status.PC); - break; - - case 6: /* APCEX */ - { - Address t; - t = R2Addr(cpu_status.A); - Addr2R(cpu_status.A, cpu_status.PC); - cpu_status.PC = t; - break; - } - - case 7: /* CPCEX */ - { - Address t; - t = R2Addr(cpu_status.C); - Addr2R(cpu_status.C, cpu_status.PC); - cpu_status.PC = t; - break; - } - - default: - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } - break; - - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Register_Pair" ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Register_Pair" ChfEnd; + ChfSignal(); + break; + } } - /* Instruction Group_8 */ -static void ExecGroup_8(void) +static void ExecGroup_8( void ) { - Nibble n = GetNibble(cpu_status.PC++); - Address addr; - int oc, rp; + Nibble n = GetNibble( cpu_status.PC++ ); + Address addr; + int oc, rp; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_8"); - switch(n) - { - case 0: - ExecGroup_80(); - break; + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "ExecGroup_8" ); + switch ( n ) { + case 0: + ExecGroup_80(); + break; - case 1: /* rSLC, rSRC, rSRB, Special Group_81 */ - n = GetNibble(cpu_status.PC++); - oc = GetOC_1(n); - rp = GetRP(n); + case 1: /* rSLC, rSRC, rSRB, Special Group_81 */ + n = GetNibble( cpu_status.PC++ ); + oc = GetOC_1( n ); + rp = GetRP( n ); - switch(oc) - { - case 0: /* rSLC */ - ShiftLeftCircR(reg_pair_0[rp], FS_W); - break; + switch ( oc ) { + case 0: /* rSLC */ + ShiftLeftCircR( reg_pair_0[ rp ], FS_W ); + break; - case 1: /* rSRC */ - ShiftRightCircR(reg_pair_0[rp], FS_W); - break; + case 1: /* rSRC */ + ShiftRightCircR( reg_pair_0[ rp ], FS_W ); + break; - case 2: /* Special Group_81 */ - ExecSpecialGroup_81(rp); - break; + case 2: /* Special Group_81 */ + ExecSpecialGroup_81( rp ); + break; - case 3: /* rSRB */ - ShiftRightBitR(reg_pair_0[rp], FS_W); - break; + case 3: /* rSRB */ + ShiftRightBitR( reg_pair_0[ rp ], FS_W ); + break; + + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } + break; + + case 2: /* CLRHSn */ + cpu_status.HST &= ~GetNibble( cpu_status.PC++ ); + break; + + case 3: /* ?HS=0 */ + n = GetNibble( cpu_status.PC++ ); + cpu_status.carry = ( ( cpu_status.HST & n ) == 0 ); + ExecGOYES_RTNYES(); + break; + + case 4: /* ST=0 n */ + cpu_status.ST &= ~st_bit_mask[ ( int )GetNibble( cpu_status.PC++ ) ]; + break; + + case 5: /* ST=1 n */ + cpu_status.ST |= st_bit_mask[ ( int )GetNibble( cpu_status.PC++ ) ]; + break; + + case 6: /* ?ST=0 n */ + cpu_status.carry = ( ( cpu_status.ST & st_bit_mask[ ( int )GetNibble( cpu_status.PC++ ) ] ) == 0 ); + ExecGOYES_RTNYES(); + break; + + case 7: /* ?ST=1 n */ + cpu_status.carry = ( ( cpu_status.ST & st_bit_mask[ ( int )GetNibble( cpu_status.PC++ ) ] ) != 0 ); + ExecGOYES_RTNYES(); + break; + + case 8: /* ?P#n */ + cpu_status.carry = ( cpu_status.P != GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; + + case 9: /* ?P=n */ + cpu_status.carry = ( cpu_status.P == GetNibble( cpu_status.PC++ ) ); + ExecGOYES_RTNYES(); + break; + + case 0xA: /* Test */ + ExecTest_8A(); + break; + + case 0xB: /* Test */ + ExecTest_8B(); + break; + + case 0xC: /* GOLONG */ + addr = Get4Nibbles2C( cpu_status.PC ); + cpu_status.PC += addr; + break; + + case 0xD: + /* GOVLNG */ + cpu_status.PC = Get5NibblesAbs( cpu_status.PC ); + break; + + case 0xE: + /* GOSUBL */ + addr = Get4Nibbles2C( cpu_status.PC ); + cpu_status.PC += 4; + PushRSTK( cpu_status.PC ); + cpu_status.PC += addr; + break; + + case 0xF: + /* GOSBVL */ + PushRSTK( cpu_status.PC + 5 ); + cpu_status.PC = Get5NibblesAbs( cpu_status.PC ); + break; default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } - break; - - case 2: /* CLRHSn */ - cpu_status.HST &= ~GetNibble(cpu_status.PC++); - break; - - case 3: /* ?HS=0 */ - n = GetNibble(cpu_status.PC++); - cpu_status.carry = ((cpu_status.HST & n) == 0); - ExecGOYES_RTNYES(); - break; - - case 4: /* ST=0 n */ - cpu_status.ST &= ~st_bit_mask[(int)GetNibble(cpu_status.PC++)]; - break; - - case 5: /* ST=1 n */ - cpu_status.ST |= st_bit_mask[(int)GetNibble(cpu_status.PC++)]; - break; - - case 6: /* ?ST=0 n */ - cpu_status.carry = - ((cpu_status.ST & st_bit_mask[(int)GetNibble(cpu_status.PC++)]) == 0); - ExecGOYES_RTNYES(); - break; - - case 7: /* ?ST=1 n */ - cpu_status.carry = - ((cpu_status.ST & st_bit_mask[(int)GetNibble(cpu_status.PC++)]) != 0); - ExecGOYES_RTNYES(); - break; - - case 8: /* ?P#n */ - cpu_status.carry = (cpu_status.P != GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 9: /* ?P=n */ - cpu_status.carry = (cpu_status.P == GetNibble(cpu_status.PC++)); - ExecGOYES_RTNYES(); - break; - - case 0xA: /* Test */ - ExecTest_8A(); - break; - - case 0xB: /* Test */ - ExecTest_8B(); - break; - - case 0xC: /* GOLONG */ - addr = Get4Nibbles2C(cpu_status.PC); - cpu_status.PC += addr; - break; - - case 0xD: - /* GOVLNG */ - cpu_status.PC = Get5NibblesAbs(cpu_status.PC); - break; - - case 0xE: - /* GOSUBL */ - addr = Get4Nibbles2C(cpu_status.PC); - cpu_status.PC += 4; - PushRSTK(cpu_status.PC); - cpu_status.PC += addr; - break; - - case 0xF: - /* GOSBVL */ - PushRSTK(cpu_status.PC + 5); - cpu_status.PC = Get5NibblesAbs(cpu_status.PC); - break; - - default: - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, cpu_status.PC, n ChfEnd; + ChfSignal(); + break; + } } - /*--------------------------------------------------------------------------- - Private functions: dump + Private functions: dump ---------------------------------------------------------------------------*/ -const char *DumpR(Nibble *r) +const char* DumpR( Nibble* r ) { - static char b[NIBBLE_PER_REGISTER+1]; - static const char hex_char[NIBBLE_PER_REGISTER] = "0123456789ABCDEF"; - int n; + static char b[ NIBBLE_PER_REGISTER + 1 ]; + static const char hex_char[ NIBBLE_PER_REGISTER ] = "0123456789ABCDEF"; + int n; - for(n=0; n 0) - if(--cpu_status.halt == 0) - { - debug0(DEBUG_C_INT, CPU_I_RUN); + if ( cpu_status.halt > 0 ) + if ( --cpu_status.halt == 0 ) { + debug0( DEBUG_C_INT, CPU_I_RUN ); - /* CPU must actually be awoken: call CpuWake() */ - CpuWake(); - } + /* CPU must actually be awoken: call CpuWake() */ + CpuWake(); + } return cpu_status.halt; #endif } - /* .+ .title : CpuHaltAllowed @@ -2955,20 +2874,20 @@ int CpuRunRequest(void) is allowed, zero otherwise. .call : - s = CpuHaltRequest(); + s = CpuHaltRequest(); .input : - void + void .output : - int s, non-zero if CpuHaltRequest() is allowed, 0 otherwise + int s, non-zero if CpuHaltRequest() is allowed, 0 otherwise .status_codes : - CPU_I_CALLED + CPU_I_CALLED .notes : 3.13, 7-Nov-2000, creation */ -int CpuHaltAllowed(void) +int CpuHaltAllowed( void ) { - debug1(DEBUG_C_TRACE|DEBUG_C_INT, CPU_I_CALLED, "CpuHaltAllowed"); + debug1( DEBUG_C_TRACE | DEBUG_C_INT, CPU_I_CALLED, "CpuHaltAllowed" ); #ifdef CPU_SPIN_SHUTDN return 0; @@ -2979,7 +2898,6 @@ int CpuHaltAllowed(void) #endif } - /* .+ .title : DumpCpuStatus @@ -2989,68 +2907,60 @@ int CpuHaltAllowed(void) This function dumps the current CPU status into the string buffer 'ob'. .call : - DumpCpuStatus(ob); + DumpCpuStatus(ob); .input : - void + void .output : - char ob[DUMP_CPU_STATUS_OB_SIZE]; + char ob[DUMP_CPU_STATUS_OB_SIZE]; .status_codes : - * + * .notes : 1.1, 3-Feb-1998, creation .- */ -void DumpCpuStatus(char ob[DUMP_CPU_STATUS_OB_SIZE]) +void DumpCpuStatus( char ob[ DUMP_CPU_STATUS_OB_SIZE ] ) { - static const char *work_n[N_WORKING_REGISTER] = { "A", "B", "C", "D" }; - char dob[DISASSEMBLE_OB_SIZE]; - int n; + static const char* work_n[ N_WORKING_REGISTER ] = { "A", "B", "C", "D" }; + char dob[ DISASSEMBLE_OB_SIZE ]; + int n; - /* Dump PC and current instruction */ - (void)Disassemble(cpu_status.PC, dob); - sprintf(ob, "%s\n\n", dob); - ob += strlen(ob); + /* Dump PC and current instruction */ + ( void )Disassemble( cpu_status.PC, dob ); + sprintf( ob, "%s\n\n", dob ); + ob += strlen( ob ); - /* Dump A, B, C, D */ - for(n=0; n>2) + nibble (bits 3..2 >>2) GetOC_2(f, o) returns the long operation code from the given - nibbles (f bit 3, o bits 3..2) + nibbles (f bit 3, o bits 3..2) GetOC_3b(o) returns the long operation code from the given - nibble (bits 2..0) + nibble (bits 2..0) GetRP(o) returns the register-pair identifier from the given - nibble (bits 1..0) + nibble (bits 1..0) GetRn(r) returns the R register index from the given nibble - (bits 2..0) + (bits 2..0) GetAC(r) returns the A/C register flag from the given nibble - (bit 3) - =0: register A - !=0: register C + (bit 3) + =0: register A + !=0: register C GetAS(r) returns the add/subtract flag from the given nibble - (bit 3) - =0: add - !=0: subtract -*/ -#define GetFS(f) ((f) & 0x7) -#define GetImmFS(o) ((o) & 0x8) -#define GetOC_1(o) (((o) & 0xC)>>2) -#define GetOC_2(f, o) ((((f) & 0x8)>>1) | (((o) & 0xC)>>2)) -#define GetOC_3b(o) ((o) & 0x7) -#define GetRP(o) ((o) & 0x3) -#define GetRn(r) ((r) & 0x7) -#define GetAC(r) ((r) & 0x8) -#define GetAS(r) ((r) & 0x8) - + (bit 3) + =0: add + !=0: subtract +*/ +#define GetFS( f ) ( ( f ) & 0x7 ) +#define GetImmFS( o ) ( ( o ) & 0x8 ) +#define GetOC_1( o ) ( ( ( o ) & 0xC ) >> 2 ) +#define GetOC_2( f, o ) ( ( ( ( f ) & 0x8 ) >> 1 ) | ( ( ( o ) & 0xC ) >> 2 ) ) +#define GetOC_3b( o ) ( ( o ) & 0x7 ) +#define GetRP( o ) ( ( o ) & 0x3 ) +#define GetRn( r ) ( ( r ) & 0x7 ) +#define GetAC( r ) ( ( r ) & 0x8 ) +#define GetAS( r ) ( ( r ) & 0x8 ) /* Field selector codes */ -#define FS_P 0 -#define FS_WP 1 -#define FS_XS 2 -#define FS_X 3 -#define FS_S 4 -#define FS_M 5 -#define FS_B 6 -#define FS_W 7 -#define FS_A 15 -#define N_FS 16 /* Total # of FS codes */ - +#define FS_P 0 +#define FS_WP 1 +#define FS_XS 2 +#define FS_X 3 +#define FS_S 4 +#define FS_M 5 +#define FS_B 6 +#define FS_W 7 +#define FS_A 15 +#define N_FS 16 /* Total # of FS codes */ /* Register pair codes */ -#define RP_AB 0 -#define RP_BC 1 -#define RP_CA 2 -#define RP_DC 3 -#define N_RP 4 /* Total # of RP codes */ - +#define RP_AB 0 +#define RP_BC 1 +#define RP_CA 2 +#define RP_DC 3 +#define N_RP 4 /* Total # of RP codes */ /* Masks */ -#define NIBBLE_MASK ((Nibble)0xF) -#define ADDRESS_MASK ((Address)0xFFFFF) +#define NIBBLE_MASK ( ( Nibble )0xF ) +#define ADDRESS_MASK ( ( Address )0xFFFFF ) -#define CLRST_MASK ((ProgramStatusRegister)0xF000) -#define D_S_MASK ((Address)0xF0000) -#define RETURN_SP_MASK 0x7 +#define CLRST_MASK ( ( ProgramStatusRegister )0xF000 ) +#define D_S_MASK ( ( Address )0xF0000 ) +#define RETURN_SP_MASK 0x7 - -typedef int1 Bit; -typedef int4 Nibble; -typedef int20 Address; -typedef int12 OutputRegister; -typedef int16 InputRegister; -typedef int16 ProgramStatusRegister; -typedef Nibble DataRegister[NIBBLE_PER_REGISTER]; +typedef int1 Bit; +typedef int4 Nibble; +typedef int20 Address; +typedef int12 OutputRegister; +typedef int16 InputRegister; +typedef int16 ProgramStatusRegister; +typedef Nibble DataRegister[ NIBBLE_PER_REGISTER ]; /* The XAddress data type holds extended addresses used to access Port 2 */ -typedef int32 XAddress; +typedef int32 XAddress; -enum IntRequest -{ - INT_REQUEST_NONE, - INT_REQUEST_IRQ, - INT_REQUEST_NMI -}; +enum IntRequest { INT_REQUEST_NONE, INT_REQUEST_IRQ, INT_REQUEST_NMI }; -struct CpuStatus -{ - DataRegister work[N_WORKING_REGISTER]; -#define A work[0] -#define B work[1] -#define C work[2] -#define D work[3] +struct CpuStatus { + DataRegister work[ N_WORKING_REGISTER ]; +#define A work[ 0 ] +#define B work[ 1 ] +#define C work[ 2 ] +#define D work[ 3 ] - DataRegister R[N_SCRATCH_REGISTER_ALL]; -#define R0 R[0] -#define R1 R[1] -#define R2 R[2] -#define R3 R[3] -#define R4 R[4] + DataRegister R[ N_SCRATCH_REGISTER_ALL ]; +#define R0 R[ 0 ] +#define R1 R[ 1 ] +#define R2 R[ 2 ] +#define R3 R[ 3 ] +#define R4 R[ 4 ] - Address DAT[N_DATA_POINTER_REGISTER]; -#define D0 DAT[0] -#define D1 DAT[1] + Address DAT[ N_DATA_POINTER_REGISTER ]; +#define D0 DAT[ 0 ] +#define D1 DAT[ 1 ] - Nibble P; - Address PC; - InputRegister IN; - OutputRegister OUT; - ProgramStatusRegister ST; + Nibble P; + Address PC; + InputRegister IN; + OutputRegister OUT; + ProgramStatusRegister ST; - Nibble HST; -#define HST_MP_MASK 0x08 -#define HST_SR_MASK 0x04 -#define HST_SB_MASK 0x02 -#define HST_XM_MASK 0x01 + Nibble HST; +#define HST_MP_MASK 0x08 +#define HST_SR_MASK 0x04 +#define HST_SB_MASK 0x02 +#define HST_XM_MASK 0x01 - Address return_stack[RETURN_STACK_SIZE]; - int return_sp; + Address return_stack[ RETURN_STACK_SIZE ]; + int return_sp; - int fs_idx_lo[N_FS]; - int fs_idx_hi[N_FS]; - int hexmode; /* DEC/HEX mode, 1=HEX */ - int carry; /* Carry bit 1=set */ - int shutdn; /* SHUTDN flag, 1=executed */ - int halt; /* 3.13: # of pending Halt */ - int int_enable; /* Int. enable, 1=enabled */ - int int_service; /* Int. service, 1=service */ - enum IntRequest int_pending; /* Pending interrupt request */ + int fs_idx_lo[ N_FS ]; + int fs_idx_hi[ N_FS ]; + int hexmode; /* DEC/HEX mode, 1=HEX */ + int carry; /* Carry bit 1=set */ + int shutdn; /* SHUTDN flag, 1=executed */ + int halt; /* 3.13: # of pending Halt */ + int int_enable; /* Int. enable, 1=enabled */ + int int_service; /* Int. service, 1=service */ + enum IntRequest int_pending; /* Pending interrupt request */ - /* 3.13: inner_loop_max gives the upper limit of the CPU speed if the - compile-time option REAL_CPU_SPEED is defined. When the CPU is reset - it has the default value INNER_LOOP_MAX, that should be close to the - real cpu speed (~4MHz). - */ - int inner_loop; /* Inner loop multiplier */ - int inner_loop_max; /* Max value of inner_loop */ -#define INNER_LOOP_MAX 26 -#define INNER_LOOP_MED 13 -#define INNER_LOOP_MIN 2 + /* 3.13: inner_loop_max gives the upper limit of the CPU speed if the + compile-time option REAL_CPU_SPEED is defined. When the CPU is reset + it has the default value INNER_LOOP_MAX, that should be close to the + real cpu speed (~4MHz). + */ + int inner_loop; /* Inner loop multiplier */ + int inner_loop_max; /* Max value of inner_loop */ +#define INNER_LOOP_MAX 26 +#define INNER_LOOP_MED 13 +#define INNER_LOOP_MIN 2 #ifdef CPU_SPIN_LOOP - int reset_req; /* Reset req. after shutdn */ + int reset_req; /* Reset req. after shutdn */ #endif }; -enum ExitOption /* 2.1: EmulatorExit() option */ +enum ExitOption /* 2.1: EmulatorExit() option */ { IMMEDIATE_EXIT, SAVE_AND_EXIT }; - /*--------------------------------------------------------------------------- - Global variables + Global variables ---------------------------------------------------------------------------*/ extern struct CpuStatus cpu_status; - /*--------------------------------------------------------------------------- - Chf condition codes + Chf condition codes ---------------------------------------------------------------------------*/ -#define CPU_I_CALLED 101 /* Function %s called */ -#define CPU_I_EXECUTING 102 /* Executing @PC %X */ -#define CPU_I_SHUTDN 103 /* Shutdown */ -#define CPU_I_WAKE 104 /* Wake */ -#define CPU_I_INT 105 /* %s request accepted */ -#define CPU_I_INT_PENDING 106 /* %s request pending */ -#define CPU_I_RTI_LOOP 107 /* RTI loop to service %s */ -#define CPU_I_RTI_END 108 /* RTI returning */ -#define CPU_I_INTON 109 /* INTON servicing %s */ -#define CPU_I_REVISION 110 /* CPU emulation revision: %s */ -#define CPU_I_TIMER1_EX 111 /* Timer 1 expired; ctrl=%x */ -#define CPU_I_TIMER2_EX 112 /* Timer 1 expired; ctrl=%x */ -#define CPU_I_EMULATOR_INT 113 /* Emulator interrupt req. detected */ -#define CPU_I_TIMER_ST 114 /* 3.1: Timer %s st: ctrl %x, val %x */ -#define CPU_I_TIMER_EXP 115 /* 3.1: Timer %s expiration %d ms */ -#define CPU_I_IDLE_X_LOOP 116 /* 3.1: Start idle loop, t/out %d ms */ -#define CPU_I_ELAPSED 117 /* 3.1: Spent %d us in idle loop */ -#define CPU_I_HALT 118 /* 3.13: CPU halted */ -#define CPU_I_RUN 119 /* 3.13: CPU running */ -#define CPU_W_RESETTING 201 /* Resetting CPU */ -#define CPU_W_BAD_MONITOR_CMD 202 /* Bad monitor command: %s */ -#define CPU_E_BAD_OPCODE 301 /* Bad opc. pc=%x, value=%x */ -#define CPU_E_SAVE 302 /* Can't save CPU status */ -#define CPU_E_NO_HALT 303 /* 3.13: Halt/Run not allowed */ -#define CPU_F_INTERR 401 /* Internal error %s */ -#define CPU_F_BAD_SHUTDN 402 /* Unexpected CPU shutdown */ - +#define CPU_I_CALLED 101 /* Function %s called */ +#define CPU_I_EXECUTING 102 /* Executing @PC %X */ +#define CPU_I_SHUTDN 103 /* Shutdown */ +#define CPU_I_WAKE 104 /* Wake */ +#define CPU_I_INT 105 /* %s request accepted */ +#define CPU_I_INT_PENDING 106 /* %s request pending */ +#define CPU_I_RTI_LOOP 107 /* RTI loop to service %s */ +#define CPU_I_RTI_END 108 /* RTI returning */ +#define CPU_I_INTON 109 /* INTON servicing %s */ +#define CPU_I_REVISION 110 /* CPU emulation revision: %s */ +#define CPU_I_TIMER1_EX 111 /* Timer 1 expired; ctrl=%x */ +#define CPU_I_TIMER2_EX 112 /* Timer 1 expired; ctrl=%x */ +#define CPU_I_EMULATOR_INT 113 /* Emulator interrupt req. detected */ +#define CPU_I_TIMER_ST 114 /* 3.1: Timer %s st: ctrl %x, val %x */ +#define CPU_I_TIMER_EXP 115 /* 3.1: Timer %s expiration %d ms */ +#define CPU_I_IDLE_X_LOOP 116 /* 3.1: Start idle loop, t/out %d ms */ +#define CPU_I_ELAPSED 117 /* 3.1: Spent %d us in idle loop */ +#define CPU_I_HALT 118 /* 3.13: CPU halted */ +#define CPU_I_RUN 119 /* 3.13: CPU running */ +#define CPU_W_RESETTING 201 /* Resetting CPU */ +#define CPU_W_BAD_MONITOR_CMD 202 /* Bad monitor command: %s */ +#define CPU_E_BAD_OPCODE 301 /* Bad opc. pc=%x, value=%x */ +#define CPU_E_SAVE 302 /* Can't save CPU status */ +#define CPU_E_NO_HALT 303 /* 3.13: Halt/Run not allowed */ +#define CPU_F_INTERR 401 /* Internal error %s */ +#define CPU_F_BAD_SHUTDN 402 /* Unexpected CPU shutdown */ /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ -void CpuInit(void); -void CpuReset(void); -void CpuSave(void); -void OneStep(void); -void CpuIntRequest(enum IntRequest ireq); -void CpuWake(void); -void Emulator(void); -void EmulatorIntRequest(void); -void EmulatorInit(void); /* 2.1 */ -void EmulatorExit(enum ExitOption opt); /* 2.1 */ -int CpuHaltRequest(void); /* 3.13 */ -int CpuRunRequest(void); /* 3.13 */ -int CpuHaltAllowed(void); /* 3.13 */ +void CpuInit( void ); +void CpuReset( void ); +void CpuSave( void ); +void OneStep( void ); +void CpuIntRequest( enum IntRequest ireq ); +void CpuWake( void ); +void Emulator( void ); +void EmulatorIntRequest( void ); +void EmulatorInit( void ); /* 2.1 */ +void EmulatorExit( enum ExitOption opt ); /* 2.1 */ +int CpuHaltRequest( void ); /* 3.13 */ +int CpuRunRequest( void ); /* 3.13 */ +int CpuHaltAllowed( void ); /* 3.13 */ -Address Disassemble(Address pc, char ob[DISASSEMBLE_OB_SIZE]); -void DumpCpuStatus(char ob[DUMP_CPU_STATUS_OB_SIZE]); +Address Disassemble( Address pc, char ob[ DISASSEMBLE_OB_SIZE ] ); +void DumpCpuStatus( char ob[ DUMP_CPU_STATUS_OB_SIZE ] ); diff --git a/src/debug.c b/src/debug.c index 93e8051..a6977c7 100644 --- a/src/debug.c +++ b/src/debug.c @@ -73,25 +73,23 @@ static char rcs_id[] = "$Id: debug.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "cpu.h" #include "debug.h" -#define CHF_MODULE_ID DEBUG_CHF_MODULE_ID +#define CHF_MODULE_ID DEBUG_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Static/Global variables + Static/Global variables ---------------------------------------------------------------------------*/ #ifdef DEBUG -#ifdef DEBUG_LEVEL +# ifdef DEBUG_LEVEL int debug_level = DEBUG_LEVEL; -#else +# else int debug_level = 0; +# endif #endif -#endif - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ /* .+ @@ -105,23 +103,23 @@ int debug_level = 0; it signals a condition and does nothing more. .call : - SetDebugLevel(new_level) + SetDebugLevel(new_level) .input : - int new_level, new value of the debug_level flag + int new_level, new value of the debug_level flag .output : - void + void .status_codes : - DEBUG_W_NOT_SUPPORTED + DEBUG_W_NOT_SUPPORTED .notes : 1.1, 28-Jan-1998, creation .- */ -void SetDebugLevel(int new_level) +void SetDebugLevel( int new_level ) { #ifdef DEBUG - debug_level = new_level; + debug_level = new_level; #else - ChfCondition DEBUG_W_NOT_SUPPORTED, CHF_WARNING ChfEnd; - ChfSignal(); + ChfCondition DEBUG_W_NOT_SUPPORTED, CHF_WARNING ChfEnd; + ChfSignal(); #endif } diff --git a/src/debug.h b/src/debug.h index c13cc0e..bf5b1e9 100644 --- a/src/debug.h +++ b/src/debug.h @@ -44,13 +44,13 @@ .description : This header defines the following macros: - - debug0(debug_class, condition_code) - - debug1(debug_class, condition_code, arg_1) - - debug2(debug_class, condition_code, arg_1, arg_2) - - debug3(debug_class, condition_code, arg_1, arg_2, arg_3) + - debug0(debug_class, condition_code) + - debug1(debug_class, condition_code, arg_1) + - debug2(debug_class, condition_code, arg_1, arg_2) + - debug3(debug_class, condition_code, arg_1, arg_2, arg_3) used throughout the source code for debugging purposes. - + If the DEBUG cpp symbol is defined, each invocation of these macros is expanded into a block of code that, at runtime, checks if the global variable 'debug_level' has set at least one of the bit 'debug_class' has @@ -60,7 +60,7 @@ If this condition is met, the code generates and immediately signals the given condition code using the Chf facility, with severity CHF_INFO, otherwise nothing is done. - + The arguments arg_1, arg_2, and arg_3 are used as additional arguments of the condition. @@ -101,73 +101,62 @@ #ifdef DEBUG -#define debug_preamble(debug_class, condition_code) \ - { \ - extern int debug_level; \ - if(debug_level & (debug_class)) \ - { \ - ChfCondition (condition_code), CHF_INFO +# define debug_preamble( debug_class, condition_code ) \ + { \ + extern int debug_level; \ + if ( debug_level & ( debug_class ) ) { \ + ChfCondition( condition_code ), CHF_INFO -#define debug_postamble \ - ChfEnd; \ - ChfSignal(); \ - } \ - } +# define debug_postamble \ + ChfEnd; \ + ChfSignal(); \ + } \ + } -#define debug0(debug_class, condition_code) \ - debug_preamble(debug_class, condition_code) \ - debug_postamble +# define debug0( debug_class, condition_code ) debug_preamble( debug_class, condition_code ) debug_postamble -#define debug1(debug_class, condition_code, arg_1) \ - debug_preamble(debug_class, condition_code), arg_1 \ - debug_postamble +# define debug1( debug_class, condition_code, arg_1 ) debug_preamble( debug_class, condition_code ), arg_1 debug_postamble -#define debug2(debug_class, condition_code, arg_1, arg_2) \ - debug_preamble(debug_class, condition_code), arg_1, arg_2 \ - debug_postamble +# define debug2( debug_class, condition_code, arg_1, arg_2 ) debug_preamble( debug_class, condition_code ), arg_1, arg_2 debug_postamble -#define debug3(debug_class, condition_code, arg_1, arg_2, arg_3) \ - debug_preamble(debug_class, condition_code), arg_1, arg_2, arg_3 \ - debug_postamble +# define debug3( debug_class, condition_code, arg_1, arg_2, arg_3 ) \ + debug_preamble( debug_class, condition_code ), arg_1, arg_2, arg_3 debug_postamble #else -#define debug0(debug_class, condition_code) -#define debug1(debug_class, condition_code, arg_1) -#define debug2(debug_class, condition_code, arg_1, arg_2) -#define debug3(debug_class, condition_code, arg_1, arg_2, arg_3) +# define debug0( debug_class, condition_code ) +# define debug1( debug_class, condition_code, arg_1 ) +# define debug2( debug_class, condition_code, arg_1, arg_2 ) +# define debug3( debug_class, condition_code, arg_1, arg_2, arg_3 ) #endif - /*--------------------------------------------------------------------------- - Debug classes + Debug classes ---------------------------------------------------------------------------*/ -#define DEBUG_C_TRACE 0x8000 /* Function Call trace */ -#define DEBUG_C_MODULES 0x4000 /* Modules configuration */ -#define DEBUG_C_DISPLAY 0x2000 /* Display activity */ -#define DEBUG_C_INT 0x1000 /* Interrupt activity */ -#define DEBUG_C_TIMERS 0x0800 /* Timers activity */ -#define DEBUG_C_SERIAL 0x0400 /* 2.5: Serial port activity */ -#define DEBUG_C_MOD_CACHE 0x0200 /* 2.7: Module cache */ -#define DEBUG_C_IMPLEMENTATION 0x0100 /* Feature implementation */ -#define DEBUG_C_FLASH 0x0080 /* 3.3: Flash ROM */ -#define DEBUG_C_X_FUNC 0x0040 /* 3.13: Extended functions */ -#define DEBUG_C_REVISION 0x0010 /* Revision information */ -#define DEBUG_C_X11 0x0001 /* X11 Interface */ - +#define DEBUG_C_TRACE 0x8000 /* Function Call trace */ +#define DEBUG_C_MODULES 0x4000 /* Modules configuration */ +#define DEBUG_C_DISPLAY 0x2000 /* Display activity */ +#define DEBUG_C_INT 0x1000 /* Interrupt activity */ +#define DEBUG_C_TIMERS 0x0800 /* Timers activity */ +#define DEBUG_C_SERIAL 0x0400 /* 2.5: Serial port activity */ +#define DEBUG_C_MOD_CACHE 0x0200 /* 2.7: Module cache */ +#define DEBUG_C_IMPLEMENTATION 0x0100 /* Feature implementation */ +#define DEBUG_C_FLASH 0x0080 /* 3.3: Flash ROM */ +#define DEBUG_C_X_FUNC 0x0040 /* 3.13: Extended functions */ +#define DEBUG_C_REVISION 0x0010 /* Revision information */ +#define DEBUG_C_X11 0x0001 /* X11 Interface */ /*--------------------------------------------------------------------------- - Chf condition codes + Chf condition codes ---------------------------------------------------------------------------*/ -#define DEBUG_W_NOT_SUPPORTED 201 /* Debug not supported */ -#define DEBUG_W_BAD_CMD 202 /* Invalid command */ - +#define DEBUG_W_NOT_SUPPORTED 201 /* Debug not supported */ +#define DEBUG_W_BAD_CMD 202 /* Invalid command */ /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ -void SetDebugLevel(int new_level); +void SetDebugLevel( int new_level ); diff --git a/src/dis.c b/src/dis.c index 516cc6f..7f0d4ff 100644 --- a/src/dis.c +++ b/src/dis.c @@ -46,9 +46,9 @@ Saturn CPU. The syntax of the disassembled code conforms to the reference: - SASM.DOC by HP (HORN disk 4) + SASM.DOC by HP (HORN disk 4) with some extensions from - Guide to the Saturn Processor Rev. 0.00f by Matthew Mastracci + Guide to the Saturn Processor Rev. 0.00f by Matthew Mastracci The disassembler is almost not table-driven, because its structure has been kept as similar as possible to the actual CPU emulator code. @@ -87,7 +87,7 @@ static char rcs_id[] = "$Id: dis.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include #include #include -#include /* 3.1: strcpy(), strcat(), strlen() */ +#include /* 3.1: strcpy(), strcat(), strlen() */ #include "config.h" #include "machdep.h" @@ -95,247 +95,211 @@ static char rcs_id[] = "$Id: dis.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "modules.h" #include "debug.h" -#define CHF_MODULE_ID CPU_CHF_MODULE_ID +#define CHF_MODULE_ID CPU_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Private functions/macros/variables + Private functions/macros/variables ---------------------------------------------------------------------------*/ /* Mnemonics */ -static const char *hex_digit[] = - { "0", "1", "2", "3", "4", "5", "6", "7", - "8", "9", "A", "B", "C", "D", "E", "F" }; +static const char* hex_digit[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" }; -static const char *reg_pair[] = - { "AB", "BC", "CA", "DC" }; +static const char* reg_pair[] = { "AB", "BC", "CA", "DC" }; -static const char *rn_name[] = - { "R0", "R1", "R2", "R3", "R4", "?R5", "?R6", "?R7" }; +static const char* rn_name[] = { "R0", "R1", "R2", "R3", "R4", "?R5", "?R6", "?R7" }; -static const char *field_sel[] = - { "P", "WP", "XS", "X", "S", "M", "B", "W", - "?[8]", "?[9]", "?[A]", "?[B]", "?[C]", "?[D]", "?[E]", "A" }; +static const char* field_sel[] = { "P", "WP", "XS", "X", "S", "M", "B", "W", "?[8]", "?[9]", "?[A]", "?[B]", "?[C]", "?[D]", "?[E]", "A" }; -static const char *group_0_opc[] = - { "RTNSXM", "RTN", "RTNSC", "RTNCC", "SETHEX", "SETDEC", "RSTK=C", "C=RSTK", - "CLRST", "C=ST", "ST=C", "CSTEX", "P=P+1", "P=P-1", NULL, "RTI" }; +static const char* group_0_opc[] = { "RTNSXM", "RTN", "RTNSC", "RTNCC", "SETHEX", "SETDEC", "RSTK=C", "C=RSTK", + "CLRST", "C=ST", "ST=C", "CSTEX", "P=P+1", "P=P-1", NULL, "RTI" }; -static const char *group_13_opc[] = - { "D0=A", "D1=A", "AD0EX", "AD1EX", "D0=C", "D1=C", "CD0EX", "CD1EX", - "D0=AS", "D1=AS", "AD0XS", "AD1XS", "D0=CS", "D1=CS", "CD0XS", "CD1XS" }; +static const char* group_13_opc[] = { "D0=A", "D1=A", "AD0EX", "AD1EX", "D0=C", "D1=C", "CD0EX", "CD1EX", + "D0=AS", "D1=AS", "AD0XS", "AD1XS", "D0=CS", "D1=CS", "CD0XS", "CD1XS" }; -static const char *group_14_opc[] = - { "DAT0=A\tA", "DAT1=A\tA", "A=DAT0\tA", "A=DAT1\tA", - "DAT0=C\tA", "DAT1=C\tA", "C=DAT0\tA", "C=DAT1\tA", - "DAT0=A\tB", "DAT1=A\tB", "A=DAT0\tB", "A=DAT1\tB", - "DAT0=C\tB", "DAT1=C\tB", "C=DAT0\tB", "C=DAT1\tB" }; +static const char* group_14_opc[] = { "DAT0=A\tA", "DAT1=A\tA", "A=DAT0\tA", "A=DAT1\tA", "DAT0=C\tA", "DAT1=C\tA", + "C=DAT0\tA", "C=DAT1\tA", "DAT0=A\tB", "DAT1=A\tB", "A=DAT0\tB", "A=DAT1\tB", + "DAT0=C\tB", "DAT1=C\tB", "C=DAT0\tB", "C=DAT1\tB" }; -static const char *group_15_opc[] = - { "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1", - "DAT0=C", "DAT1=C", "C=DAT0", "C=DAT1" }; +static const char* group_15_opc[] = { "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1", "DAT0=C", "DAT1=C", "C=DAT0", "C=DAT1" }; -static const char *group_80_opc[] = - { "OUT=CS", "OUT=C", "A=IN", "C=IN", "UNCNFG", "CONFIG", "C=ID", "SHUTDN", - "?", "C+P+1", "RESET", "BUSCC", "?", "?", "SREQ?", "?" }; - -static const char *group_81B_opc[] = - { "?", "?", "PC=A", "PC=C", "A=PC", "C=PC", "APCEX", "CPCEX", - "?", "?", "?", "?", "?", "?", "?", "?" }; +static const char* group_80_opc[] = { "OUT=CS", "OUT=C", "A=IN", "C=IN", "UNCNFG", "CONFIG", "C=ID", "SHUTDN", + "?", "C+P+1", "RESET", "BUSCC", "?", "?", "SREQ?", "?" }; +static const char* group_81B_opc[] = { "?", "?", "PC=A", "PC=C", "A=PC", "C=PC", "APCEX", "CPCEX", "?", "?", "?", "?", "?", "?", "?", "?" }; /* Get a nibble from main memory */ -#define GetNibble FetchNibble - +#define GetNibble FetchNibble /* Read two nibbles in two-complement form, starting from pc, */ -static Address Get2Nibbles2C(Address pc) +static Address Get2Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ); - return (v & 0x80) ? v - 0x100 : v; + return ( v & 0x80 ) ? v - 0x100 : v; } - /* Read three nibbles in two-complement form, starting from pc, */ -static Address Get3Nibbles2C(Address pc) +static Address Get3Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ); - return (v & 0x800) ? v - 0x1000 : v; + return ( v & 0x800 ) ? v - 0x1000 : v; } - /* Read four nibbles in two-complement form, starting from pc */ -static Address Get4Nibbles2C(Address pc) +static Address Get4Nibbles2C( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) | + ( ( Address )GetNibble( pc + 3 ) << 12 ); - return (v & 0x8000) ? v - 0x10000 : v; + return ( v & 0x8000 ) ? v - 0x10000 : v; } - /* Read four nibbles in absolute form, starting from pc */ -static Address Get5NibblesAbs(Address pc) +static Address Get5NibblesAbs( Address pc ) { - Address v = (Address)GetNibble(pc) | ((Address)GetNibble(pc+1) << 4) | - ((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12) | - ((Address)GetNibble(pc+4) << 16); + Address v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) | + ( ( Address )GetNibble( pc + 3 ) << 12 ) | ( ( Address )GetNibble( pc + 4 ) << 16 ); - return v; + return v; } - /* Disassemble Hex constant, starting from 'start', for 'm' nibbles; returns the address of the next instruction */ -static Address DisHexConstant(Address start, char *ob, int m) +static Address DisHexConstant( Address start, char* ob, int m ) { - int i; + int i; - for(i=0; i%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 4: + sprintf( ob, "?%c>%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 5: - sprintf(ob, "?%c<%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 5: + sprintf( ob, "?%c<%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 6: - sprintf(ob, "?%c>=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 6: + sprintf( ob, "?%c>=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 7: - sprintf(ob, "?%c<=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 7: + sprintf( ob, "?%c<=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(fs, ob); + /* Decode field selector */ + DisFIELD_SEL( fs, ob ); - /* Decode RTNYES/GOYES */ - return DisGOYES_RTNYES(pc, ob); + /* Decode RTNYES/GOYES */ + return DisGOYES_RTNYES( pc, ob ); } - /* ..., Register Operation with Field Selector, opcode Afo, length 3 FS = f & 0x7 @@ -502,8 +464,8 @@ static Address DisTest_9(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - f o OC RP + Opcode table + f o OC RP --- A=A+B a 0 0 0 B=B+C a 1 0 1 @@ -547,66 +509,61 @@ static Address DisTest_9(Address pc, char *ob) --- */ -static Address DisRegOp_A(Address pc, char *ob) +static Address DisRegOp_A( Address pc, char* ob ) { - Nibble f = GetNibble(pc++); - Nibble o = GetNibble(pc++); + Nibble f = GetNibble( pc++ ); + Nibble o = GetNibble( pc++ ); - int fs = GetFS(f); - int oc = GetOC_2(f, o); - int rp = GetRP(o); + int fs = GetFS( f ); + int oc = GetOC_2( f, o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c=%c-1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=%c-1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 4: - sprintf(ob, "%c=0", reg_pair[rp][0]); - break; + case 4: + sprintf( ob, "%c=0", reg_pair[ rp ][ 0 ] ); + break; - case 5: - sprintf(ob, "%c=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 5: + sprintf( ob, "%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 6: - sprintf(ob, "%c=%c", reg_pair[rp][1], reg_pair[rp][0]); - break; + case 6: + sprintf( ob, "%c=%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 7: - sprintf(ob, "%c%cEX", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 7: + sprintf( ob, "%c%cEX", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(fs, ob); + /* Decode field selector */ + DisFIELD_SEL( fs, ob ); - return pc; + return pc; } - /* ..., Register Operation with Field Selector, opcode Bfo, length 3 FS = f & 0x7 @@ -639,8 +596,8 @@ static Address DisRegOp_A(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - f o OC RP + Opcode table + f o OC RP --- A=A-B a 0 0 0 B=B-C a 1 0 1 @@ -684,66 +641,61 @@ static Address DisRegOp_A(Address pc, char *ob) --- */ -static Address DisRegOp_B(Address pc, char *ob) +static Address DisRegOp_B( Address pc, char* ob ) { - Nibble f = GetNibble(pc++); - Nibble o = GetNibble(pc++); + Nibble f = GetNibble( pc++ ); + Nibble o = GetNibble( pc++ ); - int fs = GetFS(f); - int oc = GetOC_2(f, o); - int rp = GetRP(o); + int fs = GetFS( f ); + int oc = GetOC_2( f, o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "%c=%c+1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%c=%c+1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][0], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 4: - sprintf(ob, "%cSL", reg_pair[rp][0]); - break; + case 4: + sprintf( ob, "%cSL", reg_pair[ rp ][ 0 ] ); + break; - case 5: - sprintf(ob, "%cSR", reg_pair[rp][0]); - break; + case 5: + sprintf( ob, "%cSR", reg_pair[ rp ][ 0 ] ); + break; - case 6: - sprintf(ob, "%c=-%c", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 6: + sprintf( ob, "%c=-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 7: - sprintf(ob, "%c=-%c-1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 7: + sprintf( ob, "%c=-%c-1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(fs, ob); + /* Decode field selector */ + DisFIELD_SEL( fs, ob ); - return pc; + return pc; } - /* ..., Register Operation on A Fields, opcode Co, length 2 FS = implicit, always A @@ -762,8 +714,8 @@ static Address DisRegOp_B(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - o OC RP + Opcode table + o OC RP --- A=A+B 0 0 0 B=B+C 1 0 1 @@ -786,48 +738,43 @@ static Address DisRegOp_B(Address pc, char *ob) D=D-1 F 3 3 --- */ -static Address DisRegOp_C(Address pc, char *ob) +static Address DisRegOp_C( Address pc, char* ob ) { - Nibble o = GetNibble(pc++); + Nibble o = GetNibble( pc++ ); - int oc = GetOC_1(o); - int rp = GetRP(o); + int oc = GetOC_1( o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=%c+%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c=%c-1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=%c-1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - return pc; + return pc; } - /* ..., Register Operation on A Fields, opcode Do, length 2 FS = implicit, always A @@ -846,8 +793,8 @@ static Address DisRegOp_C(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - o OC RP + Opcode table + o OC RP --- A=0 0 0 0 B=0 1 0 1 @@ -870,45 +817,43 @@ static Address DisRegOp_C(Address pc, char *ob) CDEX F 3 3 */ -static Address DisRegOp_D(Address pc, char *ob) +static Address DisRegOp_D( Address pc, char* ob ) { - Nibble o = GetNibble(pc++); + Nibble o = GetNibble( pc++ ); - int oc = GetOC_1(o); - int rp = GetRP(o); + int oc = GetOC_1( o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=0", reg_pair[rp][0]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=0", reg_pair[ rp ][ 0 ] ); + break; - case 1: - sprintf(ob, "%c=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 1: + sprintf( ob, "%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 2: - sprintf(ob, "%c=%c", reg_pair[rp][1], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c%cEX", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 3: + sprintf( ob, "%c%cEX", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - return pc; + return pc; } - /* ..., Register Operation on A Fields, opcode Eo, length 2 FS = implicit, always A @@ -927,8 +872,8 @@ static Address DisRegOp_D(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - o OC RP + Opcode table + o OC RP --- A=A-B 0 0 0 B=B-C 1 0 1 @@ -952,48 +897,43 @@ static Address DisRegOp_D(Address pc, char *ob) --- */ -static Address DisRegOp_E(Address pc, char *ob) +static Address DisRegOp_E( Address pc, char* ob ) { - Nibble o = GetNibble(pc++); + Nibble o = GetNibble( pc++ ); - int oc = GetOC_1(o); - int rp = GetRP(o); + int oc = GetOC_1( o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "%c=%c+1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%c=%c+1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c=%c-%c", - reg_pair[rp][0], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - return pc; + return pc; } - /* ..., Register Operation on A Fields, opcode Fo, length 2 FS = implicit, always A @@ -1012,8 +952,8 @@ static Address DisRegOp_E(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - o OC RP + Opcode table + o OC RP --- ASL 0 0 0 BSL 1 0 1 @@ -1037,45 +977,43 @@ static Address DisRegOp_E(Address pc, char *ob) --- */ -static Address DisRegOp_F(Address pc, char *ob) +static Address DisRegOp_F( Address pc, char* ob ) { - Nibble o = GetNibble(pc++); + Nibble o = GetNibble( pc++ ); - int oc = GetOC_1(o); - int rp = GetRP(o); + int oc = GetOC_1( o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%cSL", reg_pair[rp][0]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%cSL", reg_pair[ rp ][ 0 ] ); + break; - case 1: - sprintf(ob, "%cSR", reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%cSR", reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=-%c", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "%c=-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "%c=-%c-1", reg_pair[rp][0], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=-%c-1", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - return pc; + return pc; } - /* .&., .!., AND/OR Operations, opcode 0Efo, length 4 FS = f @@ -1105,8 +1043,8 @@ static Address DisRegOp_F(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - f o OC RP + Opcode table + f o OC RP --- A=A&B a 0 0 0 B=B&C a 1 0 1 @@ -1130,110 +1068,102 @@ static Address DisRegOp_F(Address pc, char *ob) --- */ -static Address DisAND_OR(Address pc, char *ob) +static Address DisAND_OR( Address pc, char* ob ) { - Nibble f = GetNibble(pc++); - Nibble o = GetNibble(pc++); + Nibble f = GetNibble( pc++ ); + Nibble o = GetNibble( pc++ ); - int oc = GetOC_1(o); - int rp = GetRP(o); + int oc = GetOC_1( o ); + int rp = GetRP( o ); - /* Decode operation code */ - switch(oc) - { - case 0: - sprintf(ob, "%c=%c&%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode operation code */ + switch ( oc ) { + case 0: + sprintf( ob, "%c=%c&%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "%c=%c&%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 1: + sprintf( ob, "%c=%c&%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - case 2: - sprintf(ob, "%c=%c!%c", - reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]); - break; + case 2: + sprintf( ob, "%c=%c!%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 3: - sprintf(ob, "%c=%c!%c", - reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "%c=%c!%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(f, ob); + /* Decode field selector */ + DisFIELD_SEL( f, ob ); - return pc; + return pc; } - /* Instruction Group_0 Prefix 0E introduces AND/OR opcodes */ -static Address DisGroup_0(Address pc, char *ob) +static Address DisGroup_0( Address pc, char* ob ) { - Nibble n = GetNibble(pc++); + Nibble n = GetNibble( pc++ ); - switch(n) - { - case 0: - /* RTNSXM */ - case 1: - /* RTN */ - case 2: - /* RTNSC */ - case 3: - /* RTNCC */ - case 4: - /* SETHEX */ - case 5: - /* SETDEC */ - case 6: - /* RSTK=C */ - case 7: - /* C=RSTK */ - case 8: - /* CLRST */ - case 9: - /* C=ST */ - case 0xA: - /* ST=C */ - case 0xB: - /* CSTEX */ - case 0xC: - /* P=P+1 */ - case 0xD: - /* P=P-1 */ - case 0xF: - /* RTI */ - strcpy(ob, group_0_opc[(int)n]); - break; + switch ( n ) { + case 0: + /* RTNSXM */ + case 1: + /* RTN */ + case 2: + /* RTNSC */ + case 3: + /* RTNCC */ + case 4: + /* SETHEX */ + case 5: + /* SETDEC */ + case 6: + /* RSTK=C */ + case 7: + /* C=RSTK */ + case 8: + /* CLRST */ + case 9: + /* C=ST */ + case 0xA: + /* ST=C */ + case 0xB: + /* CSTEX */ + case 0xC: + /* P=P+1 */ + case 0xD: + /* P=P-1 */ + case 0xF: + /* RTI */ + strcpy( ob, group_0_opc[ ( int )n ] ); + break; - case 0xE: - /* AND_OR */ - pc = DisAND_OR(pc, ob); - break; + case 0xE: + /* AND_OR */ + pc = DisAND_OR( pc, ob ); + break; - default: - /* Unknown opcode */ - strcpy(ob, "?"); + default: + /* Unknown opcode */ + strcpy( ob, "?" ); - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } - return pc; + return pc; } - /* Instruction Group_1 Opcode table for: @@ -1243,7 +1173,7 @@ static Address DisGroup_0(Address pc, char *ob) RN = r & 0x7 AC = r & 0x8 - Opcode RN AC + Opcode RN AC --- R0=A 100 0 0 R1=A 101 1 0 @@ -1283,7 +1213,7 @@ static Address DisGroup_0(Address pc, char *ob) Opcode table for: 13r - Opcode + Opcode --- D0=A 130 D1=A 131 @@ -1305,7 +1235,7 @@ static Address DisGroup_0(Address pc, char *ob) Opcode table for: 14r - Opcode + Opcode --- DAT0=A A 140 DAT1=A A 141 @@ -1331,7 +1261,7 @@ static Address DisGroup_0(Address pc, char *ob) OC = o & 0x7 IS = o & 0x8 - o f OC IS + o f OC IS --- DAT0=A fs 0 a 0 0 DAT1=A fs 1 a 1 0 @@ -1349,7 +1279,7 @@ static Address DisGroup_0(Address pc, char *ob) DAT1=C d D d-1 5 8 C=DAT0 d E d-1 6 8 C=DAT1 d F d-1 7 8 - + Opcode table for: 16m, D0=D0+m+1 @@ -1364,337 +1294,332 @@ static Address DisGroup_0(Address pc, char *ob) 1Dnn D1=(2) nn 1Ennnn D1=(4) nnnn 1Fnnnnn D1=(5) nnnnn - + */ -static Address DisGroup_1(Address pc, char *ob) +static Address DisGroup_1( Address pc, char* ob ) { - Nibble n = GetNibble(pc++); - Nibble f; - int rn, ac; - int oc, is; + Nibble n = GetNibble( pc++ ); + Nibble f; + int rn, ac; + int oc, is; - switch(n) - { - case 0: - /* Rn=A/C */ - n = GetNibble(pc++); - rn = GetRn(n); - ac = GetAC(n); + switch ( n ) { + case 0: + /* Rn=A/C */ + n = GetNibble( pc++ ); + rn = GetRn( n ); + ac = GetAC( n ); - sprintf(ob, "%s=%s", rn_name[rn], (ac ? "C" : "A")); - break; + sprintf( ob, "%s=%s", rn_name[ rn ], ( ac ? "C" : "A" ) ); + break; - case 1: - /* A/C=Rn */ - n = GetNibble(pc++); - rn = GetRn(n); - ac = GetAC(n); + case 1: + /* A/C=Rn */ + n = GetNibble( pc++ ); + rn = GetRn( n ); + ac = GetAC( n ); - sprintf(ob, "%s=%s", (ac ? "C" : "A"), rn_name[rn]); - break; + sprintf( ob, "%s=%s", ( ac ? "C" : "A" ), rn_name[ rn ] ); + break; - case 2: - /* ARnEX, CRnEX */ - n = GetNibble(pc++); - rn = GetRn(n); - ac = GetAC(n); + case 2: + /* ARnEX, CRnEX */ + n = GetNibble( pc++ ); + rn = GetRn( n ); + ac = GetAC( n ); - sprintf(ob, "%s%sEX", (ac ? "C" : "A"), rn_name[rn]); - break; + sprintf( ob, "%s%sEX", ( ac ? "C" : "A" ), rn_name[ rn ] ); + break; - case 3: - /* Copy/Exchange A/C and D0/D1 */ - n = GetNibble(pc++); - strcpy(ob, group_13_opc[(int)n]); - break; + case 3: + /* Copy/Exchange A/C and D0/D1 */ + n = GetNibble( pc++ ); + strcpy( ob, group_13_opc[ ( int )n ] ); + break; - case 4: - /* Load/Store A/C to @D0/@D1, Field selector A or B */ - n = GetNibble(pc++); - strcpy(ob, group_14_opc[(int)n]); - break; + case 4: + /* Load/Store A/C to @D0/@D1, Field selector A or B */ + n = GetNibble( pc++ ); + strcpy( ob, group_14_opc[ ( int )n ] ); + break; - case 5: - /* Load/Store A/C to @D0/@D1, Other Field Selectors */ - n = GetNibble(pc++); - f = GetNibble(pc++); - oc = GetOC_3b(n); - is = GetImmFS(n); + case 5: + /* Load/Store A/C to @D0/@D1, Other Field Selectors */ + n = GetNibble( pc++ ); + f = GetNibble( pc++ ); + oc = GetOC_3b( n ); + is = GetImmFS( n ); - /* Decode operation code */ - strcpy(ob, group_15_opc[oc]); + /* Decode operation code */ + strcpy( ob, group_15_opc[ oc ] ); - if(is) - /* Immediate field selector */ - DisIMM_FIELD_SEL(f, ob); + if ( is ) + /* Immediate field selector */ + DisIMM_FIELD_SEL( f, ob ); - else - /* Regular field selector */ - DisFIELD_SEL(f, ob); + else + /* Regular field selector */ + DisFIELD_SEL( f, ob ); - break; + break; - case 6: - /* D0=D0+n+1 */ - n = GetNibble(pc++); - sprintf(ob, "D0=D0+%d", n+1); - break; + case 6: + /* D0=D0+n+1 */ + n = GetNibble( pc++ ); + sprintf( ob, "D0=D0+%d", n + 1 ); + break; - case 7: - /* D1=D1+n+1 */ - n = GetNibble(pc++); - sprintf(ob, "D1=D1+%d", n+1); - break; + case 7: + /* D1=D1+n+1 */ + n = GetNibble( pc++ ); + sprintf( ob, "D1=D1+%d", n + 1 ); + break; - case 8: - /* D0=D0-(n+1) */ - n = GetNibble(pc++); - sprintf(ob, "D0=D0-%d", n+1); - break; + case 8: + /* D0=D0-(n+1) */ + n = GetNibble( pc++ ); + sprintf( ob, "D0=D0-%d", n + 1 ); + break; - case 9: - /* D0=(2) nn */ - strcpy(ob, "D0=(2)\t"); - pc = DisHexConstant(pc, ob, 2); - break; + case 9: + /* D0=(2) nn */ + strcpy( ob, "D0=(2)\t" ); + pc = DisHexConstant( pc, ob, 2 ); + break; - case 0xA: - /* D0=(4) nn */ - strcpy(ob, "D0=(4)\t"); - pc = DisHexConstant(pc, ob, 4); - break; + case 0xA: + /* D0=(4) nn */ + strcpy( ob, "D0=(4)\t" ); + pc = DisHexConstant( pc, ob, 4 ); + break; - case 0xB: - /* D0=(5) nn */ - strcpy(ob, "D0=(5)\t"); - pc = DisHexConstant(pc, ob, 5); - break; + case 0xB: + /* D0=(5) nn */ + strcpy( ob, "D0=(5)\t" ); + pc = DisHexConstant( pc, ob, 5 ); + break; - case 0xC: - /* D1=D1-(n+1) */ - n = GetNibble(pc++); - sprintf(ob, "D1=D1-%d", n+1); - break; + case 0xC: + /* D1=D1-(n+1) */ + n = GetNibble( pc++ ); + sprintf( ob, "D1=D1-%d", n + 1 ); + break; - case 0xD: - /* D1=(2) nn */ - strcpy(ob, "D1=(2)\t"); - pc = DisHexConstant(pc, ob, 2); - break; + case 0xD: + /* D1=(2) nn */ + strcpy( ob, "D1=(2)\t" ); + pc = DisHexConstant( pc, ob, 2 ); + break; - case 0xE: - /* D1=(4) nn */ - strcpy(ob, "D1=(4)\t"); - pc = DisHexConstant(pc, ob, 4); - break; + case 0xE: + /* D1=(4) nn */ + strcpy( ob, "D1=(4)\t" ); + pc = DisHexConstant( pc, ob, 4 ); + break; - case 0xF: - /* D1=(5) nn */ - strcpy(ob, "D1=(5)\t"); - pc = DisHexConstant(pc, ob, 5); - break; + case 0xF: + /* D1=(5) nn */ + strcpy( ob, "D1=(5)\t" ); + pc = DisHexConstant( pc, ob, 5 ); + break; - default: - /* Unknown opcode */ - strcpy(ob, "?"); + default: + /* Unknown opcode */ + strcpy( ob, "?" ); - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } - return pc; + return pc; } - /* Instruction Group_808 -*/ -static Address DisGroup_808(Address pc, char *ob) + */ +static Address DisGroup_808( Address pc, char* ob ) { - Nibble n = GetNibble(pc++); - Nibble m; + Nibble n = GetNibble( pc++ ); + Nibble m; - switch(n) - { - case 0: - /* INTON */ - strcpy(ob, "INTON"); - break; + switch ( n ) { + case 0: + /* INTON */ + strcpy( ob, "INTON" ); + break; - case 1: - /* RSI */ - strcpy(ob, "RSI"); - pc++; - break; + case 1: + /* RSI */ + strcpy( ob, "RSI" ); + pc++; + break; - case 2: - /* LA(m) n..n */ - m = GetNibble(pc++)+1; - sprintf(ob, "LA(%d)\t", m); - pc = DisHexConstant(pc, ob, m); - break; + case 2: + /* LA(m) n..n */ + m = GetNibble( pc++ ) + 1; + sprintf( ob, "LA(%d)\t", m ); + pc = DisHexConstant( pc, ob, m ); + break; - case 3: - /* BUSCB */ - strcpy(ob, "BUSCB"); - break; + case 3: + /* BUSCB */ + strcpy( ob, "BUSCB" ); + break; - case 4: - /* ABIT=0 d */ - m = GetNibble(pc++); - sprintf(ob, "ABIT=0 %d", m); - break; + case 4: + /* ABIT=0 d */ + m = GetNibble( pc++ ); + sprintf( ob, "ABIT=0 %d", m ); + break; - case 5: - /* ABIT=1 d */ - m = GetNibble(pc++); - sprintf(ob, "ABIT=1 %d", m); - break; - - case 6: - /* ?ABIT=0 d */ - m = GetNibble(pc++); - sprintf(ob, "?ABIT=0 %d", m); - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 7: - /* ?ABIT=1 d */ - m = GetNibble(pc++); - sprintf(ob, "?ABIT=1 %d", m); - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 8: - /* CBIT=0 d */ - m = GetNibble(pc++); - sprintf(ob, "CBIT=0 %d", m); - break; + case 5: + /* ABIT=1 d */ + m = GetNibble( pc++ ); + sprintf( ob, "ABIT=1 %d", m ); + break; - case 9: - /* CBIT=1 d */ - m = GetNibble(pc++); - sprintf(ob, "CBIT=1 %d", m); - break; - - case 0xA: - /* ?CBIT=0 d */ - m = GetNibble(pc++); - sprintf(ob, "?CBIT=0 %d", m); - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 0xB: - /* ?CBIT=1 d */ - m = GetNibble(pc++); - sprintf(ob, "?CBIT=1 %d", m); - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 0xC: - /* PC=(A) */ - strcpy(ob, "PC=(A)"); - break; + case 6: + /* ?ABIT=0 d */ + m = GetNibble( pc++ ); + sprintf( ob, "?ABIT=0 %d", m ); + pc = DisGOYES_RTNYES( pc, ob ); + break; - case 0xD: - /* BUSCD */ - strcpy(ob, "BUSCD"); - break; + case 7: + /* ?ABIT=1 d */ + m = GetNibble( pc++ ); + sprintf( ob, "?ABIT=1 %d", m ); + pc = DisGOYES_RTNYES( pc, ob ); + break; - case 0xE: - /* PC=(C) */ - strcpy(ob, "PC=(C)"); - break; + case 8: + /* CBIT=0 d */ + m = GetNibble( pc++ ); + sprintf( ob, "CBIT=0 %d", m ); + break; - case 0xF: - /* INTOFF */ - strcpy(ob, "INTOFF"); - break; + case 9: + /* CBIT=1 d */ + m = GetNibble( pc++ ); + sprintf( ob, "CBIT=1 %d", m ); + break; - default: - /* Unknown opcode */ - strcpy(ob, "?"); + case 0xA: + /* ?CBIT=0 d */ + m = GetNibble( pc++ ); + sprintf( ob, "?CBIT=0 %d", m ); + pc = DisGOYES_RTNYES( pc, ob ); + break; - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + case 0xB: + /* ?CBIT=1 d */ + m = GetNibble( pc++ ); + sprintf( ob, "?CBIT=1 %d", m ); + pc = DisGOYES_RTNYES( pc, ob ); + break; - return pc; + case 0xC: + /* PC=(A) */ + strcpy( ob, "PC=(A)" ); + break; + + case 0xD: + /* BUSCD */ + strcpy( ob, "BUSCD" ); + break; + + case 0xE: + /* PC=(C) */ + strcpy( ob, "PC=(C)" ); + break; + + case 0xF: + /* INTOFF */ + strcpy( ob, "INTOFF" ); + break; + + default: + /* Unknown opcode */ + strcpy( ob, "?" ); + + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } + + return pc; } /* Instruction Group_80 -*/ -static Address DisGroup_80(Address pc, char *ob) + */ +static Address DisGroup_80( Address pc, char* ob ) { - Nibble n = GetNibble(pc++); + Nibble n = GetNibble( pc++ ); - switch(n) - { - case 0: - /* OUT=CS */ - case 1: - /* OUT=C */ - case 2: - /* A=IN */ - case 3: - /* C=IN */ - case 4: - /* UNCNFG */ - case 5: - /* CONFIG */ - case 6: - /* C=ID */ - case 7: - /* SHUTDN */ - case 9: - /* C+P+1 */ - case 0xA: - /* RESET */ - case 0xB: - /* BUSCC */ - case 0xE: - /* SREQ? */ - strcpy(ob, group_80_opc[(int)n]); - break; + switch ( n ) { + case 0: + /* OUT=CS */ + case 1: + /* OUT=C */ + case 2: + /* A=IN */ + case 3: + /* C=IN */ + case 4: + /* UNCNFG */ + case 5: + /* CONFIG */ + case 6: + /* C=ID */ + case 7: + /* SHUTDN */ + case 9: + /* C+P+1 */ + case 0xA: + /* RESET */ + case 0xB: + /* BUSCC */ + case 0xE: + /* SREQ? */ + strcpy( ob, group_80_opc[ ( int )n ] ); + break; - case 8: - /* Group 808 */ - pc = DisGroup_808(pc, ob); - break; + case 8: + /* Group 808 */ + pc = DisGroup_808( pc, ob ); + break; - case 0xC: - /* C=P n */ - n = GetNibble(pc++); - sprintf(ob, "C=P\t%d", n); - break; + case 0xC: + /* C=P n */ + n = GetNibble( pc++ ); + sprintf( ob, "C=P\t%d", n ); + break; - case 0xD: - /* P=C n */ - n = GetNibble(pc++); - sprintf(ob, "P=C\t%d", n); - break; + case 0xD: + /* P=C n */ + n = GetNibble( pc++ ); + sprintf( ob, "P=C\t%d", n ); + break; - case 0xF: - /* CPEX */ - n = GetNibble(pc++); - sprintf(ob, "CPEX\t%d", n); - break; + case 0xF: + /* CPEX */ + n = GetNibble( pc++ ); + sprintf( ob, "CPEX\t%d", n ); + break; - default: - /* Unknown opcode */ - strcpy(ob, "?"); + default: + /* Unknown opcode */ + strcpy( ob, "?" ); - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } - return pc; + return pc; } - /* Special functions Group_81 Opcode Table for: @@ -1702,7 +1627,7 @@ static Address DisGroup_80(Address pc, char *ob) f= field selector m= d-1 - Opcode + Opcode --- A=A+CON rfs,d 818f0m A=A-CON rfs,d 818f8m @@ -1764,98 +1689,94 @@ static Address DisGroup_80(Address pc, char *ob) Opcode Table for: rp=3, opcode 81Bn - Direct execution + Direct execution */ -static Address DisSpecialGroup_81(Address pc, char *ob, int rp) +static Address DisSpecialGroup_81( Address pc, char* ob, int rp ) { - Nibble n, f, m; - int rn, ac; + Nibble n, f, m; + int rn, ac; - switch(rp) - { - case 0: - /* r=r+-CON fs, d */ - f = GetNibble(pc++); - n = GetNibble(pc++); - m = GetNibble(pc++); - rp = GetRP(n); + switch ( rp ) { + case 0: + /* r=r+-CON fs, d */ + f = GetNibble( pc++ ); + n = GetNibble( pc++ ); + m = GetNibble( pc++ ); + rp = GetRP( n ); - sprintf(ob, "%c=%c%cCON", - reg_pair[rp][0], reg_pair[rp][0], (GetAS(n) ? '-' : '+' )); + sprintf( ob, "%c=%c%cCON", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], ( GetAS( n ) ? '-' : '+' ) ); - /* Decode field selector */ - DisFIELD_SEL(f, ob); + /* Decode field selector */ + DisFIELD_SEL( f, ob ); - /* Decode constant */ - ob += strlen(ob); - sprintf(ob, ", %d", m+1); - break; - - case 1: - /* rSRB.f fs */ - f = GetNibble(pc++); - n = GetNibble(pc++); - rp = GetRP(n); + /* Decode constant */ + ob += strlen( ob ); + sprintf( ob, ", %d", m + 1 ); + break; - sprintf(ob, "%cSRB.F", reg_pair[rp][0]); - - /* Decode field selector */ - DisFIELD_SEL(f, ob); - break; + case 1: + /* rSRB.f fs */ + f = GetNibble( pc++ ); + n = GetNibble( pc++ ); + rp = GetRP( n ); - case 2: - /* Rn=r.F fs, r=R0.F fs, rRnEX.F fs */ - f = GetNibble(pc++); - n = GetNibble(pc++); - m = GetNibble(pc++); - rn = GetRn(m); - ac = GetAC(m); + sprintf( ob, "%cSRB.F", reg_pair[ rp ][ 0 ] ); - switch(n) - { - case 0: - /* Rn=r.F fs */ - sprintf(ob, "%s=%s.F", rn_name[rn], (ac ? "C" : "A")); - DisFIELD_SEL(f, ob); - break; + /* Decode field selector */ + DisFIELD_SEL( f, ob ); + break; - case 1: - /* r=R0.F fs */ - sprintf(ob, "%s=%s.F", (ac ? "C" : "A"), rn_name[rn]); - DisFIELD_SEL(f, ob); - break; + case 2: + /* Rn=r.F fs, r=R0.F fs, rRnEX.F fs */ + f = GetNibble( pc++ ); + n = GetNibble( pc++ ); + m = GetNibble( pc++ ); + rn = GetRn( m ); + ac = GetAC( m ); - case 2: - /* rRnEX.F fs */ - sprintf(ob, "%s%sEX.F", (ac ? "C" : "A"), rn_name[rn]); - DisFIELD_SEL(f, ob); - break; + switch ( n ) { + case 0: + /* Rn=r.F fs */ + sprintf( ob, "%s=%s.F", rn_name[ rn ], ( ac ? "C" : "A" ) ); + DisFIELD_SEL( f, ob ); + break; + + case 1: + /* r=R0.F fs */ + sprintf( ob, "%s=%s.F", ( ac ? "C" : "A" ), rn_name[ rn ] ); + DisFIELD_SEL( f, ob ); + break; + + case 2: + /* rRnEX.F fs */ + sprintf( ob, "%s%sEX.F", ( ac ? "C" : "A" ), rn_name[ rn ] ); + DisFIELD_SEL( f, ob ); + break; + + default: + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } + + break; + + case 3: + /* Group 81B */ + n = GetNibble( pc++ ); + strcpy( ob, group_81B_opc[ ( int )n ] ); + break; default: - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Register_Pair" ChfEnd; + ChfSignal(); + break; + } - break; - - case 3: - /* Group 81B */ - n = GetNibble(pc++); - strcpy(ob, group_81B_opc[(int)n]); - break; - - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Register_Pair" ChfEnd; - ChfSignal(); - break; - } - - return pc; + return pc; } - /* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Atyy, length 5 FS = implicit, always A @@ -1874,8 +1795,8 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp) 2 C,A 3 D,C - Opcode table - t OC RP + Opcode table + t OC RP --- A=B, B=A 0 0 0 B=C, C=B 1 0 1 @@ -1899,46 +1820,44 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp) --- */ -static Address DisTest_8A(Address pc, char *ob) +static Address DisTest_8A( Address pc, char* ob ) { - Nibble t = GetNibble(pc++); + Nibble t = GetNibble( pc++ ); - int tc = GetOC_1(t); - int rp = GetRP(t); + int tc = GetOC_1( t ); + int rp = GetRP( t ); - /* Decode test code */ - switch(tc) - { - case 0: - sprintf(ob, "?%c=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode test code */ + switch ( tc ) { + case 0: + sprintf( ob, "?%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "?%c#%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 1: + sprintf( ob, "?%c#%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 2: - sprintf(ob, "?%c=0", reg_pair[rp][0]); - break; + case 2: + sprintf( ob, "?%c=0", reg_pair[ rp ][ 0 ] ); + break; - case 3: - sprintf(ob, "?%c#0", reg_pair[rp][0]); - break; + case 3: + sprintf( ob, "?%c#0", reg_pair[ rp ][ 0 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - /* Decode RTNYES/GOYES */ - return DisGOYES_RTNYES(pc, ob); + /* Decode RTNYES/GOYES */ + return DisGOYES_RTNYES( pc, ob ); } - /* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Btyy, length 5 FS = implicit, always A @@ -1957,8 +1876,8 @@ static Address DisTest_8A(Address pc, char *ob) 2 C,A 3 D,C - Opcode table - t OC RP + Opcode table + t OC RP --- A>B 0 0 0 B>C 1 0 1 @@ -1982,46 +1901,44 @@ static Address DisTest_8A(Address pc, char *ob) --- */ -static Address DisTest_8B(Address pc, char *ob) +static Address DisTest_8B( Address pc, char* ob ) { - Nibble t = GetNibble(pc++); + Nibble t = GetNibble( pc++ ); - int tc = GetOC_1(t); - int rp = GetRP(t); + int tc = GetOC_1( t ); + int rp = GetRP( t ); - /* Decode test code */ - switch(tc) - { - case 0: - sprintf(ob, "?%c>%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + /* Decode test code */ + switch ( tc ) { + case 0: + sprintf( ob, "?%c>%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 1: - sprintf(ob, "?%c<%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 1: + sprintf( ob, "?%c<%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 2: - sprintf(ob, "?%c>=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 2: + sprintf( ob, "?%c>=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - case 3: - sprintf(ob, "?%c<=%c", reg_pair[rp][0], reg_pair[rp][1]); - break; + case 3: + sprintf( ob, "?%c<=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] ); + break; - default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; - ChfSignal(); - break; - } + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Test_Code" ChfEnd; + ChfSignal(); + break; + } - /* Decode field selector */ - DisFIELD_SEL(FS_A, ob); + /* Decode field selector */ + DisFIELD_SEL( FS_A, ob ); - /* Decode RTNYES/GOYES */ - return DisGOYES_RTNYES(pc, ob); + /* Decode RTNYES/GOYES */ + return DisGOYES_RTNYES( pc, ob ); } - /* Instruction Group_8 Opcode table for: @@ -2030,7 +1947,7 @@ static Address DisTest_8B(Address pc, char *ob) OC = (s & 0xC) >> 2 RP = (s & 0x3) - Opcode OC RP + Opcode OC RP --- ASLC 810 0 0 BSLC 811 0 1 @@ -2042,10 +1959,10 @@ static Address DisTest_8B(Address pc, char *ob) CSRC 816 1 2 DSRC 817 1 3 --- - 818 2 0, Special - 819 2 1, Special - 81A 2 2, Special - 81B 2 3, Special + 818 2 0, Special + 819 2 1, Special + 81A 2 2, Special + 81B 2 3, Special --- ASRB 81C 3 0 BSRB 81D 3 1 @@ -2069,229 +1986,224 @@ static Address DisTest_8B(Address pc, char *ob) 8Ennnn, GOSUBL 8Fnnnnn, GOSBVL */ -static Address DisGroup_8(Address pc, char *ob) +static Address DisGroup_8( Address pc, char* ob ) { - Nibble n = GetNibble(pc++); - Address addr; - int oc, rp; + Nibble n = GetNibble( pc++ ); + Address addr; + int oc, rp; - switch(n) - { - case 0: - pc = DisGroup_80(pc, ob); - break; + switch ( n ) { + case 0: + pc = DisGroup_80( pc, ob ); + break; - case 1: - /* rSLC, rSRC, rSRB, Special Group_81 */ - n = GetNibble(pc++); - oc = GetOC_1(n); - rp = GetRP(n); + case 1: + /* rSLC, rSRC, rSRB, Special Group_81 */ + n = GetNibble( pc++ ); + oc = GetOC_1( n ); + rp = GetRP( n ); - switch(oc) - { - case 0: - /* rSLC */ - sprintf(ob, "%cSLC", reg_pair[rp][0]); - break; + switch ( oc ) { + case 0: + /* rSLC */ + sprintf( ob, "%cSLC", reg_pair[ rp ][ 0 ] ); + break; - case 1: - /* rSRC */ - sprintf(ob, "%cSRC", reg_pair[rp][0]); - break; + case 1: + /* rSRC */ + sprintf( ob, "%cSRC", reg_pair[ rp ][ 0 ] ); + break; - case 2: - /* Special Group_81 */ - pc = DisSpecialGroup_81(pc, ob, rp); - break; + case 2: + /* Special Group_81 */ + pc = DisSpecialGroup_81( pc, ob, rp ); + break; - case 3: - /* rSRB */ - sprintf(ob, "%cSRB", reg_pair[rp][0]); - break; + case 3: + /* rSRB */ + sprintf( ob, "%cSRB", reg_pair[ rp ][ 0 ] ); + break; + + default: + ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; + ChfSignal(); + break; + } + break; + + case 2: + /* CLRHSn */ + n = GetNibble( pc++ ); + + switch ( n ) { + case 1: + strcpy( ob, "XM=0" ); + break; + + case 2: + strcpy( ob, "SB=0" ); + break; + + case 4: + strcpy( ob, "SR=0" ); + break; + + case 8: + strcpy( ob, "MP=0" ); + break; + + case 0xF: + strcpy( ob, "CLRHST" ); + break; + + default: + sprintf( ob, "CLRHSN\t%X", n ); + break; + } + break; + + case 3: + /* ?HS=0 */ + n = GetNibble( pc++ ); + + switch ( n ) { + case 1: + strcpy( ob, "?XM=0" ); + break; + + case 2: + strcpy( ob, "?SB=0" ); + break; + + case 4: + strcpy( ob, "?SR=0" ); + break; + + case 8: + strcpy( ob, "?MP=0" ); + break; + + default: + sprintf( ob, "?HS=0\t%X", n ); + break; + } + + /* Decode RTNYES/GOYES */ + pc = DisGOYES_RTNYES( pc, ob ); + break; + + case 4: + /* ST=0 n */ + n = GetNibble( pc++ ); + + sprintf( ob, "ST=0\t%d", n ); + break; + + case 5: + /* ST=1 n */ + n = GetNibble( pc++ ); + + sprintf( ob, "ST=1\t%d", n ); + break; + + case 6: + /* ?ST=0 n */ + n = GetNibble( pc++ ); + + /* Decode bit number */ + sprintf( ob, "?ST=0\t%d", n ); + + /* Decode RTNYES/GOYES */ + pc = DisGOYES_RTNYES( pc, ob ); + break; + + case 7: + /* ?ST=1 n */ + n = GetNibble( pc++ ); + + /* Decode bit number */ + sprintf( ob, "?ST=1\t%d", n ); + + /* Decode RTNYES/GOYES */ + pc = DisGOYES_RTNYES( pc, ob ); + break; + + case 8: + /* ?P#n */ + n = GetNibble( pc++ ); + + /* Decode bit number */ + sprintf( ob, "?P#%d", n ); + + /* Decode RTNYES/GOYES */ + pc = DisGOYES_RTNYES( pc, ob ); + break; + + case 9: + /* ?P=n */ + n = GetNibble( pc++ ); + + /* Decode bit number */ + sprintf( ob, "?P=%d", n ); + + /* Decode RTNYES/GOYES */ + pc = DisGOYES_RTNYES( pc, ob ); + break; + + case 0xA: + /* Test */ + pc = DisTest_8A( pc, ob ); + break; + + case 0xB: + /* Test */ + pc = DisTest_8B( pc, ob ); + break; + + case 0xC: + /* GOLONG */ + addr = Get4Nibbles2C( pc ); + sprintf( ob, "GOLONG\tA_%05X\t* Offset [%d]d", pc + addr, addr ); + pc += 4; + break; + + case 0xD: + /* GOVLNG */ + addr = Get5NibblesAbs( pc ); + sprintf( ob, "GOVLNG\tA_%05X", addr ); + pc += 5; + break; + + case 0xE: + /* GOSUBL */ + addr = Get4Nibbles2C( pc ); + pc += 4; + + sprintf( ob, "GOSUBL\tA_%05X\t* Offset [%d]d", pc + addr, addr ); + break; + break; + + case 0xF: + /* GOSBVL */ + addr = Get5NibblesAbs( pc ); + sprintf( ob, "GOSBVL\tA_%05X", addr ); + pc += 5; + break; default: - ChfCondition CPU_F_INTERR, CHF_FATAL, "Bad_Operation_Code" ChfEnd; - ChfSignal(); - break; - } - break; + /* Unknown opcode */ + strcpy( ob, "?" ); - case 2: - /* CLRHSn */ - n = GetNibble(pc++); + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } - switch(n) - { - case 1: - strcpy(ob, "XM=0"); - break; - - case 2: - strcpy(ob, "SB=0"); - break; - - case 4: - strcpy(ob, "SR=0"); - break; - - case 8: - strcpy(ob, "MP=0"); - break; - - case 0xF: - strcpy(ob, "CLRHST"); - break; - - default: - sprintf(ob, "CLRHSN\t%X", n); - break; - } - break; - - case 3: - /* ?HS=0 */ - n = GetNibble(pc++); - - switch(n) - { - case 1: - strcpy(ob, "?XM=0"); - break; - - case 2: - strcpy(ob, "?SB=0"); - break; - - case 4: - strcpy(ob, "?SR=0"); - break; - - case 8: - strcpy(ob, "?MP=0"); - break; - - default: - sprintf(ob, "?HS=0\t%X", n); - break; - } - - /* Decode RTNYES/GOYES */ - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 4: - /* ST=0 n */ - n = GetNibble(pc++); - - sprintf(ob, "ST=0\t%d", n); - break; - - case 5: - /* ST=1 n */ - n = GetNibble(pc++); - - sprintf(ob, "ST=1\t%d", n); - break; - - case 6: - /* ?ST=0 n */ - n = GetNibble(pc++); - - /* Decode bit number */ - sprintf(ob, "?ST=0\t%d", n); - - /* Decode RTNYES/GOYES */ - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 7: - /* ?ST=1 n */ - n = GetNibble(pc++); - - /* Decode bit number */ - sprintf(ob, "?ST=1\t%d", n); - - /* Decode RTNYES/GOYES */ - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 8: - /* ?P#n */ - n = GetNibble(pc++); - - /* Decode bit number */ - sprintf(ob, "?P#%d", n); - - /* Decode RTNYES/GOYES */ - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 9: - /* ?P=n */ - n = GetNibble(pc++); - - /* Decode bit number */ - sprintf(ob, "?P=%d", n); - - /* Decode RTNYES/GOYES */ - pc = DisGOYES_RTNYES(pc, ob); - break; - - case 0xA: - /* Test */ - pc = DisTest_8A(pc, ob); - break; - - case 0xB: - /* Test */ - pc = DisTest_8B(pc, ob); - break; - - case 0xC: - /* GOLONG */ - addr = Get4Nibbles2C(pc); - sprintf(ob, "GOLONG\tA_%05X\t* Offset [%d]d", pc+addr, addr); - pc += 4; - break; - - case 0xD: - /* GOVLNG */ - addr = Get5NibblesAbs(pc); - sprintf(ob, "GOVLNG\tA_%05X", addr); - pc += 5; - break; - - case 0xE: - /* GOSUBL */ - addr = Get4Nibbles2C(pc); - pc += 4; - - sprintf(ob, "GOSUBL\tA_%05X\t* Offset [%d]d", pc+addr, addr); - break; - break; - - case 0xF: - /* GOSBVL */ - addr = Get5NibblesAbs(pc); - sprintf(ob, "GOSBVL\tA_%05X", addr); - pc += 5; - break; - - default: - /* Unknown opcode */ - strcpy(ob, "?"); - - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } - - return pc; + return pc; } - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ /* .+ @@ -2304,104 +2216,119 @@ static Address DisGroup_8(Address pc, char *ob) puts the result into the output buffer 'ob'. .call : - new_pc = Disassemble(pc, ob) + new_pc = Disassemble(pc, ob) .input : - Address pc, address of the instruction to disassemble + Address pc, address of the instruction to disassemble .output : - char ob[DISASSEMBLE_OB_SIZE], text output buffer - Address new_pc, address of the next instruction + char ob[DISASSEMBLE_OB_SIZE], text output buffer + Address new_pc, address of the next instruction .status_codes : - CPU_E_BAD_OPCODE - CPU_F_INTERR + CPU_E_BAD_OPCODE + CPU_F_INTERR .notes : 1.1, 26-Jan-1998, creation .- */ -Address Disassemble(Address pc, char ob[DISASSEMBLE_OB_SIZE]) +Address Disassemble( Address pc, char ob[ DISASSEMBLE_OB_SIZE ] ) { - Nibble n; + Nibble n; - /* Disassemble current program counter */ - sprintf(ob,"A_%05X\t", pc); - ob += strlen(ob); + /* Disassemble current program counter */ + sprintf( ob, "A_%05X\t", pc ); + ob += strlen( ob ); - /* Get first instruction nibble */ - n = GetNibble(pc++); + /* Get first instruction nibble */ + n = GetNibble( pc++ ); - switch(n) - { - case 0: - /* Group_0 */ - pc = DisGroup_0(pc, ob); break; + switch ( n ) { + case 0: + /* Group_0 */ + pc = DisGroup_0( pc, ob ); + break; - case 1: - /* Group_1 */ - pc = DisGroup_1(pc, ob); break; + case 1: + /* Group_1 */ + pc = DisGroup_1( pc, ob ); + break; - case 2: - /* P=n */ - pc = DisPEqn(pc, ob); break; + case 2: + /* P=n */ + pc = DisPEqn( pc, ob ); + break; - case 3: - /* LC(m) n...n */ - pc = DisLC(pc, ob); break; + case 3: + /* LC(m) n...n */ + pc = DisLC( pc, ob ); + break; - case 4: - /* RTNC/GOC */ - pc = DisRTNC_GOC(pc, ob); break; + case 4: + /* RTNC/GOC */ + pc = DisRTNC_GOC( pc, ob ); + break; - case 5: - /* RTNNC/GONC */ - pc = DisRTNNC_GONC(pc, ob); break; + case 5: + /* RTNNC/GONC */ + pc = DisRTNNC_GONC( pc, ob ); + break; - case 6: - /* GOTO */ - pc = DisGOTO(pc, ob); break; + case 6: + /* GOTO */ + pc = DisGOTO( pc, ob ); + break; - case 7: - /* GOSUB */ - pc = DisGOSUB(pc, ob); break; + case 7: + /* GOSUB */ + pc = DisGOSUB( pc, ob ); + break; - case 8: - /* Group_8 */ - pc = DisGroup_8(pc, ob); break; + case 8: + /* Group_8 */ + pc = DisGroup_8( pc, ob ); + break; - case 9: - /* Test */ - pc = DisTest_9(pc, ob); break; + case 9: + /* Test */ + pc = DisTest_9( pc, ob ); + break; - case 0xA: - /* Register Operation, group A */ - pc = DisRegOp_A(pc, ob); break; + case 0xA: + /* Register Operation, group A */ + pc = DisRegOp_A( pc, ob ); + break; - case 0xB: - /* Register Operation, group B */ - pc = DisRegOp_B(pc, ob); break; + case 0xB: + /* Register Operation, group B */ + pc = DisRegOp_B( pc, ob ); + break; - case 0xC: - /* Register Operation, group C */ - pc = DisRegOp_C(pc, ob); break; + case 0xC: + /* Register Operation, group C */ + pc = DisRegOp_C( pc, ob ); + break; - case 0xD: - /* Register Operation, group D */ - pc = DisRegOp_D(pc, ob); break; + case 0xD: + /* Register Operation, group D */ + pc = DisRegOp_D( pc, ob ); + break; - case 0xE: - /* Register Operation, group E */ - pc = DisRegOp_E(pc, ob); break; + case 0xE: + /* Register Operation, group E */ + pc = DisRegOp_E( pc, ob ); + break; - case 0xF: - /* Register Operation, group F */ - pc = DisRegOp_F(pc, ob); break; + case 0xF: + /* Register Operation, group F */ + pc = DisRegOp_F( pc, ob ); + break; - default: - /* Unknown opcode */ - strcpy(ob, "?"); + default: + /* Unknown opcode */ + strcpy( ob, "?" ); - ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; - ChfSignal(); - break; - } + ChfCondition CPU_E_BAD_OPCODE, CHF_ERROR, pc, n ChfEnd; + ChfSignal(); + break; + } - return pc & ADDRESS_MASK; + return pc & ADDRESS_MASK; } diff --git a/src/disk_io.c b/src/disk_io.c index b071746..8c8355e 100644 --- a/src/disk_io.c +++ b/src/disk_io.c @@ -76,10 +76,9 @@ static char rcs_id[] = "$Id: disk_io.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" #include "disk_io.h" #include "debug.h" -#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID +#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID #include - /* .+ .title : ReadNibblesFromFile @@ -91,60 +90,55 @@ static char rcs_id[] = "$Id: disk_io.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" caller a status code. .call : - st = ReadNibbledFromFile(name, size, dest); + st = ReadNibbledFromFile(name, size, dest); .input : - const char *name, file name - int size, size of the file (nibbles, NOT bytes) + const char *name, file name + int size, size of the file (nibbles, NOT bytes) .output : - Nibble *dest, pointer to the destination memory area - int st, status code + Nibble *dest, pointer to the destination memory area + int st, status code .status_codes : - DISK_IO_I_CALLED (signalled) - DISK_IO_E_OPEN - DISK_IO_E_GETC + DISK_IO_I_CALLED (signalled) + DISK_IO_E_OPEN + DISK_IO_E_GETC .notes : 1.1, 11-Feb-1998, creation .- */ -int ReadNibblesFromFile(const char *name, int size, Nibble *dest) +int ReadNibblesFromFile( const char* name, int size, Nibble* dest ) { - FILE *f; - int i; - int by; - int st = DISK_IO_S_OK; + FILE* f; + int i; + int by; + int st = DISK_IO_S_OK; - debug1(DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadNibblesFromFile"); + debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadNibblesFromFile" ); - if((f = fopen(name, "rb")) == (FILE *)NULL) - { - ChfErrnoCondition; - ChfCondition st=DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd; - } - - else - { - for(i=0; i> 4); + ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd; } - (void)fclose(f); - } + else { + for ( i = 0; i < size; ) { + by = getc( f ); - return st; + if ( by == -1 ) { + ChfErrnoCondition; + ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd; + break; + } + + dest[ i++ ] = ( Nibble )( by & 0x0F ); + dest[ i++ ] = ( Nibble )( ( by & 0xF0 ) >> 4 ); + } + + ( void )fclose( f ); + } + + return st; } - /* .+ .title : WriteNibblesToFile @@ -155,63 +149,57 @@ int ReadNibblesFromFile(const char *name, int size, Nibble *dest) It returns to the caller a status code .call : - st = WriteNibblesToFile(src, size, name); + st = WriteNibblesToFile(src, size, name); .input : - const Nibble *src, pointer to data to be written - int size, # of nibble to write - const char *name, file name + const Nibble *src, pointer to data to be written + int size, # of nibble to write + const char *name, file name .output : - int st, status code + int st, status code .status_codes : - DISK_IO_I_CALLED (signalled) - DISK_IO_E_OPEN - DISK_IO_E_PUTC - DISK_IO_E_CLOSE + DISK_IO_I_CALLED (signalled) + DISK_IO_E_OPEN + DISK_IO_E_PUTC + DISK_IO_E_CLOSE .notes : 1.1, 11-Feb-1998, creation .- */ -int WriteNibblesToFile(const Nibble *src, int size, const char *name) +int WriteNibblesToFile( const Nibble* src, int size, const char* name ) { - FILE *f; - int i; - int by; - int st = DISK_IO_S_OK; + FILE* f; + int i; + int by; + int st = DISK_IO_S_OK; - debug1(DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteNibblesToFile"); + debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteNibblesToFile" ); - if((f = fopen(name, "wb")) == (FILE *)NULL) - { - ChfErrnoCondition; - ChfCondition st=DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd; - } - - else - { - for(i=0; i - /* .+ .title : ReadObjectFromFile @@ -104,111 +103,100 @@ static char rcs_id[] = "$Id: disk_io_obj.c,v 4.1 2000/12/11 09:54:19 cibrario Re This function returns to the caller a status code. .call : - st = ReadObjectFromFile(name, hdr, start, end); + st = ReadObjectFromFile(name, hdr, start, end); .input : - const char *name, input file name - const char *hdr, file header - Address start, start address (inclusive) - Address end, end address (exclusive) + const char *name, input file name + const char *hdr, file header + Address start, start address (inclusive) + Address end, end address (exclusive) .output : - int st, status code + int st, status code .status_codes : - DISK_IO_I_CALLED (signalled) - DISK_IO_E_OPEN - DISK_IO_E_GETC - DISK_IO_E_BAD_HDR - DISK_IO_E_SIZE + DISK_IO_I_CALLED (signalled) + DISK_IO_E_OPEN + DISK_IO_E_GETC + DISK_IO_E_BAD_HDR + DISK_IO_E_SIZE .notes : 3.14, 10-Nov-2000, creation .- */ -int ReadObjectFromFile( - const char *name, const char *hdr, Address start, Address end) +int ReadObjectFromFile( const char* name, const char* hdr, Address start, Address end ) { - size_t hdr_len = strlen(hdr); - FILE *f; + size_t hdr_len = strlen( hdr ); + FILE* f; int i; int by; Address cur; -#define N_SAVE_AREA 10 - Nibble save_area[N_SAVE_AREA]; +#define N_SAVE_AREA 10 + Nibble save_area[ N_SAVE_AREA ]; int st = DISK_IO_S_OK; - debug1(DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadObjectFromFile"); + debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadObjectFromFile" ); /* Save first nibbles of target space into save_area */ - for(cur=start, i=0; cur < end && i= end-1) - { - ChfCondition st=DISK_IO_E_SIZE, CHF_ERROR, name ChfEnd; - break; - } + /* Header check/skip OK; transfer */ + while ( ( by = getc( f ) ) != EOF ) { + /* Next byte available in by; check available space */ + if ( cur >= end - 1 ) { + ChfCondition st = DISK_IO_E_SIZE, CHF_ERROR, name ChfEnd; + break; + } - /* Store it */ - WriteNibble(cur++, (Nibble)(by & 0x0F)); - WriteNibble(cur++, (Nibble)((by & 0xF0) >> 4)); - } + /* Store it */ + WriteNibble( cur++, ( Nibble )( by & 0x0F ) ); + WriteNibble( cur++, ( Nibble )( ( by & 0xF0 ) >> 4 ) ); + } - /* Check why getc() failed */ - if(ferror(f) && !feof(f)) - { - ChfErrnoCondition; - ChfCondition st=DISK_IO_E_GETC, CHF_ERROR, name ChfEnd; - } + /* Check why getc() failed */ + if ( ferror( f ) && !feof( f ) ) { + ChfErrnoCondition; + ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd; + } - /* Recover from save_area if transfer failed */ - if(st) - for(cur=start, i=0; cur < end && i #ifndef LCD_MAG -# define LCD_MAG 2 /* 4.1.1.1: Compat. default */ +# define LCD_MAG 2 /* 4.1.1.1: Compat. default */ #endif -#define NIBBLES_PER_ROW 34 /* 136 pixel total */ -#define MAX_ROWS 64 /* 64 rows total */ -#define N_ANN 6 /* # of annunciators */ -#define LCD_X_ORIGIN 1+4*(LCD_MAG-1) /* x origin */ +#define NIBBLES_PER_ROW 34 /* 136 pixel total */ +#define MAX_ROWS 64 /* 64 rows total */ +#define N_ANN 6 /* # of annunciators */ +#define LCD_X_ORIGIN 1 + 4 * ( LCD_MAG - 1 ) /* x origin */ -#if LCD_MAG==1 -# define LCD_Y_ORIGIN 14 /* y origin */ +#if LCD_MAG == 1 +# define LCD_Y_ORIGIN 14 /* y origin */ #else -# define LCD_Y_ORIGIN 20 /* y origin */ +# define LCD_Y_ORIGIN 20 /* y origin */ #endif /* 3.8: Origin and size of clip rectangle */ -#define LCD_CLIP_X_ORIGIN LCD_X_ORIGIN -#define LCD_CLIP_Y_ORIGIN 0 /* Don't clip annunciators */ -#define LCD_CLIP_WIDTH 131*LCD_MAG -#define LCD_CLIP_HEIGHT LCD_Y_ORIGIN+64*LCD_MAG - -#define MASK_ANN_LEFT 0x81 /* Annunciator's bit masks */ -#define MASK_ANN_RIGHT 0x82 -#define MASK_ANN_ALPHA 0x84 -#define MASK_ANN_BATTERY 0x88 -#define MASK_ANN_BUSY 0x90 -#define MASK_ANN_IO 0xA0 +#define LCD_CLIP_X_ORIGIN LCD_X_ORIGIN +#define LCD_CLIP_Y_ORIGIN 0 /* Don't clip annunciators */ +#define LCD_CLIP_WIDTH 131 * LCD_MAG +#define LCD_CLIP_HEIGHT LCD_Y_ORIGIN + 64 * LCD_MAG +#define MASK_ANN_LEFT 0x81 /* Annunciator's bit masks */ +#define MASK_ANN_RIGHT 0x82 +#define MASK_ANN_ALPHA 0x84 +#define MASK_ANN_BATTERY 0x88 +#define MASK_ANN_BUSY 0x90 +#define MASK_ANN_IO 0xA0 /*--------------------------------------------------------------------------- - Static/Global variables + Static/Global variables ---------------------------------------------------------------------------*/ -static /*const*/ char nibble_bitmap_data[NIBBLE_VALUES][LCD_MAG] = -{ -#if LCD_MAG==1 - { 0x00 }, /* ---- */ - { 0x01 }, /* *--- */ - { 0x02 }, /* -*-- */ - { 0x03 }, /* **-- */ - { 0x04 }, /* --*- */ - { 0x05 }, /* *-*- */ - { 0x06 }, /* -**- */ - { 0x07 }, /* ***- */ - { 0x08 }, /* ---* */ - { 0x09 }, /* *--* */ - { 0x0a }, /* -*-* */ - { 0x0b }, /* **-* */ - { 0x0c }, /* --** */ - { 0x0d }, /* *-** */ - { 0x0e }, /* -*** */ - { 0x0f } /* **** */ -#elif LCD_MAG==2 - { 0x00, 0x00 }, /* ---- */ - { 0x03, 0x03 }, /* *--- */ - { 0x0c, 0x0c }, /* -*-- */ - { 0x0f, 0x0f }, /* **-- */ - { 0x30, 0x30 }, /* --*- */ - { 0x33, 0x33 }, /* *-*- */ - { 0x3c, 0x3c }, /* -**- */ - { 0x3f, 0x3f }, /* ***- */ - { 0xc0, 0xc0 }, /* ---* */ - { 0xc3, 0xc3 }, /* *--* */ - { 0xcc, 0xcc }, /* -*-* */ - { 0xcf, 0xcf }, /* **-* */ - { 0xf0, 0xf0 }, /* --** */ - { 0xf3, 0xf3 }, /* *-** */ - { 0xfc, 0xfc }, /* -*** */ - { 0xff, 0xff } /* **** */ +static /*const*/ char nibble_bitmap_data[ NIBBLE_VALUES ][ LCD_MAG ] = { +#if LCD_MAG == 1 + { 0x00 }, /* ---- */ + { 0x01 }, /* *--- */ + { 0x02 }, /* -*-- */ + { 0x03 }, /* **-- */ + { 0x04 }, /* --*- */ + { 0x05 }, /* *-*- */ + { 0x06 }, /* -**- */ + { 0x07 }, /* ***- */ + { 0x08 }, /* ---* */ + { 0x09 }, /* *--* */ + { 0x0a }, /* -*-* */ + { 0x0b }, /* **-* */ + { 0x0c }, /* --** */ + { 0x0d }, /* *-** */ + { 0x0e }, /* -*** */ + { 0x0f } /* **** */ +#elif LCD_MAG == 2 + { 0x00, 0x00 }, /* ---- */ + { 0x03, 0x03 }, /* *--- */ + { 0x0c, 0x0c }, /* -*-- */ + { 0x0f, 0x0f }, /* **-- */ + { 0x30, 0x30 }, /* --*- */ + { 0x33, 0x33 }, /* *-*- */ + { 0x3c, 0x3c }, /* -**- */ + { 0x3f, 0x3f }, /* ***- */ + { 0xc0, 0xc0 }, /* ---* */ + { 0xc3, 0xc3 }, /* *--* */ + { 0xcc, 0xcc }, /* -*-* */ + { 0xcf, 0xcf }, /* **-* */ + { 0xf0, 0xf0 }, /* --** */ + { 0xf3, 0xf3 }, /* *-** */ + { 0xfc, 0xfc }, /* -*** */ + { 0xff, 0xff } /* **** */ #else # error "Bad LCD_MAG; supported values are 1 and 2" #endif }; -static /*const*/ struct -{ - int mask; /* Bit mask */ - int x, y; /* Position */ - int w, h; /* Width, Height */ - char bitmap_data[24]; /* Bitmap data */ +static /*const*/ struct { + int mask; /* Bit mask */ + int x, y; /* Position */ + int w, h; /* Width, Height */ + char bitmap_data[ 24 ]; /* Bitmap data */ } -#define ANN_X(i) (8*LCD_MAG+(22*LCD_MAG+1)*i) -#define ANN_Y(i) (1+3*(LCD_MAG-1)) - -ann_data[N_ANN] = -{ - { MASK_ANN_LEFT, - ANN_X(0), ANN_Y(0), - 15, 12, - { 0xfe, 0x3f, 0xff, 0x7f, 0x9f, 0x7f, 0xcf, 0x7f, 0xe7, 0x7f, 0x03, 0x78, - 0x03, 0x70, 0xe7, 0x73, 0xcf, 0x73, 0x9f, 0x73, 0xff, 0x73, 0xfe, 0x33 - } - }, - { MASK_ANN_RIGHT, - ANN_X(1), ANN_Y(1), - 15, 12, - { 0xfe, 0x3f, 0xff, 0x7f, 0xff, 0x7c, 0xff, 0x79, 0xff, 0x73, 0x0f, 0x60, - 0x07, 0x60, 0xe7, 0x73, 0xe7, 0x79, 0xe7, 0x7c, 0xe7, 0x7f, 0xe6, 0x3f - } - }, - { MASK_ANN_ALPHA, - ANN_X(2), ANN_Y(2), - 15, 12, - { 0xe0, 0x03, 0x18, 0x44, 0x0c, 0x4c, 0x06, 0x2c, 0x07, 0x2c, 0x07, 0x1c, - 0x07, 0x0c, 0x07, 0x0c, 0x07, 0x0e, 0x0e, 0x4d, 0xf8, 0x38, 0x00, 0x00 - } - }, - { MASK_ANN_BATTERY, - ANN_X(3), ANN_Y(3), - 15, 12, - { 0x04, 0x10, 0x02, 0x20, 0x12, 0x24, 0x09, 0x48, 0xc9, 0x49, 0xc9, 0x49, - 0xc9, 0x49, 0x09, 0x48, 0x12, 0x24, 0x02, 0x20, 0x04, 0x10, 0x00, 0x00 - } - }, - { MASK_ANN_BUSY, - ANN_X(4), ANN_Y(4), - 15, 12, - { 0xfc, 0x1f, 0x08, 0x08, 0x08, 0x08, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, - 0x40, 0x01, 0x20, 0x02, 0x10, 0x04, 0xc8, 0x09, 0xe8, 0x0b, 0xfc, 0x1f - } - }, - { MASK_ANN_IO, - ANN_X(5), ANN_Y(5), - 15, 12, - { 0x0c, 0x00, 0x1e, 0x00, 0x33, 0x0c, 0x61, 0x18, 0xcc, 0x30, 0xfe, 0x7f, - 0xfe, 0x7f, 0xcc, 0x30, 0x61, 0x18, 0x33, 0x0c, 0x1e, 0x00, 0x0c, 0x00 - } - } +#define ANN_X( i ) ( 8 * LCD_MAG + ( 22 * LCD_MAG + 1 ) * i ) +#define ANN_Y( i ) ( 1 + 3 * ( LCD_MAG - 1 ) ) +ann_data[ N_ANN ] = { + {MASK_ANN_LEFT, ANN_X( 0 ), ANN_Y( 0 ), 15, 12, { 0xfe, 0x3f, 0xff, 0x7f, 0x9f, 0x7f, 0xcf, 0x7f, 0xe7, 0x7f, 0x03, 0x78, + 0x03, 0x70, 0xe7, 0x73, 0xcf, 0x73, 0x9f, 0x73, 0xff, 0x73, 0xfe, 0x33 } }, + {MASK_ANN_RIGHT, ANN_X( 1 ), ANN_Y( 1 ), 15, 12, { 0xfe, 0x3f, 0xff, 0x7f, 0xff, 0x7c, 0xff, 0x79, 0xff, 0x73, 0x0f, 0x60, + 0x07, 0x60, 0xe7, 0x73, 0xe7, 0x79, 0xe7, 0x7c, 0xe7, 0x7f, 0xe6, 0x3f } }, + {MASK_ANN_ALPHA, ANN_X( 2 ), ANN_Y( 2 ), 15, 12, { 0xe0, 0x03, 0x18, 0x44, 0x0c, 0x4c, 0x06, 0x2c, 0x07, 0x2c, 0x07, 0x1c, + 0x07, 0x0c, 0x07, 0x0c, 0x07, 0x0e, 0x0e, 0x4d, 0xf8, 0x38, 0x00, 0x00 } }, + {MASK_ANN_BATTERY, ANN_X( 3 ), ANN_Y( 3 ), 15, 12, { 0x04, 0x10, 0x02, 0x20, 0x12, 0x24, 0x09, 0x48, 0xc9, 0x49, 0xc9, 0x49, + 0xc9, 0x49, 0x09, 0x48, 0x12, 0x24, 0x02, 0x20, 0x04, 0x10, 0x00, 0x00 }}, + {MASK_ANN_BUSY, ANN_X( 4 ), ANN_Y( 4 ), 15, 12, { 0xfc, 0x1f, 0x08, 0x08, 0x08, 0x08, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, + 0x40, 0x01, 0x20, 0x02, 0x10, 0x04, 0xc8, 0x09, 0xe8, 0x0b, 0xfc, 0x1f } }, + {MASK_ANN_IO, ANN_X( 5 ), ANN_Y( 5 ), 15, 12, { 0x0c, 0x00, 0x1e, 0x00, 0x33, 0x0c, 0x61, 0x18, 0xcc, 0x30, 0xfe, 0x7f, + 0xfe, 0x7f, 0xcc, 0x30, 0x61, 0x18, 0x33, 0x0c, 0x1e, 0x00, 0x0c, 0x00 } } }; -static Nibble lcd_buffer[MAX_ROWS][NIBBLES_PER_ROW]; +static Nibble lcd_buffer[ MAX_ROWS ][ NIBBLES_PER_ROW ]; static int ann_buffer; static int clean; -static Display *display; +static Display* display; static Window window; static GC gc; static unsigned long fg_pixel, bg_pixel; static unsigned int depth; -static Pixmap nibble_pixmap[NIBBLE_VALUES]; -static Pixmap ann_pixmap[N_ANN]; - +static Pixmap nibble_pixmap[ NIBBLE_VALUES ]; +static Pixmap ann_pixmap[ N_ANN ]; /*--------------------------------------------------------------------------- - Private functions + Private functions ---------------------------------------------------------------------------*/ /* .+ @@ -272,56 +236,43 @@ static Pixmap ann_pixmap[N_ANN]; stores them into the appropriate global variables. .call : - InitPixmaps(); + InitPixmaps(); .input : - void + void .output : - void + void .status_codes : - X11_I_CALLED - X11_F_X_ERROR + X11_I_CALLED + X11_F_X_ERROR .notes : 1.1, 29-Jan-1998, creation .- */ -static void InitPixmaps(void) +static void InitPixmaps( void ) { - int i; + int i; - debug1(DEBUG_C_TRACE, X11_I_CALLED, "InitPixmaps"); + debug1( DEBUG_C_TRACE, X11_I_CALLED, "InitPixmaps" ); - /* Initialize nibble_pixmap */ - for(i=0; i - /*--------------------------------------------------------------------------- - Private macros / variables / functions + Private macros / variables / functions ---------------------------------------------------------------------------*/ -#define T1_MULTIPLIER (8192/16) /* T2/T1 increment ratio */ -#define T1_INTERVAL 62500 /* us per T1 increment */ -#define T2_INTERVAL 122 /* us per T2 increment */ +#define T1_MULTIPLIER ( 8192 / 16 ) /* T2/T1 increment ratio */ +#define T1_INTERVAL 62500 /* us per T1 increment */ +#define T2_INTERVAL 122 /* us per T2 increment */ /* 3.1: MAX_IDLE_X_LOOP_TIMEOUT must be low enough to prevent overflow of an int when computing the difference in microseconds between two @@ -155,383 +154,353 @@ static char rcs_id[] = "$Id: emulator.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $ module will support asynchronous selection on pty fd and will be able to interact with the GUI's select mechanism. */ -#define T1_MS_MULTIPLIER 63 /* 3.1: Milliseconds per T1 tick (~) */ -#define T2_MS_DIVISOR 8 /* 3.1: T2 ticks per millisecond (~) */ -#define MAX_IDLE_X_LOOP_TIMEOUT 1000 /* 3.1: Max timeout for IdleXLoop() */ +#define T1_MS_MULTIPLIER 63 /* 3.1: Milliseconds per T1 tick (~) */ +#define T2_MS_DIVISOR 8 /* 3.1: T2 ticks per millisecond (~) */ +#define MAX_IDLE_X_LOOP_TIMEOUT 1000 /* 3.1: Max timeout for IdleXLoop() */ -#define T1_OVF_MASK NIBBLE_MASK /* 3.1: Timer overflow masks */ -#define T2_OVF_MASK 0xFFFFFFFF +#define T1_OVF_MASK NIBBLE_MASK /* 3.1: Timer overflow masks */ +#define T2_OVF_MASK 0xFFFFFFFF -#define LCD_T1_MASK 0x3 /* LCD refresh timing mask */ -#define INT_T1_MASK 0xF /* Int. req. timing mask */ +#define LCD_T1_MASK 0x3 /* LCD refresh timing mask */ +#define INT_T1_MASK 0xF /* Int. req. timing mask */ -static int emulator_int_req = 0; /* Interrupt request flag */ +static int emulator_int_req = 0; /* Interrupt request flag */ /* This function contains the main emulator loop; under normal conditions, it never returns to the caller. The only way to exit this function is to signal a Chf condition that triggers an unwind operation. */ -static void EmulatorLoop(void) +static void EmulatorLoop( void ) { - struct timeval old_t, cur_t; - int ela; - int inner_loop = cpu_status.inner_loop; - int t1_count = 0; - int i, j; + struct timeval old_t, cur_t; + int ela; + int inner_loop = cpu_status.inner_loop; + int t1_count = 0; + int i, j; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "EmulatorLoop"); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "EmulatorLoop" ); - /* Ignore past interrupt requests */ - emulator_int_req = 0; + /* Ignore past interrupt requests */ + emulator_int_req = 0; - /* Get current time of day */ - gettimeofday(&old_t, NULL); + /* Get current time of day */ + gettimeofday( &old_t, NULL ); - while(1) - { - /* T1 loop */ - for(j=0; j= cpu_status.inner_loop_max) - { - inner_loop = cpu_status.inner_loop_max; - if(T1_INTERVAL > ela) usleep(T1_INTERVAL - ela); - } + /* 3.13: Force an upper limit to the CPU speed if the compile-time option + REAL_CPU_SPEED is defined: inner_loop is limited to + cpu_status.inner_loop_max + and the excess time, if any, is spent sleeping; usleep() is + BSD 4.3-specific, but most recent systems should offer it anyway, + well, I hope. + The special value cpu_status.inner_loop_max==0 gives maximum speed. + */ + if ( cpu_status.inner_loop_max != 0 && inner_loop >= cpu_status.inner_loop_max ) { + inner_loop = cpu_status.inner_loop_max; + if ( T1_INTERVAL > ela ) + usleep( T1_INTERVAL - ela ); + } #endif - cpu_status.inner_loop = inner_loop; - old_t = cur_t; - } + cpu_status.inner_loop = inner_loop; + old_t = cur_t; + } } - /* Condition handler for the EmulatorLoop */ -static ChfAction EmulatorLoopHandler( - const ChfDescriptor *d, - const ChfState s, - ChfPointer ctx -) +static ChfAction EmulatorLoopHandler( const ChfDescriptor* d, const ChfState s, ChfPointer ctx ) { - ChfAction act; + ChfAction act; - /* Check Chf state */ - switch(s) - { - /* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */ - case CHF_SIGNALING: - /* ChfSignal() in progress */ - if(ChfGetModuleId(d) == CPU_CHF_MODULE_ID) - { - /* Condition from CPU modules; check Condition Code */ - switch(ChfGetConditionCode(d)) - { + /* Check Chf state */ + switch ( s ) { + /* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */ + case CHF_SIGNALING: + /* ChfSignal() in progress */ + if ( ChfGetModuleId( d ) == CPU_CHF_MODULE_ID ) { + /* Condition from CPU modules; check Condition Code */ + switch ( ChfGetConditionCode( d ) ) { #ifdef CPU_SPIN_SHUTDN - case CPU_I_SHUTDN: - /* CPU shutdown signalled with CPU_SPIN_SHUTDN defined; - Fatal error. - */ - ChfCondition CPU_F_BAD_SHUTDN, CHF_FATAL ChfEnd; - ChfSignal(); + case CPU_I_SHUTDN: + /* CPU shutdown signalled with CPU_SPIN_SHUTDN defined; + Fatal error. + */ + ChfCondition CPU_F_BAD_SHUTDN, CHF_FATAL ChfEnd; + ChfSignal(); - act = CHF_RESIGNAL; - break; + act = CHF_RESIGNAL; + break; #else - case CPU_I_SHUTDN: - { - /* 3.1: CPU_SPIN_SHUTDN is not defined, and the cpu emulator - has just executed a shutdown instruction. - Let's do something a little tricky here: + case CPU_I_SHUTDN: + { + /* 3.1: CPU_SPIN_SHUTDN is not defined, and the cpu emulator + has just executed a shutdown instruction. + Let's do something a little tricky here: - 1- redraw the LCD + 1- redraw the LCD - 2- handle serial port activities + 2- handle serial port activities - 3- determine which timer will expire first, and - compute an approximate value of the maximum duration - of the shutdown --> ms + 3- determine which timer will expire first, and + compute an approximate value of the maximum duration + of the shutdown --> ms - 4- handle serial port activities + 4- handle serial port activities - 5- enter the inner idle loop; it breaks when either an - X Event occurred (possibly clearing the shutdown) or - the shutdown timeout elapses + 5- enter the inner idle loop; it breaks when either an + X Event occurred (possibly clearing the shutdown) or + the shutdown timeout elapses - 6- determine the actual time we spend in the idle loop - (X timeouts are not accurate enough for this purpose) + 6- determine the actual time we spend in the idle loop + (X timeouts are not accurate enough for this purpose) - 7- update T1 and T2, check their state and wake/interrupt - the CPU if necessary + 7- update T1 and T2, check their state and wake/interrupt + the CPU if necessary - Activities 3-7 above are enclosed in an outer loop because we - cannot be absolutely sure of the actual time spent - in the idle loop; moreover, not all X Events actually - spool up the CPU. The outer loop breaks when the CPU is - actually brought out of shutdown. + Activities 3-7 above are enclosed in an outer loop because we + cannot be absolutely sure of the actual time spent + in the idle loop; moreover, not all X Events actually + spool up the CPU. The outer loop breaks when the CPU is + actually brought out of shutdown. - frac_t1 and frac_t2 contain the number of microseconds - not accounted for in the last T1/T2 update, respectively; - they help minimize the cumulative timing error induced - by executing the outer idle loop more than once. - */ - struct timeval start_idle, end_idle; - int frac_t1=0, frac_t2=0; + frac_t1 and frac_t2 contain the number of microseconds + not accounted for in the last T1/T2 update, respectively; + they help minimize the cumulative timing error induced + by executing the outer idle loop more than once. + */ + struct timeval start_idle, end_idle; + int frac_t1 = 0, frac_t2 = 0; - gettimeofday(&start_idle, NULL); + gettimeofday( &start_idle, NULL ); - /* Redraw the LCD immediately before entering idle loop; - this ensures that the latest LCD updated actually - get to the screen. - */ - DrawLcd(); + /* Redraw the LCD immediately before entering idle loop; + this ensures that the latest LCD updated actually + get to the screen. + */ + DrawLcd(); - /* Handle serial port activity before entering the outer idle - loop, because this could possibly bring the cpu out of - shutdown right now. - */ - HandleSerial(); + /* Handle serial port activity before entering the outer idle + loop, because this could possibly bring the cpu out of + shutdown right now. + */ + HandleSerial(); - /* XXX - If either timer has a pending service request, - process it immediately. It is not clear why it was - not processed *before* shutdown, though. - */ - if(mod_status.hdw.t1_ctrl & T1_CTRL_SREQ) - { - if(mod_status.hdw.t1_ctrl & T1_CTRL_WAKE) - CpuWake(); + /* XXX + If either timer has a pending service request, + process it immediately. It is not clear why it was + not processed *before* shutdown, though. + */ + if ( mod_status.hdw.t1_ctrl & T1_CTRL_SREQ ) { + if ( mod_status.hdw.t1_ctrl & T1_CTRL_WAKE ) + CpuWake(); - if(mod_status.hdw.t1_ctrl & T1_CTRL_INT) - CpuIntRequest(INT_REQUEST_IRQ); - } + if ( mod_status.hdw.t1_ctrl & T1_CTRL_INT ) + CpuIntRequest( INT_REQUEST_IRQ ); + } - if(mod_status.hdw.t2_ctrl & T2_CTRL_SREQ) - { - if(mod_status.hdw.t2_ctrl & T2_CTRL_WAKE) - CpuWake(); + if ( mod_status.hdw.t2_ctrl & T2_CTRL_SREQ ) { + if ( mod_status.hdw.t2_ctrl & T2_CTRL_WAKE ) + CpuWake(); - if(mod_status.hdw.t2_ctrl & T2_CTRL_INT) - CpuIntRequest(INT_REQUEST_IRQ); - } + if ( mod_status.hdw.t2_ctrl & T2_CTRL_INT ) + CpuIntRequest( INT_REQUEST_IRQ ); + } - while(cpu_status.shutdn) - { - unsigned long ms = MAX_IDLE_X_LOOP_TIMEOUT; - unsigned long mst; - int ela; - int ela_ticks; + while ( cpu_status.shutdn ) { + unsigned long ms = MAX_IDLE_X_LOOP_TIMEOUT; + unsigned long mst; + int ela; + int ela_ticks; - debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (during SHUTDN)", - mod_status.hdw.t1_ctrl, mod_status.hdw.t1_val); - debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (during SHUTDN)", - mod_status.hdw.t2_ctrl, mod_status.hdw.t2_val); + debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (during SHUTDN)", mod_status.hdw.t1_ctrl, + mod_status.hdw.t1_val ); + debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (during SHUTDN)", mod_status.hdw.t2_ctrl, + mod_status.hdw.t2_val ); - /* Determine which timer will expire first */ - if(mod_status.hdw.t1_ctrl & (T1_CTRL_INT|T1_CTRL_WAKE)) - { - /* T1 will do something on expiration */ - mst = ((unsigned long)mod_status.hdw.t1_val + 1) - * T1_MS_MULTIPLIER; + /* Determine which timer will expire first */ + if ( mod_status.hdw.t1_ctrl & ( T1_CTRL_INT | T1_CTRL_WAKE ) ) { + /* T1 will do something on expiration */ + mst = ( ( unsigned long )mod_status.hdw.t1_val + 1 ) * T1_MS_MULTIPLIER; - debug2(DEBUG_C_TIMERS, CPU_I_TIMER_EXP, "T1", mst); + debug2( DEBUG_C_TIMERS, CPU_I_TIMER_EXP, "T1", mst ); - if(mst < ms) ms = mst; - } + if ( mst < ms ) + ms = mst; + } - if((mod_status.hdw.t2_ctrl & T2_CTRL_TRUN) - && (mod_status.hdw.t2_ctrl & (T2_CTRL_INT|T2_CTRL_WAKE))) - { - /* T2 is running and will do something on expiration */ - mst = ((unsigned long)mod_status.hdw.t2_val + 1) - / T2_MS_DIVISOR; + if ( ( mod_status.hdw.t2_ctrl & T2_CTRL_TRUN ) && + ( mod_status.hdw.t2_ctrl & ( T2_CTRL_INT | T2_CTRL_WAKE ) ) ) { + /* T2 is running and will do something on expiration */ + mst = ( ( unsigned long )mod_status.hdw.t2_val + 1 ) / T2_MS_DIVISOR; - debug2(DEBUG_C_TIMERS, CPU_I_TIMER_EXP, "T2", mst); + debug2( DEBUG_C_TIMERS, CPU_I_TIMER_EXP, "T2", mst ); - if(mst < ms) ms = mst; - } + if ( mst < ms ) + ms = mst; + } - /* Handle serial port activities at each iteration of - the outer idle loop; this ensures that the serial - port emulation will not starve. - */ - HandleSerial(); + /* Handle serial port activities at each iteration of + the outer idle loop; this ensures that the serial + port emulation will not starve. + */ + HandleSerial(); - /* Enter idle loop, possibly with timeout; - The loop breaks when: - - any X Event occurs (possibly clearing the shutdown) - - the given timeout expires - */ - debug1(DEBUG_C_TIMERS, CPU_I_IDLE_X_LOOP, ms); - IdleXLoop(ms); + /* Enter idle loop, possibly with timeout; + The loop breaks when: + - any X Event occurs (possibly clearing the shutdown) + - the given timeout expires + */ + debug1( DEBUG_C_TIMERS, CPU_I_IDLE_X_LOOP, ms ); + IdleXLoop( ms ); - /* End of idle loop; compute actual elapsed time */ - gettimeofday(&end_idle, NULL); + /* End of idle loop; compute actual elapsed time */ + gettimeofday( &end_idle, NULL ); - ela = (end_idle.tv_sec - start_idle.tv_sec) * 1000000 + - (end_idle.tv_usec - start_idle.tv_usec); + ela = ( end_idle.tv_sec - start_idle.tv_sec ) * 1000000 + ( end_idle.tv_usec - start_idle.tv_usec ); - /* Update start_idle here to contain lag */ - start_idle = end_idle; + /* Update start_idle here to contain lag */ + start_idle = end_idle; - debug1(DEBUG_C_TIMERS, CPU_I_ELAPSED, ela); + debug1( DEBUG_C_TIMERS, CPU_I_ELAPSED, ela ); - /* Update timers and act accordingly */ - ela_ticks = ((ela+frac_t1) + T1_INTERVAL/2) / T1_INTERVAL; - frac_t1 = (ela+frac_t1) - ela_ticks * T1_INTERVAL; + /* Update timers and act accordingly */ + ela_ticks = ( ( ela + frac_t1 ) + T1_INTERVAL / 2 ) / T1_INTERVAL; + frac_t1 = ( ela + frac_t1 ) - ela_ticks * T1_INTERVAL; - if(ela_ticks > mod_status.hdw.t1_val) - { - debug1(DEBUG_C_TIMERS, CPU_I_TIMER1_EX, - mod_status.hdw.t1_ctrl); + if ( ela_ticks > mod_status.hdw.t1_val ) { + debug1( DEBUG_C_TIMERS, CPU_I_TIMER1_EX, mod_status.hdw.t1_ctrl ); - mod_status.hdw.t1_ctrl |= T1_CTRL_SREQ; + mod_status.hdw.t1_ctrl |= T1_CTRL_SREQ; - if(mod_status.hdw.t1_ctrl & T1_CTRL_WAKE) - CpuWake(); + if ( mod_status.hdw.t1_ctrl & T1_CTRL_WAKE ) + CpuWake(); - if(mod_status.hdw.t1_ctrl & T1_CTRL_INT) - CpuIntRequest(INT_REQUEST_IRQ); - } + if ( mod_status.hdw.t1_ctrl & T1_CTRL_INT ) + CpuIntRequest( INT_REQUEST_IRQ ); + } - mod_status.hdw.t1_val = - (mod_status.hdw.t1_val - ela_ticks) & T1_OVF_MASK; + mod_status.hdw.t1_val = ( mod_status.hdw.t1_val - ela_ticks ) & T1_OVF_MASK; - if(mod_status.hdw.t2_ctrl & T2_CTRL_TRUN) - { - ela_ticks = ((ela+frac_t2) + T2_INTERVAL/2) / T2_INTERVAL; - frac_t2 = (ela+frac_t2) - ela_ticks * T2_INTERVAL; + if ( mod_status.hdw.t2_ctrl & T2_CTRL_TRUN ) { + ela_ticks = ( ( ela + frac_t2 ) + T2_INTERVAL / 2 ) / T2_INTERVAL; + frac_t2 = ( ela + frac_t2 ) - ela_ticks * T2_INTERVAL; - if(ela_ticks > mod_status.hdw.t2_val) - { - debug1(DEBUG_C_TIMERS, CPU_I_TIMER2_EX, - mod_status.hdw.t2_ctrl); + if ( ela_ticks > mod_status.hdw.t2_val ) { + debug1( DEBUG_C_TIMERS, CPU_I_TIMER2_EX, mod_status.hdw.t2_ctrl ); - mod_status.hdw.t2_ctrl |= T2_CTRL_SREQ; + mod_status.hdw.t2_ctrl |= T2_CTRL_SREQ; - if(mod_status.hdw.t2_ctrl & T2_CTRL_WAKE) - CpuWake(); + if ( mod_status.hdw.t2_ctrl & T2_CTRL_WAKE ) + CpuWake(); - if(mod_status.hdw.t2_ctrl & T2_CTRL_INT) - CpuIntRequest(INT_REQUEST_IRQ); - } + if ( mod_status.hdw.t2_ctrl & T2_CTRL_INT ) + CpuIntRequest( INT_REQUEST_IRQ ); + } - mod_status.hdw.t2_val = - (mod_status.hdw.t2_val - ela_ticks) & T2_OVF_MASK; - } - } + mod_status.hdw.t2_val = ( mod_status.hdw.t2_val - ela_ticks ) & T2_OVF_MASK; + } + } - debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (after SHUTDN)", - mod_status.hdw.t1_ctrl, mod_status.hdw.t1_val); - debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (after SHUTDN)", - mod_status.hdw.t2_ctrl, mod_status.hdw.t2_val); + debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (after SHUTDN)", mod_status.hdw.t1_ctrl, mod_status.hdw.t1_val ); + debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (after SHUTDN)", mod_status.hdw.t2_ctrl, mod_status.hdw.t2_val ); - act = CHF_CONTINUE; - } - break; + act = CHF_CONTINUE; + } + break; #endif - case CPU_I_EMULATOR_INT: - /* Emulator interrupt; unwind */ - act = CHF_UNWIND; - break; + case CPU_I_EMULATOR_INT: + /* Emulator interrupt; unwind */ + act = CHF_UNWIND; + break; - default: - /* Condition Code not handled; resignal */ - act = CHF_RESIGNAL; - } - } + default: + /* Condition Code not handled; resignal */ + act = CHF_RESIGNAL; + } + } - else - /* Condition from other modules; resignal */ - act = CHF_RESIGNAL; + else + /* Condition from other modules; resignal */ + act = CHF_RESIGNAL; - break; + break; - default: - /* Other states; resignal the condition */ - act = CHF_RESIGNAL; - break; - } + default: + /* Other states; resignal the condition */ + act = CHF_RESIGNAL; + break; + } - return act; + return act; } - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : Emulator @@ -547,43 +516,40 @@ static ChfAction EmulatorLoopHandler( a Chf Condition that triggers an unwind operation. .call : - Emulator(); + Emulator(); .input : - void + void .output : - void + void .status_codes : - CPU_I_CALLED - CPU_I_TIMER1_EX - CPU_I_TIMER2_EX - Other conditions signalled by lower level modules + CPU_I_CALLED + CPU_I_TIMER1_EX + CPU_I_TIMER2_EX + Other conditions signalled by lower level modules .notes : 1.1, 17-Feb-1998, creation .- */ -void Emulator(void) +void Emulator( void ) { - jmp_buf unwind_context; + jmp_buf unwind_context; - debug1(DEBUG_C_TRACE, CPU_I_CALLED, "Emulator"); + debug1( DEBUG_C_TRACE, CPU_I_CALLED, "Emulator" ); - /* Setup unwind_context */ - if(setjmp(unwind_context) == 0) - { - /* Push condition handler, with NULL context */ - ChfPushHandler(EmulatorLoopHandler, &unwind_context, (ChfPointer)NULL); + /* Setup unwind_context */ + if ( setjmp( unwind_context ) == 0 ) { + /* Push condition handler, with NULL context */ + ChfPushHandler( EmulatorLoopHandler, &unwind_context, ( ChfPointer )NULL ); - /* Activate emulator loop */ - EmulatorLoop(); - } + /* Activate emulator loop */ + EmulatorLoop(); + } - else - { - /* Unwinding after an emulator interrupt */ - } + else { + /* Unwinding after an emulator interrupt */ + } } - /* .+ .title : EmulatorIntRequest @@ -595,22 +561,18 @@ void Emulator(void) return to the caller. .call : - EmulatorIntRequest(); + EmulatorIntRequest(); .input : - void + void .output : - void + void .status_codes : - * + * .notes : 1.1, 18-Feb-1998, creation .- */ -void EmulatorIntRequest(void) -{ - emulator_int_req = 1; -} - +void EmulatorIntRequest( void ) { emulator_int_req = 1; } /* .+ @@ -623,14 +585,14 @@ void EmulatorIntRequest(void) subsystems, too. .call : - EmulatorInit(); + EmulatorInit(); .input : - void + void .output : - void + void .status_codes : - * Status codes signaled by CpuInit() and CpuReset() - * Status codes signaled by ModInit() and ModReset() + * Status codes signaled by CpuInit() and CpuReset() + * Status codes signaled by ModInit() and ModReset() .notes : 2.1, 8-Sep-2000, creation 2.4, 12-Sep-2000, update @@ -642,24 +604,22 @@ void EmulatorIntRequest(void) args.hw option. .- */ -void EmulatorInit(void) +void EmulatorInit( void ) { /* Select a module description table */ - ModSelectDescription(args.hw); + ModSelectDescription( args.hw ); /* Initialize cpu and modules subsystems */ CpuInit(); ModInit(); /* Reset if appropriate */ - if(args.reset) - { - CpuReset(); - ModReset(); + if ( args.reset ) { + CpuReset(); + ModReset(); } } - /* .+ .title : EmulatorExit @@ -672,30 +632,29 @@ void EmulatorInit(void) returns to the caller unless an unrecoverable error occurs. .call : - EmulatorExit(opt); + EmulatorExit(opt); .input : - enum ExitOption opt, emulator exit option + enum ExitOption opt, emulator exit option .output : - void + void .status_codes : - * Status codes signaled by CpuSave() and ModSave() + * Status codes signaled by CpuSave() and ModSave() .notes : 2.1, 8-Sep-2000, creation .- */ -void EmulatorExit(enum ExitOption opt) +void EmulatorExit( enum ExitOption opt ) { - switch(opt) - { + switch ( opt ) { - case SAVE_AND_EXIT: - /* Save state of cpu and modules subsystems */ - ModSave(); - CpuSave(); - break; + case SAVE_AND_EXIT: + /* Save state of cpu and modules subsystems */ + ModSave(); + CpuSave(); + break; - default: - /* Default behavior; do nothing */ - break; + default: + /* Default behavior; do nothing */ + break; } } diff --git a/src/flash49.c b/src/flash49.c index b6ae34a..65e6e1a 100644 --- a/src/flash49.c +++ b/src/flash49.c @@ -87,326 +87,273 @@ static char rcs_id[] = "$Id: flash49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" #include "args.h" -#define CHF_MODULE_ID FLASH_CHF_MODULE_ID +#define CHF_MODULE_ID FLASH_CHF_MODULE_ID #include - - /*--------------------------------------------------------------------------- Private Macro/Data type definitions ---------------------------------------------------------------------------*/ -#define BLOCK_SIZE 0x10000 -#define BLOCK_BASE_MASK 0xFFFF - -#define ByteAddress(address) ((address) >> 1) -#define NibbleAddress(address) ((address) << 1) -#define BlockBase(address) ((address) & ~BLOCK_BASE_MASK) -#define IsOdd(address) ((address) & 0x1) -#define LowNibble(d) ((Nibble)((d) & NIBBLE_MASK)) -#define HighNibble(d) ((Nibble)(((d) >> 4) & NIBBLE_MASK)) -#define ShiftHigh(d) ((d) << 4) +#define BLOCK_SIZE 0x10000 +#define BLOCK_BASE_MASK 0xFFFF +#define ByteAddress( address ) ( ( address ) >> 1 ) +#define NibbleAddress( address ) ( ( address ) << 1 ) +#define BlockBase( address ) ( ( address ) & ~BLOCK_BASE_MASK ) +#define IsOdd( address ) ( ( address ) & 0x1 ) +#define LowNibble( d ) ( ( Nibble )( ( d ) & NIBBLE_MASK ) ) +#define HighNibble( d ) ( ( Nibble )( ( ( d ) >> 4 ) & NIBBLE_MASK ) ) +#define ShiftHigh( d ) ( ( d ) << 4 ) /* Flash cycle types */ -enum FlashCycle -{ +enum FlashCycle { FLASH_CYCLE_READ = 0, FLASH_CYCLE_WRITE, - FLASH_CYCLE_N /* Total # of cycle types */ + FLASH_CYCLE_N /* Total # of cycle types */ }; /* State transition function */ -typedef int (*FlashF) - (enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data); - - +typedef int ( *FlashF )( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ); /*--------------------------------------------------------------------------- Private state variables ---------------------------------------------------------------------------*/ /* External storage */ -extern struct ModStatus_49 *mod_status_49; +extern struct ModStatus_49* mod_status_49; -static int r_buffer; /* Nibble buffer during read */ -static int w_buffer; /* Nibble buffer during write */ -static enum FlashState fsm_state; /* FSM state */ +static int r_buffer; /* Nibble buffer during read */ +static int w_buffer; /* Nibble buffer during write */ +static enum FlashState fsm_state; /* FSM state */ /* Write buffer */ -#define WB_COUNT_MASK 0x1F -#define WB_SIZE 0x20 -static int wb_count; /* Counter for Write to Buffer */ -static int wb_cdown; /* Count down */ -static XAddress wb_start; /* Start address for Write to Buffer */ -static int wb[WB_SIZE]; /* Write buffer */ - - +#define WB_COUNT_MASK 0x1F +#define WB_SIZE 0x20 +static int wb_count; /* Counter for Write to Buffer */ +static int wb_cdown; /* Count down */ +static XAddress wb_start; /* Start address for Write to Buffer */ +static int wb[ WB_SIZE ]; /* Write buffer */ /*--------------------------------------------------------------------------- State transition private functions ---------------------------------------------------------------------------*/ - /* This function is called by default for unhandled state transitions */ -static int BadCommand(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int BadCommand( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { /* Unknown command: signal and reset state to FLASH_ST_READ_ARRAY */ - ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, - *state, cycle, address, data - ChfEnd; + ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, *state, cycle, address, data ChfEnd; ChfSignal(); *state = FLASH_ST_READ_ARRAY; - return 0; /* Dummy result */ + return 0; /* Dummy result */ } - /* This function is called to read the Flash Rom array */ -static int ReadArray(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int ReadArray( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { /* Read a byte from the array; no state transitions */ - return - mod_status_49->flash[NibbleAddress(address)] - | ShiftHigh(mod_status_49->flash[NibbleAddress(address)+1]); + return mod_status_49->flash[ NibbleAddress( address ) ] | ShiftHigh( mod_status_49->flash[ NibbleAddress( address ) + 1 ] ); } - /* This function is called to parse the first byte of any command */ -static int ParseCommand(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int ParseCommand( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { - switch(data) - { - case FLASH_CMD_READ_ARRAY: - /* Transition to FLASH_ST_READ_ARRAY state */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Array"); - *state = FLASH_ST_READ_ARRAY; - break; + switch ( data ) { + case FLASH_CMD_READ_ARRAY: + /* Transition to FLASH_ST_READ_ARRAY state */ + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Array" ); + *state = FLASH_ST_READ_ARRAY; + break; - case FLASH_CMD_CLR_SR: - /* Clear status register; section 4.5 on Data Sheet. - The current implementation does nothing, because - the value of the status register is fixed. No state transitions. - */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Clear Status"); - break; + case FLASH_CMD_CLR_SR: + /* Clear status register; section 4.5 on Data Sheet. + The current implementation does nothing, because + the value of the status register is fixed. No state transitions. + */ + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Clear Status" ); + break; - case FLASH_CMD_WRITE_BUFFER: - /* Write to Buffer; section 4.8 on Data Sheet. - Transition to FLASH_ST_READ_XSR state. - */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (start)"); - *state = FLASH_ST_READ_XSR; - break; + case FLASH_CMD_WRITE_BUFFER: + /* Write to Buffer; section 4.8 on Data Sheet. + Transition to FLASH_ST_READ_XSR state. + */ + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (start)" ); + *state = FLASH_ST_READ_XSR; + break; - case FLASH_CMD_READ_SR: - /* Read Status; section 4.4 on Data Sheet. - Transition to FLASH_ST_READ_SR state. - */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Status"); - *state = FLASH_ST_READ_SR; - break; + case FLASH_CMD_READ_SR: + /* Read Status; section 4.4 on Data Sheet. + Transition to FLASH_ST_READ_SR state. + */ + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Status" ); + *state = FLASH_ST_READ_SR; + break; - case FLASH_CMD_BL_ERASE: - /* Block Erase; section 4.6 on Data Sheet. - Transition to FLASH_ST_BL_ERASE state. - Consistency of block addresses is not checked. - */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Erase Block (start)"); - *state = FLASH_ST_BL_ERASE; - break; + case FLASH_CMD_BL_ERASE: + /* Block Erase; section 4.6 on Data Sheet. + Transition to FLASH_ST_BL_ERASE state. + Consistency of block addresses is not checked. + */ + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Erase Block (start)" ); + *state = FLASH_ST_BL_ERASE; + break; - default: - /* Unknown command; signal, ignore, keep current state. */ - ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, - *state, cycle, address, data - ChfEnd; - ChfSignal(); - break; + default: + /* Unknown command; signal, ignore, keep current state. */ + ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, *state, cycle, address, data ChfEnd; + ChfSignal(); + break; } - return 0; /* No result; this is a write cycle */ + return 0; /* No result; this is a write cycle */ } - /* This function returns to the caller the value of XSR */ -static int ReadXSR(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int ReadXSR( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { /* Return XSR status; a buffer is always available in the current emulation scheme. Keep current state. */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read XSR"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read XSR" ); return FLASH_XSR_WBS; } - /* This function returns to the caller the value of SR */ -static int ReadSR(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int ReadSR( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { /* Return SR status; the WSM executes in zero time in the current emulation scheme. Keep current state. */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read SR"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read SR" ); return FLASH_SR_WSMS; } - /* This function is called to store the WRITE_BUFFER byte count; both wb_count and wb_cdown are set; StoreData() decrements the latter, WriteConfirm() uses the former to determine how many bytes must write to the Flash array. */ -static int StoreCount(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int StoreCount( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { /* Store WRITE_BUFFER count; next state is FLASH_ST_WRITE_DATA */ - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (count)"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (count)" ); wb_count = wb_cdown = data & WB_COUNT_MASK; *state = FLASH_ST_WRITE_DATA_1; - return 0; /* No result; this is a write cycle */ + return 0; /* No result; this is a write cycle */ } - /* This function is called to store a byte into the write buffer. The first write cycle also sets the buffer's base address (wb_start). The function transitions to state FLASH_ST_WRITE_CONFIRM when all bytes have been stored. */ -static int StoreData(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int StoreData( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { int index; - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (data)"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (data)" ); /* Store WRITE_BUFFER data; the first write also stores the buffer starting address. */ - switch(*state) - { + switch ( *state ) { - case FLASH_ST_WRITE_DATA_1: - wb_start = address; - wb[0] = data; - *state = FLASH_ST_WRITE_DATA_N; - break; + case FLASH_ST_WRITE_DATA_1: + wb_start = address; + wb[ 0 ] = data; + *state = FLASH_ST_WRITE_DATA_N; + break; - case FLASH_ST_WRITE_DATA_N: - index = address - wb_start; - if(index < 0 || index >= WB_SIZE) - { - ChfCondition FLASH_W_BAD_ADDRESS, CHF_WARNING, - *state, cycle, address, data - ChfEnd; - ChfSignal(); - } - else - wb[index] = data; - break; + case FLASH_ST_WRITE_DATA_N: + index = address - wb_start; + if ( index < 0 || index >= WB_SIZE ) { + ChfCondition FLASH_W_BAD_ADDRESS, CHF_WARNING, *state, cycle, address, data ChfEnd; + ChfSignal(); + } else + wb[ index ] = data; + break; - default: - *state = FLASH_ST_READ_ARRAY; - break; + default: + *state = FLASH_ST_READ_ARRAY; + break; } - if(--wb_cdown < 0) - *state = FLASH_ST_WRITE_CONFIRM; + if ( --wb_cdown < 0 ) + *state = FLASH_ST_WRITE_CONFIRM; - return 0; /* No result; this is a write cycle */ + return 0; /* No result; this is a write cycle */ } - /* This function expects a Write to Buffer confirmation command (FLASH_CMD_WRITE_BUFFER_2); if it is received, the write buffer is copied into the Flash Rom array, otherwise the write cycle is aborted. In both cases, the new state is FLASH_ST_READ_ARRAY. */ -static int WriteConfirm(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int WriteConfirm( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (end)"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Write to Buffer (end)" ); /* Expect Write to Buffer confirmation code */ - if(data == FLASH_CMD_WRITE_BUFFER_2) - { - int i; + if ( data == FLASH_CMD_WRITE_BUFFER_2 ) { + int i; - /* Confirmation OK; write. - Remember that wb_count is the byte count MINUS 1. - */ - for(i=0; i<=wb_count; i++) - { - mod_status_49->flash[NibbleAddress(wb_start+i)] - = LowNibble(wb[i]); - mod_status_49->flash[NibbleAddress(wb_start+i)+1] - = HighNibble(wb[i]); - } + /* Confirmation OK; write. + Remember that wb_count is the byte count MINUS 1. + */ + for ( i = 0; i <= wb_count; i++ ) { + mod_status_49->flash[ NibbleAddress( wb_start + i ) ] = LowNibble( wb[ i ] ); + mod_status_49->flash[ NibbleAddress( wb_start + i ) + 1 ] = HighNibble( wb[ i ] ); + } } *state = FLASH_ST_READ_ARRAY; - return 0; /* No result */ + return 0; /* No result */ } - /* If the FLASH_CMD_BL_ERASE_2 command is received, this function erases the block pointed by the current address; otherwise the block erase operation is aborted. In both cases, the new state is FLASH_ST_READ_SR. */ -static int BlockErase(enum FlashState *state, enum FlashCycle cycle, - XAddress address, int data) +static int BlockErase( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data ) { - debug1(DEBUG_C_FLASH, FLASH_I_FSM_OP, "Block Erase (end)"); + debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Block Erase (end)" ); /* Expect Write to Buffer confirmation code */ - if(data == FLASH_CMD_BL_ERASE_2) - { - XAddress block_base = BlockBase(address); - int i; + if ( data == FLASH_CMD_BL_ERASE_2 ) { + XAddress block_base = BlockBase( address ); + int i; - /* Confirmation OK; erase */ - for(i=0; iflash[ - NibbleAddress(block_base+i)] = (Nibble)0xF; - mod_status_49->flash[ - NibbleAddress(block_base+i)+1] = (Nibble)0xF; - } + /* Confirmation OK; erase */ + for ( i = 0; i < BLOCK_SIZE; i++ ) { + mod_status_49->flash[ NibbleAddress( block_base + i ) ] = ( Nibble )0xF; + mod_status_49->flash[ NibbleAddress( block_base + i ) + 1 ] = ( Nibble )0xF; + } } *state = FLASH_ST_READ_SR; - return 0; /* No result */ + return 0; /* No result */ } - - /*--------------------------------------------------------------------------- FSM state diagram; two-dimensional array of FlashF; each function is invoked when the FSM is in a given state (first index), and a particular cycle (second index) is requested. ---------------------------------------------------------------------------*/ -static FlashF F[FLASH_ST_N][FLASH_CYCLE_N] = -{ - { ReadArray, ParseCommand }, /* FLASH_ST_READ_ARRAY */ - { ReadSR, ParseCommand }, /* FLASH_ST_READ_SR */ - { ReadXSR, StoreCount }, /* FLASH_ST_READ_XSR */ - { BadCommand, StoreData }, /* FLASH_ST_WRITE_DATA_1 */ - { BadCommand, StoreData }, /* FLASH_ST_WRITE_DATA_N */ - { BadCommand, WriteConfirm }, /* FLASH_ST_WRITE_CONFIRM */ - { BadCommand, BlockErase } /* FLASH_ST_BL_ERASE */ +static FlashF F[ FLASH_ST_N ][ FLASH_CYCLE_N ] = { + {ReadArray, ParseCommand}, /* FLASH_ST_READ_ARRAY */ + {ReadSR, ParseCommand}, /* FLASH_ST_READ_SR */ + {ReadXSR, StoreCount }, /* FLASH_ST_READ_XSR */ + {BadCommand, StoreData }, /* FLASH_ST_WRITE_DATA_1 */ + {BadCommand, StoreData }, /* FLASH_ST_WRITE_DATA_N */ + {BadCommand, WriteConfirm}, /* FLASH_ST_WRITE_CONFIRM */ + {BadCommand, BlockErase } /* FLASH_ST_BL_ERASE */ }; - - /*--------------------------------------------------------------------------- Other private functions ---------------------------------------------------------------------------*/ @@ -415,25 +362,23 @@ static FlashF F[FLASH_ST_N][FLASH_CYCLE_N] = with 'address' and 'data' as arguments. Returns the result of the FSM, if any. */ -static int FSM(enum FlashCycle cycle, XAddress address, int data) +static int FSM( enum FlashCycle cycle, XAddress address, int data ) { int result; - debug2(DEBUG_C_FLASH, FLASH_I_FSM, fsm_state, cycle); - debug2(DEBUG_C_FLASH, FLASH_I_FSM_AD, address, data); + debug2( DEBUG_C_FLASH, FLASH_I_FSM, fsm_state, cycle ); + debug2( DEBUG_C_FLASH, FLASH_I_FSM_AD, address, data ); - result = F[fsm_state][cycle](&fsm_state, cycle, address, data); + result = F[ fsm_state ][ cycle ]( &fsm_state, cycle, address, data ); - debug2(DEBUG_C_FLASH, FLASH_I_FSM_RESULT, fsm_state, result); + debug2( DEBUG_C_FLASH, FLASH_I_FSM_RESULT, fsm_state, result ); return result; } - /*--------------------------------------------------------------------------- Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : FlashRead49 @@ -447,41 +392,38 @@ static int FSM(enum FlashCycle cycle, XAddress address, int data) addresses. .call : - n = FlashRead49(address); + n = FlashRead49(address); .input : - XAddress address + XAddress address .output : - Nibble n + Nibble n .status_codes : - FLASH_I_READ - FLASH_I_FSM_OP - FLASH_W_BAD_CMD + FLASH_I_READ + FLASH_I_FSM_OP + FLASH_W_BAD_CMD .notes : 3.3, 25-Sep-2000, creation .- */ -Nibble FlashRead49(XAddress address) +Nibble FlashRead49( XAddress address ) { Nibble result; - if(IsOdd(address)) - /* Odd address, return buffered data from previous read */ - result = HighNibble(r_buffer); + if ( IsOdd( address ) ) + /* Odd address, return buffered data from previous read */ + result = HighNibble( r_buffer ); - else - { - /* Even address, invoke FSM */ - r_buffer = FSM(FLASH_CYCLE_READ, ByteAddress(address), 0); - result = LowNibble(r_buffer); + else { + /* Even address, invoke FSM */ + r_buffer = FSM( FLASH_CYCLE_READ, ByteAddress( address ), 0 ); + result = LowNibble( r_buffer ); } - - debug2(DEBUG_C_TRACE|DEBUG_C_FLASH, FLASH_I_READ, address, result); + debug2( DEBUG_C_TRACE | DEBUG_C_FLASH, FLASH_I_READ, address, result ); return result; } - /* .+ .title : FlashWrite49 @@ -494,32 +436,30 @@ Nibble FlashRead49(XAddress address) addresses. .call : - FlashWrite49(address, datum); + FlashWrite49(address, datum); .input : - XAddress address - Nibble datum + XAddress address + Nibble datum .output : - void + void .status_codes : - FLASH_I_WRITE - FLASH_I_FSM_OP - FLASH_W_BAD_CMD - FLASH_W_BAD_ADDRESS + FLASH_I_WRITE + FLASH_I_FSM_OP + FLASH_W_BAD_CMD + FLASH_W_BAD_ADDRESS .notes : 3.3, 25-Sep-2000, creation .- */ -void FlashWrite49(XAddress address, Nibble datum) -{ - debug2(DEBUG_C_TRACE|DEBUG_C_FLASH, FLASH_I_WRITE, address, datum); +void FlashWrite49( XAddress address, Nibble datum ) +{ + debug2( DEBUG_C_TRACE | DEBUG_C_FLASH, FLASH_I_WRITE, address, datum ); - if(IsOdd(address)) - /* Odd address, invoke FSM; ignore result */ - FSM(FLASH_CYCLE_WRITE, ByteAddress(address), - w_buffer|ShiftHigh(datum)); + if ( IsOdd( address ) ) + /* Odd address, invoke FSM; ignore result */ + FSM( FLASH_CYCLE_WRITE, ByteAddress( address ), w_buffer | ShiftHigh( datum ) ); else - /* Even address, buffer datum */ - w_buffer = datum; - + /* Even address, buffer datum */ + w_buffer = datum; } diff --git a/src/flash49.h b/src/flash49.h index b13c9a9..3068fc6 100644 --- a/src/flash49.h +++ b/src/flash49.h @@ -31,7 +31,6 @@ /* +-+ */ - /* .+ .identifier : $Id: flash49.h,v 4.1 2000/12/11 09:54:19 cibrario Rel $ @@ -72,13 +71,11 @@ .- */ - /*--------------------------------------------------------------------------- - Macro/Data type definitions + Macro/Data type definitions ---------------------------------------------------------------------------*/ -#define FLASH49_RCS_INFO "$Revision: 4.1 $ $State: Rel $" - +#define FLASH49_RCS_INFO "$Revision: 4.1 $ $State: Rel $" /* Command Set Definitions, Table 3 on Data Sheet. Both BCS and SCS commands are listed here; commands marked with @@ -86,79 +83,73 @@ The last fixed byte of multibyte commands has a '_2' suffix. */ -#define FLASH_CMD_READ_ARRAY 0xFF /* BCS */ -#define FLASH_CMD_READ_ID 0x90 /* BCS (*) */ -#define FLASH_CMD_READ_QUERY 0x98 /* SCS (*) */ -#define FLASH_CMD_READ_SR 0x70 /* BCS */ -#define FLASH_CMD_CLR_SR 0x50 /* BCS */ -#define FLASH_CMD_WRITE_BUFFER 0xE8 /* SCS */ -# define FLASH_CMD_WRITE_BUFFER_2 0xD0 -#define FLASH_CMD_BW_PGM 0x40 /* BCS (*) */ -#define FLASH_CMD_BW_PGM_ALT 0x10 /* BCS, alternate (*) */ -#define FLASH_CMD_BL_ERASE 0x20 /* BCS */ -# define FLASH_CMD_BL_ERASE_2 0xD0 -#define FLASH_CMD_SUSPEND 0xB0 /* BCS (*) */ -#define FLASH_CMD_RESUME 0xD0 /* BCS (*) */ -#define FLASH_CMD_STS_CONFIG 0xB8 /* SCS (*) */ -#define FLASH_CMD_BL_LB 0x60 /* SCS (*) */ -# define FLASH_CMD_BL_LB_SET 0x01 -# define FLASH_CMD_BL_LB_CLR 0xD0 -#define FLASH_CMD_CHIP_ERASE 0x30 /* SCS (*) */ -# define FLASH_CMD_CHIP_ERASE_2 0xD0 - +#define FLASH_CMD_READ_ARRAY 0xFF /* BCS */ +#define FLASH_CMD_READ_ID 0x90 /* BCS (*) */ +#define FLASH_CMD_READ_QUERY 0x98 /* SCS (*) */ +#define FLASH_CMD_READ_SR 0x70 /* BCS */ +#define FLASH_CMD_CLR_SR 0x50 /* BCS */ +#define FLASH_CMD_WRITE_BUFFER 0xE8 /* SCS */ +#define FLASH_CMD_WRITE_BUFFER_2 0xD0 +#define FLASH_CMD_BW_PGM 0x40 /* BCS (*) */ +#define FLASH_CMD_BW_PGM_ALT 0x10 /* BCS, alternate (*) */ +#define FLASH_CMD_BL_ERASE 0x20 /* BCS */ +#define FLASH_CMD_BL_ERASE_2 0xD0 +#define FLASH_CMD_SUSPEND 0xB0 /* BCS (*) */ +#define FLASH_CMD_RESUME 0xD0 /* BCS (*) */ +#define FLASH_CMD_STS_CONFIG 0xB8 /* SCS (*) */ +#define FLASH_CMD_BL_LB 0x60 /* SCS (*) */ +#define FLASH_CMD_BL_LB_SET 0x01 +#define FLASH_CMD_BL_LB_CLR 0xD0 +#define FLASH_CMD_CHIP_ERASE 0x30 /* SCS (*) */ +#define FLASH_CMD_CHIP_ERASE_2 0xD0 /* Status Register bit masks, Table 15 on Data Sheet -*/ -#define FLASH_SR_WSMS 0x80 /* WSM state, 0=busy, 1=ready */ -#define FLASH_SR_ESS 0x40 /* Erase suspend, 1=suspended */ -#define FLASH_SR_ECLBS 0x20 /* 1=Error during erasure */ -#define FLASH_SR_BWSLBS 0x10 /* 1=Error during program */ -#define FLASH_SR_VPPS 0x08 /* 1=Vpp error */ -#define FLASH_SR_BWSS 0x04 /* Program suspend, 1=suspended */ -#define FLASH_SR_DPS 0x02 /* 1=Lock encountered */ - - -/* Extended Status Register bit masks, Table 16 on Data Sheet -*/ -#define FLASH_XSR_WBS 0x80 /* Write buffer status 1=available */ + */ +#define FLASH_SR_WSMS 0x80 /* WSM state, 0=busy, 1=ready */ +#define FLASH_SR_ESS 0x40 /* Erase suspend, 1=suspended */ +#define FLASH_SR_ECLBS 0x20 /* 1=Error during erasure */ +#define FLASH_SR_BWSLBS 0x10 /* 1=Error during program */ +#define FLASH_SR_VPPS 0x08 /* 1=Vpp error */ +#define FLASH_SR_BWSS 0x04 /* Program suspend, 1=suspended */ +#define FLASH_SR_DPS 0x02 /* 1=Lock encountered */ +/* Extended Status Register bit masks, Table 16 on Data Sheet + */ +#define FLASH_XSR_WBS 0x80 /* Write buffer status 1=available */ /* State of the Flash FSM, derived from command descriptions on pages 16...28 and from flowcharts on Figure 6...12 of Data Sheet */ -enum FlashState -{ - FLASH_ST_READ_ARRAY = 0, /* Read Array after CMD_READ_ARRAY */ - FLASH_ST_READ_SR, /* Read Status Reg. after CMD_READ_SR */ - FLASH_ST_READ_XSR, /* Read XSR after CMD_WRITE_BUFFER */ - FLASH_ST_WRITE_DATA_1, /* Write data after ST_WRITE_COUNT */ - FLASH_ST_WRITE_DATA_N, /* Write data after first write */ - FLASH_ST_WRITE_CONFIRM, /* Write confirmation after (ST_WRITE_DATA)* */ - FLASH_ST_BL_ERASE, /* Block erase started */ - FLASH_ST_N /* Total # of FSM states */ +enum FlashState { + FLASH_ST_READ_ARRAY = 0, /* Read Array after CMD_READ_ARRAY */ + FLASH_ST_READ_SR, /* Read Status Reg. after CMD_READ_SR */ + FLASH_ST_READ_XSR, /* Read XSR after CMD_WRITE_BUFFER */ + FLASH_ST_WRITE_DATA_1, /* Write data after ST_WRITE_COUNT */ + FLASH_ST_WRITE_DATA_N, /* Write data after first write */ + FLASH_ST_WRITE_CONFIRM, /* Write confirmation after (ST_WRITE_DATA)* */ + FLASH_ST_BL_ERASE, /* Block erase started */ + FLASH_ST_N /* Total # of FSM states */ }; - /*--------------------------------------------------------------------------- Chf condition codes ---------------------------------------------------------------------------*/ -#define FLASH_I_READ 101 /* Read from address %x: %d */ -#define FLASH_I_WRITE 102 /* Write address %x, datum %x */ -#define FLASH_I_FSM 103 /* FSM from state %d, cycle %d */ -#define FLASH_I_FSM_AD 104 /* FSM address %x, data %x */ -#define FLASH_I_FSM_RESULT 105 /* FSM next state %d, result %x */ -#define FLASH_I_FSM_OP 106 /* FSM operation %s */ -#define FLASH_W_BAD_CMD 201 /* Bad cmd st%d, cycle%d, a%x, d%d */ -#define FLASH_W_BAD_ADDRESS 202 /* Bad addr st%d, cycle%d, a%x, d%d */ -#define FLASH_E_xxx 301 -#define FLASH_F_xxx 401 - +#define FLASH_I_READ 101 /* Read from address %x: %d */ +#define FLASH_I_WRITE 102 /* Write address %x, datum %x */ +#define FLASH_I_FSM 103 /* FSM from state %d, cycle %d */ +#define FLASH_I_FSM_AD 104 /* FSM address %x, data %x */ +#define FLASH_I_FSM_RESULT 105 /* FSM next state %d, result %x */ +#define FLASH_I_FSM_OP 106 /* FSM operation %s */ +#define FLASH_W_BAD_CMD 201 /* Bad cmd st%d, cycle%d, a%x, d%d */ +#define FLASH_W_BAD_ADDRESS 202 /* Bad addr st%d, cycle%d, a%x, d%d */ +#define FLASH_E_xxx 301 +#define FLASH_F_xxx 401 /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ /* Read/Write operations, nibble-by-nibble */ -Nibble FlashRead49(XAddress address); -void FlashWrite49(XAddress address, Nibble datum); +Nibble FlashRead49( XAddress address ); +void FlashWrite49( XAddress address, Nibble datum ); diff --git a/src/hdw.c b/src/hdw.c index f928741..1794f77 100644 --- a/src/hdw.c +++ b/src/hdw.c @@ -106,7 +106,7 @@ static char rcs_id[] = "$Id: hdw.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include #include #include -#include /* 3.1: memset() */ +#include /* 3.1: memset() */ #include #include "config.h" @@ -114,22 +114,18 @@ static char rcs_id[] = "$Id: hdw.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "cpu.h" #include "modules.h" #include "disk_io.h" -#include "serial.h" /* 2.5: Serial port emulation module */ -#include "x_func.h" /* 3.13: Extended emulator functions */ +#include "serial.h" /* 2.5: Serial port emulation module */ +#include "x_func.h" /* 3.13: Extended emulator functions */ #include "debug.h" #include "args.h" -#define CHF_MODULE_ID MOD_CHF_MODULE_ID +#define CHF_MODULE_ID MOD_CHF_MODULE_ID #include - static const int addr_mask[] = { 0x0000F, 0x000F0, 0x00F00, 0x0F000, 0xF0000 }; -static const int32 int32_mask[] = -{ 0x0000000F, 0x000000F0, 0x00000F00, 0x0000F000, - 0x000F0000, 0x00F00000, 0x0F000000, 0xF0000000 }; - +static const int32 int32_mask[] = { 0x0000000F, 0x000000F0, 0x00000F00, 0x0000F000, 0x000F0000, 0x00F00000, 0x0F000000, 0xF0000000 }; /* .+ @@ -141,35 +137,32 @@ static const int32 int32_mask[] = peripheral devices associated to it from disk. .call : - HdwInit(); + HdwInit(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_HDW_INIT + MOD_I_CALLED + MOD_W_HDW_INIT .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, bug fix: memset() invocation was improper, and could lead to memory corruption .- */ -void HdwInit(void) +void HdwInit( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "HdwInit"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "HdwInit" ); - if(ReadStructFromFile(args.hdw_file_name, sizeof(mod_status.hdw), - &mod_status.hdw)) - { - ChfCondition MOD_W_HDW_INIT, CHF_WARNING ChfEnd; - ChfSignal(); + if ( ReadStructFromFile( args.hdw_file_name, sizeof( mod_status.hdw ), &mod_status.hdw ) ) { + ChfCondition MOD_W_HDW_INIT, CHF_WARNING ChfEnd; + ChfSignal(); - (void)memset(&mod_status.hdw, 0, sizeof(mod_status.hdw)); - } + ( void )memset( &mod_status.hdw, 0, sizeof( mod_status.hdw ) ); + } } - /* .+ .title : HdwSave @@ -180,31 +173,28 @@ void HdwInit(void) to the Hdw module to disk. .call : - HdwSave(); + HdwSave(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_HDW_SAVE + MOD_I_CALLED + MOD_E_HDW_SAVE .notes : 1.1, 11-Feb-1998, creation .- */ -void HdwSave(void) +void HdwSave( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "HdwSave"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "HdwSave" ); - if(WriteStructToFile(&mod_status.hdw, sizeof(mod_status.hdw), - args.hdw_file_name)) - { - ChfCondition MOD_E_HDW_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); - } + if ( WriteStructToFile( &mod_status.hdw, sizeof( mod_status.hdw ), args.hdw_file_name ) ) { + ChfCondition MOD_E_HDW_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); + } } - /* .+ .title : HdwRead @@ -214,14 +204,14 @@ void HdwSave(void) This function reads a nibble from the Hdw module. .call : - d = HdwRead(rel_address); + d = HdwRead(rel_address); .input : - Address rel_address, relative address + Address rel_address, relative address .output : - Nibble d, data + Nibble d, data .status_codes : - MOD_I_CALLED - MOD_W_HDW_READ + MOD_I_CALLED + MOD_W_HDW_READ .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, update @@ -232,130 +222,127 @@ void HdwSave(void) - added support for serial port emulation .- */ -Nibble HdwRead(Address rel_address) +Nibble HdwRead( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "HdwRead"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "HdwRead" ); - /* In the following switch, each case corresponds to one hdw register. - If the register must be read from the shadow space mod_status.hdw.hdw[], - simply put a break in the case, otherwise code any special action for - the register and end the case with a return. - */ - switch(rel_address) - { - case 0x00: /* LCD driver registers */ - case 0x01: - case 0x02: - case 0x03: - case 0x0B: - case 0x0C: - case 0x25: - case 0x26: - case 0x27: - case 0x28: - case 0x29: - break; - - case 0x04: /* CRC register */ - case 0x05: - case 0x06: - case 0x07: - return (Nibble)((mod_status.hdw.crc >> ((rel_address-0x04)*4)) & 0x0F); - - case 0x08: /* Power status */ - /* No power status related interrupt have occoured */ - return (Nibble)0; - - case 0x09: /* Power control */ - break; - - case 0x0D: /* Serial port baud-rate register */ - break; - - case 0x10: /* Serial port interrupt and I/O control register */ - return Serial_IOC_Read(); - - case 0x11: /* Serial port receiver control/status register */ - return Serial_RCS_Read(); - - case 0x12: /* Serial port transmitter control/status register */ - return Serial_TCS_Read(); - - /* Serial port receiver buffer register; the actual read takes place - when the LS nibble is read; serial_rbr buffers the MS nibble. + /* In the following switch, each case corresponds to one hdw register. + If the register must be read from the shadow space mod_status.hdw.hdw[], + simply put a break in the case, otherwise code any special action for + the register and end the case with a return. */ - case 0x14: - return (mod_status.hdw.serial_rbr = Serial_RBR_Read()) & 0x0F; + switch ( rel_address ) { + case 0x00: /* LCD driver registers */ + case 0x01: + case 0x02: + case 0x03: + case 0x0B: + case 0x0C: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + break; - case 0x15: - return (mod_status.hdw.serial_rbr >> 4) & 0x0F; + case 0x04: /* CRC register */ + case 0x05: + case 0x06: + case 0x07: + return ( Nibble )( ( mod_status.hdw.crc >> ( ( rel_address - 0x04 ) * 4 ) ) & 0x0F ); - case 0x0E: /* Card interface */ - break; + case 0x08: /* Power status */ + /* No power status related interrupt have occoured */ + return ( Nibble )0; - case 0x0F: /* Card interface */ - /* 2.4: Return current card status */ - return mod_status.hdw.card_status; + case 0x09: /* Power control */ + break; - case 0x18: /* Service request */ - case 0x19: - break; + case 0x0D: /* Serial port baud-rate register */ + break; - case 0x1A: /* IR registers */ - case 0x1C: - case 0x1D: - break; + case 0x10: /* Serial port interrupt and I/O control register */ + return Serial_IOC_Read(); - case 0x1B: /* Base nibble offset */ - break; + case 0x11: /* Serial port receiver control/status register */ + return Serial_RCS_Read(); - case 0x1E: /* Scratch pad */ - break; + case 0x12: /* Serial port transmitter control/status register */ + return Serial_TCS_Read(); - case 0x1F: /* Base Nibble */ - break; + /* Serial port receiver buffer register; the actual read takes place + when the LS nibble is read; serial_rbr buffers the MS nibble. + */ + case 0x14: + return ( mod_status.hdw.serial_rbr = Serial_RBR_Read() ) & 0x0F; - case 0x2E: /* Timer 1 Control */ - return mod_status.hdw.t1_ctrl; + case 0x15: + return ( mod_status.hdw.serial_rbr >> 4 ) & 0x0F; - case 0x2F: /* Timer 2 Control */ - return mod_status.hdw.t2_ctrl; + case 0x0E: /* Card interface */ + break; + + case 0x0F: /* Card interface */ + /* 2.4: Return current card status */ + return mod_status.hdw.card_status; + + case 0x18: /* Service request */ + case 0x19: + break; + + case 0x1A: /* IR registers */ + case 0x1C: + case 0x1D: + break; + + case 0x1B: /* Base nibble offset */ + break; + + case 0x1E: /* Scratch pad */ + break; + + case 0x1F: /* Base Nibble */ + break; + + case 0x2E: /* Timer 1 Control */ + return mod_status.hdw.t1_ctrl; + + case 0x2F: /* Timer 2 Control */ + return mod_status.hdw.t2_ctrl; #ifdef HP49_SUPPORT - /* 3.2: The HP49 firmware (1.19-4) reads a nibble from 0x30 */ - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - return (Nibble)0x0; + /* 3.2: The HP49 firmware (1.19-4) reads a nibble from 0x30 */ + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + return ( Nibble )0x0; #endif - case 0x37: /* Timer 1 value */ - return mod_status.hdw.t1_val; + case 0x37: /* Timer 1 value */ + return mod_status.hdw.t1_val; - case 0x38: /* Timer 2 value */ - case 0x39: - case 0x3A: - case 0x3B: - case 0x3C: - case 0x3D: - case 0x3E: - case 0x3F: - return - (Nibble)((mod_status.hdw.t2_val >> ((rel_address-0x38)*4)) & 0x0F); - - default: - ChfCondition MOD_W_HDW_READ, CHF_WARNING, rel_address ChfEnd; - ChfSignal(); - return (Nibble)0xF; - } + case 0x38: /* Timer 2 value */ + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + return ( Nibble )( ( mod_status.hdw.t2_val >> ( ( rel_address - 0x38 ) * 4 ) ) & 0x0F ); - /* Read from hdw register array */ - return mod_status.hdw.hdw[rel_address]; + default: + ChfCondition MOD_W_HDW_READ, CHF_WARNING, rel_address ChfEnd; + ChfSignal(); + return ( Nibble )0xF; + } + + /* Read from hdw register array */ + return mod_status.hdw.hdw[ rel_address ]; } - /* .+ .title : HdwWrite @@ -365,201 +352,198 @@ Nibble HdwRead(Address rel_address) This function writes a nibble to the Hdw module. .call : - HdwWrite(rel_address, data); + HdwWrite(rel_address, data); .input : - Address rel_address, relative address - Nibble data, data to be written + Address rel_address, relative address + Nibble data, data to be written .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_HDW_WRITE + MOD_I_CALLED + MOD_W_HDW_WRITE .notes : 1.1, 23-Jan-1998, creation 2.5, 14-Sep-2000, update - added support for serial port emulation .- */ -void HdwWrite(Address rel_address, Nibble data) +void HdwWrite( Address rel_address, Nibble data ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "HdwWrite"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "HdwWrite" ); - /* This switch has a case for each 'known' hdw register. The code inside the - case performs the actions specific for that register; the code following - the switch, instead, simply takes care to shadow the hdw register into - the mod_status.hdw.hdw[] array - */ - switch(rel_address) - { - case 0x00: /* LCD horizontal offset, LCD enable flag */ - mod_status.hdw.lcd_offset = (int)data & 0x07; - mod_status.hdw.lcd_on = ((data & 0x08) != 0); - break; - - case 0x01: /* LCD contrast, LS nibble */ - mod_status.hdw.lcd_contrast &= 0x10; - mod_status.hdw.lcd_contrast |= (int)data; - break; - - case 0x02: /* LCD contrast, MS bit */ - mod_status.hdw.lcd_contrast &= 0x0F; - mod_status.hdw.lcd_contrast |= (((int)data & 0x01) << 4); - break; - - case 0x03: /* LCD test control */ - break; - - case 0x04: /* CRC register */ - case 0x05: - case 0x06: - case 0x07: - mod_status.hdw.crc &= ~addr_mask[rel_address-0x04]; - mod_status.hdw.crc |= ((int)data << ((rel_address-0x04)*4)); - break; - - case 0x08: /* Power status and power control */ - case 0x09: - break; - - case 0x0B: /* LCD annunciator control (low nibble) */ - mod_status.hdw.lcd_ann &= 0xF0; - mod_status.hdw.lcd_ann |= (int)data; - break; - - case 0x0C: /* LCD annunciator control (high nibble) */ - mod_status.hdw.lcd_ann &= 0x0F; - mod_status.hdw.lcd_ann |= ((int)data << 4); - break; - - case 0x0D: /* Serial port baud rate */ - break; - - case 0x0E: /* Card interface */ - case 0x0F: - break; - - case 0x10: /* Serial port interrupt and I/O control/status */ - Serial_IOC_Write(data); - break; - - case 0x11: /* Serial port receiver control/status register */ - Serial_RCS_Write(data); - break; - - case 0x12: /* Serial port transmitter control/status register */ - Serial_TCS_Write(data); - break; - - case 0x13: /* Clear serial port receive error */ - Serial_CRER_Write(data); - break; - - /* 3.13: A write operation into the receiver buffer register - triggers an extended emulator function. + /* This switch has a case for each 'known' hdw register. The code inside the + case performs the actions specific for that register; the code following + the switch, instead, simply takes care to shadow the hdw register into + the mod_status.hdw.hdw[] array */ - case 0x14: - ExtendedFunction(data); - break; + switch ( rel_address ) { + case 0x00: /* LCD horizontal offset, LCD enable flag */ + mod_status.hdw.lcd_offset = ( int )data & 0x07; + mod_status.hdw.lcd_on = ( ( data & 0x08 ) != 0 ); + break; - /* Serial port transmitter buffer; the actual write takes place - when the MS nibble is written; serial_tbr buffers the LS nibble. - */ - case 0x16: - mod_status.hdw.serial_tbr = - (mod_status.hdw.serial_tbr & 0xF0) | (int8)data; - break; + case 0x01: /* LCD contrast, LS nibble */ + mod_status.hdw.lcd_contrast &= 0x10; + mod_status.hdw.lcd_contrast |= ( int )data; + break; - case 0x17: - mod_status.hdw.serial_tbr = - (mod_status.hdw.serial_tbr & 0x0F) | ((int8)data << 4); - Serial_TBR_Write(mod_status.hdw.serial_tbr); - break; + case 0x02: /* LCD contrast, MS bit */ + mod_status.hdw.lcd_contrast &= 0x0F; + mod_status.hdw.lcd_contrast |= ( ( ( int )data & 0x01 ) << 4 ); + break; - case 0x18: /* Service request */ - case 0x19: - break; + case 0x03: /* LCD test control */ + break; - case 0x1A: /* IR Control Register */ - break; + case 0x04: /* CRC register */ + case 0x05: + case 0x06: + case 0x07: + mod_status.hdw.crc &= ~addr_mask[ rel_address - 0x04 ]; + mod_status.hdw.crc |= ( ( int )data << ( ( rel_address - 0x04 ) * 4 ) ); + break; - case 0x1B: /* Base nibble offset */ - break; + case 0x08: /* Power status and power control */ + case 0x09: + break; - case 0x1C: /* IR Status Register */ - break; + case 0x0B: /* LCD annunciator control (low nibble) */ + mod_status.hdw.lcd_ann &= 0xF0; + mod_status.hdw.lcd_ann |= ( int )data; + break; - case 0x1D: /* IR Led Buffer */ - break; + case 0x0C: /* LCD annunciator control (high nibble) */ + mod_status.hdw.lcd_ann &= 0x0F; + mod_status.hdw.lcd_ann |= ( ( int )data << 4 ); + break; - case 0x1E: /* Scratch Pad */ - break; + case 0x0D: /* Serial port baud rate */ + break; - case 0x1F: /* Base Nibble */ - break; + case 0x0E: /* Card interface */ + case 0x0F: + break; - case 0x20: /* LCD base address register (write only) */ - case 0x21: - case 0x22: - case 0x23: - case 0x24: - mod_status.hdw.lcd_base_addr &= ~addr_mask[rel_address-0x20]; - mod_status.hdw.lcd_base_addr |= ((int)data << ((rel_address-0x20)*4)); - break; + case 0x10: /* Serial port interrupt and I/O control/status */ + Serial_IOC_Write( data ); + break; - case 0x25: /* LCD line offset register */ - case 0x26: - case 0x27: - mod_status.hdw.lcd_line_offset &= ~addr_mask[rel_address-0x25]; - mod_status.hdw.lcd_line_offset |= ((int)data << ((rel_address-0x25)*4)); - break; + case 0x11: /* Serial port receiver control/status register */ + Serial_RCS_Write( data ); + break; - case 0x28: /* LCD vertical line count (low nibble) */ - mod_status.hdw.lcd_vlc &= 0x30; - mod_status.hdw.lcd_vlc |= (int)data; - break; + case 0x12: /* Serial port transmitter control/status register */ + Serial_TCS_Write( data ); + break; - case 0x29: /* LCD vertical line count (higher 2 bits), others (TBD) */ - mod_status.hdw.lcd_vlc &= 0x0F; - mod_status.hdw.lcd_vlc |= (((int)data & 0x03) << 4); + case 0x13: /* Clear serial port receive error */ + Serial_CRER_Write( data ); + break; - case 0x2E: /* Timer 1 Control */ - mod_status.hdw.t1_ctrl = data; - break; + /* 3.13: A write operation into the receiver buffer register + triggers an extended emulator function. + */ + case 0x14: + ExtendedFunction( data ); + break; - case 0x2F: /* Timer 2 Control */ - mod_status.hdw.t2_ctrl = data; - break; + /* Serial port transmitter buffer; the actual write takes place + when the MS nibble is written; serial_tbr buffers the LS nibble. + */ + case 0x16: + mod_status.hdw.serial_tbr = ( mod_status.hdw.serial_tbr & 0xF0 ) | ( int8 )data; + break; - case 0x30: /* LCD menu address register (write only) */ - case 0x31: - case 0x32: - case 0x33: - case 0x34: - mod_status.hdw.lcd_menu_addr &= ~addr_mask[rel_address-0x30]; - mod_status.hdw.lcd_menu_addr |= ((int)data << ((rel_address-0x30)*4)); - break; + case 0x17: + mod_status.hdw.serial_tbr = ( mod_status.hdw.serial_tbr & 0x0F ) | ( ( int8 )data << 4 ); + Serial_TBR_Write( mod_status.hdw.serial_tbr ); + break; - case 0x37: /* Timer 1 value */ - mod_status.hdw.t1_val = data; - break; + case 0x18: /* Service request */ + case 0x19: + break; - case 0x38: /* Timer 2 value */ - case 0x39: - case 0x3A: - case 0x3B: - case 0x3C: - case 0x3D: - case 0x3E: - case 0x3F: - mod_status.hdw.t2_val &= ~int32_mask[rel_address-0x38]; - mod_status.hdw.t2_val |= ((int32)data << ((rel_address-0x38)*4)); - break; + case 0x1A: /* IR Control Register */ + break; - default: - ChfCondition MOD_W_HDW_WRITE, CHF_WARNING, rel_address, (int)data ChfEnd; - ChfSignal(); - } + case 0x1B: /* Base nibble offset */ + break; - /* Save copy into hdw register array */ - mod_status.hdw.hdw[rel_address] = data; + case 0x1C: /* IR Status Register */ + break; + + case 0x1D: /* IR Led Buffer */ + break; + + case 0x1E: /* Scratch Pad */ + break; + + case 0x1F: /* Base Nibble */ + break; + + case 0x20: /* LCD base address register (write only) */ + case 0x21: + case 0x22: + case 0x23: + case 0x24: + mod_status.hdw.lcd_base_addr &= ~addr_mask[ rel_address - 0x20 ]; + mod_status.hdw.lcd_base_addr |= ( ( int )data << ( ( rel_address - 0x20 ) * 4 ) ); + break; + + case 0x25: /* LCD line offset register */ + case 0x26: + case 0x27: + mod_status.hdw.lcd_line_offset &= ~addr_mask[ rel_address - 0x25 ]; + mod_status.hdw.lcd_line_offset |= ( ( int )data << ( ( rel_address - 0x25 ) * 4 ) ); + break; + + case 0x28: /* LCD vertical line count (low nibble) */ + mod_status.hdw.lcd_vlc &= 0x30; + mod_status.hdw.lcd_vlc |= ( int )data; + break; + + case 0x29: /* LCD vertical line count (higher 2 bits), others (TBD) */ + mod_status.hdw.lcd_vlc &= 0x0F; + mod_status.hdw.lcd_vlc |= ( ( ( int )data & 0x03 ) << 4 ); + + case 0x2E: /* Timer 1 Control */ + mod_status.hdw.t1_ctrl = data; + break; + + case 0x2F: /* Timer 2 Control */ + mod_status.hdw.t2_ctrl = data; + break; + + case 0x30: /* LCD menu address register (write only) */ + case 0x31: + case 0x32: + case 0x33: + case 0x34: + mod_status.hdw.lcd_menu_addr &= ~addr_mask[ rel_address - 0x30 ]; + mod_status.hdw.lcd_menu_addr |= ( ( int )data << ( ( rel_address - 0x30 ) * 4 ) ); + break; + + case 0x37: /* Timer 1 value */ + mod_status.hdw.t1_val = data; + break; + + case 0x38: /* Timer 2 value */ + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + mod_status.hdw.t2_val &= ~int32_mask[ rel_address - 0x38 ]; + mod_status.hdw.t2_val |= ( ( int32 )data << ( ( rel_address - 0x38 ) * 4 ) ); + break; + + default: + ChfCondition MOD_W_HDW_WRITE, CHF_WARNING, rel_address, ( int )data ChfEnd; + ChfSignal(); + } + + /* Save copy into hdw register array */ + mod_status.hdw.hdw[ rel_address ] = data; } diff --git a/src/hw_config.c b/src/hw_config.c index f5d3e14..a915258 100644 --- a/src/hw_config.c +++ b/src/hw_config.c @@ -87,194 +87,257 @@ static char rcs_id[] = "$Id: hw_config.c,v 4.1 2000/12/11 09:54:19 cibrario Rel #include "modules.h" #include "debug.h" -#define CHF_MODULE_ID MOD_CHF_MODULE_ID +#define CHF_MODULE_ID MOD_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Module description tables + Module description tables ---------------------------------------------------------------------------*/ -extern void RomInit(void); -extern void HdwInit(void); -extern void RamInit(void); -extern void Ce1Init(void); -extern void Ce2Init(void); -extern void NCe3Init(void); +extern void RomInit( void ); +extern void HdwInit( void ); +extern void RamInit( void ); +extern void Ce1Init( void ); +extern void Ce2Init( void ); +extern void NCe3Init( void ); -extern void RomSave(void); -extern void HdwSave(void); -extern void RamSave(void); -extern void Ce1Save(void); -extern void Ce2Save(void); -extern void NCe3Save(void); +extern void RomSave( void ); +extern void HdwSave( void ); +extern void RamSave( void ); +extern void Ce1Save( void ); +extern void Ce2Save( void ); +extern void NCe3Save( void ); -extern Nibble RomRead(Address); -extern Nibble HdwRead(Address); -extern Nibble RamRead(Address); -extern Nibble Ce1Read(Address); -extern Nibble Ce2Read(Address); -extern Nibble NCe3Read(Address); +extern Nibble RomRead( Address ); +extern Nibble HdwRead( Address ); +extern Nibble RamRead( Address ); +extern Nibble Ce1Read( Address ); +extern Nibble Ce2Read( Address ); +extern Nibble NCe3Read( Address ); -extern void RomWrite(Address, Nibble); -extern void HdwWrite(Address, Nibble); -extern void RamWrite(Address, Nibble); -extern void Ce1Write(Address, Nibble); -extern void Ce2Write(Address, Nibble); -extern void NCe3Write(Address, Nibble); +extern void RomWrite( Address, Nibble ); +extern void HdwWrite( Address, Nibble ); +extern void RamWrite( Address, Nibble ); +extern void Ce1Write( Address, Nibble ); +extern void Ce2Write( Address, Nibble ); +extern void NCe3Write( Address, Nibble ); -extern void RomInit49(void); -extern void HdwInit49(void); -extern void RamInit49(void); -extern void Ce1Init49(void); -extern void Ce2Init49(void); -extern void NCe3Init49(void); +extern void RomInit49( void ); +extern void HdwInit49( void ); +extern void RamInit49( void ); +extern void Ce1Init49( void ); +extern void Ce2Init49( void ); +extern void NCe3Init49( void ); -extern void RomSave49(void); -extern void HdwSave49(void); -extern void RamSave49(void); -extern void Ce1Save49(void); -extern void Ce2Save49(void); -extern void NCe3Save49(void); +extern void RomSave49( void ); +extern void HdwSave49( void ); +extern void RamSave49( void ); +extern void Ce1Save49( void ); +extern void Ce2Save49( void ); +extern void NCe3Save49( void ); -extern Nibble RomRead49(Address); -extern Nibble HdwRead49(Address); -extern Nibble RamRead49(Address); -extern Nibble Ce1Read49(Address); -extern Nibble Ce2Read49(Address); -extern Nibble NCe3Read49(Address); +extern Nibble RomRead49( Address ); +extern Nibble HdwRead49( Address ); +extern Nibble RamRead49( Address ); +extern Nibble Ce1Read49( Address ); +extern Nibble Ce2Read49( Address ); +extern Nibble NCe3Read49( Address ); -extern void RomWrite49(Address, Nibble); -extern void HdwWrite49(Address, Nibble); -extern void RamWrite49(Address, Nibble); -extern void Ce1Write49(Address, Nibble); -extern void Ce2Write49(Address, Nibble); -extern void NCe3Write49(Address, Nibble); +extern void RomWrite49( Address, Nibble ); +extern void HdwWrite49( Address, Nibble ); +extern void RamWrite49( Address, Nibble ); +extern void Ce1Write49( Address, Nibble ); +extern void Ce2Write49( Address, Nibble ); +extern void NCe3Write49( Address, Nibble ); -static const struct -{ - const char *hw; +static const struct { + const char* hw; ModDescription description; } table[] = -{ - -/*--------------------------------------------------------------------------- - HP48 - ---------------------------------------------------------------------------*/ - { - "hp48", - { - /* name, id, access_prio, - init, save, - read, write, - r_config, r_abs_base_addr, r_size, - map_flags - */ + /*--------------------------------------------------------------------------- + HP48 + ---------------------------------------------------------------------------*/ - { "ROM (ROM)", 0x00, 0, - RomInit, RomSave, - RomRead, RomWrite, - MOD_CONFIGURED, 0x00000, 0xFFFFF, - }, + {"hp48", - { "Hardware Regs. (HDW)", 0x19, 5, - HdwInit, HdwSave, - HdwRead, HdwWrite, - MOD_SIZE_CONFIGURED, 0x00000, 0x00040, - }, + { /* name, id, access_prio, + init, save, + read, write, + r_config, r_abs_base_addr, r_size, + map_flags + */ - { "Internal RAM (RAM)", 0x03, 4, - RamInit, RamSave, - RamRead, RamWrite, - MOD_UNCONFIGURED, 0, 0, - }, + { + "ROM (ROM)", + 0x00, + 0, + RomInit, + RomSave, + RomRead, + RomWrite, + MOD_CONFIGURED, + 0x00000, + 0xFFFFF, + }, - { "Bank Select (CE1)", 0x05, 2, - Ce1Init, Ce1Save, - Ce1Read, Ce1Write, - MOD_UNCONFIGURED, 0, 0, - }, + { + "Hardware Regs. (HDW)", + 0x19, + 5, + HdwInit, + HdwSave, + HdwRead, + HdwWrite, + MOD_SIZE_CONFIGURED, + 0x00000, + 0x00040, + }, - { "Port 1 Control (CE2)", 0x07, 3, - Ce2Init, Ce2Save, - Ce2Read, Ce2Write, - MOD_UNCONFIGURED, 0, 0, - }, + { + "Internal RAM (RAM)", + 0x03, + 4, + RamInit, + RamSave, + RamRead, + RamWrite, + MOD_UNCONFIGURED, + 0, + 0, + }, - { "Port 2 Control (NCE3)", 0x01, 1, - NCe3Init, NCe3Save, - NCe3Read, NCe3Write, - MOD_UNCONFIGURED, 0, 0, - } - }}, + { + "Bank Select (CE1)", + 0x05, + 2, + Ce1Init, + Ce1Save, + Ce1Read, + Ce1Write, + MOD_UNCONFIGURED, + 0, + 0, + }, -/*--------------------------------------------------------------------------- - HP49 - ---------------------------------------------------------------------------*/ + { + "Port 1 Control (CE2)", + 0x07, + 3, + Ce2Init, + Ce2Save, + Ce2Read, + Ce2Write, + MOD_UNCONFIGURED, + 0, + 0, + }, - { - "hp49", + { + "Port 2 Control (NCE3)", + 0x01, + 1, + NCe3Init, + NCe3Save, + NCe3Read, + NCe3Write, + MOD_UNCONFIGURED, + 0, + 0, + } } }, - { - /* name, id, access_prio, - init, save, - read, write, - r_config, r_abs_base_addr, r_size, - map_flags - */ + /*--------------------------------------------------------------------------- + HP49 + ---------------------------------------------------------------------------*/ - { "ROM (ROM)", 0x00, 0, - RomInit49, RomSave49, - RomRead49, RomWrite49, - MOD_CONFIGURED, 0x00000, 0xFFFFF, - }, + {"hp49", - { "Hardware Regs. (HDW)", 0x19, 5, - HdwInit, HdwSave, - HdwRead, HdwWrite, - MOD_SIZE_CONFIGURED, 0x00000, 0x00040, - }, + { /* name, id, access_prio, + init, save, + read, write, + r_config, r_abs_base_addr, r_size, + map_flags + */ - { "IRAM (RAM)", 0x03, 4, - RamInit49, RamSave49, - RamRead49, RamWrite49, - MOD_UNCONFIGURED, 0, 0, - }, + { + "ROM (ROM)", + 0x00, + 0, + RomInit49, + RomSave49, + RomRead49, + RomWrite49, + MOD_CONFIGURED, + 0x00000, + 0xFFFFF, + }, - { "Bank Select (CE1)", 0x05, 2, - Ce1Init49, Ce1Save49, - Ce1Read49, Ce1Write49, - MOD_UNCONFIGURED, 0, 0, - }, + { + "Hardware Regs. (HDW)", + 0x19, + 5, + HdwInit, + HdwSave, + HdwRead, + HdwWrite, + MOD_SIZE_CONFIGURED, + 0x00000, + 0x00040, + }, - { "ERAM Bank 0 (CE2)", 0x07, 3, - Ce2Init49, Ce2Save49, - Ce2Read49, Ce2Write49, - MOD_UNCONFIGURED, 0, 0, - }, + { + "IRAM (RAM)", + 0x03, + 4, + RamInit49, + RamSave49, + RamRead49, + RamWrite49, + MOD_UNCONFIGURED, + 0, + 0, + }, - { "ERAM Bank 1 (NCE3)", 0x01, 1, - NCe3Init49, NCe3Save49, - NCe3Read49, NCe3Write49, - MOD_UNCONFIGURED, 0, 0, - MOD_MAP_FLAGS_ABS - } - }} + { + "Bank Select (CE1)", + 0x05, + 2, + Ce1Init49, + Ce1Save49, + Ce1Read49, + Ce1Write49, + MOD_UNCONFIGURED, + 0, + 0, + }, + + { + "ERAM Bank 0 (CE2)", + 0x07, + 3, + Ce2Init49, + Ce2Save49, + Ce2Read49, + Ce2Write49, + MOD_UNCONFIGURED, + 0, + 0, + }, + + { "ERAM Bank 1 (NCE3)", 0x01, 1, NCe3Init49, NCe3Save49, NCe3Read49, NCe3Write49, MOD_UNCONFIGURED, 0, 0, + MOD_MAP_FLAGS_ABS } }} }; -#define N_DESCRIPTIONS (sizeof(table)/sizeof(table[0])) - +#define N_DESCRIPTIONS ( sizeof( table ) / sizeof( table[ 0 ] ) ) /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : ModSelectDescription @@ -286,32 +349,32 @@ table[] = string passed as argument. .call : - ModSelectDescription(hw) + ModSelectDescription(hw) .input : - const char *hw, hardware configuration string + const char *hw, hardware configuration string .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_NO_MATCH + MOD_I_CALLED + MOD_E_NO_MATCH .notes : 1.1, 28-Jan-1998, creation .- */ -void ModSelectDescription(const char *hw) +void ModSelectDescription( const char* hw ) { int i; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ModSelectDescription"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModSelectDescription" ); - for(i=0; i -#define OUT_BITS 12 +#define OUT_BITS 12 /* cur_in: This array contains the current value the CPU IN register will assume for each bit set in the OUT register. */ -static InputRegister cur_in[OUT_BITS]; - +static InputRegister cur_in[ OUT_BITS ]; /* .+ @@ -121,29 +120,27 @@ static InputRegister cur_in[OUT_BITS]; interrupt request if any key is pressed. NOTE: This function currently (r1.1) always posts an IRQ request; perhaps, - if the ON key is down, a NMI request should be posted instead. + if the ON key is down, a NMI request should be posted instead. .call : - KeybRSI(); + KeybRSI(); .input : - void + void .output : - void + void .status_codes : - * + * .notes : 1.1, 17-Feb-1998, creation .- */ -void KeybRSI(void) +void KeybRSI( void ) { - /* Post an IRQ if the IN register is not zero */ + /* Post an IRQ if the IN register is not zero */ - CpuIntRequest(KeybIN((OutputRegister)0x1FF) != (InputRegister)0 ? - INT_REQUEST_IRQ : INT_REQUEST_NONE); + CpuIntRequest( KeybIN( ( OutputRegister )0x1FF ) != ( InputRegister )0 ? INT_REQUEST_IRQ : INT_REQUEST_NONE ); } - /* .+ .title : KeybIn @@ -155,36 +152,35 @@ void KeybRSI(void) value of the IN register for the given value of the OUT reguster. .call : - in = KeybIN(out); + in = KeybIN(out); .input : - OutputRegister out, current value of the OUT register + OutputRegister out, current value of the OUT register .output : - InputRegister in, computed value of the IN register + InputRegister in, computed value of the IN register .status_codes : - * + * .notes : 1.1, 17-Feb-1998, creation .- */ -InputRegister KeybIN(OutputRegister out) +InputRegister KeybIN( OutputRegister out ) { - /* Compute the current value of the IN register */ - InputRegister in = (InputRegister)0; - int bit; + /* Compute the current value of the IN register */ + InputRegister in = ( InputRegister )0; + int bit; - /* For each bit set in the 'out' register, OR the corresponding IN register - value into 'in' - */ - for(bit=0; bit>= 1; - } + /* For each bit set in the 'out' register, OR the corresponding IN register + value into 'in' + */ + for ( bit = 0; bit < OUT_BITS; bit++ ) { + if ( out & 0x01 ) + in |= cur_in[ bit ]; + out >>= 1; + } - return in; + return in; } - /* .+ .title : KeybPress @@ -196,63 +192,57 @@ InputRegister KeybIN(OutputRegister out) necessary, posts an interrupt request to the CPU. .call : - KeybPress(key); + KeybPress(key); .input : - const char *key, identifies the key that has been pressed. + const char *key, identifies the key that has been pressed. .output : - void + void .status_codes : - MOD_W_BAD_KEY - MOD_W_BAD_OUT_BIT + MOD_W_BAD_KEY + MOD_W_BAD_OUT_BIT .notes : 1.1, 17-Feb-1998, creation 2.1, 6-Sep-2000, deeply revised to accomodate the new GUI .- */ -void KeybPress(const char *key) +void KeybPress( const char* key ) { - if(strcmp(key, "*") == 0) - { - /* This is the ON key */ - int i; + if ( strcmp( key, "*" ) == 0 ) { + /* This is the ON key */ + int i; - /* Set all 0x8000 lines */ - for(i=0; i= OUT_BITS) - { - ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd; - ChfSignal(); - } + else if ( out_bit < 0 || out_bit >= OUT_BITS ) { + ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd; + ChfSignal(); + } - else - { - /* Update the cur_in array */ - cur_in[out_bit] |= in_val; + else { + /* Update the cur_in array */ + cur_in[ out_bit ] |= in_val; - /* Post an interrupt request to the CPU */ - CpuIntRequest(INT_REQUEST_NMI); - - } + /* Post an interrupt request to the CPU */ + CpuIntRequest( INT_REQUEST_NMI ); + } } } - /* .+ .title : KeybRelease @@ -263,56 +253,51 @@ void KeybPress(const char *key) released. It updates the internal keyboard status information. .call : - KeybRelease(key); + KeybRelease(key); .input : - const char *key, identifies the key that has been released. + const char *key, identifies the key that has been released. .output : - void + void .status_codes : - MOD_W_BAD_KEY - MOD_W_BAD_OUT_BIT + MOD_W_BAD_KEY + MOD_W_BAD_OUT_BIT .notes : 1.1, 17-Feb-1998, creation 2.1, 6-Sep-2000, deeply revised to accomodate the new GUI .- */ -void KeybRelease(const char *key) +void KeybRelease( const char* key ) { - if(strcmp(key, "*") == 0) - { - /* This is the ON key */ - int i; + if ( strcmp( key, "*" ) == 0 ) { + /* This is the ON key */ + int i; - /* Reset all 0x8000 lines */ - for(i=0; i= OUT_BITS) - { - ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd; - ChfSignal(); - } + else if ( out_bit < 0 || out_bit >= OUT_BITS ) { + ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd; + ChfSignal(); + } - else - { - /* Update the cur_in array */ - cur_in[out_bit] &= ~in_val; - } + else { + /* Update the cur_in array */ + cur_in[ out_bit ] &= ~in_val; + } } } - /* .+ .title : KeybReset @@ -322,20 +307,21 @@ void KeybRelease(const char *key) This function resets the emulated keyboard; all keys are released. .call : - KeybReset(); + KeybReset(); .input : - void + void .output : - void + void .status_codes : .notes : 3.13, 7-Nov-2000, creation .- */ -void KeybReset(void) +void KeybReset( void ) { int i; /* Reset all 0x8000 lines */ - for(i=0; inext -#define ChfGetModuleId(d) (d)->module_id -#define ChfGetConditionCode(d) (d)->condition_code -#define ChfGetSeverity(d) (d)->severity -#define ChfGetLineNumber(d) (d)->line_number -#define ChfGetFileName(d) (d)->file_name -#define ChfGetPartialMessage(d) (d)->message - - +#define ChfGetNextDescriptor( d ) ( d )->next +#define ChfGetModuleId( d ) ( d )->module_id +#define ChfGetConditionCode( d ) ( d )->condition_code +#define ChfGetSeverity( d ) ( d )->severity +#define ChfGetLineNumber( d ) ( d )->line_number +#define ChfGetFileName( d ) ( d )->file_name +#define ChfGetPartialMessage( d ) ( d )->message /* ------------------------------------------------------------------------- Function prototypes ------------------------------------------------------------------------- */ -int ChfInit( /* Generic initialization */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - void *mrs_data, /* Message retrieval private data */ - ChfMrsGet mrs_get, /* 'GetMessage' function */ - ChfMrsExit mrs_exit, /* 'Exit' function */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfInit( /* Generic initialization */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + void* mrs_data, /* Message retrieval private data */ + ChfMrsGet mrs_get, /* 'GetMessage' function */ + ChfMrsExit mrs_exit, /* 'Exit' function */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ); -int ChfMsgcatInit( /* Initialization with msgcat subsystem */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - const ChfChar *msgcat_name, /* Name of the message catalog */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfMsgcatInit( /* Initialization with msgcat subsystem */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + const ChfChar* msgcat_name, /* Name of the message catalog */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ); -int ChfStaticInit( /* Initialization with static message tables */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - const ChfTable *table, /* Static message table */ - const size_t table_size, /* Size of the message table */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfStaticInit( /* Initialization with static message tables */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + const ChfTable* table, /* Static message table */ + const size_t table_size, /* Size of the message table */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ); -int ChfWin32Init( /* Initialization within _WIN32 */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ +int ChfWin32Init( /* Initialization within _WIN32 */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ #ifndef _WIN32 - void *instance, /* Fake arguments */ + void* instance, /* Fake arguments */ #else - HINSTANCE instance, /* App. instance handle */ + HINSTANCE instance, /* App. instance handle */ #endif - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ); -void ChfExit( /* Exit */ - void +void ChfExit( /* Exit */ + void ); + +void ChfAbort( /* Abort application */ + const int abort_code ); + +void ChfPushHandler( /* Push a new handler into the stack */ + ChfHandler new_handler, /* Handler to be added */ + void* unwind_context, /* Unwind context */ + ChfPointer handler_context /* Private handler context */ ); -void ChfAbort( /* Abort application */ - const int abort_code -); +void ChfPopHandler( /* Pop a handler */ + void ); -void ChfPushHandler( /* Push a new handler into the stack */ - ChfHandler new_handler, /* Handler to be added */ - void *unwind_context, /* Unwind context */ - ChfPointer handler_context /* Private handler context */ -); +ChfChar* ChfBuildMessage( /* Build a condition message */ + const ChfDescriptor* descriptor ); -void ChfPopHandler( /* Pop a handler */ - void -); +void ChfSignal( /* Signal the current conditions */ + void ); -ChfChar *ChfBuildMessage( /* Build a condition message */ - const ChfDescriptor *descriptor -); +void ChfDiscard( /* Discard the current conditions */ + void ); -void ChfSignal( /* Signal the current conditions */ - void -); +void ChfGenerate( /* Generate a condition into the stack */ + const int module_id, const ChfChar* file_name, const int line_number, const int condition_code, + const ChfSeverity severity, ... ); -void ChfDiscard( /* Discard the current conditions */ - void -); +const ChfChar* ChfGetMessage( /* Retrieve a condition message */ + const int module_id, const int condition_code, const ChfChar* default_message ); -void ChfGenerate( /* Generate a condition into the stack */ - const int module_id, - const ChfChar *file_name, - const int line_number, - const int condition_code, - const ChfSeverity severity, - ... -); - -const ChfChar *ChfGetMessage( /* Retrieve a condition message */ - const int module_id, - const int condition_code, - const ChfChar *default_message -); - -const ChfDescriptor *ChfGetTopCondition( /* Retrieve top condition */ - void -); +const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */ + void ); diff --git a/src/libChf/ChfPriv.h b/src/libChf/ChfPriv.h index 11df1ce..5e119d6 100644 --- a/src/libChf/ChfPriv.h +++ b/src/libChf/ChfPriv.h @@ -37,119 +37,110 @@ .- */ - /* ------------------------------------------------------------------------- Macros ------------------------------------------------------------------------- */ -#define CHF_MODULE_ID CHF_SET -#define CHF_TMP_MESSAGE_LENGTH (2*CHF_MAX_MESSAGE_LENGTH) -#define CHF_DEF_MESSAGE_LENGTH 40 -#define CHF_DEF_PARTIAL_MSG_FMT ChfText("Code <%d>d") -#define CHF_DEF_MID_MSG_FMT ChfText("Mid <%d>d") -#define CHF_EXTENDED_INFO_FMT ChfText("(%s,%d)") -#define CHF_SEVERITY_NAMES \ -{ ChfText("S"), ChfText("I"), ChfText("W"), ChfText("E"), ChfText("F") } -#define CHF_UNKNOWN_SEVERITY ChfText("?") -#define CHF_MESSAGE_SEPARATOR ChfText("-") -#define CHF_MESSAGE_TERMINATOR ChfText("\n") -#define CHF_ABORT_HEADER ChfText("ChfAbort-F-") -#define CHF_ABORT_BAD_CODE_FMT ChfText("Bad abort code <%d>d\n") -#define CHF_ABORT_GOOD_CODE_FMT ChfText("%s\n") - +#define CHF_MODULE_ID CHF_SET +#define CHF_TMP_MESSAGE_LENGTH ( 2 * CHF_MAX_MESSAGE_LENGTH ) +#define CHF_DEF_MESSAGE_LENGTH 40 +#define CHF_DEF_PARTIAL_MSG_FMT ChfText( "Code <%d>d" ) +#define CHF_DEF_MID_MSG_FMT ChfText( "Mid <%d>d" ) +#define CHF_EXTENDED_INFO_FMT ChfText( "(%s,%d)" ) +#define CHF_SEVERITY_NAMES \ + { \ + ChfText( "S" ), ChfText( "I" ), ChfText( "W" ), ChfText( "E" ), ChfText( "F" ) \ + } +#define CHF_UNKNOWN_SEVERITY ChfText( "?" ) +#define CHF_MESSAGE_SEPARATOR ChfText( "-" ) +#define CHF_MESSAGE_TERMINATOR ChfText( "\n" ) +#define CHF_ABORT_HEADER ChfText( "ChfAbort-F-" ) +#define CHF_ABORT_BAD_CODE_FMT ChfText( "Bad abort code <%d>d\n" ) +#define CHF_ABORT_GOOD_CODE_FMT ChfText( "%s\n" ) /* ------------------------------------------------------------------------- - Abort codes used with ChfAbort() + Abort codes used with ChfAbort() ------------------------------------------------------------------------- */ -#define CHF_ABORT_SILENT 0 -#define CHF_ABORT_INIT 1 -#define CHF_ABORT_MSG_OVF 2 -#define CHF_ABORT_INVALID_ACTION 3 -#define CHF_ABORT_DUP_INIT 4 -#define CHF_ABORT_ALREADY_UNWINDING 5 -#define CHF_ABORT_IMPROPERLY_HANDLED 6 -#define CHF_ABORT_FATAL_UNWINDING 7 -#define CHF_ABORT_COND_STACK_OVF 8 -#define CHF_ABORT_GET_CONTEXT 9 -#define CHF_ABORT_PTHREAD 10 - - +#define CHF_ABORT_SILENT 0 +#define CHF_ABORT_INIT 1 +#define CHF_ABORT_MSG_OVF 2 +#define CHF_ABORT_INVALID_ACTION 3 +#define CHF_ABORT_DUP_INIT 4 +#define CHF_ABORT_ALREADY_UNWINDING 5 +#define CHF_ABORT_IMPROPERLY_HANDLED 6 +#define CHF_ABORT_FATAL_UNWINDING 7 +#define CHF_ABORT_COND_STACK_OVF 8 +#define CHF_ABORT_GET_CONTEXT 9 +#define CHF_ABORT_PTHREAD 10 /* ------------------------------------------------------------------------- Type definitions ------------------------------------------------------------------------- */ -typedef struct ChfHandlerDescriptor_S -{ - ChfHandler handler; - void *unwind_context; - ChfPointer handler_context; -} - ChfHandlerDescriptor; +typedef struct ChfHandlerDescriptor_S { + ChfHandler handler; + void* unwind_context; + ChfPointer handler_context; +} ChfHandlerDescriptor; -typedef struct ChfContext_S /* CHF Context */ +typedef struct ChfContext_S /* CHF Context */ { - ChfState state; /* Current CHF state */ - const ChfChar *app_name; /* Application's name */ - ChfOptions options; /* Options */ - void *mrs_data; /* Message retrieval private data */ - ChfMrsGet mrs_get; /* 'GetMessage' function */ - ChfMrsExit mrs_exit; /* 'Exit' function */ - int condition_stack_size; /* Size of the condition stack */ - int handler_stack_size; /* Size of the handler stack */ - int exit_code; /* Abnormal exit code */ - ChfDescriptor *condition_stack; /* Condition stack */ - ChfDescriptor *condition_base; /* Current condition stack base */ - ChfDescriptor *condition_sp; /* Current condition stack pointer */ - ChfHandlerDescriptor *handler_stack; /* Handler stack */ - ChfHandlerDescriptor *handler_sp; /* Current handler stack pointer */ - ChfChar *message_buffer; /* Message buffer */ -} - ChfContext; - + ChfState state; /* Current CHF state */ + const ChfChar* app_name; /* Application's name */ + ChfOptions options; /* Options */ + void* mrs_data; /* Message retrieval private data */ + ChfMrsGet mrs_get; /* 'GetMessage' function */ + ChfMrsExit mrs_exit; /* 'Exit' function */ + int condition_stack_size; /* Size of the condition stack */ + int handler_stack_size; /* Size of the handler stack */ + int exit_code; /* Abnormal exit code */ + ChfDescriptor* condition_stack; /* Condition stack */ + ChfDescriptor* condition_base; /* Current condition stack base */ + ChfDescriptor* condition_sp; /* Current condition stack pointer */ + ChfHandlerDescriptor* handler_stack; /* Handler stack */ + ChfHandlerDescriptor* handler_sp; /* Current handler stack pointer */ + ChfChar* message_buffer; /* Message buffer */ +} ChfContext; /* ------------------------------------------------------------------------- Multithreading support ------------------------------------------------------------------------- */ #ifdef _REENTRANT -#define chf_context (*_ChfGetContext()) +# define chf_context ( *_ChfGetContext() ) #else -#define chf_context _chf_context +# define chf_context _chf_context #endif - /* ------------------------------------------------------------------------- Global variables ------------------------------------------------------------------------- */ -extern ChfContext _chf_context; /* CHF Context */ - +extern ChfContext _chf_context; /* CHF Context */ /* ------------------------------------------------------------------------- Private function prototypes ------------------------------------------------------------------------- */ #ifdef _REENTRANT -ChfContext *_ChfGetContext(void); +ChfContext* _ChfGetContext( void ); #endif - /* ------------------------------------------------------------------------- Private redirection of stdlib functions needed by Win32 ------------------------------------------------------------------------- */ #ifdef _WIN32 -#define ChfStrlen _tcslen -#define ChfStrcpy _tcscpy -#define ChfStrcat _tcscat -#define ChfStrncpy _tcsncpy -#define ChfSprintf _stprintf -#define ChfVsprintf _vstprintf +# define ChfStrlen _tcslen +# define ChfStrcpy _tcscpy +# define ChfStrcat _tcscat +# define ChfStrncpy _tcsncpy +# define ChfSprintf _stprintf +# define ChfVsprintf _vstprintf #else -#define ChfStrlen strlen -#define ChfStrcpy strcpy -#define ChfStrcat strcat -#define ChfStrncpy strncpy -#define ChfSprintf sprintf -#define ChfVsprintf vsprintf +# define ChfStrlen strlen +# define ChfStrcpy strcpy +# define ChfStrcat strcat +# define ChfStrncpy strncpy +# define ChfSprintf sprintf +# define ChfVsprintf vsprintf #endif diff --git a/src/libChf/chf_abrt.c b/src/libChf/chf_abrt.c index ce1993c..0b18690 100644 --- a/src/libChf/chf_abrt.c +++ b/src/libChf/chf_abrt.c @@ -37,43 +37,38 @@ static char rcs_id[] = "$Id: chf_abrt.c,v 2.2 2001/01/25 12:08:24 cibrario Exp $ #include #include #ifndef _WIN32 -#include +# include #endif #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" #ifdef _REENTRANT -#include +# include #endif - /* Abort codes message table; the relative position of the messages must match the numeric codes CHF_ABORT_xxxx defined in ChfPriv.h */ -static const ChfChar *message_table[] = -{ - (const ChfChar *)NULL, - ChfText("Not initialized"), - ChfText("Temporary message buffer overflow"), - ChfText("Invalid action from last chance handler"), - ChfText("Already initialized"), - ChfText("Unwind request while unwinding"), - ChfText("Improperly handled condition"), - ChfText("Fatal condition while unwinding"), - ChfText("Condition stack overflow"), - ChfText("Can't prime a new Chf context"), - ChfText("Pthread interaction failed") -}; - -#define MESSAGE_TABLE_SIZE (sizeof(message_table)/sizeof(const ChfChar *)) +static const ChfChar* message_table[] = { ( const ChfChar* )NULL, + ChfText( "Not initialized" ), + ChfText( "Temporary message buffer overflow" ), + ChfText( "Invalid action from last chance handler" ), + ChfText( "Already initialized" ), + ChfText( "Unwind request while unwinding" ), + ChfText( "Improperly handled condition" ), + ChfText( "Fatal condition while unwinding" ), + ChfText( "Condition stack overflow" ), + ChfText( "Can't prime a new Chf context" ), + ChfText( "Pthread interaction failed" ) }; +#define MESSAGE_TABLE_SIZE ( sizeof( message_table ) / sizeof( const ChfChar* ) ) /* .+ @@ -96,7 +91,7 @@ static const ChfChar *message_table[] = application when a CHF_FATAL condition occours. NOTE: This function must be called only when either a serious internal CHF - failure occurs or it's necessary to abort the application. + failure occurs or it's necessary to abort the application. WIN32: @@ -107,13 +102,13 @@ static const ChfChar *message_table[] = - abort() is not supported and has been replaced by exit(EXIT_FAILURE) .call : - ChfAbort(abort_code); + ChfAbort(abort_code); .input : - const int abort_code, abort_code + const int abort_code, abort_code .output : - void + void .status_codes : - none + none .notes : 1.1, 13-May-1996, creation 2.1, 19-May-2000, update: @@ -122,78 +117,66 @@ static const ChfChar *message_table[] = - added Win32 support .- */ -void ChfAbort( /* Abort application */ - const int abort_code -) +void ChfAbort( /* Abort application */ + const int abort_code ) { #ifdef _WIN32 - if(abort_code != CHF_ABORT_SILENT) - { - TCHAR abort_msg[CHF_MAX_MESSAGE_LENGTH]; - HWND active_window; + if ( abort_code != CHF_ABORT_SILENT ) { + TCHAR abort_msg[ CHF_MAX_MESSAGE_LENGTH ]; + HWND active_window; - /* stderr not available; - put complaint in a message box and display it + /* stderr not available; + put complaint in a message box and display it + */ + if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE ) + _stprintf( abort_msg, CHF_ABORT_BAD_CODE_FMT, abort_code ); + + else + _stprintf( abort_msg, CHF_ABORT_GOOD_CODE_FMT, message_table[ abort_code ] ); + + /* Return value of MessageBox() ignored, because there is only + one available choice (abort) here. Avoid using a NULL handle. + */ + if ( chf_context.state != CHF_UNKNOWN && ( active_window = GetActiveWindow() ) != ( HWND )NULL ) + ( void )MessageBox( active_window, abort_msg, chf_context.app_name, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND ); + } + + /* Immediately exit the application with exit code EXIT_FAILURE + if CHF_ABORT option is set or if something is wrong with Chf state. */ - if(abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE) - _stprintf(abort_msg, - CHF_ABORT_BAD_CODE_FMT, abort_code); + if ( chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT ) + exit( EXIT_FAILURE ); else - _stprintf(abort_msg, - CHF_ABORT_GOOD_CODE_FMT, message_table[abort_code]); - - /* Return value of MessageBox() ignored, because there is only - one available choice (abort) here. Avoid using a NULL handle. - */ - if(chf_context.state != CHF_UNKNOWN - && (active_window = GetActiveWindow()) != (HWND)NULL) - (void) - MessageBox(active_window, - abort_msg, - chf_context.app_name, - MB_OK - |MB_ICONERROR - |MB_APPLMODAL|MB_SETFOREGROUND); - } - - /* Immediately exit the application with exit code EXIT_FAILURE - if CHF_ABORT option is set or if something is wrong with Chf state. - */ - if(chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT) - exit(EXIT_FAILURE); - - else /* Else, exit the application anyway, but with the exit code registered by the application. Don't use PostQuitMessage(), because the contract is that ChfAbort() never returns to the caller. */ -#ifndef _REENTRANT - exit(chf_context.exit_code); -#else -#error "_REENTRANT not supported yet" -#endif +# ifndef _REENTRANT + exit( chf_context.exit_code ); +# else +# error "_REENTRANT not supported yet" +# endif #else - if(abort_code != CHF_ABORT_SILENT) - { - fputs(CHF_ABORT_HEADER, stderr); + if ( abort_code != CHF_ABORT_SILENT ) { + fputs( CHF_ABORT_HEADER, stderr ); - if(abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE) - fprintf(stderr, CHF_ABORT_BAD_CODE_FMT, abort_code); + if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE ) + fprintf( stderr, CHF_ABORT_BAD_CODE_FMT, abort_code ); + + else + fprintf( stderr, CHF_ABORT_GOOD_CODE_FMT, message_table[ abort_code ] ); + } + + if ( chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT ) + abort(); else - fprintf(stderr, CHF_ABORT_GOOD_CODE_FMT, message_table[abort_code]); - } - - if(chf_context.state == CHF_UNKNOWN || chf_context.options & CHF_ABORT) - abort(); - - else -#ifndef _REENTRANT - exit(chf_context.exit_code); -#else - pthread_exit((void *)(chf_context.exit_code)); -#endif +# ifndef _REENTRANT + exit( chf_context.exit_code ); +# else + pthread_exit( ( void* )( chf_context.exit_code ) ); +# endif #endif } diff --git a/src/libChf/chf_gen.c b/src/libChf/chf_gen.c index 7b389d0..c5d0d87 100644 --- a/src/libChf/chf_gen.c +++ b/src/libChf/chf_gen.c @@ -31,21 +31,20 @@ static char rcs_id[] = "$Id: chf_gen.c,v 2.2 2001/01/25 12:10:22 cibrario Exp $" #include #include #ifndef _WIN32 -#include +# include #endif #include #include #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* .+ .title : ChfGenerate @@ -63,117 +62,104 @@ static char rcs_id[] = "$Id: chf_gen.c,v 2.2 2001/01/25 12:10:22 cibrario Exp $" condition stack. NOTE: This function calls the CHF function 'ChfAbort()' to - abort the application if either: - - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) - - there is an overflow in the internal buffer used during the - generation of the partial message associated with the condition - (abort code CHF_ABORT_MSG_OVF) - - there was an attempt to generate a condition while the CHF condition - CHF_F_COND_STACK_FULL (condition stack full) was being signalled - (abort code CHF_ABORT_COND_STACK_OVF) + abort the application if either: + - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) + - there is an overflow in the internal buffer used during the + generation of the partial message associated with the condition + (abort code CHF_ABORT_MSG_OVF) + - there was an attempt to generate a condition while the CHF condition + CHF_F_COND_STACK_FULL (condition stack full) was being signalled + (abort code CHF_ABORT_COND_STACK_OVF) .call : - ChfGenerate(module_id, file_name, line_number, - condition_code, severity, ...); + ChfGenerate(module_id, file_name, line_number, + condition_code, severity, ...); .input : - const int module_id, module identifier - const char *file_name, file name - const int line_number, line number - const int condition_code, condition code - const ChfSeverity severity, severity - ..., additional arguments + const int module_id, module identifier + const char *file_name, file name + const int line_number, line number + const int condition_code, condition code + const ChfSeverity severity, severity + ..., additional arguments .output : - void + void .status_codes : - (*) CHF_F_COND_STACK_FULL, the condition stack is full + (*) CHF_F_COND_STACK_FULL, the condition stack is full .notes : 1.1, 3-May-1996, creation .- */ -void ChfGenerate( /* Generate a condition into the stack */ - const int module_id, - const ChfChar *file_name, - const int line_number, - const int condition_code, - const ChfSeverity severity, - ... -) +void ChfGenerate( /* Generate a condition into the stack */ + const int module_id, const ChfChar* file_name, const int line_number, const int condition_code, + const ChfSeverity severity, ... ) { - ChfDescriptor *new_descriptor; - va_list aux_arg; + ChfDescriptor* new_descriptor; + va_list aux_arg; - /* Check that CHF has been correctly initialized */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Check that CHF has been correctly initialized */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - /* Prepare the additional arguments list */ - va_start(aux_arg, severity); + /* Prepare the additional arguments list */ + va_start( aux_arg, severity ); - if((new_descriptor = chf_context.condition_sp) - - chf_context.condition_stack >= chf_context.condition_stack_size) - { - /* The condition stack is full; - generate the CHF_F_COND_STACK_FULL condition and signal it immediately, - using the last available slot of the stack, if it's still empty, - otherwise abort the application. - */ - if(new_descriptor - chf_context.condition_stack == - chf_context.condition_stack_size) - { - new_descriptor->module_id = CHF_MODULE_ID; - new_descriptor->condition_code = CHF_F_COND_STACK_FULL; - new_descriptor->severity = CHF_FATAL; - new_descriptor->line_number = CHF_UNKNOWN_LINE_NUMBER; - new_descriptor->file_name = CHF_UNKNOWN_FILE_NAME; + if ( ( new_descriptor = chf_context.condition_sp ) - chf_context.condition_stack >= chf_context.condition_stack_size ) { + /* The condition stack is full; + generate the CHF_F_COND_STACK_FULL condition and signal it immediately, + using the last available slot of the stack, if it's still empty, + otherwise abort the application. + */ + if ( new_descriptor - chf_context.condition_stack == chf_context.condition_stack_size ) { + new_descriptor->module_id = CHF_MODULE_ID; + new_descriptor->condition_code = CHF_F_COND_STACK_FULL; + new_descriptor->severity = CHF_FATAL; + new_descriptor->line_number = CHF_UNKNOWN_LINE_NUMBER; + new_descriptor->file_name = CHF_UNKNOWN_FILE_NAME; - ChfStrncpy(new_descriptor->message, - ChfGetMessage(CHF_MODULE_ID, CHF_F_COND_STACK_FULL, - ChfText("Condition stack is full")), CHF_MAX_MESSAGE_LENGTH-1); - new_descriptor->message[CHF_MAX_MESSAGE_LENGTH-1] = '\0'; + ChfStrncpy( new_descriptor->message, + ChfGetMessage( CHF_MODULE_ID, CHF_F_COND_STACK_FULL, ChfText( "Condition stack is full" ) ), + CHF_MAX_MESSAGE_LENGTH - 1 ); + new_descriptor->message[ CHF_MAX_MESSAGE_LENGTH - 1 ] = '\0'; - new_descriptor->next = CHF_NULL_DESCRIPTOR; - chf_context.condition_sp++; + new_descriptor->next = CHF_NULL_DESCRIPTOR; + chf_context.condition_sp++; - ChfSignal(); + ChfSignal(); + } + + else + ChfAbort( CHF_ABORT_COND_STACK_OVF ); } - else - ChfAbort(CHF_ABORT_COND_STACK_OVF); - } + else { + ChfChar def_message[ CHF_DEF_MESSAGE_LENGTH ]; + ChfChar tmp_message[ CHF_TMP_MESSAGE_LENGTH ]; - else - { - ChfChar def_message[CHF_DEF_MESSAGE_LENGTH]; - ChfChar tmp_message[CHF_TMP_MESSAGE_LENGTH]; + new_descriptor->module_id = module_id; + new_descriptor->condition_code = condition_code; + new_descriptor->severity = severity; + new_descriptor->line_number = line_number; + new_descriptor->file_name = file_name; - new_descriptor->module_id = module_id; - new_descriptor->condition_code = condition_code; - new_descriptor->severity = severity; - new_descriptor->line_number = line_number; - new_descriptor->file_name = file_name; + /* Generate the default message */ + ChfSprintf( def_message, CHF_DEF_PARTIAL_MSG_FMT, condition_code ); - /* Generate the default message */ - ChfSprintf(def_message, CHF_DEF_PARTIAL_MSG_FMT, condition_code); + /* Generate the partial message associated with the condition using a + temporary area + */ + if ( ChfVsprintf( tmp_message, ChfGetMessage( module_id, condition_code, def_message ), aux_arg ) >= CHF_TMP_MESSAGE_LENGTH ) + ChfAbort( CHF_ABORT_MSG_OVF ); - /* Generate the partial message associated with the condition using a - temporary area - */ - if( - ChfVsprintf(tmp_message, - ChfGetMessage(module_id, condition_code, def_message), aux_arg) >= - CHF_TMP_MESSAGE_LENGTH) - ChfAbort(CHF_ABORT_MSG_OVF); - - /* Copy the message into the condition descriptor */ - ChfStrncpy(new_descriptor->message, tmp_message, CHF_MAX_MESSAGE_LENGTH-1); - new_descriptor->message[CHF_MAX_MESSAGE_LENGTH-1] = '\0'; + /* Copy the message into the condition descriptor */ + ChfStrncpy( new_descriptor->message, tmp_message, CHF_MAX_MESSAGE_LENGTH - 1 ); + new_descriptor->message[ CHF_MAX_MESSAGE_LENGTH - 1 ] = '\0'; - /* Link the new descriptor with the current descriptor list, if it - isn't the first descriptor of the list - */ - new_descriptor->next = (new_descriptor == chf_context.condition_base) - ? CHF_NULL_DESCRIPTOR : new_descriptor - 1; + /* Link the new descriptor with the current descriptor list, if it + isn't the first descriptor of the list + */ + new_descriptor->next = ( new_descriptor == chf_context.condition_base ) ? CHF_NULL_DESCRIPTOR : new_descriptor - 1; - chf_context.condition_sp++; - } + chf_context.condition_sp++; + } } diff --git a/src/libChf/chf_hdlr.c b/src/libChf/chf_hdlr.c index e5723b6..56aaa5e 100644 --- a/src/libChf/chf_hdlr.c +++ b/src/libChf/chf_hdlr.c @@ -44,19 +44,18 @@ static char rcs_id[] = "$Id: chf_hdlr.c,v 2.2 2001/01/25 12:12:46 cibrario Exp $ #include #include #ifndef _WIN32 -#include +# include #endif #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* .+ .title : StructuredHelper @@ -68,42 +67,36 @@ static char rcs_id[] = "$Id: chf_hdlr.c,v 2.2 2001/01/25 12:12:46 cibrario Exp $ ChfPushHandler() when its 'new_handler' argument is CHF_NULL_HANDLER, and performs the following functions: - - if called during an ordinary signalling operation with a - CHF_FATAL condition, it requests the action CHF_UNWIND_KEEP + - if called during an ordinary signalling operation with a + CHF_FATAL condition, it requests the action CHF_UNWIND_KEEP - - if called when Chf is in any other state, or with a - severity less than CHF_FATAL, it requests the action CHF_RESIGNAL + - if called when Chf is in any other state, or with a + severity less than CHF_FATAL, it requests the action CHF_RESIGNAL The structured condition handling helper currently makes no use of handler_context. .call : - action = StructuredHelper(desc, state, context); + action = StructuredHelper(desc, state, context); .input : - const ChfDescriptor *desc, condition descriptor - const ChfState state, current CHF state + const ChfDescriptor *desc, condition descriptor + const ChfState state, current CHF state .output : - ChfAction action, action requested by the handler + ChfAction action, action requested by the handler .status_codes : - none + none .notes : 2.1, 19-May-2000, creation .- */ -static ChfAction StructuredHelper( - const ChfDescriptor *desc, - const ChfState state, - ChfPointer handler_context -) +static ChfAction StructuredHelper( const ChfDescriptor* desc, const ChfState state, ChfPointer handler_context ) { - ChfAction action; - const ChfDescriptor *d; + ChfAction action; + const ChfDescriptor* d; - return((state == CHF_SIGNALING && ChfGetSeverity(desc) == CHF_FATAL) - ? CHF_UNWIND_KEEP : CHF_RESIGNAL); + return ( ( state == CHF_SIGNALING && ChfGetSeverity( desc ) == CHF_FATAL ) ? CHF_UNWIND_KEEP : CHF_RESIGNAL ); } - /* .+ .title : ChfPushHandler @@ -123,7 +116,7 @@ static ChfAction StructuredHelper( remain valid until 'new_handler' is popped from the condition stack. 'handler_context' may be set to the special (null) value CHF_NULL_POINTER to indicate that the handler hasn't any private context information. - + If, in the future, the handler will request the CHF_UNWIND action, the setjmp() function invocation that established 'unwind_context' will appear to return again. @@ -139,19 +132,19 @@ static ChfAction StructuredHelper( conditions are CHF_FATAL. NOTE: This function calls ChfAbort() with abort code CHF_ABORT_INIT if - the CHF subsystem has not been initialized. + the CHF subsystem has not been initialized. .call : - ChfPushHandler(new_handler, unwind_context); + ChfPushHandler(new_handler, unwind_context); .input : - ChfHandler new_handler, new condition handler - void *unwind_context, handler unwind context pointer - ChfPointer handler_context, private handler context pointer + ChfHandler new_handler, new condition handler + void *unwind_context, handler unwind context pointer + ChfPointer handler_context, private handler context pointer .output : - void + void .status_codes : - (*) CHF_F_BAD_STATE, bad CHF state for requested operation - (*) CHF_F_HDLR_STACK_FULL, the handler stack is full + (*) CHF_F_BAD_STATE, bad CHF state for requested operation + (*) CHF_F_HDLR_STACK_FULL, the handler stack is full .notes : 1.1, 13-May-1996, creation 1.6, 15-Jan-1997, update: @@ -162,44 +155,34 @@ static ChfAction StructuredHelper( - added StructuredHelper handling .- */ -void ChfPushHandler( /* Push a new handler into the stack */ - ChfHandler new_handler, - void *unwind_context, - ChfPointer handler_context -) +void ChfPushHandler( /* Push a new handler into the stack */ + ChfHandler new_handler, void* unwind_context, ChfPointer handler_context ) { - /* Make sure that CHF has been correctly initialized and is idle */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Make sure that CHF has been correctly initialized and is idle */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - if(chf_context.state != CHF_IDLE) - { - ChfCondition CHF_F_BAD_STATE, CHF_FATAL - ChfEnd; + if ( chf_context.state != CHF_IDLE ) { + ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfSignal(); + } - /* Check if the handler stack is full */ - else if(chf_context.handler_sp - chf_context.handler_stack >= - chf_context.handler_stack_size) - { - ChfCondition CHF_F_HDLR_STACK_FULL, CHF_FATAL - ChfEnd; + /* Check if the handler stack is full */ + else if ( chf_context.handler_sp - chf_context.handler_stack >= chf_context.handler_stack_size ) { + ChfCondition CHF_F_HDLR_STACK_FULL, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfSignal(); + } - else - { - chf_context.handler_sp->unwind_context = unwind_context; - chf_context.handler_sp->handler_context = handler_context; - chf_context.handler_sp->handler = - ((new_handler == CHF_NULL_HANDLER) ? StructuredHelper : new_handler); - chf_context.handler_sp++; - } + else { + chf_context.handler_sp->unwind_context = unwind_context; + chf_context.handler_sp->handler_context = handler_context; + chf_context.handler_sp->handler = ( ( new_handler == CHF_NULL_HANDLER ) ? StructuredHelper : new_handler ); + chf_context.handler_sp++; + } } - /* .+ .title : ChfPopHandler @@ -208,24 +191,24 @@ void ChfPushHandler( /* Push a new handler into the stack */ .description : This function pops the topmost condition handler from the handler stack and returns to the caller. - + If some error occours during the execution, the function will generate and immediately signal one of the conditions listed below and marked with (*). The function will never return directly to the caller, since all conditions are CHF_FATAL. NOTE: This function calls ChfAbort() with abort code CHF_ABORT_INIT if - the CHF subsystem has not been initialized. + the CHF subsystem has not been initialized. .call : - ChfPopHandler(); + ChfPopHandler(); .input : - void + void .output : - void + void .status_codes : - CHF_F_BAD_STATE, bad CHF state for requested operation - CHF_F_HDLR_STACK_FULL, the handler stack is full + CHF_F_BAD_STATE, bad CHF state for requested operation + CHF_F_HDLR_STACK_FULL, the handler stack is full .notes : 1.1, 13-May-1996, creation 1.6, 15-Jan-1997, update: @@ -234,31 +217,27 @@ void ChfPushHandler( /* Push a new handler into the stack */ - improved documentation .- */ -void ChfPopHandler( /* Pop a handler */ - void -) +void ChfPopHandler( /* Pop a handler */ + void ) { - /* Make sure that CHF has been correctly initialized and is idle */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Make sure that CHF has been correctly initialized and is idle */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - if(chf_context.state != CHF_IDLE) - { - ChfCondition CHF_F_BAD_STATE, CHF_FATAL - ChfEnd; + if ( chf_context.state != CHF_IDLE ) { + ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfSignal(); + } - /* Check if the handler stack is empty */ - else if(chf_context.handler_sp == chf_context.handler_stack) - { - ChfCondition CHF_F_HDLR_STACK_EMPTY, CHF_FATAL - ChfEnd; + /* Check if the handler stack is empty */ + else if ( chf_context.handler_sp == chf_context.handler_stack ) { + ChfCondition CHF_F_HDLR_STACK_EMPTY, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfSignal(); + } - /* Discard the topmost condition handler */ - else - --chf_context.handler_sp; + /* Discard the topmost condition handler */ + else + --chf_context.handler_sp; } diff --git a/src/libChf/chf_init.c b/src/libChf/chf_init.c index fa64a68..296189b 100644 --- a/src/libChf/chf_init.c +++ b/src/libChf/chf_init.c @@ -54,20 +54,19 @@ static char rcs_id[] = "$Id: chf_init.c,v 2.2 2001/01/25 14:05:23 cibrario Exp $ #include #include #ifndef _WIN32 -#include +# include #endif #include #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* ------------------------------------------------------------------------- Global and static variables ------------------------------------------------------------------------- */ @@ -82,14 +81,13 @@ ChfContext _chf_context; /* Message separator and severity names for ChfBuildMessage() */ static const ChfChar separator[] = CHF_MESSAGE_SEPARATOR; -static const ChfChar *severity_name[] = CHF_SEVERITY_NAMES; - +static const ChfChar* severity_name[] = CHF_SEVERITY_NAMES; /* ------------------------------------------------------------------------- Multithreading support ------------------------------------------------------------------------- */ #ifdef _REENTRANT -#include +# include /* Mutex to access chf_context during initialization and exit; mutex to puts condition messages on stderr (DefaultHandler) @@ -103,21 +101,19 @@ static pthread_key_t data_key; /* This function is called to destroy a Chf context when the owning thread terminated. */ -static void DestroyContext(void *context) +static void DestroyContext( void* context ) { - free(((ChfContext *)context)->message_buffer); - free(((ChfContext *)context)->handler_stack); - free(((ChfContext *)context)->condition_stack); - free(context); + free( ( ( ChfContext* )context )->message_buffer ); + free( ( ( ChfContext* )context )->handler_stack ); + free( ( ( ChfContext* )context )->condition_stack ); + free( context ); } #endif - /* ------------------------------------------------------------------------- Private functions ------------------------------------------------------------------------- */ - /* .+ .title : DefaultHandler @@ -128,21 +124,21 @@ static void DestroyContext(void *context) pushed into the condition handler stack by ChfInit() and performs the following functions: - - if called during an unwind, it returns immediately to the caller, - requesting the action CHF_RESIGNAL, else + - if called during an unwind, it returns immediately to the caller, + requesting the action CHF_RESIGNAL, else - - if the severity of the condition being signalled is greater than - CHF_SUCCESS, it prints the messages associated with the entire - condition group on stderr using the standard function - ChfBuildMessage() to build the messages. + - if the severity of the condition being signalled is greater than + CHF_SUCCESS, it prints the messages associated with the entire + condition group on stderr using the standard function + ChfBuildMessage() to build the messages. - - if the severity of the condition being signalled is less than - CHF_FATAL, it returns to the caller requesting the action - CHF_CONTINUE, else + - if the severity of the condition being signalled is less than + CHF_FATAL, it returns to the caller requesting the action + CHF_CONTINUE, else - - if the CHF_FATAL condition was NOT signalled during an unwind - operation, it returns to the caller requesting the action - CHF_UNWIND, otherwise it requests the action CHF_RESIGNAL. + - if the CHF_FATAL condition was NOT signalled during an unwind + operation, it returns to the caller requesting the action + CHF_UNWIND, otherwise it requests the action CHF_RESIGNAL. WIN32: @@ -151,14 +147,14 @@ static void DestroyContext(void *context) anything .call : - action = DefaultHandler(desc, state, context); + action = DefaultHandler(desc, state, context); .input : - const ChfDescriptor *desc, condition descriptor - const ChfState state, current CHF state + const ChfDescriptor *desc, condition descriptor + const ChfState state, current CHF state .output : - ChfAction action, action requested by the handler + ChfAction action, action requested by the handler .status_codes : - none + none .notes : 1.1, 16-May-1996, creation 1.6, 15-Jan-1997, update: @@ -170,69 +166,62 @@ static void DestroyContext(void *context) - added Win32 support .- */ -static ChfAction DefaultHandler( - const ChfDescriptor *desc, - const ChfState state, - ChfPointer handler_context -) +static ChfAction DefaultHandler( const ChfDescriptor* desc, const ChfState state, ChfPointer handler_context ) { - ChfAction action; - const ChfDescriptor *d; + ChfAction action; + const ChfDescriptor* d; - if(state == CHF_UNWINDING) - /* If CHF is unwinding, do nothing */ - action = CHF_RESIGNAL; + if ( state == CHF_UNWINDING ) + /* If CHF is unwinding, do nothing */ + action = CHF_RESIGNAL; - else - { - /* Print the condition messages, if necessary. The sequence of fputs() - is done atomically if multithreading support is enabled. - In Win32, the default handler does not print anything. - */ - if(ChfGetSeverity(desc) > CHF_SUCCESS) - { + else { + /* Print the condition messages, if necessary. The sequence of fputs() + is done atomically if multithreading support is enabled. + In Win32, the default handler does not print anything. + */ + if ( ChfGetSeverity( desc ) > CHF_SUCCESS ) { #ifdef _REENTRANT - if(pthread_mutex_lock(&fputs_mutex)) ChfAbort(CHF_ABORT_PTHREAD); + if ( pthread_mutex_lock( &fputs_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif #ifndef _WIN32 - for(d = desc; d != CHF_NULL_DESCRIPTOR; d = ChfGetNextDescriptor(d)) - fputs(ChfBuildMessage(d), stderr); + for ( d = desc; d != CHF_NULL_DESCRIPTOR; d = ChfGetNextDescriptor( d ) ) + fputs( ChfBuildMessage( d ), stderr ); #endif #ifdef _REENTRANT - if(pthread_mutex_unlock(&fputs_mutex)) ChfAbort(CHF_ABORT_PTHREAD); + if ( pthread_mutex_unlock( &fputs_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif + } + + /* Determine the handler action */ + switch ( ChfGetSeverity( desc ) ) { + case CHF_SUCCESS: + case CHF_INFO: + case CHF_WARNING: + case CHF_ERROR: + { + /* Continue execution if the severity is less than CHF_FATAL */ + action = CHF_CONTINUE; + break; + } + + default: + { + /* The severity of the condition is CHF_FATAL; appempt to unwind if + the fatal condition wasn't signalled during another unwind. + */ + action = ( ( state == CHF_SIGNAL_UNWINDING ) ? CHF_RESIGNAL : CHF_UNWIND ); + break; + } + } } - /* Determine the handler action */ - switch(ChfGetSeverity(desc)) - { - case CHF_SUCCESS: - case CHF_INFO: - case CHF_WARNING: - case CHF_ERROR: - { - /* Continue execution if the severity is less than CHF_FATAL */ - action = CHF_CONTINUE; - break; - } - - default: - { - /* The severity of the condition is CHF_FATAL; appempt to unwind if - the fatal condition wasn't signalled during another unwind. - */ - action = ((state == CHF_SIGNAL_UNWINDING) ? CHF_RESIGNAL: CHF_UNWIND); - break; - } - } - } - - /* Return the action code to the Chf handler dispatcher */ - return action; + /* Return the action code to the Chf handler dispatcher */ + return action; } - - /* .+ .title : scopy @@ -244,45 +233,38 @@ static ChfAction DefaultHandler( The function returns a pointer to the NUL-terminator just written. .call : - np = scopy(p, q, p_end); + np = scopy(p, q, p_end); .input : - char *p, starting position for the write - const char *q, pointer to the string to be copied - char *p_end, pointer to the end of the output area + char *p, starting position for the write + const char *q, pointer to the string to be copied + char *p_end, pointer to the end of the output area .output : - char *np, pointer to the NUL-terminator just written + char *np, pointer to the NUL-terminator just written .status_codes : - none + none .notes : 1.1, 16-May-1996, creation .- */ -static ChfChar *scopy( - ChfChar *p, - const ChfChar *q, - ChfChar *p_end -) +static ChfChar* scopy( ChfChar* p, const ChfChar* q, ChfChar* p_end ) { - size_t q_len = ChfStrlen(q); - size_t p_avail = p_end - p; + size_t q_len = ChfStrlen( q ); + size_t p_avail = p_end - p; - if(q_len < p_avail) - { - ChfStrcpy(p, q); - p += q_len; - } + if ( q_len < p_avail ) { + ChfStrcpy( p, q ); + p += q_len; + } - else if(p_avail > 1) - { - ChfStrncpy(p, q, p_avail-2); - p[p_avail-1] = '\0'; - p = p_end; - } + else if ( p_avail > 1 ) { + ChfStrncpy( p, q, p_avail - 2 ); + p[ p_avail - 1 ] = '\0'; + p = p_end; + } - return p; + return p; } - /* ------------------------------------------------------------------------- Public functions ------------------------------------------------------------------------- */ @@ -300,10 +282,10 @@ static ChfChar *scopy( necessary, to retrieve the requested message. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_INIT - if CHF hasn't been correctly initialized. + if CHF hasn't been correctly initialized. NOTE: The returned pointer points to per-thread static storage, which will be - overwritten by subsequent calls to this function. + overwritten by subsequent calls to this function. WIN32: @@ -311,46 +293,42 @@ static ChfChar *scopy( codes in CHF_ERRNO_SET is not performed .call : - message = ChfGetMessage(module_id, condition_code, - default_message); + message = ChfGetMessage(module_id, condition_code, + default_message); .input : - const int module_id, module identifier - const int condition_code, condition code - const char *default_message, default message + const int module_id, module identifier + const int condition_code, condition code + const char *default_message, default message .output : - const char *message, pointer to the retrieved message + const char *message, pointer to the retrieved message .status_codes : - none + none .notes : 1.1, 17-May-1996, creation 2.2, 22-Jan-2001, update: - added Win32 support .- */ -const ChfChar *ChfGetMessage( /* Retrieve a condition message */ - const int module_id, - const int condition_code, - const ChfChar *default_message -) +const ChfChar* ChfGetMessage( /* Retrieve a condition message */ + const int module_id, const int condition_code, const ChfChar* default_message ) { - const ChfChar *message; + const ChfChar* message; - /* Check that CHF has been correctly initialized */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Check that CHF has been correctly initialized */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - if((message = chf_context.mrs_get(chf_context.mrs_data, - module_id, condition_code, default_message)) == default_message && - module_id == CHF_ERRNO_SET) -# ifdef _WIN32 - message = default_message; -# else - message = strerror(condition_code); -# endif + if ( ( message = chf_context.mrs_get( chf_context.mrs_data, module_id, condition_code, default_message ) ) == default_message && + module_id == CHF_ERRNO_SET ) +#ifdef _WIN32 + message = default_message; +#else + message = strerror( condition_code ); +#endif - return(message); + return ( message ); } - /* .+ .title : ChfBuildMessage @@ -361,10 +339,10 @@ const ChfChar *ChfGetMessage( /* Retrieve a condition message */ descriptor and returns a pointer to a string containing it. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_INIT - if CHF hasn't been correctly initialized. + if CHF hasn't been correctly initialized. NOTE: The returned pointer points to per-thread static storage, which will be - overwritten by subsequent calls to this function. + overwritten by subsequent calls to this function. WIN32: @@ -372,87 +350,81 @@ const ChfChar *ChfGetMessage( /* Retrieve a condition message */ included in the message .call : - msg = ChfBuildMessage(descriptor); + msg = ChfBuildMessage(descriptor); .input : - const ChfDescriptor *descriptor, condition descriptor + const ChfDescriptor *descriptor, condition descriptor .output : - char *msg, pointer to the message associated with 'descriptor' + char *msg, pointer to the message associated with 'descriptor' .status_codes : - none + none .notes : 1.1, 16-May-1996, creation 2.2, 22-Jan-2001, update: - added Win32 support .- */ -ChfChar *ChfBuildMessage( /* Build a condition message */ - const ChfDescriptor *descriptor -) +ChfChar* ChfBuildMessage( /* Build a condition message */ + const ChfDescriptor* descriptor ) { - ChfChar *tmp_p; - ChfChar *tmp_end; - ChfChar def_message[CHF_DEF_MESSAGE_LENGTH]; - ChfSeverity severity; + ChfChar* tmp_p; + ChfChar* tmp_end; + ChfChar def_message[ CHF_DEF_MESSAGE_LENGTH ]; + ChfSeverity severity; - /* Check that CHF has been correctly initialized */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Check that CHF has been correctly initialized */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - /* Set appropriate pointers to the start/end of the message buffer */ - tmp_p = chf_context.message_buffer; - tmp_end = tmp_p + CHF_MAX_MESSAGE_LENGTH; + /* Set appropriate pointers to the start/end of the message buffer */ + tmp_p = chf_context.message_buffer; + tmp_end = tmp_p + CHF_MAX_MESSAGE_LENGTH; #ifndef _WIN32 - /* The message starts with ": " if the condition is the first of - its condition group, with "\t" if not. - */ - if(descriptor == chf_context.condition_sp-1) - { - tmp_p = scopy(tmp_p, chf_context.app_name, tmp_end); - tmp_p = scopy(tmp_p, separator, tmp_end); - } + /* The message starts with ": " if the condition is the first of + its condition group, with "\t" if not. + */ + if ( descriptor == chf_context.condition_sp - 1 ) { + tmp_p = scopy( tmp_p, chf_context.app_name, tmp_end ); + tmp_p = scopy( tmp_p, separator, tmp_end ); + } - else - tmp_p = scopy(tmp_p, ChfText("\t"), tmp_end); + else + tmp_p = scopy( tmp_p, ChfText( "\t" ), tmp_end ); #endif - /* The message continues with the module name */ - ChfSprintf(def_message, CHF_DEF_MID_MSG_FMT, ChfGetModuleId(descriptor)); + /* The message continues with the module name */ + ChfSprintf( def_message, CHF_DEF_MID_MSG_FMT, ChfGetModuleId( descriptor ) ); - tmp_p = scopy(tmp_p, - ChfGetMessage(CHF_MODULE_NAMES_SET, ChfGetModuleId(descriptor), - def_message), tmp_end); + tmp_p = scopy( tmp_p, ChfGetMessage( CHF_MODULE_NAMES_SET, ChfGetModuleId( descriptor ), def_message ), tmp_end ); - /* Add also the extended information, if any */ - if(ChfGetLineNumber(descriptor) != CHF_UNKNOWN_LINE_NUMBER) - { - tmp_p = scopy(tmp_p, ChfText(" "), tmp_end); + /* Add also the extended information, if any */ + if ( ChfGetLineNumber( descriptor ) != CHF_UNKNOWN_LINE_NUMBER ) { + tmp_p = scopy( tmp_p, ChfText( " " ), tmp_end ); - ChfSprintf(def_message, CHF_EXTENDED_INFO_FMT, - ChfGetFileName(descriptor), ChfGetLineNumber(descriptor)); - - tmp_p = scopy(tmp_p, def_message, tmp_end); - } + ChfSprintf( def_message, CHF_EXTENDED_INFO_FMT, ChfGetFileName( descriptor ), ChfGetLineNumber( descriptor ) ); - tmp_p = scopy(tmp_p, separator, tmp_end); + tmp_p = scopy( tmp_p, def_message, tmp_end ); + } + + tmp_p = scopy( tmp_p, separator, tmp_end ); #ifndef _WIN32 - /* Add the severity code of the message */ - tmp_p = scopy(tmp_p, - ((severity = ChfGetSeverity(descriptor)) < CHF_SUCCESS || - severity > CHF_FATAL) ? CHF_UNKNOWN_SEVERITY : severity_name[severity], - tmp_end); + /* Add the severity code of the message */ + tmp_p = scopy( tmp_p, + ( ( severity = ChfGetSeverity( descriptor ) ) < CHF_SUCCESS || severity > CHF_FATAL ) ? CHF_UNKNOWN_SEVERITY + : severity_name[ severity ], + tmp_end ); - tmp_p = scopy(tmp_p, separator, tmp_end); + tmp_p = scopy( tmp_p, separator, tmp_end ); #endif - /* The message ends with the partial message from the descriptor */ - tmp_p = scopy(tmp_p, ChfGetPartialMessage(descriptor), tmp_end); - (void)scopy(tmp_p, CHF_MESSAGE_TERMINATOR, tmp_end); + /* The message ends with the partial message from the descriptor */ + tmp_p = scopy( tmp_p, ChfGetPartialMessage( descriptor ), tmp_end ); + ( void )scopy( tmp_p, CHF_MESSAGE_TERMINATOR, tmp_end ); - return chf_context.message_buffer; + return chf_context.message_buffer; } - /* .+ .title : ChfInit @@ -467,29 +439,29 @@ ChfChar *ChfBuildMessage( /* Build a condition message */ function. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_DUP_INIT - if CHF has already been initialized before. + if CHF has already been initialized before. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_PTHREAD - if a pthread operation fails. + if a pthread operation fails. .call : - cc = ChfInit(app_name, options, - mrs_data, mrs_get, mrs_exit, - condition_stack_size, handler_stack_size, - exit_code); + cc = ChfInit(app_name, options, + mrs_data, mrs_get, mrs_exit, + condition_stack_size, handler_stack_size, + exit_code); .input : - const char *app_name, Application's name - const ChfOptions options, Options - void *mrs_data, Message retrieval private data - ChfMrsGet mrs_get, 'GetMessage' function - ChfMrsExit mrs_exit, 'Exit' function - const int condition_stack_size, Size of the condition stack - const int handler_stack_size, Size of the handler stack - const int exit_code, Abnormal exit code + const char *app_name, Application's name + const ChfOptions options, Options + void *mrs_data, Message retrieval private data + ChfMrsGet mrs_get, 'GetMessage' function + ChfMrsExit mrs_exit, 'Exit' function + const int condition_stack_size, Size of the condition stack + const int handler_stack_size, Size of the handler stack + const int exit_code, Abnormal exit code .output : - int cc, condition code + int cc, condition code .status_codes : - CHF_F_MALLOC, FATAL, dynamic memory allocation failed + CHF_F_MALLOC, FATAL, dynamic memory allocation failed .notes : 1.1, 13-May-1996, creation 1.6, 15-Jan-1997, update: @@ -500,104 +472,98 @@ ChfChar *ChfBuildMessage( /* Build a condition message */ - added Win32 support; a malloc() call was not portable. .- */ -int ChfInit( /* Generic initialization */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - void *mrs_data, /* Message retrieval private data */ - ChfMrsGet mrs_get, /* 'GetMessage' function */ - ChfMrsExit mrs_exit, /* 'Exit' function */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfInit( /* Generic initialization */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + void* mrs_data, /* Message retrieval private data */ + ChfMrsGet mrs_get, /* 'GetMessage' function */ + ChfMrsExit mrs_exit, /* 'Exit' function */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ) { - int cc; + int cc; - /* Check that CHF has not been initialized yet */ + /* Check that CHF has not been initialized yet */ #ifndef _REENTRANT - if(_chf_context.state != CHF_UNKNOWN) ChfAbort(CHF_ABORT_DUP_INIT); + if ( _chf_context.state != CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_DUP_INIT ); #else - /* Reentrant check; lock context_mutex first */ - if(pthread_mutex_lock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); - if(_chf_context.state != CHF_UNKNOWN) - { - if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); - ChfAbort(CHF_ABORT_DUP_INIT); - } + /* Reentrant check; lock context_mutex first */ + if ( pthread_mutex_lock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); + if ( _chf_context.state != CHF_UNKNOWN ) { + if ( pthread_mutex_unlock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); + ChfAbort( CHF_ABORT_DUP_INIT ); + } #endif #ifndef _REENTRANT - if((_chf_context.condition_stack = - (ChfDescriptor *) - malloc((size_t)(condition_stack_size+1)*sizeof(ChfDescriptor))) == - CHF_NULL_DESCRIPTOR) - cc = CHF_F_MALLOC; + if ( ( _chf_context.condition_stack = ( ChfDescriptor* )malloc( ( size_t )( condition_stack_size + 1 ) * sizeof( ChfDescriptor ) ) ) == + CHF_NULL_DESCRIPTOR ) + cc = CHF_F_MALLOC; - else if((_chf_context.handler_stack = - (ChfHandlerDescriptor *) - malloc((size_t)handler_stack_size*sizeof(ChfHandlerDescriptor))) == - (ChfHandlerDescriptor *)NULL) - { - free(_chf_context.condition_stack); - cc = CHF_F_MALLOC; - } + else if ( ( _chf_context.handler_stack = ( ChfHandlerDescriptor* )malloc( + ( size_t )handler_stack_size * sizeof( ChfHandlerDescriptor ) ) ) == ( ChfHandlerDescriptor* )NULL ) { + free( _chf_context.condition_stack ); + cc = CHF_F_MALLOC; + } - else if((_chf_context.message_buffer = - (ChfChar *)malloc( - (size_t)(CHF_MAX_MESSAGE_LENGTH) * sizeof(ChfChar))) == (ChfChar *)NULL) - { - free(_chf_context.condition_stack); - free(_chf_context.handler_stack); - cc = CHF_F_MALLOC; - } + else if ( ( _chf_context.message_buffer = ( ChfChar* )malloc( ( size_t )( CHF_MAX_MESSAGE_LENGTH ) * sizeof( ChfChar ) ) ) == + ( ChfChar* )NULL ) { + free( _chf_context.condition_stack ); + free( _chf_context.handler_stack ); + cc = CHF_F_MALLOC; + } - else + else #else - /* Reentrant init: condition_stack, handler_stack, message_buffer - are not needed in the master Chf context. - Init the Chf data key instead. - */ - _chf_context.condition_stack = CHF_NULL_DESCRIPTOR; - _chf_context.handler_stack = (ChfHandlerDescriptor *)NULL; - _chf_context.message_buffer = (char *)NULL; - - if(pthread_key_create(&data_key, DestroyContext)) - ChfAbort(CHF_ABORT_PTHREAD); -#endif - - { - /* Initialize the CHF context */ - _chf_context.app_name = app_name; - _chf_context.options = options; - _chf_context.mrs_data = mrs_data; - _chf_context.mrs_get = mrs_get; - _chf_context.mrs_exit = mrs_exit; - _chf_context.condition_stack_size = condition_stack_size; - _chf_context.handler_stack_size = handler_stack_size; - _chf_context.exit_code = exit_code; - _chf_context.condition_base = _chf_context.condition_sp = - _chf_context.condition_stack; - _chf_context.handler_sp = _chf_context.handler_stack; - _chf_context.state = CHF_IDLE; - -#ifndef _REENTRANT - /* Push the default handler; in the reentrant case, this will be - done once per thread, when the thread-specific context is primed. + /* Reentrant init: condition_stack, handler_stack, message_buffer + are not needed in the master Chf context. + Init the Chf data key instead. */ - ChfPushHandler(DefaultHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER); + _chf_context.condition_stack = CHF_NULL_DESCRIPTOR; + _chf_context.handler_stack = ( ChfHandlerDescriptor* )NULL; + _chf_context.message_buffer = ( char* )NULL; + + if ( pthread_key_create( &data_key, DestroyContext ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif - cc = CHF_S_OK; - } + { + /* Initialize the CHF context */ + _chf_context.app_name = app_name; + _chf_context.options = options; + _chf_context.mrs_data = mrs_data; + _chf_context.mrs_get = mrs_get; + _chf_context.mrs_exit = mrs_exit; + _chf_context.condition_stack_size = condition_stack_size; + _chf_context.handler_stack_size = handler_stack_size; + _chf_context.exit_code = exit_code; + _chf_context.condition_base = _chf_context.condition_sp = _chf_context.condition_stack; + _chf_context.handler_sp = _chf_context.handler_stack; + _chf_context.state = CHF_IDLE; + +#ifndef _REENTRANT + /* Push the default handler; in the reentrant case, this will be + done once per thread, when the thread-specific context is primed. + */ + ChfPushHandler( DefaultHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER ); +#endif + + cc = CHF_S_OK; + } #ifdef _REENTRANT - if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); + if ( pthread_mutex_unlock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif - return cc; + return cc; } - /* .+ .title : ChfExit @@ -610,82 +576,82 @@ int ChfInit( /* Generic initialization */ the application using ChfAbort() with abort code CHF_ABORT_INIT. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_INIT - if CHF hasn't been initialized. + if CHF hasn't been initialized. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_PTHREAD - if a pthread operation fails. + if a pthread operation fails. .call : - ChfExit(); + ChfExit(); .input : - void + void .output : - void + void .status_codes : - none + none .notes : 1.1, 24-May-1996, creation 2.1, 19-May-2000, update: - added multithreading support .- */ -void ChfExit( - void -) +void ChfExit( void ) { - /* Check that CHF has been correctly initialized */ + /* Check that CHF has been correctly initialized */ #ifndef _REENTRANT - if(_chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + if ( _chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); #else - /* Reentrant check; lock context_mutex first */ - if(pthread_mutex_lock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); - if(_chf_context.state == CHF_UNKNOWN) - { - if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); - ChfAbort(CHF_ABORT_INIT); - } + /* Reentrant check; lock context_mutex first */ + if ( pthread_mutex_lock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); + if ( _chf_context.state == CHF_UNKNOWN ) { + if ( pthread_mutex_unlock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); + ChfAbort( CHF_ABORT_INIT ); + } #endif - /* Destroy the context associated with this thread now; this is necessary - to ensure that the context is actually destroyed when a single-threaded - application links with the multithreaded version of Chf: in this case, - pthread_exit() is called *after* ChfExit(), the Chf data key no longer - exists when pthread_exit() is called and the destructor registered - with pthread_key_create() does not take place. - The data pointer associated with the Chf data key is set to NULL to - avoid any subsequent reactivation of the destructor. - */ + /* Destroy the context associated with this thread now; this is necessary + to ensure that the context is actually destroyed when a single-threaded + application links with the multithreaded version of Chf: in this case, + pthread_exit() is called *after* ChfExit(), the Chf data key no longer + exists when pthread_exit() is called and the destructor registered + with pthread_key_create() does not take place. + The data pointer associated with the Chf data key is set to NULL to + avoid any subsequent reactivation of the destructor. + */ #ifdef _REENTRANT - DestroyContext(&chf_context); - if(pthread_setspecific(data_key, (void *)NULL)) - { - (void)pthread_mutex_unlock(&context_mutex); - ChfAbort(CHF_ABORT_PTHREAD); - } + DestroyContext( &chf_context ); + if ( pthread_setspecific( data_key, ( void* )NULL ) ) { + ( void )pthread_mutex_unlock( &context_mutex ); + ChfAbort( CHF_ABORT_PTHREAD ); + } #endif - /* Shut down the message retrieval subsystem first */ - _chf_context.mrs_exit(_chf_context.mrs_data); + /* Shut down the message retrieval subsystem first */ + _chf_context.mrs_exit( _chf_context.mrs_data ); #ifndef _REENTRANT - /* Free the dynamic memory previously allocated */ - free(_chf_context.message_buffer); - free(_chf_context.handler_stack); - free(_chf_context.condition_stack); + /* Free the dynamic memory previously allocated */ + free( _chf_context.message_buffer ); + free( _chf_context.handler_stack ); + free( _chf_context.condition_stack ); #else - /* Destroy the Chf data key */ - if(pthread_key_delete(data_key)) ChfAbort(CHF_ABORT_PTHREAD); + /* Destroy the Chf data key */ + if ( pthread_key_delete( data_key ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif - /* Reset CHF state to prevent subsequent calls to ChfExit() itself */ - _chf_context.state = CHF_UNKNOWN; + /* Reset CHF state to prevent subsequent calls to ChfExit() itself */ + _chf_context.state = CHF_UNKNOWN; #ifdef _REENTRANT - if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD); + if ( pthread_mutex_unlock( &context_mutex ) ) + ChfAbort( CHF_ABORT_PTHREAD ); #endif } - /* .+ .title : _ChfGetContext @@ -701,80 +667,66 @@ void ChfExit( successful call to ChfInit(). .call : - context = _ChfGetContext(void); + context = _ChfGetContext(void); .input : .output : - ChfContext *context, per-thread Chf context + ChfContext *context, per-thread Chf context .status_codes : - none + none .notes : 2.1, 19-May-2000, creation .- */ -ChfContext *_ChfGetContext( - void -) +ChfContext* _ChfGetContext( void ) { - ChfContext *context; + ChfContext* context; #ifndef _REENTRANT - /* This function is doomed to fail if _REENTRANT is not defined */ - ChfAbort(CHF_ABORT_GET_CONTEXT); - return((ChfContext *)NULL); + /* This function is doomed to fail if _REENTRANT is not defined */ + ChfAbort( CHF_ABORT_GET_CONTEXT ); + return ( ( ChfContext* )NULL ); #else - /* Get the thread-specific context pointer associated with the - CHF data key */ - if((context = (ChfContext *)pthread_getspecific(data_key)) - == (ChfContext *)NULL) - { - /* No context pointer; prime a new one, cloning the master context */ - if((context = (ChfContext *)malloc(sizeof(ChfContext))) - == (ChfContext *)NULL) - ChfAbort(CHF_ABORT_GET_CONTEXT); + /* Get the thread-specific context pointer associated with the + CHF data key */ + if ( ( context = ( ChfContext* )pthread_getspecific( data_key ) ) == ( ChfContext* )NULL ) { + /* No context pointer; prime a new one, cloning the master context */ + if ( ( context = ( ChfContext* )malloc( sizeof( ChfContext ) ) ) == ( ChfContext* )NULL ) + ChfAbort( CHF_ABORT_GET_CONTEXT ); - memcpy(context, &_chf_context, sizeof(ChfContext)); + memcpy( context, &_chf_context, sizeof( ChfContext ) ); - /* Allocate per-thread stacks and message buffer */ - if((context->condition_stack = - (ChfDescriptor *) - malloc((size_t)(context->condition_stack_size+1) - *sizeof(ChfDescriptor))) == CHF_NULL_DESCRIPTOR) - ChfAbort(CHF_ABORT_GET_CONTEXT); + /* Allocate per-thread stacks and message buffer */ + if ( ( context->condition_stack = ( ChfDescriptor* )malloc( ( size_t )( context->condition_stack_size + 1 ) * + sizeof( ChfDescriptor ) ) ) == CHF_NULL_DESCRIPTOR ) + ChfAbort( CHF_ABORT_GET_CONTEXT ); - if((context->handler_stack = - (ChfHandlerDescriptor *) - malloc((size_t)(context->handler_stack_size) - *sizeof(ChfHandlerDescriptor))) == (ChfHandlerDescriptor *)NULL) - { - free(context->condition_stack); - ChfAbort(CHF_ABORT_GET_CONTEXT); + if ( ( context->handler_stack = ( ChfHandlerDescriptor* )malloc( + ( size_t )( context->handler_stack_size ) * sizeof( ChfHandlerDescriptor ) ) ) == ( ChfHandlerDescriptor* )NULL ) { + free( context->condition_stack ); + ChfAbort( CHF_ABORT_GET_CONTEXT ); + } + + if ( ( context->message_buffer = ( char* )malloc( ( size_t )( CHF_MAX_MESSAGE_LENGTH ) ) ) == ( char* )NULL ) { + free( context->condition_stack ); + free( context->handler_stack ); + ChfAbort( CHF_ABORT_GET_CONTEXT ); + } + + /* Initialize stack pointers */ + context->condition_base = context->condition_sp = context->condition_stack; + context->handler_sp = context->handler_stack; + + /* Set the thread-specific context pointer; this must be done + before invoking any other function using the context, + including ChfPushHandler() below. + */ + if ( pthread_setspecific( data_key, context ) ) + ChfAbort( CHF_ABORT_GET_CONTEXT ); + + /* Push the default handler */ + ChfPushHandler( DefaultHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER ); } - if((context->message_buffer = - (char *) - malloc((size_t)(CHF_MAX_MESSAGE_LENGTH))) == (char *)NULL) - { - free(context->condition_stack); - free(context->handler_stack); - ChfAbort(CHF_ABORT_GET_CONTEXT); - } - - /* Initialize stack pointers */ - context->condition_base = context->condition_sp = - context->condition_stack; - context->handler_sp = context->handler_stack; - - /* Set the thread-specific context pointer; this must be done - before invoking any other function using the context, - including ChfPushHandler() below. - */ - if(pthread_setspecific(data_key, context)) - ChfAbort(CHF_ABORT_GET_CONTEXT); - - /* Push the default handler */ - ChfPushHandler(DefaultHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER); - } - - return context; + return context; #endif } diff --git a/src/libChf/chf_msgc.c b/src/libChf/chf_msgc.c index d8f712f..5b5ca66 100644 --- a/src/libChf/chf_msgc.c +++ b/src/libChf/chf_msgc.c @@ -35,24 +35,23 @@ static char rcs_id[] = "$Id: chf_msgc.c,v 2.2 2001/01/25 14:06:47 cibrario Exp $ #include #include #ifndef _WIN32 -#include +# include #endif #include #include #ifndef _WIN32 -#include -#include +# include +# include #endif #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* ------------------------------------------------------------------------- Global and static variables ------------------------------------------------------------------------- */ @@ -62,41 +61,28 @@ static char rcs_id[] = "$Id: chf_msgc.c,v 2.2 2001/01/25 14:06:47 cibrario Exp $ ------------------------------------------------------------------------- */ #ifndef _WIN32 -typedef struct -{ - nl_catd catalog; /* Message catalog descriptor */ -} - ChfMsgcatContext; +typedef struct { + nl_catd catalog; /* Message catalog descriptor */ +} ChfMsgcatContext; #endif - /* ------------------------------------------------------------------------- Private functions ------------------------------------------------------------------------- */ - #ifndef _WIN32 -static const char *GetMessage( - void *private_context, - const int module_id, - const int condition_code, - const char *default_message -) +static const char* GetMessage( void* private_context, const int module_id, const int condition_code, const char* default_message ) { - return(catgets(((ChfMsgcatContext *)private_context)->catalog, module_id, - condition_code, default_message)); + return ( catgets( ( ( ChfMsgcatContext* )private_context )->catalog, module_id, condition_code, default_message ) ); } -static void ExitMessage( - void *private_context -) +static void ExitMessage( void* private_context ) { - (void)catclose(((ChfMsgcatContext *)private_context)->catalog); - free(private_context); + ( void )catclose( ( ( ChfMsgcatContext* )private_context )->catalog ); + free( private_context ); } #endif - /* ------------------------------------------------------------------------- Public functions ------------------------------------------------------------------------- */ @@ -115,7 +101,7 @@ static void ExitMessage( other CHF initialization routines before using any other CHF function. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_DUP_INIT - if CHF has already been initialized before. + if CHF has already been initialized before. WIN32: @@ -123,79 +109,72 @@ static void ExitMessage( always returns CHF_F_NOT_AVAILABLE .call : - cc = ChfMsgcatInit(app_name, options, - msgcat_name, - condition_stack_size, handler_stack_size, - exit_code); + cc = ChfMsgcatInit(app_name, options, + msgcat_name, + condition_stack_size, handler_stack_size, + exit_code); .input : - const char *app_name, Application's name - const ChfOptions options, Options - const char *msgcat_name, Name of the message catalog - const int condition_stack_size, Size of the condition stack - const int handler_stack_size, Size of the handler stack - const int exit_code, Abnormal exit code + const char *app_name, Application's name + const ChfOptions options, Options + const char *msgcat_name, Name of the message catalog + const int condition_stack_size, Size of the condition stack + const int handler_stack_size, Size of the handler stack + const int exit_code, Abnormal exit code .output : - int cc, condition code + int cc, condition code .status_codes : - CHF_F_SETLOCALE, setlocale() failed - CHF_F_CATOPEN, catopen() failed - CHF_F_MALLOC, FATAL, memory allocation failed - CHF_F_NOT_AVAILABLE, FATAL, function not available + CHF_F_SETLOCALE, setlocale() failed + CHF_F_CATOPEN, catopen() failed + CHF_F_MALLOC, FATAL, memory allocation failed + CHF_F_NOT_AVAILABLE, FATAL, function not available .notes : 1.1, 17-May-1996, creation 2.2, 22-Jan-2001, update: - added Win32 support .- */ -int ChfMsgcatInit( /* Initialization with msgcat subsystem */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - const ChfChar *msgcat_name, /* Name of the message catalog */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfMsgcatInit( /* Initialization with msgcat subsystem */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + const ChfChar* msgcat_name, /* Name of the message catalog */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ) { #ifdef _WIN32 - /* This function always fails in _WIN32, because message catalogs - are not supported. - */ - return CHF_F_NOT_AVAILABLE; + /* This function always fails in _WIN32, because message catalogs + are not supported. + */ + return CHF_F_NOT_AVAILABLE; #else - ChfMsgcatContext *private_context; - int cc; + ChfMsgcatContext* private_context; + int cc; - if((private_context = - (ChfMsgcatContext *)malloc(sizeof(ChfMsgcatContext))) == - (ChfMsgcatContext *)NULL) - cc = CHF_F_MALLOC; + if ( ( private_context = ( ChfMsgcatContext* )malloc( sizeof( ChfMsgcatContext ) ) ) == ( ChfMsgcatContext* )NULL ) + cc = CHF_F_MALLOC; - else if(setlocale(LC_ALL, "") == (char *)NULL) - { - free(private_context); - cc = CHF_F_SETLOCALE; - } + else if ( setlocale( LC_ALL, "" ) == ( char* )NULL ) { + free( private_context ); + cc = CHF_F_SETLOCALE; + } - else if((private_context->catalog = catopen(msgcat_name, 0)) == - (nl_catd)(-1)) - { - free(private_context); - cc = CHF_F_CATOPEN; - } + else if ( ( private_context->catalog = catopen( msgcat_name, 0 ) ) == ( nl_catd )( -1 ) ) { + free( private_context ); + cc = CHF_F_CATOPEN; + } - else if((cc = ChfInit(app_name, options, (void *)private_context, - GetMessage, ExitMessage, condition_stack_size, handler_stack_size, - exit_code)) != CHF_S_OK) - { - (void)catclose(private_context->catalog); - free(private_context); - } + else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, GetMessage, ExitMessage, condition_stack_size, + handler_stack_size, exit_code ) ) != CHF_S_OK ) { + ( void )catclose( private_context->catalog ); + free( private_context ); + } - else - cc = CHF_S_OK; + else + cc = CHF_S_OK; - return cc; + return cc; #endif } diff --git a/src/libChf/chf_sig.c b/src/libChf/chf_sig.c index d780447..8d0a707 100644 --- a/src/libChf/chf_sig.c +++ b/src/libChf/chf_sig.c @@ -44,19 +44,18 @@ static char rcs_id[] = "$Id: chf_sig.c,v 2.2 2001/01/25 14:07:42 cibrario Exp $" #include #include #ifndef _WIN32 -#include +# include #endif #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* .+ .title : ChfSignal @@ -68,26 +67,26 @@ static char rcs_id[] = "$Id: chf_sig.c,v 2.2 2001/01/25 14:07:42 cibrario Exp $" handlers. NOTE: This function uses the CHF function 'ChfAbort()' to - abort the application if either - - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) - - the last handler on the handler stack has returned an invalid action - code (abort code CHF_ABORT_INVALID_ACTION) - - one of the handlers has requested the CHF_UNWIND action while - CHF was already unwinding (abort code CHF_ABORT_ALREADY_UNWINDING) - - a CHF_FATAL condition was signalled while CHF was unwinding - (abort code CHF_ABORT_FATAL_UNWINDING) - - all the handlers refused to handle a condition (abort code - CHF_ABORT_IMPROPERLY_HANDLED) + abort the application if either + - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) + - the last handler on the handler stack has returned an invalid action + code (abort code CHF_ABORT_INVALID_ACTION) + - one of the handlers has requested the CHF_UNWIND action while + CHF was already unwinding (abort code CHF_ABORT_ALREADY_UNWINDING) + - a CHF_FATAL condition was signalled while CHF was unwinding + (abort code CHF_ABORT_FATAL_UNWINDING) + - all the handlers refused to handle a condition (abort code + CHF_ABORT_IMPROPERLY_HANDLED) .call : - ChfSignal(); + ChfSignal(); .input : - void + void .output : - void + void .status_codes : - (*) CHF_F_COND_STACK_FULL, the condition stack is full - (*) CHF_F_INVALID_ACTION, invalid handler action (%d) + (*) CHF_F_COND_STACK_FULL, the condition stack is full + (*) CHF_F_INVALID_ACTION, invalid handler action (%d) .notes : 1.1, 10-May-1996, creation 1.6, 15-Jan-1997, update & bug fix: @@ -99,269 +98,246 @@ static char rcs_id[] = "$Id: chf_sig.c,v 2.2 2001/01/25 14:07:42 cibrario Exp $" - added support for structured condition handling .- */ -void ChfSignal( - void -) +void ChfSignal( void ) { - ChfState saved_state; - ChfDescriptor *saved_condition_base; - ChfDescriptor *current_condition; - ChfHandlerDescriptor *saved_handler_sp; - ChfHandlerDescriptor *handler_up; - ChfHandlerDescriptor *unwind_handler; - ChfAction handler_result; + ChfState saved_state; + ChfDescriptor* saved_condition_base; + ChfDescriptor* current_condition; + ChfHandlerDescriptor* saved_handler_sp; + ChfHandlerDescriptor* handler_up; + ChfHandlerDescriptor* unwind_handler; + ChfAction handler_result; - /* Check that CHF has been correctly initialized and save the current CHF - state. If CHF was CHF_IDLE change state to CHF_SIGNALING, else if CHF was - CHF_UNWINDING change to CHF_SIGNAL_UNWINDING, otherwise remain in the - previous state (that must be CHF_SIGNALING) - */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); - saved_state = chf_context.state; - - if(chf_context.state == CHF_IDLE) - chf_context.state = CHF_SIGNALING; - else if(chf_context.state == CHF_UNWINDING) - chf_context.state = CHF_SIGNAL_UNWINDING; - - if(chf_context.condition_sp > chf_context.condition_base) - { - /* Save the base of the current condition group and then update it in - order to allow further generation of conditions inside the condition - handlers that will be called soon. + /* Check that CHF has been correctly initialized and save the current CHF + state. If CHF was CHF_IDLE change state to CHF_SIGNALING, else if CHF was + CHF_UNWINDING change to CHF_SIGNAL_UNWINDING, otherwise remain in the + previous state (that must be CHF_SIGNALING) */ - current_condition = chf_context.condition_sp-1; - saved_condition_base = chf_context.condition_base; - chf_context.condition_base = chf_context.condition_sp; + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); + saved_state = chf_context.state; - /* Save the current condition handler pointer */ - saved_handler_sp = chf_context.handler_sp; + if ( chf_context.state == CHF_IDLE ) + chf_context.state = CHF_SIGNALING; + else if ( chf_context.state == CHF_UNWINDING ) + chf_context.state = CHF_SIGNAL_UNWINDING; - /* Call the condition handlers; the loop will exit either: - - when the handler stack is empty, or - - when the current handler returns either CHF_CONTINUE or CHF_UNWIND - */ - handler_result = CHF_RESIGNAL; - while(handler_result == CHF_RESIGNAL && - chf_context.handler_sp > chf_context.handler_stack) - { - chf_context.handler_sp--; + if ( chf_context.condition_sp > chf_context.condition_base ) { + /* Save the base of the current condition group and then update it in + order to allow further generation of conditions inside the condition + handlers that will be called soon. + */ + current_condition = chf_context.condition_sp - 1; + saved_condition_base = chf_context.condition_base; + chf_context.condition_base = chf_context.condition_sp; - /* The current condition handler, described by chf_context.handler_sp, - can recursively invoke ChfGenerate() and ChfSignal(). - - ChfGenerate() will store the new condition group starting from - chf_context.condition_sp, that points to the first free slot - of the condition stack. During the first generation, since - chf_context.condition_sp == chf_context.condition_base, the - link pointer of the condition will be NULL and, therefore, - the condition will be the first of a new condition group. + /* Save the current condition handler pointer */ + saved_handler_sp = chf_context.handler_sp; - ChfSignal() will signal the condition group described by the - stack block from chf_context.condition_base to - chf_context.condition_sp-1, if it contains at least one condition; - it will call the handlers starting from chf_context.handler_sp-1, - that describes the handler immediately preceding the current handler. - */ - handler_result = chf_context.handler_sp->handler( - current_condition, chf_context.state, - chf_context.handler_sp->handler_context); + /* Call the condition handlers; the loop will exit either: + - when the handler stack is empty, or + - when the current handler returns either CHF_CONTINUE or CHF_UNWIND + */ + handler_result = CHF_RESIGNAL; + while ( handler_result == CHF_RESIGNAL && chf_context.handler_sp > chf_context.handler_stack ) { + chf_context.handler_sp--; - /* When the CHF state is CHF_SIGNALING, any condition group generated - but not yet signalled when the current handler exits must be merged - with the condition group currently being signalled, in order to allow - the condition handlers to add their own conditions to the condition - group. If the severity of the previous condition group was CHF_FATAL, - the severity of the new group is forced to CHF_FATAL, too. - - When the CHF state is CHF_UNWINDING, the condition group for - which the UNWIND has been requested is 'frozen', no further - modifications are allowed on it, and the condition group is simply - discarded. - */ - if(chf_context.condition_sp > chf_context.condition_base) - { - if(chf_context.state == CHF_SIGNALING) - { - /* Force the new severity to CHF_FATAL if necessary */ - if(ChfGetSeverity(current_condition) == CHF_FATAL) - ChfGetSeverity(chf_context.condition_sp-1) = CHF_FATAL; - - /* Link together the condition groups */ - chf_context.condition_base->next = current_condition; - current_condition = chf_context.condition_sp-1; - chf_context.condition_base = chf_context.condition_sp; - } - - else - chf_context.condition_sp = chf_context.condition_base; - } - - /* The action CHF_CONTINUE is not allowed if the current condition - severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL - */ - if(handler_result == CHF_CONTINUE && - ChfGetSeverity(current_condition) == CHF_FATAL) - handler_result = CHF_RESIGNAL; - } - - /* Perform the action requested by the last condition handler invoked */ - switch(handler_result) - { - case CHF_CONTINUE: - { - /* Restore the handler stack pointer; the next ChfSignal() invoked - from our same nesting level will invoke our same handler chain - again. - */ - chf_context.handler_sp = saved_handler_sp; - - /* Discard the current condition group */ - chf_context.condition_base = chf_context.condition_sp = - saved_condition_base; - - /* Restore che saved CHF state */ - chf_context.state = saved_state; - - /* Continue from the instruction following the ChfSignal() */ - break; - } - - case CHF_UNWIND: - case CHF_UNWIND_KEEP: - { - /* Unwind the execution stack. Check that another unwind isn't - already in progress - */ - if(chf_context.state == CHF_UNWINDING) - ChfAbort(CHF_ABORT_ALREADY_UNWINDING); - - else - { - /* Change CHF state */ - chf_context.state = CHF_UNWINDING; - - /* chf_context.handler_sp points to the condition handler that - has requested the unwind; call all the handlers again, starting - from saved_handler_sp (top of the handler stack) up to and - including chf_context.handler_sp. - */ - handler_up = saved_handler_sp; - - while(handler_up > chf_context.handler_sp) - { - ChfAction unw_handler_result; - handler_up--; - - /* The current condition handler, described by handler_up + /* The current condition handler, described by chf_context.handler_sp, can recursively invoke ChfGenerate() and ChfSignal(). - - ChfGenerate() will store the new condition group starting from - chf_context.condition_sp, that points to the first free slot - of the condition stack. During the first generation, since - chf_context.condition_sp == chf_context.condition_base, the - link pointer of the condition will be NULL and, therefore, - the condition will be the first of a new condition group. - ChfSignal() will generate the condition group described by the - stack block from chf_context.condition_base to - chf_context.condition_sp-1, if it contains at least one - condition; it will call the handlers starting from - chf_context.handler_sp-1, that describes the handler - immediately preceding the handler that has requested the unwind. + ChfGenerate() will store the new condition group starting from + chf_context.condition_sp, that points to the first free slot + of the condition stack. During the first generation, since + chf_context.condition_sp == chf_context.condition_base, the + link pointer of the condition will be NULL and, therefore, + the condition will be the first of a new condition group. - Further unwind requests are not allowed, and will trigger - the condition CHF_F_UNWINDING + ChfSignal() will signal the condition group described by the + stack block from chf_context.condition_base to + chf_context.condition_sp-1, if it contains at least one condition; + it will call the handlers starting from chf_context.handler_sp-1, + that describes the handler immediately preceding the current handler. */ - unw_handler_result = handler_up->handler( - current_condition, chf_context.state, - handler_up->handler_context); + handler_result = + chf_context.handler_sp->handler( current_condition, chf_context.state, chf_context.handler_sp->handler_context ); - /* When the CHF state is CHF_UNWINDING, any condition group - generated but not yet signalled when the current handler - returns must be discarded - */ - chf_context.condition_sp = chf_context.condition_base; - } + /* When the CHF state is CHF_SIGNALING, any condition group generated + but not yet signalled when the current handler exits must be merged + with the condition group currently being signalled, in order to allow + the condition handlers to add their own conditions to the condition + group. If the severity of the previous condition group was CHF_FATAL, + the severity of the new group is forced to CHF_FATAL, too. - /* Restore the handler stack pointer, discarding the unwinded - condition handlers. chf_context.handler_sp points to the - handler that requested the unwind; that handler has been - unwinded and its location is now the first free slot in the - condition handler stack. - */ - unwind_handler = chf_context.handler_sp; + When the CHF state is CHF_UNWINDING, the condition group for + which the UNWIND has been requested is 'frozen', no further + modifications are allowed on it, and the condition group is simply + discarded. + */ + if ( chf_context.condition_sp > chf_context.condition_base ) { + if ( chf_context.state == CHF_SIGNALING ) { + /* Force the new severity to CHF_FATAL if necessary */ + if ( ChfGetSeverity( current_condition ) == CHF_FATAL ) + ChfGetSeverity( chf_context.condition_sp - 1 ) = CHF_FATAL; - if(handler_result == CHF_UNWIND) - { - /* Normal unwind: - restore the condition stack pointers, discarding all condition - groups. - */ - chf_context.condition_base = chf_context.condition_sp = - chf_context.condition_stack; - } - else - { - /* Special unwind for structured condition handling: - restore the condition_base pointer only, to keep the - topmost condition group on the condition stack. This way, - the condition group remains accessible after the unwind. - */ - chf_context.condition_base = saved_condition_base; - } + /* Link together the condition groups */ + chf_context.condition_base->next = current_condition; + current_condition = chf_context.condition_sp - 1; + chf_context.condition_base = chf_context.condition_sp; + } - /* Change the CHF state to CHF_IDLE, and execute longjmp(). - If the handler hasn't a valid unwind_context associated with it, - simply abort the application. - */ - chf_context.state = CHF_IDLE; + else + chf_context.condition_sp = chf_context.condition_base; + } - if(unwind_handler->unwind_context == CHF_NULL_CONTEXT) - ChfAbort(CHF_ABORT_SILENT); - else - ChfSiglongjmp(unwind_handler->unwind_context, 1); - } + /* The action CHF_CONTINUE is not allowed if the current condition + severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL + */ + if ( handler_result == CHF_CONTINUE && ChfGetSeverity( current_condition ) == CHF_FATAL ) + handler_result = CHF_RESIGNAL; + } - break; - } + /* Perform the action requested by the last condition handler invoked */ + switch ( handler_result ) { + case CHF_CONTINUE: + { + /* Restore the handler stack pointer; the next ChfSignal() invoked + from our same nesting level will invoke our same handler chain + again. + */ + chf_context.handler_sp = saved_handler_sp; - case CHF_RESIGNAL: - { - ChfAbort( - (chf_context.state == CHF_SIGNALING) ? - CHF_ABORT_IMPROPERLY_HANDLED : CHF_ABORT_FATAL_UNWINDING); - - break; - } + /* Discard the current condition group */ + chf_context.condition_base = chf_context.condition_sp = saved_condition_base; - default: - { - /* Invalid handler action detected; generate and immediately signal a - condition if the broken handler isn't the last handler on the stack, - otherwise call ChfAbort() - */ - if(chf_context.handler_sp > chf_context.handler_stack) - { - ChfCondition CHF_F_INVALID_ACTION, CHF_FATAL, handler_result - ChfEnd; + /* Restore che saved CHF state */ + chf_context.state = saved_state; - ChfSignal(); - } + /* Continue from the instruction following the ChfSignal() */ + break; + } - else - ChfAbort(CHF_ABORT_INVALID_ACTION); + case CHF_UNWIND: + case CHF_UNWIND_KEEP: + { + /* Unwind the execution stack. Check that another unwind isn't + already in progress + */ + if ( chf_context.state == CHF_UNWINDING ) + ChfAbort( CHF_ABORT_ALREADY_UNWINDING ); - break; - } + else { + /* Change CHF state */ + chf_context.state = CHF_UNWINDING; + + /* chf_context.handler_sp points to the condition handler that + has requested the unwind; call all the handlers again, starting + from saved_handler_sp (top of the handler stack) up to and + including chf_context.handler_sp. + */ + handler_up = saved_handler_sp; + + while ( handler_up > chf_context.handler_sp ) { + ChfAction unw_handler_result; + handler_up--; + + /* The current condition handler, described by handler_up + can recursively invoke ChfGenerate() and ChfSignal(). + + ChfGenerate() will store the new condition group starting from + chf_context.condition_sp, that points to the first free slot + of the condition stack. During the first generation, since + chf_context.condition_sp == chf_context.condition_base, the + link pointer of the condition will be NULL and, therefore, + the condition will be the first of a new condition group. + + ChfSignal() will generate the condition group described by the + stack block from chf_context.condition_base to + chf_context.condition_sp-1, if it contains at least one + condition; it will call the handlers starting from + chf_context.handler_sp-1, that describes the handler + immediately preceding the handler that has requested the unwind. + + Further unwind requests are not allowed, and will trigger + the condition CHF_F_UNWINDING + */ + unw_handler_result = handler_up->handler( current_condition, chf_context.state, handler_up->handler_context ); + + /* When the CHF state is CHF_UNWINDING, any condition group + generated but not yet signalled when the current handler + returns must be discarded + */ + chf_context.condition_sp = chf_context.condition_base; + } + + /* Restore the handler stack pointer, discarding the unwinded + condition handlers. chf_context.handler_sp points to the + handler that requested the unwind; that handler has been + unwinded and its location is now the first free slot in the + condition handler stack. + */ + unwind_handler = chf_context.handler_sp; + + if ( handler_result == CHF_UNWIND ) { + /* Normal unwind: + restore the condition stack pointers, discarding all condition + groups. + */ + chf_context.condition_base = chf_context.condition_sp = chf_context.condition_stack; + } else { + /* Special unwind for structured condition handling: + restore the condition_base pointer only, to keep the + topmost condition group on the condition stack. This way, + the condition group remains accessible after the unwind. + */ + chf_context.condition_base = saved_condition_base; + } + + /* Change the CHF state to CHF_IDLE, and execute longjmp(). + If the handler hasn't a valid unwind_context associated with it, + simply abort the application. + */ + chf_context.state = CHF_IDLE; + + if ( unwind_handler->unwind_context == CHF_NULL_CONTEXT ) + ChfAbort( CHF_ABORT_SILENT ); + else + ChfSiglongjmp( unwind_handler->unwind_context, 1 ); + } + + break; + } + + case CHF_RESIGNAL: + { + ChfAbort( ( chf_context.state == CHF_SIGNALING ) ? CHF_ABORT_IMPROPERLY_HANDLED : CHF_ABORT_FATAL_UNWINDING ); + + break; + } + + default: + { + /* Invalid handler action detected; generate and immediately signal a + condition if the broken handler isn't the last handler on the stack, + otherwise call ChfAbort() + */ + if ( chf_context.handler_sp > chf_context.handler_stack ) { + ChfCondition CHF_F_INVALID_ACTION, CHF_FATAL, handler_result ChfEnd; + + ChfSignal(); + } + + else + ChfAbort( CHF_ABORT_INVALID_ACTION ); + + break; + } + } } - } - /* Restore the old CHF state */ - chf_context.state = saved_state; + /* Restore the old CHF state */ + chf_context.state = saved_state; } - /* .+ .title : ChfDiscard @@ -373,30 +349,30 @@ void ChfSignal( the condition stack is empty. NOTE: This function uses the CHF function 'ChfAbort()' to - abort the application if either - - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) + abort the application if either + - CHF has not been initialized correctly (abort code CHF_ABORT_INIT) .call : - ChfDiscard(); + ChfDiscard(); .input : - void + void .output : - void + void .status_codes : - none + none .notes : 1.1, 17-May-1996, creation .- */ -void ChfDiscard( /* Discard the current conditions */ - void -) +void ChfDiscard( /* Discard the current conditions */ + void ) { - /* Check that CHF has been correctly initialized */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Check that CHF has been correctly initialized */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - /* Reset the current condition stack pointer to the current condition - stack base pointer - */ - chf_context.condition_sp = chf_context.condition_base; + /* Reset the current condition stack pointer to the current condition + stack base pointer + */ + chf_context.condition_sp = chf_context.condition_base; } diff --git a/src/libChf/chf_st.c b/src/libChf/chf_st.c index 5f2134b..81f5eae 100644 --- a/src/libChf/chf_st.c +++ b/src/libChf/chf_st.c @@ -31,20 +31,19 @@ static char rcs_id[] = "$Id: chf_st.c,v 2.2 2001/01/25 14:08:45 cibrario Exp $"; #include #include #ifndef _WIN32 -#include +# include #endif #include #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* ------------------------------------------------------------------------- Global and static variables ------------------------------------------------------------------------- */ @@ -53,13 +52,10 @@ static char rcs_id[] = "$Id: chf_st.c,v 2.2 2001/01/25 14:08:45 cibrario Exp $"; Private type definitions ------------------------------------------------------------------------- */ -typedef struct -{ - const ChfTable *table; - size_t size; -} - ChfStaticContext; - +typedef struct { + const ChfTable* table; + size_t size; +} ChfStaticContext; /* ------------------------------------------------------------------------- Private functions @@ -69,88 +65,67 @@ typedef struct /* Win32 does not have bsearch(); provide a simple one from glibc here. */ -static void *bsearch( - const void *key, - const void *base, - size_t nmemb, - size_t size, - int (*compar)(const void *, const void *) -) +static void* bsearch( const void* key, const void* base, size_t nmemb, size_t size, int ( *compar )( const void*, const void* ) ) { - size_t l, u, idx; - const void *p; - int comparison; + size_t l, u, idx; + const void* p; + int comparison; - l = 0; - u = nmemb; - while (l < u) - { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compar) (key, p); - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else - return (void *) p; + l = 0; + u = nmemb; + while ( l < u ) { + idx = ( l + u ) / 2; + p = ( void* )( ( ( const char* )base ) + ( idx * size ) ); + comparison = ( *compar )( key, p ); + if ( comparison < 0 ) + u = idx; + else if ( comparison > 0 ) + l = idx + 1; + else + return ( void* )p; } - return NULL; + return NULL; } #endif -#define GT 1 -#define LT -1 -#define EQ 0 +#define GT 1 +#define LT -1 +#define EQ 0 -static int Search( - const void *l, - const void *r -) +static int Search( const void* l, const void* r ) { - if(((ChfTable *)l)->module > ((ChfTable *)r)->module) - return(GT); + if ( ( ( ChfTable* )l )->module > ( ( ChfTable* )r )->module ) + return ( GT ); - else if(((ChfTable *)l)->module < ((ChfTable *)r)->module) - return(LT); + else if ( ( ( ChfTable* )l )->module < ( ( ChfTable* )r )->module ) + return ( LT ); - else if(((ChfTable *)l)->code > ((ChfTable *)r)->code) - return(GT); + else if ( ( ( ChfTable* )l )->code > ( ( ChfTable* )r )->code ) + return ( GT ); - else if(((ChfTable *)l)->code < ((ChfTable *)r)->code) - return(LT); + else if ( ( ( ChfTable* )l )->code < ( ( ChfTable* )r )->code ) + return ( LT ); - return(EQ); + return ( EQ ); } -static const ChfChar *StGetMessage( - void *private_context, - const int module_id, - const int condition_code, - const ChfChar *default_message -) +static const ChfChar* StGetMessage( void* private_context, const int module_id, const int condition_code, const ChfChar* default_message ) { - ChfTable key; - ChfTable *res; + ChfTable key; + ChfTable* res; - key.module = module_id; - key.code = condition_code; + key.module = module_id; + key.code = condition_code; - if((res = bsearch(&key, ((ChfStaticContext *)private_context)->table, - ((ChfStaticContext *)private_context)->size, sizeof(ChfTable), Search)) == - (void *)NULL) - return(default_message); + if ( ( res = bsearch( &key, ( ( ChfStaticContext* )private_context )->table, ( ( ChfStaticContext* )private_context )->size, + sizeof( ChfTable ), Search ) ) == ( void* )NULL ) + return ( default_message ); - return(((ChfTable *)res)->msg_template); -} - -static void ExitMessage( - void *private_context -) -{ + return ( ( ( ChfTable* )res )->msg_template ); } +static void ExitMessage( void* private_context ) {} /* ------------------------------------------------------------------------- Public functions @@ -170,58 +145,54 @@ static void ExitMessage( other CHF initialization routines before using any other CHF function. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_DUP_INIT - if CHF has already been initialized before. + if CHF has already been initialized before. .call : - cc = ChfStaticInit(app_name, options, - table, table_size, - condition_stack_size, handler_stack_size, - exit_code); + cc = ChfStaticInit(app_name, options, + table, table_size, + condition_stack_size, handler_stack_size, + exit_code); .input : - const char *app_name, Application's name - const ChfOptions options, Options - const ChfTable *table, pointer to the static message table - const size_t table_size, size of the table (# of entries) - const int condition_stack_size, Size of the condition stack - const int handler_stack_size, Size of the handler stack - const int exit_code, Abnormal exit code + const char *app_name, Application's name + const ChfOptions options, Options + const ChfTable *table, pointer to the static message table + const size_t table_size, size of the table (# of entries) + const int condition_stack_size, Size of the condition stack + const int handler_stack_size, Size of the handler stack + const int exit_code, Abnormal exit code .output : - int cc, condition code + int cc, condition code .status_codes : - CHF_F_MALLOC, FATAL, memory allocation failed + CHF_F_MALLOC, FATAL, memory allocation failed .notes : 1.1, 27-May-1996, creation .- */ -int ChfStaticInit( /* Initialization with static message tables */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ - const ChfTable *table, /* Static message table */ - const size_t table_size, /* Size of the message table */ - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ +int ChfStaticInit( /* Initialization with static message tables */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ + const ChfTable* table, /* Static message table */ + const size_t table_size, /* Size of the message table */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ) { - ChfStaticContext *private_context; - int cc; + ChfStaticContext* private_context; + int cc; - if((private_context = - (ChfStaticContext *)malloc(sizeof(ChfStaticContext))) == - (ChfStaticContext *)NULL) - cc = CHF_F_MALLOC; + if ( ( private_context = ( ChfStaticContext* )malloc( sizeof( ChfStaticContext ) ) ) == ( ChfStaticContext* )NULL ) + cc = CHF_F_MALLOC; - else if((cc = ChfInit(app_name, options, (void *)private_context, - StGetMessage, ExitMessage, condition_stack_size, handler_stack_size, - exit_code)) != CHF_S_OK) - free(private_context); + else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, StGetMessage, ExitMessage, condition_stack_size, + handler_stack_size, exit_code ) ) != CHF_S_OK ) + free( private_context ); - else - { - private_context->table = table; - private_context->size = table_size; - cc = CHF_S_OK; - } + else { + private_context->table = table; + private_context->size = table_size; + cc = CHF_S_OK; + } - return cc; + return cc; } diff --git a/src/libChf/chf_top.c b/src/libChf/chf_top.c index da6b824..9aac214 100644 --- a/src/libChf/chf_top.c +++ b/src/libChf/chf_top.c @@ -35,20 +35,19 @@ static char rcs_id[] = "$Id: chf_top.c,v 2.2 2001/01/25 14:09:21 cibrario Exp $" #include #include #ifndef _WIN32 -#include +# include #endif #include #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* ------------------------------------------------------------------------- Public functions ------------------------------------------------------------------------- */ @@ -65,51 +64,50 @@ static char rcs_id[] = "$Id: chf_top.c,v 2.2 2001/01/25 14:09:21 cibrario Exp $" NOTE: During condition signalling, CHF creates a new, empty, condition group - immediately before starting the invocation sequence of the condition - handlers, as described in the documentation. Therefore - ChfGetTopCondition(), if called from a condition handler, will return - a pointer to the top condition generated during the handling ONLY, and - NOT to the top condition of the condition group being signalled. The - latter pointer is directly available, as an argument, to the condition - handlers. + immediately before starting the invocation sequence of the condition + handlers, as described in the documentation. Therefore + ChfGetTopCondition(), if called from a condition handler, will return + a pointer to the top condition generated during the handling ONLY, and + NOT to the top condition of the condition group being signalled. The + latter pointer is directly available, as an argument, to the condition + handlers. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_INIT - if CHF hasn't been correctly initialized. + if CHF hasn't been correctly initialized. NOTE: The returned pointer is no longer valid when any other CHF function - is called after ChfGetTopCondition(). + is called after ChfGetTopCondition(). .call : - d = ChfGetTopCondition(); + d = ChfGetTopCondition(); .input : - void + void .output : - const ChfDescriptor *d, condition descriptor + const ChfDescriptor *d, condition descriptor .status_codes : - + .notes : 1.2, 17-May-1996, creation 2.1, 24-May-2000, bug fix: - condition stack referenced incorrectly .- */ -const ChfDescriptor *ChfGetTopCondition( /* Retrieve top condition */ - void -) +const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */ + void ) { - ChfDescriptor *d; + ChfDescriptor* d; - /* Check that CHF has been correctly initialized */ - if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT); + /* Check that CHF has been correctly initialized */ + if ( chf_context.state == CHF_UNKNOWN ) + ChfAbort( CHF_ABORT_INIT ); - if((d = chf_context.condition_sp) == chf_context.condition_base) - { - ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd; - ChfSignal(); - } + if ( ( d = chf_context.condition_sp ) == chf_context.condition_base ) { + ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd; + ChfSignal(); + } - /* The top element of the condition group is the element immediately - below the stack pointer. - */ - return d-1; + /* The top element of the condition group is the element immediately + below the stack pointer. + */ + return d - 1; } diff --git a/src/libChf/chf_win32.c b/src/libChf/chf_win32.c index 7fd7eaf..0dc0afc 100644 --- a/src/libChf/chf_win32.c +++ b/src/libChf/chf_win32.c @@ -28,20 +28,19 @@ static char rcs_id[] = "$Id: chf_win32.c,v 2.2 2001/01/25 14:11:58 cibrario Exp #include #include #ifndef _WIN32 -#include +# include #endif #include #include #ifdef _WIN32 -#include -#include +# include +# include #endif #include "Chf.h" #include "ChfPriv.h" - /* ------------------------------------------------------------------------- Global and static variables ------------------------------------------------------------------------- */ @@ -51,46 +50,30 @@ static char rcs_id[] = "$Id: chf_win32.c,v 2.2 2001/01/25 14:11:58 cibrario Exp ------------------------------------------------------------------------- */ #ifdef _WIN32 -typedef struct -{ - HINSTANCE instance; /* App. instance handle */ - ChfChar buffer[CHF_MAX_MESSAGE_LENGTH]; /* Temporary buffer */ -} - ChfWin32Context; +typedef struct { + HINSTANCE instance; /* App. instance handle */ + ChfChar buffer[ CHF_MAX_MESSAGE_LENGTH ]; /* Temporary buffer */ +} ChfWin32Context; #endif - /* ------------------------------------------------------------------------- Private functions ------------------------------------------------------------------------- */ #ifdef _WIN32 -static const ChfChar *Win32GetMessage( - void *private_context, - const int module_id, - const int condition_code, - const ChfChar *default_message -) +static const ChfChar* Win32GetMessage( void* private_context, const int module_id, const int condition_code, + const ChfChar* default_message ) { - if(!LoadString( - ((ChfWin32Context *)private_context)->instance, - module_id*1000 + condition_code, - ((ChfWin32Context *)private_context)->buffer, - CHF_MAX_MESSAGE_LENGTH-1)) - return default_message; + if ( !LoadString( ( ( ChfWin32Context* )private_context )->instance, module_id * 1000 + condition_code, + ( ( ChfWin32Context* )private_context )->buffer, CHF_MAX_MESSAGE_LENGTH - 1 ) ) + return default_message; - return ((ChfWin32Context *)private_context)->buffer; + return ( ( ChfWin32Context* )private_context )->buffer; } -static void ExitMessage( - void *private_context -) -{ - free(private_context); -} +static void ExitMessage( void* private_context ) { free( private_context ); } #endif - /* ------------------------------------------------------------------------- Public functions ------------------------------------------------------------------------- */ @@ -109,7 +92,7 @@ static void ExitMessage( other CHF initialization routines before using any other CHF function. NOTE: This function will call ChfAbort() with abort code CHF_ABORT_DUP_INIT - if CHF has already been initialized before. + if CHF has already been initialized before. WIN32: @@ -124,68 +107,63 @@ static void ExitMessage( 0 <= module_id <= 64 .call : - cc = ChfWin32Init(app_name, options, - msgcat_name, - condition_stack_size, handler_stack_size, - exit_code); + cc = ChfWin32Init(app_name, options, + msgcat_name, + condition_stack_size, handler_stack_size, + exit_code); .input : - const ChfChar *app_name, Application's name - const ChfOptions options, Options - HINSTANCE instance, App. instance handle - const int condition_stack_size, Size of the condition stack - const int handler_stack_size, Size of the handler stack - const int exit_code, Abnormal exit code + const ChfChar *app_name, Application's name + const ChfOptions options, Options + HINSTANCE instance, App. instance handle + const int condition_stack_size, Size of the condition stack + const int handler_stack_size, Size of the handler stack + const int exit_code, Abnormal exit code .output : - int cc, condition code + int cc, condition code .status_codes : - CHF_F_MALLOC, FATAL, memory allocation failed - CHF_F_NOT_AVAILABLE, FATAL, function not available + CHF_F_MALLOC, FATAL, memory allocation failed + CHF_F_NOT_AVAILABLE, FATAL, function not available .notes : 2.2, 19-Jan-2001, creation .- */ -int ChfWin32Init( /* Initialization within _WIN32 */ - const ChfChar *app_name, /* Application's name */ - const ChfOptions options, /* Options */ +int ChfWin32Init( /* Initialization within _WIN32 */ + const ChfChar* app_name, /* Application's name */ + const ChfOptions options, /* Options */ #ifndef _WIN32 - void *instance, /* Fake arguments */ + void* instance, /* Fake arguments */ #else - HINSTANCE instance, /* App. instance handle */ + HINSTANCE instance, /* App. instance handle */ #endif - const int condition_stack_size, /* Size of the condition stack */ - const int handler_stack_size, /* Size of the handler stack */ - const int exit_code /* Abnormal exit code */ + const int condition_stack_size, /* Size of the condition stack */ + const int handler_stack_size, /* Size of the handler stack */ + const int exit_code /* Abnormal exit code */ ) { #ifndef _WIN32 - /* This function is available only in Win32 */ - return CHF_F_NOT_AVAILABLE; + /* This function is available only in Win32 */ + return CHF_F_NOT_AVAILABLE; #else - ChfWin32Context *private_context; - int cc; + ChfWin32Context* private_context; + int cc; - if((private_context = - (ChfWin32Context *)malloc(sizeof(ChfWin32Context))) == - (ChfWin32Context *)NULL) - cc = CHF_F_MALLOC; + if ( ( private_context = ( ChfWin32Context* )malloc( sizeof( ChfWin32Context ) ) ) == ( ChfWin32Context* )NULL ) + cc = CHF_F_MALLOC; - else if((cc = ChfInit(app_name, options, (void *)private_context, - Win32GetMessage, ExitMessage, condition_stack_size, handler_stack_size, - exit_code)) != CHF_S_OK) - { - free(private_context); - } + else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, Win32GetMessage, ExitMessage, condition_stack_size, + handler_stack_size, exit_code ) ) != CHF_S_OK ) { + free( private_context ); + } - else - { - /* Save Win32 specific context items into private Chf context */ - private_context->instance = instance; + else { + /* Save Win32 specific context items into private Chf context */ + private_context->instance = instance; - cc = CHF_S_OK; - } + cc = CHF_S_OK; + } - return cc; + return cc; #endif } diff --git a/src/libChf/resource.h b/src/libChf/resource.h old mode 100755 new mode 100644 index 7940d7c..e0a81cc --- a/src/libChf/resource.h +++ b/src/libChf/resource.h @@ -4,12 +4,12 @@ // // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif +# ifndef APSTUDIO_READONLY_SYMBOLS +# define _APS_NEXT_RESOURCE_VALUE 101 +# define _APS_NEXT_COMMAND_VALUE 40001 +# define _APS_NEXT_CONTROL_VALUE 1000 +# define _APS_NEXT_SYMED_VALUE 101 +# endif #endif diff --git a/src/libChf/test01.c b/src/libChf/test01.c index fa3c177..570408a 100644 --- a/src/libChf/test01.c +++ b/src/libChf/test01.c @@ -11,64 +11,55 @@ #include #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" - -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; - const char *msg; + const char* msg; const ChfDescriptor *d, *e; - puts("test01"); + puts( "test01" ); - system("gencat test01.cat test01.msf"); - system("gencat test01.cat chf.msf"); + system( "gencat test01.cat test01.msf" ); + system( "gencat test01.cat chf.msf" ); /* Initialization */ - if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat", 50, 10, 1)) - exit(st); + if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) ) + exit( st ); /* ChfGetMessage: message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */ - msg = ChfGetMessage(CHF_MODULE_ID, 1, "Default_1"); - if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE); - msg = ChfGetMessage(CHF_MODULE_ID, 2, "Default_2"); - if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE); + msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" ); + if ( strcmp( msg, "Set_255,Message_1" ) ) + exit( EXIT_FAILURE ); + msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" ); + if ( strcmp( msg, "Default_2" ) ) + exit( EXIT_FAILURE ); /* Generate a condition and check descriptor; this is line 46 */ ChfCondition 3, CHF_WARNING, 456 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 3 - || d->severity != CHF_WARNING - || d->line_number != 46 - || strcmp(d->file_name, "test01.c") - || strcmp(d->message, "Set_255,Arg_456,Message_3") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 46 || + strcmp( d->file_name, "test01.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL ) + exit( EXIT_FAILURE ); /* Generate another condition and check; this is line 60 */ ChfCondition 4, CHF_INFO, "arg" ChfEnd; - if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - e->module_id != CHF_MODULE_ID - || e->condition_code != 4 - || e->severity != CHF_INFO - || e->line_number != 60 - || strcmp(e->file_name, "test01.c") - || strcmp(e->message, "Set_255,Arg_arg,Message_4") - || e->next != d - ) exit(EXIT_FAILURE); + if ( ( e = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 60 || + strcmp( e->file_name, "test01.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d ) + exit( EXIT_FAILURE ); /* Discard the previous condition group and create a new one */ ChfDiscard(); @@ -76,18 +67,13 @@ int main(int argc, char *argv[]) /* This is line 77 */ ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 5 - || d->severity != CHF_ERROR - || d->line_number != 77 - || strcmp(d->file_name, "test01.c") - || strcmp(d->message, "Set_255,Arg_456-789,Message_5") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 77 || + strcmp( d->file_name, "test01.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL ) + exit( EXIT_FAILURE ); /* Exit Chf */ ChfExit(); - exit(EXIT_SUCCESS); + exit( EXIT_SUCCESS ); } diff --git a/src/libChf/test02.c b/src/libChf/test02.c index 6219813..02438d9 100644 --- a/src/libChf/test02.c +++ b/src/libChf/test02.c @@ -11,54 +11,45 @@ #include #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" - -void *task(void *arg) +void* task( void* arg ) { - const char *msg; + const char* msg; const ChfDescriptor *d, *e; - printf("\tThread %d\n", (int)arg); + printf( "\tThread %d\n", ( int )arg ); /* message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */ - msg = ChfGetMessage(CHF_MODULE_ID, 1, "Default_1"); - if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE); - msg = ChfGetMessage(CHF_MODULE_ID, 2, "Default_2"); - if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE); + msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" ); + if ( strcmp( msg, "Set_255,Message_1" ) ) + exit( EXIT_FAILURE ); + msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" ); + if ( strcmp( msg, "Default_2" ) ) + exit( EXIT_FAILURE ); /* Generate a condition and check descriptor; this is line 36 */ ChfCondition 3, CHF_WARNING, 456 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 3 - || d->severity != CHF_WARNING - || d->line_number != 36 - || strcmp(d->file_name, "test02.c") - || strcmp(d->message, "Set_255,Arg_456,Message_3") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 36 || + strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL ) + exit( EXIT_FAILURE ); /* Generate another condition and check; this is line 50 */ ChfCondition 4, CHF_INFO, "arg" ChfEnd; - if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - e->module_id != CHF_MODULE_ID - || e->condition_code != 4 - || e->severity != CHF_INFO - || e->line_number != 50 - || strcmp(e->file_name, "test02.c") - || strcmp(e->message, "Set_255,Arg_arg,Message_4") - || e->next != d - ) exit(EXIT_FAILURE); + if ( ( e = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 50 || + strcmp( e->file_name, "test02.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d ) + exit( EXIT_FAILURE ); /* Discard the previous condition group and create a new one */ ChfDiscard(); @@ -66,56 +57,49 @@ void *task(void *arg) /* This is line 67 */ ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 5 - || d->severity != CHF_ERROR - || d->line_number != 67 - || strcmp(d->file_name, "test02.c") - || strcmp(d->message, "Set_255,Arg_456-789,Message_5") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 67 || + strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL ) + exit( EXIT_FAILURE ); - return (void *)0; + return ( void* )0; } -#define N_THREADS 50 +#define N_THREADS 50 -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; int i; - void *ret; + void* ret; #ifdef _REENTRANT - pthread_t t[N_THREADS]; + pthread_t t[ N_THREADS ]; #endif - puts("test02"); + puts( "test02" ); #ifdef _REENTRANT /* Initialization */ - if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat", 50, 10, 1)) - exit(st); + if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) ) + exit( st ); /* Create */ - for(i=0; i #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" - -void *task(void *arg) +void* task( void* arg ) { - const char *msg; + const char* msg; const ChfDescriptor *d, *e; /* The sleep() is here to increase contention between threads */ - sleep(1); + sleep( 1 ); - printf("\tThread %d\n", (int)arg); + printf( "\tThread %d\n", ( int )arg ); /* Generate a condition group and signal it */ - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - ChfCondition 7, CHF_INFO, (int)arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + ChfCondition 7, CHF_INFO, ( int )arg ChfEnd; /* The sleep() is here to increase contention between threads */ - sleep(1); + sleep( 1 ); ChfSignal(); - return (void *)0; + return ( void* )0; } -#define N_THREADS 50 +#define N_THREADS 50 -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; int i; - void *ret; + void* ret; #ifdef _REENTRANT - pthread_t t[N_THREADS]; + pthread_t t[ N_THREADS ]; #endif - puts("test03"); + puts( "test03" ); /* Initialization */ - if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat", 50, 10, 1)) - exit(st); + if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) ) + exit( st ); #ifdef _REENTRANT /* Create */ - for(i=0; i #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" -struct tdata_s -{ +struct tdata_s { const ChfDescriptor *d, *e; int phase; }; -ChfAction h1( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h1( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - struct tdata_s *tdata_p = (struct tdata_s *)p; + struct tdata_s* tdata_p = ( struct tdata_s* )p; ChfAction action; - if(c != tdata_p->e || - ChfGetNextDescriptor(c) != tdata_p->d) - { - ChfCondition 10, CHF_FATAL ChfEnd; - action = CHF_RESIGNAL; + if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) { + ChfCondition 10, CHF_FATAL ChfEnd; + action = CHF_RESIGNAL; } else - action = CHF_CONTINUE; + action = CHF_CONTINUE; return action; - } -ChfAction h2( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h2( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - struct tdata_s *tdata_p = (struct tdata_s *)p; + struct tdata_s* tdata_p = ( struct tdata_s* )p; ChfAction action; - switch(s) - { - case CHF_SIGNALING: - { - if(c != tdata_p->e - || ChfGetNextDescriptor(c) != tdata_p->d - || (tdata_p->phase != 2 && tdata_p->phase != 4)) - { - ChfCondition 10, CHF_FATAL ChfEnd; - action = CHF_RESIGNAL; - } + switch ( s ) { + case CHF_SIGNALING: + { + if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d || ( tdata_p->phase != 2 && tdata_p->phase != 4 ) ) { + ChfCondition 10, CHF_FATAL ChfEnd; + action = CHF_RESIGNAL; + } - else - { - action = (ChfGetConditionCode(c) != 8 ? CHF_CONTINUE : CHF_UNWIND); - } - break; - } - case CHF_UNWINDING: - { - if(tdata_p->phase != 4) exit(EXIT_FAILURE); - tdata_p->phase = 5; - action = CHF_CONTINUE; - break; - } - default: - { - exit(EXIT_FAILURE); - } + else { + action = ( ChfGetConditionCode( c ) != 8 ? CHF_CONTINUE : CHF_UNWIND ); + } + break; + } + case CHF_UNWINDING: + { + if ( tdata_p->phase != 4 ) + exit( EXIT_FAILURE ); + tdata_p->phase = 5; + action = CHF_CONTINUE; + break; + } + default: + { + exit( EXIT_FAILURE ); + } } return action; } -ChfAction h3( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h3( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - struct tdata_s *tdata_p = (struct tdata_s *)p; + struct tdata_s* tdata_p = ( struct tdata_s* )p; ChfAction action; /* This handler must be invoked only during the first signal */ - if(tdata_p->phase != 3) exit(EXIT_FAILURE); + if ( tdata_p->phase != 3 ) + exit( EXIT_FAILURE ); - switch(s) - { - case CHF_SIGNALING: - { - if(ChfGetConditionCode(c) != 9 || - ChfGetNextDescriptor(c) != NULL) - { - exit(EXIT_FAILURE); - } + switch ( s ) { + case CHF_SIGNALING: + { + if ( ChfGetConditionCode( c ) != 9 || ChfGetNextDescriptor( c ) != NULL ) { + exit( EXIT_FAILURE ); + } - else - { - tdata_p->phase = 4; - action = CHF_CONTINUE; - } - break; - } - default: - { - exit(EXIT_FAILURE); - } + else { + tdata_p->phase = 4; + action = CHF_CONTINUE; + } + break; + } + default: + { + exit( EXIT_FAILURE ); + } } return action; } -ChfAction h4( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h4( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - struct tdata_s *tdata_p = (struct tdata_s *)p; + struct tdata_s* tdata_p = ( struct tdata_s* )p; ChfAction action; /* This handler must be invoked only during the first signal */ - if(tdata_p->phase != 2) exit(EXIT_FAILURE); + if ( tdata_p->phase != 2 ) + exit( EXIT_FAILURE ); - switch(s) - { - case CHF_SIGNALING: - { - if(c != tdata_p->e - || ChfGetNextDescriptor(c) != tdata_p->d) - { - ChfCondition 10, CHF_FATAL ChfEnd; - action = CHF_RESIGNAL; - } + switch ( s ) { + case CHF_SIGNALING: + { + if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) { + ChfCondition 10, CHF_FATAL ChfEnd; + action = CHF_RESIGNAL; + } - else - { - /* This generates a new group and signals it */ - tdata_p->phase = 3; - ChfCondition 9, CHF_INFO ChfEnd; - ChfSignal(); + else { + /* This generates a new group and signals it */ + tdata_p->phase = 3; + ChfCondition 9, CHF_INFO ChfEnd; + ChfSignal(); - if(tdata_p->phase != 4) exit(EXIT_FAILURE); - tdata_p->phase = 5; + if ( tdata_p->phase != 4 ) + exit( EXIT_FAILURE ); + tdata_p->phase = 5; - if(c != tdata_p->e - || ChfGetNextDescriptor(c) != tdata_p->d) - { - ChfCondition 10, CHF_FATAL ChfEnd; - action = CHF_RESIGNAL; - } - else - action = CHF_CONTINUE; - } - break; - } - default: - { - exit(EXIT_FAILURE); - } + if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) { + ChfCondition 10, CHF_FATAL ChfEnd; + action = CHF_RESIGNAL; + } else + action = CHF_CONTINUE; + } + break; + } + default: + { + exit( EXIT_FAILURE ); + } } return action; } -void *task(void *arg) +void* task( void* arg ) { volatile struct tdata_s tdata; /* The sleep() is here to increase contention between threads */ - sleep(1); + sleep( 1 ); - printf("\tThread %d\n", (int)arg); + printf( "\tThread %d\n", ( int )arg ); /* Push the handler */ - ChfPushHandler(h1, NULL, (ChfPointer)(&tdata)); + ChfPushHandler( h1, NULL, ( ChfPointer )( &tdata ) ); /* Generate a condition group and signal it */ - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; tdata.d = ChfGetTopCondition(); - ChfCondition 7, CHF_INFO, (int)arg ChfEnd; + ChfCondition 7, CHF_INFO, ( int )arg ChfEnd; tdata.e = ChfGetTopCondition(); /* The sleep() is here to increase contention between threads */ - sleep(1); + sleep( 1 ); ChfSignal(); /* Pop the handler */ @@ -210,122 +178,117 @@ void *task(void *arg) and signal it; this checks that the handler has actually been removed. */ - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; tdata.d = NULL; - ChfCondition 7, CHF_INFO, (int)arg ChfEnd; + ChfCondition 7, CHF_INFO, ( int )arg ChfEnd; tdata.e = NULL; ChfSignal(); /* Conditional unwind test */ { - sigjmp_buf jb; + sigjmp_buf jb; - tdata.phase = 0; - if(setjmp(jb) == 0) - { - ChfPushHandler(h2, jb, (ChfPointer)(&tdata)); + tdata.phase = 0; + if ( setjmp( jb ) == 0 ) { + ChfPushHandler( h2, jb, ( ChfPointer )( &tdata ) ); - /* Generate a condition group and signal it */ - tdata.phase = 1; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - tdata.d = ChfGetTopCondition(); - ChfCondition 7, CHF_INFO, (int)arg ChfEnd; - tdata.e = ChfGetTopCondition(); + /* Generate a condition group and signal it */ + tdata.phase = 1; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + tdata.d = ChfGetTopCondition(); + ChfCondition 7, CHF_INFO, ( int )arg ChfEnd; + tdata.e = ChfGetTopCondition(); - /* This does not trigger an unwind */ - tdata.phase = 2; - ChfSignal(); + /* This does not trigger an unwind */ + tdata.phase = 2; + ChfSignal(); - tdata.phase = 3; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - tdata.d = ChfGetTopCondition(); - ChfCondition 8, CHF_INFO, (int)arg ChfEnd; - tdata.e = ChfGetTopCondition(); + tdata.phase = 3; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + tdata.d = ChfGetTopCondition(); + ChfCondition 8, CHF_INFO, ( int )arg ChfEnd; + tdata.e = ChfGetTopCondition(); - /* This MUST trigger an unwind */ - tdata.phase = 4; - ChfSignal(); + /* This MUST trigger an unwind */ + tdata.phase = 4; + ChfSignal(); - exit(EXIT_FAILURE); - - } - else - { - /* Unwind */ - if(tdata.phase != 5) - exit(EXIT_FAILURE); + exit( EXIT_FAILURE ); - ChfPopHandler(); - } + } else { + /* Unwind */ + if ( tdata.phase != 5 ) + exit( EXIT_FAILURE ); + + ChfPopHandler(); + } } /* Condition generation and signal while a signal is in progress; this requires two handlers. */ { - tdata.phase = 0; + tdata.phase = 0; - ChfPushHandler(h3, NULL, (ChfPointer)&tdata); - ChfPushHandler(h4, NULL, (ChfPointer)&tdata); + ChfPushHandler( h3, NULL, ( ChfPointer )&tdata ); + ChfPushHandler( h4, NULL, ( ChfPointer )&tdata ); - tdata.phase = 1; - ChfCondition 6, CHF_INFO, (int)arg ChfEnd; - tdata.d = ChfGetTopCondition(); - ChfCondition 7, CHF_INFO, (int)arg ChfEnd; - tdata.e = ChfGetTopCondition(); + tdata.phase = 1; + ChfCondition 6, CHF_INFO, ( int )arg ChfEnd; + tdata.d = ChfGetTopCondition(); + ChfCondition 7, CHF_INFO, ( int )arg ChfEnd; + tdata.e = ChfGetTopCondition(); - tdata.phase = 2; - ChfSignal(); + tdata.phase = 2; + ChfSignal(); - if(tdata.phase != 5) - exit(EXIT_FAILURE); + if ( tdata.phase != 5 ) + exit( EXIT_FAILURE ); - ChfPopHandler(); - ChfPopHandler(); + ChfPopHandler(); + ChfPopHandler(); } - return (void *)0; + return ( void* )0; } -#define N_THREADS 50 +#define N_THREADS 50 -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; int i; - void *ret; + void* ret; #ifdef _REENTRANT - pthread_t t[N_THREADS]; + pthread_t t[ N_THREADS ]; #endif - puts("test04"); + puts( "test04" ); /* Initialization */ - if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat", 50, 10, 1)) - exit(st); + if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) ) + exit( st ); #ifdef _REENTRANT /* Create */ - for(i=0; i #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" -#define H_STACK_SIZE 10 -#define C_STACK_SIZE 30 +#define H_STACK_SIZE 10 +#define C_STACK_SIZE 30 /* Dummy handler; pushed only to verify that the handler stack overflow checks are correct. */ -ChfAction h1( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) -{ - return CHF_RESIGNAL; -} +ChfAction h1( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { return CHF_RESIGNAL; } /* Overflow check handler; it unwinds if the CHF_F_HDLR_STACK_FULL condition is signalled exactly after H_STACK_SIZE-2 invocations of ChfPushHandler(), it resignals a modified condition if the condition is signalled too early */ -ChfAction h2( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h2( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - int push_count = *((int *)p); + int push_count = *( ( int* )p ); ChfAction action; - if(s == CHF_SIGNALING) - { - if(ChfGetModuleId(c) == CHF_SET - && ChfGetConditionCode(c) == CHF_F_HDLR_STACK_FULL) - { - /* Handler stack is full; check correctness of the descriptor */ - if(push_count == H_STACK_SIZE-2 - && ChfGetNextDescriptor(c) == NULL - && ChfGetSeverity(c) == CHF_FATAL) - action = CHF_UNWIND; - else - { - ChfCondition 11, CHF_FATAL, push_count, H_STACK_SIZE-2 - ChfEnd; - action = CHF_RESIGNAL; - } - } + if ( s == CHF_SIGNALING ) { + if ( ChfGetModuleId( c ) == CHF_SET && ChfGetConditionCode( c ) == CHF_F_HDLR_STACK_FULL ) { + /* Handler stack is full; check correctness of the descriptor */ + if ( push_count == H_STACK_SIZE - 2 && ChfGetNextDescriptor( c ) == NULL && ChfGetSeverity( c ) == CHF_FATAL ) + action = CHF_UNWIND; + else { + ChfCondition 11, CHF_FATAL, push_count, H_STACK_SIZE - 2 ChfEnd; + action = CHF_RESIGNAL; + } + } } else - action = CHF_RESIGNAL; + action = CHF_RESIGNAL; return action; } @@ -80,68 +62,55 @@ ChfAction h2( of ChfCondition, it resignals a modified condition if the condition is signalled too early */ -ChfAction h3( - const ChfDescriptor *c, - const ChfState s, - ChfPointer p -) +ChfAction h3( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { - int push_count = *((int *)p); + int push_count = *( ( int* )p ); ChfAction action; - if(s == CHF_SIGNALING) - { - if(ChfGetModuleId(c) == CHF_SET - && ChfGetConditionCode(c) == CHF_F_COND_STACK_FULL) - { - /* Handler stack is full; check correctness of the descriptor */ - if(push_count == C_STACK_SIZE - && ChfGetNextDescriptor(c) == NULL - && ChfGetSeverity(c) == CHF_FATAL) - action = CHF_UNWIND; - else - { - ChfCondition 12, CHF_FATAL, push_count, C_STACK_SIZE - ChfEnd; - action = CHF_RESIGNAL; - } - } + if ( s == CHF_SIGNALING ) { + if ( ChfGetModuleId( c ) == CHF_SET && ChfGetConditionCode( c ) == CHF_F_COND_STACK_FULL ) { + /* Handler stack is full; check correctness of the descriptor */ + if ( push_count == C_STACK_SIZE && ChfGetNextDescriptor( c ) == NULL && ChfGetSeverity( c ) == CHF_FATAL ) + action = CHF_UNWIND; + else { + ChfCondition 12, CHF_FATAL, push_count, C_STACK_SIZE ChfEnd; + action = CHF_RESIGNAL; + } + } } else - action = CHF_RESIGNAL; + action = CHF_RESIGNAL; return action; } - -void *task(void *arg) +void* task( void* arg ) { int push_count = 0; sigjmp_buf jb; /* The sleep() is here to increase contention between threads */ - sleep(1); + sleep( 1 ); - printf("\tThread %d\n", (int)arg); + printf( "\tThread %d\n", ( int )arg ); /* Check handler stack overflow checks */ - if(sigsetjmp(jb, 1) == 0) - { - int i; + if ( sigsetjmp( jb, 1 ) == 0 ) { + int i; - /* Push the handler */ - ChfPushHandler(h2, jb, (ChfPointer)(&push_count)); + /* Push the handler */ + ChfPushHandler( h2, jb, ( ChfPointer )( &push_count ) ); - /* The sleep() is here to increase contention between threads */ - sleep(1); + /* The sleep() is here to increase contention between threads */ + sleep( 1 ); - /* Push dummy handlers until an error should occur */ - for(; push_count #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" -#define H_STACK_SIZE 10 -#define C_STACK_SIZE 30 +#define H_STACK_SIZE 10 +#define C_STACK_SIZE 30 - -void *task(void *arg) +void* task( void* arg ) { volatile int phase = 0; ChfTry - { - phase = 1; - ChfCondition 20, CHF_SUCCESS ChfEnd; - ChfSignal(); + { + phase = 1; + ChfCondition 20, CHF_SUCCESS ChfEnd; + ChfSignal(); - phase = 2; - ChfCondition 20, CHF_INFO ChfEnd; - ChfSignal(); + phase = 2; + ChfCondition 20, CHF_INFO ChfEnd; + ChfSignal(); - phase = 3; - ChfCondition 20, CHF_WARNING ChfEnd; - ChfSignal(); + phase = 3; + ChfCondition 20, CHF_WARNING ChfEnd; + ChfSignal(); - phase = 4; - ChfCondition 20, CHF_ERROR ChfEnd; - ChfSignal(); + phase = 4; + ChfCondition 20, CHF_ERROR ChfEnd; + ChfSignal(); - phase = 5; - ChfCondition 20, CHF_FATAL ChfEnd; - ChfSignal(); + phase = 5; + ChfCondition 20, CHF_FATAL ChfEnd; + ChfSignal(); - /* Should not be reached */ - return (void *)EXIT_FAILURE; - } + /* Should not be reached */ + return ( void* )EXIT_FAILURE; + } ChfCatch - { - /* Catched an exception; check descriptor */ - const ChfDescriptor *d = ChfGetTopCondition(); - if(d == NULL - || ChfGetNextDescriptor(d) != NULL - || ChfGetModuleId(d) != CHF_MODULE_ID - || ChfGetConditionCode(d) != 20) - return (void *)EXIT_FAILURE; - } + { + /* Catched an exception; check descriptor */ + const ChfDescriptor* d = ChfGetTopCondition(); + if ( d == NULL || ChfGetNextDescriptor( d ) != NULL || ChfGetModuleId( d ) != CHF_MODULE_ID || ChfGetConditionCode( d ) != 20 ) + return ( void* )EXIT_FAILURE; + } ChfEndTry; /* Check that the condition stack actually is empty after catch */ - ChfTry - { - volatile const ChfDescriptor *e = ChfGetTopCondition(); - } + ChfTry { const volatile ChfDescriptor* e = ChfGetTopCondition(); } ChfCatch - { - const ChfDescriptor *d = ChfGetTopCondition(); - if(d == NULL - || ChfGetNextDescriptor(d) != NULL - || ChfGetModuleId(d) != CHF_SET - || ChfGetConditionCode(d) != CHF_F_BAD_STATE) - return (void *)EXIT_FAILURE; - } + { + const ChfDescriptor* d = ChfGetTopCondition(); + if ( d == NULL || ChfGetNextDescriptor( d ) != NULL || ChfGetModuleId( d ) != CHF_SET || + ChfGetConditionCode( d ) != CHF_F_BAD_STATE ) + return ( void* )EXIT_FAILURE; + } ChfEndTry; - return (void *)EXIT_SUCCESS; + return ( void* )EXIT_SUCCESS; } +#define N_THREADS 50 -#define N_THREADS 50 - -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; int i; - void *ret; + void* ret; #ifdef _REENTRANT - pthread_t t[N_THREADS]; + pthread_t t[ N_THREADS ]; #endif - puts("test06"); + puts( "test06" ); /* Initialization */ - if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat", - C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE)) - exit(st); + if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE ) ) + exit( st ); #ifdef _REENTRANT /* Create */ - for(i=0; i #ifdef _REENTRANT -#include +# include #endif -#define CHF_MODULE_ID 255 +#define CHF_MODULE_ID 255 #define CHF_EXTENDED_INFO #include "Chf.h" extern ChfTable message_table[]; extern size_t message_table_size; -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { int st; - const char *msg; + const char* msg; const ChfDescriptor *d, *e; - puts("test07"); + puts( "test07" ); /* Initialization */ - if(st = ChfStaticInit(argv[0], CHF_DEFAULT, - message_table, message_table_size, 50, 10, 1)) - exit(st); + if ( st = ChfStaticInit( argv[ 0 ], CHF_DEFAULT, message_table, message_table_size, 50, 10, 1 ) ) + exit( st ); /* ChfGetMessage: message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */ - msg = ChfGetMessage(CHF_MODULE_ID, 1, "Default_1"); - if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE); - msg = ChfGetMessage(CHF_MODULE_ID, 2, "Default_2"); - if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE); + msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" ); + if ( strcmp( msg, "Set_255,Message_1" ) ) + exit( EXIT_FAILURE ); + msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" ); + if ( strcmp( msg, "Default_2" ) ) + exit( EXIT_FAILURE ); /* Generate a condition and check descriptor; this is line 46 */ ChfCondition 3, CHF_WARNING, 456 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 3 - || d->severity != CHF_WARNING - || d->line_number != 46 - || strcmp(d->file_name, "test07.c") - || strcmp(d->message, "Set_255,Arg_456,Message_3") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 46 || + strcmp( d->file_name, "test07.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL ) + exit( EXIT_FAILURE ); /* Generate another condition and check; this is line 60 */ ChfCondition 4, CHF_INFO, "arg" ChfEnd; - if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - e->module_id != CHF_MODULE_ID - || e->condition_code != 4 - || e->severity != CHF_INFO - || e->line_number != 60 - || strcmp(e->file_name, "test07.c") - || strcmp(e->message, "Set_255,Arg_arg,Message_4") - || e->next != d - ) exit(EXIT_FAILURE); + if ( ( e = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 60 || + strcmp( e->file_name, "test07.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d ) + exit( EXIT_FAILURE ); /* Discard the previous condition group and create a new one */ ChfDiscard(); @@ -76,28 +67,22 @@ int main(int argc, char *argv[]) /* This is line 77 */ ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd; - if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE); - if( - d->module_id != CHF_MODULE_ID - || d->condition_code != 5 - || d->severity != CHF_ERROR - || d->line_number != 77 - || strcmp(d->file_name, "test07.c") - || strcmp(d->message, "Set_255,Arg_456-789,Message_5") - || d->next != NULL - ) exit(EXIT_FAILURE); + if ( ( d = ChfGetTopCondition() ) == NULL ) + exit( EXIT_FAILURE ); + if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 77 || + strcmp( d->file_name, "test07.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL ) + exit( EXIT_FAILURE ); /* Exit Chf */ ChfExit(); - exit(EXIT_SUCCESS); + exit( EXIT_SUCCESS ); } -ChfTable message_table[] = -{ - { CHF_MODULE_ID, 1, "Set_255,Message_1" }, - { CHF_MODULE_ID, 3, "Set_255,Arg_%d,Message_3" }, - { CHF_MODULE_ID, 4, "Set_255,Arg_%s,Message_4" }, - { CHF_MODULE_ID, 5, "Set_255,Arg_%d-%d,Message_5" } +ChfTable message_table[] = { + {CHF_MODULE_ID, 1, "Set_255,Message_1" }, + {CHF_MODULE_ID, 3, "Set_255,Arg_%d,Message_3" }, + {CHF_MODULE_ID, 4, "Set_255,Arg_%s,Message_4" }, + {CHF_MODULE_ID, 5, "Set_255,Arg_%d-%d,Message_5"} }; -size_t message_table_size = sizeof(message_table)/sizeof(message_table[0]); +size_t message_table_size = sizeof( message_table ) / sizeof( message_table[ 0 ] ); diff --git a/src/machdep.h b/src/machdep.h index bded182..55c0ee3 100644 --- a/src/machdep.h +++ b/src/machdep.h @@ -60,16 +60,15 @@ .- */ - /*--------------------------------------------------------------------------- - Data type definitions - All Data types must be SIGNED + Data type definitions + All Data types must be SIGNED ---------------------------------------------------------------------------*/ -typedef char int1; -typedef char int4; -typedef char int8; -typedef int int12; -typedef int int16; -typedef int int20; -typedef int int32; +typedef char int1; +typedef char int4; +typedef char int8; +typedef int int12; +typedef int int16; +typedef int int20; +typedef int int32; diff --git a/src/main.c b/src/main.c index 3e0f9f0..aa577dc 100644 --- a/src/main.c +++ b/src/main.c @@ -103,8 +103,8 @@ static char rcs_id[] = "$Id: saturn.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include #include #include -#include /* 3.1: strcpy(), strcat() */ -#include /* isatty() */ +#include /* 3.1: strcpy(), strcat() */ +#include /* isatty() */ #include "config.h" #include "machdep.h" @@ -114,24 +114,22 @@ static char rcs_id[] = "$Id: saturn.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "args.h" #include "debug.h" - /* Chf condition codes (main program only) */ -#define CHF_MODULE_ID MAIN_CHF_MODULE_ID +#define CHF_MODULE_ID MAIN_CHF_MODULE_ID #include -#define MAIN_M_COPYRIGHT 501 -#define MAIN_M_LICENSE 502 - +#define MAIN_M_COPYRIGHT 501 +#define MAIN_M_LICENSE 502 /*--------------------------------------------------------------------------- Chf parameters - Do not change. The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE) ---------------------------------------------------------------------------*/ -#define CONDITION_STACK_SIZE 16 -#define HANDLER_STACK_SIZE 8 -#define ABNORMAL_EXIT_CODE EXIT_FAILURE +#define CONDITION_STACK_SIZE 16 +#define HANDLER_STACK_SIZE 8 +#define ABNORMAL_EXIT_CODE EXIT_FAILURE /* Conditional prefix and mandatory suffix to make a message catalog name from argv[0] @@ -139,31 +137,27 @@ static char rcs_id[] = "$Id: saturn.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; static const char cat_prefix[] = "./"; static const char cat_suffix[] = ".cat"; -#define CAT_PREFIX_LEN (sizeof(cat_prefix)+1) -#define CAT_SUFFIX_LEN (sizeof(cat_suffix)+1) +#define CAT_PREFIX_LEN ( sizeof( cat_prefix ) + 1 ) +#define CAT_SUFFIX_LEN ( sizeof( cat_suffix ) + 1 ) - -static void adjust_setlocale(void) +static void adjust_setlocale( void ) { - fprintf(stderr, - "saturn-W-locale probably bad; reverting to C locale\n"); + fprintf( stderr, "saturn-W-locale probably bad; reverting to C locale\n" ); - putenv("LC_ALL=C"); - putenv("LC_COLLATE=C"); - putenv("LC_CTYPE=C"); - putenv("LC_MESSAGES=C"); - putenv("LC_MONETARY=C"); - putenv("LC_NUMERIC=C"); - putenv("LC_TIME=C"); - putenv("LANG=C"); + putenv( "LC_ALL=C" ); + putenv( "LC_COLLATE=C" ); + putenv( "LC_CTYPE=C" ); + putenv( "LC_MESSAGES=C" ); + putenv( "LC_MONETARY=C" ); + putenv( "LC_NUMERIC=C" ); + putenv( "LC_TIME=C" ); + putenv( "LANG=C" ); } - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : main @@ -182,98 +176,89 @@ static void adjust_setlocale(void) - made Chf initialization more robust with respect to bad locales .- */ -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { - char *cat_name; + char* cat_name; int st; int retry = 0; - if((cat_name = malloc(strlen(argv[0])+CAT_PREFIX_LEN+CAT_SUFFIX_LEN+1)) - == NULL) - { - fprintf(stderr, "saturn-E-cat_name initialization failed\n"); - exit(ABNORMAL_EXIT_CODE); + if ( ( cat_name = malloc( strlen( argv[ 0 ] ) + CAT_PREFIX_LEN + CAT_SUFFIX_LEN + 1 ) ) == NULL ) { + fprintf( stderr, "saturn-E-cat_name initialization failed\n" ); + exit( ABNORMAL_EXIT_CODE ); } /* Generate catalog name, without optional prefix */ - strcpy(cat_name, argv[0]); - strcat(cat_name, cat_suffix); + strcpy( cat_name, argv[ 0 ] ); + strcat( cat_name, cat_suffix ); /* 3.15: Retry the initialization steps below two times; before trying the second time, adjust the setlocale() environment variables with adjust_setlocale() */ - while(retry < 2) - { - /* Chf initialization with msgcat subsystem; notice that on - some systems (e.g. Digital UNIX) catopen() can succeed even - if it was not able to open the right message catalog; - better try it now. - */ - if((st = ChfMsgcatInit( - argv[0], /* Application's name */ - CHF_DEFAULT, /* Options */ - cat_name, /* Name of the message catalog */ - CONDITION_STACK_SIZE, /* Size of the condition stack */ - HANDLER_STACK_SIZE, /* Size of the handler stack */ - ABNORMAL_EXIT_CODE /* Abnormal exit code */ - )) != CHF_S_OK - || - ChfGetMessage(CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL) == NULL) - fprintf(stderr, - "saturn-E-Primary Chf initialization failed (%d)\n", st); + while ( retry < 2 ) { + /* Chf initialization with msgcat subsystem; notice that on + some systems (e.g. Digital UNIX) catopen() can succeed even + if it was not able to open the right message catalog; + better try it now. + */ + if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */ + CHF_DEFAULT, /* Options */ + cat_name, /* Name of the message catalog */ + CONDITION_STACK_SIZE, /* Size of the condition stack */ + HANDLER_STACK_SIZE, /* Size of the handler stack */ + ABNORMAL_EXIT_CODE /* Abnormal exit code */ + ) ) != CHF_S_OK || + ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL ) + fprintf( stderr, "saturn-E-Primary Chf initialization failed (%d)\n", st ); - else - break; + else + break; - /* Bring down Chf before initializing it again */ - if(st == CHF_S_OK) ChfExit(); + /* Bring down Chf before initializing it again */ + if ( st == CHF_S_OK ) + ChfExit(); - /* Try alternate message catalog name (with prefix) */ - strcpy(cat_name, cat_prefix); - strcat(cat_name, argv[0]); - strcat(cat_name, cat_suffix); + /* Try alternate message catalog name (with prefix) */ + strcpy( cat_name, cat_prefix ); + strcat( cat_name, argv[ 0 ] ); + strcat( cat_name, cat_suffix ); - if((st = ChfMsgcatInit( - argv[0], /* Application's name */ - CHF_DEFAULT, /* Options */ - cat_name, /* Name of the message catalog */ - CONDITION_STACK_SIZE, /* Size of the condition stack */ - HANDLER_STACK_SIZE, /* Size of the handler stack */ - ABNORMAL_EXIT_CODE /* Abnormal exit code */ - )) != CHF_S_OK - || - ChfGetMessage(CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL) == NULL) - fprintf(stderr, - "saturn-E-Alternate Chf initialization failed (%d)\n", - st); + if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */ + CHF_DEFAULT, /* Options */ + cat_name, /* Name of the message catalog */ + CONDITION_STACK_SIZE, /* Size of the condition stack */ + HANDLER_STACK_SIZE, /* Size of the handler stack */ + ABNORMAL_EXIT_CODE /* Abnormal exit code */ + ) ) != CHF_S_OK || + ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL ) + fprintf( stderr, "saturn-E-Alternate Chf initialization failed (%d)\n", st ); - else - break; + else + break; - /* Bring down Chf before initializing it again */ - if(st == CHF_S_OK) ChfExit(); + /* Bring down Chf before initializing it again */ + if ( st == CHF_S_OK ) + ChfExit(); - /* Attempt to adjust setlocale() environment variables */ - if(retry++ == 0) adjust_setlocale(); + /* Attempt to adjust setlocale() environment variables */ + if ( retry++ == 0 ) + adjust_setlocale(); } - if(retry == 2) - { - fprintf(stderr, "saturn-F-Application aborted\n"); - exit(ABNORMAL_EXIT_CODE); + if ( retry == 2 ) { + fprintf( stderr, "saturn-F-Application aborted\n" ); + exit( ABNORMAL_EXIT_CODE ); } /* cat_name no longer needed */ - free(cat_name); + free( cat_name ); /* 3.9: Print out MAIN_M_COPYRIGHT and MAIN_M_LICENSE on stdout now */ - fprintf(stdout, ChfGetMessage(CHF_MODULE_ID, MAIN_M_COPYRIGHT, ""), - "$Revision: 4.1 $"); - fprintf(stdout, ChfGetMessage(CHF_MODULE_ID, MAIN_M_LICENSE, "")); + fprintf( stdout, ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, "" ), "$Revision: 4.1 $" ); + fprintf( stdout, ChfGetMessage( CHF_MODULE_ID, MAIN_M_LICENSE, "" ) ); /* Initialize GUI and associated lcd display emulation module */ - InitializeGui(argc, argv); + InitializeGui( argc, argv ); /* Initialize serial port emulation. This function returns the name of the slave side of the pty; @@ -281,30 +266,28 @@ int main(int argc, char *argv[]) a condition containing the same information and displays the pty name on the main emulator's window. */ - (void)SerialInit(); + ( void )SerialInit(); /* Initialize emulator proper */ EmulatorInit(); /* 3.15: Repeat copyright message on GUI if stdout is not a tty */ - if(! isatty(fileno(stdout))) - { - ChfCondition MAIN_M_LICENSE, CHF_INFO ChfEnd; - ChfCondition MAIN_M_COPYRIGHT, CHF_INFO, "$Revision: 4.1 $" ChfEnd; + if ( !isatty( fileno( stdout ) ) ) { + ChfCondition MAIN_M_LICENSE, CHF_INFO ChfEnd; + ChfCondition MAIN_M_COPYRIGHT, CHF_INFO, "$Revision: 4.1 $" ChfEnd; - ChfSignal(); + ChfSignal(); } - if(args.monitor) - { - /* Invoke Monitor */ - void Monitor(void); - Monitor(); + if ( args.monitor ) { + /* Invoke Monitor */ + void Monitor( void ); + Monitor(); } else - /* Call Emulator directly */ - Emulator(); + /* Call Emulator directly */ + Emulator(); return EXIT_SUCCESS; } diff --git a/src/modules.c b/src/modules.c index 90b39f2..bb223ea 100644 --- a/src/modules.c +++ b/src/modules.c @@ -52,17 +52,17 @@ x48 source code by Eddie C. Dost (ecd@dressler.de) NOTE: Preliminary profiling information on Digital UNIX shows that, - without module config/unconfig cache (revision 1.1), while the - Saturn CPU is doing bank switching over 48% of the CPU time is - spent in RebuildPageTable(), with a peak of 60% when opening - the PLOT input form. + without module config/unconfig cache (revision 1.1), while the + Saturn CPU is doing bank switching over 48% of the CPU time is + spent in RebuildPageTable(), with a peak of 60% when opening + the PLOT input form. - With the module config/unconfig cache enabled (revision 2.7), - RebuildPageTable() drops to the 45th place in the gprof's - listing of per-function cpu time. + With the module config/unconfig cache enabled (revision 2.7), + RebuildPageTable() drops to the 45th place in the gprof's + listing of per-function cpu time. - Moreover, even during intensive calculations, over 30% of the CPU - time is spent in either FetchNibble() or RomRead() in either case. + Moreover, even during intensive calculations, over 30% of the CPU + time is spent in either FetchNibble() or RomRead() in either case. .include : config.h, machdep.h, cpu.h, modules.h @@ -128,15 +128,14 @@ static char rcs_id[] = "$Id: modules.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" #include "args.h" #include "debug.h" -#define CHF_MODULE_ID MOD_CHF_MODULE_ID +#define CHF_MODULE_ID MOD_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Static/Global variables + Static/Global variables ---------------------------------------------------------------------------*/ -struct ModStatus mod_status; /* Status information - global */ +struct ModStatus mod_status; /* Status information - global */ /* 2.7: Replaced the statically-allocated module mapping structure with a pointer to a dynamically-allocated structure, to be able to switch @@ -144,62 +143,60 @@ struct ModStatus mod_status; /* Status information - global */ refer to the current module mapping structure, and mod_map_ptr points to it. */ -static struct ModMap *mod_map_ptr; /* Module mapping information */ -#define mod_map (*mod_map_ptr) +static struct ModMap* mod_map_ptr; /* Module mapping information */ +#define mod_map ( *mod_map_ptr ) /* 2.7: All dynamically-allocated module mapping structures are linked together; cache_head points to the head of the list. The list is used to flush the cache when necessary. */ -static struct ModMap *cache_head = (struct ModMap *)NULL; +static struct ModMap* cache_head = ( struct ModMap* )NULL; /* 3.2: The ModDescription table is now configured invoking ModRegisterDescription() before invoking any other function in this module. */ -static const struct ModDescriptionEntry *mod_description; - +static const struct ModDescriptionEntry* mod_description; /*--------------------------------------------------------------------------- - Debugging & performance analysis data + Debugging & performance analysis data ---------------------------------------------------------------------------*/ #ifdef DEBUG -static int alloc_c = 0; /* Counter of live AllocModMap() invocations */ -static int flush_c = 0; /* Counter of FlushCache() invocations */ -static int hit_c = 0; /* Cache hit counter */ -static int lhit_c = 0; /* Cache late unconfig hit counter */ -static int miss_c = 0; /* Cache miss (without replacement) counter */ -static int repl_c = 0; /* Entry replacement counter */ +static int alloc_c = 0; /* Counter of live AllocModMap() invocations */ +static int flush_c = 0; /* Counter of FlushCache() invocations */ +static int hit_c = 0; /* Cache hit counter */ +static int lhit_c = 0; /* Cache late unconfig hit counter */ +static int miss_c = 0; /* Cache miss (without replacement) counter */ +static int repl_c = 0; /* Entry replacement counter */ -#define IncPerfCtr(x) x++ -#define DecPerfCtr(x) x-- -#define PrintPerfCtr(x) debug2(DEBUG_C_MOD_CACHE, MOD_I_PERF_CTR, #x, x) +# define IncPerfCtr( x ) x++ +# define DecPerfCtr( x ) x-- +# define PrintPerfCtr( x ) debug2( DEBUG_C_MOD_CACHE, MOD_I_PERF_CTR, #x, x ) -#define PrintCacheStats \ -{ \ - PrintPerfCtr(alloc_c); \ - PrintPerfCtr(flush_c); \ - PrintPerfCtr(hit_c); \ - PrintPerfCtr(lhit_c); \ - PrintPerfCtr(miss_c); \ - PrintPerfCtr(repl_c); \ -} +# define PrintCacheStats \ + { \ + PrintPerfCtr( alloc_c ); \ + PrintPerfCtr( flush_c ); \ + PrintPerfCtr( hit_c ); \ + PrintPerfCtr( lhit_c ); \ + PrintPerfCtr( miss_c ); \ + PrintPerfCtr( repl_c ); \ + } #else -#define IncPerfCtr(x) -#define DecPerfCtr(x) -#define PrintPerfCtr(x) +# define IncPerfCtr( x ) +# define DecPerfCtr( x ) +# define PrintPerfCtr( x ) -#define PrintCacheStats +# define PrintCacheStats #endif - /*--------------------------------------------------------------------------- - Private functions + Private functions ---------------------------------------------------------------------------*/ /* .+ @@ -214,28 +211,27 @@ static int repl_c = 0; /* Entry replacement counter */ It signals a warning and returns 0x0 to the caller. Since two consecutive zeros represent a RTNSXM instruction, this is an easy way to detect when a gosub transfers control to an unmapped address. - + .call : - d = BadRead(addr); + d = BadRead(addr); .input : - Address addr, address + Address addr, address .output : - Nibble d, datum + Nibble d, datum .status_codes : - MOD_E_BAD_READ + MOD_E_BAD_READ .notes : 1.1, 26-Jan-1998, creation .- */ -static Nibble BadRead(Address addr) +static Nibble BadRead( Address addr ) { - ChfCondition MOD_E_BAD_READ, CHF_ERROR, addr ChfEnd; - ChfSignal(); + ChfCondition MOD_E_BAD_READ, CHF_ERROR, addr ChfEnd; + ChfSignal(); - return (Nibble)0x0; + return ( Nibble )0x0; } - /* .+ .title : BadWrite @@ -246,27 +242,26 @@ static Nibble BadRead(Address addr) address. It signals a warning and does not execute the write. - + .call : - BadWrite(addr, datum); + BadWrite(addr, datum); .input : - Address addr, address - Nibble datum, datum to be written + Address addr, address + Nibble datum, datum to be written .output : - void + void .status_codes : - MOD_E_BAD_WRITE + MOD_E_BAD_WRITE .notes : 1.1, 26-Jan-1998, creation .- */ -static void BadWrite(Address addr, Nibble datum) +static void BadWrite( Address addr, Nibble datum ) { - ChfCondition MOD_E_BAD_WRITE, CHF_ERROR, addr, datum ChfEnd; - ChfSignal(); + ChfCondition MOD_E_BAD_WRITE, CHF_ERROR, addr, datum ChfEnd; + ChfSignal(); } - /* .+ .title : RebuildPageTable @@ -278,14 +273,14 @@ static void BadWrite(Address addr, Nibble datum) mapping structure (mod_map.map_info). .call : - RebuildPageTable(lo, hi); + RebuildPageTable(lo, hi); .input : - int lo, first page table entry to rebuild - int hi, last page table entry to rebuild + int lo, first page table entry to rebuild + int hi, last page table entry to rebuild .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 26-Jan-1998, creation 3.3, 25-Sep-2000, update @@ -297,78 +292,67 @@ static void BadWrite(Address addr, Nibble datum) module configurations. .- */ -static void RebuildPageTable(int lo, int hi) +static void RebuildPageTable( int lo, int hi ) { - int page; - int mod; + int page; + int mod; - Address page_addr; - int prio; - int winner = -1; + Address page_addr; + int prio; + int winner = -1; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RebuildPageTable"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RebuildPageTable" ); - /* Scan all pages in the [lo, hi] range */ - for(page=lo; page<=hi; page++) - { - /* Calculate the base page address for the current page */ - page_addr = ModAddress(page); + /* Scan all pages in the [lo, hi] range */ + for ( page = lo; page <= hi; page++ ) { + /* Calculate the base page address for the current page */ + page_addr = ModAddress( page ); - /* Scan the module mapping information table, searching for the module - with the highest access priority that responds to the address - page_addr. If succesful, 'prio' contains the access priority of the - winner, and 'winner' contains its index, otherwise prio is set - to MOD_MIN_ACCESS_PRIO. - */ - prio = MOD_MIN_ACCESS_PRIO; - for(mod=0; mod= mod_map.map_info[mod].abs_base_addr && - page_addr < mod_map.map_info[mod].abs_base_addr + - mod_map.map_info[mod].size && - prio < mod_description[mod].access_prio - ) - { - winner = mod; - prio = mod_description[mod].access_prio; - } + /* Scan the module mapping information table, searching for the module + with the highest access priority that responds to the address + page_addr. If succesful, 'prio' contains the access priority of the + winner, and 'winner' contains its index, otherwise prio is set + to MOD_MIN_ACCESS_PRIO. + */ + prio = MOD_MIN_ACCESS_PRIO; + for ( mod = 0; mod < N_MOD; mod++ ) { + if ( mod_map.map_info[ mod ].config == MOD_CONFIGURED && page_addr >= mod_map.map_info[ mod ].abs_base_addr && + page_addr < mod_map.map_info[ mod ].abs_base_addr + mod_map.map_info[ mod ].size && + prio < mod_description[ mod ].access_prio ) { + winner = mod; + prio = mod_description[ mod ].access_prio; + } + } + + if ( prio == MOD_MIN_ACCESS_PRIO ) { + /* The page is unmapped; set the module index to the special value + MOD_NO_MOD_INDEX, the relative base address to zero and the + read/write functions to BadRead/BadWrite, to catch accesses to + unmapped addresses. + */ + mod_map.page_table[ page ].index = MOD_NO_MOD_INDEX; + mod_map.page_table[ page ].rel_base_addr = 0x00000; + mod_map.page_table[ page ].read = BadRead; + mod_map.page_table[ page ].write = BadWrite; + } + + else { + /* The page is mapped + 3.3: If the MOD_MAP_FLAGS_ABS is set in the winner's module + description, the base address of the page is set to its + absolute address; this way, the module read/write functions + will receive absolute addresses instead of relative ones. + */ + mod_map.page_table[ page ].index = winner; + mod_map.page_table[ page ].rel_base_addr = ( mod_description[ winner ].map_flags & MOD_MAP_FLAGS_ABS ) + ? page_addr + : page_addr - mod_map.map_info[ winner ].abs_base_addr; + mod_map.page_table[ page ].read = mod_description[ winner ].read; + mod_map.page_table[ page ].write = mod_description[ winner ].write; + } } - - if(prio == MOD_MIN_ACCESS_PRIO) - { - /* The page is unmapped; set the module index to the special value - MOD_NO_MOD_INDEX, the relative base address to zero and the - read/write functions to BadRead/BadWrite, to catch accesses to - unmapped addresses. - */ - mod_map.page_table[page].index = MOD_NO_MOD_INDEX; - mod_map.page_table[page].rel_base_addr = 0x00000; - mod_map.page_table[page].read = BadRead; - mod_map.page_table[page].write = BadWrite; - } - - else - { - /* The page is mapped - 3.3: If the MOD_MAP_FLAGS_ABS is set in the winner's module - description, the base address of the page is set to its - absolute address; this way, the module read/write functions - will receive absolute addresses instead of relative ones. - */ - mod_map.page_table[page].index = winner; - mod_map.page_table[page].rel_base_addr = - (mod_description[winner].map_flags & MOD_MAP_FLAGS_ABS) - ? page_addr - : page_addr - mod_map.map_info[winner].abs_base_addr; - mod_map.page_table[page].read = mod_description[winner].read; - mod_map.page_table[page].write = mod_description[winner].write; - } - } } - /* .+ .title : ClearCachingInfo @@ -380,37 +364,37 @@ static void RebuildPageTable(int lo, int hi) the same structure. .call : - d = ClearCachingInfo(d); + d = ClearCachingInfo(d); .input : - struct ModMap *d, ptr to the structure to be wiped off + struct ModMap *d, ptr to the structure to be wiped off .output : - struct ModMap *d, ptr to affected structure + struct ModMap *d, ptr to affected structure .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 2.7, 15-Sep-2000, creation .- */ -static struct ModMap *ClearCachingInfo(struct ModMap *d) +static struct ModMap* ClearCachingInfo( struct ModMap* d ) { - static const struct ModCacheTableEntry empty = - { (Address)0, (struct ModMap *)NULL }; + static const struct ModCacheTableEntry empty = { ( Address )0, ( struct ModMap* )NULL }; int i; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ClearCachingInfo"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ClearCachingInfo" ); - for(i=0; icache.config[i] = empty; + for ( i = 0; i < N_MOD_CACHE_ENTRIES; i++ ) + d->cache.config[ i ] = empty; d->cache.victim = 0; - for(i=0; icache.unconfig[i] = (struct ModMap *)NULL; + for ( i = 0; i < N_MOD; i++ ) + d->cache.unconfig[ i ] = ( struct ModMap* )NULL; d->cache.config_point = 0; d->cache.ref_count = 0; return d; } - /* .+ .title : NewModMap @@ -428,44 +412,41 @@ static struct ModMap *ClearCachingInfo(struct ModMap *d) current value of all cache performance counters (PrintCacheStats). .call : - p = NewModMap(); + p = NewModMap(); .input : - void + void .output : - struct ModMap *p, pointer to the new struct ModMap + struct ModMap *p, pointer to the new struct ModMap .status_codes : - MOD_I_CALLED - MOD_I_PERF_CTR, performance counter: %s value: %d - MOD_F_MAP_ALLOC, allocation of new map failed + MOD_I_CALLED + MOD_I_PERF_CTR, performance counter: %s value: %d + MOD_F_MAP_ALLOC, allocation of new map failed .notes : 2.7, 15-Sep-2000, creation .- */ -static struct ModMap *NewModMap(void) +static struct ModMap* NewModMap( void ) { - struct ModMap *new; + struct ModMap* new; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NewModMap"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NewModMap" ); - if((new = (struct ModMap *)malloc(sizeof(struct ModMap))) - == (struct ModMap *)NULL) - { - ChfErrnoCondition; - ChfCondition MOD_F_MAP_ALLOC, CHF_FATAL ChfEnd; - ChfSignal(); + if ( ( new = ( struct ModMap* )malloc( sizeof( struct ModMap ) ) ) == ( struct ModMap* )NULL ) { + ChfErrnoCondition; + ChfCondition MOD_F_MAP_ALLOC, CHF_FATAL ChfEnd; + ChfSignal(); } /* Link new structure to the cache list */ new->cache.link = cache_head; cache_head = new; - IncPerfCtr(alloc_c); + IncPerfCtr( alloc_c ); PrintCacheStats; return new; } - /* .+ .title : CopyModMap @@ -480,29 +461,28 @@ static struct ModMap *NewModMap(void) list (.link field) is preserved. .call : - d = CopyModMap(d, s); + d = CopyModMap(d, s); .input : - const struct ModMap *s, ptr to source structure + const struct ModMap *s, ptr to source structure .output : - struct ModMap *d, ptr to destination structure + struct ModMap *d, ptr to destination structure .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 2.7, 15-Sep-2000, creation .- */ -static struct ModMap *CopyModMap(struct ModMap *d, const struct ModMap *s) +static struct ModMap* CopyModMap( struct ModMap* d, const struct ModMap* s ) { - struct ModMap *link = d->cache.link; /* Save .link of dest. */ + struct ModMap* link = d->cache.link; /* Save .link of dest. */ - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "CopyModMap"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "CopyModMap" ); *d = *s; - d->cache.link = link; /* Restore .link */ - return ClearCachingInfo(d); + d->cache.link = link; /* Restore .link */ + return ClearCachingInfo( d ); } - /* .+ .title : ReplaceModMap @@ -522,37 +502,35 @@ static struct ModMap *CopyModMap(struct ModMap *d, const struct ModMap *s) destination structure. .call : - ReplaceModMap(d, s); + ReplaceModMap(d, s); .input : - struct ModMap **d, ptr to destination structure ptr - const struct ModMap *s, ptr to source structure + struct ModMap **d, ptr to destination structure ptr + const struct ModMap *s, ptr to source structure .output : - struct ModMap **d, ptr to destination structure ptr; - updated when original value of *d was NULL + struct ModMap **d, ptr to destination structure ptr; + updated when original value of *d was NULL .status_codes : - MOD_I_CALLED - MOD_I_PERF_CTR, performance counter: %s value: %d - MOD_F_MAP_ALLOC, allocation of new map failed + MOD_I_CALLED + MOD_I_PERF_CTR, performance counter: %s value: %d + MOD_F_MAP_ALLOC, allocation of new map failed .notes : 2.7, 15-Sep-2000, creation .- */ -static void ReplaceModMap(struct ModMap **d, const struct ModMap *s) +static void ReplaceModMap( struct ModMap** d, const struct ModMap* s ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ReplaceModMap"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ReplaceModMap" ); - if(*d == (struct ModMap *)NULL) - /* Allocation needed; cache cleared after allocation */ - *d = CopyModMap(NewModMap(), s); + if ( *d == ( struct ModMap* )NULL ) + /* Allocation needed; cache cleared after allocation */ + *d = CopyModMap( NewModMap(), s ); - else - { - CopyModMap(*d, s); - IncPerfCtr(repl_c); + else { + CopyModMap( *d, s ); + IncPerfCtr( repl_c ); } } - /* .+ .title : FlushCache @@ -565,60 +543,56 @@ static void ReplaceModMap(struct ModMap **d, const struct ModMap *s) information is no longer valid after the flush. .call : - FlushCache(save); + FlushCache(save); .input : - struct ModMap *save + struct ModMap *save .output : - void + void .status_codes : - MOD_I_CALLED - MOD_F_BAD_ALLOC_C, bad alloc_c (%d) after FlushCache() + MOD_I_CALLED + MOD_F_BAD_ALLOC_C, bad alloc_c (%d) after FlushCache() .notes : 2.7, 15-Sep-2000, creation .- */ -static void FlushCache(struct ModMap *save) +static void FlushCache( struct ModMap* save ) { struct ModMap *p, *n; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "FlushCache"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "FlushCache" ); /* Scan the cache list; free all elements except that pointed by 'save' */ p = cache_head; - while(p != (struct ModMap *)NULL) - { + while ( p != ( struct ModMap* )NULL ) { - n = p->cache.link; + n = p->cache.link; - if(p != save) - { - free(p); - DecPerfCtr(alloc_c); - } + if ( p != save ) { + free( p ); + DecPerfCtr( alloc_c ); + } - p = n; + p = n; } /* The cache list now contains only 'save' */ - save->cache.link = (struct ModMap *)NULL; + save->cache.link = ( struct ModMap* )NULL; cache_head = save; /* Clear the caching information in 'save' */ - ClearCachingInfo(save); + ClearCachingInfo( save ); - IncPerfCtr(flush_c); + IncPerfCtr( flush_c ); #ifdef DEBUG /* The alloc_c performance counter must be exactly 1 now */ - if(alloc_c != 1) - { - ChfCondition MOD_F_BAD_ALLOC_C, CHF_ERROR, alloc_c ChfEnd; - ChfSignal(); + if ( alloc_c != 1 ) { + ChfCondition MOD_F_BAD_ALLOC_C, CHF_ERROR, alloc_c ChfEnd; + ChfSignal(); } #endif } - /* .+ .title : AccessConfigCache @@ -631,31 +605,30 @@ static void FlushCache(struct ModMap *save) just found, otherwise it returns NULL (cache miss). .call : - p = AccessConfigCache(tag); + p = AccessConfigCache(tag); .input : - Address tag, cache tag + Address tag, cache tag .output : - struct ModMap *p, cached pointer, or NULL + struct ModMap *p, cached pointer, or NULL .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 2.7, 15-Sep-2000, creation .- */ -static struct ModMap *AccessConfigCache(Address tag) +static struct ModMap* AccessConfigCache( Address tag ) { int i; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "AccessConfigCache"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "AccessConfigCache" ); - for(i=0; icache.config_point) - p = p->cache.unconfig[i]; + while ( p != ( struct ModMap* )NULL && !p->cache.config_point ) + p = p->cache.unconfig[ i ]; return p; } - /* .+ .title : SelectConfigVictim @@ -716,74 +688,66 @@ static struct ModMap *AccessUnconfigCache(int i) function immediately signals the fatal condition MOD_F_NO_VICTIM. .call : - victim = SelectConfigVictim(); + victim = SelectConfigVictim(); .input : - void + void .output : - struct ModCacheTableEntry *victim, pointer to victim entry + struct ModCacheTableEntry *victim, pointer to victim entry .status_codes : - MOD_I_CALLED - MOD_W_NO_VICTIM - MOD_F_NO_VICTIM - MOD_F_BAD_ALLOC_C, bad alloc_c (%d) after FlushCache() + MOD_I_CALLED + MOD_W_NO_VICTIM + MOD_F_NO_VICTIM + MOD_F_BAD_ALLOC_C, bad alloc_c (%d) after FlushCache() .notes : 2.7, 15-Sep-2000, creation .- */ -struct ModCacheTableEntry *SelectConfigVictim(int retry) +struct ModCacheTableEntry* SelectConfigVictim( int retry ) { int v = mod_map.cache.victim; - struct ModCacheTableEntry *victim = (struct ModCacheTableEntry *)NULL; + struct ModCacheTableEntry* victim = ( struct ModCacheTableEntry* )NULL; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "AccessUnconfigCache"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "AccessUnconfigCache" ); /* Scan the config cache entries, starting at .cache.victim, until a suitable one is found or the index loops around */ - do - { - /* A config cache entry is suitable for use if: - - it is empty (map_ptr == NULL) - - or the reference count of the associated map is 0 - */ - if((mod_map.cache.config[v].map_ptr == (struct ModMap *)NULL) - || mod_map.cache.config[v].map_ptr->cache.ref_count == 0) - victim = &(mod_map.cache.config[v]); + do { + /* A config cache entry is suitable for use if: + - it is empty (map_ptr == NULL) + - or the reference count of the associated map is 0 + */ + if ( ( mod_map.cache.config[ v ].map_ptr == ( struct ModMap* )NULL ) || mod_map.cache.config[ v ].map_ptr->cache.ref_count == 0 ) + victim = &( mod_map.cache.config[ v ] ); - v = (v + 1) % N_MOD_CACHE_ENTRIES; - } - while(victim == (struct ModCacheTableEntry *)NULL - && v != mod_map.cache.victim); + v = ( v + 1 ) % N_MOD_CACHE_ENTRIES; + } while ( victim == ( struct ModCacheTableEntry* )NULL && v != mod_map.cache.victim ); - if(victim == (struct ModCacheTableEntry *)NULL) - { - if(retry) - { - /* Unable to find a victim; flush the cache and retry */ - ChfCondition MOD_W_NO_VICTIM, CHF_WARNING ChfEnd; - ChfSignal(); + if ( victim == ( struct ModCacheTableEntry* )NULL ) { + if ( retry ) { + /* Unable to find a victim; flush the cache and retry */ + ChfCondition MOD_W_NO_VICTIM, CHF_WARNING ChfEnd; + ChfSignal(); - FlushCache(mod_map_ptr); + FlushCache( mod_map_ptr ); - victim = SelectConfigVictim(0); - } + victim = SelectConfigVictim( 0 ); + } - else - { - /* Unable to find a victim; retry is not an option; give up */ - ChfCondition MOD_F_NO_VICTIM, CHF_FATAL ChfEnd; - ChfSignal(); - } + else { + /* Unable to find a victim; retry is not an option; give up */ + ChfCondition MOD_F_NO_VICTIM, CHF_FATAL ChfEnd; + ChfSignal(); + } } else - /* Found a victim; update next-victim index */ - mod_map.cache.victim = v; + /* Found a victim; update next-victim index */ + mod_map.cache.victim = v; return victim; } - /* .+ .title : CheckForLateHit @@ -801,60 +765,53 @@ struct ModCacheTableEntry *SelectConfigVictim(int retry) that encountered an early cache miss. .call : - p = CheckForLateHit(); + p = CheckForLateHit(); .input : - void + void .output : - struct ModMap *p, cached pointer, or NULL + struct ModMap *p, cached pointer, or NULL .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 2.7, 19-Sep-2000, creation .- */ -static struct ModMap *CheckForLateHit(void) +static struct ModMap* CheckForLateHit( void ) { - struct ModMap *p; + struct ModMap* p; int i; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "AccessUnconfigCache"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "AccessUnconfigCache" ); p = cache_head; /* Scan the cache to find an entry with the same modules configuration as the current one; return a pointer to it if successful */ - while(p != (struct ModMap *)NULL) - { - /* Don't attempt to match an entry against itself */ - if(p != mod_map_ptr) - { - /* only .map_info contents must match */ - for(i=0; imap_info[i].config - != p->map_info[i].config) - || (mod_map_ptr->map_info[i].abs_base_addr != - p->map_info[i].abs_base_addr) - || (mod_map_ptr->map_info[i].size != - p->map_info[i].size)) - break; - } + while ( p != ( struct ModMap* )NULL ) { + /* Don't attempt to match an entry against itself */ + if ( p != mod_map_ptr ) { + /* only .map_info contents must match */ + for ( i = 0; i < N_MOD; i++ ) { + /* Break the for if a difference was found */ + if ( ( mod_map_ptr->map_info[ i ].config != p->map_info[ i ].config ) || + ( mod_map_ptr->map_info[ i ].abs_base_addr != p->map_info[ i ].abs_base_addr ) || + ( mod_map_ptr->map_info[ i ].size != p->map_info[ i ].size ) ) + break; + } - /* Break the while if we found a match ('for' was not broken) */ - if(i == N_MOD) break; - } + /* Break the while if we found a match ('for' was not broken) */ + if ( i == N_MOD ) + break; + } - /* Go to the next cache entry */ - p = p->cache.link; + /* Go to the next cache entry */ + p = p->cache.link; } return p; } - /* .+ .title : FreeModMap @@ -868,62 +825,58 @@ static struct ModMap *CheckForLateHit(void) longer referenced. .call : - p = CheckForLateHit(); + p = CheckForLateHit(); .input : - void + void .output : - struct ModMap *p, cached pointer, or NULL + struct ModMap *p, cached pointer, or NULL .status_codes : - MOD_I_CALLED - MOD_F_CHAIN_CORRUPTED + MOD_I_CALLED + MOD_F_CHAIN_CORRUPTED .notes : 2.7, 15-Sep-2000, creation .- */ -static void FreeModMap(struct ModMap *p) +static void FreeModMap( struct ModMap* p ) { - struct ModMap *n; + struct ModMap* n; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "FreeModMap"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "FreeModMap" ); /* Free the struct ModMap pointed by p, preserving the linkage of other entries. The caller must ensure that the entry is not referenced by any other entry through cache pointers. */ - if(p == cache_head) - { - /* Free the list head */ - cache_head = p->cache.link; - free(p); - DecPerfCtr(alloc_c); + if ( p == cache_head ) { + /* Free the list head */ + cache_head = p->cache.link; + free( p ); + DecPerfCtr( alloc_c ); } - else - { - /* Scan the cache; at end, n is either null (!) or points to the - cache entry that immediately precedes p - */ - n = cache_head; - while((n != (struct ModMap *)NULL) && n->cache.link != p) - n = n->cache.link; + else { + /* Scan the cache; at end, n is either null (!) or points to the + cache entry that immediately precedes p + */ + n = cache_head; + while ( ( n != ( struct ModMap* )NULL ) && n->cache.link != p ) + n = n->cache.link; - /* Should never happen */ - if(n == (struct ModMap *)NULL) - { - ChfCondition MOD_F_CHAIN_CORRUPTED, CHF_FATAL ChfEnd; - ChfSignal(); - } + /* Should never happen */ + if ( n == ( struct ModMap* )NULL ) { + ChfCondition MOD_F_CHAIN_CORRUPTED, CHF_FATAL ChfEnd; + ChfSignal(); + } - /* Bypass element pointed by p and free it */ - n->cache.link = p->cache.link; - free(p); - DecPerfCtr(alloc_c); + /* Bypass element pointed by p and free it */ + n->cache.link = p->cache.link; + free( p ); + DecPerfCtr( alloc_c ); } } - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ /* .+ @@ -943,25 +896,24 @@ static void FreeModMap(struct ModMap *p) returns 'void' to the caller. .call : - ModRegisterDescription(p); + ModRegisterDescription(p); .input : - ModDescription p, module description table to be registered + ModDescription p, module description table to be registered .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void ModRegisterDescription(ModDescription p) +void ModRegisterDescription( ModDescription p ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ModRegisterDescription"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModRegisterDescription" ); mod_description = p; } - /* .+ .title : ModInit @@ -977,23 +929,23 @@ void ModRegisterDescription(ModDescription p) returns 'void' to the caller. .call : - ModInit(); + ModInit(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_I_REVISION - MOD_I_INITIALIZING - MOD_I_PERF_CTR, performance counter: %s value: %d - MOD_W_RESETTING_ALL - MOD_F_MAP_ALLOC - MOD_F_NO_DESCRIPTION + MOD_I_CALLED + MOD_I_REVISION + MOD_I_INITIALIZING + MOD_I_PERF_CTR, performance counter: %s value: %d + MOD_W_RESETTING_ALL + MOD_F_MAP_ALLOC + MOD_F_NO_DESCRIPTION - NOTE: This function can also (indirectly) report any condition - code generated and/or signalled by the module initialization - functions. + NOTE: This function can also (indirectly) report any condition + code generated and/or signalled by the module initialization + functions. .notes : 1.1, 23-Jan-1998, creation 2.7, 15-Sep-2000, update @@ -1002,56 +954,50 @@ void ModRegisterDescription(ModDescription p) - added sanity check on mod_description .- */ -void ModInit(void) +void ModInit( void ) { - int mod; + int mod; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ModInit"); - debug1(DEBUG_C_REVISION, MOD_I_REVISION, MOD_RCS_INFO); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModInit" ); + debug1( DEBUG_C_REVISION, MOD_I_REVISION, MOD_RCS_INFO ); - /* First, a little sanity check on mod_description: ensure that - ModRegisterDescription() has been called at least once with a - non-NULL argument. - */ - if(mod_description == NULL) - { - ChfCondition MOD_F_NO_DESCRIPTION, CHF_FATAL ChfEnd; - ChfSignal(); - } + /* First, a little sanity check on mod_description: ensure that + ModRegisterDescription() has been called at least once with a + non-NULL argument. + */ + if ( mod_description == NULL ) { + ChfCondition MOD_F_NO_DESCRIPTION, CHF_FATAL ChfEnd; + ChfSignal(); + } - /* Scan the mod_description table, initializing all modules */ - for(mod=0; modtag = config_info; - ReplaceModMap(&(victim->map_ptr), mod_map_ptr); - - old = mod_map_ptr; - mod_map_ptr = victim->map_ptr; - - /* Scan the module information table searching for either an unconfigured - or a partially configured module - */ - for(mod=0; - modcache.ref_count++; - } -} + victim = SelectConfigVictim( 1 ); + victim->tag = config_info; + ReplaceModMap( &( victim->map_ptr ), mod_map_ptr ); + + old = mod_map_ptr; + mod_map_ptr = victim->map_ptr; + + /* Scan the module information table searching for either an unconfigured + or a partially configured module + */ + for ( mod = 0; mod < N_MOD && mod_map.map_info[ mod ].config == MOD_CONFIGURED; mod++ ) + ; + + if ( mod == N_MOD ) { + /* All modules are configured - Signal a warning */ + ChfCondition MOD_W_BAD_CONFIG, CHF_WARNING, config_info ChfEnd; + ChfSignal(); + } + + else { + if ( mod_map.map_info[ mod ].config == MOD_UNCONFIGURED ) { + /* The module was unconfigured; configure its size */ + mod_map.map_info[ mod ].size = 0x100000 - config_info; + mod_map.map_info[ mod ].config = MOD_SIZE_CONFIGURED; + } + + else { + /* The module size was already configured; configure its base address */ + mod_map.map_info[ mod ].abs_base_addr = config_info; + mod_map.map_info[ mod ].config = MOD_CONFIGURED; + + /* Rebuild the page table */ + RebuildPageTable( ModPage( mod_map.map_info[ mod ].abs_base_addr ), + ModPage( mod_map.map_info[ mod ].abs_base_addr + mod_map.map_info[ mod ].size - 1 ) ); + + /* Mark the current struct ModMap to be a configuration point; + this flag is used by the unconfig cache code to correctly + undo the last config + */ + mod_map.cache.config_point = 1; + + debug3( DEBUG_C_MODULES | DEBUG_C_MOD_CACHE, MOD_I_CONFIG, mod_description[ mod ].name, mod_map.map_info[ mod ].abs_base_addr, + mod_map.map_info[ mod ].size ); + } + + /* Set the unconfig cache pointer of module 'mod' to the old ModMap, + and increment its reference counter, to avoid freeing it + improperly. + */ + mod_map.cache.unconfig[ mod ] = old; + old->cache.ref_count++; + } +} /* .+ @@ -1389,151 +1316,138 @@ void ModConfig(Address config_info) .kind : C function .creation : 26-Jan-1998 .description : - This function unconfigures the module currently configured at address + This function unconfigures the module currently configured at address 'unconfig_info' and returns it to its after-reset configuration status. ModUnconfig also rebuilds the page table used for module access to reflect the loss of visibility of the module in the CPU address space. .call : - ModUnconfig(unconfig_info); + ModUnconfig(unconfig_info); .input : - Address unconfig_info, Unconfig information + Address unconfig_info, Unconfig information .output : - void + void .status_codes : - MOD_I_CALLED - MOD_I_UNCONFIG - MOD_I_CACHED_UNCONFIG - MOD_I_PERF_CTR, performance counter: %s value: %d - MOD_W_BAD_UNCONFIG - MOD_F_MAP_ALLOC - MOD_F_CHAIN_CORRUPTED + MOD_I_CALLED + MOD_I_UNCONFIG + MOD_I_CACHED_UNCONFIG + MOD_I_PERF_CTR, performance counter: %s value: %d + MOD_W_BAD_UNCONFIG + MOD_F_MAP_ALLOC + MOD_F_CHAIN_CORRUPTED .notes : 1.1, 26-Jan-1998, creation 2.7, 15-Sep-2000, update - implemented module config/unconfig cache .- */ -void ModUnconfig(Address unconfig_info) +void ModUnconfig( Address unconfig_info ) { - struct ModMap *nxt, *old; - int mod; + struct ModMap *nxt, *old; + int mod; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "ModUnconfig"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModUnconfig" ); - /* Determine the module to unconfigure */ - if((mod = mod_map.page_table[ModPage(unconfig_info)].index) == - MOD_NO_MOD_INDEX) - { - /* There isn't any module configured at the given address - - Signal a warning - */ - ChfCondition MOD_W_BAD_UNCONFIG, CHF_WARNING, unconfig_info ChfEnd; - ChfSignal(); - } - - else if(mod_description[mod].r_config == MOD_CONFIGURED) - { - /* The module is automatically configured after reset; it can never - be unconfigured. - */ - } - - else - { - /* Unconfiguring module 'mod': ACCESS UNCONFIG CACHE */ - if((nxt = AccessUnconfigCache(mod)) != (struct ModMap *)NULL) - { - /* CACHE HIT; switch mod_map_ptr */ - mod_map_ptr = nxt; - - IncPerfCtr(hit_c); - - debug0(DEBUG_C_MOD_CACHE, MOD_I_CACHED_UNCONFIG); - return; + /* Determine the module to unconfigure */ + if ( ( mod = mod_map.page_table[ ModPage( unconfig_info ) ].index ) == MOD_NO_MOD_INDEX ) { + /* There isn't any module configured at the given address - + Signal a warning + */ + ChfCondition MOD_W_BAD_UNCONFIG, CHF_WARNING, unconfig_info ChfEnd; + ChfSignal(); } - /* CACHE MISS - - A clone of the current struct ModMap is allocated and updated - according to the unconfig instruction being executed. - - Then, CheckForLateHit() is called to check whether in the - module mapping cache there is a struct ModMap identical to - the updated one. - - - If there is, the .unconfig[i] link is updated to point to - the cache entry just found. - - - If there is not, the whole cache is flushed and all cached - ModMap structures allocated so far are freed, except the - current one. I hope this occurrence is rare. - */ - - /* Save pointer to the old map and switch to a temporary one */ - old = mod_map_ptr; - mod_map_ptr = CopyModMap(NewModMap(), mod_map_ptr); - - /* Update the mapping information table */ - mod_map.map_info[mod].config = mod_description[mod].r_config; - - /* Rebuild the page table */ - RebuildPageTable( - ModPage(mod_map.map_info[mod].abs_base_addr), - ModPage(mod_map.map_info[mod].abs_base_addr + - mod_map.map_info[mod].size - 1)); - - /* Reset the module configuration status; the abs_base_addr of the module - is not reset because its old value is still needed by ModGetId() - The size is reset for the modules that are already MOD_SIZE_CONFIGURED - immediately after reset. - */ - mod_map.map_info[mod].size = mod_description[mod].r_size; - - if((nxt = CheckForLateHit()) != (struct ModMap *)NULL) - { - /* Update pointer from the old map to the new one, and increment - reference counter of the referenced structure - */ - old->cache.unconfig[mod] = nxt; - nxt->cache.ref_count++; - - /* Discard the temporary map and switch to the cached one */ - FreeModMap(mod_map_ptr); - mod_map_ptr = nxt; - - IncPerfCtr(lhit_c); - debug0(DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_HIT); + else if ( mod_description[ mod ].r_config == MOD_CONFIGURED ) { + /* The module is automatically configured after reset; it can never + be unconfigured. + */ } - else - { - /* Continue to use the new map with no caching information, - and hope that further configuration activities will link it - back in the immediate future. - */ + else { + /* Unconfiguring module 'mod': ACCESS UNCONFIG CACHE */ + if ( ( nxt = AccessUnconfigCache( mod ) ) != ( struct ModMap* )NULL ) { + /* CACHE HIT; switch mod_map_ptr */ + mod_map_ptr = nxt; - /* Mark the current struct ModMap to be a configuration point; - this flag is used by the unconfig cache code to correctly - undo the last config - */ - mod_map.cache.config_point = 1; + IncPerfCtr( hit_c ); - IncPerfCtr(miss_c); + debug0( DEBUG_C_MOD_CACHE, MOD_I_CACHED_UNCONFIG ); + return; + } - debug0(DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_MISS); + /* CACHE MISS - debug3(DEBUG_C_MODULES|DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG, - mod_description[mod].name, - mod_map.map_info[mod].abs_base_addr, - mod_map.map_info[mod].size - ); + A clone of the current struct ModMap is allocated and updated + according to the unconfig instruction being executed. + + Then, CheckForLateHit() is called to check whether in the + module mapping cache there is a struct ModMap identical to + the updated one. + + - If there is, the .unconfig[i] link is updated to point to + the cache entry just found. + + - If there is not, the whole cache is flushed and all cached + ModMap structures allocated so far are freed, except the + current one. I hope this occurrence is rare. + */ + + /* Save pointer to the old map and switch to a temporary one */ + old = mod_map_ptr; + mod_map_ptr = CopyModMap( NewModMap(), mod_map_ptr ); + + /* Update the mapping information table */ + mod_map.map_info[ mod ].config = mod_description[ mod ].r_config; + + /* Rebuild the page table */ + RebuildPageTable( ModPage( mod_map.map_info[ mod ].abs_base_addr ), + ModPage( mod_map.map_info[ mod ].abs_base_addr + mod_map.map_info[ mod ].size - 1 ) ); + + /* Reset the module configuration status; the abs_base_addr of the module + is not reset because its old value is still needed by ModGetId() + The size is reset for the modules that are already MOD_SIZE_CONFIGURED + immediately after reset. + */ + mod_map.map_info[ mod ].size = mod_description[ mod ].r_size; + + if ( ( nxt = CheckForLateHit() ) != ( struct ModMap* )NULL ) { + /* Update pointer from the old map to the new one, and increment + reference counter of the referenced structure + */ + old->cache.unconfig[ mod ] = nxt; + nxt->cache.ref_count++; + + /* Discard the temporary map and switch to the cached one */ + FreeModMap( mod_map_ptr ); + mod_map_ptr = nxt; + + IncPerfCtr( lhit_c ); + debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_HIT ); + } + + else { + /* Continue to use the new map with no caching information, + and hope that further configuration activities will link it + back in the immediate future. + */ + + /* Mark the current struct ModMap to be a configuration point; + this flag is used by the unconfig cache code to correctly + undo the last config + */ + mod_map.cache.config_point = 1; + + IncPerfCtr( miss_c ); + + debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_MISS ); + + debug3( DEBUG_C_MODULES | DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG, mod_description[ mod ].name, mod_map.map_info[ mod ].abs_base_addr, + mod_map.map_info[ mod ].size ); + } } - } } - /* .+ .title : FetchNibble @@ -1545,27 +1459,25 @@ void ModUnconfig(Address unconfig_info) NOTE: This function DOES NOT update the hardware CRC register. .call : - d = FetchNibble(addr); + d = FetchNibble(addr); .input : - Address addr, address + Address addr, address .output : - Nibble *d, datum + Nibble *d, datum .status_codes : - NOTE: This function indirectly reports and condition generated - and/or signalled by the module read function. + NOTE: This function indirectly reports and condition generated + and/or signalled by the module read function. .notes : 1.1, 26-Jan-1998, creation .- */ -Nibble FetchNibble(Address addr) +Nibble FetchNibble( Address addr ) { - register int page = ModPage(addr); + register int page = ModPage( addr ); - return mod_map.page_table[page].read( - mod_map.page_table[page].rel_base_addr | ModOffset(addr)); + return mod_map.page_table[ page ].read( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ) ); } - /* .+ .title : ReadNibble @@ -1575,43 +1487,40 @@ Nibble FetchNibble(Address addr) This function reads a nibble from the address 'addr' and returns it. NOTE: This function updates the hardware CRC register if the target of the - read operation is not the HDW module. The current (1.1) implementation - of this feature is inefficient because the .index field of the - addressed page must be checked against MOD_HDW_INDEX for each - access. + read operation is not the HDW module. The current (1.1) implementation + of this feature is inefficient because the .index field of the + addressed page must be checked against MOD_HDW_INDEX for each + access. .call : - d = ReadNibble(addr); + d = ReadNibble(addr); .input : - Address addr, address + Address addr, address .output : - Nibble *d, datum + Nibble *d, datum .status_codes : - NOTE: This function indirectly reports and condition generated - and/or signalled by the module read function. + NOTE: This function indirectly reports and condition generated + and/or signalled by the module read function. .notes : 1.1, 26-Jan-1998, creation .- */ -Nibble ReadNibble(Address addr) +Nibble ReadNibble( Address addr ) { - register int page = ModPage(addr); - register Nibble d; + register int page = ModPage( addr ); + register Nibble d; - /* Read the nibble from the peripheral module */ - d = mod_map.page_table[page].read( - mod_map.page_table[page].rel_base_addr | ModOffset(addr)); + /* Read the nibble from the peripheral module */ + d = mod_map.page_table[ page ].read( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ) ); - /* Update the crc register, if appropriate */ - if(mod_map.page_table[page].index != MOD_HDW_INDEX) - mod_status.hdw.crc = - (mod_status.hdw.crc >> 4) ^ (((mod_status.hdw.crc ^ d) & 0x0F) * 0x1081); + /* Update the crc register, if appropriate */ + if ( mod_map.page_table[ page ].index != MOD_HDW_INDEX ) + mod_status.hdw.crc = ( mod_status.hdw.crc >> 4 ) ^ ( ( ( mod_status.hdw.crc ^ d ) & 0x0F ) * 0x1081 ); - /* Return to the caller */ - return d; + /* Return to the caller */ + return d; } - /* .+ .title : WriteNibble @@ -1623,33 +1532,30 @@ Nibble ReadNibble(Address addr) NOTE: This function DOES NOT update the hardware CRC register. .call : - WriteNibble(addr, datum); + WriteNibble(addr, datum); .input : - Address addr, destination address - Nibble datum, nibble to be written + Address addr, destination address + Nibble datum, nibble to be written .output : - void + void .status_codes : - NOTE: This function indirectly reports and condition generated - and/or signalled by the module write function. + NOTE: This function indirectly reports and condition generated + and/or signalled by the module write function. .notes : 1.1, 26-Jan-1998, creation .- */ -void WriteNibble(Address addr, Nibble datum) +void WriteNibble( Address addr, Nibble datum ) { - register int page = ModPage(addr); + register int page = ModPage( addr ); - mod_map.page_table[page].write( - mod_map.page_table[page].rel_base_addr | ModOffset(addr), datum); + mod_map.page_table[ page ].write( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ), datum ); } - /*--------------------------------------------------------------------------- - Monitor functions + Monitor functions ---------------------------------------------------------------------------*/ - /* .+ .title : ModMapCheck @@ -1660,42 +1566,39 @@ void WriteNibble(Address addr, Nibble datum) for address 'addr'; it is used by the emulator monitor only. .call : - ModMapCheck(addr, char ob[MOD_MAP_CHECK_OB_SIZE]); + ModMapCheck(addr, char ob[MOD_MAP_CHECK_OB_SIZE]); .input : - Address addr; + Address addr; .output : - void + void .status_codes : - * + * .notes : 1.1, 26-Jan-1998, creation .- */ -void ModMapCheck(Address addr, char ob[MOD_MAP_CHECK_OB_SIZE]) +void ModMapCheck( Address addr, char ob[ MOD_MAP_CHECK_OB_SIZE ] ) { - int page; - Address offset; - int mod; + int page; + Address offset; + int mod; - page = ModPage(addr); - offset = ModOffset(addr); + page = ModPage( addr ); + offset = ModOffset( addr ); - if((mod = mod_map.page_table[page].index) == MOD_NO_MOD_INDEX) - sprintf(ob, ChfGetMessage(CHF_MODULE_ID, MOD_M_NOT_MAPPED, ""), addr); + if ( ( mod = mod_map.page_table[ page ].index ) == MOD_NO_MOD_INDEX ) + sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_NOT_MAPPED, "" ), addr ); - else - { - Address rel_addr; - rel_addr = mod_map.page_table[page].rel_base_addr | offset; - - sprintf(ob, ChfGetMessage(CHF_MODULE_ID, MOD_M_MAPPED, ""), - addr, mod_description[mod].name, rel_addr); - } + else { + Address rel_addr; + rel_addr = mod_map.page_table[ page ].rel_base_addr | offset; - ChfSignal(); + sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_MAPPED, "" ), addr, mod_description[ mod ].name, rel_addr ); + } + + ChfSignal(); } - /* .+ .title : ModMapTable @@ -1706,37 +1609,33 @@ void ModMapCheck(Address addr, char ob[MOD_MAP_CHECK_OB_SIZE]) all modules; it is used by the emulator monitor only. .call : - ModMapTable(char ob[MOD_MAP_TABLE_OB_SIZE]); + ModMapTable(char ob[MOD_MAP_TABLE_OB_SIZE]); .input : - Address addr; + Address addr; .output : - void + void .status_codes : - * + * .notes : 1.1, 26-Jan-1998, creation .- */ -void ModMapTable(char ob[MOD_MAP_TABLE_OB_SIZE]) +void ModMapTable( char ob[ MOD_MAP_TABLE_OB_SIZE ] ) { - int mod; + int mod; - sprintf(ob, "%s\n", ChfGetMessage(CHF_MODULE_ID, MOD_M_MAP_TABLE_TITLE, "")); - ob += strlen(ob); + sprintf( ob, "%s\n", ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_TABLE_TITLE, "" ) ); + ob += strlen( ob ); - for(mod=0; mod> 6)) -#define ModOffset(address) ((address) & 0x0003F) +#define ModAddress( page ) ( ( Address )( page ) << 6 ) +#define ModPage( address ) ( ( int )( ( ( address ) & 0xFFFC0 ) >> 6 ) ) +#define ModOffset( address ) ( ( address ) & 0x0003F ) - -/* - ModDescription +/* + ModDescription This const array contains an entry for each peripheral module connected to the peripheral bus of the Saturn CPU; the entry describes the characteristics of the module. name: the mnemonic name of the module; the Saturn CPU doesn't - actually use this information, but it's still useful during - debugging. + actually use this information, but it's still useful during + debugging. id: the ID of the module, returned by the C=ID instruction - when the module is unconfigured. + when the module is unconfigured. access_prio: the access priority of the module, when the address spaces of - more than one module overlap. Higher values correspond to - higher priorities. + more than one module overlap. Higher values correspond to + higher priorities. - The configuration priority of the module, when there is more - than one unconfigured module on the peripheral bus, is - determined implicitly by the order in which the module - descriptions into the array. The modules that come first - in the array are configured first. + The configuration priority of the module, when there is more + than one unconfigured module on the peripheral bus, is + determined implicitly by the order in which the module + descriptions into the array. The modules that come first + in the array are configured first. init: this function is called, without arguments, during VM startup - to initialize the device. For example, the initialization - function for the ROM module will read the ROM image from - disk and store them into the module status structure. + to initialize the device. For example, the initialization + function for the ROM module will read the ROM image from + disk and store them into the module status structure. read: this function reads a nibble from the module. It receives the - relative address of the nibble to be read. The read function - can return an interrupt request for the CPU. + relative address of the nibble to be read. The read function + can return an interrupt request for the CPU. write: this function writes a nibble to the module. It receives the - relative address and the value of the nibble to be written. - The write function can return an interrupt request for the CPU. + relative address and the value of the nibble to be written. + The write function can return an interrupt request for the CPU. r_config: this flag contains the configuration status of the module after - a bus reset. If the after-reset configuration status is - MOD_CONFIGURED, the module can never be unconfigured. + a bus reset. If the after-reset configuration status is + MOD_CONFIGURED, the module can never be unconfigured. r_abs_base_addr: absolute base address of the module after a bus reset. - It should be set only if the module is at least partially - configured automatically after a bus reset. + It should be set only if the module is at least partially + configured automatically after a bus reset. r_size: size of the address window of the module after a bus reset. - It should be set only if the module is at least partially - configured automatically after a bus reset. + It should be set only if the module is at least partially + configured automatically after a bus reset. map_flags: special map flags: - MOD_MAP_FLAGS_ABS pass absolute addresses to module - read/write functions + MOD_MAP_FLAGS_ABS pass absolute addresses to module + read/write functions Notice that the current implementation requires that the index of the HDW registers in the mod_description table must be fixed and equal to MOD_HDW_INDEX... this is unfortunate. */ -typedef void (*ModInitFunction)(void); +typedef void ( *ModInitFunction )( void ); -typedef void (*ModSaveFunction)(void); +typedef void ( *ModSaveFunction )( void ); -typedef Nibble (*ModReadFunction)(Address rel_addr); +typedef Nibble ( *ModReadFunction )( Address rel_addr ); -typedef void (*ModWriteFunction)(Address rel_addr, Nibble data); +typedef void ( *ModWriteFunction )( Address rel_addr, Nibble data ); -enum ModConfig -{ - MOD_UNCONFIGURED, - MOD_SIZE_CONFIGURED, - MOD_CONFIGURED +enum ModConfig { MOD_UNCONFIGURED, MOD_SIZE_CONFIGURED, MOD_CONFIGURED }; + +struct ModDescriptionEntry { + char* name; + Address id; + int access_prio; +#define MOD_MIN_ACCESS_PRIO ( -1 ) + + ModInitFunction init; + ModSaveFunction save; + ModReadFunction read; + ModWriteFunction write; + enum ModConfig r_config; + Address r_abs_base_addr; + Address r_size; + + int map_flags; /* 3.3 */ +#define MOD_MAP_FLAGS_ABS 0x1 /* Abs addresses to r/w */ }; -struct ModDescriptionEntry -{ - char *name; - Address id; - int access_prio; -#define MOD_MIN_ACCESS_PRIO (-1) +#define MOD_HDW_INDEX 1 +typedef const struct ModDescriptionEntry ModDescription[ N_MOD ]; - ModInitFunction init; - ModSaveFunction save; - ModReadFunction read; - ModWriteFunction write; - enum ModConfig r_config; - Address r_abs_base_addr; - Address r_size; - - int map_flags; /* 3.3 */ -#define MOD_MAP_FLAGS_ABS 0x1 /* Abs addresses to r/w */ -}; - -#define MOD_HDW_INDEX 1 -typedef const struct ModDescriptionEntry ModDescription[N_MOD]; - - -/* - ModMapInfo +/* + ModMapInfo This array contains an entry for each peripheral module connected to the peripheral bus of the Saturn CPU; the entry describes the @@ -264,41 +254,39 @@ typedef const struct ModDescriptionEntry ModDescription[N_MOD]; config: contains the current configuration status of the module. abs_base_addr: contains the current absolute base address of the module. - It's valid only if the module is currently configured. + It's valid only if the module is currently configured. size: contains the current size of the address window of the module. - It's valid only if the module is currently configured. + It's valid only if the module is currently configured. */ -struct ModMapInfoEntry -{ - enum ModConfig config; - Address abs_base_addr; - Address size; +struct ModMapInfoEntry { + enum ModConfig config; + Address abs_base_addr; + Address size; }; -typedef struct ModMapInfoEntry ModMapInfo[N_MOD]; +typedef struct ModMapInfoEntry ModMapInfo[ N_MOD ]; - -/* - ModPageTable +/* + ModPageTable This array contains an entry (of type ModPageTableEntry) for each 'page' (of size #40 nibbles) of the Saturn CPU physical address space. For each page, the following information is stored: index: the index of the module that responds to the address range of - the page in the ModDescription table.The special value - MOD_NO_MOD_INDEX indicates that no module responds to the - address range. + the page in the ModDescription table.The special value + MOD_NO_MOD_INDEX indicates that no module responds to the + address range. rel_base_addr: the relative base address of the page in the address - space of the module that responds to the address range of - the page, if any. + space of the module that responds to the address range of + the page, if any. read, write: the read/write functions of the module that responds to the - address range of the page, if any. + address range of the page, if any. - Relative address calculation for module access + Relative address calculation for module access The Saturn Physical Address (SPA) is divided into two portions: @@ -313,20 +301,18 @@ typedef struct ModMapInfoEntry ModMapInfo[N_MOD]; The relative address (RA) therefore will be RA = RBA | OFF; then, the appropriate module access function, found again in ModPageTable[PI], is called. - -*/ -struct ModPageTableEntry -{ - int index; -#define MOD_NO_MOD_INDEX (-1) - Address rel_base_addr; - ModReadFunction read; - ModWriteFunction write; +*/ +struct ModPageTableEntry { + int index; +#define MOD_NO_MOD_INDEX ( -1 ) + + Address rel_base_addr; + ModReadFunction read; + ModWriteFunction write; }; -typedef struct ModPageTableEntry ModPageTable[N_PAGE_TABLE_ENTRIES]; - +typedef struct ModPageTableEntry ModPageTable[ N_PAGE_TABLE_ENTRIES ]; /* struct ModCache (2.7) @@ -359,58 +345,53 @@ typedef struct ModPageTableEntry ModPageTable[N_PAGE_TABLE_ENTRIES]; The .link field links all cached struct ModMap together. */ -struct ModCacheTableEntry -{ +struct ModCacheTableEntry { Address tag; - struct ModMap *map_ptr; + struct ModMap* map_ptr; }; -struct ModCache -{ - struct ModCacheTableEntry config[N_MOD_CACHE_ENTRIES]; +struct ModCache { + struct ModCacheTableEntry config[ N_MOD_CACHE_ENTRIES ]; int victim; - struct ModMap *(unconfig[N_MOD]); + struct ModMap*( unconfig[ N_MOD ] ); int config_point; int ref_count; - struct ModMap *link; + struct ModMap* link; }; - -/* - struct ModMap +/* + struct ModMap This structure contains all the mapping information about the peripheral modules of the Saturn CPU. Its components are: map_info: this array describes the dynamic mapping information of - each module connected to the Saturn peripheral bus. + each module connected to the Saturn peripheral bus. page_table: this array describes the current layout of the address space - of the Saturn CPU. + of the Saturn CPU. cache (2.7): this structure holds caching information used to speed up - module config/unconfig instructions + module config/unconfig instructions */ -struct ModMap -{ - ModMapInfo map_info; - ModPageTable page_table; - struct ModCache cache; +struct ModMap { + ModMapInfo map_info; + ModPageTable page_table; + struct ModCache cache; }; - /* - struct ModStatus + struct ModStatus This structure contains the actual status of all peripheral modules of the Saturn CPU. The status of all modules is centralized to allow any device to easily access the status of other devices. - struct ModHdw + struct ModHdw This substructure contains the status of all peripheral devices controlled by the hdw module. @@ -427,190 +408,179 @@ struct ModMap ModStatus structure except .hdw): contains the storage areas for ROM and RAM in configuration 'xx', and is private to the configuration-specific ROM/RAM emulation module. - + */ -struct ModHdw48Accel -{ - XAddress bs_address; /* Bank Switcher ext. address */ +struct ModHdw48Accel { + XAddress bs_address; /* Bank Switcher ext. address */ }; -struct ModHdw49Accel -{ - XAddress view[2]; /* Base of Flash views */ +struct ModHdw49Accel { + XAddress view[ 2 ]; /* Base of Flash views */ }; -struct ModHdw -{ - Nibble hdw[N_HDW_SIZE]; /* HDW registers */ +struct ModHdw { + Nibble hdw[ N_HDW_SIZE ]; /* HDW registers */ - /* LCD driver */ - Address lcd_base_addr; /* LCD driver base address */ - int lcd_on; /* LCD driver enable flag */ - int lcd_contrast; /* LCD contrast value */ - int lcd_vlc; /* LCD vertical line count */ - int lcd_offset; /* LCD horizontal offset */ - int lcd_line_offset; /* LCD line offset */ - Address lcd_menu_addr; /* LCD menu base address */ - int lcd_ann; /* LCD annunciators status */ + /* LCD driver */ + Address lcd_base_addr; /* LCD driver base address */ + int lcd_on; /* LCD driver enable flag */ + int lcd_contrast; /* LCD contrast value */ + int lcd_vlc; /* LCD vertical line count */ + int lcd_offset; /* LCD horizontal offset */ + int lcd_line_offset; /* LCD line offset */ + Address lcd_menu_addr; /* LCD menu base address */ + int lcd_ann; /* LCD annunciators status */ - /* Timers */ - Nibble t1_ctrl; /* Timer 1 control */ -#define T1_CTRL_EXTRA 0x01 -#define T1_CTRL_INT 0x02 -#define T1_CTRL_WAKE 0x04 -#define T1_CTRL_SREQ 0x08 + /* Timers */ + Nibble t1_ctrl; /* Timer 1 control */ +#define T1_CTRL_EXTRA 0x01 +#define T1_CTRL_INT 0x02 +#define T1_CTRL_WAKE 0x04 +#define T1_CTRL_SREQ 0x08 - Nibble t2_ctrl; /* Timer 2 control */ -#define T2_CTRL_TRUN 0x01 -#define T2_CTRL_INT 0x02 -#define T2_CTRL_WAKE 0x04 -#define T2_CTRL_SREQ 0x08 + Nibble t2_ctrl; /* Timer 2 control */ +#define T2_CTRL_TRUN 0x01 +#define T2_CTRL_INT 0x02 +#define T2_CTRL_WAKE 0x04 +#define T2_CTRL_SREQ 0x08 - Nibble t1_val; /* Timer 1 value */ - int32 t2_val; /* Timer 2 value */ + Nibble t1_val; /* Timer 1 value */ + int32 t2_val; /* Timer 2 value */ - /* 2.4: New member required to support Port emulation */ - Nibble card_status; /* Card status (hdw register 0x0F) */ -#define NCE3_CARD_PRESENT 0x01 -#define CE2_CARD_PRESENT 0x02 -#define NCE3_CARD_WE 0x04 -#define CE2_CARD_WE 0x08 + /* 2.4: New member required to support Port emulation */ + Nibble card_status; /* Card status (hdw register 0x0F) */ +#define NCE3_CARD_PRESENT 0x01 +#define CE2_CARD_PRESENT 0x02 +#define NCE3_CARD_WE 0x04 +#define CE2_CARD_WE 0x08 - /* 2.4: Hw configuration-specific members used as accelerators; - accel_valid is non-zero if the accelerators are valid - */ - int accel_valid; + /* 2.4: Hw configuration-specific members used as accelerators; + accel_valid is non-zero if the accelerators are valid + */ + int accel_valid; - union - { - struct ModHdw48Accel a48; - struct ModHdw49Accel a49; - } accel; + union { + struct ModHdw48Accel a48; + struct ModHdw49Accel a49; + } accel; - /* 2.5: Serial port buffer registers */ - int8 serial_rbr; - int8 serial_tbr; + /* 2.5: Serial port buffer registers */ + int8 serial_rbr; + int8 serial_tbr; - /* Misc */ - int16 crc; /* CRC */ + /* Misc */ + int16 crc; /* CRC */ }; -struct ModStatus -{ - struct ModHdw hdw; /* HDW status */ +struct ModStatus { + struct ModHdw hdw; /* HDW status */ }; -struct ModStatus_48 -{ - Nibble rom[N_ROM_SIZE]; /* Internal ROM */ - Nibble ram[N_RAM_SIZE]; /* Internal RAM */ - Nibble port_1[N_PORT_1_SIZE]; /* 2.4: Port_1 (CE2) storage */ +struct ModStatus_48 { + Nibble rom[ N_ROM_SIZE ]; /* Internal ROM */ + Nibble ram[ N_RAM_SIZE ]; /* Internal RAM */ + Nibble port_1[ N_PORT_1_SIZE ]; /* 2.4: Port_1 (CE2) storage */ - /* 2.4: Port_2 (NCE3) storage; only needed if N_PORT_2_BANK is defined */ + /* 2.4: Port_2 (NCE3) storage; only needed if N_PORT_2_BANK is defined */ #ifdef N_PORT_2_BANK - Nibble port_2[N_PORT_2_SIZE]; + Nibble port_2[ N_PORT_2_SIZE ]; #endif }; -struct ModStatus_49 -{ - Nibble flash[N_FLASH_SIZE_49]; /* Internal Flash ROM */ - Nibble ram[N_RAM_SIZE_49]; /* Internal RAM */ - Nibble *ce2, *nce3; /* ERAM bases */ +struct ModStatus_49 { + Nibble flash[ N_FLASH_SIZE_49 ]; /* Internal Flash ROM */ + Nibble ram[ N_RAM_SIZE_49 ]; /* Internal RAM */ + Nibble *ce2, *nce3; /* ERAM bases */ }; - /*--------------------------------------------------------------------------- - Global variables + Global variables ---------------------------------------------------------------------------*/ extern struct ModStatus mod_status; - /*--------------------------------------------------------------------------- - Chf condition codes + Chf condition codes ---------------------------------------------------------------------------*/ -#define MOD_I_CALLED 101 /* Function %s called */ -#define MOD_I_INITIALIZING 102 /* Initializing module %s */ -#define MOD_I_RESETTING 103 /* Resetting module %s */ -#define MOD_I_GET_ID 106 /* ModGetID returning %x */ -#define MOD_I_CONFIG 107 /* ModConfig %s %x %x completed */ -#define MOD_I_UNCONFIG 108 /* ModUnconfig %s %x %x completed */ -#define MOD_I_SAVING 109 /* Saving status of module %s */ -#define MOD_I_NOT_IMPLEMENTED 110 /* Function %s not implemented */ -#define MOD_I_REVISION 111 /* Modules revision: %s */ -#define MOD_I_BS_ADDRESS 112 /* 2.4: Bank Switcher address: %x */ -#define MOD_I_PORT_1_WP 113 /* 2.4: Port 1 is write protected */ -#define MOD_I_PORT_2_WP 114 /* 2.4: Port 2 is write protected */ -#define MOD_I_PERF_CTR 115 /* 2.7: Value of PerfCtr %s is %d */ -#define MOD_I_CACHED_UNCONFIG 116 /* 2.7: Cached ModUnconfig completed */ -#define MOD_I_CACHED_CONFIG 117 /* 2.7: Cached ModConfig %x comp. */ -#define MOD_I_UNCONFIG_L_HIT 118 /* 2.7: Late unconfig hit */ -#define MOD_I_UNCONFIG_L_MISS 119 /* 2.7: Late unconfig miss */ -#define MOD_W_BAD_CONFIG 202 /* Bad ModConfig %x ignored */ -#define MOD_W_BAD_UNCONFIG 203 /* Bad ModUnconfig %x ignored */ -#define MOD_W_HDW_WRITE 204 /* Bad HdwWrite %x, %x */ -#define MOD_W_HDW_READ 205 /* Bad HdwRead %x */ -#define MOD_W_RESETTING_ALL 206 /* Resetting all modules */ -#define MOD_W_RAM_INIT 207 /* Can't initialize internal RAM */ -#define MOD_W_HDW_INIT 208 /* Can't initialize HDW */ -#define MOD_W_BAD_KEY 209 /* 2.1: Bad key %s ignored */ -#define MOD_W_BAD_OUT_BIT 210 /* 2.1: Bad out_bit %x ignored */ -#define MOD_W_PORT_1_INIT 211 /* 2.4: Can't initialize Port 1 */ -#define MOD_W_PORT_2_INIT 212 /* 2.4: Can't initialize Port 2 */ -#define MOD_W_NO_VICTIM 213 /* 2.7: No cache victim; flush/retry */ -#define MOD_E_BAD_READ 301 /* Read unmapped addr %x */ -#define MOD_E_BAD_WRITE 302 /* Write unmapped addr %x datum %x */ -#define MOD_E_ROM_WRITE 303 /* Write into ROM addr %x datum %x */ -#define MOD_E_RAM_SAVE 304 /* Can't save internal RAM status */ -#define MOD_E_HDW_SAVE 305 /* Can't save HDW status */ -#define MOD_E_PORT_1_SAVE 306 /* 2.4: Can't save Port 1 status */ -#define MOD_E_CE1_WRITE 307 /* 2.4: Ce1Write addr %x datum %x */ -#define MOD_E_PORT_2_SAVE 308 /* 2.4: Can't save Port 2 status */ -#define MOD_E_NCE3_READ 309 /* 2.4: Read from NCE3 addr %x */ -#define MOD_E_NCE3_WRITE 310 /* 2.4: Wr. to NCE3 addr %x datum %x */ -#define MOD_E_NO_MATCH 311 /* 3.2: Hw desription %s not found */ -#define MOD_E_ROM_SAVE 312 /* 3.3: Can't save Flash ROM */ -#define MOD_F_MAP_SAVE 401 /* Can't save mod_map information */ -#define MOD_F_ROM_INIT 402 /* Can't initialize internal ROM */ -#define MOD_F_MAP_ALLOC 403 /* Dynamic map allocation failed */ -#define MOD_F_BAD_ALLOC_C 404 /* 2.7: Bad alloc_c %d aft FlushCache*/ -#define MOD_F_CHAIN_CORRUPTED 405 /* 2.7: ModMap chain corrupted */ -#define MOD_F_NO_VICTIM 406 /* 2.7: No cache victim after flush */ -#define MOD_F_MOD_STATUS_ALLOC 407 /* 3.2: ModStatus_xx alloc failed %d */ -#define MOD_F_NO_DESCRIPTION 408 /* 3.2: No module description */ -#define MOD_M_NOT_MAPPED 501 /* Address %x not mapped */ -#define MOD_M_MAPPED 502 /* Address %x mapped to %s:%x */ -#define MOD_M_MAP_TABLE_TITLE 503 /* */ -#define MOD_M_MAP_TABLE_ROW 504 /* %s %x %x %s */ -#define MOD_M_MAP_CONFIGURED 505 /* Configured */ -#define MOD_M_MAP_SZ_CONFIGURED 506 /* Size configured */ -#define MOD_M_MAP_UNCONFIGURED 507 /* Unconfigured */ - - +#define MOD_I_CALLED 101 /* Function %s called */ +#define MOD_I_INITIALIZING 102 /* Initializing module %s */ +#define MOD_I_RESETTING 103 /* Resetting module %s */ +#define MOD_I_GET_ID 106 /* ModGetID returning %x */ +#define MOD_I_CONFIG 107 /* ModConfig %s %x %x completed */ +#define MOD_I_UNCONFIG 108 /* ModUnconfig %s %x %x completed */ +#define MOD_I_SAVING 109 /* Saving status of module %s */ +#define MOD_I_NOT_IMPLEMENTED 110 /* Function %s not implemented */ +#define MOD_I_REVISION 111 /* Modules revision: %s */ +#define MOD_I_BS_ADDRESS 112 /* 2.4: Bank Switcher address: %x */ +#define MOD_I_PORT_1_WP 113 /* 2.4: Port 1 is write protected */ +#define MOD_I_PORT_2_WP 114 /* 2.4: Port 2 is write protected */ +#define MOD_I_PERF_CTR 115 /* 2.7: Value of PerfCtr %s is %d */ +#define MOD_I_CACHED_UNCONFIG 116 /* 2.7: Cached ModUnconfig completed */ +#define MOD_I_CACHED_CONFIG 117 /* 2.7: Cached ModConfig %x comp. */ +#define MOD_I_UNCONFIG_L_HIT 118 /* 2.7: Late unconfig hit */ +#define MOD_I_UNCONFIG_L_MISS 119 /* 2.7: Late unconfig miss */ +#define MOD_W_BAD_CONFIG 202 /* Bad ModConfig %x ignored */ +#define MOD_W_BAD_UNCONFIG 203 /* Bad ModUnconfig %x ignored */ +#define MOD_W_HDW_WRITE 204 /* Bad HdwWrite %x, %x */ +#define MOD_W_HDW_READ 205 /* Bad HdwRead %x */ +#define MOD_W_RESETTING_ALL 206 /* Resetting all modules */ +#define MOD_W_RAM_INIT 207 /* Can't initialize internal RAM */ +#define MOD_W_HDW_INIT 208 /* Can't initialize HDW */ +#define MOD_W_BAD_KEY 209 /* 2.1: Bad key %s ignored */ +#define MOD_W_BAD_OUT_BIT 210 /* 2.1: Bad out_bit %x ignored */ +#define MOD_W_PORT_1_INIT 211 /* 2.4: Can't initialize Port 1 */ +#define MOD_W_PORT_2_INIT 212 /* 2.4: Can't initialize Port 2 */ +#define MOD_W_NO_VICTIM 213 /* 2.7: No cache victim; flush/retry */ +#define MOD_E_BAD_READ 301 /* Read unmapped addr %x */ +#define MOD_E_BAD_WRITE 302 /* Write unmapped addr %x datum %x */ +#define MOD_E_ROM_WRITE 303 /* Write into ROM addr %x datum %x */ +#define MOD_E_RAM_SAVE 304 /* Can't save internal RAM status */ +#define MOD_E_HDW_SAVE 305 /* Can't save HDW status */ +#define MOD_E_PORT_1_SAVE 306 /* 2.4: Can't save Port 1 status */ +#define MOD_E_CE1_WRITE 307 /* 2.4: Ce1Write addr %x datum %x */ +#define MOD_E_PORT_2_SAVE 308 /* 2.4: Can't save Port 2 status */ +#define MOD_E_NCE3_READ 309 /* 2.4: Read from NCE3 addr %x */ +#define MOD_E_NCE3_WRITE 310 /* 2.4: Wr. to NCE3 addr %x datum %x */ +#define MOD_E_NO_MATCH 311 /* 3.2: Hw desription %s not found */ +#define MOD_E_ROM_SAVE 312 /* 3.3: Can't save Flash ROM */ +#define MOD_F_MAP_SAVE 401 /* Can't save mod_map information */ +#define MOD_F_ROM_INIT 402 /* Can't initialize internal ROM */ +#define MOD_F_MAP_ALLOC 403 /* Dynamic map allocation failed */ +#define MOD_F_BAD_ALLOC_C 404 /* 2.7: Bad alloc_c %d aft FlushCache*/ +#define MOD_F_CHAIN_CORRUPTED 405 /* 2.7: ModMap chain corrupted */ +#define MOD_F_NO_VICTIM 406 /* 2.7: No cache victim after flush */ +#define MOD_F_MOD_STATUS_ALLOC 407 /* 3.2: ModStatus_xx alloc failed %d */ +#define MOD_F_NO_DESCRIPTION 408 /* 3.2: No module description */ +#define MOD_M_NOT_MAPPED 501 /* Address %x not mapped */ +#define MOD_M_MAPPED 502 /* Address %x mapped to %s:%x */ +#define MOD_M_MAP_TABLE_TITLE 503 /* */ +#define MOD_M_MAP_TABLE_ROW 504 /* %s %x %x %s */ +#define MOD_M_MAP_CONFIGURED 505 /* Configured */ +#define MOD_M_MAP_SZ_CONFIGURED 506 /* Size configured */ +#define MOD_M_MAP_UNCONFIGURED 507 /* Unconfigured */ /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ /* Initialization */ -void ModSelectDescription(const char *hw); -void ModRegisterDescription(ModDescription p); -void ModInit(void); -void ModSave(void); -void ModReset(void); +void ModSelectDescription( const char* hw ); +void ModRegisterDescription( ModDescription p ); +void ModInit( void ); +void ModSave( void ); +void ModReset( void ); /* Configuration */ -Address ModGetID(void); -void ModConfig(Address config_info); -void ModUnconfig(Address unconfig_info); +Address ModGetID( void ); +void ModConfig( Address config_info ); +void ModUnconfig( Address unconfig_info ); /* Read/Write */ -Nibble FetchNibble(Address addr); -Nibble ReadNibble(Address addr); -void WriteNibble(Address addr, Nibble datum); +Nibble FetchNibble( Address addr ); +Nibble ReadNibble( Address addr ); +void WriteNibble( Address addr, Nibble datum ); /* Monitor */ -void ModMapCheck(Address addr, char ob[MOD_MAP_CHECK_OB_SIZE]); -void ModMapTable(char ob[MOD_MAP_TABLE_OB_SIZE]); +void ModMapCheck( Address addr, char ob[ MOD_MAP_CHECK_OB_SIZE ] ); +void ModMapTable( char ob[ MOD_MAP_TABLE_OB_SIZE ] ); diff --git a/src/monitor.c b/src/monitor.c index 71de239..51e86a3 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -85,232 +85,229 @@ static char rcs_id[] = "$Id: monitor.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" #include "args.h" #include "debug.h" -#define CHF_MODULE_ID CPU_CHF_MODULE_ID +#define CHF_MODULE_ID CPU_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Macro & Data type definitions + Macro & Data type definitions ---------------------------------------------------------------------------*/ -#define LINE_BUFFER_SIZE 512 -#define TOK_DELIMITERS " \t\n" -#define ADDRESS_FMT "%x" -#define COUNT_FMT "%d" -#define PROMPT "> " -#define OK 0 -#define FAILED 1 +#define LINE_BUFFER_SIZE 512 +#define TOK_DELIMITERS " \t\n" +#define ADDRESS_FMT "%x" +#define COUNT_FMT "%d" +#define PROMPT "> " +#define OK 0 +#define FAILED 1 /*--------------------------------------------------------------------------- - Private functions - Command line parse + Private functions - Command line parse ---------------------------------------------------------------------------*/ /* Read an Address from the command line */ -static int ReadHexAddress(Address *addr) +static int ReadHexAddress( Address* addr ) { - char *p = strtok((char *)NULL, TOK_DELIMITERS); - return (p == (char *)NULL || - sscanf(p, ADDRESS_FMT, addr) != 1) ? FAILED : OK; + char* p = strtok( ( char* )NULL, TOK_DELIMITERS ); + return ( p == ( char* )NULL || sscanf( p, ADDRESS_FMT, addr ) != 1 ) ? FAILED : OK; } /* Read a Nibble from the command line */ -static int ReadHexDatum(Nibble *n) +static int ReadHexDatum( Nibble* n ) { - Address addr; - int st; - if((st = ReadHexAddress(&addr)) == OK) *n = (Nibble)addr; - return st; + Address addr; + int st; + if ( ( st = ReadHexAddress( &addr ) ) == OK ) + *n = ( Nibble )addr; + return st; } /* Read a DECIMAL count from the command line */ -static int ReadCount(int *count) +static int ReadCount( int* count ) { - char *p = strtok((char *)NULL, TOK_DELIMITERS); - return (p == (char *)NULL || sscanf(p, COUNT_FMT, count) != 1 || - *count <= 0) ? FAILED : OK; + char* p = strtok( ( char* )NULL, TOK_DELIMITERS ); + return ( p == ( char* )NULL || sscanf( p, COUNT_FMT, count ) != 1 || *count <= 0 ) ? FAILED : OK; } - /*--------------------------------------------------------------------------- - Private functions - Command execution + Private functions - Command execution ---------------------------------------------------------------------------*/ /* Run the emulator; this function exits normally only when an EmulatorIntRequest() is posted and satisfied */ -static int run(void) +static int run( void ) { - Emulator(); - return OK; + Emulator(); + return OK; } /* Set the debug level */ -static int debug(void) +static int debug( void ) { - Address addr; - if(ReadHexAddress(&addr)) return FAILED; - SetDebugLevel((int)addr); - return OK; + Address addr; + if ( ReadHexAddress( &addr ) ) + return FAILED; + SetDebugLevel( ( int )addr ); + return OK; } /* Check the mapping of an Address and print */ -static int map_check(void) +static int map_check( void ) { - Address addr; - char ob[MOD_MAP_CHECK_OB_SIZE]; - if(ReadHexAddress(&addr)) return FAILED; - ModMapCheck(addr, ob); - puts(ob); - return OK; + Address addr; + char ob[ MOD_MAP_CHECK_OB_SIZE ]; + if ( ReadHexAddress( &addr ) ) + return FAILED; + ModMapCheck( addr, ob ); + puts( ob ); + return OK; } /* Print the current module map table */ -static int map(void) +static int map( void ) { - char ob[MOD_MAP_TABLE_OB_SIZE]; - ModMapTable(ob); - puts(ob); - return OK; + char ob[ MOD_MAP_TABLE_OB_SIZE ]; + ModMapTable( ob ); + puts( ob ); + return OK; } /* Write nibbles into memory */ -static int w(void) +static int w( void ) { - Address addr; - Nibble n; - if(ReadHexAddress(&addr)) return FAILED; - while(ReadHexDatum(&n) == OK) WriteNibble(addr++, n); - return OK; + Address addr; + Nibble n; + if ( ReadHexAddress( &addr ) ) + return FAILED; + while ( ReadHexDatum( &n ) == OK ) + WriteNibble( addr++, n ); + return OK; } /* Read nibbles from memory */ -static int r(void) +static int r( void ) { - Address addr; - int count; - if(ReadHexAddress(&addr)) return FAILED; - if(ReadCount(&count)) count=1; + Address addr; + int count; + if ( ReadHexAddress( &addr ) ) + return FAILED; + if ( ReadCount( &count ) ) + count = 1; - while(count-->0) - { - printf("A_%05X\t%X\n", addr, (int)FetchNibble(addr)); - addr++; - } + while ( count-- > 0 ) { + printf( "A_%05X\t%X\n", addr, ( int )FetchNibble( addr ) ); + addr++; + } - return OK; + return OK; } /* Disassemble */ -static int d(void) +static int d( void ) { - Address addr; - int count; - char ob[DISASSEMBLE_OB_SIZE]; + Address addr; + int count; + char ob[ DISASSEMBLE_OB_SIZE ]; - if(ReadHexAddress(&addr)) return FAILED; - if(ReadCount(&count)) count=1; + if ( ReadHexAddress( &addr ) ) + return FAILED; + if ( ReadCount( &count ) ) + count = 1; - while(count-->0) - { - addr = Disassemble(addr, ob); - puts(ob); - } + while ( count-- > 0 ) { + addr = Disassemble( addr, ob ); + puts( ob ); + } - return OK; + return OK; } /* Print CPU status */ -static int cpu(void) +static int cpu( void ) { - char ob[DUMP_CPU_STATUS_OB_SIZE]; - DumpCpuStatus(ob); - puts(ob); - return OK; + char ob[ DUMP_CPU_STATUS_OB_SIZE ]; + DumpCpuStatus( ob ); + puts( ob ); + return OK; } /* Reset CPU */ -static int reset(void) +static int reset( void ) { - CpuReset(); - return OK; + CpuReset(); + return OK; } /* Save & Exit */ -static int mon_exit(void) +static int mon_exit( void ) { - ModSave(); - CpuSave(); - exit(EXIT_SUCCESS); - return OK; /* 3.1: Keep compiler happy */ + ModSave(); + CpuSave(); + exit( EXIT_SUCCESS ); + return OK; /* 3.1: Keep compiler happy */ } /* Quit without saving */ -static int mon_quit(void) +static int mon_quit( void ) { - exit(EXIT_SUCCESS); - return OK; /* 3.1: Keep compiler happy */ + exit( EXIT_SUCCESS ); + return OK; /* 3.1: Keep compiler happy */ } - /*--------------------------------------------------------------------------- - Command table + Command table ---------------------------------------------------------------------------*/ -struct TEntry -{ - char *name; - char *desc; - int (*function)(void); +struct TEntry { + char* name; + char* desc; + int ( *function )( void ); }; -#define TableSize(t) (sizeof(t)/sizeof(struct TEntry)) +#define TableSize( t ) ( sizeof( t ) / sizeof( struct TEntry ) ) /* Forward declaration for the Help funcion */ -static int Help(void); +static int Help( void ); -static const struct TEntry table[] = -{ - { "help", "Print this information", Help }, - { "run", "Run the emulator with current CPU status", run }, - { "?", ", Check address mapping", map_check }, - { "r", " [count], Read nibbles from memory", r }, - { "w", " [n]..., Write nibbles into memory", w }, - { "d", " [count], Disassemble starting from 'addr'", d }, - { "cpu", "Print CPU status", cpu }, - { "map", "Print the contents of the module map table", map }, - { "debug", "Set the debugging level", debug }, - { "reset", "Reset CPU", reset }, - { "exit", "Save emulator state & exit", mon_exit }, - { "quit", "Quit emulator WITHOUT saving its state", mon_quit } +static const struct TEntry table[] = { + {"help", "Print this information", Help }, + {"run", "Run the emulator with current CPU status", run }, + {"?", ", Check address mapping", map_check}, + {"r", " [count], Read nibbles from memory", r }, + {"w", " [n]..., Write nibbles into memory", w }, + {"d", " [count], Disassemble starting from 'addr'", d }, + {"cpu", "Print CPU status", cpu }, + {"map", "Print the contents of the module map table", map }, + {"debug", "Set the debugging level", debug }, + {"reset", "Reset CPU", reset }, + {"exit", "Save emulator state & exit", mon_exit }, + {"quit", "Quit emulator WITHOUT saving its state", mon_quit } }; /* Invoke the command 'tk' and return a status code */ -static int InvokeCommand(char *tk) +static int InvokeCommand( char* tk ) { - int i; - for(i=0; i - /* Maximum size of source ROM (bytes) handled by this utility; set to a reasonable value */ -#define MAX_SRC_SIZE (4*1024*1024) - +#define MAX_SRC_SIZE ( 4 * 1024 * 1024 ) /*--------------------------------------------------------------------------- Chf parameters - Do not change. The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE) ---------------------------------------------------------------------------*/ -#define CONDITION_STACK_SIZE 16 -#define HANDLER_STACK_SIZE 8 -#define ABNORMAL_EXIT_CODE EXIT_FAILURE +#define CONDITION_STACK_SIZE 16 +#define HANDLER_STACK_SIZE 8 +#define ABNORMAL_EXIT_CODE EXIT_FAILURE /* Conditional prefix and mandatory suffix to make a message catalog name from cat_base_name. @@ -108,30 +106,26 @@ static char rcs_id[] = "$Id"; static const char cat_prefix[] = "./"; static const char cat_suffix[] = ".cat"; -#define CAT_PREFIX_LEN (sizeof(cat_prefix)+1) -#define CAT_SUFFIX_LEN (sizeof(cat_suffix)+1) +#define CAT_PREFIX_LEN ( sizeof( cat_prefix ) + 1 ) +#define CAT_SUFFIX_LEN ( sizeof( cat_suffix ) + 1 ) /* Message catalog base_name */ static const char cat_base_name[] = "saturn"; - /* Condition codes used by this utility */ -#define UTIL_I_PACK_USAGE 1 -#define UTIL_F_PACK_CMD_LINE 2 -#define UTIL_F_PACK_STAT 3 -#define UTIL_F_PACK_SRC_SIZE 4 -#define UTIL_F_PACK_MALLOC 5 -#define UTIL_F_PACK_OPEN 6 -#define UTIL_F_PACK_READ 7 -#define UTIL_F_PACK_WRITE_NIBBLES 8 - - +#define UTIL_I_PACK_USAGE 1 +#define UTIL_F_PACK_CMD_LINE 2 +#define UTIL_F_PACK_STAT 3 +#define UTIL_F_PACK_SRC_SIZE 4 +#define UTIL_F_PACK_MALLOC 5 +#define UTIL_F_PACK_OPEN 6 +#define UTIL_F_PACK_READ 7 +#define UTIL_F_PACK_WRITE_NIBBLES 8 /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : main @@ -144,150 +138,131 @@ static const char cat_base_name[] = "saturn"; 3.6, 2-Oct-2000, creation .- */ -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { - char *cat_name; /* Message catalog name */ - struct stat statb; /* stat() buffer on source file */ - char *b; /* Source buffer */ - Nibble *nb; /* Nibble buffer */ - int d; /* Source file descriptor */ + char* cat_name; /* Message catalog name */ + struct stat statb; /* stat() buffer on source file */ + char* b; /* Source buffer */ + Nibble* nb; /* Nibble buffer */ + int d; /* Source file descriptor */ int i; int st; - if((cat_name = malloc(sizeof(cat_base_name) - +CAT_PREFIX_LEN+CAT_SUFFIX_LEN+1)) - == NULL) - { - fprintf(stderr, "Cat_name initialization failed\n"); - exit(ABNORMAL_EXIT_CODE); + if ( ( cat_name = malloc( sizeof( cat_base_name ) + CAT_PREFIX_LEN + CAT_SUFFIX_LEN + 1 ) ) == NULL ) { + fprintf( stderr, "Cat_name initialization failed\n" ); + exit( ABNORMAL_EXIT_CODE ); } /* Generate catalog name, without optional prefix */ - strcpy(cat_name, cat_base_name); - strcat(cat_name, cat_suffix); + strcpy( cat_name, cat_base_name ); + strcat( cat_name, cat_suffix ); /* Chf initialization with msgcat subsystem; notice that on some systems (e.g. Digital UNIX) catopen() can succeed even if it was not able to open the right message catalog; better try it now. */ - if((st = ChfMsgcatInit( - argv[0], /* Application's name */ - CHF_DEFAULT, /* Options */ - cat_name, /* Name of the message catalog */ - CONDITION_STACK_SIZE, /* Size of the condition stack */ - HANDLER_STACK_SIZE, /* Size of the handler stack */ - ABNORMAL_EXIT_CODE /* Abnormal exit code */ - )) != CHF_S_OK - || - ChfGetMessage(CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL) == NULL) - { - if(st != CHF_S_OK && st != CHF_F_CATOPEN) - { - fprintf(stderr, "Chf initialization failed\n"); - exit(ABNORMAL_EXIT_CODE); - } + if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */ + CHF_DEFAULT, /* Options */ + cat_name, /* Name of the message catalog */ + CONDITION_STACK_SIZE, /* Size of the condition stack */ + HANDLER_STACK_SIZE, /* Size of the handler stack */ + ABNORMAL_EXIT_CODE /* Abnormal exit code */ + ) ) != CHF_S_OK || + ChfGetMessage( CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL ) == NULL ) { + if ( st != CHF_S_OK && st != CHF_F_CATOPEN ) { + fprintf( stderr, "Chf initialization failed\n" ); + exit( ABNORMAL_EXIT_CODE ); + } - else - { - fprintf(stderr, - "Default message catalog open failed; trying alternate\n"); + else { + fprintf( stderr, "Default message catalog open failed; trying alternate\n" ); - /* Bring down Chf before initializing it again */ - if(st == CHF_S_OK) ChfExit(); + /* Bring down Chf before initializing it again */ + if ( st == CHF_S_OK ) + ChfExit(); - /* Try alternate message catalog name (with prefix) */ - strcpy(cat_name, cat_prefix); - strcat(cat_name, cat_base_name); - strcat(cat_name, cat_suffix); + /* Try alternate message catalog name (with prefix) */ + strcpy( cat_name, cat_prefix ); + strcat( cat_name, cat_base_name ); + strcat( cat_name, cat_suffix ); - if((st = ChfMsgcatInit( - argv[0], /* Application's name */ - CHF_DEFAULT, /* Options */ - cat_name, /* Name of the message catalog */ - CONDITION_STACK_SIZE, /* Size of the condition stack */ - HANDLER_STACK_SIZE, /* Size of the handler stack */ - ABNORMAL_EXIT_CODE /* Abnormal exit code */ - )) != CHF_S_OK - || - ChfGetMessage(CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL) == NULL) - { - fprintf(stderr, "Alternate Chf initialization failed\n"); - exit(ABNORMAL_EXIT_CODE); - } - } + if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */ + CHF_DEFAULT, /* Options */ + cat_name, /* Name of the message catalog */ + CONDITION_STACK_SIZE, /* Size of the condition stack */ + HANDLER_STACK_SIZE, /* Size of the handler stack */ + ABNORMAL_EXIT_CODE /* Abnormal exit code */ + ) ) != CHF_S_OK || + ChfGetMessage( CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL ) == NULL ) { + fprintf( stderr, "Alternate Chf initialization failed\n" ); + exit( ABNORMAL_EXIT_CODE ); + } + } } /* cat_name no longer needed */ - free(cat_name); + free( cat_name ); /* Now, do some useful work; pack argv[1] into argv[2] */ - if(argc != 3) - { - ChfCondition UTIL_I_PACK_USAGE, CHF_INFO ChfEnd; - ChfCondition UTIL_F_PACK_CMD_LINE, CHF_FATAL ChfEnd; - ChfSignal(); + if ( argc != 3 ) { + ChfCondition UTIL_I_PACK_USAGE, CHF_INFO ChfEnd; + ChfCondition UTIL_F_PACK_CMD_LINE, CHF_FATAL ChfEnd; + ChfSignal(); } /* Get the size of the source file */ - if(stat(argv[1], &statb)) - { - ChfErrnoCondition; - ChfCondition UTIL_F_PACK_STAT, CHF_FATAL, argv[1] ChfEnd; - ChfSignal(); + if ( stat( argv[ 1 ], &statb ) ) { + ChfErrnoCondition; + ChfCondition UTIL_F_PACK_STAT, CHF_FATAL, argv[ 1 ] ChfEnd; + ChfSignal(); } /* Check that actual size is reasonable */ - if(statb.st_size > MAX_SRC_SIZE) - { - ChfCondition UTIL_F_PACK_SRC_SIZE, CHF_FATAL, statb.st_size ChfEnd; - ChfSignal(); + if ( statb.st_size > MAX_SRC_SIZE ) { + ChfCondition UTIL_F_PACK_SRC_SIZE, CHF_FATAL, statb.st_size ChfEnd; + ChfSignal(); } /* Allocate source buffer */ - if((b = (char *)malloc(statb.st_size)) == (char *)NULL - || (nb = (Nibble *)malloc(sizeof(Nibble) * statb.st_size)) - == (Nibble *)NULL) - { - ChfErrnoCondition; - ChfCondition UTIL_F_PACK_MALLOC, CHF_FATAL, statb.st_size ChfEnd; - ChfSignal(); + if ( ( b = ( char* )malloc( statb.st_size ) ) == ( char* )NULL || + ( nb = ( Nibble* )malloc( sizeof( Nibble ) * statb.st_size ) ) == ( Nibble* )NULL ) { + ChfErrnoCondition; + ChfCondition UTIL_F_PACK_MALLOC, CHF_FATAL, statb.st_size ChfEnd; + ChfSignal(); - return EXIT_FAILURE; + return EXIT_FAILURE; } /* open/read/close */ - if((d = open(argv[1], O_RDONLY)) == -1) - { - ChfErrnoCondition; - ChfCondition UTIL_F_PACK_OPEN, CHF_FATAL, argv[1] ChfEnd; - ChfSignal(); + if ( ( d = open( argv[ 1 ], O_RDONLY ) ) == -1 ) { + ChfErrnoCondition; + ChfCondition UTIL_F_PACK_OPEN, CHF_FATAL, argv[ 1 ] ChfEnd; + ChfSignal(); } - if(read(d, b, statb.st_size) != statb.st_size) - { - ChfErrnoCondition; + if ( read( d, b, statb.st_size ) != statb.st_size ) { + ChfErrnoCondition; - (void)close(d); + ( void )close( d ); - ChfCondition UTIL_F_PACK_READ, CHF_FATAL, argv[1] ChfEnd; - ChfSignal(); + ChfCondition UTIL_F_PACK_READ, CHF_FATAL, argv[ 1 ] ChfEnd; + ChfSignal(); } - (void)close(d); + ( void )close( d ); /* Convert char -> Nibble */ - for(i=0; i #include #include -#include /* access() */ +#include /* access() */ #include #include "config.h" @@ -98,26 +98,24 @@ static char rcs_id[] = "$Id: romram.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "args.h" -#define CHF_MODULE_ID MOD_CHF_MODULE_ID +#define CHF_MODULE_ID MOD_CHF_MODULE_ID #include - /* 3.2: The rom/ram storage areas are now dynamically allocated in a private struct ModStatus_48. The dynamic allocation is performed during Rom initialization, and the following macro allows us to reuse the existing code with minimal updates. */ -static struct ModStatus_48 *mod_status_48; - -#define mod_status_hdw mod_status.hdw -#define mod_status_rom mod_status_48->rom -#define mod_status_ram mod_status_48->ram -#define mod_status_port_1 mod_status_48->port_1 -#define mod_status_port_2 mod_status_48->port_2 +static struct ModStatus_48* mod_status_48; +#define mod_status_hdw mod_status.hdw +#define mod_status_rom mod_status_48->rom +#define mod_status_ram mod_status_48->ram +#define mod_status_port_1 mod_status_48->port_1 +#define mod_status_port_2 mod_status_48->port_2 /*--------------------------------------------------------------------------- - Rom module + Rom module ---------------------------------------------------------------------------*/ /* .+ @@ -130,41 +128,35 @@ static struct ModStatus_48 *mod_status_48; module status structure, and initializes the Rom module. .call : - RomInit(); + RomInit(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_F_ROM_INIT - MOD_F_MOD_STATUS_ALLOC + MOD_I_CALLED + MOD_F_ROM_INIT + MOD_F_MOD_STATUS_ALLOC .notes : 1.1, 23-Jan-1998, creation .- */ -void RomInit(void) +void RomInit( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomInit"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit" ); - if((mod_status_48 = - (struct ModStatus_48 *)malloc(sizeof(struct ModStatus_48))) - == (struct ModStatus_48 *)NULL) - { - ChfErrnoCondition; - ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, - sizeof(struct ModStatus_48) ChfEnd; - ChfSignal(); + if ( ( mod_status_48 = ( struct ModStatus_48* )malloc( sizeof( struct ModStatus_48 ) ) ) == ( struct ModStatus_48* )NULL ) { + ChfErrnoCondition; + ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, sizeof( struct ModStatus_48 ) ChfEnd; + ChfSignal(); } - if(ReadNibblesFromFile(args.rom_file_name, N_ROM_SIZE, mod_status_rom)) - { - ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.rom_file_name, N_ROM_SIZE, mod_status_rom ) ) { + ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd; + ChfSignal(); } } - /* .+ .title : RomSave @@ -175,22 +167,18 @@ void RomInit(void) nothing. .call : - RomSave(); + RomSave(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 11-Feb-1998, creation .- */ -void RomSave(void) -{ - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomSave"); -} - +void RomSave( void ) { debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomSave" ); } /* .+ @@ -202,25 +190,24 @@ void RomSave(void) and returns it. .call : - d = RomRead(rel_address); + d = RomRead(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 26-Jan-1998, creation .- */ -Nibble RomRead(Address rel_address) +Nibble RomRead( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomRead"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomRead" ); - return mod_status_rom[rel_address]; + return mod_status_rom[ rel_address ]; } - /* .+ .title : RomWrite @@ -231,30 +218,29 @@ Nibble RomRead(Address rel_address) ROM location. It signals an error condition and does nothing. .call : - RomWrite(rel_address, datum); + RomWrite(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_ROM_WRITE + MOD_I_CALLED + MOD_E_ROM_WRITE .notes : 1.1, 26-Jan-1998, creation .- */ -void RomWrite(Address rel_address, Nibble datum) +void RomWrite( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomWrite"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomWrite" ); - ChfCondition MOD_E_ROM_WRITE, CHF_ERROR, rel_address, datum ChfEnd; - ChfSignal(); + ChfCondition MOD_E_ROM_WRITE, CHF_ERROR, rel_address, datum ChfEnd; + ChfSignal(); } - /*--------------------------------------------------------------------------- - Main Ram module + Main Ram module ---------------------------------------------------------------------------*/ /* .+ @@ -266,32 +252,30 @@ void RomWrite(Address rel_address, Nibble datum) This function initializes the Ram module. .call : - RamInit(); + RamInit(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_RAM_INIT + MOD_I_CALLED + MOD_W_RAM_INIT .notes : 1.1, 23-Jan-1998, creation .- */ -void RamInit(void) +void RamInit( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamInit"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamInit" ); - if(ReadNibblesFromFile(args.ram_file_name, N_RAM_SIZE, mod_status_ram)) - { - ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.ram_file_name, N_RAM_SIZE, mod_status_ram ) ) { + ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd; + ChfSignal(); - (void)memset(mod_status_ram, 0, sizeof(mod_status_ram)); - } + ( void )memset( mod_status_ram, 0, sizeof( mod_status_ram ) ); + } } - /* .+ .title : RamSave @@ -301,33 +285,31 @@ void RamInit(void) This function saves the status of the Ram module to disk. .call : - RamSave(); + RamSave(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_RAM_SAVE + MOD_I_CALLED + MOD_E_RAM_SAVE .notes : 1.1, 11-Feb-1998, creation 2.4, 12-Sep-2000, update - upon failure, added push of ChfErrnoCondition to condition stack. .- */ -void RamSave(void) +void RamSave( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamSave"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamSave" ); - if(WriteNibblesToFile(mod_status_ram, N_RAM_SIZE, args.ram_file_name)) - { - ChfErrnoCondition; - ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); - } + if ( WriteNibblesToFile( mod_status_ram, N_RAM_SIZE, args.ram_file_name ) ) { + ChfErrnoCondition; + ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); + } } - /* .+ .title : RamRead @@ -338,25 +320,24 @@ void RamSave(void) and returns it. .call : - d = RamRead(rel_address); + d = RamRead(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 26-Jan-1998, creation .- */ -Nibble RamRead(Address rel_address) +Nibble RamRead( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamRead"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamRead" ); - return mod_status_ram[rel_address]; + return mod_status_ram[ rel_address ]; } - /* .+ .title : RamWrite @@ -367,28 +348,27 @@ Nibble RamRead(Address rel_address) of the internal RAM. .call : - RamWrite(rel_address, datum); + RamWrite(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 26-Jan-1998, creation .- */ -void RamWrite(Address rel_address, Nibble datum) +void RamWrite( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamWrite"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamWrite" ); - mod_status_ram[rel_address] = datum; + mod_status_ram[ rel_address ] = datum; } - /*--------------------------------------------------------------------------- - Ce1 module + Ce1 module ---------------------------------------------------------------------------*/ /* .+ @@ -401,33 +381,31 @@ void RamWrite(Address rel_address, Nibble datum) Back Switcher. .call : - Ce1Init(); + Ce1Init(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce1Init(void) +void Ce1Init( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Init"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Init" ); - /* Check if bank-switcher accelerators are valid; if not, initialize - them to a reasonable value (that is, select Port_2 bank 0). - */ - if(!mod_status_hdw.accel_valid) - { - mod_status_hdw.accel_valid = 1; - mod_status_hdw.accel.a48.bs_address = (XAddress)0; - } + /* Check if bank-switcher accelerators are valid; if not, initialize + them to a reasonable value (that is, select Port_2 bank 0). + */ + if ( !mod_status_hdw.accel_valid ) { + mod_status_hdw.accel_valid = 1; + mod_status_hdw.accel.a48.bs_address = ( XAddress )0; + } } - /* .+ .title : Ce1Save @@ -437,28 +415,27 @@ void Ce1Init(void) This function saves the status of the Ce1 module. .call : - Ce1Save(); + Ce1Save(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 11-Feb-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce1Save(void) +void Ce1Save( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Save"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Save" ); - /* Nothing to be done herel the bank-switcher accelerators are saved - by the hdw modules - */ + /* Nothing to be done herel the bank-switcher accelerators are saved + by the hdw modules + */ } - /* .+ .title : Ce1Read @@ -471,37 +448,35 @@ void Ce1Save(void) most significant bits of Port_2 addresses when accessing that port. .call : - d = Ce1Read(rel_address); + d = Ce1Read(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED - MOD_I_BS_ADDRESS + MOD_I_CALLED + MOD_I_BS_ADDRESS .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -Nibble Ce1Read(Address rel_address) +Nibble Ce1Read( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Read"); - debug1(DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Read" ); + debug1( DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address ); - /* Save the read address into the hdw accelerators. - bs_address can be directly or-ed with a relative port address to - obtain a valid index in Port_2 - */ + /* Save the read address into the hdw accelerators. + bs_address can be directly or-ed with a relative port address to + obtain a valid index in Port_2 + */ #ifdef N_PORT_2_BANK - mod_status_hdw.accel.a48.bs_address = - ((XAddress)((rel_address >> 1) & 0x1F) << 18) & (N_PORT_2_SIZE-1); + mod_status_hdw.accel.a48.bs_address = ( ( XAddress )( ( rel_address >> 1 ) & 0x1F ) << 18 ) & ( N_PORT_2_SIZE - 1 ); #endif - return (Nibble)0x0; + return ( Nibble )0x0; } - /* .+ .title : Ce1Write @@ -513,31 +488,30 @@ Nibble Ce1Read(Address rel_address) state of mod_status_hdw.accel.a48.bs_address is *not* changed. .call : - Ce1Write(rel_address, datum); + Ce1Write(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_CE1_WRITE + MOD_I_CALLED + MOD_E_CE1_WRITE .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce1Write(Address rel_address, Nibble datum) +void Ce1Write( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Write"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Write" ); - ChfCondition MOD_E_CE1_WRITE, CHF_ERROR, rel_address, datum ChfEnd; - ChfSignal(); + ChfCondition MOD_E_CE1_WRITE, CHF_ERROR, rel_address, datum ChfEnd; + ChfSignal(); } - /*--------------------------------------------------------------------------- - Ce2 module + Ce2 module ---------------------------------------------------------------------------*/ /* .+ @@ -549,68 +523,61 @@ void Ce1Write(Address rel_address, Nibble datum) This function initializes the Ce2 module, corresponding to Port 1. .call : - Ce2Init(); + Ce2Init(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_PORT_1_INIT - MOD_I_PORT_1_WP + MOD_I_CALLED + MOD_W_PORT_1_INIT + MOD_I_PORT_1_WP .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce2Init(void) +void Ce2Init( void ) { Nibble new_status; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Init"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Init" ); - if(ReadNibblesFromFile(args.port_1_file_name, N_PORT_1_SIZE, - mod_status_port_1)) - { - ChfCondition MOD_W_PORT_1_INIT, CHF_WARNING ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.port_1_file_name, N_PORT_1_SIZE, mod_status_port_1 ) ) { + ChfCondition MOD_W_PORT_1_INIT, CHF_WARNING ChfEnd; + ChfSignal(); - (void)memset(mod_status_port_1, 0, sizeof(mod_status_port_1)); + ( void )memset( mod_status_port_1, 0, sizeof( mod_status_port_1 ) ); - new_status = - mod_status_hdw.card_status & ~(CE2_CARD_PRESENT|CE2_CARD_WE); + new_status = mod_status_hdw.card_status & ~( CE2_CARD_PRESENT | CE2_CARD_WE ); } - else - { - /* Card present; check write protection */ - new_status = mod_status_hdw.card_status | CE2_CARD_PRESENT; + else { + /* Card present; check write protection */ + new_status = mod_status_hdw.card_status | CE2_CARD_PRESENT; - if(access(args.port_1_file_name, W_OK) == 0) - new_status |= CE2_CARD_WE; + if ( access( args.port_1_file_name, W_OK ) == 0 ) + new_status |= CE2_CARD_WE; - else - { - new_status &= ~CE2_CARD_WE; + else { + new_status &= ~CE2_CARD_WE; - ChfErrnoCondition; - ChfCondition MOD_I_PORT_1_WP, CHF_INFO ChfEnd; - ChfSignal(); - } + ChfErrnoCondition; + ChfCondition MOD_I_PORT_1_WP, CHF_INFO ChfEnd; + ChfSignal(); + } } - if(new_status != mod_status_hdw.card_status) - { - /* card_status changed; update, set MP bit in HST and post - interrupt request. - */ - mod_status_hdw.card_status = new_status; - cpu_status.HST |= HST_MP_MASK; - CpuIntRequest(INT_REQUEST_IRQ); + if ( new_status != mod_status_hdw.card_status ) { + /* card_status changed; update, set MP bit in HST and post + interrupt request. + */ + mod_status_hdw.card_status = new_status; + cpu_status.HST |= HST_MP_MASK; + CpuIntRequest( INT_REQUEST_IRQ ); } } - /* .+ .title : Ce2Save @@ -621,35 +588,31 @@ void Ce2Init(void) not write-protected. .call : - Ce2Save(); + Ce2Save(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_PORT_1_SAVE + MOD_I_CALLED + MOD_E_PORT_1_SAVE .notes : 1.1, 11-Feb-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce2Save(void) +void Ce2Save( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Save"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Save" ); /* Attempt to save only if port is write-enabled */ - if((mod_status_hdw.card_status & CE2_CARD_WE) && - WriteNibblesToFile(mod_status_port_1, N_PORT_1_SIZE, - args.port_1_file_name)) - { - ChfErrnoCondition; - ChfCondition MOD_E_PORT_1_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); + if ( ( mod_status_hdw.card_status & CE2_CARD_WE ) && WriteNibblesToFile( mod_status_port_1, N_PORT_1_SIZE, args.port_1_file_name ) ) { + ChfErrnoCondition; + ChfCondition MOD_E_PORT_1_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); } } - /* .+ .title : Ce2Read @@ -659,26 +622,25 @@ void Ce2Save(void) This function reads a nibble from the Ce2 module. .call : - d = Ce2Read(rel_address) + d = Ce2Read(rel_address) .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -Nibble Ce2Read(Address rel_address) +Nibble Ce2Read( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Read"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Read" ); - return mod_status_port_1[rel_address]; + return mod_status_port_1[ rel_address ]; } - /* .+ .title : Ce2Write @@ -688,29 +650,28 @@ Nibble Ce2Read(Address rel_address) This function writes a nibble to the Ce2 module. .call : - Ce2Write(rel_address, datum); + Ce2Write(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void Ce2Write(Address rel_address, Nibble datum) +void Ce2Write( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Write"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Write" ); - mod_status_port_1[rel_address] = datum; + mod_status_port_1[ rel_address ] = datum; } - /*--------------------------------------------------------------------------- - NCe3 module + NCe3 module ---------------------------------------------------------------------------*/ /* .+ @@ -723,76 +684,68 @@ void Ce2Write(Address rel_address, Nibble datum) (bank switched) port 2. .call : - NCe3Init(); + NCe3Init(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_PORT_2_INIT - MOD_I_PORT_2_WP + MOD_I_CALLED + MOD_W_PORT_2_INIT + MOD_I_PORT_2_WP .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void NCe3Init(void) +void NCe3Init( void ) { Nibble new_status; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init" ); #ifdef N_PORT_2_BANK - if(ReadNibblesFromFile(args.port_2_file_name, N_PORT_2_SIZE, - mod_status_port_2)) - { - ChfCondition MOD_W_PORT_2_INIT, CHF_WARNING ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.port_2_file_name, N_PORT_2_SIZE, mod_status_port_2 ) ) { + ChfCondition MOD_W_PORT_2_INIT, CHF_WARNING ChfEnd; + ChfSignal(); - (void)memset(mod_status_port_2, 0, sizeof(mod_status_port_2)); + ( void )memset( mod_status_port_2, 0, sizeof( mod_status_port_2 ) ); - new_status = - mod_status_hdw.card_status & ~(NCE3_CARD_PRESENT|NCE3_CARD_WE); + new_status = mod_status_hdw.card_status & ~( NCE3_CARD_PRESENT | NCE3_CARD_WE ); } - else - { - /* Card present; check write protection */ - new_status = mod_status_hdw.card_status | NCE3_CARD_PRESENT; + else { + /* Card present; check write protection */ + new_status = mod_status_hdw.card_status | NCE3_CARD_PRESENT; - if(access(args.port_2_file_name, W_OK) == 0) - new_status |= NCE3_CARD_WE; + if ( access( args.port_2_file_name, W_OK ) == 0 ) + new_status |= NCE3_CARD_WE; - else - { - new_status &= ~NCE3_CARD_WE; + else { + new_status &= ~NCE3_CARD_WE; - ChfErrnoCondition; - ChfCondition MOD_I_PORT_2_WP, CHF_INFO ChfEnd; - ChfSignal(); - } + ChfErrnoCondition; + ChfCondition MOD_I_PORT_2_WP, CHF_INFO ChfEnd; + ChfSignal(); + } } #else /* If N_PORT_2_BANK is undefined, Port 2 is not emulated */ - new_status = - mod_status_hdw.card_status & ~(NCE3_CARD_PRESENT|NCE3_CARD_WE); + new_status = mod_status_hdw.card_status & ~( NCE3_CARD_PRESENT | NCE3_CARD_WE ); #endif - if(new_status != mod_status_hdw.card_status) - { - /* card_status changed; update, set MP bit in HST and post - interrupt request. - */ - mod_status_hdw.card_status = new_status; - cpu_status.HST |= HST_MP_MASK; - CpuIntRequest(INT_REQUEST_IRQ); + if ( new_status != mod_status_hdw.card_status ) { + /* card_status changed; update, set MP bit in HST and post + interrupt request. + */ + mod_status_hdw.card_status = new_status; + cpu_status.HST |= HST_MP_MASK; + CpuIntRequest( INT_REQUEST_IRQ ); } } - /* .+ .title : NCe3Save @@ -802,37 +755,33 @@ void NCe3Init(void) This function saves the status of the NCe3 module. .call : - NCe3Save(); + NCe3Save(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_PORT_2_SAVE + MOD_I_CALLED + MOD_E_PORT_2_SAVE .notes : 1.1, 11-Feb-1998, creation 2.4, 11-Sep-2000, implemented - + .- */ -void NCe3Save(void) +void NCe3Save( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Save"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Save" ); #ifdef N_PORT_2_BANK /* Attempt to save only if port is write-enabled */ - if((mod_status_hdw.card_status & NCE3_CARD_WE) && - WriteNibblesToFile(mod_status_port_2, N_PORT_2_SIZE, - args.port_2_file_name)) - { - ChfErrnoCondition; - ChfCondition MOD_E_PORT_2_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); + if ( ( mod_status_hdw.card_status & NCE3_CARD_WE ) && WriteNibblesToFile( mod_status_port_2, N_PORT_2_SIZE, args.port_2_file_name ) ) { + ChfErrnoCondition; + ChfCondition MOD_E_PORT_2_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); } #endif } - /* .+ .title : NCe3Read @@ -842,37 +791,35 @@ void NCe3Save(void) This function reads a nibble from the NCe3 module. .call : - d = NCe3Read(rel_address) + d = NCe3Read(rel_address) .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED - MOD_E_NCE3_READ + MOD_I_CALLED + MOD_E_NCE3_READ .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -Nibble NCe3Read(Address rel_address) +Nibble NCe3Read( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read" ); #ifdef N_PORT_2_BANK - return - mod_status_port_2[rel_address | mod_status_hdw.accel.a48.bs_address]; + return mod_status_port_2[ rel_address | mod_status_hdw.accel.a48.bs_address ]; #else ChfCondition MOD_E_NCE3_READ, CHF_ERROR, rel_address ChfEnd; ChfSignal(); - return (Nibble)0; + return ( Nibble )0; #endif } - /* .+ .title : NCe3Write @@ -883,28 +830,27 @@ Nibble NCe3Read(Address rel_address) it is not currently implemented. .call : - NCe3Write(rel_address, datum); + NCe3Write(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_NCE3_WRITE + MOD_I_CALLED + MOD_E_NCE3_WRITE .notes : 1.1, 23-Jan-1998, creation 2.4, 11-Sep-2000, implemented .- */ -void NCe3Write(Address rel_address, Nibble datum) +void NCe3Write( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Write"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Write" ); #ifdef N_PORT_2_BANK - mod_status_port_2[rel_address | mod_status_hdw.accel.a48.bs_address] - = datum; + mod_status_port_2[ rel_address | mod_status_hdw.accel.a48.bs_address ] = datum; #else ChfCondition MOD_E_NCE3_WRITE, CHF_ERROR, rel_address, datum ChfEnd; diff --git a/src/romram49.c b/src/romram49.c index 404a66c..7209635 100644 --- a/src/romram49.c +++ b/src/romram49.c @@ -98,7 +98,7 @@ static char rcs_id[] = "$Id: romram49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $ #include #include #include -#include /* access() */ +#include /* access() */ #include #include "config.h" @@ -111,28 +111,26 @@ static char rcs_id[] = "$Id: romram49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $ #include "args.h" -#define CHF_MODULE_ID MOD_CHF_MODULE_ID +#define CHF_MODULE_ID MOD_CHF_MODULE_ID #include +#define FLASH_VIEW_SELECTOR 0x40000 +#define FLASH_BANK_MASK 0x3FFFF -#define FLASH_VIEW_SELECTOR 0x40000 -#define FLASH_BANK_MASK 0x3FFFF +#define CE2_RAM_OFFSET 0x80000 +#define NCE3_RAM_OFFSET 0xC0000 +#define NCE3_RAM_MASK 0x3FFFF -#define CE2_RAM_OFFSET 0x80000 -#define NCE3_RAM_OFFSET 0xC0000 -#define NCE3_RAM_MASK 0x3FFFF - -#define HDW_LCR_OFFSET 0x1C -#define LCR_LED 0x8 +#define HDW_LCR_OFFSET 0x1C +#define LCR_LED 0x8 /* 3.3: This is no longer static, because flash49.c needs access to the Flash ROM array... yes, I know this is not particularly nice, */ -struct ModStatus_49 *mod_status_49; - +struct ModStatus_49* mod_status_49; /*--------------------------------------------------------------------------- - Rom module + Rom module ---------------------------------------------------------------------------*/ /* .+ @@ -145,42 +143,35 @@ struct ModStatus_49 *mod_status_49; module status structure, and initializes the Flash Rom module. .call : - RomInit49(); + RomInit49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_F_ROM_INIT - MOD_F_MOD_STATUS_ALLOC + MOD_I_CALLED + MOD_F_ROM_INIT + MOD_F_MOD_STATUS_ALLOC .notes : 3.2, 21-Sep-2000, creation .- */ -void RomInit49(void) +void RomInit49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomInit49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit49" ); - if((mod_status_49 = - (struct ModStatus_49 *)malloc(sizeof(struct ModStatus_49))) - == (struct ModStatus_49 *)NULL) - { - ChfErrnoCondition; - ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, - sizeof(struct ModStatus_49) ChfEnd; - ChfSignal(); + if ( ( mod_status_49 = ( struct ModStatus_49* )malloc( sizeof( struct ModStatus_49 ) ) ) == ( struct ModStatus_49* )NULL ) { + ChfErrnoCondition; + ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, sizeof( struct ModStatus_49 ) ChfEnd; + ChfSignal(); } - if(ReadNibblesFromFile(args.rom_file_name, N_FLASH_SIZE_49, - mod_status_49->flash)) - { - ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.rom_file_name, N_FLASH_SIZE_49, mod_status_49->flash ) ) { + ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd; + ChfSignal(); } } - /* .+ .title : RomSave49 @@ -190,33 +181,30 @@ void RomInit49(void) This function saves the status of the Flash Rom. .call : - RomSave49(); + RomSave49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_ROM_SAVE + MOD_I_CALLED + MOD_E_ROM_SAVE .notes : 3.2, 21-Sep-2000, creation 3.3, 25-Sep-2000, implemented .- */ -void RomSave49(void) +void RomSave49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomSave49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomSave49" ); - if(WriteNibblesToFile(mod_status_49->flash, N_FLASH_SIZE_49, - args.rom_file_name)) - { - ChfErrnoCondition; - ChfCondition MOD_E_ROM_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); + if ( WriteNibblesToFile( mod_status_49->flash, N_FLASH_SIZE_49, args.rom_file_name ) ) { + ChfErrnoCondition; + ChfCondition MOD_E_ROM_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); } } - /* .+ .title : RomRead49 @@ -227,30 +215,28 @@ void RomSave49(void) 'rel_address' and returns it. .call : - d = RomRead49(rel_address); + d = RomRead49(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -Nibble RomRead49(Address rel_address) +Nibble RomRead49( Address rel_address ) { register XAddress view; - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomRead49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomRead49" ); - view = mod_status.hdw.accel.a49.view[ - (rel_address & FLASH_VIEW_SELECTOR) != 0]; - - return mod_status_49->flash[view | (rel_address & FLASH_BANK_MASK)]; + view = mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ]; + + return mod_status_49->flash[ view | ( rel_address & FLASH_BANK_MASK ) ]; } - /* .+ .title : RomWrite49 @@ -266,31 +252,30 @@ Nibble RomRead49(Address rel_address) Those cycles are silently ignored. .call : - RomWrite49(rel_address, datum); + RomWrite49(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation 3.3, 26-Sep-2000, implemented .- */ -void RomWrite49(Address rel_address, Nibble datum) +void RomWrite49( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomWrite49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomWrite49" ); /* Ignore write cycles through ROM controller; HP49 ROM 1.19-4 can do this when to ON key is pressed. */ } - /*--------------------------------------------------------------------------- - Main Ram module + Main Ram module ---------------------------------------------------------------------------*/ /* .+ @@ -302,33 +287,30 @@ void RomWrite49(Address rel_address, Nibble datum) This function initializes the Ram module. .call : - RamInit49(); + RamInit49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_W_RAM_INIT + MOD_I_CALLED + MOD_W_RAM_INIT .notes : 3.2, 21-Sep-2000, creation .- */ -void RamInit49(void) +void RamInit49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamInit49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamInit49" ); - if(ReadNibblesFromFile(args.ram_file_name, N_RAM_SIZE_49, - mod_status_49->ram)) - { - ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd; - ChfSignal(); + if ( ReadNibblesFromFile( args.ram_file_name, N_RAM_SIZE_49, mod_status_49->ram ) ) { + ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd; + ChfSignal(); - (void)memset(mod_status_49->ram, 0, sizeof(mod_status_49->ram)); + ( void )memset( mod_status_49->ram, 0, sizeof( mod_status_49->ram ) ); } } - /* .+ .title : RamSave49 @@ -338,32 +320,29 @@ void RamInit49(void) This function saves the status of the Ram module to disk. .call : - RamSave49(); + RamSave49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED - MOD_E_RAM_SAVE + MOD_I_CALLED + MOD_E_RAM_SAVE .notes : 3.2, 21-Sep-2000, creation .- */ -void RamSave49(void) +void RamSave49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamSave49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamSave49" ); - if(WriteNibblesToFile(mod_status_49->ram, N_RAM_SIZE_49, - args.ram_file_name)) - { - ChfErrnoCondition; - ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd; - ChfSignal(); + if ( WriteNibblesToFile( mod_status_49->ram, N_RAM_SIZE_49, args.ram_file_name ) ) { + ChfErrnoCondition; + ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd; + ChfSignal(); } } - /* .+ .title : RamRead49 @@ -374,25 +353,24 @@ void RamSave49(void) and returns it. .call : - d = RamRead49(rel_address); + d = RamRead49(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -Nibble RamRead49(Address rel_address) +Nibble RamRead49( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamRead49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamRead49" ); - return mod_status_49->ram[rel_address]; + return mod_status_49->ram[ rel_address ]; } - /* .+ .title : RamWrite49 @@ -403,28 +381,27 @@ Nibble RamRead49(Address rel_address) of the internal RAM. .call : - RamWrite49(rel_address, datum); + RamWrite49(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void RamWrite49(Address rel_address, Nibble datum) +void RamWrite49( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RamWrite49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RamWrite49" ); - mod_status_49->ram[rel_address] = datum; + mod_status_49->ram[ rel_address ] = datum; } - /*--------------------------------------------------------------------------- - Ce1 module + Ce1 module ---------------------------------------------------------------------------*/ /* .+ @@ -437,34 +414,31 @@ void RamWrite49(Address rel_address, Nibble datum) Back Switcher. .call : - Ce1Init49(); + Ce1Init49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void Ce1Init49(void) +void Ce1Init49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Init49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Init49" ); /* Check if bank-switcher accelerators are valid; if not, initialize them to a reasonable value (that is, select Flash Rom bank 0 for both views). */ - if(!mod_status.hdw.accel_valid) - { - mod_status.hdw.accel_valid = 1; - mod_status.hdw.accel.a49.view[0] = - mod_status.hdw.accel.a49.view[1] = (XAddress)0; + if ( !mod_status.hdw.accel_valid ) { + mod_status.hdw.accel_valid = 1; + mod_status.hdw.accel.a49.view[ 0 ] = mod_status.hdw.accel.a49.view[ 1 ] = ( XAddress )0; } } - /* .+ .title : Ce1Save49 @@ -474,40 +448,36 @@ void Ce1Init49(void) This function saves the status of the Ce1 module. .call : - Ce1Save49(); + Ce1Save49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void Ce1Save49(void) +void Ce1Save49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Save49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Save49" ); /* Nothing to be done here; the bank-switcher accelerators are saved by the hdw modules */ } - /* This fragment of code is used by both Ce1Read49() and Ce1Write49(); the macro definition is here to allow us to write the code once and use it many times without incurring a function call overhead. */ -#define Ce1SetViews \ -{ \ - mod_status.hdw.accel.a49.view[0] = \ - ((XAddress)((rel_address >> 5) & 0x03) << 18); \ - \ - mod_status.hdw.accel.a49.view[1] = \ - ((XAddress)((rel_address >> 1) & 0x0F) << 18); \ -} - +#define Ce1SetViews \ + { \ + mod_status.hdw.accel.a49.view[ 0 ] = ( ( XAddress )( ( rel_address >> 5 ) & 0x03 ) << 18 ); \ + \ + mod_status.hdw.accel.a49.view[ 1 ] = ( ( XAddress )( ( rel_address >> 1 ) & 0x0F ) << 18 ); \ + } /* .+ @@ -522,33 +492,32 @@ void Ce1Save49(void) most significant bits of addresses when accessing Flash Rom. .call : - d = Ce1Read49(rel_address); + d = Ce1Read49(rel_address); .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED - MOD_I_BS_ADDRESS + MOD_I_CALLED + MOD_I_BS_ADDRESS .notes : 3.2, 21-Sep-2000, creation .- */ -Nibble Ce1Read49(Address rel_address) +Nibble Ce1Read49( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Read49"); - debug1(DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Read49" ); + debug1( DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address ); - /* Save the ROM view base addresses address into the hdw accelerators. - view[] can be directly or-ed with a relative port address to - obtain a valid index in Flash Rom. - */ - Ce1SetViews; + /* Save the ROM view base addresses address into the hdw accelerators. + view[] can be directly or-ed with a relative port address to + obtain a valid index in Flash Rom. + */ + Ce1SetViews; - return (Nibble)0x0; + return ( Nibble )0x0; } - /* .+ .title : Ce1Write49 @@ -562,34 +531,33 @@ Nibble Ce1Read49(Address rel_address) most significant bits of addresses when accessing Flash Rom. .call : - Ce1Write49(rel_address, datum); + Ce1Write49(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory; ignored + Address rel_address, memory address + Nibble datum, datum to be written into memory; ignored .output : - void + void .status_codes : - MOD_I_CALLED - MOD_I_BS_ADDRESS + MOD_I_CALLED + MOD_I_BS_ADDRESS .notes : 3.2, 21-Sep-2000, creation .- */ -void Ce1Write49(Address rel_address, Nibble datum) +void Ce1Write49( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Write49"); - debug1(DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce1Write49" ); + debug1( DEBUG_C_MODULES, MOD_I_BS_ADDRESS, rel_address ); - /* Save the ROM view base addresses address into the hdw accelerators. - view[] can be directly or-ed with a relative port address to - obtain a valid index in Flash Rom. - */ - Ce1SetViews; + /* Save the ROM view base addresses address into the hdw accelerators. + view[] can be directly or-ed with a relative port address to + obtain a valid index in Flash Rom. + */ + Ce1SetViews; } - /*--------------------------------------------------------------------------- - Ce2 module + Ce2 module ---------------------------------------------------------------------------*/ /* .+ @@ -602,13 +570,13 @@ void Ce1Write49(Address rel_address, Nibble datum) the first bank of ERAM. .call : - Ce2Init49(); + Ce2Init49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation 3.4, 27-Sep-2000, update: @@ -616,15 +584,15 @@ void Ce1Write49(Address rel_address, Nibble datum) HP39/40 firmware. .- */ -void Ce2Init49(void) +void Ce2Init49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Init49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Init49" ); /* Set base of ce2 area */ mod_status_49->ce2 = mod_status_49->ram + CE2_RAM_OFFSET; /* CE2 always present and write enabled */ - mod_status.hdw.card_status |= (CE2_CARD_PRESENT|CE2_CARD_WE); + mod_status.hdw.card_status |= ( CE2_CARD_PRESENT | CE2_CARD_WE ); #if 0 /* card_status changed; update, set MP bit in HST and post @@ -635,7 +603,6 @@ void Ce2Init49(void) #endif } - /* .+ .title : Ce2Save49 @@ -645,25 +612,24 @@ void Ce2Init49(void) This function saves the status of the Ce2 module. .call : - Ce2Save49(); + Ce2Save49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void Ce2Save49(void) +void Ce2Save49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Save49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Save49" ); /* Do nothing; the whole RAM is saved by RamSave49() */ } - /* .+ .title : Ce2Read49 @@ -673,25 +639,24 @@ void Ce2Save49(void) This function reads a nibble from the Ce2 module. .call : - d = Ce2Read49(rel_address) + d = Ce2Read49(rel_address) .input : - Address rel_address, memory address + Address rel_address, memory address .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -Nibble Ce2Read49(Address rel_address) +Nibble Ce2Read49( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Read49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Read49" ); - return mod_status_49->ce2[rel_address]; + return mod_status_49->ce2[ rel_address ]; } - /* .+ .title : Ce2Write49 @@ -701,28 +666,27 @@ Nibble Ce2Read49(Address rel_address) This function writes a nibble to the Ce2 module. .call : - Ce2Write49(rel_address, datum); + Ce2Write49(rel_address, datum); .input : - Address rel_address, memory address - Nibble datum, datum to be written into memory + Address rel_address, memory address + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation .- */ -void Ce2Write49(Address rel_address, Nibble datum) +void Ce2Write49( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Write49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "Ce2Write49" ); - mod_status_49->ce2[rel_address] = datum; + mod_status_49->ce2[ rel_address ] = datum; } - /*--------------------------------------------------------------------------- - NCe3 module + NCe3 module ---------------------------------------------------------------------------*/ /* .+ @@ -735,13 +699,13 @@ void Ce2Write49(Address rel_address, Nibble datum) the first bank of ERAM. .call : - NCe3Init49(); + NCe3Init49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation 3.4, 27-Sep-2000, update: @@ -749,15 +713,15 @@ void Ce2Write49(Address rel_address, Nibble datum) HP39/40 firmware. .- */ -void NCe3Init49(void) +void NCe3Init49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init49" ); /* Set base of nce3 area */ mod_status_49->nce3 = mod_status_49->ram + NCE3_RAM_OFFSET; /* NCE3 always present and write enabled */ - mod_status.hdw.card_status |= (NCE3_CARD_PRESENT|NCE3_CARD_WE); + mod_status.hdw.card_status |= ( NCE3_CARD_PRESENT | NCE3_CARD_WE ); #if 0 /* card_status changed; update, set MP bit in HST and post @@ -768,7 +732,6 @@ void NCe3Init49(void) #endif } - /* .+ .title : NCe3Save49 @@ -778,25 +741,24 @@ void NCe3Init49(void) This function saves the status of the NCe3 module. .call : - NCe3Save49(); + NCe3Save49(); .input : - void + void .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation - + .- */ -void NCe3Save49(void) +void NCe3Save49( void ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Save49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Save49" ); /* Do nothing; the whole RAM is saved by RamSave49() */ } - /* .+ .title : NCe3Read49 @@ -814,33 +776,29 @@ void NCe3Save49(void) the ABSOLUTE address of the memory access. .call : - d = NCe3Read49(rel_address) + d = NCe3Read49(rel_address) .input : - Address rel_address, memory address (ABSOLUTE) + Address rel_address, memory address (ABSOLUTE) .output : - Nibble *d, datum read from memory + Nibble *d, datum read from memory .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation 3.3, 25-Sep-2000, update - added vectors into flash49 for FlashROM read ops .- */ -Nibble NCe3Read49(Address rel_address) +Nibble NCe3Read49( Address rel_address ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read49" ); - return - (mod_status.hdw.hdw[HDW_LCR_OFFSET] & LCR_LED) - ? FlashRead49( - mod_status.hdw.accel.a49.view[ - (rel_address & FLASH_VIEW_SELECTOR) != 0] - | (rel_address & FLASH_BANK_MASK)) - : mod_status_49->nce3[rel_address & NCE3_RAM_MASK]; + return ( mod_status.hdw.hdw[ HDW_LCR_OFFSET ] & LCR_LED ) + ? FlashRead49( mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ] | + ( rel_address & FLASH_BANK_MASK ) ) + : mod_status_49->nce3[ rel_address & NCE3_RAM_MASK ]; } - /* .+ .title : NCe3Write49 @@ -859,29 +817,27 @@ Nibble NCe3Read49(Address rel_address) .call : - NCe3Write49(rel_address, datum); + NCe3Write49(rel_address, datum); .input : - Address rel_address, memory address (ABSOLUTE) - Nibble datum, datum to be written into memory + Address rel_address, memory address (ABSOLUTE) + Nibble datum, datum to be written into memory .output : - void + void .status_codes : - MOD_I_CALLED + MOD_I_CALLED .notes : 3.2, 21-Sep-2000, creation 3.3, 25-Sep-2000, update - added vectors into flash49 for FlashROM write ops .- */ -void NCe3Write49(Address rel_address, Nibble datum) +void NCe3Write49( Address rel_address, Nibble datum ) { - debug1(DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Write49"); + debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Write49" ); - if(mod_status.hdw.hdw[HDW_LCR_OFFSET] & LCR_LED) - FlashWrite49(mod_status.hdw.accel.a49.view[ - (rel_address & FLASH_VIEW_SELECTOR) != 0] - | (rel_address & FLASH_BANK_MASK), - datum); + if ( mod_status.hdw.hdw[ HDW_LCR_OFFSET ] & LCR_LED ) + FlashWrite49( mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ] | ( rel_address & FLASH_BANK_MASK ), + datum ); else - mod_status_49->nce3[rel_address & NCE3_RAM_MASK] = datum; + mod_status_49->nce3[ rel_address & NCE3_RAM_MASK ] = datum; } diff --git a/src/serial.c b/src/serial.c index f3d78ae..690be15 100644 --- a/src/serial.c +++ b/src/serial.c @@ -112,17 +112,16 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "config.h" #include "machdep.h" #include "cpu.h" -#include "serial.h" /* 2.5: Serial port emulation module */ +#include "serial.h" /* 2.5: Serial port emulation module */ #include "debug.h" #include "args.h" -#define CHF_MODULE_ID SERIAL_CHF_MODULE_ID +#define CHF_MODULE_ID SERIAL_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- - Determine pty implementation + Determine pty implementation Currently, the following two implementations are supported: @@ -151,52 +150,50 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #endif /* 3.5: Added linux support (__linux__ cpp macro) */ -#if (defined(__osf__) || defined(__linux__)) && !defined(FORCED) +#if ( defined( __osf__ ) || defined( __linux__ ) ) && !defined( FORCED ) # define USE_OPENPTY #endif /* 3.16: Added sgi support (__sgi cpp macro) */ -#if (defined(__sun__) || defined(__sgi)) && !defined(FORCED) +#if ( defined( __sun__ ) || defined( __sgi ) ) && !defined( FORCED ) # define USE_STREAMSPTY #endif /* 3.16: If no appropriate pty implementation has been found, throw a dummy implementation in. */ -#if !defined(USE_OPENPTY) && !defined(USE_STREAMSPTY) +#if !defined( USE_OPENPTY ) && !defined( USE_STREAMSPTY ) # define USE_NOPTY #endif #undef FORCED - /*--------------------------------------------------------------------------- - Include pty implementation-specific headers and definitions + Include pty implementation-specific headers and definitions ---------------------------------------------------------------------------*/ #ifdef USE_OPENPTY -#undef ADDRESS_MASK /* 2.6: Avoid name clash 8-( */ -#include /* fcntl() */ -#include /* ttyname() */ -#include /* openpty() */ -#include /* tcgetattr()/tcsetattr() */ -#include -#include +# undef ADDRESS_MASK /* 2.6: Avoid name clash 8-( */ +# include /* fcntl() */ +# include /* ttyname() */ +# include /* openpty() */ +# include /* tcgetattr()/tcsetattr() */ +# include +# include #endif #ifdef USE_STREAMSPTY -#undef ADDRESS_MASK /* 2.6: Avoid name clash 8-( */ +# undef ADDRESS_MASK /* 2.6: Avoid name clash 8-( */ /* stdlib.h already included */ -#include /* open(), fcntl() */ -#include -#include /* tcgetattr()/tcsetattr() */ -#include /* ioctl() */ -#define PTY_MASTER "/dev/ptmx" /* Master cloning device */ +# include /* open(), fcntl() */ +# include +# include /* tcgetattr()/tcsetattr() */ +# include /* ioctl() */ +# define PTY_MASTER "/dev/ptmx" /* Master cloning device */ #endif - /*--------------------------------------------------------------------------- - Private implementation of ring buffers + Private implementation of ring buffers The following data type definitions, macros, and functions together implement the ring buffers used to hold serial data being transmitted @@ -206,102 +203,105 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; ---------------------------------------------------------------------------*/ -#define RB_SIZE 1024 /* Buffer size (# of characters) */ +#define RB_SIZE 1024 /* Buffer size (# of characters) */ /* Hello, I am a RingBuffer... 8-} */ -struct RingBuffer -{ - int n; /* Number of full slots: 0 <= n <= RB_SIZE */ - int8 *rp, *wp; /* Read/Write pointers */ - int8 *ep; /* Pointer to the end of .data[] */ - int8 data[RB_SIZE]; /* Buffer storage */ +struct RingBuffer { + int n; /* Number of full slots: 0 <= n <= RB_SIZE */ + int8 *rp, *wp; /* Read/Write pointers */ + int8* ep; /* Pointer to the end of .data[] */ + int8 data[ RB_SIZE ]; /* Buffer storage */ }; /* Basic macros: Min(a, b) returns the minimum (as told by '<') between a and b; - warning: evaluates a and b twice. + warning: evaluates a and b twice. ReadPointer(rb) returns the read pointer of a given buffer; it - points to ContFullSlots() full buffer slots. + points to ContFullSlots() full buffer slots. FullSlots(rb) returns the number of full slots of a given buffer; - the slots are not necessarily contiguous. + the slots are not necessarily contiguous. ContFullSlots(rb) returns the number of *contiguous* full slots of a - given buffer, starting at the current ReadPointer; - this macro is guaranteed to return a strictly - positive value if the buffer is not empty. + given buffer, starting at the current ReadPointer; + this macro is guaranteed to return a strictly + positive value if the buffer is not empty. EmptySlots(rb) returns the number of empty slots of a given buffer; - the slots are not necessarily contiguous. + the slots are not necessarily contiguous. ContEmptySlots(rb) returns the number of *contiguous* empty slots of a - given buffer, starting at the current WritePointer; - this macro is guaranteed to return a strictly - positive value if the buffer is not full. + given buffer, starting at the current WritePointer; + this macro is guaranteed to return a strictly + positive value if the buffer is not full. UpdateReadPointer(rb, n) - moves the read pointer of ring buffer rb n slots - forward + moves the read pointer of ring buffer rb n slots + forward UpdateWritePointer(rb, n) - moves the write pointer of ring buffer rb n slots - forward + moves the write pointer of ring buffer rb n slots + forward Push(rb, c) pushes character c into ring buffer rb; this macro - must be invoked only if EmptySlots(rb) is strictly - positive. + must be invoked only if EmptySlots(rb) is strictly + positive. Pull(rb, cp) pulls a character from ring buffer rb and stores it - into *cp; this macro must be invoked only if - EmptySlots(rb) is strictly positive. + into *cp; this macro must be invoked only if + EmptySlots(rb) is strictly positive. InitRingBuffer(rb) initializes ring buffer rb; it must be called - before using the ring buffer in any way. + before using the ring buffer in any way. */ -#define Min(a, b) (((a) < (b)) ? (a) : (b)) -#define ReadPointer(rb) ((rb).rp) -#define FullSlots(rb) ((rb).n) -#define ContFullSlots(rb) (Min(FullSlots(rb), (rb).ep - ReadPointer(rb))) -#define WritePointer(rb) ((rb).wp) -#define EmptySlots(rb) (RB_SIZE - FullSlots(rb)) -#define ContEmptySlots(rb) (Min(EmptySlots(rb), (rb).ep - WritePointer(rb))) +#define Min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) +#define ReadPointer( rb ) ( ( rb ).rp ) +#define FullSlots( rb ) ( ( rb ).n ) +#define ContFullSlots( rb ) ( Min( FullSlots( rb ), ( rb ).ep - ReadPointer( rb ) ) ) +#define WritePointer( rb ) ( ( rb ).wp ) +#define EmptySlots( rb ) ( RB_SIZE - FullSlots( rb ) ) +#define ContEmptySlots( rb ) ( Min( EmptySlots( rb ), ( rb ).ep - WritePointer( rb ) ) ) -#define UpdateReadPointer(rb, n) \ -{ \ - FullSlots(rb) -= (n); \ - ReadPointer(rb) += (n); \ - if(ReadPointer(rb) >= (rb).ep) ReadPointer(rb) -= RB_SIZE; \ -} +#define UpdateReadPointer( rb, n ) \ + { \ + FullSlots( rb ) -= ( n ); \ + ReadPointer( rb ) += ( n ); \ + if ( ReadPointer( rb ) >= ( rb ).ep ) \ + ReadPointer( rb ) -= RB_SIZE; \ + } -#define UpdateWritePointer(rb, n) \ -{ \ - FullSlots(rb) += (n); \ - WritePointer(rb) += (n); \ - if(WritePointer(rb) >= (rb).ep) WritePointer(rb) -= RB_SIZE; \ -} +#define UpdateWritePointer( rb, n ) \ + { \ + FullSlots( rb ) += ( n ); \ + WritePointer( rb ) += ( n ); \ + if ( WritePointer( rb ) >= ( rb ).ep ) \ + WritePointer( rb ) -= RB_SIZE; \ + } -#define Push(rb, c) \ -{ \ - FullSlots(rb)++; \ - *(WritePointer(rb)++) = c; \ - if(WritePointer(rb) >= (rb).ep) WritePointer(rb) -= RB_SIZE; \ -} +#define Push( rb, c ) \ + { \ + FullSlots( rb )++; \ + *( WritePointer( rb )++ ) = c; \ + if ( WritePointer( rb ) >= ( rb ).ep ) \ + WritePointer( rb ) -= RB_SIZE; \ + } -#define Pull(rb, cp) \ -{ \ - FullSlots(rb)--; \ - *cp = *(ReadPointer(rb)++); \ - if(ReadPointer(rb) >= (rb).ep) ReadPointer(rb) -= RB_SIZE; \ -} +#define Pull( rb, cp ) \ + { \ + FullSlots( rb )--; \ + *cp = *( ReadPointer( rb )++ ); \ + if ( ReadPointer( rb ) >= ( rb ).ep ) \ + ReadPointer( rb ) -= RB_SIZE; \ + } -#define InitRingBuffer(rb) \ -{ \ - FullSlots(rb) = 0; \ - ReadPointer(rb) = WritePointer(rb) = (rb).data; \ - (rb).ep = (rb).data + RB_SIZE; \ -} +#define InitRingBuffer( rb ) \ + { \ + FullSlots( rb ) = 0; \ + ReadPointer( rb ) = WritePointer( rb ) = ( rb ).data; \ + ( rb ).ep = ( rb ).data + RB_SIZE; \ + } /* Push/Pull functions: @@ -318,188 +318,164 @@ struct RingBuffer read() reported an error. */ -static int PullAndWrite(struct RingBuffer *rbp, int fd) +static int PullAndWrite( struct RingBuffer* rbp, int fd ) { - int total = 0; /* Total # of chars written */ + int total = 0; /* Total # of chars written */ - while(FullSlots(*rbp) > 0) - { - int chunk = ContFullSlots(*rbp); /* Chunk size */ - int result; /* # of chars written */ + while ( FullSlots( *rbp ) > 0 ) { + int chunk = ContFullSlots( *rbp ); /* Chunk size */ + int result; /* # of chars written */ - /* write() takes its data from ReadPointer (full slots) */ - result = write(fd, ReadPointer(*rbp), chunk); + /* write() takes its data from ReadPointer (full slots) */ + result = write( fd, ReadPointer( *rbp ), chunk ); - if(result < 0 && errno != EAGAIN) - /* write() failed; return an error indication */ - return -1; + if ( result < 0 && errno != EAGAIN ) + /* write() failed; return an error indication */ + return -1; - if(result > 0) - { - /* write() wrote at least one character; update ReadPointer */ - total += result; - UpdateReadPointer(*rbp, result); - } + if ( result > 0 ) { + /* write() wrote at least one character; update ReadPointer */ + total += result; + UpdateReadPointer( *rbp, result ); + } - if(result != chunk) - /* Partial success of write(); break loop for now */ - break; + if ( result != chunk ) + /* Partial success of write(); break loop for now */ + break; } return total; } -static int ReadAndPush(struct RingBuffer *rbp, int fd) +static int ReadAndPush( struct RingBuffer* rbp, int fd ) { - int total = 0; /* Total # of chars read */ + int total = 0; /* Total # of chars read */ - while(EmptySlots(*rbp) > 0) - { - int chunk = ContEmptySlots(*rbp); /* Chunk size */ - int result; /* # of chars read */ + while ( EmptySlots( *rbp ) > 0 ) { + int chunk = ContEmptySlots( *rbp ); /* Chunk size */ + int result; /* # of chars read */ - /* read() puts its data into WritePointer (empty slots) */ - result = read(fd, WritePointer(*rbp), chunk); + /* read() puts its data into WritePointer (empty slots) */ + result = read( fd, WritePointer( *rbp ), chunk ); - if(result < 0 && errno != EAGAIN) - /* read() failed; return an error indication */ - return -1; + if ( result < 0 && errno != EAGAIN ) + /* read() failed; return an error indication */ + return -1; - if(result > 0) - { - /* read() read at least one character; update WritePointer */ - total += result; - UpdateWritePointer(*rbp, result); - } + if ( result > 0 ) { + /* read() read at least one character; update WritePointer */ + total += result; + UpdateWritePointer( *rbp, result ); + } - if(result != chunk) - /* Partial success of read(); break loop */ - break; + if ( result != chunk ) + /* Partial success of read(); break loop */ + break; } return total; } - /*--------------------------------------------------------------------------- - Static variables, holding the status of the emulated port + Static variables, holding the status of the emulated port ---------------------------------------------------------------------------*/ -static Nibble ioc = 0; /* I/O and interrupt control register */ -#define IOC_SON 0x08 /* Serial port enable */ -#define IOC_ETBE 0x04 /* Enable IRQ on TX buffer empty */ -#define IOC_ERBF 0x02 /* Enable IRQ on RX buffer full */ -#define IOC_ERBZ 0x01 /* Enable IRQ on RX buzy (sic) */ +static Nibble ioc = 0; /* I/O and interrupt control register */ +#define IOC_SON 0x08 /* Serial port enable */ +#define IOC_ETBE 0x04 /* Enable IRQ on TX buffer empty */ +#define IOC_ERBF 0x02 /* Enable IRQ on RX buffer full */ +#define IOC_ERBZ 0x01 /* Enable IRQ on RX buzy (sic) */ -static Nibble rcs = 0; /* RX control & status register */ -#define RCS_UNUSED 0x08 /* Unused (?) */ -#define RCS_RER 0x04 /* RX Error */ -#define RCS_RBZ 0x02 /* RX Buzy */ -#define RCS_RBF 0x01 /* RX Buffer full */ +static Nibble rcs = 0; /* RX control & status register */ +#define RCS_UNUSED 0x08 /* Unused (?) */ +#define RCS_RER 0x04 /* RX Error */ +#define RCS_RBZ 0x02 /* RX Buzy */ +#define RCS_RBF 0x01 /* RX Buffer full */ -static Nibble tcs = 0; /* TX control & status register */ -#define TCS_BRK 0x08 /* Unknown (?) */ -#define TCS_LPB 0x04 /* Unknown (?) */ -#define TCS_TBZ 0x02 /* TX Buzy */ -#define TCS_TBF 0x01 /* TX Buffer full */ +static Nibble tcs = 0; /* TX control & status register */ +#define TCS_BRK 0x08 /* Unknown (?) */ +#define TCS_LPB 0x04 /* Unknown (?) */ +#define TCS_TBZ 0x02 /* TX Buzy */ +#define TCS_TBF 0x01 /* TX Buffer full */ -static struct RingBuffer rrb; /* RX ring buffer */ -static struct RingBuffer trb; /* TX ring buffer */ - -static char *pty_name; /* Name of pty's slave side */ -static int master_pty; /* File descriptor of pty's master side */ -static int slave_pty; /* File descriptor of pty's slave side */ +static struct RingBuffer rrb; /* RX ring buffer */ +static struct RingBuffer trb; /* TX ring buffer */ +static char* pty_name; /* Name of pty's slave side */ +static int master_pty; /* File descriptor of pty's master side */ +static int slave_pty; /* File descriptor of pty's slave side */ /*--------------------------------------------------------------------------- - Helper macros + Helper macros CheckIRQ This macro checks the current status of ioc, rcs, and tcs, - and posts an interrupt request if appropriate. It should be - called by all functions that modify the above-mentioned - registers, after the modification has been made. - Interrupt requests are posted only when IOC_SON is set. + and posts an interrupt request if appropriate. It should be + called by all functions that modify the above-mentioned + registers, after the modification has been made. + Interrupt requests are posted only when IOC_SON is set. UpdateRCS This macro updates the rcs register according to the - current rrb FullSlots: - - if the receiver ring buffer holds more than 1 character, - RCS_RBZ and RCS_RBF are both set - - if the receiver ring buffer holds exactly 1 character, - RCS_RBZ is reset and RCS_RBF is set - - if the receiver ring buffer is empty, - RCS_RBZ and RCS_RBF are both reset + current rrb FullSlots: + - if the receiver ring buffer holds more than 1 character, + RCS_RBZ and RCS_RBF are both set + - if the receiver ring buffer holds exactly 1 character, + RCS_RBZ is reset and RCS_RBF is set + - if the receiver ring buffer is empty, + RCS_RBZ and RCS_RBF are both reset - 3.2: If HP49_SUPPORT is enabled, the RCS_RBZ bit is - always left clear and only RCS_RBF is updated; - this is simpler and works well on the 48, too. + 3.2: If HP49_SUPPORT is enabled, the RCS_RBZ bit is + always left clear and only RCS_RBF is updated; + this is simpler and works well on the 48, too. UpdateTCS This macro updates the tcs register according to the - current trb EmptySlots: - - if the transmitter ring buffer has more than 1 empty slot, - TCS_TBZ and TCS_TBF are both reset - - if the transmitter ring buffer has 1 empty slot, - TCS_TBZ is set and TCS_TBF is reset - - if the transmitter ring buffer is full, - TCS_TBZ and TCS_TBF are both set. + current trb EmptySlots: + - if the transmitter ring buffer has more than 1 empty slot, + TCS_TBZ and TCS_TBF are both reset + - if the transmitter ring buffer has 1 empty slot, + TCS_TBZ is set and TCS_TBF is reset + - if the transmitter ring buffer is full, + TCS_TBZ and TCS_TBF are both set. ---------------------------------------------------------------------------*/ -#define CheckIRQ \ -if((ioc & IOC_SON) \ - && ( \ - ((ioc & IOC_ETBE) && (! (tcs & TCS_TBF))) \ - || ((ioc & IOC_ERBF) && (rcs & RCS_RBF)) \ - || ((ioc & IOC_ERBZ) && (rcs & RCS_RBZ)) \ - )) CpuIntRequest(INT_REQUEST_IRQ) +#define CheckIRQ \ + if ( ( ioc & IOC_SON ) && ( ( ( ioc & IOC_ETBE ) && ( !( tcs & TCS_TBF ) ) ) || ( ( ioc & IOC_ERBF ) && ( rcs & RCS_RBF ) ) || \ + ( ( ioc & IOC_ERBZ ) && ( rcs & RCS_RBZ ) ) ) ) \ + CpuIntRequest( INT_REQUEST_IRQ ) #ifdef HP49_SUPPORT -#define UpdateRCS \ -if(FullSlots(rrb) > 0) \ -{ \ - rcs |= RCS_RBF; \ -} \ -else \ -{ \ - rcs &= ~(RCS_RBF); \ -} +# define UpdateRCS \ + if ( FullSlots( rrb ) > 0 ) { \ + rcs |= RCS_RBF; \ + } else { \ + rcs &= ~( RCS_RBF ); \ + } #else -#define UpdateRCS \ -if(FullSlots(rrb) > 1) \ -{ \ - rcs |= (RCS_RBF|RCS_RBZ); \ -} \ -else if(FullSlots(rrb) > 0) \ -{ \ - rcs |= RCS_RBF; \ - rcs &= ~RCS_RBZ; \ -} \ -else \ -{ \ - rcs &= ~(RCS_RBF|RCS_RBZ); \ -} +# define UpdateRCS \ + if ( FullSlots( rrb ) > 1 ) { \ + rcs |= ( RCS_RBF | RCS_RBZ ); \ + } else if ( FullSlots( rrb ) > 0 ) { \ + rcs |= RCS_RBF; \ + rcs &= ~RCS_RBZ; \ + } else { \ + rcs &= ~( RCS_RBF | RCS_RBZ ); \ + } #endif -#define UpdateTCS \ -if(EmptySlots(trb) > 1) \ -{ \ - tcs &= ~(TCS_TBF|TCS_TBZ); \ -} \ -else if(EmptySlots(trb) > 0) \ -{ \ - tcs &= ~TCS_TBF; \ - tcs |= TCS_TBZ; \ -} \ -else \ -{ \ - tcs |= (TCS_TBF|TCS_TBZ); \ -} - +#define UpdateTCS \ + if ( EmptySlots( trb ) > 1 ) { \ + tcs &= ~( TCS_TBF | TCS_TBZ ); \ + } else if ( EmptySlots( trb ) > 0 ) { \ + tcs &= ~TCS_TBF; \ + tcs |= TCS_TBZ; \ + } else { \ + tcs |= ( TCS_TBF | TCS_TBZ ); \ + } /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ - /* .+ .title : SerialInit @@ -517,22 +493,22 @@ else \ modified in any way. .call : - slave_pty_name = SerialInit(void); + slave_pty_name = SerialInit(void); .input : - void + void .output : - const char *slave_pty_name, name of slave pty or NULL + const char *slave_pty_name, name of slave pty or NULL .status_codes : - SERIAL_I_CALLED - SERIAL_I_PTYNAME - SERIAL_W_NOPTY - SERIAL_F_OPENPTY - SERIAL_F_FCNTL - SERIAL_F_OPEN_MASTER - SERIAL_F_GRANTPT - SERIAL_F_UNLOCKPT - SERIAL_F_OPEN_SLAVE - SERIAL_F_PUSH + SERIAL_I_CALLED + SERIAL_I_PTYNAME + SERIAL_W_NOPTY + SERIAL_F_OPENPTY + SERIAL_F_FCNTL + SERIAL_F_OPEN_MASTER + SERIAL_F_GRANTPT + SERIAL_F_UNLOCKPT + SERIAL_F_OPEN_SLAVE + SERIAL_F_PUSH .notes : 2.5, 13-Sep-2000, creation 2.6, 15-Sep-2000, update @@ -547,168 +523,152 @@ else \ - ensure that the pty is fully transparent by default - slave pty must have O_NONBLOCK set .- */ -const char *SerialInit(void) +const char* SerialInit( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialInit"); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialInit" ); /* Initialize ring buffers */ - InitRingBuffer(rrb); - InitRingBuffer(trb); + InitRingBuffer( rrb ); + InitRingBuffer( trb ); #ifndef USE_NOPTY -#ifdef USE_OPENPTY +# ifdef USE_OPENPTY /* Open pty master/slave pair; don't specify pty name, struct termios and struct winsize. */ - if(openpty(&master_pty, &slave_pty, NULL, NULL, NULL)) - { - pty_name = (char *)NULL; + if ( openpty( &master_pty, &slave_pty, NULL, NULL, NULL ) ) { + pty_name = ( char* )NULL; - ChfErrnoCondition; - ChfCondition SERIAL_F_OPENPTY, CHF_FATAL ChfEnd; - ChfSignal(); + ChfErrnoCondition; + ChfCondition SERIAL_F_OPENPTY, CHF_FATAL ChfEnd; + ChfSignal(); } - else - { - int cur_flags; + else { + int cur_flags; - pty_name = ttyname(slave_pty); + pty_name = ttyname( slave_pty ); - /* Remember: close the pty before exiting */ - atexit(SerialClose); + /* Remember: close the pty before exiting */ + atexit( SerialClose ); - /* Set O_NONBLOCK on master_pty */ - if((cur_flags = fcntl(master_pty, F_GETFL, 0)) < 0 - || fcntl(master_pty, F_SETFL, cur_flags|O_NONBLOCK) < 0) - { - ChfErrnoCondition; - ChfCondition SERIAL_F_FCNTL, CHF_FATAL ChfEnd; - ChfSignal(); - } + /* Set O_NONBLOCK on master_pty */ + if ( ( cur_flags = fcntl( master_pty, F_GETFL, 0 ) ) < 0 || fcntl( master_pty, F_SETFL, cur_flags | O_NONBLOCK ) < 0 ) { + ChfErrnoCondition; + ChfCondition SERIAL_F_FCNTL, CHF_FATAL ChfEnd; + ChfSignal(); + } } -#endif +# endif -#ifdef USE_STREAMSPTY +# ifdef USE_STREAMSPTY /* Open master cloning device */ - if((master_pty = open(PTY_MASTER, O_RDWR|O_NONBLOCK)) < 0) - { - pty_name = (char *)NULL; + if ( ( master_pty = open( PTY_MASTER, O_RDWR | O_NONBLOCK ) ) < 0 ) { + pty_name = ( char* )NULL; - ChfErrnoCondition; - ChfCondition SERIAL_F_OPEN_MASTER, CHF_FATAL, PTY_MASTER ChfEnd; - ChfSignal(); + ChfErrnoCondition; + ChfCondition SERIAL_F_OPEN_MASTER, CHF_FATAL, PTY_MASTER ChfEnd; + ChfSignal(); } - else - { - /* Master side opened ok; change permissions and unlock slave side */ + else { + /* Master side opened ok; change permissions and unlock slave side */ - if(grantpt(master_pty) < 0) - { - /* close() may modify errno; save it first */ - ChfErrnoCondition; + if ( grantpt( master_pty ) < 0 ) { + /* close() may modify errno; save it first */ + ChfErrnoCondition; - (void)close(master_pty); + ( void )close( master_pty ); - ChfCondition SERIAL_F_GRANTPT, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfCondition SERIAL_F_GRANTPT, CHF_FATAL ChfEnd; + ChfSignal(); + } - if(unlockpt(master_pty) < 0) - { - /* close() may modify errno; save it first */ - ChfErrnoCondition; + if ( unlockpt( master_pty ) < 0 ) { + /* close() may modify errno; save it first */ + ChfErrnoCondition; - (void)close(master_pty); + ( void )close( master_pty ); - ChfCondition SERIAL_F_UNLOCKPT, CHF_FATAL ChfEnd; - ChfSignal(); - } + ChfCondition SERIAL_F_UNLOCKPT, CHF_FATAL ChfEnd; + ChfSignal(); + } - /* Get name of slave side; this must be done on the *master* side */ - pty_name = ptsname(master_pty); + /* Get name of slave side; this must be done on the *master* side */ + pty_name = ptsname( master_pty ); - /* Open slave in nonblocking mode */ - if((slave_pty = open(pty_name, O_RDWR|O_NONBLOCK)) < 0) - { - /* close() may modify errno; save it first */ - ChfErrnoCondition; + /* Open slave in nonblocking mode */ + if ( ( slave_pty = open( pty_name, O_RDWR | O_NONBLOCK ) ) < 0 ) { + /* close() may modify errno; save it first */ + ChfErrnoCondition; - (void)close(master_pty); + ( void )close( master_pty ); - ChfCondition SERIAL_F_OPEN_SLAVE, CHF_FATAL, pty_name ChfEnd; - ChfSignal(); - } + ChfCondition SERIAL_F_OPEN_SLAVE, CHF_FATAL, pty_name ChfEnd; + ChfSignal(); + } - /* Remember: close the pty before exiting */ - atexit(SerialClose); + /* Remember: close the pty before exiting */ + atexit( SerialClose ); - /* Push appropriate STREAMS modules on the slave side to support - terminal emulation. This way, the slave side should be - indistinguishable from a real terminal. - */ - if(ioctl(slave_pty, I_PUSH, "ptem") == -1) - { - ChfErrnoCondition; - ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ptem" ChfEnd; - ChfSignal(); - } - - if(ioctl(slave_pty, I_PUSH, "ldterm") == -1) - { - ChfErrnoCondition; - ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ldterm" ChfEnd; - ChfSignal(); - } + /* Push appropriate STREAMS modules on the slave side to support + terminal emulation. This way, the slave side should be + indistinguishable from a real terminal. + */ + if ( ioctl( slave_pty, I_PUSH, "ptem" ) == -1 ) { + ChfErrnoCondition; + ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ptem" ChfEnd; + ChfSignal(); + } + if ( ioctl( slave_pty, I_PUSH, "ldterm" ) == -1 ) { + ChfErrnoCondition; + ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ldterm" ChfEnd; + ChfSignal(); + } } -#endif +# endif -#ifdef HP49_SUPPORT +# ifdef HP49_SUPPORT /* 3.17: Ensure that the pty is fully trasparent by default. This allows to use most non-terminal-aware applications (such as od) on the pty directly. */ { - struct termios tios; + struct termios tios; - if(tcgetattr(slave_pty, &tios)) - { - ChfErrnoCondition; - ChfCondition SERIAL_F_TCGETATTR, CHF_FATAL ChfEnd; - ChfSignal(); - } + if ( tcgetattr( slave_pty, &tios ) ) { + ChfErrnoCondition; + ChfCondition SERIAL_F_TCGETATTR, CHF_FATAL ChfEnd; + ChfSignal(); + } - tios.c_iflag &= ~(BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR - |IGNCR|ICRNL|IUCLC|IXON|IXANY|IXOFF|IMAXBEL); + tios.c_iflag &= ~( BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IUCLC | IXON | IXANY | IXOFF | IMAXBEL ); - tios.c_iflag |= IGNBRK; + tios.c_iflag |= IGNBRK; - tios.c_oflag &= ~(OPOST|OLCUC|ONLCR|OCRNL|ONOCR|ONLRET|OFILL - |OFDEL|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); + tios.c_oflag &= + ~( OPOST | OLCUC | ONLCR | OCRNL | ONOCR | ONLRET | OFILL | OFDEL | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY ); - tios.c_cflag &= ~(CSIZE|CSTOPB|PARENB|PARODD); + tios.c_cflag &= ~( CSIZE | CSTOPB | PARENB | PARODD ); - tios.c_cflag |= CS8|CREAD|HUPCL|CLOCAL; + tios.c_cflag |= CS8 | CREAD | HUPCL | CLOCAL; - tios.c_lflag &= ~(ISIG|ICANON|ECHO|ECHONL|IEXTEN); + tios.c_lflag &= ~( ISIG | ICANON | ECHO | ECHONL | IEXTEN ); - /* read()s are satisfed when at least 1 character is available; - intercharacter/read timer disabled. - */ - tios.c_cc[VMIN] = 1; - tios.c_cc[VTIME] = 0; - - if(tcsetattr(slave_pty, TCSANOW, &tios)) - { - ChfErrnoCondition; - ChfCondition SERIAL_F_TCSETATTR, CHF_FATAL ChfEnd; - ChfSignal(); - } + /* read()s are satisfed when at least 1 character is available; + intercharacter/read timer disabled. + */ + tios.c_cc[ VMIN ] = 1; + tios.c_cc[ VTIME ] = 0; + if ( tcsetattr( slave_pty, TCSANOW, &tios ) ) { + ChfErrnoCondition; + ChfCondition SERIAL_F_TCSETATTR, CHF_FATAL ChfEnd; + ChfSignal(); + } } -#endif +# endif /* Publish pty name */ ChfCondition SERIAL_I_PTY_NAME, CHF_INFO, pty_name ChfEnd; @@ -725,7 +685,6 @@ const char *SerialInit(void) return pty_name; } - /* .+ .title : SerialClose @@ -740,33 +699,31 @@ const char *SerialInit(void) successful completion. .call : - SerialClose(); + SerialClose(); .input : - void + void .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_E_PTY_CLOSE + SERIAL_I_CALLED + SERIAL_E_PTY_CLOSE .notes : 2.5, 13-Sep-2000, creation 2.6, 15-Sep-2000, update - updated documentation .- */ -void SerialClose(void) +void SerialClose( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialClose"); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialClose" ); - if(close(slave_pty) || close(master_pty)) - { - ChfErrnoCondition; - ChfCondition SERIAL_E_PTY_CLOSE, CHF_ERROR ChfEnd; - ChfSignal(); + if ( close( slave_pty ) || close( master_pty ) ) { + ChfErrnoCondition; + ChfCondition SERIAL_E_PTY_CLOSE, CHF_ERROR ChfEnd; + ChfSignal(); } } - /* .+ .title : SerialPtyName @@ -781,26 +738,25 @@ void SerialClose(void) modified in any way. .call : - slave_pty_name = SerialPtyName(); + slave_pty_name = SerialPtyName(); .input : - void + void .output : - const char *slave_pty_name, name of slave pty opened by - SerialInit() + const char *slave_pty_name, name of slave pty opened by + SerialInit() .status_codes : - SERIAL_I_CALLED + SERIAL_I_CALLED .notes : 2.5, 13-Sep-2000, creation .- */ -const char *SerialPtyName(void) +const char* SerialPtyName( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialPtyName"); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "SerialPtyName" ); return pty_name; } - /* .+ .title : Serial_IOC_Read @@ -814,27 +770,26 @@ const char *SerialPtyName(void) and does not trigger any ancillary action. .call : - n = Serial_IOC_Read(); + n = Serial_IOC_Read(); .input : - void + void .output : - Nibble n, current value of emulated register + Nibble n, current value of emulated register .status_codes : - SERIAL_I_CALLED - SERIAL_I_READ + SERIAL_I_CALLED + SERIAL_I_READ .notes : 2.5, 13-Sep-2000, creation .- */ -Nibble Serial_IOC_Read(void) +Nibble Serial_IOC_Read( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_IOC_Read"); - debug2(DEBUG_C_SERIAL, SERIAL_I_READ, "IOC", ioc); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_IOC_Read" ); + debug2( DEBUG_C_SERIAL, SERIAL_I_READ, "IOC", ioc ); return ioc; } - /* .+ .title : Serial_RCS_Read @@ -848,27 +803,26 @@ Nibble Serial_IOC_Read(void) and does not trigger any ancillary action. .call : - n = Serial_RCS_Read(); + n = Serial_RCS_Read(); .input : - void + void .output : - Nibble n, current value of emulated register + Nibble n, current value of emulated register .status_codes : - SERIAL_I_CALLED - SERIAL_I_READ + SERIAL_I_CALLED + SERIAL_I_READ .notes : 2.5, 13-Sep-2000, creation .- */ -Nibble Serial_RCS_Read(void) +Nibble Serial_RCS_Read( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RCS_Read"); - debug2(DEBUG_C_SERIAL, SERIAL_I_READ, "RCS", rcs); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RCS_Read" ); + debug2( DEBUG_C_SERIAL, SERIAL_I_READ, "RCS", rcs ); return rcs; } - /* .+ .title : Serial_TCS_Read @@ -882,27 +836,26 @@ Nibble Serial_RCS_Read(void) and does not trigger any ancillary action. .call : - n = Serial_TCS_Read(); + n = Serial_TCS_Read(); .input : - void + void .output : - Nibble n, current value of emulated register + Nibble n, current value of emulated register .status_codes : - SERIAL_I_CALLED - SERIAL_I_READ + SERIAL_I_CALLED + SERIAL_I_READ .notes : 2.5, 13-Sep-2000, creation .- */ -Nibble Serial_TCS_Read(void) +Nibble Serial_TCS_Read( void ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TCS_Read"); - debug2(DEBUG_C_SERIAL, SERIAL_I_READ, "TCS", tcs); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TCS_Read" ); + debug2( DEBUG_C_SERIAL, SERIAL_I_READ, "TCS", tcs ); return tcs; } - /* .+ .title : Serial_RBR_Read @@ -918,60 +871,56 @@ Nibble Serial_TCS_Read(void) - CheckIRQ .call : - d = Serial_RBR_Read(); + d = Serial_RBR_Read(); .input : - void + void .output : - int8 d, current value of emulated register + int8 d, current value of emulated register .status_codes : - SERIAL_I_CALLED - SERIAL_I_RBR - SERIAL_W_EMPTY_RRB + SERIAL_I_CALLED + SERIAL_I_RBR + SERIAL_W_EMPTY_RRB .notes : 2.5, 13-Sep-2000, creation 3.2, 22-Sep-2000, update - conditionally (#ifdef HP49_SUPPORT) removed warning message when reading from an empty RRB. .- */ -int8 Serial_RBR_Read(void) +int8 Serial_RBR_Read( void ) { int8 rx; - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RBR_Read"); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RBR_Read" ); /* Pull one character from rbr, if not empty */ - if(FullSlots(rrb) > 0) - { - Pull(rrb, &rx); + if ( FullSlots( rrb ) > 0 ) { + Pull( rrb, &rx ); } - else - { - /* rrb is empty */ + else { + /* rrb is empty */ #ifndef HP49_SUPPORT - /* 3.2: The HP49 firmware (1.19-4) can read from an empty RRB; - this is not harmful, and this warning can be removed. - */ - ChfCondition SERIAL_W_EMPTY_RRB, CHF_WARNING, rcs ChfEnd; - ChfSignal(); + /* 3.2: The HP49 firmware (1.19-4) can read from an empty RRB; + this is not harmful, and this warning can be removed. + */ + ChfCondition SERIAL_W_EMPTY_RRB, CHF_WARNING, rcs ChfEnd; + ChfSignal(); #endif - rx = (int8)0xFF; + rx = ( int8 )0xFF; } - /* Update receiver status */ UpdateRCS; /* Post a new IRQ if necessary */ CheckIRQ; - debug1(DEBUG_C_SERIAL, SERIAL_I_RBR, rx); + debug1( DEBUG_C_SERIAL, SERIAL_I_RBR, rx ); return rx; } - /* .+ .title : Serial_IOC_Write @@ -986,29 +935,28 @@ int8 Serial_RBR_Read(void) - CheckIRQ is executed .call : - Serial_IOC_Write(n); + Serial_IOC_Write(n); .input : - Nibble n, value to be written into the emulated register + Nibble n, value to be written into the emulated register .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_I_WRITE + SERIAL_I_CALLED + SERIAL_I_WRITE .notes : 2.5, 13-Sep-2000, creation .- */ -void Serial_IOC_Write(Nibble n) +void Serial_IOC_Write( Nibble n ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_IOC_Write"); - debug3(DEBUG_C_SERIAL, SERIAL_I_WRITE, "IOC", ioc, n); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_IOC_Write" ); + debug3( DEBUG_C_SERIAL, SERIAL_I_WRITE, "IOC", ioc, n ); ioc = n; CheckIRQ; } - /* .+ .title : Serial_RCS_Write @@ -1022,27 +970,26 @@ void Serial_IOC_Write(Nibble n) so clear when a direct write into RCS could be useful. .call : - Serial_RCS_Write(n); + Serial_RCS_Write(n); .input : - Nibble n, value to be written into the emulated register + Nibble n, value to be written into the emulated register .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_I_WRITE + SERIAL_I_CALLED + SERIAL_I_WRITE .notes : 2.5, 13-Sep-2000, creation .- */ -void Serial_RCS_Write(Nibble n) +void Serial_RCS_Write( Nibble n ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RCS_Write"); - debug3(DEBUG_C_SERIAL, SERIAL_I_WRITE, "RCS", rcs, n); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_RCS_Write" ); + debug3( DEBUG_C_SERIAL, SERIAL_I_WRITE, "RCS", rcs, n ); rcs = n; } - /* .+ .title : Serial_TCS_Write @@ -1056,27 +1003,26 @@ void Serial_RCS_Write(Nibble n) so clear when a direct write into TCS could be useful. .call : - Serial_TCS_Write(n); + Serial_TCS_Write(n); .input : - Nibble n, value to be written into the emulated register + Nibble n, value to be written into the emulated register .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_I_WRITE + SERIAL_I_CALLED + SERIAL_I_WRITE .notes : 2.5, 13-Sep-2000, creation .- */ -void Serial_TCS_Write(Nibble n) +void Serial_TCS_Write( Nibble n ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TCS_Write"); - debug3(DEBUG_C_SERIAL, SERIAL_I_WRITE, "TCS", tcs, n); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TCS_Write" ); + debug3( DEBUG_C_SERIAL, SERIAL_I_WRITE, "TCS", tcs, n ); tcs = n; } - /* .+ .title : Serial_CRER_Write @@ -1089,27 +1035,26 @@ void Serial_TCS_Write(Nibble n) The value written is ignored, and the RCS_RER bit is cleared. .call : - Serial_CRER_Write(n); + Serial_CRER_Write(n); .input : - Nibble n, value to be written into the emulated register + Nibble n, value to be written into the emulated register .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_I_WRITE + SERIAL_I_CALLED + SERIAL_I_WRITE .notes : 2.5, 13-Sep-2000, creation .- */ -void Serial_CRER_Write(Nibble n) +void Serial_CRER_Write( Nibble n ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_CRER_Write"); - debug3(DEBUG_C_SERIAL, SERIAL_I_WRITE, "CRER", 0, n); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_CRER_Write" ); + debug3( DEBUG_C_SERIAL, SERIAL_I_WRITE, "CRER", 0, n ); rcs &= ~RCS_RER; } - /* .+ .title : Serial_TBR_Write @@ -1125,35 +1070,33 @@ void Serial_CRER_Write(Nibble n) - CheckIRQ .call : - Serial_TBR_Write(d); + Serial_TBR_Write(d); .input : - int8 d, value to be written into the emulated register + int8 d, value to be written into the emulated register .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_I_TBR - SERIAL_W_FULL_TRB + SERIAL_I_CALLED + SERIAL_I_TBR + SERIAL_W_FULL_TRB .notes : 2.5, 13-Sep-2000, creation .- */ -void Serial_TBR_Write(int8 d) +void Serial_TBR_Write( int8 d ) { - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TBR_Write"); - debug1(DEBUG_C_SERIAL, SERIAL_I_TBR, d); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "Serial_TBR_Write" ); + debug1( DEBUG_C_SERIAL, SERIAL_I_TBR, d ); /* Pull one character from rbr, if not empty */ - if(EmptySlots(trb) > 0) - { - Push(trb, d); + if ( EmptySlots( trb ) > 0 ) { + Push( trb, d ); } - else - { - /* trb is full; discard character */ - ChfCondition SERIAL_W_FULL_TRB, CHF_WARNING, tcs ChfEnd; - ChfSignal(); + else { + /* trb is full; discard character */ + ChfCondition SERIAL_W_FULL_TRB, CHF_WARNING, tcs ChfEnd; + ChfSignal(); } /* Update transmitter status */ @@ -1163,7 +1106,6 @@ void Serial_TBR_Write(int8 d) CheckIRQ; } - /* .+ .title : HandleSerial @@ -1184,15 +1126,15 @@ void Serial_TBR_Write(int8 d) - CheckIRQ .call : - HandleSerial(); + HandleSerial(); .input : - void + void .output : - void + void .status_codes : - SERIAL_I_CALLED - SERIAL_E_TRB_DRAIN - SERIAL_E_RRB_CHARGE + SERIAL_I_CALLED + SERIAL_E_TRB_DRAIN + SERIAL_E_RRB_CHARGE .notes : 2.5, 14-Sep-2000, creation 2.6, 15-Sep-2000, update @@ -1202,46 +1144,42 @@ void Serial_TBR_Write(int8 d) 3.17, 22-Nov-2000, bug fix - transmit ring buffer must be emptied even when !IOC_SON .- */ -void HandleSerial(void) +void HandleSerial( void ) { int result; - debug1(DEBUG_C_TRACE, SERIAL_I_CALLED, "HandleSerial"); + debug1( DEBUG_C_TRACE, SERIAL_I_CALLED, "HandleSerial" ); #ifndef USE_NOPTY /* Attempt to drain transmitter buffer even if serial port is closed */ - result = PullAndWrite(&trb, master_pty); + result = PullAndWrite( &trb, master_pty ); /* Signal a condition upon failure */ - if(result < 0) - { - ChfErrnoCondition; - ChfCondition SERIAL_E_TRB_DRAIN, CHF_ERROR ChfEnd; - ChfSignal(); + if ( result < 0 ) { + ChfErrnoCondition; + ChfCondition SERIAL_E_TRB_DRAIN, CHF_ERROR ChfEnd; + ChfSignal(); } /* Update tcs */ UpdateTCS; - if(ioc & IOC_SON) - { - /* Attempt to charge receiver buffer */ - result = ReadAndPush(&rrb, master_pty); + if ( ioc & IOC_SON ) { + /* Attempt to charge receiver buffer */ + result = ReadAndPush( &rrb, master_pty ); - /* Signal a condition upon failure */ - if(result < 0) - { - ChfErrnoCondition; - ChfCondition SERIAL_E_RRB_CHARGE, CHF_ERROR ChfEnd; - ChfSignal(); - } + /* Signal a condition upon failure */ + if ( result < 0 ) { + ChfErrnoCondition; + ChfCondition SERIAL_E_RRB_CHARGE, CHF_ERROR ChfEnd; + ChfSignal(); + } - /* Update receiver status */ - UpdateRCS; + /* Update receiver status */ + UpdateRCS; - /* Post an IRQ if necessary */ - CheckIRQ; + /* Post an IRQ if necessary */ + CheckIRQ; } #endif - } diff --git a/src/serial.h b/src/serial.h index 2001c96..df4a609 100644 --- a/src/serial.h +++ b/src/serial.h @@ -80,65 +80,62 @@ .- */ - /*--------------------------------------------------------------------------- - Macro/Data type definitions + Macro/Data type definitions ---------------------------------------------------------------------------*/ -#define SERIAL_RCS_INFO "$Revision: 4.1 $ $State: Rel $" - +#define SERIAL_RCS_INFO "$Revision: 4.1 $ $State: Rel $" /*--------------------------------------------------------------------------- - Chf condition codes + Chf condition codes ---------------------------------------------------------------------------*/ -#define SERIAL_I_CALLED 101 /* Function %s called */ -#define SERIAL_I_REVISION 102 /* Serial port emulation rev. %s */ -#define SERIAL_I_READ 103 /* Read %s -> %x */ -#define SERIAL_I_WRITE 104 /* Write %s %x -> %x */ -#define SERIAL_I_RBR 105 /* Read RBR -> %x */ -#define SERIAL_I_TBR 106 /* Write TBR <- %x */ -#define SERIAL_I_PTY_NAME 107 /* Slave pty name is %s */ -#define SERIAL_W_EMPTY_RRB 201 /* Read from empty RX buffer, rcs=%x */ -#define SERIAL_W_FULL_TRB 202 /* Write into full TX buffer, tcs=%x */ -#define SERIAL_W_NOPTY 203 /* 3.16: Pty support not available */ -#define SERIAL_E_TRB_DRAIN 301 /* Error draining TX buffer */ -#define SERIAL_E_RRB_CHARGE 302 /* Error charging RX buffer */ -#define SERIAL_E_PTY_CLOSE 303 /* Error closing pty */ -#define SERIAL_F_OPENPTY 401 /* openpty() failed on master pty */ -#define SERIAL_F_FCNTL 402 /* fcntl() failed on master pty */ -#define SERIAL_F_OPEN_MASTER 403 /* Can't open pty master %s */ -#define SERIAL_F_GRANTPT 404 /* grantpt() failed on master pty */ -#define SERIAL_F_UNLOCKPT 405 /* unlockpt() failed on master pty */ -#define SERIAL_F_OPEN_SLAVE 406 /* Can't open pty slave %s */ -#define SERIAL_F_PUSH 407 /* ioctl(I_PUSH,%s) failed on slave */ -#define SERIAL_F_TCGETATTR 408 /* tcgetattr() failed on master */ -#define SERIAL_F_TCSETATTR 409 /* tcsetattr() failed on master */ - +#define SERIAL_I_CALLED 101 /* Function %s called */ +#define SERIAL_I_REVISION 102 /* Serial port emulation rev. %s */ +#define SERIAL_I_READ 103 /* Read %s -> %x */ +#define SERIAL_I_WRITE 104 /* Write %s %x -> %x */ +#define SERIAL_I_RBR 105 /* Read RBR -> %x */ +#define SERIAL_I_TBR 106 /* Write TBR <- %x */ +#define SERIAL_I_PTY_NAME 107 /* Slave pty name is %s */ +#define SERIAL_W_EMPTY_RRB 201 /* Read from empty RX buffer, rcs=%x */ +#define SERIAL_W_FULL_TRB 202 /* Write into full TX buffer, tcs=%x */ +#define SERIAL_W_NOPTY 203 /* 3.16: Pty support not available */ +#define SERIAL_E_TRB_DRAIN 301 /* Error draining TX buffer */ +#define SERIAL_E_RRB_CHARGE 302 /* Error charging RX buffer */ +#define SERIAL_E_PTY_CLOSE 303 /* Error closing pty */ +#define SERIAL_F_OPENPTY 401 /* openpty() failed on master pty */ +#define SERIAL_F_FCNTL 402 /* fcntl() failed on master pty */ +#define SERIAL_F_OPEN_MASTER 403 /* Can't open pty master %s */ +#define SERIAL_F_GRANTPT 404 /* grantpt() failed on master pty */ +#define SERIAL_F_UNLOCKPT 405 /* unlockpt() failed on master pty */ +#define SERIAL_F_OPEN_SLAVE 406 /* Can't open pty slave %s */ +#define SERIAL_F_PUSH 407 /* ioctl(I_PUSH,%s) failed on slave */ +#define SERIAL_F_TCGETATTR 408 /* tcgetattr() failed on master */ +#define SERIAL_F_TCSETATTR 409 /* tcsetattr() failed on master */ /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ /* Initialization */ -const char *SerialInit(void); -void SerialClose(void); +const char* SerialInit( void ); +void SerialClose( void ); /* Information about slave side of pty */ -const char *SerialPtyName(void); +const char* SerialPtyName( void ); /* Register read */ -Nibble Serial_IOC_Read(void); -Nibble Serial_RCS_Read(void); -Nibble Serial_TCS_Read(void); -int8 Serial_RBR_Read(void); +Nibble Serial_IOC_Read( void ); +Nibble Serial_RCS_Read( void ); +Nibble Serial_TCS_Read( void ); +int8 Serial_RBR_Read( void ); /* Register write */ -void Serial_IOC_Write(Nibble n); -void Serial_RCS_Write(Nibble n); -void Serial_TCS_Write(Nibble n); -void Serial_CRER_Write(Nibble n); -void Serial_TBR_Write(int8 d); +void Serial_IOC_Write( Nibble n ); +void Serial_RCS_Write( Nibble n ); +void Serial_TCS_Write( Nibble n ); +void Serial_CRER_Write( Nibble n ); +void Serial_TBR_Write( int8 d ); /* Event handling */ -void HandleSerial(void); +void HandleSerial( void ); diff --git a/src/t48.c b/src/t48.c index 08ae4dc..75edeb0 100644 --- a/src/t48.c +++ b/src/t48.c @@ -87,391 +87,395 @@ static char rcs_id[] = "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"; #include "args.h" #include "debug.h" -#define CHF_MODULE_ID X11_CHF_MODULE_ID +#define CHF_MODULE_ID X11_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- Chf parameters - Do not change. The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE) ---------------------------------------------------------------------------*/ -#define MAIN_MSGCAT_NAME "t48.cat" -#define CONDITION_STACK_SIZE 16 -#define HANDLER_STACK_SIZE 8 -#define ABNORMAL_EXIT_CODE EXIT_FAILURE - +#define MAIN_MSGCAT_NAME "t48.cat" +#define CONDITION_STACK_SIZE 16 +#define HANDLER_STACK_SIZE 8 +#define ABNORMAL_EXIT_CODE EXIT_FAILURE /*--------------------------------------------------------------------------- Other parameters ---------------------------------------------------------------------------*/ -#define APP_CLASS "T48" -#define LCD_BACKGROUND "green" -#define LCD_FOREGROUND "black" - +#define APP_CLASS "T48" +#define LCD_BACKGROUND "green" +#define LCD_FOREGROUND "black" /*--------------------------------------------------------------------------- - Private variables + Private variables ---------------------------------------------------------------------------*/ static XtAppContext app_context; static Widget shell_widget; /* Command line options descriptor */ -XrmOptionDescRec options[] = -{ - /* option, specifier, argKind, value */ - { "-reset", "*reset", XrmoptionNoArg, "True" }, - { "-monitor", "*monitor", XrmoptionNoArg, "True" }, - { "-path", "*path", XrmoptionSepArg }, - { "-cpu", "*cpu", XrmoptionSepArg }, - { "-mod", "*mod", XrmoptionSepArg }, - { "-hdw", "*hdw", XrmoptionSepArg }, - { "-rom", "*rom", XrmoptionSepArg }, - { "-ram", "*ram", XrmoptionSepArg }, - { "-port1", "*port1", XrmoptionSepArg }, - { "-port2", "*port2", XrmoptionSepArg } +XrmOptionDescRec options[] = { + /* option, specifier, argKind, value */ + { "-reset", "*reset", XrmoptionNoArg, "True" }, + { "-monitor", "*monitor", XrmoptionNoArg, "True" }, + { "-path", "*path", XrmoptionSepArg }, + { "-cpu", "*cpu", XrmoptionSepArg }, + { "-mod", "*mod", XrmoptionSepArg }, + { "-hdw", "*hdw", XrmoptionSepArg }, + { "-rom", "*rom", XrmoptionSepArg }, + { "-ram", "*ram", XrmoptionSepArg }, + { "-port1", "*port1", XrmoptionSepArg }, + { "-port2", "*port2", XrmoptionSepArg } }; -#define NUM_OPTIONS (sizeof(options)/sizeof(XrmOptionDescRec)) - +#define NUM_OPTIONS ( sizeof( options ) / sizeof( XrmOptionDescRec ) ) /* Application fallback resources */ -String fallback_resources[] = -{ - NULL /* Null terminated */ +String fallback_resources[] = { + NULL /* Null terminated */ }; - /* Application options container */ -struct app_opt -{ - Boolean reset; - Boolean monitor; - Pixel fg_pix; - Pixel bg_pix; - String path; - String cpu; - String mod; - String hdw; - String rom; - String ram; - String port1; - String port2; +struct app_opt { + Boolean reset; + Boolean monitor; + Pixel fg_pix; + Pixel bg_pix; + String path; + String cpu; + String mod; + String hdw; + String rom; + String ram; + String port1; + String port2; }; - /* Application resources/options descriptor */ -XtResource app_res[] = -{ - { "foreground", "Foreground", - XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_opt, fg_pix), - XtRString, LCD_FOREGROUND - }, - { "background", "Background", - XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_opt, bg_pix), - XtRString, LCD_BACKGROUND - }, - { "reset", "Reset", - XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, reset), - XtRString, "False" - }, - { "monitor", "Monitor", - XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, monitor), - XtRString, "False" - }, - { "path", "Path", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, path), - XtRString, "." - }, - { "cpu", "Cpu", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, cpu), - XtRString, "cpu" - }, - { "mod", "Mod", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, mod), - XtRString, "mod" - }, - { "hdw", "Hdw", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, hdw), - XtRString, "hdw" - }, - { "rom", "Rom", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, rom), - XtRString, "rom" - }, - { "ram", "Ram", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, ram), - XtRString, "ram" - }, - { "port1", "Port1", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, port1), - XtRString, "port1" - }, - { "port2", "Port2", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, port2), - XtRString, "port2" - } +XtResource app_res[] = { + {"foreground", "Foreground", XtRPixel, sizeof( Pixel ), XtOffsetOf( struct app_opt, fg_pix ), XtRString, LCD_FOREGROUND}, + {"background", "Background", XtRPixel, sizeof( Pixel ), XtOffsetOf( struct app_opt, bg_pix ), XtRString, LCD_BACKGROUND}, + {"reset", "Reset", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, reset ), XtRString, "False" }, + {"monitor", "Monitor", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, monitor ), XtRString, "False" }, + {"path", "Path", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, path ), XtRString, "." }, + {"cpu", "Cpu", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, cpu ), XtRString, "cpu" }, + {"mod", "Mod", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, mod ), XtRString, "mod" }, + {"hdw", "Hdw", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, hdw ), XtRString, "hdw" }, + {"rom", "Rom", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, rom ), XtRString, "rom" }, + {"ram", "Ram", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, ram ), XtRString, "ram" }, + {"port1", "Port1", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port1 ), XtRString, "port1" }, + {"port2", "Port2", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port2 ), XtRString, "port2" } }; -#define NUM_APP_RES (sizeof(app_res)/sizeof(XtResource)) - +#define NUM_APP_RES ( sizeof( app_res ) / sizeof( XtResource ) ) /*--------------------------------------------------------------------------- - Public variables + Public variables ---------------------------------------------------------------------------*/ /* Emulator options */ struct Args args; - /*--------------------------------------------------------------------------- - Private functions + Private functions ---------------------------------------------------------------------------*/ /* KeySym -> HP48 'enum Key' translator */ -static enum Key Ks2K(KeySym ks) +static enum Key Ks2K( KeySym ks ) { - switch(ks) - { - /* Backspace */ - case XK_BackSpace: return KEY_BKSP; + switch ( ks ) { + /* Backspace */ + case XK_BackSpace: + return KEY_BKSP; - /* Delete */ - case XK_Delete: return KEY_DEL; - case XK_KP_Delete: return KEY_DEL; + /* Delete */ + case XK_Delete: + return KEY_DEL; + case XK_KP_Delete: + return KEY_DEL; - /* Enter */ - case XK_KP_Enter: return KEY_ENTER; - case XK_Return: return KEY_ENTER; + /* Enter */ + case XK_KP_Enter: + return KEY_ENTER; + case XK_Return: + return KEY_ENTER; - /* Cursor keys */ - case XK_KP_Left: return KEY_LEFT; - case XK_Left: return KEY_LEFT; + /* Cursor keys */ + case XK_KP_Left: + return KEY_LEFT; + case XK_Left: + return KEY_LEFT; - case XK_KP_Right: return KEY_RIGHT; - case XK_Right: return KEY_RIGHT; + case XK_KP_Right: + return KEY_RIGHT; + case XK_Right: + return KEY_RIGHT; - case XK_KP_Up: return KEY_UP; - case XK_Up: return KEY_UP; + case XK_KP_Up: + return KEY_UP; + case XK_Up: + return KEY_UP; - case XK_KP_Down: return KEY_DOWN; - case XK_Down: return KEY_DOWN; + case XK_KP_Down: + return KEY_DOWN; + case XK_Down: + return KEY_DOWN; - /* Function keys */ - case XK_F1: return KEY_F1; - case XK_F2: return KEY_F2; - case XK_F3: return KEY_F3; - case XK_F4: return KEY_F4; - case XK_F5: return KEY_F5; - case XK_F6: return KEY_F6; + /* Function keys */ + case XK_F1: + return KEY_F1; + case XK_F2: + return KEY_F2; + case XK_F3: + return KEY_F3; + case XK_F4: + return KEY_F4; + case XK_F5: + return KEY_F5; + case XK_F6: + return KEY_F6; - /* Shift L, R, Alpha, ON */ - case XK_Shift_L: return KEY_SH_L; - case XK_Shift_R: return KEY_SH_R; - case XK_Alt_L: return KEY_ALPHA; - case XK_Alt_R: return KEY_ALPHA; - case XK_Escape: return KEY_ON; + /* Shift L, R, Alpha, ON */ + case XK_Shift_L: + return KEY_SH_L; + case XK_Shift_R: + return KEY_SH_R; + case XK_Alt_L: + return KEY_ALPHA; + case XK_Alt_R: + return KEY_ALPHA; + case XK_Escape: + return KEY_ON; - /* Numeric keypad and surroundings */ - case XK_KP_0: return KEY_0; - case XK_KP_1: return KEY_1; - case XK_KP_2: return KEY_2; - case XK_KP_3: return KEY_3; - case XK_KP_4: return KEY_4; - case XK_KP_5: return KEY_5; - case XK_KP_6: return KEY_6; - case XK_KP_7: return KEY_7; - case XK_KP_8: return KEY_8; - case XK_KP_9: return KEY_9; + /* Numeric keypad and surroundings */ + case XK_KP_0: + return KEY_0; + case XK_KP_1: + return KEY_1; + case XK_KP_2: + return KEY_2; + case XK_KP_3: + return KEY_3; + case XK_KP_4: + return KEY_4; + case XK_KP_5: + return KEY_5; + case XK_KP_6: + return KEY_6; + case XK_KP_7: + return KEY_7; + case XK_KP_8: + return KEY_8; + case XK_KP_9: + return KEY_9; - case XK_KP_Decimal: return KEY_DOT; + case XK_KP_Decimal: + return KEY_DOT; - case XK_KP_Add: return KEY_ADD; - case XK_plus: return KEY_ADD; + case XK_KP_Add: + return KEY_ADD; + case XK_plus: + return KEY_ADD; - case XK_KP_Subtract: return KEY_SUB; - case XK_minus: return KEY_SUB; + case XK_KP_Subtract: + return KEY_SUB; + case XK_minus: + return KEY_SUB; - case XK_KP_Multiply: return KEY_MUL; - case XK_asterisk: return KEY_MUL; + case XK_KP_Multiply: + return KEY_MUL; + case XK_asterisk: + return KEY_MUL; - case XK_KP_Divide: return KEY_DIV; - case XK_slash: return KEY_DIV; + case XK_KP_Divide: + return KEY_DIV; + case XK_slash: + return KEY_DIV; - case XK_KP_Space: return KEY_SPC; - case XK_space: return KEY_SPC; + case XK_KP_Space: + return KEY_SPC; + case XK_space: + return KEY_SPC; - /* Upper half of the keyboard */ - case XK_1: return KEY_MTH; - case XK_2: return KEY_PRG; - case XK_3: return KEY_CST; - case XK_4: return KEY_VAR; - case XK_5: return KEY_UP; - case XK_6: return KEY_NXT; + /* Upper half of the keyboard */ + case XK_1: + return KEY_MTH; + case XK_2: + return KEY_PRG; + case XK_3: + return KEY_CST; + case XK_4: + return KEY_VAR; + case XK_5: + return KEY_UP; + case XK_6: + return KEY_NXT; - case XK_q: return KEY_AP; - case XK_w: return KEY_STO; - case XK_e: return KEY_EVAL; - case XK_r: return KEY_LEFT; - case XK_t: return KEY_DOWN; - case XK_y: return KEY_RIGHT; + case XK_q: + return KEY_AP; + case XK_w: + return KEY_STO; + case XK_e: + return KEY_EVAL; + case XK_r: + return KEY_LEFT; + case XK_t: + return KEY_DOWN; + case XK_y: + return KEY_RIGHT; - case XK_a: return KEY_SIN; - case XK_s: return KEY_COS; - case XK_d: return KEY_TAN; - case XK_f: return KEY_SQRT; - case XK_g: return KEY_POWER; - case XK_h: return KEY_INV; + case XK_a: + return KEY_SIN; + case XK_s: + return KEY_COS; + case XK_d: + return KEY_TAN; + case XK_f: + return KEY_SQRT; + case XK_g: + return KEY_POWER; + case XK_h: + return KEY_INV; - case XK_z: return KEY_ENTER; - case XK_x: return KEY_ENTER; - case XK_c: return KEY_CHS; - case XK_v: return KEY_EEX; - case XK_b: return KEY_DEL; - case XK_n: return KEY_BKSP; + case XK_z: + return KEY_ENTER; + case XK_x: + return KEY_ENTER; + case XK_c: + return KEY_CHS; + case XK_v: + return KEY_EEX; + case XK_b: + return KEY_DEL; + case XK_n: + return KEY_BKSP; - /* Other useful aliases */ - case XK_Tab: return KEY_NXT; - case XK_apostrophe: return KEY_AP; - case XK_period: return KEY_DOT; + /* Other useful aliases */ + case XK_Tab: + return KEY_NXT; + case XK_apostrophe: + return KEY_AP; + case XK_period: + return KEY_DOT; - /* Save */ - case XK_Control_L: - ModSave(); - CpuSave(); - exit(0); - } + /* Save */ + case XK_Control_L: + ModSave(); + CpuSave(); + exit( 0 ); + } - return KEY_NULL; + return KEY_NULL; } - /* X Event handler, called by the X Toolkit when appropriate */ -static void XEventHandler(Widget w, XtPointer cl_data, XEvent *ev, - Boolean *cont) +static void XEventHandler( Widget w, XtPointer cl_data, XEvent* ev, Boolean* cont ) { - KeySym ks; + KeySym ks; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "XEventHandler"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "XEventHandler" ); - /* Continue to dispatch */ - *cont = True; + /* Continue to dispatch */ + *cont = True; - if(ev->type == Expose) - { - debug1(DEBUG_C_X11, X11_I_LCD_EXPOSE, ev->xexpose.count); - if(ev->xexpose.count == 0) RefreshLcd(); - } - - else if(ev->type == KeyPress || ev->type == KeyRelease) - { - (void)XLookupString((XKeyEvent *)ev, (char *)NULL, 0, &ks, - (XComposeStatus *)NULL); - - if(ev->type == KeyPress) - { - debug1(DEBUG_C_X11, X11_I_KEY_PRESS, ks); - KeybPress(Ks2K(ks)); + if ( ev->type == Expose ) { + debug1( DEBUG_C_X11, X11_I_LCD_EXPOSE, ev->xexpose.count ); + if ( ev->xexpose.count == 0 ) + RefreshLcd(); } - else if(ev->type = KeyRelease) - { - debug1(DEBUG_C_X11, X11_I_KEY_RELEASE, ks); - KeybRelease(Ks2K(ks)); - } - } + else if ( ev->type == KeyPress || ev->type == KeyRelease ) { + ( void )XLookupString( ( XKeyEvent* )ev, ( char* )NULL, 0, &ks, ( XComposeStatus* )NULL ); - else - { - /* Unknown X Event - discard */ - debug1(DEBUG_C_X11, X11_I_X_EVENT, ev->type); - } + if ( ev->type == KeyPress ) { + debug1( DEBUG_C_X11, X11_I_KEY_PRESS, ks ); + KeybPress( Ks2K( ks ) ); + } + + else if ( ev->type = KeyRelease ) { + debug1( DEBUG_C_X11, X11_I_KEY_RELEASE, ks ); + KeybRelease( Ks2K( ks ) ); + } + } + + else { + /* Unknown X Event - discard */ + debug1( DEBUG_C_X11, X11_I_X_EVENT, ev->type ); + } } - /* Path/name dynamic allocator */ -static char *GetPathname(String path, String name) +static char* GetPathname( String path, String name ) { - char *s = malloc(strlen(path)+strlen(name)+2); + char* s = malloc( strlen( path ) + strlen( name ) + 2 ); - strcpy(s, path); strcat(s, "/"); strcat(s, name); - return s; + strcpy( s, path ); + strcat( s, "/" ); + strcat( s, name ); + return s; } - /* Initialize the X interface */ -void InitializeX(int argc, char *argv[], struct app_opt *opt) +void InitializeX( int argc, char* argv[], struct app_opt* opt ) { - unsigned long fg_pix, bg_pix; - XSetWindowAttributes attr; - Arg xt_args[20]; - int n; + unsigned long fg_pix, bg_pix; + XSetWindowAttributes attr; + Arg xt_args[ 20 ]; + int n; - debug1(DEBUG_C_TRACE, X11_I_CALLED, "InitializeX"); + debug1( DEBUG_C_TRACE, X11_I_CALLED, "InitializeX" ); - /* Setup Arg vector for shell widget creation */ - n = 0; - XtSetArg(xt_args[n], XtNwidth, 131*2+2*8); n++; - XtSetArg(xt_args[n], XtNminWidth, 131*2+2*8); n++; - XtSetArg(xt_args[n], XtNmaxWidth, 131*2+2*8); n++; - XtSetArg(xt_args[n], XtNheight, 64*2+28); n++; - XtSetArg(xt_args[n], XtNminHeight, 64*2+28); n++; - XtSetArg(xt_args[n], XtNmaxHeight, 64*2+28); n++; - XtSetArg(xt_args[n], XtNx, 0); n++; - XtSetArg(xt_args[n], XtNy, 0); n++; - XtSetArg(xt_args[n], XtNinput, True); n++; + /* Setup Arg vector for shell widget creation */ + n = 0; + XtSetArg( xt_args[ n ], XtNwidth, 131 * 2 + 2 * 8 ); + n++; + XtSetArg( xt_args[ n ], XtNminWidth, 131 * 2 + 2 * 8 ); + n++; + XtSetArg( xt_args[ n ], XtNmaxWidth, 131 * 2 + 2 * 8 ); + n++; + XtSetArg( xt_args[ n ], XtNheight, 64 * 2 + 28 ); + n++; + XtSetArg( xt_args[ n ], XtNminHeight, 64 * 2 + 28 ); + n++; + XtSetArg( xt_args[ n ], XtNmaxHeight, 64 * 2 + 28 ); + n++; + XtSetArg( xt_args[ n ], XtNx, 0 ); + n++; + XtSetArg( xt_args[ n ], XtNy, 0 ); + n++; + XtSetArg( xt_args[ n ], XtNinput, True ); + n++; - /* Initialize application, parse command line options, - create its main shell. - */ - shell_widget = XtAppInitialize( - &app_context, - APP_CLASS, - options, NUM_OPTIONS, - &argc, argv, - fallback_resources, - xt_args, n - ); + /* Initialize application, parse command line options, + create its main shell. + */ + shell_widget = XtAppInitialize( &app_context, APP_CLASS, options, NUM_OPTIONS, &argc, argv, fallback_resources, xt_args, n ); - /* Check unknown options - argv[0] always contains program name */ - if(argc > 1) - { - int i; - for(i=1; i 1 ) { + int i; + for ( i = 1; i < argc; i++ ) + ChfCondition X11_E_BAD_OPTION, CHF_ERROR, argv[ i ] ChfEnd; - ChfCondition X11_I_USAGE, CHF_INFO, argv[0] ChfEnd; - ChfSignal(); - } - - /* Get application options and fill the 'struct app_opt opt' structure */ - XtGetApplicationResources( - shell_widget, - (XtPointer)opt, - app_res, - NUM_APP_RES, - (ArgList)NULL, - (Cardinal)0 - ); + ChfCondition X11_I_USAGE, CHF_INFO, argv[ 0 ] ChfEnd; + ChfSignal(); + } - /* Add private event handler for the main shell */ - XtAddEventHandler( - shell_widget, - KeyPressMask|KeyReleaseMask|ExposureMask, - False, /* Don't call with non-maskable events */ - XEventHandler, - (XtPointer)NULL - ); + /* Get application options and fill the 'struct app_opt opt' structure */ + XtGetApplicationResources( shell_widget, ( XtPointer )opt, app_res, NUM_APP_RES, ( ArgList )NULL, ( Cardinal )0 ); - /* Realize shell widget */ - XtRealizeWidget(shell_widget); + /* Add private event handler for the main shell */ + XtAddEventHandler( shell_widget, KeyPressMask | KeyReleaseMask | ExposureMask, False, /* Don't call with non-maskable events */ + XEventHandler, ( XtPointer )NULL ); + + /* Realize shell widget */ + XtRealizeWidget( shell_widget ); } - /*--------------------------------------------------------------------------- - Public functions + Public functions ---------------------------------------------------------------------------*/ /* .+ @@ -484,41 +488,40 @@ void InitializeX(int argc, char *argv[], struct app_opt *opt) It must handle the X Events relevant for the application. .call : - HandleXEvents(); + HandleXEvents(); .input : - void + void .output : - void + void .status_codes : - X11_I_CALLED - X11_I_LCD_EXPOSE - X11_I_KEY_PRESS - X11_I_KEY_RELEASE - X11_I_X_EVENT + X11_I_CALLED + X11_I_LCD_EXPOSE + X11_I_KEY_PRESS + X11_I_KEY_RELEASE + X11_I_X_EVENT .notes : 1.1, 19-Feb-1998, creation .- */ -void HandleXEvents(void) +void HandleXEvents( void ) { - debug1(DEBUG_C_TRACE, X11_I_CALLED, "HandleXEvents"); + debug1( DEBUG_C_TRACE, X11_I_CALLED, "HandleXEvents" ); - /* If there is at least one event pending, process the first event. - NOTE: This is an IF instead of a WHILE for two reasons: + /* If there is at least one event pending, process the first event. + NOTE: This is an IF instead of a WHILE for two reasons: - - to be sure that X Events related to the keyboard interface are - actually 'seen' by the HP48, since the current keyboard emulator - has no key memory. + - to be sure that X Events related to the keyboard interface are + actually 'seen' by the HP48, since the current keyboard emulator + has no key memory. - - this function will be called again very soon, so the Events queue - will not starve anyway. - */ - - if(XtAppPending(app_context)) - XtAppProcessEvent(app_context, XtIMAll); + - this function will be called again very soon, so the Events queue + will not starve anyway. + */ + + if ( XtAppPending( app_context ) ) + XtAppProcessEvent( app_context, XtIMAll ); } - /* .+ .title : main @@ -531,66 +534,60 @@ void HandleXEvents(void) 1.1, 19-Feb-1998, creation .- */ -int main(int argc, char *argv[]) +int main( int argc, char* argv[] ) { - struct app_opt opt; + struct app_opt opt; - /* Chf initialization with msgcat subsystem */ - if(ChfMsgcatInit( - argv[0], /* Application's name */ - CHF_DEFAULT, /* Options */ - MAIN_MSGCAT_NAME, /* Name of the message catalog */ - CONDITION_STACK_SIZE, /* Size of the condition stack */ - HANDLER_STACK_SIZE, /* Size of the handler stack */ - ABNORMAL_EXIT_CODE /* Abnormal exit code */ - ) != CHF_S_OK) - { - fprintf(stderr, "Chf initialization failed\n"); - exit(ABNORMAL_EXIT_CODE); - } + /* Chf initialization with msgcat subsystem */ + if ( ChfMsgcatInit( argv[ 0 ], /* Application's name */ + CHF_DEFAULT, /* Options */ + MAIN_MSGCAT_NAME, /* Name of the message catalog */ + CONDITION_STACK_SIZE, /* Size of the condition stack */ + HANDLER_STACK_SIZE, /* Size of the handler stack */ + ABNORMAL_EXIT_CODE /* Abnormal exit code */ + ) != CHF_S_OK ) { + fprintf( stderr, "Chf initialization failed\n" ); + exit( ABNORMAL_EXIT_CODE ); + } - debug1(DEBUG_C_TRACE|DEBUG_C_REVISION, X11_I_REVISION, "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"); + debug1( DEBUG_C_TRACE | DEBUG_C_REVISION, X11_I_REVISION, "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $" ); - /* Initialize X */ - InitializeX(argc, argv, &opt); + /* Initialize X */ + InitializeX( argc, argv, &opt ); - /* Initialize LCD window */ - InitLcd(XtDisplay(shell_widget), XtWindow(shell_widget), - opt.fg_pix, opt.bg_pix); + /* Initialize LCD window */ + InitLcd( XtDisplay( shell_widget ), XtWindow( shell_widget ), opt.fg_pix, opt.bg_pix ); - /* Fill the emulator options data structure */ - args.cpu_file_name = GetPathname(opt.path, opt.cpu); - args.mod_file_name = GetPathname(opt.path, opt.mod); - args.hdw_file_name = GetPathname(opt.path, opt.hdw); - args.rom_file_name = GetPathname(opt.path, opt.rom); - args.ram_file_name = GetPathname(opt.path, opt.ram); - args.port_1_file_name = GetPathname(opt.path, opt.port1); - args.port_2_file_name = GetPathname(opt.path, opt.port2); + /* Fill the emulator options data structure */ + args.cpu_file_name = GetPathname( opt.path, opt.cpu ); + args.mod_file_name = GetPathname( opt.path, opt.mod ); + args.hdw_file_name = GetPathname( opt.path, opt.hdw ); + args.rom_file_name = GetPathname( opt.path, opt.rom ); + args.ram_file_name = GetPathname( opt.path, opt.ram ); + args.port_1_file_name = GetPathname( opt.path, opt.port1 ); + args.port_2_file_name = GetPathname( opt.path, opt.port2 ); - /* Initialize peripheral modules */ - ModInit(); + /* Initialize peripheral modules */ + ModInit(); - /* Initialize peripheral modules */ - CpuInit(); + /* Initialize peripheral modules */ + CpuInit(); - /* Reset the system, if required */ - if(opt.reset) - { - ModReset(); - CpuReset(); - } + /* Reset the system, if required */ + if ( opt.reset ) { + ModReset(); + CpuReset(); + } - if(opt.monitor) - { - /* Call Monitor */ - Monitor(); - } + if ( opt.monitor ) { + /* Call Monitor */ + Monitor(); + } - else - { - /* Call Emulator directly */ - Emulator(); - } + else { + /* Call Emulator directly */ + Emulator(); + } - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/src/x11.c b/src/x11.c index 11f1fd1..5fc4a67 100644 --- a/src/x11.c +++ b/src/x11.c @@ -188,48 +188,46 @@ static char rcs_id[] = "$Id: x11.c,v 4.1.1.1 2002/11/11 16:11:47 cibrario Exp $" #include #include -#include /* Main X header */ +#include /* Main X header */ -#include /* Main Xt header */ -#include /* Literal strings of widget attributes */ +#include /* Main Xt header */ +#include /* Literal strings of widget attributes */ -#include /* Main OSF/Motif header */ -#include /* XmMainWindow widget */ -#include /* XmForm widget */ -#include /* XmLabel widget */ -#include /* XmToggleButton widget */ -#include /* XmRowColumn widget */ -#include /* XmFrame widget */ -#include /* XmDrawingArea widget */ -#include /* XmFileSelectionBox widget */ -#include /* XmMessageBox widget */ -#include /* XmTextField widget */ -#include /* XmAddWMProtocolCallback() */ +#include /* Main OSF/Motif header */ +#include /* XmMainWindow widget */ +#include /* XmForm widget */ +#include /* XmLabel widget */ +#include /* XmToggleButton widget */ +#include /* XmRowColumn widget */ +#include /* XmFrame widget */ +#include /* XmDrawingArea widget */ +#include /* XmFileSelectionBox widget */ +#include /* XmMessageBox widget */ +#include /* XmTextField widget */ +#include /* XmAddWMProtocolCallback() */ #include "config.h" #include "machdep.h" -#include "cpu.h" /* EmulatorExit(); required by keyb.h, too */ -#include "display.h" /* LcdInit() */ +#include "cpu.h" /* EmulatorExit(); required by keyb.h, too */ +#include "display.h" /* LcdInit() */ #include "keyb.h" #include "serial.h" #include "x11.h" #include "args.h" #include "debug.h" -#define CHF_MODULE_ID X11_CHF_MODULE_ID +#define CHF_MODULE_ID X11_CHF_MODULE_ID #include - /*--------------------------------------------------------------------------- Misc. parameters ---------------------------------------------------------------------------*/ -#define APP_CLASS "Saturn" -#define MAX_CS_SEGMENT_LEN 80 - +#define APP_CLASS "Saturn" +#define MAX_CS_SEGMENT_LEN 80 /*--------------------------------------------------------------------------- - Private variables and type definitions + Private variables and type definitions ---------------------------------------------------------------------------*/ static XtAppContext app_context; @@ -238,51 +236,44 @@ static Widget file_sel_box; static Widget error_dialog; static Widget msg_text_field; -#define MAX_ERROR_DIALOG_COUNT 10 +#define MAX_ERROR_DIALOG_COUNT 10 static int error_dialog_count; /* Forward static function declarations */ -static void ResetToggleButtons(Widget w); - +static void ResetToggleButtons( Widget w ); /* Continuation procedure to invoke when a FSB button is pressed */ -static FsbContinuation fsb_cont = (FsbContinuation)NULL; - +static FsbContinuation fsb_cont = ( FsbContinuation )NULL; /* Command line option descriptors; these descriptors map command line options into X resource settings */ -static XrmOptionDescRec options[] = -{ +static XrmOptionDescRec options[] = { /* option, specifier, argKind, value */ - { "-reset", "*reset", XrmoptionNoArg, "True" }, - { "-monitor", "*monitor", XrmoptionNoArg, "True" }, - { "-batchXfer", "*batchXfer", XrmoptionNoArg, "True" }, - { "-stateDir", "*stateDir", XrmoptionSepArg }, - { "-cpu", "*cpu", XrmoptionSepArg }, - { "-mod", "*mod", XrmoptionSepArg }, - { "-hdw", "*hdw", XrmoptionSepArg }, - { "-rom", "*rom", XrmoptionSepArg }, - { "-ram", "*ram", XrmoptionSepArg }, - { "-port1", "*port1", XrmoptionSepArg }, - { "-port2", "*port2", XrmoptionSepArg }, - { "-face", "*face", XrmoptionSepArg }, - { "-hw", "*hw", XrmoptionSepArg } + { "-reset", "*reset", XrmoptionNoArg, "True" }, + { "-monitor", "*monitor", XrmoptionNoArg, "True" }, + { "-batchXfer", "*batchXfer", XrmoptionNoArg, "True" }, + { "-stateDir", "*stateDir", XrmoptionSepArg }, + { "-cpu", "*cpu", XrmoptionSepArg }, + { "-mod", "*mod", XrmoptionSepArg }, + { "-hdw", "*hdw", XrmoptionSepArg }, + { "-rom", "*rom", XrmoptionSepArg }, + { "-ram", "*ram", XrmoptionSepArg }, + { "-port1", "*port1", XrmoptionSepArg }, + { "-port2", "*port2", XrmoptionSepArg }, + { "-face", "*face", XrmoptionSepArg }, + { "-hw", "*hw", XrmoptionSepArg } }; -#define NUM_OPTIONS XtNumber(options) - +#define NUM_OPTIONS XtNumber( options ) /* Application fallback resources */ -static String fallback_resources[] = -{ - NULL /* Null terminated */ +static String fallback_resources[] = { + NULL /* Null terminated */ }; - /* Application resources container (top-level resources) */ -struct app_opt -{ +struct app_opt { Boolean reset; Boolean monitor; Boolean batchXfer; @@ -298,162 +289,104 @@ struct app_opt String hw; }; - /* Application resources container (per-face resources) */ -struct face_opt -{ +struct face_opt { int nKeys; }; - /* Application resources container (per-button resources) */ -struct btn_opt -{ +struct btn_opt { String inOut; }; - /* Application resources container (compoundString resource) */ -struct cs_opt -{ +struct cs_opt { String compoundString; }; - /* Application resource descriptors (top-level resources) */ -static XtResource app_res[] = -{ - { "reset", "Reset", - XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, reset), - XtRString, "False" - }, - { "monitor", "Monitor", - XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, monitor), - XtRString, "False" - }, - { "batchXfer", "BatchXfer", - XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, batchXfer), - XtRString, "False" - }, - { "stateDir", "StateDir", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, stateDir), - XtRString, "." - }, - { "cpu", "Cpu", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, cpu), - XtRString, "cpu" - }, - { "mod", "Mod", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, mod), - XtRString, "mod" - }, - { "hdw", "Hdw", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, hdw), - XtRString, "hdw" - }, - { "rom", "Rom", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, rom), - XtRString, "rom" - }, - { "ram", "Ram", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, ram), - XtRString, "ram" - }, - { "port1", "Port1", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, port1), - XtRString, "port1" - }, - { "port2", "Port2", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, port2), - XtRString, "port2" - }, - { "face", "Face", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, face), - XtRString, "hp48" - }, - { "hw", "Hw", - XtRString, sizeof(String), XtOffsetOf(struct app_opt, hw), - XtRString, "hp48" - } +static XtResource app_res[] = { + {"reset", "Reset", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, reset ), XtRString, "False"}, + {"monitor", "Monitor", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, monitor ), XtRString, "False"}, + {"batchXfer", "BatchXfer", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, batchXfer ), XtRString, "False"}, + {"stateDir", "StateDir", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, stateDir ), XtRString, "." }, + {"cpu", "Cpu", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, cpu ), XtRString, "cpu" }, + {"mod", "Mod", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, mod ), XtRString, "mod" }, + {"hdw", "Hdw", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, hdw ), XtRString, "hdw" }, + {"rom", "Rom", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, rom ), XtRString, "rom" }, + {"ram", "Ram", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, ram ), XtRString, "ram" }, + {"port1", "Port1", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port1 ), XtRString, "port1"}, + {"port2", "Port2", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port2 ), XtRString, "port2"}, + {"face", "Face", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, face ), XtRString, "hp48" }, + {"hw", "Hw", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, hw ), XtRString, "hp48" } }; -#define NUM_APP_RES XtNumber(app_res) - +#define NUM_APP_RES XtNumber( app_res ) /* Application resource descriptors (per-face resources) */ -static XtResource face_res[] = -{ - { "nKeys", "NKeys", - XtRInt, sizeof(int), XtOffsetOf(struct face_opt, nKeys), - XtRString, "0" /* Face has no keys by default */ +static XtResource face_res[] = { + { + "nKeys", "NKeys", XtRInt, sizeof( int ), XtOffsetOf( struct face_opt, nKeys ), XtRString, "0" /* Face has no keys by default */ } }; -#define NUM_FACE_RES XtNumber(face_res) - +#define NUM_FACE_RES XtNumber( face_res ) /* Application resource descriptors (per-button resources) */ -static XtResource btn_res[] = -{ - { "inOut", "InOut", - XtRString, sizeof(String), XtOffsetOf(struct btn_opt, inOut), - XtRString, "00/0" /* Do-nothing inOut */ +static XtResource btn_res[] = { + { + "inOut", "InOut", XtRString, sizeof( String ), XtOffsetOf( struct btn_opt, inOut ), XtRString, "00/0" /* Do-nothing inOut */ } }; -#define NUM_BTN_RES XtNumber(btn_res) - +#define NUM_BTN_RES XtNumber( btn_res ) /* Application resource descriptors (compoundString resource) */ -static XtResource cs_res[] = -{ - { "compoundString", "CompoundString", - XtRString, sizeof(String), XtOffsetOf(struct cs_opt, compoundString), - XtRString, NULL /* NULL string by default */ +static XtResource cs_res[] = { + { + "compoundString", "CompoundString", XtRString, sizeof( String ), XtOffsetOf( struct cs_opt, compoundString ), XtRString, + NULL /* NULL string by default */ } }; -#define NUM_CS_RES XtNumber(cs_res) - +#define NUM_CS_RES XtNumber( cs_res ) /* Xt Actions */ -static void kbdKeyPress(Widget w, XEvent *xe, String *argv, Cardinal *argc); -static void kbdKeyRelease(Widget w, XEvent *xe, String *argv, Cardinal *argc); +static void kbdKeyPress( Widget w, XEvent* xe, String* argv, Cardinal* argc ); +static void kbdKeyRelease( Widget w, XEvent* xe, String* argv, Cardinal* argc ); -static XtActionsRec xt_actions[] = -{ - { "kbdKeyPress", kbdKeyPress }, - { "kbdKeyRelease", kbdKeyRelease } +static XtActionsRec xt_actions[] = { + {"kbdKeyPress", kbdKeyPress }, + {"kbdKeyRelease", kbdKeyRelease} }; -#define NUM_XT_ACTIONS XtNumber(xt_actions) - +#define NUM_XT_ACTIONS XtNumber( xt_actions ) /*--------------------------------------------------------------------------- - Public variables + Public variables ---------------------------------------------------------------------------*/ /* Emulator options; they are initialized here from X resources */ struct Args args; - /*--------------------------------------------------------------------------- - Private functions + Private functions ---------------------------------------------------------------------------*/ /* Path/name dynamic allocator */ -static char *GetPathname(String path, String name) +static char* GetPathname( String path, String name ) { - char *s = malloc(strlen(path)+strlen(name)+2); + char* s = malloc( strlen( path ) + strlen( name ) + 2 ); - strcpy(s, path); strcat(s, "/"); strcat(s, name); - return s; + strcpy( s, path ); + strcat( s, "/" ); + strcat( s, name ); + return s; } - /*--------------------------------------------------------------------------- - Private functions: Xt Actions and Callbacks + Private functions: Xt Actions and Callbacks ---------------------------------------------------------------------------*/ #ifdef LONG_PRESS_THR @@ -467,97 +400,68 @@ static Time arm_time = CurrentTime; /* Compute the difference between two X Server timestamps, taking wrap around of a CARD32 into account. */ -#define TimeDiff(n, o) (((n) - (o)) & 0xFFFFFFFFUL) +# define TimeDiff( n, o ) ( ( ( n ) - ( o ) ) & 0xFFFFFFFFUL ) #endif - /* This function is called when a keyboard button is armed */ -static void kbdButtonArmed( - Widget w, XtPointer client_data, XtPointer call_data) +static void kbdButtonArmed( Widget w, XtPointer client_data, XtPointer call_data ) { - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "kbdButtonArmed"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "kbdButtonArmed" ); #ifdef LONG_PRESS_THR /* Save arm_time for use at release */ - arm_time = ((XmToggleButtonCallbackStruct *)call_data) - ->event->xbutton.time; + arm_time = ( ( XmToggleButtonCallbackStruct* )call_data )->event->xbutton.time; #endif - KeybPress((char *)client_data); + KeybPress( ( char* )client_data ); } - /* This function is called when a keyboard button is disarmed */ -static void kbdButtonDisarmed( - Widget w, XtPointer client_data, XtPointer call_data) +static void kbdButtonDisarmed( Widget w, XtPointer client_data, XtPointer call_data ) { - XmToggleButtonCallbackStruct *info = - (XmToggleButtonCallbackStruct *)call_data; + XmToggleButtonCallbackStruct* info = ( XmToggleButtonCallbackStruct* )call_data; - XEvent *event = info->event; + XEvent* event = info->event; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "kbdButtonDisarmed"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "kbdButtonDisarmed" ); #ifdef LONG_PRESS_THR - if(TimeDiff(event->xbutton.time, arm_time) > LONG_PRESS_THR) - { - /* Button pressed for more than LONG_PRESS_THR; keep it pressed */ - XmToggleButtonSetState( - w, - True, - False - ); + if ( TimeDiff( event->xbutton.time, arm_time ) > LONG_PRESS_THR ) { + /* Button pressed for more than LONG_PRESS_THR; keep it pressed */ + XmToggleButtonSetState( w, True, False ); } else #endif - if(event->type == ButtonRelease - && event->xbutton.button == 3) - { - /* Keep the button pressed */ - XmToggleButtonSetState( - w, - True, - False - ); - } - else - { - /* Release the button */ - XmToggleButtonSetState( - w, - False, - False - ); + if ( event->type == ButtonRelease && event->xbutton.button == 3 ) { + /* Keep the button pressed */ + XmToggleButtonSetState( w, True, False ); + } else { + /* Release the button */ + XmToggleButtonSetState( w, False, False ); - KeybRelease((char *)client_data); + KeybRelease( ( char* )client_data ); } } - /* This function is called when the lcd widget receives an Expose event */ -static void lcdExposed( - Widget w, XtPointer client_data, XtPointer call_data) +static void lcdExposed( Widget w, XtPointer client_data, XtPointer call_data ) { - XmDrawingAreaCallbackStruct *expose_data = - (XmDrawingAreaCallbackStruct *)call_data; + XmDrawingAreaCallbackStruct* expose_data = ( XmDrawingAreaCallbackStruct* )call_data; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "lcdExposed"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "lcdExposed" ); - if(expose_data->event->type == Expose - && expose_data->event->xexpose.count == 0) - RefreshLcd(); + if ( expose_data->event->type == Expose && expose_data->event->xexpose.count == 0 ) + RefreshLcd(); } - /* This function is called when the main shell window is about to be destroyed by the wm */ -static void deleteWindow( - Widget w, XtPointer client_data, XtPointer call_data) +static void deleteWindow( Widget w, XtPointer client_data, XtPointer call_data ) { - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "deleteWindow"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "deleteWindow" ); /* 3.5: Added linux support. @@ -569,212 +473,183 @@ static void deleteWindow( so an explicit exit() has been added here; it should not harm other architectures. */ - EmulatorExit(SAVE_AND_EXIT); - exit(EXIT_SUCCESS); + EmulatorExit( SAVE_AND_EXIT ); + exit( EXIT_SUCCESS ); } - /* This function is called when the session manager wants the application to save its state. This procedure should update the WM_COMMAND property of the shell window when done. */ -static void saveYourself( - Widget w, XtPointer client_data, XtPointer call_data) +static void saveYourself( Widget w, XtPointer client_data, XtPointer call_data ) { - int argc; /* Argument vector to/from WM_COMMAND property */ - char **argv; - - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "saveYourself"); + int argc; /* Argument vector to/from WM_COMMAND property */ + char** argv; + + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "saveYourself" ); /* Attempt to save the emulator state on mass storage; default Motif callback will actually destroy the GUI and exit the application. */ - EmulatorExit(SAVE_AND_EXIT); + EmulatorExit( SAVE_AND_EXIT ); /* Update the WM_COMMAND property on w, and let the session manager continue its work. */ - if(!XGetCommand(XtDisplay(w), XtWindow(w), &argv, &argc)) - { - /* Property not found / wrong format / ... */ - ChfCondition X11_E_NO_WM_COMMAND, CHF_ERROR ChfEnd; - ChfSignal(); - } - else - { - /* Set the property to the same value it had and free the string - list returned by Xlib. - */ - XSetCommand(XtDisplay(w), XtWindow(w), argv, argc); - XFreeStringList(argv); + if ( !XGetCommand( XtDisplay( w ), XtWindow( w ), &argv, &argc ) ) { + /* Property not found / wrong format / ... */ + ChfCondition X11_E_NO_WM_COMMAND, CHF_ERROR ChfEnd; + ChfSignal(); + } else { + /* Set the property to the same value it had and free the string + list returned by Xlib. + */ + XSetCommand( XtDisplay( w ), XtWindow( w ), argv, argc ); + XFreeStringList( argv ); } } - /* This function is called when a shortcut key is pressed */ -static void kbdKeyPress(Widget w, XEvent *xe, String *argv, Cardinal *argc) +static void kbdKeyPress( Widget w, XEvent* xe, String* argv, Cardinal* argc ) { - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "kbdKeyPress"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "kbdKeyPress" ); - if(*argc == 1) - { - debug1(DEBUG_C_X11, X11_I_KEY_PRESS, argv[0]); - KeybPress(argv[0]); - } - else - { - ChfCondition X11_W_BAD_ACTION_CALL, CHF_WARNING, argc ChfEnd; - ChfSignal(); + if ( *argc == 1 ) { + debug1( DEBUG_C_X11, X11_I_KEY_PRESS, argv[ 0 ] ); + KeybPress( argv[ 0 ] ); + } else { + ChfCondition X11_W_BAD_ACTION_CALL, CHF_WARNING, argc ChfEnd; + ChfSignal(); } } - /* This function is called when a shortcut key is released */ -static void kbdKeyRelease(Widget w, XEvent *xe, String *argv, Cardinal *argc) +static void kbdKeyRelease( Widget w, XEvent* xe, String* argv, Cardinal* argc ) { - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "kbdKeyRelease"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "kbdKeyRelease" ); - if(*argc == 1) - { - debug1(DEBUG_C_X11, X11_I_KEY_RELEASE, argv[0]); - KeybRelease(argv[0]); - } - else - { - ChfCondition X11_W_BAD_ACTION_CALL, CHF_WARNING, argc ChfEnd; - ChfSignal(); + if ( *argc == 1 ) { + debug1( DEBUG_C_X11, X11_I_KEY_RELEASE, argv[ 0 ] ); + KeybRelease( argv[ 0 ] ); + } else { + ChfCondition X11_W_BAD_ACTION_CALL, CHF_WARNING, argc ChfEnd; + ChfSignal(); } } - /* This function is called when a button of the FileSelectionBox is activated. */ -static void fsbButtonPressed( - Widget w, - XtPointer client_data, XtPointer call_data) +static void fsbButtonPressed( Widget w, XtPointer client_data, XtPointer call_data ) { - XmFileSelectionBoxCallbackStruct *fsb_data = - (XmFileSelectionBoxCallbackStruct *)call_data; + XmFileSelectionBoxCallbackStruct* fsb_data = ( XmFileSelectionBoxCallbackStruct* )call_data; /* Continuation must proceed only if OK was activated. 3.16: XmCR_APPLY must not be handled here, because it corresponds to the 'Filter' key. */ - int proceed = - (fsb_data->reason == XmCR_OK); + int proceed = ( fsb_data->reason == XmCR_OK ); - char *value = (char *)NULL; + char* value = ( char* )NULL; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "fsbButtonPressed"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "fsbButtonPressed" ); - if(fsb_cont != (FsbContinuation)NULL) - { - /* If continuation must proceed, get the current user selection - from the file selection box and convert it into a char *; - the conversion should never fail. - */ - if(proceed && - !XmStringGetLtoR(fsb_data->value, XmFONTLIST_DEFAULT_TAG, &value)) - { - ChfCondition X11_E_NO_FSB_TSEG, CHF_ERROR ChfEnd; - ChfSignal(); - } + if ( fsb_cont != ( FsbContinuation )NULL ) { + /* If continuation must proceed, get the current user selection + from the file selection box and convert it into a char *; + the conversion should never fail. + */ + if ( proceed && !XmStringGetLtoR( fsb_data->value, XmFONTLIST_DEFAULT_TAG, &value ) ) { + ChfCondition X11_E_NO_FSB_TSEG, CHF_ERROR ChfEnd; + ChfSignal(); + } - else - { - /* Invoke continuation; value is meaningful only when - proceed is true. - */ - fsb_cont(proceed, value); + else { + /* Invoke continuation; value is meaningful only when + proceed is true. + */ + fsb_cont( proceed, value ); - /* Free the dynamically-allocated user selection, if any. - XtFree() handles NULL pointers correctly. - */ - XtFree(value); - } + /* Free the dynamically-allocated user selection, if any. + XtFree() handles NULL pointers correctly. + */ + XtFree( value ); + } } - else - { - /* Continuation not set; do nothing */ - ChfCondition X11_W_NO_FSB_CONT, CHF_WARNING ChfEnd; - ChfSignal(); + else { + /* Continuation not set; do nothing */ + ChfCondition X11_W_NO_FSB_CONT, CHF_WARNING ChfEnd; + ChfSignal(); } /* Remove the popup shell */ - XtUnmanageChild(w); + XtUnmanageChild( w ); } - /* This utility function builds an XmString from a string, taking newlines and tabs into account: when a newline is found, the separator 'sep' is put into the string; when a tab is found, the spacer 'spc' is put into the string. The function destroys the original string s in the process. */ -static XmString XmStringFromString(char *s, XmString sep, XmString spc) +static XmString XmStringFromString( char* s, XmString sep, XmString spc ) { - char *p; /* String scan pointer */ - char c; /* Current String character */ + char* p; /* String scan pointer */ + char c; /* Current String character */ - XmString x; /* XmString from current segment */ - XmString n; /* Result of concatenation */ + XmString x; /* XmString from current segment */ + XmString n; /* Result of concatenation */ - XmString m = XmStringCreate("", XmFONTLIST_DEFAULT_TAG); /* Buffer */ + XmString m = XmStringCreate( "", XmFONTLIST_DEFAULT_TAG ); /* Buffer */ p = s; - while((c = *p) != '\0') - { - if(c == '\n' || c == '\t') - { - /* Terminate current segment */ - *p = '\0'; + while ( ( c = *p ) != '\0' ) { + if ( c == '\n' || c == '\t' ) { + /* Terminate current segment */ + *p = '\0'; - /* Append segment to XmString, if not empty */ - if(p > s) - { - x = XmStringCreate(s, XmFONTLIST_DEFAULT_TAG); - n = XmStringConcat(m, x); + /* Append segment to XmString, if not empty */ + if ( p > s ) { + x = XmStringCreate( s, XmFONTLIST_DEFAULT_TAG ); + n = XmStringConcat( m, x ); - XmStringFree(m); - XmStringFree(x); - m = n; - } + XmStringFree( m ); + XmStringFree( x ); + m = n; + } - /* Append either sep or spc */ - n = XmStringConcat(m, (c == '\n') ? sep : spc); + /* Append either sep or spc */ + n = XmStringConcat( m, ( c == '\n' ) ? sep : spc ); - XmStringFree(m); - m = n; + XmStringFree( m ); + m = n; - /* Skip current segment and start a new one */ - p++; - s = p; - } + /* Skip current segment and start a new one */ + p++; + s = p; + } - else - /* Current segment continues */ - p++; + else + /* Current segment continues */ + p++; } - - if(p > s) - { - /* Non-empty pending segment; append */ - x = XmStringCreate(s, XmFONTLIST_DEFAULT_TAG); - n = XmStringConcat(m, x); - XmStringFree(m); - XmStringFree(x); - m = n; + if ( p > s ) { + /* Non-empty pending segment; append */ + x = XmStringCreate( s, XmFONTLIST_DEFAULT_TAG ); + n = XmStringConcat( m, x ); + + XmStringFree( m ); + XmStringFree( x ); + m = n; } return m; } - /* This is a Chf handler; it is called when any condition is signalled and prints the message through the error dialog. This handler also intercepts the SERIAL_CHF_MODULE_ID/SERIAL_I_PTY_NAME message and @@ -784,167 +659,162 @@ static XmString XmStringFromString(char *s, XmString sep, XmString spc) MAX_ERROR_DIALOG_COUNT, further messages are immediately resignaled; also, condition X11_W_TOO_MANY_MSG is signaled once. */ -static ChfAction ErrorDialogHandler( - const ChfDescriptor *d, - const ChfState s, - ChfPointer ctx) +static ChfAction ErrorDialogHandler( const ChfDescriptor* d, const ChfState s, ChfPointer ctx ) { ChfAction act; /* Check Chf state */ - switch(s) - { + switch ( s ) { - case CHF_SIGNALING: - /* ChfSignal() in progress */ - if(ChfGetSeverity(d) == CHF_FATAL) - { - /* Severity is FATAL; the application is exiting. - No point to use a message window; resignal now. - */ - act = CHF_RESIGNAL; - } + case CHF_SIGNALING: + /* ChfSignal() in progress */ + if ( ChfGetSeverity( d ) == CHF_FATAL ) { + /* Severity is FATAL; the application is exiting. + No point to use a message window; resignal now. + */ + act = CHF_RESIGNAL; + } - else if(ChfGetModuleId(d) == SERIAL_CHF_MODULE_ID - && ChfGetConditionCode(d) == SERIAL_I_PTY_NAME) - { - /* Pseudo-terminal message; this is very important. - Put it into the message display area. + else if ( ChfGetModuleId( d ) == SERIAL_CHF_MODULE_ID && ChfGetConditionCode( d ) == SERIAL_I_PTY_NAME ) { + /* Pseudo-terminal message; this is very important. + Put it into the message display area. - This is also an example of how you can intercept a - condition message and do anything with it *without* - changing a line of code elsewhere and, in particular, - in the place where the condition is generated. - */ - Arg xt_args[20]; - int n; + This is also an example of how you can intercept a + condition message and do anything with it *without* + changing a line of code elsewhere and, in particular, + in the place where the condition is generated. + */ + Arg xt_args[ 20 ]; + int n; - n = 0; - XtSetArg(xt_args[n], XmNvalue, ChfGetPartialMessage(d)); n++; - XtSetValues(msg_text_field, xt_args, n); + n = 0; + XtSetArg( xt_args[ n ], XmNvalue, ChfGetPartialMessage( d ) ); + n++; + XtSetValues( msg_text_field, xt_args, n ); - act = CHF_CONTINUE; - } + act = CHF_CONTINUE; + } - else - { - /* If maximum value of error_dialog_count has been reached, - resignal. - */ - if(error_dialog_count++ == MAX_ERROR_DIALOG_COUNT) - { - ChfCondition X11_W_TOO_MANY_MSG, CHF_WARNING, - MAX_ERROR_DIALOG_COUNT ChfEnd; - ChfSignal(); + else { + /* If maximum value of error_dialog_count has been reached, + resignal. + */ + if ( error_dialog_count++ == MAX_ERROR_DIALOG_COUNT ) { + ChfCondition X11_W_TOO_MANY_MSG, CHF_WARNING, MAX_ERROR_DIALOG_COUNT ChfEnd; + ChfSignal(); - act = CHF_RESIGNAL; - } + act = CHF_RESIGNAL; + } - else if(error_dialog_count > MAX_ERROR_DIALOG_COUNT) - act = CHF_RESIGNAL; + else if ( error_dialog_count > MAX_ERROR_DIALOG_COUNT ) + act = CHF_RESIGNAL; - else - { - unsigned char dialog_type = XmDIALOG_INFORMATION; - XmString sep = XmStringSeparatorCreate(); - XmString spc = XmStringCreate(" ", XmFONTLIST_DEFAULT_TAG); - XmString m, c, o; + else { + unsigned char dialog_type = XmDIALOG_INFORMATION; + XmString sep = XmStringSeparatorCreate(); + XmString spc = XmStringCreate( " ", XmFONTLIST_DEFAULT_TAG ); + XmString m, c, o; - Arg xt_args[20]; - int n; + Arg xt_args[ 20 ]; + int n; - /* 3.17: Reset GUI: keys and (recursively) buttons; - see comment in ActivateFSB() for more information. - */ - KeybReset(); - ResetToggleButtons(shell_widget); + /* 3.17: Reset GUI: keys and (recursively) buttons; + see comment in ActivateFSB() for more information. + */ + KeybReset(); + ResetToggleButtons( shell_widget ); - /* Determine dialog_type from top condition's severity */ - if(ChfGetSeverity(d) == CHF_ERROR) - dialog_type = XmDIALOG_ERROR; - else if(ChfGetSeverity(d) == CHF_WARNING) - dialog_type = XmDIALOG_WARNING; + /* Determine dialog_type from top condition's severity */ + if ( ChfGetSeverity( d ) == CHF_ERROR ) + dialog_type = XmDIALOG_ERROR; + else if ( ChfGetSeverity( d ) == CHF_WARNING ) + dialog_type = XmDIALOG_WARNING; - /* Put the message into the dialog; be careful with newlines */ - m = XmStringFromString(ChfBuildMessage(d), sep, spc); + /* Put the message into the dialog; be careful with newlines */ + m = XmStringFromString( ChfBuildMessage( d ), sep, spc ); - while((d = ChfGetNextDescriptor(d)) != CHF_NULL_DESCRIPTOR) - { - o = XmStringFromString(ChfBuildMessage(d), sep, spc); - c = XmStringConcat(m, o); XmStringFree(m); m = c; - XmStringFree(o); - } + while ( ( d = ChfGetNextDescriptor( d ) ) != CHF_NULL_DESCRIPTOR ) { + o = XmStringFromString( ChfBuildMessage( d ), sep, spc ); + c = XmStringConcat( m, o ); + XmStringFree( m ); + m = c; + XmStringFree( o ); + } - /* Get old value of messageString */ - n = 0; - XtSetArg(xt_args[n], XmNmessageString, &o); n++; - XtGetValues(error_dialog, xt_args, n); + /* Get old value of messageString */ + n = 0; + XtSetArg( xt_args[ n ], XmNmessageString, &o ); + n++; + XtGetValues( error_dialog, xt_args, n ); - /* Append a separator to old messageString */ - c = XmStringConcat(o, sep); XmStringFree(o); o = c; + /* Append a separator to old messageString */ + c = XmStringConcat( o, sep ); + XmStringFree( o ); + o = c; - /* Append new string to the old one */ - c = XmStringConcat(o, m); XmStringFree(o); o = c; + /* Append new string to the old one */ + c = XmStringConcat( o, m ); + XmStringFree( o ); + o = c; - /* Set the error dialog resources */ - n = 0; - XtSetArg(xt_args[n], XmNdialogType, dialog_type); n++; - XtSetArg(xt_args[n], XmNmessageString, o); n++; - XtSetValues(error_dialog, xt_args, n); + /* Set the error dialog resources */ + n = 0; + XtSetArg( xt_args[ n ], XmNdialogType, dialog_type ); + n++; + XtSetArg( xt_args[ n ], XmNmessageString, o ); + n++; + XtSetValues( error_dialog, xt_args, n ); - /* Free XmStrings */ - XmStringFree(o); - XmStringFree(m); - XmStringFree(sep); - XmStringFree(spc); + /* Free XmStrings */ + XmStringFree( o ); + XmStringFree( m ); + XmStringFree( sep ); + XmStringFree( spc ); - /* Display the error dialog */ - XtManageChild(error_dialog); + /* Display the error dialog */ + XtManageChild( error_dialog ); - act = CHF_CONTINUE; - } - } - break; + act = CHF_CONTINUE; + } + } + break; - default: - /* Other states; resignal the condition */ - act = CHF_RESIGNAL; - break; + default: + /* Other states; resignal the condition */ + act = CHF_RESIGNAL; + break; } return act; } - /* This callback is invoked when the OK button of the error dialog is pressed. */ -static void errorButtonPressed( - Widget w, - XtPointer client_data, XtPointer call_data) +static void errorButtonPressed( Widget w, XtPointer client_data, XtPointer call_data ) { - XmString e = XmStringCreate("", XmFONTLIST_DEFAULT_TAG); + XmString e = XmStringCreate( "", XmFONTLIST_DEFAULT_TAG ); - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; /* Clear messageString */ n = 0; - XtSetArg(xt_args[n], XmNmessageString, e); n++; - XtSetValues(error_dialog, xt_args, n); + XtSetArg( xt_args[ n ], XmNmessageString, e ); + n++; + XtSetValues( error_dialog, xt_args, n ); - XmStringFree(e); + XmStringFree( e ); /* Reset message counter */ error_dialog_count = 0; /* Remove the popup shell */ - XtUnmanageChild(w); + XtUnmanageChild( w ); } - /*--------------------------------------------------------------------------- - Private functions: Initialization + Private functions: Initialization ---------------------------------------------------------------------------*/ /* This function initializes the Xt application context and @@ -953,100 +823,74 @@ static void errorButtonPressed( Instead, the application's options structure (opt) is passed by reference as an argument. */ -static void InitializeXt(int argc, char *argv[], struct app_opt *opt) +static void InitializeXt( int argc, char* argv[], struct app_opt* opt ) { Atom a; - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "InitializeXt"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "InitializeXt" ); /* Enable default Xt language setup procedure */ - XtSetLanguageProc(NULL, NULL, NULL); + XtSetLanguageProc( NULL, NULL, NULL ); /* Setup Arg vector for shell widget creation */ n = 0; - XtSetArg(xt_args[n], XmNallowShellResize, True); n++; + XtSetArg( xt_args[ n ], XmNallowShellResize, True ); + n++; /* Initialize application, parse command line options, create its main shell. */ - shell_widget = XtAppInitialize( - &app_context, - APP_CLASS, - options, NUM_OPTIONS, - &argc, argv, - fallback_resources, - xt_args, n - ); + shell_widget = XtAppInitialize( &app_context, APP_CLASS, options, NUM_OPTIONS, &argc, argv, fallback_resources, xt_args, n ); /* Add WMProtocolCallback for WM_DELETE_WINDOW and WM_SAVE_YOURSELF */ - if((a = XmInternAtom(XtDisplay(shell_widget), "WM_DELETE_WINDOW", True)) - != None) - /* XmAddWMProtocolCallback() invokes XmAddProtocolCallback(); - in turn, XmAddProtocolCallback() automatically calls - XmAddProtocols() if the protocol has not yet been registered. - Therefore, XmAddWMProtocols(shell_widget, &a, 1) is not needed here. - */ - XmAddWMProtocolCallback( - shell_widget, a, deleteWindow, (XtPointer)NULL); - else - { - ChfCondition X11_W_UNKNOWN_ATOM, CHF_WARNING, "WM_DELETE_WINDOW" - ChfEnd; - ChfSignal(); + if ( ( a = XmInternAtom( XtDisplay( shell_widget ), "WM_DELETE_WINDOW", True ) ) != None ) + /* XmAddWMProtocolCallback() invokes XmAddProtocolCallback(); + in turn, XmAddProtocolCallback() automatically calls + XmAddProtocols() if the protocol has not yet been registered. + Therefore, XmAddWMProtocols(shell_widget, &a, 1) is not needed here. + */ + XmAddWMProtocolCallback( shell_widget, a, deleteWindow, ( XtPointer )NULL ); + else { + ChfCondition X11_W_UNKNOWN_ATOM, CHF_WARNING, "WM_DELETE_WINDOW" ChfEnd; + ChfSignal(); } - if((a = XmInternAtom(XtDisplay(shell_widget), "WM_SAVE_YOURSELF", True)) - != None) - XmAddWMProtocolCallback( - shell_widget, a, saveYourself, (XtPointer)NULL); - else - { - ChfCondition X11_W_UNKNOWN_ATOM, CHF_WARNING, "WM_SAVE_YOURSELF" - ChfEnd; - ChfSignal(); + if ( ( a = XmInternAtom( XtDisplay( shell_widget ), "WM_SAVE_YOURSELF", True ) ) != None ) + XmAddWMProtocolCallback( shell_widget, a, saveYourself, ( XtPointer )NULL ); + else { + ChfCondition X11_W_UNKNOWN_ATOM, CHF_WARNING, "WM_SAVE_YOURSELF" ChfEnd; + ChfSignal(); } /* Spot unknown options - argv[0] always contains program name */ - if(argc > 1) - { - int i; - for(i=1; i 1 ) { + int i; + for ( i = 1; i < argc; i++ ) + ChfCondition X11_E_BAD_OPTION, CHF_ERROR, argv[ i ] ChfEnd; - ChfCondition X11_I_USAGE, CHF_INFO, argv[0] ChfEnd; - ChfSignal(); + ChfCondition X11_I_USAGE, CHF_INFO, argv[ 0 ] ChfEnd; + ChfSignal(); } /* Get application options and fill the 'struct app_opt opt' structure (statically named options only) */ - XtGetApplicationResources( - shell_widget, - (XtPointer)opt, - app_res, - NUM_APP_RES, - (ArgList)NULL, - (Cardinal)0 - ); + XtGetApplicationResources( shell_widget, ( XtPointer )opt, app_res, NUM_APP_RES, ( ArgList )NULL, ( Cardinal )0 ); /* Announce the active face (debug only) */ - debug1(DEBUG_C_X11, X11_I_FACE, opt->face); + debug1( DEBUG_C_X11, X11_I_FACE, opt->face ); /* Install Xt actions */ - XtAppAddActions( - app_context, - xt_actions, NUM_XT_ACTIONS - ); + XtAppAddActions( app_context, xt_actions, NUM_XT_ACTIONS ); } - /* Initialize the fast-load popup window */ -static void InitializeFSB(void) +static void InitializeFSB( void ) { - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; /* Setup Arg vector for file selection dialog & box, and create them. @@ -1060,48 +904,34 @@ static void InitializeFSB(void) actions on it. */ n = 0; - XtSetArg(xt_args[n], XmNallowShellResize, True); n++; - XtSetArg(xt_args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++; - XtSetArg(xt_args[n], XmNdeleteResponse, XmDO_NOTHING); n++; + XtSetArg( xt_args[ n ], XmNallowShellResize, True ); + n++; + XtSetArg( xt_args[ n ], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL ); + n++; + XtSetArg( xt_args[ n ], XmNdeleteResponse, XmDO_NOTHING ); + n++; - file_sel_box = XmCreateFileSelectionDialog( - shell_widget, - "fsb", - xt_args, n - ); + file_sel_box = XmCreateFileSelectionDialog( shell_widget, "fsb", xt_args, n ); /* Make unused buttons insensitive */ - XtSetSensitive( - XmFileSelectionBoxGetChild(file_sel_box, XmDIALOG_HELP_BUTTON), - False); + XtSetSensitive( XmFileSelectionBoxGetChild( file_sel_box, XmDIALOG_HELP_BUTTON ), False ); /* Add callbacks for relevant buttons. 3.16: XmNapplyCallback corresponds to the 'Filter' key in this case, and must not be handled directly by the application. */ - XtAddCallback( - file_sel_box, - XmNokCallback, - fsbButtonPressed, - NULL - ); + XtAddCallback( file_sel_box, XmNokCallback, fsbButtonPressed, NULL ); - XtAddCallback( - file_sel_box, - XmNcancelCallback, - fsbButtonPressed, - NULL - ); + XtAddCallback( file_sel_box, XmNcancelCallback, fsbButtonPressed, NULL ); } - /* Initialize the dialog used to display error messages, and install a Chf handler to use it. */ -static void InitializeErrorDialog(void) +static void InitializeErrorDialog( void ) { - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; /* Setup Arg vector for error dialog and create it. @@ -1115,227 +945,188 @@ static void InitializeErrorDialog(void) actions on it. */ n = 0; - XtSetArg(xt_args[n], XmNallowShellResize, True); n++; - XtSetArg(xt_args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++; - XtSetArg(xt_args[n], XmNdeleteResponse, XmDO_NOTHING); n++; + XtSetArg( xt_args[ n ], XmNallowShellResize, True ); + n++; + XtSetArg( xt_args[ n ], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL ); + n++; + XtSetArg( xt_args[ n ], XmNdeleteResponse, XmDO_NOTHING ); + n++; - error_dialog = XmCreateErrorDialog( - shell_widget, - "error", - xt_args, n - ); + error_dialog = XmCreateErrorDialog( shell_widget, "error", xt_args, n ); /* Make unused buttons insensitive */ - XtSetSensitive( - XmMessageBoxGetChild(error_dialog, XmDIALOG_HELP_BUTTON), - False); + XtSetSensitive( XmMessageBoxGetChild( error_dialog, XmDIALOG_HELP_BUTTON ), False ); - XtSetSensitive( - XmMessageBoxGetChild(error_dialog, XmDIALOG_CANCEL_BUTTON), - False); + XtSetSensitive( XmMessageBoxGetChild( error_dialog, XmDIALOG_CANCEL_BUTTON ), False ); /* Add callback for the OK button */ - XtAddCallback( - error_dialog, - XmNokCallback, - errorButtonPressed, - NULL - ); + XtAddCallback( error_dialog, XmNokCallback, errorButtonPressed, NULL ); /* Install a Chf handler for it */ - ChfPushHandler(ErrorDialogHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER); + ChfPushHandler( ErrorDialogHandler, CHF_NULL_CONTEXT, CHF_NULL_POINTER ); /* Reset message count */ error_dialog_count = 0; } - /* This function checks if widget w has a compoundString application's resource set. If yes, the resource is parsed and the labelString widget resource is set accordingly. compoundString syntax: : ([# ] ])* : - # -- Put a single '#' in current segment - -- Create a new segment using XmFONTLIST_DEFAULT_TAG as a tag - -- Create a new segment using as a tag + # -- Put a single '#' in current segment + -- Create a new segment using XmFONTLIST_DEFAULT_TAG as a tag + -- Create a new segment using as a tag Each segment is limited to MAX_CS_SEGMENT_LEN characters; longer segments are silently truncated. Too lazy to build a full-fledged resource translator... */ -static void CheckCompoundString(Widget w) +static void CheckCompoundString( Widget w ) { struct cs_opt opt; - Arg xt_args[10]; + Arg xt_args[ 10 ]; int n; - XtGetApplicationResources( - w, - (XtPointer)&opt, - cs_res, - NUM_CS_RES, - (ArgList)NULL, - (Cardinal)0 - ); + XtGetApplicationResources( w, ( XtPointer )&opt, cs_res, NUM_CS_RES, ( ArgList )NULL, ( Cardinal )0 ); - if(opt.compoundString != NULL) - { - char user_tag[2]; /* User tag buffer, 1 char */ - char seg_buf[MAX_CS_SEGMENT_LEN+1]; /* Segment buffer */ - char *cur_tag = XmFONTLIST_DEFAULT_TAG; /* Tag of current segment */ - char *cur_sptr = opt.compoundString; /* Parser's source ptr */ - char *cur_dptr = seg_buf; /* Dest ptr in seg_buf */ - char cur_c; /* Current source char */ - char next_c; /* Next source char */ - XmString xm_string; /* Parsed xm_string */ - XmString cur_xm; /* Parsed segment */ - XmString new_xm; + if ( opt.compoundString != NULL ) { + char user_tag[ 2 ]; /* User tag buffer, 1 char */ + char seg_buf[ MAX_CS_SEGMENT_LEN + 1 ]; /* Segment buffer */ + char* cur_tag = XmFONTLIST_DEFAULT_TAG; /* Tag of current segment */ + char* cur_sptr = opt.compoundString; /* Parser's source ptr */ + char* cur_dptr = seg_buf; /* Dest ptr in seg_buf */ + char cur_c; /* Current source char */ + char next_c; /* Next source char */ + XmString xm_string; /* Parsed xm_string */ + XmString cur_xm; /* Parsed segment */ + XmString new_xm; - debug2(DEBUG_C_X11, X11_I_FOUND_CS, - XtName(XtParent(w)), opt.compoundString); + debug2( DEBUG_C_X11, X11_I_FOUND_CS, XtName( XtParent( w ) ), opt.compoundString ); - user_tag[1] = '\0'; - xm_string = XmStringCreate("", XmFONTLIST_DEFAULT_TAG); + user_tag[ 1 ] = '\0'; + xm_string = XmStringCreate( "", XmFONTLIST_DEFAULT_TAG ); - /* Parse the compoundString */ - while((cur_c = *cur_sptr++) != '\0') - { - if(cur_c == '#') - { - /* Tag marker */ - if((next_c = *cur_sptr) == '\0') - { - /* Syntax error; ignore trailing # */ - } - else - { - if(next_c == '#') - { - /* Escaped #; store in current segment and skip */ - if(cur_dptr - seg_buf < MAX_CS_SEGMENT_LEN) - *cur_dptr++ = next_c; - } - else - { - /* Close current segment and append to xm_string */ - if(cur_dptr - seg_buf > 0) - { - *cur_dptr = '\0'; - cur_xm = XmStringCreate(seg_buf, cur_tag); - new_xm = XmStringConcat(xm_string, cur_xm); - XmStringFree(xm_string); - XmStringFree(cur_xm); - xm_string = new_xm; - cur_dptr = seg_buf; - } + /* Parse the compoundString */ + while ( ( cur_c = *cur_sptr++ ) != '\0' ) { + if ( cur_c == '#' ) { + /* Tag marker */ + if ( ( next_c = *cur_sptr ) == '\0' ) { + /* Syntax error; ignore trailing # */ + } else { + if ( next_c == '#' ) { + /* Escaped #; store in current segment and skip */ + if ( cur_dptr - seg_buf < MAX_CS_SEGMENT_LEN ) + *cur_dptr++ = next_c; + } else { + /* Close current segment and append to xm_string */ + if ( cur_dptr - seg_buf > 0 ) { + *cur_dptr = '\0'; + cur_xm = XmStringCreate( seg_buf, cur_tag ); + new_xm = XmStringConcat( xm_string, cur_xm ); + XmStringFree( xm_string ); + XmStringFree( cur_xm ); + xm_string = new_xm; + cur_dptr = seg_buf; + } - /* Set new current tag */ - if(next_c == ' ') - cur_tag = XmFONTLIST_DEFAULT_TAG; - else - { - user_tag[0] = next_c; - cur_tag = user_tag; - } - } + /* Set new current tag */ + if ( next_c == ' ' ) + cur_tag = XmFONTLIST_DEFAULT_TAG; + else { + user_tag[ 0 ] = next_c; + cur_tag = user_tag; + } + } - cur_sptr++; - } - } - else - { - /* Store char in current segment */ - if(cur_dptr - seg_buf < MAX_CS_SEGMENT_LEN) - *cur_dptr++ = cur_c; - } - } + cur_sptr++; + } + } else { + /* Store char in current segment */ + if ( cur_dptr - seg_buf < MAX_CS_SEGMENT_LEN ) + *cur_dptr++ = cur_c; + } + } - /* Close ending segment and append to xm_string */ - if(cur_dptr - seg_buf > 0) - { - *cur_dptr = '\0'; - cur_xm = XmStringCreate(seg_buf, cur_tag); - new_xm = XmStringConcat(xm_string, cur_xm); - XmStringFree(xm_string); - XmStringFree(cur_xm); - xm_string = new_xm; - } + /* Close ending segment and append to xm_string */ + if ( cur_dptr - seg_buf > 0 ) { + *cur_dptr = '\0'; + cur_xm = XmStringCreate( seg_buf, cur_tag ); + new_xm = XmStringConcat( xm_string, cur_xm ); + XmStringFree( xm_string ); + XmStringFree( cur_xm ); + xm_string = new_xm; + } - /* Pant... now push xm_string into the widget */ - n = 0; - XtSetArg(xt_args[n], XmNlabelString, xm_string); n++; - XtSetValues(w, xt_args, n); - XmStringFree(xm_string); + /* Pant... now push xm_string into the widget */ + n = 0; + XtSetArg( xt_args[ n ], XmNlabelString, xm_string ); + n++; + XtSetValues( w, xt_args, n ); + XmStringFree( xm_string ); } } - /* This function creates the widget set corresponding to a key, and returns the widget id of the top widget */ -static Widget CreateKey(int k, Widget parent) +static Widget CreateKey( int k, Widget parent ) { - char container_name[8]; + char container_name[ 8 ]; Widget w, l, b; XtTranslations t; struct btn_opt opt; - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "CreateKey"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "CreateKey" ); /* Generate container_name */ - sprintf(container_name, "%d", k); + sprintf( container_name, "%d", k ); /* Container widget (xmForm) */ /* Force nonmodal navigation only; don't allow overlapping children */ n = 0; #ifdef FORCE_NONMODAL - XtSetArg(xt_args[n], XmNnavigationType, XmNONE); n++; - XtSetArg(xt_args[n], XmNtraversalOn, False); n++; + XtSetArg( xt_args[ n ], XmNnavigationType, XmNONE ); + n++; + XtSetArg( xt_args[ n ], XmNtraversalOn, False ); + n++; #endif - XtSetArg(xt_args[n], XmNallowOverlap, False); n++; + XtSetArg( xt_args[ n ], XmNallowOverlap, False ); + n++; - w = XtCreateManagedWidget( - container_name, - xmFormWidgetClass, - parent, - xt_args, n - ); + w = XtCreateManagedWidget( container_name, xmFormWidgetClass, parent, xt_args, n ); /* Upper labels */ /* Must be widgets to set own foreground color */ n = 0; - XtSetArg(xt_args[n], XmNleftAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg( xt_args[ n ], XmNleftAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNtopAttachment, XmATTACH_FORM ); + n++; - l = XtCreateManagedWidget( - "ul", - xmLabelWidgetClass, - w, - xt_args, n - ); + l = XtCreateManagedWidget( "ul", xmLabelWidgetClass, w, xt_args, n ); - CheckCompoundString(l); + CheckCompoundString( l ); n = 0; - XtSetArg(xt_args[n], XmNalignment, XmALIGNMENT_END); n++; - XtSetArg(xt_args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; - XtSetArg(xt_args[n], XmNleftWidget, l); n++; - XtSetArg(xt_args[n], XmNrightAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg( xt_args[ n ], XmNalignment, XmALIGNMENT_END ); + n++; + XtSetArg( xt_args[ n ], XmNleftAttachment, XmATTACH_WIDGET ); + n++; + XtSetArg( xt_args[ n ], XmNleftWidget, l ); + n++; + XtSetArg( xt_args[ n ], XmNrightAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNtopAttachment, XmATTACH_FORM ); + n++; - CheckCompoundString( - XtCreateManagedWidget( - "ur", - xmLabelWidgetClass, - w, - xt_args, n - )); + CheckCompoundString( XtCreateManagedWidget( "ur", xmLabelWidgetClass, w, xt_args, n ) ); /* ToggleButton */ /* - Disable ToggleButton indicator; shadowThickness must be >0 to @@ -1347,230 +1138,175 @@ static Widget CreateKey(int k, Widget parent) Instead, XtAugmentTranslations() is used after widget creation. */ n = 0; - XtSetArg(xt_args[n], XmNindicatorOn, False); n++; - XtSetArg(xt_args[n], XmNleftAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNrightAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; - XtSetArg(xt_args[n], XmNtopWidget, l); n++; + XtSetArg( xt_args[ n ], XmNindicatorOn, False ); + n++; + XtSetArg( xt_args[ n ], XmNleftAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNrightAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNtopAttachment, XmATTACH_WIDGET ); + n++; + XtSetArg( xt_args[ n ], XmNtopWidget, l ); + n++; - b = XtCreateManagedWidget( - "btn", - xmToggleButtonWidgetClass, - w, - xt_args, n - ); + b = XtCreateManagedWidget( "btn", xmToggleButtonWidgetClass, w, xt_args, n ); /* Augment the translation table to allow clicks with button 3; this key is used to hold a key pressed. */ - XtAugmentTranslations( - b, - (t = XtParseTranslationTable( - "#augment : Arm()\n" - ": Select() Disarm()\n"))); + XtAugmentTranslations( b, ( t = XtParseTranslationTable( "#augment : Arm()\n" + ": Select() Disarm()\n" ) ) ); - XtFree((void *)t); /* Free the translation table */ - CheckCompoundString(b); + XtFree( ( void* )t ); /* Free the translation table */ + CheckCompoundString( b ); /* Lower labels */ /* Must be widgets to set own foreground color */ n = 0; - XtSetArg(xt_args[n], XmNleftAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; - XtSetArg(xt_args[n], XmNtopWidget, b); n++; + XtSetArg( xt_args[ n ], XmNleftAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNtopAttachment, XmATTACH_WIDGET ); + n++; + XtSetArg( xt_args[ n ], XmNtopWidget, b ); + n++; - l = XtCreateManagedWidget( - "ll", - xmLabelWidgetClass, - w, - xt_args, n - ); + l = XtCreateManagedWidget( "ll", xmLabelWidgetClass, w, xt_args, n ); - CheckCompoundString(l); + CheckCompoundString( l ); n = 0; - XtSetArg(xt_args[n], XmNalignment, XmALIGNMENT_END); n++; - XtSetArg(xt_args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; - XtSetArg(xt_args[n], XmNleftWidget, l); n++; - XtSetArg(xt_args[n], XmNrightAttachment, XmATTACH_FORM); n++; - XtSetArg(xt_args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; - XtSetArg(xt_args[n], XmNtopWidget, b); n++; + XtSetArg( xt_args[ n ], XmNalignment, XmALIGNMENT_END ); + n++; + XtSetArg( xt_args[ n ], XmNleftAttachment, XmATTACH_WIDGET ); + n++; + XtSetArg( xt_args[ n ], XmNleftWidget, l ); + n++; + XtSetArg( xt_args[ n ], XmNrightAttachment, XmATTACH_FORM ); + n++; + XtSetArg( xt_args[ n ], XmNtopAttachment, XmATTACH_WIDGET ); + n++; + XtSetArg( xt_args[ n ], XmNtopWidget, b ); + n++; - CheckCompoundString( - XtCreateManagedWidget( - "lr", - xmLabelWidgetClass, - w, - xt_args, n - )); + CheckCompoundString( XtCreateManagedWidget( "lr", xmLabelWidgetClass, w, xt_args, n ) ); /* Get application resources of ToggleButton and fill the 'struct btn_opt opt' structure appropriately */ - XtGetApplicationResources( - b, - (XtPointer)&opt, - btn_res, - NUM_BTN_RES, - (ArgList)NULL, - (Cardinal)0 - ); + XtGetApplicationResources( b, ( XtPointer )&opt, btn_res, NUM_BTN_RES, ( ArgList )NULL, ( Cardinal )0 ); - debug2(DEBUG_C_X11, X11_I_KEY, k, opt.inOut); + debug2( DEBUG_C_X11, X11_I_KEY, k, opt.inOut ); /* Add Arm/Disarm callbacks on ToggleButton */ - XtAddCallback( - b, - XmNarmCallback, - kbdButtonArmed, - opt.inOut - ); + XtAddCallback( b, XmNarmCallback, kbdButtonArmed, opt.inOut ); - XtAddCallback( - b, - XmNdisarmCallback, - kbdButtonDisarmed, - opt.inOut - ); + XtAddCallback( b, XmNdisarmCallback, kbdButtonDisarmed, opt.inOut ); return w; } - /* This function creates, initializes and realizes the widget tree. Initialization includes callback installation. */ -static void InitializeWidgets(String face, - Display **lcd_display, Window *lcd_window, - unsigned long *lcd_fg, unsigned long *lcd_bg) +static void InitializeWidgets( String face, Display** lcd_display, Window* lcd_window, unsigned long* lcd_fg, unsigned long* lcd_bg ) { Widget mw, rc, kbd, f, lcd; int k; struct face_opt opt; Pixel lcd_fg_pixel, lcd_bg_pixel; - Arg xt_args[20]; + Arg xt_args[ 20 ]; int n; - debug1(DEBUG_C_TRACE|DEBUG_C_X11, X11_I_CALLED, "InitializeWidgets"); + debug1( DEBUG_C_TRACE | DEBUG_C_X11, X11_I_CALLED, "InitializeWidgets" ); /* Main window */ /* Force nonmodal navigation only */ n = 0; #ifdef FORCE_NONMODAL - XtSetArg(xt_args[n], XmNnavigationType, XmNONE); n++; - XtSetArg(xt_args[n], XmNtraversalOn, False); n++; + XtSetArg( xt_args[ n ], XmNnavigationType, XmNONE ); + n++; + XtSetArg( xt_args[ n ], XmNtraversalOn, False ); + n++; #endif - mw = XtCreateManagedWidget( - "main", - xmMainWindowWidgetClass, - shell_widget, - xt_args, n - ); + mw = XtCreateManagedWidget( "main", xmMainWindowWidgetClass, shell_widget, xt_args, n ); /* RowColumn container for display, keyboard and message area */ /* Force nonmodal navigation only */ n = 0; #ifdef FORCE_NONMODAL - XtSetArg(xt_args[n], XmNnavigationType, XmNONE); n++; - XtSetArg(xt_args[n], XmNtraversalOn, False); n++; + XtSetArg( xt_args[ n ], XmNnavigationType, XmNONE ); + n++; + XtSetArg( xt_args[ n ], XmNtraversalOn, False ); + n++; #endif - rc = XtCreateManagedWidget( - face, - xmRowColumnWidgetClass, - mw, - xt_args, n - ); + rc = XtCreateManagedWidget( face, xmRowColumnWidgetClass, mw, xt_args, n ); /* Get .nKeys resource (opt->nKeys) */ - XtGetApplicationResources( - rc, - (XtPointer)&opt, - face_res, - NUM_FACE_RES, - (ArgList)NULL, - (Cardinal)0 - ); + XtGetApplicationResources( rc, ( XtPointer )&opt, face_res, NUM_FACE_RES, ( ArgList )NULL, ( Cardinal )0 ); /* Announce resource value (debug only) */ - debug1(DEBUG_C_X11, X11_I_NKEYS, opt.nKeys); + debug1( DEBUG_C_X11, X11_I_NKEYS, opt.nKeys ); /* 3.15: Cannot continue if the active faceplate has no keys; the application resource file is probably wrong. */ - if(opt.nKeys <= 0) - { - ChfCondition X11_F_NO_KEYS, CHF_FATAL, face ChfEnd; - ChfSignal(); + if ( opt.nKeys <= 0 ) { + ChfCondition X11_F_NO_KEYS, CHF_FATAL, face ChfEnd; + ChfSignal(); } /* LCD Screen */ n = 0; #ifdef FORCE_NONMODAL - XtSetArg(xt_args[n], XmNnavigationType, XmNONE); n++; - XtSetArg(xt_args[n], XmNtraversalOn, False); n++; + XtSetArg( xt_args[ n ], XmNnavigationType, XmNONE ); + n++; + XtSetArg( xt_args[ n ], XmNtraversalOn, False ); + n++; #endif - f = XtCreateManagedWidget( - "frame", - xmFrameWidgetClass, - rc, - xt_args, n - ); + f = XtCreateManagedWidget( "frame", xmFrameWidgetClass, rc, xt_args, n ); n = 0; - lcd = XtCreateManagedWidget( - "lcd", - xmDrawingAreaWidgetClass, - f, - xt_args, n - ); + lcd = XtCreateManagedWidget( "lcd", xmDrawingAreaWidgetClass, f, xt_args, n ); /* Add expose callback on lcd widget */ - XtAddCallback( - lcd, - XmNexposeCallback, - lcdExposed, - (XtPointer)NULL - ); + XtAddCallback( lcd, XmNexposeCallback, lcdExposed, ( XtPointer )NULL ); /* Keyboard form */ /* Force nonmodal navigation only */ n = 0; #ifdef FORCE_NONMODAL - XtSetArg(xt_args[n], XmNnavigationType, XmNONE); n++; - XtSetArg(xt_args[n], XmNtraversalOn, False); n++; + XtSetArg( xt_args[ n ], XmNnavigationType, XmNONE ); + n++; + XtSetArg( xt_args[ n ], XmNtraversalOn, False ); + n++; #endif - XtSetArg(xt_args[n], XmNallowOverlap, False); n++; + XtSetArg( xt_args[ n ], XmNallowOverlap, False ); + n++; - kbd = XtCreateManagedWidget( - "kbd", - xmFormWidgetClass, /* widget_class */ - rc, - xt_args, n - ); + kbd = XtCreateManagedWidget( "kbd", xmFormWidgetClass, /* widget_class */ + rc, xt_args, n ); /* Create keys */ - for(k=0; k #include -#include /* Main X header */ -#include /* Main Xt header */ +#include /* Main X header */ +#include /* Main Xt header */ #include "config.h" #include "machdep.h" #include "cpu.h" #include "modules.h" #include "disk_io.h" -#include "x11.h" /* ActivateFSB() */ +#include "x11.h" /* ActivateFSB() */ #include "x_func.h" #include "args.h" #include "debug.h" -#define CHF_MODULE_ID X_FUNC_CHF_MODULE_ID +#define CHF_MODULE_ID X_FUNC_CHF_MODULE_ID #include - - /*--------------------------------------------------------------------------- - Private functions: CPU access + Private functions: CPU access ---------------------------------------------------------------------------*/ /* Return the A field of a DataRegister as an integer. */ -static int R2int(const Nibble *r) +static int R2int( const Nibble* r ) { - return( - ((int)r[0] ) | - ((int)r[1] << 4) | - ((int)r[2] << 8) | - ((int)r[3] << 12) | - ((int)r[4] << 16) - ); + return ( ( ( int )r[ 0 ] ) | ( ( int )r[ 1 ] << 4 ) | ( ( int )r[ 2 ] << 8 ) | ( ( int )r[ 3 ] << 12 ) | ( ( int )r[ 4 ] << 16 ) ); } - /* Return the contents of the byte pointed by addr. Memory is accessed through ReadNibble() */ -static int ByteFromAddress(Address addr) -{ - return (int)ReadNibble(addr) + (int)ReadNibble(addr+1) * 16; -} - +static int ByteFromAddress( Address addr ) { return ( int )ReadNibble( addr ) + ( int )ReadNibble( addr + 1 ) * 16; } /* Return a dynamically-allocated copy of the contents of the IDNT object pointed by D1. D1 points to the *body* of the RPL object, that is, to the IDNT length byte directly and *not* to the prologue. */ -static char *NameFromD1(void) +static char* NameFromD1( void ) { - Address addr = cpu_status.D1; /* Points to the IDNT body */ - int len = ByteFromAddress(addr); /* IDNT length */ - char *name = XtMalloc(len+1); /* IDNT name buffer */ + Address addr = cpu_status.D1; /* Points to the IDNT body */ + int len = ByteFromAddress( addr ); /* IDNT length */ + char* name = XtMalloc( len + 1 ); /* IDNT name buffer */ int c; /* Read the name; toascii() is there to avoid 'strange' characters */ - for(c=0; c=0, has an architectural upper limit of 2^20, - and int are at least 2^31. - */ - cpu_status.inner_loop_max = (new_speed * INNER_LOOP_MAX) / 4; + /* Compute inner loop limit; 4 is the real CPU speed in MHz when + the limit is set to INNER_LOOP_MAX. No overflow checks, + because new_speed is >=0, has an architectural upper limit of 2^20, + and int are at least 2^31. + */ + cpu_status.inner_loop_max = ( new_speed * INNER_LOOP_MAX ) / 4; - /* Notify the user about the speed change */ - if(cpu_status.inner_loop_max) - ChfCondition X_FUNC_I_SET_SPEED, CHF_INFO, new_speed ChfEnd; + /* Notify the user about the speed change */ + if ( cpu_status.inner_loop_max ) + ChfCondition X_FUNC_I_SET_SPEED, CHF_INFO, new_speed ChfEnd; - else - ChfCondition X_FUNC_I_MAX_SPEED, CHF_INFO ChfEnd; + else + ChfCondition X_FUNC_I_MAX_SPEED, CHF_INFO ChfEnd; - ChfSignal(); + ChfSignal(); } #endif } - /*---------------------------------------------------------------------------*/ - /* This array holds the binary headers for all known hw configurations; here, '?' is a wildcard character when reading from file (see ReadObjectFromFile()) and is replaced by 'S' when writing to file (see WriteObjectToFile()). */ -struct BinHdrMapping -{ - char *hw; - char *hdr; +struct BinHdrMapping { + char* hw; + char* hdr; }; -static const struct BinHdrMapping bin_hdr_mapping[] = -{ - { "hp48", "HPHP48-?" }, - { "hp49", "HPHP49-?" } +static const struct BinHdrMapping bin_hdr_mapping[] = { + {"hp48", "HPHP48-?"}, + {"hp49", "HPHP49-?"} }; -#define N_BIN_HDR_MAPPING (sizeof(bin_hdr_mapping)/sizeof(bin_hdr_mapping[0])) +#define N_BIN_HDR_MAPPING ( sizeof( bin_hdr_mapping ) / sizeof( bin_hdr_mapping[ 0 ] ) ) - /* Return the header of binary files for current hw configuration; return NULL if the header cannot be determined. In the latter case, generate an appropriate condition. */ -static const char *BinaryHeader(void) +static const char* BinaryHeader( void ) { int i; - for(i=0; i= N_X_FUNC - || function[(int)function_code] == (XFunc)NULL) - { - ChfCondition X_FUNC_W_BAD_CODE, CHF_WARNING, function_code ChfEnd; - ChfSignal(); + if ( function_code < 0 || function_code >= N_X_FUNC || function[ ( int )function_code ] == ( XFunc )NULL ) { + ChfCondition X_FUNC_W_BAD_CODE, CHF_WARNING, function_code ChfEnd; + ChfSignal(); } /* Dispatch */ else - function[(int)function_code](function_code); + function[ ( int )function_code ]( function_code ); } diff --git a/src/x_func.h b/src/x_func.h index a8e8480..4eb7a39 100644 --- a/src/x_func.h +++ b/src/x_func.h @@ -69,41 +69,38 @@ .- */ - /*--------------------------------------------------------------------------- - Macro/Data type definitions - require cpu.h + Macro/Data type definitions - require cpu.h ---------------------------------------------------------------------------*/ /* Extended function codes (argument of XFunction()) */ -#define X_FUNC_SET_SPEED (Nibble)0 -#define X_FUNC_KGET (Nibble)1 -#define X_FUNC_SEND (Nibble)2 - +#define X_FUNC_SET_SPEED ( Nibble )0 +#define X_FUNC_KGET ( Nibble )1 +#define X_FUNC_SEND ( Nibble )2 /*--------------------------------------------------------------------------- - Chf condition codes + Chf condition codes ---------------------------------------------------------------------------*/ -#define X_FUNC_I_CALLED 101 /* Function %s called */ -#define X_FUNC_I_CODE 102 /* Function code %d */ -#define X_FUNC_I_SET_SPEED 103 /* Speed set to %dMhz (%d mult.) */ -#define X_FUNC_I_MAX_SPEED 104 /* Emulator at max speed */ -#define X_FUNC_I_FILE_NAME 105 /* Transferring file name %s */ -#define X_FUNC_I_KGET 106 /* Kget start:%x end:%x hdr:%s */ -#define X_FUNC_I_SEND 107 /* Send start:%x end:%x hdr:%s */ -#define X_FUNC_W_BAD_CODE 201 /* Bad function code %d ignored */ -#define X_FUNC_W_ABORTED 202 /* Aborted by user */ -#define X_FUNC_W_FAILED 203 /* Operation failed */ -#define X_FUNC_E_NO_HALT 301 /* Cpu halt not allowed */ -#define X_FUNC_E_NO_SPEED 302 /* No speed control available */ -#define X_FUNC_E_NO_BIN_HDR 303 /* Can't determine hdr for hw %s */ -#define X_FUNC_F_xxx 401 -#define X_FUNC_M_KGET 501 /* FSB title for Kget function */ -#define X_FUNC_M_SEND 502 /* FSB title for Send function */ - +#define X_FUNC_I_CALLED 101 /* Function %s called */ +#define X_FUNC_I_CODE 102 /* Function code %d */ +#define X_FUNC_I_SET_SPEED 103 /* Speed set to %dMhz (%d mult.) */ +#define X_FUNC_I_MAX_SPEED 104 /* Emulator at max speed */ +#define X_FUNC_I_FILE_NAME 105 /* Transferring file name %s */ +#define X_FUNC_I_KGET 106 /* Kget start:%x end:%x hdr:%s */ +#define X_FUNC_I_SEND 107 /* Send start:%x end:%x hdr:%s */ +#define X_FUNC_W_BAD_CODE 201 /* Bad function code %d ignored */ +#define X_FUNC_W_ABORTED 202 /* Aborted by user */ +#define X_FUNC_W_FAILED 203 /* Operation failed */ +#define X_FUNC_E_NO_HALT 301 /* Cpu halt not allowed */ +#define X_FUNC_E_NO_SPEED 302 /* No speed control available */ +#define X_FUNC_E_NO_BIN_HDR 303 /* Can't determine hdr for hw %s */ +#define X_FUNC_F_xxx 401 +#define X_FUNC_M_KGET 501 /* FSB title for Kget function */ +#define X_FUNC_M_SEND 502 /* FSB title for Send function */ /*--------------------------------------------------------------------------- - Function prototypes + Function prototypes ---------------------------------------------------------------------------*/ -void ExtendedFunction(Nibble function_code); +void ExtendedFunction( Nibble function_code );