copy .clang-format from x48ng and format all the code
This commit is contained in:
parent
18be3f70ba
commit
d085a1537e
56 changed files with 10264 additions and 11720 deletions
59
.clang-format
Normal file
59
.clang-format
Normal file
|
@ -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
|
||||||
|
...
|
2
Makefile
2
Makefile
|
@ -87,7 +87,7 @@ clean-all: mrproper
|
||||||
|
|
||||||
# Formatting
|
# Formatting
|
||||||
pretty-code:
|
pretty-code:
|
||||||
clang-format -i src/*.c src/*.h
|
clang-format -i src/*.c src/*.h src/libChf/*.c src/libChf/*.h
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
get-roms:
|
get-roms:
|
||||||
|
|
|
@ -77,8 +77,7 @@
|
||||||
Data type definitions - require config.h
|
Data type definitions - require config.h
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
struct Args
|
struct Args {
|
||||||
{
|
|
||||||
int reset; /* 2.1: Force emulator reset */
|
int reset; /* 2.1: Force emulator reset */
|
||||||
int monitor; /* 2.1: Call monitor() on startup */
|
int monitor; /* 2.1: Call monitor() on startup */
|
||||||
int batchXfer; /* 3.15: Non-interactive file transfers */
|
int batchXfer; /* 3.15: Non-interactive file transfers */
|
||||||
|
@ -92,7 +91,6 @@ struct Args
|
||||||
char* hw; /* 2.1: Hardware configuration (unused) */
|
char* hw; /* 2.1: Hardware configuration (unused) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
14
src/config.h
14
src/config.h
|
@ -121,14 +121,12 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/* CHF_EXTENDED_INFO:
|
/* CHF_EXTENDED_INFO:
|
||||||
Define this symbol if extended information is desired during condition
|
Define this symbol if extended information is desired during condition
|
||||||
handling; this is usually useful only for debugging purposes.
|
handling; this is usually useful only for debugging purposes.
|
||||||
*/
|
*/
|
||||||
/* #define CHF_EXTENDED_INFO */
|
/* #define CHF_EXTENDED_INFO */
|
||||||
|
|
||||||
|
|
||||||
/* DEBUG:
|
/* DEBUG:
|
||||||
Define this symbol to include the debugging code for all source modules
|
Define this symbol to include the debugging code for all source modules
|
||||||
in the executable image.
|
in the executable image.
|
||||||
|
@ -139,7 +137,6 @@
|
||||||
*/
|
*/
|
||||||
/* #define DEBUG */
|
/* #define DEBUG */
|
||||||
|
|
||||||
|
|
||||||
/* DEBUG_LEVEL:
|
/* 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
|
in the executable image (DEBUG symbol set), the initial debug level
|
||||||
|
@ -151,7 +148,6 @@
|
||||||
*/
|
*/
|
||||||
#define DEBUG_LEVEL DEBUG_C_REVISION
|
#define DEBUG_LEVEL DEBUG_C_REVISION
|
||||||
|
|
||||||
|
|
||||||
/* CPU_SPIN_SHUTDN
|
/* CPU_SPIN_SHUTDN
|
||||||
If this symbol is defined, the cpu module implements the SHUTDN
|
If this symbol is defined, the cpu module implements the SHUTDN
|
||||||
instruction as a spin loop; when the instruction is encountered in the
|
instruction as a spin loop; when the instruction is encountered in the
|
||||||
|
@ -176,7 +172,6 @@
|
||||||
*/
|
*/
|
||||||
/* #define CPU_SPIN_SHUTDN */
|
/* #define CPU_SPIN_SHUTDN */
|
||||||
|
|
||||||
|
|
||||||
/* 2.1: FORCE_NONMODAL
|
/* 2.1: FORCE_NONMODAL
|
||||||
If this symbol is defined, nonmodal navigation is forced in the
|
If this symbol is defined, nonmodal navigation is forced in the
|
||||||
OSF/Motif GUI, by setting navigationType to XmNONE and traversalOn
|
OSF/Motif GUI, by setting navigationType to XmNONE and traversalOn
|
||||||
|
@ -184,7 +179,6 @@
|
||||||
*/
|
*/
|
||||||
/* #define FORCE_NONMODAL */
|
/* #define FORCE_NONMODAL */
|
||||||
|
|
||||||
|
|
||||||
/* 2.4: N_PORT_2_BANK
|
/* 2.4: N_PORT_2_BANK
|
||||||
This symbol is used to dimension the HP48GX Port_2: it denotes the
|
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
|
number of 128 Kbyte banks the port must have and must be a power of 2
|
||||||
|
@ -193,7 +187,6 @@
|
||||||
*/
|
*/
|
||||||
#define N_PORT_2_BANK 8
|
#define N_PORT_2_BANK 8
|
||||||
|
|
||||||
|
|
||||||
/* 2.5: SERIAL_FORCE_OPENPTY, SERIAL_FORCE_STREAMSPTY
|
/* 2.5: SERIAL_FORCE_OPENPTY, SERIAL_FORCE_STREAMSPTY
|
||||||
Optionally define exactly one of these symbols to force the use of a
|
Optionally define exactly one of these symbols to force the use of a
|
||||||
particular pty implementation; if no symbols are defined, the
|
particular pty implementation; if no symbols are defined, the
|
||||||
|
@ -203,7 +196,6 @@
|
||||||
/* #define SERIAL_FORCE_OPENPTY */
|
/* #define SERIAL_FORCE_OPENPTY */
|
||||||
/* #define SERIAL_FORCE_STREAMSPTY */
|
/* #define SERIAL_FORCE_STREAMSPTY */
|
||||||
|
|
||||||
|
|
||||||
/* 3.2: HP49_SUPPORT
|
/* 3.2: HP49_SUPPORT
|
||||||
Define this symbol to enable HP49-specific support code in the
|
Define this symbol to enable HP49-specific support code in the
|
||||||
emulator; it does not harm if this symbol is defined when emulating
|
emulator; it does not harm if this symbol is defined when emulating
|
||||||
|
@ -211,7 +203,6 @@
|
||||||
*/
|
*/
|
||||||
#define HP49_SUPPORT
|
#define HP49_SUPPORT
|
||||||
|
|
||||||
|
|
||||||
/* 3.13: REAL_CPU_SPEED
|
/* 3.13: REAL_CPU_SPEED
|
||||||
Define this symbol (recommended) to force the emulated CPU to run
|
Define this symbol (recommended) to force the emulated CPU to run
|
||||||
no faster than a software-controlled limit; by default, the limit
|
no faster than a software-controlled limit; by default, the limit
|
||||||
|
@ -219,7 +210,6 @@
|
||||||
*/
|
*/
|
||||||
#define REAL_CPU_SPEED
|
#define REAL_CPU_SPEED
|
||||||
|
|
||||||
|
|
||||||
/* 3.14: CPU_SLOW_IN
|
/* 3.14: CPU_SLOW_IN
|
||||||
Define this symbol (recommended) to slow down the A=IN and C=IN
|
Define this symbol (recommended) to slow down the A=IN and C=IN
|
||||||
instructions depending on the current emulated CPU speed.
|
instructions depending on the current emulated CPU speed.
|
||||||
|
@ -229,7 +219,6 @@
|
||||||
*/
|
*/
|
||||||
#define CPU_SLOW_IN 16
|
#define CPU_SLOW_IN 16
|
||||||
|
|
||||||
|
|
||||||
/* 4.1.1.1: LCD_MAG
|
/* 4.1.1.1: LCD_MAG
|
||||||
This symbol represents the magnification ratio of the emulated LCD pixels
|
This symbol represents the magnification ratio of the emulated LCD pixels
|
||||||
when drawn on the emulated display; supported values are 1 and 2; 2 is the
|
when drawn on the emulated display; supported values are 1 and 2; 2 is the
|
||||||
|
@ -238,7 +227,6 @@
|
||||||
*/
|
*/
|
||||||
#define LCD_MAG 2
|
#define LCD_MAG 2
|
||||||
|
|
||||||
|
|
||||||
/* 4.1.1.1: When defined, this symbol represents the threshold of the long
|
/* 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
|
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
|
for more than LONG_PRESS_THR milliseconds, the key stays pressed after
|
||||||
|
@ -246,7 +234,6 @@
|
||||||
*/
|
*/
|
||||||
#define LONG_PRESS_THR 1000
|
#define LONG_PRESS_THR 1000
|
||||||
|
|
||||||
|
|
||||||
/* Chf Module Identifiers:
|
/* Chf Module Identifiers:
|
||||||
Each main module of the emulator has its own Chf Module Identifier; the
|
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.
|
values defined here must match those actually used in the message catalogs.
|
||||||
|
@ -262,6 +249,5 @@
|
||||||
#define X_FUNC_CHF_MODULE_ID 18 /* 3.13 */
|
#define X_FUNC_CHF_MODULE_ID 18 /* 3.13 */
|
||||||
#define DEBUG_CHF_MODULE_ID 30
|
#define DEBUG_CHF_MODULE_ID 30
|
||||||
|
|
||||||
|
|
||||||
/* 3.16: Include automatic exceptions to user configuration */
|
/* 3.16: Include automatic exceptions to user configuration */
|
||||||
#include "config_x.h"
|
#include "config_x.h"
|
||||||
|
|
|
@ -58,7 +58,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/* REAL_CPU_SPEED is not supported on ultrix, because there is no usleep() */
|
/* REAL_CPU_SPEED is not supported on ultrix, because there is no usleep() */
|
||||||
#ifdef ultrix
|
#ifdef ultrix
|
||||||
# undef REAL_CPU_SPEED
|
# undef REAL_CPU_SPEED
|
||||||
|
|
19
src/cpu.h
19
src/cpu.h
|
@ -105,7 +105,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macro/Data type definitions - require machdep.h
|
Macro/Data type definitions - require machdep.h
|
||||||
|
|
||||||
|
@ -130,7 +129,6 @@
|
||||||
|
|
||||||
#define CPU_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
#define CPU_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
||||||
|
|
||||||
|
|
||||||
/* Instruction opcode access macros:
|
/* Instruction opcode access macros:
|
||||||
GetFS(f) returns the short field-selector value from the
|
GetFS(f) returns the short field-selector value from the
|
||||||
given nibble (bits 2..0)
|
given nibble (bits 2..0)
|
||||||
|
@ -175,7 +173,6 @@
|
||||||
#define GetAC( r ) ( ( r ) & 0x8 )
|
#define GetAC( r ) ( ( r ) & 0x8 )
|
||||||
#define GetAS( r ) ( ( r ) & 0x8 )
|
#define GetAS( r ) ( ( r ) & 0x8 )
|
||||||
|
|
||||||
|
|
||||||
/* Field selector codes */
|
/* Field selector codes */
|
||||||
#define FS_P 0
|
#define FS_P 0
|
||||||
#define FS_WP 1
|
#define FS_WP 1
|
||||||
|
@ -188,7 +185,6 @@
|
||||||
#define FS_A 15
|
#define FS_A 15
|
||||||
#define N_FS 16 /* Total # of FS codes */
|
#define N_FS 16 /* Total # of FS codes */
|
||||||
|
|
||||||
|
|
||||||
/* Register pair codes */
|
/* Register pair codes */
|
||||||
#define RP_AB 0
|
#define RP_AB 0
|
||||||
#define RP_BC 1
|
#define RP_BC 1
|
||||||
|
@ -196,7 +192,6 @@
|
||||||
#define RP_DC 3
|
#define RP_DC 3
|
||||||
#define N_RP 4 /* Total # of RP codes */
|
#define N_RP 4 /* Total # of RP codes */
|
||||||
|
|
||||||
|
|
||||||
/* Masks */
|
/* Masks */
|
||||||
#define NIBBLE_MASK ( ( Nibble )0xF )
|
#define NIBBLE_MASK ( ( Nibble )0xF )
|
||||||
#define ADDRESS_MASK ( ( Address )0xFFFFF )
|
#define ADDRESS_MASK ( ( Address )0xFFFFF )
|
||||||
|
@ -205,7 +200,6 @@
|
||||||
#define D_S_MASK ( ( Address )0xF0000 )
|
#define D_S_MASK ( ( Address )0xF0000 )
|
||||||
#define RETURN_SP_MASK 0x7
|
#define RETURN_SP_MASK 0x7
|
||||||
|
|
||||||
|
|
||||||
typedef int1 Bit;
|
typedef int1 Bit;
|
||||||
typedef int4 Nibble;
|
typedef int4 Nibble;
|
||||||
typedef int20 Address;
|
typedef int20 Address;
|
||||||
|
@ -217,15 +211,9 @@ typedef Nibble DataRegister[NIBBLE_PER_REGISTER];
|
||||||
/* The XAddress data type holds extended addresses used to access Port 2 */
|
/* The XAddress data type holds extended addresses used to access Port 2 */
|
||||||
typedef int32 XAddress;
|
typedef int32 XAddress;
|
||||||
|
|
||||||
enum IntRequest
|
enum IntRequest { INT_REQUEST_NONE, INT_REQUEST_IRQ, INT_REQUEST_NMI };
|
||||||
{
|
|
||||||
INT_REQUEST_NONE,
|
|
||||||
INT_REQUEST_IRQ,
|
|
||||||
INT_REQUEST_NMI
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CpuStatus
|
struct CpuStatus {
|
||||||
{
|
|
||||||
DataRegister work[ N_WORKING_REGISTER ];
|
DataRegister work[ N_WORKING_REGISTER ];
|
||||||
#define A work[ 0 ]
|
#define A work[ 0 ]
|
||||||
#define B work[ 1 ]
|
#define B work[ 1 ]
|
||||||
|
@ -290,14 +278,12 @@ enum ExitOption /* 2.1: EmulatorExit() option */
|
||||||
SAVE_AND_EXIT
|
SAVE_AND_EXIT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
extern struct CpuStatus cpu_status;
|
extern struct CpuStatus cpu_status;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -329,7 +315,6 @@ extern struct CpuStatus cpu_status;
|
||||||
#define CPU_F_INTERR 401 /* Internal error %s */
|
#define CPU_F_INTERR 401 /* Internal error %s */
|
||||||
#define CPU_F_BAD_SHUTDN 402 /* Unexpected CPU shutdown */
|
#define CPU_F_BAD_SHUTDN 402 /* Unexpected CPU shutdown */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -76,7 +76,6 @@ static char rcs_id[] = "$Id: debug.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID DEBUG_CHF_MODULE_ID
|
#define CHF_MODULE_ID DEBUG_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Static/Global variables
|
Static/Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -89,7 +88,6 @@ int debug_level = 0;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
21
src/debug.h
21
src/debug.h
|
@ -104,8 +104,7 @@
|
||||||
# define debug_preamble( debug_class, condition_code ) \
|
# define debug_preamble( debug_class, condition_code ) \
|
||||||
{ \
|
{ \
|
||||||
extern int debug_level; \
|
extern int debug_level; \
|
||||||
if(debug_level & (debug_class)) \
|
if ( debug_level & ( debug_class ) ) { \
|
||||||
{ \
|
|
||||||
ChfCondition( condition_code ), CHF_INFO
|
ChfCondition( condition_code ), CHF_INFO
|
||||||
|
|
||||||
# define debug_postamble \
|
# define debug_postamble \
|
||||||
|
@ -114,21 +113,14 @@
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define debug0(debug_class, condition_code) \
|
# define debug0( debug_class, condition_code ) debug_preamble( debug_class, condition_code ) debug_postamble
|
||||||
debug_preamble(debug_class, condition_code) \
|
|
||||||
debug_postamble
|
|
||||||
|
|
||||||
#define debug1(debug_class, condition_code, arg_1) \
|
# define debug1( debug_class, condition_code, arg_1 ) debug_preamble( debug_class, condition_code ), arg_1 debug_postamble
|
||||||
debug_preamble(debug_class, condition_code), arg_1 \
|
|
||||||
debug_postamble
|
|
||||||
|
|
||||||
#define debug2(debug_class, condition_code, arg_1, arg_2) \
|
# define debug2( debug_class, condition_code, arg_1, arg_2 ) debug_preamble( debug_class, condition_code ), arg_1, arg_2 debug_postamble
|
||||||
debug_preamble(debug_class, condition_code), arg_1, arg_2 \
|
|
||||||
debug_postamble
|
|
||||||
|
|
||||||
# define debug3( debug_class, condition_code, arg_1, arg_2, arg_3 ) \
|
# 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_preamble( debug_class, condition_code ), arg_1, arg_2, arg_3 debug_postamble
|
||||||
debug_postamble
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -139,7 +131,6 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Debug classes
|
Debug classes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -157,7 +148,6 @@
|
||||||
#define DEBUG_C_REVISION 0x0010 /* Revision information */
|
#define DEBUG_C_REVISION 0x0010 /* Revision information */
|
||||||
#define DEBUG_C_X11 0x0001 /* X11 Interface */
|
#define DEBUG_C_X11 0x0001 /* X11 Interface */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -165,7 +155,6 @@
|
||||||
#define DEBUG_W_NOT_SUPPORTED 201 /* Debug not supported */
|
#define DEBUG_W_NOT_SUPPORTED 201 /* Debug not supported */
|
||||||
#define DEBUG_W_BAD_CMD 202 /* Invalid command */
|
#define DEBUG_W_BAD_CMD 202 /* Invalid command */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
251
src/dis.c
251
src/dis.c
|
@ -98,57 +98,39 @@ static char rcs_id[] = "$Id: dis.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions/macros/variables
|
Private functions/macros/variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Mnemonics */
|
/* Mnemonics */
|
||||||
static const char *hex_digit[] =
|
static const char* hex_digit[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
|
||||||
{ "0", "1", "2", "3", "4", "5", "6", "7",
|
|
||||||
"8", "9", "A", "B", "C", "D", "E", "F" };
|
|
||||||
|
|
||||||
static const char *reg_pair[] =
|
static const char* reg_pair[] = { "AB", "BC", "CA", "DC" };
|
||||||
{ "AB", "BC", "CA", "DC" };
|
|
||||||
|
|
||||||
static const char *rn_name[] =
|
static const char* rn_name[] = { "R0", "R1", "R2", "R3", "R4", "?R5", "?R6", "?R7" };
|
||||||
{ "R0", "R1", "R2", "R3", "R4", "?R5", "?R6", "?R7" };
|
|
||||||
|
|
||||||
static const char *field_sel[] =
|
static const char* field_sel[] = { "P", "WP", "XS", "X", "S", "M", "B", "W", "?[8]", "?[9]", "?[A]", "?[B]", "?[C]", "?[D]", "?[E]", "A" };
|
||||||
{ "P", "WP", "XS", "X", "S", "M", "B", "W",
|
|
||||||
"?[8]", "?[9]", "?[A]", "?[B]", "?[C]", "?[D]", "?[E]", "A" };
|
|
||||||
|
|
||||||
static const char *group_0_opc[] =
|
static const char* group_0_opc[] = { "RTNSXM", "RTN", "RTNSC", "RTNCC", "SETHEX", "SETDEC", "RSTK=C", "C=RSTK",
|
||||||
{ "RTNSXM", "RTN", "RTNSC", "RTNCC", "SETHEX", "SETDEC", "RSTK=C", "C=RSTK",
|
|
||||||
"CLRST", "C=ST", "ST=C", "CSTEX", "P=P+1", "P=P-1", NULL, "RTI" };
|
"CLRST", "C=ST", "ST=C", "CSTEX", "P=P+1", "P=P-1", NULL, "RTI" };
|
||||||
|
|
||||||
static const char *group_13_opc[] =
|
static const char* group_13_opc[] = { "D0=A", "D1=A", "AD0EX", "AD1EX", "D0=C", "D1=C", "CD0EX", "CD1EX",
|
||||||
{ "D0=A", "D1=A", "AD0EX", "AD1EX", "D0=C", "D1=C", "CD0EX", "CD1EX",
|
|
||||||
"D0=AS", "D1=AS", "AD0XS", "AD1XS", "D0=CS", "D1=CS", "CD0XS", "CD1XS" };
|
"D0=AS", "D1=AS", "AD0XS", "AD1XS", "D0=CS", "D1=CS", "CD0XS", "CD1XS" };
|
||||||
|
|
||||||
static const char *group_14_opc[] =
|
static const char* group_14_opc[] = { "DAT0=A\tA", "DAT1=A\tA", "A=DAT0\tA", "A=DAT1\tA", "DAT0=C\tA", "DAT1=C\tA",
|
||||||
{ "DAT0=A\tA", "DAT1=A\tA", "A=DAT0\tA", "A=DAT1\tA",
|
"C=DAT0\tA", "C=DAT1\tA", "DAT0=A\tB", "DAT1=A\tB", "A=DAT0\tB", "A=DAT1\tB",
|
||||||
"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" };
|
"DAT0=C\tB", "DAT1=C\tB", "C=DAT0\tB", "C=DAT1\tB" };
|
||||||
|
|
||||||
static const char *group_15_opc[] =
|
static const char* group_15_opc[] = { "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1", "DAT0=C", "DAT1=C", "C=DAT0", "C=DAT1" };
|
||||||
{ "DAT0=A", "DAT1=A", "A=DAT0", "A=DAT1",
|
|
||||||
"DAT0=C", "DAT1=C", "C=DAT0", "C=DAT1" };
|
|
||||||
|
|
||||||
static const char *group_80_opc[] =
|
static const char* group_80_opc[] = { "OUT=CS", "OUT=C", "A=IN", "C=IN", "UNCNFG", "CONFIG", "C=ID", "SHUTDN",
|
||||||
{ "OUT=CS", "OUT=C", "A=IN", "C=IN", "UNCNFG", "CONFIG", "C=ID", "SHUTDN",
|
|
||||||
"?", "C+P+1", "RESET", "BUSCC", "?", "?", "SREQ?", "?" };
|
"?", "C+P+1", "RESET", "BUSCC", "?", "?", "SREQ?", "?" };
|
||||||
|
|
||||||
static const char *group_81B_opc[] =
|
static const char* group_81B_opc[] = { "?", "?", "PC=A", "PC=C", "A=PC", "C=PC", "APCEX", "CPCEX", "?", "?", "?", "?", "?", "?", "?", "?" };
|
||||||
{ "?", "?", "PC=A", "PC=C", "A=PC", "C=PC", "APCEX", "CPCEX",
|
|
||||||
"?", "?", "?", "?", "?", "?", "?", "?" };
|
|
||||||
|
|
||||||
|
|
||||||
/* Get a nibble from main memory */
|
/* Get a nibble from main memory */
|
||||||
#define GetNibble FetchNibble
|
#define GetNibble FetchNibble
|
||||||
|
|
||||||
|
|
||||||
/* Read two nibbles in two-complement form, starting from pc, */
|
/* Read two nibbles in two-complement form, starting from pc, */
|
||||||
static Address Get2Nibbles2C( Address pc )
|
static Address Get2Nibbles2C( Address pc )
|
||||||
{
|
{
|
||||||
|
@ -157,38 +139,32 @@ static Address Get2Nibbles2C(Address pc)
|
||||||
return ( v & 0x80 ) ? v - 0x100 : v;
|
return ( v & 0x80 ) ? v - 0x100 : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Read three nibbles in two-complement form, starting from pc, */
|
/* 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 v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 );
|
||||||
((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 */
|
/* 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 v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) |
|
||||||
((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12);
|
( ( 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 */
|
/* 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 v = ( Address )GetNibble( pc ) | ( ( Address )GetNibble( pc + 1 ) << 4 ) | ( ( Address )GetNibble( pc + 2 ) << 8 ) |
|
||||||
((Address)GetNibble(pc+2) << 8) | ((Address)GetNibble(pc+3) << 12) |
|
( ( Address )GetNibble( pc + 3 ) << 12 ) | ( ( Address )GetNibble( pc + 4 ) << 16 );
|
||||||
((Address)GetNibble(pc+4) << 16);
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Disassemble Hex constant, starting from 'start', for 'm' nibbles;
|
/* Disassemble Hex constant, starting from 'start', for 'm' nibbles;
|
||||||
returns the address of the next instruction
|
returns the address of the next instruction
|
||||||
*/
|
*/
|
||||||
|
@ -202,7 +178,6 @@ static Address DisHexConstant(Address start, char *ob, int m)
|
||||||
return start + m;
|
return start + m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* GOYES/RTNYES */
|
/* GOYES/RTNYES */
|
||||||
static Address DisGOYES_RTNYES( Address pc, char* ob )
|
static Address DisGOYES_RTNYES( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -221,7 +196,6 @@ static Address DisGOYES_RTNYES(Address pc, char *ob)
|
||||||
return pc + 2;
|
return pc + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Disassemble field selector */
|
/* Disassemble field selector */
|
||||||
static void DisFIELD_SEL( int fs, char* ob )
|
static void DisFIELD_SEL( int fs, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -236,7 +210,6 @@ static void DisIMM_FIELD_SEL(int fs, char *ob)
|
||||||
sprintf( ob, "\t%d", fs + 1 );
|
sprintf( ob, "\t%d", fs + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* P=n, opcode 2n, length 2 */
|
/* P=n, opcode 2n, length 2 */
|
||||||
static Address DisPEqn( Address pc, char* ob )
|
static Address DisPEqn( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -244,7 +217,6 @@ static Address DisPEqn(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* LC(m) n..n, opcode 3xn..n, length 3+m, x=m-1 */
|
/* LC(m) n..n, opcode 3xn..n, length 3+m, x=m-1 */
|
||||||
static Address DisLC( Address pc, char* ob )
|
static Address DisLC( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -254,7 +226,6 @@ static Address DisLC(Address pc, char *ob)
|
||||||
return DisHexConstant( pc, ob, m );
|
return DisHexConstant( pc, ob, m );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* RTNC, GOC, opcode 4xx, length 3 - Special case: NOP3 */
|
/* RTNC, GOC, opcode 4xx, length 3 - Special case: NOP3 */
|
||||||
static Address DisRTNC_GOC( Address pc, char* ob )
|
static Address DisRTNC_GOC( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -276,7 +247,6 @@ static Address DisRTNC_GOC(Address pc, char *ob)
|
||||||
return pc + 2;
|
return pc + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* RTNNC, GONC, opcode 5xx, length 3 */
|
/* RTNNC, GONC, opcode 5xx, length 3 */
|
||||||
static Address DisRTNNC_GONC( Address pc, char* ob )
|
static Address DisRTNNC_GONC( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -294,28 +264,24 @@ static Address DisRTNNC_GONC(Address pc, char *ob)
|
||||||
return pc + 2;
|
return pc + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* GOTO, opcode 6xxx, length 4 - Special cases: NOP4, NOP5 (p.holder) */
|
/* GOTO, opcode 6xxx, length 4 - Special cases: NOP4, NOP5 (p.holder) */
|
||||||
static Address DisGOTO( Address pc, char* ob )
|
static Address DisGOTO( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
Address offset = Get3Nibbles2C( pc );
|
Address offset = Get3Nibbles2C( pc );
|
||||||
|
|
||||||
if(offset == 3)
|
if ( offset == 3 ) {
|
||||||
{
|
|
||||||
/* NOP4 */
|
/* NOP4 */
|
||||||
sprintf( ob, "NOP4" );
|
sprintf( ob, "NOP4" );
|
||||||
pc += 3;
|
pc += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(offset == 4)
|
else if ( offset == 4 ) {
|
||||||
{
|
|
||||||
/* NOP5 */
|
/* NOP5 */
|
||||||
sprintf( ob, "NOP5" );
|
sprintf( ob, "NOP5" );
|
||||||
pc += 4;
|
pc += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
sprintf( ob, "GOTO\tA_%05X\t* Offset [%d]d", pc + offset, offset );
|
sprintf( ob, "GOTO\tA_%05X\t* Offset [%d]d", pc + offset, offset );
|
||||||
pc += 3;
|
pc += 3;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +289,6 @@ static Address DisGOTO(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* GOSUB, opcode 7xxx, length 4 */
|
/* GOSUB, opcode 7xxx, length 4 */
|
||||||
static Address DisGOSUB( Address pc, char* ob )
|
static Address DisGOSUB( Address pc, char* ob )
|
||||||
{
|
{
|
||||||
|
@ -335,7 +300,6 @@ static Address DisGOSUB(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ?..., GOYES/RTNYES, Test with Field Selector, opcode 9ftyy, length 5
|
/* ?..., GOYES/RTNYES, Test with Field Selector, opcode 9ftyy, length 5
|
||||||
|
|
||||||
FS = f & 0x7
|
FS = f & 0x7
|
||||||
|
@ -422,8 +386,7 @@ static Address DisTest_9(Address pc, char *ob)
|
||||||
int rp = GetRP( t );
|
int rp = GetRP( t );
|
||||||
|
|
||||||
/* Decode test code */
|
/* Decode test code */
|
||||||
switch(tc)
|
switch ( tc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf( ob, "?%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
sprintf( ob, "?%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
break;
|
break;
|
||||||
|
@ -469,7 +432,6 @@ static Address DisTest_9(Address pc, char *ob)
|
||||||
return DisGOYES_RTNYES( pc, ob );
|
return DisGOYES_RTNYES( pc, ob );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation with Field Selector, opcode Afo, length 3
|
/* ..., Register Operation with Field Selector, opcode Afo, length 3
|
||||||
|
|
||||||
FS = f & 0x7
|
FS = f & 0x7
|
||||||
|
@ -557,21 +519,17 @@ static Address DisRegOp_A(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -606,7 +564,6 @@ static Address DisRegOp_A(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation with Field Selector, opcode Bfo, length 3
|
/* ..., Register Operation with Field Selector, opcode Bfo, length 3
|
||||||
|
|
||||||
FS = f & 0x7
|
FS = f & 0x7
|
||||||
|
@ -694,11 +651,9 @@ static Address DisRegOp_B(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -706,13 +661,11 @@ static Address DisRegOp_B(Address pc, char *ob)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
|
@ -743,7 +696,6 @@ static Address DisRegOp_B(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation on A Fields, opcode Co, length 2
|
/* ..., Register Operation on A Fields, opcode Co, length 2
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -794,21 +746,17 @@ static Address DisRegOp_C(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(ob, "%c=%c+%c",
|
sprintf( ob, "%c=%c+%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -827,7 +775,6 @@ static Address DisRegOp_C(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation on A Fields, opcode Do, length 2
|
/* ..., Register Operation on A Fields, opcode Do, length 2
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -878,8 +825,7 @@ static Address DisRegOp_D(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf( ob, "%c=0", reg_pair[ rp ][ 0 ] );
|
sprintf( ob, "%c=0", reg_pair[ rp ][ 0 ] );
|
||||||
break;
|
break;
|
||||||
|
@ -908,7 +854,6 @@ static Address DisRegOp_D(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation on A Fields, opcode Eo, length 2
|
/* ..., Register Operation on A Fields, opcode Eo, length 2
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -960,11 +905,9 @@ static Address DisRegOp_E(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -972,13 +915,11 @@ static Address DisRegOp_E(Address pc, char *ob)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
sprintf(ob, "%c=%c-%c",
|
sprintf( ob, "%c=%c-%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -993,7 +934,6 @@ static Address DisRegOp_E(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ..., Register Operation on A Fields, opcode Fo, length 2
|
/* ..., Register Operation on A Fields, opcode Fo, length 2
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -1045,8 +985,7 @@ static Address DisRegOp_F(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf( ob, "%cSL", reg_pair[ rp ][ 0 ] );
|
sprintf( ob, "%cSL", reg_pair[ rp ][ 0 ] );
|
||||||
break;
|
break;
|
||||||
|
@ -1075,7 +1014,6 @@ static Address DisRegOp_F(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .&., .!., AND/OR Operations, opcode 0Efo, length 4
|
/* .&., .!., AND/OR Operations, opcode 0Efo, length 4
|
||||||
|
|
||||||
FS = f
|
FS = f
|
||||||
|
@ -1139,26 +1077,21 @@ static Address DisAND_OR(Address pc, char *ob)
|
||||||
int rp = GetRP( o );
|
int rp = GetRP( o );
|
||||||
|
|
||||||
/* Decode operation code */
|
/* Decode operation code */
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(ob, "%c=%c&%c",
|
sprintf( ob, "%c=%c&%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
sprintf(ob, "%c=%c&%c",
|
sprintf( ob, "%c=%c&%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(ob, "%c=%c!%c",
|
sprintf( ob, "%c=%c!%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], reg_pair[rp][1]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
sprintf(ob, "%c=%c!%c",
|
sprintf( ob, "%c=%c!%c", reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 1 ], reg_pair[ rp ][ 0 ] );
|
||||||
reg_pair[rp][1], reg_pair[rp][1], reg_pair[rp][0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1173,7 +1106,6 @@ static Address DisAND_OR(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Instruction Group_0
|
/* Instruction Group_0
|
||||||
Prefix 0E introduces AND/OR opcodes
|
Prefix 0E introduces AND/OR opcodes
|
||||||
*/
|
*/
|
||||||
|
@ -1181,8 +1113,7 @@ static Address DisGroup_0(Address pc, char *ob)
|
||||||
{
|
{
|
||||||
Nibble n = GetNibble( pc++ );
|
Nibble n = GetNibble( pc++ );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* RTNSXM */
|
/* RTNSXM */
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -1233,7 +1164,6 @@ static Address DisGroup_0(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Instruction Group_1
|
/* Instruction Group_1
|
||||||
|
|
||||||
Opcode table for:
|
Opcode table for:
|
||||||
|
@ -1374,8 +1304,7 @@ static Address DisGroup_1(Address pc, char *ob)
|
||||||
int rn, ac;
|
int rn, ac;
|
||||||
int oc, is;
|
int oc, is;
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Rn=A/C */
|
/* Rn=A/C */
|
||||||
n = GetNibble( pc++ );
|
n = GetNibble( pc++ );
|
||||||
|
@ -1507,7 +1436,6 @@ static Address DisGroup_1(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Instruction Group_808
|
/* Instruction Group_808
|
||||||
*/
|
*/
|
||||||
static Address DisGroup_808( Address pc, char* ob )
|
static Address DisGroup_808( Address pc, char* ob )
|
||||||
|
@ -1515,8 +1443,7 @@ static Address DisGroup_808(Address pc, char *ob)
|
||||||
Nibble n = GetNibble( pc++ );
|
Nibble n = GetNibble( pc++ );
|
||||||
Nibble m;
|
Nibble m;
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* INTON */
|
/* INTON */
|
||||||
strcpy( ob, "INTON" );
|
strcpy( ob, "INTON" );
|
||||||
|
@ -1630,8 +1557,7 @@ static Address DisGroup_80(Address pc, char *ob)
|
||||||
{
|
{
|
||||||
Nibble n = GetNibble( pc++ );
|
Nibble n = GetNibble( pc++ );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* OUT=CS */
|
/* OUT=CS */
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -1694,7 +1620,6 @@ static Address DisGroup_80(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Special functions Group_81
|
/* Special functions Group_81
|
||||||
|
|
||||||
Opcode Table for:
|
Opcode Table for:
|
||||||
|
@ -1772,8 +1697,7 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp)
|
||||||
Nibble n, f, m;
|
Nibble n, f, m;
|
||||||
int rn, ac;
|
int rn, ac;
|
||||||
|
|
||||||
switch(rp)
|
switch ( rp ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* r=r+-CON fs, d */
|
/* r=r+-CON fs, d */
|
||||||
f = GetNibble( pc++ );
|
f = GetNibble( pc++ );
|
||||||
|
@ -1781,8 +1705,7 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp)
|
||||||
m = GetNibble( pc++ );
|
m = GetNibble( pc++ );
|
||||||
rp = GetRP( n );
|
rp = GetRP( n );
|
||||||
|
|
||||||
sprintf(ob, "%c=%c%cCON",
|
sprintf( ob, "%c=%c%cCON", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 0 ], ( GetAS( n ) ? '-' : '+' ) );
|
||||||
reg_pair[rp][0], reg_pair[rp][0], (GetAS(n) ? '-' : '+' ));
|
|
||||||
|
|
||||||
/* Decode field selector */
|
/* Decode field selector */
|
||||||
DisFIELD_SEL( f, ob );
|
DisFIELD_SEL( f, ob );
|
||||||
|
@ -1812,8 +1735,7 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp)
|
||||||
rn = GetRn( m );
|
rn = GetRn( m );
|
||||||
ac = GetAC( m );
|
ac = GetAC( m );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Rn=r.F fs */
|
/* Rn=r.F fs */
|
||||||
sprintf( ob, "%s=%s.F", rn_name[ rn ], ( ac ? "C" : "A" ) );
|
sprintf( ob, "%s=%s.F", rn_name[ rn ], ( ac ? "C" : "A" ) );
|
||||||
|
@ -1855,7 +1777,6 @@ static Address DisSpecialGroup_81(Address pc, char *ob, int rp)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Atyy, length 5
|
/* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Atyy, length 5
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -1907,8 +1828,7 @@ static Address DisTest_8A(Address pc, char *ob)
|
||||||
int rp = GetRP( t );
|
int rp = GetRP( t );
|
||||||
|
|
||||||
/* Decode test code */
|
/* Decode test code */
|
||||||
switch(tc)
|
switch ( tc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf( ob, "?%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
sprintf( ob, "?%c=%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
break;
|
break;
|
||||||
|
@ -1938,7 +1858,6 @@ static Address DisTest_8A(Address pc, char *ob)
|
||||||
return DisGOYES_RTNYES( pc, ob );
|
return DisGOYES_RTNYES( pc, ob );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Btyy, length 5
|
/* ?..., GOYES/RTNYES, Test on A Fields, opcode 8Btyy, length 5
|
||||||
|
|
||||||
FS = implicit, always A
|
FS = implicit, always A
|
||||||
|
@ -1990,8 +1909,7 @@ static Address DisTest_8B(Address pc, char *ob)
|
||||||
int rp = GetRP( t );
|
int rp = GetRP( t );
|
||||||
|
|
||||||
/* Decode test code */
|
/* Decode test code */
|
||||||
switch(tc)
|
switch ( tc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
sprintf( ob, "?%c>%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
sprintf( ob, "?%c>%c", reg_pair[ rp ][ 0 ], reg_pair[ rp ][ 1 ] );
|
||||||
break;
|
break;
|
||||||
|
@ -2021,7 +1939,6 @@ static Address DisTest_8B(Address pc, char *ob)
|
||||||
return DisGOYES_RTNYES( pc, ob );
|
return DisGOYES_RTNYES( pc, ob );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Instruction Group_8
|
/* Instruction Group_8
|
||||||
|
|
||||||
Opcode table for:
|
Opcode table for:
|
||||||
|
@ -2075,8 +1992,7 @@ static Address DisGroup_8(Address pc, char *ob)
|
||||||
Address addr;
|
Address addr;
|
||||||
int oc, rp;
|
int oc, rp;
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
pc = DisGroup_80( pc, ob );
|
pc = DisGroup_80( pc, ob );
|
||||||
break;
|
break;
|
||||||
|
@ -2087,8 +2003,7 @@ static Address DisGroup_8(Address pc, char *ob)
|
||||||
oc = GetOC_1( n );
|
oc = GetOC_1( n );
|
||||||
rp = GetRP( n );
|
rp = GetRP( n );
|
||||||
|
|
||||||
switch(oc)
|
switch ( oc ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* rSLC */
|
/* rSLC */
|
||||||
sprintf( ob, "%cSLC", reg_pair[ rp ][ 0 ] );
|
sprintf( ob, "%cSLC", reg_pair[ rp ][ 0 ] );
|
||||||
|
@ -2120,8 +2035,7 @@ static Address DisGroup_8(Address pc, char *ob)
|
||||||
/* CLRHSn */
|
/* CLRHSn */
|
||||||
n = GetNibble( pc++ );
|
n = GetNibble( pc++ );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
strcpy( ob, "XM=0" );
|
strcpy( ob, "XM=0" );
|
||||||
break;
|
break;
|
||||||
|
@ -2152,8 +2066,7 @@ static Address DisGroup_8(Address pc, char *ob)
|
||||||
/* ?HS=0 */
|
/* ?HS=0 */
|
||||||
n = GetNibble( pc++ );
|
n = GetNibble( pc++ );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
strcpy( ob, "?XM=0" );
|
strcpy( ob, "?XM=0" );
|
||||||
break;
|
break;
|
||||||
|
@ -2289,7 +2202,6 @@ static Address DisGroup_8(Address pc, char *ob)
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -2328,71 +2240,86 @@ Address Disassemble(Address pc, char ob[DISASSEMBLE_OB_SIZE])
|
||||||
/* Get first instruction nibble */
|
/* Get first instruction nibble */
|
||||||
n = GetNibble( pc++ );
|
n = GetNibble( pc++ );
|
||||||
|
|
||||||
switch(n)
|
switch ( n ) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
/* Group_0 */
|
/* Group_0 */
|
||||||
pc = DisGroup_0(pc, ob); break;
|
pc = DisGroup_0( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
/* Group_1 */
|
/* Group_1 */
|
||||||
pc = DisGroup_1(pc, ob); break;
|
pc = DisGroup_1( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
/* P=n */
|
/* P=n */
|
||||||
pc = DisPEqn(pc, ob); break;
|
pc = DisPEqn( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
/* LC(m) n...n */
|
/* LC(m) n...n */
|
||||||
pc = DisLC(pc, ob); break;
|
pc = DisLC( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
/* RTNC/GOC */
|
/* RTNC/GOC */
|
||||||
pc = DisRTNC_GOC(pc, ob); break;
|
pc = DisRTNC_GOC( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
/* RTNNC/GONC */
|
/* RTNNC/GONC */
|
||||||
pc = DisRTNNC_GONC(pc, ob); break;
|
pc = DisRTNNC_GONC( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
/* GOTO */
|
/* GOTO */
|
||||||
pc = DisGOTO(pc, ob); break;
|
pc = DisGOTO( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
/* GOSUB */
|
/* GOSUB */
|
||||||
pc = DisGOSUB(pc, ob); break;
|
pc = DisGOSUB( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
/* Group_8 */
|
/* Group_8 */
|
||||||
pc = DisGroup_8(pc, ob); break;
|
pc = DisGroup_8( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 9:
|
case 9:
|
||||||
/* Test */
|
/* Test */
|
||||||
pc = DisTest_9(pc, ob); break;
|
pc = DisTest_9( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xA:
|
case 0xA:
|
||||||
/* Register Operation, group A */
|
/* Register Operation, group A */
|
||||||
pc = DisRegOp_A(pc, ob); break;
|
pc = DisRegOp_A( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xB:
|
case 0xB:
|
||||||
/* Register Operation, group B */
|
/* Register Operation, group B */
|
||||||
pc = DisRegOp_B(pc, ob); break;
|
pc = DisRegOp_B( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xC:
|
case 0xC:
|
||||||
/* Register Operation, group C */
|
/* Register Operation, group C */
|
||||||
pc = DisRegOp_C(pc, ob); break;
|
pc = DisRegOp_C( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xD:
|
case 0xD:
|
||||||
/* Register Operation, group D */
|
/* Register Operation, group D */
|
||||||
pc = DisRegOp_D(pc, ob); break;
|
pc = DisRegOp_D( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xE:
|
case 0xE:
|
||||||
/* Register Operation, group E */
|
/* Register Operation, group E */
|
||||||
pc = DisRegOp_E(pc, ob); break;
|
pc = DisRegOp_E( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
case 0xF:
|
case 0xF:
|
||||||
/* Register Operation, group F */
|
/* Register Operation, group F */
|
||||||
pc = DisRegOp_F(pc, ob); break;
|
pc = DisRegOp_F( pc, ob );
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Unknown opcode */
|
/* Unknown opcode */
|
||||||
|
|
|
@ -79,7 +79,6 @@ static char rcs_id[] = "$Id: disk_io.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID
|
#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ReadNibblesFromFile
|
.title : ReadNibblesFromFile
|
||||||
|
@ -115,20 +114,16 @@ int ReadNibblesFromFile(const char *name, int size, Nibble *dest)
|
||||||
|
|
||||||
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)
|
if ( ( f = fopen( name, "rb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
for ( i = 0; i < size; ) {
|
||||||
for(i=0; i<size;)
|
|
||||||
{
|
|
||||||
by = getc( f );
|
by = getc( f );
|
||||||
|
|
||||||
if(by == -1)
|
if ( by == -1 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
|
@ -144,7 +139,6 @@ int ReadNibblesFromFile(const char *name, int size, Nibble *dest)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : WriteNibblesToFile
|
.title : WriteNibblesToFile
|
||||||
|
@ -180,29 +174,24 @@ int WriteNibblesToFile(const Nibble *src, int size, const char *name)
|
||||||
|
|
||||||
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)
|
if ( ( f = fopen( name, "wb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
for ( i = 0; i < size; ) {
|
||||||
for(i=0; i<size;)
|
|
||||||
{
|
|
||||||
by = ( int )src[ i++ ];
|
by = ( int )src[ i++ ];
|
||||||
by |= ( int )src[ i++ ] << 4;
|
by |= ( int )src[ i++ ] << 4;
|
||||||
|
|
||||||
if(putc(by, f) == EOF)
|
if ( putc( by, f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fclose(f) == EOF)
|
if ( fclose( f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +200,6 @@ int WriteNibblesToFile(const Nibble *src, int size, const char *name)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ReadStructFromFile
|
.title : ReadStructFromFile
|
||||||
|
@ -243,16 +231,13 @@ int ReadStructFromFile(const char *name, size_t s_size, void *s)
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadStructFromFile" );
|
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "ReadStructFromFile" );
|
||||||
|
|
||||||
if((f = fopen(name, "rb")) == (FILE *)NULL)
|
if ( ( f = fopen( name, "rb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
if ( fread( s, s_size, ( size_t )1, f ) != 1 ) {
|
||||||
if(fread(s, s_size, (size_t)1, f) != 1)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_READ, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_READ, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +248,6 @@ int ReadStructFromFile(const char *name, size_t s_size, void *s)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : WriteStructToFile
|
.title : WriteStructToFile
|
||||||
|
@ -297,22 +281,18 @@ int WriteStructToFile(const void *s, size_t s_size, const char *name)
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteStructToFile" );
|
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteStructToFile" );
|
||||||
|
|
||||||
if((f = fopen(name, "wb")) == (FILE *)NULL)
|
if ( ( f = fopen( name, "wb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
if ( fwrite( s, s_size, ( size_t )1, f ) != 1 ) {
|
||||||
if(fwrite(s, s_size, (size_t)1, f) != 1)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_WRITE, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_WRITE, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fclose(f) == EOF)
|
if ( fclose( f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -84,7 +83,6 @@
|
||||||
#define DISK_IO_E_BAD_HDR 407 /* File %s has a bad header */
|
#define DISK_IO_E_BAD_HDR 407 /* File %s has a bad header */
|
||||||
#define DISK_IO_E_SIZE 408 /* File %s too large */
|
#define DISK_IO_E_SIZE 408 /* File %s too large */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -94,7 +92,5 @@ int WriteNibblesToFile(const Nibble *src, int size, const char *name);
|
||||||
int ReadStructFromFile( const char* name, size_t s_size, void* s );
|
int ReadStructFromFile( const char* name, size_t s_size, void* s );
|
||||||
int WriteStructToFile( const void* s, size_t s_size, const char* name );
|
int WriteStructToFile( const void* s, size_t s_size, const char* name );
|
||||||
|
|
||||||
int ReadObjectFromFile(
|
int ReadObjectFromFile( const char* name, const char* hdr, Address start, Address end );
|
||||||
const char *name, const char *hdr, Address start, Address end);
|
int WriteObjectToFile( Address start, Address end, const char* hdr, const char* name );
|
||||||
int WriteObjectToFile(
|
|
||||||
Address start, Address end, const char *hdr, const char *name);
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ static char rcs_id[] = "$Id: disk_io_obj.c,v 4.1 2000/12/11 09:54:19 cibrario Re
|
||||||
#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID
|
#define CHF_MODULE_ID DISK_IO_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ReadObjectFromFile
|
.title : ReadObjectFromFile
|
||||||
|
@ -123,8 +122,7 @@ static char rcs_id[] = "$Id: disk_io_obj.c,v 4.1 2000/12/11 09:54:19 cibrario Re
|
||||||
3.14, 10-Nov-2000, creation
|
3.14, 10-Nov-2000, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
int ReadObjectFromFile(
|
int ReadObjectFromFile( const char* name, const char* hdr, Address start, Address end )
|
||||||
const char *name, const char *hdr, Address start, Address end)
|
|
||||||
{
|
{
|
||||||
size_t hdr_len = strlen( hdr );
|
size_t hdr_len = strlen( hdr );
|
||||||
FILE* f;
|
FILE* f;
|
||||||
|
@ -143,43 +141,35 @@ int ReadObjectFromFile(
|
||||||
for ( cur = start, i = 0; cur < end && i < N_SAVE_AREA; cur++, i++ )
|
for ( cur = start, i = 0; cur < end && i < N_SAVE_AREA; cur++, i++ )
|
||||||
save_area[ i ] = ReadNibble( cur );
|
save_area[ i ] = ReadNibble( cur );
|
||||||
|
|
||||||
if((f = fopen(name, "rb")) == (FILE *)NULL)
|
if ( ( f = fopen( name, "rb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Check and skip header */
|
/* Check and skip header */
|
||||||
for(i=0; i<hdr_len; i++)
|
for ( i = 0; i < hdr_len; i++ ) {
|
||||||
{
|
|
||||||
by = getc( f );
|
by = getc( f );
|
||||||
|
|
||||||
if(by == EOF)
|
if ( by == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(hdr[i] != '?' && by != hdr[i])
|
else if ( hdr[ i ] != '?' && by != hdr[ i ] ) {
|
||||||
{
|
|
||||||
ChfCondition st = DISK_IO_E_BAD_HDR, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_BAD_HDR, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(st == DISK_IO_S_OK)
|
if ( st == DISK_IO_S_OK ) {
|
||||||
{
|
|
||||||
cur = start;
|
cur = start;
|
||||||
|
|
||||||
/* Header check/skip OK; transfer */
|
/* Header check/skip OK; transfer */
|
||||||
while((by = getc(f)) != EOF)
|
while ( ( by = getc( f ) ) != EOF ) {
|
||||||
{
|
|
||||||
/* Next byte available in by; check available space */
|
/* Next byte available in by; check available space */
|
||||||
if(cur >= end-1)
|
if ( cur >= end - 1 ) {
|
||||||
{
|
|
||||||
ChfCondition st = DISK_IO_E_SIZE, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_SIZE, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -190,8 +180,7 @@ int ReadObjectFromFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check why getc() failed */
|
/* Check why getc() failed */
|
||||||
if(ferror(f) && !feof(f))
|
if ( ferror( f ) && !feof( f ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_GETC, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +197,6 @@ int ReadObjectFromFile(
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : WriteObjectToFile
|
.title : WriteObjectToFile
|
||||||
|
@ -242,8 +230,7 @@ int ReadObjectFromFile(
|
||||||
3.14, 10-Nov-2000, creation
|
3.14, 10-Nov-2000, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
int WriteObjectToFile(
|
int WriteObjectToFile( Address start, Address end, const char* hdr, const char* name )
|
||||||
Address start, Address end, const char *hdr, const char *name)
|
|
||||||
{
|
{
|
||||||
size_t hdr_len = strlen( hdr );
|
size_t hdr_len = strlen( hdr );
|
||||||
FILE* f;
|
FILE* f;
|
||||||
|
@ -255,37 +242,30 @@ int WriteObjectToFile(
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteObjectFromFile" );
|
debug1( DEBUG_C_TRACE, DISK_IO_I_CALLED, "WriteObjectFromFile" );
|
||||||
|
|
||||||
if((f = fopen(name, "wb")) == (FILE *)NULL)
|
if ( ( f = fopen( name, "wb" ) ) == ( FILE* )NULL ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_OPEN, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Write header; replace wildcard character '?' with 'S' */
|
/* Write header; replace wildcard character '?' with 'S' */
|
||||||
for(i=0; i<hdr_len; i++)
|
for ( i = 0; i < hdr_len; i++ ) {
|
||||||
{
|
if ( putc( hdr[ i ] == '?' ? 'S' : hdr[ i ], f ) == EOF ) {
|
||||||
if(putc(hdr[i] == '?' ? 'S' : hdr[i], f) == EOF)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(st == DISK_IO_S_OK)
|
if ( st == DISK_IO_S_OK ) {
|
||||||
{
|
|
||||||
cur = start;
|
cur = start;
|
||||||
|
|
||||||
while(cur < end-1)
|
while ( cur < end - 1 ) {
|
||||||
{
|
|
||||||
/* Make a byte with two nibbles */
|
/* Make a byte with two nibbles */
|
||||||
by = ( int )ReadNibble( cur++ );
|
by = ( int )ReadNibble( cur++ );
|
||||||
by |= ( int )ReadNibble( cur++ ) << 4;
|
by |= ( int )ReadNibble( cur++ ) << 4;
|
||||||
|
|
||||||
if(putc(by, f) == EOF)
|
if ( putc( by, f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
||||||
break;
|
break;
|
||||||
|
@ -293,12 +273,10 @@ int WriteObjectToFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the last odd nibble, if necessary */
|
/* Write the last odd nibble, if necessary */
|
||||||
if(st == DISK_IO_S_OK && cur == end-1)
|
if ( st == DISK_IO_S_OK && cur == end - 1 ) {
|
||||||
{
|
|
||||||
by = ( int )ReadNibble( cur++ );
|
by = ( int )ReadNibble( cur++ );
|
||||||
|
|
||||||
if(putc(by, f) == EOF)
|
if ( putc( by, f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_PUTC, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
@ -306,8 +284,7 @@ int WriteObjectToFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the output file anyway */
|
/* Close the output file anyway */
|
||||||
if(fclose(f) == EOF)
|
if ( fclose( f ) == EOF ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
ChfCondition st = DISK_IO_E_CLOSE, CHF_ERROR, name ChfEnd;
|
||||||
}
|
}
|
||||||
|
|
194
src/display.c
194
src/display.c
|
@ -140,13 +140,11 @@ static char rcs_id[] = "$Id: display.c,v 4.1.1.1 2002/11/11 16:12:46 cibrario Ex
|
||||||
#define MASK_ANN_BUSY 0x90
|
#define MASK_ANN_BUSY 0x90
|
||||||
#define MASK_ANN_IO 0xA0
|
#define MASK_ANN_IO 0xA0
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Static/Global variables
|
Static/Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static /*const*/ char nibble_bitmap_data[NIBBLE_VALUES][LCD_MAG] =
|
static /*const*/ char nibble_bitmap_data[ NIBBLE_VALUES ][ LCD_MAG ] = {
|
||||||
{
|
|
||||||
#if LCD_MAG == 1
|
#if LCD_MAG == 1
|
||||||
{ 0x00 }, /* ---- */
|
{ 0x00 }, /* ---- */
|
||||||
{ 0x01 }, /* *--- */
|
{ 0x01 }, /* *--- */
|
||||||
|
@ -186,8 +184,7 @@ static /*const*/ char nibble_bitmap_data[NIBBLE_VALUES][LCD_MAG] =
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static /*const*/ struct
|
static /*const*/ struct {
|
||||||
{
|
|
||||||
int mask; /* Bit mask */
|
int mask; /* Bit mask */
|
||||||
int x, y; /* Position */
|
int x, y; /* Position */
|
||||||
int w, h; /* Width, Height */
|
int w, h; /* Width, Height */
|
||||||
|
@ -197,51 +194,19 @@ static /*const*/ struct
|
||||||
#define ANN_X( i ) ( 8 * LCD_MAG + ( 22 * LCD_MAG + 1 ) * i )
|
#define ANN_X( i ) ( 8 * LCD_MAG + ( 22 * LCD_MAG + 1 ) * i )
|
||||||
#define ANN_Y( i ) ( 1 + 3 * ( LCD_MAG - 1 ) )
|
#define ANN_Y( i ) ( 1 + 3 * ( LCD_MAG - 1 ) )
|
||||||
|
|
||||||
ann_data[N_ANN] =
|
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,
|
||||||
{ MASK_ANN_LEFT,
|
0x03, 0x70, 0xe7, 0x73, 0xcf, 0x73, 0x9f, 0x73, 0xff, 0x73, 0xfe, 0x33 } },
|
||||||
ANN_X(0), ANN_Y(0),
|
{MASK_ANN_RIGHT, ANN_X( 1 ), ANN_Y( 1 ), 15, 12, { 0xfe, 0x3f, 0xff, 0x7f, 0xff, 0x7c, 0xff, 0x79, 0xff, 0x73, 0x0f, 0x60,
|
||||||
15, 12,
|
0x07, 0x60, 0xe7, 0x73, 0xe7, 0x79, 0xe7, 0x7c, 0xe7, 0x7f, 0xe6, 0x3f } },
|
||||||
{ 0xfe, 0x3f, 0xff, 0x7f, 0x9f, 0x7f, 0xcf, 0x7f, 0xe7, 0x7f, 0x03, 0x78,
|
{MASK_ANN_ALPHA, ANN_X( 2 ), ANN_Y( 2 ), 15, 12, { 0xe0, 0x03, 0x18, 0x44, 0x0c, 0x4c, 0x06, 0x2c, 0x07, 0x2c, 0x07, 0x1c,
|
||||||
0x03, 0x70, 0xe7, 0x73, 0xcf, 0x73, 0x9f, 0x73, 0xff, 0x73, 0xfe, 0x33
|
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_RIGHT,
|
{MASK_ANN_BUSY, ANN_X( 4 ), ANN_Y( 4 ), 15, 12, { 0xfc, 0x1f, 0x08, 0x08, 0x08, 0x08, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01,
|
||||||
ANN_X(1), ANN_Y(1),
|
0x40, 0x01, 0x20, 0x02, 0x10, 0x04, 0xc8, 0x09, 0xe8, 0x0b, 0xfc, 0x1f } },
|
||||||
15, 12,
|
{MASK_ANN_IO, ANN_X( 5 ), ANN_Y( 5 ), 15, 12, { 0x0c, 0x00, 0x1e, 0x00, 0x33, 0x0c, 0x61, 0x18, 0xcc, 0x30, 0xfe, 0x7f,
|
||||||
{ 0xfe, 0x3f, 0xff, 0x7f, 0xff, 0x7c, 0xff, 0x79, 0xff, 0x73, 0x0f, 0x60,
|
0xfe, 0x7f, 0xcc, 0x30, 0x61, 0x18, 0x33, 0x0c, 0x1e, 0x00, 0x0c, 0x00 } }
|
||||||
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 ];
|
||||||
|
@ -257,7 +222,6 @@ static unsigned int depth;
|
||||||
static Pixmap nibble_pixmap[ NIBBLE_VALUES ];
|
static Pixmap nibble_pixmap[ NIBBLE_VALUES ];
|
||||||
static Pixmap ann_pixmap[ N_ANN ];
|
static Pixmap ann_pixmap[ N_ANN ];
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -291,37 +255,24 @@ static void InitPixmaps(void)
|
||||||
debug1( DEBUG_C_TRACE, X11_I_CALLED, "InitPixmaps" );
|
debug1( DEBUG_C_TRACE, X11_I_CALLED, "InitPixmaps" );
|
||||||
|
|
||||||
/* Initialize nibble_pixmap */
|
/* Initialize nibble_pixmap */
|
||||||
for(i=0; i<NIBBLE_VALUES; i++)
|
for ( i = 0; i < NIBBLE_VALUES; i++ ) {
|
||||||
{
|
if ( ( nibble_pixmap[ i ] = XCreatePixmapFromBitmapData( display, window, nibble_bitmap_data[ i ], 4 * LCD_MAG, LCD_MAG, fg_pixel,
|
||||||
if((nibble_pixmap[i] =
|
bg_pixel, depth ) ) == None ) {
|
||||||
XCreatePixmapFromBitmapData(
|
|
||||||
display, window, nibble_bitmap_data[i], 4*LCD_MAG, LCD_MAG,
|
|
||||||
fg_pixel, bg_pixel, depth
|
|
||||||
)) ==
|
|
||||||
None)
|
|
||||||
{
|
|
||||||
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize ann_pixmap */
|
/* Initialize ann_pixmap */
|
||||||
for (i=0; i<N_ANN; i++)
|
for ( i = 0; i < N_ANN; i++ ) {
|
||||||
{
|
if ( ( ann_pixmap[ i ] = XCreatePixmapFromBitmapData( display, window, ann_data[ i ].bitmap_data, ann_data[ i ].w, ann_data[ i ].h,
|
||||||
if((ann_pixmap[i] =
|
fg_pixel, bg_pixel, depth ) ) == None ) {
|
||||||
XCreatePixmapFromBitmapData(display, window,
|
|
||||||
ann_data[i].bitmap_data, ann_data[i].w, ann_data[i].h,
|
|
||||||
fg_pixel, bg_pixel, depth
|
|
||||||
)) ==
|
|
||||||
None)
|
|
||||||
{
|
|
||||||
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ClearLcd
|
.title : ClearLcd
|
||||||
|
@ -354,7 +305,6 @@ static void ClearLcd(void)
|
||||||
XFlush( display );
|
XFlush( display );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public funcitons
|
Public funcitons
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -386,8 +336,7 @@ static void ClearLcd(void)
|
||||||
- added clip rectangle to GC, to avoid drawing non-existent pixels.
|
- added clip rectangle to GC, to avoid drawing non-existent pixels.
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void InitLcd(Display *lcd_display, Window lcd_window,
|
void InitLcd( Display* lcd_display, Window lcd_window, unsigned long lcd_fg_pixel, unsigned long lcd_bg_pixel )
|
||||||
unsigned long lcd_fg_pixel, unsigned long lcd_bg_pixel)
|
|
||||||
{
|
{
|
||||||
XWindowAttributes xwa;
|
XWindowAttributes xwa;
|
||||||
XGCValues gc_values;
|
XGCValues gc_values;
|
||||||
|
@ -400,8 +349,7 @@ void InitLcd(Display *lcd_display, Window lcd_window,
|
||||||
bg_pixel = lcd_bg_pixel;
|
bg_pixel = lcd_bg_pixel;
|
||||||
|
|
||||||
/* Get window attributes and initialize window depth */
|
/* Get window attributes and initialize window depth */
|
||||||
if(XGetWindowAttributes(display, window, &xwa) == 0)
|
if ( XGetWindowAttributes( display, window, &xwa ) == 0 ) {
|
||||||
{
|
|
||||||
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
ChfCondition X11_F_X_ERROR, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -416,9 +364,7 @@ void InitLcd(Display *lcd_display, Window lcd_window,
|
||||||
gc_values.background = lcd_bg_pixel;
|
gc_values.background = lcd_bg_pixel;
|
||||||
gc_values.graphics_exposures = False;
|
gc_values.graphics_exposures = False;
|
||||||
|
|
||||||
gc = XCreateGC(display, window,
|
gc = XCreateGC( display, window, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCSubwindowMode | GCGraphicsExposures,
|
||||||
GCFunction|GCPlaneMask|GCForeground|GCBackground|GCSubwindowMode|
|
|
||||||
GCGraphicsExposures,
|
|
||||||
&gc_values );
|
&gc_values );
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -432,9 +378,7 @@ void InitLcd(Display *lcd_display, Window lcd_window,
|
||||||
rect[ 0 ].width = LCD_CLIP_WIDTH;
|
rect[ 0 ].width = LCD_CLIP_WIDTH;
|
||||||
rect[ 0 ].height = LCD_CLIP_HEIGHT;
|
rect[ 0 ].height = LCD_CLIP_HEIGHT;
|
||||||
|
|
||||||
XSetClipRectangles(
|
XSetClipRectangles( display, gc, 0, 0, /* Alsolute clip X,Y origin */
|
||||||
display, gc,
|
|
||||||
0, 0, /* Alsolute clip X,Y origin */
|
|
||||||
rect, 1, YXBanded );
|
rect, 1, YXBanded );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +392,6 @@ void InitLcd(Display *lcd_display, Window lcd_window,
|
||||||
clean = 1;
|
clean = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : DrawLcd
|
.title : DrawLcd
|
||||||
|
@ -482,36 +425,26 @@ void DrawLcd(void)
|
||||||
/* If the debug class DEBUG_C_DISPLAY is enabled, print the display
|
/* If the debug class DEBUG_C_DISPLAY is enabled, print the display
|
||||||
parameters
|
parameters
|
||||||
*/
|
*/
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_base_addr",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_base_addr", ( int )mod_status.hdw.lcd_base_addr );
|
||||||
(int)mod_status.hdw.lcd_base_addr);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_on",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_on", ( int )mod_status.hdw.lcd_on );
|
||||||
(int)mod_status.hdw.lcd_on);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_contrast",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_contrast", ( int )mod_status.hdw.lcd_contrast );
|
||||||
(int)mod_status.hdw.lcd_contrast);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_vlc",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_vlc", ( int )mod_status.hdw.lcd_vlc );
|
||||||
(int)mod_status.hdw.lcd_vlc);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_offset",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_offset", ( int )mod_status.hdw.lcd_offset );
|
||||||
(int)mod_status.hdw.lcd_offset);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_line_offset",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_line_offset", ( int )mod_status.hdw.lcd_line_offset );
|
||||||
(int)mod_status.hdw.lcd_line_offset);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_menu_addr",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_menu_addr", ( int )mod_status.hdw.lcd_menu_addr );
|
||||||
(int)mod_status.hdw.lcd_menu_addr);
|
|
||||||
|
|
||||||
debug2(DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_ann",
|
debug2( DEBUG_C_DISPLAY, X11_I_LCD_PAR, "_ann", ( int )mod_status.hdw.lcd_ann );
|
||||||
(int)mod_status.hdw.lcd_ann);
|
|
||||||
|
|
||||||
/* Check if display is on */
|
/* Check if display is on */
|
||||||
if(!mod_status.hdw.lcd_on)
|
if ( !mod_status.hdw.lcd_on ) {
|
||||||
{
|
|
||||||
/* Display is off; clear lcd if necessary */
|
/* Display is off; clear lcd if necessary */
|
||||||
if(!clean)
|
if ( !clean ) {
|
||||||
{
|
|
||||||
/* Set the 'display is clean' flag and clear the screen */
|
/* Set the 'display is clean' flag and clear the screen */
|
||||||
clean = 1;
|
clean = 1;
|
||||||
ClearLcd();
|
ClearLcd();
|
||||||
|
@ -523,22 +456,16 @@ void DrawLcd(void)
|
||||||
clean = 0;
|
clean = 0;
|
||||||
|
|
||||||
/* Scan active display rows */
|
/* Scan active display rows */
|
||||||
for(y=0; y<=mod_status.hdw.lcd_vlc; y++)
|
for ( y = 0; y <= mod_status.hdw.lcd_vlc; y++ ) {
|
||||||
{
|
|
||||||
/* Scan columns */
|
/* Scan columns */
|
||||||
for(x=0; x<NIBBLES_PER_ROW; x++)
|
for ( x = 0; x < NIBBLES_PER_ROW; x++ ) {
|
||||||
{
|
|
||||||
v = FetchNibble( addr++ );
|
v = FetchNibble( addr++ );
|
||||||
if( v != lcd_buffer[y][x] )
|
if ( v != lcd_buffer[ y ][ x ] ) {
|
||||||
{
|
|
||||||
lcd_buffer[ y ][ x ] = v;
|
lcd_buffer[ y ][ x ] = v;
|
||||||
|
|
||||||
XCopyArea(display, nibble_pixmap[(int)v], window, gc,
|
XCopyArea( display, nibble_pixmap[ ( int )v ], window, gc, 0, 0, /* src_x, src_y */
|
||||||
0, 0, /* src_x, src_y */
|
|
||||||
4 * LCD_MAG, LCD_MAG, /* width, height */
|
4 * LCD_MAG, LCD_MAG, /* width, height */
|
||||||
x*4*LCD_MAG + LCD_X_ORIGIN,
|
x * 4 * LCD_MAG + LCD_X_ORIGIN, y * LCD_MAG + LCD_Y_ORIGIN );
|
||||||
y*LCD_MAG + LCD_Y_ORIGIN
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,48 +474,32 @@ void DrawLcd(void)
|
||||||
|
|
||||||
/* Scan menu display rows */
|
/* Scan menu display rows */
|
||||||
addr = mod_status.hdw.lcd_menu_addr;
|
addr = mod_status.hdw.lcd_menu_addr;
|
||||||
for(; y<MAX_ROWS; y++)
|
for ( ; y < MAX_ROWS; y++ ) {
|
||||||
{
|
|
||||||
/* Scan columns */
|
/* Scan columns */
|
||||||
for(x=0; x<NIBBLES_PER_ROW; x++)
|
for ( x = 0; x < NIBBLES_PER_ROW; x++ ) {
|
||||||
{
|
|
||||||
v = FetchNibble( addr++ );
|
v = FetchNibble( addr++ );
|
||||||
if( v != lcd_buffer[y][x] )
|
if ( v != lcd_buffer[ y ][ x ] ) {
|
||||||
{
|
|
||||||
lcd_buffer[ y ][ x ] = v;
|
lcd_buffer[ y ][ x ] = v;
|
||||||
XCopyArea(display, nibble_pixmap[(int)v], window, gc,
|
XCopyArea( display, nibble_pixmap[ ( int )v ], window, gc, 0, 0, /* src_x, src_y */
|
||||||
0, 0, /* src_x, src_y */
|
|
||||||
4 * LCD_MAG, LCD_MAG, /* width, height */
|
4 * LCD_MAG, LCD_MAG, /* width, height */
|
||||||
x*4*LCD_MAG + LCD_X_ORIGIN,
|
x * 4 * LCD_MAG + LCD_X_ORIGIN, y * LCD_MAG + LCD_Y_ORIGIN );
|
||||||
y*LCD_MAG + LCD_Y_ORIGIN
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scan annunciators */
|
/* Scan annunciators */
|
||||||
if(mod_status.hdw.lcd_ann != ann_buffer)
|
if ( mod_status.hdw.lcd_ann != ann_buffer ) {
|
||||||
{
|
|
||||||
ann_buffer = mod_status.hdw.lcd_ann;
|
ann_buffer = mod_status.hdw.lcd_ann;
|
||||||
|
|
||||||
for(y=0; y<N_ANN; y++)
|
for ( y = 0; y < N_ANN; y++ ) {
|
||||||
{
|
if ( ( ann_buffer & ann_data[ y ].mask ) == ann_data[ y ].mask ) {
|
||||||
if((ann_buffer & ann_data[y].mask) == ann_data[y].mask)
|
XCopyArea( display, ann_pixmap[ y ], window, gc, 0, 0, /* src_x, src_y */
|
||||||
{
|
|
||||||
XCopyArea(display, ann_pixmap[y], window, gc,
|
|
||||||
0, 0, /* src_x, src_y */
|
|
||||||
ann_data[ y ].w, ann_data[ y ].h, /* width, height */
|
ann_data[ y ].w, ann_data[ y ].h, /* width, height */
|
||||||
ann_data[y].x,
|
ann_data[ y ].x, ann_data[ y ].y );
|
||||||
ann_data[y].y
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
XClearArea( display, window, ann_data[ y ].x, ann_data[ y ].y, ann_data[ y ].w, ann_data[ y ].h, False /* No exposures */
|
||||||
XClearArea(display, window,
|
|
||||||
ann_data[y].x, ann_data[y].y,
|
|
||||||
ann_data[y].w, ann_data[y].h,
|
|
||||||
False /* No exposures */
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,7 +509,6 @@ void DrawLcd(void)
|
||||||
XFlush( display );
|
XFlush( display );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RefreshLcd
|
.title : RefreshLcd
|
||||||
|
|
|
@ -66,28 +66,23 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Data type definitions - require config.h, machdep.h, cpu.h
|
Data type definitions - require config.h, machdep.h, cpu.h
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macros
|
Macros
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void InitLcd(Display *lcd_display, Window lcd_window,
|
void InitLcd( Display* lcd_display, Window lcd_window, unsigned long lcd_fg_pixel, unsigned long lcd_bg_pixel );
|
||||||
unsigned long lcd_fg_pixel, unsigned long lcd_bg_pixel);
|
|
||||||
|
|
||||||
void DrawLcd( void );
|
void DrawLcd( void );
|
||||||
void RefreshLcd( void );
|
void RefreshLcd( void );
|
||||||
|
|
143
src/emulator.c
143
src/emulator.c
|
@ -133,7 +133,6 @@ static char rcs_id[] = "$Id: emulator.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $
|
||||||
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private macros / variables / functions
|
Private macros / variables / functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -187,19 +186,16 @@ static void EmulatorLoop(void)
|
||||||
/* Get current time of day */
|
/* Get current time of day */
|
||||||
gettimeofday( &old_t, NULL );
|
gettimeofday( &old_t, NULL );
|
||||||
|
|
||||||
while(1)
|
while ( 1 ) {
|
||||||
{
|
|
||||||
/* T1 loop */
|
/* T1 loop */
|
||||||
for(j=0; j<T1_MULTIPLIER; j++)
|
for ( j = 0; j < T1_MULTIPLIER; j++ ) {
|
||||||
{
|
|
||||||
/* Inner loop */
|
/* Inner loop */
|
||||||
for(i=0; i<inner_loop; i++) OneStep();
|
for ( i = 0; i < inner_loop; i++ )
|
||||||
|
OneStep();
|
||||||
|
|
||||||
/* T2 update */
|
/* T2 update */
|
||||||
if(mod_status.hdw.t2_ctrl & T2_CTRL_TRUN)
|
if ( mod_status.hdw.t2_ctrl & T2_CTRL_TRUN ) {
|
||||||
{
|
if ( --mod_status.hdw.t2_val == 0xFFFFFFFF ) {
|
||||||
if(--mod_status.hdw.t2_val == 0xFFFFFFFF)
|
|
||||||
{
|
|
||||||
debug1( DEBUG_C_TIMERS, CPU_I_TIMER2_EX, mod_status.hdw.t2_ctrl );
|
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;
|
||||||
|
@ -215,8 +211,7 @@ static void EmulatorLoop(void)
|
||||||
|
|
||||||
/* T1 update */
|
/* T1 update */
|
||||||
mod_status.hdw.t1_val = ( mod_status.hdw.t1_val - 1 ) & NIBBLE_MASK;
|
mod_status.hdw.t1_val = ( mod_status.hdw.t1_val - 1 ) & NIBBLE_MASK;
|
||||||
if(mod_status.hdw.t1_val == 0xF)
|
if ( mod_status.hdw.t1_val == 0xF ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_TIMERS, CPU_I_TIMER1_EX, mod_status.hdw.t1_ctrl );
|
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;
|
||||||
|
@ -229,11 +224,11 @@ static void EmulatorLoop(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LCD update */
|
/* LCD update */
|
||||||
if((t1_count++ & LCD_T1_MASK) == 0) DrawLcd();
|
if ( ( t1_count++ & LCD_T1_MASK ) == 0 )
|
||||||
|
DrawLcd();
|
||||||
|
|
||||||
/* Emulator Interrupt Request */
|
/* Emulator Interrupt Request */
|
||||||
if((t1_count & INT_T1_MASK) == 0 && emulator_int_req)
|
if ( ( t1_count & INT_T1_MASK ) == 0 && emulator_int_req ) {
|
||||||
{
|
|
||||||
ChfCondition CPU_I_EMULATOR_INT, CHF_INFO ChfEnd;
|
ChfCondition CPU_I_EMULATOR_INT, CHF_INFO ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -247,11 +242,11 @@ static void EmulatorLoop(void)
|
||||||
/* Adjust inner_loop limit */
|
/* Adjust inner_loop limit */
|
||||||
gettimeofday( &cur_t, NULL );
|
gettimeofday( &cur_t, NULL );
|
||||||
|
|
||||||
ela = (cur_t.tv_sec - old_t.tv_sec) * 1000000 +
|
ela = ( cur_t.tv_sec - old_t.tv_sec ) * 1000000 + ( cur_t.tv_usec - old_t.tv_usec );
|
||||||
(cur_t.tv_usec - old_t.tv_usec);
|
|
||||||
|
|
||||||
inner_loop = inner_loop * T1_INTERVAL / ela;
|
inner_loop = inner_loop * T1_INTERVAL / ela;
|
||||||
if(inner_loop < INNER_LOOP_MIN) inner_loop = INNER_LOOP_MIN;
|
if ( inner_loop < INNER_LOOP_MIN )
|
||||||
|
inner_loop = INNER_LOOP_MIN;
|
||||||
|
|
||||||
#ifdef REAL_CPU_SPEED
|
#ifdef REAL_CPU_SPEED
|
||||||
/* 3.13: Force an upper limit to the CPU speed if the compile-time option
|
/* 3.13: Force an upper limit to the CPU speed if the compile-time option
|
||||||
|
@ -262,11 +257,10 @@ static void EmulatorLoop(void)
|
||||||
well, I hope.
|
well, I hope.
|
||||||
The special value cpu_status.inner_loop_max==0 gives maximum speed.
|
The special value cpu_status.inner_loop_max==0 gives maximum speed.
|
||||||
*/
|
*/
|
||||||
if(cpu_status.inner_loop_max != 0
|
if ( cpu_status.inner_loop_max != 0 && inner_loop >= cpu_status.inner_loop_max ) {
|
||||||
&& inner_loop >= cpu_status.inner_loop_max)
|
|
||||||
{
|
|
||||||
inner_loop = cpu_status.inner_loop_max;
|
inner_loop = cpu_status.inner_loop_max;
|
||||||
if(T1_INTERVAL > ela) usleep(T1_INTERVAL - ela);
|
if ( T1_INTERVAL > ela )
|
||||||
|
usleep( T1_INTERVAL - ela );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -275,27 +269,19 @@ static void EmulatorLoop(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Condition handler for the EmulatorLoop */
|
/* Condition handler for the EmulatorLoop */
|
||||||
static ChfAction EmulatorLoopHandler(
|
static ChfAction EmulatorLoopHandler( const ChfDescriptor* d, const ChfState s, ChfPointer ctx )
|
||||||
const ChfDescriptor *d,
|
|
||||||
const ChfState s,
|
|
||||||
ChfPointer ctx
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfAction act;
|
ChfAction act;
|
||||||
|
|
||||||
/* Check Chf state */
|
/* Check Chf state */
|
||||||
switch(s)
|
switch ( s ) {
|
||||||
{
|
|
||||||
/* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */
|
/* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */
|
||||||
case CHF_SIGNALING:
|
case CHF_SIGNALING:
|
||||||
/* ChfSignal() in progress */
|
/* ChfSignal() in progress */
|
||||||
if(ChfGetModuleId(d) == CPU_CHF_MODULE_ID)
|
if ( ChfGetModuleId( d ) == CPU_CHF_MODULE_ID ) {
|
||||||
{
|
|
||||||
/* Condition from CPU modules; check Condition Code */
|
/* Condition from CPU modules; check Condition Code */
|
||||||
switch(ChfGetConditionCode(d))
|
switch ( ChfGetConditionCode( d ) ) {
|
||||||
{
|
|
||||||
#ifdef CPU_SPIN_SHUTDN
|
#ifdef CPU_SPIN_SHUTDN
|
||||||
case CPU_I_SHUTDN:
|
case CPU_I_SHUTDN:
|
||||||
/* CPU shutdown signalled with CPU_SPIN_SHUTDN defined;
|
/* CPU shutdown signalled with CPU_SPIN_SHUTDN defined;
|
||||||
|
@ -366,8 +352,7 @@ static ChfAction EmulatorLoopHandler(
|
||||||
process it immediately. It is not clear why it was
|
process it immediately. It is not clear why it was
|
||||||
not processed *before* shutdown, though.
|
not processed *before* shutdown, though.
|
||||||
*/
|
*/
|
||||||
if(mod_status.hdw.t1_ctrl & T1_CTRL_SREQ)
|
if ( mod_status.hdw.t1_ctrl & T1_CTRL_SREQ ) {
|
||||||
{
|
|
||||||
if ( mod_status.hdw.t1_ctrl & T1_CTRL_WAKE )
|
if ( mod_status.hdw.t1_ctrl & T1_CTRL_WAKE )
|
||||||
CpuWake();
|
CpuWake();
|
||||||
|
|
||||||
|
@ -375,8 +360,7 @@ static ChfAction EmulatorLoopHandler(
|
||||||
CpuIntRequest( INT_REQUEST_IRQ );
|
CpuIntRequest( INT_REQUEST_IRQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mod_status.hdw.t2_ctrl & T2_CTRL_SREQ)
|
if ( mod_status.hdw.t2_ctrl & T2_CTRL_SREQ ) {
|
||||||
{
|
|
||||||
if ( mod_status.hdw.t2_ctrl & T2_CTRL_WAKE )
|
if ( mod_status.hdw.t2_ctrl & T2_CTRL_WAKE )
|
||||||
CpuWake();
|
CpuWake();
|
||||||
|
|
||||||
|
@ -384,40 +368,37 @@ static ChfAction EmulatorLoopHandler(
|
||||||
CpuIntRequest( INT_REQUEST_IRQ );
|
CpuIntRequest( INT_REQUEST_IRQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
while(cpu_status.shutdn)
|
while ( cpu_status.shutdn ) {
|
||||||
{
|
|
||||||
unsigned long ms = MAX_IDLE_X_LOOP_TIMEOUT;
|
unsigned long ms = MAX_IDLE_X_LOOP_TIMEOUT;
|
||||||
unsigned long mst;
|
unsigned long mst;
|
||||||
int ela;
|
int ela;
|
||||||
int ela_ticks;
|
int ela_ticks;
|
||||||
|
|
||||||
debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (during SHUTDN)",
|
debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (during SHUTDN)", mod_status.hdw.t1_ctrl,
|
||||||
mod_status.hdw.t1_ctrl, mod_status.hdw.t1_val);
|
mod_status.hdw.t1_val );
|
||||||
debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (during SHUTDN)",
|
debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T2 (during SHUTDN)", mod_status.hdw.t2_ctrl,
|
||||||
mod_status.hdw.t2_ctrl, mod_status.hdw.t2_val);
|
mod_status.hdw.t2_val );
|
||||||
|
|
||||||
/* Determine which timer will expire first */
|
/* Determine which timer will expire first */
|
||||||
if(mod_status.hdw.t1_ctrl & (T1_CTRL_INT|T1_CTRL_WAKE))
|
if ( mod_status.hdw.t1_ctrl & ( T1_CTRL_INT | T1_CTRL_WAKE ) ) {
|
||||||
{
|
|
||||||
/* T1 will do something on expiration */
|
/* T1 will do something on expiration */
|
||||||
mst = ((unsigned long)mod_status.hdw.t1_val + 1)
|
mst = ( ( unsigned long )mod_status.hdw.t1_val + 1 ) * T1_MS_MULTIPLIER;
|
||||||
* 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)
|
if ( ( mod_status.hdw.t2_ctrl & T2_CTRL_TRUN ) &&
|
||||||
&& (mod_status.hdw.t2_ctrl & (T2_CTRL_INT|T2_CTRL_WAKE)))
|
( mod_status.hdw.t2_ctrl & ( T2_CTRL_INT | T2_CTRL_WAKE ) ) ) {
|
||||||
{
|
|
||||||
/* T2 is running and will do something on expiration */
|
/* T2 is running and will do something on expiration */
|
||||||
mst = ((unsigned long)mod_status.hdw.t2_val + 1)
|
mst = ( ( unsigned long )mod_status.hdw.t2_val + 1 ) / T2_MS_DIVISOR;
|
||||||
/ 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
|
/* Handle serial port activities at each iteration of
|
||||||
|
@ -437,8 +418,7 @@ static ChfAction EmulatorLoopHandler(
|
||||||
/* End of idle loop; compute actual elapsed time */
|
/* End of idle loop; compute actual elapsed time */
|
||||||
gettimeofday( &end_idle, NULL );
|
gettimeofday( &end_idle, NULL );
|
||||||
|
|
||||||
ela = (end_idle.tv_sec - start_idle.tv_sec) * 1000000 +
|
ela = ( end_idle.tv_sec - start_idle.tv_sec ) * 1000000 + ( end_idle.tv_usec - start_idle.tv_usec );
|
||||||
(end_idle.tv_usec - start_idle.tv_usec);
|
|
||||||
|
|
||||||
/* Update start_idle here to contain lag */
|
/* Update start_idle here to contain lag */
|
||||||
start_idle = end_idle;
|
start_idle = end_idle;
|
||||||
|
@ -449,10 +429,8 @@ static ChfAction EmulatorLoopHandler(
|
||||||
ela_ticks = ( ( ela + frac_t1 ) + T1_INTERVAL / 2 ) / T1_INTERVAL;
|
ela_ticks = ( ( ela + frac_t1 ) + T1_INTERVAL / 2 ) / T1_INTERVAL;
|
||||||
frac_t1 = ( ela + frac_t1 ) - ela_ticks * T1_INTERVAL;
|
frac_t1 = ( ela + frac_t1 ) - ela_ticks * T1_INTERVAL;
|
||||||
|
|
||||||
if(ela_ticks > mod_status.hdw.t1_val)
|
if ( ela_ticks > mod_status.hdw.t1_val ) {
|
||||||
{
|
debug1( DEBUG_C_TIMERS, CPU_I_TIMER1_EX, mod_status.hdw.t1_ctrl );
|
||||||
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;
|
||||||
|
|
||||||
|
@ -463,18 +441,14 @@ static ChfAction EmulatorLoopHandler(
|
||||||
CpuIntRequest( INT_REQUEST_IRQ );
|
CpuIntRequest( INT_REQUEST_IRQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_status.hdw.t1_val =
|
mod_status.hdw.t1_val = ( mod_status.hdw.t1_val - ela_ticks ) & T1_OVF_MASK;
|
||||||
(mod_status.hdw.t1_val - ela_ticks) & T1_OVF_MASK;
|
|
||||||
|
|
||||||
if(mod_status.hdw.t2_ctrl & T2_CTRL_TRUN)
|
if ( mod_status.hdw.t2_ctrl & T2_CTRL_TRUN ) {
|
||||||
{
|
|
||||||
ela_ticks = ( ( ela + frac_t2 ) + T2_INTERVAL / 2 ) / T2_INTERVAL;
|
ela_ticks = ( ( ela + frac_t2 ) + T2_INTERVAL / 2 ) / T2_INTERVAL;
|
||||||
frac_t2 = ( ela + frac_t2 ) - ela_ticks * T2_INTERVAL;
|
frac_t2 = ( ela + frac_t2 ) - ela_ticks * T2_INTERVAL;
|
||||||
|
|
||||||
if(ela_ticks > mod_status.hdw.t2_val)
|
if ( ela_ticks > mod_status.hdw.t2_val ) {
|
||||||
{
|
debug1( DEBUG_C_TIMERS, CPU_I_TIMER2_EX, mod_status.hdw.t2_ctrl );
|
||||||
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;
|
||||||
|
|
||||||
|
@ -485,15 +459,12 @@ static ChfAction EmulatorLoopHandler(
|
||||||
CpuIntRequest( INT_REQUEST_IRQ );
|
CpuIntRequest( INT_REQUEST_IRQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_status.hdw.t2_val =
|
mod_status.hdw.t2_val = ( mod_status.hdw.t2_val - ela_ticks ) & T2_OVF_MASK;
|
||||||
(mod_status.hdw.t2_val - ela_ticks) & T2_OVF_MASK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug3(DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (after SHUTDN)",
|
debug3( DEBUG_C_TIMERS, CPU_I_TIMER_ST, "T1 (after SHUTDN)", mod_status.hdw.t1_ctrl, mod_status.hdw.t1_val );
|
||||||
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, "T2 (after SHUTDN)",
|
|
||||||
mod_status.hdw.t2_ctrl, mod_status.hdw.t2_val);
|
|
||||||
|
|
||||||
act = CHF_CONTINUE;
|
act = CHF_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -526,12 +497,10 @@ static ChfAction EmulatorLoopHandler(
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Emulator
|
.title : Emulator
|
||||||
|
@ -568,8 +537,7 @@ void Emulator(void)
|
||||||
debug1( DEBUG_C_TRACE, CPU_I_CALLED, "Emulator" );
|
debug1( DEBUG_C_TRACE, CPU_I_CALLED, "Emulator" );
|
||||||
|
|
||||||
/* Setup unwind_context */
|
/* Setup unwind_context */
|
||||||
if(setjmp(unwind_context) == 0)
|
if ( setjmp( unwind_context ) == 0 ) {
|
||||||
{
|
|
||||||
/* Push condition handler, with NULL context */
|
/* Push condition handler, with NULL context */
|
||||||
ChfPushHandler( EmulatorLoopHandler, &unwind_context, ( ChfPointer )NULL );
|
ChfPushHandler( EmulatorLoopHandler, &unwind_context, ( ChfPointer )NULL );
|
||||||
|
|
||||||
|
@ -577,13 +545,11 @@ void Emulator(void)
|
||||||
EmulatorLoop();
|
EmulatorLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Unwinding after an emulator interrupt */
|
/* Unwinding after an emulator interrupt */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : EmulatorIntRequest
|
.title : EmulatorIntRequest
|
||||||
|
@ -606,11 +572,7 @@ void Emulator(void)
|
||||||
1.1, 18-Feb-1998, creation
|
1.1, 18-Feb-1998, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void EmulatorIntRequest(void)
|
void EmulatorIntRequest( void ) { emulator_int_req = 1; }
|
||||||
{
|
|
||||||
emulator_int_req = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
|
@ -652,14 +614,12 @@ void EmulatorInit(void)
|
||||||
ModInit();
|
ModInit();
|
||||||
|
|
||||||
/* Reset if appropriate */
|
/* Reset if appropriate */
|
||||||
if(args.reset)
|
if ( args.reset ) {
|
||||||
{
|
|
||||||
CpuReset();
|
CpuReset();
|
||||||
ModReset();
|
ModReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : EmulatorExit
|
.title : EmulatorExit
|
||||||
|
@ -685,8 +645,7 @@ void EmulatorInit(void)
|
||||||
.- */
|
.- */
|
||||||
void EmulatorExit( enum ExitOption opt )
|
void EmulatorExit( enum ExitOption opt )
|
||||||
{
|
{
|
||||||
switch(opt)
|
switch ( opt ) {
|
||||||
{
|
|
||||||
|
|
||||||
case SAVE_AND_EXIT:
|
case SAVE_AND_EXIT:
|
||||||
/* Save state of cpu and modules subsystems */
|
/* Save state of cpu and modules subsystems */
|
||||||
|
|
120
src/flash49.c
120
src/flash49.c
|
@ -90,8 +90,6 @@ static char rcs_id[] = "$Id: flash49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
#define CHF_MODULE_ID FLASH_CHF_MODULE_ID
|
#define CHF_MODULE_ID FLASH_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private Macro/Data type definitions
|
Private Macro/Data type definitions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -107,10 +105,8 @@ static char rcs_id[] = "$Id: flash49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
#define HighNibble( d ) ( ( Nibble )( ( ( d ) >> 4 ) & NIBBLE_MASK ) )
|
#define HighNibble( d ) ( ( Nibble )( ( ( d ) >> 4 ) & NIBBLE_MASK ) )
|
||||||
#define ShiftHigh( d ) ( ( d ) << 4 )
|
#define ShiftHigh( d ) ( ( d ) << 4 )
|
||||||
|
|
||||||
|
|
||||||
/* Flash cycle types */
|
/* Flash cycle types */
|
||||||
enum FlashCycle
|
enum FlashCycle {
|
||||||
{
|
|
||||||
FLASH_CYCLE_READ = 0,
|
FLASH_CYCLE_READ = 0,
|
||||||
FLASH_CYCLE_WRITE,
|
FLASH_CYCLE_WRITE,
|
||||||
|
|
||||||
|
@ -118,11 +114,7 @@ enum FlashCycle
|
||||||
};
|
};
|
||||||
|
|
||||||
/* State transition function */
|
/* State transition function */
|
||||||
typedef int (*FlashF)
|
typedef int ( *FlashF )( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data );
|
||||||
(enum FlashState *state, enum FlashCycle cycle,
|
|
||||||
XAddress address, int data);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private state variables
|
Private state variables
|
||||||
|
@ -143,45 +135,32 @@ static int wb_cdown; /* Count down */
|
||||||
static XAddress wb_start; /* Start address for Write to Buffer */
|
static XAddress wb_start; /* Start address for Write to Buffer */
|
||||||
static int wb[ WB_SIZE ]; /* Write buffer */
|
static int wb[ WB_SIZE ]; /* Write buffer */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
State transition private functions
|
State transition private functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* This function is called by default for unhandled state transitions */
|
/* This function is called by default for unhandled state transitions */
|
||||||
static int BadCommand(enum FlashState *state, enum FlashCycle cycle,
|
static int BadCommand( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
/* Unknown command: signal and reset state to FLASH_ST_READ_ARRAY */
|
/* Unknown command: signal and reset state to FLASH_ST_READ_ARRAY */
|
||||||
ChfCondition FLASH_W_BAD_CMD, CHF_WARNING,
|
ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, *state, cycle, address, data ChfEnd;
|
||||||
*state, cycle, address, data
|
|
||||||
ChfEnd;
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
*state = FLASH_ST_READ_ARRAY;
|
*state = FLASH_ST_READ_ARRAY;
|
||||||
return 0; /* Dummy result */
|
return 0; /* Dummy result */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function is called to read the Flash Rom array */
|
/* This function is called to read the Flash Rom array */
|
||||||
static int ReadArray(enum FlashState *state, enum FlashCycle cycle,
|
static int ReadArray( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
/* Read a byte from the array; no state transitions */
|
/* Read a byte from the array; no state transitions */
|
||||||
return
|
return mod_status_49->flash[ NibbleAddress( address ) ] | ShiftHigh( mod_status_49->flash[ NibbleAddress( address ) + 1 ] );
|
||||||
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 */
|
/* This function is called to parse the first byte of any command */
|
||||||
static int ParseCommand(enum FlashState *state, enum FlashCycle cycle,
|
static int ParseCommand( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
|
||||||
switch(data)
|
|
||||||
{
|
{
|
||||||
|
switch ( data ) {
|
||||||
case FLASH_CMD_READ_ARRAY:
|
case FLASH_CMD_READ_ARRAY:
|
||||||
/* Transition to FLASH_ST_READ_ARRAY state */
|
/* Transition to FLASH_ST_READ_ARRAY state */
|
||||||
debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Array" );
|
debug1( DEBUG_C_FLASH, FLASH_I_FSM_OP, "Read Array" );
|
||||||
|
@ -223,9 +202,7 @@ static int ParseCommand(enum FlashState *state, enum FlashCycle cycle,
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Unknown command; signal, ignore, keep current state. */
|
/* Unknown command; signal, ignore, keep current state. */
|
||||||
ChfCondition FLASH_W_BAD_CMD, CHF_WARNING,
|
ChfCondition FLASH_W_BAD_CMD, CHF_WARNING, *state, cycle, address, data ChfEnd;
|
||||||
*state, cycle, address, data
|
|
||||||
ChfEnd;
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -233,10 +210,8 @@ static int ParseCommand(enum FlashState *state, enum FlashCycle cycle,
|
||||||
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 */
|
/* This function returns to the caller the value of XSR */
|
||||||
static int ReadXSR(enum FlashState *state, enum FlashCycle cycle,
|
static int ReadXSR( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
/* Return XSR status; a buffer is always available in the current
|
/* Return XSR status; a buffer is always available in the current
|
||||||
emulation scheme. Keep current state.
|
emulation scheme. Keep current state.
|
||||||
|
@ -245,10 +220,8 @@ static int ReadXSR(enum FlashState *state, enum FlashCycle cycle,
|
||||||
return FLASH_XSR_WBS;
|
return FLASH_XSR_WBS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function returns to the caller the value of SR */
|
/* This function returns to the caller the value of SR */
|
||||||
static int ReadSR(enum FlashState *state, enum FlashCycle cycle,
|
static int ReadSR( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
/* Return SR status; the WSM executes in zero time in the current
|
/* Return SR status; the WSM executes in zero time in the current
|
||||||
emulation scheme. Keep current state.
|
emulation scheme. Keep current state.
|
||||||
|
@ -257,14 +230,12 @@ static int ReadSR(enum FlashState *state, enum FlashCycle cycle,
|
||||||
return FLASH_SR_WSMS;
|
return FLASH_SR_WSMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function is called to store the WRITE_BUFFER byte count;
|
/* This function is called to store the WRITE_BUFFER byte count;
|
||||||
both wb_count and wb_cdown are set; StoreData() decrements the
|
both wb_count and wb_cdown are set; StoreData() decrements the
|
||||||
latter, WriteConfirm() uses the former to determine how many bytes
|
latter, WriteConfirm() uses the former to determine how many bytes
|
||||||
must write to the Flash array.
|
must write to the Flash array.
|
||||||
*/
|
*/
|
||||||
static int StoreCount(enum FlashState *state, enum FlashCycle cycle,
|
static int StoreCount( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
/* Store WRITE_BUFFER count; next state is FLASH_ST_WRITE_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)" );
|
||||||
|
@ -274,14 +245,12 @@ static int StoreCount(enum FlashState *state, enum FlashCycle cycle,
|
||||||
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.
|
/* 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 first write cycle also sets the buffer's base address (wb_start).
|
||||||
The function transitions to state FLASH_ST_WRITE_CONFIRM when all
|
The function transitions to state FLASH_ST_WRITE_CONFIRM when all
|
||||||
bytes have been stored.
|
bytes have been stored.
|
||||||
*/
|
*/
|
||||||
static int StoreData(enum FlashState *state, enum FlashCycle cycle,
|
static int StoreData( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
XAddress address, int data)
|
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -290,8 +259,7 @@ static int StoreData(enum FlashState *state, enum FlashCycle cycle,
|
||||||
/* Store WRITE_BUFFER data; the first write also stores the
|
/* Store WRITE_BUFFER data; the first write also stores the
|
||||||
buffer starting address.
|
buffer starting address.
|
||||||
*/
|
*/
|
||||||
switch(*state)
|
switch ( *state ) {
|
||||||
{
|
|
||||||
|
|
||||||
case FLASH_ST_WRITE_DATA_1:
|
case FLASH_ST_WRITE_DATA_1:
|
||||||
wb_start = address;
|
wb_start = address;
|
||||||
|
@ -301,14 +269,10 @@ static int StoreData(enum FlashState *state, enum FlashCycle cycle,
|
||||||
|
|
||||||
case FLASH_ST_WRITE_DATA_N:
|
case FLASH_ST_WRITE_DATA_N:
|
||||||
index = address - wb_start;
|
index = address - wb_start;
|
||||||
if(index < 0 || index >= WB_SIZE)
|
if ( index < 0 || index >= WB_SIZE ) {
|
||||||
{
|
ChfCondition FLASH_W_BAD_ADDRESS, CHF_WARNING, *state, cycle, address, data ChfEnd;
|
||||||
ChfCondition FLASH_W_BAD_ADDRESS, CHF_WARNING,
|
|
||||||
*state, cycle, address, data
|
|
||||||
ChfEnd;
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
wb[ index ] = data;
|
wb[ index ] = data;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -323,31 +287,25 @@ static int StoreData(enum FlashState *state, enum FlashCycle cycle,
|
||||||
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
|
/* This function expects a Write to Buffer confirmation command
|
||||||
(FLASH_CMD_WRITE_BUFFER_2); if it is received, the write buffer
|
(FLASH_CMD_WRITE_BUFFER_2); if it is received, the write buffer
|
||||||
is copied into the Flash Rom array, otherwise the write cycle is
|
is copied into the Flash Rom array, otherwise the write cycle is
|
||||||
aborted. In both cases, the new state is FLASH_ST_READ_ARRAY.
|
aborted. In both cases, the new state is FLASH_ST_READ_ARRAY.
|
||||||
*/
|
*/
|
||||||
static int WriteConfirm(enum FlashState *state, enum FlashCycle cycle,
|
static int WriteConfirm( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
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 */
|
/* Expect Write to Buffer confirmation code */
|
||||||
if(data == FLASH_CMD_WRITE_BUFFER_2)
|
if ( data == FLASH_CMD_WRITE_BUFFER_2 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Confirmation OK; write.
|
/* Confirmation OK; write.
|
||||||
Remember that wb_count is the byte count MINUS 1.
|
Remember that wb_count is the byte count MINUS 1.
|
||||||
*/
|
*/
|
||||||
for(i=0; i<=wb_count; i++)
|
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)]
|
mod_status_49->flash[ NibbleAddress( wb_start + i ) + 1 ] = HighNibble( wb[ i ] );
|
||||||
= LowNibble(wb[i]);
|
|
||||||
mod_status_49->flash[NibbleAddress(wb_start+i)+1]
|
|
||||||
= HighNibble(wb[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,30 +313,24 @@ static int WriteConfirm(enum FlashState *state, enum FlashCycle cycle,
|
||||||
return 0; /* No result */
|
return 0; /* No result */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* If the FLASH_CMD_BL_ERASE_2 command is received, this function erases
|
/* If the FLASH_CMD_BL_ERASE_2 command is received, this function erases
|
||||||
the block pointed by the current address; otherwise the block erase
|
the block pointed by the current address; otherwise the block erase
|
||||||
operation is aborted.
|
operation is aborted.
|
||||||
In both cases, the new state is FLASH_ST_READ_SR.
|
In both cases, the new state is FLASH_ST_READ_SR.
|
||||||
*/
|
*/
|
||||||
static int BlockErase(enum FlashState *state, enum FlashCycle cycle,
|
static int BlockErase( enum FlashState* state, enum FlashCycle cycle, XAddress address, int data )
|
||||||
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 */
|
/* Expect Write to Buffer confirmation code */
|
||||||
if(data == FLASH_CMD_BL_ERASE_2)
|
if ( data == FLASH_CMD_BL_ERASE_2 ) {
|
||||||
{
|
|
||||||
XAddress block_base = BlockBase( address );
|
XAddress block_base = BlockBase( address );
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Confirmation OK; erase */
|
/* Confirmation OK; erase */
|
||||||
for(i=0; i<BLOCK_SIZE; i++)
|
for ( i = 0; i < BLOCK_SIZE; i++ ) {
|
||||||
{
|
mod_status_49->flash[ NibbleAddress( block_base + i ) ] = ( Nibble )0xF;
|
||||||
mod_status_49->flash[
|
mod_status_49->flash[ NibbleAddress( block_base + i ) + 1 ] = ( Nibble )0xF;
|
||||||
NibbleAddress(block_base+i)] = (Nibble)0xF;
|
|
||||||
mod_status_49->flash[
|
|
||||||
NibbleAddress(block_base+i)+1] = (Nibble)0xF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,16 +338,13 @@ static int BlockErase(enum FlashState *state, enum FlashCycle cycle,
|
||||||
return 0; /* No result */
|
return 0; /* No result */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
FSM state diagram; two-dimensional array of FlashF; each function
|
FSM state diagram; two-dimensional array of FlashF; each function
|
||||||
is invoked when the FSM is in a given state (first index), and
|
is invoked when the FSM is in a given state (first index), and
|
||||||
a particular cycle (second index) is requested.
|
a particular cycle (second index) is requested.
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static FlashF F[FLASH_ST_N][FLASH_CYCLE_N] =
|
static FlashF F[ FLASH_ST_N ][ FLASH_CYCLE_N ] = {
|
||||||
{
|
|
||||||
{ReadArray, ParseCommand}, /* FLASH_ST_READ_ARRAY */
|
{ReadArray, ParseCommand}, /* FLASH_ST_READ_ARRAY */
|
||||||
{ReadSR, ParseCommand}, /* FLASH_ST_READ_SR */
|
{ReadSR, ParseCommand}, /* FLASH_ST_READ_SR */
|
||||||
{ReadXSR, StoreCount }, /* FLASH_ST_READ_XSR */
|
{ReadXSR, StoreCount }, /* FLASH_ST_READ_XSR */
|
||||||
|
@ -405,8 +354,6 @@ static FlashF F[FLASH_ST_N][FLASH_CYCLE_N] =
|
||||||
{BadCommand, BlockErase } /* FLASH_ST_BL_ERASE */
|
{BadCommand, BlockErase } /* FLASH_ST_BL_ERASE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Other private functions
|
Other private functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -428,12 +375,10 @@ static int FSM(enum FlashCycle cycle, XAddress address, int data)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : FlashRead49
|
.title : FlashRead49
|
||||||
|
@ -468,20 +413,17 @@ Nibble FlashRead49(XAddress address)
|
||||||
/* Odd address, return buffered data from previous read */
|
/* Odd address, return buffered data from previous read */
|
||||||
result = HighNibble( r_buffer );
|
result = HighNibble( r_buffer );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Even address, invoke FSM */
|
/* Even address, invoke FSM */
|
||||||
r_buffer = FSM( FLASH_CYCLE_READ, ByteAddress( address ), 0 );
|
r_buffer = FSM( FLASH_CYCLE_READ, ByteAddress( address ), 0 );
|
||||||
result = LowNibble( r_buffer );
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : FlashWrite49
|
.title : FlashWrite49
|
||||||
|
@ -515,11 +457,9 @@ void FlashWrite49(XAddress address, Nibble datum)
|
||||||
|
|
||||||
if ( IsOdd( address ) )
|
if ( IsOdd( address ) )
|
||||||
/* Odd address, invoke FSM; ignore result */
|
/* Odd address, invoke FSM; ignore result */
|
||||||
FSM(FLASH_CYCLE_WRITE, ByteAddress(address),
|
FSM( FLASH_CYCLE_WRITE, ByteAddress( address ), w_buffer | ShiftHigh( datum ) );
|
||||||
w_buffer|ShiftHigh(datum));
|
|
||||||
|
|
||||||
else
|
else
|
||||||
/* Even address, buffer datum */
|
/* Even address, buffer datum */
|
||||||
w_buffer = datum;
|
w_buffer = datum;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
/* +-+ */
|
/* +-+ */
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.identifier : $Id: flash49.h,v 4.1 2000/12/11 09:54:19 cibrario Rel $
|
.identifier : $Id: flash49.h,v 4.1 2000/12/11 09:54:19 cibrario Rel $
|
||||||
|
@ -72,14 +71,12 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
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.
|
/* Command Set Definitions, Table 3 on Data Sheet.
|
||||||
Both BCS and SCS commands are listed here; commands marked with
|
Both BCS and SCS commands are listed here; commands marked with
|
||||||
(*) are not implemented.
|
(*) are not implemented.
|
||||||
|
@ -106,7 +103,6 @@
|
||||||
#define FLASH_CMD_CHIP_ERASE 0x30 /* SCS (*) */
|
#define FLASH_CMD_CHIP_ERASE 0x30 /* SCS (*) */
|
||||||
#define FLASH_CMD_CHIP_ERASE_2 0xD0
|
#define FLASH_CMD_CHIP_ERASE_2 0xD0
|
||||||
|
|
||||||
|
|
||||||
/* Status Register bit masks, Table 15 on Data Sheet
|
/* Status Register bit masks, Table 15 on Data Sheet
|
||||||
*/
|
*/
|
||||||
#define FLASH_SR_WSMS 0x80 /* WSM state, 0=busy, 1=ready */
|
#define FLASH_SR_WSMS 0x80 /* WSM state, 0=busy, 1=ready */
|
||||||
|
@ -117,17 +113,14 @@
|
||||||
#define FLASH_SR_BWSS 0x04 /* Program suspend, 1=suspended */
|
#define FLASH_SR_BWSS 0x04 /* Program suspend, 1=suspended */
|
||||||
#define FLASH_SR_DPS 0x02 /* 1=Lock encountered */
|
#define FLASH_SR_DPS 0x02 /* 1=Lock encountered */
|
||||||
|
|
||||||
|
|
||||||
/* Extended Status Register bit masks, Table 16 on Data Sheet
|
/* Extended Status Register bit masks, Table 16 on Data Sheet
|
||||||
*/
|
*/
|
||||||
#define FLASH_XSR_WBS 0x80 /* Write buffer status 1=available */
|
#define FLASH_XSR_WBS 0x80 /* Write buffer status 1=available */
|
||||||
|
|
||||||
|
|
||||||
/* State of the Flash FSM, derived from command descriptions on
|
/* State of the Flash FSM, derived from command descriptions on
|
||||||
pages 16...28 and from flowcharts on Figure 6...12 of Data Sheet
|
pages 16...28 and from flowcharts on Figure 6...12 of Data Sheet
|
||||||
*/
|
*/
|
||||||
enum FlashState
|
enum FlashState {
|
||||||
{
|
|
||||||
FLASH_ST_READ_ARRAY = 0, /* Read Array after CMD_READ_ARRAY */
|
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_SR, /* Read Status Reg. after CMD_READ_SR */
|
||||||
FLASH_ST_READ_XSR, /* Read XSR after CMD_WRITE_BUFFER */
|
FLASH_ST_READ_XSR, /* Read XSR after CMD_WRITE_BUFFER */
|
||||||
|
@ -138,7 +131,6 @@ enum FlashState
|
||||||
FLASH_ST_N /* Total # of FSM states */
|
FLASH_ST_N /* Total # of FSM states */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -154,7 +146,6 @@ enum FlashState
|
||||||
#define FLASH_E_xxx 301
|
#define FLASH_E_xxx 301
|
||||||
#define FLASH_F_xxx 401
|
#define FLASH_F_xxx 401
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
32
src/hdw.c
32
src/hdw.c
|
@ -123,13 +123,9 @@ static char rcs_id[] = "$Id: hdw.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
static const int addr_mask[] = { 0x0000F, 0x000F0, 0x00F00, 0x0F000, 0xF0000 };
|
static const int addr_mask[] = { 0x0000F, 0x000F0, 0x00F00, 0x0F000, 0xF0000 };
|
||||||
|
|
||||||
static const int32 int32_mask[] =
|
static const int32 int32_mask[] = { 0x0000000F, 0x000000F0, 0x00000F00, 0x0000F000, 0x000F0000, 0x00F00000, 0x0F000000, 0xF0000000 };
|
||||||
{ 0x0000000F, 0x000000F0, 0x00000F00, 0x0000F000,
|
|
||||||
0x000F0000, 0x00F00000, 0x0F000000, 0xF0000000 };
|
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
|
@ -159,9 +155,7 @@ 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),
|
if ( ReadStructFromFile( args.hdw_file_name, sizeof( mod_status.hdw ), &mod_status.hdw ) ) {
|
||||||
&mod_status.hdw))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_W_HDW_INIT, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_HDW_INIT, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
|
@ -169,7 +163,6 @@ void HdwInit(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : HdwSave
|
.title : HdwSave
|
||||||
|
@ -196,15 +189,12 @@ 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),
|
if ( WriteStructToFile( &mod_status.hdw, sizeof( mod_status.hdw ), args.hdw_file_name ) ) {
|
||||||
args.hdw_file_name))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_E_HDW_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_HDW_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : HdwRead
|
.title : HdwRead
|
||||||
|
@ -241,8 +231,7 @@ Nibble HdwRead(Address rel_address)
|
||||||
simply put a break in the case, otherwise code any special action for
|
simply put a break in the case, otherwise code any special action for
|
||||||
the register and end the case with a return.
|
the register and end the case with a return.
|
||||||
*/
|
*/
|
||||||
switch(rel_address)
|
switch ( rel_address ) {
|
||||||
{
|
|
||||||
case 0x00: /* LCD driver registers */
|
case 0x00: /* LCD driver registers */
|
||||||
case 0x01:
|
case 0x01:
|
||||||
case 0x02:
|
case 0x02:
|
||||||
|
@ -342,8 +331,7 @@ Nibble HdwRead(Address rel_address)
|
||||||
case 0x3D:
|
case 0x3D:
|
||||||
case 0x3E:
|
case 0x3E:
|
||||||
case 0x3F:
|
case 0x3F:
|
||||||
return
|
return ( Nibble )( ( mod_status.hdw.t2_val >> ( ( rel_address - 0x38 ) * 4 ) ) & 0x0F );
|
||||||
(Nibble)((mod_status.hdw.t2_val >> ((rel_address-0x38)*4)) & 0x0F);
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ChfCondition MOD_W_HDW_READ, CHF_WARNING, rel_address ChfEnd;
|
ChfCondition MOD_W_HDW_READ, CHF_WARNING, rel_address ChfEnd;
|
||||||
|
@ -355,7 +343,6 @@ Nibble HdwRead(Address rel_address)
|
||||||
return mod_status.hdw.hdw[ rel_address ];
|
return mod_status.hdw.hdw[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : HdwWrite
|
.title : HdwWrite
|
||||||
|
@ -389,8 +376,7 @@ void HdwWrite(Address rel_address, Nibble data)
|
||||||
the switch, instead, simply takes care to shadow the hdw register into
|
the switch, instead, simply takes care to shadow the hdw register into
|
||||||
the mod_status.hdw.hdw[] array
|
the mod_status.hdw.hdw[] array
|
||||||
*/
|
*/
|
||||||
switch(rel_address)
|
switch ( rel_address ) {
|
||||||
{
|
|
||||||
case 0x00: /* LCD horizontal offset, LCD enable flag */
|
case 0x00: /* LCD horizontal offset, LCD enable flag */
|
||||||
mod_status.hdw.lcd_offset = ( int )data & 0x07;
|
mod_status.hdw.lcd_offset = ( int )data & 0x07;
|
||||||
mod_status.hdw.lcd_on = ( ( data & 0x08 ) != 0 );
|
mod_status.hdw.lcd_on = ( ( data & 0x08 ) != 0 );
|
||||||
|
@ -465,13 +451,11 @@ void HdwWrite(Address rel_address, Nibble data)
|
||||||
when the MS nibble is written; serial_tbr buffers the LS nibble.
|
when the MS nibble is written; serial_tbr buffers the LS nibble.
|
||||||
*/
|
*/
|
||||||
case 0x16:
|
case 0x16:
|
||||||
mod_status.hdw.serial_tbr =
|
mod_status.hdw.serial_tbr = ( mod_status.hdw.serial_tbr & 0xF0 ) | ( int8 )data;
|
||||||
(mod_status.hdw.serial_tbr & 0xF0) | (int8)data;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x17:
|
case 0x17:
|
||||||
mod_status.hdw.serial_tbr =
|
mod_status.hdw.serial_tbr = ( mod_status.hdw.serial_tbr & 0x0F ) | ( ( int8 )data << 4 );
|
||||||
(mod_status.hdw.serial_tbr & 0x0F) | ((int8)data << 4);
|
|
||||||
Serial_TBR_Write( mod_status.hdw.serial_tbr );
|
Serial_TBR_Write( mod_status.hdw.serial_tbr );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
201
src/hw_config.c
201
src/hw_config.c
|
@ -90,7 +90,6 @@ static char rcs_id[] = "$Id: hw_config.c,v 4.1 2000/12/11 09:54:19 cibrario Rel
|
||||||
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Module description tables
|
Module description tables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -151,8 +150,7 @@ extern void Ce1Write49(Address, Nibble);
|
||||||
extern void Ce2Write49( Address, Nibble );
|
extern void Ce2Write49( Address, Nibble );
|
||||||
extern void NCe3Write49( Address, Nibble );
|
extern void NCe3Write49( Address, Nibble );
|
||||||
|
|
||||||
static const struct
|
static const struct {
|
||||||
{
|
|
||||||
const char* hw;
|
const char* hw;
|
||||||
ModDescription description;
|
ModDescription description;
|
||||||
}
|
}
|
||||||
|
@ -165,116 +163,181 @@ table[] =
|
||||||
HP48
|
HP48
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
{
|
{"hp48",
|
||||||
"hp48",
|
|
||||||
|
|
||||||
{
|
{ /* name, id, access_prio,
|
||||||
/* name, id, access_prio,
|
|
||||||
init, save,
|
init, save,
|
||||||
read, write,
|
read, write,
|
||||||
r_config, r_abs_base_addr, r_size,
|
r_config, r_abs_base_addr, r_size,
|
||||||
map_flags
|
map_flags
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{ "ROM (ROM)", 0x00, 0,
|
{
|
||||||
RomInit, RomSave,
|
"ROM (ROM)",
|
||||||
RomRead, RomWrite,
|
0x00,
|
||||||
MOD_CONFIGURED, 0x00000, 0xFFFFF,
|
0,
|
||||||
|
RomInit,
|
||||||
|
RomSave,
|
||||||
|
RomRead,
|
||||||
|
RomWrite,
|
||||||
|
MOD_CONFIGURED,
|
||||||
|
0x00000,
|
||||||
|
0xFFFFF,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Hardware Regs. (HDW)", 0x19, 5,
|
{
|
||||||
HdwInit, HdwSave,
|
"Hardware Regs. (HDW)",
|
||||||
HdwRead, HdwWrite,
|
0x19,
|
||||||
MOD_SIZE_CONFIGURED, 0x00000, 0x00040,
|
5,
|
||||||
|
HdwInit,
|
||||||
|
HdwSave,
|
||||||
|
HdwRead,
|
||||||
|
HdwWrite,
|
||||||
|
MOD_SIZE_CONFIGURED,
|
||||||
|
0x00000,
|
||||||
|
0x00040,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Internal RAM (RAM)", 0x03, 4,
|
{
|
||||||
RamInit, RamSave,
|
"Internal RAM (RAM)",
|
||||||
RamRead, RamWrite,
|
0x03,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
4,
|
||||||
|
RamInit,
|
||||||
|
RamSave,
|
||||||
|
RamRead,
|
||||||
|
RamWrite,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Bank Select (CE1)", 0x05, 2,
|
{
|
||||||
Ce1Init, Ce1Save,
|
"Bank Select (CE1)",
|
||||||
Ce1Read, Ce1Write,
|
0x05,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
2,
|
||||||
|
Ce1Init,
|
||||||
|
Ce1Save,
|
||||||
|
Ce1Read,
|
||||||
|
Ce1Write,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Port 1 Control (CE2)", 0x07, 3,
|
{
|
||||||
Ce2Init, Ce2Save,
|
"Port 1 Control (CE2)",
|
||||||
Ce2Read, Ce2Write,
|
0x07,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
3,
|
||||||
|
Ce2Init,
|
||||||
|
Ce2Save,
|
||||||
|
Ce2Read,
|
||||||
|
Ce2Write,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Port 2 Control (NCE3)", 0x01, 1,
|
{
|
||||||
NCe3Init, NCe3Save,
|
"Port 2 Control (NCE3)",
|
||||||
NCe3Read, NCe3Write,
|
0x01,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
1,
|
||||||
}
|
NCe3Init,
|
||||||
}},
|
NCe3Save,
|
||||||
|
NCe3Read,
|
||||||
|
NCe3Write,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
} } },
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
HP49
|
HP49
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
{
|
{"hp49",
|
||||||
"hp49",
|
|
||||||
|
|
||||||
{
|
{ /* name, id, access_prio,
|
||||||
/* name, id, access_prio,
|
|
||||||
init, save,
|
init, save,
|
||||||
read, write,
|
read, write,
|
||||||
r_config, r_abs_base_addr, r_size,
|
r_config, r_abs_base_addr, r_size,
|
||||||
map_flags
|
map_flags
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{ "ROM (ROM)", 0x00, 0,
|
{
|
||||||
RomInit49, RomSave49,
|
"ROM (ROM)",
|
||||||
RomRead49, RomWrite49,
|
0x00,
|
||||||
MOD_CONFIGURED, 0x00000, 0xFFFFF,
|
0,
|
||||||
|
RomInit49,
|
||||||
|
RomSave49,
|
||||||
|
RomRead49,
|
||||||
|
RomWrite49,
|
||||||
|
MOD_CONFIGURED,
|
||||||
|
0x00000,
|
||||||
|
0xFFFFF,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Hardware Regs. (HDW)", 0x19, 5,
|
{
|
||||||
HdwInit, HdwSave,
|
"Hardware Regs. (HDW)",
|
||||||
HdwRead, HdwWrite,
|
0x19,
|
||||||
MOD_SIZE_CONFIGURED, 0x00000, 0x00040,
|
5,
|
||||||
|
HdwInit,
|
||||||
|
HdwSave,
|
||||||
|
HdwRead,
|
||||||
|
HdwWrite,
|
||||||
|
MOD_SIZE_CONFIGURED,
|
||||||
|
0x00000,
|
||||||
|
0x00040,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "IRAM (RAM)", 0x03, 4,
|
{
|
||||||
RamInit49, RamSave49,
|
"IRAM (RAM)",
|
||||||
RamRead49, RamWrite49,
|
0x03,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
4,
|
||||||
|
RamInit49,
|
||||||
|
RamSave49,
|
||||||
|
RamRead49,
|
||||||
|
RamWrite49,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Bank Select (CE1)", 0x05, 2,
|
{
|
||||||
Ce1Init49, Ce1Save49,
|
"Bank Select (CE1)",
|
||||||
Ce1Read49, Ce1Write49,
|
0x05,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
2,
|
||||||
|
Ce1Init49,
|
||||||
|
Ce1Save49,
|
||||||
|
Ce1Read49,
|
||||||
|
Ce1Write49,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "ERAM Bank 0 (CE2)", 0x07, 3,
|
{
|
||||||
Ce2Init49, Ce2Save49,
|
"ERAM Bank 0 (CE2)",
|
||||||
Ce2Read49, Ce2Write49,
|
0x07,
|
||||||
MOD_UNCONFIGURED, 0, 0,
|
3,
|
||||||
|
Ce2Init49,
|
||||||
|
Ce2Save49,
|
||||||
|
Ce2Read49,
|
||||||
|
Ce2Write49,
|
||||||
|
MOD_UNCONFIGURED,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "ERAM Bank 1 (NCE3)", 0x01, 1,
|
{ "ERAM Bank 1 (NCE3)", 0x01, 1, NCe3Init49, NCe3Save49, NCe3Read49, NCe3Write49, MOD_UNCONFIGURED, 0, 0,
|
||||||
NCe3Init49, NCe3Save49,
|
MOD_MAP_FLAGS_ABS } }}
|
||||||
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
|
.title : ModSelectDescription
|
||||||
|
@ -304,10 +367,10 @@ void ModSelectDescription(const char *hw)
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModSelectDescription" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModSelectDescription" );
|
||||||
|
|
||||||
for(i=0; i<N_DESCRIPTIONS && strcmp(hw, table[i].hw); i++);
|
for ( i = 0; i < N_DESCRIPTIONS && strcmp( hw, table[ i ].hw ); i++ )
|
||||||
|
;
|
||||||
|
|
||||||
if(i==N_DESCRIPTIONS)
|
if ( i == N_DESCRIPTIONS ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_E_NO_MATCH, CHF_ERROR, hw ChfEnd;
|
ChfCondition MOD_E_NO_MATCH, CHF_ERROR, hw ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
54
src/keyb.c
54
src/keyb.c
|
@ -109,7 +109,6 @@ static char rcs_id[] = "$Id: keyb.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
*/
|
*/
|
||||||
static InputRegister cur_in[ OUT_BITS ];
|
static InputRegister cur_in[ OUT_BITS ];
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : KeybRSI
|
.title : KeybRSI
|
||||||
|
@ -139,11 +138,9 @@ 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 ?
|
CpuIntRequest( KeybIN( ( OutputRegister )0x1FF ) != ( InputRegister )0 ? INT_REQUEST_IRQ : INT_REQUEST_NONE );
|
||||||
INT_REQUEST_IRQ : INT_REQUEST_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : KeybIn
|
.title : KeybIn
|
||||||
|
@ -175,16 +172,15 @@ InputRegister KeybIN(OutputRegister out)
|
||||||
/* For each bit set in the 'out' register, OR the corresponding IN register
|
/* For each bit set in the 'out' register, OR the corresponding IN register
|
||||||
value into 'in'
|
value into 'in'
|
||||||
*/
|
*/
|
||||||
for(bit=0; bit<OUT_BITS; bit++)
|
for ( bit = 0; bit < OUT_BITS; bit++ ) {
|
||||||
{
|
if ( out & 0x01 )
|
||||||
if(out & 0x01) in |= cur_in[bit];
|
in |= cur_in[ bit ];
|
||||||
out >>= 1;
|
out >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : KeybPress
|
.title : KeybPress
|
||||||
|
@ -212,47 +208,41 @@ InputRegister KeybIN(OutputRegister out)
|
||||||
.- */
|
.- */
|
||||||
void KeybPress( const char* key )
|
void KeybPress( const char* key )
|
||||||
{
|
{
|
||||||
if(strcmp(key, "*") == 0)
|
if ( strcmp( key, "*" ) == 0 ) {
|
||||||
{
|
|
||||||
/* This is the ON key */
|
/* This is the ON key */
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Set all 0x8000 lines */
|
/* Set all 0x8000 lines */
|
||||||
for(i=0; i<OUT_BITS; i++) cur_in[i] |= 0x8000;
|
for ( i = 0; i < OUT_BITS; i++ )
|
||||||
|
cur_in[ i ] |= 0x8000;
|
||||||
|
|
||||||
/* Post an interrupt request to the CPU */
|
/* Post an interrupt request to the CPU */
|
||||||
CpuIntRequest( INT_REQUEST_NMI );
|
CpuIntRequest( INT_REQUEST_NMI );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int in_val, out_bit;
|
int in_val, out_bit;
|
||||||
|
|
||||||
if(sscanf(key, "%x/%x", &out_bit, &in_val) != 2)
|
if ( sscanf( key, "%x/%x", &out_bit, &in_val ) != 2 ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_W_BAD_KEY, CHF_WARNING, key ChfEnd;
|
ChfCondition MOD_W_BAD_KEY, CHF_WARNING, key ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(out_bit < 0 || out_bit >= OUT_BITS)
|
else if ( out_bit < 0 || out_bit >= OUT_BITS ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd;
|
ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Update the cur_in array */
|
/* Update the cur_in array */
|
||||||
cur_in[ out_bit ] |= in_val;
|
cur_in[ out_bit ] |= in_val;
|
||||||
|
|
||||||
/* Post an interrupt request to the CPU */
|
/* Post an interrupt request to the CPU */
|
||||||
CpuIntRequest( INT_REQUEST_NMI );
|
CpuIntRequest( INT_REQUEST_NMI );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : KeybRelease
|
.title : KeybRelease
|
||||||
|
@ -279,40 +269,35 @@ void KeybPress(const char *key)
|
||||||
.- */
|
.- */
|
||||||
void KeybRelease( const char* key )
|
void KeybRelease( const char* key )
|
||||||
{
|
{
|
||||||
if(strcmp(key, "*") == 0)
|
if ( strcmp( key, "*" ) == 0 ) {
|
||||||
{
|
|
||||||
/* This is the ON key */
|
/* This is the ON key */
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Reset all 0x8000 lines */
|
/* Reset all 0x8000 lines */
|
||||||
for(i=0; i<OUT_BITS; i++) cur_in[i] &= 0x7FFF;
|
for ( i = 0; i < OUT_BITS; i++ )
|
||||||
|
cur_in[ i ] &= 0x7FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int in_val, out_bit;
|
int in_val, out_bit;
|
||||||
|
|
||||||
if(sscanf(key, "%x/%x", &out_bit, &in_val) != 2)
|
if ( sscanf( key, "%x/%x", &out_bit, &in_val ) != 2 ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_W_BAD_KEY, CHF_WARNING, key ChfEnd;
|
ChfCondition MOD_W_BAD_KEY, CHF_WARNING, key ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(out_bit < 0 || out_bit >= OUT_BITS)
|
else if ( out_bit < 0 || out_bit >= OUT_BITS ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd;
|
ChfCondition MOD_W_BAD_OUT_BIT, CHF_WARNING, out_bit ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Update the cur_in array */
|
/* Update the cur_in array */
|
||||||
cur_in[ out_bit ] &= ~in_val;
|
cur_in[ out_bit ] &= ~in_val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : KeybReset
|
.title : KeybReset
|
||||||
|
@ -337,5 +322,6 @@ void KeybReset(void)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Reset all 0x8000 lines */
|
/* Reset all 0x8000 lines */
|
||||||
for(i=0; i<OUT_BITS; i++) cur_in[i] = 0;
|
for ( i = 0; i < OUT_BITS; i++ )
|
||||||
|
cur_in[ i ] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
106
src/libChf/Chf.h
106
src/libChf/Chf.h
|
@ -51,7 +51,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Win32 & UNICODE support
|
Win32 & UNICODE support
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -70,7 +69,6 @@
|
||||||
# define ChfSiglongjmp( x, y ) siglongjmp( x, y )
|
# define ChfSiglongjmp( x, y ) siglongjmp( x, y )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
CHF implementation limits and other symbolic constants
|
CHF implementation limits and other symbolic constants
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -91,7 +89,6 @@
|
||||||
#define CHF_SET 2
|
#define CHF_SET 2
|
||||||
#define CHF_ERRNO_SET 3
|
#define CHF_ERRNO_SET 3
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Condition codes
|
Condition codes
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -107,29 +104,23 @@
|
||||||
#define CHF_F_SETLOCALE 10 /* setlocale() failed */
|
#define CHF_F_SETLOCALE 10 /* setlocale() failed */
|
||||||
#define CHF_F_CATOPEN 11 /* catopen() failed */
|
#define CHF_F_CATOPEN 11 /* catopen() failed */
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Type definitions
|
Type definitions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef enum /* Condition severity codes */
|
typedef enum /* Condition severity codes */
|
||||||
{
|
{ CHF_SUCCESS,
|
||||||
CHF_SUCCESS,
|
|
||||||
CHF_INFO,
|
CHF_INFO,
|
||||||
CHF_WARNING,
|
CHF_WARNING,
|
||||||
CHF_ERROR,
|
CHF_ERROR,
|
||||||
CHF_FATAL
|
CHF_FATAL } ChfSeverity;
|
||||||
}
|
|
||||||
ChfSeverity;
|
|
||||||
|
|
||||||
typedef enum /* Condition handler action codes */
|
typedef enum /* Condition handler action codes */
|
||||||
{
|
{ CHF_CONTINUE, /* Continue application */
|
||||||
CHF_CONTINUE, /* Continue application */
|
|
||||||
CHF_RESIGNAL, /* Resignal to next handler */
|
CHF_RESIGNAL, /* Resignal to next handler */
|
||||||
CHF_UNWIND, /* Stack unwind */
|
CHF_UNWIND, /* Stack unwind */
|
||||||
CHF_UNWIND_KEEP /* Unwind, keep last cond. group */
|
CHF_UNWIND_KEEP /* Unwind, keep last cond. group */
|
||||||
}
|
} ChfAction;
|
||||||
ChfAction;
|
|
||||||
|
|
||||||
typedef int /* CHF options */
|
typedef int /* CHF options */
|
||||||
ChfOptions;
|
ChfOptions;
|
||||||
|
@ -138,14 +129,11 @@ typedef int /* CHF options */
|
||||||
#define CHF_ABORT 0x0001 /* use abort() instead of exit() */
|
#define CHF_ABORT 0x0001 /* use abort() instead of exit() */
|
||||||
|
|
||||||
typedef enum /* Current CHF state */
|
typedef enum /* Current CHF state */
|
||||||
{
|
{ CHF_UNKNOWN,
|
||||||
CHF_UNKNOWN,
|
|
||||||
CHF_IDLE,
|
CHF_IDLE,
|
||||||
CHF_SIGNALING,
|
CHF_SIGNALING,
|
||||||
CHF_UNWINDING,
|
CHF_UNWINDING,
|
||||||
CHF_SIGNAL_UNWINDING
|
CHF_SIGNAL_UNWINDING } ChfState;
|
||||||
}
|
|
||||||
ChfState;
|
|
||||||
|
|
||||||
typedef struct ChfDescriptor_S /* Condition descriptor */
|
typedef struct ChfDescriptor_S /* Condition descriptor */
|
||||||
{
|
{
|
||||||
|
@ -156,40 +144,26 @@ typedef struct ChfDescriptor_S /* Condition descriptor */
|
||||||
const ChfChar* file_name; /* File name or CHF_UNK_FILE_NAME */
|
const ChfChar* file_name; /* File name or CHF_UNK_FILE_NAME */
|
||||||
ChfChar message[ CHF_MAX_MESSAGE_LENGTH ]; /* Partial message */
|
ChfChar message[ CHF_MAX_MESSAGE_LENGTH ]; /* Partial message */
|
||||||
struct ChfDescriptor_S* next; /* Link to next descriptor */
|
struct ChfDescriptor_S* next; /* Link to next descriptor */
|
||||||
}
|
} ChfDescriptor;
|
||||||
ChfDescriptor;
|
|
||||||
|
|
||||||
typedef struct ChfTable_S /* Standalone message table */
|
typedef struct ChfTable_S /* Standalone message table */
|
||||||
{
|
{
|
||||||
int module; /* Module identifier */
|
int module; /* Module identifier */
|
||||||
int code; /* Condition code */
|
int code; /* Condition code */
|
||||||
ChfChar* msg_template; /* Message template */
|
ChfChar* msg_template; /* Message template */
|
||||||
}
|
} ChfTable;
|
||||||
ChfTable;
|
|
||||||
|
|
||||||
typedef /* Generic pointer */
|
typedef /* Generic pointer */
|
||||||
void* ChfPointer;
|
void* ChfPointer;
|
||||||
|
|
||||||
typedef /* Condition handler */
|
typedef /* Condition handler */
|
||||||
ChfAction (*ChfHandler)(
|
ChfAction ( *ChfHandler )( const ChfDescriptor*, const ChfState, ChfPointer );
|
||||||
const ChfDescriptor *,
|
|
||||||
const ChfState,
|
|
||||||
ChfPointer
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef /* Message retrieval 'get_message' function */
|
typedef /* Message retrieval 'get_message' function */
|
||||||
const ChfChar * (*ChfMrsGet)(
|
const ChfChar* ( *ChfMrsGet )( void*, const int, const int, const ChfChar* default_message );
|
||||||
void *,
|
|
||||||
const int,
|
|
||||||
const int,
|
|
||||||
const ChfChar *default_message
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef /* Message retrieval 'exit' function */
|
typedef /* Message retrieval 'exit' function */
|
||||||
void (*ChfMrsExit)(
|
void ( *ChfMrsExit )( void* );
|
||||||
void *
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Condition generation macros
|
Condition generation macros
|
||||||
|
@ -204,13 +178,7 @@ typedef /* Message retrieval 'exit' function */
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
# define ChfErrnoCondition
|
# define ChfErrnoCondition
|
||||||
# else
|
# else
|
||||||
#define ChfErrnoCondition \
|
# define ChfErrnoCondition ChfGenerate( CHF_ERRNO_SET, ChfText( __FILE__ ), __LINE__, errno, CHF_ERROR )
|
||||||
ChfGenerate( \
|
|
||||||
CHF_ERRNO_SET, \
|
|
||||||
ChfText(__FILE__), __LINE__, \
|
|
||||||
errno, \
|
|
||||||
CHF_ERROR \
|
|
||||||
)
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -222,13 +190,7 @@ typedef /* Message retrieval 'exit' function */
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
# define ChfErrnoCondition
|
# define ChfErrnoCondition
|
||||||
# else
|
# else
|
||||||
#define ChfErrnoCondition \
|
# define ChfErrnoCondition ChfGenerate( CHF_ERRNO_SET, CHF_UNKNOWN_FILE_NAME, CHF_UNKNOWN_LINE_NUMBER, errno, CHF_ERROR )
|
||||||
ChfGenerate( \
|
|
||||||
CHF_ERRNO_SET, \
|
|
||||||
CHF_UNKNOWN_FILE_NAME, CHF_UNKNOWN_LINE_NUMBER, \
|
|
||||||
errno, \
|
|
||||||
CHF_ERROR \
|
|
||||||
)
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -236,7 +198,6 @@ typedef /* Message retrieval 'exit' function */
|
||||||
#define ChfEnd \
|
#define ChfEnd \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Structured condition handling
|
Structured condition handling
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -244,8 +205,7 @@ typedef /* Message retrieval 'exit' function */
|
||||||
#define ChfTry \
|
#define ChfTry \
|
||||||
{ \
|
{ \
|
||||||
ChfSigjmp_buf _chf_sigjmp_buf; \
|
ChfSigjmp_buf _chf_sigjmp_buf; \
|
||||||
if(ChfSigsetjmp(_chf_sigjmp_buf, 1) == 0)\
|
if ( ChfSigsetjmp( _chf_sigjmp_buf, 1 ) == 0 ) { \
|
||||||
{\
|
|
||||||
ChfPushHandler( CHF_NULL_HANDLER, _chf_sigjmp_buf, CHF_NULL_POINTER );
|
ChfPushHandler( CHF_NULL_HANDLER, _chf_sigjmp_buf, CHF_NULL_POINTER );
|
||||||
|
|
||||||
#define ChfCatch \
|
#define ChfCatch \
|
||||||
|
@ -259,7 +219,6 @@ typedef /* Message retrieval 'exit' function */
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Other macros
|
Other macros
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -272,8 +231,6 @@ typedef /* Message retrieval 'exit' function */
|
||||||
#define ChfGetFileName( d ) ( d )->file_name
|
#define ChfGetFileName( d ) ( d )->file_name
|
||||||
#define ChfGetPartialMessage( d ) ( d )->message
|
#define ChfGetPartialMessage( d ) ( d )->message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -322,12 +279,10 @@ int ChfWin32Init( /* Initialization within _WIN32 */
|
||||||
);
|
);
|
||||||
|
|
||||||
void ChfExit( /* Exit */
|
void ChfExit( /* Exit */
|
||||||
void
|
void );
|
||||||
);
|
|
||||||
|
|
||||||
void ChfAbort( /* Abort application */
|
void ChfAbort( /* Abort application */
|
||||||
const int abort_code
|
const int abort_code );
|
||||||
);
|
|
||||||
|
|
||||||
void ChfPushHandler( /* Push a new handler into the stack */
|
void ChfPushHandler( /* Push a new handler into the stack */
|
||||||
ChfHandler new_handler, /* Handler to be added */
|
ChfHandler new_handler, /* Handler to be added */
|
||||||
|
@ -336,36 +291,23 @@ void ChfPushHandler( /* Push a new handler into the stack */
|
||||||
);
|
);
|
||||||
|
|
||||||
void ChfPopHandler( /* Pop a handler */
|
void ChfPopHandler( /* Pop a handler */
|
||||||
void
|
void );
|
||||||
);
|
|
||||||
|
|
||||||
ChfChar* ChfBuildMessage( /* Build a condition message */
|
ChfChar* ChfBuildMessage( /* Build a condition message */
|
||||||
const ChfDescriptor *descriptor
|
const ChfDescriptor* descriptor );
|
||||||
);
|
|
||||||
|
|
||||||
void ChfSignal( /* Signal the current conditions */
|
void ChfSignal( /* Signal the current conditions */
|
||||||
void
|
void );
|
||||||
);
|
|
||||||
|
|
||||||
void ChfDiscard( /* Discard the current conditions */
|
void ChfDiscard( /* Discard the current conditions */
|
||||||
void
|
void );
|
||||||
);
|
|
||||||
|
|
||||||
void ChfGenerate( /* Generate a condition into the stack */
|
void ChfGenerate( /* Generate a condition into the stack */
|
||||||
const int module_id,
|
const int module_id, const ChfChar* file_name, const int line_number, const int condition_code,
|
||||||
const ChfChar *file_name,
|
const ChfSeverity severity, ... );
|
||||||
const int line_number,
|
|
||||||
const int condition_code,
|
|
||||||
const ChfSeverity severity,
|
|
||||||
...
|
|
||||||
);
|
|
||||||
|
|
||||||
const ChfChar* ChfGetMessage( /* Retrieve a condition message */
|
const ChfChar* ChfGetMessage( /* Retrieve a condition message */
|
||||||
const int module_id,
|
const int module_id, const int condition_code, const ChfChar* default_message );
|
||||||
const int condition_code,
|
|
||||||
const ChfChar *default_message
|
|
||||||
);
|
|
||||||
|
|
||||||
const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
|
const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
|
||||||
void
|
void );
|
||||||
);
|
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Macros
|
Macros
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -49,7 +48,9 @@
|
||||||
#define CHF_DEF_MID_MSG_FMT ChfText( "Mid <%d>d" )
|
#define CHF_DEF_MID_MSG_FMT ChfText( "Mid <%d>d" )
|
||||||
#define CHF_EXTENDED_INFO_FMT ChfText( "(%s,%d)" )
|
#define CHF_EXTENDED_INFO_FMT ChfText( "(%s,%d)" )
|
||||||
#define CHF_SEVERITY_NAMES \
|
#define CHF_SEVERITY_NAMES \
|
||||||
{ ChfText("S"), ChfText("I"), ChfText("W"), ChfText("E"), ChfText("F") }
|
{ \
|
||||||
|
ChfText( "S" ), ChfText( "I" ), ChfText( "W" ), ChfText( "E" ), ChfText( "F" ) \
|
||||||
|
}
|
||||||
#define CHF_UNKNOWN_SEVERITY ChfText( "?" )
|
#define CHF_UNKNOWN_SEVERITY ChfText( "?" )
|
||||||
#define CHF_MESSAGE_SEPARATOR ChfText( "-" )
|
#define CHF_MESSAGE_SEPARATOR ChfText( "-" )
|
||||||
#define CHF_MESSAGE_TERMINATOR ChfText( "\n" )
|
#define CHF_MESSAGE_TERMINATOR ChfText( "\n" )
|
||||||
|
@ -57,7 +58,6 @@
|
||||||
#define CHF_ABORT_BAD_CODE_FMT ChfText( "Bad abort code <%d>d\n" )
|
#define CHF_ABORT_BAD_CODE_FMT ChfText( "Bad abort code <%d>d\n" )
|
||||||
#define CHF_ABORT_GOOD_CODE_FMT ChfText( "%s\n" )
|
#define CHF_ABORT_GOOD_CODE_FMT ChfText( "%s\n" )
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Abort codes used with ChfAbort()
|
Abort codes used with ChfAbort()
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -74,19 +74,15 @@
|
||||||
#define CHF_ABORT_GET_CONTEXT 9
|
#define CHF_ABORT_GET_CONTEXT 9
|
||||||
#define CHF_ABORT_PTHREAD 10
|
#define CHF_ABORT_PTHREAD 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Type definitions
|
Type definitions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef struct ChfHandlerDescriptor_S
|
typedef struct ChfHandlerDescriptor_S {
|
||||||
{
|
|
||||||
ChfHandler handler;
|
ChfHandler handler;
|
||||||
void* unwind_context;
|
void* unwind_context;
|
||||||
ChfPointer handler_context;
|
ChfPointer handler_context;
|
||||||
}
|
} ChfHandlerDescriptor;
|
||||||
ChfHandlerDescriptor;
|
|
||||||
|
|
||||||
typedef struct ChfContext_S /* CHF Context */
|
typedef struct ChfContext_S /* CHF Context */
|
||||||
{
|
{
|
||||||
|
@ -105,9 +101,7 @@ typedef struct ChfContext_S /* CHF Context */
|
||||||
ChfHandlerDescriptor* handler_stack; /* Handler stack */
|
ChfHandlerDescriptor* handler_stack; /* Handler stack */
|
||||||
ChfHandlerDescriptor* handler_sp; /* Current handler stack pointer */
|
ChfHandlerDescriptor* handler_sp; /* Current handler stack pointer */
|
||||||
ChfChar* message_buffer; /* Message buffer */
|
ChfChar* message_buffer; /* Message buffer */
|
||||||
}
|
} ChfContext;
|
||||||
ChfContext;
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Multithreading support
|
Multithreading support
|
||||||
|
@ -118,14 +112,12 @@ typedef struct ChfContext_S /* CHF Context */
|
||||||
# define chf_context _chf_context
|
# define chf_context _chf_context
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern ChfContext _chf_context; /* CHF Context */
|
extern ChfContext _chf_context; /* CHF Context */
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private function prototypes
|
Private function prototypes
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -133,7 +125,6 @@ extern ChfContext _chf_context; /* CHF Context */
|
||||||
ChfContext* _ChfGetContext( void );
|
ChfContext* _ChfGetContext( void );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private redirection of stdlib functions needed by Win32
|
Private redirection of stdlib functions needed by Win32
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
|
@ -53,13 +53,10 @@ static char rcs_id[] = "$Id: chf_abrt.c,v 2.2 2001/01/25 12:08:24 cibrario Exp $
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Abort codes message table; the relative position of the messages must
|
/* Abort codes message table; the relative position of the messages must
|
||||||
match the numeric codes CHF_ABORT_xxxx defined in ChfPriv.h
|
match the numeric codes CHF_ABORT_xxxx defined in ChfPriv.h
|
||||||
*/
|
*/
|
||||||
static const ChfChar *message_table[] =
|
static const ChfChar* message_table[] = { ( const ChfChar* )NULL,
|
||||||
{
|
|
||||||
(const ChfChar *)NULL,
|
|
||||||
ChfText( "Not initialized" ),
|
ChfText( "Not initialized" ),
|
||||||
ChfText( "Temporary message buffer overflow" ),
|
ChfText( "Temporary message buffer overflow" ),
|
||||||
ChfText( "Invalid action from last chance handler" ),
|
ChfText( "Invalid action from last chance handler" ),
|
||||||
|
@ -69,12 +66,10 @@ static const ChfChar *message_table[] =
|
||||||
ChfText( "Fatal condition while unwinding" ),
|
ChfText( "Fatal condition while unwinding" ),
|
||||||
ChfText( "Condition stack overflow" ),
|
ChfText( "Condition stack overflow" ),
|
||||||
ChfText( "Can't prime a new Chf context" ),
|
ChfText( "Can't prime a new Chf context" ),
|
||||||
ChfText("Pthread interaction failed")
|
ChfText( "Pthread interaction failed" ) };
|
||||||
};
|
|
||||||
|
|
||||||
#define MESSAGE_TABLE_SIZE ( sizeof( message_table ) / sizeof( const ChfChar* ) )
|
#define MESSAGE_TABLE_SIZE ( sizeof( message_table ) / sizeof( const ChfChar* ) )
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfAbort
|
.title : ChfAbort
|
||||||
|
@ -123,12 +118,10 @@ static const ChfChar *message_table[] =
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfAbort( /* Abort application */
|
void ChfAbort( /* Abort application */
|
||||||
const int abort_code
|
const int abort_code )
|
||||||
)
|
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(abort_code != CHF_ABORT_SILENT)
|
if ( abort_code != CHF_ABORT_SILENT ) {
|
||||||
{
|
|
||||||
TCHAR abort_msg[ CHF_MAX_MESSAGE_LENGTH ];
|
TCHAR abort_msg[ CHF_MAX_MESSAGE_LENGTH ];
|
||||||
HWND active_window;
|
HWND active_window;
|
||||||
|
|
||||||
|
@ -136,25 +129,16 @@ void ChfAbort( /* Abort application */
|
||||||
put complaint in a message box and display it
|
put complaint in a message box and display it
|
||||||
*/
|
*/
|
||||||
if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE )
|
if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE )
|
||||||
_stprintf(abort_msg,
|
_stprintf( abort_msg, CHF_ABORT_BAD_CODE_FMT, abort_code );
|
||||||
CHF_ABORT_BAD_CODE_FMT, abort_code);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
_stprintf(abort_msg,
|
_stprintf( abort_msg, CHF_ABORT_GOOD_CODE_FMT, message_table[ abort_code ] );
|
||||||
CHF_ABORT_GOOD_CODE_FMT, message_table[abort_code]);
|
|
||||||
|
|
||||||
/* Return value of MessageBox() ignored, because there is only
|
/* Return value of MessageBox() ignored, because there is only
|
||||||
one available choice (abort) here. Avoid using a NULL handle.
|
one available choice (abort) here. Avoid using a NULL handle.
|
||||||
*/
|
*/
|
||||||
if(chf_context.state != CHF_UNKNOWN
|
if ( chf_context.state != CHF_UNKNOWN && ( active_window = GetActiveWindow() ) != ( HWND )NULL )
|
||||||
&& (active_window = GetActiveWindow()) != (HWND)NULL)
|
( void )MessageBox( active_window, abort_msg, chf_context.app_name, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND );
|
||||||
(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
|
/* Immediately exit the application with exit code EXIT_FAILURE
|
||||||
|
@ -175,8 +159,7 @@ void ChfAbort( /* Abort application */
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if(abort_code != CHF_ABORT_SILENT)
|
if ( abort_code != CHF_ABORT_SILENT ) {
|
||||||
{
|
|
||||||
fputs( CHF_ABORT_HEADER, stderr );
|
fputs( CHF_ABORT_HEADER, stderr );
|
||||||
|
|
||||||
if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE )
|
if ( abort_code < 0 || abort_code >= MESSAGE_TABLE_SIZE )
|
||||||
|
|
|
@ -45,7 +45,6 @@ static char rcs_id[] = "$Id: chf_gen.c,v 2.2 2001/01/25 12:10:22 cibrario Exp $"
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfGenerate
|
.title : ChfGenerate
|
||||||
|
@ -92,34 +91,26 @@ static char rcs_id[] = "$Id: chf_gen.c,v 2.2 2001/01/25 12:10:22 cibrario Exp $"
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfGenerate( /* Generate a condition into the stack */
|
void ChfGenerate( /* Generate a condition into the stack */
|
||||||
const int module_id,
|
const int module_id, const ChfChar* file_name, const int line_number, const int condition_code,
|
||||||
const ChfChar *file_name,
|
const ChfSeverity severity, ... )
|
||||||
const int line_number,
|
|
||||||
const int condition_code,
|
|
||||||
const ChfSeverity severity,
|
|
||||||
...
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfDescriptor* new_descriptor;
|
ChfDescriptor* new_descriptor;
|
||||||
va_list aux_arg;
|
va_list aux_arg;
|
||||||
|
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
/* Prepare the additional arguments list */
|
/* Prepare the additional arguments list */
|
||||||
va_start( aux_arg, severity );
|
va_start( aux_arg, severity );
|
||||||
|
|
||||||
if((new_descriptor = chf_context.condition_sp) -
|
if ( ( new_descriptor = chf_context.condition_sp ) - chf_context.condition_stack >= chf_context.condition_stack_size ) {
|
||||||
chf_context.condition_stack >= chf_context.condition_stack_size)
|
|
||||||
{
|
|
||||||
/* The condition stack is full;
|
/* The condition stack is full;
|
||||||
generate the CHF_F_COND_STACK_FULL condition and signal it immediately,
|
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,
|
using the last available slot of the stack, if it's still empty,
|
||||||
otherwise abort the application.
|
otherwise abort the application.
|
||||||
*/
|
*/
|
||||||
if(new_descriptor - chf_context.condition_stack ==
|
if ( new_descriptor - chf_context.condition_stack == chf_context.condition_stack_size ) {
|
||||||
chf_context.condition_stack_size)
|
|
||||||
{
|
|
||||||
new_descriptor->module_id = CHF_MODULE_ID;
|
new_descriptor->module_id = CHF_MODULE_ID;
|
||||||
new_descriptor->condition_code = CHF_F_COND_STACK_FULL;
|
new_descriptor->condition_code = CHF_F_COND_STACK_FULL;
|
||||||
new_descriptor->severity = CHF_FATAL;
|
new_descriptor->severity = CHF_FATAL;
|
||||||
|
@ -127,8 +118,8 @@ void ChfGenerate( /* Generate a condition into the stack */
|
||||||
new_descriptor->file_name = CHF_UNKNOWN_FILE_NAME;
|
new_descriptor->file_name = CHF_UNKNOWN_FILE_NAME;
|
||||||
|
|
||||||
ChfStrncpy( new_descriptor->message,
|
ChfStrncpy( new_descriptor->message,
|
||||||
ChfGetMessage(CHF_MODULE_ID, CHF_F_COND_STACK_FULL,
|
ChfGetMessage( CHF_MODULE_ID, CHF_F_COND_STACK_FULL, ChfText( "Condition stack is full" ) ),
|
||||||
ChfText("Condition stack is full")), CHF_MAX_MESSAGE_LENGTH-1);
|
CHF_MAX_MESSAGE_LENGTH - 1 );
|
||||||
new_descriptor->message[ CHF_MAX_MESSAGE_LENGTH - 1 ] = '\0';
|
new_descriptor->message[ CHF_MAX_MESSAGE_LENGTH - 1 ] = '\0';
|
||||||
|
|
||||||
new_descriptor->next = CHF_NULL_DESCRIPTOR;
|
new_descriptor->next = CHF_NULL_DESCRIPTOR;
|
||||||
|
@ -141,8 +132,7 @@ void ChfGenerate( /* Generate a condition into the stack */
|
||||||
ChfAbort( CHF_ABORT_COND_STACK_OVF );
|
ChfAbort( CHF_ABORT_COND_STACK_OVF );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ChfChar def_message[ CHF_DEF_MESSAGE_LENGTH ];
|
ChfChar def_message[ CHF_DEF_MESSAGE_LENGTH ];
|
||||||
ChfChar tmp_message[ CHF_TMP_MESSAGE_LENGTH ];
|
ChfChar tmp_message[ CHF_TMP_MESSAGE_LENGTH ];
|
||||||
|
|
||||||
|
@ -158,10 +148,7 @@ void ChfGenerate( /* Generate a condition into the stack */
|
||||||
/* Generate the partial message associated with the condition using a
|
/* Generate the partial message associated with the condition using a
|
||||||
temporary area
|
temporary area
|
||||||
*/
|
*/
|
||||||
if(
|
if ( ChfVsprintf( tmp_message, ChfGetMessage( module_id, condition_code, def_message ), aux_arg ) >= CHF_TMP_MESSAGE_LENGTH )
|
||||||
ChfVsprintf(tmp_message,
|
|
||||||
ChfGetMessage(module_id, condition_code, def_message), aux_arg) >=
|
|
||||||
CHF_TMP_MESSAGE_LENGTH)
|
|
||||||
ChfAbort( CHF_ABORT_MSG_OVF );
|
ChfAbort( CHF_ABORT_MSG_OVF );
|
||||||
|
|
||||||
/* Copy the message into the condition descriptor */
|
/* Copy the message into the condition descriptor */
|
||||||
|
@ -171,8 +158,7 @@ void ChfGenerate( /* Generate a condition into the stack */
|
||||||
/* Link the new descriptor with the current descriptor list, if it
|
/* Link the new descriptor with the current descriptor list, if it
|
||||||
isn't the first descriptor of the list
|
isn't the first descriptor of the list
|
||||||
*/
|
*/
|
||||||
new_descriptor->next = (new_descriptor == chf_context.condition_base)
|
new_descriptor->next = ( new_descriptor == chf_context.condition_base ) ? CHF_NULL_DESCRIPTOR : new_descriptor - 1;
|
||||||
? CHF_NULL_DESCRIPTOR : new_descriptor - 1;
|
|
||||||
|
|
||||||
chf_context.condition_sp++;
|
chf_context.condition_sp++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ static char rcs_id[] = "$Id: chf_hdlr.c,v 2.2 2001/01/25 12:12:46 cibrario Exp $
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : StructuredHelper
|
.title : StructuredHelper
|
||||||
|
@ -90,20 +89,14 @@ static char rcs_id[] = "$Id: chf_hdlr.c,v 2.2 2001/01/25 12:12:46 cibrario Exp $
|
||||||
2.1, 19-May-2000, creation
|
2.1, 19-May-2000, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
static ChfAction StructuredHelper(
|
static ChfAction StructuredHelper( const ChfDescriptor* desc, const ChfState state, ChfPointer handler_context )
|
||||||
const ChfDescriptor *desc,
|
|
||||||
const ChfState state,
|
|
||||||
ChfPointer handler_context
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfAction action;
|
ChfAction action;
|
||||||
const ChfDescriptor* d;
|
const ChfDescriptor* d;
|
||||||
|
|
||||||
return((state == CHF_SIGNALING && ChfGetSeverity(desc) == CHF_FATAL)
|
return ( ( state == CHF_SIGNALING && ChfGetSeverity( desc ) == CHF_FATAL ) ? CHF_UNWIND_KEEP : CHF_RESIGNAL );
|
||||||
? CHF_UNWIND_KEEP : CHF_RESIGNAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfPushHandler
|
.title : ChfPushHandler
|
||||||
|
@ -163,43 +156,33 @@ static ChfAction StructuredHelper(
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfPushHandler( /* Push a new handler into the stack */
|
void ChfPushHandler( /* Push a new handler into the stack */
|
||||||
ChfHandler new_handler,
|
ChfHandler new_handler, void* unwind_context, ChfPointer handler_context )
|
||||||
void *unwind_context,
|
|
||||||
ChfPointer handler_context
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/* Make sure that CHF has been correctly initialized and is idle */
|
/* 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_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
if(chf_context.state != CHF_IDLE)
|
if ( chf_context.state != CHF_IDLE ) {
|
||||||
{
|
ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
|
||||||
ChfCondition CHF_F_BAD_STATE, CHF_FATAL
|
|
||||||
ChfEnd;
|
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the handler stack is full */
|
/* Check if the handler stack is full */
|
||||||
else if(chf_context.handler_sp - chf_context.handler_stack >=
|
else if ( chf_context.handler_sp - chf_context.handler_stack >= chf_context.handler_stack_size ) {
|
||||||
chf_context.handler_stack_size)
|
ChfCondition CHF_F_HDLR_STACK_FULL, CHF_FATAL ChfEnd;
|
||||||
{
|
|
||||||
ChfCondition CHF_F_HDLR_STACK_FULL, CHF_FATAL
|
|
||||||
ChfEnd;
|
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
chf_context.handler_sp->unwind_context = unwind_context;
|
chf_context.handler_sp->unwind_context = unwind_context;
|
||||||
chf_context.handler_sp->handler_context = handler_context;
|
chf_context.handler_sp->handler_context = handler_context;
|
||||||
chf_context.handler_sp->handler =
|
chf_context.handler_sp->handler = ( ( new_handler == CHF_NULL_HANDLER ) ? StructuredHelper : new_handler );
|
||||||
((new_handler == CHF_NULL_HANDLER) ? StructuredHelper : new_handler);
|
|
||||||
chf_context.handler_sp++;
|
chf_context.handler_sp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfPopHandler
|
.title : ChfPopHandler
|
||||||
|
@ -235,25 +218,21 @@ void ChfPushHandler( /* Push a new handler into the stack */
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfPopHandler( /* Pop a handler */
|
void ChfPopHandler( /* Pop a handler */
|
||||||
void
|
void )
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/* Make sure that CHF has been correctly initialized and is idle */
|
/* 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_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
if(chf_context.state != CHF_IDLE)
|
if ( chf_context.state != CHF_IDLE ) {
|
||||||
{
|
ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
|
||||||
ChfCondition CHF_F_BAD_STATE, CHF_FATAL
|
|
||||||
ChfEnd;
|
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the handler stack is empty */
|
/* Check if the handler stack is empty */
|
||||||
else if(chf_context.handler_sp == chf_context.handler_stack)
|
else if ( chf_context.handler_sp == chf_context.handler_stack ) {
|
||||||
{
|
ChfCondition CHF_F_HDLR_STACK_EMPTY, CHF_FATAL ChfEnd;
|
||||||
ChfCondition CHF_F_HDLR_STACK_EMPTY, CHF_FATAL
|
|
||||||
ChfEnd;
|
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,6 @@ static char rcs_id[] = "$Id: chf_init.c,v 2.2 2001/01/25 14:05:23 cibrario Exp $
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Global and static variables
|
Global and static variables
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -84,7 +83,6 @@ ChfContext _chf_context;
|
||||||
static const ChfChar separator[] = CHF_MESSAGE_SEPARATOR;
|
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
|
Multithreading support
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -112,12 +110,10 @@ static void DestroyContext(void *context)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : DefaultHandler
|
.title : DefaultHandler
|
||||||
|
@ -170,11 +166,7 @@ static void DestroyContext(void *context)
|
||||||
- added Win32 support
|
- added Win32 support
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
static ChfAction DefaultHandler(
|
static ChfAction DefaultHandler( const ChfDescriptor* desc, const ChfState state, ChfPointer handler_context )
|
||||||
const ChfDescriptor *desc,
|
|
||||||
const ChfState state,
|
|
||||||
ChfPointer handler_context
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfAction action;
|
ChfAction action;
|
||||||
const ChfDescriptor* d;
|
const ChfDescriptor* d;
|
||||||
|
@ -183,29 +175,28 @@ static ChfAction DefaultHandler(
|
||||||
/* If CHF is unwinding, do nothing */
|
/* If CHF is unwinding, do nothing */
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Print the condition messages, if necessary. The sequence of fputs()
|
/* Print the condition messages, if necessary. The sequence of fputs()
|
||||||
is done atomically if multithreading support is enabled.
|
is done atomically if multithreading support is enabled.
|
||||||
In Win32, the default handler does not print anything.
|
In Win32, the default handler does not print anything.
|
||||||
*/
|
*/
|
||||||
if(ChfGetSeverity(desc) > CHF_SUCCESS)
|
if ( ChfGetSeverity( desc ) > CHF_SUCCESS ) {
|
||||||
{
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
if(pthread_mutex_lock(&fputs_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_lock( &fputs_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
#endif
|
#endif
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
for ( d = desc; d != CHF_NULL_DESCRIPTOR; d = ChfGetNextDescriptor( d ) )
|
for ( d = desc; d != CHF_NULL_DESCRIPTOR; d = ChfGetNextDescriptor( d ) )
|
||||||
fputs( ChfBuildMessage( d ), stderr );
|
fputs( ChfBuildMessage( d ), stderr );
|
||||||
#endif
|
#endif
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
if(pthread_mutex_unlock(&fputs_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_unlock( &fputs_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine the handler action */
|
/* Determine the handler action */
|
||||||
switch(ChfGetSeverity(desc))
|
switch ( ChfGetSeverity( desc ) ) {
|
||||||
{
|
|
||||||
case CHF_SUCCESS:
|
case CHF_SUCCESS:
|
||||||
case CHF_INFO:
|
case CHF_INFO:
|
||||||
case CHF_WARNING:
|
case CHF_WARNING:
|
||||||
|
@ -231,8 +222,6 @@ static ChfAction DefaultHandler(
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : scopy
|
.title : scopy
|
||||||
|
@ -257,23 +246,17 @@ static ChfAction DefaultHandler(
|
||||||
1.1, 16-May-1996, creation
|
1.1, 16-May-1996, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
static ChfChar *scopy(
|
static ChfChar* scopy( ChfChar* p, const ChfChar* q, ChfChar* p_end )
|
||||||
ChfChar *p,
|
|
||||||
const ChfChar *q,
|
|
||||||
ChfChar *p_end
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
size_t q_len = ChfStrlen( q );
|
size_t q_len = ChfStrlen( q );
|
||||||
size_t p_avail = p_end - p;
|
size_t p_avail = p_end - p;
|
||||||
|
|
||||||
if(q_len < p_avail)
|
if ( q_len < p_avail ) {
|
||||||
{
|
|
||||||
ChfStrcpy( p, q );
|
ChfStrcpy( p, q );
|
||||||
p += q_len;
|
p += q_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(p_avail > 1)
|
else if ( p_avail > 1 ) {
|
||||||
{
|
|
||||||
ChfStrncpy( p, q, p_avail - 2 );
|
ChfStrncpy( p, q, p_avail - 2 );
|
||||||
p[ p_avail - 1 ] = '\0';
|
p[ p_avail - 1 ] = '\0';
|
||||||
p = p_end;
|
p = p_end;
|
||||||
|
@ -282,7 +265,6 @@ static ChfChar *scopy(
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -328,18 +310,15 @@ static ChfChar *scopy(
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
const ChfChar* ChfGetMessage( /* Retrieve a condition message */
|
const ChfChar* ChfGetMessage( /* Retrieve a condition message */
|
||||||
const int module_id,
|
const int module_id, const int condition_code, const ChfChar* default_message )
|
||||||
const int condition_code,
|
|
||||||
const ChfChar *default_message
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
const ChfChar* message;
|
const ChfChar* message;
|
||||||
|
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
if((message = chf_context.mrs_get(chf_context.mrs_data,
|
if ( ( message = chf_context.mrs_get( chf_context.mrs_data, module_id, condition_code, default_message ) ) == default_message &&
|
||||||
module_id, condition_code, default_message)) == default_message &&
|
|
||||||
module_id == CHF_ERRNO_SET )
|
module_id == CHF_ERRNO_SET )
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
message = default_message;
|
message = default_message;
|
||||||
|
@ -350,7 +329,6 @@ const ChfChar *ChfGetMessage( /* Retrieve a condition message */
|
||||||
return ( message );
|
return ( message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfBuildMessage
|
.title : ChfBuildMessage
|
||||||
|
@ -386,8 +364,7 @@ const ChfChar *ChfGetMessage( /* Retrieve a condition message */
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
ChfChar* ChfBuildMessage( /* Build a condition message */
|
ChfChar* ChfBuildMessage( /* Build a condition message */
|
||||||
const ChfDescriptor *descriptor
|
const ChfDescriptor* descriptor )
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfChar* tmp_p;
|
ChfChar* tmp_p;
|
||||||
ChfChar* tmp_end;
|
ChfChar* tmp_end;
|
||||||
|
@ -395,7 +372,8 @@ ChfChar *ChfBuildMessage( /* Build a condition message */
|
||||||
ChfSeverity severity;
|
ChfSeverity severity;
|
||||||
|
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
/* Set appropriate pointers to the start/end of the message buffer */
|
/* Set appropriate pointers to the start/end of the message buffer */
|
||||||
tmp_p = chf_context.message_buffer;
|
tmp_p = chf_context.message_buffer;
|
||||||
|
@ -405,8 +383,7 @@ ChfChar *ChfBuildMessage( /* Build a condition message */
|
||||||
/* The message starts with "<app_name>: " if the condition is the first of
|
/* The message starts with "<app_name>: " if the condition is the first of
|
||||||
its condition group, with "\t" if not.
|
its condition group, with "\t" if not.
|
||||||
*/
|
*/
|
||||||
if(descriptor == chf_context.condition_sp-1)
|
if ( descriptor == chf_context.condition_sp - 1 ) {
|
||||||
{
|
|
||||||
tmp_p = scopy( tmp_p, chf_context.app_name, tmp_end );
|
tmp_p = scopy( tmp_p, chf_context.app_name, tmp_end );
|
||||||
tmp_p = scopy( tmp_p, separator, tmp_end );
|
tmp_p = scopy( tmp_p, separator, tmp_end );
|
||||||
}
|
}
|
||||||
|
@ -418,17 +395,13 @@ ChfChar *ChfBuildMessage( /* Build a condition message */
|
||||||
/* The message continues with the module name */
|
/* The message continues with the module name */
|
||||||
ChfSprintf( def_message, CHF_DEF_MID_MSG_FMT, ChfGetModuleId( descriptor ) );
|
ChfSprintf( def_message, CHF_DEF_MID_MSG_FMT, ChfGetModuleId( descriptor ) );
|
||||||
|
|
||||||
tmp_p = scopy(tmp_p,
|
tmp_p = scopy( tmp_p, ChfGetMessage( CHF_MODULE_NAMES_SET, ChfGetModuleId( descriptor ), def_message ), tmp_end );
|
||||||
ChfGetMessage(CHF_MODULE_NAMES_SET, ChfGetModuleId(descriptor),
|
|
||||||
def_message), tmp_end);
|
|
||||||
|
|
||||||
/* Add also the extended information, if any */
|
/* Add also the extended information, if any */
|
||||||
if(ChfGetLineNumber(descriptor) != CHF_UNKNOWN_LINE_NUMBER)
|
if ( ChfGetLineNumber( descriptor ) != CHF_UNKNOWN_LINE_NUMBER ) {
|
||||||
{
|
|
||||||
tmp_p = scopy( tmp_p, ChfText( " " ), tmp_end );
|
tmp_p = scopy( tmp_p, ChfText( " " ), tmp_end );
|
||||||
|
|
||||||
ChfSprintf(def_message, CHF_EXTENDED_INFO_FMT,
|
ChfSprintf( def_message, CHF_EXTENDED_INFO_FMT, ChfGetFileName( descriptor ), ChfGetLineNumber( descriptor ) );
|
||||||
ChfGetFileName(descriptor), ChfGetLineNumber(descriptor));
|
|
||||||
|
|
||||||
tmp_p = scopy( tmp_p, def_message, tmp_end );
|
tmp_p = scopy( tmp_p, def_message, tmp_end );
|
||||||
}
|
}
|
||||||
|
@ -438,8 +411,8 @@ ChfChar *ChfBuildMessage( /* Build a condition message */
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/* Add the severity code of the message */
|
/* Add the severity code of the message */
|
||||||
tmp_p = scopy( tmp_p,
|
tmp_p = scopy( tmp_p,
|
||||||
((severity = ChfGetSeverity(descriptor)) < CHF_SUCCESS ||
|
( ( severity = ChfGetSeverity( descriptor ) ) < CHF_SUCCESS || severity > CHF_FATAL ) ? CHF_UNKNOWN_SEVERITY
|
||||||
severity > CHF_FATAL) ? CHF_UNKNOWN_SEVERITY : severity_name[severity],
|
: severity_name[ severity ],
|
||||||
tmp_end );
|
tmp_end );
|
||||||
|
|
||||||
tmp_p = scopy( tmp_p, separator, tmp_end );
|
tmp_p = scopy( tmp_p, separator, tmp_end );
|
||||||
|
@ -452,7 +425,6 @@ ChfChar *ChfBuildMessage( /* Build a condition message */
|
||||||
return chf_context.message_buffer;
|
return chf_context.message_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfInit
|
.title : ChfInit
|
||||||
|
@ -515,37 +487,32 @@ int ChfInit( /* Generic initialization */
|
||||||
|
|
||||||
/* Check that CHF has not been initialized yet */
|
/* Check that CHF has not been initialized yet */
|
||||||
#ifndef _REENTRANT
|
#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
|
#else
|
||||||
/* Reentrant check; lock context_mutex first */
|
/* Reentrant check; lock context_mutex first */
|
||||||
if(pthread_mutex_lock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_lock( &context_mutex ) )
|
||||||
if(_chf_context.state != CHF_UNKNOWN)
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
{
|
if ( _chf_context.state != CHF_UNKNOWN ) {
|
||||||
if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
ChfAbort( CHF_ABORT_DUP_INIT );
|
ChfAbort( CHF_ABORT_DUP_INIT );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _REENTRANT
|
#ifndef _REENTRANT
|
||||||
if((_chf_context.condition_stack =
|
if ( ( _chf_context.condition_stack = ( ChfDescriptor* )malloc( ( size_t )( condition_stack_size + 1 ) * sizeof( ChfDescriptor ) ) ) ==
|
||||||
(ChfDescriptor *)
|
|
||||||
malloc((size_t)(condition_stack_size+1)*sizeof(ChfDescriptor))) ==
|
|
||||||
CHF_NULL_DESCRIPTOR )
|
CHF_NULL_DESCRIPTOR )
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
|
|
||||||
else if((_chf_context.handler_stack =
|
else if ( ( _chf_context.handler_stack = ( ChfHandlerDescriptor* )malloc(
|
||||||
(ChfHandlerDescriptor *)
|
( size_t )handler_stack_size * sizeof( ChfHandlerDescriptor ) ) ) == ( ChfHandlerDescriptor* )NULL ) {
|
||||||
malloc((size_t)handler_stack_size*sizeof(ChfHandlerDescriptor))) ==
|
|
||||||
(ChfHandlerDescriptor *)NULL)
|
|
||||||
{
|
|
||||||
free( _chf_context.condition_stack );
|
free( _chf_context.condition_stack );
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if((_chf_context.message_buffer =
|
else if ( ( _chf_context.message_buffer = ( ChfChar* )malloc( ( size_t )( CHF_MAX_MESSAGE_LENGTH ) * sizeof( ChfChar ) ) ) ==
|
||||||
(ChfChar *)malloc(
|
( ChfChar* )NULL ) {
|
||||||
(size_t)(CHF_MAX_MESSAGE_LENGTH) * sizeof(ChfChar))) == (ChfChar *)NULL)
|
|
||||||
{
|
|
||||||
free( _chf_context.condition_stack );
|
free( _chf_context.condition_stack );
|
||||||
free( _chf_context.handler_stack );
|
free( _chf_context.handler_stack );
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
|
@ -575,8 +542,7 @@ int ChfInit( /* Generic initialization */
|
||||||
_chf_context.condition_stack_size = condition_stack_size;
|
_chf_context.condition_stack_size = condition_stack_size;
|
||||||
_chf_context.handler_stack_size = handler_stack_size;
|
_chf_context.handler_stack_size = handler_stack_size;
|
||||||
_chf_context.exit_code = exit_code;
|
_chf_context.exit_code = exit_code;
|
||||||
_chf_context.condition_base = _chf_context.condition_sp =
|
_chf_context.condition_base = _chf_context.condition_sp = _chf_context.condition_stack;
|
||||||
_chf_context.condition_stack;
|
|
||||||
_chf_context.handler_sp = _chf_context.handler_stack;
|
_chf_context.handler_sp = _chf_context.handler_stack;
|
||||||
_chf_context.state = CHF_IDLE;
|
_chf_context.state = CHF_IDLE;
|
||||||
|
|
||||||
|
@ -591,13 +557,13 @@ int ChfInit( /* Generic initialization */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfExit
|
.title : ChfExit
|
||||||
|
@ -629,19 +595,19 @@ int ChfInit( /* Generic initialization */
|
||||||
- added multithreading support
|
- added multithreading support
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfExit(
|
void ChfExit( void )
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
#ifndef _REENTRANT
|
#ifndef _REENTRANT
|
||||||
if(_chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( _chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
#else
|
#else
|
||||||
/* Reentrant check; lock context_mutex first */
|
/* Reentrant check; lock context_mutex first */
|
||||||
if(pthread_mutex_lock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_lock( &context_mutex ) )
|
||||||
if(_chf_context.state == CHF_UNKNOWN)
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
{
|
if ( _chf_context.state == CHF_UNKNOWN ) {
|
||||||
if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
ChfAbort( CHF_ABORT_INIT );
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -657,8 +623,7 @@ void ChfExit(
|
||||||
*/
|
*/
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
DestroyContext( &chf_context );
|
DestroyContext( &chf_context );
|
||||||
if(pthread_setspecific(data_key, (void *)NULL))
|
if ( pthread_setspecific( data_key, ( void* )NULL ) ) {
|
||||||
{
|
|
||||||
( void )pthread_mutex_unlock( &context_mutex );
|
( void )pthread_mutex_unlock( &context_mutex );
|
||||||
ChfAbort( CHF_ABORT_PTHREAD );
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
}
|
}
|
||||||
|
@ -674,18 +639,19 @@ void ChfExit(
|
||||||
free( _chf_context.condition_stack );
|
free( _chf_context.condition_stack );
|
||||||
#else
|
#else
|
||||||
/* Destroy the Chf data key */
|
/* Destroy the Chf data key */
|
||||||
if(pthread_key_delete(data_key)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_key_delete( data_key ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Reset CHF state to prevent subsequent calls to ChfExit() itself */
|
/* Reset CHF state to prevent subsequent calls to ChfExit() itself */
|
||||||
_chf_context.state = CHF_UNKNOWN;
|
_chf_context.state = CHF_UNKNOWN;
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
if(pthread_mutex_unlock(&context_mutex)) ChfAbort(CHF_ABORT_PTHREAD);
|
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||||
|
ChfAbort( CHF_ABORT_PTHREAD );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : _ChfGetContext
|
.title : _ChfGetContext
|
||||||
|
@ -711,9 +677,7 @@ void ChfExit(
|
||||||
2.1, 19-May-2000, creation
|
2.1, 19-May-2000, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
ChfContext *_ChfGetContext(
|
ChfContext* _ChfGetContext( void )
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfContext* context;
|
ChfContext* context;
|
||||||
|
|
||||||
|
@ -724,44 +688,32 @@ ChfContext *_ChfGetContext(
|
||||||
#else
|
#else
|
||||||
/* Get the thread-specific context pointer associated with the
|
/* Get the thread-specific context pointer associated with the
|
||||||
CHF data key */
|
CHF data key */
|
||||||
if((context = (ChfContext *)pthread_getspecific(data_key))
|
if ( ( context = ( ChfContext* )pthread_getspecific( data_key ) ) == ( ChfContext* )NULL ) {
|
||||||
== (ChfContext *)NULL)
|
|
||||||
{
|
|
||||||
/* No context pointer; prime a new one, cloning the master context */
|
/* No context pointer; prime a new one, cloning the master context */
|
||||||
if((context = (ChfContext *)malloc(sizeof(ChfContext)))
|
if ( ( context = ( ChfContext* )malloc( sizeof( ChfContext ) ) ) == ( ChfContext* )NULL )
|
||||||
== (ChfContext *)NULL)
|
|
||||||
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
||||||
|
|
||||||
memcpy( context, &_chf_context, sizeof( ChfContext ) );
|
memcpy( context, &_chf_context, sizeof( ChfContext ) );
|
||||||
|
|
||||||
/* Allocate per-thread stacks and message buffer */
|
/* Allocate per-thread stacks and message buffer */
|
||||||
if((context->condition_stack =
|
if ( ( context->condition_stack = ( ChfDescriptor* )malloc( ( size_t )( context->condition_stack_size + 1 ) *
|
||||||
(ChfDescriptor *)
|
sizeof( ChfDescriptor ) ) ) == CHF_NULL_DESCRIPTOR )
|
||||||
malloc((size_t)(context->condition_stack_size+1)
|
|
||||||
*sizeof(ChfDescriptor))) == CHF_NULL_DESCRIPTOR)
|
|
||||||
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
||||||
|
|
||||||
if((context->handler_stack =
|
if ( ( context->handler_stack = ( ChfHandlerDescriptor* )malloc(
|
||||||
(ChfHandlerDescriptor *)
|
( size_t )( context->handler_stack_size ) * sizeof( ChfHandlerDescriptor ) ) ) == ( ChfHandlerDescriptor* )NULL ) {
|
||||||
malloc((size_t)(context->handler_stack_size)
|
|
||||||
*sizeof(ChfHandlerDescriptor))) == (ChfHandlerDescriptor *)NULL)
|
|
||||||
{
|
|
||||||
free( context->condition_stack );
|
free( context->condition_stack );
|
||||||
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
||||||
}
|
}
|
||||||
|
|
||||||
if((context->message_buffer =
|
if ( ( context->message_buffer = ( char* )malloc( ( size_t )( CHF_MAX_MESSAGE_LENGTH ) ) ) == ( char* )NULL ) {
|
||||||
(char *)
|
|
||||||
malloc((size_t)(CHF_MAX_MESSAGE_LENGTH))) == (char *)NULL)
|
|
||||||
{
|
|
||||||
free( context->condition_stack );
|
free( context->condition_stack );
|
||||||
free( context->handler_stack );
|
free( context->handler_stack );
|
||||||
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
ChfAbort( CHF_ABORT_GET_CONTEXT );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize stack pointers */
|
/* Initialize stack pointers */
|
||||||
context->condition_base = context->condition_sp =
|
context->condition_base = context->condition_sp = context->condition_stack;
|
||||||
context->condition_stack;
|
|
||||||
context->handler_sp = context->handler_stack;
|
context->handler_sp = context->handler_stack;
|
||||||
|
|
||||||
/* Set the thread-specific context pointer; this must be done
|
/* Set the thread-specific context pointer; this must be done
|
||||||
|
|
|
@ -52,7 +52,6 @@ static char rcs_id[] = "$Id: chf_msgc.c,v 2.2 2001/01/25 14:06:47 cibrario Exp $
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Global and static variables
|
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
|
#ifndef _WIN32
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
nl_catd catalog; /* Message catalog descriptor */
|
nl_catd catalog; /* Message catalog descriptor */
|
||||||
}
|
} ChfMsgcatContext;
|
||||||
ChfMsgcatContext;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static const char *GetMessage(
|
static const char* GetMessage( void* private_context, const int module_id, const int condition_code, const char* default_message )
|
||||||
void *private_context,
|
|
||||||
const int module_id,
|
|
||||||
const int condition_code,
|
|
||||||
const char *default_message
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return(catgets(((ChfMsgcatContext *)private_context)->catalog, module_id,
|
return ( catgets( ( ( ChfMsgcatContext* )private_context )->catalog, module_id, condition_code, default_message ) );
|
||||||
condition_code, default_message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExitMessage(
|
static void ExitMessage( void* private_context )
|
||||||
void *private_context
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
( void )catclose( ( ( ChfMsgcatContext* )private_context )->catalog );
|
( void )catclose( ( ( ChfMsgcatContext* )private_context )->catalog );
|
||||||
free( private_context );
|
free( private_context );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -166,28 +152,21 @@ int ChfMsgcatInit( /* Initialization with msgcat subsystem */
|
||||||
ChfMsgcatContext* private_context;
|
ChfMsgcatContext* private_context;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
if((private_context =
|
if ( ( private_context = ( ChfMsgcatContext* )malloc( sizeof( ChfMsgcatContext ) ) ) == ( ChfMsgcatContext* )NULL )
|
||||||
(ChfMsgcatContext *)malloc(sizeof(ChfMsgcatContext))) ==
|
|
||||||
(ChfMsgcatContext *)NULL)
|
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
|
|
||||||
else if(setlocale(LC_ALL, "") == (char *)NULL)
|
else if ( setlocale( LC_ALL, "" ) == ( char* )NULL ) {
|
||||||
{
|
|
||||||
free( private_context );
|
free( private_context );
|
||||||
cc = CHF_F_SETLOCALE;
|
cc = CHF_F_SETLOCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if((private_context->catalog = catopen(msgcat_name, 0)) ==
|
else if ( ( private_context->catalog = catopen( msgcat_name, 0 ) ) == ( nl_catd )( -1 ) ) {
|
||||||
(nl_catd)(-1))
|
|
||||||
{
|
|
||||||
free( private_context );
|
free( private_context );
|
||||||
cc = CHF_F_CATOPEN;
|
cc = CHF_F_CATOPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if((cc = ChfInit(app_name, options, (void *)private_context,
|
else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, GetMessage, ExitMessage, condition_stack_size,
|
||||||
GetMessage, ExitMessage, condition_stack_size, handler_stack_size,
|
handler_stack_size, exit_code ) ) != CHF_S_OK ) {
|
||||||
exit_code)) != CHF_S_OK)
|
|
||||||
{
|
|
||||||
( void )catclose( private_context->catalog );
|
( void )catclose( private_context->catalog );
|
||||||
free( private_context );
|
free( private_context );
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ static char rcs_id[] = "$Id: chf_sig.c,v 2.2 2001/01/25 14:07:42 cibrario Exp $"
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfSignal
|
.title : ChfSignal
|
||||||
|
@ -99,9 +98,7 @@ 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
|
- added support for structured condition handling
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfSignal(
|
void ChfSignal( void )
|
||||||
void
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfState saved_state;
|
ChfState saved_state;
|
||||||
ChfDescriptor* saved_condition_base;
|
ChfDescriptor* saved_condition_base;
|
||||||
|
@ -116,7 +113,8 @@ void ChfSignal(
|
||||||
CHF_UNWINDING change to CHF_SIGNAL_UNWINDING, otherwise remain in the
|
CHF_UNWINDING change to CHF_SIGNAL_UNWINDING, otherwise remain in the
|
||||||
previous state (that must be CHF_SIGNALING)
|
previous state (that must be CHF_SIGNALING)
|
||||||
*/
|
*/
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
saved_state = chf_context.state;
|
saved_state = chf_context.state;
|
||||||
|
|
||||||
if ( chf_context.state == CHF_IDLE )
|
if ( chf_context.state == CHF_IDLE )
|
||||||
|
@ -124,8 +122,7 @@ void ChfSignal(
|
||||||
else if ( chf_context.state == CHF_UNWINDING )
|
else if ( chf_context.state == CHF_UNWINDING )
|
||||||
chf_context.state = CHF_SIGNAL_UNWINDING;
|
chf_context.state = CHF_SIGNAL_UNWINDING;
|
||||||
|
|
||||||
if(chf_context.condition_sp > chf_context.condition_base)
|
if ( chf_context.condition_sp > chf_context.condition_base ) {
|
||||||
{
|
|
||||||
/* Save the base of the current condition group and then update it in
|
/* Save the base of the current condition group and then update it in
|
||||||
order to allow further generation of conditions inside the condition
|
order to allow further generation of conditions inside the condition
|
||||||
handlers that will be called soon.
|
handlers that will be called soon.
|
||||||
|
@ -142,9 +139,7 @@ void ChfSignal(
|
||||||
- when the current handler returns either CHF_CONTINUE or CHF_UNWIND
|
- when the current handler returns either CHF_CONTINUE or CHF_UNWIND
|
||||||
*/
|
*/
|
||||||
handler_result = CHF_RESIGNAL;
|
handler_result = CHF_RESIGNAL;
|
||||||
while(handler_result == CHF_RESIGNAL &&
|
while ( handler_result == CHF_RESIGNAL && chf_context.handler_sp > chf_context.handler_stack ) {
|
||||||
chf_context.handler_sp > chf_context.handler_stack)
|
|
||||||
{
|
|
||||||
chf_context.handler_sp--;
|
chf_context.handler_sp--;
|
||||||
|
|
||||||
/* The current condition handler, described by chf_context.handler_sp,
|
/* The current condition handler, described by chf_context.handler_sp,
|
||||||
|
@ -163,9 +158,8 @@ void ChfSignal(
|
||||||
it will call the handlers starting from chf_context.handler_sp-1,
|
it will call the handlers starting from chf_context.handler_sp-1,
|
||||||
that describes the handler immediately preceding the current handler.
|
that describes the handler immediately preceding the current handler.
|
||||||
*/
|
*/
|
||||||
handler_result = chf_context.handler_sp->handler(
|
handler_result =
|
||||||
current_condition, chf_context.state,
|
chf_context.handler_sp->handler( current_condition, chf_context.state, chf_context.handler_sp->handler_context );
|
||||||
chf_context.handler_sp->handler_context);
|
|
||||||
|
|
||||||
/* When the CHF state is CHF_SIGNALING, any condition group generated
|
/* When the CHF state is CHF_SIGNALING, any condition group generated
|
||||||
but not yet signalled when the current handler exits must be merged
|
but not yet signalled when the current handler exits must be merged
|
||||||
|
@ -179,10 +173,8 @@ void ChfSignal(
|
||||||
modifications are allowed on it, and the condition group is simply
|
modifications are allowed on it, and the condition group is simply
|
||||||
discarded.
|
discarded.
|
||||||
*/
|
*/
|
||||||
if(chf_context.condition_sp > chf_context.condition_base)
|
if ( chf_context.condition_sp > chf_context.condition_base ) {
|
||||||
{
|
if ( chf_context.state == CHF_SIGNALING ) {
|
||||||
if(chf_context.state == CHF_SIGNALING)
|
|
||||||
{
|
|
||||||
/* Force the new severity to CHF_FATAL if necessary */
|
/* Force the new severity to CHF_FATAL if necessary */
|
||||||
if ( ChfGetSeverity( current_condition ) == CHF_FATAL )
|
if ( ChfGetSeverity( current_condition ) == CHF_FATAL )
|
||||||
ChfGetSeverity( chf_context.condition_sp - 1 ) = CHF_FATAL;
|
ChfGetSeverity( chf_context.condition_sp - 1 ) = CHF_FATAL;
|
||||||
|
@ -200,14 +192,12 @@ void ChfSignal(
|
||||||
/* The action CHF_CONTINUE is not allowed if the current condition
|
/* The action CHF_CONTINUE is not allowed if the current condition
|
||||||
severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL
|
severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL
|
||||||
*/
|
*/
|
||||||
if(handler_result == CHF_CONTINUE &&
|
if ( handler_result == CHF_CONTINUE && ChfGetSeverity( current_condition ) == CHF_FATAL )
|
||||||
ChfGetSeverity(current_condition) == CHF_FATAL)
|
|
||||||
handler_result = CHF_RESIGNAL;
|
handler_result = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the action requested by the last condition handler invoked */
|
/* Perform the action requested by the last condition handler invoked */
|
||||||
switch(handler_result)
|
switch ( handler_result ) {
|
||||||
{
|
|
||||||
case CHF_CONTINUE:
|
case CHF_CONTINUE:
|
||||||
{
|
{
|
||||||
/* Restore the handler stack pointer; the next ChfSignal() invoked
|
/* Restore the handler stack pointer; the next ChfSignal() invoked
|
||||||
|
@ -217,8 +207,7 @@ void ChfSignal(
|
||||||
chf_context.handler_sp = saved_handler_sp;
|
chf_context.handler_sp = saved_handler_sp;
|
||||||
|
|
||||||
/* Discard the current condition group */
|
/* Discard the current condition group */
|
||||||
chf_context.condition_base = chf_context.condition_sp =
|
chf_context.condition_base = chf_context.condition_sp = saved_condition_base;
|
||||||
saved_condition_base;
|
|
||||||
|
|
||||||
/* Restore che saved CHF state */
|
/* Restore che saved CHF state */
|
||||||
chf_context.state = saved_state;
|
chf_context.state = saved_state;
|
||||||
|
@ -236,8 +225,7 @@ void ChfSignal(
|
||||||
if ( chf_context.state == CHF_UNWINDING )
|
if ( chf_context.state == CHF_UNWINDING )
|
||||||
ChfAbort( CHF_ABORT_ALREADY_UNWINDING );
|
ChfAbort( CHF_ABORT_ALREADY_UNWINDING );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Change CHF state */
|
/* Change CHF state */
|
||||||
chf_context.state = CHF_UNWINDING;
|
chf_context.state = CHF_UNWINDING;
|
||||||
|
|
||||||
|
@ -248,8 +236,7 @@ void ChfSignal(
|
||||||
*/
|
*/
|
||||||
handler_up = saved_handler_sp;
|
handler_up = saved_handler_sp;
|
||||||
|
|
||||||
while(handler_up > chf_context.handler_sp)
|
while ( handler_up > chf_context.handler_sp ) {
|
||||||
{
|
|
||||||
ChfAction unw_handler_result;
|
ChfAction unw_handler_result;
|
||||||
handler_up--;
|
handler_up--;
|
||||||
|
|
||||||
|
@ -273,9 +260,7 @@ void ChfSignal(
|
||||||
Further unwind requests are not allowed, and will trigger
|
Further unwind requests are not allowed, and will trigger
|
||||||
the condition CHF_F_UNWINDING
|
the condition CHF_F_UNWINDING
|
||||||
*/
|
*/
|
||||||
unw_handler_result = handler_up->handler(
|
unw_handler_result = handler_up->handler( current_condition, chf_context.state, handler_up->handler_context );
|
||||||
current_condition, chf_context.state,
|
|
||||||
handler_up->handler_context);
|
|
||||||
|
|
||||||
/* When the CHF state is CHF_UNWINDING, any condition group
|
/* When the CHF state is CHF_UNWINDING, any condition group
|
||||||
generated but not yet signalled when the current handler
|
generated but not yet signalled when the current handler
|
||||||
|
@ -292,17 +277,13 @@ void ChfSignal(
|
||||||
*/
|
*/
|
||||||
unwind_handler = chf_context.handler_sp;
|
unwind_handler = chf_context.handler_sp;
|
||||||
|
|
||||||
if(handler_result == CHF_UNWIND)
|
if ( handler_result == CHF_UNWIND ) {
|
||||||
{
|
|
||||||
/* Normal unwind:
|
/* Normal unwind:
|
||||||
restore the condition stack pointers, discarding all condition
|
restore the condition stack pointers, discarding all condition
|
||||||
groups.
|
groups.
|
||||||
*/
|
*/
|
||||||
chf_context.condition_base = chf_context.condition_sp =
|
chf_context.condition_base = chf_context.condition_sp = chf_context.condition_stack;
|
||||||
chf_context.condition_stack;
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Special unwind for structured condition handling:
|
/* Special unwind for structured condition handling:
|
||||||
restore the condition_base pointer only, to keep the
|
restore the condition_base pointer only, to keep the
|
||||||
topmost condition group on the condition stack. This way,
|
topmost condition group on the condition stack. This way,
|
||||||
|
@ -328,9 +309,7 @@ void ChfSignal(
|
||||||
|
|
||||||
case CHF_RESIGNAL:
|
case CHF_RESIGNAL:
|
||||||
{
|
{
|
||||||
ChfAbort(
|
ChfAbort( ( chf_context.state == CHF_SIGNALING ) ? CHF_ABORT_IMPROPERLY_HANDLED : CHF_ABORT_FATAL_UNWINDING );
|
||||||
(chf_context.state == CHF_SIGNALING) ?
|
|
||||||
CHF_ABORT_IMPROPERLY_HANDLED : CHF_ABORT_FATAL_UNWINDING);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -341,10 +320,8 @@ void ChfSignal(
|
||||||
condition if the broken handler isn't the last handler on the stack,
|
condition if the broken handler isn't the last handler on the stack,
|
||||||
otherwise call ChfAbort()
|
otherwise call ChfAbort()
|
||||||
*/
|
*/
|
||||||
if(chf_context.handler_sp > chf_context.handler_stack)
|
if ( chf_context.handler_sp > chf_context.handler_stack ) {
|
||||||
{
|
ChfCondition CHF_F_INVALID_ACTION, CHF_FATAL, handler_result ChfEnd;
|
||||||
ChfCondition CHF_F_INVALID_ACTION, CHF_FATAL, handler_result
|
|
||||||
ChfEnd;
|
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -361,7 +338,6 @@ void ChfSignal(
|
||||||
chf_context.state = saved_state;
|
chf_context.state = saved_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ChfDiscard
|
.title : ChfDiscard
|
||||||
|
@ -389,11 +365,11 @@ void ChfSignal(
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void ChfDiscard( /* Discard the current conditions */
|
void ChfDiscard( /* Discard the current conditions */
|
||||||
void
|
void )
|
||||||
)
|
|
||||||
{
|
{
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
/* Reset the current condition stack pointer to the current condition
|
/* Reset the current condition stack pointer to the current condition
|
||||||
stack base pointer
|
stack base pointer
|
||||||
|
|
|
@ -44,7 +44,6 @@ static char rcs_id[] = "$Id: chf_st.c,v 2.2 2001/01/25 14:08:45 cibrario Exp $";
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Global and static variables
|
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
|
Private type definitions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
const ChfTable* table;
|
const ChfTable* table;
|
||||||
size_t size;
|
size_t size;
|
||||||
}
|
} ChfStaticContext;
|
||||||
ChfStaticContext;
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
|
@ -69,13 +65,7 @@ typedef struct
|
||||||
/* Win32 does not have bsearch();
|
/* Win32 does not have bsearch();
|
||||||
provide a simple one from glibc here.
|
provide a simple one from glibc here.
|
||||||
*/
|
*/
|
||||||
static void *bsearch(
|
static void* bsearch( const void* key, const void* base, size_t nmemb, size_t size, int ( *compar )( const void*, const void* ) )
|
||||||
const void *key,
|
|
||||||
const void *base,
|
|
||||||
size_t nmemb,
|
|
||||||
size_t size,
|
|
||||||
int (*compar)(const void *, const void *)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
size_t l, u, idx;
|
size_t l, u, idx;
|
||||||
const void* p;
|
const void* p;
|
||||||
|
@ -83,8 +73,7 @@ static void *bsearch(
|
||||||
|
|
||||||
l = 0;
|
l = 0;
|
||||||
u = nmemb;
|
u = nmemb;
|
||||||
while (l < u)
|
while ( l < u ) {
|
||||||
{
|
|
||||||
idx = ( l + u ) / 2;
|
idx = ( l + u ) / 2;
|
||||||
p = ( void* )( ( ( const char* )base ) + ( idx * size ) );
|
p = ( void* )( ( ( const char* )base ) + ( idx * size ) );
|
||||||
comparison = ( *compar )( key, p );
|
comparison = ( *compar )( key, p );
|
||||||
|
@ -104,10 +93,7 @@ static void *bsearch(
|
||||||
#define LT -1
|
#define LT -1
|
||||||
#define EQ 0
|
#define EQ 0
|
||||||
|
|
||||||
static int Search(
|
static int Search( const void* l, const void* r )
|
||||||
const void *l,
|
|
||||||
const void *r
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if ( ( ( ChfTable* )l )->module > ( ( ChfTable* )r )->module )
|
if ( ( ( ChfTable* )l )->module > ( ( ChfTable* )r )->module )
|
||||||
return ( GT );
|
return ( GT );
|
||||||
|
@ -124,12 +110,7 @@ static int Search(
|
||||||
return ( EQ );
|
return ( EQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
static const ChfChar *StGetMessage(
|
static const ChfChar* StGetMessage( void* private_context, const int module_id, const int condition_code, const ChfChar* default_message )
|
||||||
void *private_context,
|
|
||||||
const int module_id,
|
|
||||||
const int condition_code,
|
|
||||||
const ChfChar *default_message
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfTable key;
|
ChfTable key;
|
||||||
ChfTable* res;
|
ChfTable* res;
|
||||||
|
@ -137,20 +118,14 @@ static const ChfChar *StGetMessage(
|
||||||
key.module = module_id;
|
key.module = module_id;
|
||||||
key.code = condition_code;
|
key.code = condition_code;
|
||||||
|
|
||||||
if((res = bsearch(&key, ((ChfStaticContext *)private_context)->table,
|
if ( ( res = bsearch( &key, ( ( ChfStaticContext* )private_context )->table, ( ( ChfStaticContext* )private_context )->size,
|
||||||
((ChfStaticContext *)private_context)->size, sizeof(ChfTable), Search)) ==
|
sizeof( ChfTable ), Search ) ) == ( void* )NULL )
|
||||||
(void *)NULL)
|
|
||||||
return ( default_message );
|
return ( default_message );
|
||||||
|
|
||||||
return ( ( ( ChfTable* )res )->msg_template );
|
return ( ( ( ChfTable* )res )->msg_template );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExitMessage(
|
static void ExitMessage( void* private_context ) {}
|
||||||
void *private_context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
|
@ -206,18 +181,14 @@ int ChfStaticInit( /* Initialization with static message tables */
|
||||||
ChfStaticContext* private_context;
|
ChfStaticContext* private_context;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
if((private_context =
|
if ( ( private_context = ( ChfStaticContext* )malloc( sizeof( ChfStaticContext ) ) ) == ( ChfStaticContext* )NULL )
|
||||||
(ChfStaticContext *)malloc(sizeof(ChfStaticContext))) ==
|
|
||||||
(ChfStaticContext *)NULL)
|
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
|
|
||||||
else if((cc = ChfInit(app_name, options, (void *)private_context,
|
else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, StGetMessage, ExitMessage, condition_stack_size,
|
||||||
StGetMessage, ExitMessage, condition_stack_size, handler_stack_size,
|
handler_stack_size, exit_code ) ) != CHF_S_OK )
|
||||||
exit_code)) != CHF_S_OK)
|
|
||||||
free( private_context );
|
free( private_context );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
private_context->table = table;
|
private_context->table = table;
|
||||||
private_context->size = table_size;
|
private_context->size = table_size;
|
||||||
cc = CHF_S_OK;
|
cc = CHF_S_OK;
|
||||||
|
|
|
@ -48,7 +48,6 @@ static char rcs_id[] = "$Id: chf_top.c,v 2.2 2001/01/25 14:09:21 cibrario Exp $"
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -94,16 +93,15 @@ static char rcs_id[] = "$Id: chf_top.c,v 2.2 2001/01/25 14:09:21 cibrario Exp $"
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
|
const ChfDescriptor* ChfGetTopCondition( /* Retrieve top condition */
|
||||||
void
|
void )
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ChfDescriptor* d;
|
ChfDescriptor* d;
|
||||||
|
|
||||||
/* Check that CHF has been correctly initialized */
|
/* Check that CHF has been correctly initialized */
|
||||||
if(chf_context.state == CHF_UNKNOWN) ChfAbort(CHF_ABORT_INIT);
|
if ( chf_context.state == CHF_UNKNOWN )
|
||||||
|
ChfAbort( CHF_ABORT_INIT );
|
||||||
|
|
||||||
if((d = chf_context.condition_sp) == chf_context.condition_base)
|
if ( ( d = chf_context.condition_sp ) == chf_context.condition_base ) {
|
||||||
{
|
|
||||||
ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
|
ChfCondition CHF_F_BAD_STATE, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ static char rcs_id[] = "$Id: chf_win32.c,v 2.2 2001/01/25 14:11:58 cibrario Exp
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
#include "ChfPriv.h"
|
#include "ChfPriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Global and static variables
|
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
|
#ifdef _WIN32
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
HINSTANCE instance; /* App. instance handle */
|
HINSTANCE instance; /* App. instance handle */
|
||||||
ChfChar buffer[ CHF_MAX_MESSAGE_LENGTH ]; /* Temporary buffer */
|
ChfChar buffer[ CHF_MAX_MESSAGE_LENGTH ]; /* Temporary buffer */
|
||||||
}
|
} ChfWin32Context;
|
||||||
ChfWin32Context;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static const ChfChar *Win32GetMessage(
|
static const ChfChar* Win32GetMessage( void* private_context, const int module_id, const int condition_code,
|
||||||
void *private_context,
|
const ChfChar* default_message )
|
||||||
const int module_id,
|
|
||||||
const int condition_code,
|
|
||||||
const ChfChar *default_message
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if(!LoadString(
|
if ( !LoadString( ( ( ChfWin32Context* )private_context )->instance, module_id * 1000 + condition_code,
|
||||||
((ChfWin32Context *)private_context)->instance,
|
( ( ChfWin32Context* )private_context )->buffer, CHF_MAX_MESSAGE_LENGTH - 1 ) )
|
||||||
module_id*1000 + condition_code,
|
|
||||||
((ChfWin32Context *)private_context)->buffer,
|
|
||||||
CHF_MAX_MESSAGE_LENGTH-1))
|
|
||||||
return default_message;
|
return default_message;
|
||||||
|
|
||||||
return ( ( ChfWin32Context* )private_context )->buffer;
|
return ( ( ChfWin32Context* )private_context )->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExitMessage(
|
static void ExitMessage( void* private_context ) { free( private_context ); }
|
||||||
void *private_context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
free(private_context);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
@ -165,20 +148,15 @@ int ChfWin32Init( /* Initialization within _WIN32 */
|
||||||
ChfWin32Context* private_context;
|
ChfWin32Context* private_context;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
if((private_context =
|
if ( ( private_context = ( ChfWin32Context* )malloc( sizeof( ChfWin32Context ) ) ) == ( ChfWin32Context* )NULL )
|
||||||
(ChfWin32Context *)malloc(sizeof(ChfWin32Context))) ==
|
|
||||||
(ChfWin32Context *)NULL)
|
|
||||||
cc = CHF_F_MALLOC;
|
cc = CHF_F_MALLOC;
|
||||||
|
|
||||||
else if((cc = ChfInit(app_name, options, (void *)private_context,
|
else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, Win32GetMessage, ExitMessage, condition_stack_size,
|
||||||
Win32GetMessage, ExitMessage, condition_stack_size, handler_stack_size,
|
handler_stack_size, exit_code ) ) != CHF_S_OK ) {
|
||||||
exit_code)) != CHF_S_OK)
|
|
||||||
{
|
|
||||||
free( private_context );
|
free( private_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Save Win32 specific context items into private Chf context */
|
/* Save Win32 specific context items into private Chf context */
|
||||||
private_context->instance = instance;
|
private_context->instance = instance;
|
||||||
|
|
||||||
|
|
0
src/libChf/resource.h
Executable file → Normal file
0
src/libChf/resource.h
Executable file → Normal file
|
@ -18,7 +18,6 @@
|
||||||
#define CHF_EXTENDED_INFO
|
#define CHF_EXTENDED_INFO
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
int st;
|
int st;
|
||||||
|
@ -38,37 +37,29 @@ int main(int argc, char *argv[])
|
||||||
message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not
|
message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not
|
||||||
*/
|
*/
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
||||||
if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Set_255,Message_1" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
||||||
if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Default_2" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
/* Generate a condition and check descriptor; this is line 46 */
|
/* Generate a condition and check descriptor; this is line 46 */
|
||||||
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 46 ||
|
||||||
|| d->condition_code != 3
|
strcmp( d->file_name, "test01.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_WARNING
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Generate another condition and check; this is line 60 */
|
||||||
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
||||||
|
|
||||||
if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( e = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
e->module_id != CHF_MODULE_ID
|
if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 60 ||
|
||||||
|| e->condition_code != 4
|
strcmp( e->file_name, "test01.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d )
|
||||||
|| e->severity != CHF_INFO
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Discard the previous condition group and create a new one */
|
||||||
ChfDiscard();
|
ChfDiscard();
|
||||||
|
@ -76,16 +67,11 @@ int main(int argc, char *argv[])
|
||||||
/* This is line 77 */
|
/* This is line 77 */
|
||||||
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 77 ||
|
||||||
|| d->condition_code != 5
|
strcmp( d->file_name, "test01.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_ERROR
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Exit Chf */
|
||||||
ChfExit();
|
ChfExit();
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#define CHF_EXTENDED_INFO
|
#define CHF_EXTENDED_INFO
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
|
|
||||||
|
|
||||||
void* task( void* arg )
|
void* task( void* arg )
|
||||||
{
|
{
|
||||||
const char* msg;
|
const char* msg;
|
||||||
|
@ -28,37 +27,29 @@ void *task(void *arg)
|
||||||
|
|
||||||
/* message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */
|
/* message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
||||||
if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Set_255,Message_1" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
||||||
if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Default_2" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
/* Generate a condition and check descriptor; this is line 36 */
|
/* Generate a condition and check descriptor; this is line 36 */
|
||||||
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 36 ||
|
||||||
|| d->condition_code != 3
|
strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_WARNING
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Generate another condition and check; this is line 50 */
|
||||||
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
||||||
|
|
||||||
if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( e = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
e->module_id != CHF_MODULE_ID
|
if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 50 ||
|
||||||
|| e->condition_code != 4
|
strcmp( e->file_name, "test02.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d )
|
||||||
|| e->severity != CHF_INFO
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Discard the previous condition group and create a new one */
|
||||||
ChfDiscard();
|
ChfDiscard();
|
||||||
|
@ -66,16 +57,11 @@ void *task(void *arg)
|
||||||
/* This is line 67 */
|
/* This is line 67 */
|
||||||
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 67 ||
|
||||||
|| d->condition_code != 5
|
strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_ERROR
|
exit( EXIT_FAILURE );
|
||||||
|| 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;
|
||||||
}
|
}
|
||||||
|
@ -100,16 +86,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Create */
|
/* Create */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(st = pthread_create(&(t[i]), NULL, task, (void *)i))
|
if ( st = pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
||||||
{
|
|
||||||
printf( "pthread_create: error %d", st );
|
printf( "pthread_create: error %d", st );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Join */
|
/* Join */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(st = pthread_join(t[i], &ret))
|
if ( st = pthread_join( t[ i ], &ret ) ) {
|
||||||
{
|
|
||||||
printf( "pthread_join: error %d", st );
|
printf( "pthread_join: error %d", st );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#define CHF_EXTENDED_INFO
|
#define CHF_EXTENDED_INFO
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
|
|
||||||
|
|
||||||
void* task( void* arg )
|
void* task( void* arg )
|
||||||
{
|
{
|
||||||
const char* msg;
|
const char* msg;
|
||||||
|
@ -67,16 +66,14 @@ int main(int argc, char *argv[])
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* Create */
|
/* Create */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_create(&(t[i]), NULL, task, (void *)i))
|
if ( pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_create" );
|
perror( "pthread_create" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Join */
|
/* Join */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_join(t[i], &ret))
|
if ( pthread_join( t[ i ], &ret ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_join" );
|
perror( "pthread_join" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,24 +21,17 @@
|
||||||
#define CHF_EXTENDED_INFO
|
#define CHF_EXTENDED_INFO
|
||||||
#include "Chf.h"
|
#include "Chf.h"
|
||||||
|
|
||||||
struct tdata_s
|
struct tdata_s {
|
||||||
{
|
|
||||||
const ChfDescriptor *d, *e;
|
const ChfDescriptor *d, *e;
|
||||||
int phase;
|
int phase;
|
||||||
};
|
};
|
||||||
|
|
||||||
ChfAction h1(
|
ChfAction h1( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
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;
|
ChfAction action;
|
||||||
|
|
||||||
if(c != tdata_p->e ||
|
if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) {
|
||||||
ChfGetNextDescriptor(c) != tdata_p->d)
|
|
||||||
{
|
|
||||||
ChfCondition 10, CHF_FATAL ChfEnd;
|
ChfCondition 10, CHF_FATAL ChfEnd;
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
|
@ -47,39 +40,30 @@ ChfAction h1(
|
||||||
action = CHF_CONTINUE;
|
action = CHF_CONTINUE;
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChfAction h2(
|
ChfAction h2( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
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;
|
ChfAction action;
|
||||||
|
|
||||||
switch(s)
|
switch ( s ) {
|
||||||
{
|
|
||||||
case CHF_SIGNALING:
|
case CHF_SIGNALING:
|
||||||
{
|
{
|
||||||
if(c != tdata_p->e
|
if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d || ( tdata_p->phase != 2 && tdata_p->phase != 4 ) ) {
|
||||||
|| ChfGetNextDescriptor(c) != tdata_p->d
|
|
||||||
|| (tdata_p->phase != 2 && tdata_p->phase != 4))
|
|
||||||
{
|
|
||||||
ChfCondition 10, CHF_FATAL ChfEnd;
|
ChfCondition 10, CHF_FATAL ChfEnd;
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
action = ( ChfGetConditionCode( c ) != 8 ? CHF_CONTINUE : CHF_UNWIND );
|
action = ( ChfGetConditionCode( c ) != 8 ? CHF_CONTINUE : CHF_UNWIND );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CHF_UNWINDING:
|
case CHF_UNWINDING:
|
||||||
{
|
{
|
||||||
if(tdata_p->phase != 4) exit(EXIT_FAILURE);
|
if ( tdata_p->phase != 4 )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
tdata_p->phase = 5;
|
tdata_p->phase = 5;
|
||||||
action = CHF_CONTINUE;
|
action = CHF_CONTINUE;
|
||||||
break;
|
break;
|
||||||
|
@ -92,30 +76,23 @@ ChfAction h2(
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChfAction h3(
|
ChfAction h3( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
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;
|
ChfAction action;
|
||||||
|
|
||||||
/* This handler must be invoked only during the first signal */
|
/* 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)
|
switch ( s ) {
|
||||||
{
|
|
||||||
case CHF_SIGNALING:
|
case CHF_SIGNALING:
|
||||||
{
|
{
|
||||||
if(ChfGetConditionCode(c) != 9 ||
|
if ( ChfGetConditionCode( c ) != 9 || ChfGetNextDescriptor( c ) != NULL ) {
|
||||||
ChfGetNextDescriptor(c) != NULL)
|
|
||||||
{
|
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
tdata_p->phase = 4;
|
tdata_p->phase = 4;
|
||||||
action = CHF_CONTINUE;
|
action = CHF_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -129,46 +106,37 @@ ChfAction h3(
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChfAction h4(
|
ChfAction h4( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
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;
|
ChfAction action;
|
||||||
|
|
||||||
/* This handler must be invoked only during the first signal */
|
/* 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)
|
switch ( s ) {
|
||||||
{
|
|
||||||
case CHF_SIGNALING:
|
case CHF_SIGNALING:
|
||||||
{
|
{
|
||||||
if(c != tdata_p->e
|
if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) {
|
||||||
|| ChfGetNextDescriptor(c) != tdata_p->d)
|
|
||||||
{
|
|
||||||
ChfCondition 10, CHF_FATAL ChfEnd;
|
ChfCondition 10, CHF_FATAL ChfEnd;
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* This generates a new group and signals it */
|
/* This generates a new group and signals it */
|
||||||
tdata_p->phase = 3;
|
tdata_p->phase = 3;
|
||||||
ChfCondition 9, CHF_INFO ChfEnd;
|
ChfCondition 9, CHF_INFO ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
if(tdata_p->phase != 4) exit(EXIT_FAILURE);
|
if ( tdata_p->phase != 4 )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
tdata_p->phase = 5;
|
tdata_p->phase = 5;
|
||||||
|
|
||||||
if(c != tdata_p->e
|
if ( c != tdata_p->e || ChfGetNextDescriptor( c ) != tdata_p->d ) {
|
||||||
|| ChfGetNextDescriptor(c) != tdata_p->d)
|
|
||||||
{
|
|
||||||
ChfCondition 10, CHF_FATAL ChfEnd;
|
ChfCondition 10, CHF_FATAL ChfEnd;
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
action = CHF_CONTINUE;
|
action = CHF_CONTINUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -221,8 +189,7 @@ void *task(void *arg)
|
||||||
sigjmp_buf jb;
|
sigjmp_buf jb;
|
||||||
|
|
||||||
tdata.phase = 0;
|
tdata.phase = 0;
|
||||||
if(setjmp(jb) == 0)
|
if ( setjmp( jb ) == 0 ) {
|
||||||
{
|
|
||||||
ChfPushHandler( h2, jb, ( ChfPointer )( &tdata ) );
|
ChfPushHandler( h2, jb, ( ChfPointer )( &tdata ) );
|
||||||
|
|
||||||
/* Generate a condition group and signal it */
|
/* Generate a condition group and signal it */
|
||||||
|
@ -248,9 +215,7 @@ void *task(void *arg)
|
||||||
|
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Unwind */
|
/* Unwind */
|
||||||
if ( tdata.phase != 5 )
|
if ( tdata.phase != 5 )
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
|
@ -308,16 +273,14 @@ int main(int argc, char *argv[])
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* Create */
|
/* Create */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_create(&(t[i]), NULL, task, (void *)i))
|
if ( pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_create" );
|
perror( "pthread_create" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Join */
|
/* Join */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_join(t[i], &ret))
|
if ( pthread_join( t[ i ], &ret ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_join" );
|
perror( "pthread_join" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,43 +27,25 @@
|
||||||
/* Dummy handler; pushed only to verify that the handler stack overflow
|
/* Dummy handler; pushed only to verify that the handler stack overflow
|
||||||
checks are correct.
|
checks are correct.
|
||||||
*/
|
*/
|
||||||
ChfAction h1(
|
ChfAction h1( const ChfDescriptor* c, const ChfState s, ChfPointer p ) { return CHF_RESIGNAL; }
|
||||||
const ChfDescriptor *c,
|
|
||||||
const ChfState s,
|
|
||||||
ChfPointer p
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return CHF_RESIGNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Overflow check handler; it unwinds if the CHF_F_HDLR_STACK_FULL
|
/* Overflow check handler; it unwinds if the CHF_F_HDLR_STACK_FULL
|
||||||
condition is signalled exactly after H_STACK_SIZE-2 invocations
|
condition is signalled exactly after H_STACK_SIZE-2 invocations
|
||||||
of ChfPushHandler(), it resignals a modified condition if the
|
of ChfPushHandler(), it resignals a modified condition if the
|
||||||
condition is signalled too early
|
condition is signalled too early
|
||||||
*/
|
*/
|
||||||
ChfAction h2(
|
ChfAction h2( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
const ChfDescriptor *c,
|
|
||||||
const ChfState s,
|
|
||||||
ChfPointer p
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int push_count = *( ( int* )p );
|
int push_count = *( ( int* )p );
|
||||||
ChfAction action;
|
ChfAction action;
|
||||||
|
|
||||||
if(s == CHF_SIGNALING)
|
if ( s == CHF_SIGNALING ) {
|
||||||
{
|
if ( ChfGetModuleId( c ) == CHF_SET && ChfGetConditionCode( c ) == CHF_F_HDLR_STACK_FULL ) {
|
||||||
if(ChfGetModuleId(c) == CHF_SET
|
|
||||||
&& ChfGetConditionCode(c) == CHF_F_HDLR_STACK_FULL)
|
|
||||||
{
|
|
||||||
/* Handler stack is full; check correctness of the descriptor */
|
/* Handler stack is full; check correctness of the descriptor */
|
||||||
if(push_count == H_STACK_SIZE-2
|
if ( push_count == H_STACK_SIZE - 2 && ChfGetNextDescriptor( c ) == NULL && ChfGetSeverity( c ) == CHF_FATAL )
|
||||||
&& ChfGetNextDescriptor(c) == NULL
|
|
||||||
&& ChfGetSeverity(c) == CHF_FATAL)
|
|
||||||
action = CHF_UNWIND;
|
action = CHF_UNWIND;
|
||||||
else
|
else {
|
||||||
{
|
ChfCondition 11, CHF_FATAL, push_count, H_STACK_SIZE - 2 ChfEnd;
|
||||||
ChfCondition 11, CHF_FATAL, push_count, H_STACK_SIZE-2
|
|
||||||
ChfEnd;
|
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,29 +62,18 @@ ChfAction h2(
|
||||||
of ChfCondition, it resignals a modified condition if the
|
of ChfCondition, it resignals a modified condition if the
|
||||||
condition is signalled too early
|
condition is signalled too early
|
||||||
*/
|
*/
|
||||||
ChfAction h3(
|
ChfAction h3( const ChfDescriptor* c, const ChfState s, ChfPointer p )
|
||||||
const ChfDescriptor *c,
|
|
||||||
const ChfState s,
|
|
||||||
ChfPointer p
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int push_count = *( ( int* )p );
|
int push_count = *( ( int* )p );
|
||||||
ChfAction action;
|
ChfAction action;
|
||||||
|
|
||||||
if(s == CHF_SIGNALING)
|
if ( s == CHF_SIGNALING ) {
|
||||||
{
|
if ( ChfGetModuleId( c ) == CHF_SET && ChfGetConditionCode( c ) == CHF_F_COND_STACK_FULL ) {
|
||||||
if(ChfGetModuleId(c) == CHF_SET
|
|
||||||
&& ChfGetConditionCode(c) == CHF_F_COND_STACK_FULL)
|
|
||||||
{
|
|
||||||
/* Handler stack is full; check correctness of the descriptor */
|
/* Handler stack is full; check correctness of the descriptor */
|
||||||
if(push_count == C_STACK_SIZE
|
if ( push_count == C_STACK_SIZE && ChfGetNextDescriptor( c ) == NULL && ChfGetSeverity( c ) == CHF_FATAL )
|
||||||
&& ChfGetNextDescriptor(c) == NULL
|
|
||||||
&& ChfGetSeverity(c) == CHF_FATAL)
|
|
||||||
action = CHF_UNWIND;
|
action = CHF_UNWIND;
|
||||||
else
|
else {
|
||||||
{
|
ChfCondition 12, CHF_FATAL, push_count, C_STACK_SIZE ChfEnd;
|
||||||
ChfCondition 12, CHF_FATAL, push_count, C_STACK_SIZE
|
|
||||||
ChfEnd;
|
|
||||||
action = CHF_RESIGNAL;
|
action = CHF_RESIGNAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +85,6 @@ ChfAction h3(
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* task( void* arg )
|
void* task( void* arg )
|
||||||
{
|
{
|
||||||
int push_count = 0;
|
int push_count = 0;
|
||||||
|
@ -126,8 +96,7 @@ void *task(void *arg)
|
||||||
printf( "\tThread %d\n", ( int )arg );
|
printf( "\tThread %d\n", ( int )arg );
|
||||||
|
|
||||||
/* Check handler stack overflow checks */
|
/* Check handler stack overflow checks */
|
||||||
if(sigsetjmp(jb, 1) == 0)
|
if ( sigsetjmp( jb, 1 ) == 0 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Push the handler */
|
/* Push the handler */
|
||||||
|
@ -149,8 +118,7 @@ void *task(void *arg)
|
||||||
Check condition stack overflow checks
|
Check condition stack overflow checks
|
||||||
*/
|
*/
|
||||||
push_count = 0;
|
push_count = 0;
|
||||||
if(sigsetjmp(jb, 1) == 0)
|
if ( sigsetjmp( jb, 1 ) == 0 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Push the handler */
|
/* Push the handler */
|
||||||
|
@ -173,8 +141,7 @@ void *task(void *arg)
|
||||||
conditions were left out in the previous check.
|
conditions were left out in the previous check.
|
||||||
*/
|
*/
|
||||||
push_count = 0;
|
push_count = 0;
|
||||||
if(sigsetjmp(jb, 1) == 0)
|
if ( sigsetjmp( jb, 1 ) == 0 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Push the handler */
|
/* Push the handler */
|
||||||
|
@ -194,7 +161,6 @@ void *task(void *arg)
|
||||||
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[] )
|
||||||
|
@ -210,28 +176,23 @@ int main(int argc, char *argv[])
|
||||||
puts( "test05" );
|
puts( "test05" );
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat",
|
if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE ) )
|
||||||
C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE))
|
|
||||||
exit( st );
|
exit( st );
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* Create */
|
/* Create */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_create(&(t[i]), NULL, task, (void *)i))
|
if ( pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_create" );
|
perror( "pthread_create" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Join */
|
/* Join */
|
||||||
for(i=0; i<N_THREADS; i++)
|
for ( i = 0; i < N_THREADS; i++ ) {
|
||||||
{
|
if ( pthread_join( t[ i ], &ret ) ) {
|
||||||
if(pthread_join(t[i], &ret))
|
|
||||||
{
|
|
||||||
perror( "pthread_join" );
|
perror( "pthread_join" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
} else if ( ( int )ret != EXIT_SUCCESS )
|
||||||
else if((int)ret != EXIT_SUCCESS)
|
|
||||||
exit( ( int )ret );
|
exit( ( int )ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,4 +205,3 @@ int main(int argc, char *argv[])
|
||||||
ChfExit();
|
ChfExit();
|
||||||
exit( st );
|
exit( st );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#define H_STACK_SIZE 10
|
#define H_STACK_SIZE 10
|
||||||
#define C_STACK_SIZE 30
|
#define C_STACK_SIZE 30
|
||||||
|
|
||||||
|
|
||||||
void* task( void* arg )
|
void* task( void* arg )
|
||||||
{
|
{
|
||||||
volatile int phase = 0;
|
volatile int phase = 0;
|
||||||
|
@ -58,26 +57,18 @@ void *task(void *arg)
|
||||||
{
|
{
|
||||||
/* Catched an exception; check descriptor */
|
/* Catched an exception; check descriptor */
|
||||||
const ChfDescriptor* d = ChfGetTopCondition();
|
const ChfDescriptor* d = ChfGetTopCondition();
|
||||||
if(d == NULL
|
if ( d == NULL || ChfGetNextDescriptor( d ) != NULL || ChfGetModuleId( d ) != CHF_MODULE_ID || ChfGetConditionCode( d ) != 20 )
|
||||||
|| ChfGetNextDescriptor(d) != NULL
|
|
||||||
|| ChfGetModuleId(d) != CHF_MODULE_ID
|
|
||||||
|| ChfGetConditionCode(d) != 20)
|
|
||||||
return ( void* )EXIT_FAILURE;
|
return ( void* )EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
ChfEndTry;
|
ChfEndTry;
|
||||||
|
|
||||||
/* Check that the condition stack actually is empty after catch */
|
/* Check that the condition stack actually is empty after catch */
|
||||||
ChfTry
|
ChfTry { const volatile ChfDescriptor* e = ChfGetTopCondition(); }
|
||||||
{
|
|
||||||
volatile const ChfDescriptor *e = ChfGetTopCondition();
|
|
||||||
}
|
|
||||||
ChfCatch
|
ChfCatch
|
||||||
{
|
{
|
||||||
const ChfDescriptor* d = ChfGetTopCondition();
|
const ChfDescriptor* d = ChfGetTopCondition();
|
||||||
if(d == NULL
|
if ( d == NULL || ChfGetNextDescriptor( d ) != NULL || ChfGetModuleId( d ) != CHF_SET ||
|
||||||
|| ChfGetNextDescriptor(d) != NULL
|
ChfGetConditionCode( d ) != CHF_F_BAD_STATE )
|
||||||
|| ChfGetModuleId(d) != CHF_SET
|
|
||||||
|| ChfGetConditionCode(d) != CHF_F_BAD_STATE)
|
|
||||||
return ( void* )EXIT_FAILURE;
|
return ( void* )EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
ChfEndTry;
|
ChfEndTry;
|
||||||
|
@ -85,7 +76,6 @@ void *task(void *arg)
|
||||||
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[] )
|
||||||
|
@ -101,28 +91,23 @@ int main(int argc, char *argv[])
|
||||||
puts( "test06" );
|
puts( "test06" );
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
if(st = ChfMsgcatInit(argv[0], CHF_DEFAULT, "./test01.cat",
|
if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE ) )
|
||||||
C_STACK_SIZE, H_STACK_SIZE, EXIT_FAILURE))
|
|
||||||
exit( st );
|
exit( st );
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* Create */
|
/* Create */
|
||||||
for ( i = 0; i < N_THREADS; i++ )
|
for ( i = 0; i < N_THREADS; i++ )
|
||||||
if(pthread_create(&(t[i]), NULL, task, (void *)i))
|
if ( pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
||||||
{
|
|
||||||
perror( "pthread_create" );
|
perror( "pthread_create" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Join */
|
/* Join */
|
||||||
for(i=0; i<N_THREADS; i++)
|
for ( i = 0; i < N_THREADS; i++ ) {
|
||||||
{
|
if ( pthread_join( t[ i ], &ret ) ) {
|
||||||
if(pthread_join(t[i], &ret))
|
|
||||||
{
|
|
||||||
perror( "pthread_join" );
|
perror( "pthread_join" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
} else if ( ( int )ret != EXIT_SUCCESS )
|
||||||
else if((int)ret != EXIT_SUCCESS)
|
|
||||||
exit( ( int )ret );
|
exit( ( int )ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,4 +120,3 @@ int main(int argc, char *argv[])
|
||||||
ChfExit();
|
ChfExit();
|
||||||
exit( st );
|
exit( st );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,45 +30,36 @@ int main(int argc, char *argv[])
|
||||||
puts( "test07" );
|
puts( "test07" );
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
if(st = ChfStaticInit(argv[0], CHF_DEFAULT,
|
if ( st = ChfStaticInit( argv[ 0 ], CHF_DEFAULT, message_table, message_table_size, 50, 10, 1 ) )
|
||||||
message_table, message_table_size, 50, 10, 1))
|
|
||||||
exit( st );
|
exit( st );
|
||||||
|
|
||||||
/* ChfGetMessage:
|
/* ChfGetMessage:
|
||||||
message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not
|
message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not
|
||||||
*/
|
*/
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
||||||
if(strcmp(msg, "Set_255,Message_1")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Set_255,Message_1" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
||||||
if(strcmp(msg, "Default_2")) exit(EXIT_FAILURE);
|
if ( strcmp( msg, "Default_2" ) )
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
/* Generate a condition and check descriptor; this is line 46 */
|
/* Generate a condition and check descriptor; this is line 46 */
|
||||||
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 46 ||
|
||||||
|| d->condition_code != 3
|
strcmp( d->file_name, "test07.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_WARNING
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Generate another condition and check; this is line 60 */
|
||||||
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
||||||
|
|
||||||
if((e = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( e = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
e->module_id != CHF_MODULE_ID
|
if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 60 ||
|
||||||
|| e->condition_code != 4
|
strcmp( e->file_name, "test07.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d )
|
||||||
|| e->severity != CHF_INFO
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Discard the previous condition group and create a new one */
|
||||||
ChfDiscard();
|
ChfDiscard();
|
||||||
|
@ -76,24 +67,18 @@ int main(int argc, char *argv[])
|
||||||
/* This is line 77 */
|
/* This is line 77 */
|
||||||
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
||||||
|
|
||||||
if((d = ChfGetTopCondition()) == NULL) exit(EXIT_FAILURE);
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
||||||
if(
|
exit( EXIT_FAILURE );
|
||||||
d->module_id != CHF_MODULE_ID
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 77 ||
|
||||||
|| d->condition_code != 5
|
strcmp( d->file_name, "test07.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL )
|
||||||
|| d->severity != CHF_ERROR
|
exit( EXIT_FAILURE );
|
||||||
|| 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 */
|
/* Exit Chf */
|
||||||
ChfExit();
|
ChfExit();
|
||||||
exit( EXIT_SUCCESS );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
ChfTable message_table[] =
|
ChfTable message_table[] = {
|
||||||
{
|
|
||||||
{CHF_MODULE_ID, 1, "Set_255,Message_1" },
|
{CHF_MODULE_ID, 1, "Set_255,Message_1" },
|
||||||
{CHF_MODULE_ID, 3, "Set_255,Arg_%d,Message_3" },
|
{CHF_MODULE_ID, 3, "Set_255,Arg_%d,Message_3" },
|
||||||
{CHF_MODULE_ID, 4, "Set_255,Arg_%s,Message_4" },
|
{CHF_MODULE_ID, 4, "Set_255,Arg_%s,Message_4" },
|
||||||
|
|
|
@ -60,7 +60,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Data type definitions
|
Data type definitions
|
||||||
All Data types must be SIGNED
|
All Data types must be SIGNED
|
||||||
|
|
55
src/main.c
55
src/main.c
|
@ -114,7 +114,6 @@ static char rcs_id[] = "$Id: saturn.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
/* Chf condition codes (main program only) */
|
/* Chf condition codes (main program only) */
|
||||||
|
|
||||||
#define CHF_MODULE_ID MAIN_CHF_MODULE_ID
|
#define CHF_MODULE_ID MAIN_CHF_MODULE_ID
|
||||||
|
@ -123,7 +122,6 @@ static char rcs_id[] = "$Id: saturn.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define MAIN_M_COPYRIGHT 501
|
#define MAIN_M_COPYRIGHT 501
|
||||||
#define MAIN_M_LICENSE 502
|
#define MAIN_M_LICENSE 502
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf parameters - Do not change.
|
Chf parameters - Do not change.
|
||||||
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
||||||
|
@ -142,11 +140,9 @@ static const char cat_suffix[] = ".cat";
|
||||||
#define CAT_PREFIX_LEN ( sizeof( cat_prefix ) + 1 )
|
#define CAT_PREFIX_LEN ( sizeof( cat_prefix ) + 1 )
|
||||||
#define CAT_SUFFIX_LEN ( sizeof( cat_suffix ) + 1 )
|
#define CAT_SUFFIX_LEN ( sizeof( cat_suffix ) + 1 )
|
||||||
|
|
||||||
|
|
||||||
static void adjust_setlocale( void )
|
static void adjust_setlocale( void )
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf( stderr, "saturn-W-locale probably bad; reverting to C locale\n" );
|
||||||
"saturn-W-locale probably bad; reverting to C locale\n");
|
|
||||||
|
|
||||||
putenv( "LC_ALL=C" );
|
putenv( "LC_ALL=C" );
|
||||||
putenv( "LC_COLLATE=C" );
|
putenv( "LC_COLLATE=C" );
|
||||||
|
@ -158,12 +154,10 @@ static void adjust_setlocale(void)
|
||||||
putenv( "LANG=C" );
|
putenv( "LANG=C" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : main
|
.title : main
|
||||||
|
@ -188,9 +182,7 @@ int main(int argc, char *argv[])
|
||||||
int st;
|
int st;
|
||||||
int retry = 0;
|
int retry = 0;
|
||||||
|
|
||||||
if((cat_name = malloc(strlen(argv[0])+CAT_PREFIX_LEN+CAT_SUFFIX_LEN+1))
|
if ( ( cat_name = malloc( strlen( argv[ 0 ] ) + CAT_PREFIX_LEN + CAT_SUFFIX_LEN + 1 ) ) == NULL ) {
|
||||||
== NULL)
|
|
||||||
{
|
|
||||||
fprintf( stderr, "saturn-E-cat_name initialization failed\n" );
|
fprintf( stderr, "saturn-E-cat_name initialization failed\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
@ -203,63 +195,57 @@ int main(int argc, char *argv[])
|
||||||
the second time, adjust the setlocale() environment variables
|
the second time, adjust the setlocale() environment variables
|
||||||
with adjust_setlocale()
|
with adjust_setlocale()
|
||||||
*/
|
*/
|
||||||
while(retry < 2)
|
while ( retry < 2 ) {
|
||||||
{
|
|
||||||
/* Chf initialization with msgcat subsystem; notice that on
|
/* Chf initialization with msgcat subsystem; notice that on
|
||||||
some systems (e.g. Digital UNIX) catopen() can succeed even
|
some systems (e.g. Digital UNIX) catopen() can succeed even
|
||||||
if it was not able to open the right message catalog;
|
if it was not able to open the right message catalog;
|
||||||
better try it now.
|
better try it now.
|
||||||
*/
|
*/
|
||||||
if((st = ChfMsgcatInit(
|
if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */
|
||||||
argv[0], /* Application's name */
|
|
||||||
CHF_DEFAULT, /* Options */
|
CHF_DEFAULT, /* Options */
|
||||||
cat_name, /* Name of the message catalog */
|
cat_name, /* Name of the message catalog */
|
||||||
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
||||||
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
||||||
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
||||||
)) != CHF_S_OK
|
) ) != CHF_S_OK ||
|
||||||
||
|
|
||||||
ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL )
|
ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL )
|
||||||
fprintf(stderr,
|
fprintf( stderr, "saturn-E-Primary Chf initialization failed (%d)\n", st );
|
||||||
"saturn-E-Primary Chf initialization failed (%d)\n", st);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Bring down Chf before initializing it again */
|
/* Bring down Chf before initializing it again */
|
||||||
if(st == CHF_S_OK) ChfExit();
|
if ( st == CHF_S_OK )
|
||||||
|
ChfExit();
|
||||||
|
|
||||||
/* Try alternate message catalog name (with prefix) */
|
/* Try alternate message catalog name (with prefix) */
|
||||||
strcpy( cat_name, cat_prefix );
|
strcpy( cat_name, cat_prefix );
|
||||||
strcat( cat_name, argv[ 0 ] );
|
strcat( cat_name, argv[ 0 ] );
|
||||||
strcat( cat_name, cat_suffix );
|
strcat( cat_name, cat_suffix );
|
||||||
|
|
||||||
if((st = ChfMsgcatInit(
|
if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */
|
||||||
argv[0], /* Application's name */
|
|
||||||
CHF_DEFAULT, /* Options */
|
CHF_DEFAULT, /* Options */
|
||||||
cat_name, /* Name of the message catalog */
|
cat_name, /* Name of the message catalog */
|
||||||
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
||||||
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
||||||
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
||||||
)) != CHF_S_OK
|
) ) != CHF_S_OK ||
|
||||||
||
|
|
||||||
ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL )
|
ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, NULL ) == NULL )
|
||||||
fprintf(stderr,
|
fprintf( stderr, "saturn-E-Alternate Chf initialization failed (%d)\n", st );
|
||||||
"saturn-E-Alternate Chf initialization failed (%d)\n",
|
|
||||||
st);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Bring down Chf before initializing it again */
|
/* Bring down Chf before initializing it again */
|
||||||
if(st == CHF_S_OK) ChfExit();
|
if ( st == CHF_S_OK )
|
||||||
|
ChfExit();
|
||||||
|
|
||||||
/* Attempt to adjust setlocale() environment variables */
|
/* Attempt to adjust setlocale() environment variables */
|
||||||
if(retry++ == 0) adjust_setlocale();
|
if ( retry++ == 0 )
|
||||||
|
adjust_setlocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retry == 2)
|
if ( retry == 2 ) {
|
||||||
{
|
|
||||||
fprintf( stderr, "saturn-F-Application aborted\n" );
|
fprintf( stderr, "saturn-F-Application aborted\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
@ -268,8 +254,7 @@ int main(int argc, char *argv[])
|
||||||
free( cat_name );
|
free( cat_name );
|
||||||
|
|
||||||
/* 3.9: Print out MAIN_M_COPYRIGHT and MAIN_M_LICENSE on stdout now */
|
/* 3.9: Print out MAIN_M_COPYRIGHT and MAIN_M_LICENSE on stdout now */
|
||||||
fprintf(stdout, ChfGetMessage(CHF_MODULE_ID, MAIN_M_COPYRIGHT, ""),
|
fprintf( stdout, ChfGetMessage( CHF_MODULE_ID, MAIN_M_COPYRIGHT, "" ), "$Revision: 4.1 $" );
|
||||||
"$Revision: 4.1 $");
|
|
||||||
fprintf( stdout, ChfGetMessage( CHF_MODULE_ID, MAIN_M_LICENSE, "" ) );
|
fprintf( stdout, ChfGetMessage( CHF_MODULE_ID, MAIN_M_LICENSE, "" ) );
|
||||||
|
|
||||||
/* Initialize GUI and associated lcd display emulation module */
|
/* Initialize GUI and associated lcd display emulation module */
|
||||||
|
@ -287,16 +272,14 @@ int main(int argc, char *argv[])
|
||||||
EmulatorInit();
|
EmulatorInit();
|
||||||
|
|
||||||
/* 3.15: Repeat copyright message on GUI if stdout is not a tty */
|
/* 3.15: Repeat copyright message on GUI if stdout is not a tty */
|
||||||
if(! isatty(fileno(stdout)))
|
if ( !isatty( fileno( stdout ) ) ) {
|
||||||
{
|
|
||||||
ChfCondition MAIN_M_LICENSE, CHF_INFO ChfEnd;
|
ChfCondition MAIN_M_LICENSE, CHF_INFO ChfEnd;
|
||||||
ChfCondition MAIN_M_COPYRIGHT, CHF_INFO, "$Revision: 4.1 $" ChfEnd;
|
ChfCondition MAIN_M_COPYRIGHT, CHF_INFO, "$Revision: 4.1 $" ChfEnd;
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.monitor)
|
if ( args.monitor ) {
|
||||||
{
|
|
||||||
/* Invoke Monitor */
|
/* Invoke Monitor */
|
||||||
void Monitor( void );
|
void Monitor( void );
|
||||||
Monitor();
|
Monitor();
|
||||||
|
|
259
src/modules.c
259
src/modules.c
|
@ -131,7 +131,6 @@ static char rcs_id[] = "$Id: modules.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Static/Global variables
|
Static/Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -159,7 +158,6 @@ static struct ModMap *cache_head = (struct ModMap *)NULL;
|
||||||
*/
|
*/
|
||||||
static const struct ModDescriptionEntry* mod_description;
|
static const struct ModDescriptionEntry* mod_description;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Debugging & performance analysis data
|
Debugging & performance analysis data
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -197,7 +195,6 @@ static int repl_c = 0; /* Entry replacement counter */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -235,7 +232,6 @@ static Nibble BadRead(Address addr)
|
||||||
return ( Nibble )0x0;
|
return ( Nibble )0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : BadWrite
|
.title : BadWrite
|
||||||
|
@ -266,7 +262,6 @@ static void BadWrite(Address addr, Nibble datum)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RebuildPageTable
|
.title : RebuildPageTable
|
||||||
|
@ -309,8 +304,7 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RebuildPageTable" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RebuildPageTable" );
|
||||||
|
|
||||||
/* Scan all pages in the [lo, hi] range */
|
/* Scan all pages in the [lo, hi] range */
|
||||||
for(page=lo; page<=hi; page++)
|
for ( page = lo; page <= hi; page++ ) {
|
||||||
{
|
|
||||||
/* Calculate the base page address for the current page */
|
/* Calculate the base page address for the current page */
|
||||||
page_addr = ModAddress( page );
|
page_addr = ModAddress( page );
|
||||||
|
|
||||||
|
@ -321,23 +315,16 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
to MOD_MIN_ACCESS_PRIO.
|
to MOD_MIN_ACCESS_PRIO.
|
||||||
*/
|
*/
|
||||||
prio = MOD_MIN_ACCESS_PRIO;
|
prio = MOD_MIN_ACCESS_PRIO;
|
||||||
for(mod=0; mod<N_MOD; mod++)
|
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 &&
|
||||||
if(
|
page_addr < mod_map.map_info[ mod ].abs_base_addr + mod_map.map_info[ mod ].size &&
|
||||||
mod_map.map_info[mod].config == MOD_CONFIGURED &&
|
prio < mod_description[ mod ].access_prio ) {
|
||||||
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;
|
winner = mod;
|
||||||
prio = mod_description[ mod ].access_prio;
|
prio = mod_description[ mod ].access_prio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prio == MOD_MIN_ACCESS_PRIO)
|
if ( prio == MOD_MIN_ACCESS_PRIO ) {
|
||||||
{
|
|
||||||
/* The page is unmapped; set the module index to the special value
|
/* The page is unmapped; set the module index to the special value
|
||||||
MOD_NO_MOD_INDEX, the relative base address to zero and the
|
MOD_NO_MOD_INDEX, the relative base address to zero and the
|
||||||
read/write functions to BadRead/BadWrite, to catch accesses to
|
read/write functions to BadRead/BadWrite, to catch accesses to
|
||||||
|
@ -349,8 +336,7 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
mod_map.page_table[ page ].write = BadWrite;
|
mod_map.page_table[ page ].write = BadWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* The page is mapped
|
/* The page is mapped
|
||||||
3.3: If the MOD_MAP_FLAGS_ABS is set in the winner's module
|
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
|
description, the base address of the page is set to its
|
||||||
|
@ -358,8 +344,7 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
will receive absolute addresses instead of relative ones.
|
will receive absolute addresses instead of relative ones.
|
||||||
*/
|
*/
|
||||||
mod_map.page_table[ page ].index = winner;
|
mod_map.page_table[ page ].index = winner;
|
||||||
mod_map.page_table[page].rel_base_addr =
|
mod_map.page_table[ page ].rel_base_addr = ( mod_description[ winner ].map_flags & MOD_MAP_FLAGS_ABS )
|
||||||
(mod_description[winner].map_flags & MOD_MAP_FLAGS_ABS)
|
|
||||||
? page_addr
|
? page_addr
|
||||||
: page_addr - mod_map.map_info[ winner ].abs_base_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 ].read = mod_description[ winner ].read;
|
||||||
|
@ -368,7 +353,6 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ClearCachingInfo
|
.title : ClearCachingInfo
|
||||||
|
@ -393,24 +377,24 @@ static void RebuildPageTable(int lo, int hi)
|
||||||
.- */
|
.- */
|
||||||
static struct ModMap* ClearCachingInfo( struct ModMap* d )
|
static struct ModMap* ClearCachingInfo( struct ModMap* d )
|
||||||
{
|
{
|
||||||
static const struct ModCacheTableEntry empty =
|
static const struct ModCacheTableEntry empty = { ( Address )0, ( struct ModMap* )NULL };
|
||||||
{ (Address)0, (struct ModMap *)NULL };
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ClearCachingInfo" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ClearCachingInfo" );
|
||||||
|
|
||||||
for(i=0; i<N_MOD_CACHE_ENTRIES; i++) d->cache.config[i] = empty;
|
for ( i = 0; i < N_MOD_CACHE_ENTRIES; i++ )
|
||||||
|
d->cache.config[ i ] = empty;
|
||||||
d->cache.victim = 0;
|
d->cache.victim = 0;
|
||||||
|
|
||||||
for(i=0; i<N_MOD; i++) d->cache.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.config_point = 0;
|
||||||
d->cache.ref_count = 0;
|
d->cache.ref_count = 0;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NewModMap
|
.title : NewModMap
|
||||||
|
@ -447,9 +431,7 @@ static struct ModMap *NewModMap(void)
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NewModMap" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NewModMap" );
|
||||||
|
|
||||||
if((new = (struct ModMap *)malloc(sizeof(struct ModMap)))
|
if ( ( new = ( struct ModMap* )malloc( sizeof( struct ModMap ) ) ) == ( struct ModMap* )NULL ) {
|
||||||
== (struct ModMap *)NULL)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_F_MAP_ALLOC, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_MAP_ALLOC, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -465,7 +447,6 @@ static struct ModMap *NewModMap(void)
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : CopyModMap
|
.title : CopyModMap
|
||||||
|
@ -502,7 +483,6 @@ static struct ModMap *CopyModMap(struct ModMap *d, const struct ModMap *s)
|
||||||
return ClearCachingInfo( d );
|
return ClearCachingInfo( d );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ReplaceModMap
|
.title : ReplaceModMap
|
||||||
|
@ -545,14 +525,12 @@ static void ReplaceModMap(struct ModMap **d, const struct ModMap *s)
|
||||||
/* Allocation needed; cache cleared after allocation */
|
/* Allocation needed; cache cleared after allocation */
|
||||||
*d = CopyModMap( NewModMap(), s );
|
*d = CopyModMap( NewModMap(), s );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
CopyModMap( *d, s );
|
CopyModMap( *d, s );
|
||||||
IncPerfCtr( repl_c );
|
IncPerfCtr( repl_c );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : FlushCache
|
.title : FlushCache
|
||||||
|
@ -585,13 +563,11 @@ static void FlushCache(struct ModMap *save)
|
||||||
|
|
||||||
/* Scan the cache list; free all elements except that pointed by 'save' */
|
/* Scan the cache list; free all elements except that pointed by 'save' */
|
||||||
p = cache_head;
|
p = cache_head;
|
||||||
while(p != (struct ModMap *)NULL)
|
while ( p != ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
|
|
||||||
n = p->cache.link;
|
n = p->cache.link;
|
||||||
|
|
||||||
if(p != save)
|
if ( p != save ) {
|
||||||
{
|
|
||||||
free( p );
|
free( p );
|
||||||
DecPerfCtr( alloc_c );
|
DecPerfCtr( alloc_c );
|
||||||
}
|
}
|
||||||
|
@ -610,15 +586,13 @@ static void FlushCache(struct ModMap *save)
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
/* The alloc_c performance counter must be exactly 1 now */
|
/* The alloc_c performance counter must be exactly 1 now */
|
||||||
if(alloc_c != 1)
|
if ( alloc_c != 1 ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_F_BAD_ALLOC_C, CHF_ERROR, alloc_c ChfEnd;
|
ChfCondition MOD_F_BAD_ALLOC_C, CHF_ERROR, alloc_c ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : AccessConfigCache
|
.title : AccessConfigCache
|
||||||
|
@ -655,7 +629,6 @@ static struct ModMap *AccessConfigCache(Address tag)
|
||||||
return ( struct ModMap* )NULL;
|
return ( struct ModMap* )NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : AccessUnconfigCache
|
.title : AccessUnconfigCache
|
||||||
|
@ -695,7 +668,6 @@ static struct ModMap *AccessUnconfigCache(int i)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : SelectConfigVictim
|
.title : SelectConfigVictim
|
||||||
|
@ -740,25 +712,19 @@ struct ModCacheTableEntry *SelectConfigVictim(int retry)
|
||||||
/* Scan the config cache entries, starting at .cache.victim,
|
/* Scan the config cache entries, starting at .cache.victim,
|
||||||
until a suitable one is found or the index loops around
|
until a suitable one is found or the index loops around
|
||||||
*/
|
*/
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
/* A config cache entry is suitable for use if:
|
/* A config cache entry is suitable for use if:
|
||||||
- it is empty (map_ptr == NULL)
|
- it is empty (map_ptr == NULL)
|
||||||
- or the reference count of the associated map is 0
|
- or the reference count of the associated map is 0
|
||||||
*/
|
*/
|
||||||
if((mod_map.cache.config[v].map_ptr == (struct ModMap *)NULL)
|
if ( ( mod_map.cache.config[ v ].map_ptr == ( struct ModMap* )NULL ) || mod_map.cache.config[ v ].map_ptr->cache.ref_count == 0 )
|
||||||
|| mod_map.cache.config[v].map_ptr->cache.ref_count == 0)
|
|
||||||
victim = &( mod_map.cache.config[ v ] );
|
victim = &( mod_map.cache.config[ v ] );
|
||||||
|
|
||||||
v = ( v + 1 ) % N_MOD_CACHE_ENTRIES;
|
v = ( v + 1 ) % N_MOD_CACHE_ENTRIES;
|
||||||
}
|
} while ( victim == ( struct ModCacheTableEntry* )NULL && v != mod_map.cache.victim );
|
||||||
while(victim == (struct ModCacheTableEntry *)NULL
|
|
||||||
&& v != mod_map.cache.victim);
|
|
||||||
|
|
||||||
if(victim == (struct ModCacheTableEntry *)NULL)
|
if ( victim == ( struct ModCacheTableEntry* )NULL ) {
|
||||||
{
|
if ( retry ) {
|
||||||
if(retry)
|
|
||||||
{
|
|
||||||
/* Unable to find a victim; flush the cache and retry */
|
/* Unable to find a victim; flush the cache and retry */
|
||||||
ChfCondition MOD_W_NO_VICTIM, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_NO_VICTIM, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -768,8 +734,7 @@ struct ModCacheTableEntry *SelectConfigVictim(int retry)
|
||||||
victim = SelectConfigVictim( 0 );
|
victim = SelectConfigVictim( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Unable to find a victim; retry is not an option; give up */
|
/* Unable to find a victim; retry is not an option; give up */
|
||||||
ChfCondition MOD_F_NO_VICTIM, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_NO_VICTIM, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -783,7 +748,6 @@ struct ModCacheTableEntry *SelectConfigVictim(int retry)
|
||||||
return victim;
|
return victim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : CheckForLateHit
|
.title : CheckForLateHit
|
||||||
|
@ -824,27 +788,21 @@ static struct ModMap *CheckForLateHit(void)
|
||||||
/* Scan the cache to find an entry with the same modules configuration
|
/* Scan the cache to find an entry with the same modules configuration
|
||||||
as the current one; return a pointer to it if successful
|
as the current one; return a pointer to it if successful
|
||||||
*/
|
*/
|
||||||
while(p != (struct ModMap *)NULL)
|
while ( p != ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
/* Don't attempt to match an entry against itself */
|
/* Don't attempt to match an entry against itself */
|
||||||
if(p != mod_map_ptr)
|
if ( p != mod_map_ptr ) {
|
||||||
{
|
|
||||||
/* only .map_info contents must match */
|
/* only .map_info contents must match */
|
||||||
for(i=0; i<N_MOD; i++)
|
for ( i = 0; i < N_MOD; i++ ) {
|
||||||
{
|
|
||||||
/* Break the for if a difference was found */
|
/* Break the for if a difference was found */
|
||||||
if(
|
if ( ( mod_map_ptr->map_info[ i ].config != p->map_info[ i ].config ) ||
|
||||||
(mod_map_ptr->map_info[i].config
|
( mod_map_ptr->map_info[ i ].abs_base_addr != p->map_info[ i ].abs_base_addr ) ||
|
||||||
!= p->map_info[i].config)
|
( mod_map_ptr->map_info[ i ].size != p->map_info[ i ].size ) )
|
||||||
|| (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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Break the while if we found a match ('for' was not broken) */
|
/* Break the while if we found a match ('for' was not broken) */
|
||||||
if(i == N_MOD) break;
|
if ( i == N_MOD )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go to the next cache entry */
|
/* Go to the next cache entry */
|
||||||
|
@ -854,7 +812,6 @@ static struct ModMap *CheckForLateHit(void)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : FreeModMap
|
.title : FreeModMap
|
||||||
|
@ -890,16 +847,14 @@ static void FreeModMap(struct ModMap *p)
|
||||||
other entries. The caller must ensure that the entry is not
|
other entries. The caller must ensure that the entry is not
|
||||||
referenced by any other entry through cache pointers.
|
referenced by any other entry through cache pointers.
|
||||||
*/
|
*/
|
||||||
if(p == cache_head)
|
if ( p == cache_head ) {
|
||||||
{
|
|
||||||
/* Free the list head */
|
/* Free the list head */
|
||||||
cache_head = p->cache.link;
|
cache_head = p->cache.link;
|
||||||
free( p );
|
free( p );
|
||||||
DecPerfCtr( alloc_c );
|
DecPerfCtr( alloc_c );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Scan the cache; at end, n is either null (!) or points to the
|
/* Scan the cache; at end, n is either null (!) or points to the
|
||||||
cache entry that immediately precedes p
|
cache entry that immediately precedes p
|
||||||
*/
|
*/
|
||||||
|
@ -908,8 +863,7 @@ static void FreeModMap(struct ModMap *p)
|
||||||
n = n->cache.link;
|
n = n->cache.link;
|
||||||
|
|
||||||
/* Should never happen */
|
/* Should never happen */
|
||||||
if(n == (struct ModMap *)NULL)
|
if ( n == ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_F_CHAIN_CORRUPTED, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_CHAIN_CORRUPTED, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -921,7 +875,6 @@ static void FreeModMap(struct ModMap *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -961,7 +914,6 @@ void ModRegisterDescription(ModDescription p)
|
||||||
mod_description = p;
|
mod_description = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModInit
|
.title : ModInit
|
||||||
|
@ -1013,15 +965,13 @@ void ModInit(void)
|
||||||
ModRegisterDescription() has been called at least once with a
|
ModRegisterDescription() has been called at least once with a
|
||||||
non-NULL argument.
|
non-NULL argument.
|
||||||
*/
|
*/
|
||||||
if(mod_description == NULL)
|
if ( mod_description == NULL ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_F_NO_DESCRIPTION, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_NO_DESCRIPTION, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scan the mod_description table, initializing all modules */
|
/* Scan the mod_description table, initializing all modules */
|
||||||
for(mod=0; mod<N_MOD; mod++)
|
for ( mod = 0; mod < N_MOD; mod++ ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_MODULES, MOD_I_INITIALIZING, mod_description[ mod ].name );
|
debug1( DEBUG_C_MODULES, MOD_I_INITIALIZING, mod_description[ mod ].name );
|
||||||
mod_description[ mod ].init();
|
mod_description[ mod ].init();
|
||||||
}
|
}
|
||||||
|
@ -1034,9 +984,7 @@ void ModInit(void)
|
||||||
/* Attempt to restore the mod_map from file; reset modules if the read
|
/* Attempt to restore the mod_map from file; reset modules if the read
|
||||||
fails.
|
fails.
|
||||||
*/
|
*/
|
||||||
if(ReadStructFromFile(args.mod_file_name,
|
if ( ReadStructFromFile( args.mod_file_name, sizeof( mod_map.map_info ), &mod_map.map_info ) ) {
|
||||||
sizeof(mod_map.map_info), &mod_map.map_info))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_W_RESETTING_ALL, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_RESETTING_ALL, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
|
@ -1044,14 +992,12 @@ void ModInit(void)
|
||||||
ModReset();
|
ModReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Rebuild page table (not saved on disk) */
|
/* Rebuild page table (not saved on disk) */
|
||||||
RebuildPageTable( 0, N_PAGE_TABLE_ENTRIES - 1 );
|
RebuildPageTable( 0, N_PAGE_TABLE_ENTRIES - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModSave
|
.title : ModSave
|
||||||
|
@ -1089,22 +1035,18 @@ void ModSave(void)
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModSave" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModSave" );
|
||||||
|
|
||||||
/* Scan the mod_description table, initializing all modules */
|
/* Scan the mod_description table, initializing all modules */
|
||||||
for(mod=0; mod<N_MOD; mod++)
|
for ( mod = 0; mod < N_MOD; mod++ ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_MODULES, MOD_I_SAVING, mod_description[ mod ].name );
|
debug1( DEBUG_C_MODULES, MOD_I_SAVING, mod_description[ mod ].name );
|
||||||
mod_description[ mod ].save();
|
mod_description[ mod ].save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attempt to save the mod_map from file */
|
/* Attempt to save the mod_map from file */
|
||||||
if(WriteStructToFile(&mod_map.map_info, sizeof(mod_map.map_info),
|
if ( WriteStructToFile( &mod_map.map_info, sizeof( mod_map.map_info ), args.mod_file_name ) ) {
|
||||||
args.mod_file_name))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_F_MAP_SAVE, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_MAP_SAVE, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModGetID
|
.title : ModGetID
|
||||||
|
@ -1151,8 +1093,8 @@ Address ModGetID(void)
|
||||||
/* Scan the module information table searching for either an unconfigured
|
/* Scan the module information table searching for either an unconfigured
|
||||||
or a partially configured module
|
or a partially configured module
|
||||||
*/
|
*/
|
||||||
for(mod=0;
|
for ( mod = 0; mod < N_MOD && mod_map.map_info[ mod ].config == MOD_CONFIGURED; mod++ )
|
||||||
mod<N_MOD && mod_map.map_info[mod].config == MOD_CONFIGURED; mod++);
|
;
|
||||||
|
|
||||||
if ( mod == N_MOD )
|
if ( mod == N_MOD )
|
||||||
/* All modules are configured */
|
/* All modules are configured */
|
||||||
|
@ -1162,14 +1104,12 @@ Address ModGetID(void)
|
||||||
/* Build the module id */
|
/* Build the module id */
|
||||||
id = ( mod_map.map_info[ mod ].abs_base_addr & 0xFFF00 ) |
|
id = ( mod_map.map_info[ mod ].abs_base_addr & 0xFFF00 ) |
|
||||||
( mod_map.map_info[ mod ].config == MOD_UNCONFIGURED ? 0x00000 : 0x000F0 ) |
|
( mod_map.map_info[ mod ].config == MOD_UNCONFIGURED ? 0x00000 : 0x000F0 ) |
|
||||||
(mod_description[mod].id +
|
( mod_description[ mod ].id + ( mod_map.map_info[ mod ].config == MOD_UNCONFIGURED ? 0 : 1 ) );
|
||||||
(mod_map.map_info[mod].config == MOD_UNCONFIGURED ? 0 : 1));
|
|
||||||
|
|
||||||
debug1( DEBUG_C_MODULES, MOD_I_GET_ID, id );
|
debug1( DEBUG_C_MODULES, MOD_I_GET_ID, id );
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModReset
|
.title : ModReset
|
||||||
|
@ -1204,8 +1144,7 @@ void ModReset(void)
|
||||||
/* Scan the mod_description table, initializing the module
|
/* Scan the mod_description table, initializing the module
|
||||||
mapping information mod_map.map_info.
|
mapping information mod_map.map_info.
|
||||||
*/
|
*/
|
||||||
for(mod=0; mod<N_MOD; mod++)
|
for ( mod = 0; mod < N_MOD; mod++ ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_MODULES, MOD_I_RESETTING, mod_description[ mod ].name );
|
debug1( DEBUG_C_MODULES, MOD_I_RESETTING, mod_description[ mod ].name );
|
||||||
|
|
||||||
/* Set the module configuration status */
|
/* Set the module configuration status */
|
||||||
|
@ -1227,7 +1166,6 @@ void ModReset(void)
|
||||||
mod_map.cache.config_point = 1;
|
mod_map.cache.config_point = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModConfig
|
.title : ModConfig
|
||||||
|
@ -1290,8 +1228,7 @@ void ModConfig(Address config_info)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ACCESS CONFIG CACHE */
|
/* ACCESS CONFIG CACHE */
|
||||||
if((nxt = AccessConfigCache(config_info)) != (struct ModMap *)NULL)
|
if ( ( nxt = AccessConfigCache( config_info ) ) != ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
/* CACHE HIT; switch mod_map_ptr */
|
/* CACHE HIT; switch mod_map_ptr */
|
||||||
mod_map_ptr = nxt;
|
mod_map_ptr = nxt;
|
||||||
|
|
||||||
|
@ -1329,36 +1266,30 @@ void ModConfig(Address config_info)
|
||||||
/* Scan the module information table searching for either an unconfigured
|
/* Scan the module information table searching for either an unconfigured
|
||||||
or a partially configured module
|
or a partially configured module
|
||||||
*/
|
*/
|
||||||
for(mod=0;
|
for ( mod = 0; mod < N_MOD && mod_map.map_info[ mod ].config == MOD_CONFIGURED; mod++ )
|
||||||
mod<N_MOD && mod_map.map_info[mod].config == MOD_CONFIGURED; mod++);
|
;
|
||||||
|
|
||||||
if(mod==N_MOD)
|
if ( mod == N_MOD ) {
|
||||||
{
|
|
||||||
/* All modules are configured - Signal a warning */
|
/* All modules are configured - Signal a warning */
|
||||||
ChfCondition MOD_W_BAD_CONFIG, CHF_WARNING, config_info ChfEnd;
|
ChfCondition MOD_W_BAD_CONFIG, CHF_WARNING, config_info ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
if ( mod_map.map_info[ mod ].config == MOD_UNCONFIGURED ) {
|
||||||
if(mod_map.map_info[mod].config == MOD_UNCONFIGURED)
|
|
||||||
{
|
|
||||||
/* The module was unconfigured; configure its size */
|
/* The module was unconfigured; configure its size */
|
||||||
mod_map.map_info[ mod ].size = 0x100000 - config_info;
|
mod_map.map_info[ mod ].size = 0x100000 - config_info;
|
||||||
mod_map.map_info[ mod ].config = MOD_SIZE_CONFIGURED;
|
mod_map.map_info[ mod ].config = MOD_SIZE_CONFIGURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* The module size was already configured; configure its base address */
|
/* 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 ].abs_base_addr = config_info;
|
||||||
mod_map.map_info[ mod ].config = MOD_CONFIGURED;
|
mod_map.map_info[ mod ].config = MOD_CONFIGURED;
|
||||||
|
|
||||||
/* Rebuild the page table */
|
/* Rebuild the page table */
|
||||||
RebuildPageTable(
|
RebuildPageTable( ModPage( mod_map.map_info[ mod ].abs_base_addr ),
|
||||||
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 ) );
|
||||||
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;
|
/* Mark the current struct ModMap to be a configuration point;
|
||||||
this flag is used by the unconfig cache code to correctly
|
this flag is used by the unconfig cache code to correctly
|
||||||
|
@ -1366,11 +1297,8 @@ void ModConfig(Address config_info)
|
||||||
*/
|
*/
|
||||||
mod_map.cache.config_point = 1;
|
mod_map.cache.config_point = 1;
|
||||||
|
|
||||||
debug3(DEBUG_C_MODULES|DEBUG_C_MOD_CACHE, MOD_I_CONFIG,
|
debug3( DEBUG_C_MODULES | DEBUG_C_MOD_CACHE, MOD_I_CONFIG, mod_description[ mod ].name, mod_map.map_info[ mod ].abs_base_addr,
|
||||||
mod_description[mod].name,
|
mod_map.map_info[ mod ].size );
|
||||||
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,
|
/* Set the unconfig cache pointer of module 'mod' to the old ModMap,
|
||||||
|
@ -1382,7 +1310,6 @@ void ModConfig(Address config_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModUnconfig
|
.title : ModUnconfig
|
||||||
|
@ -1423,9 +1350,7 @@ void ModUnconfig(Address unconfig_info)
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModUnconfig" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "ModUnconfig" );
|
||||||
|
|
||||||
/* Determine the module to unconfigure */
|
/* Determine the module to unconfigure */
|
||||||
if((mod = mod_map.page_table[ModPage(unconfig_info)].index) ==
|
if ( ( mod = mod_map.page_table[ ModPage( unconfig_info ) ].index ) == MOD_NO_MOD_INDEX ) {
|
||||||
MOD_NO_MOD_INDEX)
|
|
||||||
{
|
|
||||||
/* There isn't any module configured at the given address -
|
/* There isn't any module configured at the given address -
|
||||||
Signal a warning
|
Signal a warning
|
||||||
*/
|
*/
|
||||||
|
@ -1433,18 +1358,15 @@ void ModUnconfig(Address unconfig_info)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(mod_description[mod].r_config == MOD_CONFIGURED)
|
else if ( mod_description[ mod ].r_config == MOD_CONFIGURED ) {
|
||||||
{
|
|
||||||
/* The module is automatically configured after reset; it can never
|
/* The module is automatically configured after reset; it can never
|
||||||
be unconfigured.
|
be unconfigured.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Unconfiguring module 'mod': ACCESS UNCONFIG CACHE */
|
/* Unconfiguring module 'mod': ACCESS UNCONFIG CACHE */
|
||||||
if((nxt = AccessUnconfigCache(mod)) != (struct ModMap *)NULL)
|
if ( ( nxt = AccessUnconfigCache( mod ) ) != ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
/* CACHE HIT; switch mod_map_ptr */
|
/* CACHE HIT; switch mod_map_ptr */
|
||||||
mod_map_ptr = nxt;
|
mod_map_ptr = nxt;
|
||||||
|
|
||||||
|
@ -1479,10 +1401,8 @@ void ModUnconfig(Address unconfig_info)
|
||||||
mod_map.map_info[ mod ].config = mod_description[ mod ].r_config;
|
mod_map.map_info[ mod ].config = mod_description[ mod ].r_config;
|
||||||
|
|
||||||
/* Rebuild the page table */
|
/* Rebuild the page table */
|
||||||
RebuildPageTable(
|
RebuildPageTable( ModPage( mod_map.map_info[ mod ].abs_base_addr ),
|
||||||
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 ) );
|
||||||
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
|
/* Reset the module configuration status; the abs_base_addr of the module
|
||||||
is not reset because its old value is still needed by ModGetId()
|
is not reset because its old value is still needed by ModGetId()
|
||||||
|
@ -1491,8 +1411,7 @@ void ModUnconfig(Address unconfig_info)
|
||||||
*/
|
*/
|
||||||
mod_map.map_info[ mod ].size = mod_description[ mod ].r_size;
|
mod_map.map_info[ mod ].size = mod_description[ mod ].r_size;
|
||||||
|
|
||||||
if((nxt = CheckForLateHit()) != (struct ModMap *)NULL)
|
if ( ( nxt = CheckForLateHit() ) != ( struct ModMap* )NULL ) {
|
||||||
{
|
|
||||||
/* Update pointer from the old map to the new one, and increment
|
/* Update pointer from the old map to the new one, and increment
|
||||||
reference counter of the referenced structure
|
reference counter of the referenced structure
|
||||||
*/
|
*/
|
||||||
|
@ -1507,8 +1426,7 @@ void ModUnconfig(Address unconfig_info)
|
||||||
debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_HIT );
|
debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_HIT );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Continue to use the new map with no caching information,
|
/* Continue to use the new map with no caching information,
|
||||||
and hope that further configuration activities will link it
|
and hope that further configuration activities will link it
|
||||||
back in the immediate future.
|
back in the immediate future.
|
||||||
|
@ -1524,16 +1442,12 @@ void ModUnconfig(Address unconfig_info)
|
||||||
|
|
||||||
debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_MISS );
|
debug0( DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG_L_MISS );
|
||||||
|
|
||||||
debug3(DEBUG_C_MODULES|DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG,
|
debug3( DEBUG_C_MODULES | DEBUG_C_MOD_CACHE, MOD_I_UNCONFIG, mod_description[ mod ].name, mod_map.map_info[ mod ].abs_base_addr,
|
||||||
mod_description[mod].name,
|
mod_map.map_info[ mod ].size );
|
||||||
mod_map.map_info[mod].abs_base_addr,
|
|
||||||
mod_map.map_info[mod].size
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : FetchNibble
|
.title : FetchNibble
|
||||||
|
@ -1561,11 +1475,9 @@ Nibble FetchNibble(Address addr)
|
||||||
{
|
{
|
||||||
register int page = ModPage( addr );
|
register int page = ModPage( addr );
|
||||||
|
|
||||||
return mod_map.page_table[page].read(
|
return mod_map.page_table[ page ].read( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ) );
|
||||||
mod_map.page_table[page].rel_base_addr | ModOffset(addr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ReadNibble
|
.title : ReadNibble
|
||||||
|
@ -1599,19 +1511,16 @@ Nibble ReadNibble(Address addr)
|
||||||
register Nibble d;
|
register Nibble d;
|
||||||
|
|
||||||
/* Read the nibble from the peripheral module */
|
/* Read the nibble from the peripheral module */
|
||||||
d = mod_map.page_table[page].read(
|
d = mod_map.page_table[ page ].read( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ) );
|
||||||
mod_map.page_table[page].rel_base_addr | ModOffset(addr));
|
|
||||||
|
|
||||||
/* Update the crc register, if appropriate */
|
/* Update the crc register, if appropriate */
|
||||||
if ( mod_map.page_table[ page ].index != MOD_HDW_INDEX )
|
if ( mod_map.page_table[ page ].index != MOD_HDW_INDEX )
|
||||||
mod_status.hdw.crc =
|
mod_status.hdw.crc = ( mod_status.hdw.crc >> 4 ) ^ ( ( ( mod_status.hdw.crc ^ d ) & 0x0F ) * 0x1081 );
|
||||||
(mod_status.hdw.crc >> 4) ^ (((mod_status.hdw.crc ^ d) & 0x0F) * 0x1081);
|
|
||||||
|
|
||||||
/* Return to the caller */
|
/* Return to the caller */
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : WriteNibble
|
.title : WriteNibble
|
||||||
|
@ -1640,16 +1549,13 @@ 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 ].write( mod_map.page_table[ page ].rel_base_addr | ModOffset( addr ), datum );
|
||||||
mod_map.page_table[page].rel_base_addr | ModOffset(addr), datum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Monitor functions
|
Monitor functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModMapCheck
|
.title : ModMapCheck
|
||||||
|
@ -1683,19 +1589,16 @@ void ModMapCheck(Address addr, char ob[MOD_MAP_CHECK_OB_SIZE])
|
||||||
if ( ( mod = mod_map.page_table[ page ].index ) == MOD_NO_MOD_INDEX )
|
if ( ( mod = mod_map.page_table[ page ].index ) == MOD_NO_MOD_INDEX )
|
||||||
sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_NOT_MAPPED, "" ), addr );
|
sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_NOT_MAPPED, "" ), addr );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Address rel_addr;
|
Address rel_addr;
|
||||||
rel_addr = mod_map.page_table[ page ].rel_base_addr | offset;
|
rel_addr = mod_map.page_table[ page ].rel_base_addr | offset;
|
||||||
|
|
||||||
sprintf(ob, ChfGetMessage(CHF_MODULE_ID, MOD_M_MAPPED, ""),
|
sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_MAPPED, "" ), addr, mod_description[ mod ].name, rel_addr );
|
||||||
addr, mod_description[mod].name, rel_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : ModMapTable
|
.title : ModMapTable
|
||||||
|
@ -1724,17 +1627,13 @@ void ModMapTable(char ob[MOD_MAP_TABLE_OB_SIZE])
|
||||||
sprintf( ob, "%s\n", ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_TABLE_TITLE, "" ) );
|
sprintf( ob, "%s\n", ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_TABLE_TITLE, "" ) );
|
||||||
ob += strlen( ob );
|
ob += strlen( ob );
|
||||||
|
|
||||||
for(mod=0; mod<N_MOD; mod++)
|
for ( mod = 0; mod < N_MOD; mod++ ) {
|
||||||
{
|
sprintf( ob, ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_TABLE_ROW, "" ), mod_description[ mod ].name,
|
||||||
sprintf(ob, ChfGetMessage(CHF_MODULE_ID, MOD_M_MAP_TABLE_ROW, ""),
|
mod_map.map_info[ mod ].abs_base_addr, mod_map.map_info[ mod ].size,
|
||||||
mod_description[mod].name,
|
mod_map.map_info[ mod ].config == MOD_CONFIGURED ? ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_CONFIGURED, "C" )
|
||||||
mod_map.map_info[mod].abs_base_addr,
|
: ( mod_map.map_info[ mod ].config == MOD_SIZE_CONFIGURED
|
||||||
mod_map.map_info[mod].size,
|
? ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_SZ_CONFIGURED, "S" )
|
||||||
mod_map.map_info[mod].config == MOD_CONFIGURED ?
|
: ChfGetMessage( CHF_MODULE_ID, MOD_M_MAP_UNCONFIGURED, "U" ) ) );
|
||||||
ChfGetMessage(CHF_MODULE_ID, MOD_M_MAP_CONFIGURED, "C") :
|
|
||||||
( mod_map.map_info[mod].config == MOD_SIZE_CONFIGURED ?
|
|
||||||
ChfGetMessage(CHF_MODULE_ID, MOD_M_MAP_SZ_CONFIGURED, "S") :
|
|
||||||
ChfGetMessage(CHF_MODULE_ID, MOD_M_MAP_UNCONFIGURED, "U")));
|
|
||||||
|
|
||||||
strcat( ob, "\n" );
|
strcat( ob, "\n" );
|
||||||
ob += strlen( ob );
|
ob += strlen( ob );
|
||||||
|
|
|
@ -117,7 +117,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Data type definitions - require config.h, machdep.h, cpu.h
|
Data type definitions - require config.h, machdep.h, cpu.h
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -144,7 +143,6 @@
|
||||||
|
|
||||||
#define MOD_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
#define MOD_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macros
|
Macros
|
||||||
|
|
||||||
|
@ -157,7 +155,6 @@
|
||||||
#define ModPage( address ) ( ( int )( ( ( address ) & 0xFFFC0 ) >> 6 ) )
|
#define ModPage( address ) ( ( int )( ( ( address ) & 0xFFFC0 ) >> 6 ) )
|
||||||
#define ModOffset( address ) ( ( address ) & 0x0003F )
|
#define ModOffset( address ) ( ( address ) & 0x0003F )
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ModDescription
|
ModDescription
|
||||||
|
|
||||||
|
@ -224,15 +221,9 @@ typedef Nibble (*ModReadFunction)(Address rel_addr);
|
||||||
|
|
||||||
typedef void ( *ModWriteFunction )( Address rel_addr, Nibble data );
|
typedef void ( *ModWriteFunction )( Address rel_addr, Nibble data );
|
||||||
|
|
||||||
enum ModConfig
|
enum ModConfig { MOD_UNCONFIGURED, MOD_SIZE_CONFIGURED, MOD_CONFIGURED };
|
||||||
{
|
|
||||||
MOD_UNCONFIGURED,
|
|
||||||
MOD_SIZE_CONFIGURED,
|
|
||||||
MOD_CONFIGURED
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModDescriptionEntry
|
struct ModDescriptionEntry {
|
||||||
{
|
|
||||||
char* name;
|
char* name;
|
||||||
Address id;
|
Address id;
|
||||||
int access_prio;
|
int access_prio;
|
||||||
|
@ -253,7 +244,6 @@ struct ModDescriptionEntry
|
||||||
#define MOD_HDW_INDEX 1
|
#define MOD_HDW_INDEX 1
|
||||||
typedef const struct ModDescriptionEntry ModDescription[ N_MOD ];
|
typedef const struct ModDescriptionEntry ModDescription[ N_MOD ];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ModMapInfo
|
ModMapInfo
|
||||||
|
|
||||||
|
@ -269,8 +259,7 @@ typedef const struct ModDescriptionEntry ModDescription[N_MOD];
|
||||||
size: contains the current size of the address window of the module.
|
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
|
struct ModMapInfoEntry {
|
||||||
{
|
|
||||||
enum ModConfig config;
|
enum ModConfig config;
|
||||||
Address abs_base_addr;
|
Address abs_base_addr;
|
||||||
Address size;
|
Address size;
|
||||||
|
@ -278,7 +267,6 @@ struct ModMapInfoEntry
|
||||||
|
|
||||||
typedef struct ModMapInfoEntry ModMapInfo[ N_MOD ];
|
typedef struct ModMapInfoEntry ModMapInfo[ N_MOD ];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ModPageTable
|
ModPageTable
|
||||||
|
|
||||||
|
@ -315,8 +303,7 @@ typedef struct ModMapInfoEntry ModMapInfo[N_MOD];
|
||||||
is called.
|
is called.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct ModPageTableEntry
|
struct ModPageTableEntry {
|
||||||
{
|
|
||||||
int index;
|
int index;
|
||||||
#define MOD_NO_MOD_INDEX ( -1 )
|
#define MOD_NO_MOD_INDEX ( -1 )
|
||||||
|
|
||||||
|
@ -327,7 +314,6 @@ struct ModPageTableEntry
|
||||||
|
|
||||||
typedef struct ModPageTableEntry ModPageTable[ N_PAGE_TABLE_ENTRIES ];
|
typedef struct ModPageTableEntry ModPageTable[ N_PAGE_TABLE_ENTRIES ];
|
||||||
|
|
||||||
|
|
||||||
/* struct ModCache (2.7)
|
/* struct ModCache (2.7)
|
||||||
|
|
||||||
This structure holds the caching information for module config/unconfig.
|
This structure holds the caching information for module config/unconfig.
|
||||||
|
@ -359,14 +345,12 @@ typedef struct ModPageTableEntry ModPageTable[N_PAGE_TABLE_ENTRIES];
|
||||||
|
|
||||||
The .link field links all cached struct ModMap together.
|
The .link field links all cached struct ModMap together.
|
||||||
*/
|
*/
|
||||||
struct ModCacheTableEntry
|
struct ModCacheTableEntry {
|
||||||
{
|
|
||||||
Address tag;
|
Address tag;
|
||||||
struct ModMap* map_ptr;
|
struct ModMap* map_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModCache
|
struct ModCache {
|
||||||
{
|
|
||||||
struct ModCacheTableEntry config[ N_MOD_CACHE_ENTRIES ];
|
struct ModCacheTableEntry config[ N_MOD_CACHE_ENTRIES ];
|
||||||
int victim;
|
int victim;
|
||||||
|
|
||||||
|
@ -378,7 +362,6 @@ struct ModCache
|
||||||
struct ModMap* link;
|
struct ModMap* link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct ModMap
|
struct ModMap
|
||||||
|
|
||||||
|
@ -395,14 +378,12 @@ struct ModCache
|
||||||
module config/unconfig instructions
|
module config/unconfig instructions
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct ModMap
|
struct ModMap {
|
||||||
{
|
|
||||||
ModMapInfo map_info;
|
ModMapInfo map_info;
|
||||||
ModPageTable page_table;
|
ModPageTable page_table;
|
||||||
struct ModCache cache;
|
struct ModCache cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct ModStatus
|
struct ModStatus
|
||||||
|
|
||||||
|
@ -429,18 +410,15 @@ struct ModMap
|
||||||
configuration-specific ROM/RAM emulation module.
|
configuration-specific ROM/RAM emulation module.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
struct ModHdw48Accel
|
struct ModHdw48Accel {
|
||||||
{
|
|
||||||
XAddress bs_address; /* Bank Switcher ext. address */
|
XAddress bs_address; /* Bank Switcher ext. address */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModHdw49Accel
|
struct ModHdw49Accel {
|
||||||
{
|
|
||||||
XAddress view[ 2 ]; /* Base of Flash views */
|
XAddress view[ 2 ]; /* Base of Flash views */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModHdw
|
struct ModHdw {
|
||||||
{
|
|
||||||
Nibble hdw[ N_HDW_SIZE ]; /* HDW registers */
|
Nibble hdw[ N_HDW_SIZE ]; /* HDW registers */
|
||||||
|
|
||||||
/* LCD driver */
|
/* LCD driver */
|
||||||
|
@ -481,8 +459,7 @@ struct ModHdw
|
||||||
*/
|
*/
|
||||||
int accel_valid;
|
int accel_valid;
|
||||||
|
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct ModHdw48Accel a48;
|
struct ModHdw48Accel a48;
|
||||||
struct ModHdw49Accel a49;
|
struct ModHdw49Accel a49;
|
||||||
} accel;
|
} accel;
|
||||||
|
@ -495,13 +472,11 @@ struct ModHdw
|
||||||
int16 crc; /* CRC */
|
int16 crc; /* CRC */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModStatus
|
struct ModStatus {
|
||||||
{
|
|
||||||
struct ModHdw hdw; /* HDW status */
|
struct ModHdw hdw; /* HDW status */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModStatus_48
|
struct ModStatus_48 {
|
||||||
{
|
|
||||||
Nibble rom[ N_ROM_SIZE ]; /* Internal ROM */
|
Nibble rom[ N_ROM_SIZE ]; /* Internal ROM */
|
||||||
Nibble ram[ N_RAM_SIZE ]; /* Internal RAM */
|
Nibble ram[ N_RAM_SIZE ]; /* Internal RAM */
|
||||||
Nibble port_1[ N_PORT_1_SIZE ]; /* 2.4: Port_1 (CE2) storage */
|
Nibble port_1[ N_PORT_1_SIZE ]; /* 2.4: Port_1 (CE2) storage */
|
||||||
|
@ -512,21 +487,18 @@ struct ModStatus_48
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModStatus_49
|
struct ModStatus_49 {
|
||||||
{
|
|
||||||
Nibble flash[ N_FLASH_SIZE_49 ]; /* Internal Flash ROM */
|
Nibble flash[ N_FLASH_SIZE_49 ]; /* Internal Flash ROM */
|
||||||
Nibble ram[ N_RAM_SIZE_49 ]; /* Internal RAM */
|
Nibble ram[ N_RAM_SIZE_49 ]; /* Internal RAM */
|
||||||
Nibble *ce2, *nce3; /* ERAM bases */
|
Nibble *ce2, *nce3; /* ERAM bases */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
extern struct ModStatus mod_status;
|
extern struct ModStatus mod_status;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -588,8 +560,6 @@ extern struct ModStatus mod_status;
|
||||||
#define MOD_M_MAP_SZ_CONFIGURED 506 /* Size configured */
|
#define MOD_M_MAP_SZ_CONFIGURED 506 /* Size configured */
|
||||||
#define MOD_M_MAP_UNCONFIGURED 507 /* Unconfigured */
|
#define MOD_M_MAP_UNCONFIGURED 507 /* Unconfigured */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -88,7 +88,6 @@ static char rcs_id[] = "$Id: monitor.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
#define CHF_MODULE_ID CPU_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macro & Data type definitions
|
Macro & Data type definitions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -109,8 +108,7 @@ static char rcs_id[] = "$Id: monitor.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $"
|
||||||
static int ReadHexAddress( Address* addr )
|
static int ReadHexAddress( Address* addr )
|
||||||
{
|
{
|
||||||
char* p = strtok( ( char* )NULL, TOK_DELIMITERS );
|
char* p = strtok( ( char* )NULL, TOK_DELIMITERS );
|
||||||
return (p == (char *)NULL ||
|
return ( p == ( char* )NULL || sscanf( p, ADDRESS_FMT, addr ) != 1 ) ? FAILED : OK;
|
||||||
sscanf(p, ADDRESS_FMT, addr) != 1) ? FAILED : OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read a Nibble from the command line */
|
/* Read a Nibble from the command line */
|
||||||
|
@ -118,7 +116,8 @@ static int ReadHexDatum(Nibble *n)
|
||||||
{
|
{
|
||||||
Address addr;
|
Address addr;
|
||||||
int st;
|
int st;
|
||||||
if((st = ReadHexAddress(&addr)) == OK) *n = (Nibble)addr;
|
if ( ( st = ReadHexAddress( &addr ) ) == OK )
|
||||||
|
*n = ( Nibble )addr;
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,11 +125,9 @@ static int ReadHexDatum(Nibble *n)
|
||||||
static int ReadCount( int* count )
|
static int ReadCount( int* count )
|
||||||
{
|
{
|
||||||
char* p = strtok( ( char* )NULL, TOK_DELIMITERS );
|
char* p = strtok( ( char* )NULL, TOK_DELIMITERS );
|
||||||
return (p == (char *)NULL || sscanf(p, COUNT_FMT, count) != 1 ||
|
return ( p == ( char* )NULL || sscanf( p, COUNT_FMT, count ) != 1 || *count <= 0 ) ? FAILED : OK;
|
||||||
*count <= 0) ? FAILED : OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions - Command execution
|
Private functions - Command execution
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -148,7 +145,8 @@ static int run(void)
|
||||||
static int debug( void )
|
static int debug( void )
|
||||||
{
|
{
|
||||||
Address addr;
|
Address addr;
|
||||||
if(ReadHexAddress(&addr)) return FAILED;
|
if ( ReadHexAddress( &addr ) )
|
||||||
|
return FAILED;
|
||||||
SetDebugLevel( ( int )addr );
|
SetDebugLevel( ( int )addr );
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +156,8 @@ static int map_check(void)
|
||||||
{
|
{
|
||||||
Address addr;
|
Address addr;
|
||||||
char ob[ MOD_MAP_CHECK_OB_SIZE ];
|
char ob[ MOD_MAP_CHECK_OB_SIZE ];
|
||||||
if(ReadHexAddress(&addr)) return FAILED;
|
if ( ReadHexAddress( &addr ) )
|
||||||
|
return FAILED;
|
||||||
ModMapCheck( addr, ob );
|
ModMapCheck( addr, ob );
|
||||||
puts( ob );
|
puts( ob );
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -178,8 +177,10 @@ static int w(void)
|
||||||
{
|
{
|
||||||
Address addr;
|
Address addr;
|
||||||
Nibble n;
|
Nibble n;
|
||||||
if(ReadHexAddress(&addr)) return FAILED;
|
if ( ReadHexAddress( &addr ) )
|
||||||
while(ReadHexDatum(&n) == OK) WriteNibble(addr++, n);
|
return FAILED;
|
||||||
|
while ( ReadHexDatum( &n ) == OK )
|
||||||
|
WriteNibble( addr++, n );
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,11 +189,12 @@ static int r(void)
|
||||||
{
|
{
|
||||||
Address addr;
|
Address addr;
|
||||||
int count;
|
int count;
|
||||||
if(ReadHexAddress(&addr)) return FAILED;
|
if ( ReadHexAddress( &addr ) )
|
||||||
if(ReadCount(&count)) count=1;
|
return FAILED;
|
||||||
|
if ( ReadCount( &count ) )
|
||||||
|
count = 1;
|
||||||
|
|
||||||
while(count-->0)
|
while ( count-- > 0 ) {
|
||||||
{
|
|
||||||
printf( "A_%05X\t%X\n", addr, ( int )FetchNibble( addr ) );
|
printf( "A_%05X\t%X\n", addr, ( int )FetchNibble( addr ) );
|
||||||
addr++;
|
addr++;
|
||||||
}
|
}
|
||||||
|
@ -207,11 +209,12 @@ static int d(void)
|
||||||
int count;
|
int count;
|
||||||
char ob[ DISASSEMBLE_OB_SIZE ];
|
char ob[ DISASSEMBLE_OB_SIZE ];
|
||||||
|
|
||||||
if(ReadHexAddress(&addr)) return FAILED;
|
if ( ReadHexAddress( &addr ) )
|
||||||
if(ReadCount(&count)) count=1;
|
return FAILED;
|
||||||
|
if ( ReadCount( &count ) )
|
||||||
|
count = 1;
|
||||||
|
|
||||||
while(count-->0)
|
while ( count-- > 0 ) {
|
||||||
{
|
|
||||||
addr = Disassemble( addr, ob );
|
addr = Disassemble( addr, ob );
|
||||||
puts( ob );
|
puts( ob );
|
||||||
}
|
}
|
||||||
|
@ -251,13 +254,11 @@ static int mon_quit(void)
|
||||||
return OK; /* 3.1: Keep compiler happy */
|
return OK; /* 3.1: Keep compiler happy */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Command table
|
Command table
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
struct TEntry
|
struct TEntry {
|
||||||
{
|
|
||||||
char* name;
|
char* name;
|
||||||
char* desc;
|
char* desc;
|
||||||
int ( *function )( void );
|
int ( *function )( void );
|
||||||
|
@ -268,8 +269,7 @@ struct TEntry
|
||||||
/* Forward declaration for the Help funcion */
|
/* Forward declaration for the Help funcion */
|
||||||
static int Help( void );
|
static int Help( void );
|
||||||
|
|
||||||
static const struct TEntry table[] =
|
static const struct TEntry table[] = {
|
||||||
{
|
|
||||||
{"help", "Print this information", Help },
|
{"help", "Print this information", Help },
|
||||||
{"run", "Run the emulator with current CPU status", run },
|
{"run", "Run the emulator with current CPU status", run },
|
||||||
{"?", "<addr>, Check address mapping", map_check},
|
{"?", "<addr>, Check address mapping", map_check},
|
||||||
|
@ -288,7 +288,8 @@ static const struct TEntry table[] =
|
||||||
static int InvokeCommand( char* tk )
|
static int InvokeCommand( char* tk )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<TableSize(table) && strcmp(tk, table[i].name); i++);
|
for ( i = 0; i < TableSize( table ) && strcmp( tk, table[ i ].name ); i++ )
|
||||||
|
;
|
||||||
return i == TableSize( table ) ? FAILED : table[ i ].function();
|
return i == TableSize( table ) ? FAILED : table[ i ].function();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +304,7 @@ static int Help(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handler for SIGINT during monitor execution */
|
/* Handler for SIGINT during monitor execution */
|
||||||
static void sigint_handler(int s)
|
static void sigint_handler( int s ) { EmulatorIntRequest(); }
|
||||||
{
|
|
||||||
EmulatorIntRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
|
@ -347,15 +344,12 @@ void Monitor(void)
|
||||||
signal( SIGINT, sigint_handler );
|
signal( SIGINT, sigint_handler );
|
||||||
|
|
||||||
/* Infinite loop; it's exited only when a condition is signalled */
|
/* Infinite loop; it's exited only when a condition is signalled */
|
||||||
while(1)
|
while ( 1 ) {
|
||||||
{
|
|
||||||
/* Write prompt */
|
/* Write prompt */
|
||||||
fputs( PROMPT, stdout );
|
fputs( PROMPT, stdout );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
if(fgets(cmd, LINE_BUFFER_SIZE, stdin) == (char *)NULL ||
|
if ( fgets( cmd, LINE_BUFFER_SIZE, stdin ) == ( char* )NULL || ( tk = strtok( cmd, TOK_DELIMITERS ) ) == ( char* )NULL ) {
|
||||||
(tk = strtok(cmd, TOK_DELIMITERS)) == (char *)NULL)
|
|
||||||
{
|
|
||||||
/* New command empty; try old command */
|
/* New command empty; try old command */
|
||||||
if ( ( tk = strtok( old_cmd, TOK_DELIMITERS ) ) != ( char* )NULL )
|
if ( ( tk = strtok( old_cmd, TOK_DELIMITERS ) ) != ( char* )NULL )
|
||||||
if ( InvokeCommand( tk ) )
|
if ( InvokeCommand( tk ) )
|
||||||
|
@ -363,14 +357,12 @@ void Monitor(void)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Save command */
|
/* Save command */
|
||||||
strcpy( old_cmd, cmd );
|
strcpy( old_cmd, cmd );
|
||||||
|
|
||||||
/* New command */
|
/* New command */
|
||||||
if(InvokeCommand(tk))
|
if ( InvokeCommand( tk ) ) {
|
||||||
{
|
|
||||||
ChfCondition CPU_W_BAD_MONITOR_CMD, CHF_WARNING, tk ChfEnd;
|
ChfCondition CPU_W_BAD_MONITOR_CMD, CHF_WARNING, tk ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
65
src/pack.c
65
src/pack.c
|
@ -86,13 +86,11 @@ static char rcs_id[] = "$Id";
|
||||||
#define CHF_MODULE_ID UTIL_CHF_MODULE_ID
|
#define CHF_MODULE_ID UTIL_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/* Maximum size of source ROM (bytes) handled by this utility; set to
|
/* Maximum size of source ROM (bytes) handled by this utility; set to
|
||||||
a reasonable value
|
a reasonable value
|
||||||
*/
|
*/
|
||||||
#define MAX_SRC_SIZE ( 4 * 1024 * 1024 )
|
#define MAX_SRC_SIZE ( 4 * 1024 * 1024 )
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf parameters - Do not change.
|
Chf parameters - Do not change.
|
||||||
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
||||||
|
@ -114,7 +112,6 @@ static const char cat_suffix[] = ".cat";
|
||||||
/* Message catalog base_name */
|
/* Message catalog base_name */
|
||||||
static const char cat_base_name[] = "saturn";
|
static const char cat_base_name[] = "saturn";
|
||||||
|
|
||||||
|
|
||||||
/* Condition codes used by this utility */
|
/* Condition codes used by this utility */
|
||||||
#define UTIL_I_PACK_USAGE 1
|
#define UTIL_I_PACK_USAGE 1
|
||||||
#define UTIL_F_PACK_CMD_LINE 2
|
#define UTIL_F_PACK_CMD_LINE 2
|
||||||
|
@ -125,13 +122,10 @@ static const char cat_base_name[] = "saturn";
|
||||||
#define UTIL_F_PACK_READ 7
|
#define UTIL_F_PACK_READ 7
|
||||||
#define UTIL_F_PACK_WRITE_NIBBLES 8
|
#define UTIL_F_PACK_WRITE_NIBBLES 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : main
|
.title : main
|
||||||
|
@ -154,10 +148,7 @@ int main(int argc, char *argv[])
|
||||||
int i;
|
int i;
|
||||||
int st;
|
int st;
|
||||||
|
|
||||||
if((cat_name = malloc(sizeof(cat_base_name)
|
if ( ( cat_name = malloc( sizeof( cat_base_name ) + CAT_PREFIX_LEN + CAT_SUFFIX_LEN + 1 ) ) == NULL ) {
|
||||||
+CAT_PREFIX_LEN+CAT_SUFFIX_LEN+1))
|
|
||||||
== NULL)
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Cat_name initialization failed\n" );
|
fprintf( stderr, "Cat_name initialization failed\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
@ -171,47 +162,39 @@ int main(int argc, char *argv[])
|
||||||
even if it was not able to open the right message catalog; better
|
even if it was not able to open the right message catalog; better
|
||||||
try it now.
|
try it now.
|
||||||
*/
|
*/
|
||||||
if((st = ChfMsgcatInit(
|
if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */
|
||||||
argv[0], /* Application's name */
|
|
||||||
CHF_DEFAULT, /* Options */
|
CHF_DEFAULT, /* Options */
|
||||||
cat_name, /* Name of the message catalog */
|
cat_name, /* Name of the message catalog */
|
||||||
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
||||||
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
||||||
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
||||||
)) != CHF_S_OK
|
) ) != CHF_S_OK ||
|
||||||
||
|
ChfGetMessage( CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL ) == NULL ) {
|
||||||
ChfGetMessage(CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL) == NULL)
|
if ( st != CHF_S_OK && st != CHF_F_CATOPEN ) {
|
||||||
{
|
|
||||||
if(st != CHF_S_OK && st != CHF_F_CATOPEN)
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Chf initialization failed\n" );
|
fprintf( stderr, "Chf initialization failed\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
fprintf( stderr, "Default message catalog open failed; trying alternate\n" );
|
||||||
fprintf(stderr,
|
|
||||||
"Default message catalog open failed; trying alternate\n");
|
|
||||||
|
|
||||||
/* Bring down Chf before initializing it again */
|
/* Bring down Chf before initializing it again */
|
||||||
if(st == CHF_S_OK) ChfExit();
|
if ( st == CHF_S_OK )
|
||||||
|
ChfExit();
|
||||||
|
|
||||||
/* Try alternate message catalog name (with prefix) */
|
/* Try alternate message catalog name (with prefix) */
|
||||||
strcpy( cat_name, cat_prefix );
|
strcpy( cat_name, cat_prefix );
|
||||||
strcat( cat_name, cat_base_name );
|
strcat( cat_name, cat_base_name );
|
||||||
strcat( cat_name, cat_suffix );
|
strcat( cat_name, cat_suffix );
|
||||||
|
|
||||||
if((st = ChfMsgcatInit(
|
if ( ( st = ChfMsgcatInit( argv[ 0 ], /* Application's name */
|
||||||
argv[0], /* Application's name */
|
|
||||||
CHF_DEFAULT, /* Options */
|
CHF_DEFAULT, /* Options */
|
||||||
cat_name, /* Name of the message catalog */
|
cat_name, /* Name of the message catalog */
|
||||||
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
||||||
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
||||||
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
||||||
)) != CHF_S_OK
|
) ) != CHF_S_OK ||
|
||||||
||
|
ChfGetMessage( CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL ) == NULL ) {
|
||||||
ChfGetMessage(CHF_MODULE_ID, UTIL_I_PACK_USAGE, NULL) == NULL)
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Alternate Chf initialization failed\n" );
|
fprintf( stderr, "Alternate Chf initialization failed\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
@ -222,33 +205,28 @@ int main(int argc, char *argv[])
|
||||||
free( cat_name );
|
free( cat_name );
|
||||||
|
|
||||||
/* Now, do some useful work; pack argv[1] into argv[2] */
|
/* Now, do some useful work; pack argv[1] into argv[2] */
|
||||||
if(argc != 3)
|
if ( argc != 3 ) {
|
||||||
{
|
|
||||||
ChfCondition UTIL_I_PACK_USAGE, CHF_INFO ChfEnd;
|
ChfCondition UTIL_I_PACK_USAGE, CHF_INFO ChfEnd;
|
||||||
ChfCondition UTIL_F_PACK_CMD_LINE, CHF_FATAL ChfEnd;
|
ChfCondition UTIL_F_PACK_CMD_LINE, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the size of the source file */
|
/* Get the size of the source file */
|
||||||
if(stat(argv[1], &statb))
|
if ( stat( argv[ 1 ], &statb ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition UTIL_F_PACK_STAT, CHF_FATAL, argv[ 1 ] ChfEnd;
|
ChfCondition UTIL_F_PACK_STAT, CHF_FATAL, argv[ 1 ] ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that actual size is reasonable */
|
/* Check that actual size is reasonable */
|
||||||
if(statb.st_size > MAX_SRC_SIZE)
|
if ( statb.st_size > MAX_SRC_SIZE ) {
|
||||||
{
|
|
||||||
ChfCondition UTIL_F_PACK_SRC_SIZE, CHF_FATAL, statb.st_size ChfEnd;
|
ChfCondition UTIL_F_PACK_SRC_SIZE, CHF_FATAL, statb.st_size ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate source buffer */
|
/* Allocate source buffer */
|
||||||
if((b = (char *)malloc(statb.st_size)) == (char *)NULL
|
if ( ( b = ( char* )malloc( statb.st_size ) ) == ( char* )NULL ||
|
||||||
|| (nb = (Nibble *)malloc(sizeof(Nibble) * statb.st_size))
|
( nb = ( Nibble* )malloc( sizeof( Nibble ) * statb.st_size ) ) == ( Nibble* )NULL ) {
|
||||||
== (Nibble *)NULL)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition UTIL_F_PACK_MALLOC, CHF_FATAL, statb.st_size ChfEnd;
|
ChfCondition UTIL_F_PACK_MALLOC, CHF_FATAL, statb.st_size ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -257,15 +235,13 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open/read/close */
|
/* open/read/close */
|
||||||
if((d = open(argv[1], O_RDONLY)) == -1)
|
if ( ( d = open( argv[ 1 ], O_RDONLY ) ) == -1 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition UTIL_F_PACK_OPEN, CHF_FATAL, argv[ 1 ] ChfEnd;
|
ChfCondition UTIL_F_PACK_OPEN, CHF_FATAL, argv[ 1 ] ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(read(d, b, statb.st_size) != statb.st_size)
|
if ( read( d, b, statb.st_size ) != statb.st_size ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
|
||||||
( void )close( d );
|
( void )close( d );
|
||||||
|
@ -284,8 +260,7 @@ int main(int argc, char *argv[])
|
||||||
free( b );
|
free( b );
|
||||||
|
|
||||||
/* Write */
|
/* Write */
|
||||||
if(WriteNibblesToFile(nb, statb.st_size, argv[2]))
|
if ( WriteNibblesToFile( nb, statb.st_size, argv[ 2 ] ) ) {
|
||||||
{
|
|
||||||
ChfCondition UTIL_F_PACK_WRITE_NIBBLES, CHF_FATAL ChfEnd;
|
ChfCondition UTIL_F_PACK_WRITE_NIBBLES, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
100
src/romram.c
100
src/romram.c
|
@ -101,7 +101,6 @@ static char rcs_id[] = "$Id: romram.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/* 3.2: The rom/ram storage areas are now dynamically allocated in
|
/* 3.2: The rom/ram storage areas are now dynamically allocated in
|
||||||
a private struct ModStatus_48. The dynamic allocation is performed during
|
a private struct ModStatus_48. The dynamic allocation is performed during
|
||||||
Rom initialization, and the following macro allows us to reuse the
|
Rom initialization, and the following macro allows us to reuse the
|
||||||
|
@ -115,7 +114,6 @@ static struct ModStatus_48 *mod_status_48;
|
||||||
#define mod_status_port_1 mod_status_48->port_1
|
#define mod_status_port_1 mod_status_48->port_1
|
||||||
#define mod_status_port_2 mod_status_48->port_2
|
#define mod_status_port_2 mod_status_48->port_2
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Rom module
|
Rom module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -147,24 +145,18 @@ void RomInit(void)
|
||||||
{
|
{
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit" );
|
||||||
|
|
||||||
if((mod_status_48 =
|
if ( ( mod_status_48 = ( struct ModStatus_48* )malloc( sizeof( struct ModStatus_48 ) ) ) == ( struct ModStatus_48* )NULL ) {
|
||||||
(struct ModStatus_48 *)malloc(sizeof(struct ModStatus_48)))
|
|
||||||
== (struct ModStatus_48 *)NULL)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL,
|
ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, sizeof( struct ModStatus_48 ) ChfEnd;
|
||||||
sizeof(struct ModStatus_48) ChfEnd;
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ReadNibblesFromFile(args.rom_file_name, N_ROM_SIZE, mod_status_rom))
|
if ( ReadNibblesFromFile( args.rom_file_name, N_ROM_SIZE, mod_status_rom ) ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RomSave
|
.title : RomSave
|
||||||
|
@ -186,11 +178,7 @@ void RomInit(void)
|
||||||
1.1, 11-Feb-1998, creation
|
1.1, 11-Feb-1998, creation
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
void RomSave(void)
|
void RomSave( void ) { debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomSave" ); }
|
||||||
{
|
|
||||||
debug1(DEBUG_C_TRACE, MOD_I_CALLED, "RomSave");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
|
@ -220,7 +208,6 @@ Nibble RomRead(Address rel_address)
|
||||||
return mod_status_rom[ rel_address ];
|
return mod_status_rom[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RomWrite
|
.title : RomWrite
|
||||||
|
@ -252,7 +239,6 @@ void RomWrite(Address rel_address, Nibble datum)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Main Ram module
|
Main Ram module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -282,8 +268,7 @@ 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))
|
if ( ReadNibblesFromFile( args.ram_file_name, N_RAM_SIZE, mod_status_ram ) ) {
|
||||||
{
|
|
||||||
ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
|
@ -291,7 +276,6 @@ void RamInit(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamSave
|
.title : RamSave
|
||||||
|
@ -319,15 +303,13 @@ 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))
|
if ( WriteNibblesToFile( mod_status_ram, N_RAM_SIZE, args.ram_file_name ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamRead
|
.title : RamRead
|
||||||
|
@ -356,7 +338,6 @@ Nibble RamRead(Address rel_address)
|
||||||
return mod_status_ram[ rel_address ];
|
return mod_status_ram[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamWrite
|
.title : RamWrite
|
||||||
|
@ -386,7 +367,6 @@ void RamWrite(Address rel_address, Nibble datum)
|
||||||
mod_status_ram[ rel_address ] = datum;
|
mod_status_ram[ rel_address ] = datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Ce1 module
|
Ce1 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -420,14 +400,12 @@ void Ce1Init(void)
|
||||||
/* Check if bank-switcher accelerators are valid; if not, initialize
|
/* Check if bank-switcher accelerators are valid; if not, initialize
|
||||||
them to a reasonable value (that is, select Port_2 bank 0).
|
them to a reasonable value (that is, select Port_2 bank 0).
|
||||||
*/
|
*/
|
||||||
if(!mod_status_hdw.accel_valid)
|
if ( !mod_status_hdw.accel_valid ) {
|
||||||
{
|
|
||||||
mod_status_hdw.accel_valid = 1;
|
mod_status_hdw.accel_valid = 1;
|
||||||
mod_status_hdw.accel.a48.bs_address = ( XAddress )0;
|
mod_status_hdw.accel.a48.bs_address = ( XAddress )0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Save
|
.title : Ce1Save
|
||||||
|
@ -458,7 +436,6 @@ void Ce1Save(void)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Read
|
.title : Ce1Read
|
||||||
|
@ -494,14 +471,12 @@ Nibble Ce1Read(Address rel_address)
|
||||||
obtain a valid index in Port_2
|
obtain a valid index in Port_2
|
||||||
*/
|
*/
|
||||||
#ifdef N_PORT_2_BANK
|
#ifdef N_PORT_2_BANK
|
||||||
mod_status_hdw.accel.a48.bs_address =
|
mod_status_hdw.accel.a48.bs_address = ( ( XAddress )( ( rel_address >> 1 ) & 0x1F ) << 18 ) & ( N_PORT_2_SIZE - 1 );
|
||||||
((XAddress)((rel_address >> 1) & 0x1F) << 18) & (N_PORT_2_SIZE-1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ( Nibble )0x0;
|
return ( Nibble )0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Write
|
.title : Ce1Write
|
||||||
|
@ -535,7 +510,6 @@ void Ce1Write(Address rel_address, Nibble datum)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Ce2 module
|
Ce2 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -569,28 +543,23 @@ void Ce2Init(void)
|
||||||
|
|
||||||
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,
|
if ( ReadNibblesFromFile( args.port_1_file_name, N_PORT_1_SIZE, mod_status_port_1 ) ) {
|
||||||
mod_status_port_1))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_W_PORT_1_INIT, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_PORT_1_INIT, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
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 =
|
new_status = mod_status_hdw.card_status & ~( CE2_CARD_PRESENT | CE2_CARD_WE );
|
||||||
mod_status_hdw.card_status & ~(CE2_CARD_PRESENT|CE2_CARD_WE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Card present; check write protection */
|
/* Card present; check write protection */
|
||||||
new_status = mod_status_hdw.card_status | CE2_CARD_PRESENT;
|
new_status = mod_status_hdw.card_status | CE2_CARD_PRESENT;
|
||||||
|
|
||||||
if ( access( args.port_1_file_name, W_OK ) == 0 )
|
if ( access( args.port_1_file_name, W_OK ) == 0 )
|
||||||
new_status |= CE2_CARD_WE;
|
new_status |= CE2_CARD_WE;
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
new_status &= ~CE2_CARD_WE;
|
new_status &= ~CE2_CARD_WE;
|
||||||
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
@ -599,8 +568,7 @@ void Ce2Init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new_status != mod_status_hdw.card_status)
|
if ( new_status != mod_status_hdw.card_status ) {
|
||||||
{
|
|
||||||
/* card_status changed; update, set MP bit in HST and post
|
/* card_status changed; update, set MP bit in HST and post
|
||||||
interrupt request.
|
interrupt request.
|
||||||
*/
|
*/
|
||||||
|
@ -610,7 +578,6 @@ void Ce2Init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Save
|
.title : Ce2Save
|
||||||
|
@ -639,17 +606,13 @@ 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 */
|
/* Attempt to save only if port is write-enabled */
|
||||||
if((mod_status_hdw.card_status & CE2_CARD_WE) &&
|
if ( ( mod_status_hdw.card_status & CE2_CARD_WE ) && WriteNibblesToFile( mod_status_port_1, N_PORT_1_SIZE, args.port_1_file_name ) ) {
|
||||||
WriteNibblesToFile(mod_status_port_1, N_PORT_1_SIZE,
|
|
||||||
args.port_1_file_name))
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_E_PORT_1_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_PORT_1_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Read
|
.title : Ce2Read
|
||||||
|
@ -678,7 +641,6 @@ Nibble Ce2Read(Address rel_address)
|
||||||
return mod_status_port_1[ rel_address ];
|
return mod_status_port_1[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Write
|
.title : Ce2Write
|
||||||
|
@ -708,7 +670,6 @@ void Ce2Write(Address rel_address, Nibble datum)
|
||||||
mod_status_port_1[ rel_address ] = datum;
|
mod_status_port_1[ rel_address ] = datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
NCe3 module
|
NCe3 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -744,28 +705,23 @@ void NCe3Init(void)
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Init" );
|
||||||
|
|
||||||
#ifdef N_PORT_2_BANK
|
#ifdef N_PORT_2_BANK
|
||||||
if(ReadNibblesFromFile(args.port_2_file_name, N_PORT_2_SIZE,
|
if ( ReadNibblesFromFile( args.port_2_file_name, N_PORT_2_SIZE, mod_status_port_2 ) ) {
|
||||||
mod_status_port_2))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_W_PORT_2_INIT, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_PORT_2_INIT, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
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 =
|
new_status = mod_status_hdw.card_status & ~( NCE3_CARD_PRESENT | NCE3_CARD_WE );
|
||||||
mod_status_hdw.card_status & ~(NCE3_CARD_PRESENT|NCE3_CARD_WE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Card present; check write protection */
|
/* Card present; check write protection */
|
||||||
new_status = mod_status_hdw.card_status | NCE3_CARD_PRESENT;
|
new_status = mod_status_hdw.card_status | NCE3_CARD_PRESENT;
|
||||||
|
|
||||||
if ( access( args.port_2_file_name, W_OK ) == 0 )
|
if ( access( args.port_2_file_name, W_OK ) == 0 )
|
||||||
new_status |= NCE3_CARD_WE;
|
new_status |= NCE3_CARD_WE;
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
new_status &= ~NCE3_CARD_WE;
|
new_status &= ~NCE3_CARD_WE;
|
||||||
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
@ -776,13 +732,11 @@ void NCe3Init(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* If N_PORT_2_BANK is undefined, Port 2 is not emulated */
|
/* If N_PORT_2_BANK is undefined, Port 2 is not emulated */
|
||||||
new_status =
|
new_status = mod_status_hdw.card_status & ~( NCE3_CARD_PRESENT | NCE3_CARD_WE );
|
||||||
mod_status_hdw.card_status & ~(NCE3_CARD_PRESENT|NCE3_CARD_WE);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(new_status != mod_status_hdw.card_status)
|
if ( new_status != mod_status_hdw.card_status ) {
|
||||||
{
|
|
||||||
/* card_status changed; update, set MP bit in HST and post
|
/* card_status changed; update, set MP bit in HST and post
|
||||||
interrupt request.
|
interrupt request.
|
||||||
*/
|
*/
|
||||||
|
@ -792,7 +746,6 @@ void NCe3Init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Save
|
.title : NCe3Save
|
||||||
|
@ -821,10 +774,7 @@ void NCe3Save(void)
|
||||||
|
|
||||||
#ifdef N_PORT_2_BANK
|
#ifdef N_PORT_2_BANK
|
||||||
/* Attempt to save only if port is write-enabled */
|
/* Attempt to save only if port is write-enabled */
|
||||||
if((mod_status_hdw.card_status & NCE3_CARD_WE) &&
|
if ( ( mod_status_hdw.card_status & NCE3_CARD_WE ) && WriteNibblesToFile( mod_status_port_2, N_PORT_2_SIZE, args.port_2_file_name ) ) {
|
||||||
WriteNibblesToFile(mod_status_port_2, N_PORT_2_SIZE,
|
|
||||||
args.port_2_file_name))
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_E_PORT_2_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_PORT_2_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -832,7 +782,6 @@ void NCe3Save(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Read
|
.title : NCe3Read
|
||||||
|
@ -861,8 +810,7 @@ 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
|
#ifdef N_PORT_2_BANK
|
||||||
return
|
return mod_status_port_2[ rel_address | mod_status_hdw.accel.a48.bs_address ];
|
||||||
mod_status_port_2[rel_address | mod_status_hdw.accel.a48.bs_address];
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
ChfCondition MOD_E_NCE3_READ, CHF_ERROR, rel_address ChfEnd;
|
ChfCondition MOD_E_NCE3_READ, CHF_ERROR, rel_address ChfEnd;
|
||||||
|
@ -872,7 +820,6 @@ Nibble NCe3Read(Address rel_address)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Write
|
.title : NCe3Write
|
||||||
|
@ -903,8 +850,7 @@ 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
|
#ifdef N_PORT_2_BANK
|
||||||
mod_status_port_2[rel_address | mod_status_hdw.accel.a48.bs_address]
|
mod_status_port_2[ rel_address | mod_status_hdw.accel.a48.bs_address ] = datum;
|
||||||
= datum;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
ChfCondition MOD_E_NCE3_WRITE, CHF_ERROR, rel_address, datum ChfEnd;
|
ChfCondition MOD_E_NCE3_WRITE, CHF_ERROR, rel_address, datum ChfEnd;
|
||||||
|
|
|
@ -114,7 +114,6 @@ static char rcs_id[] = "$Id: romram49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $
|
||||||
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
#define CHF_MODULE_ID MOD_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
#define FLASH_VIEW_SELECTOR 0x40000
|
#define FLASH_VIEW_SELECTOR 0x40000
|
||||||
#define FLASH_BANK_MASK 0x3FFFF
|
#define FLASH_BANK_MASK 0x3FFFF
|
||||||
|
|
||||||
|
@ -130,7 +129,6 @@ static char rcs_id[] = "$Id: romram49.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $
|
||||||
*/
|
*/
|
||||||
struct ModStatus_49* mod_status_49;
|
struct ModStatus_49* mod_status_49;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Rom module
|
Rom module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -162,25 +160,18 @@ void RomInit49(void)
|
||||||
{
|
{
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit49" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomInit49" );
|
||||||
|
|
||||||
if((mod_status_49 =
|
if ( ( mod_status_49 = ( struct ModStatus_49* )malloc( sizeof( struct ModStatus_49 ) ) ) == ( struct ModStatus_49* )NULL ) {
|
||||||
(struct ModStatus_49 *)malloc(sizeof(struct ModStatus_49)))
|
|
||||||
== (struct ModStatus_49 *)NULL)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL,
|
ChfCondition MOD_F_MOD_STATUS_ALLOC, CHF_FATAL, sizeof( struct ModStatus_49 ) ChfEnd;
|
||||||
sizeof(struct ModStatus_49) ChfEnd;
|
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ReadNibblesFromFile(args.rom_file_name, N_FLASH_SIZE_49,
|
if ( ReadNibblesFromFile( args.rom_file_name, N_FLASH_SIZE_49, mod_status_49->flash ) ) {
|
||||||
mod_status_49->flash))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd;
|
ChfCondition MOD_F_ROM_INIT, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RomSave49
|
.title : RomSave49
|
||||||
|
@ -207,16 +198,13 @@ 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,
|
if ( WriteNibblesToFile( mod_status_49->flash, N_FLASH_SIZE_49, args.rom_file_name ) ) {
|
||||||
args.rom_file_name))
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_E_ROM_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_ROM_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RomRead49
|
.title : RomRead49
|
||||||
|
@ -244,13 +232,11 @@ Nibble RomRead49(Address rel_address)
|
||||||
|
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomRead49" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "RomRead49" );
|
||||||
|
|
||||||
view = mod_status.hdw.accel.a49.view[
|
view = mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ];
|
||||||
(rel_address & FLASH_VIEW_SELECTOR) != 0];
|
|
||||||
|
|
||||||
return mod_status_49->flash[ view | ( rel_address & FLASH_BANK_MASK ) ];
|
return mod_status_49->flash[ view | ( rel_address & FLASH_BANK_MASK ) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RomWrite49
|
.title : RomWrite49
|
||||||
|
@ -288,7 +274,6 @@ void RomWrite49(Address rel_address, Nibble datum)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Main Ram module
|
Main Ram module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -318,9 +303,7 @@ 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,
|
if ( ReadNibblesFromFile( args.ram_file_name, N_RAM_SIZE_49, mod_status_49->ram ) ) {
|
||||||
mod_status_49->ram))
|
|
||||||
{
|
|
||||||
ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd;
|
ChfCondition MOD_W_RAM_INIT, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
|
||||||
|
@ -328,7 +311,6 @@ void RamInit49(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamSave49
|
.title : RamSave49
|
||||||
|
@ -354,16 +336,13 @@ 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,
|
if ( WriteNibblesToFile( mod_status_49->ram, N_RAM_SIZE_49, args.ram_file_name ) ) {
|
||||||
args.ram_file_name))
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd;
|
ChfCondition MOD_E_RAM_SAVE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamRead49
|
.title : RamRead49
|
||||||
|
@ -392,7 +371,6 @@ Nibble RamRead49(Address rel_address)
|
||||||
return mod_status_49->ram[ rel_address ];
|
return mod_status_49->ram[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : RamWrite49
|
.title : RamWrite49
|
||||||
|
@ -422,7 +400,6 @@ void RamWrite49(Address rel_address, Nibble datum)
|
||||||
mod_status_49->ram[ rel_address ] = datum;
|
mod_status_49->ram[ rel_address ] = datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Ce1 module
|
Ce1 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -456,15 +433,12 @@ void Ce1Init49(void)
|
||||||
them to a reasonable value (that is, select Flash Rom bank 0 for
|
them to a reasonable value (that is, select Flash Rom bank 0 for
|
||||||
both views).
|
both views).
|
||||||
*/
|
*/
|
||||||
if(!mod_status.hdw.accel_valid)
|
if ( !mod_status.hdw.accel_valid ) {
|
||||||
{
|
|
||||||
mod_status.hdw.accel_valid = 1;
|
mod_status.hdw.accel_valid = 1;
|
||||||
mod_status.hdw.accel.a49.view[0] =
|
mod_status.hdw.accel.a49.view[ 0 ] = mod_status.hdw.accel.a49.view[ 1 ] = ( XAddress )0;
|
||||||
mod_status.hdw.accel.a49.view[1] = (XAddress)0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Save49
|
.title : Ce1Save49
|
||||||
|
@ -494,21 +468,17 @@ void Ce1Save49(void)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This fragment of code is used by both Ce1Read49() and Ce1Write49();
|
/* 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
|
the macro definition is here to allow us to write the code once and
|
||||||
use it many times without incurring a function call overhead.
|
use it many times without incurring a function call overhead.
|
||||||
*/
|
*/
|
||||||
#define Ce1SetViews \
|
#define Ce1SetViews \
|
||||||
{ \
|
{ \
|
||||||
mod_status.hdw.accel.a49.view[0] = \
|
mod_status.hdw.accel.a49.view[ 0 ] = ( ( XAddress )( ( rel_address >> 5 ) & 0x03 ) << 18 ); \
|
||||||
((XAddress)((rel_address >> 5) & 0x03) << 18); \
|
|
||||||
\
|
\
|
||||||
mod_status.hdw.accel.a49.view[1] = \
|
mod_status.hdw.accel.a49.view[ 1 ] = ( ( XAddress )( ( rel_address >> 1 ) & 0x0F ) << 18 ); \
|
||||||
((XAddress)((rel_address >> 1) & 0x0F) << 18); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Read49
|
.title : Ce1Read49
|
||||||
|
@ -548,7 +518,6 @@ Nibble Ce1Read49(Address rel_address)
|
||||||
return ( Nibble )0x0;
|
return ( Nibble )0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce1Write49
|
.title : Ce1Write49
|
||||||
|
@ -587,7 +556,6 @@ void Ce1Write49(Address rel_address, Nibble datum)
|
||||||
Ce1SetViews;
|
Ce1SetViews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Ce2 module
|
Ce2 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -635,7 +603,6 @@ void Ce2Init49(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Save49
|
.title : Ce2Save49
|
||||||
|
@ -663,7 +630,6 @@ void Ce2Save49(void)
|
||||||
/* Do nothing; the whole RAM is saved by RamSave49() */
|
/* Do nothing; the whole RAM is saved by RamSave49() */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Read49
|
.title : Ce2Read49
|
||||||
|
@ -691,7 +657,6 @@ Nibble Ce2Read49(Address rel_address)
|
||||||
return mod_status_49->ce2[ rel_address ];
|
return mod_status_49->ce2[ rel_address ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Ce2Write49
|
.title : Ce2Write49
|
||||||
|
@ -720,7 +685,6 @@ void Ce2Write49(Address rel_address, Nibble datum)
|
||||||
mod_status_49->ce2[ rel_address ] = datum;
|
mod_status_49->ce2[ rel_address ] = datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
NCe3 module
|
NCe3 module
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -768,7 +732,6 @@ void NCe3Init49(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Save49
|
.title : NCe3Save49
|
||||||
|
@ -796,7 +759,6 @@ void NCe3Save49(void)
|
||||||
/* Do nothing; the whole RAM is saved by RamSave49() */
|
/* Do nothing; the whole RAM is saved by RamSave49() */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Read49
|
.title : NCe3Read49
|
||||||
|
@ -831,16 +793,12 @@ Nibble NCe3Read49(Address rel_address)
|
||||||
{
|
{
|
||||||
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read49" );
|
debug1( DEBUG_C_TRACE, MOD_I_CALLED, "NCe3Read49" );
|
||||||
|
|
||||||
return
|
return ( mod_status.hdw.hdw[ HDW_LCR_OFFSET ] & LCR_LED )
|
||||||
(mod_status.hdw.hdw[HDW_LCR_OFFSET] & LCR_LED)
|
? FlashRead49( mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ] |
|
||||||
? FlashRead49(
|
( rel_address & FLASH_BANK_MASK ) )
|
||||||
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 ];
|
: mod_status_49->nce3[ rel_address & NCE3_RAM_MASK ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : NCe3Write49
|
.title : NCe3Write49
|
||||||
|
@ -878,9 +836,7 @@ 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 )
|
if ( mod_status.hdw.hdw[ HDW_LCR_OFFSET ] & LCR_LED )
|
||||||
FlashWrite49(mod_status.hdw.accel.a49.view[
|
FlashWrite49( mod_status.hdw.accel.a49.view[ ( rel_address & FLASH_VIEW_SELECTOR ) != 0 ] | ( rel_address & FLASH_BANK_MASK ),
|
||||||
(rel_address & FLASH_VIEW_SELECTOR) != 0]
|
|
||||||
| (rel_address & FLASH_BANK_MASK),
|
|
||||||
datum );
|
datum );
|
||||||
else
|
else
|
||||||
mod_status_49->nce3[ rel_address & NCE3_RAM_MASK ] = datum;
|
mod_status_49->nce3[ rel_address & NCE3_RAM_MASK ] = datum;
|
||||||
|
|
156
src/serial.c
156
src/serial.c
|
@ -120,7 +120,6 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID SERIAL_CHF_MODULE_ID
|
#define CHF_MODULE_ID SERIAL_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Determine pty implementation
|
Determine pty implementation
|
||||||
|
|
||||||
|
@ -169,7 +168,6 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
|
|
||||||
#undef FORCED
|
#undef FORCED
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Include pty implementation-specific headers and definitions
|
Include pty implementation-specific headers and definitions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -194,7 +192,6 @@ static char rcs_id[] = "$Id: serial.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
# define PTY_MASTER "/dev/ptmx" /* Master cloning device */
|
# define PTY_MASTER "/dev/ptmx" /* Master cloning device */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private implementation of ring buffers
|
Private implementation of ring buffers
|
||||||
|
|
||||||
|
@ -209,8 +206,7 @@ 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-} */
|
/* Hello, I am a RingBuffer... 8-} */
|
||||||
struct RingBuffer
|
struct RingBuffer {
|
||||||
{
|
|
||||||
int n; /* Number of full slots: 0 <= n <= RB_SIZE */
|
int n; /* Number of full slots: 0 <= n <= RB_SIZE */
|
||||||
int8 *rp, *wp; /* Read/Write pointers */
|
int8 *rp, *wp; /* Read/Write pointers */
|
||||||
int8* ep; /* Pointer to the end of .data[] */
|
int8* ep; /* Pointer to the end of .data[] */
|
||||||
|
@ -272,28 +268,32 @@ struct RingBuffer
|
||||||
{ \
|
{ \
|
||||||
FullSlots( rb ) -= ( n ); \
|
FullSlots( rb ) -= ( n ); \
|
||||||
ReadPointer( rb ) += ( n ); \
|
ReadPointer( rb ) += ( n ); \
|
||||||
if(ReadPointer(rb) >= (rb).ep) ReadPointer(rb) -= RB_SIZE; \
|
if ( ReadPointer( rb ) >= ( rb ).ep ) \
|
||||||
|
ReadPointer( rb ) -= RB_SIZE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UpdateWritePointer( rb, n ) \
|
#define UpdateWritePointer( rb, n ) \
|
||||||
{ \
|
{ \
|
||||||
FullSlots( rb ) += ( n ); \
|
FullSlots( rb ) += ( n ); \
|
||||||
WritePointer( rb ) += ( n ); \
|
WritePointer( rb ) += ( n ); \
|
||||||
if(WritePointer(rb) >= (rb).ep) WritePointer(rb) -= RB_SIZE; \
|
if ( WritePointer( rb ) >= ( rb ).ep ) \
|
||||||
|
WritePointer( rb ) -= RB_SIZE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define Push( rb, c ) \
|
#define Push( rb, c ) \
|
||||||
{ \
|
{ \
|
||||||
FullSlots( rb )++; \
|
FullSlots( rb )++; \
|
||||||
*( WritePointer( rb )++ ) = c; \
|
*( WritePointer( rb )++ ) = c; \
|
||||||
if(WritePointer(rb) >= (rb).ep) WritePointer(rb) -= RB_SIZE; \
|
if ( WritePointer( rb ) >= ( rb ).ep ) \
|
||||||
|
WritePointer( rb ) -= RB_SIZE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define Pull( rb, cp ) \
|
#define Pull( rb, cp ) \
|
||||||
{ \
|
{ \
|
||||||
FullSlots( rb )--; \
|
FullSlots( rb )--; \
|
||||||
*cp = *( ReadPointer( rb )++ ); \
|
*cp = *( ReadPointer( rb )++ ); \
|
||||||
if(ReadPointer(rb) >= (rb).ep) ReadPointer(rb) -= RB_SIZE; \
|
if ( ReadPointer( rb ) >= ( rb ).ep ) \
|
||||||
|
ReadPointer( rb ) -= RB_SIZE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define InitRingBuffer( rb ) \
|
#define InitRingBuffer( rb ) \
|
||||||
|
@ -322,8 +322,7 @@ 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)
|
while ( FullSlots( *rbp ) > 0 ) {
|
||||||
{
|
|
||||||
int chunk = ContFullSlots( *rbp ); /* Chunk size */
|
int chunk = ContFullSlots( *rbp ); /* Chunk size */
|
||||||
int result; /* # of chars written */
|
int result; /* # of chars written */
|
||||||
|
|
||||||
|
@ -334,8 +333,7 @@ static int PullAndWrite(struct RingBuffer *rbp, int fd)
|
||||||
/* write() failed; return an error indication */
|
/* write() failed; return an error indication */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(result > 0)
|
if ( result > 0 ) {
|
||||||
{
|
|
||||||
/* write() wrote at least one character; update ReadPointer */
|
/* write() wrote at least one character; update ReadPointer */
|
||||||
total += result;
|
total += result;
|
||||||
UpdateReadPointer( *rbp, result );
|
UpdateReadPointer( *rbp, result );
|
||||||
|
@ -353,8 +351,7 @@ 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)
|
while ( EmptySlots( *rbp ) > 0 ) {
|
||||||
{
|
|
||||||
int chunk = ContEmptySlots( *rbp ); /* Chunk size */
|
int chunk = ContEmptySlots( *rbp ); /* Chunk size */
|
||||||
int result; /* # of chars read */
|
int result; /* # of chars read */
|
||||||
|
|
||||||
|
@ -365,8 +362,7 @@ static int ReadAndPush(struct RingBuffer *rbp, int fd)
|
||||||
/* read() failed; return an error indication */
|
/* read() failed; return an error indication */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(result > 0)
|
if ( result > 0 ) {
|
||||||
{
|
|
||||||
/* read() read at least one character; update WritePointer */
|
/* read() read at least one character; update WritePointer */
|
||||||
total += result;
|
total += result;
|
||||||
UpdateWritePointer( *rbp, result );
|
UpdateWritePointer( *rbp, result );
|
||||||
|
@ -380,7 +376,6 @@ static int ReadAndPush(struct RingBuffer *rbp, int fd)
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Static variables, holding the status of the emulated port
|
Static variables, holding the status of the emulated port
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -410,7 +405,6 @@ static char *pty_name; /* Name of pty's slave side */
|
||||||
static int master_pty; /* File descriptor of pty's master side */
|
static int master_pty; /* File descriptor of pty's master side */
|
||||||
static int slave_pty; /* File descriptor of pty's slave side */
|
static int slave_pty; /* File descriptor of pty's slave side */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Helper macros
|
Helper macros
|
||||||
|
|
||||||
|
@ -445,61 +439,43 @@ static int slave_pty; /* File descriptor of pty's slave side */
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define CheckIRQ \
|
#define CheckIRQ \
|
||||||
if((ioc & IOC_SON) \
|
if ( ( ioc & IOC_SON ) && ( ( ( ioc & IOC_ETBE ) && ( !( tcs & TCS_TBF ) ) ) || ( ( ioc & IOC_ERBF ) && ( rcs & RCS_RBF ) ) || \
|
||||||
&& ( \
|
( ( ioc & IOC_ERBZ ) && ( rcs & RCS_RBZ ) ) ) ) \
|
||||||
((ioc & IOC_ETBE) && (! (tcs & TCS_TBF))) \
|
CpuIntRequest( INT_REQUEST_IRQ )
|
||||||
|| ((ioc & IOC_ERBF) && (rcs & RCS_RBF)) \
|
|
||||||
|| ((ioc & IOC_ERBZ) && (rcs & RCS_RBZ)) \
|
|
||||||
)) CpuIntRequest(INT_REQUEST_IRQ)
|
|
||||||
|
|
||||||
#ifdef HP49_SUPPORT
|
#ifdef HP49_SUPPORT
|
||||||
# define UpdateRCS \
|
# define UpdateRCS \
|
||||||
if(FullSlots(rrb) > 0) \
|
if ( FullSlots( rrb ) > 0 ) { \
|
||||||
{ \
|
|
||||||
rcs |= RCS_RBF; \
|
rcs |= RCS_RBF; \
|
||||||
} \
|
} else { \
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
rcs &= ~( RCS_RBF ); \
|
rcs &= ~( RCS_RBF ); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define UpdateRCS \
|
# define UpdateRCS \
|
||||||
if(FullSlots(rrb) > 1) \
|
if ( FullSlots( rrb ) > 1 ) { \
|
||||||
{ \
|
|
||||||
rcs |= ( RCS_RBF | RCS_RBZ ); \
|
rcs |= ( RCS_RBF | RCS_RBZ ); \
|
||||||
} \
|
} else if ( FullSlots( rrb ) > 0 ) { \
|
||||||
else if(FullSlots(rrb) > 0) \
|
|
||||||
{ \
|
|
||||||
rcs |= RCS_RBF; \
|
rcs |= RCS_RBF; \
|
||||||
rcs &= ~RCS_RBZ; \
|
rcs &= ~RCS_RBZ; \
|
||||||
} \
|
} else { \
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
rcs &= ~( RCS_RBF | RCS_RBZ ); \
|
rcs &= ~( RCS_RBF | RCS_RBZ ); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define UpdateTCS \
|
#define UpdateTCS \
|
||||||
if(EmptySlots(trb) > 1) \
|
if ( EmptySlots( trb ) > 1 ) { \
|
||||||
{ \
|
|
||||||
tcs &= ~( TCS_TBF | TCS_TBZ ); \
|
tcs &= ~( TCS_TBF | TCS_TBZ ); \
|
||||||
} \
|
} else if ( EmptySlots( trb ) > 0 ) { \
|
||||||
else if(EmptySlots(trb) > 0) \
|
|
||||||
{ \
|
|
||||||
tcs &= ~TCS_TBF; \
|
tcs &= ~TCS_TBF; \
|
||||||
tcs |= TCS_TBZ; \
|
tcs |= TCS_TBZ; \
|
||||||
} \
|
} else { \
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
tcs |= ( TCS_TBF | TCS_TBZ ); \
|
tcs |= ( TCS_TBF | TCS_TBZ ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : SerialInit
|
.title : SerialInit
|
||||||
|
@ -560,8 +536,7 @@ const char *SerialInit(void)
|
||||||
/* Open pty master/slave pair; don't specify pty name, struct termios
|
/* Open pty master/slave pair; don't specify pty name, struct termios
|
||||||
and struct winsize.
|
and struct winsize.
|
||||||
*/
|
*/
|
||||||
if(openpty(&master_pty, &slave_pty, NULL, NULL, NULL))
|
if ( openpty( &master_pty, &slave_pty, NULL, NULL, NULL ) ) {
|
||||||
{
|
|
||||||
pty_name = ( char* )NULL;
|
pty_name = ( char* )NULL;
|
||||||
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
@ -569,8 +544,7 @@ const char *SerialInit(void)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int cur_flags;
|
int cur_flags;
|
||||||
|
|
||||||
pty_name = ttyname( slave_pty );
|
pty_name = ttyname( slave_pty );
|
||||||
|
@ -579,9 +553,7 @@ const char *SerialInit(void)
|
||||||
atexit( SerialClose );
|
atexit( SerialClose );
|
||||||
|
|
||||||
/* Set O_NONBLOCK on master_pty */
|
/* Set O_NONBLOCK on master_pty */
|
||||||
if((cur_flags = fcntl(master_pty, F_GETFL, 0)) < 0
|
if ( ( cur_flags = fcntl( master_pty, F_GETFL, 0 ) ) < 0 || fcntl( master_pty, F_SETFL, cur_flags | O_NONBLOCK ) < 0 ) {
|
||||||
|| fcntl(master_pty, F_SETFL, cur_flags|O_NONBLOCK) < 0)
|
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_F_FCNTL, CHF_FATAL ChfEnd;
|
ChfCondition SERIAL_F_FCNTL, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -591,8 +563,7 @@ const char *SerialInit(void)
|
||||||
|
|
||||||
# ifdef USE_STREAMSPTY
|
# ifdef USE_STREAMSPTY
|
||||||
/* Open master cloning device */
|
/* Open master cloning device */
|
||||||
if((master_pty = open(PTY_MASTER, O_RDWR|O_NONBLOCK)) < 0)
|
if ( ( master_pty = open( PTY_MASTER, O_RDWR | O_NONBLOCK ) ) < 0 ) {
|
||||||
{
|
|
||||||
pty_name = ( char* )NULL;
|
pty_name = ( char* )NULL;
|
||||||
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
@ -600,12 +571,10 @@ const char *SerialInit(void)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Master side opened ok; change permissions and unlock slave side */
|
/* Master side opened ok; change permissions and unlock slave side */
|
||||||
|
|
||||||
if(grantpt(master_pty) < 0)
|
if ( grantpt( master_pty ) < 0 ) {
|
||||||
{
|
|
||||||
/* close() may modify errno; save it first */
|
/* close() may modify errno; save it first */
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
|
||||||
|
@ -615,8 +584,7 @@ const char *SerialInit(void)
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unlockpt(master_pty) < 0)
|
if ( unlockpt( master_pty ) < 0 ) {
|
||||||
{
|
|
||||||
/* close() may modify errno; save it first */
|
/* close() may modify errno; save it first */
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
|
||||||
|
@ -630,8 +598,7 @@ const char *SerialInit(void)
|
||||||
pty_name = ptsname( master_pty );
|
pty_name = ptsname( master_pty );
|
||||||
|
|
||||||
/* Open slave in nonblocking mode */
|
/* Open slave in nonblocking mode */
|
||||||
if((slave_pty = open(pty_name, O_RDWR|O_NONBLOCK)) < 0)
|
if ( ( slave_pty = open( pty_name, O_RDWR | O_NONBLOCK ) ) < 0 ) {
|
||||||
{
|
|
||||||
/* close() may modify errno; save it first */
|
/* close() may modify errno; save it first */
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
|
|
||||||
|
@ -648,20 +615,17 @@ const char *SerialInit(void)
|
||||||
terminal emulation. This way, the slave side should be
|
terminal emulation. This way, the slave side should be
|
||||||
indistinguishable from a real terminal.
|
indistinguishable from a real terminal.
|
||||||
*/
|
*/
|
||||||
if(ioctl(slave_pty, I_PUSH, "ptem") == -1)
|
if ( ioctl( slave_pty, I_PUSH, "ptem" ) == -1 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ptem" ChfEnd;
|
ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ptem" ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ioctl(slave_pty, I_PUSH, "ldterm") == -1)
|
if ( ioctl( slave_pty, I_PUSH, "ldterm" ) == -1 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ldterm" ChfEnd;
|
ChfCondition SERIAL_F_PUSH, CHF_FATAL, "ldterm" ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
@ -673,20 +637,18 @@ const char *SerialInit(void)
|
||||||
{
|
{
|
||||||
struct termios tios;
|
struct termios tios;
|
||||||
|
|
||||||
if(tcgetattr(slave_pty, &tios))
|
if ( tcgetattr( slave_pty, &tios ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_F_TCGETATTR, CHF_FATAL ChfEnd;
|
ChfCondition SERIAL_F_TCGETATTR, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
tios.c_iflag &= ~(BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR
|
tios.c_iflag &= ~( BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IUCLC | IXON | IXANY | IXOFF | IMAXBEL );
|
||||||
|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
|
tios.c_oflag &=
|
||||||
|OFDEL|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
|
~( 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 );
|
||||||
|
|
||||||
|
@ -700,13 +662,11 @@ const char *SerialInit(void)
|
||||||
tios.c_cc[ VMIN ] = 1;
|
tios.c_cc[ VMIN ] = 1;
|
||||||
tios.c_cc[ VTIME ] = 0;
|
tios.c_cc[ VTIME ] = 0;
|
||||||
|
|
||||||
if(tcsetattr(slave_pty, TCSANOW, &tios))
|
if ( tcsetattr( slave_pty, TCSANOW, &tios ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_F_TCSETATTR, CHF_FATAL ChfEnd;
|
ChfCondition SERIAL_F_TCSETATTR, CHF_FATAL ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
@ -725,7 +685,6 @@ const char *SerialInit(void)
|
||||||
return pty_name;
|
return pty_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : SerialClose
|
.title : SerialClose
|
||||||
|
@ -758,15 +717,13 @@ 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))
|
if ( close( slave_pty ) || close( master_pty ) ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_E_PTY_CLOSE, CHF_ERROR ChfEnd;
|
ChfCondition SERIAL_E_PTY_CLOSE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : SerialPtyName
|
.title : SerialPtyName
|
||||||
|
@ -800,7 +757,6 @@ const char *SerialPtyName(void)
|
||||||
return pty_name;
|
return pty_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_IOC_Read
|
.title : Serial_IOC_Read
|
||||||
|
@ -834,7 +790,6 @@ Nibble Serial_IOC_Read(void)
|
||||||
return ioc;
|
return ioc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_RCS_Read
|
.title : Serial_RCS_Read
|
||||||
|
@ -868,7 +823,6 @@ Nibble Serial_RCS_Read(void)
|
||||||
return rcs;
|
return rcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_TCS_Read
|
.title : Serial_TCS_Read
|
||||||
|
@ -902,7 +856,6 @@ Nibble Serial_TCS_Read(void)
|
||||||
return tcs;
|
return tcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_RBR_Read
|
.title : Serial_RBR_Read
|
||||||
|
@ -940,13 +893,11 @@ int8 Serial_RBR_Read(void)
|
||||||
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 */
|
/* Pull one character from rbr, if not empty */
|
||||||
if(FullSlots(rrb) > 0)
|
if ( FullSlots( rrb ) > 0 ) {
|
||||||
{
|
|
||||||
Pull( rrb, &rx );
|
Pull( rrb, &rx );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* rrb is empty */
|
/* rrb is empty */
|
||||||
|
|
||||||
#ifndef HP49_SUPPORT
|
#ifndef HP49_SUPPORT
|
||||||
|
@ -960,7 +911,6 @@ int8 Serial_RBR_Read(void)
|
||||||
rx = ( int8 )0xFF;
|
rx = ( int8 )0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Update receiver status */
|
/* Update receiver status */
|
||||||
UpdateRCS;
|
UpdateRCS;
|
||||||
|
|
||||||
|
@ -971,7 +921,6 @@ int8 Serial_RBR_Read(void)
|
||||||
return rx;
|
return rx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_IOC_Write
|
.title : Serial_IOC_Write
|
||||||
|
@ -1008,7 +957,6 @@ void Serial_IOC_Write(Nibble n)
|
||||||
CheckIRQ;
|
CheckIRQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_RCS_Write
|
.title : Serial_RCS_Write
|
||||||
|
@ -1042,7 +990,6 @@ void Serial_RCS_Write(Nibble n)
|
||||||
rcs = n;
|
rcs = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_TCS_Write
|
.title : Serial_TCS_Write
|
||||||
|
@ -1076,7 +1023,6 @@ void Serial_TCS_Write(Nibble n)
|
||||||
tcs = n;
|
tcs = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_CRER_Write
|
.title : Serial_CRER_Write
|
||||||
|
@ -1109,7 +1055,6 @@ void Serial_CRER_Write(Nibble n)
|
||||||
rcs &= ~RCS_RER;
|
rcs &= ~RCS_RER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : Serial_TBR_Write
|
.title : Serial_TBR_Write
|
||||||
|
@ -1144,13 +1089,11 @@ void Serial_TBR_Write(int8 d)
|
||||||
debug1( DEBUG_C_SERIAL, SERIAL_I_TBR, d );
|
debug1( DEBUG_C_SERIAL, SERIAL_I_TBR, d );
|
||||||
|
|
||||||
/* Pull one character from rbr, if not empty */
|
/* Pull one character from rbr, if not empty */
|
||||||
if(EmptySlots(trb) > 0)
|
if ( EmptySlots( trb ) > 0 ) {
|
||||||
{
|
|
||||||
Push( trb, d );
|
Push( trb, d );
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* trb is full; discard character */
|
/* trb is full; discard character */
|
||||||
ChfCondition SERIAL_W_FULL_TRB, CHF_WARNING, tcs ChfEnd;
|
ChfCondition SERIAL_W_FULL_TRB, CHF_WARNING, tcs ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -1163,7 +1106,6 @@ void Serial_TBR_Write(int8 d)
|
||||||
CheckIRQ;
|
CheckIRQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : HandleSerial
|
.title : HandleSerial
|
||||||
|
@ -1213,8 +1155,7 @@ void HandleSerial(void)
|
||||||
result = PullAndWrite( &trb, master_pty );
|
result = PullAndWrite( &trb, master_pty );
|
||||||
|
|
||||||
/* Signal a condition upon failure */
|
/* Signal a condition upon failure */
|
||||||
if(result < 0)
|
if ( result < 0 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_E_TRB_DRAIN, CHF_ERROR ChfEnd;
|
ChfCondition SERIAL_E_TRB_DRAIN, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -1223,14 +1164,12 @@ void HandleSerial(void)
|
||||||
/* Update tcs */
|
/* Update tcs */
|
||||||
UpdateTCS;
|
UpdateTCS;
|
||||||
|
|
||||||
if(ioc & IOC_SON)
|
if ( ioc & IOC_SON ) {
|
||||||
{
|
|
||||||
/* Attempt to charge receiver buffer */
|
/* Attempt to charge receiver buffer */
|
||||||
result = ReadAndPush( &rrb, master_pty );
|
result = ReadAndPush( &rrb, master_pty );
|
||||||
|
|
||||||
/* Signal a condition upon failure */
|
/* Signal a condition upon failure */
|
||||||
if(result < 0)
|
if ( result < 0 ) {
|
||||||
{
|
|
||||||
ChfErrnoCondition;
|
ChfErrnoCondition;
|
||||||
ChfCondition SERIAL_E_RRB_CHARGE, CHF_ERROR ChfEnd;
|
ChfCondition SERIAL_E_RRB_CHARGE, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
|
@ -1243,5 +1182,4 @@ void HandleSerial(void)
|
||||||
CheckIRQ;
|
CheckIRQ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,14 +80,12 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
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
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -115,7 +113,6 @@
|
||||||
#define SERIAL_F_TCGETATTR 408 /* tcgetattr() failed on master */
|
#define SERIAL_F_TCGETATTR 408 /* tcgetattr() failed on master */
|
||||||
#define SERIAL_F_TCSETATTR 409 /* tcsetattr() failed on master */
|
#define SERIAL_F_TCSETATTR 409 /* tcsetattr() failed on master */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
407
src/t48.c
407
src/t48.c
|
@ -90,7 +90,6 @@ static char rcs_id[] = "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID X11_CHF_MODULE_ID
|
#define CHF_MODULE_ID X11_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf parameters - Do not change.
|
Chf parameters - Do not change.
|
||||||
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
The ABNORMAL_EXIT_CODE is taken from stdlib.h (EXIT_FAILURE)
|
||||||
|
@ -101,7 +100,6 @@ static char rcs_id[] = "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define HANDLER_STACK_SIZE 8
|
#define HANDLER_STACK_SIZE 8
|
||||||
#define ABNORMAL_EXIT_CODE EXIT_FAILURE
|
#define ABNORMAL_EXIT_CODE EXIT_FAILURE
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Other parameters
|
Other parameters
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -110,7 +108,6 @@ static char rcs_id[] = "$Id: t48.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define LCD_BACKGROUND "green"
|
#define LCD_BACKGROUND "green"
|
||||||
#define LCD_FOREGROUND "black"
|
#define LCD_FOREGROUND "black"
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private variables
|
Private variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -119,8 +116,7 @@ static XtAppContext app_context;
|
||||||
static Widget shell_widget;
|
static Widget shell_widget;
|
||||||
|
|
||||||
/* Command line options descriptor */
|
/* Command line options descriptor */
|
||||||
XrmOptionDescRec options[] =
|
XrmOptionDescRec options[] = {
|
||||||
{
|
|
||||||
/* option, specifier, argKind, value */
|
/* option, specifier, argKind, value */
|
||||||
{ "-reset", "*reset", XrmoptionNoArg, "True" },
|
{ "-reset", "*reset", XrmoptionNoArg, "True" },
|
||||||
{ "-monitor", "*monitor", XrmoptionNoArg, "True" },
|
{ "-monitor", "*monitor", XrmoptionNoArg, "True" },
|
||||||
|
@ -136,17 +132,13 @@ XrmOptionDescRec options[] =
|
||||||
|
|
||||||
#define NUM_OPTIONS ( sizeof( options ) / sizeof( XrmOptionDescRec ) )
|
#define NUM_OPTIONS ( sizeof( options ) / sizeof( XrmOptionDescRec ) )
|
||||||
|
|
||||||
|
|
||||||
/* Application fallback resources */
|
/* Application fallback resources */
|
||||||
String fallback_resources[] =
|
String fallback_resources[] = {
|
||||||
{
|
|
||||||
NULL /* Null terminated */
|
NULL /* Null terminated */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Application options container */
|
/* Application options container */
|
||||||
struct app_opt
|
struct app_opt {
|
||||||
{
|
|
||||||
Boolean reset;
|
Boolean reset;
|
||||||
Boolean monitor;
|
Boolean monitor;
|
||||||
Pixel fg_pix;
|
Pixel fg_pix;
|
||||||
|
@ -161,63 +153,24 @@ struct app_opt
|
||||||
String port2;
|
String port2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Application resources/options descriptor */
|
/* Application resources/options descriptor */
|
||||||
XtResource app_res[] =
|
XtResource app_res[] = {
|
||||||
{
|
{"foreground", "Foreground", XtRPixel, sizeof( Pixel ), XtOffsetOf( struct app_opt, fg_pix ), XtRString, LCD_FOREGROUND},
|
||||||
{ "foreground", "Foreground",
|
{"background", "Background", XtRPixel, sizeof( Pixel ), XtOffsetOf( struct app_opt, bg_pix ), XtRString, LCD_BACKGROUND},
|
||||||
XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_opt, fg_pix),
|
{"reset", "Reset", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, reset ), XtRString, "False" },
|
||||||
XtRString, LCD_FOREGROUND
|
{"monitor", "Monitor", XtRBoolean, sizeof( Boolean ), XtOffsetOf( struct app_opt, monitor ), XtRString, "False" },
|
||||||
},
|
{"path", "Path", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, path ), XtRString, "." },
|
||||||
{ "background", "Background",
|
{"cpu", "Cpu", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, cpu ), XtRString, "cpu" },
|
||||||
XtRPixel, sizeof(Pixel), XtOffsetOf(struct app_opt, bg_pix),
|
{"mod", "Mod", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, mod ), XtRString, "mod" },
|
||||||
XtRString, LCD_BACKGROUND
|
{"hdw", "Hdw", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, hdw ), XtRString, "hdw" },
|
||||||
},
|
{"rom", "Rom", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, rom ), XtRString, "rom" },
|
||||||
{ "reset", "Reset",
|
{"ram", "Ram", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, ram ), XtRString, "ram" },
|
||||||
XtRBoolean, sizeof(Boolean), XtOffsetOf(struct app_opt, reset),
|
{"port1", "Port1", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port1 ), XtRString, "port1" },
|
||||||
XtRString, "False"
|
{"port2", "Port2", XtRString, sizeof( String ), XtOffsetOf( struct app_opt, port2 ), XtRString, "port2" }
|
||||||
},
|
|
||||||
{ "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
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -225,7 +178,6 @@ XtResource app_res[] =
|
||||||
/* Emulator options */
|
/* Emulator options */
|
||||||
struct Args args;
|
struct Args args;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions
|
Private functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -233,109 +185,180 @@ struct Args args;
|
||||||
/* KeySym -> HP48 'enum Key' translator */
|
/* KeySym -> HP48 'enum Key' translator */
|
||||||
static enum Key Ks2K( KeySym ks )
|
static enum Key Ks2K( KeySym ks )
|
||||||
{
|
{
|
||||||
switch(ks)
|
switch ( ks ) {
|
||||||
{
|
|
||||||
/* Backspace */
|
/* Backspace */
|
||||||
case XK_BackSpace: return KEY_BKSP;
|
case XK_BackSpace:
|
||||||
|
return KEY_BKSP;
|
||||||
|
|
||||||
/* Delete */
|
/* Delete */
|
||||||
case XK_Delete: return KEY_DEL;
|
case XK_Delete:
|
||||||
case XK_KP_Delete: return KEY_DEL;
|
return KEY_DEL;
|
||||||
|
case XK_KP_Delete:
|
||||||
|
return KEY_DEL;
|
||||||
|
|
||||||
/* Enter */
|
/* Enter */
|
||||||
case XK_KP_Enter: return KEY_ENTER;
|
case XK_KP_Enter:
|
||||||
case XK_Return: return KEY_ENTER;
|
return KEY_ENTER;
|
||||||
|
case XK_Return:
|
||||||
|
return KEY_ENTER;
|
||||||
|
|
||||||
/* Cursor keys */
|
/* Cursor keys */
|
||||||
case XK_KP_Left: return KEY_LEFT;
|
case XK_KP_Left:
|
||||||
case XK_Left: return KEY_LEFT;
|
return KEY_LEFT;
|
||||||
|
case XK_Left:
|
||||||
|
return KEY_LEFT;
|
||||||
|
|
||||||
case XK_KP_Right: return KEY_RIGHT;
|
case XK_KP_Right:
|
||||||
case XK_Right: return KEY_RIGHT;
|
return KEY_RIGHT;
|
||||||
|
case XK_Right:
|
||||||
|
return KEY_RIGHT;
|
||||||
|
|
||||||
case XK_KP_Up: return KEY_UP;
|
case XK_KP_Up:
|
||||||
case XK_Up: return KEY_UP;
|
return KEY_UP;
|
||||||
|
case XK_Up:
|
||||||
|
return KEY_UP;
|
||||||
|
|
||||||
case XK_KP_Down: return KEY_DOWN;
|
case XK_KP_Down:
|
||||||
case XK_Down: return KEY_DOWN;
|
return KEY_DOWN;
|
||||||
|
case XK_Down:
|
||||||
|
return KEY_DOWN;
|
||||||
|
|
||||||
/* Function keys */
|
/* Function keys */
|
||||||
case XK_F1: return KEY_F1;
|
case XK_F1:
|
||||||
case XK_F2: return KEY_F2;
|
return KEY_F1;
|
||||||
case XK_F3: return KEY_F3;
|
case XK_F2:
|
||||||
case XK_F4: return KEY_F4;
|
return KEY_F2;
|
||||||
case XK_F5: return KEY_F5;
|
case XK_F3:
|
||||||
case XK_F6: return KEY_F6;
|
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 */
|
/* Shift L, R, Alpha, ON */
|
||||||
case XK_Shift_L: return KEY_SH_L;
|
case XK_Shift_L:
|
||||||
case XK_Shift_R: return KEY_SH_R;
|
return KEY_SH_L;
|
||||||
case XK_Alt_L: return KEY_ALPHA;
|
case XK_Shift_R:
|
||||||
case XK_Alt_R: return KEY_ALPHA;
|
return KEY_SH_R;
|
||||||
case XK_Escape: return KEY_ON;
|
case XK_Alt_L:
|
||||||
|
return KEY_ALPHA;
|
||||||
|
case XK_Alt_R:
|
||||||
|
return KEY_ALPHA;
|
||||||
|
case XK_Escape:
|
||||||
|
return KEY_ON;
|
||||||
|
|
||||||
/* Numeric keypad and surroundings */
|
/* Numeric keypad and surroundings */
|
||||||
case XK_KP_0: return KEY_0;
|
case XK_KP_0:
|
||||||
case XK_KP_1: return KEY_1;
|
return KEY_0;
|
||||||
case XK_KP_2: return KEY_2;
|
case XK_KP_1:
|
||||||
case XK_KP_3: return KEY_3;
|
return KEY_1;
|
||||||
case XK_KP_4: return KEY_4;
|
case XK_KP_2:
|
||||||
case XK_KP_5: return KEY_5;
|
return KEY_2;
|
||||||
case XK_KP_6: return KEY_6;
|
case XK_KP_3:
|
||||||
case XK_KP_7: return KEY_7;
|
return KEY_3;
|
||||||
case XK_KP_8: return KEY_8;
|
case XK_KP_4:
|
||||||
case XK_KP_9: return KEY_9;
|
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_KP_Add:
|
||||||
case XK_plus: return KEY_ADD;
|
return KEY_ADD;
|
||||||
|
case XK_plus:
|
||||||
|
return KEY_ADD;
|
||||||
|
|
||||||
case XK_KP_Subtract: return KEY_SUB;
|
case XK_KP_Subtract:
|
||||||
case XK_minus: return KEY_SUB;
|
return KEY_SUB;
|
||||||
|
case XK_minus:
|
||||||
|
return KEY_SUB;
|
||||||
|
|
||||||
case XK_KP_Multiply: return KEY_MUL;
|
case XK_KP_Multiply:
|
||||||
case XK_asterisk: return KEY_MUL;
|
return KEY_MUL;
|
||||||
|
case XK_asterisk:
|
||||||
|
return KEY_MUL;
|
||||||
|
|
||||||
case XK_KP_Divide: return KEY_DIV;
|
case XK_KP_Divide:
|
||||||
case XK_slash: return KEY_DIV;
|
return KEY_DIV;
|
||||||
|
case XK_slash:
|
||||||
|
return KEY_DIV;
|
||||||
|
|
||||||
case XK_KP_Space: return KEY_SPC;
|
case XK_KP_Space:
|
||||||
case XK_space: return KEY_SPC;
|
return KEY_SPC;
|
||||||
|
case XK_space:
|
||||||
|
return KEY_SPC;
|
||||||
|
|
||||||
/* Upper half of the keyboard */
|
/* Upper half of the keyboard */
|
||||||
case XK_1: return KEY_MTH;
|
case XK_1:
|
||||||
case XK_2: return KEY_PRG;
|
return KEY_MTH;
|
||||||
case XK_3: return KEY_CST;
|
case XK_2:
|
||||||
case XK_4: return KEY_VAR;
|
return KEY_PRG;
|
||||||
case XK_5: return KEY_UP;
|
case XK_3:
|
||||||
case XK_6: return KEY_NXT;
|
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_q:
|
||||||
case XK_w: return KEY_STO;
|
return KEY_AP;
|
||||||
case XK_e: return KEY_EVAL;
|
case XK_w:
|
||||||
case XK_r: return KEY_LEFT;
|
return KEY_STO;
|
||||||
case XK_t: return KEY_DOWN;
|
case XK_e:
|
||||||
case XK_y: return KEY_RIGHT;
|
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_a:
|
||||||
case XK_s: return KEY_COS;
|
return KEY_SIN;
|
||||||
case XK_d: return KEY_TAN;
|
case XK_s:
|
||||||
case XK_f: return KEY_SQRT;
|
return KEY_COS;
|
||||||
case XK_g: return KEY_POWER;
|
case XK_d:
|
||||||
case XK_h: return KEY_INV;
|
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_z:
|
||||||
case XK_x: return KEY_ENTER;
|
return KEY_ENTER;
|
||||||
case XK_c: return KEY_CHS;
|
case XK_x:
|
||||||
case XK_v: return KEY_EEX;
|
return KEY_ENTER;
|
||||||
case XK_b: return KEY_DEL;
|
case XK_c:
|
||||||
case XK_n: return KEY_BKSP;
|
return KEY_CHS;
|
||||||
|
case XK_v:
|
||||||
|
return KEY_EEX;
|
||||||
|
case XK_b:
|
||||||
|
return KEY_DEL;
|
||||||
|
case XK_n:
|
||||||
|
return KEY_BKSP;
|
||||||
|
|
||||||
/* Other useful aliases */
|
/* Other useful aliases */
|
||||||
case XK_Tab: return KEY_NXT;
|
case XK_Tab:
|
||||||
case XK_apostrophe: return KEY_AP;
|
return KEY_NXT;
|
||||||
case XK_period: return KEY_DOT;
|
case XK_apostrophe:
|
||||||
|
return KEY_AP;
|
||||||
|
case XK_period:
|
||||||
|
return KEY_DOT;
|
||||||
|
|
||||||
/* Save */
|
/* Save */
|
||||||
case XK_Control_L:
|
case XK_Control_L:
|
||||||
|
@ -347,10 +370,8 @@ static enum Key Ks2K(KeySym ks)
|
||||||
return KEY_NULL;
|
return KEY_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* X Event handler, called by the X Toolkit when appropriate */
|
/* X Event handler, called by the X Toolkit when appropriate */
|
||||||
static void XEventHandler(Widget w, XtPointer cl_data, XEvent *ev,
|
static void XEventHandler( Widget w, XtPointer cl_data, XEvent* ev, Boolean* cont )
|
||||||
Boolean *cont)
|
|
||||||
{
|
{
|
||||||
KeySym ks;
|
KeySym ks;
|
||||||
|
|
||||||
|
@ -359,48 +380,43 @@ static void XEventHandler(Widget w, XtPointer cl_data, XEvent *ev,
|
||||||
/* Continue to dispatch */
|
/* Continue to dispatch */
|
||||||
*cont = True;
|
*cont = True;
|
||||||
|
|
||||||
if(ev->type == Expose)
|
if ( ev->type == Expose ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_X11, X11_I_LCD_EXPOSE, ev->xexpose.count );
|
debug1( DEBUG_C_X11, X11_I_LCD_EXPOSE, ev->xexpose.count );
|
||||||
if(ev->xexpose.count == 0) RefreshLcd();
|
if ( ev->xexpose.count == 0 )
|
||||||
|
RefreshLcd();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(ev->type == KeyPress || ev->type == KeyRelease)
|
else if ( ev->type == KeyPress || ev->type == KeyRelease ) {
|
||||||
{
|
( void )XLookupString( ( XKeyEvent* )ev, ( char* )NULL, 0, &ks, ( XComposeStatus* )NULL );
|
||||||
(void)XLookupString((XKeyEvent *)ev, (char *)NULL, 0, &ks,
|
|
||||||
(XComposeStatus *)NULL);
|
|
||||||
|
|
||||||
if(ev->type == KeyPress)
|
if ( ev->type == KeyPress ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_X11, X11_I_KEY_PRESS, ks );
|
debug1( DEBUG_C_X11, X11_I_KEY_PRESS, ks );
|
||||||
KeybPress( Ks2K( ks ) );
|
KeybPress( Ks2K( ks ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(ev->type = KeyRelease)
|
else if ( ev->type = KeyRelease ) {
|
||||||
{
|
|
||||||
debug1( DEBUG_C_X11, X11_I_KEY_RELEASE, ks );
|
debug1( DEBUG_C_X11, X11_I_KEY_RELEASE, ks );
|
||||||
KeybRelease( Ks2K( ks ) );
|
KeybRelease( Ks2K( ks ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Unknown X Event - discard */
|
/* Unknown X Event - discard */
|
||||||
debug1( DEBUG_C_X11, X11_I_X_EVENT, ev->type );
|
debug1( DEBUG_C_X11, X11_I_X_EVENT, ev->type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Path/name dynamic allocator */
|
/* 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);
|
strcpy( s, path );
|
||||||
|
strcat( s, "/" );
|
||||||
|
strcat( s, name );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Initialize the X interface */
|
/* Initialize the X interface */
|
||||||
void InitializeX( int argc, char* argv[], struct app_opt* opt )
|
void InitializeX( int argc, char* argv[], struct app_opt* opt )
|
||||||
{
|
{
|
||||||
|
@ -413,31 +429,32 @@ void InitializeX(int argc, char *argv[], struct app_opt *opt)
|
||||||
|
|
||||||
/* Setup Arg vector for shell widget creation */
|
/* Setup Arg vector for shell widget creation */
|
||||||
n = 0;
|
n = 0;
|
||||||
XtSetArg(xt_args[n], XtNwidth, 131*2+2*8); n++;
|
XtSetArg( xt_args[ n ], XtNwidth, 131 * 2 + 2 * 8 );
|
||||||
XtSetArg(xt_args[n], XtNminWidth, 131*2+2*8); n++;
|
n++;
|
||||||
XtSetArg(xt_args[n], XtNmaxWidth, 131*2+2*8); n++;
|
XtSetArg( xt_args[ n ], XtNminWidth, 131 * 2 + 2 * 8 );
|
||||||
XtSetArg(xt_args[n], XtNheight, 64*2+28); n++;
|
n++;
|
||||||
XtSetArg(xt_args[n], XtNminHeight, 64*2+28); n++;
|
XtSetArg( xt_args[ n ], XtNmaxWidth, 131 * 2 + 2 * 8 );
|
||||||
XtSetArg(xt_args[n], XtNmaxHeight, 64*2+28); n++;
|
n++;
|
||||||
XtSetArg(xt_args[n], XtNx, 0); n++;
|
XtSetArg( xt_args[ n ], XtNheight, 64 * 2 + 28 );
|
||||||
XtSetArg(xt_args[n], XtNy, 0); n++;
|
n++;
|
||||||
XtSetArg(xt_args[n], XtNinput, True); 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,
|
/* Initialize application, parse command line options,
|
||||||
create its main shell.
|
create its main shell.
|
||||||
*/
|
*/
|
||||||
shell_widget = XtAppInitialize(
|
shell_widget = XtAppInitialize( &app_context, APP_CLASS, options, NUM_OPTIONS, &argc, argv, fallback_resources, xt_args, n );
|
||||||
&app_context,
|
|
||||||
APP_CLASS,
|
|
||||||
options, NUM_OPTIONS,
|
|
||||||
&argc, argv,
|
|
||||||
fallback_resources,
|
|
||||||
xt_args, n
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Check unknown options - argv[0] always contains program name */
|
/* Check unknown options - argv[0] always contains program name */
|
||||||
if(argc > 1)
|
if ( argc > 1 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for ( i = 1; i < argc; i++ )
|
for ( i = 1; i < argc; i++ )
|
||||||
ChfCondition X11_E_BAD_OPTION, CHF_ERROR, argv[ i ] ChfEnd;
|
ChfCondition X11_E_BAD_OPTION, CHF_ERROR, argv[ i ] ChfEnd;
|
||||||
|
@ -447,29 +464,16 @@ void InitializeX(int argc, char *argv[], struct app_opt *opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get application options and fill the 'struct app_opt opt' structure */
|
/* Get application options and fill the 'struct app_opt opt' structure */
|
||||||
XtGetApplicationResources(
|
XtGetApplicationResources( shell_widget, ( XtPointer )opt, app_res, NUM_APP_RES, ( ArgList )NULL, ( Cardinal )0 );
|
||||||
shell_widget,
|
|
||||||
(XtPointer)opt,
|
|
||||||
app_res,
|
|
||||||
NUM_APP_RES,
|
|
||||||
(ArgList)NULL,
|
|
||||||
(Cardinal)0
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Add private event handler for the main shell */
|
/* Add private event handler for the main shell */
|
||||||
XtAddEventHandler(
|
XtAddEventHandler( shell_widget, KeyPressMask | KeyReleaseMask | ExposureMask, False, /* Don't call with non-maskable events */
|
||||||
shell_widget,
|
XEventHandler, ( XtPointer )NULL );
|
||||||
KeyPressMask|KeyReleaseMask|ExposureMask,
|
|
||||||
False, /* Don't call with non-maskable events */
|
|
||||||
XEventHandler,
|
|
||||||
(XtPointer)NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Realize shell widget */
|
/* Realize shell widget */
|
||||||
XtRealizeWidget( shell_widget );
|
XtRealizeWidget( shell_widget );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -518,7 +522,6 @@ void HandleXEvents(void)
|
||||||
XtAppProcessEvent( app_context, XtIMAll );
|
XtAppProcessEvent( app_context, XtIMAll );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* .+
|
/* .+
|
||||||
|
|
||||||
.title : main
|
.title : main
|
||||||
|
@ -536,15 +539,13 @@ int main(int argc, char *argv[])
|
||||||
struct app_opt opt;
|
struct app_opt opt;
|
||||||
|
|
||||||
/* Chf initialization with msgcat subsystem */
|
/* Chf initialization with msgcat subsystem */
|
||||||
if(ChfMsgcatInit(
|
if ( ChfMsgcatInit( argv[ 0 ], /* Application's name */
|
||||||
argv[0], /* Application's name */
|
|
||||||
CHF_DEFAULT, /* Options */
|
CHF_DEFAULT, /* Options */
|
||||||
MAIN_MSGCAT_NAME, /* Name of the message catalog */
|
MAIN_MSGCAT_NAME, /* Name of the message catalog */
|
||||||
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
CONDITION_STACK_SIZE, /* Size of the condition stack */
|
||||||
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
HANDLER_STACK_SIZE, /* Size of the handler stack */
|
||||||
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
ABNORMAL_EXIT_CODE /* Abnormal exit code */
|
||||||
) != CHF_S_OK)
|
) != CHF_S_OK ) {
|
||||||
{
|
|
||||||
fprintf( stderr, "Chf initialization failed\n" );
|
fprintf( stderr, "Chf initialization failed\n" );
|
||||||
exit( ABNORMAL_EXIT_CODE );
|
exit( ABNORMAL_EXIT_CODE );
|
||||||
}
|
}
|
||||||
|
@ -555,8 +556,7 @@ int main(int argc, char *argv[])
|
||||||
InitializeX( argc, argv, &opt );
|
InitializeX( argc, argv, &opt );
|
||||||
|
|
||||||
/* Initialize LCD window */
|
/* Initialize LCD window */
|
||||||
InitLcd(XtDisplay(shell_widget), XtWindow(shell_widget),
|
InitLcd( XtDisplay( shell_widget ), XtWindow( shell_widget ), opt.fg_pix, opt.bg_pix );
|
||||||
opt.fg_pix, opt.bg_pix);
|
|
||||||
|
|
||||||
/* Fill the emulator options data structure */
|
/* Fill the emulator options data structure */
|
||||||
args.cpu_file_name = GetPathname( opt.path, opt.cpu );
|
args.cpu_file_name = GetPathname( opt.path, opt.cpu );
|
||||||
|
@ -574,20 +574,17 @@ int main(int argc, char *argv[])
|
||||||
CpuInit();
|
CpuInit();
|
||||||
|
|
||||||
/* Reset the system, if required */
|
/* Reset the system, if required */
|
||||||
if(opt.reset)
|
if ( opt.reset ) {
|
||||||
{
|
|
||||||
ModReset();
|
ModReset();
|
||||||
CpuReset();
|
CpuReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(opt.monitor)
|
if ( opt.monitor ) {
|
||||||
{
|
|
||||||
/* Call Monitor */
|
/* Call Monitor */
|
||||||
Monitor();
|
Monitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Call Emulator directly */
|
/* Call Emulator directly */
|
||||||
Emulator();
|
Emulator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,22 +101,18 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macro/Data type definitions
|
Macro/Data type definitions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define X11_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
#define X11_RCS_INFO "$Revision: 4.1 $ $State: Rel $"
|
||||||
|
|
||||||
|
|
||||||
typedef void ( *FsbContinuation )( int proceed, char* file_name );
|
typedef void ( *FsbContinuation )( int proceed, char* file_name );
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Global variables
|
Global variables
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -144,7 +140,6 @@ typedef void (*FsbContinuation)(int proceed, char *file_name);
|
||||||
#define X11_F_X_ERROR 401 /* X Window System fatal error */
|
#define X11_F_X_ERROR 401 /* X Window System fatal error */
|
||||||
#define X11_F_NO_KEYS 402 /* 3.15: Face has no keys */
|
#define X11_F_NO_KEYS 402 /* 3.15: Face has no keys */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
102
src/x_func.c
102
src/x_func.c
|
@ -110,8 +110,6 @@ static char rcs_id[] = "$Id: x_func.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
#define CHF_MODULE_ID X_FUNC_CHF_MODULE_ID
|
#define CHF_MODULE_ID X_FUNC_CHF_MODULE_ID
|
||||||
#include <Chf.h>
|
#include <Chf.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions: CPU access
|
Private functions: CPU access
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -119,24 +117,13 @@ static char rcs_id[] = "$Id: x_func.c,v 4.1 2000/12/11 09:54:19 cibrario Rel $";
|
||||||
/* Return the A field of a DataRegister as an integer. */
|
/* Return the A field of a DataRegister as an integer. */
|
||||||
static int R2int( const Nibble* r )
|
static int R2int( const Nibble* r )
|
||||||
{
|
{
|
||||||
return(
|
return ( ( ( int )r[ 0 ] ) | ( ( int )r[ 1 ] << 4 ) | ( ( int )r[ 2 ] << 8 ) | ( ( int )r[ 3 ] << 12 ) | ( ( int )r[ 4 ] << 16 ) );
|
||||||
((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.
|
/* Return the contents of the byte pointed by addr.
|
||||||
Memory is accessed through ReadNibble()
|
Memory is accessed through ReadNibble()
|
||||||
*/
|
*/
|
||||||
static int ByteFromAddress(Address addr)
|
static int ByteFromAddress( Address addr ) { return ( int )ReadNibble( addr ) + ( int )ReadNibble( addr + 1 ) * 16; }
|
||||||
{
|
|
||||||
return (int)ReadNibble(addr) + (int)ReadNibble(addr+1) * 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Return a dynamically-allocated copy of the contents of the IDNT
|
/* Return a dynamically-allocated copy of the contents of the IDNT
|
||||||
object pointed by D1. D1 points to the *body* of the
|
object pointed by D1. D1 points to the *body* of the
|
||||||
|
@ -151,8 +138,7 @@ static char *NameFromD1(void)
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* Read the name; toascii() is there to avoid 'strange' characters */
|
/* Read the name; toascii() is there to avoid 'strange' characters */
|
||||||
for(c=0; c<len; c++)
|
for ( c = 0; c < len; c++ ) {
|
||||||
{
|
|
||||||
addr += 2;
|
addr += 2;
|
||||||
name[ c ] = ( char )toascii( ByteFromAddress( addr ) );
|
name[ c ] = ( char )toascii( ByteFromAddress( addr ) );
|
||||||
}
|
}
|
||||||
|
@ -161,15 +147,12 @@ static char *NameFromD1(void)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Private functions: action routines
|
Private functions: action routines
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* Set the emulator speed to the given value (in MHz); the desired speed
|
/* Set the emulator speed to the given value (in MHz); the desired speed
|
||||||
value is held in the A field of the C CPU register. No handshake.
|
value is held in the A field of the C CPU register. No handshake.
|
||||||
*/
|
*/
|
||||||
|
@ -208,30 +191,25 @@ static void SetSpeed(Nibble function_code)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* This array holds the binary headers for all known hw configurations;
|
/* This array holds the binary headers for all known hw configurations;
|
||||||
here, '?' is a wildcard character when reading from file
|
here, '?' is a wildcard character when reading from file
|
||||||
(see ReadObjectFromFile()) and is replaced by 'S' when writing
|
(see ReadObjectFromFile()) and is replaced by 'S' when writing
|
||||||
to file (see WriteObjectToFile()).
|
to file (see WriteObjectToFile()).
|
||||||
*/
|
*/
|
||||||
struct BinHdrMapping
|
struct BinHdrMapping {
|
||||||
{
|
|
||||||
char* hw;
|
char* hw;
|
||||||
char* hdr;
|
char* hdr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct BinHdrMapping bin_hdr_mapping[] =
|
static const struct BinHdrMapping bin_hdr_mapping[] = {
|
||||||
{
|
|
||||||
{"hp48", "HPHP48-?"},
|
{"hp48", "HPHP48-?"},
|
||||||
{"hp49", "HPHP49-?"}
|
{"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 the header of binary files for current hw configuration;
|
||||||
return NULL if the header cannot be determined. In the latter case,
|
return NULL if the header cannot be determined. In the latter case,
|
||||||
generate an appropriate condition.
|
generate an appropriate condition.
|
||||||
|
@ -248,21 +226,18 @@ static const char *BinaryHeader(void)
|
||||||
return ( char* )NULL;
|
return ( char* )NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function is the continuation of Kget(); it is invoked when the
|
/* This function is the continuation of Kget(); it is invoked when the
|
||||||
user interaction with the FSB ends.
|
user interaction with the FSB ends.
|
||||||
*/
|
*/
|
||||||
static void KgetContinuation( int proceed, char* file_name )
|
static void KgetContinuation( int proceed, char* file_name )
|
||||||
{
|
{
|
||||||
/* Check whether continuation should proceed */
|
/* Check whether continuation should proceed */
|
||||||
if(!proceed)
|
if ( !proceed ) {
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_ABORTED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_ABORTED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Ok to proceed; read:
|
/* Ok to proceed; read:
|
||||||
- target start address from A[A]
|
- target start address from A[A]
|
||||||
- target end address from C[A]
|
- target end address from C[A]
|
||||||
|
@ -275,10 +250,7 @@ static void KgetContinuation(int proceed, char *file_name)
|
||||||
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
||||||
debug3( DEBUG_C_X_FUNC, X_FUNC_I_KGET, start_addr, end_addr, bin_hdr );
|
debug3( DEBUG_C_X_FUNC, X_FUNC_I_KGET, start_addr, end_addr, bin_hdr );
|
||||||
|
|
||||||
if(bin_hdr == (const char *)NULL
|
if ( bin_hdr == ( const char* )NULL || ReadObjectFromFile( file_name, bin_hdr, ( Address )start_addr, ( Address )end_addr ) ) {
|
||||||
|| ReadObjectFromFile(file_name, bin_hdr, (Address)start_addr,
|
|
||||||
(Address)end_addr))
|
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -287,20 +259,17 @@ static void KgetContinuation(int proceed, char *file_name)
|
||||||
CpuRunRequest();
|
CpuRunRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function is the continuation of Send(); it is invoked when the
|
/* This function is the continuation of Send(); it is invoked when the
|
||||||
user interaction with the FSB ends.
|
user interaction with the FSB ends.
|
||||||
*/
|
*/
|
||||||
static void SendContinuation( int proceed, char* file_name )
|
static void SendContinuation( int proceed, char* file_name )
|
||||||
{
|
{
|
||||||
if(!proceed)
|
if ( !proceed ) {
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_ABORTED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_ABORTED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Ok to proceed; read:
|
/* Ok to proceed; read:
|
||||||
- source start address from A[A]
|
- source start address from A[A]
|
||||||
- source end address from C[A]
|
- source end address from C[A]
|
||||||
|
@ -313,10 +282,7 @@ static void SendContinuation(int proceed, char *file_name)
|
||||||
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
||||||
debug3( DEBUG_C_X_FUNC, X_FUNC_I_SEND, start_addr, end_addr, bin_hdr );
|
debug3( DEBUG_C_X_FUNC, X_FUNC_I_SEND, start_addr, end_addr, bin_hdr );
|
||||||
|
|
||||||
if(bin_hdr == (const char *)NULL
|
if ( bin_hdr == ( const char* )NULL || WriteObjectToFile( ( Address )start_addr, ( Address )end_addr, bin_hdr, file_name ) ) {
|
||||||
|| WriteObjectToFile((Address)start_addr,
|
|
||||||
(Address)end_addr, bin_hdr, file_name))
|
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
@ -325,7 +291,6 @@ static void SendContinuation(int proceed, char *file_name)
|
||||||
CpuRunRequest();
|
CpuRunRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function does the setup of a transfer, performing the following
|
/* This function does the setup of a transfer, performing the following
|
||||||
actions:
|
actions:
|
||||||
|
|
||||||
|
@ -336,18 +301,14 @@ static void SendContinuation(int proceed, char *file_name)
|
||||||
be invoked when the user interaction ends
|
be invoked when the user interaction ends
|
||||||
- Halts the CPU
|
- Halts the CPU
|
||||||
*/
|
*/
|
||||||
static void SetupXfer(
|
static void SetupXfer( int msg, const char* def_msg, FsbContinuation cont )
|
||||||
int msg, const char *def_msg, FsbContinuation cont)
|
|
||||||
{
|
{
|
||||||
debug1( DEBUG_C_TRACE, X_FUNC_I_CALLED, "SetupXfer" );
|
debug1( DEBUG_C_TRACE, X_FUNC_I_CALLED, "SetupXfer" );
|
||||||
|
|
||||||
if(CpuHaltAllowed())
|
if ( CpuHaltAllowed() ) {
|
||||||
{
|
char* fsb_title = XtNewString( ChfGetMessage( CHF_MODULE_ID, msg, def_msg ) );
|
||||||
char *fsb_title =
|
|
||||||
XtNewString(ChfGetMessage(CHF_MODULE_ID, msg, def_msg));
|
|
||||||
|
|
||||||
char *fsb_file =
|
char* fsb_file = NameFromD1();
|
||||||
NameFromD1();
|
|
||||||
|
|
||||||
ActivateFSB( fsb_title, fsb_file, cont );
|
ActivateFSB( fsb_title, fsb_file, cont );
|
||||||
|
|
||||||
|
@ -360,14 +321,12 @@ static void SetupXfer(
|
||||||
( void )CpuHaltRequest();
|
( void )CpuHaltRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_E_NO_HALT, CHF_ERROR ChfEnd;
|
ChfCondition X_FUNC_E_NO_HALT, CHF_ERROR ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is the emulator's extended function for 'kget': this function
|
/* This is the emulator's extended function for 'kget': this function
|
||||||
transfers a file from disk into the calculator's memory.
|
transfers a file from disk into the calculator's memory.
|
||||||
*/
|
*/
|
||||||
|
@ -379,8 +338,7 @@ static void Kget(Nibble function_code)
|
||||||
if ( !args.batchXfer )
|
if ( !args.batchXfer )
|
||||||
SetupXfer( X_FUNC_M_KGET, "Kget", KgetContinuation );
|
SetupXfer( X_FUNC_M_KGET, "Kget", KgetContinuation );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Ok to proceed; read:
|
/* Ok to proceed; read:
|
||||||
- file name from @D1
|
- file name from @D1
|
||||||
- target start address from A[A]
|
- target start address from A[A]
|
||||||
|
@ -395,17 +353,13 @@ static void Kget(Nibble function_code)
|
||||||
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
||||||
debug3( DEBUG_C_X_FUNC, X_FUNC_I_KGET, start_addr, end_addr, bin_hdr );
|
debug3( DEBUG_C_X_FUNC, X_FUNC_I_KGET, start_addr, end_addr, bin_hdr );
|
||||||
|
|
||||||
if(bin_hdr == (const char *)NULL
|
if ( bin_hdr == ( const char* )NULL || ReadObjectFromFile( file_name, bin_hdr, ( Address )start_addr, ( Address )end_addr ) ) {
|
||||||
|| ReadObjectFromFile(file_name, bin_hdr, (Address)start_addr,
|
|
||||||
(Address)end_addr))
|
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is the emulator's extended function for 'send': this function
|
/* This is the emulator's extended function for 'send': this function
|
||||||
transfers an object from the calculator's memory into a disk file.
|
transfers an object from the calculator's memory into a disk file.
|
||||||
*/
|
*/
|
||||||
|
@ -417,8 +371,7 @@ static void Send(Nibble function_code)
|
||||||
if ( !args.batchXfer )
|
if ( !args.batchXfer )
|
||||||
SetupXfer( X_FUNC_M_SEND, "Send", SendContinuation );
|
SetupXfer( X_FUNC_M_SEND, "Send", SendContinuation );
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Ok to proceed; read:
|
/* Ok to proceed; read:
|
||||||
- file name from @D1
|
- file name from @D1
|
||||||
- source start address from A[A]
|
- source start address from A[A]
|
||||||
|
@ -433,20 +386,15 @@ static void Send(Nibble function_code)
|
||||||
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
debug1( DEBUG_C_X_FUNC, X_FUNC_I_FILE_NAME, file_name );
|
||||||
debug3( DEBUG_C_X_FUNC, X_FUNC_I_SEND, start_addr, end_addr, bin_hdr );
|
debug3( DEBUG_C_X_FUNC, X_FUNC_I_SEND, start_addr, end_addr, bin_hdr );
|
||||||
|
|
||||||
if(bin_hdr == (const char *)NULL
|
if ( bin_hdr == ( const char* )NULL || WriteObjectToFile( ( Address )start_addr, ( Address )end_addr, bin_hdr, file_name ) ) {
|
||||||
|| WriteObjectToFile((Address)start_addr,
|
|
||||||
(Address)end_addr, bin_hdr, file_name))
|
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
ChfCondition X_FUNC_W_FAILED, CHF_WARNING ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Dispatch table of emulator's extended functions, indexed by function code;
|
Dispatch table of emulator's extended functions, indexed by function code;
|
||||||
the function code is propagated to functions in the table.
|
the function code is propagated to functions in the table.
|
||||||
|
@ -454,8 +402,7 @@ static void Send(Nibble function_code)
|
||||||
|
|
||||||
typedef void ( *XFunc )( Nibble );
|
typedef void ( *XFunc )( Nibble );
|
||||||
|
|
||||||
static const XFunc function[] =
|
static const XFunc function[] = {
|
||||||
{
|
|
||||||
SetSpeed, /* Function code 0 */
|
SetSpeed, /* Function code 0 */
|
||||||
Kget, /* 1 */
|
Kget, /* 1 */
|
||||||
Send /* 2 */
|
Send /* 2 */
|
||||||
|
@ -463,8 +410,6 @@ static const XFunc function[] =
|
||||||
|
|
||||||
#define N_X_FUNC ( sizeof( function ) / sizeof( function[ 0 ] ) )
|
#define N_X_FUNC ( sizeof( function ) / sizeof( function[ 0 ] ) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Public functions
|
Public functions
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -500,10 +445,7 @@ void ExtendedFunction(Nibble function_code)
|
||||||
debug1( DEBUG_C_X_FUNC, X_FUNC_I_CODE, function_code );
|
debug1( DEBUG_C_X_FUNC, X_FUNC_I_CODE, function_code );
|
||||||
|
|
||||||
/* Some sanity checks, first */
|
/* Some sanity checks, first */
|
||||||
if(function_code < 0
|
if ( function_code < 0 || function_code >= N_X_FUNC || function[ ( int )function_code ] == ( XFunc )NULL ) {
|
||||||
|| function_code >= N_X_FUNC
|
|
||||||
|| function[(int)function_code] == (XFunc)NULL)
|
|
||||||
{
|
|
||||||
ChfCondition X_FUNC_W_BAD_CODE, CHF_WARNING, function_code ChfEnd;
|
ChfCondition X_FUNC_W_BAD_CODE, CHF_WARNING, function_code ChfEnd;
|
||||||
ChfSignal();
|
ChfSignal();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,6 @@
|
||||||
|
|
||||||
.- */
|
.- */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Macro/Data type definitions - require cpu.h
|
Macro/Data type definitions - require cpu.h
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -79,7 +78,6 @@
|
||||||
#define X_FUNC_KGET ( Nibble )1
|
#define X_FUNC_KGET ( Nibble )1
|
||||||
#define X_FUNC_SEND ( Nibble )2
|
#define X_FUNC_SEND ( Nibble )2
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Chf condition codes
|
Chf condition codes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
@ -101,7 +99,6 @@
|
||||||
#define X_FUNC_M_KGET 501 /* FSB title for Kget function */
|
#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_M_SEND 502 /* FSB title for Send function */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Function prototypes
|
Function prototypes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue