Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C64] implement 2Mhz CPU speed for C128 running in C64 mode #101

Open
nippur72 opened this issue Apr 26, 2019 · 9 comments
Open

[C64] implement 2Mhz CPU speed for C128 running in C64 mode #101

nippur72 opened this issue Apr 26, 2019 · 9 comments

Comments

@nippur72
Copy link
Contributor

there are some games (notably the new "Super Mario Bros") that are able to take advantage of the 2Mhz CPU speed that you can get when running the C128 in C64 mode.

I think it would be nice if we have this option in the MiST core too (e.g. "Enable 2Mhz 8502: Off;On;")

I tried to code it myself but got lost in the fine details of the state machine, sysCycleDef and the intricate jungle of enable signals. I thought it would be as easy as adding an extra CPU cycle, but of course it wasn't.

Summary of the 2Mhz mode:

  • when enabled the C64 responds to the register $D030, otherwise the register is always $FF
  • bit 0: when 1 => 2Mhz speed is active (not exactly 2Mhz, it's just that clock speed is doubled)
  • bit 1: test bit (not used but can be read and written)
  • other bits are always 1

When running at 2Mhz, the VIC-II can't cope with the new speed and displays garbage in the active area, but borders are ok. Games usually enable it during the blanking/border periods.

All other chips receive an effective 1Mhz frequency:

[...] the system employs an elaborate technique known as clock stretching, where the
clock period is extended to create an effective 1-MHz rate for the portion of the clock cycle when the I/O chip is being accessed.

@gyurco
Copy link
Contributor

gyurco commented Apr 26, 2019

It'll also affect SDRAM timings, not sure if the current controller can cope with that. Also it shouldn't clash with VIC II memory access, so if 2MHz is enabled, VIC II should be disabled. Then the VIC memory cycle can be used for the 8502.

@harbaum
Copy link
Contributor

harbaum commented Apr 26, 2019

As far as i understand this would not need ram timing changes. Instead the cpu just also gets the vic memory slots assigned. The vic would then just display garbage while the cpu is running at 2 Mhz which also happens on the real c128 in c64 mode.

So in thery there shouldn't be many things to change. But i am not sure it's worth tje effort and even less the confusion this option may cause with many users.

@gyurco
Copy link
Contributor

gyurco commented Apr 26, 2019

Yepp, probably it's enough to have a second cpuEnable together with enableVic, but set cpuHasBus to 1 in the VIC II cycle, too.

@gyurco
Copy link
Contributor

gyurco commented Apr 27, 2019

Experimented with turbo mode, but at the end you have to switch back to 1 MHz mode if the CPU does IO to CIA, SID, etc... because at 2MHz these can miss reads and writes. And also have to adjust these peripherals CE (do the clock stretching). The result however was not very reliable, so at the end I gave up on this.

@juri74
Copy link

juri74 commented Apr 30, 2019

i had a quick look at c128 schematics, looks like the cpu is always clocked at 2mhz, i have to verify this with an oscilloscope, the 2mhz line go to MMU too, then there are some logic chips that drive the RDY signal of cpu, i think that when in 1mhz mode the cpu is somehow halted for 1 cycle, so it is acting like is feeded with 1 mhz clock. i found this interesting article about pheriperal driving with 2mhz 6502
http://6502.org/mini-projects/rdy-generation/index.html

@gyurco
Copy link
Contributor

gyurco commented Apr 30, 2019

Halting with RDY is not the same as giving it a 1 MHz clock, for example RDY doesn't stop a write cycle.

@juri74
Copy link

juri74 commented May 3, 2019

ok i investigated a little further, the cpu is not actually clocked @2mhz forever, and when the cpu is "forced" @2mhz (for example using FAST command on c128) it do not stay @2mhz forever, the clock line return @1Mhz during dynamic ram refresh and during i/o access. some interesting infos are found in C128 service manual (pag 33 and 34):
http://zetaweb.org/web/manuals/C128%20Service%20Manual.pdf

@gyurco
Copy link
Contributor

gyurco commented May 4, 2019

That make sense, actually that's what I deduced. But not trivial to implement.

@gyurco
Copy link
Contributor

gyurco commented Aug 31, 2021

I finally added this feature. Looks like the 1541 doesn't work with it, I wonder if it's the same with a C128 - 1541 combo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants