;; stable raster on cpc
;;
;; The easiest way to have stable interrupts is to use HALT.
;; This will execute the equivalent of a NOP instruction until an
;; interrupt is acknowledged.
;;
;; At this point you need your own interrupt handler so you always
;; get the same number of cycles
;;
;; The minimal one:
;;
;; EI
;; RET
;;
;; or
;; 
;; EI
;; RETI
;;
;; will take constant time
;;
;; the following happens:

;; 1. HALT waits for an interrupt to come and burns cycles performing
;; NOP instructions
;; 2. Interrupt comes
;; 3. Interrupt is acknowledged (takes some fixed number of cycles
;; to start your interrupt routine)
;; 4. Your interrupt routine takes a furthur number of fixed cycles)
;; 5. Code returns to after the HALT.
;; At this point we are synchronised to the screen and have a stable
;; raster position.


;; example:

org &8000

di
im 1
;; write EI:RET to &0038
;; EI is 1 NOP cycle
;; RET is 4 NOP cycles
;; interrupt acknowledge in mode 1 is 5 NOP cycles
ld hl,&c9fb
ld (&0038),hl
ei

mainloop:
ld b,&f5
ml1:
in a,(c)
rra
jr nc,ml1
halt
;; sychronised with raster position here
halt
;; sychronised with raster position here
halt
;; sychronised with raster position here
halt
;; sychronised with raster position here
halt
;; sychronised with raster position here
halt
;; sychronised with raster position here

jp