aboutsummaryrefslogtreecommitdiff
path: root/space/src
diff options
context:
space:
mode:
Diffstat (limited to 'space/src')
-rw-r--r--space/src/space.s5
-rw-r--r--space/src/states/bullets.s32
-rw-r--r--space/src/states/game.s10
-rw-r--r--space/src/states/player.s160
-rw-r--r--space/src/vectors/irq.s5
-rw-r--r--space/src/vectors/nmi.s3
-rw-r--r--space/src/vectors/reset.s7
7 files changed, 111 insertions, 111 deletions
diff --git a/space/src/space.s b/space/src/space.s
index 1d39e7a..4db273d 100644
--- a/space/src/space.s
+++ b/space/src/space.s
@@ -9,7 +9,6 @@
;;
;; The subpixel movement is largely based on:
;; https://github.com/NesHacker/PlatformerMovement.
-;;;
.segment "HEADER"
.byte 'N', 'E', 'S', $1A
@@ -77,10 +76,10 @@
jsr Bullets::update
;; This is a hand-shake between the code on `main` and the code on the
- ;; `nmi`. See Game::flags for more.
+ ;; `nmi`. See Game::zp_flags for more.
SET_RENDER_FLAG
@wait_for_render:
- bit Game::flags
+ bit Game::zp_flags
bmi @wait_for_render
;; Rendering is done, we can perform another iteration of the loop!
diff --git a/space/src/states/bullets.s b/space/src/states/bullets.s
index af74ce7..a51e7e8 100644
--- a/space/src/states/bullets.s
+++ b/space/src/states/bullets.s
@@ -13,10 +13,10 @@
;; deal.
.scope Bullets
;; The number of bullets shown on screen for the current frame.
- m_bullets_screen = $40
+ zp_bullets_screen = $40
;; Frame counter. See `FRAMES` below.
- m_frames = $41
+ zp_frames = $41
;; How many frames have to pass to allow the user to shoot another bullet
;; after the previous one.
@@ -27,14 +27,14 @@
;; Initializing variables.
lda #0
- sta m_bullets_screen
+ sta zp_bullets_screen
lda #FRAMES
- sta m_frames
+ sta zp_frames
;; Set X and Y positions off-screen for the three available slots.
- lda #$ff
+ lda #$FF
sta $208
sta $20C
sta $210
@@ -64,10 +64,10 @@
;; If the frame counter has the same value as our allowed one, we can go
;; into the `bullets_pressed` subroutine, otherwise we will skip it
;; altogether.
- lda m_frames
+ lda zp_frames
cmp #FRAMES
beq @check
- inc m_frames
+ inc zp_frames
jmp @position
@check:
jsr bullets_pressed
@@ -81,7 +81,7 @@
;; and it is possible.
.proc bullets_pressed
;; If we reached the maximum of bullets on screen, return early.
- lda m_bullets_screen
+ lda zp_bullets_screen
cmp #3
bne :+
rts
@@ -117,9 +117,9 @@
;; At the current index we have a bullet to initialize. Hence, give it
;; the Y value from the player and the X one (+4 so it's at the center
;; of the ship on the X axis).
- lda Player::m_screen_y
+ lda Player::zp_screen_y
sta $208, x
- lda Player::m_screen_x
+ lda Player::zp_screen_x
clc
adc #4
inx
@@ -127,11 +127,11 @@
inx
sta $208, x
- ;; Reset the `m_frames` so to disallow too many bullets being shot at
- ;; once, and increate the `m_bullets_screen` variable.
+ ;; Reset the `zp_frames` so to disallow too many bullets being shot at
+ ;; once, and increate the `zp_bullets_screen` variable.
lda #0
- sta m_frames
- inc m_bullets_screen
+ sta zp_frames
+ inc zp_bullets_screen
@end:
rts
.endproc
@@ -158,9 +158,9 @@
sbc #10
jmp @save
@free:
- ;; This bullet should be freed, decrease `m_bullets_screen` and set `a`
+ ;; This bullet should be freed, decrease `zp_bullets_screen` and set `a`
;; to an off-screen value.
- dec m_bullets_screen
+ dec zp_bullets_screen
lda #$FF
@save:
;; Either way you reach this, in `a` we have the Y value to be stored.
diff --git a/space/src/states/game.s b/space/src/states/game.s
index ca8a49b..ef5b6ef 100644
--- a/space/src/states/game.s
+++ b/space/src/states/game.s
@@ -3,19 +3,19 @@
;; - 7: set to 1 whenever the game logic is over and we can start
;; rendering; set to 0 when rendering is done.
;; - 6-0: unused.
- flags = $20
+ zp_flags = $20
.endscope
;; SET_RENDER_FLAG sets the render bit on Game::flags to 1.
.macro SET_RENDER_FLAG
lda #%10000000
- ora Game::flags
- sta Game::flags
+ ora Game::zp_flags
+ sta Game::zp_flags
.endmacro
;; UNSET_RENDER_FLAG sets the render bit on Game::flags to 0.
.macro UNSET_RENDER_FLAG
lda #%01111111
- and Game::flags
- sta Game::flags
+ and Game::zp_flags
+ sta Game::zp_flags
.endmacro
diff --git a/space/src/states/player.s b/space/src/states/player.s
index e03f54c..59dc9c7 100644
--- a/space/src/states/player.s
+++ b/space/src/states/player.s
@@ -6,54 +6,54 @@
;;;
.scope Player
;; Unsigned screen coordinates on the X axis.
- m_screen_x = $30
+ zp_screen_x = $30
;; Unsigned screen coordinates on the Y axis.
- m_screen_y = $31
+ zp_screen_y = $31
;; The actual velocity on the X coordinates. This is a signed fixed point
;; 4.4 (high nibble: pixels; low: subpixels).
- m_velocity_x = $32
+ zp_velocity_x = $32
;; The actual velocity on the Y coordinates. This is a signed fixed point
;; 4.4 (high nibble: pixels; low: subpixels).
- m_velocity_y = $33
+ zp_velocity_y = $33
;; The target velocity on the X coordinates. This is a signed fixed point
;; 4.4 (high nibble: pixels; low: subpixels).
- m_target_velocity_x = $34
+ zp_target_velocity_x = $34
;; The target velocity on the Y coordinates. This is a signed fixed point
;; 4.4 (high nibble: pixels; low: subpixels).
- m_target_velocity_y = $35
+ zp_target_velocity_y = $35
;; Computed position on the X coordinates at the subpixel level. This is a
;; signed fixed point 12.4. NOTE: two bytes!
- m_position_x = $36
+ zp_position_x = $36
;; Computed position on the X coordinates at the subpixel level. This is a
;; signed fixed point 12.4. NOTE: two bytes!
- m_position_y = $38
+ zp_position_y = $38
;; Initializes the player by initializing its internal data and loading some
;; values of the sprite itself.
.proc init
;; Initialize position + subpixel.
lda #$B0
- sta m_position_y
+ sta zp_position_y
lda #$00
- sta m_position_y + 1
+ sta zp_position_y + 1
lda #$7A
- sta m_position_x
+ sta zp_position_x
lda #$F0
- sta m_position_x + 1
+ sta zp_position_x + 1
;; Initialize velocity.
lda #0
- sta m_velocity_x
- sta m_velocity_y
- sta m_target_velocity_x
- sta m_target_velocity_y
+ sta zp_velocity_x
+ sta zp_velocity_y
+ sta zp_target_velocity_x
+ sta zp_target_velocity_y
rts
.endproc
@@ -90,7 +90,7 @@
and Joypad::m_buttons1
beq @target_check_left
lda positive_velocity, x
- sta m_target_velocity_x
+ sta zp_target_velocity_x
jmp @target_check_up
@target_check_left:
;; Similar to before: if it was not pressed, then set the target
@@ -100,13 +100,13 @@
and Joypad::m_buttons1
beq @target_no_x
lda negative_velocity, x
- sta m_target_velocity_x
+ sta zp_target_velocity_x
jmp @target_check_up
@target_no_x:
;; None of the buttons on the X-axis were pressed. Set the target
;; velocity to 0.
lda #0
- sta m_target_velocity_x
+ sta zp_target_velocity_x
@target_check_up:
;; Same as before but we return early if it was pressed, otherwise
;; we go into the arrow-down check.
@@ -114,7 +114,7 @@
and Joypad::m_buttons1
beq @target_check_down
lda negative_velocity, x
- sta m_target_velocity_y
+ sta zp_target_velocity_y
rts
@target_check_down:
;; If down was not pressed, go to the "no_y" case, otherwise return
@@ -123,13 +123,13 @@
and Joypad::m_buttons1
beq @target_no_y
lda positive_velocity, x
- sta m_target_velocity_y
+ sta zp_target_velocity_y
rts
@target_no_y:
;; None of the buttons on the Y-axis were pressed. Set the target
;; velocity to 0.
lda #0
- sta m_target_velocity_y
+ sta zp_target_velocity_y
rts
positive_velocity:
.byte $18, $28
@@ -141,81 +141,81 @@
;; velocity on each case. Note that the velocity is simply increased by
;; one. A more detailed code could be more nuanced than this.
.proc accelerate
- lda m_velocity_x
+ lda zp_velocity_x
sec
- sbc m_target_velocity_x
+ sbc zp_target_velocity_x
bne @accelerate_x_check_greater
jmp @accelerate_y
@accelerate_x_check_greater:
bmi @accelerate_x_check_lesser
- dec m_velocity_x
+ dec zp_velocity_x
jmp @accelerate_y
@accelerate_x_check_lesser:
- inc m_velocity_x
+ inc zp_velocity_x
@accelerate_y:
- lda m_velocity_y
+ lda zp_velocity_y
sec
- sbc m_target_velocity_y
+ sbc zp_target_velocity_y
bne @accelerate_y_check_greater
rts
@accelerate_y_check_greater:
bmi @accelerate_y_check_lesser
- dec m_velocity_y
+ dec zp_velocity_y
rts
@accelerate_y_check_lesser:
- inc m_velocity_y
+ inc zp_velocity_y
rts
.endproc
;; Apply the currently computed velocity to the position at subpixel
;; level.
.proc apply_velocity
- lda m_velocity_x
+ lda zp_velocity_x
bmi @apply_negative_velocity_x
clc
- adc m_position_x
- sta m_position_x
+ adc zp_position_x
+ sta zp_position_x
lda #0 ;NOTE: adding possible carry!
- adc m_position_x + 1
- sta m_position_x + 1
+ adc zp_position_x + 1
+ sta zp_position_x + 1
jmp @apply_velocity_y
@apply_negative_velocity_x:
lda #0
sec
- sbc m_velocity_x
+ sbc zp_velocity_x
sta $00
- lda m_position_x
+ lda zp_position_x
sec
sbc $00
- sta m_position_x
- lda m_position_x + 1
+ sta zp_position_x
+ lda zp_position_x + 1
sbc #0
- sta m_position_x + 1
+ sta zp_position_x + 1
@apply_velocity_y:
- lda m_velocity_y
+ lda zp_velocity_y
bmi @apply_negative_velocity_y
clc
- adc m_position_y
- sta m_position_y
+ adc zp_position_y
+ sta zp_position_y
lda #0
- adc m_position_y + 1
- sta m_position_y + 1
+ adc zp_position_y + 1
+ sta zp_position_y + 1
rts
@apply_negative_velocity_y:
lda #0
sec
- sbc m_velocity_y
+ sbc zp_velocity_y
sta $00
- lda m_position_y
+ lda zp_position_y
sec
sbc $00
- sta m_position_y
- lda m_position_y + 1
+ sta zp_position_y
+ lda zp_position_y + 1
sbc #0
- sta m_position_y + 1
+ sta zp_position_y + 1
rts
.endproc
@@ -229,9 +229,9 @@
;; Translate the X position at subpixel level to actual screen coordinates.
.proc position_to_coordinates_x
;; Convert the fixed point position coordinate into screen coordinates
- lda m_position_x
+ lda zp_position_x
sta $00
- lda m_position_x + 1
+ lda zp_position_x + 1
sta $01
lsr $01
ror $00
@@ -243,9 +243,9 @@
ror $00
; Assume that everything is fine and save the sprite position
lda $00
- sta m_screen_x
+ sta zp_screen_x
- lda m_velocity_x
+ lda zp_velocity_x
bmi @position_from_negative_velocity
lda $01
@@ -256,33 +256,33 @@
rts
@bound_upper_x:
lda #$EF
- sta m_screen_x
+ sta zp_screen_x
lda #$0E
- sta m_position_x + 1
+ sta zp_position_x + 1
lda #$F0
- sta m_position_x
+ sta zp_position_x
lda #0
- sta m_velocity_x
+ sta zp_velocity_x
rts
@position_from_negative_velocity:
- lda m_position_x + 1
+ lda zp_position_x + 1
bmi @bound_lower_x
rts
@bound_lower_x:
lda #0
- sta m_position_x
- sta m_position_x + 1
- sta m_screen_x
- sta m_velocity_x
+ sta zp_position_x
+ sta zp_position_x + 1
+ sta zp_screen_x
+ sta zp_velocity_x
rts
.endproc
;; Translate the Y position at subpixel level to actual screen coordinates.
.proc position_to_coordinates_y
;; Convert the fixed point position coordinate into screen coordinates
- lda m_position_y
+ lda zp_position_y
sta $00
- lda m_position_y + 1
+ lda zp_position_y + 1
sta $01
lsr $01
ror $00
@@ -294,9 +294,9 @@
ror $00
; Assume that everything is fine and save the sprite position
lda $00
- sta m_screen_y
+ sta zp_screen_y
- lda m_velocity_y
+ lda zp_velocity_y
bmi @position_from_negative_velocity_y
lda $01
@@ -307,24 +307,24 @@
rts
@bound_upper_y:
lda #$EF
- sta m_screen_y
+ sta zp_screen_y
lda #$0E
- sta m_position_y + 1
+ sta zp_position_y + 1
lda #$F0
- sta m_position_y
+ sta zp_position_y
lda #0
- sta m_velocity_y
+ sta zp_velocity_y
rts
@position_from_negative_velocity_y:
- lda m_position_y + 1
+ lda zp_position_y + 1
bmi @bound_lower_y
rts
@bound_lower_y:
lda #0
- sta m_position_y
- sta m_position_y + 1
- sta m_screen_y
- sta m_velocity_y
+ sta zp_position_y
+ sta zp_position_y + 1
+ sta zp_screen_y
+ sta zp_velocity_y
rts
.endproc
.endscope
@@ -335,12 +335,12 @@
;; internal data stored in $30-$3F.
.proc update
;; Update Y position.
- lda m_screen_y
+ lda zp_screen_y
sta $200
sta $204
;; Update X position.
- lda m_screen_x
+ lda zp_screen_x
sta $203
clc
adc #8
@@ -348,9 +348,9 @@
;; If we have a target velocity, then we will show some fire,
;; otherwise we keep the basic ship.
- lda m_target_velocity_x
+ lda zp_target_velocity_x
bne @fire
- lda m_target_velocity_y
+ lda zp_target_velocity_y
bne @fire
lda #0
jmp @sprite_set
diff --git a/space/src/vectors/irq.s b/space/src/vectors/irq.s
index 2be3a94..ed8cf47 100644
--- a/space/src/vectors/irq.s
+++ b/space/src/vectors/irq.s
@@ -1,6 +1,5 @@
-.segment "CODE"
-
;; Interrupt Requests handler.
-irq:
+.proc irq
;; Nothing to do for us here :)
rti
+.endproc
diff --git a/space/src/vectors/nmi.s b/space/src/vectors/nmi.s
index e049239..4fe95bd 100644
--- a/space/src/vectors/nmi.s
+++ b/space/src/vectors/nmi.s
@@ -1,5 +1,5 @@
;; See `basics/sprite.s` for more info. I'm not doing anything fancier here.
-nmi:
+.proc nmi
bit $20
bpl @next
@@ -30,3 +30,4 @@ nmi:
pla
@next:
rti
+.endproc
diff --git a/space/src/vectors/reset.s b/space/src/vectors/reset.s
index 1216146..b024e65 100644
--- a/space/src/vectors/reset.s
+++ b/space/src/vectors/reset.s
@@ -2,13 +2,13 @@
;; Check `basics/sprite.s` for a deeper look on the logic below. I have only
;; added code after configuration/reset is done.
-reset:
+.proc reset
sei
cld
ldx #$40
stx $4017
- ldx #$ff
+ ldx #$FF
txs
inx
@@ -33,7 +33,7 @@ reset:
inx
bne @ram_reset_loop
- lda #$ef
+ lda #$EF
@sprite_reset_loop:
sta $200, x
inx
@@ -47,3 +47,4 @@ reset:
;; NOTE: configuration/reset is done, the code below is our actual program :D
jmp main
+.endproc