summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miniasm/optable.h10
-rw-r--r--miniasm/parse.h8
-rw-r--r--miniasm/scan.h12
-rw-r--r--minic/minic.c6
-rw-r--r--miniemu/cpu.h16
-rw-r--r--miniemu/memory.h14
-rw-r--r--minilib/arena.h4
-rw-r--r--minilib/ctype.h8
-rw-r--r--minilib/hash.h12
-rw-r--r--minilib/io.h8
-rw-r--r--minilib/minilib.h2
-rw-r--r--minilib/stddef.h5
-rw-r--r--minilib/stdlib.c46
-rw-r--r--minilib/stdlib.h4
-rw-r--r--minilib/string.h12
-rw-r--r--minilib/utils.h4
16 files changed, 113 insertions, 58 deletions
diff --git a/miniasm/optable.h b/miniasm/optable.h
index bd3c5c2..d0b18b3 100644
--- a/miniasm/optable.h
+++ b/miniasm/optable.h
@@ -13,10 +13,10 @@ typedef struct OpcodeInfo
int operands;
} OpcodeInfo;
-extern OpcodeInfo opcodeTable[NOF_OPCODES];
+OpcodeInfo opcodeTable[NOF_OPCODES];
-extern intHashTable opcode_ht;
+intHashTable opcode_ht;
-extern void opcode_table_init( );
-extern void opcode_table_done( );
-extern OpcodeInfo *lookup_opcode( char *mnemonic );
+void opcode_table_init( );
+void opcode_table_done( );
+OpcodeInfo *lookup_opcode( char *mnemonic );
diff --git a/miniasm/parse.h b/miniasm/parse.h
index 4187f29..dfc109f 100644
--- a/miniasm/parse.h
+++ b/miniasm/parse.h
@@ -33,7 +33,7 @@ typedef struct Parser {
int pass;
} Parser;
-extern void parser_init( Parser *p, Scanner *s );
-extern void parser_done( Parser *p );
-extern void parser_debug( Parser *p, int enable );
-extern void parser_parse( Parser *p );
+void parser_init( Parser *p, Scanner *s );
+void parser_done( Parser *p );
+void parser_debug( Parser *p, int enable );
+void parser_parse( Parser *p );
diff --git a/miniasm/scan.h b/miniasm/scan.h
index c4d3b9d..fbc5697 100644
--- a/miniasm/scan.h
+++ b/miniasm/scan.h
@@ -29,9 +29,9 @@ typedef struct Scanner {
int debug;
} Scanner;
-extern void scanner_init( Scanner *s, char *src );
-extern void scanner_reset( Scanner *s );
-extern void scanner_done( Scanner *s );
-extern Symbol scanner_scan( Scanner *s );
-extern void scanner_debug( Scanner *s, int enable );
-extern void scanner_skip_line( Scanner *s );
+void scanner_init( Scanner *s, char *src );
+void scanner_reset( Scanner *s );
+void scanner_done( Scanner *s );
+Symbol scanner_scan( Scanner *s );
+void scanner_debug( Scanner *s, int enable );
+void scanner_skip_line( Scanner *s );
diff --git a/minic/minic.c b/minic/minic.c
new file mode 100644
index 0000000..0031601
--- /dev/null
+++ b/minic/minic.c
@@ -0,0 +1,6 @@
+#include "arena.h"
+
+int main( int argc, char *argv[] )
+{
+ return 0;
+}
diff --git a/miniemu/cpu.h b/miniemu/cpu.h
index b9695c4..7d1ca2d 100644
--- a/miniemu/cpu.h
+++ b/miniemu/cpu.h
@@ -20,11 +20,11 @@ typedef struct Cpu {
int debug;
} Cpu;
-extern void cpu_init( Cpu *cpu, struct Memory *memory );
-extern void cpu_done( Cpu *cpu );
-extern void cpu_reset( Cpu *cpu );
-extern void cpu_step( Cpu *cpu );
-extern int cpu_stopped( Cpu *cpu );
-extern int cpu_has_errors( Cpu *cpu );
-extern void cpu_debug( Cpu *cpu, int enable );
-extern void cpu_print_dump( Cpu *cpu );
+void cpu_init( Cpu *cpu, struct Memory *memory );
+void cpu_done( Cpu *cpu );
+void cpu_reset( Cpu *cpu );
+void cpu_step( Cpu *cpu );
+int cpu_stopped( Cpu *cpu );
+int cpu_has_errors( Cpu *cpu );
+void cpu_debug( Cpu *cpu, int enable );
+void cpu_print_dump( Cpu *cpu );
diff --git a/miniemu/memory.h b/miniemu/memory.h
index 312a42f..e402c91 100644
--- a/miniemu/memory.h
+++ b/miniemu/memory.h
@@ -5,10 +5,10 @@ typedef struct Memory {
char *m;
} Memory;
-extern void memory_init( Memory *memory, int size );
-extern void memory_done( Memory *memory );
-extern void memory_reset( Memory *memory );
-extern void memory_write( Memory *memory, int addr, char v );
-extern char memory_read( Memory *memory, int addr );
-extern void memory_print_dump( Memory *memory );
-extern void memory_read_from_file( Memory *memory, char *filename );
+void memory_init( Memory *memory, int size );
+void memory_done( Memory *memory );
+void memory_reset( Memory *memory );
+void memory_write( Memory *memory, int addr, char v );
+char memory_read( Memory *memory, int addr );
+void memory_print_dump( Memory *memory );
+void memory_read_from_file( Memory *memory, char *filename );
diff --git a/minilib/arena.h b/minilib/arena.h
index 3f486e4..d781981 100644
--- a/minilib/arena.h
+++ b/minilib/arena.h
@@ -9,5 +9,5 @@ enum {
ARENA_SIZE = 65535
};
-extern void *allocate( int size );
-extern void deallocate( void **p );
+void *allocate( int size );
+void deallocate( void **p );
diff --git a/minilib/ctype.h b/minilib/ctype.h
index f19fbce..1262a37 100644
--- a/minilib/ctype.h
+++ b/minilib/ctype.h
@@ -1,6 +1,6 @@
#pragma once
-extern int isalpha( int c );
-extern int isdigit( int c );
-extern int isalnum( int c );
-extern int isspace( int c );
+int isalpha( int c );
+int isdigit( int c );
+int isalnum( int c );
+int isspace( int c );
diff --git a/minilib/hash.h b/minilib/hash.h
index 4be951c..1aaf8ed 100644
--- a/minilib/hash.h
+++ b/minilib/hash.h
@@ -18,9 +18,9 @@ typedef struct intHashIterator {
intHashTable *ht;
} intHashIterator;
-extern void inthash_init( intHashTable *ht, int size );
-extern void inthash_done( intHashTable *ht );
-extern void inthash_set( intHashTable *ht, char *key, int value );
-extern int inthash_get( intHashTable *ht, char *key );
-extern intHashEntry *inthash_getfirst( intHashTable *ht, intHashIterator *it );
-extern intHashEntry *inthash_getnext( intHashIterator *it );
+void inthash_init( intHashTable *ht, int size );
+void inthash_done( intHashTable *ht );
+void inthash_set( intHashTable *ht, char *key, int value );
+int inthash_get( intHashTable *ht, char *key );
+intHashEntry *inthash_getfirst( intHashTable *ht, intHashIterator *it );
+intHashEntry *inthash_getnext( intHashIterator *it );
diff --git a/minilib/io.h b/minilib/io.h
index b2c8033..5dac1c3 100644
--- a/minilib/io.h
+++ b/minilib/io.h
@@ -1,6 +1,6 @@
#pragma once
-extern void print( char *s );
-extern int readfile( char *filename, char *s, int size );
-extern int writefile( char *filename, char *s, int size );
-extern char *readallfile( char *filename );
+void print( char *s );
+int readfile( char *filename, char *s, int size );
+int writefile( char *filename, char *s, int size );
+char *readallfile( char *filename );
diff --git a/minilib/minilib.h b/minilib/minilib.h
index 2e9dd3d..b815836 100644
--- a/minilib/minilib.h
+++ b/minilib/minilib.h
@@ -1,3 +1,3 @@
#pragma once
-extern void halt( void );
+void halt( void );
diff --git a/minilib/stddef.h b/minilib/stddef.h
index a288c39..8ee8040 100644
--- a/minilib/stddef.h
+++ b/minilib/stddef.h
@@ -1,9 +1,10 @@
#pragma once
+/* TODO: preprocess just to define the NULL pointer?! */
#define NULL ( (void *) 0)
/* TODO: drawn in by using some functions from the host */
-#define size_t int
+typedef int size_t;
/* TODO: drawn in by using some functions from the host */
-#define wchar_t int
+typedef int wchar_t;
diff --git a/minilib/stdlib.c b/minilib/stdlib.c
index 96b9b58..53ae0df 100644
--- a/minilib/stdlib.c
+++ b/minilib/stdlib.c
@@ -1,4 +1,50 @@
#include "stdlib.h"
+#include "stdbool.h"
+#include "string.h"
+#include "stddef.h"
+
+static void strreverse( char *s )
+{
+ char *end = s + strlen( s ) - 1;
+
+ while( s < end ) {
+ // XOR swap;
+ *s ^= *end;
+ *end ^= *s;
+ *s ^= *end;
+ s++;
+ end--;
+ }
+}
+
+char *itoa( int v, char *s, int base )
+{
+ static char digit[] = "0123456789ABCDEF";
+ bool sign = false;
+ char *p = s;
+
+ if( base < 2 || base > 16 ) {
+ return NULL;
+ }
+
+ if( v < 0 ) {
+ v = -v;
+ sign = true;
+ }
+
+ do {
+ *p++ = digit[v % base];
+ } while( ( v /= base ) > 0 );
+
+ if( sign ) {
+ *p++ = '-';
+ }
+ *p = '\0';
+
+ strreverse( s );
+
+ return s;
+}
/* TODO: this is the Linux hosted environment */
#define _GNU_SOURCE
diff --git a/minilib/stdlib.h b/minilib/stdlib.h
index 4300381..67335f7 100644
--- a/minilib/stdlib.h
+++ b/minilib/stdlib.h
@@ -1,3 +1,5 @@
#pragma once
-extern void exit( int status );
+char *itoa( int v, char *s, int base );
+
+void exit( int status );
diff --git a/minilib/string.h b/minilib/string.h
index 60cd785..79f903a 100644
--- a/minilib/string.h
+++ b/minilib/string.h
@@ -1,8 +1,8 @@
#pragma once
-extern char *memset( void *p, int c, int n );
-extern char *strcat( char *d, char *s );
-extern char *strcpy( char *d, char *s );
-extern int strlen( char *s );
-extern int strcmp( char *s1, char *s2 );
-extern char *strdup( char *s );
+char *memset( void *p, int c, int n );
+char *strcat( char *d, char *s );
+char *strcpy( char *d, char *s );
+int strlen( char *s );
+int strcmp( char *s1, char *s2 );
+char *strdup( char *s );
diff --git a/minilib/utils.h b/minilib/utils.h
index 1ab26de..068eaea 100644
--- a/minilib/utils.h
+++ b/minilib/utils.h
@@ -1,4 +1,4 @@
#pragma once
-extern void strtohex( char *p, int len, char *s );
-extern void inttohex( int i, char *s );
+void strtohex( char *p, int len, char *s );
+void inttohex( int i, char *s );