Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Copyright (c) 1997-2017, FenixOS Developers
- All Rights Reserved.
- This file is subject to the terms and conditions defined in
- file 'LICENSE', which is part of this source code package.
- */
- /*! \file video.c This file holds implementations of functions
- presenting output to the VGA screen. */
- #include <stdint.h>
- /*! Max number of columns in the VGA buffer. */
- #define MAX_COLS (80)
- /*! Max number of columns in the VGA buffer. */
- #define MAX_ROWS (25)
- struct screen_position {
- unsigned char character; /*!< The character part of the byte tuple used for
- each screen position. */
- unsigned char attribute; /*!< The character part of the byte tuple used for
- each screen position. */
- };
- /*!< Defines a VGA text mode screen position. */
- struct screen {
- struct screen_position positions[MAX_ROWS][MAX_COLS];
- /*!< The VGA screen. It is organized as a two dimensional array. */
- };
- /*!< Defines a VGA text mode screen. */
- /*! points to the VGA screen. */
- static struct screen* const screen_pointer = (struct screen*) 0xB8000;
- uint16_t const colorByte = 0x0f;
- void printCharArray(const char* string, uint16_t x,uint16_t y) {
- volatile uint16_t * location;
- uint16_t newy = y;
- uint16_t newx = x;
- location = (volatile uint16_t *)0xB8000 + (y * 80 + x);
- newx++;
- if (newx == 80) {
- newx = 0;
- newy++;
- }
- *location = *string | colorByte << 8;
- if (*string+1 == '/n') {
- printCharArray(string + 2, newx, newy + 1);
- } else if (*string+1 != '/0') {
- printCharArray(string + 1, newx, newy);
- }
- }
- void kprints(const char* string) {
- uint16_t y = 0;
- uint16_t x = 0;
- printCharArray(string, x, y);
- }
- void kprinthex(const register uint32_t value) {
- volatile uint16_t * location;
- location = (volatile uint16_t *)0xB8000 ;
- uint16_t number = 0;
- uint32_t newValue = value;
- while (newValue) {
- uint16_t temp = value == '1' ? 1 : 0;
- number = (value << 1) | temp;
- newValue = newValue << 1;
- }
- *location = number | colorByte << 8;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement