			  Z80 ASSEMBLER - ZASM VER 1.6
                      	;Compatible BASIC for PC-6001
                      	; by AKIKAWA, Hisashi  2013-2025
                      	
                      	;This software is redistributable under the LGPLv2.1 or any later version.
                      	
                      	
                      	;subroutine entry address
  0000                	BOOT	equ	0000h
  0008                	CHKPAR	equ	0008h
  0010                	ANADAT	equ	0010h
  0018                	JPHK1	equ	0018h
  0020                	CPHLDE	equ	0020h
  0028                	CHKSGN	equ	0028h
  0038                	JPHK2	equ	0038h
  0384                	ERRSTR	equ	0384h
  038B                	ERRIN	equ	038bh
  0390                	OK	equ	0390h
  0442                	EDIT	equ	0442h
  06EA                	CMDEND	equ	06eah
  0709                	INTPRT2	equ	0709h
  0741                	FTOI2	equ	0741h
  0955                	PIEND	equ	0955h
  0A8F                	CHKEXTR	equ	0a8fh
  0A9B                	INPT1EX	equ	0a9bh
  0BEE                	TOUPHL	equ	0beeh
  0D16                	ABTOF	equ	0d16h
  0DE3                	INT1INC	equ	0de3h
  0DE4                	INT1ARG	equ	0de4h
  0E78                	IN90H	equ	0e78h
  0E8F                	OUT90H	equ	0e8fh
  0EB0                	INTGRP	equ	0eb0h
  0EB5                	INTKEY	equ	0eb5h
  0EF6                	IKBF	equ	0ef6h
  0F2B                	IKPOP	equ	0f2bh
  0F74                	INTTIM	equ	0f74h
  0FBC                	GETCH	equ	0fbch
  0FC4                	GETC	equ	0fc4h
  103A                	GETKBF	equ	103ah
  1058                	CLRKBF	equ	1058h
  1061                	STICK	equ	1061h
  1075                	PRTC	equ	1075h
  10AA                	PRTCH	equ	10aah
  10EA                	PATCH1	equ	10eah
  116D                	SETCSR	equ	116dh
  1179                	CSRON	equ	1179h
  1181                	CSROFF	equ	1181h
  11B8                	Y2AD	equ	11b8h
  11CD                	XY2AD	equ	11cdh
  11DA                	DELLIN	equ	11dah
  1257                	PRTCHXY	equ	1257h
  1260                	SCRLUP	equ	1260h
  12A9                	SCRLDW	equ	12a9h
  12B5                	PRTFKEY	equ	12b5h
  1390                	CHGMOD	equ	1390h
  13ED                	CHGDSP	equ	13edh
  140C                	CHGACT	equ	140ch
  1478                	AD2GAD	equ	1478h
  14A0                	CGROM	equ	14a0h
  14AF                	PRTCHAD	equ	14afh
  1578                	GXY2SXY	equ	1578h
  15BA                	SXY2AD	equ	15bah
  15C0                	SETATT	equ	15c0h
  15D5                	GETCOLR	equ	15d5h
  18C3                	SETBO	equ	18c3h
  1A1C                	PUTPRT	equ	1a1ch
  1A4F                	CNVKANA	equ	1a4fh
  1A61                	ROPEN	equ	1a61h
  1A70                	GETCMT	equ	1a70h
  1AAA                	RCLOSE	equ	1aaah
  1AB8                	WOPEN	equ	1ab8h
  1ACC                	PUTCMT	equ	1acch
  1AED                	CHK90H	equ	1aedh
  1B06                	WCLOSE	equ	1b06h
  1B2A                	BLNKAST	equ	1b2ah
  1B49                	RLOFF	equ	1b49h
  1B4B                	RLON	equ	1b4bh
  1B54                	OUTB0H	equ	1b54h
  1B60                	PLSTPS	equ	1b60h
  1BB3                	PLSTOP	equ	1bb3h
  1BBE                	SETPSG2	equ	1bbeh
  1BC5                	SETPSG	equ	1bc5h
  1BCD                	BELL	equ	1bcdh
  1CA6                	JOYSTK	equ	1ca6h
  1CB4                	PATCH2	equ	1cb4h
  1D52                	CNSMAIN	equ	1d52h
  1D73                	SETCNSL	equ	1d73h
  1DBB                	SETC3	equ	1dbbh
  1DFB                	CLS	equ	1dfbh
  1E39                	SCRMAIN	equ	1e39h
  1EB3                	PLAY	equ	1eb3h
  2030                	SCALE2	equ	2030h		;for mkII
  204B                	SCALE	equ	204bh
  2286                	JOYTBL	equ	2286h
  2296                	CSRTBL	equ	2296h
  2539                	GETFN	equ	2539h
  254E                	CMTSKP	equ	254eh
  2576                	FOUND	equ	2576h
  2583                	PUTFN	equ	2583h
  259A                	INPOPN	equ	259ah
  25A8                	PRTOPN	equ	25a8h
  25E5                	WAIT	equ	25e5h
  26C7                	PUTDEV	equ	26c7h
  2701                	PUTPRNL	equ	2701h
  272D                	PUTNLX	equ	272dh
  2739                	PUTNL	equ	2739h
  274D                	STOPESC	equ	274dh
  2874                	CTLL	equ	2874h
  28F9                	INPTSCR	equ	28f9h
  2905                	INPT1	equ	2905h
  2D13                	SETGXY	equ	2d13h
  2D47                	PSET	equ	2d47h
  2DE4                	LINEBF	equ	2de4h
  2E1F                	LINE	equ	2e1fh
  2E35                	LINEB	equ	2e35h
  2EF1                	PAPOP	equ	2ef1h
  2EFA                	PAINT	equ	2efah
  30CE                	PUTSINC	equ	30ceh
  30CF                	PUTS	equ	30cfh
  310F                	GC	equ	310fh
  34F9                	RESSTK	equ	34f9h
  3913                	DE2HL4	equ	3913h
  397A                	PUTI1	equ	397ah		;for mkII
  3A99                	INLNUM	equ	3a99h
  3AA1                	PUTI2	equ	3aa1h
  3AA5                	I2TOA	equ	3aa5h
  3AAC                	FTOA	equ	3aach
  3BAF                	RNDPLS	equ	3bafh
                      	
                      	;BASIC command
  0781                	C_RUN	equ	0781h		;RUN
  07E0                	C_DATA	equ	07e0h		;DATA
  07E2                	C_REM	equ	07e2h		;REM
  087A                	C_LPRT	equ	087ah		;LPRINT
  087E                	C_PRT	equ	087eh		;PRINT
  1CD2                	C_LOCA	equ	1cd2h		;LOCATE
  1CF6                	C_CNSL	equ	1cf6h		;CONSOLE
  1D9B                	C_COLR	equ	1d9bh		;COLOR
  1E04                	C_SCRN	equ	1e04h		;SCREEN
  2236                	F_STCK	equ	2236h		;STICK()
  2256                	F_STRG	equ	2256h		;STRIG()
  22A6                	C_LCPY	equ	22a6h		;LCOPY
  2D37                	C_PRST	equ	2d37h		;PRESET
  2D3C                	C_PSET	equ	2d3ch		;PSET
  35A9                	C_CLR	equ	35a9h		;CLEAR
                      	
                      	;work area
  FA18                	STOPFLG	equ	0fa18h		;03h=STOP,1bh=ESC
  FA19                	CMTSTAT	equ	0fa19h		;bit1=data received, bit4=error
  FA1A                	INPDEV	equ	0fa1ah		;input device
  FA1D                	CMTBUF	equ	0fa1dh		;CMT data
  FA1E                	ASTSTAT	equ	0fa1eh		;cload asterisk status
  FA1F                	BAUD	equ	0fa1fh		;baud rate (00=600baud, ff=1200baud)
  FA20                	HEIGHT	equ	0fa20h		;Y max+1
  FA27                	PORTB0H	equ	0fa27h		;port b0h
  FA28                	TMCNT	equ	0fa28h		;time count, fa28-fa2b
  FA2D                	CONSOL4	equ	0fa2dh		;console 4th parameter
  FA2E                	CSRBLNK	equ	0fa2eh		;0=cursor blink off, 1=on
  FA2F                	CSRSTAT	equ	0fa2fh		;0=normal, ff=reversed
  FA30                	GRPWRK	equ	0fa30h		;input graphic character work
  FA31                	GRPFLG	equ	0fa31h		;print graphic character flag
  FA32                	FKEYCNT	equ	0fa32h		;function key counter
  FA51                	RSEED	equ	0fa51h		;random seed, fa51-fa55
  FA57                	PRTPOS	equ	0fa57h		;printer head position (0-origin)
  FA58                	DEVICE	equ	0fa58h		;output device
  FA59                	CMMCNST	equ	0fa59h		;constant for print-comma
  FA5B                	STACK	equ	0fa5bh		;initial stack pointer
  FA5D                	LINENUM	equ	0fa5dh		;current line number
  FA5F                	STARTAD	equ	0fa5fh		;basic program start address
  FA61                	CMDTBL	equ	0fa61h		;command jump table
  FAE5                	FNCTBL	equ	0fae5h		;function jump table
  FB3D                	FKEYTBL	equ	0fb3dh		;function key data
  FB8D                	FKEYAD	equ	0fb8dh		;function key address
  FB8F                	KYBFIN	equ	0fb8fh		;key buffer pointer for input
  FB90                	KYBFOUT	equ	0fb90h		;key buffer pointer for output
  FB92                	KYBFSZ	equ	0fb92h		;key buffer size
  FB93                	KYBFAD	equ	0fb93h		;key buffer address
  FB95                	RSBFIN	equ	0fb95h		;RS-232C buffer in
  FB96                	RSBFOUT	equ	0fb96h		;RS-232C buffer out
  FB98                	RSBFSZ	equ	0fb98h		;RS-232C buffer size
  FB99                	RSBFAD	equ	0fb99h		;RS-232C buffer address
                      	
                      	;PLAY command
  FBA1                	BUFAIN	equ	0fba1h		;channelA buffer pointer for input
  FBA2                	BUFAOUT	equ	0fba2h		;channelA buffer pointer for output
  FBA4                	BUFASZ	equ	0fba4h		;channelA buffer size
  FBA5                	BUFAAD	equ	0fba5h		;channelA buffer address
  FBA7                	BUFBIN	equ	0fba7h		;channelB buffer in
  FBAD                	BUFCIN	equ	0fbadh		;channelC buffer in
                      	
  FBB9                	KEYBUF	equ	0fbb9h		;key buffer, fbb9-fbf8
  FBF9                	RSBUF	equ	0fbf9h		;RS-232C buffer, fbf9-fc38
                      	
                      	;PLAY command
  FC39                	BUFA	equ	0fc39h		;channelA buffer, fc39-fc78
  FC79                	BUFB	equ	0fc79h		;channelB buffer, fc79-fcb8
  FCB9                	BUFC	equ	0fcb9h		;channelC buffer, fcb9-fcf8
  FD14                	CHANNEL	equ	0fd14h		;channel (0-2)
  FD15                	SVBCK	equ	0fd15h		;backup of S/V-value
  FD17                	PLAYLEN	equ	0fd17h		;length
  FD18                	PLAYSTR	equ	0fd18h		;string address
  FD1B                	PLAYST	equ	0fd1bh		;PLAY status
  FD1D                	PLWKA	equ	0fd1dh		;PLAY work for channelA
  0000                	REMAIN	equ	0fd1dh-PLWKA	;remaining time
  0002                	PLLEN	equ	0fd1fh-PLWKA	;string length
  0003                	PLADR	equ	0fd20h-PLWKA	;string address
  000F                	OCTAVE	equ	0fd2ch-PLWKA	;O-value
  0010                	LENGTH	equ	0fd2dh-PLWKA	;L-value
  0011                	TEMPO	equ	0fd2eh-PLWKA	;T-value
  0012                	VOLUME	equ	0fd2fh-PLWKA	;V-value
  0013                	PERIOD	equ	0fd30h-PLWKA	;M-value
  FD42                	PLWKB	equ	0fd42h		;PLAY work for channelB
  FD67                	PLWKC	equ	0fd67h		;PLAY work for channelC
                      	
  FD8C                	PAGES	equ	0fd8ch		;How many pages?
  FD8D                	USREND	equ	0fd8dh		;user area end, fd8d-fd8e
  FD8F                	SCREEN2	equ	0fd8fh		;screen 2nd parameter-1
  FD90                	SCREEN3	equ	0fd90h		;screen 3rd parameter-1
                      	
  FD91                	VRAM	equ	0fd91h		;VRAM address (high)
  FD92                	SCREEN1	equ	0fd92h		;screen 1st parameter-1
  FD93                	COLOR1	equ	0fd93h		;color 1st parameter
  FD94                	COLOR2	equ	0fd94h		;color 2nd parameter
  FD95                	COLOR3	equ	0fd95h		;color 3rd parameter (1,2 -> 0,2)
  FD96                	M1COLOR	equ	0fd96h		;screen mode 1 color parameters, fd96-fd98
  FD99                	M2COLOR	equ	0fd99h		;screen mode 2 color parameters, fd99-fd9b
  FD9C                	M3COLOR	equ	0fd9ch		;screen mode 3 color parameters, fd9c-fd9e
  FD9F                	M4COLOR	equ	0fd9fh		;screen mode 4 color parameters, fd9f-fda1
  FDA2                	CONSOL1	equ	0fda2h		;console 1st line number+1
  FDA3                	CONSOL2	equ	0fda3h		;console last line number+1
  FDA4                	FSTLIN	equ	0fda4h		;=(CONSOL1)
  FDA5                	LASTLIN	equ	0fda5h		;sc12:(CONSOL2)-(CONSOL3) sc34:(CONSOLE2)
  FDA6                	CONSOL3	equ	0fda6h		;console 3rd parameter
  FDA7                	FKEYSFT	equ	0fda7h		;shift key status for function key display
  FDA8                	CSRY	equ	0fda8h		;cursor Y+1
  FDA9                	CSRX	equ	0fda9h		;cursor X+1
  FDAA                	CSRAD	equ	0fdaah		;cursor address
  FDAC                	WIDTH	equ	0fdach		;X max+1
  FDAE                	GRPX1	equ	0fdaeh		;graphic X, fdae-fdaf
  FDB0                	GRPY1	equ	0fdb0h		;graphic Y, fdb0-fdb1
  FDB2                	VRAMBIT	equ	0fdb2h		;color bit/dot pattern
  FDB3                	VRAMAD	equ	0fdb3h		;VRAM attribute address
  FDB7                	LINEST	equ	0fdb7h		;line connection status, fdb7-fdc6 (0=connect to next line)
  FDC8                	PAGE1	equ	0fdc8h		;page1 data, fdc8-fdfe
  FDFF                	PAGE2	equ	0fdffh		;page2 data, fdff-fe35
  FE36                	PAGE3	equ	0fe36h		;page3 data, fe36-fe6c
  FE6D                	PAGE4	equ	0fe6dh		;page4 data, fe6d-fea3
                      	
  FEA4                	INPTXY	equ	0fea4h		;INPUT command initial position
  FEA6                	INPTX	equ	0fea6h		;INPUT command end position, or length
  FEA7                	INPTPAG	equ	0fea7h		;INPUT command page
  FEA8                	INSMODE	equ	0fea8h		;0=not insert mode, ff=insert mode
  FEAA                	STOPSC2	equ	0feaah		;screen 2nd parameter -1 in stop
  FEAB                	STOPSC3	equ	0feabh		;screen 3rd parameter -1 in stop
  FEAC                	ATTDAT	equ	0feach		;color attribute data
  FEAD                	GRPX2	equ	0feadh		;graphic X, fead-feae
  FEAF                	GRPY2	equ	0feafh		;graphic Y, feaf-feb0
  FEB1                	GRPX3	equ	0feb1h		;graphic work, feb1-feb2
  FEB3                	GRPY3	equ	0feb3h		;graphic work, feb3-feb4
  FEB5                	PAWRK	equ	0feb5h		;paint work, feb5-feb6
  FEB7                	PACNT	equ	0feb7h		;paint work
  FEC5                	BORDERA	equ	0fec5h		;paint border color attribute
  FEC6                	BORDERC	equ	0fec6h		;paint border color code
  FECA                	GMKYBUF	equ	0fecah		;reply to game key query
                      	;TARGET	equ	0fecbh		;target file name, fecb-fed0
  FED1                	FNAME	equ	0fed1h		;loading file name, fed1-fed6
  FED8                	VERIFY	equ	0fed8h		;load/verify flag 00h=load ffh=verify
  FEDA                	INPBUF	equ	0fedah		;input buffer, feda-ff21, (ff22)-(ff23)=00h
  FF25                	ARGTYP	equ	0ff25h		;0=value 1=string
  FF27                	STREND	equ	0ff27h		;strings area end
  FF29                	BASICAD	equ	0ff29h		;basic area start
  FF2D                	STRDSC1	equ	0ff2dh		;temporary string descriptor, ff2d-ff30
  FF31                	STRDSC2	equ	0ff31h		;ff31-ff34
  FF35                	STRDSC3	equ	0ff35h		;ff35-ff38
  FF39                	STRDSC4	equ	0ff39h		;ff39-ff3c
  FF3D                	STRAD	equ	0ff3dh		;string area start address - 1
  FF41                	GCWRK	equ	0ff41h		;garbage collection work
  FF45                	DATALN	equ	0ff45h		;data line number
  FF49                	INPRD	equ	0ff49h		;INPUT(=0) or READ(>0)
  FF4E                	PROGAD	equ	0ff4eh		;program address in interpreting
  FF50                	TMP	equ	0ff50h		;temporary
  FF52                	STOPLN	equ	0ff52h		;line number at stop
  FF54                	STOPAD	equ	0ff54h		;stop address
  FF56                	VARAD	equ	0ff56h		;variable area start address
  FF58                	ARRAD	equ	0ff58h		;array area start address
  FF5A                	FREEAD	equ	0ff5ah		;free area start address
  FF5C                	DATAAD	equ	0ff5ch		;data command address
  FF5E                	FNPAR	equ	0ff5eh		;FN() parameter name
  FF60                	FNARG	equ	0ff60h		;FN() argument value, ff60-ff64
  FF65                	OPRTR	equ	0ff65h		;operator, FAC1-1
  FF66                	FAC1	equ	0ff66h		;floating accumlator 1, ff66-ff6a
  FF6D                	FAC2	equ	0ff6dh		;floating accumlator 2, ff6d-ff71
  FF72                	FAC3	equ	0ff72h		;floating accumlator 3 (string conversion)
  FF8A                	HOOK	equ	0ff8ah		;hook area, ff8a-ffe3
  FF8A                	HOOKPED	equ	0ff8ah		;hook for print end
  FF8D                	HOOKERR	equ	0ff8dh		;hook for error
  FF93                	HOOKEDT	equ	0ff93h		;hook for screen editor
  FF99                	HOOKCLP	equ	0ff99h		;hook for changing link pointer
  FFAE                	HOOKPRT	equ	0ffaeh		;hook for PRINT# command
  FFBA                	HOOKINP	equ	0ffbah		;hook for INPUT# command
  FFC9                	HOOKRES	equ	0ffc9h		;hook for RESSTK
  FFCF                	HOOKPUT	equ	0ffcfh		;hook for PUTDEV
  FFD2                	HOOKLCP	equ	0ffd2h		;hook for LCOPY
  FFD8                	HOOKSTP	equ	0ffd8h		;hook for stop key
  FFDB                	HOOK18H	equ	0ffdbh		;hook for 0018h
  FFE1                	HOOK38H	equ	0ffe1h		;hook for 0038h
                      	
  0020                	COLUMNS	equ	32
  0010                	ROWS	equ	16
                      	
  0081                	FOR_	equ	081h
  0083                	DATA_	equ	083h
  0088                	GOTO_	equ	088h
  0089                	RUN_	equ	089h
  008C                	GOSUB_	equ	08ch
  008E                	REM_	equ	08eh
  0093                	DEF_	equ	093h
  0095                	PRINT_	equ	095h
  009F                	SCREEN_	equ	09fh
  00AA                	CMDLAST	equ	0aah		;last command
  00C2                	TAB_	equ	0c2h
  00C3                	TO_	equ	0c3h
  00C4                	FN_	equ	0c4h
  00C5                	SPC_	equ	0c5h
  00C6                	INKEY_	equ	0c6h
  00C7                	THEN_	equ	0c7h
  00C8                	NOT_	equ	0c8h
  00C9                	STEP_	equ	0c9h
  00CA                	PLUS_	equ	0cah
  00CB                	MINUS_	equ	0cbh
  00CC                	ASTRSK_	equ	0cch
  00D1                	GT_	equ	0d1h
  00D2                	EQ_	equ	0d2h
  00D3                	LT_	equ	0d3h
  00D4                	FNC1ST	equ	0d4h		;1st function
  00D7                	USR_	equ	0d7h
  00EA                	LEFT_	equ	0eah
  00EC                	MID_	equ	0ech
  00EF                	STICK_	equ	0efh
  00F0                	STRIG_	equ	0f0h
  00F1                	FNCLAST	equ	0f1h		;last function
                      	
                      	
                      	;;;;;;;;;;;;;;;;;;;;;;;;;
                      	
                      	;boot
  0000                		org	BOOT
  0000  F3            		di
  0001  C34316        		jp	COLD
                      	
                      	
                      	;check parameter
                      	; compare (hl) and data at (sp)
                      	;input: sp,hl
                      	;output: a=data, hl=data address, z-flag(a=00h or 3ah), c-flag(a=30h-39h)
  0004                	_CHKPAR:ds	CHKPAR-_CHKPAR
  0008                		org	CHKPAR
                      	
  0008  E3            		ex	(sp),hl
  0009  7E            		ld	a,(hl)
  000A  23            		inc	hl
  000B  E3            		ex	(sp),hl
  000C  BE            		cp	(hl)
  000D  C2DC03        		jp	nz,SNERR
                      	
                      	
                      	;skip space and analyze a byte
                      	;input: hl=address-1
                      	;output: a=data, hl=data address, z-flag(a=00h or 3ah), c-flag(a=30h-39h)
                      	;destroy: f
  0010                	_ANADAT:ds	ANADAT-_ANADAT
  0010                		org	ANADAT
                      	
  0010  CD563F        		call	SKIPSPINC
  0013  C3E00B        		jp	CHKFIG
                      	
                      	
                      	;jump hook
  0016                	_JPHK1:	ds	JPHK1-_JPHK1
  0018                		org	JPHK1
                      	
  0018  C3DBFF        		jp	HOOK18H
                      	
                      	
                      	;compare hl and de
                      	;input: hl,de
                      	;output: f
                      	;destroy: af
  001B                	_CPHLDE:ds	CPHLDE-_CPHLDE
  0020                		org	CPHLDE
                      	
  0020  7C            		ld	a,h
  0021  92            		sub	d
  0022  C0            		ret	nz
  0023  7D            		ld	a,l
  0024  93            		sub	e
  0025  C9            		ret
                      	
                      	
                      	;check sign of FAC1
                      	;input: FAC1
                      	;output: a(0:FAC1=0 1:FAC1>0 ff:FAC1<0), z(1:FAC1=0)
                      	;destroy: af
  0026                	_CHKSGN:ds	CHKSGN-_CHKSGN
  0028                		org	CHKSGN
  0028  3A6AFF        		ld	a,(FAC1+4)
  002B  B7            		or	a
  002C  C8            		ret	z
  002D  C3FC38        		jp	CHKSGN2
                      	
                      	
                      	;jump hook
  0030                	_JPHK2:	ds	JPHK2-_JPHK2
  0038                		org	JPHK2
                      	
  0038  C3E1FF        		jp	HOOK38H
                      	
                      	
                      	;hot start
  003B                	HOT:
                      	;initialize function key
  003B  217001        		ld	hl,FKEYLST
  003E  113DFB        		ld	de,FKEYTBL
  0041  0E0A          		ld	c,0ah
  0043                	SETFKLP1:
  0043  7E            		ld	a,(hl)
  0044  23            		inc	hl
  0045  E5            		push	hl		;
  0046  CDB525        		call	CNVASC
                      	
  0049  0608          		ld	b,08h
  004B                	SETFKLP2:
  004B  05            		dec	b
  004C  12            		ld	(de),a
  004D  13            		inc	de
  004E  23            		inc	hl
  004F  7E            		ld	a,(hl)
  0050  B7            		or	a
  0051  F24B00        		jp	p,SETFKLP2
                      	
  0054  E1            		pop	hl		;
  0055  7E            		ld	a,(hl)
  0056  23            		inc	hl
                      	
  0057                	SETFKLP3:
  0057  12            		ld	(de),a
  0058  13            		inc	de
  0059  AF            		xor	a
  005A  10FB          		djnz	SETFKLP3
                      	
  005C  0D            		dec	c
  005D  20E4          		jr	nz,SETFKLP1
  005F  CDB512        		call	PRTFKEY
                      	
                      	;check external ROM
  0062  2A0040        		ld	hl,(4000h)
  0065  114142        		ld	de,'A'+'B'*100h
  0068  E7            		rst	CPHLDE
  0069  2A0240        		ld	hl,(4002h)
  006C  CCA507        		call	z,JPHL
                      	
                      	;How Many Pages?
  006F                	PAGELP:
  006F  211501        		ld	hl,HOWMANY
  0072  CDCF30        		call	PUTS
  0075  CD0529        		call	INPT1
  0078  D7            		rst	ANADAT
  0079  1600          		ld	d,00h
  007B  3016          		jr	nc,SETPAGEMAX
  007D  CDCA27        		call	ATOI2
  0080  7A            		ld	a,d
  0081  B7            		or	a
  0082  2008          		jr	nz,PAGEFC
  0084  7B            		ld	a,e
  0085  3D            		dec	a
  0086  218CFD        		ld	hl,PAGES
  0089  BE            		cp	(hl)
  008A  3814          		jr	c,SETPAGE
  008C                	PAGEFC:
  008C  1E08          		ld	e,08h		;?FC Error
  008E                	PAGEERR:
  008E  CDBF03        		call	PRTERR
  0091  18DC          		jr	PAGELP
                      	
  0093                	SETPAGEMAX:
  0093  1E02          		ld	e,02h		;?SN Error
  0095  20F7          		jr	nz,PAGEERR
  0097  B7            		or	a
  0098  1E26          		ld	e,26h		;?MO Error
  009A  20F2          		jr	nz,PAGEERR	;colon
                      	
  009C  218CFD        		ld	hl,PAGES
  009F  5E            		ld	e,(hl)
  00A0                	SETPAGE:
  00A0  73            		ld	(hl),e
                      	
  00A1  CDBE34        		call	NEW
  00A4  211001        		ld	hl,ENDTBL-1
  00A7  19            		add	hl,de		;d=0
  00A8  66            		ld	h,(hl)
  00A9  2EFF          		ld	l,0ffh
  00AB  228DFD        		ld	(USREND),hl
  00AE  013200        		ld	bc,50
  00B1  CDD135        		call	CLRMAIN
                      	
                      	;print start message
  00B4  CDA03F        		call	CHK6001A
  00B7  212701        		ld	hl,SYSNAME
  00BA  2003          		jr	nz,PC6001
  00BC  212C01        		ld	hl,SYSNAME2
  00BF                	PC6001:
  00BF  CDCF30        		call	PUTS
  00C2  213801        		ld	hl,BASICVER
  00C5  CDCF30        		call	PUTS
  00C8  CDCC34        		call	CHKFRE
                      	;	ld	hl,002fh	;for compatibility with N60-BASIC
  00CB  212800        		ld	hl,0028h	;for compatibility with N60-BASIC
  00CE  19            		add	hl,de
  00CF  CDA13A        		call	PUTI2
  00D2  210501        		ld	hl,BFREE
  00D5                	PUTSEDIT:
  00D5  CDCF30        		call	PUTS
  00D8  C34204        		jp	EDIT
                      	
                      	
                      	;initialize table
  00DB                	IOTBL93:
  00DB  C0            		db	0c0h		;bit7: mode definition
                      					;bit65:portA,portC-upper=mode 2
                      					;bit4: portA=output
                      					;bit3: portC-upper=output
                      					;bit2: portB,portC-lower=mode 0
                      					;bit1: portB=output
                      					;bit0: portC-lower=output
  00DC  0D            		db	0dh		;enable 8255 INT for writing
  00DD  09            		db	09h		;enable 8255 INT for reading
  00DE  05            		db	05h		;CGROM off
  00DF  03            		db	03h		;CRTC
  00E0  0F            		db	0fh		;nobf=1 (for emulator?)
                      	
  00E1                	IOTBL81:
  00E1  92            		db	92h		;reset error, DTR=1, RxE/TxEN=0
  00E2  92            		db	92h		; set twice for synchronous mode
  00E3  52            		db	52h		;reset, reset error, DTR=1, RxE/TxEN=0
  00E4  4F            		db	4fh		;stop bits=1, parity disable,
                      					; character length=8bits, baud rate factor=64
  00E5  37            		db	37h		;reset error, RTS/DTR/RxE/TxEN=1
                      	
                      	;for mkII
  00E6                	IOTBLF0:
                      	;F0:	db	0ddh		;0000-7fff:internal RAM for reading (test)
  00E6  71            	F0:	db	71h		;0000-3fff:internal ROM for reading
                      					;4000-7fff:external ROM for reading
  00E7  DD            	F1:	db	0ddh		;8000-ffff:internal RAM for reading
  00E8  55            	F2:	db	55h		;0000-ffff:internal RAM for writing
  00E9  C2            	F3:	db	0c2h		;wait and interrupt control
                      					; bit7: M1 wait (1=on)
                      					; bit6: ROM wait (1=on)
                      					; bit5: RAM wait (1=on)
                      					; bit4: INT2 interrupt address (1=output)
                      					; bit3: INT1 interrupt address (1=output)
                      					; bit2: timer interrupt (1=disable)
                      					; bit1: INT2 interrupt (1=disable)
                      					; bit0: INT1 interrupt (1=disable)
  00EA  00            	F4:	db	00h		;INT1 address
  00EB  00            	F5:	db	00h		;INT2 address
  00EC  03            	F6:	db	03h		;timer count up
  00ED  06            	F7:	db	06h		;timer interrupt address
  00EE  C3            	F8:	db	0c3h		;CG rom access control
                      					; bit7: wait (0=off, 1=on)
                      					; bit6: read enable (0=disable, 1=enable)
                      					; bit5: bit2 mask (1=mask)
                      					; bit4: bit1 mask (1=mask)
                      					; bit3: bit0 mask (1=mask)
                      					; bit2-0: CGROM address (=A15-A13)
                      	
                      	;interrupt
  00EF                	INTTBL:
  00EF  B50E          		dw	INTKEY		;fa02 normal key
  00F1  590F          		dw	INT232		;fa04 RS-232C
  00F3  740F          		dw	INTTIM		;fa06 2ms timer
  00F5  9A0F          		dw	INTCMT		;fa08 CMT read
  00F7  A70F          		dw	EIRET		;fa0a ?
  00F9  A70F          		dw	EIRET		;fa0c ?
  00FB  A90F          		dw	INTWSTP		;fa0e CMT write stop
  00FD  A90F          		dw	INTRSTP		;fa10 CMT read stop
  00FF  B10F          		dw	INTERR		;fa12 CMT error
  0101  B00E          		dw	INTGRP		;fa14 GRAPH key etc.
  0103  100F          		dw	INTGAM		;fa16 reply to game key query
                      	
                      	
  0105                	BFREE:
  0105  20427974657320		db	" Bytes free", 00h
  0111                	ENDTBL:
  0111  F9DFBF9F      		db	0f9h, 0dfh, 0bfh, 9fh
  0115                	HOWMANY:
  0115  486F77204D616E		db	"How Many Pages", 00h
  0124                	QMARK:
  0124  3F2000        		db	"? ", 00h
  0127                	SYSNAME:
  0127  9ADE96FD00    		db	9ah, 0deh, 96h, 0fdh, 00h
  012C                	SYSNAME2:
  012C  436F6D70617469		db	"Compatible ", 00h
  0138                	BASICVER:
  0138  42415349432056		db	"BASIC Ver.0.8.1", 0dh, 0ah, 00h
                      	
  014A                	PAGEDATA:
  014A  C0            		db	0c0h		;fd91	VRAM address
  014B  00            		db	00h		;fd92	screen 1st parameter-1
  014C  01            		db	01h		;fd93	color 1st parameter
  014D  00            		db	00h		;fd94	color 2nd parameter
  014E  00            		db	00h		;fd95	color 3rd parameter (1,2 -> 0,2)
  014F  010000        		db	01h, 00h, 00h	;fd96	screen mode 1 color parameters
  0152  010000        		db	01h, 00h, 00h	;fd99	screen mode 2 color parameters
  0155  020000        		db	02h, 00h, 00h	;fd9c	screen mode 3 color parameters
  0158  030000        		db	03h, 00h, 00h	;fd9f	screen mode 4 color parameters
  015B  01            		db	01h		;fda2	console 1st line number+1
  015C  10            		db	10h		;fda3	console last line number+1
  015D  01            		db	01h		;fda4	=(fda2)
  015E  0F            		db	0fh		;fda5	sc12:(fda3)-(fda6) sc34:(fda3)
  015F  01            		db	01h		;fda6	console 3rd parameter
  0160  00            		db	00h		;fda7	shift key status for function key disp
  0161  01            		db	01h		;fda8	cursor Y+1
  0162  01            		db	01h		;fda9	cursor X+1
  0163  00C2          		dw	0c200h		;fdaa	cursor address
  0165  20            		db	COLUMNS		;fdac	X max+1
  0166  00            		db	00h		;fdad
  0167  0000          		dw	0000h		;fdae	graphic X
  0169  0000          		dw	0000h		;fdb0	graphic Y
  016B  00            		db	00h		;fdb2
  016C  00            		db	00h		;fdb3
  016D  00            		db	00h		;fdb4
  016E  00            		db	00h		;fdb5
  016F  10            		db	10h		;fdb6	LINEST-1
                      	
                      	
  0170                	FKEYLST:
  0170  9A20          		db	9ah, ' '	;COLOR
  0172  A322          		db	0a3h, 22h	;CLOAD"
  0174  8820          		db	GOTO_, ' '	;GOTO
  0176  9720          		db	97h, ' '	;LIST
  0178  890D          		db	RUN_, 0dh	;RUN
  017A  9F20          		db	9fh, ' '	;SCREEN
  017C  A422          		db	0a4h, 22h	;CSAVE"
  017E  9520          		db	PRINT_, ' '	;PRINT
  0180  A720          		db	0a7h, ' '	;PLAY
  0182  960D          		db	96h, 0dh	;CONT
                      	
                      	
  0184                	OPRTBL:
                      	;c4-c7
                      	;	dw					F_FN,	F_SPC,	F_INKY,	C_THEN
                      	;c8-cf
  0184  100CDC037E3694		dw	O_NOT,	C_STEP,	O_PLS,	O_MNS,	O_MUL,	O_DIV,	O_POW,	O_AND
                      	;d0-d3
  0194  F80B220C      		dw	O_OR,	O_GTEQLT
                      	
  0198                	CMDLST:
                      	;80-8f
  0198  66356506F135E0		dw	C_END,	C_FOR,	C_NEXT,	C_DATA,	C_INPT,	C_DIM,	C_READ,	C_LET
  01A8  A6078107590817		dw	C_GOTO,	C_RUN,	C_IF,	C_RSTR,	C_GSUB,	C_RET,	C_REM,	C_STOP
                      	;90-9f
  01B8  B60D36087A0857		dw	C_OUT,	C_ON,	C_LPRT,	C_DEF,	C_POKE,	C_PRT,	C_CONT,	C_LIST
  01C8  C005A9359B1D3C		dw	C_LLST,	C_CLR,	C_COLR,	C_PSET,	C_PRST,	C_LINE,	C_PAIN,	C_SCRN
                      	;a0-aa
  01D8  FB1DD21CF61CB5		dw	C_CLS,	C_LOCA,	C_CNSL,	C_CLD,	C_CSV,	C_EXEC,	C_SOUN,	C_PLAY
  01E8  4123A622B034  		dw	C_KEY,	C_LCPY,	C_NEW
                      	
  01EE                	FNCLST:
                      	;d4-df
  01EE  043980391C39E5		dw					F_SGN,	F_INT,	F_ABS,	F_USR
  01F6  2932A80D330D41		dw	F_FRE,	F_INP,	F_LPOS,	F_POS,	F_SQR,	F_RND,	F_LOG,	F_EXP
                      	;e0-ef
  0206  7D3D903D583EEE		dw	F_COS,	F_SIN,	F_TAN,	F_PEEK,	F_LEN,	F_HEX,	F_STR,	F_VAL
  0216  AC31B631C031C7		dw	F_ASC,	F_CHR,	F_LEFT,	F_RGT,	F_MID,	F_POIN,	F_CSRL,	F_STCK
                      	;f0-f1
  0226  56226C1E      		dw	F_STRG,	F_TIME
                      	
                      	
  022A                	CMDNAME:
  022A  C54E44C64F52CE		db	'E'+80h,"ND",	'F'+80h,"OR",	'N'+80h,"EXT",	'D'+80h,"ATA"
  0238  C94E505554C449		db	'I'+80h,"NPUT",	'D'+80h,"IM",	'R'+80h,"EAD",	'L'+80h,"ET"
  0247  C74F544FD2554E		db	'G'+80h,"OTO",	'R'+80h,"UN",	'I'+80h,"F",	'R'+80h,"ESTORE"
  0257  C74F535542D245		db	'G'+80h,"OSUB",	'R'+80h,"ETURN",'R'+80h,"EM",	'S'+80h,"TOP"
                      	
  0269  CF5554CF4ECC50		db	'O'+80h,"UT",	'O'+80h,"N",	'L'+80h,"PRINT",'D'+80h,"EF"
  0277  D04F4B45D05249		db	'P'+80h,"OKE",	'P'+80h,"RINT",	'C'+80h,"ONT",	'L'+80h,"IST"
  0288  CC4C495354C34C		db	'L'+80h,"LIST",	'C'+80h,"LEAR",	'C'+80h,"OLOR",	'P'+80h,"SET"
  029B  D05245534554CC		db	'P'+80h,"RESET",'L'+80h,"INE",	'P'+80h,"AINT",	'S'+80h,"CREEN"
                      	
  02B0  C34C53CC4F4341		db	'C'+80h,"LS",	'L'+80h,"OCATE",'C'+80h,"ONSOLE",'C'+80h,"LOAD"
  02C5  C353415645C558		db	'C'+80h,"SAVE",	'E'+80h,"XEC",	'S'+80h,"OUND",	'P'+80h,"LAY"
  02D7  CB4559CC434F50		db	'K'+80h,"EY",	'L'+80h,"COPY",	'N'+80h,"EW"
                      	
  02E2                	FNCNAME:
  02E2  D4414228D44F  		db					'T'+80h,"AB(",	'T'+80h,"O"
  02E8  C64ED3504328C9		db	'F'+80h,"N",	'S'+80h,"PC(",	'I'+80h,"NKEY$",'T'+80h,"HEN"
  02F8  CE4F54D3544550		db	'N'+80h,"OT",	'S'+80h,"TEP",	'+'+80h,	'-'+80h
  0301  AAAFDEC14E44  		db	'*'+80h,	'/'+80h,	'^'+80h,	'A'+80h,"ND"
                      	
  0307  CF52BEBDBC    		db	'O'+80h,"R",	'>'+80h,	'='+80h,	'<'+80h
  030C  D3474EC94E54C1		db	'S'+80h,"GN",	'I'+80h,"NT",	'A'+80h,"BS",	'U'+80h,"SR"
  0318  C65245C94E50CC		db	'F'+80h,"RE",	'I'+80h,"NP",	'L'+80h,"POS",	'P'+80h,"OS"
  0325  D35152D24E44CC		db	'S'+80h,"QR",	'R'+80h,"ND",	'L'+80h,"OG",	'E'+80h,"XP"
                      	
  0331  C34F53D3494ED4		db	'C'+80h,"OS",	'S'+80h,"IN",	'T'+80h,"AN",	'P'+80h,"EEK"
  033E  CC454EC8455824		db	'L'+80h,"EN",	'H'+80h,"EX$",	'S'+80h,"TR$",	'V'+80h,"AL"
  034C  C15343C3485224		db	'A'+80h,"SC",	'C'+80h,"HR$",	'L'+80h,"EFT$",	'R'+80h,"IGHT$"
  035E  CD494424D04F49		db	'M'+80h,"ID$",	'P'+80h,"OINT",	'C'+80h,"SRLIN",'S'+80h,"TICK"
                      	
  0372  D354524947D449		db	'S'+80h,"TRIG",	'T'+80h,"IME",	80h
                      	
                      	
  037C                	_ERRBELL:ds	ERRSTR-1-_ERRBELL
  0383                		org	ERRSTR-1
  0383                	ERRBELL:
  0383  07            		db	07h
                      	
  0384                	_ERRSTR:ds	ERRSTR-_ERRSTR
  0384                		org	ERRSTR
  0384  204572726F7200		db	" Error", 00h
                      	
  038B                	_ERRIN:	ds	ERRIN-_ERRIN
  038B                		org	ERRIN
  038B  20696E2000    		db	" in ", 00h
                      	
  0390                	_OK:
  0390                		ds	OK-_OK
  0390                		org	OK
  0390  4F6B0D0A00    		db	"Ok", 0dh, 0ah, 00h
                      	
  0395                	ERRID:
  0395  4E46534E52474F		db	"NF", "SN", "RG", "OD", "FC", "OV", "OM", "UL"
  03A5  425344442F3049		db	"BS", "DD", "/0", "ID", "TM", "OS", "LS", "ST"
  03B5  434E554654524D		db	"CN", "UF", "TR", "MO", "FD"
                      	
                      	
                      	;print error message
                      	;input: e=error number
                      	;destroy: af,bc,de,hl
  03BF                	PRTERR:
  03BF  3E3F          		ld	a,'?'
  03C1  CD7510        		call	PRTC
  03C4  219503        		ld	hl,ERRID
  03C7  1600          		ld	d,00h
  03C9  19            		add	hl,de
  03CA  7E            		ld	a,(hl)
  03CB  CD7510        		call	PRTC
  03CE  23            		inc	hl
  03CF  7E            		ld	a,(hl)
  03D0  CD7510        		call	PRTC
  03D3  218303        		ld	hl,ERRBELL
  03D6  C3CF30        		jp	PUTS
                      	
                      	
  03D9                	NFERR:
  03D9  1E00          		ld	e,00h
  03DB  01            		db	01h		;ld bc,****
  03DC                	F_HEX:
  03DC                	C_TO:
  03DC                	C_TAB:
  03DC                	F_SPC:
  03DC                	C_THEN:
  03DC                	C_STEP:
  03DC                	SNERR:
  03DC  1E02          		ld	e,02h
  03DE  01            		db	01h		;ld bc,****
  03DF                	RGERR:
  03DF  1E04          		ld	e,04h
  03E1  01            		db	01h		;ld bc,****
  03E2                	ODERR:
  03E2  1E06          		ld	e,06h
  03E4  01            		db	01h		;ld bc,****
  03E5                	FCERR:
  03E5                	F_USR:
  03E5  1E08          		ld	e,08h
  03E7  01            		db	01h		;ld bc,****
  03E8                	OVERR:
  03E8  1E0A          		ld	e,0ah
  03EA  01            		db	01h		;ld bc,****
  03EB                	OMERR:
  03EB  1E0C          		ld	e,0ch
  03ED  01            		db	01h		;ld bc,****
  03EE                	ULERR:
  03EE  1E0E          		ld	e,0eh
  03F0  01            		db	01h		;ld bc,****
  03F1                	BSERR:
  03F1  1E10          		ld	e,10h
  03F3  01            		db	01h		;ld bc,****
  03F4                	DDERR:
  03F4  1E12          		ld	e,12h
  03F6  01            		db	01h		;ld bc,****
  03F7                	DIV0ERR:
  03F7  1E14          		ld	e,14h
  03F9  01            		db	01h		;ld bc,****
  03FA                	IDERR:
  03FA  1E16          		ld	e,16h
  03FC  01            		db	01h		;ld bc,****
  03FD                	TMERR:
  03FD  1E18          		ld	e,18h
  03FF  01            		db	01h		;ld bc,****
  0400                	OSERR:
  0400  1E1A          		ld	e,1ah
  0402  01            		db	01h		;ld bc,****
  0403                	LSERR:
  0403  1E1C          		ld	e,1ch
  0405  01            		db	01h		;ld bc,****
  0406                	STERR:
  0406  1E1E          		ld	e,1eh
  0408  01            		db	01h		;ld bc,****
  0409                	CNERR:
  0409  1E20          		ld	e,20h
  040B  01            		db	01h		;ld bc,****
  040C                	UFERR:
  040C  1E22          		ld	e,22h
  040E  01            		db	01h		;ld bc,****
  040F                	TRERR:
  040F  1E24          		ld	e,24h
  0411  01            		db	01h		;ld bc,****
  0412                	MOERR:
  0412  1E26          		ld	e,26h
  0414  01            		db	01h		;ld bc,****
  0415                	FDERR:
  0415  1E28          		ld	e,28h
                      	
  0417                	ERROR:
  0417  CD8DFF        		call	HOOKERR
  041A  ED7B5BFA      		ld	sp,(STACK)
  041E  AF            		xor	a
  041F  3231FF        		ld	(STRDSC2),a
  0422  3235FF        		ld	(STRDSC3),a
  0425  3239FF        		ld	(STRDSC4),a
  0428  3D            		dec	a
  0429  3255FF        		ld	(STOPAD+1),a	;(STOPAD)>=fa00h
  042C  CD3909        		call	PRTNLXTXT
  042F  CDBF03        		call	PRTERR
                      	
  0432                	PRTLNUM:
  0432  CDB31B        		call	PLSTOP
                      	
  0435  2A5DFA        		ld	hl,(LINENUM)
  0438  7C            		ld	a,h
  0439  A5            		and	l
  043A  3C            		inc	a
  043B  C4993A        		call	nz,INLNUM	;if (LINENUM)<>0ffffh
  043E  C34204        		jp	EDIT
                      	
                      	
                      	;program edit and direct command mode
  0441                	_EDIT:	ds	EDIT-_EDIT
  0442                		org	EDIT
                      	
  0442  CD93FF        		call	HOOKEDT
  0445  CD5810        		call	CLRKBF
  0448  CD3C09        		call	PRTNLX		;for graphic screen
  044B  CD3909        		call	PRTNLXTXT
  044E  219003        		ld	hl,OK
  0451  CDCF30        		call	PUTS
  0454                	EDIT2:
  0454  CD0127        		call	PUTPRNL
  0457  21FFFF        		ld	hl,0ffffh
  045A  225DFA        		ld	(LINENUM),hl
                      	
  045D                	EDITLP:
  045D  CDF928        		call	INPTSCR		;hl=INPBUF-1
  0460  DCB31B        		call	c,PLSTOP
  0463  CD2605        		call	CNVIL
  0466  21D9FE        		ld	hl,INPBUF-1
  0469  D7            		rst	ANADAT		;
  046A  3C            		inc	a
  046B  3D            		dec	a
  046C  28EF          		jr	z,EDITLP
  046E  D20A07        		jp	nc,INTPRT	;
                      	
                      	
                      	;change program
  0471                	CHGPRG:
  0471  CD6807        		call	GETLN
  0474  E5            		push	hl		;buffer address after line number
  0475  D5            		push	de		;line number
  0476  E5            		push	hl		;buffer address after line number
  0477  CDF304        		call	SRCHLN
  047A  DCDD04        		call	c,DELPRG	;c-flag=1
  047D  E1            		pop	hl		;buffer address after line number
  047E  34            		inc	(hl)
  047F  35            		dec	(hl)
  0480  2005          		jr	nz,INSPRG
  0482  3836          		jr	c,CHGLKP	;
  0484  C3EE03        		jp	ULERR
                      	
                      	;insert program
  0487                	INSPRG:
  0487  AF            		xor	a
  0488  110500        		ld	de,0005h
  048B                	PRGLP:
  048B  1C            		inc	e
  048C  3C            		inc	a
  048D  23            		inc	hl
  048E  34            		inc	(hl)
  048F  35            		dec	(hl)
  0490  20F9          		jr	nz,PRGLP
                      	
  0492  2A56FF        		ld	hl,(VARAD)
  0495  E5            		push	hl
                      	;	or	a
  0496  ED42          		sbc	hl,bc
  0498  E5            		push	hl		;slide size
  0499  09            		add	hl,bc		;old (VARAD)
  049A  19            		add	hl,de		;old (VARAD)+size
  049B  CDCF34        		call	CHKSTK
  049E  2256FF        		ld	(VARAD),hl
  04A1  EB            		ex	de,hl
  04A2  C1            		pop	bc		;slide size
  04A3  E1            		pop	hl		;old (VARAD)
  04A4  2B            		dec	hl
  04A5  1B            		dec	de
  04A6  EDB8          		lddr
                      	
  04A8                	COPYPRG:
  04A8  23            		inc	hl		;address to be inserted in
  04A9  23            		inc	hl
  04AA  13            		inc	de
  04AB  13            		inc	de
  04AC  73            		ld	(hl),e
  04AD  23            		inc	hl
  04AE  72            		ld	(hl),d
  04AF  23            		inc	hl
  04B0  D1            		pop	de		;line number
  04B1  73            		ld	(hl),e
  04B2  23            		inc	hl
  04B3  72            		ld	(hl),d
  04B4  23            		inc	hl
  04B5  EB            		ex	de,hl
  04B6  E1            		pop	hl		;buffer address after line number
                      	
  04B7  4F            		ld	c,a		;b=0
  04B8  EDB0          		ldir
                      	;	jr	CHGLKP
                      	
                      	
                      	;change link pointer
  04BA                	CHGLKP:
  04BA  CD99FF        		call	HOOKCLP
  04BD  CDF934        		call	RESSTK
  04C0  CDC504        		call	CHGLKPMAIN
  04C3  188F          		jr	EDIT2
                      	
                      	
                      	;change link pointer (main)
                      	;output: hl=last address
                      	;destroy: af,bc,de
  04C5                	CHGLKPMAIN:
  04C5  ED5B5FFA      		ld	de,(STARTAD)
                      	;skip address and line number
  04C9                	CHGLKPLP:
  04C9  62            		ld	h,d
  04CA  6B            		ld	l,e
  04CB  7E            		ld	a,(hl)
  04CC  23            		inc	hl
  04CD  B6            		or	(hl)
  04CE  C8            		ret	z
                      	
  04CF  010300        		ld	bc,0003h
  04D2  09            		add	hl,bc
                      	
                      	;search for next line
  04D3  AF            		xor	a
  04D4  4F            		ld	c,a		;b=0
  04D5  EDB1          		cpir
                      	
                      	;next line address
  04D7  EB            		ex	de,hl
  04D8  73            		ld	(hl),e
  04D9  23            		inc	hl
  04DA  72            		ld	(hl),d
  04DB  18EC          		jr	CHGLKPLP
                      	
                      	
                      	;input: bc=address to be deleted, hl=next line address
                      	;output: c-flag=1
                      	;destroy: af,de,hl
  04DD                	DELPRG:
  04DD  C5            		push	bc		;address to be deleted
  04DE  EB            		ex	de,hl		;de <- next line address
  04DF  2A56FF        		ld	hl,(VARAD)
  04E2  B7            		or	a
  04E3  ED52          		sbc	hl,de
  04E5  44            		ld	b,h
  04E6  4D            		ld	c,l
  04E7  EB            		ex	de,hl		;hl <- next line address
  04E8  D1            		pop	de		;address to be deleted
  04E9  D5            		push	de
  04EA  EDB0          		ldir
  04EC  ED5356FF      		ld	(VARAD),de
  04F0  C1            		pop	bc
  04F1  37            		scf
  04F2  C9            		ret
                      	
                      	
                      	;search for line number
                      	;input: de=line number
                      	;output: z=1,c=1) bc=address, hl=next line address
                      	;	 z=0,c=0) bc=next line address, hl=next next line address
                      	;	 z=1,c=0) bc=hl=end address
                      	;destroy: af
  04F3                	SRCHLN:
  04F3  2A5DFA        		ld	hl,(LINENUM)
  04F6  E7            		rst	CPHLDE
  04F7  300C          		jr	nc,SRCHSTART	;less than or equal to current line number
  04F9  2A4EFF        		ld	hl,(PROGAD)
  04FC                	SRCHLP1:
  04FC  7E            		ld	a,(hl)
  04FD  23            		inc	hl
  04FE  B7            		or	a
  04FF  20FB          		jr	nz,SRCHLP1
                      	
                      	;for PORTOPIA (mk2)
                      	;	jr	SRCHLP2
  0501  CD0805        		call	SRCHLP2
  0504  D8            		ret	c
                      	
  0505                	SRCHSTART:
  0505  2A5FFA        		ld	hl,(STARTAD)	;search from program start address
                      	
  0508                	SRCHLP2:
  0508  44            		ld	b,h
  0509  4D            		ld	c,l
  050A  7E            		ld	a,(hl)
  050B  23            		inc	hl
  050C  B6            		or	(hl)
  050D  2813          		jr	z,SRCHEND	;program end
  050F  23            		inc	hl
  0510  23            		inc	hl
  0511  7E            		ld	a,(hl)
  0512  2B            		dec	hl
  0513  BA            		cp	d
  0514  2002          		jr	nz,SRCHNZ
  0516  7E            		ld	a,(hl)
  0517  BB            		cp	e
  0518                	SRCHNZ:
  0518  0A            		ld	a,(bc)
  0519  2B            		dec	hl
  051A  66            		ld	h,(hl)
  051B  6F            		ld	l,a
  051C  38EA          		jr	c,SRCHLP2	;(hl,hl-1)<de
  051E  23            		inc	hl
  051F  2001          		jr	nz,SRCHEND	;(hl,hl-1)>de
  0521  37            		scf
  0522                	SRCHEND:
  0522  2B            		dec	hl
  0523  0B            		dec	bc
  0524  2B            		dec	hl
  0525  C9            		ret
                      	
                      	
                      	;convert to intermediate language
                      	;input: hl=INPBUF-1
  0526                	CNVIL:
  0526  54            		ld	d,h
  0527  5D            		ld	e,l
                      	
  0528                	ILLP1:
  0528  13            		inc	de
  0529  1A            		ld	a,(de)
                      	
  052A  B7            		or	a
  052B  FA2805        		jp	m,ILLP1		;skip kana
                      	
  052E  23            		inc	hl
  052F  2827          		jr	z,ILEND1	;00=line end
                      	
  0531  CDE00B        		call	CHKFIG
  0534  3818          		jr	c,ILPUT
                      	
  0536  FE22          		cp	22h		;double quotation mark
  0538  2817          		jr	z,ILDQ
  053A  FE14          		cp	14h
  053C  280C          		jr	z,ILGRP
  053E  FE2A          		cp	'*'
  0540  380C          		jr	c,ILPUT		;00h-29h
  0542  FE3F          		cp	'?'
  0544  203F          		jr	nz,ILCMP
                      	
                      	;question mark
  0546  3695          		ld	(hl),PRINT_	;95h
  0548  18DE          		jr	ILLP1
                      	
                      	;graphic character
  054A                	ILGRP:
  054A  77            		ld	(hl),a
  054B  23            		inc	hl
  054C  13            		inc	de
  054D  1A            		ld	a,(de)
  054E                	ILPUT:
  054E  77            		ld	(hl),a
  054F  18D7          		jr	ILLP1
                      	
                      	
                      	;double quotation mark
  0551                	ILDQ:
  0551  77            		ld	(hl),a
                      	
                      	;REM
  0552                	ILREM:
  0552  4F            		ld	c,a		;double quotation mark or 0(REM)
  0553  0601          		ld	b,01h		;double quotation counter
                      	
                      	;REM,DATA,""
                      	;loop until (de)=0 or (de)=c
  0555                	ILLP2:
  0555  13            		inc	de
  0556  23            		inc	hl
  0557  1A            		ld	a,(de)
  0558                	ILEND1:
  0558  77            		ld	(hl),a
  0559  B7            		or	a
  055A  280E          		jr	z,ILEND2
  055C  FE22          		cp	22h
  055E  2001          		jr	nz,ILNZ
  0560  04            		inc	b
  0561                	ILNZ:
  0561  CB40          		bit	0,b
  0563  20F0          		jr	nz,ILLP2
  0565  B9            		cp	c
  0566  20ED          		jr	nz,ILLP2
  0568  18BE          		jr	ILLP1
                      	
  056A                	ILEND2:
  056A  23            		inc	hl
  056B  77            		ld	(hl),a		;a=0
  056C  23            		inc	hl
  056D  77            		ld	(hl),a		;a=0
  056E  C9            		ret
                      	
                      	;found
  056F                	ILFOUND:
  056F  F1            		pop	af		;cancel
  0570  E1            		pop	hl
  0571  70            		ld	(hl),b
  0572  78            		ld	a,b
  0573  D68E          		sub	REM_
  0575  28DB          		jr	z,ILREM
  0577  FEF5          		cp	DATA_-REM_
  0579  20AD          		jr	nz,ILLP1
                      	
                      	;DATA
  057B                	ILDAT:
  057B  013A00        		ld	bc,003ah	;b=0, c=':'
  057E  18D5          		jr	ILLP2
                      	
                      	
                      	;not found
  0580                	ILNC:
  0580  E1            		pop	hl
  0581  1A            		ld	a,(de)
  0582  77            		ld	(hl),a
  0583  18A3          		jr	ILLP1
                      	
                      	;compare with command string
  0585                	ILCMP:
  0585  CDEF0B        		call	TOUPPER
  0588  12            		ld	(de),a
                      	
  0589  E5            		push	hl
  058A  212A02        		ld	hl,CMDNAME
  058D  0680          		ld	b,80h
                      	
  058F                	ILLP3:
  058F  1A            		ld	a,(de)
  0590  F680          		or	80h
  0592  BE            		cp	(hl)
  0593  2018          		jr	nz,ILLP6
                      	
                      	;1st character matched
  0595  D5            		push	de
  0596                	ILLP4:
  0596  23            		inc	hl
  0597  7E            		ld	a,(hl)
  0598  07            		rlca
  0599  38D4          		jr	c,ILFOUND
                      	
  059B  78            		ld	a,b
  059C  FE88          		cp	GOTO_
  059E                	ILLP5:
  059E  13            		inc	de
  059F  1A            		ld	a,(de)
  05A0  2004          		jr	nz,NOGOTO
  05A2  FE20          		cp	' '
  05A4  28F8          		jr	z,ILLP5
  05A6                	NOGOTO:
  05A6  CDEF0B        		call	TOUPPER
  05A9  BE            		cp	(hl)
  05AA  28EA          		jr	z,ILLP4
  05AC  D1            		pop	de
                      	
  05AD                	ILLP6:
  05AD  23            		inc	hl
  05AE  7E            		ld	a,(hl)
  05AF  07            		rlca
  05B0  30FB          		jr	nc,ILLP6
  05B2  04            		inc	b
                      	
  05B3  78            		ld	a,b
  05B4  FEF2          		cp	FNCLAST+1
  05B6  30C8          		jr	nc,ILNC
  05B8  FEAB          		cp	CMDLAST+1
  05BA  20D3          		jr	nz,ILLP3
  05BC  06C2          		ld	b,TAB_
  05BE  18CF          		jr	ILLP3
                      	
                      	
                      	;LLIST command
  05C0                	C_LLST:
  05C0  3E01          		ld	a,01h
  05C2  3258FA        		ld	(DEVICE),a
                      	;	jp	C_LIST
                      	
                      	
                      	;LIST command
  05C5                	C_LIST:
  05C5  F1            		pop	af		;cancel return address
  05C6  110000        		ld	de,0000h
  05C9  CD5E3F        		call	CHKCLN
  05CC  2814          		jr	z,LISTTOEND
                      	
  05CE  CD6807        		call	GETLN
  05D1  D5            		push	de		;start line number
  05D2  CD5E3F        		call	CHKCLN
  05D5  281D          		jr	z,LISTSTRT
                      	
  05D7  FECB          		cp	MINUS_
  05D9  C2DC03        		jp	nz,SNERR
  05DC  CD5D3F        		call	CHKCLNINC
  05DF  2007          		jr	nz,LISTNZ
  05E1  D1            		pop	de
  05E2                	LISTTOEND:
  05E2  01FAFF        		ld	bc,65530
  05E5  C5            		push	bc
  05E6  180C          		jr	LISTSTRT
                      	
  05E8                	LISTNZ:
  05E8  CD6807        		call	GETLN
  05EB  CD5E3F        		call	CHKCLN
  05EE  C2DC03        		jp	nz,SNERR
                      	
  05F1  E1            		pop	hl
  05F2  D5            		push	de		;push end line number
  05F3  EB            		ex	de,hl		;de <- start line number
                      	
                      	
                      	;de=start line number, (sp)=end line number
  05F4                	LISTSTRT:
  05F4  CDF304        		call	SRCHLN
  05F7  60            		ld	h,b
  05F8  69            		ld	l,c
                      	
  05F9                	LISTLP1:
  05F9  CD4D27        		call	STOPESC
                      	
  05FC  23            		inc	hl
  05FD  7E            		ld	a,(hl)
  05FE  23            		inc	hl
  05FF  B6            		or	(hl)
  0600  2843          		jr	z,LISTEND2
                      	
  0602  CD3927        		call	PUTNL
                      	
  0605  D1            		pop	de		;end line number
  0606  D5            		push	de
                      	
  0607  23            		inc	hl
  0608  7E            		ld	a,(hl)
  0609  23            		inc	hl
  060A  E5            		push	hl
  060B  66            		ld	h,(hl)
  060C  6F            		ld	l,a
                      	
  060D  13            		inc	de
  060E  E7            		rst	CPHLDE
  060F  3033          		jr	nc,LISTEND
                      	
  0611  CDA13A        		call	PUTI2
  0614  3E20          		ld	a,' '
  0616  CDC726        		call	PUTDEV
                      	
  0619  E1            		pop	hl
                      	
  061A  110000        		ld	de,0000h	;double quotation mark and DATA counter
  061D  4B            		ld	c,e		;REM counter
  061E                	LISTLP3:
  061E  23            		inc	hl
  061F  7E            		ld	a,(hl)
  0620  B7            		or	a
  0621  28D6          		jr	z,LISTLP1
                      	
  0623  FE22          		cp	22h
  0625  2822          		jr	z,LISTDQ
                      	
  0627  CB42          		bit	0,d
  0629  2014          		jr	nz,LISTPUT
                      	
  062B  1C            		inc	e
  062C  1D            		dec	e
  062D  201D          		jr	nz,LISTCHKCLN
                      	
  062F  0C            		inc	c
  0630  0D            		dec	c
  0631  200C          		jr	nz,LISTPUT
                      	
  0633  FE8E          		cp	REM_
  0635  281C          		jr	z,LISTREM
  0637  FE83          		cp	DATA_
  0639  2819          		jr	z,LISTDATA
  063B  B7            		or	a
  063C  FA5506        		jp	m,LISTCMD
  063F                	LISTPUT:
  063F  CDC726        		call	PUTDEV
  0642  18DA          		jr	LISTLP3
                      	
  0644                	LISTEND:
  0644  F1            		pop	af		;cancel stack
  0645                	LISTEND2:
  0645  F1            		pop	af		;cancel stack
  0646  C34204        		jp	EDIT
                      	
  0649                	LISTDQ:
  0649  14            		inc	d
  064A  18F3          		jr	LISTPUT
                      	
  064C                	LISTCHKCLN:
  064C  FE3A          		cp	':'
  064E  20EF          		jr	nz,LISTPUT
  0650  1D            		dec	e
  0651  18EC          		jr	LISTPUT
                      	
  0653                	LISTREM:
  0653  0C            		inc	c
  0654                	LISTDATA:
  0654  1C            		inc	e
  0655                	LISTCMD:
  0655  E5            		push	hl
  0656  CDB525        		call	CNVASC
                      	
  0659                	LISTLP4:
  0659  CDC726        		call	PUTDEV
  065C  23            		inc	hl
  065D  7E            		ld	a,(hl)
  065E  B7            		or	a
  065F  F25906        		jp	p,LISTLP4
  0662  E1            		pop	hl
  0663  18B9          		jr	LISTLP3
                      	
                      	
                      	;FOR command
  0665                	C_FOR:
  0665  F1            		pop	af		;cancel return address
  0666  CD8F33        		call	CHKVAR
  0669  7E            		ld	a,(hl)
  066A  FE28          		cp	'('
  066C  CADC03        		jp	z,SNERR
                      	
  066F  CDA932        		call	GETVAR
  0672  2A4EFF        		ld	hl,(PROGAD)
                      	
  0675  D5            		push	de		;variable address
                      	
  0676  CD0408        		call	VARIN
  0679  CD9B0B        		call	CHKNUM
  067C  7E            		ld	a,(hl)
  067D  FEC3          		cp	TO_
  067F  C2DC03        		jp	nz,SNERR
  0682  CD910B        		call	NARGMOINC
  0685  EB            		ex	de,hl
  0686  CD2539        		call	PUSHF1		;TO value
  0689  EB            		ex	de,hl
  068A  CD5E3F        		call	CHKCLN		;a=(hl)
  068D  224EFF        		ld	(PROGAD),hl
  0690  CC6422        		call	z,SETPLS1	;no change in z-flag
  0693  2808          		jr	z,STEP1
  0695  FEC9          		cp	STEP_
  0697  C2DC03        		jp	nz,SNERR
  069A  CD910B        		call	NARGMOINC
  069D                	STEP1:
  069D  CD4339        		call	POPF2		;TO value
  06A0  C1            		pop	bc		;variable address
                      	
  06A1  2A4EFF        		ld	hl,(PROGAD)
  06A4  E5            		push	hl		;program address
  06A5  210200        		ld	hl,0002h
  06A8  39            		add	hl,sp
  06A9                	FORLP:
  06A9  CDD507        		call	SRCHSTK2
  06AC  280F          		jr	z,FOROK		;not found or gosub identifier found
                      	
                      	;check program address
  06AE  111100        		ld	de,0011h
  06B1  19            		add	hl,de
  06B2  5E            		ld	e,(hl)
  06B3  23            		inc	hl
  06B4  56            		ld	d,(hl)
  06B5  23            		inc	hl
  06B6  E3            		ex	(sp),hl
  06B7  E7            		rst	CPHLDE
  06B8  E3            		ex	(sp),hl
  06B9  20EE          		jr	nz,FORLP
                      	
  06BB  F9            		ld	sp,hl
  06BC  D5            		push	de		;program address
                      	
  06BD                	FOROK:
  06BD  2A5DFA        		ld	hl,(LINENUM)
  06C0  E5            		push	hl		;line number
  06C1  CD1A3C        		call	PUSHF2		;TO value
  06C4  CD2539        		call	PUSHF1		;STEP value
  06C7  C5            		push	bc		;variable address
  06C8  3E81          		ld	a,FOR_		;identifier
  06CA  F5            		push	af
  06CB  33            		inc	sp
  06CC  1819          		jr	INTPEND
                      	
                      	
                      	;
                      	;
                      	;
                      	;
  06CE                	_COMMAND:ds	CMDEND-14-_COMMAND
  06DC                		org	CMDEND-14
                      	
                      	;execute command
  06DC                	COMMAND:
  06DC  FEAB          		cp	CMDLAST+1	;abh
  06DE  D2DC03        		jp	nc,SNERR
  06E1  1161FA        		ld	de,CMDTBL
  06E4  CD473F        		call	JPTBL
                      	
                      	;intepretation end
  06E7                	INTPEND:
  06E7  2A4EFF        		ld	hl,(PROGAD)
                      	
                      	;command end
  06EA                	_CMDEND:ds	CMDEND-_CMDEND
  06EA                		org	CMDEND
                      	
  06EA  2B            		dec	hl
  06EB  D7            		rst	ANADAT
                      	
                      	;	call	CHKCLN
                      	
  06EC  CA0A07        		jp	z,INTPRT
  06EF  C3DC03        		jp	SNERR
                      	
                      	
  06F2                	RUNLP:
  06F2  7E            		ld	a,(hl)
  06F3  23            		inc	hl
  06F4  B6            		or	(hl)
  06F5  CA4204        		jp	z,EDIT
  06F8  23            		inc	hl
  06F9  5E            		ld	e,(hl)
  06FA  23            		inc	hl
  06FB  56            		ld	d,(hl)
  06FC  ED535DFA      		ld	(LINENUM),de
  0700  C30907        		jp	INTPRT2
                      	
                      	
                      	;0709h: used by PORTOPIA
  0703                	_INTPRT2:ds	INTPRT2-_INTPRT2
  0709                		org	INTPRT2
                      	
  0709  23            		inc	hl
                      	
  070A                	INTPRT:
  070A  CD5B27        		call	CHKSTOP
  070D  CA3735        		jp	z,STOP1
  0710  7E            		ld	a,(hl)
  0711  23            		inc	hl
  0712  224EFF        		ld	(PROGAD),hl
  0715  B7            		or	a
  0716  FADC06        		jp	m,COMMAND
  0719  28D7          		jr	z,RUNLP
  071B  FE3A          		cp	':'
  071D  28EB          		jr	z,INTPRT
  071F  FE20          		cp	' '
  0721  28E7          		jr	z,INTPRT
  0723  2B            		dec	hl
  0724  CDFB07        		call	C_LET
  0727  18BE          		jr	INTPEND
                      	
                      	
                      	;continued from C_RUN
                      	;RUN with parameter
  0729                	RUNPAR:
  0729  CDF934        		call	RESSTK
  072C  2A4EFF        		ld	hl,(PROGAD)
  072F  CDA607        		call	C_GOTO
  0732  60            		ld	h,b
  0733  69            		ld	l,c
  0734  23            		inc	hl
  0735  18BB          		jr	RUNLP
                      	
                      	
                      	;convert float to 2-byte integer for USR() [-32768,32767]
                      	;input: FAC1
                      	;output: de
                      	;destroy: af,bc,hl
  0737                	_FTOI2:	ds	FTOI2-_FTOI2
  0741                		org	FTOI2
                      	
  0741  CD9F0C        		call	FTOI
  0744  3A69FF        		ld	a,(FAC1+3)
  0747  AA            		xor	d
  0748  F0            		ret	p
  0749  C3E503        		jp	FCERR
                      	
                      	
                      	;convert float to 1-byte integer [0,255]
                      	;input: FAC1
                      	;output: e, a(0=ok)
                      	;destroy: f,bc,de,hl
  074C                	FTOI1:
  074C  CD4107        		call	FTOI2
  074F  7A            		ld	a,d
  0750  B7            		or	a
  0751  C8            		ret	z
  0752  C3E503        		jp	FCERR
                      	
                      	
                      	;convert FAC1 and FAC2 to 2-byte integer
                      	;input: FAC1, FAC2
                      	;output: hl, de
                      	;destroy: af,bc,FAC1,FAC2
  0755                	F12TOI2:
  0755  3A25FF        		ld	a,(ARGTYP)
  0758  B7            		or	a
  0759  C2FD03        		jp	nz,TMERR
  075C  CD4107        		call	FTOI2
  075F  D5            		push	de		;
  0760  CD6539        		call	EXFAC
  0763  CD4107        		call	FTOI2
  0766  E1            		pop	hl		;
  0767  C9            		ret
                      	
                      	
                      	;get line number from string (0-65529)
                      	;input: hl=program address
                      	;output: de=line number, hl=next address
                      	;destroy: af,bc
  0768                	GETLN:
  0768  CDCA27        		call	ATOI2
  076B  E5            		push	hl
  076C  21F9FF        		ld	hl,65529
  076F  E7            		rst	CPHLDE
  0770  E1            		pop	hl
  0771  D0            		ret	nc
  0772  119919        		ld	de,6553
  0775                	GETLNLP:
  0775  2B            		dec	hl
  0776  7E            		ld	a,(hl)
  0777  FE20          		cp	' '
  0779  C0            		ret	nz
  077A  18F9          		jr	GETLNLP
                      	
                      	
                      	;RUN command
  077C                	_C_RUN:	ds	C_RUN-_C_RUN
  0781                		org	C_RUN
                      	
  0781  CD5E3F        		call	CHKCLN
  0784  20A3          		jr	nz,RUNPAR	;with parameter
  0786  CDF934        		call	RESSTK
  0789  2A5FFA        		ld	hl,(STARTAD)
  078C  C3F206        		jp	RUNLP
                      	
                      	
                      	;GOSUB command
  078F                	C_GSUB:
  078F  CDA607        		call	C_GOTO
  0792  2B            		dec	hl
  0793                	GSUBLP:
  0793  CD5D3F        		call	CHKCLNINC
  0796  20FB          		jr	nz,GSUBLP
                      	
  0798  E3            		ex	(sp),hl
  0799  E5            		push	hl
  079A  CDCC34        		call	CHKFRE
  079D  2A5DFA        		ld	hl,(LINENUM)
  07A0  E3            		ex	(sp),hl
  07A1  3E8C          		ld	a,GOSUB_
  07A3  F5            		push	af		;gosub identifier
  07A4  33            		inc	sp
  07A5                	JPHL:
  07A5  E9            		jp	(hl)
                      	
                      	
                      	;GOTO command
                      	;output: bc=new address, hl=old address (after line number)
  07A6                	C_GOTO:
  07A6  CD6807        		call	GETLN
  07A9  E5            		push	hl
  07AA  CDF304        		call	SRCHLN
  07AD  E1            		pop	hl
  07AE  D2EE03        		jp	nc,ULERR
  07B1  ED434EFF      		ld	(PROGAD),bc
  07B5  C9            		ret
                      	
                      	
                      	;RETURN command
  07B6                	C_RET:
  07B6  C1            		pop	bc		;return address
  07B7                	RETLP:
  07B7  CDD107        		call	SRCHSTK
  07BA  D2DF03        		jp	nc,RGERR	;not found
  07BD  2807          		jr	z,RETOK		;gosub identifier found
  07BF  211300        		ld	hl,0013h
  07C2  39            		add	hl,sp
  07C3  F9            		ld	sp,hl
  07C4  18F1          		jr	RETLP
                      	
  07C6                	RETOK:
  07C6  33            		inc	sp
  07C7  E1            		pop	hl
  07C8  225DFA        		ld	(LINENUM),hl
  07CB  E1            		pop	hl
  07CC  224EFF        		ld	(PROGAD),hl
  07CF  C5            		push	bc		;return address
  07D0  C9            		ret
                      	
                      	
                      	;search stack for for/gosub identifier
                      	;output: c-flag(1=found), z-flag(0=for/1=gosub if found)
                      	;destroy: af,de,hl
  07D1                	SRCHSTK:
  07D1  210200        		ld	hl,0002h
  07D4  39            		add	hl,sp
                      	
                      	;search (hl)
                      	;destroy: af,de
  07D5                	SRCHSTK2:
  07D5  ED5B5BFA      		ld	de,(STACK)
  07D9  E7            		rst	CPHLDE
  07DA  D0            		ret	nc		;(z-flag=1)
  07DB  7E            		ld	a,(hl)
  07DC  FE8C          		cp	GOSUB_
  07DE  37            		scf
  07DF  C9            		ret
                      	
                      	
                      	;DATA command
  07E0                	_C_DATA:ds	C_DATA-_C_DATA
  07E0                		org	C_DATA
                      	
  07E0  013A          		db	01h, ':'	;ld bc,0e3ah/nop
                      	
                      	
                      	;REM command
  07E2                	_C_REM:	ds	C_REM-_C_REM
  07E2                		org	C_REM
                      	
  07E2  0E00          		ld	c,00h
                      	
                      	;input: c
  07E4                	DATREM:
  07E4  0600          		ld	b,00h
  07E6                	DATALP:
  07E6  7E            		ld	a,(hl)
  07E7  B7            		or	a
  07E8  CACB0B        		jp	z,SETPRGAD
                      	
  07EB  CB40          		bit	0,b
  07ED  2004          		jr	nz,DATANZ
  07EF  B9            		cp	c
  07F0  CACB0B        		jp	z,SETPRGAD
  07F3                	DATANZ:
  07F3  23            		inc	hl
  07F4  FE22          		cp	22h		;double quotation mark
  07F6  20EE          		jr	nz,DATALP
  07F8  04            		inc	b
  07F9  18EB          		jr	DATALP
                      	
                      	
                      	;LET command
  07FB                	C_LET:
  07FB  CD8F33        		call	CHKVAR
  07FE  CDA932        		call	GETVAR
  0801  2A4EFF        		ld	hl,(PROGAD)
                      	;	jp	VARIN
                      	
                      	
                      	;put into variable
                      	;input: bc=variable name, hl=program address, de=variable address
                      	;output: hl=next program address
                      	;destroy: FAC1,FAC2,af,bc,de
  0804                	VARIN:
  0804  CD573F        		call	SKIPSP
  0807  FED2          		cp	EQ_		;0d2h
  0809  C2DC03        		jp	nz,SNERR
                      	
  080C  D5            		push	de		;variable address
  080D  23            		inc	hl
  080E  CB79          		bit	7,c
  0810  2814          		jr	z,VARNUM
                      	
                      	;string
  0812  CD8126        		call	STRARG
  0815  47            		ld	b,a
  0816  7A            		ld	a,d
  0817  FEFA          		cp	0fah		;fa00h=work area start address
  0819  78            		ld	a,b
  081A  EB            		ex	de,hl
  081B  D44227        		call	nc,MAKESTR
  081E  212DFF        		ld	hl,STRDSC1
  0821  010400        		ld	bc,0004h
  0824  1809          		jr	VARINOK
                      	
  0826                	VARNUM:
  0826  CD920B        		call	NARGMO
  0829  2166FF        		ld	hl,FAC1
  082C  010500        		ld	bc,0005h
  082F                	VARINOK:
  082F  D1            		pop	de		;variable address
  0830  EDB0          		ldir
  0832  2A4EFF        		ld	hl,(PROGAD)
  0835  C9            		ret
                      	
                      	
                      	;ON command
  0836                	C_ON:
  0836  CDE40D        		call	INT1ARG
  0839  7E            		ld	a,(hl)
  083A  57            		ld	d,a		;
  083B  F604          		or	04h
  083D  FE8C          		cp	GOSUB_		;88h(GOTO) or 8ch(GOSUB)
  083F  C2DC03        		jp	nz,SNERR
                      	
  0842                	ONLP:
  0842  23            		inc	hl
  0843  1D            		dec	e
  0844  280E          		jr	z,ONZ
  0846  D5            		push	de
  0847  CD6807        		call	GETLN
  084A  224EFF        		ld	(PROGAD),hl
  084D  D1            		pop	de
  084E  7E            		ld	a,(hl)
  084F  FE2C          		cp	','
  0851  28EF          		jr	z,ONLP
  0853  C9            		ret
                      	
  0854                	ONZ:
  0854  F1            		pop	af		;cancel return address
  0855  7A            		ld	a,d		;
  0856  C3DC06        		jp	COMMAND
                      	
                      	
                      	;IF command
  0859                	C_IF:
  0859  CD920B        		call	NARGMO
  085C  7E            		ld	a,(hl)
  085D  FEC7          		cp	THEN_
  085F  2805          		jr	z,IFOK
  0861  FE88          		cp	GOTO_
  0863  C2DC03        		jp	nz,SNERR
  0866                	IFOK:
  0866  3A6AFF        		ld	a,(FAC1+4)
  0869  B7            		or	a
  086A  CAE207        		jp	z,C_REM
                      	;	call	SKIPSPINC
                      	;	sub	'0'
                      	;	cp	'9'-'0'+1
                      	
  086D  D7            		rst	ANADAT
                      	
  086E  DAA607        		jp	c,C_GOTO
  0871                	IFEND:
  0871  F1            		pop	af		;cancel return address
  0872  C30A07        		jp	INTPRT		;skip colon check
                      	
                      	
                      	;LPRINT command
  0875                	_C_LPRT:ds	C_LPRT-_C_LPRT
  087A                		org	C_LPRT
                      	
  087A  3E01          		ld	a,01h
  087C  1806          		jr	PRTDEV
                      	
                      	
                      	;PRINT command
  087E                	_C_PRT:	ds	C_PRT-_C_PRT
  087E                		org	C_PRT
                      	
  087E  CDAEFF        		call	HOOKPRT
  0881  CD9F27        		call	DEVNUM
  0884                	PRTDEV:
  0884  3258FA        		ld	(DEVICE),a
  0887  07            		rlca
  0888  DCA825        		call	c,PRTOPN
                      	
  088B                	PRTLP1:
  088B  CD5E3F        		call	CHKCLN		;a=(hl)
  088E  CA4809        		jp	z,PRTEOL
  0891                	PRTLP2:
  0891  23            		inc	hl
  0892  FE3B          		cp	';'
  0894  284C          		jr	z,PRTNEXT
  0896  FE2C          		cp	','
  0898  2842          		jr	z,PRTCMM
  089A  FEC5          		cp	SPC_
  089C  2879          		jr	z,SPCTAB
  089E  D6C2          		sub	TAB_
  08A0  2875          		jr	z,SPCTAB
                      	
  08A2  2B            		dec	hl
  08A3  CD2C17        		call	ARG
  08A6  3A25FF        		ld	a,(ARGTYP)
  08A9  B7            		or	a
  08AA  2813          		jr	z,PRTNUM
                      	
                      	;string
  08AC  CD8A26        		call	STRARG2
  08AF  2A4EFF        		ld	hl,(PROGAD)
  08B2  B7            		or	a
  08B3  28D6          		jr	z,PRTLP1
  08B5  47            		ld	b,a
  08B6                	PRTSLP:
  08B6  1A            		ld	a,(de)
  08B7  13            		inc	de
  08B8  CDC726        		call	PUTDEV
  08BB  10F9          		djnz	PRTSLP
  08BD  18CC          		jr	PRTLP1
                      	
  08BF                	PRTNUM:
  08BF  E5            		push	hl
  08C0  CDAC3A        		call	FTOA
                      	
  08C3  3AACFD        		ld	a,(WIDTH)
  08C6  C603          		add	a,03h
  08C8  4F            		ld	c,a
  08C9  AF            		xor	a
  08CA  EDB1          		cpir
  08CC  3AA9FD        		ld	a,(CSRX)
  08CF  B9            		cp	c
  08D0  D43927        		call	nc,PUTNL
  08D3  2172FF        		ld	hl,FAC3
  08D6  CDCF30        		call	PUTS
  08D9  E1            		pop	hl
  08DA  18AF          		jr	PRTLP1
                      	
  08DC                	PRTCMM:
  08DC  CDE908        		call	CMMMAIN
  08DF  D43927        		call	nc,PUTNL
                      	
  08E2                	PRTNEXT:
  08E2  CD5E3F        		call	CHKCLN
  08E5  20AA          		jr	nz,PRTLP2
  08E7  1862          		jr	PRTEND
                      	
  08E9                	CMMMAIN:
  08E9  1E0E          		ld	e,0eh
  08EB  3A58FA        		ld	a,(DEVICE)
  08EE  B7            		or	a
  08EF  280E          		jr	z,CMM0
  08F1  3D            		dec	a
  08F2  201F          		jr	nz,CMM2
                      	
                      	;printer
  08F4                	CMM1:
  08F4  0608          		ld	b,08h
  08F6                	TAB1:
  08F6  3A57FA        		ld	a,(PRTPOS)
  08F9                	TABLP:
  08F9  93            		sub	e
  08FA  380B          		jr	c,PUTSPNEG
  08FC  10FB          		djnz	TABLP
  08FE  C9            		ret
                      	
                      	;CRT
  08FF                	CMM0:
  08FF  0601          		ld	b,01h
  0901                	TAB0:
  0901  3AA9FD        		ld	a,(CSRX)
  0904  3D            		dec	a
  0905  18F2          		jr	TABLP
                      	
  0907                	PUTSPNEG:
  0907  ED44          		neg
  0909                	PUTSP:
  0909  47            		ld	b,a
  090A                	PUTSPLP:
  090A  3E20          		ld	a,' '
  090C  CDC726        		call	PUTDEV
  090F  10F9          		djnz	PUTSPLP
  0911  37            		scf
  0912  C9            		ret
                      	
  0913                	CMM2:
                      	;RS-232C,CMT
  0913  060E          		ld	b,0eh
  0915  18F3          		jr	PUTSPLP
                      	
  0917                	SPCTAB:
  0917  CD1C09        		call	SPCTABMAIN
  091A  18C6          		jr	PRTNEXT
                      	
  091C                	SPCTABMAIN:
  091C  F5            		push	af		;00=tab
  091D  CD890B        		call	FNCNUMR
  0920  E5            		push	hl
  0921  CD4C07        		call	FTOI1
  0924  E1            		pop	hl
  0925  F1            		pop	af
  0926  B7            		or	a
  0927  200B          		jr	nz,PRTSPC
                      	
  0929                	PRTTAB:
  0929  0601          		ld	b,01h
  092B  3A58FA        		ld	a,(DEVICE)
  092E  B7            		or	a
  092F  28D0          		jr	z,TAB0		;0=CRT
  0931  3D            		dec	a
  0932  28C2          		jr	z,TAB1		;1=printer
                      	
  0934                	PRTSPC:
  0934  7B            		ld	a,e
  0935  B7            		or	a
  0936  20D1          		jr	nz,PUTSP
  0938  C9            		ret
                      	
                      	
                      	;change to text screen and print new line in CRT
                      	;if (CSRX)>1 then print new line
  0939                	PRTNLXTXT:
  0939  CD7213        		call	CHGTXT
  093C                	PRTNLX:
  093C  AF            		xor	a
  093D  3258FA        		ld	(DEVICE),a
  0940  3AA9FD        		ld	a,(CSRX)
  0943  3D            		dec	a
  0944  C8            		ret	z
  0945  C33927        		jp	PUTNL
                      	
                      	
  0948                	PRTEOL:
                      	;	xor	a
                      	;	ld	(GRPFLG),a
  0948  CD3927        		call	PUTNL
                      	
  094B                	PRTEND:
  094B  224EFF        		ld	(PROGAD),hl
                      	
                      	;print# and input# end
                      	;destroy: af,hl
  094E                	_PIEND:	ds	PIEND-_PIEND
  0955                		org	PIEND
                      	
  0955  CD8AFF        		call	HOOKPED
  0958  2158FA        		ld	hl,DEVICE
  095B  7E            		ld	a,(hl)
  095C  3600          		ld	(hl),00h
  095E  07            		rlca
  095F  D0            		ret	nc
  0960  C3061B        		jp	WCLOSE
                      	
                      	
  0963                	REDO:
  0963  3F5265646F2066		db	"?Redo from start", 0dh, 0ah, 00h
                      	
                      	;input: a=input(0)/read(>0), hl=input address
                      	;output: a=length, hl=next address, bc=start address
                      	;destroy: af,bc
  0976                	INPRDSTR:
  0976  3249FF        		ld	(INPRD),a
  0979  0600          		ld	b,00h		;length
  097B  CD573F        		call	SKIPSP
  097E  FE22          		cp	22h
  0980  200E          		jr	nz,IRSNDQ	;no double quotation
                      	
                      	;with double quotation
  0982  23            		inc	hl
  0983  E5            		push	hl
  0984                	IRSLP1:
  0984  7E            		ld	a,(hl)
  0985  B7            		or	a
  0986  281F          		jr	z,IRSEND
  0988  23            		inc	hl
  0989  FE22          		cp	22h
  098B  281A          		jr	z,IRSEND
  098D  04            		inc	b
                      	;	jp	z,LSERR
  098E  18F4          		jr	IRSLP1
                      	
                      	;no double quotation
  0990                	IRSNDQ:
  0990  E5            		push	hl
  0991                	IRSLP2:
  0991  7E            		ld	a,(hl)
  0992  B7            		or	a
  0993  2812          		jr	z,IRSEND
  0995  FE2C          		cp	','
  0997  280E          		jr	z,IRSEND
  0999  FE3A          		cp	':'
  099B  2006          		jr	nz,IRSNZ
  099D  3A49FF        		ld	a,(INPRD)
  09A0  B7            		or	a
  09A1  2004          		jr	nz,IRSEND		;READ
  09A3                	IRSNZ:
  09A3  23            		inc	hl
  09A4  04            		inc	b
                      	;	jp	z,LSERR
  09A5  18EA          		jr	IRSLP2
                      	
  09A7                	IRSEND:
  09A7  78            		ld	a,b
  09A8  C1            		pop	bc
  09A9  C9            		ret
                      	
                      	
                      	;INPUT command
  09AA                	C_INPT:
  09AA  7C            		ld	a,h
  09AB  FEFA          		cp	0fah
  09AD  D2FA03        		jp	nc,IDERR
  09B0  2B            		dec	hl
  09B1  2254FF        		ld	(STOPAD),hl
  09B4  23            		inc	hl
                      	
  09B5  CDBAFF        		call	HOOKINP
  09B8  CD9F27        		call	DEVNUM
  09BB  321AFA        		ld	(INPDEV),a
  09BE  3D            		dec	a
  09BF  CAE503        		jp	z,FCERR		;printer
  09C2  3C            		inc	a
  09C3  2022          		jr	nz,INPTSTRT
                      	
                      	;INPUT #0,
  09C5  CD7213        		call	CHGTXT
  09C8  CD573F        		call	SKIPSP
  09CB  FE22          		cp	22h		;double quotation mark
  09CD  2018          		jr	nz,INPTSTRT
                      	
  09CF                	PROMPT:
  09CF  23            		inc	hl
  09D0  7E            		ld	a,(hl)
  09D1  B7            		or	a
  09D2  CADC03        		jp	z,SNERR
  09D5  FE22          		cp	22h		;double quotation mark
  09D7  2805          		jr	z,PROMPTEND
  09D9  CD7510        		call	PRTC
  09DC  18F1          		jr	PROMPT
                      	
  09DE                	PROMPTEND:
  09DE  CD563F        		call	SKIPSPINC
  09E1  FE3B          		cp	';'
  09E3  C2DC03        		jp	nz,SNERR
  09E6  23            		inc	hl
                      	
  09E7                	INPTSTRT:
  09E7  E5            		push	hl		;program address (push for "?Redo from start")
                      	
  09E8                	INPTMAIN:
  09E8  224EFF        		ld	(PROGAD),hl
  09EB  3A1AFA        		ld	a,(INPDEV)
  09EE  B7            		or	a
  09EF  2011          		jr	nz,INPTEXT
                      	
  09F1  CD0529        		call	INPT1
                      	
  09F4  D1            		pop	de		;program address
  09F5  C1            		pop	bc		;return address
  09F6  DA3F35        		jp	c,STOP3
  09F9  C5            		push	bc		;return address
  09FA  D5            		push	de		;program address
                      	
  09FB  3EFF          		ld	a,0ffh
  09FD  3255FF        		ld	(STOPAD+1),a
  0A00  180C          		jr	INPTANA
                      	
                      	;input from external device
                      	;input: a=(INPDEV), hl=INPBUF-1
                      	;destroy: af,bc,de,hl
  0A02                	INPTEXT:
  0A02  07            		rlca
  0A03  F5            		push	af		;c-flag=0:RS-232C, 1=CMT
  0A04  DC9A25        		call	c,INPOPN
  0A07  CD9B0A        		call	INPT1EX
  0A0A  F1            		pop	af
  0A0B  DCAA1A        		call	c,RCLOSE
                      	;	jr	INPTANA
                      	
                      	;analyze input buffer
  0A0E                	INPTANA:
  0A0E  11DAFE        		ld	de,INPBUF
  0A11  2A4EFF        		ld	hl,(PROGAD)
  0A14                	INPTLP:
  0A14  CD8F33        		call	CHKVAR
  0A17  224EFF        		ld	(PROGAD),hl
  0A1A  3ADAFE        		ld	a,(INPBUF)
  0A1D  B7            		or	a
  0A1E  283D          		jr	z,INPTNEXT	;if no input, no change in varible
  0A20  D5            		push	de		;input buffer
  0A21  CDA932        		call	GETVAR
  0A24  E1            		pop	hl		;input buffer
  0A25  CB79          		bit	7,c
  0A27  2005          		jr	nz,INPTSTR
                      	
  0A29                	INPTNUM:
  0A29  CD780B        		call	INPRDNUM
  0A2C  1815          		jr	INPTERR
                      	
  0A2E                	INPTSTR:
  0A2E  AF            		xor	a
  0A2F  CD7609        		call	INPRDSTR
  0A32  E5            		push	hl		;input buffer
  0A33  60            		ld	h,b
  0A34  69            		ld	l,c
  0A35  D5            		push	de		;variable address
  0A36  CD4227        		call	MAKESTR
  0A39  D1            		pop	de		;variable address
  0A3A  212DFF        		ld	hl,STRDSC1
  0A3D  010400        		ld	bc,0004h
  0A40  EDB0          		ldir
  0A42  E1            		pop	hl		;input buffer
                      	
  0A43                	INPTERR:
  0A43  CD5E3F        		call	CHKCLN		;for compatibility with N6X-BASIC
  0A46  EB            		ex	de,hl
  0A47  2814          		jr	z,INPTNEXT
  0A49  FE2C          		cp	','
  0A4B  2810          		jr	z,INPTNEXT
  0A4D  3A1AFA        		ld	a,(INPDEV)
  0A50  B7            		or	a
  0A51  C21504        		jp	nz,FDERR
  0A54  216309        		ld	hl,REDO
  0A57  CDCF30        		call	PUTS
  0A5A  E1            		pop	hl		;program address
  0A5B  188A          		jr	INPTSTRT
                      	
  0A5D                	INPTNEXT:
  0A5D  2A4EFF        		ld	hl,(PROGAD)
  0A60  7E            		ld	a,(hl)
  0A61  FE2C          		cp	','
  0A63  201C          		jr	nz,INPTEND
                      	
                      	;comma
  0A65  23            		inc	hl
  0A66  3ADAFE        		ld	a,(INPBUF)
  0A69  B7            		or	a
  0A6A  28A8          		jr	z,INPTLP
  0A6C  1A            		ld	a,(de)
  0A6D  13            		inc	de
  0A6E  FE2C          		cp	','
  0A70  28A2          		jr	z,INPTLP
  0A72  3A1AFA        		ld	a,(INPDEV)
  0A75  B7            		or	a
  0A76  C2E203        		jp	nz,ODERR
  0A79  3E3F          		ld	a,'?'
  0A7B  CD7510        		call	PRTC
  0A7E  C3E809        		jp	INPTMAIN
                      	
                      	;not comma
  0A81                	INPTEND:
  0A81  F1            		pop	af		;cancel program address
  0A82  EB            		ex	de,hl
                      	;	jr	CHKEXTR
                      	
                      	;Extra ignored check?
                      	;used by EXAS BASIC compiler
                      	;input: hl=input buffer address
                      	;destroy: af,bc,de,hl
  0A83                	_CHKEXTR:ds	CHKEXTR-_CHKEXTR
  0A8F                		org	CHKEXTR
                      	
  0A8F  7E            		ld	a,(hl)
  0A90  B7            		or	a
  0A91  21D00A        		ld	hl,EXTRA
  0A94  C4CF30        		call	nz,PUTS
  0A97  C35509        		jp	PIEND
                      	
                      	
                      	;one line input for external device
                      	;used by EXAS BASIC compiler
                      	;output: hl=INPBUF-1
                      	;destroy: af,bc
  0A9A                	_INPT1EX:ds	INPT1EX-_INPT1EX
  0A9B                		org	INPT1EX
                      	
  0A9B  3A1AFA        		ld	a,(INPDEV)
  0A9E  07            		rlca
  0A9F  F5            		push	af		;c-flag=0:RS-232C, 1=CMT
  0AA0  21DAFE        		ld	hl,INPBUF
  0AA3  0647          		ld	b,71
  0AA5                	INPTEXTLP:
  0AA5  F1            		pop	af		;c-flag=0:RS-232C, 1=CMT
  0AA6  F5            		push	af
  0AA7  3822          		jr	c,INPTCMT
                      	
  0AA9                	INPT232:
  0AA9  E5            		push	hl
  0AAA                	INPT232LP:
  0AAA  3E37          		ld	a,37h
  0AAC  D381          		out	(81h),a
  0AAE  3A18FA        		ld	a,(STOPFLG)
  0AB1  FE03          		cp	03h
  0AB3  CA5127        		jp	z,STOPSP
  0AB6  CD4310        		call	GETRSBF
  0AB9  28EF          		jr	z,INPT232LP
  0ABB  E1            		pop	hl
                      	
  0ABC                	INPTCHKRET:
  0ABC  FE0D          		cp	0dh
  0ABE  2804          		jr	z,INPTEXTEND
  0AC0  77            		ld	(hl),a
  0AC1  23            		inc	hl
  0AC2  10E1          		djnz	INPTEXTLP
                      	
  0AC4                	INPTEXTEND:
  0AC4  F1            		pop	af
  0AC5  3600          		ld	(hl),00h
  0AC7  21D9FE        		ld	hl,INPBUF-1
  0ACA  C9            		ret
                      	
  0ACB                	INPTCMT:
  0ACB  CD8F1A        		call	GETCMTTR
  0ACE  18EC          		jr	INPTCHKRET
                      	
  0AD0                	EXTRA:
  0AD0  3F457874726120		db	"?Extra ignored", 0dh, 0ah, 00h
                      	
                      	
                      	;READ command
  0AE1                	C_READ:
  0AE1  CD8F33        		call	CHKVAR
  0AE4  CDA932        		call	GETVAR
  0AE7  C5            		push	bc		;variable name
  0AE8  D5            		push	de		;variable address
                      	
  0AE9  2A5CFF        		ld	hl,(DATAAD)
  0AEC  ED5B45FF      		ld	de,(DATALN)
  0AF0  7E            		ld	a,(hl)
  0AF1  FE2C          		cp	','
  0AF3  2847          		jr	z,READDATA
  0AF5  FE3A          		cp	':'
  0AF7  2810          		jr	z,READLP3
  0AF9  B7            		or	a
  0AFA  C2E203        		jp	nz,ODERR
                      	
  0AFD                	READLP1:
  0AFD  23            		inc	hl
  0AFE                	READLP2:
  0AFE  4F            		ld	c,a		;always a=0, double quation mark counter
  0AFF  7E            		ld	a,(hl)
  0B00  23            		inc	hl
  0B01  B6            		or	(hl)
  0B02  CAE203        		jp	z,ODERR
  0B05  23            		inc	hl
  0B06  5E            		ld	e,(hl)
  0B07  23            		inc	hl
  0B08  56            		ld	d,(hl)
                      	
  0B09                	READLP3:
  0B09  23            		inc	hl
  0B0A  7E            		ld	a,(hl)
  0B0B  B7            		or	a
  0B0C  28EF          		jr	z,READLP1
  0B0E  FE83          		cp	DATA_
  0B10  282A          		jr	z,READDATA
  0B12  FE22          		cp	22h		;double quotation mark
  0B14  281D          		jr	z,READDQ
  0B16  FE3A          		cp	':'
  0B18  28EF          		jr	z,READLP3
  0B1A  FE20          		cp	' '
  0B1C  28EB          		jr	z,READLP3
  0B1E  D68E          		sub	REM_
  0B20  2814          		jr	z,READREM
                      	
  0B22                	READLP4:
  0B22  23            		inc	hl
  0B23  7E            		ld	a,(hl)
  0B24  B7            		or	a
  0B25  28D6          		jr	z,READLP1
  0B27  CB41          		bit	0,c
  0B29  2004          		jr	nz,SKIPCLN
  0B2B  FE3A          		cp	':'
  0B2D  28DA          		jr	z,READLP3
  0B2F                	SKIPCLN:
  0B2F  FE22          		cp	22h		;double quotation mark
  0B31  20EF          		jr	nz,READLP4
  0B33                	READDQ:
  0B33  0C            		inc	c
  0B34  18EC          		jr	READLP4
                      	
                      	;a=0
  0B36                	READREM:
                      	;	xor	a
  0B36  47            		ld	b,a
  0B37  4F            		ld	c,a
  0B38  EDB1          		cpir
  0B3A  18C2          		jr	READLP2
                      	
  0B3C                	READDATA:
  0B3C  ED5345FF      		ld	(DATALN),de
  0B40  23            		inc	hl
  0B41  D1            		pop	de		;variable address
  0B42  C1            		pop	bc		;variable name
  0B43  CB79          		bit	7,c
  0B45  2005          		jr	nz,READSTR
                      	
  0B47                	READNUM:
  0B47  CD780B        		call	INPRDNUM
  0B4A  180C          		jr	READERR
                      	
                      	;de=variable address
  0B4C                	READSTR:
  0B4C  78            		ld	a,b		;>0
  0B4D  CD7609        		call	INPRDSTR
  0B50  12            		ld	(de),a
  0B51  13            		inc	de
  0B52  13            		inc	de
  0B53  79            		ld	a,c
  0B54  12            		ld	(de),a
  0B55  13            		inc	de
  0B56  78            		ld	a,b
  0B57  12            		ld	(de),a
                      	
                      	;error check
  0B58                	READERR:
  0B58  CD5E3F        		call	CHKCLN
  0B5B  280D          		jr	z,READNEXT
  0B5D  FE2C          		cp	','
  0B5F  2809          		jr	z,READNEXT
  0B61  2A45FF        		ld	hl,(DATALN)
  0B64  225DFA        		ld	(LINENUM),hl
  0B67  C3DC03        		jp	SNERR
                      	
  0B6A                	READNEXT:
  0B6A  225CFF        		ld	(DATAAD),hl
  0B6D  2A4EFF        		ld	hl,(PROGAD)
  0B70  7E            		ld	a,(hl)
  0B71  FE2C          		cp	','
  0B73  C0            		ret	nz
  0B74  23            		inc	hl
  0B75  C3E10A        		jp	C_READ
                      	
                      	
                      	;for INPUT/READ
                      	;input: de=variable adderss, hl=program address
  0B78                	INPRDNUM:
  0B78  D5            		push	de		;variable address
  0B79  CD9839        		call	ATOF
  0B7C  D1            		pop	de		;variable address
  0B7D  E5            		push	hl		;input buffer/data address
  0B7E  2166FF        		ld	hl,FAC1
  0B81  CD480C        		call	SETF
  0B84  E1            		pop	hl		;input buffer/data address
  0B85  C9            		ret
                      	
                      	
                      	;get a numerical argument for function
                      	;input: hl=program address
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  0B86                	FNCNUM:
  0B86  CDB50B        		call	CHKLPAR
  0B89                	FNCNUMR:
  0B89  CD2C17        		call	ARG
  0B8C  CDC40B        		call	CHKRPAR
  0B8F  180A          		jr	CHKNUM
                      	
                      	
                      	;get a numerical argument and check result (?MO Error)
                      	;input: hl=program address-1
                      	;output: FAC1, hl=next address
                      	;destroy: af,bc,de,FAC2
  0B91                	NARGMOINC:
  0B91  23            		inc	hl
                      	
                      	;get a numerical argument and check result (?MO Error)
                      	;input: hl=program address
                      	;output: FAC1, hl=next address
                      	;destroy: af,bc,de,FAC2
  0B92                	NARGMO:
  0B92  CD5E3F        		call	CHKCLN
  0B95  CA1204        		jp	z,MOERR
                      	;	call	NUMARG
                      	;	ret
                      	
                      	
                      	;get a numerical argument and check result
                      	;input: hl=program address
                      	;output: FAC1, hl=next address
                      	;destroy: af,bc,de,FAC2
  0B98                	NUMARG:
  0B98  CD2C17        		call	ARG
                      	;	call	CHKNUM
                      	;	ret
                      	
                      	
                      	;check numeric or not
                      	;output: z-flag (1=ok)
                      	;destroy: af
  0B9B                	CHKNUM:
  0B9B  3A25FF        		ld	a,(ARGTYP)
  0B9E  B7            		or	a
  0B9F  C8            		ret	z
  0BA0  3D            		dec	a
  0BA1                	CHKNERR:
  0BA1  CAFD03        		jp	z,TMERR
  0BA4  C3DC03        		jp	SNERR
                      	
                      	
                      	;check string argument or not
                      	;output: a=length, hl=string descriptor address, z-flag(1=ok)
                      	;destroy: f
  0BA7                	CHKSTR:
  0BA7  3A25FF        		ld	a,(ARGTYP)
  0BAA  3D            		dec	a
  0BAB  2005          		jr	nz,CHKSERR
  0BAD  2A67FF        		ld	hl,(FAC1+1)
  0BB0  7E            		ld	a,(hl)
  0BB1  C9            		ret
                      	
  0BB2                	CHKSERR:
  0BB2  3C            		inc	a
  0BB3  18EC          		jr	CHKNERR
                      	
                      	
                      	;check (
                      	;input: hl=program address
                      	;output: hl=next address
                      	;destroy: af
  0BB5                	CHKLPAR:
  0BB5  CD573F        		call	SKIPSP
  0BB8  FE28          		cp	'('
  0BBA  C2DC03        		jp	nz,SNERR
  0BBD  CD5D3F        		call	CHKCLNINC
  0BC0  C0            		ret	nz
  0BC1  C31204        		jp	MOERR
                      	
                      	
                      	;check )
                      	;input: hl=program address
                      	;output: hl=next address
                      	;destroy: af
  0BC4                	CHKRPAR:
  0BC4  7E            		ld	a,(hl)
  0BC5  FE29          		cp	')'
  0BC7  C2DC03        		jp	nz,SNERR
  0BCA  23            		inc	hl
  0BCB                	SETPRGAD:
  0BCB  224EFF        		ld	(PROGAD),hl
  0BCE  C9            		ret
                      	
                      	
                      	;alphabet, numeral, or katakana? (case ignored)
  0BCF                	ALPNUM2:
  0BCF  FEE0          		cp	0e0h
  0BD1  3F            		ccf
  0BD2  D8            		ret	c
  0BD3  FEA1          		cp	0a1h
  0BD5  D0            		ret	nc
  0BD6  CDEF0B        		call	TOUPPER
                      	;	call	ALPNUM
                      	;	ret
                      	
                      	
                      	;alphabet (capital) or numeral?
                      	;input: a
                      	;output: c-flag(1=yes,0=no)
                      	;destroy: f
  0BD9                	ALPNUM:
  0BD9  FE5B          		cp	'Z'+1
  0BDB  D0            		ret	nc
  0BDC  FE41          		cp	'A'
  0BDE  3F            		ccf
  0BDF  D8            		ret	c
                      	;	jp	CHKFIG
                      	
                      	
                      	;analyze for 0010h
                      	;input: a
                      	;output: z-flag(1=00h or 3ah), c-flag(1=30h-39h)
                      	;destroy: f
  0BE0                	CHKFIG:
  0BE0  B7            		or	a
  0BE1  C8            		ret	z
  0BE2  FE30          		cp	'0'
  0BE4  3F            		ccf
  0BE5  D0            		ret	nc
  0BE6  FE3A          		cp	':'
                      	;	ret	z
                      	;	cp	'9'+1
  0BE8  C9            		ret
                      	
                      	
                      	;convert lowercase letter to uppercase letter
                      	;input: hl=data address
                      	;output: a
                      	;destroy: f
  0BE9                	_TOUPHL:ds	TOUPHL-_TOUPHL
  0BEE  7E            		ld	a,(hl)
                      	
                      	;0bef: used by 256 bytes monitor
                      	;input: a=data
  0BEF                	TOUPPER:
  0BEF  FE7B          		cp	'z'+1
  0BF1  D0            		ret	nc
  0BF2                	TOUPPER2:
  0BF2  FE61          		cp	'a'
  0BF4  D8            		ret	c
  0BF5  D620          		sub	'a'-'A'
  0BF7  C9            		ret
                      	
                      	
                      	;OR operator
  0BF8                	O_OR:
  0BF8  CD5507        		call	F12TOI2
  0BFB  7C            		ld	a,h
  0BFC  B2            		or	d
  0BFD  67            		ld	h,a
  0BFE  7D            		ld	a,l
  0BFF  B3            		or	e
  0C00  6F            		ld	l,a
  0C01  C3180D        		jp	S2TOF
                      	
                      	
                      	;AND operator
  0C04                	O_AND:
  0C04  CD5507        		call	F12TOI2
  0C07  7C            		ld	a,h
  0C08  A2            		and	d
  0C09  67            		ld	h,a
  0C0A  7D            		ld	a,l
  0C0B  A3            		and	e
  0C0C  6F            		ld	l,a
  0C0D  C3180D        		jp	S2TOF
                      	
                      	
                      	;NOT operator
  0C10                	O_NOT:
  0C10  CD9B0B        		call	CHKNUM
  0C13  CD6539        		call	EXFAC
  0C16  CD4107        		call	FTOI2
  0C19  7A            		ld	a,d
  0C1A  2F            		cpl
  0C1B  67            		ld	h,a
  0C1C  7B            		ld	a,e
  0C1D  2F            		cpl
  0C1E  6F            		ld	l,a
  0C1F  C3180D        		jp	S2TOF
                      	
                      	
                      	;>,=,< operator
                      	;bit0: >
                      	;bit1: =
                      	;bit2: <
  0C22                	O_GTEQLT:
  0C22  3A25FF        		ld	a,(ARGTYP)
  0C25  B7            		or	a
  0C26  280D          		jr	z,GTEQLTZ
  0C28  D603          		sub	03h		;string and string
  0C2A  C2FD03        		jp	nz,TMERR
  0C2D  3225FF        		ld	(ARGTYP),a	;a=0
  0C30  CD580C        		call	CMPSTR
  0C33  1803          		jr	GTEQLTEND
  0C35                	GTEQLTZ:
  0C35  CD193F        		call	CMPF
  0C38                	GTEQLTEND:
  0C38  79            		ld	a,c		;operator
  0C39  2803          		jr	z,CASE_EQ
  0C3B  3002          		jr	nc,CASE_GT
  0C3D                	CASE_LT:
  0C3D  0F            		rrca
  0C3E                	CASE_EQ:
  0C3E  0F            		rrca
  0C3F                	CASE_GT:
  0C3F  0F            		rrca
  0C40  3811          		jr	c,SETTRUE
                      	;	jr	SETFALSE
                      	
  0C42                	SETFALSE:
  0C42                	SETZERO:
  0C42  21AB0E        		ld	hl,ZERO
  0C45                	SETF1:
  0C45  1166FF        		ld	de,FAC1
  0C48                	SETF:
  0C48  010500        		ld	bc,0005h
  0C4B  EDB0          		ldir
  0C4D  C9            		ret
                      	
  0C4E                	SETF2:
  0C4E  116DFF        		ld	de,FAC2
  0C51  18F5          		jr	SETF
                      	
  0C53                	SETTRUE:
  0C53                	SETMNS1:
  0C53  21A60E        		ld	hl,MNSONE
  0C56  18ED          		jr	SETF1
                      	
                      	
  0C58                	CMPSTR:
  0C58  2139FF        		ld	hl,STRDSC4
  0C5B  46            		ld	b,(hl)
  0C5C  3600          		ld	(hl),00h
  0C5E  3A2DFF        		ld	a,(STRDSC1)
  0C61  B8            		cp	b
  0C62  F5            		push	af		;flag
  0C63  3801          		jr	c,CMPSNC
  0C65  78            		ld	a,b
  0C66                	CMPSNC:
  0C66  B7            		or	a
  0C67  2810          		jr	z,CMPSZ
                      	
  0C69  ED5B2FFF      		ld	de,(STRDSC1+2)
  0C6D  2A3BFF        		ld	hl,(STRDSC4+2)
  0C70  47            		ld	b,a
  0C71                	CMPSLP:
  0C71  1A            		ld	a,(de)
  0C72  BE            		cp	(hl)
  0C73  2006          		jr	nz,CMPSNZ
  0C75  13            		inc	de
  0C76  23            		inc	hl
  0C77  10F8          		djnz	CMPSLP
  0C79                	CMPSZ:
  0C79  F1            		pop	af		;flag
  0C7A  C9            		ret
                      	
  0C7B                	CMPSNZ:
  0C7B  E1            		pop	hl		;cancel stack
  0C7C  C9            		ret
                      	
                      	
                      	;input: a=integer (unsigned)
  0C7D                	I1TOFA:
  0C7D  6F            		ld	l,a
                      	
                      	;convert 1- or 2-byte integer to float
                      	;input: hl=integer (unsigned)
                      	;output: FAC1
                      	;destroy: af,b,hl
  0C7E                	I1TOF:
  0C7E  2600          		ld	h,00h
  0C80                	I2TOF:
  0C80  D5            		push	de
  0C81  110000        		ld	de,0000h
  0C84  7C            		ld	a,h
  0C85  B5            		or	l
  0C86  280F          		jr	z,I2TOFZERO
  0C88  0610          		ld	b,10h
  0C8A                	I2TOFLP:
  0C8A  29            		add	hl,hl
  0C8B  3802          		jr	c,I2TOFEND
  0C8D  10FB          		djnz	I2TOFLP
                      	
  0C8F                	I2TOFEND:
  0C8F  CB3C          		srl	h
  0C91  CB1D          		rr	l
  0C93  EB            		ex	de,hl
  0C94                	I2TOFEND2:
  0C94  78            		ld	a,b
  0C95  C680          		add	a,80h
  0C97                	I2TOFZERO:
                      	;	ld	(FAC1),hl
                      	;	ld	(FAC1+2),de
  0C97  326AFF        		ld	(FAC1+4),a
  0C9A  CD0725        		call	SETI4
  0C9D  D1            		pop	de
  0C9E  C9            		ret
                      	
                      	
                      	;convert float to 2-byte integer [-65535,65535]
                      	;(round toward minus infinity)
                      	;input: FAC1
                      	;output: de
                      	;destroy: af,bc,hl
  0C9F                	FTOI:
  0C9F  110000        		ld	de,0000h
  0CA2  3A6AFF        		ld	a,(FAC1+4)
  0CA5  B7            		or	a
  0CA6  C8            		ret	z
  0CA7  D691          		sub	91h
  0CA9  D2E503        		jp	nc,FCERR
  0CAC  ED44          		neg
  0CAE  47            		ld	b,a
                      	
  0CAF  2A66FF        		ld	hl,(FAC1)
  0CB2  7C            		ld	a,h
  0CB3  B5            		or	l		;fraction
                      	
  0CB4  2A68FF        		ld	hl,(FAC1+2)
  0CB7  4C            		ld	c,h		;sign
  0CB8  CBFC          		set	7,h
  0CBA  05            		dec	b
  0CBB  2809          		jr	z,FTOIZ
  0CBD                	FTOILP:
  0CBD  CB3C          		srl	h
  0CBF  CB1D          		rr	l
  0CC1  3001          		jr	nc,FTOINC
  0CC3  17            		rla			;a>0
  0CC4                	FTOINC:
  0CC4  10F7          		djnz	FTOILP
                      	
  0CC6                	FTOIZ:
  0CC6  EB            		ex	de,hl
  0CC7  CB79          		bit	7,c		;sign
  0CC9  C8            		ret	z
                      	
  0CCA  ED44          		neg			;set c-flag if a>0
  0CCC  ED52          		sbc	hl,de
  0CCE  EB            		ex	de,hl
  0CCF  C9            		ret
                      	
                      	
                      	;get integer part from float
                      	;(round toward zero)
                      	;input: FAC1
                      	;output: FAC1
                      	;destroy: af,b,hl
  0CD0                	GETINT:
  0CD0  3A6AFF        		ld	a,(FAC1+4)
  0CD3  FE81          		cp	81h
  0CD5  DA420C        		jp	c,SETZERO
  0CD8  D6A0          		sub	0a0h
  0CDA  D0            		ret	nc
  0CDB  2166FF        		ld	hl,FAC1
  0CDE                	GETILP1:
  0CDE  C608          		add	a,08h		;
  0CE0  3805          		jr	c,GETIC
  0CE2  3600          		ld	(hl),00h
  0CE4  23            		inc	hl
  0CE5  18F7          		jr	GETILP1
  0CE7                	GETIC:
  0CE7  47            		ld	b,a
  0CE8  04            		inc	b
  0CE9  AF            		xor	a
  0CEA                	GETILP2:
  0CEA  1F            		rra
  0CEB  37            		scf
  0CEC  10FC          		djnz	GETILP2
  0CEE  A6            		and	(hl)
  0CEF  77            		ld	(hl),a
  0CF0  C9            		ret
                      	
                      	
                      	;convert 1-byte signed integer to float
                      	;input: b=integer (signed)
                      	;output: FAC1
                      	;destroy: af,bc,hl
  0CF1                	_S1TOF:	ds	ABTOF-5-_S1TOF
  0D11                		org	ABTOF-5
  0D11                	S1TOF:
  0D11  78            		ld	a,b
  0D12  07            		rlca
  0D13  9F            		sbc	a,a		;a=0(b<80h) or ffh(b>=80h)
  0D14  1800          		jr	ABTOF
                      	
                      	
                      	;convert 2-byte integer to float for USR()
                      	;input: ab
                      	;output: FAC1
                      	;destroy: af,bc,hl
  0D16                	_ABTOF:	ds	ABTOF-_ABTOF
  0D16                		org	ABTOF
                      	
  0D16  67            		ld	h,a
  0D17  68            		ld	l,b
                      	;	jr	S2TOF
                      	
                      	
                      	;convert 2-byte signed integer to float
                      	;input: hl=integer (signed)
                      	;output: FAC1
                      	;destroy: af,b,hl
  0D18                	S2TOF:
  0D18  CB7C          		bit	7,h
  0D1A  CA800C        		jp	z,I2TOF
  0D1D  AF            		xor	a
  0D1E  95            		sub	l
  0D1F  6F            		ld	l,a
  0D20  9C            		sbc	a,h
  0D21  95            		sub	l
  0D22  67            		ld	h,a
  0D23  CD800C        		call	I2TOF
  0D26  1805          		jr	NEGABSNZ
                      	
                      	
                      	;FAC1=-abs(FAC1)
                      	;destroy: af,hl
  0D28                	NEGABS:
  0D28  3A6AFF        		ld	a,(FAC1+4)
  0D2B  B7            		or	a
  0D2C  C8            		ret	z
                      	
                      	;FAC1=-abs(FAC1) without checking zero
                      	;destroy: f,hl
  0D2D                	NEGABSNZ:
  0D2D  2169FF        		ld	hl,FAC1+3
  0D30  CBFE          		set	7,(hl)
  0D32  C9            		ret
                      	
                      	
                      	;LPOS() function
  0D33                	F_LPOS:
  0D33  3A25FF        		ld	a,(ARGTYP)
  0D36  FE02          		cp	02h
  0D38  D2DC03        		jp	nc,SNERR
  0D3B  2A57FA        		ld	hl,(PRTPOS)
  0D3E  C3A431        		jp	SETI1
                      	
                      	
                      	;POS() function
  0D41                	F_POS:
  0D41  3A25FF        		ld	a,(ARGTYP)
  0D44  FE02          		cp	02h
  0D46  D2DC03        		jp	nc,SNERR
  0D49  2AA9FD        		ld	hl,(CSRX)
  0D4C  2D            		dec	l
  0D4D  C3A431        		jp	SETI1
                      	
                      	
                      	;CSRLINE function
  0D50                	F_CSRL:
  0D50  2AA8FD        		ld	hl,(CSRY)
  0D53  2D            		dec	l
  0D54  C37E0C        		jp	I1TOF
                      	
                      	
                      	;DEF command
  0D57                	C_DEF:
  0D57  ED5B5DFA      		ld	de,(LINENUM)
  0D5B  7A            		ld	a,d
  0D5C  A3            		and	e
  0D5D  3C            		inc	a
  0D5E  CAFA03        		jp	z,IDERR
  0D61  CD573F        		call	SKIPSP
  0D64  FEC4          		cp	FN_
  0D66  C2DC03        		jp	nz,SNERR
  0D69  23            		inc	hl
  0D6A  CD8F33        		call	CHKVAR
  0D6D  CB79          		bit	7,c
  0D6F  C2FD03        		jp	nz,TMERR
  0D72  CBF8          		set	7,b
  0D74  E5            		push	hl		;program address
  0D75  CDC133        		call	SRCHVAR
  0D78  DCEB33        		call	c,MAKEVAR
  0D7B  E1            		pop	hl		;program address
  0D7C  CDB50B        		call	CHKLPAR
  0D7F  CD8F33        		call	CHKVAR
  0D82  CB79          		bit	7,c
  0D84  C2FD03        		jp	nz,TMERR
  0D87  CDC40B        		call	CHKRPAR
  0D8A  CD573F        		call	SKIPSP
  0D8D  FED2          		cp	EQ_
  0D8F  C2DC03        		jp	nz,SNERR
  0D92  CD563F        		call	SKIPSPINC
                      	
  0D95  EB            		ex	de,hl
  0D96  73            		ld	(hl),e
  0D97  23            		inc	hl
  0D98  72            		ld	(hl),d
  0D99  23            		inc	hl
  0D9A  70            		ld	(hl),b
  0D9B  23            		inc	hl
  0D9C  71            		ld	(hl),c
                      	;	inc	hl
                      	;	ld	(hl),00h
  0D9D  EB            		ex	de,hl
                      	
  0D9E  2B            		dec	hl
  0D9F                	DEFLP:
  0D9F  CD5D3F        		call	CHKCLNINC
  0DA2  20FB          		jr	nz,DEFLP
                      	
  0DA4  224EFF        		ld	(PROGAD),hl
  0DA7  C9            		ret
                      	
                      	
                      	;INP() function
  0DA8                	F_INP:
  0DA8  CD9B0B        		call	CHKNUM
  0DAB  CD4C07        		call	FTOI1
  0DAE  42            		ld	b,d		;d=0
  0DAF  4B            		ld	c,e
  0DB0  ED68          		in	l,(c)
  0DB2  62            		ld	h,d		;d=0
  0DB3  C3800C        		jp	I2TOF
                      	
                      	
                      	;OUT command
  0DB6                	C_OUT:
  0DB6  CDE40D        		call	INT1ARG
  0DB9  7E            		ld	a,(hl)
  0DBA  FE2C          		cp	','
  0DBC  C2DC03        		jp	nz,SNERR
  0DBF  D5            		push	de		;
  0DC0  CDE30D        		call	INT1INC
  0DC3  C1            		pop	bc		;
  0DC4  ED59          		out	(c),e
  0DC6  C9            		ret
                      	
                      	
                      	;increment hl and get a 1-byte integer argument [0,255]
  0DC7                	_INT1INC:ds	INT1INC-_INT1INC
  0DE3                		org	INT1INC
                      	
  0DE3  23            		inc	hl
                      	
                      	;get a 1-byte integer argument [0,255]
                      	;input: hl=program address
                      	;output: FAC1,a,de=integer, hl=next address
                      	;destroy: FAC2,f,bc
  0DE4                	_INT1ARG:ds	INT1ARG-_INT1ARG
  0DE4                		org	INT1ARG
                      	
  0DE4  CD140E        		call	INT2ARG
  0DE7  7A            		ld	a,d
  0DE8  B7            		or	a
  0DE9  7B            		ld	a,e
  0DEA  C8            		ret	z
  0DEB  C3E503        		jp	FCERR
                      	
                      	
                      	;PEEK() function
  0DEE                	F_PEEK:
  0DEE  CD9B0B        		call	CHKNUM
  0DF1  CD9F0C        		call	FTOI
  0DF4  1A            		ld	a,(de)
  0DF5  C37D0C        		jp	I1TOFA
                      	
                      	
                      	;POKE command
  0DF8                	C_POKE:
  0DF8  CD0B0E        		call	INTARG
  0DFB  7E            		ld	a,(hl)
  0DFC  FE2C          		cp	','
  0DFE  C2DC03        		jp	nz,SNERR
  0E01  D5            		push	de		;
  0E02  CD910B        		call	NARGMOINC
  0E05  CD4C07        		call	FTOI1
  0E08  E1            		pop	hl		;
  0E09  73            		ld	(hl),e
  0E0A  C9            		ret
                      	
                      	
                      	;get a 2-byte integer argument [-65535,65535]
                      	;input: hl=program address
                      	;output: FAC1,de=integer, hl=next address
                      	;destroy: FAC2,af,bc
  0E0B                	INTARG:
  0E0B  CD920B        		call	NARGMO
  0E0E  E5            		push	hl
  0E0F  CD9F0C        		call	FTOI
  0E12  E1            		pop	hl
  0E13  C9            		ret
                      	
                      	
                      	;get a 2-byte integer argument [-32768,32767]
                      	;input: hl=program address
                      	;output: FAC1,de=integer, hl=next address
                      	;destroy: FAC2,af,bc
  0E14                	INT2ARG:
  0E14  CD920B        		call	NARGMO
  0E17  E5            		push	hl
  0E18  CD4107        		call	FTOI2
  0E1B  E1            		pop	hl
  0E1C  C9            		ret
                      	
                      	
                      	;get two 2-byte integer arguments [-65535,65535]
                      	;input: hl=program address
                      	;output: FAC1, bc=1st, de=2nd, hl=next address
                      	;destroy: af
  0E1D                	INTARG2:
  0E1D  CD0B0E        		call	INTARG
  0E20  7E            		ld	a,(hl)
  0E21  FE2C          		cp	','
  0E23  C2DC03        		jp	nz,SNERR
  0E26  23            		inc	hl
  0E27  D5            		push	de		;
  0E28  CD0B0E        		call	INTARG
  0E2B  C1            		pop	bc		;
  0E2C  C9            		ret
                      	
                      	
                      	;get space attribute data for scroll
                      	;output: a
                      	;destroy: f
  0E2D                	GETSPA:
  0E2D  3A92FD        		ld	a,(SCREEN1)
  0E30  3D            		dec	a
  0E31  FA0716        		jp	m,CNVATT1
  0E34  280B          		jr	z,GETSPA2
                      	
  0E36                	GETSPAG:
  0E36  3D            		dec	a
  0E37  3A95FD        		ld	a,(COLOR3)
  0E3A  2802          		jr	z,GETSPA3
  0E3C  C650          		add	a,50h
  0E3E                	GETSPA3:
  0E3E  C68C          		add	a,8ch		;screen mode 3=8ch, screen mode 4=dch
  0E40  C9            		ret
                      	
  0E41                	GETSPA2:
  0E41  3A94FD        		ld	a,(COLOR2)
  0E44  B7            		or	a
  0E45  2003          		jr	nz,GETSPA2NZ
  0E47  3A93FD        		ld	a,(COLOR1)
                      	
  0E4A                	GETSPA2NZ:
  0E4A  FE05          		cp	05h
  0E4C  3A95FD        		ld	a,(COLOR3)
  0E4F  3802          		jr	c,GETSPAC
  0E51  EE02          		xor	02h
  0E53                	GETSPAC:
  0E53  C660          		add	a,60h
  0E55  C9            		ret
                      	
                      	
                      	;get data from port 90h
                      	;output: a
                      	;destroy: f
  0E56                	_IN90H:	ds	IN90H-_IN90H
  0E78                		org	IN90H
                      	
  0E78  3E0C          		ld	a,0ch
  0E7A  D393          		out	(93h),a		;disable 8255 INT for writing
  0E7C                	IN90HLP:
  0E7C  DB92          		in	a,(92h)
  0E7E  2F            		cpl
  0E7F  E628          		and	28h
  0E81  20F9          		jr	nz,IN90HLP	;wait for ibf=1,intr=1
  0E83  3E0D          		ld	a,0dh
  0E85  D393          		out	(93h),a		;enable 8255 INT for writing
  0E87  DB90          		in	a,(90h)
  0E89  C9            		ret
                      	
                      	
                      	;output to port 90h (send sub CPU command)
                      	;input: a=data
                      	;destroy: none
  0E8A                	_OUT90H:ds	OUT90H-_OUT90H
  0E8F                		org	OUT90H
                      	
  0E8F  F5            		push	af
  0E90  3E08          		ld	a,08h
  0E92  D393          		out	(93h),a		;disable 8255 INT for reading
  0E94                	OUT90HLP:
  0E94  DB92          		in	a,(92h)
  0E96  07            		rlca
  0E97  30FB          		jr	nc,OUT90HLP	;wait for nobf=1
  0E99  3E09          		ld	a,09h
  0E9B  D393          		out	(93h),a		;enable 8255 INT for reading
  0E9D  F1            		pop	af
  0E9E  D390          		out	(90h),a
  0EA0  C9            		ret
                      	
                      	
  0EA1                	PLSONE:
  0EA1  0000000081    		db	00h, 00h, 00h, 00h, 81h
                      	
  0EA6                	MNSONE:
  0EA6  0000008081    		db	00h, 00h, 00h, 80h, 81h
                      	
  0EAB                	ZERO:
  0EAB  0000000000    		db	00h, 00h, 00h, 00h, 00h
                      	
                      	
                      	;interrupt for graphic key
  0EB0                	_INTGRP:ds	INTGRP-_INTGRP
  0EB0                		org	INTGRP
                      	
  0EB0  C5            		push	bc
  0EB1  0601          		ld	b,01h
  0EB3  1803          		jr	KEYCOMMON
                      	
                      	
                      	;interrupt for normal key
  0EB5                	_INTKEY:ds	INTKEY-_INTKEY
  0EB5                		org	INTKEY
                      	
  0EB5  C5            		push	bc
  0EB6  0600          		ld	b,00h
                      	
  0EB8                	KEYCOMMON:
  0EB8  F5            		push	af
  0EB9  CD780E        		call	IN90H
                      	
                      	;0ebch: used by SPACE HARRIER
  0EBC  D5            		push	de
  0EBD  E5            		push	hl
  0EBE  B7            		or	a
  0EBF  286A          		jr	z,IKPOP
                      	;	dec	b
                      	;	jr	nz,NORMAL
  0EC1  1020          		djnz	NORMAL
                      	
  0EC3                	GRAPH:
  0EC3  FEFC          		cp	0fch		;SHIFT+PAGE, only for emulator
  0EC5  285D          		jr	z,RESSTOP
  0EC7  FEFE          		cp	0feh		;KANA, only for emulator
  0EC9  2859          		jr	z,RESSTOP
                      	
  0ECB  CD2215        		call	CLICK
  0ECE  FEFA          		cp	0fah		;STOP
  0ED0  2848          		jr	z,STOPKEY
  0ED2  3057          		jr	nc,IKPOP	;CAPS/MODE, for mk2
  0ED4  47            		ld	b,a		;;
  0ED5  218FFB        		ld	hl,KYBFIN
  0ED8  4E            		ld	c,(hl)		;
  0ED9  3E14          		ld	a,14h
  0EDB  CD360F        		call	PUTKBF
  0EDE  3844          		jr	c,RESSTOP
  0EE0  78            		ld	a,b		;;
  0EE1  1822          		jr	IKBF2
                      	
                      	
                      	;normal key
  0EE3                	NORMAL:
  0EE3  CD2215        		call	CLICK
  0EE6  FE03          		cp	03h		;Ctrl-C
  0EE8  2835          		jr	z,STOPKEY2
  0EEA  FE1B          		cp	1bh
  0EEC  2831          		jr	z,STOPKEY2
  0EEE  FE7F          		cp	7fh
  0EF0  2004          		jr	nz,IKBF
  0EF2  3E08          		ld	a,08h		;DEL->ctrl-H, not necessary for emulator?
                      	
  0EF4  1800          		jr	IKBF
                      	
                      	
                      	;0ef6h: used by PORTOPIA
  0EF6                	_IKBF:ds	IKBF-_IKBF
  0EF6                		org	IKBF
                      	
  0EF6  218FFB        		ld	hl,KYBFIN
  0EF9  4E            		ld	c,(hl)		;
  0EFA  CD360F        		call	PUTKBF
  0EFD  3825          		jr	c,RESSTOP
  0EFF  FE14          		cp	14h
  0F01  2021          		jr	nz,RESSTOP
  0F03  3EEF          		ld	a,0efh		;Ctrl-T->14h+0efh
                      	
  0F05                	IKBF2:
  0F05  CD360F        		call	PUTKBF
  0F08  301A          		jr	nc,RESSTOP
                      	
  0F0A  218FFB        		ld	hl,KYBFIN
  0F0D  71            		ld	(hl),c		;
  0F0E  1814          		jr	RESSTOP
                      	
                      	
                      	;interrupt for reply to key query
  0F10                	INTGAM:
  0F10  F5            		push	af
  0F11  CD780E        		call	IN90H
  0F14  32CAFE        		ld	(GMKYBUF),a
  0F17  F1            		pop	af
  0F18  FB            		ei
  0F19  C9            		ret
                      	
                      	
  0F1A                	STOPKEY:
  0F1A  CDD8FF        		call	HOOKSTP
  0F1D  3E03          		ld	a,03h
  0F1F                	STOPKEY2:
  0F1F  CD360F        		call	PUTKBF
  0F22  1801          		jr	SETSTOP
                      	
  0F24                	RESSTOP:
  0F24  AF            		xor	a
  0F25                	SETSTOP:
  0F25  3218FA        		ld	(STOPFLG),a
                      	;	jr	IKPOP
                      	
                      	
                      	;pop register for key interrupt
  0F28                	_IKPOP:	ds	IKPOP-_IKPOP
  0F2B                		org	IKPOP
                      	
  0F2B  E1            		pop	hl
  0F2C  D1            		pop	de
                      	
                      	;0f2dh: used by SPACE HARRIER
  0F2D  F1            		pop	af
  0F2E  C1            		pop	bc
  0F2F  FB            		ei
  0F30  C9            		ret
                      	
                      	
                      	;put into PLAY command buffer
                      	;input: a=data
                      	;destroy: f,hl
  0F31                	PUTPLBF:
  0F31  CD871C        		call	GETPLAD
  0F34  1803          		jr	PUTBF
                      	
                      	
                      	;put into key buffer
                      	;input: a
                      	;output: c-flag (1=buffer full)
                      	;destroy: f,hl
  0F36                	PUTKBF:
  0F36  218FFB        		ld	hl,KYBFIN
                      	;	call	PUTBF
                      	;	ret
                      	
                      	
                      	;put characer into buffer
                      	;input: a=character, hl=buffer control address
                      	;output: c-flag (1=buffer full)
                      	;destroy: f,hl
  0F39                	PUTBF:
  0F39  F5            		push	af
  0F3A  7E            		ld	a,(hl)		;in
  0F3B  3C            		inc	a
  0F3C  2C            		inc	l		;inc hl
  0F3D  2C            		inc	l		;inc hl
  0F3E  2C            		inc	l		;inc hl
  0F3F  A6            		and	(hl)		;size
  0F40  2D            		dec	l		;dec hl
  0F41  2D            		dec	l		;dec hl
  0F42  BE            		cp	(hl)		;out
  0F43  2811          		jr	z,BFFULL
                      	
  0F45  2D            		dec	l		;dec hl
  0F46  77            		ld	(hl),a		;in
  0F47  2C            		inc	l		;inc hl
  0F48  2C            		inc	l		;inc hl
  0F49  2C            		inc	l		;inc hl
  0F4A  2C            		inc	l		;inc hl
  0F4B  86            		add	a,(hl)		;address
  0F4C  2C            		inc	l		;inc hl
  0F4D  66            		ld	h,(hl)
  0F4E  6F            		ld	l,a
  0F4F  3001          		jr	nc,PTBNC
  0F51  24            		inc	h
  0F52                	PTBNC:
  0F52  F1            		pop	af
  0F53  77            		ld	(hl),a
  0F54  B7            		or	a		;reset c-flag
  0F55  C9            		ret
                      	
  0F56                	BFFULL:
  0F56  F1            		pop	af
  0F57  37            		scf
  0F58  C9            		ret
                      	
                      	
                      	;interrupt for RS-232C
  0F59                	INT232:
  0F59  F5            		push	af
  0F5A  E5            		push	hl
  0F5B  3E17          		ld	a,17h		;RTS=0
  0F5D  D381          		out	(81h),a
                      	
  0F5F  DB80          		in	a,(80h)
  0F61  2195FB        		ld	hl,RSBFIN
  0F64  CD390F        		call	PUTBF
                      	
  0F67  3E0C          		ld	a,0ch		;enable RS-232C interrupt
  0F69  CD8F0E        		call	OUT90H
                      	
  0F6C  3E37          		ld	a,37h		;RTS=1
  0F6E  D381          		out	(81h),a
  0F70  E1            		pop	hl
  0F71  1833          		jr	POPAF
                      	
                      	
                      	;interrupt for timer
  0F73                	_INTTIM:ds	INTTIM-_INTTIM
  0F74                		org	INTTIM
                      	
  0F74  C5            		push	bc
  0F75  F5            		push	af
  0F76  D5            		push	de
  0F77  E5            		push	hl
                      	
  0F78  CDEC1B        		call	PLAYINT
                      	
  0F7B  2128FA        		ld	hl,TMCNT
  0F7E  34            		inc	(hl)
  0F7F  34            		inc	(hl)
  0F80  20A9          		jr	nz,IKPOP
  0F82  2C            		inc	l		;inc hl
  0F83  34            		inc	(hl)
  0F84  2006          		jr	nz,TIMCSR
  0F86  2C            		inc	l
  0F87  34            		inc	(hl)
  0F88  2002          		jr	nz,TIMCSR
  0F8A  2C            		inc	l
  0F8B  34            		inc	(hl)
                      	
  0F8C                	TIMCSR:
                      	;cursor blink
  0F8C  3A92FD        		ld	a,(SCREEN1)
  0F8F  212EFA        		ld	hl,CSRBLNK
  0F92  2F            		cpl
  0F93  0F            		rrca
  0F94  A6            		and	(hl)
  0F95  C48F11        		call	nz,CSRREV	;(SCREEN1)=0or1, (CSRBLNK)=1
  0F98  1891          		jr	IKPOP
                      	
                      	
                      	;interrupt for CMT load
  0F9A                	INTCMT:
  0F9A  F5            		push	af
  0F9B  CD780E        		call	IN90H
  0F9E  321DFA        		ld	(CMTBUF),a
  0FA1  3E02          		ld	a,02h
  0FA3                	SETCMTST:
  0FA3  3219FA        		ld	(CMTSTAT),a
  0FA6                	POPAF:
  0FA6  F1            		pop	af
  0FA7                	EIRET:
  0FA7  FB            		ei
  0FA8  C9            		ret
                      	
                      	
                      	;interrupt for CMT write stop
  0FA9                	INTWSTP:
                      	;interrupt for CMT read stop
  0FA9                	INTRSTP:
  0FA9  F5            		push	af
  0FAA  3E03          		ld	a,03h
  0FAC  3218FA        		ld	(STOPFLG),a
  0FAF  18F5          		jr	POPAF
                      	
                      	
                      	;interrupt for CMT error
  0FB1                	INTERR:
  0FB1  F5            		push	af
  0FB2  3E10          		ld	a,10h
  0FB4  18ED          		jr	SETCMTST
                      	
                      	
                      	;get input character
                      	;output: a, z-flag(1=no input)
                      	;destroy: f
  0FB6                	_GETCH:	ds	GETCH-_GETCH
  0FBC                		org	GETCH
                      	
  0FBC  E5            		push	hl
  0FBD  CDF10F        		call	GETCH2
  0FC0  E1            		pop	hl
  0FC1  C9            		ret
                      	
                      	
                      	;wait for input and get a character
                      	;output: a
                      	;destroy: f
  0FC2                	_GETC:	ds	GETC-_GETC
  0FC4                		org	GETC
                      	
  0FC4  E5            		push	hl
  0FC5                	GETCLP1:
  0FC5  CD7911        		call	CSRON
  0FC8  2600          		ld	h,00h
  0FCA                	GETCLP2:
  0FCA  24            		inc	h
  0FCB  CCB912        		call	z,PRTFKEY2
  0FCE  CDBC0F        		call	GETCH
  0FD1  28F7          		jr	z,GETCLP2
                      	
  0FD3  CD8111        		call	CSROFF
  0FD6  FEFE          		cp	0feh		;page switching key
  0FD8  2807          		jr	z,GETCPAGE
  0FDA  67            		ld	h,a
  0FDB  CD7213        		call	CHGTXT
  0FDE  7C            		ld	a,h
  0FDF  E1            		pop	hl
  0FE0  C9            		ret
                      	
  0FE1                	GETCPAGE:
  0FE1  3A8FFD        		ld	a,(SCREEN2)
  0FE4  3C            		inc	a
  0FE5  218CFD        		ld	hl,PAGES
  0FE8  BE            		cp	(hl)
  0FE9  3801          		jr	c,GETCC
  0FEB  AF            		xor	a
  0FEC                	GETCC:
  0FEC  CD7F13        		call	CHGSCR
  0FEF  18D4          		jr	GETCLP1
                      	
                      	
  0FF1                	GETCH2:
  0FF1  3A32FA        		ld	a,(FKEYCNT)
  0FF4  B7            		or	a
  0FF5  202E          		jr	nz,GETFKEY
  0FF7  2130FA        		ld	hl,GRPWRK
  0FFA  B6            		or	(hl)		;a=0
  0FFB  2808          		jr	z,GETCHZ	;(hl)=0?
  0FFD  3600          		ld	(hl),00h
  0FFF  FEEF          		cp	0efh		;Ctrl-T=14h+0efh
  1001  C8            		ret	z
  1002  C630          		add	a,30h
  1004  C9            		ret			;z-flag=0
                      	
  1005                	GETCHZ:
                      	;(GRPWRK)=0
  1005  CD3A10        		call	GETKBF
  1008  C8            		ret	z
  1009  FE14          		cp	14h
  100B  C0            		ret	nz
                      	
                      	;14h+**
  100C  CD3A10        		call	GETKBF
  100F  FEF0          		cp	0f0h
  1011  3006          		jr	nc,CNVFKEY
  1013  3230FA        		ld	(GRPWRK),a
  1016  3E14          		ld	a,14h
  1018  C9            		ret			;z-flag=0
                      	
                      	;a=f0-f9
  1019                	CNVFKEY:
  1019  21BDFB        		ld	hl,FKEYTBL+80h
                      	;	and	0fh
  101C  87            		add	a,a
  101D  87            		add	a,a
  101E  87            		add	a,a
  101F  85            		add	a,l		;no carry
  1020  6F            		ld	l,a
                      	;	jr	nc,CNVFKNC
                      	;	inc	h
                      	;CNVFKNC:
  1021  3E07          		ld	a,07h
  1023  1804          		jr	GETFKEY2
                      	
                      	;function key
  1025                	GETFKEY:
  1025  2A8DFB        		ld	hl,(FKEYAD)
  1028  3D            		dec	a
  1029                	GETFKEY2:
  1029  3232FA        		ld	(FKEYCNT),a
  102C  7E            		ld	a,(hl)
  102D  23            		inc	hl
  102E  228DFB        		ld	(FKEYAD),hl
  1031  B7            		or	a
  1032  C0            		ret	nz
  1033  3232FA        		ld	(FKEYCNT),a	;=0
  1036  C9            		ret			;z-flag=1: no input
                      	
                      	
                      	;get a character from key buffer
                      	;output: a,z-flag(1=no input)
                      	;destroy: f,hl
  1037                	_GETKBF:ds	GETKBF-_GETKBF
  103A                		org	GETKBF
                      	
  103A  218FFB        		ld	hl,KYBFIN
  103D                	CALLGETBF:
  103D  F3            		di
  103E  CD0B26        		call	GETBF
  1041  FB            		ei
  1042  C9            		ret
                      	
                      	
                      	;get a character from RS-232C buffer
                      	;output: a,z-flag(1=no input)
                      	;destroy: f,hl
  1043                	GETRSBF:
  1043  2195FB        		ld	hl,RSBFIN
  1046  18F5          		jr	CALLGETBF
                      	
                      	
                      	;get from PLAY command buffer
                      	;input: b=channel+1 (1,2,3)
                      	;output: a,z-flag(1=no input)
                      	;destroy: f,hl
  1048                	GETPLBF:
  1048  219BFB        		ld	hl,BUFAIN-6
  104B  78            		ld	a,b
  104C  87            		add	a,a		;*2
  104D  80            		add	a,b		;*3
  104E  87            		add	a,a		;*6
  104F  85            		add	a,l		;no carry
  1050  6F            		ld	l,a
  1051  C30B26        		jp	GETBF
                      	
                      	
                      	;clear key buffer pointer
                      	;destroy: hl,(af,bc,de)
  1054                	_CLRKBF:ds	CLRKBF-_CLRKBF
  1058                		org	CLRKBF
                      	
  1058  210000        		ld	hl,0000h
  105B  228FFB        		ld	(KYBFIN),hl	;(KYBFIN),(KYBFOUT)=0
  105E  C9            		ret
                      	
                      	
                      	;send key-query to sub CPU and get reply
                      	;output: a (space-0-left-right-down-up-stop-shift)
                      	;destroy: f (no change in c-flag)
  105F                	_STICK:	ds	STICK-_STICK
  1061                		org	STICK
                      	
  1061  3EFF          		ld	a,0ffh
  1063  32CAFE        		ld	(GMKYBUF),a
  1066  3E06          		ld	a,06h
  1068  F3            		di
  1069  CD8F0E        		call	OUT90H
  106C  FB            		ei
  106D                	STICKLP:
  106D  3ACAFE        		ld	a,(GMKYBUF)
  1070  3C            		inc	a
  1071  28FA          		jr	z,STICKLP	;wait for bit6=0
  1073  3D            		dec	a
  1074  C9            		ret
                      	
                      	
                      	;print a character in CRT
                      	;input: a=character code
                      	;destroy: none
  1075                	_PRTC:	ds	PRTC-_PRTC
  1075                		org	PRTC
                      	
  1075  F5            		push	af
  1076  E5            		push	hl
                      	
  1077  2A31FA        		ld	hl,(GRPFLG)
  107A  2C            		inc	l
  107B  2D            		dec	l
  107C  200D          		jr	nz,PRTGRP
  107E  FE20          		cp	20h
  1080  3010          		jr	nc,PRTCNC
  1082  D5            		push	de
  1083  C5            		push	bc
  1084  CDFA10        		call	PRTCTL
  1087  C1            		pop	bc
  1088  D1            		pop	de
  1089  180A          		jr	PRTCEND
                      	
  108B                	PRTGRP:
  108B  D630          		sub	30h
  108D  2131FA        		ld	hl,GRPFLG
  1090  3600          		ld	(hl),00h
  1092                	PRTCNC:
  1092  CDAA10        		call	PRTCH
                      	
  1095                	PRTCEND:
  1095  E1            		pop	hl
  1096  F1            		pop	af
  1097  C9            		ret
                      	
                      	
                      	;print a character in graphic mode (screen mode 3,4)
                      	;input: a=character
                      	;destroy: af,hl
  1098                	PRT34:
  1098  2AA8FD        		ld	hl,(CSRY)
  109B  CDD514        		call	PRT34XY
  109E                	CTLRGT:
  109E  2AAAFD        		ld	hl,(CSRAD)
  10A1  23            		inc	hl
  10A2  1813          		jr	CHKNL
                      	
                      	;print a character in CRT (no control code)
                      	;input: a=character code
                      	;destroy: af,hl
  10A4                	_PRTCH:ds	PRTCH-_PRTCH
  10AA                		org	PRTCH
                      	
  10AA  2A92FD        		ld	hl,(SCREEN1)
  10AD  CB4D          		bit	1,l
  10AF  20E7          		jr	nz,PRT34	;screen mode 3,4
                      	
  10B1  2AAAFD        		ld	hl,(CSRAD)
  10B4  CDCA14        		call	PRT12
                      	
                      	;next line?
  10B7                	CHKNL:
  10B7  22AAFD        		ld	(CSRAD),hl
  10BA  21A9FD        		ld	hl,CSRX
  10BD  34            		inc	(hl)
  10BE  3AACFD        		ld	a,(WIDTH)
  10C1  BE            		cp	(hl)
  10C2  D0            		ret	nc
  10C3                	CHKNL2:
  10C3  3601          		ld	(hl),1
                      	
  10C5  3AA5FD        		ld	a,(LASTLIN)
  10C8  2AA2FD        		ld	hl,(CONSOL1)	;l=(CONSOL1)
  10CB  95            		sub	l
  10CC  2802          		jr	z,CTLLF
  10CE  3EFF          		ld	a,0ffh
                      	
  10D0                	CTLLF:
  10D0  3C            		inc	a		;0 or 1
  10D1  2AA8FD        		ld	hl,(CSRY)	;l=y+1,h=x+1
                      	
  10D4  E5            		push	hl
  10D5  D5            		push	de
  10D6  CD4F14        		call	SETLINE
  10D9  D1            		pop	de
  10DA  E1            		pop	hl
                      	
  10DB  2C            		inc	l
  10DC  3AA5FD        		ld	a,(LASTLIN)
  10DF  BD            		cp	l
  10E0  D26D11        		jp	nc,SETCSR
                      	
                      	;scroll
  10E3  D5            		push	de
  10E4  54            		ld	d,h		;x+1
  10E5  2AA1FD        		ld	hl,(CONSOL1-1)	;h=(CONSOL1)
  10E8  1801          		jr	SKPPATCH1
                      	
                      	
                      	;10eah: to be patched by iP6/iP6win
  10EA                	_PATCH1:ds	PATCH1-_PATCH1
  10EA                		org	PATCH1
  10EA  00            		db	00h
                      	
  10EB                	SKPPATCH1:
  10EB  6F            		ld	l,a
  10EC  9C            		sbc	a,h		;c-flag=1, (LASTLIN)-(CONSOL1)-1
  10ED  D46012        		call	nc,SCRLUP
                      	
  10F0  62            		ld	h,d		;x+1
  10F1  CDB811        		call	Y2AD
  10F4  CDDA11        		call	DELLIN
  10F7  D1            		pop	de
  10F8  1873          		jr	SETCSR
                      	
                      	
  10FA                	PRTCTL:
  10FA  FE14          		cp	14h
  10FC  2847          		jr	z,CTLGRP
  10FE  FE07          		cp	07h
  1100  CACD1B        		jp	z,BELL
  1103  D60A          		sub	0ah
  1105  28C9          		jr	z,CTLLF
  1107  3D            		dec	a
  1108  283F          		jr	z,CTLHOM	;0bh
  110A  3D            		dec	a
  110B  CA7428        		jp	z,CTLL		;0ch
  110E  2AA8FD        		ld	hl,(CSRY)	;l=y+1,h=x+1
  1111  3D            		dec	a
  1112  2838          		jr	z,CTLCR		;0dh
  1114  D60F          		sub	1ch-0dh
  1116  2886          		jr	z,CTLRGT	;1ch
  1118  3D            		dec	a
  1119  2808          		jr	z,CTLLFT	;1dh
  111B  3D            		dec	a
  111C  2814          		jr	z,CTLUP		;1eh
  111E  3D            		dec	a
  111F  C0            		ret	nz
                      	;	jr	z,CTLDWN	;1fh
                      	
  1120                	CTLDWN:
  1120  2C            		inc	l
  1121  1819          		jr	CTLUPNZ
                      	
  1123                	CTLLFT:
  1123  25            		dec	h
  1124  2047          		jr	nz,SETCSR
  1126  3AA2FD        		ld	a,(CONSOL1)
  1129  BD            		cp	l
  112A  D0            		ret	nc
  112B  2D            		dec	l
  112C  3AACFD        		ld	a,(WIDTH)
  112F  67            		ld	h,a
  1130  183B          		jr	SETCSR
                      	
  1132                	CTLUP:
  1132  3AA2FD        		ld	a,(CONSOL1)
  1135  BD            		cp	l
  1136  C8            		ret	z
  1137  2D            		dec	l
  1138  2002          		jr	nz,CTLUPNZ
  113A  2E01          		ld	l,01h
  113C                	CTLUPNZ:
  113C  3AA5FD        		ld	a,(LASTLIN)
  113F  BD            		cp	l
  1140  302B          		jr	nc,SETCSR
  1142  6F            		ld	l,a
  1143  1828          		jr	SETCSR
                      	
  1145                	CTLGRP:
  1145  3231FA        		ld	(GRPFLG),a	;a=14h
  1148  C9            		ret
                      	
  1149                	CTLHOM:
  1149  2AA2FD        		ld	hl,(CONSOL1)	;l=(CONSOL1)
                      	
  114C                	CTLCR:
  114C  2601          		ld	h,1
  114E  181D          		jr	SETCSR
                      	
                      	
                      	;convert VRAM address to text screen (x,y)
                      	;input: hl=address
                      	;output: h=x+1, l=y+1(0=error)
                      	;destroy: af
  1150                	AD2XY:
  1150  CB4C          		bit	1,h
  1152  280F          		jr	z,AD2XYZ
                      	
  1154  7C            		ld	a,h
  1155  E601          		and	01h
  1157  67            		ld	h,a
  1158  7D            		ld	a,l
  1159  E61F          		and	1fh
  115B  29            		add	hl,hl
  115C  29            		add	hl,hl
  115D  29            		add	hl,hl
  115E  6C            		ld	l,h
  115F  67            		ld	h,a
  1160  24            		inc	h
  1161  2C            		inc	l
  1162  C9            		ret
                      	
  1163                	AD2XYZ:
  1163  2E00          		ld	l,00h
  1165  C9            		ret
                      	
                      	
                      	;set cursor position
                      	;input: h=x+1, l=y+1
                      	;output: (fda8h)=y+1,(fda9h)=x+1,(fdaa-fdab)=VRAM address
                      	;destroy: none
  1166                	_SETCSR:ds	SETCSR-_SETCSR
  116D                		org	SETCSR
                      	
  116D  E5            		push	hl
  116E  22A8FD        		ld	(CSRY),hl
  1171  CDCD11        		call	XY2AD
  1174  22AAFD        		ld	(CSRAD),hl
  1177  E1            		pop	hl
  1178  C9            		ret
                      	
                      	
                      	;cursor blink on
                      	;destroy: none
  1179                	_CSRON:
  1179                		ds	CSRON-_CSRON
  1179                		org	CSRON
                      	
  1179  F5            		push	af
  117A  3E01          		ld	a,01h
  117C  322EFA        		ld	(CSRBLNK),a
  117F  F1            		pop	af
  1180  C9            		ret
                      	
                      	
                      	;cursor blink off
                      	;destroy: hl
  1181                	_CSROFF:
  1181                		ds	CSROFF-_CSROFF
  1181                		org	CSROFF
                      	
  1181  F5            		push	af
  1182  AF            		xor	a
  1183  322EFA        		ld	(CSRBLNK),a
  1186  3A2FFA        		ld	a,(CSRSTAT)
  1189  B7            		or	a
  118A  C48F11        		call	nz,CSRREV
  118D  F1            		pop	af
  118E  C9            		ret
                      	
                      	
                      	;reverse cursor
                      	;destroy: af,hl
  118F                	CSRREV:
  118F  212FFA        		ld	hl,CSRSTAT
  1192  7E            		ld	a,(hl)
  1193  2F            		cpl
  1194  77            		ld	(hl),a
  1195  2AAAFD        		ld	hl,(CSRAD)
  1198  25            		dec	h
  1199  25            		dec	h
  119A  7E            		ld	a,(hl)
  119B  CB77          		bit	6,a		;semi-graphic mode?
  119D  2004          		jr	nz,CSRSEMI
  119F  EE01          		xor	01h
  11A1  77            		ld	(hl),a
  11A2  C9            		ret
                      	
  11A3                	CSRSEMI:
  11A3  24            		inc	h
  11A4  24            		inc	h
  11A5  7E            		ld	a,(hl)
  11A6  2F            		cpl
  11A7  77            		ld	(hl),a
  11A8  C9            		ret
                      	
                      	
                      	;get left edge address
                      	;input: l=y+1
                      	;output: de=VRAM address
                      	;destroy: none
  11A9                	_Y2AD:ds	Y2AD-_Y2AD
  11B8                		org	Y2AD
                      	
  11B8  F5            		push	af
  11B9  7D            		ld	a,l
  11BA  3D            		dec	a
  11BB  0F            		rrca
  11BC  0F            		rrca
  11BD  0F            		rrca
  11BE  57            		ld	d,a
  11BF  E6E0          		and	0e0h
  11C1  5F            		ld	e,a
  11C2  AA            		xor	d
  11C3  57            		ld	d,a
  11C4  3A91FD        		ld	a,(VRAM)
  11C7  C602          		add	a,02h
  11C9  82            		add	a,d
  11CA  57            		ld	d,a
  11CB  F1            		pop	af
  11CC  C9            		ret
                      	
                      	
                      	;get VRAM character address (screen mode 1,2)
                      	;input: h=x+1, l=y+1
                      	;output: hl=VRAM address
                      	;destroy: none
  11CD                	_XY2AD:	ds	XY2AD-_XY2AD
  11CD                		org	XY2AD
                      	
  11CD  F5            		push	af
  11CE  D5            		push	de
  11CF  CDB811        		call	Y2AD
  11D2  25            		dec	h
  11D3  6C            		ld	l,h
  11D4  2600          		ld	h,00h
  11D6  19            		add	hl,de
  11D7  D1            		pop	de
  11D8  F1            		pop	af
  11D9  C9            		ret
                      	
                      	
                      	;delete line
                      	;input: de=left edge address (for screen mode 1,2)
                      	;destroy: none
  11DA                	_DELLIN:ds	DELLIN-_DELLIN
  11DA                		org	DELLIN
                      	
  11DA  F5            		push	af
  11DB  E5            		push	hl
  11DC  D5            		push	de
  11DD  C5            		push	bc
                      	
  11DE  3A92FD        		ld	a,(SCREEN1)
  11E1  FE02          		cp	02h
  11E3  3020          		jr	nc,DELG
                      	
  11E5  D5            		push	de		;
  11E6  15            		dec	d
  11E7  15            		dec	d
  11E8  62            		ld	h,d
  11E9  6B            		ld	l,e
  11EA  13            		inc	de
  11EB  CD2D0E        		call	GETSPA
  11EE  77            		ld	(hl),a
  11EF  011F00        		ld	bc,COLUMNS-1
  11F2  EDB0          		ldir
                      	
  11F4  E1            		pop	hl		;
  11F5  0E1F          		ld	c,COLUMNS-1
                      	
  11F7                	DELLEND:
  11F7  54            		ld	d,h
  11F8  5D            		ld	e,l
  11F9  13            		inc	de
  11FA  CD1F16        		call	GETSP
  11FD  77            		ld	(hl),a
  11FE  EDB0          		ldir
                      	
  1200  C1            		pop	bc
  1201  D1            		pop	de
  1202  E1            		pop	hl
  1203  F1            		pop	af
  1204  C9            		ret
                      	
                      	
                      	;for graphic mode (screen3,4)
  1205                	DELG:
  1205  EB            		ex	de,hl
  1206  CD7814        		call	AD2GAD
  1209  017F01        		ld	bc,0180h-1
  120C  18E9          		jr	DELLEND
                      	
                      	
                      	;for graphic mode (screen mode 3,4)
  120E                	SCRLG:
                      	;bc=a*32*12=a*(256+128)
  120E  48            		ld	c,b		;b=0
  120F  47            		ld	b,a
  1210  CB38          		srl	b
  1212  CB19          		rr	c
  1214  80            		add	a,b
  1215  47            		ld	b,a
                      	
  1216  2601          		ld	h,1
  1218  CD7D14        		call	XY2GAD
  121B  EB            		ex	de,hl
  121C  218001        		ld	hl,COLUMNS*12
  121F  19            		add	hl,de
  1220  F1            		pop	af		;up/down
  1221  3003          		jr	nc,SCRLATT
  1223  EB            		ex	de,hl
  1224  1B            		dec	de
  1225  2B            		dec	hl
                      	
  1226                	SCRLATT:
  1226  CD2D13        		call	LDIDR
  1229  C1            		pop	bc
  122A  D1            		pop	de
  122B  E1            		pop	hl
                      	
                      	;scroll INPUT prompt position
                      	;z=0: up,h=first,l=last
                      	;z=1: down,h=last,l=first
  122C  E5            		push	hl
  122D  D5            		push	de
                      	
  122E  1EFF          		ld	e,0-01h
  1230  2005          		jr	nz,SCRLIUP
  1232  1E01          		ld	e,01h
  1234  7C            		ld	a,h
  1235  65            		ld	h,l
  1236  6F            		ld	l,a
  1237                	SCRLIUP:
  1237  3AABFD        		ld	a,(CSRAD+1)
  123A  57            		ld	d,a
  123B  3AA7FE        		ld	a,(INPTPAG)
  123E  AA            		xor	d
  123F  E6F0          		and	0f0h
  1241  200E          		jr	nz,SCRLIEND
                      	
  1243  3AA4FE        		ld	a,(INPTXY)
  1246  BC            		cp	h
  1247  3808          		jr	c,SCRLIEND
  1249  2C            		inc	l
  124A  BD            		cp	l
  124B  3004          		jr	nc,SCRLIEND
  124D  83            		add	a,e
  124E  32A4FE        		ld	(INPTXY),a
  1251                	SCRLIEND:
  1251  D1            		pop	de
  1252  E1            		pop	hl
  1253  C9            		ret
                      	
                      	
                      	;print a character in CRT (no control code, no move in cursor)
                      	;input: a=character code, h=x+1, l=y+1
                      	;destroy: none
  1254                	_PRTCHXY:ds	PRTCHXY-_PRTCHXY
  1257                		org	PRTCHXY
                      	
  1257  E5            		push	hl
  1258  CDCD11        		call	XY2AD
  125B  CDAF14        		call	PRTCHAD
  125E  E1            		pop	hl
  125F  C9            		ret
                      	
                      	
                      	;scroll up
                      	;input: h=first line+1, l=last line+1
                      	;destroy: af
  1260                	_SCRLUP:ds	SCRLUP-_SCRLUP
  1260                		org	SCRLUP
                      	
  1260  7D            		ld	a,l
  1261  94            		sub	h		;a=(LASTLIN)-(CONSOL1) < 16
                      	;	ret	z
                      	;	ret	c
  1262  E5            		push	hl
                      	
                      	;c-flag=0:scroll up, c-flag=1:scroll down
  1263                	SCRLUD:
  1263  D5            		push	de
  1264  C5            		push	bc
  1265  F5            		push	af		;up/down
                      	
                      	;line connection status
  1266  6C            		ld	l,h
  1267  E5            		push	hl
  1268  F5            		push	af		;up/down
  1269  CD4F14        		call	SETLINE		;get work area address
  126C  54            		ld	d,h
  126D  5D            		ld	e,l
  126E  0600          		ld	b,00h
  1270  4F            		ld	c,a
  1271  F1            		pop	af		;up/down
  1272  3005          		jr	nc,SCRLNC1
  1274  12            		ld	(de),a		;>0
  1275  1D            		dec	e		;dec de
  1276  2D            		dec	l		;dec hl
  1277  2D            		dec	l		;dec hl
  1278  2D            		dec	l		;dec hl
  1279                	SCRLNC1:
  1279  2C            		inc	l		;inc hl
  127A  CD2D13        		call	LDIDR
                      	
  127D  12            		ld	(de),a		;>0
  127E  2A92FD        		ld	hl,(SCREEN1)
  1281  2D            		dec	l
  1282  2D            		dec	l
  1283  E1            		pop	hl
  1284  F20E12        		jp	p,SCRLG		;screen mode 3,4
                      	
  1287  CD853F        		call	MUL32
  128A  CDB811        		call	Y2AD
  128D  212000        		ld	hl,COLUMNS
  1290  19            		add	hl,de
  1291  F1            		pop	af		;up/down
  1292  F5            		push	af		;up/down
  1293  3003          		jr	nc,SCRLNC2
  1295  EB            		ex	de,hl
  1296  1B            		dec	de
  1297  2B            		dec	hl
                      	
  1298                	SCRLNC2:
  1298  E5            		push	hl
  1299  D5            		push	de
  129A  C5            		push	bc
  129B  CD2D13        		call	LDIDR
  129E  C1            		pop	bc
  129F  D1            		pop	de
  12A0  E1            		pop	hl
                      	
                      	;attribute
  12A1  25            		dec	h
  12A2  25            		dec	h
  12A3  15            		dec	d
  12A4  15            		dec	d
  12A5  F1            		pop	af		;up/down
  12A6  C32612        		jp	SCRLATT
                      	
                      	
                      	;scroll down
                      	;input: h=last line+1, l=first line+1
                      	;destroy: af
  12A9                	_SCRLDW:ds	SCRLDW-_SCRLDW
  12A9                		org	SCRLDW
                      	
  12A9  7C            		ld	a,h
  12AA  95            		sub	l
                      	;	ret	z
                      	;	ret	c
  12AB  E5            		push	hl
  12AC  37            		scf			;set c-flag
  12AD  18B4          		jr	SCRLUD
                      	
                      	
                      	;print function key
                      	;input: none
                      	;output: none
                      	;destroy: af
  12AF                	_PRTFKEY:ds	PRTFKEY-_PRTFKEY
  12B5                		org	PRTFKEY
                      	
  12B5  AF            		xor	a
  12B6  32A7FD        		ld	(FKEYSFT),a
                      	
  12B9                	PRTFKEY2:
  12B9  3A92FD        		ld	a,(SCREEN1)
  12BC  FE02          		cp	02h
  12BE  D0            		ret	nc		;screen mode 3 or 4
                      	
  12BF  E5            		push	hl
  12C0  D5            		push	de
  12C1  C5            		push	bc
                      	
  12C2  2A20FA        		ld	hl,(HEIGHT)
  12C5  CDB811        		call	Y2AD
                      	
  12C8  CD6110        		call	STICK		;bit0=shift
  12CB  2AA6FD        		ld	hl,(CONSOL3)	;(CONSOL3)=0 or 1
  12CE  A5            		and	l
  12CF  07            		rlca
  12D0  B5            		or	l
  12D1  21A7FD        		ld	hl,FKEYSFT
  12D4  BE            		cp	(hl)
  12D5  284D          		jr	z,PFKEND
                      	
  12D7  77            		ld	(hl),a
  12D8  0F            		rrca
  12D9  304D          		jr	nc,DELFK
                      	
  12DB  EB            		ex	de,hl
  12DC  113DFB        		ld	de,FKEYTBL
  12DF  0F            		rrca
  12E0  3002          		jr	nc,PFKSTRT
  12E2  1E65          		ld	e,FKEYTBL+8*5-(FKEYTBL+8*5)/256*256	;de=FKEYTBL+8*5
                      	
  12E4                	PFKSTRT:
  12E4  CD6113        		call	CHRREV
  12E7  3A8FFD        		ld	a,(SCREEN2)
  12EA  C631          		add	a,'1'
  12EC  CDCA14        		call	PRT12
                      	
  12EF  CD6113        		call	CHRREV
  12F2  3E20          		ld	a,' '
  12F4  CDCA14        		call	PRT12
                      	
  12F7  0E05          		ld	c,05h
  12F9                	FKEYLP1:
  12F9  CD6113        		call	CHRREV
  12FC  0605          		ld	b,05h
  12FE                	FKEYLP2:
  12FE  1A            		ld	a,(de)
  12FF  B7            		or	a
  1300  280C          		jr	z,FKEYNEXT
  1302  FE20          		cp	' '
  1304  3002          		jr	nc,FKEYNC
  1306  3E20          		ld	a,' '
  1308                	FKEYNC:
  1308  CDCA14        		call	PRT12
  130B  1C            		inc	e		;inc de
  130C  10F0          		djnz	FKEYLP2
                      	
  130E                	FKEYNEXT:
  130E  04            		inc	b
  130F                	FKEYLP3:
  130F  78            		ld	a,b
  1310  3D            		dec	a
  1311  CC6113        		call	z,CHRREV
  1314  3E20          		ld	a,' '
  1316  CDCA14        		call	PRT12
  1319  1C            		inc	e		;inc de
  131A  10F3          		djnz	FKEYLP3
                      	
  131C  1C            		inc	e		;inc de
  131D  1C            		inc	e		;inc de
  131E  0D            		dec	c
  131F  20D8          		jr	nz,FKEYLP1
                      	
  1321                	PFKEND2:
  1321  CD6F1D        		call	SETCNSL2
  1324                	PFKEND:
  1324  C1            		pop	bc
  1325  D1            		pop	de
  1326  E1            		pop	hl
  1327  C9            		ret
                      	
  1328                	DELFK:
  1328  CDDA11        		call	DELLIN
  132B  18F4          		jr	PFKEND2
                      	
                      	
                      	;ldir or lddr
                      	;input: bc,de,hl,c-flag(0=ldir,1=lddr)
                      	;output: bc=0,de,hl
                      	;destroy: f
  132D                	LDIDR:
  132D  3803          		jr	c,LDIDRC
  132F  EDB0          		ldir
  1331  C9            		ret
  1332                	LDIDRC:
  1332  EDB8          		lddr
  1334  C9            		ret
                      	
                      	
                      	;get page data address
                      	;input: a=page-1
                      	;output: hl=address, bc=size
                      	;destroy: af
  1335                	GETPGAD:
  1335  21C8FD        		ld	hl,PAGE1
  1338  013700        		ld	bc,PAGE2-PAGE1
  133B  B7            		or	a
  133C                	PGADLP:
  133C  C8            		ret	z
  133D  09            		add	hl,bc
  133E  3D            		dec	a
  133F  18FB          		jr	PGADLP
                      	
                      	
                      	;get corrected color parameter
                      	;output: a
                      	;destroy: f
  1341                	CORRC:
  1341  3A92FD        		ld	a,(SCREEN1)
  1344  CB3F          		srl	a
  1346  3A93FD        		ld	a,(COLOR1)
  1349  3008          		jr	nc,CORRC13
  134B  200F          		jr	nz,CORRC4
                      	
                      	;screen mode 2: 0~8
  134D                	CORRC2:
  134D  FE08          		cp	08h
  134F  D8            		ret	c
  1350  3E08          		ld	a,08h
  1352  C9            		ret
                      	
                      	;screen mode 1,3: 1~4
  1353                	CORRC13:
  1353  B7            		or	a
  1354  2808          		jr	z,CORRCZ
  1356  FE04          		cp	04h
  1358  D8            		ret	c
  1359  3E04          		ld	a,04h
  135B  C9            		ret
                      	
                      	;screen mode 4: 0~1
  135C                	CORRC4:
  135C  B7            		or	a
  135D  C8            		ret	z
  135E                	CORRCZ:
  135E  3E01          		ld	a,01h
  1360  C9            		ret
                      	
                      	
                      	;reverse character attribute
                      	;destroy: af
  1361                	CHRREV:
  1361  CD4113        		call	CORRC
  1364  EE07          		xor	07h
  1366  FE05          		cp	05h
  1368  3802          		jr	c,REVEND
  136A  E603          		and	03h
  136C                	REVEND:
  136C  3293FD        		ld	(COLOR1),a
  136F  C3C015        		jp	SETATT
                      	
                      	
                      	;change to text screen
                      	;input: none
                      	;output: none
                      	;destroy: af
  1372                	CHGTXT:
  1372  3A90FD        		ld	a,(SCREEN3)
  1375  CD0C14        		call	CHGACT
  1378  3A92FD        		ld	a,(SCREEN1)
  137B  FE02          		cp	02h
  137D  D8            		ret	c
  137E  AF            		xor	a
  137F                	CHGSCR:
  137F  CD0C14        		call	CHGACT
  1382  1869          		jr	CHGDSP
                      	
                      	
                      	;change screen mode
                      	;input: a=mode-1
                      	;destroy: af,de
  1384                	_CHGMOD:ds	CHGMOD-_CHGMOD
  1390                		org	CHGMOD
                      	
  1390  FE04          		cp	04h
  1392  D2E503        		jp	nc,FCERR
  1395  E5            		push	hl
  1396  2192FD        		ld	hl,SCREEN1
  1399  5E            		ld	e,(hl)		;
  139A  BB            		cp	e
  139B  2848          		jr	z,CMODEND
  139D  77            		ld	(hl),a
                      	
  139E  C5            		push	bc
  139F  F5            		push	af		;;
                      	
  13A0  FE02          		cp	02h
  13A2  3E20          		ld	a,COLUMNS	;screen mode 1,2,4:width=32
  13A4  2001          		jr	nz,SETWID
  13A6  1F            		rra			;screen mode 3:width=16
  13A7                	SETWID:
  13A7  32ACFD        		ld	(WIDTH),a
                      	
  13AA  2196FD        		ld	hl,M1COLOR
  13AD  010300        		ld	bc,0003h
  13B0  50            		ld	d,b		;b=0
  13B1  19            		add	hl,de		;
  13B2  19            		add	hl,de
  13B3  19            		add	hl,de
  13B4  EB            		ex	de,hl
  13B5  2193FD        		ld	hl,COLOR1
  13B8  EDB0          		ldir
                      	
  13BA  F1            		pop	af		;;
  13BB  2196FD        		ld	hl,M1COLOR
  13BE  50            		ld	d,b		;b=0
  13BF  5F            		ld	e,a
  13C0  19            		add	hl,de
  13C1  19            		add	hl,de
  13C2  19            		add	hl,de
  13C3  1193FD        		ld	de,COLOR1
  13C6  0E03          		ld	c,03h		;b=0
  13C8  EDB0          		ldir
                      	
  13CA  CD2D0E        		call	GETSPA
  13CD  2A90FD        		ld	hl,(VRAM-1)	;h=(VRAM)
  13D0  68            		ld	l,b		;b=0
  13D1  77            		ld	(hl),a
  13D2  04            		inc	b
  13D3  54            		ld	d,h
  13D4  58            		ld	e,b		;de=hl+1
  13D5  0D            		dec	c		;bc=1ffh
  13D6  EDB0          		ldir
                      	
  13D8  CD6F1D        		call	SETCNSL2
  13DB  0E01          		ld	c,01h
  13DD  3A20FA        		ld	a,(HEIGHT)
  13E0  37            		scf
  13E1  CDDC1D        		call	CLSMAIN
                      	
  13E4  C1            		pop	bc
  13E5                	CMODEND:
  13E5  E1            		pop	hl
  13E6  C9            		ret
                      	
                      	
                      	;change display page
                      	;page1=8000h or c000h	out (0b0h),4 or 0
                      	;page2=e000h		out (0b0h),2
                      	;page3=c000h		out (0b0h),0
                      	;page4=a000h		out (0b0h),6
                      	;input: a=page-1
                      	;destroy: af
  13E7                	_CHGDSP:ds	CHGDSP-_CHGDSP
  13ED                		org	CHGDSP
                      	
  13ED  3290FD        		ld	(SCREEN3),a
  13F0  B7            		or	a
  13F1  2006          		jr	nz,DSPOK
  13F3  3A2AFF        		ld	a,(BASICAD+1)	;84h or c4h
  13F6  07            		rlca
  13F7  07            		rlca
  13F8  87            		add	a,a		;32KB:page1=8000h
                      					;16KB:page1=c000h
  13F9                	DSPOK:
                      	;0,1,2,3->4,2,0,6
  13F9  3C            		inc	a
  13FA  2F            		cpl
  13FB  07            		rlca
                      	;	and	06h
                      	
  13FC  C5            		push	bc
  13FD  0606          		ld	b,00000110b
  13FF  CD541B        		call	OUTB0H
  1402  C1            		pop	bc
                      	
  1403  C3B912        		jp	PRTFKEY2
                      	
                      	
                      	;change active page
                      	;input: a=page-1
                      	;destroy: none
  1406                	_CHGACT:ds	CHGACT-_CHGACT
  140C                		org	CHGACT
                      	
  140C  F5            		push	af
  140D  E5            		push	hl
                      	
  140E  218FFD        		ld	hl,SCREEN2
  1411  BE            		cp	(hl)
  1412  281C          		jr	z,ACTEND
                      	
  1414  D5            		push	de
  1415  C5            		push	bc
                      	
  1416  57            		ld	d,a		;
  1417  7E            		ld	a,(hl)
  1418  72            		ld	(hl),d		;
  1419  CD3513        		call	GETPGAD
  141C  7A            		ld	a,d		;
  141D  EB            		ex	de,hl
  141E  2191FD        		ld	hl,VRAM		;top of active page data
  1421  EDB0          		ldir
                      	
  1423  CD3513        		call	GETPGAD
  1426  1191FD        		ld	de,VRAM
  1429  EDB0          		ldir
                      	
  142B  CDB512        		call	PRTFKEY
                      	
  142E  C1            		pop	bc
  142F  D1            		pop	de
                      	
  1430                	ACTEND:
  1430  E1            		pop	hl
  1431  F1            		pop	af
  1432  C9            		ret
                      	
                      	
                      	;check connection to previous character
                      	;input: hl=VRAM address
                      	;output: z-flag(1:connect)
                      	;destroy: af
  1433                	CHKLINE:
  1433  7D            		ld	a,l
  1434  E61F          		and	1fh
  1436  2010          		jr	nz,CHKLINENZ
  1438  E5            		push	hl
  1439  29            		add	hl,hl
  143A  29            		add	hl,hl
  143B  29            		add	hl,hl
  143C  7C            		ld	a,h
  143D  E60F          		and	0fh
  143F  21B6FD        		ld	hl,LINEST-1
  1442  85            		add	a,l		;no carry
  1443  6F            		ld	l,a
  1444  7E            		ld	a,(hl)
  1445  E1            		pop	hl
  1446  B7            		or	a
  1447  C9            		ret
                      	
  1448                	CHKLINENZ:
  1448  AF            		xor	a
  1449  C9            		ret
                      	
                      	
                      	;cut connection before cursor line
                      	;output: hl=line status address
                      	;destroy: af,de
  144A                	CUTLINE:
  144A  3AA8FD        		ld	a,(CSRY)	;a>0
                      	
                      	;input: a=y+1
                      	;output: hl=line status address
                      	;destroy: f,de
  144D                	CUTLINE2:
  144D  6F            		ld	l,a
  144E  2D            		dec	l
                      	;	jp	SETLINE
                      	
                      	;set line connection status (connection to next line)
                      	;input: l=y+1, a=data (0=connect or not)
                      	;output: hl=line status address
                      	;destroy: f,de
  144F                	SETLINE:
  144F  2600          		ld	h,00h
  1451  11B6FD        		ld	de,LINEST-1
  1454  19            		add	hl,de
  1455  77            		ld	(hl),a
  1456  C9            		ret
                      	
                      	
                      	;convert character VRAM address to graphic VRAM address
                      	;(screen mode 1,2 -> screen mode 3,4)
                      	;input: hl=character VRAM address
                      	;output: hl=graphic VRAM address
                      	;destroy: none
  1457                	_AD2GAD:ds	AD2GAD-_AD2GAD
  1478                		org	AD2GAD
                      	
  1478  F5            		push	af
  1479  CD5011        		call	AD2XY
  147C  F1            		pop	af
                      	;	jr	XY2GAD
                      	
                      	
                      	;get VRAM address (screen mode 3,4)
                      	;input: h=x+1, l=y+1
                      	;output: hl=graphic VRAM address =(VRAM+200h)+y*0180h+x
                      	;destroy: none
  147D                	XY2GAD:
  147D  F5            		push	af
  147E  25            		dec	h
  147F  2D            		dec	l
  1480  3A92FD        		ld	a,(SCREEN1)
  1483  FE02          		cp	02h
  1485  2002          		jr	nz,XY2GADC
  1487  CB24          		sla	h		;screen mode 3
  1489                	XY2GADC:
  1489  CB24          		sla	h
  148B  3A91FD        		ld	a,(VRAM)
  148E  C602          		add	a,02h
  1490  85            		add	a,l
  1491  CB3D          		srl	l
  1493  CB1C          		rr	h
  1495  85            		add	a,l
  1496  6C            		ld	l,h
  1497  67            		ld	h,a
  1498  F1            		pop	af
  1499  C9            		ret
                      	
                      	
                      	;get CGROM address (DE=6000h+A*10h)
                      	;input: a=character code
                      	;output: de=address
                      	;destroy: none
  149A                	_CGROM:	ds	CGROM-_CGROM
  14A0                		org	CGROM
                      	
  14A0  F5            		push	af
  14A1  07            		rlca
  14A2  07            		rlca
  14A3  07            		rlca
  14A4  07            		rlca
  14A5  57            		ld	d,a
  14A6  E6F0          		and	0f0h
  14A8  5F            		ld	e,a
  14A9  AA            		xor	d
  14AA  C660          		add	a,60h
  14AC  57            		ld	d,a
  14AD  F1            		pop	af
  14AE  C9            		ret
                      	
                      	;	push	af		;push flag
                      	;	ex	de,hl
                      	;	ld	h,06h
                      	;	ld	l,a
                      	;	add	hl,hl
                      	;	add	hl,hl
                      	;	add	hl,hl
                      	;	add	hl,hl
                      	;	ex	de,hl
                      	;	pop	af		;pop flag
                      	;	ret
                      	
                      	
                      	;print a character in CRT (no control code, no move in cursor)
                      	;input: a=character code, hl=VRAM address
                      	;destroy: none
  14AF                	_PRTCHAD:ds	PRTCHAD-_PRTCHAD
  14AF                		org	PRTCHAD
                      	
  14AF  E5            		push	hl
  14B0  F5            		push	af
  14B1  3A92FD        		ld	a,(SCREEN1)
  14B4  FE02          		cp	02h
  14B6  380A          		jr	c,PRTCHXY12
                      	
                      	;screen mode 3,4
  14B8  CD5011        		call	AD2XY
  14BB  F1            		pop	af
  14BC  F5            		push	af
  14BD  CDD514        		call	PRT34XY
  14C0  1805          		jr	PRTCHADEND
                      	
  14C2                	PRTCHXY12:
  14C2  F1            		pop	af
  14C3  F5            		push	af
  14C4  CDCA14        		call	PRT12
                      	
  14C7                	PRTCHADEND:
  14C7  F1            		pop	af
  14C8  E1            		pop	hl
  14C9  C9            		ret
                      	
                      	
                      	;print a character in text mode (screen mode 1,2)
                      	;input: a=character code, hl=VRAM address
                      	;output: hl=hl+1
                      	;destroy: af
  14CA                	PRT12:
  14CA  77            		ld	(hl),a
  14CB  CD0716        		call	CNVATT1
  14CE  25            		dec	h
  14CF  25            		dec	h
  14D0  77            		ld	(hl),a
  14D1  24            		inc	h
  14D2  24            		inc	h
  14D3  23            		inc	hl
  14D4  C9            		ret
                      	
                      	
                      	;print a character in graphic mode (screen mode 3,4)
                      	;input: a=character code, h=x+1, l=y+1
                      	;destroy af,hl
  14D5                	PRT34XY:
  14D5  D5            		push	de
  14D6  C5            		push	bc
                      	
  14D7  CDA014        		call	CGROM
  14DA  3A93FD        		ld	a,(COLOR1)
  14DD  CDC015        		call	SETATT
                      	
  14E0  CD7D14        		call	XY2GAD
                      	
  14E3  3E04          		ld	a,04h
  14E5  D393          		out	(93h),a		;CGROM ON
                      	
  14E7  060C          		ld	b,0ch
  14E9                	PRT34XYLP:
  14E9  D5            		push	de
  14EA  3A92FD        		ld	a,(SCREEN1)
  14ED  0F            		rrca			;
  14EE  1A            		ld	a,(de)
  14EF  3005          		jr	nc,CALL3	;
  14F1  CD1915        		call	PRT4
  14F4  1804          		jr	CALL34END
  14F6                	CALL3:
  14F6  CD0915        		call	PRT3
  14F9  2B            		dec	hl
                      	
  14FA                	CALL34END:
  14FA  112000        		ld	de,COLUMNS
  14FD  19            		add	hl,de
  14FE  D1            		pop	de
  14FF  1C            		inc	e		;inc de
  1500  10E7          		djnz	PRT34XYLP
                      	
  1502  3E05          		ld	a,05h
  1504  D393          		out	(93h),a		;CGROM OFF
                      	
  1506  C1            		pop	bc
  1507  D1            		pop	de
  1508  C9            		ret
                      	
  1509                	PRT3:
  1509  5F            		ld	e,a
  150A  CD0E15        		call	PRT3HALF
  150D  23            		inc	hl
  150E                	PRT3HALF:
  150E  1604          		ld	d,04h
  1510                	PRT3LP:
  1510  CB03          		rlc	e
  1512  17            		rla
  1513  0F            		rrca
  1514  07            		rlca
  1515  17            		rla
  1516  15            		dec	d
  1517  20F7          		jr	nz,PRT3LP
                      	
  1519                	PRT4:
  1519  4F            		ld	c,a
  151A  3AACFE        		ld	a,(ATTDAT)
  151D  AE            		xor	(hl)
  151E  A1            		and	c
  151F  AE            		xor	(hl)
  1520  77            		ld	(hl),a
  1521  C9            		ret
                      	
                      	
                      	;click sound
                      	;destroy: de
  1522                	CLICK:
  1522  F5            		push	af
  1523  3A2DFA        		ld	a,(CONSOL4)
  1526  B7            		or	a
  1527  2823          		jr	z,SKPCLK
                      	
  1529  C5            		push	bc
                      	
  152A  3E08          		ld	a,08h		;register8=ch.A volume
  152C  1E0F          		ld	e,0fh
  152E  CDBE1B        		call	SETPSG2
  1531  D5            		push	de		;
                      	
  1532  3E01          		ld	a,01h		;register1=ch.A coarse tune
  1534  1E00          		ld	e,00h
  1536  43            		ld	b,e
  1537  4F            		ld	c,a
  1538  CDBE1B        		call	SETPSG2		;;
                      	
  153B  CDE825        		call	WAITLP		;bc=0001h
  153E  3E01          		ld	a,01h		;register1=ch.A coarse tune
  1540  5A            		ld	e,d		;;
  1541  CDC51B        		call	SETPSG
                      	
  1544  3E08          		ld	a,08h		;register8=ch.A volume
  1546  D1            		pop	de		;
  1547  5A            		ld	e,d
  1548  CDC51B        		call	SETPSG
                      	
  154B  C1            		pop	bc
                      	
  154C                	SKPCLK:
  154C  F1            		pop	af
  154D  C9            		ret
                      	
                      	
                      	;graphic cordinates -> screen mode cordinates
                      	;input: bc=graphic X, de=graphic Y
                      	;output: bc=screen mode X, de=screen mode Y, (c-flag=1 for EXAS BASIC compiler)
                      	;destroy: af
  154E                	_GXY2SXY:ds	GXY2SXY-_GXY2SXY
  1578                		org	GXY2SXY
                      	
  1578  E5            		push	hl
  1579  CDF22B        		call	CHKGXY
  157C  E1            		pop	hl
  157D  3A92FD        		ld	a,(SCREEN1)
  1580  CB3F          		srl	a
  1582  380F          		jr	c,GXY2SXY24
  1584  2009          		jr	nz,GXY2SXY3
                      	
                      	;screen mode 1: 32x16
  1586                	GXY2SXY1:
  1586  C5            		push	bc
  1587  CD9A15        		call	DIV12
  158A  C1            		pop	bc
  158B  CB39          		srl	c
  158D                	SRLC2:
  158D  CB39          		srl	c
                      	
                      	;screen mode 3: 128x192
  158F                	GXY2SXY3:
  158F  CB39          		srl	c
  1591  37            		scf			;for EXAS BASIC compiler
  1592  C9            		ret
                      	
  1593                	GXY2SXY24:
                      	;	scf
  1593  C0            		ret	nz		;screen mode 4: 256x192
                      	
                      	;screen mode 2: 64x48
  1594                	GXY2SXY2:
  1594  CB3B          		srl	e
  1596  CB3B          		srl	e
  1598  18F3          		jr	SRLC2
                      	
                      	
                      	;de=de/12
                      	;input: de<192
                      	;output: de=int(de/12), a=de mod 12
                      	;destroy: f,b=0,l
  159A                	DIV12:
  159A  7B            		ld	a,e
  159B  5A            		ld	e,d		;d=0
  159C  2E60          		ld	l,01100000b
  159E  0604          		ld	b,04h
  15A0                	DIV12LP:
  15A0  BD            		cp	l
  15A1  3801          		jr	c,DIV12C
  15A3  95            		sub	l
  15A4                	DIV12C:
  15A4  3F            		ccf
  15A5  CB13          		rl	e
  15A7  CB3D          		srl	l
  15A9  10F5          		djnz	DIV12LP
  15AB  C9            		ret
                      	
                      	
                      	;graphic cordinates -> VARM address
                      	; 60: screen1=+0000h, screen2-4=+0200h
                      	; 66: screen1=+0000h, screen2=+0400h, screen3-4=+2000h
                      	;input: bc=graphic X, de=graphic Y
                      	;output: hl=VRAM address, a=bit
                      	;destroy: af,bc,e
  15AC                	GXY2AD:
  15AC  CD7815        		call	GXY2SXY
  15AF  C3BA15        		jp	SXY2AD
                      	
                      	
                      	;screen mode cordinates -> VARM address
                      	; 60: screen1=+0000h, screen2-4=+0200h
                      	; 66: screen1=+0000h, screen2=+0400h, screen3-4=+2000h
                      	;input: bc=screen mode X, de=screen mode Y
                      	;output: hl=(fdb3-fdb4)=attribute address, a=(fdb2)=bit
                      	;destroy: f
  15B2                	_SXY2AD:ds	SXY2AD-_SXY2AD
  15BA                		org	SXY2AD
                      	
  15BA  C3B33F        		jp	SXY2ADMAIN
                      	
                      	
                      	;set attribute data
                      	;set attribute data
                      	;input: a=color code
                      	;output: a,(ATTDAT)=attribute, (c-flag=0 for EXAS BASIC compiler)
                      	;destroy: f
  15BD                	_SETATT:ds	SETATT-_SETATT
  15C0                		org	SETATT
                      	
  15C0  CDD815        		call	CNVATT
  15C3  32ACFE        		ld	(ATTDAT),a
  15C6  C9            		ret
                      	
                      	
                      	;get color code
                      	;input: (fdb3h-fdb4h)=attribute address, (fdb2h)=bit
                      	;output: a=color
                      	;destroy: f,hl
  15C7                	_GETCOLR:ds	GETCOLR-_GETCOLR
  15D5                		org	GETCOLR
                      	
  15D5  C3763E        		jp	GETCOLRMAIN
                      	
                      	
                      	;convert to attribute data (screen mode 1)
                      	; or color code (screen moode 2)
                      	; or bit pattern (screen mode 3,4)
                      	;input: a=color code
                      	;output: a=attribute, (c-flag=0 for EXAS BASIC compiler)
                      	;destroy: f
  15D8                	CNVATT:
  15D8  F5            		push	af		;color
  15D9  3A92FD        		ld	a,(SCREEN1)
  15DC  CB3F          		srl	a
  15DE  281C          		jr	z,ATT12		;screen mode 1 or 2
  15E0  3006          		jr	nc,ATT3		;screen mode 3
                      	
  15E2                	ATT4:
  15E2  F1            		pop	af
  15E3  B7            		or	a
  15E4  C8            		ret	z
  15E5  3EFF          		ld	a,0ffh
  15E7  C9            		ret
                      	
  15E8                	ATT3:
  15E8  F1            		pop	af
  15E9  B7            		or	a
  15EA  C8            		ret	z
                      	
  15EB  C5            		push	bc
  15EC  0604          		ld	b,04h
  15EE  B8            		cp	b
  15EF  3801          		jr	c,ATT3C
  15F1  78            		ld	a,b
  15F2                	ATT3C:
  15F2  3D            		dec	a
  15F3  4F            		ld	c,a
  15F4  05            		dec	b		;=3
  15F5                	ATT3LP:
  15F5  0F            		rrca
  15F6  0F            		rrca
  15F7  B1            		or	c
  15F8  10FB          		djnz	ATT3LP
  15FA  C1            		pop	bc
  15FB  C9            		ret
                      	
  15FC                	ATT12:
  15FC  300D          		jr	nc,ATT1
                      	
  15FE                	ATT2:
  15FE  F1            		pop	af
  15FF  FE09          		cp	09h
  1601  3F            		ccf			;reset c-flag for EXAS BASIC compiler
  1602  D0            		ret	nc
  1603  3E08          		ld	a,08h
  1605  B7            		or	a		;reset c-flag for EXAS BASIC compiler
  1606  C9            		ret
                      	
                      	
                      	;get attribue data for screen mode 1
                      	;output: a=attirbute value
                      	;destroy: f
  1607                	CNVATT1:
  1607  3A93FD        		ld	a,(COLOR1)
  160A  F5            		push	af
  160B                	ATT1:
  160B  F1            		pop	af
  160C  B7            		or	a
  160D  2807          		jr	z,ATT1OK
  160F  3D            		dec	a
  1610  FE04          		cp	04h
  1612  3802          		jr	c,ATT1OK
  1614  3E03          		ld	a,03h
  1616                	ATT1OK:
  1616  C620          		add	a,20h
  1618  E5            		push	hl
  1619  2195FD        		ld	hl,COLOR3
  161C  AE            		xor	(hl)
  161D  E1            		pop	hl
  161E  C9            		ret
                      	
                      	
                      	;get space character data for scroll
                      	;output: a
                      	;destroy: f
  161F                	GETSP:
  161F  3A92FD        		ld	a,(SCREEN1)
  1622  3D            		dec	a
  1623  3E20          		ld	a,' '
  1625  F8            		ret	m		;screen mode 1
  1626  3A94FD        		ld	a,(COLOR2)
  1629  20AD          		jr	nz,CNVATT	;screen mode 3,4
                      	
                      	;screen mode 2
  162B                	GETSP2:
  162B  B7            		or	a
  162C  2806          		jr	z,GETSP2Z	;color,0
  162E  3D            		dec	a
  162F  0F            		rrca
  1630  0F            		rrca
  1631  F63F          		or	3fh
  1633  C9            		ret
                      	
  1634                	GETSP2Z:
  1634  3A93FD        		ld	a,(COLOR1)
  1637  B7            		or	a
  1638  C8            		ret	z
  1639  3D            		dec	a
  163A  FE04          		cp	04h
  163C  3802          		jr	c,GETSP2ZC
  163E  D604          		sub	04h
  1640                	GETSP2ZC:
  1640  0F            		rrca
  1641  0F            		rrca
  1642  C9            		ret
                      	
                      	
                      	;cold start (initialize hardware)
  1643                	COLD:
                      	
                      	;8255 (port 93h)
  1643  019306        		ld	bc,0693h
  1646  21DB00        		ld	hl,IOTBL93
  1649  EDB3          		otir
                      	
                      	;8251 (port 81h)
  164B  018105        		ld	bc,0581h
                      	;	ld	hl,IOTBL81
  164E  EDB3          		otir
  1650  3E0C          		ld	a,0ch		;enable RS-232C interrupt
  1652  CD8F0E        		call	OUT90H
                      	
                      	;for mkII
                      	;port f0h-f8h and port c1h
  1655  01EF09        		ld	bc,09efh
                      	;	ld	hl,IOTBLF0
  1658                	F0LP:
  1658  0C            		inc	c
  1659  EDA3          		outi
  165B  20FB          		jr	nz,F0LP
  165D  3E06          		ld	a,06h
  165F  D3C1          		out	(0c1h),a	;32x16 text mode
                      	
                      	;interrupt
                      	;	ld	hl,INTTBL
  1661  1102FA        		ld	de,0fa02h
  1664  0E16          		ld	c,11*2		;b=0
  1666  EDB0          		ldir
  1668  7A            		ld	a,d
  1669  ED47          		ld	i,a
  166B  ED5E          		im	2
                      	
                      	;clear work area
  166D  AF            		xor	a
  166E  62            		ld	h,d
  166F  6B            		ld	l,e
  1670  77            		ld	(hl),a
  1671  13            		inc	de
  1672  01E705        		ld	bc,0ffffh-0fa18h
  1675  EDB0          		ldir
                      	
                      	;stack pointer
  1677  31CDF9        		ld	sp,0f9ffh-50	;temporary
                      	
                      	;relay,VRAM,timer
                      	;	xor	a
  167A  D3B0          		out	(0b0h),a	;bit3=CMT relay, bit21=VRAM address=c000, bit0=timer on
                      	
  167C  3D            		dec	a
  167D  321FFA        		ld	(BAUD),a	;a=ffh:1200 baud
                      	
                      	;misc
  1680  3E20          		ld	a,' '
  1682  321EFA        		ld	(ASTSTAT),a
  1685  3E01          		ld	a,01h
  1687  322DFA        		ld	(CONSOL4),a
  168A  3E0E          		ld	a,0eh
  168C  3259FA        		ld	(CMMCNST),a	;used by EXAS BASIC compiler
                      	
                      	;hook
  168F  218AFF        		ld	hl,HOOK
  1692  1E03          		ld	e,03h		;d=0
  1694  061E          		ld	b,1eh
  1696                	COLDLP1:
  1696  36C9          		ld	(hl),0c9h
  1698  19            		add	hl,de
  1699  10FB          		djnz	COLDLP1
                      	
                      	
                      	;buffer
  169B  21B9FB        		ld	hl,KEYBUF
  169E  1E40          		ld	e,40h		;d=0
  16A0  2293FB        		ld	(KYBFAD),hl
  16A3  19            		add	hl,de		;hl=RSBUF
  16A4  2299FB        		ld	(RSBFAD),hl
  16A7  19            		add	hl,de		;hl=BUFA
  16A8  22A5FB        		ld	(BUFAAD),hl
  16AB  19            		add	hl,de		;hl=BUFB
  16AC  22ABFB        		ld	(BUFAAD+6),hl
  16AF  19            		add	hl,de		;hl=BUFC
  16B0  22B1FB        		ld	(BUFAAD+12),hl
                      	
  16B3  2192FB        		ld	hl,KYBFSZ
  16B6  1E06          		ld	e,06h		;d=0
  16B8  43            		ld	b,e		;e=6
  16B9                	COLDLP2:
  16B9  363F          		ld	(hl),3fh	;KYBFSZ,RSBFSZ,,BUFASZ,BUFBSZ,BUFCSZ
  16BB  19            		add	hl,de
  16BC  10FB          		djnz	COLDLP2
                      	
                      	;command jump table
  16BE  219801        		ld	hl,CMDLST
  16C1  1161FA        		ld	de,CMDTBL
  16C4  0E56          		ld	c,2*(CMDLAST-80h+1)	;b=0
  16C6  EDB0          		ldir
                      	
                      	;function jump table
                      	;	ld	hl,FNCLST
  16C8  11E5FA        		ld	de,FNCTBL
  16CB  0E3C          		ld	c,2*(FNCLAST-FNC1ST+1)	;b=0
  16CD  EDB0          		ldir
                      	
                      	;screen
  16CF  3E10          		ld	a,ROWS
  16D1  3220FA        		ld	(HEIGHT),a
                      	
  16D4  1191FD        		ld	de,VRAM		;top of active page data
  16D7  3E05          		ld	a,05h
  16D9                	COLDLP3:
  16D9  214A01        		ld	hl,PAGEDATA
  16DC  0E37          		ld	c,PAGE1-VRAM	;b=0
  16DE  EDB0          		ldir
  16E0  3D            		dec	a
  16E1  20F6          		jr	nz,COLDLP3
                      	
                      	;	ld	de,PAGE4+(PAGE4-PAGE3)
  16E3  EB            		ex	de,hl
  16E4  11C9FF        		ld	de,0-(PAGE4-PAGE3)
  16E7  3EA0          		ld	a,0a0h
  16E9                	COLDLP5:
  16E9  19            		add	hl,de
  16EA  77            		ld	(hl),a		;(PAGE4)=a0h, (PAGE3)=c0h, (PAGE2)=e0h
  16EB  C620          		add	a,20h
  16ED  20FA          		jr	nz,COLDLP5
                      	
                      	;RND()
                      	;	call	SETZERO
  16EF  CDB53B        		call	RNDMNS
                      	
                      	;16KB or 32KB?
  16F2  210080        		ld	hl,8000h
                      	
                      	;for iP6/iP6win: 16KB if patched
  16F5  3AEA10        		ld	a,(PATCH1)
  16F8  B7            		or	a
  16F9  2008          		jr	nz,RAM16K
                      	
  16FB  7E            		ld	a,(hl)
  16FC  2F            		cpl
  16FD  77            		ld	(hl),a
  16FE  BE            		cp	(hl)
  16FF  3E04          		ld	a,04h
  1701  2804          		jr	z,RAM32K
  1703                	RAM16K:
  1703  26C0          		ld	h,0c0h
  1705  3E02          		ld	a,02h
  1707                	RAM32K:
  1707  328CFD        		ld	(PAGES),a
  170A  47            		ld	b,a		;
                      	
  170B  7C            		ld	a,h
  170C  3291FD        		ld	(VRAM),a
  170F  CBD4          		set	2,h		;h=h+40h
  1711  2229FF        		ld	(BASICAD),hl	;l=0
  1714  2C            		inc	l		;inc hl
  1715  225FFA        		ld	(STARTAD),hl
                      	
  1718                	COLDLP4:
  1718  78            		ld	a,b		;
  1719  3D            		dec	a
  171A  CD0C14        		call	CHGACT
  171D  CDFB1D        		call	CLS
  1720  10F6          		djnz	COLDLP4
                      	
  1722  AF            		xor	a
  1723  CDED13        		call	CHGDSP
                      	
                      	;PLAY
  1726  CDB31B        		call	PLSTOP		;ei
                      	
  1729  C33B00        		jp	HOT
                      	
                      	
                      	;analyze an argument
                      	;input: hl=program address
                      	;output: hl=next address, FAC1=numerical value or pointer to string descriptor
                      	;	 (ARGTYP)=0(numeric), 1(string), other(cannot analyze)
                      	;destroy: FAC2,af,bc,de,hl
  172C                	ARG:
  172C  E5            		push	hl
  172D  CD420C        		call	SETZERO		;for first +-
  1730  E1            		pop	hl
  1731  AF            		xor	a
  1732  5F            		ld	e,a
  1733  D5            		push	de		;e=dummy operator
  1734  3D            		dec	a
  1735  3225FF        		ld	(ARGTYP),a	;ff=unknown
  1738  3265FF        		ld	(OPRTR),a
  173B                	ARGLP:
  173B  E5            		push	hl
  173C  CDCC34        		call	CHKFRE
  173F  E1            		pop	hl
  1740                	ARGLP2:
  1740  CD573F        		call	SKIPSP
  1743  47            		ld	b,a		;
  1744  23            		inc	hl
  1745  224EFF        		ld	(PROGAD),hl
                      	
                      	;command, function, operator
  1748  B7            		or	a
  1749  FA2018        		jp	m,ARGCMD
                      	
                      	;previous argument without operator?
  174C  3A65FF        		ld	a,(OPRTR)
  174F  B7            		or	a
  1750  281F          		jr	z,ARGTAIL
                      	;[A-Z]
  1752  78            		ld	a,b		;
  1753  D641          		sub	'A'
  1755  FE1A          		cp	'Z'-'A'+1
  1757  3847          		jr	c,ARGVAR
                      	;[0-9&.]
  1759  D6EF          		sub	'0'-'A'
  175B  FE0A          		cp	'9'-'0'+1
  175D  78            		ld	a,b		;
  175E  382F          		jr	c,ARGNUM
  1760  FE26          		cp	'&'
  1762  282B          		jr	z,ARGNUM
  1764  FE2E          		cp	'.'
  1766  2827          		jr	z,ARGNUM
                      	;others
  1768  FE22          		cp	22h		;double quotation mark
  176A  CAF217        		jp	z,ARGSTR
  176D  FE28          		cp	'('
  176F  2808          		jr	z,PARL
  1771                	ARGTAIL:
  1771  2B            		dec	hl
  1772  224EFF        		ld	(PROGAD),hl
  1775  AF            		xor	a
  1776  C3FA18        		jp	OPR
                      	
  1779                	PARL:
  1779  CD5E3F        		call	CHKCLN
  177C  CA1204        		jp	z,MOERR
  177F  CD2C17        		call	ARG
  1782  3A25FF        		ld	a,(ARGTYP)
  1785  FE02          		cp	02h
  1787  D2DC03        		jp	nc,SNERR
  178A  CDC40B        		call	CHKRPAR
  178D  18AC          		jr	ARGLP
                      	
  178F                	ARGNUM:
  178F  CD9817        		call	ARGNCHK
  1792  2B            		dec	hl
  1793  CD9839        		call	ATOF
  1796  18A8          		jr	ARGLP2
                      	
  1798                	ARGNCHK:
  1798  AF            		xor	a
  1799  3265FF        		ld	(OPRTR),a
  179C  3225FF        		ld	(ARGTYP),a
  179F  C9            		ret
                      	
  17A0                	ARGVAR:
  17A0  E5            		push	hl		;program address
  17A1  CD9D33        		call	GETNAME
  17A4  3A25FF        		ld	a,(ARGTYP)
  17A7  F5            		push	af		;;
  17A8  3A65FF        		ld	a,(OPRTR)
  17AB  F5            		push	af		;;;
  17AC  EB            		ex	de,hl
  17AD  CD2539        		call	PUSHF1
  17B0  EB            		ex	de,hl
                      	
  17B1  C5            		push	bc		;variable name
  17B2  7E            		ld	a,(hl)
  17B3  FE28          		cp	'('
  17B5  280D          		jr	z,ARGVARR
  17B7  224EFF        		ld	(PROGAD),hl
  17BA  CDC133        		call	SRCHVAR
  17BD  3008          		jr	nc,ARGVNC
  17BF  11AB0E        		ld	de,ZERO
  17C2  1803          		jr	ARGVNC
  17C4                	ARGVARR:
  17C4  CDBF32        		call	GETARR
  17C7                	ARGVNC:
  17C7  C1            		pop	bc		;variable name
  17C8  CD3439        		call	POPF1
  17CB  F1            		pop	af		;;;
  17CC  3225FF        		ld	(ARGTYP),a
  17CF  F1            		pop	af		;;
  17D0  3265FF        		ld	(OPRTR),a
  17D3  E1            		pop	hl		;program address
  17D4  CB79          		bit	7,c
  17D6  2011          		jr	nz,ARGVSTR
  17D8                	ARGVNUM:
  17D8  CD9817        		call	ARGNCHK
  17DB  EB            		ex	de,hl
  17DC  1166FF        		ld	de,FAC1
  17DF  EDA0          		ldi
  17E1                	ARGVLDIR:
  17E1  010400        		ld	bc,0004h
  17E4  EDB0          		ldir
  17E6  C34819        		jp	ARGNEXT2
                      	
                      	
                      	;string variable
  17E9                	ARGVSTR:
  17E9  CD1018        		call	ARGSCHK
  17EC  EB            		ex	de,hl
  17ED  112DFF        		ld	de,STRDSC1
  17F0  18EF          		jr	ARGVLDIR
                      	
  17F2                	ARGSTR:
  17F2  CD1018        		call	ARGSCHK
  17F5  222FFF        		ld	(STRDSC1+2),hl
  17F8  1E00          		ld	e,00h
  17FA                	ARGSLP:
  17FA  7E            		ld	a,(hl)
  17FB  B7            		or	a
  17FC  280B          		jr	z,ARGSOK
  17FE  23            		inc	hl
  17FF  FE22          		cp	22h		;double quotation mark
  1801  2806          		jr	z,ARGSOK
  1803  1C            		inc	e
  1804  CA0304        		jp	z,LSERR
  1807  18F1          		jr	ARGSLP
  1809                	ARGSOK:
  1809  7B            		ld	a,e
  180A  322DFF        		ld	(STRDSC1),a
  180D  C34017        		jp	ARGLP2
                      	
                      	;destroy: af,bc
  1810                	ARGSCHK:
  1810  AF            		xor	a
  1811  3265FF        		ld	(OPRTR),a	;a=0
  1814  3C            		inc	a
  1815  3225FF        		ld	(ARGTYP),a	;a=1
  1818  012DFF        		ld	bc,STRDSC1
  181B  ED4367FF      		ld	(FAC1+1),bc
  181F  C9            		ret
                      	
  1820                	ARGCMD:
  1820  FEF2          		cp	FNCLAST+1	;0f2h
  1822  D2DC03        		jp	nc,SNERR
  1825  D6CA          		sub	PLUS_		;0cah
  1827  FE0A          		cp	FNC1ST-PLUS_
  1829  78            		ld	a,b		;
  182A  DAFA18        		jp	c,OPR		;0cah-0d3h
                      	
  182D  3A65FF        		ld	a,(OPRTR)
  1830  B7            		or	a
  1831  CA7117        		jp	z,ARGTAIL
                      	
  1834  78            		ld	a,b		;
  1835  FEC8          		cp	NOT_		;0c8h
  1837  CAFA18        		jp	z,OPR
  183A  FE9F          		cp	SCREEN_		;9fh
  183C  280D          		jr	z,FNC
  183E  FEC4          		cp	FN_		;0c4h
  1840  2809          		jr	z,FNC
  1842  FEC6          		cp	INKEY_		;0c6h
  1844  2805          		jr	z,FNC
  1846  FECA          		cp	PLUS_		;0cah
  1848  DA7117        		jp	c,ARGTAIL
                      	
                      	;	jr	FNC
                      	
                      	;function
  184B                	FNC:
  184B  AF            		xor	a
  184C  3225FF        		ld	(ARGTYP),a
  184F  78            		ld	a,b		;
  1850  FEC6          		cp	INKEY_
  1852  CA6927        		jp	z,F_INKY
  1855  FEC4          		cp	FN_
  1857  CAC53E        		jp	z,F_FN
  185A  FE9F          		cp	SCREEN_
  185C  CAA43E        		jp	z,F_SCRN
                      	
  185F  CDCD18        		call	CALLFNC
  1862                	FNCRTN:
  1862  2A4EFF        		ld	hl,(PROGAD)
  1865                	CLRSTRD:
  1865  3A25FF        		ld	a,(ARGTYP)
  1868  B7            		or	a
  1869  2003          		jr	nz,CLRSTRDNZ
  186B  322DFF        		ld	(STRDSC1),a	;=0
  186E                	CLRSTRDNZ:
  186E  AF            		xor	a
  186F  3265FF        		ld	(OPRTR),a
  1872  C33B17        		jp	ARGLP
                      	
                      	
                      	;set border attribute
                      	;input: a=color code
                      	;destroy: af
  1875                	_SETBO:	ds	SETBO-_SETBO
  18C3                		org	SETBO
                      	
  18C3  32C6FE        		ld	(BORDERC),a
  18C6  CDD815        		call	CNVATT
  18C9  32C5FE        		ld	(BORDERA),a
  18CC  C9            		ret
                      	
                      	
  18CD                	CALLFNC:
  18CD  FEEF          		cp	STICK_
  18CF  2804          		jr	z,STKSTR
  18D1  FEF0          		cp	STRIG_
  18D3  2001          		jr	nz,NOTSTKSTR
  18D5                	STKSTR:
  18D5  2B            		dec	hl		;for STICK(),STRIG()
                      	
  18D6                	NOTSTKSTR:
  18D6  FEEA          		cp	LEFT_
  18D8  300B          		jr	nc,SKIPARG
                      	
                      	;SGN()...CHR$()
  18DA  F5            		push	af
  18DB  CDB50B        		call	CHKLPAR
  18DE  CD2C17        		call	ARG
  18E1  CDC40B        		call	CHKRPAR
  18E4  F1            		pop	af
                      	
  18E5                	SKIPARG:
  18E5  113DFA        		ld	de,FNCTBL-(FNC1ST-80h)*2
  18E8  FED7          		cp	USR_
  18EA  C2473F        		jp	nz,JPTBL
                      	
                      	;USR() function
  18ED  E5            		push	hl		;program address
  18EE  CD473F        		call	JPTBL
  18F1  CD9B0B        		call	CHKNUM
  18F4  AF            		xor	a
  18F5  322DFF        		ld	(STRDSC1),a
  18F8  F1            		pop	af		;cancel program address
  18F9  C9            		ret
                      	
                      	
                      	;operator
  18FA                	OPR:
  18FA  FED3          		cp	LT_		;0d3h
  18FC  2001          		jr	nz,OPRNZ
  18FE  3C            		inc	a		;0d3h -> 0d4h
  18FF                	OPRNZ:
  18FF  57            		ld	d,a		;operator
  1900  3A65FF        		ld	a,(OPRTR)
  1903  3C            		inc	a
  1904  FE02          		cp	02h
  1906  D29A19        		jp	nc,OPROPR	;not 00 nor ff
  1909  3A25FF        		ld	a,(ARGTYP)
  190C  3C            		inc	a
  190D  7A            		ld	a,d		;operator
  190E  2010          		jr	nz,NOTHEAD
                      	;first +, for numeric and string
  1910  FECA          		cp	PLUS_
  1912  2834          		jr	z,ARGNEXT2
  1914  FECB          		cp	MINUS_
  1916  2808          		jr	z,NOTHEAD
  1918  FEC8          		cp	NOT_
  191A  2804          		jr	z,NOTHEAD
  191C  B7            		or	a
  191D  C2DC03        		jp	nz,SNERR
  1920                	NOTHEAD:
  1920  CDCC19        		call	GETPRIO
  1923  5F            		ld	e,a
  1924  C1            		pop	bc		;c=previous operator
  1925  C5            		push	bc
  1926  79            		ld	a,c
  1927  B7            		or	a
  1928  2868          		jr	z,ARGHEAD
                      	
  192A  CDCC19        		call	GETPRIO
  192D  BB            		cp	e
  192E  301E          		jr	nc,CALLOP
  1930  7A            		ld	a,d		;operator
  1931                	ARGNEXT:
  1931  3265FF        		ld	(OPRTR),a
  1934  3A25FF        		ld	a,(ARGTYP)
  1937  3D            		dec	a
  1938  2805          		jr	z,ARGNEXTS
  193A  CD2539        		call	PUSHF1
  193D  1809          		jr	ARGNEXT2
  193F                	ARGNEXTS:
  193F  CDE819        		call	COPYSTR
  1942  2A65FF        		ld	hl,(FAC1-1)	;l=operator
  1945  CBB5          		res	6,l
  1947  E5            		push	hl
  1948                	ARGNEXT2:
  1948  2A4EFF        		ld	hl,(PROGAD)
  194B  C33B17        		jp	ARGLP
                      	
                      	
  194E                	CALLOP:
  194E  3A25FF        		ld	a,(ARGTYP)
  1951  3D            		dec	a
  1952  2827          		jr	z,CALLOPS
                      	
                      	;numeric
  1954  CD5239        		call	CPYFAC
  1957  CD3439        		call	POPF1
                      	
  195A                	CALLOPEND:
  195A  CB71          		bit	6,c		;c=previous operator
  195C  2007          		jr	nz,TYPNUM
  195E  CBF1          		set	6,c
  1960  2125FF        		ld	hl,ARGTYP
  1963  CBCE          		set	1,(hl)
  1965                	TYPNUM:
  1965  D5            		push	de		;;d=following operator
  1966  79            		ld	a,c
  1967  FED2          		cp	GT_+1
  1969  3802          		jr	c,CALLOPOK
                      	;>,=,<
  196B  3ED1          		ld	a,GT_
                      	
  196D                	CALLOPOK:
  196D  11F400        		ld	de,OPRTBL-(0c8h-80h)*2
  1970  CD473F        		call	JPTBL
  1973  AF            		xor	a
  1974  3265FF        		ld	(OPRTR),a
  1977  F1            		pop	af		;;a=following operator
  1978  C3FA18        		jp	OPR
                      	
                      	;string
  197B                	CALLOPS:
  197B  C5            		push	bc		;c=previous operator
  197C  3A2DFF        		ld	a,(STRDSC1)
  197F  2A2FFF        		ld	hl,(STRDSC1+2)
  1982  CDFC19        		call	BACKSTR
  1985  3239FF        		ld	(STRDSC4),a
  1988  223BFF        		ld	(STRDSC4+2),hl
  198B  C1            		pop	bc
  198C  E1            		pop	hl
  198D  2265FF        		ld	(FAC1-1),hl
  1990  18C8          		jr	CALLOPEND
                      	
  1992                	ARGHEAD:
  1992  82            		add	a,d		;d=0?
  1993  209C          		jr	nz,ARGNEXT
  1995  E1            		pop	hl		;cancel dummy operator
  1996  2A4EFF        		ld	hl,(PROGAD)
  1999  C9            		ret
                      	
                      	;operator and operator
  199A                	OPROPR:
  199A  7A            		ld	a,d		;operator
  199B  FEC8          		cp	NOT_		;0c8h
  199D  2892          		jr	z,ARGNEXT
  199F  FECA          		cp	PLUS_		;0cah
  19A1  28A5          		jr	z,ARGNEXT2
  19A3  FECB          		cp	MINUS_		;0cbh
  19A5  281D          		jr	z,OPRMNS
  19A7  FED1          		cp	GT_		;0d1h
  19A9  DADC03        		jp	c,SNERR
                      	
                      	;>,=,<
                      	;bit0: >
                      	;bit1: =
                      	;bit2: <
  19AC  2165FF        		ld	hl,OPRTR
  19AF  7E            		ld	a,(hl)
  19B0  FED1          		cp	GT_
  19B2  DADC03        		jp	c,SNERR
  19B5  B2            		or	d
  19B6  BE            		cp	(hl)
  19B7  CADC03        		jp	z,SNERR
  19BA  77            		ld	(hl),a
                      	
                      	;copy numeric/string bit
  19BB  E607          		and	07h		;<=> bits
  19BD  C1            		pop	bc		;c=previous operator
  19BE  B1            		or	c
  19BF  4F            		ld	c,a
  19C0  C5            		push	bc
  19C1  C34819        		jp	ARGNEXT2
                      	
                      	;-
  19C4                	OPRMNS:
  19C4  CD530C        		call	SETMNS1
  19C7  3ECC          		ld	a,ASTRSK_	;0cch
  19C9  C33119        		jp	ARGNEXT
                      	
                      	
                      	;input: a=operator
                      	;output: a=priority
                      	;destroy: f,hl
  19CC                	GETPRIO:
  19CC  B7            		or	a
  19CD  C8            		ret	z
  19CE  21E719        		ld	hl,PRIO+GT_-NOT_
  19D1  F640          		or	40h		;numeric/string bit
  19D3  D6D1          		sub	GT_		;0d1h
  19D5  3005          		jr	nc,PRIONC	;>,=,<
  19D7  85            		add	a,l
  19D8  6F            		ld	l,a
  19D9  3801          		jr	c,PRIONC
  19DB  25            		dec	h
  19DC                	PRIONC:
  19DC  7E            		ld	a,(hl)
  19DD  C9            		ret
                      	
  19DE                	PRIO:
                      	;operator priority table
                      	;		not   +  -  *  /  ^ and or >=<
  19DE  03000505060607		db	3, 0, 5, 5, 6, 6, 7, 2, 1, 4
                      	
                      	
                      	;check string descriptor and copy
                      	;destroy: af,bc,de,hl
  19E8                	COPYSTR:
  19E8  2139FF        		ld	hl,STRDSC4
  19EB  7E            		ld	a,(hl)
  19EC  B7            		or	a
  19ED  C20604        		jp	nz,STERR
  19F0  2B            		dec	hl		;STRDSC3+3
  19F1  113CFF        		ld	de,STRDSC4+3
  19F4  010C00        		ld	bc,000ch
  19F7  EDB8          		lddr			;STRDSC3->STRDSC4, STRDSC2->STRDSC3, STRDSC1->STRDSC2
                      	;	xor	a
  19F9  23            		inc	hl
  19FA  77            		ld	(hl),a		;(STRDSC1)=0
  19FB  C9            		ret
                      	
                      	
                      	;copy back string descriptor
                      	;destroy: f,bc
  19FC                	BACKSTR:
  19FC  E5            		push	hl
  19FD  D5            		push	de
  19FE  2131FF        		ld	hl,STRDSC2
  1A01  112DFF        		ld	de,STRDSC1
  1A04  010C00        		ld	bc,000ch
  1A07  EDB0          		ldir			;STRDSC2->STRDSC1, STRDSC3->STRDSC2, STRDSC4->STRDSC3
  1A09  EB            		ex	de,hl
  1A0A  70            		ld	(hl),b		;(STRDSC4)=0
  1A0B  D1            		pop	de
  1A0C  E1            		pop	hl
  1A0D  C9            		ret
                      	
                      	
                      	;send graphic data to PC-6021
                      	;input: c
                      	;destroy: af
  1A0E                	SENDGRP:
  1A0E  3E80          		ld	a,80h
  1A10                	SENDGLP:
  1A10  CB01          		rlc	c
  1A12  1F            		rra
  1A13  30FB          		jr	nc,SENDGLP
  1A15  1820          		jr	PRINTER
                      	
                      	
                      	;put a character to printer
                      	;input: a
                      	;destroy: none
  1A17                	_PUTPRT:ds	PUTPRT-_PUTPRT
  1A1C                		org	PUTPRT
                      	
  1A1C  F5            		push	af
  1A1D  3A31FA        		ld	a,(GRPFLG)
  1A20  B7            		or	a
  1A21  2806          		jr	z,NOTGRP
  1A23  AF            		xor	a
  1A24                	SETGRP:
  1A24  3231FA        		ld	(GRPFLG),a
  1A27  F1            		pop	af
  1A28  C9            		ret
                      	
  1A29                	NOTGRP:
  1A29  F1            		pop	af
  1A2A  F5            		push	af
  1A2B  FE14          		cp	14h
  1A2D  28F5          		jr	z,SETGRP
  1A2F  CD903F        		call	CNVKANA2
  1A32  CD371A        		call	PRINTER
  1A35  F1            		pop	af
  1A36  C9            		ret
                      	
                      	
                      	;put data to printer
                      	;input: a
                      	;destroy: af
  1A37                	PRINTER:
  1A37  F5            		push	af
  1A38                	PRINTERLP:
  1A38  DBC0          		in	a,(0c0h)
  1A3A  E602          		and	02h
  1A3C  2005          		jr	nz,PRINTERZ	;ready
  1A3E  CD4D27        		call	STOPESC
  1A41  18F5          		jr	PRINTERLP
                      	
  1A43                	PRINTERZ:
  1A43  F1            		pop	af
  1A44  2F            		cpl
  1A45  D391          		out	(91h),a
  1A47  3E01          		ld	a,01h
  1A49  D393          		out	(93h),a		;strobe (>1us)
  1A4B  AF            		xor	a
  1A4C  D393          		out	(93h),a
  1A4E  C9            		ret
                      	
                      	
                      	;convert hiragana -> katakana
                      	;input: a
                      	;output: a
                      	;destroy: f
  1A4F                	_CNVKANA:ds	CNVKANA-_CNVKANA
  1A4F                		org	CNVKANA
                      	
  1A4F  FE86          		cp	86h
  1A51  D8            		ret	c
  1A52  FEA0          		cp	0a0h
  1A54  3803          		jr	c,HIRAGANA
  1A56  FEE0          		cp	0e0h
  1A58  D8            		ret	c
  1A59                	HIRAGANA:
  1A59  EE20          		xor	20h
  1A5B  C9            		ret
                      	
                      	
                      	;CMT open for verify
                      	;destroy: a
  1A5C                	VRFOPN:
  1A5C  3EFF          		ld	a,0ffh
  1A5E  32D8FE        		ld	(VERIFY),a
                      	;	jr	ROPEN
                      	
                      	
                      	;open for tape read
                      	;destroy: none
  1A61                	_ROPEN:ds	ROPEN-_ROPEN
  1A61                		org	ROPEN
                      	
  1A61  F5            		push	af
  1A62  C5            		push	bc
  1A63  061E          		ld	b,1eh
  1A65  CD121B        		call	OPENCMT
  1A68  CD4B1B        		call	RLON
  1A6B  C1            		pop	bc
  1A6C  F1            		pop	af
  1A6D  C9            		ret
                      	
                      	
                      	;get 1 character from CMT
                      	;output: a=data, z(0=error, 1=no error)
                      	;destroy: f
  1A6E                	_GETCMT:ds	GETCMT-_GETCMT
  1A70                		org	GETCMT
                      	
  1A70  3A18FA        		ld	a,(STOPFLG)
  1A73  FE03          		cp	03h
  1A75  2812          		jr	z,CMTSTP
  1A77  3A19FA        		ld	a,(CMTSTAT)
  1A7A  CB67          		bit	4,a
  1A7C  C0            		ret	nz		;read error, z-flag=0
  1A7D  E602          		and	02h
  1A7F  28EF          		jr	z,GETCMT
  1A81  AF            		xor	a		;set z-flag
  1A82  3219FA        		ld	(CMTSTAT),a
  1A85  3A1DFA        		ld	a,(CMTBUF)
  1A88  C9            		ret
                      	
  1A89                	CMTSTP:
  1A89  CD991A        		call	CHKVRF
  1A8C  C35127        		jp	STOPSP
                      	
                      	
                      	;call GETCMT, if z=0 then ?TR Error
  1A8F                	GETCMTTR:
  1A8F  CD701A        		call	GETCMT
  1A92  C8            		ret	z
  1A93  CD991A        		call	CHKVRF
  1A96  C30F04        		jp	TRERR
                      	
                      	
                      	;check verify or not
  1A99                	CHKVRF:
  1A99  CDAA1A        		call	RCLOSE
  1A9C                	CHKVRF2:
  1A9C  3AD8FE        		ld	a,(VERIFY)
  1A9F  B7            		or	a
  1AA0  CCBE34        		call	z,NEW
  1AA3  C9            		ret
                      	
                      	
                      	;close for tape read
                      	;destroy: none
  1AA4                	_RCLOSE:ds	RCLOSE-_RCLOSE
  1AAA                		org	RCLOSE
                      	
  1AAA  F5            		push	af
  1AAB  C5            		push	bc
  1AAC  3E1A          		ld	a,1ah
  1AAE                	CLOSEEND:
  1AAE  CD8F0E        		call	OUT90H
  1AB1  CD491B        		call	RLOFF
  1AB4  C1            		pop	bc
  1AB5  F1            		pop	af
  1AB6  C9            		ret
                      	
                      	
                      	;open for tape write
                      	;destroy: none
  1AB7                	_WOPEN:	ds	WOPEN-_WOPEN
  1AB8                		org	WOPEN
                      	
  1AB8  F5            		push	af
  1AB9  C5            		push	bc
  1ABA  CD4B1B        		call	RLON
  1ABD  CDD91A        		call	BLANK
  1AC0  063E          		ld	b,3eh
  1AC2  CD121B        		call	OPENCMT
  1AC5  CDD91A        		call	BLANK
  1AC8  C1            		pop	bc
  1AC9  F1            		pop	af
  1ACA  C9            		ret
                      	
                      	
                      	;put 1 character to CMT
                      	;input: a=data
                      	;destroy: none
  1ACB                	_PUTCMT:ds	PUTCMT-_PUTCMT
  1ACC                		org	PUTCMT
                      	
  1ACC  F5            		push	af
  1ACD                	PUTCMT2:
  1ACD  CDDC1A        		call	CHKWSTP
  1AD0  3E38          		ld	a,38h
  1AD2  CD8F0E        		call	OUT90H
  1AD5  F1            		pop	af
  1AD6  C38F0E        		jp	OUT90H
                      	
                      	
                      	;wait and check stop for tape write
                      	;destroy: af,bc
  1AD9                	BLANK:
  1AD9  CDE525        		call	WAIT
                      	;	jr	CHKWSTP
                      	
                      	;check stop for tape write
                      	;destroy: af (when not stop)
  1ADC                	CHKWSTP:
  1ADC  3A18FA        		ld	a,(STOPFLG)
  1ADF  FE03          		cp	03h
  1AE1  C0            		ret	nz
  1AE2  CD491B        		call	RLOFF
  1AE5  C35127        		jp	STOPSP
                      	
                      	
                      	;check 8255 status (ready for output to port 90h)
                      	;output: z(0=ready)
                      	;destroy: af,(b)
  1AE8                	_CHK90H:ds	CHK90H-_CHK90H
  1AED                		org	CHK90H
                      	
  1AED  3E08          		ld	a,08h
  1AEF  D393          		out	(93h),a		;disable 8255 INT for reading
  1AF1  DB92          		in	a,(92h)
  1AF3  E688          		and	88h		;nobf=1,intr=1?
  1AF5  EAF91A        		jp	pe,CHK90PE
  1AF8  BF            		cp	a		;set z-flag
  1AF9                	CHK90PE:
  1AF9  3E09          		ld	a,09h
  1AFB  D393          		out	(93h),a		;enable 8255 INT for reading
  1AFD  C9            		ret
                      	
                      	
                      	;close for tape write
                      	;destroy: none
  1AFE                	_WCLOSE:ds	WCLOSE-_WCLOSE
  1B06                		org	WCLOSE
                      	
  1B06  F5            		push	af
  1B07  C5            		push	bc
  1B08  01B003        		ld	bc,03b0h
  1B0B  CDE825        		call	WAITLP
  1B0E  3E3A          		ld	a,3ah
  1B10  189C          		jr	CLOSEEND
                      	
                      	
                      	;open CMT subroutine
                      	;input: b (1eh=read, 3eh=write)
                      	;destroy: af,b
  1B12                	OPENCMT:
  1B12  3A1FFA        		ld	a,(BAUD)	;00=600baud, others=1200baud
  1B15  FE01          		cp	01h
  1B17  9F            		sbc	a,a		;ff=600baud, 00=1200baud
  1B18  80            		add	a,b
  1B19  CD8F0E        		call	OUT90H		;read=1dh(600baud), 1eh(1200baud)
                      					;write=3dh(600baud), 3eh(1200baud)
  1B1C  E6F8          		and	0f8h
  1B1E  3C            		inc	a		;read=19h, write=39h
                      	;	di
  1B1F  CD8F0E        		call	OUT90H
                      	;	ei
  1B22  AF            		xor	a
  1B23  3219FA        		ld	(CMTSTAT),a
                      	;	ld	(STOPFLG),a
  1B26  C9            		ret
                      	
                      	
                      	;blink asterisk
                      	;destroy: af
  1B27                	_BLNKAST:ds	BLNKAST-_BLNKAST
  1B2A                		org	BLNKAST
                      	
  1B2A  E5            		push	hl
  1B2B  211EFA        		ld	hl,ASTSTAT
  1B2E  7E            		ld	a,(hl)
  1B2F  EE0A          		xor	'*'-' '
  1B31  77            		ld	(hl),a
                      	
                      	;	ld	hl,(WIDTH-1)	;h=(WIDTH)
                      	;	dec	h
                      	;	ld	l,01h
                      	
                      	;for compatibility with N60-BASIC
  1B32  21011F        		ld	hl,01h+(COLUMNS-1)*100h
                      	
  1B35  CD5712        		call	PRTCHXY
  1B38  E1            		pop	hl
  1B39  C9            		ret
                      	
                      	
                      	;CMT relay on/off
                      	;destroy: af,b
  1B3A                	_RLOFF:	ds	RLOFF-_RLOFF
  1B49                		org	RLOFF
                      	
  1B49  1801          		jr	RLOFF2
                      	
  1B4B                	_RLON:	ds	RLON-_RLON
  1B4B                		org	RLON
                      	
  1B4B  3E            		db	3eh		;ld a,
  1B4C                	RLOFF2:
  1B4C  AF            		xor	a		;afh
                      	
  1B4D  0608          		ld	b,00001000b	;bit3=CMT relay
  1B4F  C3541B        		jp	OUTB0H
                      	
                      	
                      	;output to port b0h
                      	;input: a=new data, b=change bit
                      	;destroy: af
  1B52                	_OUTB0H:ds	OUTB0H-_OUTB0H
  1B54                		org	OUTB0H
                      	
  1B54  E5            		push	hl
  1B55  2127FA        		ld	hl,PORTB0H
  1B58  AE            		xor	(hl)
  1B59  A0            		and	b
  1B5A  AE            		xor	(hl)
  1B5B  D3B0          		out	(0b0h),a
  1B5D  77            		ld	(hl),a
  1B5E  E1            		pop	hl
  1B5F  C9            		ret
                      	
                      	
                      	;PLAY stop sub
                      	;destroy: none
  1B60                	_PLSTPS:ds	PLSTPS-_PLSTPS
  1B60                		org	PLSTPS
                      	
  1B60  F5            		push	af
  1B61  E5            		push	hl
  1B62  D5            		push	de
  1B63  C5            		push	bc
                      	
  1B64  3E07          		ld	a,07h		;ch.ABC=tone,portAB=in
  1B66  1E38          		ld	e,38h
  1B68  CDC51B        		call	SETPSG
  1B6B  3C            		inc	a		;register8=ch.A volume
  1B6C  1E00          		ld	e,00h
  1B6E  CDC51B        		call	SETPSG
  1B71  3C            		inc	a		;register9=ch.B volume
  1B72  CDC51B        		call	SETPSG
  1B75  3C            		inc	a		;register10=ch.C volume
  1B76  CDC51B        		call	SETPSG
                      	
  1B79  AF            		xor	a
  1B7A  321BFD        		ld	(PLAYST),a
  1B7D  3214FD        		ld	(CHANNEL),a
                      	
  1B80  67            		ld	h,a
  1B81  6F            		ld	l,a
  1B82  22A1FB        		ld	(BUFAIN),hl	;clear BFIN and BFOUT for ch.A
  1B85  22A7FB        		ld	(BUFBIN),hl	;clear BFIN and BFOUT for ch.B
  1B88  22ADFB        		ld	(BUFCIN),hl	;clear BFIN and BFOUT for ch.C
                      	
  1B8B  211DFD        		ld	hl,PLWKA
  1B8E  77            		ld	(hl),a
  1B8F  54            		ld	d,h
  1B90  5D            		ld	e,l
  1B91  13            		inc	de
  1B92  012400        		ld	bc,PLWKB-PLWKA-1
  1B95  EDB0          		ldir
                      	
  1B97  21B91B        		ld	hl,PLWKTBL
  1B9A  112CFD        		ld	de,PLWKA+OCTAVE
  1B9D  0E05          		ld	c,05h		;b=0
  1B9F  EDB0          		ldir
                      	
  1BA1  211DFD        		ld	hl,PLWKA
  1BA4  1142FD        		ld	de,PLWKB
  1BA7  0E4A          		ld	c,PLWKC-PLWKA	;b=0
  1BA9  EDB0          		ldir
                      	
  1BAB  C1            		pop	bc
  1BAC  D1            		pop	de
  1BAD  E1            		pop	hl
  1BAE  F1            		pop	af
  1BAF  C9            		ret
                      	
                      	
                      	;stop and initialize for PLAY command
                      	;destroy: none
  1BB0                	_PLSTOP:ds	PLSTOP-_PLSTOP
  1BB3                		org	PLSTOP
  1BB3  F3            		di
  1BB4  CD601B        		call	PLSTPS
  1BB7  FB            		ei
  1BB8  C9            		ret
                      	
                      	
  1BB9                	PLWKTBL:
  1BB9  04            		db	4		;O-value
  1BBA  04            		db	4		;L-value
  1BBB  78            		db	120		;T-value
  1BBC  08            		db	8		;V-value
  1BBD  FF            		db	255		;M-value(low)
                      	
                      	
                      	;get PSG resister value and set new value
                      	;input: a=register, e=value
                      	;output: d=old value
                      	;destroy: none
  1BBE                	_SETPSG2:ds	SETPSG2-_SETPSG2
  1BBE                		org	SETPSG2
                      	
  1BBE  F5            		push	af
  1BBF  D3A0          		out	(0a0h),a
  1BC1  DBA2          		in	a,(0a2h)
  1BC3  57            		ld	d,a
  1BC4  F1            		pop	af
                      	;	jp	SETPSG
                      	
                      	
                      	;set PSG register
                      	;input: a=register, e=value
                      	;destroy: none
  1BC5                	_SETPSG:ds	SETPSG-_SETPSG
  1BC5                		org	SETPSG
                      	
  1BC5  F5            		push	af
  1BC6  D3A0          		out	(0a0h),a
  1BC8  7B            		ld	a,e
  1BC9  D3A1          		out	(0a1h),a
  1BCB  F1            		pop	af
  1BCC  C9            		ret
                      	
                      	
                      	;bell
                      	;destroy: af,bc,e
  1BCD                	_BELL:	ds	BELL-_BELL
  1BCD                		org	BELL
                      	
  1BCD  CDB31B        		call	PLSTOP
                      	;tune
  1BD0  AF            		xor	a		;register0=ch.A 8bit fine tune
  1BD1  1E55          		ld	e,55h
  1BD3  CDC51B        		call	SETPSG
  1BD6  5F            		ld	e,a		;a=0
  1BD7  3C            		inc	a		;register1=ch.A 4bit coarse tune
  1BD8  CDC51B        		call	SETPSG
                      	;volume
  1BDB  1E07          		ld	e,07h
                      	;	ld	a,08h		;register8=ch.A volume
  1BDD  83            		add	a,e		;register8=ch.A volume
  1BDE  CDC51B        		call	SETPSG
  1BE1  010004        		ld	bc,0400h
  1BE4  59            		ld	e,c		;c=0
  1BE5  CDE825        		call	WAITLP
                      	;volume
  1BE8  3E08          		ld	a,08h		;register8=ch.A volume
  1BEA  18D9          		jr	SETPSG
                      	
                      	
                      	;play subroutine called by time interrupt
                      	;destroy: af,bc,de,hl
  1BEC                	PLAYINT:
  1BEC  3A1BFD        		ld	a,(PLAYST)
  1BEF  B7            		or	a
  1BF0  C8            		ret	z
  1BF1                	PLIZ:
  1BF1  0F            		rrca
  1BF2  0F            		rrca
  1BF3  0F            		rrca
  1BF4  4F            		ld	c,a
  1BF5  2167FD        		ld	hl,PLWKC
  1BF8  0603          		ld	b,03h
  1BFA                	PLILP:
  1BFA  E5            		push	hl
  1BFB  CB01          		rlc	c
  1BFD  300D          		jr	nc,PLINC
                      	
  1BFF  56            		ld	d,(hl)
  1C00  2C            		inc	l		;inc	hl
  1C01  5E            		ld	e,(hl)
  1C02  1B            		dec	de
  1C03  73            		ld	(hl),e
  1C04  2D            		dec	l		;dec	hl
  1C05  72            		ld	(hl),d
  1C06  7A            		ld	a,d
  1C07  B3            		or	e
  1C08  205D          		jr	nz,PLINEXT
  1C0A  1806          		jr	PLIGET
                      	
  1C0C                	PLINC:
  1C0C  3A1BFD        		ld	a,(PLAYST)
  1C0F  B7            		or	a
  1C10  2055          		jr	nz,PLINEXT	;if (PLAYST)<>0
                      	
  1C12                	PLIGET:
                      	;length
  1C12  CD4810        		call	GETPLBF
                      	;	jr	z,PLINEXT
  1C15  2864          		jr	z,PLIRES
  1C17  FEFF          		cp	0ffh
  1C19  2860          		jr	z,PLIRES
  1C1B  D1            		pop	de
  1C1C  D5            		push	de
  1C1D  12            		ld	(de),a
  1C1E  CD4810        		call	GETPLBF		;no change in de
  1C21  1C            		inc	e		;inc de
  1C22  12            		ld	(de),a
                      	
                      	;tune
  1C23  CD4810        		call	GETPLBF
  1C26  5F            		ld	e,a
  1C27  78            		ld	a,b
  1C28  87            		add	a,a
  1C29  3D            		dec	a		;register1,3,5=4bit coarse tune
  1C2A  CDC51B        		call	SETPSG
  1C2D  CD4810        		call	GETPLBF
  1C30  5F            		ld	e,a
  1C31  78            		ld	a,b
  1C32  3D            		dec	a
  1C33  87            		add	a,a		;register0,2,4=8bit fine tune
  1C34  CDC51B        		call	SETPSG
                      	
                      	;volume or envelope
  1C37  CD4810        		call	GETPLBF
  1C3A  57            		ld	d,a		;
  1C3B  FE10          		cp	10h
  1C3D  3802          		jr	c,PLIVOL
  1C3F  3E10          		ld	a,10h		;envelope
  1C41                	PLIVOL:
  1C41  5F            		ld	e,a
  1C42  78            		ld	a,b
  1C43  C607          		add	a,07h		;register8,9,10=volume
  1C45  CDC51B        		call	SETPSG
  1C48  7A            		ld	a,d		;
  1C49  D610          		sub	10h
  1C4B  3818          		jr	c,PLISET
                      	
                      	;period
  1C4D  57            		ld	d,a		;
  1C4E  CD4810        		call	GETPLBF
  1C51  5F            		ld	e,a
  1C52  3E0B          		ld	a,0bh
  1C54  CDC51B        		call	SETPSG
  1C57  CD4810        		call	GETPLBF
  1C5A  5F            		ld	e,a
  1C5B  3E0C          		ld	a,0ch
  1C5D  CDC51B        		call	SETPSG
                      	
                      	;envelope pattern
  1C60  5A            		ld	e,d		;
  1C61  3C            		inc	a		;register13=envelope pattern
  1C62  CDC51B        		call	SETPSG
                      	
                      	;status
  1C65                	PLISET:
  1C65  CBC1          		set	0,c
                      	
  1C67                	PLINEXT:
  1C67  E1            		pop	hl
  1C68  7D            		ld	a,l
  1C69  C6DB          		add	a,PLWKA-PLWKB	;no carry
  1C6B  6F            		ld	l,a
  1C6C  108C          		djnz	PLILP
                      	
  1C6E  211BFD        		ld	hl,PLAYST
  1C71  7E            		ld	a,(hl)
  1C72  71            		ld	(hl),c
  1C73  B7            		or	a
  1C74  C8            		ret	z		;old (PLAYST)=0
  1C75  79            		ld	a,c
  1C76  B7            		or	a
  1C77  C0            		ret	nz		;new (PLAYST)<>0
  1C78  C3F11B        		jp	PLIZ		;old<>0 and new=0
                      	
                      	;reset
  1C7B                	PLIRES:
  1C7B  CB81          		res	0,c
  1C7D  78            		ld	a,b
  1C7E  C607          		add	a,07h		;register8,9,10=volume
  1C80  1E00          		ld	e,00h
  1C82  CDC51B        		call	SETPSG
  1C85  18E0          		jr	PLINEXT
                      	
                      	
                      	;get play buffer address
                      	;output: hl
                      	;destroy: f
  1C87                	GETPLAD:
  1C87  67            		ld	h,a
  1C88  3A14FD        		ld	a,(CHANNEL)
  1C8B  6F            		ld	l,a
  1C8C  87            		add	a,a		;a*2
  1C8D  85            		add	a,l		;a*3
  1C8E  87            		add	a,a		;a*6
  1C8F  C6A1          		add	a,BUFAIN-BUFAIN/256*256		;no carry
  1C91  6F            		ld	l,a
  1C92  7C            		ld	a,h
  1C93  26FB          		ld	h,BUFAIN/256	;higher byte
  1C95  C9            		ret
                      	
                      	
                      	;joystick
                      	;input: a=1or2
                      	;output: a (0-0-trigger2-trigger1-right-left-down-up)
                      	;destroy: f
  1C96                	_JOYSTK:ds	JOYSTK-_JOYSTK
  1CA6                		org	JOYSTK
                      	
  1CA6  D5            		push	de
  1CA7  0F            		rrca
  1CA8  37            		scf
  1CA9  1F            		rra
  1CAA  5F            		ld	e,a		;c0h or 80h
                      	
  1CAB  3E07          		ld	a,07h		;register7=portABin-out,noise,tone
  1CAD  F3            		di
  1CAE  D3A0          		out	(0a0h),a
  1CB0  DBA2          		in	a,(0a2h)
  1CB2  1802          		jr	SKPPATCH2
                      	
                      	
                      	;1cb4h-1cb5h: to be patched by PC6001V/VX/VW
  1CB4                	_PATCH2:ds	PATCH2-_PATCH2
  1CB4                		org	PATCH2
  1CB4  0000          		db	00h, 00h
                      	
                      	
  1CB6                	SKPPATCH2:
  1CB6  57            		ld	d,a		;
                      	
  1CB7  E6BF          		and	10111111b	;parallel port A=in
  1CB9  F680          		or	10000000b	;parallel port B=out
  1CBB  D3A1          		out	(0a1h),a
                      	
  1CBD  3E0F          		ld	a,0fh		;register15=parallel port B
  1CBF  CDC51B        		call	SETPSG		;c0h or 80h
                      	
  1CC2  3D            		dec	a		;register14=parallel port A
  1CC3  D3A0          		out	(0a0h),a
  1CC5  DBA2          		in	a,(0a2h)
  1CC7  2F            		cpl
  1CC8  5A            		ld	e,d		;
  1CC9  57            		ld	d,a		;;
                      	
  1CCA  3E07          		ld	a,07h
  1CCC  CD901E        		call	SETPSGEI
                      	
  1CCF  7A            		ld	a,d		;;
  1CD0  D1            		pop	de
  1CD1  C9            		ret
                      	
                      	
                      	;LOCATE command
  1CD2                	_C_LOCA:ds	C_LOCA-_C_LOCA
  1CD2                		org	C_LOCA
                      	
  1CD2  CDE40D        		call	INT1ARG
  1CD5  ED5BACFD      		ld	de,(WIDTH)
  1CD9  BB            		cp	e
  1CDA  D2E503        		jp	nc,FCERR
  1CDD  3C            		inc	a
  1CDE  F5            		push	af		;
  1CDF  7E            		ld	a,(hl)
  1CE0  FE2C          		cp	','
  1CE2  C2DC03        		jp	nz,SNERR
  1CE5  CDE30D        		call	INT1INC
                      	
  1CE8  2A20FA        		ld	hl,(HEIGHT)	;l=(HEIGHT)
  1CEB  BD            		cp	l
  1CEC  D2E503        		jp	nc,FCERR
  1CEF  3C            		inc	a
                      	
  1CF0  E1            		pop	hl		;
  1CF1  6F            		ld	l,a
  1CF2  C36D11        		jp	SETCSR
                      	
                      	
                      	;CONSOLE command
  1CF5                	_C_CNSL:ds	C_CNSL-_C_CNSL
  1CF6                		org	C_CNSL
                      	
  1CF6  ED4BA2FD      		ld	bc,(CONSOL1)	;c=(CONSOL1),b=(CONSOL2)
  1CFA  C5            		push	bc
                      	
  1CFB  CD693F        		call	CHKCMM
  1CFE  2814          		jr	z,CNSLPAR2
                      	
  1D00  CDE40D        		call	INT1ARG
  1D03  3A20FA        		ld	a,(HEIGHT)
  1D06  3D            		dec	a
  1D07  BB            		cp	e
  1D08  3801          		jr	c,CNSLC
  1D0A  7B            		ld	a,e
  1D0B                	CNSLC:
  1D0B  3C            		inc	a
  1D0C  C1            		pop	bc
  1D0D  4F            		ld	c,a
  1D0E  C5            		push	bc
                      	
  1D0F  CD793F        		call	CHKCLCM
  1D12  2838          		jr	z,CNSLEND
                      	
  1D14                	CNSLPAR2:
  1D14  CD693F        		call	CHKCMM
  1D17  2810          		jr	z,CNSLPAR3
                      	
  1D19  CDE40D        		call	INT1ARG
                      	
  1D1C  C1            		pop	bc
  1D1D  81            		add	a,c
  1D1E  DAE503        		jp	c,FCERR
  1D21  3D            		dec	a
  1D22  47            		ld	b,a
  1D23  C5            		push	bc
                      	
  1D24  CD793F        		call	CHKCLCM
  1D27  2823          		jr	z,CNSLEND
                      	
  1D29                	CNSLPAR3:
  1D29  CD693F        		call	CHKCMM
  1D2C  2813          		jr	z,CNSLPAR4
                      	
  1D2E  CDE40D        		call	INT1ARG
  1D31  FE02          		cp	02h
  1D33  D2E503        		jp	nc,FCERR
  1D36  32A6FD        		ld	(CONSOL3),a
                      	
  1D39  CDB912        		call	PRTFKEY2
  1D3C  CD793F        		call	CHKCLCM
  1D3F  280B          		jr	z,CNSLEND
                      	
  1D41                	CNSLPAR4:
  1D41  CDE40D        		call	INT1ARG
  1D44  FE02          		cp	02h
  1D46  D2E503        		jp	nc,FCERR
  1D49  322DFA        		ld	(CONSOL4),a
                      	
  1D4C                	CNSLEND:
  1D4C  D1            		pop	de
  1D4D  7A            		ld	a,d
  1D4E  BB            		cp	e
  1D4F  DAE503        		jp	c,FCERR
                      	;	jr	CNSMAIN
                      	
                      	
                      	;CONSOLE command main part
                      	;used by EXAS BASIC compiler
                      	;destroy: af,de,hl
  1D52                	_CNSMAIN:ds	CNSMAIN-_CNSMAIN
  1D52                		org	CNSMAIN
                      	
  1D52  CD731D        		call	SETCNSL
                      	
  1D55  3AA2FD        		ld	a,(CONSOL1)
  1D58  CD4D14        		call	CUTLINE2
                      	
  1D5B  3AA8FD        		ld	a,(CSRY)
  1D5E  3D            		dec	a
  1D5F  21A5FD        		ld	hl,LASTLIN
  1D62  BE            		cp	(hl)
  1D63  D8            		ret	c
  1D64  6E            		ld	l,(hl)
  1D65  C34C11        		jp	CTLCR
                      	
                      	
                      	;set console parameter
                      	;destroy: af,de,hl
  1D68                	_SETCNSL2:ds	SETCNSL-4-_SETCNSL2
  1D6F                		org	SETCNSL-4
  1D6F                	SETCNSL2:
  1D6F  ED5BA2FD      		ld	de,(CONSOL1)
                      	
                      	;set console parameter
                      	;input: d=last line+1, e=first line+1
                      	;destroy: af,de,hl
  1D73                	_SETCNSL:ds	SETCNSL-_SETCNSL
  1D73                		org	SETCNSL
                      	;2nd parameter
  1D73  3AA6FD        		ld	a,(CONSOL3)
  1D76  67            		ld	h,a
  1D77  3A20FA        		ld	a,(HEIGHT)
  1D7A  BA            		cp	d
  1D7B  3001          		jr	nc,CNSLNC1
  1D7D  57            		ld	d,a
  1D7E                	CNSLNC1:
                      	
                      	;1st parameter
  1D7E  94            		sub	h
  1D7F  BB            		cp	e
  1D80  3001          		jr	nc,CNSLNC2
  1D82  5F            		ld	e,a
  1D83                	CNSLNC2:
  1D83  6B            		ld	l,e
                      	
                      	;last line
  1D84  67            		ld	h,a		;h=(HEIGHT)-(CONSOL3)
  1D85  BA            		cp	d
  1D86  3F            		ccf
  1D87  3A92FD        		ld	a,(SCREEN1)
  1D8A  1F            		rra
  1D8B  B7            		or	a
  1D8C  2801          		jr	z,CNSLZ
  1D8E  62            		ld	h,d		;if screen mode 3,4 or 2nd<height-3rd
  1D8F                	CNSLZ:
                      	
  1D8F  ED53A2FD      		ld	(CONSOL1),de
  1D93  22A4FD        		ld	(FSTLIN),hl
  1D96  C9            		ret
                      	
                      	
                      	;COLOR command
  1D97                	_C_COLR:ds	C_COLR-_C_COLR
  1D9B                		org	C_COLR
                      	
  1D9B  1193FD        		ld	de,COLOR1
  1D9E  0602          		ld	b,02h
  1DA0                	COLRLP:
  1DA0  CD693F        		call	CHKCMM
  1DA3  2810          		jr	z,COLRZ
  1DA5  C5            		push	bc
  1DA6  D5            		push	de
  1DA7  CDE40D        		call	INT1ARG
  1DAA  D1            		pop	de
  1DAB  C1            		pop	bc
  1DAC  12            		ld	(de),a
  1DAD  CD5E3F        		call	CHKCLN		;a=(hl)
  1DB0  C8            		ret	z
  1DB1  FE2C          		cp	','
  1DB3  C0            		ret	nz
  1DB4  23            		inc	hl
  1DB5                	COLRZ:
  1DB5  13            		inc	de
  1DB6  10E8          		djnz	COLRLP
                      	
  1DB8                	COLRPAR3:
  1DB8  CDE40D        		call	INT1ARG
                      	;	jp	SETC3
                      	
                      	
                      	;set color 3rd parameter
                      	;input: a=3rd color parameter (1 or 2)
                      	;destroy: af,bc,de
  1DBB                	_SETC3:	ds	SETC3-_SETC3
  1DBB                		org	SETC3
                      	
  1DBB  EB            		ex	de,hl
  1DBC  3D            		dec	a
  1DBD  FE02          		cp	02h
  1DBF  D2E503        		jp	nc,FCERR
  1DC2  87            		add	a,a		;0 or 2
                      	
  1DC3  2195FD        		ld	hl,COLOR3
  1DC6  BE            		cp	(hl)
  1DC7  C8            		ret	z
  1DC8  77            		ld	(hl),a
                      	
  1DC9  2A90FD        		ld	hl,(VRAM-1)
  1DCC  010200        		ld	bc,0002h	;32*16=256*2
  1DCF  68            		ld	l,b		;b=0
  1DD0                	SETC3LP:
  1DD0  7E            		ld	a,(hl)
  1DD1  EE02          		xor	02h
  1DD3  77            		ld	(hl),a
  1DD4  23            		inc	hl
  1DD5  10F9          		djnz	SETC3LP
  1DD7  0D            		dec	c
  1DD8  20F6          		jr	nz,SETC3LP
  1DDA  EB            		ex	de,hl
  1DDB  C9            		ret
                      	
                      	
                      	;clear screen and reset graphic cordinate
                      	;input: c-flag=1: c=first line+1, a=last line-first line+1
                      	;       c-flag=0: using console parameters
                      	;destroy: af,bc,de,hl
  1DDC                	CLSMAIN:
  1DDC  210000        		ld	hl,0000h
  1DDF  22AEFD        		ld	(GRPX1),hl
  1DE2  22B0FD        		ld	(GRPY1),hl
  1DE5  2C            		inc	l
  1DE6  CD4C11        		call	CTLCR		;(0,0)
  1DE9  DA7E28        		jp	c,CLSMAIN2	;if a,c given
  1DEC  C37428        		jp	CTLL
                      	
                      	
                      	;CLS command
                      	;destroy: af,de
  1DEF                	_CLS:	ds	CLS-_CLS
  1DFB                	C_CLS:
  1DFB                		org	CLS
                      	
  1DFB  E5            		push	hl
  1DFC  C5            		push	bc
  1DFD  B7            		or	a		;reset c-flag
  1DFE  CDDC1D        		call	CLSMAIN
  1E01  C1            		pop	bc
  1E02  E1            		pop	hl
  1E03  C9            		ret
                      	
                      	
                      	;SCREEN command
  1E04                	_C_SCRN:ds	C_SCRN-_C_SCRN
  1E04                		org	C_SCRN
                      	
  1E04  AF            		xor	a		;1st parameter=none
  1E05  F5            		push	af
  1E06  ED4B8FFD      		ld	bc,(SCREEN2)
  1E0A  51            		ld	d,c		;2nd parameter-1
  1E0B  58            		ld	e,b		;3rd parameter-1
                      	
  1E0C  CD693F        		call	CHKCMM
  1E0F  280C          		jr	z,SCRPAR2
                      	
  1E11  D5            		push	de
  1E12  CDE40D        		call	INT1ARG
  1E15  D1            		pop	de
  1E16  C1            		pop	bc
  1E17  F5            		push	af		;1st parameter
                      	
  1E18  CD793F        		call	CHKCLCM
  1E1B  2818          		jr	z,GOSCRMAIN
                      	
  1E1D                	SCRPAR2:
  1E1D  CD693F        		call	CHKCMM
  1E20  280C          		jr	z,SCRPAR3
                      	
  1E22  D5            		push	de
  1E23  CDE40D        		call	INT1ARG
  1E26  D1            		pop	de
  1E27  3D            		dec	a
  1E28  57            		ld	d,a		;2nd parameter-1
                      	
  1E29  CD793F        		call	CHKCLCM
  1E2C  2807          		jr	z,GOSCRMAIN
                      	
  1E2E                	SCRPAR3:
  1E2E  D5            		push	de
  1E2F  CDE40D        		call	INT1ARG
  1E32  D1            		pop	de
  1E33  3D            		dec	a
  1E34  5F            		ld	e,a		;3rd parameter-1
                      	
  1E35                	GOSCRMAIN:
  1E35  F1            		pop	af
  1E36  3D            		dec	a
  1E37  4F            		ld	c,a		;1st parameter-1
                      	;	jr	SCRMAIN
                      	
                      	
                      	;SCREEN command main part
                      	;used by EXAS BASIC compiler
                      	;input: c=1st paraeter-1(ff=none), d=2nd parameter-1, e=3rd parameter-1
                      	;destroy: af,de
  1E38                	_SCRMAIN:ds	SCRMAIN-_SCRMAIN
  1E39                		org	SCRMAIN
                      	
  1E39  3A8CFD        		ld	a,(PAGES)
  1E3C  3D            		dec	a
  1E3D  BA            		cp	d
  1E3E  DAE503        		jp	c,FCERR
  1E41  BB            		cp	e
  1E42  DAE503        		jp	c,FCERR
                      	
  1E45  79            		ld	a,c
  1E46  3C            		inc	a
  1E47  FE03          		cp	03h
  1E49  380A          		jr	c,SCROK
  1E4B  FE05          		cp	05h
  1E4D  D2E503        		jp	nc,FCERR
  1E50  7A            		ld	a,d
  1E51  B7            		or	a
  1E52  CAE503        		jp	z,FCERR
                      	
  1E55                	SCROK:
  1E55  7A            		ld	a,d
  1E56  CD0C14        		call	CHGACT
                      	
  1E59  3A90FD        		ld	a,(SCREEN3)
  1E5C  BB            		cp	e
  1E5D  7B            		ld	a,e
  1E5E  C4ED13        		call	nz,CHGDSP
                      	
  1E61  3A92FD        		ld	a,(SCREEN1)
  1E64  B9            		cp	c
  1E65  C8            		ret	z
  1E66  79            		ld	a,c
  1E67  0C            		inc	c
  1E68  C8            		ret	z		;1st parameter=none
  1E69  C39013        		jp	CHGMOD
                      	
                      	
                      	;TIME function
  1E6C                	F_TIME:
  1E6C  2A28FA        		ld	hl,(TMCNT)
  1E6F  ED5B2AFA      		ld	de,(TMCNT+2)
  1E73  C30F25        		jp	I4TOF
                      	
                      	
                      	;SOUND command
  1E76                	C_SOUN:
  1E76  CD5E3F        		call	CHKCLN
  1E79  CADC03        		jp	z,SNERR
  1E7C  CDE40D        		call	INT1ARG
  1E7F  FE10          		cp	10h
  1E81  D2E503        		jp	nc,FCERR
  1E84  F5            		push	af
  1E85  7E            		ld	a,(hl)
  1E86  FE2C          		cp	','
  1E88  C2DC03        		jp	nz,SNERR
  1E8B  CDE30D        		call	INT1INC
  1E8E  F1            		pop	af
  1E8F  F3            		di
  1E90                	SETPSGEI:
  1E90  CDC51B        		call	SETPSG
  1E93  FB            		ei
  1E94  C9            		ret
                      	
                      	
                      	;PLAY command
  1E95                	C_PLAY:
  1E95  CDB31E        		call	PLAY
  1E98  224EFF        		ld	(PROGAD),hl
  1E9B  C9            		ret
                      	
                      	
                      	;play routine
                      	;input: hl=data address, (z=0)
                      	;output: hl=next address
                      	;destroy: af,bc,de
  1E9C                	_PLAY:	ds	PLAY-_PLAY
  1EB3                		org	PLAY
                      	
  1EB3  DDE5          		push	ix
  1EB5  ED5B4EFF      		ld	de,(PROGAD)
  1EB9  D5            		push	de
                      	
  1EBA  AF            		xor	a
  1EBB  3244FD        		ld	(PLWKB+PLLEN),a
  1EBE  3269FD        		ld	(PLWKC+PLLEN),a
                      	
  1EC1  DD211DFD      		ld	ix,PLWKA
  1EC5  0603          		ld	b,03h
  1EC7                	PLAYLP1:
  1EC7  C5            		push	bc
  1EC8  CD8126        		call	STRARG
  1ECB  DD7702        		ld	(ix+PLLEN),a
  1ECE  DD7303        		ld	(ix+PLADR),e
  1ED1  DD7204        		ld	(ix+PLADR+1),d
  1ED4  012500        		ld	bc,PLWKB-PLWKA
  1ED7  DD09          		add	ix,bc
  1ED9  C1            		pop	bc
  1EDA  CD793F        		call	CHKCLCM
  1EDD  2802          		jr	z,PLSTR0
  1EDF  10E6          		djnz	PLAYLP1
                      	
                      	;check string length=0?
  1EE1                	PLSTR0:
  1EE1  2169FD        		ld	hl,PLWKC+PLLEN
  1EE4  11DBFF        		ld	de,PLWKB-PLWKC
  1EE7  0603          		ld	b,03h
  1EE9                	PLAYLP2:
  1EE9  7E            		ld	a,(hl)
  1EEA  B7            		or	a
  1EEB  200E          		jr	nz,PLAYNZ1
  1EED  78            		ld	a,b
  1EEE  3D            		dec	a
  1EEF  3214FD        		ld	(CHANNEL),a
  1EF2  3EFF          		ld	a,0ffh
  1EF4  E5            		push	hl
  1EF5  F3            		di
  1EF6  CD310F        		call	PUTPLBF
  1EF9  FB            		ei
  1EFA  E1            		pop	hl
  1EFB                	PLAYNZ1:
  1EFB  19            		add	hl,de
  1EFC  10EB          		djnz	PLAYLP2
                      	
  1EFE                	PLAYLP3:
  1EFE  3A18FA        		ld	a,(STOPFLG)
  1F01  FE03          		cp	03h
  1F03  CCB31B        		call	z,PLSTOP
  1F06  285C          		jr	z,PLAYEND
                      	
  1F08  F3            		di
  1F09  DD2167FD      		ld	ix,PLWKC
  1F0D  010003        		ld	bc,0300h	;c=PLAYLEN check counter
  1F10                	PLAYLP4:
  1F10  78            		ld	a,b
  1F11  3D            		dec	a
  1F12  3214FD        		ld	(CHANNEL),a
  1F15  DD7E02        		ld	a,(ix+PLLEN)
  1F18  B7            		or	a
  1F19  2829          		jr	z,PLAYNEXT
                      	
  1F1B  DD6E03        		ld	l,(ix+PLADR)
  1F1E  DD6604        		ld	h,(ix+PLADR+1)
                      	
  1F21  3217FD        		ld	(PLAYLEN),a
  1F24  2218FD        		ld	(PLAYSTR),hl
  1F27  C5            		push	bc
  1F28  CD6F1F        		call	CNVPLAY
  1F2B  C1            		pop	bc
  1F2C  3A17FD        		ld	a,(PLAYLEN)
  1F2F  DD7702        		ld	(ix+PLLEN),a
  1F32  2A18FD        		ld	hl,(PLAYSTR)
  1F35  DD7503        		ld	(ix+PLADR),l
  1F38  DD7404        		ld	(ix+PLADR+1),h
                      	
  1F3B  0C            		inc	c
  1F3C  B7            		or	a
  1F3D  2005          		jr	nz,PLAYNEXT
  1F3F  0D            		dec	c
  1F40  3D            		dec	a
  1F41  CD310F        		call	PUTPLBF		;a=ffh
  1F44                	PLAYNEXT:
  1F44  11DBFF        		ld	de,PLWKB-PLWKC
  1F47  DD19          		add	ix,de
  1F49  10C5          		djnz	PLAYLP4
                      	
  1F4B  211BFD        		ld	hl,PLAYST
  1F4E  7E            		ld	a,(hl)
  1F4F  B7            		or	a
  1F50  200D          		jr	nz,PLAYNZ2
                      	
  1F52  3C            		inc	a		;=01h
  1F53  321EFD        		ld	(PLWKA+REMAIN+1),a
  1F56  3243FD        		ld	(PLWKB+REMAIN+1),a
  1F59  3268FD        		ld	(PLWKC+REMAIN+1),a
  1F5C  3E07          		ld	a,07h
  1F5E  77            		ld	(hl),a
                      	
  1F5F                	PLAYNZ2:
  1F5F  FB            		ei
  1F60  79            		ld	a,c		;c=PLAYLEN check counter
  1F61  B7            		or	a
  1F62  209A          		jr	nz,PLAYLP3
                      	
  1F64                	PLAYEND:
  1F64  D1            		pop	de
  1F65  2A4EFF        		ld	hl,(PROGAD)
  1F68  ED534EFF      		ld	(PROGAD),de
  1F6C  DDE1          		pop	ix
  1F6E  C9            		ret
                      	
                      	
                      	;convert play data
                      	;input: a=string length, hl=string address, ix=play work
                      	;destroy: af,bc,de,hl
  1F6F                	CNVPLAY:
  1F6F  CD871C        		call	GETPLAD
  1F72  56            		ld	d,(hl)
  1F73  14            		inc	d		;in+1
  1F74  23            		inc	hl
  1F75  7E            		ld	a,(hl)		;out
  1F76  92            		sub	d
  1F77  3004          		jr	nc,CNVPLNC
                      	
  1F79  23            		inc	hl
  1F7A  23            		inc	hl		;size
  1F7B  3C            		inc	a
  1F7C  86            		add	a,(hl)
  1F7D                	CNVPLNC:
  1F7D  FE08          		cp	08h
  1F7F  D8            		ret	c
                      	
  1F80  CD1D20        		call	PLAYGETC
  1F83  C8            		ret	z
  1F84  CD6A20        		call	PLAYINC
  1F87  CDEF0B        		call	TOUPPER
  1F8A  CD8F1F        		call	PLAYCMD
  1F8D  18E0          		jr	CNVPLAY
                      	
                      	
  1F8F                	PLAYCMD:
  1F8F  D641          		sub	'A'
  1F91  FE07          		cp	'G'-'A'+1
  1F93  DAC620        		jp	c,TONE
  1F96  FE0C          		cp	'M'-'A'
  1F98  282F          		jr	z,PLAYM
  1F9A  FE12          		cp	'S'-'A'
  1F9C  283F          		jr	z,PLAYS
  1F9E  FE0B          		cp	'L'-'A'
  1FA0  2847          		jr	z,PLAYL
  1FA2  FE13          		cp	'T'-'A'
  1FA4  2855          		jr	z,PLAYT
  1FA6  FE0E          		cp	'O'-'A'
  1FA8  2861          		jr	z,PLAYO
  1FAA  FE11          		cp	'R'-'A'
  1FAC  CA9520        		jp	z,PLAYR
  1FAF  FE0D          		cp	'N'-'A'
  1FB1  CA7620        		jp	z,PLAYN
  1FB4  FE15          		cp	'V'-'A'
  1FB6  C2E503        		jp	nz,FCERR
                      	
                      	
  1FB9                	PLAYV:
  1FB9  CD5821        		call	GETNUM1
  1FBC  3802          		jr	c,PLAYVNUM
  1FBE  3E08          		ld	a,08h
  1FC0                	PLAYVNUM:
  1FC0  FE10          		cp	10h
  1FC2  D2E503        		jp	nc,FCERR
  1FC5                	PUTV:
  1FC5  DD7712        		ld	(ix+VOLUME),a
  1FC8  C9            		ret
                      	
  1FC9                	PLAYM:
  1FC9  CD6321        		call	GETNUM2
  1FCC  3803          		jr	c,PLAYMNUM
  1FCE  11FF00        		ld	de,00ffh
  1FD1                	PLAYMNUM:
  1FD1  7A            		ld	a,d
  1FD2  B3            		or	e
  1FD3  CAE503        		jp	z,FCERR
  1FD6  DD7313        		ld	(ix+PERIOD),e
  1FD9  DD7214        		ld	(ix+PERIOD+1),d
  1FDC  C9            		ret
                      	
  1FDD                	PLAYS:
  1FDD  CD5821        		call	GETNUM1
  1FE0  FE10          		cp	10h
  1FE2  D2E503        		jp	nc,FCERR
  1FE5  C610          		add	a,10h
  1FE7  18DC          		jr	PUTV
                      	
  1FE9                	PLAYL:
  1FE9  CD5821        		call	GETNUM1
  1FEC  3802          		jr	c,PLAYLNUM
  1FEE  3E04          		ld	a,04h
  1FF0                	PLAYLNUM:
  1FF0  3D            		dec	a
  1FF1  FE40          		cp	40h
  1FF3  D2E503        		jp	nc,FCERR
  1FF6  3C            		inc	a
  1FF7  DD7710        		ld	(ix+LENGTH),a
  1FFA  C9            		ret
                      	
  1FFB                	PLAYT:
  1FFB  CD5821        		call	GETNUM1
  1FFE  3802          		jr	c,PLAYTNUM
  2000  3E78          		ld	a,120
  2002                	PLAYTNUM:
  2002  FE20          		cp	32
  2004  DAE503        		jp	c,FCERR
  2007  DD7711        		ld	(ix+TEMPO),a
  200A  C9            		ret
                      	
  200B                	PLAYO:
  200B  CD5821        		call	GETNUM1
  200E  3802          		jr	c,PLAYONUM
  2010  3E04          		ld	a,04h
  2012                	PLAYONUM:
  2012  3D            		dec	a
  2013  FE08          		cp	08h
  2015  D2E503        		jp	nc,FCERR
  2018  3C            		inc	a
  2019  DD770F        		ld	(ix+OCTAVE),a
  201C  C9            		ret
                      	
                      	
                      	;get a character from PLAY string
                      	;output: a=data, hl=address, z-flag(1=no character)
                      	;destroy: f,hl
  201D                	PLAYGETC:
  201D  3A17FD        		ld	a,(PLAYLEN)
  2020  B7            		or	a
  2021  C8            		ret	z		;a=0 if no character
  2022  2A18FD        		ld	hl,(PLAYSTR)
  2025  7E            		ld	a,(hl)
  2026  FE20          		cp	' '
  2028  C0            		ret	nz
  2029  CD6A20        		call	PLAYINC
  202C  18EF          		jr	PLAYGETC
                      	
                      	
                      	;scale data
                      	;address probably equals to 6001mkII/6601 ROM (used by BELUGA)
  202E                	_SCALE2:ds	SCALE2-_SCALE2
  2030                		org	SCALE2
                      	
                      	;		c/b+	c+/d-	d	d+/e-	e/f-	f/e+
  2030  E80E120E480D89		dw	0ee8h,	0e12h,	0d48h,	0c89h,	0bd5h,	0b2bh
                      	;		f+/g-	g	g+/a-	a	a+/b-	b/c-
  203C  8A0AF3096409DD		dw	0a8ah,	09f3h,	0964h,	08ddh,	085eh,	07e6h
                      	
                      	
                      	;scale data
  2048                	_SCALE:	ds	SCALE-_SCALE
  204B                		org	SCALE
                      	
                      	;		c/b+	c+/d-	d	d+/e-	e/f-	f/e+
  204B  E80E120E480D89		dw	0ee8h,	0e12h,	0d48h,	0c89h,	0bd5h,	0b2bh
                      	;		f+/g-	g	g+/a-	a	a+/b-	b/c-
  2057  8A0AF3096409DD		dw	0a8ah,	09f3h,	0964h,	08ddh,	085eh,	07e6h
                      	
                      	
  2063                	TONETBL:
                      	;		a   b   c  d  e  f   g
  2063  12160004080A0E		db	18, 22, 0, 4, 8, 10, 14
                      	
                      	
                      	;increment (PLAYSTR) and decrement (PLAYLEN)
                      	;destroy: f,hl
  206A                	PLAYINC:
  206A  2117FD        		ld	hl,PLAYLEN
  206D  35            		dec	(hl)
  206E  2118FD        		ld	hl,PLAYSTR
  2071  34            		inc	(hl)
  2072  C0            		ret	nz
  2073  2C            		inc	l		;inc hl
  2074  34            		inc	(hl)
  2075  C9            		ret
                      	
                      	
  2076                	PLAYN:
  2076  CD5821        		call	GETNUM1
  2079  D2E503        		jp	nc,FCERR
  207C  FE61          		cp	97
  207E  D2E503        		jp	nc,FCERR
  2081  B7            		or	a
  2082  283C          		jr	z,PLAYN0
                      	
  2084  0600          		ld	b,00h
  2086                	PLAYNLP:
  2086  04            		inc	b
  2087  D60C          		sub	0ch
  2089  30FB          		jr	nc,PLAYNLP
  208B  87            		add	a,a
  208C  16FF          		ld	d,0ffh
  208E  5F            		ld	e,a
  208F  216320        		ld	hl,SCALE+24
  2092  19            		add	hl,de
  2093  1856          		jr	GETFREQ
                      	
  2095                	PLAYR:
  2095  AF            		xor	a
  2096  F5            		push	af		;volume
  2097  D5            		push	de		;(tune)
  2098  CD5821        		call	GETNUM1
  209B  3006          		jr	nc,PLAYRNC
  209D  B7            		or	a
  209E  2065          		jr	nz,CHKLEN
  20A0  C3E503        		jp	FCERR
                      	
  20A3                	PLAYRNC:
  20A3  3E04          		ld	a,04h
  20A5  1863          		jr	CALCLEN
                      	
                      	;accidental mark
  20A7                	PLAYPLS:
  20A7  CD6A20        		call	PLAYINC
  20AA  1C            		inc	e
  20AB  1C            		inc	e
  20AC  7B            		ld	a,e
  20AD  D618          		sub	24
  20AF  3833          		jr	c,NOACC
  20B1  5F            		ld	e,a		;=0
  20B2  1830          		jr	NOACC
                      	
  20B4                	PLAYMNS:
  20B4  CD6A20        		call	PLAYINC
  20B7  1D            		dec	e
  20B8  1D            		dec	e
  20B9  F2E420        		jp	p,NOACC
  20BC  1E16          		ld	e,22
  20BE  1824          		jr	NOACC
                      	
  20C0                	PLAYN0:
                      	;	xor	a
  20C0  F5            		push	af		;volume=0
  20C1  D5            		push	de		;(tune)
                      	
                      	;for compatibility with PC-6001
  20C2  3E50          		ld	a,80
  20C4  1844          		jr	CALCLEN
                      	
                      	
  20C6                	TONE:
  20C6  216320        		ld	hl,TONETBL
  20C9  1600          		ld	d,00h
  20CB  5F            		ld	e,a
  20CC  19            		add	hl,de
  20CD  5E            		ld	e,(hl)
  20CE  CD1D20        		call	PLAYGETC
  20D1  2811          		jr	z,NOACC
  20D3  FE2B          		cp	'+'
  20D5  28D0          		jr	z,PLAYPLS
  20D7  FE23          		cp	'#'
  20D9  28CC          		jr	z,PLAYPLS
  20DB  FE2D          		cp	'-'
  20DD  28D5          		jr	z,PLAYMNS
  20DF  FE3D          		cp	'='
  20E1  CAE503        		jp	z,FCERR
                      	
  20E4                	NOACC:
  20E4  DD460F        		ld	b,(ix+OCTAVE)
  20E7  214B20        		ld	hl,SCALE
                      	;	ld	d,00h
  20EA  19            		add	hl,de		;d=0
  20EB                	GETFREQ:
  20EB  7E            		ld	a,(hl)
  20EC  23            		inc	hl
  20ED  56            		ld	d,(hl)
  20EE  05            		dec	b
  20EF  2805          		jr	z,OCTAVE1
  20F1                	OCTVLP:
  20F1  CB3A          		srl	d
  20F3  1F            		rra
  20F4  10FB          		djnz	OCTVLP
  20F6                	OCTAVE1:
  20F6  5F            		ld	e,a
  20F7  DD7E12        		ld	a,(ix+VOLUME)
                      	
  20FA                	PUSHVOL:
  20FA  F5            		push	af		;volume
  20FB  D5            		push	de		;tune
  20FC  CD5821        		call	GETNUM1
  20FF  B7            		or	a
  2100  2003          		jr	nz,CHKLEN
  2102  DD7E10        		ld	a,(ix+LENGTH)
  2105                	CHKLEN:
  2105  FE41          		cp	65
  2107  D2E503        		jp	nc,FCERR
                      	
  210A                	CALCLEN:
                      	;60[s/min]/T[/min]/(L/4)/(8192/3993600[Hz])=117000/T/L
  210A  DD4611        		ld	b,(ix+TEMPO)	;T-value
  210D  CDE821        		call	MULINT1		;hl=T*L (<=3fc0h)
  2110  1184E4        		ld	de,0e484h	;117000/2
  2113  CD1322        		call	DIVINT2		;bc=(117000/2)/(T*L)*2
  2116  50            		ld	d,b
  2117  59            		ld	e,c
                      	
                      	;dotted note
  2118                	DOTLP:
  2118  CD1D20        		call	PLAYGETC
  211B  FE2E          		cp	'.'
  211D  200C          		jr	nz,NOTDOT
  211F  CD6A20        		call	PLAYINC
  2122  CB38          		srl	b
  2124  CB19          		rr	c
  2126  EB            		ex	de,hl
  2127  09            		add	hl,bc
  2128  EB            		ex	de,hl
  2129  18ED          		jr	DOTLP
  212B                	NOTDOT:
                      	;	di
                      	;for compatibility with PC-6001
  212B  212D00        		ld	hl,002dh
  212E  E7            		rst	CPHLDE
  212F  3801          		jr	c,LENOK
  2131  EB            		ex	de,hl
  2132                	LENOK:
  2132  7A            		ld	a,d		;length
  2133  CD310F        		call	PUTPLBF
  2136  7B            		ld	a,e
  2137  CD310F        		call	PUTPLBF
  213A  D1            		pop	de		;tune
  213B  7A            		ld	a,d
  213C  CD310F        		call	PUTPLBF
  213F  7B            		ld	a,e
  2140  CD310F        		call	PUTPLBF
  2143  F1            		pop	af		;volume
  2144  CD310F        		call	PUTPLBF
  2147  FE10          		cp	10h
  2149  380C          		jr	c,PLCMDEND
  214B  DD7E13        		ld	a,(ix+PERIOD)	;period
  214E  CD310F        		call	PUTPLBF
  2151  DD7E14        		ld	a,(ix+PERIOD+1)
  2154  CD310F        		call	PUTPLBF
  2157                	PLCMDEND:
                      	;	ei
  2157  C9            		ret
                      	
                      	
  2158                	GETNUM1:
                      	;output: a,c-flag(1=number)
                      	;destroy: f,bc,de,hl
  2158  CD6321        		call	GETNUM2
  215B  7B            		ld	a,e
  215C  D0            		ret	nc
  215D  14            		inc	d
  215E  15            		dec	d
  215F  C8            		ret	z		;c-flag=1
  2160  C3E503        		jp	FCERR
                      	
                      	
  2163                	GETNUM2:
                      	;output: de,c-flag(1=number)
                      	;destroy: af,bc,de
  2163  CD1D20        		call	PLAYGETC	;hl=address if z-flag=0
  2166  110000        		ld	de,0000h
  2169  C8            		ret	z		;c-flag=0
  216A  FE3D          		cp	'='
  216C  282A          		jr	z,GETNUMEQ
  216E  FE3B          		cp	';'
  2170  281F          		jr	z,GETNUMSEMI
  2172  D630          		sub	'0'
  2174  FE0A          		cp	'9'-'0'+1
  2176  D0            		ret	nc		;c-flag=0
  2177  3A17FD        		ld	a,(PLAYLEN)
  217A  47            		ld	b,a
  217B  CDCC27        		call	ATOI2LEN
  217E  78            		ld	a,b
  217F  3217FD        		ld	(PLAYLEN),a
  2182  2218FD        		ld	(PLAYSTR),hl
  2185  CD1D20        		call	PLAYGETC
  2188  2805          		jr	z,GETNUMZ
  218A  FE3B          		cp	';'
  218C  CC6A20        		call	z,PLAYINC
  218F                	GETNUMZ:
  218F  37            		scf			;set c-flag
  2190  C9            		ret
                      	
  2191                	GETNUMSEMI:
  2191  CD6A20        		call	PLAYINC
  2194  AF            		xor	a		;reset c-flag
  2195  57            		ld	d,a
  2196  5F            		ld	e,a
  2197  C9            		ret
                      	
  2198                	GETNUMEQ:
  2198  CD6A20        		call	PLAYINC
  219B  11DAFE        		ld	de,INPBUF
  219E                	GETNUMEQLP:
  219E  CD1D20        		call	PLAYGETC
  21A1  CAE503        		jp	z,FCERR
  21A4  CD6A20        		call	PLAYINC
  21A7  CDF20B        		call	TOUPPER2
  21AA  12            		ld	(de),a
  21AB  13            		inc	de
  21AC  FE3B          		cp	';'
  21AE  20EE          		jr	nz,GETNUMEQLP
                      	
  21B0  21DAFE        		ld	hl,INPBUF
  21B3  46            		ld	b,(hl)
  21B4  78            		ld	a,b
  21B5  D641          		sub	'A'
  21B7  FE1A          		cp	'Z'-'A'+1
  21B9  D2E503        		jp	nc,FCERR
  21BC  23            		inc	hl
  21BD  CD9D33        		call	GETNAME
  21C0  FE24          		cp	'$'
  21C2  CAFD03        		jp	z,TMERR
  21C5  FE28          		cp	'('
  21C7  2811          		jr	z,GETNUMARR
                      	
  21C9  CDC133        		call	SRCHVAR
  21CC  3003          		jr	nc,GETNUMEQNC
  21CE  11AB0E        		ld	de,ZERO
  21D1                	GETNUMEQNC:
  21D1  EB            		ex	de,hl
  21D2  CD450C        		call	SETF1
  21D5  CD9F0C        		call	FTOI
  21D8  37            		scf
  21D9  C9            		ret
                      	
                      	
  21DA                	GETNUMARR:
  21DA  ED5B4EFF      		ld	de,(PROGAD)
  21DE  D5            		push	de
  21DF  CDBF32        		call	GETARR
  21E2  E1            		pop	hl
  21E3  224EFF        		ld	(PROGAD),hl
  21E6  18E9          		jr	GETNUMEQNC
                      	
                      	
                      	;hl=a*b
                      	;input: a,b
                      	;output: hl
                      	;destroy: af,c
  21E8                	MULINT1:
  21E8  210000        		ld	hl,0000h
  21EB  4D            		ld	c,l		;=0
  21EC  1801          		jr	MULI1NZ
  21EE                	MULI1C:
  21EE  09            		add	hl,bc
  21EF                	MULI1NZ:
  21EF  CB38          		srl	b
  21F1  CB19          		rr	c
  21F3  87            		add	a,a
  21F4  38F8          		jr	c,MULI1C
  21F6  20F7          		jr	nz,MULI1NZ
  21F8  C9            		ret
                      	
                      	
                      	;dehl=de*hl
                      	;input: de,hl
                      	;output: dehl
                      	;destroy: af,bc
  21F9                	MULINT2:
  21F9  7C            		ld	a,h
  21FA  4D            		ld	c,l
  21FB  210000        		ld	hl,0000h
  21FE  0610          		ld	b,10h
  2200                	MULI2LP:
  2200  1F            		rra
  2201  CB19          		rr	c
  2203  3001          		jr	nc,MULI2NC
  2205  19            		add	hl,de
  2206                	MULI2NC:
  2206  CB1C          		rr	h
  2208  CB1D          		rr	l
  220A  10F4          		djnz	MULI2LP
  220C  1F            		rra
  220D  CB19          		rr	c
  220F  59            		ld	e,c
  2210  57            		ld	d,a
  2211  EB            		ex	de,hl
  2212  C9            		ret
                      	
                      	
                      	;bc=de/hl*2
                      	;input: de,hl(<8000h)
                      	;output: bc...hl
                      	;destroy: af,de,hl
  2213                	DIVINT2:
  2213  AF            		xor	a
  2214  010002        		ld	bc,0200h	;*2^(b-1)
  2217                	DIVILP1:
  2217  04            		inc	b
  2218  ED6A          		adc	hl,hl		;c-flag=0
  221A  F21722        		jp	p,DIVILP1
  221D  EB            		ex	de,hl
  221E                	DIVILP2:
  221E  B7            		or	a
  221F  ED52          		sbc	hl,de
  2221  3001          		jr	nc,DIVNC
  2223  19            		add	hl,de
  2224                	DIVNC:
  2224  3F            		ccf
  2225  CB11          		rl	c
  2227  17            		rla
  2228  CB3A          		srl	d
  222A  CB1B          		rr	e
  222C  10F0          		djnz	DIVILP2
                      	
  222E  47            		ld	b,a
  222F  C9            		ret
                      	
                      	
                      	;STICK() function
  2230                	_F_STCK:ds	F_STCK-_F_STCK
  2236                		org	F_STCK
                      	
  2236  CD7122        		call	FNCI1
                      	
                      	;2239: used by SNAKE & ALIEN, MAD CHASER
  2239  B7            		or	a
  223A  2808          		jr	z,STCK0
  223C  CDA61C        		call	JOYSTK
  223F  218622        		ld	hl,JOYTBL
  2242  1808          		jr	CNVSTCK
                      	
  2244                	STCK0:
  2244  CD6110        		call	STICK
  2247  0F            		rrca
  2248  0F            		rrca
  2249  219622        		ld	hl,CSRTBL
  224C                	CNVSTCK:
  224C  E60F          		and	0fh
  224E  1600          		ld	d,00h
  2250  5F            		ld	e,a
  2251  19            		add	hl,de
  2252  6E            		ld	l,(hl)
  2253  C37E0C        		jp	I1TOF
                      	
                      	
                      	;STRIG() function
  2256                	_F_STRG:ds	F_STRG-_F_STRG
  2256                		org	F_STRG
                      	
  2256  CD7122        		call	FNCI1
                      	
                      	;2259: used by SNAKE & ALIEN, MAD CHASER
  2259  B7            		or	a
  225A  280E          		jr	z,STRG0
  225C  CDA61C        		call	JOYSTK
  225F  E610          		and	10h
  2261                	STRGEND:
  2261  CA420C        		jp	z,SETZERO
                      	;	jp	SETPLS1
                      	
  2264                	SETPLS1:
  2264  21A10E        		ld	hl,PLSONE
  2267  C3450C        		jp	SETF1
                      	
  226A                	STRG0:
  226A  CD6110        		call	STICK
  226D  E680          		and	80h
  226F  18F0          		jr	STRGEND
                      	
                      	
                      	;get a 1-byte integer for function for stick()/strig()
                      	;input: hl=program address-1
                      	;output: FAC1,a, hl=next address
                      	;destroy: FAC2,f,bc
  2271                	FNCI1:
  2271  23            		inc	hl
  2272  CD860B        		call	FNCNUM
  2275  CD4C07        		call	FTOI1
  2278  83            		add	a,e
  2279  FE03          		cp	03h
  227B  D8            		ret	c
  227C  C3E503        		jp	FCERR
                      	
                      	
                      	;joystick -> stick()
  227F                	_JOYTBL:ds	JOYTBL-_JOYTBL
  2286                		org	JOYTBL
                      	;		    u   d   ud  l   ul  dl  udl
  2286  00010500070806		db	0,  1,  5,  0,  7,  8,  6,  7
                      	;		r   ur  dr  udr lr  ulr dlr udlr
  228E  03020403000105		db	3,  2,  4,  3,  0,  1,  5,  0
                      	
                      	
                      	;cursor key -> stick()
  2296                	_CSRTBL:ds	CSRTBL-_CSRTBL
  2296                		org	CSRTBL
                      	;		    u   d   ud  r   ur  dr  udr
  2296  00010500030204		db	0,  1,  5,  0,  3,  2,  4,  3
                      	;		l   ul  dl  udl rl url drl udrl
  229E  07080607000105		db	7,  8,  6,  7,  0,  1,  5,  0
                      	
                      	
                      	;LCOPY command
  22A6                	_C_LCPY:ds	C_LCPY-_C_LCPY
  22A6                		org	C_LCPY
                      	
  22A6  CDD2FF        		call	HOOKLCP
  22A9  21DF22        		ld	hl,LCPYHD
  22AC  0605          		ld	b,05h
  22AE                	LCPYLP1:
  22AE  7E            		ld	a,(hl)
  22AF  CD371A        		call	PRINTER
  22B2  23            		inc	hl
  22B3  10F9          		djnz	LCPYLP1
                      	
  22B5  2A90FD        		ld	hl,(VRAM-1)	;h=(VRAM)
  22B8  24            		inc	h
  22B9  24            		inc	h
  22BA  68            		ld	l,b		;b=0
  22BB  3A92FD        		ld	a,(SCREEN1)
  22BE  FE02          		cp	02h
  22C0  3822          		jr	c,LCPYTXT
                      	
  22C2                	LCPYGRP:
  22C2  110018        		ld	de,1800h
  22C5                	LCPYLP2:
  22C5  4E            		ld	c,(hl)
  22C6  CD0E1A        		call	SENDGRP
  22C9  23            		inc	hl
  22CA  1B            		dec	de
  22CB  7A            		ld	a,d
  22CC  B3            		or	e
  22CD  20F6          		jr	nz,LCPYLP2
                      	
  22CF                	LCPYEND:
  22CF  010020        		ld	bc,2000h
  22D2  CDD822        		call	LCPYLP3
                      	
  22D5  010A06        		ld	bc,060ah
  22D8                	LCPYLP3:
  22D8  79            		ld	a,c
  22D9  CD371A        		call	PRINTER
  22DC  10FA          		djnz	LCPYLP3
  22DE  C9            		ret
                      	
                      	;header for lcopy
  22DF                	LCPYHD:
  22DF  20200A1DC1    		db	20h, 20h, 0ah, 1dh, 0c1h
                      	
                      	;lcopy text screen
  22E4                	LCPYTXT:
  22E4  3E04          		ld	a,04h
  22E6  D393          		out	(93h),a		;CGROM ON
  22E8  3A20FA        		ld	a,(HEIGHT)
  22EB  47            		ld	b,a
  22EC                	LCPYTLP1:
  22EC  C5            		push	bc
  22ED  0E0C          		ld	c,0ch
  22EF                	LCPYTLP2:
  22EF  0620          		ld	b,COLUMNS
  22F1                	LCPYTLP3:
  22F1  C5            		push	bc
  22F2  7E            		ld	a,(hl)
  22F3  CDA014        		call	CGROM
  22F6  7B            		ld	a,e
  22F7  C60C          		add	a,0ch
  22F9  91            		sub	c
  22FA  5F            		ld	e,a
  22FB  1A            		ld	a,(de)
                      	
  22FC  57            		ld	d,a		;
  22FD  25            		dec	h
  22FE  25            		dec	h
  22FF  7E            		ld	a,(hl)		;attribute
  2300  24            		inc	h
  2301  24            		inc	h
  2302  CB77          		bit	6,a
  2304  201F          		jr	nz,LCPYSEMI
  2306  0F            		rrca
  2307  7A            		ld	a,d		;
  2308  3001          		jr	nc,NOTREV
  230A  2F            		cpl
  230B                	NOTREV:
  230B  4F            		ld	c,a
  230C  CD0E1A        		call	SENDGRP
  230F  23            		inc	hl
  2310  C1            		pop	bc
  2311  10DE          		djnz	LCPYTLP3
                      	
  2313  0D            		dec	c
  2314  2806          		jr	z,LCPYTZ
  2316  11E0FF        		ld	de,0-COLUMNS
  2319  19            		add	hl,de
  231A  18D3          		jr	LCPYTLP2
                      	
  231C                	LCPYTZ:
  231C  C1            		pop	bc
  231D  10CD          		djnz	LCPYTLP1
                      	
  231F  3E05          		ld	a,05h
  2321  D393          		out	(93h),a		;CGROM OFF
  2323  18AA          		jr	LCPYEND
                      	
  2325                	LCPYSEMI:
                      	;c=	9-12	xx**....
                      	;	5-8	xx..**..
                      	;	1-4	xx....**
                      	
  2325  7E            		ld	a,(hl)
  2326  0D            		dec	c
  2327  CB51          		bit	2,c
  2329  2006          		jr	nz,SEMI58	;c=5-8
  232B  CB59          		bit	3,c
  232D  2804          		jr	z,SEMI14	;c=1-4
                      	
  232F  0F            		rrca
  2330  0F            		rrca
  2331                	SEMI58:
  2331  0F            		rrca
  2332  0F            		rrca
  2333                	SEMI14:
  2333  E603          		and	03h
                      	
                      	;00h->00h, 01h->0fh, 02h->f0h, 03h->ffh
  2335  1F            		rra			;c-flag=0
  2336  3002          		jr	nc,SEMINC
  2338  C61E          		add	a,0fh*2
  233A                	SEMINC:
  233A  1F            		rra			;c-flag=0
  233B  30CE          		jr	nc,NOTREV
  233D  C6F0          		add	a,0f0h
  233F  18CA          		jr	NOTREV
                      	
                      	
                      	;KEY command
  2341                	C_KEY:
  2341  CDE40D        		call	INT1ARG
  2344  3D            		dec	a
  2345  FE0A          		cp	0ah
  2347  D2E503        		jp	nc,FCERR
  234A  113DFB        		ld	de,FKEYTBL
  234D  87            		add	a,a		;*2
  234E  87            		add	a,a		;*4
  234F  87            		add	a,a		;*8
  2350  83            		add	a,e		;no carry
  2351  5F            		ld	e,a
  2352  7E            		ld	a,(hl)
  2353  FE2C          		cp	','
  2355  C2DC03        		jp	nz,SNERR
  2358  D5            		push	de		;
  2359  23            		inc	hl
  235A  CD8126        		call	STRARG
  235D  EB            		ex	de,hl
  235E  D1            		pop	de		;
                      	
  235F  01FF08        		ld	bc,08ffh
  2362  3C            		inc	a
  2363                	KEYLP1:
  2363  3D            		dec	a
  2364  2806          		jr	z,KEYLP2
  2366  EDA0          		ldi
  2368  10F9          		djnz	KEYLP1
  236A  1804          		jr	KEYEND
                      	
  236C                	KEYLP2:
  236C  12            		ld	(de),a		;a=0
  236D  13            		inc	de
  236E  10FC          		djnz	KEYLP2
  2370                	KEYEND:
  2370  C3B512        		jp	PRTFKEY
                      	
                      	
                      	;CSAVE command
  2373                	C_CSV:
  2373  CD8126        		call	STRARG
  2376  B7            		or	a
  2377  CAE503        		jp	z,FCERR
  237A  4F            		ld	c,a
                      	
                      	;write header (d3h*10)
  237B  CDB81A        		call	WOPEN
  237E  3ED3          		ld	a,0d3h
  2380  060A          		ld	b,0ah
  2382                	CSVLP1:
  2382  CDCC1A        		call	PUTCMT
  2385  10FB          		djnz	CSVLP1
                      	
                      	;file name
  2387  0606          		ld	b,06h
                      	
  2389  0C            		inc	c
  238A                	CSVLP2:
  238A  1A            		ld	a,(de)
  238B  0D            		dec	c
  238C  2002          		jr	nz,CSVNZ
  238E  AF            		xor	a
  238F  0C            		inc	c
  2390                	CSVNZ:
  2390  CDCC1A        		call	PUTCMT
  2393  13            		inc	de
  2394  10F4          		djnz	CSVLP2
                      	
                      	;data
  2396                	CSVDATA:
  2396  01B024        		ld	bc,24b0h
  2399  CDE825        		call	WAITLP
                      	
  239C  2A5FFA        		ld	hl,(STARTAD)
  239F  ED5B56FF      		ld	de,(VARAD)
  23A3                	CSVLP3:
  23A3  7E            		ld	a,(hl)
  23A4  CDCC1A        		call	PUTCMT
  23A7  23            		inc	hl
  23A8  E7            		rst	CPHLDE
  23A9  20F8          		jr	nz,CSVLP3
                      	
                      	;footer (00h*9)
  23AB  0609          		ld	b,09h
  23AD                	CSVLP4:
  23AD  CDCC1A        		call	PUTCMT		;a=0
  23B0  10FB          		djnz	CSVLP4
                      	
  23B2  C3061B        		jp	WCLOSE
                      	
                      	
                      	;CLOAD command
  23B5                	C_CLD:
  23B5  F1            		pop	af		;cancel return address
  23B6  CD573F        		call	SKIPSP
  23B9  FE95          		cp	PRINT_
  23BB  0E00          		ld	c,00h		;file name length
  23BD  79            		ld	a,c
  23BE  2002          		jr	nz,CLDNZ1
  23C0  23            		inc	hl
  23C1  2F            		cpl
  23C2                	CLDNZ1:
  23C2  32D8FE        		ld	(VERIFY),a
  23C5  F5            		push	af		;verify?
  23C6  CD5E3F        		call	CHKCLN
  23C9  2808          		jr	z,NOTARGET
  23CB  CD8126        		call	STRARG
  23CE  B7            		or	a
  23CF  CAE503        		jp	z,FCERR
  23D2  4F            		ld	c,a
  23D3                	NOTARGET:
  23D3  CD611A        		call	ROPEN
                      	
  23D6                	CLDLP1:
  23D6  EB            		ex	de,hl
  23D7  CD3925        		call	GETFN
  23DA  EB            		ex	de,hl
                      	
                      	;compare file name
  23DB  79            		ld	a,c
  23DC  B7            		or	a
  23DD  2815          		jr	z,CLDFND
                      	
  23DF  D5            		push	de		;target
                      	
  23E0  21D1FE        		ld	hl,FNAME
  23E3  0C            		inc	c
  23E4  0606          		ld	b,06h
  23E6                	CLDLP2:
  23E6  1A            		ld	a,(de)
  23E7  0D            		dec	c
  23E8  2002          		jr	nz,CLDNZ2
  23EA  AF            		xor	a
  23EB  0C            		inc	c
  23EC                	CLDNZ2:
  23EC  BE            		cp	(hl)
  23ED  2045          		jr	nz,CLDSKIP
  23EF  23            		inc	hl
  23F0  13            		inc	de
  23F1  10F3          		djnz	CLDLP2
  23F3  D1            		pop	de		;target
                      	
  23F4                	CLDFND:
  23F4  217625        		ld	hl,FOUND
  23F7  CD8325        		call	PUTFN
  23FA  CD9C1A        		call	CHKVRF2
                      	
  23FD  F1            		pop	af		;verify?
  23FE  4F            		ld	c,a		;c=0: not verify
                      	
  23FF  2A5FFA        		ld	hl,(STARTAD)
  2402                	CLDLP3:
  2402  060A          		ld	b,0ah
  2404                	CLDLP4:
  2404  EB            		ex	de,hl
  2405  21FEFF        		ld	hl,0-0002h
  2408  39            		add	hl,sp
  2409  E7            		rst	CPHLDE
  240A  2837          		jr	z,CLDOM		;over memory error
  240C  EB            		ex	de,hl
  240D  CD8F1A        		call	GETCMTTR
  2410  0C            		inc	c
  2411  0D            		dec	c
  2412  2803          		jr	z,CLDZ2		;c=0: not verify
  2414  BE            		cp	(hl)
  2415  2035          		jr	nz,CLDBAD
  2417                	CLDZ2:
  2417  77            		ld	(hl),a
  2418  23            		inc	hl
  2419  B7            		or	a
  241A  20E6          		jr	nz,CLDLP3
  241C  CD2A1B        		call	BLNKAST
  241F  10E3          		djnz	CLDLP4
  2421  CDAA1A        		call	RCLOSE
                      	
  2424  2256FF        		ld	(VARAD),hl
                      	
  2427  AF            		xor	a
  2428  3258FA        		ld	(DEVICE),a
  242B  219003        		ld	hl,OK
  242E  CDCF30        		call	PUTS
  2431  C3BA04        		jp	CHGLKP
                      	
  2434                	CLDSKIP:
  2434  217D25        		ld	hl,SKIP
  2437  CD8325        		call	PUTFN
                      	
                      	;check footer (00h*10)
  243A  11000A        		ld	de,0a00h
  243D  CD4E25        		call	CMTSKP
  2440  D1            		pop	de		;target
  2441  1893          		jr	CLDLP1
                      	
  2443                	CLDOM:
  2443  CDAA1A        		call	RCLOSE
  2446  CDBE34        		call	NEW
  2449  C3EB03        		jp	OMERR
                      	
  244C                	CLDBAD:
  244C  CDAA1A        		call	RCLOSE
  244F  215524        		ld	hl,BAD
  2452  C3D500        		jp	PUTSEDIT
                      	
  2455                	BAD:
  2455  42616400      		db	"Bad", 00h
                      	
                      	
                      	;add 4-byte integer and 4byte integer
                      	;input: FAC1(integer),FAC2(integer)
                      	;output: FAC1(integer),f
                      	;destroy: de,hl
  2459                	ADDINT4:
  2459  2A66FF        		ld	hl,(FAC1)
  245C  ED5B6DFF      		ld	de,(FAC2)
  2460  19            		add	hl,de
  2461  2266FF        		ld	(FAC1),hl
  2464  2A68FF        		ld	hl,(FAC1+2)
  2467  ED5B6FFF      		ld	de,(FAC2+2)
  246B  ED5A          		adc	hl,de
  246D  2268FF        		ld	(FAC1+2),hl
  2470  C9            		ret
                      	
                      	
                      	;subtract 4-byte integer from 4-byte integer
                      	;input: FAC1(integer),FAC2(integer)
                      	;output: FAC1(integer),f
                      	;destroy: f,de,hl
  2471                	SUBINT4:
  2471  2A66FF        		ld	hl,(FAC1)
  2474  ED5B6DFF      		ld	de,(FAC2)
  2478  B7            		or	a
  2479  ED52          		sbc	hl,de
  247B  2266FF        		ld	(FAC1),hl
  247E  2A68FF        		ld	hl,(FAC1+2)
  2481  ED5B6FFF      		ld	de,(FAC2+2)
  2485  ED52          		sbc	hl,de
  2487  2268FF        		ld	(FAC1+2),hl
  248A  C9            		ret
                      	
                      	
                      	;a=FAC1(int4)/(hl)<=9, FAC1%=(hl), hl+=4
                      	;input: FAC1(integer), hl=division factor (4byte int) address
                      	;output: a=FAC1/(hl4), FAC1=FAC1%(hl4), hl=hl+4, a=[0,9]
                      	;destroy: f,FAC2
  248B                	DIVINT4:
  248B  C5            		push	bc
  248C  D5            		push	de
  248D  CD4E0C        		call	SETF2
  2490  2B            		dec	hl
  2491  E5            		push	hl
  2492  AF            		xor	a
  2493                	DIVINT4LP:
  2493  3C            		inc	a
  2494  CD7124        		call	SUBINT4
  2497  30FA          		jr	nc,DIVINT4LP
  2499  3D            		dec	a
  249A  CD5924        		call	ADDINT4
  249D  E1            		pop	hl
  249E  D1            		pop	de
  249F  C1            		pop	bc
  24A0  C9            		ret
                      	
                      	
                      	;negate 4-byte integer
                      	;input: FAC1(integer)
                      	;output: FAC1(integer), c-flag, z-flag
                      	;destroy: af,hl
  24A1                	NEGINT4:
  24A1  2166FF        		ld	hl,FAC1
  24A4  AF            		xor	a
  24A5  96            		sub	(hl)
  24A6  77            		ld	(hl),a
  24A7  23            		inc	hl
  24A8  3E00          		ld	a,00h
  24AA  9E            		sbc	a,(hl)
  24AB  77            		ld	(hl),a
  24AC  23            		inc	hl
  24AD  3E00          		ld	a,00h
  24AF  9E            		sbc	a,(hl)
  24B0  77            		ld	(hl),a
  24B1  23            		inc	hl
  24B2  3E00          		ld	a,00h
  24B4  9E            		sbc	a,(hl)
  24B5  77            		ld	(hl),a
  24B6  C9            		ret
                      	
                      	
                      	;compare 4-byte integer and 4-byte integer
                      	;input: FAC1(integer), FAC2(integer)
                      	;output: c-flag,z-flag
                      	;destroy: f,de,hl
  24B7                	CMPINT4:
  24B7  2A68FF        		ld	hl,(FAC1+2)
  24BA  ED5B6FFF      		ld	de,(FAC2+2)
  24BE  B7            		or	a
  24BF  ED52          		sbc	hl,de
  24C1  C0            		ret	nz
  24C2  2A66FF        		ld	hl,(FAC1)
  24C5  ED5B6DFF      		ld	de,(FAC2)
  24C9  ED52          		sbc	hl,de
  24CB  C9            		ret
                      	
                      	
                      	;decrement 4-byte integer
                      	;input: FAC1
                      	;output: FAC1
                      	;destroy: af,hl
  24CC                	DECINT4:
  24CC  2A66FF        		ld	hl,(FAC1)
  24CF  7C            		ld	a,h
  24D0  B5            		or	l		;
  24D1  2B            		dec	hl
  24D2  2266FF        		ld	(FAC1),hl
  24D5  C0            		ret	nz		;
  24D6  2A68FF        		ld	hl,(FAC1+2)
  24D9  2B            		dec	hl
  24DA  2268FF        		ld	(FAC1+2),hl
  24DD  C9            		ret
                      	
                      	
                      	;4-byte integer=0?
                      	;output: a(4 bytes OR),z-flag
                      	;destroy: af
  24DE                	CHKINT4:
  24DE  E5            		push	hl
  24DF  2A66FF        		ld	hl,(FAC1)
  24E2  7C            		ld	a,h
  24E3  B5            		or	l
  24E4  2A68FF        		ld	hl,(FAC1+2)
  24E7  B4            		or	h
  24E8  B5            		or	l
  24E9  E1            		pop	hl
  24EA  C9            		ret
                      	
                      	
                      	;convert float to 4-byte integer (>=0)
                      	;(round toward zero)
                      	;input: FAC1
                      	;output: FAC1 (integer)
                      	;destroy: af,b,de,hl
  24EB                	FTOI4:
  24EB  3EA0          		ld	a,81h+1fh
  24ED  216AFF        		ld	hl,FAC1+4
  24F0  96            		sub	(hl)		;
  24F1  47            		ld	b,a
  24F2  2A66FF        		ld	hl,(FAC1)
  24F5  ED5B68FF      		ld	de,(FAC1+2)
  24F9  CBFA          		set	7,d
  24FB  280A          		jr	z,FTOI4END	;
  24FD                	FTOI4LP:
  24FD  CB3A          		srl	d
  24FF  CB1B          		rr	e
  2501  CB1C          		rr	h
  2503  CB1D          		rr	l
  2505  10F6          		djnz	FTOI4LP
  2507                	FTOI4END:
                      	;	jp	SETI4
                      	
                      	;set 4-byte integer in FAC1
                      	;input: de-hl
  2507                	SETI4:
  2507  2266FF        		ld	(FAC1),hl
  250A  ED5368FF      		ld	(FAC1+2),de
  250E  C9            		ret
                      	
                      	
                      	
                      	;convert 4-byte integer to float (unsigned)
                      	;input: de-hl
                      	;output: FAC1
                      	;destroy: af,b,hl
  250F                	I4TOF:
  250F  D5            		push	de
  2510  7A            		ld	a,d
  2511  B3            		or	e
  2512  B4            		or	h
  2513  B5            		or	l
  2514  CA970C        		jp	z,I2TOFZERO
                      	
  2517  7A            		ld	a,d
  2518  0620          		ld	b,20h
  251A                	I4TOFLP:
  251A  C680          		add	a,80h
  251C  3806          		jr	c,I4TOFEND
  251E  29            		add	hl,hl
  251F  CB13          		rl	e
  2521  17            		rla
  2522  10F6          		djnz	I4TOFLP
                      	
  2524                	I4TOFEND:
  2524  57            		ld	d,a
  2525  C3940C        		jp	I2TOFEND2
                      	
                      	
                      	;check cload header and get file name
                      	;destroy: af,b,de (if no error)
  2528                	_GETFN:	ds	GETFN-_GETFN
  2539                		org	GETFN
                      	
                      	;check header (d3h*10)
  2539  11D30A        		ld	de,0ad3h
  253C  CD4E25        		call	CMTSKP
                      	;file name
  253F  11D1FE        		ld	de,FNAME
                      	
  2542  0606          		ld	b,06h
  2544                	GETFNLP:
  2544  CD8F1A        		call	GETCMTTR
  2547  12            		ld	(de),a
  2548  13            		inc	de
  2549  10F9          		djnz	GETFNLP
  254B  C9            		ret
                      	
                      	
                      	;skip CMT data
                      	;input: d=count, e=data
                      	;destroy: af,b
  254C                	_CMTSKP:ds	CMTSKP-_CMTSKP
  254E                		org	CMTSKP
                      	
  254E  42            		ld	b,d
  254F                	CMTSKPLP:
  254F  CD8F1A        		call	GETCMTTR
  2552  BB            		cp	e
  2553  20F9          		jr	nz,CMTSKP
  2555  10F8          		djnz	CMTSKPLP
  2557  C9            		ret
                      	
                      	
  2558                	_FOUND:	ds	FOUND-_FOUND
  2576                		org	FOUND
                      	
  2576  466F756E643A00		db	"Found:", 00h
                      	
  257D                	SKIP:
  257D  536B69703A00  		db	"Skip:", 00h
                      	
                      	
                      	;put message and file name in device
                      	;input: hl=message address
                      	;destroy: af,hl,(bc,de,FAC1)
  2583                	_PUTFN:	ds	PUTFN-_PUTFN
  2583                		org	PUTFN
                      	
  2583  CDCF30        		call	PUTS
  2586  21D1FE        		ld	hl,FNAME
  2589  CDCF30        		call	PUTS
  258C  C33927        		jp	PUTNL
                      	
                      	
                      	;CMT open for INPUT #-1
                      	;destroy: af,b
  258F                	_INPOPN:ds	INPOPN-_INPOPN
  259A                		org	INPOPN
                      	
                      	;	ld	a,0ffh
                      	;	ld	(VERIFY),a
                      	;	call	ROPEN
  259A  CD5C1A        		call	VRFOPN
  259D  D5            		push	de
  259E  119C06        		ld	de,069ch
  25A1  CD4E25        		call	CMTSKP
  25A4  D1            		pop	de
  25A5  C9            		ret
                      	
                      	
                      	;CMT open for PRINT #-1
                      	;destroy: a,b
  25A6                	_PRTOPN:ds	PRTOPN-_PRTOPN
  25A8                		org	PRTOPN
                      	
  25A8  CDB81A        		call	WOPEN
  25AB  3E9C          		ld	a,9ch
  25AD  0606          		ld	b,06h
  25AF                	PRTOPNLP:
  25AF  CDCC1A        		call	PUTCMT
  25B2  10FB          		djnz	PRTOPNLP
  25B4  C9            		ret
                      	
                      	
                      	;convert intermediate code to command/function ascii characters
                      	;input: a=code
                      	;output: a=first character, hl=address
                      	;destroy: b,f,hl
  25B5                	CNVASC:
  25B5  212902        		ld	hl,CMDNAME-1
  25B8  FEC2          		cp	TAB_
  25BA  3805          		jr	c,CNVASCC
                      	;function
  25BC  21E102        		ld	hl,FNCNAME-1
  25BF  D642          		sub	TAB_-80h
                      	
  25C1                	CNVASCC:
  25C1  D67F          		sub	7fh
  25C3  47            		ld	b,a
  25C4                	CNVASCLP:
  25C4  23            		inc	hl
  25C5  7E            		ld	a,(hl)
  25C6  D680          		sub	80h
  25C8  38FA          		jr	c,CNVASCLP
  25CA  10F8          		djnz	CNVASCLP
  25CC  C9            		ret
                      	
                      	
                      	;wait for about 3.5s
                      	;destroy: af,bc
  25CD                	_WAIT:	ds	WAIT-_WAIT
  25E5                		org	WAIT
                      	
  25E5  010000        		ld	bc,0000h
                      	;25e8
  25E8                	WAITLP:
  25E8  3A18FA        		ld	a,(STOPFLG)
  25EB  FE03          		cp	03h
  25ED  C8            		ret	z
                      	
  25EE  E3            		ex	(sp),hl		;waste time
  25EF  E3            		ex	(sp),hl		;waste time
  25F0  00            		nop			;waste time
                      	
  25F1  0B            		dec	bc
  25F2  78            		ld	a,b
  25F3  B1            		or	c
  25F4  20F2          		jr	nz,WAITLP
  25F6  C9            		ret
                      	
                      	
                      	;EXEC command
  25F7                	C_EXEC:
  25F7  CD920B        		call	NARGMO
  25FA  CD9F0C        		call	FTOI
                      	
                      	;for compatibility with N60-BASIC
  25FD  2A4EFF        		ld	hl,(PROGAD)
  2600  EB            		ex	de,hl
  2601  7C            		ld	a,h
  2602  B5            		or	l
  2603  ED44          		neg			;set c-flag if address<>0
  2605  D5            		push	de
  2606  CDA507        		call	JPHL
  2609  D1            		pop	de
  260A  C9            		ret
                      	
                      	
                      	;get a character from buffer
                      	;input: hl=buffer map address
                      	;output: a,z-flag(1=no input)
                      	;destroy: f,hl
  260B                	GETBF:
  260B  7E            		ld	a,(hl)		;in
  260C  2C            		inc	l		;inc hl
  260D  BE            		cp	(hl)		;out
  260E  C8            		ret	z
  260F  7E            		ld	a,(hl)
  2610  3C            		inc	a
  2611  2C            		inc	l		;inc hl
  2612  2C            		inc	l		;inc hl
  2613  A6            		and	(hl)		;size
  2614  2D            		dec	l		;dec hl
  2615  2D            		dec	l		;dec hl
  2616  77            		ld	(hl),a		;out
  2617  2C            		inc	l		;inc hl
  2618  2C            		inc	l		;inc hl
  2619  2C            		inc	l		;inc hl
  261A  86            		add	a,(hl)		;hl=(buffer address)+a
  261B  2C            		inc	l		;inc hl, l>0, reset z-flag
  261C  66            		ld	h,(hl)
  261D  6F            		ld	l,a
  261E  3001          		jr	nc,GETBFNC
  2620  24            		inc	h		;h>0, reset z-flag
  2621                	GETBFNC:
  2621  7E            		ld	a,(hl)
  2622  C9            		ret
                      	
                      	
                      	;input: STRDSC1, STRDSC4
                      	;destroy: af,bc,de,hl
  2623                	ADDSTR:
  2623  3A39FF        		ld	a,(STRDSC4)
  2626                	ADDSTR2:
  2626  47            		ld	b,a		;;
  2627  3A2DFF        		ld	a,(STRDSC1)
  262A  4F            		ld	c,a		;
  262B  80            		add	a,b		;c+b
  262C  DA0304        		jp	c,LSERR		;over 255 characters
                      	
  262F  CD5D26        		call	GCCHECK
  2632  223DFF        		ld	(STRAD),hl
  2635  23            		inc	hl
  2636  EB            		ex	de,hl
  2637  2A2FFF        		ld	hl,(STRDSC1+2)
  263A  ED532FFF      		ld	(STRDSC1+2),de
                      	
  263E  78            		ld	a,b		;;
  263F  81            		add	a,c		;
  2640  322DFF        		ld	(STRDSC1),a
  2643  90            		sub	b		;c=0?
                      	
  2644  78            		ld	a,b
  2645  0600          		ld	b,00h
  2647  2802          		jr	z,ADDSZ1
  2649  EDB0          		ldir
  264B                	ADDSZ1:
  264B  B7            		or	a
  264C  2806          		jr	z,ADDSZ2
  264E  4F            		ld	c,a		;b=0
  264F  2A3BFF        		ld	hl,(STRDSC4+2)
  2652  EDB0          		ldir
  2654                	ADDSZ2:
  2654  AF            		xor	a
  2655  3239FF        		ld	(STRDSC4),a
  2658  3C            		inc	a
  2659  3225FF        		ld	(ARGTYP),a	;=1
  265C  C9            		ret
                      	
                      	
                      	;check string area and call GC if necessary
                      	;input: a=new string length
                      	;output: hl=new (STRAD)+1
                      	;destroy: af,de
  265D                	GCCHECK:
  265D  C5            		push	bc
  265E  1600          		ld	d,00h
  2660  5F            		ld	e,a
  2661  D5            		push	de
  2662  CD7526        		call	CHKSAREA
  2665  D1            		pop	de
  2666  300B          		jr	nc,GCCHECKOK
  2668  D5            		push	de
  2669  CD0F31        		call	GC
  266C  D1            		pop	de
  266D  CD7526        		call	CHKSAREA
  2670  DA0004        		jp	c,OSERR
  2673                	GCCHECKOK:
  2673  C1            		pop	bc
  2674  C9            		ret
                      	
                      	;check string area
  2675                	CHKSAREA:
  2675  2A3DFF        		ld	hl,(STRAD)
  2678  B7            		or	a
  2679  ED52          		sbc	hl,de
  267B  ED5B5BFA      		ld	de,(STACK)
  267F  E7            		rst	CPHLDE
  2680  C9            		ret
                      	
                      	
                      	;get a string argument
                      	;input: hl=program address
                      	;output: a=length, de=string address, hl=next address, z-flag(1=ok)
                      	;destroy: f,bc,FAC1,FAC2
  2681                	STRARG:
  2681  CD5E3F        		call	CHKCLN
  2684  CA1204        		jp	z,MOERR
  2687  CD2C17        		call	ARG
  268A                	STRARG2:
  268A  EB            		ex	de,hl
  268B  CDA70B        		call	CHKSTR
                      	;get string pointer
  268E  23            		inc	hl
  268F  23            		inc	hl
  2690  46            		ld	b,(hl)
  2691  23            		inc	hl
  2692  66            		ld	h,(hl)
  2693  68            		ld	l,b
  2694  EB            		ex	de,hl
  2695  C9            		ret
                      	
                      	
                      	;get string,integer argument for LEFT$(),RIGHT$(),MID$()
                      	;input: hl=program address
                      	;output: STRDSC1, a=length, hl=string address, FAC1,de=integer
                      	;destroy: FAC2,f,bc
  2696                	ARGSI1:
  2696  CDB50B        		call	CHKLPAR
  2699  CD8126        		call	STRARG
  269C  F5            		push	af
  269D  322DFF        		ld	(STRDSC1),a	;length
  26A0  ED532FFF      		ld	(STRDSC1+2),de	;string address
  26A4  7E            		ld	a,(hl)
  26A5  FE2C          		cp	','
  26A7  C2DC03        		jp	nz,SNERR
  26AA  CDB226        		call	ARGI1
  26AD  2A2FFF        		ld	hl,(STRDSC1+2)	;string address
  26B0  F1            		pop	af		;length
  26B1  C9            		ret
                      	
                      	
                      	;protect string descriptor and get integer argument
                      	;input: hl=program address
                      	;output: FAC1,de=integer
                      	;destroy: FAC2,af,bc,hl
  26B2                	ARGI1:
  26B2  E5            		push	hl		;program address
  26B3  CDE819        		call	COPYSTR
  26B6  E1            		pop	hl
  26B7  CDE30D        		call	INT1INC
  26BA  C3FC19        		jp	BACKSTR
                      	
                      	
                      	;put a character in device
                      	;input: a=character code, (DEVICE)=0:CRT, 1:printer, 2:RS-232C, 80h-ffh:CMT
                      	; (1,4,5,8,9,c,d...:printer, 2,3,6,7,a,b,e,f...:RS-232C)
                      	;destroy: af
  26BD                	_PUTDEV:ds	PUTDEV-_PUTDEV
  26C7                		org	PUTDEV
                      	
  26C7  CDCFFF        		call	HOOKPUT
  26CA  F5            		push	af
  26CB  3A58FA        		ld	a,(DEVICE)
  26CE  B7            		or	a
  26CF  2856          		jr	z,PUTCRT
  26D1  FACD1A        		jp	m,PUTCMT2
  26D4  E602          		and	02h
  26D6  283A          		jr	z,PUTPRT2
                      	;	jr	nz,PUT232
                      	
                      	;input: a
                      	;output: none
                      	;destroy: af
  26D8                	PUT232:
  26D8  3E17          		ld	a,17h		;RTS=0
  26DA  D381          		out	(81h),a
                      	
  26DC                	PUT232LP:
  26DC  DB81          		in	a,(81h)
  26DE  2F            		cpl
  26DF  E605          		and	05h
  26E1  280C          		jr	z,PUT232Z	;if TxEMPTY=1, TxRDY=1
                      	
  26E3  3A18FA        		ld	a,(STOPFLG)
  26E6  FE03          		cp	03h
  26E8  20F2          		jr	nz,PUT232LP
                      	;stop
  26EA  CDF226        		call	PUT232END
  26ED  1862          		jr	STOPSP
                      	
  26EF                	PUT232Z:
  26EF  F1            		pop	af
  26F0  D380          		out	(80h),a
  26F2                	PUT232END:
  26F2  3E37          		ld	a,37h		;RTS=1
  26F4  D381          		out	(81h),a
  26F6  C9            		ret
                      	
                      	
  26F7                	PUTPRTTAB:
  26F7  3E20          		ld	a,' '
  26F9  CD1727        		call	PUTPRT3		;a<-(PRTPOS)
  26FC  E607          		and	07h
  26FE  20F7          		jr	nz,PUTPRTTAB
  2700  C9            		ret
                      	
                      	
                      	;put new line to printer
                      	;destroy: af
  2701                	_PUTPRNL:ds	PUTPRNL-_PUTPRNL
  2701                		org	PUTPRNL
  2701  3E01          		ld	a,01h
  2703  3258FA        		ld	(DEVICE),a
  2706  3A57FA        		ld	a,(PRTPOS)
  2709  B7            		or	a
  270A  C43927        		call	nz,PUTNL
  270D  AF            		xor	a
  270E  3258FA        		ld	(DEVICE),a
  2711  C9            		ret
                      	
                      	
  2712                	PUTPRT2:
  2712  F1            		pop	af
  2713  FE09          		cp	09h
  2715  28E0          		jr	z,PUTPRTTAB
  2717                	PUTPRT3:
  2717  CD1C1A        		call	PUTPRT
  271A  D60D          		sub	0dh
  271C  2805          		jr	z,PUTPRTZ	;a=0 if CR
  271E  D8            		ret	c
  271F  3A57FA        		ld	a,(PRTPOS)
  2722  3C            		inc	a
  2723                	PUTPRTZ:
  2723  3257FA        		ld	(PRTPOS),a
  2726  C9            		ret
                      	
                      	
  2727                	PUTCRT:
  2727  F1            		pop	af
  2728  C37510        		jp	PRTC
                      	
                      	
                      	;put new line if necessary
                      	;destroy: af
  272B                	_PUTNLX:ds	PUTNLX-_PUTNLX
  272D                		org	PUTNLX
  272D  3A58FA        		ld	a,(DEVICE)
  2730  B7            		or	a
  2731  CA3C09        		jp	z,PRTNLX
  2734  3D            		dec	a
  2735  28CA          		jr	z,PUTPRNL
  2737  1800          		jr	PUTNL
                      	
                      	
                      	;put new line
                      	;destroy: af
  2739                	_PUTNL:	ds	PUTNL-_PUTNL
  2739                		org	PUTNL
                      	
  2739  3E0D          		ld	a,0dh
  273B  CDC726        		call	PUTDEV
  273E  3E0A          		ld	a,0ah
  2740  1885          		jr	PUTDEV
                      	
                      	
                      	;input: a=length, hl=string address
                      	;destroy: af,bc,de,hl
  2742                	MAKESTR:
  2742  322DFF        		ld	(STRDSC1),a
  2745  222FFF        		ld	(STRDSC1+2),hl
  2748  AF            		xor	a
  2749  C32626        		jp	ADDSTR2
                      	
                      	
                      	;STOP and ESC
                      	;destroy: af
  274C                	_STOPESC:ds	STOPESC-_STOPESC
  274D                		org	STOPESC
                      	
  274D  CD5B27        		call	CHKSTOP
  2750  C0            		ret	nz
                      	;	jp	STOPSP
                      	
                      	;reset sp and stop
  2751                	STOPSP:
  2751  ED7B5BFA      		ld	sp,(STACK)
  2755  21FFFF        		ld	hl,0ffffh
  2758  C33C35        		jp	STOP2
                      	
                      	
                      	;check STOP/ESC
                      	;output: z-flag (1=STOP)
                      	;destroy: af
  275B                	CHKSTOP:
  275B  3A18FA        		ld	a,(STOPFLG)
  275E  FE03          		cp	03h
  2760  C8            		ret	z
  2761  FE1B          		cp	1bh
  2763  C0            		ret	nz
  2764  CDBC0F        		call	GETCH		;cancel ESC
  2767  18F2          		jr	CHKSTOP
                      	
                      	
                      	;INKEY$
  2769                	F_INKY:
  2769  216218        		ld	hl,FNCRTN
  276C  E5            		push	hl
                      	
  276D  CDBC0F        		call	GETCH
  2770  282A          		jr	z,INKYZ
                      	
  2772  FE03          		cp	03h
  2774  2826          		jr	z,INKYZ
  2776  FE1B          		cp	1bh
  2778  2822          		jr	z,INKYZ
                      	
  277A  47            		ld	b,a		;
  277B                	INKYNZ:
  277B  3E01          		ld	a,01h		;new string length=1
  277D  3230FF        		ld	(STRDSC1+3),a	;old string descriptor address < (STRAD)
  2780  CD5D26        		call	GCCHECK
  2783  223DFF        		ld	(STRAD),hl
  2786  23            		inc	hl
  2787  70            		ld	(hl),b		;
  2788  222FFF        		ld	(STRDSC1+2),hl	;new string descriptor address
  278B  3E01          		ld	a,01h
  278D                	INKYLEN:
  278D  322DFF        		ld	(STRDSC1),a
                      	
  2790                	INKYEND:
  2790  212DFF        		ld	hl,STRDSC1
  2793  2267FF        		ld	(FAC1+1),hl
  2796  3E01          		ld	a,01h
  2798  3225FF        		ld	(ARGTYP),a
  279B  C9            		ret
                      	
  279C                	INKYZ:
  279C  AF            		xor	a
  279D  18EE          		jr	INKYLEN
                      	
                      	
                      	;get device number
                      	;in	out
                      	;#0	0	CRT
                      	;#-1	80h	CMT
                      	;#-2	2	RS-232C
                      	;#-3	1	printer
                      	;input: hl=program address
                      	;output: a, hl,(PROGAD)=next address
                      	;destroy: f,bc,de
  279F                	DEVNUM:
  279F  CD573F        		call	SKIPSP
  27A2  FE23          		cp	'#'
  27A4  3E00          		ld	a,00h
  27A6  C0            		ret	nz
                      	
  27A7  23            		inc	hl
  27A8  CD140E        		call	INT2ARG
  27AB  E5            		push	hl
  27AC  1B            		dec	de
  27AD  210400        		ld	hl,0004h
  27B0  19            		add	hl,de
  27B1  D2E503        		jp	nc,FCERR
  27B4  7D            		ld	a,l
  27B5  3C            		inc	a
  27B6  FE03          		cp	03h
  27B8  3803          		jr	c,DEVNUMC	;#-2,#-3
  27BA  E601          		and	01h
  27BC  0F            		rrca
  27BD                	DEVNUMC:
  27BD  E1            		pop	hl
  27BE  F5            		push	af
  27BF  CD693F        		call	CHKCMM
  27C2  C2DC03        		jp	nz,SNERR
  27C5  224EFF        		ld	(PROGAD),hl
  27C8  F1            		pop	af
  27C9  C9            		ret
                      	
                      	
                      	;convert string to 2-byte integer (unsigned)
                      	;input: hl=program address
                      	;output: de=integer, hl=next address
                      	;destroy: af,bc
  27CA                	ATOI2:
  27CA  0600          		ld	b,00h
                      	
                      	;input: hl=program address, b=string length
                      	;output: b=remaining length, de=integer, hl=next address
  27CC                	ATOI2LEN:
  27CC  110000        		ld	de,0000h
  27CF                	ATOI2LP:
  27CF  CD573F        		call	SKIPSP
  27D2  D630          		sub	'0'
  27D4  FE0A          		cp	'9'-'0'+1
  27D6  D0            		ret	nc
                      	
  27D7  E5            		push	hl
                      	
  27D8  2166E6        		ld	hl,0-6554
  27DB  19            		add	hl,de
  27DC  3813          		jr	c,ATOI2END
                      	
  27DE  62            		ld	h,d
  27DF  6B            		ld	l,e
  27E0  29            		add	hl,hl
  27E1  29            		add	hl,hl
  27E2  19            		add	hl,de
  27E3  29            		add	hl,hl
                      	
  27E4  85            		add	a,l
  27E5  6F            		ld	l,a
  27E6  3003          		jr	nc,ATOI2NC
  27E8  24            		inc	h
  27E9  2806          		jr	z,ATOI2END
                      	
  27EB                	ATOI2NC:
  27EB  EB            		ex	de,hl
  27EC  E1            		pop	hl
  27ED  23            		inc	hl
  27EE  10DF          		djnz	ATOI2LP
  27F0  C9            		ret
                      	
  27F1                	ATOI2END:
  27F1  E1            		pop	hl
  27F2  C9            		ret
                      	
                      	
                      	;convert string to float (integer part)
                      	;input: hl=address
                      	;output: FAC1, hl=next address
                      	;destroy: FAC2,af,bc,de
  27F3                	ATOIF:
  27F3  E5            		push	hl
  27F4  CD420C        		call	SETZERO
  27F7  E1            		pop	hl
  27F8  CD853A        		call	SKIPSPA
  27FB  C8            		ret	z
                      	
  27FC  0600          		ld	b,00h		;sign for CTOF
  27FE  23            		inc	hl
  27FF  FE2B          		cp	'+'
  2801  280F          		jr	z,ATOIFLP
  2803  FECA          		cp	PLUS_
  2805  280B          		jr	z,ATOIFLP
  2807  04            		inc	b
  2808  FE2D          		cp	'-'
  280A  2806          		jr	z,ATOIFLP
  280C  FECB          		cp	MINUS_
  280E  2802          		jr	z,ATOIFLP
  2810  05            		dec	b
  2811  2B            		dec	hl
  2812                	ATOIFLP:
  2812  CD1828        		call	CTOF
  2815  38FB          		jr	c,ATOIFLP
  2817  C9            		ret
                      	
                      	
                      	;FAC1 = FAC1 * 10 + [0-9]
                      	;input: FAC1, hl=address, b=sign(0=plus, 1=minus)
                      	;output: FAC1, c-flag(1=OK), hl=next address
                      	;destroy: FAC2,af,de
  2818                	CTOF:
  2818  CD853A        		call	SKIPSPA
  281B  C8            		ret	z		;c-flag=0
                      	
  281C  D630          		sub	'0'
  281E  FE0A          		cp	'9'-'0'+1
  2820  D0            		ret	nc
  2821  23            		inc	hl
  2822  E5            		push	hl
                      	
  2823  C5            		push	bc
  2824  F5            		push	af
  2825  CD1F39        		call	ABS
  2828  CD9F37        		call	MULF10
  282B  CD5239        		call	CPYFAC
  282E  F1            		pop	af
  282F  CD7D0C        		call	I1TOFA
  2832  CD9E36        		call	ADDF
  2835  C1            		pop	bc
                      	
  2836  78            		ld	a,b
  2837  0F            		rrca
  2838  DC280D        		call	c,NEGABS
                      	
  283B  E1            		pop	hl
  283C  37            		scf
  283D  C9            		ret
                      	
                      	
                      	;insert a character
                      	;output: hl=VRAM address
                      	;destroy: f,bc,de
  283E                	INSERT:
  283E  F5            		push	af
                      	
  283F  2AAAFD        		ld	hl,(CSRAD)
  2842  CDE628        		call	GETSCRC
  2845  47            		ld	b,a		;
                      	
  2846  23            		inc	hl
  2847  CD3314        		call	CHKLINE
  284A  204C          		jr	nz,INSSCRL
                      	
  284C  CD0716        		call	CNVATT1
  284F  4F            		ld	c,a
                      	
  2850                	INSLP:
  2850  CDE628        		call	GETSCRC
  2853  25            		dec	h
  2854  25            		dec	h
  2855  71            		ld	(hl),c
  2856  24            		inc	h
  2857  24            		inc	h
                      	
  2858  70            		ld	(hl),b
  2859  47            		ld	b,a
  285A  23            		inc	hl
  285B  CD3314        		call	CHKLINE
  285E  28F0          		jr	z,INSLP
                      	
  2860  78            		ld	a,b
  2861  FE20          		cp	' '
  2863  2033          		jr	nz,INSSCRL
  2865  F1            		pop	af
  2866  C9            		ret
                      	
  2867                	NOINSTBL:
  2867  020305060B0C0D		db	02h, 03h, 05h, 06h, 0bh, 0ch, 0dh, 15h, 1ch, 1dh, 1eh, 1fh
                      	
                      	
                      	;clear screen using console parameters
                      	;destroy: af,bc,de,hl
  2873                	_CTLL:	ds	CTLL-_CTLL
  2874                		org	CTLL
                      	
  2874  CD4911        		call	CTLHOM
  2877  ED4BA4FD      		ld	bc,(FSTLIN)	;c=(FSTLIN),b=(LASTLIN)
  287B  78            		ld	a,b
  287C  91            		sub	c
  287D  3C            		inc	a
                      	
                      	;input: e=first line+1, a=last line-first line+1
  287E                	CLSMAIN2:
  287E  0600          		ld	b,00h
  2880  21B6FD        		ld	hl,LINEST-1
  2883  09            		add	hl,bc
  2884  47            		ld	b,a
  2885  04            		inc	b
  2886                	CLSLP1:
  2886  70            		ld	(hl),b		;b>0
  2887  23            		inc	hl
  2888  10FC          		djnz	CLSLP1
                      	
  288A  47            		ld	b,a
  288B                	CLSLP2:
  288B  69            		ld	l,c
  288C  CDB811        		call	Y2AD
  288F  CDDA11        		call	DELLIN
  2892  0C            		inc	c
  2893  10F6          		djnz	CLSLP2
                      	
  2895  C3B512        		jp	PRTFKEY
                      	
                      	
  2898                	INSSCRL:
  2898  E5            		push	hl
                      	
  2899  CD5011        		call	AD2XY
                      	
  289C  3AA5FD        		ld	a,(LASTLIN)
  289F  BD            		cp	l
  28A0  381F          		jr	c,INSSCRLU
                      	
  28A2  67            		ld	h,a		;(LASTLIN)
  28A3  2835          		jr	z,NOSCRLD
  28A5  CDA912        		call	SCRLDW
                      	
  28A8                	INSSCRLEND:
  28A8  4D            		ld	c,l		;;
  28A9  2D            		dec	l
  28AA  AF            		xor	a
                      	
  28AB                	INSSCRLEND2:
  28AB  CD4F14        		call	SETLINE
  28AE  69            		ld	l,c		;;
  28AF  CDB811        		call	Y2AD
  28B2  CDDA11        		call	DELLIN
  28B5  E1            		pop	hl
                      	
  28B6  25            		dec	h
  28B7  25            		dec	h
  28B8  CD0716        		call	CNVATT1
  28BB  77            		ld	(hl),a
  28BC  24            		inc	h
  28BD  24            		inc	h
                      	
  28BE  70            		ld	(hl),b		;
  28BF  F1            		pop	af
  28C0  C9            		ret
                      	
  28C1                	INSSCRLU:
  28C1  E1            		pop	hl
  28C2  11E0FF        		ld	de,0-COLUMNS
  28C5  19            		add	hl,de
  28C6  E5            		push	hl
                      	
  28C7  6F            		ld	l,a		;(LASTLIN)
  28C8  3E1E          		ld	a,1eh		;up
  28CA  CD7510        		call	PRTC
                      	
  28CD  3AA2FD        		ld	a,(CONSOL1)
  28D0  67            		ld	h,a
  28D1  95            		sub	l
  28D2  4D            		ld	c,l
  28D3  280B          		jr	z,NOSCRLU	;a=0
                      	
  28D5  CD6012        		call	SCRLUP
  28D8  18CE          		jr	INSSCRLEND
                      	
  28DA                	NOSCRLD:
  28DA  AF            		xor	a
  28DB  32A4FE        		ld	(INPTXY),a	;scroll out
  28DE  18C8          		jr	INSSCRLEND
                      	
  28E0                	NOSCRLU:
                      	;	xor	a
  28E0  32A4FE        		ld	(INPTXY),a	;scroll out
  28E3  3C            		inc	a
  28E4  18C5          		jr	INSSCRLEND2
                      	
                      	
                      	;get character from screen
                      	;input: hl
                      	;output: a
                      	;destroy: f
  28E6                	GETSCRC:
  28E6  7E            		ld	a,(hl)
  28E7  25            		dec	h
  28E8  25            		dec	h
  28E9  CB76          		bit	6,(hl)
  28EB  2802          		jr	z,GETSCRCZ
  28ED  3E20          		ld	a,' '
  28EF                	GETSCRCZ:
  28EF  24            		inc	h
  28F0  24            		inc	h
  28F1  C9            		ret
                      	
                      	
                      	;screen input
                      	;output: hl=INPBUF-1, c-flag(1=stop)
                      	;destroy: af,bc,de
  28F2                	_INPTSCR:ds	INPTSCR-_INPTSCR
  28F9                		org	INPTSCR
                      	
  28F9  CD5529        		call	SCREDIT
  28FC  D8            		ret	c
  28FD  3E47          		ld	a,71
  28FF  1811          		jr	COPYIBF
                      	
                      	
                      	;one line input for keyboard
                      	;output: hl=INPBUF-1, c-flag(1=stop)
                      	;destroy: af,bc,de
  2901                	_INPT1:	ds	INPT1-_INPT1
  2905                		org	INPT1
                      	
  2905  212401        		ld	hl,QMARK
  2908  CDCF30        		call	PUTS
  290B  CD5529        		call	SCREDIT
  290E  D8            		ret	c
  290F  3AA6FE        		ld	a,(INPTX)
                      	;	jr	COPYIBF
                      	
                      	;copy characters to input buffer from VRAM
                      	;input: a=length, hl=start position address
                      	;output: hl=INPBUF-1, c-flag=0
                      	;destroy: af,bc,de
  2912                	COPYIBF:
  2912  11DAFE        		ld	de,INPBUF
  2915  B7            		or	a
  2916  2813          		jr	z,CPIBFZ
  2918  4F            		ld	c,a
  2919  0647          		ld	b,71
  291B                	CPIBFLP1:
  291B  CDE628        		call	GETSCRC
  291E  FE20          		cp	20h
  2920  300F          		jr	nc,CPIBFNC
  2922  EB            		ex	de,hl
  2923  3614          		ld	(hl),14h
  2925  EB            		ex	de,hl
  2926  1006          		djnz	CPIBFGRP
  2928  AF            		xor	a
  2929  1813          		jr	CPIBFNZ
  292B                	CPIBFZ:
  292B  12            		ld	(de),a
  292C  1810          		jr	CPIBFNZ
  292E                	CPIBFGRP:
  292E  13            		inc	de
  292F  C630          		add	a,30h
                      	
  2931                	CPIBFNC:
  2931  12            		ld	(de),a
  2932  13            		inc	de
  2933  23            		inc	hl
  2934  CD3314        		call	CHKLINE
  2937  2005          		jr	nz,CPIBFNZ
  2939  0D            		dec	c
  293A  2802          		jr	z,CPIBFNZ
  293C  10DD          		djnz	CPIBFLP1
                      	
  293E                	CPIBFNZ:
  293E  2B            		dec	hl
  293F  CD5011        		call	AD2XY
  2942  CD6D11        		call	SETCSR
  2945  CD3927        		call	PUTNL
                      	
  2948                	CPIBFLP2:
  2948  1B            		dec	de
  2949  1A            		ld	a,(de)
  294A  FE20          		cp	' '
  294C  28FA          		jr	z,CPIBFLP2
  294E  13            		inc	de
  294F  AF            		xor	a
  2950  12            		ld	(de),a
                      	
  2951  21D9FE        		ld	hl,INPBUF-1
  2954  C9            		ret
                      	
                      	
                      	;screen edit
                      	;output: hl=start position address, c-flag(1=stop)
                      	;destroy: af,bc,de
  2955                	SCREDIT:
  2955  CD4A14        		call	CUTLINE
  2958  2AA8FD        		ld	hl,(CSRY)
  295B  22A5FE        		ld	(INPTX-1),hl	;h=end position for INPUT command
  295E  22A4FE        		ld	(INPTXY),hl	;initial position for INPUT command
  2961  3AABFD        		ld	a,(CSRAD+1)
  2964  32A7FE        		ld	(INPTPAG),a	;page for INPUT command
                      	
  2967                	SEDLP:
  2967  CDC40F        		call	GETC
  296A  CD6F29        		call	SEDMAIN
  296D  18F8          		jr	SEDLP
                      	
                      	
                      	;screen edit main routine
  296F                	SEDMAIN:
  296F  FE20          		cp	20h
  2971  3836          		jr	c,SEDCTL
                      	
  2973  2AA8FE        		ld	hl,(INSMODE)
  2976  2C            		inc	l
  2977  2D            		dec	l
  2978  C43E28        		call	nz,INSERT
                      	
  297B                	SEDPRTC:
  297B  CD7510        		call	PRTC
                      	
  297E                	CHKIPOS2:
  297E  2AAAFD        		ld	hl,(CSRAD)
                      	
                      	;check cursor position for input command
                      	;input: hl=cursor address
                      	;output: hl=cursor XY, de=cursor address
                      	;destroy: af
  2981                	CHKIPOS:
  2981  54            		ld	d,h
  2982  5D            		ld	e,l
  2983  CD5011        		call	AD2XY
  2986  3AA4FE        		ld	a,(INPTXY)	;y+1
  2989  BD            		cp	l
  298A  C0            		ret	nz
                      	
  298B  3AA6FE        		ld	a,(INPTX)
  298E  BC            		cp	h
  298F  3004          		jr	nc,IPOSNC
  2991  7C            		ld	a,h
  2992  32A6FE        		ld	(INPTX),a
  2995                	IPOSNC:
  2995  3AA5FE        		ld	a,(INPTXY+1)	;x+1
  2998  BC            		cp	h
  2999  D8            		ret	c
                      	
  299A  3AA7FE        		ld	a,(INPTPAG)
  299D  AA            		xor	d
  299E  E6F0          		and	0f0h
  29A0  C0            		ret	nz
                      	
  29A1  22A4FE        		ld	(INPTXY),hl
  29A4  C9            		ret
                      	
                      	
  29A5                	DELSTR:
  29A5  1D201D00      		db	1dh, ' ', 1dh, 00h
                      	
                      	
                      	;control code
  29A9                	SEDCTL:
  29A9  216728        		ld	hl,NOINSTBL
  29AC  010C00        		ld	bc,000ch
  29AF  EDB1          		cpir
  29B1  2004          		jr	nz,SEDCTLNZ
  29B3  21A8FE        		ld	hl,INSMODE
  29B6  70            		ld	(hl),b		;b=0
  29B7                	SEDCTLNZ:
  29B7  2AAAFD        		ld	hl,(CSRAD)
                      	
  29BA  FE02          		cp	02h
  29BC  287D          		jr	z,SEDCTLB
  29BE  FE03          		cp	03h
  29C0  CACD2A        		jp	z,SEDSTOP
  29C3  FE05          		cp	05h
  29C5  2863          		jr	z,SEDCTLE
  29C7  FE06          		cp	06h
  29C9  CA5D2A        		jp	z,SEDCTLF
  29CC  FE07          		cp	07h
  29CE  CA3C2B        		jp	z,SEDBELL
  29D1  FE08          		cp	08h
  29D3  281E          		jr	z,SEDDEL
  29D5  FE09          		cp	09h
  29D7  CAAF2A        		jp	z,SEDTAB
  29DA  FE0A          		cp	0ah
  29DC  CA882A        		jp	z,SEDCTLJ
  29DF  FE0D          		cp	0dh
  29E1  CAEF2A        		jp	z,SEDRET
  29E4  FE15          		cp	15h
  29E6  283D          		jr	z,SEDCTLU
  29E8  FE12          		cp	12h
  29EA  208F          		jr	nz,SEDPRTC	;14h,1ch,1dh,1eh,1fh
                      	
  29EC                	SEDINS:
  29EC  21A8FE        		ld	hl,INSMODE
  29EF  7E            		ld	a,(hl)
  29F0  2F            		cpl
  29F1  77            		ld	(hl),a
  29F2  C9            		ret
                      	
                      	
  29F3                	SEDDEL:
  29F3  CD3314        		call	CHKLINE
  29F6  EB            		ex	de,hl
  29F7  21A529        		ld	hl,DELSTR
  29FA  2802          		jr	z,SEDDELZ
  29FC  13            		inc	de
  29FD  23            		inc	hl
  29FE                	SEDDELZ:
  29FE  D5            		push	de		;
  29FF  CDCF30        		call	PUTS
  2A02  CD7E29        		call	CHKIPOS2
  2A05  D1            		pop	de		;
  2A06  62            		ld	h,d
  2A07  6B            		ld	l,e
  2A08  1B            		dec	de
  2A09  CD0716        		call	CNVATT1
  2A0C  4F            		ld	c,a
  2A0D                	DELLP:
  2A0D  CDE628        		call	GETSCRC
  2A10  12            		ld	(de),a
                      	
  2A11  25            		dec	h
  2A12  25            		dec	h
  2A13  71            		ld	(hl),c
  2A14  24            		inc	h
  2A15  24            		inc	h
                      	
  2A16  13            		inc	de
  2A17  23            		inc	hl
                      	
  2A18  CD3314        		call	CHKLINE
  2A1B  28F0          		jr	z,DELLP
                      	
  2A1D  2B            		dec	hl
  2A1E  3620          		ld	(hl),' '
  2A20  25            		dec	h
  2A21  25            		dec	h
  2A22  71            		ld	(hl),c
                      	
  2A23  C9            		ret
                      	
                      	
  2A24                	CTLULP:
  2A24  2B            		dec	hl
  2A25                	SEDCTLU:
  2A25  CD3314        		call	CHKLINE
  2A28  28FA          		jr	z,CTLULP
                      	
  2A2A                	SEDCTLE:
  2A2A  25            		dec	h
  2A2B  25            		dec	h
  2A2C  CD0716        		call	CNVATT1
  2A2F  77            		ld	(hl),a
  2A30  24            		inc	h
  2A31  24            		inc	h
  2A32  3620          		ld	(hl),' '
  2A34  23            		inc	hl
  2A35  CD3314        		call	CHKLINE
  2A38  28F0          		jr	z,SEDCTLE
  2A3A  C9            		ret
                      	
                      	
  2A3B                	SEDCTLB:
  2A3B  CD4C2A        		call	CHKCTLB
  2A3E  30FB          		jr	nc,SEDCTLB
  2A40                	CTLBLP:
  2A40  CD4C2A        		call	CHKCTLB
  2A43  38FB          		jr	c,CTLBLP
  2A45  23            		inc	hl
  2A46  CD8129        		call	CHKIPOS
  2A49  C36D11        		jp	SETCSR
                      	
  2A4C                	CHKCTLB:
  2A4C  2B            		dec	hl
  2A4D  54            		ld	d,h
  2A4E  5D            		ld	e,l
  2A4F  CD5011        		call	AD2XY
  2A52  3AA2FD        		ld	a,(CONSOL1)
  2A55  2C            		inc	l
  2A56  BD            		cp	l
  2A57  3821          		jr	c,CTLBC
  2A59                	CTLBNC:
  2A59  F1            		pop	af		;cancel return address
  2A5A  C34C11        		jp	CTLCR
                      	
                      	
  2A5D                	SEDCTLF:
  2A5D  CD6E2A        		call	CHKCTLF
  2A60  38FB          		jr	c,SEDCTLF
  2A62                	CTLFLP:
  2A62  CD6E2A        		call	CHKCTLF
  2A65  30FB          		jr	nc,CTLFLP
  2A67  EB            		ex	de,hl
  2A68  CD6D11        		call	SETCSR
  2A6B  C37E29        		jp	CHKIPOS2
                      	
  2A6E                	CHKCTLF:
  2A6E  23            		inc	hl
  2A6F  54            		ld	d,h
  2A70  5D            		ld	e,l
  2A71  CD5011        		call	AD2XY
  2A74  3AA5FD        		ld	a,(LASTLIN)
  2A77  BD            		cp	l
  2A78  3807          		jr	c,CTLFC
  2A7A                	CTLBC:
  2A7A  EB            		ex	de,hl
  2A7B  CDE628        		call	GETSCRC
  2A7E  C3CF0B        		jp	ALPNUM2
                      	
  2A81                	CTLFC:
  2A81  6F            		ld	l,a
  2A82  2620          		ld	h,COLUMNS
  2A84  F1            		pop	af		;cancel return address
  2A85  C36D11        		jp	SETCSR
                      	
  2A88                	SEDCTLJ:
  2A88  3AA8FE        		ld	a,(INSMODE)
  2A8B  B7            		or	a
  2A8C  3E0A          		ld	a,0ah
  2A8E  CA7B29        		jp	z,SEDPRTC
                      	
  2A91  2AA8FD        		ld	hl,(CSRY)	;l=y+1, h=x+1
  2A94  3E21          		ld	a,COLUMNS+1
  2A96  94            		sub	h
  2A97  47            		ld	b,a
  2A98                	CTLJLP:
  2A98  C5            		push	bc
  2A99  3E20          		ld	a,' '
  2A9B  CD3E28        		call	INSERT
  2A9E  2AAAFD        		ld	hl,(CSRAD)
  2AA1  77            		ld	(hl),a
  2AA2  C1            		pop	bc
  2AA3  10F3          		djnz	CTLJLP
                      	
  2AA5  CD5011        		call	AD2XY
  2AA8  CD6D11        		call	SETCSR
  2AAB  7C            		ld	a,h		;>0
  2AAC  C34F14        		jp	SETLINE
                      	
                      	
  2AAF                	SEDTAB:
  2AAF  3AA9FD        		ld	a,(CSRX)
  2AB2  D619          		sub	COLUMNS-07h
  2AB4  DE07          		sbc	a,07h
  2AB6  C8            		ret	z
  2AB7  2F            		cpl
  2AB8  E607          		and	07h
  2ABA  3C            		inc	a
  2ABB  47            		ld	b,a
  2ABC  3AA8FE        		ld	a,(INSMODE)
  2ABF  E604          		and	04h
  2AC1  C61C          		add	a,1ch		;1ch(right) or 20h(space)
  2AC3  4F            		ld	c,a
  2AC4                	SEDTABLP:
  2AC4  C5            		push	bc
  2AC5  79            		ld	a,c
  2AC6  CD6F29        		call	SEDMAIN
  2AC9  C1            		pop	bc
  2ACA  10F8          		djnz	SEDTABLP
  2ACC  C9            		ret
                      	
                      	
  2ACD                	SEDSTOP:
  2ACD  E1            		pop	hl		;cancel return address
  2ACE  2AA8FD        		ld	hl,(CSRY)
  2AD1  AF            		xor	a
  2AD2  67            		ld	h,a
  2AD3  11B5FD        		ld	de,LINEST-2
  2AD6  19            		add	hl,de
  2AD7                	STOPLP:
  2AD7  23            		inc	hl
  2AD8  B6            		or	(hl)
  2AD9  28FC          		jr	z,STOPLP
                      	
                      	;	or	a
  2ADB  ED52          		sbc	hl,de
  2ADD  2D            		dec	l
  2ADE  CD6D11        		call	SETCSR
  2AE1  CD3927        		call	PUTNL
                      	
  2AE4  21DAFE        		ld	hl,INPBUF
  2AE7  AF            		xor	a
  2AE8  3218FA        		ld	(STOPFLG),a
  2AEB  77            		ld	(hl),a
  2AEC  2B            		dec	hl
  2AED  37            		scf
  2AEE  C9            		ret
                      	
                      	
  2AEF                	SEDRET:
  2AEF  F1            		pop	af		;cancel return address
                      	
  2AF0  3AA7FE        		ld	a,(INPTPAG)
  2AF3  AC            		xor	h		;(CSRAD+1)
  2AF4  E6F0          		and	0f0h
  2AF6  201F          		jr	nz,SETLENMAX	;if other page
                      	
  2AF8  3AA8FD        		ld	a,(CSRY)
  2AFB  ED5BA4FE      		ld	de,(INPTXY)
  2AFF  BB            		cp	e
  2B00  2015          		jr	nz,SETLENMAX
                      	
  2B02  01B6FD        		ld	bc,LINEST-1
  2B05  79            		ld	a,c
  2B06  83            		add	a,e		;no carry
  2B07  4F            		ld	c,a
  2B08  0A            		ld	a,(bc)
  2B09  B7            		or	a
  2B0A  280B          		jr	z,SETLENMAX	;if connected to next line
  2B0C  0B            		dec	bc
  2B0D  0A            		ld	a,(bc)
  2B0E  B7            		or	a
  2B0F  2806          		jr	z,SETLENMAX	;if connected to previous line
                      	
  2B11  3AA6FE        		ld	a,(INPTX)	;end position
  2B14  92            		sub	d		;(INPTXY+1)
  2B15  1802          		jr	SETLEN
                      	
  2B17                	SETLENMAX:
  2B17  3E47          		ld	a,71
  2B19                	SETLEN:
  2B19  32A6FE        		ld	(INPTX),a	;length
                      	
  2B1C                	SRETLP:
  2B1C  CD3314        		call	CHKLINE
  2B1F  2B            		dec	hl
  2B20  28FA          		jr	z,SRETLP
                      	
  2B22  23            		inc	hl
  2B23  54            		ld	d,h		;
  2B24  CD5011        		call	AD2XY
  2B27  3AA7FE        		ld	a,(INPTPAG)
  2B2A  AA            		xor	d		;
  2B2B  E6F0          		and	0f0h
  2B2D  2009          		jr	nz,SRETNZ	;if different page
                      	
  2B2F  ED5BA4FE      		ld	de,(INPTXY)	;initial position
  2B33  7D            		ld	a,l
  2B34  BB            		cp	e
  2B35  2001          		jr	nz,SRETNZ	;if different line
  2B37  EB            		ex	de,hl		;if same line
  2B38                	SRETNZ:
  2B38  B7            		or	a		;reset c-flag
  2B39  C3CD11        		jp	XY2AD
                      	
                      	
  2B3C                	SEDBELL:
  2B3C  3AA8FE        		ld	a,(INSMODE)
  2B3F  B7            		or	a
  2B40  CACD1B        		jp	z,BELL
  2B43  3E20          		ld	a,' '
  2B45  C36F29        		jp	SEDMAIN
                      	
                      	
                      	;x=x+-1
                      	;input: b(bit7=0:increment, bit7=1:decrement), (GRPX3)
                      	;output: hl,(GRPX3)=X, z-flag(1=overflow)
                      	;destroy: af,de
  2B48                	INCGX:
  2B48  2AB1FE        		ld	hl,(GRPX3)
  2B4B  CB78          		bit	7,b
  2B4D  2005          		jr	nz,INCGXNZ
  2B4F  23            		inc	hl
  2B50  7C            		ld	a,h
  2B51  B5            		or	l
  2B52  1803          		jr	INCGXEND
  2B54                	INCGXNZ:
  2B54  7C            		ld	a,h
  2B55  B5            		or	l
  2B56  2B            		dec	hl
  2B57                	INCGXEND:
  2B57  22B1FE        		ld	(GRPX3),hl
  2B5A  C9            		ret
                      	
                      	
                      	;y=y+1
                      	;input: (GRPY3)
                      	;output: de=(GRPY3)
                      	;destroy: af
  2B5B                	INCGY:
  2B5B  ED5BB3FE      		ld	de,(GRPY3)
  2B5F  13            		inc	de
  2B60  ED53B3FE      		ld	(GRPY3),de
  2B64  C9            		ret
                      	
                      	
                      	;error-=|dx|*2
                      	;input: bc=dx, hl=error
                      	;output: hl=error
                      	;destroy: af
  2B65                	SUB2DX:
  2B65  78            		ld	a,b
  2B66  07            		rlca
  2B67  3805          		jr	c,SUB2DXNZ
                      	;dx>0
                      	;	or	a
  2B69  ED42          		sbc	hl,bc
  2B6B  ED42          		sbc	hl,bc
  2B6D  C9            		ret
                      	
                      	;dx<0
  2B6E                	SUB2DXNZ:
  2B6E  09            		add	hl,bc
  2B6F  09            		add	hl,bc
  2B70  C9            		ret
                      	
                      	
                      	;x1 <-> x2, y1 <-> y2
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2
                      	;output: (GRPX2)=larger x,(GRPY2)=larger y,(GRPX3)=smaller x,(GRPY3)=smaller y
                      	;destroy: bc,de,hl
  2B71                	SORTXY:
  2B71  F5            		push	af
  2B72  B7            		or	a
  2B73  CDC32B        		call	CHKGXY23
  2B76  3807          		jr	c,SORTXOK
  2B78  22AFFE        		ld	(GRPY2),hl
  2B7B  ED53B3FE      		ld	(GRPY3),de
  2B7F                	SORTXOK:
  2B7F  2AADFE        		ld	hl,(GRPX2)
  2B82  ED5BB1FE      		ld	de,(GRPX3)
  2B86  E7            		rst	CPHLDE
  2B87  3817          		jr	c,SORTX
  2B89  F1            		pop	af
  2B8A  C9            		ret
                      	
                      	
                      	;(x1,y1) <-> (x2,y2)
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2
                      	;output: (GRPX2),(GRPY2)=larger y with x, (GRPX3),(GRPY3)=small y with x
                      	;destroy: bc,de,hl
  2B8B                	SORTY:
  2B8B  F5            		push	af
  2B8C  37            		scf
  2B8D  CDC32B        		call	CHKGXY23
  2B90  3815          		jr	c,NOSORT
  2B92  22AFFE        		ld	(GRPY2),hl
  2B95  ED53B3FE      		ld	(GRPY3),de
  2B99  2AADFE        		ld	hl,(GRPX2)
  2B9C  ED5BB1FE      		ld	de,(GRPX3)
  2BA0                	SORTX:
  2BA0  ED53ADFE      		ld	(GRPX2),de
  2BA4  22B1FE        		ld	(GRPX3),hl
  2BA7                	NOSORT:
  2BA7  F1            		pop	af
  2BA8  C9            		ret
                      	
                      	
                      	;sort XY and put bc,de,hl
                      	;output: bc=smaller x, de=smaller y, hl=larger y
                      	;destroy: none
  2BA9                	SORTXY2:
  2BA9  CD712B        		call	SORTXY
  2BAC  ED4BB1FE      		ld	bc,(GRPX3)	;smaller x, b=0
  2BB0  ED5BB3FE      		ld	de,(GRPY3)	;smaller y
  2BB4  2AAFFE        		ld	hl,(GRPY2)	;larger y
  2BB7  C9            		ret
                      	
                      	
                      	;push (GRPX2),(GRPY2)
                      	;destroy: af,hl
  2BB8                	PUSHGXY:
  2BB8  F1            		pop	af		;return address
  2BB9  2AADFE        		ld	hl,(GRPX2)
  2BBC  E5            		push	hl
  2BBD  2AAFFE        		ld	hl,(GRPY2)
  2BC0  E5            		push	hl
  2BC1  F5            		push	af		;return address
  2BC2  C9            		ret
                      	
                      	
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2,
                      	;       c-flag(1=convert to screen mode cordinate)
                      	;output: bc=(GRPX2)=x2, de=(GRPY2)=y2, hl=(GRPY3)=y1, (GRPX3)=x1, z,c(y1>y2?)
                      	;destroy: af
  2BC3                	CHKGXY23:
  2BC3  F5            		push	af
  2BC4  DC7815        		call	c,GXY2SXY
  2BC7  F1            		pop	af
  2BC8  F5            		push	af
  2BC9  D4F22B        		call	nc,CHKGXY
  2BCC  F1            		pop	af
  2BCD  ED43B1FE      		ld	(GRPX3),bc
  2BD1  ED53B3FE      		ld	(GRPY3),de
  2BD5  ED4BADFE      		ld	bc,(GRPX2)
  2BD9  ED5BAFFE      		ld	de,(GRPY2)
  2BDD  F5            		push	af
  2BDE  DC7815        		call	c,GXY2SXY
  2BE1  F1            		pop	af
  2BE2  D4F22B        		call	nc,CHKGXY
  2BE5  ED43ADFE      		ld	(GRPX2),bc
  2BE9  ED53AFFE      		ld	(GRPY2),de
                      	
  2BED  2AB3FE        		ld	hl,(GRPY3)
  2BF0  E7            		rst	CPHLDE
  2BF1  C9            		ret
                      	
                      	
                      	;check and round graphic coordinates (x,y)
                      	;input: bc=x, de=y
                      	;output: bc=x, de=y
                      	;destroy: af,hl
  2BF2                	CHKGXY:
  2BF2  78            		ld	a,b
  2BF3  B7            		or	a
  2BF4  2802          		jr	z,CHKMNS
  2BF6  0EFF          		ld	c,0ffh
  2BF8                	CHKMNS:
  2BF8  B2            		or	d
  2BF9  FAE503        		jp	m,FCERR
                      	
  2BFC  3A92FD        		ld	a,(SCREEN1)
  2BFF  47            		ld	b,a		;
  2C00  0F            		rrca
  2C01  2F            		cpl
  2C02  21A6FD        		ld	hl,CONSOL3
  2C05  A6            		and	(hl)
  2C06  0F            		rrca
  2C07  21BF00        		ld	hl,191
  2C0A  3003          		jr	nc,NOFKEY
  2C0C  21B300        		ld	hl,191-12
  2C0F                	NOFKEY:
  2C0F  E7            		rst	CPHLDE
  2C10  3001          		jr	nc,CHKYOK
  2C12  EB            		ex	de,hl
  2C13                	CHKYOK:
  2C13  78            		ld	a,b		;
  2C14  3D            		dec	a
  2C15  280D          		jr	z,ROUNDY2
  2C17  F2282C        		jp	p,ROUNDX	;screen mode 3,4
                      	
                      	;round off y for screen mode 1
  2C1A                	ROUNDY1:
  2C1A  CD9A15        		call	DIV12
  2C1D  7B            		ld	a,e
  2C1E  87            		add	a,a		;*2
  2C1F  83            		add	a,e		;*3
  2C20  87            		add	a,a		;*6
  2C21  87            		add	a,a		;*12
  2C22  1803          		jr	ROUNDY2END
                      	
                      	;round off y for screen mode 2
  2C24                	ROUNDY2:
  2C24  7B            		ld	a,e
  2C25  E6FC          		and	0fch
  2C27                	ROUNDY2END:
  2C27  5F            		ld	e,a
                      	
  2C28                	ROUNDX:
  2C28  04            		inc	b		;
  2C29  3EF0          		ld	a,0f0h
  2C2B                	ROUNDXLP:
  2C2B  37            		scf
  2C2C  1F            		rra			;f8,fc,fe,ff
  2C2D  10FC          		djnz	ROUNDXLP
                      	
  2C2F  A1            		and	c
  2C30  4F            		ld	c,a		;b=0
  2C31  C9            		ret
                      	
                      	
  2C32                	PSCOLR:
  2C32  C5            		push	bc		;x
  2C33  D5            		push	de		;y
  2C34  47            		ld	b,a		;color
  2C35  7E            		ld	a,(hl)
  2C36  FE2C          		cp	','
  2C38  78            		ld	a,b		;color
  2C39  CCE30D        		call	z,INT1INC
  2C3C  D1            		pop	de		;y
  2C3D  C1            		pop	bc		;x
  2C3E  C3C015        		jp	SETATT
                      	
                      	
                      	;screen mode 2
  2C41                	PSET2:
  2C41  25            		dec	h
  2C42  25            		dec	h
  2C43  3AACFE        		ld	a,(ATTDAT)
  2C46  5E            		ld	e,(hl)		;
  2C47  B7            		or	a
  2C48  2004          		jr	nz,PS2NZ1
  2C4A  CB73          		bit	6,e		;
  2C4C  2004          		jr	nz,PS2NZ2
  2C4E                	PS2NZ1:
  2C4E  CD4A0E        		call	GETSPA2NZ
  2C51  77            		ld	(hl),a
  2C52                	PS2NZ2:
  2C52  24            		inc	h
  2C53  24            		inc	h
  2C54  CB73          		bit	6,e		;
  2C56  2004          		jr	nz,PS2SEMI	;semi-graphic mode?
  2C58  CD1F16        		call	GETSP
  2C5B  77            		ld	(hl),a
                      	
  2C5C                	PS2SEMI:
  2C5C  7E            		ld	a,(hl)
  2C5D  E63F          		and	3fh
  2C5F  B2            		or	d
  2C60  4F            		ld	c,a		;;
                      	
  2C61  3AACFE        		ld	a,(ATTDAT)
  2C64  B7            		or	a
  2C65  2809          		jr	z,PSET2C0
  2C67  3D            		dec	a
  2C68  E603          		and	03h
  2C6A  0F            		rrca
  2C6B  0F            		rrca
  2C6C  81            		add	a,c		;;
  2C6D  77            		ld	(hl),a
  2C6E  E1            		pop	hl
  2C6F  C9            		ret
                      	
  2C70                	PSET2C0:
  2C70  7A            		ld	a,d
  2C71  2F            		cpl
  2C72  A6            		and	(hl)
  2C73  77            		ld	(hl),a
  2C74  E1            		pop	hl
  2C75  C9            		ret
                      	
                      	
                      	;continued from BFG
  2C76                	BFG2:
  2C76  3AB1FE        		ld	a,(GRPX3)	;smaller x
  2C79  E6F8          		and	0f8h
  2C7B  47            		ld	b,a
  2C7C  3AADFE        		ld	a,(GRPX2)	;larger x
  2C7F  E6F8          		and	0f8h
  2C81  90            		sub	b		;
  2C82  0F            		rrca
  2C83  0F            		rrca
  2C84  0F            		rrca			;int(larger/8)-int(smaller/8)
  2C85  47            		ld	b,a		;bytes
  2C86  2003          		jr	nz,BFGLP3	;a=0?
  2C88  7A            		ld	a,d
  2C89  A3            		and	e
  2C8A  57            		ld	d,a
                      	
  2C8B                	BFGLP3:
                      	;left part
  2C8B  C5            		push	bc
  2C8C  3AACFE        		ld	a,(ATTDAT)
  2C8F  AE            		xor	(hl)
  2C90  A2            		and	d		;d=left part mask
  2C91  AE            		xor	(hl)
  2C92  77            		ld	(hl),a
                      	
  2C93  05            		dec	b		;
  2C94  FAA72C        		jp	m,BFGNEXT
                      	
                      	;middle part
  2C97  E5            		push	hl		;VRAM address
  2C98  3AACFE        		ld	a,(ATTDAT)
  2C9B  2804          		jr	z,BFGRGT	;
  2C9D                	BFGLP4:
  2C9D  23            		inc	hl
  2C9E  77            		ld	(hl),a
  2C9F  10FC          		djnz	BFGLP4
                      	
                      	;right part
  2CA1                	BFGRGT:
  2CA1  23            		inc	hl
  2CA2  AE            		xor	(hl)
  2CA3  A3            		and	e		;e=right part mask
  2CA4  AE            		xor	(hl)
  2CA5  77            		ld	(hl),a
  2CA6  E1            		pop	hl		;VRAM address
                      	
  2CA7                	BFGNEXT:
  2CA7  012000        		ld	bc,0020h
  2CAA  09            		add	hl,bc
  2CAB  C1            		pop	bc
  2CAC  0D            		dec	c
  2CAD  20DC          		jr	nz,BFGLP3
  2CAF  C3BA2E        		jp	LINEEND2
                      	
                      	
                      	;if |dy/dx|<=1
  2CB2                	SLOPEX:
  2CB2  23            		inc	hl
                      	;	or	a
  2CB3  ED52          		sbc	hl,de		;error=-|dx|
  2CB5  D9            		exx			;bc'=dx, de'=dy, hl'=error
  2CB6                	LINELP2:
  2CB6  ED4BB1FE      		ld	bc,(GRPX3)
  2CBA  ED5BB3FE      		ld	de,(GRPY3)
  2CBE  CD4A2D        		call	PSETSXY
                      	
  2CC1  D9            		exx
  2CC2  19            		add	hl,de		;error+=dy
  2CC3  19            		add	hl,de		;error+=dy
  2CC4  CB7C          		bit	7,h
  2CC6  2008          		jr	nz,ERRMNS
                      	
                      	;if error>=0
  2CC8  CD652B        		call	SUB2DX		;error-=|dx|*2
  2CCB  D9            		exx
  2CCC  CD5B2B        		call	INCGY		;increment Y
  2CCF  D9            		exx
                      	
  2CD0                	ERRMNS:
  2CD0  78            		ld	a,b
  2CD1  D9            		exx
  2CD2  47            		ld	b,a
  2CD3  CD482B        		call	INCGX		;increment or decrement X
  2CD6  CAB82E        		jp	z,LINEEND
                      	
  2CD9  EB            		ex	de,hl		;de=X
  2CDA  2AADFE        		ld	hl,(GRPX2)
  2CDD  D9            		exx
  2CDE  CB78          		bit	7,b
  2CE0  D9            		exx
  2CE1  2801          		jr	z,LINEZ
  2CE3  EB            		ex	de,hl		;if dx<0
  2CE4                	LINEZ:
  2CE4  E7            		rst	CPHLDE
  2CE5  30CF          		jr	nc,LINELP2
  2CE7  C3B82E        		jp	LINEEND
                      	
                      	
                      	;get [step](x,y) cordinate
                      	;input: hl=program address
                      	;output: bc=graphic X, de=graphic Y,
                      	;	 (GRPX1)=(GRPX2),(GRPY1)=(GRPY2)=0-32767
                      	;	 a=next data, hl=next data address, z(, or not)
                      	;destroy: f
  2CEA                	GETGXY:
  2CEA  CD573F        		call	SKIPSP
  2CED  FEC9          		cp	STEP_
  2CEF  F5            		push	af		;STEP?
  2CF0  2001          		jr	nz,GETGXYNZ
  2CF2  23            		inc	hl
  2CF3                	GETGXYNZ:
  2CF3  CDB50B        		call	CHKLPAR
  2CF6  CD1D0E        		call	INTARG2		;bc,de
  2CF9  CDC40B        		call	CHKRPAR
  2CFC  F1            		pop	af		;STEP?
  2CFD  CD132D        		call	SETGXY
  2D00  CD573F        		call	SKIPSP
  2D03  FE2C          		cp	','
  2D05  C9            		ret
                      	
                      	
                      	;input: bc=x, de=y, z(0=absolute, 1=relative)
                      	;output: bc=x, de=y, (GRPX1)=(GRPX2)=x, (GRPY1)=(GRPY2)=y
                      	;destroy: f
  2D06                	_SETGXY:ds	SETGXY-_SETGXY
  2D13                		org	SETGXY
                      	
  2D13  E5            		push	hl
  2D14  200B          		jr	nz,SETGXYNZ
  2D16  2AAEFD        		ld	hl,(GRPX1)
  2D19  09            		add	hl,bc
  2D1A  44            		ld	b,h
  2D1B  4D            		ld	c,l
  2D1C  2AB0FD        		ld	hl,(GRPY1)
  2D1F  19            		add	hl,de
  2D20  EB            		ex	de,hl
  2D21                	SETGXYNZ:
  2D21  ED43AEFD      		ld	(GRPX1),bc
  2D25  ED43ADFE      		ld	(GRPX2),bc
  2D29  ED53B0FD      		ld	(GRPY1),de
  2D2D  ED53AFFE      		ld	(GRPY2),de
  2D31  E1            		pop	hl
  2D32  C9            		ret
                      	
                      	
                      	;PRESET command
  2D33                	_C_PRST:ds	C_PRST-_C_PRST
  2D37                		org	C_PRST
                      	
  2D37  3A94FD        		ld	a,(COLOR2)
  2D3A  1803          		jr	PSETRST
                      	
                      	;PSET command
  2D3C                	_C_PSET:ds	C_PSET-_C_PSET
  2D3C                		org	C_PSET
                      	
  2D3C  3A93FD        		ld	a,(COLOR1)
                      	
                      	;PSET and PRESET
  2D3F                	PSETRST:
  2D3F  F5            		push	af
  2D40  CDEA2C        		call	GETGXY
  2D43  F1            		pop	af
  2D44  CD322C        		call	PSCOLR
                      	;	jp	PSET
                      	
                      	
                      	;input: bc=x1, de=y1, (ATTDAT)=attribute
                      	;destroy: af,bc,de
  2D47                	_PSET:	ds	PSET-_PSET
  2D47                		org	PSET
                      	
  2D47  CD7815        		call	GXY2SXY
                      	
  2D4A                	PSETSXY:
  2D4A  E5            		push	hl
  2D4B  CDBA15        		call	SXY2AD
  2D4E  57            		ld	d,a
  2D4F  3A92FD        		ld	a,(SCREEN1)
  2D52  3D            		dec	a
  2D53  CA412C        		jp	z,PSET2
  2D56  3AACFE        		ld	a,(ATTDAT)
  2D59  FA5F2D        		jp	m,PSET1
                      	
                      	;screen mode 3,4
  2D5C                	PSET34:
  2D5C  AE            		xor	(hl)
  2D5D  A2            		and	d
  2D5E  AE            		xor	(hl)
  2D5F                	PSET1:
  2D5F  77            		ld	(hl),a
  2D60  E1            		pop	hl
  2D61  C9            		ret
                      	
                      	
                      	;POINT() function
  2D62                	F_POIN:
  2D62  CDEA2C        		call	GETGXY
  2D65  CD733E        		call	POINT
  2D68  C37D0C        		jp	I1TOFA
                      	
                      	
                      	;skip @
  2D6B                	SKIPAT:
  2D6B  CD573F        		call	SKIPSP
  2D6E  FE40          		cp	'@'
  2D70  C0            		ret	nz
  2D71  C3563F        		jp	SKIPSPINC
                      	
                      	
                      	;LINE command
  2D74                	C_LINE:
  2D74  CD6B2D        		call	SKIPAT
  2D77  FECB          		cp	MINUS_
  2D79  ED4BAEFD      		ld	bc,(GRPX1)
  2D7D  ED5BB0FD      		ld	de,(GRPY1)
  2D81  2808          		jr	z,LINE2P
                      	
  2D83                	LINE1P:
  2D83  CDEA2C        		call	GETGXY
  2D86  FECB          		cp	MINUS_
  2D88  C2DC03        		jp	nz,SNERR
                      	
  2D8B                	LINE2P:
  2D8B  C5            		push	bc		;x1
  2D8C  D5            		push	de		;y1
                      	
  2D8D  23            		inc	hl
  2D8E  CDEA2C        		call	GETGXY
  2D91  ED43ADFE      		ld	(GRPX2),bc	;x2
  2D95  ED53AFFE      		ld	(GRPY2),de	;y2
  2D99  3A93FD        		ld	a,(COLOR1)
  2D9C  2011          		jr	nz,NOTBOX
  2D9E  5F            		ld	e,a
  2D9F  CD563F        		call	SKIPSPINC
  2DA2  FE2C          		cp	','
  2DA4  2810          		jr	z,CHKBF
                      	
                      	;color
  2DA6  CDE40D        		call	INT1ARG
  2DA9  7E            		ld	a,(hl)
  2DAA  FE2C          		cp	','
  2DAC  2808          		jr	z,CHKBF
  2DAE  7B            		ld	a,e
                      	
  2DAF                	NOTBOX:
  2DAF  CDC015        		call	SETATT
  2DB2  D1            		pop	de		;y1
  2DB3  C1            		pop	bc		;x1
  2DB4  1869          		jr	LINE
                      	
                      	;check 'B' and 'F'
  2DB6                	CHKBF:
  2DB6  CD563F        		call	SKIPSPINC
  2DB9  FE42          		cp	'B'
  2DBB  C2DC03        		jp	nz,SNERR
                      	
  2DBE  7B            		ld	a,e
  2DBF  CDC015        		call	SETATT
                      	
  2DC2  CD563F        		call	SKIPSPINC
  2DC5  FE46          		cp	'F'
  2DC7  2001          		jr	nz,BOX
  2DC9  23            		inc	hl		;for box fill
  2DCA                	BOX:
  2DCA  224EFF        		ld	(PROGAD),hl
  2DCD  D1            		pop	de		;y1
  2DCE  C1            		pop	bc		;x1
  2DCF  2064          		jr	nz,LINEB
  2DD1  1811          		jr	LINEBF
                      	
                      	
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2, (ATTDAT)=attribute
                      	;destroy: af,bc,de
  2DD3                	_LINEBF:ds	LINEBF-_LINEBF
  2DE4                		org	LINEBF
                      	
  2DE4  E5            		push	hl
  2DE5  CDB82B        		call	PUSHGXY
  2DE8  CDA92B        		call	SORTXY2
                      	
  2DEB  3A92FD        		ld	a,(SCREEN1)
  2DEE  FE02          		cp	02h
  2DF0  3868          		jr	c,BF12
                      	
                      	;line bf (graphic mode)
  2DF2                	BFG:
  2DF2  3AADFE        		ld	a,(GRPX2)	;larger x
  2DF5  2001          		jr	nz,BF4
  2DF7  3C            		inc	a		;screen mode 3
  2DF8                	BF4:
  2DF8  E607          		and	07h
  2DFA  3C            		inc	a
  2DFB  47            		ld	b,a
  2DFC  AF            		xor	a
  2DFD                	BFGLP1:
  2DFD  37            		scf
  2DFE  1F            		rra			;right part mask
  2DFF  10FC          		djnz	BFGLP1
                      	
                      	;	or	a
  2E01  ED52          		sbc	hl,de
  2E03  2C            		inc	l
  2E04  E5            		push	hl		;l=lines
                      	
  2E05  6F            		ld	l,a		;right part mask
                      	
  2E06  79            		ld	a,c		;smaller x
  2E07  E607          		and	07h
  2E09  47            		ld	b,a
  2E0A  3EFF          		ld	a,0ffh
  2E0C  2804          		jr	z,BFGZ
  2E0E                	BFGLP2:
  2E0E  CB3F          		srl	a
  2E10  10FC          		djnz	BFGLP2
  2E12                	BFGZ:
  2E12  67            		ld	h,a		;left part mask
                      	
  2E13  E5            		push	hl
  2E14  CDAC15        		call	GXY2AD		;b=0
  2E17  D1            		pop	de		;d=left part mask, e=right part mask
  2E18  C1            		pop	bc		;c=lines
                      	
  2E19  C3762C        		jp	BFG2
                      	
                      	
                      	;by Bresenham's line algorithm
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2, (ATTDAT)=attribute
                      	;destroy: af
  2E1C                	_LINE:	ds	LINE-_LINE
  2E1F                		org	LINE
                      	
  2E1F  E5            		push	hl
  2E20  CDB82B        		call	PUSHGXY
  2E23  D5            		push	de
  2E24  C5            		push	bc
                      	
  2E25  CD8B2B        		call	SORTY
  2E28  ED4BB3FE      		ld	bc,(GRPY3)	;start (smaller y)
  2E2C  2AAFFE        		ld	hl,(GRPY2)	;end (larger y)
  2E2F  B7            		or	a
  2E30  ED42          		sbc	hl,bc		;dy
  2E32  1841          		jr	LINE2
                      	
                      	
                      	;input: bc=x1, de=y1, (GRPX2)=x2, (GRPY2)=y2, (ATTDAT)=attribute
                      	;destroy: af,bc,de
  2E34                	_LINEB:	ds	LINEB-_LINEB
  2E35                		org	LINEB
                      	
  2E35  E5            		push	hl
  2E36  CDB82B        		call	PUSHGXY
  2E39  CDA92B        		call	SORTXY2
  2E3C  EB            		ex	de,hl
                      	
                      	;down-up-right-left
  2E3D  C5            		push	bc
  2E3E  CD1F2E        		call	LINE
  2E41  22AFFE        		ld	(GRPY2),hl	;smaller y
  2E44  EB            		ex	de,hl
  2E45  CD1F2E        		call	LINE
  2E48  ED4BADFE      		ld	bc,(GRPX2)	;larger x
  2E4C  EB            		ex	de,hl		;larger y
  2E4D  CD1F2E        		call	LINE
  2E50  C1            		pop	bc		;smaller x
  2E51  ED43ADFE      		ld	(GRPX2),bc
  2E55  CD1F2E        		call	LINE
  2E58  1860          		jr	LINEEND2
                      	
                      	
                      	;line bf (screen mode 1,2)
                      	;hl=larger y, a=screen mode-1
  2E5A                	BF12:
  2E5A  ED53AFFE      		ld	(GRPY2),de
  2E5E  CD1F2E        		call	LINE
  2E61  E7            		rst	CPHLDE
  2E62  2856          		jr	z,LINEEND2
                      	
  2E64  E5            		push	hl
  2E65  3A92FD        		ld	a,(SCREEN1)
  2E68  87            		add	a,a
  2E69  87            		add	a,a
  2E6A  210C00        		ld	hl,000ch
  2E6D  2801          		jr	z,BF12Z
  2E6F  6F            		ld	l,a
  2E70                	BF12Z:
  2E70  19            		add	hl,de		;+12 or +4
  2E71  EB            		ex	de,hl
  2E72  E1            		pop	hl
  2E73  18E5          		jr	BF12
                      	
                      	
  2E75                	LINE2:
  2E75  EB            		ex	de,hl
  2E76  ED4BB1FE      		ld	bc,(GRPX3)	;start (x)
  2E7A  2AADFE        		ld	hl,(GRPX2)	;end (x)
  2E7D  B7            		or	a
  2E7E  ED42          		sbc	hl,bc		;dx
  2E80  44            		ld	b,h
  2E81  4D            		ld	c,l
                      	
  2E82  3806          		jr	c,DXMNS		;if dx<0
                      	;if dx>=0, hl=-hl=-|dx|
  2E84  AF            		xor	a
  2E85  95            		sub	l
  2E86  6F            		ld	l,a
  2E87  9C            		sbc	a,h
  2E88  95            		sub	l
  2E89  67            		ld	h,a
  2E8A                	DXMNS:
  2E8A  2B            		dec	hl
  2E8B  19            		add	hl,de
  2E8C  D2B22C        		jp	nc,SLOPEX	;if |dy/dx|<=1
                      	
                      	;if |dy/dx|>1
  2E8F  62            		ld	h,d		;error=dy
  2E90  6B            		ld	l,e
                      	
  2E91  D9            		exx			;bc'=dx, de'=dy, hl'=error
  2E92  ED5BB3FE      		ld	de,(GRPY3)
  2E96                	LINELP1:
  2E96  ED4BB1FE      		ld	bc,(GRPX3)
  2E9A  CD4A2D        		call	PSETSXY
                      	
  2E9D  D9            		exx
  2E9E  CD652B        		call	SUB2DX		;error-=|dx|*2
  2EA1  CB7C          		bit	7,h
  2EA3  2809          		jr	z,ERRPLS
                      	
                      	;if error<0
  2EA5  19            		add	hl,de		;error+=dy
  2EA6  19            		add	hl,de		;error+=dy
  2EA7  78            		ld	a,b
  2EA8  D9            		exx
  2EA9  47            		ld	b,a
  2EAA  CD482B        		call	INCGX		;increment or decrement X
  2EAD  D9            		exx
                      	;	jr	c,LINEEND
                      	
  2EAE                	ERRPLS:
  2EAE  D9            		exx
  2EAF  CD5B2B        		call	INCGY		;increment Y
  2EB2  2AAFFE        		ld	hl,(GRPY2)
  2EB5  E7            		rst	CPHLDE
  2EB6  30DE          		jr	nc,LINELP1
                      	
  2EB8                	LINEEND:
  2EB8  C1            		pop	bc
  2EB9  D1            		pop	de
                      	
  2EBA                	LINEEND2:
  2EBA  E1            		pop	hl
  2EBB  22AFFE        		ld	(GRPY2),hl
  2EBE  E1            		pop	hl
  2EBF  22ADFE        		ld	(GRPX2),hl
  2EC2  E1            		pop	hl
  2EC3  C9            		ret
                      	
                      	
                      	;PAINT command
  2EC4                	C_PAIN:
  2EC4  CD6B2D        		call	SKIPAT
  2EC7  CDEA2C        		call	GETGXY
  2ECA  C5            		push	bc		;X
  2ECB  D5            		push	de		;Y
  2ECC  3A93FD        		ld	a,(COLOR1)
  2ECF  CCE30D        		call	z,INT1INC
  2ED2  CDC015        		call	SETATT
  2ED5  7E            		ld	a,(hl)
  2ED6  FE2C          		cp	','
  2ED8  3AC5FE        		ld	a,(BORDERA)
  2EDB  2006          		jr	nz,PANZ
  2EDD  CDE30D        		call	INT1INC
  2EE0  32C6FE        		ld	(BORDERC),a
  2EE3                	PANZ:
  2EE3  5F            		ld	e,a
  2EE4  C3F12E        		jp	PAPOP
                      	
                      	
                      	;paint used by OKHOTSK
                      	;input: e=color code, (sp)=Y, (sp+2)=X
  2EE7                	_PAPOP:ds	PAPOP-_PAPOP
  2EF1                		org	PAPOP
                      	
  2EF1  7B            		ld	a,e
  2EF2  CDC318        		call	SETBO
  2EF5  D1            		pop	de		;Y
  2EF6  C1            		pop	bc		;X
  2EF7  C3FA2E        		jp	PAINT
                      	
                      	
                      	;input: bc=x, de=y, (ATTDAT)=attribute, (BORDERA)=attribute, (BORDERC)=color
                      	;destroy: af,bc,de
  2EFA                	_PAINT:	ds	PAINT-_PAINT
  2EFA                		org	PAINT
                      	
  2EFA  3A92FD        		ld	a,(SCREEN1)
  2EFD  3D            		dec	a
  2EFE  C8            		ret	z		;screen mode 2
  2EFF  E5            		push	hl
  2F00  F5            		push	af
  2F01  CDAC15        		call	GXY2AD
  2F04  57            		ld	d,a
  2F05  F1            		pop	af
  2F06  FA0E2F        		jp	m,PAINT1	;screen mode 1
  2F09                	PAMAIN:
  2F09  CD122F        		call	PADWN
  2F0C  E1            		pop	hl
  2F0D  C9            		ret
                      	
  2F0E                	PAINT1:
  2F0E  16FF          		ld	d,0ffh
  2F10  18F7          		jr	PAMAIN
                      	
                      	
  2F12                	PADWN:
  2F12  CDC42F        		call	PALINE
  2F15  C8            		ret	z
  2F16  E5            		push	hl		;address
  2F17  D5            		push	de		;bit
  2F18  ED4BB5FE      		ld	bc,(PAWRK)
  2F1C  C5            		push	bc
  2F1D  CD812F        		call	PAUP2
  2F20  E1            		pop	hl
  2F21  22B5FE        		ld	(PAWRK),hl
  2F24  D1            		pop	de		;bit
  2F25  E1            		pop	hl		;address
                      	
  2F26                	PADWN2:
  2F26  3A92FD        		ld	a,(SCREEN1)
  2F29  B7            		or	a
  2F2A  1E19          		ld	e,19h
  2F2C  2002          		jr	nz,PADWNG
  2F2E  1E01          		ld	e,01h
  2F30                	PADWNG:
  2F30  7C            		ld	a,h
  2F31  E61F          		and	1fh
  2F33  BB            		cp	e
  2F34  3804          		jr	c,PADWNOK
  2F36  7D            		ld	a,l
  2F37  FEE0          		cp	0e0h
  2F39  D0            		ret	nc
  2F3A                	PADWNOK:
  2F3A  012000        		ld	bc,COLUMNS
  2F3D  09            		add	hl,bc
                      	
  2F3E  AF            		xor	a
  2F3F  32B7FE        		ld	(PACNT),a
  2F42                	PADWNLP1:
  2F42  CD1E30        		call	SRCHOK
  2F45  3812          		jr	c,CALLDWN
  2F47  E5            		push	hl		;address
  2F48  21B7FE        		ld	hl,PACNT
  2F4B  34            		inc	(hl)
  2F4C  D5            		push	de		;bit
  2F4D  CDCC34        		call	CHKFRE
  2F50  D1            		pop	de
  2F51  E1            		pop	hl
  2F52  E5            		push	hl
  2F53  D5            		push	de
                      	
                      	;	ld	a,l
                      	;	inc	a
                      	;	and	1fh
                      	;	jr	nz,PADWNNZ
                      	;	bit	0,d
                      	;	jr	nz,CALLDWN
                      	;PADWNNZ:
                      	;	call	INCGXPA
                      	
  2F54  CD4B30        		call	SRCHNG
  2F57  30E9          		jr	nc,PADWNLP1
                      	
  2F59                	CALLDWN:
  2F59  3AB7FE        		ld	a,(PACNT)
  2F5C  B7            		or	a
  2F5D  C8            		ret	z
  2F5E                	PADWNLP2:
  2F5E  D1            		pop	de		;bit
  2F5F  E1            		pop	hl		;address
  2F60  3D            		dec	a
  2F61  32B7FE        		ld	(PACNT),a
  2F64  28AC          		jr	z,PADWN
  2F66  F5            		push	af
  2F67  CD122F        		call	PADWN
  2F6A  F1            		pop	af
  2F6B  18F1          		jr	PADWNLP2
                      	
                      	
  2F6D                	PAUP:
  2F6D  CDC42F        		call	PALINE
  2F70  C8            		ret	z
  2F71  E5            		push	hl		;address
  2F72  D5            		push	de		;bit
  2F73  ED4BB5FE      		ld	bc,(PAWRK)
  2F77  C5            		push	bc
  2F78  CD262F        		call	PADWN2
  2F7B  E1            		pop	hl
  2F7C  22B5FE        		ld	(PAWRK),hl
  2F7F  D1            		pop	de		;bit
  2F80  E1            		pop	hl		;address
                      	
  2F81                	PAUP2:
                      	;if (hl - start address) < 0020h
  2F81  3A92FD        		ld	a,(SCREEN1)
  2F84  E602          		and	02h		;0(screen mode 1) or 2(screen mode 3,4)
  2F86  5F            		ld	e,a
  2F87  7C            		ld	a,h
  2F88  E61F          		and	1fh
  2F8A  BB            		cp	e
  2F8B  2004          		jr	nz,PAUPNZ1
  2F8D  7D            		ld	a,l
  2F8E  FE20          		cp	20h
  2F90  D8            		ret	c
  2F91                	PAUPNZ1:
  2F91  01E0FF        		ld	bc,0-COLUMNS
  2F94  09            		add	hl,bc
                      	
  2F95  AF            		xor	a
  2F96  32B7FE        		ld	(PACNT),a
  2F99                	PAUPLP1:
  2F99  CD1E30        		call	SRCHOK
  2F9C  3812          		jr	c,CALLUP
  2F9E  E5            		push	hl		;address
  2F9F  21B7FE        		ld	hl,PACNT
  2FA2  34            		inc	(hl)
  2FA3  D5            		push	de		;bit
  2FA4  CDCC34        		call	CHKFRE
  2FA7  D1            		pop	de
  2FA8  E1            		pop	hl
  2FA9  E5            		push	hl
  2FAA  D5            		push	de
                      	
                      	;	ld	a,l
                      	;	inc	a
                      	;	and	1fh
                      	;	jr	nz,PAUPNZ2
                      	;	bit	0,d
                      	;	jr	nz,CALLUP
                      	;PAUPNZ2:
                      	;	call	INCGXPA
                      	
  2FAB  CD4B30        		call	SRCHNG
  2FAE  30E9          		jr	nc,PAUPLP1
                      	
  2FB0                	CALLUP:
  2FB0  3AB7FE        		ld	a,(PACNT)
  2FB3  B7            		or	a
  2FB4  C8            		ret	z
  2FB5                	PAUPLP2:
  2FB5  D1            		pop	de		;bit
  2FB6  E1            		pop	hl		;address
  2FB7  3D            		dec	a
  2FB8  32B7FE        		ld	(PACNT),a
  2FBB  28B0          		jr	z,PAUP
  2FBD  F5            		push	af
  2FBE  CD6D2F        		call	PAUP
  2FC1  F1            		pop	af
  2FC2  18F1          		jr	PAUPLP2
                      	
                      	
                      	;paint 1 line
                      	;input: hl=address, d=bit
                      	;output: hl, d, z-flag(1=not painted)
                      	;destroy: af,bc
  2FC4                	PALINE:
  2FC4  CD4D27        		call	STOPESC
  2FC7  CD0F30        		call	CHKPA
  2FCA  C8            		ret	z
  2FCB  E5            		push	hl		;address
  2FCC  D5            		push	de		;bit
  2FCD  CDF42F        		call	PAINTR
  2FD0  7D            		ld	a,l
  2FD1  E61F          		and	1fh
  2FD3  6F            		ld	l,a
  2FD4  62            		ld	h,d
  2FD5  22B5FE        		ld	(PAWRK),hl	;X_right
  2FD8  D1            		pop	de		;bit
  2FD9  E1            		pop	hl		;address
                      	;	jr	PAINTL		;z-flag=0
                      	
                      	
                      	;paint to left direction
                      	;input: hl=address, d=bit
                      	;output: hl, d, z-flag=0
                      	;destroy: af,bc
  2FDA                	PAINTL:
  2FDA  7D            		ld	a,l
  2FDB  E61F          		and	1fh
  2FDD  2003          		jr	nz,PALOK
  2FDF  CB7A          		bit	7,d
  2FE1  C0            		ret	nz
                      	
  2FE2                	PALOK:
  2FE2  CD0530        		call	DECGXPA
  2FE5  CD0F30        		call	CHKPA
  2FE8  20F0          		jr	nz,PAINTL
                      	;	jp	INCGXPA
                      	
                      	
                      	;increment x for paint
                      	;input: hl=address, d=bit
                      	;output: hl, d, z-flag=0
                      	;destroy: af
  2FEA                	INCGXPA:
  2FEA  CB0A          		rrc	d
  2FEC  E2F12F        		jp	po,INCGXPA4	;screen mode 4
  2FEF  CB0A          		rrc	d		;screen mode 1 or 3
  2FF1                	INCGXPA4:
  2FF1  D0            		ret	nc
  2FF2  23            		inc	hl
  2FF3  C9            		ret
                      	
                      	
                      	;paint to right direction
                      	;input: hl=address, d=bit
                      	;output: hl,d
                      	;destroy: af,bc
  2FF4                	PAINTR:
  2FF4  7D            		ld	a,l
  2FF5  3C            		inc	a
  2FF6  E61F          		and	1fh
  2FF8  2003          		jr	nz,PAROK
  2FFA  CB42          		bit	0,d
  2FFC  C0            		ret	nz
                      	
  2FFD                	PAROK:
  2FFD  CDEA2F        		call	INCGXPA
  3000  CD0F30        		call	CHKPA
  3003  20EF          		jr	nz,PAINTR
                      	;	jp	DECGXPA
                      	
                      	
                      	;decrement x for paint
                      	;input: hl=address, d=bit
                      	;output: hl, d
                      	;destroy: af
  3005                	DECGXPA:
  3005  CB02          		rlc	d
  3007  E20C30        		jp	po,DECGXPA4	;screen mode 4
  300A  CB02          		rlc	d		;screen mode 1 or 3
  300C                	DECGXPA4:
  300C  D0            		ret	nc
  300D  2B            		dec	hl
  300E  C9            		ret
                      	
                      	
                      	;check and paint
                      	;input: hl=address, d=bit
                      	;output: z(1=not painted)
                      	;destroy: af
  300F                	CHKPA:
  300F  3AC5FE        		ld	a,(BORDERA)
  3012  AE            		xor	(hl)
  3013  A2            		and	d
  3014  C8            		ret	z
                      	
  3015  3AACFE        		ld	a,(ATTDAT)
  3018  AE            		xor	(hl)
  3019  A2            		and	d
  301A  AE            		xor	(hl)
  301B  77            		ld	(hl),a
  301C  B2            		or	d		;d>0, reset z-flag
  301D  C9            		ret
                      	
                      	
                      	;search for paintable area
                      	;input: hl=address, d=bit
                      	;output: hl, d, c-flag(1=over,0=OK)
                      	;destroy: af,e
  301E                	SRCHOK:
  301E  7D            		ld	a,l
  301F  E61F          		and	1fh
  3021  5F            		ld	e,a
  3022  3AB5FE        		ld	a,(PAWRK)	;address low (5 bits)
  3025  BB            		cp	e
  3026  D8            		ret	c
                      	
  3027  2007          		jr	nz,SRCHOKNZ
  3029  3AB6FE        		ld	a,(PAWRK+1)	;bit
  302C  3D            		dec	a
  302D  BA            		cp	d
  302E  3F            		ccf
  302F  D8            		ret	c
                      	
  3030                	SRCHOKNZ:
  3030  5E            		ld	e,(hl)
  3031  3AC5FE        		ld	a,(BORDERA)
  3034  AB            		xor	e
  3035  A2            		and	d
  3036  2806          		jr	z,SRCHOKZ
                      	
  3038  3AACFE        		ld	a,(ATTDAT)
  303B  AB            		xor	e
  303C  A2            		and	d
  303D  C0            		ret	nz		;c-flag=0
                      	
  303E                	SRCHOKZ:
  303E  CDEA2F        		call	INCGXPA
  3041  7D            		ld	a,l
  3042  E61F          		and	1fh
  3044  20D8          		jr	nz,SRCHOK
  3046  7A            		ld	a,d
  3047  07            		rlca
  3048  30D4          		jr	nc,SRCHOK
  304A  C9            		ret			;c-flag=1
                      	
                      	
                      	;search for unpaintable area
                      	;get unpaintable area
                      	;input: hl=address, d=bit
                      	;output: hl, d, c-flag(1=over,0=NG)
                      	;destroy: af,e
  304B                	SRCHNG:
  304B  7D            		ld	a,l
  304C  E61F          		and	1fh
  304E  5F            		ld	e,a
  304F  3AB5FE        		ld	a,(PAWRK)	;address low (5 bits)
  3052  BB            		cp	e
  3053  D8            		ret	c
                      	
  3054  2007          		jr	nz,SRCHNGNZ
  3056  3AB6FE        		ld	a,(PAWRK+1)	;bit
  3059  3D            		dec	a
  305A  BA            		cp	d
  305B  3F            		ccf
  305C  D8            		ret	c
                      	
  305D                	SRCHNGNZ:
  305D  5E            		ld	e,(hl)
  305E  3AC5FE        		ld	a,(BORDERA)
  3061  AB            		xor	e
  3062  A2            		and	d
  3063  C8            		ret	z		;c-flag=0
                      	
  3064  CDEA2F        		call	INCGXPA
  3067  7D            		ld	a,l
  3068  E61F          		and	1fh
  306A  20DF          		jr	nz,SRCHNG
  306C  7A            		ld	a,d
  306D  07            		rlca
  306E  30DB          		jr	nc,SRCHNG
  3070  C9            		ret			;c-flag=1
                      	
                      	
                      	;STR$() function
  3071                	F_STR:
  3071  CD9B0B        		call	CHKNUM
  3074  CDAC3A        		call	FTOA
  3077  E5            		push	hl
  3078  010101        		ld	bc,0101h
  307B  AF            		xor	a
  307C  EDB1          		cpir
  307E  91            		sub	c
  307F  E1            		pop	hl
  3080  CD4227        		call	MAKESTR
  3083  C39027        		jp	INKYEND
                      	
                      	
                      	;put characters (skip first character) (used by LIZARD)
  3086                	_PUTSINC:ds	PUTSINC-_PUTSINC
  30CE                		org	PUTSINC
                      	
  30CE  23            		inc	hl
                      	
                      	;put characters
                      	;input: hl,(DEVICE)=0:CRT, 1:printer, 2:RS-232C, 80h-ffh:CMT
                      	;destroy: af,hl,(bc,de,FAC1)
  30CF                	_PUTS:	ds	PUTS-_PUTS
  30CF                		org	PUTS
                      	
  30CF  7E            		ld	a,(hl)
  30D0  B7            		or	a
  30D1  C8            		ret	z
  30D2  FE22          		cp	22h		;double quotation mark
  30D4  C8            		ret	z
  30D5  CDC726        		call	PUTDEV
  30D8  18F4          		jr	PUTSINC
                      	
                      	
                      	;input: bc=candidate of string descriptor address
                      	;       hl=string descriptor address to be checked
                      	;	(GCWRK)=candidate of string data address to be comacted
                      	;	stack=string descriptor address pointing to same data (endmark=0000)
                      	;output: bc=string descriptor address to be compacted
                      	;	 (GCWRK)=string data address to be comacted
                      	;	 hl=next string descriptor address
                      	;	 stack=string descriptor address pointing to same data (endmark=0000)
                      	;destroy: af,de
  30DA                	GETSTR:
  30DA  E5            		push	hl
  30DB  7E            		ld	a,(hl)
  30DC  23            		inc	hl
  30DD  23            		inc	hl
  30DE  5E            		ld	e,(hl)
  30DF  23            		inc	hl
  30E0  56            		ld	d,(hl)
  30E1  23            		inc	hl
                      	
  30E2  B7            		or	a
  30E3  2852          		jr	z,GETNOSTR2	;length=0
                      	
  30E5  E5            		push	hl
  30E6  2A56FF        		ld	hl,(VARAD)
  30E9  E7            		rst	CPHLDE
  30EA  304A          		jr	nc,GETNOSTR	;in program area
  30EC  2A3DFF        		ld	hl,(STRAD)
  30EF  E7            		rst	CPHLDE
  30F0  3844          		jr	c,GETNOSTR	;in work area or have been compacted
  30F2  2A41FF        		ld	hl,(GCWRK)
  30F5  E7            		rst	CPHLDE
  30F6  E1            		pop	hl
  30F7  2811          		jr	z,GETSTRZ
  30F9  303C          		jr	nc,GETNOSTR2	;de < candidate
                      	
                      	;new candidate found
  30FB  ED5341FF      		ld	(GCWRK),de
  30FF  C1            		pop	bc
  3100  D1            		pop	de		;return address
                      	
  3101                	GETSTRLP:
  3101  F1            		pop	af		;pushed address? (a=higher byte)
  3102  F5            		push	af
  3103  D5            		push	de		;return address
  3104  B7            		or	a
  3105  C8            		ret	z		;no data
  3106  D1            		pop	de		;return address
  3107  F1            		pop	af		;cancel
  3108  18F7          		jr	GETSTRLP
                      	
  310A                	GETSTRZ:
  310A  F1            		pop	af
  310B  D1            		pop	de		;return address
  310C  F5            		push	af
  310D  D5            		push	de		;return address
  310E  C9            		ret
                      	
                      	
                      	;garbage collection
                      	;destroy: af,bc,de,hl
  310F                	_GC:	ds	GC-_GC
  310F                		org	GC
                      	
  310F  2A27FF        		ld	hl,(STREND)
  3112  223DFF        		ld	(STRAD),hl
                      	
                      	;	ld	hl,0000h
  3115  2600          		ld	h,00h		;higher byte
  3117                	GCLP1:
  3117  E5            		push	hl
  3118  2241FF        		ld	(GCWRK),hl
  311B  2A56FF        		ld	hl,(VARAD)
                      	
                      	;normal variable
  311E                	GCVAR:
  311E  ED5B58FF      		ld	de,(ARRAD)
  3122  E7            		rst	CPHLDE
  3123  3014          		jr	nc,GCARR
  3125  23            		inc	hl
  3126  7E            		ld	a,(hl)
  3127  07            		rlca
  3128  3806          		jr	c,GCVARS
  312A  110600        		ld	de,0006h
  312D  19            		add	hl,de
  312E  18EE          		jr	GCVAR
  3130                	GCVARS:
  3130  23            		inc	hl
  3131  CDDA30        		call	GETSTR
  3134  18E8          		jr	GCVAR
                      	
                      	
  3136                	GETNOSTR:
  3136  E1            		pop	hl
  3137                	GETNOSTR2:
  3137  F1            		pop	af	;cancel
  3138  C9            		ret
                      	
                      	
                      	;array variable
  3139                	GCARR:
  3139  ED5B5AFF      		ld	de,(FREEAD)
  313D  E7            		rst	CPHLDE
  313E  3029          		jr	nc,GCSDSC
  3140  23            		inc	hl
  3141  7E            		ld	a,(hl)
  3142  23            		inc	hl
  3143  5E            		ld	e,(hl)
  3144  23            		inc	hl
  3145  56            		ld	d,(hl)
  3146  23            		inc	hl
  3147  07            		rlca
  3148  3803          		jr	c,GCARRS
  314A  19            		add	hl,de
  314B  18EC          		jr	GCARR
                      	
  314D                	GCARRS:
  314D  EB            		ex	de,hl
  314E  19            		add	hl,de
  314F  EB            		ex	de,hl
  3150  D5            		push	de
  3151  5E            		ld	e,(hl)		;dimensions
  3152  1600          		ld	d,00h
  3154  23            		inc	hl
  3155  19            		add	hl,de
  3156  19            		add	hl,de
  3157                	GCARRLP:
  3157  D1            		pop	de
  3158  E7            		rst	CPHLDE
  3159  30DE          		jr	nc,GCARR
  315B  ED5350FF      		ld	(TMP),de
  315F  CDDA30        		call	GETSTR
  3162  ED5B50FF      		ld	de,(TMP)
  3166  D5            		push	de
  3167  18EE          		jr	GCARRLP
                      	
                      	;temporary string descriptor
  3169                	GCSDSC:
  3169  212DFF        		ld	hl,STRDSC1
  316C  CDDA30        		call	GETSTR
                      	;	ld	hl,STRDSC2
  316F  CDDA30        		call	GETSTR
                      	;	ld	hl,STRDSC3
  3172  CDDA30        		call	GETSTR
                      	;	ld	hl,STRDSC4
  3175  CDDA30        		call	GETSTR
                      	
  3178  2A41FF        		ld	hl,(GCWRK)
  317B  7C            		ld	a,h
                      	;	or	l
  317C  B7            		or	a		;higher byte
  317D  D1            		pop	de		;cancel
  317E  C8            		ret	z
  317F  D5            		push	de
                      	
                      	;compaction
                      	;input:	bc=string descriptor address
                      	;	hl=string data address to be comacted
                      	
  3180  0A            		ld	a,(bc)
  3181  C5            		push	bc		;
  3182  0600          		ld	b,00h
  3184  4F            		ld	c,a
  3185  09            		add	hl,bc
  3186  2B            		dec	hl
  3187  ED5B3DFF      		ld	de,(STRAD)
  318B  EDB8          		lddr
  318D  ED533DFF      		ld	(STRAD),de
  3191  13            		inc	de
                      	
  3192  E1            		pop	hl		;
  3193                	GCLP2:
  3193  23            		inc	hl
  3194  23            		inc	hl
  3195  73            		ld	(hl),e
  3196  23            		inc	hl
  3197  72            		ld	(hl),d
  3198  E1            		pop	hl
  3199  7C            		ld	a,h
                      	;	or	l
  319A  B7            		or	a		;higher byte
  319B  CA1731        		jp	z,GCLP1
  319E  18F3          		jr	GCLP2
                      	
                      	
                      	;LEN() function
  31A0                	F_LEN:
  31A0  CDA70B        		call	CHKSTR
  31A3                	SETI1A:
  31A3  6F            		ld	l,a
  31A4                	SETI1:
  31A4  CD7E0C        		call	I1TOF
  31A7                	SETTYP0:
  31A7  AF            		xor	a
  31A8  3225FF        		ld	(ARGTYP),a	;0=numeric
  31AB  C9            		ret
                      	
                      	
                      	;ASC() function
  31AC                	F_ASC:
  31AC  CD8A26        		call	STRARG2
  31AF  B7            		or	a
  31B0  CAE503        		jp	z,FCERR
  31B3  1A            		ld	a,(de)
  31B4  18ED          		jr	SETI1A
                      	
                      	
                      	;CHR$() function
  31B6                	F_CHR:
  31B6  CD9B0B        		call	CHKNUM
  31B9  CD4C07        		call	FTOI1
  31BC  43            		ld	b,e
  31BD  C37B27        		jp	INKYNZ
                      	
                      	
                      	;LEFT$() function
  31C0                	F_LEFT:
  31C0  CD9626        		call	ARGSI1
  31C3  0E00          		ld	c,00h
  31C5  1824          		jr	MID
                      	
                      	
                      	;RIGHT$() function
  31C7                	F_RGT:
  31C7  CD9626        		call	ARGSI1
  31CA  57            		ld	d,a		;
  31CB  93            		sub	e
  31CC  3001          		jr	nc,RGTNC
  31CE  AF            		xor	a
  31CF                	RGTNC:
  31CF  4F            		ld	c,a
  31D0  5A            		ld	e,d		;
  31D1  7A            		ld	a,d
  31D2  1817          		jr	MID
                      	
                      	
                      	;MID$() function
  31D4                	F_MID:
  31D4  CD9626        		call	ARGSI1
  31D7  57            		ld	d,a		;length
  31D8  1D            		dec	e
  31D9  D5            		push	de		;d=length, e=2nd parameter-1
  31DA  1C            		inc	e
  31DB  CAE503        		jp	z,FCERR		;if 2nd parameter=0
                      	
  31DE  2A4EFF        		ld	hl,(PROGAD)
  31E1  1EFF          		ld	e,0ffh
  31E3  7E            		ld	a,(hl)
  31E4  FE2C          		cp	','
  31E6  CCB226        		call	z,ARGI1
  31E9  C1            		pop	bc		;b=length, c=2nd parameter-1
  31EA  78            		ld	a,b
                      	
                      	;input: STRDSC1=string, a=string length, c=2nd parameter-1, e=3rd parameter
  31EB                	MID:
  31EB  91            		sub	c
  31EC  3001          		jr	nc,MIDNC
  31EE  AF            		xor	a
  31EF                	MIDNC:
  31EF  BB            		cp	e
  31F0  3801          		jr	c,MIDC
  31F2  7B            		ld	a,e
  31F3                	MIDC:
  31F3  47            		ld	b,a		;output length
  31F4  CD5D26        		call	GCCHECK
  31F7  78            		ld	a,b		;output length
  31F8  2A2FFF        		ld	hl,(STRDSC1+2)
  31FB  0600          		ld	b,00h
  31FD  09            		add	hl,bc
  31FE  CD4227        		call	MAKESTR
  3201  2A4EFF        		ld	hl,(PROGAD)
  3204  CDC40B        		call	CHKRPAR
  3207  C39027        		jp	INKYEND
                      	
                      	
                      	;VAL() function
  320A                	F_VAL:
  320A  CD8A26        		call	STRARG2
  320D  2A27FF        		ld	hl,(STREND)
  3210  23            		inc	hl
  3211  EB            		ex	de,hl
                      	
  3212  0600          		ld	b,00h
  3214  4F            		ld	c,a
  3215  09            		add	hl,bc
  3216  E7            		rst	CPHLDE
  3217  7E            		ld	a,(hl)
  3218  F5            		push	af
  3219  E5            		push	hl
  321A  2801          		jr	z,VALZ
  321C  AF            		xor	a
  321D                	VALZ:
  321D  77            		ld	(hl),a
                      	;	or	a
  321E  ED42          		sbc	hl,bc
  3220  CD9839        		call	ATOF
  3223  E1            		pop	hl
  3224  F1            		pop	af
  3225  77            		ld	(hl),a
  3226  C3A731        		jp	SETTYP0
                      	
                      	
                      	;FRE() function
  3229                	F_FRE:
  3229  2125FF        		ld	hl,ARGTYP
  322C  7E            		ld	a,(hl)
  322D  B7            		or	a
  322E  2814          		jr	z,FRENUM
  3230  3D            		dec	a
  3231  C2DC03        		jp	nz,SNERR
                      	;string
  3234  77            		ld	(hl),a		;=0
  3235  322DFF        		ld	(STRDSC1),a	;=0
  3238  CD0F31        		call	GC
  323B  2A3DFF        		ld	hl,(STRAD)
  323E  ED5B5BFA      		ld	de,(STACK)
  3242  1808          		jr	CALCFRE
                      	;numeric
  3244                	FRENUM:
  3244  21FAFF        		ld	hl,0-0006h	;for compatibility with N60-BASIC
  3247  39            		add	hl,sp
  3248  ED5B5AFF      		ld	de,(FREEAD)
  324C                	CALCFRE:
  324C  B7            		or	a
  324D  ED52          		sbc	hl,de
  324F  C3800C        		jp	I2TOF
                      	
                      	
                      	;DIM command
  3252                	C_DIM:
  3252  CD8F33        		call	CHKVAR
                      	
  3255  7E            		ld	a,(hl)
  3256  FE28          		cp	'('
  3258  2044          		jr	nz,NOTARR
  325A  23            		inc	hl
                      	
  325B  E5            		push	hl		;program address
  325C  CD3D34        		call	SRCHARR
  325F  D2F403        		jp	nc,DDERR
  3262  CD8533        		call	SETARNM
  3265  CD3534        		call	VARSIZE
  3268  E1            		pop	hl		;program address
  3269  D5            		push	de		;array address
  326A  D5            		push	de		;array address
  326B  C5            		push	bc		;element bytes
                      	
  326C  48            		ld	c,b		;b=0
  326D                	DIMLP:
  326D  C5            		push	bc		;dimensions
  326E  CD140E        		call	INT2ARG
  3271  C1            		pop	bc		;dimensions
  3272  CB7A          		bit	7,d
  3274  C2E503        		jp	nz,FCERR
  3277  0C            		inc	c
  3278  CAEB03        		jp	z,OMERR		;over 255 dimensions
  327B  13            		inc	de		;+1
                      	
  327C  E1            		pop	hl		;element bytes
  327D  F1            		pop	af		;array address
  327E  D5            		push	de		;size
  327F  F5            		push	af		;array address
  3280  E5            		push	hl		;element bytes
                      	
  3281  2A4EFF        		ld	hl,(PROGAD)
  3284  7E            		ld	a,(hl)
  3285  23            		inc	hl
  3286  FE2C          		cp	','
  3288  28E3          		jr	z,DIMLP
  328A  FE29          		cp	')'
  328C  C2DC03        		jp	nz,SNERR
  328F  CD5934        		call	MAKEARR
                      	
  3292                	DIMNEXT:
  3292  2A4EFF        		ld	hl,(PROGAD)
  3295  2B            		dec	hl
  3296  D7            		rst	ANADAT
  3297  C8            		ret	z
  3298  23            		inc	hl
  3299  FE2C          		cp	','
  329B  C0            		ret	nz
  329C  18B4          		jr	C_DIM
                      	
  329E                	NOTARR:
  329E  224EFF        		ld	(PROGAD),hl
  32A1  CDC133        		call	SRCHVAR
  32A4  DCEB33        		call	c,MAKEVAR
  32A7  18E9          		jr	DIMNEXT
                      	
                      	
                      	;get variable address
                      	;input: bc=variable name, hl=program address
                      	;output: de=variable address, (PROGAD)=next program address
                      	;destroy: FAC1,FAC2,af,hl
  32A9                	GETVAR:
  32A9  C5            		push	bc
  32AA  7E            		ld	a,(hl)
  32AB  FE28          		cp	'('
  32AD  280B          		jr	z,GETVARR
  32AF  224EFF        		ld	(PROGAD),hl
  32B2  CDC133        		call	SRCHVAR
  32B5  DCEB33        		call	c,MAKEVAR
  32B8  C1            		pop	bc
  32B9  C9            		ret
  32BA                	GETVARR:
  32BA  CDBF32        		call	GETARR
  32BD  C1            		pop	bc
  32BE  C9            		ret
                      	
                      	
                      	;get array address
                      	;input: bc=variable name, hl=program address of '('
                      	;output: de=array address
                      	;destroy: af,bc,hl
  32BF                	GETARR:
  32BF  23            		inc	hl
  32C0  224EFF        		ld	(PROGAD),hl
  32C3  C5            		push	bc		;variable name
  32C4  CD3D34        		call	SRCHARR
  32C7  300F          		jr	nc,ARROK
                      	
  32C9  D5            		push	de		;array address
  32CA  2A4EFF        		ld	hl,(PROGAD)
  32CD  E5            		push	hl		;program address
  32CE  CD5333        		call	DIMAUTO
  32D1  E1            		pop	hl		;program address
  32D2  224EFF        		ld	(PROGAD),hl
  32D5  D1            		pop	de		;array address
  32D6  13            		inc	de
  32D7  13            		inc	de
  32D8                	ARROK:
  32D8  EB            		ex	de,hl
  32D9  23            		inc	hl
  32DA  23            		inc	hl
  32DB  0600          		ld	b,00h
  32DD  4E            		ld	c,(hl)		;dimensions
  32DE  09            		add	hl,bc
  32DF  09            		add	hl,bc
  32E0  E5            		push	hl		;array address
  32E1  79            		ld	a,c
  32E2  08            		ex	af,af'		;dimensions
  32E3  F5            		push	af
  32E4  48            		ld	c,b		;=0
  32E5  C5            		push	bc		;pointer
  32E6  E5            		push	hl		;array address
  32E7  210100        		ld	hl,0001h
  32EA  2250FF        		ld	(TMP),hl	;multiplied sizes
                      	
  32ED                	GETALP:
  32ED  2A50FF        		ld	hl,(TMP)
  32F0  E5            		push	hl		;multiplied sizes
  32F1  2A4EFF        		ld	hl,(PROGAD)
  32F4  CD140E        		call	INT2ARG		;get index
  32F7  E1            		pop	hl		;multiplied sizes
  32F8  2250FF        		ld	(TMP),hl
  32FB  E1            		pop	hl		;array address
  32FC  D5            		push	de		;index
  32FD  56            		ld	d,(hl)		;de=size of each dimension
  32FE  2B            		dec	hl
  32FF  5E            		ld	e,(hl)
  3300  2B            		dec	hl
  3301  E3            		ex	(sp),hl		;push array address, pop index
  3302  E7            		rst	CPHLDE
  3303  D2F103        		jp	nc,BSERR
                      	
  3306  D5            		push	de		;size
  3307  ED5B50FF      		ld	de,(TMP)	;multiplied sizes
  330B  CDF921        		call	MULINT2		;hl = multiplied sizes * index
  330E  C1            		pop	bc		;size
  330F  EB            		ex	de,hl
  3310  E1            		pop	hl		;array address
  3311  E3            		ex	(sp),hl		;push array address, pop pointer
  3312  19            		add	hl,de		;pointer += multiplied sizes * index
  3313  E5            		push	hl		;pointer
  3314  2A50FF        		ld	hl,(TMP)	;multiplied sizes
  3317  50            		ld	d,b		;size
  3318  59            		ld	e,c
  3319  CDF921        		call	MULINT2		;hl = multiplied sizes * size
  331C  2250FF        		ld	(TMP),hl
  331F  E1            		pop	hl		;pointer
  3320  E3            		ex	(sp),hl		;push poniter, pop array address
  3321  E5            		push	hl		;array address
                      	
  3322  08            		ex	af,af'		;dimensions
  3323  3D            		dec	a
  3324  47            		ld	b,a
  3325  08            		ex	af,af'
  3326  2A4EFF        		ld	hl,(PROGAD)
  3329  7E            		ld	a,(hl)
  332A  FE2C          		cp	','
  332C  200A          		jr	nz,NOTCMM
  332E  23            		inc	hl
  332F  224EFF        		ld	(PROGAD),hl
  3332  04            		inc	b
                      	;	dec	b
                      	;	jr	nz,GETALP
  3333  10B8          		djnz	GETALP
  3335  C3F103        		jp	BSERR
                      	
  3338                	NOTCMM:
  3338  04            		inc	b
  3339  05            		dec	b
  333A  C2F103        		jp	nz,BSERR
  333D  CDC40B        		call	CHKRPAR
                      	
  3340  D1            		pop	de		;array address
  3341  E1            		pop	hl		;pointer
  3342  F1            		pop	af
  3343  08            		ex	af,af'
  3344  D1            		pop	de		;array address
  3345  C1            		pop	bc		;variable name
  3346  79            		ld	a,c
  3347  44            		ld	b,h
  3348  4D            		ld	c,l
  3349  29            		add	hl,hl		;*2
  334A  29            		add	hl,hl		;*4
  334B  07            		rlca
  334C  3801          		jr	c,NCMMSTR
  334E  09            		add	hl,bc		;*5
  334F                	NCMMSTR:
  334F  19            		add	hl,de
  3350  23            		inc	hl
  3351  EB            		ex	de,hl
  3352  C9            		ret
                      	
                      	
  3353                	DIMAUTO:
  3353  CD8533        		call	SETARNM
  3356  D5            		push	de		;array address
  3357  CD3534        		call	VARSIZE
  335A  D5            		push	de		;array address
  335B  C5            		push	bc		;element bytes
                      	
  335C  2A4EFF        		ld	hl,(PROGAD)
  335F  48            		ld	c,b		;b=0
  3360                	AUTOLP1:
  3360  C5            		push	bc		;dimensions
  3361  CD140E        		call	INT2ARG		;de=size
                      	;	ld	a,d
                      	;	or	a
                      	;	jp	nz,BSERR
                      	;	ld	a,e
                      	;	ld	e,0bh		;de=10+1
                      	;	cp	e
                      	;	jp	nc,BSERR
                      	
  3364  110B00        		ld	de,000bh
                      	
  3367  C1            		pop	bc		;dimensions
  3368  0C            		inc	c
  3369  CB51          		bit	2,c
  336B  C2F103        		jp	nz,BSERR	;over 3 dimensions
                      	
  336E  EB            		ex	de,hl
  336F  D1            		pop	de		;element bytes
  3370  E3            		ex	(sp),hl		;push size, pop array address
  3371  E5            		push	hl		;array address
  3372  D5            		push	de		;element bytes
                      	
                      	
  3373  2A4EFF        		ld	hl,(PROGAD)
  3376  7E            		ld	a,(hl)
  3377  23            		inc	hl
  3378  FE2C          		cp	','
  337A  28E4          		jr	z,AUTOLP1
  337C  FE29          		cp	')'
  337E  C2DC03        		jp	nz,SNERR
  3381  CD5934        		call	MAKEARR
  3384  C9            		ret
                      	
                      	
                      	;set array name
                      	;input: bc=name, de=array address
                      	;output: de=array address (next of name)
                      	;destroy: af,hl
  3385                	SETARNM:
  3385  EB            		ex	de,hl
  3386  CDCF34        		call	CHKSTK
  3389  70            		ld	(hl),b
  338A  23            		inc	hl
  338B  71            		ld	(hl),c
  338C  23            		inc	hl
  338D  EB            		ex	de,hl
  338E  C9            		ret
                      	
                      	
                      	;check variable name
                      	;input: hl=program address
                      	;output: a=next character, bc=name, hl=next address
                      	;destroy: f
  338F                	CHKVAR:
  338F  7E            		ld	a,(hl)
  3390  23            		inc	hl
  3391  FE20          		cp	' '
  3393  28FA          		jr	z,CHKVAR
  3395  47            		ld	b,a
  3396  D641          		sub	'A'
  3398  FE1A          		cp	'Z'-'A'+1
  339A  D2DC03        		jp	nc,SNERR
                      	;	call	GETNAME
                      	;	ret
                      	
                      	
                      	;get variable name
                      	;input: hl=2nd character address, b=1st character
                      	;output: a=next character, bc=name, hl=next address
                      	;destroy: f
  339D                	GETNAME:
  339D  0E00          		ld	c,00h
  339F  2B            		dec	hl
  33A0                	GETNMLP1:
  33A0  23            		inc	hl
  33A1  7E            		ld	a,(hl)
  33A2  FE20          		cp	' '
  33A4  28FA          		jr	z,GETNMLP1
  33A6  FE24          		cp	'$'
  33A8  2813          		jr	z,NAMESTR
  33AA  CDD90B        		call	ALPNUM
  33AD  D0            		ret	nc
  33AE  4F            		ld	c,a
  33AF                	GETNMLP2:
  33AF  23            		inc	hl
  33B0  7E            		ld	a,(hl)
  33B1  FE20          		cp	' '
  33B3  28FA          		jr	z,GETNMLP2
  33B5  CDD90B        		call	ALPNUM
  33B8  38F5          		jr	c,GETNMLP2
  33BA  FE24          		cp	'$'
  33BC  C0            		ret	nz
  33BD                	NAMESTR:
  33BD  23            		inc	hl
  33BE  CBF9          		set	7,c
  33C0  C9            		ret
                      	
                      	
                      	;search for variable
                      	;input: bc=variable name
                      	;output: de=variable address, c-flag(1=not found)
                      	;destroy: af,hl
  33C1                	SRCHVAR:
  33C1  2A5EFF        		ld	hl,(FNPAR)
  33C4  7D            		ld	a,l
  33C5  B8            		cp	b
  33C6  2006          		jr	nz,SRCHVMAIN
  33C8  7C            		ld	a,h
  33C9  B9            		cp	c
  33CA  1160FF        		ld	de,FNARG
  33CD  C8            		ret	z
                      	
  33CE                	SRCHVMAIN:
  33CE  ED5B56FF      		ld	de,(VARAD)
  33D2                	SRCHVLP:
  33D2  2A58FF        		ld	hl,(ARRAD)
  33D5  2B            		dec	hl
  33D6  E7            		rst	CPHLDE
  33D7  D8            		ret	c		;not found
  33D8  1A            		ld	a,(de)
  33D9  13            		inc	de
  33DA  B8            		cp	b		;
  33DB  1A            		ld	a,(de)
  33DC  13            		inc	de
  33DD  2002          		jr	nz,VARNEXT	;
  33DF  B9            		cp	c
  33E0  C8            		ret	z		;found
  33E1                	VARNEXT:
  33E1  07            		rlca			;c-flag=1 if string
  33E2  3F            		ccf
  33E3  210400        		ld	hl,6-2
  33E6  ED5A          		adc	hl,de
  33E8  EB            		ex	de,hl
  33E9  18E7          		jr	SRCHVLP
                      	
                      	
                      	;make variable
                      	;input: bc=variable name, de=variable address
                      	;output: de=de+2
                      	;destroy: af,bc,hl
  33EB                	MAKEVAR:
  33EB  C5            		push	bc		;variable name
  33EC  D5            		push	de		;variable address
                      	
  33ED  110600        		ld	de,0006h
  33F0  CB79          		bit	7,c
  33F2  2001          		jr	nz,MAKEVSTR	;numeric=7, string=6
  33F4  1C            		inc	e
  33F5                	MAKEVSTR:
  33F5  2A5AFF        		ld	hl,(FREEAD)
  33F8  ED4B58FF      		ld	bc,(ARRAD)
  33FC  B7            		or	a
  33FD  ED42          		sbc	hl,bc
  33FF  44            		ld	b,h
  3400  4D            		ld	c,l
                      	
  3401  2A5AFF        		ld	hl,(FREEAD)
                      	
  3404  19            		add	hl,de
  3405  D5            		push	de		;numeric=7, string=6
  3406  CDCF34        		call	CHKSTK
  3409  D1            		pop	de		;numeric=7, string=6
  340A  225AFF        		ld	(FREEAD),hl
  340D  2A58FF        		ld	hl,(ARRAD)
  3410  19            		add	hl,de
  3411  2258FF        		ld	(ARRAD),hl
                      	
  3414  78            		ld	a,b
  3415  B1            		or	c
  3416  280B          		jr	z,NOLDDR
  3418  2A5AFF        		ld	hl,(FREEAD)
  341B  E5            		push	hl		;
                      	;	or	a
  341C  ED52          		sbc	hl,de
  341E  2B            		dec	hl
  341F  D1            		pop	de		;
  3420  1B            		dec	de
  3421  EDB8          		lddr
  3423                	NOLDDR:
  3423  E1            		pop	hl		;variable address
  3424  C1            		pop	bc		;variable name
  3425  70            		ld	(hl),b
  3426  23            		inc	hl
  3427  71            		ld	(hl),c
  3428  23            		inc	hl
  3429  E5            		push	hl		;variable address
                      	
  342A  EB            		ex	de,hl
  342B  21AB0E        		ld	hl,ZERO
  342E  CD3534        		call	VARSIZE
  3431  EDB0          		ldir
  3433  D1            		pop	de		;variable address
  3434  C9            		ret
                      	
                      	
                      	;get variable element size
                      	;input: bc=variable name
                      	;output: bc=5(numeric) or 4(string)
                      	;destroy: f
  3435                	VARSIZE:
  3435  CB79          		bit	7,c
  3437  010500        		ld	bc,0005h
  343A  C8            		ret	z
  343B  0D            		dec	c
  343C  C9            		ret
                      	
                      	
                      	;search for array variable
                      	;input: bc=variable name
                      	;output: de=array address, c-flag(1=not found)
                      	;destroy: af,hl
  343D                	SRCHARR:
  343D  ED5B58FF      		ld	de,(ARRAD)
  3441                	SRCHALP:
  3441  2A5AFF        		ld	hl,(FREEAD)
  3444  2B            		dec	hl
  3445  E7            		rst	CPHLDE
  3446  D8            		ret	c		;not found
  3447  1A            		ld	a,(de)
  3448  13            		inc	de
  3449  B8            		cp	b		;
  344A  1A            		ld	a,(de)
  344B  13            		inc	de
  344C  2002          		jr	nz,ARRNEXT	;
  344E  B9            		cp	c
  344F  C8            		ret	z		;found
  3450                	ARRNEXT:
  3450  EB            		ex	de,hl
  3451  5E            		ld	e,(hl)
  3452  23            		inc	hl
  3453  56            		ld	d,(hl)
  3454  23            		inc	hl
  3455  19            		add	hl,de
  3456  EB            		ex	de,hl
  3457  18E8          		jr	SRCHALP
                      	
                      	
                      	;make array
                      	;input: c=dimensions, hl=program address
                      	;pushed: size*[1,255], array address, element bytes
                      	;destroy: af,bc,de,hl
  3459                	MAKEARR:
  3459  224EFF        		ld	(PROGAD),hl
  345C  E1            		pop	hl		;return address
  345D  2250FF        		ld	(TMP),hl
  3460  D1            		pop	de		;element bytes
  3461  E1            		pop	hl		;array address
  3462  23            		inc	hl
  3463  23            		inc	hl
  3464  71            		ld	(hl),c		;dimensions
  3465  23            		inc	hl
  3466  EB            		ex	de,hl
                      	
  3467  41            		ld	b,c
  3468                	MKALP:
  3468  E3            		ex	(sp),hl		;push element bytes, pop size
  3469  EB            		ex	de,hl
  346A  73            		ld	(hl),e
  346B  23            		inc	hl
  346C  72            		ld	(hl),d
  346D  23            		inc	hl
  346E  E3            		ex	(sp),hl		;push array address, pop element bytes
  346F  C5            		push	bc		;dimensions
  3470  CDF921        		call	MULINT2		;element bytes *= each dimension size
  3473  C1            		pop	bc		;dimensions
  3474  7A            		ld	a,d
  3475  B3            		or	e
  3476  C2F103        		jp	nz,BSERR	;for compatibility with N60-BASIC
  3479  D1            		pop	de		;array address
  347A  10EC          		djnz	MKALP
                      	
  347C  E5            		push	hl		;element bytes
  347D  EB            		ex	de,hl
  347E  60            		ld	h,b
  347F  69            		ld	l,c
  3480  29            		add	hl,hl
  3481  23            		inc	hl
  3482  19            		add	hl,de
  3483  DAEB03        		jp	c,OMERR
                      	
  3486  E5            		push	hl		;dimensions*2 + element bytes + 1
  3487  ED5B5AFF      		ld	de,(FREEAD)
  348B  13            		inc	de		;+2(total bytes)
  348C  13            		inc	de
  348D  13            		inc	de		;+2(name)
  348E  13            		inc	de
  348F  19            		add	hl,de
  3490  DAEB03        		jp	c,OMERR
  3493  CDCF34        		call	CHKSTK
  3496  225AFF        		ld	(FREEAD),hl
                      	
  3499  79            		ld	a,c		;dimensions
  349A  D1            		pop	de		;dimensions*2 + element bytes + 1
  349B  E1            		pop	hl		;element bytes
  349C  E3            		ex	(sp),hl		;push element bytes, pop array address
                      	
  349D  73            		ld	(hl),e
  349E  23            		inc	hl
  349F  72            		ld	(hl),d
  34A0  23            		inc	hl
  34A1  23            		inc	hl
  34A2  09            		add	hl,bc
  34A3  09            		add	hl,bc
                      	
  34A4  70            		ld	(hl),b		;b=0
  34A5  54            		ld	d,h
  34A6  5D            		ld	e,l
  34A7  13            		inc	de
  34A8  C1            		pop	bc		;element bytes
  34A9  0B            		dec	bc
  34AA  EDB0          		ldir
  34AC  2A50FF        		ld	hl,(TMP)	;return address
  34AF  E9            		jp	(hl)
                      	
                      	
                      	;NEW command
  34B0                	C_NEW:
  34B0  CD5E3F        		call	CHKCLN
  34B3  C2DC03        		jp	nz,SNERR
  34B6  214204        		ld	hl,EDIT
  34B9  E5            		push	hl
                      	
                      	;destroy: af,bc,de,hl
  34BA                	NEWRESSTK:
  34BA  21F934        		ld	hl,RESSTK
  34BD  E5            		push	hl
                      	;	jp	NEW
                      	
                      	;destroy: af,hl
  34BE                	NEW:
  34BE  2A29FF        		ld	hl,(BASICAD)
  34C1  AF            		xor	a
  34C2  77            		ld	(hl),a
  34C3  23            		inc	hl
  34C4  77            		ld	(hl),a
  34C5  23            		inc	hl
  34C6  77            		ld	(hl),a
  34C7  23            		inc	hl
  34C8  2256FF        		ld	(VARAD),hl
  34CB  C9            		ret
                      	
                      	
                      	;check free size
                      	;output: de=free size
                      	;destroy: f,hl
  34CC                	CHKFRE:
  34CC  2A5AFF        		ld	hl,(FREEAD)
                      	
                      	;check stack size
                      	;hl <= stack - 003bh?
                      	;input: hl=address
                      	;output: de=free size
                      	;destroy: f
  34CF                	CHKSTK:
  34CF  EB            		ex	de,hl
                      	;	ld	hl,0-003bh+1
  34D0  21CDFF        		ld	hl,0-0034h+1
  34D3  39            		add	hl,sp
  34D4  ED52          		sbc	hl,de		;c-flag=1
  34D6  DAEB03        		jp	c,OMERR
  34D9  EB            		ex	de,hl
  34DA  C9            		ret
                      	
                      	
                      	;reset stack and variables
                      	;destroy: af,bc,de,hl
  34DB                	_RESSTK:ds	RESSTK-_RESSTK
  34F9                		org	RESSTK
                      	
  34F9  C1            		pop	bc		;return address
  34FA  ED7B5BFA      		ld	sp,(STACK)
  34FE  C5            		push	bc		;return address
  34FF  3EFF          		ld	a,0ffh
  3501  3255FF        		ld	(STOPAD+1),a
  3504  2A56FF        		ld	hl,(VARAD)
  3507  2258FF        		ld	(ARRAD),hl
  350A  225AFF        		ld	(FREEAD),hl
  350D  CDC9FF        		call	HOOKRES
  3510                	RSTRZ:
  3510  2A29FF        		ld	hl,(BASICAD)
  3513  225CFF        		ld	(DATAAD),hl
  3516  C9            		ret
                      	
                      	
                      	;RESTORE command
  3517                	C_RSTR:
  3517  CD5E3F        		call	CHKCLN
  351A  224EFF        		ld	(PROGAD),hl
  351D  28F1          		jr	z,RSTRZ
  351F  CD6807        		call	GETLN
  3522  224EFF        		ld	(PROGAD),hl
  3525  CDF304        		call	SRCHLN
  3528  D2EE03        		jp	nc,ULERR
  352B  ED435CFF      		ld	(DATAAD),bc
  352F  C9            		ret
                      	
                      	
                      	;STOP command
  3530                	C_STOP:
  3530  CD5E3F        		call	CHKCLN
  3533  C2DC03        		jp	nz,SNERR
  3536  F1            		pop	af		;cancel return address
                      	
  3537                	STOP1:
  3537  7C            		ld	a,h
  3538  FEFA          		cp	0fah
  353A  300F          		jr	nc,STOPNC
  353C                	STOP2:
  353C  2254FF        		ld	(STOPAD),hl
  353F                	STOP3:
  353F  2A8FFD        		ld	hl,(SCREEN2)	;l=(SCREEN2),h=(SCREEN3)
  3542  22AAFE        		ld	(STOPSC2),hl	;(STOPSC2)=l,(STOPSC3)=h
  3545  2A5DFA        		ld	hl,(LINENUM)
  3548  2252FF        		ld	(STOPLN),hl
  354B                	STOPNC:
  354B  FB            		ei
  354C  AF            		xor	a
  354D  3218FA        		ld	(STOPFLG),a
                      	
  3550  CD3C09        		call	PRTNLX
  3553  CD7213        		call	CHGTXT
  3556  215F35        		ld	hl,BREAK
  3559  CDCF30        		call	PUTS
  355C  C33204        		jp	PRTLNUM
                      	
  355F                	BREAK:
  355F  07427265616B00		db	07h, "Break", 00h
                      	
                      	
                      	;END command
  3566                	C_END:
  3566  F1            		pop	af		;cancel stack
  3567  C34204        		jp	EDIT
                      	
                      	
                      	;CONT command
  356A                	C_CONT:
  356A  F1            		pop	af		;cancel return address
                      	
  356B  7C            		ld	a,h
  356C  FEFA          		cp	0fah
  356E  DA0904        		jp	c,CNERR		;cont in program
                      	
  3571  2A54FF        		ld	hl,(STOPAD)
  3574  7C            		ld	a,h
  3575  FEFA          		cp	0fah
  3577  D20904        		jp	nc,CNERR	;stop in direct command mode
                      	
  357A  9F            		sbc	a,a		;c-flag=1
  357B  3255FF        		ld	(STOPAD+1),a	;a=ffh
                      	
  357E  EB            		ex	de,hl
  357F  2A52FF        		ld	hl,(STOPLN)
  3582  225DFA        		ld	(LINENUM),hl
  3585  2AAAFE        		ld	hl,(STOPSC2)	;l=(STOPSC2),h=(STOPSC3)
  3588  7D            		ld	a,l
  3589  CD0C14        		call	CHGACT
  358C  7C            		ld	a,h
  358D  CDED13        		call	CHGDSP
  3590  EB            		ex	de,hl
                      	
  3591  C30A07        		jp	INTPRT
                      	
                      	
                      	;CLEAR command
  3594                	_C_CLR:	ds	C_CLR-_C_CLR
  35A9                		org	C_CLR
                      	
  35A9  CD5E3F        		call	CHKCLN
  35AC  CAF934        		jp	z,RESSTK
  35AF  CD140E        		call	INT2ARG
  35B2  CB7A          		bit	7,d
  35B4  C2E503        		jp	nz,FCERR
  35B7  D5            		push	de		;1st parameter
  35B8  ED5B27FF      		ld	de,(STREND)
  35BC  7E            		ld	a,(hl)
  35BD  FE2C          		cp	','
  35BF  200E          		jr	nz,CLRNZ
  35C1  CD910B        		call	NARGMOINC
  35C4  CD9F0C        		call	FTOI
  35C7  1B            		dec	de
  35C8  2A8DFD        		ld	hl,(USREND)
  35CB  E7            		rst	CPHLDE
  35CC  DAE503        		jp	c,FCERR
                      	
  35CF                	CLRNZ:
  35CF  EB            		ex	de,hl
  35D0  C1            		pop	bc		;1st parameter
                      	
                      	;input: bc=1st parameter, hl=2nd parameter-1
  35D1                	CLRMAIN:
  35D1  E5            		push	hl		;2nd parameter-1
  35D2  B7            		or	a
  35D3  ED42          		sbc	hl,bc
                      	;	jp	c,OMERR
  35D5  380A          		jr	c,CLRC
  35D7  EB            		ex	de,hl
  35D8  2A56FF        		ld	hl,(VARAD)
  35DB  013800        		ld	bc,0038h
  35DE  09            		add	hl,bc
  35DF  EB            		ex	de,hl
  35E0  E7            		rst	CPHLDE
  35E1                	CLRC:
  35E1  DAEB03        		jp	c,OMERR
  35E4  225BFA        		ld	(STACK),hl
  35E7  E1            		pop	hl		;2nd parameter-1
  35E8  2227FF        		ld	(STREND),hl
  35EB  223DFF        		ld	(STRAD),hl
  35EE  C3F934        		jp	RESSTK
                      	
                      	
                      	;NEXT command
  35F1                	C_NEXT:
  35F1  F1            		pop	af		;cancel return address
  35F2  0600          		ld	b,00h
  35F4                	NEXTLP:
  35F4  CD5E3F        		call	CHKCLN
  35F7  C48F33        		call	nz,CHKVAR
  35FA  224EFF        		ld	(PROGAD),hl
                      	
  35FD                	NEXTVLP:
  35FD  CDD107        		call	SRCHSTK
  3600  CAD903        		jp	z,NFERR		;not found or gosub identifier found
  3603  33            		inc	sp		;identifier
                      	
  3604  D1            		pop	de		;variable address
                      	
  3605  78            		ld	a,b
  3606  B7            		or	a
  3607  2813          		jr	z,NEXTOK
                      	
  3609  1B            		dec	de
  360A  1A            		ld	a,(de)
  360B  B9            		cp	c
  360C  2007          		jr	nz,NEXTNZ
  360E  1B            		dec	de
  360F  1A            		ld	a,(de)
  3610  13            		inc	de
  3611  13            		inc	de
  3612  B8            		cp	b
  3613  2807          		jr	z,NEXTOK
  3615                	NEXTNZ:
  3615  211000        		ld	hl,0010h	;STEP(6)+TO(6)+line number(2)+program address(2)
  3618  39            		add	hl,sp
  3619  F9            		ld	sp,hl
  361A  18E1          		jr	NEXTVLP
                      	
  361C                	NEXTOK:
  361C  CD3439        		call	POPF1		;STEP value
  361F  CD2539        		call	PUSHF1		;STEP value
                      	
  3622  D5            		push	de		;variable address
  3623  EB            		ex	de,hl
  3624  CD8F36        		call	SETADDF
  3627  D1            		pop	de		;variable address
  3628  D5            		push	de		;variable address
  3629  2166FF        		ld	hl,FAC1
  362C  CD480C        		call	SETF
                      	
  362F  D1            		pop	de		;variable address
                      	
  3630  CD3439        		call	POPF1		;STEP value
  3633  CD4339        		call	POPF2		;TO value
  3636  CD1A3C        		call	PUSHF2		;TO value
  3639  CD2539        		call	PUSHF1		;STEP value
                      	
  363C  D5            		push	de		;variable address
                      	
  363D  EF            		rst	CHKSGN
  363E  EB            		ex	de,hl		;variable address
  363F  CD450C        		call	SETF1		;no change in z,c-flag
  3642  2822          		jr	z,STEP0		;if STEP value = 0
  3644  D46539        		call	nc,EXFAC	;if STEP value > 0
  3647  CD193F        		call	CMPF
  364A  381F          		jr	c,NEXTEND	;for-next loop end
                      	
  364C                	NEXTCONT:
  364C  210E00        		ld	hl,000eh	;variable address(2)+STEP(6)+TO(6)
  364F  39            		add	hl,sp
  3650  5E            		ld	e,(hl)
  3651  23            		inc	hl
  3652  56            		ld	d,(hl)
  3653  ED535DFA      		ld	(LINENUM),de
  3657  23            		inc	hl
  3658  5E            		ld	e,(hl)
  3659  23            		inc	hl
  365A  56            		ld	d,(hl)
  365B  ED534EFF      		ld	(PROGAD),de
  365F  3E81          		ld	a,FOR_
  3661  F5            		push	af		;identifier
  3662  33            		inc	sp
  3663  C3E706        		jp	INTPEND
                      	
  3666                	STEP0:
  3666  CD193F        		call	CMPF
  3669  20E1          		jr	nz,NEXTCONT
                      	
  366B                	NEXTEND:
  366B  211200        		ld	hl,0012h	;variable address(2)+STEP(6)+TO(6)+line number(2)+program address(2)
  366E  39            		add	hl,sp
  366F  F9            		ld	sp,hl
                      	
  3670  2A4EFF        		ld	hl,(PROGAD)
  3673  7E            		ld	a,(hl)
  3674  FE2C          		cp	','
  3676  C2E706        		jp	nz,INTPEND
  3679  23            		inc	hl
  367A  47            		ld	b,a		;not variable name
  367B  C3F435        		jp	NEXTLP
                      	
                      	
                      	;+ operator
  367E                	O_PLS:
  367E  3A25FF        		ld	a,(ARGTYP)
  3681  B7            		or	a
  3682  281A          		jr	z,ADDF
                      	
  3684                	PLSSTR:
  3684  FE03          		cp	03h		;string and string
  3686  CA2326        		jp	z,ADDSTR
  3689  C3FD03        		jp	TMERR
                      	
                      	
                      	;FAC1=FAC1+1
                      	;destroy: FAC2,af,bc,de,hl
  368C                	INCF1:
  368C  21A10E        		ld	hl,PLSONE
                      	
                      	;set FAC2 and add
                      	;input: FAC1, hl=float address
  368F                	SETADDF:
  368F  CD4E0C        		call	SETF2
  3692  180A          		jr	ADDF
                      	
                      	
                      	;- operator
  3694                	O_MNS:
  3694  CD9B0B        		call	CHKNUM
                      	;	call	SUBF
                      	;	ret
                      	
                      	
                      	;FAC1 = FAC1 - FAC2
                      	;input: FAC1,FAC2
                      	;output: FAC1
                      	;destroy: FAC2,af,b,de,hl
  3697                	SUBF:
  3697  2170FF        		ld	hl,FAC2+3
  369A                	CHGSGNADD:
  369A  7E            		ld	a,(hl)
  369B  EE80          		xor	80h
  369D  77            		ld	(hl),a
                      	;	call	ADDF
                      	;	ret
                      	
                      	
                      	;FAC1 = FAC1 + FAC2
                      	;input: FAC1,FAC2
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  369E                	ADDF:
  369E  2A70FF        		ld	hl,(FAC2+3)	;l=(FAC2+3),h=(FAC2+4)
  36A1  7C            		ld	a,h
  36A2  B7            		or	a
  36A3  C8            		ret	z		;FAC2=0
                      	
  36A4  E5            		push	hl
  36A5  CBFD          		set	7,l
  36A7  2270FF        		ld	(FAC2+3),hl
                      	
  36AA  2A69FF        		ld	hl,(FAC1+3)	;l=(FAC1+3),h=(FAC1+4)
  36AD  E5            		push	hl
  36AE  CBFD          		set	7,l
  36B0  2269FF        		ld	(FAC1+3),hl
                      	
                      	;	sub	h
                      	;	jr	c,ADD1GT2	;|FAC1| > |FAC2|
                      	;	jr	nz,ADD1LT2	;|FAC1| < |FAC2|
                      	
  36B3  CD193F        		call	CMPF
  36B6  380D          		jr	c,ADD1GT2	;|FAC1| > |FAC2|
                      	
  36B8                	ADD1LT2:
  36B8  CD6539        		call	EXFAC
                      	
  36BB  D1            		pop	de		;e=(FAC1+3),d=(FAC1+4)
  36BC  E1            		pop	hl		;l=(FAC2+3),h=(FAC2+4)
                      	
  36BD  7A            		ld	a,d
  36BE  B7            		or	a
  36BF  2006          		jr	nz,ADDCHKSGN
  36C1  2269FF        		ld	(FAC1+3),hl
  36C4  C9            		ret
                      	
  36C5                	ADD1GT2:
  36C5  E1            		pop	hl		;l=(FAC1+3),h=(FAC1+4)
  36C6  D1            		pop	de		;e=(FAC2+3),d=(FAC2+4)
                      	
  36C7                	ADDCHKSGN:
  36C7  7C            		ld	a,h
  36C8  92            		sub	d
  36C9  47            		ld	b,a		;exponent difference
                      	
  36CA  7D            		ld	a,l
  36CB  F5            		push	af		;sign
                      	
  36CC  AB            		xor	e
  36CD  07            		rlca
  36CE  F5            		push	af		;c-flag=0:same sign
  36CF  3009          		jr	nc,SAMESGN
                      	
  36D1  CD6539        		call	EXFAC
  36D4  CDA124        		call	NEGINT4
  36D7  CD6539        		call	EXFAC
                      	
  36DA                	SAMESGN:
  36DA  0E00          		ld	c,00h		;guard/round/sticky bit
  36DC  2A6DFF        		ld	hl,(FAC2)
  36DF  ED5B6FFF      		ld	de,(FAC2+2)
                      	
  36E3                	ADDFLP1:
  36E3  78            		ld	a,b		;exponent difference
  36E4  D608          		sub	08h
  36E6  3818          		jr	c,EXPLT8
  36E8  47            		ld	b,a
                      	
  36E9  7D            		ld	a,l
  36EA  E63F          		and	3fh
  36EC  2004          		jr	nz,SETSBIT
  36EE  0C            		inc	c
  36EF  0D            		dec	c
  36F0  2802          		jr	z,NOSBIT
  36F2                	SETSBIT:
  36F2  0E20          		ld	c,20h		;set sticky bit
  36F4                	NOSBIT:
  36F4  AD            		xor	l
  36F5  B1            		or	c
  36F6  4F            		ld	c,a
  36F7  6C            		ld	l,h
  36F8  63            		ld	h,e
  36F9  5A            		ld	e,d
  36FA  F1            		pop	af		;same sign?
  36FB  F5            		push	af
  36FC  9F            		sbc	a,a		;00h or ffh
  36FD  57            		ld	d,a
  36FE  18E3          		jr	ADDFLP1
                      	
  3700                	EXPLT8:
  3700  C608          		add	a,08h
  3702  2813          		jr	z,SAMEEXP
                      	
  3704                	ADDFLP2:
  3704  F1            		pop	af		;same sign?
  3705  F5            		push	af
  3706  CB1A          		rr	d
  3708  CB1B          		rr	e
  370A  CB1C          		rr	h
  370C  CB1D          		rr	l
                      	
  370E  79            		ld	a,c
  370F  CB19          		rr	c
  3711  E620          		and	20h		;sticky bit
  3713  B1            		or	c
                      	;	and	0e0h
  3714  4F            		ld	c,a
  3715  10ED          		djnz	ADDFLP2
                      	
  3717                	SAMEEXP:
  3717  226DFF        		ld	(FAC2),hl
  371A  ED536FFF      		ld	(FAC2+2),de
                      	
  371E  EB            		ex	de,hl
                      	
  371F  2A66FF        		ld	hl,(FAC1)
                      	;	ld	de,(FAC2)
  3722  19            		add	hl,de
  3723  2266FF        		ld	(FAC1),hl
  3726  2A68FF        		ld	hl,(FAC1+2)
  3729  ED5B6FFF      		ld	de,(FAC2+2)
  372D  ED5A          		adc	hl,de
  372F  2268FF        		ld	(FAC1+2),hl
                      	
  3732  17            		rla
  3733  E1            		pop	hl		;l-bit0=same sign?
  3734  AD            		xor	l
  3735  0F            		rrca
  3736  301A          		jr	nc,SEARCH1
                      	
  3738  216AFF        		ld	hl,FAC1+4
  373B  34            		inc	(hl)
  373C  CAE803        		jp	z,OVERR
                      	
                      	;	scf			;c-flag=1
  373F  2D            		dec	l		;dec hl,FAC1+3
  3740  CB1E          		rr	(hl)
  3742  2D            		dec	l		;dec hl,FAC1+2
  3743  CB1E          		rr	(hl)
  3745  2D            		dec	l		;dec hl,FAC1+1
  3746  CB1E          		rr	(hl)
  3748  2D            		dec	l		;dec hl,FAC1
  3749  CB1E          		rr	(hl)
                      	
  374B  79            		ld	a,c
  374C  CB19          		rr	c
  374E  E620          		and	20h		;sticky bit
  3750  B1            		or	c
                      	;	and	0e0h
  3751  4F            		ld	c,a
                      	
  3752                	SEARCH1:
  3752  2A66FF        		ld	hl,(FAC1)
  3755  ED5B68FF      		ld	de,(FAC1+2)
                      	;	ld	a,h
                      	;	or	l
                      	;	or	d
                      	;	or	e
                      	;	or	c
                      	;	jp	z,MULFZERO
                      	
  3759                	ADDFLP3:
  3759  CB7A          		bit	7,d
  375B  2014          		jr	nz,CHKROUND
  375D  CB21          		sla	c
  375F  ED6A          		adc	hl,hl
  3761  CB13          		rl	e
  3763  CB12          		rl	d
  3765  3A6AFF        		ld	a,(FAC1+4)
  3768  3D            		dec	a
  3769  326AFF        		ld	(FAC1+4),a
  376C  20EB          		jr	nz,ADDFLP3
  376E  C33338        		jp	MULFZERO	;pop af/jp SETZERO
                      	
                      	;round to the nearest even
  3771                	CHKROUND:
  3771  7D            		ld	a,l
  3772  0F            		rrca
  3773  79            		ld	a,c
  3774  8F            		adc	a,a
  3775  3015          		jr	nc,ADDSGN	;guard bit=0
  3777  2813          		jr	z,ADDSGN	;round bit=0 and sticky bit=0 and l=even
                      	
                      	;round up
  3779  23            		inc	hl
  377A  7C            		ld	a,h
  377B  B5            		or	l
  377C  200E          		jr	nz,ADDSGN
  377E  13            		inc	de
  377F  7A            		ld	a,d
  3780  B3            		or	e
  3781  2009          		jr	nz,ADDSGN
                      	
  3783  216AFF        		ld	hl,FAC1+4
  3786  34            		inc	(hl)
  3787  CAE803        		jp	z,OVERR
                      	;	ld	d,80h
  378A  63            		ld	h,e		;e=0
  378B  6B            		ld	l,e		;e=0
                      	
  378C                	ADDSGN:
  378C  F1            		pop	af		;sign
  378D  AA            		xor	d
  378E  E680          		and	80h
  3790  AA            		xor	d
  3791  57            		ld	d,a
                      	
  3792  C30725        		jp	SETI4
                      	
                      	
                      	;FAC1 = FAC1 * 0.1
                      	;input: FAC1
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  3795                	DIVF10:
  3795  219A37        		ld	hl,EM1
  3798  1808          		jr	SETMULF
                      	
                      	;0.1
  379A                	EM1:
  379A  CDCCCC4C7D    		db	0cdh, 0cch, 0cch, 4ch, 7dh
                      	
                      	
                      	;FAC1 = FAC1 * 10
                      	;input: FAC1
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  379F                	MULF10:
  379F  21A737        		ld	hl,TEN
                      	
                      	;set FAC2 and multiply
                      	;input: FAC1, hl=float address
  37A2                	SETMULF:
  37A2  CD4E0C        		call	SETF2
  37A5  1808          		jr	MULF
                      	
  37A7                	TEN:
  37A7  0000002084    		db	00h, 00h, 00h, 20h, 84h
                      	
                      	
                      	;* operator
  37AC                	O_MUL:
  37AC  CD9B0B        		call	CHKNUM
                      	;	call	MULF
                      	;	ret
                      	
                      	
                      	;FAC1 = FAC1 * FAC2
                      	;input: FAC1,FAC2
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  37AF                	MULF:
                      	
                      	;result=bc-de-de'-hl'
                      	
  37AF  CD4D38        		call	MULDIVSGN
  37B2  CA420C        		jp	z,SETZERO	;FAC2=0
  37B5  D8            		ret	c		;FAC1=0
                      	
  37B6  010000        		ld	bc,0000h
  37B9  50            		ld	d,b
  37BA  59            		ld	e,c
                      	
  37BB  F5            		push	af		;sign
  37BC  D9            		exx
  37BD  E5            		push	hl
  37BE  D5            		push	de
  37BF  C5            		push	bc
                      	
  37C0  2A66FF        		ld	hl,(FAC1)
  37C3  ED5B68FF      		ld	de,(FAC1+2)
                      	;	or	a		;c-flag=0
                      	
  37C7  0620          		ld	b,20h
  37C9                	MULFLP:
                      	;shift result and FAC1
  37C9  D9            		exx
  37CA  CB18          		rr	b
  37CC  CB19          		rr	c
  37CE  CB1A          		rr	d
  37D0  CB1B          		rr	e
  37D2  D9            		exx
  37D3  CB1A          		rr	d
  37D5  CB1B          		rr	e
  37D7  CB1C          		rr	h
  37D9  CB1D          		rr	l
  37DB  300E          		jr	nc,MULFNC1
                      	
                      	;add
  37DD  D9            		exx
  37DE  2A6DFF        		ld	hl,(FAC2)
  37E1  19            		add	hl,de
  37E2  EB            		ex	de,hl
  37E3  2A6FFF        		ld	hl,(FAC2+2)
  37E6  ED4A          		adc	hl,bc
  37E8  44            		ld	b,h
  37E9  4D            		ld	c,l
  37EA  D9            		exx
  37EB                	MULFNC1:
  37EB  10DC          		djnz	MULFLP
                      	
  37ED  D9            		exx
  37EE  216AFF        		ld	hl,FAC1+4
  37F1  300D          		jr	nc,MULFNC2
                      	
                      	;shift result
  37F3  CB18          		rr	b
  37F5  CB19          		rr	c
  37F7  CB1A          		rr	d
  37F9  CB1B          		rr	e
  37FB  D9            		exx
  37FC  CB1A          		rr	d
                      	;	rr	e
                      	;	rr	h
                      	;	rr	l
  37FE  D9            		exx
  37FF  34            		inc	(hl)
                      	
  3800                	MULFNC2:
  3800  35            		dec	(hl)		;;
                      	
                      	;round to the nearest even
  3801  D9            		exx
  3802  7A            		ld	a,d
  3803  8F            		adc	a,a		;check d-bit7
  3804  3041          		jr	nc,NOROUNDUP
  3806  B3            		or	e
  3807  B4            		or	h
  3808  B5            		or	l
  3809  C1            		pop	bc
  380A  D1            		pop	de
  380B  E1            		pop	hl
  380C  D9            		exx
  380D  2004          		jr	nz,ROUNDUP
  380F  7B            		ld	a,e
  3810  0F            		rrca
  3811  300E          		jr	nc,MULFEND
                      	
  3813                	ROUNDUP:
  3813  13            		inc	de
  3814  7A            		ld	a,d
  3815  B3            		or	e
  3816  2009          		jr	nz,MULFEND
  3818  03            		inc	bc
  3819  78            		ld	a,b
  381A  B1            		or	c
  381B  2004          		jr	nz,MULFEND
                      	;	ld	b,80h
  381D  34            		inc	(hl)
  381E  CAE803        		jp	z,OVERR
                      	
  3821                	MULFEND:
  3821  ED5366FF      		ld	(FAC1),de
  3825  ED4368FF      		ld	(FAC1+2),bc
                      	
                      	;exponent
  3829  3A71FF        		ld	a,(FAC2+4)
  382C  86            		add	a,(hl)
  382D  3808          		jr	c,MULFC
  382F  D680          		sub	80h		;;not 81h
  3831  3009          		jr	nc,MULEXP
                      	
  3833                	MULFZERO:
  3833  F1            		pop	af		;cancel
  3834  C3420C        		jp	SETZERO
                      	
  3837                	MULFC:
  3837  D680          		sub	80h		;;not 81h
  3839                	MULFCHKOV:
  3839  D2E803        		jp	nc,OVERR
  383C                	MULEXP:
  383C  77            		ld	(hl),a		;FAC1+4
  383D  28F4          		jr	z,MULFZERO
  383F  2D            		dec	l		;dec hl,FAC1+3
  3840  F1            		pop	af		;sign
  3841  07            		rlca
  3842  7E            		ld	a,(hl)
  3843  17            		rla
  3844  0F            		rrca
  3845  77            		ld	(hl),a
  3846  C9            		ret
                      	
  3847                	NOROUNDUP:
  3847  C1            		pop	bc
  3848  D1            		pop	de
  3849  E1            		pop	hl
  384A  D9            		exx
  384B  18D4          		jr	MULFEND
                      	
                      	
                      	;check signs and set sign bits of FAC1/2 for MULF/DIVF
                      	;output: a-bit7(xor of FAC1,2 sign), c-flag(1:FAC1=0) z-flag(1:FAC2=0)
                      	;destroy: f,hl
  384D                	MULDIVSGN:
  384D  2171FF        		ld	hl,FAC2+4
  3850  7E            		ld	a,(hl)		;FAC2+4
  3851  B7            		or	a
  3852  C8            		ret	z
  3853  2E6A          		ld	l,FAC1+4-(FAC1+4)/256*256
  3855  7E            		ld	a,(hl)		;FAC1+4
  3856  FE01          		cp	01h
  3858  D8            		ret	c
  3859  2D            		dec	l
  385A  7E            		ld	a,(hl)		;FAC1+3
  385B  CBFE          		set	7,(hl)
  385D  2E70          		ld	l,FAC2+3-(FAC2+3)/256*256
  385F  AE            		xor	(hl)		;FAC2+3, clear c-flag
  3860  CBFE          		set	7,(hl)
  3862  25            		dec	h		;clear z-flag
  3863  C9            		ret
                      	
                      	
                      	;/ operator
  3864                	O_DIV:
  3864  CD9B0B        		call	CHKNUM
                      	;	call	DIVF
                      	;	ret
                      	
                      	
                      	;FAC1 = FAC1 / FAC2
                      	;input: FAC1,FAC2
                      	;output: FAC1
                      	;destroy: FAC2,af,bc,de,hl
  3867                	DIVF:
  3867  CD4D38        		call	MULDIVSGN
  386A  CAF703        		jp	z,DIV0ERR	;FAC2=0
  386D  D8            		ret	c		;FAC1=0
                      	
  386E  210000        		ld	hl,0000h
  3871  54            		ld	d,h
  3872  5D            		ld	e,l
                      	
  3873  F5            		push	af		;sign
  3874  D9            		exx			;
  3875  E5            		push	hl
  3876  D5            		push	de
                      	
  3877  CDB724        		call	CMPINT4
  387A  3007          		jr	nc,DIVFNC
  387C  216AFF        		ld	hl,FAC1+4
  387F  35            		dec	(hl)
  3880  CD383F        		call	SLAINT4
                      	
  3883                	DIVFNC:
  3883  0620          		ld	b,20h
  3885                	DIVFLP:
  3885  3805          		jr	c,DIVFC1
  3887  CDB724        		call	CMPINT4
  388A  381A          		jr	c,DIVFC2
  388C                	DIVFC1:
  388C  2A66FF        		ld	hl,(FAC1)
  388F  ED5B6DFF      		ld	de,(FAC2)
  3893  B7            		or	a
  3894  ED52          		sbc	hl,de
  3896  2266FF        		ld	(FAC1),hl
  3899  2A68FF        		ld	hl,(FAC1+2)
  389C  ED5B6FFF      		ld	de,(FAC2+2)
  38A0  ED52          		sbc	hl,de
  38A2  2268FF        		ld	(FAC1+2),hl
  38A5  B7            		or	a		;reset c-flag
  38A6                	DIVFC2:
  38A6  3F            		ccf
  38A7  D9            		exx			;
  38A8  ED6A          		adc	hl,hl
  38AA  CB13          		rl	e
  38AC  CB12          		rl	d
  38AE  D9            		exx			;
                      	
  38AF  CD383F        		call	SLAINT4
  38B2  10D1          		djnz	DIVFLP
                      	
  38B4  17            		rla			;store c-flag
  38B5  CDB724        		call	CMPINT4		;no change in a
  38B8  D1            		pop	de
  38B9  E1            		pop	hl
  38BA  D9            		exx
                      	
  38BB  1F            		rra
  38BC  3809          		jr	c,DIVFUP
  38BE  07            		rlca
  38BF  381B          		jr	c,DIVFNOUP
                      	
                      	;round to the nearest even
  38C1  2004          		jr	nz,DIVFUP
  38C3  7D            		ld	a,l
  38C4  0F            		rrca
  38C5  3015          		jr	nc,DIVFNOUP
                      	
                      	;round up
  38C7                	DIVFUP:
  38C7  23            		inc	hl
  38C8  7C            		ld	a,h
  38C9  B5            		or	l
  38CA  2010          		jr	nz,DIVFNOUP
  38CC  13            		inc	de
  38CD  7A            		ld	a,d
  38CE  B3            		or	e
  38CF  200B          		jr	nz,DIVFNOUP
  38D1  216AFF        		ld	hl,FAC1+4
  38D4  34            		inc	(hl)
  38D5  CAE803        		jp	z,OVERR
  38D8  EB            		ex	de,hl		;hl<-0
  38D9  110080        		ld	de,8000h
                      	
  38DC                	DIVFNOUP:
  38DC  2266FF        		ld	(FAC1),hl
  38DF  ED5368FF      		ld	(FAC1+2),de
                      	
  38E3  3A71FF        		ld	a,(FAC2+4)
  38E6  47            		ld	b,a
  38E7  216AFF        		ld	hl,FAC1+4
  38EA  7E            		ld	a,(hl)
  38EB  90            		sub	b
  38EC  3806          		jr	c,DIVF1LT2
                      	
                      	;FAC1>=FAC2
  38EE  C681          		add	a,81h
  38F0  3F            		ccf
  38F1  C33938        		jp	MULFCHKOV
                      	
                      	
                      	;FAC1<FAC2
  38F4                	DIVF1LT2:
  38F4  F23338        		jp	p,MULFZERO
  38F7  C681          		add	a,81h
  38F9  C33C38        		jp	MULEXP
                      	
                      	
                      	;continued from CHKSGN
  38FC                	CHKSGN2:
  38FC  3A69FF        		ld	a,(FAC1+3)
  38FF  07            		rlca
  3900  9F            		sbc	a,a		;00h or ffh
  3901  D8            		ret	c		;ffh
  3902  3C            		inc	a
  3903  C9            		ret			;01h
                      	
                      	
                      	;SGN() function
  3904                	F_SGN:
  3904  CD9B0B        		call	CHKNUM
  3907  EF            		rst	CHKSGN
  3908  C8            		ret	z
  3909  3C            		inc	a
  390A  CA530C        		jp	z,SETMNS1
  390D  C36422        		jp	SETPLS1
                      	
                      	
                      	;(de)->(hl):4
                      	;input: de=source address, hl=destination address
                      	;destroy: b,de,hl
  3910                	_DE2HL4:ds	DE2HL4-_DE2HL4
  3913                		org	DE2HL4
                      	
  3913  0604          		ld	b,04h
  3915                	DE2HL4LP:
  3915  1A            		ld	a,(de)
  3916  77            		ld	(hl),a
  3917  13            		inc	de
  3918  23            		inc	hl
  3919  10FA          		djnz	DE2HL4LP
  391B  C9            		ret
                      	
                      	
                      	;ABS() function
  391C                	F_ABS:
  391C  CD9B0B        		call	CHKNUM
  391F                	ABS:
  391F  2169FF        		ld	hl,FAC1+3
  3922  CBBE          		res	7,(hl)
  3924  C9            		ret
                      	
                      	
                      	;push FAC1
                      	;input: FAC1
                      	;output: sp=sp-6
                      	;destroy: af,hl
  3925                	PUSHF1:
  3925  F1            		pop	af		;return address
  3926  2A69FF        		ld	hl,(FAC1+3)
  3929  E5            		push	hl
  392A  2A67FF        		ld	hl,(FAC1+1)
  392D  E5            		push	hl
  392E  2A65FF        		ld	hl,(FAC1-1)
  3931  E5            		push	hl
  3932  F5            		push	af		;
  3933  C9            		ret
                      	
                      	
                      	;pop FAC1
                      	;input: none
                      	;output: FAC1,sp=sp+6
                      	;destroy: af,hl
  3934                	POPF1:
  3934  F1            		pop	af		;return address
  3935  E1            		pop	hl
  3936  2265FF        		ld	(FAC1-1),hl
  3939  E1            		pop	hl
  393A  2267FF        		ld	(FAC1+1),hl
  393D  E1            		pop	hl
  393E  2269FF        		ld	(FAC1+3),hl
  3941  F5            		push	af		;
  3942  C9            		ret
                      	
                      	
                      	;pop FAC2
                      	;input: none
                      	;output: FAC2,sp=sp+6
                      	;destroy: af,hl
  3943                	POPF2:
  3943  F1            		pop	af		;return address
  3944  E1            		pop	hl
  3945  226CFF        		ld	(FAC2-1),hl
  3948  E1            		pop	hl
  3949  226EFF        		ld	(FAC2+1),hl
  394C  E1            		pop	hl
  394D  2270FF        		ld	(FAC2+3),hl
  3950  F5            		push	af		;
  3951  C9            		ret
                      	
                      	
                      	;copy FAC1 to FAC2
                      	;input: FAC1
                      	;output: FAC2
                      	;destroy: hl
  3952                	CPYFAC:
  3952  2A65FF        		ld	hl,(FAC1-1)
  3955  226CFF        		ld	(FAC2-1),hl
  3958  2A67FF        		ld	hl,(FAC1+1)
  395B  226EFF        		ld	(FAC2+1),hl
  395E  2A69FF        		ld	hl,(FAC1+3)
  3961  2270FF        		ld	(FAC2+3),hl
  3964  C9            		ret
                      	
                      	
                      	;exchange FAC1 and FAC2
                      	;input: FAC1,FAC2
                      	;output: FAC1,FAC2
                      	;destroy: hl
  3965                	EXFAC:
  3965  F5            		push	af
  3966  CD1A3C        		call	PUSHF2
  3969  CD5239        		call	CPYFAC
  396C  CD3439        		call	POPF1
  396F  F1            		pop	af
  3970  C9            		ret
                      	
                      	
                      	;print 1-byte integer in device (unsigned)
                      	;input: a
                      	;destroy: af,bc,de,hl
  3971                	_PUTI1:	ds	PUTI1-_PUTI1
  397A                		org	PUTI1
                      	
  397A  2600          		ld	h,00h
  397C  6F            		ld	l,a
  397D  C3A13A        		jp	PUTI2
                      	
                      	
                      	;INT() function
                      	;(round toward minus infinity)
  3980                	F_INT:
  3980  CD9B0B        		call	CHKNUM
  3983                	INT:
  3983  CD5239        		call	CPYFAC
  3986  CDD00C        		call	GETINT
  3989  3A70FF        		ld	a,(FAC2+3)
  398C  07            		rlca
  398D  D0            		ret	nc
  398E  CD193F        		call	CMPF
  3991  C8            		ret	z
  3992  21A60E        		ld	hl,MNSONE
  3995  C38F36        		jp	SETADDF
                      	
                      	
                      	;convert string to float
                      	;input: hl=address
                      	;output: FAC1, hl=next address
                      	;destroy: FAC2, af,bc,de
  3998                	ATOF:
  3998  E5            		push	hl
  3999  CD420C        		call	SETZERO
  399C  E1            		pop	hl
  399D  CD853A        		call	SKIPSPA
  39A0  C8            		ret	z
  39A1  B7            		or	a
  39A2  F8            		ret	m		;reject PLUS_ and MINUS_ in VAL()
  39A3  FE26          		cp	'&'
  39A5  CA3C3A        		jp	z,ATOFHEX
                      	
  39A8  CDF327        		call	ATOIF
                      	
  39AB  CD853A        		call	SKIPSPA
  39AE  C8            		ret	z
  39AF  23            		inc	hl
  39B0  0E00          		ld	c,00h		;after-dot counter
  39B2  FE2E          		cp	'.'
  39B4  280E          		jr	z,ATOFDOT
  39B6  F620          		or	20h
  39B8  FE65          		cp	'e'
  39BA  281D          		jr	z,ATOFEXP
  39BC  2B            		dec	hl
  39BD  C9            		ret
                      	
  39BE                	ATOFLP1:
  39BE  CD1828        		call	CTOF
  39C1  3008          		jr	nc,CHKEXP
  39C3  0C            		inc	c
  39C4                	ATOFDOT:
  39C4  CD853A        		call	SKIPSPA
  39C7  20F5          		jr	nz,ATOFLP1
  39C9  180E          		jr	ATOFEXP
                      	
  39CB                	CHKEXP:
  39CB  CD853A        		call	SKIPSPA
  39CE  2814          		jr	z,ATOFE0
  39D0  F620          		or	20h
  39D2  FE65          		cp	'e'
  39D4  200E          		jr	nz,ATOFE0
  39D6  23            		inc	hl
  39D7  1800          		jr	ATOFEXP
                      	
  39D9                	ATOFEXP:
  39D9  EB            		ex	de,hl
  39DA  CD2539        		call	PUSHF1
  39DD  EB            		ex	de,hl
  39DE  C5            		push	bc		;c=after-dot counter
                      	
  39DF  CDF327        		call	ATOIF
  39E2  180B          		jr	CALCEXP
                      	
  39E4                	ATOFE0:
  39E4  EB            		ex	de,hl
  39E5  CD2539        		call	PUSHF1
  39E8  EB            		ex	de,hl
  39E9  C5            		push	bc		;c=after-dot counter
                      	
  39EA  E5            		push	hl
  39EB  CD420C        		call	SETZERO
  39EE  E1            		pop	hl
                      	
  39EF                	CALCEXP:
  39EF  C1            		pop	bc		;c=after-dot counter
  39F0  E5            		push	hl		;address
  39F1  CD5239        		call	CPYFAC
  39F4  69            		ld	l,c		;c=after-dot counter
  39F5  CD7E0C        		call	I1TOF
  39F8  CD143E        		call	SUBF21
  39FB  D1            		pop	de		;address
                      	
  39FC  CD5239        		call	CPYFAC
  39FF  CD3439        		call	POPF1
  3A02  D5            		push	de		;address
                      	
  3A03  2170FF        		ld	hl,FAC2+3
  3A06  7E            		ld	a,(hl)
  3A07  F5            		push	af		;E sign
  3A08  CBBE          		res	7,(hl)
                      	
  3A0A                	ATOFLP2:
  3A0A  3A71FF        		ld	a,(FAC2+4)
  3A0D  B7            		or	a
  3A0E  2829          		jr	z,ATOFEND	;E0
                      	
  3A10  3A6AFF        		ld	a,(FAC1+4)
  3A13  B7            		or	a
  3A14  2823          		jr	z,ATOFEND	;=0
                      	
  3A16  CD2539        		call	PUSHF1
  3A19  CD530C        		call	SETMNS1
  3A1C  CD9E36        		call	ADDF
  3A1F  CD5239        		call	CPYFAC
  3A22  CD3439        		call	POPF1
                      	
  3A25  C1            		pop	bc		;b=E sign
  3A26  C5            		push	bc
  3A27  CD1A3C        		call	PUSHF2
  3A2A  78            		ld	a,b
  3A2B  07            		rlca
  3A2C  F5            		push	af
  3A2D  D49F37        		call	nc,MULF10
  3A30  F1            		pop	af
  3A31  DC9537        		call	c,DIVF10
  3A34  CD4339        		call	POPF2
                      	
  3A37  18D1          		jr	ATOFLP2
                      	
  3A39                	ATOFEND:
  3A39  F1            		pop	af
  3A3A  E1            		pop	hl		;address
  3A3B  C9            		ret
                      	
  3A3C                	ATOFHEX:
  3A3C  CD453A        		call	HEX
  3A3F  EB            		ex	de,hl
  3A40  CD180D        		call	S2TOF
  3A43  EB            		ex	de,hl
  3A44  C9            		ret
                      	
                      	
                      	;convert hexadecimal string to integer
                      	;input: hl="&" address
                      	;output: de=value, hl=next address
                      	;destroy: af,c,de
  3A45                	HEX:
  3A45  CD843A        		call	SKIPSPAINC
  3A48  CADC03        		jp	z,SNERR
  3A4B  F620          		or	20h
  3A4D  D668          		sub	'h'		;
  3A4F  C2DC03        		jp	nz,SNERR
                      	
  3A52  57            		ld	d,a		;=0
  3A53  5F            		ld	e,a		;=0
  3A54  0E05          		ld	c,05h
  3A56                	HEXLP:
  3A56  D5            		push	de
  3A57  CD843A        		call	SKIPSPAINC
  3A5A  D1            		pop	de
  3A5B  C8            		ret	z
  3A5C  FE93          		cp	DEF_		;93h
  3A5E  281D          		jr	z,HEXDEF
  3A60  D630          		sub	'0'
  3A62  FE0A          		cp	'9'-'0'+1
  3A64  3809          		jr	c,HEX0F
  3A66  F620          		or	20h
  3A68  D631          		sub	'a'-'0'
  3A6A  FE06          		cp	'f'-'a'+1
  3A6C  D0            		ret	nc		;not hex
  3A6D  C60A          		add	a,0ah
  3A6F                	HEX0F:
  3A6F  0D            		dec	c
  3A70  CAE803        		jp	z,OVERR
  3A73  EB            		ex	de,hl
  3A74  29            		add	hl,hl		;*2
  3A75  29            		add	hl,hl		;*4
  3A76  29            		add	hl,hl		;*8
  3A77  29            		add	hl,hl		;*16
  3A78  85            		add	a,l		;no carry
  3A79  6F            		ld	l,a
  3A7A  EB            		ex	de,hl
  3A7B  18D9          		jr	HEXLP
                      	
  3A7D                	HEXDEF:
  3A7D  53            		ld	d,e
  3A7E  1EDE          		ld	e,0deh
  3A80  3E0F          		ld	a,0fh
  3A82  18EB          		jr	HEX0F
                      	
                      	
                      	;increment hl and skip space and check (STREND) for ATOF
  3A84                	SKIPSPAINC:
  3A84  23            		inc	hl
                      	
                      	;skip space and check (STREND) for ATOF
                      	;input: hl=address
                      	;output: a=data, hl=data address, z-flag(1=no data)
                      	;destroy: f,de
  3A85                	SKIPSPA:
  3A85  ED5B27FF      		ld	de,(STREND)
  3A89  13            		inc	de
  3A8A                	SKIPSPALP:
  3A8A  E7            		rst	CPHLDE
  3A8B  C8            		ret	z
  3A8C  7E            		ld	a,(hl)
  3A8D  B7            		or	a
  3A8E  C8            		ret	z
  3A8F  FE20          		cp	' '
  3A91  C0            		ret	nz
  3A92  23            		inc	hl
  3A93  18F5          		jr	SKIPSPALP
                      	
                      	
                      	;print "in *****"
                      	;input: hl
                      	;destory: af,bc,de,hl
  3A95                	_INLNUM:
  3A95                		ds	INLNUM-_INLNUM
  3A99                		org	INLNUM
                      	
  3A99  E5            		push	hl		;
  3A9A  218B03        		ld	hl,ERRIN
  3A9D  CDCF30        		call	PUTS
  3AA0  E1            		pop	hl		;
                      	;	jp	PUTI2
                      	
                      	
                      	;print 2-byte integer in device (unsigned)
                      	;input: hl
                      	;destory: af,bc,de,hl
  3AA1                	_PUTI2:	ds	PUTI2-_PUTI2
  3AA1                		org	PUTI2
                      	
  3AA1  11CE30        		ld	de,PUTSINC
  3AA4  D5            		push	de
                      	;	jp	I2TOA
                      	
                      	
                      	;convert 2-byte integer (unsigned) to string
                      	;input: hl
                      	;output: FAC3, hl=FAC3
                      	;destroy: af,bc,de
  3AA5                	_I2TOA:	ds	I2TOA-_I2TOA
  3AA5                		org	I2TOA
                      	
  3AA5  CD800C        		call	I2TOF
  3AA8  C3AC3A        		jp	FTOA
                      	
                      	
                      	;convert float to string
                      	;input: FAC1
                      	;output: FAC3, hl=FAC3
                      	;destroy: FAC1,FAC2,af,bc,de
  3AAB                	_FTOA:	ds	FTOA-_FTOA
  3AAC                		org	FTOA
                      	
  3AAC  2172FF        		ld	hl,FAC3
  3AAF  3620          		ld	(hl),' '
  3AB1  EF            		rst	CHKSGN
  3AB2  CA603B        		jp	z,FTOAZERO	;a=0
  3AB5  3D            		dec	a
  3AB6  2802          		jr	z,FTOAPLS	;if FAC1>0
  3AB8  362D          		ld	(hl),'-'
  3ABA                	FTOAPLS:
  3ABA  CD1F39        		call	ABS
  3ABD  21693B        		ld	hl,E9
  3AC0  CD163F        		call	SETCMPF
  3AC3  3071          		jr	nc,LARGE	;FAC1 >= 1e9
  3AC5  217D3B        		ld	hl,EM2
  3AC8  CD163F        		call	SETCMPF
  3ACB  3856          		jr	c,SMALL		;FAC1 < 1e-2
                      	
  3ACD                	FTOA2:
  3ACD  060A          		ld	b,0ah
  3ACF                	FTOALP1:
  3ACF  C5            		push	bc
  3AD0  216E3B        		ld	hl,E8
  3AD3  CD163F        		call	SETCMPF
  3AD6  3007          		jr	nc,FTOAOK
  3AD8  CD9F37        		call	MULF10
  3ADB  C1            		pop	bc
  3ADC  10F1          		djnz	FTOALP1
  3ADE  C5            		push	bc
                      	
  3ADF                	FTOAOK:
  3ADF  3A6AFF        		ld	a,(FAC1+4)
  3AE2  D697          		sub	97h
  3AE4  47            		ld	b,a
  3AE5  3A66FF        		ld	a,(FAC1)
  3AE8                	FTOALP2:
  3AE8  07            		rlca
  3AE9  10FD          		djnz	FTOALP2
  3AEB  DC8C36        		call	c,INCF1		;round up
                      	
  3AEE  CDEB24        		call	FTOI4
                      	
  3AF1  21823B        		ld	hl,INTE8
  3AF4  1173FF        		ld	de,FAC3+1
  3AF7  C1            		pop	bc
  3AF8  48            		ld	c,b		;
  3AF9  05            		dec	b
  3AFA                	FTOALP3:
  3AFA  05            		dec	b
  3AFB  FA073B        		jp	m,FTOADOT
  3AFE  CD8B24        		call	DIVINT4
  3B01  C630          		add	a,'0'
  3B03  12            		ld	(de),a
  3B04  13            		inc	de
  3B05  18F3          		jr	FTOALP3
                      	
  3B07                	FTOADOT:
  3B07  CDDE24        		call	CHKINT4
  3B0A  2812          		jr	z,FTOAEND
                      	
  3B0C  3E2E          		ld	a,'.'
  3B0E  12            		ld	(de),a
  3B0F  13            		inc	de
                      	
  3B10  79            		ld	a,c		;
  3B11  B7            		or	a
  3B12                	FTOALP4:
  3B12  C48B24        		call	nz,DIVINT4
  3B15  C630          		add	a,'0'
  3B17  12            		ld	(de),a
  3B18  13            		inc	de
  3B19  CDDE24        		call	CHKINT4
  3B1C  20F4          		jr	nz,FTOALP4
                      	
  3B1E                	FTOAEND:
  3B1E  12            		ld	(de),a		;a=0
  3B1F  2172FF        		ld	hl,FAC3
  3B22  C9            		ret
                      	
  3B23                	SMALL:
  3B23  012D00        		ld	bc,002dh	;c='-'
  3B26                	SMALLLP:
  3B26  04            		inc	b
  3B27  C5            		push	bc
  3B28  CD9F37        		call	MULF10
  3B2B  21783B        		ld	hl,E0
  3B2E  CD163F        		call	SETCMPF
  3B31  C1            		pop	bc
  3B32  38F2          		jr	c,SMALLLP
  3B34  1811          		jr	LARSMA
                      	
  3B36                	LARGE:
  3B36  012B00        		ld	bc,002bh	;c='+'
  3B39                	LARGELP:
  3B39  04            		inc	b
  3B3A  C5            		push	bc
  3B3B  CD9537        		call	DIVF10
  3B3E  21733B        		ld	hl,E2
  3B41  CD163F        		call	SETCMPF
  3B44  C1            		pop	bc
  3B45  30F2          		jr	nc,LARGELP
                      	
  3B47                	LARSMA:
  3B47  C5            		push	bc		;
  3B48  CDCD3A        		call	FTOA2
                      	
  3B4B                	LARLP2:
  3B4B  23            		inc	hl
  3B4C  7E            		ld	a,(hl)
  3B4D  B7            		or	a
  3B4E  20FB          		jr	nz,LARLP2
                      	
  3B50  3645          		ld	(hl),'E'
  3B52  23            		inc	hl
  3B53  C1            		pop	bc		;
  3B54  78            		ld	a,b
  3B55  71            		ld	(hl),c
  3B56  23            		inc	hl
  3B57  010A2F        		ld	bc,2f0ah	;b='0'-1, c=10
  3B5A                	LARLP3:
  3B5A  04            		inc	b
  3B5B  91            		sub	c
  3B5C  30FC          		jr	nc,LARLP3
  3B5E  81            		add	a,c
  3B5F  70            		ld	(hl),b
                      	
  3B60                	FTOAZERO:
  3B60  23            		inc	hl
  3B61  C630          		add	a,'0'
  3B63  77            		ld	(hl),a
  3B64  23            		inc	hl
  3B65  EB            		ex	de,hl
  3B66  AF            		xor	a
  3B67  18B5          		jr	FTOAEND
                      	
                      	
                      	;999999999.5
  3B69                	E9:
  3B69  FE276B6E9E    		db	0feh, 27h, 6bh, 6eh, 9eh
                      	
                      	;99999999.95
  3B6E                	E8:
  3B6E  FE1FBC3E9B    		db	0feh, 1fh, 0bch, 3eh, 9bh
                      	
                      	;9.999999995
  3B73                	E2:
  3B73  FFFFFF1F84    		db	0ffh, 0ffh, 0ffh, 1fh, 84h
                      	
                      	;0.9999999995
  3B78                	E0:
  3B78  FEFFFF7F80    		db	0feh, 0ffh, 0ffh, 7fh, 80h
                      	
                      	;0.00999999995
  3B7D                	EM2:
  3B7D  3C0AD7237A    		db	3ch, 0ah, 0d7h, 23h, 7ah
                      	
  3B82                	INTE8:
  3B82  00E1F505      		db	00h,0e1h,0f5h, 05h	;10^8
  3B86  80969800      		db	80h, 96h, 98h, 00h	;10^7
  3B8A  40420F00      		db	40h, 42h, 0fh, 00h	;10^6
  3B8E  A0860100      		db	0a0h,86h, 01h, 00h	;10^5
  3B92  10270000      		db	10h, 27h, 00h, 00h	;10^4
  3B96  E8030000      		db	0e8h,03h, 00h, 00h	;10^3
  3B9A  64000000      		db	64h, 00h, 00h, 00h	;10^2
  3B9E  0A000000      		db	0ah, 00h, 00h, 00h	;10^1
  3BA2  01000000      		db	01h, 00h, 00h, 00h	;10^0
                      	
                      	
                      	;RND() function
  3BA6                	_F_RND:	ds	RNDPLS-9-_F_RND
  3BA6                		org	RNDPLS-9
  3BA6                	F_RND:
  3BA6  CD9B0B        		call	CHKNUM
  3BA9  EF            		rst	CHKSGN
  3BAA  2815          		jr	z,RND0		;rnd(0)
  3BAC  3C            		inc	a
  3BAD  2806          		jr	z,RNDMNS	;rnd(-x)
                      	
                      	;rnd(+x)
  3BAF                	_RNDPLS:ds	RNDPLS-_RNDPLS
  3BAF                		org	RNDPLS
                      	
  3BAF  2151FA        		ld	hl,RSEED
  3BB2  CD450C        		call	SETF1
  3BB5                	RNDMNS:
  3BB5  CDCC24        		call	DECINT4
  3BB8  21D53B        		ld	hl,RNDFCT
  3BBB  CD4E0C        		call	SETF2
  3BBE  CDD93B        		call	MULRND
  3BC1                	RND0:
  3BC1  2A51FA        		ld	hl,(RSEED)
  3BC4  ED5B53FA      		ld	de,(RSEED+2)
  3BC8  CD0F25        		call	I4TOF
  3BCB  216AFF        		ld	hl,FAC1+4
  3BCE  7E            		ld	a,(hl)
  3BCF  B7            		or	a
  3BD0  C8            		ret	z
  3BD1  D620          		sub	20h
  3BD3  77            		ld	(hl),a
  3BD4  C9            		ret
                      	
                      	
  3BD5                	RNDFCT:
  3BD5  65520F00      		db	65h, 52h, 0fh, 00h
                      	
                      	
                      	;RSEED = (FAC1 (integer) * FAC2 (integer)) & ff,ff,ff,ff,ffh
                      	; for RND() function
                      	;input: FAC1,FAC2 (not zero)
                      	;output: RSEED
                      	;destroy: FAC1,af,bc,de,hl
  3BD9                	MULRND:
  3BD9  21AB0E        		ld	hl,ZERO
  3BDC  1151FA        		ld	de,RSEED
  3BDF  CD480C        		call	SETF
  3BE2  AF            		xor	a
  3BE3  326AFF        		ld	(FAC1+4),a
                      	
  3BE6  D9            		exx			;
  3BE7  E5            		push	hl
  3BE8  D5            		push	de
  3BE9  2A6DFF        		ld	hl,(FAC2)
  3BEC  ED5B6FFF      		ld	de,(FAC2+2)
  3BF0  D9            		exx			;
                      	
  3BF1  0E20          		ld	c,20h
  3BF3                	MULRLP1:
  3BF3  D9            		exx			;
  3BF4  CB3A          		srl	d
  3BF6  CB1B          		rr	e
  3BF8  CB1C          		rr	h
  3BFA  CB1D          		rr	l
  3BFC  D9            		exx			;
  3BFD  3010          		jr	nc,MULRNC
                      	
  3BFF  1166FF        		ld	de,FAC1
  3C02  2151FA        		ld	hl,RSEED
  3C05  B7            		or	a
  3C06  0604          		ld	b,04h
  3C08                	MULRLP2:
  3C08  1A            		ld	a,(de)
  3C09  8E            		adc	a,(hl)
  3C0A  77            		ld	(hl),a
  3C0B  1C            		inc	e		;inc de
  3C0C  2C            		inc	l		;inc hl
  3C0D  10F9          		djnz	MULRLP2
                      	
  3C0F                	MULRNC:
  3C0F  CD383F        		call	SLAINT4
  3C12  0D            		dec	c
  3C13  20DE          		jr	nz,MULRLP1
                      	
  3C15  D9            		exx			;
  3C16  D1            		pop	de
  3C17  E1            		pop	hl
  3C18  D9            		exx			;
  3C19  C9            		ret
                      	
                      	
                      	;push FAC2
                      	;input: FAC2
                      	;output: sp=sp-6
                      	;destroy: af,hl
  3C1A                	PUSHF2:
  3C1A  F1            		pop	af		;return address
  3C1B  2A70FF        		ld	hl,(FAC2+3)
  3C1E  E5            		push	hl
  3C1F  2A6EFF        		ld	hl,(FAC2+1)
  3C22  E5            		push	hl
  3C23  2A6CFF        		ld	hl,(FAC2-1)
  3C26  E5            		push	hl
  3C27  F5            		push	af		;
  3C28  C9            		ret
                      	
                      	
                      	;EXP() function
                      	;exp(x)=2^n * e^a, n=[x/log2], a=x-n*log2
  3C29                	F_EXP:
  3C29  CD9B0B        		call	CHKNUM
  3C2C                	EXP:
  3C2C  CD2539        		call	PUSHF1		;x
  3C2F  21993C        		ld	hl,LOG2
  3C32  CD4E0C        		call	SETF2
  3C35  CD6738        		call	DIVF		;x/log2
                      	
  3C38  2A69FF        		ld	hl,(FAC1+3)
  3C3B  7C            		ld	a,h		;(FAC1+4)
  3C3C  FE89          		cp	89h
  3C3E  3050          		jr	nc,EXPLARGE	;|x/log2|>=256
                      	
  3C40  CD8339        		call	INT		;n=[x/log2]
  3C43  CD9F0C        		call	FTOI
  3C46  D5            		push	de		;n
  3C47  21993C        		ld	hl,LOG2
  3C4A  CDA237        		call	SETMULF		;n*log2
  3C4D  D1            		pop	de		;n
  3C4E  CD4339        		call	POPF2		;x
  3C51  D5            		push	de		;n
  3C52  CD143E        		call	SUBF21		;a=x-n*log2
                      	
                      	;1+a(1+a/2(1+a/3(1+...(1+a/10))))))))))
  3C55  CD5239        		call	CPYFAC
  3C58  CD6422        		call	SETPLS1
                      	
  3C5B  0E0A          		ld	c,0ah
  3C5D                	EXPLP:
  3C5D  CD1A3C        		call	PUSHF2		;a
  3C60  C5            		push	bc
  3C61  CDAF37        		call	MULF		;a*y
  3C64  CD5239        		call	CPYFAC
  3C67  E1            		pop	hl
  3C68  E5            		push	hl
  3C69  CD7E0C        		call	I1TOF
  3C6C  CD6539        		call	EXFAC
  3C6F  CD6738        		call	DIVF		;a*y/b
  3C72  CD8C36        		call	INCF1		;a*y/b+1
  3C75  C1            		pop	bc
  3C76  CD4339        		call	POPF2		;a
  3C79  0D            		dec	c
  3C7A  20E1          		jr	nz,EXPLP
                      	
  3C7C  D1            		pop	de		;-256<=n<=255
                      	;	ld	a,(FAC1+4)	;=81h?
  3C7D  3E81          		ld	a,81h
  3C7F  83            		add	a,e
  3C80  326AFF        		ld	(FAC1+4),a	;exponent
  3C83  CB7A          		bit	7,d
  3C85  2004          		jr	nz,EXPNZ
  3C87  D0            		ret	nc		;0<=n<=126
  3C88                	EXPOV:
  3C88  C3E803        		jp	OVERR		;127<=n<=255
  3C8B                	EXPNZ:
  3C8B  3D            		dec	a
  3C8C  F0            		ret	p		;-128<=n<=-1
  3C8D                	EXPZERO:
  3C8D  C3420C        		jp	SETZERO		;-256<=n<=-129
                      	
  3C90                	EXPLARGE:
  3C90  CB7D          		bit	7,l		;(FAC1+3)
  3C92  28F4          		jr	z,EXPOV		;x/log2>=256
  3C94  CD3439        		call	POPF1
  3C97  18F4          		jr	EXPZERO		;x/log2<=-256
                      	
                      	;log(2)
  3C99                	LOG2:
  3C99  F817723180    		db	0f8h, 17h, 72h, 31h, 80h
                      	
                      	
                      	;LOG() function
                      	;log(x)=log(a*2^n)=log(a)+n*log(2)
                      	;a'=(a-1)/(a+1)
                      	;log(a)=2*(a'+a'^3/3+a'^5/5+...)=2a'(1+1/3*a'^2(1+3/5*a'^2(...(1+19/21*a'^2))))))))))
  3C9E                	F_LOG:
  3C9E  CD9B0B        		call	CHKNUM
  3CA1                	LOG:
  3CA1  EF            		rst	CHKSGN
  3CA2  3D            		dec	a
  3CA3  C2E503        		jp	nz,FCERR	;x<=0
                      	
  3CA6  216AFF        		ld	hl,FAC1+4
  3CA9  7E            		ld	a,(hl)
  3CAA  D681          		sub	81h
  3CAC  F5            		push	af		;n
  3CAD  3681          		ld	(hl),81h	;a
  3CAF  CD2539        		call	PUSHF1		;a
  3CB2  CD8C36        		call	INCF1
  3CB5  CD4339        		call	POPF2		;a
  3CB8  CD2539        		call	PUSHF1		;a+1
  3CBB  CD530C        		call	SETMNS1
  3CBE  CD9E36        		call	ADDF		;a-1
  3CC1  CD4339        		call	POPF2		;a+1
  3CC4  CD6738        		call	DIVF		;a'=(a-1)/(a+1)
  3CC7  CD2539        		call	PUSHF1		;a'
  3CCA  CD5239        		call	CPYFAC
  3CCD  CDAF37        		call	MULF		;a'^2
  3CD0  CD5239        		call	CPYFAC		;a'^2
  3CD3  CD6422        		call	SETPLS1		;y0
                      	
  3CD6  0E12          		ld	c,12h
  3CD8                	LOGLP:
  3CD8  CD1A3C        		call	PUSHF2		;a'^2
  3CDB  C5            		push	bc
  3CDC  CDAF37        		call	MULF		;y*a'^2
  3CDF  CD5239        		call	CPYFAC
  3CE2  E1            		pop	hl		;l=c
  3CE3  E5            		push	hl
  3CE4  2C            		inc	l
  3CE5  CD7E0C        		call	I1TOF
  3CE8  CD6539        		call	EXFAC
  3CEB  CD6738        		call	DIVF		;y*a'^2/(c+1)
  3CEE  CD5239        		call	CPYFAC
  3CF1  E1            		pop	hl
  3CF2  2D            		dec	l
  3CF3  E5            		push	hl
  3CF4  CD7E0C        		call	I1TOF		;c-1
  3CF7  CDAF37        		call	MULF		;y*a'^2*(c-1)/(c+1)
  3CFA  CD8C36        		call	INCF1		;y=1+y*a'^2*(c-1)/(c+1)
  3CFD  C1            		pop	bc
  3CFE  CD4339        		call	POPF2		;a'^2
  3D01  0D            		dec	c
  3D02  20D4          		jr	nz,LOGLP
                      	
  3D04  CD4339        		call	POPF2		;a'
  3D07  CDAF37        		call	MULF		;a'*y
  3D0A  216AFF        		ld	hl,FAC1+4
  3D0D  7E            		ld	a,(hl)
  3D0E  B7            		or	a
  3D0F  2804          		jr	z,LOGZ
  3D11  34            		inc	(hl)		;2*a'*y
  3D12  CAE803        		jp	z,OVERR
  3D15                	LOGZ:
  3D15  C1            		pop	bc		;b=n
  3D16  CD2539        		call	PUSHF1		;2*a'*y
  3D19  CD110D        		call	S1TOF
  3D1C  21993C        		ld	hl,LOG2
  3D1F  CDA237        		call	SETMULF		;n*log(2)
  3D22  CD4339        		call	POPF2		;2*a'*y
  3D25  C39E36        		jp	ADDF		;n*log(2)+2*a'*y
                      	
                      	
                      	;^ operator
  3D28                	O_POW:
  3D28  CD9B0B        		call	CHKNUM
                      	
  3D2B  2A70FF        		ld	hl,(FAC2+3)
  3D2E  7C            		ld	a,h		;(FAC2+4)
  3D2F  B7            		or	a
  3D30  CA6422        		jp	z,SETPLS1	;x^0
                      	
  3D33  EF            		rst	CHKSGN
  3D34  2812          		jr	z,POWZERO
  3D36  3C            		inc	a
  3D37  2815          		jr	z,POWNEG
                      	
                      	;x^y=exp(ylog(x))
  3D39                	POWPOS:
  3D39  CD1A3C        		call	PUSHF2		;y
  3D3C  CDA13C        		call	LOG		;log(x)
  3D3F  CD4339        		call	POPF2		;y
  3D42  CDAF37        		call	MULF		;ylog(x)
  3D45  C32C3C        		jp	EXP
                      	
                      	;0^y
  3D48                	POWZERO:
  3D48  7D            		ld	a,l		;(FAC2+3)
  3D49  07            		rlca
  3D4A  D0            		ret	nc		;0^(positive)
  3D4B  C3F703        		jp	DIV0ERR		;0^(negative)
                      	
                      	;(negative)^y
  3D4E                	POWNEG:
  3D4E  7C            		ld	a,h		;(FAC2+4)
  3D4F  FEA1          		cp	0a1h
  3D51  D2E503        		jp	nc,FCERR
                      	
  3D54  CD2539        		call	PUSHF1
  3D57  CD1A3C        		call	PUSHF2
  3D5A  CD3439        		call	POPF1
                      	
  3D5D  CDD00C        		call	GETINT
  3D60  CD193F        		call	CMPF
  3D63  C2E503        		jp	nz,FCERR	;y=not integer
  3D66  CDEB24        		call	FTOI4
  3D69  3A66FF        		ld	a,(FAC1)	;even/odd
  3D6C  47            		ld	b,a
                      	
  3D6D  CD3439        		call	POPF1
  3D70  C5            		push	bc		;
  3D71  CD1F39        		call	ABS
  3D74  CD393D        		call	POWPOS
  3D77  F1            		pop	af		;
  3D78  0F            		rrca
  3D79  D0            		ret	nc		;y=even
  3D7A  C32D0D        		jp	NEGABSNZ	;y=odd
                      	
                      	
                      	;COS() function
                      	;cos(x)=sin(pi/2-|x|)
  3D7D                	F_COS:
  3D7D  CD9B0B        		call	CHKNUM
  3D80                	COS:
  3D80  CD280D        		call	NEGABS
  3D83  218B3D        		ld	hl,PIDIV2
  3D86  CD8F36        		call	SETADDF		;pi/2-|x|
  3D89  1808          		jr	SIN
                      	
                      	;pi/2
  3D8B                	PIDIV2:
  3D8B  A2DA0F4981    		db	0a2h, 0dah, 0fh, 49h, 81h
                      	
                      	
                      	;SIN() function
                      	;x-x^3/3!+x^5/5!-...=x(1-x^2/(2*3)(1-x^2/(4*5)(...(1-x^2/(12*13)))))))))))
  3D90                	F_SIN:
  3D90  CD9B0B        		call	CHKNUM
  3D93                	SIN:
  3D93  CD2539        		call	PUSHF1		;x
  3D96  211A3E        		ld	hl,PI2
  3D99  CD4E0C        		call	SETF2
  3D9C  CD6738        		call	DIVF		;x/2pi
  3D9F  CDD00C        		call	GETINT		;int(x/2pi)
  3DA2  211A3E        		ld	hl,PI2
  3DA5  CDA237        		call	SETMULF		;int(x/2pi)*2pi
  3DA8  CD4339        		call	POPF2		;x
  3DAB  CD143E        		call	SUBF21		;x'=x-int(x/2pi)*2pi
                      	
  3DAE  CDFF3D        		call	SINRANGE	;[-pi,+pi]
  3DB1  CDFF3D        		call	SINRANGE	;[-pi/2,+pi/2]
                      	
  3DB4  CD2539        		call	PUSHF1		;x'
  3DB7  CD5239        		call	CPYFAC
  3DBA  CDAF37        		call	MULF		;x'^2
                      	
  3DBD  CD5239        		call	CPYFAC
  3DC0  CD6422        		call	SETPLS1		;y=1
                      	
  3DC3  060C          		ld	b,0ch
  3DC5                	SINLP:
  3DC5  CD1A3C        		call	PUSHF2		;x'^2
  3DC8  C5            		push	bc
  3DC9  CDAF37        		call	MULF		;x'^2*y
  3DCC  C1            		pop	bc
  3DCD  C5            		push	bc
  3DCE  CD2539        		call	PUSHF1		;x'^2*y
                      	
  3DD1  78            		ld	a,b
  3DD2  04            		inc	b
  3DD3  CDE821        		call	MULINT1		;hl=b(b+1)
  3DD6  CD800C        		call	I2TOF		;hl->FAC1
                      	
  3DD9  CD5239        		call	CPYFAC
  3DDC  CD3439        		call	POPF1		;x'^2*y
  3DDF  CD6738        		call	DIVF		;x'^2/b/(b+1)*y
  3DE2  CD280D        		call	NEGABS		;-x'^2/b/(b+1)*y (y>0)
  3DE5  CD8C36        		call	INCF1		;y=1-x'^2/b/(b+1)*y
                      	
  3DE8  C1            		pop	bc
  3DE9  CD4339        		call	POPF2		;x'^2
  3DEC  05            		dec	b
  3DED  10D6          		djnz	SINLP
                      	
  3DEF  CD4339        		call	POPF2		;x'
  3DF2  CDAF37        		call	MULF
  3DF5  3A6AFF        		ld	a,(FAC1+4)
  3DF8  D681          		sub	81h
  3DFA  C0            		ret	nz
                      	
                      	;if |result|>=1
  3DFB  3266FF        		ld	(FAC1),a	;=0
  3DFE  C9            		ret
                      	
                      	;[-pi/2,+pi/2]
  3DFF                	SINRANGE:
  3DFF  218B3D        		ld	hl,PIDIV2	;pi/2
  3E02  CD163F        		call	SETCMPF
  3E05  3009          		jr	nc,RANGENC
  3E07  2170FF        		ld	hl,FAC2+3
  3E0A  CBFE          		set	7,(hl)		;-pi/2
  3E0C  CD193F        		call	CMPF
  3E0F  D0            		ret	nc
  3E10                	RANGENC:
  3E10  2171FF        		ld	hl,FAC2+4
  3E13  34            		inc	(hl)		;+-pi
                      	
                      	;FAC1=FAC2-FAC1
  3E14                	SUBF21:
  3E14  2169FF        		ld	hl,FAC1+3
  3E17  C39A36        		jp	CHGSGNADD
                      	
                      	;pi*2
  3E1A                	PI2:
  3E1A  A2DA0F4983    		db	0a2h, 0dah, 0fh, 49h, 83h
                      	
                      	
                      	;SQR() function
                      	;y_n+1=(y_n + x/y_n)/2
  3E1F                	F_SQR:
  3E1F  CD9B0B        		call	CHKNUM
  3E22  EF            		rst	CHKSGN
  3E23  C8            		ret	z		;sqr(0)=0
  3E24  3C            		inc	a
  3E25  CAE503        		jp	z,FCERR		;sqr(-x)
                      	
  3E28  CD2539        		call	PUSHF1
  3E2B  216AFF        		ld	hl,FAC1+4
  3E2E  7E            		ld	a,(hl)
  3E2F  D681          		sub	81h
  3E31  1F            		rra			;=sra a,c-flag=bit7
  3E32  C681          		add	a,81h
  3E34  77            		ld	(hl),a		;exponent of y_0 = (exponent of x)/2
                      	
  3E35  0605          		ld	b,05h
  3E37                	SQRLP:
  3E37  CD5239        		call	CPYFAC
  3E3A  CD3439        		call	POPF1		;x
  3E3D  CD2539        		call	PUSHF1		;x
  3E40  C5            		push	bc
  3E41  CD1A3C        		call	PUSHF2		;;y
  3E44  CD6738        		call	DIVF		;x/y
  3E47  CD4339        		call	POPF2		;;y
  3E4A  CD9E36        		call	ADDF		;x/y+y
  3E4D  216AFF        		ld	hl,FAC1+4
  3E50  35            		dec	(hl)		;y=(x/y+y)/2
  3E51  C1            		pop	bc
  3E52  10E3          		djnz	SQRLP
  3E54  CD4339        		call	POPF2
  3E57  C9            		ret
                      	
                      	
                      	;TAN() function
                      	;tan(x)=sin(x)/cos(x)
  3E58                	F_TAN:
  3E58  CD9B0B        		call	CHKNUM
  3E5B  CD2539        		call	PUSHF1		;x
  3E5E  CD803D        		call	COS		;cos(x)
  3E61  CD5239        		call	CPYFAC
  3E64  CD3439        		call	POPF1		;x
  3E67  CD1A3C        		call	PUSHF2		;cos(x)
  3E6A  CD933D        		call	SIN		;sin(x)
  3E6D  CD4339        		call	POPF2		;cos(x)
  3E70  C36738        		jp	DIVF		;sin(x)/cos(x)
                      	
                      	
                      	;input: bc=graphic X, de=graphic Y
                      	;output: a=color
                      	;destroy: f,bc,de,hl
  3E73                	POINT:
  3E73  CDAC15        		call	GXY2AD
                      	;	jp	GETCOLRMAIN
                      	
                      	;input: (fdb3h-fdb4h)=attribute address, (fdb2h)=bit
                      	;output: a=color
                      	;destroy: f,hl
  3E76                	GETCOLRMAIN:
  3E76  2AB3FD        		ld	hl,(VRAMAD)
  3E79  3A92FD        		ld	a,(SCREEN1)
  3E7C  CB3F          		srl	a
  3E7E  3AB2FD        		ld	a,(VRAMBIT)
  3E81  2014          		jr	nz,GETCOLR34
  3E83  3803          		jr	c,GETCOLR2
                      	
                      	;screen mode 1
  3E85                	GETCOLR1:
  3E85  A6            		and	(hl)
  3E86  3C            		inc	a
  3E87  C9            		ret
                      	
                      	;screen mode 2
  3E88                	GETCOLR2:
  3E88  A6            		and	(hl)
  3E89  C8            		ret	z
                      	
  3E8A  7E            		ld	a,(hl)		;bit7-6
  3E8B  07            		rlca
  3E8C  CB8C          		res	1,h
  3E8E  AE            		xor	(hl)		;bit1
  3E8F  E681          		and	81h
  3E91  AE            		xor	(hl)
  3E92  07            		rlca
  3E93  E607          		and	07h
  3E95  3C            		inc	a
  3E96  C9            		ret
                      	
                      	;screen mode 3
                      	;screen mode 4
  3E97                	GETCOLR34:
  3E97  C5            		push	bc
  3E98  47            		ld	b,a
  3E99  A6            		and	(hl)
  3E9A  07            		rlca
  3E9B                	GETCOLRLP:
  3E9B  0F            		rrca
  3E9C  CB38          		srl	b
  3E9E  30FB          		jr	nc,GETCOLRLP
  3EA0  C1            		pop	bc
  3EA1  C8            		ret	z		;screen mode 4
  3EA2  3C            		inc	a		;screen mode 3
  3EA3  C9            		ret
                      	
                      	
                      	;SCREEN() function
                      	;not called but jumped
  3EA4                	F_SCRN:
  3EA4  CDB50B        		call	CHKLPAR
  3EA7  CDE40D        		call	INT1ARG
  3EAA  F5            		push	af		;
  3EAB  7E            		ld	a,(hl)
  3EAC  FE2C          		cp	','
  3EAE  C2DC03        		jp	nz,SNERR
  3EB1  CDE30D        		call	INT1INC
  3EB4  CDC40B        		call	CHKRPAR
  3EB7  E1            		pop	hl		;
  3EB8  6B            		ld	l,e
  3EB9  24            		inc	h
  3EBA  2C            		inc	l
  3EBB  CDCD11        		call	XY2AD
  3EBE  6E            		ld	l,(hl)
  3EBF  CD7E0C        		call	I1TOF
  3EC2  C36218        		jp	FNCRTN
                      	
                      	
                      	;FN() function
                      	;not called but jumped
  3EC5                	F_FN:
  3EC5  CD8F33        		call	CHKVAR
  3EC8  E5            		push	hl		;program address
  3EC9  CBF8          		set	7,b
  3ECB  CDC133        		call	SRCHVAR
  3ECE  DA0C04        		jp	c,UFERR
  3ED1  E1            		pop	hl		;program address
  3ED2  D5            		push	de		;function address
  3ED3  CD860B        		call	FNCNUM
  3ED6  C1            		pop	bc		;function address
  3ED7  E5            		push	hl		;program address
                      	
                      	;push old FN() argument
  3ED8  2A63FF        		ld	hl,(FNARG+3)
  3EDB  E5            		push	hl
  3EDC  2A61FF        		ld	hl,(FNARG+1)
  3EDF  E5            		push	hl
  3EE0  3A60FF        		ld	a,(FNARG)
  3EE3  F5            		push	af
  3EE4  2A5EFF        		ld	hl,(FNPAR)
  3EE7  E5            		push	hl		;old FN() parameter
                      	
  3EE8  C5            		push	bc		;function address
  3EE9  2166FF        		ld	hl,FAC1
  3EEC  1160FF        		ld	de,FNARG
  3EEF  CD480C        		call	SETF
  3EF2  E1            		pop	hl		;function address
                      	
  3EF3  5E            		ld	e,(hl)
  3EF4  23            		inc	hl
  3EF5  56            		ld	d,(hl)
  3EF6  23            		inc	hl
  3EF7  7E            		ld	a,(hl)
  3EF8  23            		inc	hl
  3EF9  66            		ld	h,(hl)
  3EFA  6F            		ld	l,a
  3EFB  225EFF        		ld	(FNPAR),hl
                      	
  3EFE  EB            		ex	de,hl
  3EFF  CD2C17        		call	ARG
                      	
  3F02  E1            		pop	hl		;old FN() parameter
  3F03  225EFF        		ld	(FNPAR),hl
                      	
                      	;pop old FN() argument
  3F06  F1            		pop	af
  3F07  3260FF        		ld	(FNARG),a
  3F0A  E1            		pop	hl
  3F0B  2261FF        		ld	(FNARG+1),hl
  3F0E  E1            		pop	hl
  3F0F  2263FF        		ld	(FNARG+3),hl
  3F12  E1            		pop	hl		;program address
  3F13  C36518        		jp	CLRSTRD
                      	
                      	
                      	;set FAC2 and compare
                      	;input: FAC1,hl=float address
                      	;output: c-flag, z-flag, FAC2
                      	;destroy: af,bc,de,hl
  3F16                	SETCMPF:
  3F16  CD4E0C        		call	SETF2
                      	;	jp	CMPF
                      	
                      	
                      	;compare FAC2 and FAC1
                      	;input: FAC1,FAC2
                      	;output: c-flag,z-flag
                      	;destroy: af,b,de,hl
  3F19                	CMPF:
  3F19  1169FF        		ld	de,FAC1+3
  3F1C  2170FF        		ld	hl,FAC2+3
  3F1F  B4            		or	h		;h>0, reset z-flag
  3F20  7E            		ld	a,(hl)
  3F21  07            		rlca
  3F22  1A            		ld	a,(de)
  3F23  380E          		jr	c,CMPFNEG
  3F25  07            		rlca
  3F26  D8            		ret	c
                      	
  3F27                	CMPFPOS:
  3F27  13            		inc	de
  3F28  23            		inc	hl
  3F29  0605          		ld	b,05h
  3F2B                	CMPFLP:
  3F2B  1A            		ld	a,(de)
  3F2C  BE            		cp	(hl)
  3F2D  C0            		ret	nz
  3F2E  2B            		dec	hl
  3F2F  1B            		dec	de
  3F30  10F9          		djnz	CMPFLP
  3F32  C9            		ret
                      	
  3F33                	CMPFNEG:
  3F33  07            		rlca
  3F34  D0            		ret	nc
                      	
                      	;FAC1<0, FAC2<0
  3F35  EB            		ex	de,hl
  3F36  18EF          		jr	CMPFPOS
                      	
                      	
                      	;shift left arithmetic for FAC1
                      	;input: FAC1
                      	;output: FAC1,c-flag
                      	;destroy: f,hl
  3F38                	SLAINT4:
  3F38  2166FF        		ld	hl,FAC1
  3F3B  CB26          		sla	(hl)
  3F3D  23            		inc	hl
  3F3E  CB16          		rl	(hl)
  3F40  23            		inc	hl
  3F41  CB16          		rl	(hl)
  3F43  23            		inc	hl
  3F44  CB16          		rl	(hl)
  3F46  C9            		ret
                      	
                      	
                      	;jump subroutine in table
                      	;input: de=table address, a=data(00h-7fh or 80h-ffh)
                      	;output: de=jump address, a=(hl)
                      	;destroy: f
  3F47                	JPTBL:
  3F47  EB            		ex	de,hl
  3F48  87            		add	a,a
  3F49  85            		add	a,l
  3F4A  6F            		ld	l,a
  3F4B  3001          		jr	nc,JPTBLNC
  3F4D  24            		inc	h
  3F4E                	JPTBLNC:
  3F4E  7E            		ld	a,(hl)
  3F4F  23            		inc	hl
  3F50  66            		ld	h,(hl)
  3F51  6F            		ld	l,a
                      	
  3F52  EB            		ex	de,hl
  3F53  7E            		ld	a,(hl)		;for ALIEN IN MAZE
  3F54  D5            		push	de
  3F55  C9            		ret
                      	
                      	
                      	;skip space
                      	;input: hl=program address-1
                      	;output: a=data, hl=next address
                      	;destroy: f
  3F56                	SKIPSPINC:
  3F56  23            		inc	hl
  3F57                	SKIPSP:
  3F57  7E            		ld	a,(hl)
  3F58  FE20          		cp	' '
  3F5A  C0            		ret	nz
  3F5B  18F9          		jr	SKIPSPINC
                      	
                      	
                      	;check colon and line end
                      	;input: hl=program address
                      	;output: a=(hl), z-flag(1= 00h or ":")
                      	;destroy: af
  3F5D                	CHKCLNINC:
  3F5D  23            		inc	hl
  3F5E                	CHKCLN:
  3F5E  7E            		ld	a,(hl)
  3F5F  B7            		or	a
  3F60  C8            		ret	z
  3F61  FE3A          		cp	':'
  3F63  C8            		ret	z
  3F64  FE20          		cp	' '
  3F66  C0            		ret	nz
  3F67  18F4          		jr	CHKCLNINC
                      	
                      	
                      	;check comma or argument
                      	;input: hl=program address
                      	;output: a=(hl), z-flag(1=comma), hl=next address
                      	;destroy: f
  3F69                	CHKCMM:
  3F69  CD5E3F        		call	CHKCLN		;a=(hl)
  3F6C  CA1204        		jp	z,MOERR
  3F6F  23            		inc	hl
  3F70  FE20          		cp	' '
  3F72  28F5          		jr	z,CHKCMM
  3F74  FE2C          		cp	','
  3F76  C8            		ret	z
  3F77  2B            		dec	hl
  3F78  C9            		ret
                      	
                      	
                      	;check colon and comma
                      	;input: hl=program address
                      	;output: a=(hl), z-flag(1= 00h or ":" ), hl=hl+1(comma)
                      	;destroy: af
  3F79                	CHKCLCM:
  3F79  CD5E3F        		call	CHKCLN
  3F7C  C8            		ret	z
  3F7D  FE2C          		cp	','
  3F7F  C2DC03        		jp	nz,SNERR
  3F82  23            		inc	hl
  3F83  B7            		or	a		;reset z-flag
  3F84  C9            		ret
                      	
                      	
                      	;bc=a*32
                      	;input: a(<=16), b=0
                      	;output: bc
                      	;destroy: f
  3F85                	MUL32:
  3F85  87            		add	a,a		;*2
  3F86  87            		add	a,a		;*4
  3F87  87            		add	a,a		;*8
  3F88  87            		add	a,a		;*16
  3F89  CB10          		rl	b
  3F8B  87            		add	a,a		;*32
  3F8C  CB10          		rl	b
  3F8E  4F            		ld	c,a
  3F8F  C9            		ret
                      	
                      	
                      	;convert hiragana -> katakana (PC-6001)
                      	;convert kana -> 00h (PC-6001A)
  3F90                	CNVKANA2:
  3F90  B7            		or	a
  3F91  F0            		ret	p
  3F92  E5            		push	hl
  3F93  C5            		push	bc
  3F94  4F            		ld	c,a
  3F95  CDA03F        		call	CHK6001A
  3F98  79            		ld	a,c
  3F99  C1            		pop	bc
  3F9A  E1            		pop	hl
  3F9B  C24F1A        		jp	nz,CNVKANA
  3F9E  AF            		xor	a
  3F9F  C9            		ret
                      	
                      	
                      	;check if PC-6001A
                      	;output: z-flag(1=PC-6001A)
                      	;destroy: af,b,hl
  3FA0                	CHK6001A:
  3FA0  3E04          		ld	a,04h
  3FA2  D393          		out	(93h),a		;CGROM ON
  3FA4  21D06F        		ld	hl,6fd0h	;nn
  3FA7  060C          		ld	b,0ch
  3FA9  AF            		xor	a
  3FAA                	CHK6001ALP:
  3FAA  B6            		or	(hl)
  3FAB  23            		inc	hl
  3FAC  10FC          		djnz	CHK6001ALP
  3FAE  3E05          		ld	a,05h
  3FB0  D393          		out	(93h),a		;CGROM OFF
  3FB2  C9            		ret
                      	
                      	
                      	;input: bc=screen mode X, de=screen mode Y, z-flag(1=mode5)
  3FB3                	SXY2ADMAIN:
  3FB3  C5            		push	bc
  3FB4  D5            		push	de
  3FB5  3A92FD        		ld	a,(SCREEN1)
  3FB8  67            		ld	h,a		;(SCREEN1)
  3FB9  CB3F          		srl	a
  3FBB  2015          		jr	nz,SXY2AD34
  3FBD  3E03          		ld	a,03h
  3FBF  3027          		jr	nc,SXY2AD1
                      	
                      	;(VRAM)*256+int(de/3)*32+bc/2
                      	;screen mode 2
  3FC1                	SXY2AD2:
  3FC1  EB            		ex	de,hl
  3FC2  29            		add	hl,hl
  3FC3  29            		add	hl,hl
  3FC4  EB            		ex	de,hl
  3FC5  CD9A15        		call	DIV12
                      	;a=0,4,8
  3FC8  0F            		rrca
  3FC9  0F            		rrca
                      	;e=0-15,a=0,1,2
  3FCA  CB39          		srl	c
  3FCC  17            		rla
                      	;c=0-31,e=0-15,a=0-5
  3FCD  47            		ld	b,a
  3FCE  3E40          		ld	a,40h
  3FD0  1812          		jr	SXY2ADBIT
                      	
  3FD2                	SXY2AD34:
  3FD2  3804          		jr	c,SXY2AD4
                      	
                      	;(VRAM)*256+de*32+bc/4
                      	;screen mode 3
  3FD4                	SXY2AD3:
  3FD4  3E81          		ld	a,81h
  3FD6  CB21          		sla	c
                      	
                      	;(VRAM)*256+de*32+bc/8
                      	;screen mode 4
  3FD8                	SXY2AD4:
  3FD8  57            		ld	d,a		;81h=screen mode 3=81h, 01h=screen mode 4
  3FD9  79            		ld	a,c
  3FDA  E607          		and	07h
  3FDC  47            		ld	b,a
  3FDD  7A            		ld	a,d		;81h=screen mode 3=81h, 01h=screen mode 4
  3FDE  CB39          		srl	c
  3FE0  CB39          		srl	c
  3FE2  CB39          		srl	c
  3FE4                	SXY2ADBIT:
  3FE4  04            		inc	b
  3FE5                	SXY2ADLP:
  3FE5  0F            		rrca
  3FE6  10FD          		djnz	SXY2ADLP
                      	
                      	;(VRAM)*256+de*32+bc
                      	;screen mode 1
  3FE8                	SXY2AD1:
  3FE8  54            		ld	d,h		;(SCREEN1)
  3FE9  61            		ld	h,c
  3FEA  6B            		ld	l,e
  3FEB  24            		inc	h
  3FEC  2C            		inc	l
  3FED  CDCD11        		call	XY2AD
  3FF0  14            		inc	d		;(SCREEN1)
  3FF1  15            		dec	d		;(SCREEN1)
  3FF2  2002          		jr	nz,SXY2ADNZ
  3FF4  25            		dec	h
  3FF5  25            		dec	h
  3FF6                	SXY2ADNZ:
  3FF6  22B3FD        		ld	(VRAMAD),hl
  3FF9  32B2FD        		ld	(VRAMBIT),a
  3FFC  D1            		pop	de
  3FFD  C1            		pop	bc
  3FFE  C9            		ret
                      	
                      	
                      	;ROM end
  3FFF                	_4000H:	ds	4000h-_4000H
                      	
  4000                		end
