diff options
author | Kartik Agaram <vc@akkartik.com> | 2021-01-12 19:50:22 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2021-01-12 19:50:22 -0800 |
commit | e59086e65a204740da5ba1cf6a70c262bfc03b69 (patch) | |
tree | c2f55702aab0ed1d0195092ccbd56100d95183c3 /baremetal | |
parent | 0d12f6676bab81d1d68239dcd26089612450232d (diff) | |
download | mu-e59086e65a204740da5ba1cf6a70c262bfc03b69.tar.gz |
7503 - baremetal: noodling on default VGA palette
Diffstat (limited to 'baremetal')
-rw-r--r-- | baremetal/vga_palette | 283 | ||||
-rw-r--r-- | baremetal/vga_palette.c | 168 | ||||
-rw-r--r-- | baremetal/vga_palette.png | bin | 0 -> 1326889 bytes |
3 files changed, 451 insertions, 0 deletions
diff --git a/baremetal/vga_palette b/baremetal/vga_palette new file mode 100644 index 00000000..1b69c3c8 --- /dev/null +++ b/baremetal/vga_palette @@ -0,0 +1,283 @@ +# Default VGA 256-color palette + +# First 16 colors + 0: 0 0 0 + 1: 0 0 42 .......................................... + 2: 0 42 0 .......................................... + 3: 0 42 42 .......................................... .......................................... + 4: 42 0 0 .......................................... + 5: 42 0 42 .......................................... .......................................... + 6: 42 21 0 .......................................... ..................... + 7: 42 42 42 .......................................... .......................................... .......................................... + 8: 21 21 21 ..................... ..................... ..................... + 9: 21 21 63 ..................... ..................... ............................................................... + 10: 21 63 21 ..................... ............................................................... ..................... + 11: 21 63 63 ..................... ............................................................... ............................................................... + 12: 63 21 21 ............................................................... ..................... ..................... + 13: 63 21 63 ............................................................... ..................... ............................................................... + 14: 63 63 21 ............................................................... ............................................................... ..................... + 15: 63 63 63 ............................................................... ............................................................... ............................................................... + +# Greyscale + 16: 0 0 0 + 17: 5 5 5 ..... ..... ..... + 18: 8 8 8 ........ ........ ........ + 19: 11 11 11 ........... ........... ........... + 20: 14 14 14 .............. .............. .............. + 21: 17 17 17 ................. ................. ................. + 22: 20 20 20 .................... .................... .................... + 23: 24 24 24 ........................ ........................ ........................ + 24: 28 28 28 ............................ ............................ ............................ + 25: 32 32 32 ................................ ................................ ................................ + 26: 36 36 36 .................................... .................................... .................................... + 27: 40 40 40 ........................................ ........................................ ........................................ + 28: 45 45 45 ............................................. ............................................. ............................................. + 29: 50 50 50 .................................................. .................................................. .................................................. + 30: 56 56 56 ........................................................ ........................................................ ........................................................ + 31: 63 63 63 ............................................................... ............................................................... ............................................................... + +# Cycle 0 + 32: 0 0 63 ............................................................... + 33: 16 0 63 ................ ............................................................... + 34: 31 0 63 ............................... ............................................................... + 35: 47 0 63 ............................................... ............................................................... + 36: 63 0 63 ............................................................... ............................................................... + 37: 63 0 47 ............................................................... ............................................... + 38: 63 0 31 ............................................................... ............................... + 39: 63 0 16 ............................................................... ................ + 40: 63 0 0 ............................................................... + 41: 63 16 0 ............................................................... ................ + 42: 63 31 0 ............................................................... ............................... + 43: 63 47 0 ............................................................... ............................................... + 44: 63 63 0 ............................................................... ............................................................... + 45: 47 63 0 ............................................... ............................................................... + 46: 31 63 0 ............................... ............................................................... + 47: 16 63 0 ................ ............................................................... + 48: 0 63 0 ............................................................... + 49: 0 63 16 ............................................................... ................ + 50: 0 63 31 ............................................................... ............................... + 51: 0 63 47 ............................................................... ............................................... + 52: 0 63 63 ............................................................... ............................................................... + 53: 0 47 63 ............................................... ............................................................... + 54: 0 31 63 ............................... ............................................................... + 55: 0 16 63 ................ ............................................................... + + # Cycle 1 + 56: 31 31 63 ............................... ............................... ............................................................... + 57: 39 31 63 ....................................... ............................... ............................................................... + 58: 47 31 63 ............................................... ............................... ............................................................... + 59: 55 31 63 ....................................................... ............................... ............................................................... + 60: 63 31 63 ............................................................... ............................... ............................................................... + 61: 63 31 55 ............................................................... ............................... ....................................................... + 62: 63 31 47 ............................................................... ............................... ............................................... + 63: 63 31 39 ............................................................... ............................... ....................................... + 64: 63 31 31 ............................................................... ............................... ............................... + 65: 63 39 31 ............................................................... ....................................... ............................... + 66: 63 47 31 ............................................................... ............................................... ............................... + 67: 63 55 31 ............................................................... ....................................................... ............................... + 68: 63 63 31 ............................................................... ............................................................... ............................... + 69: 55 63 31 ....................................................... ............................................................... ............................... + 70: 47 63 31 ............................................... ............................................................... ............................... + 71: 39 63 31 ....................................... ............................................................... ............................... + 72: 31 63 31 ............................... ............................................................... ............................... + 73: 31 63 39 ............................... ............................................................... ....................................... + 74: 31 63 47 ............................... ............................................................... ............................................... + 75: 31 63 55 ............................... ............................................................... ....................................................... + 76: 31 63 63 ............................... ............................................................... ............................................................... + 77: 31 55 63 ............................... ....................................................... ............................................................... + 78: 31 47 63 ............................... ............................................... ............................................................... + 79: 31 39 63 ............................... ....................................... ............................................................... + + # Cycle 2 + 80: 45 45 63 ............................................. ............................................. ............................................................... + 81: 49 45 63 ................................................. ............................................. ............................................................... + 82: 54 45 63 ...................................................... ............................................. ............................................................... + 83: 58 45 63 .......................................................... ............................................. ............................................................... + 84: 63 45 63 ............................................................... ............................................. ............................................................... + 85: 63 45 58 ............................................................... ............................................. .......................................................... + 86: 63 45 54 ............................................................... ............................................. ...................................................... + 87: 63 45 49 ............................................................... ............................................. ................................................. + 88: 63 45 45 ............................................................... ............................................. ............................................. + 89: 63 49 45 ............................................................... ................................................. ............................................. + 90: 63 54 45 ............................................................... ...................................................... ............................................. + 91: 63 58 45 ............................................................... .......................................................... ............................................. + 92: 63 63 45 ............................................................... ............................................................... ............................................. + 93: 58 63 45 .......................................................... ............................................................... ............................................. + 94: 54 63 45 ...................................................... ............................................................... ............................................. + 95: 49 63 45 ................................................. ............................................................... ............................................. + 96: 45 63 45 ............................................. ............................................................... ............................................. + 97: 45 63 49 ............................................. ............................................................... ................................................. + 98: 45 63 54 ............................................. ............................................................... ...................................................... + 99: 45 63 58 ............................................. ............................................................... .......................................................... +100: 45 63 63 ............................................. ............................................................... ............................................................... +101: 45 58 63 ............................................. .......................................................... ............................................................... +102: 45 54 63 ............................................. ...................................................... ............................................................... +103: 45 49 63 ............................................. ................................................. ............................................................... + +# Cycle 3 +104: 0 0 28 ............................ +105: 7 0 28 ....... ............................ +106: 14 0 28 .............. ............................ +107: 21 0 28 ..................... ............................ +108: 28 0 28 ............................ ............................ +109: 28 0 21 ............................ ..................... +110: 28 0 14 ............................ .............. +111: 28 0 7 ............................ ....... +112: 28 0 0 ............................ +113: 28 7 0 ............................ ....... +114: 28 14 0 ............................ .............. +115: 28 21 0 ............................ ..................... +116: 28 28 0 ............................ ............................ +117: 21 28 0 ..................... ............................ +118: 14 28 0 .............. ............................ +119: 7 28 0 ....... ............................ +120: 0 28 0 ............................ +121: 0 28 7 ............................ ....... +122: 0 28 14 ............................ .............. +123: 0 28 21 ............................ ..................... +124: 0 28 28 ............................ ............................ +125: 0 21 28 ..................... ............................ +126: 0 14 28 .............. ............................ +127: 0 7 28 ....... ............................ + +# Cycle 4 +128: 14 14 28 .............. .............. ............................ +129: 17 14 28 ................. .............. ............................ +130: 21 14 28 ..................... .............. ............................ +131: 24 14 28 ........................ .............. ............................ +132: 28 14 28 ............................ .............. ............................ +133: 28 14 24 ............................ .............. ........................ +134: 28 14 21 ............................ .............. ..................... +135: 28 14 17 ............................ .............. ................. +136: 28 14 14 ............................ .............. .............. +137: 28 17 14 ............................ ................. .............. +138: 28 21 14 ............................ ..................... .............. +139: 28 24 14 ............................ ........................ .............. +140: 28 28 14 ............................ ............................ .............. +141: 24 28 14 ........................ ............................ .............. +142: 21 28 14 ..................... ............................ .............. +143: 17 28 14 ................. ............................ .............. +144: 14 28 14 .............. ............................ .............. +145: 14 28 17 .............. ............................ ................. +146: 14 28 21 .............. ............................ ..................... +147: 14 28 24 .............. ............................ ........................ +148: 14 28 28 .............. ............................ ............................ +149: 14 24 28 .............. ........................ ............................ +150: 14 21 28 .............. ..................... ............................ +151: 14 17 28 .............. ................. ............................ + +# Cycle 5 +152: 20 20 28 .................... .................... ............................ +153: 22 20 28 ...................... .................... ............................ +154: 24 20 28 ........................ .................... ............................ +155: 26 20 28 .......................... .................... ............................ +156: 28 20 28 ............................ .................... ............................ +157: 28 20 26 ............................ .................... .......................... +158: 28 20 24 ............................ .................... ........................ +159: 28 20 22 ............................ .................... ...................... +160: 28 20 20 ............................ .................... .................... +161: 28 22 20 ............................ ...................... .................... +162: 28 24 20 ............................ ........................ .................... +163: 28 26 20 ............................ .......................... .................... +164: 28 28 20 ............................ ............................ .................... +165: 26 28 20 .......................... ............................ .................... +166: 24 28 20 ........................ ............................ .................... +167: 22 28 20 ...................... ............................ .................... +168: 20 28 20 .................... ............................ .................... +169: 20 28 22 .................... ............................ ...................... +170: 20 28 24 .................... ............................ ........................ +171: 20 28 26 .................... ............................ .......................... +172: 20 28 28 .................... ............................ ............................ +173: 20 26 28 .................... .......................... ............................ +174: 20 24 28 .................... ........................ ............................ +175: 20 22 28 .................... ...................... ............................ + +# Cycle 6 +176: 0 0 16 ................ +177: 4 0 16 .... ................ +178: 8 0 16 ........ ................ +179: 12 0 16 ............ ................ +180: 16 0 16 ................ ................ +181: 16 0 12 ................ ............ +182: 16 0 8 ................ ........ +183: 16 0 4 ................ .... +184: 16 0 0 ................ +185: 16 4 0 ................ .... +186: 16 8 0 ................ ........ +187: 16 12 0 ................ ............ +188: 16 16 0 ................ ................ +189: 12 16 0 ............ ................ +190: 8 16 0 ........ ................ +191: 4 16 0 .... ................ +192: 0 16 0 ................ +193: 0 16 4 ................ .... +194: 0 16 8 ................ ........ +195: 0 16 12 ................ ............ +196: 0 16 16 ................ ................ +197: 0 12 16 ............ ................ +198: 0 8 16 ........ ................ +199: 0 4 16 .... ................ + +# Cycle 7 +200: 8 8 16 ........ ........ ................ +201: 10 8 16 .......... ........ ................ +202: 12 8 16 ............ ........ ................ +203: 14 8 16 .............. ........ ................ +204: 16 8 16 ................ ........ ................ +205: 16 8 14 ................ ........ .............. +206: 16 8 12 ................ ........ ............ +207: 16 8 10 ................ ........ .......... +208: 16 8 8 ................ ........ ........ +209: 16 10 8 ................ .......... ........ +210: 16 12 8 ................ ............ ........ +211: 16 14 8 ................ .............. ........ +212: 16 16 8 ................ ................ ........ +213: 14 16 8 .............. ................ ........ +214: 12 16 8 ............ ................ ........ +215: 10 16 8 .......... ................ ........ +216: 8 16 8 ........ ................ ........ +217: 8 16 10 ........ ................ .......... +218: 8 16 12 ........ ................ ............ +219: 8 16 14 ........ ................ .............. +220: 8 16 16 ........ ................ ................ +221: 8 14 16 ........ .............. ................ +222: 8 12 16 ........ ............ ................ +223: 8 10 16 ........ .......... ................ + +# Cycle 8 +224: 11 11 16 ........... ........... ................ +225: 12 11 16 ............ ........... ................ +226: 13 11 16 ............. ........... ................ +227: 15 11 16 ............... ........... ................ +228: 16 11 16 ................ ........... ................ +229: 16 11 15 ................ ........... ............... +230: 16 11 13 ................ ........... ............. +231: 16 11 12 ................ ........... ............ +232: 16 11 11 ................ ........... ........... +233: 16 12 11 ................ ............ ........... +234: 16 13 11 ................ ............. ........... +235: 16 15 11 ................ ............... ........... +236: 16 16 11 ................ ................ ........... +237: 15 16 11 ............... ................ ........... +238: 13 16 11 ............. ................ ........... +239: 12 16 11 ............ ................ ........... +240: 11 16 11 ........... ................ ........... +241: 11 16 12 ........... ................ ............ +242: 11 16 13 ........... ................ ............. +243: 11 16 15 ........... ................ ............... +244: 11 16 16 ........... ................ ................ +245: 11 15 16 ........... ............... ................ +246: 11 13 16 ........... ............. ................ +247: 11 12 16 ........... ............ ................ + +# Black +248: 0 0 0 +249: 0 0 0 +250: 0 0 0 +251: 0 0 0 +252: 0 0 0 +253: 0 0 0 +254: 0 0 0 +255: 0 0 0 + +# vim:listchars=:nowrap diff --git a/baremetal/vga_palette.c b/baremetal/vga_palette.c new file mode 100644 index 00000000..11a440ce --- /dev/null +++ b/baremetal/vga_palette.c @@ -0,0 +1,168 @@ +/* Visualize the standard VGA palette. + * Based on https://github.com/canidlogic/vgapal (MIT License) */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +char* bar(int n) { + char* result = calloc(65, 1); + int i; + for (i = 0; i < n; ++i) + result[i] = '.'; + for (; i < 64; ++i) + result[i] = ' '; + result[64] = '\0'; + return result; +} + +void addColor(int r, int g, int b) { + static int i = 0; +//? printf("%02x %02x %02x\n", r, g, b); + printf("%3d: %2d %2d %2d %s %s %s\n", i, r, g, b, bar(r), bar(g), bar(b)); + ++i; +} + +void addGrayColor(int v) { + addColor(v, v, v); +} + +void add16Color(int lo, int melo, int mehi, int hi) { + int r, g, b, i, h, l; + + for (i = 0; i < 8; i++) { + r = g = b = lo; + if (i & 4) r = mehi; + if (i & 2) g = (i==6)?melo:mehi; /* exception: color 6 is brown rather than dark yellow */ + if (i & 1) b = mehi; + addColor(r, g, b); + } + + for (i = 0; i < 8; i++) { + r = g = b = melo; + if (i & 4) r = hi; + if (i & 2) g = hi; + if (i & 1) b = hi; + addColor(r, g, b); + } +} + +/* Add four colors to the palette corresponding to a "run" within an RGB cycle. + * + * start - high and low starting states for each channel at the start of the run + * ch - the channel to change from high to low or low to high */ +void addRun(int start, int ch, int lo, int melo, int me, int mehi, int hi) { + int r, g, b, i, up; + + /* Check parameters */ + if (start < 0 || start > 7) + abort(); + if (ch != 1 && ch != 2 && ch != 4) + abort(); + + /* Get the starting RGB color and add it */ + r = lo; + g = lo; + b = lo; + if ((start & 4) == 4) + r = hi; + if ((start & 2) == 2) + g = hi; + if ((start & 1) == 1) + b = hi; + addColor(r, g, b); + + /* If selected channel starts high, we're going down; otherwise we're going up */ + up = (start & ch) != ch; + + /* Add remaining three colors of the run */ + switch (ch) { + case 4: r = up?melo:mehi; break; + case 2: g = up?melo:mehi; break; + case 1: b = up?melo:mehi; break; + } + addColor(r, g, b); + + switch (ch) { + case 4: r = me; break; + case 2: g = me; break; + case 1: b = me; break; + } + addColor(r, g, b); + + switch (ch) { + case 4: r = up?mehi:melo; break; + case 2: g = up?mehi:melo; break; + case 1: b = up?mehi:melo; break; + } + addColor(r, g, b); +} + +/* A cycle consists of six 4-color runs, each of which transitions from + * one hue to another until arriving back at starting position. */ +void addCycle(int lo, int melo, int me, int mehi, int hi) { + int hue = 1; /* blue */ + addRun(hue, 4, lo, melo, me, mehi, hi); + hue ^= 4; + assert(hue == 5); + addRun(hue, 1, lo, melo, me, mehi, hi); + hue ^= 1; + assert(hue == 4); + addRun(hue, 2, lo, melo, me, mehi, hi); + hue ^= 2; + assert(hue == 6); + addRun(hue, 4, lo, melo, me, mehi, hi); + hue ^= 4; + assert(hue == 2); + addRun(hue, 1, lo, melo, me, mehi, hi); + hue ^= 1; + assert(hue == 3); + addRun(hue, 2, lo, melo, me, mehi, hi); +} + +int main(void) { + int i; + + /* 16-color palette */ + add16Color(0, 21, 42, 63); + + /* 16 shades of gray */ + addGrayColor( 0); + addGrayColor( 5); + addGrayColor( 8); + addGrayColor(11); + addGrayColor(14); + addGrayColor(17); + addGrayColor(20); + addGrayColor(24); + addGrayColor(28); + addGrayColor(32); + addGrayColor(36); + addGrayColor(40); + addGrayColor(45); + addGrayColor(50); + addGrayColor(56); + addGrayColor(63); + + /* Nine RGB cycles organized in three groups of three cycles, + * The groups represent high/medium/low value, + * and the cycles within the groups represent high/medium/low saturation. */ + addCycle( 0, 16, 31, 47, 63); + addCycle(31, 39, 47, 55, 63); + addCycle(45, 49, 54, 58, 63); + + addCycle( 0, 7, 14, 21, 28); + addCycle(14, 17, 21, 24, 28); + addCycle(20, 22, 24, 26, 28); + + addCycle( 0, 4, 8, 12, 16); + addCycle( 8, 10, 12, 14, 16); + addCycle(11, 12, 13, 15, 16); + + /* final eight palette entries are full black */ + for (i = 0; i < 8; ++i) + addGrayColor(0); + + return 0; +} diff --git a/baremetal/vga_palette.png b/baremetal/vga_palette.png new file mode 100644 index 00000000..cea46962 --- /dev/null +++ b/baremetal/vga_palette.png Binary files differ |