Commit MetaInfo

Revisionba9d1cd9352d3c7d9703905d25a048b77b648a21 (tree)
Time2019-05-20 14:07:47
Authoringlorion <homemicro@ingl...>
Commiteringlorion

Log Message

added application to test emulator

Change Summary

Incremental Difference

diff -r 293173929fb5 -r ba9d1cd9352d apps/emutest/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/emutest/Makefile Sun May 19 22:07:47 2019 -0700
@@ -0,0 +1,13 @@
1+TARGETS = emutest.bin
2+
3+all : $(TARGETS)
4+
5+clean :
6+
7+distclean : clean
8+ -rm $(TARGETS)
9+
10+emutest.bin : emutest.s
11+ xa -M -bt 57344 -o emutest.bin emutest.s
12+
13+.PHONY : all clean distclean
diff -r 293173929fb5 -r ba9d1cd9352d apps/emutest/emutest.s
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/emutest/emutest.s Sun May 19 22:07:47 2019 -0700
@@ -0,0 +1,639 @@
1+ cls = $e003
2+ curpos = $80
3+ fontbase = $e800
4+
5+ ;; Locations at which to store temporary values.
6+ ;; These must be consecutive, with no page boundary in between.
7+ t0 = $8
8+ t1 = $9
9+
10+ ;; A location on the zero page. May be the same or different
11+ ;; from the t locations.
12+ zp0 = t0
13+
14+ * = $0000
15+ .byt "HM",0,1
16+ .word _start
17+ .word 32
18+ .word _endhdr
19+ .word _end-_start
20+ .word _start
21+ .word 0
22+
23+_endhdr:
24+ * = $0400
25+_start:
26+ ;; Initialization.
27+ ;; We want to keep the number of instructions we rely on small,
28+ ;; so that the tests can work even if not all instructions are
29+ ;; not completely correctly implemented. However, to put the CPU
30+ ;; in a known state, we execute some instructions here that we
31+ ;; otherwise do not rely on. If any of these are not implemented
32+ ;; in an emulator being tested, they can be commented out.
33+ sei
34+ cld
35+ ldx #$ff
36+ txs
37+ jsr initoutp
38+
39+ ;; Test bne instruction.
40+ ;; Instructions assumed working:
41+ ;; - lda immediate must correctly load value, set the z flag
42+ ;; if it is 0, and clear the z flag if it is nonzero.
43+ ;; - jmp absolute must transfer control to the correct address.
44+ ;; - jsr must save address and transfer control to the correct
45+ ;; address.
46+ ;; - rts must return to the instruction after the most recent jsr.
47+ ;; - nop
48+ ;; The test is surrounded by nop slides that jmp to the failure
49+ ;; code.
50+ ;; For correct reporting, the report, ok, and fail procedures
51+ ;; must also work.
52+ jmp test_bne
53+ .dsb 253, $ea
54+ jmp bne_fail
55+test_bne:
56+ lda #$00
57+ jsr report
58+ lda #0
59+ bne bne_fail
60+ lda #1
61+ bne bne_ok
62+bne_fail:
63+ jsr fail
64+ jmp halt
65+bne_ok1:
66+ jmp bne_done
67+bne_ok:
68+ lda #0
69+ bne bne_fail
70+ lda #1
71+ bne bne_ok1
72+ .dsb 253, $ea
73+ jmp bne_fail
74+bne_done:
75+ jsr ok
76+
77+test_cmpz:
78+ ;; Tests that the cmp instruction sets the z flag as expected.
79+ lda #$01
80+ jsr report
81+ lda #0
82+ cmp #0
83+ bne cmpz_fail
84+ cmp #1
85+ bne cmpz_ok
86+cmpz_fail:
87+ jsr fail
88+ jmp halt
89+cmpz_ok:
90+ lda #1
91+ sta t0
92+ cmp t0
93+ bne cmpz_fail
94+ lda #0
95+ cmp t0
96+ bne cmpz_ok1
97+ jmp cmpz_fail
98+cmpz_ok1:
99+ jsr ok
100+
101+test_flags:
102+ ;; Test processor status register.
103+ ;; Layout:
104+ ;; N V 1 B D I Z C
105+ ;; | | | | | | | |
106+ ;; | | | | | | | \-- carry
107+ ;; | | | | | | \---- zero
108+ ;; | | | | | \------ interrupt disable
109+ ;; | | | | \-------- decimal mode
110+ ;; | | | \---------- break
111+ ;; | | \------------ always 1
112+ ;; | \-------------- overflow
113+ ;; \---------------- negative
114+ ;;
115+ ;; Instructions assumed working:
116+ ;; - lda immediate must correctly load value.
117+ ;; - jmp absolute must transfer control to the correct address.
118+ ;; - jsr must save address and transfer control to the correct
119+ ;; address.
120+ ;; - rts must return to the point right after jsr.
121+ ;; - cmp immediate must set the zero flag when imm is equal to a,
122+ ;; and clear the zero flag when they are not equal.
123+ ;; - bne must transfer control to the correct location.
124+ ;; - php must push processor status.
125+ ;; - pla must pull a.
126+ lda #$02
127+ jsr report
128+ lda #2
129+ cmp #1
130+ clc
131+ cli
132+ php
133+ sei
134+ pla
135+ ;; only b set
136+ cmp #$30
137+ bne fail02
138+ jmp ok02
139+fail02:
140+ jsr fail
141+ jmp halt
142+ok02:
143+ lda #2
144+ cmp #1
145+ clc
146+ php
147+ pla
148+ ;; only b and i set.
149+ cmp #$34
150+ bne fail02
151+ lda #0
152+ cmp #0
153+ clc
154+ php
155+ pla
156+ ;; b, i and z set
157+ cmp #$36
158+ bne fail02
159+ lda #0
160+ cmp #0
161+ php
162+ pla
163+ ;; b, c, i and z set
164+ cmp #$37
165+ bne fail02
166+ lda #1
167+ cmp #0
168+ php
169+ pla
170+ ;; b, c, and i set
171+ cmp #$35
172+ bne fail02
173+ lda #0
174+ cmp #1
175+ php
176+ pla
177+ ;; b, i and n set
178+ cmp #$b4
179+ bne fail02
180+ sec
181+ php
182+ pla
183+ ;; b, c, i, and z set
184+ cmp #$37
185+ bne fail02
186+ jsr ok
187+
188+ ;; At this point, we have a basic set of useful instructions:
189+ ;; - bne jumps to the correct location under the right conditions.
190+ ;; - clc, cli, sec, and sei work.
191+ ;; - cmp correctly sets the flags.
192+ ;; - jmp absolute, jsr, and rts work.
193+ ;; - lda correctly loads immediate values and sets the z flag.
194+ ;; - php pushes the processor status register
195+ ;; - pha pulls a
196+ ;; - the flags are in the correct locations in the processor
197+ ;; status register.
198+
199+test_pha:
200+ ;; Tests the pha instruction.
201+ lda #$03
202+ jsr report
203+ lda #$53
204+ bne pha_nzok
205+ jmp pha_fail
206+pha_nzok:
207+ cmp #$53
208+ ;; Save flags after equal comparison.
209+ php
210+ pla
211+ sta t0
212+ lda #$53
213+ cmp #$53
214+ ;; Flags at this point should equal saved flags.
215+ pha
216+ ;; pha should not have affected flags.
217+ php
218+ pla
219+ cmp t0
220+ bne pha_fail
221+ ;; After pla, z flag should be clear and a
222+ ;; should be #$53.
223+ lda #0
224+ pla
225+ bne pha_nzok1
226+ jmp pha_fail
227+pha_nzok1:
228+ cmp #$53
229+ bne pha_fail
230+ jsr ok
231+ jmp pha_done
232+pha_fail:
233+ jsr fail
234+pha_done:
235+
236+test_and:
237+ lda #$04
238+ jsr report
239+ ;; and with #$80 should clear all but the highest bit.
240+ lda #$ff
241+ and #$80
242+ cmp #$80
243+ bne and_fail
244+ lda #$80
245+ and #$7f
246+ cmp #0
247+ bne and_fail
248+ ;; and should set the z flag depending on the result.
249+ lda #$aa
250+ and #$55
251+ bne and_fail
252+ lda #$ab
253+ and #$55
254+ bne andne
255+ jmp and_fail
256+andne:
257+ lda #$e3
258+ sta t0
259+ ;; and with 0 should always result in 0.
260+ and #0
261+ bne and_fail
262+ ;; and should work on values in memory.
263+ lda #$ff
264+ and t0
265+ cmp #$e3
266+ bne and_fail
267+ lda #$55
268+ and t0
269+ cmp #$41
270+ bne and_fail
271+ ;; and should set the n flag depending on the result.
272+ lda #$7f
273+ and t0
274+ php
275+ pla
276+ and #$80
277+ bne and_fail
278+ lda t0
279+ and #$80
280+ php
281+ pla
282+ and #$80
283+ cmp #$80
284+ bne and_fail
285+ jsr ok
286+ jmp and_done
287+and_fail:
288+ jsr fail
289+and_done:
290+
291+test_ora:
292+ lda #$05
293+ jsr report
294+ ;; ora with 0 leaves value unchanged.
295+ lda #$a0
296+ sta t0
297+ lda #0
298+ ora t0
299+ cmp #$a0
300+ bne ora_fail
301+ ;; ora with some set bits causes those bits
302+ ;; to become set.
303+ lda t0
304+ ora #$15
305+ cmp #$b5
306+ bne ora_fail
307+ ;; ora sets n flag.
308+ lda #0
309+ ora t0
310+ php
311+ pla
312+ and #$80
313+ cmp #$80
314+ bne ora_fail
315+ ;; ora clears z flag.
316+ lda #0
317+ ora t0
318+ bne orane
319+ jmp ora_fail
320+orane:
321+ ;; ora sets z flag.
322+ lda #0
323+ sta t0
324+ cmp #1
325+ ora t0
326+ bne ora_fail
327+ jsr ok
328+ jmp ora_done
329+ora_fail:
330+ jsr fail
331+ora_done:
332+
333+ ;; At this point, in addition to the basic instructions
334+ ;; established earlier, we have and, ora, and pha.
335+ ;; We will use these with the plp instruction to arbitrarily
336+ ;; manipulate processor flags, and use those flags to test
337+ ;; branch instructions.
338+
339+test_branches:
340+ lda #$06
341+ jsr report
342+ php
343+ pla
344+ ora #2
345+ pha
346+ plp
347+ beq beq_taken
348+ jmp branches_fail
349+beq_taken:
350+ and #$fd
351+ pha
352+ plp
353+ beq branches_fail
354+ ora #1
355+ pha
356+ plp
357+ bcc branches_fail
358+ bcs bcs_taken
359+ jmp branches_fail
360+bcs_taken:
361+ and #$fe
362+ pha
363+ plp
364+ bcs branches_fail
365+ bcc bcc_taken
366+ jmp branches_fail
367+bcc_taken:
368+ ora #$80
369+ pha
370+ plp
371+ bpl branches_fail
372+ bmi bmi_taken
373+ jmp branches_fail
374+bmi_taken:
375+ and #$7f
376+ pha
377+ plp
378+ bmi branches_fail
379+ bpl bpl_taken
380+ jmp branches_fail
381+bpl_taken:
382+ ora #$40
383+ pha
384+ plp
385+ bvc branches_fail
386+ bvs bvs_taken
387+ jmp branches_fail
388+bvs_taken:
389+ and #$bf
390+ pha
391+ plp
392+ bvs branches_fail
393+ bvc bvc_taken
394+ jmp branches_fail
395+bvc_taken:
396+ jsr ok
397+ jmp branches_done
398+branches_fail:
399+ jsr fail
400+ jmp halt
401+branches_done:
402+
403+test_xy:
404+ ;; Tests that we can load, store, and compare x and y.
405+ lda #$08
406+ jsr report
407+ ldx #$8f
408+ beq xy_fail
409+ bpl xy_fail
410+ cpx #$90
411+ beq xy_fail
412+ bcs xy_fail
413+ bpl xy_fail
414+ cpx #$7f
415+ beq xy_fail
416+ bcc xy_fail
417+ bmi xy_fail
418+ cpx #$8f
419+ bne xy_fail
420+ bcc xy_fail
421+ bmi_xy_fail
422+ stx t0
423+ ldx #0
424+ bne xy_fail
425+ bmi xy_fail
426+ ldx t0
427+ cpx #$8f
428+ bne xy_fail
429+ ldy #$7f
430+ beq xy_fail
431+ bmi xy_fail
432+ cpy #$80
433+ beq xy_fail
434+ bcs xy_fail
435+ bpl xy_fail
436+ cpy #$7e
437+ beq xy_fail
438+ bcc xy_fail
439+ bmi xy_fail
440+ cpy #$7f
441+ bne xy_fail
442+ bcc xy_fail
443+ bmi xy_fail
444+ ;; Test indexed loads.
445+ lda #1
446+ sta t0
447+ lda #2
448+ sta t1
449+ ldy #0
450+ ldx t0, y
451+ cpx #1
452+ bne xy_fail
453+ ldy #1
454+ ldx t0, y
455+ cpx t1
456+ bne xy_fail
457+ ldx #1
458+ ldy t0, x
459+ cpy #2
460+ bne xy_fail
461+ ldx #0
462+ ldy t0, x
463+ cpy t0
464+ bne xy_fail
465+ jsr ok
466+ jmp xy_done
467+xy_fail:
468+ jsr fail
469+xy_done:
470+
471+test_wrap:
472+ ;; Tests that zero page indexed loads wrap around.
473+ lda #$09
474+ jsr report
475+ ;; zp, y wraps around.
476+ lda #3
477+ sta zp0
478+ ldy #$ff
479+ ldx zp0 + 1, y
480+ cpx #3
481+ bne wrap_fail
482+ lda #4
483+ sta zp0
484+ ldx zp0 + 1, y
485+ cpx #4
486+ bne wrap_fail
487+ ;; zp, x wraps around.
488+ lda #3
489+ ldx #$ff
490+ ldy zp0 + 1, x
491+ cpy #4
492+ bne wrap_fail
493+ sta zp0
494+ ldy zp0 + 1, x
495+ cpy #3
496+ bne wrap_fail
497+ jsr ok
498+ jmp wrap_done
499+wrap_fail:
500+ jsr fail
501+wrap_done:
502+
503+test_adc:
504+ lda #$0a
505+ jsr report
506+ lda #1
507+ sta t0
508+ ;; no carry in
509+ lda #0
510+ clc
511+ adc #$2a
512+ bcs adc_fail
513+ bvs adc_fail
514+ bmi adc_fail
515+ cmp #$2a
516+ bne adc_fail
517+ ;; carry in
518+ sec
519+ adc #0
520+ bcs adc_fail
521+ bvs adc_fail
522+ bmi adc_fail
523+ cmp #$2b
524+ bne adc_fail
525+ ;; no overflow, positive
526+ lda #$7e
527+ clc
528+ adc #1
529+ bcs adc_fail
530+ bvs adc_fail
531+ bmi adc_fail
532+ cmp #$7f
533+ bne adc_fail
534+ ;; overflow, negatize
535+ clc
536+ adc t0
537+ bcs adc_fail
538+ bvc adc_fail
539+ bpl adc_fail
540+ cmp #$80
541+ bne adc_fail
542+ ;; overflow, carry, positive
543+ lda #$ff
544+ clc
545+ adc t0
546+ bcc adc_fail
547+ bvc adc_fail
548+ bmi adc_fail
549+ cmp #$7f
550+ bne adc_fail
551+ jsr ok
552+ jmp adc_done
553+adc_fail:
554+ jsr fail
555+adc_done:
556+
557+test_asl:
558+
559+
560+
561+halt:
562+ jmp halt
563+
564+initoutp:
565+;;; Initialize output.
566+;;; This clears the screen and sets the cursor to the
567+;;; beginning of the screen.
568+ jsr cls
569+ lda #$20
570+ sta curpos + 1
571+ lda #0
572+ sta curpos
573+ rts
574+
575+ok:
576+;;; Report success. Displays a minus sign.
577+ lda #$2d
578+ jmp showchr
579+
580+fail:
581+;;; Report failure. Displays an exclamation mark.
582+ lda #$21
583+ jmp showchr
584+
585+report:
586+;;; Report what we're currently working on.
587+;;; For simplicity, this just outputs a in hexadecimal.
588+;;; Clobbers y.
589+ pha
590+ lsr
591+ lsr
592+ lsr
593+ lsr
594+ tay
595+ lda hexits, y
596+ jsr showchr
597+ pla
598+ and #$f
599+ tay
600+ lda hexits, y
601+ jmp showchr
602+
603+showchr:
604+;;; Displays a character at the current cursor position
605+;;; and updates the cursor position.
606+;;; In:
607+;;; a Character to display.
608+;;; Clobbers y.
609+ asl
610+ rol
611+ rol
612+ tay
613+ rol
614+ and #7
615+ clc
616+ adc #>fontbase
617+ sta $a1
618+ tya
619+ and #$f8
620+ sta $a0
621+ ldy #7
622+showchr_loop:
623+ lda ($a0), y
624+ sta (curpos), y
625+ dey
626+ bpl showchr_loop
627+ lda curpos
628+ ;; Assume carry is clear. Last instr affecting it was
629+ ;; adc #>fontbase, which should not have resulted in carry.
630+ adc #8
631+ sta curpos
632+ lda curpos + 1
633+ adc #0
634+ sta curpos + 1
635+ rts
636+
637+hexits:
638+ .byte "0123456789abcdef"
639+_end:
Show on old repository browser