summaryrefslogtreecommitdiff
path: root/src/arch/amd64/drivers/bochs.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/arch/amd64/drivers/bochs.c (renamed from src/arch/amd64/fb.c)34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/arch/amd64/fb.c b/src/arch/amd64/drivers/bochs.c
index 8560166..5383213 100644
--- a/src/arch/amd64/fb.c
+++ b/src/arch/amd64/drivers/bochs.c
@@ -3,8 +3,9 @@
#include <stdint.h>
#include <panic.h>
#include <pci.h>
+#include <bochs.h>
-#include "bindings.h"
+#include "../bindings.h"
#define INDEX 0x1CE
#define DATA 0x1CF
@@ -52,38 +53,21 @@ static void set_mode(uint16_t width, uint16_t height, uint16_t bit_depth, int lf
(clear ? 0 : DATA_NO_CLEAR_MEM));
}
-//static void set_bank(uint16_t bank) {
-// write(INDEX_BANK, bank);
-//}
+uint32_t* bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth) {
-int fb_init(uint16_t width, uint16_t height) {
-
- set_mode(width, height, 32, true, true);
+ set_mode(width, height, bit_depth, true, true);
if (!is_available())
- panic("bochs framebuffer not avaliable");
+ return NULL;
struct pci_device bochs = {0};
bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL);
if (!found)
- panic("bochs pci device not avaliable");
+ return NULL;
uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D);
- uint32_t *fb = (uint32_t*) (uintptr_t) bar0;
- fb = mmap(fb, width * height * 4);
-
- for (uint16_t y = 0; y < height; y++) {
- for (uint16_t x = 0; x < width; x++) {
- double dx = x / (double) width,
- dy = y / (double) height,
- dz = (2 - dx - dy) / 2;
- uint32_t r = (uint32_t)(dx * 255),
- g = (uint32_t)(dy * 255),
- b = (uint32_t)(dz * 255);
- fb[x + y * width] = (b << 0) | (g << 8) | (r << 16);
- }
- }
-
+ uint32_t *addr = (uint32_t*) (uintptr_t) bar0;
+ addr = mmap(addr, width * height * bit_depth);
- return 0;
+ return addr;
}