Amiga Machine Code Letter I - Hint

Amiga machine code - letter 1

Here’s an important hint to get the correct emulated Amiga graphic.

While watching ScoopexUs Youtube channel about Amiga programming, I saw this very interesting text in the video discription:

NOTE the Get Started with WinUAE link in the WinUAE box! Use the default Quickstart Config and check Chipset - Cycle-Exact to make the emulator behave like a real Amiga.

What is cycle-exact? Well, it turns out that cycle-exact does wonders for the mc0101 program! 😉 Let’s revisit the mc0101 code with it’s busy loop, that waits for the left mouse button to be pressed.

; file mc0101.S
move.w    #$4000, $DFF09A
move.w    #$03A0, $DFF096
move.w    $DFF006, $DFF180  ; Set background color to VHPOSR
btst      #6, $BFE001       ; Check left mouse button 
bne.s     loop              ; If not pressed go to loop
move.w    #$83A0, $DFF096
move.w    #$C000, $DFF09A

Without cycle-exact, we just see this screen.

mc0101 screenshot

This is rather static, and not at all what you would expect if you know what the program is doing. Especially this line is worth an explaination.

move.w    $DFF006, $DFF180  ; Set background color to VHPOSR

From the Amiga Hardware Reference Manual we get the following information

DFF006  VHPOSR    Read vert and horiz position of beam
DFF180  COLOR00   Color table 0 (background color)

So, the move instruction is actually moving the VHPOSR beam position into color table 0, which is the background color. In other words we should see something more dynamic in the background. With cycle-exact turned on, the mc0101 program looks liks this:

mc0101 animation

Dramatic difference - n’est-ce pas? Cycle-exact is turned on in the WinUAE chipset settings.

cycle-exact setting

Note, that with cycle-exact turned on, the mc0101 program takes 30% CPU compared to 0-1% when turned off.

There are tons of Amiga stuff at ScoopexUS’s homepage over at If you are into assembly, then visit.

Update 2019-01-13

A friend of mine had an interesting question.

An Amiga 500 has a display resolution of 640x512 and a CPU that runs 7.14 Mhz. That’s around 23 cycles per pixel. If we assume one instruction per cycle, then we have 23 instructions per pixel, which is more than enough time to push the VHPOSR position into color table 0. So why do we see flickering?

Since I’m just starting on this Amiga journey, I could not answer that question, but I did post it on the English Amiga Board. It’s a great board and worth a visit. The board members roondar and Toni Wilen, both agreed that it had something to do with the loop not being alligned with the DMA cycle boundaries. Both their answeres are worth a quote:


I do have a hypothesis as to why your program acts like it does. In fact, I think it’d do the same on a real Amiga (interlaced or not). See, the write action you do with the move.w $DFF006, $DFF180 will execute at whatever cycle is available. And the code you’ve written probably doesn’t fully align on DMA cycle boundaries. Which can cause the position of the colour change to shift from frame to fram.

Or to put it in a different way: the timing of the code you’ve written might not be ‘good enough’ for a stable display. The non-cycle exact mode might simply be more ‘relaxed’ on this front and thus work as you want.

If you want stable timing for colour changes etc, I’d recommend getting to grips with the Copper. Using the Copper guarantees the raster location of register changes. Which is much harder to do with the CPU.

Note: this is an untested hypothesis, I may be wrong 😉

Toni Wilen:

Yeah, cycles used by code isn’t integer divisible by cycles available in one frame. There is also CIA access which is not slowed down by DMA and is not in sync with DMA cycles.

Only cycle-exact mode emulates DMA stealing cycles from CPU. This is not normally a problem because almost all programs use copper which is accurate in all modes.

In the next Amiga machine code letter (letter 2) we will begin to look at the copper 😉.

Some thoughts

The Amiga machine code course came in twelve letters, one each month. I was wondering why there were such a big gab between letters, since I can chew through a letter in one day.

As you can see from the update above, knowledge needs time to ferment. Sometimes it’s good to just go off-piste and allow yourself the time to experiment and investigate what you have learned, so that it can take root.

In the week since I posted this post, and now this update, I have tried to reason about the copper in letter two and get my head around the flickering described in this post. And I was lucky to have a friend that could ask the right question.

Seeing how fast I got answeres to my question, posted on the English Amiga Board, by some very competent members I might add, I’m left in awe.

Games, programs and books have been digitized, and real people are standing by to answer questions. It’s as if the Amiga is a platform that will not die.

Amiga Machine Code Course

Previous post: Amiga Machine Code Letter I - Debugger

Next post: Amiga Machine Code Letter II - Part 1.

Mark Wrobel
Mark Wrobel
Team Lead, developer and mortgage expert