diff --git a/atlantico/Makefile b/atlantico/Makefile index bee39cd..e953e5d 100755 --- a/atlantico/Makefile +++ b/atlantico/Makefile @@ -15,5 +15,5 @@ clean: # Rule to run the final cartridge .nes file in the FCEUX emulator ############################################################################### run: - on-workspace 1 "fceux atlantico.nes && i3-msg '[id=$(xdotool getactivewindow)] floating enable'" + on-workspace 1 "fceux ./atlantico.nes && i3-msg '[id=$(xdotool getactivewindow)] floating enable'" #on-workspace 1 "fceux atlantico.nes" diff --git a/atlantico/atlantico.asm b/atlantico/atlantico.asm index 0ed3387..37fb20f 100755 --- a/atlantico/atlantico.asm +++ b/atlantico/atlantico.asm @@ -8,6 +8,8 @@ ;; Variables declared in RAM zero-page ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .segment "ZEROPAGE" +Score: .res 4 ; 4 bytes for 1s, 10s, 100s, 1000s, For score + Collision: .res 1 ; 0 or 1, if 0 no collision, if 1, collisison Buttons: .res 1 ; Pressed buttons (A|B|Sel|Start|Up|Dwn|Lft|Rgt) @@ -28,6 +30,7 @@ Clock60: .res 1 ; Counter that increments per second (60 frames) BgPtr: .res 2 ; Pointer to background address - 16bits (lo,hi) SprPtr: .res 2 ; Pointer to the sprite address - 16bits (lo,hi) +BufPtr: .res 2 ; Pointer to the Buffer Address - 16bite (lo,hi) XScroll: .res 1 ; Store the horizontal scroll position CurrNametable: .res 1 ; Store the current starting nametable (0 or 1) @@ -51,6 +54,7 @@ PrevOAMCount: .res 1 ; Store the previous number of bytes that were sent Seed: .res 2 ; Initialize the 16-bit seed to any value except 0 + ActorsArray: .res MAX_ACTORS * .sizeof(Actor) @@ -77,6 +81,114 @@ LoopButtons: rts .endproc + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Increment the score, simulating BCD mode +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.proc IncrementScore ; LittleEndian + Increment1stDigit: + lda Score+0 + clc + adc #1 + sta Score+0 + cmp #$A + bne DoneIncrementing + Increment10sDigit: + lda #0 + sta Score+0 + lda Score+1 + clc + adc #1 + sta Score+1 + cmp #$A + bne DoneIncrementing + Increment100sDigit: + lda #0 + sta Score+1 + lda Score+2 + clc + adc #1 + sta Score+2 + cmp #$A + bne DoneIncrementing + Increment1000sDigit: + lda #0 + sta Score+2 + lda Score+3 + clc + adc #1 + sta Score+3 + cmp #$A + bne DoneIncrementing + + DoneIncrementing: + rts +.endproc + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Draw the score in ther nametable/background using buffering +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Buffer format starting at Ram Address $7000 +;; 03 20 52 00 00 02 01 20 78 00 00 +;; | \___/ \______/ | \___/ | | +;; | | | | | | | +;; | | | | | | Length=0 (End of buffering) +;; | | | | | byte to copy +;; | | | | PPU Address $2078 +;; | | | Length=1 +;; | | bytes to copy +;; | PPU address $2052 +;; Length = +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.proc DrawScore + lda #$70 + sta BufPtr+1 + lda #$00 + sta BufPtr+0 + + ldy #0 + + lda #3 ; send 3 bytes + sta (BufPtr),y + iny + + lda #$20 + sta (BufPtr),y ; hi byte + iny + lda #$52 + sta (BufPtr),y ; lo byte + iny + + ;; Send the 3 digits of the score from MSB to LSB + ;; Offset by #$60 to point to numbers + lda Score+2 ; 100s + clc + adc #$60 + sta (BufPtr),y + iny + + lda Score+1 ; 10s + clc + adc #$60 + sta (BufPtr),y + iny + + lda Score+0 ; 1s + clc + adc #$60 + sta (BufPtr),y + iny + + lda #0 + sta (BufPtr),y ; Length=0, to signal the end of the buffer + iny + + rts +.endproc + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Returns a random 8-bit number inside A (0-255), clobbers Y (0). ;; Requires a 2-byte value on the Zero page called "Seed" @@ -372,7 +484,7 @@ EndRoutine: lda Collision beq NextEnemy - lda #ActorType::NULL + lda #ActorType::NULL ; Set actor to null - TODO: maybe make an explosion sta ActorsArray+Actor::Type,x jmp FinishCollisionCheck @@ -465,8 +577,10 @@ FinishCollisionCheck: lda Collision beq NoCollisionFound - lda #ActorType::NULL + lda #ActorType::NULL ; Delete missile Actor sta ActorsArray+Actor::Type,x + ;; TODO: increment Score + jsr IncrementScore NoCollisionFound: @@ -838,6 +952,40 @@ OAMStartDMACopy: ; DMA copy of OAM data from RAM to PPU lda #$02 ; Every frame, we copy spite data starting at $02** sta PPU_OAM_DMA ; The OAM-DMA copy starts when we write to $4014 +;; TODO +;; Loop all bytes of the background buffer at $7000 until we find length=0 +;; Sending the tiles to the PPU nametable in VRAM +BackgroundCopy: + lda #$70 + sta BufPtr+1 + lda #$00 + sta BufPtr + + ldy #$00 + BufferLoop: + lda (BufPtr),y ; Fetch the length + beq EndBackgroundCopy ; if len is 0, stop reading from bg buffer + + tax ; x = length + + iny + lda (BufPtr),y ; hi byte + sta PPU_ADDR + iny + lda (BufPtr),y ; low byte + sta PPU_ADDR + iny + DataLoop: + lda (BufPtr),y + sta PPU_DATA + iny + dex ; X-- + bne DataLoop + + jmp BufferLoop +EndBackgroundCopy: + + NewColumnCheck: lda XScroll and #%00000111 ; Check if the scroll a multiple of 8 @@ -906,6 +1054,10 @@ SetGameClock: inc Clock60 ; But if it is 60, then increment Clock60 and zero Frame counter lda #0 sta Frame + + ;; TODO: REMOVE + jsr IncrementScore + jsr DrawScore : SetDrawComplete: diff --git a/atlantico/atlantico.nes b/atlantico/atlantico.nes index 01ff9e1..c559f0d 100644 Binary files a/atlantico/atlantico.nes and b/atlantico/atlantico.nes differ diff --git a/atlantico/atlantico.o b/atlantico/atlantico.o index edbfcdf..4cc8e05 100644 Binary files a/atlantico/atlantico.o and b/atlantico/atlantico.o differ