Bug: Cast to i16 was failing, casted unsigned char to sbyte before promoting
This commit is contained in:
parent
f4d6835694
commit
2a92f04836
11
decode.c
11
decode.c
@ -55,7 +55,7 @@ char* memory[65536];
|
|||||||
/// Get Effective Address Calculation Registers
|
/// Get Effective Address Calculation Registers
|
||||||
char* get_eac_registers(char rm)
|
char* get_eac_registers(char rm)
|
||||||
{
|
{
|
||||||
char *reg_name;
|
char* reg_name;
|
||||||
switch (rm)
|
switch (rm)
|
||||||
{
|
{
|
||||||
case 0b000:
|
case 0b000:
|
||||||
@ -89,14 +89,15 @@ char* get_eac_registers(char rm)
|
|||||||
return reg_name;
|
return reg_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char *reg_name(Register reg, char wide)
|
static inline char* reg_name(Register reg, char wide)
|
||||||
{
|
{
|
||||||
return wide == 1 ? reg.fullname : reg.bytename;
|
return wide == 1 ? reg.fullname : reg.bytename;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline i16 get_data(unsigned char *buf, char wide)
|
static inline i16 get_data(unsigned char* buf, char wide)
|
||||||
{
|
{
|
||||||
return wide == 1 ? (i16)buf[1] << 8 | buf[0] : buf[0];
|
// Cast buf[0] to sbyte if not the conversion to i16 won't detect signedness
|
||||||
|
return wide == 1 ? (i16)buf[1] << 8 | buf[0] : (sbyte)buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
@ -153,7 +154,7 @@ int main(int argc, char** argv)
|
|||||||
if (bytes_to_read > 0)
|
if (bytes_to_read > 0)
|
||||||
{
|
{
|
||||||
i16 disp = get_data(buf, bytes_to_read - 1);
|
i16 disp = get_data(buf, bytes_to_read - 1);
|
||||||
if (disp > 0) sprintf(disp_buf, " %s %d", disp >= 0 ? "+" : "-", abs(disp));
|
sprintf(disp_buf, " %s %hd", disp >= 0 ? "+" : "-", abs(disp));
|
||||||
}
|
}
|
||||||
Register reg = registers[reg_idx];
|
Register reg = registers[reg_idx];
|
||||||
if (d) printf("mov %s, [%s%s] ;1", reg_name(reg, w), eac_name, disp_buf);
|
if (d) printf("mov %s, [%s%s] ;1", reg_name(reg, w), eac_name, disp_buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user