Difference between revisions of "Programming:Fast plot"
From CPCWiki - THE Amstrad CPC encyclopedia!
m (Sorted routines by mode) |
Executioner (Talk | contribs) (Added MODE 2 version to complete it and fixed MODE 0 comment) |
||
Line 25: | Line 25: | ||
RR E ;2 pixel per byte, Carry is X MOD 2 | RR E ;2 pixel per byte, Carry is X MOD 2 | ||
− | LD C, %10101010 ;Bitmask for MODE | + | LD C, %10101010 ;Bitmask for MODE 0 |
JR NC, NSHIFT ;-> = 0, no shift | JR NC, NSHIFT ;-> = 0, no shift | ||
SHIFT LD C, %01010101 ;other bitmask for right pixel | SHIFT LD C, %01010101 ;other bitmask for right pixel | ||
Line 72: | Line 72: | ||
JR Z, NSHIFT ;-> = 0, no shift | JR Z, NSHIFT ;-> = 0, no shift | ||
SHIFT SRL C ;move bitmask to pixel | SHIFT SRL C ;move bitmask to pixel | ||
+ | DEC A ;loop counter | ||
+ | JR NZ,SHIFT ;-position | ||
+ | |||
+ | NSHIFT LD A, (CMASK) ;get color mask | ||
+ | XOR (HL) ;XOR screenbyte | ||
+ | AND C ;AND bitmask | ||
+ | XOR (HL) ;XOR screenbyte | ||
+ | LD (HL), A ;new screenbyte | ||
+ | RET ;done | ||
+ | </pre> | ||
+ | |||
+ | == Fast plotting routine for MODE 2 == | ||
+ | |||
+ | And the MODE 2 routine. Perhaps this could be improved since there are only two colours, and the pixel shift may need to operate up to 7 times (so perhaps a table would average out better). | ||
+ | |||
+ | <pre> | ||
+ | CMASK EQU &B338 ;Adress for colormask | ||
+ | ;664/6128 - &B6A3 | ||
+ | |||
+ | FPLOT LD A, L ;A = Lowbyte Y | ||
+ | AND %00000111 ;isolate Bit 0..2 | ||
+ | LD H, A ;= y MOD 8 to H | ||
+ | XOR L ;A = Bit 3..7 of Y | ||
+ | LD L, A ;= (Y\8)*8 to L | ||
+ | LD C, A ;store in C | ||
+ | LD B, &60 ;B = &C0\2 = Highbyte Screenstart\2 | ||
+ | |||
+ | ADD HL, HL ;HL * 2 | ||
+ | ADD HL, HL ;HL * 4 | ||
+ | ADD HL, BC ;+ BC = Startaddress | ||
+ | ADD HL, HL ;of the raster line | ||
+ | |||
+ | SRL D ;calculate X\8, because | ||
+ | RR E ;8 pixel per byte | ||
+ | SRL D | ||
+ | RR E | ||
+ | SRL E | ||
+ | ADD HL,DE ;+ HL = Screenaddress | ||
+ | |||
+ | LD C,%10000000 ;Bitmask for MODE 2 | ||
+ | AND %00000111 ;A = X MOD 8 | ||
+ | JR Z, NSHIFT ;-> = 0, no shift | ||
+ | |||
+ | SHIFT SRL C ;move bitmask to pixel | ||
DEC A ;loop counter | DEC A ;loop counter | ||
JR NZ,SHIFT ;-position | JR NZ,SHIFT ;-position |
Revision as of 15:09, 24 August 2006
Fast plotting routine for MODE 0
Converted from the Mode 1 routine by The Executioner
Input: DE = X (0..159), HL = Y (0..199)
CMASK EQU &B338 ;Adress for colormask ;664/6128: &B6A3 FPLOT LD A, L ;A = Lowbyte Y AND %00000111 ;isolate Bit 0..2 LD H, A ;= y MOD 8 to H XOR L ;A = Bit 3..7 of Y LD L, A ;= (Y\8)*8 to L LD C, A ;store in C LD B, &60 ;B = &C0\2 = Highbyte Screenstart\2 ADD HL, HL ;HL * 2 ADD HL, HL ;HL * 4 ADD HL, BC ;+ BC = Startaddress ADD HL, HL ;of the raster line SRL D ;calculate X\2, because RR E ;2 pixel per byte, Carry is X MOD 2 LD C, %10101010 ;Bitmask for MODE 0 JR NC, NSHIFT ;-> = 0, no shift SHIFT LD C, %01010101 ;other bitmask for right pixel NSHIFT ADD HL, DE ;+ HL = Screenaddress LD A, (CMASK) ;get color mask XOR (HL) ;XOR screenbyte AND C ;AND bitmask XOR (HL) ;XOR screenbyte LD (HL), A ;new screenbyte RET ;done
Fast plotting routine for MODE 1
This routine is approx. 6 times faster than the OS routine GRA PLOT, because it is dpendent to MODE 1 and doesn't perform range checks. It can draw 10500 pixels per second.
Input: DE = X (0..319), HL = Y (0..199)
CMASK EQU &B338 ;Adress for colormask ;664/6128: &B6A3 FPLOT LD A, L ;A = Lowbyte Y AND %00000111 ;isolate Bit 0..2 LD H, A ;= y MOD 8 to H XOR L ;A = Bit 3..7 of Y LD L, A ;= (Y\8)*8 to L LD C, A ;store in C LD B, &60 ;B = &C0\2 = Highbyte Screenstart\2 ADD HL, HL ;HL * 2 ADD HL, HL ;HL * 4 ADD HL, BC ;+ BC = Startaddress ADD HL, HL ;of the raster line LD A, E ;Lowbyte X to A SRL D ;calculate X\4, because RR E ;4 pixel per byte SRL E ADD HL, DE ;+ HL = Screenaddress LD C, %10001000 ;Bitmask for MODE 1 AND %00000011 ;A = X MOD 4 JR Z, NSHIFT ;-> = 0, no shift SHIFT SRL C ;move bitmask to pixel DEC A ;loop counter JR NZ,SHIFT ;-position NSHIFT LD A, (CMASK) ;get color mask XOR (HL) ;XOR screenbyte AND C ;AND bitmask XOR (HL) ;XOR screenbyte LD (HL), A ;new screenbyte RET ;done
Fast plotting routine for MODE 2
And the MODE 2 routine. Perhaps this could be improved since there are only two colours, and the pixel shift may need to operate up to 7 times (so perhaps a table would average out better).
CMASK EQU &B338 ;Adress for colormask ;664/6128 - &B6A3 FPLOT LD A, L ;A = Lowbyte Y AND %00000111 ;isolate Bit 0..2 LD H, A ;= y MOD 8 to H XOR L ;A = Bit 3..7 of Y LD L, A ;= (Y\8)*8 to L LD C, A ;store in C LD B, &60 ;B = &C0\2 = Highbyte Screenstart\2 ADD HL, HL ;HL * 2 ADD HL, HL ;HL * 4 ADD HL, BC ;+ BC = Startaddress ADD HL, HL ;of the raster line SRL D ;calculate X\8, because RR E ;8 pixel per byte SRL D RR E SRL E ADD HL,DE ;+ HL = Screenaddress LD C,%10000000 ;Bitmask for MODE 2 AND %00000111 ;A = X MOD 8 JR Z, NSHIFT ;-> = 0, no shift SHIFT SRL C ;move bitmask to pixel DEC A ;loop counter JR NZ,SHIFT ;-position NSHIFT LD A, (CMASK) ;get color mask XOR (HL) ;XOR screenbyte AND C ;AND bitmask XOR (HL) ;XOR screenbyte LD (HL), A ;new screenbyte RET ;done