From c36780b42d675b5af2668e69c88d254ccb5726d1 Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 21 May 2021 09:31:32 +0200 Subject: [PATCH] uxnds 0.2.2 --- Makefile | 4 ++-- arm7/source/main.c | 2 +- arm9/source/emulator.c | 27 ++++++++++++--------------- arm9/source/ppu.c | 36 +++++++++++------------------------- include/fifo.h | 1 + 5 files changed, 27 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index d3fda53..36ec8b8 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,9 @@ export TOPDIR := $(CURDIR) NITRO_FILES := # These set the information text in the nds file -GAME_TITLE := uxnds v0.2.1 +GAME_TITLE := uxnds v0.2.2 GAME_SUBTITLE1 := tiny virtual machine -GAME_SUBTITLE2 := 20/05/2021 +GAME_SUBTITLE2 := 21/05/2021 include $(DEVKITARM)/ds_rules diff --git a/arm7/source/main.c b/arm7/source/main.c index c821fa0..2936b9a 100644 --- a/arm7/source/main.c +++ b/arm7/source/main.c @@ -79,7 +79,7 @@ void fifo_handler(u32 cmd, void *unused) { case UXNDS_FIFO_CMD_SET_ADDR: sampling_addr = (s16*) (cmd & ~UXNDS_FIFO_CMD_MASK); sampling_pos = 0; - sampling_bufsize = 512; + sampling_bufsize = UXNDS_AUDIO_BUFFER_SIZE; SCHANNEL_CR(0) = 0; SCHANNEL_TIMER(0) = sampling_timer_freq; diff --git a/arm9/source/emulator.c b/arm9/source/emulator.c index 535ff8e..ff43c66 100644 --- a/arm9/source/emulator.c +++ b/arm9/source/emulator.c @@ -22,7 +22,7 @@ WITH REGARD TO THIS SOFTWARE. DTCM_BSS static Ppu ppu; static Apu apu[POLYPHONY]; -static u32 apu_samples[(512 * 4) >> 1]; +static u32 apu_samples[(UXNDS_AUDIO_BUFFER_SIZE * 4) >> 1]; static Device *devscreen, *devctrl, *devmouse, *devaudio0; Uint8 dispswap = 0, debug = 0; @@ -216,24 +216,14 @@ doctrl(Uxn *u) } static touchPosition tpos; -static Uint8 last_dispswap = 0; +static Uint8 istouching = 0; void domouse(Uxn *u) { - bool firstTouch; - - if (last_dispswap || (keysUp() & KEY_TOUCH)) { - mempoke16(devmouse->dat, 0x2, tpos.px); - mempoke16(devmouse->dat, 0x4, tpos.py); - devmouse->dat[6] = 0x00; - devmouse->dat[7] = 0x00; - evaluxn(u, mempeek16(devmouse->dat, 0)); - last_dispswap = 0; - } else if (dispswap && ((keysDown() | keysHeld()) & KEY_TOUCH)) { - firstTouch = (keysDown() & KEY_TOUCH); + if (dispswap && (keysHeld() & KEY_TOUCH)) { touchRead(&tpos); - if (firstTouch + if (!istouching || mempeek16(devmouse->dat, 0x2) != tpos.px || mempeek16(devmouse->dat, 0x4) != tpos.py) { @@ -242,8 +232,15 @@ domouse(Uxn *u) devmouse->dat[6] = 0x01; devmouse->dat[7] = 0x00; evaluxn(u, mempeek16(devmouse->dat, 0)); - last_dispswap = 1; + istouching = 1; } + } else if (istouching) { + mempoke16(devmouse->dat, 0x2, tpos.px); + mempoke16(devmouse->dat, 0x4, tpos.py); + devmouse->dat[6] = 0x00; + devmouse->dat[7] = 0x00; + evaluxn(u, mempeek16(devmouse->dat, 0)); + istouching = 0; } } diff --git a/arm9/source/ppu.c b/arm9/source/ppu.c index a9a5321..fd442c2 100644 --- a/arm9/source/ppu.c +++ b/arm9/source/ppu.c @@ -196,33 +196,19 @@ drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr) } } */ +typedef struct { + Uint32 a, b, c, d, e, f, g, h; +} TileBackup; + DTCM_BSS -static Uint32 tile_backup[8]; +static TileBackup tile_backup; static inline void -copytile(Uint32 *tptr) +copytile(TileBackup *tptr) { - // TODO: use ldmia/stmia for faster performance - - tile_backup[0] = tptr[0]; - tile_backup[1] = tptr[1]; - tile_backup[2] = tptr[2]; - tile_backup[3] = tptr[3]; - tile_backup[4] = tptr[4]; - tile_backup[5] = tptr[5]; - tile_backup[6] = tptr[6]; - tile_backup[7] = tptr[7]; - - tptr = (Uint32*) (((u32) tptr) & 0xFFFEFFFF); - - tptr[0] = tile_backup[0]; - tptr[1] = tile_backup[1]; - tptr[2] = tile_backup[2]; - tptr[3] = tile_backup[3]; - tptr[4] = tile_backup[4]; - tptr[5] = tile_backup[5]; - tptr[6] = tile_backup[6]; - tptr[7] = tile_backup[7]; + tile_backup = *tptr; + tptr = (TileBackup*) (((u32) tptr) & 0xFFFEFFFF); + *tptr = tile_backup; } ITCM_ARM_CODE @@ -237,8 +223,8 @@ copyppu(Ppu *p) k = 1; for (j = 0; j < 32; j++, ofs += 8, k <<= 1) { if (tile_dirty[i] & k) { - copytile(p->bg + ofs); - copytile(p->fg + ofs); + copytile((TileBackup*) (p->bg + ofs)); + copytile((TileBackup*) (p->fg + ofs)); } } tile_dirty[i] = 0; diff --git a/include/fifo.h b/include/fifo.h index d344a59..c367189 100644 --- a/include/fifo.h +++ b/include/fifo.h @@ -11,6 +11,7 @@ WITH REGARD TO THIS SOFTWARE. #include +#define UXNDS_AUDIO_BUFFER_SIZE 512 #define UXNDS_FIFO_CHANNEL FIFO_USER_01 #define UXNDS_FIFO_CMD_SET_RATE 0x10000000 #define UXNDS_FIFO_CMD_SET_ADDR 0x20000000