Converted to Ophis, ripped out pad reading code to start over

This commit is contained in:
2012-11-04 12:00:03 -05:00
parent 4c5b4719fa
commit ff7579cdfe
2 changed files with 49 additions and 94 deletions

View File

@@ -1,15 +1 @@
playerx=$0010 .alias curSpriteData curSpriteDataHi
playery=$0011
curSpriteData=$0012 ; 2 bytes
curSpriteDataLo=$0013
curSpriteDataHi=$0012
curSpriteLen=$0014
pad1a=$0015
pad1b=$0016
pad1select=$0017
pad1start=$0018
pad1up=$0019
pad1down=$001A
pad1left=$001B
pad1right=$001C
pad1areleased=$001D

123
nesgame.S
View File

@@ -3,17 +3,40 @@
;; how many 8kB banks of CHR data, which mapper to use for bank swapping ;; how many 8kB banks of CHR data, which mapper to use for bank swapping
;; and how to perform background mirroring ;; and how to perform background mirroring
.inesprg 1 ;; 1x 16kB bank of PRG (program) code ;; iNES header block
.ineschr 1 ;; 1x 8kB bank of CHR (tile/sprite) data
.inesmap 0 ;; use mapper 0; NROM, no bank swapping .byte "NES",$1A
.inesmir 1 ;; background mirroring (we don't care for now) .byte $01 ;; 1 PRG ROM page (how big is an ophis page?)
.byte $02 ;; 1 CHR (tile/sprite) ROM page (how big is a page?)
.byte $00 ; Horizontal mirroring
.byte $00 ; Mapper 0 (NROM, no bank switching)
.byte $00,$00,$00,$00 ; Reserved bytes
.byte $00,$00,$00,$00 ; Reserved bytes
.include "defines.S" .include "defines.S"
;; For NESASM, we need to tell it where each bank begins. .text zp ; zero page - this begins at $00
; all pointers should go here
;; $0000 - $000F is reserved for local variables/function args
.org $0010 ; $0010 - 002F reserved for pointers
.space curSpriteDataLo 1
.space curSpriteDataHi 1
.org $0030
.space curSpriteLen 1
.space playery 1
.space playerx 1
.space pad1a 1
.space pad1b 1
.space pad1select 1
.space pad1start 1
.space pad1up 1
.space pad1down 1
.space pad1left 1
.space pad1right 1
.space pad1areleased 1
.bank 0 .text
.org $C000 ;; PRG bank 1 has 8kB at 0x0C000 .org $C000 ;; PRG bank code starts at 0xC000
;; START will be called by the NES whenever the system boots ;; START will be called by the NES whenever the system boots
;; or when the reset button is pressed (think of _start in libc ) ;; or when the reset button is pressed (think of _start in libc )
@@ -171,48 +194,6 @@ _MAIN_LoadPaletteLoop:
STA playerx STA playerx
STA playery STA playery
_MAIN_loop: _MAIN_loop:
LDA #$01
STA $4016
LDA #$01
STA $4016 ; $4016 is the controller port, this tells both
;; controllers to latch their buttons and
;; make data available
LDA #$0
STA pad1areleased
LDA $4016
AND #%00000001
BNE _MAIN_loop_pad1a_finished
_MAIN_loop_pad1a_release:
PHA
LDA #pad1a
AND #%00000001
PLA
BNE _MAIN_loop_pad1a_finished
LDX #$1
STX pad1areleased
_MAIN_loop_pad1a_finished:
STA pad1a
LDA $4016
_MAIN_loop_pad1b_finished:
STA pad1b
LDA $4016
_MAIN_loop_pad1sel_finished:
STA pad1select
LDA $4016
_MAIN_loop_pad1start_finished:
STA pad1start
LDA $4016
_MAIN_loop_pad1up_finished:
STA pad1up
LDA $4016
_MAIN_loop_pad1down_finished:
STA pad1down
LDA $4016
_MAIN_loop_pad1left_finished:
STA pad1left
LDA $4016
_MAIN_loop_pad1right_finished:
STA pad1right
JMP _MAIN_loop ;; Loop forever JMP _MAIN_loop ;; Loop forever
NMI: NMI:
@@ -220,10 +201,6 @@ NMI:
LDY #$0 LDY #$0
LDA sprMario LDA sprMario
STA curSpriteLen STA curSpriteLen
LDA #LOW(sprMarioData) ; This stuff doesn't work at current
STA curSpriteDataLo ; ""
LDA #HIGH(sprMarioData) ; ""
STA curSpriteDataHi ; ""
_NMI_CopyMarioToOAM: _NMI_CopyMarioToOAM:
LDA playery ; set Y position LDA playery ; set Y position
CLC CLC
@@ -236,7 +213,7 @@ _NMI_CopyMarioToOAM:
LDA pad1a LDA pad1a
AND #%00000001 AND #%00000001
BNE _NMI_CopyMarioToOAM_padup BNE _NMI_CopyMarioToOAM_padup
LDA #$03 LDA sprMarioData, x
JMP _NMI_CopyMarioToOAM_paddone JMP _NMI_CopyMarioToOAM_paddone
_NMI_CopyMarioToOAM_padup: _NMI_CopyMarioToOAM_padup:
LDA sprMarioData, x ; set attributes LDA sprMarioData, x ; set attributes
@@ -266,38 +243,30 @@ _NMI_CopyMarioToOAM_paddone:
; 3-4 times as long. ; 3-4 times as long.
RTI ; just return RTI ; just return
.bank 1 ;; NESASM sees our 16kB code banks as pairs of
.org $E000 ;; 8kB code banks, so we have to declare each
;; 8kB half-bank separately, and split code
;; between them.
;; .. How to know when we have written enough
;; code? ..
palette: palette:
.db $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F .byte $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F
.db $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C .byte $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C
sprMario: sprMario:
.db $08 ; Total number of subsprites in this metasprite .byte $08 ; Total number of subsprites in this metasprite
sprMarioData: sprMarioData:
;; Y, Tile, Atr, X ;; Y, Tile, Atr, X
.db $00,$00,$00,$00 .byte $00,$00,$00,$00
.db $00,$01,$00,$08 .byte $00,$01,$00,$08
.db $08,$02,$00,$00 .byte $08,$02,$00,$00
.db $08,$03,$00,$08 .byte $08,$03,$00,$08
.db $10,$04,$00,$00 .byte $10,$04,$00,$00
.db $10,$05,$00,$08 .byte $10,$05,$00,$08
.db $18,$06,$00,$00 .byte $18,$06,$00,$00
.db $18,$07,$00,$08 .byte $18,$07,$00,$08
.bank 1 .advance $FFFA
.org $FFFA .word NMI ;; For Non-Maskable Interrupts, please jump to the location
.dw NMI ;; For Non-Maskable Interrupts, please jump to the location
;; of the NMI label ;; of the NMI label
.dw START ;; For the reset button or power-on, jump to the location .word START ;; For the reset button or power-on, jump to the location
;; of the START label ;; of the START label
.dw 0 ;; If we used an external IRQ vector, we would put it here .word 0 ;; If we used an external IRQ vector, we would put it here
;; --- graphics bank ;; --- graphics bank
.bank 2 ;; CHR bank 0 starts here for tile/sprite data
.org $0000 ;; CHR data is below PRG data in the memory .org $0000 ;; CHR data is below PRG data in the memory
.incbin "mario.chr" ; include 8kB of graphics from SMB1 .incbin "mario.chr" ; include 8kB of graphics from SMB1