2001-09-01 Michael Hope <michaelh@juju.net.nz>
+ * device/lib/gbz80/Makefile: Fixed up all the libraries to pass the regression tests.
+
* support/regression/ports/host/spec.mk: Updated to compile with the new type specifiers.
* device/lib/Makefile.in (Z80SOURCES): Removed old _mululong, _mulslong, and unneeded _mulint.
/* The following are disabled to make the dhrystone test more authentic.
*/
-#define _SDCC_PORT_PROVIDES_MEMCPY 1
-#define _SDCC_PORT_PROVIDES_STRCMP 1
+#define _SDCC_PORT_PROVIDES_MEMCPY 0
+#define _SDCC_PORT_PROVIDES_STRCMP 0
/* Register allocator is as good as hand coded asm. Cool. */
#define _SDCC_PORT_PROVIDES_STRCPY 0
/* The following are disabled to make the dhrystone test more authentic.
*/
-#define _SDCC_PORT_PROVIDES_MEMCPY 1
-#define _SDCC_PORT_PROVIDES_STRCMP 1
+#define _SDCC_PORT_PROVIDES_MEMCPY 0
+#define _SDCC_PORT_PROVIDES_STRCMP 0
/* Register allocator is as good as hand coded asm. Cool. */
#define _SDCC_PORT_PROVIDES_STRCPY 0
SCC = $(TOPDIR)/bin/sdcc -mgbz80
SAS = $(TOPDIR)/bin/as-gbz80
-OBJ = putchar.o string.o printf.o div.o mul.o stubs.o shift.o
+OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o
+
LIB = gbz80.lib
CC = $(SCC)
AS = $(SAS)
_dummy:
clean:
- rm -f $(OBJ) *~ $(CLEANSPEC) *.dump* *.asm *.lib
+ rm -f *.o *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib
;; Stack at the top of memory.
ld sp,#0xdfff
+ ;; Setup global data
+ call gsinit
+
;; Use _main instead of main to bypass sdcc's intelligence
call _main
jp _exit
call .div8
- ld l,c
- ld h,b
+ ld e,c
+ ld d,b
ret
call .div8
- ld l,e
- ld h,d
-
+ ;; Already in DE
+
ret
__divsint_rrx_s::
call .div16
- ld l,c
- ld h,b
+ ld e,c
+ ld d,b
ret
call .div16
- ld l,e
- ld h,d
+ ;; Already in DE
ret
ld c,l
call .divu8
- ld l,c
- ld h,b
+ ld e,c
+ ld d,b
ret
ld c,l
call .divu8
- ld l,e
- ld h,d
+ ;; Already in DE
ret
ld c,l
call .divu16
- ld l,c
- ld h,b
+ ld e,c
+ ld d,b
ret
call .divu16
- ld l,e
- ld h,d
+ ;; Already in DE
ret
2$:
dec b
jr nz,1$
+
+ ;; Return in DE
+ ld e,l
+ ld d,h
+
ret
#include <stdarg.h>
#include <stdio.h>
+#define STATIC
+
/* PENDING */
#define NULL 0
-static void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(), void *pData)
+STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(char, void *), void *pData)
{
const char *_hex = "0123456789ABCDEF";
if (issigned && ((int)u < 0)) {
(*emitter)(_hex[u%base], pData);
}
-static void _printf(const char *format, void (*emitter)(), void *pData, va_list va)
+STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va)
{
while (*format) {
if (*format == '%') {
switch (*++format) {
case 'c': {
- char c = va_arg(va, char);
+ char c = (char)va_arg(va, int);
(*emitter)(c, pData);
break;
}
void putchar(char c);
-static void _char_emitter(char c, void *pData)
+STATIC void _char_emitter(char c, void *pData)
{
/* PENDING: Make the compiler happy. */
pData = 0;
va_list va;
va_start(va, format);
- _printf(format, _char_emitter, NULL, va);
_printf(format, _char_emitter, NULL, va);
/* PENDING: What to return? */
;;
__rrulong_rrx_s::
- ld hl,#2+4
+ ld hl,#2
add hl,sp
-
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
+
ld e,(hl)
- dec hl
+ inc hl
+ ld d,(hl)
+ inc hl
+ ld c,(hl)
+ inc hl
+ ld b,(hl)
+ inc hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
- ld a,c
+ ld l,c
+ ld h,b
1$:
or a,a
ret z
- rr d
- rr e
rr h
rr l
+ rr d
+ rr e
dec a
jp 1$
__rrslong_rrx_s::
- ld hl,#2+4
+ ld hl,#2
add hl,sp
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
ld e,(hl)
- dec hl
+ inc hl
+ ld d,(hl)
+ inc hl
+ ld c,(hl)
+ inc hl
+ ld b,(hl)
+ inc hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
- ld a,c
+ ld l,c
+ ld h,b
1$:
or a,a
ret z
- sra d
- rr e
- rr h
+ sra h
rr l
+ rr d
+ rr e
dec a
jp 1$
__rlslong_rrx_s::
__rlulong_rrx_s::
- ld hl,#2+4
+ ld hl,#2
add hl,sp
- ld c,(hl)
- dec hl
- ld d,(hl)
- dec hl
ld e,(hl)
- dec hl
+ inc hl
+ ld d,(hl)
+ inc hl
+ ld c,(hl)
+ inc hl
+ ld b,(hl)
+ inc hl
ld a,(hl)
- dec hl
- ld l,(hl)
- ld h,a
- ld a,c
+ ld l,c
+ ld h,b
1$:
or a,a
ret z
- rl l
- rl h
rl e
rl d
+ rl l
+ rl h
dec a
jp 1$
SCC = $(TOPDIR)/bin/sdcc -mz80
SAS = $(TOPDIR)/bin/as-z80
-OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o \
- asm_strings.o
+OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o
LIB = z80.lib
CC = $(SCC)
_dummy:
clean:
- rm -f $(OBJ) *~ $(CLEANSPEC) *.dump* *.asm *.lib
+ rm -f *.o *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib
static const char *aopGet (asmop * aop, int offset, bool bit16);
+static PAIR_ID
+_getTempPairId(void)
+{
+ if (IS_GB)
+ {
+ return PAIR_DE;
+ }
+ else
+ {
+ return PAIR_HL;
+ }
+}
+
+static const char *
+_getTempPairName(void)
+{
+ return _pairs[_getTempPairId()].name;
+}
+
+#if 0
+static const char *
+_getTempPairPart(int idx)
+{
+ wassertl (idx == LSB || idx == MSB16, "Invalid pair offset");
+
+ if (idx == LSB)
+ {
+ return _pairs[_getTempPairId()].l;
+ }
+ else
+ {
+ return _pairs[_getTempPairId()].h;
+ }
+}
+#endif
+
static void
_tidyUp (char *buf)
{
/* we need to get it byte by byte */
if (pairId == PAIR_HL && IS_GB && requiresHL (aop)) {
aopGet (aop, offset, FALSE);
- switch (aop->size) {
+ switch (aop->size - offset) {
case 1:
emit2 ("ld l,!*hl");
emit2 ("ld h,!immedbyte", 0);
break;
case 2:
+ // PENDING: Requires that you are only fetching two bytes.
+ case 4:
emit2 ("!ldahli");
emit2 ("ld h,!*hl");
emit2 ("ld l,a");
break;
default:
- emitDebug ("; WARNING: mlh woosed out. This code is invalid.");
+ wassertl (0, "Attempted to fetch too much data into HL");
+ break;
}
}
else if (IS_Z80 && aop->type == AOP_IY) {
_push (PAIR_HL);
aopPut (AOP (oper), _fReturn[0], 0);
aopPut (AOP (oper), _fReturn[1], 1);
- emit2 ("pop de");
- _G.stack.pushed -= 2;
+ _pop (PAIR_DE);
aopPut (AOP (oper), _fReturn[0], 2);
aopPut (AOP (oper), _fReturn[1], 3);
}
/* if increment 16 bits in register */
if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
- (size == 2))
+ (size == 2)
+ )
{
- fetchPair (PAIR_HL, AOP (IC_RESULT (ic)));
+ fetchPair (_getTempPairId(), AOP (IC_RESULT (ic)));
while (icount--) {
- emit2 ("dec hl");
+ emit2 ("dec %s", _getTempPairName());
}
- aopPut (AOP (IC_RESULT (ic)), "l", LSB);
- aopPut (AOP (IC_RESULT (ic)), "h", MSB16);
+
+ commitPair (AOP (IC_RESULT (ic)), _getTempPairId());
return TRUE;
}
}
else if (size == 4)
{
+ /* Anything could be on the stack, and we can't afford
+ to setup the base pointer as that may nuke the carry.
+ */
emitDebug ("; WARNING: This sub is probably broken.\n");
}
}
}
else
{
+#if 0
+ // PENDING: Doesn't work around zero
+
/* Special cases:
On the GB:
If the left or the right is a lit:
emit2 ("add hl,%s", _getPairIdName (id));
goto release;
}
+#endif
if (AOP_TYPE (right) == AOP_LIT)
{
lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
static const char *_gbz80_linkCmd[] =
{
- "link-z80",
+ "link-gbz80",
"-n", // Don't echo output
"-c", // Command line input
"--", // Again, command line input...
"-- " // Again, command line input...
"-b_CODE=0x%04X " // Code starts at 0x200
"-b_DATA=0x%04X " // RAM starts at 0x8000
+ "-m " // Map file
"-j ", // Output a symbol file as well
portName,
options.code_loc,
} by {
xor a,a
}
+
\ No newline at end of file
rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc
inter-port-clean:
- rm -f fwk/lib/*.o
+ rm -f fwk/lib/*.o fwk/lib/*.asm
--- /dev/null
+/** Add, sub tests.
+
+ type: signed char, int, long
+ storage: static,
+ attr: volatile
+*/
+#include <testfwk.h>
+
+void
+testAdd(void)
+{
+ {storage} {attr} {type} left, right, result;
+
+ left = 5;
+ right = 26;
+
+ result = left+right;
+ ASSERT(result == 31);
+
+ left = 39;
+ right = -120;
+
+ result = left+right;
+ ASSERT(result == (39-120));
+}
+
+void
+testSub(void)
+{
+ {storage} {attr} {type} left, right, result;
+
+ left = 5;
+ right = 26;
+
+ result = left-right;
+ ASSERT(result == (5-26));
+
+ left = 39;
+ right = -76;
+
+ result = left-right;
+ ASSERT(result == (39+76));
+}
dhry.ihx: dhry.c
$(CC) $(CFLAGS) dhry.c
+dhry.gb: dhry.c
+ $(CC) $(CFLAGS) dhry.c
+
dhry.c: dhry.h
dhry.bin: dhry.ihx
#include <tinibios.h>
#define clock() ClockTicks()
#define CLOCKS_PER_SEC 1000
-#undef PRINT_T_STATES
#define memcpy(d,s,l) memcpyx(d,s,l)
-#elif defined(__z80)
+#elif defined(__z80) || defined(__gbz80)
unsigned int _clock(void);
#define clock _clock
#define CLOCKS_PER_SEC 100
-#define PRINT_T_STATES 1
#else
/** For clock() */
#include <time.h>
#include <types.h>
-#define PRINT_T_STATES
-#endif
-
-/** Print the number of t-states this program has been executing for.
- Optional :)
-*/
-#ifdef PRINT_T_STATES
-void _printTStates(void);
#endif
/** Set to one to print more messages about expected values etc.
/* Used instead of malloc() */
static Rec_Type _r[2];
+void mark(void)
+{
+}
+
void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
void Proc_2 (One_Fifty *Int_Par_Ref);
void Proc_5 (void);
DPRINTF(("Looping.\n"));
} /* loop "for Run_Index" */
-#ifdef PRINT_T_STATES
- _printTStates();
-#endif
-
printf("Run_Index = %d\n", Run_Index);
runTime = clock() - runTime;
#endif
#if 1
printf("Number of runs: %u. runTime: %u.\n", Number_Of_Runs, (unsigned)runTime);
+ mark();
printf("Dhrystones/s = %u\n", (unsigned)((unsigned long)Number_Of_Runs / (runTime/CLOCKS_PER_SEC)));
printf("MIPS = d/s/1757 = (sigh, need floats...)\n");
#endif