From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Creating several types from a base type and conversion
Date: Tue, 21 Jan 2020 13:35:22 -0800 (PST)
Date: 2020-01-21T13:35:22-08:00 [thread overview]
Message-ID: <e199618f-5588-4249-8d73-e854f10a48dc@googlegroups.com> (raw)
In-Reply-To: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com>
On Saturday, January 18, 2020 at 5:49:17 AM UTC-7, Ken Roberts wrote:
>
> The concept is emulating a 30-bit computer from olden days.
Then allow me to suggest you do that, instead:
Type Word is range 0..2**30-1
with Size => 30;
this allows you to also do something like this:
Function Convert( Data : Integer ) return Word
with Inline, Pre => Data in Integer(Word'First)..Integer(Word'Last);
Function Convert( Data : Word ) return Integer
with Inline;
-- ...
Function Convert( Data : Integer ) return Word is ( Word(Data) );
Function Convert( Data : Word ) return Integer is ( Integer(Data) );
>
> It was my understanding that a boolean array would be better than an
> integer in order to do some of the bit manipulations that the old
> computer was designed for.
That might be true; though If you're going that route you may want to number the array indices 1..30.
>
> One example:
>
> ADD LP : L[Y*(Q)]+(A) -> A
>
> Take the logical product of Y and Q register, then add A register,
> place results in A register.
>
> (LP being boolean AND of 2 registers)
>
> I think I tried doing tagged records and subtypes, but kept getting
> errors like 'Bits already mapped' when trying to extend the BaseWord
> (30 bit) into a data word ( 2 separate 15-bit fields) and instruction
> word (5 separate bit-mapped fields) while still being able to easily
> convert between BaseWord and others (think pulling next instruction from memory array, then pulling data from arbitrary location in memory array).
Hm, you *could* make the programs a stream and use the stream read/write attributes. -- Though this *might* be a bit of a bear to debug, it does have the advantage that you could "dump the bits to the stream" and let the Read attribute/function take care of interpreting the data.
>
> Functionally, it would be relatively easy to just ignore the hardware
> aspect of the emulation, but I'm trying to set it up so I can emulate
> the hardware later as a learning tool to how this old computer
> actually did things (like 1's complement subtractive addition). The
> real fun will be programming the timing (1MHz clock split into 4
> phases, with interesting interrupt handling).
Hm, this is interesting... it sounds like it would make a really good Ada/VHDL combined-language project. (But I have no idea how hard that would be compared to just simulating things pure-Ada.)
>
> I know - _very_ ambitious project for a beginner in the language (not
> to programming), but I figure might as well have an interesting
> project to work on while learning rather than the basic "Hello World"
> style that seems to be prevalent.
Yes. I would tend to agree.
Allow me to suggest that you could leverage the power of enumerations for the instruction-set.
Then you could build your instruction-stream off that; eg:
-- Ultra-simplified:
Type OP_CODE is (ADD, DIV, EXMPL); -- SUB, MUL, WTVR.
Type Register_Code is (R1, R2, AD, SB)
with Size => 4; -- Four bit register-code; single-trace active.
For Register_Code use (
R1 => 2#0001#,
R2 => 2#0010#,
AD => 2#0100#,
SB => 2#1000#
);
Type Instruction( Op : Opcode ) is record
case Op is
When ADD => Val_1, Val_2 : Word; -- two Word-size operands.
When DIV => Val_1, Val_2 : Word;
When EXMPL => Register : Register_Code;
-- other operations
end case;
end record
with Static_Predicate => -- NOTE: YOU CAN ENFORCE INSTRUCTION VALIDITY.
(Case Instruction.Op is
When Add => True, -- All values are good.
When Div => Instruction.Val_2 /= 0 or else raise Program_Error with "Invalid bitstream",
When EXMPL => Instruction.Register /= AD
);
The above is a simplified version of something I played around with a few years ago: https://github.com/OneWingedShark/Lamman/blob/master/src/ghost_cpu.ads
IOW, don't be afraid to logically model things a bit more than the bit-twiddling would suggest. Also Bill Findlay's KDF9 emulator is probably a really good resource in using Ada to emulate old hardware. (I think there was an Ada implementation of the WWII Enigma machine or something similar someone built, but I can't remember *who*.)
next prev parent reply other threads:[~2020-01-21 21:35 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-18 7:32 Creating several types from a base type and conversion Ken Roberts
2020-01-18 12:16 ` Simon Wright
2020-01-18 12:49 ` Ken Roberts
2020-01-18 14:56 ` Bill Findlay
2020-01-18 16:13 ` Jeffrey R. Carter
2020-01-18 18:20 ` Bill Findlay
2020-01-18 18:32 ` Jeffrey R. Carter
2020-01-18 20:34 ` Simon Wright
2020-01-20 16:38 ` Bill Findlay
2020-01-18 22:20 ` Ken Roberts
2020-01-18 15:09 ` Simon Wright
2020-01-18 22:16 ` Ken Roberts
2020-01-18 22:35 ` Simon Wright
2020-01-18 23:03 ` Ken Roberts
2020-01-18 23:38 ` Simon Wright
2020-01-19 0:12 ` Ken Roberts
2020-01-19 9:37 ` Simon Wright
2020-01-19 11:48 ` AdaMagica
2020-01-19 14:51 ` Simon Wright
2020-01-19 15:24 ` Niklas Holsti
2020-01-19 16:11 ` Optikos
2020-01-19 0:33 ` Ken Roberts
2020-01-19 0:07 ` Niklas Holsti
2020-01-18 15:47 ` Simon Wright
2020-01-21 21:35 ` Shark8 [this message]
2020-01-21 23:06 ` Niklas Holsti
2020-01-22 1:08 ` Ken Roberts
2020-01-22 14:18 ` Ken Roberts
2020-01-22 8:37 ` Simon Wright
2020-01-22 14:32 ` Shark8
2020-01-22 15:40 ` Simon Wright
2020-01-18 14:17 ` Optikos
2020-01-18 17:57 ` Niklas Holsti
2020-01-18 22:59 ` Ken Roberts
2020-01-19 0:30 ` Niklas Holsti
2020-01-19 1:07 ` Ken Roberts
2020-01-19 3:37 ` Ken Roberts
2020-01-23 21:39 ` Optikos
2020-01-24 9:35 ` Ken Roberts
2020-01-24 10:04 ` AdaMagica
2020-01-24 12:38 ` Optikos
2020-01-24 15:01 ` Ken Roberts
2020-01-24 15:22 ` Simon Wright
2020-01-24 15:40 ` Ken Roberts
2020-01-24 15:54 ` Simon Wright
2020-01-25 10:37 ` Ken Roberts
2020-01-25 10:44 ` Ken Roberts
2020-01-25 20:26 ` Shark8
2020-01-27 14:10 ` Ken Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox