Reworked rendering system and added dynamic colors
This commit is contained in:
parent
0b6a27a5ce
commit
a640c1a764
85
src/video.c
85
src/video.c
@ -1,5 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#define HIGHCOLOR 255
|
||||
#define LOWCOLOR 96
|
||||
|
||||
extern float displayScale;
|
||||
|
||||
@ -13,24 +17,43 @@ uint8_t videoMode;
|
||||
uint8_t videoA;
|
||||
|
||||
/* Private Variables */
|
||||
static uint8_t videoRow;
|
||||
static uint8_t videoValue;
|
||||
static uint8_t videoColorValue;
|
||||
|
||||
static uint32_t videoColorIndex[] = {
|
||||
0x000000FF,
|
||||
0xFF0000FF,
|
||||
0x00FF00FF,
|
||||
0xFFFF00FF,
|
||||
0x0000FFFF,
|
||||
0xFF00FFFF,
|
||||
0x00FFFFFF,
|
||||
0xFFFFFFFF
|
||||
};
|
||||
static uint32_t videoColorIndex[16];
|
||||
static uint8_t videoMemory[0x8000];
|
||||
static uint32_t renderMemory[(SDL_X_SIZE * SDL_Y_SIZE)];
|
||||
uint32_t renderMemory[(SDL_X_SIZE * SDL_Y_SIZE)];
|
||||
|
||||
|
||||
|
||||
void updatePalette(){
|
||||
uint8_t accentColors = videoMode & 0b11101110;
|
||||
for (uint8_t i = 0; i < 16; i++){
|
||||
uint32_t rawColor =
|
||||
((i & 0b1) ?
|
||||
HIGHCOLOR - (i & 0x8 ? 0 : LOWCOLOR) : 0) << 24 |
|
||||
|
||||
(((i & 0b10) ?
|
||||
HIGHCOLOR - (i & 0x8 ? 0 : LOWCOLOR) : 0) << 16) |
|
||||
|
||||
(((i & 0b100) ?
|
||||
HIGHCOLOR - (i & 0x8 ? 0 : LOWCOLOR) : 0) << 8) |
|
||||
|
||||
0x000000FF;
|
||||
|
||||
videoColorIndex[i] = rawColor;
|
||||
}
|
||||
}
|
||||
|
||||
void initVideo(){
|
||||
videoModified = 1;
|
||||
videoMode = 0x01;
|
||||
updatePalette();
|
||||
|
||||
/* Fill VRAM with random values, just for fun */
|
||||
for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand();
|
||||
}
|
||||
|
||||
void writeVideo(){
|
||||
videoMemory[videoX + (videoY * 128)] = videoA;
|
||||
videoModified = 1;
|
||||
@ -40,22 +63,8 @@ uint8_t readVideo(){
|
||||
return videoMemory[videoX + (videoY * 128)];
|
||||
}
|
||||
|
||||
void initVideo(){
|
||||
videoModified = 1;
|
||||
videoMode = 0x01;
|
||||
|
||||
for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand();
|
||||
}
|
||||
|
||||
void updateVideo(){
|
||||
if (videoModified){
|
||||
//sfVertexArray_clear(renderArray);
|
||||
|
||||
for (uint8_t y = 0; y < 255; y++){
|
||||
videoRow = (int8_t)(y & 0x7);
|
||||
|
||||
for (uint8_t x = 0; x < 48; x++){
|
||||
|
||||
void setPixels(uint8_t x, uint8_t y){
|
||||
/* Check for Text or Graphics Mode */
|
||||
if ((videoMode & 0x01) == 0){
|
||||
/*
|
||||
* Text Address Format
|
||||
@ -65,11 +74,11 @@ void updateVideo(){
|
||||
* A = address
|
||||
*/
|
||||
|
||||
// Get text index value
|
||||
/* Get text index value */
|
||||
videoValue = videoMemory[(((y & 0xF8) >> 3) << 7) | x];
|
||||
|
||||
// Index the value in font location
|
||||
videoValue = videoMemory[(videoRow | 0b1111000) + (videoValue * 128)];
|
||||
/* Index the value in font location */
|
||||
videoValue = videoMemory[((y & 0x7) | 0b1111000) + (videoValue * 128)];
|
||||
videoColorValue = videoMemory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)];
|
||||
}
|
||||
else {
|
||||
@ -78,7 +87,7 @@ void updateVideo(){
|
||||
}
|
||||
|
||||
// Snipping out the upper 8 colors
|
||||
videoColorValue &= 0x77;
|
||||
// videoColorValue &= 0x77;
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++){
|
||||
if (displayScale == 1){
|
||||
@ -91,12 +100,18 @@ void updateVideo(){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateVideo(){
|
||||
if (videoModified){
|
||||
//sfVertexArray_clear(renderArray);
|
||||
|
||||
for (uint16_t y = 0; y < 256; y++){
|
||||
for (uint8_t x = 0; x < 48; x++){
|
||||
setPixels(x, (uint8_t)y);
|
||||
}
|
||||
}
|
||||
|
||||
videoModified = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user