mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2026-04-19 08:27:40 +00:00
nes: added road, tint demo; extra tools; embed.html fetch remote url
This commit is contained in:
+2
-2
@@ -26,10 +26,10 @@ Start:
|
||||
lda #$1c ; $1C = light blue color
|
||||
sta PPU_DATA ; $1C -> PPU data
|
||||
; activate PPU graphics
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
lda #MASK_COLOR
|
||||
sta PPU_MASK ; enable rendering
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
|
||||
|
||||
+2
-2
@@ -28,10 +28,10 @@ Start:
|
||||
sta PPU_SCROLL
|
||||
sta PPU_SCROLL ; PPU scroll = $0000
|
||||
; activate PPU graphics
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
lda #MASK_BG
|
||||
sta PPU_MASK ; enable rendering
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
|
||||
|
||||
+2
-2
@@ -30,10 +30,10 @@ Start:
|
||||
sta PPU_SCROLL
|
||||
sta PPU_SCROLL ; scroll = $0000
|
||||
; activate PPU graphics
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
lda #MASK_BG
|
||||
sta PPU_MASK ; enable rendering
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
|
||||
|
||||
+2
-2
@@ -34,10 +34,10 @@ Start:
|
||||
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
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ;endless loop
|
||||
|
||||
|
||||
+2
-2
@@ -29,10 +29,10 @@ Start:
|
||||
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
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ;endless loop
|
||||
|
||||
|
||||
@@ -287,6 +287,10 @@ void __fastcall__ nmi_set_callback(void (*callback)(void));
|
||||
#define MASK_BG 0x08
|
||||
#define MASK_EDGE_SPR 0x04
|
||||
#define MASK_EDGE_BG 0x02
|
||||
#define MASK_TINT_RED 0x20
|
||||
#define MASK_TINT_BLUE 0x40
|
||||
#define MASK_TINT_GREEN 0x80
|
||||
#define MASK_MONO 0x01
|
||||
|
||||
#define NAMETABLE_A 0x2000
|
||||
#define NAMETABLE_B 0x2400
|
||||
|
||||
@@ -12,8 +12,6 @@ extern const byte climbr_title_rle[];
|
||||
|
||||
// link title screen palette and RLE nametable
|
||||
//#link "climbr_title.s"
|
||||
|
||||
|
||||
void fade_in() {
|
||||
byte vb;
|
||||
for (vb=0; vb<=4; vb++) {
|
||||
|
||||
+67
-47
@@ -5,6 +5,8 @@
|
||||
|
||||
seg.u ZEROPAGE
|
||||
org $0
|
||||
|
||||
Ptr1 .word ; for temporary pointer storage
|
||||
|
||||
TrackFrac .byte ; fractional position along track
|
||||
Speed .byte ; speed of car
|
||||
@@ -24,9 +26,8 @@ ZOfs .byte ; counter to draw striped center line
|
||||
Weather .byte ; bitmask for weather
|
||||
Heading .word ; sky scroll pos.
|
||||
|
||||
XCenter = 128
|
||||
NumRoadSegments = 28
|
||||
|
||||
NumRoadScanlines = 112
|
||||
NumRoadSegments = 56
|
||||
; Preprocessing result: X positions for all track segments
|
||||
RoadX0 ds NumRoadSegments
|
||||
|
||||
@@ -43,7 +44,7 @@ InitialSpeed equ 10 ; starting speed
|
||||
|
||||
;;;;; NES CARTRIDGE HEADER
|
||||
|
||||
NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror
|
||||
NES_HEADER 0,2,1,1 ; mapper 0, 2 PRGs, 1 CHR, vert mirror
|
||||
|
||||
;;;;; START OF CODE
|
||||
|
||||
@@ -53,7 +54,6 @@ Start:
|
||||
jsr ClearRAM ; clear RAM
|
||||
jsr WaitSync ; wait for VSYNC (and PPU warmup)
|
||||
|
||||
jsr SetPalette ; set palette colors
|
||||
jsr FillVRAM ; set PPU video RAM
|
||||
|
||||
jsr RoadSetup
|
||||
@@ -63,10 +63,10 @@ Start:
|
||||
sta PPU_ADDR ; PPU addr = $0000
|
||||
sta PPU_SCROLL
|
||||
sta PPU_SCROLL ; scroll = $0000
|
||||
lda #MASK_BG|MASK_SPR|MASK_BG_CLIP
|
||||
sta PPU_MASK ; enable rendering (first!)
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
lda #MASK_BG|MASK_SPR
|
||||
sta PPU_MASK ; enable rendering
|
||||
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
@@ -249,43 +249,43 @@ GenTrack subroutine
|
||||
|
||||
; fill video RAM
|
||||
FillVRAM: subroutine
|
||||
txa
|
||||
ldy #$20
|
||||
sty PPU_ADDR
|
||||
sta PPU_ADDR
|
||||
ldy #$10
|
||||
PPU_SETADDR $2000
|
||||
lda #<RoadTables
|
||||
sta Ptr1
|
||||
lda #>RoadTables
|
||||
sta Ptr1+1
|
||||
ldx #8
|
||||
ldy #0
|
||||
.loop:
|
||||
lda (Ptr1),y
|
||||
sta PPU_DATA
|
||||
adc #7
|
||||
inx
|
||||
iny
|
||||
bne .loop
|
||||
dey
|
||||
inc Ptr1+1
|
||||
dex
|
||||
bne .loop
|
||||
rts
|
||||
|
||||
; set palette colors
|
||||
SetPalette: subroutine
|
||||
ldy #$00
|
||||
lda #$3f
|
||||
sta PPU_ADDR
|
||||
sty PPU_ADDR
|
||||
ldx #32
|
||||
PPU_SETADDR $3f00
|
||||
ldx #16
|
||||
.loop:
|
||||
lda Palette,y
|
||||
sta PPU_DATA
|
||||
iny
|
||||
dex
|
||||
dex
|
||||
bne .loop
|
||||
rts
|
||||
|
||||
; set sprite 0
|
||||
SetSprite0: subroutine
|
||||
sta $200 ;y
|
||||
lda #1 ;code
|
||||
sta $200 ;ypos
|
||||
lda #$00 ;code
|
||||
sta $201
|
||||
lda #0 ;flags
|
||||
lda #$20 ;flags
|
||||
sta $202
|
||||
lda #8 ;xpos
|
||||
lda #$fe ;xpos
|
||||
sta $203
|
||||
rts
|
||||
|
||||
@@ -314,18 +314,26 @@ SetSprite0: subroutine
|
||||
ENDM
|
||||
|
||||
NMIHandler: subroutine
|
||||
; save registers
|
||||
SAVE_REGS
|
||||
; setup sky scroll
|
||||
lda Heading+1
|
||||
sta PPU_SCROLL
|
||||
lda #0
|
||||
sta PPU_SCROLL
|
||||
; load sprites
|
||||
lda #112
|
||||
; cycle palette colors
|
||||
lda TPos ; track position
|
||||
lsr ; / 2
|
||||
and #16 ; now either 0 or 16
|
||||
tay ; Y is palette offset
|
||||
jsr SetPalette ; call SetPalette
|
||||
PPU_SETADDR $2000 ; reset PPU address
|
||||
; load sprite zero
|
||||
lda #109
|
||||
jsr SetSprite0
|
||||
lda #$02
|
||||
sta PPU_OAM_DMA
|
||||
; do road calc
|
||||
; setup sky scroll
|
||||
lda Heading+1
|
||||
sta PPU_SCROLL ; X scroll
|
||||
lda #0
|
||||
sta PPU_SCROLL ; Y scroll = 0
|
||||
; do road calculations
|
||||
jsr RoadPreSetup
|
||||
jsr PreprocessCurve
|
||||
jsr RoadPostFrame
|
||||
@@ -337,30 +345,42 @@ NMIHandler: subroutine
|
||||
; alter horiz. scroll position for each scanline
|
||||
ldy #0
|
||||
.loop
|
||||
; pad out rest of scanline
|
||||
SLEEP 78
|
||||
; change scroll register
|
||||
tya
|
||||
lsr
|
||||
lsr
|
||||
lsr ; / 2
|
||||
tax
|
||||
lda RoadX0,x
|
||||
lda RoadX0,x ; get X offset of scanline
|
||||
eor #$80 ; + 128
|
||||
sta PPU_SCROLL ; horiz byte
|
||||
lda #0
|
||||
sta PPU_SCROLL ; vert byte
|
||||
SLEEP 84
|
||||
sta PPU_SCROLL ; vert byte = 0
|
||||
; take extra cycle every 4th line
|
||||
tya
|
||||
and #3
|
||||
bne .skipcyc
|
||||
.skipcyc
|
||||
; next loop iteration
|
||||
iny
|
||||
cpy #112
|
||||
bne .loop
|
||||
cpy #NumRoadScanlines
|
||||
bne .loop ; do next scanline
|
||||
; restore registers and return from interrupt
|
||||
RESTORE_REGS
|
||||
rti
|
||||
|
||||
;;;;; CONSTANT DATA
|
||||
|
||||
align $100
|
||||
;;{pal:"nes",layout:"nes"};;
|
||||
Palette:
|
||||
hex 1f ;background
|
||||
hex 09092c00 ;bg0
|
||||
hex 09091900 ;bg1
|
||||
hex 09091500 ;bg2
|
||||
hex 09092500 ;bg3
|
||||
hex 0F3F06300F19063F0F1916063F180801
|
||||
hex 0F30163F0F19163F0F1906160F180801
|
||||
;;
|
||||
RoadTables:
|
||||
incbin "road/nametable.dat"
|
||||
incbin "road/attribute.dat"
|
||||
incbin "road/nametable1.dat"
|
||||
incbin "road/attribute1.dat"
|
||||
|
||||
;;;;; CPU VECTORS
|
||||
|
||||
@@ -369,4 +389,4 @@ Palette:
|
||||
;;;;; TILE SETS
|
||||
|
||||
org $10000
|
||||
incbin "jroatch.chr"
|
||||
incbin "road/road.chr"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,8 @@
|
||||
|
||||
seg.u ZEROPAGE
|
||||
org $0
|
||||
|
||||
SkipY ds 1
|
||||
|
||||
;;;;; OTHER VARIABLES
|
||||
|
||||
@@ -34,10 +36,10 @@ Start:
|
||||
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
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
|
||||
@@ -69,7 +71,7 @@ SetPalette: subroutine
|
||||
; set sprite 0
|
||||
SetSprite0: subroutine
|
||||
sta $200 ;y
|
||||
lda #$01 ;code
|
||||
lda #$a0 ;code
|
||||
sta $201
|
||||
lda #$20 ;flags
|
||||
sta $202
|
||||
@@ -100,6 +102,13 @@ NMIHandler: subroutine
|
||||
bvc .wait1
|
||||
ldy #0
|
||||
.loop
|
||||
; take out cycle every 4th line
|
||||
tya
|
||||
and #3
|
||||
bne .skipcyc ; clks = 2/3/3/3
|
||||
.skipcyc
|
||||
; pad out rest of scanline
|
||||
SLEEP 65
|
||||
; alter horiz. scroll position for each scanline
|
||||
tya
|
||||
sec
|
||||
@@ -111,10 +120,9 @@ NMIHandler: subroutine
|
||||
sta PPU_SCROLL ; horiz byte
|
||||
lda #0
|
||||
sta PPU_SCROLL ; vert byte
|
||||
; pad out rest of scanline
|
||||
SLEEP 72
|
||||
; next iteration of loop
|
||||
iny
|
||||
cpy #224
|
||||
cpy #112
|
||||
bne .loop
|
||||
RESTORE_REGS
|
||||
rti
|
||||
|
||||
@@ -1,16 +1,45 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// include NESLIB header
|
||||
#include "neslib.h"
|
||||
|
||||
// link the pattern table into CHR ROM
|
||||
//#link "chr_generic.s"
|
||||
|
||||
/*{pal:"nes",layout:"nes"}*/
|
||||
const char PALETTE[32] = {
|
||||
0x03, // screen color
|
||||
|
||||
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,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
|
||||
void setup_graphics() {
|
||||
// clear sprites
|
||||
oam_clear();
|
||||
// set palette colors
|
||||
pal_all(PALETTE);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
pal_col(1,0x04);
|
||||
pal_col(2,0x20);
|
||||
pal_col(3,0x30);
|
||||
setup_graphics();
|
||||
// draw message
|
||||
vram_adr(NTADR_A(2,2));
|
||||
vram_write("HELLO, WORLD!", 12);
|
||||
ppu_on_all();//enable rendering
|
||||
while(1);//do nothing, infinite loop
|
||||
// enable rendering
|
||||
ppu_on_all();
|
||||
// infinite loop
|
||||
while(1) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// include NESLIB header
|
||||
#include "neslib.h"
|
||||
|
||||
// link the pattern table into CHR ROM
|
||||
//#link "chr_generic.s"
|
||||
|
||||
/*{pal:"nes",layout:"nes"}*/
|
||||
const char PALETTE[32] = {
|
||||
0x2D, // screen color
|
||||
|
||||
0x00,0x30,0x30,0x00, // background palette 0
|
||||
0x0C,0x20,0x2C,0x00, // background palette 1
|
||||
0x14,0x10,0x25,0x00, // background palette 2
|
||||
0x17,0x16,0x28,0x00, // background palette 3
|
||||
|
||||
0x16,0x35,0x24,0x00, // sprite palette 0
|
||||
0x00,0x37,0x25,0x00, // sprite palette 1
|
||||
0x0D,0x2D,0x3A,0x00, // sprite palette 2
|
||||
0x0D,0x27,0x2A // sprite palette 3
|
||||
};
|
||||
|
||||
// setup PPU and tables
|
||||
void setup_graphics() {
|
||||
// clear sprites
|
||||
oam_clear();
|
||||
// set palette colors
|
||||
pal_all(PALETTE);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
byte i;
|
||||
setup_graphics();
|
||||
// draw message
|
||||
for (i=0; i<30; i++) {
|
||||
vram_adr(NTADR_A(1,i));
|
||||
// vram_write("\x18\x18 USE CONTROLLER FOR TINT \x18\x18\x18", 30);
|
||||
vram_write(" A:red B:green \x1e\x1f:blue \x1c\x1d:mono", 30);
|
||||
}
|
||||
// attributes
|
||||
vram_adr(0x23c0);
|
||||
vram_fill(0x00, 8);
|
||||
vram_fill(0x55, 8);
|
||||
vram_fill(0xaa, 8);
|
||||
vram_fill(0xff, 8);
|
||||
vram_fill(0x11, 8);
|
||||
vram_fill(0x33, 8);
|
||||
vram_fill(0xdd, 8);
|
||||
// enable rendering
|
||||
ppu_on_all();
|
||||
// infinite loop
|
||||
while(1) {
|
||||
byte pad = pad_poll(0);
|
||||
byte mask = MASK_BG;
|
||||
if (pad & PAD_A)
|
||||
mask |= MASK_TINT_RED;
|
||||
if (pad & PAD_B)
|
||||
mask |= MASK_TINT_GREEN;
|
||||
if (pad & (PAD_LEFT|PAD_RIGHT))
|
||||
mask |= MASK_TINT_BLUE;
|
||||
if (pad & (PAD_UP|PAD_DOWN))
|
||||
mask |= MASK_MONO;
|
||||
ppu_mask(mask);
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -34,10 +34,10 @@ Start:
|
||||
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
|
||||
lda #CTRL_NMI
|
||||
sta PPU_CTRL ; enable NMI
|
||||
.endless
|
||||
jmp .endless ; endless loop
|
||||
|
||||
@@ -93,26 +93,26 @@ NMIHandler: subroutine
|
||||
; 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
|
||||
; compute second PPU_ADDR write
|
||||
lda ScrollX
|
||||
tax
|
||||
tax ; ScrollX -> X
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
sta Temp
|
||||
lda ScrollY
|
||||
tay
|
||||
and #$f8
|
||||
tay ; ScrollY -> Y
|
||||
and #$38
|
||||
asl
|
||||
asl
|
||||
ora Temp
|
||||
pha
|
||||
ora Temp ; (ScrollX >> 3) | ((ScrollY & 0x38) << 2)
|
||||
pha ; push onto stack
|
||||
; wait for sprite 0
|
||||
.wait0 bit PPU_STATUS
|
||||
bvs .wait0
|
||||
.wait1 bit PPU_STATUS
|
||||
bvc .wait1
|
||||
; set PPU_ADDR.1
|
||||
lda #0
|
||||
sta PPU_ADDR
|
||||
|
||||
Reference in New Issue
Block a user