ctk-80col.c

来自「伟大的Contiki工程, 短小精悍 的操作系统, 学习编程不可不看」· C语言 代码 · 共 1,191 行 · 第 1/3 页

C
1,191
字号
/* * Copyright (c) 2004, 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. Neither the name of the Institute nor the names of its contributors  *    may be used to endorse or promote products derived from this software  *    without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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 Contiki operating system. *  * Author: Adam Dunkels <adam@sics.se> * * $Id: ctk-80col.c,v 1.1 2007/05/23 23:11:27 oliverschmidt Exp $ */#include "contiki.h"#include "ctk/ctk.h"#include "ctk/ctk-draw.h"#include "ctk/ctk-draw-service.h"#include "ctk-80col-asm.h"#include "ctk-80col-theme.h"#include <string.h>unsigned char ctk_80col_cursx, ctk_80col_cursy;unsigned char ctk_80col_reversed;unsigned char ctk_80col_color;unsigned char *ctk_80col_bitmapptr;unsigned char ctk_80col_underline = 0;#define SCREEN_HEIGHT 25#define SCREEN_WIDTH  80#define SCREENADDR 0xdc00#define HIRESADDR  0xe000unsigned char ctk_80col_lefttab[256];unsigned char ctk_80col_righttab[256];#define COLOR(bg, fg) ((fg << 4) | (bg))#define COLOR_DIALOG            0x01#define COLOR_FOCUS_WINDOW      0xbf#define COLOR_BACKGROUND_WINDOW 0x0c#define color(c) ctk_80col_color = c#define BGCOLOR1 7#define BGCOLOR2 10#define BGCOLOR3 4#define BGCOLOR4 6unsigned char ctk_80col_screencolors[25] =  {COLOR(BGCOLOR4,BGCOLOR1),   COLOR(BGCOLOR2,BGCOLOR1),   COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),   COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),   COLOR(BGCOLOR2,BGCOLOR1),COLOR(BGCOLOR2,BGCOLOR1),   COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),   COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),   COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),   COLOR(BGCOLOR3,BGCOLOR2),COLOR(BGCOLOR3,BGCOLOR2),   COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),   COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),   COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),   COLOR(BGCOLOR4,BGCOLOR3),COLOR(BGCOLOR4,BGCOLOR3),   COLOR(BGCOLOR4,1)};unsigned char ctk_80col_screenpattern[25*8] =  {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,   0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,   0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,   0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,   0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,   0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,   0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,   0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,   0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,   0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,   0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,   0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,   0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,   0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,   0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,   0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,   0xff,0x55,0xff,0x55,0xff,0x55,0xff,0x55,   0xee,0x55,0xbb,0x55,0xee,0x55,0xbb,0x55,   0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,   0xaa,0x44,0xaa,0x11,0xaa,0x44,0xaa,0x11,   0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,   0x88,0x00,0x22,0x00,0x88,0x00,0x22,0x00,   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsigned short ctk_80col_yscreenaddr[25] =  {0 * 40 + SCREENADDR, 1 * 40 + SCREENADDR,   2 * 40 + SCREENADDR, 3 * 40 + SCREENADDR,   4 * 40 + SCREENADDR, 5 * 40 + SCREENADDR,   6 * 40 + SCREENADDR, 7 * 40 + SCREENADDR,   8 * 40 + SCREENADDR, 9 * 40 + SCREENADDR,   10 * 40 + SCREENADDR, 11 * 40 + SCREENADDR,   12 * 40 + SCREENADDR, 13 * 40 + SCREENADDR,   14 * 40 + SCREENADDR, 15 * 40 + SCREENADDR,   16 * 40 + SCREENADDR, 17 * 40 + SCREENADDR,   18 * 40 + SCREENADDR, 19 * 40 + SCREENADDR,   20 * 40 + SCREENADDR, 21 * 40 + SCREENADDR,   22 * 40 + SCREENADDR, 23 * 40 + SCREENADDR,   24 * 40 + SCREENADDR};unsigned short ctk_80col_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};struct ctk_80col_theme ctk_80col_theme =  {    /* Version string. */    /*    char version[8]; */    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    /* Window borders patterns. */    /* unsigned char ulcorner[8], */ /* Upper left corner. */    {0xff,0xc0,0x80,0xbf,0x80,0xbf,0x80,0x80},        /* titlebar[8], */            /* Title bar pattern. */    {0xff,0x00,0x00,0xff,0x00,0xff,0x00,0x00},        /* urcorner[8],       */       /* Upper right corner. */    {0xff,0x03,0x01,0xfd,0x01,0xfd,0x01,0x01},        /* rightborder[8],     */      /* Right border. */    {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},        /* lrcorner[8],      */        /* Lower right corner. */    {0x01,0x01,0x01,0x01,0x01,0x01,0x03,0xff},        /* lowerborder[8], */          /* Lower border. */    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},        /* llcorner[8],  */            /* Lower left corner. */    {0x80,0x80,0x80,0x80,0x80,0x80,0xc0,0xff},        /* leftborder[8]; */          /* Left border. */    {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},    /* Button corner patterns. */    /*    unsigned char buttonleft[8], */    {0xc5,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf},        /* buttonright[8]; */    {0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xa3},      /* Menu border patterns. */    /*    unsigned char menuleftpattern[8], */    {0x0f,0x3f,0x3f,0x7f,0x7f,0xff,0xff,0xff},        /* menurightpatterns[8]; */    {0xf0,0xfc,0xfc,0xfe,0xfe,0xff,0xff,0xff},        /* Window and widget colors. */    /*    unsigned char windowcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_BLACK),     COLOR(COLOR_GRAY2, COLOR_BLACK),     COLOR(COLOR_GRAY3, COLOR_GRAY1),     COLOR(COLOR_GRAY3, COLOR_GRAY1),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK)},        /* separatorcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY3, COLOR_GRAY2),     COLOR(COLOR_GRAY3, COLOR_GRAY2),     COLOR(COLOR_WHITE, COLOR_GRAY1),     COLOR(COLOR_WHITE, COLOR_GRAY1)},        /* labelcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK)},        /* buttoncolors[6], */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY1, COLOR_GRAY2),     COLOR(COLOR_GRAY3, COLOR_GRAY1),     COLOR(COLOR_GRAY1, COLOR_GRAY3),     COLOR(COLOR_GRAY3, COLOR_GRAY1),     COLOR(COLOR_GRAY1, COLOR_GRAY3)},        /* hyperlinkcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE),     COLOR(COLOR_GRAY2, COLOR_LIGHTBLUE),     COLOR(COLOR_WHITE, COLOR_BLUE),     COLOR(COLOR_BLUE, COLOR_WHITE),     COLOR(COLOR_WHITE, COLOR_BLUE),     COLOR(COLOR_BLUE, COLOR_WHITE)},        /* textentrycolors[6],  */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY2, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_GRAY3, COLOR_BLACK),     COLOR(COLOR_GRAY3, COLOR_BLACK)},        /* bitmapcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY1, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_GRAY1),     COLOR(COLOR_GRAY3, COLOR_BLACK),     COLOR(COLOR_GRAY3, COLOR_BLACK),     COLOR(COLOR_GRAY3, COLOR_BLACK)},        /* textmapcolors[6], */    {COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_GRAY2, COLOR_GRAY1),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_WHITE, COLOR_BLACK)},        /* iconcolors[6]; */    {COLOR(COLOR_GRAY3, COLOR_GRAY1),     COLOR(COLOR_GRAY1, COLOR_GRAY2),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_BLUE, COLOR_WHITE),     COLOR(COLOR_WHITE, COLOR_BLACK),     COLOR(COLOR_BLACK, COLOR_YELLOW)},        /* Menu colors. */    /*    unsigned char menucolor,*/    COLOR(COLOR_YELLOW, COLOR_BLACK),        /*    openmenucolor, */    COLOR(COLOR_WHITE, COLOR_BLACK),        /* activemenucolor; */    COLOR(COLOR_BLACK, COLOR_WHITE),      };char ctk_80col_versionstring[] = CONTIKI_VERSION_STRING;char ctk_80col_versionstring_len = sizeof(CONTIKI_VERSION_STRING) - 1;struct ctk_80col_windowparams ctk_80col_windowparams;/*---------------------------------------------------------------------------*//*voidctk_arch_draw_char(char c,		   unsigned char xpos,		   unsigned char ypos,		   unsigned char reversedflag,		   unsigned char color){  ctk_80col_cursx = xpos;  ctk_80col_cursy = ypos;  ctk_80col_reversed = reversedflag;  ctk_80col_color = color;    ctk_80col_cputc(c);}*//*---------------------------------------------------------------------------*/#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)/*---------------------------------------------------------------------------*/void reset(void);voidquit(void){  VIC.ctrl1 = 0x1b;  /* $D011 */  VIC.addr  = 0x17;  /* $D018 */  VIC.ctrl2 = 0xc8;  /* $D016 */  CIA2.pra  = 0x03;  /* $DD00 */  VIC.bordercolor = 0x0e; /* $D020 */  VIC.bgcolor0 = 0x06; /* $D021 */  memset((char *)0xd800, 0x0e, 40*25);}/*-----------------------------------------------------------------------------------*/#pragma optimize(push, off)static voidctk_80col_init(void){  int i;    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 = 0x06; /* $D020 */  VIC.bgcolor0 = 0x0b; /* $D021 */    /* Fill color memory. */  asm("sei");  asm("lda $01");  asm("pha");  asm("lda #$30");  asm("sta $01");  asm("ldx #0");  asm("lda #$0");  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");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?