Part 5: Standard Lines
If Bit 7 was a '0' then we will have arrived here. Here is where we build the standard Line type which will be in HL & DE
the format of A will now be as follows;
Bits 7-4 will be 4 bits of data, anything you like as long as its the White version of the Data. This will become clearer soon.
Bits 3-0 are the counter which determines the length of the line. This value is currently -4, which gets added (remember B from a few posts earlier?)
So, given the byte A=A4 for instance (would've started as 52h before the BIT 7 test shift)
This contains the Data 0101 and the counter 0100 (04)
Upon correction the counter will become 08, meaning we perform 8 shifts (4 on each buffer Left and Right)
Assuming this will be a White piece, The line would look like this in the data buffers before the shift cycle;
This will form the line on screen when its printed;
Code: Select all
ld l,a ;save source in L
and 0f0h ;mask Data part upper 4 bits
ld d,a ;save in D
xor l ;inverse mask - 0Fh to get counter
add a,b ;ADD +04h - same as SUB -0FCh
ld b,a ;counter into B
ld a,c ;B/W component into A
or 0ch ;overlay add-in outer bits
and 0fch ;mask 0FCh
ld e,a ;into E
xor d ;apply Data
ld l,a ;into L
ld d,c ;B/W component into D
ld h,c ;B/W component into H
inc c ;test C (00-01=W/FF-00=B)
jr nz,st_lp1 ;skip over swap if Black
ex de,hl ;swap buffers Left-Right
add hl,hl ;propagate the unwanted bits out of HL
djnz st_lp0 ;loop
ld a,h ;replace BIT 7 of H
rla ;with the last BIT carried
rrca ;out of D
jr bit4_res+1 ;jump to printing line -1 (ld h,a)
After the data is built and prior to the shift cycle, a test of C (the Black or White component) is performed. This swaps the sides that the register pairs relate to depending on which colour piece we're making. A simple way of reversing the shading from one side to the other.
Basically the lines are made at their maximum length, then squashed to the required length.
Clear as mud eh?
Finally, the last bit to be shifted out gets put into the other side at BIT 7. This allows the Data infill to cross a maximum of 1 bit into the opposite side. The longest line possible would be 26 bits, the shortest, 8 bits.