Lightgun techdemo

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Lightgun techdemo

Post by atari2600a »

Well I thought it necessary to break my previous thread off into a more organized one. I will be updating this post as necessary, & hopefully this game'll turn out to be worth downloading.

ROM & Source: http://mtac.profusehost.net/misc/NES/

Code: Select all

	*=$C000

	!cpu 6502

	!to "gameprg.bin", plain

	sprdma=$00		;set here do avoid annoying ACME warning



;=============================Init===========================================



reset	CLC			;clear crap

	LDA #0

	STA scrstat

	

vb1	LDA $2002

	BPL vb1

vb2	LDA $2002

	BPL vb2



	SEI

	LDX #$ff

	TXS

	LDA #0

	STA $2000		;kill PPU

	STA $2001



	LDA #$20

	LDX #0

	LDY #0

nt1wrt	STA $2006

	STX $2006

	STY $2007

	INX

	CPY #00

	BNE nt1wrt

	CMP #$24

	ADC #1

	BNE nt1wrt



	LDA #$3F

	LDX #$00

	STA $2006

	STX $2006

pal1wrt	LDY bgpal,x

	STY $2007

	INX

	CPX #$20

	BNE pal1wrt

	

	LDX #0

sprwrt	LDA spr1,x

	STA sprdma

	INX

	CPX #4

	BNE sprwrt

	LDA #$00

	STA $4014

	

	

	LDA #%10001000		;Enable graphics

	STA $2000

	STA ppu0

	LDA #%00011110

	STA $2001

	STA ppu1

	CLI

	

	

loop	JMP loop





;==========================vblank=======================================



vblank

	INC sprdma+3

	LDA sprdma+3		;NOTE TO SELF:  Find out why Y cord write

	;CMP #0			;is causing sprite to dissapear

	;BNE scrchk

	;INC sprdma

	

scrchk	LDA scrstat

	CMP #1

	BEQ blkchk

	CMP #2

	BEQ whtchk



gunchk		

	LDA $4016

	AND #%00010000		;check for trigger status

	CMP #%00010000

	BEQ shoot



dmaset	LDA $00

	STA $4014

	

noshoot

	RTI



shoot	LDA #%00000110		;kill PPU

	STA $2001

	INC scrstat

	JMP dmaset

	

blkchk	LDA $4016

	AND #%00001000		;check for black

	CMP #%00000000

	BNE usuck

	LDA #1			;Don't increment so trigger can be held

	STA scrstat

	STA sprdma+1

	LDA #%00010110

	STA $2001

	JMP dmaset

	

whtchk	LDA $4016		;check for white

	AND #%00001000

	CMP #%00001000

	BNE usuck

	INC p1scr

	LDA #0			;reset scrstat

	STA scrstat

	STA sprdma

	LDA ppu1

	STA $2001

	INC p1scr

	LDA p1scr

	LDX #$24

	LDY #$00

	STX $2006

	STY $2006

	STA $2007

	JMP dmaset

	

usuck	LDA #$20

	LDX #$00		;write text to upper-left corner

suck1	LDY sucktxt,X

	STA $2006

	STX $2006

	STY $2007

	INX

	CPY "*"

	BNE suck1

	LDA ppu1

	STA $2001

	RTI

	

irq	RTI

	

;==========================Data=========================================



bgpal	!byte $0F,$2A,$2B,$2C,$34,$35,$36,$37

	!byte $38,$39,$3A,$3B,$3C,$3D,$3E,$3F



sprpal	!byte $00,$14,$15,$16,$04,$05,$06,$07

	!byte $08,$09,$0A,$0B,$0C,$0D,$0E,$0F



spr1	!byte %00001000,%00000000,%00000011,%00001000



sucktxt	!text "YOU SUCK*"





;==========================Interrupts===================================



	!align $FFFA, $FFFA, $00

	!word vblank		;

	!word reset		;

	!word irq		;IRQ vector currently set to nothing



;==========================Labels=======================================



ppu0=$0200

ppu1=$0201

scrstat=$0202

p1scr=$0203

Code: Select all

	*=$0000

	!CPU 6502

	!to "gamechr.bin", plain

	;

	!byte %00000010	;2222223.

	!byte %00000010	;2222223.

	!byte %00000010	;2222223.

	!byte %00000010	;2222223.

	!byte %00000010	;2222223.

	!byte %00000010	;2222223.

	!byte %11111110	;1111113.

	!byte %00000000	;........

	;

	!byte %11111110	;

	!byte %11111110	;

	!byte %11111110	;

	!byte %11111110	;

	!byte %11111110	;

	!byte %11111110	;

	!byte %00000010	;

	!byte %00000000	;

	;

	;

	!align $0200,$0200,$00

	;

	;STOLEN C64 ASCII SET, remember to replace w/ tight-ass custom oldskool compy font

	!byte $00,$00,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 32

	!byte $18,$18,$18,$18,$00,$00,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 33

	!byte $66,$66,$66,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 34

	!byte $66,$66,$FF,$66,$FF,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 35

	!byte $18,$3E,$60,$3C,$06,$7C,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 36

	!byte $62,$66,$0C,$18,$30,$66,$46,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 37

	!byte $3C,$66,$3C,$38,$67,$66,$3F,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 38

	!byte $06,$0C,$18,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 39

	!byte $0C,$18,$30,$30,$30,$18,$0C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 40

	!byte $30,$18,$0C,$0C,$0C,$18,$30,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 41

	!byte $00,$66,$3C,$FF,$3C,$66,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 42

	!byte $00,$18,$18,$7E,$18,$18,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 43

	!byte $00,$00,$00,$00,$00,$18,$18,$30,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 44

	!byte $00,$00,$00,$7E,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 45

	!byte $00,$00,$00,$00,$00,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 46

	!byte $00,$03,$06,$0C,$18,$30,$60,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 47

	!byte $3C,$66,$6E,$76,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 48

	!byte $18,$18,$38,$18,$18,$18,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 49

	!byte $3C,$66,$06,$0C,$30,$60,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 50

	!byte $3C,$66,$06,$1C,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 51

	!byte $06,$0E,$1E,$66,$7F,$06,$06,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 52

	!byte $7E,$60,$7C,$06,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 53

	!byte $3C,$66,$60,$7C,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 54

	!byte $7E,$66,$0C,$18,$18,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 55

	!byte $3C,$66,$66,$3C,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 56

	!byte $3C,$66,$66,$3E,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 57

	!byte $00,$00,$18,$00,$00,$18,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 58

	!byte $00,$00,$18,$00,$00,$18,$18,$30,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 59

	!byte $0E,$18,$30,$60,$30,$18,$0E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 60

	!byte $00,$00,$7E,$00,$7E,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 61

	!byte $70,$18,$0C,$06,$0C,$18,$70,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 62

	!byte $3C,$66,$06,$0C,$18,$00,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 63

	!byte $3C,$66,$6E,$6E,$60,$62,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 64

	!byte $18,$3C,$66,$7E,$66,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 65

	!byte $7C,$66,$66,$7C,$66,$66,$7C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 66

	!byte $3C,$66,$60,$60,$60,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 67

	!byte $78,$6C,$66,$66,$66,$6C,$78,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 68

	!byte $7E,$60,$60,$78,$60,$60,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 69

	!byte $7E,$60,$60,$78,$60,$60,$60,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 70

	!byte $3C,$66,$60,$6E,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 71

	!byte $66,$66,$66,$7E,$66,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 72

	!byte $3C,$18,$18,$18,$18,$18,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 73

	!byte $1E,$0C,$0C,$0C,$0C,$6C,$38,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 74

	!byte $66,$6C,$78,$70,$78,$6C,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 75

	!byte $60,$60,$60,$60,$60,$60,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 76

	!byte $63,$77,$7F,$6B,$63,$63,$63,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 77

	!byte $66,$76,$7E,$7E,$6E,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 78

	!byte $3C,$66,$66,$66,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 79

	!byte $7C,$66,$66,$7C,$60,$60,$60,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 80

	!byte $3C,$66,$66,$66,$66,$3C,$0E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 81

	!byte $7C,$66,$66,$7C,$78,$6C,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 82

	!byte $3C,$66,$60,$3C,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 83

	!byte $7E,$18,$18,$18,$18,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 84

	!byte $66,$66,$66,$66,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 85

	!byte $66,$66,$66,$66,$66,$3C,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 86

	!byte $63,$63,$63,$6B,$7F,$77,$63,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 87

	!byte $66,$66,$3C,$18,$3C,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 88

	!byte $66,$66,$66,$3C,$18,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 89

	!byte $7E,$06,$0C,$18,$30,$60,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 90

	!byte $3C,$30,$30,$30,$30,$30,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 91

	!byte $0C,$12,$30,$7C,$30,$62,$FC,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 92

	!byte $3C,$0C,$0C,$0C,$0C,$0C,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 93

	!byte $00,$18,$3C,$7E,$18,$18,$18,$18,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 94

	!byte $00,$10,$30,$7F,$7F,$30,$10,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Character 95

	;

	;

	;

	!align $1000, $1000, $00

	;

	;

	!byte %00000000	;........

	!byte %00011000	;...33...

	!byte %00111100	;..3331..

	!byte %01110010	;.333221.

	!byte %01100010	;.332221.

	!byte %00000100	;..2221..

	!byte %00011000	;...11...

	!byte %00000000	;........

	;

	!byte %00000000	;

	!byte %00011000	;

	!byte %00111000	;

	!byte %01111100	;

	!byte %01111100	;

	!byte %00111000	;

	!byte %00000000	;

	!byte %00000000	;

	;

	!byte %11111111	;33333333

	!byte %11111111	;33333333

	!byte %11111111	;33333333

	!byte %11111111	;33333333

	!byte %11111111	;33333333

	!byte %11111111 ;33333333

	!byte %11111111	;33333333

	!byte %11111111	;33333333

	;

	!byte %11111111

	!byte %11111111

	!byte %11111111

	!byte %11111111

	!byte %11111111

	!byte %11111111

	!byte %11111111

	

	





	;

	!align $2000,$2000, $00

	!eof

Code: Select all

	*=$000000

	!to "techdemo.nes", plain

	

	;====================iNES Header Begin====================

	

	; iNES identifier

	

	!text "NES"

	!byte $1A

	

	; Number of PRG-ROM blocks

	

	!byte $01

	

	;

	; Number of CHR-ROM blocks

	

	!byte $01

	

	;	

	; ROM control bytes: Horizontal mirroring, no SRAM

	; or trainer, Mapper #0

	

	!byte %00000000, %00000000

	

	;

	; Filler

	

	!byte $00,$00,$00,$00,$00,$00,$00,$00

	

	;====================iNES Header End======================

	;

	;=====================Program Start=======================

	!bin "gameprg.bin"

	!bin "gamechr.bin"

	!eof
Last edited by atari2600a on Tue Oct 23, 2007 1:05 pm, edited 3 times in total.

Code: Select all

          *=$0000
loop      JMP loop
          .eof
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

Anyways, I can't get the screen to turn black on the trigger being pulled, under the 'shoot' label. (Also I've noticed the Nesdevwiki info on the Zapper conflicts w/ the nestech.txt info) Can anybody see why?

Oh, & I know the sprite isn't moving. I'm still tweaking that code, & I can't really fix it on this computer right now as it's runing Ubuntu linux & I'd have to run Wine to compile each time for each file, w/o the BAT file I have set up.

Code: Select all

          *=$0000
loop      JMP loop
          .eof
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

Right now I'm stuck on getting the screen to blank on the shoot routine. I'm reading the trigger fine now but for some reason somewhere along the line writing #0 to $2001 isn't clearing the screen. Should I use a bitwise instruction on it (& by it, I mean the buffer in memory I'm using) instead?

Code: Select all

          *=$0000
loop      JMP loop
          .eof
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

atari2600a wrote:but for some reason somewhere along the line writing #0 to $2001 isn't clearing the screen.
Clearing CPU $2001 to 0 fills the screen with the color in palette entry 0. Do you also set palette entry 0 (PPU $3F00) to #$0F?
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

tepples wrote:
atari2600a wrote:but for some reason somewhere along the line writing #0 to $2001 isn't clearing the screen.
Clearing CPU $2001 to 0 fills the screen with the color in palette entry 0. Do you also set palette entry 0 (PPU $3F00) to #$0F?
So THAT'S what bg palette #0 does! Damn I really wish the NES was as well documented as 6502 computers!:P

Well anyways I'm getting this odd scrolling effect. The effect is *completely* unintentional, but the effect looks awesome nonetheless. I should *really* start uploading my *.NES ROM to one of my servers...

Code: Select all

          *=$0000
loop      JMP loop
          .eof
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

The address you set with $2006 is the same address that the PPU uses for its scrolling. So whenever you draw stuff to $2007, you're unintentionally mucking up the scroll. Therefore, in VBlank, after you're done drawing, you should always reset the scroll with a write to $2000 (to set the NT bits) and dual writes to $2005 (to set the X,Y scroll). Once you set the scroll in that manner, do not mess with $2006 or $2007 any more or else the scroll will get mucked up again
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

Hmm...that would *kinda* explain it. The $2006/$2007 code in usuck was put there when it started acting up, but it shouldn't even be executed unless the trigger was pulled away from the screen or an IRQ was executed...I'll have to look more into this...

Code: Select all

          *=$0000
loop      JMP loop
          .eof
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Something else it might be:

If you turn the PPU on too late (after rendering has started), you'll miss the scroll reset (which the PPU does at the start of the frame -- but only if the PPU is on). If you're turning off the PPU during VBlank, be sure you're turning it back on before VBlank is over (or don't turn it off at all -- you don't need to have the PPU off if you finish all your drawing in VBlank)
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Disch wrote:If you're turning off the PPU during VBlank, be sure you're turning it back on before VBlank is over (or don't turn it off at all -- you don't need to have the PPU off if you finish all your drawing in VBlank)
IMO, "good" VBlank code should always end before VBlank is over. If it doesn't, turning the PPU off or not, you get visual glitches. Sure, the effects are much worse when the PPU is on, because not only you'll get currupt graphics for that frame, but you may end up corrupting the name tables and so on, affecting future frames. If you have rendering off, when you turn it back on the screen will just be misplaced, and the image will appear to "jump" because of that one frame.

Anyway, always do your best to keep your VBlank code within VBlank time. If you need more than that time, you'll either have to turn rendering off early, or turn it on late, but always at the same time, by means of IRQ's, sprite 0 hits or timed code, so that the image does not "jump".
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

Wow, it's been a while since I last updated this thread! :P

Anyways, now it just stalls somewhere after blkchk, & I can't seem to find out why...can anyone help me on this?

Also added link to ROM to first post...

Code: Select all

          *=$0000
loop      JMP loop
          .eof
Post Reply