Skip to content

Commit

Permalink
SR/SRW: use short conditional jumps in x86 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
M-HT committed May 14, 2022
1 parent 1643594 commit d219ab8
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 108 deletions.
13 changes: 10 additions & 3 deletions SR-games/Albion/SR/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/Warcraft/SR-cd-gog/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/Warcraft/SR-cd/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
2 changes: 2 additions & 0 deletions SR-games/Warcraft/SR/build-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ rm *.sci
./compact_source.py
nasm -felf32 -O1 -w+orphan-labels -w-number-overflow -ix86/ war-asm.asm 2>a.a
./repair_short_jumps.py
nasm -felf32 -O1 -w+orphan-labels -w-number-overflow -ix86/ war-asm.asm 2>a.a
./repair_short_jumps.py
rm *.a
13 changes: 10 additions & 3 deletions SR-games/Warcraft/SR/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/X-Com - Terror from the Deep/SR1/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/X-Com - Terror from the Deep/SR2/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/X-Com - Ufo Defense/SR1/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/X-Com - Ufo Defense/SR2/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
13 changes: 10 additions & 3 deletions SR-games/X-Com - Ufo Defense/SR3/repair_short_jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
cLine = fIn.readline()
iLine = iLine + 1

if cLine.startswith("jmp short"):
if cLine.startswith("jmp short "):
# if line begins "jmp short" then remove "short" keyword
cLine = "jmp" + cLine[9:]
else:
# else insert "next" keyword after first word
iTemp = cLine.find(" ")
cLine = cLine[ : iTemp + 1] + "near" + cLine[iTemp : ]
cFirst = cLine[ : iTemp + 1]
cSecond = cLine[iTemp + 1 : ].lstrip()

if cFirst.startswith("j") and cSecond.startswith("short "):
# if line begins "j?? short" then replace "short" keyword with "near" keyword
cLine = cFirst + "near " + cSecond[6:]
else:
# else insert "near" keyword after first word
cLine = cFirst + "near " + cSecond

fOut.write(cLine)

Expand Down
9 changes: 6 additions & 3 deletions SR/SR_full_dos.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2016-2019 Roman Pauer
* Copyright (C) 2016-2022 Roman Pauer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -337,7 +337,7 @@ int SR_disassemble_offset_dos(unsigned int Entry, uint_fast32_t offset)
}

#ifdef DISPLAY_DISASSEMBLY
printf("loc_%X: %s\n", section[Entry].start + offset, ud_insn_asm(&ud_obj));
printf("loc_%X: %s\n", (unsigned int)(section[Entry].start + offset), ud_insn_asm(&ud_obj));
#endif


Expand Down Expand Up @@ -488,19 +488,22 @@ int SR_disassemble_offset_dos(unsigned int Entry, uint_fast32_t offset)
)
{
uint_fast32_t address;
int jumptype;

if (ud_obj.operand[0].size == 32)
{
address = ud_obj.operand[0].lval.sdword + (uint_fast32_t) ud_obj.pc;
jumptype = 0;
}
else
{
address = ud_obj.operand[0].lval.sbyte + (uint_fast32_t) ud_obj.pc;
jumptype = ((ud_obj.mnemonic == UD_Ijcxz) || (ud_obj.mnemonic == UD_Ijecxz) || (ud_obj.mnemonic == UD_Ijrcxz))?2:1;
}

SR_disassemble_add_address(Entry, address);

ret = SR_disassemble_convert_cjump(cResult, ((ud_obj.operand[0].size == 32)?" near":""), address, NULL);
ret = SR_disassemble_convert_cjump(cResult, ((jumptype == 0)?" near":((jumptype == 1)?" short":"")), address, NULL);

if (ret) return ret;

Expand Down
9 changes: 6 additions & 3 deletions SR/SR_full_win32.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2016-2019 Roman Pauer
* Copyright (C) 2016-2022 Roman Pauer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -309,7 +309,7 @@ int SR_disassemble_offset_win32(unsigned int Entry, uint_fast32_t offset)
#endif

#ifdef DISPLAY_DISASSEMBLY
printf("loc_%X: %s\n", section[Entry].start + offset, ud_insn_asm(&ud_obj));
printf("loc_%X: %s\n", (unsigned int)(section[Entry].start + offset), ud_insn_asm(&ud_obj));
#endif

fixup2 = NULL;
Expand Down Expand Up @@ -598,16 +598,19 @@ int SR_disassemble_offset_win32(unsigned int Entry, uint_fast32_t offset)
{
uint_fast32_t address;
int backward;
int jumptype;

if (ud_obj.operand[0].size == 32)
{
backward = (ud_obj.operand[0].lval.sdword < 0)?1:0;
address = ud_obj.operand[0].lval.sdword + (uint_fast32_t) ud_obj.pc;
jumptype = 0;
}
else
{
backward = (ud_obj.operand[0].lval.sbyte < 0)?1:0;
address = ud_obj.operand[0].lval.sbyte + (uint_fast32_t) ud_obj.pc;
jumptype = ((ud_obj.mnemonic == UD_Ijcxz) || (ud_obj.mnemonic == UD_Ijecxz) || (ud_obj.mnemonic == UD_Ijrcxz))?2:1;
}

extrn = SR_disassemble_find_proc(Entry, address);
Expand All @@ -626,7 +629,7 @@ int SR_disassemble_offset_win32(unsigned int Entry, uint_fast32_t offset)
strcpy(cResult, "ACTION_CONDITIONAL_JUMP_FORWARD\n");
}

ret = SR_disassemble_convert_cjump(&(cResult[strlen(cResult)]), ((ud_obj.operand[0].size == 32)?" near":""), address, extrn);
ret = SR_disassemble_convert_cjump(&(cResult[strlen(cResult)]), ((jumptype == 0)?" near":((jumptype == 1)?" short":"")), address, extrn);

if (ret) return ret;

Expand Down
2 changes: 0 additions & 2 deletions SRW-games/Battle Isle 3/SRW-wc_figtr/build-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ cp x86/*.sci ./
./SRW.exe WC_FIGTR.DLL WC_FIGTR.asm >a.a 2>b.a
rm *.sci
./compact_source.py
nasm -felf32 -O1 -w+orphan-labels -w-number-overflow -ix86/ WC_FIGTR.asm 2>a.a
./repair_short_jumps.py
rm *.a
rm WC_FIGTR.def
64 changes: 0 additions & 64 deletions SRW-games/Battle Isle 3/SRW-wc_figtr/repair_short_jumps.py

This file was deleted.

Loading

0 comments on commit d219ab8

Please sign in to comment.