From: sparky4 Date: Thu, 14 Jun 2018 14:39:19 +0000 (-0500) Subject: worked abit on the type_to_bianary functions X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=commitdiff_plain;h=40badd0143ad830bd4d873acb9a836f191cc6d57 worked abit on the type_to_bianary functions --- diff --git a/src/inputest.c b/src/inputest.c index 8016e495..08c5745f 100755 --- a/src/inputest.c +++ b/src/inputest.c @@ -67,6 +67,8 @@ main(int argc, char *argv[]) gvar.player[0].enti.d=2; gvar.player[0].enti.spt=4; +// wordtest(); + bytetest(); //0000 nibbletest(); //0000 booleantest(); //printf("dbg_testkeyin=%u dbg_testcontrolnoisy=%u dbg_nogvar.playerinpu=%u\nloop if this is not responsive then please KILL or reset machine sorry!!\n", dbg_testkeyin, dbg_testcontrolnoisy, dbg_nogvar.playerinpu); diff --git a/src/lib/16_head.c b/src/lib/16_head.c index 68b0645e..e5ddd6dc 100755 --- a/src/lib/16_head.c +++ b/src/lib/16_head.c @@ -323,6 +323,7 @@ _dl=_DL; // printf(" ip=%04x\n\n", _IP); // printf(" cf=%04x\npf=%04x\naf=%04x\nzf=%04x\nsf=%04x\ntf=%04x\nif=%04x\ndf=%04x\nof=%04x\n", _CF, _PF, _AF, _ZF, _SF, _TF, _IF, _DF, _OF); printf("cflag: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_cflag>>8), BYTE_TO_BINARY(_cflag)); +// printf("cflag: %s\n",(_cflag)); #endif printf("dx: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_dx>>8), BYTE_TO_BINARY(_dx)); printf(" ---------------------------------------\n"); diff --git a/src/lib/16_tail.c b/src/lib/16_tail.c index 50cd2e82..d8f18b94 100755 --- a/src/lib/16_tail.c +++ b/src/lib/16_tail.c @@ -793,37 +793,52 @@ void turboXT(byte bakapee) } #endif -const char *word_to_binary(word x) +//from https://stackoverflow.com/questions/18327439/printing-binary-representation-of-a-char-in-c +const char *word_to_binary(int x) { static char b[17]; int z; b[0] = '\0'; - for (z = 16; z > 0; z >>= 1) + for (z = 256; z > 0; z >>= 1) { +/// printf(" z=%u b=%u x=%u\n", z, b, x); strcat(b, ((x & z) == z) ? "1" : "0"); } return b; } -const char *nibble_to_binary(nibble x) +const char *byte_to_binary(int x) { static char b[9]; int z; b[0] = '\0'; - for (z = 8; z > 0; z >>= 1) + for (z = 128; z > 0; z >>= 1) { strcat(b, ((x & z) == z) ? "1" : "0"); } return b; } -const char *boolean_to_binary(boolean x) +const char *nibble_to_binary(int x) { static char b[9]; int z; + b[0] = '\0'; + for (z = 8; z > 0; z >>= 1) + { + strcat(b, ((x & z) == z) ? "1" : "0"); + } + return b; +} + +const char *boolean_to_binary(int x) +{ + static char b[3]; + int z; + b[0] = '\0'; for (z = 1; z > 0; z >>= 1) { @@ -832,13 +847,35 @@ const char *boolean_to_binary(boolean x) return b; } +void wordtest() +{ + word pee; + printf("wordtest\n"); + /* word to binary string */ + for(pee=0;pee<280;pee++) + printf(" %u %s\n", pee, word_to_binary(pee)); + printf(" sizeof(word)=%s\n", word_to_binary(sizeof(word))); + printf("end of word test\n"); +} + +void bytetest() +{ + byte pee; + printf("bytetest\n"); + /* byte to binary string */ + for(pee=0;pee<18;pee++) + printf(" %u %s\n", pee, byte_to_binary(pee)); + printf(" sizeof(byte)=%s\n", byte_to_binary(sizeof(byte))); + printf("end of byte test\n"); +} + void nibbletest() { nibble pee; printf("nibbletest\n"); /* nibble to binary string */ for(pee=0;pee<18;pee++) - printf(" %u %s\n", pee, nibble_to_binary(pee)); + printf(" %u %s\n", pee, nibble_to_binary(pee)); printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble))); printf("end of nibble test\n"); } @@ -849,7 +886,7 @@ void booleantest() printf("booleantest\n"); /* boolean to binary string */ for(pee=0;pee<4;pee++) - printf(" %u %s\n", pee, boolean_to_binary(pee)); + printf(" %u %s\n", pee, boolean_to_binary(pee)); printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean))); printf("end of boolean test\n"); } diff --git a/src/lib/16_tail.h b/src/lib/16_tail.h index 79cf67aa..9d6555ad 100755 --- a/src/lib/16_tail.h +++ b/src/lib/16_tail.h @@ -141,6 +141,12 @@ void DebugMemory_(global_game_variables_t *gvar, boolean q); void ClearMemory (global_game_variables_t *gvar); void Quit (global_game_variables_t *gvar, char *error); void turboXT(byte bakapee); +const char *word_to_binary(int x); +const char *byte_to_binary(int x); +const char *nibble_to_binary(int x); +const char *boolean_to_binary(int x); +void wordtest(); +void bytetest(); void nibbletest(); void booleantest();