From 21a33681c0b8cf7bec1e760a2a07b76aad6e98bc Mon Sep 17 00:00:00 2001 From: lux Date: Mon, 2 Oct 2017 01:19:11 +0200 Subject: [PATCH] expand code documentation. --- src/helper.h | 19 ++++++++++++++++++- src/toy.h | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/helper.h b/src/helper.h index d715703..0f416aa 100644 --- a/src/helper.h +++ b/src/helper.h @@ -2,13 +2,30 @@ #define DEBUG_H /** -* get2compl(): interpret the transfer value as tow's complement +* get2compl(): interprets the transfer value as tow's complement * Return: tow's complement value between -32768 and 32767 */ int32_t get2compl(uint16_t value); +/** + * fprintBits(): interprets an integer value as a binary pattern.(little endian) + * if you pass the datatype and the address of an integer, + * the funktion will supply the binary representation. + * (give "stdout" as the last parameter for standard output, + * otherwise hand over a filepointer) + * Return: none + */ + void fprintBits(size_t const size, void const * const ptr, FILE *file_pointer); + +/** + * makeHexDump(): writes the RAM content to a textfile. + * if you pass true to base_2, binary code is written to the textfile, + * otherwise hexcode. + * Return: none + */ + void makeHexDump(bool base_2, uint16_t ram[]); #endif diff --git a/src/toy.h b/src/toy.h index b85bd20..31b3d46 100644 --- a/src/toy.h +++ b/src/toy.h @@ -9,8 +9,8 @@ extern const uint16_t * const ACCU; //read only access to accu /** -* print_instructionSet(): print the cpu instruction set -* This is a user help function, can be activated via +* print_instructionSet(): prints the cpu instruction set. +* This is a user help function and can be activated via * the -h paramter. * Return: none */ @@ -18,33 +18,33 @@ extern const uint16_t * const ACCU; //read only access to accu void print_instructionSet(void); /** -* initialise_ram(): read inputstream into the toy-ram +* initialise_ram(): reads inputstream into the toy-ram. * Return: * the number of successfully read machine words, -* -1 in case of error +* -1 in case of error. */ int initialise_ram(uint16_t *ram, int argc, char **argv ); /** -* get_opcode(): segments the mashine code in the OP-Code -* Return: 4 bit OP-Code +* get_opcode(): segments the mashine code in the OP-Code. +* Return: 4 bit OP-Code. */ uint8_t get_opcode(uint16_t instruction); /** -* get_data(): get the addressed data from the RAM -* Return: the 12 bit data address +* get_data(): gets the addressed data from the RAM. +* Return: the 12 bit data address. */ uint16_t get_data(uint16_t instruction); /** -* execute(): execute the toy-CPU instruction +* execute(): executes the toy-CPU instruction. * This function implements the CPU instruction set, * use print_instructionSet() for an overview. -* Return: true if there is a jump +* Return: true if there is a jump. */ bool execute(uint8_t op_code, int data_addr,uint16_t *ram);