shithub: sms

Download patch

ref: ae213213deb37a397af488b373481f54da7b1fe9
parent: fffe0bedee6390e098ad9533113cdab3a73d72e2
author: Jean-André Santoni <jean.andre.santoni@gmail.com>
date: Thu Aug 28 05:07:07 EDT 2025

plan9 port

--- a/Makefile
+++ /dev/null
@@ -1,9 +1,0 @@
-
-TARGET := sms_libretro.so
-SHARED := -shared
-CFLAGS += -g -O3 -fPIC -flto
-LDFLAGS += -flto
-
-OBJ = sms.o z80.o mem.o vdp.o psg.o
-$(TARGET): $(OBJ) ; $(CC) $(SHARED) -o $@ $^ $(LDFLAGS)
-clean:            ; rm -f $(OBJ) $(TARGET)
--- a/dat.h
+++ b/dat.h
@@ -1,24 +1,22 @@
-#include <stdint.h>
+extern u32int irq;
 
-extern uint32_t irq;
+extern u8int reg[16];
 
-extern uint8_t reg[16];
+extern u8int z80bus, z80irq;
+extern u16int pc, curpc;
 
-extern uint8_t z80bus, z80irq;
-extern uint16_t pc, curpc;
+extern u16int ram[32768];
+extern u8int *prg;
+extern u8int *rom;
+extern u8int *mem;
 
-extern uint16_t ram[32768];
-extern uint8_t *prg;
-extern uint8_t *rom;
-extern uint8_t *mem;
-
-extern uint8_t vram[32768], vsram[40];
-extern uint8_t cram[64];
-extern uint32_t cramc[64];
+extern u8int vram[32768], vsram[40];
+extern u8int cram[64];
+extern u32int cramc[64];
 extern int vdpx, vdpy, frame, intla;
 
-extern uint8_t portDC;
-extern uint8_t portDD;
+extern u8int portDC;
+extern u8int portDD;
 
 enum {
 	MODE1   = 0x00,
--- a/fns.h
+++ b/fns.h
@@ -1,22 +1,20 @@
-#include <stdint.h>
-
-uint16_t memread(uint32_t);
-void memwrite(uint32_t, uint16_t, uint16_t);
+u16int memread(u32int);
+void memwrite(u32int, u16int, u16int);
 int z80step(void);
-uint8_t z80read(uint16_t);
-void z80write(uint16_t, uint8_t);
-uint8_t z80in(uint8_t);
-void z80out(uint8_t, uint8_t);
+u8int z80read(u16int);
+void z80write(u16int, u8int);
+u8int z80in(u8int);
+void z80out(u8int, u8int);
 void flush(void);
 void vdpmode(void);
-void vdpctrl(uint8_t);
-void vdpdata(uint8_t);
+void vdpctrl(u8int);
+void vdpdata(u8int);
 void vdpstep(void);
-uint8_t vdpstatus(void);
-uint8_t vdpdataport(void);
-uint8_t vdphcounter(void);
-uint8_t vdpvcounter(void);
-void cramwrite(uint16_t, uint8_t);
-void psginit(const uint16_t, const int);
-void psgwrite(const uint8_t);
-uint16_t psgstep();
+u8int vdpstatus(void);
+u8int vdpdataport(void);
+u8int vdphcounter(void);
+u8int vdpvcounter(void);
+void cramwrite(u16int, u8int);
+void psginit(const u16int, const int);
+void psgwrite(const u8int);
+u16int psgstep();
--- a/mem.c
+++ b/mem.c
@@ -1,40 +1,39 @@
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "fns.h"
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "../eui.h"
 #include "dat.h"
+#include "fns.h"
 
-#define sysfatal(fmt, ...){printf(fmt"\n", ##__VA_ARGS__); exit(EXIT_FAILURE);}
-
-uint16_t ram[32768] = {0};
-uint8_t vram[32768];
-uint8_t cram[64], vsram[40];
-uint32_t cramc[64];
-uint8_t reg[16] = {
+u16int ram[32768] = {0};
+u8int vram[32768];
+u8int cram[64], vsram[40];
+u32int cramc[64];
+u8int reg[16] = {
     0x36, 0x80, 0xff, 0xff,
     0xff, 0xff, 0xfb, 0x00,
     0x00, 0x00, 0xff, 0x00,
     0x00, 0x00, 0x00, 0x00,
 };
-uint8_t ctl[15];
+u8int ctl[15];
 
-uint8_t vdplatch;
+u8int vdplatch;
 
-uint8_t z80bus = 0;
-uint16_t ram_bank;
-uint8_t ram_enabled = 0;
+u8int z80bus = 0;
+u16int ram_bank;
+u8int ram_enabled = 0;
 
 int slotaddr[3] = {0, 0, 0};
 int nbank = 16;
 
 void
-cramwrite(uint16_t a, uint8_t v)
+cramwrite(u16int a, u8int v)
 {
 	cram[a & 0x1f] = v;
 
-	uint8_t r = (v & 0x03) << 6;
-	uint8_t g = (v & 0x0c) << 4;
-	uint8_t b = (v & 0x30) << 2;
+	u8int r = (v & 0x03) << 6;
+	u8int g = (v & 0x0c) << 4;
+	u8int b = (v & 0x30) << 2;
 
 	cramc[a & 0x1f] = (b << 16) | (g << 8) | r;
 
@@ -44,11 +43,10 @@
 	// printf("\n");
 }
 
-uint8_t
-z80read(uint16_t a)
+u8int
+z80read(u16int a)
 {
 	// printf("z80read %x\n", a);
-	uint16_t v;
 
 	if (a < 0x400)
 		return rom[a];
@@ -69,16 +67,16 @@
 }
 
 void
-z80write(uint16_t a, uint8_t v)
+z80write(u16int a, u8int v)
 {
 	// printf("z80write %x %x\n", a, v);
 	if (a < 0x8000)
-		printf("wrong z80write page 0 or 1 %x %x\n", a, v);
+		print("wrong z80write page 0 or 1 %x %x", a, v);
 	else if (a < 0xC000)
 		if (ram_enabled)
 			ram[(a - 0x8000) + ram_bank] = v;
 		else
-			printf("wrong z80write page 2 %x %x\n", a, v);
+			print("wrong z80write page 2 %x %x", a, v);
 	else if (a < 0xE000)
 	{
 		mem[a] = v;
@@ -114,16 +112,16 @@
 	}
 }
 
-uint8_t portDC = 0x00;
-uint8_t portDD = 0xff;
-uint8_t port3E = 0x00;
-uint8_t port3F = 0x00;
-uint8_t port3FHC = 0x00;
+u8int portDC = 0x00;
+u8int portDD = 0xff;
+u8int port3E = 0x00;
+u8int port3F = 0x00;
+u8int port3FHC = 0x00;
 
-uint8_t
-z80in(uint8_t port)
+u8int
+z80in(u8int port)
 {
-	// printf("z80in %x\n", port);
+	// print("z80in %x", port);
 	if (port < 0x40)
 		return 0xff;
 	else if (port >= 0x40 && port < 0x80)
@@ -144,11 +142,11 @@
 }
 
 void
-z80out(uint8_t port, uint8_t v)
+z80out(u8int port, u8int v)
 {
-	// printf("z80out %x %x\n", port, v);
+	// print("z80out %x %x", port, v);
 	if (port < 0x40){
-		// printf("  write to control register\n");
+		// print("  write to control register");
 		if ((port & 0x01) == 0x00)
 			port3E = v;
 		else{
@@ -156,14 +154,14 @@
 			port3F = ((v & 0x80) | (v & 0x20) << 1) & 0xC0;
 		}
 	}else if ((port >= 0x40) && (port < 0x80)){
-		// printf("  write to SN76489 PSG\n");
+		// print("  write to SN76489 PSG");
 		psgwrite(v);
 	}else if ((port >= 0x80) && (port < 0xC0)){
-		// printf("  write to VDP\n");
+		// print("  write to VDP");
 		if ((port & 0x01) == 0x00)
 			vdpdata(v);
 		else
 			vdpctrl(v);
 	}else
-		printf("  write with no effect\n");
+		print("  write with no effect");
 }
--- a/psg.c
+++ b/psg.c
@@ -1,11 +1,13 @@
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "../eui.h"
 #include "dat.h"
+#include "fns.h"
 
 #define NOISE_TAPPED 0x9
 
-static const uint8_t noise_table[3] = { 0x10, 0x20, 0x40 };
+static const u8int noise_table[3] = { 0x10, 0x20, 0x40 };
 static const short vol_table[16] = {
 	8191, 6507, 5168, 4105, 3261, 2590, 2057,
 	1642, 1298, 1031, 819, 650, 516, 410, 326, 0
@@ -13,16 +15,16 @@
 
 static double cyclespersample;
 static double cycles;
-static uint16_t freqreg[4];
-static uint16_t countreg[4];
-static uint8_t attn[4];
+static u16int freqreg[4];
+static u16int countreg[4];
+static u8int attn[4];
 static bool flipflop[4];
-static uint16_t noise;
-static uint8_t curr_reg;
-static uint8_t curr_type;
+static u16int noise;
+static u8int curr_reg;
+static u8int curr_type;
 
 void
-psginit(const uint16_t rate, const int clockspd)
+psginit(const u16int rate, const int clockspd)
 {
 	cyclespersample = (double)clockspd / (double)PSGDIV/ (double)rate;
 	cycles = cyclespersample;
@@ -29,7 +31,7 @@
 }
 
 void
-psgwrite(const uint8_t data)
+psgwrite(const u8int data)
 {
 	bool first = data & 128;
 	if(first){
@@ -49,8 +51,8 @@
 		countreg[curr_reg] = freqreg[curr_reg] = (freqreg[curr_reg] & 0x0F) | ((data & 0x3F) << 4);
 }
 
-static inline uint16_t
-parity(uint16_t v)
+static inline u16int
+parity(u16int v)
 {
 	v ^= v >> 8;
 	v ^= v >> 4;
@@ -60,8 +62,8 @@
 	return v;
 }
 
-static inline uint16_t
-vol(uint8_t chn)
+static inline u16int
+vol(u8int chn)
 {
 	return (flipflop[chn] ? 1 : -1) * vol_table[attn[chn]];
 }
@@ -70,7 +72,7 @@
 psgstep()
 {
 	while(cycles > 0){
-		for(uint8_t i = 0; i < 4; i++){
+		for(u8int i = 0; i < 4; i++){
 			countreg[i]--;
 			if(!countreg[i]){
 				if(i < 3){
@@ -77,8 +79,8 @@
 					countreg[i] = freqreg[i];
 					flipflop[i] = !flipflop[i];
 				}else{
-					uint8_t nf = freqreg[3] & 3;
-					uint8_t fb = (freqreg[3] >> 2) & 1;
+					u8int nf = freqreg[3] & 3;
+					u8int fb = (freqreg[3] >> 2) & 1;
 					countreg[3] = nf == 3 ? freqreg[2] : (0x10 << nf);
 
 					noise = (noise >> 1) | ((fb ? parity(noise & NOISE_TAPPED) : noise & 1) << 15);
--- a/vdp.c
+++ b/vdp.c
@@ -1,16 +1,18 @@
-#include <stdint.h>
-#include <stdio.h>
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
-extern uint8_t *pic;
+extern u8int *pic;
 
-uint8_t vdpcode, vdpstat = 0;
-uint16_t vdpaddr;
-uint8_t vdpbuf;
+u8int vdpcode, vdpstat = 0;
+u16int vdpaddr;
+u8int vdpbuf;
 int vdpx = 0, vdpyy, frame, intla;
 int first = 1;
-uint16_t hctr;
+u16int hctr;
 static int xmax, xdisp;
 enum { ymax = 262, yvbl = 234 };
 int vdpy = ymax-1;
@@ -23,12 +25,12 @@
 }
 
 static void
-pixeldraw(int x, int y, uint32_t v)
+pixeldraw(int x, int y, u32int v)
 {
-	uint32_t *p;
-	union { uint32_t l; uint8_t b[4]; } u;
+	u32int *p;
+	union { u32int l; u8int b[4]; } u;
 
-	p = (uint32_t *)pic + (x + y * 320);
+	p = (u32int *)pic + (x + y * 320);
 	u.b[0] = v >> 16;
 	u.b[1] = v >> 8;
 	u.b[2] = v;
@@ -39,27 +41,27 @@
 static void
 planes(void)
 {
-	uint16_t screenmap = (reg[PANT] & 0x0e) << 10;
+	u16int screenmap = (reg[PANT] & 0x0e) << 10;
 
-	uint8_t y = vdpy + reg[VERSCR];
+	u8int y = vdpy + reg[VERSCR];
 	y %= 224;
 	int ty = y >> 3;
 	int tyoff = y & 7;
 
-	uint8_t x = vdpx - reg[HORSCR];
+	u8int x = vdpx - reg[HORSCR];
 	int tx = x >> 3;
 	int txoff = x & 7;
 
-	uint16_t taddr = screenmap + (((ty << 5) + tx) << 1);
-	uint16_t tidx = vram[taddr];
-	uint8_t info = vram[taddr + 1];
+	u16int taddr = screenmap + (((ty << 5) + tx) << 1);
+	u16int tidx = vram[taddr];
+	u8int info = vram[taddr + 1];
 
 	if ((info & 1) != 0)
 		tidx = (tidx | 0x100) & 0x1ff;
 
-	uint8_t hflip = (info & 1 << 1) != 0;
-	uint8_t vflip = (info & 1 << 2) != 0;
-	uint8_t paloff = (info & 1 << 3) != 0 ? 16 : 0;
+	u8int hflip = (info & 1 << 1) != 0;
+	u8int vflip = (info & 1 << 2) != 0;
+	u8int paloff = (info & 1 << 3) != 0 ? 16 : 0;
 
 	int data = (tidx << 5) + ((vflip ? 7 - tyoff : tyoff) << 2);
 	int xx = hflip ? txoff : 7 - txoff;
@@ -77,8 +79,8 @@
 static void
 spritesinit(void)
 {
-	uint16_t t1 = (reg[SPRTAB] << 7 & 0x3f00);
-	uint16_t t2 = t1 + 0x80;
+	u16int t1 = (reg[SPRTAB] << 7 & 0x3f00);
+	u16int t2 = t1 + 0x80;
 
 	int bufidx = 0;
 	for(int i = bufidx; i < 8; i++)
@@ -109,9 +111,9 @@
 static void
 sprites(void)
 {
-	uint16_t t1 = (reg[SPRTAB] << 7 & 0x3f00);
-	uint16_t t2 = t1 + 0x80;
-	uint16_t t3 = (reg[SPRADDR] << 11) & 0x2000;
+	u16int t1 = (reg[SPRTAB] << 7 & 0x3f00);
+	u16int t2 = t1 + 0x80;
+	u16int t3 = (reg[SPRADDR] << 11) & 0x2000;
 
 	for(int i = 7; i >= 0; i--){
 		if(sprlst[i] < 0) continue;
@@ -119,9 +121,9 @@
 		int spr = sprlst[i];
 		int spridx = t1 + spr;
 		int y = vram[spridx] + 1;
-		uint16_t info = t2 + (spr << 1);
+		u16int info = t2 + (spr << 1);
 		int x = vram[info];
-		int h = (reg[MODE2] & 1 << 1) != 0 ? 16 : 8;
+		//int h = (reg[MODE2] & 1 << 1) != 0 ? 16 : 8;
 
 		int t = vram[info + 1];
 		t &= (reg[MODE2] & 1 << 1) != 0 ? 0xfe : 0xff;
@@ -139,7 +141,7 @@
 }
 
 void
-vdpctrl(uint8_t v)
+vdpctrl(u8int v)
 {
 	// printf("	vdp write to control port %x\n", v);
 
@@ -167,7 +169,7 @@
 }
 
 void
-vdpdata(uint8_t v)
+vdpdata(u8int v)
 {
 	// printf("	vdp (code: %x) write to data port %x\n", vdpcode, v);
 	first = 1;
@@ -183,10 +185,10 @@
 	vdpaddr &= 0x3fff;
 }
 
-uint8_t
+u8int
 vdpdataport(void)
 {
-	uint8_t v = vdpbuf;
+	u8int v = vdpbuf;
 	vdpbuf = vram[vdpaddr];
 	vdpaddr++;
 	vdpaddr &= 0x3fff;
@@ -195,10 +197,10 @@
 	return v;
 }
 
-uint8_t
+u8int
 vdpstatus(void)
 {
-	uint8_t v = vdpstat | 0x1f;
+	u8int v = vdpstat | 0x1f;
 	vdpstat = 0;
 	z80irq = 0;
 	// printf("    vdp read status flags %x\n", v);
@@ -206,7 +208,7 @@
 	return v;
 }
 
-uint8_t
+u8int
 vdphcounter(void)
 {
 	// printf("    vdp read hcounter %x\n", vdpx);
@@ -213,7 +215,7 @@
 	return vdpx;
 }
 
-uint8_t
+u8int
 vdpvcounter(void)
 {
 	// printf("    vdp read hcounter %y\n", vdpy);
@@ -225,8 +227,6 @@
 void
 vdpstep(void)
 {
-	uint32_t v;
-
 	if(vdpx == 0)
 		spritesinit();
 
--- a/z80.c
+++ b/z80.c
@@ -1,16 +1,13 @@
-#include <fcntl.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "fns.h"
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
 #include "dat.h"
+#include "fns.h"
 
-#define sysfatal(fmt, ...){printf(fmt"\n", ##__VA_ARGS__); exit(EXIT_FAILURE);}
-
-uint8_t ipage, intm, z80irq;
-uint16_t ix[2] = {0xffff, 0xffff};
-uint16_t pc, curpc;
-uint16_t sp = 0xdff0;
+u8int ipage, intm, z80irq;
+u16int ix[2] = {0xffff, 0xffff};
+u16int pc, curpc;
+u16int sp = 0xdff0;
 int halt;
 int inplast;
 
@@ -29,7 +26,7 @@
 #define DE() (s[rD] << 8 | s[rE])
 #define HL() (s[rH] << 8 | s[rL])
 
-uint8_t s[16] = {
+u8int s[16] = {
 	[rA] = 0x00, [rF] = 0x40,
 	[rB] = 0x00, [rC] = 0x00,
 	[rD] = 0x00, [rE] = 0x00,
@@ -36,53 +33,53 @@
 	[rH] = 0x00, [rL] = 0x00,
 };
 
-static uint8_t
+static u8int
 fetch8(void)
 {
 	return z80read(pc++);
 }
 
-static uint16_t
+static u16int
 fetch16(void)
 {
-	uint16_t u = z80read(pc++);
+	u16int u = z80read(pc++);
 	return u | z80read(pc++) << 8;
 }
 
 static void
-push8(uint8_t u)
+push8(u8int u)
 {
 	z80write(--sp, u);
 }
 
 static void
-push16(uint16_t u)
+push16(u16int u)
 {
 	z80write(--sp, u >> 8);
 	z80write(--sp, u);
 }
 
-static uint8_t
+static u8int
 pop8(void)
 {
 	return z80read(sp++);
 }
 
-static uint16_t
+static u16int
 pop16(void)
 {
-	uint16_t v = z80read(sp++);
+	u16int v = z80read(sp++);
 	return v | z80read(sp++) << 8;
 }
 
-static uint16_t
-read16(uint16_t n)
+static u16int
+read16(u16int n)
 {
 	return z80read(n) | z80read(n+1) << 8;
 }
 
 static void
-write16(uint16_t n, uint16_t v)
+write16(u16int n, u16int v)
 {
 	z80write(n++, v);
 	z80write(n, v >> 8);
@@ -89,13 +86,13 @@
 }
 
 static int
-parity(uint8_t v)
+parity(u8int v)
 {
 	return (((v * 0x0101010101010101ULL) & 0x8040201008040201ULL) % 0x1FF) & 1;
 }
 
 static int
-move(uint8_t dst, uint8_t src)
+move(u8int dst, u8int src)
 {
 	if(dst == rHL){
 		if(src == rHL){
@@ -114,11 +111,11 @@
 }
 
 static int
-alu(uint8_t op, uint8_t n)
+alu(u8int op, u8int n)
 {
-	uint8_t v4;
-	uint8_t u;
-	uint16_t v;
+	u8int v4;
+	u8int u;
+	u16int v;
 	int t;
 
 	switch(n){
@@ -161,7 +158,7 @@
 	case 6: v = s[rA] | u; break;
 	}
 	s[rF] = 0;
-	if((uint8_t)v == 0)
+	if((u8int)v == 0)
 		s[rF] |= FLAGZ;
 	if((v & 0x80) != 0)
 		s[rF] |= FLAGS;
@@ -196,7 +193,7 @@
 static int
 branch(int cc, int t)
 {
-	uint16_t v = (int8_t)fetch8();
+	u16int v = (int8_t)fetch8();
 	if(!cc)
 		return t + 7;
 	pc += v;
@@ -203,8 +200,8 @@
 	return t + 12;
 }
 
-static uint8_t
-inc(uint8_t v)
+static u8int
+inc(u8int v)
 {
 	s[rF] &= FLAGC;
 	++v;
@@ -219,8 +216,8 @@
 	return v;
 }
 
-static uint8_t
-dec(uint8_t v)
+static u8int
+dec(u8int v)
 {
 	--v;
 	s[rF] = s[rF] & FLAGC | FLAGN;
@@ -236,10 +233,10 @@
 }
 
 static int
-addhl(uint16_t u)
+addhl(u16int u)
 {
 	s[rF] &= ~(FLAGN|FLAGC|FLAGH);
-	uint32_t v = HL() + u;
+	u32int v = HL() + u;
 	if((v & 0x10000) != 0)
 		s[rF] |= FLAGC;
 	if((HL() & 0xfff) + (u & 0xfff) >= 0x1000)
@@ -250,16 +247,16 @@
 }
 
 static void
-adchl(uint16_t u)
+adchl(u16int u)
 {
-	uint32_t v = HL() + u + (s[rF] & FLAGC);
-	uint32_t v4 = (HL() & 0xfff) + (u & 0xfff) + (s[rF] & FLAGC);
+	u32int v = HL() + u + (s[rF] & FLAGC);
+	u32int v4 = (HL() & 0xfff) + (u & 0xfff) + (s[rF] & FLAGC);
 	s[rF] = 0;
 	if((v & 0x10000) != 0)
 		s[rF] |= FLAGC;
 	if((v4 & 0x1000) != 0)
 		s[rF] |= FLAGH;
-	if((uint16_t)v == 0)
+	if((u16int)v == 0)
 		s[rF] |= FLAGZ;
 	if((v & 0x8000) != 0)
 		s[rF] |= FLAGS;
@@ -270,16 +267,16 @@
 }
 
 static void
-sbchl(uint16_t u)
+sbchl(u16int u)
 {
-	uint32_t v = HL() + (uint16_t)~u + (~s[rF] & FLAGC);
-	uint32_t v4 = (HL() & 0xfff) + (~u & 0xfff) + (~s[rF] & FLAGC);
+	u32int v = HL() + (u16int)~u + (~s[rF] & FLAGC);
+	u32int v4 = (HL() & 0xfff) + (~u & 0xfff) + (~s[rF] & FLAGC);
 	s[rF] = FLAGN;
 	if((v & 0x10000) == 0)
 		s[rF] |= FLAGC;
 	if((v4 & 0x1000) == 0)
 		s[rF] |= FLAGH;
-	if((uint16_t)v == 0)
+	if((u16int)v == 0)
 		s[rF] |= FLAGZ;
 	if((v & 0x8000) != 0)
 		s[rF] |= FLAGS;
@@ -292,10 +289,10 @@
 }
 
 static int
-addindex(int n, uint16_t u)
+addindex(int n, u16int u)
 {
 	s[rF] &= ~(FLAGN|FLAGC|FLAGH);
-	uint32_t v = ix[n] + u;
+	u32int v = ix[n] + u;
 	if((v & 0x10000) != 0)
 		s[rF] |= FLAGC;
 	if((ix[n] & 0xfff) + (u & 0xfff) >= 0x1000)
@@ -307,7 +304,7 @@
 static int
 jump(int cc)
 {
-	uint16_t v = fetch16();
+	u16int v = fetch16();
 	if(cc)
 		pc = v;
 	return 10;
@@ -314,7 +311,7 @@
 }
 
 static int
-call(uint16_t a, int cc)
+call(u16int a, int cc)
 {
 	if(!cc)
 		return 10;
@@ -324,7 +321,7 @@
 }
 
 static int
-call2(uint16_t a, int cc)
+call2(u16int a, int cc)
 {
 	if(!cc)
 		return 0;
@@ -334,9 +331,9 @@
 }
 
 static void
-swap(uint8_t a)
+swap(u8int a)
 {
-	uint8_t v = s[a];
+	u8int v = s[a];
 	s[a] = s[a + 8];
 	s[a + 8] = v;
 }
@@ -344,8 +341,8 @@
 static int
 bits(int i)
 {
-	uint8_t op, v, n, m, c;
-	uint16_t a;
+	u8int op, v, n, m, c;
+	u16int a;
 	int t;
 
 	//SET(a, v, t);
@@ -411,8 +408,8 @@
 static int
 ed(void)
 {
-	uint8_t op, v, u, l;
-	uint16_t a, n;
+	u8int op, v, u, l;
+	u16int a, n;
 
 	op = fetch8();
 	// printf("ed %.2x\n", op);
@@ -542,7 +539,7 @@
 	case 0x79: z80out(s[rC], s[rA]); return 12;
 	case 0xb3:
 		s[rB]--;
-		uint8_t u = z80read(HL());
+		u8int u = z80read(HL());
 		z80out(s[rC], u);
 		addhl(1);
 		if (s[rB] == 0) s[rF] |= FLAGZ; else s[rF] &= ~FLAGZ;
@@ -579,9 +576,9 @@
 static int
 index_(int n)
 {
-	uint16_t v;
+	u16int v;
 
-	uint8_t op = fetch8();
+	u8int op = fetch8();
 	switch(op){
 	case 0x40: case 0x41: case 0x42: case 0x43: case 0x47:
 	case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4f:
@@ -654,8 +651,8 @@
 int
 z80step(void)
 {
-	uint8_t op;
-	uint16_t v, w;
+	u8int op;
+	u16int v, w;
 
 	if((z80bus & RESET) != 0){
 		printf("reset\n");
--