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

Subversion Repositories z3

[/] [z3/] [trunk/] [utils/] [screen.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 charcole
#include "SDL.h"
2
#include <stdio.h>
3
 
4
unsigned short myPixels[320*240];
5
 
6
int hex2num(char c)
7
{
8
        if (c>='0' && c<='9')
9
                return c-'0';
10
        if (c>='a' && c<='f')
11
                return c-'a'+10;
12
        if (c>='A' && c<='F')
13
                return c-'A'+10;
14
        printf("Bad hex:%c\n", c);
15
        return 0;
16
}
17
 
18
int main(int argc, char* argv[])
19
{
20
        FILE *f;
21
    SDL_Window *window;
22
        SDL_Renderer *ren;
23
        SDL_Texture *tex;
24
        unsigned short curReg=0;
25
        unsigned short curData=0;
26
        int curRecv=0;
27
        int curX=0;
28
        int curY=0;
29
        int curIdx=0;
30
        if (argc!=2)
31
        {
32
                printf("Usage: screen.out simulation.log\n");
33
        return 1;
34
        }
35
        f=fopen(argv[1],"r");
36
        if (!f)
37
        {
38
                printf("Couldn't open %s\n", argv[1]);
39
        return 1;
40
        }
41
        while (1)
42
        {
43
                char line[1024];
44
                char *start;
45
                if (!fgets(line, sizeof(line)-1, f))
46
                {
47
                        break;
48
                }
49
                start=strchr(line, 'P');
50
                if (start && start[1]=='E' && start[2]==':')
51
                {
52
                        int lcdWR=start[3]-'0';
53
                        int lcdCS=start[4]-'0';
54
                        int lcdReset=start[6]-'0';
55
                        if (lcdCS==0 && lcdReset==1 && lcdWR==0)
56
                        {
57
                                int lcdRS=start[5]-'0';
58
                                char *data=strchr(start, 'D');
59
                                unsigned char d;
60
                                if (data && data[1]==':')
61
                                {
62
                                        d=(hex2num(data[2])<<4)|hex2num(data[3]);
63
                                }
64
                                if (lcdRS==0)
65
                                {
66
                                        if (curRecv>=2)
67
                                                curRecv=0;
68
                                        curRecv++;
69
                                        curReg<<=8;
70
                                        curReg|=d;
71
                                }
72
                                else
73
                                {
74
                                        curRecv++;
75
                                        curData<<=8;
76
                                        curData|=d;
77
                                        if (curRecv>=4 && !(curRecv&1))
78
                                        {
79
                                                if (curReg==0x22)
80
                                                {
81
                                                        myPixels[curIdx%(320*240)]=curData;
82
                                                        curIdx++;
83
                                                }
84
                                                else if (curReg==0x20)
85
                                                {
86
                                                        curX=curData;
87
                                                        curIdx=curY*240+curX;
88
                                                }
89
                                                else if (curReg==0x21)
90
                                                {
91
                                                        curY=curData;
92
                                                        curIdx=curY*240+curX;
93
                                                }
94
                                        }
95
                                }
96
                        }
97
                }
98
        }
99
    SDL_Init(SDL_INIT_VIDEO);
100
    window = SDL_CreateWindow("TFTLCD",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,240,320,SDL_WINDOW_SHOWN);
101
    if (window == NULL)
102
        {
103
        printf("Could not create window: %s\n", SDL_GetError());
104
        return 1;
105
    }
106
        ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
107
        if (ren == NULL)
108
        {
109
        printf("Could not create renderer: %s\n", SDL_GetError());
110
                return 1;
111
        }
112
        tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, 240, 320);
113
        if (tex == NULL)
114
        {
115
        printf("Could not create texture: %s\n", SDL_GetError());
116
                return 1;
117
        }
118
        SDL_UpdateTexture(tex, NULL, myPixels, 240*sizeof(myPixels[0]));
119
        SDL_RenderClear(ren);
120
        SDL_RenderCopy(ren, tex, NULL, NULL);
121
        SDL_RenderPresent(ren);
122
    SDL_Delay(10000);
123
        SDL_DestroyTexture(tex);
124
        SDL_DestroyRenderer(ren);
125
        SDL_DestroyWindow(window);
126
    SDL_Quit();
127
    return 0;
128
}

powered by: WebSVN 2.1.0

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