Skip to content

Demo Improvements #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions resources/bk2_demo_to_input_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python
import io
import os
import sys

if len(sys.argv) != 3:
print("bk2_demo_to_input_log.py <asm_file> <output_log_file>")
sys.exit()
else:
asm_name = sys.argv[1]
output_name = sys.argv[2]

asm_file = io.open(os.path.join(os.path.dirname(os.path.realpath(__file__)), asm_name), "r")
asm_lines = asm_file.readlines()
asm_file.close()

output_file = io.open(os.path.join(os.path.dirname(os.path.realpath(__file__)), output_name), "w", newline='\n')
output_file.write("\n; ---------------")
output_file.write("\n; Log Export")
output_file.write("\n; (autogenerated)")
output_file.write("\n; ---------------\n\n")

demo_input_started = False
for line in asm_lines:
if line.startswith("DemoInputInstructionLists"):
demo_input_started = True
if demo_input_started:
if len(line) < 20 or not line.startswith(" dw $"):
output_file.write(line)
else:
count = int(line[8:12], 16)
keys = int(line[15:19], 16)
output_line = bytearray("|..|............|\n", "ascii")
if keys >= 0x8000:
keys -= 0x8000
output_line[11] = ord('B')
if keys >= 0x4000:
keys -= 0x4000
output_line[10] = ord('Y')
if keys >= 0x2000:
keys -= 0x2000
output_line[8] = ord('s')
if keys >= 0x1000:
keys -= 0x1000
output_line[9] = ord('S')
if keys >= 0x800:
keys -= 0x800
output_line[4] = ord('U')
if keys >= 0x400:
keys -= 0x400
output_line[5] = ord('D')
if keys >= 0x200:
keys -= 0x200
output_line[6] = ord('L')
if keys >= 0x100:
keys -= 0x100
output_line[7] = ord('R')
if keys >= 0x80:
keys -= 0x80
output_line[13] = ord('A')
if keys >= 0x40:
keys -= 0x40
output_line[12] = ord('X')
if keys >= 0x20:
keys -= 0x20
output_line[14] = ord('l')
if keys >= 0x10:
keys -= 0x10
output_line[15] = ord('r')
finished_line = output_line.decode()
while count > 0:
output_file.write(finished_line)
count -= 1

output_file.close()

70 changes: 70 additions & 0 deletions resources/bk2_input_log_to_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
import io
import os
import sys

if len(sys.argv) != 3:
print("bk2_input_log_to_demo.py <input_log_file> <demo_output_file>")
sys.exit()
else:
input_name = sys.argv[1]
demo_name = sys.argv[2]

input_file = io.open(os.path.join(os.path.dirname(os.path.realpath(__file__)), input_name), "r")
input_lines = input_file.readlines()
input_file.close()

demo_file = io.open(os.path.join(os.path.dirname(os.path.realpath(__file__)), demo_name), "w", newline='\n')
demo_file.write("\n; ---------------")
demo_file.write("\n; Demo Export")
demo_file.write("\n; (autogenerated)")
demo_file.write("\n; ---------------\n\n")

current_input = 0
previous_line = None
previous_count = 0
for line in input_lines:
if len(line) < 17 or '|' != line[0] or '|' != line[3] or '|' != line[16]:
if previous_count > 0:
demo_file.write(f' dw ${previous_count:04X}, ${current_input:04X} ; {previous_line[4:16]}\n')
previous_line = None
previous_count = 0
demo_file.write(line)
else:
if previous_count > 0 and previous_line != line:
demo_file.write(f' dw ${previous_count:04X}, ${current_input:04X} ; {previous_line[4:16]}\n')
previous_line = None
previous_count = 0
if previous_line is None:
previous_line = line
current_input = 0
if 'U' == line[4]:
current_input += 0x800
if 'D' == line[5]:
current_input += 0x400
if 'L' == line[6]:
current_input += 0x200
if 'R' == line[7]:
current_input += 0x100
if 's' == line[8]:
current_input += 0x2000
if 'S' == line[9]:
current_input += 0x1000
if 'Y' == line[10]:
current_input += 0x4000
if 'B' == line[11]:
current_input += 0x8000
if 'X' == line[12]:
current_input += 0x40
if 'A' == line[13]:
current_input += 0x80
if 'l' == line[14]:
current_input += 0x20
if 'r' == line[15]:
current_input += 0x10
previous_count = previous_count + 1
if previous_count > 0:
demo_file.write(f' dw ${previous_count:04X}, ${current_input:04X} ; {previous_line[4:16]}\n\n')

demo_file.close()

17 changes: 17 additions & 0 deletions src/defines.asm
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
!DEBUG_MODE = $05D1
!CACHED_RANDOM_NUMBER = $05E5
!DISABLE_SOUNDS = $05F5
!DISABLE_MINIMAP = $05F7
!SOUND_TIMER = $0686
!LOAD_STATION_INDEX = $078B
!DOOR_ID = $078D
Expand All @@ -511,6 +512,8 @@
!LAYER1_Y = $0915
!LAYER2_X = $0917
!LAYER2_Y = $0919
!BG1_X_OFFSET = $091D
!BG1_Y_OFFSET = $091F
!BG2_X_SCROLL = $0921
!BG2_Y_SCROLL = $0923
!SAMUS_DOOR_SUBSPEED = $092B
Expand Down Expand Up @@ -538,6 +541,7 @@
!IGT_SECONDS = $09DC
!IGT_MINUTES = $09DE
!IGT_HOURS = $09E0
!SAMUS_MOONWALK = $09E4
!PAL_DEBUG_MOVEMENT = $09E6
!SAMUS_AUTO_CANCEL = $0A04
!SAMUS_LAST_HP = $0A06
Expand All @@ -557,12 +561,20 @@
!SAMUS_MOVEMENT_HANDLER = $0A44
!SAMUS_SUBUNIT_ENERGY = $0A4C
!SAMUS_NORMAL_MOVEMENT_HANDLER = $0A58
!SAMUS_DRAW_HANDLER = $0A5C
!SAMUS_CONTROLLER_HANDLER = $0A60
!SAMUS_SHINE_TIMER = $0A68
!SAMUS_HEALTH_WARNING = $0A6A
!SAMUS_CONTACT_DAMAGE_INDEX = $0A6E
!SAMUS_WATER_PHYSICS = $0A70 ; Not used in vanilla
!SAMUS_HYPER_BEAM = $0A76
!DEMO_PREINSTRUCTION_POINTER = $0A7A
!DEMO_INSTRUCTION_TIMER = $0A7C
!DEMO_INSTRUCTION_POINTER = $0A7E
!DEMO_CONTROLLER_PRI = $0A84
!DEMO_INPUT_ENABLED = $0A88
!DEMO_PREVIOUS_CONTROLLER_PRI = $0A8C
!DEMO_PREVIOUS_CONTROLLER_PRI_NEW = $0A8E
!SAMUS_ANIMATION_FRAME_TIMER = $0A94
!SAMUS_ANIMATION_FRAME = $0A96
!SAMUS_LAVA_DAMAGE_SUITS = $0A98 ; Not used in vanilla
Expand Down Expand Up @@ -604,6 +616,8 @@
!SAMUS_BOMB_SPREAD_CHARGE_TIMER = $0CD4
!SAMUS_POWER_BOMB_X = $0CE2
!SAMUS_POWER_BOMB_Y = $0CE4
!PREVIOUS_CONTROLLER_PRI = $0DFE
!PREVIOUS_CONTROLLER_PRI_NEW = $0E00
!ELEVATOR_PROPERTIES = $0E16
!ELEVATOR_STATUS = $0E18
!HEALTH_BOMB_FLAG = $0E1A
Expand Down Expand Up @@ -631,6 +645,9 @@
!ENEMY_PROJ_RADIUS = $1BB3
!ENEMY_PROJ_PROPERTIES = $1BD7
!MESSAGE_BOX_INDEX = $1C1F
!DEMO_TIMER = $1F53
!DEMO_CURRENT_SET = $1F55
!DEMO_CURRENT_SCENE = $1F57

!PLM_DELETE = $AAE3

Expand Down
Loading
Loading