castleraider

changeset 299:fee41b81b008

Added a title screen to the game itself.
author David Boddie <david@boddie.org.uk>
date Sat Apr 05 18:32:11 2014 +0200
parents 8627e554e78a
children 2cc46aa21ee8
files build.py code.oph levels/default.txt loader.oph monsters.oph plotting.oph title.txt tools/makelevels.py
diffstat 8 files changed, 175 insertions(+), 24 deletions(-) [+]
line diff
     1.1 --- a/build.py	Fri Apr 04 00:50:20 2014 +0200
     1.2 +++ b/build.py	Sat Apr 05 18:32:11 2014 +0200
     1.3 @@ -217,6 +217,12 @@
     1.4      # Initial displacements for the rows.
     1.5      initial_row_offsets           = row_indices + 0x10
     1.6      
     1.7 +    # Store the in-game title data above the working data - this is done in the
     1.8 +    # loader.
     1.9 +    title_data_address = initial_row_offsets + 0x10
    1.10 +    
    1.11 +    # Permanent data
    1.12 +    
    1.13      # Level data
    1.14      level_data_start = data_start
    1.15      
    1.16 @@ -309,6 +315,34 @@
    1.17      
    1.18      title_data = makesprites.read_title("images/title.png")
    1.19      
    1.20 +    # Encode the in-game title data.
    1.21 +    title_data_oph = "title_data:\n"
    1.22 +    
    1.23 +    title_rows = 0
    1.24 +    for line in open("title.txt").readlines():
    1.25 +    
    1.26 +        line = line.rstrip("\n")
    1.27 +        title_data_oph += ".byte "
    1.28 +        
    1.29 +        for i in range(0, 40, 4):
    1.30 +        
    1.31 +            byte = 0
    1.32 +            shift = 0
    1.33 +            for char in line[i:i + 4]:
    1.34 +                byte = byte | (".@#+".index(char) << shift)
    1.35 +                shift += 2
    1.36 +            
    1.37 +            title_data_oph += "$%02x" % byte
    1.38 +            if i < 36:
    1.39 +                title_data_oph += ", "
    1.40 +        
    1.41 +        title_data_oph += "\n"
    1.42 +        title_rows += 1
    1.43 +    
    1.44 +    title_data_oph += "\ntitle_end:\n.alias title_length [title_end - title_data]\n"
    1.45 +    
    1.46 +    open("title-data.oph", "w").write(title_data_oph)
    1.47 +    
    1.48      # Create the contents of a file containing constant values.
    1.49      
    1.50      constants_oph = (
    1.51 @@ -520,6 +554,12 @@
    1.52               monster_right_offset,
    1.53               monster_right_max_offset)
    1.54      
    1.55 +    constants_oph += (
    1.56 +        ".alias title_data_address              $%x\n"
    1.57 +        ".alias title_rows                      %i\n"
    1.58 +        "\n"
    1.59 +        ) % (title_data_address, title_rows)
    1.60 +    
    1.61      scenery_rows = 16
    1.62      extra_rows = 7
    1.63      top_char_row, top_monster_row, top_row = 0, 0, 0
    1.64 @@ -613,7 +653,7 @@
    1.65          ) % ((code_start,) + address_length_end(code_start, code) + \
    1.66               (len(markers),))
    1.67      
    1.68 -    open("constants.oph", "w").write(extras_oph)
    1.69 +    open("loader-constants.oph", "w").write(extras_oph)
    1.70      
    1.71      system("ophis loader.oph -o LOADER")
    1.72      loader_code = open("LOADER").read() + markers + title_data
     2.1 --- a/code.oph	Fri Apr 04 00:50:20 2014 +0200
     2.2 +++ b/code.oph	Sat Apr 05 18:32:11 2014 +0200
     2.3 @@ -25,8 +25,11 @@
     2.4      lda #2
     2.5      jsr change_palette
     2.6  
     2.7 +    jsr plot_title
     2.8 +
     2.9      jsr show_bank2          ; Show bank 2 since this is where the output of OS
    2.10                              ; calls will appear.
    2.11 +
    2.12      ldx #0
    2.13      title_text_loop:
    2.14          lda title_text,x
    2.15 @@ -1103,8 +1106,8 @@
    2.16  ;    clc
    2.17  ;    rts
    2.18  
    2.19 -title_text: .byte 26, 31, 2, 20, 17, 2, "Press ", 17, 3, "SPACE/FIRE"
    2.20 -            .byte     31, 6, 21, 17, 2, "to play"
    2.21 +title_text: .byte 26, 31, 2, 26, 17, 2, "Press ", 17, 3, "SPACE/FIRE"
    2.22 +            .byte     31, 6, 28, 17, 2, "to play"
    2.23  title_text_end:
    2.24  
    2.25  .include "screen.oph"
     3.1 --- a/levels/default.txt	Fri Apr 04 00:50:20 2014 +0200
     3.2 +++ b/levels/default.txt	Sat Apr 05 18:32:11 2014 +0200
     3.3 @@ -139,4 +139,3 @@
     3.4  ...................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................................@@@@@@@@@@@@@@@@@@@..........................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.........@@@@@@@@@@@@@............................++++++######################################################################################################################################+++.........................................
     3.5  ...................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@......----..................................NNN@@@@@@@@@@@@@@@@@@@.......>..................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..>......@@@@@@@@@@@@@..>..........+++++++++++++++###############################################################################################################################################++++++++++...............................
     3.6  ...................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............@@@@@@@@@@@@@@@@@@......@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@########################################################################################################################################################################+++++++++++++++++++++++++++++++
     3.7 -
     4.1 --- a/loader.oph	Fri Apr 04 00:50:20 2014 +0200
     4.2 +++ b/loader.oph	Sat Apr 05 18:32:11 2014 +0200
     4.3 @@ -15,9 +15,11 @@
     4.4  
     4.5  .org $3500
     4.6  
     4.7 -.include "constants.oph"
     4.8 +.include "loader-constants.oph"
     4.9  
    4.10  main:
    4.11 +    jsr move_title_data     ; Move the title data into the temporary data area.
    4.12 +
    4.13      lda #22         ; MODE 5
    4.14      jsr $ffee
    4.15      lda #5
    4.16 @@ -479,6 +481,50 @@
    4.17              .byte "GNU GPL v.3 or later"
    4.18  title_text_end:
    4.19  
    4.20 +; In-game title data handling routines and data.
    4.21 +
    4.22 +move_title_data:
    4.23 +
    4.24 +    ldx #0
    4.25 +    ldy #0
    4.26 +
    4.27 +    lda #<title_data
    4.28 +    sta $70
    4.29 +    lda #>title_data
    4.30 +    sta $71
    4.31 +
    4.32 +    lda #<title_data_address
    4.33 +    sta $72
    4.34 +    lda #>title_data_address
    4.35 +    sta $73
    4.36 +
    4.37 +    move_title_data_loop:
    4.38 +
    4.39 +        clc
    4.40 +        lda ($70),y
    4.41 +        sta ($72),y
    4.42 +
    4.43 +        lda $70
    4.44 +        adc #1
    4.45 +        sta $70
    4.46 +        lda $71
    4.47 +        adc #0
    4.48 +        sta $71
    4.49 +        clc
    4.50 +
    4.51 +        inc $72 ; The destination address falls within a page, so we only need
    4.52 +                ; to update the lower byte of the address.
    4.53 +        inx
    4.54 +        cpx #title_length
    4.55 +        bne move_title_data_loop
    4.56 +
    4.57 +    clc
    4.58 +    rts
    4.59 +
    4.60 +.include "title-data.oph"
    4.61 +
    4.62 +; Flag drawing routines
    4.63 +
    4.64  .alias title_start_address $5e48
    4.65  .alias title_upper_address $5e4c
    4.66  .alias title_lower_address $5f84
     5.1 --- a/monsters.oph	Fri Apr 04 00:50:20 2014 +0200
     5.2 +++ b/monsters.oph	Sat Apr 05 18:32:11 2014 +0200
     5.3 @@ -128,33 +128,22 @@
     5.4  
     5.5      lda bank_number
     5.6      bne plot_monsters_bank2
     5.7 -    beq plot_monsters_bank1
     5.8  
     5.9  plot_monsters_bank1:            ; Entry point for plotting monsters on bank 1.
    5.10  
    5.11 -    jsr set_monsters_bank1
    5.12 +    lda #<plot_monster_bank1
    5.13 +    sta $7a
    5.14 +    lda #>plot_monster_bank1
    5.15 +    sta $7b
    5.16      jmp plot_monsters_pre_loop
    5.17  
    5.18  plot_monsters_bank2:            ; Entry point for plotting monsters on bank 2.
    5.19  
    5.20 -    jsr set_monsters_bank2
    5.21 -    jmp plot_monsters_pre_loop
    5.22 -
    5.23 -set_monsters_bank1:             ; General routine for setting the monster
    5.24 -                                ; plotting routine. Could be moved into
    5.25 -    lda #<plot_monster_bank1    ; plot_monsters_bank1 later.
    5.26 -    sta $7a
    5.27 -    lda #>plot_monster_bank1
    5.28 -    sta $7b
    5.29 -    rts
    5.30 -
    5.31 -set_monsters_bank2:             ; General routine for setting the monster
    5.32 -                                ; plotting routine. Could be moved into
    5.33 -    lda #<plot_monster_bank2    ; plot_monsters_bank2 later.
    5.34 +    lda #<plot_monster_bank2
    5.35      sta $7a
    5.36      lda #>plot_monster_bank2
    5.37      sta $7b
    5.38 -    rts
    5.39 +    jmp plot_monsters_pre_loop
    5.40  
    5.41  plot_monsters_pre_loop:
    5.42  
    5.43 @@ -182,7 +171,7 @@
    5.44      clc
    5.45      rts
    5.46  
    5.47 -plot_monster:   ; $7a,$7b=sprite plotting routing for a given bank
    5.48 +plot_monster:   ; $7a,$7b=sprite plotting routine for a given bank
    5.49                  ; (set up in set_monsters_bank1 or set_monsters_bank2)
    5.50                  ; A=monster type
    5.51                  ; Y=offset into monster table (0, 5, 10, 15)
     6.1 --- a/plotting.oph	Fri Apr 04 00:50:20 2014 +0200
     6.2 +++ b/plotting.oph	Sat Apr 05 18:32:11 2014 +0200
     6.3 @@ -1506,3 +1506,64 @@
     6.4  vsync:
     6.5      lda #19
     6.6      jmp $fff4
     6.7 +
     6.8 +plot_title:
     6.9 +
    6.10 +    lda #0
    6.11 +    sta $80                 ; Set the row number.
    6.12 +    sta $81                 ; Set the data offset.
    6.13 +
    6.14 +    plot_title_row_loop:
    6.15 +
    6.16 +        lda #0                              ; Initialise the column number.
    6.17 +        sta $7a
    6.18 +
    6.19 +        plot_title_column_loop:
    6.20 +
    6.21 +            ldx $81
    6.22 +            lda title_data_address,x        ; Load the current byte.
    6.23 +            sta $7b
    6.24 +
    6.25 +            plot_title_byte_loop:
    6.26 +
    6.27 +                lda $7b
    6.28 +                and #$03
    6.29 +                jsr read_sprite_address_next    ; Use an internal label to look
    6.30 +                                                ; up the sprite address.
    6.31 +
    6.32 +                lda $7a                         ; Load the column number.
    6.33 +                ldx $80                         ; Load the row number.
    6.34 +                jsr read_screen_address_bank2   ; Sets $72,$73 from A and X.
    6.35 +
    6.36 +                lda $73
    6.37 +                sec
    6.38 +                sbc #$05
    6.39 +                sta $73
    6.40 +                clc
    6.41 +
    6.42 +                jsr plot_tile_bank
    6.43 +
    6.44 +                lda $7b
    6.45 +                ror
    6.46 +                ror
    6.47 +                clc
    6.48 +                sta $7b
    6.49 +
    6.50 +                inc $7a                         ; Increment the column number.
    6.51 +                lda $7a
    6.52 +                and #$03
    6.53 +                bne plot_title_byte_loop        ; Loop if column % 4 != 0.
    6.54 +
    6.55 +            inc $81                     ; Move to the next byte in the data.
    6.56 +
    6.57 +            lda $7a
    6.58 +            cmp #40                     ; Continue plotting until the end of
    6.59 +            bne plot_title_column_loop  ; the row.
    6.60 +
    6.61 +        inc $80
    6.62 +        lda $80
    6.63 +        cmp #title_rows
    6.64 +        bne plot_title_row_loop ; Continue plotting until the end of the title.
    6.65 +
    6.66 +    clc
    6.67 +    rts
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/title.txt	Sat Apr 05 18:32:11 2014 +0200
     7.3 @@ -0,0 +1,13 @@
     7.4 +...@@@@...@@...@@@@@.@@@@@.@.....@@@@@..
     7.5 +..@.......@@..@........@...@.....@......
     7.6 +..@......@..@..@@@@@...@...@.....@@@@...
     7.7 +..@......@@@@.......@..@...@.....@......
     7.8 +..@.....@....@......@..@...@.....@......
     7.9 +...@@@@.@....@.@@@@@...@...@@@@@.@@@@@..
    7.10 +........................................
    7.11 +..++++....++...+++++.++++..+++++.++++...
    7.12 +..#...+...##.....#...#...+.#.....#...+..
    7.13 +..#...#..+..+....#...#...#.#+++..#...#..
    7.14 +..#+++...#++#....#...#...#.#.....#+++...
    7.15 +..#...+.+....+...#...#...#.#.....#...+..
    7.16 +..#...#.#....#.++#++.#+++..#++++.#...#..
     8.1 --- a/tools/makelevels.py	Fri Apr 04 00:50:20 2014 +0200
     8.2 +++ b/tools/makelevels.py	Sat Apr 05 18:32:11 2014 +0200
     8.3 @@ -62,7 +62,7 @@
     8.4  
     8.5  # Collectable items after the first 16 tiles are ignored by the editor.
     8.6  
     8.7 -tile_order = (".", "@", "#", "=", "+", "-", "X", "|",   # regular tiles
     8.8 +tile_order = (".", "@", "#", "+", "=", "-", "X", "|",   # regular tiles
     8.9                "?", "[", "]", "/", "\\", "{", "I", "%",  #
    8.10                "K", "L", "M", "N", "q", "C", "D", "E", "F")   # collectable tiles
    8.11