cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401 Apple-1 Replica Emulator

Digimorf
Associate III
Posted on September 22, 2016 at 13:24

Hello to All, 

recently I coded an emulator of an old Apple-1 inside a STM32F401 Discovery board. It is capable to generate a PAL/NTSC composite video signal, it's interfaced to an old Macintosh 128K keyboard through an Arduino Mini Pro. Currently all programs made for the Apple-1 can run on it, but now I am trying to develop a driver/interface to save or load program to/from a tape player. This is a tricky part because it should run almost in real time to save the signal correctly. 

I am evaluating different options, but it's not easy because the clock of the emulated 6502 has to be 1Mhz, and I can't use an interrupt to execute one instruction a time without interfere with the TV signal generation. 

The 401 is clocked at 84MHz, I was wondering if using something faster like a 429 the 1MHz interrupt can be handled better.

Thanks.

0690X00000603CJQAY.jpg

0690X00000603COQAY.jpg

0690X000006039GQAQ.jpg

0690X0000060367QAA.jpg

0690X00000603CTQAY.jpg

0690X000006039VQAQ.jpg

#apple-1-stm32f401-timer-interrupts
2 REPLIES 2
Posted on September 22, 2016 at 16:02

Interrupting at 1MHz is highly impractical here, you are burning a lot of cycles in the entry/exit switching context, figure out a different way to pace instruction execution. For example watching DWT_CYCCNT, so you have a little more flexibility

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Digimorf
Associate III
Posted on September 22, 2016 at 17:04

Hi Clive1,

thank you for your answer. Yes that is a problem, because the instruction of the emulated CPU needs to be executed at regular intervals as much as possible if I want a ''reral-time'' generation of a signal. Many retrocomputers used to calculates timings by counting CPU cycles and then switching or toggling output signals to save data into tape. 

I can't simply execute a number of instructions each video frame, synchronized by the video driver, because the emulated CPU results in a irregular speed when outputting the signal.

I tried different ways... but not good results. Tried to execute a number of instructions each scanline, but that resulted on a huge jitter in rendering the graphics. Tried also to use the Systick timer configured at 1MHz to execute instructions, and it partially works. The result is a better signal but not enough good for my purpose.

I have read something about this register (DWT_CYCCNT) in other posts about having a timer at MHz. But not yet tried this solution. I suppose I have to monitor this register calling some custom routine from the main, right? Then I can execute instructions from there when a kind of interval has been reached, correct? 

In this case, the interrupt generated by the video driver (a PWM timer that creates the horizontal sync), isn't affected by this. The ''main'' task is left, and then continued.

This could work...