sporniket / ideas

My backlog of ideas, organized as a bunch of issues
0 stars 0 forks source link

Mode texte bas niveau #1

Open sporniket opened 2 years ago

sporniket commented 2 years ago

Modèles

Grille

(nb lignes × nb colonnes) de cellules ( {glyphe, couleur, couleur fond})

using ColorIndex = uint8_t ;
using ColorIndexBackground = ColorIndex ;
using CellColors = uint8_t ;

struct CellColorsExpanded {
    ColorIndex color;
    ColorIndexBackground backgroundColor;
} ;

class CellColorsHelper {
    static CellColors fromColors(ColorIndex color, ColorIndexBackground backgroundColor) {
        return (CellColors)((backgroundColor & 0xf) << 4 + color & 0xf) ;
    }

    static CellColors fromCellColorsExpanded(CellColorsExpanded colors) {
        return fromColors(colors.color, colors.backgroundColor) ;
    }
} ;

class ColorIndexHelper {
    static ColorIndex fromCellColors(CellColors colors) { return colors & 0xf ; }
} ;

class ColorIndexBackgroundHelper {
    static ColorIndexBackground fromCellColors(CellColors colors) { return (colors >> 4) & 0xf ; }
} ;

using GlyphIndex = uint16_t ;
struct Cell {
    GlyphIndex glyph ;
    CellColors colors ;
} ;

Rendu graphique : glyphes

//Look-Up Table
class GlyphLut {
    public:
    GlyphIndex fromCharCode8(uint8_t) ;
    GlyphIndex fromCharCode16(uint16_t) ;
}

using GlyphMetricPx = uint8_t ;
class GlyphSet {
    GlyphMetricPx glyphWidthPx ;
    GlyphMetricPx glyphHeightPx ;
    uint16_t size; //-->glyph index = 0..(size-1)
    uint8_t* glyphData ; // = (glyphWidthPx+7)>>3 * glyphHeightPx * size
}

class GlyphSet {
    GlyphLut lut ;
    GlyphBitmap bitmap ;
}

Mode Texte direct

Désigne directement les cellules à modifier

enum ColorSupport {
    MONO=2, 
    LIMITED_COLORS=4, 
    FULL_COLORS=16
};

TextModeRam{
    private:
    // instance specs
    uint8_t gridWidth;
    uint8_t gridHeight;
    uint8_t gridSize; //number of cells
    ColorSupport colorSupport;
    Cell* screen; // = gridWidth * gridHeight

   Cell* getCell_unsafe(uint16_t address) {return screen[address];}

    public:
    TextModeRam(uint8_t gridWidth, uint8_t gridHeight, ColorSupport  colorSupport) ;
    virtual ~TextModeRam(); //-> libère la zone mémoire
    Cell* getCell(uint8_t column, uint8_t row) { return (column < gridWidth && row < gridHeight) ? getCell_unsafe(gridWidth*row + column) : nullptr ;)
    Cell* getCell(uint16_t address) { return (address < gridSize) ? getCell_unsafe(address) : nullptr ;}
}