For this exercise, I want you to write a mode 8 plot routine in a manner similar to the plot_4 routine shown above. Here are some hints :
Avoid the flash bits like the plague. Simply mask them out and set them to zero.
The calc routine works for mode 8 as well. No need to change it.
The mask for pixel 0's colour needs to be GF000000 RB000000.
The mask to clear pixel 0 needs to be 01111111 00111111 ($7f3f).
The algorithm is as follows :
Calculate the screen address by calling calc. Sets A1 = screen address.
Mask out all but bits 0, 1 and 2 of D3.W This is the pixel colour. D3 = GRB.
Shift D3.W LEFT by 6 bits.
Copy D3.W to D4.W
Shift D4 left by 7 bits.
ANDI.W D4.W with $8000 to preserve only bit 15 = G.
ANDI.W D3.W with $C0 to zero the G bit currently in bit 8.
OR.W D4 into D3 to give the correct colour mask for pixel 0.
ANDI.W d1 with 6 to get the correct number of rotates (6 makes it even which it must be because we need to rotate two bits for each pixel.)
Rotate right, the two mask words, the correct number of bits.
AND.W the mask with the screen word.
OR.W the colour mask with the screen word.
Clear D0 and return.
The results of (x and 6) are as follows :
X | X AND 6 |
---|---|
0 | 0 |
1 | 0 |
2 | 2 |
3 | 2 |
4 | 4 |
5 | 4 |
6 | 6 |
7 | 6 |
8 | 0 |
9 | 0 |
10 | 2 |
And so on. Because we are using two bits of the green and red bytes to represent our colour, we need to always rotate by an even number.
To test it all out, add the code to the end of the original file which has plot_4 in it and change the first two lines from this :
start bra plot_init plot_4 bsr.s calc
to the following :
start bra plot_init plot_4 bra plot_4 plot_8 bra plot_8
This means that plot_init is the start address, plot_4 is at address + 4 and plot_8 has been inserted at start address + 8, as follows :
1000 PLOT_INIT = RESPR(256): REMark Enough space for plot_8 as well ! 1005 PLOT_4 = PLOT_INIT + 4 1010 PLOT_8 = PLOT_INIT + 8 1010 LBYTES flp1_plot_bin, PLOT_INIT 1015 CALL PLOT_INIT
Have fun.