General Category > Programming

Newbie screen address question

(1/5) > >>

scheeba:
Hi all, was wondering if anyone here could help me out.

I'm using z88dk with cpcrslib, and can get sprites loaded and displaying at 0xc000 just fine. However I'm trying to get them to display at other x/y co-ordinates and I'm having trouble figuring out how the screen address is calculated on the cpc. Any tips on how to convert an x,y co-ordinate on a mode1 screen into an address would be great, thanks.

Bryce:
Have you read this.....

http://www.cpcwiki.eu/index.php/Programming:Fast_Sprites

There might be some tips for you in there.

Bryce.

scheeba:
I read that and a couple of other bits n' pieces, but it all seems well above my level as well as being much more than I need. I just need some reference I can use when placing images onscreen, I don't need to calculate movement or anything. Thanks anyway though.

Grim:
The screen address can be calculated with something like this:

--- Quote ---screenaddr = screenbase + (y AND 7)*&800 + int(y/8)*2*R1 + int(x/M)
--- End quote ---
with:
x and y your 2D coordinate.

R1 = value of CRTC register 1 (eg. 40 with the default firmware settings)

M = 2 (for screen mode 0, 2 pixels/byte)
M = 4 (for screen mode 1, 4 pixels/byte)
M = 8 (for screen mode 2, 8 pixels/byte)

screenbase = &C000

robcfg:
As far as I remember, the screen memory in the cpc is not linear, but character based.

Each character has 8 rows, so the first 80 bytes of memory would be 320 pixels in mode 1, that is the first scanline of the first row of characters. Then, instead of the second scanline of the 1st row of characters, you have the 1st scanline of the second line of characters, and so on until the you get the 1st scanline of the 8th line of characters. Then you begin with the second scanline of the 1st line of chars, etc...

I also think that every 2000 bytes, you have to jump to the next 2048 byte block.

Also, in mode 1 there are 4 pixels packed in one byte, so you'll have to get the byte where the pixel is and unpack it to get the value or pack it to modify the value.

Maybe I'm mistaken, but that's what I remember, hope this helps.

Navigation

[0] Message Index

[#] Next page

Go to full version
Powered by SMFPacks Media Embedder
Powered by SMFPacks Alerts Pro Mod
Powered by SMFPacks Mentions Pro Mod