Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Kick Assembler Thread 2
2009-07-21 17:20
Slammer

Registered: Feb 2004
Posts: 416
Kick Assembler Thread 2

The previous thread took a little long to load, so this is a new fresh one..
 
... 592 posts hidden. Click here to view all posts....
 
2011-07-22 13:29
Frantic

Registered: Mar 2003
Posts: 1635
I added the script to codebase (including TWW's addition). If you make further additions/improvements to this script, don't hesitate to modify the codebase version too! It is here:

http://www.codebase64.org/doku.php?id=base:kick_assembler_macro..
2011-07-22 21:13
Pantaloon

Registered: Aug 2003
Posts: 124
Here are some code to find the closest c-64 color index from an RGB value, usefull when doing image conversion.

there are ofcourse better ways to find the best match but this works ok if you have images with c-64 colors allready.

i use it for my kickasm image converters, can convert sprites / hires / multicolor etc.

	.struct RGB {r,g,b}
	
	.var s_palette = List().add(
			RGB(0,0,0),		// black 0
			RGB(255,255,255),	// white 1
			RGB(104,55,43),		// red 2
			RGB(131,240,220),	// cyan 3
			RGB(111,61,134),	// purple 4
			RGB(89,205,54),		// green 5
			RGB(65,55,205),		// blue 6
			RGB(184,199,111),	// yellow 7
			RGB(209,127,48),	// orange 8
			RGB(67,57,0),		// brown 9	
			RGB(154,103,89),	// light_red 10
			RGB(91,91,91),		// dark_gray 11
			RGB(142,142,142),	// gray 12
			RGB(157,255,157),	// light_green 13
			RGB(117,161,236),	// light_blue 14
			RGB(193,193,193)	// light_gray 15
			);
	
	.function colorDistance(c1,c2)
	{
		.var cr = c1.r-c2.r
		.var cg = c1.g-c2.g
		.var cb = c1.b-c2.b
		.return sqrt([cr*cr] + [cg*cg] + [cb*cb])
	}

	.function getClosestColorIndex(rgb)
	{
		.return getClosestColorIndex(
			rgb, s_palette
			)
	}

	.function getClosestColorIndex(rgb, palette)
	{
		.var distance = colorDistance(rgb, palette.get(0))
		.var closestColorIndex = 0

		.for (var index = 1; index < palette.size(); index++)
		{
			.var d = colorDistance(rgb, palette.get(index))
			.if (d < distance)
			{
				.eval distance = d
				.eval closestColorIndex = index
			}
		}

		.return closestColorIndex
	}


2011-07-23 07:20
Cruzer

Registered: Dec 2001
Posts: 1048
Pantaloon: Nice! My approach is usually to add an extra line to the gfx with the palette, and load them from there to avoid having to type them in manually. But this would be even easier, if it works with all the different colorschemes around.
2011-07-23 14:06
MagerValp

Registered: Dec 2001
Posts: 1060
Quote: Pantaloon: Nice! My approach is usually to add an extra line to the gfx with the palette, and load them from there to avoid having to type them in manually. But this would be even easier, if it works with all the different colorschemes around.

...or just save the image as a 16 color PNG or BMP and ignore the RGB values altogether.
2011-07-23 16:06
algorithm

Registered: May 2002
Posts: 703
Quote: Nice one.. Btw. There is an error directive so you can fail if the number of chars exceeds 256.

The below tool can be used to pack a full screen image (or many images) to 256 chars. non-lossy if there are less than 256 unique 8x8 blocks. Lossy if more.
CSAM V3

2011-08-01 15:00
tlr

Registered: Sep 2003
Posts: 1739
Maybe this has been discussed before but:

If I do this...
.const str = "TESTING"
text:
	.fill	str.size(), str.charAt(i) & $3f
...or this...
.const str = "TESTING"
.function to_scr(c) {
    .return c & $3f
}
text:
	.fill	str.size(), to_scr(str.charAt(i))
... Kick Assembler 3.18 fails to recognize the '&' operator.

however this works:
.const str = "TESTING"
text:
	.fill	str.size(), $3f & str.charAt(i)

My guess that this is a problem with implicit casting of chars, no?

It took a while to figure out. I'd prefer if both ways of ordering worked or if it was at least documented... ;)
2011-08-01 15:44
Slammer

Registered: Feb 2004
Posts: 416
Good question.

Kick Assembler works with objects, just like object oriented languages like C++, C# and java. Each class of objects has
assigned a set of functions and operators. Eg. a String object has a charAt function, but the number function hasn't.
The & operator is placed on the number object and not on the char object (See documentation).

When you write:
.var a = 'x' & 1
The & operator is called on the char object. But it isn't defined so you will get an error.

But this work:
.var b = 1 & 'x'
The & operator is called on the number object which cast the char object parameter to a number value and performs the and operation.

Guess it would be nice if we could explicitly typecast objects - That will probably be in the next release. Until then you can make a dirty typecast to convert chars into numbers like this:
.var a = [0+'x'] & 1 



EDIT: So yes, it is a issue of casting cos how should the assembler know that we meant the & operator on the number object and the perform the cast to a number? Theoretically, we could have defined an & operator on the String value that appended two strings - should we then implicitly cast to a number or to a string (or to a third value). So the assembler cant decide this and gives an error.
2011-08-01 18:41
JackAsser

Registered: Jun 2002
Posts: 1997
@Slammer: The simple solution would be (as in Java) to treat chars as a kind of number, hence the &-operator would exist on char-objects aswell. I.e. simply allow the &-operator on char-objects. Or let char-class be a subclass of the more general number-class.

Regarding &-operator on strings to concatenate => fine, since string != char. "foo"&"bar" == "foobar" vs 'x'&'y' == 0xSomething. Right?
2011-08-02 10:12
Slammer

Registered: Feb 2004
Posts: 416
Making the char class a subclass of the number class is absolutly a possibility. Im a bit defensive about these things since its easy to implement features with unwanted side effects you cant get rid of cos of backward compatibility.

In java 'o'+'k'=218 but 'o'+'k'="ok" seems more logical, so taking the java approach may also lead to surprises (In this example you can consider the char a subclass of a string).
2011-08-02 10:36
tlr

Registered: Sep 2003
Posts: 1739
Quote: Making the char class a subclass of the number class is absolutly a possibility. Im a bit defensive about these things since its easy to implement features with unwanted side effects you cant get rid of cos of backward compatibility.

In java 'o'+'k'=218 but 'o'+'k'="ok" seems more logical, so taking the java approach may also lead to surprises (In this example you can consider the char a subclass of a string).


Actually for someone (me) who has programmed assembly and C a lot I think 'o'+'k' = 218 is much more logical.

It's pretty common to do LDA #'<char>' and things like that so we should be quite used to seeing it as a number.

Explicit casting instead of 0+'<char>' would be acceptable but the above would be better IMO.

Can it be done with "<string>" + '<char>' still working?
Previous - 1 | ... | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | ... | 61 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Guests online: 67
Top Demos
1 Next Level  (9.7)
2 Mojo  (9.7)
3 13:37  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.7)
6 Uncensored  (9.6)
7 Comaland 100%  (9.6)
8 No Bounds  (9.6)
9 Aliens in Wonderland  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Morph  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Offence  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Stinsen  (9.7)
3 Jeroen Tel  (9.6)
4 Linus  (9.6)
5 MacMagix  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.074 sec.