I'm trying to convert a BASIC program which PEEKs the text screen, and I'm having a really hard time figuring out a similar formula for the Apple II.
The original computer stores screen memory sequentially from top left to bottom right. But the Apple skips seven lines after every 40 characters (that's not entirely accurate, but you probably know what I'm describing.)
Beagle Bros has a short routine to solve this by positioning the cursor using HTAB and VTAB, then PEEK to find the memory location:
PEEK (40) + PEEK (41) * 256 + PEEK (36)
40 and 41 are the base memory address of the cursor position, and 36 is the horizontal position. However, adding this routine to the program, plus its overhead, slows it down considerably.
I would imagine that there's a known mathematical formula to do this more directly, but I can't find it with Google and I can't figure it out on my own. Can anyone point me to a solution? Machine language isn't out of the question, but I'd rather keep it in BASIC. (Timing isn't critical, just inconvenient.)