; * * * * BAUD.MAC Vers 1.1 25Mar87 * * * * ; upgraded to 9mhz operation by Al Heynneman ; - changed baud rate tables. ; - changed match routine for new prescaler value. ; - fixed misc typos in help messages. TITLE HITACHI HD64180 CPU Baud rate change utility. Subttl By W. Brimhall / Znode 52 (602)996-8739 ;COMMAND LINE SYNTAX: ;HBAUD Display current baud rates. ;HBAUD // Display Help info. ;HBAUD C=R Set baud rate of SIO Channel C (0 or 1) to R ; (150,300,600,1200,2400,4800,9600,19200). ;Command lines used to generate this program: ; M80 =HBAUD ;assemble into .rel file ; LINK HBAUD,CONIO,SUBLIB[S] ;link into .com file ; + + + + XL-M180 port equates + + + + ;The following values are the offset from the HD64180 internal IO ;port base to the address of the selected port. frc equ 18h ;free running counter port bdrate0 equ 2 ;baud rate port cr equ 0dh lf equ 0ah tab equ 09h esc equ 1bh name ('baud') .z80 ; + + + + ilprn + + + + ;This macro sets up calls to a special inline string print subroutine ;that will not lose control when tracing with the ZSID TW command. ilprn macro call ilprn@## ;subroutine library routine ret ;extra ret needed endm ; + + + + print + + + + ;This macro prints the string addressed by hl on the console. It must ;terminate with 0h. print macro call print@## ;subroutine library routine endm ; + + + + MAIN PROGRAM + + + + baud:: ld (stack),sp ;save ccp stack pointer ld sp,stack ;set up new stack call lociob ;locate the HD64180 iobase register jp c,abort ;abort if iobase not found ld a,(80H) ;a= command line length or A jp z,crates ;display current baud rates if a= 0 cp 4 jp C,help ;display help info if A < 4. ;Extract parameters from CP/M command line ld de,81h ;DE --> command line buffer ld l,a ld h,0 ;HL = # of chars in buffer add hl,de ;HL --> end of buffer ld (hl),0 ;terminate buffer with 0H ex de,hl ;HL --> start of buffer ld (scnptr##),hl ;scnptr --> start of buffer baud0:: call next## ;get channel cp '0' jp c,error1 ;error if ch < "0" cp '2' jp nc,error1 ;error if ch > "1" sub '0' ;convert to binary ld (chanel),a ;save channel call next## cp '=' jp nz,error3 ;error if bad delimiter call parm## ;extract baud rate jp c,error ;error if cf set ld (bdrate),hl ;store baud rate ;Lookup baud rate in table lookup:: ld hl,brtbl ;hl --> baud rate table look1: ld e,(hl) inc hl ld d,(hl) ;de= dec baud rate from table inc hl ;hl--> port value ld a,d or e ;check for end of table jp z,error2 ;jmp if end of table push hl ;save table pointer ld hl,(bdrate) ;hl= selected baud rate xor a sbc hl,de ;compare selection to table pop hl ;hl= table pointer jr z, match ;jmp if match inc hl ;hl--> next baud rate jr look1 ;Output rate byte to selected baud rate port. match:: ld c,bdrate0 ;c= offset from iobase to ch0 baud rate port call addiob ;bc--> ch0 baud rate port ld a,(chanel) ;a= selected channel (0 or 1) add a,c ld c,a ;bc--> selected baud rate port ld a,(hl) ;a= baud rate byte from table ADD A,20h ;BAUD RATE GEN PRESCALE FACTOR out (c),a ;set new baud rate ;Continue setting baud rates until command line is exhausted. call next## ;get next char from command line or a jr nz,baud0 ;loop til end of command line call drates ;display new baud rates ;fall into quit ; + + + + QUIT + + + + ;Perform a quick exit by restoring the CCP stack ;pointer & returning to the CCP. quit:: call crlf ld sp,(stack) ret ; + + + + ABORT + + + + abort:: ilprn db '+ + For use with HITACHI HD64180 CPUs only!!!',cr,lf db ' (Couldn''t locate iobase register.)',cr,lf,0 jp quit ; + + + + BRTBL + + + + ;Baud rate table ;NOTE: ;Actual baud rate values are hex values shown below + 20h. ;Bit 5 of CNTLA0/B0 indicates port CTS state when it is read, ;but acts as the baud rate generator prescaler value when written. ;See patch in "match::" subroutine above. brtbl:: dw 150 ;16 bit baud rate db 0Dh ;rate byte to output to port dw 300 db 06h dw 600 db 05h dw 1200 db 04h dw 2400 db 03h dw 4800 db 02h dw 9600 db 01h dw 19200 db 0 ; ; dw 38400 ;NOT SUPPORTED AT 9MHZ ; db 0 ;NOT SUPPORTED AT 9MHZ ; dw 0 ;end of table ; + + + + ERROR + + + + ;Display selected error message & exit to the OS. error:: dec a ;make error code 0 based ld hl,msgtbl ;HL --> error message table call selmsg@## ;display selected message jp quit error1::ld hl,msg4 print jp quit error2:: ld hl,msg2 print jp quit error3:: ld hl,msg3 print jp quit ; + + + + error messages + + + + msgtbl:: dw msg1,msg2,msg3 ;message address table msg1:: db '++ILLEGAL CHARACTER IN COMMAND LINE',0 msg2:: db '++BAD BAUD RATE (150,300,600,1200,2400,4800,' db '9600,19200)',0 msg3:: db '++COMMAND LINE SYNTAX ERROR',0 msg4:: db '++BAD SIO CHANNEL (0 or 1)',0 ; + + + + CRATES + + + + ;Display the current baud rates and exit back to the CCP. crates:: call drates ;display baud rates jp quit ;quick exit to ccp ; + + + + HELP + + + + ;Display HELP message & exit to the CCP. help:: ilprn db cr,lf,'HBAUD.COM Vers 1.1 25Mar87',cr,lf db ' by W. Brimhall / Z-Node 52 (602)996-8739',cr,lf db ' updated to 9mhz operation by Al Heynneman',cr,lf,lf db '+ + For use with 9mhz HD64180 CPUs ONLY!!! + +' db cr,lf,lf db 'This program let''s you set and display the SIO channel' db ' baud rates.',cr,lf db '(The baud rate ports are automatically found, so ' db 'the HD64180 IO base can',cr,lf db ' be relocated to any address.)',cr,lf,lf db 'HBAUD ;Display current baud rates.',cr,lf db 'HBAUD // ;Display this help info.',cr,lf db 'HBAUD C=R ;Set SIO Channel C (0 or 1) to baud Rate R' db cr,lf db ' ;(150,300,600,1200,2400,4800,9600,19200' db ').',cr,lf db ' ;(Both channels can be set on the same ' db 'command',cr,lf db ' ;line if they are seperated with commas.)',cr,lf db 'Example:',cr,lf db ' HBAUD 1=19200,0=2400 ;set ch1 to 19200bps, ch0 to ' db '2400bps.',cr,lf,0 jp quit ;quick exit to ccp ; + + + + DRATES + + + + ;Display the current baud rates. drates:: ilprn db cr,lf db 'Current Baud Rates: Ch0=',0 ld c,bdrate0 ;c= offset from iob to ch0 baud rate port call addiob ;bc--> ch0 baud rate port call lup ;look up baud rate and print it ilprn db 'bps, Ch1=',0 inc bc ;bc--> ch1 baud rate port call lup ;look up baud rate and print it ilprn db 'bps',cr,lf,0 ret ; + + + + LUP + + + + ;Use the baud rate byte input from the selected sio channel baud rate ;port to look up the current 16 bit baud rate value from the brtbl and ;display it. If the port byte is not found in the table then display ;????? instead of the 16 bit value. ;inputs: ;bc--> selected channel baud rate port lup: ld hl,brtbl ;hl--> baud rate table lup1: ld e,(hl) inc hl ld d,(hl) ;de= 16 bit baud rate ld a,e or d jr z,lup3 ;jmp if end of table inc hl ;hl--> port rate byte push de ;save 16 bit rate ld e,(hl) ;e= rate byte from table in a,(c) ;a= rate byte from port and 0fh ;mask low 4 bits cp e pop de ;de= 16 bit rate jr z,lup2 ;jmp if rate bytes match inc hl jr lup1 ;loop till match or end of table lup2:: ex de,hl ;hl=16 bit rate call prndec## ;display rate in decimal ret ;No match in table, display ?????. lup3: ilprn db '?????',0 ret ; + + + + CRLF + + + + ;Output a CRLF to the console. crlf:: ilprn db cr,lf,0 ret ; + + + + LOCIOB + + + + ;Locate the base address of the HD64180 internal ports and ;store it at iobase. The ports could possibly be relocated to ;0h, 40h, 80h or C0h. Checking for the free running timer port ;seems to be the easiest way to determine where they are. Return ;with CF set if the FRC cannot be located. lociob:: ld hl,0 ;hl= inital iobase address loc0:: ld bc,frc ;bc--> free running counter if iobase= 0 push hl add hl,bc ld b,h ld c,l ;bc--> next possible FRC address pop hl ;hl= next possible iobase address ld e,5 ;test 5 bytes in a,(c) loc1:: ld d,a ;d= 1st counter byte in a,(c) ;get next counter byte cp d jr z,loc2 ;jmp if FRC value did not change dec e jr nz,loc3 ;loop til 5 FRC bytes are tested loc2:: ld bc,40h ;bc= offset to next possible iobase address add hl,bc ;hl= next possible iobase address ld a,h or a jr z,loc0 ;loop til h > 0 ;The FRC could not be located so this is probably not ;a HD64180 cpu. scf ;cf= 1 ret ;All 5 FRC bytes are different so set iobase to ;the address in hl. loc3:: ld (iobase),hl ;set the IO base address xor a ;cf= 0 ret ; + + + + ADDIOB + + + + ;Add the current internal io port base address value to reg BC. addiob: push hl ld hl,(iobase) ;hl= io base address ld b,0 add hl,bc ld c,l ld b,h ;bc= bc+(iobase) pop hl ret ; + + + + DATA STORAGE AREA + + + + chanel:: ds 1 ;selected sio channel (0 or 1) bdrate:: ds 2 ;selected 16 bit baud rate iobase:: dw 0 ;internal IO register base address ds 64 ;stack space stack:: ds 2 end