1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include <ronin/ronin.h>
24 #include <string.h>
25
26 #include "label.h"
27
28
29 void *get_romfont_address() __asm__(".get_romfont_address");
30 __asm__("\
31 \n\
32 .get_romfont_address: \n\
33 mov.l 1f,r0 \n\
34 mov.l @r0,r0 \n\
35 jmp @r0 \n\
36 mov #0,r1 \n\
37 .align 2 \n\
38 1: .long 0x8c0000b4 \n\
39 \n\
40 ");
41
42
draw_char(unsigned short * dst,int mod,int c,void * font_base)43 static void draw_char(unsigned short *dst, int mod, int c, void *font_base)
44 {
45 unsigned char *src;
46 int i, j;
47 if (c<=32 || c>255 || (c>=127 && c<160)) c=160;
48 if (c<128) c -= 32; else c -= 64;
49 src = c*36 + (unsigned char *)font_base;
50 for (i=0; i<12; i++) {
51 int n = (src[0]<<16)|(src[1]<<8)|src[2];
52 for (j=0; j<12; j++, n<<=1)
53 if (n & (1<<23)) {
54 dst[j] = 0xffff;
55 dst[j+1] = 0xffff;
56 dst[j+2] = 0xa108;
57 dst[j+mod] = 0xa108;
58 dst[j+mod+1] = 0xa108;
59 }
60 dst += mod;
61 for (j=0; j<12; j++, n<<=1)
62 if (n & (1<<23)) {
63 dst[j] = 0xffff;
64 dst[j+1] = 0xffff;
65 dst[j+2] = 0xa108;
66 dst[j+mod] = 0xa108;
67 dst[j+mod+1] = 0xa108;
68 }
69 dst += mod;
70 src += 3;
71 }
72 }
73
create_texture(const char * text)74 void Label::create_texture(const char *text)
75 {
76 void *font = get_romfont_address();
77 int l = strlen(text);
78 if (l>64) l=64;
79 int w = 14*l;
80 for (tex_u=TA_POLYMODE2_U_SIZE_8, u=8; u<w; u<<=1, tex_u += 1<<3);
81 int tsz = u*32;
82 unsigned short *tex = (unsigned short *)ta_txalloc(tsz*2);
83 for (int i=0; i<tsz; i++)
84 tex[i] = 0;
85 int p=l*14;
86 while (l>0)
87 draw_char(tex+(p-=14), u, text[--l], font);
88 texture = tex;
89 }
90
draw(float x,float y,unsigned int argb,float scale)91 void Label::draw(float x, float y, unsigned int argb, float scale)
92 {
93 struct polygon_list mypoly;
94 struct packed_colour_vertex_list myvertex;
95
96 mypoly.cmd =
97 TA_CMD_POLYGON|TA_CMD_POLYGON_TYPE_TRANSPARENT|TA_CMD_POLYGON_SUBLIST|
98 TA_CMD_POLYGON_STRIPLENGTH_2|TA_CMD_POLYGON_PACKED_COLOUR|TA_CMD_POLYGON_TEXTURED;
99 mypoly.mode1 = TA_POLYMODE1_Z_ALWAYS|TA_POLYMODE1_NO_Z_UPDATE;
100 mypoly.mode2 =
101 TA_POLYMODE2_BLEND_SRC_ALPHA|TA_POLYMODE2_BLEND_DST_INVALPHA|
102 TA_POLYMODE2_FOG_DISABLED|TA_POLYMODE2_ENABLE_ALPHA|
103 TA_POLYMODE2_TEXTURE_MODULATE_ALPHA|TA_POLYMODE2_V_SIZE_32|tex_u;
104 mypoly.texture = TA_TEXTUREMODE_ARGB1555|TA_TEXTUREMODE_NON_TWIDDLED|
105 TA_TEXTUREMODE_ADDRESS(texture);
106
107 mypoly.red = mypoly.green = mypoly.blue = mypoly.alpha = 0;
108
109 ta_commit_list(&mypoly);
110
111 myvertex.cmd = TA_CMD_VERTEX;
112 myvertex.ocolour = 0;
113 myvertex.colour = argb;
114 myvertex.z = 0.5;
115 myvertex.u = 0.0;
116 myvertex.v = 0.0;
117
118 myvertex.x = x;
119 myvertex.y = y;
120 ta_commit_list(&myvertex);
121
122 myvertex.x = x+u*scale;
123 myvertex.u = 1.0;
124 ta_commit_list(&myvertex);
125
126 myvertex.x = x;
127 myvertex.y = y+25.0*scale;
128 myvertex.u = 0.0;
129 myvertex.v = 25.0/32.0;
130 ta_commit_list(&myvertex);
131
132 myvertex.x = x+u*scale;
133 myvertex.u = 1.0;
134 myvertex.cmd |= TA_CMD_VERTEX_EOS;
135 ta_commit_list(&myvertex);
136 }
137