ctk-hires.c
来自「伟大的Contiki工程, 短小精悍 的操作系统, 学习编程不可不看」· C语言 代码 · 共 872 行 · 第 1/2 页
C
872 行
/* * Copyright (c) 2002, Adam Dunkels. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * 3. The name of the author may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of the "ctk" console GUI toolkit for cc65 * * $Id: ctk-hires.c,v 1.1 2007/05/23 23:11:27 oliverschmidt Exp $ * */#include "contiki-version.h"#include "ctk/ctk.h"#include "ctk-draw.h"#include "ctk-hires.h"#include "ctk-hires-asm.h"#include "ctk-hires-theme.h"#include <string.h>#include <ctype.h>#ifndef NULL#define NULL (void *)0#endif /* NULL */#define SCREEN_HEIGHT 25#define SCREEN_WIDTH 40#define SCREENADDR 0xdc00#define HIRESADDR 0xe000static unsigned char lineptr;unsigned char ctk_hires_cursx, ctk_hires_cursy;unsigned char ctk_hires_reversed;unsigned char ctk_hires_color;unsigned char ctk_hires_underline;/*static unsigned char cchar;static unsigned char tmp01;static unsigned char tmph, tmpl, tmpborder;static unsigned char *tmpptr;*/static unsigned char x, y, i;/*static unsigned char h;*/static unsigned char wfocus;static unsigned char x1, y1, x2, y2;struct ctk_hires_windowparams ctk_hires_windowparams;unsigned char *ctk_hires_bitmapptr;unsigned char ctk_draw_windowborder_height = 1;unsigned char ctk_draw_windowborder_width = 1;unsigned char ctk_draw_windowtitle_height = 1;/*-----------------------------------------------------------------------------------*//* Tables. */unsigned short ctk_hires_yscreenaddr[25] = {0 * SCREEN_WIDTH + SCREENADDR, 1 * SCREEN_WIDTH + SCREENADDR, 2 * SCREEN_WIDTH + SCREENADDR, 3 * SCREEN_WIDTH + SCREENADDR, 4 * SCREEN_WIDTH + SCREENADDR, 5 * SCREEN_WIDTH + SCREENADDR, 6 * SCREEN_WIDTH + SCREENADDR, 7 * SCREEN_WIDTH + SCREENADDR, 8 * SCREEN_WIDTH + SCREENADDR, 9 * SCREEN_WIDTH + SCREENADDR, 10 * SCREEN_WIDTH + SCREENADDR, 11 * SCREEN_WIDTH + SCREENADDR, 12 * SCREEN_WIDTH + SCREENADDR, 13 * SCREEN_WIDTH + SCREENADDR, 14 * SCREEN_WIDTH + SCREENADDR, 15 * SCREEN_WIDTH + SCREENADDR, 16 * SCREEN_WIDTH + SCREENADDR, 17 * SCREEN_WIDTH + SCREENADDR, 18 * SCREEN_WIDTH + SCREENADDR, 19 * SCREEN_WIDTH + SCREENADDR, 20 * SCREEN_WIDTH + SCREENADDR, 21 * SCREEN_WIDTH + SCREENADDR, 22 * SCREEN_WIDTH + SCREENADDR, 23 * SCREEN_WIDTH + SCREENADDR, 24 * SCREEN_WIDTH + SCREENADDR};unsigned short ctk_hires_yhiresaddr[25] = {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR, 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR, 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR, 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR, 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR, 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR, 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR, 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR, 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR, 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR, 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR, 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR, 24 * 320 + HIRESADDR};extern struct ctk_hires_theme ctk_hires_theme;struct ctk_hires_theme *ctk_hires_theme_ptr = &ctk_hires_theme;/*-----------------------------------------------------------------------------------*/#define hires_wherex() ctk_hires_cursx#define hires_revers(c) ctk_hires_reversed = c#define hires_color(c) ctk_hires_color = c#define hires_underline(c) ctk_hires_underline = c/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_cvline(unsigned char length){ static unsigned char i; for(i = 0; i < length; ++i) { ctk_hires_cputc('|'); --ctk_hires_cursx; ++ctk_hires_cursy; }}/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_gotoxy(unsigned char x, unsigned char y){ ctk_hires_cursx = x; ctk_hires_cursy = y;}/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_cclearxy(unsigned char x, unsigned char y, unsigned char length){ hires_gotoxy(x, y); ctk_hires_cclear(length);}/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_chlinexy(unsigned char x, unsigned char y, unsigned char length){ hires_gotoxy(x, y); ctk_hires_chline(length);}/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_cvlinexy(unsigned char x, unsigned char y, unsigned char length){ hires_gotoxy(x, y); hires_cvline(length);}/*-----------------------------------------------------------------------------------*/static void __fastcall__hires_cputcxy(unsigned char x, unsigned char y, char c){ hires_gotoxy(x, y); ctk_hires_cputc(c);}/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)static void clear_line(unsigned char line){ lineptr = line; asm("lda %v", lineptr); asm("asl"); asm("tax"); asm("lda %v,x", ctk_hires_yhiresaddr); asm("sta ptr2"); asm("lda %v+1,x", ctk_hires_yhiresaddr); asm("sta ptr2+1"); asm("lda %v,x", ctk_hires_yscreenaddr); asm("sta ptr1"); asm("lda %v+1,x", ctk_hires_yscreenaddr); asm("sta ptr1+1"); asm("sei"); asm("lda $01"); asm("pha"); asm("lda #$30"); asm("sta $01"); asm("ldy #39"); asm("ldx %v", lineptr); asm("lda %v+%w,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpatterncolors)); asm("clearlineloop1:"); asm("sta (ptr1),y"); asm("dey"); asm("bpl clearlineloop1"); asm("pla"); asm("sta $01"); asm("cli"); asm("lda %v", lineptr); /* asm("and #7");*/ asm("asl"); asm("asl"); asm("asl"); asm("tax"); asm("ldy #0"); asm("clearlineloop2:"); asm("lda %v+%w+0,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+1,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+2,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+3,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+4,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+5,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+6,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+7,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("bne clearlineloop2"); asm("inc ptr2+1"); asm("ldy #0"); asm("clearlineloop3:"); asm("lda %v+%w+0,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+1,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+2,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+3,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+4,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+5,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+6,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("lda %v+%w+7,x", ctk_hires_theme, offsetof(struct ctk_hires_theme, backgroundpattern)); asm("sta (ptr2),y"); asm("iny"); asm("cpy #$40"); asm("bne clearlineloop3"); if(lineptr == 24) { hires_color(ctk_hires_theme.backgroundpatterncolors[24]); hires_gotoxy(0, 24); ctk_hires_cputsn(CONTIKI_VERSION_STRING, sizeof(CONTIKI_VERSION_STRING) - 1); }}#pragma optimize(pop)/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)static voidnmi2(void){ asm("pla"); asm("sta $01"); asm("pla"); asm("rti");} #pragma optimize(pop)/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)static voidnmi(void){ asm("sei"); asm("pha"); asm("inc $d020"); asm("lda $01"); asm("pha"); asm("lda #$36"); asm("sta $01"); asm("lda #>_nmi2"); asm("pha"); asm("lda #<_nmi2"); asm("pha"); asm("php"); asm("jmp ($0318)"); nmi2();}#pragma optimize(pop)/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)static voidsetup_nmi(void){ asm("lda #<_nmi"); asm("sta $fffa"); asm("lda #>_nmi"); asm("sta $fffb"); return; nmi();}#pragma optimize(pop)/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)voidctk_draw_init(void){ unsigned char i, *ptr1, *ptr2; setup_nmi(); /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for hires/colors. */ VIC.ctrl1 = 0x3b; /* $D011 */ VIC.addr = 0x78; /* $D018 */ VIC.ctrl2 = 0xc8; /* $D016 */ CIA2.pra = 0x00; /* $DD00 */ VIC.bordercolor = ctk_hires_theme.bordercolor; /* $D020 */ VIC.bgcolor0 = ctk_hires_theme.screencolor; /* $D021 */ /* Fill color memory. */ asm("sei"); asm("lda $01"); asm("pha"); asm("lda #$30"); asm("sta $01"); asm("ldx #0"); asm("lda #$c0"); asm("fillcolorloop:"); asm("sta $dc00,x"); asm("sta $dd00,x"); asm("sta $de00,x"); asm("sta $df00,x"); asm("inx"); asm("bne fillcolorloop"); /* Setup sprite pointers */ asm("ldx #$fd"); asm("stx $dff8"); asm("inx"); asm("stx $dff9"); asm("pla"); asm("sta $01"); asm("cli"); /* Fill hires memory with 0. */ asm("lda $fd"); asm("pha"); asm("lda $fe"); asm("pha"); asm("lda #0"); asm("sta $fd"); asm("lda #$e0"); asm("sta $fe"); asm("ldy #0"); asm("lda #0"); asm("clrscrnloop:"); asm("lda #$55"); asm("sta ($fd),y"); asm("iny"); asm("lda #$aa"); asm("sta ($fd),y"); asm("iny"); asm("bne clrscrnloop"); asm("inc $fe"); asm("lda $fe"); asm("cmp #$ff"); asm("bne clrscrnloop"); asm("ldy #$00"); asm("clrscrnloop2:"); asm("lda #$55"); asm("sta $ff00,y"); asm("iny"); asm("lda #$aa"); asm("sta $ff00,y"); asm("iny"); asm("cpy #$40"); asm("bne clrscrnloop2"); asm("pla"); asm("sta $fe"); asm("pla"); asm("sta $fd"); ctk_draw_clear(0, SCREEN_HEIGHT); /* Setup mouse pointer sprite. */ asm("lda %v+%w", ctk_hires_theme, offsetof(struct ctk_hires_theme, pointermaskcolor)); asm("sta $d027");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?