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