diff --git a/Book/Common/test.cpp b/Book/Common/test.cpp new file mode 100644 index 0000000..4bd65fa --- /dev/null +++ b/Book/Common/test.cpp @@ -0,0 +1,23 @@ + +enum ColourFormat { + RGB_555 = 0, + RGB_565, + RGB_888 , + ARGB_8888 +}; + +class Colour { + public: + unsigned char red; +}; + +static const int screenWidth = 1024; + +template +void writePixel(int x, int y, Colour col) +{ + int index = (y * screenWidth) + x; + //framebufferBaseAddress[index] = val; +} + + diff --git a/Book/Common/test.cpp b/Book/Common/test.cpp new file mode 100644 index 0000000..4bd65fa --- /dev/null +++ b/Book/Common/test.cpp @@ -0,0 +1,23 @@ + +enum ColourFormat { + RGB_555 = 0, + RGB_565, + RGB_888 , + ARGB_8888 +}; + +class Colour { + public: + unsigned char red; +}; + +static const int screenWidth = 1024; + +template +void writePixel(int x, int y, Colour col) +{ + int index = (y * screenWidth) + x; + //framebufferBaseAddress[index] = val; +} + + diff --git a/Book/Linux/direct.cpp b/Book/Linux/direct.cpp new file mode 100644 index 0000000..486ec80 --- /dev/null +++ b/Book/Linux/direct.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +static const int count = 1024; + +int main(int argc, char *argv[]) +{ + int fileDescriptor; + char *frameBuffer; + int index; + + /* Open the framebuffer device */ + fileDescriptor = open("/dev/fb0", O_RDWR); + if (fileDescriptor <= 0) { + perror("Error opening framebuffer device /dev/fb0"); + return 0; + } + + /* Map the framebuffer to the process address space */ + frameBuffer = (char *)mmap(0, count, PROT_READ | PROT_WRITE, + MAP_SHARED, fileDescriptor, 0); + if (frameBuffer <= 0) { + perror("Error mapping framebuffer to address space"); + return 0; + } + + /* Write to the framebuffer memory */ + for (index = 0; index < count; index++) { + frameBuffer[index] = 0xFF; + } + + /* Shutdown */ + munmap((void *)frameBuffer, count); + close(fileDescriptor); + return 1; +} +