1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-07 17:29:31 +00:00

NES presets; neslib .o w/ splitxy()

This commit is contained in:
Steven Hugg 2019-04-18 14:52:59 -04:00
parent dcd07a1440
commit 645815155b
7 changed files with 168 additions and 18 deletions

View File

@ -60,17 +60,17 @@ const unsigned char* const playerRunSeq[16] = {
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
0x03, // background color
0x03, // screen color
0x25,0x30,0x27,0x00, // ladders and pickups
0x1C,0x20,0x2C,0x00, // floor blocks
0x00,0x10,0x20,0x00,
0x06,0x16,0x26,0x00,
0x11,0x30,0x27,0x0, // background palette 0
0x1c,0x20,0x2c,0x0, // background palette 1
0x00,0x10,0x20,0x0, // background palette 2
0x06,0x16,0x26,0x0, // background palette 3
0x16,0x35,0x24,0x00, // enemy sprites
0x00,0x37,0x25,0x00, // rescue person
0x0D,0x2D,0x1A,0x00,
0x0D,0x27,0x2A // player sprites
0x16,0x35,0x24,0x0, // sprite palette 0
0x00,0x37,0x25,0x0, // sprite palette 1
0x0d,0x2d,0x3a,0x0, // sprite palette 2
0x0d,0x27,0x2a // sprite palette 3
};
// setup PPU and tables

View File

@ -172,6 +172,11 @@ void __fastcall__ scroll(unsigned int x, unsigned int y);
// warning: only X scroll could be changed in this version
void __fastcall__ split(unsigned int x, unsigned int y);
// set scroll after screen split invoked by the sprite 0 hit
// sets both X and Y, but timing might be iffy depending
// on exact sprite 0 position
void __fastcall__ splitxy(unsigned int x, unsigned int y);
// select current chr bank for sprites, 0..1
void __fastcall__ bank_spr(unsigned char n);

View File

@ -43,10 +43,7 @@ Start:
; fill video RAM
FillVRAM: subroutine
txa
ldy #$20
sty PPU_ADDR
sta PPU_ADDR
PPU_SETADDR $2000
ldy #$10
.loop:
sta PPU_DATA
@ -59,10 +56,7 @@ FillVRAM: subroutine
; set palette colors
SetPalette: subroutine
ldy #$00
lda #$3f
sta PPU_ADDR
sty PPU_ADDR
PPU_SETADDR $3f00
ldx #32
.loop:
lda Palette,y

150
presets/nes/xyscroll.asm Normal file
View File

@ -0,0 +1,150 @@
include "nesdefs.asm"
;;;;; ZERO-PAGE VARIABLES
seg.u ZEROPAGE
org $0
ScrollX ds 1
ScrollY ds 1
Temp ds 1
;;;;; OTHER VARIABLES
seg.u RAM
org $300
;;;;; 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 ; wait for VSYNC
jsr ClearRAM ; clear RAM
jsr WaitSync ; wait for VSYNC (and PPU warmup)
jsr SetPalette ; set palette colors
jsr FillVRAM ; set PPU video RAM
lda #0
sta PPU_ADDR
sta PPU_ADDR ; PPU addr = $0000
sta PPU_SCROLL
sta PPU_SCROLL ; scroll = $0000
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
PPU_SETADDR $2000
ldy #$10
.loop:
sta PPU_DATA
adc #7
inx
bne .loop
dey
bne .loop
rts
; set palette colors
SetPalette: subroutine
PPU_SETADDR $3f00
ldx #32
.loop:
lda Palette,y
sta PPU_DATA
iny
dex
bne .loop
rts
; set sprite 0
SetSprite0: subroutine
sta $200 ;y
lda #$01 ;code
sta $201
lda #$20 ;flags
sta $202
lda #$fe ;xpos
sta $203
rts
;;;;; COMMON SUBROUTINES
include "nesppu.asm"
;;;;; INTERRUPT HANDLERS
NMIHandler: subroutine
SAVE_REGS
lda #0
sta PPU_SCROLL
sta PPU_SCROLL
lda #111
jsr SetSprite0
; load sprites
lda #$02
sta PPU_OAM_DMA
; wait for sprite 0
.wait0 bit PPU_STATUS
bvs .wait0
.wait1 bit PPU_STATUS
bvc .wait1
; set XY scroll
; compute first PPU_ADDR write
lda ScrollX
tax
lsr
lsr
lsr
sta Temp
lda ScrollY
tay
and #$f8
asl
asl
ora Temp
pha
; set PPU_ADDR.1
lda #0
sta PPU_ADDR
; set PPU_SCROLL.1
sty PPU_SCROLL
; set PPU_SCROLL.2
stx PPU_SCROLL
; set PPU_ADDR.2
pla
sta PPU_ADDR
; modify scroll positions
inc ScrollX
inc ScrollY
; restore registers and return
RESTORE_REGS
rti
;;;;; CONSTANT DATA
align $100
Palette:
hex 1f ;background
hex 09092c00 ;bg0
hex 09091900 ;bg1
hex 09091500 ;bg2
hex 09092500 ;bg3
;;;;; CPU VECTORS
NES_VECTORS
;;;;; TILE SETS
org $10000
incbin "jroatch.chr"

View File

@ -36,6 +36,7 @@ const JSNES_PRESETS = [
{id:'bankswitch.c', name:'Bank Switching'},
{id:'irq.c', name:'IRQ Scanline Counter'},
{id:'scrollrt.asm', name:'Line-by-line Scrolling (ASM)'},
{id:'xyscroll.asm', name:'XY Split Scrolling (ASM)'},
];
/// JSNES

Binary file not shown.

2
tss

@ -1 +1 @@
Subproject commit 5b5ee67fc06956bc7dce51726e98812d2d897eaa
Subproject commit 61a1691a1de05dca3b694bf603db49ffbaf572cf