Skip to content

Commit

Permalink
Merge pull request #433 from kiwisincebirth/map/cbios-drive-select
Browse files Browse the repository at this point in the history
cbios changes to use HBIOS for Drive Slice Selection
  • Loading branch information
wwarthen authored Oct 9, 2024
2 parents 76a5f21 + 65ca9af commit ee60c11
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 79 deletions.
1 change: 1 addition & 0 deletions Doc/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Version 3.5
- MAP: Contributed COPYSL utility
- MAP: Added new HBIOS function SYSGET_DIOMED
- MAP: ROMLDR now uses SYSGET_DIOMED to get Slice Sector for boot
- MAP: CBIOS now uses SYSGET_DIOMED during drive selection

Version 3.4
-----------
Expand Down
135 changes: 61 additions & 74 deletions Source/CBIOS/cbios.asm
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ WBOOT:
LD DE,(BNKBIOS) ; UBIOS_PAGE (SEE PAGES.INC)
RST 08 ; DO IT
PUSH DE ; SAVE PREVIOUS BANK

LD HL,(CCPBUF) ; ADDRESS OF CCP BUF IN BIOS MEM
LD DE,CCP_LOC ; ADDRESS IN HI MEM OF CCP
LD BC,CCP_SIZ ; SIZE OF CCP
LDIR ; DO IT

LD BC,$01FB ; UNA FUNC = SET BANK
POP DE ; RECOVER OPERATING BANK
RST 08 ; DO IT
Expand Down Expand Up @@ -804,7 +804,7 @@ WRITE:
LD A,C
LD (WRTYPE),A ; SAVE WRITE TYPE
LD A,DOP_WRITE
JR READWRITE
;JR READWRITE ; OPTIMISATION (FALL THRU TO READWRITE)
;
;__________________________________________________________________________________________________
READWRITE:
Expand Down Expand Up @@ -1232,11 +1232,11 @@ DSK_GETINF:
RLCA ; ... TO USE AS OFFSET INTO DRVMAP
CALL ADDHLA ; ADD OFFSET
LD D,(HL) ; D := UNIT

LD A,D ; PUT UNIT IN ACCUM
INC A ; $FF -> $00
JR Z,DSK_GETINF1 ; HANDLE UNASSIGNED DRIVE LETTER

INC HL ; BUMP TO SLICE
LD E,(HL) ; E := SLICE
INC HL ; POINT TO DPH LSB
Expand All @@ -1261,7 +1261,8 @@ DSK_GETINF1: ; ERROR RETURN
INC A
RET
;
;
; BIOS FUNCTION FOR SELECTING CPM DRIVE (A-P) IN C REGISTER
; RETURN HL - BASE ADDRESS OF DPH (0x0000 FOR AN ERROR)
;
DSK_SELECT:
LD B,E ; SAVE E IN B FOR NOW
Expand Down Expand Up @@ -1321,19 +1322,8 @@ DSK_SELECT1A:
LD (MEDID),A
;
#ELSE
;
; DETERMINE MEDIA IN DRIVE
LD A,(SEKUNIT) ; GET UNIT
LD C,A ; STORE IN C
LD B,BF_DIOMEDIA ; DRIVER FUNCTION = DISK MEDIA
LD E,1 ; ENABLE MEDIA CHECK/DISCOVERY
RST 08 ; DO IT
LD A,E ; RESULTANT MEDIA ID TO ACCUM
LD (MEDID),A ; SAVE IT
OR A ; SET FLAGS
LD HL,0 ; ASSUME FAILURE
RET Z ; BAIL OUT IF NO MEDIA
;
; NOTE: Setting the (MEDID) is not required for RomWBW at this point
; The media ID is determined during call to DSK_MBR:
#ENDIF
;
; CLEAR LBA OFFSET (DWORD)
Expand All @@ -1343,24 +1333,7 @@ DSK_SELECT1A:
SET 7,H ; ASSUME LBA ACCESS FOR NOW
LD (SEKLBA+2),HL ; CLEAR SECOND WORD
;
#IFDEF PLTWBW
;
LD A,(SEKUNIT) ; GET UNIT
LD C,A ; STORE IN C
LD B,BF_DIODEVICE ; HBIOS FUNC: REPORT DEVICE INFO
RST 08 ; GET UNIT INFO, DEVICE TYPE IN D
LD A,D ; DEVICE TYPE -> A
CP DIODEV_FD ; FLOPPY?
JR NZ,DSK_SELECT1B ; IF NOT, DO LBA IO
LD HL,SEKLBA+3 ; POINT TO HIGH ORDER BYTE
RES 7,(HL) ; SWITCH FROM LBA -> CHS
;
#ENDIF
;
DSK_SELECT1B:
; SET LEGACY SECTORS PER SLICE
LD HL,16640 ; LEGACY SECTORS PER SLICE
LD (SPS),HL ; SAVE IT
;
; CHECK MBR OF PHYSICAL DISK BEING SELECTED
; WILL UPDATE MEDID AND LBAOFF IF VALID CP/M PARTITION EXISTS
Expand Down Expand Up @@ -1407,29 +1380,48 @@ DSK_SELECT2:
; THE MEDIA ID (MEDID).
;
DSK_MBR:
;
#IFDEF PLTWBW
;
; GET EXTENDED INFORMATION FOR THE DEVICE/SLICE
LD A,(SEKUNIT) ; PASSING BOOT UNIT
LD D,A
LD A,(SLICE) ; AND SLICE
LD E,A
LD B,BF_SYSGET ; HBIOS FUNC: SYS GET
LD C,BF_SYSGET_DIOMED ; HBIOS SUB-FUNC: GET DISK INFO
RST 08 ; DO IT
;
; CHECK ERRORS FROM THE FUNCTION
RET NZ ; ABORT ON ERROR

; SAVE MEDIA ID
LD A,C ; C IS MEDIA ID FROM HBIOS
LD (MEDID),A ; SAVE IT

; TEST IF FLOPPY MEDIA - BIT 7 DEVICE ATTRIBUTES
BIT 7,B ; B IS ATTRIBUTES FROM HBIOS
JR NZ,DSK_MBR11 ; FLOPPY - SAVE AND RETURN DEHL -> CHS

; CODE FALL THRU NEXT IFDEF AND SETS 7,D
; THEN RETURNS DEHL -> LBA MODE
;
#ENDIF
;
#IFDEF PLTUNA
; CHECK MEDIA TYPE, ONLY HARD DISK IS APPLICABLE
LD A,(MEDID) ; GET MEDIA ID
CP MID_HD ; HARD DISK?
JR Z,DSK_MBR0 ; IF SO, CONTINUE
XOR A ; ELSE, N/A, SIGNAL SUCCESS
RET ; AND RETURN

DSK_MBR0:
;
#IFDEF PLTWBW
; ACTIVATE BIOS BANK TO ACCESS DISK BUFFER
LD (STKSAV),SP ; SAVE CUR STACK
LD SP,STACK ; NEW STACK IN HI MEM
LD A,(BNKBIOS) ; ACTIVATE HBIOS BANK
PUSH IX ; SAVE IX
LD IX,DSK_MBR1 ; ROUTINE TO RUN
CALL HB_BNKCALL ; DO IT
POP IX ; RESTORE IX
LD SP,(STKSAV) ; RESTORE ORIGINAL STACK
RET
#ENDIF
;
DSK_MBR1:
; SET LEGACY SECTORS PER SLICE - USED IN CAPACITY CALC
LD HL,SPS_HD512 ; LEGACY SECTORS PER SLICE
LD (SPS),HL ; SAVE IT
;
; FLUSH DSKBUF TO MAKE SURE IT IS SAFE TO USE IT.
CALL BLKFLSH ; MAKE SURE DISK BUFFER IS NOT DIRTY
XOR A ; CLEAR ACCUM
Expand All @@ -1441,9 +1433,6 @@ DSK_MBR1:
LD C,A ; PUT IN C
LD DE,0 ; LBA SECTOR ZERO
LD HL,0 ; ...
#IFDEF PLTWBW
SET 7,D ; MAKE SURE LBA ACCESS BIT SET
#ENDIF
CALL DSK_IO2 ; DO IT
RET NZ ; ABORT ON ERROR
;
Expand Down Expand Up @@ -1487,6 +1476,8 @@ DSK_MBR3:
; CHECK THAT REQUESTED SLICE IS "INSIDE" PARTITION
; SLICE SIZE IS EXACTLY 16,384 SECTORS (8MB), SO WE CAN JUST
; RIGHT SHIFT PARTITION SECTOR COUNT BY 14 BITS
; IMPLEMENTED BY : LEFT SHIFT BY 2, AND TAKE HIGH ORDER WORD
; SAME AS DISCARDING THE LOWER 14 BITS, SINCE KEEP 2 BY SHIFT
LD E,(HL) ; HL POINTS TO FIRST BYTE
INC HL ; ... OF 32 BIT PARTITION
LD D,(HL) ; ... SECTOR COUNT,
Expand All @@ -1510,7 +1501,7 @@ DSK_MBR3:
;
DSK_MBR4:
; IF BOOT FROM PARTITION, USE NEW SECTORS PER SLICE VALUE
LD HL,16384 ; NEW SECTORS PER SLICE
LD HL,SPS_HD1K ; NEW SECTORS PER SLICE
LD (SPS),HL ; SAVE IT

; UPDATE MEDIA ID
Expand All @@ -1519,18 +1510,19 @@ DSK_MBR4:
;
DSK_MBR5:
; ADJUST LBA OFFSET BASED ON TARGET SLICE
; ALSO JP HERE IF NO PARTITION TABLE, OR NO CPM PARTION
LD A,(SLICE) ; GET SLICE, A IS LOOP CNT
LD HL,(SEKLBA) ; SET DE:HL
LD DE,(SEKLBA+2) ; ... TO STARTING LBA
LD BC,(SPS) ; SECTORS PER SLICE
RES 7,D ; CLEAR LBA MODE BIT
DSK_MBR6:
DSK_MBR6:
OR A ; SET FLAGS TO CHECK LOOP CNTR
JR Z,DSK_MBR8 ; DONE IF COUNTER EXHAUSTED
ADD HL,BC ; ADD ONE SLICE TO LOW WORD
JR NC,DSK_MBR7 ; CHECK FOR CARRY
INC DE ; IF SO, BUMP HIGH WORD
DSK_MBR7:
DSK_MBR7:
DEC A ; DEC LOOP DOWNCOUNTER
JR DSK_MBR6 ; AND LOOP
DSK_MBR8:
Expand All @@ -1552,21 +1544,11 @@ DSK_MBR9:
LD (CAP_REQ),HL ; LSW
LD (CAP_REQ+2),DE ; MSW
;
#IFDEF PLTWBW
; GET DSK_CAP (DE:HL)
LD B,BF_DIOCAP ; HBIOS DISK CAPACITY FUNC
LD A,(SEKUNIT) ; DISK UNIT NUMBER
LD C,A ; ... INTO C
RST 08 ; HBIOS CALL (DE:HL = CAPACITY)
#ENDIF
;
#IFDEF PLTUNA
; GET DSK_CAP (DE:HL)
LD C,$45 ; UBIOS DISK INFO FUNC
LD A,(SEKUNIT) ; DISK UNIT NUMBER
LD B,A ; ... INTO B
RST 08 ; CALL UNA (DE:HL = CAPACITY)
#ENDIF
;
; SAVE DSK_CAP (DE:HL)
PUSH DE ; SAVE DSK_CAP (MSW)
Expand All @@ -1591,17 +1573,20 @@ DSK_MBR9:
OR $FF ; SIGNAL ERROR
RET ; DONE
;
#ENDIF
;
DSK_MBR10:
; FINALIZE SLICE LBA
SET 7,D ; SET LBA ACCESS FLAG
DSK_MBR11:
; RESAVE IT
LD (SEKLBA),HL ; LOWORD
LD (SEKLBA+2),DE ; HIWORD
; SUCCESSFUL FINISH
XOR A ; SUCCESS
RET ; DONE
;
;
; CHECK DISK STATUS (PART OF BIOS COLD WARM BOOT)
;
DSK_STATUS:
#IFDEF PLTUNA
Expand All @@ -1619,21 +1604,21 @@ DSK_STATUS:
RET
#ENDIF
;
;
; READ PHYSICAL SECTOR INTO BUFFER
;
DSK_READ:
; SET B = FUNCTION: READ
LD B,BF_DIOREAD
JR DSK_IO
;
;
; WRITE PHYSICAL SECTOR FROM BUFFER
;
DSK_WRITE:
; SET B = FUNCTION: WRITE
LD B,BF_DIOWRITE
JR DSK_IO
;
;
; READ/WRITE PHYSICAL SECTOR
;
DSK_IO:
LD A,(HSTUNIT) ; GET UNIT
Expand Down Expand Up @@ -1671,8 +1656,8 @@ LBA_IO:
LD L,A
; ADD IN LBA OFFSET FOR PARTITION AND/OR SLICE
LD BC,(HSTLBA) ; LBA OFFSET LOWORD
ADD HL,BC
EX DE,HL
ADD HL,BC
EX DE,HL
LD BC,(HSTLBA+2) ; LBA OFFSET HIWORD
ADC HL,BC
EX DE,HL
Expand Down Expand Up @@ -1816,8 +1801,10 @@ DEFDRIVE .DB 0 ; DEFAULT DRIVE
CCPBUF .DW 0 ; ADDRESS OF CCP BUF IN BIOS BANK
MEDID .DB 0 ; TEMP STORAGE FOR MEDIA ID
SLICE .DB 0 ; CURRENT SLICE
#IFDEF PLTUNA
SPS .DW 0 ; SECTORS PER SLICE
CAP_REQ .DW 0,0 ; LBA CAP REQUIRED FOR SLICE
#ENDIF
STKSAV .DW 0 ; TEMP SAVED STACK POINTER
;
#IFDEF PLTWBW
Expand Down Expand Up @@ -2596,7 +2583,7 @@ MD_INIT:
LD A,(HCB + HCB_RAMD_BNKS) ; RAM DISK SIZE IN BANKS
LD IX,DPB_RAM ; ADDRESS OF DPB
CALL MD_INIT1 ; FIX IT UP
;
;
JR MD_INIT4 ; DONE
;
MD_INIT1:
Expand Down
6 changes: 3 additions & 3 deletions Source/HBIOS/hbios.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5263,11 +5263,11 @@ SYS_GETDIOMED:
; SAVE CALL ARGUMENTS
LD (DIOMED_SLICE),DE ; STORES DE -> SLICE/UNIT PARAMETERS

; READ DEVICE INFORMATION USING DIODEVICE FUNTON
; READ DEVICE INFORMATION USING DIODEVICE FUNCTION
LD A,(DIOMED_UNIT)
LD C,A ; UNIT ID PARAMETER INTO C
LD B,BF_DIODEVICE ; DRIVER FUNCTION = DISK MEDIA
CALL DIO_DISPATCH ; CALL DIO TO GET MEDIAID (RESULT IN E)
CALL DIO_DISPATCH ; CALL DIO TO GET DEVICE ATTRIBUTES
RET NZ ; ABORT ON ERROR
;
; DEVICE ATTRIBUTES IN C
Expand Down Expand Up @@ -5298,7 +5298,7 @@ SYS_GETDIOMED1A:
; RETURN MEDIA ID (NOT HD) WITH SUCCESS
LD DE,0 ; LBA VALUE WILL BE ZERO
LD HL,0
JP SYS_GETDIOMED6A ; RETURN SUCESS
JP SYS_GETDIOMED6A ; RETURN SUCCESS
;
SYS_GETDIOMED1B:
; FOUND HD, NEED TO PROCESS MBR / PART TABLE
Expand Down
5 changes: 5 additions & 0 deletions Source/UBIOS/ubios.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ MID_FD360 .EQU 7
MID_FD120 .EQU 8
MID_FD111 .EQU 9
MID_HDNEW .EQU 10
;
; SECTORS PER SLICE
;
SPS_HD512 .EQU $4100
SPS_HD1K .EQU $4000
2 changes: 1 addition & 1 deletion Source/ver.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#DEFINE RMN 5
#DEFINE RUP 0
#DEFINE RTP 0
#DEFINE BIOSVER "3.5.0-dev.89"
#DEFINE BIOSVER "3.5.0-dev.90"
#define rmj RMJ
#define rmn RMN
#define rup RUP
Expand Down
2 changes: 1 addition & 1 deletion Source/ver.lib
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ rmn equ 5
rup equ 0
rtp equ 0
biosver macro
db "3.5.0-dev.89"
db "3.5.0-dev.90"
endm

0 comments on commit ee60c11

Please sign in to comment.