adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, 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 |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * This file is part of the "ctk" console GUI toolkit for cc65 |
| 31 | * |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 32 | * $Id: ctk-hires.c,v 1.12 2004/07/18 13:19:47 oliverschmidt Exp $ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 35 | |
adamdunkels | 1036722 | 2004-02-24 09:50:58 +0000 | [diff] [blame] | 36 | #include "contiki-version.h" |
| 37 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 38 | #include "ctk.h" |
| 39 | #include "ctk-draw.h" |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 40 | #include "ctk-hires.h" |
| 41 | #include "ctk-hires-asm.h" |
| 42 | |
| 43 | #include "ctk-hires-theme.h" |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 44 | |
| 45 | #include <string.h> |
| 46 | |
| 47 | #ifndef NULL |
| 48 | #define NULL (void *)0 |
| 49 | #endif /* NULL */ |
| 50 | |
| 51 | #define SCREEN_HEIGHT 25 |
| 52 | #define SCREEN_WIDTH 40 |
| 53 | |
| 54 | #define SCREENADDR 0xdc00 |
| 55 | #define HIRESADDR 0xe000 |
| 56 | |
| 57 | static unsigned char lineptr; |
| 58 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 59 | unsigned char ctk_hires_cursx, ctk_hires_cursy; |
| 60 | unsigned char ctk_hires_reversed; |
| 61 | unsigned char ctk_hires_color; |
| 62 | unsigned char ctk_hires_underline; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 63 | |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 64 | /*static unsigned char cchar; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 65 | |
| 66 | static unsigned char tmp01; |
| 67 | static unsigned char tmph, tmpl, tmpborder; |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 68 | static unsigned char *tmpptr;*/ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | static unsigned char x, y, i; |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 72 | /*static unsigned char h;*/ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 73 | static unsigned char wfocus; |
| 74 | static unsigned char x1, y1, x2, y2; |
| 75 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 76 | struct ctk_hires_windowparams ctk_hires_windowparams; |
| 77 | unsigned char *ctk_hires_bitmapptr; |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 78 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 79 | unsigned char ctk_draw_windowborder_height = 1; |
| 80 | unsigned char ctk_draw_windowborder_width = 1; |
| 81 | unsigned char ctk_draw_windowtitle_height = 1; |
| 82 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 83 | /*-----------------------------------------------------------------------------------*/ |
| 84 | /* Tables. */ |
| 85 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 86 | unsigned short ctk_hires_yscreenaddr[25] = |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 87 | {0 * SCREEN_WIDTH + SCREENADDR, 1 * SCREEN_WIDTH + SCREENADDR, |
| 88 | 2 * SCREEN_WIDTH + SCREENADDR, 3 * SCREEN_WIDTH + SCREENADDR, |
| 89 | 4 * SCREEN_WIDTH + SCREENADDR, 5 * SCREEN_WIDTH + SCREENADDR, |
| 90 | 6 * SCREEN_WIDTH + SCREENADDR, 7 * SCREEN_WIDTH + SCREENADDR, |
| 91 | 8 * SCREEN_WIDTH + SCREENADDR, 9 * SCREEN_WIDTH + SCREENADDR, |
| 92 | 10 * SCREEN_WIDTH + SCREENADDR, 11 * SCREEN_WIDTH + SCREENADDR, |
| 93 | 12 * SCREEN_WIDTH + SCREENADDR, 13 * SCREEN_WIDTH + SCREENADDR, |
| 94 | 14 * SCREEN_WIDTH + SCREENADDR, 15 * SCREEN_WIDTH + SCREENADDR, |
| 95 | 16 * SCREEN_WIDTH + SCREENADDR, 17 * SCREEN_WIDTH + SCREENADDR, |
| 96 | 18 * SCREEN_WIDTH + SCREENADDR, 19 * SCREEN_WIDTH + SCREENADDR, |
| 97 | 20 * SCREEN_WIDTH + SCREENADDR, 21 * SCREEN_WIDTH + SCREENADDR, |
| 98 | 22 * SCREEN_WIDTH + SCREENADDR, 23 * SCREEN_WIDTH + SCREENADDR, |
| 99 | 24 * SCREEN_WIDTH + SCREENADDR}; |
| 100 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 101 | unsigned short ctk_hires_yhiresaddr[25] = |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 102 | {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR, |
| 103 | 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR, |
| 104 | 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR, |
| 105 | 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR, |
| 106 | 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR, |
| 107 | 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR, |
| 108 | 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR, |
| 109 | 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR, |
| 110 | 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR, |
| 111 | 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR, |
| 112 | 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR, |
| 113 | 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR, |
| 114 | 24 * 320 + HIRESADDR}; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 115 | extern struct ctk_hires_theme ctk_hires_theme; |
| 116 | struct ctk_hires_theme *ctk_hires_theme_ptr = &ctk_hires_theme; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 117 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 118 | #define hires_wherex() ctk_hires_cursx |
| 119 | #define hires_revers(c) ctk_hires_reversed = c |
| 120 | #define hires_color(c) ctk_hires_color = c |
| 121 | #define hires_underline(c) ctk_hires_underline = c |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 122 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 123 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 124 | hires_cvline(unsigned char length) |
| 125 | { |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 126 | static unsigned char i; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 127 | |
| 128 | for(i = 0; i < length; ++i) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 129 | ctk_hires_cputc('|'); |
| 130 | --ctk_hires_cursx; |
| 131 | ++ctk_hires_cursy; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 135 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 136 | hires_gotoxy(unsigned char x, unsigned char y) |
| 137 | { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 138 | ctk_hires_cursx = x; |
| 139 | ctk_hires_cursy = y; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 140 | } |
| 141 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 142 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 143 | hires_cclearxy(unsigned char x, unsigned char y, unsigned char length) |
| 144 | { |
| 145 | hires_gotoxy(x, y); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 146 | ctk_hires_cclear(length); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 147 | } |
| 148 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 149 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 150 | hires_chlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 151 | { |
| 152 | hires_gotoxy(x, y); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 153 | ctk_hires_chline(length); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 154 | } |
| 155 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 156 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 157 | hires_cvlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 158 | { |
| 159 | hires_gotoxy(x, y); |
| 160 | hires_cvline(length); |
| 161 | } |
| 162 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 163 | static void __fastcall__ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 164 | hires_cputcxy(unsigned char x, unsigned char y, char c) |
| 165 | { |
| 166 | hires_gotoxy(x, y); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 167 | ctk_hires_cputc(c); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 168 | } |
| 169 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 170 | #pragma optimize(push, off) |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 171 | static void |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 172 | clear_line(unsigned char line) |
| 173 | { |
| 174 | lineptr = line; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 175 | asm("lda %v", lineptr); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 176 | asm("asl"); |
| 177 | asm("tax"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 178 | asm("lda %v,x", ctk_hires_yhiresaddr); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 179 | asm("sta ptr2"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 180 | asm("lda %v+1,x", ctk_hires_yhiresaddr); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 181 | asm("sta ptr2+1"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 182 | asm("lda %v,x", ctk_hires_yscreenaddr); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 183 | asm("sta ptr1"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 184 | asm("lda %v+1,x", ctk_hires_yscreenaddr); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 185 | asm("sta ptr1+1"); |
| 186 | |
| 187 | |
| 188 | asm("sei"); |
| 189 | asm("lda $01"); |
| 190 | asm("pha"); |
| 191 | asm("lda #$30"); |
| 192 | asm("sta $01"); |
| 193 | asm("ldy #39"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 194 | asm("ldx %v", lineptr); |
| 195 | asm("lda %v+%w,x", ctk_hires_theme, |
| 196 | offsetof(struct ctk_hires_theme, backgroundpatterncolors)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 197 | asm("clearlineloop1:"); |
| 198 | asm("sta (ptr1),y"); |
| 199 | asm("dey"); |
| 200 | asm("bpl clearlineloop1"); |
| 201 | asm("pla"); |
| 202 | asm("sta $01"); |
| 203 | asm("cli"); |
| 204 | |
| 205 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 206 | asm("lda %v", lineptr); |
| 207 | /* asm("and #7");*/ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 208 | asm("asl"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 209 | asm("asl"); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 210 | asm("asl"); |
| 211 | asm("tax"); |
| 212 | asm("ldy #0"); |
| 213 | asm("clearlineloop2:"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 214 | asm("lda %v+%w+0,x", ctk_hires_theme, |
| 215 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 216 | asm("sta (ptr2),y"); |
| 217 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 218 | asm("lda %v+%w+1,x", ctk_hires_theme, |
| 219 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 220 | asm("sta (ptr2),y"); |
| 221 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 222 | asm("lda %v+%w+2,x", ctk_hires_theme, |
| 223 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 224 | asm("sta (ptr2),y"); |
| 225 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 226 | asm("lda %v+%w+3,x", ctk_hires_theme, |
| 227 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 228 | asm("sta (ptr2),y"); |
| 229 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 230 | asm("lda %v+%w+4,x", ctk_hires_theme, |
| 231 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 232 | asm("sta (ptr2),y"); |
| 233 | asm("iny"); |
| 234 | asm("lda %v+%w+5,x", ctk_hires_theme, |
| 235 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 236 | asm("sta (ptr2),y"); |
| 237 | asm("iny"); |
| 238 | asm("lda %v+%w+6,x", ctk_hires_theme, |
| 239 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 240 | asm("sta (ptr2),y"); |
| 241 | asm("iny"); |
| 242 | asm("lda %v+%w+7,x", ctk_hires_theme, |
| 243 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 244 | asm("sta (ptr2),y"); |
| 245 | asm("iny"); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 246 | asm("bne clearlineloop2"); |
| 247 | |
| 248 | asm("inc ptr2+1"); |
| 249 | |
| 250 | asm("ldy #0"); |
| 251 | asm("clearlineloop3:"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 252 | asm("lda %v+%w+0,x", ctk_hires_theme, |
| 253 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 254 | asm("sta (ptr2),y"); |
| 255 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 256 | asm("lda %v+%w+1,x", ctk_hires_theme, |
| 257 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 258 | asm("sta (ptr2),y"); |
| 259 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 260 | asm("lda %v+%w+2,x", ctk_hires_theme, |
| 261 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 262 | asm("sta (ptr2),y"); |
| 263 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 264 | asm("lda %v+%w+3,x", ctk_hires_theme, |
| 265 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 266 | asm("sta (ptr2),y"); |
| 267 | asm("iny"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 268 | asm("lda %v+%w+4,x", ctk_hires_theme, |
| 269 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 270 | asm("sta (ptr2),y"); |
| 271 | asm("iny"); |
| 272 | asm("lda %v+%w+5,x", ctk_hires_theme, |
| 273 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 274 | asm("sta (ptr2),y"); |
| 275 | asm("iny"); |
| 276 | asm("lda %v+%w+6,x", ctk_hires_theme, |
| 277 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 278 | asm("sta (ptr2),y"); |
| 279 | asm("iny"); |
| 280 | asm("lda %v+%w+7,x", ctk_hires_theme, |
| 281 | offsetof(struct ctk_hires_theme, backgroundpattern)); |
| 282 | asm("sta (ptr2),y"); |
| 283 | asm("iny"); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 284 | asm("cpy #$40"); |
| 285 | asm("bne clearlineloop3"); |
adamdunkels | 1de1f84 | 2004-02-16 20:57:36 +0000 | [diff] [blame] | 286 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 287 | |
adamdunkels | 1de1f84 | 2004-02-16 20:57:36 +0000 | [diff] [blame] | 288 | if(lineptr == 24) { |
adamdunkels | 1de1f84 | 2004-02-16 20:57:36 +0000 | [diff] [blame] | 289 | hires_color(ctk_hires_theme.backgroundpatterncolors[24]); |
| 290 | hires_gotoxy(0, 24); |
| 291 | ctk_hires_cputsn(CONTIKI_VERSION_STRING, |
| 292 | sizeof(CONTIKI_VERSION_STRING) - 1); |
| 293 | } |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 294 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 295 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 296 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 297 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 298 | static void |
| 299 | nmi2(void) |
| 300 | { |
| 301 | asm("pla"); |
| 302 | asm("sta $01"); |
| 303 | asm("pla"); |
| 304 | asm("rti"); |
| 305 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 306 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 307 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 308 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 309 | static void |
| 310 | nmi(void) |
| 311 | { |
| 312 | asm("sei"); |
| 313 | asm("pha"); |
| 314 | asm("inc $d020"); |
| 315 | asm("lda $01"); |
| 316 | asm("pha"); |
| 317 | asm("lda #$36"); |
| 318 | asm("sta $01"); |
| 319 | asm("lda #>_nmi2"); |
| 320 | asm("pha"); |
| 321 | asm("lda #<_nmi2"); |
| 322 | asm("pha"); |
| 323 | asm("php"); |
| 324 | asm("jmp ($0318)"); |
| 325 | |
| 326 | nmi2(); |
| 327 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 328 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 329 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 330 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 331 | static void |
| 332 | setup_nmi(void) |
| 333 | { |
| 334 | asm("lda #<_nmi"); |
| 335 | asm("sta $fffa"); |
| 336 | asm("lda #>_nmi"); |
| 337 | asm("sta $fffb"); |
| 338 | return; |
| 339 | nmi(); |
| 340 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 341 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 342 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 343 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 344 | void |
| 345 | ctk_draw_init(void) |
| 346 | { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 347 | unsigned char i, *ptr1, *ptr2; |
| 348 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 349 | setup_nmi(); |
| 350 | |
| 351 | /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for |
| 352 | hires/colors. */ |
| 353 | VIC.ctrl1 = 0x3b; /* $D011 */ |
| 354 | VIC.addr = 0x78; /* $D018 */ |
| 355 | VIC.ctrl2 = 0xc8; /* $D016 */ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 356 | CIA2.pra = 0x00; /* $DD00 */ |
| 357 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 358 | VIC.bordercolor = ctk_hires_theme.bordercolor; /* $D020 */ |
| 359 | VIC.bgcolor0 = ctk_hires_theme.screencolor; /* $D021 */ |
| 360 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 361 | /* Fill color memory. */ |
| 362 | asm("sei"); |
| 363 | asm("lda $01"); |
| 364 | asm("pha"); |
| 365 | asm("lda #$30"); |
| 366 | asm("sta $01"); |
| 367 | asm("ldx #0"); |
| 368 | asm("lda #$c0"); |
| 369 | asm("fillcolorloop:"); |
| 370 | asm("sta $dc00,x"); |
| 371 | asm("sta $dd00,x"); |
| 372 | asm("sta $de00,x"); |
| 373 | asm("sta $df00,x"); |
| 374 | asm("inx"); |
| 375 | asm("bne fillcolorloop"); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 376 | |
| 377 | /* Setup sprite pointers */ |
| 378 | asm("ldx #$fd"); |
| 379 | asm("stx $dff8"); |
| 380 | asm("inx"); |
| 381 | asm("stx $dff9"); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 382 | asm("pla"); |
| 383 | asm("sta $01"); |
| 384 | asm("cli"); |
| 385 | |
| 386 | /* Fill hires memory with 0. */ |
| 387 | |
| 388 | asm("lda $fd"); |
| 389 | asm("pha"); |
| 390 | asm("lda $fe"); |
| 391 | asm("pha"); |
| 392 | asm("lda #0"); |
| 393 | asm("sta $fd"); |
| 394 | asm("lda #$e0"); |
| 395 | asm("sta $fe"); |
| 396 | asm("ldy #0"); |
| 397 | asm("lda #0"); |
| 398 | asm("clrscrnloop:"); |
| 399 | asm("lda #$55"); |
| 400 | asm("sta ($fd),y"); |
| 401 | asm("iny"); |
| 402 | asm("lda #$aa"); |
| 403 | asm("sta ($fd),y"); |
| 404 | asm("iny"); |
| 405 | asm("bne clrscrnloop"); |
| 406 | asm("inc $fe"); |
| 407 | asm("lda $fe"); |
| 408 | asm("cmp #$ff"); |
| 409 | asm("bne clrscrnloop"); |
| 410 | |
| 411 | asm("ldy #$00"); |
| 412 | asm("clrscrnloop2:"); |
| 413 | asm("lda #$55"); |
| 414 | asm("sta $ff00,y"); |
| 415 | asm("iny"); |
| 416 | asm("lda #$aa"); |
| 417 | asm("sta $ff00,y"); |
| 418 | asm("iny"); |
| 419 | asm("cpy #$40"); |
| 420 | asm("bne clrscrnloop2"); |
| 421 | |
| 422 | |
| 423 | asm("pla"); |
| 424 | asm("sta $fe"); |
| 425 | asm("pla"); |
| 426 | asm("sta $fd"); |
| 427 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 428 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 429 | ctk_draw_clear(0, SCREEN_HEIGHT); |
| 430 | |
| 431 | /* Setup mouse pointer sprite. */ |
| 432 | asm("lda %v+%w", ctk_hires_theme, |
| 433 | offsetof(struct ctk_hires_theme, pointermaskcolor)); |
| 434 | asm("sta $d027"); |
| 435 | asm("lda %v+%w", ctk_hires_theme, |
| 436 | offsetof(struct ctk_hires_theme, pointercolor)); |
| 437 | asm("sta $d028"); |
| 438 | |
| 439 | ptr1 = ctk_hires_theme.pointer; |
| 440 | ptr2 = (unsigned char *)0xff40; |
| 441 | |
| 442 | for(i = 0; i < 0x80; ++i) { |
| 443 | *ptr2++ = *ptr1++; |
| 444 | } |
| 445 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 446 | return; |
| 447 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 448 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 449 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | c1c84be | 2003-08-09 13:26:22 +0000 | [diff] [blame] | 450 | static void __fastcall__ |
adamdunkels | d742208 | 2003-08-05 13:57:01 +0000 | [diff] [blame] | 451 | draw_widget(register struct ctk_widget *w, |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 452 | unsigned char x, unsigned char y, |
| 453 | unsigned char clipy1, unsigned char clipy2, |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 454 | unsigned char afocus) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 455 | { |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 456 | static unsigned char xpos, ypos, xscroll; |
| 457 | static unsigned char i; |
| 458 | static char c; |
| 459 | static unsigned char len; |
adamdunkels | d388da1 | 2003-08-20 19:55:25 +0000 | [diff] [blame] | 460 | static unsigned char tmp; |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 461 | static unsigned char yclipped; |
| 462 | static unsigned char focus; |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 463 | char *text; |
| 464 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 465 | xpos = x + w->x; |
adamdunkels | d388da1 | 2003-08-20 19:55:25 +0000 | [diff] [blame] | 466 | ypos = y + w->y; |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 467 | |
| 468 | yclipped = 0; |
| 469 | if(ypos >= clipy1 && ypos < clipy2) { |
| 470 | yclipped = 1; |
| 471 | } |
| 472 | focus = afocus; |
| 473 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 474 | |
| 475 | switch(w->type) { |
| 476 | case CTK_WIDGET_SEPARATOR: |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 477 | hires_color(ctk_hires_theme.separatorcolors[focus]); |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 478 | if(yclipped) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 479 | hires_chlinexy(xpos, ypos, w->w); |
| 480 | } |
| 481 | break; |
| 482 | case CTK_WIDGET_LABEL: |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 483 | hires_color(ctk_hires_theme.labelcolors[focus]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 484 | text = w->widget.label.text; |
adamdunkels | 4134361 | 2003-07-31 23:23:25 +0000 | [diff] [blame] | 485 | for(i = 0; i < w->h; ++i) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 486 | if(ypos >= clipy1 && ypos < clipy2) { |
| 487 | hires_gotoxy(xpos, ypos); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 488 | ctk_hires_cputsn(text, w->w); |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 489 | tmp = w->w - (hires_wherex() - xpos); |
| 490 | if(tmp > 0) { |
| 491 | ctk_hires_cclear(tmp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | ++ypos; |
| 495 | text += w->w; |
| 496 | } |
| 497 | break; |
| 498 | case CTK_WIDGET_BUTTON: |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 499 | if(yclipped) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 500 | hires_color(ctk_hires_theme.buttonleftcolors[focus]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 501 | hires_gotoxy(xpos, ypos); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 502 | ctk_hires_draw_buttonleft(); |
| 503 | hires_color(ctk_hires_theme.buttoncolors[focus]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 504 | hires_gotoxy(xpos + 1, ypos); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 505 | ctk_hires_cputsn(w->widget.button.text, w->w); |
| 506 | hires_color(ctk_hires_theme.buttonrightcolors[focus]); |
| 507 | ctk_hires_draw_buttonright(); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 508 | } |
| 509 | break; |
| 510 | case CTK_WIDGET_HYPERLINK: |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 511 | if(yclipped) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 512 | hires_color(ctk_hires_theme.hyperlinkcolors[focus]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 513 | hires_underline(1); |
| 514 | hires_gotoxy(xpos, ypos); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 515 | ctk_hires_cputsn(w->widget.button.text, w->w); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 516 | hires_underline(0); |
| 517 | } |
| 518 | break; |
| 519 | case CTK_WIDGET_TEXTENTRY: |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 520 | if(yclipped) { |
| 521 | hires_color(ctk_hires_theme.textentrycolors[focus]); |
| 522 | |
| 523 | if((focus & CTK_FOCUS_WIDGET) && |
| 524 | w->widget.textentry.state != CTK_TEXTENTRY_EDIT) { |
| 525 | hires_revers(1); |
| 526 | } else { |
| 527 | hires_revers(0); |
| 528 | } |
| 529 | xscroll = 0; |
| 530 | tmp = w->w - 1; |
| 531 | if(w->widget.textentry.xpos >= tmp) { |
| 532 | xscroll = w->widget.textentry.xpos - tmp; |
| 533 | } |
| 534 | text = w->widget.textentry.text; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 535 | if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT) { |
| 536 | hires_revers(0); |
| 537 | hires_cputcxy(xpos, ypos, '>'); |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 538 | text += xscroll; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 539 | for(i = 0; i < w->w; ++i) { |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 540 | c = *text; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 541 | if(i == w->widget.textentry.xpos - xscroll) { |
| 542 | hires_revers(1); |
| 543 | } else { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 544 | hires_revers(0); |
| 545 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 546 | if(c == 0) { |
| 547 | ctk_hires_cputc(' '); |
| 548 | } else { |
| 549 | ctk_hires_cputc(c); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 550 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 551 | hires_revers(0); |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 552 | ++text; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 553 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 554 | ctk_hires_cputc('<'); |
| 555 | } else { |
| 556 | hires_cputcxy(xpos, ypos, '|'); |
| 557 | /* hires_gotoxy(xpos + 1, ypos); */ |
| 558 | ctk_hires_cputsn(text, w->w); |
| 559 | i = hires_wherex(); |
adamdunkels | d388da1 | 2003-08-20 19:55:25 +0000 | [diff] [blame] | 560 | tmp = i - xpos - 1; |
| 561 | if(tmp < w->w) { |
| 562 | ctk_hires_cclear(w->w - tmp); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 563 | } |
| 564 | ctk_hires_cputc('|'); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 565 | } |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 566 | } |
| 567 | hires_revers(0); |
| 568 | break; |
| 569 | case CTK_WIDGET_ICON: |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 570 | if(yclipped) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 571 | hires_color(ctk_hires_theme.iconcolors[focus]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 572 | |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 573 | x = xpos; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 574 | len = strlen(w->widget.icon.title); |
| 575 | if(x + len >= SCREEN_WIDTH) { |
| 576 | x = SCREEN_WIDTH - len; |
| 577 | } |
adamdunkels | d388da1 | 2003-08-20 19:55:25 +0000 | [diff] [blame] | 578 | |
| 579 | tmp = ypos + 3; |
| 580 | |
| 581 | if(tmp < clipy2) { |
| 582 | hires_gotoxy(x, tmp); |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 583 | ctk_hires_cputsn(w->widget.icon.title, len); |
| 584 | } |
| 585 | |
| 586 | hires_gotoxy(xpos, ypos); |
| 587 | if(w->widget.icon.bitmap != NULL) { |
| 588 | ctk_hires_bitmapptr = w->widget.icon.bitmap; |
| 589 | for(i = 0; i < 3; ++i) { |
| 590 | if(ypos >= clipy1 && ypos < clipy2) { |
| 591 | hires_gotoxy(xpos, ypos); |
| 592 | ctk_hires_draw_bitmapline(3); |
| 593 | } |
| 594 | ctk_hires_bitmapptr += 3 * 8; |
| 595 | ++ypos; |
| 596 | } |
| 597 | |
| 598 | /* draw_bitmap_icon(w->widget.icon.bitmap);*/ |
| 599 | } |
| 600 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 601 | } |
| 602 | break; |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 603 | case CTK_WIDGET_BITMAP: |
| 604 | hires_color(ctk_hires_theme.bitmapcolors[focus]); |
| 605 | ctk_hires_bitmapptr = w->widget.bitmap.bitmap; |
adamdunkels | 4134361 | 2003-07-31 23:23:25 +0000 | [diff] [blame] | 606 | for(i = 0; i < w->h; ++i) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 607 | if(ypos >= clipy1 && ypos < clipy2) { |
| 608 | hires_gotoxy(xpos, ypos); |
| 609 | ctk_hires_draw_bitmapline(w->w); |
| 610 | } |
| 611 | ctk_hires_bitmapptr += w->w * 8; |
| 612 | ++ypos; |
| 613 | } |
| 614 | break; |
| 615 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 616 | default: |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | /*-----------------------------------------------------------------------------------*/ |
| 621 | void |
| 622 | ctk_draw_widget(struct ctk_widget *w, |
| 623 | unsigned char focus, |
| 624 | unsigned char clipy1, |
| 625 | unsigned char clipy2) |
| 626 | { |
| 627 | struct ctk_window *win = w->window; |
| 628 | unsigned char posx, posy; |
| 629 | |
| 630 | posx = win->x + 1; |
| 631 | posy = win->y + 2; |
| 632 | |
| 633 | if(w == win->focused) { |
| 634 | focus |= CTK_FOCUS_WIDGET; |
| 635 | } |
| 636 | |
| 637 | draw_widget(w, posx, posy, |
| 638 | clipy1, clipy2, |
| 639 | focus); |
| 640 | } |
| 641 | /*-----------------------------------------------------------------------------------*/ |
| 642 | void |
adamdunkels | d742208 | 2003-08-05 13:57:01 +0000 | [diff] [blame] | 643 | ctk_draw_clear_window(register struct ctk_window *window, |
adamdunkels | a6e7a8e | 2003-04-08 19:12:02 +0000 | [diff] [blame] | 644 | unsigned char focus, |
| 645 | unsigned char clipy1, |
| 646 | unsigned char clipy2) |
| 647 | { |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 648 | static unsigned char h; |
adamdunkels | a6e7a8e | 2003-04-08 19:12:02 +0000 | [diff] [blame] | 649 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 650 | hires_color(ctk_hires_theme.windowcolors[focus]); |
adamdunkels | a6e7a8e | 2003-04-08 19:12:02 +0000 | [diff] [blame] | 651 | |
| 652 | h = window->y + 2 + window->h; |
| 653 | /* Clear window contents. */ |
| 654 | for(i = window->y + 2; i < h; ++i) { |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 655 | if(i >= clipy1 && i <= clipy2) { |
adamdunkels | a6e7a8e | 2003-04-08 19:12:02 +0000 | [diff] [blame] | 656 | hires_cclearxy(window->x + 1, i, window->w); |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | /*-----------------------------------------------------------------------------------*/ |
| 661 | void |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 662 | ctk_draw_window(register struct ctk_window *window, |
| 663 | unsigned char focus, |
| 664 | unsigned char clipy1, unsigned char clipy2) |
| 665 | { |
| 666 | register struct ctk_widget *w; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 667 | x = window->x; |
| 668 | y = window->y + 1; |
| 669 | |
| 670 | ++clipy2; |
| 671 | |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 672 | if(clipy2 <= y) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 673 | return; |
| 674 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 675 | |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 676 | /* hires_color(ctk_hires_theme.windowcolors[focus+1]);*/ |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 677 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 678 | x1 = x + 1; |
| 679 | y1 = y + 1; |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 680 | /* x2 = x1 + window->w; |
| 681 | y2 = y1 + window->h;*/ |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 682 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 683 | hires_gotoxy(x, y); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 684 | ctk_hires_windowparams.w = window->w; |
| 685 | ctk_hires_windowparams.h = window->h; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 686 | if(clipy1 < y) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 687 | ctk_hires_windowparams.clipy1 = 0; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 688 | } else { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 689 | ctk_hires_windowparams.clipy1 = clipy1 - y; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 690 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 691 | ctk_hires_windowparams.clipy2 = clipy2 - y; |
| 692 | ctk_hires_windowparams.color1 = ctk_hires_theme.windowcolors[focus+1]; |
| 693 | ctk_hires_windowparams.color2 = ctk_hires_theme.windowcolors[focus]; |
| 694 | ctk_hires_windowparams.title = window->title; |
| 695 | ctk_hires_windowparams.titlelen = window->titlelen; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 696 | |
adamdunkels | 9e046b4 | 2003-04-24 17:05:41 +0000 | [diff] [blame] | 697 | if(ctk_hires_windowparams.clipy1 < ctk_hires_windowparams.clipy2 && |
| 698 | ctk_hires_windowparams.clipy2 > 0) { |
| 699 | ctk_hires_draw_windowborders(); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 700 | } |
adamdunkels | 4134361 | 2003-07-31 23:23:25 +0000 | [diff] [blame] | 701 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 702 | focus = focus & CTK_FOCUS_WINDOW; |
| 703 | |
| 704 | /* Draw inactive widgets. */ |
| 705 | for(w = window->inactive; w != NULL; w = w->next) { |
| 706 | draw_widget(w, x1, y1, |
| 707 | clipy1, clipy2, |
| 708 | focus); |
| 709 | } |
| 710 | |
| 711 | /* Draw active widgets. */ |
| 712 | for(w = window->active; w != NULL; w = w->next) { |
| 713 | wfocus = focus; |
| 714 | if(w == window->focused) { |
| 715 | wfocus |= CTK_FOCUS_WIDGET; |
| 716 | } |
| 717 | draw_widget(w, x1, y1, |
| 718 | clipy1, clipy2, |
| 719 | wfocus); |
| 720 | } |
| 721 | } |
| 722 | /*-----------------------------------------------------------------------------------*/ |
| 723 | void |
| 724 | ctk_draw_dialog(register struct ctk_window *dialog) |
| 725 | { |
| 726 | register struct ctk_widget *w; |
| 727 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 728 | hires_color(ctk_hires_theme.windowcolors[CTK_FOCUS_DIALOG]); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 729 | |
| 730 | /* x = (SCREEN_WIDTH - dialog->w) / 2; |
| 731 | y = (SCREEN_HEIGHT - 1 - dialog->h) / 2; */ |
| 732 | x = dialog->x; |
| 733 | y = dialog->y + 1; |
| 734 | |
| 735 | |
| 736 | x1 = x + 1; |
| 737 | y1 = y + 1; |
| 738 | x2 = x1 + dialog->w; |
| 739 | y2 = y1 + dialog->h; |
| 740 | |
| 741 | |
| 742 | /* Draw dialog frame. */ |
| 743 | |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 744 | hires_cvlinexy(x, y1, dialog->h); |
| 745 | hires_cvlinexy(x2, y1, dialog->h); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 746 | |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 747 | hires_chlinexy(x1, y, dialog->w); |
| 748 | hires_chlinexy(x1, y2, dialog->w); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 749 | |
| 750 | hires_cputcxy(x, y, CH_ULCORNER); |
| 751 | hires_cputcxy(x, y2, CH_LLCORNER); |
| 752 | hires_cputcxy(x2, y, CH_URCORNER); |
| 753 | hires_cputcxy(x2, y2, CH_LRCORNER); |
| 754 | |
| 755 | |
| 756 | /* Clear window contents. */ |
adamdunkels | 97c19b7 | 2003-08-24 22:29:41 +0000 | [diff] [blame] | 757 | for(i = y1; i < y2; ++i) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 758 | hires_cclearxy(x1, i, dialog->w); |
| 759 | } |
| 760 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 761 | /* Draw inactive widgets. */ |
| 762 | for(w = dialog->inactive; w != NULL; w = w->next) { |
| 763 | draw_widget(w, x1, y1, |
| 764 | 0, SCREEN_HEIGHT, CTK_FOCUS_DIALOG); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | /* Draw active widgets. */ |
| 769 | for(w = dialog->active; w != NULL; w = w->next) { |
| 770 | wfocus = CTK_FOCUS_DIALOG; |
| 771 | if(w == dialog->focused) { |
| 772 | wfocus |= CTK_FOCUS_WIDGET; |
| 773 | } |
| 774 | draw_widget(w, x1, y1, |
| 775 | 0, SCREEN_HEIGHT, wfocus); |
| 776 | } |
| 777 | |
| 778 | } |
| 779 | /*-----------------------------------------------------------------------------------*/ |
| 780 | void |
| 781 | ctk_draw_clear(unsigned char y1, unsigned char y2) |
| 782 | { |
| 783 | for(i = y1; i < y2; ++i) { |
| 784 | clear_line(i); |
| 785 | } |
| 786 | } |
| 787 | /*-----------------------------------------------------------------------------------*/ |
| 788 | static void |
adamdunkels | d742208 | 2003-08-05 13:57:01 +0000 | [diff] [blame] | 789 | draw_menu(register struct ctk_menu *m) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 790 | { |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 791 | static unsigned char x, x2, y; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 792 | |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 793 | hires_color(ctk_hires_theme.openmenucolor); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 794 | x = hires_wherex(); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 795 | ctk_hires_cputsn(m->title, m->titlelen); |
| 796 | ctk_hires_cputc(' '); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 797 | x2 = hires_wherex(); |
| 798 | if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) { |
| 799 | x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH; |
| 800 | } |
| 801 | for(y = 0; y < m->nitems; ++y) { |
| 802 | if(y == m->active) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 803 | hires_color(ctk_hires_theme.activemenucolor); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 804 | } else { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 805 | hires_color(ctk_hires_theme.menucolor); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 806 | } |
| 807 | hires_gotoxy(x, y + 1); |
| 808 | if(m->items[y].title[0] == '-') { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 809 | ctk_hires_chline(CTK_CONF_MENUWIDTH); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 810 | } else { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 811 | ctk_hires_cputsn(m->items[y].title, |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 812 | strlen(m->items[y].title)); |
| 813 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 814 | ctk_hires_cclear(x + CTK_CONF_MENUWIDTH - hires_wherex()); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 815 | hires_revers(0); |
| 816 | } |
| 817 | hires_gotoxy(x2, 0); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 818 | hires_color(ctk_hires_theme.menucolor); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 819 | } |
| 820 | /*-----------------------------------------------------------------------------------*/ |
| 821 | void |
| 822 | ctk_draw_menus(struct ctk_menus *menus) |
| 823 | { |
| 824 | struct ctk_menu *m; |
adamdunkels | 23b30d5 | 2003-08-15 18:46:25 +0000 | [diff] [blame] | 825 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 826 | /* Draw menus */ |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 827 | hires_color(ctk_hires_theme.menucolor); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 828 | hires_gotoxy(0, 0); |
| 829 | hires_revers(0); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 830 | ctk_hires_cputc(' '); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 831 | for(m = menus->menus->next; m != NULL; m = m->next) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 832 | if(m != menus->open) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 833 | ctk_hires_cputsn(m->title, m->titlelen); |
| 834 | ctk_hires_cputc(' '); |
adamdunkels | 4134361 | 2003-07-31 23:23:25 +0000 | [diff] [blame] | 835 | } else { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 836 | draw_menu(m); |
| 837 | } |
| 838 | } |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 839 | ctk_hires_cclear(SCREEN_WIDTH - hires_wherex() - |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 840 | strlen(menus->desktopmenu->title) - 1); |
| 841 | |
| 842 | /* Draw desktopmenu */ |
| 843 | if(menus->desktopmenu != menus->open) { |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 844 | ctk_hires_cputsn(menus->desktopmenu->title, |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 845 | menus->desktopmenu->titlelen); |
adamdunkels | 77e4706 | 2003-04-17 15:09:31 +0000 | [diff] [blame] | 846 | ctk_hires_cputc(' '); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 847 | } else { |
| 848 | draw_menu(menus->desktopmenu); |
| 849 | } |
| 850 | |
| 851 | } |
| 852 | /*-----------------------------------------------------------------------------------*/ |
| 853 | unsigned char |
| 854 | ctk_draw_height(void) |
| 855 | { |
| 856 | return SCREEN_HEIGHT; |
| 857 | } |
| 858 | /*-----------------------------------------------------------------------------------*/ |
| 859 | unsigned char |
| 860 | ctk_draw_width(void) |
| 861 | { |
| 862 | return SCREEN_WIDTH; |
| 863 | } |
| 864 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 865 | unsigned char |
| 866 | ctk_arch_isprint(char c) |
| 867 | { |
| 868 | return isprint(c); |
| 869 | } |