<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://c64mags.untergrund.net/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://c64mags.untergrund.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Skyhigh_20_Coding_chapter</id>
		<title>Skyhigh 20 Coding chapter - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://c64mags.untergrund.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Skyhigh_20_Coding_chapter"/>
		<link rel="alternate" type="text/html" href="http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_20_Coding_chapter&amp;action=history"/>
		<updated>2026-06-13T13:26:04Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.0</generator>

	<entry>
		<id>http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_20_Coding_chapter&amp;diff=3852&amp;oldid=prev</id>
		<title>Ymgve at 17:16, 29 November 2007</title>
		<link rel="alternate" type="text/html" href="http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_20_Coding_chapter&amp;diff=3852&amp;oldid=prev"/>
				<updated>2007-11-29T17:16:14Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;Coding chapter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hmm....&lt;br /&gt;
&lt;br /&gt;
It strikes me as very odd that when Skyhigh is a&lt;br /&gt;
magazine produced by one of the ruling demogroups,&lt;br /&gt;
Camelot, which has some of the best coders on the&lt;br /&gt;
C64 in it, that the coding chapter for the mag is&lt;br /&gt;
going to be hosted by someone who does not really&lt;br /&gt;
class as a coder. Yup, I bet when you saw that there&lt;br /&gt;
was a coding chapter in this issue, you thought that&lt;br /&gt;
Raz, Glasnost, Slammer etc would be hosting it. But,&lt;br /&gt;
sadly, the duty has fallen to your fool of the hour,&lt;br /&gt;
Shuze.&lt;br /&gt;
&lt;br /&gt;
Coding chapters in magazines are truly bizarre, it&lt;br /&gt;
must be said. They are also the easiest in the world&lt;br /&gt;
to do if you are feeling lazy. After all, I don't think&lt;br /&gt;
I could count as high as I would need to, just to&lt;br /&gt;
count the amount of magazines which have listed all&lt;br /&gt;
the Kernal routines. The same applies for the mags&lt;br /&gt;
which have listed illegal opcodes. The word &amp;quot;boring&amp;quot;&lt;br /&gt;
immediately springs to mind.&lt;br /&gt;
&lt;br /&gt;
So, this is going to be a different chapter. What I am&lt;br /&gt;
planning to do is start on a project, and I will tell&lt;br /&gt;
you all, in theory, how to do all the important bits&lt;br /&gt;
of the coding.&lt;br /&gt;
&lt;br /&gt;
I will also be slipping in tips here and there, to help&lt;br /&gt;
you speed up your code, and so on. But I won't list&lt;br /&gt;
any fucking illegal opcodes....&lt;br /&gt;
&lt;br /&gt;
OK, the best thing I think we should work towards is&lt;br /&gt;
this:&lt;br /&gt;
&lt;br /&gt;
HOW TO CODE A MAGAZINE OUTFIT&lt;br /&gt;
HOW TO CODE A MAGAZINE OUTFIT&lt;br /&gt;
&lt;br /&gt;
It seems a better and better idea every second to&lt;br /&gt;
get Raz to do this....&lt;br /&gt;
&lt;br /&gt;
Anway, lets decide on a few parameters for our&lt;br /&gt;
magazine's outfit. Imagine we have a real cunt of an&lt;br /&gt;
editor who wants a load of totally unreasonble&lt;br /&gt;
things done with the outfit (that's you, NTI! 8-):&lt;br /&gt;
&lt;br /&gt;
1) A proportional displayer/upscroller&lt;br /&gt;
2)  An IRQ loader&lt;br /&gt;
3)  A scrolling menu&lt;br /&gt;
4) A logo above the text display&lt;br /&gt;
&lt;br /&gt;
And some other stuff.&lt;br /&gt;
&lt;br /&gt;
So, lets begin shall we, with a proportional displayer&lt;br /&gt;
for our unreasonable editor.&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&lt;br /&gt;
As I said, I am not going to give you any code yet,&lt;br /&gt;
but am instead just going to give you a lot of help&lt;br /&gt;
on how you can code your own. If I can persuade&lt;br /&gt;
either Biz Kid or Cupid to do some logo's and fonts&lt;br /&gt;
for me, and Metal to do some music, I guess I will&lt;br /&gt;
actually do all the code, and link it as an extra.&lt;br /&gt;
&lt;br /&gt;
OK, part one is a proportional displayer.&lt;br /&gt;
&lt;br /&gt;
These things are actually a standard on PC software&lt;br /&gt;
these days, due to the extra speed of such&lt;br /&gt;
computers. But, they are still perfectly reasonable&lt;br /&gt;
on the C64, as you obviously have seen, from this&lt;br /&gt;
mag! The general idea is that each letter only fills&lt;br /&gt;
the space that it needs, instead of the typical C64&lt;br /&gt;
way, where each character fills 8 bits across, and&lt;br /&gt;
8 bytes down. So, each character takes up 64 bits,&lt;br /&gt;
even though it may only be like the letter &amp;quot;i&amp;quot;, and&lt;br /&gt;
really fill 1 bit across. The idea of a proportional&lt;br /&gt;
font is that it only takes up that one bit (or 2, as it&lt;br /&gt;
will have a blank bit on the right, so all the letters&lt;br /&gt;
are not stuck onto each other).&lt;br /&gt;
&lt;br /&gt;
OK, so now you know the idea, this is how it is done.&lt;br /&gt;
&lt;br /&gt;
There are two ways in which you can show your font&lt;br /&gt;
on the screen. The first way is to use a bitmap&lt;br /&gt;
screen, which is NOT the method that this outfit&lt;br /&gt;
uses, but is the best method for a normal displayer.&lt;br /&gt;
That is what we will use. The second method is the&lt;br /&gt;
one that this magazine, and The Relax use, to allow&lt;br /&gt;
an upscroller. That involves splitting the screen&lt;br /&gt;
into horizontal bars, with a raster split. In each of&lt;br /&gt;
those bars, you display a NORMAL block of text, with&lt;br /&gt;
40 chars across, and 6 chars down. Then, on each of&lt;br /&gt;
the raster splits, you change the charset. The idea&lt;br /&gt;
is to have, for example, in the top block, the chars&lt;br /&gt;
numbered 0 to 239. That is 6 rows and 40 columns&lt;br /&gt;
of chars, all of which are different. If you know&lt;br /&gt;
anything about the way a font is defined, the data&lt;br /&gt;
is held in the exact same way as a bitmap screen, so&lt;br /&gt;
what you do is that you treat the charset data the&lt;br /&gt;
same as how you would treat a bitmap screen. So, if&lt;br /&gt;
bar one has the charset stored at $2000 to $2800,&lt;br /&gt;
you would say &amp;quot;OK, so the first 6 row's bitmap screen&lt;br /&gt;
is at $2000 to $2800. The second 6 row's is stored&lt;br /&gt;
at $2800-$3000, and so on....&amp;quot; But, because you are&lt;br /&gt;
only using 240 of the characters in the $800 bytes&lt;br /&gt;
of screen store, instead of 256, the screen for each&lt;br /&gt;
bar is really only stored at $800 - ($10*$8), as you&lt;br /&gt;
are not using 16 chars worth of data, which is the&lt;br /&gt;
same as 16*8 (16 chars*8 bytes), which is, in hex,&lt;br /&gt;
$10*$8. So, you have to be careful of that.&lt;br /&gt;
&lt;br /&gt;
Anyway, that is neither here nor there, as we are&lt;br /&gt;
using the first far simpler method of a plain old&lt;br /&gt;
bitmap screen. We will use the second method when&lt;br /&gt;
we get onto doing a proportional upscroller. Eek.&lt;br /&gt;
&lt;br /&gt;
OK, so now we move onto the theory of proportional&lt;br /&gt;
fonts.&lt;br /&gt;
&lt;br /&gt;
The very first thing you need is a charset, and a&lt;br /&gt;
list of lengths. The charset is in the usual format&lt;br /&gt;
and attatched to them are the lengths, which are&lt;br /&gt;
$100 (256) bytes long. Each byte in the lenghts is&lt;br /&gt;
in the corresponding position to the screen code&lt;br /&gt;
of the letter in question. So, if you store the&lt;br /&gt;
lengths at position $4000 to $4100, the length at&lt;br /&gt;
position $4001 is the length for the letter &amp;quot;a&amp;quot;. And&lt;br /&gt;
$4002 is &amp;quot;b&amp;quot;, $4003 is &amp;quot;c&amp;quot; and so on. This makes life&lt;br /&gt;
very easy, as if you want to get the length of the&lt;br /&gt;
letter &amp;quot;a&amp;quot;, you will already have the screen code&lt;br /&gt;
somewhere, probably in the A register. So, just move&lt;br /&gt;
it to the X register, and do:&lt;br /&gt;
&lt;br /&gt;
LDA $4000,X&lt;br /&gt;
&lt;br /&gt;
To get the length for the letter &amp;quot;a&amp;quot;. Clever, eh?&lt;br /&gt;
&lt;br /&gt;
As a note, the easiest way to get the lengths is to&lt;br /&gt;
use a small programme called &amp;quot;Proportional Convert&amp;quot;&lt;br /&gt;
coded by Fuben/Oxyron. It will give you the lengths&lt;br /&gt;
that you need. You can actuall put some code in&lt;br /&gt;
your proportional routine to work out the length&lt;br /&gt;
for you, but all it does is slow the whole lot down.&lt;br /&gt;
&lt;br /&gt;
OK, so we have our data, and our lengths. Now, onto&lt;br /&gt;
the hard stuff.&lt;br /&gt;
&lt;br /&gt;
Imagine we are at the start of the top line, so since&lt;br /&gt;
we are storing our bitmap at $2000, we are at that&lt;br /&gt;
position.&lt;br /&gt;
&lt;br /&gt;
What we do is get the character we want to display&lt;br /&gt;
from the memory (remember, we have already coded&lt;br /&gt;
our text editor (ha!)). Lets say it is the letter &amp;quot;a&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We know we are at the start of the line, so what we&lt;br /&gt;
do is to get the data, and we want to store it at the&lt;br /&gt;
right position.&lt;br /&gt;
&lt;br /&gt;
So, what we do is to get the position from 0 to 7 of&lt;br /&gt;
where the last letter ended. Since we are at the&lt;br /&gt;
start of the line, it is 0. So, we do not have to move&lt;br /&gt;
the data over any.&lt;br /&gt;
&lt;br /&gt;
We then just pick up the charset data, and store&lt;br /&gt;
it in th bitmap screen, at $2000-$2007. The best way&lt;br /&gt;
to store it is with an ORA command. OK, then we check&lt;br /&gt;
the length of the character.&lt;br /&gt;
&lt;br /&gt;
We know the oldlength was 0, and the length of the&lt;br /&gt;
letter &amp;quot;a&amp;quot; is 7 (as we got the before). So, 0+7 is 7,&lt;br /&gt;
so we know that it fitted into the space. If it had&lt;br /&gt;
been greater that 8, then we would know the letter&lt;br /&gt;
had not fitted. Anyway, lets move on.&lt;br /&gt;
&lt;br /&gt;
Store the 7 somewhere, as we need that for the&lt;br /&gt;
next letter, we'll store it at $FB.&lt;br /&gt;
&lt;br /&gt;
So, increment the counter of the letter we are&lt;br /&gt;
getting next.&lt;br /&gt;
&lt;br /&gt;
The next letter we get is the letter &amp;quot;b&amp;quot;. So, get the&lt;br /&gt;
value in $FB. Oops, it is 7. OK, so what we do now is&lt;br /&gt;
this. We just store the letter as normal, but in the&lt;br /&gt;
loop where we pick it up from the data and place&lt;br /&gt;
it on the screen, we LSR the data $FB times. So, what&lt;br /&gt;
we are doing is moving all the data 7 positions to the&lt;br /&gt;
right. That then means that the data at positions&lt;br /&gt;
$2000 to $2007 is the whole letter &amp;quot;a&amp;quot;, and only one&lt;br /&gt;
pixel of the letter &amp;quot;b&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
So, add $FB and the length of the letter &amp;quot;b&amp;quot;, which&lt;br /&gt;
we find to be 7 also.&lt;br /&gt;
&lt;br /&gt;
So, 7+7=14. Oops, bigger than 8, so we know that the&lt;br /&gt;
letter has not fully fitted into the space $2000 to&lt;br /&gt;
$2007. So, we store the value 14 at $FC for future&lt;br /&gt;
reference.&lt;br /&gt;
&lt;br /&gt;
Then, we don't get another letter, we move onto a&lt;br /&gt;
new loop we have not met yet. OK, this loop again&lt;br /&gt;
gets the data we want, but it is a little different.&lt;br /&gt;
Instead of getting the value in $FB, and LSRing is,&lt;br /&gt;
we want to ASL the data, as now we are dealing with&lt;br /&gt;
the RIGHT side of the letter. Confusing?&lt;br /&gt;
&lt;br /&gt;
OK, but how do we know how many we want to ASL&lt;br /&gt;
it. This is the numbers bit....&lt;br /&gt;
&lt;br /&gt;
OK, since we fitted in 1 column of the letter &amp;quot;b&amp;quot;, it&lt;br /&gt;
means that column 1 has been printed. So, we want&lt;br /&gt;
to move it over 1 bit to the left. So, we get the&lt;br /&gt;
value in $FB, and subtract it from $8, as then we&lt;br /&gt;
get 1. And that is right, as if the value in $FB had&lt;br /&gt;
been 5, and we had fitted in 3 columns of the letter,&lt;br /&gt;
we would want to move the letter 3 bits left, which&lt;br /&gt;
is 8-5.&lt;br /&gt;
&lt;br /&gt;
So, what you then do is to get $FB, and subtract it&lt;br /&gt;
from 8 (remember to set the carry or the maths will&lt;br /&gt;
bug here and there....) and then in your loop where&lt;br /&gt;
you display the letter, ASL each byte 8-$FB times.&lt;br /&gt;
Simple?!?!?!?!?&lt;br /&gt;
&lt;br /&gt;
So, now what you have to remember to do is to get&lt;br /&gt;
the length of the letter &amp;quot;b&amp;quot;, and subtract 8-$FB&lt;br /&gt;
from it, to get the length that you want to be stored&lt;br /&gt;
in $FB next time. Then, from this loop, what you do is&lt;br /&gt;
add 8 to the place where you are storing the data,&lt;br /&gt;
so that it is then stored at $2008-$200F, and so on.&lt;br /&gt;
&lt;br /&gt;
And then you continue in a loop.&lt;br /&gt;
&lt;br /&gt;
Obviously, if you are doing that on the IRQ, you want&lt;br /&gt;
to keep a count of the amount of letters you are&lt;br /&gt;
doing, and find out how many letters you can do in&lt;br /&gt;
each frame. Using that method, I have got mine to&lt;br /&gt;
display rougly 20 letters per frame, which is about&lt;br /&gt;
as fast as you need.&lt;br /&gt;
&lt;br /&gt;
OK, so I will summarise the whole thing in a simple&lt;br /&gt;
algorithm:&lt;br /&gt;
&lt;br /&gt;
1) Get character&lt;br /&gt;
2) Get $FB&lt;br /&gt;
3) Get data and store it in the position, LSRing the&lt;br /&gt;
data $FB times&lt;br /&gt;
4) Add the letter length to $FB, and store it at $FC&lt;br /&gt;
5) If $FC&amp;amp;gt;8 then goto 10&lt;br /&gt;
6) Store $FC at $FB&lt;br /&gt;
7) Increment the letter-getting routine&lt;br /&gt;
8) Goto 1&lt;br /&gt;
9) ;&lt;br /&gt;
10) Store 8-$FB at $FD&lt;br /&gt;
11) Get the data and store it in the right position,&lt;br /&gt;
ASLing it $FD times&lt;br /&gt;
12) Store charlength-$FD at $FB&lt;br /&gt;
13) Add 8 to the position where the data is being&lt;br /&gt;
stored in the bitmap screen&lt;br /&gt;
14) Increment the letter getting routine&lt;br /&gt;
15) Goto 1&lt;br /&gt;
&lt;br /&gt;
And that is it, except that you need a few more&lt;br /&gt;
routines to code a mag outfit. The main ones are&lt;br /&gt;
routines to check if the letter you have got is a&lt;br /&gt;
marker for the end of a line or page.&lt;br /&gt;
&lt;br /&gt;
For that, just check if the letter you have gotten&lt;br /&gt;
is equal to a $00 byte, and if so, then store 0 at&lt;br /&gt;
$FB, and change the position that the text is being&lt;br /&gt;
stored at. It is easier to store somewhere the&lt;br /&gt;
position in memory of the start of the line you are&lt;br /&gt;
on (so, store the bytes $00 and $20 somewhere) and&lt;br /&gt;
then if you rech a $00 byte, add 320 to those bytes,&lt;br /&gt;
by the usual hi/lo byte method (i.e. add 160 to the&lt;br /&gt;
$00 byte, and if the carry is set, increment the $20&lt;br /&gt;
byte, then do that again, to add 320). Then, store&lt;br /&gt;
that value at the loop that displays the text.&lt;br /&gt;
&lt;br /&gt;
Then, you need an end of page routine, which is easy,&lt;br /&gt;
as all you do is check, when you hit an $00 byte, if&lt;br /&gt;
adding 320 will take you past the end of your page,&lt;br /&gt;
and if so, then you set an end flag, and wait for the&lt;br /&gt;
spacebar to be pressed, or the joystick, or&lt;br /&gt;
something like that. Going backwards through the&lt;br /&gt;
text is a little more difficult, as then you then have&lt;br /&gt;
to scan backwards through a certain amount of $00&lt;br /&gt;
bytes. But, if you have an end marker at the end of&lt;br /&gt;
a page, like Raz does in this outfit, it is a lot easier.&lt;br /&gt;
&lt;br /&gt;
And that is it.&lt;br /&gt;
&lt;br /&gt;
Next time, we will go over the theory of a&lt;br /&gt;
proportional upscroller and I will hopefully code&lt;br /&gt;
one to show you how it is done. Sadly, there will be&lt;br /&gt;
no code on this issue from me, as I have already&lt;br /&gt;
gone 3 days over my deadline from Biz Kid, so I do&lt;br /&gt;
not have time to do more! But, hopefully we can&lt;br /&gt;
squeeze Fuben/Oxyron's proportional converter on&lt;br /&gt;
this issue for you.&lt;br /&gt;
&lt;br /&gt;
Ok then, that is it. I particularly need your comments&lt;br /&gt;
on this chapter so that I can try and make it more&lt;br /&gt;
reader friendly, so either get in touch, or write a&lt;br /&gt;
reaction on a sheet. Thanks a lot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Shuze/AFL'70&lt;br /&gt;
&lt;br /&gt;
(I really would have included the proportional con-&lt;br /&gt;
verter from my cool buddy Fuben, but Shuze forgot&lt;br /&gt;
to include it on his disk, and I can't find my own ver-&lt;br /&gt;
sion!! So I guess you will have to wait for the next&lt;br /&gt;
issue to get it - right Paul!!  -bk!)&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ymgve</name></author>	</entry>

	</feed>