c compiler for hack cpu

classic Classic list List threaded Threaded
♦
♦
3 messages Options
Reply | Threaded
Open this post in threaded view
♦
♦
|

c compiler for hack cpu

pm100
here is a c compiler for the hack cpu. https://github.com/pm100/hack_cc

There are a few sample apps - including tetris !

Note that the code generated by the compiler quite often wont run in the 'legacy' desktop emulator because it uses the free RAM space beyond the screen buffer and the desktop emulator doesnt permit that. The web UI does allow it but that runs too slow to usefully run tetris. I have several other emulators

- there is a WIP IDE , emulator and debugger in https://github.com/pm100/hackem
- there is a simple python emulator in https://github.com/pm100/hack_cc
- there is a standalone c++ emulator using the excellent one lone code pixel game engine in https://github.com/pm100/hack_olc

I also have a 'fixed' version of the desktop ide that allows high RAM addresses

At the moment the main oddness is that an int (16 bits) is not the same size as 2 chars (as required by posix), a char also occupies 1 word so we can address each char in a string. I am working on an option to make a 16 bit int occupy 2 words, so that you can address the ho and lo byte separately
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: c compiler for hack cpu

dolomiti7
Great work! I always had a C compiler on my bucket list as well... What do you mean by allowing high RAM addresses? In your docs I saw that you are using 32767 as a kind of terminal output port. Do you have any other uses for the high RAM addresses in your code? Like a second RAM area? That would allow some 80s style RAM expansion techniques like EMS expansion cards that allowed the 8088 IBM PC to address more than the 20-bit 1 MB limit with a hardware+software paging... ;-)
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: c compiler for hack cpu

pm100
Regarding high memory.
The RAM memory map is basically
- 0x0000-0x3fff general purpose
- 0x4000 - 0x5fff screen memory
- 0x6000 - kb input
- 0x6001 - 0x7fff general purpose

The 'legacy' desktop (java) IDE does not allow read or write above 0x6001, there is no reason for this blockage.  It has this line

    public static final int RAM_SIZE = 24577;

The web GUI  has the full RAM size of 32k words