mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-22 14:33:51 +00:00
don't save to local storage unless edited; handle running out of local storage
This commit is contained in:
parent
a087e6b7cf
commit
56677a25e9
102
presets/nes-conio/ex0.asm
Normal file
102
presets/nes-conio/ex0.asm
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
;;;;; CONSTANTS
|
||||
|
||||
PPU_CTRL equ $2000
|
||||
PPU_MASK equ $2001
|
||||
PPU_STATUS equ $2002
|
||||
PPU_SCROLL equ $2005
|
||||
PPU_ADDR equ $2006
|
||||
PPU_DATA equ $2007
|
||||
DMC_FREQ equ $4010
|
||||
|
||||
;;;;; CARTRIDGE FILE HEADER
|
||||
|
||||
processor 6502
|
||||
seg Header
|
||||
org $7FF0
|
||||
|
||||
NES_MAPPER equ 0 ;mapper number
|
||||
NES_PRG_BANKS equ 2 ;number of 16K PRG banks, change to 2 for NROM256
|
||||
NES_CHR_BANKS equ 1 ;number of 8K CHR banks (0 = RAM)
|
||||
NES_MIRRORING equ 1 ;0 horizontal, 1 vertical, 8 four screen
|
||||
|
||||
.byte $4e,$45,$53,$1a ; header
|
||||
.byte NES_PRG_BANKS
|
||||
.byte NES_CHR_BANKS
|
||||
.byte NES_MIRRORING|(NES_MAPPER<<4)
|
||||
.byte NES_MAPPER&$f0
|
||||
|
||||
;;;;; CODE
|
||||
|
||||
seg Code
|
||||
org $8000
|
||||
start:
|
||||
_exit:
|
||||
sei ;disable IRQs
|
||||
cld ;decimal mode not supported
|
||||
ldx #$ff
|
||||
txs ;set up stack pointer
|
||||
inx ;increment X to 0
|
||||
stx PPU_MASK ;disable rendering
|
||||
stx DMC_FREQ ;disable DMC interrupts
|
||||
stx PPU_CTRL ;disable NMI interrupts
|
||||
jsr WaitSyncSafe ;wait for VSYNC
|
||||
; clear RAM -- not a subroutine because we clear the stack too
|
||||
lda #0
|
||||
tax
|
||||
.loop
|
||||
sta $0,x
|
||||
sta $100,x
|
||||
; skip $200-$2FF, used for OAM display list
|
||||
sta $300,x
|
||||
sta $400,x
|
||||
sta $500,x
|
||||
sta $600,x
|
||||
sta $700,x
|
||||
inx
|
||||
bne .loop
|
||||
; wait for PPU warmup
|
||||
jsr WaitSync
|
||||
; set palette background
|
||||
ldy #$0
|
||||
lda #$3f
|
||||
sta PPU_ADDR
|
||||
sty PPU_ADDR
|
||||
lda #$1c
|
||||
sta PPU_DATA
|
||||
; enable PPU rendering
|
||||
lda #0
|
||||
sta PPU_ADDR
|
||||
sta PPU_ADDR ;PPU addr = 0
|
||||
sta PPU_SCROLL
|
||||
sta PPU_SCROLL ;scroll = 0
|
||||
lda #$90
|
||||
sta PPU_CTRL ;enable NMI
|
||||
lda #$1e
|
||||
sta PPU_MASK ;enable rendering
|
||||
.endless
|
||||
jmp .endless ;endless loop
|
||||
|
||||
;;;;; SUBROUTINES
|
||||
|
||||
; wait for VSYNC to start
|
||||
WaitSyncSafe: subroutine
|
||||
bit PPU_STATUS
|
||||
WaitSync:
|
||||
bit PPU_STATUS
|
||||
bpl WaitSync
|
||||
rts
|
||||
|
||||
;;;;; INTERRUPT HANDLERS
|
||||
|
||||
nmi:
|
||||
irq:
|
||||
rti
|
||||
|
||||
;;;;; CPU VECTORS
|
||||
|
||||
org $fffa
|
||||
.word nmi ;$fffa vblank nmi
|
||||
.word start ;$fffc reset
|
||||
.word irq ;$fffe irq / brk
|
||||
|
@ -4,16 +4,13 @@
|
||||
PPU_CTRL equ $2000
|
||||
PPU_MASK equ $2001
|
||||
PPU_STATUS equ $2002
|
||||
PPU_OAM_ADDR equ $2003
|
||||
PPU_OAM_DATA equ $2004
|
||||
OAM_ADDR equ $2003
|
||||
OAM_DATA equ $2004
|
||||
PPU_SCROLL equ $2005
|
||||
PPU_ADDR equ $2006
|
||||
PPU_DATA equ $2007
|
||||
PPU_OAM_DMA equ $4014
|
||||
PPU_FRAMECNT equ $4017
|
||||
DMC_FREQ equ $4010
|
||||
CTRL_PORT1 equ $4016
|
||||
CTRL_PORT2 equ $4017
|
||||
|
||||
;;;;; ZERO-PAGE VARIABLES
|
||||
|
||||
@ -45,16 +42,33 @@ NES_MIRRORING equ 1 ;0 horizontal, 1 vertical, 8 four screen
|
||||
org $8000
|
||||
start:
|
||||
_exit:
|
||||
sei
|
||||
sei ;disable IRQs
|
||||
cld ;decimal mode not supported
|
||||
ldx #$ff
|
||||
txs
|
||||
inx ;X=0
|
||||
txs ;set up stack pointer
|
||||
inx ;increment X to 0
|
||||
stx PPU_MASK ;disable rendering
|
||||
stx DMC_FREQ ;disable DMC (samples)
|
||||
stx PPU_CTRL ;disable NMI (interrupts)
|
||||
jsr WaitSync ;wait for VSYNC
|
||||
stx DMC_FREQ ;disable DMC interrupts
|
||||
stx PPU_CTRL ;disable NMI interrupts
|
||||
jsr WaitSyncSafe ;wait for VSYNC
|
||||
; clear RAM -- not a subroutine because we clear the stack too
|
||||
lda #0
|
||||
tax
|
||||
.loop
|
||||
sta $0,x
|
||||
sta $100,x
|
||||
; skip $200-$2FF, used for OAM display list
|
||||
sta $300,x
|
||||
sta $400,x
|
||||
sta $500,x
|
||||
sta $600,x
|
||||
sta $700,x
|
||||
inx
|
||||
bne .loop
|
||||
; end of clear RAM routine
|
||||
jsr SetPalette ;set colors
|
||||
jsr ClearVRAM ;clear VRAM
|
||||
jsr FillVRAM ;set PPU RAM
|
||||
jsr WaitSync ;wait for VSYNC (and PPU warmup)
|
||||
lda #0
|
||||
sta PPU_ADDR
|
||||
sta PPU_ADDR ;PPU addr = 0
|
||||
@ -84,8 +98,8 @@ SetPalette: subroutine
|
||||
bne .loop
|
||||
rts
|
||||
|
||||
; clear video RAM
|
||||
ClearVRAM: subroutine
|
||||
; fill video RAM
|
||||
FillVRAM: subroutine
|
||||
txa
|
||||
ldy #$20
|
||||
sty PPU_ADDR
|
||||
@ -101,11 +115,11 @@ ClearVRAM: subroutine
|
||||
rts
|
||||
|
||||
; wait for VSYNC to start
|
||||
WaitSync: subroutine
|
||||
WaitSyncSafe: subroutine
|
||||
bit PPU_STATUS
|
||||
.1:
|
||||
WaitSync:
|
||||
bit PPU_STATUS
|
||||
bpl .1
|
||||
bpl WaitSync
|
||||
rts
|
||||
|
||||
;;;;; INTERRUPT HANDLERS
|
||||
|
@ -8,10 +8,11 @@ var NES_NESLIB_PRESETS = [
|
||||
];
|
||||
|
||||
var NES_CONIO_PRESETS = [
|
||||
{id:'hello.c', name:'Hello PPU'},
|
||||
{id:'conio.c', name:'Hello Console I/O'},
|
||||
{id:'siegegame.c', name:'Siege Game'},
|
||||
{id:'ex1.asm', name:'Assembly Example'},
|
||||
{id:'ex0.asm', name:'ASM: Initialization'},
|
||||
{id:'ex1.asm', name:'ASM: Scrolling Demo'},
|
||||
{id:'hello.c', name:'C: Hello PPU'},
|
||||
{id:'conio.c', name:'C: Hello Console I/O'},
|
||||
{id:'siegegame.c', name:'C: Siege Game'},
|
||||
];
|
||||
|
||||
/// JSNES
|
||||
|
33
src/ui.js
33
src/ui.js
@ -35,13 +35,39 @@ Javatari.AUTO_START = false;
|
||||
var PRESETS; // presets array
|
||||
var platform_id;
|
||||
var platform; // platform object
|
||||
var originalFileID;
|
||||
var originalText;
|
||||
|
||||
var toolbar = $("#controls_top");
|
||||
|
||||
function getBiggestItems(storage) {
|
||||
var items = [];
|
||||
for (var i = 0; i < storage.length; i++) {
|
||||
var key = storage.key(i);
|
||||
items.push([lpad(storage.getItem(key).length+"", 12), key]);
|
||||
}
|
||||
items.sort();
|
||||
var s = "";
|
||||
for (var i=items.length-5; i<items.length; i++) {
|
||||
s += items[i] + "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
var FileStore = function(storage, prefix) {
|
||||
var self = this;
|
||||
this.saveFile = function(name, text) {
|
||||
storage.setItem(prefix + name, text);
|
||||
try {
|
||||
storage.setItem(prefix + name, text);
|
||||
} catch (e) {
|
||||
if (e.name == 'NS_ERROR_DOM_QUOTA_REACHED') {
|
||||
console.log(e);
|
||||
alert("Sorry, you've reached your local storage quota for this browser.\n\nHere are the biggest items:\n\n" +
|
||||
getBiggestItems(storage));
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.loadFile = function(name) {
|
||||
return storage.getItem(prefix + name) || storage.getItem(name);
|
||||
@ -181,7 +207,7 @@ function setLastPreset(id) {
|
||||
}
|
||||
|
||||
function updatePreset(current_preset_id, text) {
|
||||
if (text.trim().length) {
|
||||
if (text.trim().length && (originalFileID != current_preset_id || text != originalText)) {
|
||||
store.saveFile(current_preset_id, text);
|
||||
}
|
||||
}
|
||||
@ -193,6 +219,8 @@ function loadCode(text, fileid) {
|
||||
editor.clearHistory();
|
||||
current_output = null;
|
||||
setLastPreset(fileid);
|
||||
originalFileID = fileid;
|
||||
originalText = text;
|
||||
}
|
||||
|
||||
function loadFile(fileid, filename, index) {
|
||||
@ -220,7 +248,6 @@ function loadFile(fileid, filename, index) {
|
||||
var ext = platform.getToolForFilename(fileid);
|
||||
$.get( "presets/"+platform_id+"/skeleton."+ext, function( text ) {
|
||||
loadCode(text, fileid);
|
||||
updatePreset(fileid, text);
|
||||
}, 'text')
|
||||
.fail(function() {
|
||||
alert("Could not load skeleton for " + platform_id + "/" + ext);
|
||||
|
Loading…
Reference in New Issue
Block a user