| ... | ... |
@@ -78,5 +78,15 @@ ppu_init(Ppu *p, Uint8 hor, Uint8 ver) |
| 78 | 78 |
p->height = 8 * ver; |
| 79 | 79 |
p->bg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); |
| 80 | 80 |
p->fg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); |
| 81 |
- return 1; |
|
| 81 |
+ return p->bg && p->fg; |
|
| 82 | 82 |
} |
| 83 |
+ |
|
| 84 |
+int |
|
| 85 |
+ppu_resize(Ppu *p, Uint8 hor, Uint8 ver) |
|
| 86 |
+{
|
|
| 87 |
+ p->width = 8 * hor; |
|
| 88 |
+ p->height = 8 * ver; |
|
| 89 |
+ p->bg = realloc(p->bg, p->width / 4 * p->height * sizeof(Uint8)); |
|
| 90 |
+ p->fg = realloc(p->fg, p->width / 4 * p->height * sizeof(Uint8)); |
|
| 91 |
+ return p->bg && p->fg; |
|
| 92 |
+} |
|
| 83 | 93 |
\ No newline at end of file |
| ... | ... |
@@ -23,6 +23,7 @@ typedef struct Ppu {
|
| 23 | 23 |
} Ppu; |
| 24 | 24 |
|
| 25 | 25 |
int ppu_init(Ppu *p, Uint8 hor, Uint8 ver); |
| 26 |
+int ppu_resize(Ppu *p, Uint8 hor, Uint8 ver); |
|
| 26 | 27 |
void ppu_pixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color); |
| 27 | 28 |
void ppu_1bpp(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
| 28 | 29 |
void ppu_2bpp(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
| ... | ... |
@@ -298,6 +298,21 @@ update_palette(Uint8 *addr) |
| 298 | 298 |
reqdraw = 1; |
| 299 | 299 |
} |
| 300 | 300 |
|
| 301 |
+void |
|
| 302 |
+set_size(Uxn *u, Uint16 width, Uint16 height) |
|
| 303 |
+{
|
|
| 304 |
+ ppu_resize(&ppu, width / 8, height / 8); |
|
| 305 |
+ gRect.w = ppu.width; |
|
| 306 |
+ gRect.h = ppu.height; |
|
| 307 |
+ if(!(ppu_screen = realloc(ppu_screen, ppu.width * ppu.height * sizeof(Uint32)))) |
|
| 308 |
+ return; |
|
| 309 |
+ SDL_DestroyTexture(gTexture); |
|
| 310 |
+ SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2); |
|
| 311 |
+ gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2); |
|
| 312 |
+ SDL_SetWindowSize(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom); |
|
| 313 |
+ redraw(u); |
|
| 314 |
+} |
|
| 315 |
+ |
|
| 301 | 316 |
#pragma mark - Devices |
| 302 | 317 |
|
| 303 | 318 |
static int |
| ... | ... |
@@ -331,7 +346,13 @@ console_talk(Device *d, Uint8 b0, Uint8 w) |
| 331 | 346 |
static int |
| 332 | 347 |
screen_talk(Device *d, Uint8 b0, Uint8 w) |
| 333 | 348 |
{
|
| 334 |
- if(w && b0 == 0xe) {
|
|
| 349 |
+ if(!w) |
|
| 350 |
+ return 1; |
|
| 351 |
+ if(b0 == 0x3) |
|
| 352 |
+ set_size(d->u, peek16(d->dat, 0x2), ppu.height); |
|
| 353 |
+ else if(b0 == 0x5) |
|
| 354 |
+ set_size(d->u, ppu.width, peek16(d->dat, 0x4)); |
|
| 355 |
+ else if(b0 == 0xe) {
|
|
| 335 | 356 |
Uint16 x = peek16(d->dat, 0x8); |
| 336 | 357 |
Uint16 y = peek16(d->dat, 0xa); |
| 337 | 358 |
Uint8 layer = d->dat[0xe] & 0x40; |
| ... | ... |
@@ -339,7 +360,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) |
| 339 | 360 |
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */ |
| 340 | 361 |
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */ |
| 341 | 362 |
reqdraw = 1; |
| 342 |
- } else if(w && b0 == 0xf) {
|
|
| 363 |
+ } else if(b0 == 0xf) {
|
|
| 343 | 364 |
Uint16 x = peek16(d->dat, 0x8); |
| 344 | 365 |
Uint16 y = peek16(d->dat, 0xa); |
| 345 | 366 |
Uint8 layer = d->dat[0xf] & 0x40; |