blob: 21f0a28c81c6ed49befcb414d1656f107fe43b38 [file] [log] [blame]
adamdunkels38fb3502004-09-12 20:30:03 +00001/*
2 * Copyright (c) 2004, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
oliverschmidtdbd44a12006-05-28 20:40:16 +000033 * $Id: ctk-80col.c,v 1.16 2006/05/28 20:40:16 oliverschmidt Exp $
adamdunkels38fb3502004-09-12 20:30:03 +000034 */
adamdunkels4f45d1f2004-08-09 20:53:08 +000035
adamdunkelsf2cd18a2004-09-05 20:58:13 +000036#include "contiki.h"
adamdunkels4f45d1f2004-08-09 20:53:08 +000037
adamdunkelsa726d4f2004-09-05 07:09:41 +000038#include "ctk.h"
39#include "ctk-draw.h"
40#include "ctk-draw-service.h"
adamdunkels4f45d1f2004-08-09 20:53:08 +000041
adamdunkelsa726d4f2004-09-05 07:09:41 +000042#include "ctk-80col-asm.h"
adamdunkels4f45d1f2004-08-09 20:53:08 +000043
adamdunkelsf2cd18a2004-09-05 20:58:13 +000044#include "ctk-80col-theme.h"
45
adamdunkelsa726d4f2004-09-05 07:09:41 +000046#include <string.h>
47
48unsigned char ctk_80col_cursx, ctk_80col_cursy;
49unsigned char ctk_80col_reversed;
50unsigned char ctk_80col_color;
51unsigned char *ctk_80col_bitmapptr;
52unsigned char ctk_80col_underline = 0;
adamdunkels4f45d1f2004-08-09 20:53:08 +000053
54#define SCREEN_HEIGHT 25
55#define SCREEN_WIDTH 80
56
57#define SCREENADDR 0xdc00
58#define HIRESADDR 0xe000
59
60unsigned char ctk_80col_lefttab[256];
61unsigned char ctk_80col_righttab[256];
62
adamdunkelsf2cd18a2004-09-05 20:58:13 +000063#define COLOR(bg, fg) ((fg << 4) | (bg))
64
adamdunkelsfa6f7362004-09-06 06:33:39 +000065#define COLOR_DIALOG 0x01
adamdunkelsf2cd18a2004-09-05 20:58:13 +000066#define COLOR_FOCUS_WINDOW 0xbf
adamdunkelsfa6f7362004-09-06 06:33:39 +000067#define COLOR_BACKGROUND_WINDOW 0x0c
adamdunkelsf2cd18a2004-09-05 20:58:13 +000068
69#define color(c) ctk_80col_color = c
70
71#define BGCOLOR1 7
72#define BGCOLOR2 10
73#define BGCOLOR3 4
74#define BGCOLOR4 6
75
76unsigned char ctk_80col_screencolors[25] =
77 {COLOR(BGCOLOR4,BGCOLOR1),
adamdunkels4f087742004-09-09 21:45:37 +000078 COLOR(BGCOLOR2,BGCOLOR1),
adamdunkelsf2cd18a2004-09-05 20:58:13 +000079 COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),
80 COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),
81 COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),
82 COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),
83 COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),
84 COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),
85 COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),
86 COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),
87 COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),
88 COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),
adamdunkels4f087742004-09-09 21:45:37 +000089 COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),
adamdunkelsa766bf42004-09-18 20:43:01 +000090 COLOR(BGCOLOR4,1)};
adamdunkelsf2cd18a2004-09-05 20:58:13 +000091
92unsigned char ctk_80col_screenpattern[25*8] =
adamdunkels4f087742004-09-09 21:45:37 +000093 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
adamdunkelsf2cd18a2004-09-05 20:58:13 +000094 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,
95 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,
96 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,
97 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
98 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,
99 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,
100 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,
101 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
102 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,
103 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,
104 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,
105 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
106 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,
107 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,
108 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,
109 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
110 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,
111 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,
112 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,
113 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
114 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,
115 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,
adamdunkels4f087742004-09-09 21:45:37 +0000116 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,
117 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000118
119unsigned short ctk_80col_yscreenaddr[25] =
120 {0 * 40 + SCREENADDR, 1 * 40 + SCREENADDR,
121 2 * 40 + SCREENADDR, 3 * 40 + SCREENADDR,
122 4 * 40 + SCREENADDR, 5 * 40 + SCREENADDR,
123 6 * 40 + SCREENADDR, 7 * 40 + SCREENADDR,
124 8 * 40 + SCREENADDR, 9 * 40 + SCREENADDR,
125 10 * 40 + SCREENADDR, 11 * 40 + SCREENADDR,
126 12 * 40 + SCREENADDR, 13 * 40 + SCREENADDR,
127 14 * 40 + SCREENADDR, 15 * 40 + SCREENADDR,
128 16 * 40 + SCREENADDR, 17 * 40 + SCREENADDR,
129 18 * 40 + SCREENADDR, 19 * 40 + SCREENADDR,
130 20 * 40 + SCREENADDR, 21 * 40 + SCREENADDR,
131 22 * 40 + SCREENADDR, 23 * 40 + SCREENADDR,
132 24 * 40 + SCREENADDR};
133
adamdunkelsa726d4f2004-09-05 07:09:41 +0000134unsigned short ctk_80col_yhiresaddr[25] =
adamdunkels4f45d1f2004-08-09 20:53:08 +0000135 {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR,
136 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR,
137 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR,
138 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR,
139 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR,
140 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR,
141 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR,
142 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR,
143 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR,
144 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR,
145 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR,
146 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR,
147 24 * 320 + HIRESADDR};
148
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000149
150struct ctk_80col_theme ctk_80col_theme =
151 {
152 /* Version string. */
153 /* char version[8]; */
154 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
155
156 /* Window borders patterns. */
157 /* unsigned char ulcorner[8], */ /* Upper left corner. */
158 {0xff,0xc0,0x80,0xbf,0x80,0xbf,0x80,0x80},
159
160 /* titlebar[8], */ /* Title bar pattern. */
161 {0xff,0x00,0x00,0xff,0x00,0xff,0x00,0x00},
162
163 /* urcorner[8], */ /* Upper right corner. */
164 {0xff,0x03,0x01,0xfd,0x01,0xfd,0x01,0x01},
165
166 /* rightborder[8], */ /* Right border. */
167 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
168
169 /* lrcorner[8], */ /* Lower right corner. */
170 {0x01,0x01,0x01,0x01,0x01,0x01,0x03,0xff},
171
172 /* lowerborder[8], */ /* Lower border. */
173 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
174
175 /* llcorner[8], */ /* Lower left corner. */
176 {0x80,0x80,0x80,0x80,0x80,0x80,0xc0,0xff},
177
178 /* leftborder[8]; */ /* Left border. */
179 {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},
180
181 /* Button corner patterns. */
182 /* unsigned char buttonleft[8], */
183 {0xc5,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf},
184
185 /* buttonright[8]; */
186 {0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xa3},
adamdunkelsfa6f7362004-09-06 06:33:39 +0000187
188 /* Menu border patterns. */
189 /* unsigned char menuleftpattern[8], */
190 {0x0f,0x3f,0x3f,0x7f,0x7f,0xff,0xff,0xff},
191
192 /* menurightpatterns[8]; */
193 {0xf0,0xfc,0xfc,0xfe,0xfe,0xff,0xff,0xff},
194
195 /* Window and widget colors. */
196 /* unsigned char windowcolors[6], */
197 {COLOR(COLOR_GRAY2, COLOR_BLACK),
198 COLOR(COLOR_GRAY2, COLOR_BLACK),
199 COLOR(COLOR_GRAY3, COLOR_GRAY1),
200 COLOR(COLOR_GRAY3, COLOR_GRAY1),
201 COLOR(COLOR_WHITE, COLOR_BLACK),
202 COLOR(COLOR_WHITE, COLOR_BLACK)},
203
204 /* separatorcolors[6], */
205 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
206 COLOR(COLOR_GRAY2, COLOR_GRAY1),
207 COLOR(COLOR_GRAY3, COLOR_GRAY2),
208 COLOR(COLOR_GRAY3, COLOR_GRAY2),
209 COLOR(COLOR_WHITE, COLOR_GRAY1),
210 COLOR(COLOR_WHITE, COLOR_GRAY1)},
211
212 /* labelcolors[6], */
213 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
214 COLOR(COLOR_GRAY2, COLOR_GRAY1),
215 COLOR(COLOR_WHITE, COLOR_BLACK),
216 COLOR(COLOR_WHITE, COLOR_BLACK),
217 COLOR(COLOR_WHITE, COLOR_BLACK),
218 COLOR(COLOR_WHITE, COLOR_BLACK)},
219
220 /* buttoncolors[6], */
221 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
222 COLOR(COLOR_GRAY1, COLOR_GRAY2),
223 COLOR(COLOR_GRAY3, COLOR_GRAY1),
224 COLOR(COLOR_GRAY1, COLOR_GRAY3),
225 COLOR(COLOR_GRAY3, COLOR_GRAY1),
226 COLOR(COLOR_GRAY1, COLOR_GRAY3)},
227
228 /* hyperlinkcolors[6], */
229 {COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE),
230 COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE),
231 COLOR(COLOR_WHITE, COLOR_BLUE),
232 COLOR(COLOR_BLUE, COLOR_WHITE),
233 COLOR(COLOR_WHITE, COLOR_BLUE),
234 COLOR(COLOR_BLUE, COLOR_WHITE)},
235
236 /* textentrycolors[6], */
237 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
238 COLOR(COLOR_GRAY2, COLOR_BLACK),
239 COLOR(COLOR_WHITE, COLOR_BLACK),
240 COLOR(COLOR_WHITE, COLOR_BLACK),
241 COLOR(COLOR_GRAY3, COLOR_BLACK),
242 COLOR(COLOR_GRAY3, COLOR_BLACK)},
243
244 /* bitmapcolors[6], */
245 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
246 COLOR(COLOR_GRAY1, COLOR_BLACK),
247 COLOR(COLOR_WHITE, COLOR_GRAY1),
248 COLOR(COLOR_GRAY3, COLOR_BLACK),
249 COLOR(COLOR_GRAY3, COLOR_BLACK),
250 COLOR(COLOR_GRAY3, COLOR_BLACK)},
251
252 /* textmapcolors[6], */
253 {COLOR(COLOR_GRAY2, COLOR_GRAY1),
254 COLOR(COLOR_GRAY2, COLOR_GRAY1),
255 COLOR(COLOR_WHITE, COLOR_BLACK),
256 COLOR(COLOR_WHITE, COLOR_BLACK),
257 COLOR(COLOR_WHITE, COLOR_BLACK),
258 COLOR(COLOR_WHITE, COLOR_BLACK)},
259
260 /* iconcolors[6]; */
261 {COLOR(COLOR_GRAY3, COLOR_GRAY1),
262 COLOR(COLOR_GRAY1, COLOR_GRAY2),
263 COLOR(COLOR_WHITE, COLOR_BLACK),
adamdunkels4f087742004-09-09 21:45:37 +0000264 COLOR(COLOR_BLUE, COLOR_WHITE),
adamdunkelsfa6f7362004-09-06 06:33:39 +0000265 COLOR(COLOR_WHITE, COLOR_BLACK),
266 COLOR(COLOR_BLACK, COLOR_YELLOW)},
267
adamdunkels4f087742004-09-09 21:45:37 +0000268 /* Menu colors. */
269 /* unsigned char menucolor,*/
adamdunkelsa766bf42004-09-18 20:43:01 +0000270 COLOR(COLOR_YELLOW, COLOR_BLACK),
adamdunkels4f087742004-09-09 21:45:37 +0000271
272 /* openmenucolor, */
adamdunkelsa766bf42004-09-18 20:43:01 +0000273 COLOR(COLOR_WHITE, COLOR_BLACK),
adamdunkels4f087742004-09-09 21:45:37 +0000274
275 /* activemenucolor; */
adamdunkelsa766bf42004-09-18 20:43:01 +0000276 COLOR(COLOR_BLACK, COLOR_WHITE),
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000277
278 };
279char ctk_80col_versionstring[] = CONTIKI_VERSION_STRING;
280char ctk_80col_versionstring_len = sizeof(CONTIKI_VERSION_STRING) - 1;
281
282struct ctk_80col_windowparams ctk_80col_windowparams;
283
adamdunkels4f45d1f2004-08-09 20:53:08 +0000284/*---------------------------------------------------------------------------*/
adamdunkelsa726d4f2004-09-05 07:09:41 +0000285/*void
adamdunkels4f45d1f2004-08-09 20:53:08 +0000286ctk_arch_draw_char(char c,
287 unsigned char xpos,
288 unsigned char ypos,
289 unsigned char reversedflag,
290 unsigned char color)
291{
adamdunkelsa726d4f2004-09-05 07:09:41 +0000292 ctk_80col_cursx = xpos;
293 ctk_80col_cursy = ypos;
294 ctk_80col_reversed = reversedflag;
295 ctk_80col_color = color;
adamdunkels4f45d1f2004-08-09 20:53:08 +0000296
adamdunkelsa726d4f2004-09-05 07:09:41 +0000297 ctk_80col_cputc(c);
298}*/
adamdunkels4f45d1f2004-08-09 20:53:08 +0000299/*---------------------------------------------------------------------------*/
300#pragma optimize(push, off)
301static void
302nmi2(void)
303{
304 asm("pla");
305 asm("sta $01");
306 asm("pla");
307 asm("rti");
308}
309#pragma optimize(pop)
310/*---------------------------------------------------------------------------*/
311#pragma optimize(push, off)
312static void
313nmi(void)
314{
315 asm("sei");
316 asm("pha");
317 asm("inc $d020");
318 asm("lda $01");
319 asm("pha");
320 asm("lda #$36");
321 asm("sta $01");
322 asm("lda #>_nmi2");
323 asm("pha");
324 asm("lda #<_nmi2");
325 asm("pha");
326 asm("php");
327 asm("jmp ($0318)");
328
329 nmi2();
330}
331#pragma optimize(pop)
332/*---------------------------------------------------------------------------*/
333#pragma optimize(push, off)
334static void
335setup_nmi(void)
336{
337 asm("lda #<_nmi");
338 asm("sta $fffa");
339 asm("lda #>_nmi");
340 asm("sta $fffb");
341 return;
342 nmi();
343}
344#pragma optimize(pop)
345/*---------------------------------------------------------------------------*/
adamdunkels81061fe2004-09-12 07:29:00 +0000346void reset(void);
347void
348quit(void)
349{
350 VIC.ctrl1 = 0x1b; /* $D011 */
351 VIC.addr = 0x17; /* $D018 */
352 VIC.ctrl2 = 0xc8; /* $D016 */
353 CIA2.pra = 0x03; /* $DD00 */
354
355 VIC.bordercolor = 0x0e; /* $D020 */
356 VIC.bgcolor0 = 0x06; /* $D021 */
357
358 memset((char *)0xd800, 0x0e, 40*25);
359
adamdunkels81061fe2004-09-12 07:29:00 +0000360}
361/*-----------------------------------------------------------------------------------*/
adamdunkels4f45d1f2004-08-09 20:53:08 +0000362#pragma optimize(push, off)
adamdunkelsa766bf42004-09-18 20:43:01 +0000363static void
adamdunkels4f45d1f2004-08-09 20:53:08 +0000364ctk_80col_init(void)
365{
366 int i;
adamdunkels4f45d1f2004-08-09 20:53:08 +0000367
368 setup_nmi();
369
370 /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for
371 hires/colors. */
372 VIC.ctrl1 = 0x3b; /* $D011 */
373 VIC.addr = 0x78; /* $D018 */
374 VIC.ctrl2 = 0xc8; /* $D016 */
375 CIA2.pra = 0x00; /* $DD00 */
376
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000377 VIC.bordercolor = 0x06; /* $D020 */
adamdunkels4f45d1f2004-08-09 20:53:08 +0000378 VIC.bgcolor0 = 0x0b; /* $D021 */
379
380 /* Fill color memory. */
381 asm("sei");
382 asm("lda $01");
383 asm("pha");
384 asm("lda #$30");
385 asm("sta $01");
386 asm("ldx #0");
adamdunkels81061fe2004-09-12 07:29:00 +0000387 asm("lda #$0");
adamdunkels4f45d1f2004-08-09 20:53:08 +0000388 asm("fillcolorloop:");
389 asm("sta $dc00,x");
390 asm("sta $dd00,x");
391 asm("sta $de00,x");
392 asm("sta $df00,x");
393 asm("inx");
394 asm("bne fillcolorloop");
395
396 /* Setup sprite pointers */
397 asm("ldx #$fd");
398 asm("stx $dff8");
399 asm("inx");
400 asm("stx $dff9");
401 asm("pla");
402 asm("sta $01");
403 asm("cli");
404
405 /* Fill hires memory with 0. */
406
adamdunkelsa766bf42004-09-18 20:43:01 +0000407 memset((char *)0xe000, 0, 8000);
adamdunkels4f45d1f2004-08-09 20:53:08 +0000408
409 for(i = 0; i < 256; ++i) {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000410#if 0
411 ctk_80col_lefttab[i] =
412 ((i & 0x40) << 1) |
413 ((i & 0x20) << 1) |
414 ((i & 0x08) << 2) |
415 ((i & 0x02) << 3);
416 ctk_80col_righttab[i] =
417 ((i & 0x40) >> 3) |
418 ((i & 0x20) >> 3) |
419 ((i & 0x08) >> 2) |
420 ((i & 0x02) >> 1);
421#else
adamdunkels4f45d1f2004-08-09 20:53:08 +0000422 ctk_80col_lefttab[i] =
423 ((i & 0x40) << 1) |
424 ((i & 0x10) << 2) |
425 ((i & 0x04) << 3) |
426 ((i & 0x01) << 4);
427 ctk_80col_righttab[i] =
428 ((i & 0x40) >> 3) |
429 ((i & 0x10) >> 2) |
430 ((i & 0x04) >> 1) |
431 ((i & 0x01));
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000432#endif
adamdunkels4f45d1f2004-08-09 20:53:08 +0000433 }
434
435#if 0
436 /* Setup mouse pointer sprite. */
adamdunkelsa726d4f2004-09-05 07:09:41 +0000437 asm("lda %v+%w", ctk_80col_theme,
438 offsetof(struct ctk_80col_theme, pointermaskcolor));
adamdunkels4f45d1f2004-08-09 20:53:08 +0000439 asm("sta $d027");
adamdunkelsa726d4f2004-09-05 07:09:41 +0000440 asm("lda %v+%w", ctk_80col_theme,
441 offsetof(struct ctk_80col_theme, pointercolor));
adamdunkels4f45d1f2004-08-09 20:53:08 +0000442 asm("sta $d028");
443
adamdunkelsa726d4f2004-09-05 07:09:41 +0000444 ptr1 = ctk_80col_theme.pointer;
adamdunkels4f45d1f2004-08-09 20:53:08 +0000445 ptr2 = (unsigned char *)0xff40;
446
447 for(i = 0; i < 0x80; ++i) {
448 *ptr2++ = *ptr1++;
449 }
450#endif
451 return;
452}
453#pragma optimize(pop)
454/*---------------------------------------------------------------------------*/
adamdunkelsa726d4f2004-09-05 07:09:41 +0000455/*static unsigned char cursx, cursy;
456 static unsigned char reversed;*/
457
458/*-----------------------------------------------------------------------------------*/
459static void CC_FASTCALL
460cputc(char c)
461{
462 /* ctk_arch_draw_char(c, cursx, cursy, reversed, 0);*/
463 ctk_80col_cputc(c);
464 /* ++cursx;*/
465}
466/*-----------------------------------------------------------------------------------*/
467unsigned char
468wherex(void)
469{
470 return ctk_80col_cursx;
471}
472/*-----------------------------------------------------------------------------------*/
473unsigned char
474wherey(void)
475{
476 return ctk_80col_cursy;
477}
478/*-----------------------------------------------------------------------------------*/
479/*void
480clrscr(void)
481{
482 unsigned char x, y;
483
484 for(x = 0; x < SCREEN_WIDTH; ++x) {
485 for(y = 0; y < SCREEN_HEIGHT; ++y) {
486 gotoxy(x, y);
487 cputc(' ');
488 }
489 }
490}*/
491/*-----------------------------------------------------------------------------------*/
492#define revers(c) ctk_80col_reversed = c
493/*-----------------------------------------------------------------------------------*/
494static void CC_FASTCALL
495_cputs(char *str)
496{
497 char *ptr = str;
498
499 while(*ptr != 0) {
500 cputc(*ptr++);
501 }
502
503 /* int i;
504 for(i = 0; i < strlen(str); ++i) {
505 cputc(str[i]);
506 }*/
507}
508/*-----------------------------------------------------------------------------------*/
509static void CC_FASTCALL
510cclear(unsigned char length)
511{
512 int i;
513 for(i = 0; i < length; ++i) {
514 cputc(' ');
515 }
516}
517/*-----------------------------------------------------------------------------------*/
518void CC_FASTCALL
519chline(unsigned char length)
520{
521 int i;
522 for(i = 0; i < length; ++i) {
523 cputc('-');
524 }
525}
526/*-----------------------------------------------------------------------------------*/
527void CC_FASTCALL
528cvline(unsigned char length)
529{
530 int i;
531 for(i = 0; i < length; ++i) {
532 cputc('|');
533 --ctk_80col_cursx;
534 ++ctk_80col_cursy;
535 }
536}
537/*-----------------------------------------------------------------------------------*/
538void CC_FASTCALL
539gotoxy(unsigned char x, unsigned char y)
540{
541 ctk_80col_cursx = x;
542 ctk_80col_cursy = y;
543}
544/*-----------------------------------------------------------------------------------*/
545void CC_FASTCALL
546cclearxy(unsigned char x, unsigned char y, unsigned char length)
547{
548 gotoxy(x, y);
549 cclear(length);
550}
551/*-----------------------------------------------------------------------------------*/
552void CC_FASTCALL
553chlinexy(unsigned char x, unsigned char y, unsigned char length)
554{
555 gotoxy(x, y);
556 chline(length);
557}
558/*-----------------------------------------------------------------------------------*/
559void CC_FASTCALL
560cvlinexy(unsigned char x, unsigned char y, unsigned char length)
561{
562 gotoxy(x, y);
563 cvline(length);
564}
565/*-----------------------------------------------------------------------------------*/
566void CC_FASTCALL
567_cputsxy(unsigned char x, unsigned char y, char *str)
568{
569 gotoxy(x, y);
570 _cputs(str);
571}
572/*-----------------------------------------------------------------------------------*/
573void CC_FASTCALL
574cputcxy(unsigned char x, unsigned char y, char c)
575{
576 gotoxy(x, y);
577 cputc(c);
578}
579/*-----------------------------------------------------------------------------------*/
adamdunkelsdea725c2004-09-12 13:25:15 +0000580/*void CC_FASTCALL
adamdunkelsa726d4f2004-09-05 07:09:41 +0000581screensize(unsigned char *x, unsigned char *y)
582{
583 *x = SCREEN_WIDTH;
584 *y = SCREEN_HEIGHT;
adamdunkelsdea725c2004-09-12 13:25:15 +0000585}*/
adamdunkelsa726d4f2004-09-05 07:09:41 +0000586/*-----------------------------------------------------------------------------------*/
adamdunkelsdea725c2004-09-12 13:25:15 +0000587/*static unsigned char sizex, sizey;*/
adamdunkelsa726d4f2004-09-05 07:09:41 +0000588/*-----------------------------------------------------------------------------------*/
589static void
590_cputsn(char *str, unsigned char len)
591{
592 /* char c;
593
594 while(len > 0) {
595 --len;
596 c = *str;
597 if(c == 0) {
598 break;
599 }
600 cputc(c);
601 ++str;
602 }*/
603 ctk_80col_cputsn(str, len);
604}
605/*-----------------------------------------------------------------------------------*/
606static void
607s_ctk_draw_init(void)
608{
adamdunkelsdea725c2004-09-12 13:25:15 +0000609 ctk_80col_init();
610
611 /* screensize(&sizex, &sizey);*/
612
613 ctk_draw_clear(0, SCREEN_HEIGHT);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000614}
615/*-----------------------------------------------------------------------------------*/
616static void
617draw_widget(struct ctk_widget *w,
618 unsigned char x, unsigned char y,
619 unsigned char clipx,
620 unsigned char clipy,
621 unsigned char clipy1, unsigned char clipy2,
622 unsigned char focus)
623{
624 unsigned char xpos, ypos, xscroll;
625 unsigned char i, j;
626 char c, *text;
627 unsigned char len, wfocus;
628
629 wfocus = 0;
630 if(focus & CTK_FOCUS_WINDOW) {
631 if(focus & CTK_FOCUS_WIDGET) {
632 wfocus = 1;
633 }
634 } else if(focus & CTK_FOCUS_DIALOG) {
635 if(focus & CTK_FOCUS_WIDGET) {
636 wfocus = 1;
637 }
638 } else {
639 }
640
641 xpos = x + w->x;
642 ypos = y + w->y;
643
644 switch(w->type) {
645 case CTK_WIDGET_SEPARATOR:
646 if(ypos >= clipy1 && ypos < clipy2) {
647 chlinexy(xpos, ypos, w->w);
648 }
649 break;
650 case CTK_WIDGET_LABEL:
651 text = w->widget.label.text;
652 for(i = 0; i < w->h; ++i) {
653 if(ypos >= clipy1 && ypos < clipy2) {
654 gotoxy(xpos, ypos);
655 _cputsn(text, w->w);
656 if(w->w - (wherex() - xpos) > 0) {
657 cclear(w->w - (wherex() - xpos));
658 }
659 }
660 ++ypos;
661 text += w->w;
662 }
663 break;
664 case CTK_WIDGET_BUTTON:
665 if(ypos >= clipy1 && ypos < clipy2) {
666 if(wfocus != 0) {
667 revers(1);
668 } else {
669 revers(0);
670 }
671 cputcxy(xpos, ypos, '[');
672 _cputsn(w->widget.button.text, w->w);
673 cputc(']');
674 revers(0);
675 }
676 break;
677 case CTK_WIDGET_HYPERLINK:
678 if(ypos >= clipy1 && ypos < clipy2) {
679 if(wfocus != 0) {
680 revers(0);
681 } else {
682 revers(1);
683 }
684 gotoxy(xpos, ypos);
685 _cputsn(w->widget.button.text, w->w);
686 revers(0);
687 }
688 break;
689 case CTK_WIDGET_TEXTENTRY:
690 text = w->widget.textentry.text;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000691 xscroll = 0;
692 if(w->widget.textentry.xpos >= w->w - 1) {
693 xscroll = w->widget.textentry.xpos - w->w + 1;
694 }
695 for(j = 0; j < w->h; ++j) {
696 if(ypos >= clipy1 && ypos < clipy2) {
697 if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT &&
698 w->widget.textentry.ypos == j) {
699 revers(0);
700 cputcxy(xpos, ypos, '>');
oliverschmidtdbd44a12006-05-28 20:40:16 +0000701 c = 1;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000702 for(i = 0; i < w->w; ++i) {
oliverschmidtdbd44a12006-05-28 20:40:16 +0000703 if(c != 0) {
704 c = text[i + xscroll];
705 }
adamdunkelsa726d4f2004-09-05 07:09:41 +0000706 if(i == w->widget.textentry.xpos - xscroll) {
707 revers(1);
708 } else {
709 revers(0);
710 }
711 if(c == 0) {
712 cputc(' ');
713 } else {
714 cputc(c);
715 }
716 revers(0);
717 }
718 cputc('<');
719 } else {
oliverschmidt6a7513a2005-05-04 22:06:05 +0000720 if(wfocus != 0 && j == w->widget.textentry.ypos) {
721 revers(1);
722 } else {
723 revers(0);
724 }
adamdunkelsa726d4f2004-09-05 07:09:41 +0000725 cvlinexy(xpos, ypos, 1);
726 gotoxy(xpos + 1, ypos);
727 _cputsn(text, w->w);
728 i = wherex();
729 if(i - xpos - 1 < w->w) {
730 cclear(w->w - (i - xpos) + 1);
731 }
732 cvline(1);
733 }
734 }
735 ++ypos;
oliverschmidte5a7b9d2005-05-05 20:55:26 +0000736 text += w->widget.textentry.len + 1;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000737 }
738 revers(0);
739 break;
740 case CTK_WIDGET_ICON:
741 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkels4f087742004-09-09 21:45:37 +0000742 color(ctk_80col_theme.iconcolors[focus]);
743
744 /* if(focus & 1) {
745
adamdunkelsa726d4f2004-09-05 07:09:41 +0000746 revers(1);
747 } else {
748 revers(0);
adamdunkels4f087742004-09-09 21:45:37 +0000749 }*/
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000750 /* gotoxy(xpos, ypos);*/
751 if(xpos >= 73) {
752 xpos = 73;
753 }
754 if(xpos <= 2) {
755 xpos = 2;
756 }
adamdunkelsa726d4f2004-09-05 07:09:41 +0000757 if(w->widget.icon.textmap != NULL) {
758 ctk_80col_bitmapptr = w->widget.icon.bitmap;
759 for(i = 0; i < 3; ++i) {
adamdunkelsa726d4f2004-09-05 07:09:41 +0000760 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000761 gotoxy(xpos, ypos);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000762 ctk_80col_draw_bitmapline(3);
763 }
764 ctk_80col_bitmapptr += 3 * 8;
765 ++ypos;
766 }
767 }
768 x = xpos;
769
770 len = strlen(w->widget.icon.title);
adamdunkelsdea725c2004-09-12 13:25:15 +0000771 if(x + len >= SCREEN_WIDTH) {
772 x = SCREEN_WIDTH - len;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000773 }
774
adamdunkelsa726d4f2004-09-05 07:09:41 +0000775 if(ypos >= clipy1 && ypos < clipy2) {
adamdunkels4f087742004-09-09 21:45:37 +0000776 len = strlen(w->widget.icon.title);
777 gotoxy((x & 0xfe) + 1, ypos);
adamdunkelsa766bf42004-09-18 20:43:01 +0000778 ctk_80col_cclear((len - 1)/ 2);
adamdunkels4f087742004-09-09 21:45:37 +0000779 gotoxy(x, ypos);
780 ctk_80col_cputsn(w->widget.icon.title, len);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000781 }
782 revers(0);
783 }
784 break;
785
786 default:
787 break;
788 }
789}
790/*-----------------------------------------------------------------------------------*/
791static void
792s_ctk_draw_widget(struct ctk_widget *w,
793 unsigned char focus,
794 unsigned char clipy1,
795 unsigned char clipy2)
796{
797 struct ctk_window *win = w->window;
798 unsigned char posx, posy;
799
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000800 posx = (win->x & 0xfe) + 1;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000801 posy = win->y + 2;
802
803 if(w == win->focused) {
804 focus |= CTK_FOCUS_WIDGET;
805 }
806
807 draw_widget(w, posx, posy,
808 posx + win->w,
809 posy + win->h,
810 clipy1, clipy2,
811 focus);
812
813#ifdef CTK_CONIO_CONF_UPDATE
814 CTK_CONIO_CONF_UPDATE();
815#endif /* CTK_CONIO_CONF_UPDATE */
816}
817/*-----------------------------------------------------------------------------------*/
818static void
819s_ctk_draw_clear_window(struct ctk_window *window,
820 unsigned char focus,
821 unsigned char clipy1,
822 unsigned char clipy2)
823{
824 unsigned char i;
825 unsigned char h;
adamdunkelsdea725c2004-09-12 13:25:15 +0000826
adamdunkelsa726d4f2004-09-05 07:09:41 +0000827 if(focus & CTK_FOCUS_WINDOW) {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000828 color(COLOR_FOCUS_WINDOW);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000829 } else {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000830 color(COLOR_BACKGROUND_WINDOW);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000831 }
832
833 h = window->y + 2 + window->h;
834 /* Clear window contents. */
835 for(i = window->y + 2; i < h; ++i) {
836 if(i >= clipy1 && i < clipy2) {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000837 gotoxy((window->x & 0xfe) + 1, i);
838 ctk_80col_cclear((window->w + 1)/2);
adamdunkelsa726d4f2004-09-05 07:09:41 +0000839 }
840 }
841}
842/*-----------------------------------------------------------------------------------*/
843static void
844draw_window_contents(struct ctk_window *window, unsigned char focus,
845 unsigned char clipy1, unsigned char clipy2,
846 unsigned char x1, unsigned char x2,
847 unsigned char y1, unsigned char y2)
848{
849 struct ctk_widget *w;
850 unsigned char wfocus;
851
852 /* Draw inactive widgets. */
853 for(w = window->inactive; w != NULL; w = w->next) {
854 draw_widget(w, x1, y1, x2, y2,
855 clipy1, clipy2,
856 focus);
857 }
858
859 /* Draw active widgets. */
860 for(w = window->active; w != NULL; w = w->next) {
861 wfocus = focus;
862 if(w == window->focused) {
863 wfocus |= CTK_FOCUS_WIDGET;
864 }
865
866 draw_widget(w, x1, y1, x2, y2,
867 clipy1, clipy2,
868 wfocus);
869 }
870
871#ifdef CTK_CONIO_CONF_UPDATE
872 CTK_CONIO_CONF_UPDATE();
873#endif /* CTK_CONIO_CONF_UPDATE */
874
875}
876/*-----------------------------------------------------------------------------------*/
877static void
878s_ctk_draw_window(struct ctk_window *window, unsigned char focus,
oliverschmidt4c59cb02005-03-15 15:56:07 +0000879 unsigned char clipy1, unsigned char clipy2,
880 unsigned char draw_borders)
adamdunkelsa726d4f2004-09-05 07:09:41 +0000881{
882 unsigned char x, y;
883 unsigned char h;
884 unsigned char x1, y1, x2, y2;
885
adamdunkelsdea725c2004-09-12 13:25:15 +0000886
adamdunkelsa726d4f2004-09-05 07:09:41 +0000887 if(window->y + 1 >= clipy2) {
888 return;
889 }
890
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000891 x = window->x & 0xfe;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000892 y = window->y + 1;
893
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000894/* if(focus & CTK_FOCUS_WINDOW) {
adamdunkelsa726d4f2004-09-05 07:09:41 +0000895 } else {
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000896 }*/
adamdunkelsa726d4f2004-09-05 07:09:41 +0000897
898 x1 = x + 1;
899 y1 = y + 1;
900 x2 = x1 + window->w;
901 y2 = y1 + window->h;
902
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000903 /* Draw window frame. */
904 gotoxy(x, y);
905 ctk_80col_windowparams.w = (window->w-1)/2;
906 ctk_80col_windowparams.h = window->h;
907 if(clipy1 < y) {
908 ctk_80col_windowparams.clipy1 = 0;
909 } else {
910 ctk_80col_windowparams.clipy1 = clipy1 - y;
911 }
adamdunkelsfa6f7362004-09-06 06:33:39 +0000912 ctk_80col_windowparams.clipy2 = clipy2 - y + 1;
913 ctk_80col_windowparams.color1 = ctk_80col_theme.windowcolors[focus];
914 ctk_80col_windowparams.color2 = ctk_80col_theme.windowcolors[focus];
915 ctk_80col_windowparams.titlecolor = ctk_80col_theme.windowcolors[focus+1];
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000916 ctk_80col_windowparams.title = window->title;
917 ctk_80col_windowparams.titlelen = window->titlelen/2;
918
919 if(ctk_80col_windowparams.clipy1 < ctk_80col_windowparams.clipy2 &&
920 ctk_80col_windowparams.clipy2 > 0) {
921 ctk_80col_draw_windowborders();
922 }
923 /*
adamdunkelsa726d4f2004-09-05 07:09:41 +0000924 if(y >= clipy1) {
925 cputcxy(x, y, CH_ULCORNER);
oliverschmidt84016062005-03-18 01:09:15 +0000926 gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey());
adamdunkelsa726d4f2004-09-05 07:09:41 +0000927 chline(window->w - (wherex() - x) - 2);
928 cputcxy(x2, y, CH_URCORNER);
929 }
930
931 h = window->h;
932
933 if(clipy1 > y1) {
934 if(clipy1 - y1 < h) {
935 h = clipy1 - y1;
936 y1 = clipy1;
937 } else {
938 h = 0;
939 }
940 }
941
942 if(clipy2 < y1 + h) {
943 if(y1 >= clipy2) {
944 h = 0;
945 } else {
946 h = clipy2 - y1;
947 }
948 }
949
950 cvlinexy(x, y1, h);
951 cvlinexy(x2, y1, h);
952
953 if(y + window->h >= clipy1 &&
954 y + window->h < clipy2) {
955 cputcxy(x, y2, CH_LLCORNER);
956 chlinexy(x1, y2, window->w);
957 cputcxy(x2, y2, CH_LRCORNER);
958 }
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000959 */
adamdunkelsfa6f7362004-09-06 06:33:39 +0000960 if(ctk_mode_get() != CTK_MODE_WINDOWMOVE) {
oliverschmidt6dd844a2004-12-27 22:04:30 +0000961 draw_window_contents(window, focus, clipy1, clipy2,
adamdunkelsfa6f7362004-09-06 06:33:39 +0000962 x1, x2, y + 1, y2);
963 }
adamdunkelsa726d4f2004-09-05 07:09:41 +0000964}
965/*-----------------------------------------------------------------------------------*/
966static void
967s_ctk_draw_dialog(struct ctk_window *dialog)
968{
969 unsigned char x, y;
970 unsigned char i;
971 unsigned char x1, y1, x2, y2;
972
adamdunkelsdea725c2004-09-12 13:25:15 +0000973
adamdunkelsf2cd18a2004-09-05 20:58:13 +0000974 x = dialog->x & 0xfe;
adamdunkelsa726d4f2004-09-05 07:09:41 +0000975 y = dialog->y + 1;
976
977
978 x1 = x + 1;
979 y1 = y + 1;
980 x2 = x1 + dialog->w;
981 y2 = y1 + dialog->h;
982
983
984 /* Draw dialog frame. */
985
adamdunkelsfa6f7362004-09-06 06:33:39 +0000986 /* cvlinexy(x, y1,
adamdunkelsa726d4f2004-09-05 07:09:41 +0000987 dialog->h);
988 cvlinexy(x2, y1,
989 dialog->h);
990
991 chlinexy(x1, y,
992 dialog->w);
993 chlinexy(x1, y2,
994 dialog->w);
995
996 cputcxy(x, y, CH_ULCORNER);
997 cputcxy(x, y2, CH_LLCORNER);
998 cputcxy(x2, y, CH_URCORNER);
999 cputcxy(x2, y2, CH_LRCORNER);
adamdunkelsfa6f7362004-09-06 06:33:39 +00001000 */
1001 gotoxy(x, y);
1002 ctk_80col_windowparams.w = (dialog->w-1)/2;
1003 ctk_80col_windowparams.h = dialog->h;
1004 ctk_80col_windowparams.clipy1 = 0;
1005 ctk_80col_windowparams.clipy2 = SCREEN_HEIGHT;
1006 ctk_80col_windowparams.color1 = ctk_80col_theme.windowcolors[4];
1007 ctk_80col_windowparams.color2 = ctk_80col_theme.windowcolors[4];
1008 ctk_80col_windowparams.titlecolor = ctk_80col_theme.windowcolors[5];
1009
1010 ctk_80col_draw_windowborders();
adamdunkelsa726d4f2004-09-05 07:09:41 +00001011
1012 /* Clear dialog contents. */
adamdunkelsfa6f7362004-09-06 06:33:39 +00001013 color(COLOR_DIALOG);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001014 for(i = y1; i < y2; ++i) {
adamdunkelsfa6f7362004-09-06 06:33:39 +00001015 gotoxy((x1 & 0xfe) + 2, i);
1016 ctk_80col_cclear((dialog->w + 1)/2 - 2);
1017 /* cclearxy(x1, i, dialog->w);*/
adamdunkelsa726d4f2004-09-05 07:09:41 +00001018 }
1019
adamdunkelsdea725c2004-09-12 13:25:15 +00001020 draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, SCREEN_HEIGHT,
adamdunkelsa726d4f2004-09-05 07:09:41 +00001021 x1, x2, y1, y2);
1022}
1023/*-----------------------------------------------------------------------------------*/
1024static void
1025s_ctk_draw_clear(unsigned char y1, unsigned char y2)
1026{
1027 unsigned char i;
adamdunkelsdea725c2004-09-12 13:25:15 +00001028
1029
adamdunkelsa726d4f2004-09-05 07:09:41 +00001030 for(i = y1; i < y2; ++i) {
1031
1032 ctk_80col_clear_line(i);
1033 }
1034}
1035/*-----------------------------------------------------------------------------------*/
1036static void
1037draw_menu(struct ctk_menu *m)
1038{
1039 unsigned char x, x2, y;
adamdunkels4f087742004-09-09 21:45:37 +00001040
1041 color(ctk_80col_theme.openmenucolor);
1042
adamdunkelsa726d4f2004-09-05 07:09:41 +00001043 revers(0);
1044 x = wherex();
1045 _cputs(m->title);
1046 cputc(' ');
1047 x2 = wherex();
adamdunkelsdea725c2004-09-12 13:25:15 +00001048 if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) {
1049 x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH - 2;
adamdunkelsa726d4f2004-09-05 07:09:41 +00001050 }
adamdunkels4f087742004-09-09 21:45:37 +00001051
adamdunkelsa726d4f2004-09-05 07:09:41 +00001052 for(y = 0; y < m->nitems; ++y) {
1053 if(y == m->active) {
adamdunkels4f087742004-09-09 21:45:37 +00001054 color(ctk_80col_theme.activemenucolor);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001055 } else {
adamdunkelsa766bf42004-09-18 20:43:01 +00001056 color(ctk_80col_theme.openmenucolor);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001057 }
1058 gotoxy(x, y + 1);
adamdunkels4f087742004-09-09 21:45:37 +00001059 ctk_80col_cclear(CTK_CONF_MENUWIDTH/2);
1060
1061 gotoxy(x, y + 1);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001062 if(m->items[y].title[0] == '-') {
1063 chline(CTK_CONF_MENUWIDTH);
1064 } else {
adamdunkelsa766bf42004-09-18 20:43:01 +00001065 /* _cputs(m->items[y].title);*/
1066 ctk_80col_cputsn(m->items[y].title, m->items[y].titlelen);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001067 }
adamdunkels4f087742004-09-09 21:45:37 +00001068 /* if(x + CTK_CONF_MENUWIDTH > wherex()) {
adamdunkelsa726d4f2004-09-05 07:09:41 +00001069 cclear(x + CTK_CONF_MENUWIDTH - wherex());
adamdunkels4f087742004-09-09 21:45:37 +00001070 }*/
adamdunkelsa726d4f2004-09-05 07:09:41 +00001071
1072 }
1073 gotoxy(x2, 0);
1074 revers(1);
adamdunkels4f087742004-09-09 21:45:37 +00001075
adamdunkelsa726d4f2004-09-05 07:09:41 +00001076}
1077/*-----------------------------------------------------------------------------------*/
1078static void
1079s_ctk_draw_menus(struct ctk_menus *menus)
1080{
1081 struct ctk_menu *m;
adamdunkelsdea725c2004-09-12 13:25:15 +00001082
1083 memcpy((char *)0xe000, ctk_80col_theme.menuleftpattern, 8);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001084 /* Draw menus */
adamdunkels4f087742004-09-09 21:45:37 +00001085 gotoxy(2, 0);
adamdunkelsa766bf42004-09-18 20:43:01 +00001086
1087 revers(1);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001088 for(m = menus->menus->next; m != NULL; m = m->next) {
adamdunkelsa766bf42004-09-18 20:43:01 +00001089 color(ctk_80col_theme.menucolor);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001090 if(m != menus->open) {
adamdunkelsa766bf42004-09-18 20:43:01 +00001091 /* _cputs(m->title);*/
1092 ctk_80col_cputsn(m->title, m->titlelen);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001093 cputc(' ');
1094 } else {
1095 draw_menu(m);
1096 }
1097 }
1098
adamdunkelsa766bf42004-09-18 20:43:01 +00001099 color(ctk_80col_theme.menucolor);
1100
adamdunkelsdea725c2004-09-12 13:25:15 +00001101 if(wherex() + strlen(menus->desktopmenu->title) + 2 >= SCREEN_WIDTH) {
1102 gotoxy(SCREEN_WIDTH - strlen(menus->desktopmenu->title) - 2, 0);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001103 } else {
adamdunkelsdea725c2004-09-12 13:25:15 +00001104 cclear(SCREEN_WIDTH - wherex() -
adamdunkels4f087742004-09-09 21:45:37 +00001105 strlen(menus->desktopmenu->title) - 2);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001106 }
1107
1108 /* Draw desktopmenu */
1109 if(menus->desktopmenu != menus->open) {
adamdunkelsa766bf42004-09-18 20:43:01 +00001110 ctk_80col_cputsn(menus->desktopmenu->title, menus->desktopmenu->titlelen);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001111 } else {
1112 draw_menu(menus->desktopmenu);
1113 }
1114
adamdunkelsa766bf42004-09-18 20:43:01 +00001115 /* gotoxy(78, 0);
1116 color(ctk_80col_screencolors[0]);
1117 cputc(' ');
1118 cputc(' '); */
1119
adamdunkelsa726d4f2004-09-05 07:09:41 +00001120 revers(0);
adamdunkelsa766bf42004-09-18 20:43:01 +00001121 memcpy((char *)0xe138, ctk_80col_theme.menurightpattern, 8);
adamdunkelsa726d4f2004-09-05 07:09:41 +00001122}
1123/*-----------------------------------------------------------------------------------*/
1124static unsigned char
1125s_ctk_draw_height(void)
1126{
adamdunkelsdea725c2004-09-12 13:25:15 +00001127 return SCREEN_HEIGHT;
adamdunkelsa726d4f2004-09-05 07:09:41 +00001128}
1129/*-----------------------------------------------------------------------------------*/
1130static unsigned char
1131s_ctk_draw_width(void)
1132{
adamdunkelsdea725c2004-09-12 13:25:15 +00001133 return SCREEN_WIDTH;
adamdunkelsa726d4f2004-09-05 07:09:41 +00001134}
1135/*-----------------------------------------------------------------------------------*/
1136static unsigned short
1137s_ctk_mouse_xtoc(unsigned short x)
1138{
1139 return x / 4;
1140}
1141/*-----------------------------------------------------------------------------------*/
1142static unsigned short
1143s_ctk_mouse_ytoc(unsigned short y)
1144{
1145 return y / 8;
1146}
1147/*-----------------------------------------------------------------------------------*/
1148static const struct ctk_draw_service_interface interface =
1149 {CTK_DRAW_SERVICE_VERSION,
1150 1,
1151 1,
1152 1,
1153 s_ctk_draw_init,
1154 s_ctk_draw_clear,
1155 s_ctk_draw_clear_window,
1156 s_ctk_draw_window,
1157 s_ctk_draw_dialog,
1158 s_ctk_draw_widget,
1159 s_ctk_draw_menus,
1160 s_ctk_draw_width,
1161 s_ctk_draw_height,
1162 s_ctk_mouse_xtoc,
1163 s_ctk_mouse_ytoc,
1164 };
1165
1166EK_EVENTHANDLER(eventhandler, ev, data);
1167EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": 80col", EK_PRIO_NORMAL,
1168 eventhandler, NULL, (void *)&interface);
1169
1170/*--------------------------------------------------------------------------*/
1171LOADER_INIT_FUNC(ctk_80col_service_init, arg)
1172{
1173 ek_service_start(CTK_DRAW_SERVICE_NAME, &proc);
1174}
1175/*--------------------------------------------------------------------------*/
1176EK_EVENTHANDLER(eventhandler, ev, data)
1177{
1178 EK_EVENTHANDLER_ARGS(ev, data);
1179
1180 switch(ev) {
1181 case EK_EVENT_INIT:
1182 case EK_EVENT_REPLACE:
adamdunkels4f087742004-09-09 21:45:37 +00001183 s_ctk_draw_init();
adamdunkelsa726d4f2004-09-05 07:09:41 +00001184 ctk_restore();
1185 break;
1186 case EK_EVENT_REQUEST_REPLACE:
adamdunkels81061fe2004-09-12 07:29:00 +00001187 VIC.ctrl1 = 0x1b; /* $D011 */
1188 VIC.addr = 0x17; /* $D018 */
1189 VIC.ctrl2 = 0xc8; /* $D016 */
1190 CIA2.pra = 0x03; /* $DD00 */
adamdunkelsa726d4f2004-09-05 07:09:41 +00001191 ek_replace((struct ek_proc *)data, NULL);
1192 LOADER_UNLOAD();
adamdunkels81061fe2004-09-12 07:29:00 +00001193 break;
1194 case EK_EVENT_REQUEST_EXIT:
1195 quit();
1196 ek_exit();
1197 LOADER_UNLOAD();
adamdunkelsa726d4f2004-09-05 07:09:41 +00001198 break;
1199 }
1200}
1201/*--------------------------------------------------------------------------*/