EP X positioning code
Greetings to the 20 readers who visited yesterday.The Expensive Planetarium drawn using 256 8x8 pixel tile sprites, with each sprite having 8 "stars" in a quincunx pattern either on or off. (Actually, there are two sets of tile sprites, odd & even, to make up for the 160 positioning in 320 mode.) The actual star map is 90 rows of 256 tiles (each tile is 1 byte). This makes the starmap effectively 2048x720 pixels (360x180 degrees).On the 7800 tiles are drawn using 5 byte DL entries. Each entry contains a 16 bit address of the tiles, the number of tiles to draw and the horizontal position of the first sprite. Each DL entry can draw up to 32 tiles, and since the screen is 320 pixels wide, we need 41 tiles (1 extra for offscreen) per line or two DL entries.Actually, it's a little more difficult than that. To handle wrap around you need three DL entries. To simplify things, the second DL entry is always for 20 tiles. Okay, some code!
LDA EP_X_MSB CMP #216 BCS EP_X_1 LDA #-16 BCC EP_X_2EP_X_1 CMP #236 BCS EP_X_2 ADC #20EP_X_2 STA EP_W1 ASL ASL EOR #$FF ADC #0 STA EP_P2 LDA EP_X_MSB SEC SBC EP_W1 STA EP_L2 CLC ADC #20 STA EP_L3
This calculates 5 of the 9 values needed. The first bit of code determines the width for the first DL entry based on the X_MSB, which is also the first DL entry tile address LSB. That value is then multiplied by 4 and inverted to calculate the position for the second DL entry. (Actually, that value will get updated later.) Note: the width is negative, which also means the ASLs set the Carry bit.The next code calculates the address LSB for the other DL entries. I have to explicitly set the carry bit both times because it changes depending on the value of EP_X_MSB. (I double checked using a spreadsheet.)I'll stop here because my head is hurting trying to figure out the steps needed to calculate the width for the third DLL entry.
2 Comments
Recommended Comments