junglejourney
changeset 0:9b4b52cca2fe
Started working on a pseudo-random map-based game.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Fri Jul 22 02:00:13 2011 +0200 |
| parents | |
| children | 5e4bc7f3ef15 |
| files | LOADER UEFfile.py build.py makesprites.py mapcode.oph |
| diffstat | 5 files changed, 465 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LOADER Fri Jul 22 02:00:13 2011 +0200 1.3 @@ -0,0 +1,23 @@ 1.4 +AUTO 1.5 +MODE 6 1.6 +OSCLI("LOAD CODE") 1.7 +OSCLI("LOAD SPRITES") 1.8 + 1.9 +MODE 5 1.10 +VDU 23,1,0;0;0;0; 1.11 +VDU 19,2,2,0,0,0 1.12 +VDU 19,3,4,0,0,0 1.13 + 1.14 +?&78=0 1.15 +?&79=0 1.16 + 1.17 +REPEAT 1.18 +CALL &19A9 1.19 + 1.20 +A% = GET 1.21 +IF A%=90 ?&79=?&79-1 1.22 +IF A%=88 ?&79=?&79+1 1.23 +IF A%=58 ?&78=?&78-1 1.24 +IF A%=47 ?&78=?&78+1 1.25 + 1.26 +UNTIL FALSE
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/UEFfile.py Fri Jul 22 02:00:13 2011 +0200 2.3 @@ -0,0 +1,1 @@ 2.4 +../Game/UEFfile.py 2.5 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/build.py Fri Jul 22 02:00:13 2011 +0200 3.3 @@ -0,0 +1,80 @@ 3.4 +#!/usr/bin/env python 3.5 + 3.6 +""" 3.7 +Copyright (C) 2011 David Boddie <david@boddie.org.uk> 3.8 + 3.9 +This program is free software: you can redistribute it and/or modify 3.10 +it under the terms of the GNU General Public License as published by 3.11 +the Free Software Foundation, either version 3 of the License, or 3.12 +(at your option) any later version. 3.13 + 3.14 +This program is distributed in the hope that it will be useful, 3.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 3.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.17 +GNU General Public License for more details. 3.18 + 3.19 +You should have received a copy of the GNU General Public License 3.20 +along with this program. If not, see <http://www.gnu.org/licenses/>. 3.21 +""" 3.22 + 3.23 +import os, sys 3.24 +import UEFfile 3.25 +import makesprites 3.26 + 3.27 +version = "0.1" 3.28 + 3.29 +def system(command): 3.30 + 3.31 + if os.system(command): 3.32 + sys.exit(1) 3.33 + 3.34 +def read_basic(path): 3.35 + 3.36 + t = open(path).read() 3.37 + t = t.replace("\n", "\r") 3.38 + lines = t.rstrip().split("\r") 3.39 + t = "\r".join(lines) + "\r" 3.40 + return t 3.41 + 3.42 + 3.43 +if __name__ == "__main__": 3.44 + 3.45 + if len(sys.argv) != 2: 3.46 + 3.47 + sys.stderr.write("Usage: %s <new UEF file>\n" % sys.argv[0]) 3.48 + sys.exit(1) 3.49 + 3.50 + out_uef_file = sys.argv[1] 3.51 + 3.52 + files = [] 3.53 + 3.54 + system("ophis mapcode.oph CODE") 3.55 + code = open("CODE").read() 3.56 + files.append(("CODE", 0x1900, 0x1900, code)) 3.57 + 3.58 + i = 0 3.59 + while i < len(code): 3.60 + if ord(code[i]) == 0x60: 3.61 + if i + 1 < len(code): 3.62 + print hex(i + 1) 3.63 + i += 1 3.64 + 3.65 + data = makesprites.read_sprites() 3.66 + files.append(("SPRITES", 0x5600, 0x5600, data)) 3.67 + 3.68 + t = read_basic("LOADER") 3.69 + files.append(("LOADER", 0xffff0e00, 0xffff802b, t)) 3.70 + 3.71 + u = UEFfile.UEFfile(creator = 'build.py '+version) 3.72 + u.minor = 6 3.73 + u.import_files(0, files) 3.74 + 3.75 + # Write the new UEF file. 3.76 + try: 3.77 + u.write(out_uef_file, write_emulator_info = False) 3.78 + except UEFfile.UEFfile_error: 3.79 + sys.stderr.write("Couldn't write the new executable to %s.\n" % out_uef_file) 3.80 + sys.exit(1) 3.81 + 3.82 + # Exit 3.83 + sys.exit()
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/makesprites.py Fri Jul 22 02:00:13 2011 +0200 4.3 @@ -0,0 +1,135 @@ 4.4 +#!/usr/bin/env python 4.5 + 4.6 +""" 4.7 +Copyright (C) 2011 David Boddie <david@boddie.org.uk> 4.8 + 4.9 +This program is free software: you can redistribute it and/or modify 4.10 +it under the terms of the GNU General Public License as published by 4.11 +the Free Software Foundation, either version 3 of the License, or 4.12 +(at your option) any later version. 4.13 + 4.14 +This program is distributed in the hope that it will be useful, 4.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 4.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4.17 +GNU General Public License for more details. 4.18 + 4.19 +You should have received a copy of the GNU General Public License 4.20 +along with this program. If not, see <http://www.gnu.org/licenses/>. 4.21 +""" 4.22 + 4.23 +sprites = [ 4.24 + ("0000000000000000",)*24, 4.25 + ("0022200000000000", 4.26 + "0222220000222200", 4.27 + "2222220002222220", 4.28 + "2200222022220022", 4.29 + "2000022022200000", 4.30 + "2000002022200000", 4.31 + "0000002202000000", 4.32 + "0022202220000220", 4.33 + "0222222220022220", 4.34 + "0222202220222220", 4.35 + "2222002220222200", 4.36 + "2220002222222000", 4.37 + "2000000222000000", 4.38 + "0000220220002220", 4.39 + "0002222220022222", 4.40 + "0022002220222202", 4.41 + "2000000222222000", 4.42 + "2200000222200000", 4.43 + "0220220222002200", 4.44 + "0022220222002222", 4.45 + "2222200222022220", 4.46 + "2002000222020000", 4.47 + "0002000222020000", 4.48 + "0002200222200000"), 4.49 + ("0333000003330000", 4.50 + "3000300330003000", 4.51 + "0000033300000333", 4.52 + "0000000000000000", 4.53 + "0033300000333000", 4.54 + "0300330003000300", 4.55 + "3000003330000033", 4.56 + "0000000000000000", 4.57 + "0333000003330000", 4.58 + "3000300030003300", 4.59 + "0000033300000333", 4.60 + "0000000000000000", 4.61 + "3330000033300000", 4.62 + "0003003300030003", 4.63 + "0000333000003330", 4.64 + "0000000000000000", 4.65 + "0333000003330000", 4.66 + "3300300030003000", 4.67 + "0000033300000333", 4.68 + "0000000000000000", 4.69 + "0033300000333000", 4.70 + "0300030003300300", 4.71 + "3000003330000033", 4.72 + "0000000000000000"), 4.73 + ("0022000200000000", 4.74 + "0002202220002000", 4.75 + "0002222200020000", 4.76 + "0000220000220000", 4.77 + "0000220000022000", 4.78 + "0020222000002000", 4.79 + "0222022002002200", 4.80 + "2222022022200202", 4.81 + "0020022222220220", 4.82 + "0000002202000200", 4.83 + "0000002200002200", 4.84 + "0002002200000220", 4.85 + "0022222202002200", 4.86 + "0222022022002000", 4.87 + "0000022002202200", 4.88 + "0200022000022000", 4.89 + "2220022000220000", 4.90 + "0222222020022200", 4.91 + "0020222222202020", 4.92 + "0000220022020000", 4.93 + "0000220000022000", 4.94 + "0000220000202000", 4.95 + "0000220000002000", 4.96 + "0000220000002000") 4.97 + ] 4.98 + 4.99 + 4.100 +def read_sprite(lines): 4.101 + 4.102 + data = "" 4.103 + 4.104 + # Read 8 rows at a time. 4.105 + for row in range(0, len(lines), 8): 4.106 + 4.107 + # Read 4 columns at a time. 4.108 + for column in range(0, len(lines[0]), 4): 4.109 + 4.110 + # Read the rows. 4.111 + for line in lines[row:row + 8]: 4.112 + 4.113 + shift = 3 4.114 + byte = 0 4.115 + for pixel in line[column:column + 4]: 4.116 + 4.117 + if pixel == "1": 4.118 + byte = byte | (0x01 << shift) 4.119 + elif pixel == "2": 4.120 + byte = byte | (0x10 << shift) 4.121 + elif pixel == "3": 4.122 + byte = byte | (0x11 << shift) 4.123 + 4.124 + shift -= 1 4.125 + 4.126 + data += chr(byte) 4.127 + 4.128 + return data 4.129 + 4.130 + 4.131 +def read_sprites(): 4.132 + 4.133 + data = "" 4.134 + 4.135 + for lines in sprites: 4.136 + data += read_sprite(lines) 4.137 + 4.138 + return data
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/mapcode.oph Fri Jul 22 02:00:13 2011 +0200 5.3 @@ -0,0 +1,226 @@ 5.4 +.org $1900 5.5 +unlimited_values: ; $7c,$7d=first,second 5.6 + ; Add $7c and $7d, store the result in $7d and the original 5.7 + ; $7d value in $7c, returning the sum in the accumulator. 5.8 + lda $7c 5.9 + sta $7b 5.10 + lda $7d 5.11 + sta $7c 5.12 + adc $7b 5.13 + sta $7d 5.14 + clc 5.15 + rts 5.16 + 5.17 +next_value: 5.18 + lda $7d 5.19 + 5.20 +divide_loop: 5.21 + cmp #9 5.22 + bmi after_divide_loop 5.23 + sec 5.24 + sbc #9 5.25 + jmp divide_loop 5.26 + 5.27 +after_divide_loop: 5.28 + clc 5.29 + and #3 5.30 + sta $7b 5.31 + rts 5.32 + 5.33 +make_room: ; $78,$79=i,j 5.34 + ; $7e,$7f=first,second 5.35 + lda $7f 5.36 + adc $79 5.37 + sta $7c 5.38 + sec 5.39 + lda #100 5.40 + sbc $78 5.41 + sec 5.42 + sbc $7e 5.43 + sta $7d 5.44 + clc 5.45 + ; Discard the first ten values. 5.46 + ldx #10 5.47 +make_room_loop0: 5.48 + jsr unlimited_values 5.49 + dex 5.50 + bne make_room_loop0 5.51 + rts 5.52 + 5.53 + 5.54 +plot: ; $70,$71=source address 5.55 + ; $72,$73=destination address 5.56 + ldy #$1f 5.57 +plotloop0: 5.58 + lda ($70),y 5.59 + sta ($72),y 5.60 + dey 5.61 + bpl plotloop0 5.62 + 5.63 + lda $72 5.64 + adc #$20 5.65 + sta $72 5.66 + lda $73 5.67 + adc #$01 5.68 + sta $73 ; next line minus 0x20 5.69 + clc 5.70 + 5.71 + ldy #$3f 5.72 +plotloop1: 5.73 + lda ($70),y 5.74 + sta ($72),y 5.75 + dey 5.76 + cpy #$20 5.77 + bpl plotloop1 5.78 + 5.79 + lda $72 5.80 + adc #$20 5.81 + sta $72 5.82 + lda $73 5.83 + adc #$01 5.84 + sta $73 ; next line minus 0x20 5.85 + clc 5.86 + 5.87 + ldy #$5f 5.88 +plotloop2: 5.89 + lda ($70),y 5.90 + sta ($72),y 5.91 + dey 5.92 + cpy #$40 5.93 + bpl plotloop2 5.94 + 5.95 + sec 5.96 + lda $72 5.97 + sbc #$20 5.98 + sta $72 5.99 + lda $73 5.100 + sbc #$02 5.101 + sta $73 ; back two lines minus 0x20 5.102 + clc 5.103 + 5.104 + rts 5.105 + 5.106 + 5.107 +plot_tile: ; $74,$75=sprite area address 5.108 + ; $7b=tile number 5.109 + ; $72,$73=screen position 5.110 + 5.111 + ; Calculate the sprite address ($74,$75 + $76*0x60). 5.112 + lda $74 5.113 + sta $70 5.114 + lda $75 5.115 + sta $71 5.116 + lda $7b 5.117 + tax 5.118 + 5.119 + cpx #0 5.120 + beq after_multiply_loop 5.121 + 5.122 +multiply_loop: 5.123 + 5.124 + clc 5.125 + lda $70 5.126 + adc #$60 5.127 + sta $70 5.128 + lda $71 5.129 + adc #0 5.130 + sta $71 5.131 + clc 5.132 + dex 5.133 + bne multiply_loop 5.134 + 5.135 +after_multiply_loop: 5.136 + clc 5.137 + jsr plot 5.138 + rts 5.139 + 5.140 +plot_room: ; $78,$79 = i,j 5.141 + lda #0 5.142 + sta $7e 5.143 + sta $7f 5.144 + 5.145 + lda #$e0 5.146 + sta $72 5.147 + lda #$5b 5.148 + sta $73 ; $72,$73 = screen position 5.149 + 5.150 + lda #$00 5.151 + sta $74 5.152 + lda #$56 5.153 + sta $75 ; $74,$75 = sprite area address 5.154 + 5.155 + lda #0 5.156 + sta $7e ; first 5.157 + sta $7f ; second 5.158 + 5.159 + jsr make_room 5.160 + 5.161 +row_loop: 5.162 + 5.163 + lda #8 5.164 + sta $7a 5.165 +column_loop: 5.166 + jsr unlimited_values 5.167 + jsr next_value 5.168 + jsr plot_tile 5.169 + 5.170 + sec 5.171 + lda $7a 5.172 + sbc #1 5.173 + sta $7a 5.174 + clc 5.175 + 5.176 + cmp #0 5.177 + bne column_loop 5.178 + clc 5.179 + 5.180 + lda $72 5.181 + adc #$c0 5.182 + sta $72 5.183 + lda $73 5.184 + adc #$02 5.185 + sta $73 5.186 + clc 5.187 + cmp #$79 5.188 + beq end_rows 5.189 + 5.190 + jmp row_loop 5.191 + 5.192 +end_rows: 5.193 + rts 5.194 + 5.195 + 5.196 +test_plot: 5.197 + lda #$60 5.198 + sta $70 5.199 + lda #$56 5.200 + sta $71 5.201 + lda #0 5.202 + sta $72 5.203 + lda #$58 5.204 + sta $73 5.205 + jsr plot 5.206 + rts 5.207 + 5.208 +test_plot_tile: 5.209 + lda #$00 5.210 + sta $74 5.211 + lda #$56 5.212 + sta $75 5.213 + lda #1 5.214 + sta $7d 5.215 + lda #0 5.216 + sta $72 5.217 + lda #$58 5.218 + sta $73 5.219 +test_plot_tile_loop: 5.220 + lda $7d 5.221 + sta $7b 5.222 + jsr plot_tile 5.223 + clc 5.224 + lda $7d 5.225 + adc #1 5.226 + sta $7d 5.227 + cmp #4 5.228 + bne test_plot_tile_loop 5.229 + rts
