{}
run-icon
main.c
#include <stdio.h> #include <string.h> #define MAX_INPUT_SIZE 8192 #define ROW_SIZE 32 char get_tile_index(char c) { if (c == ' ') return 0x00; // Blank else if (c == ',') return 0x01; // Comma else if (c >= 'A' && c <= 'Z') return 0x02 + (c - 'A'); // A-Z else if (c >= 'a' && c <= 'z') return 0x02 + (c - 'a'); // a-z else if (c >= '0' && c <= '9') return 0x1C + (c - '0'); // 0-9 else if (c == '$') return 0x26; // Dollar sign else if (c == '+') return 0x27; // Plus sign else if (c == '-') return 0x28; // Minus sign else if (c == '!') return 0x29; // Exclamation mark else if (c == '?') return 0x2A; // Question mark else if (c == '\'') return 0x2B; // Single quotation mark else if (c == '.') return 0x2C; // Period return -1; // Invalid character } void print_asm_bytes(const char *input) { int index = 0; int row_count = 0; int current_row_size = 0; printf(".byte "); while (input[index] != '\0') { char tile_index = get_tile_index(input[index]); if (tile_index != -1) { if (current_row_size == ROW_SIZE) { printf("\n.byte "); row_count++; current_row_size = 0; } if (current_row_size > 0) { printf(","); } printf("$%02X", tile_index); current_row_size++; } else if (input[index] == ' ') { // Handle spaces to ensure words fit within rows if (current_row_size + 1 > ROW_SIZE) { printf(",\n.byte $00"); row_count++; current_row_size = 1; } else { if (current_row_size > 0) { printf(","); } printf("$00"); current_row_size++; } } index++; } // Pad the last row with $00 if it isn't full while (current_row_size < ROW_SIZE) { if (current_row_size > 0) { printf(","); } printf("$00"); current_row_size++; } printf("\n"); } int main() { char input[MAX_INPUT_SIZE + 1]; // Allow up to 8192 characters plus null terminator // Prompt the user for input printf("Enter a string (max 8192 bytes): "); // Read the input string if (fgets(input, MAX_INPUT_SIZE + 1, stdin) == NULL) { printf("Error reading input\n"); return 1; } // Remove newline character if present size_t len = strlen(input); if (len > 0 && input[len - 1] == '\n') { input[len - 1] = '\0'; } // Print the assembly representation of the tile indices print_asm_bytes(input); return 0; }
Output