castleraider

changeset 294:f8a3753a9c53

Another memory saving optimisation.
author David Boddie <david@boddie.org.uk>
date Mon Mar 31 00:13:33 2014 +0200
parents 0511bde814c4
children 2710f1180f5e
files monsters.oph
diffstat 1 files changed, 47 insertions(+), 53 deletions(-) [+]
line diff
     1.1 --- a/monsters.oph	Sun Mar 30 23:39:32 2014 +0200
     1.2 +++ b/monsters.oph	Mon Mar 31 00:13:33 2014 +0200
     1.3 @@ -708,55 +708,6 @@
     1.4      ldy $8d
     1.5      rts
     1.6  
     1.7 -check_monster_player:
     1.8 -
     1.9 -    lda ($86),y                     ; Load monster type and dx value.
    1.10 -    and #monster_dx_bit
    1.11 -    lsr
    1.12 -    sta $80
    1.13 -
    1.14 -    iny
    1.15 -    lda ($86),y                     ; Load monster x offset.
    1.16 -    asl                             ; Convert to half columns.
    1.17 -    adc $80                         ; Add dx to x.
    1.18 -
    1.19 -    cmp #35                         ; Compare the right edge to the character's
    1.20 -    bcc check_monster_common_exit   ; left edge and exit if too far left.
    1.21 -    cmp #42                         ; Compare the left edge to the character's
    1.22 -    bcs check_monster_common_exit   ; right edge and exit if too far right.
    1.23 -
    1.24 -    lda player_y                    ; Check for the top of the character.
    1.25 -    asl
    1.26 -    adc player_ys                   ; Store the y position in terms of half
    1.27 -    sta $81                         ; rows.
    1.28 -
    1.29 -    iny
    1.30 -    lda ($86),y                     ; Load monster y offset.
    1.31 -    asl                             ; Convert it to half rows.
    1.32 -    iny
    1.33 -    adc ($86),y                     ; Add it to the monster's ys value.
    1.34 -
    1.35 -    adc #1                          ; Add half the monster's height to the
    1.36 -                                    ; offset to help with comparison using
    1.37 -                                    ; its bottom edge.
    1.38 -
    1.39 -    cmp $81                         ; Compare to the character's top edge.
    1.40 -    bcc check_monster_common_exit   ; Exit if above the character. This means
    1.41 -                                    ; that the bottom edge could be aligned
    1.42 -                                    ; with the character's top edge.
    1.43 -
    1.44 -    sbc #7                          ; Check for the character's bottom edge
    1.45 -    clc                             ; (six half rows plus the half row already
    1.46 -    cmp $81                         ; added above).
    1.47 -    bcs check_monster_common_exit
    1.48 -
    1.49 -    jmp player_demise               ; Decrease the number of lives and exit.
    1.50 -
    1.51 -check_monster_common_exit:
    1.52 -
    1.53 -    clc
    1.54 -    rts
    1.55 -
    1.56  check_player_monsters:
    1.57  
    1.58      ldy #0
    1.59 @@ -764,11 +715,49 @@
    1.60      check_player_monsters_loop:
    1.61  
    1.62          sty $88
    1.63 -        lda ($86),y
    1.64 -        beq check_player_monsters_next
    1.65 +        lda ($86),y                     ; Load monster type and dx value.
    1.66 +        beq check_player_monsters_next  ; If none present, check the next one.
    1.67  
    1.68 -        jsr check_monster_player
    1.69 -        bcs check_monster_common_exit
    1.70 +            and #monster_dx_bit
    1.71 +            lsr
    1.72 +            sta $80
    1.73 +
    1.74 +            iny
    1.75 +            lda ($86),y                     ; Load monster x offset.
    1.76 +            asl                             ; Convert to half columns.
    1.77 +            adc $80                         ; Add dx to x.
    1.78 +
    1.79 +            cmp #35                         ; Compare the right edge to the character's
    1.80 +            bcc check_player_monsters_next  ; left edge and exit if too far left.
    1.81 +            cmp #42                         ; Compare the left edge to the character's
    1.82 +            bcs check_player_monsters_next  ; right edge and exit if too far right.
    1.83 +
    1.84 +            lda player_y                    ; Check for the top of the character.
    1.85 +            asl
    1.86 +            adc player_ys                   ; Store the y position in terms of half
    1.87 +            sta $81                         ; rows.
    1.88 +
    1.89 +            iny
    1.90 +            lda ($86),y                     ; Load monster y offset.
    1.91 +            asl                             ; Convert it to half rows.
    1.92 +            iny
    1.93 +            adc ($86),y                     ; Add it to the monster's ys value.
    1.94 +
    1.95 +            adc #1                          ; Add half the monster's height to the
    1.96 +                                            ; offset to help with comparison using
    1.97 +                                            ; its bottom edge.
    1.98 +
    1.99 +            cmp $81                         ; Compare to the character's top edge.
   1.100 +            bcc check_player_monsters_next  ; Exit if above the character. This means
   1.101 +                                            ; that the bottom edge could be aligned
   1.102 +                                            ; with the character's top edge.
   1.103 +
   1.104 +            sbc #7                          ; Check for the character's bottom edge
   1.105 +            clc                             ; (six half rows plus the half row already
   1.106 +            cmp $81                         ; added above).
   1.107 +            bcs check_player_monsters_next
   1.108 +
   1.109 +            jmp player_demise               ; Decrease the number of lives and exit.
   1.110  
   1.111          check_player_monsters_next:
   1.112          clc
   1.113 @@ -779,3 +768,8 @@
   1.114          beq check_monster_common_exit
   1.115          tay
   1.116          bne check_player_monsters_loop
   1.117 +
   1.118 +check_monster_common_exit:
   1.119 +
   1.120 +    clc
   1.121 +    rts