📅July 31st, 2020
See a video of it here: https://www.youtube.com/watch?v=lmg9sN9FO-w
Also on Twitter: https://twitter.com/clandrew__/status/1288941082202390533
As a fun thing to do for a few days I made this demo, for background I have programmed on Apple II in the past but in higher-level ways, through BASIC and Logo. The idea here was to write something in 6502 so that I could learn more about the platform. Prior to this I had some background debugging and doing small code patchings in SNES's 65816 (similar to 6502) and how to use an Apple II computer but no experience at all writing 6502 for it.
I got a book "Assembly Lines" by Roger Wagner which was a lot of help plus "Inside the Apple IIe" by Gary Little. And also a bigger book of opcodes lent to me by a friend.
Things that were easy
- Trancoding from a .PNG image file on Windows to indexed image data compatible with LORES memory layout. I wrote this command line tool which inputs an image file on Windows and outputs a bunch of data directives for the LORES compatible image data. I referred to the "Inside the Apple IIe" book to source out what the format is. The tool uses WIC to open the image and shoves a bunch of things around. This took like 20min. The code is here
https://github.com/clandrew/demoII/blob/master/ImageTranscoder/ImageTranscoder.cpp
- Testing on real actual hardware. What I mean is, I thought this would shake loose a bunch of problems. Especially around sound. There was conflicting information as to how you're supposed to access $C030 to sound the speaker. If an opcode technically corresponds to *two* accesses of the I/O port instead of one it could cancel out so no sound. This is an area where emulator would likely be more forgiving. And before you think "just copy from some sample code", various sample code and documentation contradicted each other. In the end I picked absolute LDA and it worked.
- Modern IDE Now, the bulk of the code was written using Merlin's interface on the actual Apple II. It's actually pretty good and I thought it was fine. Once in a while, whenever there was a big messy refactor though I copied the code out of the Apple II data disk and into a Windows filesystem text file because of course that's a thing. And quickly do the reverse, too. What a time to be alive.
- Debugging. The debugger built into the emulator is the most luxurious type of pampering. This is the reason I don't know what it is to work or to suffer. You can set breakpoints, conditional breakpoints, view memory and disassembly of what's executing. From talking to people, "Back in the day" you would debug by breaking into the Monitor or not at all. There are hobbyists writing Apple II code today though and I am pretty sure they all use tools like this. I feel okay with this hybrid way of doing things.
Things that were not easy
- Correct sound. Sound on most Apple II models is emitted in a weird way. You touch a memory-mapped I/O port- and how *frequently* you access the port (read or write) changes the pitch of the sound. A touch followed by 50 NOPs is a different pitch from a touch followed by 100 NOPs. And of course, you should put all of that in a loop or else the sound will be so quick it's hardly observable. You need very careful counting of clock cycles to play different tones of uniform duration. Yes, calculation involving clock cycles to figure out how to emit notes of *different tones* but *equal length*
- "Holes" and nonlinearity of graphics memory-map. Say you have some image data. It is stored with the top left byte first, and the bottom right byte last. To display it you might think, "just do a memcopy!". No no no. In graphics memory rows of pixels are stored in all jumbled up order. Even if you store your image data in that same jumbled-up order, there are "holes" in the range which you are not supposed to write to. Because I wanted to keep image positionings flexible for future use I had my source image data stored in straightforward order and copied each pair of rows based on a table of offsets. This wasn't the absolute worst just fussy.
- Branch distance limit. Because only one signed byte specifies the offset you can't branch anywhere too far away. To get around this, you branch to an intermediate place which jumps to the final place but also need to take care that the jump isn't accidentally taken by something else.
- Asymmetry of how you're allowed to use registers X and Y. For example, when you use indirect-indexed-load with X, it's pre-indexed but if you do it with Y it's post-indexed. Merlin's semantics between these two is ever so slightly different it's easy to miss and this was the root cause of an annoying bug I fixed Tuesday.
I scoped this project to LORES only so that it would be feasible and also a way to get comfortable with environment, instruction set and functions specific to this computer. The things I've heard about HIRES is that it's fewer colors, higher res, and more gnarly to work with, could also be good to check out at some point.
Some highlights
<-- Graphics bug turned a bit a e s t h e t i c.
The root cause of this was the image loading code would scramble the input image offset passed to it. I was testing out scrolling of images (as a possible future thing to add), so the corruption happened when you hit the "down" key. Scrolling would call the image loading code again with the scrambled registers, loading an image from an incorrect place and changing which incorrect place every time.

Debugger built into the emulator. does you a favor and gives memory-mapped registers helpful human readable names (e.g., SPKR, called CHIRP in my code) rather than raw offsets. This was how I sometimes found out that I was actually using some areas of memory which seem general purpose but are not really.

For the music, I sketched it out a single-channel MIDI in Noteworthy Composer and then started testing different tones to find what ratio of I/O port setting + busy waits would produce which notes. I added the frequencies as text in the staff at the bottom.
You have this problem of "how to emit tones of different pitch but the same duration".
This problem will be obvious to you if you've programmed Apple II like this before, but I'll say it in case: to emit a tone on Apple II you touch a memory-mapped IO port. How often you touch it determines what tone it is. "Touch" here means read or write.
You're going to want to touch the port in a loop padded with a bunch of sleeps. To get a lower note, add more sleeps. To get a higher note, use less sleeps*. Easy enough.
*For sleeps it doesn't literally have to be a sleep, it could be a NOP or anything that takes up time. In my sound code the busy wait is "decrement a counter, branch conditional". You could expand the gamut of what sounds you can emit by adding an actual NOP or two.
What if you want to emit two different tones which both have the same duration? If you change the number of sleeps, you change the duration. How fussy. Fortunately, we own the code for touching the port. So I fix this by counting the number of clock cycles it takes to emit a baseline tone, and solving for the number of sleeps needed to emit a different tone with the same duration.
My code to emit sound looks like
* ;CLOCK
A6 07 TONE LDX $07 ;3
A4 06 DUR LDY $06 ;3
AD 30 C0 LDA CHIRP ;4
88 PCH DEY ;2
D0 FD BNE PCH ;Branch taken: 3. Not taken: 2
CA DEX ;2
D0 F5 BNE DUR ;Branch taken: 3. Not taken: 2
60 RTS ;6
See there is a routine called TONE, and two loops labeled DUR and PCH.
PCH is an inner loop.
DUR is an outer loop.
I added comments describing how many clock cycles each line will take. For branches the number of clock cycles depends on whether the branch is taken.
Example of usage of TONE- (this part doesn't vary between pitch
or duration so clocks are not taken into account)
A9 BC LDA #188
85 06 STA $06
A9 6A LDA #106
85 07 STA $07
20 26 66 JSR TONE
60 RTS
TONE is subroutine with two arguments: pitch and duration, nicknamed pch and dur below.
TONE takes some number of clock cycles to execute, nicknamed clk below.
We can calculate clk as a function of pch and dur.
Looking at the implementation of TONE, the initial load and return don't vary so they weren't taken into consideration. But we can go line by line and calculate how many clock cycles the interesting parts will be
clk = 0;
clk += dur * 3; // DUR LDY $06
clk += dur * 4; // LDA CHIRP
clk += pch * dur * 2; // PCH DEY
clk += (pch * dur * 3) - (dur * 3); // BNE PCH (branch taken)
clk += dur * 2; // BNE PCH (branch not taken)
clk += dur * 2; // DEX
clk += (dur * 3) - 3; // BNE DUR (branch taken)
clk += 2; // BNE DUR (branch not taken)
which simplifies down to
clk = dur * (11 + 5 * pch) - 1;
rearranged to solve for dur, you get
clk + 1 = dur * (11 + 5 * pch)
dur = (clk + 1) / (11 + 5 * pch)
This way I got what value of 'dur' you need for each pitch to use to get about the same target cycle count as the middle pitch, 138 with duration 144 (picked arbitrarily).
If you are pro you might factor non-sound code (e.g., the loading of graphics images) into your calculations.. fortunately here the amount of time to load graphics and on other control flow ended up being negligible so it didn't end up mattering

And of course, a good thumbnail is about setting the right expectation.

Source code posted here: https://github.com/clandrew/demoII/blob/master/T.GR.asm
📅June 2nd, 2020
Finished Arcana (SNES).
Play as Rooks, an orphaned magic card user who needs to stop an evil empress vying to take over the kingdom. Rooks also wants to live up to his late father's legacy.
Turn-based JRPG, Wizardry-like, with "cards" being a prominent visual motif and somewhat gameplay motif. Unique qualities: no backtracking, death of anyone in your party == game over
The use of cards in the gameplay would lead you to think the game has a combat system way more evolved than the old "Fight Magic Item Flee". It does not.
There is a rock-paper-scissors-style elemental system. The game is balanced such that you can ignore it. There are also four pokemon ("Spirits") which act like party members except disposable and only their magic is any good.
Pop quiz: magic spell called "Attribute 6". What does it do, take a guess? Bonus: how it is different from Attribute 5.
I think people might not play this game any more because of the enemy system. What enemy system? Random encounters. How many? A lot. It has one of the worst grinds. Find enclosed: random encounters every two steps in the map, or on simply a 90 degree turn. If not for the in-game map it would have been a big problem. Although there's items and spells to hightail it out of a dungeon, you always enter a dungeon from the very beginning.
Lack of checkpointing is a problem for one of the largest areas called "Stavery Tower", a twelve-floor maze. You can't save while in a dungeon, not even a save-to-be-deleted-on-resume (those are not popular on SNES platform anyway). So you will need to book one to three hours per game session. Alternatively, you can leave your SNES on and hope there isn't a power outage, or use a piece of technology which rhymes with asdflemulator.
Still, the first 5 minutes and the last 30 minutes were Awesome. This game has a great soundtrack and visual style with a lot of character. The final boss concept is extremely cool. This game, you can tell what they were going for.
📅May 29th, 2020
The portraits you make on IR-7000 are not merely for spicing up your address book. They are integrated with a "game" and that game is called Brain Drain.
In Brain Drain you choose a portrait to play as, and face off against a different portrait using psychic abilities. It is a bit thin on gameplay and soundtrack but it is kind of fun.
Eons ago I wanted to see if the outcomes of the game were pre-determined based on the character features or if there is some RNG. So I cloned one character to see. It turns out, there is some RNG.

📅May 27th, 2020
The mid-late 90s personal organizer. The big companies making them were Sharp and Casio, although there were a lot of other ones.
I still have mine, the IR-7000, made by Sega. Looks like this:

Still works turns out.
Like the standard organizer it flipped open and had a QWERTY keyboard. It could store notes, addresses, do calculator functions, time zone calculations, set an alarm and show you a calendar. Plus, a hilarious "human portrait" maker along with a simple game you can play with the portraits.
If two people had IR-7000, you could use its infra-red communication to exchange messages, but I never came across someone who also had this organizer. The industry was really fragmented toward lots of different organizers and everyone seemed to have a different one.
The modern equivalent today would be something between a cellphone or tablet. Cellphone and tablet subsume all of the functionality that these organizers had, but in much more general-purpose ways with fuller software stacks. I can understand why these fuller software stacks are desirable yet in my heart I'm always keeping a space for the long battery life and reliability of this specialized tool for specific things.
📅May 22nd, 2020
A response to this: "What were the five most important video games to you throughout your youth/teen years? No curating to look cool/interesting please"
1. Lagoon (SNES)
Comment: The first RPG I played. The environments and sense of world-building were a lot deeper than the other games I was familiar with, so it was easy to get really invested. The ultra-small hitboxes and the lack of user-friendliness I wrote off as "the game is hard" not "the game is flawed", so I spent effort getting better at the action mechanic. Nowadays the time I spend on Lagoon is part nostalgia, part meme-ery. It affected the ways I perceive other games then and today and led into ARPGs like Souls.
I've been maintaining a fan site for Lagoon for 13 years.
2. Speedway Classic (Apple II)
Comment: The game had this really cool looking 3D effect and a memorable intro. It was my go-to game on this platform narrowly beating out Lemonade Stand. Since I coded on this platform it was helpful to see the connection from code --> possible program.
3. Final Fantasy 3 or 6 (SNES)
Comment: This is a very normie pick. You know I'm taking the no-curating seriously.
This game for me is tied up with a) interest in video game characters, since before that I didn't play many heavily character-based games) first experiences in PC usage when trying to get more content for it.
I first played it around 1995 and wanted more content about it (besides a magazine article) but it was hard to find any. I didn't have a lot of experience using PCs or the internet but it was worth a try.
The best time was when my parents took me to a computer exhibit at the <city name> Science Center, they had a bunch of computers hooked up with internet access. It was a bit rough at the start because it was not like the Apple IIc (at home) or the IIe (at school) and the GUI/mouse/internet browser was a lot different, from what I recall the demo machines were Windows 95 with Netscape Navigator. But I got to use it to find a lot of cool things- secrets, strategies and so on.
4. Dynasty Warriors 4 (PS2)
Comment: This was when I was a teenager. Since I was under a lot of stress in high school, overbooked with way too many clubs + part time job, it was a good de-stresser.
5. Tekken 2 (Arcade)
Comment: Noise, dirty floors, cigarette smoke, frantically pushing the button + kicking the machine to un-jam your quarter. There were a couple dive-y arcades I used to go to. I used to always play as Angel on 2, Yoshimitsu on others, and got decent at those but didn't know any other moveset. Nowadays I can do some combos with Paul.
Honorable mention: Fatty Bear's Birthday Surprise, a point-and-click game for kids. The game is just so weird yet full of cool things. First seen at my daycare. I later got the CD from somewhere when I was in high school because I was nostalgic then too.


📅February 9th, 2020
They are so uncommon let's take a second to appreciate SNES games with functional loading screens.
Game: Civilization 1
Loading time: ~40 seconds
Purpose: When you create a new game. It is procedurally generating the terrain of the map, placing the other civilizations you're playing with. Rather than a fixed map, it gets randomly generated each time plus the algorithm is customizeable to include different kinds of climates and features. The longest load time I have seen on this platform.
A video: https://youtu.be/oWtVe2qm7_w?t=129 (not mine, random search off youtube)
Game: Romance of the Three Kingdoms IV: Wall of Fire
Loading time: 2 or 3 seconds
Purpose: When you create a new game. Procedurally generating what commander has what resource allocations, which officers are where. Although the game comes with a fixed set of "scenarios", you can create your own commander and/or officers and choose who to control. I believe this, plus the difficulty level affects where the game places things and there are too many combinations to pre-compute them.
Game: Another World (also called, Out of this World)
Loading time: ~10 seconds
Purpose: Transitioning out of a simple menu, into the game
This game is, in a word, ambitious. Big, lush backgrounds with lots of things animating. Nothing looks like 'sprites'; they look like 2D vector graphics rasterized to low resolution to be honest.
This game was originally for Amiga and ported to SNES. The graphics have a unique style which unfortunately doesn't fit well to SNES technical constraints, which tend to involve either conventional 2D graphics modes with heavily re-used sprites, or just Mode 7-- neither of which fit this game well. Now that's not to say it can't work. Take, for example, the backgrounds of Super Mario RPG or Wonder Project J. You can make smart judgments about when to re-use sprites and try to hide them among the other elements. Of course, those games were designed from the ground-up for SNES. For this game, conversion to sprites would be an after-thought with the port. The sheer amount of graphics this game has is very large and scenes are organized in ways that are hard to break down into patterned elements.
While I don't tend to like this type of game- the latency of controls is so slow and loose, for one-- I respect its commitment to the unique art style. Given everything this game has going on, the loading screen is not frivolous.
Game: Sim City
Loading time: ~12 seconds
Purpose: When previewing the terrain on which to build your city- there are 1000 terrains (e.g., random seeds). Note that the load time is NOT just for creating a game with the level- it's to let you view a small 120x100 image. This, plus the instantaneous "OK" button tells us two things. First, there was not enough space on the cart to store 1000 of these images. Second, unpacking the preview image is about the same as unpacking the full map. While I think all of this is okay, they could have done with fewer better-optimized seeds. Fortunately the instruction manual has a couple pages of previews of maps which you can flip through quickly.
Game: Batman Forever
Loading time: ~5 seconds
Purpose: Transitioning out of cutscene into gameplay. Likely to be graphics-related. There are big, detailed sprites with lots of frames of animation.
Although there's an explanation for a load screen, it may not have been completely necessary. At 24Mbit, the cart is not that small; it's very likely the graphics could fit without super aggressive compression schemes. Some contributing factors to the need for load time may have been 1) the fact that this game is a port, and there wasn't time to optimize for any particular platform, and 2) these flashy 3D wireframe-map montage scenes, which would require different types of data and loader code.
Although this game gets a bad rap I respect its live-action-to-low-res-low-color Mortal Kombat aesthetic.
Maybe others I haven't encountered yet.
See, a couple big things affecting our modern conception of loading screens are optical media and network latency's failure to keep up with increasing size of game payloads. Computationally, modern computers have advanced a lot to the point where it is rare to see games spinning on procedural content like this, but it is common to spend a lot of time copying game assets from an optical medium to faster local solid-state storage, or downloading game assets from the internet.
There have been some modern efforts to curb load times. For example the Nintendo Switch had a return to a faster-than-optical-disk game media. You know, a cartridge. However, many Nintendo Switch games- non-procedural, fixed-level action games do have loading screens- screens which would have been unacceptable in 1995 but are acceptable now since we are used to them.
📅February 8th, 2020
Earth, who wore it better?
left: E. V. O. (SNES) right: Civilization (SNES)

📅February 8th, 2020
Finished Donkey Kong Country 2: Diddy's Kong Quest. This was a co-operative gameplay I finished with a couple friends as a follow up to our completion of Donkey Kong Country 1.
Completion time: about a year, since we played in small increments once in a while.
Game is longer and a lot spicier than 1. Some levels gave us a very hard time. Yeah I am a big fan of the minecart autoscroller.
Time and time again I am really impressed by how much graphics can be fit on a SNES cart. The levels are all full of lush, irregularly-shaped (non-tiled-looking) elements without a lot of repetition; sprites are big with lots of animations, lots of frames in each one; backgrounds have a lot of variety. At the same time, it also doesn't appear they got too fancy with storage of graphics. I looked at the ROM and could spot at least some 4bpp graphics data stored plain, uncompressed. They just used a big cartridge-- 32mb, big for this console.
The technical high points for this game are offline rather than online of course. These are pre-rendered 3D models rendered with Silicon Graphics software, likely on CPU, baked into a bunch of 2D sprites. Everyone likes this. I can't think of a single fourth-console-generation game which does this and looks bad. More games would have surely done it if it wasn't so expensive back then, in terms of money.
Only criticism is I was disappointed with the final boss fight. The fight from DKC1 established a pretty high bar, to be fair- it had that cool "fake credits then surprise there's more". Not saying DKC2 had to replicate that, but maybe the final boss could have had something else cool. Nope. You fight King K Rool on a pirate ship. He throws projectiles. Pretty standard stuff. Maybe they thought no one would get far enough to see that, due to Windy H̶e̶l̶l̶ Well.

📅September 16th, 2019
Total play time = 2 years, 156 days, 20 hours, 36 minutes, 39 seconds
Couple friends and I started playing back in April 2017. The progress isn't deliberately slow, it's just that we playing a half-hour or an hour here and there, once in a while and it's a proper full-length RPG. Furthermore we made a best effort to play it spoiler-free with as minimal outside help as possible.
I never beat this game before. SoM is in the category of "played as a child by repeated rental, wanted to own, couldn't get a copy".
It is hard nowadays imagining "not being able to purchase something" but was the situation here. If no video or toy store in our city had it then out of luck. There were also toy catalogs where you can phone or mail in an order, but they weren't a whole lot better in terms of the video game selection. The one place I could find that had Secret of Mana had it for rent. So I rented it repeatedly. I still had to take it back at certain intervals and some jerkface wiped my save. After that I became demoralized and moved on to playing something else (Uncharted Waters 2)
Fast-forward to today and I have every game in the world. This one has a lot of critical acclaim, and still has some love today (it got a remake last year), it deserves playthough to the end.
Originally I thought I'd move onto the remake after finishing this, but after reading some reviews, maybe not 🙁 It's just as well, initially I was kind of turned off by the graphics. When early gameplay came out I recall telling people it looked Bad. Like some free-to-play MMO from ~2006. It reminded me of Audition Online. I don't know what's up with the art direction. Apparently there are problems with the soundtrack and gameplay also... How did they mess this up? I may someday play it anyway but give it a while.
This game had a lot of positive qualities, it deserves to be on all those top-10 lists.
- The soundtrack is very strong
- Large sprites with nice animations
- Many cool concepts for bosses, large enemy artworks
- Willingness to make a three-player SNES game represents a lot of technical initiative
The one thing that was almost a problem- it is borderline on the "turn based games disguised as action games" genre.
You know. Practically very MMORPG does this. The combat works like: you and the enemy can both be freely positioned in the world, and can attach each other, but the attacks always land regardless of how you are positioned. Why have the positioning mechanic at all, then? Why not just have a menu? If they shoot an arrow or something it's not like you can move out of the way. I know why they do it in MMOs, but I'm less on board in any locally-played action game.
I suppose this bothers me because it encourages you to waste brain cells in combat trying to move around the map when you might as well just stand there.
Fortunately, this game doesn't 100% do that, it's only for certain attacks. Some experimenting helped figure this out. For other ones, you can move out of the way, sometimes outside of a hitbox that seems rather big.
On a whole I loved playing this game, and getting the chance to play it co-operatively even though it's long after the fact.

📅September 5th, 2019
Finished J.R.R. Tolkien's Lord of the Rings (SNES)
This is an action-RPG based on the book series, pre-Peter Jackson movie IP.
This game has some cool moments and good atmosphere and potential to be good. Still, it was held back by many technical problems. This game ended up being a rabbit hole into something else.
A couple weeks ago, I cleared the last boss, the Balrog using the full party (minus Gandalf, since having him in your party prevents you from beating the boss; also Boromir is E_NOTIMPL) and finished the game but didn't get such a good ending because Merry and Pippin died in the boss fight. They die really easily.
So last Saturday, I booted up the game with the intention to resume at the boss fight, attempt it again and keep them alive.
However the password I had written down was rejected by the game. I swear to goodness I wrote it down correctly. I went upstairs to my computer, reproduced the situation with an emulator. It turns out, the game will indeed give you invalid passwords and that's what happened here. So I went about trying to figure out how to "fix" my password.
The password system itself involves encoding a bunch of the game state in a certain way with a checksum. This game is a bit unusual in that there are no saves to the cartridge, it hashes together literally all the state into a 48-character-long password. It took a bit of effort, but I figured out how to derive the password. From there, how to un-glitch my password and preserve the progress I had (items, character stats, door open+close state) while letting it be accepted by the game. With this, I was able to re-attempt the boss fight and get the good ending!
After trying many different passwords looking for patterns, I cracked the password algorithm. It was not too much more work to put it into a program in case other people run into the same issues.
I posted the program to Github https://github.com/clandrew/lotrpwcheck/ .
As for the ending itself it was pretty cool, there is a scene where you meet Galadriel and she shows you the mirror. Although they never released a Vol II for SNES, I can see the next one picking up where this one left off.










































