adamdunkels | 4f45d1f | 2004-08-09 20:53:08 +0000 | [diff] [blame^] | 1 | |
| 2 | #include <c64.h> |
| 3 | |
| 4 | #include "libconio.h" |
| 5 | |
| 6 | #include "ctk-hires-asm.h" |
| 7 | |
| 8 | unsigned char ctk_hires_cursx, ctk_hires_cursy; |
| 9 | unsigned char ctk_hires_reversed; |
| 10 | unsigned char ctk_hires_color; |
| 11 | unsigned char ctk_hires_underline = 0; |
| 12 | |
| 13 | #define SCREEN_HEIGHT 25 |
| 14 | #define SCREEN_WIDTH 80 |
| 15 | |
| 16 | #define SCREENADDR 0xdc00 |
| 17 | #define HIRESADDR 0xe000 |
| 18 | |
| 19 | unsigned char ctk_80col_lefttab[256]; |
| 20 | unsigned char ctk_80col_righttab[256]; |
| 21 | |
| 22 | unsigned short ctk_hires_yhiresaddr[25] = |
| 23 | {0 * 320 + HIRESADDR, 1 * 320 + HIRESADDR, |
| 24 | 2 * 320 + HIRESADDR, 3 * 320 + HIRESADDR, |
| 25 | 4 * 320 + HIRESADDR, 5 * 320 + HIRESADDR, |
| 26 | 6 * 320 + HIRESADDR, 7 * 320 + HIRESADDR, |
| 27 | 8 * 320 + HIRESADDR, 9 * 320 + HIRESADDR, |
| 28 | 10 * 320 + HIRESADDR, 11 * 320 + HIRESADDR, |
| 29 | 12 * 320 + HIRESADDR, 13 * 320 + HIRESADDR, |
| 30 | 14 * 320 + HIRESADDR, 15 * 320 + HIRESADDR, |
| 31 | 16 * 320 + HIRESADDR, 17 * 320 + HIRESADDR, |
| 32 | 18 * 320 + HIRESADDR, 19 * 320 + HIRESADDR, |
| 33 | 20 * 320 + HIRESADDR, 21 * 320 + HIRESADDR, |
| 34 | 22 * 320 + HIRESADDR, 23 * 320 + HIRESADDR, |
| 35 | 24 * 320 + HIRESADDR}; |
| 36 | |
| 37 | /*---------------------------------------------------------------------------*/ |
| 38 | void |
| 39 | ctk_arch_draw_char(char c, |
| 40 | unsigned char xpos, |
| 41 | unsigned char ypos, |
| 42 | unsigned char reversedflag, |
| 43 | unsigned char color) |
| 44 | { |
| 45 | ctk_hires_cursx = xpos; |
| 46 | ctk_hires_cursy = ypos; |
| 47 | ctk_hires_reversed = reversedflag; |
| 48 | ctk_hires_color = color; |
| 49 | |
| 50 | ctk_hires_cputc(c); |
| 51 | } |
| 52 | /*---------------------------------------------------------------------------*/ |
| 53 | #pragma optimize(push, off) |
| 54 | static void |
| 55 | nmi2(void) |
| 56 | { |
| 57 | asm("pla"); |
| 58 | asm("sta $01"); |
| 59 | asm("pla"); |
| 60 | asm("rti"); |
| 61 | } |
| 62 | #pragma optimize(pop) |
| 63 | /*---------------------------------------------------------------------------*/ |
| 64 | #pragma optimize(push, off) |
| 65 | static void |
| 66 | nmi(void) |
| 67 | { |
| 68 | asm("sei"); |
| 69 | asm("pha"); |
| 70 | asm("inc $d020"); |
| 71 | asm("lda $01"); |
| 72 | asm("pha"); |
| 73 | asm("lda #$36"); |
| 74 | asm("sta $01"); |
| 75 | asm("lda #>_nmi2"); |
| 76 | asm("pha"); |
| 77 | asm("lda #<_nmi2"); |
| 78 | asm("pha"); |
| 79 | asm("php"); |
| 80 | asm("jmp ($0318)"); |
| 81 | |
| 82 | nmi2(); |
| 83 | } |
| 84 | #pragma optimize(pop) |
| 85 | /*---------------------------------------------------------------------------*/ |
| 86 | #pragma optimize(push, off) |
| 87 | static void |
| 88 | setup_nmi(void) |
| 89 | { |
| 90 | asm("lda #<_nmi"); |
| 91 | asm("sta $fffa"); |
| 92 | asm("lda #>_nmi"); |
| 93 | asm("sta $fffb"); |
| 94 | return; |
| 95 | nmi(); |
| 96 | } |
| 97 | #pragma optimize(pop) |
| 98 | /*---------------------------------------------------------------------------*/ |
| 99 | #pragma optimize(push, off) |
| 100 | void |
| 101 | ctk_80col_init(void) |
| 102 | { |
| 103 | int i; |
| 104 | |
| 105 | |
| 106 | setup_nmi(); |
| 107 | |
| 108 | /* Turn on hires mode, bank 0 ($c000 - $ffff) and $e000/$c000 for |
| 109 | hires/colors. */ |
| 110 | VIC.ctrl1 = 0x3b; /* $D011 */ |
| 111 | VIC.addr = 0x78; /* $D018 */ |
| 112 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 113 | CIA2.pra = 0x00; /* $DD00 */ |
| 114 | |
| 115 | VIC.bordercolor = 0x0f; /* $D020 */ |
| 116 | VIC.bgcolor0 = 0x0b; /* $D021 */ |
| 117 | |
| 118 | /* Fill color memory. */ |
| 119 | asm("sei"); |
| 120 | asm("lda $01"); |
| 121 | asm("pha"); |
| 122 | asm("lda #$30"); |
| 123 | asm("sta $01"); |
| 124 | asm("ldx #0"); |
| 125 | asm("lda #$bf"); |
| 126 | asm("fillcolorloop:"); |
| 127 | asm("sta $dc00,x"); |
| 128 | asm("sta $dd00,x"); |
| 129 | asm("sta $de00,x"); |
| 130 | asm("sta $df00,x"); |
| 131 | asm("inx"); |
| 132 | asm("bne fillcolorloop"); |
| 133 | |
| 134 | /* Setup sprite pointers */ |
| 135 | asm("ldx #$fd"); |
| 136 | asm("stx $dff8"); |
| 137 | asm("inx"); |
| 138 | asm("stx $dff9"); |
| 139 | asm("pla"); |
| 140 | asm("sta $01"); |
| 141 | asm("cli"); |
| 142 | |
| 143 | /* Fill hires memory with 0. */ |
| 144 | |
| 145 | asm("lda $fd"); |
| 146 | asm("pha"); |
| 147 | asm("lda $fe"); |
| 148 | asm("pha"); |
| 149 | asm("lda #0"); |
| 150 | asm("sta $fd"); |
| 151 | asm("lda #$e0"); |
| 152 | asm("sta $fe"); |
| 153 | asm("ldy #0"); |
| 154 | asm("lda #0"); |
| 155 | asm("clrscrnloop:"); |
| 156 | asm("lda #$55"); |
| 157 | asm("sta ($fd),y"); |
| 158 | asm("iny"); |
| 159 | asm("lda #$aa"); |
| 160 | asm("sta ($fd),y"); |
| 161 | asm("iny"); |
| 162 | asm("bne clrscrnloop"); |
| 163 | asm("inc $fe"); |
| 164 | asm("lda $fe"); |
| 165 | asm("cmp #$ff"); |
| 166 | asm("bne clrscrnloop"); |
| 167 | |
| 168 | asm("ldy #$00"); |
| 169 | asm("clrscrnloop2:"); |
| 170 | asm("lda #$55"); |
| 171 | asm("sta $ff00,y"); |
| 172 | asm("iny"); |
| 173 | asm("lda #$aa"); |
| 174 | asm("sta $ff00,y"); |
| 175 | asm("iny"); |
| 176 | asm("cpy #$40"); |
| 177 | asm("bne clrscrnloop2"); |
| 178 | |
| 179 | |
| 180 | asm("pla"); |
| 181 | asm("sta $fe"); |
| 182 | asm("pla"); |
| 183 | asm("sta $fd"); |
| 184 | |
| 185 | |
| 186 | /* ctk_draw_clear(0, 24);*/ |
| 187 | |
| 188 | for(i = 0; i < 256; ++i) { |
| 189 | ctk_80col_lefttab[i] = |
| 190 | ((i & 0x40) << 1) | |
| 191 | ((i & 0x10) << 2) | |
| 192 | ((i & 0x04) << 3) | |
| 193 | ((i & 0x01) << 4); |
| 194 | ctk_80col_righttab[i] = |
| 195 | ((i & 0x40) >> 3) | |
| 196 | ((i & 0x10) >> 2) | |
| 197 | ((i & 0x04) >> 1) | |
| 198 | ((i & 0x01)); |
| 199 | } |
| 200 | |
| 201 | #if 0 |
| 202 | /* Setup mouse pointer sprite. */ |
| 203 | asm("lda %v+%w", ctk_hires_theme, |
| 204 | offsetof(struct ctk_hires_theme, pointermaskcolor)); |
| 205 | asm("sta $d027"); |
| 206 | asm("lda %v+%w", ctk_hires_theme, |
| 207 | offsetof(struct ctk_hires_theme, pointercolor)); |
| 208 | asm("sta $d028"); |
| 209 | |
| 210 | ptr1 = ctk_hires_theme.pointer; |
| 211 | ptr2 = (unsigned char *)0xff40; |
| 212 | |
| 213 | for(i = 0; i < 0x80; ++i) { |
| 214 | *ptr2++ = *ptr1++; |
| 215 | } |
| 216 | #endif |
| 217 | return; |
| 218 | } |
| 219 | #pragma optimize(pop) |
| 220 | /*---------------------------------------------------------------------------*/ |