aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2022-04-02 01:14:57 +0200
committerJavier <dev.git@javispedro.com>2022-04-02 01:14:57 +0200
commit3e39df4a4185f947d1af564aca265c0f6b51c9ec (patch)
tree453b4c1cb56cf029ebe96a02f91075912e64d0eb /utils.h
parenta816d1a09b1045fb5c155ac73f3231fcf9d93180 (diff)
downloadvbados-3e39df4a4185f947d1af564aca265c0f6b51c9ec.tar.gz
vbados-3e39df4a4185f947d1af564aca265c0f6b51c9ec.zip
implement graphic cursor for CGA modes, wheel mouse detection, int2f hooking, simplify w16 driver
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/utils.h b/utils.h
index 4740644..39260c4 100644
--- a/utils.h
+++ b/utils.h
@@ -27,7 +27,17 @@ static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax);
"div bx" /* ax = dx:ax / srcmax */\
__parm [ax] [bx] [cx] \
__value [ax] \
- __modify [ax cx dx]
+ __modify [ax dx]
+
+/** Map x linearly from range [0, srcmax] to [0, dstmax].
+ * Equivalent of (x * dstmax) / srcmax but with 32-bit signed precision. */
+static int scalei(int x, int srcmax, int dstmax);
+#pragma aux scalei = \
+ "imul cx" /* dx:ax = x * dstmax */ \
+ "idiv bx" /* ax = dx:ax / srcmax */ \
+ __parm [ax] [bx] [cx] \
+ __value [ax] \
+ __modify [ax dx]
/** Map x linearly from range [0, srcmax] to [0, dstmax].
* Equivalent of (x * dstmax) / srcmax but with 32-bit signed precision.
@@ -36,13 +46,18 @@ static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax);
static int scalei_rem(int x, int srcmax, int dstmax, short *rem);
#pragma aux scalei_rem = \
"imul cx" /* dx:ax = x * dstmax */ \
+ "mov cx, [si]" /* cx = rem */ \
+ "test cx, cx" \
+ "setns cl" /* cl = 1 if rem positive, 0 if negative */ \
+ "movzx cx, cl" \
+ "dec cx" /* cx = 0 if rem positive, -1 if negative */ \
"add ax, [si]" /* ax += *rem */ \
- "adc dx, 0" /* dx += 1 if carry */ \
+ "adc dx, cx" /* dx += 1 if carry and rem positive, 0 if carry and rem negative (aka. signed addition) */ \
"idiv bx" /* ax = dx:ax / srcmax, dx = new remainder */ \
"mov [si], dx" /* store the new remainder */ \
__parm [ax] [bx] [cx] [si] \
__value [ax] \
- __modify [ax cx dx]
+ __modify [ax cx dx si]
static void bzero(void __far *buf, unsigned int size);
#pragma aux bzero = \