;wp2.def
;2/26/2017
;$Id: wp2.def,v 1.16 2019/03/06 04:06:11 goosey Exp goosey $
;Willard Goosey
;goosey@sdc.org


;Tandy WP-2 ROM calls
;ASM80/ZMAC

;Sources:
;Tandy WP-2 Service Manual
;ROMRTN.TXT by Michael F. Klar
;ROMRT2.TXT by Michael F. Klar


;ROM calls

CHARSENSE equ 0100H
;Check Keyboard buffer
;returns key if one is pressed, key is NOT removed 
;from input buffer. use CHARGET to remove it from the buffer
;Entry Conditions: None
;Exit  Conditions: Z flag set = no key
;		Z flag clear = key
;		H = character code
;		L = control key status
;		bit 0: F2
;		bit 1: F1
;		bit 2: Ctrl
;		bit 3: right shift
;		bit 4: left shift
;		bit 5: Caps Lock OFF/On
;		bit 7,6:
;			0,x: normal mode
;			1,0: GRPH mode
;			1,1: CODE mode
;		Carry flag set: ASCII Character
;		Carry flag clear: CODE or GRPH character
;	BC,DE,IX,IY,AF',BC',DE',HL' preserved

CHARGET equ 0103h
;Get one character
;blocks if no keys in buffer
;Entry Condition: None
;Exit  Condition: Z flag set = no key
;		Z flag clear = key
;		H = character code
;		L = control key status
;		bit 0: F2
;		bit 1: F1
;		bit 2: Ctrl
;		bit 3: right shift
;		bit 4: left shift
;		bit 5: Caps Lock OFF/On
;		bit 7,6:
;			0,x: normal mode
;			1,0: GRPH mode
;			1,1: CODE mode
;		Carry flag set: ASCII Character
;		Carry flag clear: CODE or GRPH character
;	BC,DE,IX,IY,AF',BC',DE',HL' preserved

KILLBUF equ 0106h
;Kill Key Buffer
;Entry Conditions: None
;Exit  Conditions: BC,DE,IX,IY,AF',BC',DE',HL' preserved

SETLOC equ 0109h
;Set Cursor Location
;Entry Conditions: H = X (0<=H<=79)
;			L=Y (0<=L<=7)
;Exit  Conditions: All regs perserved

GETLOC equ 010ch
;get cursor location
;Entry Conditions: none
;Exit  Conditions: H=X, L=Y
;		all other regs preserved

SETCURSORONOFF equ 010Fh
;turn on or off cursor
;Entry Conditions: A=0 cursor blink on
;		A=1 cursor blink off
;Exit  Contitions: AF destroyed, all other
;		regs preserved

SETCOLOR equ 0115h
;Set Character Color
;be sure to reset at exit or the file menu will
;be messed up
;Entry Conditions:A=0 normal
;		A=1 reverse
;Exit  Conditions: AF destroyed, all other
;		regs preserved

CHAROUT equ 0118h
;Character output
;does not support escape codes, or LF, CR, BS
;Entry Conditions: A=ASCII code to output
;Exit  Conditions: all regs preserved

PUTCHAR equ 01A3h
;Character output
;DOES support escape codes
;Entry Conditions: A = ASCII code to output
;Supported Commands: A=....
;	08H	BS
;	09H	TAB
;	0AH	LF
;	0DH	CR
;	ESC A	cursor up
;	ESC B	cursor down
;	ESC C	cursor right
;	ESC D	cursor left
;	ESC H	home cursor
;	ESC J	erase to end of screen (buggy?)
;	ESC K	erase to end of line
;	ESC Y ln col	direct cursor address
;Exit  Conditions: IX,IY,AF',BC',DE',HL' preserved

STROUT equ 011bh
;string output
;does not support escape codes or CR,LF
;Entry Conditions: HL-> string null terminated
;Exit  Conditions: AF,HL destroyed
;		all other regs preserved

CLS equ 011eh
;clear screen
;Entry Conditions: none
;Exit  Conditions:IX,IY,AF',BC',DE',HL' preserved

BEEP equ 0121h
;make a noise
;Entry Conditions: A = buzzer type
;		(0=low tone, 1=high tone)
;Exit  Conditions: all regs preserved

CHECKCNCL equ 0124h
;check for CNCL key pushed
;this does not remove the <esc> from the input buffer
;Entry Conditions: None
;Exit  Conditions: Carry flag set = escape pressed
;		Carry flag clear = escape not pressed
;		AF destroyed, all other regs
;		preserved

PRNOUT equ 0130h
;send one byte to printer
;must check printer status with PRNSTATUS first
;Entry Conditions: A=data
;Exit  Conditions: AF destroyed, all other regs
;		preserved

PRNSTATUS equ 0133h
;Check printer status
;Entry Conditions: none
;Exit  Conditions: Zero flag set = printer ready
;		Zero flag clear = printer not ready
;		AF destroyed, all other regs 
;		preserved

READSLOT equ 0160h
;read data from a slot
;Entry Conditions: A=slot number
;		HL = offset (0<=HL<=3fff)
;Exit  Conditions: A=data
;		AF destroyed, all other regs 
;		preserved

CHGSLOT equ 0166h
;Change Slots
;changes selected ROM slot addressed at 4000-7fff
;must change this back to slot 0 before exit
;Entry Conditions: A= slot number
;Exit  Conditions: E,HL,IX,IY,
;		AF',BC',DE',HL' preserved

;CALLFAR
;Calling a routine in a different slot:
;rst 30h
;db n slot number
;dw nn address

RSINIT equ 0140h
;initialize RS232
;Entry Conditions: HL=baud rate, etc
; H=baud rate
;    0=75 bps
;    1=110
;    2=150
;    3=300
;    4=600
;    5=1200
;    6=2400
;    7=4800
;    8=9600
;    9=19200
;L(bits 7,6)= stop bits
;    00=0
;    01=1
;    10=1.5
;    11=2
;L(5,4)=parity check
;    x0=no parity
;    01=odd parity
;    11=even parity
;L(3,2)=data length
;    00=5 bit
;    01=6 bit
;    10=7 bit
;    11=8 bit
;L bit 1 = xon/xoff enable/disable
;   0=disable
;L bit 0 = timer interupt 
;   0=enable
;Exit Conditions: all regs preserved

GETDATALEN equ 0143h
;get the length of effective data in aux-buffer
;Entry Conditions: none
;Exit  Conditions: HL=data length
;		AF,HL destroyed, all other regs
;		preserved

SENDDATA equ 0146h
;send one byte to rs232
;Entry Conditions: RSINIT called, RTS asserted(?), A=data
;Exit  Conditions: Carry set on error
;		All regs preserved

GETDATA equ 0149h
;read data from rs232 buffer
;Entry Condtions:RSINIT called
;Exit  Conditions: Zero flag set= no data in buffer
;		Zero flag clear = data exists
;		A=data
;		E=status
;		   bit 7: frame error
;		   bit 6: overrun error
;		   bit 5: parity error
;		BC,HL,IX,IY,
;		AF',BC',DE',HL' preserved

RSCLOSE equ 014ch
;close rs232 port, hang up modem, forget line settings
;unnecessary, do not use (Klar)
;Entry Conditions: none
;Exit  Conditions: BC destroyed, all other regs preserved

TAPEIN equ 0150h
;read data from tape
;Entry Conditions: none
;Exit  Conditions: Carry Flag set = Cancel key pushed
;		Carry flag clear = OK
;		A=data
;		DE,HL,IX,IY,AF',BC',DE',HL' preserved

TAPEOUT equ 0153h
;Write data to tape
;Entry Conditions: A=data
;Exit  Conditions: Carry Flag set = Cancel key pushed
;		Carry Flag clear = OK
;		DE,HL,IX,IY,AF',BC',DE',HL' preserved

MOTORON equ 0156h
;Turn tape motor on
;Entry Conditions: none
;Exit  Conditions: DE,HL,IX,IY,AF',BC',DE',HL' preserved

MOTOROFF equ 0159h
;Turn tape motor off
;Entry Conditions: none
;Exit  Conditions: DE,HL,IX,IY,AF',BC',DE',HL' preserved

SYNCREAD equ 0169h
;read sync byte from tape
;Entry Conditions: none
;Exit  Conditions: Carry Flag set = cancel key pushed
;		Carry Flag clear = OK
;		IX,IY,AF',BC',DE',HL' preserved

LINEIN equ 01a6h
;cooked mode line input
;RETURN and ESCAPE end input, and that char returned in A
;<ctrl>-V means literal-value next char, for instance
;<ctrl>-V <ctrl>-B is a smiley-face
;Entry Conditions: BC=length+1 (BC < 80)
;		DE -> buffer
;Exit  Conditions: A=last char
;		HL->buffer
;		(AP must copy this string to its buffer)
;		IX,IY,AF',BC',DE',HL' preserved

LINEIN2 equ 01ach
;cooked mode line input with default string
;Entry Conditions: BC=length (BC < 80)
;		DE -> buffer
;		HL -> default string (null terminated)
;Exit  Conditions: A=last char
;		HL->buffer
;		(AP must copy this string to its buffer)
;		IX,IY,AF',BC',DE',HL' preserved

UNGETFORLINEP equ 01a9h
;Unget char for LINEIN and LINEIN2
;Entry Conditions: A=char to unget
;Exit  Conditions: All regs preserved

CMPHLDE equ 20h
;Compare HL to DE
;rst 20h
;Entry Conditions: HL=number1
;		DE=number2
;Exit  Conditions:
;		Zero Flag set = HL==DE
;		Zero Flag clear = HL!=DE
;		Carry Flag set = HL<DE
;		Carry Flag clear = HL=>DE
;		F set, all other regs preserved

MALLOC equ 0170h
;memory allocation
;Entry Conditions: HL->fname[12]
;		HL=0 to alloc all free RAM
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		HL->returned block
;		DE=length of block (32 byte units)
;		IX,IY,AF',BC',DE',HL' preserved
;..........012345678901
;fname db "foo     .bar"

MCHGSIZE equ 0173h
;Change size of malloced block
;Entry Conditions: MALLOC called 
;		HL = length you want in 32-byte blocks
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		HL=new length of block in 32-byte units
;		IX,IY,AF',BC',DE',HL' preserved

MFREE equ 0176h
;free MALLOCed block
;deletes the ram file
;Entry Conditions: MALLOC callled
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

MCLOSE equ 017Ch
;Close (save) MALLOCed block
;if you MCLOSE a block without MNAMEing it you will
;leave an unnamed file in RAM that can only be erased
;with a cold start
;Entry Conditions: None
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

MNAME equ 017Fh
;Name MALLOCed block
;Entry Conditions: HL=> fname[12]
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved
;You must MNAME a block before MCLOSEing it or
;the block will be saved but untouchable!

LIST0 equ 0182h
;Initialize file listing
;AP must call this function before calling FILELIST!
;Entry Conditions: None
;Exit  Conditions: None
;		IX,IY,AF',BC',DE',HL' preserved

FILELIST equ 0185h
;Get File List
;Entry Conditions: LIST0 has been called 
;		DE->FCB
;		A=0 : next file
;		A=FFh : previous file
;Exit  Conditions: Carry Flag set = no more files
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

;FCB structure:
; char device;
; char name[12];
; int filelength;
; char currentrecord;
; int device dependant;
; char mode;
; char reserved[13];
FCB$DEV$MEMORY equ 01h ;main memory
FCB$DEV$RAMDISK equ 02h; ramdisk
FCB$DEV$ICRAM equ 03h  ;IC card RAM
FCB$DEV$DRIVEA equ 11h ;PDD disk drive
;
FCB$MODE$WRITE equ 00h
FCB$MODE$RW equ 01h
FCB$MODE$READ equ 02h


OPEN equ 0188h
;open a file
;Entry Conditions: DE-> FCB
;		A=0 :open new file in write mode
;		A=1 :open file in read/write
;		A=2 :open file in read mode
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

FREAD equ 018bh
;read a file
;Entry Conditions: file OPENed
;		DE-> FCB
;		HL->128 byte buffer
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		A=# of bytes read, meaning
;		A=128 for all records except the last 
;			record
;		A=128+# of bytes in last record, or
;		A=0  if last record had 128 bytes
;		IX,IY,AF',BC',DE',HL' preserved

WRITE equ 018eh
;write a file
;Entry Conditions: file OPENed
;		DE-> FCB
;		HL-> 128 byte buffer
;Exit  Conditions: Carry Flag set = error
;		Carry flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

CLOSE equ 0191h
;close a file
;Entry Conditions: file OPENed
;		HL-> FCB
;		DE=0
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

DELETE equ 0194h
;delete a file
;Entry Conditions: HL-> FCB
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

RENAME equ 0197h
;rename a file
;Entry Conditions: HL-> newnameFCB
;		DE->oldnameFCB
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

FORMAT equ 019ah
;formate a device
;Entry Conditions: A=device number
;	02h : internal RAM disk
;	03h : IC RAM card
;	11h : PDD disk drive
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

DEVROOM equ 01c1h
;get device rest size
;Entry Conditions: A=device number
;	02h : internal RAM disk
;	03h : IC RAM card
;	11h : PDD disk drive
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

SEEK equ 01beh
;move file pointer
;only for RAM disk and IC card
;Entry Conditions: HL-> FCB
;		DE=seek position from head
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

WAIT equ 01a0h
;wait a time
;Entry Conditions: A= time to wait 1/10 seconds
;Exit  Conditions: none
;	BC,DE,HL,IX,IY,AF',BC',DE',HL' preserved

RUNIC equ 01afh
;run IC card program
;Entry Conditions: none
;Exit  Conditions: depends on program

RUNFILE equ 01b2h
;run binary program file
;Entry Conditions: HL-> FCB
;Exit  Conditions: none
;	preserved regs depend on program

;bin file header is:
;db 'PR' : magic number
;dw size : program size
;dw entry : entry point
;dw load : load address 0=normal=AC00h

POFFCOUNTPOINTER equ 01b5h
;get power off counter pointer
;Entry Conditions: none
;Exit  Conditions: HL-> counter
;		IX,IY,AF',BC',DE',HL' preserved

SETBTYPE equ 01b8h
;set battery type
;Entry Conditions: A=0 : Alkaline
;		A=1 : Ni-Cad
;Exit  Conditions: none
;		HL,IX,IY,AF',BC',DE',HL' preserved

GETWORK equ 01bbh
;get working area
;Entry Conditions: HL= address AP wants to get
;	if HL=0 free work area
;Exit  Conditions: Carry Flag set = error
;		Carry Flag clear = no error
;		IX,IY,AF',BC',DE',HL' preserved

SPELLER equ 2c00h
;call spell check/thesarus
;Entry Conditions A=function code
;		HL-> string to check if needed (null terminate)
;Exit  Conditions: vary by function
;	all regs destroyed

;Function codes in A
SPELLSTRING equ 2
;check spelling of string
;Entry Condition: HL->string
;Exit  Conditions: C=1 if OK
;		C=0 if misspelled

SINGLECHAR equ 3
;look for alternates 
;where a single char would be 
;(1) deleted (2) transposed (3) inserted (4) replaced
;Entry Conditions: HL-> string
;Exit  Conditions: HL-> first alternate
;		A=number of alternates

PHONETIC equ 4
;phonetic correct
;Entry Conditions: HL-> string
;Exit  Conditions: C=1 if alternates exist
;		HL-> alternate
;		A=number of alternates

SYNONYM equ 10
;find synonyms
;Entry Conditions: none?
;Exit  Conditions: C=0 only one synonym
;		C=1 if more ofsynonyms exist
;		HL-> first syn.
;		A=number of synonyms in this row
;		B=0 (noun)
;		  1 (verb)
;		  2 (adjective)
;		  3 (adverb)
;		  4 (preposition)
;		  7 (conjunction)

NEXTSYN equ 11
;next synonym row
;Exit  Conditions: C=0 no more rows
;		C=1 if more rows of synonyms exist
;		HL-> first syn.
;		A=number of synonyms in this row
;		B=0 (noun)
;		  1 (verb)
;		  2 (adjective)
;		  3 (adverb)
;		  4 (preposition)
;		  7 (conjunction)

PREVSYN equ 12
;Exit  Conditions: C=0 at top
;		C=1 if theres a row above
;		HL-> first syn.
;		A=number of synonyms in this row
;		B=0 (noun)
;		  1 (verb)
;		  2 (adjective)
;		  3 (adverb)
;		  4 (preposition)
;		  7 (conjunction)

;Synonym organization:
;all strings null terminated
;<main syn 1> <next main syn 1> <alt syn 11> <alt syn 12>...<alt syn 1N>
;<main syn 2> <next main syn 2> <alt syn 21> .... <alt syn 2N>
;....
;<main syn m> <next main syn m> <alt syn m1>... <alt syn mn>

;SPELLER vars:
SINGLECOR equ 8325h
PHONETICCOR equ 8326h
QUITCOR equ 8327h

;VT-52 codes supported by WP2
;ESC A		cursor up
;ESC B		cursor down
;ESC C		cursor right
;ESC D		cursor left
;ESC H		home cursor
;ESC J		erase to end of screen
;ESC K		erase to end of line
;ESC Y line col	direct cursor address
;ESC Z		Identify

DEBUG equ 28h
;hook for a debugger at RST 28h

MULTA equ 1740H
;multiply A by 128
;Entry Conditions: A=value
;Exit  Conditions: HL=A*128

UPCASE equ 5557H
;Slot 1
;convert char in A to uppercase
;Entry Conditions: A=char
;Exit  Conditions: A=uppercase(A)

MKFCB equ 5428h
;slot 1
;Make an FCB at address 96A3h
;asks user for name and device?
;Entry Conditions: none
;Exit  Conditions: carry flag set if ESC pushed
;		or file extention is 3 chars long
;		and ends in an uppercase char

FILES equ 546fh ;slot 0
;Files application
;Entry Condition: none?
;Exit  Condition: returns to wp mode

;file subroutines at 5f35, 47eb, and 56f6..


;end wp2.def
