Files
@ a22b6e149063
Branch filter:
Location: libtransport.git/backends/frotz/dfrotz/dumb/dumb_pic.c
a22b6e149063
4.1 KiB
text/plain
Finished frotz backend :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | /* dumb-pic.c
* $Id: dumb-pic.c,v 1.1.1.1 2002/03/26 22:38:34 feedle Exp $
*
* Copyright 1997,1998 Alcibiades Petrofsky
* <alcibiades@petrofsky.berkeley.ca.us>.
* Any use permitted provided this notice stays intact.
*/
#include "dumb_frotz.h"
f_setup_t f_setup;
#define PIC_FILE_HEADER_FLAGS 1
#define PIC_FILE_HEADER_NUM_IMAGES 4
#define PIC_FILE_HEADER_ENTRY_SIZE 8
#define PIC_FILE_HEADER_VERSION 14
#define PIC_HEADER_NUMBER 0
#define PIC_HEADER_WIDTH 2
#define PIC_HEADER_HEIGHT 4
static struct {
int z_num;
int width;
int height;
int orig_width;
int orig_height;
} *pict_info;
static int num_pictures = 0;
static unsigned char lookupb(unsigned char *p, int n) {return p[n];}
static unsigned short lookupw(unsigned char *p, int n)
{
return (p[n + 1] << 8) | p[n];
}
void dumb_init_pictures (char *filename)
{
FILE *file = NULL;
int success = FALSE;
unsigned char gheader[16];
unsigned char *raw_info = NULL;
int i, entry_size, flags;
float x_scaler, y_scaler;
do {
if ((h_version != V6)
|| !filename
|| ((file = fopen (filename, "rb")) == NULL)
|| (fread(&gheader, sizeof (gheader), 1, file) != 1))
break;
num_pictures = lookupw(gheader, PIC_FILE_HEADER_NUM_IMAGES);
entry_size = lookupb(gheader, PIC_FILE_HEADER_ENTRY_SIZE);
flags = lookupb(gheader, PIC_FILE_HEADER_FLAGS);
raw_info = malloc(num_pictures * entry_size);
if (fread(raw_info, num_pictures * entry_size, 1, file) != 1)
break;
pict_info = malloc((num_pictures + 1) * sizeof(*pict_info));
pict_info[0].z_num = 0;
pict_info[0].height = num_pictures;
pict_info[0].width = lookupw(gheader, PIC_FILE_HEADER_VERSION);
y_scaler = h_screen_rows / 200.0;
x_scaler = h_screen_cols / ((flags & 0x08) ? 640.0 : 320.0);
/* Copy and scale. */
for (i = 1; i <= num_pictures; i++) {
unsigned char *p = raw_info + entry_size * (i - 1);
pict_info[i].z_num = lookupw(p, PIC_HEADER_NUMBER);
pict_info[i].orig_height = lookupw(p, PIC_HEADER_HEIGHT);
pict_info[i].orig_width = lookupw(p, PIC_HEADER_WIDTH);
pict_info[i].height = pict_info[i].orig_height * y_scaler + .5;
pict_info[i].width = pict_info[i].orig_width * x_scaler + .5;
}
success = TRUE;
} while (0);
if (file)
fclose(file);
if (raw_info)
free(raw_info);
if (success)
h_config |= CONFIG_PICTURES;
else
{
h_flags &= ~GRAPHICS_FLAG;
if (filename)
fprintf(stderr, "Warning: could not read graphics file %s\n", filename);
}
}
/* Convert a Z picture number to an index into pict_info. */
static int z_num_to_index(int n)
{
int i;
for (i = 0; i <= num_pictures; i++)
if (pict_info[i].z_num == n)
return i;
return -1;
}
bool os_picture_data(int num, int *height, int *width)
{
int index;
*height = 0;
*width = 0;
if (!pict_info)
return FALSE;
if ((index = z_num_to_index(num)) == -1)
return FALSE;
*height = pict_info[index].height;
*width = pict_info[index].width;
return TRUE;
}
void os_draw_picture (int num, int row, int col)
{
int width, height, r, c;
if (!os_picture_data(num, &height, &width) || !width || !height)
return;
col--, row--;
/* Draw corners */
dumb_set_picture_cell(row, col, '+');
dumb_set_picture_cell(row, col + width - 1, '+');
dumb_set_picture_cell(row + height - 1, col, '+');
dumb_set_picture_cell(row + height - 1, col + width - 1, '+');
/* sides */
for (c = col + 1; c < col + width - 1; c++) {
dumb_set_picture_cell(row, c, '-');
dumb_set_picture_cell(row + height - 1, c, '-');
}
for (r = row + 1; r < row + height - 1; r++) {
dumb_set_picture_cell(r, col, '|');
dumb_set_picture_cell(r, col + width - 1, '|');
}
/* body, but for last line */
for (r = row + 1; r < row + height - 2; r++)
for (c = col + 1; c < col + width - 1; c++)
dumb_set_picture_cell(r, c, ':');
/* Last line of body, including picture number. */
if (height >= 3)
for (c = col + width - 2; c > col; c--, (num /= 10))
dumb_set_picture_cell(row + height - 2, c, num ? (num % 10 + '0') : ':');
}
int os_peek_colour (void) {return BLACK_COLOUR; }
|