mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-23 12:29:53 +00:00
nes: added nesasm3
This commit is contained in:
parent
1f3f0e7613
commit
8b2b512b28
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ local
|
||||
release
|
||||
gen
|
||||
test/output
|
||||
.DS_Store
|
||||
|
@ -128,6 +128,7 @@ TODO:
|
||||
- show cur/tmp vram addresses
|
||||
- NES crt should mark raster pos when debugging
|
||||
- OAMDMA in profiler? (haltCycles)
|
||||
- ca65 skeleton
|
||||
- JSNES
|
||||
- doesn't support hiding >8 sprites
|
||||
- doesn't do sprite zero test right
|
||||
|
99
presets/nes/skeleton.ca65
Normal file
99
presets/nes/skeleton.ca65
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
;#define LIBARGS ,
|
||||
|
||||
;
|
||||
; iNES header
|
||||
;
|
||||
|
||||
.segment "HEADER"
|
||||
|
||||
INES_MAPPER = 0 ; 0 = NROM
|
||||
INES_MIRROR = 1 ; 0 = horizontal mirroring, 1 = vertical mirroring
|
||||
INES_SRAM = 0 ; 1 = battery backed SRAM at $6000-7FFF
|
||||
|
||||
.byte 'N', 'E', 'S', $1A ; ID
|
||||
.byte $02 ; 16k PRG chunk count
|
||||
.byte $01 ; 8k CHR chunk count
|
||||
.byte INES_MIRROR | (INES_SRAM << 1) | ((INES_MAPPER & $f) << 4)
|
||||
.byte (INES_MAPPER & %11110000)
|
||||
.byte $0, $0, $0, $0, $0, $0, $0, $0 ; padding
|
||||
|
||||
;;;;; START OF CODE
|
||||
|
||||
.segment "CODE"
|
||||
Start:
|
||||
sei ; mask interrupts
|
||||
lda #0
|
||||
sta $2000 ; disable NMI
|
||||
sta $2001 ; disable rendering
|
||||
sta $4015 ; disable APU sound
|
||||
sta $4010 ; disable DMC IRQ
|
||||
lda #$40
|
||||
sta $4017 ; disable APU IRQ
|
||||
cld ; disable decimal mode
|
||||
ldx #$FF
|
||||
txs ; initialize stack
|
||||
; wait for first vblank
|
||||
bit $2002
|
||||
:
|
||||
bit $2002
|
||||
bpl :-
|
||||
; clear all RAM to 0
|
||||
lda #0
|
||||
ldx #0
|
||||
:
|
||||
sta $0000, X
|
||||
sta $0100, X
|
||||
sta $0200, X
|
||||
sta $0300, X
|
||||
sta $0400, X
|
||||
sta $0500, X
|
||||
sta $0600, X
|
||||
sta $0700, X
|
||||
inx
|
||||
bne :-
|
||||
; place all sprites offscreen at Y=255
|
||||
lda #255
|
||||
ldx #0
|
||||
:
|
||||
sta $200, X
|
||||
inx
|
||||
inx
|
||||
inx
|
||||
inx
|
||||
bne :-
|
||||
; wait for second vblank
|
||||
:
|
||||
bit $2002
|
||||
bpl :-
|
||||
; NES is initialized, ready to begin!
|
||||
; enable the NMI for graphical updates, and jump to our main program
|
||||
lda #%10001000
|
||||
sta $2000
|
||||
Endless:
|
||||
jmp Endless ; endless loop
|
||||
|
||||
;;;;; INTERRUPT HANDLERS
|
||||
|
||||
NMIHandler:
|
||||
rti
|
||||
|
||||
;;;;; CPU VECTORS
|
||||
|
||||
.segment "VECTORS"
|
||||
|
||||
.word NMIHandler
|
||||
.word Start
|
||||
.word NMIHandler
|
||||
|
||||
;
|
||||
; CHR ROM
|
||||
;
|
||||
.segment "CHARS"
|
||||
.incbin "jroatch.chr"
|
||||
|
||||
;
|
||||
; .etc
|
||||
;
|
||||
.segment "STARTUP"
|
||||
.segment "SAMPLES"
|
63
presets/nes/skeleton.nesasm
Normal file
63
presets/nes/skeleton.nesasm
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
.inesprg 1 ; 1x 16KB PRG code
|
||||
.ineschr 1 ; 1x 8KB CHR data
|
||||
.inesmap 0 ; mapper 0 = NROM, no bank swapping
|
||||
.inesmir 1 ; background mirroring
|
||||
|
||||
;;;;;;;;;;;;;;;
|
||||
|
||||
.bank 0
|
||||
.org $C000
|
||||
RESET:
|
||||
SEI ; disable IRQs
|
||||
CLD ; disable decimal mode
|
||||
LDX #$40
|
||||
STX $4017 ; disable APU frame IRQ
|
||||
LDX #$FF
|
||||
TXS ; Set up stack
|
||||
INX ; now X = 0
|
||||
STX $2000 ; disable NMI
|
||||
STX $2001 ; disable rendering
|
||||
STX $4010 ; disable DMC IRQs
|
||||
|
||||
vblankwait1: ; First wait for vblank to make sure PPU is ready
|
||||
BIT $2002
|
||||
BPL vblankwait1
|
||||
|
||||
clrmem:
|
||||
LDA #$00
|
||||
STA $0000, x
|
||||
STA $0100, x
|
||||
STA $0400, x
|
||||
STA $0500, x
|
||||
STA $0600, x
|
||||
STA $0700, x
|
||||
LDA #$FE
|
||||
STA $0300, x
|
||||
INX
|
||||
BNE clrmem
|
||||
|
||||
vblankwait2: ; Second wait for vblank, PPU is ready after this
|
||||
BIT $2002
|
||||
BPL vblankwait2
|
||||
|
||||
Foreverloop:
|
||||
JMP Foreverloop ;jump back to Forever, infinite loop
|
||||
|
||||
IRQ:
|
||||
NMI:
|
||||
RTI
|
||||
|
||||
;;;;;;;;;;;;;;
|
||||
|
||||
.bank 1
|
||||
.org $FFFA
|
||||
.dw NMI
|
||||
.dw RESET
|
||||
.dw IRQ
|
||||
|
||||
;;;;;;;;;;;;;;
|
||||
|
||||
.bank 2
|
||||
.org $0000
|
||||
.incbin "jroatch.chr" ;include CHR ROM
|
@ -385,8 +385,8 @@ class JSNESPlatform extends Base6502Platform implements Platform {
|
||||
}
|
||||
getToolForFilename = (fn:string) : string => {
|
||||
//if (fn.endsWith(".asm")) return "ca65"; // .asm uses ca65
|
||||
//else
|
||||
return getToolForFilename_6502(fn);
|
||||
if (fn.endsWith(".nesasm")) return "nesasm";
|
||||
else return getToolForFilename_6502(fn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ var TOOL_TO_SOURCE_STYLE = {
|
||||
'acme': '6502',
|
||||
'cc65': 'text/x-csrc',
|
||||
'ca65': '6502',
|
||||
'nesasm': '6502',
|
||||
'z80asm': 'z80',
|
||||
'sdasz80': 'z80',
|
||||
'sdcc': 'text/x-csrc',
|
||||
|
21
src/worker/wasm/nesasm.js
Normal file
21
src/worker/wasm/nesasm.js
Normal file
File diff suppressed because one or more lines are too long
BIN
src/worker/wasm/nesasm.wasm
Normal file
BIN
src/worker/wasm/nesasm.wasm
Normal file
Binary file not shown.
@ -1995,12 +1995,110 @@ function assembleXASM6809(step:BuildStep) {
|
||||
};
|
||||
}
|
||||
|
||||
// http://www.nespowerpak.com/nesasm/
|
||||
function assembleNESASM(step:BuildStep) {
|
||||
loadNative("nesasm");
|
||||
var re_filename = /[#](\d+)\s+(\S+)/;
|
||||
var re_insn = /\s+(\d+)\s+([0-9A-F]+):([0-9A-F]+)/;
|
||||
var re_error = /\s+(.+)/;
|
||||
var errors = [];
|
||||
var state = 0;
|
||||
var lineno = 0;
|
||||
var filename;
|
||||
function match_fn(s) {
|
||||
var m;
|
||||
switch (state) {
|
||||
case 0:
|
||||
m = re_filename.exec(s);
|
||||
if (m) {
|
||||
filename = m[2];
|
||||
}
|
||||
m = re_insn.exec(s);
|
||||
if (m) {
|
||||
lineno = parseInt(m[1]);
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
m = re_error.exec(s);
|
||||
if (m) {
|
||||
errors.push({line:lineno, msg:m[1]});
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
var Module = emglobal.nesasm({
|
||||
instantiateWasm: moduleInstFn('nesasm'),
|
||||
noInitialRun:true,
|
||||
print:match_fn
|
||||
});
|
||||
var FS = Module['FS'];
|
||||
populateFiles(step, FS, {
|
||||
mainFilePath:'main.a'
|
||||
});
|
||||
var binpath = step.prefix+'.nes';
|
||||
var lstpath = step.prefix+'.lst';
|
||||
var sympath = step.prefix+'.fns';
|
||||
execMain(step, Module, [step.path, '-s', "-l", "2" ]);
|
||||
// parse main listing, get errors and listings for each file
|
||||
var listings = {};
|
||||
try {
|
||||
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
|
||||
// 16 00:C004 8E 17 40 STX $4017 ; disable APU frame IRQ
|
||||
var asmlines = parseListing(alst, /^\s*(\d+)\s+([0-9A-F]+):([0-9A-F]+)\s+([0-9A-F ]+?) (.*)/i, 1, 3, 4);
|
||||
putWorkFile(lstpath, alst);
|
||||
listings[lstpath] = {
|
||||
lines:asmlines,
|
||||
text:alst
|
||||
};
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
if (errors.length) {
|
||||
return {errors:errors};
|
||||
}
|
||||
// read binary rom output and symbols
|
||||
var aout, asym;
|
||||
aout = FS.readFile(binpath);
|
||||
try {
|
||||
asym = FS.readFile(sympath, {'encoding':'utf8'});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
errors.push({line:0,msg:"No symbol table generated, maybe segment overflow?"});
|
||||
return {errors:errors}
|
||||
}
|
||||
putWorkFile(binpath, aout);
|
||||
putWorkFile(sympath, asym);
|
||||
if (alst) putWorkFile(lstpath, alst); // listing optional (use LIST)
|
||||
// return unchanged if no files changed
|
||||
if (!anyTargetChanged(step, [binpath, sympath]))
|
||||
return;
|
||||
// parse symbols
|
||||
var symbolmap = {};
|
||||
for (var s of asym.split("\n")) {
|
||||
if (!s.startsWith(';')) {
|
||||
var m = /(\w+)\s+=\s+[$]([0-9A-F]+)/.exec(s);
|
||||
if (m) {
|
||||
symbolmap[m[1]] = parseInt(m[2], 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
var segments = step.params.extra_segments;
|
||||
return {
|
||||
output:aout,
|
||||
listings:listings,
|
||||
errors:errors,
|
||||
symbolmap:symbolmap,
|
||||
segments:segments
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
var TOOLS = {
|
||||
'dasm': assembleDASM,
|
||||
|
||||
//'acme': assembleACME,
|
||||
//'plasm': compilePLASMA,
|
||||
'cc65': compileCC65,
|
||||
@ -2018,6 +2116,7 @@ var TOOLS = {
|
||||
//'caspr': compileCASPR,
|
||||
'jsasm': compileJSASMStep,
|
||||
'zmac': assembleZMAC,
|
||||
'nesasm': assembleNESASM,
|
||||
'bataribasic': compileBatariBasic,
|
||||
'markdown': translateShowdown,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user