1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-23 23:32:45 +00:00

Use vm_area for draw_rect.

This simplifies and to some degree normalizes the way we reference areas
in the vm subsystem.
This commit is contained in:
Peter Evans 2017-12-27 16:42:30 -06:00
parent c7b830bb4a
commit efb8f04555
3 changed files with 15 additions and 27 deletions

View File

@ -7,14 +7,6 @@
#define VM_SCREEN_DEFWIDTH 800
#define VM_SCREEN_DEFHEIGHT 600
/*
* If you just want to plot a single pixel, you can use this macro to
* abstract away the need to indicate the x/y dimensions (as those must
* necessarily be 1x1).
*/
#define vm_screen_draw_pixel(screen, xpos, ypos) \
vm_screen_draw_rect(screen, xpos, ypos, 1, 1)
typedef struct {
int xoff;
int yoff;
@ -54,7 +46,7 @@ extern int vm_screen_init();
extern int vm_screen_xcoords(vm_screen *);
extern int vm_screen_ycoords(vm_screen *);
extern vm_screen *vm_screen_create();
extern void vm_screen_draw_rect(vm_screen *, int, int, int, int);
extern void vm_screen_draw_rect(vm_screen *, vm_area *);
extern void vm_screen_finish();
extern void vm_screen_free(vm_screen *);
extern void vm_screen_refresh(vm_screen *);

View File

@ -42,7 +42,7 @@ apple2_draw_pixel_lores(apple2 *mach, vm_16bit addr)
{
vm_8bit color = vm_segment_get(mach->memory, addr);
vm_8bit top, bottom;
SDL_Rect loc;
vm_area loc;
int *colors;
// The top color is the low order nibble, so we can blank out the
@ -53,18 +53,23 @@ apple2_draw_pixel_lores(apple2 *mach, vm_16bit addr)
bottom = color >> 4;
// The next thing we need to consider is where we draw the pixel
loc.x = (addr & 0xff) * mach->sysfont->width;
loc.y = (addr >> 8) * mach->sysfont->height;
loc.w = mach->sysfont->width;
loc.h = mach->sysfont->height / 2;
loc.xoff = (addr & 0xff) * mach->sysfont->width;
loc.yoff = (addr >> 8) * mach->sysfont->height;
loc.width = mach->sysfont->width;
loc.height = mach->sysfont->height / 2;
colors = lores_colors[top];
vm_screen_set_color(mach->screen, colors[0], colors[1], colors[2], 255);
vm_screen_draw_rect(mach->screen, loc.x, loc.y, loc.w, loc.h);
vm_screen_draw_rect(mach->screen, &loc);
// The bottom pixel we need to draw now must be offset by the height
// of the pixel we just drew. (Remember, positive equals down in the
// y-axis.)
loc.yoff += loc.height;
colors = lores_colors[bottom];
vm_screen_set_color(mach->screen, colors[0], colors[1], colors[2], 255);
vm_screen_draw_rect(mach->screen, loc.x, loc.y + loc.h, loc.w, loc.h);
vm_screen_draw_rect(mach->screen, &loc);
}
void

View File

@ -204,20 +204,11 @@ vm_screen_set_color(vm_screen *screen,
* set of x/y dimensions, with a given screen.
*/
void
vm_screen_draw_rect(vm_screen *screen,
int xpos,
int ypos,
int xsize,
int ysize)
vm_screen_draw_rect(vm_screen *screen, vm_area *area)
{
SDL_Rect rect;
// The renderer will take care of translating the positions and
// sizes into whatever the window is really at.
rect.x = xpos;
rect.y = ypos;
rect.w = xsize;
rect.h = ysize;
MAKE_SDL_RECT(rect, *area);
SDL_RenderFillRect(screen->render, &rect);
}