build segment table; download all has local/ prefix; NES: use CHR ROM for C

This commit is contained in:
Steven Hugg 2019-02-21 14:19:29 -05:00
parent e9d207fa84
commit 806600994f
25 changed files with 1353 additions and 1382 deletions

View File

@ -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

View File

@ -3,25 +3,20 @@
#include <string.h>
// include NESLIB header
#include "neslib.h"
// include CC65 NES Header (PPU)
#include <nes.h>
// 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);

View File

@ -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){

View File

@ -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

View File

@ -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!"

View File

@ -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

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -3,18 +3,13 @@
#include <string.h>
// include NESLIB header
#include "neslib.h"
// include CC65 NES Header (PPU)
#include <nes.h>
///// 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

View File

@ -3,18 +3,13 @@
#include <string.h>
// include NESLIB header
#include "neslib.h"
// include CC65 NES Header (PPU)
#include <nes.h>
///// 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

View File

@ -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

View File

@ -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

View File

@ -2,12 +2,8 @@
#include "neslib.h"
#include <string.h>
// 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);

View File

@ -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

View File

@ -1,4 +1,4 @@

include "nesdefs.asm"
;;;;; ZERO-PAGE VARIABLES

View File

@ -2,12 +2,8 @@
#include "neslib.h"
#include <string.h>
// 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);

View File

@ -1,4 +1,4 @@

#include <stdlib.h>
#include <string.h>
#include <nes.h>

View File

@ -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);

View File

@ -3,18 +3,13 @@
#include <string.h>
// include NESLIB header
#include "neslib.h"
// include CC65 NES Header (PPU)
#include <nes.h>
///// 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

View File

@ -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);

View File

@ -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,

View File

@ -1,10 +1,13 @@

//this example code shows how to put some text in nametable
#include "neslib.h"
#include <string.h>
#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,

View File

@ -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) => {

View File

@ -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
};
}
}