Skip to content

Commit 755e5f5

Browse files
author
unknown
committed
Updated screen code. Added puthex and putdec functions and wrapped zero case for putdec in unlikely macro since we do not expect it to happen often (statistically anyway)
1 parent b40f755 commit 755e5f5

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

‎scrn.c‎

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ void putch(unsigned char c)
8282
unsigned short*where;
8383
unsignedatt=attrib << 8;
8484

85-
/* Handle a backspace, by moving the cursor back one space */
85+
/*Backspace Code*/
8686
if(c==0x08)
8787
{
8888
if(csr_x!=0) csr_x--;
8989
}
90-
/* Handles a tab by incrementing the cursor's x, but only
91-
* to a point that will make it divisible by 8 */
90+
9291
elseif(c==0x09)
9392
{
9493
csr_x= (csr_x+8) & ~(8-1);
@@ -132,6 +131,7 @@ void putch(unsigned char c)
132131
}
133132

134133
/* Uses the above routine to output a string... */
134+
135135
voidputs(unsigned char*text)
136136
{
137137
inti;
@@ -142,15 +142,80 @@ void puts(unsigned char *text)
142142
}
143143
}
144144

145-
/* Sets the forecolor and backcolor that we will use */
145+
voidputdec(unsigned intn)
146+
{
147+
/* Statistically, we do NOT expect this to be 0 */
148+
if(__builtin_expect((n<1), 0))
149+
{
150+
putch('0');
151+
return;
152+
}
153+
else
154+
{
155+
charc[32];
156+
inti=0;
157+
while (n>0)
158+
159+
{
160+
c[i] ='0'+ (n%10);
161+
n /= 10;
162+
i++;
163+
}
164+
c[i] =0;
165+
166+
charc2[i+1];
167+
c2[i--] =0;
168+
intj=0;
169+
while(i >= 0)
170+
{
171+
c2[i--] =c[j++];
172+
}
173+
puts(c2);
174+
}
175+
176+
}
177+
178+
voidputhex(unsigned intn)
179+
{
180+
inttmp;
181+
182+
puts("0x");
183+
inti;
184+
/* Chop our 32 bit type into groups of 4 and convert */
185+
for (i=28; i>0; i-=4)
186+
{
187+
tmp= (n >> i) &0xF;
188+
189+
if (tmp >= 0xA)
190+
{
191+
putch (tmp-0xA+'a' );
192+
}
193+
else
194+
{
195+
putch( tmp+'0' );
196+
}
197+
}
198+
199+
tmp=n&0xF;
200+
if (tmp >= 0xA)
201+
{
202+
putch (tmp-0xA+'a');
203+
}
204+
else
205+
{
206+
putch (tmp+'0');
207+
}
208+
}
209+
210+
146211
voidsettextcolor(unsigned charforecolor, unsigned charbackcolor)
147212
{
148213
/* Top 4 bytes are the background, bottom 4 bytes
149214
* are the foreground color */
150215
attrib= (backcolor << 4) | (forecolor&0x0F);
151216
}
152217

153-
/* Sets our text-mode VGA pointer, then clears the screen for us */
218+
154219
voidinit_video(void)
155220
{
156221
textmemptr= (unsigned short*)0xB8000;

0 commit comments

Comments
(0)