OpenCores
URL https://opencores.org/ocsvn/light52/light52/trunk

Subversion Repositories light52

[/] [light52/] [trunk/] [tools/] [b51/] [src/] [b51_log.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ja_rd
 
2
 
3
#include <stdint.h>
4
#include <stdbool.h>
5
#include <stdio.h>
6
 
7
#include "b51_cpu.h"
8
#include "b51_log.h"
9
 
10
 
11
static FILE *log_con_fp = NULL;
12
static FILE *log_sw_fp = NULL;
13
 
14
extern bool log_init(const char *sw_log_file, const char *con_log_file){
15
    if(sw_log_file != NULL){
16
        log_sw_fp = fopen(sw_log_file, "w");
17
        if(log_sw_fp==NULL){
18
            perror("Error opening log file");
19
            return false;
20
        }
21
    }
22
    else{
23
        /* NULL argument: do not log */
24
        log_sw_fp = NULL; /* stdout; */
25
    }
26
 
27
    if(con_log_file != NULL){
28
        log_con_fp = fopen(con_log_file, "w");
29
        if(log_con_fp==NULL){
30
            perror("Error opening console log file");
31
            return false;
32
        }
33
    }
34
    else{
35
        /* NULL argument: Redirect to host console */
36
        log_con_fp = stdout;
37
    }
38
 
39
    return true;
40
}
41
 
42
extern void log_close(void){
43
    if(log_sw_fp!=NULL){
44
        fclose(log_sw_fp);
45
        log_sw_fp = NULL;
46
    }
47
    if(log_con_fp!=NULL){
48
        fclose(log_con_fp);
49
        log_con_fp = NULL;
50
    }
51
}
52
 
53
 
54
extern void log_baseline(log51_t *log, uint16_t pc, uint8_t sp, uint8_t a, uint8_t psw){
55
    log->pc = pc;
56
    log->psw = psw;
57
    log->sp = sp;
58
    log->a = a;
59
}
60
 
61
extern void log_idata(log51_t *log, uint8_t addr, uint8_t value){
62
    if(log_sw_fp!=NULL){
63
        fprintf(log_sw_fp, "(%04X) [%02X] = %02X\n", log->pc, addr, value);
64
    }
65
}
66
 
67
extern void log_xdata(log51_t *log, uint16_t addr, uint8_t value){
68
    if(log_sw_fp!=NULL){
69
        fprintf(log_sw_fp, "(%04X) <%04X> = %02X\n", log->pc, addr, value);
70
    }
71
}
72
 
73
extern void log_sfr(log51_t *log, uint8_t addr, uint8_t value){
74
    if(log_sw_fp!=NULL){
75
        fprintf(log_sw_fp, "(%04X) SFR[%02X] = %02X\n", log->pc, addr, value);
76
    }
77
}
78
 
79
extern bool log_jump(log51_t *log, uint16_t addr){
80
    if(log_sw_fp!=NULL){
81
        fprintf(log_sw_fp, "(%04X) PC = %04X\n", log->pc, addr);
82
    }
83
    return (log->pc == addr);
84
}
85
 
86
extern void log_unimplemented(log51_t *log, uint8_t opcode){
87
    if(log_sw_fp!=NULL){
88
        fprintf(log_sw_fp, "(%04X) UNIMPLEMENTED: %02X\n", log->pc, opcode);
89
    }
90
    printf("\n(%04X) UNIMPLEMENTED: %02X\n", log->pc, opcode);
91
}
92
 
93
extern void log_reg16(log51_t *log, const char *msg, uint16_t value){
94
    if(log_sw_fp!=NULL){
95
        fprintf(log_sw_fp, "(%04X) %s = %04X\n", log->pc, msg, value);
96
    }
97
}
98
 
99
extern void log_status(log51_t *log, uint8_t sp, uint8_t a, uint8_t psw){
100
    /* Order of checks & log messages matches light52_tb_pkg */
101
    if(log_sw_fp!=NULL){
102
        if(sp != log->sp){
103
            fprintf(log_sw_fp, "(%04X) SP = %02X\n", log->pc, sp);
104
        }
105
        if(a != log->a){
106
            fprintf(log_sw_fp, "(%04X) A = %02X\n", log->pc, a);
107
        }
108
        if((psw) != (log->psw)){
109
            fprintf(log_sw_fp, "(%04X) PSW = %02X\n",
110
                    log->pc, psw);
111
        }
112
    }
113
}
114
 
115
 
116
extern void log_con_output(char c){
117
    if(log_con_fp!=NULL){
118
        fprintf(log_con_fp, "%c", c);
119
    }
120
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.