From 9605d80b99dd89dbdffb46439d74cc11aad44c42 Mon Sep 17 00:00:00 2001 From: Wayne Warthen Date: Fri, 8 Apr 2016 18:04:06 -0700 Subject: [PATCH] Code Cleaning --- Source/Apps/Assign.asm | 76 +++++++++++++--------- Source/HBIOS/Config/plt_mk4.asm | 23 ++++++- Source/HBIOS/hbios.asm | 6 +- Source/HBIOS/romldr.asm | 10 +-- Source/HBIOS/uart.asm | 112 +++++++++++++++++--------------- 5 files changed, 137 insertions(+), 90 deletions(-) diff --git a/Source/Apps/Assign.asm b/Source/Apps/Assign.asm index d01197fb..01d6ecf4 100644 --- a/Source/Apps/Assign.asm +++ b/Source/Apps/Assign.asm @@ -19,7 +19,7 @@ ; ; Change Log: ; 2016-03-21 [WBW] Updated for HBIOS 2.8 -; 2016-04-07 [WBW] Determine key memory addresses dynamically +; 2016-04-08 [WBW] Determine key memory addresses dynamically ;_______________________________________________________________________________ ; ; ToDo: @@ -140,20 +140,21 @@ init: ld (bioend),hl ; save as CBIOS end address ; ; check for UNA (UBIOS) - ld a,($fffd) ; fixed location of UNA API vector - cp $c3 ; jp instruction? + ld a,($FFFD) ; fixed location of UNA API vector + cp $C3 ; jp instruction? jr nz,initx ; if not, not UNA - ld hl,($fffe) ; get jp address + ld hl,($FFFE) ; get jp address ld a,(hl) ; get byte at target address - cp $fd ; first byte of UNA push ix instruction + cp $FD ; first byte of UNA push ix instruction jr nz,initx ; if not, not UNA inc hl ; point to next byte ld a,(hl) ; get next byte - cp $e5 ; second byte of UNA push ix instruction + cp $E5 ; second byte of UNA push ix instruction jr nz,initx ; if not, not UNA ld hl,unamod ; point to UNA mode flag - ld (hl),$ff ; set UNA mode - ld hl,$FF00 ; assumed start of UNA proxy + ld (hl),$FF ; set UNA mode flag + ld c,$F1 ; UNA func: Get HMA + rst 08 ; call UNA, HL := UNA proxy start address ld (bioend),hl ; save as CBIOS end address ; initx: @@ -169,6 +170,23 @@ initx: ld de,-$40 ; allow 40 bytes for CBIOS stack add hl,de ; adjust ld (heaplim),hl ; save it +; +#if 0 + ld a,' ' + call crlf + ld bc,(bioloc) + call prthexword + call prtchr + ld bc,(bioend) + call prthexword + call prtchr + ld bc,(maploc) + call prthexword + call prtchr + ld bc,(heaplim) + call prthexword + +#endif ; ; return success xor a ; signal success @@ -295,7 +313,7 @@ usage: call crlf2 ; blank line ld de,msguse ; point to usage message call prtstr ; print it - or $ff ; signal no action performed + or $FF ; signal no action performed ret ; and return ; devlist: @@ -304,7 +322,7 @@ devlist: or a ; set flags jr nz,devlstu ; do UNA mode dev list ; - ld b,$f7 ; hbios func: sysget + ld b,$F7 ; hbios func: sysget ld c,$10 ; sysget subfunc: diocnt rst 08 ; call hbios, E := device count ld b,e ; use device count for loop count @@ -321,7 +339,7 @@ devlist1: pop bc ; restore loop control inc c ; next device index djnz devlist1 ; loop as needed - or $ff ; signal no action taken + or $FF ; signal no action taken ret ; done ; devlstu: @@ -427,7 +445,7 @@ dph_init: dph_init1: ; no DPH if drive not assigned ld a,(hl) - cp $ff + cp $FF jr nz,dph_init2 ld de,0 ; not assigned, use DPH pointer of zero jr dph_init3 @@ -519,7 +537,7 @@ makdphwbw: ; determine appropriate dpb (WBW mode) ld e,2 ; assume ram cp $00+1 ; ram? jr z,makdph0 ; yes, jump ahead - and $f0 ; ignore unit nibble now + and $F0 ; ignore unit nibble now ld e,6 ; assume floppy cp $10 ; floppy? jr z,makdph0 ; yes, jump ahead @@ -661,7 +679,7 @@ valid: ld b,16 - 1 ; loop one less times than num entries ; ; check that drive A: is assigned - ld a,$ff ; value that indicates unassigned + ld a,$FF ; value that indicates unassigned cp (hl) ; compare to A: value jp z,errnoa ; handle failure ; @@ -688,7 +706,7 @@ valid2: ; setup for inner loop valid3: ; inner loop ; bypass unassigned drives (only need to test 1) ld a,(hl) ; get first drive unit in A - cp $ff ; unassigned? + cp $FF ; unassigned? jr z,valid4 ; yes, skip ; ; compare unit/slice values @@ -735,7 +753,7 @@ drvdel: rlca ; ... as drive num * 4 call addhl ; get final table offset ; wipe out the drive letter - ld a,$ff ; dev/unit := $FF (unassigned) + ld a,$FF ; dev/unit := $FF (unassigned) ld (hl),a ; do it xor a ; zero accum inc hl ; slice := 0 @@ -854,7 +872,7 @@ drvmap2: ld (device),a ; save as device id ; ; loop thru hbios units looking for device type/unit match - ld b,$f7 ; hbios func: sysget + ld b,$F7 ; hbios func: sysget ld c,$10 ; sysget subfunc: diocnt rst 08 ; call hbios, E := device count ld b,e ; use device count for loop count @@ -991,7 +1009,7 @@ showall: ld c,0 ; map index (drive letter) ; ld a,b ; load count - or $ff ; signal no action + or $FF ; signal no action ret z ; bail out if zero ; showall1: ; loop @@ -1001,7 +1019,7 @@ showall1: ; loop pop bc ; restore loop control inc c djnz showall1 - or $ff + or $FF ret ; ; Display drive letter assignment IF it is assigned @@ -1016,7 +1034,7 @@ showass: rlca call addhl ; HL = address of drive map table entry ld a,(hl) ; get unit value - cp $ff ; compare to unassigned value + cp $FF ; compare to unassigned value ld a,c ; recover original drive num ret z ; bail out if unassigned drive ; fall thru to display drive @@ -1065,11 +1083,11 @@ showone: ; Force BDOS to reset (logout) all drives ; drvrst: - ld c,$0d ; BDOS Reset Disk function + ld c,$0D ; BDOS Reset Disk function call bdos ; do it ; ld c,$25 ; BDOS Reset Multiple Drives - ld de,$ffff ; all drives + ld de,$FFFF ; all drives call bdos ; do it ; xor a ; signal success @@ -1092,7 +1110,7 @@ prtdev: rrca ; ... rrca ; ... rrca ; ... into low nibble - and $0f ; mask out undesired bits + and $0F ; mask out undesired bits push hl ; save HL add a,a ; multiple A by two for word table ld hl,devtbl ; point to start of device name table @@ -1175,7 +1193,7 @@ chkdrv: ; chkdev: ; HBIOS variant push af ; save incoming unit - ld b,$f7 ; hbios func: sysget + ld b,$F7 ; hbios func: sysget ld c,$10 ; sysget subfunc: diocnt rst 08 ; call hbios, E := device count pop af ; restore incoming unit @@ -1308,7 +1326,7 @@ hexascii: ; Convert low nibble of A to ascii hex ; hexconv: - and $0f ; low nibble only + and $0F ; low nibble only add a,$90 daa adc a,$40 @@ -1402,7 +1420,7 @@ delim: or a ret z cp ':' ; colon ret z - cp $3b ; semicolon + cp $3B ; semicolon ret z cp '<' ; less than ret z @@ -1500,7 +1518,7 @@ strcmp: ; The CBIOS function offset must be stored in the byte ; following the call instruction. ex: ; call cbios -; .db $0c ; offset of CONOUT CBIOS function +; .db $0C ; offset of CONOUT CBIOS function ; cbios: ex (sp),hl @@ -1603,7 +1621,7 @@ err1: ; without the leading crlf ; err2: ; without the string ; call crlf ; print newline - or $ff ; signal error + or $FF ; signal error ret ; done ; ;=============================================================================== @@ -1624,7 +1642,7 @@ device .db 0 ; source device unit .db 0 ; source unit slice .db 0 ; source slice ; -unamod .db 0 ; $ff indicates UNA UBIOS active +unamod .db 0 ; $FF indicates UNA UBIOS active modcnt .db 0 ; count of drive map modifications ; srcptr .dw 0 ; source pointer for copy diff --git a/Source/HBIOS/Config/plt_mk4.asm b/Source/HBIOS/Config/plt_mk4.asm index e4615f6d..ef931ea8 100644 --- a/Source/HBIOS/Config/plt_mk4.asm +++ b/Source/HBIOS/Config/plt_mk4.asm @@ -18,8 +18,27 @@ SIMRTCENABLE .EQU FALSE ; SIMH CLOCK DRIVER DSRTCENABLE .EQU TRUE ; DS-1302 CLOCK DRIVER DSRTCMODE .EQU DSRTCMODE_STD ; DSRTCMODE_STD, DSRTCMODE_MFPIC ; -UARTENABLE .EQU FALSE ; TRUE FOR UART SUPPORT (N8 USES ASCI DRIVER) -UARTCNT .EQU 0 ; NUMBER OF UARTS +UARTENABLE .EQU TRUE ; TRUE FOR UART SUPPORT (ALMOST ALWAYS WANT THIS TO BE TRUE) +UARTOSC .EQU 1843200 ; UART OSC FREQUENCY +UARTCNT .EQU 6 ; NUMBER OF UARTS +UART0IOB .EQU $80 ; IOBASE (CASSETTE INTERFACE) +UART0BAUD .EQU CONBAUD ; BAUDRATE +UART0FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC +UART1IOB .EQU $88 ; IOBASE (MF/PIC) +UART1BAUD .EQU CONBAUD ; BAUDRATE +UART1FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC +UART2IOB .EQU $C0 ; IOBASE (4UART PORT A) +UART2BAUD .EQU CONBAUD ; BAUDRATE +UART2FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC +UART3IOB .EQU $C8 ; IOBASE (4UART PORT B) +UART3BAUD .EQU CONBAUD ; BAUDRATE +UART3FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC +UART4IOB .EQU $D0 ; IOBASE (4UART PORT C) +UART4BAUD .EQU CONBAUD ; BAUDRATE +UART4FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC +UART5IOB .EQU $D8 ; IOBASE (4UART PORT D) +UART5BAUD .EQU CONBAUD ; BAUDRATE +UART5FEAT .EQU UF_FIFO ; FEATURE FLAGS: UF_FIFO | UF_AFC ; ASCIENABLE .EQU TRUE ; TRUE FOR Z180 ASCI SUPPORT ASCI0BAUD .EQU CONBAUD ; ASCI0 BAUDRATE (IMPLEMENTED BY Z180_ASCIB0) diff --git a/Source/HBIOS/hbios.asm b/Source/HBIOS/hbios.asm index 144e622d..2c165cd2 100644 --- a/Source/HBIOS/hbios.asm +++ b/Source/HBIOS/hbios.asm @@ -609,12 +609,12 @@ INITSYS2: ;================================================================================================== ; HB_INITTBL: -#IF (UARTENABLE) - .DW UART_INIT -#ENDIF #IF (ASCIENABLE) .DW ASCI_INIT #ENDIF +#IF (UARTENABLE) + .DW UART_INIT +#ENDIF #IF (SIMRTCENABLE) .DW SIMRTC_INIT #ENDIF diff --git a/Source/HBIOS/romldr.asm b/Source/HBIOS/romldr.asm index 9e6179de..3a7463aa 100644 --- a/Source/HBIOS/romldr.asm +++ b/Source/HBIOS/romldr.asm @@ -755,9 +755,9 @@ PRTDRV: LD A,E ; LOAD DRIVER MODE/UNIT AND $0F ; ISOLATE UNIT CALL PRTDECB ; PRINT IT -; CALL PC_COLON ; FORMATTING -; LD A,E ; LOAD LU -; CALL PRTDECB ; PRINT IT + CALL PC_COLON ; FORMATTING + ;LD A,E ; LOAD LU + ;CALL PRTDECB ; PRINT IT RET ; DEVTBL: ; DEVICE TABLE @@ -867,7 +867,7 @@ STR_CPMLOC .DB "LOC=$" STR_CPMEND .DB "END=$" STR_CPMENT .DB "ENT=$" STR_LABEL .DB "LABEL=$" -STR_DRVLIST .DB "\r\nDevices:\r\n$" +STR_DRVLIST .DB "\r\nDisk Devices:\r\n$" STR_PREFIX .DB "\r\n $" STR_LOADING .DB "\r\nLoading$" STR_NODISK .DB "\r\nNo disk!$" @@ -876,7 +876,7 @@ STR_BOOTERR .DB "\r\nBoot failure!$" ; STR_BANNER .DB "\r\n", PLATFORM_NAME, " Boot Loader$" STR_BOOTMENU .DB "\r\nBoot: (C)PM, (Z)System, (M)onitor,\r\n" - .DB " (L)ist devices, or Device ID ===> $" + .DB " (L)ist disks, or Disk Unit # ===> $" ; .IF DSKYENABLE BOOT: diff --git a/Source/HBIOS/uart.asm b/Source/HBIOS/uart.asm index e6e8a95e..b4d1c499 100644 --- a/Source/HBIOS/uart.asm +++ b/Source/HBIOS/uart.asm @@ -45,59 +45,47 @@ UART_INIT: ; ; 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 + LD A,$80 ; SELECT 7.3728MHZ OSC & LOCK CONFIG REGISTER + OUT ($CF),A ; DO IT ; ; SETUP THE DISPATCH TABLE ENTRIES ; - LD B,UARTCNT ; LOOP CONTROL - LD C,0 ; PHYSICAL UNIT INDEX -UART_INIT0: - 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 - CALL UART_INIT1 ; DO HARDWARE INIT FOR CURRENT UART - POP DE ; GET ENTRY ADDRESS BACK, BUT PUT IN DE - POP BC ; RESTORE LOOP CONTROL - - LD A,(UART_TYPE) ; GET THE UART TYPE DETECTED - OR A ; SET FLAGS + LD B,UARTCNT ; LOOP CONTROL + LD C,0 ; PHYSICAL UNIT INDEX + XOR A ; ZERO TO ACCUM + LD (UART_DEV),A ; CURRENT DEVICE NUMBER +UART_INIT0: + 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 + CALL UART_INIT1 ; DO HARDWARE INIT FOR CURRENT UART + POP DE ; GET ENTRY ADDRESS BACK, BUT PUT IN DE + POP BC ; RESTORE LOOP CONTROL - PUSH BC ; SAVE LOOP CONTROL - ;LD B,C ; PHYSICAL UNIT -> B - ;LD C,CIODEV_UART ; DEVICE TYPE -> C + LD A,(UART_TYPE) ; GET THE UART TYPE DETECTED + OR A ; SET FLAGS + JR Z,UART_INIT00 ; SKIP IT IF NOTHING FOUND + + PUSH BC ; SAVE LOOP CONTROL LD BC,UART_DISPATCH ; BC := DISPATCH ADDRESS - CALL NZ,CIO_ADDENT ; ADD ENTRY IF UART FOUND, BC:DE - POP BC ; RESTORE LOOP CONTROL - - INC C ; NEXT PHYSICAL UNIT - DJNZ UART_INIT0 ; LOOP UNTIL DONE - XOR A ; SIGNAL SUCCESS - RET ; AND RETURN + CALL NZ,CIO_ADDENT ; ADD ENTRY IF UART FOUND, BC:DE + POP BC ; RESTORE LOOP CONTROL + +UART_INIT00: + INC C ; NEXT PHYSICAL UNIT + DJNZ UART_INIT0 ; LOOP UNTIL DONE + XOR A ; SIGNAL SUCCESS + RET ; AND RETURN ; UART_INIT1: PUSH HL ; COPY CFG DATA PTR POP IY ; ... TO IY - ; INIT PORT BASED ON CONFIG AT HL - CALL NEWLINE ; FORMATTING - PRTS("UART$") ; FORMATTING - LD A,(HL) ; DEVICE NUM - CALL PRTDECB ; PRINT DEVICE NUM - PRTS(": IO=0x$") ; FORMATTING - INC HL ; BUMP TO BASE PORT FIELD - LD A,(HL) ; GET BASE PORT - CALL PRTHEXBYTE ; PRINT BASE PORT ; - ; SETUP FOR GENERIC INIT ROUTINE - INC HL ; BUMP TO - INC HL ; ... FEATURES BYTE - LD A,(HL) ; GET FEATURES BYTE - LD (UART_FUNC),A ; SAVE IT JP UART_INITP ; HAND OFF TO GENERIC INIT CODE ; ; @@ -209,7 +197,28 @@ UART_INITP00: UART_INITP0: ; DETECT THE UART TYPE CALL UART_DETECT ; DETERMINE UART TYPE + OR A ; SET FLAGS + RET Z ; ABORT IF NOTHING THERE LD (UART_TYPE),A ; SAVE TYPE + + ; 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 + + ; 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 + 1) ; GET BASE PORT + CALL PRTHEXBYTE ; PRINT BASE PORT +; + ; SETUP FOR GENERIC INIT ROUTINE + LD A,(IY + 3) ; GET FEATURES BYTE + LD (UART_FUNC),A ; SAVE IT ; RESET FEATURE BITS LD HL,UART_FEAT ; HL POINTS TO FEATURE FLAGS BYTE @@ -590,12 +599,13 @@ UART_STR_16850 .DB "16850$" UART_TYPE .DB 0 ; UART TYPE DISCOVERED UART_FUNC .DB 0 ; UART FUNCTIONS REQUESTED UART_FEAT .DB 0 ; UART FEATURES DISCOVERED +UART_DEV .DB 0 ; DEVICE NUM USED DURING INIT ; ; UART PORT TABLE ; UART_CFG: #IF (UARTCNT >= 1) - .DB 0 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART0IOB ; IO PORT BASE (RBR, THR) .DB UART0IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART0FEAT @@ -603,7 +613,7 @@ UART_CFG: .DW UART0BAUD >> 16 #ENDIF #IF (UARTCNT >= 2) - .DB 1 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART1IOB ; IO PORT BASE .DB UART1IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART1FEAT @@ -611,7 +621,7 @@ UART_CFG: .DW UART1BAUD >> 16 #ENDIF #IF (UARTCNT >= 3) - .DB 2 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART2IOB ; IO PORT BASE .DB UART2IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART2FEAT @@ -619,7 +629,7 @@ UART_CFG: .DW UART2BAUD >> 16 #ENDIF #IF (UARTCNT >= 4) - .DB 3 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART3IOB ; IO PORT BASE .DB UART3IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART3FEAT @@ -627,7 +637,7 @@ UART_CFG: .DW UART3BAUD >> 16 #ENDIF #IF (UARTCNT >= 5) - .DB 4 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART4IOB ; IO PORT BASE .DB UART4IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART4FEAT @@ -635,7 +645,7 @@ UART_CFG: .DW UART4BAUD >> 16 #ENDIF #IF (UARTCNT >= 6) - .DB 5 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART5IOB ; IO PORT BASE .DB UART5IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART5FEAT @@ -643,7 +653,7 @@ UART_CFG: .DW UART5BAUD >> 16 #ENDIF #IF (UARTCNT >= 7) - .DB 6 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART6IOB ; IO PORT BASE .DB UART6IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART6FEAT @@ -651,7 +661,7 @@ UART_CFG: .DW UART6BAUD >> 16 #ENDIF #IF (UARTCNT >= 8) - .DB 7 ; DEVICE NUMBER + .DB 0 ; DEVICE NUMBER (UPDATED DURING INIT) .DB UART7IOB ; IO PORT BASE .DB UART7IOB + UART_LSR ; LINE STATUS PORT (LSR) .DB UART7FEAT