0

try to understand a code In the following website is a code a scrollers with wave-like movements. In general, I also understand the code very well. What I don't quite understand IS why he uses Ypos and Yposh the way he uses them. So why, bits 0 -2 were masked with the 7 and stored in Ypos? And why are the values ​​then shifted 3 to the right and stored in Yposh?

This code you can see in this Website: https://codebase64.org/doku.php?id=magazines:chacking6#the_demo_cornerdycp_-_horizontal_scrolling

Thanks for Your answers.

Understanding the code

BlackStan
  • 1
  • 1
  • Probably bit offset/position vs. byte offset/position. – Erik Eidt Jan 08 '23 at 17:34
  • Please don't repost questions. As I said, that's because character cell is 8 pixels so that separates the position and the offset. Shifting by 3 is dividing by 8 (because 8=2^3) and masking by 7 is the remainder. – Jester Jan 08 '23 at 18:33
  • @ErikEidt Could You Explain it more in detail? Thats Correct but i do not understand the principle. Why mask with 7 and does the offset and Position work? – BlackStan Jan 09 '23 at 13:49
  • This is probably a better question for https://retrocomputing.stackexchange.com/ – puppydrum64 Jan 09 '23 at 15:11
  • @jester Could You explain it more in detail? – BlackStan Jan 09 '23 at 16:30

1 Answers1

0

Our "modern" computer systems are byte addressable.  That means that the smallest item we can address to access memory is 8 bits, and each successive memory address holds a different 8 bit byte.

When we want to address something larger or smaller than 8 bits we have to do some work.

As an example of composing bytes to make a large item, a 16-bit integer takes 2 bytes of memory, and to access an element of a 16-bit integer array, as in a[i], we have to do address arithmetic that scales i by the size of the integer, in bytes, so a+i*2, since each 2-byte integer takes two byte addresses.  (We refer to multi-byte items by just one of its addresses, namely the lowest/smallest address, but since a multi-byte item takes multiple byte addresses, the next multi-byte item in an array needs to skip over all the addresses of the current item.)

To address something smaller than a single byte, as in a bit for a bit-mapped display, then we also need to do some work.  First, we'll invent a notion of bit address.  The bit address is a number that represents a single bit of memory.  Like byte addresses and byte offsets, the bit address or bit offset is just a number, and unsigned integer.  Each successive bit address refers to the next bit of memory.  Just like byte addresses and byte offsets, we can do arithmetic on bit addresses and bit offsets, indexing computations and such, e.g. for a 2-D display.

Of course, the hardware doesn't support bit addressing, only byte addressing — so to read a single bit, we need to read the entire byte that contains the bit, and to write a single bit, we need to write the entire byte that contains the bit. 

(Writing is a bit more complex, because usually when we write a single bit we don't want to disturb the other nearby bits, so writing a single bit is really logically a read byte (that contains the bit of interest), modify that byte, and then write it back.  How we accomplish the read-modify-write depends on the CPU's instruction set.)

A bit address or bit offset differs from byte address or byte offsets by a factor of 8 (because bytes hold 8 bits)!  Thus, the byte containing the bit at a given byte address has an address that is the bit address divided by 8, and, given that one byte, the bit number within that byte is the bit address modulus 8, a number from 0 to 7.

Division by 8 and modulus by 8 are easy for binary hardware to do: divide by 8 is shift right 3 bit positions, e.g. in C, b >> 3, and modulus by 8 is masking keeping only the lower 3 bits, e.g. in C as b & 7.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • What I find strange is that they did all that inside the IRQ. Seems like a task that should be done outside it to save time. – puppydrum64 Jan 12 '23 at 11:49