This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made cursor support and window support!
- Loading branch information
1 parent
b458b90
commit caf9f82
Showing
13 changed files
with
258 additions
and
64 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdlib.h> | ||
|
||
static unsigned long int next = 1; | ||
|
||
int rand(void) { | ||
next = next * 1103515245 + 12345; | ||
return (unsigned int)(next / 65536) % 32768; | ||
} | ||
|
||
void srand(unsigned int seed) { next = seed; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include "windows.h" | ||
|
||
window_t windows[MAX_WINDOWS]; | ||
int num_windows = 0; | ||
|
||
void spawn_window(window_t *window) { | ||
if (num_windows < MAX_WINDOWS) { | ||
window->buffer = malloc(window->width * window->height * sizeof(uint32_t)); | ||
window->old_buffer = | ||
malloc(window->width * window->height * sizeof(uint32_t)); | ||
if (window->buffer == NULL || window->old_buffer == NULL) { | ||
dprintf("Failed to allocate memory for window buffer\n"); | ||
return; | ||
} | ||
|
||
memset(window->buffer, 0xFFFFFFFF, | ||
window->width * window->height * sizeof(uint32_t)); | ||
memcpy(window->old_buffer, window->buffer, | ||
window->width * window->height * sizeof(uint32_t)); | ||
|
||
int i, j; | ||
uint32_t pixel; | ||
|
||
for (i = 0; i < window->height; i++) { | ||
for (j = 0; j < window->width; j++) { | ||
pixel = window->buffer[i * window->width + j]; | ||
uint8_t alpha = (pixel & ALPHA_MASK) >> ALPHA_SHIFT; | ||
uint8_t red = (pixel & RED_MASK) >> RED_SHIFT; | ||
uint8_t green = (pixel & GREEN_MASK) >> GREEN_SHIFT; | ||
uint8_t blue = (pixel & BLUE_MASK) >> BLUE_SHIFT; | ||
put_pixel_rgba(window->x + j, window->y + i, red, green, blue, alpha); | ||
} | ||
} | ||
|
||
char *img; | ||
uint32_t size; | ||
vfs_op_status status; | ||
|
||
status = driver_read(vfs, 0x00000000, DEFAULT_WIN_DEC, &img); | ||
if (status == STATUS_OK) { | ||
size = vfs_get_file_size(vfs, 0x00000000, DEFAULT_WIN_DEC); | ||
draw_tga_from_raw(window->x, window->y, img, size); | ||
} | ||
|
||
update_window(window); | ||
} else { | ||
dprintf("Maximum number of windows reached\n"); | ||
} | ||
} | ||
|
||
void update_window(window_t *window) { | ||
int i, j; | ||
uint32_t pixel; | ||
|
||
if (!window->initialized) { | ||
for (i = 0; i < window->height; i++) { | ||
for (j = 0; j < window->width; j++) { | ||
pixel = window->buffer[i * window->width + j]; | ||
uint8_t alpha = (pixel & ALPHA_MASK) >> ALPHA_SHIFT; | ||
uint8_t red = (pixel & RED_MASK) >> RED_SHIFT; | ||
uint8_t green = (pixel & GREEN_MASK) >> GREEN_SHIFT; | ||
uint8_t blue = (pixel & BLUE_MASK) >> BLUE_SHIFT; | ||
put_pixel_rgba(window->x + j, window->y + i, red, green, blue, alpha); | ||
} | ||
} | ||
|
||
char *img; | ||
uint32_t size; | ||
vfs_op_status status; | ||
|
||
status = driver_read(vfs, 0x00000000, DEFAULT_WIN_DEC, &img); | ||
if (status == STATUS_OK) { | ||
size = vfs_get_file_size(vfs, 0x00000000, DEFAULT_WIN_DEC); | ||
draw_tga_from_raw(window->x, window->y, img, size); | ||
} | ||
|
||
window->initialized = 1; | ||
} else { | ||
for (i = 0; i < window->height; i++) { | ||
for (j = 0; j < window->width; j++) { | ||
pixel = window->buffer[i * window->width + j]; | ||
uint8_t alpha = (pixel & ALPHA_MASK) >> ALPHA_SHIFT; | ||
uint8_t red = (pixel & RED_MASK) >> RED_SHIFT; | ||
uint8_t green = (pixel & GREEN_MASK) >> GREEN_SHIFT; | ||
uint8_t blue = (pixel & BLUE_MASK) >> BLUE_SHIFT; | ||
put_pixel_rgba(window->x + j, window->y + i, red, green, blue, alpha); | ||
} | ||
} | ||
|
||
char *img; | ||
uint32_t size; | ||
vfs_op_status status; | ||
|
||
status = driver_read(vfs, 0x00000000, DEFAULT_WIN_DEC, &img); | ||
if (status == STATUS_OK) { | ||
size = vfs_get_file_size(vfs, 0x00000000, DEFAULT_WIN_DEC); | ||
draw_tga_from_raw(window->x, window->y, img, size); | ||
} | ||
} | ||
} | ||
|
||
void update_all_windows() { | ||
for (int i = 0; i < num_windows; i++) { | ||
update_window(&windows[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef __WINDOWS_H__ | ||
#define __WINDOWS_H__ | ||
|
||
#include <filesystem/vfs.h> | ||
#include <kernel/boot.h> | ||
#include <math.h> | ||
#include <printf.h> | ||
#include <stdlib.h> | ||
#include <tga.h> | ||
#include <vga.h> | ||
|
||
#define MAX_WINDOWS 100 | ||
|
||
#define WIN_WIDTH 688 | ||
#define WIN_HEIGHT 417 | ||
|
||
#define ALPHA_MASK 0xFF000000 | ||
#define RED_MASK 0x00FF0000 | ||
#define GREEN_MASK 0x0000FF00 | ||
#define BLUE_MASK 0x000000FF | ||
|
||
#define ALPHA_SHIFT 24 | ||
#define RED_SHIFT 16 | ||
#define GREEN_SHIFT 8 | ||
#define BLUE_SHIFT 0 | ||
|
||
#define DEFAULT_WIN_DEC "/etc/graphics/window.tga" | ||
|
||
typedef struct { | ||
char *title; | ||
int x; | ||
int y; | ||
int width; | ||
int height; | ||
uint32_t *buffer; | ||
uint32_t *old_buffer; | ||
int initialized; | ||
} window_t; | ||
|
||
extern window_t windows[MAX_WINDOWS]; | ||
extern int num_windows; | ||
|
||
void spawn_window(window_t *window); | ||
void update_window(window_t *window); | ||
void update_all_windows(); | ||
#endif // __WINDOWS_H__ |
Oops, something went wrong.