comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Creating several types from a base type and conversion
Date: Wed, 22 Jan 2020 01:06:53 +0200
Date: 2020-01-22T01:06:53+02:00	[thread overview]
Message-ID: <h8pegdF8u13U1@mid.individual.net> (raw)
In-Reply-To: <e199618f-5588-4249-8d73-e854f10a48dc@googlegroups.com>

On 2020-01-21 23:35, Shark8 wrote:
> 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);

This won't work in Janus/Ada or other Ada compilers (if there are 
any...) with a 16-bit Integer. Better use a user-defined type with a 
sufficient range.

>> 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.

Why? Bit numbers normally start at zero, in either bit-number order, and 
in all computer manuals and instruction sets I have ever seen.

(The rest of my comments are addressed mainly to Ken Roberts.)

>> 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)

Modular types, including Interfaces.Unsigned_32, have built-in bit-wise 
boolean operators, so there is little advantage in using arrays of 
booleans instead of modular types.

>> 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).

Perhaps you (Ken) did not understand that when you extend a tagged 
record type, you are *adding* components to the components in the parent 
type. The parent type's components are still there, and still occupy the 
bit ranges specified in the representation clause for the parent type. 
This is not a "remapping" or "reinterpretation" of the bits of the 
parent type -- that is what the Unchecked_Conversion function is for.

> 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.

That's a bad idea, IMO. The emulated RAM should be randomly accessible, 
word by word, which is cumbersome and slow (if possible) for streams.

>> 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).

It seems to me that emulating the instruction semantics (functional 
emulation) is a reasonable goal for someone new to Ada. Emulating the 
cycle-by-cycle operation of the HW is much more ambitious, especially 
when various HW units are running in parallel, and I do not advise 
starting there. Better to start from a functional emulation, and tackle 
the cycle-accurate emulation later.

Your github documents suggest that you intend use network messages to 
emulate data transmitted at clock-rate between the different HW units of 
the emulated computer. I suspect that this, together with the 
cycle/phase-specific emulation, will not let you reach your target of 
running the emulation at the 1 MHz rate of the original computer.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

  reply	other threads:[~2020-01-21 23:06 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
2020-01-21 23:06       ` Niklas Holsti [this message]
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