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

;
; nono
; Copyright (C) 2023 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.

; エリアセット、拡張エリアセットで設定した領域を DMAC からアクセスしてみる
; テスト。だけのはずだったがついでに各 FC でアクセスしてみる。
;
; % has area.has
; % hlk area.o si_util.o
;
; usage:
;   area <address>

		.include	doscall.mac
		.include	iocscall.mac
		.xref		hexstr_long

DMAC_ch2:	.equ	$e84080
DMAC_CSR:	.equ	$00
DMAC_DCR:	.equ	$04
DMAC_OCR:	.equ	$05
DMAC_SCR:	.equ	$06
DMAC_CCR:	.equ	$07
DMAC_MTC:	.equ	$0a
DMAC_MAR:	.equ	$0c
DMAC_DAR:	.equ	$14
DMAC_NIV:	.equ	$25
DMAC_EIV:	.equ	$27
DMAC_MFC:	.equ	$29
DMAC_DFC:	.equ	$31

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

PUTCHAR		.macro	chr
		move.w	#chr,-(sp)
		DOS	_PUTCHAR
		addq.l	#2,sp
		.endm

		.cpu	68000
		.list
		.text
		.even
start:
		clr.l	-(sp)
		DOS	_SUPER
		addq.l	#4,sp

		exg.l	sp,sp			; ブレークポイント
		bsr	check_arg
		bsr	init

		move.l	addr(pc),d0		; アドレス表示
		lea.l	addrbuf(pc),a0
		bsr	hexstr_long
		move.b	#' ',(a0)+
		move.b	#0,(a0)
		PRINT	addrbuf(pc)

		move.l	addr(pc),a0

		moveq.l	#$1,d1
		bsr	print_rw
		PUTCHAR	' '
		moveq.l	#$2,d1
		bsr	print_rw
		PUTCHAR	' '
		moveq.l	#$5,d1
		bsr	print_rw
		PUTCHAR	' '
		moveq.l	#$6,d1
		bsr	print_rw
		PRINT	msg_crlf(pc)

		; 後始末
		moveq.l	#$68,d1
		move.l	niv_backup(pc),a1
		IOCS	_B_INTVCS
		moveq.l	#$69,d1
		move.l	eiv_backup(pc),a1
		IOCS	_B_INTVCS

		DOS	_EXIT

; a0 (d1.B がFC) について読み書きした結果を表示する。
; 破壊 d2
print_rw:
		moveq.l	#$80,d2
		bsr	checkmem
		bne	@f
		PUTCHAR	'R'
		bra	@@f
@@:
		PUTCHAR	'-'
@@:

		moveq.l	#$00,d2
		bsr	checkmem
		bne	@f
		PUTCHAR	'W'
		bra	@@f
@@:
		PUTCHAR	'-'
@@:
		rts


; DMA でアクセス出来るかチェックする。
; d1.B はチェックする FC。
; d2.B は 0 なら書き込み、0x80 なら読み込み。
; a1.L はチェックするアドレス。
; a4 は DMA#2 のベースアドレス (グローバル変数)
; アクセスできれば d0.L に 0 を返す。出来なければ非0 を返す。
checkmem:
		movem.l	a0,-(sp)

		clr.b	niv_occur
		clr.b	eiv_occur

		moveq.l	#$11,d0			; Word, ReqMax
		or.b	d2,d0			; bit7 = DtoM/MtoD
		move.b	d0,DMAC_OCR(a4)

		move.w	#$0001,DMAC_MTC(a4)
		move.l	a0,DMAC_DAR(a4)
		lea.l	buf(pc),a0
		move.l	a0,DMAC_MAR(a4)
		move.b	d1,DMAC_DFC(a4)
		move.b	#$05,DMAC_MFC(a4)
		move.b	#$00,DMAC_CSR(a4)	; Clear status
		move.b	#$88,DMAC_CCR(a4)	; Start!
@@:
		move.w	niv_occur(pc),d0
		beq	@b		; Wait until either niv/eiv occur

		movem.l	(sp)+,a0
		moveq.l	#0,d0
		move.b	eiv_occur,d0
		rts

; 初期化
init:
		movem.l	a0,-(sp)
		movea.l	#DMAC_ch2,a4

		moveq.l	#$68,d1			; NIV 設定
		move.b	d1,DMAC_NIV(a4)
		lea.l	niv_handler(pc),a1
		IOCS	_B_INTVCS
		move.l	d0,niv_backup

		moveq.l	#$69,d1			; EIV 設定
		move.b	d1,DMAC_EIV(a4)
		lea.l	eiv_handler(pc),a1
		IOCS	_B_INTVCS
		move.l	d0,eiv_backup

		move.b	#$08,DMAC_DCR(a4)	; DCR=16bit
		move.b	#$05,DMAC_SCR(a4)	; S++,D++
		movem.l	(sp)+,a0
		rts

niv_handler:
		move.b	#$10,DMAC_CCR(a4)	; Stop
		move.b	#$ff,DMAC_CSR(a4)
		st	niv_occur
		rte

eiv_handler:
		move.b	#$10,DMAC_CCR(a4)	; Stop
		move.b	#$ff,DMAC_CSR(a4)
		st	eiv_occur
		rte


; 引数のアドレスを addr に返す。
; a2 は引数の先頭 (先頭1バイトが長さ)。先頭の余分な空白はない。
check_arg:
		move.b	(a2)+,d1		; arglen
		beq	usage
		movea.l	a2,a0
		.dc.w	$fe12			; __STOH
		bcs	usage
		move.l	d0,addr
		rts

usage:
		PRINT	msg_usage(pc)
		DOS	_EXIT


msg_usage:
		.dc.b	"usage: <address>",$d,$a
		.dc.b	"  Access an <address> with FC=1,2,5,6."
msg_crlf:
		.dc.b	$d,$a,0

		.even
buf:
		.ds.l	2
addr:
		.ds.l	1
niv_backup:
		.ds.l	1
eiv_backup:
		.ds.l	1
		.even
niv_occur:
		.ds.b	1
eiv_occur:
		.ds.b	1
addrbuf:
		.ds.b	10

		.end
; vi:set ts=8:

unix.superglobalmegacorp.com

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