Amiga Copper Demo and Module Music Video

June 8, 2021

While researching a future post about the Copper functionality of the Amiga’s Agnus custom chip, I decided to really dig in and figure out how the Copper worked and how you would write some of the bare metal custom chip code. The process of making this video made me realize I need to do a few other posts before I can do one about the Copper, as there are a lot of prerequisites to understand it, at least at the level I am now able to understand it at. I also wanted to showcase a lot of the kind of music the Amiga was known for, module music made on music trackers. So here’s a nice, long video, with a real Amiga Copper demo (the kind I know I would make made back in the day, cartoon characters included, if I had these skills in the 90s!) and a lot of really great music to listen to.

How was it made?

  • The animation was done in Krita on Android. I used a pixel brush for the in-Amiga emulation to ensure all the pixels lined up with the 320x256 screen I was working on. The rest was done normally with regular brushes.
  • I used GIMP to convert the images destined for the Amiga into 16 color PNGs. The trick to keeping a consistent palette across all of the images was:
    • Convert one image to a 16 color image.
    • Swap around the colors in the index so that the color index to knock out via the Copper effect was index 0.
    • Create new layers to physically swap the color pixels in the image. You have the ability to select all of the pixels of a particular index, and then you can fill a new layer on top of the original to change the color.
    • After you’ve swapped one of these around, you can convert the remaining ones using the first image’s palette.
  • I used Personal Paint to convert the images from PNGs to IFFs.
  • I loaded all of the images, one by one, into memory banks in AMOS Professional. I loaded the first image again into a separate memory bank, but one that preserved screen resolution and palette, to simplify app initialization. I flip through these memory banks to animate Bamboo, as the IFF animation tools in AMOS Pro seem a bit broken.
  • I wrote a lot of AMOS BASIC, which I hadn’t done since 1997, and I referenced a lot of Amiga Copper, bitplane (Denise’s territory), and DMA examples. These ones helped out the most:
  • I ran all of this in FS-UAE, and captured it with vokoscreenNG.
  • I edited the video with Kdenlive.
  • I converted the music mod files using ffmpeg. It was the fastest way to convert a large number of modules at once for evaluation and movie use. I hope they sound OK!

Code & Assets

I put the AMOS code – the bundled .amos file, the .abk with the animation frames, and a .txt file with the code in plaintext – up on GitHub. The code is released under an MIT license, but the artwork is copyright by me, all rights reserved. I’m no expert at Copper coding, so if there are improvements (besides rewriting it in assembler. Learning 68K assembler is on my list of things to do for R1KR), I’d love to hear them! For it to run fast enough, I emulated a 68030 with JIT enabled in FS-UAE.

Music

All the music is either Public Domain or Creative Commons Attribution 3.0, and it all comes from The Mod Archive. Check out all of these artists' awesome work! There’s way more there than I could put into this 90 minute video.

  • The beat

    • Andreas Viklund
    • CC-BY 3.0
  • Frostbiter

    • Pip Malt
    • CC-BY 3.0
  • Super Dance

    • Katie Cadet
    • Public Domain
  • NeuroTransfer

    • JAM
    • Public Domain
  • Momentary Meditation

    • K. Jose
    • CC-BY 3.0
  • Computer Adventures Of Drozerix

    • Drozerix
    • Public Domain
  • Filterness

    • Katie Cadet
    • Public Domain
  • Additional Discomfort

    • Pip Malt
    • CC-BY 3.0
  • Gate 303 - demomix

    • Andreas Viklund
    • CC-BY 3.0
  • the Epic Chip

    • M0ns0n/Drozerix
    • Public Domain
  • Pretty Big Stench

    • Pip Malt
    • CC-BY 3.0
  • Harmony-PartyEdit

    • Andreas Viklund
    • CC-BY 3.0
  • Digital Rendezvous

    • Drozerix
    • Public Domain
  • Simple Chip Tune

    • JAM
    • Public Domain
  • Dangerous Radiation

    • JAM

    • Public Domain

  • Sound Effects

    All sound effects, except for Bamboo’s “heh” which was all me, come from Freesound, and are also either Public Domain or Creative Commons Attribution 3.0.

    What’s next?

    I’ll be converting some of my prior posts into short YouTube videos on the Rabbit with 1000 Repos channel, reworking them and updating them for a more visual medium. Once they’re done, I’ll post them here for viewing!

    Changelog

    • 2021-06-08: Initial post.

    Self-Portrait May 2021

    May 19, 2021

    I painted up a new Bamboo self-portait for May 2021!

    I’m still looking for the tools in Krita I enjoy the most. This one came together a lot faster than the prior one. I think I’m getting better at this.

    The NES: Playing Volleyball with Three of Your Friends

    May 17, 2021

    Playing a video game with a friend is great. You get to have fun and bond while you stop the aliens together or compete for the high score. But what if you have more than one friend? Weird to think about, right? And what if you wanted to play a bodacious new volleyball video game with more than one friend at the same time. Well, if you were gaming in the early 90s, this required some creative hardware and software tricks to make happen.

    My first Nintendo console was a Family Computer we got at a flea market. That had two controllers hard-wired into the console. Eventually that stopped working and, for some holiday, I got the NES Sports Pack, which included controllers and a multicart with Super Spike V’Ball and a soccer game, World Cup Soccer, that was actually part of a crazy huge game world in Japan? I did always wonder why the soccer game looked a lot like like River City Ransom

    Anyway, the coolest thing it came with was the NES Satellite, which allows you to use four (!) controllers instead of the normal two. It’s an infrared version of the wired Four Score multitap, so you put the 6 D-cell powered Satellite transmitter with the controllers plugged into it about 10 or 15 feet away from the NES and the signal is transmitted via infrared. I had an electronics kit when I was very young, and one of the experiments was turning a flashlight, photosensor, and speaker into an alarm, so I kinda knew how the infrared part worked. But I always wondered how the heck the four-controllers-instead-of-two thing worked.

    Bamboo puts his hand in front of an NES Satellite and his three friends are upset.

    Only block the infrared light on the Satellite if you're winning by a lot, or losing by a lot.

    The NES and its controllers communicate, much like how the C128 and 1571 floppy drives communicate, with a shift register between the controller and console. When you want to know the state of the first controller, you tell that controller to start reading that state of all of the buttons into the shift register of the controller by writing a 1 to a specific memory location in the NES, $4016. This is like lighting up a “START READING” sign inside the controller. Then, when you’re ready for the data, you tell the controller to stop capturing by writing a 0, which lights up a “Pack up your current state now!” sign. Imagine a set of 8 suitcases, one for each button, all in a line on the baggage carousel, and they’re being filled with the state of each button on the controller:

    Agents are putting together the suitcases to send along the conveyor belt.

    The type of shift register the NES has is a parallel in, serial out shift register, which means the state of all 8 buttons is captured at the same time, and is then squashed down into a byte to send across the wire, one bit at a time in order. If the button is down, the corresponding bit sent via the shift register is a 1. Otherwise, it’s a 0. The button state is always sent in this order: A, B, Select, Start, Up, Down, Left, Right.

    A diagram of a single controller plugged into the NES

    On the other end, the NES shifts the first bit off of the shift register and onto the same memory location you used to start the process, replacing the lowest bit in $4016 with the bit from the register. Once you read a byte of data from $4016, the next value is shifted off of the register into the lowest bit of $4016 again. When reading button press state, the rest of the bits in $4016 are unused and can be ignored.

    This process continues until you’ve done 8 reads to $4016, pulling all the suitcases off of the carousel to work with in your code. Continuing to read from that memory address will tell you if a controller is hooked up or not to that controller port, to know if the data is trustworthy.

    A luggage agent is taking suitcases off the conveyor belt in order. There's a sign indicating these suitcases are from a rear controller.

    Since there are two controllers, there are two shift registers and two memory areas where data is loaded from. For most games, this is all you need. But you want to bump-set-spike that volleyball with three of your rad friends. How does the NES Satellite make four controllers work?

    The Four Score and Satellite connect the four controller shift registers to its own hardware, and the Satellite has its own shift registers that hook up to the NES controller ports via the infrared receiver. Your game asks for controller data the same way, by writing a 1, then a 0, to $4016, and the Satellite will pass this commmand along to the controllers plugged into ports 1 and 3 on the Satellite so they can start collecting button presses. The the game will start reading from the memory location like before, which is now being populated by the Satellite.

    A diagram of two controllers plugged into a Satellite.

    Instead of stopping at sending 8 bits though, the Satellite sends, in the case of the first controller port, the first 8 bits for the first controller, then the next 8 bits for the third controller. Then, it sends a magic 8 bit code (10 in this case) to let the game know that this data is coming from a Four Score or Satellite and that the four player mode is enabled. You can use these codes to detect if there is a Four Score or Satellite plugged in, allowing you to enable menu options to start 3- or 4-player games. Without a Four Score plugged in, for example, Super Spike V’Ball will show the 2 vs. 1 or 2 vs. 2 options in the main menu, but you can’t select them.

    A luggage agent is asking a volleyball player who is overflowing with suitcases if they know how to handle all of the suitcases.

    There were plenty of games made that supported the Four Score and Satellite, and this style of multitap continued on with the PC Engine and SNES. There were even directions in some later Amiga games for building a parallel port controller multitap from a printer cable for adding two more controller ports! Eventually, Bluetooth & other wireless connectivity and USB eliminated the need for what was essentially a clever hack on top of the existing controller systems to expand gameplay to more than the few controller ports early game consoles and computers had.

    Now avoid those campfires and set up for a power alley, and watch the line shot! Those are volleyball terms!

    Changelog

    • 2021-05-17: Initial post

    Self-Portrait April 2021

    April 22, 2021

    I chalked up a new Bamboo self-portait for April 2021!

    April was a rough month and a lot of stuff got in my way when it came to doing art and writing for the site. I think I took the reference photo early in April but only now had the time and availability to finish it. New self portrait sometime in May!

    The Commodore 64 and 1541 Floppy Drive: The Micromanaging Bosses

    April 21, 2021
    Bamboo waving a 5.25 inch floppy disk in the air.

    Ever have a micromanaging boss? Someone who just didn’t think you could do the job right and insisted on doing it all for you? Like, even if you were screwing up in the past, but you worked real hard and got your act together, they would still watch you like a hawk ‘cause they couldn’t trust you? Well, that’s kinda sorta what happened to the data connection between the Commodore 64 computer and the Commodore 1541 floppy drive.

    Commodore built a couple of different floppy drives for their early computers, and it’s in the 5.25" 1540 floppy disk drive, made for the VIC-20, the C64’s predecessor, where all the trouble started. The 1540 has two processors – a 6502 that handle talking to the computer and understanding the files on the disk, and a 6504 that handle spinning the disk and moving the read/write head. They send data to and from the computer using a pair of MOS 6522 Versatile Interface Adapter (VIA) chips, one in the computer and one in the drive. These chips work together to transfer data to and from the CPUs in each device.

    One of the big reasons for using a 6522 VIA in the VIC-20 was because of a skill it has called the shift register. A register is an area of the CPU it has immediate access to perform operations on, and it’s the fastest thing it can manipulate. When you read a byte of data (the word size of the 6502) off the floppy drive, the CPU can put it into this shift register of the 6522 and then shift a bit of it at a time to another source, like the 6522 VIA in your VIC-20. All the VIC-20 has to do is signal to the drive that it wants the next byte once you’ve received 8 bits. This is very fast since this action is hard-wired into the 6522s, and you can hook these registers up to each other. The CPUs have timers, like drums that they’re beating, so that they and their respective 6522s stay in sync with each other, putting bytes on and taking bytes off their shift registers for future computing use at the right times. It’s a clever setup that just works.

    Two cat managers drumming along keeping time while two muskrat workers are moving bits along on a conveyor belt.

    Well…it would “just work”, if the MOS6522 VIA didn’t have a bug in it. Occasionally, that signaling between the VIC-20’s and 1540’s shift registers would arrive a little too close to the drumbeat timer the respective CPU had with their 6522. If that happens, the 6522 would get confused, and ignore one of the bits they were shifting.

    A worker turns to the manager, who is drumming, and drops the bit.

    This is, of course, not good. The VIC-20 doesn’t know they’re missing a bit, the 1540 doesn’t know that they dropped a bit, and crashes would occur.

    Now, other computers of the era use 6522s for communications with peripherals. The first Macintosh has a 6522 to accept keyboard input, but since the Mac initiates communication with the keyboard, rather than letting the keyboard stream everything over unchecked, it knows if it receives bad data and can re-request it. Not so with Commodore floppy drives.

    Since this hardware-based fast transfer of data couldn’t be trusted, Commodore engineers had to write software that would require the CPUs to take over the jobs of the shift registers, extracting data one bit at a time from the drive and verifying each one. Writing software the CPU executes to handle these sorts of transfers manually instead of letting the hardware handle it is called bit-banging, which–

    Bamboo telling us to keep it safe for work

    –get your mind out of the gutter, Bamboo. Anyway, the VIC-20 CPU now has to take time out of its busy schedule to coordinate with the floppy drive CPU to gather every bit, one at a time, and assemble them into a byte themselves, acting as a very micromanage-y manager over each 6522:

    The cat managers are telling the muskrats to stay focused as the muskrats manually push one bit at a time across a decommissioned conveyor belt.

    When the Commodore 64 and 1541 drives came out, the buggy 6522 was replaced with the 6526 CIA, which did not have the shift register issue. Theoretically, these two chips could have been hooked together as intended in the VIC-20 days. But, to ensure that the new 1541s could be used on existing VIC-20s, the C64 and 1541 drive kept using the inefficient CPU-driven bit-banging to send data back and forth. It was made even worse when the video hardware on the C64, the VIC-II chip (the VIC-20 was named after the first generation of the chip), needed to completely halt the CPU many times a second to handle screen drawing. For this reason, the drive was purposely slowed down even more so it would work in the C64 reliably. So a bad situation got even worse!

    Two muskrats complaining about being overqualified for the job now and about Vic.

    The combo C64 and the 1541 were slow. Like, really really slow. The inefficient management of the bit-banging protocol and fighting VIC-II for CPU time made floppy disk usage awful, esepcially compared to Commodore’s competitors. But, just like at work, a change of management can make a world of difference for the workers. And that’s where fast loader software and cartridges come in.

    Except for things written in BASIC, all the code in the C64 is 6502 machine language code and lives in unprotected memory. It’s easy to read and modify any code at any location in the computer, including the code that controls floppy disk communication. Since the 1541 also has a 6502 CPU and RAM, all the code there can be read and modified, too. The simplest way to make the connection between computer and floppy drive faster is to replace the code that runs the bit-banging protocol between the devices. There were a bunch of different cartridges sold, usually by game manufacturers like Epyx and Cinemaware, that would modify the code in the C64 and 1541 to replace the inefficient bit-banging managers with much more efficient, but still bit-banging, ones. It wasn’t as fast as hooking up the shift registers, but it was, even with the most simplistic, naive code, at least 5 times faster than the original Commodore code.

    Two coyotes are cheering on two muskrats who are passing entire bytes at a time along the conveyor belt. Everyone is in winter sports gear.

    Eventually, the shift registers were hooked up between the Commodore 128 and the 1570/1571 drives (which also had 6526s), and fast loaders weren’t as necessary for performant disk access. The CPU could spend its time doing other things, and no more micromanaging managers were needed to ensure the safety of the data coming off the disk.

    Changelog

    • 2021-04-21: Initial post

    The NES: The Game State That Lasted Seven Days

    March 28, 2021

    Bamboo renting Final Fantasy, declaring he will beat it in seven days.

    Before the first NES game with battery backup, The Legend of Zelda, came out, you had two options:

    • Either you beat the whole game in one sitting
    • Or you got these weird passcodes you had to type in to restore where you were.

    Old-school Metroid players knew of JUSTIN BAILEY, the amazingly random password that gave you all sorts of crazy gear. Mega Man had you put dots in spots to get your gear back. These both worked by recreating the state of the game.

    When a game (or any computer program) runs, it interacts with the outside world. You move a character, an AI shoots at you, you drink a healing potion. These decisions change the program state. Every program that does anything useful has state. This state is stored in the NES’s powered-on RAM while you play, and is continuously updated. On the NES, this data would be in the 2K of RAM available to games. But when you power down the NES, the state goes away with it. The trick is finding a way to preserve the game state so you can keep playing from where you left off.

    With a game like Mega Man 3, the state is very simple, and it’s easy to store and recreate from a few dots on the screen. All you need to know is:

    • What bosses were defeated
    • How many energy tanks you had

    A password for Mega Man 3 for being Magnet Man with 0 E-Tanks

    Need a password for having defeated Magnet Man with 0 Energy Tanks? Well here it is. I got it especially for you. Top Man is next if you go by that one copy of Nintendo Power I still own.

    With a game like Final Fantasy, though, there’s no way all of the game state can be stored in a simple password:

    • Every warrior has a name and individual stats, gear, and spells
    • You have different items and counts of items
    • You’ve unlocked different parts of the game

    Bamboo, dressed as a Fighter, not looking forward to entering in a grid password to restore his saved game.

    This 38x38 grid of 2 bit (3 different dots + empty) squares will give you just over 768 bytes of data, enough to represent the important parts of the Final Fantasy God Mode save file.

    The memory magician, as a red mage, casting a spell on a RAM chip

    Final Fantasy used a common memory magician – I mean, memory management chip – named the MMC1. The MMC1 allowed for storing game state on a RAM chip on the cartridge board that was powered by a button battery.

    The code of the game could talk to the memory magician on the board and let it know it wanted to read and write to the cartridge’s RAM, treating it as part of one of the PRG banks loaded and saved in the upper 32K of the NES’s RAM. Normal RAM chips typically need constant electricity to remember what was stored there (unlike EEPROMs – Flash memory is a type of EEPROM used to make SSDs). When the game was in the NES and powered on, these on-board RAM chips were powered by the console. When the power cut out because you held in the RESET button while powering off the NES (or you had to shut it off quick ‘cause it was time for dinner and Mom had already called you, like, ten times), the battery on the cartridge board took over and kept the onboard RAM powered up just enough to preserve the game state.

    There were problems with this, of course. Batteries could die, and couldn’t be user-replaced easily. The hardware on the cartridge might not handle the transition from NES-power to battery-power well, corrupting the fragile state. You might forget to hold down RESET while powering off the system (or be forced to not do so because of dinner) and the CPU continued to execute, corrupting your game. But for most games, and most of the time, it worked. The battery backed-up RAM allowed players to play much larger games, paving the way for truly large RPGs like Final Fantasy and Dragon Warrior, adventure games and ARPGs like The Legend of Zelda and Crystalis, and in-depth simulation games like Bandit Kings of Ancient China.

    Bamboo returning Final Fantasy, not having beaten it in the 7 day rental period.

    And yes, I did try to beat Final Fantasy this way twice, in two separate 7 day rental periods, and could never pull it off fast enough.

    Changelog

    • 2021-03-28: Initial Post