
I managed to move my little dude in all 4 directions, but the screen is garbled! My code is as follows...
.inesprg 1 ; 1x 16KB PRG code
.ineschr 1 ; 1x 8KB CHR data
.inesmap 0 ; mapper 0 = NROM, no bank swapping
.inesmir 1 ; background mirroring
;;;;;;;;;;;;;;;
.bank 0
.org $C000
RESET:
SEI
CLD
LDX #$40
STX $4017
LDX #$FF
TXS
INX
STX $2000
STX $2001
STX $4010
vblankwait1:
BIT $2002
BPL vblankwait1
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0300, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0200, x
INX
BNE clrmem
vblankwait2:
BIT $2002
BPL vblankwait2
LoadPalettes:
LDA $2002 ; read PPU STAtus to reset the high/low latch
LDA #$3F
STA $2006 ; write the high byte of $3F00 address
LDA #$00
STA $2006 ; write the low byte of $3F00 address
LDX #$00
LoadPalettesLoop:
LDA palette, x ;load palette byte
STA $2007 ;write to PPU
INX ;set index to next byte
CPX #$20
BNE LoadPalettesLoop ;if x = $20, 32 bytes copied, all done
load_sprite_data:
LDX #$00
.loop:
LDA data, x
STA $0200, x
INX
CPX #$FF
BNE .loop
RTS
LDA #%10000000 ; enable NMI, sprites from Pattern Table 1
STA $2000
LDA #%00010000 ; enable sprites
STA $2001
Forever:
JMP Forever ;jump back to Forever, infinite loop
NMI:
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$02
STA $4014 ; set the high byte (02) of the RAM address, STArt the transfer
LatchController:
LDA #$01
STA $4016
LDA #$00
STA $4016 ; tell both the controllers to latch buttons
ReadA:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
ReadADone:
ReadB:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadBDone ; branch to ReadADone if button is NOT pressed (0)
ReadBDone:
ReadSe:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadSeDone ; branch to ReadADone if button is NOT pressed (0)
ReadSeDone:
ReadSt:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadStDone ; branch to ReadADone if button is NOT pressed (0)
ReadStDone:
ReadD:
LDA $4016 ; dans l'ordre - A,B,Se,St,H,B,G,D
AND #%00000001
BEQ ReadDDone
LDA $0200
SEC
SBC #$01
STA $0200
LDA $0204
SEC
SBC #$01
STA $0204
LDA $0208
SEC
SBC #$01
STA $0208
LDA $020C
SEC
SBC #$01
STA $020C
ReadDDone:
ReadU:
LDA $4016 ; dans l'ordre - A,B,Se,St,H,B,G,D
AND #%00000001
BEQ ReadUDone
LDA $0200
CLC
ADC #$01
STA $0200
LDA $0204
CLC
ADC #$01
STA $0204
LDA $0208
CLC
ADC #$01
STA $0208
LDA $020C
CLC
ADC #$01
STA $020C
ReadUDone:
LDA $4016 ; dans l'ordre - A,B,Se,St,H,B,G,D
AND #%00000001
BEQ ReadLDone
LDA $0203
SEC
SBC #$01
STA $0203
LDA $0207
SEC
SBC #$01
STA $0207
LDA $020B
SEC
SBC #$01
STA $020B
LDA $020F
SEC
SBC #$01
STA $020F
ReadLDone:
LDA $4016 ; dans l'ordre - A,B,Se,St,H,B,G,D
AND #%00000001
BEQ ReadRDone
LDA $0203
CLC
ADC #$01
STA $0203
LDA $0207
CLC
ADC #$01
STA $0207
LDA $020B
CLC
ADC #$01
STA $020B
LDA $020F
CLC
ADC #$01
STA $020F
ReadRDone:
RTI
;;;;;;;;;;;;;;
.bank 1
.org $E000
palette:
.db $0F,$29,$37,$3D,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F
.db $0F,$29,$37,$3D,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C
data:
.db $80,$00,$00,$80,$80,$01,$00,$88,$88,$02,$00,$80,$88,$03,$00,$88
.org $FFFA ;first of the three vectors STArts here
.dw NMI ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
.dw RESET ;when the processor first turns on or is reset, it will jump
;to the label RESET:
.dw 0 ;external interrupt IRQ is not used in this tutorial
;;;;;;;;;;;;;;
.bank 2
.org $0000
.incbin "mario.chr" ;includes 8KB graphics file from SMB1