aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-06 03:31:27 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-06 03:31:27 -0400
commitae6804de4a6607e67c7dd54e7d0a03b77c651245 (patch)
tree6d3f7a73103a80df8857e764337bd25ad8740ad4
parente41acefb3a71bfa430768b8f0766ba150137a748 (diff)
downloadnes-snake-ae6804de4a6607e67c7dd54e7d0a03b77c651245.tar.gz
nes-snake-ae6804de4a6607e67c7dd54e7d0a03b77c651245.zip
copy over some changes from the project skeleton
-rw-r--r--Makefile6
-rw-r--r--linkfile2
-rw-r--r--main.s (renamed from snake.s)91
-rw-r--r--sprites.chr (renamed from snake.chr)bin8192 -> 8192 bytes
4 files changed, 67 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index b3bfaac..4353c6b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
NAME = snake
-OBJS = snake.o
+OBJS = main.o
CC = wla-6502
LD = wlalink
@@ -15,11 +15,11 @@ $(NAME).nes: $(NAME).rom header.bin
$(NAME).rom: $(OBJS) linkfile
$(LD) $(LDFLAGS) linkfile $@
-snake.o: snake.chr
-
%.o: %.s
$(CC) $(CFLAGS) -o $<
+main.o: sprites.chr
+
run: $(NAME).nes
fceux $(NAME).nes
diff --git a/linkfile b/linkfile
index c41ff42..3dddda7 100644
--- a/linkfile
+++ b/linkfile
@@ -1,2 +1,2 @@
[objects]
-snake.o
+main.o
diff --git a/snake.s b/main.s
index 58665ba..1a12ed7 100644
--- a/snake.s
+++ b/main.s
@@ -15,34 +15,47 @@ BANKS 1
.ENDRO
- .enum $0000
+.ENUM $0000
buttons_pressed DB
head_x DB
head_y DB
direction DB ; 0: up, 1: down, 2: left, 3: right
frame_skip DB
frame_count DB
- .ende
+.ENDE
.bank 0
.org $0000
+; the ppu takes two frames to initialize, so we have some time to do whatever
+; initialization of our own that we want to while we wait. we choose here to
+; set up cpu flags in the first frame and clear out system ram in the second
+; frame (clearing out ram isn't at all necessary, but we can't do anything
+; useful at this point anyway, so we may as well in order to make things more
+; predictable). clearing out system ram actually takes quite a bit longer than
+; a frame (a frame is ~2273 cycles, or ~324-1136 opcodes), but we may as well
+; start the process while we wait.
RESET:
- SEI ; disable IRQs
- CLD ; disable decimal mode
+ SEI ; disable IRQs
+ CLD ; disable decimal mode
LDX #$40
- STX $4017.W ; disable APU frame IRQ
+ STX $4017.w ; disable APU frame IRQ
LDX #$FF
- TXS ; Set up stack
- INX ; now X = 0
- STX $2000.W ; disable NMI
- STX $2001.W ; disable rendering
- STX $4010.W ; disable DMC IRQs
+ TXS ; Set up stack (grows down from $FF to $00, at $0100-$01FF)
+ INX ; now X = 0
+ STX $2000.w ; disable NMI (we'll enable it later once the ppu is ready)
+ STX $2001.w ; disable rendering (same)
+ STX $4010.w ; disable DMC IRQs
vblankwait1: ; First wait for vblank to make sure PPU is ready
- BIT $2002
- BPL vblankwait1
-
+ BIT $2002 ; bit 7 of $2002 is reset once vblank ends
+ BPL vblankwait1 ; and bit 7 is what is checked by BPL
+
+ ; set everything in ram ($0000-$07FF) to $00, except for $0200-$02FF which
+ ; is conventionally used to hold sprite attribute data. we set that range
+ ; to $FE, since that value as a position moves the sprites offscreen, and
+ ; when the sprites are offscreen, it doesn't matter which sprites are
+ ; selected or what their attributes are
clrmem:
LDA #$00
STA $0000, x
@@ -53,14 +66,46 @@ clrmem:
STA $0600, x
STA $0700, x
LDA #$FE
- STA $0200, x ;move all sprites off screen
+ STA $0200, x
INX
BNE clrmem
+ ; initialize variables in ram
+ LDA #$00
+ STA buttons_pressed
+ STA direction
+ STA frame_count
+ LDA #$80
+ STA head_x
+ STA head_y
+ LDA #30
+ STA frame_skip
+
+ LDA #$32
+ STA $0201 ; set the sprite number to display
+ LDA #$00
+ STA $0202 ; set the sprite attributes (palette, flipping, etc)
+
+ LDA #$33
+ STA $0205 ; set the sprite number to display
+ LDA #$00
+ STA $0206 ; set the sprite attributes (palette, flipping, etc)
+
+ LDA #$34
+ STA $0209 ; set the sprite number to display
+ LDA #$00
+ STA $020A ; set the sprite attributes (palette, flipping, etc)
+
+ LDA #$35
+ STA $020D ; set the sprite number to display
+ LDA #$00
+ STA $020E ; set the sprite attributes (palette, flipping, etc)
+
vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT $2002
BPL vblankwait2
+ ; now that the ppu is ready, we can start initializing it
LoadPalettes:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$3F
@@ -69,23 +114,12 @@ LoadPalettes:
STA $2006 ; write the low byte of $3F00 address
LDX #$00
LoadPalettesLoop:
- LDA palette.w, x ;load palette byte
+ LDA palette.w, x ;load palette byte
STA $2007 ;write to PPU
INX ;set index to next byte
- CPX #$20
+ CPX #$20
BNE LoadPalettesLoop ;if x = $20, 32 bytes copied, all done
- ; initialize variables in ram
- LDA #$00
- STA buttons_pressed
- STA direction
- STA frame_count
- LDA #$80
- STA head_x
- STA head_y
- LDA #30
- STA frame_skip
-
LDA #%00010000 ; enable sprites
STA $2001
@@ -95,6 +129,7 @@ LoadPalettesLoop:
loop:
JMP loop
+
read_controller1:
; latch
LDA #$01
@@ -216,4 +251,4 @@ palette:
.bank 1 slot 1
.org $0000
- .incbin "snake.chr"
+ .incbin "sprites.chr"
diff --git a/snake.chr b/sprites.chr
index fa71045..fa71045 100644
--- a/snake.chr
+++ b/sprites.chr
Binary files differ