diff --git a/atlantico/Makefile b/atlantico/Makefile index 12f762d..bee39cd 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 4 "fceux atlantico.nes && i3-msg '[id=$(xdotool getactivewindow)] floating enable'" - on-workspace 4 "fceux atlantico.nes" + 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 1db2e67..b5834a8 100755 --- a/atlantico/atlantico.asm +++ b/atlantico/atlantico.asm @@ -42,9 +42,10 @@ ParamAttribs: .res 1 ; Used as parameter to subroutine PrevOAMCount: .res 1 ; Store the previous number of bytes that were sent to the OAM +Seed: .res 2 ; Initialize the 16-bit seed to any value except 0 + ActorsArray: .res MAX_ACTORS * .sizeof(Actor) -Seed: .res 1 ; Used as the RANDOM NUMBER GENERATOR SEED ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PRG-ROM code located at $8000 @@ -69,6 +70,29 @@ LoopButtons: 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" +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; This is a 16-bit Galois Linerar Feedback Shift register with polynomial $0039 +;; The sequence of numbers it generates will repeat after 65535 calls. +;; Execution time is an average of 125 cycles (excluding jsr and rts) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.proc GetRandomNumber + ldy #8 ; Loop counter (generates 8 bits) + lda Seed+0 +: asl ; Shift the register + rol Seed+1 + bcc :+ + eor #$39 ; Apply XOR feedback when a 1 bit is shifted out + : + dey + bne :-- + sta Seed+0 ; Saves the value in A into the Seed + cmp #0 ; Set flags + rts +.endproc + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Subroutine to load all 32 color palette values from ROM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -258,7 +282,13 @@ EndRoutine: sta ParamType ; Load parameter for the actor type lda #223 sta ParamXPos ; Load parameter for actor position X - lda #185 + jsr GetRandomNumber ; load random number into A + + lsr ; Divide by 8 (right shift thrice) + lsr + lsr + clc + adc #180 ; add 180 to lower it sta ParamYPos jsr AddNewActor ; Call the subroutine to add the new missile actor @@ -277,7 +307,16 @@ EndRoutine: sta ParamType ; Load parameter for the actor type lda #235 sta ParamXPos ; Load parameter for actor position X - lda #60 + jsr GetRandomNumber ; load random number into A + + lsr ; Divide by 4 (right shift twice) + lsr + clc + adc #35 ; add 35 to lower it, so its not in the status bar + + ;Adjust the random Y to be between top and bottom + + sta ParamYPos jsr AddNewActor ; Call the subroutine to add the new missile actor @@ -515,30 +554,6 @@ EndRoutine: .endproc -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Returns a random 8 bit number inside A (0-255), clobbers Y (0) -;; requires 1-byte value on the Zero Page called Seed -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; this is an 8 bit galois LFSR with polynomial $1D -;; The sequence of numbers it generates will repeat after 255 calls -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -.proc GetRandomNumber - ldy #8 ; Loop counter (generates 8 bits) - lda Seed ; - -Loop8Times: - asl ; Shift the register left - bcc :+ ; - eor #$1D ; Apply XOR feebback when a 1bit is shifted out - : ; - dey ; - bne Loop8Times ; - - sta Seed ; Saves the value in A - cmp #0 ; - rts ; -.endproc - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Reset handler (called when the NES resets or powers on) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -557,6 +572,10 @@ InitVariables: lda #165 sta YPos + lda #$10 + sta Seed+1 + sta Seed+0 ; Initialize the seed with any value not zero + Main: jsr LoadPalette ; Call LoadPalette subroutine to load 32 colors into our palette diff --git a/atlantico/atlantico.nes b/atlantico/atlantico.nes index 18fe21f..e64e2b3 100644 Binary files a/atlantico/atlantico.nes and b/atlantico/atlantico.nes differ diff --git a/atlantico/atlantico.o b/atlantico/atlantico.o index 3a82003..d9efa3a 100644 Binary files a/atlantico/atlantico.o and b/atlantico/atlantico.o differ