From d9bd41c68acb6f1499cece2312eb309ad13c404c Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 23 Jun 2022 18:13:07 +1000 Subject: [PATCH] More analysis about how the microcode tables work --- disasm/star_blazer.asm.patch | 72 +++++++++++++++---- disasm/star_blazer.txt | 132 ++++++++++++++++++++++++++++++----- 2 files changed, 175 insertions(+), 29 deletions(-) diff --git a/disasm/star_blazer.asm.patch b/disasm/star_blazer.asm.patch index 79825c1..4bd4e79 100644 --- a/disasm/star_blazer.asm.patch +++ b/disasm/star_blazer.asm.patch @@ -1,5 +1,5 @@ ---- star_blazer.asm0 2022-06-23 02:59:40.560126092 +1000 -+++ star_blazer.asm 2022-06-23 12:47:34.327997560 +1000 +--- star_blazer.asm0 2022-06-23 18:12:24.911895205 +1000 ++++ star_blazer.asm 2022-06-23 18:12:53.087894857 +1000 @@ -1,3 +1,8 @@ +ALIGN = 0 +DHGR = 1 @@ -108,20 +108,20 @@ @@ -1072,7 +1117,7 @@ tsx ; 1095 -> 1097 -> 1098 r stx *microcode_sp ; 1097 -> 1098 -> 109a r - ldx *microcode_object_c9 ; 1098 -> 109a -> 109c r + ldx *microcode_x_save_c9 ; 1098 -> 109a -> 109c r - lda 0xaee0,x ; 109a -> 109c -> 109f r x=01..7f -+ lda object1080_aef0 - 0x10,x ;0xaee0,x ; 109a -> 109c -> 109f r x=01..7f - sta *microcode_object_cc ; 109c -> 109f -> 10a1 r - loc_10a1: ++ lda object1080_start_sentinel - 0x10,x ;0xaee0,x ; 109a -> 109c -> 109f r x=01..7f + sta *microcode_start_sentinel ; 109c -> 109f -> 10a1 r + microcode_execute_1093_entry: ldy #0x00 ; 1090,109f -> 10a1 -> 10a3 r @@ -1099,7 +1144,7 @@ - jsr do_microcode_test1 ; 10c6 -> 10c8 -> 106a r s=f7..f9,02 + jsr do_microcode_test ; 10c6 -> 10c8 -> 106a r s=f7..f9,02 bne 3$ ; 107b -> 10cb -> 10c0 r z=0 - loc_10cd: + microcode_execute_1093_done: - lda 0xaee0,x ; 1093,10a5,10ba,10c2,10c6 -> 10cd -> 10d0 r x=01..7f -+ lda object1080_aef0 - 0x10,x ;0xaee0,x ; 1093,10a5,10ba,10c2,10c6 -> 10cd -> 10d0 r x=01..7f ++ lda object1080_start_sentinel - 0x10,x ;0xaee0,x ; 1093,10a5,10ba,10c2,10c6 -> 10cd -> 10d0 r x=01..7f rts ; 10cd -> 10d0 -> 123e,143a,1615,1629,1633,1649,165b,1759 r s=f7..fd,02 - sub_10d1: + microcode_execute_10d1: beq rts_10ec ; 1216,123b,1260,1285 -> 10d1 -> 10d3,10ec r z=0..1 @@ -1981,10 +2026,35 @@ sta *button_state ; 17ce r @@ -1546,7 +1546,55 @@ microcode_table_5560_data_8e00: .db 0x30 ; 8e00 r .db 0x0f ; 8e01 -@@ -26926,31 +26780,308 @@ +@@ -24655,7 +24509,15 @@ + .db 0x0a ; 95da + .db 0x00 ; 95db + microcode_table_54d6_data_95dc: ++.if 0 ; testing ++ .db 0x73 ; radar0 shape ++ .db 0x74 ; radar1 shape ++ .db 0x75 ; radar2 shape ++ .db 0x74 ; radar1 shape ++ .db 0xf8 ; -> repeating ++.else + .db 0x2c ; 95dc r ++.endif + .db 0xf2 ; 95dd + .db 0x2e ; 95de + .db 0xf3 ; 95df +@@ -24670,7 +24532,15 @@ + .db 0x60 ; 95e7 + .db 0x00 ; 95e8 + microcode_table_54d8_data_95e9: ++.if 0 ; testing ++ .db 0x73 ; radar0 shape ++ .db 0x74 ; radar1 shape ++ .db 0x75 ; radar2 shape ++ .db 0x74 ; radar1 shape ++ .db 0xf8 ; -> repeating ++.else + .db 0x2c ; 95e9 r ++.endif + .db 0xf2 ; 95ea + .db 0x2e ; 95eb + .db 0xf3 ; 95ec +@@ -24685,7 +24555,15 @@ + .db 0x60 ; 95f4 + .db 0x00 ; 95f5 + microcode_table_54da_data_95f6: ++.if 0 ; testing ++ .db 0x73 ; radar0 shape ++ .db 0x74 ; radar1 shape ++ .db 0x75 ; radar2 shape ++ .db 0x74 ; radar1 shape ++ .db 0xf8 ; -> repeating ++.else + .db 0x2c ; 95f6 r ++.endif + .db 0xf2 ; 95f7 + .db 0x2e ; 95f8 + .db 0xf3 ; 95f9 +@@ -26926,31 +26804,308 @@ .db 0x7c ; 9dea .db 0x98 ; 9deb .db 0x00 ; 9dec @@ -1880,7 +1928,7 @@ .area udata2 -@@ -27033,3 +27164,4 @@ +@@ -27033,3 +27188,4 @@ object6080_b560: .ds 0x20 ; b560 rw diff --git a/disasm/star_blazer.txt b/disasm/star_blazer.txt index 0eb2a08..6391f9c 100644 --- a/disasm/star_blazer.txt +++ b/disasm/star_blazer.txt @@ -52,16 +52,20 @@ items # decimal + 0xe: ? 0x00b0,0x0010,decimal,byte 0x00c0,0x0002,microcode_ptr_c0,word +0x00c2,0x0001,microcode_test_object,byte 0x00c7,0x0001,microcode_object_c7,byte 0x00c8,0x0001,sp_save,byte -0x00c9,0x0001,microcode_object_c9,byte -0x00cc,0x0001,microcode_object_cc,byte +0x00c9,0x0001,microcode_x_save_c9,byte +0x00ca,0x0001,microcode_y_save_ca,byte +# may contain a value from object1080_microcode_start_sentinel (basically +# the current state of the object) and also seems to be used as a counter +0x00cc,0x0001,microcode_start_sentinel,byte 0x00cd,0x0001,microcode_sp,byte 0x00d0,0x0002,microcode_ptr_d0,word # or shape_ptr? 0x00d2,0x0002,temp,word 0x00d4,0x0001,y_save,byte -0x00e2,0x0001,microcode_x_save,byte -0x00e3,0x0001,microcode_y_save,byte +0x00e2,0x0001,microcode_x_save_e2,byte +0x00e3,0x0001,microcode_y_save_e3,byte 0x00e4,0x0002,homing_ptr,word # is it really? 0x00e6,0x0002,microcode_ptr_e6,word 0x00f0,0x0001,demo_mode,byte # 0xff = demo mode, 0x00 = play mode @@ -136,21 +140,51 @@ items 0x0f57,0x0001,decimal_inc,code 0x0f66,0x0001,decimal_dec,code 0x0f83,0x0001,vector_to_update_a_decimal,code -0x0f8d,0x0001,microcode_test0,code +0x0f8d,0x0001,microcode_test_end,code 0x0fb1,0x0001,adjust_score_for_reset_object,code -0x0fdb,0x0001,microcode_test,code -0x0fdd,0x0001,microcode_test1,code +0x0fdb,0x0001,microcode_test_loop,code +# enter with a = command from microcode, microcode_test_object setup +# these values come from do_microcode_test (I think the only external caller) +0x0fdd,0x0001,microcode_test,code 0x1009,0x0001,vector_to_microcode,code 0x1016,0x0001,check_microcode_status_bits,code -0x106a,0x0001,do_microcode_test1,code +# enter with a = value for microcode_test_object, microcode_ptr_c0 setup, +# y = index into table at microcode_ptr_c0 (it will be incremented twice) +# routine loads a command from the microcode table and calls microcode_test +0x106a,0x0001,do_microcode_test,code 0x107c,0x0001,decimal_zero,code +# zf=1 -> go to loc_10cd +# otherwise load microcode_start_sentinel from object1080_start_sentinel, +# and enter a loop scanning microcode table at microcode_ptr_c0 from index 0, +# when value read from microcode table is: +# 0 go to loc_10cd +# >= 0xf0 see if it's the start sentinel in microcode_start_sentinel +# if it's not then keep skipping 2 locations until end of table or found +# when found, skip 2 locations and check for more commands (0 is end of +# table, >= 0xf0 is a different section, otherwise execute + zf=0 repeat +# otherwise execute it via do_microcode_test, and check zf return because +# zf=1 means terminate the loop at loc_10cd otherwise keep executing loop +# in summary there seems to be a global section at the start of the table that +# is always executed, and a specific section to execute based on current state +0x1093,0x0001,microcode_execute_1093,code 0x109c,0x0001,,code_ign # bug? spans ae80 and aef0 tables, don't merge them -0x10cd,0x0001,,code_ign # bug? spans ae80 and aef0 tables, don't merge them +# alternative entry point for microcode_execute_1093 that comes from scoring? +0x10a1,0x0001,microcode_execute_1093_entry,code +# returns the current value of object1080_start_sentinel for the object in x +# I think this might be to provide the correct flags return? +0x10cd,0x0001,microcode_execute_1093_done,code_ign # bug? spans ae80 and aef0 tables, don't merge them +# it seems to read values from table at microcode_ptr_c0 with some complicated +# indirection (value from table = index to use for next read from table?) and +# it executes them by calling do_microcode_test, this may read adjacent value? +# microcode_start_sentinel = counter that gets decremented to 0 +# bvar_00cb = start index in table, and is advanced by the routine +0x10d1,0x0001,microcode_execute_10d1,code 0x10ed,0x0001,adjust_score,code 0x1153,0x0001,reset_decimals,code -0x1160,0x0001,do_set_object_shape,code -0x11a7,0x0001,set_object1080_aef0_bit7_and_compute_object_bounds,code -0x11b2,0x0001,clear_object1080_aef0_bit7_and_erase_object,code +0x1160,0x0001,reset_object_state,code +0x11a7,0x0001,set_object1080_start_sentinel_bit7_and_compute_object_bounds,code +0x11b2,0x0001,clear_object1080_start_sentinel_bit7_and_erase_object,code +0x11bd,0x0001,countdown_b120_or_b190_expired,code 0x1291,0x0001,homing_test,code 0x12e1,0x0001,accelerate_object_towards_another,code 0x133f,0x0001,sign_extend_a_to_ya_asl_by_4,code @@ -271,8 +305,8 @@ items 0x53c0,0x0020,object6080_53c0,byte 0x53e0,0x0020,object6080_53e0,byte # the partitioning below is approximate and just tries to cover everything -0x5400,0x0020,,word # object_shape_table_ptr? -0x5420,0x00e0,microcode_table_5420,word +0x5400,0x0020,,word +0x5420,0x00e0,microcode_table_animate_shape,word 0x5500,0x0020,microcode_table_5500,word 0x5520,0x00e0,microcode_table_5520,word 0x5600,0x0020,,word @@ -708,10 +742,37 @@ items 0x95b7,0x0001,microcode_table_5b3e_data_95b7,byte 0x95c4,0x0001,microcode_table_5b3a_data_95c4,byte 0x95d1,0x0001,microcode_table_551c_data_95d1,byte +# object 0x6b is helicopter_or_enemy_plane0 +# 54d6 = microcode_table_animate_shape + 0x6b * 2 +# -> implied start of section 0xf0 +# .db 0x2c helicopter shape +# .db 0xf2 -> start of section 0xf2 +# .db 0x2e enemy_plane0 shape +# .db 0xf3 -> start of section 0xf3 +# .db 0x2f enemy_plane1 shape +# .db 0x00 sentinel 0x95dc,0x0001,microcode_table_54d6_data_95dc,byte 0x95e2,0x0001,microcode_table_5936_data_95e2,byte +# object 0x6c is helicopter_or_enemy_plane1 +# 54d8 = microcode_table_animate_shape + 0x6c * 2 +# -> implied start of section 0xf0 +# .db 0x2c helicopter shape +# .db 0xf2 -> start of section 0xf2 +# .db 0x2e enemy_plane0 shape +# .db 0xf3 -> start of section 0xf3 +# .db 0x2f enemy_plane1 shape +# .db 0x00 sentinel 0x95e9,0x0001,microcode_table_54d8_data_95e9,byte 0x95ef,0x0001,microcode_table_5938_data_95ef,byte +# object 0x6d is helicopter_or_enemy_plane2 +# 54da = microcode_table_animate_shape + 0x6d * 2 +# -> implied start of section 0xf0 +# .db 0x2c helicopter shape +# .db 0xf2 -> start of section 0xf2 +# .db 0x2e enemy_plane0 shape +# .db 0xf3 -> start of section 0xf3 +# .db 0x2f enemy_plane1 shape +# .db 0x00 sentinel 0x95f6,0x0001,microcode_table_54da_data_95f6,byte 0x95fc,0x0001,microcode_table_593a_data_95fc,byte 0x9603,0x0001,microcode_table_54dc_data_9603,byte @@ -763,6 +824,40 @@ items 0x96e0,0x0001,microcode_table_555a_data_96e0,byte 0x96f1,0x0001,microcode_table_555c_data_96f1,byte 0x9704,0x0001,microcode_table_5b6e_data_9704,byte +# object 0x4d is radar_or_icbm +# 549a = microcode_table_animate_shape + 0x4d * 2 +# controls the headquarters, icbm or radar shape as follows +# -> implied start of section 0xf0 +# .db 0x72 headquarters shape +# .db 0xf2 -> start of section 0xf2 +# .db 0x76 icbm shape +# .db 0xf1 -> start of section 0xf1 +# .db 0x73 radar0 shape +# .db 0x74 radar1 shape +# .db 0x75 radar2 shape +# .db 0x74 radar1 shape +# .db 0xf9 -> repeating, & 0xf3 for start sentinel (0xf1) +# .db 0x00 sentinel +# object1080_animate_shape_index + 0x4d holds the index into above table +# loc_0daf controls wraparound when sentinel >= 0xf0 reached +# loc_0da6 does a post-increment +# loc_0dac for 0xff +# loc_0db9 for 0xf8..0xfe (repeating, & 0xf3 for the start sentinel) +# 0xf0..0xf3 value is poked into object1080_start_sentinel + object, and +# something happens when it changes, if object >= 0x60 ... then loc_0dcb +# loc_0dcb for 0xf0..0xf7 +# scan the table from the beginning (except if sentinel was 0xf0) +# loc_0ddc when end of table is reached +# scan until we find the value at object1080_start_sentinel + object +# loc_0ddc a = table index where start sentinel was found (or end sentinel) +# update object1080_animate_shape_index with this index (causes the +# wrapping to restart the animation sequence) ... resume at loc_0da6 +# note: the microcode_test routine seems implicated in launching this: +# 0$: ldy object1080_start_sentinel - 0x10,x +# bpl 2$ +# and #0x03 +# ora #0xf0 +# jmp [vec_calculate_object_shape] 0x9707,0x0001,microcode_table_549a_data_9707,byte 0x9711,0x0001,microcode_table_54e4_data_9711,byte 0x971d,0x0001,microcode_table_56c4_data_971d,byte @@ -933,7 +1028,10 @@ items 0xada0,0x0070,object1080_x1,byte 0xae10,0x0070,object1080_y0,byte 0xae80,0x0070,object1080_y1,byte -0xaef0,0x0070,object1080_aef0,byte +# current state of object +# often a value 0xf0..0xf3 to identify relevant section in microcode table, +# but I think it has other purposes too (bit 7 may mean object is active?) +0xaef0,0x0070,object1080_start_sentinel,byte 0xaf60,0x0070,object1080_velocity_x_hi,byte 0xafd0,0x0070,object1080_velocity_y_hi,byte 0xb040,0x0070,object1080_velocity_x_lo,byte @@ -942,8 +1040,8 @@ items 0xb190,0x0070,object1080_countdown_b190,byte 0xb200,0x0070,object1080_x_lo,byte 0xb270,0x0070,object1080_y_lo,byte -0xb2e0,0x0070,object1080_b2e0,byte -0xb350,0x0070,object1080_shape_table_index,byte +0xb2e0,0x0070,object1080_animate2,byte +0xb350,0x0070,object1080_animate_shape_index,byte 0xb3c0,0x0030,object5080_abs_x_difference,byte 0xb3f0,0x0030,object5080_abs_y_difference,byte 0xb420,0x0030,object5080_abs_difference_b420,byte -- 2.34.1