Guest User

Untitled

a guest
Aug 27th, 2014
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. //MachinimaBIOS minimalistic GPU driver
  2. #include "gpudriver.h"
  3. #include "minihal.h"
  4.  
  5. unsigned char gpuSlot = 0;
  6. unsigned char currentLine;
  7. unsigned char currentColumn;
  8. unsigned char scrollLine;
  9.  
  10. int gpu_init(unsigned char slot) {
  11.     unsigned char deviceID;
  12.     if (slot == 0) {
  13.         return GPURESULT_INVALID_SLOT;
  14.     }
  15.    
  16.     deviceID = readIO(slot, GPUDRV_IOADR_HWID);
  17.     if (deviceID != GPUDRV_DEVICE_ID) {
  18.         return GPURESULT_INVALID_SLOT;
  19.     }
  20.    
  21.     gpuSlot = slot;
  22.     gpu_cls();
  23.     return GPURESULT_OK;
  24. }
  25.  
  26.  
  27. int gpu_cls() {
  28.     unsigned char line;
  29.     if (gpuSlot == 0) {
  30.         return GPURESULT_NOT_INITIALIZED;
  31.     }
  32.     gpu_setCursor(0, 0);
  33.     gpu_scroll(0);
  34.     for (line = 0; line < 60; line++) {
  35.         gpu_clearline(line);
  36.     }
  37.     return GPURESULT_OK;
  38. }
  39.  
  40. int gpu_clearline(unsigned char line) {
  41.     unsigned char column;
  42.     if (gpuSlot == 0) {
  43.         return GPURESULT_NOT_INITIALIZED;
  44.     }
  45.     writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, line);
  46.     for (column = 0; column < 80; column++) {
  47.         writeIO(gpuSlot, GPUDRV_IOADR_DATA + column, 0);
  48.     }
  49.     return GPURESULT_OK;
  50. }
  51.  
  52. unsigned char gpu_getLine() {
  53.     return currentLine;
  54. }
  55.  
  56. unsigned char gpu_getColumn() {
  57.     return currentColumn;
  58. }
  59.  
  60. unsigned char gpu_getWidth() {
  61.     return 80;
  62. }
  63.  
  64. unsigned char gpu_getHeight() {
  65.     return 60;
  66. }
  67.  
  68. int gpu_setCursor(unsigned char line, unsigned char column) {
  69.     if (gpuSlot == 0) {
  70.         return GPURESULT_NOT_INITIALIZED;
  71.     }
  72.     currentLine = line;
  73.     currentColumn = column;
  74.     return GPURESULT_OK;
  75. }
  76.  
  77. int gpu_scroll(unsigned char line) {
  78.     if (gpuSlot == 0) {
  79.         return GPURESULT_NOT_INITIALIZED;
  80.     }
  81.     scrollLine = line;
  82.     writeIO(gpuSlot, GPUDRV_IOADR_SCROLL, scrollLine);
  83.     return GPURESULT_OK;
  84. }
  85.  
  86. int gpu_print(char* text) {
  87.     unsigned int i;
  88.     unsigned char cont;
  89.     if (gpuSlot == 0) {
  90.         return GPURESULT_NOT_INITIALIZED;
  91.     }
  92.    
  93.     i = 0;
  94.     cont = 1;
  95.     writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, currentLine);
  96.     while (cont) {
  97.         if ((text[i] == 13) | (currentColumn >= 80)) {
  98.             currentLine++;
  99.             currentColumn = 0;
  100.             gpu_clearline(currentLine);
  101.             writeIO(gpuSlot, GPUDRV_IOADR_LINESEL, currentLine);
  102.         }
  103.        
  104.         if ((text[i] != 0) & (text[i] != 13)) {
  105.             writeIO(gpuSlot, GPUDRV_IOADR_DATA + currentColumn, text[i]);
  106.             currentColumn++;
  107.         }
  108.        
  109.         if (text[i] == 0) {
  110.             cont = 0;
  111.         }
  112.        
  113.         i++;
  114.     }
  115.    
  116.     if ((currentLine - scrollLine) >= 60) {
  117.         gpu_scroll(currentLine - 59);
  118.     }
  119.    
  120.     return GPURESULT_OK;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment