Author Topic: The new fork of HuC  (Read 14076 times)

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #15 on: August 20, 2016, 08:55:48 AM »
Ahh thanks! I'm not familiar at all with github, so just now getting a chance to explore it/figure things out. It's actually pretty decent idea.

Also, having some fun testing out new features:
Code: [Select]
#include "huc.h"
#include "string.h"



struct BMP {
  int height;
  int width;
  char name[10];
};

struct BMP bmp;
struct BMP png;
struct BMP *bmp_ptr;

main()
{
 
  set_color_rgb(1, 7, 7, 7);
  set_font_color(1, 0);
  set_font_pal(0);
  load_default_font();
  disp_on();
  cls();
 
 
  bmp.height = 1;
  bmp.width = 1;
  strcpy(bmp.name, "test");

  put_string(bmp.name, 8, 5);

 
  bmp_ptr = &bmp;
 
  bmp_ptr->width = 256;
  bmp_ptr->height = 192;
  strcpy(bmp_ptr->name,"Ginger");
 
  put_string(bmp.name, 8, 6);
 
  bmp_ptr = &png;
  bmp_ptr->height = 32;
  bmp_ptr->width = 32;
  strcpy(bmp_ptr->name,"Bonk");

  put_string(png.name, 8, 7);

  bmp_ptr = &bmp;
  strcpy(bmp_ptr->name,"test2");

  put_string(bmp_ptr->name, 8, 8);

 
  while(1){};
 
 
  return 0;
}

 Note: I'm also looking at code improvements. The compiler sometimes optimizes for values kept in A:X, which is decent, but then there are occasions like temp++; which loads a 16bit value of temp (which is a char) into A:X, but then does a simple inc temp following it.

 The other thing that bothers me, is that all 8bit values being extended into 16 values (A:X) are done at runtime instead of compile time, if the variable is signed. Because the compiler is doing this automated extension, it also means signed extension has to be handle at runtime. This means unsigned vars will always be faster than signed - for chars. If compiler didn't automatically extend everything into 16bit, this wouldn't be a problem. So this is an area where the compiler still needs work. I mean, unsigned char is just one extra byte and 2 extra cpu cycles (cla).

 In other words, the compiler is automatically type casting every char. It shouldn't. There should a specific set of build-macros just for handling char values (I think Dave Shadoff was working on this as an optimization switch in the 3.21 version).
« Last Edit: August 20, 2016, 09:21:13 AM by Bonknuts »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #16 on: August 20, 2016, 09:23:52 AM »
I can't think of anything less fun than writing 6802-style ASM. Maybe compiling a compiler.

 This got me thinking. So, do you have any ASM mixed into your C code? Would you be willing to use some generic, easy to use ASM template code if it was given to you in tutorial form - to mix with C?

nodtveidt

  • Guest
Re: The new fork of HuC
« Reply #17 on: August 20, 2016, 08:55:22 PM »
Arkhan and I have been finding ways around HuC's limitations for years now. Just sayin'. :D

spenoza

  • Hero Member
  • *****
  • Posts: 2751
Re: The new fork of HuC
« Reply #18 on: August 21, 2016, 03:29:38 AM »
Arkhan and I have been finding ways around HuC's limitations for years now. Just sayin'. :D

Can you blame folks for wanting better? The tools folks use are important to them.
<a href="http://www.pcedaisakusen.net/2/34/103/show-collection.htm" class="bbc_link" target="_blank">My meager PC Engine Collection so far.</a><br><a href="https://www.pcenginefx.com/forums/" class="bbc_link" target="_blank">PC Engine Software Bible</a><br><a href="http://www.racketboy.com/forum/" c

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Re: The new fork of HuC
« Reply #19 on: August 21, 2016, 05:44:31 AM »
I can't think of anything less fun than writing 6802-style ASM. Maybe compiling a compiler.

 This got me thinking. So, do you have any ASM mixed into your C code? Would you be willing to use some generic, easy to use ASM template code if it was given to you in tutorial form - to mix with C?

Um, absolutely, if it helps the program. That said, I'm not sure what you could provide, since that is really the job of the compiler, right?
Hey, you.

nodtveidt

  • Guest
Re: The new fork of HuC
« Reply #20 on: August 21, 2016, 08:17:13 AM »
Can you blame folks for wanting better? The tools folks use are important to them.
No way! Never once in the 13+ years I've been using HuC have I ever thought "you know what? it would be nice if this was more efficient and I didn't have to longform certain techniques just to get good speed out of them at the expense of code size"... never once crossed my mind!

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #21 on: August 21, 2016, 08:27:17 AM »
That said, I'm not sure what you could provide, since that is really the job of the compiler, right?
Speed.

 In the form of small copy/paste segments of asm code that you simply replace the variable name.

 Anything else, like added complexity, and you'd just have to learn ASM yourself to implement it.


Arkhan and I have been finding ways around HuC's limitations for years now. Just sayin'. :D
It wasn't aimed at asking HuC vets ;) Funny though, but I haven't seen you guys post anything public about it, specifically. Or did I miss something? Exclusive club? :P

nodtveidt

  • Guest
Re: The new fork of HuC
« Reply #22 on: August 21, 2016, 08:40:14 AM »
Funny though, but I haven't seen you guys post anything public about it, specifically. Or did I miss something? Exclusive club? :P
Perhaps because these solutions are usually specific to the implementation and don't have general application. Either that or we just converse in secret, keeping all of the secrets of the universe to ourselves. :lol:

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #23 on: August 21, 2016, 09:28:59 AM »
Illuminati!

esteban

  • Hero Member
  • *****
  • Posts: 24063
The new fork of HuC
« Reply #24 on: August 21, 2016, 09:32:40 AM »
If only the Illuminati would release the PC Cocoron ISO.
  |    | 

elmer

  • Hero Member
  • *****
  • Posts: 2153
Re: The new fork of HuC
« Reply #25 on: August 22, 2016, 04:17:42 AM »
Can you blame folks for wanting better? The tools folks use are important to them.

Having a compiler that barely-qualifies as recognizable modern-C, and that requires you to perform all sorts of undocumented and hidden gyrations in order to work around its limitations ... is not very user-friendly.

IMHO, it should be possible to do better these days, and have a compiler that produces "just-about-acceptable" code that's no more than 2 or 3 times slower than pure hand-optimized assembly language.

The work that Uli (and Artemio and the others) have done has been a big step forward in making HuC more usable for modern folks, and I hope that people will take advantage of it.

I just know that a better compiler is possible, and that it could help people.

But it doesn't replace the desire or passion of dedicated homebrew developers, who will work long hours to create something fun on the PCE with whatever tools are available.


Arkhan and I have been finding ways around HuC's limitations for years now. Just sayin'. :D

And as Arkhan has said himself ... he basically prototypes in HuC, and then when he's got the logic flow written, he rewrites large chunks of C code in pure assembly.

That shouldn't really be necessary ... or at least be something that's confined to a few specialized functions that get called lots of times per frame.


No way! Never once in the 13+ years I've been using HuC have I ever thought "you know what? it would be nice if this was more efficient and I didn't have to longform certain techniques just to get good speed out of them at the expense of code size"... never once crossed my mind!

Good for you!  :wink:

For me ... I looked at language limitations and the code that it produced and said "I'd rather be writing in assembly".

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #26 on: August 22, 2016, 04:27:24 PM »

Having a compiler that barely-qualifies as recognizable modern-C, and that requires you to perform all sorts of undocumented and hidden gyrations in order to work around its limitations ... is not very user-friendly.

IMHO, it should be possible to do better these days, and have a compiler that produces "just-about-acceptable" code that's no more than 2 or 3 times slower than pure hand-optimized assembly language.

The work that Uli (and Artemio and the others) have done has been a big step forward in making HuC more usable for modern folks, and I hope that people will take advantage of it.

 I agree. And not just modern folks, but the whole idea of a higher level language environment is to avoid dedicating years of experience with assembly targeted for said platform. It seems ridiculous that programmers should have to fight the compiler the whole way through, such as HuC, when there are much more similar and mature language products.. on similar spec'd platforms.

 I know the 65x arch isn't the best design for efficiency for something like C, but that isn't the whole excuse. HuC, version 3.21, I wouldn't even call it "small" C.. I'd call it "barely" C. I'm not bagging on it for not being more than what it was (Dave Shadoff even described it as being an introduction to PCE programming and nothing equating seriousness). To me, that implies "novice" and "toy". But that doesn't mean both functionality (support for more modern concepts and constructs), and speed/efficiency can't be brought up quite a few levels. I find the upgrades that Uli has done to be quite staggering by comparison (you don't get a full picture until you go through the hundreds of test files in the PCE C test source folder, showing off new functionality).

 I admit my motives might extended beyond just the benefits of the PCE, but I find the platform a comfortable choice since I know it so well; I'm interested in both compiler work and implementing different programming concepts. That said, I'm actually kinda excited to do a C project for the PCE with the new changes/upgrades. This.. coming from an assembly-to-the-core guy for PCE. Heh.

 
« Last Edit: August 22, 2016, 04:29:07 PM by Bonknuts »

dshadoff

  • Full Member
  • ***
  • Posts: 175
Re: The new fork of HuC
« Reply #27 on: August 23, 2016, 12:53:27 PM »
If you really want to talk about high-level programming, then even more important than the compiler is the set of libraries and base functions which are available to the programmer out-of-the-box.

HuC implemented many things which had not been attempted or available before - and were developed as part of the work of HuC:

Such as:

- CD-ROM boot (and a dual-boot option which some had thought was not possible)
- standard hooks into the CDROM card (including documentation), and replacements of most functions for HuCard builds
- more access to the VDC than had been available previously
- an integrated font and print functions (not just POSIX streaming to a termnal device)
- access to backup ram functionality
- PCE mouse functionality
- a clock timer
- random number generator
- a standard set of IPL routines (including initialization to various resolution modes)
etc.

A lot of work went into this functionality which could have otherwise been spent on the compiler - but then the compiler would have been even less useful.

While you work on the newer compiler, please keep this in mind and consider the libraries - which would by definition be hand-optimized and the best code available - and make a lush set of building blocks.  If done properly, this could reduce reliance on the code generator for speed and efficiency - and on the language itself for ease-of-programming.

Please be my guest to use what exists in HuC, and build on it where it makes sense.

-Dave

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: The new fork of HuC
« Reply #28 on: August 23, 2016, 01:59:22 PM »
I never posted anything publicly for assembly optimizations, because it's simply hand-converting C code to 6502 assembly.

If you don't know how to do that, me pasting it to you isn't going to help, lol.

It came up briefly in that other thread.   

It's as simple as accessing arrays using 6502 assembly.   That's something any 6502 book will show you, fairly simply.

and then If/Else is just converted to compare/branch code.     Simple, really.    Just find a 6502 tutorial and read how to do compares and indexing.

It's not really a mind blowing process.   It's more like mind numbing.   

The compiler, even if it were to be improved over HuC, would still be a bit goony with regards to doing efficient array usage in something like:
Code: [Select]
if(thing[i] > thingy[i]).
You could make it smart about the generation of stuff, but then it adds alot of complexity to how you generate that code.


Hand converting functional C code to 6502 is OK by me.   It's a great learning experience, and a great encouragement to convert to using z80 instead.

6502 is mental.

lol
« Last Edit: August 23, 2016, 02:01:34 PM by Arkhan »
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: The new fork of HuC
« Reply #29 on: August 23, 2016, 08:02:57 PM »
The compiler, even if it were to be improved over HuC, would still be a bit goony with regards to doing efficient array usage in something like:
Code: [Select]
if(thing[i] > thingy[i]).
You could make it smart about the generation of stuff, but then it adds alot of complexity to how you generate that code.
HuC 3.98 code generation isn't too bad:
Code: [Select]
__ldub _arr1+1
__pushw
__ldub _arr2+1
  jsr gt
__ldub is just ldx $abs and then a "cla", which is pretty fast. __pushw is a bit ugly since it uses the larger stack by default, but Uli has working optimization switches which use a much faster internal stack method in the code generation. At least the array access is fast.

 Dshadoff: That's a great point. Sometimes I forget just how much work was put into the library for HuC.