diff --git a/src/soft/vga.c b/src/soft/vga.c
index 8347b3ae55c0400becdbd67cb796e6d6b8ad60fe..63b5f65b7f104ef2204b2058a6dfb6c6fe9266fa 100644 (file)
--- a/src/soft/vga.c
+++ b/src/soft/vga.c
-/*
- Copyright (C) Prikol Software 1996-1997
- Copyright (C) Aleksey Volynskov 1996-1997
- Copyright (C) <ARembo@gmail.com> 2011
-
- This file is part of the Doom2D:Rembo project.
-
- Doom2D:Rembo is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
-
- Doom2D:Rembo 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, see <http://www.gnu.org/licenses/> or
- write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+/* Copyright (C) 1996-1997 Aleksey Volynskov
+ * Copyright (C) 2011 Rambo
+ * Copyright (C) 2020 SovietPony
+ *
+ * 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, version 3 of the License ONLY.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
#include "glob.h"
#include "vga.h"
-#include <SDL.h>
#include "error.h"
#include "view.h"
#include "memory.h"
#include "misc.h"
#include "files.h"
+#include "system.h"
+#include <string.h>
#include <assert.h>
-
-// адрес экранного буфера
-//unsigned char *scra;
-
-// виртуальный экран
-//unsigned char scrbuf[64000];
-
int SCRW = 800;
int SCRH = 600;
char fullscreen = OFF;
byte mixmap[256][256];
byte clrmap[256*12];
-static SDL_Surface* screen = NULL;
-static int cx1,cx2,cy1,cy2;
+byte *buffer;
+int buf_w, buf_h, pitch;
+static int offx, offy;
+static int cx1, cx2, cy1, cy2;
static byte flametab[16] = {
0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
};
-static int offx = 0;
-static int offy = 0;
-
-#define HQ 2
vgaimg *V_getvgaimg (int id) {
int loaded = M_was_locked(id);
return V_getvgaimg(F_getresid(name));
}
-short V_init (void) {
- Uint32 flags = SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_HWPALETTE;
- if (fullscreen) flags = flags | SDL_FULLSCREEN;
- screen = SDL_SetVideoMode(SCRW, SCRH, 8, flags);
- if (!screen) ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
- SCRW /= HQ;
- SCRH /= HQ;
- return 0;
-}
-
-// переключение в текстовый режим
-void V_done (void) {
- SDL_Quit();
+void V_update_buffer (void) {
+ Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch);
+ V_setrect(0, 0, buf_w, buf_h);
}
static void draw_rect (int x, int y, int w, int h, int c) {
- SDL_Rect dstrect;
- dstrect.x = x*HQ;
- dstrect.y = y*HQ;
- dstrect.w = w*HQ;
- dstrect.h = h*HQ;
- SDL_FillRect(screen, &dstrect, c);
+ int i;
+ int x0 = max(x, cx1);
+ int y0 = max(y, cy1);
+ int x1 = min(x + w - 1, cx2);
+ int y1 = min(y + h - 1, cy2);
+ int len = x1 - x0;
+ for (i = y0; i <= y1; i++) {
+ memset(&buffer[i * pitch + x0], c, len);
+ }
}
-// установить область вывода
-void V_setrect (short x,short w,short y,short h) {
- SDL_Rect r;
- r.x=x*HQ;
- r.y=y*HQ;
- r.w=w*HQ;
- r.h=h*HQ;
- SDL_SetClipRect(screen, &r);
- SDL_GetClipRect(screen, &r);
- cx1 = x;
- cx2 = x+w-1;
- cy1 = y;
- cy2 = y+h-1;
- if (cx1<0) cx1=0;
- if (cx2>=SCRW) cx2=SCRW-1;
- if (cy1<0) cy1=0;
- if (cy2>=SCRH) cy2=SCRH-1;
+void V_setrect (short x, short w, short y, short h) {
+ assert(w >= 0);
+ assert(h >= 0);
+ cx1 = max(x, 0);
+ cx2 = min(x + w - 1, buf_w - 1);
+ cy1 = max(y, 0);
+ cy2 = min(y + h - 1, buf_h - 1);
}
-static void putpixel (int x, int y, Uint8 color) {
- if(x>=cx1 && x<=cx2 && y>=cy1 && y<=cy2) {
- x*=HQ;
- y*=HQ;
- Uint8 *p = (Uint8 *)screen->pixels + y*screen->pitch + x;
- *p = color;
- *(p+1) = color;
- p += screen->pitch;
- *p = color;
- *(p+1) = color;
- }
+static void putpixel (int x, int y, byte color) {
+ if (x >= cx1 && x <= cx2 && y >= cy1 && y <= cy2) {
+ buffer[y * pitch + x] = color;
+ }
}
static byte getpixel (int x, int y) {
- if(x>=cx1 && x<=cx2 && y>=cy1 && y<=cy2) {
- x*=HQ;
- y*=HQ;
- return *((Uint8 *)screen->pixels + y*screen->pitch + x);
- }
- return 0;
+ return x >= cx1 && x <= cx2 && y >= cy1 && y <= cy2 ? buffer[y * pitch + x] : 0;
}
-static void mappixel (int x, int y, byte* cmap) {
- byte c = getpixel(x,y);
- putpixel(x,y,cmap[c]);
+static void mappixel (int x, int y, byte *cmap) {
+ byte c = getpixel(x, y);
+ putpixel(x, y, cmap[c]);
}
void V_center (int f) {
- if (f) V_offset(SCRW/2-320/2, SCRH/2-200/2);
- else V_offset(0, 0);
+ if (f) {
+ V_offset(buf_w / 2 - 320 / 2, buf_h / 2 - 200 / 2);
+ } else {
+ V_offset(0, 0);
+ }
}
void V_offset (int ox, int oy) {
- offx=ox;
- offy=oy;
+ offx = ox;
+ offy = oy;
}
static void draw_spr (short x, short y, vgaimg *i, int d, int c) {
for (ly=0; ly<i->h; ly++) {
for(lx=0; lx<i->w; lx++) {
int rx,ry;
- rx = (d & 1) ? (i->w-lx-1) : (rx=lx);
- ry = (d & 2) ? (i->h-ly-1) : (ry=ly);
+ rx = (d & 1) ? (i->w-lx-1) : (lx);
+ ry = (d & 2) ? (i->h-ly-1) : (ly);
if (*p) {
byte t = *p;
if (c) if (t>=0x70 && t<=0x7F) t=t-0x70+c;
draw_spr(x, y, p, 1, c);
}
-// вывести точку цвета c в координатах (x,y)
-void V_dot (short x,short y, unsigned char c) {
- putpixel(x,y,c);
+void V_dot (short x, short y, unsigned char c) {
+ putpixel(x, y, c);
}
void smoke_sprf (int x, int y, byte c) {
draw_rect(x, y, w, h, c);
}
-// установить n цветов, начиная с f, из массива p
-static void VP_set (void *p, short f, short n) {
- byte *ptr = (byte*)p;
- SDL_Color colors[256];
- int i;
- for(i=f;i<f+n;i++)
- {
- colors[i].r=ptr[0]*4;
- colors[i].g=ptr[1]*4;
- colors[i].b=ptr[2]*4;
- ptr+=3;
- }
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, f, n);
-}
-
-// установить палитру из массива p
-void VP_setall (void *p) {
- VP_set(p, 0, 256);
-}
-
-// установить адрес экранного буфера
-// NULL - реальный экран
void V_setscr (void *p) {
- if (screen) SDL_Flip(screen);
+ Y_repaint();
}
-// скопировать прямоугольник на экран
void V_copytoscr (short x, short w, short y, short h) {
- x*=HQ; y*=HQ; w*=HQ; h*=HQ;
- SDL_UpdateRect(screen, x, y, w, h);
+ Y_repaint_rect(x, y, w, h);
}
void V_maptoscr (int x, int w, int y, int h, void *cmap) {
for (cy=y; cy<y+h; cy++)
mappixel(cx,cy,cmap);
}
-
-void V_toggle (void) {
- if (!SDL_WM_ToggleFullScreen(screen)) {
- int ncolors = screen->format->palette->ncolors;
- SDL_Color colors[256];
- int i;
- for (i=0; i<ncolors; i++) {
- colors[i].r = screen->format->palette->colors[i].r;
- colors[i].g = screen->format->palette->colors[i].g;
- colors[i].b = screen->format->palette->colors[i].b;
- }
-
- Uint32 flags = screen->flags;
-
- SDL_FreeSurface(screen);
-
- screen = SDL_SetVideoMode(0, 0, 0, flags ^ SDL_FULLSCREEN);
- if(screen == NULL) {
- ERR_fatal("Unable to set video mode\n");
- exit(1);
- }
-
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, ncolors);
- }
-}