vga.c 1.2 KB
Newer Older
Z
Zihao Yu 已提交
1 2 3 4
#include "common.h"

#ifdef HAS_IOE

5
#include "device/map.h"
Z
Zihao Yu 已提交
6 7 8 9
#include <SDL2/SDL.h>

#define VMEM 0x40000

10
#define SCREEN_PORT 0x100 // Note that this is not the standard
Z
Zihao Yu 已提交
11
#define SCREEN_MMIO 0x4100
Z
Zihao Yu 已提交
12 13 14 15 16 17 18 19
#define SCREEN_H 300
#define SCREEN_W 400

static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_Texture *texture;

static uint32_t (*vmem) [SCREEN_W];
20
static uint32_t *screensize_port_base;
Z
Zihao Yu 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

void update_screen() {
  SDL_UpdateTexture(texture, NULL, vmem, SCREEN_W * sizeof(vmem[0][0]));
  SDL_RenderClear(renderer);
  SDL_RenderCopy(renderer, texture, NULL, NULL);
  SDL_RenderPresent(renderer);
}

void init_vga() {
  SDL_Init(SDL_INIT_VIDEO);
  SDL_CreateWindowAndRenderer(SCREEN_W * 2, SCREEN_H * 2, 0, &window, &renderer);
  SDL_SetWindowTitle(window, "NEMU");
  texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
      SDL_TEXTUREACCESS_STATIC, SCREEN_W, SCREEN_H);

36
  screensize_port_base = (void *)new_space(4);
37
  *screensize_port_base = ((SCREEN_W) << 16) | (SCREEN_H);
38
  add_pio_map(SCREEN_PORT, (void *)screensize_port_base, 4, NULL);
Z
Zihao Yu 已提交
39
  add_mmio_map(SCREEN_MMIO, (void *)screensize_port_base, 4, NULL);
40 41 42

  vmem = (void *)new_space(0x80000);
  add_mmio_map(VMEM, (void *)vmem, 0x80000, NULL);
Z
Zihao Yu 已提交
43 44
}
#endif	/* HAS_IOE */