Monday, November 6, 2023

Know the hardware.

What we need also is a schematic of the mainboard of the Macintosh 128k, and a photo of the PCB, top and bottom side. 

I think that if I dig into the hardware I could learn more, and the development process should be a bit easier.

Unfortunately, ChatGPT can't help me find those on the Internet, so I did it by myself. It has been difficult to find them but in the end, I have found something useful.







Sunday, November 5, 2023

Where to start from.

Now that I've set an environment for the development of tests that I can share with you, I am going back to the emulator

My first idea is to design a main section based on a Finite State Machine, that is executed every cycle of the host application. In my Replit project this application is the SDL based environment, while in the STM32 board is a specific H7 targeted project.

I would like to develop this emulator as a scalable and portable application to have it running on different target platforms. My goal here is not to build a commercial product, but to learn, experiment and enjoy the development of an Apple Macintosh 128k.

There are different approaches in building an emulator. Usually, it should be best to start from a minimalist virtual system, so CPU, RAM, ROM, and the minimum hardware used to control the system. But it may not be fun. The systems that I have written a emulator were equipped with a Video Display Processor, so I started to write my emulators from the video stage. This let me to set a visual output system to be used to show debug information.

When I asked ChatGPT to give me information about the Apple Macintosh 128k, it provided me some details on the graphics section. I to was...

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.

And the answer for the graphics section was...

3. Display:

  • Tipo: CRT (tubo a raggi catodici) monocromatico incorporato
  • Dimensione: 9 pollici (diagonale)
  • Risoluzione: 512 x 342 pixel, il che offriva un'immagine sorprendentemente nitida e dettagliata per l'epoca, supportando l'interfaccia grafica dettagliata del Mac.

Actually not many details, Ineed to understand how graphics is generatedfor the video signal.

How graphics are generated on Apple Macintosh 128k?

The graphics on the Apple Macintosh 128K are generated through a combination of hardware and software components. Here's a basic description of the process:

1. Microprocessor: The Macintosh contains a Motorola MC68000 microprocessor, which is the central processing unit responsible for executing instructions, including those for graphic generation.

2. Video Display: The Macintosh uses a bit-mapped video display. This means that the screen is composed of a grid of pixels, where each pixel's state (on or off) is controlled by a corresponding bit in the computer's memory.

3. Video Memory: The video generator uses 21,888 bytes of RAM to create a bit-mapped video image that is 512 pixels wide by 342 pixels tall. Each bit in this memory range controls a single pixel: a 0 bit represents a white pixel, and a 1 bit represents a black pixel.

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

5. Video Scanning Pattern: A full screen display consists of 342 horizontal scan lines. The video scanning pattern includes a vertical blanking interval, which is the time taken by the electron beam to move from the last line of one frame to the first line of the next frame.

6. Toolbox and Operating System Routines: To maintain software compatibility across the Macintosh line and to allow for future changes to the hardware, developers are strongly advised to use the Toolbox and Operating System routines wherever possible for graphics generation.

7. Memory Addresses and Screen Size: It's important to note that memory addresses and screen size may differ across different Macintosh models. Therefore, developers should retrieve the video base address and bit mappings directly from the system to ensure compatibility.

The graphics generation process is designed to be flexible and to provide a high degree of control to the software, allowing for the creation of rich graphical user interfaces and applications that were a hallmark of the early Macintosh computers.

From this it seems that the CPU is responsible for drawing the graphics on the video frame buffer. When a screen has been drawn, somehow the CPU Enables the transfer of data to VIDEO through specific circuits respecting the timings of the video signal. There doesn't appear to be a GPU or VDP.

This could make your job of implementing video output much easier.

Thursday, November 2, 2023

Code sharing, such a great idea.

Difficulties can't stop me, maybe they delay my results but my strong will helps me to find out a way to get things done.

I had to stop for a couple of days, I had to go through several things, but I got an idea for this blog, and some enthusiasm made me get back on this track.

What if I can show you the working source code or the entire emulator? Wouldn't it be great to show directly inside a post a working part of the code? That's a real possibility with Replit.

For now, as an example, I opened a public Replit project where I will save demos shown here. Why Replit? I discovered that supports the use of the SDL library. That means GRAPHICS!! Moreover, it's possible to embed a project inside an <iframe> tag.

Check the "Code development" page!

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.