summary refs log tree commit diff stats
path: root/README.org
blob: a83f8f095956bd7ba731079d86e1e1ae2fe6deb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#+HTML_HEAD: <link rel="stylesheet" href="../../static/style.css">
#+HTML_HEAD: <link rel="icon" href="../../static/projects/cetus/favicon.png" type="image/png">
#+EXPORT_FILE_NAME: index
#+TITLE: Cetus

Cetus is a simple wallpaper management tool written in Go. It supports multiple
sources for fetching the background.

| Project Home | [[https://andinus.nand.sh/projects/cetus/][Cetus]]           |
| Source Code  | [[https://framagit.org/andinus/cetus][Andinus / Cetus]] |

*Note*: Cetus is a work in-progress & many features are yet to be implemented.

*Dependency*: [[https://feh.finalrewind.org/][feh]]

* NASA Astronomy Picture of the Day
cetus-nasa uses NASA's API to get the Astronomy Picture of the Day.
** Features
- set APOD as background
- fetch information on APOD
- choose custom date
- choose date randomly
** Examples
#+BEGIN_SRC sh
# set currently APOD as background
cetus-nasa

# set date randomly
cetus-nasa -random

# set 2020-01-05 APOD as background
cetus-nasa -date 2020-01-05

# change api endpoint & api key
cetus-nasa -api https://api.nasa.gov/planetary/apod \
           -api-key DEMO_KEY

# don't set background, just fetch information
cetus-nasa -fetch-only

# don't output anything
cetus-nasa -quiet

# don't set background, just fetch & don't output anything
cetus-nasa -quiet -fetch-only # why would anyone do this?
#+END_SRC
* Demo
I just run some cetus commands on my computer, nothing fancy. I'll make better
demo videos someday.

*Note*: Cetus was restructured multiple times & these demos may not work on the
latest release.

| Version | Video                                                                |
|---------+----------------------------------------------------------------------|
| v0.3.1  | https://diode.zone/videos/watch/0808c512-315a-4dab-9526-4a537e8c3257 |
| v0.2.0  | https://diode.zone/videos/watch/12db31e1-3517-4888-ad06-55f3859447a1 |
* Installation
** Binary
framagit.org compiles cetus for OpenBSD & GNU/Linux amd64 on every release, to
get the binary goto [[https://framagit.org/andinus/cetus/pipelines?scope=tags&page=1][Pipelines - tags]].

To get the latest binary goto [[https://framagit.org/andinus/cetus/pipelines][Pipelines]].

** From Source
#+BEGIN_SRC sh
# get master branch archive
curl -o cetus-master.tar.gz \
     https://framagit.org/andinus/cetus/-/archive/master/cetus-master.tar.gz

# extract the archive
tar -xzf cetus-master.tar.gz

# install cetus
cd cetus-master && \
    go install ./cmd/cetus-nasa
#+END_SRC
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;
        }
    }
}