Skip to content

Commit

Permalink
Create objects once; reset them on reset()
Browse files Browse the repository at this point in the history
Coincidentally fixes #466
  • Loading branch information
mattgodbolt committed Jan 1, 2025
1 parent d3787d5 commit 7b080be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/6502.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ export class Cpu6502 extends Base6502 {
this.debugger = dbgr;

this.video = video_;
this.crtc = this.video.crtc;
this.ula = this.video.ula;
this.soundChip = soundChip_;
this.music5000 = music5000_;
this.ddNoise = ddNoise_;
Expand Down Expand Up @@ -615,6 +617,24 @@ export class Cpu6502 extends Base6502 {
this.debugInstruction = new DebugHook(this, "_debugInstruction");
this.debugRead = new DebugHook(this, "_debugRead");
this.debugWrite = new DebugHook(this, "_debugWrite");

this.scheduler = new Scheduler();
this.sysvia = new via.SysVia(
this,
this.scheduler,
this.video,
this.soundChip,
this.cmos,
this.model.isMaster,
this.config.keyLayout,
this.config.getGamepads,
);
this.uservia = new via.UserVia(this, this.scheduler, this.model.isMaster, this.config.userPort);
this.acia = new Acia(this, this.soundChip.toneGenerator, this.scheduler, this.touchScreen);
this.serial = new Serial(this.acia);
this.adconverter = new Adc(this.sysvia, this.scheduler);
this.soundChip.setScheduler(this.scheduler);
this.fdc = new this.model.Fdc(this, this.ddNoise, this.scheduler, this.debugFlags);
}

getPrevPc(index) {
Expand Down Expand Up @@ -1141,32 +1161,19 @@ export class Cpu6502 extends Base6502 {
}
}
this.videoDisplayPage = 0;
this.scheduler = new Scheduler();
this.soundChip.setScheduler(this.scheduler);
this.sysvia = new via.SysVia(
this,
this.scheduler,
this.video,
this.soundChip,
this.cmos,
this.model.isMaster,
this.config.keyLayout,
this.config.getGamepads,
);
this.uservia = new via.UserVia(this, this.scheduler, this.model.isMaster, this.config.userPort);
if (this.config.printerPort) this.uservia.ca2changecallback = this.config.printerPort.outputStrobe;
this.touchScreen = new TouchScreen(this.scheduler);
this.acia = new Acia(this, this.soundChip.toneGenerator, this.scheduler, this.touchScreen);
this.serial = new Serial(this.acia);

this.sysvia.reset();
this.uservia.reset();
this.acia.reset();
this.serial.reset();
this.ddNoise.spinDown();
this.fdc = new this.model.Fdc(this, this.ddNoise, this.scheduler, this.debugFlags);
this.crtc = this.video.crtc;
this.ula = this.video.ula;
this.adconverter = new Adc(this.sysvia, this.scheduler);
this.fdc.powerOnReset();
this.adconverter.reset();

this.touchScreen = new TouchScreen(this.scheduler);
if (this.model.hasTeletextAdaptor) this.teletextAdaptor = new TeletextAdaptor(this);
if (this.econet) this.filestore = new Filestore(this, this.econet);
this.sysvia.reset(hard);
this.uservia.reset(hard);
} else {
this.fdc.reset();
}
Expand Down
6 changes: 6 additions & 0 deletions src/adc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export class Adc {
this.high = 0x00;
}

reset() {
this.status = 0x40;
this.low = 0x00;
this.high = 0x00;
}

read(addr) {
switch (addr & 3) {
case 0:
Expand Down

0 comments on commit 7b080be

Please sign in to comment.