;========================================================================================
;  crtmodtest.s
;  Copyright (C) 2003-2025 Makoto Kamada
;
;  This file is part of the XEiJ (X68000 Emulator in Java).
;  You can use, modify and redistribute the XEiJ if the conditions are met.
;  Read the XEiJ License for more details.
;  https://stdkmd.net/xeij/
;========================================================================================

;----------------------------------------------------------------
;
;	crtmodtest.x
;		IOCS _CRTMOD偺幚憰偲儌僯僞偺惈擻傪妋擣偡傞偨傔偺夋柺傪昞帵偟傑偡丅
;		IPLROM 1.6/crtmod16.x偱奼挘偝傟偨夋柺儌乕僪偵懳墳偟偰偄傑偡丅
;
;	嵟廔峏怴
;		2025-04-13
;
;	嶌傝曽
;		has060 -i include -o crtmodtest.o -w crtmodtest.s
;		lk -o crtmodtest.x crtmodtest.o
;
;	巊偄曽
;		-l CRTorLCD儌乕僪
;			CRTorLCD儌乕僪傪巜掕偟傑偡丅
;			0傪巜掕偡傞偲CRT岦偗偺摨婜廃攇悢偵丄1傪巜掕偡傞偲LCD岦偗偺摨婜廃攇悢偵側傝傑偡丅
;			-l傪巜掕偟偰-s傪巜掕偟側偐偭偨偲偒偼CRTorLCD儌乕僪傪尦偵栠偟偰廔椆偟傑偡丅
;			-l傪巜掕偟偰-s傕巜掕偟偨偲偒偼CRTorLCD儌乕僪傪曄峏偟偨傑傑廔椆偟傑偡丅
;			-l傪巜掕偟側偐偭偨偲偒偼尰嵼偺CRTorLCD儌乕僪傪梡偄傑偡丅
;			-l傪巜掕偟側偐偭偨偲偒偼-s偼巜掕偱偒傑偣傫丅
;		-m 夋柺儌乕僪
;			夋柺儌乕僪傪0乣47偺斖埻偱巜掕偟傑偡丅
;			夋柺儌乕僪偺堦棗偼巊梡朄偵彂偄偰偁傝傑偡丅
;		-s
;			-l偱巜掕偝傟偨CRTorLCD儌乕僪傪SRAM偵曐懚偟傑偡丅
;		夋柺傪昞帵偟偰僉乕擖椡懸偪偵側傝傑偡丅
;		壗偐僉乕傪墴偡偲夋柺儌乕僪傪尦偵栠偟偰廔椆偟傑偡丅
;		ESC僉乕偑墴偝傟偨偲偒偼夋柺儌乕僪傪曄峏偟偨傑傑廔椆偟傑偡丅
;
;	峏怴棜楌
;		2022-02-21
;			岞奐丅
;		2023-01-10
;			挿偄僿儖僾儊僢僙乕僕傪儁乕僕枅偵嬫愗偭偰昞帵偡傞傛偆偵偟傑偟偨丅
;		2023-11-14
;			-l傪巜掕偟偨偲偒CRTorLCD儌乕僪傪曄峏偟偨傑傑廔椆偟偰偄傑偟偨偑丄尦偵栠偟偰廔椆偡傞傛偆偵偟傑偟偨丅
;			-s傪捛壛偟傑偟偨丅-s傪巜掕偡傞偲-l偱巜掕偝傟偨CRTorLCD儌乕僪偵曄峏偟偨傑傑廔椆偟傑偡丅
;		2024-08-25
;			夋柺儌乕僪40乣47偵懳墳偟傑偟偨丅
;		2024-08-26
;			IPLROM 1.0乣1.3偺IOCS _SP_INIT偺僶僌傪摜傑側偄傛偆偵偟傑偟偨丅
;			ESC僉乕偱廔椆偟偨偲偒丄僗僾儔僀僩偲僌儔僼傿僢僋傪旕昞帵偵丄僥僉僗僩傪徚嫀丄僥僉僗僩僷儗僢僩傪暅尦偟傑偡丅
;			僐乕僪傪惍棟偟傑偟偨丅
;		2025-04-01
;			IPLROM 1.6/CRTMOD16.X埲奜偺娐嫬偱摦偐偡偲夋柺偑棎傟傞栤戣傪廋惓偟傑偟偨丅
;		2025-04-13
;			stou傪廋惓偟傑偟偨丅
;
;----------------------------------------------------------------

	.include	bioswork.equ
	.include	control2.mac
	.include	crtc.equ
	.include	doscall.mac
	.include	iocscall.mac
	.include	misc.mac
	.include	push2.mac
	.include	sprc.equ

TITLE_STRING	reg	'crtmodtest.x for IPLROM 1.6/crtmod16.x (2025-04-13)'

MAX_SCREEN_MODE	equ	47		;夋柺儌乕僪偺嵟戝抣

TEXT_LINE	equ	3
GRAPHIC_LINE	equ	4		;4,5,6,7
SPRITE_LINE	equ	8
BG_LINE		equ	9		;9,10

	.text

base:
	lea.l	base(pc),a6
r	reg	-base(a6)

;僆僾僔儑儞傪妋擣偡傞
	moveq.l	#-1,d6			;CRTorLCD儌乕僪偼巜掕偝傟偰偄側偄
	moveq.l	#-1,d7			;夋柺儌乕僪偼巜掕偝傟偰偄側偄
	sf.b	(save_to_sram)r		;CRTorLCD儌乕僪傪SRAM偵曐懚偟側偄
	lea.l	1(a2),a0
	dostart
		gotoand	<cmp.b #'-',d0>,ne,<cmp.b #'/',d0>,ne,usage_exit	;-,/埲奜
		addq.l	#1,a0
		move.b	(a0)+,d0
		goto	eq,usage_exit		;-,/偺屻偵暥帤偑側偄
		bsr	tolower
		if	<cmp.b #'l',d0>,eq	;-l
			goto	<tst.l d6>,pl,usage_exit	;CRTorLCD儌乕僪偼婛偵巜掕偝傟偰偄傞
			bsr	nextword
			bsr	stou
			gotoor	<>,cs,<cmp.l #1,d0>,hi,usage_exit	;10恑悢偑側偄偐斖埻奜
			move.l	d0,d6			;CRTorLCD儌乕僪偑巜掕偝傟偨
		elif	<cmp.b #'m',d0>,eq	;-m
			goto	<tst.l d7>,pl,usage_exit	;夋柺儌乕僪偼婛偵巜掕偝傟偰偄傞
			bsr	nextword
			bsr	stou
			gotoor	<>,cs,<cmp.l #MAX_SCREEN_MODE,d0>,hi,usage_exit	;10恑悢偑側偄偐斖埻奜
			move.l	d0,d7			;夋柺儌乕僪偑巜掕偝傟偨
		elif	<cmp.b #'s',d0>,eq	;-s
			st.b	(save_to_sram)r		;CRTorLCD儌乕僪傪SRAM偵曐懚偡傞
		else				;-l,-m,-s埲奜
			goto	usage_exit
		endif
	start
		bsr	nextword
	while	ne
	goto	<tst.l d7>,mi,usage_exit	;夋柺儌乕僪偑巜掕偝傟偰偄側偄
	gotoand	<tst.l d6>,mi,<tst.b (save_to_sram)r>,ne,usage_exit	;CRTorLCD儌乕僪偑巜掕偝傟偰偄側偄偺偱SRAM偵曐懚偱偒側偄
;<d6.l:CRTorLCD儌乕僪丅0=CRT岦偗,1=LCD岦偗,-1=巜掕偝傟偰偄側偄
;<d7.l:夋柺儌乕僪

;僗乕僷乕僶僀僓儌乕僪傊堏峴偡傞
	supervisormode

;CRTorLCD儌乕僪傪曐懚偡傞
	move.w	#$16FF,d1
	IOCS	_CRTMOD
	rol.l	#8,d0
	cmp.b	#$96,d0
	seq.b	(saved_crtlcd)r

;CRTorLCD儌乕僪傪曄峏偡傞
	if	<tst.l d6>,pl		;CRTorLCD儌乕僪偑巜掕偝傟偰偄傞
		if	eq			;CRT岦偗
			move.w	#$43FF,d1
		else				;LCD岦偗
			move.w	#$4CFF,d1
		endif
		IOCS	_CRTMOD			;CRTorLCD儌乕僪傪曄峏偡傞
	endif

;夋柺儌乕僪傪愝掕偡傞
	move.l	d7,d1			;夋柺儌乕僪
	IOCS	_CRTMOD
	IOCS	_G_CLR_ON

;忣曬傪廤傔傞
;夋柺儌乕僪
	moveq.l	#0,d0
	move.b	BIOS_CRTMOD.w,(screen_mode)r
;CRTorLCD儌乕僪
	move.w	#$16FF,d1
	IOCS	_CRTMOD
	rol.l	#8,d0
	cmp.b	#$96,d0
	seq.b	(crtlcd_mode)r
;僌儔僼傿僢僋儁乕僕悢
	move.b	BIOS_GRAPHIC_PAGES.w,d0
	move.b	d0,(pages)r
;BG僒僀僘
	move.w	SPRC_RESOLUTION,d0
	btst.l	#0,d0
	sne.b	(bg_size)r
;僗僾儔僀僩夋柺偺桳柍
	moveq.l	#%10010,d0
	and.w	CRTC_MODE_RESOLUTION,d0
	cmp.w	#%10010,d0
	sne.b	(sprite_exists)r
;夋柺偺暆
	move.w	BIOS_GRAPHIC_RIGHT.w,d0
	addq.w	#1,d0
	move.w	BIOS_CONSOLE_RIGHT.w,d1
	addq.w	#1,d1
	lsl.w	#3,d1
	if	<cmp.w d1,d0>,lo
		move.w	d1,d0
	endif
	move.w	d0,(screen_width)r
;夋柺偺崅偝
	moveq.l	#0,d0
	move.w	BIOS_GRAPHIC_BOTTOM.w,d0
	addq.l	#1,d0
	moveq.l	#0,d1
	move.w	BIOS_CONSOLE_BOTTOM.w,d1
	addq.w	#1,d1
	lsl.w	#4,d1
	if	<cmp.l d1,d0>,lo
		move.l	d1,d0
	endif
	move.w	d0,(screen_height)r
;僗僾儔僀僩夋柺偺崅偝
	move.w	(screen_height)r,(sprite_height)r
	ifand	<cmpi.b #44,(screen_mode)r>,hs,<cmpi.b #MAX_SCREEN_MODE,(screen_mode)r>,ls
		lsl.w	(sprite_height)r	;夋柺儌乕僪44乣47偼僗僾儔僀僩夋柺偺崅偝傪2攞偵偡傞
	endif
;幚夋柺僒僀僘
	move.l	BIOS_GRAPHIC_Y_OFFSET.w,d0
	lsr.l	#1,d0
	move.w	d0,(real_size)r
;僌儔僼傿僢僋怓悢
	moveq.l	#0,d0
	move.w	BIOS_GRAPHIC_PALETS.w,d0
	addq.l	#1,d0
	move.l	d0,(palets)r

;儐乕僓儌乕僪傊暅婣偡傞
	usermode

;僥僉僗僩夋柺傪昤偔
;僷儗僢僩傪愝掕偡傞
	moveq.l	#3,d1			;僷儗僢僩僐乕僪
	move.w	(text_color)r,d2	;僇儔乕僐乕僪
	IOCS	_TPALET
;夋柺儌乕僪傪昞帵偡傞
	lea.l	(string_buffer)r,a0
	movestr	'CRTMOD(',a1
	bsr	strcpy
	moveq.l	#0,d0
	move.b	(screen_mode)r,d0
	bsr	utos
	if	<tst.b (crtlcd_mode)r>,eq
		movestr	') CRT',a1
	else
		movestr	') LCD',a1
	endif
	bsr	strcpy
	moveq.l	#3,d1			;僷儗僢僩僐乕僪
	moveq.l	#2,d2			;X嵗昗
	moveq.l	#TEXT_LINE-2,d3		;Y嵗昗
	lea.l	(string_buffer)r,a1	;暥帤楍
	move.l	a0,d4
	sub.l	a1,d4
	subq.w	#1,d4			;寘悢-1
	IOCS	_B_PUTMES
;夋柺僒僀僘傪昞帵偡傞
	lea.l	(string_buffer)r,a0
	moveq.l	#0,d0
	move.w	(screen_width)r,d0
	bsr	utos
	move.b	#'x',(a0)+
	moveq.l	#0,d0
	move.w	(screen_height)r,d0
	bsr	utos
	move.b	#'/',(a0)+
	moveq.l	#0,d0
	move.w	(real_size)r,d0
	bsr	utos
	move.b	#'x',(a0)+
	moveq.l	#0,d0
	move.w	(real_size)r,d0
	bsr	utos
	move.b	#' ',(a0)+
	move.l	(palets)r,d0
	bsr	utos
	move.b	#' ',(a0)+
	moveq.l	#0,d0
	move.b	(pages)r,d0
	bsr	utos
	moveq.l	#3,d1			;僷儗僢僩僐乕僪
	moveq.l	#2,d2			;X嵗昗
	moveq.l	#TEXT_LINE-1,d3		;Y嵗昗
	lea.l	(string_buffer)r,a1	;暥帤楍
	move.l	a0,d4
	sub.l	a1,d4
	subq.w	#1,d4			;寘悢-1
	IOCS	_B_PUTMES
;TEXT偲彂偔
	moveq.l	#3,d1			;僷儗僢僩僐乕僪
	moveq.l	#2,d2			;X嵗昗
	moveq.l	#TEXT_LINE,d3		;Y嵗昗
	moveq.l	#8-1,d4			;寘悢-1
	movestr	'俿俤倃俿',a1		;暥帤楍
	IOCS	_B_PUTMES

;僌儔僼傿僢僋夋柺傪昤偔
;僷儗僢僩傪愝掕偡傞
	if	<cmp.l #65536,(palets)r>,lo
		moveq.l	#0,d1			;僷儗僢僩僐乕僪0
		moveq.l	#0,d2			;僇儔乕僐乕僪
		IOCS	_GPALET
		lea.l	(graphic_color)r,a0
		moveq.l	#1,d3
		do
			move.w	d3,d1			;僷儗僢僩僐乕僪1乣4
			move.w	(a0)+,d2		;僇儔乕僐乕僪
			IOCS	_GPALET
			addq.w	#1,d3
		while	<cmp.w #4,d3>,ls
	endif
;榞傪昤偔
	move.w	#$F0F0,-(sp)		;儔僀儞僗僞僀儖
	moveq.l	#1,d0
	if	<cmp.l #65536,(palets)r>,eq
		move.w	(graphic_color)r,d0
	endif
	move.w	d0,-(sp)		;僷儗僢僩僐乕僪
	move.w	(screen_height)r,d0
	subq.w	#1,d0
	move.w	d0,-(sp)		;廔揰Y嵗昗
	move.w	(screen_width)r,d0
	subq.w	#1,d0
	move.w	d0,-(sp)		;廔揰X嵗昗
	clr.w	-(sp)			;巒揰Y嵗昗
	clr.w	-(sp)			;巒揰X嵗昗
	moveq.l	#2-1,d1			;奜懁,撪懁
	for	d1
		movea.l	sp,a1
		IOCS	_BOX
		addq.w	#4,(sp)			;巒揰X嵗昗
		addq.w	#4,2(sp)		;巒揰Y嵗昗
		subq.w	#4,4(sp)		;廔揰X嵗昗
		subq.w	#4,6(sp)		;廔揰Y嵗昗
	next
	lea.l	12(sp),sp
;GRAPHIC PAGE 0/1/2/3偲彂偔
	moveq.l	#0,d5			;儁乕僕斣崋 0,1,2,3
	do
	;暥帤楍傪嶌傞
		lea.l	(string_buffer)r,a0
		movestr	'俧俼俙俹俫俬俠丂俹俙俧俤丂',a1
		bsr	strcpy
		move.w	#'侽',d0
		add.w	d5,d0
		rol.w	#8,d0
		move.b	d0,(a0)+
		rol.w	#8,d0
		move.b	d0,(a0)+
		clr.b	d0
	;儁乕僕傪慖戰偡傞
		move.l	d5,d1
		IOCS	_APAGE
	;昤偔
		move.w	#1<<8|0,-(sp)		;僒僀僘:妏搙
		moveq.l	#1,d0
		add.w	d5,d0
		if	<cmp.l #65536,(palets)r>,eq
			move.w	d5,d0
			lea.l	(graphic_color)r,a0
			add.w	d0,d0
			move.w	(a0,d0.w),d0
		endif
		move.w	d0,-(sp)		;僷儗僢僩僐乕僪
		move.w	#1<<8|1,-(sp)		;X曽岦偺攞棪:Y曽岦偺攞棪
		pea.l	(string_buffer)r	;暥帤楍
		moveq.l	#GRAPHIC_LINE,d0
		add.w	d5,d0
		lsl.w	#4,d0
		move.w	d0,-(sp)		;Y嵗昗
		move.w	#8*2,-(sp)		;X嵗昗
		movea.l	sp,a1
		IOCS	_SYMBOL
		lea.l	14(sp),sp
		addq.w	#1,d5
	while	<cmp.b (pages)r,d5>,lo

;僗僾儔僀僩夋柺傪昤偔
	if	<tst.b (sprite_exists)r>,ne	;僗僾儔僀僩夋柺偁傝
	;弶婜壔偡傞
		IOCS	_SP_INIT
		IOCS	_SP_ON
	;僷儗僢僩傪愝掕偡傞
		lea.l	(sprite_color)r,a0
		moveq.l	#1,d4			;僷儗僢僩僽儘僢僋 1,2,3
		do
			moveq.l	#0,d1			;僷儗僢僩僐乕僪
			move.l	d4,d2			;僷儗僢僩僽儘僢僋
			moveq.l	#0,d3			;僇儔乕僐乕僪
			IOCS	_SPALET
			moveq.l	#1,d1			;僷儗僢僩僐乕僪
			move.l	d4,d2			;僷儗僢僩僽儘僢僋
			move.w	(a0)+,d3		;僇儔乕僐乕僪
			IOCS	_SPALET
			addq.w	#1,d4
		while	<cmp.w #3,d4>,ls
	;恾宍僷僞乕儞傪掕媊偡傞
		moveq.l	#2,d1			;僷僞乕儞斣崋 2
		moveq.l	#1,d2			;僒僀僘 16x16
		lea.l	(sprite_pattern)r,a1	;僗僾儔僀僩僷僞乕儞
		IOCS	_SP_DEFCG		;僷僞乕儞傪掕媊偡傞
	;暥帤僷僞乕儞傪掕媊偡傞
	;		  3 4 5 6 7 8 910111213141516171819202122
		movestr	'俽俹俼俬俿俤俛俙俠俲亅俧俼俷倀俶俢丂侽侾',a4
		moveq.l	#3,d6			;僷僞乕儞斣崋
		dostart
			lsl.w	#8,d1
			move.b	(a4)+,d1		;暥帤僐乕僪壓埵
			moveq.l	#8,d2			;僒僀僘 16x16
			lea.l	(font_buffer)r,a1	;僼僅儞僩僶僢僼傽
			IOCS	_FNTGET			;僼僅儞僩僨乕僞傪庢傝弌偡
			lea.l	(pattern_buffer)r,a0	;僷僞乕儞僶僢僼傽
			moveq.l	#0,d7			;0屌掕
			moveq.l	#-2,d5			;-2=嵍敿暘,-1=塃敿暘
			do
				lea.l	(font_buffer+4)r,a1	;僼僅儞僩僨乕僞偺杮懱
				moveq.l	#16-1,d3		;廲16僪僢僩
				for	d3
				;	moveq.l	#0,d0
					move.b	2(a1,d5.w),d1		;嵍敿暘傑偨偼塃敿暘
					moveq.l	#8-1,d2			;墶8僪僢僩
					for	d2
						lsl.l	#4,d0			;0傪0000偵丄1傪0001偵偡傞
						add.b	d1,d1			;d1.b偺忋埵偐傜墴偟弌偟偰
						addx.b	d7,d0			;d0.l偺壓埵傊墴偟崬傓
					next
					move.l	d0,(a0)+		;僷僞乕儞僨乕僞
					addq.l	#2,a1
				next
				addq.w	#1,d5
			while	ne
			move.w	d6,d1			;僷僞乕儞斣崋
			moveq.l	#1,d2			;僒僀僘 16x16
			lea.l	(pattern_buffer)r,a1	;僷僞乕儞僨乕僞
			IOCS	_SP_DEFCG		;僷僞乕儞傪掕媊偡傞
			addq.w	#1,d6			;師偺僷僞乕儞斣崋
		start
			moveq.l	#0,d1
			move.b	(a4)+,d1		;暥帤僐乕僪忋埵
		while	ne
	;巐嬿偺僗僾儔僀僩傪昞帵偡傞
		moveq.l	#0,d6			;埵抲=僗僾儔僀僩斣崋 0=嵍忋,1=塃忋,2=嵍壓,3=塃壓
		do
			move.l	d6,d1			;僗僾儔僀僩斣崋 0,1,2,3
			moveq.l	#16,d2			;X嵗昗嵍抂
			if	<btst.l #0,d6>,ne
				move.w	(screen_width)r,d2	;X嵗昗塃抂
			endif
			moveq.l	#16,d3			;Y嵗昗忋抂
			if	<btst.l #1,d6>,ne
				move.w	(sprite_height)r,d3	;Y嵗昗壓抂
			endif
			move.w	#1<<8|2,d4		;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋 1:2
			moveq.l	#3,d5			;僾儔僀僆儕僥傿 3
			IOCS	_SP_REGST
			addq.w	#1,d6			;師偺埵抲=僗僾儔僀僩斣崋
		while	<cmp.w #3,d6>,ls
	;SPRITE偲彂偔
		moveq.l	#16+16*1,d2
		movea.l	d2,a2			;X嵗昗
		moveq.l	#SPRITE_LINE,d3
		move.w	(screen_height)r,d0
		if	<cmp.w (sprite_height)r,d0>,ne
			add.w	d3,d3
		endif
		lsl.w	#4,d3
		add.w	#16,d3
		movea.l	d3,a3			;Y嵗昗
	;		 S P R I T E
		movestr	<3,4,5,6,7,8>,a4	;僷僞乕儞斣崋
		moveq.l	#4,d7			;僗僾儔僀僩斣崋
		dostart
			move.l	d7,d1			;僗僾儔僀僩斣崋
			move.w	a2,d2			;X嵗昗
			move.w	a3,d3			;Y嵗昗
			move.w	#1<<8,d4
			move.b	d0,d4			;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋
			moveq.l	#3,d5			;僾儔僀僆儕僥傿 3
			IOCS	_SP_REGST
			addq.w	#1,d7			;師偺僗僾儔僀僩斣崋
			adda.w	#16,a2			;師偺X嵗昗
		start
			moveq.l	#0,d0
			move.b	(a4)+,d0		;僷僞乕儞斣崋
		while	ne
	;BG傪昤偔
		if	<tst.b (bg_size)r>,eq	;8x8/512x512x2
			moveq.l	#0,d5			;BG僥僉僗僩僄儕傾 0,1
			do
			;榞偺僷僞乕儞傪掕媊偡傞
				move.l	d5,d1
				addq.w	#2,d1			;僷僞乕儞斣崋 2,3
				moveq.l	#0,d2			;僒僀僘 8x8
				lea.l	(bg_pattern_8x8)r,a1
				move.l	d5,d0
				lsl.w	#5,d0
				adda.l	d0,a1			;僷僞乕儞僨乕僞
				IOCS	_SP_DEFCG
			;榞偺僷僞乕儞偱揾傝捵偡
				move.l	d5,d1			;BG僥僉僗僩僄儕傾 0,1
				move.l	d5,d2
				addq.w	#2,d2			;僷僞乕儞斣崋=僷儗僢僩僽儘僢僋 2,3
				move.b	d2,d0
				lsl.w	#8,d2
				move.b	d0,d2			;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋 2:2,3:3
				IOCS	_BGTEXTCL
			;榞傪巆偟偰撪懁傪偔傝敳偔
				move.l	d5,d1			;BG僥僉僗僩僄儕傾 0,1
				moveq.l	#0<<8|0,d4		;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋 0:0
				moveq.l	#1,d3			;BG僥僉僗僩Y嵗昗丅榞偺1屄
				move.w	(sprite_height)r,d7
				lsr.w	#3,d7			;8x8偑廲偵暲傇悢
				subq.w	#2+1,d7			;榞偺2屄
				for	d7			;廲
					moveq.l	#1,d2			;BG僥僉僗僩X嵗昗丅榞偺1屄
					move.w	(screen_width)r,d6
					lsr.w	#3,d6			;8x8偑墶偵暲傇悢
					subq.w	#2+1,d6			;榞偺2屄
					for	d6			;墶
						IOCS	_BGTEXTST
						addq.w	#1,d2			;師偺BG僥僉僗僩X嵗昗
					next
					addq.w	#1,d3			;師偺BG僥僉僗僩Y嵗昗
				next
			;BACK-GROUND 0/1偲彂偔
				moveq.l	#2*1,d2
				movea.l	d2,a2			;X嵗昗
				moveq.l	#BG_LINE,d3
				add.w	d5,d3
				move.w	(screen_height)r,d0
				if	<cmp.w (sprite_height)r,d0>,ne
					add.w	d3,d3
				endif
				add.w	d3,d3
				movea.l	d3,a3			;Y嵗昗
			;		 B  A  C  K  -  G  R  O  U  N  D     0
				movestr	<9,10,11,12,13,14,15,16,17,18,19,20,21>,a4	;僷僞乕儞斣崋
				dostart
					move.l	d5,d4
					addq.b	#2,d4			;僷儗僢僩僽儘僢僋 2,3
					lsl.w	#8,d4
					if	<cmp.b #21,d0>,eq	;0/1
						add.b	d5,d0			;21(0)仺22(1)
					endif
					move.b	d0,d4			;僷儗僢僩僽儘僢僋:16x16僷僞乕儞斣崋
					lsl.b	#2,d4			;僷儗僢僩僽儘僢僋:8x8僷僞乕儞斣崋
					moveq.l	#4-1,d6			;嵍忋,嵍壓,塃忋,塃壓
					for	d6
						move.l	d5,d1			;BG僥僉僗僩僄儕傾 0,1
						moveq.l	#2,d2
						and.b	d4,d2
						lsr.w	#1,d2
						add.w	a2,d2			;BG僥僉僗僩X嵗昗
						moveq.l	#1,d3
						and.b	d4,d3
						add.w	a3,d3			;BG僥僉僗僩Y嵗昗
						IOCS	_BGTEXTST
						addq.b	#1,d4			;師偺8x8僷僞乕儞斣崋
					next
					addq.w	#2,a2			;BG僥僉僗僩X嵗昗
				start
					moveq.l	#0,d0
					move.b	(a4)+,d0		;僷僞乕儞斣崋
				while	ne
			;昞帵ON
				move.l	d5,d1			;BG儁乕僕 0,1
				move.l	d5,d2			;BG僥僉僗僩僄儕傾 0,1
				moveq.l	#1,d3			;昞帵ON
				IOCS	_BGCTRLST
			;
				addq.w	#1,d5			;師偺BG僥僉僗僩僄儕傾
			while	<cmp.w #1,d5>,ls
		else				;16x16/1024x1024x1
		;榞偺僷僞乕儞傪掕媊偡傞
			moveq.l	#1,d1			;僷僞乕儞斣崋 1
			moveq.l	#1,d2			;僒僀僘 16x16
			lea.l	(bg_pattern_16x16)r,a1	;僷僞乕儞僨乕僞
			IOCS	_SP_DEFCG
		;榞偺僷僞乕儞偱揾傝捵偡
			moveq.l	#0,d1			;BG僥僉僗僩僄儕傾 0
			move.w	#2<<8|1,d2		;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋 2:1
			IOCS	_BGTEXTCL
		;榞傪巆偟偰撪懁傪偔傝敳偔
			moveq.l	#0,d1			;BG僥僉僗僩僄儕傾 0
			move.w	#0<<8|0,d4		;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋 0:0
			moveq.l	#1,d3			;BG僥僉僗僩Y嵗昗丅榞偺1屄
			move.w	(sprite_height)r,d7
			lsr.w	#4,d7			;16x16偑廲偵暲傇悢
			subq.w	#2+1,d7			;榞偺2屄
			for	d7			;廲
				moveq.l	#1,d2			;BG僥僉僗僩X嵗昗丅榞偺1屄
				move.w	(screen_width)r,d6
				lsr.w	#4,d6			;16x16偑墶偵暲傇悢
				subq.w	#2+1,d6			;榞偺2屄
				for	d6			;墶
					IOCS	_BGTEXTST
					addq.w	#1,d2			;師偺BG僥僉僗僩X嵗昗
				next
				addq.w	#1,d3			;師偺BG僥僉僗僩Y嵗昗
			next
		;BACK-GROUND 0偲彂偔
			moveq.l	#1*1,d2
			move.l	d2,a2			;X嵗昗
			moveq.l	#BG_LINE,d3
			move.w	(screen_height)r,d0
			if	<cmp.w (sprite_height)r,d0>,ne
				add.w	d3,d3
			endif
			movea.l	d3,a3			;Y嵗昗
		;		 B  A  C  K  -  G  R  O  U  N  D     0
			movestr	<9,10,11,12,13,14,15,16,17,18,19,20,21>,a4	;僷僞乕儞斣崋
			dostart
				move.w	#2<<8,d4
				move.b	d0,d4			;僷儗僢僩僽儘僢僋:僷僞乕儞斣崋
				moveq.l	#0,d1			;BG僥僉僗僩僄儕傾 0
				move.w	a2,d2			;BG僥僉僗僩X嵗昗
				move.w	a3,d3			;BG僥僉僗僩Y嵗昗
				IOCS	_BGTEXTST
				addq.w	#1,a2			;BG僥僉僗僩X嵗昗
			start
				moveq.l	#0,d0
				move.b	(a4)+,d0		;僷僞乕儞斣崋
			while	ne
		;昞帵ON
			moveq.l	#0,d1			;BG儁乕僕 0
			moveq.l	#0,d2			;BG僥僉僗僩僄儕傾 0
			moveq.l	#1,d3			;昞帵ON
			IOCS	_BGCTRLST
		endif
	endif

;僉乕擖椡傪懸偭偰偐傜夋柺儌乕僪傪暅尦偡傞
	IOCS	_B_CUROFF
	DOS	_GETC
	if	<cmp.b #27,d0>,eq	;ESC僉乕偑墴偝傟偨偲偒
	;僗僾儔僀僩夋柺偲僌儔僼傿僢僋夋柺傪OFF偵偡傞
		moveq.l	#$0020,d1
		IOCS	_CRTMOD2
	;僥僉僗僩夋柺傪徚嫀偡傞
		moveq.l	#2,d1
		IOCS	_B_CLR_ST
	;僥僉僗僩僷儗僢僩傪暅尦偡傞
		moveq.l	#3,d1
		moveq.l	#-2,d2
		IOCS	_TPALET
	else				;ESC僉乕埲奜偑墴偝傟偨偲偒
	;CRTorLCD儌乕僪傪暅尦偡傞
		if	<tst.b (save_to_sram)r>,eq	;CRTorLCD儌乕僪傪SRAM偵曐懚偟側偄
			if	<tst.b (saved_crtlcd)r>,eq	;CRT岦偗偩偭偨
				move.w	#$43FF,d1
			else				;LCD岦偗偩偭偨
				move.w	#$4CFF,d1
			endif
			IOCS	_CRTMOD			;CRTorLCD儌乕僪傪暅尦偡傞
		endif
	;OS偺夋柺儌乕僪傪暅尦偡傞
		move.l	#(16<<16)|$FFFF,-(sp)
		DOS	_CONCTRL
		move.w	d0,2(sp)
		DOS	_CONCTRL
		addq.l	#4,sp
	endif
	IOCS	_B_CURON

;廔椆偡傞
exit:
	DOS	_EXIT

;僞僀僩儖偲巊梡朄傪昞帵偟偰廔椆偡傞
usage_exit:
	lea.l	title_usage(pc),a0
	bsr	more
	goto	exit

;僞僀僩儖偲巊梡朄
title_usage:
	.dc.b	TITLE_STRING,13,10
	.dc.b	'僆僾僔儑儞',13,10
	.dc.b	'  -l 0-1   CRTorLCD儌乕僪丅0=CRT岦偗,1=LCD岦偗',13,10
	.dc.b	'  -m 0-47  夋柺儌乕僪',13,10
	.dc.b	'  -s       -l偱巜掕偟偨CRTorLCD儌乕僪傪SRAM偵曐懚偡傞',13,10
	.dc.b	'  劇劅劅劅劍劅劅劅劅劅劅劅劅劅劅劅劍劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉',13,10
	.dc.b	'  劆CRTMOD劆幚夋柺僒僀僘 怓 儁乕僕劆        悈暯摨婜  悅捈摨婜  夋柺僒僀僘      旛峫      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆   0  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆   4  劆  512x512      16  4  劆  CRT  31.500kHz  55.458Hz   512x512                  劆',13,10
	.dc.b	'  劆   8  劆  512x512     256  2  劆  LCD  35.341kHz  56.546Hz   512x512                  劆',13,10
	.dc.b	'  劆  12  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆   1  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆   5  劆  512x512      16  4  劆  CRT  15.980kHz  61.463Hz   512x480   僀儞僞乕儗乕僗 劆',13,10
	.dc.b	'  劆   9  劆  512x512     256  2  劆  LCD  35.341kHz  56.546Hz   512x480                  劆',13,10
	.dc.b	'  劆  13  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆   2  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆   6  劆  512x512      16  4  劆  CRT  31.500kHz  55.458Hz   256x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  10  劆  512x512     256  2  劆  LCD  34.500kHz  55.200Hz   256x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  14  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆   3  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆   7  劆  512x512      16  4  劆  CRT  15.980kHz  61.463Hz   256x240                  劆',13,10
	.dc.b	'  劆  11  劆  512x512     256  2  劆  LCD  34.500kHz  55.200Hz   256x240   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  15  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  16  劆 1024x1024     16  1  劆  CRT  31.500kHz  55.458Hz   768x512                  劆',13,10
	.dc.b	'  劆  20  劆  512x512     256  2  劆  LCD  35.056kHz  56.090Hz   768x512                  劆',13,10
	.dc.b	'  劆  24  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  17  劆 1024x1024     16  1  劆  CRT  24.699kHz  53.116Hz  1024x424                  劆',13,10
	.dc.b	'  劆  21  劆  512x512     256  2  劆  LCD  35.056kHz  56.090Hz   768x600                  劆',13,10
	.dc.b	'  劆  25  劆  512x512   65536  1  劆                               曄宍                   劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  18  劆 1024x1024     16  1  劆  CRT  24.699kHz  53.116Hz  1024x848   僀儞僞乕儗乕僗 劆',13,10
	.dc.b	'  劆  22  劆  512x512     256  2  劆  LCD  35.056kHz  56.090Hz   768x1024  僀儞僞乕儗乕僗 劆',13,10
	.dc.b	'  劆  26  劆  512x512   65536  1  劆                               曄宍                   劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  19  劆 1024x1024     16  1  劆  CRT  31.500kHz  55.458Hz   640x480   VGA偱偼側偄    劆',13,10
	.dc.b	'  劆  23  劆  512x512     256  2  劆  LCD  31.469kHz  59.940Hz   640x480   VGA            劆',13,10
	.dc.b	'  劆  27  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  28  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆  29  劆  512x512      16  4  劆  CRT  31.963kHz  56.273Hz   384x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  30  劆  512x512     256  2  劆  LCD  31.963kHz  51.141Hz   384x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  31  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  32  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆  33  劆  512x512      16  4  劆  CRT  31.500kHz  55.458Hz   512x512                  劆',13,10
	.dc.b	'  劆  34  劆  512x512     256  2  劆  LCD  35.056kHz  56.090Hz   512x512                  劆',13,10
	.dc.b	'  劆  35  劆  512x512   65536  1  劆                              惓曽宍                  劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  36  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆  37  劆  512x512      16  4  劆  CRT  31.963kHz  56.273Hz   256x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  38  劆  512x512     256  2  劆  LCD  31.963kHz  51.141Hz   256x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  39  劆  512x512   65536  1  劆                              惓曽宍                  劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  40  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆  41  劆  512x512      16  4  劆  CRT  31.500kHz  55.458Hz   512x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  42  劆  512x512     256  2  劆  LCD  35.341kHz  56.546Hz   512x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  43  劆  512x512   65536  1  劆                                                      劆',13,10
	.dc.b	'  劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎',13,10
	.dc.b	'  劆  44  劆 1024x1024     16  1  劆                                                      劆',13,10
	.dc.b	'  劆  45  劆  512x512      16  4  劆  CRT  31.500kHz  55.458Hz   512x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  46  劆  512x512     256  2  劆  LCD  35.341kHz  56.546Hz   512x256   儔僗僞2搙撉傒  劆',13,10
	.dc.b	'  劆  47  劆  512x512   65536  1  劆                       僗僾儔僀僩偼512x512            劆',13,10
	.dc.b	'  劋劅劅劅劏劅劅劅劅劅劅劅劅劅劅劅劏劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊',13,10
	.dc.b	0
	.even

;怓
text_color:	dchsv	0,24,31
graphic_color:	dchsv	24,24,31
		dchsv	48,24,31
		dchsv	72,24,31
		dchsv	96,24,31
sprite_color:	dchsv	120,24,31
		dchsv	144,24,31
		dchsv	168,24,31

;BG僷僞乕儞
bg_pattern_8x8:
	.dc.l	$00110011		;BG0
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000

	.dc.l	$00000000		;BG1
	.dc.l	$00000000
	.dc.l	$11001100
	.dc.l	$11001100
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$11001100
	.dc.l	$11001100

bg_pattern_16x16:
	.dc.l	$00110011		;嵍敿暘
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000

	.dc.l	$00110011		;塃敿暘
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000
	.dc.l	$00110011
	.dc.l	$00110011
	.dc.l	$00000000
	.dc.l	$00000000

;僗僾儔僀僩僷僞乕儞
sprite_pattern:
	.dc.l	$00001111		;嵍敿暘
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000

	.dc.l	$00001111		;塃敿暘
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$00001111
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000
	.dc.l	$11110000

	.bss

save_to_sram:	.ds.b	1		;CRTorLCD儌乕僪傪SRAM偵曐懚偡傞偐丅0=偟側偄,-1=偡傞
saved_crtlcd:	.ds.b	1		;尦偺夋柺儌乕僪
screen_mode:	.ds.b	1		;夋柺儌乕僪
crtlcd_mode:	.ds.b	1		;CRTorLCD儌乕僪丅0=CRT岦偗,-1=LCD岦偗
pages:		.ds.b	1		;僌儔僼傿僢僋儁乕僕悢
bg_size:	.ds.b	1		;BG僒僀僘丅0=8x8/512x512x2,-1=16x16/1024x1024x1
sprite_exists:	.ds.b	1		;僗僾儔僀僩夋柺偺桳柍丅0=側偟,-1=偁傝
	.even
screen_width:	.ds.w	1		;夋柺偺暆
screen_height:	.ds.w	1		;夋柺偺崅偝
sprite_height:	.ds.w	1		;僗僾儔僀僩夋柺偺崅偝
real_size:	.ds.w	1		;幚夋柺僒僀僘
palets:		.ds.l	1		;僌儔僼傿僢僋怓悢
font_buffer:	.ds.w	2+2+3*24	;僼僅儞僩僶僢僼傽
pattern_buffer:	.ds.l	8*4		;僗僾儔僀僩僷僞乕儞僶僢僼傽
string_buffer:	.ds.b	256		;暥帤楍僶僢僼傽

	.text



;----------------------------------------------------------------
;-more-傪嫴傒側偑傜暥帤楍傪昞帵偡傞
;<a0.l:暥帤楍
more::
	push	d0-d5/a0-a2
;昗弨擖椡傪妋擣偡傞
	clr.l	-(sp)			;(0<<16)|0
	DOS	_IOCTRL
	addq.l	#4,sp
;<d0.b:昗弨擖椡偺FCB僼儔僌
	and.b	#$81,d0			;僉儍儔僋僞僨僶僀僗丄昗弨擖椡
	goto	<cmp.b #$81,d0>,ne,90f	;昗弨擖椡偑儕僟僀儗僋僩偝傟偰偄傞丅more偟側偄
;昗弨弌椡傪妋擣偡傞
	pea.l	1.w			;(0<<16)|1
	DOS	_IOCTRL
	addq.l	#4,sp
;<d0.b:昗弨弌椡偺FCB僼儔僌
	and.b	#$82,d0			;僉儍儔僋僞僨僶僀僗丄昗弨弌椡
	goto	<cmp.b #$82,d0>,ne,90f	;昗弨弌椡偑儕僟僀儗僋僩偝傟偰偄傞丅more偟側偄
;CONDRV.SYS傪妋擣偡傞
	move.w	#$0100+_KEY_INIT,-(sp)
	DOS	_INTVCG
	addq.l	#2,sp
	movea.l	d0,a1
	subq.l	#4,a1
	IOCS	_B_LPEEK
	goto	<cmp.l #'hmk*',d0>,eq,90f	;CONDRV.SYS偑慻傒崬傑傟偰偄傞丅more偟側偄
;夋柺偺戝偒偝傪妋擣偡傞
	moveq.l	#-1,d1
	moveq.l	#-1,d2
	IOCS	_B_CONSOL
;<d2.l:塃抂偺寘嵗昗<<16|壓抂偺峴嵗昗
	move.w	d2,d3
	swap.w	d2
	addq.w	#1,d2
;<d2.w:夋柺偺寘悢
;<d3.w:壓抂偺峴嵗昗丅-more-偺峴傪彍偄偨夋柺偺峴悢
	gotoor	<cmp.w #8,d2>,lo,<tst.w d3>,eq,90f	;夋柺偑嫹偡偓傞丅more偟側偄丅僞僽傪娷傔偰1暥帤埲忋彂偗側偗傟偽側傜側偄偺偱8寘x1峴偑壓尷
;儁乕僕儖乕僾
	do
		move.l	#0,d4			;寘嵗昗
		move.l	#0,d5			;峴嵗昗
		movea.l	a0,a2			;儁乕僕愭摢
	;暥帤儖乕僾
		do
			movea.l	a0,a1			;暥帤愭摢
			move.b	(a0)+,d0		;1僶僀僩栚
			if	eq			;00 廔椆
				subq.l	#1,a0
				break
			elif	<cmp.b #$09,d0>,eq	;09 僞僽
				moveq.l	#7,d1
				and.w	d4,d1
				subq.w	#8,d1
				neg.w	d1		;僞僽偺寘悢
			elif	<cmp.b #$0A,d0>,eq	;0A 夵峴
				moveq.l	#0,d4		;嵍抂傊
				addq.w	#1,d5		;師偺峴傊
				break	<cmp.w d3,d5>,eq	;壓抂丅儁乕僕廔傢傝
				continue
			elif	<cmp.b #$0C,d0>,eq	;0C 夵儁乕僕
				break
			elif	<cmp.b #$1F,d0>,ls	;01-08,0B,0D-1F 柍帇偡傞
				continue
			else				;20-FF
				do
					moveq.l	#1,d1			;敿妏偺寘悢
					break	<tst.b d0>,pl		;20-7F 傾僗僉乕
					breakand	<cmp.b #$A0,d0>,hs,<cmp.b #$DF,d0>,ls	;A0-DF 敿妏僇僞僇僫
					addq.l	#1,a0			;2僶僀僩栚
					break	<cmp.b #$80,d0>,eq	;8000-80FF 敿妏傂傜偑側
					break	<cmp.b #$F0,d0>,hs	;F000-FFFF 1/4妏丄敿妏奜帤
					moveq.l	#2,d1			;慡妏偺寘悢
				while	f
			endif
			add.w	d1,d4			;昞帵偟偨屻偺寘嵗昗
			if	<cmp.w d2,d4>,hi	;偼傒弌偡
				sub.w	d1,d4			;恑傒夁偓偨暘栠傞
				movea.l	a1,a0
				addq.w	#1,d5			;師偺峴傊
				break	<cmp.w d3,d5>,eq	;壓抂丅儁乕僕廔傢傝
				moveq.l	#0,d4			;嵍抂傊
			endif
		while	t
	;1儁乕僕昞帵偡傞
		move.l	a0,d0			;枛旜
		sub.l	a2,d0			;枛旜-愭摢=挿偝
		move.l	d0,-(sp)		;挿偝
		move.l	a2,-(sp)		;愭摢
		move.w	#1,-(sp)		;昗弨弌椡
		DOS	_WRITE
		lea.l	10(sp),sp
	;懕偒偑側偗傟偽廔椆偡傞
		break	<tst.b (a0)>,eq
	;昁梫側傜偽夵峴偡傞
		ifand	<tst.w d4>,ne,<cmp.w d2,d4>,ne	;嵍抂偱傕塃抂偱傕側偄
			bsr	printcrlf
		endif
	;-more-傪昞帵偡傞
		pea.l	6.w
		pea.l	100f(pc)		;'-more-'
		move.w	#1,-(sp)
		DOS	_WRITE
		lea.l	10(sp),sp
	;僉乕擖椡傪懸偮
		DOS	_GETC
		move.l	d0,d1
	;夵峴偡傞
		bsr	printcrlf
	whileand	<cmp.b #$1B,d1>,ne,<cmp.b #'Q',d1>,ne,<cmp.b #'q',d1>,ne	;ESC傑偨偼Q偑墴偝傟偨偲偒偼廔椆偡傞
99:	pop
	rts

;more偟側偄
90:	bsr	print
	goto	99b

100:	.dc.b	'-more-'
	.even

;----------------------------------------------------------------
;嬻敀傪撉傒旘偽偡
;<a0.l:暥帤楍
;>d0.l:嵟弶偺嬻敀埲奜偺暥帤傑偨偼0
;>a0.l:嵟弶偺嬻敀埲奜偺暥帤傑偨偼0偺埵抲
;>z:ne=嬻敀埲奜偺暥帤偑偁傞,eq=嬻敀埲奜偺暥帤偑側偄
nextword::
	moveq.l	#0,d0
	do
		move.b	(a0)+,d0		;師偺暥帤
		break	eq			;0側傜偽廔椆
		redo	<cmp.b #' ',d0>,eq	;' '側傜偽孞傝曉偡
	whileand	<cmp.b #9,d0>,hs,<cmp.b #13,d0>,ls	;\t\n\v\f\r側傜偽孞傝曉偡
	subq.l	#1,a0			;恑傒夁偓偨暘栠傞
	tst.l	d0
	rts

;----------------------------------------------------------------
;暥帤楍傪昞帵偡傞
;<a0.l:暥帤楍
print::
	push	d0
	bsr	strlen
	move.l	d0,-(sp)
	move.l	a0,-(sp)
	move.w	#1,-(sp)
	DOS	_WRITE
	lea.l	(10,sp),sp
	pop
	rts

;----------------------------------------------------------------
;夵峴傪昞帵偡傞
printcrlf::
	move.l	a0,-(sp)
	lea.l	100f(pc),a0		;13,10
	bsr	print
	movea.l	(sp)+,a0
	rts

100:	.dc.b	13,10,0
	.even

;----------------------------------------------------------------
;10恑悢偺暥帤楍傪晞崋側偟惍悢偵曄姺偡傞
;<a0.l:10恑悢偺暥帤楍丅愭摢偺嬻敀偼擣傔側偄
;>d0.l:(cc偺偲偒)晞崋側偟惍悢丅(cs偺偲偒)0=10恑悢偺暥帤偑側偄,-1=僆乕僶乕僼儘乕
;>a0.l:(cc偺偲偒)10恑悢偺暥帤楍偺師偺埵抲丅(cs偺偲偒)曄壔偟側偄
;>z:(cc偺偲偒)eq=晞崋側偟惍悢偑0
;>v:(cs偺偲偒)vc=10恑悢偺暥帤偑側偄,vs=僆乕僶乕僼儘乕
;>c:cs=10恑悢偺暥帤偑側偄傑偨偼僆乕僶乕僼儘乕
stou::
	push	d1-d2/a1
	moveq.l	#0,d0			;晞崋側偟惍悢
	moveq.l	#0,d1			;暥帤
	movea.l	a0,a1			;奐巒埵抲
	dostart
		goto	<cmp.l #$1999999A,d0>,hs,20f	;10攞偟偨傜僆乕僶乕僼儘乕偡傞
		move.l	d0,d2			;1攞
		lsl.l	#2,d0			;4攞
		add.l	d2,d0			;5攞
		add.l	d0,d0			;10攞偟偰
		add.l	d1,d0			;1寘壛偊傞
		goto	cs,20f			;僆乕僶乕僼儘乕偟偨
	start
		move.b	(a0)+,d1		;師偺暥帤
		sub.b	#'0',d1			;惍悢偵偡傞
	whileand	<>,hs,<cmp.b #10,d1>,lo	;10恑悢偺暥帤側傜偽孞傝曉偡
	subq.l	#1,a0			;恑傒夁偓偨暘栠傞
	goto	<cmpa.l a1,a0>,eq,30f	;恑傫偱偄側偄丅10恑悢偺暥帤偑側偄
	tst.l	d0			;ne/eq,vc,cc
10:	pop
	rts

;僆乕僶乕僼儘乕
20:
  .if 0
	do
		move.b	(a0)+,d1		;師偺暥帤
		sub.b	#'0',d1			;惍悢偵偡傞
	whileand	<>,hs,<cmp.b #10,d1>,lo	;10恑悢偺暥帤傪撉傒旘偽偡
	subq.l	#1,a0			;恑傒夁偓偨暘栠傞
  .else
	movea.l	a1,a0			;奐巒埵抲偵栠傞
  .endif
	moveq.l	#-1,d0			;僆乕僶乕僼儘乕
	move.w	#%00011,ccr		;ne,vs,cs
	goto	10b

;10恑悢偺暥帤偑側偄
30:
;	moveq.l	#0,d0			;10恑悢偺暥帤偑側偄
	move.w	#%00101,ccr		;eq,vc,cs
	goto	10b

;----------------------------------------------------------------
;暥帤楍傪僐僺乕偡傞
;<a0.l:僐僺乕愭
;<a1.l:僐僺乕尦
;>a0.l:僐僺乕愭偺0偺埵抲
;>a1.l:僐僺乕尦偺0偺師偺埵抲
strcpy::
	do
		move.b	(a1)+,(a0)+
	while	ne			;0偱側偗傟偽孞傝曉偡
	subq.l	#1,a0			;恑傒夁偓偨暘栠傞
	rts

;----------------------------------------------------------------
;暥帤楍偺挿偝傪悢偊傞
;<a0.l:暥帤楍
;>d0.l:挿偝
strlen::
	move.l	a0,d0			;d0=愭摢
	do
		tst.b (a0)+
	while	ne			;0偱側偗傟偽孞傝曉偡
	subq.l	#1,a0			;恑傒夁偓偨暘栠傞丅a0=枛旜
	exg.l	d0,a0			;d0=枛旜,a0=愭摢
	sub.l	a0,d0			;d0=枛旜-愭摢=挿偝
	rts

;----------------------------------------------------------------
;彫暥帤偵偡傞
;<d0.b:暥帤
;>d0.b:暥帤
tolower::
	ifand	<cmp.b #'A',d0>,hs,<cmp.b #'Z',d0>,ls	;戝暥帤
		add.b	#'a'-'A',d0		;彫暥帤偵偡傞
	endif
	rts

;----------------------------------------------------------------
;32價僢僩晞崋側偟惍悢傪10恑悢偺暥帤楍偵曄姺偡傞
;<d0.l:晞崋側偟惍悢
;<a0.l:僶僢僼傽丅10恑悢偺暥帤楍偺愭摢
;>a0.l:10恑悢偺暥帤楍偺枛旜偺0偺埵抲
utos::
	if	<tst.l d0>,eq		;0
		move.b	#'0',(a0)+
	else				;0埲奜
		push	d0-d2/a1
		lea.l	utos_table(pc),a1
		do
			move.l	(a1)+,d1
		while	<cmp.l d1,d0>,lo	;堷偗傞偲偙傠傑偱恑傓丅僛儘僒僾儗僗
		do
			moveq.l	#'0'-1,d2
			do
				addq.b	#1,d2
				sub.l	d1,d0
			while	hs			;堷偗傞夞悢傪悢偊傞
			move.b	d2,(a0)+
			add.l	d1,d0			;堷偒夁偓偨暘傪壛偊栠偡
			move.l	(a1)+,d1
		while	ne
		pop
	endif
	clr.b	(a0)
	rts

utos_table::
	.dc.l	1000000000
	.dc.l	100000000
	.dc.l	10000000
	.dc.l	1000000
	.dc.l	100000
	.dc.l	10000
	.dc.l	1000
	.dc.l	100
	.dc.l	10
	.dc.l	1
	.dc.l	0



	.end
