Skip to content

Commit 81c11bd

Browse files
committed
backported fixes from 256boss
1 parent 7dcd507 commit 81c11bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1631
-225
lines changed

src/boot.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef BOOT_H_
2+
#define BOOT_H_
3+
4+
extern unsigned char low_mem_buffer[];
5+
extern int boot_drive_number;
6+
7+
#endif /* BOOT_H_ */

src/boot/boot.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pcboot - bootable PC demo/game kernel
2-
# Copyright (C) 2018-2019 John Tsiombikas <[email protected]>
2+
# Copyright (C) 2018 John Tsiombikas <[email protected]>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by

src/boot/boot2.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# pcboot - bootable PC demo/game kernel
2-
# Copyright (C) 2018-2019 John Tsiombikas <[email protected]>
1+
# 256boss - bootable launcher for 256byte intros
2+
# Copyright (C) 2018 John Tsiombikas <[email protected]>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by

src/contty.c

Lines changed: 92 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
4040
#define CRTC_REG_CURLOC_L 0x0f
4141

4242
#define VMEM_CHAR(c, attr) \
43-
((uint16_t)(c) | ((uint16_t)(attr) << 8))
43+
(((uint16_t)(c) & 0xff) | ((uint16_t)(attr) << 8))
4444

4545
static void scroll(void);
4646
static void crtc_cursor(int x, int y);
4747
static void crtc_setstart(int y);
4848
static inline unsigned char crtc_read(int reg);
4949
static inline void crtc_write(int reg, unsigned char val);
50-
static inline void crtc_write_bits(int reg, unsigned char val, unsigned char mask);
5150

5251
extern int cursor_x, cursor_y;
5352
static unsigned char txattr = 0x07;
5453
static int start_line;
54+
static unsigned char cy0, cy1;
55+
static int curvis;
56+
static int scr_on = 1;
5557

5658
int con_init(void)
5759
{
@@ -60,26 +62,39 @@ int con_init(void)
6062
#endif
6163

6264
#ifdef CON_TEXTMODE
65+
cy0 = crtc_read(CRTC_REG_CURSTART);
66+
curvis = cy0 & 0x20 ? 1 : 0;
67+
cy0 &= 0x1f;
68+
cy1 = crtc_read(CRTC_REG_CUREND) & 0x1f;
69+
6370
con_show_cursor(1);
6471
crtc_setstart(0);
6572
crtc_cursor(cursor_x, cursor_y);
66-
/*
67-
printf("curloc: %x %x\n", (unsigned int)crtc_read(CRTC_REG_CURLOC_H),
68-
(unsigned int)crtc_read(CRTC_REG_CURLOC_L));
69-
printf("curstart: %x\n", (unsigned int)crtc_read(CRTC_REG_CURSTART));
70-
printf("curend: %x\n", (unsigned int)crtc_read(CRTC_REG_CUREND));
71-
*/
73+
scr_on = 1;
7274
#endif
7375

7476
return 0;
7577
}
7678

79+
void con_scr_enable(void)
80+
{
81+
scr_on = 1;
82+
}
83+
84+
void con_scr_disable(void)
85+
{
86+
scr_on = 0;
87+
}
88+
7789
void con_show_cursor(int show)
7890
{
7991
#ifdef CON_TEXTMODE
80-
unsigned char val = show ? 0 : 0x20;
81-
82-
crtc_write_bits(CRTC_REG_CURSTART, val, 0x20);
92+
unsigned char val = cy0 & 0x1f;
93+
if(!show) {
94+
val |= 0x20;
95+
}
96+
crtc_write(CRTC_REG_CURSTART, val);
97+
curvis = show;
8398
#endif
8499
}
85100

@@ -92,6 +107,23 @@ void con_cursor(int x, int y)
92107
#endif
93108
}
94109

110+
void con_curattr(int shape, int blink)
111+
{
112+
#ifdef CON_TEXTMODE
113+
unsigned char start;
114+
cy0 = (shape == CON_CURSOR_LINE) ? 0xd : 0;
115+
cy1 = 0xe;
116+
117+
start = cy0;
118+
if(curvis) {
119+
start |= 0x20;
120+
}
121+
122+
crtc_write(CRTC_REG_CURSTART, start);
123+
crtc_write(CRTC_REG_CUREND, cy0);
124+
#endif
125+
}
126+
95127
void con_fgcolor(int c)
96128
{
97129
txattr = (txattr & 0xf0) | c;
@@ -102,10 +134,20 @@ void con_bgcolor(int c)
102134
txattr = (txattr & 0x0f) | (c << 4);
103135
}
104136

137+
void con_setattr(unsigned char attr)
138+
{
139+
txattr = attr;
140+
}
141+
142+
unsigned char con_getattr(void)
143+
{
144+
return txattr;
145+
}
146+
105147
void con_clear(void)
106148
{
107149
#ifdef CON_TEXTMODE
108-
memset(TEXT_ADDR, 0, NCOLS * NROWS * 2);
150+
memset16(TEXT_ADDR, VMEM_CHAR(' ', txattr), NCOLS * NROWS);
109151

110152
start_line = 0;
111153
crtc_setstart(0);
@@ -126,33 +168,39 @@ static inline void linefeed(void)
126168
void con_putchar(int c)
127169
{
128170
#ifdef CON_TEXTMODE
129-
uint16_t *ptr;
130-
131-
switch(c) {
132-
case '\n':
133-
linefeed();
134-
case '\r':
135-
cursor_x = 0;
136-
crtc_cursor(cursor_x, cursor_y);
137-
break;
138-
139-
case '\t':
140-
cursor_x = (cursor_x & 0x7) + 8;
141-
if(cursor_x >= NCOLS) {
142-
linefeed();
143-
cursor_x = 0;
144-
}
145-
crtc_cursor(cursor_x, cursor_y);
146-
break;
147-
148-
default:
149-
con_putchar_scr(cursor_x, cursor_y, c);
150-
151-
if(++cursor_x >= NCOLS) {
171+
if(scr_on) {
172+
switch(c) {
173+
case '\n':
152174
linefeed();
175+
case '\r':
153176
cursor_x = 0;
177+
crtc_cursor(cursor_x, cursor_y);
178+
break;
179+
180+
case '\t':
181+
cursor_x = (cursor_x & 0x7) + 8;
182+
if(cursor_x >= NCOLS) {
183+
linefeed();
184+
cursor_x = 0;
185+
}
186+
crtc_cursor(cursor_x, cursor_y);
187+
break;
188+
189+
case '\b':
190+
if(cursor_x > 0) cursor_x--;
191+
con_putchar_scr(cursor_x, cursor_y, ' ');
192+
crtc_cursor(cursor_x, cursor_y);
193+
break;
194+
195+
default:
196+
con_putchar_scr(cursor_x, cursor_y, c);
197+
198+
if(++cursor_x >= NCOLS) {
199+
linefeed();
200+
cursor_x = 0;
201+
}
202+
crtc_cursor(cursor_x, cursor_y);
154203
}
155-
crtc_cursor(cursor_x, cursor_y);
156204
}
157205
#endif
158206

@@ -163,12 +211,15 @@ void con_putchar(int c)
163211

164212
void con_putchar_scr(int x, int y, int c)
165213
{
214+
#ifdef CON_TEXTMODE
166215
uint16_t *ptr = (uint16_t*)TEXT_ADDR;
167216
ptr[(y + start_line) * NCOLS + x] = VMEM_CHAR(c, txattr);
217+
#endif
168218
}
169219

170-
void con_printf(int x, int y, const char *fmt, ...)
220+
int con_printf(int x, int y, const char *fmt, ...)
171221
{
222+
#ifdef CON_TEXTMODE
172223
va_list ap;
173224
char buf[81];
174225
char *ptr = buf;
@@ -180,6 +231,10 @@ void con_printf(int x, int y, const char *fmt, ...)
180231
while(*ptr && x < 80) {
181232
con_putchar_scr(x++, y, *ptr++);
182233
}
234+
return ptr - buf;
235+
#else
236+
return 0;
237+
#endif
183238
}
184239

185240
static void scroll(void)
@@ -229,12 +284,3 @@ static inline void crtc_write(int reg, unsigned char val)
229284
outb(reg, CRTC_ADDR);
230285
outb(val, CRTC_DATA);
231286
}
232-
233-
static inline void crtc_write_bits(int reg, unsigned char val, unsigned char mask)
234-
{
235-
unsigned char prev;
236-
outb(reg, CRTC_ADDR);
237-
prev = inb(CRTC_DATA);
238-
val = (prev & ~mask) | (val & mask);
239-
outb(val, CRTC_DATA);
240-
}

src/contty.h

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,70 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
#ifndef CONTTY_H_
1919
#define CONTTY_H_
2020

21+
enum {
22+
CON_CURSOR_LINE,
23+
CON_CURSOR_BLOCK
24+
};
25+
26+
enum {
27+
BLACK,
28+
BLUE,
29+
GREEN,
30+
CYAN,
31+
RED,
32+
MAGENTA,
33+
BROWN,
34+
LTGREY,
35+
GREY,
36+
LTBLUE,
37+
LTGREEN,
38+
LTCYAN,
39+
LTRED,
40+
LTMAGENTA,
41+
YELLOW,
42+
WHITE
43+
};
44+
#define BRIGHT 8
45+
#define FG_BRIGHT 0x08
46+
#define BG_BRIGHT 0x80
47+
48+
enum {
49+
G_DIAMOND = 0x04,
50+
G_CHECKER = 0xb1,
51+
G_LR_CORNER = 0xd9,
52+
G_UR_CORNER = 0xbf,
53+
G_UL_CORNER = 0xda,
54+
G_LL_CORNER = 0xc0,
55+
G_CROSS = 0xc5,
56+
G_HLINE = 0xc4,
57+
G_L_TEE = 0xc3,
58+
G_R_TEE = 0xb4,
59+
G_B_TEE = 0xc1,
60+
G_T_TEE = 0xc2,
61+
G_VLINE = 0xb3,
62+
G_CDOT = 0xf8,
63+
64+
G_HDBL = 0xcd,
65+
G_UL_HDBL = 0xd5,
66+
G_UR_HDBL = 0xb8,
67+
G_T_HDBL_TEE = 0xd1
68+
};
69+
70+
2171
int con_init(void);
72+
void con_scr_enable(void);
73+
void con_scr_disable(void);
2274
void con_show_cursor(int show);
2375
void con_cursor(int x, int y);
76+
void con_curattr(int shape, int blink);
2477
void con_fgcolor(int c);
2578
void con_bgcolor(int c);
79+
void con_setattr(unsigned char attr);
80+
unsigned char con_getattr(void);
2681
void con_clear(void);
2782
void con_putchar(int c);
2883

2984
void con_putchar_scr(int x, int y, int c);
30-
void con_printf(int x, int y, const char *fmt, ...);
85+
int con_printf(int x, int y, const char *fmt, ...);
3186

3287
#endif /* CONTTY_H_ */

src/intr.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818
#include <stdio.h>
19+
#include "config.h"
1920
#include "intr.h"
2021
#include "desc.h"
2122
#include "segm.h"
@@ -150,13 +151,18 @@ void dispatch_intr(struct intr_frame frm)
150151
}
151152

152153
void init_pic(void)
154+
{
155+
prog_pic(IRQ_OFFSET);
156+
}
157+
158+
void prog_pic(int offs)
153159
{
154160
/* send ICW1 saying we'll follow with ICW4 later on */
155161
outb(ICW1_INIT | ICW1_ICW4_NEEDED, PIC1_CMD);
156162
outb(ICW1_INIT | ICW1_ICW4_NEEDED, PIC2_CMD);
157163
/* send ICW2 with IRQ remapping */
158-
outb(IRQ_OFFSET, PIC1_DATA);
159-
outb(IRQ_OFFSET + 8, PIC2_DATA);
164+
outb(offs, PIC1_DATA);
165+
outb(offs + 8, PIC2_DATA);
160166
/* send ICW3 to setup the master/slave relationship */
161167
/* ... set bit3 = 3rd interrupt input has a slave */
162168
outb(4, PIC1_DATA);
@@ -257,3 +263,10 @@ void end_of_irq(int irq)
257263

258264
set_intr_flag(intr_state);
259265
}
266+
267+
#ifdef ENABLE_GDB_STUB
268+
void exceptionHandler(int id, void (*func)())
269+
{
270+
set_intr_entry(id, func);
271+
}
272+
#endif

src/intr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void interrupt(int intr_num, intr_func_t func);
7272
*/
7373
void set_intr_entry(int num, void (*handler)(void));
7474

75+
void prog_pic(int offs);
7576
void set_pic_mask(int pic, unsigned char mask);
7677
unsigned char get_pic_mask(int pic);
7778
void mask_irq(int irq);

src/kbregs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2727

2828
#define KB_ACK 0xfa
2929
#define KB_NACK 0xfe
30+
#define KB_TEST_PASSED 0x55
31+
#define KB_TEST_FAILED 0xfc
3032

3133
#define KB_STAT_OUTBUF_FULL 0x01
3234
#define KB_STAT_INBUF_FULL 0x02
@@ -37,6 +39,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
3739
#define KB_STAT_TIMEOUT 0x40
3840
#define KB_STAT_PAR_ERROR 0x80
3941

42+
#define KB_CMD_TEST 0xaa
43+
4044
/* keyboard commands */
4145
#define KB_CMD_GET_CMDBYTE 0x20
4246
#define KB_CMD_SET_CMDBYTE 0x60

0 commit comments

Comments
 (0)