Skip to content

Commit 8f7604a

Browse files
committed
Blank white screen works in VGA graphics
1 parent e640aa5 commit 8f7604a

File tree

8 files changed

+52
-18
lines changed

8 files changed

+52
-18
lines changed

.gdbinit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ define view_realmode
7272
end
7373

7474
define view_kernelmode
75-
set $CS_BASE = 0x10000
76-
set $DS_BASE = 0x10000
77-
set $SS_BASE = 0x10000
75+
set $CS_BASE = 0x0C000
76+
set $DS_BASE = 0x0C000
77+
set $SS_BASE = 0x0C000
7878
symbol-file build/kernel/core.elf
7979
clayout
8080
end

include/fuzzy/drivers/display/vga/graphics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
#include <stddef.h>
44

5-
int graphics_switchto_320x200x256();
5+
int graphics_set_mode(uint8_t video_mode);
6+
uint8_t graphics_get_mode();
7+
68
int graphics_write_320x200x256(int user_ds, uint8_t *__us_buffer);

include/fuzzy/memmgr/layout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
// START_ENSURE_SAME_layout_asm
4-
#define MEMORY_APP_SIZE 0x20000
4+
#define MEMORY_APP_SIZE 0x200000
55
#define STACKINIT_APP (MEMORY_APP_SIZE-4)
66
#define MEMORY_REALLIBRARY_DATA_ADDRESS 0x70000
77
#define MEMORY_REALLIBRARY_DATA_SIZE 0x10000

src/drivers/display/text_mode_vga.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ void io_low_scroll_screen(char count, unsigned char color,
8888
void io_low_put_char(char c, unsigned char color) {
8989
_low_put_char(c,color, location_xy);
9090
buffer[location_xy]=(((unsigned short)color)<<8)|c;
91-
// slows down char printing but good enough for now.
92-
io_low_flush();
9391
}
9492

9593
void io_low_flush() {

src/drivers/display/vga/graphics.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,32 @@
66

77
#include <stddef.h>
88

9-
int graphics_switchto_320x200x256() {
10-
uint8_t video_mode_flag = 0x13; // 320x200x256
11-
real_mode_client(
9+
int graphics_set_mode(uint8_t video_mode) {
10+
// https://en.wikipedia.org/wiki/INT_10H
11+
int eax = real_mode_client(
1212
0x10, // interrupt number
13-
(0x00<<8) | video_mode_flag,
13+
(0x00<<8) | video_mode, // set video mode
1414
0, // do not care
1515
0, // do not care
1616
0, // do not care
1717
0 // do not care
1818
);
1919
return 0;
20-
}
20+
}
21+
22+
uint8_t graphics_get_mode() {
23+
// https://en.wikipedia.org/wiki/INT_10H
24+
int eax = real_mode_client(
25+
0x10, // interrupt number
26+
(0x0F<<8), // get video mode
27+
0, // do not care
28+
0, // do not care
29+
0, // do not care
30+
0 // do not care
31+
);
32+
// active page ignored
33+
return eax&0xFF;
34+
}
2135

2236
int graphics_write_320x200x256(int user_ds, uint8_t *__us_buffer) {
2337
const int size = 320*200*1;

src/kernel/syscall/graphics.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
#include <fuzzy/kernel/syscall/graphics.h>
22
#include <fuzzy/drivers/display/vga/graphics.h>
3-
3+
#include <fuzzy/memmgr/tables/gdt.h>
44
#include <graphics.h>
55

6+
static int _graphics_prev_mode = -1;
7+
8+
69
static int _graphics_init() {
7-
// switch to 320x200x256 mode
8-
return graphics_switchto_320x200x256();
10+
if(_graphics_prev_mode!=-1) {
11+
// already in graphics mode
12+
return -1;
13+
}
14+
_graphics_prev_mode = graphics_get_mode();
15+
int err = graphics_set_mode(GRAPHIC_MODE_320x200x16);
16+
return err;
917
}
1018

1119
static int _graphics_close() {
12-
return 0;
20+
if(_graphics_prev_mode==-1) {
21+
// not in graphics mode
22+
return -1;
23+
}
24+
int err = graphics_set_mode(_graphics_prev_mode);
25+
// flush text screen
26+
flush_screen();
27+
_graphics_prev_mode = -1;
28+
return err;
1329
}
1430

1531
static int _graphics_copybuffer(int user_ds, void *_us_buffer) {
32+
uint8_t ARR[10][10];
33+
for(int i=0;i<10;i++)for(int j=0;j<10;j++) {
34+
ARR[i][j] = WHITE;
35+
}
1636
return graphics_write_320x200x256(user_ds, _us_buffer);
1737
}
1838

src/usr/include/graphics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define DETECT 0
77
#define GRAPHIC_DRIVER_VGA 1
88

9-
#define GRAPHIC_MODE_320x200x16 1
9+
#define GRAPHIC_MODE_320x200x16 0x13
1010

1111
#define BLACK 0x0
1212
#define BLUE 0x1

src/usr/lib/graphics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int getcolor() {
6464
}
6565

6666
void setbkcolor(int color) {
67-
// TODO
67+
gstate.bkcolor = color;
6868
}
6969

7070
int getbkcolor() {

0 commit comments

Comments
 (0)