URL
https://opencores.org/ocsvn/tv80/tv80/trunk
Subversion Repositories tv80
Compare Revisions
- This comparison shows the changes necessary to convert path
/tv80/branches/hpa1/tests
- from Rev 19 to Rev 84
- ↔ Reverse comparison
Rev 19 → Rev 84
/tv80_env.h
0,0 → 1,65
// Environment library |
// Creates definitions of the special I/O ports used by the |
// environment, as well as some utility functions to allow |
// programs to print out strings in the test log. |
|
#ifndef TV80_ENV_H |
#define TV80_ENV_H |
|
sfr at 0x80 sim_ctl_port; |
sfr at 0x81 msg_port; |
sfr at 0x82 timeout_port; |
sfr at 0x83 max_timeout_low; |
sfr at 0x84 max_timeout_high; |
|
#define SC_TEST_PASSED 0x01 |
#define SC_TEST_FAILED 0x02 |
#define SC_DUMPON 0x03 |
#define SC_DUMPOFF 0x04 |
|
void print (char *string) |
{ |
char *iter; |
|
timeout_port = 0x02; |
timeout_port = 0x01; |
|
iter = string; |
while (*iter != 0) { |
msg_port = *iter++; |
} |
} |
|
void print_num (int num) |
{ |
int cd = 0; |
int i; |
char digits[8]; |
|
timeout_port = 0x02; |
timeout_port = 0x01; |
|
while (num > 0) { |
digits[cd++] = (num % 10) + '0'; |
num /= 10; |
} |
for (i=cd; i>0; i--) |
msg_port = digits[i-1]; |
} |
|
void sim_ctl (unsigned char code) |
{ |
sim_ctl_port = code; |
} |
|
void set_timeout (unsigned int max_timeout) |
{ |
timeout_port = 0x02; |
|
max_timeout_low = (max_timeout & 0xFF); |
max_timeout_high = (max_timeout >> 8); |
|
timeout_port = 0x01; |
} |
|
#endif |
/fib.c
0,0 → 1,54
// Recursively compute fibonnaci sequence, using a |
// really inefficient algorithm. |
// (Stack exercise test) |
|
#include "tv80_env.h" |
|
int answers[] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, |
233, 377, 610, 987, 1597, 2584, 4181 }; |
|
int fib (int n) |
{ |
int rv; |
timeout_port = 0x02; |
|
if (n < 2) rv = n; |
else rv = fib(n-1) + fib(n-2); |
|
timeout_port = 0x01; |
return rv; |
} |
|
int main () |
{ |
int fn, fr; |
char pass; |
|
set_timeout (60000); |
pass = 1; |
|
for (fn = 1; fn < 20; fn++) { |
print ("Computing Fibonacci number "); |
print_num (fn); |
print ("\n"); |
|
fr = fib(fn); |
print ("Number is: "); |
print_num (fr); |
|
if (fr == answers[fn-1]) { |
print (" (correct)\n"); |
} else { |
print (" (incorrect)\n"); |
print ("Correct result: "); |
print_num (answers[fn-1]); |
pass = 0; |
print ("\n"); |
} |
} |
|
if (pass) |
sim_ctl (SC_TEST_PASSED); |
else |
sim_ctl (SC_TEST_FAILED); |
} |
/hello.c
0,0 → 1,23
|
sfr at 0x80 sim_ctl_port; |
sfr at 0x81 msg_port; |
sfr at 0x82 timeout_port; |
|
void print (char *string) |
{ |
char *iter; |
|
iter = string; |
while (*iter != 0) { |
msg_port = *iter++; |
} |
} |
|
int main () |
{ |
print ("Hello, world!\n"); |
|
sim_ctl_port = 0x01; |
return 0; |
} |
|
/malloc.c
0,0 → 1,39
#include <malloc.h> |
|
#include "tv80_env.h" |
|
#define TEST_SIZE 200 |
int main () |
{ |
char *foo; |
int i; |
int cksum_in, cksum_out; |
|
sim_ctl (SC_DUMPON); |
|
foo = malloc (TEST_SIZE); |
set_timeout (30000); |
|
print ("Memory allocated\n"); |
|
cksum_in = 0; |
for (i=0; i<TEST_SIZE; i=i+1) { |
cksum_in += i; |
foo[i] = i; |
} |
|
print ("Values assigned\n"); |
|
cksum_out = 0; |
for (i=0; i<TEST_SIZE; i++) |
cksum_out += foo[i]; |
|
print ("Checksum computed\n"); |
|
if (cksum_in == cksum_out) |
sim_ctl (SC_TEST_PASSED); |
else |
sim_ctl (SC_TEST_FAILED); |
|
return 0; |
} |
/basic_int.asm
0,0 → 1,65
.module basic_int |
|
test_ctl_port = 0x80 |
print_port = 0x81 |
int_timeout_port = 0x90 |
|
.area BOOT_VEC |
|
jp main |
|
.area INT_VEC |
|
int_entry: |
exx |
|
ld b, a |
ld hl, #int_seen_str |
|
print_str: |
ld a, (hl) |
cp #0 |
jp z, print_str_exit |
out (print_port), a |
inc hl |
jp print_str |
|
print_str_exit: |
ld a, b |
exx |
|
ld h, #1 |
reti |
|
.area _CODE |
|
main: |
ld h, #0 |
ld bc, #100 |
ld a, #50 |
out (int_timeout_port), a |
|
test_timeout_loop: |
ld a, #1 |
cp h |
jp z, test_pass |
|
dec bc |
jp nz, test_timeout_loop |
|
test_fail: |
ld a, #2 |
out (test_ctl_port), a |
.db 0x76 ; hlt |
|
test_pass: |
ld a, #1 |
out (test_ctl_port), a |
.db 0x76 ; hlt |
|
.area _DATA |
|
int_seen_str: |
.ascii "Interrupt asserted" |
.db 0x0a |
.db 0x00 |
/Makefile
0,0 → 1,36
# Makefile for Z80 C/Assembly files |
# Assumes that SDCC is installed parallel to TV80 root |
|
SDCC_ROOT=../../sdcc |
CC=$(SDCC_ROOT)/bin/sdcc -mz80 |
AS=$(SDCC_ROOT)/bin/as-z80 |
LD=$(SDCC_ROOT)/bin/link-z80 |
IHEX2MEM=../scripts/ihex2mem.py |
LINK_OPTIONS=-- -m -j -x -b_CODE=0x0200 -b_DATA=0x8000 -k$(SDCC_ROOT)/share/sdcc/lib/z80 -k$(SDCC_ROOT)/lib/z80 -lz80 |
AS_LINK_OPTIONS=-bBOOT_VEC=0x0000 -bINT_VEC=0x0038 |
C_LINK_OPTIONS=$(SDCC_ROOT)/share/sdcc/lib/z80/crt0.o |
|
%.vmem : %.ihx |
$(IHEX2MEM) $^ $@ |
|
%.ihx : %.c |
$(CC) $^ |
|
%.o : %.asm |
$(AS) -o $*.o $^ |
|
%.ihx : %.o |
$(LD) $(LINK_OPTIONS) $(AS_LINK_OPTIONS) -i $* $^ -e |
|
clean : |
rm -f *.map |
rm -f *.mem |
rm -f *.rel |
rm -f *.rst |
rm -f *.sym |
rm -f *.o |
rm -f *.lnk |
rm -f *.ihx |
rm -f *.lst |
rm -f *.vmem |
|