-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmach_wdc_16.s
201 lines (187 loc) · 2.76 KB
/
mach_wdc_16.s
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
mach_init0:
.ax8
sei
ldx #80
ldy #24
jsr pagesize
rts
mach_init1:
.ax8
lda #1
jsr set_led
jsr con_init
rts
mach_reset:
jmp start
mach_hex_char:
.ax8
lda 1,s
and #$0f
cmp #10
bcc _is_digit
clc
adc #55
bra _done
_is_digit:
clc
adc #$30
_done:
sta 1,s
jmp do_next
mach_dbg:
;; A has low order of new IP
;jsr set_led
rts
set_led:
.ax8
pha ; Save selected LED(s)
lda #00 ; DDRA access
sta PIA_A_CTRL
lda #$ff ; All bits as "output"
sta PIA_A_DATA
lda #04 ; ORA access
sta PIA_A_CTRL
pla ; Fetch select LED(s)
sta PIA_A_DATA
rts
con_init:
.ax8
;; Set USB_CTRL_WR and USB_CTRL_RDb pins as OUTPUT; others as input
lda #USB_CTRL_WR|USB_CTRL_RDb
sta USB_CTRL_DDR
rts
con_tx:
.ax8
stz USB_DATA_DDR
sta USB_DATA_OR
lda #USB_CTRL_TXEb
;; Wait for transmitter availability
- bit USB_CTRL_IR
bne -
lda #$ff
sta USB_DATA_DDR
lda #USB_CTRL_WRSTR
sta USB_CTRL_OR
nop
nop
lda #USB_CTRL_DEF
sta USB_CTRL_OR
rts
con_rx:
.ax8
stz USB_DATA_DDR
lda #USB_CTRL_RXFb
- bit USB_CTRL_IR
bne -
lda #USB_CTRL_RDSTR
sta USB_CTRL_OR
nop
nop
nop
nop
lda USB_DATA_IR
pha
lda #USB_CTRL_DEF
sta USB_CTRL_OR
pla
rts
raw_bs:
.ax8
lda #8
rts
ll_mult:
.ax16
lda 3,s
sta mac
lda 1,s
sta mac+2
lda #0
_again
ldx mac
beq _done
lsr mac
bcc _skip_add
clc
adc mac+2
_skip_add
asl mac+2
bra _again
_done
sta 3,s
pla
jmp do_next
ll_slash_mod:
.ax16
;; Taken almost verbatim from the WDC 65816 6502 Programming Manual
lda 3,s
tax
lda 1,s
stz quotient
ldy #1
_div1:
asl a
bcs _div2
iny
cpy #17
bne _div1
_div2:
ror a
_div4:
pha
txa
sec
sbc 1,s
bcc _div3
tax
_div3:
rol quotient
pla
lsr a
dey
bne _div4
_done:
txa
sta 3,s
lda quotient
sta 1,s
jmp do_next
pagesize:
.ax8
sty size_y
stx size_x
rts
;; cup=\E[%i%p1%d;%p2%dH
;; cursor position by sending
;; ESC[row;colH
;; where row = y, col = x
gotoxy:
.ax8
phx
phy
lda #27 ;ESC
jsr con_tx
lda #"["
jsr con_tx
pla
jsr prt_dec_num
lda #";"
jsr con_tx
pla
jsr prt_dec_num
lda #"H"
jsr con_tx
rts
clear_seq: .byte 27,"[","H",27,"[","J",0
scroll_up:
.ax8
cmp #255
bne _done
ldx #0
_another:
lda clear_seq,x
beq _done
jsr con_tx
inx
bra _another
_done:
rts