diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-10 22:52:15 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-03-10 22:52:15 +0100 |
| commit | 1a74e6a1856673072a61abd0861759901bc2d939 (patch) | |
| tree | bb1b54a7c27280d7d9e83c031233dd8402f1e721 | |
| parent | ff22231f8a2f3714df701fd7c12b07915adc15e9 (diff) | |
| download | code.nes-1a74e6a1856673072a61abd0861759901bc2d939.tar.gz code.nes-1a74e6a1856673072a61abd0861759901bc2d939.zip | |
Bring code style to better standards
Be more careful on everything and try to follow along style.nes from my
repository. This might change in the future, but it's in a much better
state now.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
| -rw-r--r-- | .editorconfig | 11 | ||||
| -rw-r--r-- | basics/chr-ram.s | 37 | ||||
| -rw-r--r-- | basics/flicker.s | 14 | ||||
| -rw-r--r-- | basics/input.s | 23 | ||||
| -rw-r--r-- | basics/persist.s | 16 | ||||
| -rw-r--r-- | basics/sprite.s | 26 | ||||
| -rw-r--r-- | basics/unrom.s | 18 | ||||
| -rw-r--r-- | fx/blink.s | 33 | ||||
| -rw-r--r-- | scroll/include/apu.s | 2 | ||||
| -rw-r--r-- | space/src/space.s | 5 | ||||
| -rw-r--r-- | space/src/states/bullets.s | 32 | ||||
| -rw-r--r-- | space/src/states/game.s | 10 | ||||
| -rw-r--r-- | space/src/states/player.s | 160 | ||||
| -rw-r--r-- | space/src/vectors/irq.s | 5 | ||||
| -rw-r--r-- | space/src/vectors/nmi.s | 3 | ||||
| -rw-r--r-- | space/src/vectors/reset.s | 7 |
16 files changed, 206 insertions, 196 deletions
diff --git a/.editorconfig b/.editorconfig index 3433fac..c420a82 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,8 +1,13 @@ root = true -[{*.{s,S},Makefile}] +[*] charset = utf-8 -end_of_line = lf +indent_size = 4 insert_final_newline = true +end_of_line = lf + +[*.{s,S}] indent_style = space -indent_size = 4 + +[Makefile] +indent_style = tab diff --git a/basics/chr-ram.s b/basics/chr-ram.s index 20e1b30..bb2186e 100644 --- a/basics/chr-ram.s +++ b/basics/chr-ram.s @@ -29,7 +29,8 @@ .segment "BANK0" -chr: .incbin "../assets/basic.chr" +chr: + .incbin "../assets/basic.chr" .segment "BANK1" .byte $00 @@ -56,33 +57,18 @@ chr: .incbin "../assets/basic.chr" .segment "FIXED" ;;; -;; Bank switching code as with `basics/unrom.s`. Not used here. - -banktable: - .byte $00, $01, $02, $03, $04, $05, $06 - -m_current_bank = $00 - -bankswitch: - sty m_current_bank -bankswitch_nosave: - tya - sta banktable, y - rts - -;;; ;; From here on the code is basically the same as `basics/sprite.s`, but with a ;; special twist that will be commented in. For comments on the rest of the code ;; just check `basics/sprite.s`. -reset: +.proc reset sei cld - ldx #$40 + ldx #$FF stx $4017 - ldx #$ff + ldx #$FF txs inx stx $2000 @@ -139,6 +125,7 @@ reset: bne @palettes_reset_loop jmp main +.endproc ;;; ;; Transfer the CHR data from PRG-ROM into RAM. @@ -166,17 +153,17 @@ reset: ;; - x contains the number of 256-byte pages to copy. ;; - y will index within the page ($00-$FF). ldx #32 -loop: +@loop: ;; First part of the loop: copy each byte of the current page. lda ($00), y sta $2007 iny - bne loop + bne @loop ;; Go to the next page and repeat the first part of the loop. inc $01 dex - bne loop + bne @loop rts .endproc @@ -274,7 +261,7 @@ initial_sprite_data: .byte $B0, $00, %01000000, $82 .endproc -nmi: +.proc nmi bit $20 bpl @next @@ -305,6 +292,8 @@ nmi: pla @next: rti +.endproc -irq: +.proc irq rti +.endproc diff --git a/basics/flicker.s b/basics/flicker.s index 8db03e8..2522cb2 100644 --- a/basics/flicker.s +++ b/basics/flicker.s @@ -61,7 +61,6 @@ jmp @main_game_loop .endproc - ;;; ;; NOTE: this is the actual meat of the example :D .proc apply_flicker @@ -135,7 +134,7 @@ ;;; ;; NOTE: and from here on stuff that is not relevant for sprite flickering. -nmi: +.proc nmi bit $20 bpl @next @@ -168,15 +167,16 @@ nmi: pla @next: rti +.endproc -reset: +.proc reset sei cld ldx #$40 stx $4017 ; APU Frame Counter - ldx #$ff + ldx #$FF txs inx @@ -201,7 +201,7 @@ reset: inx bne @ram_reset_loop ; if x overflows back to #00, then we are done. - lda #$ef + lda #$EF @sprite_reset_loop: sta $200, x inx @@ -229,9 +229,11 @@ reset: bne @palettes_reset_loop jmp main +.endproc -irq: +.proc irq rti +.endproc .proc init_sprites NUM_SPRITES = 20 diff --git a/basics/input.s b/basics/input.s index b773fd7..df49a66 100644 --- a/basics/input.s +++ b/basics/input.s @@ -13,12 +13,10 @@ ;; which brings some other considerations when reading from controllers. That ;; is, the algorithm shown below is not entirely "safe" due to a hardware bug ;; which might give unreliable inputs on some spikes. -;;; ;;; ;; You can safely ignore all of this up until the `ReadController` subroutine. ;; This is boilerplate that is explained on the `sprite.s` example. -;;; .segment "HEADER" .byte 'N', 'E', 'S', $1A @@ -34,17 +32,23 @@ .segment "CODE" -nmi: -irq: - rti +;; Unused +.proc nmi + rti +.endproc + +;; Unused +.proc irq + rti +.endproc -reset: +.proc reset sei cld ldx #$40 stx $4017 - ldx #$ff + ldx #$FF txs inx @@ -75,6 +79,7 @@ reset: bpl @vblankwait2 jmp main +.endproc .proc ReadController ;; The status of the eight buttons fits into a single byte. We start the whole @@ -117,7 +122,7 @@ reset: ;; `rol` instruction. At this point, we have already read the full byte. read_loop: lda $4016 - lsr a + lsr rol $20 bcc read_loop @@ -166,8 +171,6 @@ pressed: ;; There and back again. jmp loop - - rts .endproc .segment "CHARS" diff --git a/basics/persist.s b/basics/persist.s index 3e7c439..e7dfb07 100644 --- a/basics/persist.s +++ b/basics/persist.s @@ -43,19 +43,24 @@ .segment "BANK1" ;; Unused -nmi: -irq: - rti +.proc nmi + rti +.endproc + +;; Unused +.proc irq + rti +.endproc ;; Check `basics/sprite.s` for a deeper look on the logic below. I have only ;; added comments to MMC1-specific stuff. -reset: +.proc reset sei cld ldx #$40 stx $4017 - ldx #$ff + ldx #$FF txs inx @@ -165,6 +170,7 @@ reset_mmc1: ;; Loop forever, there's nothing to be done here. @loop: jmp @loop +.endproc ;; Unused .segment "CHR0" diff --git a/basics/sprite.s b/basics/sprite.s index 1892ce5..6fcdad3 100644 --- a/basics/sprite.s +++ b/basics/sprite.s @@ -23,7 +23,6 @@ ;; basic identification, it defines some relevant things like PRG and CHR sizes, ;; plus mapping if desired. See https://www.nesdev.org/wiki/NES_2.0#Header for ;; documentation on this, or also: https://www.nesdev.org/neshdr20.txt. -;;; .segment "HEADER" ;; The first thing to do is to define the magic "NES\0" string identifier ;; ($1A is the ASCII that MS-DOS wanted as end of string). Some people write @@ -82,7 +81,6 @@ ;; actually removes this segment in its linker configuration down the road). ;; This is also removed by the configuration provided in `config/nrom.cfg`, ;; which is the one being used in the end for this example. -;;; ;; .segment "STARTUP" .segment "CODE" @@ -94,8 +92,7 @@ ;; NesDev wiki which is pretty much followed by everyone as I could see. The ;; main idea is to leave the hardware in a known state and then jump into the ;; main game subroutine. -;;; -reset: +.proc reset ;; We first instruct the NES to disable everything. That is, we don't want ;; any pesky interrupt to make us jump into the `nmi` section, for example, ;; before we have configured everything. @@ -200,10 +197,10 @@ reset: ;; ;; "Resetting sprites" is just a matter of giving them a value which will ;; not bother us in the future. One way to do this is to set each value to - ;; $ef, which will give each "sprite" off-screen Y-coordinates. How any of + ;; $EF, which will give each "sprite" off-screen Y-coordinates. How any of ;; this is the case will be shown whenever we deal with loading proper ;; sprites below. - lda #$ef + lda #$EF @sprite_reset_loop: sta $200, x inx @@ -217,7 +214,7 @@ reset: ;; the byte given at the OAMADDR, thus XX = #$00; and N = 2 (see `lda ;; #$02`). Therefore, we are telling the PPU to start the DMA process from ;; $200. The PPU will assume that the following 256 bytes of memory are the - ;; ones to be copied, resulting in a DMA copy of $200-$2ff, right where we + ;; ones to be copied, resulting in a DMA copy of $200-$2FF, right where we ;; stored the sprite data in advance. lda #$00 sta $2003 ; OAMADDR @@ -238,7 +235,7 @@ reset: ;; stored. Palettes are the answer from old systems like the NES to: how can ;; you display this amount of colors on screen without taking too much ;; memory? The NES allows developers to store eight palettes (four - ;; background, four foreground), and each palette group four colors. This + ;; background, four foreground), and each palette groups four colors. This ;; way, whenever we want to draw a sprite or a piece of background, we don't ;; specify which colors to pick for each pixel, but we rather apply a ;; palette to a sprite or background tile definition. @@ -268,12 +265,12 @@ reset: ;; jump into our main subroutine and start loading sprites, palettes, etc.; ;; and start the game proper. jmp main +.endproc ;;; ;; This is our main subroutine. At this point we can assume that the hardware ;; has already been set to a proper and defined state. So now we can load all ;; the data we need for our game and enter the main game loop. -;;; .proc main ;; Before starting the game loop proper we initialize all our assets: load ;; the palettes, nametables and sprites for this game. @@ -341,7 +338,7 @@ reset: .proc init_palettes ;; Remember these four instructions? That's what we also did when resetting ;; palettes on the reset code. That is, we are preparing the PPU to write - ;; data starting from $3f00. + ;; data starting from $3F00. lda #$3F sta $2006 ; PPUADDR lda #$00 @@ -500,7 +497,7 @@ palettes: ;; This is tied to the number of sprites stored in the `initial_sprite_data` ;; section. Remember that this can be 64 *maximum*: 64 sprites * 4 bytes per ;; sprite = 256 bytes; which is the reserved space in memory we have for - ;; sprites: $0200-$02ff. + ;; sprites: $0200-$02FF. NUM_SPRITES = 2 ;; The loading is quite straight-forward. We just store whatever is on @@ -551,8 +548,7 @@ initial_sprite_data: ;; we ought to keep things as simple and fast as possible. You can take a look ;; at the examples from `scroll` for more complex NMI code that have to handle ;; stuff like VRAM buffering or setting other PPU registers. -;;; -nmi: +.proc nmi ;; As mentioned on the `main` subroutine, rendering will be skipped until ;; the proper flag is set. bit $20 @@ -601,6 +597,7 @@ nmi: pla @next: rti +.endproc ;;; ;; Interrupt Requests handler. This is triggered by the NES' sound processor @@ -608,8 +605,9 @@ nmi: ;; mapper). In our case we don't have to do anything here, so we just return ;; from the interrupt. ;;; -irq: +.proc irq rti +.endproc ;;; ;; Include into this all the data that needs to go into the CHR ROM. One typical diff --git a/basics/unrom.s b/basics/unrom.s index b6deb4d..eb49b17 100644 --- a/basics/unrom.s +++ b/basics/unrom.s @@ -101,32 +101,37 @@ banktable: ;; Variable containing the bank we are currently in. It's useful to keep track ;; of the bank so the NMI handler can restore it if it does some bank switching ;; of its own. -m_current_bank = $00 +zp_current_bank = $00 ;; Perform a bankswitch by using the value on the `y` register. Note that you ;; can use the `bankswitch_nosave` variant, which is useful if you just want to ;; perform a temporary bankswitch (e.g. on NMI code). bankswitch: - sty m_current_bank + sty zp_current_bank bankswitch_nosave: tya sta banktable, y rts ;; Unused -nmi: -irq: +.proc nmi rti +.endproc + +;; Unused +.proc irq + rti +.endproc ;; 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 @@ -178,3 +183,4 @@ reset: ;; Loop forever, there's nothing to be done here. @loop: jmp @loop +.endproc @@ -5,7 +5,7 @@ ;; https://www.nesdev.org/wiki/MMC3. The MMC3 is a pretty advanced chip, so ;; first go over the `basics/` directory for a better understanding on easier ;; topics. Most importantly, take a look at examples like `basics/persist.s` or -;; `basics/unrom`, which also perform bank switching albeit with simpler +;; `basics/unrom.s`, which also perform bank switching albeit with simpler ;; hardware. ;; ;; This example basically makes use of the bank switching capabilities of the @@ -41,8 +41,8 @@ ;; Variables used on this example. .scope Vars - counter = $00 - last_bank = $01 + zp_counter = $00 + zp_last_bank = $01 .endscope .segment "HEADER" @@ -128,14 +128,14 @@ ;;; specific to this example. .segment "TAIL" -reset: +.proc reset sei cld ldx #$40 stx $4017 - ldx #$ff + ldx #$FF txs inx @@ -217,7 +217,7 @@ reset: inx bne @ram_reset_loop - lda #$ef + lda #$EF @sprite_reset_loop: sta $200, x inx @@ -244,6 +244,7 @@ reset: dex bne @palettes_reset_loop jmp main +.endproc ;;; NOTE: mainly as usual except that a bit of game loop has been added to ;;; handle the blinking state. @@ -251,7 +252,7 @@ reset: ;; The code will iterate between banks 4 and 6 on the pattern table, as ;; that's where sprites are located (check the CHARS segment for more info). lda #4 - sta Vars::last_bank + sta Vars::zp_last_bank CLEAR_SCREEN @@ -289,13 +290,13 @@ reset: ;; NOTE: let there be a game logic :D ;; Is the counter already at the limit? If not just restart the game loop. - lda Vars::counter + lda Vars::zp_counter cmp #$20 bne @main_game_loop ;; Reset the counter lda #0 - sta Vars::counter + sta Vars::zp_counter ;; The whole trick is done on R2, which points to $1000, where the sprite ;; tiles begin. Hence, select it. @@ -303,7 +304,7 @@ reset: sta MMC3::BANK_SELECT ;; The value for the register is either 4 or 6 depending on its last value. - lda Vars::last_bank + lda Vars::zp_last_bank cmp #4 beq :+ lda #4 @@ -312,7 +313,7 @@ reset: lda #6 @set: ;; Save which is the bank being used both internally and onto the MMC3 chip. - sta Vars::last_bank + sta Vars::zp_last_bank sta MMC3::BANK_DATA jmp @main_game_loop @@ -346,7 +347,7 @@ initial_sprite_data: ;;; NOTE: nothing to highlight here other than the counter is increased on each ;;; NMI. -nmi: +.proc nmi bit $20 bpl @next @@ -357,7 +358,7 @@ nmi: pha ;; Increase the counter for the blinking. - inc Vars::counter + inc Vars::zp_counter jsr Diskun::nmi_update @@ -382,10 +383,12 @@ nmi: pla @next: rti +.endproc ;;; NOTE: IRQ is disabled when setting up the MMC3 chip for this example. -irq: +.proc irq rti +.endproc ;;; NOTE: The header for this game advertises 128KB for CHR-ROM. This is wildly ;;; too much for this example, but it's a reasonable size for an MMC3 game. @@ -402,7 +405,7 @@ irq: ;; filled with `diskun0.chr` and `diskun1.chr`, which are 2KB each. Hence, the ;; 4th CHR bank contains the regular character, and the 6th CHR bank contains ;; the blinking version. You can see these values used when initializing -;; `Vars::last_bank`, or when performing bank switching. +;; `Vars::zp_last_bank`, or when performing bank switching. .res $1000, $00 .incbin "../assets/diskun0.chr" ; First half of the second pattern table has the default diskun character. .incbin "../assets/diskun1.chr" ; Second half of the second pattern table simply has the blinking version. diff --git a/scroll/include/apu.s b/scroll/include/apu.s index 32ccff2..65d9876 100644 --- a/scroll/include/apu.s +++ b/scroll/include/apu.s @@ -1,5 +1,3 @@ -.segment "CODE" - .scope APU DMC = $4010 FRAME_COUNTER = $4017 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 |
