From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a37:6313:: with SMTP id x19mr7035559qkb.231.1579642523335; Tue, 21 Jan 2020 13:35:23 -0800 (PST) X-Received: by 2002:a54:4713:: with SMTP id k19mr4528589oik.113.1579642523040; Tue, 21 Jan 2020 13:35:23 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no8545865qtd.0!news-out.google.com!w29ni2118qtc.0!nntp.google.com!g89no8545857qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 21 Jan 2020 13:35:22 -0800 (PST) In-Reply-To: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Creating several types from a base type and conversion From: Shark8 Injection-Date: Tue, 21 Jan 2020 21:35:23 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57912 Date: 2020-01-21T13:35:22-08:00 List-Id: On Saturday, January 18, 2020 at 5:49:17 AM UTC-7, Ken Roberts wrote: >=20 > 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 =3D> 30; this allows you to also do something like this: Function Convert( Data : Integer ) return Word with Inline, Pre =3D> 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) ); >=20 > 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 numbe= r the array indices 1..30. >=20 > One example: >=20 > ADD LP : L[Y*(Q)]+(A) -> A >=20 > Take the logical product of Y and Q register, then add A register, > place results in A register. >=20 > (LP being boolean AND of 2 registers) >=20 > 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 at= tributes. -- 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. >=20 > 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/V= HDL combined-language project. (But I have no idea how hard that would be c= ompared to just simulating things pure-Ada.) >=20 > 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 t= he instruction-set. Then you could build your instruction-stream off that; eg: -- Ultra-simplified: Type OP_CODE is (ADD, DIV, EXMPL); -- SUB, MUL, WTVR. =20 Type Register_Code is (R1, R2, AD, SB) with Size =3D> 4; -- Four bit register-code; single-trace active. For Register_Code use ( R1 =3D> 2#0001#, R2 =3D> 2#0010#, AD =3D> 2#0100#, SB =3D> 2#1000# ); =20 Type Instruction( Op : Opcode ) is record case Op is When ADD =3D> Val_1, Val_2 : Word; -- two Word-size operands. When DIV =3D> Val_1, Val_2 : Word; When EXMPL =3D> Register : Register_Code; -- other operations end case; end record with Static_Predicate =3D> -- NOTE: YOU CAN ENFORCE INSTRUCTION VALIDITY. (Case Instruction.Op is When Add =3D> True, -- All values are good. When Div =3D> Instruction.Val_2 /=3D 0 or else raise Program_Error wit= h "Invalid bitstream", When EXMPL =3D> Instruction.Register /=3D AD ); The above is a simplified version of something I played around with a few y= ears ago: https://github.com/OneWingedShark/Lamman/blob/master/src/ghost_cp= u.ads IOW, don't be afraid to logically model things a bit more than the bit-twid= dling 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*.)