diff --git a/step_3/Makefile b/step_3/Makefile index bc292f6..ed545c4 100644 --- a/step_3/Makefile +++ b/step_3/Makefile @@ -11,7 +11,9 @@ LOADER=loader ROOT=.. FILESYSTEM=filesystem USER=user -all: $(USER)/stone.bin $(KERNEL)/kernel.bin $(LOADER)/loader.bin build cleangch +STONE=stone +STONE_OBJ=$(USER)/$(STONE)/stoneQ.bin $(USER)/$(STONE)/stoneW.bin $(USER)/$(STONE)/stoneA.bin $(USER)/$(STONE)/stoneS.bin +all: $(STONE_OBJ) $(KERNEL)/kernel.bin $(LOADER)/loader.bin build cleangch $(KERNEL)/kernel.bin: echo "\n" @@ -43,12 +45,25 @@ $(FILESYSTEM)/datablock.bin: cd $(FILESYSTEM)/ && make cd $(ROOT)/ -$(USER)/stone.bin: +$(USER)/$(STONE)/stoneQ.bin: echo "\n" cd $(USER)/ && make cd $(ROOT)/ +$(USER)/$(STONE)/stoneW.bin: + echo "\n" + cd $(USER)/ && make + cd $(ROOT)/ +$(USER)/$(STONE)/stoneA.bin: + echo "\n" + cd $(USER)/ && make + cd $(ROOT)/ +$(USER)/$(STONE)/stoneS.bin: + echo "\n" + cd $(USER)/ && make + cd $(ROOT)/ + -build: $(LOADER)/loader.bin $(FILESYSTEM)/DBR.bin $(FILESYSTEM)/FAT.bin $(FILESYSTEM)/datablock.bin +build: $(LOADER)/loader.bin $(FILESYSTEM)/DBR.bin $(FILESYSTEM)/FAT.bin $(FILESYSTEM)/datablock.bin $(STONE_OBJ) echo "\n" dd if=$(LOADER)/loader.bin of=OS.img conv=notrunc dd if=$(FILESYSTEM)/DBR.bin of=OS.img conv=notrunc oflag=seek_bytes seek=512 @@ -56,7 +71,10 @@ build: $(LOADER)/loader.bin $(FILESYSTEM)/DBR.bin $(FILESYSTEM)/FAT.bin $(FILESY dd if=$(FILESYSTEM)/FAT.bin of=OS.img conv=notrunc oflag=seek_bytes seek=3584 dd if=$(FILESYSTEM)/datablock.bin of=OS.img conv=notrunc oflag=seek_bytes seek=6656 dd if=$(KERNEL)/kernel.bin of=OS.img conv=notrunc oflag=seek_bytes seek=7680 - dd if=$(USER)/stone.bin of=OS.img conv=notrunc oflag=seek_bytes seek=12800 + dd if=$(USER)/$(STONE)/stoneQ.bin of=OS.img conv=notrunc oflag=seek_bytes seek=12800 + dd if=$(USER)/$(STONE)/stoneW.bin of=OS.img conv=notrunc oflag=seek_bytes seek=14848 + dd if=$(USER)/$(STONE)/stoneA.bin of=OS.img conv=notrunc oflag=seek_bytes seek=16896 + dd if=$(USER)/$(STONE)/stoneS.bin of=OS.img conv=notrunc oflag=seek_bytes seek=18944 clean: echo "\n" find . -name "*.bin" -type f -delete diff --git a/step_3/filesystem/FAT.c b/step_3/filesystem/FAT.c index cd92d65..a1267b1 100644 --- a/step_3/filesystem/FAT.c +++ b/step_3/filesystem/FAT.c @@ -15,5 +15,32 @@ FAT_ITEM_T fat_items[] = { 0xFFFF, // 11 0xFFFF, // 12 0xFFFF, // 13 - 0xFFFF, //14 + 0x000F, // 14 + 0x0010, // 15 + 0x0011, // 16 + 0xFFFF, // 17 + 0x0013, // 18 + 0x0014, // 19 + 0x0015, // 20 + 0xFFFF, // 21 + 0x0017, // 22 + 0x0018, // 23 + 0x0019, // 24 + 0xFFFF, // 25 + 0x001B, // 26 + 0x001C, // 27 + 0x001D, // 28 + 0xFFFF, // 29 + 0xFFFF, // 30 + 0xFFFF, // 31 + 0xFFFF, // 32 + 0xFFFF, // 33 + 0xFFFF, // 34 + 0xFFFF, // 35 + 0xFFFF, // 36 + 0xFFFF, // 37 + 0xFFFF, // 38 + 0xFFFF, // 39 + 0xFFFF, // 40 + 0xFFFF, // 41 }; diff --git a/step_3/filesystem/README.md b/step_3/filesystem/README.md index ec42b31..9bc1b7f 100644 --- a/step_3/filesystem/README.md +++ b/step_3/filesystem/README.md @@ -10,11 +10,19 @@ FAT表2 8-11扇区(4个)512*7 = 3584 [e00~1600] 内核程序 16-23 512*15= 7680 [1e00~2e00] home/ 24 [2e00~3000] msg 25 [3000~3200] -用户程序 26-29 512*25=12800 [3200~3a00] +用户程序q 26-29 512*25=12800 [3200~3a00] +用户程序w 30-33 512*29=14848 [3a00~4200] +用户程序a 34-37 512*33=16896 [4200~4a00] +用户程序s 38-41 512*37=18944 [4a00~5200] ## 软盘结构 ; 磁道 面 扇区 ; 0~79 0~1 1~18 - +1 0 2 +逻辑扇区 面 运算后的结果 +1~18 0 -1/18-> 0 +19~36 1 -1/18-> 1 +37~54 0 -1/18-> 2 +55~72 1 -1/18-> 3 ## 内存结构 1:0x7C00: MBR(loader) 2:0x7E00: DBR diff --git a/step_3/filesystem/datablock.c b/step_3/filesystem/datablock.c index 6b663c7..912fb19 100644 --- a/step_3/filesystem/datablock.c +++ b/step_3/filesystem/datablock.c @@ -63,8 +63,8 @@ FAT_ITEM msg = { 13, 0 }; -FAT_ITEM user_program = { - "stone", +FAT_ITEM user_programQ = { + "stoneQ", "bin", FAT_rw, 0, 0, 0, 0, 0, 0, @@ -72,4 +72,35 @@ FAT_ITEM user_program = { 0, 14, 512*4 // 4 sectors +}; + +FAT_ITEM user_programW = { + "stoneW", + "bin", + FAT_rw, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 18, + 512*4 // 4 sectors +}; +FAT_ITEM user_programA = { + "stoneA", + "bin", + FAT_rw, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 22, + 512*4 // 4 sectors +}; +FAT_ITEM user_programS = { + "stoneS", + "bin", + FAT_rw, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 26, + 512*4 // 4 sectors }; \ No newline at end of file diff --git a/step_3/filesystem/fsutilities.h b/step_3/filesystem/fsutilities.h index 9ddee1d..b6eb067 100644 --- a/step_3/filesystem/fsutilities.h +++ b/step_3/filesystem/fsutilities.h @@ -2,7 +2,7 @@ #define __FS_UTILITIES_H_ #include #define lgsector2sector(X) (((X-1)%18)+1) -#define lgsector2head(X) ((X-1)/18) +#define lgsector2head(X) (((X-1)/18)%2) #define lgsector2track(X) ((X-1)/36) void loadSector(uint16_t track, uint16_t head, uint16_t sector, uint16_t addr, uint16_t num); static inline void loadLogicSector(uint16_t lgsector, uint16_t addr, uint16_t num) { diff --git a/step_3/kernel/Makefile b/step_3/kernel/Makefile index 38e73cc..f887e7a 100644 --- a/step_3/kernel/Makefile +++ b/step_3/kernel/Makefile @@ -9,9 +9,10 @@ ROOT=.. INCLUDE=../include USER=../user FILESYSTEM=../filesystem +STONE=stone USER_HEADER=$(USER)/user.h $(USER)/terminal.h -USER_OBJ=$(USER)/user.o $(USER)/terminal.o $(USER)/stone.o +USER_OBJ=$(USER)/user.o $(USER)/terminal.o all: kernel.bin @@ -31,6 +32,9 @@ $(INCLUDE)/mystring.o: $(FILESYSTEM)/fsutilities.o: cd $(FILESYSTEM)/ && make cd ../kernel +$(USER)/$(STONE)/stoneQ.o: + cd $(USER)/ && make + cd ../kernel clean: rm *.bin -f rm *.o -f diff --git a/step_3/kernel/kernel.c b/step_3/kernel/kernel.c index eed19df..571c7c5 100644 --- a/step_3/kernel/kernel.c +++ b/step_3/kernel/kernel.c @@ -7,6 +7,7 @@ #define true 1 #define false 0 int main() { + // __load_program("stoneS"); clear_screen(); draw_str("enter help to get help", 0, 30); //draw_char_style('A', 0, 10, G_DEFAULT); diff --git a/step_3/user/Makefile b/step_3/user/Makefile index 7c919c5..e0d2ac0 100644 --- a/step_3/user/Makefile +++ b/step_3/user/Makefile @@ -6,18 +6,35 @@ AS=nasm ASFLAGS= UTILITIES=../include - -all: user.o terminal.o stone.bin +STONE=stone +STONE_BIN = $(STONE)/stoneQ.bin $(STONE)/stoneW.bin $(STONE)/stoneA.bin $(STONE)/stoneS.bin +all: user.o terminal.o $(STONE_BIN) user.o: user.c $(UTILITIES)/utilities.h $(CC) $(CCFLAGS) -c $^ -terminal.o: terminal.c $(UTILITIES)/utilities.h stone.h +terminal.o: terminal.c $(UTILITIES)/utilities.h $(CC) $(CCFLAGS) -c $^ -stone.bin: stone.o $(UTILITIES)/utilities.o +$(STONE)/stoneQ.bin: $(STONE)/stoneQ.o $(UTILITIES)/utilities.o $(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^ -stone.o: stone.c $(UTILITIES)/utilities.h - $(CC) $(CCFLAGS) -c $^ +$(STONE)/stoneQ.o: $(STONE)/stone.c $(UTILITIES)/utilities.h + $(CC) $(CCFLAGS) -c $< -D UL -o $@ + +$(STONE)/stoneW.bin: $(STONE)/stoneW.o $(UTILITIES)/utilities.o + $(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^ +$(STONE)/stoneW.o: $(STONE)/stone.c $(UTILITIES)/utilities.h + $(CC) $(CCFLAGS) -c $< -D UR -o $@ + +$(STONE)/stoneS.bin: $(STONE)/stoneS.o $(UTILITIES)/utilities.o + $(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^ +$(STONE)/stoneS.o: $(STONE)/stone.c $(UTILITIES)/utilities.h + $(CC) $(CCFLAGS) -c $< -D DR -o $@ + +$(STONE)/stoneA.bin: $(STONE)/stoneA.o $(UTILITIES)/utilities.o + $(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^ +$(STONE)/stoneA.o: $(STONE)/stone.c $(UTILITIES)/utilities.h + $(CC) $(CCFLAGS) -c $< -D DL -o $@ + $(UTILITIES)/utilities.o: cd $(UTILITIES)/ && make diff --git a/step_3/user/stone.h b/step_3/user/stone.h deleted file mode 100644 index de5ced0..0000000 --- a/step_3/user/stone.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __STONE_H_ -#define __STONE_H_ -int stone(); -#endif \ No newline at end of file diff --git a/step_3/user/stone.c b/step_3/user/stone/stone.c similarity index 61% rename from step_3/user/stone.c rename to step_3/user/stone/stone.c index a4fe954..8515ed9 100644 --- a/step_3/user/stone.c +++ b/step_3/user/stone/stone.c @@ -1,7 +1,8 @@ __asm__("jmpl $0, $stone\n"); -#include "../include/utilities.h" -#define DELAY (1e5) +#include "../../include/utilities.h" +#include "stone.h" +#define DELAY (5 * 1e5) int getKbHit(); void checkBound(); @@ -11,10 +12,11 @@ int deltax; int deltay; int stone() { // return 0; - x = 5; - y = 5; + x = _X; + y = _Y; deltax = 1; deltay = 1; + uint8_t style = 0; clear_screen(); while(1) { @@ -24,11 +26,13 @@ int stone() { int delay = DELAY; while ((--delay) >= 0) continue; + draw_str(" ", y, x); x += deltax; y += deltay; checkBound(); - draw_str("A", y, x); + draw_str_style("A", y, x, style & 15); + style++; } } @@ -41,8 +45,8 @@ int getKbHit() { return 0; } void checkBound() { - if (x == 0) deltax = 1; - if (x == 79) deltax = -1; - if (y == 0) deltay = 1; - if (y == 24) deltay = -1; + if (x <= LEFT_B) deltax = 1; + if (x >= RIGHT_B) deltax = -1; + if (y <= UP_B) deltay = 1; + if (y >= DOWN_B) deltay = -1; } \ No newline at end of file diff --git a/step_3/user/stone/stone.h b/step_3/user/stone/stone.h new file mode 100644 index 0000000..a68bce4 --- /dev/null +++ b/step_3/user/stone/stone.h @@ -0,0 +1,33 @@ +#ifndef __STONE_H_ +#define __STONE_H_ +#if defined(UL) + #define _X 5 + #define _Y 5 + #define LEFT_B 1 + #define RIGHT_B 40 + #define UP_B 1 + #define DOWN_B 12 +#elif defined(UR) + #define _X 70 + #define _Y 5 + #define LEFT_B 40 + #define RIGHT_B 79 + #define UP_B 1 + #define DOWN_B 12 +#elif defined(DL) + #define _X 5 + #define _Y 20 + #define LEFT_B 1 + #define RIGHT_B 40 + #define UP_B 13 + #define DOWN_B 24 +#elif defined(DR) + #define _X 70 + #define _Y 20 + #define LEFT_B 40 + #define RIGHT_B 79 + #define UP_B 13 + #define DOWN_B 24 +#endif + +#endif \ No newline at end of file diff --git a/step_3/user/terminal.c b/step_3/user/terminal.c index 579e9c0..0236d7d 100644 --- a/step_3/user/terminal.c +++ b/step_3/user/terminal.c @@ -1,6 +1,5 @@ #include "../include/utilities.h" #include "../include/mystring.h" -#include "stone.h" #include "../filesystem/API/fsapi.h" #define BACK_SPACE 8 @@ -95,11 +94,15 @@ void parseCMD(int CMDindex) { FAT_ITEM* pfat = CUR_DIR; if (__FAT_showable_item(pfat)) { putln(pfat->filename); + // putiln(pfat->blow_cluster); + // putiln(pfat->filesize); } while (__has_next_item(pfat)) { pfat = __next_item(pfat); if (__FAT_showable_item(pfat)) { putln(pfat->filename); + // putiln(pfat->blow_cluster); + // putiln(pfat->filesize); } } }