Programming:Mixed modes using firmware

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
	
;; Example to change the mode and inks using the firmware
;; and then how to plot in each area.
;; by Kevin Thacker. 2025. Released under BSD License.
kl_new_fast_ticker equ &bce0
mc_set_mode equ &bd1c
kl_new_frame_fly equ &bcd7
mc_set_inks equ &bd25
scr_set_mode equ &bc0e
scr_mode_clear equ &bdeb
txt_set_cursor equ &bb75
txt_output equ &bb5a

;;---------------------------------------------------------------------------------------

org &4000
;;---------------------------------------------------------------------------------------

start:
;; set a mode and clear screen
xor a
call scr_set_mode

;; prevent screen clearing. See SOFT968 Hits and Tips
ld a,&c9
ld (scr_mode_clear),a

;; interrupt counter which goes from 0-5.
xor a
ld (interrupt_index),a

;; install frame flyback interrupt to reset counter.
ld hl,frame_flyback_block
ld b,&81
ld c,&ff
ld de,frame_flyback_function
call kl_new_frame_fly

;; install fast ticker interrupt to set mode and inks.
ld hl,fast_ticker_block
ld b,&81
ld c,&ff ;; in main ram
ld de,fast_ticker_function
call kl_new_fast_ticker

;; set mode 1 - now without clearing screen
ld a,1
call scr_set_mode
;; set text position
ld h,1
ld l,24
call txt_set_cursor
;; write text in mode 1
ld hl,message_lower
call display_message

;; set mode 0 - now without clearing screen
xor a
call scr_set_mode
;; set text position
ld h,1
ld l,1
call txt_set_cursor
;; write text in mode 0
ld hl,message_upper
call display_message

;; loop to see effect.
loop:
jp loop


;;---------------------------------------------------------------------------------------
message_upper:
defb "This is in mode 0",0


;;---------------------------------------------------------------------------------------
message_lower:
defb "This is in mode 1",0

;;---------------------------------------------------------------------------------------
display_message:
ld a,(hl)
inc hl
or a ;; look for 0 which is end of string
ret z
call txt_output
jr display_message

;;---------------------------------------------------------------------------------------
frame_flyback_function:
push af
xor a
ld (fast_ticker_block),a
pop af
ret
;;---------------------------------------------------------------------------------------

fast_ticker_function:
push af
push hl
push bc
push de

ld hl,modes
ld a,(fast_ticker_block)
ld c,a
ld b,0
add hl,bc
ld a,(hl)
call mc_set_mode

ld a,(fast_ticker_block)
ld l,a
ld h,0
ld c,l
ld b,0
add hl,hl   ;; x2
add hl,hl   ;; x4
add hl,hl   ;; x8
add hl,hl   ;; x16
add hl,bc   ;; x17
ld bc,inks
add hl,bc
ld e,l
ld d,h
call mc_set_inks

ld a,(fast_ticker_block)
cp 5
jr z,ftf
inc a
ld (fast_ticker_block),a
ftf:


pop de
pop bc
pop hl
pop af
ret
;;---------------------------------------------------------------------------------------

;; must be in range &4000-&7fff
frame_flyback_block:
defs 9

;; must be in range &4000-&7fff
fast_ticker_block:
defs 9

;;---------------------------------------------------------------------------------------

;; which interrupt.
interrupt_index:
defb 0

;;---------------------------------------------------------------------------------------

;; mode per interrupt
modes:
;; mode in top border. not useful unless screen height is changed.
defb 0

;; to set mode for top few lines of screen
defb 0

;; mode in middle of screen
defb 0
defb 0

;; to set mode for bottom few lines of screen
defb 1

;; mode in bottom border. not useful unless screen height is changed.
defb 0

;;---------------------------------------------------------------------------------------

;; palette per interrupt; 17 values, border then inks.
;; All inks are set even if mode doesn't use them all.
inks:
;; top border.
defb 21,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23

;; just before graphics starts.
defb 0,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23

defb 21,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23

defb 0,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23

defb 21,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23

;; single line before graphics ends and into bottom border
defb 0,21,10,20,12,11,20,21,13,6,30,27,7,18,25,4,23


end start