diff --git a/src/video.c b/src/video.c new file mode 100644 index 0000000..c86bfed --- /dev/null +++ b/src/video.c @@ -0,0 +1,117 @@ +#include +#include + +#include +#include +#include + +/* Public Variables */ +extern sfVertexArray *renderArray; +int8_t videoModified; +int8_t videoMode; + +/* Private Variables */ +static uint8_t video_row; +static uint8_t video_value; +static uint8_t video_colorValue; +static sfColor video_displayColor; +static sfColor video_foreColor; +static sfColor video_backColor; + +const sfColor video_upperPalette = (sfColor){ 64, 64, 64 }; + +static sfColor *video_colorIndex[16] = { + &sfBlack, // 0x0 + &sfRed, // 0x1 + &sfGreen, // 0x2 + &sfYellow, // 0x3 + &sfBlue, // 0x4 + &sfMagenta, // 0x5 + &sfCyan, // 0x6 + &(sfColor){ 96, 96, 96 }, // 0x7 + + &(sfColor){ 162, 162, 162 },// 0x8 + &sfRed, // 0x9 + &sfGreen, // 0xA + &sfYellow, // 0xB + &sfBlue, // 0xC + &sfMagenta, // 0xD + &sfCyan, // 0xE + &sfWhite, // 0xF +}; + +static uint8_t video_memory[0x8000]; // Empty Memory with 32k space + +void initVideo(){ + renderArray = sfVertexArray_create(); + sfVertexArray_setPrimitiveType(renderArray, sfQuads); + + videoModified = 1; + videoMode = 0; + + for (int i = 0x8; i < 0xF; i++){ + //*video_colorIndex[i] = sfColor_add(*video_colorIndex[i], video_upperPalette); + } + + for (int i = 0; i < 0x8000; i++){ + video_memory[i] = rand(); + } +} + +void updateVideo(){ + sfVertexArray_clear(renderArray); + sfVertexArray_setPrimitiveType(renderArray, sfQuads); + + videoModified = 0; + + for (int y = 0; y < 256; y++){ + video_row = (int8_t)(y & 0x7); + + for (int x = 0; x < 48; x++){ + + if (videoMode == 1){ + /* + * Text Address Format + * 0bRRR1111AAAAAAAA + * + * R = row pins + * A = address + */ + + // Get text index value + video_value = video_memory[(((y & 0xF8) >> 3) << 7) | x]; + + // Index the value in font location + video_value = video_memory[(video_row | 0b1111000) + (video_value * 128)]; + video_colorValue = video_memory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)]; + } + else { + video_value = video_memory[(y * 128) + x]; + video_colorValue = video_memory[(y * 128) + (x | 0x40)]; + } + + // Snipping out the upper 8 colors + //video_colorValue &= 0x77; + + video_foreColor = *video_colorIndex[(video_colorValue & 0x0F)]; + video_backColor = *video_colorIndex[((video_colorValue & 0xF0) >> 4)]; + + + for (int i = 0; i < 8; i++){ + if (video_value & (128 >> i)){ + video_displayColor = video_foreColor; + } else { + video_displayColor = video_backColor; + } + + sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i, y }, video_displayColor}); + sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i + 1, y }, video_displayColor}); + sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i + 1, y + 1 }, video_displayColor}); + sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i, y + 1 }, video_displayColor}); + } + } + } +} + + +