Difference between revisions of "Programming:Next / previous line calculation"
From CPCWiki - THE Amstrad CPC encyclopedia!
								
												
				|  (Created page with "= Next line =  This routines calculate the next line from the given address.  == Firmware ==  '''Input:''' HL=Address  '''Output:''' HL=Address of the next line  '''Destroyed:'''...") |  (→Fastest way to print a character in Mode 2) | ||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 15: | Line 15: | ||
| call SCR_NEXT_LINE | call SCR_NEXT_LINE | ||
| + | |||
| + | |||
| + | ACTUAL #BC26 ROUTINE FOLLOWS: | ||
| + | |||
| + | ld a,h:add #08:ld h,a:and #38:ret nz | ||
| + | ld a,h:sub #40:ld h,a:ld a,l:add reg1*2:ld l,a:ret nc  ;reg1= CRTC reg.1 value | ||
| + | inc h:ld a,h:and #07:ret nz | ||
| + | ld a,h:sub #08:ld h,a:ret | ||
| + | |||
| + | |||
| </pre> | </pre> | ||
| Line 23: | Line 33: | ||
| '''Output:''' HL=Address of the next line | '''Output:''' HL=Address of the next line | ||
| − | '''Destroyed:''' AF | + | '''Destroyed:''' AF,BC | 
| <pre> | <pre> | ||
| Line 34: | Line 44: | ||
|          add h   |          add h   | ||
|          ld h,a   |          ld h,a   | ||
| − | + |          ret nc | |
| − |          ret  | + |          ld bc,#c050 | 
| − |          ld bc, | + |          add hl,bc   | 
| − | + | ||
|          ret |          ret | ||
| </pre> | </pre> | ||
| Line 57: | Line 66: | ||
| call SCR_PREV_LINE | call SCR_PREV_LINE | ||
| + | |||
| + | |||
| + | ACTUAL #BC29 ROUTINE FOLLOWS: | ||
| + | |||
| + | ld a,h:sub #08:ld h,a:and #38:cp #38:ret nz | ||
| + | ld a,h:add #40:ld h,a:ld a,l:sub reg1*2:ld l,a:ret nc ; reg1= CRTC reg.1 value | ||
| + | ld a,h:dec h:and #07:ret nz | ||
| + | ld a,h:add #08:ld h,a:ret | ||
| + | |||
| </pre> | </pre> | ||
| + | |||
| + | |||
| + | |||
| + | = Fastest way to print a character in Mode 2 = | ||
| + | |||
| + | |||
| + | '''Input:''' HL=Address of sprite/char.data    DE=screen address (works for every first line of screen !! For example: &C000, &C050, &C0A0 etc..) | ||
| + | |||
| + | '''Destroyed:''' AF, C | ||
| + | |||
| + | '''Unchanged:''' DE returns to its input value (through C register) | ||
| + | |||
| + | ''''If HL is not page aligned, INC HL must be used instead of INC L (1 NOP SLOWER!) | ||
| + | |||
| + | |||
| + | <pre> | ||
| + | ld c,d | ||
| + | ld a,(hl):ld(de),a:inc l:set 3,d | ||
| + | ld a,(hl):ld(de),a:inc l:ld d,c:set 4,d | ||
| + | ld a,(hl):ld(de),a:inc l:set 3,d | ||
| + | ld a,(hl):ld(de),a:inc l:ld d,c:set 5,d | ||
| + | ld a,(hl):ld(de),a:inc l:set 3,d | ||
| + | ld a,(hl):ld(de),a:inc l:set 4,d:res 3,d | ||
| + | ld a,(hl):ld(de),a:inc l:set 3,d | ||
| + | ld a,(hl):ld(de),a | ||
| + | ld d,c | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | |||
| [[Category:Programming]] | [[Category:Programming]] | ||
Latest revision as of 07:11, 16 January 2016
Contents
Next line
This routines calculate the next line from the given address.
Firmware
Input: HL=Address
Output: HL=Address of the next line
Destroyed: AF
SCR_NEXT_LINE equ #BC26 call SCR_NEXT_LINE ACTUAL #BC26 ROUTINE FOLLOWS: ld a,h:add #08:ld h,a:and #38:ret nz ld a,h:sub #40:ld h,a:ld a,l:add reg1*2:ld l,a:ret nc ;reg1= CRTC reg.1 value inc h:ld a,h:and #07:ret nz ld a,h:sub #08:ld h,a:ret
Without Firmware
Input: HL=Address
Output: HL=Address of the next line
Destroyed: AF,BC
; Richard Fairhurst 
; October 1997 
; 
;*** Next line down from HL *** 
.nline  ld a,8 
        add h 
        ld h,a 
        ret nc
        ld bc,#c050
        add hl,bc 
        ret
Previous line
This routines calculate the previous line from the given address.
Firmware
Input: HL=Address
Output: HL=Address of the previous line
Destroyed: AF
SCR_PREV_LINE equ #BC29 call SCR_PREV_LINE ACTUAL #BC29 ROUTINE FOLLOWS: ld a,h:sub #08:ld h,a:and #38:cp #38:ret nz ld a,h:add #40:ld h,a:ld a,l:sub reg1*2:ld l,a:ret nc ; reg1= CRTC reg.1 value ld a,h:dec h:and #07:ret nz ld a,h:add #08:ld h,a:ret
Fastest way to print a character in Mode 2
Input: HL=Address of sprite/char.data DE=screen address (works for every first line of screen !! For example: &C000, &C050, &C0A0 etc..)
Destroyed: AF, C
Unchanged: DE returns to its input value (through C register)
'If HL is not page aligned, INC HL must be used instead of INC L (1 NOP SLOWER!)
ld c,d ld a,(hl):ld(de),a:inc l:set 3,d ld a,(hl):ld(de),a:inc l:ld d,c:set 4,d ld a,(hl):ld(de),a:inc l:set 3,d ld a,(hl):ld(de),a:inc l:ld d,c:set 5,d ld a,(hl):ld(de),a:inc l:set 3,d ld a,(hl):ld(de),a:inc l:set 4,d:res 3,d ld a,(hl):ld(de),a:inc l:set 3,d ld a,(hl):ld(de),a ld d,c
