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

Subversion Repositories diogenes

[/] [diogenes/] [trunk/] [video/] [tga2dump.c] - Blame information for rev 168

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

Line No. Rev Author Line
1 168 fellnhofer
/***************************************************************************
2
 *   Copyright (C) 2008 by David Rigler   *
3
 *                                                                         *
4
 *   This program is free software; you can redistribute it and/or modify  *
5
 *   it under the terms of the GNU General Public License as published by  *
6
 *   the Free Software Foundation; either version 2 of the License, or     *
7
 *   (at your option) any later version.                                   *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#include <stdio.h>
21
 
22
 
23
 
24
 
25
unsigned char header[0x2A] = {
26
  0x00,0x01,0x01,0x00,0x00,0x08,0x00,0x18,
27
  0x00,0x00,0x00,0x00,0x80,0x02,0xE0,0x01,
28
  0x08,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
29
  0x00,0xFF,0x00,0x00,0xFF,0xFF,0xC2,0x79,
30
  0x02,0xC2,0x5D,0xFC,0xFF,0xE8,0xA3,0xFF,
31
  0xFF,0xFF};
32
 
33
 
34
  FILE *vram_dump = 0;
35
  FILE *tgain = 0;
36
 
37
  typedef struct
38
  {
39
      unsigned int pix[4][8];
40
  } my_tile;
41
 
42
#define NR_TILES 96
43
#define VRAM_SIZE 8192
44
 
45
  int used_tiles = 0;
46
  my_tile tiles[96];
47
 
48
 
49
 
50
  unsigned char encoded(int tilenum)
51
  {
52
        int x = (tilenum%12) + 4;
53
        int y = tilenum/12;
54
    return (y << 4) | x;
55
  }
56
 
57
 
58
 
59
  unsigned char outoftiles = 0;
60
  unsigned char VRAM[VRAM_SIZE] = {0};
61
  unsigned char bitmap[640][480] = {0};
62
 
63
  unsigned char tileindex(int x_in, int y_in) {
64
    int x,y,i;
65
    my_tile t;
66
    int tilenum;
67
 
68
    for(y = 0; y < 8; y++){
69
      for(x = 0; x < 4; x++){
70
        t.pix[x][y] = (bitmap[x_in*8+2*x][y_in*8 + y] << 4) | bitmap[x_in*8+2*x+1][y_in*8 + y];
71
      }
72
    }
73
 
74
    int pissoff = 0;
75
    for(i = 0; i < used_tiles; i++) {
76
      pissoff = 0;
77
      for( x = 0; !pissoff && x < 4; x++)
78
        for( y = 0; !pissoff && y < 8; y++)
79
          if(tiles[i].pix[x][y] != t.pix[x][y])
80
            pissoff = 1;
81
 
82
      if(!pissoff){
83
        tilenum = i;
84
        break;
85
      }
86
    }
87
 
88
    if( i == used_tiles) {
89
                if(used_tiles >= NR_TILES) {
90
                        tilenum = 0;
91
                        outoftiles = 1;
92
                } else {
93
                  tilenum = used_tiles++;
94
                  for( x = 0;  x < 4; x++)
95
                        for( y = 0;  y < 8; y++)
96
                          tiles[tilenum].pix[x][y] = t.pix[x][y];
97
                }
98
        }
99
 
100
    return encoded(tilenum);
101
  }
102
 
103
 
104
 
105
 
106
  int main(int argc, char **argv) {
107
    int i; int x; int y;
108
 
109
    if(argc != 3)
110
      printf("usage: tga2dump [inputfile] [outputfile]\n");
111
 
112
 
113
    tgain = fopen(argv[1], "r");
114
 
115
    if(!tgain) {
116
      printf("input file");
117
      return 1;
118
    }
119
 
120
    vram_dump = fopen(argv[2], "w+");
121
 
122
    if(!vram_dump){
123
      printf("output file");
124
      return 1;
125
    }
126
 
127
  FILE *tgaout = fopen("debug.tga", "w+");
128
 
129
  if(!tgaout){
130
    printf("debug file");
131
    exit(1);
132
  }
133
 
134
    for(i = 1; i < NR_TILES; i++)
135
      for(y = 0; y < 8; y++)
136
                 for(x = 0; x < 4; x++)
137
                        tiles[i].pix[x][y] = 0x77;
138
 
139
  for(i = 0; i < 0x2A; i++) {
140
    fputc(header[i],tgaout);
141
  }
142
 
143
 
144
 
145
    fseek(tgain, 0x2A, SEEK_SET);
146
 
147
    for(y = 479; y >= 0; y--)
148
      for(x = 0; x < 640; x++)
149
        bitmap[x][y] = fgetc(tgain);
150
 
151
 
152
    for(y = 0; y < 60; y++)
153
      for(x = 0; x < 80; x++)
154
 
155
        VRAM[y*128 + x] = tileindex(x,y);
156
 
157
 
158
 
159
    for(i = 0; i < NR_TILES; i++)
160
      for(y = 0; y < 8; y++)
161
        for(x = 0; x < 4; x++)
162
          VRAM[128*( 8*(i/12) +y) + 80 + (i%12)*4 + x ] = tiles[i].pix[x][y];
163
 
164
    for(i = 0; i<VRAM_SIZE; i++)
165
      fputc(VRAM[i], vram_dump);
166
 
167
 
168
    // debug TILES
169
    for(i = 0; i < NR_TILES; i++)
170
      for(y = 0; y < 8; y++)
171
                 for(x = 0; x < 4; x++){
172
          bitmap[(i%12) * 9+2*x+1][200 + y + (i/12)*9] = tiles[i].pix[x][y] &0xf ;
173
                  bitmap[(i%12) * 9 + 2*x][200 + y + (i/12)*9] = tiles[i].pix[x][y]>>4;
174
                 }
175
 
176
     for(i = 0; i < NR_TILES; i++)
177
      for(y = 0; y < 8; y++)
178
                 for(x = 0; x < 4; x++){
179
          bitmap[(i%12) * 8+2*x +1+ 13*9][200 + y + (i/12)*8] = tiles[i].pix[x][y] &0xf ;
180
                  bitmap[(i%12) * 8 + 2*x + 13*9][200 + y + (i/12)*8] = tiles[i].pix[x][y]>>4;
181
                 }
182
 
183
   for(y = 479; y >= 0; y --)
184
    for(x = 0; x < 640; x++)
185
      fputc(bitmap[x][y], tgaout);
186
 
187
 
188
 
189
    fclose(vram_dump);
190
    fclose(tgain);
191
    fclose(tgaout);
192
 
193
        if(outoftiles)
194
          printf("to few tiles\n");
195
 
196
    return 0;
197
  }

powered by: WebSVN 2.1.0

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