Skip to content

Commit 5e1f037

Browse files
author
Commander Coder
committed
added snow effect due to CPU accessing video memory at same time as VDG
1 parent 3870b64 commit 5e1f037

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

6502.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ function Tube6502(model, cpu) {
350350
if (this.romPaged && (offset & 0xf000) === 0xf000) {
351351
return this.rom[offset & 0xfff];
352352
}
353+
354+
// video generator needs to know when CPU is accessing memory so it can make snow
355+
if (model.isAtom && model.snow) this.video.video6847.cpuAddrAccess(offset & 0xffff);
356+
353357
return this.memory[offset & 0xffff];
354358
};
355359
this.readmemZpStack = function (offset) {
@@ -833,6 +837,10 @@ export function Cpu6502(model, dbgr, video_, soundChip_, ddNoise_, music5000_, c
833837
if (this._debugWrite) this._debugWrite(addr, b);
834838
if (this.memStat[this.memStatOffset + (addr >>> 8)] === 1) {
835839
var offset = this.memLook[this.memStatOffset + (addr >>> 8)];
840+
841+
// video generator needs to know when CPU is accessing memory so it can make snow
842+
if (model.isAtom && model.snow) this.video.video6847.cpuAddrAccess(offset + addr);
843+
836844
this.ramRomOs[offset + addr] = b;
837845
return;
838846
}

6847.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,38 @@ export function Video6847(video) {
178178
this.bitmapY = 0;
179179
};
180180

181+
/*
182+
Snow is caused by the CPU changing the address bus for 500ns at the
183+
same time as the VDG is expecting to get data from the address it has
184+
requested, which takes 1100ns (1.1us). This only occurs if the cpu is
185+
access graphics memory. So while the VDG is generating a scanline, the address
186+
will change for 500ns based on the CPU memory accesses (read or write) and
187+
the VDG will read 'noise' from the CPU addressed memory location instead.
188+
*/
189+
190+
this.cpuAddr = 0;
191+
this.cpuAddrAccess = function (addr) {
192+
// CPU has read from memory here
193+
// VDG can read from this address for a cycle if it was video memory
194+
// to generate snow
195+
this.cpuAddr = addr;
196+
};
197+
181198
// atom video memory is 0x8000->0x9fff (8k but only bottom 6k used)
199+
// effecively goes up to 0x9800
182200
this.readVideoMem = function () {
183-
var memAddr = this.addr & 0x1fff; //6k
201+
let cpuaddr = this.cpuAddr;
202+
203+
this.cpuAddr = 0; // reset the memory access by cpu but if it tries again it'll be set again
204+
205+
// during a vdg cycle, cpu might be active
206+
if (this.vdg_cycles >= 0 && this.vdg_cycles < 1) {
207+
if (cpuaddr > 0x8000 && this.cpuAddr <= 0x9800) {
208+
return this.cpu.videoRead(cpuaddr);
209+
}
210+
}
211+
212+
var memAddr = this.addr & 0x1fff;
184213
memAddr |= 0x8000;
185214
return this.cpu.videoRead(memAddr);
186215
};

config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function Config(onClose) {
1313
this.set65c02(this.model.tube);
1414
this.setTeletext(this.model.hasTeletextAdaptor);
1515
this.setMusic5000(this.model.hasMusic5000);
16+
this.setSnowstorm(this.model.snow);
17+
setModelMenus(this.model.name);
1618
});
1719

1820
$configuration.addEventListener("hide.bs.modal", () => onClose(changed));
@@ -46,17 +48,34 @@ export function Config(onClose) {
4648
this.addRemoveROM("ats-3.0.rom", enabled);
4749
};
4850

51+
this.setSnowstorm = function (enabled) {
52+
enabled = !!enabled;
53+
$("#showAtomSnowstorm").prop("checked", enabled);
54+
this.model.snow = enabled;
55+
};
56+
4957
function setDropdownText(modelName) {
5058
$("#bbc-model-dropdown .bbc-model").text(modelName);
5159
}
5260

61+
function setModelMenus(modelname) {
62+
// set BBC and ATOM stuff
63+
let atom = modelname.includes("Atom");
64+
65+
$("#65c02").prop("disabled", atom);
66+
$("#hasTeletextAdaptor").prop("disabled", atom);
67+
$("#hasMusic5000").prop("disabled", atom);
68+
$("#showAtomSnowstorm").prop("disabled", !atom);
69+
}
70+
5371
$(".model-menu a").on(
5472
"click",
5573
function (e) {
5674
const modelName = $(e.target).attr("data-target");
5775
changed.model = modelName;
5876

5977
setDropdownText($(e.target).text());
78+
setModelMenus(modelName);
6079
}.bind(this)
6180
);
6281

@@ -81,6 +100,13 @@ export function Config(onClose) {
81100
}.bind(this)
82101
);
83102

103+
$("#showAtomSnowstorm").on(
104+
"click",
105+
function () {
106+
changed.snow = $("#showAtomSnowstorm").prop("checked");
107+
}.bind(this)
108+
);
109+
84110
$(".keyboard-menu a").on(
85111
"click",
86112
function (e) {

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,10 @@ <h5 class="modal-title" id="configurationModalLabel">Emulation Configuration</h5
934934
<input class="form-check-input" type="checkbox" id="hasTeletextAdaptor" name="hasTeletextAdaptor" />
935935
<label class="form-check-label" for="hasTeletextAdaptor">Teletext adaptor</label>
936936
</div>
937+
<div class="form-check">
938+
<input class="form-check-input" type="checkbox" id="showAtomSnowstorm" name="showAtomSnowstorm" />
939+
<label class="form-check-label" for="showAtomSnowstorm">Atom Snowstorm</label>
940+
</div>
937941
</div>
938942
</div>
939943
</div>

main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ var config = new Config(function (changed) {
166166
changed.model ||
167167
changed.coProcessor !== undefined ||
168168
changed.hasMusic5000 !== undefined ||
169-
changed.hasTeletextAdaptor !== undefined
169+
changed.hasTeletextAdaptor !== undefined ||
170+
changed.snow !== undefined
170171
) {
171172
areYouSure(
172173
"Changing model requires a restart of the emulator. Restart now?",
@@ -193,6 +194,7 @@ config.setKeyLayout(keyLayout);
193194
config.set65c02(parsedQuery.coProcessor);
194195
config.setMusic5000(parsedQuery.hasMusic5000);
195196
config.setTeletext(parsedQuery.hasTeletextAdaptor);
197+
config.setSnowstorm(parsedQuery.snow);
196198

197199
model = config.model;
198200

0 commit comments

Comments
 (0)