Title Micro_Decision Installation SubProceedure Number 2 (6_Jul_84) ; ; Copyright 1984 ; Morrow Designs, Inc. ; San Leandro, Ca. ; John Zalabak ; .z80 Aseg Org 0100h ;---------------------------------------------------------------------- ; Index (6_Jul_84) ;----------------- ; ; Isub2_Main Main Line of Sub Installation Proceedure 2 ; ; Get_Version Check the CP/M version ; Install_Drives Install the Number of Physical Drives ; ; Read_Cpm2_Bios Read the Cp/m 2.2 Bios ; Write_Cpm2_Bios Write the Cp/m 2.2 Bios ; Setup_IX Setup the IX and Initialize Pertinant Values ; ; Get_Bios_Pntr Get One of the Bios Pointers ; Get_DE_Indr_HL Load the DE register Pair Indirectly Through the HL ; ; Cpm2_Bias Figure the Memory Bias for Cpm 2.2 ; Apply_Bias_DE Apply the Bias to the DE Pair ; ; Report_Errors Report an Error on the Console ; Print_Message Print a Message on the Console page 60 ;---------------------------------------------------------------------- ; Equates (25_Jun_84) ;-------------------- ; ;Bios/Bdos Equates Bios_Entry equ 0 ;Bios Entry Point Bdos_Entry equ 5 ;Bdos: Entry Vector Location Bdos_PString equ 9 ; Print a Sting on the Console Bdos_Ret_Ver equ 12 ; Return CP/M version ; Cp/m 2.2 Bios Jump Table Offsets Bios_Offset equ 200h ;Offset: Bios Start from Start Disk Buffer Bios_Address equ 1 ;Address of Bios (Warm Boot Vector Addr) WBoot_Offset equ 4 ;Warm Boot address (Gives base of Bios) RdBlk_Offset equ 37h ;Read a Block from the Floppy Disk WrBlk_Offset equ 3Ah ;Write a Block to the Floppy Disk RamDatX_Offset equ 40h ;Pointer to RamDatX Area RamDatY_Offset equ 42h ;Pointer to RamDatY Area Mtab_Offset equ 44h ;Pointer to Mtabs ; RamDatX Area Definitions HstDsk equ 0 ;Host Level Disk HstTrk equ 1 ; " " Track HstSec equ 2 ; " " Sector SecCnt equ 3 ;Sector Count (1 to n) Retry equ 4 ;Error Retry Count HstBuf equ 5 ;Host Buffer ErFlag equ 7 ;Error Flag ; Error String Codes Error_Opening equ 10 ;Error Intro Error_Version equ 11 ;Wrong Version of CP/M Sys_Read_Err equ 12 ;Unable to read System from the Disk Sys_Write_Err equ 13 ;Unable to Write System to the Disk ;Non Printing Ascii Equates Control_C equ 03h ;Control C (Force CPM Warm Boot) Tab equ 09h ;Tab Lf equ 0Ah ;Line Feed Cr equ 0Dh ;Carriage Return ;Other Definitions Disk_Buffer equ 2000h ;Start of Disk Buffer (must be above Rom) Mtab_Leng equ 9 ;Length of an Mtab Tot_Mtab equ 5 ;Total Number of Mtabs page ;====================================================================== ; Main Line of Sub Installation Proceedure 2 (6_Jul_84) ;====================================================== ; Isub2_Main: call Get_Version ;If (this is NOT Version 2.x) jr nz,ImErr ; Goto Report Error call Read_Cpm2_Bios ;Read the Bios or a ;If (there was an error) jr nz,ImErr ; Goto Report Error call Install_Drives ;Install the Drives call Write_Cpm2_Bios ;Write the Bios or a ;If (There was an Error) jr z,ImDone ; Goto Report Error ImErr: call Report_Errors ;Report the Error ImDone: jp Bios_Entry ;Return ;====================================================================== ; Check the CP/M version (5_Jul_84) ;================================== ; 1) This routine checks the CP/M version. It returns with the ; Z flag = 1 if CP/M 2. ; Get_Version: ld c,Bdos_Ret_Ver ;Return version Bdos call call Bdos_Entry ld a,0F0h and l cp 20h ;If (this is NOT CP/M 2.x) ld a,Error_Version ; A:= Version Error ret nz ; Return ld a,0 ;Else A:= No Error ret ; Return page ;====================================================================== ; Install the Number of Physical Drives (6_Jul_84) ;================================================= ; 1) This routine Updates the Bios Image of Vnum, copies the resident ; system's Mtabs into the Memory image and then resets the current ; track values in the memory image to De:Calibrated (0FFh). ; Install_Drives: call Cpm2_Bias ;Figure the Bias values ld de,RamDatY_Offset call Get_Bios_Pntr ;DE:= Pointer to Start of RamDatY dec de dec de ;DE:= Pointer to Vnum ld a,(de) ;A:= Vnum call Apply_Bias_DE ;DE:= Pointer to Memory Image of Vnum ld (de),a ;Update Vnum ld de,Mtab_Offset call Get_Bios_Pntr ;DE:= Pointer to Start of Mtabs push de call Apply_Bias_DE ;DE:= Pointer to Memory Image of Mtabs pop hl ;HL:= Pointer to System Mtabs ld bc,Mtab_Leng * Tot_Mtab ;BC:= Counter for number of Mtabs push de ;(Save pointer to start of Memory Mtabs) ldir ;Move the System Mtabs to Memory Image pop hl ld de,Mtab_Leng - 1 ;DE:= Offset to Current Track in Mtab add hl,de ;HL:= Pointer to Current Track (memory image) ld de,Mtab_Leng ;DE:= Length of an Mtab ld b,Tot_Mtab ;B:= Counter (total number of Mtabs) IdLp1: ld (hl),0FFh ;Repeat Reset the Current Track add hl,de ; HL:= HL + Mtab_Leng djnz IdLp1 ;Until (all current track values reset) ret ;Return page ;====================================================================== ; Read the Cp/m 2.2 Bios (23_Jun_84) ;=================================== ; 1) This routine reads the Bios from the system tracks into the ; next free memory space (next free space pointer set in Build_Tables) ; Read_Cpm2_Bios: call Setup_IX ;Set IX to RamdatX and Save the Original ld de,RdBlk_Offset ;DE:= Offset to the RdBlk Address call Get_Bios_Pntr ex de,hl ;HL:= Vector to Read a Block Routine call IR_HL ;Execute the read a block routine ld a,(ix+ErFlag) or a ;If (there were no errors) ret z ; Return ld a,Sys_Read_Err ;Else A:= Error Code ret ; Return IR_HL: jp (hl) ;====================================================================== ; Write the Cp/m 2.2 Bios (25_Jun_84) ;==================================== ; 1) This routine writes the Bios back to the system tracks. ; Write_Cpm2_Bios: call Setup_IX ;Set IX to RamdatX and Save the Original ld de,WrBlk_Offset ;DE:= Offset to the WrBlk Address call Get_Bios_Pntr ex de,hl ;HL:= Vector to Read a Block Routine call IW_HL ;Execute the Write a Block routine ld a,(ix+ErFlag) or a ;If (There were no errors) ret z ; Return ld a,Sys_Write_Err ;Else A:= Error Code ret ; Return IW_HL: jp (hl) page ;---------------------------------------------------------------------- ; Setup the IX and Initialize Pertinant Values (22_Jun_84) ;--------------------------------------------------------- ; 1) This routine Sets the IX register 2 pages before the start of ; the Bdos and then initializes the essential parameters. ; Setup_IX: ld hl,(Bdos_Entry+1) ;HL:= Pointer to Start of Bdos ld l,0 ;HL:= Pointer to Base of Bios dec h ;HL:= Base Page of Bios - 1 dec h push hl pop ix ;IX:= Base Page of Bios - 1 ld (ix+HstDsk),0 ;Drive:= 0 ld (ix+HstTrk),1 ;Starting_Track:= 1 ld (ix+HstSec),2 ;Starting_Sector:= 2 ld (ix+SecCnt),4 ;Number_of_Sectors_to_Read:= 4 ld (ix+Retry),10 ;Retries:= 10 ld (ix+HstBuf), LOW Disk_Buffer ld (ix+HstBuf+1),HIGH Disk_Buffer ld (ix+ErFlag),0 ;Error_Flag:= Reset ret ;---------------------------------------------------------------------- ; Get One of the Bios Pointers (20_Jun_84) ;----------------------------------------- ; Get_Bios_Pntr: ld hl,(Bios_Entry+1) ;HL:= Pointer to Warm Boot Entry ld l,0 ;HL:= Pointer to Base of Bios call Get_DE_Indr_HL ;DE:= Contents of Addr Pointed to by HL ret ;Return ;---------------------------------------------------------------------- ; Load the DE register Pair Indirectly Through the HL (20_Jun_84) ;---------------------------------------------------------------- ; 1) This routine Loads the DE register pair Indirectly through the ; HL register pair after adding the entry values of the DE and HL. ; 2) Register Usage: ; DE -> On Entry = Offset; On Exit = (HL + DE) ; HL -> [preseved] Base Address ; Get_DE_Indr_HL: add hl,de ;HL:= Pointer to RamDatY Pointer ld e,(hl) inc hl ld d,(hl) ;DE:= Contents of Addr Pointed to by HL dec hl ret ;Return page ;---------------------------------------------------------------------- ; Figure the Memory Bias for Cpm 2.2 (21_Jun_84) ;----------------------------------------------- ; 1) This routine Sets up the Bios Base and the Bios Bias. The Bios ; Base is the starting memory address of where the bios is current ; loaded. The bios Bias is the Starting Memory Address of where the ; bios is intented to be loaded. ; Cpm2_Bias: ld hl,Disk_Buffer ;HL:= Start of the Disk Buffer ld de,Bios_Offset ;DE:= Offset to Bios Start add hl,de ;HL:= Pointer to Start of Cpm Bios ld (Bios_Base),hl ;(save the Base address of the Bios) ld de,WBoot_Offset ;DE:= Offset to Warm Boot Address call Get_DE_Indr_HL ld e,0 ;DE:= Start of Load Location of Bios ld (Bios_Bias),de ;(save the Load address of the Bios) ret ;---------------------------------------------------------------------- ; Apply the Bias to the DE Pair (21_Jun_84) ;------------------------------------------ ; 1) This routine adjusts the DE pair. On entry, the DE pair is pointing ; to the actual load address of an object. On exit, the DE pair is ; pointing to the current memory location containing that object. ; 2) Register Usage: ; DE -> Entry: Load Address; Exit: Actual Address ; HL -> Used in figuring the offsets ; Apply_Bias_DE: push hl ex de,hl ;HL:= Load Address Data Object ld de,(Bios_Bias) ;DE:= Load Address Base of Bios or a sbc hl,de ;HL:= Offset from Bios Base ld de,(Bios_Base) ;DE:= Offset to Base of Bios in Memory add hl,de ex de,hl ;DE:= Current Memory address pop hl ret page ;====================================================================== ; Report Errors (5_Jun_84) ;========================= ; 1) Report Errors on the console. ; 2) Register Usage: ; A -> Has Error Code on entry ; Report_Errors: push af ld a,Error_Opening call Print_Message ;Print the Error Opening Message pop af call Print_Message ;Print the Error Message ret ;====================================================================== ; Print a Message on the Console (5_Jul_84) ;========================================== ; 1) This routine prints a message string on the console. ; 2) Register Usage: ; A -> Has Error Code on entry ; B -> Counter ; C -> Holds copy of Error Code ; DE -> Pointer to Message String ; HL -> Pointer into Message Code Table ; Print_Message: push af ld de,CrLf ;DE:= Pointer to Cr/Lf String ld c,Bdos_PString ;C:= Print String Function call Bdos_Entry ;Print Carriage Return Line Feed pop af ld c,a ;C:= Error Code to Find ld b,Max_Table ld hl,Message_Table ;HL:= Start of the Message table PMLp1: ld a,(hl) ;Repeat A:= Table's Message Code inc hl ld e,(hl) inc hl ld d,(hl) ; DE:= Pointer to String inc hl ; (HL equal to start next entry) cp c ; If (Code eq table) jr z,PMprn ; Goto Print djnz PMLp1 ;Until (the whole tables been checked) ld de,NoCode ;(set pointer to 'Unrecognized Message') PMprn: ld c,Bdos_PString ; call Bdos_Entry ; Print the Message ret page ;---------------------------------------------------------------------- ; Message Strings (6_Jul_84) ;--------------------------- ; ; Message String Lookup Table ;----------------------------- ; Message_Table: db Error_Opening ;Error Intro dw ErrOpn db Error_Version ;Wrong Version of CP/M dw EVmsg db Sys_Read_Err ;Unable to read System from the Disk dw SRmsg db Sys_Write_Err ;Unable to Write System to the Disk dw SWmsg End_Table: Max_Table equ ( (End_Table - Message_Table)/3 ) + 1 page ;---------------------------------------------------------------------- ; Text Strings (6_Jul_84) ;------------------------ ; ErrOpn: db '*=> Error: $' EVmsg: db 'This Program only runs under CP/M 2.x $' SRmsg: db 'Unable to read System from the Disk $' SWmsg: db 'Unable to Write System to the Disk $' CrLf: db Cr,Lf,'$' NoCode: db 'Unrecognized Message $' ;---------------------------------------------------------------------- ; Local Data Area (5_Jul_84) ;--------------------------- ; Bios_Base: dw 0 ;Actual Memory Address of the Bios Bios_Bias: dw 0 ;Intended Load Address of the Bios end