Fastest Character Print in Mode 2

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search

Is it possible to print a character in Mode 2 in less than a raster line time (64nops)?

YES, using RES and SET commands to calculate next line screen address!!

This routine works in all vertical positions. It automatically calculates from which raster line of character we start to plot (CRTC reg. 9) and it uses special routine for each (0 - 7 lines).

Code is MAXAM compatible / timed and documented to my best..


;FASTEST CHARACTER PRINTER IN ALL Y COORDINATES
;takes less time than a raster line per char. in mode 2
;9.10.2016
;FG Brain

org &7000 : RUN $ :nolist

;INPUT HL = Screen Address to PLOT

ld a,h
and %00111000
rra
rra
; A=no of raster line (0-7) of char. we plot
;[ rra NEEDED but destroyed then with add a,a ]
ld hl,tablinerout
ld b,0:ld c,a
add hl,bc
ld de,jphere+1
ldi:ldi
LD DE,&C850
LD BC,font
adr  ld hl,0
jphere jp jphere             ;get adr to jump according to A

ret

tablinerout
dw line0,line1,line2,line3,line4,line5,line6,line7

;===PLOT 8 BYTES VERTICAL FROM ALL LINES===
;input DE = &C850  BC=font adr  HL=screen adr to print char.font

line0 ;LINE 0
ld a,(bc):ld(hl),a:inc c	;5
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a	;6
RET	;3
;=64 NOPs

line1 ;LINE 1
ld a,(bc):ld(hl),a:inc c	;5
res 3,h:set 4,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
res 3,h:set 4,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a	;7
ret	;3
;=65 NOPs

line2 ;LINE 2
ld a,(bc):ld(hl),a:inc c	;5
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a	;6
Ret	;3
;=63 NOPs

line3 ;LINE 3
ld a,(bc):ld(hl),a:inc c	;5
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a	;8
ret	;3
;=65 NOPs

line4 ;LINE 4
ld a,(bc):ld(hl),a:inc c	;5
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a	;6
ret	;3
;=61 NOPs

line5 ;LINE 5
ld a,(bc):ld(hl),a:inc c	;5
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a	;10
ret	;3
;=65 NOPs

line6 ;LINE 6
ld a,(bc):ld(hl),a:inc c	;5
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a ;6
ret ;3
;=63 NOPs

line7 ;LINE 7
ld a,(bc):ld(hl),a:inc c	;5
add hl,de:ld a,(bc):ld(hl),a:inc c	;8
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;9
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 5,h:res 4,h:res 3,h:ld a,(bc):ld(hl),a:inc c	;11
set 3,h:ld a,(bc):ld(hl),a:inc c	;7
set 4,h:res 3,h:ld a,(bc):ld(hl),a	;8
ret	;3
;=65 NOPs


align 256
FONT
DB 200,100,200,100,200,100,200,100

end


Compare with the normal routine (but much smaller in size), which needs at least 104 nops!!

ldi:   ;5
dec hl ;2
ld a,h:add 8:ld h,a ;4
jr nc,okk  ;2 / 3   13*8=104 NOPs
ld bc,&c050 ; 3
add hl,bc ; 3
jr okk ;3 ;  104+9=113 nops