File: vgascr.c

package info (click to toggle)
spectemu 0.94a-8
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 1,252 kB
  • ctags: 3,088
  • sloc: ansic: 15,419; asm: 5,160; sh: 2,760; cpp: 377; makefile: 228
file content (307 lines) | stat: -rw-r--r-- 5,656 bytes parent folder | download | duplicates (11)
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* 
 * 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 "config.h"

#include "vgascr.h"
#include "spperif.h"
#include "spscr.h"
#include "spscr_p.h"
#include "spkey_p.h"
#include "misc.h"
#include "interf.h"

#define TV_WIDTH         320
#define TV_HEIGHT_SMALL  200
#define TV_HEIGHT_LARGE  240

#define X_OFF        ((TV_WIDTH - WIDTH) / 2)
#define Y_OFF_L      ((TV_HEIGHT_LARGE - HEIGHT) / 2)


#define WIDTH      256
#define HEIGHT     192

int small_screen = 0;
int vga_pause_bg = 0;

int scrmul;           /* DUMMY */
int use_shm;          /* DUMMY */
int privatemap;       /* DUMMY */
int pause_on_iconify; /* DUMMY */

#ifndef USE_DJGPP

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

static volatile int need_restore = 0;

void update_screen(void)
{
  if(need_restore) {
    need_restore = 0;
    spscr_init_line_pointers(small_screen ? TV_HEIGHT_SMALL : TV_HEIGHT_LARGE);
    sp_init_screen_mark();
  }
  if(!small_screen) {
    int i;
    /* TODO: Only update if necessary */

    for(i = 0; i < TV_HEIGHT_LARGE; i++) {
      if(sp_border_update || 
         (i >= Y_OFF_L && i < TV_HEIGHT_LARGE - Y_OFF_L && 
          sp_imag_mark[i - Y_OFF_L])) {
	
        if(i >= Y_OFF_L && i < TV_HEIGHT_LARGE - Y_OFF_L) 
          sp_imag_mark[i - Y_OFF_L] = 0;

	vga_drawscanline(i, &sp_image[i * TV_WIDTH]);
      }

    }
  }
}

#if RUN_IN_BACKGROUND && defined(VGA_GOTOBACK)
static void noupdt(void)
{
  int i;

  for(i = 0; i < PORT_TIME_NUM; i++) sp_scri[i] = -2;
  screen_visible = 0;
  accept_keys = 0;
}

static int paused_bak = 0;

static void swto(void)
{
  if(vga_pause_bg) paused_bak = sp_paused, sp_paused = 1;
  noupdt();
}

static void swfrom(void)
{
  if(vga_pause_bg && sp_paused) sp_paused = paused_bak;
  
  need_restore = 1;
  screen_visible = 1;
  accept_keys = 1;

  spvk_after_switch = 1;
}

static void start_background(void)
{
  if(vga_runinbackground_version() == 1) {
    vga_runinbackground(VGA_GOTOBACK, swto);
    vga_runinbackground(VGA_COMEFROMBACK, swfrom);
    vga_runinbackground(1);
  }
}

#else /* RUN_IN_BACKGROUND */

static void start_background(void)
{
}
#endif /* RUN_IN_BACKGROUND */

void set_vga_spmode(void)
{
  if(!small_screen) {
    if(vga_setmode(G320x240x256) < 0) {
      put_msg("Can't use mode 320x240/256");
      small_screen = 1;
    }
  }
  if(small_screen) vga_setmode(G320x200x256);

  vga_setpalvec(1, COLORNUM, &spscr_crgb[0].r);
}

void restore_sptextmode(void)
{
  vga_setmode(TEXT);
}


void init_spect_scr(void)
{
  int i;

  spscr_init_colors();
  start_background();
  set_vga_spmode();
   
  if(small_screen) sp_image = (char *) vga_getgraphmem();
  else sp_image = (char *) malloc_err(TV_WIDTH * TV_HEIGHT_LARGE);

  for(i = 0; i < COLORNUM; i++) {
    sp_colors[i] = i+1;
  }

  spscr_init_mask_color();

  spscr_init_line_pointers(small_screen ? TV_HEIGHT_SMALL : TV_HEIGHT_LARGE);
}

void sp_init_vga(void)
{
  vga_init();
  printf("\n");
}

#else /* !USE_DJGPP */

#ifdef Z80C
#warning Compile with i386 assembly!
#endif


#include <stdio.h>
#include <stdlib.h>
#include <dpmi.h>
#include <go32.h>
#include <sys/farptr.h>
#include <stdlib.h>

#ifdef USE_ALLEGRO
#include "allegro.h"
#endif

static int origmode;
int djsp_video_segment;

#define VIDEO_LEN     64000
#define VIDEO_OFFSET  0x000a0000

static void set_video_mode(int mode)
{
  __dpmi_regs r;

  r.h.ah = 0x00;
  r.h.al = mode;
  __dpmi_int(0x10, &r);
}

static int get_video_mode(void)
{
  __dpmi_regs r;
  
  r.h.ah = 0x0f;
  __dpmi_int(0x10, &r);
  return r.h.al;
}

void update_screen(void)
{
#ifdef Z80C
  movedata(_my_ds(), (int) sp_image, VIDEO_OFFSET, VIDEO_LEN);
#endif
}


static void set_pal(int start, int num, int *pal) 
{
  int i;
  __dpmi_regs r;
  
  for(i = 0; i < num * 3; i++) 
    _farpokeb(_dos_ds, (__tb & 0x000fffff)+i, pal[i]);

  r.x.ax = 0x1012;
  r.x.bx = start;
  r.x.cx = num;
  r.x.dx = __tb & 0x0f;
  r.x.es = (__tb >> 4) & 0xffff;
  __dpmi_int(0x10, &r);
}

void set_vga_spmode(void)
{
  set_video_mode(0x13);
  set_pal(1, COLORNUM,  &spscr_crgb[0].r);
  spif_can_print = 0;
}

void restore_sptextmode(void)
{
  set_video_mode(origmode);
  spif_can_print = 1;
}

void init_spect_scr(void)
{
  int i;

  spscr_init_colors();

#ifdef Z80C
  sp_image = (char *) malloc_err(VIDEO_LEN);
#else
  djsp_video_segment = _dos_ds;
  sp_image = (char *) VIDEO_OFFSET;
#endif


  origmode = get_video_mode();
  atexit(restore_sptextmode);

  set_vga_spmode();

  for(i = 0; i < COLORNUM; i++) {
    sp_colors[i] = i+1;
  }

  spscr_init_mask_color();
  spscr_init_line_pointers(TV_HEIGHT_SMALL);
}

void sp_init_vga(void)
{
#ifdef USE_ALLEGRO
  if(allegro_init() != 0) {
    fprintf(stderr, "Could not initialize allegro\n");
    exit(1);
  }
#endif
}

#endif /* !USE_DJGPP */

void destroy_spect_scr(void)
{
}

void resize_spect_scr(int s)
{
  s = s;
}

void spcf_read_xresources(void)
{
}

void spscr_refresh_colors(void)
{
}