-
Notifications
You must be signed in to change notification settings - Fork 6
/
hexchar.cpp
62 lines (57 loc) · 1.87 KB
/
hexchar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* $Id$
* MegaZeux
*
* Copyright (C) 1996 Greg Janson
* Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// Procedures to write hex strs onscreen
#include "hexchar.h"
#include "graphics.h"
#include <stdlib.h>
#include "string.h"
#define num2hex(x) ((x)>9 ? 87+(x) : 48+(x))
//DOES NOT PRESERVE MOUSE CURSOR
void write_hex_byte(unsigned char byte,unsigned char color,int x,int y,
unsigned int segment) {
int t1,t2;
t1=(byte&240)>>4;
t1=num2hex(t1);
t2=byte&15;
t2=num2hex(t2);
draw_char(t1,color,x,y,segment);
draw_char(t2,color,x+1,y,segment);
}
//Set rightalign to print the rightmost char at xy and proceed to the left
//minlen is the minimum length to print. Pad with 0.
//DOES NOT PRESERVE MOUSE CURSOR
void write_number(int number,unsigned char color,int x,int y,
unsigned int segment,char minlen,char rightalign,int base) {
char temp[7];
int t1,t2;
itoa(number,temp,base);
if(rightalign) {
t1=str_len(temp);
if(minlen>t1) t1=minlen;
x-=t1-1;
}
if((t2=str_len(temp))<minlen) {
t2=minlen-t2;
for(t1=0;t1<t2;t1++)
draw_char('0',color,x++,y,segment);
}
write_string(temp,x,y,color,segment);
}