From 1777a98f62fbe65e032d4806ec068258d1a54e78 Mon Sep 17 00:00:00 2001 From: Marcin Gasperowicz Date: Mon, 31 Dec 2012 16:55:32 +0100 Subject: [PATCH] Poorman's testing framework and i don't remember what --- include/assert.h | 55 ++++++++ include/console.h | 7 + include/redbus.h | 2 +- lib/common/Makefile | 5 +- lib/common/_hextab.c | 15 +++ lib/common/_hextab.s | 34 +++++ lib/rpc8e.lib | Bin 146816 -> 147314 bytes lib/rpc8e/Makefile | 4 +- lib/rpc8e/console.c | 1 + test/Makefile | 18 +-- test/irc_client.c | 4 - test/test.c | 59 +++++++++ test/test.h | 4 + test/test.s | 304 +++++++++++++++++++++++++++++++++++++++++++ test/test_ctype.c | 0 test/test_rb.s | 64 --------- test/test_stdlib.c | 48 +++++++ test/test_string.c | 0 18 files changed, 544 insertions(+), 80 deletions(-) create mode 100644 include/assert.h create mode 100644 lib/common/_hextab.c create mode 100644 lib/common/_hextab.s create mode 100644 lib/rpc8e/console.c create mode 100644 test/test.c create mode 100644 test/test.h create mode 100644 test/test.s create mode 100644 test/test_ctype.c delete mode 100644 test/test_rb.s create mode 100644 test/test_stdlib.c create mode 100644 test/test_string.c diff --git a/include/assert.h b/include/assert.h new file mode 100644 index 0000000..bd58e20 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,55 @@ +/*****************************************************************************/ +/* */ +/* assert.h */ +/* */ +/* Diagnostics */ +/* */ +/* */ +/* */ +/* (C) 1998-2000 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@musoftware.de */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _ASSERT_H +#define _ASSERT_H + + + +#undef assert +#ifdef NDEBUG +# define assert(expr) +#else +extern void _afailed (const char*, unsigned); +# define assert(expr) ((expr)? (void)0 : _afailed(__FILE__, __LINE__)) +#endif + + + +/* End of assert.h */ +#endif + + + diff --git a/include/console.h b/include/console.h index 561a941..8eb83b7 100644 --- a/include/console.h +++ b/include/console.h @@ -46,3 +46,10 @@ typedef struct Console { //character with inverted colors #define inv(c) ((c) | 0x80) +//void blit(char command, char x, char y, char xo, char yo, char w, char h); + +#define fill(b, x, y, w, h) blit(1, b, 0, x, y, w, h) +#define invert(x, y, w, h) blit(2, 0, 0, x, y, w, h) +#define scroll(x, y, ox, oy, w, h) blit(3, x, y, ox, oy, w, h) + + diff --git a/include/redbus.h b/include/redbus.h index 344bd75..b24807e 100644 --- a/include/redbus.h +++ b/include/redbus.h @@ -30,4 +30,4 @@ void __fastcall__ rb_map_device(unsigned char id); // 0x06 Set POR address to A // 0x86 Get POR address to A -// 0xFF Output A register to MC logfile. \ No newline at end of file +// 0xFF Output A register to MC logfile. diff --git a/lib/common/Makefile b/lib/common/Makefile index 3c25b6f..a2be6b2 100644 --- a/lib/common/Makefile +++ b/lib/common/Makefile @@ -43,10 +43,11 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include --cpu $( C_OBJS = strtok.o \ strtol.o \ strtoul.o \ - strxfrm.o + strxfrm.o \ + _hextab.o # strftime.o \ #_afailed.o \ -# _hextab.o \ + # _poserror.o \ # _scanf.o \ # abort.o \ diff --git a/lib/common/_hextab.c b/lib/common/_hextab.c new file mode 100644 index 0000000..d4f24b2 --- /dev/null +++ b/lib/common/_hextab.c @@ -0,0 +1,15 @@ +/* + * Ullrich von Bassewitz, 11.08.1998 + * + * Hex conversion table. Must be in C since the compiler will convert + * to the correct character set for the target platform. + */ + + + +const unsigned char _hextab [16] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' +}; + + diff --git a/lib/common/_hextab.s b/lib/common/_hextab.s new file mode 100644 index 0000000..91dcfd8 --- /dev/null +++ b/lib/common/_hextab.s @@ -0,0 +1,34 @@ +; +; File generated by cc65 v 2.13.3 +; + .fopt compiler,"cc65 v 2.13.3" + .setcpu "65C02" + .smart on + .autoimport on + .case on + .debuginfo on + .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 + .macpack longbranch + .dbg file, "_hextab.c", 306, 965299531 + .export __hextab + +.segment "RODATA" + +__hextab: + .byte $30 + .byte $31 + .byte $32 + .byte $33 + .byte $34 + .byte $35 + .byte $36 + .byte $37 + .byte $38 + .byte $39 + .byte $41 + .byte $42 + .byte $43 + .byte $44 + .byte $45 + .byte $46 + diff --git a/lib/rpc8e.lib b/lib/rpc8e.lib index 61a67af089e0fe940c77d2cd55cc19371a835a9d..1049e0aeda80160ff16450a99c559c4507539aff 100644 GIT binary patch delta 1129 zcmY*XSxi$w6rDQ{>Z4^ZJ5(sRpg>zz0UNfqVy!425&}`75D)_biZO(kAc!nq601I< zV#S!~52znx;+LoiBrY-G!-^5t1QUJ?xDip}ycwQ>m-lkcx#!+HcjnERWpQyuR5v@z zIy4BOw3}V(aW&}mUNe1fdx=pGkyxOVI1(VjhX;=&gAPI)X|`Np1cbB{Ptoszt1B$J zvxr9M`~R`5YU^qcBk+^WAT=^!-?QMSK?24FV0q65GV^Ah`XD(1=tBsbai{R3lE^`*83w39>!SV)+ z*X1?Yl`eE~JIQxI_nIzZ35a}1?S8oD&Gs;P0ABLgP&xPrEOx6B_Hedv2!3)l?}S%g z%zaW19+g0khzuWtMebfW4*gmd)18Avp0|4d{DWDn;wsqq8H`+mca)WSr0(nRSHNO3M_V5?RUhFY;|wL_J&pDiP??Ou3v#iy5 z+_P;rUVmn@eD2wiryx=CN{E10mm>mcBN?86lEP zpwkGQgsHnG=u?Y}Kjd7U6&^E_dg`Dao2ub5q%#a@&kj)I>Kf=}9*)}J1y^#IE8ZsO zGHnA*@|4zHaQ*)&#)ixk$|AoSGZB>W{ogP~oysV-kgw$*Y-t58zhR#XqH1=Ht_@ys zZ)QJa3(Wi44o1@Ih9oIDI+-Nlp3@)mfoQcQG9hASd+kLQW_+smI(gkN{@TJPu*6 zFmyhEZwpBW2##btQdLAi2>JrFW-WQ9SG$j#GMrGUTqNEc{M zpAER|7CKT)Ub4bHE1oPNdBC8z3j5Y8;M$I38x$zA;r)#Y%-7wGnjjZC26um{?)smZk0Phb|VgLXD diff --git a/lib/rpc8e/Makefile b/lib/rpc8e/Makefile index db84454..c8e9f12 100644 --- a/lib/rpc8e/Makefile +++ b/lib/rpc8e/Makefile @@ -32,12 +32,14 @@ OBJS = crt0.o \ redbus.o \ ctype.o +#COBJS = console.o + #-------------------------------------------------------------------------- # Targets .PHONY: all clean zap -all: $(OBJS) +all: $(OBJS) $(COBJS) clean: @$(RM) *~ $(COBJS:.o=.s) $(OBJS) diff --git a/lib/rpc8e/console.c b/lib/rpc8e/console.c new file mode 100644 index 0000000..876a6b9 --- /dev/null +++ b/lib/rpc8e/console.c @@ -0,0 +1 @@ +#include diff --git a/test/Makefile b/test/Makefile index a9a86c2..e4474cb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,14 +3,19 @@ AS = ../bin/ca65 CC = ../bin/cc65 AL = ../bin/align -CINCLUDE = -I ../include +CINCLUDE = -I../include CFLAGS = -t none --cpu $(CPU) LFLAGS = -C ../lib/rpc8e.cfg LLIBS = ../lib/rpc8e.lib -IMAGES = test_rb.img irc_client.img +#gonna leave this here for now +CPU = 65c02 + + +IMAGES = test_rb.img test_stdlib.img .PHONY: all + all: $(IMAGES) %.s: %.c @@ -19,15 +24,12 @@ all: $(IMAGES) %.o: %.s $(AS) $(CFLAGS) $< -%.img: %.o - $(LD) $(LFLAGS) $< $(LLIBS) -o $@ +%.img: %.o test.o + $(LD) $(LFLAGS) $< test.o $(LLIBS) -o $@ $(AL) $@ - - - clean: - rm *.o + rm *.o *.s .SUFFIXES: \ No newline at end of file diff --git a/test/irc_client.c b/test/irc_client.c index e276cc0..9762e0d 100644 --- a/test/irc_client.c +++ b/test/irc_client.c @@ -35,10 +35,6 @@ void blit(char command, char x, char y, char xo, char yo, char w, char h) { while(con->blit_mode != 0) ; //WAI } -#define fill(b, x, y, w, h) blit(1, b, 0, x, y, w, h) -#define invert(x, y, w, h) blit(2, 0, 0, x, y, w, h) -#define scroll(x, y, ox, oy, w, h) blit(3, x, y, ox, oy, w, h) - #define LF 13 void prepare_screen() { diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..385f1ac --- /dev/null +++ b/test/test.c @@ -0,0 +1,59 @@ +#include +#include + +#include "test.h" + +#define RB 0x0300 +#define LSTREAM 47 +#define SCREEN_W 80 +#define SCREEN_H 50 + +Console* con; + +void blit(char command, char x, char y, char xo, char yo, char w, char h) { + con->blit_start_x = x; + con->blit_start_y = y; + con->blit_offset_x = xo; + con->blit_offset_y = yo; + con->blit_width = w; + con->blit_height = h; + con->blit_mode = command; + while(con->blit_mode != 0) ; //WAI +} + +void linefeed() { + scroll(0,1,0,0,SCREEN_W,SCREEN_H-3); + fill(0x20,0,LSTREAM,SCREEN_W,1); +} + +unsigned char cursor = 0; + +void print(char* buffer) { + unsigned char i = 0; + + if(buffer[0] == 0) return; + + con->line = LSTREAM; + + if(cursor == 0) linefeed(); + + while(buffer[i] != 0 && i < 128) { + if(buffer[i] == '\n' || cursor == 80) { + cursor = 0; + linefeed(); + } else { + con->display[cursor] = buffer[i]; + ++cursor; + } + ++i; + } + + if(i < 128) + cursor = 0; +} + +void init_tests() { + rb_set_window((void*)RB); + con = (Console*)RB; + rb_enable(); +} \ No newline at end of file diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..240abc7 --- /dev/null +++ b/test/test.h @@ -0,0 +1,4 @@ +void init_tests(); +void print(char* buffer); + +#define TEST(NAME, COND) print(NAME); print(#COND); if((COND)) print("PASS\n"); else print("FAIL\n") diff --git a/test/test.s b/test/test.s new file mode 100644 index 0000000..7d1d51c --- /dev/null +++ b/test/test.s @@ -0,0 +1,304 @@ +; +; File generated by cc65 v 2.13.3 +; + .fopt compiler,"cc65 v 2.13.3" + .setcpu "65C02" + .smart on + .autoimport on + .case on + .debuginfo off + .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 + .macpack longbranch + .import _rb_enable + .import _rb_set_window + .export _init_tests + .export _print + .export _con + .export _blit + .export _linefeed + .export _cursor + +.segment "DATA" + +_cursor: + .byte $00 + +.segment "BSS" + +_con: + .res 2,$00 + +; --------------------------------------------------------------- +; void __near__ init_tests (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _init_tests: near + +.segment "CODE" + + ldx #$03 + lda #$00 + jsr _rb_set_window + ldx #$03 + lda #$00 + sta _con + stx _con+1 + jsr _rb_enable + rts + +.endproc + +; --------------------------------------------------------------- +; void __near__ print (__near__ unsigned char*) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _print: near + +.segment "CODE" + + lda #$00 + jsr pusha + ldy #$02 + jsr ldaxysp + ldy #$00 + jsr ldauidx + cmp #$00 + jsr booleq + jeq L0029 + jmp L0045 +L0029: lda _con + ldx _con+1 + jsr pushax + ldx #$00 + lda #$2F + ldy #$00 + jsr staspidx + ldx #$00 + lda _cursor + cmp #$00 + jsr booleq + jeq L002E + jsr _linefeed +L002E: ldy #$02 + jsr ldaxysp + jsr pushax + ldy #$02 + ldx #$00 + lda (sp),y + jsr tosaddax + ldy #$00 + jsr ldauidx + cmp #$00 + jsr boolne + jeq L0035 + ldy #$00 + ldx #$00 + lda (sp),y + cmp #$80 + jsr boolult + jne L0033 +L0035: ldx #$00 + lda #$00 + jeq L0036 +L0033: ldx #$00 + lda #$01 +L0036: jeq L0032 + ldy #$02 + jsr ldaxysp + jsr pushax + ldy #$02 + ldx #$00 + lda (sp),y + jsr tosaddax + ldy #$00 + jsr ldauidx + cmp #$0A + jsr booleq + jne L0038 + ldx #$00 + lda _cursor + cmp #$50 + jsr booleq + jne L0038 + ldx #$00 + lda #$00 + jeq L003A +L0038: ldx #$00 + lda #$01 +L003A: jeq L0037 + ldx #$00 + lda #$00 + sta _cursor + jsr _linefeed + jmp L003E +L0037: lda _con + ldx _con+1 + ldy #$10 + jsr incaxy + jsr pushax + ldx #$00 + lda _cursor + jsr tosaddax + jsr pushax + ldy #$04 + jsr ldaxysp + jsr pushax + ldy #$04 + ldx #$00 + lda (sp),y + jsr tosaddax + ldy #$00 + jsr ldauidx + ldy #$00 + jsr staspidx + ldx #$00 + inc _cursor + lda _cursor +L003E: ldy #$00 + ldx #$00 + clc + lda #$01 + adc (sp),y + sta (sp),y + jmp L002E +L0032: ldy #$00 + ldx #$00 + lda (sp),y + cmp #$80 + jsr boolult + jeq L0045 + ldx #$00 + lda #$00 + sta _cursor +L0045: jsr incsp3 + rts + +.endproc + +; --------------------------------------------------------------- +; void __near__ blit (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _blit: near + +.segment "CODE" + + lda _con + ldx _con+1 + jsr pushax + ldy #$07 + ldx #$00 + lda (sp),y + ldy #$08 + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$06 + ldx #$00 + lda (sp),y + ldy #$09 + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$05 + ldx #$00 + lda (sp),y + ldy #$0A + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$04 + ldx #$00 + lda (sp),y + ldy #$0B + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$03 + ldx #$00 + lda (sp),y + ldy #$0C + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$02 + ldx #$00 + lda (sp),y + ldy #$0D + jsr staspidx + lda _con + ldx _con+1 + jsr pushax + ldy #$08 + ldx #$00 + lda (sp),y + ldy #$07 + jsr staspidx +L0012: lda _con + ldx _con+1 + ldy #$07 + jsr ldauidx + cmp #$00 + jsr boolne + jeq L0013 + jmp L0012 +L0013: jsr incsp7 + rts + +.endproc + +; --------------------------------------------------------------- +; void __near__ linefeed (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _linefeed: near + +.segment "CODE" + + lda #$03 + jsr pusha + lda #$00 + jsr pusha + lda #$01 + jsr pusha + lda #$00 + jsr pusha + lda #$00 + jsr pusha + lda #$50 + jsr pusha + lda #$2F + jsr pusha + jsr _blit + lda #$01 + jsr pusha + lda #$20 + jsr pusha + lda #$00 + jsr pusha + lda #$00 + jsr pusha + lda #$2F + jsr pusha + lda #$50 + jsr pusha + lda #$01 + jsr pusha + jsr _blit + rts + +.endproc + diff --git a/test/test_ctype.c b/test/test_ctype.c new file mode 100644 index 0000000..e69de29 diff --git a/test/test_rb.s b/test/test_rb.s deleted file mode 100644 index c0063b2..0000000 --- a/test/test_rb.s +++ /dev/null @@ -1,64 +0,0 @@ -; -; File generated by cc65 v 2.13.3 -; - .fopt compiler,"cc65 v 2.13.3" - .setcpu "65C02" - .smart on - .autoimport on - .case on - .debuginfo off - .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 - .macpack longbranch - .forceimport __STARTUP__ - .import _rb_enable - .import _rb_set_window - .import _rb_map_device - .export _main - -; --------------------------------------------------------------- -; void __near__ main (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _main: near - -.segment "CODE" - - jsr decsp2 - ldx #$03 - lda #$00 - jsr _rb_set_window - lda #$01 - jsr _rb_map_device - jsr _rb_enable - ldx #$03 - lda #$00 - ldy #$00 - jsr staxysp - ldy #$01 - jsr ldaxysp - jsr pushax - ldx #$00 - lda #$02 - ldy #$03 - jsr staspidx - ldy #$01 - jsr ldaxysp - jsr pushax - ldx #$00 - lda #$58 - ldy #$10 - jsr staspidx - ldy #$01 - jsr ldaxysp - jsr pushax - ldx #$00 - lda #$D9 - ldy #$11 - jsr staspidx - jsr incsp2 - rts - -.endproc - diff --git a/test/test_stdlib.c b/test/test_stdlib.c new file mode 100644 index 0000000..f457661 --- /dev/null +++ b/test/test_stdlib.c @@ -0,0 +1,48 @@ +#include +#include "test.h" + + +// void* malloc (size_t size); +// void* calloc (size_t count, size_t size); +// void* realloc (void* block, size_t size); +// void free (void* block); +// void _heapadd (void* mem, size_t size); +// size_t _heapblocksize (const void* block); +// size_t _heapmemavail (void); +// size_t _heapmaxavail (void); +// int rand (void); +// void srand (unsigned seed); +// void _randomize (void); +// void abort (void); +//// int abs (int val); +// long labs (long val); +//// int atoi (const char* s); +// long atol (const char* s); +// int atexit (void (*exitfunc) (void)); +// void* bsearch (const void* key, const void* base, size_t n, size_t size, int (*cmp) (const void*, const void*)); +// div_t div (int numer, int denom); +// void exit (int ret); +// char* getenv (const char* name); +// void qsort (void* base, size_t count, size_t size, int (*compare) (const void*, const void*)); +// long strtol (const char* nptr, char** endptr, int base); +// unsigned long strtoul (const char* nptr, char** endptr, int base); +// int system (const char* s); +// void _swap (void* p, void* q, size_t size); +//// char* itoa (int val, char* buf, int radix); +// char* utoa (unsigned val, char* buf, int radix); +// char* ltoa (long val, char* buf, int radix); +// char* ultoa (unsigned long val, char* buf, int radix); +// int putenv (char* s); + + +void main() +{ + char temp[5]; + + init_tests(); + + TEST("abs", 1 == abs(-1)); + TEST("abs", 0xFAF == abs(0xFAF)); + + TEST("itoa-atoi", 257 == atoi(itoa(257, temp, 10))); +} \ No newline at end of file diff --git a/test/test_string.c b/test/test_string.c new file mode 100644 index 0000000..e69de29