Skip to content

Commit 2fac871

Browse files
committed
finish VGA
1 parent b1c7254 commit 2fac871

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

abstract-machine/am/src/platform/nemu/ioe/gpu.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
11
#include <am.h>
22
#include <nemu.h>
3+
#include <string.h>
4+
#include <stdio.h>
35

46
#define SYNC_ADDR (VGACTL_ADDR + 4)
57

8+
#define WMASK 0xffff0000
9+
#define HMASK 0x0000ffff
10+
11+
static int width = 0;
12+
static int height = 0;
13+
614
void __am_gpu_init() {
15+
uint32_t cfg = inl(VGACTL_ADDR);
16+
width = cfg & WMASK >> 16;
17+
height = cfg & HMASK;
18+
// uint32_t *fb = (uint32_t *)(uintptr_t)FB_ADDR;
19+
// for (int i = 0; i < width * height; i ++) fb[i] = i;
20+
21+
outl(SYNC_ADDR, 1);
722
}
823

924
void __am_gpu_config(AM_GPU_CONFIG_T *cfg) {
1025
*cfg = (AM_GPU_CONFIG_T) {
1126
.present = true, .has_accel = false,
12-
.width = 0, .height = 0,
27+
.width = width, .height = height,
1328
.vmemsz = 0
1429
};
1530
}
1631

1732
void __am_gpu_fbdraw(AM_GPU_FBDRAW_T *ctl) {
18-
if (ctl->sync) {
19-
outl(SYNC_ADDR, 1);
33+
int x = ctl->x, y = ctl->y, w = ctl->w, h = ctl->h;
34+
if (w == 0 || h == 0) return;
35+
36+
uint32_t *pixels = ctl->pixels;
37+
uint32_t *fb = (uint32_t *)(uintptr_t)FB_ADDR;
38+
uint32_t screen_w = inl(VGACTL_ADDR) >> 16;
39+
for (int i = y; i < y+h; i++) {
40+
for (int j = x; j < x+w; j++) {
41+
fb[screen_w*i+j] = pixels[w*(i-y)+(j-x)]; //缓冲区是一个像素块
42+
}
2043
}
44+
45+
if (ctl->sync) outl(SYNC_ADDR, 1);
46+
2147
}
2248

2349
void __am_gpu_status(AM_GPU_STATUS_T *status) {

abstract-machine/klib/src/stdio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ unsigned long m_pow_n(unsigned long m, unsigned long n)
2020
int printf(const char *fmt, ...) {
2121
va_list ap;
2222
va_start(ap, fmt);
23-
char out[4096];
23+
char out[409600];
2424
int length = vsprintf(out, fmt, ap);
2525
for (int i = 0; i < length; i++) {
2626
putch(out[i]);

am-kernels/kernels/demo/include/io.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef __DRAW_H__
22

3-
// #define HAS_GUI
3+
#define HAS_GUI
44

55
#include <stdio.h>
66
#include <am.h>

nemu/src/device/vga.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ static inline void update_screen() {
7272
#endif
7373

7474
void vga_update_screen() {
75-
// TODO: call `update_screen()` when the sync register is non-zero,
76-
// then zero out the sync register
75+
if (vgactl_port_base[1] != 0) update_screen();
7776
}
7877

7978
void init_vga() {

nemu/src/monitor/trace/iringbuf.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ int p_cur = 0;
1414
int p_error = 0;
1515
bool is_full = false;
1616

17+
#if defined(CONFIG_IRINGBUF_COND)
18+
1719
void iringbuf_inst(word_t pc, uint32_t inst) {
1820
iringbuf[p_cur].pc = pc;
1921
iringbuf[p_cur].inst = inst;
@@ -42,4 +44,4 @@ void display_iringbuf() {
4244

4345
}
4446

45-
47+
#endif

npc/sim/monitor/trace/iringbuf.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ int p_cur = 0;
1414
int p_error = 0;
1515
bool is_full = false;
1616

17+
#if defined(CONFIG_IRINGBUF_COND)
18+
1719
void iringbuf_inst(word_t pc, uint32_t inst) {
1820
iringbuf[p_cur].pc = pc;
1921
iringbuf[p_cur].inst = inst;
@@ -42,4 +44,4 @@ void display_iringbuf() {
4244

4345
}
4446

45-
47+
#endif

0 commit comments

Comments
 (0)