|
1 | 1 | #include <am.h>
|
2 | 2 | #include <nemu.h>
|
| 3 | +#include <string.h> |
| 4 | +#include <stdio.h> |
3 | 5 |
|
4 | 6 | #define SYNC_ADDR (VGACTL_ADDR + 4)
|
5 | 7 |
|
| 8 | +#define WMASK 0xffff0000 |
| 9 | +#define HMASK 0x0000ffff |
| 10 | + |
| 11 | +static int width = 0; |
| 12 | +static int height = 0; |
| 13 | + |
6 | 14 | 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); |
7 | 22 | }
|
8 | 23 |
|
9 | 24 | void __am_gpu_config(AM_GPU_CONFIG_T *cfg) {
|
10 | 25 | *cfg = (AM_GPU_CONFIG_T) {
|
11 | 26 | .present = true, .has_accel = false,
|
12 |
| - .width = 0, .height = 0, |
| 27 | + .width = width, .height = height, |
13 | 28 | .vmemsz = 0
|
14 | 29 | };
|
15 | 30 | }
|
16 | 31 |
|
17 | 32 | 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 | + } |
20 | 43 | }
|
| 44 | + |
| 45 | + if (ctl->sync) outl(SYNC_ADDR, 1); |
| 46 | + |
21 | 47 | }
|
22 | 48 |
|
23 | 49 | void __am_gpu_status(AM_GPU_STATUS_T *status) {
|
|
0 commit comments