Groups | Search | Server Info | Login | Register


Groups > comp.sys.amstrad.8bit > #400

fast C (or other readable language) version of SCR DOT POSITION with screen_offset!=0?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Jens Thiele <karme@karme.de>
Newsgroups comp.sys.amstrad.8bit
Subject fast C (or other readable language) version of SCR DOT POSITION with screen_offset!=0?
Date Thu, 02 Oct 2025 12:50:04 +0200
Organization A noiseless patient Spider
Lines 38
Message-ID <10bllcs$uu7p$1@dont-email.me> (permalink)
MIME-Version 1.0
Content-Type text/plain
Injection-Date Thu, 02 Oct 2025 10:50:05 +0000 (UTC)
Injection-Info dont-email.me; posting-host="743e99b00c13a96db17499150ef39bb4"; logging-data="1014009"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AJYYje6TgTH5cvuaERbr+"
Cancel-Lock sha1:d/KsYlnAPfhXi1Z+Z7rzYDqzt80=
Xref csiph.com comp.sys.amstrad.8bit:400

Show key headers only | View raw


Hi,

I am playing around with hardware scrolling and I still didn't really
understand the video memory layout, when the screen offset is != 0.
(I now get 49fps when scrolling up/down, but only 16fps (~20fps without
sync) when scrolling left/right)

To better understand the video memory layout I wrote various functions
mapping offset, x and y to the byte address in memory (I use fixed
mode 2 and fixed base address of 0xc000). So far my C versions all are
much slower than calling the firmware function SCR DOT POSITION.

A version that is somewhat readable but relatively slow:

/*
   scroff : screen offset [0,2047]
   x      : x coordinate  [0,639]
   y      : y coordinate  [0,199]
   returns pointer to screen byte
*/
inline char* scr_dot_position_c1(uint16_t scroff, int16_t x, uint8_t y)
{
	uint16_t scroffy=scroff/80;
	uint16_t scroffx=scroff%80;
	uint16_t yoff=(80 * (scroffy + (y / 8))) + (2048 * (y % 8));
	uint8_t  xoff=x>>3;
	uint16_t off=yoff+scroffx+xoff;
	/* do we cross over a 2048 byte boundary? */
	uint8_t i=yoff/2048;
	uint8_t j=off/2048;
	if (i!=j) off-=2048;
	/* fix for wrap around */
	int8_t wrapped_lines=scroffy-1;
	if (y>=200-wrapped_lines*8) off-=2048;
	return (char*)0xc000+off;
}

Do you have a better (faster or cleaner) version?

Back to comp.sys.amstrad.8bit | Previous | NextNext in thread | Find similar


Thread

fast C (or other readable language) version of SCR DOT POSITION with screen_offset!=0? Jens Thiele <karme@karme.de> - 2025-10-02 12:50 +0200
  Re: fast C (or other readable language) version of SCR DOT POSITION with screen_offset!=0? Jens Thiele <karme@karme.de> - 2025-10-02 12:56 +0200

csiph-web