Date : Tue, 27 Mar 2001 17:58:33 +0100
From : Tom Seddon <T.W.Seddon@...>
Subject: Re: 2 requests
>===== Original Message From Thomas Harte <t.harte@...> ====
>Sent my reply straight to the original poster, as I usually quite stupidly
>do, but is this a good solution to 'decoding a BBC [80 column] screen
>address' ?
Here is an alternative. I like it because it uses a table, but just a small
one. Now you can turn an address into an (X,Y) with one subtract and some
shifts and ands. The table looks like this:
struct xy {
int x,y;
};
xy table[160];
For 80 column modes:
for(int a=0,i=0;a<20480;a+=128,++i) {
table[i].y=(a/640);
table[i].x=(a%640)>>3;
}
And for 40:
for(int a=0,i=0;a<10240;a+=64,++i) {
table[i].y=a/320;
table[i].x=(a%320)>>3;
}
now, to calculate the X and Y of a given point on screen:
// a -> BBC address
// r -> points to xy filled in with (X,Y) coordinates on screen
void calc(WORD a,xy *r) {
a-=0x3000;//&3000 aka HIMEM for the mode in question
*r=table[a>>7];// >>6 for 40 col modes
a&=127;//63 for 40 col modes
r->x+=a>>3;
r->y+=a&7;
}
Note that there is no need to calculate wrapping to the next line, as the
first location on any line has a table entry. With some fiddling with 'a',
it should be possible to take into account hardware scrolling as well.
Changes to 6845 R1 will require rebuilding the table, though as it's small
itmight not be a problem to precalculate all the possibilities beforehand.
Note also this is all off the top of my head so there may be mistakes in
the above... it _should_ work though :-)
--
--Tom
+-----------------------+-----------------------------------------+
| T.W.Seddon@... | My other life is 3rd person perspective |
+-----------------------+-----------------------------------------+