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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [output.c] - Blame information for rev 157

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 hellwig
/*
2
 * output.c -- output to file on host system
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
#include "common.h"
11
#include "console.h"
12
#include "error.h"
13
#include "output.h"
14
 
15
 
16
static FILE *outputFile;
17
 
18
 
19
Word outputRead(Word addr) {
20
  if (outputFile == NULL) {
21
    /* output device not installed */
22
    error("output device not installed");
23
  }
24
  /* output device always returns 0 on read */
25
  return 0;
26
}
27
 
28
 
29
void outputWrite(Word addr, Word data) {
30
  char c;
31
 
32
  if (outputFile == NULL) {
33
    /* output device not installed */
34
    error("output device not installed");
35
  }
36
  c = data;
37
  if (fwrite(&c, 1, 1, outputFile) != 1) {
38
    error("write error on output device");
39
  }
40
}
41
 
42
 
43
void outputReset(void) {
44
  if (outputFile == NULL) {
45
    /* output device not installed */
46
    return;
47
  }
48 25 hellwig
  cPrintf("Resetting Output Device...\n");
49 8 hellwig
  fseek(outputFile, 0, SEEK_SET);
50
}
51
 
52
 
53
void outputInit(char *outputFileName) {
54
  if (outputFileName == NULL) {
55
    /* do not install output device */
56
    outputFile = NULL;
57
  } else {
58
    /* try to install output device */
59
    outputFile = fopen(outputFileName, "wb");
60
    if (outputFile == NULL) {
61
      error("cannot open output device file '%s'", outputFileName);
62
    }
63
    setvbuf(outputFile, NULL, _IONBF, 0);
64
  }
65
  outputReset();
66
}
67
 
68
 
69
void outputExit(void) {
70
  if (outputFile == NULL) {
71
    /* output device not installed */
72
    return;
73
  }
74
  fclose(outputFile);
75
}

powered by: WebSVN 2.1.0

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