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

Subversion Repositories yacc

[/] [yacc/] [trunk/] [bench/] [c_src/] [pi/] [pi2.BAK] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tak.sugawa
/*Calculate the value of PI.  Takes a long time!*/
2
void putchar(char);
3
 
4
#define print_port 0x3ff0
5
#define print_char_port 0x3ff1
6
#define print_int_port 0x3ff2
7
#define print_long_port 0x3ff4
8
 
9
 
10
 
11
 
12
 
13
#define uart_port               0x03ffc //for 16KRAM
14
#define uart_wport uart_port
15
#define uart_rport uart_port
16
#define int_set_address 0x03ff8 //for 16KRAM
17
 
18
void print_uart(unsigned char* ptr)//
19
{
20
        unsigned int uport;
21
        #define WRITE_BUSY 0x0100
22
 
23
 
24
        while (*ptr) {
25
 
26
                do {
27
                  uport=*(volatile unsigned*)   uart_port;
28
                } while (uport & WRITE_BUSY);
29
                *(volatile unsigned char*)uart_wport=*(ptr++);
30
        }
31
}
32
 
33
 
34
void putc_uart(unsigned char c)//
35
{
36
        unsigned int uport;
37
 
38
 
39
        do {
40
                  uport=*(volatile unsigned*)   uart_port;
41
        } while (uport & WRITE_BUSY);
42
        *(volatile unsigned char*)uart_wport=c;
43
 
44
}
45
 
46
 
47
void print(unsigned char* ptr)//Verilog Test Bench Use
48
{
49
 
50
        while (*ptr) {
51
 
52
                *(volatile unsigned char*)print_port=*(ptr++);
53
        }
54
 
55
        *(volatile unsigned char*)print_port=0x00;//Write Done
56
 
57
}
58
void print_char(unsigned char val)//Little Endian write out 16bit number
59
{
60
        *(volatile unsigned char*)print_port=(unsigned char)val ;
61
 
62
}
63
 
64
void print_num(unsigned long num)
65
{
66
   unsigned long digit,offset;
67
   for(offset=1000;offset;offset/=10) {
68
      digit=num/offset;
69
      #ifdef RTL_SIM
70
      print_char(digit+'0');
71
      #else
72
        putc_uart(digit+'0');
73
      #endif
74
      num-=digit*offset;
75
   }
76
}
77
 
78
long a=10000,b,c=56,d,e,f[57],g;
79
//long a=10000,b,c=2800,d,e,f[2801],g;
80
void main()
81
{
82
 
83
 
84
#endif
85
for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
86
 
87
 
88
 
89
   print_char('\n');
90
   print("");
91
}
92
 

powered by: WebSVN 2.1.0

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