From b4ca9174fde3b4ff1bc8f79513f2d7238b236716 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 30 Apr 2018 21:35:20 -0700 Subject: [PATCH] SCP: Add formatting support for signed t_value (t_svalue). PV_LEFTSIGN - left justified signed value PV_RCOMMASIGN - right, space filled, Comma separated every 3 treat as signed --- scp.c | 12 ++++++++++++ sim_defs.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/scp.c b/scp.c index 7f2b84a2..f27f4293 100644 --- a/scp.c +++ b/scp.c @@ -9782,9 +9782,15 @@ t_stat sprint_val (char *buffer, t_value val, uint32 radix, { #define MAX_WIDTH ((int) ((CHAR_BIT * sizeof (t_value) * 4 + 3)/3)) t_value owtest, wtest; +t_bool negative = FALSE; int32 d, digit, ndigits, commas = 0; char dbuf[MAX_WIDTH + 1]; +if (((format == PV_LEFTSIGN) || (format == PV_RCOMMASIGN)) && + (0 > (t_svalue)val)) { + val = (t_value)(-((t_svalue)val)); + negative = TRUE; + } for (d = 0; d < MAX_WIDTH; d++) dbuf[d] = (format == PV_RZRO)? '0': ' '; dbuf[MAX_WIDTH] = 0; @@ -9795,11 +9801,15 @@ do { val = val / radix; dbuf[d] = (char)((digit <= 9)? '0' + digit: 'A' + (digit - 10)); } while ((d > 0) && (val != 0)); +if (negative && (format == PV_LEFTSIGN)) + dbuf[--d] = '-'; switch (format) { case PV_LEFT: + case PV_LEFTSIGN: break; case PV_RCOMMA: + case PV_RCOMMASIGN: for (digit = 0; digit < MAX_WIDTH; digit++) if (dbuf[digit] != ' ') break; @@ -9810,6 +9820,8 @@ switch (format) { for (digit=1; digit<=commas; digit++) dbuf[MAX_WIDTH - (digit * 4)] = ','; d = d - commas; + if (negative && (format == PV_RCOMMASIGN)) + dbuf[--d] = '-'; if (width > MAX_WIDTH) { if (!buffer) return width; diff --git a/sim_defs.h b/sim_defs.h index cd04481c..e8061edf 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -418,6 +418,8 @@ typedef uint32 t_addr; #define PV_RSPC 1 /* right, space fill */ #define PV_RCOMMA 2 /* right, space fill. Comma separate every 3 */ #define PV_LEFT 3 /* left justify */ +#define PV_RCOMMASIGN 6 /* right, space fill. Comma separate every 3 treat as signed */ +#define PV_LEFTSIGN 7 /* left justify treat as signed */ /* Default timing parameters */