Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » [RetroHack] Start of competition

This thread is locked; no one can reply to it. rss feed Print
[RetroHack] Start of competition
HardTranceFan
Member #7,317
June 2006
avatar

n/m - I think I'm a bit slow when it comes to understanding the colour schemes...

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Thomas Harte
Member #33
April 2000
avatar

Big long, rambling post...

Quote:

Wasn't aware of that, sorry. I've never seen a BBC Micro in real life, and I'm not even sure they were ever available here (Poland being part of the socialist block back then).

Anyway, I just want to get the most kick out of participating and trying new things - hence doing my own tracker is just something to boost my own satisfaction .

Makes sense. And I was aware that the PSG file format is quite bloated and hard to create data for when I was implementing it. An earlier version of the library also had a RetroHack-specific file format implemented which tried to reach something a lot like a tracker format from compression of a PSG, but I couldn't really justify the time it was taking to get right. And it wouldn't have fixed the latter problem anyway.

Quote:

Thomas, any chance of modifying the library to play .ay files?

It seems I may need to implement a fully functional Z80 emulator to fully support AY files, at least based on the docs I eventually found bundled with a program called AYMakeR. Well, strictly speaking I think I'd need a Z80 emulator and a 68000 emulator, but I'm assured that most PC players don't support the 68000 code so I think I can ignore that. Luckily I have a full Z80 emulator to hand but it's both very multithreaded (as an easy way to implement coroutines — I care about the accuracy of my emulators) and about 45 kB in size. Which is quite a lot out of 512 kB. Nevertheless I'll see what I can do.

Responding to a request not on this thread, I also want to put some sort of graphics conversion tool together...

Quote:

Just starting here.. and I'm wondering about colors, each sprite can use one 16-color palette out of the following 48 palettes - did I interpret that right?

The main difference I can see between yours and the ones I've just got the RetroHack simulator to spit out (subject to an observation below, source code attached) is in the RT_MIX set. Did you notice that the low two bits of the colour info in the sprite get separated, one becoming the high bit on the Cb channel and the other becoming the high bit on the Cr channel?

This has actually uncovered another bug in version 1.0 of the library — it doesn't cram RT_MIX in correctly. An attached example program should display all the colour combos.

At the minute, with the bug, it shows (please ignore my haphazard cropping):

http://www.allegro.cc/files/attachment/593580

When fixed it should show:
http://www.allegro.cc/files/attachment/593581

If you want to apply the fix yourself in the run up to version 1.1 then go into retrohack.c, find the two instances of "RT_MIX" (should be at or around lines 321 and 338) and change the lines beneath so that they're masking the first two things by 0xc instead of 0xb, i.e.

putpixel(newgraphic->images[c], x, y, (((Colour & 0xc) << 4) | ((c&0xc) << 2) | ((Colour & 0x2) << 2) | ((c&0x2) << 1) | ((Colour & 0x1) << 1) | (c&0x1))^COLOUR_MASK);

and

newgraphic->MaskCols[c] = (((maskcol & 0xc) << 4) | ((c&0xc) << 2) | ((maskcol&0x2) << 2) | ((c&0x2) << 1) | ((maskcol&0x1) << 1) | (c&0x1))^COLOUR_MASK;

Respectively.

Quote:

Jakub! Also You could release your tracker for other person using... like me

Just to reiterate for any third parties dropping into the conversation: this is explicitly allowed.

Richard Phipps
Member #1,632
November 2001
avatar

Has anyone got any progress to show yet?

X-G
Member #856
December 2000
avatar

Just this:

http://www.allegro.cc/files/attachment/593582

I have to be honest, the thing that's most difficult to work around right now is the colors available. Not the bit depth... 16 colors is enough to make some real dandy sprites. No, the problem is the overabundance of green tones, the lack of any deep dark tones, and the fact that you can't mix-and-match colors the way you want. It means you end up wasting 60-80% of all the colors in each palette, which is annoying. The luma gamut is wider than it needs to be, and the chroma gamuts are too small. It makes you have to do some funky things, but that's all right. It's what this is about, working under constraints. Just mentioning what's giving me the most trouble right now.

EDIT: Improved him a little.

http://www.allegro.cc/files/attachment/593584

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Elias
Member #358
May 2000

Quote:

The main difference I can see between yours and the ones I've just got the RetroHack simulator to spit out (subject to an observation below, source code attached) is in the RT_MIX set. Did you notice that the low two bits of the colour info in the sprite get separated, one becoming the high bit on the Cb channel and the other becoming the high bit on the Cr channel?

Thanks, indeed. (I updated the picture in my previous post to not confuse anyone.)

--
"Either help out or stop whining" - Evert

Thomas Harte
Member #33
April 2000
avatar

Right. A new test version 1.1 of the RetroHack library is attached. It hopefully addresses the issues found with:

  • plain #including the library from C++

  • the RT_MIX colour palette

  • sound playback on machines with high latency

Please test! I'll rebuild the sample programs for OS X and Windows, and be back promptly.

EDIT: Never mind! I've finally managed to recreate HardTranceFan's sound issues under Windows on my own machine. Hopefully I can get completely to the bottom of this now.

Elias
Member #358
May 2000

The demo still works here in linux :)

You might want to fix the following warnings for gcc -W -Wall to work:

gcc -o retrohack.o -c -W -Wall -Wno-unused-parameter -I/usr/local/include retrohack.c
retrohack.c: In function '__ay_Init':
retrohack.c:792: warning: suggest parentheses around assignment used as truth value
retrohack.c: In function '__ay_Update':
retrohack.c:1099: warning: suggest parentheses around assignment used as truth value
retrohack.c:1120: warning: comparison between signed and unsigned
retrohack.c:1120: warning: comparison between signed and unsigned
retrohack.c:1128: warning: comparison between signed and unsigned

[edit:]
I just hit a problem costing me some time to solve - some colors in the 1x1 bitmap palette have the same RGB value, which causes Gimp to use them in a non-deterministic way on saving. So in case someone else hits this problem, just very slightly changing one of the two colors for all pairs of identical colors so they are unique makes it work.

Oh, and I'm making a sequel to my last retrohack entry - "Tom the Tomato 2". This is the current placeholder for Tom, but I also got an artist now so it should improve a lot yet. http://www.allegro.cc/files/attachment/593586

--
"Either help out or stop whining" - Evert

HardTranceFan
Member #7,317
June 2006
avatar

I now don't even have a blank screen anymore - my PC crashed on boot up this morning!

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Thomas Harte
Member #33
April 2000
avatar

Right, I think I cracked the sound problems. Under Windows, Allegro seems to have an interesting 'feature' whereby get_audio_stream_buffer() won't return anything for quite a while, then will suddenly have four or five buffers ready to fill at once. That removes any way to know anything useful about where Allegro is in playing your audiostream (and is strictly contrary to the documented behaviour of the function, but I'll post in the right place to complain about that), which is what was confusing my code.

I've rejigged it to deal with that, though it has the disadvantage that if your setup is one of those affected then sound latency can be quite bad. At the minute I can't think of a way to avoid that with Allegro, so commiserations to affected people. Fingers crossed this misbehaviour is related to the Allegro/sound driver combination and not to the Allegro/Windows combination.

OS X, Linux and any other platform where Allegro works as described in the manual should be unaffected and continue to work well.

Anyway, new test version of the library is here. Also: Windows test programs, OS X test programs.

HardTranceFan
Member #7,317
June 2006
avatar

Quote:

Responding to a request not on this thread, I also want to put some sort of graphics conversion tool together...

Oh, yes please! Trying to get my head around the colour schemes is driving me nuts. I completely forgot about the colour formats until Elias pointed out the total of 48x16 colour palettes. I'm used to true colour and the Amstrad colour schemes, and I'm finding this is taking a little bit of thought.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

X-G
Member #856
December 2000
avatar

1import yaml
2import sys
3from struct import pack
4from PIL import Image
5 
6if __name__ == "__main__":
7
8 imagedef = yaml.load(file("gfxconv.yaml", "r"))
9
10 for image in imagedef:
11 print "Processing %s..." % image["infile"]
12 # Open source bitmap
13 srcimg = Image.open(image["infile"])
14 w, h = srcimg.size
15
16 # Open output raw
17 ofp = file("../bin/" + image["infile"][:-3]+"rts", "wb")
18
19 # Write frame size
20 fw, fh = w, h
21 try:
22 fw, fh = image["framesize"]
23 except KeyError:
24 pass
25 ofp.write(pack("BB", fw, fh))
26 ofp.write(pack("B", int(h/fh)))
27
28 # Write palette type
29 ft = {"Y":0, "CbCr":1, "MIX":2}[image["mode"]]
30 pal = image["palette"]
31 composite = (ft << 6) + (pal & 0x1F)
32 ofp.write(pack("B", composite))
33
34 # Convert and write all the image data.
35 for y in xrange(h):
36 for x in xrange(w / 2):
37 left = srcimg.getpixel((x*2, y))
38 right = srcimg.getpixel((x*2 + 1, y))
39 composite = ((left << 4) & 0xF0) + (right & 0x0F);
40 ofp.write(pack("B", composite))
41
42 # Done with this file.
43 ofp.close()
44
45 exit(0)

This is a Python script I whipped out that converts a 16-bit paletted image into a format suitable for uploading to retrohack video memory, plus hints for what mode and nibble to use as well as frame size information. As you can see it's pretty hardcoded right now, but it reads a file called gfxconv.yaml in the same directory which looks like this:

- infile: friedrich.bmp
  mode: MIX
  palette: 1
  framesize: [26, 26]
- infile: friedrich_b.bmp
  mode: CbCr
  palette: 0
  framesize: [26, 26]

It needs pyYAML and PIL, obviously. Do let me know if you find it useful.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Thomas Harte
Member #33
April 2000
avatar

Further to this general topic, a new RetroHack example program is attached (and will shortly appear on the website).

It loads 8bpp PCX files (and exactly that format only), maps them onto the best fitting RetroHack palette (without dithering), uploads them to graphics memory and returns a colour parameter for you to pass to Blit or MaskedBlit.

The one useful function is:

void *rtSup_LoadPCX(char *Name, int *OtherNibble, int Masked)

Where:
Name is the filename of the graphic to be loaded.
OtherNibble is an integer that will be filled with the value you should pass as OtherNibble in subsequent calls to Blit/MaskedBlit to get the best colour match.
Masked is a boolean (i.e. pass TRUE or FALSE) that hints whether this is a graphic intended for masked blitting or not. If you pass FALSE then all colours in the graphic are given equal importance. If you pass TRUE then the colour with palette entry 0 in your PCX file is treated as a mask colour. Subsequently the routine doesn't care how closely that colour is mapped to the RetroHack palette and makes sure that no other colour in the graphic you are loading is mapped to the same RetroHack spot.

Included in the demo is a luigi.pcx I just downloaded, and it should display this:
{"name":"593596","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/7\/b7f9625dcdda97c7f63abcb571e38c8d.png","w":653,"h":489,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/7\/b7f9625dcdda97c7f63abcb571e38c8d"}593596

Hope this helps!

EDIT: note that it assumes the RT_MIX palettes are working correctly, as in the v1.1 test releases of the library above, not as in the bugged v1.0. So I recommend you test against that. Especially as I'd also like to know if 1.1 is suitable for proper release.

Elias
Member #358
May 2000

I found the AY data sheet PDF rather scary, but some googling turned up a page with this table, which has 100% of the same relevant info as the whole PDF (scroll down to Yamahatm YM-2149):
http://sc68.atari.org/developers_technicals.html

So, basically, 14 registers, where I can set frequencies and volume, plus noise channel and envelope :)

--
"Either help out or stop whining" - Evert

Thomas Harte
Member #33
April 2000
avatar

Quote:

So, basically, 14 registers, where I can set frequencies and volume, plus noise channel and envelope

Yep, that sounds about right. And the only other potentially interesting thing is that per channel mixing is done with an active low bitwise OR. Which explains how you can get a level wave, as per the sample demo.

Paul Pridham
Member #250
April 2000
avatar

Thomas, what's the license for this code, anyway? There's some neat stuff in there.

Thomas Harte
Member #33
April 2000
avatar

Quote:

Thomas, what's the license for this code, anyway? There's some neat stuff in there.

It's not really that neat, but since there is the potential for other people to create games that are dependent on my code, I guess a license that is as permissive as possible is desirable. I guess I'll adopt the zlib license unless anybody wants anything more flexible?

Paul Pridham
Member #250
April 2000
avatar

Looks good to me!

Jakub Wasilewski
Member #3,653
June 2003
avatar

Having a job sucks. Especially if you want to participate in a competition, but instead, all your computer time at home goes into earning money...

However, I finally managed to save up some time to actually put in a few hours into Retrohack, and I'm pretty happy with the (preliminary) results. The tracker is coming together nicely and I expect to have it somewhat finished by Saturday. I will probably release the source code and all revelant files once I have a "finished product".

For now, I have a demo I would like you to test - it is a Windows binary with an example one-pattern module (with samples and the track itself ripped from Amiga's Lotus 2 and ported to my own text format). I'd like you to give it a few spins and let me know if there are any problems with the playback on your machine. Don't expect wonders though, the quality will be rather crap :).

Thomas:
The binary is linked against Retrohack lib 1.0. Version 1.1 causes the playback to be completely borked on my machine - it plays a fragment properly, then inserts some silence, then plays back something random and finally resumes playing the tune. I rely heavily on RT_HSYNC timing, so it might be me doing something funky. On the other hand, some people have been reporting problems on Windows, so perhaps it's not my fault.

Another thing regarding 1.1 - there is a problem with the retrohack.h header under C++. The Allegro header is wrapped in 'extern "C"', which makes the compiler misunderstand the definition of the fix class and throw an awful lot of errors. Moving #include <allegro.h> outside the 'extern "C"' helps.

Oh, and the thread became awfully silent lately... Come on people, tell us about your progress!

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

HardTranceFan
Member #7,317
June 2006
avatar

Nothing from this corner as yet. Time has been rather sparse in it's availability. However, next week looks more promising for a few decent hours of coding.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Jeff Bernard
Member #6,698
December 2005
avatar

So, I started playing some NES games as research for my RetroHack entry because I want my entry to be kinda like an NES game. In other words, they game would be really fun despite not having breathtaking graphics or sounds.

I've kinda gotten a bit carried away in the sense that I haven't programmed for about a week and I've beaten quite a few NES games and continue to play more.

--
I thought I was wrong once, but I was mistaken.

Jakub Wasilewski
Member #3,653
June 2003
avatar

Quote:

I'd like you to give it a few spins and let me know if there are any problems with the playback on your machine.

So, did anyone try it?

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

Elias
Member #358
May 2000

Quote:

Oh, and the thread became awfully silent lately... Come on people, tell us about your progress!

We are making good progress here. Right now, we are using about 20K out of 64K of video ram - but if Paul keeps drawing sprite frames at the rate has has done until now, it will get a problem :) There's only one sprite so far, which means we can only add two more, to still have room for a few tiles.

Oh, and I'm looking forward to your tracker. I wrote a crude ASCII format so you can define instrument envelopes and define tracks by writing the notes (like "C D E F F#") - but a proper tracker certainly would be preferable.

--
"Either help out or stop whining" - Evert

Jeff Bernard
Member #6,698
December 2005
avatar

Quote:

So, did anyone try it?

Nope. I've been too busy abandoning everything in my life to play as many NES games as I can.;D

--
I thought I was wrong once, but I was mistaken.

Paul Pridham
Member #250
April 2000
avatar

Sorry, haven't tried it either. Too busy... we have a game to make.

Oh yea people, it's on! ;)

HardTranceFan
Member #7,317
June 2006
avatar

@Jakub: I ran it, but it crashed part way through the tune (about 6 seconds into the piece). But the bit before the crash sounded really good :D.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)



Go to: