aboutsummaryrefslogtreecommitdiff
path: root/src/parisc/sti.c
blob: 1bba98973bc37f4c3f8864563bf83268e34312ee (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* STI console code
 *
 * Copyright (C) 2019 Sven Schnelle <svens@stackframe.org>
 *
 * This file may be distributed under the terms of the GNU LGPLv3 license.
 */

#include "autoconf.h"
#include "types.h"
#include "std/optionrom.h"
#include "vgahw.h"
#include "parisc/sticore.h"
#include "parisc/hppa_hardware.h"
#include "output.h"
#include "pdc.h"
#include "hppa.h"

static int sti_enabled;

static struct sti_init_flags sti_init_flags = {
        .wait = 1,
        .reset = 1,
        .text = 1,
        .nontext = 1,
        .cmap_blk = 1,
        .no_chg_bet = 1,
        .no_chg_bei = 1,
        .init_cmap_tx = 1,
        .clear = 1,
};

static struct sti_glob_cfg_ext sti_glob_ext_cfg = {
};

static struct sti_glob_cfg sti_glob_cfg = {
        .region_ptrs = { 0, ARTIST_FB_ADDR, 0xf8100000, 0xf8380000, 0, 0, 0, 0 },
};

static struct sti_init_inptr_ext sti_init_inptr_ext = {
        .config_mon_type = 1,
};

static struct sti_init_inptr sti_init_inptr = {
        .text_planes = 3,
};

static struct sti_init_outptr sti_init_outptr = {
};

static struct sti_font_flags sti_font_flags = {
        .wait = 1,
};

static struct sti_font_inptr sti_font_inptr = {
        .fg_color = 1,
        .bg_color = 0,
};

static struct sti_font_outptr sti_font_outptr = {
};

static struct sti_blkmv_flags sti_blkmv_flags = {
        .wait = 1,
};

static struct sti_blkmv_inptr sti_blkmv_inptr = {
};

static struct sti_blkmv_outptr sti_blkmv_outptr = {
};

static void sti_putchar(struct sti_rom *rom, int row, int column, const char c)
{
    int (*sti_unpmv)(struct sti_font_flags *,
                     struct sti_font_inptr *,
                     struct sti_font_outptr *,
                     struct sti_glob_cfg *);

    struct sti_rom_font *font = (void *)rom + rom->font_start;
    sti_unpmv = (void *)rom + rom->font_unpmv;

    sti_font_inptr.dest_x = column * font->width;
    sti_font_inptr.dest_y = row * font->height;
    sti_font_inptr.index = c;
    sti_font_inptr.font_start_addr = (u32) font;

    sti_unpmv(&sti_font_flags, &sti_font_inptr,
        &sti_font_outptr, &sti_glob_cfg);
}

static void sti_block_move(struct sti_rom *rom, int src_x, int src_y,
                                          int dest_x, int dest_y,
                                          int width, int height,
                                          int clear)
{
    int (*sti_block_move)(struct sti_blkmv_flags *,
                          struct sti_blkmv_inptr *,
                          struct sti_blkmv_outptr *,
                          struct sti_glob_cfg *);
    sti_block_move = (void *)rom + rom->block_move;

    sti_blkmv_inptr.src_x = src_x;
    sti_blkmv_inptr.src_y = src_y;
    sti_blkmv_inptr.dest_x = dest_x;
    sti_blkmv_inptr.dest_y = dest_y;
    sti_blkmv_inptr.width = width;
    sti_blkmv_inptr.height = height;
    sti_blkmv_flags.clear = clear;

    sti_block_move(&sti_blkmv_flags, &sti_blkmv_inptr,
                   &sti_blkmv_outptr, &sti_glob_cfg);
}

void sti_console_init(struct sti_rom *rom)
{
    int (*sti_init)(struct sti_init_flags *,
                    struct sti_init_inptr *,
                    struct sti_init_outptr *,
                    struct sti_glob_cfg *);

    sti_init = (void *)rom + rom->init_graph;
    sti_glob_cfg.ext_ptr = (u32)&sti_glob_ext_cfg;
    sti_init_inptr.ext_ptr = (u32)&sti_init_inptr_ext;

    sti_init(&sti_init_flags, &sti_init_inptr,
             &sti_init_outptr, &sti_glob_cfg);

    sti_enabled = 1;
}

void sti_putc(const char c)
{
    struct sti_rom *rom = (struct sti_rom *) ROM_EXTEND(PAGE0->proc_sti);
    struct sti_rom_font *font = (void *)rom + rom->font_start;
    static int row, col;

    if (!sti_enabled)
        return;

    if (c == '\r') {
        col = 0;
        return;
    }

    if (c == 0x08) {
        if (col > 0)
            col--;
        return;
    }

    if (c == '\n') {
        col = 0;
        row++;

        if (row >= sti_glob_cfg.onscreen_y / font->height) {
            sti_block_move(rom,
                    0, font->height,
                    0, 0,
                    sti_glob_cfg.total_x, sti_glob_cfg.onscreen_y - font->height, 0);

            /* clear new line at bottom */
            sti_block_move(rom,
                    0, 0, /* source */
                    0, sti_glob_cfg.onscreen_y - font->height, /* dest */
                    sti_glob_cfg.onscreen_x, font->height,
                    1);

            row = (sti_glob_cfg.onscreen_y / font->height)-1;
        }
        return;
    }

    /* wrap to next line or scroll screen if EOL reached */
    if (col >= ((sti_glob_cfg.onscreen_x / font->width) - 1))
	sti_putc('\n');

    sti_putchar(rom, row, col++, c);
}