Commit 1af8c1a9 authored by David Skywalker's avatar David Skywalker
Browse files

[video] add comments!

parent cf4326bd
Pipeline #105569 passed with stages
in 2 minutes and 3 seconds
......@@ -48,6 +48,10 @@
#include "software.h"
#include "video.h"
/**
* draw_rect:
* draw a rectangle, used by UI and KoS
**/
void draw_rect(uint32_t * buffer, int x, int y, int width, int height, uint32_t color)
{
buffer = (buffer + (x >> retro_video.raw_density_byte)) + (y * retro_video.bps);
......@@ -59,6 +63,10 @@ void draw_rect(uint32_t * buffer, int x, int y, int width, int height, uint32_t
}
}
/**
* draw_char:
* draw a char, used by mouse cursor and text
**/
void draw_char(uint32_t * buffer, int x, int y, char chr_idx, uint32_t color)
{
buffer = (buffer + (x >> retro_video.raw_density_byte)) + (y * retro_video.bps);
......@@ -66,6 +74,10 @@ void draw_char(uint32_t * buffer, int x, int y, char chr_idx, uint32_t color)
retro_video.draw_char(buffer, &font[chr_idx * BITS_IN_BYTE], color);
}
/**
* draw_text:
* draw a text, used by UI and KoS
**/
void draw_text(uint32_t * buffer, int x, int y, const char *text, uint32_t color)
{
int len = strlen(text); // number of characters to process
......@@ -91,6 +103,11 @@ void draw_text(uint32_t * buffer, int x, int y, const char *text, uint32_t color
}
}
/**
* draw_image_linear:
* simple function to draw an image that occupies the entire screen
* does not need to recalculate the position after each line.
**/
void draw_image_linear(unsigned int * buffer, const unsigned int * img, int x, int y, unsigned int size)
{
buffer = (buffer + x) + (y * retro_video.bps);
......@@ -108,11 +125,20 @@ void draw_image_linear(unsigned int * buffer, const unsigned int * img, int x, i
* images are in uint32_t mode
*/
/**
* convert_image:
* convert intenal UI images to current depth mode (using video depth driver)
**/
void convert_image(unsigned int * buffer, const unsigned int * img, unsigned int size)
{
retro_video.convert_image(buffer, img, size);
}
/**
* draw_image_transparent:
* draw a image with full transparency or not (no blend)
* used by KoS letters
**/
void draw_image_transparent(unsigned int * buffer, const unsigned int * img, int x, int y, unsigned int size)
{
uint32_t * buffer_ptr = (
......
......@@ -59,6 +59,21 @@ union TPixel
unsigned int colour;
};
union TColor
{
struct
{
#ifdef MSB_FIRST
unsigned short high;
unsigned short low;
#else
unsigned short low;
unsigned short high;
#endif
};
unsigned int colour;
};
//*****************************************************************************
// Graph helpers functions
......
......@@ -40,8 +40,10 @@
#include "video.h"
#include "assets/assets.h"
/**
* video_setup:
* setup video on core boot
**/
void video_setup(retro_video_depth_t video_depth)
{
switch (video_depth)
......@@ -79,4 +81,4 @@ void video_setup(retro_video_depth_t video_depth)
// cached values
retro_video.bps = (EMULATION_SCREEN_WIDTH) >> retro_video.raw_density_byte;
retro_video.char_size = (FNT_CHAR_WIDTH >> retro_video.raw_density_byte) * EMULATION_SCALE;
}
\ No newline at end of file
}
......@@ -56,7 +56,7 @@ static union TPixel pixel;
#define DATA2RED5(colour) (((colour>>3) & 0x1F) << 11)
/**
* generate antialias values using 32/16bits macros
* generate antialias values using 16bpp macros
*
* RGB[10] 00CE60 || CC CC 00
* 00CE60 (10) || C8 CC 00
......@@ -70,11 +70,19 @@ void video_set_palette_antialias_16bpp(void)
GateArray.palette[33] = (unsigned short) RGB2COLOR(r2/2, g2/2, b2/2);
}
/**
* rgb2color_16bpp:
* convert rgb to 16bpp color (see macros)
**/
unsigned int rgb2color_16bpp(unsigned int r, unsigned int g, unsigned int b)
{
return RGB2COLOR(r, g, b);
}
/**
* convert_color:
* convert raw color to 16bpp color (see macros)
**/
static INLINE unsigned int convert_color(unsigned int colour)
{
pixel.colour = colour;
......@@ -85,6 +93,10 @@ static INLINE unsigned int convert_color(unsigned int colour)
);
}
/**
* draw_pixel_16bpp:
* simple method to emulate a transparency, almost slow but is only used on init
**/
void draw_pixel_16bpp(unsigned int * dest, const unsigned int * img)
{
uint16_t * buffer_ptr = (uint16_t *) dest;
......@@ -100,6 +112,10 @@ void draw_pixel_16bpp(unsigned int * dest, const unsigned int * img)
}
}
/**
* convert_image_16bpp:
* convert raw image to 16bpp, used on init
**/
void convert_image_16bpp(unsigned int * dest, const unsigned int * img, int size)
{
uint16_t * buffer_ptr = (uint16_t *) dest;
......@@ -112,17 +128,31 @@ void convert_image_16bpp(unsigned int * dest, const unsigned int * img, int size
}
}
void draw_line_16bpp(unsigned int * dest, int width, unsigned int color)
/**
* draw_line_16bpp:
* copy a 16bpp color to your dest, optimized
**/
void draw_line_16bpp(unsigned int * dest, int width, unsigned int colour)
{
unsigned short *buffer_ptr = (unsigned short *) dest;
// prepare copy using 32bits
colour += colour << 16;
width >>= 1;
while (width--)
*(buffer_ptr++) = color;
*(dest++) = colour;
}
void draw_char_16bpp(unsigned int * dest, const unsigned char *font_data, unsigned int color)
/**
* draw_char_16bpp:
* draw a 16bpp char to your dest, optimized
**/
void draw_char_16bpp(unsigned int * dest, const unsigned char *font_data, unsigned int colour)
{
#ifdef LOWRES
unsigned short *buffer_ptr = (unsigned short *) dest;
#else
unsigned int *buffer_ptr = dest;
#endif
int height = FNT_CHAR_HEIGHT;
while (height--)
......@@ -133,18 +163,19 @@ void draw_char_16bpp(unsigned int * dest, const unsigned char *font_data, unsign
{
if (data & 0x80) // is the bit set?
{
#ifndef LOWRES
*(buffer_ptr++) = color;
#ifdef LOWRES
*(buffer_ptr++) = colour; // draw the character pixel
#else
*(buffer_ptr++) = colour + (colour << 16);
#endif
*(buffer_ptr++) = color; // draw the character pixel
}
else
{
buffer_ptr += EMULATION_SCALE;
buffer_ptr ++;
}
data <<= 1; // advance to the next bit
}
font_data ++;
buffer_ptr += EMULATION_SCREEN_WIDTH - (FNT_CHAR_WIDTH * EMULATION_SCALE);
buffer_ptr += CPC_SCREEN_WIDTH - (FNT_CHAR_WIDTH);
}
}
......@@ -51,6 +51,12 @@ static union TPixel pixel;
#define RGB2GREEN(colour) ((colour>>8) & 0xFF)
#define RGB2BLUE(colour) (colour & 0xFF)
/**
* generate antialias values using 24bpp macros
*
* RGB[10] 00CE60 || CC CC 00
* 00CE60 (10) || C8 CC 00
*/
void video_set_palette_antialias_24bpp(void)
{
uint8_t r2,g2,b2;
......@@ -60,11 +66,19 @@ void video_set_palette_antialias_24bpp(void)
GateArray.palette[33] = (unsigned short) RGB2COLOR(r2/2, g2/2, b2/2);
}
/**
* rgb2color_24bpp:
* convert rgb to 24bpp color (see macros)
**/
unsigned int rgb2color_24bpp(unsigned int r, unsigned int g, unsigned int b)
{
return RGB2COLOR(r, g, b);
}
/**
* convert_color:
* convert raw color to 24bpp color (see macros)
**/
static INLINE unsigned int convert_color(unsigned int colour)
{
pixel.colour = colour;
......@@ -75,6 +89,10 @@ static INLINE unsigned int convert_color(unsigned int colour)
);
}
/**
* draw_pixel_24bpp:
* simple method to emulate a transparency
**/
void draw_pixel_24bpp(unsigned int * dest, const unsigned int * img)
{
if (*(img) != PIXEL_TRANSPARENT)
......@@ -83,6 +101,10 @@ void draw_pixel_24bpp(unsigned int * dest, const unsigned int * img)
}
}
/**
* convert_image_24bpp:
* convert raw image to 24bpp, used on init
**/
void convert_image_24bpp(unsigned int * dest, const unsigned int * img, int size)
{
while (size--)
......@@ -94,12 +116,20 @@ void convert_image_24bpp(unsigned int * dest, const unsigned int * img, int size
}
}
/**
* draw_line_24bpp:
* copy a 24bpp color to your dest
**/
void draw_line_24bpp(unsigned int * dest, int width, unsigned int color)
{
while (width--)
*(dest++) = color;
}
/**
* draw_char_24bpp:
* draw a 24bpp char to your dest
**/
void draw_char_24bpp(unsigned int * buffer_ptr, const unsigned char *font_data, unsigned int color)
{
int height = FNT_CHAR_HEIGHT;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment