Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 760

Controllers and NMI

$
0
0
So i been digging through some Tutorial on using Controller NMI and i cannot seem to get it working with a sprite i created maybe im doing something wrong?

My main.asm

Code:

.p816.smart.include "Devsub/regs.asm".include "Devsub/variables.asm".include "Devsub/macros.asm".include "Devsub/init.asm".include "Devsub/intro.asm".include "Devsub/music.asm".include "Devsub/Fade.Asm".include "Devsub/introgfxDATA.asm".include "Devsub/MusicRom.asm".segment "CODE"; enters here in forced blankMain:.a16 ; the setting from init code.i16phkplbA8main:;jsr Intro1 ;Rem this to skip introSEP #$20STZ $2100LDA #$80STA $2100;jsr music2 ;Rem this to skip music; COPY PALETTES to PAL_BUFFER;BLOCK_MOVE  length, src_addr, dst_addrBLOCK_MOVE  288, Testspritepal1, PAL_BUFFER; 256 for BG palette, 32 for sprite palette; DMA from PAL_BUFFER to CGRAMjsr DMA_Palette ; in init.asm; COPY sprites to sprite bufferBLOCK_MOVE  12, Sprites, OAM_BUFFERA8 ;block move will put AXY16. Undo that.; COPY just 1 high table numberlda #$6A ;= 01 101010 = flip all the size bits to large ;will give us 16x16 tiles ;leave the 4th sprite small and in negative xsta OAM_BUFFER2; DMA from OAM_BUFFER to the OAM RAMjsr DMA_OAM ; in init.asm; DMA from Spr_Tiles to VRAMlda #V_INC_1 ; the value $80sta VMAIN  ; $2115 = set the increment mode +1ldx #$4000stx VMADDL ; set an address in the vram of $4000lda #1sta $4300 ; transfer mode, 2 registers 1 write  ; $2118 and $2119 are a pair Low/Highlda #$18  ; $2118sta $4301 ; destination, vram dataldx #.loword(Testspritepal2)stx $4302 ; sourcelda #^Testspritepal2sta $4304 ; bankldx #(End_Testspritepal2-Testspritepal2) ;let the assembler figure out   ;the size of the tiles for usstx $4305 ; lengthlda #1sta MDMAEN ; $420b start dma, channel 0;$2101 sssnn-bb;sss = sprite sizes, 000 = 8x8 and 16x16 sprites;nn = displacement for the 2nd set of sprite tiles, 00 = normal;-bb = where are the sprite tiles, in steps of $2000;that upper bit is useless, as usual, so I marked it with a dash -lda #2 ;sprite tiles at $4000sta OBSEL ;= $2101lda #1 ; mode 1, tilesize 8x8 allsta BGMODE ; $2105;allow sprites on the main screenlda #SPR_ON ; $10, only show spritessta TM ; $212clda #NMI_ON|AUTO_JOY_ONsta NMITIMEN ;$4200lda #FULL_BRIGHT ; $0f = turn the screen on, full brighnesssta INIDISP ; $2100Infinite_Loop:A8XY16jsr Wait_NMIjsr DMA_OAM  ;copy the OAM_BUFFER to the OAMjsr Pad_Poll ;read controllersAXY16lda pad1and #KEY_LEFTbeq @not_left@left:A8dec OAM_BUFFER ;decrease the X valuesA16@not_left:lda pad1and #KEY_RIGHTbeq @not_right@right:A8inc OAM_BUFFER ;increase the X valuesA16@not_right:lda pad1and #KEY_UPbeq @not_up@up:A8dec OAM_BUFFER+1 ;decrease the Y valuesA16@not_up:lda pad1and #KEY_DOWNbeq @not_down@down:A8inc OAM_BUFFER+1 ;increase the Y valuesA16@not_down:A8;code goes herejmp Infinite_Loopjmp Wait_NMIPad_Poll:.a8.i16; reads both controllers to pad1, pad1_new, pad2, pad2_new; auto controller reads done, call this once per main loop; copies the current controller reads to these variables; pad1, pad1_new, pad2, pad2_new (all 16 bit)phpA8@wait:; wait till auto-controller reads are donelda $4212lsr abcs @waitA16lda pad1sta temp1 ; save last framelda $4218 ; controller 1sta pad1eor temp1and pad1sta pad1_newlda pad2sta temp1 ; save last framelda $421a ; controller 2sta pad2eor temp1and pad2sta pad2_newplprtsSprites:;4 bytes per sprite = x, y, tile #, attribute.byte $80, $80, $00, SPR_PRIOR_2Wait_NMI:.a8.i16LDA #$80STA $4200;should work fine regardless of size of Alda in_nmi ;load A register with previous in_nmi@check_again:WAI ;wait for an interruptcmp in_nmi;compare A to current in_nmi;wait for it to change;make sure it was an nmi interruptbeq @check_againrtsTIMER:LDX #$0000DELAY_LOOP:inxcpx #$FFFFBNE DELAY_LOOPrts;Music startmusic2:AXY16lda #.loword(music_code)ldx #^music_codejsl SPC_InitAXY16lda #$0001jsl SPC_Stereolda #$0070taxjsl SPC_Global_VolumeAXY16;a = address of song;x = bank of songlda #.loword(song1)ldx #^song1jsl SPC_Play_Songrts.include "Devsub/header.asm"
My GFX data

Code:

;THIS IS ALL DATA STORED IN ROM.segment "RODATA1";background1 for startP1:.byte $60, $0C, $07, $00, $80, $10, $80, $14, $25, $04, $09, $00, $A0, $14, $C0, $10, $A0, $18, $C0, $14, $A1, $14, $65, $0C, $C0, $18, $A1, $18, $A2, $14, $E0, $14.byte $C1, $10, $84, $10, $A2, $18, $C1, $18, $A3, $14, $00, $15, $C2, $10, $66, $0C, $E0, $18, $84, $14, $86, $0C, $A3, $18, $C2, $18, $20, $15, $A5, $10, $C3, $18.byte $87, $10, $A5, $14, $C4, $10, $A4, $18, $E3, $10, $88, $08, $C4, $18, $E3, $18, $C5, $14, $A6, $14, $A7, $10, $E6, $08, $88, $10, $E4, $14, $A9, $08, $C5, $18.byte $A7, $14, $C6, $14, $A6, $18, $10, $00, $AA, $04, $8A, $08, $A8, $14, $C7, $14, $E5, $14, $C6, $18, $A9, $10, $C7, $10, $E6, $14, $CA, $08, $E7, $14, $05, $11.byte $CB, $04, $8A, $10, $A9, $14, $28, $09, $07, $11, $A8, $18, $06, $19, $E8, $14, $E7, $18, $AA, $14, $4A, $01, $07, $19, $EB, $08, $E9, $10, $AC, $0C, $27, $11.byte $CA, $14, $CE, $04, $27, $19, $53, $00, $E9, $18, $0C, $05, $0E, $01, $AC, $14, $0A, $11, $29, $15, $28, $19, $2C, $05, $EB, $10, $49, $11, $F1, $00, $AF, $10.byte $0A, $15, $CF, $0C, $2A, $11, $49, $19, $2C, $0D, $6A, $11, $4E, $01, $2D, $09, $ED, $10, $8D, $01, $6B, $0D, $4A, $19, $75, $04, $F3, $00, $93, $08, $2B, $15.byte $6A, $15, $B5, $00, $4D, $0D, $6F, $05, $6C, $15, $2D, $15, $2E, $11, $32, $01, $AF, $01, $97, $04, $71, $01, $10, $11, $B6, $04, $34, $01, $8C, $15, $8E, $0D.byte $CF, $01, $12, $0D, $B6, $0C, $8D, $11, $B1, $01, $6E, $15, $B8, $08, $D0, $01, $15, $05, $73, $01, $D7, $04, $D6, $08, $AF, $09, $50, $11, $D4, $14, $B8, $0C.byte $F1, $01, $D6, $10, $71, $0D, $AE, $15, $CD, $15, $D2, $01, $B1, $09, $D8, $0C, $6F, $19, $D6, $14, $B2, $05, $D8, $10, $F0, $09, $CF, $11, $F2, $05, $F3, $01.byte $D8, $14, $CE, $19, $B0, $15, $12, $02, $F6, $14, $F8, $10, $F7, $14, $74, $11, $B3, $0D, $11, $0A, $16, $15, $F0, $11, $F8, $18, $F3, $09, $B5, $09, $57, $0D.byte $B2, $19, $18, $19, $F0, $19, $F4, $09, $F2, $11, $17, $1D, $33, $0A, $37, $19, $32, $0E, $31, $16, $F2, $19, $D4, $15, $57, $19, $B7, $0D, $14, $12, $F4, $15.byte $33, $16, $37, $21, $32, $1A, $53, $16, $54, $12, $14, $1A, $D6, $15, $52, $1A, $54, $16, $13, $1E, $15, $1A, $97, $1D, $35, $16, $54, $1A, $13, $22, $73, $1A.byte $15, $1E, $16, $1A, $98, $25, $55, $1A, $54, $1E, $75, $16, $56, $1A, $34, $22, $75, $1E, $74, $22, $D8, $25, $95, $1A, $76, $1E, $36, $22, $95, $22, $96, $1E.byte $74, $26, $76, $22, $17, $26, $77, $1E, $95, $26, $96, $22, $57, $26, $96, $26, $B6, $22, $95, $2A, $57, $2A, $76, $2A, $B6, $26, $97, $26, $B7, $26, $B6, $2A.byte $95, $2E, $97, $2A, $B6, $2E, $B7, $2A, $77, $2E, $D7, $2A, $B7, $2E, $B6, $32, $D7, $2E, $D7, $32, $F7, $2E, $D8, $32, $D7, $36, $F7, $36, $F8, $36, $F8, $3A;background2 for start.segment "RODATA2"T11:.incbin "GFXsub/1stScreen.map".segment "RODATA3"T12:.incbin "GFXsub/1stScreen1.chr".segment "RODATA4"T13:.incbin "GFXsub/1stScreen2.chr"P2:.byte $00, $00, $01, $00, $02, $00, $03, $00, $04, $00, $22, $00, $05, $00, $24, $00, $25, $00, $06, $00, $07, $00, $24, $04, $08, $00, $45, $00, $09, $00, $47, $00.byte $28, $00, $67, $00, $0A, $00, $68, $00, $49, $00, $2A, $00, $0C, $00, $67, $08, $68, $04, $89, $00, $4A, $04, $8A, $00, $4C, $00, $0F, $00, $AB, $00, $6C, $04.byte $AC, $00, $A9, $0C, $AD, $00, $6E, $00, $8C, $04, $CD, $00, $AB, $08, $6F, $00, $8F, $00, $CE, $00, $8E, $08, $CF, $00, $B0, $04, $8A, $1C, $91, $00, $AD, $0C.byte $F0, $00, $EC, $10, $D0, $04, $AF, $0C, $B2, $00, $87, $30, $EE, $0C, $F1, $00, $D2, $04, $CD, $1C, $0C, $15, $F2, $00, $A2, $48, $F1, $08, $D0, $0C, $12, $01.byte $D3, $08, $F4, $00, $2E, $11, $11, $09, $D2, $0C, $F4, $08, $13, $09, $15, $01, $F4, $0C, $CC, $30, $F5, $08, $4E, $19, $C7, $44, $12, $11, $EF, $20, $34, $05.byte $E3, $54, $50, $15, $14, $11, $34, $0D, $36, $05, $35, $0D, $13, $19, $CB, $40, $36, $0D, $12, $21, $70, $1D, $15, $15, $03, $5D, $37, $0D, $23, $61, $55, $0D.byte $54, $15, $05, $59, $57, $09, $55, $15, $43, $61, $24, $61, $90, $21, $E9, $4C, $57, $11, $54, $1D, $44, $61, $43, $65, $57, $15, $25, $61, $58, $0D, $44, $65.byte $31, $31, $56, $19, $97, $0D, $55, $1D, $46, $61, $45, $65, $78, $15, $27, $5D, $96, $15, $B3, $21, $54, $25, $46, $65, $D1, $25, $99, $0D, $98, $15, $96, $1D.byte $78, $19, $66, $65, $67, $61, $B8, $15, $2B, $59, $67, $65, $79, $19, $77, $21, $74, $31, $B6, $1D, $96, $25, $68, $65, $B8, $15, $68, $61, $9A, $15, $52, $41.byte $DA, $11, $88, $65, $B8, $1D, $F3, $29, $89, $65, $6A, $61, $DA, $15, $BA, $1D, $4F, $51, $96, $31, $BA, $21, $D7, $29, $AA, $65, $FB, $15, $6E, $59, $B9, $25.byte $AB, $61, $FA, $1D, $73, $49, $F9, $21, $15, $2E, $DB, $21, $8C, $61, $B5, $39, $1A, $22, $B4, $45, $DB, $25, $19, $26, $1C, $1A, $91, $51, $FC, $21, $D9, $31.byte $1B, $26, $3B, $1E, $B3, $4D, $B0, $59, $1C, $26, $3B, $26, $FA, $2D, $57, $32, $3C, $22, $FC, $29, $3A, $2E, $3C, $2A, $5C, $22, $19, $3A, $1C, $2E, $5C, $2A.byte $7B, $2A, $5D, $2A, $5B, $32, $7D, $2A, $78, $3A, $3D, $32, $7D, $2E, $3B, $3E, $9C, $2E, $7D, $32, $B9, $36, $5C, $36, $9B, $36, $9E, $2E, $BC, $32, $7E, $36.byte $9D, $36, $9C, $3E, $BE, $32, $7B, $46, $DB, $3E, $9E, $3A, $DD, $3A, $9D, $42, $FE, $36, $BC, $46, $FD, $3E, $FB, $46, $DE, $42, $1D, $3B, $BE, $4A, $1D, $43.byte $FE, $46, $1F, $3F, $DC, $4E, $FF, $42, $FE, $4A, $1D, $4B, $DE, $4E, $5E, $43, $1D, $53, $FD, $56, $1F, $4B, $3D, $53, $5E, $4B, $1F, $53, $5E, $53, $1E, $5B.byte $3D, $5F, $9F, $53, $3F, $5F, $7E, $5B, $5E, $63, $BF, $57, $7E, $63, $7E, $6B, $BE, $63, $BF, $67, $9E, $6F, $9E, $73, $BF, $77, $DF, $77, $DF, $7F, $FF, $7FT21:; $700 = 1792 bytes.incbin "GFXsub/back2.map".segment "RODATA5"T22:; 8bpp tileset.incbin "GFXsub/back2.chr".segment "RODATA6"T23:; 8bpp tileset.incbin "GFXsub/back22.chr".segment "RODATA7"music_code:.incbin "MUSIC/spc700.bin", 0, 31225;put the first 32768 bytes heremusic_code_end:.segment "RODATA9"Testspritepal1:.incbin "GFXsub/default.pal";.incbin "Testsprite/sprite.pal".byte $00, $00, $1F, $00, $E0, $03, $00, $7C, $1F, $00, $E0, $03, $00, $7C, $00, $00.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00.byte $00, $00, $00, $00, $84, $10, $C6, $18, $08, $21, $4A, $29, $8C, $31, $CE, $39.byte $10, $42, $52, $4A, $94, $52, $D6, $5A, $18, $63, $5A, $6B, $9C, $73, $FF, $7F.byte $00, $00, $04, $00, $08, $00, $0C, $00, $10, $00, $14, $00, $18, $00, $1F, $00.byte $9F, $10, $1F, $21, $9F, $31, $1F, $42, $9F, $52, $1F, $63, $9F, $73, $FF, $7F.byte $00, $00, $80, $00, $00, $01, $80, $01, $00, $02, $80, $02, $00, $03, $E0, $03.byte $E4, $13, $E8, $23, $EC, $33, $F0, $43, $F4, $53, $F8, $63, $FC, $73, $FF, $7F.byte $00, $00, $00, $10, $00, $20, $00, $30, $00, $40, $00, $50, $00, $60, $00, $7C.byte $84, $7C, $08, $7D, $8C, $7D, $10, $7E, $94, $7E, $18, $7F, $9C, $7F, $FF, $7F.byte $00, $00, $84, $00, $08, $01, $8C, $01, $10, $02, $94, $02, $18, $03, $FF, $03.byte $FF, $13, $FF, $23, $FF, $33, $FF, $43, $FF, $53, $FF, $63, $FF, $73, $FF, $7F.byte $00, $00, $04, $10, $08, $20, $0C, $30, $10, $40, $14, $50, $18, $60, $1F, $7C.byte $9F, $7C, $1F, $7D, $9F, $7D, $1F, $7E, $9F, $7E, $1F, $7F, $9F, $7F, $FF, $7F.byte $00, $00, $80, $10, $00, $21, $80, $31, $00, $42, $80, $52, $00, $63, $E0, $7F.byte $E4, $7F, $E8, $7F, $EC, $7F, $F0, $7F, $F4, $7F, $F8, $7F, $FC, $7F, $FF, $7FTestspritepal2:.incbin "Testsprite/test.chr";.incbin "Testsprite/sprite.chr"End_Testspritepal2:
Now everything seems to work just cannot get my test sprite to move at all

now rest stuff i added in attachment is my setup for this
init.asm

macros.asm

regs.asm

variables.asm

Test.chr

Statistics: Posted by cronambs — Sun Sep 01, 2024 12:17 pm — Replies 2 — Views 71



Viewing all articles
Browse latest Browse all 760