0
|
1 % ISPS Description of the MOS Technology MCS 6502 Microprocessor
|
|
2
|
|
3 % G.W.Leive
|
|
4 % 10 July 1978 ISPS Version
|
|
5 % COPYRIGHT (C) 1978
|
|
6
|
|
7 % rewriten for Tokio
|
|
8
|
|
9 % MC6502 :-
|
|
10
|
|
11 '$function' bit(Bit,I) = ( I >> Bit ) /\ 1 :-true .
|
|
12 '$function' high(Word) = (Word>>8)/\hex("ff") :-true .
|
|
13 '$function' low(Word) = (Word/\hex("ff")) :-true .
|
|
14 '$function' signed(Data) = Signed :- signed(Data,Signed) .
|
|
15 '$function' byte(Word) = (Word/\hex("ff")) :-true .
|
|
16
|
|
17 signed(Data,Signed) :- Data >127,!, Signed = Data - 256.
|
|
18 signed(Data,Data).
|
|
19
|
|
20 :-op(600,xfy, xor).
|
|
21 '$function' xor(A,B) = ( (-A) /\ B) \/ (A /\ (-B)) :-true .
|
|
22
|
|
23 :-static([
|
|
24 mem(_),
|
|
25
|
|
26 % *PCSTATE
|
|
27
|
|
28 pc, % program counter
|
|
29 y, % Index register
|
|
30 x, % Index register
|
|
31 s, % stack pointer
|
|
32 dl, % Input data latch
|
|
33 a, % accumulator
|
|
34 ir, % Instruction register
|
|
35 p, % processor status
|
|
36
|
|
37 n, % Negative result
|
|
38 v, % Overflow
|
|
39 b, % Break command
|
|
40 d, % Decimal mode
|
|
41 i, % Interrupt disable
|
|
42 z, % Zero
|
|
43 c, % Carry
|
|
44
|
|
45 irq, % Interrupt request
|
|
46 nmi, % Non-maskable interrupt
|
|
47 ifsync, % High when instruction fetch
|
|
48 rw, % Read/Write control pin
|
|
49 so, % set overflow pin
|
|
50 reset, % power up bit
|
|
51 ready % 1 means run, 0 means stop
|
|
52
|
|
53 ]).
|
|
54
|
|
55 status_report :-
|
|
56 write(('pc=',*pc,' y=', *y, ' x=',*x , ' dl=', *dl,
|
|
57 ' a=',*a,' ir=',*ir, ' rw=', *rw,
|
|
58 ' s=',*s, ' c=', *c, ' z=' ,*z)).
|
|
59
|
|
60
|
|
61 % ADDRESS.CALCULATION
|
|
62
|
|
63 immed(R):- % Immediate
|
|
64 R <- *pc,
|
|
65 *pc <= *pc + 1.
|
|
66
|
|
67 zp(R):- % Zero page
|
|
68 read(*pc,R) , *pc <= *pc + 1.
|
|
69
|
|
70 abs(R):- % Absolute
|
|
71 ab(*pc + 1, *pc,R),
|
|
72 *pc <= *pc + 2.
|
|
73
|
|
74 indx(R):- % Indexed indirect - (IND, *x)
|
|
75 read(*pc,R) &&
|
|
76 R1 = R + *x, read_2(R1+1,R1,H,L) &&
|
|
77 ab(H,L,R), *pc <= *pc + 1.
|
|
78
|
|
79 indy(R):- % Indirect indexed - (IND), *y
|
|
80 read(*pc,R) &&
|
|
81 ab(R + 1,R ,R) &&
|
|
82 R <- R + *y, *pc <= *pc + 1.
|
|
83
|
|
84 zpx(R):- % Zero page indexed by *x
|
|
85 read(*pc,R1) &&
|
|
86 R <- byte(R1 + *x), *pc <= *pc + 1.
|
|
87
|
|
88 zpy(R):- % Zero page indexed by *y
|
|
89 read(*pc,R1) &&
|
|
90 R <- byte(R1 + *y), *pc <= *pc + 1.
|
|
91
|
|
92 absy(R):- % absolute modified by *y
|
|
93 ab(*pc + 1, *pc,R1) &&
|
|
94 R <- R1 + *y , *pc <= *pc + 2.
|
|
95
|
|
96 absx(R) :- % absolute modified by *x
|
|
97 ab(*pc + 1, *pc,R1) &&
|
|
98 R <- R1 + *x , *pc <= *pc + 2.
|
|
99
|
|
100
|
|
101 % *SERVICE.FACILITIES
|
|
102
|
|
103 push(Dbb) :- % Push a byte on the stack
|
|
104 write(hex("100") + *s, Dbb),
|
|
105 *s <= *s - 1.
|
|
106
|
|
107 pull(R):- % pull a byte off the stack
|
|
108 *s <= *s + 1 &&
|
|
109 read(hex("100") + *s,R).
|
|
110
|
|
111 opex :- % Operation exception
|
|
112 *ready <= 0 && run.
|
|
113
|
|
114 setnz(Ta):- % Set neg and zero condition code
|
|
115 Ta = 0,!, *z <= 1, *n <= 0.
|
|
116 setnz(Ta):-
|
|
117 Ta < 0,!, *z <= 0, *n <= 1.
|
|
118 setnz(Ta):-
|
|
119 Ta > 0,!, *z <= 0, *n <= 0.
|
|
120
|
|
121 branch(0) :- *pc <= *pc + 1.
|
|
122 branch(1) :- read(*pc,R) &&
|
|
123 *pc <= *pc + 1 + signed(R). % Relative addressing
|
|
124
|
|
125 decimal_adjust(Tac):- % Used by sbc and adc
|
|
126 ( if (bit(7,*a) = bit(7,Tac))
|
|
127 then
|
|
128 *v <= bit(7,Tac) xor bit(7,*a),
|
|
129 *c <= bit(8,Tac) ) &&
|
|
130 ( if (*d = 1) then (
|
|
131 (if Tac /\ binary("1111") > 9 then
|
|
132 Tac <- (Tac/\hex("ff") + 6)) &&
|
|
133 (if *c = 0 then *c <= bit(8,Tac)) &&
|
|
134 (if (Tac /\ binary("11110000")>>4) > 9 then
|
|
135 Tac <- (Tac/\hex("ff") + hex("60"))) &&
|
|
136 (if *c = 0 then *c <= bit(8,Tac))
|
|
137 )) &&
|
|
138 *a <= byte(Tac) &&
|
|
139 setnz(*a).
|
|
140
|
|
141 ab(Adh,Adl,R):- % *address buffer
|
|
142 read_2(Adh,Adl,R1,R2),
|
|
143 fin( R = R1<<8 + R2 ).
|
|
144
|
|
145 % Read and write memory access routines
|
|
146
|
|
147 read(Adr,Value):- % Read from valid memory
|
|
148 *rw <= 1, Adr <- Adr &&
|
|
149 read_1(Adr,Value).
|
|
150 read_1(Adr,Value):-
|
|
151 *ready=0,!, int,Adr <- Adr && read_1(Adr,Value).
|
|
152 read_1(Adr,Value) :-
|
|
153 Value <- *mem(Adr).
|
|
154
|
|
155 read_2(AdrH,AdrL,Vh,Vl) :-
|
|
156 read(AdrH,Vh) && read(AdrL,Vl), Vh <- Vh.
|
|
157
|
|
158 write(Adr,Value) :- % Write to valid memory
|
|
159 *rw <=0,Adr <- Adr,Value <-Value &&
|
|
160 *mem(Adr) <= Value.
|
|
161
|
|
162 % Interrupt routines
|
|
163
|
|
164 intstk :- % Interrupt stack operations
|
|
165 push(high(*pc)) &&
|
|
166 push(low(*pc)) &&
|
|
167 push(*p), *i <= 1.
|
|
168
|
|
169 int :- % Interrupt processing
|
|
170 *reset = 0,!,
|
|
171 *reset <= 1,*irq <= 1,*nmi <= 1,*ready <= 1 &&
|
|
172 ab(hex("FFFD"), hex("FFFC"),R) &&
|
|
173 *pc <= R, *i <= 1.
|
|
174 int :-
|
|
175 *nmi = 0,!,
|
|
176 *nmi <= 1 &&
|
|
177 intstk &&
|
|
178 ab(hex("FFFB"), hex("FFFA"),R) &&
|
|
179 *pc <= R.
|
|
180 int :-
|
|
181 (*b = 1 ; *irq = 0, *i = 0),!,
|
|
182 intstk, *b <= 0 &&
|
|
183 ab(hex("FFFF"), hex("FFFE"),R) &&
|
|
184 *pc <= R.
|
|
185 int.
|
|
186
|
|
187 % INSTRUCTION.INTERPRETATION
|
|
188 % Yes It is the main routine.
|
|
189
|
|
190 run :-
|
|
191 (if *reset = 0 then int ) && % Initial startup
|
|
192 run1.
|
|
193 run1 :- *ready = 0 ,! , empty.
|
|
194 run1 :- *ifsync <= 1 && % Instruction fetch
|
|
195 read(*pc,R) &&
|
|
196 *ir <= R , *pc <= *pc + 1, *ifsync <= 0 && % Execute
|
|
197 run_decode(*ir/\binary("11")) &&
|
|
198 int &&
|
|
199 ( if *so=1 then *v <= 1), status_report &&
|
|
200 run.
|
|
201
|
|
202 run_decode(binary("01")) :- !,
|
|
203 I1 = (*ir>>5)/\binary("111"),group1(I1).
|
|
204 run_decode(binary("10")) :- !,
|
|
205 I1 = (*ir>>5)/\binary("111"),group2(I1).
|
|
206 run_decode(binary("00")) :- !, group3(*ir).
|
|
207 run_decode(binary("11")) :- !, opex.
|
|
208
|
|
209 % Group 1 instruction decode
|
|
210
|
|
211 group1( 0 ):- ora.
|
|
212 group1( 1 ):- and.
|
|
213 group1( 2 ):- eor.
|
|
214 group1( 3 ):- adc.
|
|
215 group1( 4 ):- sta.
|
|
216 group1( 5 ):- lda.
|
|
217 group1( 6 ):- cmp.
|
|
218 group1( 7 ):- sbc.
|
|
219
|
|
220 % Group 2 instruction decode
|
|
221
|
|
222 group2( 0 ):- asl.
|
|
223 group2( 1 ):- rol.
|
|
224 group2( 2 ):- lsr.
|
|
225 group2( 3 ):- ror.
|
|
226 group2( 4 ):- stx. % Includes txa. txs
|
|
227 group2( 5 ):- ldx. % Includes tax. tsx
|
|
228 group2( 6 ):- dec. % Includes dex
|
|
229 group2( 7 ):- inc. % Includes no.op
|
|
230
|
|
231 % Group 3 instruction decode
|
|
232
|
|
233 group3(hex("00")) :- !, brk. % Break
|
|
234 group3(hex("08")) :- !, php. % push status on stack
|
|
235 group3(hex("28")) :- !, plp. % pull status from stack
|
|
236 group3(hex("48")) :- !, pha. % push accumulator
|
|
237 group3(hex("68")) :- !, pla. % pull accumulator
|
|
238 group3(hex("10")) :- !, bpl. % Branch on plus
|
|
239 group3(hex("30")) :- !, bmi. % Branch on minus
|
|
240 group3(hex("50")) :- !, bvc. % Branch if overflow clear
|
|
241 group3(hex("70")) :- !, bvs. % Branch if overflow set
|
|
242 group3(hex("90")) :- !, bcc. % Branch on carry clear
|
|
243 group3(hex("D0")) :- !, bne. % Branch on not equal
|
|
244 group3(hex("F0")) :- !, beq. % Branch if equal
|
|
245 group3(hex("B0")) :- !, bcs. % Branch if carry set
|
|
246 group3(hex("18")) :- !, clc. % Clear carry
|
|
247 group3(hex("38")) :- !, sec. % set carry
|
|
248 group3(hex("58")) :- !, cli. % Clear interrupt enable
|
|
249 group3(hex("78")) :- !, sei. % set interrupt enable
|
|
250 group3(hex("B8")) :- !, clv. % Clear overflow
|
|
251 group3(hex("D8")) :- !, cld. % Clear decimal mode
|
|
252 group3(hex("F8")) :- !, sed. % set decimal mode
|
|
253 group3(hex("20")) :- !, jsr. % Jump to subroutine
|
|
254 group3(hex("24")) :- !, % Bit test - zero page
|
|
255 zp(Adr) && read(Adr,V) && bit(V).
|
|
256 group3(hex("2C")) :- !, % Bit test - absolute
|
|
257 abs(Adr) && read(Adr,V) && bit(V).
|
|
258 group3(hex("40")) :- !, rti. % Return from interrupt
|
|
259 group3(hex("4C")) :- !, jmp. % Jump - absolute
|
|
260 group3(hex("6C")) :- !, jmp. % Jump - indirect
|
|
261 group3(hex("60")) :- !, rts. % Return from subroutine
|
|
262 group3(hex("84")) :- !, % Store *y - zero page
|
|
263 zp(Adr) && sty(Adr).
|
|
264 group3(hex("8C")) :- !, % Store *y - absolute
|
|
265 abs(Adr) && sty(Adr).
|
|
266 group3(hex("94")) :- !, % Store *y - zero page, *x
|
|
267 zpx(Adr) && sty(Adr).
|
|
268 group3(hex("88")) :- !, dey. % Decrement *y
|
|
269 group3(hex("C8")) :- !, iny. % Increment *y
|
|
270 group3(hex("E8")) :- !, inx. % Increment *x
|
|
271 group3(hex("98")) :- !, tya. % Transfer *y to *a
|
|
272 group3(hex("A8")) :- !, tay. % Transfer *a to *y
|
|
273 group3(hex("A0")) :- !, % Load *y - immediate
|
|
274 immed(Adr) && ldy(Adr).
|
|
275 group3(hex("A4")) :- !, % Load *y - zero page
|
|
276 zp(Adr) && ldy(Adr).
|
|
277 group3(hex("AC")) :- !, % Load *y - absolute
|
|
278 abs(Adr) && ldy(Adr).
|
|
279 group3(hex("B4")) :- !, % Load *y - zero page, *x
|
|
280 zpx(Adr) && ldy(Adr).
|
|
281 group3(hex("BC")) :- !, % Load *y - absolute, *x
|
|
282 absz(Adr) && ldy(Adr).
|
|
283 group3(hex("C0")) :- !, % Compare immediate to *y
|
|
284 immed(Adr) && cpy(Adr).
|
|
285 group3(hex("C4")) :- !, % Compare zero page to *y
|
|
286 zp(Adr) && cpy(Adr).
|
|
287 group3(hex("CC")) :- !, % Compare absolute to *y
|
|
288 abs(Adr) && cpy(Adr).
|
|
289 group3(hex("E0")) :- !, % Compare immediate to *x
|
|
290 immed(Adr) && cpx(Adr).
|
|
291 group3(hex("E4")) :- !, % Compare zero page to *x
|
|
292 zp(Adr) && cpx(Adr).
|
|
293 group3(hex("EC")) :- !, % Compare absolute to *x
|
|
294 abs(Adr) && cpx(Adr).
|
|
295 group3(I) :- opex.
|
|
296
|
|
297
|
|
298 % INSTRUCTION.EXECUTION
|
|
299
|
|
300 % Group 1 instruction execution
|
|
301
|
|
302 addrs1(Adr) :- % Group 1 address generation
|
|
303 I = (*ir >> 2 ) /\ binary("111"),
|
|
304 addrs1(I,Adr).
|
|
305
|
|
306 addrs1( 0 , Adr):- indx(Adr).
|
|
307 addrs1( 1 , Adr):- zp(Adr).
|
|
308 addrs1( 2 , Adr):- immed(Adr).
|
|
309 addrs1( 3 , Adr):- abs(Adr).
|
|
310 addrs1( 4 , Adr):- indy(Adr).
|
|
311 addrs1( 5 , Adr):- zpx(Adr).
|
|
312 addrs1( 6 , Adr):- absy(Adr).
|
|
313 addrs1( 7 , Adr):- absx(Adr).
|
|
314
|
|
315 ora :- % Or
|
|
316 addrs1(Adr) && read(Adr,R) && *a <= *a /\ R &&
|
|
317 setnz(*a).
|
|
318
|
|
319 and :- % And
|
|
320 addrs1(Adr) && read(Adr,R) && *a <= *a /\ R &&
|
|
321 setnz(*a).
|
|
322
|
|
323 eor :- % Exclusive or
|
|
324 addrs1(Adr) && read(Adr,R) && *a <= *a xor R &&
|
|
325 setnz(*a).
|
|
326
|
|
327 adc :-
|
|
328 addrs1(Adr) && read(Adr,R) &&
|
|
329 decimal_adjust(*a + *c + R). % add with carry
|
|
330
|
|
331 sta :- *ir \= hex("89"),!,
|
|
332 addrs1(Adr) && write(Adr,*a). % store immediate
|
|
333
|
|
334 lda :- % Load accumulator
|
|
335 addrs1(Adr) && read(Adr,R) && *a <= R &&
|
|
336 setnz(*a).
|
|
337
|
|
338 cmp :- % Compare
|
|
339 addrs1(Adr) && read(Adr,R) && setnz(*a - R) &&
|
|
340 if *a > R then *c<=1 else *c<=0.
|
|
341
|
|
342 sbc :-
|
|
343 addrs1(Adr) && read(Adr,R) &&
|
|
344 decimal_adjust(*a + *c - R). % Sub/carry
|
|
345
|
|
346 % Group 2 addressing mode selection
|
|
347
|
|
348 % Group 2 gets and puts
|
|
349
|
|
350 get2(R1,Adr) :- % Get the correct operand and return it in R1
|
|
351 I = (*ir >> 2) /\ binary("111"),
|
|
352 get2(I,R,Adr) ,fin( R1 = R + (*c << 8)).
|
|
353
|
|
354 get2(1,R,Adr) :- zp(Adr) && Adr <- Adr, read(Adr,R).
|
|
355 get2(2,R,Adr) :- R <- *a, Adr <- Adr.
|
|
356 get2(3,R,Adr) :- abs(Adr) && Adr <- Adr, read(Adr,R).
|
|
357 get2(5,R,Adr) :- zpx(Adr) && Adr <- Adr, read(Adr,R).
|
|
358 get2(7,R,Adr) :- absx(Adr) && Adr <- Adr, read(Adr,R).
|
|
359 get2(_,R,Adr) :- opex.
|
|
360
|
|
361 put2(Ta,Adr) :- % put the operand in the proper location
|
|
362 I = (*ir >> 2) /\ binary("111"),
|
|
363 put2(I,Ta,Adr),Ta<-Ta && setnz(Ta).
|
|
364
|
|
365 put2(1,Ta,Adr) :- write(Adr, Ta).
|
|
366 put2(3,Ta,Adr) :- write(Adr, Ta).
|
|
367 put2(5,Ta,Adr) :- write(Adr, Ta).
|
|
368 put2(7,Ta,Adr) :- write(Adr, Ta).
|
|
369 put2(2,Ta,Adr) :- *a <= Ta.
|
|
370 put2(_,Ta,Adr) :-opex.
|
|
371
|
|
372 % Group 2 instruction execution
|
|
373
|
|
374 asl :- % Arithmetic shift left
|
|
375 get2(V,Adr) &&
|
|
376 V1 = V << 1,
|
|
377 *c <= (V1 >> 8) /\ 1,put2(byte(V1),Adr).
|
|
378
|
|
379 rol :- % rotate left
|
|
380 get2(V,Adr) &&
|
|
381 V1 = (V << 1)+ *c,
|
|
382 *c <= (V1 >> 8) /\ 1,put2(byte(V1),Adr).
|
|
383
|
|
384 lsr :- % Logical shift right
|
|
385 get2(V,Adr) &&
|
|
386 V1 = (V >> 1)/\ hex("7f") ,
|
|
387 *c <= V /\ 1, put2(byte(V1),Adr).
|
|
388
|
|
389 ror :- % Rotate right
|
|
390 get2(V,Adr) &&
|
|
391 V1 = (V >> 1)/\ hex("7f") + ( (V /\ 1) << 8),
|
|
392 *c <= V /\ 1 , put2(byte(V1),Adr).
|
|
393
|
|
394 stx :- % store index register
|
|
395 I = (*ir>>2)/\binary("111"),
|
|
396 stx(I,*x).
|
|
397
|
|
398 stx(1,X) :- zp(Adr) && write(Adr, X).
|
|
399 stx(2,X) :- *a <= X. % Txa
|
|
400 stx(3,X) :- as(Adr) && write(Adr, X).
|
|
401 stx(5,X) :- zpy(Adr) && write(Adr, X).
|
|
402 stx(6,X) :- *s <= X. % Txs
|
|
403 stx(_,_) :- opex.
|
|
404
|
|
405 ldx :- % Load index register
|
|
406 I = (*ir>>2)/\binary("111"),
|
|
407 ldx(I,X) && *x <= X && setnz(*x).
|
|
408
|
|
409 ldx(0,X) :- immed(Adr) && read(Adr,X).
|
|
410 ldx(1,X) :- zp(Adr) && read(Adr,X).
|
|
411 ldx(2,X) :- X <- *a. % Tax
|
|
412 ldx(3,X) :- abs(Adr) && read(Adr,X).
|
|
413 ldx(4,X) :- opex.
|
|
414 ldx(5,X) :- zpy(Adr) && read(Adr,X).
|
|
415 ldx(6,X) :- X <- *s. % Tsx
|
|
416 ldx(7,X) :- absy(Adr) && read(Adr,X).
|
|
417
|
|
418 dec :- % Decrement
|
|
419 *ir = hex("CA"),!, % Dex
|
|
420 X = *x - 1,*x <= X, setnz(X).
|
|
421 dec :- get2(Value,Adr) && put2(Value - 1,Adr).
|
|
422
|
|
423 inc :- % Increment
|
|
424 *ir = hex("EA"),!. % EA no.op
|
|
425 inc :-
|
|
426 get2(Value,Adr) && put2(Value + 1,Adr).
|
|
427
|
|
428 % Group 3 instruction execution
|
|
429
|
|
430 brk :-
|
|
431 *ready <= 0. % for Debug
|
|
432 % (*b <= 1, *pc <= *pc+1). % Break
|
|
433
|
|
434 php :- push(*p). % push processor status on stack
|
|
435 plp :- pull(A),*p <= A. % pull processor status from stack
|
|
436 pha :- push(*a). % push accumulator on stack
|
|
437 pla :- % pull accumulator from stack
|
|
438 pull(A) && *a <= A, setnz(A).
|
|
439
|
|
440 bpl :- boolNot(*n,B),branch(B). % Branch on plus
|
|
441 bmi :- bool(*n,B),branch(B). % Branch on minus
|
|
442 bvc :- boolNot(*v,B),branch(B). % Branch on overflow clear
|
|
443 bvs :- bool(*v,B),branch(B). % Branch if overflow set
|
|
444 bcc :- boolNot(*c,B),branch(B). % Branch on carry clear
|
|
445 bne :- boolNot(*z,B),branch(B). % Branch if not equal
|
|
446 beq :- bool(*z,B),branch(B). % Branch on equal
|
|
447 bcs :- bool(*c,B),branch(B). % Branch on carry set
|
|
448
|
|
449 bool(1,1). bool(0,0).
|
|
450 boolNot(1,0). boolNot(0,1).
|
|
451
|
|
452 clc :- *c <= 0. % Clear carry flag
|
|
453 sec :- *c <= 1. % Set carry
|
|
454 cli :- *i <= 0. % Clear interrupt disable bit
|
|
455 sei :- *i <= 1. % Set interrupt disable status
|
|
456 clv :- *v <= 0. % Clear overflow
|
|
457 cld :- *d <= 0. % Clear decimal mode
|
|
458 sed :- *d <= 1. % Set decimal mode
|
|
459
|
|
460 jsr :- % Jump to subroutine
|
|
461 push(high(*pc + 1)) &&
|
|
462 push(low(*pc + 1)) &&
|
|
463 abs(Value) && *pc <= Value.
|
|
464
|
|
465 bit(Ta) :- % Bit test
|
|
466 *n <= Ta, (if (Ta /\ *a)=0 then *z <= 1 else *z <= 0).
|
|
467
|
|
468 rti :- % Return from interrupt
|
|
469 pull(P) && *p <= P &&
|
|
470 pull(P) && *pc<= P &&
|
|
471 pull(P) && *pc<= (P<<8)+ *pc, *b <= 0.
|
|
472
|
|
473 jmp :- *ir = hex("6C"),!,
|
|
474 abs(Value) && *pc <= Value &&
|
|
475 abs(Value) && *pc <= Value . % Indirect
|
|
476 jmp :- abs(Value) && *pc <= Value.
|
|
477
|
|
478
|
|
479 % Group 3 instruction execution (page 2)
|
|
480
|
|
481 rts :- % return from subroutine
|
|
482 pull(P) && *pc<= P &&
|
|
483 pull(P) && *pc<= (P<<8)+ *pc &&
|
|
484 *pc <= *pc+1.
|
|
485
|
|
486 sty(X) :- write(X, *y). % Store index *y in memory
|
|
487
|
|
488 dey :- % Decrement index *y by one
|
|
489 Y = *y - 1,*y <= Y, setnz(Y).
|
|
490
|
|
491 tya :- % Transfer index *y to accumulator
|
|
492 *a <= *y, setnz(*y).
|
|
493
|
|
494 ldy(A) :- read(A,Value) && *y <= Value. % Load index *y with memory
|
|
495
|
|
496 tay :- % Transfer accumulator to index *y
|
|
497 *y <= *a, setnz(*a).
|
|
498
|
|
499 cpy(A) :- % Compare memory and index *y
|
|
500 read(A,Value) && setnz(*y - Value),
|
|
501 (if *y > Value then *c <= 1 else *c <= 0).
|
|
502
|
|
503 iny :- % Increment index *y by one
|
|
504 Y = *y + 1 , *y <= Y, setnz(*y).
|
|
505
|
|
506 cpx(A) :- % Compare memory and index *x
|
|
507 read(A,Value) && setnz(*x - Value),
|
|
508 (if *x > Value then *c <= 1 else *c <= 0).
|
|
509
|
|
510 inx :- % Increment index *x by one
|
|
511 X = *x + 1, *x <= X, setnz(*x).
|
|
512
|
|
513 % End of MC6502
|
|
514
|
|
515
|