uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit bca5562eeca8a9e2f34ddb11cc082c5a6215e118
parent 3d8cf7c25715db0354d15e55e3e04623a91c6f95
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 18 Sep 2021 16:51:20 -0700

The screen width/height ports can be written to

Diffstat:
Mprojects/examples/demos/piano.tal | 3+++
Mprojects/software/calc.tal | 3+++
Msrc/devices/ppu.c | 13++++++++++++-
Msrc/devices/ppu.h | 1+
Msrc/uxnemu.c | 25+++++++++++++++++++++++--
5 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal @@ -54,6 +54,9 @@ ;on-mouse .Mouse/vector DEO2 ;on-message .Console/vector DEO2 + #0160 .Screen/width DEO2 + #0100 .Screen/height DEO2 + ( find center ) .Screen/width DEI2 2// .center/x STZ2 .Screen/height DEI2 2// .center/y STZ2 diff --git a/projects/software/calc.tal b/projects/software/calc.tal @@ -62,6 +62,9 @@ #0fc5 .System/g DEO2 #0f25 .System/b DEO2 + #0100 .Screen/width DEO2 + #0160 .Screen/height DEO2 + ( center ) .Screen/width DEI2 2// .center/x STZ2 .Screen/height DEI2 2// .center/y STZ2 diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -78,5 +78,15 @@ ppu_init(Ppu *p, Uint8 hor, Uint8 ver) p->height = 8 * ver; p->bg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); p->fg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); - return 1; + return p->bg && p->fg; } + +int +ppu_resize(Ppu *p, Uint8 hor, Uint8 ver) +{ + p->width = 8 * hor; + p->height = 8 * ver; + p->bg = realloc(p->bg, p->width / 4 * p->height * sizeof(Uint8)); + p->fg = realloc(p->fg, p->width / 4 * p->height * sizeof(Uint8)); + return p->bg && p->fg; +} +\ No newline at end of file diff --git a/src/devices/ppu.h b/src/devices/ppu.h @@ -23,6 +23,7 @@ typedef struct Ppu { } Ppu; int ppu_init(Ppu *p, Uint8 hor, Uint8 ver); +int ppu_resize(Ppu *p, Uint8 hor, Uint8 ver); void ppu_pixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color); void ppu_1bpp(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); void ppu_2bpp(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -298,6 +298,21 @@ update_palette(Uint8 *addr) reqdraw = 1; } +void +set_size(Uxn *u, Uint16 width, Uint16 height) +{ + ppu_resize(&ppu, width / 8, height / 8); + gRect.w = ppu.width; + gRect.h = ppu.height; + if(!(ppu_screen = realloc(ppu_screen, ppu.width * ppu.height * sizeof(Uint32)))) + return; + SDL_DestroyTexture(gTexture); + SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2); + gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2); + SDL_SetWindowSize(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom); + redraw(u); +} + #pragma mark - Devices static int @@ -331,7 +346,13 @@ console_talk(Device *d, Uint8 b0, Uint8 w) static int screen_talk(Device *d, Uint8 b0, Uint8 w) { - if(w && b0 == 0xe) { + if(!w) + return 1; + if(b0 == 0x3) + set_size(d->u, peek16(d->dat, 0x2), ppu.height); + else if(b0 == 0x5) + set_size(d->u, ppu.width, peek16(d->dat, 0x4)); + else if(b0 == 0xe) { Uint16 x = peek16(d->dat, 0x8); Uint16 y = peek16(d->dat, 0xa); Uint8 layer = d->dat[0xe] & 0x40; @@ -339,7 +360,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */ if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */ reqdraw = 1; - } else if(w && b0 == 0xf) { + } else if(b0 == 0xf) { Uint16 x = peek16(d->dat, 0x8); Uint16 y = peek16(d->dat, 0xa); Uint8 layer = d->dat[0xf] & 0x40;