castleraider
changeset 332:4d2ef247d046
Combined the miscellaneous routines into a single file to be loaded in the
game loader.
Combined the TILES and SPRITES files into a single SPRITES file.
Removed all sprite files from the code to generate file markers for the
interrupt routine used by the game loader since the sprites are now loaded
before the routine is run and it intentionally inverts bits in memory in
order to check when certain bytes have been loaded.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Wed Oct 08 00:47:54 2014 +0200 |
| parents | 6d3d1810ebf6 |
| children | abe1e2a3e703 |
| files | build.py loader.oph |
| diffstat | 2 files changed, 74 insertions(+), 124 deletions(-) [+] |
line diff
1.1 --- a/build.py Tue Oct 07 23:48:10 2014 +0200 1.2 +++ b/build.py Wed Oct 08 00:47:54 2014 +0200 1.3 @@ -55,7 +55,7 @@ 1.4 # print it. 1.5 1.6 text_length = 0 1.7 - data_oph = "" 1.8 + data = "" 1.9 lines.reverse() 1.10 1.11 for line in lines: 1.12 @@ -65,16 +65,14 @@ 1.13 for piece in line: 1.14 1.15 if type(piece) == int: 1.16 - text_length += 1 1.17 - text_values.append(str(piece)) 1.18 + text_values.append(chr(piece)) 1.19 else: 1.20 - text_length += len(piece) 1.21 - text_values.append('"' + piece[::-1] + '"') 1.22 + text_values.append(piece[::-1]) 1.23 1.24 text_values.reverse() 1.25 - data_oph += ".byte " + ", ".join(text_values) + "\n" 1.26 + data += "".join(text_values) 1.27 1.28 - return data_oph, text_length 1.29 + return data 1.30 1.31 def encode_data(bytes): 1.32 1.33 @@ -99,7 +97,7 @@ 1.34 1.35 life_sprites = ["images/life1.png", "images/life2.png"] 1.36 1.37 -title_data_oph_routines = [ 1.38 +misc_routines = [ 1.39 "print_title_text", 1.40 "print_game_over_text", 1.41 "check_key", 1.42 @@ -109,16 +107,15 @@ 1.43 "read_joystick_fire" 1.44 ] 1.45 1.46 -def encode_in_game_data(in_game_data_address): 1.47 +def encode_in_game_data_and_routines(in_game_data_address): 1.48 1.49 # Encode the in-game title data. 1.50 - title_data_oph = "" 1.51 + data = "" 1.52 1.53 title_rows = 0 1.54 for line in open("title.txt").readlines(): 1.55 1.56 line = line.rstrip("\n") 1.57 - title_data_oph += ".byte " 1.58 1.59 for i in range(0, 40, 4): 1.60 1.61 @@ -128,34 +125,33 @@ 1.62 byte = byte | (".@#+".index(char) << shift) 1.63 shift += 2 1.64 1.65 - title_data_oph += "$%02x" % byte 1.66 - if i < 36: 1.67 - title_data_oph += ", " 1.68 + data += chr(byte) 1.69 1.70 - title_data_oph += "\n" 1.71 title_rows += 1 1.72 1.73 - title_data_oph += "\n" 1.74 + in_game_title_text_address = in_game_data_address + len(data) 1.75 1.76 title_text = [(26, 31, 3, 6, 17, 3, "Retro Software"), 1.77 (31, 6, 8, "presents"), 1.78 (31, 2, 27, 17, 2, "Press ", 17, 3, "SPACE/FIRE"), 1.79 (31, 6, 29, 17, 2, "to play")] 1.80 1.81 - title_data, in_game_title_text_length = encode_text(title_text) 1.82 - title_data_oph += title_data 1.83 - title_data_oph += '\n' 1.84 + title_data = encode_text(title_text) 1.85 + data += title_data 1.86 + in_game_title_text_length = len(title_data) 1.87 + 1.88 + in_game_game_over_text_address = in_game_title_text_address + \ 1.89 + in_game_title_text_length 1.90 1.91 game_over_text = [(26, 31, 1, 16, 17, 3, "Your quest is over"), 1.92 (31, 4, 29, 17, 1, "Press SPACE")] 1.93 1.94 - game_over_data, in_game_game_over_text_length = encode_text(game_over_text) 1.95 - title_data_oph += game_over_data 1.96 - title_data_oph += '\n' 1.97 + game_over_data = encode_text(game_over_text) 1.98 + data += game_over_data 1.99 + in_game_game_over_text_length = len(game_over_data) 1.100 1.101 - in_game_title_text_address = in_game_data_address + (title_rows * 10) 1.102 - in_game_game_over_text_address = in_game_title_text_address + in_game_title_text_length 1.103 - in_game_title_routines_address = in_game_game_over_text_address + in_game_game_over_text_length 1.104 + in_game_title_routines_address = in_game_game_over_text_address + \ 1.105 + in_game_game_over_text_length 1.106 1.107 labels = ( 1.108 ".alias title_data_address $%(title_data_address)x\n" 1.109 @@ -176,10 +172,10 @@ 1.110 } 1.111 1.112 routine_address = in_game_title_routines_address 1.113 - for name in title_data_oph_routines: 1.114 + 1.115 + for name in misc_routines: 1.116 1.117 routine = open(os.path.join("routines", name + ".oph")).read() 1.118 - 1.119 print "Assembling", name, "at $%x" % routine_address 1.120 1.121 # Substitute the routine address into the code if necessary and include 1.122 @@ -191,7 +187,7 @@ 1.123 system("ophis temp.oph -o TEMP") 1.124 1.125 # Include the routine in the title data file. 1.126 - title_data_oph += encode_data(open("TEMP").read()) + "\n" 1.127 + data += open("TEMP").read() 1.128 1.129 # Add the run-time address to the constants. 1.130 labels += ".alias " + name + (" $%0x\n" % routine_address) 1.131 @@ -206,9 +202,22 @@ 1.132 # Store the address of the end of the working area. 1.133 details["working_end"] = routine_address 1.134 1.135 - open("title-data-and-ending.oph", "w").write(title_data_oph) 1.136 + # Define aliases for the start, length and end of the block of data 1.137 + # created by this function. 1.138 1.139 - return labels, details 1.140 + labels += ( 1.141 + ".alias routines_low $%02x\n" 1.142 + ".alias routines_high $%02x\n" 1.143 + ".alias routines_length_low $%02x\n" 1.144 + ".alias routines_length_high $%02x\n" 1.145 + ".alias routines_end_low $%02x\n" 1.146 + ".alias routines_end_high $%02x\n" 1.147 + ) % (in_game_data_address & 0xff, in_game_data_address >> 8, 1.148 + len(data) & 0xff, len(data) >> 8, 1.149 + (in_game_data_address + len(data)) & 0xff, 1.150 + (in_game_data_address + len(data)) >> 8) 1.151 + 1.152 + return labels, details, data 1.153 1.154 if __name__ == "__main__": 1.155 1.156 @@ -307,7 +316,8 @@ 1.157 # This is done in the loader. 1.158 title_data_address = initial_row_offsets + 0x10 1.159 1.160 - in_game_data_labels, in_game_data_details = encode_in_game_data(title_data_address) 1.161 + in_game_data_labels, in_game_data_details, title_data_routines = \ 1.162 + encode_in_game_data_and_routines(title_data_address) 1.163 working_end = in_game_data_details["working_end"] 1.164 1.165 # Permanent data 1.166 @@ -533,16 +543,16 @@ 1.167 tile_visibility_high, maximum_number_of_special_tiles) 1.168 1.169 constants_oph += ( 1.170 - ".alias char_area $%x\n" 1.171 - ".alias char_area_low $%02x\n" 1.172 - ".alias char_area_high $%02x\n" 1.173 - ".alias char_area_length_low $%02x\n" 1.174 - ".alias char_area_length_high $%02x\n" 1.175 - ".alias char_area_end_low $%02x\n" 1.176 - ".alias char_area_end_high $%02x\n" 1.177 + ".alias sprites_file_area $%x\n" 1.178 + ".alias sprites_file_area_low $%02x\n" 1.179 + ".alias sprites_file_area_high $%02x\n" 1.180 + ".alias sprites_file_area_length_low $%02x\n" 1.181 + ".alias sprites_file_area_length_high $%02x\n" 1.182 + ".alias sprites_file_area_end_low $%02x\n" 1.183 + ".alias sprites_file_area_end_high $%02x\n" 1.184 "\n" 1.185 - ) % ((char_area_address,) + \ 1.186 - address_length_end(char_area_address, char_data)) 1.187 + ) % ((sprite_area_address,) + \ 1.188 + address_length_end(sprite_area_address, sprite_data + char_data)) 1.189 1.190 constants_oph += ( 1.191 ".alias top_panel_address_low $%02x\n" 1.192 @@ -678,8 +688,7 @@ 1.193 1.194 loader_start = 0x3500 1.195 1.196 - marker_info = [(sprite_area_address, sprite_data), 1.197 - (levels_address, level_data), 1.198 + marker_info = [(levels_address, level_data), 1.199 (panel_address, panel), 1.200 (code_start, code)] 1.201 markers = "" 1.202 @@ -725,8 +734,10 @@ 1.203 1.204 files = [("CASTLE", bootloader_start, bootloader_start, bootloader_code), 1.205 ("LOADER", loader_start, loader_start, loader_code), 1.206 - ("SPRITES", char_area_address, char_area_address, char_data), 1.207 - ("TILES", sprite_area_address, sprite_area_address, sprite_data), 1.208 + ("ROUTINES", title_data_address, title_data_address, 1.209 + title_data_routines), 1.210 + ("SPRITES", sprite_area_address, sprite_area_address, 1.211 + sprite_data + char_data), 1.212 ("LEVELS", levels_address, levels_address, level_data), 1.213 ("PANEL", panel_address, panel_address, panel), 1.214 ("CODE", code_start, code_start, code)] 1.215 @@ -771,17 +782,8 @@ 1.216 else: 1.217 print " (%i bytes free)" % (sprite_area_address - levels_finish) 1.218 1.219 - sprite_area_finish = sprite_area_address + len(sprite_data) 1.220 - print "TILES runs from %04x to %04x" % (sprite_area_address, sprite_area_finish), 1.221 - if sprite_area_finish > char_area_address: 1.222 - print 1.223 - sys.stderr.write("TILES overruns following data by %i bytes.\n" % (sprite_area_finish - char_area_address)) 1.224 - sys.exit(1) 1.225 - else: 1.226 - print " (%i bytes free)" % (char_area_address - sprite_area_finish) 1.227 - 1.228 - char_area_finish = char_area_address + len(char_data) 1.229 - print "SPRITES runs from %04x to %04x" % (char_area_address, char_area_finish) 1.230 + char_area_finish = sprite_area_address + len(sprite_data) + len(char_data) 1.231 + print "SPRITES runs from %04x to %04x" % (sprite_area_address, char_area_finish) 1.232 #if char_area_finish > panel_address: 1.233 # sys.stderr.write("SPRITES overruns following data by %i bytes.\n" % (char_area_finish - panel_address)) 1.234 # sys.exit(1) 1.235 @@ -872,7 +874,6 @@ 1.236 os.remove("constants.oph") 1.237 os.remove("loader-constants.oph") 1.238 os.remove("screen.oph") 1.239 - os.remove("title-data-and-ending.oph") 1.240 1.241 # Exit 1.242 sys.exit()
2.1 --- a/loader.oph Tue Oct 07 23:48:10 2014 +0200 2.2 +++ b/loader.oph Wed Oct 08 00:47:54 2014 +0200 2.3 @@ -18,8 +18,6 @@ 2.4 .include "loader-constants.oph" 2.5 2.6 main: 2.7 - jsr move_title_data ; Move the title data into the temporary data area. 2.8 - 2.9 lda #22 2.10 jsr $ffee 2.11 lda #5 2.12 @@ -38,6 +36,13 @@ 2.13 2.14 jsr set_core_palette 2.15 2.16 + ; Load miscellaneous routines. 2.17 + 2.18 + lda #255 2.19 + ldx #<routines_block 2.20 + ldy #>routines_block 2.21 + jsr $ffdd 2.22 + 2.23 ; Load the sprites. 2.24 2.25 lda #255 2.26 @@ -153,11 +158,6 @@ 2.27 bne init_load_window_loop 2.28 2.29 lda #255 2.30 - ldx #<tiles_block 2.31 - ldy #>tiles_block 2.32 - jsr $ffdd 2.33 - 2.34 - lda #255 2.35 ldx #<levels_block 2.36 ldy #>levels_block 2.37 jsr $ffdd 2.38 @@ -404,19 +404,19 @@ 2.39 clc 2.40 rts 2.41 2.42 -tiles_block: .byte <tiles_file_name, >tiles_file_name 2.43 - .byte sprite_area_low, sprite_area_high, 0, 0 2.44 - .byte sprite_area_low, sprite_area_high, 0, 0 2.45 - .byte sprite_area_length_low, sprite_area_length_high, 0, 0 2.46 - .byte sprite_area_end_low, sprite_area_end_high, 0, 0 2.47 +routines_block: .byte <routines_file_name, >routines_file_name 2.48 + .byte routines_low, routines_high, 0, 0 2.49 + .byte routines_low, routines_high, 0, 0 2.50 + .byte routines_length_low, routines_length_high, 0, 0 2.51 + .byte routines_end_low, routines_end_high, 0, 0 2.52 2.53 -tiles_file_name: .byte "TILES", 13 2.54 +routines_file_name: .byte "ROUTINES", 13 2.55 2.56 sprites_block: .byte <sprites_file_name, >sprites_file_name 2.57 - .byte char_area_low, char_area_high, 0, 0 2.58 - .byte char_area_low, char_area_high, 0, 0 2.59 - .byte char_area_length_low, char_area_length_high, 0, 0 2.60 - .byte char_area_end_low, char_area_end_high, 0, 0 2.61 + .byte sprites_file_area_low, sprites_file_area_high, 0, 0 2.62 + .byte sprites_file_area_low, sprites_file_area_high, 0, 0 2.63 + .byte sprites_file_area_length_low, sprites_file_area_length_high, 0, 0 2.64 + .byte sprites_file_area_end_low, sprites_file_area_end_high, 0, 0 2.65 2.66 sprites_file_name: .byte "SPRITES", 13 2.67 2.68 @@ -470,53 +470,6 @@ 2.69 .byte "GNU GPL v.3 or later" 2.70 title_text_end: 2.71 2.72 -; In-game title data handling routines and data. 2.73 - 2.74 -move_title_data: 2.75 - 2.76 - lda #<in_game_data_start 2.77 - sta $70 2.78 - lda #>in_game_data_start 2.79 - sta $71 2.80 - 2.81 - lda #<title_data_address 2.82 - sta $72 2.83 - lda #>title_data_address 2.84 - sta $73 2.85 - 2.86 - ldy #0 2.87 - move_title_data_loop: 2.88 - 2.89 - clc 2.90 - lda ($70),y 2.91 - sta ($72),y 2.92 - 2.93 - inc $70 2.94 - lda $70 2.95 - cmp #0 2.96 - bne move_title_data_loop_next1 2.97 - inc $71 2.98 - move_title_data_loop_next1: 2.99 - clc 2.100 - 2.101 - inc $72 2.102 - lda $72 2.103 - cmp #0 2.104 - bne move_title_data_loop_next2 2.105 - inc $73 2.106 - move_title_data_loop_next2: 2.107 - clc 2.108 - 2.109 - lda $70 2.110 - cmp #<in_game_data_end 2.111 - bne move_title_data_loop 2.112 - lda $71 2.113 - cmp #>in_game_data_end 2.114 - bne move_title_data_loop 2.115 - 2.116 - clc 2.117 - rts 2.118 - 2.119 ; Flag drawing routines 2.120 2.121 .alias title_start_address $5e48 2.122 @@ -1021,8 +974,4 @@ 2.123 pla 2.124 jmp (cassette_original_irq1v) 2.125 2.126 -in_game_data_start: 2.127 -.include "title-data-and-ending.oph" 2.128 -in_game_data_end: 2.129 - 2.130 cassette_markers:
