~vdupras/duskos

6d37181369052b92f1aa59e129d86562a0066b61 — Virgil Dupras 13 days ago c67fc35
emul/uxn: CC was fine, it was me who was stupid
1 files changed, 13 insertions(+), 28 deletions(-)

M fs/emul/uxn/vm.c
M fs/emul/uxn/vm.c => fs/emul/uxn/vm.c +13 -28
@@ 37,13 37,12 @@ static void error(int code) {
	abort();
}

// TODO: have pointer arithmetics strong enough to use something like this:
// static unsigned short gw(unsigned short *a) { return *a<<8|*(a+1); }
// static void sw(unsigned short *a, unsigned short val) {
//	   *a = val>>8; *(a+1) = val; }
static unsigned short gw(unsigned char *a) { return *a<<8|*(a+1); }
static void sw(unsigned char *a, unsigned short val) {
	*a = val>>8; *(a+1) = val; }

static unsigned short signext(unsigned short val) {
    // TODO: allow sign-extending through typecasting
	// TODO: allow sign-extending through typecasting
	if (val >= $80) return val - $100; else return val;
}



@@ 52,13 51,12 @@ static void push8(Stack *s, unsigned char val) {
}
static void push16(Stack *s, unsigned short val) {
	if (s->ptr >= $fe) { error(2); } else {
		s->dat[s->ptr] = val >> 8;
		s->dat[s->ptr+1] = val;
		sw(&s->dat[s->ptr], val);
		s->ptr += 2 ;
	}
}
static void pushs(Stack *s, unsigned short val) {
    if (bs) push16(s, val); else push8(s, val); }
	if (bs) push16(s, val); else push8(s, val); }
static void push(unsigned short val) { pushs(src, val); }

static unsigned char pop8() {


@@ 68,29 66,16 @@ static unsigned short pop16() {
	unsigned short val;
	if (*sp <= 1) { error(0); } else {
		*sp -= 2;
		val = src->dat[*sp] << 8;
		val |= src->dat[*sp+1];
		return val;
		return gw(&src->dat[*sp]);
	}
}
static unsigned short pop() { if (bs) return pop16(); else return pop8(); }

static void poke(unsigned short addr, unsigned short val) {
	if (bs) {
		ram[addr] = val >> 8;
		ram[addr+1] = val;
	} else {
		ram[addr] = val;
	}
}
	if (bs) sw(&ram[addr], val); else ram[addr] = val; }

static unsigned short peek(unsigned short addr) {
	if (bs) {
		return (ram[addr] << 8) | ram[addr+1];
	} else {
		return ram[addr];
	}
}
	if (bs) return gw(&ram[addr]); else return ram[addr]; }

static void warp(unsigned short addr) {
	if (bs) {


@@ 150,13 135,13 @@ static void DEI() {
	Device *d = &dev[port>>4];
	port &= $f;
	if (bs) {
        val = d->dei(d, port++) << 8;
		val = d->dei(d, port++) << 8;
		port &= $f;
        val |= d->dei(d, port);
		val |= d->dei(d, port);
	} else {
        val = d->dei(d, port);
		val = d->dei(d, port);
	}
    push(val);
	push(val);
}
static void DEO() {
	unsigned char port = pop8();