Invader

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
walter
Site Admin
Posts: 160
Joined: 13 May 2018, 08:00

Re: Invader

Post by walter »

Again, a very nice piece of software!

I hate it when the last invader goes so incredibly fast, I need to underclock the Gigatron to get a decent score. :lol:

I've put a version of the emulator with an Invader-only ROM online as well: https://gigatron.io/emu-invader/
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 »

For the last invader, left to right is 3 pixels per frame, right to left is 2 pixels per frame, (just like the original), so it's usually a little easier to wait for right to left.

Under-clocking/using mode 0: I see you went to the Kirk-Kobayashi-Maru school for lessons :)
delpozzo
Posts: 38
Joined: 03 Jun 2020, 18:47

Re: Invader

Post by delpozzo »

Fantastic job at67, the game runs beautifully on my Gigatron! (I'm currently running the latest DEVROM)
I hate it when the last invader goes so incredibly fast, I need to underclock the Gigatron to get a decent score.
I literally get anxiety when it comes down to the last invader :lol:
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 »

delpozzo wrote: 16 Jul 2020, 18:26 I literally get anxiety when it comes down to the last invader :lol:
Then my job here is done ;)
bmwtcu
Posts: 145
Joined: 01 Nov 2018, 12:02

Re: Invader

Post by bmwtcu »

Amazing how much you squeezed out of the Gigatron! I spent more time than I care to admit playing this today. I did notice an anomaly playing with keyboard that I'm trying to make sense of. If you fire using the enter key, the player shifts a little to the right with each shot, which doesn't happen if you use the controller to fire. I also noticed the same behavior with the online emulator. The weird thing is that I saw similar behavior in blaknite's puzzle game when you use the enter key to rotate blocks. Is this a known limitation of Babelfish? I haven't seen anyone else talk about it. Regular use of the enter key in basic seems fine.
blaknite
Posts: 22
Joined: 18 Jun 2020, 01:10
Contact:

Re: Invader

Post by blaknite »

bmwtcu wrote: 03 Aug 2020, 07:44 Amazing how much you squeezed out of the Gigatron! I spent more time than I care to admit playing this today. I did notice an anomaly playing with keyboard that I'm trying to make sense of. If you fire using the enter key, the player shifts a little to the right with each shot, which doesn't happen if you use the controller to fire. I also noticed the same behavior with the online emulator. The weird thing is that I saw similar behavior in blaknite's puzzle game when you use the enter key to rotate blocks. Is this a known limitation of Babelfish? I haven't seen anyone else talk about it. Regular use of the enter key in basic seems fine.
To my understanding, Babelfish maps keys to a specific value (combination of bits) whereas a controller has a bit per key. This means some keys are two or more controller buttons pushed at once. I think home/end and insert/delete will be the keys you’re after for the A/B inputs.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: Invader

Post by at67 »

bmwtcu wrote: 03 Aug 2020, 07:44 Amazing how much you squeezed out of the Gigatron! I spent more time than I care to admit playing this today.
:)
bmwtcu wrote: 03 Aug 2020, 07:44 I did notice an anomaly playing with keyboard that I'm trying to make sense of. If you fire using the enter key, the player shifts a little to the right with each shot, which doesn't happen if you use the controller to fire. I also noticed the same behavior with the online emulator. The weird thing is that I saw similar behavior in blaknite's puzzle game when you use the enter key to rotate blocks. Is this a known limitation of Babelfish? I haven't seen anyone else talk about it. Regular use of the enter key in basic seems fine.
It kind of is and kind of isn't a limitation of BabelFish, more a limitation of having a shared register/physical interface for both controller and keyboard.

The controller's 8 buttons are mapped to individual negative logic bits within buttonState, (address 0x0011), so each one of them can be individually checked with appropriate masking, (you can also check for any combination of "n" buttons being pressed simultaneously using this system). The keyboard's ASCII values are mapped to serialRaw, (address 0x000F); in reality buttonState and serialRaw are almost the exact same thing, it's just that buttonState allows you to reset the individual bits facilitating edge detection on button presses for one shot processing. If you don't use the bit resetting ability, then the registers are mirrors of each other.

The PS2 keyboard on the other hand is trying to present 100+ keys on the same interface without a keyboard buffer, FIFO, etc, so that each key pressed is mapped to an individual ASCII code. Of course this ASCII code uses 7 out of the 8 bits for representation and therefore without some sort of buffering system each new keypress wipes out the previous keypress so that you can only identify one key at a time, i.e. no "n" key rollover, or probably more accurately n = 1.

The reason Enter and most other keys cause strange behaviour on controller based games is that a lot of the ASCII codes will map to multiple controller button presses. i.e. In your case Enter is mapping to fire and move right. The reason it moves right for a few frames is that BabelFish sends PS2 keyboard events for 3 or so frames, (to simulate a human holding the key for around 50ms).

If you look at PS2.ino which is part of BabelFish, you'll see the following switch statement, (this version of PS2.ino was hand crafted by Marcel specifically for the Gigatron and supports multiple layouts/regions):

Code: Select all

switch (value) {
      // Extended codes in "Set 2"
      case 0xe075: button = buttonUp;     break; // [UpArrow]
      case 0xe06b: button = buttonLeft;   break; // [LeftArrow]
      case 0xe072: button = buttonDown;   break; // [DownArrow]
      case 0xe074: button = buttonRight;  break; // [RightArrow]
      case 0x66:                                 // [BackSpace]
      case 0xe071: if ((flags & ctrlFlags)       // [Delete]
                    && (flags & altFlags))
                     newAscii = CTRLALTDEL;      // [Ctrl-Alt-Del] becomes [Start]
                   else
                     button = buttonA;    break; // ASCII DEL is 127 is ~buttonA
      case 0xe069: button = buttonA;      break; // [End]
      case 0xe070:                               // [Insert]
      case 0xe06c: button = buttonB;      break; // [Home]
      case 0xe07a: button = buttonSelect; break; // [PageDown]
      case 0xe07d: button = buttonStart;  break; // [PageUp]
      case 0xe04a: newAscii = '/';        break; // [/] on numeric island
      case 0xe05a: newAscii = '\n';       break; // [Enter] on numeric island
      default:
        // Apply keyboard mapping to ASCII
        if ((flags & altGrFlag) ||
           ((flags & ctrlFlags) && (flags & altFlag))) // Ctrl+Alt is AltGr
          newAscii = lookup(ALTGR, value);
        else if (flags & shiftFlags)
          newAscii = lookup(SHIFT, value);
        else
          newAscii = lookup(NOMOD, value);

        // Handle control key combinations
        if (flags & ctrlFlags)
          switch (newAscii) {
            case '?':     newAscii = 127; break; // Traditional mapping of Ctrl-? to DEL
            case ' ':     button   = 255; break; // Make it send a 0 byte
            default:
              byte f = fnKey(newAscii);
              if (f) {
                if (flags & altFlags)
                  // Ctrl-Alt-Fxx changes the keymap
                  EEPROM.write(offsetof(struct EEPROMlayout, keymapIndex), f-1);
                else
                  // Ctrl+Fxx are BabelFish commands
                  newAscii ^= 64;
              } else
                // Make control codes (what the key is for...)
                newAscii &= 31;
          }
    }
You can see that the cursor keys and a bunch of the editing keys are mapped to the controller, so that these keys do not suffer the same limitation as the other keys that are mapped to ASCII codes, i.e. you can press and detect them simultaneously. Delete gets special attention as it's ASCII value of 127 maps directly to button A's 0x7F negative logic.

TLDR:
So to shoot AND to be able to move at the same time, you want to be pressing either DELETE or END whilst using the arrow keys.

P.S. Blaknite beat me to it and lol at how he managed to convey the same information that I did, but did it in 2 lines instead of 5 paragraphs.
bmwtcu
Posts: 145
Joined: 01 Nov 2018, 12:02

Re: Invader

Post by bmwtcu »

Thanks much to both of you for the information. Makes sense now.
Post Reply