aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO7
-rw-r--r--hcalc.141
-rw-r--r--hcalc.rst43
-rw-r--r--input.c33
4 files changed, 77 insertions, 47 deletions
diff --git a/TODO b/TODO
index 443bb43..1d69241 100644
--- a/TODO
+++ b/TODO
@@ -1,13 +1,6 @@
-- On startup, the value is read from the config file... but it can't
- be used as an argument to a binary op (only a unary one) if it's
- more than one digit. Except sometimes it can. Investigate and fix.
- Cleaner way of switching window sizes at runtime.
-- Better handling of divide-by-zero (why an f? why not e for error?)
- Reindent the code (it's a confusing mess of tabs and spaces), and
reformat it to my personal style.
-- Make it play nicer with tiling WMs. If possible, anyway: echinus
- doesn't try to tile it (which is correct, since it won't resize).
- Try some others. Low priority.
- Long range possibility: rewrite the display/input stuff to use SDL2,
so we can scale arbitrarily. Probably this would mean it'd work on
diff --git a/hcalc.1 b/hcalc.1
index 30a6e6c..a606652 100644
--- a/hcalc.1
+++ b/hcalc.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "HCALC" 1 "2024-01-09" "1.2u1" "Urchlay's Misc Stuff"
+.TH "HCALC" 1 "2024-01-10" "1.2u1" "Urchlay's Misc Stuff"
.SH NAME
hcalc \- graphical hex calculator
.\" RST source for hcalc(1) man page. Convert with:
@@ -107,6 +107,10 @@ The user interface mimics a pocket calculator, so it\(aqs made of
buttons. Each button can be pressed either by clicking on it with the
mouse, or pressing its keystroke (given in \fBbold\fP). A few buttons
have multiple functions, depending on which mouse button is used.
+.sp
+The descriptions below assume a right\-handed mouse, and refer to mouse
+button 1 as "left" and button 3 as "right". If your mouse is set up
+left\-handed, reverse them.
.INDENT 0.0
.TP
.B \fI0\fP to \fI9\fP, \fIA\fP to \fIF\fP (\fB0\-9\fP, \fBa\-f\fP)
@@ -130,14 +134,16 @@ Finish the calculation and display the result.
Invert sign.
.TP
.B \fIINV\fP (\fB~\fP)
-Unary NOT; invert the bits in the current number.
+Unary NOT, aka 1\(aqs complement; invert the bits in the current number.
+For 32\-bit two\(aqs complement, right\-click or use \fB@\fP on the keyboard.
+Integer operation; truncates digits after the decimal point.
.TP
.B \fIOR\fP \fIAND\fP \fIXOR\fP (\fB&\fP \fB|\fP \fB^\fP)
-Boolean operations.
+Boolean operations. Integer operations; truncates digits after the decimal point.
.TP
.B \fIDEC\fP \fIHEX\fP \fIOCT\fP \fIBIN\fP (\fBD\fP \fBH\fP \fBO\fP \fBB\fP or \fBF1\fP to \fBF4\fP)
Change the number base. The number being displayed will be converted
-to the new base.
+to the new base. Truncates digits after the decimal point.
.TP
.B \fIDEL\fP (\fBBackspace\fP or \fBDelete\fP)
Delete the last digit entered. Deleting the last digit results in 0.
@@ -146,8 +152,9 @@ Delete the last digit entered. Deleting the last digit results in 0.
Store to memory (like \fIM\fP on most calculators); recall memory (like \fIMR\fP);
add current value to memory (like \fIM+\fP).
.TP
-.B \fI<<*\fP \fI>>\fP (\fB<\fP \fB>\fP)
+.B \fI<<\fP \fI>>\fP (\fB<\fP \fB>\fP)
Bit shift by one position, left or right.
+Integer operation; truncates digits after the decimal point.
.TP
.B \fISHF\fP (\fBS\fP)
Shift left/right by some number of bits (binary
@@ -155,6 +162,7 @@ operation, like addition). Shifts left for positive
numbers and right for negative. This is less confusing
than it sounds: 1 shifted left once is 2, \-1 shifted right
once in \-2.
+Integer operation; truncates digits after the decimal point.
.TP
.B \fICE\fP (\fBu\fP)
Clears the number being entered, same as backspacing over it,
@@ -166,22 +174,23 @@ exits \fBhcalc\fP (use \fBQ\fP or \fB^Q\fP to quit from the keyboard).
.UNINDENT
.SH MOUSE
.sp
-Mouse operation is simple: for the most part, just click on the
+Mouse operation is simple: for the most part, just left\-click on the
buttons to press them.
.sp
There\(aqs no \fI%\fP button for the modulus operator, but you can
-right\-click on the \fI÷\fP (division) key.
+right\-click on the \fI÷\fP (division) key. Also, right\-click on
+the \fIINV\fP key for two\(aqs complement.
+.sp
+Right\-clicking on the \fICLR\fP key exits \fBhcalc\fP\&.
.sp
-Right\-clicking (or any button other than 1) on the \fICLR\fP key exits
-\fBhcalc\fP\&.
+For the numeric display, a left\-click copies the number to the X
+selection buffer. Right\-click pastes from X, but beware: pasting
+anything but a number in the current base might have unexpected
+effects, because all pasted characters are treated as keystrokes (so,
+e.g. pasting a capital Q quits the application). This can be useful,
+e.g. if you paste "2+2=", \fBhcalc\fP will display "4".
.sp
-For the numeric display, clicking button 1 (usually the left one)
-copies the number to the X selection buffer. Clicking any other
-button pastes from X, but beware: pasting anything but a number in
-the current base might have unexpected effects, because all pasted
-characters are treated as keystrokes (so, e.g. pasting a capital Q
-quits the application). This can be useful, e.g. if you paste "2+2=",
-\fBhcalc\fP will display "4".
+A center\-click (button 2) anywhere in the \fBhcalc\fP window also pastes.
.SH KEYBOARD
.sp
These keys don\(aqt have calculator buttons.
diff --git a/hcalc.rst b/hcalc.rst
index 314944e..7611248 100644
--- a/hcalc.rst
+++ b/hcalc.rst
@@ -95,6 +95,10 @@ buttons. Each button can be pressed either by clicking on it with the
mouse, or pressing its keystroke (given in **bold**). A few buttons
have multiple functions, depending on which mouse button is used.
+The descriptions below assume a right-handed mouse, and refer to mouse
+button 1 as "left" and button 3 as "right". If your mouse is set up
+left-handed, reverse them.
+
*0* to *9*, *A* to *F* (**0-9**, **a-f**)
Digits. Lowercase only for the hex digits. Entering digits
larger than the current number base is impossible (e.g. hex digits
@@ -116,14 +120,16 @@ have multiple functions, depending on which mouse button is used.
Invert sign.
*INV* (**~**)
- Unary NOT; invert the bits in the current number.
+ Unary NOT, aka 1's complement; invert the bits in the current number.
+ For 32-bit two's complement, right-click or use **@** on the keyboard.
+ Integer operation; truncates digits after the decimal point.
*OR* *AND* *XOR* (**&** **|** **^**)
- Boolean operations.
+ Boolean operations. Integer operations; truncates digits after the decimal point.
*DEC* *HEX* *OCT* *BIN* (**D** **H** **O** **B** or **F1** to **F4**)
Change the number base. The number being displayed will be converted
- to the new base.
+ to the new base. Truncates digits after the decimal point.
*DEL* (**Backspace** or **Delete**)
Delete the last digit entered. Deleting the last digit results in 0.
@@ -132,8 +138,9 @@ have multiple functions, depending on which mouse button is used.
Store to memory (like *M* on most calculators); recall memory (like *MR*);
add current value to memory (like *M+*).
-*<<** *>>* (**<** **>**)
+*<<* *>>* (**<** **>**)
Bit shift by one position, left or right.
+ Integer operation; truncates digits after the decimal point.
*SHF* (**S**)
Shift left/right by some number of bits (binary
@@ -141,6 +148,7 @@ have multiple functions, depending on which mouse button is used.
numbers and right for negative. This is less confusing
than it sounds: 1 shifted left once is 2, -1 shifted right
once in -2.
+ Integer operation; truncates digits after the decimal point.
*CE* (**u**)
Clears the number being entered, same as backspacing over it,
@@ -153,22 +161,23 @@ have multiple functions, depending on which mouse button is used.
MOUSE
=====
-Mouse operation is simple: for the most part, just click on the
+Mouse operation is simple: for the most part, just left-click on the
buttons to press them.
There's no *%* button for the modulus operator, but you can
-right-click on the *÷* (division) key.
-
-Right-clicking (or any button other than 1) on the *CLR* key exits
-**hcalc**.
-
-For the numeric display, clicking button 1 (usually the left one)
-copies the number to the X selection buffer. Clicking any other
-button pastes from X, but beware: pasting anything but a number in
-the current base might have unexpected effects, because all pasted
-characters are treated as keystrokes (so, e.g. pasting a capital Q
-quits the application). This can be useful, e.g. if you paste "2+2=",
-**hcalc** will display "4".
+right-click on the *÷* (division) key. Also, right-click on
+the *INV* key for two's complement.
+
+Right-clicking on the *CLR* key exits **hcalc**.
+
+For the numeric display, a left-click copies the number to the X
+selection buffer. Right-click pastes from X, but beware: pasting
+anything but a number in the current base might have unexpected
+effects, because all pasted characters are treated as keystrokes (so,
+e.g. pasting a capital Q quits the application). This can be useful,
+e.g. if you paste "2+2=", **hcalc** will display "4".
+
+A center-click (button 2) anywhere in the **hcalc** window also pastes.
KEYBOARD
========
diff --git a/input.c b/input.c
index 62ad271..47a6f59 100644
--- a/input.c
+++ b/input.c
@@ -403,6 +403,16 @@ key(char c)
show_value();
break;
+ case '@': /* Two's complement */
+ end_number();
+ {
+ unsigned int i = ((unsigned int)value) & 0xffffffff;
+ value = ~i + 1;
+ }
+ saved = value;
+ show_value();
+ break;
+
case '<': /* SHL by one bit only */
/* Modified by Keith Meehl to fix bit shift bug*/
end_number();
@@ -525,6 +535,13 @@ complete_paste(unsigned char *s, int n)
void
button(int b, int x, int y)
{
+ char k;
+
+ if(b == 2) {
+ paste();
+ return;
+ }
+
x = (x-2)/(24 * scale_factor);
if (x < 0) x = 0;
if (x > 4) x = 4;
@@ -532,17 +549,19 @@ button(int b, int x, int y)
if (y < 0) y = 0;
if (y > 8) y = 8;
- if (bmap[y][x] == 27 && b == 3)
+ k = bmap[y][x];
+
+ if (k == 27 && b == 3)
exit(0);
- if (bmap[y][x] == 'P' && b == 1)
+ if (k == 'P' && b == 1)
copy();
- if (bmap[y][x] == 'P' && b != 1)
+ else if (k == 'P' && b != 1)
paste();
-
- if(bmap[y][x] == '/' && b != 1)
+ else if(k == '/' && b != 1)
key('%');
+ else if(k == '~' && b != 1)
+ key('@');
else
- key(bmap[y][x]);
- /* printf("bmap[%i][%i] and b=%i\n", y, x, b); */
+ key(k);
}