Reworked rendering system and added dynamic colors
This commit is contained in:
parent
0b6a27a5ce
commit
a640c1a764
131
src/video.c
131
src/video.c
@ -1,5 +1,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#define HIGHCOLOR 255
|
||||||
|
#define LOWCOLOR 96
|
||||||
|
|
||||||
extern float displayScale;
|
extern float displayScale;
|
||||||
|
|
||||||
@ -13,24 +17,43 @@ uint8_t videoMode;
|
|||||||
uint8_t videoA;
|
uint8_t videoA;
|
||||||
|
|
||||||
/* Private Variables */
|
/* Private Variables */
|
||||||
static uint8_t videoRow;
|
|
||||||
static uint8_t videoValue;
|
static uint8_t videoValue;
|
||||||
static uint8_t videoColorValue;
|
static uint8_t videoColorValue;
|
||||||
|
|
||||||
static uint32_t videoColorIndex[] = {
|
static uint32_t videoColorIndex[16];
|
||||||
0x000000FF,
|
|
||||||
0xFF0000FF,
|
|
||||||
0x00FF00FF,
|
|
||||||
0xFFFF00FF,
|
|
||||||
0x0000FFFF,
|
|
||||||
0xFF00FFFF,
|
|
||||||
0x00FFFFFF,
|
|
||||||
0xFFFFFFFF
|
|
||||||
};
|
|
||||||
static uint8_t videoMemory[0x8000];
|
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(){
|
void writeVideo(){
|
||||||
videoMemory[videoX + (videoY * 128)] = videoA;
|
videoMemory[videoX + (videoY * 128)] = videoA;
|
||||||
videoModified = 1;
|
videoModified = 1;
|
||||||
@ -40,63 +63,55 @@ uint8_t readVideo(){
|
|||||||
return videoMemory[videoX + (videoY * 128)];
|
return videoMemory[videoX + (videoY * 128)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void initVideo(){
|
void setPixels(uint8_t x, uint8_t y){
|
||||||
videoModified = 1;
|
/* Check for Text or Graphics Mode */
|
||||||
videoMode = 0x01;
|
if ((videoMode & 0x01) == 0){
|
||||||
|
/*
|
||||||
|
* Text Address Format
|
||||||
|
* 0bRRR1111AAAAAAAA
|
||||||
|
*
|
||||||
|
* R = row pins
|
||||||
|
* A = address
|
||||||
|
*/
|
||||||
|
|
||||||
for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand();
|
/* Get text index value */
|
||||||
|
videoValue = videoMemory[(((y & 0xF8) >> 3) << 7) | x];
|
||||||
|
|
||||||
|
/* Index the value in font location */
|
||||||
|
videoValue = videoMemory[((y & 0x7) | 0b1111000) + (videoValue * 128)];
|
||||||
|
videoColorValue = videoMemory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
videoValue = videoMemory[(y * 128) + x];
|
||||||
|
videoColorValue = videoMemory[(y * 128) + (x | 0x40)];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snipping out the upper 8 colors
|
||||||
|
// videoColorValue &= 0x77;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 8; i++){
|
||||||
|
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)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateVideo(){
|
void updateVideo(){
|
||||||
if (videoModified){
|
if (videoModified){
|
||||||
//sfVertexArray_clear(renderArray);
|
//sfVertexArray_clear(renderArray);
|
||||||
|
|
||||||
for (uint8_t y = 0; y < 255; y++){
|
for (uint16_t y = 0; y < 256; y++){
|
||||||
videoRow = (int8_t)(y & 0x7);
|
|
||||||
|
|
||||||
for (uint8_t x = 0; x < 48; x++){
|
for (uint8_t x = 0; x < 48; x++){
|
||||||
|
setPixels(x, (uint8_t)y);
|
||||||
if ((videoMode & 0x01) == 0){
|
|
||||||
/*
|
|
||||||
* Text Address Format
|
|
||||||
* 0bRRR1111AAAAAAAA
|
|
||||||
*
|
|
||||||
* R = row pins
|
|
||||||
* A = address
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Get text index value
|
|
||||||
videoValue = videoMemory[(((y & 0xF8) >> 3) << 7) | x];
|
|
||||||
|
|
||||||
// Index the value in font location
|
|
||||||
videoValue = videoMemory[(videoRow | 0b1111000) + (videoValue * 128)];
|
|
||||||
videoColorValue = videoMemory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
videoValue = videoMemory[(y * 128) + x];
|
|
||||||
videoColorValue = videoMemory[(y * 128) + (x | 0x40)];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Snipping out the upper 8 colors
|
|
||||||
videoColorValue &= 0x77;
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 8; i++){
|
|
||||||
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)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
videoModified = 0;
|
videoModified = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user