File:  [Isaki's NoNo m68k/m88k emulator] / nono / exp / cas1.has
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:49 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v027, v026, v025, HEAD
nono 1.5.0

; vi:set ts=8:

; nono
; Copyright (C) 2025 nono project
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
;    notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
;    notice, this list of conditions and the following disclaimer in the
;    documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
; SUCH DAMAGE.

; CAS.[BWL] Dc,Du,<ea>
;
;  cc := *(ea) - Dc
;  If (Z), *(ea) := Du
;  Else    Dc := *(ea)

	.xref	hexstr_long
	.include doscall.mac
	.list
	.cpu	68030

PRINT	.macro	msg
	pea.l	msg
	DOS	_PRINT
	addq.l	#4,sp
	.endm

	.offset	0
o_initea:	.ds.l	1
o_exp_dc:	.ds.l	1
o_exp_du:	.ds.l	1
o_exp_ac:	.ds.l	1
o_exp_au:	.ds.l	1
o_exp_ea:	.ds.l	1
o_inst:		.ds.w	3
o_msg:		.ds.b	0

	.text
	.even

	; d0-d1	汎用
	; d2-d3	Dc,Du 用
	; d4    <ea> 入出力用
	; d7	テスト番号
	; a2-a3 Ac,Au 用
	; a4	<ea>
	; a5	テストデータ

start:
	lea.l	data(pc),a4

	moveq.l	#0,d7
loop:
	bsr	do_test
	addq.l	#1,d7
	cmpi.l	#8,d7
	bne	loop

	DOS	_EXIT

do_test:
	lea.l	testdata,a5
	move.l	(a5,d7.l*4),a5
	PRINT	o_msg(a5)
	; Exec
	movem.l	initial(pc),d2-d3/a2-a3
	move.l	o_initea(a5),(a4)
	jsr	o_inst(a5)
check:
check_dc:
	move.l	o_exp_dc(a5),d1
	cmp.l	d1,d2
	beq	@f
	pea.l	msg_dc(pc)
	move.l	d1,-(sp)
	move.l	d2,-(sp)
	bsr	fail
	lea.l	12(sp),sp
@@:
check_du:
	move.l	o_exp_du(a5),d1
	cmp.l	d1,d3
	beq	@f
	pea.l	msg_du(pc)
	move.l	d1,-(sp)
	move.l	d3,-(sp)
	bsr	fail
	lea.l	12(sp),sp
@@:
check_ac:
	move.l	o_exp_ac(a5),d1
	cmpa.l	d1,a2
	beq	@f
	pea.l	msg_ac(pc)
	move.l	d1,-(sp)
	move.l	a2,-(sp)
	bsr	fail
	lea.l	12(sp),sp
@@:
check_au:
	move.l	o_exp_au(a5),d1
	cmpa.l	d1,a3
	beq	@f
	pea.l	msg_au(pc)
	move.l	d1,-(sp)
	move.l	a3,-(sp)
	bsr	fail
	lea.l	12(sp),sp
@@:
check_ea:
	move.l	o_exp_ea(a5),d1
	cmp.l	(a4),d1
	beq	@f
	pea.l	msg_ea(pc)
	move.l	d1,-(sp)
	move.l	(a4),-(sp)
	bsr	fail
	lea.l	12(sp),sp
@@:
check_done:
	rts

; arg: +$4.l actual
;      +$8.l expected
;      +$c.l name
fail:
	PRINT	msg_fail(pc)
	move.l	$c(sp),-(sp)
	DOS	_PRINT
	addq.l	#4,sp
	PRINT	msg_expects(pc)
	move.l	$8(sp),d0
	lea.l	hexbuf(pc),a0
	bsr	hexstr_long
	PRINT	hexbuf(pc)
	PRINT	msg_but(pc)
	move.l	$4(sp),d0
	lea.l	hexbuf(pc),a0
	bsr	hexstr_long
	PRINT	hexbuf(pc)
	PRINT	msg_crlf(pc)
	rts

	; d2-d3/a2-a3 の初期値
initial:
	.dc.l	1, 2, 3, 4

testdata:
	.dc.l	testdata0
	.dc.l	testdata1
	.dc.l	testdata2
	.dc.l	testdata3
	.dc.l	testdata4
	.dc.l	testdata5
	.dc.l	testdata6
	.dc.l	testdata7

	; <ea> の初期値
	; Dc, Du, Ac, Au, <ea> の期待値
	; 実行する命令; rts
	; 表示するテスト名

testdata0:
	.dc.l	1
	.dc.l	1, 2, 3, 4, 2
	cas.l	d2,d3,(a4)
	rts
	.dc.b	"CAS Dc,Du,<ea> (EQ)",$d,$a,0
	.even
testdata1:
	.dc.l	0
	.dc.l	0, 2, 3, 4, 0
	cas.l	d2,d3,(a4)
	rts
	.dc.b	"CAS Dc,Du,<ea> (NE)",$d,$a,0
	.even
testdata2:
	.dc.l	1
	.dc.l	1, 2, 3, 4, 2
	.dc.w	$0ed4, $2+($b<<6)	; cas.l	d2,a3,(a4)
	rts
	.dc.b	"CAS Dc,Au,<ea> (EQ)",$d,$a,0
	.even
testdata3:
	.dc.l	0
	.dc.l	0, 2, 3, 4, 0
	.dc.w	$0ed4, $2+($b<<6)	; cas.l	d2,a3,(a4)
	rts
	.dc.b	"CAS Dc,Au,<ea> (NE)",$d,$a,0
	.even
testdata4:
	.dc.l	3
	.dc.l	1, 2, 3, 4, 2
	.dc.w	$0ed4, $a+($3<<6)	; cas.l a2,d3,(a4)
	rts
	.dc.b	"CAS Ac,Du,<ea> (EQ)",$d,$a,0
	.even
testdata5:
	.dc.l	0
	.dc.l	1, 2, 0, 4, 0
	.dc.w	$0ed4, $a+($3<<6)	; cas.l a2,d3,(a4)
	rts
	.dc.b	"CAS Ac,Du,<ea> (NE)",$d,$a,0
	.even
testdata6:
	.dc.l	3
	.dc.l	1, 2, 3, 4, 4
	.dc.w	$0ed4, $a+($b<<6)	; cas.l a2,a3,(a4)
	rts
	.dc.b	"CAS Ac,Au,<ea> (EQ)",$d,$a,0
	.even
testdata7:
	.dc.l	0
	.dc.l	1, 2, 0, 4, 0
	.dc.w	$0ed4, $a+($b<<6)	; cas.l a2,a3,(a4)
	rts
	.dc.b	"CAS Ac,Au,<ea> (NE)",$d,$a,0
	.even

msg_dc:	.dc.b	"Dc",0
msg_du:	.dc.b	"Du",0
msg_ac:	.dc.b	"Ac",0
msg_au:	.dc.b	"Au",0
msg_ea:	.dc.b	"<ea>",0
msg_crlf:
	.dc.b	$d,$a,0
msg_fail:
	.dc.b	$9,"*** ",0
msg_expects:
	.dc.b	" expects ",0
msg_but:
	.dc.b	" but got ",0

	.bss
data:
	.ds.l	1
hexbuf:
	.ds.b	16

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.