Jump to content
IGNORED

My Atari Lynx Programming Journal


OldAtAtari

Recommended Posts

3 hours ago, karri said:

The pcx encoding of files have changed recently in Gimp. All modern tools create different pcx format files. I have updated my tools to cope with the new and the old format. But most other tools will fail decoding pcx unless they are updated.

 

If you need to patch sp65 in some version have a look at my commit

https://bitbucket.org/atarilynx/lynx/commits/007a077f6b586c0c0a232b1f47a974f43ded05df

 

So if you are using my cc65 please do a

 

cd lynx/tools

git pull

make -f Makefile.deb

 

You also need to remove the old version before doing this.

Hmmm... I removed /lynx/tools/cc65 and also /usr/local/lib/cc65.

Then I did a git pull.

It responded "Already up to date".

 

My original setup used

"git clone https://bitbucket.org/atarilynx/lynx.git"

 

Does that mean I had the latest and greatest already?

 

 

Link to comment
Share on other sites

2 hours ago, karri said:

Yep. Your version should understand the pcx variants I have seen so far.

Ok, then I have another graphics problem then, on my Linux machine. Not worth fixing at this point though. The Windows setup seems to be working great, so all is well. Thanks as always for the help.

 

 

Edited by OldAtAtari
Link to comment
Share on other sites

25 minutes ago, Positron5 said:

Hi OldAtAtari,

image.thumb.png.78aa8651b08adb56f22f05b29b2d0a14.png

 The errors you get like this are typically typos -like @Karri said. Also I looked at your code and I couldn't see a main() /main(void) function. cc65 is Case sensitive too.

Cheers Positron5.

Thanks, Positron5!

That problem has been resolved. It seems to have not been a typo. I was following an outdated example and calling various collision-related functions and defining various structures that are no longer necessary, and apparently not understood by the new cc65. I deleted all those, and then the compile worked. But then again, maybe there was a typo in the example code I copied in, so deleting the example code got rid of the typo. Either way, all is well now. Thanks again.

Link to comment
Share on other sites

30 minutes ago, Positron5 said:

All good.

The tool chain I use is cc65 for windows, cygwin64 for win, gimp2, mednafen and a lot of head scratching ???

Thank you. I've been curious what people are using. At the moment, I'm doing my code writing and compiling in Linux. As of today, I'm doing my editing in vi (it's about time I learn vi). The jury is still out regarding graphics editors, but I'm leaning toward grafx2, because it seems like a simpler interface, compared to Gimp. And Windows Handy 0.971 for emulation, though I want to track down a copy of Handybug and give that a try.

Link to comment
Share on other sites

39 minutes ago, OldAtAtari said:

The jury is still out regarding graphics editors, but I'm leaning toward grafx2, because it seems like a simpler interface, compared to Gimp.

Just to defend Gimp...

 

There is a reason behind the default palette in the Lynx.

Lynx.gpl

If you put this palette under .gimp-2.8/palettes life gets much easier.

 

Now you can open up the Windows->Dockable Dialogs->Palettes and you find the default palette.

 

262544897_Screenshotfrom2020-08-1719-55-47.png.f7ec3c96e874752619bdfbde276a7bfb.png

 

When you choose the Lynx palette and open up Windows->Dockable Dialogs->Colours you can click on the "palette' icon (5th from left) and end up with the Lynx colours.

 

116967010_Screenshotfrom2020-08-1719-57-15.png.4e1e129288a2979b538e0af779d0afbe.png

 

The colours in this palette are arranged for intuitive editing. The neighbour colours provide logical shade or highlight. So it makes sense to use colours close to each other.

 

I usually re-colour everything in RGB mode using only colours in this palette. Once I am happy with the result I convert the image to indexed.

 

Image->Mode->Indexed

 

Now I can easily convert the image to the desired 16 bit default colours.

608644039_Screenshotfrom2020-08-1720-07-02.thumb.png.f35a29b2f8573a3e77499d789bf3b175.png

 

The important thing is that I do not want to reduce colours. So I leave the tick reduce colours off.

 

After this I scale down the image to the smallest possible size that still leaves the sprite usable.

 

In Titan I can easily activate the default palette with

 

tgi_setpalette(tgi_getdefpalette());

Sometimes I need to use other colours instead of the default colours. For this there is a special command for extracting the palette from the pcx file.

 

sp65 -r picture.pcx -p lynx-palette,pal.c

 

This creates a C-file with just the content of the palette.

/*
 * This file was generated by sp65 2.13.9 from
 * picture.pcx (94x38, 16 colors, indexed)
 */

    0x00,0x03,0x09,0x09,0x07,0x03,0x04,0x07,0x0D,0x0C,0x08,0x02,0x04,0x08,0x0C,0x0F,
    0x11,0x4D,0xAF,0xB8,0x77,0x35,0x48,0x5E,0x5F,0x53,0x22,0x23,0x84,0xE5,0xF5,0xFF,

You can then just add the name of the palette around it and use it in your code.

 

unsigned char pal[] = {

    0x00,0x03,0x09,0x09,0x07,0x03,0x04,0x07,0x0D,0x0C,0x08,0x02,0x04,0x08,0x0C,0x0F,
    0x11,0x4D,0xAF,0xB8,0x77,0x35,0x48,0x5E,0x5F,0x53,0x22,0x23,0x84,0xE5,0xF5,0xFF,

};

tgi_setpalette(pal);

 

 

 

  • Like 1
Link to comment
Share on other sites

13 minutes ago, karri said:

Just to defend Gimp...

 

There is a reason behind the default palette in the Lynx.

Lynx.gpl 342 B · 0 downloads

If you put this palette under .gimp-2.8/palettes life gets much easier.

 

Now you can open up the Windows->Dockable Dialogs->Palettes and you find the default palette.

 

262544897_Screenshotfrom2020-08-1719-55-47.png.f7ec3c96e874752619bdfbde276a7bfb.png

 

When you choose the Lynx palette and open up Windows->Dockable Dialogs->Colours you can click on the "palette' icon (5th from left) and end up with the Lynx colours.

 

116967010_Screenshotfrom2020-08-1719-57-15.png.4e1e129288a2979b538e0af779d0afbe.png

 

The colours in this palette are arranged for intuitive editing. The neighbour colours provide logical shade or highlight. So it makes sense to use colours close to each other.

 

I usually re-colour everything in RGB mode using only colours in this palette. Once I am happy with the result I convert the image to indexed.

 

Image->Mode->Indexed

 

Now I can easily convert the image to the desired 16 bit default colours.

608644039_Screenshotfrom2020-08-1720-07-02.thumb.png.f35a29b2f8573a3e77499d789bf3b175.png

 

The important thing is that I do not want to reduce colours. So I leave the tick reduce colours off.

 

After this I scale down the image to the smallest possible size that still leaves the sprite usable.

 

In Titan I can easily activate the default palette with

 


tgi_setpalette(tgi_getdefpalette());

Sometimes I need to use other colours instead of the default colours. For this there is a special command for extracting the palette from the pcx file.

 


sp65 -r picture.pcx -p lynx-palette,pal.c

 

This creates a C-file with just the content of the palette.


/*
 * This file was generated by sp65 2.13.9 from
 * picture.pcx (94x38, 16 colors, indexed)
 */

    0x00,0x03,0x09,0x09,0x07,0x03,0x04,0x07,0x0D,0x0C,0x08,0x02,0x04,0x08,0x0C,0x0F,
    0x11,0x4D,0xAF,0xB8,0x77,0x35,0x48,0x5E,0x5F,0x53,0x22,0x23,0x84,0xE5,0xF5,0xFF,

You can then just add the name of the palette around it and use it in your code.

 


unsigned char pal[] = {

    0x00,0x03,0x09,0x09,0x07,0x03,0x04,0x07,0x0D,0x0C,0x08,0x02,0x04,0x08,0x0C,0x0F,
    0x11,0x4D,0xAF,0xB8,0x77,0x35,0x48,0x5E,0x5F,0x53,0x22,0x23,0x84,0xE5,0xF5,0xFF,

};

tgi_setpalette(pal);

 

 

 

Wow, that's a helpful message with lots of detail. And it makes Gimp sound pretty good. I'll look forward to trying it. Thank you so much, karri.

Link to comment
Share on other sites

2 minutes ago, OldAtAtari said:

Sometimes I need to use other colours instead of the default colours. For this there is a special command for extracting the palette from the pcx file.

 


sp65 -r picture.pcx -p lynx-palette,pal.c

So for this option, you're saying that you can use any colors that Gimp offers, and then sp65 will reduce it to 16 Lynx-friendly colors and output that palette?

Link to comment
Share on other sites

22 minutes ago, OldAtAtari said:

So for this option, you're saying that you can use any colors that Gimp offers, and then sp65 will reduce it to 16 Lynx-friendly colors and output that palette?

Yes. But Gimp can also choose the 16 closest colours and create a "best palette"

 

But that was not the way I work.

 

The sp65 can extract any 16 colour indexed image palette automatically. sp65 does not do any colour changes.

Screenshot from 2020-08-17 20-55-47.png

  • Like 1
Link to comment
Share on other sites

33 minutes ago, karri said:

Yes. But Gimp can also choose the 16 closest colours and create a "best palette"

But that was not the way I work.

 

The sp65 can extract any 16 colour indexed image palette automatically. sp65 does not do any colour changes.

 

So you're saying if I create an indexed pcx with any 16 colors, sp65 will be able to use those colors in the palette? If so, that's terrific. I figured the colors would have to be tweaked to a certain set of Lynx compatible colors.

Link to comment
Share on other sites

10 minutes ago, OldAtAtari said:

So you're saying if I create an indexed pcx with any 16 colors, sp65 will be able to use those colors in the palette? If so, that's terrific. I figured the colors would have to be tweaked to a certain set of Lynx compatible colors.

Yes, Lynx can use any 12bit RGB color (that are 4096 possible colors), but only 16 of them at the same time (per single row, but this is complicated to achieve, so usually the limit is 16 colors per screen).

 

In Gimp I use to define my 16 colors palette with 24 bits colors. The colors will be scaled down to 12 bits by the converter.

 

And you can change the palette at every frame if you want ?.

 

Or you can mantain the color fixed and change how the pixels maps to the colors with the pens array in the sprite ?.

 

Or both the two ???.

 

 

Link to comment
Share on other sites

"Lynx compatible" means: The colors look good on the old LCD.

But neither sp65 nor sprpck will pick the best colors. You have to do this with Gimp or grafx2 or what ever.

 

See microfnt demo which uses the sub-pixels for a 480x102 display to see what you can do with colors.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Nop90 said:

Yes, Lynx can use any 12bit RGB color (that are 4096 possible colors), but only 16 of them at the same time (per single row, but this is complicated to achieve, so usually the limit is 16 colors per screen).

 

In Gimp I use to define my 16 colors palette with 24 bits colors. The colors will be scaled down to 12 bits by the converter.

 

And you can change the palette at every frame if you want ?.

 

Or you can mantain the color fixed and change how the pixels maps to the colors with the pens array in the sprite ?.

 

Or both the two ???.

 

 

It almost sounds like you're saying that you can use all 4096 colors if you know what you're doing. But for the rest of us, it's 16 colors per screen. ? I can live with that.

Link to comment
Share on other sites

2 minutes ago, 42bs said:

"Lynx compatible" means: The colors look good on the old LCD.

But neither sp65 nor sprpck will pick the best colors. You have to do this with Gimp or grafx2 or what ever.

 

See microfnt demo which uses the sub-pixels for a 480x102 display to see what you can do with colors.

Very nice. Thank you. I'll check out microfnt.

 

Link to comment
Share on other sites

24 minutes ago, 42bs said:

Definitely of interest. While I'm excited that I'm nearly finished with my first game in C, which is just a silly and simple hack of the template game, programming in assembly still seems like the ultimate goal for me, and I'm still learning that on the side. I've completed the general 6502 for Monsters Monsters course (the Youtube version) https://chibiakumas.com/6502/ , and I've started his Lynx-specific assembly course. So yeah, anything that moves me in that direction, including scans of old books, is of interest. Thank you for sharing the link.

Link to comment
Share on other sites

Just updating my journal here, for anyone who's interested.

My silly simple practice game, based on the template's game.c, is done as far as playability and graphics are concerned. Nothing special, but I just wanted to try out some basic graphics, collision, and scorekeeping things.

Now I'm looking at creating sounds. It's a lot to take in. Even with the Getting Started guide and the official documentation for Chipper, I still feel like I'm randomly clicking boxes and hoping it will somehow output a file that I can figure out how to use. Same with ABCmusic, which certainly looks easier, but it still feels like I'm guessing my way through it. So it's a struggle, but that seems to be part of the hobby. I'll keep trying! And I'm sure I'll be asking questions. You guys created all these programming tools, and you know this stuff better than anyone. I appreciate all the support you give on this forum.

Edited by OldAtAtari
Link to comment
Share on other sites

You could have a look at lynx/contrib/abcmusic/cc65version in my bitbucket.org/atarilynx archive.

 

It has a large number of demos in the main.c file.

 

Basically you can play a single note on 4 different Lynx audio channels.

 

A single melody is descibed as characters:

abcplay (0,
       "X7 I0 V100 T20 R0 H8 K4 O5CEG O4CEG O3CEG O2CEG O1CEG O0CEG cegc'e'g'");

 

The first parameter 0,1,2,3 tells which channel we play this on. Then we set up our instrument:

 

X7 - feedback taps
I0 - 0=square wave, 1=intergrated (triangle)
V100 - volume
T20 - tempo
R0 - ramp volume increment at start of note

H8 - hold time of note

K4 - fade out sound decrement

O5 - octave 5

C - note C

E - note E

G - note G
^G - note Gis

G, - note G one octave down

g - note G one octave up

G2 - note G for 2 beats

 

Just go into this directory, type make and run the test.lnx file in your emulator or real Lynx.

test.lnx

  • Like 1
Link to comment
Share on other sites

9 minutes ago, karri said:

You could have a look at lynx/contrib/abcmusic/cc65version in my bitbucket.org/atarilynx archive.

 

It has a large number of demos in the main.c file.

 

Basically you can play a single note on 4 different Lynx audio channels.

 

A single melody is descibed as characters:

abcplay (0,
       "X7 I0 V100 T20 R0 H8 K4 O5CEG O4CEG O3CEG O2CEG O1CEG O0CEG cegc'e'g'");

 

The first parameter 0,1,2,3 tells which channel we play this on. Then we set up our instrument:

 

X7 - feedback taps
I0 - 0=square wave, 1=intergrated (triangle)
V100 - volume
T20 - tempo
R0 - ramp volume increment at start of note

H8 - hold time of note

K4 - fade out sound decrement

O5 - octave 5

C - note C

E - note E

G - note G
^G - note Gis

G, - note G one octave down

g - note G one octave up

G2 - note G for 2 beats

 

Just go into this directory, type make and run the test.lnx file in your emulator or real Lynx.

test.lnx 8.94 kB · 1 download

Hi, Karri. Thank you so much! I've been looking at that directory and playing around with the main.c file, but I hadn't figured out anything that makes as much sense as the cheatsheet you just posted here. Thank you for this.

 

So "G" is just a G, and "G," is an octave lower, and "g" is an octave higher. That alone explains a lot that I was missing before.

I am confused by the output of this. It outputs a .lnx, which is the playable demo. It also outputs a .o file. Is the .o file the one that would get compiled into my game? Your game.c has a sound. I just want to replace that sound with something of my own creation. So would this .o file just replace track2.o in the /template/tunes/ directory? Or am I completely missing the idea?

Thanks again for your support, Karri. I hope if I can just finish this practice game, then I should be set for my future programming endeavors, which much less support needed.
 

Link to comment
Share on other sites

The clue is in the Makefile.

 

objects= \
        abcmusic.o \
        main.o \

target = test.lnx
 

It links 2 object. One is abcmusic.o and the other is main.o

 

The abcmusic.o is actually compiled from abcmusic.s which is the abcmusic library for cc65.

 

You don't need Chipper at all. Just delete the tunes directory and also the lynxsnd.s driver if you go with ABCmusic. Again, look at the Makefile.

 

Actually... You should not use the template at all. Just edit your main.c file to contain your game.

  • Like 1
Link to comment
Share on other sites

2 hours ago, karri said:

The clue is in the Makefile.

 

objects= \
        abcmusic.o \
        main.o \

target = test.lnx
 

It links 2 object. One is abcmusic.o and the other is main.o

 

The abcmusic.o is actually compiled from abcmusic.s which is the abcmusic library for cc65.

 

You don't need Chipper at all. Just delete the tunes directory and also the lynxsnd.s driver if you go with ABCmusic. Again, look at the Makefile.

 

Actually... You should not use the template at all. Just edit your main.c file to contain your game.

Ok, so it sounds like I was on the wrong track (two music puns in that sentence). I'm using game.c, which apparently uses Chipper. So I bet I can delete all the sound related stuff in that file, and then replace it with whatever makes abcmusic work.

So here's my new understanding:

There is a cc65 library called abcmusic.s which I imagine holds all the different bits and pieces that make the thing work. That gets compiled into abcmusic.o. And then the MakeFile combines abcmusic.o with the main program (main.o). So what this does is it gives main.o musical ability, such that you can use lines like this:

abcplay (0,
           "X7 O1 I1 V100 T20 R0 H0 K3 CDEEDEFFEFGEFDGGCDEEDEFFEFGEFDCCcBAABAGGAGFFEDEEcBAABAGGAGFFEDCCECDDFDEEGEFGABccECDDFDEEGEFGABccCDEEDEFFEFGEFDGGCDEEDEFFEFGEF
DCC");

 

Without abcmusic.o, such a line would bomb. But with it, you're able to put the musical string, right there in main.c. Or in my case, if I want a jump sound in game.c, I just have to link game.c with abcmusic.o, along with this section, I bet:

 

extern void abcstop ();
extern void abcplay (unsigned char channel, char *tune);
extern unsigned char abcactive[4];
// Special low-level calls to set up underlying hardware
// abcoctave legal values 0..6
extern void __fastcall__ abcoctave(unsigned char chan, unsigned char val);
// abcpitch legal values 0..255
extern void __fastcall__ abcpitch(unsigned char chan, unsigned char val);
// abctaps legal values 0..511
extern void __fastcall__ abctaps(unsigned char chan, unsigned int val);
// abcintegrate legal values 0..1
extern void __fastcall__ abcintegrate(unsigned char chan, unsigned char val);
// abcvolume legal values 0..127
extern void __fastcall__ abcvolume(unsigned char chan, unsigned char val);

 

So I link to abcmusic.o, I add this extern void setup section, and then I can have abcplay strings of music directly in my code. As opposed to Chipper, which apparently exports sound files that our outside your code, and all you do in your script is refer to them.

Am I getting closer? Close enough that I feel like trying it, so I'll go do that.

 

Thanks, Karri!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...