Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Bootloader for PBDOS programs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bootloader for PBDOS programs

    '
    Code:
    'This program will modify the boot sector of a 1.44 floppy to load a Powerbasic for DOS
    'or assembler program with the name startme.exe. No operating system is loaded,
    'except you call it startme.exe. The program will not load .com programs.
    'How to use this program:
    '1. put a formatted(!) 1.44 floppy into drive a:
    '2. enter "dir a:" from the command line to make sure you can access the disk
    '3. run this program - it will modify the boot sector on the floppy
    '4. rename your program to startme.exe and copy it to this floppy
    '5. restart the computer with this floppy in the drive
    '6. the computer will boot from the floppy and load the startme.exe program
    '7. when the startme.exe program terminates, it will be loaded again, but often not run properly.
    '
    'the loaded program shall not use DOS calls (int21h) - except 30h - get version
    'so don't try to open files etc.
    'you can patch a different name into the bootstrap code as long as you don't
    'change the length of the name - use blanks and no dot
    '
    '6.11.2004 Georg Potthast
    '
    defint a-z
    a$=string$(1024,0) '2 disk segments - 512 each
    mbrseg=strseg(a$)
    mbroff=strptr(a$)
    
    'read the mbr of the floppy
    asm mov di,5       ; 5 attempts
    mbrretry:
    asm xor ah, ah     ; ah = 0 = reset function
    asm int &H13       ; reset drive
    delay 1
    asm mov ax,&H0202  ; AH=2 read, AL=Sectors, 2 sectors=1 cluster on 1.44 floppy
    asm mov cx,&H0001  ; CH=Cylinder, CL=Sector
    asm mov dx,&H0000  ; DH=Head,DL=Drive - 0=1.FD
    asm mov es,mbrseg  ; Segment to store
    asm mov bx,mbroff  ; Offset  to store
    asm int &H13
    asm jnc mbrcontinue
    asm dec di         ; next attempt to read
    asm jnz mbrretry
    asm jmp errread
    
    'now write our bootstrap into the mbr
    
    'first read the bootstrap from the data statements
    mbrcontinue:
    FOR i = 0 to 511
        READ B$
        if i>&H3D then 'keep the mbr from 0-3D - Bootstrap starts at 3E !
           def seg = mbrseg
           poke$ mbroff+i,CHR$(VAL("&H"+B$))
           def seg
        end if
    NEXT
    
    'write the mbr of the floppy
    asm mov di,5       ; 5 attempts
    mbr2retry:
    asm xor ah, ah     ; ah = 0 = reset function
    asm int &H13       ; reset drive
    delay 1
    asm mov ax,&H0302  ; AH=3 write, AL=Sectors
    asm mov cx,&H0001
    asm mov dx,&H0000
    asm mov es,mbrseg
    asm mov bx,mbroff
    asm int &H13
    asm jnc mbr2continue
    asm dec di         ; next attempt
    asm jnz mbr2retry
    asm jmp errwrite
    
    mbr2continue:
    print "Floppy will boot startme.exe now"
    end
    
    errread:
    print "Cannot read boot sector of floppy"
    end
    
    errwrite:
    print "Cannot write boot sector of floppy"
    end
    
    'Bootstrap code
    DATA EB,3C,90,42,6F,6F,74,50,72,6F,67,0,0,0,0,0,0,0,0,0,0,0,0
    DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4E,4F,20,4E
    DATA 41,4D,45,20,20,20,20,46,41,54,31,32,20,20,20,FC,31,C0,8E,D8,C7,6,70,4
    DATA 80,F4,C7,6,72,4,30,B3,C7,6,74,4,0,3A,C7,6,76,4,DC,B8,C7,6,78,4
    DATA 3,1E,C7,6,7A,4,B9,0,C7,6,7C,4,0,CF,B8,70,4,A3,84,0,31,C0,A3,86
    DATA 0,CD,12,C1,E0,6,2D,20,0,8E,C0,2D,80,0,8E,D0,BC,0,8,B9,0,1,BE,0
    DATA 7C,31,FF,8E,DF,F3,A5,6,68,9B,0,CB,E,1F,88,16,24,0,A1,B,0,C1,E8,4
    DATA 8B,E,16,0,F7,E1,8C,D7,29,C7,8E,C7,31,DB,A1,E,0,31,D2,E8,EB,0,89,C3
    DATA 89,D7,B8,20,0,8B,36,11,0,F7,E6,F7,36,B,0,89,C1,A0,10,0,98,F7,26,16
    DATA 0,1,D8,11,FA,6,68,60,0,7,31,DB,E8,C2,0,1,C8,11,DA,52,50,89,DF,89
    DATA F2,BE,F3,1,B9,B,0,26,38,2D,74,D,60,F3,A6,61,74,A,81,C7,20,0,4A,75
    DATA EE,E9,E0,0,26,8B,75,1A,E8,55,0,81,FE,F8,F,72,F7,FA,B8,60,0,8E,C0,8E
    DATA D8,3E,3,6,8,0,3E,8B,E,6,0,3E,8B,1E,18,0,E3,16,3E,8B,3F,3E,8B,57
    DATA 2,1,C2,1E,8E,DA,3E,1,5,1F,81,C3,4,0,E2,EA,89,C3,3E,3,1E,E,0,8E
    DATA D3,3E,8B,26,10,0,3E,3,6,16,0,50,3E,FF,36,14,0,2E,8A,16,24,0,FB,CB
    DATA 89,E5,8D,44,FE,30,ED,8A,E,D,0,F7,E1,36,3,46,2,36,13,56,4,E8,29,0
    DATA A1,B,0,C1,E8,4,F7,E1,8C,C1,1,C1,8E,C1,B8,3,0,F7,E6,D1,E8,96,1E,36
    DATA 8E,5E,6,3E,8B,34,1F,73,3,C1,EE,4,81,E6,FF,F,C3,60,BF,5,0,60,F7,36
    DATA 18,0,89,D1,41,31,D2,F7,36,1A,0,88,C5,C0,E4,6,8,E1,88,D6,8A,16,24,0
    DATA B8,1,2,CD,13,73,A,30,E4,CD,13,61,4F,75,D6,EB,13,61,49,74,D,3,1E,B
    '                                                       S  T  A  R
    DATA 0,5,1,0,81,D2,0,0,EB,C0,61,C3,B8,7,E,CD,10,52,4E,0,53,54,41,52
    '    T  M  E     E  X  E
    DATA 54,4D,45,20,45,58,45,55,AA
    '</code>
    '<code>
    'the following Powerbasic programs will run with this bootstrap code:
    $if 0
    cls
    line input "Please enter your name: " a$
    print "Hello "a$
    while (1) : wend 'end and avoid reload
    $endif
    $if 0
    $lib iprint
    defint a-z
    $com 1024
    open "com1: 9600,N,8,1" as #1 len = 1024
    color 7,1 : cls : locate ,,1
    print "COM1 opened"
    echo=0
    while (1)
    	while not instat
               if loc(1)>0 then
                  chars$ = input$(loc(1),#1)
                  print chars$;
               end if
    	wend
            while instat
                  mykey$=inkey$
                  print #1,mykey$;
                  if echo=1 then print mykey$;
            wend
    wend
    $endif
    '

    ------------------




    [This message has been edited by Georg Potthast (edited November 06, 2004).]
Working...
X