Skip to content

Commit

Permalink
uxnds 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed May 21, 2021
1 parent e0b6a7f commit c36780b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 12 additions & 15 deletions arm9/source/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
}

Expand Down
36 changes: 11 additions & 25 deletions arm9/source/ppu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WITH REGARD TO THIS SOFTWARE.

#include <nds.h>

#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
Expand Down

0 comments on commit c36780b

Please sign in to comment.