summaryrefslogtreecommitdiff
path: root/apps/plugins/zxbox/spscr.c
blob: 2693812bf68982b0affdda92e2381ac9d95e9c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* 
 * Copyright (C) 1996-1998 Szeredi Miklos
 * Email: mszeredi@inf.bme.hu
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See the file COPYING. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "spscr_p.h"
#include "spscr.h"

#include "spperif.h"
#include "z80.h"


#include <stdlib.h>
#include <stdio.h>

int color_type = 0;

#define N0 0x04
#define N1 0x34

#define B0 0x08
#define B1 0x3F


struct rgb *spscr_crgb;

static struct rgb norm_colors[COLORNUM]={
  {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1},
  {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1},

  {0x15,0x15,0x15},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1},
  {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1}
};

static struct rgb gray_colors[COLORNUM]={
  {0,0,0},{20,20,20},{26,26,26},{32,32,32},
  {38,38,38},{44,44,44},{50,50,50},{56,56,56},

  {16,16,16},{23,23,23},{30,30,30},{36,36,36},
  {43,43,43},{50,50,50},{56,56,56},{63,63,63}
};

struct rgb custom_colors[COLORNUM]={
  {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1},
  {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1},

  {0x15,0x15,0x15},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1},
  {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1}
};


#define TABOFFS 2

volatile int screen_visible = 1;
volatile int accept_keys = 1;


byte *update_screen_line(byte *scrp, int coli, int scri, int border,
             qbyte *cmarkp)
{
  qbyte *scrptr;
#if LCD_WIDTH == 320 && ( LCD_HEIGHT == 240 || LCD_HEIGHT == 200 )
  qbyte brd_color;
#else
  (void) border;
#endif
  int i;
  qbyte *tmptr, *mptr;
  qbyte mark, cmark;
  
  cmark = *cmarkp;
  scrptr = (qbyte *) scrp;
  if(scri >= 0) {          /* normal line */
#if LCD_WIDTH == 320 && ( LCD_HEIGHT == 240 || LCD_HEIGHT == 200 )
    if(SPNM(border_update)) {
      brd_color = SPNM(colors)[border];
      brd_color |= brd_color << 8;
      brd_color |= brd_color << 16;
      for(i = 8; i; i--) *scrptr++ = brd_color;
      scrptr += 0x40;
      for(i = 8; i; i--) *scrptr++ = brd_color;
      scrptr -= 0x48;
    }
    else
#endif
        scrptr += 0x08;

    tmptr = SPNM(scr_mark) + 0x2C0 + (coli >> 3);
    mark = *tmptr;
    if(!(coli & 0x07)) {
      cmark = mark;
      *tmptr = 0;
    }
    else cmark |= mark;
    mptr = SPNM(scr_mark) + scri;
    
    mark = *mptr | cmark;
    if(mark) {
      byte *spmp, *spcp;
      qbyte *scr_tab;
      
      *mptr = 0;
      SPNM(imag_mark)[coli] |= mark;
      SPNM(imag_horiz) |= mark;
      coli >>= 3;
      SPNM(imag_vert) |= (1 << coli);
      
      spmp = PRNM(proc).mem + (scri << 5);
      spcp = PRNM(proc).mem + 0x5800 + (coli << 5);

      if(!SPNM(flash_state)) scr_tab = SPNM(scr_f0_table);
      else scr_tab = SPNM(scr_f1_table);
      for(i = 32; i; i--) {
    register dbyte spcx, spmx;
    spcx = (*spcp++) << 6;
    spmx = *spmp++;
    *scrptr++ = scr_tab[spcx|((spmx & 0xf0) >> 4)];
    *scrptr++ = scr_tab[spcx|((spmx & 0x0f))];
      }
      scrptr +=0x08;
    }
    else scrptr += 0x48;
  }
  else if(scri == -1) {  /* only border */
#if LCD_WIDTH == 320 && ( LCD_HEIGHT == 240 || LCD_HEIGHT == 200 )
    if(SPNM(border_update)) {
      brd_color = SPNM(colors)[border];
      brd_color |= brd_color << 8;
      brd_color |= brd_color << 16;
      for(i = 0x50; i; i--) *scrptr++ = brd_color;
    }
    else
#endif
        scrptr += 0x50;

  }

  *cmarkp = cmark;
  return (byte *) scrptr;
}

void spscr_init_mask_color(void)
{
  int clb;
  int bwb;
  int hb;
  int ix, j;
  int bc, fc;
  byte *tab_f0, *tab_f1;

  sp_scr_f0_table = (qbyte *) (PRNM(proc).mem + 0x10000);
  sp_scr_f1_table = (qbyte *) (PRNM(proc).mem + 0x20000);

  sp_colors[8] = sp_colors[0];

  for(clb = 0; clb < 256; clb++) 
    for(hb = 0; hb < 16; hb++) {

      bc = (clb & 0x38) >> 3;
      fc = clb & 0x07;
      
      if(clb & 0x40) {
    fc |= 0x08;
    bc |= 0x08;
      }
      bwb = hb;

      ix = (clb << 8) + (hb << TABOFFS);
      tab_f0 = ((byte *) sp_scr_f0_table) + ix + 3;
      tab_f1 = ((byte *) sp_scr_f1_table) + ix + 3;

      for(j = 4; j; bwb >>= 1, j--)  {
    *tab_f0-- = (byte) sp_colors[(bwb & 0x01) ? fc : bc];
    *tab_f1-- = (byte) sp_colors[(clb & 0x80) ? 
                    ((bwb & 0x01) ? bc : fc) :
                    ((bwb & 0x01) ? fc : bc)];
      }
    }
}

void flash_change(void)
{
  int i,j;
  byte *scp;
  qbyte *mcp;
  register unsigned int val;

  mcp = sp_scr_mark + 0x2C0;
  scp = z80_proc.mem + 0x5800;

  for(i = 24; i; mcp++, i--) {
    val = 0;
    for(j = 32; j; scp++, j--) {
      val >>= 1;
      if(*scp & 0x80) val |= (1 << 31);
    }
    *mcp |= val;
  }
}

void spscr_init_line_pointers(int lines)
{
  int i;
  int bs;
  int y;
  int scline;
  
  bs = (lines - 192) / 2;

  for(i = 0; i < PORT_TIME_NUM; i++) {

    sp_scri[i] = -2;

    if(i < ODDHF) scline = i;
    else scline = i - ODDHF;
    
    if(scline >= 64-bs && scline < 256+bs) {
      if(scline >= 64 && scline < 256) {
    y = scline - 64;
    sp_coli[i] = y;
    sp_scri[i] = 0x200 +
      (y & 0xC0) + ((y & 0x07) << 3) + ((y & 0x38) >> 3);
      }
      else sp_scri[i] = -1;
    }
  }
}

void spscr_init_colors(void)
{
  spscr_crgb = norm_colors;
  
  switch(color_type) {
  case 0:
    spscr_crgb = norm_colors;
    break;
    
  case 1:
    spscr_crgb = gray_colors;
    break;
    
  case 2:
    spscr_crgb = custom_colors;
    break;
  }
}