On program start, draw a diagonal line down and right at a 45-degree angle from the top-left pixel of the screen. Each time the 'm' key is pressed, alternate between showing the line and showing a blank screen.

Part 1: Start with RAM[0] = 1, toggle it between 1 and 0 every time 'm' is pressed.

Part 2: Actually draw the line.

The current key that's being pressed (if any) is stored in RAM[KBD] = RAM[0x6000], so we should check whether this is equal to 'm' = 109. So 'm' is currently be pressed if and only if RAM[KBD] = 109.

Pseudocode v1 (broken):
RAM[0] = 1;
while(true) {
  if (RAM[KBD] == 109) {
    // Option 1:
    // RAM[0] = (RAM[0] == 0) ? 1 : 0;
    // Option 2:
    // RAM[0] = RAM[0] ^ 1;
    // Option 3: Same thing but a little easier to write
    // in ASM.
    RAM[0] = 1 - RAM[0]
  }
}

Pseudocode v2:
RAM[0] = 1;
mpressed = 0;
while(true) {
  if (RAM[KBD] == 109) {
    if (mpressed == 0) {
      mpressed = 1;
      RAM[0] = 1 - RAM[0];
    }
  } else { 
      if (mpressed == 1) {
        mpressed = 0;
      }
  }
}

For the line drawing:

We want a pixel in the top-left
Then one down and to the right
Then one down and to the right
[...]

RAM[0x4000] = 0x1
RAM[0x4000 + 32 = 0x4020] = 0x2
RAM[0x4040] = 0x4
...
RAM[0x4000 + 15*0x20] = 0x8000
RAM[0x4000 + 16*0x20 + 0x1] = 0x1

Pseudocode v3:
drawline = 1;
mpressed = 0;
while(true) {
  // Check if m was just pressed or released
  if (RAM[KBD] == 109) {
    if (mpressed == 0) {
      mpressed = 1;
      drawline = 1 - drawline;
    }
  } else { 
      if (mpressed == 1) {
        mpressed = 0;
      }
  }
  
  // Draw the line if needed
  if (drawline == 1) {
    int addr = 0x4000;
    int i = 0;
    while (i < 16) {
      int towrite = 1;
      int j = 0;
      while (j < 16) {
        RAM[addr] = towrite;
        addr += 32;
        towrite *= 2;
        j++;
      }
      addr++;
      i++;
    }
  
  // Clear the screen if needed
  } else {
    int addr = 0x4000;
    while (addr < 0x6000) {
      RAM[addr] = 0;
      addr++;
    }
  }  
}
