HiSoft C programmers?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
GRC7800
Drutt
Posts: 31
Joined: Sat Jan 28, 2023 4:02 pm

HiSoft C programmers?

Post by GRC7800 »

This is a sincere question: Has anyone done any serious programming of any sort with HiSoft C? I’m absolutely fascinated by this implementation. However, before I go all in, I was just wondering what people thought about it in general? Is it a capable compiler or more of a quaint curiosity? If you’ve made anything with it, what was it? What was your workflow like?

Any thoughts or comments would be appreciated. Thanks in advance!
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

i played a little with HiSoft Pascal and HiSoft C on real machine long time ago, and my conslusion was "nice toys!" generated code is far from good, overhead for supporting recursion and "proper locals" is too big, and you will run out of RAM long before writing something really useful. generally, C (and any other such language with proper support for locals AND recursion out of the box) doesn't fit to CPUs without SP-relative addressing instructions. there is a reason why PL/M didn't supported "proper recursion" by default. ;-)

but using "The Real Language" on poor small Speccy was fun anyway. ;-)
_dw
Dizzy
Posts: 96
Joined: Thu Dec 07, 2023 1:52 am

Re: HiSoft C programmers?

Post by _dw »

GRC7800 wrote: Sun Dec 17, 2023 2:27 am This is a sincere question: Has anyone done any serious programming of any sort with HiSoft C?
I was glad that I understood at all that I can control it. Direct programming on original hw is hard. Programming on an emulator is a double whammy, it makes no sense to me.
GRC7800 wrote: Sun Dec 17, 2023 2:27 am I’m absolutely fascinated by this implementation. However, before I go all in, I was just wondering what people thought about it in general? Is it a capable compiler or more of a quaint curiosity? If you’ve made anything with it, what was it? What was your workflow like?

Any thoughts or comments would be appreciated. Thanks in advance!
I also think that C is not a suitable language for the Z80. C is defined to support recursion even when not used. And that costs too much for the Z80. Besides, all compilers are pretty bad.

You can use Basic on the ZX, because it is tokenized, and the runtime library is already occupied in the ROM. You can compile Basic. Basic is easy to write and just as readable as C.

You can use assembler and do it as fast as possible. Assembler is the easiest to learn, but the hardest to program in. Because in addition to assembler, you have to learn how to break the program into small parts. Don't be fooled by the fact that it is more optimal when it is written as a whole. Define some rules for how you use registries and stick to them even if they may not be the most convenient. It will reduce the chaos if you know what to expect. Try making a lego out of it.

You can use Forth and make the program even smaller than in pure assembly and faster than with (uncompiled) Basic. But Forth can resemble tokenized assembler for readability.

Some combination.

In C, you will decide how to compile it at all, what parameter to enter. You need to find information about which optimized library someone has already written to solve a problem. Programming in C is like being addicted. The only advantage is readability, which Basic also has, which does not have the iron ball at its feet called recursion.

If it will be the same in the end in C, I recommend not looking at the binary for peace of mind. I looked at the binary code and ended up writing my own compiler.
Z80 Forth compiler (ZX Spectrum 48kb): https://codeberg.org/DW0RKiN/M4_FORTH
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: HiSoft C programmers?

Post by Wall_Axe »

I much prefer assembler, I had trouble even with the modern C compilers.

There's a bit of work to get started, you have to get a font , write a print string function (unless you want to use the rom print) write a print byte function.

Then you have to experiment a bit with dereferencing pointers in assembler.

Then you've got all the language features of C at your fingertips.

It's kind of a pain to write sometimes, and does take longer than C or basic to do basic things.
But if you're trying to do something even slightly complicated you need it.

If I had a forth cross compiler from windows/Linux to spectrum I'd try that. I think there is one for Linux but I haven't tried it out.

I think a problem with most languages for spectrum is the overhead, a small program which printed strings to the screen took up 20k in some languages.
I had tried to reserve some space for rooms, and characters but ended up just crashing the spectrum because the code overwrote the data!
This is a modern C implementation...

Using assembler I've recreated the same program and it takes up about 3k including all code, data and a font. I understand every part of the program which is nice.

My code will never overwrite my data cos it's all in a text file, together.
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

shameless offtopic self-promotion
Wall_Axe wrote: Sun Dec 17, 2023 9:04 am If I had a forth cross compiler from windows/Linux to spectrum I'd try that.
shameless offtopic self-promotion: now, as i wrote The Beast, i will definitely write a cross-compiler with it, because i have several interesting ideas to try. and yep, The Beast will have a windows port (althrough 32-bit only).
Wall_Axe
Manic Miner
Posts: 500
Joined: Mon Nov 13, 2017 11:13 pm

Re: HiSoft C programmers?

Post by Wall_Axe »

Cool I'll try that.

Any chance of porting it to c64 :)

It would be a first to have a language for both that is fast and efficient.
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

Wall_Axe wrote: Sun Dec 17, 2023 9:32 am Any chance of porting it to c64 :)
Spoiler
nope, sorry. ;-) i never had C64 myself, so i don't have enough interest in it. besides, 6502 is even less suitable for Forth than Z80. it is doable, of course, but…

besides, there will be a little reason in doing so, because the code won't be portable anyway. the idea is that you'll mix asm primitives and high-level Forth code, and the compiler will try to build a minimal kernel for it. you'll also be able to run your code in very simplistic built-in emulator, to get a rough idea of what it will look like on The Real Thing (and debug it).

so, low-level asm primitives to work with screen, sprites and sound won't be portable. and then, i'll have to write a C64 emulator too, which is not something i am capable of (i don't know enough technical details about C64). and even if i'll do it all, memory layout and hardware limitations will prevent you from easily porting your code anyway.

of course, if i'll finish my ZX cross-compiler, and then somebody from C64 scene will show some interest in helping to port it, it may happen. but i'm not even sure when (or, IF) i'll finish ZX thing… ;-)

but we're derailing the thread. ;-)
dfzx
Manic Miner
Posts: 684
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: HiSoft C programmers?

Post by dfzx »

If anyone so much as mentions C on the Spectrum Computing forums our little band of C-haters will immediately pop up and pronounce what a terrible language it is, how badly it works on the Z80, how recursion is a problem and how anyone interested in C should definitely be learning Forth instead. Take what they say with a pinch of salt. C is a fine language with excellent support in the ZX eco-system. A lot of good software has been written in C for the Spectrum. But, er, not in HiSoft C. :)

HiSoft C is, like most Spectrum language implementations from the mid '80s, a curio these days. It's obviously an ancient implementation of the language, and even then it was somewhat hobbled to get it into the available memory. No floats, for example. The cassette-based Spectrum can't handle a separate editor, compiler, linker and execution environment, so the language came with its own editor. It was dreadful, but we should acknowledge it for the achievement it was - an IDE on a 48K machine was no mean feat - and on a microdrive- or disk-enabled 128K machine it might even have been vaguely usable.

The main use of HiSoft C back in the 80s was probably learning C. Because it supported most of the K&R standard it would have allowed a Spectrum user to get started with the most common system programming language. I don't know anyone who ever used it for that purpose but it's nice to think that maybe it opened doors for people, educationally, and eventually, professionally.

Like so much ZX history, HiSoft C is charming in its way, and it's fun to review how things were back then. But you wouldn't want to use it today to do anything actually useful. If that's your goal, see my sig.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Timmy
Manic Miner
Posts: 231
Joined: Sat Apr 23, 2022 7:13 pm
Location: The Netherlands

Re: HiSoft C programmers?

Post by Timmy »

I think I agree with a lot of comments here.

I'd say that about 30% of the games here made in the last ten years is written with at least a bit of C. Why would anyone wants to use a proven and solid solution like C to make games if you can also use Pascal or Forth? ;)

That said, HiSoft C is definitely better than typing out DATA statements and POKE-ing them directly into memory. Otherwise it's just a relic from the 80s.

Making games for the Spectrum with C has improved since then.

But if you want to believe that people use HiSoft C is the best way to make games, then I am not going to stop you believing. And if a Forth like solution is better than HiSoft C, then it's an achievement! (just a very easy achievement worth 1 point out of 1000, mind.)
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

Timmy wrote: Sun Dec 17, 2023 12:09 pm Why would anyone wants to use a proven and solid solution like C to make games if you can also use Pascal or Forth? ;)
because it doesn't matter how good the compiler is, actually. ;-) nobody's writing low-level sprite routines and such in Z80 C anyway, everybody is using fast assembler gfx engines. so high-level language is used mostly as a scripting glue, and here even the classic P-Code will fit. or AGD scripting lang, for that matter. ;-)

but try to write something else and complex with Z80 C — like, for example… native C compiler — and you'll see how useless Z80 C is. ;-) and ZX Forth compiler can be about 6KB of code (plus ~0.7/1.5 KB for native assembler support, depending on features). yay, a fully-featured high-level language, running natively on ZX, with no penalty for recursion, with built-in assembler, in 8KB, leaving plenty of room for your code too! now, beat that with C! ;-)
dfzx
Manic Miner
Posts: 684
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: HiSoft C programmers?

Post by dfzx »

ketmar wrote: Sun Dec 17, 2023 12:25 pm but try to write something else and complex with Z80 C — like, for example… native C compiler — and you'll see how useless Z80 C is. ;-)
No you won't. Z80 C isn't useless. Lots of good software has been written in it. Z80 C is excellent for a whole bunch of tasks.
ketmar wrote: Sun Dec 17, 2023 12:25 pm and ZX Forth compiler can be about 6KB of code (plus ~0.7/1.5 KB for native assembler support, depending on features). yay, a fully-featured high-level language, running natively on ZX, with no penalty for recursion, with built-in assembler, in 8KB, leaving plenty of room for your code too! now, beat that with C! ;-)
If that's your weirdly specific criteria for your ultimate development tool, then Forth may very well be your best choice. The vast majority of us don't use native development tools any more and we don't need a built in assembler.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

dfzx wrote: Sun Dec 17, 2023 1:03 pmIf that's your weirdly specific criteria for your ultimate development tool
it is just an example of complex app. ok, let's take another one: scriptable text editor, for example. again, i can fit it into 16 kb (prolly even less), with fully-featured compiled language inside. but i know, this, again, is not the task we're doing today. actually, any more-or-less complex task falls into this category, so we're going back to point zero: scripting glue. where C is not the best choice again, people just stick to it because "this is The Real Language, not some toy one".

but please note that i am talking about C on Z80, not about C in general. for CPUs with rich instruction set C is a good more-or-less portable macroassembler with a bit of high-level sugar thrown in.
Timmy
Manic Miner
Posts: 231
Joined: Sat Apr 23, 2022 7:13 pm
Location: The Netherlands

Re: HiSoft C programmers?

Post by Timmy »

ketmar wrote: Sun Dec 17, 2023 12:25 pm because it doesn't matter how good the compiler is, actually. ;-) nobody's writing low-level sprite routines and such in Z80 C anyway, everybody is using fast assembler gfx engines. so high-level language is used mostly as a scripting glue, and here even the classic P-Code will fit. or AGD scripting lang, for that matter. ;-)
I'm not here to discourage you from doing Forth. But you do seem to have a need to talk down other languages.

And if you believe the compiler doesn't matter, then I'd say I thought that too when I wrote my GAC compiler and interpreter. :D Then again, I wrote for compatibility reasons, and text adventure games don't need the speed.
but try to write something else and complex with Z80 C — like, for example… native C compiler — and you'll see how useless Z80 C is. ;-) and ZX Forth compiler can be about 6KB of code (plus ~0.7/1.5 KB for native assembler support, depending on features). yay, a fully-featured high-level language, running natively on ZX, with no penalty for recursion, with built-in assembler, in 8KB, leaving plenty of room for your code too! now, beat that with C! ;-)
Yes, as I said it's an achievement!!!1!

By the way, I also like you started the thread with "a genuine question" too. You are a really funny person! :santa
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

Timmy wrote: Sun Dec 17, 2023 1:40 pm By the way, I also like you started the thread with "a genuine question" too. You are a really funny person! :santa
especially considering that i didn't started this thread…

p.s.: and didn't mentioned other languages besides PL/M in my answer, btw.
dfzx
Manic Miner
Posts: 684
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: HiSoft C programmers?

Post by dfzx »

ketmar wrote: Sun Dec 17, 2023 1:20 pm it is just an example of complex app. ok, let's take another one: scriptable text editor, for example. again, i can fit it into 16 kb (prolly even less), with fully-featured compiled language inside. but i know, this, again, is not the task we're doing today. actually, any more-or-less complex task falls into this category, so we're going back to point zero: scripting glue. where C is not the best choice again, people just stick to it because "this is The Real Language, not some toy one".

but please note that i am talking about C on Z80, not about C in general. for CPUs with rich instruction set C is a good more-or-less portable macroassembler with a bit of high-level sugar thrown in.
I would be 100% confident I could write a scriptable text editor with an internal fully featured compiled language in C inside 8K, never mind 16K. That's exactly the sort of task what C was designed for, and Z80 C is perfectly capable of doing that sort of thing.

So what is it about Z80 that you think is so bad? A lot of talented people have put in an awful lot of effort into making the modern Z80 C compilers, and you just dismiss them as "useless." Why do you think that?
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

dfzx wrote: Sun Dec 17, 2023 2:02 pm Why do you think that?
that's why. i literally replied to OPs question in full with my very first message here.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: HiSoft C programmers?

Post by catmeows »

GRC7800 wrote: Sun Dec 17, 2023 2:27 am This is a sincere question: Has anyone done any serious programming of any sort with HiSoft C? I’m absolutely fascinated by this implementation. However, before I go all in, I was just wondering what people thought about it in general? Is it a capable compiler or more of a quaint curiosity? If you’ve made anything with it, what was it? What was your workflow like?

Any thoughts or comments would be appreciated. Thanks in advance!
Not bad for what it is. I played a bit with both Hisoft Pascal and C and while I can imagine to write a short utility using Hisoft compilers, I really don't know how far they can be pushed.
I wonder if anyone tried to use Hisoft C or Pascal when writing a game.
Proud owner of Didaktik M
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

catmeows wrote: Sun Dec 17, 2023 2:19 pm I wonder if anyone tried to use Hisoft C or Pascal when writing a game.
i did. ;-) wrote "kingdom of grain"-like one, and a snake clone. haven't had disk drive back then, so RAM quickly became an issue. i think that if there were a +3 version (or Opus, or for some other disk system), it could be way more usable, with separate compilation and such.
dfzx
Manic Miner
Posts: 684
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: HiSoft C programmers?

Post by dfzx »

ketmar wrote: Sun Dec 17, 2023 2:13 pm that's why. i literally replied to OPs question in full with my very first message here.
Oh I see. Your opinion on modern Z80 C is based on your experience with HiSoft C for the ZX Spectrum from 1984. Yes, that explains quite a lot.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
GRC7800
Drutt
Posts: 31
Joined: Sat Jan 28, 2023 4:02 pm

Re: HiSoft C programmers?

Post by GRC7800 »

OP here. Thanks to everyone for their input! This turned into quite the debate! But I’ll now be checking out _dw’s FORTH compiler and dfzx’s C Programming Getting Started Guide. I mucked around with HiSoft C last night, and I agree that it’s probably best considered a learning tool.
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

dfzx wrote: Sun Dec 17, 2023 2:50 pm Oh I see. Your opinion on modern Z80 C is based on your experience with HiSoft C for the ZX Spectrum from 1984. Yes, that explains quite a lot.
sorry, i didn't knew that Z80 magically got new instructions since 1984. i guess that's what happens with any CPU over time: they gain new instructions which are stealthly retrofitted to the original CPUs using a time machine, rendering all prior knowledge wrong. either this, or you haven't a slightest idea of what i am talking about. but either way, i am done with this… conversation.
Timmy
Manic Miner
Posts: 231
Joined: Sat Apr 23, 2022 7:13 pm
Location: The Netherlands

Re: HiSoft C programmers?

Post by Timmy »

ketmar wrote: Sun Dec 17, 2023 1:53 pm especially considering that i didn't started this thread…
Sorry about that, I was very tired and just slept for an hour. Probably shouldn't be replying before going to sleep. :D
User avatar
ketmar
Manic Miner
Posts: 719
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: HiSoft C programmers?

Post by ketmar »

Timmy wrote: Sun Dec 17, 2023 3:49 pm Sorry about that, I was very tired and just slept for an hour. Probably shouldn't be replying before going to sleep. :D
no problems. ;-) take a good sleep and take care of yourself, it is way more important than any forum out there. ;-)
User avatar
druellan
Dynamite Dan
Posts: 1475
Joined: Tue Apr 03, 2018 7:19 pm

Re: HiSoft C programmers?

Post by druellan »

GRC7800 wrote: Sun Dec 17, 2023 2:27 am This is a sincere question: Has anyone done any serious programming of any sort with HiSoft C?
I worked with the compiler back in the day, trying to achieve something semi-serious for my dad's work, that required some data input/output and some charts, but quickly realized that Basic was good enough for what was required, and I don't remember if I even managed to do some complex outputs like charts using C. I do remember that was nice and interesting to learn and work on, and the end result was faster than Basic.
User avatar
+3code
Manic Miner
Posts: 436
Joined: Sat Mar 19, 2022 7:40 am

Re: HiSoft C programmers?

Post by +3code »

ketmar wrote: Sun Dec 17, 2023 2:23 pm i think that if there were a +3 version (or Opus, or for some other disk system), it could be way more usable, with separate compilation and such.
Seem there are +3 and disciple/+D disk versions of Hisoft C (and Hisoft Pascal).
Post Reply