castleraider
changeset 331:6d3d1810ebf6
Moved the code snippets from the build script to a routines directory and
included a couple of routines from the main code.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Tue Oct 07 23:48:10 2014 +0200 |
| parents | 2c7077f98932 |
| children | 4d2ef247d046 |
| files | build.py code.oph ending.oph joystick.oph plotting.oph routines/check_key.oph routines/clear_bank.oph routines/print_game_over_text.oph routines/print_title_text.oph routines/read_joystick_axis.oph routines/read_joystick_fire.oph routines/wait_for_key.oph |
| diffstat | 12 files changed, 214 insertions(+), 131 deletions(-) [+] |
line diff
1.1 --- a/build.py Tue Oct 07 00:27:58 2014 +0200 1.2 +++ b/build.py Tue Oct 07 23:48:10 2014 +0200 1.3 @@ -100,46 +100,14 @@ 1.4 life_sprites = ["images/life1.png", "images/life2.png"] 1.5 1.6 title_data_oph_routines = [ 1.7 -("print_title_text", """ 1.8 - 1.9 - ldx #[%(in_game_title_text_length)i - 1] 1.10 - title_text_loop: 1.11 - lda $%(in_game_title_text_address)x,x 1.12 - jsr $ffee 1.13 - dex 1.14 - bpl title_text_loop 1.15 - 1.16 - clc 1.17 - rts 1.18 -"""), 1.19 -("print_game_over_text", """ 1.20 - 1.21 - ldx #[%(in_game_game_over_text_length)i - 1] 1.22 - game_over_text_loop: 1.23 - lda $%(in_game_game_over_text_address)x,x 1.24 - jsr $ffee 1.25 - dex 1.26 - bpl game_over_text_loop 1.27 - 1.28 - clc 1.29 - rts 1.30 -"""), 1.31 -("check_key", """ ; x=key code 1.32 - lda #129 ; returns y=255 or 0 1.33 - ldy #255 1.34 - jsr $fff4 1.35 - cpy #255 ; Perform the check for a pressed key here. 1.36 - rts 1.37 -"""), 1.38 -("wait_for_key", """ ; A=key 1.39 - 1.40 - sta $70 1.41 - wait_for_key_loop: 1.42 - ldx $70 1.43 - jsr check_key 1.44 - bne wait_for_key_loop 1.45 - rts 1.46 -""")] 1.47 + "print_title_text", 1.48 + "print_game_over_text", 1.49 + "check_key", 1.50 + "wait_for_key", 1.51 + "clear_bank", 1.52 + "read_joystick_axis", 1.53 + "read_joystick_fire" 1.54 + ] 1.55 1.56 def encode_in_game_data(in_game_data_address): 1.57 1.58 @@ -208,8 +176,10 @@ 1.59 } 1.60 1.61 routine_address = in_game_title_routines_address 1.62 - for name, routine in title_data_oph_routines: 1.63 + for name in title_data_oph_routines: 1.64 1.65 + routine = open(os.path.join("routines", name + ".oph")).read() 1.66 + 1.67 print "Assembling", name, "at $%x" % routine_address 1.68 1.69 # Substitute the routine address into the code if necessary and include 1.70 @@ -233,20 +203,8 @@ 1.71 os.remove("temp.oph") 1.72 os.remove("TEMP") 1.73 1.74 - # The completion code is stored after the title routines. 1.75 - details["in_game_completion_address"] = routine_address 1.76 - labels += ".alias in_game_completion_address $%(in_game_completion_address)x\n" 1.77 - 1.78 - print "Assembling ending.oph at $%x" % routine_address 1.79 - ending = open("ending.oph").read() 1.80 - ending = (ending % details) + "\n" + (labels % details) 1.81 - open("temp.oph", "w").write(ending) 1.82 - 1.83 - system("ophis temp.oph -o TEMP") 1.84 - ending = open("TEMP").read() 1.85 - os.remove("temp.oph") 1.86 - os.remove("TEMP") 1.87 - title_data_oph += encode_data(ending) 1.88 + # Store the address of the end of the working area. 1.89 + details["working_end"] = routine_address 1.90 1.91 open("title-data-and-ending.oph", "w").write(title_data_oph) 1.92 1.93 @@ -345,12 +303,12 @@ 1.94 # Initial displacements for the rows. 1.95 initial_row_offsets = row_indices + 0x10 1.96 1.97 - # Store the in-game text data and the completion code above the working 1.98 - # data - this is done in the loader. 1.99 + # Store the in-game text data and other routines above the working data. 1.100 + # This is done in the loader. 1.101 title_data_address = initial_row_offsets + 0x10 1.102 1.103 in_game_data_labels, in_game_data_details = encode_in_game_data(title_data_address) 1.104 - working_end = in_game_data_details["in_game_completion_address"] 1.105 + working_end = in_game_data_details["working_end"] 1.106 1.107 # Permanent data 1.108
2.1 --- a/code.oph Tue Oct 07 00:27:58 2014 +0200 2.2 +++ b/code.oph Tue Oct 07 23:48:10 2014 +0200 2.3 @@ -191,7 +191,7 @@ 2.4 2.5 ; Jump to an address in the working area where the completion code 2.6 ; was copied to by the loader. 2.7 - jsr in_game_completion_address 2.8 + jsr game_completed 2.9 2.10 main_loop_check_monsters: 2.11 jsr check_player_monsters 2.12 @@ -1079,5 +1079,5 @@ 2.13 .include "scrolling.oph" 2.14 .include "bank_routines.oph" 2.15 .include "monsters.oph" 2.16 -.include "joystick.oph" 2.17 .include "sound.oph" 2.18 +.include "ending.oph"
3.1 --- a/ending.oph Tue Oct 07 00:27:58 2014 +0200 3.2 +++ b/ending.oph Tue Oct 07 23:48:10 2014 +0200 3.3 @@ -15,7 +15,6 @@ 3.4 3.5 ; The following line contains a placeholder address that the build script 3.6 ; calculates and fills in. 3.7 -.org $%(in_game_completion_address)x 3.8 3.9 game_completed: 3.10
4.1 --- a/joystick.oph Tue Oct 07 00:27:58 2014 +0200 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,44 +0,0 @@ 4.4 -; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 4.5 -; 4.6 -; This program is free software: you can redistribute it and/or modify 4.7 -; it under the terms of the GNU General Public License as published by 4.8 -; the Free Software Foundation, either version 3 of the License, or 4.9 -; (at your option) any later version. 4.10 -; 4.11 -; This program is distributed in the hope that it will be useful, 4.12 -; but WITHOUT ANY WARRANTY; without even the implied warranty of 4.13 -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.14 -; GNU General Public License for more details. 4.15 -; 4.16 -; You should have received a copy of the GNU General Public License 4.17 -; along with this program. If not, see <http://www.gnu.org/licenses/>. 4.18 - 4.19 -read_joystick_axis: ; X=axis (1=horizontal, 2=vertical) 4.20 - ; Returns 0=left/up or 1=right/down with carry set if 4.21 - ; valid input is present; otherwise carry is clear. 4.22 - lda #128 4.23 - jsr $fff4 4.24 - cpy #160 4.25 - bcs read_joystick_positive 4.26 - cpy #97 4.27 - bcc read_joystick_negative 4.28 - 4.29 - clc ; Return with carry clear to indicate no input. 4.30 - rts 4.31 - 4.32 - read_joystick_positive: 4.33 - lda #1 4.34 - rts 4.35 - 4.36 - read_joystick_negative: 4.37 - lda #0 4.38 - sec 4.39 - rts 4.40 - 4.41 -read_joystick_fire: ; Returns with carry set if a button is pressed; 4.42 - ; otherwise returns with carry clear. 4.43 - lda #128 4.44 - ldx #0 4.45 - jsr $fff4 4.46 - cpx #$01 ; If X>=1 then set the carry flag. 4.47 - rts
5.1 --- a/plotting.oph Tue Oct 07 00:27:58 2014 +0200 5.2 +++ b/plotting.oph Tue Oct 07 23:48:10 2014 +0200 5.3 @@ -34,32 +34,7 @@ 5.4 sta $71 5.5 lda #$80 5.6 sta $72 5.7 - ; fall through 5.8 - 5.9 -clear_bank: 5.10 - 5.11 - lda #$00 5.12 - sta $70 5.13 - ldy #0 5.14 - 5.15 - clear_bank_loop: 5.16 - 5.17 - lda #0 5.18 - sta ($70),y 5.19 - 5.20 - lda $70 5.21 - adc #1 5.22 - sta $70 5.23 - lda $71 5.24 - adc #0 5.25 - sta $71 5.26 - clc 5.27 - 5.28 - cmp $72 5.29 - bne clear_bank_loop 5.30 - 5.31 - clc 5.32 - rts 5.33 + jmp clear_bank 5.34 5.35 read_screen_address_bank1: ; X=row, A=column offset 5.36 ; sets $72,$73
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/routines/check_key.oph Tue Oct 07 23:48:10 2014 +0200 6.3 @@ -0,0 +1,22 @@ 6.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 6.5 +; 6.6 +; This program is free software: you can redistribute it and/or modify 6.7 +; it under the terms of the GNU General Public License as published by 6.8 +; the Free Software Foundation, either version 3 of the License, or 6.9 +; (at your option) any later version. 6.10 +; 6.11 +; This program is distributed in the hope that it will be useful, 6.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 6.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6.14 +; GNU General Public License for more details. 6.15 +; 6.16 +; You should have received a copy of the GNU General Public License 6.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 6.18 + 6.19 +; check_key: ; x=key code 6.20 + 6.21 + lda #129 ; returns y=255 or 0 6.22 + ldy #255 6.23 + jsr $fff4 6.24 + cpy #255 ; Perform the check for a pressed key here. 6.25 + rts
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/routines/clear_bank.oph Tue Oct 07 23:48:10 2014 +0200 7.3 @@ -0,0 +1,40 @@ 7.4 +; Copyright (C) 2013 David Boddie <david@boddie.org.uk> 7.5 +; 7.6 +; This program is free software: you can redistribute it and/or modify 7.7 +; it under the terms of the GNU General Public License as published by 7.8 +; the Free Software Foundation, either version 3 of the License, or 7.9 +; (at your option) any later version. 7.10 +; 7.11 +; This program is distributed in the hope that it will be useful, 7.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 7.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7.14 +; GNU General Public License for more details. 7.15 +; 7.16 +; You should have received a copy of the GNU General Public License 7.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 7.18 + 7.19 +; clear_bank: 7.20 + 7.21 + lda #$00 7.22 + sta $70 7.23 + ldy #0 7.24 + 7.25 + clear_bank_loop: 7.26 + 7.27 + lda #0 7.28 + sta ($70),y 7.29 + 7.30 + lda $70 7.31 + adc #1 7.32 + sta $70 7.33 + lda $71 7.34 + adc #0 7.35 + sta $71 7.36 + clc 7.37 + 7.38 + cmp $72 7.39 + bne clear_bank_loop 7.40 + 7.41 + clc 7.42 + rts 7.43 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/routines/print_game_over_text.oph Tue Oct 07 23:48:10 2014 +0200 8.3 @@ -0,0 +1,26 @@ 8.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 8.5 +; 8.6 +; This program is free software: you can redistribute it and/or modify 8.7 +; it under the terms of the GNU General Public License as published by 8.8 +; the Free Software Foundation, either version 3 of the License, or 8.9 +; (at your option) any later version. 8.10 +; 8.11 +; This program is distributed in the hope that it will be useful, 8.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 8.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8.14 +; GNU General Public License for more details. 8.15 +; 8.16 +; You should have received a copy of the GNU General Public License 8.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 8.18 + 8.19 +; print_game_over_text: 8.20 + 8.21 + ldx #[%(in_game_game_over_text_length)i - 1] 8.22 + game_over_text_loop: 8.23 + lda $%(in_game_game_over_text_address)x,x 8.24 + jsr $ffee 8.25 + dex 8.26 + bpl game_over_text_loop 8.27 + 8.28 + clc 8.29 + rts
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/routines/print_title_text.oph Tue Oct 07 23:48:10 2014 +0200 9.3 @@ -0,0 +1,26 @@ 9.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 9.5 +; 9.6 +; This program is free software: you can redistribute it and/or modify 9.7 +; it under the terms of the GNU General Public License as published by 9.8 +; the Free Software Foundation, either version 3 of the License, or 9.9 +; (at your option) any later version. 9.10 +; 9.11 +; This program is distributed in the hope that it will be useful, 9.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 9.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9.14 +; GNU General Public License for more details. 9.15 +; 9.16 +; You should have received a copy of the GNU General Public License 9.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 9.18 + 9.19 +; print_title_text: 9.20 + 9.21 + ldx #[%(in_game_title_text_length)i - 1] 9.22 + title_text_loop: 9.23 + lda $%(in_game_title_text_address)x,x 9.24 + jsr $ffee 9.25 + dex 9.26 + bpl title_text_loop 9.27 + 9.28 + clc 9.29 + rts
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/routines/read_joystick_axis.oph Tue Oct 07 23:48:10 2014 +0200 10.3 @@ -0,0 +1,36 @@ 10.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 10.5 +; 10.6 +; This program is free software: you can redistribute it and/or modify 10.7 +; it under the terms of the GNU General Public License as published by 10.8 +; the Free Software Foundation, either version 3 of the License, or 10.9 +; (at your option) any later version. 10.10 +; 10.11 +; This program is distributed in the hope that it will be useful, 10.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 10.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10.14 +; GNU General Public License for more details. 10.15 +; 10.16 +; You should have received a copy of the GNU General Public License 10.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 10.18 + 10.19 +; read_joystick_axis: ; X=axis (1=horizontal, 2=vertical) 10.20 + ; Returns 0=left/up or 1=right/down with carry set if 10.21 + ; valid input is present; otherwise carry is clear. 10.22 + lda #128 10.23 + jsr $fff4 10.24 + cpy #160 10.25 + bcs read_joystick_positive 10.26 + cpy #97 10.27 + bcc read_joystick_negative 10.28 + 10.29 + clc ; Return with carry clear to indicate no input. 10.30 + rts 10.31 + 10.32 + read_joystick_positive: 10.33 + lda #1 10.34 + rts 10.35 + 10.36 + read_joystick_negative: 10.37 + lda #0 10.38 + sec 10.39 + rts
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/routines/read_joystick_fire.oph Tue Oct 07 23:48:10 2014 +0200 11.3 @@ -0,0 +1,22 @@ 11.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 11.5 +; 11.6 +; This program is free software: you can redistribute it and/or modify 11.7 +; it under the terms of the GNU General Public License as published by 11.8 +; the Free Software Foundation, either version 3 of the License, or 11.9 +; (at your option) any later version. 11.10 +; 11.11 +; This program is distributed in the hope that it will be useful, 11.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 11.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.14 +; GNU General Public License for more details. 11.15 +; 11.16 +; You should have received a copy of the GNU General Public License 11.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 11.18 + 11.19 +; read_joystick_fire: ; Returns with carry set if a button is pressed; 11.20 + ; otherwise returns with carry clear. 11.21 + lda #128 11.22 + ldx #0 11.23 + jsr $fff4 11.24 + cpx #$01 ; If X>=1 then set the carry flag. 11.25 + rts
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/routines/wait_for_key.oph Tue Oct 07 23:48:10 2014 +0200 12.3 @@ -0,0 +1,23 @@ 12.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk> 12.5 +; 12.6 +; This program is free software: you can redistribute it and/or modify 12.7 +; it under the terms of the GNU General Public License as published by 12.8 +; the Free Software Foundation, either version 3 of the License, or 12.9 +; (at your option) any later version. 12.10 +; 12.11 +; This program is distributed in the hope that it will be useful, 12.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of 12.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12.14 +; GNU General Public License for more details. 12.15 +; 12.16 +; You should have received a copy of the GNU General Public License 12.17 +; along with this program. If not, see <http://www.gnu.org/licenses/>. 12.18 + 12.19 +; wait_for_key: ; A=key 12.20 + 12.21 + sta $70 12.22 + wait_for_key_loop: 12.23 + ldx $70 12.24 + jsr check_key 12.25 + bne wait_for_key_loop 12.26 + rts
