Diff markup
001 001
>> 002
002 003
003 004
004 005
005 006
006 007
007 008
008 009
009 010
010 011
011 012
012 013
013 014
014 015
015 016
016 017
017 018
018 #include <sos/klibc.h> 019 #include <sos/klibc.h>
019 #include <hwcore/ioports.h> 020 #include <hwcore/ioports.h>
020 021
021 #include "x86_videomem.h" 022 #include "x86_videomem.h"
022 023
023 024
024 025
025 026
026 #define VIDEO 0xb8000 027 #define VIDEO 0xb8000
027 028
028 029
029 030
030 #define LINES 25 031 #define LINES 25
031 #define COLUMNS 80 032 #define COLUMNS 80
032 033
033 034
034 035
035 036
036 typedef struct { 037 typedef struct {
037 unsigned char character; 038 unsigned char character;
038 unsigned char attribute; 039 unsigned char attribute;
039 } __attribute__ ((packed)) x86_video_mem[LINES 040 } __attribute__ ((packed)) x86_video_mem[LINES*COLUMNS];
040 041
041 042
042 043
043 044
044 static volatile x86_video_mem *video = (volati 045 static volatile x86_video_mem *video = (volatile x86_video_mem*)VIDEO;
045 046
046 sos_ret_t sos_x86_videomem_setup(void) 047 sos_ret_t sos_x86_videomem_setup(void)
047 { 048 {
048 049
049 050
050 051
051 052
052 #define CRT_REG_INDEX 0x3d4 053 #define CRT_REG_INDEX 0x3d4
053 #define CRT_REG_DATA 0x3d5 054 #define CRT_REG_DATA 0x3d5
054 055
055 056
056 057
057 outb(0x0a, CRT_REG_INDEX); 058 outb(0x0a, CRT_REG_INDEX);
058 059
059 060
060 outb(1 << 5, CRT_REG_DATA); 061 outb(1 << 5, CRT_REG_DATA);
061 062
062 return SOS_OK; 063 return SOS_OK;
063 } 064 }
064 065
065 066
066 sos_ret_t sos_x86_videomem_cls(unsigned char a 067 sos_ret_t sos_x86_videomem_cls(unsigned char attribute)
067 { 068 {
068 069
069 int i; 070 int i;
070 for(i = 0 ; i < LINES*COLUMNS ; i++) 071 for(i = 0 ; i < LINES*COLUMNS ; i++)
071 { 072 {
072 (*video)[i].character = 0; 073 (*video)[i].character = 0;
073 (*video)[i].attribute = attribute; 074 (*video)[i].attribute = attribute;
074 } 075 }
075 076
076 return SOS_OK; 077 return SOS_OK;
077 } 078 }
078 079
079 080
080 sos_ret_t sos_x86_videomem_putstring(unsigned 081 sos_ret_t sos_x86_videomem_putstring(unsigned char row, unsigned char col,
081 unsigned 082 unsigned char attribute,
082 const cha 083 const char *str)
083 { 084 {
084 unsigned video_offs = row*COLUMNS + col; 085 unsigned video_offs = row*COLUMNS + col;
085 086
086 if (video_offs >= LINES*COLUMNS) 087 if (video_offs >= LINES*COLUMNS)
087 return -SOS_EINVAL; 088 return -SOS_EINVAL;
088 089
089 for ( ; str && *str && (video_offs < LINES*C 090 for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++)
090 { 091 {
091 (*video)[video_offs].character = (unsign 092 (*video)[video_offs].character = (unsigned char)*str;
092 (*video)[video_offs].attribute = attribu 093 (*video)[video_offs].attribute = attribute;
093 } 094 }
094 095
095 return SOS_OK; 096 return SOS_OK;
096 } 097 }
097 098
098 099
099 sos_ret_t sos_x86_videomem_putchar(unsigned ch 100 sos_ret_t sos_x86_videomem_putchar(unsigned char row, unsigned char col,
100 unsigned ch 101 unsigned char attribute,
101 unsigned ch 102 unsigned char c)
102 { 103 {
103 unsigned video_offs = row*COLUMNS + col; 104 unsigned video_offs = row*COLUMNS + col;
104 105
105 if (video_offs >= LINES*COLUMNS) 106 if (video_offs >= LINES*COLUMNS)
106 return -SOS_EINVAL; 107 return -SOS_EINVAL;
107 108
108 (*video)[video_offs].character = c; 109 (*video)[video_offs].character = c;
109 (*video)[video_offs].attribute = attribute; 110 (*video)[video_offs].attribute = attribute;
110 111
111 return SOS_OK; 112 return SOS_OK;
112 } 113 }
113 114
114 115
115 sos_ret_t sos_x86_videomem_printf(unsigned cha 116 sos_ret_t sos_x86_videomem_printf(unsigned char row, unsigned char col,
116 unsigned cha 117 unsigned char attribute,
117 const char * 118 const char *format, ...)
118 { 119 {
119 char buff[256]; 120 char buff[256];
120 va_list ap; 121 va_list ap;
121 122
122 va_start(ap, format); 123 va_start(ap, format);
123 vsnprintf(buff, sizeof(buff), format, ap); 124 vsnprintf(buff, sizeof(buff), format, ap);
124 va_end(ap); 125 va_end(ap);
125 126
126 return sos_x86_videomem_putstring(row, col, 127 return sos_x86_videomem_putstring(row, col, attribute, buff);
127 } 128 }