Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MachinimaBIOS minimalistic GPU driver
- #include "gpudriver.h"
- #include "minihal.h"
- unsigned char gpuSlot = 0;
- unsigned char currentLine;
- unsigned char currentColumn;
- unsigned char scrollLine;
- int gpu_init(unsigned char slot) {
- unsigned char deviceID;
- if (slot == 0) {
- return GPURESULT_INVALID_SLOT;
- }
- deviceID = readIO(slot, GPUDRV_IOADR_HWID);
- if (deviceID != GPUDRV_DEVICE_ID) {
- return GPURESULT_INVALID_SLOT;
- }
- gpuSlot = slot;
- gpu_cls();
- return GPURESULT_OK;
- }
- int gpu_cls() {
- unsigned char line;
- if (gpuSlot == 0) {
- return GPURESULT_NOT_INITIALIZED;
- }
- gpu_setCursor(0, 0);
- gpu_scroll(0);
- for (line = 0; line < 60; line++) {
- gpu_clearline(line);
- }
- return GPURESULT_OK;
- }
- int gpu_clearline(unsigned char line) {
- unsigned char column;
- if (gpuSlot == 0) {
- return GPURESULT_NOT_INITIALIZED;
- }
- writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, line);
- for (column = 0; column < 80; column++) {
- writeIO(gpuSlot, GPUDRV_IOADR_DATA + column, 0);
- }
- return GPURESULT_OK;
- }
- unsigned char gpu_getLine() {
- return currentLine;
- }
- unsigned char gpu_getColumn() {
- return currentColumn;
- }
- unsigned char gpu_getWidth() {
- return 80;
- }
- unsigned char gpu_getHeight() {
- return 60;
- }
- int gpu_setCursor(unsigned char line, unsigned char column) {
- if (gpuSlot == 0) {
- return GPURESULT_NOT_INITIALIZED;
- }
- currentLine = line;
- currentColumn = column;
- return GPURESULT_OK;
- }
- int gpu_scroll(unsigned char line) {
- if (gpuSlot == 0) {
- return GPURESULT_NOT_INITIALIZED;
- }
- scrollLine = line;
- writeIO(gpuSlot, GPUDRV_IOADR_SCROLL, scrollLine);
- return GPURESULT_OK;
- }
- int gpu_print(char* text) {
- unsigned int i;
- unsigned char cont;
- if (gpuSlot == 0) {
- return GPURESULT_NOT_INITIALIZED;
- }
- i = 0;
- cont = 1;
- writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, currentLine);
- while (cont) {
- if ((text[i] == 13) | (currentColumn >= 80)) {
- currentLine++;
- currentColumn = 0;
- gpu_clearline(currentLine);
- writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, currentLine);
- }
- if ((text[i] != 0) & (text[i] != 13)) {
- writeIO(gpuSlot, GPUDRV_IOADR_DATA + currentColumn, text[i]);
- currentColumn++;
- }
- if (text[i] == 0) {
- cont = 0;
- }
- i++;
- }
- if ((currentLine - scrollLine) >= 60) {
- gpu_scroll(currentLine - 59);
- }
- return GPURESULT_OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment