PC-98 フロッピーIPLサンプル


Bドライブなら1、セクタ番号を指定し、フロッピーのセクタを読み込み表示します。

secread.c
#include <stdio.h>
#include <dos.h>
#include <ctype.h>

#define SECBYTE 1024

void secread(unsigned char *buf, int drive, int n, int sec)
{
    _asm {
        push    bp
        mov     bx, buf
        mov     ax, drive
        mov     cx, n
        mov     dx, sec
        int     25h
        popf
        pop     bp
    }
}

int main()
{
    int i, j, drive, sec;
    unsigned char buf[SECBYTE];

    printf("drive no ? ");
    scanf("%d", &drive);
    printf("read sector no ? ");
    scanf("%d", &sec);
    secread(buf, drive, 1, sec);

    for (j = 0; j < 16; j++) {
        printf("%04x: ", j*16);
        for (i = 0; i < 16; i++) {
            printf("%02x ", buf[j*16+i]);
        }
        putchar('\n');
    }
    return 0;
}

IPLファイルを指定し、Bドライブのセクタ番号0に書き込みます。

secwrite.c
#include <dos.h>
#include <stdio.h>
#include <string.h>

#define SECBYTE 1024

void secwrite(char *buf, int drive, int n, int sec)
{
    _asm {
        push    bp
        mov     bx, buf
        mov     ax, drive
        mov     cx, n
        mov     dx, sec
        int     26h
        popf
        pop     bp
    }
}

int main(int argc, char *argv[])
{
    int drive = 1;
    int sec = 0;
    char *fname;
    FILE *file;
    char buf[SECBYTE];

    if (argc != 2) {
        fprintf(stderr, "usage: secwrite filename\n");
        return 1;
    }
    fname = argv[1];

    file = fopen(fname, "rb");
    if (! file) {
        perror(fname);
        exit(1);
    }
    memset(buf, 0, SECBYTE);
    fread(buf, 1, SECBYTE, file);
    fclose(file);

    secwrite(buf, drive, 1, sec);
    return 0;
}

セクタ番号0が(1fc0:0000)に読み込まれ実行されます。

hello3.asm
comment *
        hello3.asm for MASM32

path %path%;C:\masm32\bin
ml /c /AT /Fl hello3.asm
link16 /t hello3;
*
        .model  tiny

        .code
        org     0h
start:
        push    cs
        pop     ds
        mov     si, offset data
        mov     ax, 0a000h
        mov     es, ax
        mov     di, 0h
L1:
        mov     al, ds:[si]
        cmp     al, 0h
        jz      L2
        mov     es:[di], al
        inc     si
        inc     di
        inc     di
        jmp     L1
L2:
        cli
        hlt

data    db      'hello, world', 0h

        end     start