adamdunkels | 38fb350 | 2004-09-12 20:30:03 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
oliverschmidt | dbd44a1 | 2006-05-28 20:40:16 +0000 | [diff] [blame] | 33 | * $Id: ctk-80col.c,v 1.16 2006/05/28 20:40:16 oliverschmidt Exp $ |
adamdunkels | 38fb350 | 2004-09-12 20:30:03 +0000 | [diff] [blame] | 34 | */ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 35 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 36 | #include "contiki.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 37 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 38 | #include "ctk.h" |
| 39 | #include "ctk-draw.h" |
| 40 | #include "ctk-draw-service.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 41 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 42 | #include "ctk-80col-asm.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 43 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 44 | #include "ctk-80col-theme.h" |
| 45 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 46 | #include <string.h> |
| 47 | |
| 48 | unsigned char ctk_80col_cursx, ctk_80col_cursy; |
| 49 | unsigned char ctk_80col_reversed; |
| 50 | unsigned char ctk_80col_color; |
| 51 | unsigned char *ctk_80col_bitmapptr; |
| 52 | unsigned char ctk_80col_underline = 0; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 53 | |
| 54 | #define SCREEN_HEIGHT 25 |
| 55 | #define SCREEN_WIDTH 80 |
| 56 | |
| 57 | #define SCREENADDR 0xdc00 |
| 58 | #define HIRESADDR 0xe000 |
| 59 | |
| 60 | unsigned char ctk_80col_lefttab[256]; |
| 61 | unsigned char ctk_80col_righttab[256]; |
| 62 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 63 | #define COLOR(bg, fg) ((fg << 4) | (bg)) |
| 64 | |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 65 | #define COLOR_DIALOG 0x01 |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 66 | #define COLOR_FOCUS_WINDOW 0xbf |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 67 | #define COLOR_BACKGROUND_WINDOW 0x0c |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 68 | |
| 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 | |
| 76 | unsigned char ctk_80col_screencolors[25] = |
| 77 | {COLOR(BGCOLOR4,BGCOLOR1), |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 78 | COLOR(BGCOLOR2,BGCOLOR1), |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 79 | 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), |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 89 | COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3), |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 90 | COLOR(BGCOLOR4,1)}; |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 91 | |
| 92 | unsigned char ctk_80col_screenpattern[25*8] = |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 93 | {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 94 | 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, |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 116 | 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00, |
| 117 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 118 | |
| 119 | unsigned 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 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 134 | unsigned short ctk_80col_yhiresaddr[25] = |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 135 | {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 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 149 | |
| 150 | struct 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}, |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 187 | |
| 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), |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 264 | COLOR(COLOR_BLUE, COLOR_WHITE), |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 265 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 266 | COLOR(COLOR_BLACK, COLOR_YELLOW)}, |
| 267 | |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 268 | /* Menu colors. */ |
| 269 | /* unsigned char menucolor,*/ |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 270 | COLOR(COLOR_YELLOW, COLOR_BLACK), |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 271 | |
| 272 | /* openmenucolor, */ |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 273 | COLOR(COLOR_WHITE, COLOR_BLACK), |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 274 | |
| 275 | /* activemenucolor; */ |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 276 | COLOR(COLOR_BLACK, COLOR_WHITE), |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 277 | |
| 278 | }; |
| 279 | char ctk_80col_versionstring[] = CONTIKI_VERSION_STRING; |
| 280 | char ctk_80col_versionstring_len = sizeof(CONTIKI_VERSION_STRING) - 1; |
| 281 | |
| 282 | struct ctk_80col_windowparams ctk_80col_windowparams; |
| 283 | |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 284 | /*---------------------------------------------------------------------------*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 285 | /*void |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 286 | ctk_arch_draw_char(char c, |
| 287 | unsigned char xpos, |
| 288 | unsigned char ypos, |
| 289 | unsigned char reversedflag, |
| 290 | unsigned char color) |
| 291 | { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 292 | ctk_80col_cursx = xpos; |
| 293 | ctk_80col_cursy = ypos; |
| 294 | ctk_80col_reversed = reversedflag; |
| 295 | ctk_80col_color = color; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 296 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 297 | ctk_80col_cputc(c); |
| 298 | }*/ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 299 | /*---------------------------------------------------------------------------*/ |
| 300 | #pragma optimize(push, off) |
| 301 | static void |
| 302 | nmi2(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) |
| 312 | static void |
| 313 | nmi(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) |
| 334 | static void |
| 335 | setup_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 | /*---------------------------------------------------------------------------*/ |
adamdunkels | 81061fe | 2004-09-12 07:29:00 +0000 | [diff] [blame] | 346 | void reset(void); |
| 347 | void |
| 348 | quit(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 | |
adamdunkels | 81061fe | 2004-09-12 07:29:00 +0000 | [diff] [blame] | 360 | } |
| 361 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 362 | #pragma optimize(push, off) |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 363 | static void |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 364 | ctk_80col_init(void) |
| 365 | { |
| 366 | int i; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 367 | |
| 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 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 377 | VIC.bordercolor = 0x06; /* $D020 */ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 378 | 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"); |
adamdunkels | 81061fe | 2004-09-12 07:29:00 +0000 | [diff] [blame] | 387 | asm("lda #$0"); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 388 | 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 | |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 407 | memset((char *)0xe000, 0, 8000); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 408 | |
| 409 | for(i = 0; i < 256; ++i) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 410 | #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 |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 422 | 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)); |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 432 | #endif |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | #if 0 |
| 436 | /* Setup mouse pointer sprite. */ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 437 | asm("lda %v+%w", ctk_80col_theme, |
| 438 | offsetof(struct ctk_80col_theme, pointermaskcolor)); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 439 | asm("sta $d027"); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 440 | asm("lda %v+%w", ctk_80col_theme, |
| 441 | offsetof(struct ctk_80col_theme, pointercolor)); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 442 | asm("sta $d028"); |
| 443 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 444 | ptr1 = ctk_80col_theme.pointer; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 445 | 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 | /*---------------------------------------------------------------------------*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 455 | /*static unsigned char cursx, cursy; |
| 456 | static unsigned char reversed;*/ |
| 457 | |
| 458 | /*-----------------------------------------------------------------------------------*/ |
| 459 | static void CC_FASTCALL |
| 460 | cputc(char c) |
| 461 | { |
| 462 | /* ctk_arch_draw_char(c, cursx, cursy, reversed, 0);*/ |
| 463 | ctk_80col_cputc(c); |
| 464 | /* ++cursx;*/ |
| 465 | } |
| 466 | /*-----------------------------------------------------------------------------------*/ |
| 467 | unsigned char |
| 468 | wherex(void) |
| 469 | { |
| 470 | return ctk_80col_cursx; |
| 471 | } |
| 472 | /*-----------------------------------------------------------------------------------*/ |
| 473 | unsigned char |
| 474 | wherey(void) |
| 475 | { |
| 476 | return ctk_80col_cursy; |
| 477 | } |
| 478 | /*-----------------------------------------------------------------------------------*/ |
| 479 | /*void |
| 480 | clrscr(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 | /*-----------------------------------------------------------------------------------*/ |
| 494 | static 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 | /*-----------------------------------------------------------------------------------*/ |
| 509 | static void CC_FASTCALL |
| 510 | cclear(unsigned char length) |
| 511 | { |
| 512 | int i; |
| 513 | for(i = 0; i < length; ++i) { |
| 514 | cputc(' '); |
| 515 | } |
| 516 | } |
| 517 | /*-----------------------------------------------------------------------------------*/ |
| 518 | void CC_FASTCALL |
| 519 | chline(unsigned char length) |
| 520 | { |
| 521 | int i; |
| 522 | for(i = 0; i < length; ++i) { |
| 523 | cputc('-'); |
| 524 | } |
| 525 | } |
| 526 | /*-----------------------------------------------------------------------------------*/ |
| 527 | void CC_FASTCALL |
| 528 | cvline(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 | /*-----------------------------------------------------------------------------------*/ |
| 538 | void CC_FASTCALL |
| 539 | gotoxy(unsigned char x, unsigned char y) |
| 540 | { |
| 541 | ctk_80col_cursx = x; |
| 542 | ctk_80col_cursy = y; |
| 543 | } |
| 544 | /*-----------------------------------------------------------------------------------*/ |
| 545 | void CC_FASTCALL |
| 546 | cclearxy(unsigned char x, unsigned char y, unsigned char length) |
| 547 | { |
| 548 | gotoxy(x, y); |
| 549 | cclear(length); |
| 550 | } |
| 551 | /*-----------------------------------------------------------------------------------*/ |
| 552 | void CC_FASTCALL |
| 553 | chlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 554 | { |
| 555 | gotoxy(x, y); |
| 556 | chline(length); |
| 557 | } |
| 558 | /*-----------------------------------------------------------------------------------*/ |
| 559 | void CC_FASTCALL |
| 560 | cvlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 561 | { |
| 562 | gotoxy(x, y); |
| 563 | cvline(length); |
| 564 | } |
| 565 | /*-----------------------------------------------------------------------------------*/ |
| 566 | void CC_FASTCALL |
| 567 | _cputsxy(unsigned char x, unsigned char y, char *str) |
| 568 | { |
| 569 | gotoxy(x, y); |
| 570 | _cputs(str); |
| 571 | } |
| 572 | /*-----------------------------------------------------------------------------------*/ |
| 573 | void CC_FASTCALL |
| 574 | cputcxy(unsigned char x, unsigned char y, char c) |
| 575 | { |
| 576 | gotoxy(x, y); |
| 577 | cputc(c); |
| 578 | } |
| 579 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 580 | /*void CC_FASTCALL |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 581 | screensize(unsigned char *x, unsigned char *y) |
| 582 | { |
| 583 | *x = SCREEN_WIDTH; |
| 584 | *y = SCREEN_HEIGHT; |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 585 | }*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 586 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 587 | /*static unsigned char sizex, sizey;*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 588 | /*-----------------------------------------------------------------------------------*/ |
| 589 | static 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 | /*-----------------------------------------------------------------------------------*/ |
| 606 | static void |
| 607 | s_ctk_draw_init(void) |
| 608 | { |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 609 | ctk_80col_init(); |
| 610 | |
| 611 | /* screensize(&sizex, &sizey);*/ |
| 612 | |
| 613 | ctk_draw_clear(0, SCREEN_HEIGHT); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 614 | } |
| 615 | /*-----------------------------------------------------------------------------------*/ |
| 616 | static void |
| 617 | draw_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; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 691 | 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, '>'); |
oliverschmidt | dbd44a1 | 2006-05-28 20:40:16 +0000 | [diff] [blame] | 701 | c = 1; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 702 | for(i = 0; i < w->w; ++i) { |
oliverschmidt | dbd44a1 | 2006-05-28 20:40:16 +0000 | [diff] [blame] | 703 | if(c != 0) { |
| 704 | c = text[i + xscroll]; |
| 705 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 706 | 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 { |
oliverschmidt | 6a7513a | 2005-05-04 22:06:05 +0000 | [diff] [blame] | 720 | if(wfocus != 0 && j == w->widget.textentry.ypos) { |
| 721 | revers(1); |
| 722 | } else { |
| 723 | revers(0); |
| 724 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 725 | 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; |
oliverschmidt | e5a7b9d | 2005-05-05 20:55:26 +0000 | [diff] [blame] | 736 | text += w->widget.textentry.len + 1; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 737 | } |
| 738 | revers(0); |
| 739 | break; |
| 740 | case CTK_WIDGET_ICON: |
| 741 | if(ypos >= clipy1 && ypos < clipy2) { |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 742 | color(ctk_80col_theme.iconcolors[focus]); |
| 743 | |
| 744 | /* if(focus & 1) { |
| 745 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 746 | revers(1); |
| 747 | } else { |
| 748 | revers(0); |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 749 | }*/ |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 750 | /* gotoxy(xpos, ypos);*/ |
| 751 | if(xpos >= 73) { |
| 752 | xpos = 73; |
| 753 | } |
| 754 | if(xpos <= 2) { |
| 755 | xpos = 2; |
| 756 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 757 | if(w->widget.icon.textmap != NULL) { |
| 758 | ctk_80col_bitmapptr = w->widget.icon.bitmap; |
| 759 | for(i = 0; i < 3; ++i) { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 760 | if(ypos >= clipy1 && ypos < clipy2) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 761 | gotoxy(xpos, ypos); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 762 | 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); |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 771 | if(x + len >= SCREEN_WIDTH) { |
| 772 | x = SCREEN_WIDTH - len; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 773 | } |
| 774 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 775 | if(ypos >= clipy1 && ypos < clipy2) { |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 776 | len = strlen(w->widget.icon.title); |
| 777 | gotoxy((x & 0xfe) + 1, ypos); |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 778 | ctk_80col_cclear((len - 1)/ 2); |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 779 | gotoxy(x, ypos); |
| 780 | ctk_80col_cputsn(w->widget.icon.title, len); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 781 | } |
| 782 | revers(0); |
| 783 | } |
| 784 | break; |
| 785 | |
| 786 | default: |
| 787 | break; |
| 788 | } |
| 789 | } |
| 790 | /*-----------------------------------------------------------------------------------*/ |
| 791 | static void |
| 792 | s_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 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 800 | posx = (win->x & 0xfe) + 1; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 801 | 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 | /*-----------------------------------------------------------------------------------*/ |
| 818 | static void |
| 819 | s_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; |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 826 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 827 | if(focus & CTK_FOCUS_WINDOW) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 828 | color(COLOR_FOCUS_WINDOW); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 829 | } else { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 830 | color(COLOR_BACKGROUND_WINDOW); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 831 | } |
| 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) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 837 | gotoxy((window->x & 0xfe) + 1, i); |
| 838 | ctk_80col_cclear((window->w + 1)/2); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | } |
| 842 | /*-----------------------------------------------------------------------------------*/ |
| 843 | static void |
| 844 | draw_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 | /*-----------------------------------------------------------------------------------*/ |
| 877 | static void |
| 878 | s_ctk_draw_window(struct ctk_window *window, unsigned char focus, |
oliverschmidt | 4c59cb0 | 2005-03-15 15:56:07 +0000 | [diff] [blame] | 879 | unsigned char clipy1, unsigned char clipy2, |
| 880 | unsigned char draw_borders) |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 881 | { |
| 882 | unsigned char x, y; |
| 883 | unsigned char h; |
| 884 | unsigned char x1, y1, x2, y2; |
| 885 | |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 886 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 887 | if(window->y + 1 >= clipy2) { |
| 888 | return; |
| 889 | } |
| 890 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 891 | x = window->x & 0xfe; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 892 | y = window->y + 1; |
| 893 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 894 | /* if(focus & CTK_FOCUS_WINDOW) { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 895 | } else { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 896 | }*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 897 | |
| 898 | x1 = x + 1; |
| 899 | y1 = y + 1; |
| 900 | x2 = x1 + window->w; |
| 901 | y2 = y1 + window->h; |
| 902 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 903 | /* 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 | } |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 912 | 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]; |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 916 | 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 | /* |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 924 | if(y >= clipy1) { |
| 925 | cputcxy(x, y, CH_ULCORNER); |
oliverschmidt | 8401606 | 2005-03-18 01:09:15 +0000 | [diff] [blame] | 926 | gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey()); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 927 | 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 | } |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 959 | */ |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 960 | if(ctk_mode_get() != CTK_MODE_WINDOWMOVE) { |
oliverschmidt | 6dd844a | 2004-12-27 22:04:30 +0000 | [diff] [blame] | 961 | draw_window_contents(window, focus, clipy1, clipy2, |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 962 | x1, x2, y + 1, y2); |
| 963 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 964 | } |
| 965 | /*-----------------------------------------------------------------------------------*/ |
| 966 | static void |
| 967 | s_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 | |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 973 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 974 | x = dialog->x & 0xfe; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 975 | 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 | |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 986 | /* cvlinexy(x, y1, |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 987 | 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); |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 1000 | */ |
| 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(); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1011 | |
| 1012 | /* Clear dialog contents. */ |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 1013 | color(COLOR_DIALOG); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1014 | for(i = y1; i < y2; ++i) { |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame] | 1015 | gotoxy((x1 & 0xfe) + 2, i); |
| 1016 | ctk_80col_cclear((dialog->w + 1)/2 - 2); |
| 1017 | /* cclearxy(x1, i, dialog->w);*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1020 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, SCREEN_HEIGHT, |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1021 | x1, x2, y1, y2); |
| 1022 | } |
| 1023 | /*-----------------------------------------------------------------------------------*/ |
| 1024 | static void |
| 1025 | s_ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 1026 | { |
| 1027 | unsigned char i; |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1028 | |
| 1029 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1030 | for(i = y1; i < y2; ++i) { |
| 1031 | |
| 1032 | ctk_80col_clear_line(i); |
| 1033 | } |
| 1034 | } |
| 1035 | /*-----------------------------------------------------------------------------------*/ |
| 1036 | static void |
| 1037 | draw_menu(struct ctk_menu *m) |
| 1038 | { |
| 1039 | unsigned char x, x2, y; |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1040 | |
| 1041 | color(ctk_80col_theme.openmenucolor); |
| 1042 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1043 | revers(0); |
| 1044 | x = wherex(); |
| 1045 | _cputs(m->title); |
| 1046 | cputc(' '); |
| 1047 | x2 = wherex(); |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1048 | if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) { |
| 1049 | x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH - 2; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1050 | } |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1051 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1052 | for(y = 0; y < m->nitems; ++y) { |
| 1053 | if(y == m->active) { |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1054 | color(ctk_80col_theme.activemenucolor); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1055 | } else { |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1056 | color(ctk_80col_theme.openmenucolor); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1057 | } |
| 1058 | gotoxy(x, y + 1); |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1059 | ctk_80col_cclear(CTK_CONF_MENUWIDTH/2); |
| 1060 | |
| 1061 | gotoxy(x, y + 1); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1062 | if(m->items[y].title[0] == '-') { |
| 1063 | chline(CTK_CONF_MENUWIDTH); |
| 1064 | } else { |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1065 | /* _cputs(m->items[y].title);*/ |
| 1066 | ctk_80col_cputsn(m->items[y].title, m->items[y].titlelen); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1067 | } |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1068 | /* if(x + CTK_CONF_MENUWIDTH > wherex()) { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1069 | cclear(x + CTK_CONF_MENUWIDTH - wherex()); |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1070 | }*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1071 | |
| 1072 | } |
| 1073 | gotoxy(x2, 0); |
| 1074 | revers(1); |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1075 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1076 | } |
| 1077 | /*-----------------------------------------------------------------------------------*/ |
| 1078 | static void |
| 1079 | s_ctk_draw_menus(struct ctk_menus *menus) |
| 1080 | { |
| 1081 | struct ctk_menu *m; |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1082 | |
| 1083 | memcpy((char *)0xe000, ctk_80col_theme.menuleftpattern, 8); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1084 | /* Draw menus */ |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1085 | gotoxy(2, 0); |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1086 | |
| 1087 | revers(1); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1088 | for(m = menus->menus->next; m != NULL; m = m->next) { |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1089 | color(ctk_80col_theme.menucolor); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1090 | if(m != menus->open) { |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1091 | /* _cputs(m->title);*/ |
| 1092 | ctk_80col_cputsn(m->title, m->titlelen); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1093 | cputc(' '); |
| 1094 | } else { |
| 1095 | draw_menu(m); |
| 1096 | } |
| 1097 | } |
| 1098 | |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1099 | color(ctk_80col_theme.menucolor); |
| 1100 | |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1101 | if(wherex() + strlen(menus->desktopmenu->title) + 2 >= SCREEN_WIDTH) { |
| 1102 | gotoxy(SCREEN_WIDTH - strlen(menus->desktopmenu->title) - 2, 0); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1103 | } else { |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1104 | cclear(SCREEN_WIDTH - wherex() - |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1105 | strlen(menus->desktopmenu->title) - 2); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /* Draw desktopmenu */ |
| 1109 | if(menus->desktopmenu != menus->open) { |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1110 | ctk_80col_cputsn(menus->desktopmenu->title, menus->desktopmenu->titlelen); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1111 | } else { |
| 1112 | draw_menu(menus->desktopmenu); |
| 1113 | } |
| 1114 | |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1115 | /* gotoxy(78, 0); |
| 1116 | color(ctk_80col_screencolors[0]); |
| 1117 | cputc(' '); |
| 1118 | cputc(' '); */ |
| 1119 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1120 | revers(0); |
adamdunkels | a766bf4 | 2004-09-18 20:43:01 +0000 | [diff] [blame] | 1121 | memcpy((char *)0xe138, ctk_80col_theme.menurightpattern, 8); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1122 | } |
| 1123 | /*-----------------------------------------------------------------------------------*/ |
| 1124 | static unsigned char |
| 1125 | s_ctk_draw_height(void) |
| 1126 | { |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1127 | return SCREEN_HEIGHT; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1128 | } |
| 1129 | /*-----------------------------------------------------------------------------------*/ |
| 1130 | static unsigned char |
| 1131 | s_ctk_draw_width(void) |
| 1132 | { |
adamdunkels | dea725c | 2004-09-12 13:25:15 +0000 | [diff] [blame] | 1133 | return SCREEN_WIDTH; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1134 | } |
| 1135 | /*-----------------------------------------------------------------------------------*/ |
| 1136 | static unsigned short |
| 1137 | s_ctk_mouse_xtoc(unsigned short x) |
| 1138 | { |
| 1139 | return x / 4; |
| 1140 | } |
| 1141 | /*-----------------------------------------------------------------------------------*/ |
| 1142 | static unsigned short |
| 1143 | s_ctk_mouse_ytoc(unsigned short y) |
| 1144 | { |
| 1145 | return y / 8; |
| 1146 | } |
| 1147 | /*-----------------------------------------------------------------------------------*/ |
| 1148 | static 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 | |
| 1166 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 1167 | EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": 80col", EK_PRIO_NORMAL, |
| 1168 | eventhandler, NULL, (void *)&interface); |
| 1169 | |
| 1170 | /*--------------------------------------------------------------------------*/ |
| 1171 | LOADER_INIT_FUNC(ctk_80col_service_init, arg) |
| 1172 | { |
| 1173 | ek_service_start(CTK_DRAW_SERVICE_NAME, &proc); |
| 1174 | } |
| 1175 | /*--------------------------------------------------------------------------*/ |
| 1176 | EK_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: |
adamdunkels | 4f08774 | 2004-09-09 21:45:37 +0000 | [diff] [blame] | 1183 | s_ctk_draw_init(); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1184 | ctk_restore(); |
| 1185 | break; |
| 1186 | case EK_EVENT_REQUEST_REPLACE: |
adamdunkels | 81061fe | 2004-09-12 07:29:00 +0000 | [diff] [blame] | 1187 | VIC.ctrl1 = 0x1b; /* $D011 */ |
| 1188 | VIC.addr = 0x17; /* $D018 */ |
| 1189 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 1190 | CIA2.pra = 0x03; /* $DD00 */ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1191 | ek_replace((struct ek_proc *)data, NULL); |
| 1192 | LOADER_UNLOAD(); |
adamdunkels | 81061fe | 2004-09-12 07:29:00 +0000 | [diff] [blame] | 1193 | break; |
| 1194 | case EK_EVENT_REQUEST_EXIT: |
| 1195 | quit(); |
| 1196 | ek_exit(); |
| 1197 | LOADER_UNLOAD(); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 1198 | break; |
| 1199 | } |
| 1200 | } |
| 1201 | /*--------------------------------------------------------------------------*/ |