Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Ivion Kernel - The Future Free Kernel
- * Copyright(C)2013 Muhammad Irvan H.
- * Software ini boleh dimiliki, disebarkan, diubah dengan bebas.
- * Dengan catatan:
- * > Boleh menambah, namun dilarang mengubah komentar ini.
- * > Hanya dipakai untuk edukasi dan non-profit(non-komersil).
- * > Dilarang mendokumentasikan kode dalam bentuk buku atau semacamnya,
- * sebelum izin kepada kru Ivion. (Izin GRATIS)
- */
- #include "struct.h"
- #include "type.h"
- char* current_video_mem = (char*)0xB8000;
- uchar current_col;
- uchar current_row;
- const uchar MAX_COL = 80;
- const uchar MAX_ROW = 25;
- const uint VIDEO_MEM_BASE = 0xB8000;
- const uchar BYTES_PER_CHAR = 2;
- ushort cursor_pos;
- void move_cursor(short, short);
- void new_line();
- /* *
- * Print String from char * strings with attributes
- * */
- void print_str(char* strings, uchar attributes)
- {
- int i = 0;
- while(strings[i] != 0)
- {
- if (strings[i] == '\n')
- {
- new_line();
- i++;
- }
- else
- {
- *current_video_mem = strings[i];
- current_video_mem++;
- *current_video_mem = attributes;
- current_video_mem++;
- i++;
- if (current_col == 79)
- {
- new_line();
- }
- else
- {
- current_col++;
- }
- }
- }
- move_cursor(current_col,current_row);
- }
- /* *
- * Print Single Character from char character, with attributes
- * */
- void putch(char character, char attributes)
- {
- char the_char[2];
- the_char[0] = character;
- the_char[1] = 0;
- print_str(&the_char[0],attributes);
- }
- /* *
- * New Line with auto scrolling
- * */
- void new_line()
- {
- int i;
- char* location=(char*)VIDEO_MEM_BASE;
- if (current_row == 24)
- {
- for (i = 0; i <= 80*25*2; i++)
- {
- location[i] = location[i+80*2];
- }
- current_row = 24;
- current_col = 0;
- }
- else
- {
- current_row++;
- current_col=0;
- }
- current_video_mem = (char*)VIDEO_MEM_BASE + ((current_row * 80 + current_col) * 2);
- move_cursor(current_col,current_row);
- }
- /* *
- * Clear screen
- * */
- void clear_scr()
- {
- int i;
- short* location = (short*)VIDEO_MEM_BASE;
- for(i=0; i<MAX_COL*MAX_ROW; i++)
- {
- *location = 0x0f00;
- location++;
- }
- move_cursor(0,0);
- }
- /* *
- * Move caret/cursor to X, Y
- * */
- void move_cursor(short x, short y)
- {
- cursor_pos = (y * MAX_COL) + x;
- asm (".intel_syntax noprefix");
- asm ("mov al,14");
- asm ("mov dx,0x3d4");
- asm ("out dx,al");
- asm ("mov ax,[cursor_pos]");
- asm ("shr ax,8");
- asm ("mov dx,0x3d5");
- asm ("out dx,al");
- asm ("mov al,15");
- asm ("mov dx,0x3d4");
- asm ("out dx,al");
- asm ("mov ax,[cursor_pos]");
- asm ("mov dx, 0x3d5");
- asm ("out dx,al");
- }
- void get_cursor_pos(cursor_position_struct* cursor_pos_struct)
- {
- cursor_pos_struct->x = current_col;
- cursor_pos_struct->y = current_row;
- }
- /* *
- * Convert Integer Number to Hexadecimal Number
- * Number saved to char* buffer
- * */
- char hexadecimal[9];
- void int_to_hex_str(uint number, char* buffer)
- {
- int i,j=0;
- //process
- for (i=0;number / 0x10 != 0; i++)
- {
- if(number % 0x10 > 9)
- {
- hexadecimal[i] = (number % 0x10) + 0x37;
- }
- else
- {
- hexadecimal[i] = (number % 0x10) + 0x30;
- }
- number /= 0x10;
- }
- if(number % 0x10 > 9)
- {
- hexadecimal[i] = (number % 0x10) + 0x37;
- }
- else
- {
- hexadecimal[i] = (number % 0x10) + 0x30;
- }
- //save
- while(i != 0)
- {
- buffer[j] = hexadecimal[i];
- i--;
- j++;
- }
- buffer[j] = hexadecimal[i];
- buffer[j+1] = 0;
- }
- /* *
- * Convert Unsigned Integer Number to Decimal String
- * Number saved to char* buffer
- * */
- char decimal[15];
- void uint_to_decimal_str(uint number, char* buffer)
- {
- int i,j=0;
- //process
- for (i=0;number / 10 != 0; i++)
- {
- decimal[i] = (number % 10) + 0x30;
- number /= 10;
- }
- decimal[i] = number + 0x30;
- //save
- while(i != 0)
- {
- buffer[j] = decimal[i];
- i--;
- j++;
- }
- buffer[j] = decimal[i];
- buffer[j+1] = 0;
- }
- /* *
- * Convert Signed Integer Number to Decimal String
- * Number saved to char* buffer
- * */
- void sint_to_decimal_str(sint snumber, char* buffer)
- {
- int i,j=0,number;
- //compare
- if(snumber < 0)
- {
- number = (snumber * -1);
- }
- else
- {
- number = snumber;
- }
- //process
- for (i=0;number / 10 != 0; i++)
- {
- decimal[i] = (number % 10) + 0x30;
- number /= 10;
- }
- decimal[i] = number + 0x30;
- //set sign
- if (snumber < 0)
- {
- buffer[j] = 0x2d; //strip (-)
- j++;
- }
- //save
- while(i != 0)
- {
- buffer[j] = decimal[i];
- i--;
- j++;
- }
- buffer[j] = decimal[i];
- buffer[j+1] = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement