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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
xdef pgstart
absentry pgstart
*
*******************************************************************************
* Macros
*
PORTB equ $0001
DDRB equ $0003
SCHBDH equ $00C8
SCHBDL equ $00C9
SCICR2 equ $00CB
SCISR1 equ $00CC
SCIDRL equ $00CF
CRGFLG equ $0037
CRGINT equ $0038
RTICTL equ $003B
*
*******************************************************************************
* RTI Vector Section: [ $FFF0 to $FFF1 ]
*
org $FFF0
dc.w RTIISR
*
*******************************************************************************
* Data Section: [ $3000 to $30FF ]
*
org $3000
counter dc.w $0000
msg dc.b 'This program will print a $ every second',$00
numBuf ds.b $0002
dc.b $00
inNumBuf dc.w $0000
*
*******************************************************************************
* Program Section: [ $3100 to $3FFF ]
*
org $3100
pgstart
lds #pgstart
ldaa #1
staa SCHBDH
ldaa #$0C
staa SCICR2
ldaa #%00011001
staa RTICTL
bset CRGINT,#%10000000
bset CRGFLG,#%10000000
ldx #msg
jsr printmsg
cli
loop jsr getchar
tsta
beq loop
jsr putchar
bra loop
;******************************************************************************
; Subroutine Section
;
RTIISR bset CRGFLG,#%10000000
ldx counter
inx
stx counter
cpx #400
bne RTIDONE
ldx #0
stx counter
ldaa #'$'
jsr putchar
RTIDONE rti
getchar
brclr SCISR1,#%00100000,empty
ldaa SCIDRL
rts
empty clra
rts
PrintTwoDigitDecimal
pshx
pshd
pshy
ldy #numBuf
ConvertLoop ldx #10
idiv
cpd #0
beq CheckX
XNotZero addb #'0'
stab 1,y+
exg d,x
bra ConvertLoop
CheckX cpx #0
bne XNotZero
ldx #numBuf
jsr printmsg
puly
puld
pulx
rts
ReadTwoDigitDecimal
pshx
pshd
pshy
ldd #0
ReadLoop ldab 1,x+
beq ReadDone
cmpb #'0'
blt ReadDone
cmpb #'9'
bhi ReadDone
pshb
ldd inNumBuf
ldy #10
emul
std inNumBuf
pulb
subb #'0'
ldy inNumBuf
aby
sty inNumBuf
bra ReadLoop
ReadDone puly
puld
pulx
rts
putchar
brclr SCISR1,#%10000000,putchar
staa SCIDRL
rts
printmsg
pshx
psha
printLoop ldaa 1,x+
beq printDone
jsr putchar
bra printLoop
printDone pula
pulx
rts
;
;******************************************************************************
end
|