Files
RomWBW/Source/HBIOS/uart.asm
b1ackmai1er 78f65522b7 Dev (#108)
* added hack to handle tunes

* quiet clean

* added chmod for execution

* suppress warnings

* Multi-boot fixes

* the windows build somehow thinks that these filesystems are cpm3.

* credit and primitive instructions

* Update sd.asm

Cosmetic fix.

* make compile shut up about conditionals

* Add bin2asm for linus and update build to process font files under linix

* fixed quoted double quote bug, added tests

* added tests

* added bin2asm for font file source creation

* Revert linux bin2asm font stuff

* added rule for font source generation

* build fonts

* added directory mapping cache.  if the same directory is being hit
as last run, we don't need to rebuild the map.  will likely break if
you are running more than one at a time, in that the cache will be
ineffective.  also, if the directory contents change, this will also break.

* removed strip.  breaks osx

* added directory tag so . isn't matched all over the place

* added real cache validation

* fixed build

* this file is copied from optdsk.lib or optcmd.lib

* install to ../HBIOS

* prerequisite verbosity

* diff soft failure and casefn speedup

* added lzsa

* added lzsa

* removed strip. breaks on osx

* added clobber

* added code to handle multiple platform rom builds with rom size override

* added align and 0x55 hex syntax

* default to hd64180

* added N8 capability

* added SBC_std.rom to default build

* added support for binary diff

* diff fixes

* clean, identical build.  font source generator emitted .align.  this does not match the windows build

* Upgrade NZCOM to latest

* Misc. Cleanup

* fixed expression parser bug : ~(1|2) returned 0xfe

* added diff build option

* Update Makefile

Makefile enhancement to better handle ncurses library from Bob Dunlop.

* Update sd.asm

Back out hack for uz80as now that Curt fixed it.

* Misc. Cleanup

* UNA Catchup

UNA support was lacking some of the more recent behavior changes.  This corrects most of it.

* Add github action for building RomWBW

* Bump Pre-release Version

* Update build.yml

Added "make clean" which will remove temporary files without removing final binary outputs.

* Update Makefile

Build all ROM variants by default in Linux/Mac build.

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update Makefile

* Update for GitHub Build

Case issue in TASM includes showing up in GitHub build.  This should correct that.

* Added an gitignore files to exclude generated files

* Removed Tunes/clean.cmd and Tunes/ReadMe.txt - as make clean removes them

* Build.sh: marked as executable

chmod +x Build.sh

* Fix to HBIOS/build.sh

When adding files to rom disk, if files were missing, it would error out.

It appears the intent is to skip non-existing files.

Updated to log out correctly for missing files - and continue operation.

* Update Microsoft NASCOM BASIC.docx

Nascom manual, text version by Jan S (full name unknown)

* Fix issue with Apps/Tune not making

If dest directory does not exist, fails to make Apps

* Create ReadMe.txt

* Update Makefile

* Update Build.sh

* Make .gitignores for Tools/unix more specific

* cpmtools Update

Updated cpmtools applications (Windows only).  Removed hack in diskdefs that is no longer required.

* HBIOS Proxy Temp Stack Enhancement

Reuse the bounce buffer area as the temporary stack space required briefly in HBX_INVOKE when transitioning banks.  Increases size of temporary stack space to 64 bytes.

* Update ReadMe.txt

* HBIOS - clean up TMPSTK

* Update hbios.asm

Minor cosmetic changes.

* Build Process Updates

Minor udpates to build process to improve consistency between Windows and Mac/Linux builds.

* Update hbios.asm

Add improved interrupt protection to HBIOS PEEK, POKE, and BNKCPY functions.

* hbios - wrap hbx_bnkcpy

* hbios - adjust hbx_peek hbx_poke guards

* Update hbios.asm

Adjusted used of DI/EI for PEEK and POKE to regain a bit of INTSTK space.  Added code so that HB_INVBNK can be used as a flag indicating if HBIOS is active, $FF is inactive, anything else means active.

* Add HBIOS MuTex

* Initial Nascom basic ecb-vdu graphics

set and reset for 80x25b screen with 256 character mod

* Finalize Pre-release 34

Final support for FreeRTOS

* Update nascom.asm

Optimization, cleanup, tabs and white spaces

* IDE & PPIDE Cleanup

* Clean up

Make version include files common.

* Update Makefile

* Update Makefile

* Build Test

* Build Test

* Build Fixes

* Update nascom.asm

Cleanup

* Update nascom.asm

Optimization

* hbios - temp stack tweak

* Update hbios.asm

Comments on HBX_BUF usage.

* Update nascom.asm

Optimization

* Update nascom.asm

Setup ECB-VDU build option, remove debug code

* Update nascom.asm

Set default build. update initialization

* Update nascom.asm

Make CLS clear vdu screen

* Update nascom.asm

Fixup top screen line not showing

* Add SC131 Support

Also cleaned up some ReadMe files.

* HBIOS SCZ180 - remove mutex special files

* HBIOS SCZ180 - adjust mutex comment

* Misc. Cleanup

Includes some minor improvements to contents in some disk images.

* Delete FAT.COM

Changing case of FAT.COM extension to lowercase.

* Create FAT.com

Completing change of case in extension of FAT.com.

* Update Makefile

Remove ROM variants that just have the HBIOS MUTEX enabled.  Users can easily enable this in a custom build.

* Cleanup

Removed hack from Images Makefile.  Fixed use of DEFSERCFG in various places.

* GitHub CI Updates

Adds automation of build and release assets upon release.

* Prerelease 36

General cleanup

* Build Script Cleanups

* Config File Cleanups

* Update RomWBW Architecture

General refresh for v2.9.2

* Update vdu.asm

Removed a hack in VDU driver that has existed for 8 years.  :-)

* Fix CONSOLE Constant

Rename CIODEV_CONSOLE constant to CIO_CONSOLE because it is a unit code, not a device type code.

Retabify TastyBasic.

* Minor Bug Fixes

- Disk assignment edge case
- CP/M 3 accidental fall thru
- Cosmetic updates

* Update util.z80

* Documentation Cleanup

* Documentation Update

* Documentation Update

* Documentation Updates

* Documentation Updates

* Create Common.inc

* Documentation Updates

* Documentation Updates

* doc - a few random fixes

* Documentation Cleanup

* Fix IM 0 Build Error in ACIA

* Documentation Updates

* Documentation Cleanup

* Remove OSLDR

The OSLDR application was badly broken and almost impossible to fix with new expanded OS support.

* Bug Fixes

- Init RAM disk at boot under CP/M 3
- Fix ACR activation in TUNE

* FD Motor Timeout

- Made FDC motor timeout smaller and more consistent across different speed CPUs
- Added "boot" messaging to RTC

* Cleanup

* Cleanup

- Fix SuperZAP to work under NZCOM and ZPM3
- Finalize standard config files

* Minor Changes

- Slight change to ZAP configuration
- Added ZSDOS.ZRL to NZCOM image

* ZDE Upgrade

- Upgraded ZDE 1.6 -> 1.6a

* Config File Tuning

* Pre-release for Testing

* cfg - mutex consistent config language

* Bump to Version 3.0

* Update SD Card How-To

Thanks David!

* update ReadMe.md

Remove some odd `\`.

* Update ReadMe.txt

* Update ReadMe.md

* Update Generated Doc Files

* Improve XModem Startup

- Extended startup timeout for XM.COM so that it doesn't timeout so quickly while host is selecing a file to send.
- Updated SD Card How-To from David Reese.

* XModem Timing Refinements

* TMS Driver Z180 Improvements

- TMS driver udpated to insert Z180 I/O waitstates internally so other code can run at full speed.
- Updated How-To documents from David.
- Fixed TUNE app to properly restore Z180 I/O waitstates after manipulating them.

* CLRDIR and ZDE updates

- CLRDIR has been updated by Max Scane for CP/M 3 compatibility.
- A minor issue in the preconfigured ZDE VT100 terminal escape sequences was corrected.

* Fix Auto CRT Console Switch on CP/M 3

* Handle lack of RTC better

DSRTC driver now correctly returns an error if there is no RTC present.

* Minor RTC Updates

* Finalize v3.0.1

Cleanup release for v3.0

* New ROMLDR and INTRTC driver

- Refactored romldr.asm
- Added new periodic timer based RTC driver

* CP/M 3 Date Hack

- Hack to allow INTRTC to increment time without destroying the date

* Update romldr.asm

Work around minor Linux build inconsistency

* Update Apps for New Version

* Revert "Update Apps for New Version"

This reverts commit ad80432252.

* Revert "Update romldr.asm"

This reverts commit 4a9825cd57.

* Revert "CP/M 3 Date Hack"

This reverts commit 153b494e61.

* Revert "New ROMLDR and INTRTC driver"

This reverts commit d9bed4563e.

* Start v3.1 Development

* Update FDISK80.COM

Updated FDISK80 to allow reserving up to 256 slices.

* Update sd.asm

For Z180 CSIO, ensure that xmit is finished, before asserting CS for next transaction.

* Add RC2014 UART, Improve SD protocol fix

- RC2014 and related platforms will autodetect a UART at 0xA0 and 0xA8
- Ensure that CS fully brackets all SD I/O

* ROMLDR Improvements

.com files can now be started from CP/M and size of .com files has been reduced so they always fit.

* Update commit.yml

Run commit build in all branches

* Update commit.yml

Run commit build for master and dev branches

* Improved clock driver auto-detect/fallback

* SIO driver now CTC aware

The SIO driver can now use a CTC (if available) to provide much more flexible baud rate programming.

* CTC driver fine tuning

* Update xmdm125.asm

Fixed a small issue in core XM125 code that caused a file write error message to not be displayed when it should be.

* CF Card compatibility improvement

Older CF Cards did not reset IDE registers to defaults values when reset.  Implemented a work around.

* Update ACIA detection

ACIA should no longer be detected if there is also a UART module in the system.

* Handle CTC anomaly

Small update to accommodate CTC behavior that occurs when the CTC trigger is more than half the CTC clock.

* Update acia.asm

Updated ACIA detection to use primary ACIA port instead of phantom port.

* Update acia.asm

Fix bug in ACIA detection.

Thanks Alan!

* MacOS Build Improvement

Build script updated to improve compatibility with MacOS.

Credit to Fredrik Axtelius for this.

* HBIOS Makefile - use env vars for target

Allow build ROM targets to be restricted to just one platform thru use of ENV vars:

ROM_PLATFORM - if defined to a known platform, only this platform is build - defaults to std config
ROM_CONFIG - sets the desired platform config - defaults to std

if the above ENVs are not defined, builds all ROMs

* Added some more gitignores

* Whitespace changes (crlf)

* HBIOS: Force the assembly to fail for vdu drivers if function table count is not correct

* Whitespace: trailing whitespaces

* makefile: updated some make scripts to use  when calling subdir makefiles

* linux build: update to Build.sh fix for some platforms

The initialization of the Rom dat file used the pipe (|) operator to build an initial empty file.

But the pipe operator | may sometimes return a non-zero exit code for some linux platforms, if the
the streams are closed before dd has fully processed the stream.

This issue occured on a travis linux ubuntu image.

Solution was to change to redirection.

* Bump version

* Enhance CTC periodic timer

Add ability to use TIMER mode in CTC driver to generate priodic interrupts.

* HBIOS: Added support for sound drivers

New sound driver support with initial support for the SN76489 chip

New build configuration entry:
* SN76489ENABLE

Ports are currently locked in with:
* SN76489_PORT_LEFT       .EQU    $FC     ; PORTS FOR ACCESSING THE SN76489 CHIP (LEFT)
* SN76489_PORT_RIGHT      .EQU    $F8     ; PORTS FOR ACCESSING THE SN76489 CHIP (LEFT)

* Miscellaneous Cleanup

No functional changes.

Co-authored-by: curt mayer <curt@zen-room.org>
Co-authored-by: Wayne Warthen <wwarthen@gmail.com>
Co-authored-by: ed <linux@maidavale.org>
Co-authored-by: Dean Netherton <dnetherton@dius.com.au>
Co-authored-by: ed <ed@maidavale.org>
Co-authored-by: Phillip Stevens <phillip.stevens@gmail.com>
Co-authored-by: Dean Netherton <dean.netherton@gmail.com>
2020-04-24 06:17:22 +08:00

647 lines
17 KiB
NASM

;
;==================================================================================================
; UART DRIVER (SERIAL PORT)
;==================================================================================================
;
; SETUP PARAMETER WORD:
; +-------+---+-------------------+ +---+---+-----------+---+-------+
; | |RTS| ENCODED BAUD RATE | |DTR|XON| PARITY |STP| 8/7/6 |
; +-------+---+---+---------------+ ----+---+-----------+---+-------+
; F E D C B A 9 8 7 6 5 4 3 2 1 0
; -- MSB (D REGISTER) -- -- LSB (E REGISTER) --
;
; UART CONFIGURATION REGISTERS:
; +-------+---+-------------------+ +---+---+-----------+---+-------+
; | 0 0 |AFE|LP OT2 OT1 RTS DTR| |DLB|BRK|STK EPS PEN|STB| WLS |
; +-------+---+-------------------+ +---+---+-----------+---+-------+
; F E D C B A 9 8 7 6 5 4 3 2 1 0
; -- MCR -- -- LCR --
;
;
UART_DEBUG .EQU FALSE
;
UART_NONE .EQU 0 ; UNKNOWN OR NOT PRESENT
UART_8250 .EQU 1
UART_16450 .EQU 2
UART_16550 .EQU 3
UART_16550A .EQU 4
UART_16550C .EQU 5
UART_16650 .EQU 6
UART_16750 .EQU 7
UART_16850 .EQU 8
;
UART_RBR .EQU 0 ; DLAB=0: RCVR BUFFER REG (READ)
UART_THR .EQU 0 ; DLAB=0: XMIT HOLDING REG (WRITE)
UART_IER .EQU 1 ; DLAB=0: INT ENABLE REG (READ)
UART_IIR .EQU 2 ; INT IDENT REGISTER (READ)
UART_FCR .EQU 2 ; FIFO CONTROL REG (WRITE)
UART_LCR .EQU 3 ; LINE CONTROL REG (READ/WRITE)
UART_MCR .EQU 4 ; MODEM CONTROL REG (READ/WRITE)
UART_LSR .EQU 5 ; LINE STATUS REG (READ)
UART_MSR .EQU 6 ; MODEM STATUS REG (READ)
UART_SCR .EQU 7 ; SCRATCH REGISTER (READ/WRITE)
UART_DLL .EQU 0 ; DLAB=1: DIVISOR LATCH (LS) (READ/WRITE)
UART_DLM .EQU 1 ; DLAB=1: DIVISOR LATCH (MS) (READ/WRITE)
UART_EFR .EQU 2 ; LCR=$BF: ENHANCED FEATURE REG (READ/WRITE)
;;
;UART_FIFO .EQU 0 ; FIFO ENABLE BIT
;UART_AFC .EQU 1 ; AUTO FLOW CONTROL ENABLE BIT
;
#DEFINE UART_INP(RID) CALL UART_INP_IMP \ .DB RID
#DEFINE UART_OUTP(RID) CALL UART_OUTP_IMP \ .DB RID
;
;
;
UART_PREINIT:
;
; INIT UART4 BOARD CONFIG REGISTER (NO HARM IF IT IS NOT THERE)
;
LD A,$80 ; SELECT 7.3728MHZ OSC & LOCK CONFIG REGISTER
OUT ($CF),A ; DO IT
;
; SETUP THE DISPATCH TABLE ENTRIES
;
LD B,UART_CNT ; LOOP CONTROL
LD C,0 ; PHYSICAL UNIT INDEX
XOR A ; ZERO TO ACCUM
LD (UART_DEV),A ; CURRENT DEVICE NUMBER
UART_PREINIT0:
PUSH BC ; SAVE LOOP CONTROL
LD A,C ; PHYSICAL UNIT TO A
RLCA ; MULTIPLY BY CFG TABLE ENTRY SIZE (8 BYTES)
RLCA ; ...
RLCA ; ... TO GET OFFSET INTO CFG TABLE
LD HL,UART_CFG ; POINT TO START OF CFG TABLE
CALL ADDHLA ; HL := ENTRY ADDRESS
PUSH HL ; SAVE IT
PUSH HL ; COPY CFG DATA PTR
POP IY ; ... TO IY
CALL UART_INITUNIT ; HAND OFF TO GENERIC INIT CODE
POP DE ; GET ENTRY ADDRESS BACK, BUT PUT IN DE
POP BC ; RESTORE LOOP CONTROL
;
LD A,(IY + 1) ; GET THE UART TYPE DETECTED
OR A ; SET FLAGS
JR Z,UART_PREINIT2 ; SKIP IT IF NOTHING FOUND
;
PUSH BC ; SAVE LOOP CONTROL
LD BC,UART_FNTBL ; BC := FUNCTION TABLE ADDRESS
CALL NZ,CIO_ADDENT ; ADD ENTRY IF UART FOUND, BC:DE
POP BC ; RESTORE LOOP CONTROL
;
UART_PREINIT2:
INC C ; NEXT PHYSICAL UNIT
DJNZ UART_PREINIT0 ; LOOP UNTIL DONE
XOR A ; SIGNAL SUCCESS
RET ; AND RETURN
;
; UART INITIALIZATION ROUTINE
;
UART_INITUNIT:
; DETECT THE UART TYPE
CALL UART_DETECT ; DETERMINE UART TYPE
LD (IY + 1),A ; ALSO SAVE IN CONFIG TABLE
OR A ; SET FLAGS
RET Z ; ABORT IF NOTHING THERE
; UPDATE WORKING UART DEVICE NUM
LD HL,UART_DEV ; POINT TO CURRENT UART DEVICE NUM
LD A,(HL) ; PUT IN ACCUM
INC (HL) ; INCREMENT IT (FOR NEXT LOOP)
LD (IY),A ; UDPATE UNIT NUM
; SET DEFAULT CONFIG
LD DE,-1 ; LEAVE CONFIG ALONE
JP UART_INITDEV ; IMPLEMENT IT AND RETURN
;
;
;
UART_INIT:
LD B,UART_CNT ; COUNT OF POSSIBLE UART UNITS
LD C,0 ; INDEX INTO UART CONFIG TABLE
UART_INIT1:
PUSH BC ; SAVE LOOP CONTROL
LD A,C ; PHYSICAL UNIT TO A
RLCA ; MULTIPLY BY CFG TABLE ENTRY SIZE (8 BYTES)
RLCA ; ...
RLCA ; ... TO GET OFFSET INTO CFG TABLE
LD HL,UART_CFG ; POINT TO START OF CFG TABLE
CALL ADDHLA ; HL := ENTRY ADDRESS
PUSH HL ; COPY CFG DATA PTR
POP IY ; ... TO IY
LD A,(IY + 1) ; GET UART TYPE
OR A ; SET FLAGS
CALL NZ,UART_PRTCFG ; PRINT IF NOT ZERO
POP BC ; RESTORE LOOP CONTROL
INC C ; NEXT UNIT
DJNZ UART_INIT1 ; LOOP TILL DONE
;
XOR A ; SIGNAL SUCCESS
RET ; DONE
;
; DRIVER FUNCTION TABLE
;
UART_FNTBL:
.DW UART_IN
.DW UART_OUT
.DW UART_IST
.DW UART_OST
.DW UART_INITDEV
.DW UART_QUERY
.DW UART_DEVICE
#IF (($ - UART_FNTBL) != (CIO_FNCNT * 2))
.ECHO "*** INVALID UART FUNCTION TABLE ***\n"
#ENDIF
;
;
;
UART_IN:
CALL UART_IST ; RECEIVED CHAR READY?
JR Z,UART_IN ; LOOP IF NOT
LD C,(IY + 2) ; C := BASE UART PORT (WHICH IS ALSO RBR REG)
IN E,(C) ; CHAR READ TO E
XOR A ; SIGNAL SUCCESS
RET ; AND DONE
;
;
;
UART_OUT:
CALL UART_OST ; READY FOR CHAR?
JR Z,UART_OUT ; LOOP IF NOT
LD C,(IY + 2) ; C := BASE UART PORT (WHICH IS ALSO THR REG)
OUT (C),E ; SEND CHAR FROM E
XOR A ; SIGNAL SUCCESS
RET
;
;
;
UART_IST:
LD C,(IY + 3) ; C := LINE STATUS REG (LSR)
IN A,(C) ; GET STATUS
AND $01 ; ISOLATE BIT 0 (RECEIVE DATA READY)
JP Z,CIO_IDLE ; NOT READY, RETURN VIA IDLE PROCESSING
XOR A ; ZERO ACCUM
INC A ; ACCUM := 1 TO SIGNAL 1 CHAR WAITING
RET ; DONE
;
;
;
UART_OST:
LD C,(IY + 3) ; C := LINE STATUS REG (LSR)
IN A,(C) ; GET STATUS
AND $20 ; ISOLATE BIT 5 ()
JP Z,CIO_IDLE ; NOT READY, RETURN VIA IDLE PROCESSING
XOR A ; ZERO ACCUM
INC A ; ACCUM := 1 TO SIGNAL 1 BUFFER POSITION
RET ; DONE
;
;
;
UART_INITDEV:
; TEST FOR -1 WHICH MEANS USE CURRENT CONFIG (JUST REINIT)
LD A,D ; TEST DE FOR
AND E ; ... VALUE OF -1
INC A ; ... SO Z SET IF -1
JR NZ,UART_INITDEV1 ; IF DE == -1, REINIT CURRENT CONFIG
;
; LOAD EXISTING CONFIG TO REINIT
LD E,(IY + 4) ; LOW BYTE
LD D,(IY + 5) ; HIGH BYTE
;
UART_INITDEV1:
; DETERMINE DIVISOR
PUSH DE ; SAVE CONFIG
CALL UART_COMPDIV ; COMPUTE DIVISOR TO BC
POP DE ; RESTORE CONFIG
RET NZ ; ABORT IF COMPDIV FAILS!
;
; GOT A DIVISOR, COMMIT NEW CONFIG
LD (IY + 4),E ; SAVE LOW WORD
LD (IY + 5),D ; SAVE HI WORD
;
; START OF ACTUAL UART CONFIGURATION
LD A,80H ; DLAB IS BIT 7 OF LCR
UART_OUTP(UART_LCR) ; DLAB ON
LD A,B
UART_OUTP(UART_DLM) ; SET DIVISOR (MS)
LD A,C
UART_OUTP(UART_DLL) ; SET DIVISOR (LS)
;
; SETUP FCR (DLAB MUST STILL BE ON FOR ACCESS TO BIT 5)
LD A,%00100111 ; FIFO ENABLE & RESET, 64 BYTE FIFO ENABLE ON 750+
UART_OUTP(UART_FCR) ; DO IT
;
; SETUP LCR FROM SECOND CONFIG BYTE (DLAB IS CLEARED)
LD A,(IY + 4) ; GET CONFIG BYTE
AND ~$C0 ; ISOLATE PARITY, STOP/DATA BITS
UART_OUTP(UART_LCR) ; SAVE IT
;
; SETUP MCR FROM FIRST CONFIG BYTE
LD A,(IY + 5) ; GET CONFIG BYTE
AND ~$1F ; REMOVE ENCODED BAUD RATE BITS
OR $03 ; FORCE RTS & DTR
UART_OUTP(UART_MCR) ; SAVE IT
;
; TEST FOR EFR CAPABLE CHIPS
LD A,(IY + 1) ; GET UART TYPE
CP UART_16650 ; 16650?
JR Z,UART_INITDEV2 ; USE EFR REGISTER
CP UART_16850 ; 16850?
JR Z,UART_INITDEV2 ; USE EFR REGISTER
JR UART_INITDEV4 ; NO EFR, SKIP AHEAD
;
UART_INITDEV2:
; WE HAVE AN EFR CAPABLE CHIP, SET EFR REGISTER
UART_INP(UART_LCR) ; GET CURRENT LCR VALUE
PUSH AF ; SAVE IT
LD A,$BF ; VALUE TO ACCESS EFR
UART_OUTP(UART_LCR) ; SET VALUE IN LCR
LD A,(IY + 5) ; GET CONFIG BYTE
BIT 5,A ; AFC REQUESTED?
LD A,$C0 ; ASSUME AFC ON
JR NZ,UART_INITDEV3 ; YES, IMPLEMENT IT
XOR A ; NO AFC REQEUST, EFR := 0
;
UART_INITDEV3:
UART_OUTP(UART_EFR) ; SAVE IT
POP AF ; RECOVER ORIGINAL LCR VALUE
UART_OUTP(UART_LCR) ; AND PUT IT BACK
;
UART_INITDEV4:
#IF (UART_DEBUG)
PRTS(" [$")
; DEBUG: DUMP UART TYPE
LD A,(IY + 1)
CALL PRTHEXBYTE
; DEBUG: DUMP IIR
UART_INP(UART_IIR)
CALL PC_SPACE
CALL PRTHEXBYTE
; DEBUG: DUMP LCR
UART_INP(UART_LCR)
CALL PC_SPACE
CALL PRTHEXBYTE
; DEBUG: DUMP MCR
UART_INP(UART_MCR)
CALL PC_SPACE
CALL PRTHEXBYTE
; DEBUG: DUMP EFR
UART_INP(UART_LCR)
PUSH AF
LD A,$BF
UART_OUTP(UART_LCR)
UART_INP(UART_EFR)
LD H,A
EX (SP),HL
LD A,H
UART_OUTP(UART_LCR)
POP AF
CALL PC_SPACE
CALL PRTHEXBYTE
PRTC(']')
#ENDIF
;
XOR A ; SIGNAL SUCCESS
RET
;
;
;
UART_QUERY:
LD E,(IY + 4) ; FIRST CONFIG BYTE TO E
LD D,(IY + 5) ; SECOND CONFIG BYTE TO D
XOR A ; SIGNAL SUCCESS
RET ; DONE
;
;
;
UART_DEVICE:
LD D,CIODEV_UART ; D := DEVICE TYPE
LD E,(IY) ; E := PHYSICAL UNIT
LD C,$00 ; C := DEVICE TYPE, 0x00 IS RS-232
XOR A ; SIGNAL SUCCESS
RET
;
; UART DETECTION ROUTINE
;
UART_DETECT:
;
; SEE IF UART IS THERE BY CHECKING DLAB FUNCTIONALITY
XOR A ; ZERO ACCUM
UART_OUTP(UART_IER) ; IER := 0
LD A,$80 ; DLAB BIT ON
UART_OUTP(UART_LCR) ; OUTPUT TO LCR (DLAB REGS NOW ACTIVE)
LD A,$5A ; LOAD TEST VALUE
UART_OUTP(UART_DLM) ; OUTPUT TO DLM
UART_INP(UART_DLM) ; READ IT BACK
CP $5A ; CHECK FOR TEST VALUE
JP NZ,UART_DETECT_NONE ; NOPE, UNKNOWN UART OR NOT PRESENT
XOR A ; DLAB BIT OFF
UART_OUTP(UART_LCR) ; OUTPUT TO LCR (DLAB REGS NOW INACTIVE)
UART_INP(UART_IER) ; READ IER
CP $5A ; CHECK FOR TEST VALUE
JP Z,UART_DETECT_NONE ; IF STILL $5A, UNKNOWN OR NOT PRESENT
;
; TEST FOR FUNCTIONAL SCRATCH REG, IF NOT, WE HAVE AN 8250
LD A,$5A ; LOAD TEST VALUE
UART_OUTP(UART_SCR) ; PUT IT IN SCRATCH REGISTER
UART_INP(UART_SCR) ; READ IT BACK
CP $5A ; CHECK IT
JR NZ,UART_DETECT_8250 ; STUPID 8250
;
; TEST FOR EFR REGISTER WHICH IMPLIES 16650/850
LD A,$BF ; VALUE TO ENABLE EFR
UART_OUTP(UART_LCR) ; WRITE IT TO LCR
UART_INP(UART_SCR) ; READ SCRATCH REGISTER
CP $5A ; SPR STILL THERE?
JR NZ,UART_DETECT1 ; NOPE, HIDDEN, MUST BE 16650/850
;
; RESET LCR TO DEFAULT
LD A,$80 ; DLAB BIT ON
UART_OUTP(UART_LCR) ; RESET LCR
;
; TEST FCR TO ISOLATE 16450/550/550A
LD A,$E7 ; TEST VALUE
UART_OUTP(UART_FCR) ; PUT IT IN FCR
UART_INP(UART_IIR) ; READ BACK FROM IIR
BIT 6,A ; BIT 6 IS FIFO ENABLE, LO BIT
JR Z,UART_DETECT_16450 ; IF NOT SET, MUST BE 16450
BIT 7,A ; BIT 7 IS FIFO ENABLE, HI BIT
JR Z,UART_DETECT_16550 ; IF NOT SET, MUST BE 16550
BIT 5,A ; BIT 5 IS 64 BYTE FIFO
JR Z,UART_DETECT2 ; IF NOT SET, MUST BE 16550A/C
JR UART_DETECT_16750 ; ONLY THING LEFT IS 16750
;
UART_DETECT1: ; PICK BETWEEN 16650/850
; NOT SURE HOW TO DIFFERENTIATE 16650 FROM 16850 YET
JR UART_DETECT_16650 ; ASSUME 16650
RET
;
UART_DETECT2: ; PICK BETWEEN 16550A/C
; SET AFC BIT IN FCR
LD A,$20 ; SET AFC BIT, MCR:5
UART_OUTP(UART_MCR) ; WRITE NEW FCR VALUE
;
; READ IT BACK, IF SET, WE HAVE 16550C
UART_INP(UART_MCR) ; READ BACK MCR
BIT 5,A ; CHECK AFC BIT
JR Z,UART_DETECT_16550A ; NOT SET, SO 16550A
JR UART_DETECT_16550C ; IS SET, SO 16550C
;
UART_DETECT_NONE:
LD A,(IY + 2) ; BASE IO PORT
CP $68 ; IS THIS PRIMARY SBC PORT?
JR Z,UART_DETECT_8250 ; SPECIAL CASE FOR PRIMARY UART!
LD A,UART_NONE ; IF SO, TREAT AS 8250 NO MATTER WHAT
RET
;
UART_DETECT_8250:
LD A,UART_8250
RET
;
UART_DETECT_16450:
LD A,UART_16450
RET
;
UART_DETECT_16550:
LD A,UART_16550
RET
;
UART_DETECT_16550A:
LD A,UART_16550A
RET
;
UART_DETECT_16550C:
LD A,UART_16550C
RET
;
UART_DETECT_16650:
LD A,UART_16650
RET
;
UART_DETECT_16750:
LD A,UART_16750
RET
;
UART_DETECT_16850:
LD A,UART_16850
RET
;
; COMPUTE DIVISOR TO BC
;
UART_COMPDIV:
; WE WANT TO DETERMINE A DIVISOR FOR THE UART CLOCK
; THAT RESULTS IN THE DESIRED BAUD RATE.
; BAUD RATE = UART CLK / DIVISOR, OR TO SOLVE FOR DIVISOR
; DIVISOR = UART CLK / BAUDRATE.
; THE UART CLOCK IS THE UART OSC PRESCALED BY 16. ALSO, WE CAN
; TAKE ADVANTAGE OF ENCODED BAUD RATES ALWAYS BEING A FACTOR OF 75.
; SO, WE CAN USE (UART OSC / 16 / 75) / (BAUDRATE / 75)
;
; FIRST WE DECODE THE BAUDRATE, BUT WE USE A CONSTANT OF 1 INSTEAD
; OF THE NORMAL 75. THIS PRODUCES (BAUDRATE / 75).
;
LD A,D ; GET CONFIG MSB
AND $1F ; ISOLATE ENCODED BAUD RATE
LD L,A ; PUT IN L
LD H,0 ; H IS ALWAYS ZERO
LD DE,1 ; USE 1 FOR ENCODING CONSTANT
CALL DECODE ; DE:HL := BAUD RATE, ERRORS IGNORED
EX DE,HL ; DE := (BAUDRATE / 75), DISCARD HL
LD HL,UARTOSC / 16 / 75 ; HL := (UART OSC / 16 / 75)
JP DIV16 ; BC := HL/DE == DIVISOR AND RETURN
;
;
;
UART_PRTCFG:
; ANNOUNCE PORT
CALL NEWLINE ; FORMATTING
PRTS("UART$") ; FORMATTING
LD A,(IY) ; DEVICE NUM
CALL PRTDECB ; PRINT DEVICE NUM
PRTS(": IO=0x$") ; FORMATTING
LD A,(IY + 2) ; GET BASE PORT
CALL PRTHEXBYTE ; PRINT BASE PORT
; PRINT THE UART TYPE
CALL PC_SPACE ; FORMATTING
LD A,(IY + 1) ; GET UART TYPE BYTE
RLCA ; MAKE IT A WORD OFFSET
LD HL,UART_TYPE_MAP ; POINT HL TO TYPE MAP TABLE
CALL ADDHLA ; HL := ENTRY
LD E,(HL) ; DEREFERENCE
INC HL ; ...
LD D,(HL) ; ... TO GET STRING POINTER
CALL WRITESTR ; PRINT IT
;
; ALL DONE IF NO UART WAS DETECTED
LD A,(IY + 1) ; GET UART TYPE BYTE
OR A ; SET FLAGS
RET Z ; IF ZERO, NOT PRESENT
;
PRTS(" MODE=$") ; FORMATTING
LD E,(IY + 4) ; LOAD CONFIG
LD D,(IY + 5) ; ... WORD TO DE
CALL PS_PRTSC0 ; PRINT CONFIG
;
; ; PRINT FEATURES ENABLED
; LD A,(UART_FEAT)
; BIT UART_FIFO,A
; JR Z,UART_INITUNIT2
; PRTS(" FIFO$")
;UART_INITUNIT2:
; BIT UART_AFC,A
; JR Z,UART_INITUNIT3
; PRTS(" AFC$")
;UART_INITUNIT3:
;
XOR A
RET
;
; ROUTINES TO READ/WRITE PORTS INDIRECTLY
;
; READ VALUE OF UART PORT ON TOS INTO REGISTER A
;
UART_INP_IMP:
EX (SP),HL ; SWAP HL AND TOS
PUSH BC ; PRESERVE BC
LD A,(IY + 2) ; GET UART IO BASE PORT
OR (HL) ; OR IN REGISTER ID BITS
LD C,A ; C := PORT
IN A,(C) ; READ PORT INTO A
POP BC ; RESTORE BC
INC HL ; BUMP HL PAST REG ID PARM
EX (SP),HL ; SWAP BACK HL AND TOS
RET
;
; WRITE VALUE IN REGISTER A TO UART PORT ON TOS
;
UART_OUTP_IMP:
EX (SP),HL ; SWAP HL AND TOS
PUSH BC ; PRESERVE BC
LD B,A ; PUT VALUE TO WRITE IN B
LD A,(IY + 2) ; GET UART IO BASE PORT
OR (HL) ; OR IN REGISTER ID BITS
LD C,A ; C := PORT
OUT (C),B ; WRITE VALUE TO PORT
POP BC ; RESTORE BC
INC HL ; BUMP HL PAST REG ID PARM
EX (SP),HL ; SWAP BACK HL AND TOS
RET
;
;
;
UART_TYPE_MAP:
.DW UART_STR_NONE
.DW UART_STR_8250
.DW UART_STR_16450
.DW UART_STR_16550
.DW UART_STR_16550A
.DW UART_STR_16550C
.DW UART_STR_16650
.DW UART_STR_16750
.DW UART_STR_16850
UART_STR_NONE .DB "<NOT PRESENT>$"
UART_STR_8250 .DB "8250$"
UART_STR_16450 .DB "16450$"
UART_STR_16550 .DB "16550$"
UART_STR_16550A .DB "16550A$"
UART_STR_16550C .DB "16550C$"
UART_STR_16650 .DB "16650$"
UART_STR_16750 .DB "16750$"
UART_STR_16850 .DB "16850$"
;
UART_PAR_MAP .DB "NONENMNS"
;
; WORKING VARIABLES
;
UART_DEV .DB 0 ; DEVICE NUM USED DURING INIT
;
; UART PORT TABLE
;
UART_CFG:
#IF (UARTSBC)
; SBC/ZETA ONBOARD SERIAL PORT
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $68 ; IO PORT BASE (RBR, THR)
.DB $68 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
#ENDIF
#IF (UARTCAS)
; CASSETTE INTERFACE SERIAL PORT
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $80 ; IO PORT BASE (RBR, THR)
.DB $80 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCASSPD ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
#ENDIF
#IF (UARTMFP)
; MF/PIC SERIAL PORT
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $48 ; IO PORT BASE (RBR, THR)
.DB $48 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
#ENDIF
#IF (UART4)
; 4UART SERIAL PORT A
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $C0 ; IO PORT BASE (RBR, THR)
.DB $C0 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
; 4UART SERIAL PORT B
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $C8 ; IO PORT BASE (RBR, THR)
.DB $C8 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
; 4UART SERIAL PORT C
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $D0 ; IO PORT BASE (RBR, THR)
.DB $D0 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
; 4UART SERIAL PORT D
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $D8 ; IO PORT BASE (RBR, THR)
.DB $D8 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
#ENDIF
#IF (UARTRC)
; UARTRC SERIAL PORT A
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $A0 ; IO PORT BASE (RBR, THR)
.DB $A0 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
; UARTRC SERIAL PORT B
.DB 0 ; DEVICE NUMBER (UPDATED DURING INIT)
.DB 0 ; UART TYPE
.DB $A8 ; IO PORT BASE (RBR, THR)
.DB $A8 + UART_LSR ; LINE STATUS PORT (LSR)
.DW UARTCFG ; LINE CONFIGURATION
.FILL 2,$FF ; FILLER
#ENDIF
;
UART_CNT .EQU ($ - UART_CFG) / 8