Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

print.c (4224B)


      1 #include "../include/main.h"
      2 #include "../include/print.h"
      3 #include "../include/font.h"
      4 #include "../include/strcmp.h"
      5 #include <stdint.h>
      6 
      7 #define OFF_WHITE 0xFFFFFDD0
      8 #define BLACK 0x00000000
      9 #define RED 0xFFFF0000
     10 #define YELLOW 0xFFFFFF00
     11 #define WHITE 0xFFFFFFFF
     12 
     13 uint64_t x = 0;
     14 uint64_t y = 0;
     15 
     16 
     17 void perRowPrint(unsigned char line, int line_idx, int x_dyn, char *mode) {
     18     if (strcmp(mode, "black") == 1) {
     19         for (int i = 0; i < 8; i++) {
     20             unsigned char mask = 0x80 >> i;
     21 
     22             if (line & mask) {
     23                 fb[(y+line_idx) * ppline + (x_dyn+i)] = WHITE;
     24             } else {
     25                 fb[(y+line_idx) * ppline + (x_dyn+i)] = BLACK;
     26             }
     27         }
     28     }
     29     else {
     30         for (int i = 0; i < 8; i++) {
     31             unsigned char mask = 0x80 >> i;
     32 
     33             if (line & mask) {
     34                 fb[(y+line_idx) * ppline + (x_dyn+i)] = BLACK;
     35             } else {
     36                 fb[(y+line_idx) * ppline + (x_dyn+i)] = WHITE;
     37             }
     38         }
     39     }
     40 }
     41 
     42 void perRowWarn(unsigned char line, int line_idx, int x_dyn, char *mode) {
     43     if (strcmp(mode, "black") == 1) {
     44         for (int i = 0; i < 8; i++) {
     45             unsigned char mask = 0x80 >> i;
     46 
     47             if (line & mask) {
     48                 fb[(y+line_idx) * ppline + (x_dyn+i)] = RED;
     49             } else {
     50                 fb[(y+line_idx) * ppline + (x_dyn+i)] = BLACK;
     51             }
     52         }
     53     }
     54     else {
     55         for (int i = 0; i < 8; i++) {
     56             unsigned char mask = 0x80 >> i;
     57 
     58             if (line & mask) {
     59                 fb[(y+line_idx) * ppline + (x_dyn+i)] = RED;
     60             } else {
     61                 fb[(y+line_idx) * ppline + (x_dyn+i)] = WHITE;
     62             }
     63         }
     64     }
     65 }
     66 
     67 void perRowInfo(unsigned char line, int line_idx, int x_dyn, char *mode) {
     68     if (strcmp(mode, "black") == 1) {
     69         for (int i = 0; i < 8; i++) {
     70             unsigned char mask = 0x80 >> i;
     71 
     72             if (line & mask) {
     73                 fb[(y+line_idx) * ppline + (x_dyn+i)] = YELLOW;
     74             } else {
     75                 fb[(y+line_idx) * ppline + (x_dyn+i)] = BLACK;
     76             }
     77         }
     78     }
     79     else {
     80         for (int i = 0; i < 8; i++) {
     81             unsigned char mask = 0x80 >> i;
     82 
     83             if (line & mask) {
     84                 fb[(y+line_idx) * ppline + (x_dyn+i)] = YELLOW;
     85             } else {
     86                 fb[(y+line_idx) * ppline + (x_dyn+i)] = WHITE;
     87             }
     88         }
     89     }
     90 }
     91 
     92 void k_print(char *mode, const char *str) {
     93     int line_idx;
     94 
     95     const char *ch = str;
     96     while (*ch != 0) {
     97         if (*ch=='\n') {
     98             x = 0;
     99             y +=16;
    100             ch++;
    101             continue;
    102         }
    103 
    104         for (line_idx = 0; line_idx < 16; line_idx++) {
    105             perRowPrint(font8x16[(unsigned char)*ch][line_idx], line_idx, x, mode);
    106         }
    107 
    108         if (x+8==maxX) {
    109             x=0; y+=16;
    110         }
    111         x+=8; ch++;
    112     }
    113 }
    114 
    115 void k_warn(char *mode, const char *str) {
    116     int line_idx;
    117 
    118     const char *ch = str;
    119     while (*ch != 0) {
    120         if (*ch=='\n') {
    121             x = 0;
    122             y +=16;
    123             ch++;
    124             continue;
    125         }
    126 
    127         for (line_idx = 0; line_idx < 16; line_idx++) {
    128             perRowWarn(font8x16[(unsigned char)*ch][line_idx], line_idx, x, mode);
    129         }
    130 
    131         if (x+8==maxX) {
    132             x=0; y+=16;
    133         }
    134         x+=8; ch++;
    135     }
    136 }
    137 
    138 void k_info(char *mode, const char *str) {
    139     int line_idx;
    140 
    141     const char *ch = str;
    142     while (*ch != 0) {
    143         if (*ch=='\n') {
    144             x = 0;
    145             y +=16;
    146             ch++;
    147             continue;
    148         }
    149 
    150         for (line_idx = 0; line_idx < 16; line_idx++) {
    151             perRowInfo(font8x16[(unsigned char)*ch][line_idx], line_idx, x, mode);
    152         }
    153 
    154         if (x+8==maxX) {
    155             x=0; y+=16;
    156         }
    157         x+=8; ch++;
    158     }
    159 }
    160 
    161 void k_delete(char *mode) {
    162     if (x<=72) {
    163         return;
    164     } else {
    165         x-=8;
    166         k_print(mode, " ");
    167         x-=8;
    168     }
    169 }
    170 
    171 void k_init (char *mode) {
    172     if (strcmp(mode, "black") == 1) {
    173         for (uint64_t i = 0; i < fsize / 4; i++) {
    174             fb[i] = BLACK;
    175         }
    176     } else {
    177         for (uint64_t i = 0; i < fsize / 4; i++) {
    178             fb[i] = WHITE;
    179         }
    180     }
    181 }