Skip to content
Snippets Groups Projects
Commit f75149aa authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

ctoi() implemented: character to integer

parent 1dd59a11
Branches
No related tags found
No related merge requests found
0
abcdef 00
012345 ffffffff
pqrstu 7C2
098765
...@@ -57,6 +57,7 @@ int iostat(void); // returns integer with status at lsb ...@@ -57,6 +57,7 @@ int iostat(void); // returns integer with status at lsb
void ioctl(int); // write lsb in control register void ioctl(int); // write lsb in control register
char getc(void); // returns char in queue, decrements nrx char getc(void); // returns char in queue, decrements nrx
int Putc(char); // inserts char in queue, decrements ntx int Putc(char); // inserts char in queue, decrements ntx
int ctoi(char); // converts a character to an integer
void initUd(); void initUd();
...@@ -67,7 +68,7 @@ int main(){ ...@@ -67,7 +68,7 @@ int main(){
int i; int i;
volatile int state; // tell GCC not to optimize away code volatile int state; // tell GCC not to optimize away code
volatile Tstatus status; volatile Tstatus status;
volatile char c, last; volatile char c;
uart = (void *)IO_UART_ADDR; // bottom of UART address range uart = (void *)IO_UART_ADDR; // bottom of UART address range
Tcontrol ctrl; Tcontrol ctrl;
...@@ -80,23 +81,23 @@ int main(){ ...@@ -80,23 +81,23 @@ int main(){
initUd(); initUd();
//uart->d.tx = 'a';
//print(lol);
/*while(c!='\n'){
/*to_stdout('X');
to_stdout('\n');
//print(lol);
c = getc(); c = getc();
}*/ while(c != '\0') {
last = '0';
while((c=getc()) != '\0'){
if(c != EOF) { if(c != EOF) {
while(!Putc(c)); // Wait till there's space on queue int n = 0;
while(c != '\n' && c != '\0') {
int h = ctoi(c);
if(h != EOF) {
n = n*16 + h;
}
c = getc();
} }
print(n);
//while(!Putc(c)); // Wait till there's space on queue
} }
Putc(c); // Sends '\0' c = getc();
}
Putc(c); // Sends EOF
return 0; return 0;
} }
...@@ -124,9 +125,6 @@ char getc(){ ...@@ -124,9 +125,6 @@ char getc(){
//print(2); //print(2);
c = EOF; c = EOF;
} }
//print((int)c);
// to_stdout(c);
// to_stdout('\n');
return c; return c;
} }
...@@ -157,3 +155,22 @@ int proberx(){ ...@@ -157,3 +155,22 @@ int proberx(){
int probetx(){ int probetx(){
return Ud.ntx; return Ud.ntx;
} }
int ctoi(char c) {
// If it's a number
if(c >=0x30 && c < 0x3a) {
return ((int) c) - 0x30;
}
// If it's an uppercase letter
if(c >= 0x41 && c < 0x47) {
return ((int) c) - 0x37; // 0x40 - 0xa
}
// If it's a lowercase letter
if(c >= 0x61 && c < 0x67) {
return ((int) c) - 0x57; //0x60 - 0xa
}
return EOF;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment