snes: use Y*4 in many cases instead of Y

this in theory trades off lots of shifting for a few increments
it does make the code a bit more confusing
This commit is contained in:
Vince Weaver 2013-02-06 00:32:06 -05:00
parent a6a8904c1c
commit 58178b95cd
3 changed files with 82 additions and 104 deletions

View File

@ -1,2 +1,2 @@
.word $f93f ; Complement of checksum
.word $6c0 ; Unsigned 16-bit sum of ROM
.word $e1c ; Complement of checksum
.word $f1e3 ; Unsigned 16-bit sum of ROM

View File

@ -423,22 +423,14 @@ level1_setup_video:
do_new_game:
;; set up struct pointers
; ldx #.LOWORD(missile_0) ; setup missle struct pointer
; stx MISSILE_PL
; ldx #.LOWORD(enemy_0) ; setup enemy struct pointer
; stx ENEMY_PL
;; Clear BSS
ldx #$0
clear_bss:
stz start_bss,X
inx
cpx #end_bss-start_bss
bne clear_bss
; ldx #$0
;clear_bss:
; stz start_bss,X
; inx
; cpx #end_bss-start_bss
; bne clear_bss
;; Init one-time vars
@ -450,7 +442,7 @@ clear_bss:
; jsr update_shields
lda #104
sta shipx ; shipx at start is 18
sta shipx ; shipx at start is 104
lda #$1
sta LEVEL ; start at level 1
@ -581,13 +573,16 @@ same_enemy_type:
; find empty enemy slot
ldy #$20 ; point to enemies[0]
ldy #$80 ; point to enemies[0] $20 * 4
find_empty_enemy:
jsr is_sprite_active
bcc add_enemy
iny
cpy #($20+NUM_ENEMIES)
iny
iny
iny
cpy #($80+4*NUM_ENEMIES)
bne find_empty_enemy
jmp move_enemies ; no empty, slots, move on
@ -803,17 +798,17 @@ store_enemy_kind:
; want to store to $200 + (Y*4)
rep #$20 ; set A to 16-bit
.a16
; rep #$20 ; set A to 16-bit
;.a16
tya ; copy Y to A
asl
asl ; multiply by 4
tax ; put in X
tyx ; copy Y to A
; asl
; asl ; multiply by 4
; tax ; put in X
sep #$20 ; set A back to 8-bit
.a8
; sep #$20 ; set A back to 8-bit
;.a8
; determine enemy _x
; if < 0, make random between 2->34
@ -1809,22 +1804,22 @@ done_with_boss:
; Missiles are 8,9,10,11 in sprite table
ldy #$8 ; point to missile[0]
ldy #$20 ; point to missile[0] (8*4)
move_missiles:
jsr is_sprite_active
bcc loop_move_missiles ; if not active, skip
phy
tya
asl
asl
tay
; phy
; tya
; asl
; asl
; tay
lda $0201,Y
dea
sta $0201,Y
ply
; ply
cmp #200
@ -1897,7 +1892,10 @@ done_missile_collision:
loop_move_missiles:
iny
cpy #(8+NUM_MISSILES) ; have we checked all missiles?
iny
iny
iny
cpy #($20+4*NUM_MISSILES) ; have we checked all missiles?
bne move_missiles ; if not, loop
done_move_missiles:
@ -1948,16 +1946,16 @@ key_A:
bit #$80
beq game_unknown
ldy #$8 ; point to missile[y]
ldy #$20 ; point to missile[y] (8*4)
fire_missiles:
jsr is_sprite_active
bcs end_fire_loop ; if active, skip to next
phy
tya
asl
asl
tay
; phy
; tya
; asl
; asl
; tay
lda #8
clc
@ -1968,15 +1966,18 @@ fire_missiles:
sta $0201,Y
ply
; ply
jsr activate_sprite
bra done_fire_missiles ; done firing missile
end_fire_loop:
iny ; point to next missile
iny
iny
iny
cpy #(8+NUM_MISSILES) ; see if we have more missiles
cpy #($20+4*NUM_MISSILES) ; see if we have more missiles
bne fire_missiles ; if so, loop
done_fire_missiles:

View File

@ -272,32 +272,31 @@ found_keypress:
plp ; restore status
rts
;===========================
;===========================
; is_sprite_active
;===========================
;===========================
; assumes high sprite table at $0400
; sets carry if active
; clears carry if not
; sprite number in Y
is_sprite_active:
php ; save status
;===========================
;===========================
; get_sprite_mask
;===========================
;===========================
; only meant to be called by the routines below
; sprite number is Y/4
get_sprite_mask:
rep #$30 ; A=16bit X/Y=16bit
.i16
.a16
phx ; save X on stack
phy ; save Y on stack
tyx ; copy Y to X
; tyx ; copy Y to X
; address=$0400 + Y/4
; address=$0400 + Y/16
tya ; copy Y to A
lsr ; divide by 4
lsr ; divide by 16
lsr
tax
lsr
lsr
tay ; copy back to Y
@ -309,6 +308,26 @@ is_sprite_active:
.a8
lda SPRITE_HIGH_LOOKUP,X
; get bitmask for X
plx
rts
;===========================
;===========================
; is_sprite_active
;===========================
;===========================
; assumes high sprite table at $0400
; sets carry if active
; clears carry if not
; sprite number is Y/4
is_sprite_active:
php ; save status
phy ; save Y on stack
jsr get_sprite_mask
.a8
; mask is in A
and $0400,Y ; sprite on screen when bit is 0
@ -316,14 +335,12 @@ is_sprite_active:
sprite_is_not_active:
ply
plx
plp
clc
rts
sprite_is_active:
ply
plx
plp
sec
rts
@ -335,40 +352,20 @@ sprite_is_active:
;===========================
;===========================
; assumes high sprite table at $0400
; sets carry if active
; clears carry if not
; sprite number in Y
; sprite number is Y/4
activate_sprite:
php ; store status
phx ; store X on stack
phy ; store Y on stack
rep #$20 ; make A 16-bit
.a16
tyx ; copy Y to X
; address=$0400 + Y/4
tya ; copy Y to A
lsr ; divide by 4
lsr
tay ; transfer back to Y
txa ; get saved copy of Y
and #$3 ; mask to get low bits
tax ; transfer back to X
sep #$20 ; make A 8-bit
jsr get_sprite_mask
.a8
lda SPRITE_HIGH_LOOKUP,X ; load from lookup table
eor #$ff ; negate it
and $0400,Y ; sprite on screen when bit is 0
sta $0400,Y ; store it back out
ply ; restore values from stack
plx
plp
rts ; return
@ -379,38 +376,18 @@ activate_sprite:
;===========================
;===========================
; assumes high sprite table at $0400
; sets carry if active
; clears carry if not
; sprite number in Y
; sprite number is Y/4
deactivate_sprite:
php ; save status on stack
phx ; save X
phy ; save Y
tyx ; copy Y to X
rep #$20 ; set A to 16-bit
.a16
; address=$0400 + Y/4
tya ; copy Y to A
lsr ; divide by 4
lsr
tay ; copy back to Y
txa ; get low bits into X
and #$3 ; Mask
tax
sep #$20 ; set A to 8-bit
jsr get_sprite_mask
.a8
lda SPRITE_HIGH_LOOKUP,X ; lookup bits in table
ora $0400,Y ; sprite off screen when bit is 1
sta $0400,Y ; save value back out
ply ; restore Y
plx ; restore X
plp ; restore status
rts ; return