Tuesday, October 31, 2023

Emulator time scale.

I want to get an idea of how the emulated CPU should work when displaying a video frame. Let's see.

I know that a frame is drawn every 16625.8 µs. Each frame is composed of 342 lines in the Vertical Active Area and 28 lines in the Vertical Blank Area, for a total of 370 lines.

ChatGPT didn't tell me the length of a scanline, but doing some math, 16625.8 µs (frames) / 370 (lines) = 44.395 µs.

This length should include the Horizontal Active Area and the Horizontal Blank Area.


What's the length of an entire scanline?

The length of an entire scanline for the Macintosh 128K's video display is determined by both the time taken to display the pixels on the screen and the horizontal blanking interval. Here's the breakdown:

1. Pixel Clock Rate: The frequency at which pixels are displayed is 15.6672 MHz. This translates to approximately 0.064 microseconds (µsec) per pixel.

2. Pixels Displayed: For each scan line, 512 pixels are drawn on the screen. This requires 32.68 µsec.

3. Horizontal Blanking Interval: After displaying the pixels for a scan line, there's a short period known as the "horizontal blanking interval" before the next scan line begins. This interval takes the time of an additional 192 pixels, which is 12.25 µsec.

Combining the time taken to display the pixels and the horizontal blanking interval, the total time for each full scan line is 44.93 µsec. This means the horizontal scan rate (the frequency at which each horizontal line is refreshed) is 22.25 kilohertz.

In summary, the length of an entire scanline, in terms of time, is 44.93 µsec.

The document "Inside Macintosh Volume III" has been successfully uploaded. It appears to be a detailed manual from Apple, published in 1985, covering various aspects of the Macintosh systems at the time. The manual seems to be quite comprehensive, with a total of 290 pages, and it likely contains technical information, guidelines, and instructions related to the Macintosh computers of that era.

You can now ask specific questions about the content of this manual, or if you need information on particular topics within the document, feel free to ask!

Cool, it seems that we both are on the same line. Now I have to decide how to coordinate the work of the virtual CPU and the updating of the input/output. In previous emulators, I have found it to be a good compromise to make the virtual CPU work for the length of a scanline, and then update input/output.

In terms of graphics I can get effects on individual scanlines, while in terms of sound, I can get more detailed sample generation.I did all this reasoning to understand how to better organize the construction of the virtual CPU, so that I can make it work for a certain number of cycles, so I can update the rest of the virtual machine. I will return to this again.

I did all this reasoning to understand how to better organize the construction of the virtual CPU, so that I can make it work for a certain number of cycles, so I can update the rest of the virtual machine.

Monday, October 30, 2023

CRT still rules.

In older systems equipped with a video or TV output, it was mandatory to synchronize the times of display of the video image and its composition in the system memory.  The cathode ray, continuously driven by the monitor circuits, lights up dots of fluorescent substance deposited inside the screen.

Let's compare this cathode ray to a laser ray, let's imagine moving it from left to right (horizontal active area), turning it on and off at regular time intervals (pixel clock), based on a sequence of "0" and "1" (memory video).  We will have drawn a scanline.

Now we turn off the laser (blank) and bring the beam all the way to the left and below the line we have just drawn (horizontal blank time), at this point, we repeat these steps until we reach the end of the image (vertical active area).

From the bottom of the image we bring the laser back to the top of the screen (vertical blank time), and a new image is read and shown on the screen.

Imagining absurdly that a CRT monitor had a very low resolution and displayed the Apple logo, we could visualize this result:

Where the cathode ray would have this behavior:

These timings are specific to the electronics that drive the cathode ray and must be respected by the other hardware components, otherwise, the images shown would be distorted.

For this purpose the CPU works in parallel until the cathode ray has reached the bottom of the image, then usually through a specific signal, while the cathode ray returns to the top (vertical blank area), the CPU can transfer or calculate the new image into the video memory.

So, the emulator must run all the hardware respecting vertical and horizontal timings. Now, I need to do some math.

Sunday, October 29, 2023

Getting the best basis of knowledge.

After a few days of searching for information about the video signal generated by the Macintosh 128K, I found a PDF of a book about this computer, aimed at developers.

Actually, I have found several books, but only this one showed me the complete timings of a video frame generated by the Macintosh.

This book is what I need for my adventure into coding this emulator. On page 25 of the PDF, in the section "III-18 Over-view of the Hardware", I have found the description of the video interface. 

Here it is explained exactly how a video frame is composed, and the timings of the video signal.

Apple "Inside Macintosh Volume III"

Now, since I can ask ChatGPT to read a PDF for me and then I can ask him what I need, I activate the plugin "AskYourPDF" within a new chat v.4.x

Then I uploaded that PDF in my personal FTP space so that I have full control of the access restrictions.

I am ready now to give the link to ChatGPT:

Here's the PDF about the Macintosh 128k: http://www.x.com/chatgpt/Inside_Macintosh_Volume_III_1985.pdf

The document "Inside Macintosh Volume III" has been successfully uploaded. It appears to be a detailed manual from Apple, published in 1985, covering various aspects of the Macintosh systems at the time. The manual seems to be quite comprehensive, with a total of 290 pages, and it likely contains technical information, guidelines, and instructions related to the Macintosh computers of that era.

You can now ask specific questions about the content of this manual, or if you need information on particular topics within the document, feel free to ask!

Now ChatGPT should use this PDF to answer me.

Please, show me the timings of the video signal generated by the Mac.

The Macintosh 128K uses a specific video scanning pattern to generate its display. Here's a detailed breakdown of the video signal timings:

1. Full-Screen Display: The entire screen display consists of 342 horizontal scan lines. Each full screen takes approximately 15.37 milliseconds (ms) or 15367.65 microseconds (µs) to be scanned. This duration includes the drawing of all horizontal lines across the screen.

2. Vertical Blanking Interval: After completing the last horizontal scan line, there's a short period when all scanning stops to allow the electron beam to return to the top of the screen and start the new screen scan cycle. This interval is called the "vertical blanking interval," taking up additional time equivalent to 28 scan lines, which is approximately 1.26 ms or 1258.17 µs.

3. Full-Screen Refresh Rate: Considering the time taken for both the full-screen display and the vertical blanking interval, the entire screen is redisplayed once every 16.6 ms or 16625.8 µs. This calculation sets the vertical scan rate (the frequency of full-screen refresh) at approximately 60.15 Hertz.

4. Video Memory Usage: The video generator utilizes 21,888 bytes of RAM to compose a bit-mapped video image that is 512 pixels wide by 342 pixels tall. Each bit in this memory range corresponds to a single pixel on the screen, with a 0 representing a white pixel and a 1 representing a black pixel.

5. Screen Buffers: There are two main screen buffers in the memory from which the video circuitry reads information to create the screen display. The starting addresses of these buffers depend on the total memory available in the Macintosh system.

The detailed timing and organization of the video signal are crucial for the correct rendering of the screen display, ensuring that the visuals appear as intended and that the system synchronizes the screen refresh cycles with the internal operations, providing a stable and consistent user experience.

For any modifications or specific operations related to the video display, developers and users were advised to retrieve the video base address and bit mappings directly from the system to ensure compatibility and stability, especially considering future system upgrades or variations in Macintosh models.

This is INSANE! Absolutely amazing.

Friday, October 27, 2023

The concept of the "main cycle" of the emulator.

The basic concept behind the emulator is to mimic the functions of the older computer's hardware components. This doesn't mean it replicates the exact hardware physically. Instead, it simulates the behavior of the hardware using software. It can emulate the function of processors, memory, graphics units, I/O systems, etc.

Since the hardware components run in parallel, the emulator must run a small portion of the code and update the simulation of the input/output virtual components.

What I usually do is make the main cycle duration of the emulator exactly the time of a frame video of the CRT monitor. This mimics the way vintage computers were programmed.

I could summarize the main cycle of the emulation into steps:

  • Run CPU.  
  • Run Graphics unit.
  • Run Sound unit.
  • Run input/output unit.
  • Update audio/video.

Each step must perform the same operations performed by the real hardware in the amount of time that we decide. We need to calculate it, so Jarvis, are you awake?

How long is a frame in the video signal generated by the Macintosh 128k?

Calculating the duration of a frame in the video signal generated by the Macintosh 128K requires knowing technical specifications such as the monitor's refresh rate or other specifications relating to the timing of the video signal. However, I was unable to find this precise information in the documents consulted.

Without the exact specs of the Macintosh 128K monitor, I can't provide an accurate value. If you have additional questions or if I can assist you in any other way, please let me know.

This is not good. I think that it will be difficult to find the specific timings of the CRT monitor embedded in the Macintosh 128K. I think it's better if I search for those data personally by hand.

Monday, October 23, 2023

The Motorola 68000: Introduction.

Another day, another step forward.The most important thing is not to stop. Anyway, it's better to think about something fun, so I am going to have an overall description of the Motorola 68000.

Then, I will dive in to the different aspects of the CPU. My emulator will start from a very small and simple virtual machine made of CPU, ROM and RAM.

I would like to start writing a small test virtual machine made of a basic 68k, and expand it little by little.

Can you describe the 68000?

The Motorola 68000 (shortened to 68k) is a 16/32-bit microprocessor that marked a revolution in micro processor design in the 1980s and beyond. Here's a detailed overview of its features and capabilities:

  • CISC: The 68k is a CISC (Complex Instruction Set Computing) processor, with a rich and varied instruction set that allows for complex operations, ideal for the operating systems of the time that were not optimized for RISC (Reduced Instruction Set Computing) processors.

  • 32-bit Architecture: Although it communicated externally on a 16-bit data bus, it was internally a 32-bit processor. This means it could utilize 32-bit operations and numbers, allowing for the computation of large amounts of data and much larger addresses, though the narrower data bus required more cycles to complete operations.

  • General-Purpose Registers: The 68k featured eight data registers (D0-D7) and seven address registers (A0-A6) for general-purpose operations, all 32-bit. The A7 register was used as the stack pointer.

  • Pipeline Fetch-Execute: It had a simple two-stage pipeline, one for fetching and one for executing the instruction. This was a relatively simple design, but it still allowed a degree of overlap between fetch and execute operations, improving overall performance.
  • Flat Addressing Space: The 68k could address up to 16 MB of memory in a flat address space, meaning that the program and data resided in the same address space (unlike segmented architectures like that used by the Intel 8086).

  • Support for Virtual Memory: Although the base 68000 did not have hardware support for virtual memory, later versions in the 68k series added this support, which was essential for modern operating systems.
  • High-Level Instructions: The instruction set included a variety of high-level operations, including mathematical operations, array management, and bit manipulation, as well as powerful flow control instructions.

  • Flexible Addressing Modes: The 68k supported several addressing modes, allowing programmers to access memory in various ways, thus optimizing memory and code usage.

The 68k handled a wide range of hardware interrupts and exceptions, supporting preemptive multitasking and improving system robustness, essential for operating systems like those used in Macintosh and Amiga computers.

Overall, the Motorola 68000 was known for its balance between power and flexibility. It was relatively easy to program, thanks to its high-level instruction set and its various addressing modes, making it popular among programmers of the time. It laid the groundwork for future generations of processors, influencing system and application design for decades.

What worries me is the development of the CISC tecnology for the instruction parser. It can turn into a nightmare because the emulation of the CPU must be fast.

Anyway, all these information will be useful for the implementation of the emulator, but I need some more information on the CPU.

Saturday, October 21, 2023

Getting an overall idea.

Well, before we get into the architecture of the 68k, can you tell me which computers from the past were designed with this CPU?

The Motorola 68000 CPU, often abbreviated as 68k, has been one of the most influential in several generations of computers, not just the original Macintosh. Here are some of the best-known computers that used the Motorola 68000 processor family:

Apple Macintosh: The original series of Macintosh computers used the 68000, including the Macintosh 128k, the 512k, and the Macintosh Plus.

Atari ST: A series of personal computers produced by Atari Corp from 1985 until the early 1990s. The Atari ST was popular, particularly in Europe, and competed directly with the Commodore Amiga.

Commodore Amiga: Although early Amiga models (most notably the Amiga 1000 and Amiga 500) used the 68000, later models were based on more advanced versions of the Motorola 68k CPU line .

Sinclair QL: This was a personal computer developed by Sinclair Research in 1984, notable for being one of the first home computers based on a 32-bit processor, although commercially it was not very successful.

Sega Genesis/Mega Drive: This popular video game console, released in the late 1980s, used a Motorola 68000 processor as its main CPU, allowing for advanced graphics and gaming performance for its time.

NeXT Computer: The NeXT series of computers, developed by NeXT Inc. (the company founded by Steve Jobs after his departure from Apple in 1985), was based on the Motorola 68k processor, specifically the 68030.

UNIX workstation/workstation systems: Several workstation systems running various forms of UNIX were based on 68k family processors, including those produced by companies such as Sun Microsystems and Silicon Graphics (before they switched to RISC-based CPUs).

These systems demonstrate the flexibility and power of the Motorola 68000, which was suitable for everything from personal computers to professional workstations and gaming consoles. Its architecture has been the basis for many key concepts in CPU design and has influenced software and hardware development for many years.

Very good, it's always good to know that if you need inspiration or help in finding solutions for your work,there are many other possible examples to learn from.

All those systems are advanced, all with different interesting features.

The Macintosh 128K, released in 1984, was Apple's first personal computer to feature a graphical user interface and a mouse, marking a new era in user-friendly computing experiences.


The Commodore Amiga, launched in 1985, was a significant breakthrough in the world of personal computing due to its advanced multimedia capabilities that were ahead of its time.


In any case, now I need to learn more on the 68K. So let's move on.

Thursday, October 19, 2023

Taking advantage of everything that can help me.

The biggest advantage of having a partner like an AI assistant is that you can work whenever you want without being sent to hell. This is great because while you're working on one or more chats you can stop and continue at your convenience, like I'm doing right now.

 A new day is starting, I've done the exercises and now I'm resting on the sofa. What a great time to talk to "Jarvis" and move forward with my project. I'll have to come up with a code name. Anyone have suggestions?

However, let's move on, I have to get much more information on the Macintosh 128K and its architecture. 

Good morning, thanks for this initial information. Now let's proceed in order. I would like a more detailed description of the hardware divided into areas.

The answer is a bit long, so I will split it into more parts.

Of course, let's proceed with a more detailed description of the Macintosh 128k hardware, dividing the analysis into the various key components of the system:

1. CPU (Central Processing Unit):

Model: Motorola 68000

Clock frequency: 7.8336 MHz

The Motorola 68000 CPU was quite advanced for its time, capable of handling up to 16 megabytes of memory addressing (although the Macintosh 128k only used a fraction of that). It had a 32-bit data structure internally with 16- and 24-bit external data and address buses respectively.

excellent, this CPU handles 32bit data, it could be advantageous because the target architecture of the emulator is 32 bit. In the meantime, I'll start taking notes.

But let's try to delve deeper, I still need more information. So, at the end of the previous answer, I will make sure that ChatGPT will "keep in mind" the list of the components.

Ok, keep in mind this list which I will call "structure".

Absolutely, I will keep the "outline" as a reference for our future discussions and for any assistance or details you may need as you work on your emulation project. If you have specific questions or if there is a particular area you would like to focus on or explore further, please let me know and we can proceed accordingly.

ChatGPT will remember it for me, but of course I will collect the informationI need inside a document.

Now I can continue studying the CPU.

Monday, October 16, 2023

How Artificial Intelligence can help me now.


For this project, I need special help. My health issues have changed since the Apple 1 replica project. The learning and studying process can be significantly slowed down. The discouragement, illness, and tiredness caused by a difficult health situation make the development path of a project very difficult if not impossible.

I have always fought, this time I want to have a tool at my side that speeds up the process of searching for information and developing content, leaving me more energy to dedicate to the creative and analysis process.

There has been a lot of discussion lately about the use of AI. As with everything the uses of this technology are varied, what I will show in this project is a "collaboration" in order to complete a project. It will not be a tutorial or a course. Just a blog with results as a practical example of using technology to help a person going through health issues.

For this collaboration, I decided to ask for help from ChatGPT and show you our talks in between the different development steps. I won't go into details on how to use ChatGPT, there are a lot of tutorials on the Internet, so let's start talking to it about my project.

Hello, I would like to start a new project and I need your help.
Of course, I'd be happy to help with your project. Please provide more details about what you're planning. What is the project about? What are your goals? Are there specific areas where you need the most assistance? The more information you give, the better I can provide targeted advice.

Then I'll explain the project to you. Some time ago I built a replica of an Apple 1 computer, which inside had an STM32F4-Discovery electronic board that ran an emulator of this computer. Now I would like to create an emulator for the Macintosh 128k model. I will use a board that mounts an STM32H735 microcontroller. I don't know the Macintosh computer and for this reason, I would like to ask for your help in understanding its architecture. To start, can you tell me something about the Apple Macintosh 128k?

Of course, I will be happy to provide you with information about the Apple Macintosh 128k, which was an iconic and revolutionary computer for its time.

Story and Release:

The Apple Macintosh 128k was the first in a long line of Macintosh computers, launched in January 1984. It was known simply as the "Macintosh" until the successor, the Macintosh 512k, was released, and that's when people started referring to the original model as "128k" to distinguish between the two due to its 128 kilobyte RAM memory.

Innovative Design:

One of the most revolutionary aspects of the Macintosh 128k was its graphical user interface (GUI). Up until that point, most computers relied on text-based command lines that required some technical knowledge to use effectively. The Macintosh, on the other hand, was designed to be intuitive and accessible, even for those with no prior computing experience. It used icons, windows, folders, and mice, relatively new concepts at the time, but which are now universal standards.

Hardware:

On a hardware level, the Macintosh 128k was quite advanced for its time, although its 128 kilobytes of memory soon became a limitation for more advanced applications. Here are some specs:

- CPU: Motorola 68000 at 7.8336 MHz
- RAM: 128 KB (not expandable)
- Display: Integrated 9-inch monochrome screen with a resolution of 512×342 pixels.
- Mass storage: 3.5-inch disk drive for 400 KB diskettes
- Ports: Audio output, mouse port, keyboard port, and two serial ports for accessories such as printers and modems.

Software development:

Software-wise, the Macintosh 128k used the classic Mac OS operating system, which at the time was simply called "System Software". This operating system is significantly different from command line interfaces like DOS or Unix, requiring unique approaches to software development.

Creating an emulator for the Macintosh 128k would be an exciting but challenging project, as you would have to replicate not only the system's hardware but also provide an implementation of the graphical user interface and interaction with the software. Having some experience emulating the Apple 1, you may find this project advanced and rewarding, but it will require a thorough study of the Macintosh 128k's hardware architecture, its system interfaces, and its operating system.

WOW! This is a very promising starting point. I can do my research by asking an AI for the information I need without the risk of getting lost in the sea of the internet. This will be an incredible advantage.

Saturday, October 14, 2023

A Macintosh replica to rise the bar.

Today is a new day. I have a new goal, something that will keep my mind busy, and this time I will try to use the help of artificial intelligence. Hopefully, I will be able to overcome some limitations and speed up the making of this project. But, what kind of project is this? You probably already saw a picture that suggests something. Have you seen a Macintosh old computer? Yes, you have! I have the ambitious goal to build my own Macintosh 128K replica.

I decided to build the first Macintosh because of several features that in some aspects can make my task easier, such as video emulation, since the graphic has only one bit per plane, it will require less memory and simpler hardware to generate the black and white video signal.

In the past I have dedicated myself to emulating 8-bit CPUs, so with this project, I will have the opportunity to work on a 16/32bit CPU, the Motorola 68000. If I have to keep my head busy the project must be a new adventure, after all, the beauty is not arriving but the journey.

I talked about building a replica, but what kind? Going back to the past, the replica of the Apple 1 that I made is very reminiscent of the legend handed down through stories and films about the birth of Apple.


The work was a lot of fun, and it was very demanding both physically and mentally, in fact, I made the wooden case of the computer and the monitor by hand without the use of CNC. To create the exterior I followed an old school approach and I must say that the result was fascinating. 



As regards the internal hardware I decided to follow a more flexible approach even if less faithful to the original. Instead of building a replica of the original PCB and using real chips, I decided to implement a software emulator that runs in an embedded system.

It might seem empty, but thanks to the flexibility of microcontrollers we have the possibility to embed almost all the hardware of a computer in only one chip. 


What about the Macintosh? I already have something in my mind. I will write an emulator for an STM32-powered embedded system for sure, but for the rest it will be a surprise and we will discover it together!

Thursday, October 12, 2023

When needs meet Artificial Intelligence: the beginning.

I have decided to start a new project. I need to set myself a short/medium-term goal to keep me busy. My life will soon take a toll on me and having an exciting project to distract me is vital. In the past I have tackled projects involving retrocomputers, a topic that I particularly love, so I revisited an idea I had some time ago, after I built a replica of the Apple 1 computer at the Embedded World 2019 fair, in Nuremberg, Germany. 

Four years have passed since then, and things have changed. My health has worsened, and the problems are limiting me greatly. I can't afford to do the same things, even though I love these projects, and so in order not to resign myself to fate, I have to work hard to do the same things but in a different way.

I've always wanted to have Jarvis, Tony Stark's artificial assistant. All Iron Man fans remember this scene...

But if we think about it, we are very close. Today with generative artificial intelligence, even I with my disabilities can have a helper who can put into practice what I have in mind. Of course, not at the same level, but hey, I'm a "MECHANIC", I just have to think what I can still do to do what I want to do!

Well, I decided to keep this blog, as a testimony, as proof to myself that I can still be useful. And I hope that anyone who finds themselves at the crossroads of their life can take courage from how much enthusiasm for life I will be able to share.

So, whenever you are in front of a change, remember...


Now, why would I need to use artificial intelligence? I have already created a replica of an Apple 1 computer in the past and I have already written several emulators for retrocomputers. My disability slows me down in many activities such as typing, browsing datasheets, and drawing diagrams. Having an AI assistant, along with voice dictation, will allow me to search and summarize very quickly.

I want to show how Artificial Intelligence can be of help as it is to me for my project.