castleraider

changeset 326:061d634f7bc5

Moved the mode change and palette code back into the loader. Changed the shared code labels so that calls can be made to addresses that at least look like ordinary labels. Removed unused interrupt checks from the title screen animation code.
author David Boddie <david@boddie.org.uk>
date Sun Oct 05 02:11:53 2014 +0200
parents 0849cd711949
children af97e2fac44b ac4e97a8c699
files build.py code.oph loader.oph
diffstat 3 files changed, 100 insertions(+), 152 deletions(-) [+]
line diff
     1.1 --- a/build.py	Sun Oct 05 00:38:04 2014 +0200
     1.2 +++ b/build.py	Sun Oct 05 02:11:53 2014 +0200
     1.3 @@ -124,38 +124,20 @@
     1.4      clc
     1.5      rts
     1.6  """),
     1.7 -("set_core_palette", """
     1.8 +("check_key", """ ; x=key code
     1.9 +    lda #129    ; returns y=255 or 0
    1.10 +    ldy #255
    1.11 +    jsr $fff4
    1.12 +    cpy #255    ; Perform the check for a pressed key here.
    1.13 +    rts
    1.14 +"""),
    1.15 +("wait_for_key", """ ; A=key
    1.16  
    1.17 -    lda #2
    1.18      sta $70
    1.19 -    lda #2
    1.20 -    sta $71
    1.21 -    jsr set_palette
    1.22 -
    1.23 -    lda #3
    1.24 -    sta $70
    1.25 -    lda #3
    1.26 -    sta $71
    1.27 -    jsr set_palette
    1.28 -
    1.29 -    rts
    1.30 -
    1.31 -set_palette:
    1.32 -                    ; $70=logical colour
    1.33 -                    ; $71=physical colour
    1.34 -    lda $70
    1.35 -    sta $3dfb
    1.36 -    lda $71
    1.37 -    sta $3dfc
    1.38 -    lda #0
    1.39 -    sta $3dfd
    1.40 -    sta $3dfe
    1.41 -    sta $3dff
    1.42 -
    1.43 -    lda #$c         
    1.44 -    ldx #$fb
    1.45 -    ldy #$3d
    1.46 -    jsr $fff1
    1.47 +    wait_for_key_loop:
    1.48 +        ldx $70
    1.49 +        jsr check_key
    1.50 +        bne wait_for_key_loop
    1.51      rts
    1.52  """)]
    1.53  
    1.54 @@ -214,7 +196,6 @@
    1.55          ".alias in_game_title_text_length       %(in_game_title_text_length)i\n"
    1.56          ".alias in_game_game_over_text_address  $%(in_game_game_over_text_address)x\n"
    1.57          ".alias in_game_game_over_text_length   %(in_game_game_over_text_length)i\n"
    1.58 -        ".alias in_game_completion_address      $%(in_game_completion_address)x\n"
    1.59      )
    1.60      
    1.61      details = {
    1.62 @@ -229,16 +210,22 @@
    1.63      routine_address = in_game_title_routines_address
    1.64      for name, routine in title_data_oph_routines:
    1.65      
    1.66 -        routine = name + ":" + (routine % details)
    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 +        # aliases so that the routine can call any previously defined routines.
    1.71 +        details["routine_address"] = routine_address
    1.72 +        routine = (routine % details) + "\n" + (labels % details)
    1.73 +        
    1.74          open("temp.oph", "w").write(routine)
    1.75          system("ophis temp.oph -o TEMP")
    1.76          
    1.77          # Include the routine in the title data file.
    1.78 -        title_data_oph += routine + "\n"
    1.79 +        title_data_oph += encode_data(open("TEMP").read()) + "\n"
    1.80          
    1.81          # Add the run-time address to the constants.
    1.82 -        labels += ".alias " + name + "_address" + (" $%0x\n" % routine_address)
    1.83 -        details[name + "_address"] = routine_address
    1.84 +        labels += ".alias " + name + (" $%0x\n" % routine_address)
    1.85 +        details[name] = routine_address
    1.86          
    1.87          # Update the routine address.
    1.88          routine_address += os.stat("TEMP")[stat.ST_SIZE]
    1.89 @@ -248,9 +235,11 @@
    1.90      
    1.91      # The completion code is stored after the title routines.
    1.92      details["in_game_completion_address"] = routine_address
    1.93 +    labels += ".alias in_game_completion_address      $%(in_game_completion_address)x\n"
    1.94      
    1.95 +    print "Assembling ending.oph at $%x" % routine_address
    1.96      ending = open("ending.oph").read()
    1.97 -    ending = ending % {"in_game_completion_address": routine_address}
    1.98 +    ending = (ending % details) + "\n" + (labels % details)
    1.99      open("temp.oph", "w").write(ending)
   1.100      
   1.101      system("ophis temp.oph -o TEMP")
   1.102 @@ -784,14 +773,6 @@
   1.103               ("PANEL", panel_address, panel_address, panel),
   1.104               ("CODE", code_start, code_start, code)]
   1.105      
   1.106 -    #from tools.compress import Compressor
   1.107 -    #c = Compressor()
   1.108 -    #for info in files:
   1.109 -    #    data = info[-1]
   1.110 -    #    compressed = c.compress(data)
   1.111 -    #    uncompressed = c.uncompress(compressed)
   1.112 -    #    print info[0], len(data), len(compressed), data == uncompressed
   1.113 -    
   1.114      loader_size = len(loader_code)
   1.115      print
   1.116      print "%i bytes (%04x) of loader code" % (loader_size, loader_size)
   1.117 @@ -807,8 +788,9 @@
   1.118      print
   1.119      
   1.120      # Calculate the amount of working space used.
   1.121 +    # 0xcfb is the start of a block of memory used for palette operations.
   1.122      
   1.123 -    print "Working data area runs from 0b00 to %04x (%i bytes free)" % (working_end, 0xd00 - working_end)
   1.124 +    print "Working data area runs from 0b00 to %04x (%i bytes free)" % (working_end, 0xcfb - working_end)
   1.125      print
   1.126      
   1.127      # Calculate the amount of memory used for each file.
     2.1 --- a/code.oph	Sun Oct 05 00:38:04 2014 +0200
     2.2 +++ b/code.oph	Sun Oct 05 02:11:53 2014 +0200
     2.3 @@ -30,7 +30,7 @@
     2.4      jsr show_bank2          ; Show bank 2 since this is where the output of OS
     2.5                              ; calls will appear.
     2.6  
     2.7 -    jsr print_title_text_address
     2.8 +    jsr print_title_text
     2.9  
    2.10      ; Wait for the SPACE key or fire button to be pressed.
    2.11      main_start_wait_loop:
    2.12 @@ -189,6 +189,8 @@
    2.13              cmp #finish_scroll_offset_high
    2.14              bne main_loop_check_monsters
    2.15  
    2.16 +            ; Jump to an address in the working area where the completion code
    2.17 +            ; was copied to by the loader.
    2.18              jsr in_game_completion_address
    2.19  
    2.20          main_loop_check_monsters:
    2.21 @@ -245,22 +247,13 @@
    2.22      jsr show_bank2          ; Show bank 2 since this is where the output of OS
    2.23                              ; calls will appear.
    2.24  
    2.25 -    jsr print_game_over_text_address
    2.26 +    jsr print_game_over_text
    2.27  
    2.28      lda #157        ; (SPACE)
    2.29      jsr wait_for_key
    2.30  
    2.31      jmp main
    2.32  
    2.33 -wait_for_key:   ; A=key
    2.34 -
    2.35 -    sta $70
    2.36 -    wait_for_key_loop:
    2.37 -        ldx $70
    2.38 -        jsr check_key
    2.39 -        bne wait_for_key_loop
    2.40 -    rts
    2.41 -
    2.42  player_move:
    2.43  
    2.44      lda player_jumping
    2.45 @@ -389,13 +382,6 @@
    2.46  
    2.47      jmp player_enter                ; Branch then exit.
    2.48  
    2.49 -check_key:      ; x=key code
    2.50 -    lda #129    ; returns y=255 or 0
    2.51 -    ldy #255
    2.52 -    jsr $fff4
    2.53 -    cpy #255    ; Perform the check for a pressed key here.
    2.54 -    rts
    2.55 -
    2.56  check_beneath:      ; Checks beneath the character for solid tiles.
    2.57                      ; Sets player_falling if none exist.
    2.58      lda player_ys
    2.59 @@ -969,13 +955,12 @@
    2.60  
    2.61      jump_to_tracking_offset_left:
    2.62      
    2.63 -    sec
    2.64 +    dec scroll_offset_low
    2.65      lda scroll_offset_low
    2.66 -    sbc #1
    2.67 -    sta scroll_offset_low
    2.68 -    lda scroll_offset_high
    2.69 -    sbc #0
    2.70 -    sta scroll_offset_high
    2.71 +    cmp #$ff
    2.72 +    bne jump_to_tracking_offset_left_next
    2.73 +    dec scroll_offset_high
    2.74 +    jump_to_tracking_offset_left_next:
    2.75      clc
    2.76  
    2.77      jsr scroll_left_update_monsters
    2.78 @@ -984,12 +969,12 @@
    2.79  
    2.80      jump_to_tracking_offset_right:
    2.81  
    2.82 +    inc scroll_offset_low
    2.83      lda scroll_offset_low
    2.84 -    adc #1
    2.85 -    sta scroll_offset_low
    2.86 -    lda scroll_offset_high
    2.87 -    adc #0
    2.88 -    sta scroll_offset_high
    2.89 +    cmp #0
    2.90 +    bne jump_to_tracking_offset_right_next
    2.91 +    inc scroll_offset_high
    2.92 +    jump_to_tracking_offset_right_next:
    2.93      clc
    2.94  
    2.95      jsr scroll_right_update_monsters
     3.1 --- a/loader.oph	Sun Oct 05 00:38:04 2014 +0200
     3.2 +++ b/loader.oph	Sun Oct 05 02:11:53 2014 +0200
     3.3 @@ -20,7 +20,7 @@
     3.4  main:
     3.5      jsr move_title_data     ; Move the title data into the temporary data area.
     3.6  
     3.7 -    lda #22         ; MODE 5
     3.8 +    lda #22
     3.9      jsr $ffee
    3.10      lda #5
    3.11      jsr $ffee
    3.12 @@ -36,7 +36,7 @@
    3.13          dex
    3.14          bpl cursor_loop
    3.15  
    3.16 -    jsr set_core_palette_address
    3.17 +    jsr set_core_palette
    3.18  
    3.19      ; Load the sprites.
    3.20  
    3.21 @@ -81,9 +81,6 @@
    3.22  
    3.23      jsr init_update_title
    3.24  
    3.25 -    lda #0                  ; clear polling flag to indicate that the animation
    3.26 -    sta $8f                 ; is not running as an interrupt routine
    3.27 -
    3.28      title_animation_loop:
    3.29  
    3.30          jsr update_title
    3.31 @@ -144,9 +141,6 @@
    3.32  
    3.33      ; Configure the interrupt routine.
    3.34  
    3.35 -    lda #1                  ; set polling flag to ensure that the interrupt
    3.36 -    sta $8f                 ; routine gives enough time to the OS
    3.37 -
    3.38      jsr cassette_init
    3.39  
    3.40      ldx #0
    3.41 @@ -221,6 +215,37 @@
    3.42      txa
    3.43      jmp $ffee
    3.44  
    3.45 +set_core_palette:
    3.46 +
    3.47 +    lda #2
    3.48 +    sta $70
    3.49 +    lda #2
    3.50 +    sta $71
    3.51 +    jsr set_palette
    3.52 +
    3.53 +    lda #3
    3.54 +    sta $70
    3.55 +    lda #3
    3.56 +    sta $71         ; drop through into the subroutine
    3.57 +
    3.58 +set_palette:
    3.59 +                    ; $70=logical colour
    3.60 +                    ; $71=physical colour
    3.61 +    lda $70
    3.62 +    sta $cfb
    3.63 +    lda $71
    3.64 +    sta $cfc
    3.65 +    lda #0
    3.66 +    sta $cfd
    3.67 +    sta $cfe
    3.68 +    sta $cff
    3.69 +
    3.70 +    lda #$c         
    3.71 +    ldx #$fb
    3.72 +    ldy #$0c
    3.73 +    jsr $fff1
    3.74 +    rts
    3.75 +
    3.76  copy_panel:
    3.77  
    3.78      lda #$00
    3.79 @@ -239,36 +264,29 @@
    3.80          lda ($70),y
    3.81          sta ($72),y
    3.82  
    3.83 +        inc $70
    3.84          lda $70
    3.85 -        adc #1
    3.86 -        sta $70
    3.87 -        lda $71
    3.88 -        adc #0
    3.89 -        sta $71
    3.90 +        cmp #0
    3.91 +        bne copy_top_panel_loop_next1
    3.92 +        inc $71
    3.93 +        copy_top_panel_loop_next1:
    3.94          clc
    3.95  
    3.96 +        inc $72
    3.97          lda $72
    3.98 -        adc #1
    3.99 -        sta $72
   3.100 -        lda $73
   3.101 -        adc #0
   3.102 -        sta $73
   3.103 +        cmp #0
   3.104 +        bne copy_top_panel_loop_next2
   3.105 +        inc $73
   3.106 +        copy_top_panel_loop_next2:
   3.107          clc
   3.108  
   3.109 +        lda $73
   3.110          cmp #$5d
   3.111          bne copy_top_panel_loop
   3.112  
   3.113      clc
   3.114      rts
   3.115  
   3.116 -check_key:      ; x=key code
   3.117 -    lda #129    ; returns Z flag set if the key is pressed
   3.118 -    ldy #255
   3.119 -    jsr $fff4
   3.120 -    cpy #255
   3.121 -    rts
   3.122 -
   3.123 -
   3.124  plot8x24_y0:            ; $70,$71=source address
   3.125                          ; $72,$73=destination address
   3.126  
   3.127 @@ -473,20 +491,20 @@
   3.128          lda ($70),y
   3.129          sta ($72),y
   3.130  
   3.131 +        inc $70
   3.132          lda $70
   3.133 -        adc #1
   3.134 -        sta $70
   3.135 -        lda $71
   3.136 -        adc #0
   3.137 -        sta $71
   3.138 +        cmp #0
   3.139 +        bne move_title_data_loop_next1
   3.140 +        inc $71
   3.141 +        move_title_data_loop_next1:
   3.142          clc
   3.143  
   3.144 +        inc $72
   3.145          lda $72
   3.146 -        adc #1
   3.147 -        sta $72
   3.148 -        lda $73
   3.149 -        adc #0
   3.150 -        sta $73
   3.151 +        cmp #0
   3.152 +        bne move_title_data_loop_next2
   3.153 +        inc $73
   3.154 +        move_title_data_loop_next2:
   3.155          clc
   3.156  
   3.157          lda $70
   3.158 @@ -499,10 +517,6 @@
   3.159      clc
   3.160      rts
   3.161  
   3.162 -in_game_data_start:
   3.163 -.include "title-data-and-ending.oph"
   3.164 -in_game_data_end:
   3.165 -
   3.166  ; Flag drawing routines
   3.167  
   3.168  .alias title_start_address $5e48
   3.169 @@ -722,16 +736,6 @@
   3.170      dey
   3.171      sta ($72),y
   3.172  
   3.173 -    lda $8f                 ; if not running as an interrupt, jump straight
   3.174 -    beq update_column_loop  ; into the column loop
   3.175 -
   3.176 -    lda #<update_column_loop
   3.177 -    sta $7a
   3.178 -    lda #>update_column_loop
   3.179 -    sta $7b
   3.180 -
   3.181 -    rts
   3.182 -
   3.183  update_column_loop:
   3.184  
   3.185          lda $81             ; load the current colour
   3.186 @@ -789,10 +793,7 @@
   3.187          eor #$f0                    ; red <-> yellow
   3.188          sta $81
   3.189  
   3.190 -        lda $8f
   3.191 -        beq update_column_loop
   3.192 -
   3.193 -        rts                 ; keep $7a,$7b the same (loop)
   3.194 +        jmp update_column_loop
   3.195  
   3.196      update_column_loop_next:
   3.197      clc
   3.198 @@ -817,17 +818,6 @@
   3.199      dey
   3.200      sta ($76),y
   3.201  
   3.202 -    lda $8f                 ; if not running as an interrupt, jump straight
   3.203 -    beq update_title3       ; into the next part of the routine
   3.204 -
   3.205 -    lda #<update_title3
   3.206 -    sta $7a
   3.207 -    lda #>update_title3
   3.208 -    sta $7b
   3.209 -
   3.210 -    clc
   3.211 -    rts
   3.212 -
   3.213  update_title3:
   3.214  
   3.215      sec
   3.216 @@ -860,21 +850,8 @@
   3.217      beq update_title_loop_exit
   3.218      inc $84
   3.219  
   3.220 -    lda $8f
   3.221 -    bne update_title3_break
   3.222 -
   3.223      jmp update_title2
   3.224  
   3.225 -    update_title3_break:
   3.226 -
   3.227 -    lda #<update_title2
   3.228 -    sta $7a
   3.229 -    lda #>update_title2
   3.230 -    sta $7b
   3.231 -
   3.232 -    clc                         ; loop back to update_title2
   3.233 -    rts
   3.234 -
   3.235      update_title_loop_exit:
   3.236  
   3.237      lda $78
   3.238 @@ -1044,4 +1021,8 @@
   3.239      pla
   3.240      jmp (cassette_original_irq1v)
   3.241  
   3.242 +in_game_data_start:
   3.243 +.include "title-data-and-ending.oph"
   3.244 +in_game_data_end:
   3.245 +
   3.246  cassette_markers: