Started 6809 Flutter Emulator

Date: Jan 11, 2025 / Updated: Jan 11, 2025

I started working on my 6809 emulator again, but instead of finishing my Java Swing version, I decided to start again using Dart and Flutter. The goal is to learn Dart and Flutter a little more in depth. I was worried about using Dart when I had to import a package just so I could output hex numbers, and I had to convert to a Flutter program in order to debug.

Otherwise Dart is proving to be nice to work with, and unit tests are on par with Java JUnits.

I implemented LD instructions for A,B,D,X,Y, and addressing modes immediate, direct, and extended. In order to get indexed working, I discovered there was about 220 variations! The first byte being LD, the second byte is a post byte. This byte describes if the value is a 5 bit two's complement signed number, 8 or 16 bit offset, an accumulator offset, etc, etc.

Folks on the Coco discord were nice enough to point me to tim lindner's 6309 Indexed Addressing Mode Post Byte, and pointed out that the Motorola 6809 and Hitachi 6309 Programming Reference (Darren Atkinson) had the following reference. Much nicer to decipher then an entire table as it groups things.

I was happy to discover that converting a negative two's complement number was easy. My lda -1,x converts to 1F, which is -1 in two's complement.

 0007 A61F             (          foo.asm):00026 [5]      lda -1,x

The entire routine to read the postbyte and decide what to load follows.

int load8Indexed() {  
  int postByte = memory[regs.pc.vinc()];  
  if(postByte&0x80 == 0) {  
    return load5bitOffset(postByte);  
  }  
  return 0;  
}  
int load5bitOffset(int postByte) {  
  int registerBits = (postByte&0x60) >> 5;  //grab bits 65 and shift down (0110 0000)  
  int offset = postByte&0x0f;   //grab bits 3210  
  if(postByte&0x10 == 0x10) {  
    offset = -(1+0xf-offset); // convert from twos complement  
  }  
  int address=0;  
  switch(registerBits) {  
    case 0: address=regs.x.value;  
    case 1: address=regs.y.value;  
    case 2: address=regs.u.value;  
    case 3: address=regs.s.value;  
  }  
  return memory[address+offset];  
}


Copyright © 2025, Lee Patterson