Martin Krischik avatar

Ben Eater 6502 Kit — Day 11

krischik

Published: 12 Nov 2020 › Updated: 12 Nov 2020Ben Eater 6502 Kit — Day 11

Ben Eater 6502 Kit — Day 11

Screenshot at Nov 11 192533.png

Up until now the 65C02 was only supplied with NOP operation. Including the reset and interrupt vectors making the CPU start execution at EAEA₁₆ while the first address of the ROM is 8000₁₆ which would also be the correct place to start the program.

So I updated the Ada program which generates the ROM image with so that the reset and interrupt vectors are all filled with 8000₁₆. Do read the comments for more informations on this over engendered code.

with Ada.Sequential_IO;
with Ada.IO_Exceptions;
with Ada.Command_Line;
with Ada.Text_IO;
with Interfaces;

procedure Create_Reset is

  type Byte is new Interfaces.Unsigned_8;
  type Address is new Interfaces.Unsigned_16;

  --  One of the cool feature of Ada is it's ability to set the lower and
  --  upper bound of an array to any value you want. So we can set use the
  --  actual ROM addresses as array index an save ourself the work and
  --  remove one potential error source.
  --
  type ROM_Type is
     array (Address range 16#8000# .. 16#FFFF#)
     of Byte;

  package ROM_IO is new Ada.Sequential_IO (ROM_Type);

  ROM_Output : ROM_IO.File_Type;

  --  65C02 related constants as named in the original
  --  WDC design document
  --
  NOP      : constant Byte    := 16#EA#;
  NMIB     : constant Address := 16#FFFA#;
  RESB     : constant Address := 16#FFFC#;
  BRK_IRQB : constant Address := 16#FFFE#;

  --  Another interesting feature Ada arrays is specifying the index of
  --  elements when initialising the array. As well specifying an value
  --  for all not explicitly initialised values. Makes setting up the
  --  ROM array super easy.
  --
  ROM : constant ROM_Type :=
     (NMIB + 0     => 16#00#,
      NMIB + 1     => 16#80#,
      RESB + 0     => 16#00#,
      RESB + 1     => 16#80#,
      BRK_IRQB + 0 => 16#00#,
      BRK_IRQB + 1 => 16#80#,
      others       => NOP);

begin
  if Ada.Command_Line.Argument_Count < 1 then
     Ada.Text_IO.Put_Line ("Syntax: Create_Reset ");
  else
     declare
        File_Name : constant String := Ada.Command_Line.Argument (1);
     begin
        ROM_IO.Create (ROM_Output, ROM_IO.Out_File, File_Name);
     exception
        when Ada.IO_Exceptions.Name_Error =>
           Ada.Text_IO.Put_Line ("File “" & File_Name & "” couldn't be created.");
           Ada.Text_IO.Put_Line ("See stack trace below for more details.");
           raise;
     end;

     --  Just like Python Ada can write the whole array in one go.
     --
     ROM_IO.Write (ROM_Output, ROM);
     ROM_IO.Close (ROM_Output);
  end if;
end Create_Reset;

1.jpeg
Write the ROM image

2.jpeg
Test using the Arduino


You find the full source code with makefiles, project files and source on GitLab: 6502Tutorial — Tools/Create_Reset

Leave Ben Eater 6502 Kit — Day 11 to:

Written by

For each right there is an equal and opposite obligation. — me

Read more #vintage-computing posts


Best Posts From Martin Krischik

We have not curated any of krischik's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Martin Krischik