1
0
mirror of https://github.com/rzzzwilson/pymlac.git synced 2025-06-10 09:32:41 +00:00

Title and close button, button doesn't work, TWO SCREENS?

This commit is contained in:
Ross Wilson
2018-08-03 11:48:26 +07:00
parent e45b11c5b1
commit fe65fb3a0b
6 changed files with 85 additions and 12 deletions

View File

@@ -3,7 +3,8 @@ CFILES = cpu.c dcpu.c ptrptp.c memory.c kb.c ttyin.c ttyout.c trace.c error.c lo
HFILES = cpu.h dcpu.h ptrptp.h memory.h kb.h ttyin.h ttyout.h trace.h error.h log.h plist.h bootstrap.h display_sdl.h
OFILES = vimlac.o $(DEVFILES)
CFLAGS=-O2 -Wall -pedantic -std=c99 -g -I /usr/local/include/SDL2/ -l SDL2-2.0.0
CFLAGS=-O2 -Wall -pedantic -std=c99 -g -I /usr/local/include/SDL2/
LDFLAGS=-l SDL2-2.0.0
test: vimlac
rm -f vimlac.log trace.out *.pbm; time ./vimlac -b ptr -ptr chars.ptp -r 040 -r 0100
@@ -15,7 +16,7 @@ test_cpu: test_cpu.c $(DEVFILES) Makefile
gcc -o test_cpu ${CFLAGS} $(DEVFILES) test_cpu.c
vimlac: ${OFILES} Makefile
gcc -o vimlac ${CFLAGS} ${OFILES}
gcc -o vimlac ${CFLAGS} ${OFILES} ${LDFLAGS}
test_ptr: test_ptr.c ptrptp.c error.c Makefile
gcc -o test_ptr ${CFLAGS} error.c ptrptp.c test_ptr.c

View File

@@ -141,6 +141,12 @@ cpu_running(void)
}
void
cpu_abort(void)
{
cpu_on = false;
}
void
cpu_set_AC(WORD new_ac)
{

View File

@@ -25,6 +25,7 @@ void cpu_set_AC(WORD ac);
void cpu_set_L(WORD l);
void cpu_set_PC(WORD pc);
void cpu_set_DS(WORD ds);
void cpu_abort(void);
#endif

View File

@@ -9,7 +9,7 @@
#include "vimlac.h"
#include "dcpu.h"
#include "memory.h"
#include "display_pbm.h"
#include "display.h"
#include "log.h"
#include "trace.h"

View File

@@ -17,8 +17,13 @@
* Constants, etc.
******/
#define MAX_X 512 // max X coord
#define MAX_Y 512 // max Y coord
// screen/display stuff
#define MAX_X 512 // max X coord for display
#define MAX_Y 512 // max Y coord for display
#define SCALE_MAX_X 2048 // max vimlac X coord
#define SCALE_MAX_Y 2048 // max vimlac Y coord
// initial and increment size for dynamic DisplayList
#define DL_INIT_SIZE 2048 // initial size of the DisplayList array
#define DL_INC_SIZE 1024 // how much we increase DisplayList size
@@ -32,10 +37,10 @@ typedef struct DrawLine
} DrawLine;
// display state variables
static SDL_Window* window = NULL; // the SDL window reference
static SDL_Renderer* renderer = NULL; // reference to SDL renderer
static SDL_Window *window = NULL; // the SDL window reference
static SDL_Renderer *renderer = NULL; // reference to SDL renderer
static DrawLine *DisplayList; // the DrawLine array
static DrawLine *DisplayList; // the DrawLine array (dynamic)
static int DisplayListSize = 0; // current size of the dynamic DisplayList
static int NumLines = 0; // number of lines in DisplayList
static bool DisplayDirty = false; // true if the DisplayList has changed
@@ -69,6 +74,16 @@ void display_draw(int x1, int y1, int x2, int y2)
DisplayListSize = newsize;
}
// invert the Y coords
y1 = SCALE_MAX_Y - y1;
y2 = SCALE_MAX_Y - y2;
// scale line coords
x1 = x1 / (SCALE_MAX_X / MAX_X);
y1 = y1 / (SCALE_MAX_Y / MAX_Y);
x2 = x2 / (SCALE_MAX_X / MAX_X);
y2 = y2 / (SCALE_MAX_Y / MAX_Y);
// add new line to DisplayList
DrawLine *p = &DisplayList[NumLines++];
@@ -131,18 +146,58 @@ Description : Initialize the SDL system.
bool display_init()
{
printf("display_init: called\n");
SDL_DisplayMode dm;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
return false;
if (SDL_CreateWindowAndRenderer(MAX_X, MAX_Y, 0, &window, &renderer) != 0)
if (SDL_GetDesktopDisplayMode(0, &dm) != 0)
{
printf("SDL_GetDesktopDisplayMode failed: %s\n", SDL_GetError());
return false;
}
printf("Screen wxh = %d x %d\n", dm.w, dm.h);
// if (SDL_CreateWindowAndRenderer(MAX_X, MAX_Y, 0, &window, &renderer) != 0)
// {
// if (renderer)
// SDL_DestroyRenderer(renderer);
// if (window)
// SDL_DestroyWindow(window);
// return false;
// }
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, MAX_X,
MAX_Y, SDL_WINDOW_SHOWN);
// window = SDL_CreateWindow(
// "An SDL2 window", // window title
// SDL_WINDOWPOS_UNDEFINED, // initial x position
// SDL_WINDOWPOS_UNDEFINED, // initial y position
// MAX_X, // width, in pixels
// MAX_Y, // height, in pixels
// SDL_WINDOW_OPENGL // flags - see below
// );
if (!window)
{
return false;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer)
{
if (renderer)
SDL_DestroyRenderer(renderer);
if (window)
SDL_DestroyWindow(window);
return false;
}
// set window title
SDL_SetWindowTitle(window, "vimlac 0.1");
// allocate the initial DisplayList array
DisplayList = malloc(sizeof(DrawLine) * DL_INIT_SIZE);
if (DisplayList)

View File

@@ -32,12 +32,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <SDL.h>
#include "vimlac.h"
#include "bootstrap.h"
#include "memory.h"
#include "ptrptp.h"
//#include "display_pbm.h"
#include "display.h"
#include "cpu.h"
#include "dcpu.h"
@@ -140,6 +140,16 @@ run(WORD pc)
if (!dcpu_running() && display_dirty())
display_write();
SDL_Event e;
while (SDL_PollEvent(&e) != 0)
{
if (e.type == SDL_QUIT)
{
cpu_abort();
printf("cpu_on set to %s\n", cpu_running() ? "true" : "false");
}
}
}
trace_close();