mirror of
https://github.com/pevans/erc-c.git
synced 2025-02-05 19:31:34 +00:00
Move vm_area logic into its own file
This commit is contained in:
parent
143a2b176c
commit
b2add9c3de
45
include/vm_area.h
Normal file
45
include/vm_area.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef _VM_AREA_H_
|
||||||
|
#define _VM_AREA_H_
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/*
|
||||||
|
* These are the x and y coordinate offsets in the logical dimension
|
||||||
|
* established in a vm_screen. An offset of (0, 0) would be in the
|
||||||
|
* top-left; (5, 5) would be 5 pixels down, and 5 pixels to the
|
||||||
|
* right, of that top-left corner.
|
||||||
|
*/
|
||||||
|
int xoff;
|
||||||
|
int yoff;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are the width and height of the area we're defining. A
|
||||||
|
* single pixel in the logical area would have a width and height of
|
||||||
|
* (1, 1); use larger numbers to indicate a larger square (if the
|
||||||
|
* two are equal) or rectangle (if unequal).
|
||||||
|
*/
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
} vm_area;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the contents of an SDL_Rect to the equivalent fields contained in
|
||||||
|
* a vm_area.
|
||||||
|
*/
|
||||||
|
#define SET_SDL_RECT(name, a) \
|
||||||
|
(name).x = (a).xoff; \
|
||||||
|
(name).y = (a).yoff; \
|
||||||
|
(name).w = (a).width; \
|
||||||
|
(name).h = (a).height
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Much like SET_SDL_RECT(), except this will (as a side-effect!)
|
||||||
|
* declare an SDL_Rect variable (`name`) and pass that into the SET
|
||||||
|
* macro.
|
||||||
|
*/
|
||||||
|
#define MAKE_SDL_RECT(name, a) \
|
||||||
|
SDL_Rect name; \
|
||||||
|
SET_SDL_RECT(name, a)
|
||||||
|
|
||||||
|
extern void vm_area_set(vm_area *, int, int, int, int);
|
||||||
|
|
||||||
|
#endif
|
@ -4,25 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
typedef struct {
|
#include "vm_area.h"
|
||||||
/*
|
|
||||||
* These are the x and y coordinate offsets in the logical dimension
|
|
||||||
* established in a vm_screen. An offset of (0, 0) would be in the
|
|
||||||
* top-left; (5, 5) would be 5 pixels down, and 5 pixels to the
|
|
||||||
* right, of that top-left corner.
|
|
||||||
*/
|
|
||||||
int xoff;
|
|
||||||
int yoff;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These are the width and height of the area we're defining. A
|
|
||||||
* single pixel in the logical area would have a width and height of
|
|
||||||
* (1, 1); use larger numbers to indicate a larger square (if the
|
|
||||||
* two are equal) or rectangle (if unequal).
|
|
||||||
*/
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
} vm_area;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*
|
/*
|
||||||
@ -49,27 +31,7 @@ typedef struct {
|
|||||||
int ycoords;
|
int ycoords;
|
||||||
} vm_screen;
|
} vm_screen;
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the contents of an SDL_Rect to the equivalent fields contained in
|
|
||||||
* a vm_area.
|
|
||||||
*/
|
|
||||||
#define SET_SDL_RECT(name, a) \
|
|
||||||
(name).x = (a).xoff; \
|
|
||||||
(name).y = (a).yoff; \
|
|
||||||
(name).w = (a).width; \
|
|
||||||
(name).h = (a).height
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Much like SET_SDL_RECT(), except this will (as a side-effect!)
|
|
||||||
* declare an SDL_Rect variable (`name`) and pass that into the SET
|
|
||||||
* macro.
|
|
||||||
*/
|
|
||||||
#define MAKE_SDL_RECT(name, a) \
|
|
||||||
SDL_Rect name; \
|
|
||||||
SET_SDL_RECT(name, a)
|
|
||||||
|
|
||||||
extern bool vm_screen_active(vm_screen *);
|
extern bool vm_screen_active(vm_screen *);
|
||||||
extern void vm_area_set(vm_area *, int, int, int, int);
|
|
||||||
extern int vm_screen_add_window(vm_screen *, int, int);
|
extern int vm_screen_add_window(vm_screen *, int, int);
|
||||||
extern int vm_screen_init();
|
extern int vm_screen_init();
|
||||||
extern int vm_screen_xcoords(vm_screen *);
|
extern int vm_screen_xcoords(vm_screen *);
|
||||||
|
@ -15,6 +15,7 @@ set(erc_sources
|
|||||||
mos6502.stat.c
|
mos6502.stat.c
|
||||||
objstore.c
|
objstore.c
|
||||||
option.c
|
option.c
|
||||||
|
vm_area.c
|
||||||
vm_bitfont.c
|
vm_bitfont.c
|
||||||
vm_screen.c
|
vm_screen.c
|
||||||
vm_segment.c
|
vm_segment.c
|
||||||
|
18
src/vm_area.c
Normal file
18
src/vm_area.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* vm_area.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vm_area.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Assign the values of an area, which are an x and y offset plus a
|
||||||
|
* width and height.
|
||||||
|
*/
|
||||||
|
inline void
|
||||||
|
vm_area_set(vm_area *area, int xoff, int yoff, int width, int height)
|
||||||
|
{
|
||||||
|
area->xoff = xoff;
|
||||||
|
area->yoff = yoff;
|
||||||
|
area->width = width;
|
||||||
|
area->height = height;
|
||||||
|
}
|
@ -210,16 +210,3 @@ vm_screen_draw_rect(vm_screen *screen, vm_area *area)
|
|||||||
|
|
||||||
SDL_RenderFillRect(screen->render, &rect);
|
SDL_RenderFillRect(screen->render, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Assign the values of an area, which are an x and y offset plus a
|
|
||||||
* width and height.
|
|
||||||
*/
|
|
||||||
inline void
|
|
||||||
vm_area_set(vm_area *area, int xoff, int yoff, int width, int height)
|
|
||||||
{
|
|
||||||
area->xoff = xoff;
|
|
||||||
area->yoff = yoff;
|
|
||||||
area->width = width;
|
|
||||||
area->height = height;
|
|
||||||
}
|
|
||||||
|
14
tests/vm_area.c
Normal file
14
tests/vm_area.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <criterion/criterion.h>
|
||||||
|
|
||||||
|
#include "vm_area.h"
|
||||||
|
|
||||||
|
Test(vm_area, set)
|
||||||
|
{
|
||||||
|
vm_area area;
|
||||||
|
|
||||||
|
vm_area_set(&area, 1, 2, 3, 4);
|
||||||
|
cr_assert_eq(area.xoff, 1);
|
||||||
|
cr_assert_eq(area.yoff, 2);
|
||||||
|
cr_assert_eq(area.width, 3);
|
||||||
|
cr_assert_eq(area.height, 4);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user