diff --git a/doc/notes.txt b/doc/notes.txt index 8511be5e..84f3b511 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -95,7 +95,6 @@ TODO: - show .map file in listings? memory map view? - open ROM from URL? - NES: disassembly not aligned on PC -- NES: listing for .s files WEB WORKER FORMAT diff --git a/presets/nes/jroatch.s b/presets/nes/chr_generic.s similarity index 100% rename from presets/nes/jroatch.s rename to presets/nes/chr_generic.s diff --git a/presets/nes/climber.c b/presets/nes/climber.c index 24a4c71b..52c757c0 100644 --- a/presets/nes/climber.c +++ b/presets/nes/climber.c @@ -3,25 +3,20 @@ #include // include NESLIB header - #include "neslib.h" // include CC65 NES Header (PPU) - #include +// link the pattern table into CHR ROM +//#link "chr_generic.s" + // define basic types typedef unsigned char byte; typedef signed char sbyte; typedef unsigned short word; typedef enum { false, true } bool; -///// PATTERN TABLE - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr - ///// DEFINES #define COLS 30 // floor width in tiles @@ -766,9 +761,7 @@ const char PALETTE[32] = { void setup_graphics() { ppu_off(); - oam_hide_rest(0); - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); + oam_clear(); pal_all(PALETTE); vram_adr(0x2000); vram_fill(CH_BLANK, 0x1000); diff --git a/presets/nes/crypto.c b/presets/nes/crypto.c index 577b3add..d28b57a0 100644 --- a/presets/nes/crypto.c +++ b/presets/nes/crypto.c @@ -1,12 +1,20 @@ #include "neslib.h" +#pragma data-name (push,"CHARS") +#pragma data-name (pop) + //#define DEBUG #define HAS_DEBUGGER #define PLAYER_1 0 #define PLAYER_2 1 +void sfx_play(char a, char b) { + a=a; + b=b; +} + static const unsigned char palette[]={ 0xD, 0x00, 0x3D, 0x3c, 0xD, 0x09, 0x1B, 0x3c, @@ -34,6 +42,8 @@ static const unsigned char paused_palette[]={ #pragma bss-name(push,"ZEROPAGE") #pragma data-name(push,"ZEROPAGE") +unsigned char oam_off; + static unsigned char i, j; static unsigned char player_dir[2]; @@ -2823,7 +2833,7 @@ void __fastcall__ reset(void){ void main(void){ init(); - music_play(0); +// music_play(0); oam_clear(); while(1){ diff --git a/presets/nes/ex0.asm b/presets/nes/ex0.asm index 09f6d651..071c9e6c 100644 --- a/presets/nes/ex0.asm +++ b/presets/nes/ex0.asm @@ -8,7 +8,7 @@ ;;;;; NES CARTRIDGE HEADER - NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, vertical + NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror ;;;;; START OF CODE diff --git a/presets/nes/ex1.asm b/presets/nes/ex1.asm index ced63e84..9cc9bbf7 100644 --- a/presets/nes/ex1.asm +++ b/presets/nes/ex1.asm @@ -46,7 +46,7 @@ HelloVRAM: subroutine bne .loop ; loop .end rts ; return to caller - +3 ; ASCII message to display on screen HelloMsg: .byte "Hello, World!" diff --git a/presets/nes/ex3.asm b/presets/nes/ex3.asm index 49c69da7..eeebaad8 100644 --- a/presets/nes/ex3.asm +++ b/presets/nes/ex3.asm @@ -6,11 +6,8 @@ seg.u RAM org $0 -ScrollPos byte ; used during NMI -Rand byte -Temp1 byte - -SpriteBuf equ $200 +ScrollX byte ; used during NMI +ScrollY byte ; used during NMI ;;;;; NES CARTRIDGE HEADER @@ -27,7 +24,6 @@ Start: jsr SetPalette ;set colors jsr FillVRAM ;set PPU RAM jsr WaitSync ;wait for VSYNC (and PPU warmup) - jsr InitSprites lda #0 sta PPU_ADDR sta PPU_ADDR ;PPU addr = 0 @@ -55,33 +51,6 @@ FillVRAM: subroutine bne .loop rts -; -InitSprites: subroutine - lda #1 - ldx #0 -.loop - sta SpriteBuf,x - jsr NextRandom - inx - bne .loop - rts - -; -MoveSprites: subroutine - lda #1 - ldx #0 -.loop - sta Temp1 - and #3 - clc - adc SpriteBuf,x - sta SpriteBuf,x - lda Temp1 - jsr NextRandom - inx - bne .loop - rts - ; set palette colors SetPalette: subroutine @@ -107,21 +76,34 @@ SetPalette: subroutine NMIHandler: SAVE_REGS -; load sprites - lda #$02 - sta PPU_OAM_DMA ; update scroll position (must be done after VRAM updates) - inc ScrollPos - lda ScrollPos + jsr ReadJoypad + pha + and #$03 + tay + lda ScrollDirTab,y + clc + adc ScrollX + sta ScrollX sta PPU_SCROLL - lda #0 + pla + lsr + lsr + and #$03 + tay + lda ScrollDirTab,y + clc + adc ScrollY + sta ScrollY sta PPU_SCROLL -; move sprites - jsr MoveSprites ; reload registers RESTORE_REGS rti +; Scroll direction lookup table +ScrollDirTab: + hex 00 01 ff 00 + ;;;;; CONSTANT DATA align $100 diff --git a/presets/nes/fami.c b/presets/nes/fami.c index f7e2654f..96de1caf 100644 --- a/presets/nes/fami.c +++ b/presets/nes/fami.c @@ -1,9 +1,8 @@ #include "neslib.h" -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define TILESET jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" //#link "famitone2.s" void __fastcall__ famitone_update(void); @@ -16,9 +15,6 @@ extern char demo_sounds[]; void main(void) { - //copy tileset to RAM - vram_adr(0x0); - vram_write((unsigned char*)TILESET, sizeof(TILESET)); pal_col(1,0x04); pal_col(2,0x20); pal_col(3,0x30); diff --git a/presets/nes/famitone2.asm b/presets/nes/famitone2.asm index 0d731b4a..cece79a1 100644 --- a/presets/nes/famitone2.asm +++ b/presets/nes/famitone2.asm @@ -1,1242 +1,1242 @@ -;FamiTone2 v1.12 - -;settings, uncomment or put them into your main program; the latter makes possible updates easier - -; FT_BASE_ADR = $0300 ;page in the RAM used for FT2 variables, should be $xx00 -; FT_TEMP = $00 ;3 bytes in zeropage used by the library as a scratchpad -; FT_DPCM_OFF = $c000 ;$c000..$ffc0, 64-byte steps -; FT_SFX_STREAMS = 4 ;number of sound effects played at once, 1..4 - -; FT_DPCM_ENABLE ;undefine to exclude all DMC code -; FT_SFX_ENABLE ;undefine to exclude all sound effects code -; FT_THREAD ;undefine if you are calling sound effects from the same thread as the sound update call - -; FT_PAL_SUPPORT ;undefine to exclude PAL support -; FT_NTSC_SUPPORT ;undefine to exclude NTSC support - - - -;internal defines - - IFCONST FT_PAL_SUPPORT - IFCONST FT_NTSC_SUPPORT -FT_PITCH_FIX equ 1 ;add PAL/NTSC pitch correction code only when both modes are enabled - ENDIF - ENDIF - -FT_DPCM_PTR = (FT_DPCM_OFF&$3fff)>>6 - - -;zero page variables - -FT_TEMP_PTR = FT_TEMP ;word -FT_TEMP_PTR_L = FT_TEMP_PTR+0 -FT_TEMP_PTR_H = FT_TEMP_PTR+1 -FT_TEMP_VAR1 = FT_TEMP+2 -FT_TEMP_SIZE = 3 - -;envelope structure offsets, 5 bytes per envelope, grouped by variable type - -FT_ENVELOPES_ALL = 3+3+3+2 ;3 for the pulse and triangle channels, 2 for the noise channel -FT_ENV_STRUCT_SIZE = 5 - -FT_ENV_VALUE = FT_BASE_ADR+0*FT_ENVELOPES_ALL -FT_ENV_REPEAT = FT_BASE_ADR+1*FT_ENVELOPES_ALL -FT_ENV_ADR_L = FT_BASE_ADR+2*FT_ENVELOPES_ALL -FT_ENV_ADR_H = FT_BASE_ADR+3*FT_ENVELOPES_ALL -FT_ENV_PTR = FT_BASE_ADR+4*FT_ENVELOPES_ALL - - -;channel structure offsets, 7 bytes per channel - -FT_CHANNELS_ALL = 5 -FT_CHN_STRUCT_SIZE = 9 - -FT_CHN_PTR_L = FT_BASE_ADR+0*FT_CHANNELS_ALL -FT_CHN_PTR_H = FT_BASE_ADR+1*FT_CHANNELS_ALL -FT_CHN_NOTE = FT_BASE_ADR+2*FT_CHANNELS_ALL -FT_CHN_INSTRUMENT = FT_BASE_ADR+3*FT_CHANNELS_ALL -FT_CHN_REPEAT = FT_BASE_ADR+4*FT_CHANNELS_ALL -FT_CHN_RETURN_L = FT_BASE_ADR+5*FT_CHANNELS_ALL -FT_CHN_RETURN_H = FT_BASE_ADR+6*FT_CHANNELS_ALL -FT_CHN_REF_LEN = FT_BASE_ADR+7*FT_CHANNELS_ALL -FT_CHN_DUTY = FT_BASE_ADR+8*FT_CHANNELS_ALL - - -;variables and aliases - -FT_ENVELOPES = FT_BASE_ADR -FT_CH1_ENVS = FT_ENVELOPES+0 -FT_CH2_ENVS = FT_ENVELOPES+3 -FT_CH3_ENVS = FT_ENVELOPES+6 -FT_CH4_ENVS = FT_ENVELOPES+9 - -FT_CHANNELS = FT_ENVELOPES+FT_ENVELOPES_ALL*FT_ENV_STRUCT_SIZE -FT_CH1_VARS = FT_CHANNELS+0 -FT_CH2_VARS = FT_CHANNELS+1 -FT_CH3_VARS = FT_CHANNELS+2 -FT_CH4_VARS = FT_CHANNELS+3 -FT_CH5_VARS = FT_CHANNELS+4 - - -FT_CH1_NOTE = FT_CH1_VARS+<(FT_CHN_NOTE) -FT_CH2_NOTE = FT_CH2_VARS+<(FT_CHN_NOTE) -FT_CH3_NOTE = FT_CH3_VARS+<(FT_CHN_NOTE) -FT_CH4_NOTE = FT_CH4_VARS+<(FT_CHN_NOTE) -FT_CH5_NOTE = FT_CH5_VARS+<(FT_CHN_NOTE) - -FT_CH1_INSTRUMENT = FT_CH1_VARS+<(FT_CHN_INSTRUMENT) -FT_CH2_INSTRUMENT = FT_CH2_VARS+<(FT_CHN_INSTRUMENT) -FT_CH3_INSTRUMENT = FT_CH3_VARS+<(FT_CHN_INSTRUMENT) -FT_CH4_INSTRUMENT = FT_CH4_VARS+<(FT_CHN_INSTRUMENT) -FT_CH5_INSTRUMENT = FT_CH5_VARS+<(FT_CHN_INSTRUMENT) - -FT_CH1_DUTY = FT_CH1_VARS+<(FT_CHN_DUTY) -FT_CH2_DUTY = FT_CH2_VARS+<(FT_CHN_DUTY) -FT_CH3_DUTY = FT_CH3_VARS+<(FT_CHN_DUTY) -FT_CH4_DUTY = FT_CH4_VARS+<(FT_CHN_DUTY) -FT_CH5_DUTY = FT_CH5_VARS+<(FT_CHN_DUTY) - -FT_CH1_VOLUME = FT_CH1_ENVS+<(FT_ENV_VALUE)+0 -FT_CH2_VOLUME = FT_CH2_ENVS+<(FT_ENV_VALUE)+0 -FT_CH3_VOLUME = FT_CH3_ENVS+<(FT_ENV_VALUE)+0 -FT_CH4_VOLUME = FT_CH4_ENVS+<(FT_ENV_VALUE)+0 - -FT_CH1_NOTE_OFF = FT_CH1_ENVS+<(FT_ENV_VALUE)+1 -FT_CH2_NOTE_OFF = FT_CH2_ENVS+<(FT_ENV_VALUE)+1 -FT_CH3_NOTE_OFF = FT_CH3_ENVS+<(FT_ENV_VALUE)+1 -FT_CH4_NOTE_OFF = FT_CH4_ENVS+<(FT_ENV_VALUE)+1 - -FT_CH1_PITCH_OFF = FT_CH1_ENVS+<(FT_ENV_VALUE)+2 -FT_CH2_PITCH_OFF = FT_CH2_ENVS+<(FT_ENV_VALUE)+2 -FT_CH3_PITCH_OFF = FT_CH3_ENVS+<(FT_ENV_VALUE)+2 - - -FT_VARS = FT_CHANNELS+FT_CHANNELS_ALL*FT_CHN_STRUCT_SIZE - -FT_PAL_ADJUST = FT_VARS+0 -FT_SONG_LIST_L = FT_VARS+1 -FT_SONG_LIST_H = FT_VARS+2 -FT_INSTRUMENT_L = FT_VARS+3 -FT_INSTRUMENT_H = FT_VARS+4 -FT_TEMPO_STEP_L = FT_VARS+5 -FT_TEMPO_STEP_H = FT_VARS+6 -FT_TEMPO_ACC_L = FT_VARS+7 -FT_TEMPO_ACC_H = FT_VARS+8 -FT_SONG_SPEED = FT_CH5_INSTRUMENT -FT_PULSE1_PREV = FT_CH3_DUTY -FT_PULSE2_PREV = FT_CH5_DUTY -FT_DPCM_LIST_L = FT_VARS+9 -FT_DPCM_LIST_H = FT_VARS+10 -FT_DPCM_EFFECT = FT_VARS+11 -FT_OUT_BUF = FT_VARS+12 ;11 bytes - - -;sound effect stream variables, 2 bytes and 15 bytes per stream -;when sound effects are disabled, this memory is not used - -FT_SFX_ADR_L = FT_VARS+23 -FT_SFX_ADR_H = FT_VARS+24 -FT_SFX_BASE_ADR = FT_VARS+25 - -FT_SFX_STRUCT_SIZE = 15 -FT_SFX_REPEAT = FT_SFX_BASE_ADR+0 -FT_SFX_PTR_L = FT_SFX_BASE_ADR+1 -FT_SFX_PTR_H = FT_SFX_BASE_ADR+2 -FT_SFX_OFF = FT_SFX_BASE_ADR+3 -FT_SFX_BUF = FT_SFX_BASE_ADR+4 ;11 bytes - -FT_BASE_SIZE = FT_SFX_BUF+11-FT_BASE_ADR - -;aliases for sound effect channels to use in user calls - -FT_SFX_CH0 = FT_SFX_STRUCT_SIZE*0 -FT_SFX_CH1 = FT_SFX_STRUCT_SIZE*1 -FT_SFX_CH2 = FT_SFX_STRUCT_SIZE*2 -FT_SFX_CH3 = FT_SFX_STRUCT_SIZE*3 - - -;aliases for the APU registers - -APU_PL1_VOL = $4000 -APU_PL1_SWEEP = $4001 -APU_PL1_LO = $4002 -APU_PL1_HI = $4003 -APU_PL2_VOL = $4004 -APU_PL2_SWEEP = $4005 -APU_PL2_LO = $4006 -APU_PL2_HI = $4007 -APU_TRI_LINEAR = $4008 -APU_TRI_LO = $400a -APU_TRI_HI = $400b -APU_NOISE_VOL = $400c -APU_NOISE_LO = $400e -APU_NOISE_HI = $400f -APU_DMC_FREQ = $4010 -APU_DMC_RAW = $4011 -APU_DMC_START = $4012 -APU_DMC_LEN = $4013 -APU_SND_CHN = $4015 - - -;aliases for the APU registers in the output buffer - - IFNCONST FT_SFX_ENABLE ;if sound effects are disabled, write to the APU directly -FT_MR_PULSE1_V = APU_PL1_VOL -FT_MR_PULSE1_L = APU_PL1_LO -FT_MR_PULSE1_H = APU_PL1_HI -FT_MR_PULSE2_V = APU_PL2_VOL -FT_MR_PULSE2_L = APU_PL2_LO -FT_MR_PULSE2_H = APU_PL2_HI -FT_MR_TRI_V = APU_TRI_LINEAR -FT_MR_TRI_L = APU_TRI_LO -FT_MR_TRI_H = APU_TRI_HI -FT_MR_NOISE_V = APU_NOISE_VOL -FT_MR_NOISE_F = APU_NOISE_LO - ELSE ;otherwise write to the output buffer -FT_MR_PULSE1_V = FT_OUT_BUF -FT_MR_PULSE1_L = FT_OUT_BUF+1 -FT_MR_PULSE1_H = FT_OUT_BUF+2 -FT_MR_PULSE2_V = FT_OUT_BUF+3 -FT_MR_PULSE2_L = FT_OUT_BUF+4 -FT_MR_PULSE2_H = FT_OUT_BUF+5 -FT_MR_TRI_V = FT_OUT_BUF+6 -FT_MR_TRI_L = FT_OUT_BUF+7 -FT_MR_TRI_H = FT_OUT_BUF+8 -FT_MR_NOISE_V = FT_OUT_BUF+9 -FT_MR_NOISE_F = FT_OUT_BUF+10 - ENDIF - - - -;------------------------------------------------------------------------------ -; reset APU, initialize FamiTone -; in: A 0 for PAL, not 0 for NTSC -; X,Y pointer to music data -;------------------------------------------------------------------------------ - -FamiToneInit: subroutine - - stx FT_SONG_LIST_L ;store music data pointer for further use - sty FT_SONG_LIST_H - stx (_FT2DummyEnvelope) - sta FT_ENV_ADR_H,x - lda #0 - sta FT_ENV_REPEAT,x - sta FT_ENV_VALUE,x - inx - cpx #<(FT_ENVELOPES)+FT_ENVELOPES_ALL - - bne .set_envelopes - - jmp FamiToneSampleStop - - -;------------------------------------------------------------------------------ -; play music -; in: A number of subsong -;------------------------------------------------------------------------------ - -FamiToneMusicPlay: subroutine - - ldx FT_SONG_LIST_L - stx 0 - ldx #FT_SFX_CH0 - jsr _FT2SfxUpdate - ENDIF - .if FT_SFX_STREAMS>1 - ldx #FT_SFX_CH1 - jsr _FT2SfxUpdate - ENDIF - .if FT_SFX_STREAMS>2 - ldx #FT_SFX_CH2 - jsr _FT2SfxUpdate - ENDIF - .if FT_SFX_STREAMS>3 - ldx #FT_SFX_CH3 - jsr _FT2SfxUpdate - ENDIF - - - ;send data from the output buffer to the APU - - lda FT_OUT_BUF ;pulse 1 volume - sta APU_PL1_VOL - lda FT_OUT_BUF+1 ;pulse 1 period LSB - sta APU_PL1_LO - lda FT_OUT_BUF+2 ;pulse 1 period MSB, only applied when changed - cmp FT_PULSE1_PREV - beq .no_pulse1_upd - sta FT_PULSE1_PREV - sta APU_PL1_HI -.no_pulse1_upd: - - lda FT_OUT_BUF+3 ;pulse 2 volume - sta APU_PL2_VOL - lda FT_OUT_BUF+4 ;pulse 2 period LSB - sta APU_PL2_LO - lda FT_OUT_BUF+5 ;pulse 2 period MSB, only applied when changed - cmp FT_PULSE2_PREV - beq .no_pulse2_upd - sta FT_PULSE2_PREV - sta APU_PL2_HI -.no_pulse2_upd: - - lda FT_OUT_BUF+6 ;triangle volume (plays or not) - sta APU_TRI_LINEAR - lda FT_OUT_BUF+7 ;triangle period LSB - sta APU_TRI_LO - lda FT_OUT_BUF+8 ;triangle period MSB - sta APU_TRI_HI - - lda FT_OUT_BUF+9 ;noise volume - sta APU_NOISE_VOL - lda FT_OUT_BUF+10 ;noise period - sta APU_NOISE_LO - - ENDIF - - IFCONST FT_THREAD - pla - sta FT_TEMP_PTR_H - pla - sta FT_TEMP_PTR_L - ENDIF - - rts - - -;internal routine, sets up envelopes of a channel according to current instrument -;in X envelope group offset, A instrument number - -_FT2SetInstrument: subroutine - asl ;instrument number is pre multiplied by 4 - tay - lda FT_INSTRUMENT_H - adc #0 ;use carry to extend range for 64 instruments - sta >6 + + +;zero page variables + +FT_TEMP_PTR = FT_TEMP ;word +FT_TEMP_PTR_L = FT_TEMP_PTR+0 +FT_TEMP_PTR_H = FT_TEMP_PTR+1 +FT_TEMP_VAR1 = FT_TEMP+2 +FT_TEMP_SIZE = 3 + +;envelope structure offsets, 5 bytes per envelope, grouped by variable type + +FT_ENVELOPES_ALL = 3+3+3+2 ;3 for the pulse and triangle channels, 2 for the noise channel +FT_ENV_STRUCT_SIZE = 5 + +FT_ENV_VALUE = FT_BASE_ADR+0*FT_ENVELOPES_ALL +FT_ENV_REPEAT = FT_BASE_ADR+1*FT_ENVELOPES_ALL +FT_ENV_ADR_L = FT_BASE_ADR+2*FT_ENVELOPES_ALL +FT_ENV_ADR_H = FT_BASE_ADR+3*FT_ENVELOPES_ALL +FT_ENV_PTR = FT_BASE_ADR+4*FT_ENVELOPES_ALL + + +;channel structure offsets, 7 bytes per channel + +FT_CHANNELS_ALL = 5 +FT_CHN_STRUCT_SIZE = 9 + +FT_CHN_PTR_L = FT_BASE_ADR+0*FT_CHANNELS_ALL +FT_CHN_PTR_H = FT_BASE_ADR+1*FT_CHANNELS_ALL +FT_CHN_NOTE = FT_BASE_ADR+2*FT_CHANNELS_ALL +FT_CHN_INSTRUMENT = FT_BASE_ADR+3*FT_CHANNELS_ALL +FT_CHN_REPEAT = FT_BASE_ADR+4*FT_CHANNELS_ALL +FT_CHN_RETURN_L = FT_BASE_ADR+5*FT_CHANNELS_ALL +FT_CHN_RETURN_H = FT_BASE_ADR+6*FT_CHANNELS_ALL +FT_CHN_REF_LEN = FT_BASE_ADR+7*FT_CHANNELS_ALL +FT_CHN_DUTY = FT_BASE_ADR+8*FT_CHANNELS_ALL + + +;variables and aliases + +FT_ENVELOPES = FT_BASE_ADR +FT_CH1_ENVS = FT_ENVELOPES+0 +FT_CH2_ENVS = FT_ENVELOPES+3 +FT_CH3_ENVS = FT_ENVELOPES+6 +FT_CH4_ENVS = FT_ENVELOPES+9 + +FT_CHANNELS = FT_ENVELOPES+FT_ENVELOPES_ALL*FT_ENV_STRUCT_SIZE +FT_CH1_VARS = FT_CHANNELS+0 +FT_CH2_VARS = FT_CHANNELS+1 +FT_CH3_VARS = FT_CHANNELS+2 +FT_CH4_VARS = FT_CHANNELS+3 +FT_CH5_VARS = FT_CHANNELS+4 + + +FT_CH1_NOTE = FT_CH1_VARS+<(FT_CHN_NOTE) +FT_CH2_NOTE = FT_CH2_VARS+<(FT_CHN_NOTE) +FT_CH3_NOTE = FT_CH3_VARS+<(FT_CHN_NOTE) +FT_CH4_NOTE = FT_CH4_VARS+<(FT_CHN_NOTE) +FT_CH5_NOTE = FT_CH5_VARS+<(FT_CHN_NOTE) + +FT_CH1_INSTRUMENT = FT_CH1_VARS+<(FT_CHN_INSTRUMENT) +FT_CH2_INSTRUMENT = FT_CH2_VARS+<(FT_CHN_INSTRUMENT) +FT_CH3_INSTRUMENT = FT_CH3_VARS+<(FT_CHN_INSTRUMENT) +FT_CH4_INSTRUMENT = FT_CH4_VARS+<(FT_CHN_INSTRUMENT) +FT_CH5_INSTRUMENT = FT_CH5_VARS+<(FT_CHN_INSTRUMENT) + +FT_CH1_DUTY = FT_CH1_VARS+<(FT_CHN_DUTY) +FT_CH2_DUTY = FT_CH2_VARS+<(FT_CHN_DUTY) +FT_CH3_DUTY = FT_CH3_VARS+<(FT_CHN_DUTY) +FT_CH4_DUTY = FT_CH4_VARS+<(FT_CHN_DUTY) +FT_CH5_DUTY = FT_CH5_VARS+<(FT_CHN_DUTY) + +FT_CH1_VOLUME = FT_CH1_ENVS+<(FT_ENV_VALUE)+0 +FT_CH2_VOLUME = FT_CH2_ENVS+<(FT_ENV_VALUE)+0 +FT_CH3_VOLUME = FT_CH3_ENVS+<(FT_ENV_VALUE)+0 +FT_CH4_VOLUME = FT_CH4_ENVS+<(FT_ENV_VALUE)+0 + +FT_CH1_NOTE_OFF = FT_CH1_ENVS+<(FT_ENV_VALUE)+1 +FT_CH2_NOTE_OFF = FT_CH2_ENVS+<(FT_ENV_VALUE)+1 +FT_CH3_NOTE_OFF = FT_CH3_ENVS+<(FT_ENV_VALUE)+1 +FT_CH4_NOTE_OFF = FT_CH4_ENVS+<(FT_ENV_VALUE)+1 + +FT_CH1_PITCH_OFF = FT_CH1_ENVS+<(FT_ENV_VALUE)+2 +FT_CH2_PITCH_OFF = FT_CH2_ENVS+<(FT_ENV_VALUE)+2 +FT_CH3_PITCH_OFF = FT_CH3_ENVS+<(FT_ENV_VALUE)+2 + + +FT_VARS = FT_CHANNELS+FT_CHANNELS_ALL*FT_CHN_STRUCT_SIZE + +FT_PAL_ADJUST = FT_VARS+0 +FT_SONG_LIST_L = FT_VARS+1 +FT_SONG_LIST_H = FT_VARS+2 +FT_INSTRUMENT_L = FT_VARS+3 +FT_INSTRUMENT_H = FT_VARS+4 +FT_TEMPO_STEP_L = FT_VARS+5 +FT_TEMPO_STEP_H = FT_VARS+6 +FT_TEMPO_ACC_L = FT_VARS+7 +FT_TEMPO_ACC_H = FT_VARS+8 +FT_SONG_SPEED = FT_CH5_INSTRUMENT +FT_PULSE1_PREV = FT_CH3_DUTY +FT_PULSE2_PREV = FT_CH5_DUTY +FT_DPCM_LIST_L = FT_VARS+9 +FT_DPCM_LIST_H = FT_VARS+10 +FT_DPCM_EFFECT = FT_VARS+11 +FT_OUT_BUF = FT_VARS+12 ;11 bytes + + +;sound effect stream variables, 2 bytes and 15 bytes per stream +;when sound effects are disabled, this memory is not used + +FT_SFX_ADR_L = FT_VARS+23 +FT_SFX_ADR_H = FT_VARS+24 +FT_SFX_BASE_ADR = FT_VARS+25 + +FT_SFX_STRUCT_SIZE = 15 +FT_SFX_REPEAT = FT_SFX_BASE_ADR+0 +FT_SFX_PTR_L = FT_SFX_BASE_ADR+1 +FT_SFX_PTR_H = FT_SFX_BASE_ADR+2 +FT_SFX_OFF = FT_SFX_BASE_ADR+3 +FT_SFX_BUF = FT_SFX_BASE_ADR+4 ;11 bytes + +FT_BASE_SIZE = FT_SFX_BUF+11-FT_BASE_ADR + +;aliases for sound effect channels to use in user calls + +FT_SFX_CH0 = FT_SFX_STRUCT_SIZE*0 +FT_SFX_CH1 = FT_SFX_STRUCT_SIZE*1 +FT_SFX_CH2 = FT_SFX_STRUCT_SIZE*2 +FT_SFX_CH3 = FT_SFX_STRUCT_SIZE*3 + + +;aliases for the APU registers + +APU_PL1_VOL = $4000 +APU_PL1_SWEEP = $4001 +APU_PL1_LO = $4002 +APU_PL1_HI = $4003 +APU_PL2_VOL = $4004 +APU_PL2_SWEEP = $4005 +APU_PL2_LO = $4006 +APU_PL2_HI = $4007 +APU_TRI_LINEAR = $4008 +APU_TRI_LO = $400a +APU_TRI_HI = $400b +APU_NOISE_VOL = $400c +APU_NOISE_LO = $400e +APU_NOISE_HI = $400f +APU_DMC_FREQ = $4010 +APU_DMC_RAW = $4011 +APU_DMC_START = $4012 +APU_DMC_LEN = $4013 +APU_SND_CHN = $4015 + + +;aliases for the APU registers in the output buffer + + IFNCONST FT_SFX_ENABLE ;if sound effects are disabled, write to the APU directly +FT_MR_PULSE1_V = APU_PL1_VOL +FT_MR_PULSE1_L = APU_PL1_LO +FT_MR_PULSE1_H = APU_PL1_HI +FT_MR_PULSE2_V = APU_PL2_VOL +FT_MR_PULSE2_L = APU_PL2_LO +FT_MR_PULSE2_H = APU_PL2_HI +FT_MR_TRI_V = APU_TRI_LINEAR +FT_MR_TRI_L = APU_TRI_LO +FT_MR_TRI_H = APU_TRI_HI +FT_MR_NOISE_V = APU_NOISE_VOL +FT_MR_NOISE_F = APU_NOISE_LO + ELSE ;otherwise write to the output buffer +FT_MR_PULSE1_V = FT_OUT_BUF +FT_MR_PULSE1_L = FT_OUT_BUF+1 +FT_MR_PULSE1_H = FT_OUT_BUF+2 +FT_MR_PULSE2_V = FT_OUT_BUF+3 +FT_MR_PULSE2_L = FT_OUT_BUF+4 +FT_MR_PULSE2_H = FT_OUT_BUF+5 +FT_MR_TRI_V = FT_OUT_BUF+6 +FT_MR_TRI_L = FT_OUT_BUF+7 +FT_MR_TRI_H = FT_OUT_BUF+8 +FT_MR_NOISE_V = FT_OUT_BUF+9 +FT_MR_NOISE_F = FT_OUT_BUF+10 + ENDIF + + + +;------------------------------------------------------------------------------ +; reset APU, initialize FamiTone +; in: A 0 for PAL, not 0 for NTSC +; X,Y pointer to music data +;------------------------------------------------------------------------------ + +FamiToneInit: subroutine + + stx FT_SONG_LIST_L ;store music data pointer for further use + sty FT_SONG_LIST_H + stx (_FT2DummyEnvelope) + sta FT_ENV_ADR_H,x + lda #0 + sta FT_ENV_REPEAT,x + sta FT_ENV_VALUE,x + inx + cpx #<(FT_ENVELOPES)+FT_ENVELOPES_ALL + + bne .set_envelopes + + jmp FamiToneSampleStop + + +;------------------------------------------------------------------------------ +; play music +; in: A number of subsong +;------------------------------------------------------------------------------ + +FamiToneMusicPlay: subroutine + + ldx FT_SONG_LIST_L + stx 0 + ldx #FT_SFX_CH0 + jsr _FT2SfxUpdate + ENDIF + .if FT_SFX_STREAMS>1 + ldx #FT_SFX_CH1 + jsr _FT2SfxUpdate + ENDIF + .if FT_SFX_STREAMS>2 + ldx #FT_SFX_CH2 + jsr _FT2SfxUpdate + ENDIF + .if FT_SFX_STREAMS>3 + ldx #FT_SFX_CH3 + jsr _FT2SfxUpdate + ENDIF + + + ;send data from the output buffer to the APU + + lda FT_OUT_BUF ;pulse 1 volume + sta APU_PL1_VOL + lda FT_OUT_BUF+1 ;pulse 1 period LSB + sta APU_PL1_LO + lda FT_OUT_BUF+2 ;pulse 1 period MSB, only applied when changed + cmp FT_PULSE1_PREV + beq .no_pulse1_upd + sta FT_PULSE1_PREV + sta APU_PL1_HI +.no_pulse1_upd: + + lda FT_OUT_BUF+3 ;pulse 2 volume + sta APU_PL2_VOL + lda FT_OUT_BUF+4 ;pulse 2 period LSB + sta APU_PL2_LO + lda FT_OUT_BUF+5 ;pulse 2 period MSB, only applied when changed + cmp FT_PULSE2_PREV + beq .no_pulse2_upd + sta FT_PULSE2_PREV + sta APU_PL2_HI +.no_pulse2_upd: + + lda FT_OUT_BUF+6 ;triangle volume (plays or not) + sta APU_TRI_LINEAR + lda FT_OUT_BUF+7 ;triangle period LSB + sta APU_TRI_LO + lda FT_OUT_BUF+8 ;triangle period MSB + sta APU_TRI_HI + + lda FT_OUT_BUF+9 ;noise volume + sta APU_NOISE_VOL + lda FT_OUT_BUF+10 ;noise period + sta APU_NOISE_LO + + ENDIF + + IFCONST FT_THREAD + pla + sta FT_TEMP_PTR_H + pla + sta FT_TEMP_PTR_L + ENDIF + + rts + + +;internal routine, sets up envelopes of a channel according to current instrument +;in X envelope group offset, A instrument number + +_FT2SetInstrument: subroutine + asl ;instrument number is pre multiplied by 4 + tay + lda FT_INSTRUMENT_H + adc #0 ;use carry to extend range for 64 instruments + sta // include NESLIB header - #include "neslib.h" // include CC65 NES Header (PPU) - #include -///// PATTERN TABLE - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" ///// METASPRITES @@ -79,9 +74,6 @@ const char PALETTE[32] = { // setup PPU and tables void setup_graphics() { - // set pattern table - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); // clear sprites oam_hide_rest(0); // set palette colors diff --git a/presets/nes/metasprites.c b/presets/nes/metasprites.c index f7becbf6..f704d9b2 100644 --- a/presets/nes/metasprites.c +++ b/presets/nes/metasprites.c @@ -3,18 +3,13 @@ #include // include NESLIB header - #include "neslib.h" // include CC65 NES Header (PPU) - #include -///// PATTERN TABLE - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" ///// METASPRITES @@ -79,9 +74,6 @@ const char PALETTE[32] = { // setup PPU and tables void setup_graphics() { - // set pattern table - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); // clear sprites oam_clear(); // set palette colors diff --git a/presets/nes/musicdemo.asm b/presets/nes/musicdemo.asm index cbc16cc1..067b80c6 100644 --- a/presets/nes/musicdemo.asm +++ b/presets/nes/musicdemo.asm @@ -12,10 +12,10 @@ FT_TEMP ds 3 ;3 bytes in zeropage used by the library as a scratchpad FT_BASE_ADR = $0500 ;page in the RAM used for FT2 variables, should be $xx00 FT_DPCM_OFF = DMCSamples ;$c000..$ffc0, 64-byte steps FT_SFX_STREAMS = 4 ;number of sound effects played at once, 1..4 -FT_DPCM_ENABLE = 1 ;undefine to exclude all DMC code +;FT_DPCM_ENABLE = 1 ;undefine to exclude all DMC code FT_SFX_ENABLE = 1 ;undefine to exclude all sound effects code ;FT_THREAD = 1 ;undefine if you are calling sound effects from the same thread as the sound update call -;FT_PAL_SUPPORT = 1 ;undefine to exclude PAL support +FT_PAL_SUPPORT = 1 ;undefine to exclude PAL support FT_NTSC_SUPPORT = 1 ;undefine to exclude NTSC support ;;;;; NES CARTRIDGE HEADER @@ -52,6 +52,7 @@ Start: ldy #>music_data lda PPU_STATUS and #$80 ;NTSC_MODE + eor #$80 jsr FamiToneInit lda #0 jsr FamiToneMusicPlay diff --git a/presets/nes/nesdefs.asm b/presets/nes/nesdefs.asm index 2050a84e..77ecf506 100644 --- a/presets/nes/nesdefs.asm +++ b/presets/nes/nesdefs.asm @@ -22,6 +22,9 @@ APU_DMC_CTRL = $4010 APU_CHAN_CTRL = $4015 APU_FRAME = $4017 +JOYPAD1 = $4016 +JOYPAD2 = $4017 + ; NOTE: I've put this outside of the PPU & APU, because it is a feature ; of the APU that is primarily of use to the PPU. OAM_DMA = $4014 @@ -139,7 +142,7 @@ NES_MIRR_QUAD = 8 pha ENDM -;;;;; SAVE_REGS - restore Y/X/A registers +;;;;; RESTORE_REGS - restore Y/X/A registers MAC RESTORE_REGS pla diff --git a/presets/nes/neslib1.c b/presets/nes/neslib1.c index 1af0f866..8f6e14b8 100644 --- a/presets/nes/neslib1.c +++ b/presets/nes/neslib1.c @@ -2,12 +2,8 @@ #include "neslib.h" #include -// link the pattern table into PRG ROM -// we'll write it into CHR RAM on startup - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" // function to write a string into the name table // adr = start address in name table @@ -19,10 +15,6 @@ void put_str(unsigned int adr, const char *str) { // main function, run after console reset void main(void) { - // copy pattern table to PRG RAM - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); - // set palette colors pal_col(1,0x04); pal_col(2,0x20); diff --git a/presets/nes/nesppu.asm b/presets/nes/nesppu.asm index 788e4866..20462c5d 100644 --- a/presets/nes/nesppu.asm +++ b/presets/nes/nesppu.asm @@ -42,3 +42,20 @@ PrevRandom subroutine .NoEor: rts +;;;;; CONTROLLER READING + +ReadJoypad subroutine + lda #$01 + sta JOYPAD1 ; set strobe bit + tax ; X = 1 + lsr ; now A is 0 + sta JOYPAD1 ; clear strobe bit +.loop: + lda JOYPAD1 ; load controller state + lsr ; bit 0 -> carry + txa ; X -> A + rol ; carry -> bit 0 of result, bit 7 -> carry + tax ; A -> X + bcc .loop ; repeat until 1 shifted out + rts ; controller bits returned in A + diff --git a/presets/nes/road.asm b/presets/nes/road.asm index 7c83fcc7..f966d4ed 100644 --- a/presets/nes/road.asm +++ b/presets/nes/road.asm @@ -1,4 +1,4 @@ - + include "nesdefs.asm" ;;;;; ZERO-PAGE VARIABLES diff --git a/presets/nes/scroll.c b/presets/nes/scroll.c index 7e9414db..d32ac498 100644 --- a/presets/nes/scroll.c +++ b/presets/nes/scroll.c @@ -2,12 +2,8 @@ #include "neslib.h" #include -// link the pattern table into PRG ROM -// we'll write it into CHR RAM on startup - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" // function to write a string into the name table // adr = start address in name table @@ -38,10 +34,6 @@ void scroll_demo() { // main function, run after console reset void main(void) { - // copy pattern table to PRG RAM - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); - // set palette colors pal_col(1,0x04); pal_col(2,0x20); diff --git a/presets/nes/shoot2.c b/presets/nes/shoot2.c index 8d8fea79..499c3cf9 100644 --- a/presets/nes/shoot2.c +++ b/presets/nes/shoot2.c @@ -1,4 +1,4 @@ - + #include #include #include diff --git a/presets/nes/skeleton.cc65 b/presets/nes/skeleton.cc65 index 039fdb15..6eac344b 100644 --- a/presets/nes/skeleton.cc65 +++ b/presets/nes/skeleton.cc65 @@ -1,15 +1,11 @@ #include "neslib.h" -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define TILESET jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" void main(void) { - //copy tileset to RAM - vram_adr(0x0); - vram_write((unsigned char*)TILESET, sizeof(TILESET)); pal_col(1,0x04); pal_col(2,0x20); pal_col(3,0x30); diff --git a/presets/nes/sprites.c b/presets/nes/sprites.c index 7c215e1d..644129da 100644 --- a/presets/nes/sprites.c +++ b/presets/nes/sprites.c @@ -3,18 +3,13 @@ #include // include NESLIB header - #include "neslib.h" // include CC65 NES Header (PPU) - #include -///// PATTERN TABLE - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" const char PALETTE[32] = { @@ -33,9 +28,6 @@ const char PALETTE[32] = { // setup PPU and tables void setup_graphics() { - // set pattern table - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); // clear sprites oam_clear(); // set palette colors diff --git a/presets/nes/statusbar.c b/presets/nes/statusbar.c index ac3398bc..3afb5f06 100644 --- a/presets/nes/statusbar.c +++ b/presets/nes/statusbar.c @@ -5,12 +5,8 @@ // vertical mirroring (horizontal scroling) #define NES_MIRRORING 1 -// link the pattern table into PRG ROM -// we'll write it into CHR RAM on startup - -//#link "jroatch.c" -extern unsigned char jroatch_chr[0x1000]; -#define PATTERN_TABLE jroatch_chr +// link the pattern table into CHR ROM +//#link "chr_generic.s" // function to write a string into the name table // adr = start address in name table @@ -40,10 +36,6 @@ void scroll_demo() { // main function, run after console reset void main(void) { - // copy pattern table to PRG RAM - vram_adr(0x0); - vram_write((unsigned char*)PATTERN_TABLE, sizeof(PATTERN_TABLE)); - // set palette colors pal_col(0,0x00); pal_col(1,0x04); diff --git a/presets/nes/tileset1.c b/presets/nes/tileset1.c index a5b74554..8d8d01fe 100644 --- a/presets/nes/tileset1.c +++ b/presets/nes/tileset1.c @@ -7,7 +7,8 @@ const unsigned char palSprites[16]={/*{pal:"nes",n:4,sets:4}*/ 0x0f,0x19,0x29,0x39 }; -const unsigned char TILESET[8*256] = {/*{w:8,h:8,bpp:1,count:256,brev:1,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}*/ +const unsigned char TILESET[8*256] = { +/*{w:8,h:8,bpp:1,count:256,brev:1,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x7c,0x7c,0x7c,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0x6c,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0xfe,0x6c,0xfe,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xfe,0xd0,0xfe,0x16,0xfe,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xce,0xdc,0x38,0x76,0xe6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x6c,0x7c,0xec,0xee,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x70,0x70,0x70,0x70,0x70,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x38,0x38,0x38,0x38,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0x38,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0xfe,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x1e,0x3c,0x78,0xf0,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x7c,0xee,0xee,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x78,0x38,0x38,0x38,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x0e,0x7c,0xe0,0xee,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x0e,0x3c,0x0e,0x0e,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x7e,0xee,0xee,0xfe,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0xe0,0xfc,0x0e,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0xfc,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xee,0x1c,0x1c,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0x7c,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0x7e,0x0e,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x60,0x60,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x38,0x70,0x70,0x38,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x38,0x1c,0x1c,0x38,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0x1c,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x7c,0xee,0xee,0xee,0xe0,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0xee,0xfe,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0xee,0xfc,0xee,0xee,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xe0,0xe0,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xec,0xee,0xee,0xee,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xe0,0xf0,0xe0,0xe0,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xe0,0xf8,0xe0,0xe0,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0xee,0xee,0xee,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xfe,0xee,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x38,0x38,0x38,0x38,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x0e,0x0e,0x0e,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xfc,0xf8,0xec,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0xe0,0xe0,0xe0,0xee,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0xee,0xfe,0xfe,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xce,0xee,0xfe,0xfe,0xee,0xe6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, diff --git a/presets/nes/transtable.c b/presets/nes/transtable.c index ceb7e779..43fe2bab 100644 --- a/presets/nes/transtable.c +++ b/presets/nes/transtable.c @@ -1,10 +1,13 @@ - + //this example code shows how to put some text in nametable #include "neslib.h" #include +#pragma data-name (push,"CHARS") +#pragma data-name(pop) + const unsigned char TILESET[48*16] = {/*{w:8,h:8,bpp:1,count:48,brev:1,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x7e,0x42,0x42,0x46,0x46,0x46,0x7e,0x00,0x7e,0x42,0x42,0x46,0x46,0x46,0x7e,0x00, diff --git a/src/ui.ts b/src/ui.ts index 66391ab1..e91df95c 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -538,7 +538,7 @@ function _downloadAllFilesZipFile(e) { // TODO: handle binary files store.getItem(path, (err, text) => { if (text) { - zip.file(fixFilename(getFilenameForPath(path)), text); + zip.file(fixFilename(path), text); } if (++count == keys.length) { zip.generateAsync({type:"blob"}).then( (content) => { diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index 192fc976..9aa17561 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -126,9 +126,9 @@ var PLATFORM_PARAMS = { define: '__NES__', cfgfile: 'neslib.cfg', libargs: ['crt0.o', 'nes.lib', - '-D', 'NES_MAPPER=2', // UxROM + '-D', 'NES_MAPPER=0', // UxROM '-D', 'NES_PRG_BANKS=2', // 2 PRG banks - '-D', 'NES_CHR_BANKS=0', // TODO: >0 doesn't seem to work + '-D', 'NES_CHR_BANKS=1', // 1 CHR bank '-D', 'NES_MIRRORING=0', // horizontal mirroring ], extra_link_files: ['crt0.o'], @@ -876,13 +876,30 @@ function linkLD65(step:BuildStep) { return; // parse symbol map (TODO: omit segments, constants) var symbolmap = {}; + var seg_re = /^__(\w+)_SIZE__$/; for (var s of viceout.split("\n")) { var toks = s.split(" "); if (toks[0] == 'al') { - symbolmap[toks[2].substr(1)] = parseInt(toks[1], 16); + let ident = toks[2].substr(1); + let ofs = parseInt(toks[1], 16); + symbolmap[ident] = ofs; } } - // TODO: "of" in IE? + // build segment map + var segments = {}; + for (let ident in symbolmap) { + let m = seg_re.exec(ident); + if (m) { + let seg = m[1]; + let segstart = symbolmap['__'+seg+'_RUN__'] || symbolmap['__'+seg+'_START__']; + let segsize = symbolmap['__'+seg+'_SIZE__']; + let seglast = symbolmap['__'+seg+'_LAST__']; + if (segstart >= 0 && segsize > 0) { + segments[seg] = {start:segstart, size:segsize, last:seglast}; + } + } + } + // build listings var listings = {}; for (var fn of step.files) { if (fn.endsWith('.lst')) { @@ -902,6 +919,7 @@ function linkLD65(step:BuildStep) { listings:listings, errors:errors, symbolmap:symbolmap, + segments:segments }; } }