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