Guest User

main.c

a guest
Mar 25th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <color.h>
  2. #include <display.h>
  3. #include <display_syscalls.h>
  4. #include <keyboard.hpp>
  5. #include <keyboard_syscalls.h>
  6. /* USEFUL ROUTINES */
  7. #include "routines.h"
  8.  
  9.  
  10. /* FUNCTIONS */
  11. void dispCanvas(int x, int y, int width, int height, int zoom, color_t **canvas) {
  12.     int i;
  13.     int j;
  14.     for (i = 0; i < width; i++) {
  15.         for (j = 0; j < height; j++) {
  16.             if (canvas[i][j]) {
  17.                 fillArea(i*zoom+x, j*zoom+y, zoom, zoom, canvas[i][j]);
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. void dispCursor(int origin_x, int origin_y, int x, int y, int zoom) {
  24.     fillArea(x*zoom+origin_x, y*zoom+origin_y, zoom, zoom, COLOR_RED);
  25. }
  26.  
  27. /* MAIN FUNCTION */
  28. int main() {
  29.     /* SETUP */
  30.     // enable fullcolor
  31.     Bdisp_EnableColor(1);
  32.     /* VARS */
  33.     char buffer[10];
  34.  
  35.     int key;
  36.     int key_dump;
  37.  
  38.     int cursor[2] = {0,0};
  39.     int origin[2] = {1,1};
  40.  
  41.     int canvas_height = 8;
  42.     int canvas_width = 8;
  43.     color_t canvas[8][8];
  44.  
  45.     int zoom = 4;
  46.  
  47.     int i;
  48.     int j;
  49.  
  50.     for (i = 0; i < canvas_height; i++) {
  51.         for (j = 0; j < canvas_width; j++) {
  52.             canvas[i][j] = COLOR_WHITE;
  53.         }
  54.     }
  55.  
  56.     /* MAIN LOOP, NEVER BREAK */
  57.     while (1) {
  58.         // clear screen
  59.         Bdisp_AllClr_VRAM();
  60.  
  61.         /* GETKEY */
  62.         if (PRGM_GetKey()==KEY_PRGM_MENU) {
  63.             // handle menu
  64.             GetKey(&key_dump);
  65.         }
  66.  
  67.         // move cursor
  68.         if ((PRGM_GetKey()==KEY_PRGM_UP) && (cursor[1]>0)) {
  69.             cursor[1]--;
  70.         }
  71.  
  72.         if ((PRGM_GetKey()==KEY_PRGM_DOWN) && (cursor[1]<canvas_height)) {
  73.             cursor[1]++;
  74.         }
  75.  
  76.         if ((PRGM_GetKey()==KEY_PRGM_LEFT) && (cursor[0]>0)) {
  77.                 cursor[0]--;
  78.         }
  79.  
  80.         if ((PRGM_GetKey()==KEY_PRGM_RIGHT) && (cursor[0]<canvas_width)) {
  81.                 cursor[0]++;
  82.         }
  83.  
  84.         // display the canvas
  85.         dispCanvas(origin[0], origin[1], canvas_width, canvas_height, zoom, canvas);
  86.  
  87.         // display the cursor
  88.         dispCursor(origin[0], origin[1], cursor[0], cursor[1], zoom);
  89.  
  90.         // debug
  91.         strcpy(buffer, "  ");
  92.         itoa(cursor[1], buffer+2);
  93.         PrintXY(1, 7, buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
  94.  
  95.         // refresh screen
  96.         Bdisp_PutDisp_DD();
  97.     }
  98.  
  99.  
  100.     return 1;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment