Monday 12 April 2021

The first thing I C!

I got a few minutes to start on the transcode today. I did a very, very preliminary scan of the code to get an idea of the data and code structures and its suitability to be converted to C a few days ago; now I'm simply working through the execution path from cold reset, adding data variables and routines as I go.

This is what I saw tonight. It appeared 'magically' when I implemented the Scramble code to fill character RAM with white rectangles. The arcade code is running in one thread, whilst the Allegro-based OS-dependent code is refrshing the display at 60Hz.

Just to give you an idea of what the transcode looks like, here's the main routine so far...


void scramble (void)
{
  // $0000 disables interrupts and jumps here
  memset (wram, 0, 0x0800);
  // jumps to $0069, immedaitely above here
  // - so implement here
  //0069: 3E 9B       ld   a,$9B
  //006B: 32 03 81    ld   ($8103),a             ; does nothing
  //006E: 3E 88       ld   a,$88
  //0070: 32 03 82    ld   ($8203),a             ; does nothing
  //0073: 3E 08       ld   a,$08
  //0075: 32 42 42    ld   ($4242),a             ; set IRQTRIGGER_CTRL
  //0078: 32 01 82    ld   ($8201),a             ; bit 3 = interrupt trigger on audio CPU
  
  rst10_memset ((void *)circ_cmd_queue, 0xff, sizeof(circ_cmd_queue));
  rst10_memset ((void *)circ_sound_cmd_queue, 0xff, sizeof(circ_sound_cmd_queue));
  circ_sound_cmd_queue_ptr = circ_sound_cmd_queue;
  circ_sound_cmd_queue_proc = circ_sound_cmd_queue;
  
  // kick watchdog
  // disable interrupts
  //00E0: 32 05 70    ld   ($7005),a             ; does nothing
  //00E3: 32 06 68    ld   ($6806),a             ; disable screen vertical flip
  //00E6: 32 07 68    ld   ($6807),a             ; disable screen horizontal flip
    
  circ_cmd_queue_ptr = circ_cmd_queue;
  circ_cmd_queue_proc = circ_cmd_queue;
  
  //00F0: 32 04 68    ld   ($6804),a             ; enable stars
  temp_char_ram_ptr = cram;
  temp_counter_4008 = 0x20;
  bonus_jet_for = 10;                           // 10,000 points (originally BCD)
  uint8_t in2 = 0;
  coinage_value = (in2>>1) & 0x03;
  is_cocktail = (in2>>3) & 0x01;
  uint8_t in1 = 0 & 0x03;
  if (in1 == 3)
    default_player_lives = 255;
  else
    default_player_lives = in1 + 3;
  disable_sound ();
  // protection stuff
  memset ((void *)&objram, 0, sizeof(objram));
  //; Fill screen with 8x8 white rectangles
  memset ((void *)cram, 0x3f, sizeof(cram));
}

I've included the original assembler as comments for any instructions whose purpose is questionable. Ditto for functionality I probably won't need to implement (such as screen flipping). There's a few of these in the start-up code, as you can see above, but I suspect there's very few throughout the remainder of the code.

From here-on in, there's going to be quite a few weeks of simply working my way through the code. I'll be ignoring any protection schemes, watchdogs, sound hardware etc.

No comments:

Post a Comment