Subversion Repositories shark

Rev

Rev 709 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
692 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Mauro Marinoni      <mauro.marinoni@unipv.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 */
34
 
35
#include "kernel/kern.h"
36
#include "string.h"
37
#include "drivers/shark_fb26.h"
38
#include "snapshot.h"
39
 
40
struct SNAP_SLOT{
41
        char used;
693 giacomo 42
        int  wx;
43
        int  wy;
44
        int  bytesperpixel;
45
        void *buff;
46
} sslot[16] = {{0, 0, 0, 0, NULL},
47
               {0, 0, 0, 0, NULL},
48
               {0, 0, 0, 0, NULL},
49
               {0, 0, 0, 0, NULL},
50
               {0, 0, 0, 0, NULL},
51
               {0, 0, 0, 0, NULL},
52
               {0, 0, 0, 0, NULL},
53
               {0, 0, 0, 0, NULL},
54
               {0, 0, 0, 0, NULL},
55
               {0, 0, 0, 0, NULL},
56
               {0, 0, 0, 0, NULL},
57
               {0, 0, 0, 0, NULL},
58
               {0, 0, 0, 0, NULL},
59
               {0, 0, 0, 0, NULL},
60
               {0, 0, 0, 0, NULL},
61
               {0, 0, 0, 0, NULL}};
692 mauro 62
 
693 giacomo 63
void *snapshot_getslot(int nbuff, int wx, int wy, int bytesperpixel)
692 mauro 64
{
693 giacomo 65
        void* tmp;
692 mauro 66
 
694 giacomo 67
        if ((wx<=0) || (wy<=0) || (nbuff<0) || (nbuff>15)){
692 mauro 68
                return NULL;
69
        }
70
 
693 giacomo 71
        if (sslot[nbuff].used)
692 mauro 72
                return NULL;
73
 
693 giacomo 74
        /* Allocate memory. */
75
        tmp = (void *)kern_alloc(wx * wy * bytesperpixel);
76
        if (!tmp) return NULL;
692 mauro 77
 
78
        sslot[nbuff].used = 1;
693 giacomo 79
        sslot[nbuff].wx = wx;
80
        sslot[nbuff].wy = wy;
81
        sslot[nbuff].bytesperpixel = bytesperpixel;
692 mauro 82
        sslot[nbuff].buff = tmp;
83
        return tmp;
84
}
85
 
86
void snapshot_freeslot(int nbuff)
87
{
693 giacomo 88
        if (sslot[nbuff].used == 0) return;
89
        kern_free(sslot[nbuff].buff, sslot[nbuff].wx * sslot[nbuff].wy * sslot[nbuff].bytesperpixel);
90
        sslot[nbuff].used = 0;
692 mauro 91
}
92
 
93
void snapshot_grab(int nbuff)
94
{
694 giacomo 95
        extern void *video_memory;
692 mauro 96
 
694 giacomo 97
        memcpy(sslot[nbuff].buff,video_memory,sslot[nbuff].wx * sslot[nbuff].wy * sslot[nbuff].bytesperpixel);
693 giacomo 98
 
692 mauro 99
}
100
 
101
int snapshot_save_pgm(int nbuff, char *fname)
102
{
103
        char out_st[40];
693 giacomo 104
        register int i;
709 giacomo 105
        unsigned char tmp[3];
692 mauro 106
        DOS_FILE *outf;
107
 
108
        if ((outf = DOS_fopen(fname, "w")) == NULL) {
109
                return -1;
110
        } else {
693 giacomo 111
                sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255);
692 mauro 112
                DOS_fwrite(out_st, strlen(out_st), 1, outf);
113
                cprintf(out_st);
114
 
693 giacomo 115
                for (i = 0; i < sslot[nbuff].wy * sslot[nbuff].wx; i++) {
709 giacomo 116
                        tmp[0] = *(unsigned char *)(sslot[nbuff].buff + i);
117
                        tmp[1] = ' ';
118
                        tmp[2] = 0;
693 giacomo 119
                        DOS_fwrite(&tmp, 1, 1, outf);
692 mauro 120
                }
121
                DOS_fclose(outf);
122
        }
123
        return 0;
124
}
125
 
126
int snapshot_save_ppm(int nbuff, char *fname)
127
{
128
        char out_st[40];
693 giacomo 129
        register int i;
692 mauro 130
        int col_r, col_g, col_b;
131
        DOS_FILE *outf;
132
 
133
        if ((outf = DOS_fopen(fname, "w")) == NULL) {
134
                return -1;
135
        } else {
693 giacomo 136
                sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255);
692 mauro 137
                DOS_fwrite(out_st, strlen(out_st), 1, outf);
138
                cprintf(out_st);
139
 
693 giacomo 140
                for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++) {
694 giacomo 141
                        col_r = ((*(int *)(sslot[nbuff].buff + i*2) & 0xF800) >> 11) << 3;
142
                        col_g = ((*(int *)(sslot[nbuff].buff + i*2) & 0x07E0) >>  5) << 2;
143
                        col_b =  (*(int *)(sslot[nbuff].buff + i*2) & 0x001F) << 3;
693 giacomo 144
                        sprintf(out_st, "%d %d %d  ", col_r, col_g, col_b);
145
                        DOS_fwrite(out_st, strlen(out_st), 1, outf);
692 mauro 146
                }
147
                DOS_fclose(outf);
148
        }
149
        return 0;
150
}