Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to SDL2 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

CFLAGS := -O3 -Wall -Wextra $(shell sdl-config --cflags)
LIBS := $(shell sdl-config --libs) -lSDL_gfx -lSDL_image
CFLAGS := -O3 -Wall -Wextra $(shell sdl2-config --cflags)
LIBS := $(shell sdl2-config --libs) -lSDL2_gfx
OBJECTS := e6809.o e8910.o osint.o vecx.o
TARGET := vecx
CLEANFILES := $(TARGET) $(OBJECTS)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Requirements
------------
* `libsdl`
* `sdl_gfx`
* `sdl_image`

Usage
-----
Expand All @@ -19,4 +18,8 @@ Authors
* [John Hawthorn](https://twitter.com/jhawthorn) - SDL port
* [Nikita Zimin](https://twitter.com/nzeemin) - audio

Contributors
-------
* [Simon Rodriguez](https://twitter.com/simonkosua) - SDL2 port


2 changes: 1 addition & 1 deletion e6809.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* the lower bits with the unused upper bits all set to zero.
*/

#define einline __inline
#define einline static __inline

enum {
FLAG_E = 0x80,
Expand Down
53 changes: 29 additions & 24 deletions osint.c
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_gfxPrimitives.h"
#include "SDL_rotozoom.h"
#include "SDL2_gfxPrimitives.h"

#include "osint.h"
#include "e8910.h"
#include "vecx.h"

#define EMU_TIMER 20 /* the emulators heart beats at 20 milliseconds */

static SDL_Surface *screen = NULL;
static SDL_Surface *overlay_original = NULL;
static SDL_Surface *overlay = NULL;
static SDL_Window *screen = NULL;
static SDL_Renderer *renderer= NULL;
static SDL_Texture *overlay = NULL;

static long scl_factor;
static long offx;
static long offy;

void osint_render(void){
SDL_FillRect(screen, NULL, 0);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);

int v;
for(v = 0; v < vector_draw_cnt; v++){
Uint8 c = vectors_draw[v].color * 256 / VECTREX_COLORS;
aalineRGBA(screen,
aalineRGBA(renderer,
offx + vectors_draw[v].x0 / scl_factor,
offy + vectors_draw[v].y0 / scl_factor,
offx + vectors_draw[v].x1 / scl_factor,
offy + vectors_draw[v].y1 / scl_factor,
c, c, c, 0xff);
}
if(overlay){
SDL_Rect dest_rect = {offx, offy, 0, 0};
SDL_BlitSurface(overlay, NULL, screen, &dest_rect);
SDL_Rect dest_rect = {offx, offy, ((double)ALG_MAX_X / (double)scl_factor), ((double)ALG_MAX_Y / (double)scl_factor)};
SDL_RenderCopy(renderer, overlay, NULL, &dest_rect);
}
SDL_Flip(screen);
SDL_RenderPresent(renderer);
}

static char *romfilename = "rom.dat";
Expand Down Expand Up @@ -70,22 +70,14 @@ void resize(int width, int height){

long screenx = width;
long screeny = height;
screen = SDL_SetVideoMode(screenx, screeny, 0, SDL_SWSURFACE | SDL_RESIZABLE);

sclx = ALG_MAX_X / screen->w;
scly = ALG_MAX_Y / screen->h;
sclx = ALG_MAX_X / width;
scly = ALG_MAX_Y / height;

scl_factor = sclx > scly ? sclx : scly;

offx = (screenx - ALG_MAX_X / scl_factor) / 2;
offy = (screeny - ALG_MAX_Y / scl_factor) / 2;

if(overlay_original){
if(overlay)
SDL_FreeSurface(overlay);
double overlay_scale = ((double)ALG_MAX_X / (double)scl_factor) / (double)overlay_original->w;
overlay = zoomSurface(overlay_original, overlay_scale, overlay_scale, 0);
}
}

static void readevents(){
Expand All @@ -95,8 +87,15 @@ static void readevents(){
case SDL_QUIT:
exit(EXIT_SUCCESS);
break;
case SDL_VIDEORESIZE:
resize(e.resize.w, e.resize.h);
case SDL_WINDOWEVENT:
switch (e.window.event) {
case SDL_WINDOWEVENT_RESIZED:
resize(e.window.data1, e.window.data2);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
resize(e.window.data1, e.window.data2);
break;
}
break;
case SDL_KEYDOWN:
switch(e.key.keysym.sym){
Expand Down Expand Up @@ -186,9 +185,10 @@ void osint_emuloop(){

void load_overlay(const char *filename){
SDL_Surface *image;
image = IMG_Load(filename);
image = SDL_LoadBMP(filename);
if(image){
overlay_original = image;
overlay = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
}else{
fprintf(stderr, "IMG_Load: %s\n", IMG_GetError());
}
Expand All @@ -199,6 +199,11 @@ int main(int argc, char *argv[]){
fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
exit(-1);
}
SDL_CreateWindowAndRenderer(330*3/2, 410*3/2, SDL_WINDOW_RESIZABLE, &screen, &renderer);
if(screen == NULL || renderer == NULL){
fprintf(stderr, "Failed to initialize SDL window/renderer: %s\n", SDL_GetError());
exit(-2);
}

resize(330*3/2, 410*3/2);

Expand Down