-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrupt.asm
122 lines (110 loc) · 3.22 KB
/
interrupt.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
;===============================================================================
;
; Interrupt handlers
;
;===============================================================================
;===============================================================================
;
; Z80 IM2 smart vectored interrupts
;
; The interrupt vector table needs to be aligned as the CPU knows the top
; eight bits of its address b15-b8, the CTC knows bits b7-b3 and the actual
; interrupt hardware supplies the bottom bits b2-0
;
;===============================================================================
;
; iTable has been moved to stepper.asm to make it fixed between BIOS options
; This assumes the ctc_int has already been run to set up the vectors
int_init
; first build the interrupt vector parts
ld a, high iTable ; top 8 bits of table address
ld i, a ; the special 'i' register
im 2
ret
;-------------------------------------------------------------------------------
; CTC0 should not trigger (CTC0)
;-------------------------------------------------------------------------------
int0 ei
reti
;-------------------------------------------------------------------------------
; CTC1 50Hz = 20mS
;-------------------------------------------------------------------------------
if LIGHTS_EXIST
led_countdown db 0
strobe_table db 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
db 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
db 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
db 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
len_strobe equ $-strobe_table
endif
int1 di
push af, hl
; 50 Hz ticks
ld a, [Z.preTick] ; uint8 counts 0-49
inc a
ld [Z.preTick], a
cp 50
jr c, .q2
xor a
ld [Z.preTick], a
; 1Hz ticks
ld hl, Z.Ticks ; unit32 counts seconds
inc [hl] ; b0-7
jr nz, .q1 ; beware, inc does not set carry
inc hl
inc [hl] ; b8-15
jr nz, .q1
inc hl
inc [hl] ; b16-23
jr nz, .q1
inc hl
inc [hl] ; b24-31 2^32 seconds is 136 years
.q1
; put things for 1Hz service here
.q2
; put things for 50Hz service here
; strobe leds
if LIGHTS_EXIST
ld a, [Z.preTick] ; drop to 25Hz
and 1
jr nz, .lr2
ld a, [led_countdown] ; do we want a countdown?
or a
jr z, .lr2 ; no
cp len_strobe ; beware the table length
jr c, .lr1
ld a, len_strobe
.lr1 dec a
ld [led_countdown], a
ld hl, strobe_table
add a, l
ld l, a
ld a, h
adc 0
ld h, a
ld a, [hl]
out (LIGHTS), a
.lr2
; switches to lights option
if BIOSROM == 0
ld a, [cmd_bits]
and 1 ; bit 0 = 'A'
jr z, .q3
in a, (SWITCHES) ; read switches
out (LIGHTS), a ; write leds
.q3
endif
endif
; finished and exit
pop hl, af
ei
reti
;-------------------------------------------------------------------------------
; CTC2 Wired trigger from UART
;-------------------------------------------------------------------------------
int2 jp serial_interrupt
;-------------------------------------------------------------------------------
; CTC3 Wired to PC3 which is an interrupt output in a smart mode
;-------------------------------------------------------------------------------
int3 ei
reti