-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex8.c
150 lines (112 loc) · 2.89 KB
/
ex8.c
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
/*=========================================================================
GFX EXAMPLE CODE - #8
"alphabets"
Copyright (C) 2004 Rafael de Oliveira Jannone
This example's source code is Public Domain.
WARNING: The author makes no guarantees and holds no responsibility for
any damage, injury or loss that may result from the use of this source
code. USE IT AT YOUR OWN RISK.
Contact the author:
by e-mail : rafael AT jannone DOT org
homepage : http://jannone.org/gfxlib
ICQ UIN : 10115284
=========================================================================*/
#include <stdio.h>
#include "gfx.h"
#define VRAM_OFFS 0
#define FILE_OFFS 7
#define MAX_BUF (256 * 8)
// binary data
#asm
psect data
global _square
_square:
defb 11100111B
defb 10000001B
defb 10000001B
defb 00000000B
defb 00000000B
defb 10000001B
defb 10000001B
defb 11100111B
#endasm
// cursor shape
extern u_char square[];
// zooms into a char shape
void preview_char(u_char* p) {
int x, y, addr;
u_char c;
for (y = 0; y < 8; y++) {
addr = map_pixel(22 * 8, (y << 3) + 8);
c = *p++;
for (x = 0; x < 8; x++) {
fill(addr, (c & 128) ? 255 : 0, 8);
c <<= 1;
addr += 8;
}
}
}
// do the whole preview table and stuff :)
void do_preview(u_char* buf) {
int asc, x, y, addr;
u_char st;
set_color(15, 4, 4);
set_sprite_8(0, square);
fill(MODE2_ATTR, 0xF0, MODE2_MAX);
// start blitting buffer at pixel (16,16)
addr = map_block(16, 16);
// 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);
// fill yellow background
blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);
x = 0; y = 0;
// preview loop
while (!get_trigger(0)) {
// move the cursor and set the zooming
st = st_dir[get_stick(0)];
x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);
x &= 15;
y &= 15;
asc = (y << 4) + x;
put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);
preview_char(buf + (asc << 3));
}
}
main(int argc, char *argv[]) {
FILE* f;
bool preview;
u_char buf[MAX_BUF];
// bouring argv stuff
if (!--argc) {
printf("Usage: ex8 [-]file.alf\n");
printf("\t- : preview mode\n");
printf("file must be of type GRAPHOS ALPHABET (.ALF)\n");
return 1;
}
preview = false;
++argv;
if (*argv[0] == '-') {
(*argv)++;
preview = true;
printf("preview mode on\n");
}
// read file
f = fopen(*argv, "rb");
if (!f) {
printf("couldn't open file %s\n", *argv);
return 2;
}
fseek(f, FILE_OFFS, 0);
fread(buf + 8, 1, MAX_BUF - 8, f);
fclose(f);
buf[0]=buf[1]=buf[2]=buf[3]=buf[4]=buf[5]=buf[6]=buf[7]=0;
// here is the thing: when not previewing, the vwrite will set
// your whole char table with the given alphabet. nice :)
set_mode((preview) ? mode_2 : mode_1);
if (preview) {
do_preview(buf);
set_mode(mode_0);
} else
vwrite(buf + 8, VRAM_OFFS, MAX_BUF);
}