-
Notifications
You must be signed in to change notification settings - Fork 13
Simple Modes
Some have expressed the interest for simple modes for the Bitbox. An recent commit is providing such mode , on top of the standard kernel.
The so-called simple modes are called like this because they provide a frame buffer interface, so the application programmer will only have to write bits and bytes to the video memory - much like it's done on PC. So the interface is a vram buch of memory and a color palette (because the tradeoff is a reduced palette or resolution)
There are two examples in the bitbox SDK (one of them below), but generally you'll need to define a simple makefile variable VGA_SIMPLE_MODE=X with the given mode and include the bitbox.mk standard makefile.
(Yes it's currently defined at compile time - if your program needs to switch between two modes at runtime, it might be time to switch to a standard kernel / engine - it's not difficult !)
The modes are the following:
mode | type | colors | resolution | VRAM | kernel mode |
---|---|---|---|---|---|
0 | text | 2 | 80x25 | 2k+2k | 640x480 |
1 | text | 2* | 132x75 | 10k+10k | 800x600 |
2 | graphical | 2 | 800x600 | 59k | 800x600 |
3 | graphical | 4 | 640x400 | 64k | 640x480 |
4 | graphical | 16 | 400x300 | 64k | 800x600 |
5 | graphical | 256 | 320x200 | 64k | 640x480 |
10 | text | 256* | 80x30 | <10k | 640x480 |
11 | text | 256* | 120x75 | <10k | 800x600 |
12 | text | 256* | 80x60 | <10k | 640x480 |
*text modes 0 and 1 are only B&W (well, whatever you define as palette 0 and 1). Modes 10 and 11 use a 256 entry palette of u16 fg / u16 bg attributes. Beware that using mode 11 (really stretching the harwdare) with too much color changes per line might create dark lines.
All modes use a palette of u16. Set the color by setting a 0rrrrrgggggbbbbb 15- bit word entry in the palette array. By example, to assign a bright red color to color index 4 (zero-based), just set
extern uint16_t palette[16];
palette[4]=0b0111110000000000; // binary literal or use RGB(x,y,z)
2-color palettes : 0 : black, 1:white
4-color palette: 0 : black, 1 : cyan, 2 : red, 3:light grey
16-color palette : standard CGA 16 color palette (http://en.wikipedia.org/wiki/Color_Graphics_Adapter)
256-color palette : unsurprisingly, this default palette is VGA mode 0x13 standard palette. (see http://fr.wikipedia.org/wiki/Mode_13h )
Text modes 0 and 1 define text modes with color attributes.
Mode 0 is 80 columns by 25 lines, Mode 1 is 132 columns by 75 lines.
Video Memory has one array of characters (vram)
Examples
Example to draw the ASCII table :
#define SCREEN_W 132
for (int i=0;i<256;i++)
vram[(i/16)*SCREEN_W + i%16]=i;
Feel free to use memcpy / memset also (strcpy writes a zero character after the string)
char *my_str = "Bitbox rules";
memcpy(&vram[4*132+13], my_str,strlen(my_str));
Graphical mode map linearly pixels (color indexes) to bits in memory, ie to set a pixel as color 1 (defined in the palette) on coordinates 100,50 with mode 2, use
extern uint32_t vram;
// set a bit on the bit array of pixels, made of 32bit words
vram[(50*800+100)/32] |= 1<<(100%32);
or just use the draw_pixel or draw_line functions (of course to fill/copy a bunch of pixels, you'd better use memory access)
draw_pixel(100,100,1);
The program can be found in the SDK examples.
Here is it in its entirety:
- Makefile
NO_USB=1
NO_SDCARD=1
# See lib/simple.h for modes
VGA_SIMPLE_MODE=4
NAME = sgraph
GAME_C_FILES = $(NAME).c
# see this file for options
include $(BITBOX)/lib/bitbox.mk
- test_simple_graph.c
#include <stdlib.h> // rand
#include "simple.h"
void game_init(void) {}
void game_frame(void)
{
if (vga_frame%180==0) clear();
for (int i=0;i<10;i++)
draw_line( rand()%SCREEN_W, rand()%SCREEN_H,
rand()%SCREEN_W, rand()%SCREEN_H,
rand()%(1<<BPP));
}
- Result
Simple, no ?
Well, I cheated there is no such mode :)
However, there is a simple example project using the engine that you can use very simply, just take the test_engine project in the SDK and tweak it !