adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 1 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 2 | #include "contiki.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 3 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 4 | #include "ctk.h" |
| 5 | #include "ctk-draw.h" |
| 6 | #include "ctk-draw-service.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 7 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 8 | #include "ctk-80col-asm.h" |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 9 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 10 | #include "ctk-80col-theme.h" |
| 11 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 12 | #include <string.h> |
| 13 | |
| 14 | unsigned char ctk_80col_cursx, ctk_80col_cursy; |
| 15 | unsigned char ctk_80col_reversed; |
| 16 | unsigned char ctk_80col_color; |
| 17 | unsigned char *ctk_80col_bitmapptr; |
| 18 | unsigned char ctk_80col_underline = 0; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 19 | |
| 20 | #define SCREEN_HEIGHT 25 |
| 21 | #define SCREEN_WIDTH 80 |
| 22 | |
| 23 | #define SCREENADDR 0xdc00 |
| 24 | #define HIRESADDR 0xe000 |
| 25 | |
| 26 | unsigned char ctk_80col_lefttab[256]; |
| 27 | unsigned char ctk_80col_righttab[256]; |
| 28 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 29 | #define COLOR(bg, fg) ((fg << 4) | (bg)) |
| 30 | |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 31 | #define COLOR_DIALOG 0x01 |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 32 | #define COLOR_FOCUS_WINDOW 0xbf |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 33 | #define COLOR_BACKGROUND_WINDOW 0x0c |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 34 | |
| 35 | #define color(c) ctk_80col_color = c |
| 36 | |
| 37 | #define BGCOLOR1 7 |
| 38 | #define BGCOLOR2 10 |
| 39 | #define BGCOLOR3 4 |
| 40 | #define BGCOLOR4 6 |
| 41 | |
| 42 | unsigned char ctk_80col_screencolors[25] = |
| 43 | {COLOR(BGCOLOR4,BGCOLOR1), |
| 44 | COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1), |
| 45 | COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1), |
| 46 | COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1), |
| 47 | COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1), |
| 48 | COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2), |
| 49 | COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2), |
| 50 | COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2), |
| 51 | COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2), |
| 52 | COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3), |
| 53 | COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3), |
| 54 | COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3), |
| 55 | COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3)}; |
| 56 | |
| 57 | unsigned char ctk_80col_screenpattern[25*8] = |
| 58 | {0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00, |
| 59 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 60 | 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77, |
| 61 | 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55, |
| 62 | 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55, |
| 63 | 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, |
| 64 | 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11, |
| 65 | 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00, |
| 66 | 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00, |
| 67 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 68 | 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77, |
| 69 | 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55, |
| 70 | 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55, |
| 71 | 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, |
| 72 | 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11, |
| 73 | 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00, |
| 74 | 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00, |
| 75 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 76 | 0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77, |
| 77 | 0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55, |
| 78 | 0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55, |
| 79 | 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, |
| 80 | 0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11, |
| 81 | 0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00, |
| 82 | 0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00}; |
| 83 | |
| 84 | unsigned short ctk_80col_yscreenaddr[25] = |
| 85 | {0 * 40 + SCREENADDR, 1 * 40 + SCREENADDR, |
| 86 | 2 * 40 + SCREENADDR, 3 * 40 + SCREENADDR, |
| 87 | 4 * 40 + SCREENADDR, 5 * 40 + SCREENADDR, |
| 88 | 6 * 40 + SCREENADDR, 7 * 40 + SCREENADDR, |
| 89 | 8 * 40 + SCREENADDR, 9 * 40 + SCREENADDR, |
| 90 | 10 * 40 + SCREENADDR, 11 * 40 + SCREENADDR, |
| 91 | 12 * 40 + SCREENADDR, 13 * 40 + SCREENADDR, |
| 92 | 14 * 40 + SCREENADDR, 15 * 40 + SCREENADDR, |
| 93 | 16 * 40 + SCREENADDR, 17 * 40 + SCREENADDR, |
| 94 | 18 * 40 + SCREENADDR, 19 * 40 + SCREENADDR, |
| 95 | 20 * 40 + SCREENADDR, 21 * 40 + SCREENADDR, |
| 96 | 22 * 40 + SCREENADDR, 23 * 40 + SCREENADDR, |
| 97 | 24 * 40 + SCREENADDR}; |
| 98 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 99 | unsigned short ctk_80col_yhiresaddr[25] = |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 100 | {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR, |
| 101 | 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR, |
| 102 | 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR, |
| 103 | 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR, |
| 104 | 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR, |
| 105 | 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR, |
| 106 | 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR, |
| 107 | 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR, |
| 108 | 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR, |
| 109 | 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR, |
| 110 | 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR, |
| 111 | 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR, |
| 112 | 24 * 320 + HIRESADDR}; |
| 113 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 114 | |
| 115 | struct ctk_80col_theme ctk_80col_theme = |
| 116 | { |
| 117 | /* Version string. */ |
| 118 | /* char version[8]; */ |
| 119 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, |
| 120 | |
| 121 | /* Window borders patterns. */ |
| 122 | /* unsigned char ulcorner[8], */ /* Upper left corner. */ |
| 123 | {0xff,0xc0,0x80,0xbf,0x80,0xbf,0x80,0x80}, |
| 124 | |
| 125 | /* titlebar[8], */ /* Title bar pattern. */ |
| 126 | {0xff,0x00,0x00,0xff,0x00,0xff,0x00,0x00}, |
| 127 | |
| 128 | /* urcorner[8], */ /* Upper right corner. */ |
| 129 | {0xff,0x03,0x01,0xfd,0x01,0xfd,0x01,0x01}, |
| 130 | |
| 131 | /* rightborder[8], */ /* Right border. */ |
| 132 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, |
| 133 | |
| 134 | /* lrcorner[8], */ /* Lower right corner. */ |
| 135 | {0x01,0x01,0x01,0x01,0x01,0x01,0x03,0xff}, |
| 136 | |
| 137 | /* lowerborder[8], */ /* Lower border. */ |
| 138 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, |
| 139 | |
| 140 | /* llcorner[8], */ /* Lower left corner. */ |
| 141 | {0x80,0x80,0x80,0x80,0x80,0x80,0xc0,0xff}, |
| 142 | |
| 143 | /* leftborder[8]; */ /* Left border. */ |
| 144 | {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80}, |
| 145 | |
| 146 | /* Button corner patterns. */ |
| 147 | /* unsigned char buttonleft[8], */ |
| 148 | {0xc5,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf}, |
| 149 | |
| 150 | /* buttonright[8]; */ |
| 151 | {0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xa3}, |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 152 | |
| 153 | /* Menu border patterns. */ |
| 154 | /* unsigned char menuleftpattern[8], */ |
| 155 | {0x0f,0x3f,0x3f,0x7f,0x7f,0xff,0xff,0xff}, |
| 156 | |
| 157 | /* menurightpatterns[8]; */ |
| 158 | {0xf0,0xfc,0xfc,0xfe,0xfe,0xff,0xff,0xff}, |
| 159 | |
| 160 | /* Window and widget colors. */ |
| 161 | /* unsigned char windowcolors[6], */ |
| 162 | {COLOR(COLOR_GRAY2, COLOR_BLACK), |
| 163 | COLOR(COLOR_GRAY2, COLOR_BLACK), |
| 164 | COLOR(COLOR_GRAY3, COLOR_GRAY1), |
| 165 | COLOR(COLOR_GRAY3, COLOR_GRAY1), |
| 166 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 167 | COLOR(COLOR_WHITE, COLOR_BLACK)}, |
| 168 | |
| 169 | /* separatorcolors[6], */ |
| 170 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 171 | COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 172 | COLOR(COLOR_GRAY3, COLOR_GRAY2), |
| 173 | COLOR(COLOR_GRAY3, COLOR_GRAY2), |
| 174 | COLOR(COLOR_WHITE, COLOR_GRAY1), |
| 175 | COLOR(COLOR_WHITE, COLOR_GRAY1)}, |
| 176 | |
| 177 | /* labelcolors[6], */ |
| 178 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 179 | COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 180 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 181 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 182 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 183 | COLOR(COLOR_WHITE, COLOR_BLACK)}, |
| 184 | |
| 185 | /* buttoncolors[6], */ |
| 186 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 187 | COLOR(COLOR_GRAY1, COLOR_GRAY2), |
| 188 | COLOR(COLOR_GRAY3, COLOR_GRAY1), |
| 189 | COLOR(COLOR_GRAY1, COLOR_GRAY3), |
| 190 | COLOR(COLOR_GRAY3, COLOR_GRAY1), |
| 191 | COLOR(COLOR_GRAY1, COLOR_GRAY3)}, |
| 192 | |
| 193 | /* hyperlinkcolors[6], */ |
| 194 | {COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE), |
| 195 | COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE), |
| 196 | COLOR(COLOR_WHITE, COLOR_BLUE), |
| 197 | COLOR(COLOR_BLUE, COLOR_WHITE), |
| 198 | COLOR(COLOR_WHITE, COLOR_BLUE), |
| 199 | COLOR(COLOR_BLUE, COLOR_WHITE)}, |
| 200 | |
| 201 | /* textentrycolors[6], */ |
| 202 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 203 | COLOR(COLOR_GRAY2, COLOR_BLACK), |
| 204 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 205 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 206 | COLOR(COLOR_GRAY3, COLOR_BLACK), |
| 207 | COLOR(COLOR_GRAY3, COLOR_BLACK)}, |
| 208 | |
| 209 | /* bitmapcolors[6], */ |
| 210 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 211 | COLOR(COLOR_GRAY1, COLOR_BLACK), |
| 212 | COLOR(COLOR_WHITE, COLOR_GRAY1), |
| 213 | COLOR(COLOR_GRAY3, COLOR_BLACK), |
| 214 | COLOR(COLOR_GRAY3, COLOR_BLACK), |
| 215 | COLOR(COLOR_GRAY3, COLOR_BLACK)}, |
| 216 | |
| 217 | /* textmapcolors[6], */ |
| 218 | {COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 219 | COLOR(COLOR_GRAY2, COLOR_GRAY1), |
| 220 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 221 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 222 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 223 | COLOR(COLOR_WHITE, COLOR_BLACK)}, |
| 224 | |
| 225 | /* iconcolors[6]; */ |
| 226 | {COLOR(COLOR_GRAY3, COLOR_GRAY1), |
| 227 | COLOR(COLOR_GRAY1, COLOR_GRAY2), |
| 228 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 229 | COLOR(COLOR_BLACK, COLOR_YELLOW), |
| 230 | COLOR(COLOR_WHITE, COLOR_BLACK), |
| 231 | COLOR(COLOR_BLACK, COLOR_YELLOW)}, |
| 232 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 233 | |
| 234 | }; |
| 235 | char ctk_80col_versionstring[] = CONTIKI_VERSION_STRING; |
| 236 | char ctk_80col_versionstring_len = sizeof(CONTIKI_VERSION_STRING) - 1; |
| 237 | |
| 238 | struct ctk_80col_windowparams ctk_80col_windowparams; |
| 239 | |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 240 | /*---------------------------------------------------------------------------*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 241 | /*void |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 242 | ctk_arch_draw_char(char c, |
| 243 | unsigned char xpos, |
| 244 | unsigned char ypos, |
| 245 | unsigned char reversedflag, |
| 246 | unsigned char color) |
| 247 | { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 248 | ctk_80col_cursx = xpos; |
| 249 | ctk_80col_cursy = ypos; |
| 250 | ctk_80col_reversed = reversedflag; |
| 251 | ctk_80col_color = color; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 252 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 253 | ctk_80col_cputc(c); |
| 254 | }*/ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 255 | /*---------------------------------------------------------------------------*/ |
| 256 | #pragma optimize(push, off) |
| 257 | static void |
| 258 | nmi2(void) |
| 259 | { |
| 260 | asm("pla"); |
| 261 | asm("sta $01"); |
| 262 | asm("pla"); |
| 263 | asm("rti"); |
| 264 | } |
| 265 | #pragma optimize(pop) |
| 266 | /*---------------------------------------------------------------------------*/ |
| 267 | #pragma optimize(push, off) |
| 268 | static void |
| 269 | nmi(void) |
| 270 | { |
| 271 | asm("sei"); |
| 272 | asm("pha"); |
| 273 | asm("inc $d020"); |
| 274 | asm("lda $01"); |
| 275 | asm("pha"); |
| 276 | asm("lda #$36"); |
| 277 | asm("sta $01"); |
| 278 | asm("lda #>_nmi2"); |
| 279 | asm("pha"); |
| 280 | asm("lda #<_nmi2"); |
| 281 | asm("pha"); |
| 282 | asm("php"); |
| 283 | asm("jmp ($0318)"); |
| 284 | |
| 285 | nmi2(); |
| 286 | } |
| 287 | #pragma optimize(pop) |
| 288 | /*---------------------------------------------------------------------------*/ |
| 289 | #pragma optimize(push, off) |
| 290 | static void |
| 291 | setup_nmi(void) |
| 292 | { |
| 293 | asm("lda #<_nmi"); |
| 294 | asm("sta $fffa"); |
| 295 | asm("lda #>_nmi"); |
| 296 | asm("sta $fffb"); |
| 297 | return; |
| 298 | nmi(); |
| 299 | } |
| 300 | #pragma optimize(pop) |
| 301 | /*---------------------------------------------------------------------------*/ |
| 302 | #pragma optimize(push, off) |
| 303 | void |
| 304 | ctk_80col_init(void) |
| 305 | { |
| 306 | int i; |
| 307 | |
| 308 | |
| 309 | setup_nmi(); |
| 310 | |
| 311 | /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for |
| 312 | hires/colors. */ |
| 313 | VIC.ctrl1 = 0x3b; /* $D011 */ |
| 314 | VIC.addr = 0x78; /* $D018 */ |
| 315 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 316 | CIA2.pra = 0x00; /* $DD00 */ |
| 317 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 318 | VIC.bordercolor = 0x06; /* $D020 */ |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 319 | VIC.bgcolor0 = 0x0b; /* $D021 */ |
| 320 | |
| 321 | /* Fill color memory. */ |
| 322 | asm("sei"); |
| 323 | asm("lda $01"); |
| 324 | asm("pha"); |
| 325 | asm("lda #$30"); |
| 326 | asm("sta $01"); |
| 327 | asm("ldx #0"); |
| 328 | asm("lda #$bf"); |
| 329 | asm("fillcolorloop:"); |
| 330 | asm("sta $dc00,x"); |
| 331 | asm("sta $dd00,x"); |
| 332 | asm("sta $de00,x"); |
| 333 | asm("sta $df00,x"); |
| 334 | asm("inx"); |
| 335 | asm("bne fillcolorloop"); |
| 336 | |
| 337 | /* Setup sprite pointers */ |
| 338 | asm("ldx #$fd"); |
| 339 | asm("stx $dff8"); |
| 340 | asm("inx"); |
| 341 | asm("stx $dff9"); |
| 342 | asm("pla"); |
| 343 | asm("sta $01"); |
| 344 | asm("cli"); |
| 345 | |
| 346 | /* Fill hires memory with 0. */ |
| 347 | |
| 348 | asm("lda $fd"); |
| 349 | asm("pha"); |
| 350 | asm("lda $fe"); |
| 351 | asm("pha"); |
| 352 | asm("lda #0"); |
| 353 | asm("sta $fd"); |
| 354 | asm("lda #$e0"); |
| 355 | asm("sta $fe"); |
| 356 | asm("ldy #0"); |
| 357 | asm("lda #0"); |
| 358 | asm("clrscrnloop:"); |
| 359 | asm("lda #$55"); |
| 360 | asm("sta ($fd),y"); |
| 361 | asm("iny"); |
| 362 | asm("lda #$aa"); |
| 363 | asm("sta ($fd),y"); |
| 364 | asm("iny"); |
| 365 | asm("bne clrscrnloop"); |
| 366 | asm("inc $fe"); |
| 367 | asm("lda $fe"); |
| 368 | asm("cmp #$ff"); |
| 369 | asm("bne clrscrnloop"); |
| 370 | |
| 371 | asm("ldy #$00"); |
| 372 | asm("clrscrnloop2:"); |
| 373 | asm("lda #$55"); |
| 374 | asm("sta $ff00,y"); |
| 375 | asm("iny"); |
| 376 | asm("lda #$aa"); |
| 377 | asm("sta $ff00,y"); |
| 378 | asm("iny"); |
| 379 | asm("cpy #$40"); |
| 380 | asm("bne clrscrnloop2"); |
| 381 | |
| 382 | |
| 383 | asm("pla"); |
| 384 | asm("sta $fe"); |
| 385 | asm("pla"); |
| 386 | asm("sta $fd"); |
| 387 | |
| 388 | |
| 389 | /* ctk_draw_clear(0, 24);*/ |
| 390 | |
| 391 | for(i = 0; i < 256; ++i) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 392 | #if 0 |
| 393 | ctk_80col_lefttab[i] = |
| 394 | ((i & 0x40) << 1) | |
| 395 | ((i & 0x20) << 1) | |
| 396 | ((i & 0x08) << 2) | |
| 397 | ((i & 0x02) << 3); |
| 398 | ctk_80col_righttab[i] = |
| 399 | ((i & 0x40) >> 3) | |
| 400 | ((i & 0x20) >> 3) | |
| 401 | ((i & 0x08) >> 2) | |
| 402 | ((i & 0x02) >> 1); |
| 403 | #else |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 404 | ctk_80col_lefttab[i] = |
| 405 | ((i & 0x40) << 1) | |
| 406 | ((i & 0x10) << 2) | |
| 407 | ((i & 0x04) << 3) | |
| 408 | ((i & 0x01) << 4); |
| 409 | ctk_80col_righttab[i] = |
| 410 | ((i & 0x40) >> 3) | |
| 411 | ((i & 0x10) >> 2) | |
| 412 | ((i & 0x04) >> 1) | |
| 413 | ((i & 0x01)); |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 414 | #endif |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | #if 0 |
| 418 | /* Setup mouse pointer sprite. */ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 419 | asm("lda %v+%w", ctk_80col_theme, |
| 420 | offsetof(struct ctk_80col_theme, pointermaskcolor)); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 421 | asm("sta $d027"); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 422 | asm("lda %v+%w", ctk_80col_theme, |
| 423 | offsetof(struct ctk_80col_theme, pointercolor)); |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 424 | asm("sta $d028"); |
| 425 | |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 426 | ptr1 = ctk_80col_theme.pointer; |
adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame] | 427 | ptr2 = (unsigned char *)0xff40; |
| 428 | |
| 429 | for(i = 0; i < 0x80; ++i) { |
| 430 | *ptr2++ = *ptr1++; |
| 431 | } |
| 432 | #endif |
| 433 | return; |
| 434 | } |
| 435 | #pragma optimize(pop) |
| 436 | /*---------------------------------------------------------------------------*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 437 | /*static unsigned char cursx, cursy; |
| 438 | static unsigned char reversed;*/ |
| 439 | |
| 440 | /*-----------------------------------------------------------------------------------*/ |
| 441 | static void CC_FASTCALL |
| 442 | cputc(char c) |
| 443 | { |
| 444 | /* ctk_arch_draw_char(c, cursx, cursy, reversed, 0);*/ |
| 445 | ctk_80col_cputc(c); |
| 446 | /* ++cursx;*/ |
| 447 | } |
| 448 | /*-----------------------------------------------------------------------------------*/ |
| 449 | unsigned char |
| 450 | wherex(void) |
| 451 | { |
| 452 | return ctk_80col_cursx; |
| 453 | } |
| 454 | /*-----------------------------------------------------------------------------------*/ |
| 455 | unsigned char |
| 456 | wherey(void) |
| 457 | { |
| 458 | return ctk_80col_cursy; |
| 459 | } |
| 460 | /*-----------------------------------------------------------------------------------*/ |
| 461 | /*void |
| 462 | clrscr(void) |
| 463 | { |
| 464 | unsigned char x, y; |
| 465 | |
| 466 | for(x = 0; x < SCREEN_WIDTH; ++x) { |
| 467 | for(y = 0; y < SCREEN_HEIGHT; ++y) { |
| 468 | gotoxy(x, y); |
| 469 | cputc(' '); |
| 470 | } |
| 471 | } |
| 472 | }*/ |
| 473 | /*-----------------------------------------------------------------------------------*/ |
| 474 | #define revers(c) ctk_80col_reversed = c |
| 475 | /*-----------------------------------------------------------------------------------*/ |
| 476 | static void CC_FASTCALL |
| 477 | _cputs(char *str) |
| 478 | { |
| 479 | char *ptr = str; |
| 480 | |
| 481 | while(*ptr != 0) { |
| 482 | cputc(*ptr++); |
| 483 | } |
| 484 | |
| 485 | /* int i; |
| 486 | for(i = 0; i < strlen(str); ++i) { |
| 487 | cputc(str[i]); |
| 488 | }*/ |
| 489 | } |
| 490 | /*-----------------------------------------------------------------------------------*/ |
| 491 | static void CC_FASTCALL |
| 492 | cclear(unsigned char length) |
| 493 | { |
| 494 | int i; |
| 495 | for(i = 0; i < length; ++i) { |
| 496 | cputc(' '); |
| 497 | } |
| 498 | } |
| 499 | /*-----------------------------------------------------------------------------------*/ |
| 500 | void CC_FASTCALL |
| 501 | chline(unsigned char length) |
| 502 | { |
| 503 | int i; |
| 504 | for(i = 0; i < length; ++i) { |
| 505 | cputc('-'); |
| 506 | } |
| 507 | } |
| 508 | /*-----------------------------------------------------------------------------------*/ |
| 509 | void CC_FASTCALL |
| 510 | cvline(unsigned char length) |
| 511 | { |
| 512 | int i; |
| 513 | for(i = 0; i < length; ++i) { |
| 514 | cputc('|'); |
| 515 | --ctk_80col_cursx; |
| 516 | ++ctk_80col_cursy; |
| 517 | } |
| 518 | } |
| 519 | /*-----------------------------------------------------------------------------------*/ |
| 520 | void CC_FASTCALL |
| 521 | gotoxy(unsigned char x, unsigned char y) |
| 522 | { |
| 523 | ctk_80col_cursx = x; |
| 524 | ctk_80col_cursy = y; |
| 525 | } |
| 526 | /*-----------------------------------------------------------------------------------*/ |
| 527 | void CC_FASTCALL |
| 528 | cclearxy(unsigned char x, unsigned char y, unsigned char length) |
| 529 | { |
| 530 | gotoxy(x, y); |
| 531 | cclear(length); |
| 532 | } |
| 533 | /*-----------------------------------------------------------------------------------*/ |
| 534 | void CC_FASTCALL |
| 535 | chlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 536 | { |
| 537 | gotoxy(x, y); |
| 538 | chline(length); |
| 539 | } |
| 540 | /*-----------------------------------------------------------------------------------*/ |
| 541 | void CC_FASTCALL |
| 542 | cvlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 543 | { |
| 544 | gotoxy(x, y); |
| 545 | cvline(length); |
| 546 | } |
| 547 | /*-----------------------------------------------------------------------------------*/ |
| 548 | void CC_FASTCALL |
| 549 | _cputsxy(unsigned char x, unsigned char y, char *str) |
| 550 | { |
| 551 | gotoxy(x, y); |
| 552 | _cputs(str); |
| 553 | } |
| 554 | /*-----------------------------------------------------------------------------------*/ |
| 555 | void CC_FASTCALL |
| 556 | cputcxy(unsigned char x, unsigned char y, char c) |
| 557 | { |
| 558 | gotoxy(x, y); |
| 559 | cputc(c); |
| 560 | } |
| 561 | /*-----------------------------------------------------------------------------------*/ |
| 562 | void CC_FASTCALL |
| 563 | screensize(unsigned char *x, unsigned char *y) |
| 564 | { |
| 565 | *x = SCREEN_WIDTH; |
| 566 | *y = SCREEN_HEIGHT; |
| 567 | } |
| 568 | /*-----------------------------------------------------------------------------------*/ |
| 569 | static unsigned char sizex, sizey; |
| 570 | /*-----------------------------------------------------------------------------------*/ |
| 571 | static void |
| 572 | _cputsn(char *str, unsigned char len) |
| 573 | { |
| 574 | /* char c; |
| 575 | |
| 576 | while(len > 0) { |
| 577 | --len; |
| 578 | c = *str; |
| 579 | if(c == 0) { |
| 580 | break; |
| 581 | } |
| 582 | cputc(c); |
| 583 | ++str; |
| 584 | }*/ |
| 585 | ctk_80col_cputsn(str, len); |
| 586 | } |
| 587 | /*-----------------------------------------------------------------------------------*/ |
| 588 | static void |
| 589 | s_ctk_draw_init(void) |
| 590 | { |
| 591 | screensize(&sizex, &sizey); |
| 592 | ctk_draw_clear(0, sizey); |
| 593 | } |
| 594 | /*-----------------------------------------------------------------------------------*/ |
| 595 | static void |
| 596 | draw_widget(struct ctk_widget *w, |
| 597 | unsigned char x, unsigned char y, |
| 598 | unsigned char clipx, |
| 599 | unsigned char clipy, |
| 600 | unsigned char clipy1, unsigned char clipy2, |
| 601 | unsigned char focus) |
| 602 | { |
| 603 | unsigned char xpos, ypos, xscroll; |
| 604 | unsigned char i, j; |
| 605 | char c, *text; |
| 606 | unsigned char len, wfocus; |
| 607 | |
| 608 | wfocus = 0; |
| 609 | if(focus & CTK_FOCUS_WINDOW) { |
| 610 | if(focus & CTK_FOCUS_WIDGET) { |
| 611 | wfocus = 1; |
| 612 | } |
| 613 | } else if(focus & CTK_FOCUS_DIALOG) { |
| 614 | if(focus & CTK_FOCUS_WIDGET) { |
| 615 | wfocus = 1; |
| 616 | } |
| 617 | } else { |
| 618 | } |
| 619 | |
| 620 | xpos = x + w->x; |
| 621 | ypos = y + w->y; |
| 622 | |
| 623 | switch(w->type) { |
| 624 | case CTK_WIDGET_SEPARATOR: |
| 625 | if(ypos >= clipy1 && ypos < clipy2) { |
| 626 | chlinexy(xpos, ypos, w->w); |
| 627 | } |
| 628 | break; |
| 629 | case CTK_WIDGET_LABEL: |
| 630 | text = w->widget.label.text; |
| 631 | for(i = 0; i < w->h; ++i) { |
| 632 | if(ypos >= clipy1 && ypos < clipy2) { |
| 633 | gotoxy(xpos, ypos); |
| 634 | _cputsn(text, w->w); |
| 635 | if(w->w - (wherex() - xpos) > 0) { |
| 636 | cclear(w->w - (wherex() - xpos)); |
| 637 | } |
| 638 | } |
| 639 | ++ypos; |
| 640 | text += w->w; |
| 641 | } |
| 642 | break; |
| 643 | case CTK_WIDGET_BUTTON: |
| 644 | if(ypos >= clipy1 && ypos < clipy2) { |
| 645 | if(wfocus != 0) { |
| 646 | revers(1); |
| 647 | } else { |
| 648 | revers(0); |
| 649 | } |
| 650 | cputcxy(xpos, ypos, '['); |
| 651 | _cputsn(w->widget.button.text, w->w); |
| 652 | cputc(']'); |
| 653 | revers(0); |
| 654 | } |
| 655 | break; |
| 656 | case CTK_WIDGET_HYPERLINK: |
| 657 | if(ypos >= clipy1 && ypos < clipy2) { |
| 658 | if(wfocus != 0) { |
| 659 | revers(0); |
| 660 | } else { |
| 661 | revers(1); |
| 662 | } |
| 663 | gotoxy(xpos, ypos); |
| 664 | _cputsn(w->widget.button.text, w->w); |
| 665 | revers(0); |
| 666 | } |
| 667 | break; |
| 668 | case CTK_WIDGET_TEXTENTRY: |
| 669 | text = w->widget.textentry.text; |
| 670 | if(wfocus != 0) { |
| 671 | revers(1); |
| 672 | } else { |
| 673 | revers(0); |
| 674 | } |
| 675 | xscroll = 0; |
| 676 | if(w->widget.textentry.xpos >= w->w - 1) { |
| 677 | xscroll = w->widget.textentry.xpos - w->w + 1; |
| 678 | } |
| 679 | for(j = 0; j < w->h; ++j) { |
| 680 | if(ypos >= clipy1 && ypos < clipy2) { |
| 681 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && |
| 682 | w->widget.textentry.ypos == j) { |
| 683 | revers(0); |
| 684 | cputcxy(xpos, ypos, '>'); |
| 685 | for(i = 0; i < w->w; ++i) { |
| 686 | c = text[i + xscroll]; |
| 687 | if(i == w->widget.textentry.xpos - xscroll) { |
| 688 | revers(1); |
| 689 | } else { |
| 690 | revers(0); |
| 691 | } |
| 692 | if(c == 0) { |
| 693 | cputc(' '); |
| 694 | } else { |
| 695 | cputc(c); |
| 696 | } |
| 697 | revers(0); |
| 698 | } |
| 699 | cputc('<'); |
| 700 | } else { |
| 701 | cvlinexy(xpos, ypos, 1); |
| 702 | gotoxy(xpos + 1, ypos); |
| 703 | _cputsn(text, w->w); |
| 704 | i = wherex(); |
| 705 | if(i - xpos - 1 < w->w) { |
| 706 | cclear(w->w - (i - xpos) + 1); |
| 707 | } |
| 708 | cvline(1); |
| 709 | } |
| 710 | } |
| 711 | ++ypos; |
| 712 | text += w->w; |
| 713 | } |
| 714 | revers(0); |
| 715 | break; |
| 716 | case CTK_WIDGET_ICON: |
| 717 | if(ypos >= clipy1 && ypos < clipy2) { |
| 718 | if(focus & 1) { |
| 719 | revers(1); |
| 720 | } else { |
| 721 | revers(0); |
| 722 | } |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 723 | /* gotoxy(xpos, ypos);*/ |
| 724 | if(xpos >= 73) { |
| 725 | xpos = 73; |
| 726 | } |
| 727 | if(xpos <= 2) { |
| 728 | xpos = 2; |
| 729 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 730 | if(w->widget.icon.textmap != NULL) { |
| 731 | ctk_80col_bitmapptr = w->widget.icon.bitmap; |
| 732 | for(i = 0; i < 3; ++i) { |
| 733 | gotoxy(xpos, ypos); |
| 734 | if(ypos >= clipy1 && ypos < clipy2) { |
| 735 | /* cputc(w->widget.icon.textmap[0 + 3 * i]); |
| 736 | cputc(w->widget.icon.textmap[1 + 3 * i]); |
| 737 | cputc(w->widget.icon.textmap[2 + 3 * i]);*/ |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 738 | gotoxy(xpos, ypos); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 739 | ctk_80col_draw_bitmapline(3); |
| 740 | } |
| 741 | ctk_80col_bitmapptr += 3 * 8; |
| 742 | ++ypos; |
| 743 | } |
| 744 | } |
| 745 | x = xpos; |
| 746 | |
| 747 | len = strlen(w->widget.icon.title); |
| 748 | if(x + len >= sizex) { |
| 749 | x = sizex - len; |
| 750 | } |
| 751 | |
| 752 | gotoxy(x, ypos); |
| 753 | if(ypos >= clipy1 && ypos < clipy2) { |
| 754 | _cputs(w->widget.icon.title); |
| 755 | } |
| 756 | revers(0); |
| 757 | } |
| 758 | break; |
| 759 | |
| 760 | default: |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | /*-----------------------------------------------------------------------------------*/ |
| 765 | static void |
| 766 | s_ctk_draw_widget(struct ctk_widget *w, |
| 767 | unsigned char focus, |
| 768 | unsigned char clipy1, |
| 769 | unsigned char clipy2) |
| 770 | { |
| 771 | struct ctk_window *win = w->window; |
| 772 | unsigned char posx, posy; |
| 773 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 774 | posx = (win->x & 0xfe) + 1; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 775 | posy = win->y + 2; |
| 776 | |
| 777 | if(w == win->focused) { |
| 778 | focus |= CTK_FOCUS_WIDGET; |
| 779 | } |
| 780 | |
| 781 | draw_widget(w, posx, posy, |
| 782 | posx + win->w, |
| 783 | posy + win->h, |
| 784 | clipy1, clipy2, |
| 785 | focus); |
| 786 | |
| 787 | #ifdef CTK_CONIO_CONF_UPDATE |
| 788 | CTK_CONIO_CONF_UPDATE(); |
| 789 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 790 | } |
| 791 | /*-----------------------------------------------------------------------------------*/ |
| 792 | static void |
| 793 | s_ctk_draw_clear_window(struct ctk_window *window, |
| 794 | unsigned char focus, |
| 795 | unsigned char clipy1, |
| 796 | unsigned char clipy2) |
| 797 | { |
| 798 | unsigned char i; |
| 799 | unsigned char h; |
| 800 | |
| 801 | if(focus & CTK_FOCUS_WINDOW) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 802 | color(COLOR_FOCUS_WINDOW); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 803 | } else { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 804 | color(COLOR_BACKGROUND_WINDOW); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | h = window->y + 2 + window->h; |
| 808 | /* Clear window contents. */ |
| 809 | for(i = window->y + 2; i < h; ++i) { |
| 810 | if(i >= clipy1 && i < clipy2) { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 811 | gotoxy((window->x & 0xfe) + 1, i); |
| 812 | ctk_80col_cclear((window->w + 1)/2); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | } |
| 816 | /*-----------------------------------------------------------------------------------*/ |
| 817 | static void |
| 818 | draw_window_contents(struct ctk_window *window, unsigned char focus, |
| 819 | unsigned char clipy1, unsigned char clipy2, |
| 820 | unsigned char x1, unsigned char x2, |
| 821 | unsigned char y1, unsigned char y2) |
| 822 | { |
| 823 | struct ctk_widget *w; |
| 824 | unsigned char wfocus; |
| 825 | |
| 826 | /* Draw inactive widgets. */ |
| 827 | for(w = window->inactive; w != NULL; w = w->next) { |
| 828 | draw_widget(w, x1, y1, x2, y2, |
| 829 | clipy1, clipy2, |
| 830 | focus); |
| 831 | } |
| 832 | |
| 833 | /* Draw active widgets. */ |
| 834 | for(w = window->active; w != NULL; w = w->next) { |
| 835 | wfocus = focus; |
| 836 | if(w == window->focused) { |
| 837 | wfocus |= CTK_FOCUS_WIDGET; |
| 838 | } |
| 839 | |
| 840 | draw_widget(w, x1, y1, x2, y2, |
| 841 | clipy1, clipy2, |
| 842 | wfocus); |
| 843 | } |
| 844 | |
| 845 | #ifdef CTK_CONIO_CONF_UPDATE |
| 846 | CTK_CONIO_CONF_UPDATE(); |
| 847 | #endif /* CTK_CONIO_CONF_UPDATE */ |
| 848 | |
| 849 | } |
| 850 | /*-----------------------------------------------------------------------------------*/ |
| 851 | static void |
| 852 | s_ctk_draw_window(struct ctk_window *window, unsigned char focus, |
| 853 | unsigned char clipy1, unsigned char clipy2) |
| 854 | { |
| 855 | unsigned char x, y; |
| 856 | unsigned char h; |
| 857 | unsigned char x1, y1, x2, y2; |
| 858 | |
| 859 | if(window->y + 1 >= clipy2) { |
| 860 | return; |
| 861 | } |
| 862 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 863 | x = window->x & 0xfe; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 864 | y = window->y + 1; |
| 865 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 866 | /* if(focus & CTK_FOCUS_WINDOW) { |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 867 | } else { |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 868 | }*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 869 | |
| 870 | x1 = x + 1; |
| 871 | y1 = y + 1; |
| 872 | x2 = x1 + window->w; |
| 873 | y2 = y1 + window->h; |
| 874 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 875 | /* Draw window frame. */ |
| 876 | gotoxy(x, y); |
| 877 | ctk_80col_windowparams.w = (window->w-1)/2; |
| 878 | ctk_80col_windowparams.h = window->h; |
| 879 | if(clipy1 < y) { |
| 880 | ctk_80col_windowparams.clipy1 = 0; |
| 881 | } else { |
| 882 | ctk_80col_windowparams.clipy1 = clipy1 - y; |
| 883 | } |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 884 | ctk_80col_windowparams.clipy2 = clipy2 - y + 1; |
| 885 | ctk_80col_windowparams.color1 = ctk_80col_theme.windowcolors[focus]; |
| 886 | ctk_80col_windowparams.color2 = ctk_80col_theme.windowcolors[focus]; |
| 887 | ctk_80col_windowparams.titlecolor = ctk_80col_theme.windowcolors[focus+1]; |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 888 | ctk_80col_windowparams.title = window->title; |
| 889 | ctk_80col_windowparams.titlelen = window->titlelen/2; |
| 890 | |
| 891 | if(ctk_80col_windowparams.clipy1 < ctk_80col_windowparams.clipy2 && |
| 892 | ctk_80col_windowparams.clipy2 > 0) { |
| 893 | ctk_80col_draw_windowborders(); |
| 894 | } |
| 895 | /* |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 896 | if(y >= clipy1) { |
| 897 | cputcxy(x, y, CH_ULCORNER); |
| 898 | gotoxy(wherex() + window->titlelen + 2, wherey()); |
| 899 | chline(window->w - (wherex() - x) - 2); |
| 900 | cputcxy(x2, y, CH_URCORNER); |
| 901 | } |
| 902 | |
| 903 | h = window->h; |
| 904 | |
| 905 | if(clipy1 > y1) { |
| 906 | if(clipy1 - y1 < h) { |
| 907 | h = clipy1 - y1; |
| 908 | y1 = clipy1; |
| 909 | } else { |
| 910 | h = 0; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | if(clipy2 < y1 + h) { |
| 915 | if(y1 >= clipy2) { |
| 916 | h = 0; |
| 917 | } else { |
| 918 | h = clipy2 - y1; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | cvlinexy(x, y1, h); |
| 923 | cvlinexy(x2, y1, h); |
| 924 | |
| 925 | if(y + window->h >= clipy1 && |
| 926 | y + window->h < clipy2) { |
| 927 | cputcxy(x, y2, CH_LLCORNER); |
| 928 | chlinexy(x1, y2, window->w); |
| 929 | cputcxy(x2, y2, CH_LRCORNER); |
| 930 | } |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 931 | */ |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 932 | if(ctk_mode_get() != CTK_MODE_WINDOWMOVE) { |
| 933 | draw_window_contents(window, focus & CTK_FOCUS_WINDOW, clipy1, clipy2, |
| 934 | x1, x2, y + 1, y2); |
| 935 | } |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 936 | } |
| 937 | /*-----------------------------------------------------------------------------------*/ |
| 938 | static void |
| 939 | s_ctk_draw_dialog(struct ctk_window *dialog) |
| 940 | { |
| 941 | unsigned char x, y; |
| 942 | unsigned char i; |
| 943 | unsigned char x1, y1, x2, y2; |
| 944 | |
| 945 | |
adamdunkels | f2cd18a | 2004-09-05 20:58:13 +0000 | [diff] [blame] | 946 | x = dialog->x & 0xfe; |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 947 | y = dialog->y + 1; |
| 948 | |
| 949 | |
| 950 | x1 = x + 1; |
| 951 | y1 = y + 1; |
| 952 | x2 = x1 + dialog->w; |
| 953 | y2 = y1 + dialog->h; |
| 954 | |
| 955 | |
| 956 | /* Draw dialog frame. */ |
| 957 | |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 958 | /* cvlinexy(x, y1, |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 959 | dialog->h); |
| 960 | cvlinexy(x2, y1, |
| 961 | dialog->h); |
| 962 | |
| 963 | chlinexy(x1, y, |
| 964 | dialog->w); |
| 965 | chlinexy(x1, y2, |
| 966 | dialog->w); |
| 967 | |
| 968 | cputcxy(x, y, CH_ULCORNER); |
| 969 | cputcxy(x, y2, CH_LLCORNER); |
| 970 | cputcxy(x2, y, CH_URCORNER); |
| 971 | cputcxy(x2, y2, CH_LRCORNER); |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 972 | */ |
| 973 | gotoxy(x, y); |
| 974 | ctk_80col_windowparams.w = (dialog->w-1)/2; |
| 975 | ctk_80col_windowparams.h = dialog->h; |
| 976 | ctk_80col_windowparams.clipy1 = 0; |
| 977 | ctk_80col_windowparams.clipy2 = SCREEN_HEIGHT; |
| 978 | ctk_80col_windowparams.color1 = ctk_80col_theme.windowcolors[4]; |
| 979 | ctk_80col_windowparams.color2 = ctk_80col_theme.windowcolors[4]; |
| 980 | ctk_80col_windowparams.titlecolor = ctk_80col_theme.windowcolors[5]; |
| 981 | |
| 982 | ctk_80col_draw_windowborders(); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 983 | |
| 984 | /* Clear dialog contents. */ |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 985 | color(COLOR_DIALOG); |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 986 | for(i = y1; i < y2; ++i) { |
adamdunkels | fa6f736 | 2004-09-06 06:33:39 +0000 | [diff] [blame^] | 987 | gotoxy((x1 & 0xfe) + 2, i); |
| 988 | ctk_80col_cclear((dialog->w + 1)/2 - 2); |
| 989 | /* cclearxy(x1, i, dialog->w);*/ |
adamdunkels | a726d4f | 2004-09-05 07:09:41 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, |
| 993 | x1, x2, y1, y2); |
| 994 | } |
| 995 | /*-----------------------------------------------------------------------------------*/ |
| 996 | static void |
| 997 | s_ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 998 | { |
| 999 | unsigned char i; |
| 1000 | |
| 1001 | for(i = y1; i < y2; ++i) { |
| 1002 | |
| 1003 | ctk_80col_clear_line(i); |
| 1004 | } |
| 1005 | } |
| 1006 | /*-----------------------------------------------------------------------------------*/ |
| 1007 | static void |
| 1008 | draw_menu(struct ctk_menu *m) |
| 1009 | { |
| 1010 | unsigned char x, x2, y; |
| 1011 | revers(0); |
| 1012 | x = wherex(); |
| 1013 | _cputs(m->title); |
| 1014 | cputc(' '); |
| 1015 | x2 = wherex(); |
| 1016 | if(x + CTK_CONF_MENUWIDTH > sizex) { |
| 1017 | x = sizex - CTK_CONF_MENUWIDTH; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | for(y = 0; y < m->nitems; ++y) { |
| 1022 | if(y == m->active) { |
| 1023 | revers(0); |
| 1024 | } else { |
| 1025 | revers(1); |
| 1026 | } |
| 1027 | gotoxy(x, y + 1); |
| 1028 | if(m->items[y].title[0] == '-') { |
| 1029 | chline(CTK_CONF_MENUWIDTH); |
| 1030 | } else { |
| 1031 | _cputs(m->items[y].title); |
| 1032 | } |
| 1033 | if(x + CTK_CONF_MENUWIDTH > wherex()) { |
| 1034 | cclear(x + CTK_CONF_MENUWIDTH - wherex()); |
| 1035 | } |
| 1036 | |
| 1037 | } |
| 1038 | gotoxy(x2, 0); |
| 1039 | revers(1); |
| 1040 | } |
| 1041 | /*-----------------------------------------------------------------------------------*/ |
| 1042 | static void |
| 1043 | s_ctk_draw_menus(struct ctk_menus *menus) |
| 1044 | { |
| 1045 | struct ctk_menu *m; |
| 1046 | |
| 1047 | /* Draw menus */ |
| 1048 | gotoxy(0, 0); |
| 1049 | revers(1); |
| 1050 | cputc(' '); |
| 1051 | for(m = menus->menus->next; m != NULL; m = m->next) { |
| 1052 | if(m != menus->open) { |
| 1053 | _cputs(m->title); |
| 1054 | cputc(' '); |
| 1055 | } else { |
| 1056 | draw_menu(m); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) { |
| 1062 | gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); |
| 1063 | } else { |
| 1064 | cclear(sizex - wherex() - |
| 1065 | strlen(menus->desktopmenu->title) - 1); |
| 1066 | } |
| 1067 | |
| 1068 | /* Draw desktopmenu */ |
| 1069 | if(menus->desktopmenu != menus->open) { |
| 1070 | _cputs(menus->desktopmenu->title); |
| 1071 | cputc(' '); |
| 1072 | } else { |
| 1073 | draw_menu(menus->desktopmenu); |
| 1074 | } |
| 1075 | |
| 1076 | revers(0); |
| 1077 | } |
| 1078 | /*-----------------------------------------------------------------------------------*/ |
| 1079 | static unsigned char |
| 1080 | s_ctk_draw_height(void) |
| 1081 | { |
| 1082 | return sizey; |
| 1083 | } |
| 1084 | /*-----------------------------------------------------------------------------------*/ |
| 1085 | static unsigned char |
| 1086 | s_ctk_draw_width(void) |
| 1087 | { |
| 1088 | return sizex; |
| 1089 | } |
| 1090 | /*-----------------------------------------------------------------------------------*/ |
| 1091 | static unsigned short |
| 1092 | s_ctk_mouse_xtoc(unsigned short x) |
| 1093 | { |
| 1094 | return x / 4; |
| 1095 | } |
| 1096 | /*-----------------------------------------------------------------------------------*/ |
| 1097 | static unsigned short |
| 1098 | s_ctk_mouse_ytoc(unsigned short y) |
| 1099 | { |
| 1100 | return y / 8; |
| 1101 | } |
| 1102 | /*-----------------------------------------------------------------------------------*/ |
| 1103 | static const struct ctk_draw_service_interface interface = |
| 1104 | {CTK_DRAW_SERVICE_VERSION, |
| 1105 | 1, |
| 1106 | 1, |
| 1107 | 1, |
| 1108 | s_ctk_draw_init, |
| 1109 | s_ctk_draw_clear, |
| 1110 | s_ctk_draw_clear_window, |
| 1111 | s_ctk_draw_window, |
| 1112 | s_ctk_draw_dialog, |
| 1113 | s_ctk_draw_widget, |
| 1114 | s_ctk_draw_menus, |
| 1115 | s_ctk_draw_width, |
| 1116 | s_ctk_draw_height, |
| 1117 | s_ctk_mouse_xtoc, |
| 1118 | s_ctk_mouse_ytoc, |
| 1119 | }; |
| 1120 | |
| 1121 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 1122 | EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME ": 80col", EK_PRIO_NORMAL, |
| 1123 | eventhandler, NULL, (void *)&interface); |
| 1124 | |
| 1125 | /*--------------------------------------------------------------------------*/ |
| 1126 | LOADER_INIT_FUNC(ctk_80col_service_init, arg) |
| 1127 | { |
| 1128 | ek_service_start(CTK_DRAW_SERVICE_NAME, &proc); |
| 1129 | } |
| 1130 | /*--------------------------------------------------------------------------*/ |
| 1131 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 1132 | { |
| 1133 | EK_EVENTHANDLER_ARGS(ev, data); |
| 1134 | |
| 1135 | switch(ev) { |
| 1136 | case EK_EVENT_INIT: |
| 1137 | case EK_EVENT_REPLACE: |
| 1138 | ctk_80col_init(); |
| 1139 | ctk_restore(); |
| 1140 | break; |
| 1141 | case EK_EVENT_REQUEST_REPLACE: |
| 1142 | ek_replace((struct ek_proc *)data, NULL); |
| 1143 | LOADER_UNLOAD(); |
| 1144 | break; |
| 1145 | } |
| 1146 | } |
| 1147 | /*--------------------------------------------------------------------------*/ |