mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-18 00:30:43 +00:00
nes: controller demo
This commit is contained in:
parent
6919e1eaf6
commit
566bbdca94
@ -96,6 +96,7 @@ TODO:
|
|||||||
- show .map file in listings?
|
- show .map file in listings?
|
||||||
- open ROM from URL?
|
- open ROM from URL?
|
||||||
- #include can't have comment immediately on line before
|
- #include can't have comment immediately on line before
|
||||||
|
- NES: breakpoint on illegal instruction
|
||||||
|
|
||||||
|
|
||||||
WEB WORKER FORMAT
|
WEB WORKER FORMAT
|
||||||
|
128
presets/nes/ex4.asm
Normal file
128
presets/nes/ex4.asm
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
include "nesdefs.asm"
|
||||||
|
|
||||||
|
;;;;; VARIABLES
|
||||||
|
|
||||||
|
seg.u RAM
|
||||||
|
org $0
|
||||||
|
|
||||||
|
ScrollX byte ; used during NMI
|
||||||
|
ScrollY byte ; used during NMI
|
||||||
|
|
||||||
|
;;;;; NES CARTRIDGE HEADER
|
||||||
|
|
||||||
|
NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror
|
||||||
|
|
||||||
|
;;;;; START OF CODE
|
||||||
|
|
||||||
|
Start:
|
||||||
|
NES_INIT ; set up stack pointer, turn off PPU
|
||||||
|
jsr WaitSync
|
||||||
|
jsr WaitSync
|
||||||
|
jsr ClearRAM
|
||||||
|
jsr WaitSync ;wait for VSYNC
|
||||||
|
jsr SetPalette ;set colors
|
||||||
|
jsr FillVRAM ;set PPU RAM
|
||||||
|
jsr WaitSync ;wait for VSYNC (and PPU warmup)
|
||||||
|
lda #0
|
||||||
|
sta PPU_ADDR
|
||||||
|
sta PPU_ADDR ;PPU addr = 0
|
||||||
|
sta PPU_SCROLL
|
||||||
|
sta PPU_SCROLL ;scroll = 0
|
||||||
|
lda #CTRL_NMI
|
||||||
|
sta PPU_CTRL ; enable NMI
|
||||||
|
lda #MASK_BG|MASK_SPR
|
||||||
|
sta PPU_MASK ; enable rendering
|
||||||
|
.endless
|
||||||
|
jmp .endless ;endless loop
|
||||||
|
|
||||||
|
; fill video RAM
|
||||||
|
FillVRAM: subroutine
|
||||||
|
txa
|
||||||
|
ldy #$20
|
||||||
|
sty PPU_ADDR
|
||||||
|
sta PPU_ADDR
|
||||||
|
ldy #$10
|
||||||
|
.loop:
|
||||||
|
stx PPU_DATA
|
||||||
|
inx
|
||||||
|
bne .loop
|
||||||
|
dey
|
||||||
|
bne .loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
; set palette colors
|
||||||
|
|
||||||
|
SetPalette: subroutine
|
||||||
|
ldy #$00
|
||||||
|
lda #$3f
|
||||||
|
sta PPU_ADDR
|
||||||
|
sty PPU_ADDR
|
||||||
|
ldx #32
|
||||||
|
.loop:
|
||||||
|
lda Palette,y
|
||||||
|
sta PPU_DATA
|
||||||
|
iny
|
||||||
|
dex
|
||||||
|
bne .loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
;;;;; COMMON SUBROUTINES
|
||||||
|
|
||||||
|
include "nesppu.asm"
|
||||||
|
|
||||||
|
;;;;; INTERRUPT HANDLERS
|
||||||
|
|
||||||
|
NMIHandler:
|
||||||
|
SAVE_REGS
|
||||||
|
; update scroll position (must be done after VRAM updates)
|
||||||
|
jsr ReadJoypad
|
||||||
|
pha
|
||||||
|
and #$03
|
||||||
|
tay
|
||||||
|
lda ScrollDirTab,y
|
||||||
|
clc
|
||||||
|
adc ScrollX
|
||||||
|
sta ScrollX
|
||||||
|
sta PPU_SCROLL
|
||||||
|
pla
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
and #$03
|
||||||
|
tay
|
||||||
|
lda ScrollDirTab,y
|
||||||
|
clc
|
||||||
|
adc ScrollY
|
||||||
|
sta ScrollY
|
||||||
|
sta PPU_SCROLL
|
||||||
|
; reload registers
|
||||||
|
RESTORE_REGS
|
||||||
|
rti
|
||||||
|
|
||||||
|
; Scroll direction lookup table
|
||||||
|
ScrollDirTab:
|
||||||
|
hex 00 01 ff 00
|
||||||
|
|
||||||
|
;;;;; CONSTANT DATA
|
||||||
|
|
||||||
|
align $100
|
||||||
|
Palette:
|
||||||
|
hex 1f ;background
|
||||||
|
hex 09090000 ;bg0
|
||||||
|
hex 09090c00 ;bg1
|
||||||
|
hex 09091c00 ;bg2
|
||||||
|
hex 09092c00 ;bg3
|
||||||
|
hex 14243400 ;sp0
|
||||||
|
hex 15253500 ;sp1
|
||||||
|
hex 16263600 ;sp2
|
||||||
|
hex 17273700 ;sp3
|
||||||
|
|
||||||
|
;;;;; CPU VECTORS
|
||||||
|
|
||||||
|
NES_VECTORS
|
||||||
|
|
||||||
|
;;;;; TILE SETS
|
||||||
|
|
||||||
|
org $10000
|
||||||
|
incbin "jroatch.chr"
|
@ -13,6 +13,7 @@ const JSNES_PRESETS = [
|
|||||||
{id:'ex1.asm', name:'Hello World (ASM)'},
|
{id:'ex1.asm', name:'Hello World (ASM)'},
|
||||||
{id:'ex2.asm', name:'Scrolling Demo (ASM)'},
|
{id:'ex2.asm', name:'Scrolling Demo (ASM)'},
|
||||||
{id:'ex3.asm', name:'Sprite Demo (ASM)'},
|
{id:'ex3.asm', name:'Sprite Demo (ASM)'},
|
||||||
|
{id:'ex4.asm', name:'Controller Demo (ASM)'},
|
||||||
{id:'neslib1.c', name:'Text'},
|
{id:'neslib1.c', name:'Text'},
|
||||||
{id:'neslib2.c', name:'Sprites'},
|
{id:'neslib2.c', name:'Sprites'},
|
||||||
{id:'neslib3.c', name:'Cursor'},
|
{id:'neslib3.c', name:'Cursor'},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user