From 070a67a9176eed3de7a4ad7234eacc81591a494c Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 13 May 2019 18:36:25 -0400 Subject: [PATCH] nes: updates --- doc/notes.txt | 3 +-- presets/nes/climber.c | 26 +++++++++++--------------- presets/nes/road.dasm | 35 +++++++++++++++++++---------------- presets/nes/scrollrt.dasm | 29 ++++++++++++++++------------- src/platform/nes.ts | 2 +- src/services.ts | 6 ++++-- 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index 1754edd8..4ab7d2e4 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -138,6 +138,7 @@ TODO: - target ES6 - don't have to include bootstrap-tourist each time? - don't have to include firebase always? +- build ca65 projects w/ no crt0? https://github.com/pinobatch/thwaite-nes/blob/master/makefile - Github - gh-pages branch with embedded - handle overwrite logic @@ -152,8 +153,6 @@ TODO: - don't import useless files - support projects with subdirectories, file list? - emulator needs reset shortcut for nes - - local/ files in repository? - - build ca65 projects w/ no crt0? https://github.com/pinobatch/thwaite-nes/blob/master/makefile - switching platform of a repo? diff --git a/presets/nes/climber.c b/presets/nes/climber.c index 57977add..c8461bcc 100644 --- a/presets/nes/climber.c +++ b/presets/nes/climber.c @@ -369,12 +369,8 @@ typedef struct Actor { int pal:2; // palette color (2 bits) int dir:1; // direction (0=right, 1=left) int onscreen:1; // is actor onscreen? - union { - struct { // when jumping... - sbyte yvel; // Y velocity - sbyte xvel; // X velocity - } jumping; - } u; + sbyte yvel; // Y velocity (when jumping) + sbyte xvel; // X velocity (when jumping) } Actor; Actor actors[MAX_ACTORS]; @@ -509,8 +505,8 @@ void check_scroll_down() { void fall_down(struct Actor* actor) { actor->floor--; actor->state = FALLING; - actor->u.jumping.xvel = 0; - actor->u.jumping.yvel = 0; + actor->xvel = 0; + actor->yvel = 0; } void move_actor(struct Actor* actor, byte joystick, bool scroll) { @@ -521,10 +517,10 @@ void move_actor(struct Actor* actor, byte joystick, bool scroll) { // left/right has priority over climbing if (joystick & PAD_A) { actor->state = JUMPING; - actor->u.jumping.xvel = 0; - actor->u.jumping.yvel = JUMP_VELOCITY; - if (joystick & PAD_LEFT) actor->u.jumping.xvel = -1; - if (joystick & PAD_RIGHT) actor->u.jumping.xvel = 1; + actor->xvel = 0; + actor->yvel = JUMP_VELOCITY; + if (joystick & PAD_LEFT) actor->xvel = -1; + if (joystick & PAD_RIGHT) actor->xvel = 1; // play sound for player if (scroll) sfx_play(SND_JUMP,0); } else if (joystick & PAD_LEFT) { @@ -575,9 +571,9 @@ void move_actor(struct Actor* actor, byte joystick, bool scroll) { check_scroll_down(); } case JUMPING: - actor->x += actor->u.jumping.xvel; - actor->yy += actor->u.jumping.yvel/4; - actor->u.jumping.yvel -= 1; + actor->x += actor->xvel; + actor->yy += actor->yvel/4; + actor->yvel -= 1; if (actor->yy <= get_floor_yy(actor->floor)) { actor->yy = get_floor_yy(actor->floor); actor->state = STANDING; diff --git a/presets/nes/road.dasm b/presets/nes/road.dasm index 5fa9258c..7ea24436 100644 --- a/presets/nes/road.dasm +++ b/presets/nes/road.dasm @@ -278,7 +278,7 @@ SetPalette: subroutine bne .loop rts -; set sprite 0 +; set sprite 0 (A = top scanline) SetSprite0: subroutine sta $200 ;ypos lda #$00 ;code @@ -313,6 +313,10 @@ SetSprite0: subroutine REPEND ENDM +;;; +;;; NMI HANDLER +;;; + NMIHandler: subroutine ; save registers SAVE_REGS @@ -325,11 +329,11 @@ NMIHandler: subroutine PPU_SETADDR $2000 ; reset PPU address ; load sprite zero lda #109 - jsr SetSprite0 + jsr SetSprite0 ; set sprite 0 position lda #$02 - sta PPU_OAM_DMA + sta PPU_OAM_DMA ; send sprites to PPU ; setup sky scroll - lda Heading+1 + lda Heading+1 ; heading scroll pos. sta PPU_SCROLL ; X scroll lda #0 sta PPU_SCROLL ; Y scroll = 0 @@ -339,27 +343,26 @@ NMIHandler: subroutine jsr RoadPostFrame ; wait for sprite 0 .wait0 bit PPU_STATUS - bvs .wait0 + bvs .wait0 ; until bit 6 set .wait1 bit PPU_STATUS - bvc .wait1 + bvc .wait1 ; until bit 6 clear ; alter horiz. scroll position for each scanline ldy #0 .loop ; pad out rest of scanline - SLEEP 78 + SLEEP 80 ; change scroll register - tya - lsr ; / 2 - tax + tya ; Y -> A + lsr ; A / 2 + tax ; A -> X lda RoadX0,x ; get X offset of scanline eor #$80 ; + 128 sta PPU_SCROLL ; horiz byte - lda #0 - sta PPU_SCROLL ; vert byte = 0 -; take extra cycle every 4th line - tya - and #3 - bne .skipcyc + sta PPU_SCROLL ; vert byte (ignored) +; take back 1 cycle every 4th line + tya ; Y -> A + and #3 ; mask first 2 bits + bne .skipcyc ; -1 cycle every 4 lines .skipcyc ; next loop iteration iny diff --git a/presets/nes/scrollrt.dasm b/presets/nes/scrollrt.dasm index e3924d82..60659585 100644 --- a/presets/nes/scrollrt.dasm +++ b/presets/nes/scrollrt.dasm @@ -6,8 +6,6 @@ seg.u ZEROPAGE org $0 -SkipY ds 1 - ;;;;; OTHER VARIABLES seg.u RAM @@ -97,21 +95,21 @@ NMIHandler: subroutine sta PPU_OAM_DMA ; wait for sprite 0 .wait0 bit PPU_STATUS - bvs .wait0 + bvs .wait0 ; until bit 6 set .wait1 bit PPU_STATUS - bvc .wait1 + bvc .wait1 ; until bit 6 clear + SLEEP 14 ldy #0 .loop -; take out cycle every 4th line - tya - and #3 - bne .skipcyc ; clks = 2/3/3/3 +; add two cycles every 6th line + lda Div3Table,y ; is non-zero? + bne .skipcyc ; branch adds +1 cycle .skipcyc ; pad out rest of scanline - SLEEP 65 + SLEEP 66 ; alter horiz. scroll position for each scanline tya - sec + clc adc LineXLo,y sta LineXLo,y lda LineXHi,y @@ -122,14 +120,19 @@ NMIHandler: subroutine sta PPU_SCROLL ; vert byte ; next iteration of loop iny - cpy #112 - bne .loop + cpy #112 ; out of lines? + bne .loop ; no, repeat RESTORE_REGS rti ;;;;; CONSTANT DATA - align $100 + align $100 ; align to page boundary +Div3Table: + REPEAT 38 ; repeat 3*38 times + .byte 0,1,1 ; repeating 0-1-1 bytes + REPEND ; end of repeat block + Palette: hex 1f ;background hex 09092c00 ;bg0 diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 34cd5416..21c6d48d 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -36,7 +36,7 @@ const JSNES_PRESETS = [ {id:'ex4.dasm', name:'Controller Demo (ASM)'}, {id:'musicdemo.dasm', name:'Famitone Demo (ASM)'}, {id:'xyscroll.dasm', name:'XY Split Scrolling (ASM)'}, - {id:'scrollrt.dasm', name:'Line-by-line Scrolling (ASM)'}, +// {id:'scrollrt.dasm', name:'Line-by-line Scrolling (ASM)'}, {id:'road.dasm', name:'3-D Road Demo (ASM)'}, {id:'chase/game.c', name:'Shiru\'s Chase Game'}, ]; diff --git a/src/services.ts b/src/services.ts index 568326a9..80df2524 100644 --- a/src/services.ts +++ b/src/services.ts @@ -234,6 +234,8 @@ export class GithubService { publish(reponame:string, desc:string, license:string, isprivate:boolean) : Promise { var repo; + var platform_id = this.project.platform_id; + var mainPath = this.project.stripLocalPath(this.project.mainPath); return this.github.user.repos.create({ name: reponame, description: desc, @@ -246,9 +248,9 @@ export class GithubService { // create README.md var s = README_md_template; s = s.replace(/\$NAME/g, encodeURIComponent(reponame)); - s = s.replace(/\$PLATFORM/g, encodeURIComponent(this.project.platform_id)); + s = s.replace(/\$PLATFORM/g, encodeURIComponent(platform_id)); s = s.replace(/\$GITHUBURL/g, encodeURIComponent(repo.html_url)); - s = s.replace(/\$MAINFILE/g, encodeURIComponent(this.project.stripLocalPath(this.project.mainPath))); + s = s.replace(/\$MAINFILE/g, encodeURIComponent(mainPath)); var config = { message: '8bitworkshop: updated metadata in README.md', content: btoa(s)