Skip to content

Commit

Permalink
28-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kowill committed Sep 8, 2019
1 parent bc28d7c commit c8a99ad
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 5 deletions.
13 changes: 13 additions & 0 deletions 28_day/app_c/api000.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api000.nas"]

GLOBAL __alloca

[SECTION .text]

__alloca:
ADD EAX, -4
SUB ESP, EAX
JMP DWORD [ESP+EAX]
13 changes: 8 additions & 5 deletions 28_day/app_c/api021.nas
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
[BITS 32]
[FILE "api021.nas"]

GLOBAL __alloca
GLOBAL _api_fopen

[SECTION .text]

__alloca:
ADD EAX, -4
SUB ESP, EAX
JMP DWORD [ESP+EAX]
_api_fopen: ; int api_fopen(char *fname);
PUSH EBX
MOV EDX, 21
MOV EBX, [ESP+8]
INT 0x40
POP EBX
RET
14 changes: 14 additions & 0 deletions 28_day/app_c/api022.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api022.nas"]

GLOBAL _api_fclose

[SECTION .text]

_api_fclose: ; void api_fclose(int fhandle);
MOV EDX, 22
MOV EAX, [ESP+4]
INT 0x40
RET
18 changes: 18 additions & 0 deletions 28_day/app_c/api023.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api023.nas"]

GLOBAL _api_fseek

[SECTION .text]

_api_fseek: ; void api_fseek(int fhandle, int offset, int mode);
PUSH EBX
MOV EDX, 23
MOV EAX, [ESP+8]
MOV ECX, [ESP+16]
MOV EBX, [ESP+12]
INT 0x40
POP EBX
RET
15 changes: 15 additions & 0 deletions 28_day/app_c/api024.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api024.nas"]

GLOBAL _api_fsize

[SECTION .text]

_api_fsize: ; void api_fsize(int fhandle, int mode);
MOV EDX, 24
MOV EAX, [ESP+4]
MOV ECX, [ESP+8]
INT 0x40
RET
18 changes: 18 additions & 0 deletions 28_day/app_c/api025.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api025.nas"]

GLOBAL _api_fread

[SECTION .text]

_api_fread: ; void api_fread(char *buf, int maxsize, int fhandle);
PUSH EBX
MOV EDX, 25
MOV EAX, [ESP+16]
MOV ECX, [ESP+12]
MOV EBX, [ESP+8]
INT 0x40
POP EBX
RET
5 changes: 5 additions & 0 deletions 28_day/app_c/apilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ void api_inittimer(int timer, int data);
void api_settimer(int timer, int time);
void api_freetimer(int timer);
void api_beep(int tone);
int api_fopen(char *fname);
void api_fclose(int fhandle);
void api_fseek(int fhandle, int offset, int mode);
int api_fsize(int fhandle, int mode);
int api_fread(char *buf, int maxsize, int fhandle);
19 changes: 19 additions & 0 deletions 28_day/app_c/typeipl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "apilib.h"

void HariMain(void)
{
int fh;
char c;
// typeiplなのだが、readme
fh = api_fopen("readme.md");
if (fh != 0)
{
for (;;)
{
if (api_fread(&c, 1, fh) == 0)
break;
api_putchar(c);
}
}
api_end();
}
9 changes: 9 additions & 0 deletions 28_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ struct TASK
struct SEGMENT_DESCRIPTOR ldt[2];
struct CONSOLE *cons;
int ds_base, cons_stack;
struct FILEHANDLE *fhandle;
int *fat;
};

struct FILEHANDLE
{
char *buf;
char size;
char pos;
};

struct TASKLEVEL
Expand Down
79 changes: 79 additions & 0 deletions 28_day/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void console_task(struct SHEET *sheet, unsigned int memtotal)
struct TASK *task = task_now();
struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
struct CONSOLE cons;
struct FILEHANDLE fhandle[8];
int i, *fat = (int *)memman_alloc_4k(memman, 4 * 2880);
char cmdline[30];
cons.sht = sheet;
Expand All @@ -48,6 +49,10 @@ void console_task(struct SHEET *sheet, unsigned int memtotal)
}

file_readfat(fat, (unsigned char *)(ADR_DISKING + 0x000200));
for (i = 0; i < 8; i++)
fhandle[i].buf = 0;
task->fhandle = fhandle;
task->fat = fat;

cons_putchar(&cons, '>', 1);

Expand Down Expand Up @@ -321,6 +326,14 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
sheet_free(sht);
}
}
for (i = 0; i < 8; i++)
{
if (task->fhandle[i].buf != 0)
{
memman_free_4k(memman, (int)task->fhandle[i].buf, task->fhandle[i].size);
task->fhandle[i].buf = 0;
}
}
timer_cancelall(&task->fifo);
memman_free_4k(memman, (int)q, segsiz);
}
Expand Down Expand Up @@ -357,7 +370,11 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
struct SHTCTL *shtctl = (struct SHTCTL *)*((int *)0x0fe4);
struct SHEET *sht;
struct FIFO32 *sys_fifo = (struct FIFO32 *)*((int *)0x0fec);
struct FILEINFO *finfo;
struct FILEHANDLE *fh;
struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
int *reg = &eax + 1;

if (edx == 1)
cons_putchar(cons, eax & 0xff, 1);
else if (edx == 2)
Expand Down Expand Up @@ -500,6 +517,68 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
io_out8(0x61, (i | 0x03) & 0x0f);
}
}
else if (edx == 21)
{
for (i = 0; i < 8; i++)
if (task->fhandle[i].buf == 0)
break;
fh = &task->fhandle[i];
reg[7] = 0;
if (i < 8)
{
finfo = file_search((char *)ebx + ds_base, (struct FILEINFO *)(ADR_DISKING + 0x002600), 224);
if (finfo != 0)
{
reg[7] = (int)fh;
fh->buf = (char *)memman_alloc_4k(memman, finfo->size);
fh->size = finfo->size;
fh->pos = 0;
file_loadfile(finfo->clustno, finfo->size, fh->buf, task->fat, (char *)(ADR_DISKING + 0x003e00));
}
}
}
else if (edx == 22)
{
fh = (struct FILEHANDLE *)eax;
memman_free_4k(memman, (int)fh->buf, fh->size);
fh->buf = 0;
}
else if (edx == 23)
{
fh = (struct FILEHANDLE *)eax;
if (ecx == 0)
fh->pos = ebx;
else if (ecx == 1)
fh->pos += ebx;
else if (ecx == 2)
fh->pos = fh->size + ebx;
if (fh->pos < 0)
fh->pos = 0;
if (fh->pos > fh->size)
fh->pos = fh->size;
}
else if (edx == 24)
{
fh = (struct FILEHANDLE *)eax;
if (ecx == 0)
reg[7] = fh->size;
else if (ecx == 1)
reg[7] = fh->pos;
else if (ecx == 2)
reg[7] = fh->pos - fh->size;
}
else if (edx == 25)
{
fh = (struct FILEHANDLE *)eax;
for (i = 0; i < ecx; i++)
{
if (fh->pos == fh->size)
break;
*((char *) ebx + ds_base + i) = fh->buf[fh->pos];
fh->pos++;
}
reg[7] = i;
}
return 0;
}

Expand Down

0 comments on commit c8a99ad

Please sign in to comment.