-
Notifications
You must be signed in to change notification settings - Fork 1
/
irq.asm
88 lines (66 loc) · 2.91 KB
/
irq.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module IRQ
; To install the display driver simply:
; ld ix,DISPLAY._GENERATE
_GENERATE_VSYNC:
IN A,($FE) ; Start the VSync pulse.
; The user actions must always take the same length of time.
; Should be at least 3.3 scanlines (684 T-states) in duration for Chroma 81 compatibility.
CALL INPUT._read
OUT ($FF),A ; End the VSync pulse.
LD HL,(frames)
INC HL
LD (frames),hl
.ifdef TOP_BORDER_USER_ACTIONS
LD A,(margin) ; Fetch or specify the number of lines in the top border (must be a multiple of 8).
NEG ; The value could be precalculated to avoid the need for the NEG and INC A here.
INC A
EX AF,AF'
OUT ($FE),A ; Turn on the NMI generator to commence generating the top border lines.
; OUT ($FD),A ; @ Turn off the NMI generator to visually see how long the user actions take, i.e. how many extra top border lines it introduces.
CALL DO_TOP_USER_ACTIONS ; The user actions must not take longer than the time to generate the top border at either 50Hz or 60Hz.
; OUT ($FE),A ; @ Turn on the NMI generator to stop timing the user actions.
LD IX,_GENERATE_DISPLAY ; Set the display routine pointer to generate the main picture area next.
JP $02A4 ; Return to the user program.
.else
LD A,(margin) ; Fetch or specify the number of lines in the top border (must be a multiple of 8).
LD IX,_GENERATE_DISPLAY ; Set the display routine pointer to generate the main picture area next.
JP $029E ; Commence generating the top border lines and return to the user program.
.endif
_GENERATE_DISPLAY:
LD A,R ; Fine tune delay.
LD BC,$1901 ; B=Row count (24 in main display + 1 for the border). C=Scan line counter for the border 'row'.
LD A,$F5 ; Timing constant to complete the current border line.
CALL $02B5 ; Complete the current border line and then generate the main display area.
LD A,(margin) ; Fetch or specify the number of lines in the bottom border (does not have to be a multiple of 8).
NEG ; The value could be precalculated to avoid the need for the NEG and INC A here.
INC A
EX AF,AF'
OUT ($FE),A ; Turn on the NMI generator to commence generating the bottom border lines.
PUSH IY
irqsnd=$+1
CALL _dummy ; The user actions must not take longer than the time to generate the bottom border at either 50Hz or 60Hz.
POP IY
LD IX,_GENERATE_VSYNC ; Set the display routine pointer to generate the VSync pulse next.
JP $02A4 ; Return to the user program.
framesync:
ld hl,frames
ld a,(hl)
-: cp (hl)
jr z,{-}
ledsoff:
ld a,$b7 ; green off
call ledctl
ld a,$b9 ; red off
ledctl:
push bc
ld bc,$e007 ; zxpand LED control
out (c),a
pop bc
ret
waitframes:
call framesync
djnz waitframes
_dummy:
ret