|
|
1.1 root 1: /*
2: * Hatari - trace.c
3: *
4: * This file is distributed under the GNU Public License, version 2 or at
5: * your option any later version. Read the file gpl.txt for details.
6: *
7: * This files allows to dynamically output trace messages, based on the content
8: * of HatariTraceLevel. Multiple trace levels can be set at once, by setting
9: * the corresponding bits in HatariTraceLevel/
10: *
11: */
12:
13:
14: /* 2007/09/28 [NP] Creation of trace.c */
15:
16:
17:
18: #include <string.h>
19: #include <stdio.h>
20:
21: #include "trace.h"
22:
23:
24: struct { Uint32 Level;
25: const char *Name;
26: }
27: TraceOptions[] = {
28: { HATARI_TRACE_VIDEO_SYNC , "video_sync" } ,
29: { HATARI_TRACE_VIDEO_RES , "video_res" } ,
30: { HATARI_TRACE_VIDEO_COLOR , "video_color" } ,
31: { HATARI_TRACE_VIDEO_BORDER_V , "video_border_v" } ,
32: { HATARI_TRACE_VIDEO_BORDER_H , "video_border_h" } ,
33: { HATARI_TRACE_VIDEO_ADDR , "video_addr" } ,
34: { HATARI_TRACE_VIDEO_HBL , "video_hbl" } ,
35: { HATARI_TRACE_VIDEO_VBL , "video_vbl" } ,
36: { HATARI_TRACE_VIDEO_STE , "video_ste" } ,
37: { HATARI_TRACE_VIDEO_ALL , "video_all" } ,
38:
39: { HATARI_TRACE_MFP_EXCEPTION , "mfp_exception" } ,
40: { HATARI_TRACE_MFP_START , "mfp_start" } ,
41: { HATARI_TRACE_MFP_READ , "mfp_read" } ,
42: { HATARI_TRACE_MFP_WRITE , "mfp_write" } ,
43: { HATARI_TRACE_MFP_ALL , "mfp_all" } ,
44:
45: { HATARI_TRACE_PSG_WRITE_REG , "psg_write_reg" } ,
46: { HATARI_TRACE_PSG_WRITE_DATA , "psg_write_data" } ,
47: { HATARI_TRACE_PSG_ALL , "psg_all" } ,
48:
49: { HATARI_TRACE_CPU_PAIRING , "cpu_pairing" } ,
50: { HATARI_TRACE_CPU_DISASM , "cpu_disasm" } ,
51: { HATARI_TRACE_CPU_EXCEPTION , "cpu_exception" } ,
52: { HATARI_TRACE_CPU_ALL , "cpu_all" } ,
53:
54: { HATARI_TRACE_INT , "int" } ,
55:
56: { HATARI_TRACE_FDC , "fdc" } ,
57:
58: { HATARI_TRACE_IKBD , "ikbd" } ,
59:
60:
61: { HATARI_TRACE_ALL , "all" }
62: };
63:
64:
65: Uint32 HatariTraceLevel = HATARI_TRACE_NONE;
66:
67:
68:
69: /* Parse a list of comma separated strings. */
70: /* If the string is prefixed with an optional '+', */
71: /* corresponding trace level is turned on. */
72: /* If the string is prefixed with a '-', corresponding */
73: /* trace level is turned off. */
74: /* Result is stored in HatariTraceLevel. */
75:
76: int ParseTraceOptions ( char *OptionsStr )
77: {
78: char *OptionsCopy;
79: char *cur, *sep;
80: int i;
81: int Mode; /* 0=add, 1=del */
82: int MaxOptions;
83:
84:
85: MaxOptions = sizeof ( TraceOptions ) / sizeof ( TraceOptions[ 0 ] );
86:
87: /* special case for "help" : display the list of possible trace levels */
88: if ( strcmp ( OptionsStr , "help" ) == 0 )
89: {
90: fprintf ( stderr , "\nList of available trace levels :\n" );
91:
92: for ( i = 0 ; i < MaxOptions ; i++ )
93: fprintf ( stderr , " %s\n" , TraceOptions[ i ].Name );
94:
95: fprintf ( stderr , "Multiple trace levels can be separated by ','\n" );
96: fprintf ( stderr , "Levels can be prefixed by '+' or '-' to be mixed.\n\n" );
97: return 0;
98: }
99:
100: HatariTraceLevel = HATARI_TRACE_NONE;
101:
102: OptionsCopy = strdup ( OptionsStr );
103: if ( !OptionsCopy )
104: {
105: fprintf ( stderr , "strdup error in ParseTraceOptions\n" );
106: return 0;
107: }
108:
109: cur = OptionsCopy;
110: while ( cur )
111: {
112: sep = strchr ( cur , ',' );
113: if ( sep ) /* end of next options */
114: *sep++ = '\0';
115:
116: Mode = 0; /* default is 'add' */
117: if ( *cur == '+' )
118: { Mode = 0; cur++; }
119: else if ( *cur == '-' )
120: { Mode = 1; cur++; }
121:
122: for ( i = 0 ; i < MaxOptions ; i++ )
123: {
124: if ( strcmp ( cur , TraceOptions[ i ].Name ) == 0 )
125: break;
126: }
127:
128: if ( i < MaxOptions ) /* option found */
129: {
130: if ( Mode == 0 ) HatariTraceLevel |= TraceOptions[ i ].Level;
131: else HatariTraceLevel &= (~TraceOptions[ i ].Level);
132: }
133:
134: else
135: {
136: fprintf ( stderr , "unknown trace option %s\n" , cur );
137: free ( OptionsCopy );
138: return 0;
139: }
140:
141: cur = sep;
142: }
143:
144: //fprintf ( stderr , "trace parse <%x>\n" , HatariTraceLevel );
145:
146: free ( OptionsCopy );
147: return 1;
148: }
149:
150:
151:
152:
153:
154:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.