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