about summary refs log tree commit diff stats
path: root/tangle.mu
Commit message (Expand)AuthorAgeFilesLines
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-031-1/+1
* 4002Kartik K. Agaram2017-09-231-13/+12
* 3483Kartik K. Agaram2016-10-081-1/+1
* 3380Kartik K. Agaram2016-09-171-5/+5
* 3302Kartik K. Agaram2016-09-071-1/+2
* 2746Kartik K. Agaram2016-03-091-1/+1
* 2735 - define recipes using 'def'Kartik K. Agaram2016-03-081-3/+3
* 2426Kartik K. Agaram2015-11-111-4/+3
* 2235Kartik K. Agaram2015-10-021-4/+4
* 1880 - switch .mu files to new type-deducing idiomKartik K. Agaram2015-07-291-6/+6
* 1868 - start using naked literals everywhereKartik K. Agaram2015-07-281-4/+4
* 1780 - now we always reclaim local scopesKartik K. Agaram2015-07-131-1/+1
* 1773 - update all mu recipes to new-default-spaceKartik K. Agaram2015-07-131-1/+1
* 1363 - rename 'integer' to 'number'Kartik K. Agaram2015-05-131-8/+8
* 1345Kartik K. Agaram2015-05-111-3/+6
* 1298 - better ingredient/product handlingKartik K. Agaram2015-05-071-3/+1
* 1278 - support before/after tangle directivesKartik K. Agaram2015-05-051-0/+36
* 1276 - make C++ version the defaultKartik K. Agaram2015-05-051-35/+0
* 690 - convention: '$' commands for debugging onlyKartik K. Agaram2015-02-011-2/+2
* 578 - switch to non-polymorphic 'print' functionsKartik K. Agaram2015-01-171-1/+1
* 574 - printing string literals is a hack; hard-code it in for nowKartik K. Agaram2015-01-161-2/+2
* 571 - screen primitives take an explicit terminalKartik K. Agaram2015-01-151-3/+3
* 497 - strengthen the concept of 'space'Kartik K. Agaram2015-01-021-1/+1
* 428 - cleanup odds and endsKartik K. Agaram2014-12-141-13/+13
* 403 - 'function' is more clear than 'def'Kartik K. Agaram2014-12-121-2/+2
* al.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "gfx.h"
#include "vmm.h"
#include "serial.h"
#include "framebuffer.h"
#include "debugprint.h"

static uint32 gWidth = 0;
static uint32 gHeight = 0;
static uint32 gBytesPerPixel = 0;
static uint32 gPitch = 0;
static uint32* gPixels = NULL;

extern char _binary_font_psf_start;
extern char _binary_font_psf_end;

uint16 *gUnicode = NULL;

static int gLineCount = 10;
static int gColumnCount = 10;
static uint16 gCurrentLine = 0;
static uint16 gCurrentColumn = 0;

#define LINE_HEIGHT 16

void Gfx_Initialize(uint32* pixels, uint32 width, uint32 height, uint32 bytesPerPixel, uint32 pitch) {
    char* p_address = (char*)pixels;
    char* v_address = (char*)GFX_MEMORY;

    //Usually physical and virtual are the same here but of course they don't have to

    gPixels = (uint32*)v_address;
    gWidth = width;
    gHeight = height;
    gBytesPerPixel = bytesPerPixel;
    gPitch = pitch;

    gLineCount = gHeight / LINE_HEIGHT;
    gColumnCount = gWidth / 8;


    BOOL success = addPageToPd(gKernelPageDirectory, v_address, p_address, 0);

    if (success) {
        for (int y = 0; y < gHeight; ++y) {
            for (int x = 0; x < gWidth; ++x) {
                gPixels[x + y * gWidth] = 0xFFFFFFFF;
            }
        }
    }
    else {
        Debug_PrintF("Gfx initialization failed!\n");
    }

    initializeFrameBuffer((uint8*)p_address, (uint8*)v_address);
}

#define PSF_FONT_MAGIC 0x864ab572

typedef struct {
    uint32 magic;         /* magic bytes to identify PSF */
    uint32 version;       /* zero */
    uint32 headersize;    /* offset of bitmaps in file, 32 */
    uint32 flags;         /* 0 if there's no unicode table */
    uint32 numglyph;      /* number of glyphs */
    uint32 bytesperglyph; /* size of each glyph */
    uint32 height;        /* height in pixels */
    uint32 width;         /* width in pixels */
} PSF_font;

//From Osdev PC Screen Font (The font used here is free to use)
void Gfx_PutCharAt(
    /* note that this is int, not char as it's a unicode character */
    unsigned short int c,
    /* cursor position on screen, in characters not in pixels */
    int cx, int cy,
    /* foreground and background colors, say 0xFFFFFF and 0x000000 */
    uint32 fg, uint32 bg) {
    /* cast the address to PSF header struct */
    PSF_font *font = (PSF_font*)&_binary_font_psf_start;
    /* we need to know how many bytes encode one row */
    int bytesperline=(font->width+7)/8;
    /* unicode translation */
    if(gUnicode != NULL) {
        c = gUnicode[c];
    }
    /* get the glyph for the character. If there's no
       glyph for a given character, we'll display the first glyph. */
    unsigned char *glyph =
     (unsigned char*)&_binary_font_psf_start +
     font->headersize +
     (c>0&&c<font->numglyph?c:0)*font->bytesperglyph;
    /* calculate the upper left corner on screen where we want to display.
       we only do this once, and adjust the offset later. This is faster. */
    int offs =
        (cy * font->height * gPitch) +
        (cx * (font->width+1) * 4);
    /* finally display pixels according to the bitmap */
    int x,y, line,mask;
    for(y=0;y<font->height;y++){
        /* save the starting position of the line */
        line=offs;
        mask=1<<(font->width-1);
        /* display a row */
        for(x=0;x<font->width;x++) {
            if (c == 0) {
                *((uint32*)((uint8*)gPixels + line)) = bg;
            }
            else {
                *((uint32*)((uint8*)gPixels + line)) = ((int)*glyph) & (mask) ? fg : bg;
            }

            /* adjust to the next pixel */
            mask >>= 1;
            line += 4;
        }
        /* adjust to the next line */
        glyph += bytesperline;
        offs  += gPitch;
    }
}

void Gfx_FlushFromTty(Tty* tty) {
    for (uint32 r = 0; r < tty->lineCount; ++r) {
        for (uint32 c = 0; c < tty->columnCount; ++c) {
            uint8* ttyPos = tty->buffer + (r * tty->columnCount + c) * 2;

            uint8 chr = ttyPos[0];
            uint8 color = ttyPos[1];

            Gfx_PutCharAt(chr, c, r, 0, 0xFFFFFFFF);
        }
    }

    //Screen_MoveCursor(tty->currentLine, tty->currentColumn);
}

uint8* Gfx_GetVideoMemory() {
    return (uint8*)gPixels;
}

uint16 Gfx_GetWidth() {
    return gWidth;
}

uint16 Gfx_GetHeight() {
    return gHeight;
}

uint16 Gfx_GetBytesPerPixel() {
    return gBytesPerPixel;
}

void Gfx_Fill(uint32 color) {
    for (uint32 y = 0; y < gHeight; ++y) {
        for (uint32 x = 0; x < gWidth; ++x) {
            gPixels[x + y * gWidth] = color;
        }
    }
}