Updated video.c for SDL
This commit is contained in:
parent
1884b56533
commit
98b435f570
55
src/video.c
55
src/video.c
@ -1,12 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <SFML/System.h>
|
||||
#include <SFML/Graphics.h>
|
||||
#include <SFML/Window.h>
|
||||
extern float displayScale;
|
||||
|
||||
/* Public Variables */
|
||||
extern sfVertexArray *renderArray;
|
||||
int8_t videoModified;
|
||||
|
||||
/* Hardware-like Registers */
|
||||
@ -19,24 +16,19 @@ uint8_t videoA;
|
||||
static uint8_t videoRow;
|
||||
static uint8_t videoValue;
|
||||
static uint8_t videoColorValue;
|
||||
static sfColor videoDisplayColor;
|
||||
static sfColor videoForeColor;
|
||||
static sfColor videoBackColor;
|
||||
|
||||
const static sfColor videoUpperPalette = (sfColor){ 64, 64, 64 };
|
||||
|
||||
static sfColor *videoColorIndex[] = {
|
||||
&sfBlack, &sfRed, &sfGreen, &sfYellow, &sfBlue, &sfMagenta, &sfCyan, &sfWhite//&(sfColor){ 96, 96, 96 } ,
|
||||
/*&(sfColor){ 0, 0, 0 },
|
||||
&(sfColor){ 0xFF, 0, 0 },
|
||||
&(sfColor){ 0, 0xFF, 0 },
|
||||
&(sfColor){ 0xFF, 0xFF, 0 },
|
||||
&(sfColor){ 0, 0, 0xFF },
|
||||
&(sfColor){ 0xFF, 0, 0xFF },
|
||||
&(sfColor){ 0, 0xFF, 0xFF },
|
||||
&(sfColor){ 0xFF, 0xFF, 0xFF },*/
|
||||
static uint32_t videoColorIndex[] = {
|
||||
0x000000FF,
|
||||
0xFF0000FF,
|
||||
0x00FF00FF,
|
||||
0xFFFF00FF,
|
||||
0x0000FFFF,
|
||||
0xFF00FFFF,
|
||||
0x00FFFFFF,
|
||||
0xFFFFFFFF
|
||||
};
|
||||
static uint8_t videoMemory[0x8000];
|
||||
static uint32_t renderMemory[(SDL_X_SIZE * SDL_Y_SIZE)];
|
||||
|
||||
|
||||
void writeVideo(){
|
||||
@ -49,9 +41,6 @@ uint8_t readVideo(){
|
||||
}
|
||||
|
||||
void initVideo(){
|
||||
renderArray = sfVertexArray_create();
|
||||
sfVertexArray_setPrimitiveType(renderArray, sfQuads);
|
||||
|
||||
videoModified = 1;
|
||||
videoMode = 0x01;
|
||||
|
||||
@ -60,7 +49,7 @@ void initVideo(){
|
||||
|
||||
void updateVideo(){
|
||||
if (videoModified){
|
||||
sfVertexArray_clear(renderArray);
|
||||
//sfVertexArray_clear(renderArray);
|
||||
|
||||
for (uint8_t y = 0; y < 255; y++){
|
||||
videoRow = (int8_t)(y & 0x7);
|
||||
@ -91,18 +80,16 @@ void updateVideo(){
|
||||
// Snipping out the upper 8 colors
|
||||
videoColorValue &= 0x77;
|
||||
|
||||
videoForeColor = *videoColorIndex[(videoColorValue & 0x0F)];
|
||||
videoBackColor = *videoColorIndex[((videoColorValue & 0xF0) >> 4)];
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++){
|
||||
if (videoValue & (128 >> i)) videoDisplayColor = videoBackColor;
|
||||
else videoDisplayColor = videoForeColor;
|
||||
|
||||
sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i, y }, videoDisplayColor});
|
||||
sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i + 1, y }, videoDisplayColor});
|
||||
sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i + 1, y + 1 }, videoDisplayColor});
|
||||
sfVertexArray_append(renderArray, (sfVertex){ (sfVector2f){ (x * 8) + i, y + 1 }, videoDisplayColor});
|
||||
if (displayScale == 1){
|
||||
renderMemory[(y * SDL_X_SIZE) + ((x * 8) + i)] = (videoValue & (128 >> i)) ? videoColorIndex[((videoColorValue & 0xF0) >> 4)] : videoColorIndex[(videoColorValue & 0x0F)];
|
||||
} else {
|
||||
for (uint8_t _x = 0; _x < displayScale; _x++){
|
||||
for (uint8_t _y = 0; _y < displayScale; _y++){
|
||||
renderMemory[(((y * (int)displayScale) + _y) * SDL_X_SIZE) + ((((x * (int)displayScale) * 8) + (i * (int)displayScale)) + _x)] = (videoValue & (128 >> i)) ? videoColorIndex[((videoColorValue & 0xF0) >> 4)] : videoColorIndex[(videoColorValue & 0x0F)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user