;-----------------------------------------------------------------------------
; Mini Z80 BIOS Interface
; Mike Christle (c) 2016
;-----------------------------------------------------------------------------
;                        TERMS OF USE: MIT License
;-----------------------------------------------------------------------------
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
; 
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
; 
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; 68681 DUART Register Port Addresses
;-----------------------------------------------------------------------------
DUART_MR1A        EQU   0
DUART_MR2A        EQU   0
DUART_SRA         EQU   1
DUART_CSRA        EQU   1
DUART_BRG_TEST    EQU   2
DUART_CRA         EQU   2
DUART_RHRA        EQU   3
DUART_THRA        EQU   3
DUART_IPCR        EQU   4
DUART_ACR         EQU   4
DUART_ISR         EQU   5
DUART_IMR         EQU   5
DUART_CTU         EQU   6
DUART_CTUR        EQU   6
DUART_CTL         EQU   7
DUART_CTLR        EQU   7
DUART_MR1B        EQU   8
DUART_MR2B        EQU   8
DUART_SRB         EQU   9
DUART_CSRB        EQU   9
DUART_1X_TEST     EQU   10
DUART_CRB         EQU   10
DUART_RHRB        EQU   11
DUART_THRB        EQU   11
DUART_IVR         EQU   12
DUART_IN_PORT     EQU   13
DUART_OPCR        EQU   13
DUART_START_CNTR  EQU   14
DUART_STOP_CNTR   EQU   15
DUART_SOPR        EQU   14
DUART_ROPR        EQU   15

;-----------------------------------------------------------------------------
; Interrupt Numbers
;-----------------------------------------------------------------------------
INPORT_INT        EQU   14
BREAKB_INT        EQU   12
RXRDYB_INT        EQU   10
TXRDYB_INT        EQU   8
CTRRDY_INT        EQU   6
BREAKA_INT        EQU   4
RXRDYA_INT        EQU   2
TXRDYA_INT        EQU   0

;-----------------------------------------------------------------------------
APP_START         EQU   8000H
BIOS_CALL         EQU   8

;-----------------------------------------------------------------------------
; GETC
; Output    A = Char
;           z = 1 if buffer empty
;-----------------------------------------------------------------------------
#macro            GETC
                  LD    HL, (1F00H)
                  RST   BIOS_CALL
#endmacro

;-----------------------------------------------------------------------------
; GETS      Buffer Address, Max Byte Count
; Exits on CR or buffer full
; Terminates buffer with 0.
;-----------------------------------------------------------------------------
#macro            GETS  ADRS, COUNT
                  LD    DE, %ADRS
                  LD    C, %COUNT
                  LD    HL, (1F04H)
                  RST   BIOS_CALL
#endmacro

;-----------------------------------------------------------------------------
; PUTC
; Waits if buffer full
; Input     A = Char
;-----------------------------------------------------------------------------
#macro            PUTC
                  LD    HL, (1F02H)
                  RST   BIOS_CALL
#endmacro

;-----------------------------------------------------------------------------
; PUTS      String Address
;-----------------------------------------------------------------------------
#macro            PUTS  ADRS
                  LD    DE, %ADRS
                  LD    HL, (1F06H)
                  RST   BIOS_CALL
#endmacro

;-----------------------------------------------------------------------------
; Print a Hex Digit
; Input     A = Value
;-----------------------------------------------------------------------------
#macro            PRINT_HEX
                  LD    HL, (1F08H)
                  RST   BIOS_CALL
#endmacro

;-----------------------------------------------------------------------------
; Link Interrupt Service Routine
; A  = Vector Number
; DE = ISR Address
;-----------------------------------------------------------------------------
#macro            LINK_ISR VEC_NO, ISR_ADRS
                  LD    A, %VEC_NO
                  LD    DE, %ISR_ADRS
                  LD    HL, (1F0AH)
                  RST   BIOS_CALL
#endmacro
