├── !cons_9x.bat ├── !cons_nt.bat ├── .gitignore ├── Makefile ├── README.md ├── a ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── a.c └── make.bat ├── apilib.h ├── apilib ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── alloca.nas ├── api001.nas ├── api002.nas ├── api003.nas ├── api004.nas ├── api005.nas ├── api006.nas ├── api007.nas ├── api008.nas ├── api009.nas ├── api010.nas ├── api011.nas ├── api012.nas ├── api013.nas ├── api014.nas ├── api015.nas ├── api016.nas ├── api017.nas ├── api018.nas ├── api019.nas ├── api020.nas ├── api021.nas ├── api022.nas ├── api023.nas ├── api024.nas ├── api025.nas ├── api026.nas ├── api027.nas └── make.bat ├── app_make.txt ├── app_make_elf.txt ├── bball ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── bball.c └── make.bat ├── beepdown ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── beepdown.c └── make.bat ├── calc ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── calc.c └── make.bat ├── chklang ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── chklang.c └── make.bat ├── color ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── color.c └── make.bat ├── color2 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── color2.c └── make.bat ├── ebball ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── ebball.c ├── ld_variables.lds └── make.bat ├── einvader ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── einvader.c ├── ld_variables.lds └── make.bat ├── elines ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── elines.c ├── ld_variables.lds └── make.bat ├── euc.txt ├── gview ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── bmp.nasm ├── bmp.obj ├── gview.c ├── jpeg.c └── make.bat ├── haribote.rul ├── haribote ├── !cons_9x.bat ├── !cons_nt.bat ├── .gitignore ├── Makefile ├── asmhead.nas ├── bootpack.c ├── bootpack.h ├── console.c ├── dsctbl.c ├── elf.c ├── elf.h ├── fifo.c ├── file.c ├── graphic.c ├── hankaku.txt ├── hello.c ├── int.c ├── ipl11.nas ├── keyboard.c ├── lines.c ├── make.bat ├── memory.c ├── module.h ├── mouse.c ├── mtask.c ├── naskfunc.nas ├── noodle.c ├── sheet.c ├── tek.c ├── timer.c └── window.c ├── haribote_elf.lds ├── hello3 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── hello3.c └── make.bat ├── hello4 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── hello4.c └── make.bat ├── hello5 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── hello5.nas └── make.bat ├── invader ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── invader.c └── make.bat ├── ipl09.nas ├── iroha ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── iroha.c └── make.bat ├── lines ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── lines.c └── make.bat ├── make.bat ├── mmldata ├── daigo.mml ├── daigo.org ├── daiku.mml ├── daiku.org ├── fujisan.mml ├── fujisan.org ├── kirakira.mml └── kirakira.org ├── mmlplay ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── mmlplay.c ├── nihongo ├── jpn16v00.fnt ├── nihongo.fnt └── nihongo.org ├── noodle ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── noodle.c ├── notrec ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── notrec.c ├── pictdata ├── fujisan.jpg ├── fujisan_.jpg ├── night.bmp └── night_.bmp ├── sosu ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── sosu.c ├── sosu2 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat ├── sosu2.c └── sosu2.nas ├── sosu3 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── sosu3.c ├── star1 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── star1.c ├── stars ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── stars.c ├── stars2 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── stars2.c ├── tek ├── autodec_.c └── tek.c ├── tview ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── tview.c ├── type ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── type.c ├── walk ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── walk.c ├── winhelo ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── winhelo.c ├── winhelo2 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── winhelo2.c └── winhelo3 ├── !cons_9x.bat ├── !cons_nt.bat ├── Makefile ├── make.bat └── winhelo3.c /!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.hrb 2 | *.elf 3 | *.bin 4 | *.iso 5 | *.img 6 | *.obj 7 | *.o 8 | *.bim 9 | *.lst 10 | *.map 11 | *.lib 12 | *.a 13 | a/a.org 14 | hello4/hello4.org 15 | hello5/hello5.org 16 | iroha/iroha.org 17 | winhelo/winhelo.org 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TOOLPATH = ../z_tools/ 2 | INCPATH = ../z_tools/haribote/ 3 | 4 | MAKE = $(TOOLPATH)make -r 5 | EDIMG = $(TOOLPATH)edimg 6 | HARITOL = $(TOOLPATH)haritol 7 | 8 | # デフォルト動作 9 | 10 | default : 11 | $(MAKE) haribote.img 12 | 13 | # ファイル生成規則 14 | 15 | haribote.img : haribote/ipl11.bin haribote/haribote.sys Makefile \ 16 | a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \ 17 | winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \ 18 | star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \ 19 | lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \ 20 | beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \ 21 | sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \ 22 | type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \ 23 | notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \ 24 | calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb gview/gview.hrb \ 25 | ebball/ebball.elf einvader/einvader.elf elines/elines.elf \ 26 | haribote/autoexec.bat haribote/hello.ko 27 | $(EDIMG) imgin:../z_tools/fdimg0at.tek \ 28 | wbinimg src:haribote/ipl11.bin len:512 from:0 to:0 \ 29 | copy from:haribote/haribote.sys to:@: \ 30 | copy from:ipl09.nas to:@: \ 31 | copy from:make.bat to:@: \ 32 | copy from:a/a.hrb to:@: \ 33 | copy from:hello3/hello3.hrb to:@: \ 34 | copy from:hello4/hello4.hrb to:@: \ 35 | copy from:hello5/hello5.hrb to:@: \ 36 | copy from:winhelo/winhelo.hrb to:@: \ 37 | copy from:winhelo2/winhelo2.hrb to:@: \ 38 | copy from:winhelo3/winhelo3.hrb to:@: \ 39 | copy from:star1/star1.hrb to:@: \ 40 | copy from:stars/stars.hrb to:@: \ 41 | copy from:stars2/stars2.hrb to:@: \ 42 | copy from:lines/lines.hrb to:@: \ 43 | copy from:walk/walk.hrb to:@: \ 44 | copy from:noodle/noodle.hrb to:@: \ 45 | copy from:beepdown/beepdown.hrb to:@: \ 46 | copy from:color/color.hrb to:@: \ 47 | copy from:color2/color2.hrb to:@: \ 48 | copy from:sosu/sosu.hrb to:@: \ 49 | copy from:sosu2/sosu2.hrb to:@: \ 50 | copy from:sosu3/sosu3.hrb to:@: \ 51 | copy from:type/type.hrb to:@: \ 52 | copy from:iroha/iroha.hrb to:@: \ 53 | copy from:chklang/chklang.hrb to:@: \ 54 | copy from:euc.txt to:@: \ 55 | copy from:notrec/notrec.hrb to:@: \ 56 | copy from:bball/bball.hrb to:@: \ 57 | copy from:invader/invader.hrb to:@: \ 58 | copy from:calc/calc.hrb to:@: \ 59 | copy from:tview/tview.hrb to:@: \ 60 | copy from:mmlplay/mmlplay.hrb to:@: \ 61 | copy from:mmldata/kirakira.mml to:@: \ 62 | copy from:mmldata/fujisan.mml to:@: \ 63 | copy from:mmldata/daigo.mml to:@: \ 64 | copy from:mmldata/daiku.mml to:@: \ 65 | copy from:gview/gview.hrb to:@: \ 66 | copy from:pictdata/fujisan.jpg to:@: \ 67 | copy from:pictdata/night.bmp to:@: \ 68 | copy from:nihongo/nihongo.fnt to:@: \ 69 | copy from:ebball/ebball.elf to:@: \ 70 | copy from:einvader/einvader.elf to:@: \ 71 | copy from:elines/elines.elf to:@: \ 72 | copy from:haribote/autoexec.bat to:@: \ 73 | copy from:haribote/hello.ko to:@: \ 74 | imgout:haribote.img 75 | 76 | # コマンド 77 | 78 | run : 79 | $(MAKE) haribote.img 80 | $(HARITOL) concat ../z_tools/qemu/fdimage0.bin haribote.img 81 | $(MAKE) -C ../z_tools/qemu 82 | 83 | install : 84 | $(MAKE) haribote.img 85 | $(HARITOL) concat ../z_tools/fdwrite/fdimage0.bin haribote.img 86 | $(MAKE) -C ../z_tools/fdwrite 87 | 88 | iso : 89 | $(MAKE) haribote.img 90 | $(HARITOL) concat ../z_tools/makeiso/fdimage0.bin haribote.img 91 | $(MAKE) -C ../z_tools/makeiso 92 | $(HARITOL) concat haribote.iso ../z_tools/makeiso/haribote.iso 93 | 94 | full : 95 | $(MAKE) -C haribote 96 | $(MAKE) -C apilib 97 | $(MAKE) -C a 98 | $(MAKE) -C hello3 99 | $(MAKE) -C hello4 100 | $(MAKE) -C hello5 101 | $(MAKE) -C winhelo 102 | $(MAKE) -C winhelo2 103 | $(MAKE) -C winhelo3 104 | $(MAKE) -C star1 105 | $(MAKE) -C stars 106 | $(MAKE) -C stars2 107 | $(MAKE) -C lines 108 | $(MAKE) -C walk 109 | $(MAKE) -C noodle 110 | $(MAKE) -C beepdown 111 | $(MAKE) -C color 112 | $(MAKE) -C color2 113 | $(MAKE) -C sosu 114 | $(MAKE) -C sosu2 115 | $(MAKE) -C sosu3 116 | $(MAKE) -C type 117 | $(MAKE) -C iroha 118 | $(MAKE) -C chklang 119 | $(MAKE) -C notrec 120 | $(MAKE) -C bball 121 | $(MAKE) -C invader 122 | $(MAKE) -C calc 123 | $(MAKE) -C tview 124 | $(MAKE) -C mmlplay 125 | $(MAKE) -C gview 126 | $(MAKE) -C ebball 127 | $(MAKE) -C einvader 128 | $(MAKE) -C elines 129 | $(MAKE) haribote.img 130 | 131 | run_full : 132 | $(MAKE) full 133 | $(HARITOL) concat ../z_tools/qemu/fdimage0.bin haribote.img 134 | $(MAKE) -C ../z_tools/qemu 135 | 136 | install_full : 137 | $(MAKE) full 138 | $(IMGTOL) w a: haribote.img 139 | 140 | run_os : 141 | $(MAKE) -C haribote 142 | $(MAKE) run 143 | 144 | clean : 145 | # 何もしない 146 | 147 | src_only : 148 | $(MAKE) clean 149 | -$(HARITOL) remove haribote.img 150 | 151 | clean_full : 152 | $(MAKE) -C haribote clean 153 | $(MAKE) -C apilib clean 154 | $(MAKE) -C a clean 155 | $(MAKE) -C hello3 clean 156 | $(MAKE) -C hello4 clean 157 | $(MAKE) -C hello5 clean 158 | $(MAKE) -C winhelo clean 159 | $(MAKE) -C winhelo2 clean 160 | $(MAKE) -C winhelo3 clean 161 | $(MAKE) -C star1 clean 162 | $(MAKE) -C stars clean 163 | $(MAKE) -C stars2 clean 164 | $(MAKE) -C lines clean 165 | $(MAKE) -C walk clean 166 | $(MAKE) -C noodle clean 167 | $(MAKE) -C beepdown clean 168 | $(MAKE) -C color clean 169 | $(MAKE) -C color2 clean 170 | $(MAKE) -C sosu clean 171 | $(MAKE) -C sosu2 clean 172 | $(MAKE) -C sosu3 clean 173 | $(MAKE) -C type clean 174 | $(MAKE) -C iroha clean 175 | $(MAKE) -C chklang clean 176 | $(MAKE) -C notrec clean 177 | $(MAKE) -C bball clean 178 | $(MAKE) -C invader clean 179 | $(MAKE) -C calc clean 180 | $(MAKE) -C tview clean 181 | $(MAKE) -C mmlplay clean 182 | $(MAKE) -C gview clean 183 | $(MAKE) -C ebball clean 184 | $(MAKE) -C einvader clean 185 | $(MAKE) -C elines clean 186 | 187 | src_only_full : 188 | $(MAKE) -C haribote src_only 189 | $(MAKE) -C apilib src_only 190 | $(MAKE) -C a src_only 191 | $(MAKE) -C hello3 src_only 192 | $(MAKE) -C hello4 src_only 193 | $(MAKE) -C hello5 src_only 194 | $(MAKE) -C winhelo src_only 195 | $(MAKE) -C winhelo2 src_only 196 | $(MAKE) -C winhelo3 src_only 197 | $(MAKE) -C star1 src_only 198 | $(MAKE) -C stars src_only 199 | $(MAKE) -C stars2 src_only 200 | $(MAKE) -C lines src_only 201 | $(MAKE) -C walk src_only 202 | $(MAKE) -C noodle src_only 203 | $(MAKE) -C beepdown src_only 204 | $(MAKE) -C color src_only 205 | $(MAKE) -C color2 src_only 206 | $(MAKE) -C sosu src_only 207 | $(MAKE) -C sosu2 src_only 208 | $(MAKE) -C sosu3 src_only 209 | $(MAKE) -C type src_only 210 | $(MAKE) -C iroha src_only 211 | $(MAKE) -C chklang src_only 212 | $(MAKE) -C notrec src_only 213 | $(MAKE) -C bball src_only 214 | $(MAKE) -C invader src_only 215 | $(MAKE) -C calc src_only 216 | $(MAKE) -C tview src_only 217 | $(MAKE) -C mmlplay src_only 218 | $(MAKE) -C gview src_only 219 | $(MAKE) -C ebball src_only 220 | $(MAKE) -C einvader src_only 221 | $(MAKE) -C elines src_only 222 | -$(HARITOL) remove haribote.img 223 | -$(HARITOL) remove haribote.iso 224 | 225 | refresh : 226 | $(MAKE) full 227 | $(MAKE) clean_full 228 | -$(HARITOL) remove haribote.img 229 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/README.md -------------------------------------------------------------------------------- /a/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /a/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /a/Makefile: -------------------------------------------------------------------------------- 1 | APP = a 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | 7 | $(APP).hrb : $(APP).org Makefile 8 | $(COPY) $(APP).org $(APP).hrb 9 | -------------------------------------------------------------------------------- /a/a.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | api_putchar('A'); 6 | api_end(); 7 | } 8 | -------------------------------------------------------------------------------- /a/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /apilib.h: -------------------------------------------------------------------------------- 1 | void api_putchar(int c); 2 | void api_putstr0(char *s); 3 | void api_putstr1(char *s, int l); 4 | void api_end(void); 5 | int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); 6 | void api_putstrwin(int win, int x, int y, int col, int len, char *str); 7 | void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col); 8 | void api_initmalloc(void); 9 | char *api_malloc(int size); 10 | void api_free(char *addr, int size); 11 | void api_point(int win, int x, int y, int col); 12 | void api_refreshwin(int win, int x0, int y0, int x1, int y1); 13 | void api_linewin(int win, int x0, int y0, int x1, int y1, int col); 14 | void api_closewin(int win); 15 | int api_getkey(int mode); 16 | int api_alloctimer(void); 17 | void api_inittimer(int timer, int data); 18 | void api_settimer(int timer, int time); 19 | void api_freetimer(int timer); 20 | void api_beep(int tone); 21 | int api_fopen(char *fname); 22 | void api_fclose(int fhandle); 23 | void api_fseek(int fhandle, int offset, int mode); 24 | int api_fsize(int fhandle, int mode); 25 | int api_fread(char *buf, int maxsize, int fhandle); 26 | int api_cmdline(char *buf, int maxsize); 27 | int api_getlang(void); 28 | -------------------------------------------------------------------------------- /apilib/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /apilib/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /apilib/Makefile: -------------------------------------------------------------------------------- 1 | OBJS_API = api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \ 2 | api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \ 3 | api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \ 4 | api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \ 5 | api025.obj api026.obj api027.obj alloca.obj 6 | 7 | TOOLPATH = ../../z_tools/ 8 | #TOOLPATH86 = ../../../tolset_p86/z_tools/ 9 | INCPATH = ../../z_tools/haribote/ 10 | 11 | MAKE = $(TOOLPATH)make -r 12 | NASK = $(TOOLPATH)nask 13 | CC1 = $(TOOLPATH)gocc1 -I$(INCPATH) -Os -Wall -quiet 14 | GAS2NASK = $(TOOLPATH)gas2nask -a 15 | OBJ2BIM = $(TOOLPATH)obj2bim 16 | MAKEFONT = $(TOOLPATH)makefont 17 | BIN2OBJ = $(TOOLPATH)bin2obj 18 | BIM2HRB = $(TOOLPATH)bim2hrb 19 | RULEFILE = ../haribote.rul 20 | EDIMG = $(TOOLPATH)edimg 21 | GOLIB = $(TOOLPATH)golib00 22 | HARITOL = $(TOOLPATH)haritol 23 | COPY = $(HARITOL) copy 24 | DEL = $(HARITOL) remove 25 | 26 | #OBJCOPY = $(TOOLPATH86)i386-elf-gcc/bin/i386-elf-objcopy 27 | OBJCOPY = $(HOME)/gcc-6.3.0/i386-elf-gcc/bin/i386-elf-objcopy 28 | 29 | CLEAN_FILES := $(wildcard *.lst *.obj) 30 | 31 | # デフォルト動作 32 | 33 | default : 34 | $(MAKE) apilib.lib libapi.a 35 | 36 | # ファイル生成規則 37 | 38 | apilib.lib : Makefile $(OBJS_API) 39 | $(GOLIB) $(OBJS_API) out:apilib.lib 40 | 41 | libapi.a : apilib.lib Makefile 42 | $(OBJCOPY) apilib.lib -I coff-i386 -O elf32-i386 libapi.a 43 | 44 | # 一般規則 45 | 46 | %.obj : %.nas Makefile 47 | $(NASK) $*.nas $*.obj $*.lst 48 | 49 | # コマンド 50 | 51 | clean : 52 | -$(DEL) $(CLEAN_FILES) 53 | 54 | src_only : 55 | $(MAKE) clean 56 | -$(DEL) apilib.lib 57 | -------------------------------------------------------------------------------- /apilib/alloca.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "alloca.nas"] 5 | 6 | GLOBAL __alloca 7 | 8 | [SECTION .text] 9 | 10 | __alloca: 11 | ADD EAX,-4 12 | SUB ESP,EAX 13 | JMP DWORD [ESP+EAX] ; RETの代わり 14 | -------------------------------------------------------------------------------- /apilib/api001.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api001.nas"] 5 | 6 | GLOBAL _api_putchar 7 | 8 | [SECTION .text] 9 | 10 | _api_putchar: ; void api_putchar(int c); 11 | MOV EDX,1 12 | MOV AL,[ESP+4] ; c 13 | INT 0x40 14 | RET 15 | -------------------------------------------------------------------------------- /apilib/api002.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api002.nas"] 5 | 6 | GLOBAL _api_putstr0 7 | 8 | [SECTION .text] 9 | 10 | _api_putstr0: ; void api_putstr0(char *s); 11 | PUSH EBX 12 | MOV EDX,2 13 | MOV EBX,[ESP+8] ; s 14 | INT 0x40 15 | POP EBX 16 | RET 17 | -------------------------------------------------------------------------------- /apilib/api003.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api003.nas"] 5 | 6 | GLOBAL _api_putstr1 7 | 8 | [SECTION .text] 9 | 10 | _api_putstr1: ; void api_putstr1(char *s, int l); 11 | PUSH EBX 12 | MOV EDX,3 13 | MOV EBX,[ESP+ 8] ; s 14 | MOV ECX,[ESP+12] ; l 15 | INT 0x40 16 | POP EBX 17 | RET 18 | -------------------------------------------------------------------------------- /apilib/api004.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api004.nas"] 5 | 6 | GLOBAL _api_end 7 | 8 | [SECTION .text] 9 | 10 | _api_end: ; void api_end(void); 11 | MOV EDX,4 12 | INT 0x40 13 | -------------------------------------------------------------------------------- /apilib/api005.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api005.nas"] 5 | 6 | GLOBAL _api_openwin 7 | 8 | [SECTION .text] 9 | 10 | _api_openwin: ; int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBX 14 | MOV EDX,5 15 | MOV EBX,[ESP+16] ; buf 16 | MOV ESI,[ESP+20] ; xsiz 17 | MOV EDI,[ESP+24] ; ysiz 18 | MOV EAX,[ESP+28] ; col_inv 19 | MOV ECX,[ESP+32] ; title 20 | INT 0x40 21 | POP EBX 22 | POP ESI 23 | POP EDI 24 | RET 25 | -------------------------------------------------------------------------------- /apilib/api006.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api006.nas"] 5 | 6 | GLOBAL _api_putstrwin 7 | 8 | [SECTION .text] 9 | 10 | _api_putstrwin: ; void api_putstrwin(int win, int x, int y, int col, int len, char *str); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBP 14 | PUSH EBX 15 | MOV EDX,6 16 | MOV EBX,[ESP+20] ; win 17 | MOV ESI,[ESP+24] ; x 18 | MOV EDI,[ESP+28] ; y 19 | MOV EAX,[ESP+32] ; col 20 | MOV ECX,[ESP+36] ; len 21 | MOV EBP,[ESP+40] ; str 22 | INT 0x40 23 | POP EBX 24 | POP EBP 25 | POP ESI 26 | POP EDI 27 | RET 28 | -------------------------------------------------------------------------------- /apilib/api007.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api007.nas"] 5 | 6 | GLOBAL _api_boxfilwin 7 | 8 | [SECTION .text] 9 | 10 | _api_boxfilwin: ; void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBP 14 | PUSH EBX 15 | MOV EDX,7 16 | MOV EBX,[ESP+20] ; win 17 | MOV EAX,[ESP+24] ; x0 18 | MOV ECX,[ESP+28] ; y0 19 | MOV ESI,[ESP+32] ; x1 20 | MOV EDI,[ESP+36] ; y1 21 | MOV EBP,[ESP+40] ; col 22 | INT 0x40 23 | POP EBX 24 | POP EBP 25 | POP ESI 26 | POP EDI 27 | RET 28 | -------------------------------------------------------------------------------- /apilib/api008.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api008.nas"] 5 | 6 | GLOBAL _api_initmalloc 7 | 8 | [SECTION .text] 9 | 10 | _api_initmalloc: ; void api_initmalloc(void); 11 | PUSH EBX 12 | MOV EDX,8 13 | MOV EBX,[CS:0x0020] ; malloc領域の番地 14 | MOV EAX,EBX 15 | ADD EAX,32*1024 ; 32KBを足す 16 | MOV ECX,[CS:0x0000] ; データセグメントの大きさ 17 | SUB ECX,EAX 18 | INT 0x40 19 | POP EBX 20 | RET 21 | -------------------------------------------------------------------------------- /apilib/api009.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api009.nas"] 5 | 6 | GLOBAL _api_malloc 7 | 8 | [SECTION .text] 9 | 10 | _api_malloc: ; char *api_malloc(int size); 11 | PUSH EBX 12 | MOV EDX,9 13 | MOV EBX,[CS:0x0020] 14 | MOV ECX,[ESP+8] ; size 15 | INT 0x40 16 | POP EBX 17 | RET 18 | -------------------------------------------------------------------------------- /apilib/api010.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api010.nas"] 5 | 6 | GLOBAL _api_free 7 | 8 | [SECTION .text] 9 | 10 | _api_free: ; void api_free(char *addr, int size); 11 | PUSH EBX 12 | MOV EDX,10 13 | MOV EBX,[CS:0x0020] 14 | MOV EAX,[ESP+ 8] ; addr 15 | MOV ECX,[ESP+12] ; size 16 | INT 0x40 17 | POP EBX 18 | RET 19 | -------------------------------------------------------------------------------- /apilib/api011.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api011.nas"] 5 | 6 | GLOBAL _api_point 7 | 8 | [SECTION .text] 9 | 10 | _api_point: ; void api_point(int win, int x, int y, int col); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBX 14 | MOV EDX,11 15 | MOV EBX,[ESP+16] ; win 16 | MOV ESI,[ESP+20] ; x 17 | MOV EDI,[ESP+24] ; y 18 | MOV EAX,[ESP+28] ; col 19 | INT 0x40 20 | POP EBX 21 | POP ESI 22 | POP EDI 23 | RET 24 | -------------------------------------------------------------------------------- /apilib/api012.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api012.nas"] 5 | 6 | GLOBAL _api_refreshwin 7 | 8 | [SECTION .text] 9 | 10 | _api_refreshwin: ; void api_refreshwin(int win, int x0, int y0, int x1, int y1); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBX 14 | MOV EDX,12 15 | MOV EBX,[ESP+16] ; win 16 | MOV EAX,[ESP+20] ; x0 17 | MOV ECX,[ESP+24] ; y0 18 | MOV ESI,[ESP+28] ; x1 19 | MOV EDI,[ESP+32] ; y1 20 | INT 0x40 21 | POP EBX 22 | POP ESI 23 | POP EDI 24 | RET 25 | -------------------------------------------------------------------------------- /apilib/api013.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api013.nas"] 5 | 6 | GLOBAL _api_linewin 7 | 8 | [SECTION .text] 9 | 10 | _api_linewin: ; void api_linewin(int win, int x0, int y0, int x1, int y1, int col); 11 | PUSH EDI 12 | PUSH ESI 13 | PUSH EBP 14 | PUSH EBX 15 | MOV EDX,13 16 | MOV EBX,[ESP+20] ; win 17 | MOV EAX,[ESP+24] ; x0 18 | MOV ECX,[ESP+28] ; y0 19 | MOV ESI,[ESP+32] ; x1 20 | MOV EDI,[ESP+36] ; y1 21 | MOV EBP,[ESP+40] ; col 22 | INT 0x40 23 | POP EBX 24 | POP EBP 25 | POP ESI 26 | POP EDI 27 | RET 28 | -------------------------------------------------------------------------------- /apilib/api014.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api014.nas"] 5 | 6 | GLOBAL _api_closewin 7 | 8 | [SECTION .text] 9 | 10 | _api_closewin: ; void api_closewin(int win); 11 | PUSH EBX 12 | MOV EDX,14 13 | MOV EBX,[ESP+8] ; win 14 | INT 0x40 15 | POP EBX 16 | RET 17 | -------------------------------------------------------------------------------- /apilib/api015.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api015.nas"] 5 | 6 | GLOBAL _api_getkey 7 | 8 | [SECTION .text] 9 | 10 | _api_getkey: ; int api_getkey(int mode); 11 | MOV EDX,15 12 | MOV EAX,[ESP+4] ; mode 13 | INT 0x40 14 | RET 15 | -------------------------------------------------------------------------------- /apilib/api016.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api016.nas"] 5 | 6 | GLOBAL _api_alloctimer 7 | 8 | [SECTION .text] 9 | 10 | _api_alloctimer: ; int api_alloctimer(void); 11 | MOV EDX,16 12 | INT 0x40 13 | RET 14 | -------------------------------------------------------------------------------- /apilib/api017.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api017.nas"] 5 | 6 | GLOBAL _api_inittimer 7 | 8 | [SECTION .text] 9 | 10 | _api_inittimer: ; void api_inittimer(int timer, int data); 11 | PUSH EBX 12 | MOV EDX,17 13 | MOV EBX,[ESP+ 8] ; timer 14 | MOV EAX,[ESP+12] ; data 15 | INT 0x40 16 | POP EBX 17 | RET 18 | -------------------------------------------------------------------------------- /apilib/api018.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api018.nas"] 5 | 6 | GLOBAL _api_settimer 7 | 8 | [SECTION .text] 9 | 10 | _api_settimer: ; void api_settimer(int timer, int time); 11 | PUSH EBX 12 | MOV EDX,18 13 | MOV EBX,[ESP+ 8] ; timer 14 | MOV EAX,[ESP+12] ; time 15 | INT 0x40 16 | POP EBX 17 | RET 18 | -------------------------------------------------------------------------------- /apilib/api019.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api019.nas"] 5 | 6 | GLOBAL _api_freetimer 7 | 8 | [SECTION .text] 9 | 10 | _api_freetimer: ; void api_freetimer(int timer); 11 | PUSH EBX 12 | MOV EDX,19 13 | MOV EBX,[ESP+ 8] ; timer 14 | INT 0x40 15 | POP EBX 16 | RET 17 | -------------------------------------------------------------------------------- /apilib/api020.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api020.nas"] 5 | 6 | GLOBAL _api_beep 7 | 8 | [SECTION .text] 9 | 10 | _api_beep: ; void api_beep(int tone); 11 | MOV EDX,20 12 | MOV EAX,[ESP+4] ; tone 13 | INT 0x40 14 | RET 15 | -------------------------------------------------------------------------------- /apilib/api021.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api021.nas"] 5 | 6 | GLOBAL _api_fopen 7 | 8 | [SECTION .text] 9 | 10 | _api_fopen: ; int api_fopen(char *fname); 11 | PUSH EBX 12 | MOV EDX,21 13 | MOV EBX,[ESP+8] ; fname 14 | INT 0x40 15 | POP EBX 16 | RET 17 | -------------------------------------------------------------------------------- /apilib/api022.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api022.nas"] 5 | 6 | GLOBAL _api_fclose 7 | 8 | [SECTION .text] 9 | 10 | _api_fclose: ; void api_fclose(int fhandle); 11 | MOV EDX,22 12 | MOV EAX,[ESP+4] ; fhandle 13 | INT 0x40 14 | RET 15 | -------------------------------------------------------------------------------- /apilib/api023.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api023.nas"] 5 | 6 | GLOBAL _api_fseek 7 | 8 | [SECTION .text] 9 | 10 | _api_fseek: ; void api_fseek(int fhandle, int offset, int mode); 11 | PUSH EBX 12 | MOV EDX,23 13 | MOV EAX,[ESP+8] ; fhandle 14 | MOV ECX,[ESP+16] ; mode 15 | MOV EBX,[ESP+12] ; offset 16 | INT 0x40 17 | POP EBX 18 | RET 19 | -------------------------------------------------------------------------------- /apilib/api024.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api024.nas"] 5 | 6 | GLOBAL _api_fsize 7 | 8 | [SECTION .text] 9 | 10 | _api_fsize: ; int api_fsize(int fhandle, int mode); 11 | MOV EDX,24 12 | MOV EAX,[ESP+4] ; fhandle 13 | MOV ECX,[ESP+8] ; mode 14 | INT 0x40 15 | RET 16 | -------------------------------------------------------------------------------- /apilib/api025.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api025.nas"] 5 | 6 | GLOBAL _api_fread 7 | 8 | [SECTION .text] 9 | 10 | _api_fread: ; int api_fread(char *buf, int maxsize, int fhandle); 11 | PUSH EBX 12 | MOV EDX,25 13 | MOV EAX,[ESP+16] ; fhandle 14 | MOV ECX,[ESP+12] ; maxsize 15 | MOV EBX,[ESP+8] ; buf 16 | INT 0x40 17 | POP EBX 18 | RET 19 | -------------------------------------------------------------------------------- /apilib/api026.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api026.nas"] 5 | 6 | GLOBAL _api_cmdline 7 | 8 | [SECTION .text] 9 | 10 | _api_cmdline: ; int api_cmdline(char *buf, int maxsize); 11 | PUSH EBX 12 | MOV EDX,26 13 | MOV ECX,[ESP+12] ; maxsize 14 | MOV EBX,[ESP+8] ; buf 15 | INT 0x40 16 | POP EBX 17 | RET 18 | -------------------------------------------------------------------------------- /apilib/api027.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "api027.nas"] 5 | 6 | GLOBAL _api_getlang 7 | 8 | [SECTION .text] 9 | 10 | _api_getlang: ; int api_getlang(void); 11 | MOV EDX,27 12 | INT 0x40 13 | RET 14 | -------------------------------------------------------------------------------- /apilib/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /app_make.txt: -------------------------------------------------------------------------------- 1 | TOOLPATH = ../../z_tools/ 2 | INCPATH = ../../z_tools/haribote/ 3 | APILIBPATH = ../apilib/ 4 | HARIBOTEPATH = ../haribote/ 5 | 6 | MAKE = $(TOOLPATH)make -r 7 | NASK = $(TOOLPATH)nask 8 | CC1 = $(TOOLPATH)gocc1 -I$(INCPATH) -I../ -Os -Wall -quiet 9 | GAS2NASK = $(TOOLPATH)gas2nask -a 10 | OBJ2BIM = $(TOOLPATH)obj2bim 11 | MAKEFONT = $(TOOLPATH)makefont 12 | BIN2OBJ = $(TOOLPATH)bin2obj 13 | BIM2HRB = $(TOOLPATH)bim2hrb 14 | BIM2BIN = $(TOOLPATH)bim2bin 15 | RULEFILE = ../haribote.rul 16 | EDIMG = $(TOOLPATH)edimg 17 | IMGTOL = $(TOOLPATH)imgtol.com 18 | GOLIB = $(TOOLPATH)golib00 19 | HARITOL = $(TOOLPATH)haritol 20 | COPY = $(HARITOL) copy 21 | DEL = $(HARITOL) remove 22 | 23 | CLEAN_FILES := $(wildcard *.lst *.obj *.map *.bim *.org) 24 | 25 | # デフォルト動作 26 | 27 | default : 28 | $(MAKE) $(APP).hrb 29 | 30 | # ファイル生成規則 31 | 32 | $(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib Makefile ../app_make.txt 33 | $(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \ 34 | $(APP).obj $(APILIBPATH)apilib.lib 35 | 36 | haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \ 37 | Makefile ../app_make.txt 38 | $(EDIMG) imgin:../../z_tools/fdimg0at.tek \ 39 | wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \ 40 | copy from:../haribote/haribote.sys to:@: \ 41 | copy from:$(APP).hrb to:@: \ 42 | copy from:../nihongo/nihongo.fnt to:@: \ 43 | imgout:haribote.img 44 | 45 | # 一般規則 46 | 47 | %.gas : %.c ../apilib.h Makefile ../app_make.txt 48 | $(CC1) -o $*.gas $*.c 49 | 50 | %.nas : %.gas Makefile ../app_make.txt 51 | $(GAS2NASK) $*.gas $*.nas 52 | 53 | %.obj : %.nas Makefile ../app_make.txt 54 | $(NASK) $*.nas $*.obj $*.lst 55 | 56 | %.org : %.bim Makefile ../app_make.txt 57 | $(BIM2HRB) $*.bim $*.org $(MALLOC) 58 | 59 | %.hrb : %.org Makefile ../app_make.txt 60 | $(BIM2BIN) -osacmp in:$*.org out:$*.hrb 61 | 62 | # コマンド 63 | 64 | run : 65 | $(MAKE) haribote.img 66 | $(HARITOL) concat ..\..\z_tools\qemu\fdimage0.bin haribote.img 67 | $(MAKE) -C ../../z_tools/qemu 68 | 69 | full : 70 | $(MAKE) -C $(APILIBPATH) 71 | $(MAKE) $(APP).hrb 72 | 73 | run_full : 74 | $(MAKE) -C $(APILIBPATH) 75 | $(MAKE) -C ../haribote 76 | $(MAKE) run 77 | 78 | clean : 79 | -$(HARITOL) remove $(CLEAN_FILES) 80 | -$(DEL) haribote.img 81 | 82 | src_only : 83 | $(MAKE) clean 84 | -$(DEL) $(APP).hrb 85 | -------------------------------------------------------------------------------- /app_make_elf.txt: -------------------------------------------------------------------------------- 1 | TOOLPATH = ../../z_tools/ 2 | INCPATH = ../../z_tools/haribote/ 3 | APILIBPATH = ../apilib/ 4 | HARIBOTEPATH = ../haribote/ 5 | 6 | #TOOLPATH86 = ../../../tolset_p86/z_tools/ 7 | #ELFGCCPATH = $(TOOLPATH86)i386-elf-gcc/bin/ 8 | ELFGCCPATH = $(HOME)/gcc-6.3.0/i386-elf-gcc/bin/ 9 | export PATH:=$(subst /,\,$(TOOLPATH86));$(ELFGCCPATH);$(PATH) 10 | 11 | MAKE = $(TOOLPATH)make -r 12 | MAKEFONT = $(TOOLPATH)makefont 13 | EDIMG = $(TOOLPATH)edimg 14 | GOLIB = $(TOOLPATH)golib00 15 | HARITOL = $(TOOLPATH)haritol 16 | COPY = $(HARITOL) copy 17 | DEL = $(HARITOL) remove 18 | 19 | #NASM = $(TOOLPATH86)nasm 20 | NASM = nasm 21 | CC = $(ELFGCCPATH)i386-elf-gcc -I$(INCPATH) -I../ -Os -Wall -fleading-underscore -fno-unwind-tables -fno-asynchronous-unwind-tables 22 | LD = $(ELFGCCPATH)i386-elf-ld -L$(APILIBPATH) --nmagic 23 | LDSCRIPT = ../haribote_elf.lds 24 | 25 | CLEAN_FILES := $(wildcard *.o haribote.img) 26 | 27 | # デフォルト動作 28 | 29 | default : 30 | $(MAKE) $(APP).elf 31 | 32 | # ファイル生成規則 33 | 34 | $(APP).elf : $(APP).o $(APILIBPATH)libapi.a Makefile $(LDSCRIPT) ld_variables.lds ../app_make_elf.txt 35 | $(LD) --no-check-sections -T$(LDSCRIPT) -o $(APP).elf $(APP).o -lapi 36 | 37 | haribote.img : ../haribote/ipl11.bin ../haribote/haribote.sys $(APP).elf \ 38 | Makefile ../app_make.txt 39 | $(EDIMG) imgin:../../z_tools/fdimg0at.tek \ 40 | wbinimg src:../haribote/ipl11.bin len:512 from:0 to:0 \ 41 | copy from:../haribote/haribote.sys to:@: \ 42 | copy from:$(APP).elf to:@: \ 43 | copy from:../nihongo/nihongo.fnt to:@: \ 44 | imgout:haribote.img 45 | 46 | # 一般規則 47 | 48 | %.o : %.c ../apilib.h Makefile ../app_make_elf.txt 49 | $(CC) -c -o $*.o $*.c 50 | 51 | # コマンド 52 | 53 | run : 54 | $(MAKE) haribote.img 55 | $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin 56 | $(MAKE) -C ../../z_tools/qemu 57 | 58 | full : 59 | $(MAKE) -C $(APILIBPATH) 60 | $(MAKE) $(APP).elf 61 | 62 | run_full : 63 | $(MAKE) -C $(APILIBPATH) 64 | $(MAKE) -C ../haribote 65 | $(MAKE) run 66 | 67 | clean : 68 | -$(DEL) $(CLEAN_FILES) 69 | 70 | src_only : 71 | $(MAKE) clean 72 | -$(DEL) $(APP).elf 73 | -------------------------------------------------------------------------------- /bball/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /bball/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /bball/Makefile: -------------------------------------------------------------------------------- 1 | APP = bball 2 | STACK = 52k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /bball/bball.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int win, i, j, dis; 6 | char buf[216 * 237]; 7 | struct POINT { 8 | int x, y; 9 | }; 10 | static struct POINT table[16] = { 11 | { 204, 129 }, { 195, 90 }, { 172, 58 }, { 137, 38 }, { 98, 34 }, 12 | { 61, 46 }, { 31, 73 }, { 15, 110 }, { 15, 148 }, { 31, 185 }, 13 | { 61, 212 }, { 98, 224 }, { 137, 220 }, { 172, 200 }, { 195, 168 }, 14 | { 204, 129 } 15 | }; 16 | 17 | win = api_openwin(buf, 216, 237, -1, "bball"); 18 | api_boxfilwin(win, 8, 29, 207, 228, 0); 19 | for (i = 0; i <= 14; i++) { 20 | for (j = i + 1; j <= 15; j++) { 21 | dis = j - i; /* 2つの点の距離 */ 22 | if (dis >= 8) { 23 | dis = 15 - dis; /* 逆回りに数える */ 24 | } 25 | if (dis != 0) { 26 | api_linewin(win, table[i].x, table[i].y, table[j].x, table[j].y, 8 - dis); 27 | } 28 | } 29 | } 30 | 31 | for (;;) { 32 | if (api_getkey(1) == 0x0a) { 33 | break; /* Enterならbreak; */ 34 | } 35 | } 36 | api_end(); 37 | } 38 | -------------------------------------------------------------------------------- /bball/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /beepdown/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /beepdown/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /beepdown/Makefile: -------------------------------------------------------------------------------- 1 | APP = beepdown 2 | STACK = 1k 3 | MALLOC = 40k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /beepdown/beepdown.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int i, timer; 6 | timer = api_alloctimer(); 7 | api_inittimer(timer, 128); 8 | for (i = 20000000; i >= 20000; i -= i / 100) { 9 | /* 20KHz〜20Hz : 人間に聞こえる音の範囲 */ 10 | /* iは1%ずつ減らされていく */ 11 | api_beep(i); 12 | api_settimer(timer, 1); /* 0.01秒 */ 13 | if (api_getkey(1) != 128) { 14 | break; 15 | } 16 | } 17 | api_beep(0); 18 | api_end(); 19 | } 20 | -------------------------------------------------------------------------------- /beepdown/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /calc/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /calc/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /calc/Makefile: -------------------------------------------------------------------------------- 1 | APP = calc 2 | STACK = 4k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /calc/calc.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | #include /* sprintf */ 3 | 4 | #define INVALID -0x7fffffff 5 | 6 | int strtol(char *s, char **endp, int base); /* 標準関数(stdlib.h) */ 7 | 8 | char *skipspace(char *p); 9 | int getnum(char **pp, int priority); 10 | 11 | void HariMain(void) 12 | { 13 | int i; 14 | char s[30], *p; 15 | 16 | api_cmdline(s, 30); 17 | for (p = s; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 18 | i = getnum(&p, 9); 19 | if (i == INVALID) { 20 | api_putstr0("error!\n"); 21 | } else { 22 | sprintf(s, "= %d = 0x%x\n", i, i); 23 | api_putstr0(s); 24 | } 25 | api_end(); 26 | } 27 | 28 | char *skipspace(char *p) 29 | { 30 | for (; *p == ' '; p++) { } /* スペースを読み飛ばす */ 31 | return p; 32 | } 33 | 34 | int getnum(char **pp, int priority) 35 | { 36 | char *p = *pp; 37 | int i = INVALID, j; 38 | p = skipspace(p); 39 | 40 | /* 単項演算子 */ 41 | if (*p == '+') { 42 | p = skipspace(p + 1); 43 | i = getnum(&p, 0); 44 | } else if (*p == '-') { 45 | p = skipspace(p + 1); 46 | i = getnum(&p, 0); 47 | if (i != INVALID) { 48 | i = - i; 49 | } 50 | } else if (*p == '~') { 51 | p = skipspace(p + 1); 52 | i = getnum(&p, 0); 53 | if (i != INVALID) { 54 | i = ~i; 55 | } 56 | } else if (*p == '(') { /* かっこ */ 57 | p = skipspace(p + 1); 58 | i = getnum(&p, 9); 59 | if (*p == ')') { 60 | p = skipspace(p + 1); 61 | } else { 62 | i = INVALID; 63 | } 64 | } else if ('0' <= *p && *p <= '9') { /* 数値 */ 65 | i = strtol(p, &p, 0); 66 | } else { /* エラー */ 67 | i = INVALID; 68 | } 69 | 70 | /* 二項演算子 */ 71 | for (;;) { 72 | if (i == INVALID) { 73 | break; 74 | } 75 | p = skipspace(p); 76 | if (*p == '+' && priority >= 2) { 77 | p = skipspace(p + 1); 78 | j = getnum(&p, 2); 79 | if (j != INVALID) { 80 | i += j; 81 | } else { 82 | i = INVALID; 83 | } 84 | } else if (*p == '-' && priority >= 2) { 85 | p = skipspace(p + 1); 86 | j = getnum(&p, 2); 87 | if (j != INVALID) { 88 | i -= j; 89 | } else { 90 | i = INVALID; 91 | } 92 | } else if (*p == '*' && priority >= 1) { 93 | p = skipspace(p + 1); 94 | j = getnum(&p, 1); 95 | if (j != INVALID) { 96 | i *= j; 97 | } else { 98 | i = INVALID; 99 | } 100 | } else if (*p == '/' && priority >= 1) { 101 | p = skipspace(p + 1); 102 | j = getnum(&p, 1); 103 | if (j != INVALID && j != 0) { 104 | i /= j; 105 | } else { 106 | i = INVALID; 107 | } 108 | } else if (*p == '%' && priority >= 1) { 109 | p = skipspace(p + 1); 110 | j = getnum(&p, 1); 111 | if (j != INVALID && j != 0) { 112 | i %= j; 113 | } else { 114 | i = INVALID; 115 | } 116 | } else if (*p == '<' && p[1] == '<' && priority >= 3) { 117 | p = skipspace(p + 2); 118 | j = getnum(&p, 3); 119 | if (j != INVALID && j != 0) { 120 | i <<= j; 121 | } else { 122 | i = INVALID; 123 | } 124 | } else if (*p == '>' && p[1] == '>' && priority >= 3) { 125 | p = skipspace(p + 2); 126 | j = getnum(&p, 3); 127 | if (j != INVALID && j != 0) { 128 | i >>= j; 129 | } else { 130 | i = INVALID; 131 | } 132 | } else if (*p == '&' && priority >= 4) { 133 | p = skipspace(p + 1); 134 | j = getnum(&p, 4); 135 | if (j != INVALID) { 136 | i &= j; 137 | } else { 138 | i = INVALID; 139 | } 140 | } else if (*p == '^' && priority >= 5) { 141 | p = skipspace(p + 1); 142 | j = getnum(&p, 5); 143 | if (j != INVALID) { 144 | i ^= j; 145 | } else { 146 | i = INVALID; 147 | } 148 | } else if (*p == '|' && priority >= 6) { 149 | p = skipspace(p + 1); 150 | j = getnum(&p, 6); 151 | if (j != INVALID) { 152 | i |= j; 153 | } else { 154 | i = INVALID; 155 | } 156 | } else { 157 | break; 158 | } 159 | } 160 | p = skipspace(p); 161 | *pp = p; 162 | return i; 163 | } 164 | -------------------------------------------------------------------------------- /calc/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /chklang/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /chklang/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /chklang/Makefile: -------------------------------------------------------------------------------- 1 | APP = chklang 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /chklang/chklang.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int langmode = api_getlang(); 6 | static char s1[23] = { /* 日本語シフトJISモード */ 7 | 0x93, 0xfa, 0x96, 0x7b, 0x8c, 0xea, 0x83, 0x56, 0x83, 0x74, 0x83, 0x67, 8 | 0x4a, 0x49, 0x53, 0x83, 0x82, 0x81, 0x5b, 0x83, 0x68, 0x0a, 0x00 9 | }; 10 | static char s2[17] = { /* 日本語EUCモード */ 11 | 0xc6, 0xfc, 0xcb, 0xdc, 0xb8, 0xec, 0x45, 0x55, 0x43, 0xa5, 0xe2, 0xa1, 12 | 0xbc, 0xa5, 0xc9, 0x0a, 0x00 13 | }; 14 | if (langmode == 0) { 15 | api_putstr0("English ASCII mode\n"); 16 | } 17 | if (langmode == 1) { 18 | api_putstr0(s1); 19 | } 20 | if (langmode == 2) { 21 | api_putstr0(s2); 22 | } 23 | api_end(); 24 | } 25 | -------------------------------------------------------------------------------- /chklang/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /color/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /color/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /color/Makefile: -------------------------------------------------------------------------------- 1 | APP = color 2 | STACK = 1k 3 | MALLOC = 56k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /color/color.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win, x, y, r, g, b; 7 | api_initmalloc(); 8 | buf = api_malloc(144 * 164); 9 | win = api_openwin(buf, 144, 164, -1, "color"); 10 | for (y = 0; y < 128; y++) { 11 | for (x = 0; x < 128; x++) { 12 | r = x * 2; 13 | g = y * 2; 14 | b = 0; 15 | buf[(x + 8) + (y + 28) * 144] = 16 + (r / 43) + (g / 43) * 6 + (b / 43) * 36; 16 | } 17 | } 18 | api_refreshwin(win, 8, 28, 136, 156); 19 | api_getkey(1); /* てきとうなキー入力を待つ */ 20 | api_end(); 21 | } 22 | -------------------------------------------------------------------------------- /color/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /color2/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /color2/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /color2/Makefile: -------------------------------------------------------------------------------- 1 | APP = color2 2 | STACK = 1k 3 | MALLOC = 56k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /color2/color2.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | unsigned char rgb2pal(int r, int g, int b, int x, int y); 4 | 5 | void HariMain(void) 6 | { 7 | char *buf; 8 | int win, x, y; 9 | api_initmalloc(); 10 | buf = api_malloc(144 * 164); 11 | win = api_openwin(buf, 144, 164, -1, "color2"); 12 | for (y = 0; y < 128; y++) { 13 | for (x = 0; x < 128; x++) { 14 | buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y); 15 | } 16 | } 17 | api_refreshwin(win, 8, 28, 136, 156); 18 | api_getkey(1); /* てきとうなキー入力を待つ */ 19 | api_end(); 20 | } 21 | 22 | unsigned char rgb2pal(int r, int g, int b, int x, int y) 23 | { 24 | static int table[4] = { 3, 1, 0, 2 }; 25 | int i; 26 | x &= 1; /* 偶数か奇数か */ 27 | y &= 1; 28 | i = table[x + y * 2]; /* 中間色を作るための定数 */ 29 | r = (r * 21) / 256; /* これで 0〜20 になる */ 30 | g = (g * 21) / 256; 31 | b = (b * 21) / 256; 32 | r = (r + i) / 4; /* これで 0〜5 になる */ 33 | g = (g + i) / 4; 34 | b = (b + i) / 4; 35 | return 16 + r + g * 6 + b * 36; 36 | } 37 | -------------------------------------------------------------------------------- /color2/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /ebball/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /ebball/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /ebball/Makefile: -------------------------------------------------------------------------------- 1 | APP = ebball 2 | 3 | include ../app_make_elf.txt 4 | -------------------------------------------------------------------------------- /ebball/ebball.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int win, i, j, dis; 6 | char buf[216 * 237]; 7 | struct POINT { 8 | int x, y; 9 | }; 10 | static struct POINT table[16] = { 11 | { 204, 129 }, { 195, 90 }, { 172, 58 }, { 137, 38 }, { 98, 34 }, 12 | { 61, 46 }, { 31, 73 }, { 15, 110 }, { 15, 148 }, { 31, 185 }, 13 | { 61, 212 }, { 98, 224 }, { 137, 220 }, { 172, 200 }, { 195, 168 }, 14 | { 204, 129 } 15 | }; 16 | 17 | win = api_openwin(buf, 216, 237, -1, "bball"); 18 | api_boxfilwin(win, 8, 29, 207, 228, 0); 19 | for (i = 0; i <= 14; i++) { 20 | for (j = i + 1; j <= 15; j++) { 21 | dis = j - i; /* 2つの点の距離 */ 22 | if (dis >= 8) { 23 | dis = 15 - dis; /* 逆回りに数える */ 24 | } 25 | if (dis != 0) { 26 | api_linewin(win, table[i].x, table[i].y, table[j].x, table[j].y, 8 - dis); 27 | } 28 | } 29 | } 30 | 31 | for (;;) { 32 | if (api_getkey(1) == 0x0a) { 33 | break; /* Enterならbreak; */ 34 | } 35 | } 36 | api_end(); 37 | } 38 | -------------------------------------------------------------------------------- /ebball/ld_variables.lds: -------------------------------------------------------------------------------- 1 | STACK = 52*1024; 2 | MALLOC = 0; 3 | -------------------------------------------------------------------------------- /ebball/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /einvader/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /einvader/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /einvader/Makefile: -------------------------------------------------------------------------------- 1 | APP = einvader 2 | 3 | include ../app_make_elf.txt 4 | -------------------------------------------------------------------------------- /einvader/einvader.c: -------------------------------------------------------------------------------- 1 | #include /* strlen */ 2 | #include "apilib.h" 3 | 4 | void putstr(int win, char *winbuf, int x, int y, int col, unsigned char *s); 5 | void wait(int i, int timer, char *keyflag); 6 | void setdec8(char *s, int i); 7 | 8 | static unsigned char charset[16 * 8] = { 9 | 10 | /* invader(0) */ 11 | 0x00, 0x00, 0x00, 0x43, 0x5f, 0x5f, 0x5f, 0x7f, 12 | 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x20, 0x3f, 0x00, 13 | 14 | /* invader(1) */ 15 | 0x00, 0x0f, 0x7f, 0xff, 0xcf, 0xcf, 0xcf, 0xff, 16 | 0xff, 0xe0, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0x00, 17 | 18 | /* invader(2) */ 19 | 0x00, 0xf0, 0xfe, 0xff, 0xf3, 0xf3, 0xf3, 0xff, 20 | 0xff, 0x07, 0xff, 0xff, 0x03, 0x03, 0x03, 0x00, 21 | 22 | /* invader(3) */ 23 | 0x00, 0x00, 0x00, 0xc2, 0xfa, 0xfa, 0xfa, 0xfe, 24 | 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x04, 0xfc, 0x00, 25 | 26 | /* fighter(0) */ 27 | 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 28 | 0x01, 0x43, 0x47, 0x4f, 0x5f, 0x7f, 0x7f, 0x00, 29 | 30 | /* fighter(1) */ 31 | 0x18, 0x7e, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 32 | 0xff, 0xff, 0xe7, 0xe7, 0xe7, 0xe7, 0xff, 0x00, 33 | 34 | /* fighter(2) */ 35 | 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 36 | 0x80, 0xc2, 0xe2, 0xf2, 0xfa, 0xfe, 0xfe, 0x00, 37 | 38 | /* laser */ 39 | 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 40 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00 41 | }; 42 | /* invader:"abcd", fighter:"efg", laser:"h" */ 43 | 44 | void HariMain(void) 45 | { 46 | int win, timer, i, j, fx, laserwait, lx = 0, ly; 47 | int ix, iy, movewait0, movewait, idir; 48 | int invline, score, high, point; 49 | char winbuf[336 * 261], invstr[32 * 6], s[12], keyflag[4], *p; 50 | static char invstr0[32] = " abcd abcd abcd abcd abcd "; 51 | 52 | win = api_openwin(winbuf, 336, 261, -1, "invader"); 53 | api_boxfilwin(win, 6, 27, 329, 254, 0); 54 | timer = api_alloctimer(); 55 | api_inittimer(timer, 128); 56 | 57 | high = 0; 58 | putstr(win, winbuf, 22, 0, 7, "HIGH:00000000"); 59 | 60 | restart: 61 | score = 0; 62 | point = 1; 63 | putstr(win, winbuf, 4, 0, 7, "SCORE:00000000"); 64 | movewait0 = 20; 65 | fx = 18; 66 | putstr(win, winbuf, fx, 13, 6, "efg"); 67 | wait(100, timer, keyflag); 68 | 69 | next_group: 70 | wait(100, timer, keyflag); 71 | ix = 7; 72 | iy = 1; 73 | invline = 6; 74 | for (i = 0; i < 6; i++) { 75 | for (j = 0; j < 27; j++) { 76 | invstr[i * 32 + j] = invstr0[j]; 77 | } 78 | putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32); 79 | } 80 | keyflag[0] = 0; 81 | keyflag[1] = 0; 82 | keyflag[2] = 0; 83 | 84 | ly = 0; /* 非表示 */ 85 | laserwait = 0; 86 | movewait = movewait0; 87 | idir = +1; 88 | wait(100, timer, keyflag); 89 | 90 | for (;;) { 91 | if (laserwait != 0) { 92 | laserwait--; 93 | keyflag[2 /* space */] = 0; 94 | } 95 | 96 | wait(4, timer, keyflag); 97 | 98 | /* 自機の処理 */ 99 | if (keyflag[0 /* left */] != 0 && fx > 0) { 100 | fx--; 101 | putstr(win, winbuf, fx, 13, 6, "efg "); 102 | keyflag[0 /* left */] = 0; 103 | } 104 | if (keyflag[1 /* right */] != 0 && fx < 37) { 105 | putstr(win, winbuf, fx, 13, 6, " efg"); 106 | fx++; 107 | keyflag[1 /* right */] = 0; 108 | } 109 | if (keyflag[2 /* space */] != 0 && laserwait == 0) { 110 | laserwait = 15; 111 | lx = fx + 1; 112 | ly = 13; 113 | } 114 | 115 | /* インベーダ移動 */ 116 | if (movewait != 0) { 117 | movewait--; 118 | } else { 119 | movewait = movewait0; 120 | if (ix + idir > 14 || ix + idir < 0) { 121 | if (iy + invline == 13) { 122 | break; /* GAME OVER */ 123 | } 124 | idir = - idir; 125 | putstr(win, winbuf, ix + 1, iy, 0, " "); 126 | iy++; 127 | } else { 128 | ix += idir; 129 | } 130 | for (i = 0; i < invline; i++) { 131 | putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32); 132 | } 133 | } 134 | 135 | /* レーザー処理 */ 136 | if (ly > 0) { 137 | if (ly < 13) { 138 | if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) { 139 | putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32); 140 | } else { 141 | putstr(win, winbuf, lx, ly, 0, " "); 142 | } 143 | } 144 | ly--; 145 | if (ly > 0) { 146 | putstr(win, winbuf, lx, ly, 3, "h"); 147 | } else { 148 | point -= 10; 149 | if (point <= 0) { 150 | point = 1; 151 | } 152 | } 153 | if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) { 154 | p = invstr + (ly - iy) * 32 + (lx - ix); 155 | if (*p != ' ') { 156 | /* hit ! */ 157 | score += point; 158 | point++; 159 | setdec8(s, score); 160 | putstr(win, winbuf, 10, 0, 7, s); 161 | if (high < score) { 162 | high = score; 163 | putstr(win, winbuf, 27, 0, 7, s); 164 | } 165 | for (p--; *p != ' '; p--) { } 166 | for (i = 1; i < 5; i++) { 167 | p[i] = ' '; 168 | } 169 | putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32); 170 | for (; invline > 0; invline--) { 171 | for (p = invstr + (invline - 1) * 32; *p != 0; p++) { 172 | if (*p != ' ') { 173 | goto alive; 174 | } 175 | } 176 | } 177 | /* 全部やっつけられた */ 178 | movewait0 -= movewait0 / 3; 179 | goto next_group; 180 | alive: 181 | ly = 0; 182 | } 183 | } 184 | } 185 | } 186 | 187 | /* GAME OVER */ 188 | putstr(win, winbuf, 15, 6, 1, "GAME OVER"); 189 | wait(0, timer, keyflag); 190 | for (i = 1; i < 14; i++) { 191 | putstr(win, winbuf, 0, i, 0, " "); 192 | } 193 | goto restart; 194 | } 195 | 196 | void putstr(int win, char *winbuf, int x, int y, int col, unsigned char *s) 197 | { 198 | int c, x0, i; 199 | char *p, *q, t[2]; 200 | x = x * 8 + 8; 201 | y = y * 16 + 29; 202 | x0 = x; 203 | i = strlen(s); /* sの文字数を数える */ 204 | api_boxfilwin(win + 1, x, y, x + i * 8 - 1, y + 15, 0); 205 | q = winbuf + y * 336; 206 | t[1] = 0; 207 | for (;;) { 208 | c = *s; 209 | if (c == 0) { 210 | break; 211 | } 212 | if (c != ' ') { 213 | if ('a' <= c && c <= 'h') { 214 | p = charset + 16 * (c - 'a'); 215 | q += x; 216 | for (i = 0; i < 16; i++) { 217 | if ((p[i] & 0x80) != 0) { q[0] = col; } 218 | if ((p[i] & 0x40) != 0) { q[1] = col; } 219 | if ((p[i] & 0x20) != 0) { q[2] = col; } 220 | if ((p[i] & 0x10) != 0) { q[3] = col; } 221 | if ((p[i] & 0x08) != 0) { q[4] = col; } 222 | if ((p[i] & 0x04) != 0) { q[5] = col; } 223 | if ((p[i] & 0x02) != 0) { q[6] = col; } 224 | if ((p[i] & 0x01) != 0) { q[7] = col; } 225 | q += 336; 226 | } 227 | q -= 336 * 16 + x; 228 | } else { 229 | t[0] = *s; 230 | api_putstrwin(win + 1, x, y, col, 1, t); 231 | } 232 | } 233 | s++; 234 | x += 8; 235 | } 236 | api_refreshwin(win, x0, y, x, y + 16); 237 | return; 238 | } 239 | 240 | void wait(int i, int timer, char *keyflag) 241 | { 242 | int j; 243 | if (i > 0) { 244 | /* 一定時間待つ */ 245 | api_settimer(timer, i); 246 | i = 128; 247 | } else { 248 | i = 0x0a; /* Enter */ 249 | } 250 | for (;;) { 251 | j = api_getkey(1); 252 | if (i == j) { 253 | break; 254 | } 255 | if (j == '4') { 256 | keyflag[0 /* left */] = 1; 257 | } 258 | if (j == '6') { 259 | keyflag[1 /* right */] = 1; 260 | } 261 | if (j == ' ') { 262 | keyflag[2 /* space */] = 1; 263 | } 264 | } 265 | return; 266 | } 267 | 268 | void setdec8(char *s, int i) 269 | /* iを10進数表記でsに格納 */ 270 | { 271 | int j; 272 | for (j = 7; j >= 0; j--) { 273 | s[j] = '0' + i % 10; 274 | i /= 10; 275 | } 276 | s[8] = 0; 277 | return; 278 | } 279 | -------------------------------------------------------------------------------- /einvader/ld_variables.lds: -------------------------------------------------------------------------------- 1 | STACK = 90*1024; 2 | MALLOC = 0; 3 | -------------------------------------------------------------------------------- /einvader/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /elines/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /elines/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /elines/Makefile: -------------------------------------------------------------------------------- 1 | APP = elines 2 | STACK = 1k 3 | MALLOC = 48k 4 | 5 | include ../app_make_elf.txt 6 | -------------------------------------------------------------------------------- /elines/elines.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win, i; 7 | api_initmalloc(); 8 | buf = api_malloc(160 * 100); 9 | win = api_openwin(buf, 160, 100, -1, "lines"); 10 | for (i = 0; i < 8; i++) { 11 | api_linewin(win + 1, 8, 26, 77, i * 9 + 26, i); 12 | api_linewin(win + 1, 88, 26, i * 9 + 88, 89, i); 13 | } 14 | api_refreshwin(win, 6, 26, 154, 90); 15 | for (;;) { 16 | if (api_getkey(1) == 0x0a) { 17 | break; /* Enterならbreak; */ 18 | } 19 | } 20 | api_closewin(win); 21 | api_end(); 22 | } 23 | -------------------------------------------------------------------------------- /elines/ld_variables.lds: -------------------------------------------------------------------------------- 1 | STACK = 1*1024; 2 | MALLOC = 48*1024; 3 | -------------------------------------------------------------------------------- /elines/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /euc.txt: -------------------------------------------------------------------------------- 1 | 日本語EUCで書いてみたよー 2 | -------------------------------------------------------------------------------- /gview/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /gview/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /gview/Makefile: -------------------------------------------------------------------------------- 1 | APP = gview 2 | STACK = 4480k 3 | MALLOC = 0k 4 | 5 | TOOLPATH = ../../z_tools/ 6 | INCPATH = ../../z_tools/haribote/ 7 | APILIBPATH = ../apilib/ 8 | HARIBOTEPATH = ../haribote/ 9 | 10 | MAKE = $(TOOLPATH)make -r 11 | NASK = $(TOOLPATH)nask 12 | CC1 = $(TOOLPATH)gocc1 -I$(INCPATH) -I../ -Os -Wall -quiet 13 | GAS2NASK = $(TOOLPATH)gas2nask -a 14 | OBJ2BIM = $(TOOLPATH)obj2bim 15 | MAKEFONT = $(TOOLPATH)makefont 16 | BIN2OBJ = $(TOOLPATH)bin2obj 17 | BIM2HRB = $(TOOLPATH)bim2hrb 18 | BIM2BIN = $(TOOLPATH)bim2bin 19 | RULEFILE = ../haribote.rul 20 | EDIMG = $(TOOLPATH)edimg 21 | IMGTOL = $(TOOLPATH)imgtol.com 22 | GOLIB = $(TOOLPATH)golib00 23 | HARITOL = $(TOOLPATH)haritol 24 | COPY = $(HARITOL) copy 25 | DEL = $(HARITOL) remove 26 | 27 | CLEAN_FILES := $(wildcard *.lst *.map *.bim *.org) 28 | 29 | # デフォルト動作 30 | 31 | default : 32 | $(MAKE) $(APP).hrb 33 | 34 | # ファイル生成規則 35 | 36 | $(APP).bim : $(APP).obj bmp.obj jpeg.obj $(APILIBPATH)apilib.lib Makefile 37 | $(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \ 38 | $(APP).obj jpeg.obj bmp.obj $(APILIBPATH)apilib.lib 39 | 40 | haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \ 41 | Makefile 42 | $(EDIMG) imgin:../../z_tools/fdimg0at.tek \ 43 | wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \ 44 | copy from:../haribote/haribote.sys to:@: \ 45 | copy from:$(APP).hrb to:@: \ 46 | copy from:../nihongo/nihongo.fnt to:@: \ 47 | imgout:haribote.img 48 | 49 | # 一般規則 50 | 51 | %.gas : %.c ../apilib.h Makefile 52 | $(CC1) -o $*.gas $*.c 53 | 54 | %.nas : %.gas Makefile 55 | $(GAS2NASK) $*.gas $*.nas 56 | 57 | %.obj : %.nas Makefile 58 | $(NASK) $*.nas $*.obj $*.lst 59 | 60 | %.org : %.bim Makefile 61 | $(BIM2HRB) $*.bim $*.org $(MALLOC) 62 | 63 | %.hrb : %.org Makefile 64 | $(BIM2BIN) -osacmp in:$*.org out:$*.hrb 65 | 66 | # コマンド 67 | 68 | run : 69 | $(MAKE) haribote.img 70 | $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin 71 | $(MAKE) -C ../../z_tools/qemu 72 | 73 | full : 74 | $(MAKE) -C $(APILIBPATH) 75 | $(MAKE) $(APP).hrb 76 | 77 | run_full : 78 | $(MAKE) -C $(APILIBPATH) 79 | $(MAKE) -C ../haribote 80 | $(MAKE) run 81 | 82 | clean : 83 | -$(DEL) *.lst 84 | -$(DEL) gview.obj 85 | -$(DEL) jpeg.obj 86 | -$(DEL) *.map 87 | -$(DEL) *.bim 88 | -$(DEL) *.org 89 | -$(DEL) haribote.img 90 | 91 | src_only : 92 | $(MAKE) clean 93 | -$(DEL) $(APP).hrb 94 | -------------------------------------------------------------------------------- /gview/bmp.nasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/gview/bmp.nasm -------------------------------------------------------------------------------- /gview/bmp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/gview/bmp.obj -------------------------------------------------------------------------------- /gview/gview.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | struct DLL_STRPICENV { /* 64KB */ 4 | int work[64 * 1024 / 4]; 5 | }; 6 | 7 | struct RGB { 8 | unsigned char b, g, r, t; 9 | }; 10 | 11 | /* bmp.nasm */ 12 | int info_BMP(struct DLL_STRPICENV *env, int *info, int size, char *fp); 13 | int decode0_BMP(struct DLL_STRPICENV *env, int size, char *fp, int b_type, char *buf, int skip); 14 | 15 | /* jpeg.c */ 16 | int info_JPEG(struct DLL_STRPICENV *env, int *info, int size, char *fp); 17 | int decode0_JPEG(struct DLL_STRPICENV *env, int size, char *fp, int b_type, char *buf, int skip); 18 | 19 | unsigned char rgb2pal(int r, int g, int b, int x, int y); 20 | void error(char *s); 21 | 22 | void HariMain(void) 23 | { 24 | struct DLL_STRPICENV env; 25 | char filebuf[512 * 1024], winbuf[1040 * 805]; 26 | char s[32], *p; 27 | int win, i, j, fsize, xsize, info[8]; 28 | struct RGB picbuf[1024 * 768], *q; 29 | 30 | /* コマンドライン解析 */ 31 | api_cmdline(s, 30); 32 | for (p = s; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 33 | for (; *p == ' '; p++) { } /* スペースを読み飛ばす */ 34 | 35 | /* ファイル読み込み */ 36 | i = api_fopen(p); 37 | fsize = api_fsize(i, 0); 38 | if (fsize > 512 * 1024) { 39 | error("file too large.\n"); 40 | } 41 | api_fread(filebuf, fsize, i); 42 | api_fclose(i); 43 | 44 | /* ファイルタイプチェック */ 45 | if (info_BMP(&env, info, fsize, filebuf) == 0) { 46 | /* BMPではなかった */ 47 | if (info_JPEG(&env, info, fsize, filebuf) == 0) { 48 | /* JPEGでもなかった */ 49 | api_putstr0("file type unknown.\n"); 50 | api_end(); 51 | } 52 | } 53 | /* どちらかのinfo関数が成功すると、以下の情報がinfoに入っている */ 54 | /* info[0] : ファイルタイプ (1:BMP, 2:JPEG) */ 55 | /* info[1] : カラー情報 */ 56 | /* info[2] : xsize */ 57 | /* info[3] ; ysize */ 58 | 59 | if (info[2] > 1024 || info[3] > 768) { 60 | error("picture too large.\n"); 61 | } 62 | 63 | /* ウィンドウの準備 */ 64 | xsize = info[2] + 16; 65 | if (xsize < 136) { 66 | xsize = 136; 67 | } 68 | win = api_openwin(winbuf, xsize, info[3] + 37, -1, "gview"); 69 | 70 | /* ファイル内容を画像データに変換 */ 71 | if (info[0] == 1) { 72 | i = decode0_BMP (&env, fsize, filebuf, 4, (char *) picbuf, 0); 73 | } else { 74 | i = decode0_JPEG(&env, fsize, filebuf, 4, (char *) picbuf, 0); 75 | } 76 | /* b_type = 4 は、 struct RGB 形式を意味する */ 77 | /* skipは0にしておけばよい */ 78 | if (i != 0) { 79 | error("decode error.\n"); 80 | } 81 | 82 | /* 表示 */ 83 | for (i = 0; i < info[3]; i++) { 84 | p = winbuf + (i + 29) * xsize + (xsize - info[2]) / 2; 85 | q = picbuf + i * info[2]; 86 | for (j = 0; j < info[2]; j++) { 87 | p[j] = rgb2pal(q[j].r, q[j].g, q[j].b, j, i); 88 | } 89 | } 90 | api_refreshwin(win, (xsize - info[2]) / 2, 29, (xsize - info[2]) / 2 + info[2], 29 + info[3]); 91 | 92 | /* 終了待ち */ 93 | for (;;) { 94 | i = api_getkey(1); 95 | if (i == 'Q' || i == 'q') { 96 | api_end(); 97 | } 98 | } 99 | } 100 | 101 | unsigned char rgb2pal(int r, int g, int b, int x, int y) 102 | { 103 | static int table[4] = { 3, 1, 0, 2 }; 104 | int i; 105 | x &= 1; /* 偶数か奇数か */ 106 | y &= 1; 107 | i = table[x + y * 2]; /* 中間色を作るための定数 */ 108 | r = (r * 21) / 256; /* これで 0〜20 になる */ 109 | g = (g * 21) / 256; 110 | b = (b * 21) / 256; 111 | r = (r + i) / 4; /* これで 0〜5 になる */ 112 | g = (g + i) / 4; 113 | b = (b + i) / 4; 114 | return 16 + r + g * 6 + b * 36; 115 | } 116 | 117 | void error(char *s) 118 | { 119 | api_putstr0(s); 120 | api_end(); 121 | } 122 | -------------------------------------------------------------------------------- /gview/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /haribote.rul: -------------------------------------------------------------------------------- 1 | format: 2 | /* このセクションでリンクの方針を記述 */ 3 | code(align:1, logic:0x24, file:0x24); 4 | data(align:4, logic:stack_end, file:code_end); 5 | 6 | file: 7 | /* このセクションでコマンドラインに書ききれなかった 8 | .ojbファイル、.libファイルを記載 */ 9 | /* なお、このセクションはフルパスで書いてもよい。 */ 10 | /* 例: c:/osask/gg00libc.lib; */ 11 | ../../z_tools/haribote/harilibc.lib; 12 | ../../z_tools/haribote/golibc.lib; 13 | 14 | label: 15 | /* 必ずリンクしなければいけないラベルを指定 */ 16 | /* エントリポイントを指定すればいいと思ってください */ 17 | _HariStartup; 18 | 19 | /* 上記3セクションの順序は入れ替えてはいけません! */ 20 | -------------------------------------------------------------------------------- /haribote/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /haribote/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /haribote/.gitignore: -------------------------------------------------------------------------------- 1 | *.sys 2 | *.bin 3 | -------------------------------------------------------------------------------- /haribote/Makefile: -------------------------------------------------------------------------------- 1 | OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \ 2 | int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj \ 3 | mtask.obj window.obj console.obj file.obj tek.obj elf.obj 4 | 5 | TOOLPATH = ../../z_tools/ 6 | INCPATH = ../../z_tools/haribote/ 7 | 8 | MAKE = $(TOOLPATH)make -r 9 | NASK = $(TOOLPATH)nask 10 | CC1 = $(TOOLPATH)gocc1 -I$(INCPATH) -Os -Wall -quiet 11 | GAS2NASK = $(TOOLPATH)gas2nask -a 12 | OBJ2BIM = $(TOOLPATH)obj2bim 13 | MAKEFONT = $(TOOLPATH)makefont 14 | BIN2OBJ = $(TOOLPATH)bin2obj 15 | BIM2HRB = $(TOOLPATH)bim2hrb 16 | RULEFILE = ../haribote.rul 17 | EDIMG = $(TOOLPATH)edimg 18 | IMGTOL = $(TOOLPATH)imgtol 19 | GOLIB = $(TOOLPATH)golib00 20 | HARITOL = $(TOOLPATH)haritol 21 | 22 | CLEAN_FILES := $(wildcard *.lst *.obj *.map *.bim *.hrb) 23 | 24 | 25 | #TOOLPATH86 = ../../../tolset_p86/z_tools/ 26 | #ELFGCCPATH = $(TOOLPATH86)i386-elf-gcc/bin/ 27 | ELFGCCPATH = $(HOME)/gcc-6.3.0/i386-elf-gcc/bin/ 28 | export PATH:=$(subst /,\,$(TOOLPATH86));$(ELFGCCPATH);$(PATH) 29 | 30 | CC = $(ELFGCCPATH)i386-elf-gcc -I$(INCPATH) -I../ -Os -Wall -fleading-underscore -fno-unwind-tables -fno-asynchronous-unwind-tables 31 | LD = $(ELFGCCPATH)i386-elf-ld -L$(APILIBPATH) --nmagic 32 | 33 | 34 | # デフォルト動作 35 | 36 | default : 37 | $(MAKE) ipl11.bin 38 | $(MAKE) haribote.sys 39 | 40 | # ファイル生成規則 41 | 42 | ipl11.bin : ipl11.nas Makefile 43 | $(NASK) ipl11.nas ipl11.bin ipl11.lst 44 | 45 | asmhead.bin : asmhead.nas Makefile 46 | $(NASK) asmhead.nas asmhead.bin asmhead.lst 47 | 48 | hankaku.bin : hankaku.txt Makefile 49 | $(MAKEFONT) hankaku.txt hankaku.bin 50 | 51 | hankaku.obj : hankaku.bin Makefile 52 | $(BIN2OBJ) hankaku.bin hankaku.obj _hankaku 53 | 54 | bootpack.bim : $(OBJS_BOOTPACK) Makefile 55 | $(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \ 56 | $(OBJS_BOOTPACK) 57 | # 3MB+64KB=3136KB 58 | 59 | bootpack.hrb : bootpack.bim Makefile 60 | $(BIM2HRB) bootpack.bim bootpack.hrb 0 61 | 62 | haribote.sys : asmhead.bin bootpack.hrb Makefile 63 | $(HARITOL) concat haribote.sys asmhead.bin bootpack.hrb 64 | 65 | hello.ko : hello.c Makefile 66 | $(CC) -c hello.c 67 | $(HARITOL) copy hello.o hello.ko 68 | 69 | # 一般規則 70 | 71 | %.gas : %.c bootpack.h Makefile 72 | $(CC1) -o $*.gas $*.c 73 | 74 | %.nas : %.gas Makefile 75 | $(GAS2NASK) $*.gas $*.nas 76 | 77 | %.obj : %.nas Makefile 78 | $(NASK) $*.nas $*.obj $*.lst 79 | 80 | # コマンド 81 | 82 | clean : 83 | -$(HARITOL) remove asmhead.bin 84 | -$(HARITOL) remove hankaku.bin 85 | -$(HARITOL) remove $(CLEAN_FILES) 86 | 87 | src_only : 88 | $(MAKE) clean 89 | -$(HARITOL) remove $(wildcard ipl*.bin) 90 | -$(HARITOL) remove haribote.sys 91 | -------------------------------------------------------------------------------- /haribote/asmhead.nas: -------------------------------------------------------------------------------- 1 | ; haribote-os boot asm 2 | ; TAB=4 3 | 4 | [INSTRSET "i486p"] 5 | 6 | VBEMODE EQU 0x105 ; 1024 x 768 x 8bitカラー 7 | ; (画面モード一覧) 8 | ; 0x100 : 640 x 400 x 8bitカラー 9 | ; 0x101 : 640 x 480 x 8bitカラー 10 | ; 0x103 : 800 x 600 x 8bitカラー 11 | ; 0x105 : 1024 x 768 x 8bitカラー 12 | ; 0x107 : 1280 x 1024 x 8bitカラー 13 | 14 | BOTPAK EQU 0x00280000 ; bootpackのロード先 15 | DSKCAC EQU 0x00100000 ; ディスクキャッシュの場所 16 | DSKCAC0 EQU 0x00008000 ; ディスクキャッシュの場所(リアルモード) 17 | 18 | ; BOOT_INFO関係 19 | CYLS EQU 0x0ff0 ; ブートセクタが設定する 20 | LEDS EQU 0x0ff1 21 | VMODE EQU 0x0ff2 ; 色数に関する情報。何ビットカラーか? 22 | SCRNX EQU 0x0ff4 ; 解像度のX 23 | SCRNY EQU 0x0ff6 ; 解像度のY 24 | VRAM EQU 0x0ff8 ; グラフィックバッファの開始番地 25 | 26 | ORG 0xc200 ; このプログラムがどこに読み込まれるのか 27 | 28 | ; VBE存在確認 29 | 30 | MOV AX,0x9000 31 | MOV ES,AX 32 | MOV DI,0 33 | MOV AX,0x4f00 34 | INT 0x10 35 | CMP AX,0x004f 36 | JNE scrn320 37 | 38 | ; VBEのバージョンチェック 39 | 40 | MOV AX,[ES:DI+4] 41 | CMP AX,0x0200 42 | JB scrn320 ; if (AX < 0x0200) goto scrn320 43 | 44 | ; 画面モード情報を得る 45 | 46 | MOV CX,VBEMODE 47 | MOV AX,0x4f01 48 | INT 0x10 49 | CMP AX,0x004f 50 | JNE scrn320 51 | 52 | ; 画面モード情報の確認 53 | 54 | CMP BYTE [ES:DI+0x19],8 55 | JNE scrn320 56 | CMP BYTE [ES:DI+0x1b],4 57 | JNE scrn320 58 | MOV AX,[ES:DI+0x00] 59 | AND AX,0x0080 60 | JZ scrn320 ; モード属性のbit7が0だったのであきらめる 61 | 62 | ; 画面モードの切り替え 63 | 64 | MOV BX,VBEMODE+0x4000 65 | MOV AX,0x4f02 66 | INT 0x10 67 | MOV BYTE [VMODE],8 ; 画面モードをメモする(C言語が参照する) 68 | MOV AX,[ES:DI+0x12] 69 | MOV [SCRNX],AX 70 | MOV AX,[ES:DI+0x14] 71 | MOV [SCRNY],AX 72 | MOV EAX,[ES:DI+0x28] 73 | MOV [VRAM],EAX 74 | JMP keystatus 75 | 76 | scrn320: 77 | MOV AL,0x13 ; VGAグラフィックス、320x200x8bitカラー 78 | MOV AH,0x00 79 | INT 0x10 80 | MOV BYTE [VMODE],8 ; 画面モードをメモする(C言語が参照する) 81 | MOV WORD [SCRNX],320 82 | MOV WORD [SCRNY],200 83 | MOV DWORD [VRAM],0x000a0000 84 | 85 | ; キーボードのLED状態をBIOSに教えてもらう 86 | 87 | keystatus: 88 | MOV AH,0x02 89 | INT 0x16 ; keyboard BIOS 90 | MOV [LEDS],AL 91 | 92 | ; PICが一切の割り込みを受け付けないようにする 93 | ; AT互換機の仕様では、PICの初期化をするなら、 94 | ; こいつをCLI前にやっておかないと、たまにハングアップする 95 | ; PICの初期化はあとでやる 96 | 97 | MOV AL,0xff 98 | OUT 0x21,AL 99 | NOP ; OUT命令を連続させるとうまくいかない機種があるらしいので 100 | OUT 0xa1,AL 101 | 102 | CLI ; さらにCPUレベルでも割り込み禁止 103 | 104 | ; CPUから1MB以上のメモリにアクセスできるように、A20GATEを設定 105 | 106 | CALL waitkbdout 107 | MOV AL,0xd1 108 | OUT 0x64,AL 109 | CALL waitkbdout 110 | MOV AL,0xdf ; enable A20 111 | OUT 0x60,AL 112 | CALL waitkbdout 113 | 114 | ; プロテクトモード移行 115 | 116 | LGDT [GDTR0] ; 暫定GDTを設定 117 | MOV EAX,CR0 118 | AND EAX,0x7fffffff ; bit31を0にする(ページング禁止のため) 119 | OR EAX,0x00000001 ; bit0を1にする(プロテクトモード移行のため) 120 | MOV CR0,EAX 121 | JMP pipelineflash 122 | pipelineflash: 123 | MOV AX,1*8 ; 読み書き可能セグメント32bit 124 | MOV DS,AX 125 | MOV ES,AX 126 | MOV FS,AX 127 | MOV GS,AX 128 | MOV SS,AX 129 | 130 | ; bootpackの転送 131 | 132 | MOV ESI,bootpack ; 転送元 133 | MOV EDI,BOTPAK ; 転送先 134 | MOV ECX,512*1024/4 135 | CALL memcpy 136 | 137 | ; ついでにディスクデータも本来の位置へ転送 138 | 139 | ; まずはブートセクタから 140 | 141 | MOV ESI,0x7c00 ; 転送元 142 | MOV EDI,DSKCAC ; 転送先 143 | MOV ECX,512/4 144 | CALL memcpy 145 | 146 | ; 残り全部 147 | 148 | MOV ESI,DSKCAC0+512 ; 転送元 149 | MOV EDI,DSKCAC+512 ; 転送先 150 | MOV ECX,0 151 | MOV CL,BYTE [CYLS] 152 | IMUL ECX,512*18*2/4 ; シリンダ数からバイト数/4に変換 153 | SUB ECX,512/4 ; IPLの分だけ差し引く 154 | CALL memcpy 155 | 156 | ; asmheadでしなければいけないことは全部し終わったので、 157 | ; あとはbootpackに任せる 158 | 159 | ; bootpackの起動 160 | 161 | MOV EBX,BOTPAK 162 | MOV ECX,[EBX+16] 163 | ADD ECX,3 ; ECX += 3; 164 | SHR ECX,2 ; ECX /= 4; 165 | JZ skip ; 転送するべきものがない 166 | MOV ESI,[EBX+20] ; 転送元 167 | ADD ESI,EBX 168 | MOV EDI,[EBX+12] ; 転送先 169 | CALL memcpy 170 | skip: 171 | MOV ESP,[EBX+12] ; スタック初期値 172 | JMP DWORD 2*8:0x0000001b 173 | 174 | waitkbdout: 175 | IN AL,0x64 176 | AND AL,0x02 177 | IN AL,0x60 ; から読み(受信バッファが悪さをしないように) 178 | JNZ waitkbdout ; ANDの結果が0でなければwaitkbdoutへ 179 | RET 180 | 181 | memcpy: 182 | MOV EAX,[ESI] 183 | ADD ESI,4 184 | MOV [EDI],EAX 185 | ADD EDI,4 186 | SUB ECX,1 187 | JNZ memcpy ; 引き算した結果が0でなければmemcpyへ 188 | RET 189 | ; memcpyはアドレスサイズプリフィクスを入れ忘れなければ、ストリング命令でも書ける 190 | 191 | ALIGNB 16 192 | GDT0: 193 | RESB 8 ; ヌルセレクタ 194 | DW 0xffff,0x0000,0x9200,0x00cf ; 読み書き可能セグメント32bit 195 | ;DW 0xffff,0x0000,0x9a28,0x0047 ; 実行可能セグメント32bit(bootpack用) 196 | DW 0xffff,0x0000,0x9a28,0x00cf ; 実行可能セグメント32bit(bootpack用) 197 | 198 | DW 0 199 | GDTR0: 200 | DW 8*3-1 201 | DD GDT0 202 | 203 | ALIGNB 16 204 | bootpack: 205 | -------------------------------------------------------------------------------- /haribote/bootpack.c: -------------------------------------------------------------------------------- 1 | /* bootpackのメイン */ 2 | 3 | #include "bootpack.h" 4 | #include 5 | 6 | #define KEYCMD_LED 0xed 7 | 8 | void keywin_off(struct SHEET *key_win); 9 | void keywin_on(struct SHEET *key_win); 10 | void close_console(struct SHEET *sht); 11 | void close_constask(struct TASK *task); 12 | 13 | struct CONSOLE **default_console; 14 | 15 | void HariMain(void) 16 | { 17 | struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; 18 | struct SHTCTL *shtctl; 19 | char s[40]; 20 | struct FIFO32 fifo, keycmd; 21 | int fifobuf[128], keycmd_buf[32]; 22 | int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; 23 | unsigned int memtotal; 24 | struct MOUSE_DEC mdec; 25 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 26 | unsigned char *buf_back, buf_mouse[256]; 27 | struct SHEET *sht_back, *sht_mouse, *sht_cons; 28 | struct TASK *task_a, *task; 29 | static char keytable0[0x80] = { 30 | 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 31 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 32 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 33 | 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 34 | 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', 35 | '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37 | 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 38 | }; 39 | static char keytable1[0x80] = { 40 | 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 41 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 42 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 43 | 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 44 | 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', 45 | '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47 | 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 48 | }; 49 | int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; 50 | int j, x, y, mmx = -1, mmy = -1, mmx2 = 0; 51 | struct SHEET *sht = 0, *key_win, *sht2; 52 | int *fat; 53 | unsigned char *nihongo; 54 | struct FILEINFO *finfo; 55 | extern char hankaku[4096]; 56 | 57 | init_gdtidt(); 58 | init_pic(); 59 | io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ 60 | fifo32_init(&fifo, 128, fifobuf, 0); 61 | *((int *) 0x0fec) = (int) &fifo; 62 | init_pit(); 63 | init_keyboard(&fifo, 256); 64 | enable_mouse(&fifo, 512, &mdec); 65 | io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ 66 | io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ 67 | fifo32_init(&keycmd, 32, keycmd_buf, 0); 68 | 69 | memtotal = memtest(0x00400000, 0xbfffffff); 70 | memman_init(memman); 71 | //memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ 72 | memman_free(memman, 0x00400000, memtotal - 0x00400000); 73 | 74 | init_palette(); 75 | shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); 76 | task_a = task_init(memman); 77 | fifo.task = task_a; 78 | task_run(task_a, 1, 2); 79 | *((int *) 0x0fe4) = (int) shtctl; 80 | task_a->langmode = 0; 81 | 82 | /* sht_back */ 83 | sht_back = sheet_alloc(shtctl); 84 | buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); 85 | sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ 86 | init_screen8(buf_back, binfo->scrnx, binfo->scrny); 87 | 88 | /* sht_cons */ 89 | sht_cons = key_win = open_console(shtctl, memtotal, 80, 24); 90 | default_console = &sht_cons->task->cons; 91 | 92 | /* sht_mouse */ 93 | sht_mouse = sheet_alloc(shtctl); 94 | sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); 95 | init_mouse_cursor8(buf_mouse, 99); 96 | mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ 97 | my = (binfo->scrny - 28 - 16) / 2; 98 | 99 | sheet_slide(sht_back, 0, 0); 100 | sheet_slide(key_win, 32, 4); 101 | sheet_slide(sht_mouse, mx, my); 102 | sheet_updown(sht_back, 0); 103 | sheet_updown(key_win, 1); 104 | sheet_updown(sht_mouse, 2); 105 | keywin_on(key_win); 106 | 107 | /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ 108 | fifo32_put(&keycmd, KEYCMD_LED); 109 | fifo32_put(&keycmd, key_leds); 110 | 111 | /* nihongo.fntの読み込み */ 112 | fat = (int *) memman_alloc_4k(memman, 4 * 2880); 113 | file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); 114 | 115 | finfo = file_search("nihongo.fnt", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); 116 | if (finfo != 0) { 117 | i = finfo->size; 118 | nihongo = file_loadfile2(finfo->clustno, &i, fat); 119 | } else { 120 | nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47); 121 | for (i = 0; i < 16 * 256; i++) { 122 | nihongo[i] = hankaku[i]; /* フォントがなかったので半角部分をコピー */ 123 | } 124 | for (i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) { 125 | nihongo[i] = 0xff; /* フォントがなかったので全角部分を0xffで埋め尽くす */ 126 | } 127 | } 128 | *((int *) 0x0fe8) = (int) nihongo; 129 | 130 | /* autoexec.bat があれば、内容をすべて console に送信 */ 131 | finfo = file_search("autoexec.bat", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); 132 | if (finfo != 0) { 133 | int real_size; 134 | unsigned char *autoexec; 135 | 136 | i = finfo->size; 137 | autoexec = file_loadfile2(finfo->clustno, &i, fat); 138 | real_size = i; 139 | for (i = 0; i < real_size; i++) { 140 | fifo32_put(&sht_cons->task->fifo, autoexec[i] + 256); 141 | } 142 | } 143 | 144 | memman_free_4k(memman, (int) fat, 4 * 2880); 145 | 146 | for (;;) { 147 | if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { 148 | /* キーボードコントローラに送るデータがあれば、送る */ 149 | keycmd_wait = fifo32_get(&keycmd); 150 | wait_KBC_sendready(); 151 | io_out8(PORT_KEYDAT, keycmd_wait); 152 | } 153 | io_cli(); 154 | if (fifo32_status(&fifo) == 0) { 155 | /* FIFOがからっぽになったので、保留している描画があれば実行する */ 156 | if (new_mx >= 0) { 157 | io_sti(); 158 | sheet_slide(sht_mouse, new_mx, new_my); 159 | new_mx = -1; 160 | } else if (new_wx != 0x7fffffff) { 161 | io_sti(); 162 | sheet_slide(sht, new_wx, new_wy); 163 | new_wx = 0x7fffffff; 164 | } else { 165 | task_sleep(task_a); 166 | io_sti(); 167 | } 168 | } else { 169 | i = fifo32_get(&fifo); 170 | io_sti(); 171 | if (key_win != 0 && key_win->flags == 0) { /* ウィンドウが閉じられた */ 172 | if (shtctl->top == 1) { /* もうマウスと背景しかない */ 173 | key_win = 0; 174 | } else { 175 | key_win = shtctl->sheets[shtctl->top - 1]; 176 | keywin_on(key_win); 177 | } 178 | } 179 | if (256 <= i && i <= 511) { /* キーボードデータ */ 180 | if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ 181 | if (key_shift == 0) { 182 | s[0] = keytable0[i - 256]; 183 | } else { 184 | s[0] = keytable1[i - 256]; 185 | } 186 | } else { 187 | s[0] = 0; 188 | } 189 | if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ 190 | if (((key_leds & 4) == 0 && key_shift == 0) || 191 | ((key_leds & 4) != 0 && key_shift != 0)) { 192 | s[0] += 0x20; /* 大文字を小文字に変換 */ 193 | } 194 | } 195 | if (s[0] != 0 && key_win != 0) { /* 通常文字、バックスペース、Enter */ 196 | fifo32_put(&key_win->task->fifo, s[0] + 256); 197 | } 198 | if (i == 256 + 0x0f && key_win != 0) { /* Tab */ 199 | keywin_off(key_win); 200 | j = key_win->height - 1; 201 | if (j == 0) { 202 | j = shtctl->top - 1; 203 | } 204 | key_win = shtctl->sheets[j]; 205 | keywin_on(key_win); 206 | } 207 | if (i == 256 + 0x2a) { /* 左シフト ON */ 208 | key_shift |= 1; 209 | } 210 | if (i == 256 + 0x36) { /* 右シフト ON */ 211 | key_shift |= 2; 212 | } 213 | if (i == 256 + 0xaa) { /* 左シフト OFF */ 214 | key_shift &= ~1; 215 | } 216 | if (i == 256 + 0xb6) { /* 右シフト OFF */ 217 | key_shift &= ~2; 218 | } 219 | if (i == 256 + 0x3a) { /* CapsLock */ 220 | key_leds ^= 4; 221 | fifo32_put(&keycmd, KEYCMD_LED); 222 | fifo32_put(&keycmd, key_leds); 223 | } 224 | if (i == 256 + 0x45) { /* NumLock */ 225 | key_leds ^= 2; 226 | fifo32_put(&keycmd, KEYCMD_LED); 227 | fifo32_put(&keycmd, key_leds); 228 | } 229 | if (i == 256 + 0x46) { /* ScrollLock */ 230 | key_leds ^= 1; 231 | fifo32_put(&keycmd, KEYCMD_LED); 232 | fifo32_put(&keycmd, key_leds); 233 | } 234 | if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */ 235 | task = key_win->task; 236 | if (task != 0 && task->tss.ss0 != 0) { 237 | cons_putstr0(task->cons, "\nBreak(key) :\n"); 238 | io_cli(); /* 強制終了処理中にタスクが変わると困るから */ 239 | task->tss.eax = (int) &(task->tss.esp0); 240 | task->tss.eip = (int) asm_end_app; 241 | io_sti(); 242 | task_run(task, -1, 0); /* 終了処理を確実にやらせるために、寝ていたら起こす */ 243 | } 244 | } 245 | if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */ 246 | /* 新しく作ったコンソールを入力選択状態にする(そのほうが親切だよね?) */ 247 | if (key_win != 0) { 248 | keywin_off(key_win); 249 | } 250 | key_win = open_console(shtctl, memtotal, 80, 24); 251 | sheet_slide(key_win, 32, 4); 252 | sheet_updown(key_win, shtctl->top); 253 | keywin_on(key_win); 254 | } 255 | if (i == 256 + 0x57) { /* F11 */ 256 | sheet_updown(shtctl->sheets[1], shtctl->top - 1); 257 | } 258 | if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ 259 | keycmd_wait = -1; 260 | } 261 | if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ 262 | wait_KBC_sendready(); 263 | io_out8(PORT_KEYDAT, keycmd_wait); 264 | } 265 | } else if (512 <= i && i <= 767) { /* マウスデータ */ 266 | if (mouse_decode(&mdec, i - 512) != 0) { 267 | /* マウスカーソルの移動 */ 268 | mx += mdec.x; 269 | my += mdec.y; 270 | if (mx < 0) { 271 | mx = 0; 272 | } 273 | if (my < 0) { 274 | my = 0; 275 | } 276 | if (mx > binfo->scrnx - 1) { 277 | mx = binfo->scrnx - 1; 278 | } 279 | if (my > binfo->scrny - 1) { 280 | my = binfo->scrny - 1; 281 | } 282 | new_mx = mx; 283 | new_my = my; 284 | if ((mdec.btn & 0x01) != 0) { 285 | /* 左ボタンを押している */ 286 | if (mmx < 0) { 287 | /* 通常モードの場合 */ 288 | /* 上の下じきから順番にマウスが指している下じきを探す */ 289 | for (j = shtctl->top - 1; j > 0; j--) { 290 | sht = shtctl->sheets[j]; 291 | x = mx - sht->vx0; 292 | y = my - sht->vy0; 293 | if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { 294 | if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { 295 | sheet_updown(sht, shtctl->top - 1); 296 | if (sht != key_win) { 297 | keywin_off(key_win); 298 | key_win = sht; 299 | keywin_on(key_win); 300 | } 301 | if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { 302 | mmx = mx; /* ウィンドウ移動モードへ */ 303 | mmy = my; 304 | mmx2 = sht->vx0; 305 | new_wy = sht->vy0; 306 | } 307 | if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { 308 | /* 「×」ボタンクリック */ 309 | if ((sht->flags & 0x10) != 0) { /* アプリが作ったウィンドウか? */ 310 | task = sht->task; 311 | cons_putstr0(task->cons, "\nBreak(mouse) :\n"); 312 | io_cli(); /* 強制終了処理中にタスクが変わると困るから */ 313 | task->tss.eax = (int) &(task->tss.esp0); 314 | task->tss.eip = (int) asm_end_app; 315 | io_sti(); 316 | task_run(task, -1, 0); 317 | } else { /* コンソール */ 318 | task = sht->task; 319 | sheet_updown(sht, -1); /* とりあえず非表示にしておく */ 320 | keywin_off(key_win); 321 | key_win = shtctl->sheets[shtctl->top - 1]; 322 | keywin_on(key_win); 323 | io_cli(); 324 | fifo32_put(&task->fifo, 4); 325 | io_sti(); 326 | } 327 | } 328 | break; 329 | } 330 | } 331 | } 332 | } else { 333 | /* ウィンドウ移動モードの場合 */ 334 | x = mx - mmx; /* マウスの移動量を計算 */ 335 | y = my - mmy; 336 | new_wx = (mmx2 + x + 2) & ~3; 337 | new_wy = new_wy + y; 338 | mmy = my; /* 移動後の座標に更新 */ 339 | } 340 | } else { 341 | /* 左ボタンを押していない */ 342 | mmx = -1; /* 通常モードへ */ 343 | if (new_wx != 0x7fffffff) { 344 | sheet_slide(sht, new_wx, new_wy); /* 一度確定させる */ 345 | new_wx = 0x7fffffff; 346 | } 347 | } 348 | } 349 | } else if (768 <= i && i <= 1023) { /* コンソール終了処理 */ 350 | close_console(shtctl->sheets0 + (i - 768)); 351 | } else if (1024 <= i && i <= 2023) { 352 | close_constask(taskctl->tasks0 + (i - 1024)); 353 | } else if (2024 <= i && i <= 2279) { /* コンソールだけを閉じる */ 354 | sht2 = shtctl->sheets0 + (i - 2024); 355 | memman_free_4k(memman, (int) sht2->buf, 256 * 165); 356 | sheet_free(sht2); 357 | } 358 | } 359 | } 360 | } 361 | 362 | void keywin_off(struct SHEET *key_win) 363 | { 364 | change_wtitle8(key_win, 0); 365 | if ((key_win->flags & 0x20) != 0) { 366 | fifo32_put(&key_win->task->fifo, 3); /* コンソールのカーソルOFF */ 367 | } 368 | return; 369 | } 370 | 371 | void keywin_on(struct SHEET *key_win) 372 | { 373 | change_wtitle8(key_win, 1); 374 | if ((key_win->flags & 0x20) != 0) { 375 | fifo32_put(&key_win->task->fifo, 2); /* コンソールのカーソルON */ 376 | } 377 | return; 378 | } 379 | 380 | struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal, int width, int height) 381 | { 382 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 383 | struct TASK *task = task_alloc(); 384 | int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4); 385 | task->cons_stack = memman_alloc_4k(memman, 64 * 1024); 386 | task->tss.esp = task->cons_stack + 64 * 1024 - 20; 387 | task->tss.eip = (int) &console_task; 388 | task->tss.es = 1 * 8; 389 | task->tss.cs = 2 * 8; 390 | task->tss.ss = 1 * 8; 391 | task->tss.ds = 1 * 8; 392 | task->tss.fs = 1 * 8; 393 | task->tss.gs = 1 * 8; 394 | *((int *) (task->tss.esp + 4)) = (int) sht; 395 | *((int *) (task->tss.esp + 8)) = memtotal; 396 | *((int *) (task->tss.esp + 12)) = width; 397 | *((int *) (task->tss.esp + 16)) = height; 398 | task_run(task, 2, 2); /* level=2, priority=2 */ 399 | fifo32_init(&task->fifo, 128, cons_fifo, task); 400 | return task; 401 | } 402 | 403 | struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal, int width, int height) 404 | { 405 | int win_xsize = 8 * width + 16; 406 | int win_ysize = 16 * height + 37; 407 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 408 | struct SHEET *sht = sheet_alloc(shtctl); 409 | unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, win_xsize * win_ysize); 410 | sheet_setbuf(sht, buf, win_xsize, win_ysize, -1); /* 透明色なし */ 411 | make_window8(buf, win_xsize, win_ysize, "console", 0); 412 | make_textbox8(sht, 8, 28, 8 * width, 16 * height, COL8_000000); 413 | sht->task = open_constask(sht, memtotal, width, height); 414 | sht->flags |= 0x20; /* カーソルあり */ 415 | return sht; 416 | } 417 | 418 | void close_constask(struct TASK *task) 419 | { 420 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 421 | task_sleep(task); 422 | memman_free_4k(memman, task->cons_stack, 64 * 1024); 423 | memman_free_4k(memman, (int) task->fifo.buf, 128 * 4); 424 | task->flags = 0; /* task_free(task); の代わり */ 425 | return; 426 | } 427 | 428 | void close_console(struct SHEET *sht) 429 | { 430 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 431 | struct TASK *task = sht->task; 432 | memman_free_4k(memman, (int) sht->buf, sht->bxsize * sht->bysize); 433 | sheet_free(sht); 434 | close_constask(task); 435 | return; 436 | } 437 | 438 | int hrb_print(const char *s) 439 | { 440 | cons_putstr0(*default_console, s); 441 | } 442 | -------------------------------------------------------------------------------- /haribote/bootpack.h: -------------------------------------------------------------------------------- 1 | /* asmhead.nas */ 2 | struct BOOTINFO { /* 0x0ff0-0x0fff */ 3 | char cyls; /* ブートセクタはどこまでディスクを読んだのか */ 4 | char leds; /* ブート時のキーボードのLEDの状態 */ 5 | char vmode; /* ビデオモード 何ビットカラーか */ 6 | char reserve; 7 | short scrnx, scrny; /* 画面解像度 */ 8 | char *vram; 9 | }; 10 | #define ADR_BOOTINFO 0x00000ff0 11 | #define ADR_DISKIMG 0x00100000 12 | 13 | /* naskfunc.nas */ 14 | void io_hlt(void); 15 | void io_cli(void); 16 | void io_sti(void); 17 | void io_stihlt(void); 18 | int io_in8(int port); 19 | void io_out8(int port, int data); 20 | int io_load_eflags(void); 21 | void io_store_eflags(int eflags); 22 | void load_gdtr(int limit, int addr); 23 | void load_idtr(int limit, int addr); 24 | int load_cr0(void); 25 | void store_cr0(int cr0); 26 | void load_tr(int tr); 27 | void asm_inthandler0c(void); 28 | void asm_inthandler0d(void); 29 | void asm_inthandler20(void); 30 | void asm_inthandler21(void); 31 | void asm_inthandler2c(void); 32 | unsigned int memtest_sub(unsigned int start, unsigned int end); 33 | void farjmp(int eip, int cs); 34 | void farcall(int eip, int cs); 35 | void asm_hrb_api(void); 36 | void start_app(int eip, int cs, int esp, int ds, int *tss_esp0); 37 | void asm_end_app(void); 38 | 39 | /* fifo.c */ 40 | struct FIFO32 { 41 | int *buf; 42 | int p, q, size, free, flags; 43 | struct TASK *task; 44 | }; 45 | void fifo32_init(struct FIFO32 *fifo, int size, int *buf, struct TASK *task); 46 | int fifo32_put(struct FIFO32 *fifo, int data); 47 | int fifo32_get(struct FIFO32 *fifo); 48 | int fifo32_status(struct FIFO32 *fifo); 49 | 50 | /* graphic.c */ 51 | void init_palette(void); 52 | void set_palette(int start, int end, unsigned char *rgb); 53 | void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1); 54 | void init_screen8(char *vram, int x, int y); 55 | void putfont8(char *vram, int xsize, int x, int y, char c, char *font); 56 | void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s); 57 | void init_mouse_cursor8(char *mouse, char bc); 58 | void putblock8_8(char *vram, int vxsize, int pxsize, 59 | int pysize, int px0, int py0, char *buf, int bxsize); 60 | #define COL8_000000 0 61 | #define COL8_FF0000 1 62 | #define COL8_00FF00 2 63 | #define COL8_FFFF00 3 64 | #define COL8_0000FF 4 65 | #define COL8_FF00FF 5 66 | #define COL8_00FFFF 6 67 | #define COL8_FFFFFF 7 68 | #define COL8_C6C6C6 8 69 | #define COL8_840000 9 70 | #define COL8_008400 10 71 | #define COL8_848400 11 72 | #define COL8_000084 12 73 | #define COL8_840084 13 74 | #define COL8_008484 14 75 | #define COL8_848484 15 76 | 77 | /* dsctbl.c */ 78 | struct SEGMENT_DESCRIPTOR { 79 | short limit_low, base_low; 80 | char base_mid, access_right; 81 | char limit_high, base_high; 82 | }; 83 | struct GATE_DESCRIPTOR { 84 | short offset_low, selector; 85 | char dw_count, access_right; 86 | short offset_high; 87 | }; 88 | void init_gdtidt(void); 89 | void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar); 90 | void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar); 91 | #define ADR_IDT 0x0026f800 92 | #define LIMIT_IDT 0x000007ff 93 | #define ADR_GDT 0x00270000 94 | #define LIMIT_GDT 0x0000ffff 95 | #define ADR_BOTPAK 0x00280000 96 | #define LIMIT_BOTPAK (0xffffffff - ADR_BOTPAK) 97 | #define AR_DATA32_RW 0x4092 98 | #define AR_CODE32_ER 0x409a 99 | #define AR_LDT 0x0082 100 | #define AR_TSS32 0x0089 101 | #define AR_INTGATE32 0x008e 102 | 103 | /* int.c */ 104 | void init_pic(void); 105 | #define PIC0_ICW1 0x0020 106 | #define PIC0_OCW2 0x0020 107 | #define PIC0_IMR 0x0021 108 | #define PIC0_ICW2 0x0021 109 | #define PIC0_ICW3 0x0021 110 | #define PIC0_ICW4 0x0021 111 | #define PIC1_ICW1 0x00a0 112 | #define PIC1_OCW2 0x00a0 113 | #define PIC1_IMR 0x00a1 114 | #define PIC1_ICW2 0x00a1 115 | #define PIC1_ICW3 0x00a1 116 | #define PIC1_ICW4 0x00a1 117 | 118 | /* keyboard.c */ 119 | void inthandler21(int *esp); 120 | void wait_KBC_sendready(void); 121 | void init_keyboard(struct FIFO32 *fifo, int data0); 122 | #define PORT_KEYDAT 0x0060 123 | #define PORT_KEYCMD 0x0064 124 | 125 | /* mouse.c */ 126 | struct MOUSE_DEC { 127 | unsigned char buf[3], phase; 128 | int x, y, btn; 129 | }; 130 | void enable_mouse(struct FIFO32 *fifo, int data0, struct MOUSE_DEC *mdec); 131 | int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat); 132 | 133 | /* memory.c */ 134 | #define MEMMAN_FREES 4090 /* これで約32KB */ 135 | #define MEMMAN_ADDR 0x003c0000 136 | struct FREEINFO { /* あき情報 */ 137 | unsigned int addr, size; 138 | }; 139 | struct MEMMAN { /* メモリ管理 */ 140 | int frees, maxfrees, lostsize, losts; 141 | struct FREEINFO free[MEMMAN_FREES]; 142 | }; 143 | unsigned int memtest(unsigned int start, unsigned int end); 144 | void memman_init(struct MEMMAN *man); 145 | unsigned int memman_total(struct MEMMAN *man); 146 | unsigned int memman_alloc(struct MEMMAN *man, unsigned int size); 147 | int memman_free(struct MEMMAN *man, unsigned int addr, unsigned int size); 148 | unsigned int memman_alloc_4k(struct MEMMAN *man, unsigned int size); 149 | int memman_free_4k(struct MEMMAN *man, unsigned int addr, unsigned int size); 150 | 151 | /* sheet.c */ 152 | #define MAX_SHEETS 256 153 | struct SHEET { 154 | unsigned char *buf; 155 | int bxsize, bysize, vx0, vy0, col_inv, height, flags; 156 | struct SHTCTL *ctl; 157 | struct TASK *task; 158 | }; 159 | struct SHTCTL { 160 | unsigned char *vram, *map; 161 | int xsize, ysize, top; 162 | struct SHEET *sheets[MAX_SHEETS]; 163 | struct SHEET sheets0[MAX_SHEETS]; 164 | }; 165 | struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize); 166 | struct SHEET *sheet_alloc(struct SHTCTL *ctl); 167 | void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, int col_inv); 168 | void sheet_updown(struct SHEET *sht, int height); 169 | void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1); 170 | void sheet_slide(struct SHEET *sht, int vx0, int vy0); 171 | void sheet_free(struct SHEET *sht); 172 | 173 | /* timer.c */ 174 | #define MAX_TIMER 500 175 | struct TIMER { 176 | struct TIMER *next; 177 | unsigned int timeout; 178 | char flags, flags2; 179 | struct FIFO32 *fifo; 180 | int data; 181 | }; 182 | struct TIMERCTL { 183 | unsigned int count, next; 184 | struct TIMER *t0; 185 | struct TIMER timers0[MAX_TIMER]; 186 | }; 187 | extern struct TIMERCTL timerctl; 188 | void init_pit(void); 189 | struct TIMER *timer_alloc(void); 190 | void timer_free(struct TIMER *timer); 191 | void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data); 192 | void timer_settime(struct TIMER *timer, unsigned int timeout); 193 | void inthandler20(int *esp); 194 | int timer_cancel(struct TIMER *timer); 195 | void timer_cancelall(struct FIFO32 *fifo); 196 | 197 | /* mtask.c */ 198 | #define MAX_TASKS 1000 /* 最大タスク数 */ 199 | #define TASK_GDT0 3 /* TSSをGDTの何番から割り当てるのか */ 200 | #define MAX_TASKS_LV 100 201 | #define MAX_TASKLEVELS 10 202 | struct TSS32 { 203 | int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3; 204 | int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi; 205 | int es, cs, ss, ds, fs, gs; 206 | int ldtr, iomap; 207 | }; 208 | struct TASK { 209 | int sel, flags; /* selはGDTの番号のこと */ 210 | int level, priority; 211 | struct FIFO32 fifo; 212 | struct TSS32 tss; 213 | struct SEGMENT_DESCRIPTOR ldt[2]; 214 | struct CONSOLE *cons; 215 | int cs_base, ds_base, cons_stack; 216 | struct FILEHANDLE *fhandle; 217 | int *fat; 218 | char *cmdline; 219 | unsigned char langmode, langbyte1; 220 | }; 221 | struct TASKLEVEL { 222 | int running; /* 動作しているタスクの数 */ 223 | int now; /* 現在動作しているタスクがどれだか分かるようにするための変数 */ 224 | struct TASK *tasks[MAX_TASKS_LV]; 225 | }; 226 | struct TASKCTL { 227 | int now_lv; /* 現在動作中のレベル */ 228 | char lv_change; /* 次回タスクスイッチのときに、レベルも変えたほうがいいかどうか */ 229 | struct TASKLEVEL level[MAX_TASKLEVELS]; 230 | struct TASK tasks0[MAX_TASKS]; 231 | }; 232 | extern struct TASKCTL *taskctl; 233 | extern struct TIMER *task_timer; 234 | struct TASK *task_now(void); 235 | struct TASK *task_init(struct MEMMAN *memman); 236 | struct TASK *task_alloc(void); 237 | void task_run(struct TASK *task, int level, int priority); 238 | void task_switch(void); 239 | void task_sleep(struct TASK *task); 240 | 241 | /* window.c */ 242 | void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act); 243 | void putfouts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l); 244 | void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); 245 | void make_wtitle8(unsigned char *buf, int xsize, char *title, char act); 246 | void change_wtitle8(struct SHEET *sht, char act); 247 | 248 | /* console.c */ 249 | struct CONSOLE { 250 | struct SHEET *sht; 251 | int width, height; // the number of characters 252 | int cur_x, cur_y, cur_c; 253 | struct TIMER *timer; 254 | }; 255 | struct FILEHANDLE { 256 | char *buf; 257 | int size; 258 | int pos; 259 | }; 260 | void console_task(struct SHEET *sheet, int memtotal, int width, int height); 261 | void cons_putchar(struct CONSOLE *cons, int chr, char move); 262 | void cons_newline(struct CONSOLE *cons); 263 | void cons_putstr0(struct CONSOLE *cons, char *s); 264 | void cons_putstr1(struct CONSOLE *cons, char *s, int l); 265 | void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal); 266 | void cmd_mem(struct CONSOLE *cons, int memtotal); 267 | void cmd_cls(struct CONSOLE *cons); 268 | void cmd_dir(struct CONSOLE *cons); 269 | void cmd_exit(struct CONSOLE *cons, int *fat); 270 | void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal); 271 | void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal); 272 | void cmd_langmode(struct CONSOLE *cons, char *cmdline); 273 | void cmd_insmod(struct CONSOLE *cons, int *fat, char *cmdline); 274 | int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline); 275 | int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax); 276 | int *inthandler0d(int *esp); 277 | int *inthandler0c(int *esp); 278 | void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1, int col); 279 | 280 | /* file.c */ 281 | struct FILEINFO { 282 | unsigned char name[8], ext[3], type; 283 | char reserve[10]; 284 | unsigned short time, date, clustno; 285 | unsigned int size; 286 | }; 287 | void file_readfat(int *fat, unsigned char *img); 288 | void file_loadfile(int clustno, int size, char *buf, int *fat, char *img); 289 | struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max); 290 | char *file_loadfile2(int clustno, int *psize, int *fat); 291 | 292 | /* tek.c */ 293 | int tek_getsize(unsigned char *p); 294 | int tek_decomp(unsigned char *p, char *q, int size); 295 | 296 | /* bootpack.c */ 297 | struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal, int width, int height); 298 | struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal, int width, int height); 299 | extern struct CONSOLE **default_console; 300 | int hrb_print(const char *s); 301 | -------------------------------------------------------------------------------- /haribote/dsctbl.c: -------------------------------------------------------------------------------- 1 | /* GDTやIDTなどの、 descriptor table 関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | void init_gdtidt(void) 6 | { 7 | struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; 8 | struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) ADR_IDT; 9 | int i; 10 | 11 | /* GDTの初期化 */ 12 | for (i = 0; i <= LIMIT_GDT / 8; i++) { 13 | set_segmdesc(gdt + i, 0, 0, 0); 14 | } 15 | set_segmdesc(gdt + 1, 0xffffffff, 0x00000000, AR_DATA32_RW); 16 | set_segmdesc(gdt + 2, LIMIT_BOTPAK, ADR_BOTPAK, AR_CODE32_ER); 17 | load_gdtr(LIMIT_GDT, ADR_GDT); 18 | 19 | /* IDTの初期化 */ 20 | for (i = 0; i <= LIMIT_IDT / 8; i++) { 21 | set_gatedesc(idt + i, 0, 0, 0); 22 | } 23 | load_idtr(LIMIT_IDT, ADR_IDT); 24 | 25 | /* IDTの設定 */ 26 | set_gatedesc(idt + 0x0c, (int) asm_inthandler0c, 2 * 8, AR_INTGATE32); 27 | set_gatedesc(idt + 0x0d, (int) asm_inthandler0d, 2 * 8, AR_INTGATE32); 28 | set_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32); 29 | set_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32); 30 | set_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32); 31 | set_gatedesc(idt + 0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32 + 0x60); 32 | 33 | return; 34 | } 35 | 36 | void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar) 37 | { 38 | if (limit > 0xfffff) { 39 | ar |= 0x8000; /* G_bit = 1 */ 40 | limit /= 0x1000; 41 | } 42 | sd->limit_low = limit & 0xffff; 43 | sd->base_low = base & 0xffff; 44 | sd->base_mid = (base >> 16) & 0xff; 45 | sd->access_right = ar & 0xff; 46 | sd->limit_high = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0); 47 | sd->base_high = (base >> 24) & 0xff; 48 | return; 49 | } 50 | 51 | void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar) 52 | { 53 | gd->offset_low = offset & 0xffff; 54 | gd->selector = selector; 55 | gd->dw_count = (ar >> 8) & 0xff; 56 | gd->access_right = ar & 0xff; 57 | gd->offset_high = (offset >> 16) & 0xffff; 58 | return; 59 | } 60 | -------------------------------------------------------------------------------- /haribote/elf.c: -------------------------------------------------------------------------------- 1 | #include "elf.h" 2 | #include 3 | 4 | Elf32_Shdr* elf32_find_section(Elf32_Ehdr* ehdr, const char* secname) 5 | { 6 | Elf32_Shdr* shdr = ELF_GET_SHDR(ehdr); 7 | const char* strtab = ELF_GET_SHSTRTAB(ehdr); 8 | int i; 9 | for (i = 0; i < ehdr->e_shnum; i++) { 10 | if (strcmp(secname, strtab + shdr[i].sh_name) == 0) { 11 | return &shdr[i]; 12 | } 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /haribote/elf.h: -------------------------------------------------------------------------------- 1 | // 2016 uchan 2 | 3 | #define EI_NIDENT 16 4 | 5 | typedef unsigned short int Elf32_Half; 6 | typedef unsigned int Elf32_Word; 7 | typedef signed int Elf32_Sword; 8 | typedef unsigned int Elf32_Addr; 9 | typedef unsigned int Elf32_Off; 10 | typedef unsigned int Elf32_Size; 11 | 12 | typedef struct { 13 | unsigned char e_ident[EI_NIDENT]; 14 | Elf32_Half e_type; 15 | Elf32_Half e_machine; 16 | Elf32_Word e_version; 17 | Elf32_Addr e_entry; 18 | Elf32_Off e_phoff; 19 | Elf32_Off e_shoff; 20 | Elf32_Word e_flags; 21 | Elf32_Half e_ehsize; 22 | Elf32_Half e_phentsize; 23 | Elf32_Half e_phnum; 24 | Elf32_Half e_shentsize; 25 | Elf32_Half e_shnum; 26 | Elf32_Half e_shstrndx; 27 | } Elf32_Ehdr; 28 | 29 | #define IS_ELF(ehdr) \ 30 | ((ehdr).e_ident[0] == 0x7f && \ 31 | (ehdr).e_ident[1] == 'E' && \ 32 | (ehdr).e_ident[2] == 'L' && \ 33 | (ehdr).e_ident[3] == 'F') 34 | 35 | typedef struct { 36 | Elf32_Word sh_name; 37 | Elf32_Word sh_type; 38 | Elf32_Word sh_flags; 39 | Elf32_Addr sh_addr; 40 | Elf32_Off sh_offset; 41 | Elf32_Size sh_size; 42 | Elf32_Word sh_link; 43 | Elf32_Word sh_info; 44 | Elf32_Size sh_addralign; 45 | Elf32_Size sh_entsize; 46 | } Elf32_Shdr; 47 | 48 | #define SHN_UNDEF 0 49 | 50 | typedef struct { 51 | Elf32_Word p_type; 52 | Elf32_Off p_offset; 53 | Elf32_Addr p_vaddr; 54 | Elf32_Addr p_paddr; 55 | Elf32_Size p_filesz; 56 | Elf32_Size p_memsz; 57 | Elf32_Word p_flags; 58 | Elf32_Size p_align; 59 | } Elf32_Phdr; 60 | 61 | #define PF_X 1 62 | #define PF_W 2 63 | #define PF_R 4 64 | 65 | typedef struct { 66 | Elf32_Word st_name; 67 | Elf32_Addr st_value; 68 | Elf32_Size st_size; 69 | unsigned char st_info; 70 | unsigned char st_other; 71 | Elf32_Half st_shndx; 72 | } Elf32_Sym; 73 | 74 | typedef struct { 75 | Elf32_Addr r_offset; 76 | Elf32_Word r_info; 77 | } Elf32_Rel; 78 | 79 | typedef struct { 80 | Elf32_Addr r_offset; 81 | Elf32_Word r_info; 82 | Elf32_Sword r_addend; 83 | } Elf32_Rela; 84 | 85 | #define ELF_R_SYM(r_info) (((r_info) & 0xffffff00u) >> 8u) 86 | #define ELF_R_TYPE(r_info) ((r_info) & 0x000000ffu) 87 | 88 | #define R_386_NONE 0 89 | #define R_386_32 1 90 | #define R_386_PC32 2 91 | 92 | // Utilities 93 | 94 | #define ELF_GET_SHDR(ehdr) ((Elf32_Shdr*)((char*)(ehdr) + (ehdr)->e_shoff)) 95 | #define ELF_GET_PHDR(ehdr) ((Elf32_Phdr*)((char*)(ehdr) + (ehdr)->e_phoff)) 96 | #define ELF_GET_SHSTRTAB(ehdr) ((char*)(ehdr) + ELF_GET_SHDR(ehdr)[(ehdr)->e_shstrndx].sh_offset) 97 | Elf32_Shdr* elf32_find_section(Elf32_Ehdr* ehdr, const char* secname); 98 | -------------------------------------------------------------------------------- /haribote/fifo.c: -------------------------------------------------------------------------------- 1 | /* FIFOライブラリ */ 2 | 3 | #include "bootpack.h" 4 | 5 | #define FLAGS_OVERRUN 0x0001 6 | 7 | void fifo32_init(struct FIFO32 *fifo, int size, int *buf, struct TASK *task) 8 | /* FIFOバッファの初期化 */ 9 | { 10 | fifo->size = size; 11 | fifo->buf = buf; 12 | fifo->free = size; /* 空き */ 13 | fifo->flags = 0; 14 | fifo->p = 0; /* 書き込み位置 */ 15 | fifo->q = 0; /* 読み込み位置 */ 16 | fifo->task = task; /* データが入ったときに起こすタスク */ 17 | return; 18 | } 19 | 20 | int fifo32_put(struct FIFO32 *fifo, int data) 21 | /* FIFOへデータを送り込んで蓄える */ 22 | { 23 | if (fifo->free == 0) { 24 | /* 空きがなくてあふれた */ 25 | fifo->flags |= FLAGS_OVERRUN; 26 | return -1; 27 | } 28 | fifo->buf[fifo->p] = data; 29 | fifo->p++; 30 | if (fifo->p == fifo->size) { 31 | fifo->p = 0; 32 | } 33 | fifo->free--; 34 | if (fifo->task != 0) { 35 | if (fifo->task->flags != 2) { /* タスクが寝ていたら */ 36 | task_run(fifo->task, -1, 0); /* 起こしてあげる */ 37 | } 38 | } 39 | return 0; 40 | } 41 | 42 | int fifo32_get(struct FIFO32 *fifo) 43 | /* FIFOからデータを一つとってくる */ 44 | { 45 | int data; 46 | if (fifo->free == fifo->size) { 47 | /* バッファが空っぽのときは、とりあえず-1が返される */ 48 | return -1; 49 | } 50 | data = fifo->buf[fifo->q]; 51 | fifo->q++; 52 | if (fifo->q == fifo->size) { 53 | fifo->q = 0; 54 | } 55 | fifo->free++; 56 | return data; 57 | } 58 | 59 | int fifo32_status(struct FIFO32 *fifo) 60 | /* どのくらいデータが溜まっているかを報告する */ 61 | { 62 | return fifo->size - fifo->free; 63 | } 64 | -------------------------------------------------------------------------------- /haribote/file.c: -------------------------------------------------------------------------------- 1 | /* ファイル関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | void file_readfat(int *fat, unsigned char *img) 6 | /* ディスクイメージ内のFATの圧縮をとく */ 7 | { 8 | int i, j = 0; 9 | for (i = 0; i < 2880; i += 2) { 10 | fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; 11 | fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; 12 | j += 3; 13 | } 14 | return; 15 | } 16 | 17 | void file_loadfile(int clustno, int size, char *buf, int *fat, char *img) 18 | { 19 | int i; 20 | for (;;) { 21 | if (size <= 512) { 22 | for (i = 0; i < size; i++) { 23 | buf[i] = img[clustno * 512 + i]; 24 | } 25 | break; 26 | } 27 | for (i = 0; i < 512; i++) { 28 | buf[i] = img[clustno * 512 + i]; 29 | } 30 | size -= 512; 31 | buf += 512; 32 | clustno = fat[clustno]; 33 | } 34 | return; 35 | } 36 | 37 | struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max) 38 | { 39 | int i, j; 40 | char s[12]; 41 | for (j = 0; j < 11; j++) { 42 | s[j] = ' '; 43 | } 44 | j = 0; 45 | for (i = 0; j < 11 && name[i] != 0; i++) { 46 | if (name[i] == '.') { 47 | j = 8; 48 | } else { 49 | s[j] = name[i]; 50 | if ('a' <= s[j] && s[j] <= 'z') { 51 | /* 小文字は大文字に直す */ 52 | s[j] -= 0x20; 53 | } 54 | j++; 55 | } 56 | } 57 | for (i = 0; i < max; ) { 58 | if (finfo->name[0] == 0x00) { 59 | break; 60 | } 61 | if ((finfo[i].type & 0x18) == 0) { 62 | for (j = 0; j < 11; j++) { 63 | if (finfo[i].name[j] != s[j]) { 64 | goto next; 65 | } 66 | } 67 | return finfo + i; /* ファイルが見つかった */ 68 | } 69 | next: 70 | i++; 71 | } 72 | return 0; /* 見つからなかった */ 73 | } 74 | 75 | char *file_loadfile2(int clustno, int *psize, int *fat) 76 | { 77 | int size = *psize, size2; 78 | struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; 79 | char *buf, *buf2; 80 | buf = (char *) memman_alloc_4k(memman, size); 81 | file_loadfile(clustno, size, buf, fat, (char *) (ADR_DISKIMG + 0x003e00)); 82 | if (size >= 17) { 83 | size2 = tek_getsize(buf); 84 | if (size2 > 0) { /* tek圧縮がかかっていた */ 85 | buf2 = (char *) memman_alloc_4k(memman, size2); 86 | tek_decomp(buf, buf2, size2); 87 | memman_free_4k(memman, (int) buf, size); 88 | buf = buf2; 89 | *psize = size2; 90 | } 91 | } 92 | return buf; 93 | } 94 | -------------------------------------------------------------------------------- /haribote/graphic.c: -------------------------------------------------------------------------------- 1 | /* グラフィック処理関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | void init_palette(void) 6 | { 7 | static unsigned char table_rgb[16 * 3] = { 8 | 0x00, 0x00, 0x00, /* 0:黒 */ 9 | 0xff, 0x00, 0x00, /* 1:明るい赤 */ 10 | 0x00, 0xff, 0x00, /* 2:明るい緑 */ 11 | 0xff, 0xff, 0x00, /* 3:明るい黄色 */ 12 | 0x00, 0x00, 0xff, /* 4:明るい青 */ 13 | 0xff, 0x00, 0xff, /* 5:明るい紫 */ 14 | 0x00, 0xff, 0xff, /* 6:明るい水色 */ 15 | 0xff, 0xff, 0xff, /* 7:白 */ 16 | 0xc6, 0xc6, 0xc6, /* 8:明るい灰色 */ 17 | 0x84, 0x00, 0x00, /* 9:暗い赤 */ 18 | 0x00, 0x84, 0x00, /* 10:暗い緑 */ 19 | 0x84, 0x84, 0x00, /* 11:暗い黄色 */ 20 | 0x00, 0x00, 0x84, /* 12:暗い青 */ 21 | 0x84, 0x00, 0x84, /* 13:暗い紫 */ 22 | 0x00, 0x84, 0x84, /* 14:暗い水色 */ 23 | 0x84, 0x84, 0x84 /* 15:暗い灰色 */ 24 | }; 25 | unsigned char table2[216 * 3]; 26 | int r, g, b; 27 | set_palette(0, 15, table_rgb); 28 | for (b = 0; b < 6; b++) { 29 | for (g = 0; g < 6; g++) { 30 | for (r = 0; r < 6; r++) { 31 | table2[(r + g * 6 + b * 36) * 3 + 0] = r * 51; 32 | table2[(r + g * 6 + b * 36) * 3 + 1] = g * 51; 33 | table2[(r + g * 6 + b * 36) * 3 + 2] = b * 51; 34 | } 35 | } 36 | } 37 | set_palette(16, 231, table2); 38 | return; 39 | } 40 | 41 | void set_palette(int start, int end, unsigned char *rgb) 42 | { 43 | int i, eflags; 44 | eflags = io_load_eflags(); /* 割り込み許可フラグの値を記録する */ 45 | io_cli(); /* 許可フラグを0にして割り込み禁止にする */ 46 | io_out8(0x03c8, start); 47 | for (i = start; i <= end; i++) { 48 | io_out8(0x03c9, rgb[0] / 4); 49 | io_out8(0x03c9, rgb[1] / 4); 50 | io_out8(0x03c9, rgb[2] / 4); 51 | rgb += 3; 52 | } 53 | io_store_eflags(eflags); /* 割り込み許可フラグを元に戻す */ 54 | return; 55 | } 56 | 57 | void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1) 58 | { 59 | int x, y; 60 | for (y = y0; y <= y1; y++) { 61 | for (x = x0; x <= x1; x++) 62 | vram[y * xsize + x] = c; 63 | } 64 | return; 65 | } 66 | 67 | void init_screen8(char *vram, int x, int y) 68 | { 69 | boxfill8(vram, x, COL8_008484, 0, 0, x - 1, y - 29); 70 | boxfill8(vram, x, COL8_C6C6C6, 0, y - 28, x - 1, y - 28); 71 | boxfill8(vram, x, COL8_FFFFFF, 0, y - 27, x - 1, y - 27); 72 | boxfill8(vram, x, COL8_C6C6C6, 0, y - 26, x - 1, y - 1); 73 | 74 | boxfill8(vram, x, COL8_FFFFFF, 3, y - 24, 59, y - 24); 75 | boxfill8(vram, x, COL8_FFFFFF, 2, y - 24, 2, y - 4); 76 | boxfill8(vram, x, COL8_848484, 3, y - 4, 59, y - 4); 77 | boxfill8(vram, x, COL8_848484, 59, y - 23, 59, y - 5); 78 | boxfill8(vram, x, COL8_000000, 2, y - 3, 59, y - 3); 79 | boxfill8(vram, x, COL8_000000, 60, y - 24, 60, y - 3); 80 | 81 | boxfill8(vram, x, COL8_848484, x - 47, y - 24, x - 4, y - 24); 82 | boxfill8(vram, x, COL8_848484, x - 47, y - 23, x - 47, y - 4); 83 | boxfill8(vram, x, COL8_FFFFFF, x - 47, y - 3, x - 4, y - 3); 84 | boxfill8(vram, x, COL8_FFFFFF, x - 3, y - 24, x - 3, y - 3); 85 | return; 86 | } 87 | 88 | void putfont8(char *vram, int xsize, int x, int y, char c, char *font) 89 | { 90 | int i; 91 | char *p, d /* data */; 92 | for (i = 0; i < 16; i++) { 93 | p = vram + (y + i) * xsize + x; 94 | d = font[i]; 95 | if ((d & 0x80) != 0) { p[0] = c; } 96 | if ((d & 0x40) != 0) { p[1] = c; } 97 | if ((d & 0x20) != 0) { p[2] = c; } 98 | if ((d & 0x10) != 0) { p[3] = c; } 99 | if ((d & 0x08) != 0) { p[4] = c; } 100 | if ((d & 0x04) != 0) { p[5] = c; } 101 | if ((d & 0x02) != 0) { p[6] = c; } 102 | if ((d & 0x01) != 0) { p[7] = c; } 103 | } 104 | return; 105 | } 106 | 107 | void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s) 108 | { 109 | extern char hankaku[4096]; 110 | struct TASK *task = task_now(); 111 | char *nihongo = (char *) *((int *) 0x0fe8), *font; 112 | int k, t; 113 | 114 | if (task->langmode == 0) { 115 | for (; *s != 0x00; s++) { 116 | putfont8(vram, xsize, x, y, c, hankaku + *s * 16); 117 | x += 8; 118 | } 119 | } 120 | if (task->langmode == 1) { 121 | for (; *s != 0x00; s++) { 122 | if (task->langbyte1 == 0) { 123 | if ((0x81 <= *s && *s <= 0x9f) || (0xe0 <= *s && *s <= 0xfc)) { 124 | task->langbyte1 = *s; 125 | } else { 126 | putfont8(vram, xsize, x, y, c, nihongo + *s * 16); 127 | } 128 | } else { 129 | if (0x81 <= task->langbyte1 && task->langbyte1 <= 0x9f) { 130 | k = (task->langbyte1 - 0x81) * 2; 131 | } else { 132 | k = (task->langbyte1 - 0xe0) * 2 + 62; 133 | } 134 | if (0x40 <= *s && *s <= 0x7e) { 135 | t = *s - 0x40; 136 | } else if (0x80 <= *s && *s <= 0x9e) { 137 | t = *s - 0x80 + 63; 138 | } else { 139 | t = *s - 0x9f; 140 | k++; 141 | } 142 | task->langbyte1 = 0; 143 | font = nihongo + 256 * 16 + (k * 94 + t) * 32; 144 | putfont8(vram, xsize, x - 8, y, c, font ); /* 左半分 */ 145 | putfont8(vram, xsize, x , y, c, font + 16); /* 右半分 */ 146 | } 147 | x += 8; 148 | } 149 | } 150 | if (task->langmode == 2) { 151 | for (; *s != 0x00; s++) { 152 | if (task->langbyte1 == 0) { 153 | if (0x81 <= *s && *s <= 0xfe) { 154 | task->langbyte1 = *s; 155 | } else { 156 | putfont8(vram, xsize, x, y, c, nihongo + *s * 16); 157 | } 158 | } else { 159 | k = task->langbyte1 - 0xa1; 160 | t = *s - 0xa1; 161 | task->langbyte1 = 0; 162 | font = nihongo + 256 * 16 + (k * 94 + t) * 32; 163 | putfont8(vram, xsize, x - 8, y, c, font ); /* 左半分 */ 164 | putfont8(vram, xsize, x , y, c, font + 16); /* 右半分 */ 165 | } 166 | x += 8; 167 | } 168 | } 169 | return; 170 | } 171 | 172 | void init_mouse_cursor8(char *mouse, char bc) 173 | /* マウスカーソルを準備(16x16) */ 174 | { 175 | static char cursor[16][16] = { 176 | "**************..", 177 | "*OOOOOOOOOOO*...", 178 | "*OOOOOOOOOO*....", 179 | "*OOOOOOOOO*.....", 180 | "*OOOOOOOO*......", 181 | "*OOOOOOO*.......", 182 | "*OOOOOOO*.......", 183 | "*OOOOOOOO*......", 184 | "*OOOO**OOO*.....", 185 | "*OOO*..*OOO*....", 186 | "*OO*....*OOO*...", 187 | "*O*......*OOO*..", 188 | "**........*OOO*.", 189 | "*..........*OOO*", 190 | "............*OO*", 191 | ".............***" 192 | }; 193 | int x, y; 194 | 195 | for (y = 0; y < 16; y++) { 196 | for (x = 0; x < 16; x++) { 197 | if (cursor[y][x] == '*') { 198 | mouse[y * 16 + x] = COL8_000000; 199 | } 200 | if (cursor[y][x] == 'O') { 201 | mouse[y * 16 + x] = COL8_FFFFFF; 202 | } 203 | if (cursor[y][x] == '.') { 204 | mouse[y * 16 + x] = bc; 205 | } 206 | } 207 | } 208 | return; 209 | } 210 | 211 | void putblock8_8(char *vram, int vxsize, int pxsize, 212 | int pysize, int px0, int py0, char *buf, int bxsize) 213 | { 214 | int x, y; 215 | for (y = 0; y < pysize; y++) { 216 | for (x = 0; x < pxsize; x++) { 217 | vram[(py0 + y) * vxsize + (px0 + x)] = buf[y * bxsize + x]; 218 | } 219 | } 220 | return; 221 | } 222 | -------------------------------------------------------------------------------- /haribote/hello.c: -------------------------------------------------------------------------------- 1 | #include "module.h" 2 | #include "bootpack.h" 3 | 4 | static int init_hello(void) 5 | { 6 | hrb_print("init_hello is called.\n"); 7 | return 0; 8 | } 9 | 10 | static void exit_hello(void) 11 | { 12 | hrb_print("exit_hello is called. bye...\n"); 13 | } 14 | 15 | struct module this_module 16 | __attribute__((section(".this_module"))) = { 17 | .init = init_hello, 18 | .exit = exit_hello 19 | }; 20 | -------------------------------------------------------------------------------- /haribote/int.c: -------------------------------------------------------------------------------- 1 | /* 割り込み関係 */ 2 | 3 | #include "bootpack.h" 4 | #include 5 | 6 | void init_pic(void) 7 | /* PICの初期化 */ 8 | { 9 | io_out8(PIC0_IMR, 0xff ); /* 全ての割り込みを受け付けない */ 10 | io_out8(PIC1_IMR, 0xff ); /* 全ての割り込みを受け付けない */ 11 | 12 | io_out8(PIC0_ICW1, 0x11 ); /* エッジトリガモード */ 13 | io_out8(PIC0_ICW2, 0x20 ); /* IRQ0-7は、INT20-27で受ける */ 14 | io_out8(PIC0_ICW3, 1 << 2); /* PIC1はIRQ2にて接続 */ 15 | io_out8(PIC0_ICW4, 0x01 ); /* ノンバッファモード */ 16 | 17 | io_out8(PIC1_ICW1, 0x11 ); /* エッジトリガモード */ 18 | io_out8(PIC1_ICW2, 0x28 ); /* IRQ8-15は、INT28-2fで受ける */ 19 | io_out8(PIC1_ICW3, 2 ); /* PIC1はIRQ2にて接続 */ 20 | io_out8(PIC1_ICW4, 0x01 ); /* ノンバッファモード */ 21 | 22 | io_out8(PIC0_IMR, 0xfb ); /* 11111011 PIC1以外は全て禁止 */ 23 | io_out8(PIC1_IMR, 0xff ); /* 11111111 全ての割り込みを受け付けない */ 24 | 25 | return; 26 | } 27 | -------------------------------------------------------------------------------- /haribote/ipl11.nas: -------------------------------------------------------------------------------- 1 | ; haribote-ipl 2 | ; TAB=4 3 | 4 | CYLS EQU 12 ; どこまで読み込むか 5 | 6 | ORG 0x7c00 ; このプログラムがどこに読み込まれるのか 7 | 8 | ; 以下は標準的なFAT12フォーマットフロッピーディスクのための記述 9 | 10 | JMP entry 11 | DB 0x90 12 | DB "HARIBOTE" ; ブートセクタの名前を自由に書いてよい(8バイト) 13 | DW 512 ; 1セクタの大きさ(512にしなければいけない) 14 | DB 1 ; クラスタの大きさ(1セクタにしなければいけない) 15 | DW 1 ; FATがどこから始まるか(普通は1セクタ目からにする) 16 | DB 2 ; FATの個数(2にしなければいけない) 17 | DW 224 ; ルートディレクトリ領域の大きさ(普通は224エントリにする) 18 | DW 2880 ; このドライブの大きさ(2880セクタにしなければいけない) 19 | DB 0xf0 ; メディアのタイプ(0xf0にしなければいけない) 20 | DW 9 ; FAT領域の長さ(9セクタにしなければいけない) 21 | DW 18 ; 1トラックにいくつのセクタがあるか(18にしなければいけない) 22 | DW 2 ; ヘッドの数(2にしなければいけない) 23 | DD 0 ; パーティションを使ってないのでここは必ず0 24 | DD 2880 ; このドライブ大きさをもう一度書く 25 | DB 0,0,0x29 ; よくわからないけどこの値にしておくといいらしい 26 | DD 0xffffffff ; たぶんボリュームシリアル番号 27 | DB "HARIBOTEOS " ; ディスクの名前(11バイト) 28 | DB "FAT12 " ; フォーマットの名前(8バイト) 29 | RESB 18 ; とりあえず18バイトあけておく 30 | 31 | ; プログラム本体 32 | 33 | entry: 34 | MOV AX,0 ; レジスタ初期化 35 | MOV SS,AX 36 | MOV SP,0x7c00 37 | MOV DS,AX 38 | 39 | ; ディスクを読む 40 | 41 | MOV AX,0x0820 42 | MOV ES,AX 43 | MOV CH,0 ; シリンダ0 44 | MOV DH,0 ; ヘッド0 45 | MOV CL,2 ; セクタ2 46 | MOV BX,18*2*CYLS-1 ; 読み込みたい合計セクタ数 47 | CALL readfast ; 高速読み込み 48 | 49 | ; 読み終わったのでharibote.sysを実行だ! 50 | 51 | MOV BYTE [0x0ff0],CYLS ; IPLがどこまで読んだのかをメモ 52 | JMP 0xc200 53 | 54 | error: 55 | MOV AX,0 56 | MOV ES,AX 57 | MOV SI,msg 58 | putloop: 59 | MOV AL,[SI] 60 | ADD SI,1 ; SIに1を足す 61 | CMP AL,0 62 | JE fin 63 | MOV AH,0x0e ; 一文字表示ファンクション 64 | MOV BX,15 ; カラーコード 65 | INT 0x10 ; ビデオBIOS呼び出し 66 | JMP putloop 67 | fin: 68 | HLT ; 何かあるまでCPUを停止させる 69 | JMP fin ; 無限ループ 70 | msg: 71 | DB 0x0a, 0x0a ; 改行を2つ 72 | DB "load error" 73 | DB 0x0a ; 改行 74 | DB 0 75 | 76 | readfast: ; ALを使ってできるだけまとめて読み出す 77 | ; ES:読み込み番地, CH:シリンダ, DH:ヘッド, CL:セクタ, BX:読み込みセクタ数 78 | 79 | MOV AX,ES ; < ESからALの最大値を計算 > 80 | SHL AX,3 ; AXを32で割って、その結果をAHに入れたことになる 81 | AND AH,0x7f ; AHはAHを128で割った余り(512*128=64K) 82 | MOV AL,128 ; AL = 128 - AH; 一番近い64KB境界まで最大何セクタ入るか 83 | SUB AL,AH 84 | 85 | MOV AH,BL ; < BXからALの最大値をAHに計算 > 86 | CMP BH,0 ; if (BH != 0) { AH = 18; } 87 | JE .skip1 88 | MOV AH,18 89 | .skip1: 90 | CMP AL,AH ; if (AL > AH) { AL = AH; } 91 | JBE .skip2 92 | MOV AL,AH 93 | .skip2: 94 | 95 | MOV AH,19 ; < CLからALの最大値をAHに計算 > 96 | SUB AH,CL ; AH = 19 - CL; 97 | CMP AL,AH ; if (AL > AH) { AL = AH; } 98 | JBE .skip3 99 | MOV AL,AH 100 | .skip3: 101 | 102 | PUSH BX 103 | MOV SI,0 ; 失敗回数を数えるレジスタ 104 | retry: 105 | MOV AH,0x02 ; AH=0x02 : ディスク読み込み 106 | MOV BX,0 107 | MOV DL,0x00 ; Aドライブ 108 | PUSH ES 109 | PUSH DX 110 | PUSH CX 111 | PUSH AX 112 | INT 0x13 ; ディスクBIOS呼び出し 113 | JNC next ; エラーがおきなればnextへ 114 | ADD SI,1 ; SIに1を足す 115 | CMP SI,5 ; SIと5を比較 116 | JAE error ; SI >= 5 だったらerrorへ 117 | MOV AH,0x00 118 | MOV DL,0x00 ; Aドライブ 119 | INT 0x13 ; ドライブのリセット 120 | POP AX 121 | POP CX 122 | POP DX 123 | POP ES 124 | JMP retry 125 | next: 126 | POP AX 127 | POP CX 128 | POP DX 129 | POP BX ; ESの内容をBXで受け取る 130 | SHR BX,5 ; BXを16バイト単位から512バイト単位へ 131 | MOV AH,0 132 | ADD BX,AX ; BX += AL; 133 | SHL BX,5 ; BXを512バイト単位から16バイト単位へ 134 | MOV ES,BX ; これで ES += AL * 0x20; になる 135 | POP BX 136 | SUB BX,AX 137 | JZ .ret 138 | ADD CL,AL ; CLにALを足す 139 | CMP CL,18 ; CLと18を比較 140 | JBE readfast ; CL <= 18 だったらreadfastへ 141 | MOV CL,1 142 | ADD DH,1 143 | CMP DH,2 144 | JB readfast ; DH < 2 だったらreadfastへ 145 | MOV DH,0 146 | ADD CH,1 147 | JMP readfast 148 | .ret: 149 | RET 150 | 151 | RESB 0x7dfe-$ ; 0x7dfeまでを0x00で埋める命令 152 | 153 | DB 0x55, 0xaa 154 | -------------------------------------------------------------------------------- /haribote/keyboard.c: -------------------------------------------------------------------------------- 1 | /* キーボード関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | struct FIFO32 *keyfifo; 6 | int keydata0; 7 | 8 | void inthandler21(int *esp) 9 | { 10 | int data; 11 | io_out8(PIC0_OCW2, 0x61); /* IRQ-01受付完了をPICに通知 */ 12 | data = io_in8(PORT_KEYDAT); 13 | fifo32_put(keyfifo, data + keydata0); 14 | return; 15 | } 16 | 17 | #define PORT_KEYSTA 0x0064 18 | #define KEYSTA_SEND_NOTREADY 0x02 19 | #define KEYCMD_WRITE_MODE 0x60 20 | #define KBC_MODE 0x47 21 | 22 | void wait_KBC_sendready(void) 23 | { 24 | /* キーボードコントローラがデータ送信可能になるのを待つ */ 25 | for (;;) { 26 | if ((io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0) { 27 | break; 28 | } 29 | } 30 | return; 31 | } 32 | 33 | void init_keyboard(struct FIFO32 *fifo, int data0) 34 | { 35 | /* 書き込み先のFIFOバッファを記憶 */ 36 | keyfifo = fifo; 37 | keydata0 = data0; 38 | /* キーボードコントローラの初期化 */ 39 | wait_KBC_sendready(); 40 | io_out8(PORT_KEYCMD, KEYCMD_WRITE_MODE); 41 | wait_KBC_sendready(); 42 | io_out8(PORT_KEYDAT, KBC_MODE); 43 | return; 44 | } 45 | -------------------------------------------------------------------------------- /haribote/lines.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win, i; 7 | api_initmalloc(); 8 | buf = api_malloc(160 * 100); 9 | win = api_openwin(buf, 160, 100, -1, "lines"); 10 | for (i = 0; i < 8; i++) { 11 | api_linewin(win + 1, 8, 26, 77, i * 9 + 26, i); 12 | api_linewin(win + 1, 88, 26, i * 9 + 88, 89, i); 13 | } 14 | api_refreshwin(win, 6, 26, 154, 90); 15 | for (;;) { 16 | if (api_getkey(1) == 0x0a) { 17 | break; /* Enterならbreak; */ 18 | } 19 | } 20 | api_closewin(win); 21 | api_end(); 22 | } 23 | -------------------------------------------------------------------------------- /haribote/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /haribote/memory.c: -------------------------------------------------------------------------------- 1 | /* メモリ関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | #define EFLAGS_AC_BIT 0x00040000 6 | #define CR0_CACHE_DISABLE 0x60000000 7 | 8 | unsigned int memtest(unsigned int start, unsigned int end) 9 | { 10 | char flg486 = 0; 11 | unsigned int eflg, cr0, i; 12 | 13 | /* 386か、486以降なのかの確認 */ 14 | eflg = io_load_eflags(); 15 | eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */ 16 | io_store_eflags(eflg); 17 | eflg = io_load_eflags(); 18 | if ((eflg & EFLAGS_AC_BIT) != 0) { /* 386ではAC=1にしても自動で0に戻ってしまう */ 19 | flg486 = 1; 20 | } 21 | eflg &= ~EFLAGS_AC_BIT; /* AC-bit = 0 */ 22 | io_store_eflags(eflg); 23 | 24 | if (flg486 != 0) { 25 | cr0 = load_cr0(); 26 | cr0 |= CR0_CACHE_DISABLE; /* キャッシュ禁止 */ 27 | store_cr0(cr0); 28 | } 29 | 30 | i = memtest_sub(start, end); 31 | 32 | if (flg486 != 0) { 33 | cr0 = load_cr0(); 34 | cr0 &= ~CR0_CACHE_DISABLE; /* キャッシュ許可 */ 35 | store_cr0(cr0); 36 | } 37 | 38 | return i; 39 | } 40 | 41 | void memman_init(struct MEMMAN *man) 42 | { 43 | man->frees = 0; /* あき情報の個数 */ 44 | man->maxfrees = 0; /* 状況観察用:freesの最大値 */ 45 | man->lostsize = 0; /* 解放に失敗した合計サイズ */ 46 | man->losts = 0; /* 解放に失敗した回数 */ 47 | return; 48 | } 49 | 50 | unsigned int memman_total(struct MEMMAN *man) 51 | /* あきサイズの合計を報告 */ 52 | { 53 | unsigned int i, t = 0; 54 | for (i = 0; i < man->frees; i++) { 55 | t += man->free[i].size; 56 | } 57 | return t; 58 | } 59 | 60 | unsigned int memman_alloc(struct MEMMAN *man, unsigned int size) 61 | /* 確保 */ 62 | { 63 | unsigned int i, a; 64 | for (i = 0; i < man->frees; i++) { 65 | if (man->free[i].size >= size) { 66 | /* 十分な広さのあきを発見 */ 67 | a = man->free[i].addr; 68 | man->free[i].addr += size; 69 | man->free[i].size -= size; 70 | if (man->free[i].size == 0) { 71 | /* free[i]がなくなったので前へつめる */ 72 | man->frees--; 73 | for (; i < man->frees; i++) { 74 | man->free[i] = man->free[i + 1]; /* 構造体の代入 */ 75 | } 76 | } 77 | return a; 78 | } 79 | } 80 | return 0; /* あきがない */ 81 | } 82 | 83 | int memman_free(struct MEMMAN *man, unsigned int addr, unsigned int size) 84 | /* 解放 */ 85 | { 86 | int i, j; 87 | /* まとめやすさを考えると、free[]がaddr順に並んでいるほうがいい */ 88 | /* だからまず、どこに入れるべきかを決める */ 89 | for (i = 0; i < man->frees; i++) { 90 | if (man->free[i].addr > addr) { 91 | break; 92 | } 93 | } 94 | /* free[i - 1].addr < addr < free[i].addr */ 95 | if (i > 0) { 96 | /* 前がある */ 97 | if (man->free[i - 1].addr + man->free[i - 1].size == addr) { 98 | /* 前のあき領域にまとめられる */ 99 | man->free[i - 1].size += size; 100 | if (i < man->frees) { 101 | /* 後ろもある */ 102 | if (addr + size == man->free[i].addr) { 103 | /* なんと後ろともまとめられる */ 104 | man->free[i - 1].size += man->free[i].size; 105 | /* man->free[i]の削除 */ 106 | /* free[i]がなくなったので前へつめる */ 107 | man->frees--; 108 | for (; i < man->frees; i++) { 109 | man->free[i] = man->free[i + 1]; /* 構造体の代入 */ 110 | } 111 | } 112 | } 113 | return 0; /* 成功終了 */ 114 | } 115 | } 116 | /* 前とはまとめられなかった */ 117 | if (i < man->frees) { 118 | /* 後ろがある */ 119 | if (addr + size == man->free[i].addr) { 120 | /* 後ろとはまとめられる */ 121 | man->free[i].addr = addr; 122 | man->free[i].size += size; 123 | return 0; /* 成功終了 */ 124 | } 125 | } 126 | /* 前にも後ろにもまとめられない */ 127 | if (man->frees < MEMMAN_FREES) { 128 | /* free[i]より後ろを、後ろへずらして、すきまを作る */ 129 | for (j = man->frees; j > i; j--) { 130 | man->free[j] = man->free[j - 1]; 131 | } 132 | man->frees++; 133 | if (man->maxfrees < man->frees) { 134 | man->maxfrees = man->frees; /* 最大値を更新 */ 135 | } 136 | man->free[i].addr = addr; 137 | man->free[i].size = size; 138 | return 0; /* 成功終了 */ 139 | } 140 | /* 後ろにずらせなかった */ 141 | man->losts++; 142 | man->lostsize += size; 143 | return -1; /* 失敗終了 */ 144 | } 145 | 146 | unsigned int memman_alloc_4k(struct MEMMAN *man, unsigned int size) 147 | { 148 | unsigned int a; 149 | size = (size + 0xfff) & 0xfffff000; 150 | a = memman_alloc(man, size); 151 | return a; 152 | } 153 | 154 | int memman_free_4k(struct MEMMAN *man, unsigned int addr, unsigned int size) 155 | { 156 | int i; 157 | size = (size + 0xfff) & 0xfffff000; 158 | i = memman_free(man, addr, size); 159 | return i; 160 | } 161 | -------------------------------------------------------------------------------- /haribote/module.h: -------------------------------------------------------------------------------- 1 | #ifndef MODULE_H_ 2 | #define MODULE_H_ 3 | 4 | struct module { 5 | int (*init)(void); 6 | void (*exit)(void); 7 | }; 8 | 9 | #endif // MODULE_H_ 10 | -------------------------------------------------------------------------------- /haribote/mouse.c: -------------------------------------------------------------------------------- 1 | /* マウス関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | struct FIFO32 *mousefifo; 6 | int mousedata0; 7 | 8 | void inthandler2c(int *esp) 9 | /* PS/2マウスからの割り込み */ 10 | { 11 | int data; 12 | io_out8(PIC1_OCW2, 0x64); /* IRQ-12受付完了をPIC1に通知 */ 13 | io_out8(PIC0_OCW2, 0x62); /* IRQ-02受付完了をPIC0に通知 */ 14 | data = io_in8(PORT_KEYDAT); 15 | fifo32_put(mousefifo, data + mousedata0); 16 | return; 17 | } 18 | 19 | #define KEYCMD_SENDTO_MOUSE 0xd4 20 | #define MOUSECMD_ENABLE 0xf4 21 | 22 | void enable_mouse(struct FIFO32 *fifo, int data0, struct MOUSE_DEC *mdec) 23 | { 24 | /* 書き込み先のFIFOバッファを記憶 */ 25 | mousefifo = fifo; 26 | mousedata0 = data0; 27 | /* マウス有効 */ 28 | wait_KBC_sendready(); 29 | io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE); 30 | wait_KBC_sendready(); 31 | io_out8(PORT_KEYDAT, MOUSECMD_ENABLE); 32 | /* うまくいくとACK(0xfa)が送信されてくる */ 33 | mdec->phase = 0; /* マウスの0xfaを待っている段階 */ 34 | return; 35 | } 36 | 37 | int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat) 38 | { 39 | if (mdec->phase == 0) { 40 | /* マウスの0xfaを待っている段階 */ 41 | if (dat == 0xfa) { 42 | mdec->phase = 1; 43 | } 44 | return 0; 45 | } 46 | if (mdec->phase == 1) { 47 | /* マウスの1バイト目を待っている段階 */ 48 | if ((dat & 0xc8) == 0x08) { 49 | /* 正しい1バイト目だった */ 50 | mdec->buf[0] = dat; 51 | mdec->phase = 2; 52 | } 53 | return 0; 54 | } 55 | if (mdec->phase == 2) { 56 | /* マウスの2バイト目を待っている段階 */ 57 | mdec->buf[1] = dat; 58 | mdec->phase = 3; 59 | return 0; 60 | } 61 | if (mdec->phase == 3) { 62 | /* マウスの3バイト目を待っている段階 */ 63 | mdec->buf[2] = dat; 64 | mdec->phase = 1; 65 | mdec->btn = mdec->buf[0] & 0x07; 66 | mdec->x = mdec->buf[1]; 67 | mdec->y = mdec->buf[2]; 68 | if ((mdec->buf[0] & 0x10) != 0) { 69 | mdec->x |= 0xffffff00; 70 | } 71 | if ((mdec->buf[0] & 0x20) != 0) { 72 | mdec->y |= 0xffffff00; 73 | } 74 | mdec->y = - mdec->y; /* マウスではy方向の符号が画面と反対 */ 75 | return 1; 76 | } 77 | return -1; /* ここに来ることはないはず */ 78 | } 79 | -------------------------------------------------------------------------------- /haribote/mtask.c: -------------------------------------------------------------------------------- 1 | /* マルチタスク関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | struct TASKCTL *taskctl; 6 | struct TIMER *task_timer; 7 | 8 | struct TASK *task_now(void) 9 | { 10 | struct TASKLEVEL *tl = &taskctl->level[taskctl->now_lv]; 11 | return tl->tasks[tl->now]; 12 | } 13 | 14 | void task_add(struct TASK *task) 15 | { 16 | struct TASKLEVEL *tl = &taskctl->level[task->level]; 17 | tl->tasks[tl->running] = task; 18 | tl->running++; 19 | task->flags = 2; /* 動作中 */ 20 | return; 21 | } 22 | 23 | void task_remove(struct TASK *task) 24 | { 25 | int i; 26 | struct TASKLEVEL *tl = &taskctl->level[task->level]; 27 | 28 | /* taskがどこにいるかを探す */ 29 | for (i = 0; i < tl->running; i++) { 30 | if (tl->tasks[i] == task) { 31 | /* ここにいた */ 32 | break; 33 | } 34 | } 35 | 36 | tl->running--; 37 | if (i < tl->now) { 38 | tl->now--; /* ずれるので、これもあわせておく */ 39 | } 40 | if (tl->now >= tl->running) { 41 | /* nowがおかしな値になっていたら、修正する */ 42 | tl->now = 0; 43 | } 44 | task->flags = 1; /* スリープ中 */ 45 | 46 | /* ずらし */ 47 | for (; i < tl->running; i++) { 48 | tl->tasks[i] = tl->tasks[i + 1]; 49 | } 50 | 51 | return; 52 | } 53 | 54 | void task_switchsub(void) 55 | { 56 | int i; 57 | /* 一番上のレベルを探す */ 58 | for (i = 0; i < MAX_TASKLEVELS; i++) { 59 | if (taskctl->level[i].running > 0) { 60 | break; /* 見つかった */ 61 | } 62 | } 63 | taskctl->now_lv = i; 64 | taskctl->lv_change = 0; 65 | return; 66 | } 67 | 68 | void task_idle(void) 69 | { 70 | for (;;) { 71 | io_hlt(); 72 | } 73 | } 74 | 75 | struct TASK *task_init(struct MEMMAN *memman) 76 | { 77 | int i; 78 | struct TASK *task, *idle; 79 | struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; 80 | 81 | taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL)); 82 | for (i = 0; i < MAX_TASKS; i++) { 83 | taskctl->tasks0[i].flags = 0; 84 | taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8; 85 | taskctl->tasks0[i].tss.ldtr = (TASK_GDT0 + MAX_TASKS + i) * 8; 86 | set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32); 87 | set_segmdesc(gdt + TASK_GDT0 + MAX_TASKS + i, 15, (int) taskctl->tasks0[i].ldt, AR_LDT); 88 | } 89 | for (i = 0; i < MAX_TASKLEVELS; i++) { 90 | taskctl->level[i].running = 0; 91 | taskctl->level[i].now = 0; 92 | } 93 | 94 | task = task_alloc(); 95 | task->flags = 2; /* 動作中マーク */ 96 | task->priority = 2; /* 0.02秒 */ 97 | task->level = 0; /* 最高レベル */ 98 | task_add(task); 99 | task_switchsub(); /* レベル設定 */ 100 | load_tr(task->sel); 101 | task_timer = timer_alloc(); 102 | timer_settime(task_timer, task->priority); 103 | 104 | idle = task_alloc(); 105 | idle->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024; 106 | idle->tss.eip = (int) &task_idle; 107 | idle->tss.es = 1 * 8; 108 | idle->tss.cs = 2 * 8; 109 | idle->tss.ss = 1 * 8; 110 | idle->tss.ds = 1 * 8; 111 | idle->tss.fs = 1 * 8; 112 | idle->tss.gs = 1 * 8; 113 | task_run(idle, MAX_TASKLEVELS - 1, 1); 114 | 115 | return task; 116 | } 117 | 118 | struct TASK *task_alloc(void) 119 | { 120 | int i; 121 | struct TASK *task; 122 | for (i = 0; i < MAX_TASKS; i++) { 123 | if (taskctl->tasks0[i].flags == 0) { 124 | task = &taskctl->tasks0[i]; 125 | task->flags = 1; /* 使用中マーク */ 126 | task->tss.eflags = 0x00000202; /* IF = 1; */ 127 | task->tss.eax = 0; /* とりあえず0にしておくことにする */ 128 | task->tss.ecx = 0; 129 | task->tss.edx = 0; 130 | task->tss.ebx = 0; 131 | task->tss.ebp = 0; 132 | task->tss.esi = 0; 133 | task->tss.edi = 0; 134 | task->tss.es = 0; 135 | task->tss.ds = 0; 136 | task->tss.fs = 0; 137 | task->tss.gs = 0; 138 | task->tss.iomap = 0x40000000; 139 | task->tss.ss0 = 0; 140 | return task; 141 | } 142 | } 143 | return 0; /* もう全部使用中 */ 144 | } 145 | 146 | void task_run(struct TASK *task, int level, int priority) 147 | { 148 | if (level < 0) { 149 | level = task->level; /* レベルを変更しない */ 150 | } 151 | if (priority > 0) { 152 | task->priority = priority; 153 | } 154 | 155 | if (task->flags == 2 && task->level != level) { /* 動作中のレベルの変更 */ 156 | task_remove(task); /* これを実行するとflagsは1になるので下のifも実行される */ 157 | } 158 | if (task->flags != 2) { 159 | /* スリープから起こされる場合 */ 160 | task->level = level; 161 | task_add(task); 162 | } 163 | 164 | taskctl->lv_change = 1; /* 次回タスクスイッチのときにレベルを見直す */ 165 | return; 166 | } 167 | 168 | void task_sleep(struct TASK *task) 169 | { 170 | struct TASK *now_task; 171 | if (task->flags == 2) { 172 | /* 動作中だったら */ 173 | now_task = task_now(); 174 | task_remove(task); /* これを実行するとflagsは1になる */ 175 | if (task == now_task) { 176 | /* 自分自身のスリープだったので、タスクスイッチが必要 */ 177 | task_switchsub(); 178 | now_task = task_now(); /* 設定後での、「現在のタスク」を教えてもらう */ 179 | farjmp(0, now_task->sel); 180 | } 181 | } 182 | return; 183 | } 184 | 185 | void task_switch(void) 186 | { 187 | struct TASKLEVEL *tl = &taskctl->level[taskctl->now_lv]; 188 | struct TASK *new_task, *now_task = tl->tasks[tl->now]; 189 | tl->now++; 190 | if (tl->now == tl->running) { 191 | tl->now = 0; 192 | } 193 | if (taskctl->lv_change != 0) { 194 | task_switchsub(); 195 | tl = &taskctl->level[taskctl->now_lv]; 196 | } 197 | new_task = tl->tasks[tl->now]; 198 | timer_settime(task_timer, new_task->priority); 199 | if (new_task != now_task) { 200 | farjmp(0, new_task->sel); 201 | } 202 | return; 203 | } 204 | -------------------------------------------------------------------------------- /haribote/naskfunc.nas: -------------------------------------------------------------------------------- 1 | ; naskfunc 2 | ; TAB=4 3 | 4 | [FORMAT "WCOFF"] ; オブジェクトファイルを作るモード 5 | [INSTRSET "i486p"] ; 486の命令まで使いたいという記述 6 | [BITS 32] ; 32ビットモード用の機械語を作らせる 7 | [FILE "naskfunc.nas"] ; ソースファイル名情報 8 | 9 | GLOBAL _io_hlt, _io_cli, _io_sti, _io_stihlt 10 | GLOBAL _io_in8, _io_in16, _io_in32 11 | GLOBAL _io_out8, _io_out16, _io_out32 12 | GLOBAL _io_load_eflags, _io_store_eflags 13 | GLOBAL _load_gdtr, _load_idtr 14 | GLOBAL _load_cr0, _store_cr0 15 | GLOBAL _load_tr 16 | GLOBAL _asm_inthandler20, _asm_inthandler21 17 | GLOBAL _asm_inthandler2c, _asm_inthandler0c 18 | GLOBAL _asm_inthandler0d, _asm_end_app 19 | GLOBAL _memtest_sub 20 | GLOBAL _farjmp, _farcall 21 | GLOBAL _asm_hrb_api, _start_app 22 | EXTERN _inthandler20, _inthandler21 23 | EXTERN _inthandler2c, _inthandler0d 24 | EXTERN _inthandler0c 25 | EXTERN _hrb_api 26 | 27 | [SECTION .text] 28 | 29 | _io_hlt: ; void io_hlt(void); 30 | HLT 31 | RET 32 | 33 | _io_cli: ; void io_cli(void); 34 | CLI 35 | RET 36 | 37 | _io_sti: ; void io_sti(void); 38 | STI 39 | RET 40 | 41 | _io_stihlt: ; void io_stihlt(void); 42 | STI 43 | HLT 44 | RET 45 | 46 | _io_in8: ; int io_in8(int port); 47 | MOV EDX,[ESP+4] ; port 48 | MOV EAX,0 49 | IN AL,DX 50 | RET 51 | 52 | _io_in16: ; int io_in16(int port); 53 | MOV EDX,[ESP+4] ; port 54 | MOV EAX,0 55 | IN AX,DX 56 | RET 57 | 58 | _io_in32: ; int io_in32(int port); 59 | MOV EDX,[ESP+4] ; port 60 | IN EAX,DX 61 | RET 62 | 63 | _io_out8: ; void io_out8(int port, int data); 64 | MOV EDX,[ESP+4] ; port 65 | MOV AL,[ESP+8] ; data 66 | OUT DX,AL 67 | RET 68 | 69 | _io_out16: ; void io_out16(int port, int data); 70 | MOV EDX,[ESP+4] ; port 71 | MOV EAX,[ESP+8] ; data 72 | OUT DX,AX 73 | RET 74 | 75 | _io_out32: ; void io_out32(int port, int data); 76 | MOV EDX,[ESP+4] ; port 77 | MOV EAX,[ESP+8] ; data 78 | OUT DX,EAX 79 | RET 80 | 81 | _io_load_eflags: ; int io_load_eflags(void); 82 | PUSHFD ; PUSH EFLAGS という意味 83 | POP EAX 84 | RET 85 | 86 | _io_store_eflags: ; void io_store_eflags(int eflags); 87 | MOV EAX,[ESP+4] 88 | PUSH EAX 89 | POPFD ; POP EFLAGS という意味 90 | RET 91 | 92 | _load_gdtr: ; void load_gdtr(int limit, int addr); 93 | MOV AX,[ESP+4] ; limit 94 | MOV [ESP+6],AX 95 | LGDT [ESP+6] 96 | RET 97 | 98 | _load_idtr: ; void load_idtr(int limit, int addr); 99 | MOV AX,[ESP+4] ; limit 100 | MOV [ESP+6],AX 101 | LIDT [ESP+6] 102 | RET 103 | 104 | _load_cr0: ; int load_cr0(void); 105 | MOV EAX,CR0 106 | RET 107 | 108 | _store_cr0: ; void store_cr0(int cr0); 109 | MOV EAX,[ESP+4] 110 | MOV CR0,EAX 111 | RET 112 | 113 | _load_tr: ; void load_tr(int tr); 114 | LTR [ESP+4] ; tr 115 | RET 116 | 117 | _asm_inthandler20: 118 | PUSH ES 119 | PUSH DS 120 | PUSHAD 121 | MOV EAX,ESP 122 | PUSH EAX 123 | MOV AX,SS 124 | MOV DS,AX 125 | MOV ES,AX 126 | CALL _inthandler20 127 | POP EAX 128 | POPAD 129 | POP DS 130 | POP ES 131 | IRETD 132 | 133 | _asm_inthandler21: 134 | PUSH ES 135 | PUSH DS 136 | PUSHAD 137 | MOV EAX,ESP 138 | PUSH EAX 139 | MOV AX,SS 140 | MOV DS,AX 141 | MOV ES,AX 142 | CALL _inthandler21 143 | POP EAX 144 | POPAD 145 | POP DS 146 | POP ES 147 | IRETD 148 | 149 | _asm_inthandler2c: 150 | PUSH ES 151 | PUSH DS 152 | PUSHAD 153 | MOV EAX,ESP 154 | PUSH EAX 155 | MOV AX,SS 156 | MOV DS,AX 157 | MOV ES,AX 158 | CALL _inthandler2c 159 | POP EAX 160 | POPAD 161 | POP DS 162 | POP ES 163 | IRETD 164 | 165 | _asm_inthandler0c: 166 | STI 167 | PUSH ES 168 | PUSH DS 169 | PUSHAD 170 | MOV EAX,ESP 171 | PUSH EAX 172 | MOV AX,SS 173 | MOV DS,AX 174 | MOV ES,AX 175 | CALL _inthandler0c 176 | CMP EAX,0 177 | JNE _asm_end_app 178 | POP EAX 179 | POPAD 180 | POP DS 181 | POP ES 182 | ADD ESP,4 ; INT 0x0c でも、これが必要 183 | IRETD 184 | 185 | _asm_inthandler0d: 186 | STI 187 | PUSH ES 188 | PUSH DS 189 | PUSHAD 190 | MOV EAX,ESP 191 | PUSH EAX 192 | MOV AX,SS 193 | MOV DS,AX 194 | MOV ES,AX 195 | CALL _inthandler0d 196 | CMP EAX,0 ; ここだけ違う 197 | JNE _asm_end_app ; ここだけ違う 198 | POP EAX 199 | POPAD 200 | POP DS 201 | POP ES 202 | ADD ESP,4 ; INT 0x0d では、これが必要 203 | IRETD 204 | 205 | _memtest_sub: ; unsigned int memtest_sub(unsigned int start, unsigned int end) 206 | PUSH EDI ; (EBX, ESI, EDI も使いたいので) 207 | PUSH ESI 208 | PUSH EBX 209 | MOV ESI,0xaa55aa55 ; pat0 = 0xaa55aa55; 210 | MOV EDI,0x55aa55aa ; pat1 = 0x55aa55aa; 211 | MOV EAX,[ESP+12+4] ; i = start; 212 | mts_loop: 213 | MOV EBX,EAX 214 | ADD EBX,0xffc ; p = i + 0xffc; 215 | MOV EDX,[EBX] ; old = *p; 216 | MOV [EBX],ESI ; *p = pat0; 217 | XOR DWORD [EBX],0xffffffff ; *p ^= 0xffffffff; 218 | CMP EDI,[EBX] ; if (*p != pat1) goto fin; 219 | JNE mts_fin 220 | XOR DWORD [EBX],0xffffffff ; *p ^= 0xffffffff; 221 | CMP ESI,[EBX] ; if (*p != pat0) goto fin; 222 | JNE mts_fin 223 | MOV [EBX],EDX ; *p = old; 224 | ADD EAX,0x1000 ; i += 0x1000; 225 | CMP EAX,[ESP+12+8] ; if (i <= end) goto mts_loop; 226 | JBE mts_loop 227 | POP EBX 228 | POP ESI 229 | POP EDI 230 | RET 231 | mts_fin: 232 | MOV [EBX],EDX ; *p = old; 233 | POP EBX 234 | POP ESI 235 | POP EDI 236 | RET 237 | 238 | _farjmp: ; void farjmp(int eip, int cs); 239 | JMP FAR [ESP+4] ; eip, cs 240 | RET 241 | 242 | _farcall: ; void farcall(int eip, int cs); 243 | CALL FAR [ESP+4] ; eip, cs 244 | RET 245 | 246 | _asm_hrb_api: 247 | STI 248 | PUSH DS 249 | PUSH ES 250 | PUSHAD ; 保存のためのPUSH 251 | PUSHAD ; hrb_apiにわたすためのPUSH 252 | MOV AX,SS 253 | MOV DS,AX ; OS用のセグメントをDSとESにも入れる 254 | MOV ES,AX 255 | CALL _hrb_api 256 | CMP EAX,0 ; EAXが0でなければアプリ終了処理 257 | JNE _asm_end_app 258 | ADD ESP,32 259 | POPAD 260 | POP ES 261 | POP DS 262 | IRETD 263 | _asm_end_app: 264 | ; EAXはtss.esp0の番地 265 | MOV ESP,[EAX] 266 | MOV DWORD [EAX+4],0 267 | POPAD 268 | RET ; cmd_appへ帰る 269 | 270 | _start_app: ; void start_app(int eip, int cs, int esp, int ds, int *tss_esp0); 271 | PUSHAD ; 32ビットレジスタを全部保存しておく 272 | MOV EAX,[ESP+36] ; アプリ用のEIP 273 | MOV ECX,[ESP+40] ; アプリ用のCS 274 | MOV EDX,[ESP+44] ; アプリ用のESP 275 | MOV EBX,[ESP+48] ; アプリ用のDS/SS 276 | MOV EBP,[ESP+52] ; tss.esp0の番地 277 | MOV [EBP ],ESP ; OS用のESPを保存 278 | MOV [EBP+4],SS ; OS用のSSを保存 279 | MOV ES,BX 280 | MOV DS,BX 281 | MOV FS,BX 282 | MOV GS,BX 283 | ; 以下はRETFでアプリに行かせるためのスタック調整 284 | OR ECX,3 ; アプリ用のセグメント番号に3をORする 285 | OR EBX,3 ; アプリ用のセグメント番号に3をORする 286 | PUSH EBX ; アプリのSS 287 | PUSH EDX ; アプリのESP 288 | PUSH ECX ; アプリのCS 289 | PUSH EAX ; アプリのEIP 290 | RETF 291 | ; アプリが終了してもここには来ない 292 | -------------------------------------------------------------------------------- /haribote/noodle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "apilib.h" 3 | 4 | void HariMain(void) 5 | { 6 | char *buf, s[12]; 7 | int win, timer, sec = 0, min = 0, hou = 0; 8 | api_initmalloc(); 9 | buf = api_malloc(150 * 50); 10 | win = api_openwin(buf, 150, 50, -1, "noodle"); 11 | timer = api_alloctimer(); 12 | api_inittimer(timer, 128); 13 | for (;;) { 14 | sprintf(s, "%5d:%02d:%02d", hou, min, sec); 15 | api_boxfilwin(win, 28, 27, 115, 41, 7 /* 白 */); 16 | api_putstrwin(win, 28, 27, 0 /* 黒 */, 11, s); 17 | api_settimer(timer, 100); /* 1秒間 */ 18 | if (api_getkey(1) != 128) { 19 | break; 20 | } 21 | sec++; 22 | if (sec == 60) { 23 | sec = 0; 24 | min++; 25 | if (min == 60) { 26 | min = 0; 27 | hou++; 28 | } 29 | } 30 | } 31 | api_end(); 32 | } 33 | -------------------------------------------------------------------------------- /haribote/sheet.c: -------------------------------------------------------------------------------- 1 | /* マウスやウィンドウの重ね合わせ処理 */ 2 | 3 | #include "bootpack.h" 4 | 5 | #define SHEET_USE 1 6 | 7 | struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize) 8 | { 9 | struct SHTCTL *ctl; 10 | int i; 11 | ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL)); 12 | if (ctl == 0) { 13 | goto err; 14 | } 15 | ctl->map = (unsigned char *) memman_alloc_4k(memman, xsize * ysize); 16 | if (ctl->map == 0) { 17 | memman_free_4k(memman, (int) ctl, sizeof (struct SHTCTL)); 18 | goto err; 19 | } 20 | ctl->vram = vram; 21 | ctl->xsize = xsize; 22 | ctl->ysize = ysize; 23 | ctl->top = -1; /* シートは一枚もない */ 24 | for (i = 0; i < MAX_SHEETS; i++) { 25 | ctl->sheets0[i].flags = 0; /* 未使用マーク */ 26 | ctl->sheets0[i].ctl = ctl; /* 所属を記録 */ 27 | } 28 | err: 29 | return ctl; 30 | } 31 | 32 | struct SHEET *sheet_alloc(struct SHTCTL *ctl) 33 | { 34 | struct SHEET *sht; 35 | int i; 36 | for (i = 0; i < MAX_SHEETS; i++) { 37 | if (ctl->sheets0[i].flags == 0) { 38 | sht = &ctl->sheets0[i]; 39 | sht->flags = SHEET_USE; /* 使用中マーク */ 40 | sht->height = -1; /* 非表示中 */ 41 | sht->task = 0; /* 自動で閉じる機能を使わない */ 42 | return sht; 43 | } 44 | } 45 | return 0; /* 全てのシートが使用中だった */ 46 | } 47 | 48 | void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, int col_inv) 49 | { 50 | sht->buf = buf; 51 | sht->bxsize = xsize; 52 | sht->bysize = ysize; 53 | sht->col_inv = col_inv; 54 | return; 55 | } 56 | 57 | void sheet_refreshmap(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0) 58 | { 59 | int h, bx, by, vx, vy, bx0, by0, bx1, by1, sid4, *p; 60 | unsigned char *buf, sid, *map = ctl->map; 61 | struct SHEET *sht; 62 | if (vx0 < 0) { vx0 = 0; } 63 | if (vy0 < 0) { vy0 = 0; } 64 | if (vx1 > ctl->xsize) { vx1 = ctl->xsize; } 65 | if (vy1 > ctl->ysize) { vy1 = ctl->ysize; } 66 | for (h = h0; h <= ctl->top; h++) { 67 | sht = ctl->sheets[h]; 68 | sid = sht - ctl->sheets0; /* 番地を引き算してそれを下じき番号として利用 */ 69 | buf = sht->buf; 70 | bx0 = vx0 - sht->vx0; 71 | by0 = vy0 - sht->vy0; 72 | bx1 = vx1 - sht->vx0; 73 | by1 = vy1 - sht->vy0; 74 | if (bx0 < 0) { bx0 = 0; } 75 | if (by0 < 0) { by0 = 0; } 76 | if (bx1 > sht->bxsize) { bx1 = sht->bxsize; } 77 | if (by1 > sht->bysize) { by1 = sht->bysize; } 78 | if (sht->col_inv == -1) { 79 | if ((sht->vx0 & 3) == 0 && (bx0 & 3) == 0 && (bx1 & 3) == 0) { 80 | /* 透明色なし専用の高速版(4バイト型) */ 81 | bx1 = (bx1 - bx0) / 4; /* MOV回数 */ 82 | sid4 = sid | sid << 8 | sid << 16 | sid << 24; 83 | for (by = by0; by < by1; by++) { 84 | vy = sht->vy0 + by; 85 | vx = sht->vx0 + bx0; 86 | p = (int *) &map[vy * ctl->xsize + vx]; 87 | for (bx = 0; bx < bx1; bx++) { 88 | p[bx] = sid4; 89 | } 90 | } 91 | } else { 92 | /* 透明色なし専用の高速版(1バイト型) */ 93 | for (by = by0; by < by1; by++) { 94 | vy = sht->vy0 + by; 95 | for (bx = bx0; bx < bx1; bx++) { 96 | vx = sht->vx0 + bx; 97 | map[vy * ctl->xsize + vx] = sid; 98 | } 99 | } 100 | } 101 | } else { 102 | /* 透明色ありの一般版 */ 103 | for (by = by0; by < by1; by++) { 104 | vy = sht->vy0 + by; 105 | for (bx = bx0; bx < bx1; bx++) { 106 | vx = sht->vx0 + bx; 107 | if (buf[by * sht->bxsize + bx] != sht->col_inv) { 108 | map[vy * ctl->xsize + vx] = sid; 109 | } 110 | } 111 | } 112 | } 113 | } 114 | return; 115 | } 116 | 117 | void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0, int h1) 118 | { 119 | int h, bx, by, vx, vy, bx0, by0, bx1, by1, bx2, sid4, i, i1, *p, *q, *r; 120 | unsigned char *buf, *vram = ctl->vram, *map = ctl->map, sid; 121 | struct SHEET *sht; 122 | /* refresh範囲が画面外にはみ出していたら補正 */ 123 | if (vx0 < 0) { vx0 = 0; } 124 | if (vy0 < 0) { vy0 = 0; } 125 | if (vx1 > ctl->xsize) { vx1 = ctl->xsize; } 126 | if (vy1 > ctl->ysize) { vy1 = ctl->ysize; } 127 | for (h = h0; h <= h1; h++) { 128 | sht = ctl->sheets[h]; 129 | buf = sht->buf; 130 | sid = sht - ctl->sheets0; 131 | /* vx0〜vy1を使って、bx0〜by1を逆算する */ 132 | bx0 = vx0 - sht->vx0; 133 | by0 = vy0 - sht->vy0; 134 | bx1 = vx1 - sht->vx0; 135 | by1 = vy1 - sht->vy0; 136 | if (bx0 < 0) { bx0 = 0; } 137 | if (by0 < 0) { by0 = 0; } 138 | if (bx1 > sht->bxsize) { bx1 = sht->bxsize; } 139 | if (by1 > sht->bysize) { by1 = sht->bysize; } 140 | if ((sht->vx0 & 3) == 0) { 141 | /* 4バイト型 */ 142 | i = (bx0 + 3) / 4; /* bx0を4で割ったもの(端数切り上げ) */ 143 | i1 = bx1 / 4; /* bx1を4で割ったもの(端数切り捨て) */ 144 | i1 = i1 - i; 145 | sid4 = sid | sid << 8 | sid << 16 | sid << 24; 146 | for (by = by0; by < by1; by++) { 147 | vy = sht->vy0 + by; 148 | for (bx = bx0; bx < bx1 && (bx & 3) != 0; bx++) { /* 前の端数を1バイトずつ */ 149 | vx = sht->vx0 + bx; 150 | if (map[vy * ctl->xsize + vx] == sid) { 151 | vram[vy * ctl->xsize + vx] = buf[by * sht->bxsize + bx]; 152 | } 153 | } 154 | vx = sht->vx0 + bx; 155 | p = (int *) &map[vy * ctl->xsize + vx]; 156 | q = (int *) &vram[vy * ctl->xsize + vx]; 157 | r = (int *) &buf[by * sht->bxsize + bx]; 158 | for (i = 0; i < i1; i++) { /* 4の倍数部分 */ 159 | if (p[i] == sid4) { 160 | q[i] = r[i]; 161 | } else { 162 | bx2 = bx + i * 4; 163 | vx = sht->vx0 + bx2; 164 | if (map[vy * ctl->xsize + vx + 0] == sid) { 165 | vram[vy * ctl->xsize + vx + 0] = buf[by * sht->bxsize + bx2 + 0]; 166 | } 167 | if (map[vy * ctl->xsize + vx + 1] == sid) { 168 | vram[vy * ctl->xsize + vx + 1] = buf[by * sht->bxsize + bx2 + 1]; 169 | } 170 | if (map[vy * ctl->xsize + vx + 2] == sid) { 171 | vram[vy * ctl->xsize + vx + 2] = buf[by * sht->bxsize + bx2 + 2]; 172 | } 173 | if (map[vy * ctl->xsize + vx + 3] == sid) { 174 | vram[vy * ctl->xsize + vx + 3] = buf[by * sht->bxsize + bx2 + 3]; 175 | } 176 | } 177 | } 178 | for (bx += i1 * 4; bx < bx1; bx++) { /* 後ろの端数を1バイトずつ */ 179 | vx = sht->vx0 + bx; 180 | if (map[vy * ctl->xsize + vx] == sid) { 181 | vram[vy * ctl->xsize + vx] = buf[by * sht->bxsize + bx]; 182 | } 183 | } 184 | } 185 | } else { 186 | /* 1バイト型 */ 187 | for (by = by0; by < by1; by++) { 188 | vy = sht->vy0 + by; 189 | for (bx = bx0; bx < bx1; bx++) { 190 | vx = sht->vx0 + bx; 191 | if (map[vy * ctl->xsize + vx] == sid) { 192 | vram[vy * ctl->xsize + vx] = buf[by * sht->bxsize + bx]; 193 | } 194 | } 195 | } 196 | } 197 | } 198 | return; 199 | } 200 | 201 | void sheet_updown(struct SHEET *sht, int height) 202 | { 203 | struct SHTCTL *ctl = sht->ctl; 204 | int h, old = sht->height; /* 設定前の高さを記憶する */ 205 | 206 | /* 指定が低すぎや高すぎだったら、修正する */ 207 | if (height > ctl->top + 1) { 208 | height = ctl->top + 1; 209 | } 210 | if (height < -1) { 211 | height = -1; 212 | } 213 | sht->height = height; /* 高さを設定 */ 214 | 215 | /* 以下は主にsheets[]の並べ替え */ 216 | if (old > height) { /* 以前よりも低くなる */ 217 | if (height >= 0) { 218 | /* 間のものを引き上げる */ 219 | for (h = old; h > height; h--) { 220 | ctl->sheets[h] = ctl->sheets[h - 1]; 221 | ctl->sheets[h]->height = h; 222 | } 223 | ctl->sheets[height] = sht; 224 | sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height + 1); 225 | sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height + 1, old); 226 | } else { /* 非表示化 */ 227 | if (ctl->top > old) { 228 | /* 上になっているものをおろす */ 229 | for (h = old; h < ctl->top; h++) { 230 | ctl->sheets[h] = ctl->sheets[h + 1]; 231 | ctl->sheets[h]->height = h; 232 | } 233 | } 234 | ctl->top--; /* 表示中の下じきが一つ減るので、一番上の高さが減る */ 235 | sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0); 236 | sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0, old - 1); 237 | } 238 | } else if (old < height) { /* 以前よりも高くなる */ 239 | if (old >= 0) { 240 | /* 間のものを押し下げる */ 241 | for (h = old; h < height; h++) { 242 | ctl->sheets[h] = ctl->sheets[h + 1]; 243 | ctl->sheets[h]->height = h; 244 | } 245 | ctl->sheets[height] = sht; 246 | } else { /* 非表示状態から表示状態へ */ 247 | /* 上になるものを持ち上げる */ 248 | for (h = ctl->top; h >= height; h--) { 249 | ctl->sheets[h + 1] = ctl->sheets[h]; 250 | ctl->sheets[h + 1]->height = h + 1; 251 | } 252 | ctl->sheets[height] = sht; 253 | ctl->top++; /* 表示中の下じきが一つ増えるので、一番上の高さが増える */ 254 | } 255 | sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height); 256 | sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height, height); 257 | } 258 | return; 259 | } 260 | 261 | void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1) 262 | { 263 | if (sht->height >= 0) { /* もしも表示中なら、新しい下じきの情報に沿って画面を描き直す */ 264 | sheet_refreshsub(sht->ctl, sht->vx0 + bx0, sht->vy0 + by0, sht->vx0 + bx1, sht->vy0 + by1, sht->height, sht->height); 265 | } 266 | return; 267 | } 268 | 269 | void sheet_slide(struct SHEET *sht, int vx0, int vy0) 270 | { 271 | struct SHTCTL *ctl = sht->ctl; 272 | int old_vx0 = sht->vx0, old_vy0 = sht->vy0; 273 | sht->vx0 = vx0; 274 | sht->vy0 = vy0; 275 | if (sht->height >= 0) { /* もしも表示中なら、新しい下じきの情報に沿って画面を描き直す */ 276 | sheet_refreshmap(ctl, old_vx0, old_vy0, old_vx0 + sht->bxsize, old_vy0 + sht->bysize, 0); 277 | sheet_refreshmap(ctl, vx0, vy0, vx0 + sht->bxsize, vy0 + sht->bysize, sht->height); 278 | sheet_refreshsub(ctl, old_vx0, old_vy0, old_vx0 + sht->bxsize, old_vy0 + sht->bysize, 0, sht->height - 1); 279 | sheet_refreshsub(ctl, vx0, vy0, vx0 + sht->bxsize, vy0 + sht->bysize, sht->height, sht->height); 280 | } 281 | return; 282 | } 283 | 284 | void sheet_free(struct SHEET *sht) 285 | { 286 | if (sht->height >= 0) { 287 | sheet_updown(sht, -1); /* 表示中ならまず非表示にする */ 288 | } 289 | sht->flags = 0; /* 未使用マーク */ 290 | return; 291 | } 292 | -------------------------------------------------------------------------------- /haribote/timer.c: -------------------------------------------------------------------------------- 1 | /* タイマ関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | #define PIT_CTRL 0x0043 6 | #define PIT_CNT0 0x0040 7 | 8 | struct TIMERCTL timerctl; 9 | 10 | #define TIMER_FLAGS_ALLOC 1 /* 確保した状態 */ 11 | #define TIMER_FLAGS_USING 2 /* タイマ作動中 */ 12 | 13 | void init_pit(void) 14 | { 15 | int i; 16 | struct TIMER *t; 17 | io_out8(PIT_CTRL, 0x34); 18 | io_out8(PIT_CNT0, 0x9c); 19 | io_out8(PIT_CNT0, 0x2e); 20 | timerctl.count = 0; 21 | for (i = 0; i < MAX_TIMER; i++) { 22 | timerctl.timers0[i].flags = 0; /* 未使用 */ 23 | } 24 | t = timer_alloc(); /* 一つもらってくる */ 25 | t->timeout = 0xffffffff; 26 | t->flags = TIMER_FLAGS_USING; 27 | t->next = 0; /* 一番うしろ */ 28 | timerctl.t0 = t; /* 今は番兵しかいないので先頭でもある */ 29 | timerctl.next = 0xffffffff; /* 番兵しかいないので番兵の時刻 */ 30 | return; 31 | } 32 | 33 | struct TIMER *timer_alloc(void) 34 | { 35 | int i; 36 | for (i = 0; i < MAX_TIMER; i++) { 37 | if (timerctl.timers0[i].flags == 0) { 38 | timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC; 39 | timerctl.timers0[i].flags2 = 0; 40 | return &timerctl.timers0[i]; 41 | } 42 | } 43 | return 0; /* 見つからなかった */ 44 | } 45 | 46 | void timer_free(struct TIMER *timer) 47 | { 48 | timer->flags = 0; /* 未使用 */ 49 | return; 50 | } 51 | 52 | void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data) 53 | { 54 | timer->fifo = fifo; 55 | timer->data = data; 56 | return; 57 | } 58 | 59 | void timer_settime(struct TIMER *timer, unsigned int timeout) 60 | { 61 | int e; 62 | struct TIMER *t, *s; 63 | timer->timeout = timeout + timerctl.count; 64 | timer->flags = TIMER_FLAGS_USING; 65 | e = io_load_eflags(); 66 | io_cli(); 67 | t = timerctl.t0; 68 | if (timer->timeout <= t->timeout) { 69 | /* 先頭に入れる場合 */ 70 | timerctl.t0 = timer; 71 | timer->next = t; /* 次はt */ 72 | timerctl.next = timer->timeout; 73 | io_store_eflags(e); 74 | return; 75 | } 76 | /* どこに入れればいいかを探す */ 77 | for (;;) { 78 | s = t; 79 | t = t->next; 80 | if (timer->timeout <= t->timeout) { 81 | /* sとtの間に入れる場合 */ 82 | s->next = timer; /* sの次はtimer */ 83 | timer->next = t; /* timerの次はt */ 84 | io_store_eflags(e); 85 | return; 86 | } 87 | } 88 | } 89 | 90 | void inthandler20(int *esp) 91 | { 92 | struct TIMER *timer; 93 | char ts = 0; 94 | io_out8(PIC0_OCW2, 0x60); /* IRQ-00受付完了をPICに通知 */ 95 | timerctl.count++; 96 | if (timerctl.next > timerctl.count) { 97 | return; 98 | } 99 | timer = timerctl.t0; /* とりあえず先頭の番地をtimerに代入 */ 100 | for (;;) { 101 | /* timersのタイマは全て動作中のものなので、flagsを確認しない */ 102 | if (timer->timeout > timerctl.count) { 103 | break; 104 | } 105 | /* タイムアウト */ 106 | timer->flags = TIMER_FLAGS_ALLOC; 107 | if (timer != task_timer) { 108 | fifo32_put(timer->fifo, timer->data); 109 | } else { 110 | ts = 1; /* task_timerがタイムアウトした */ 111 | } 112 | timer = timer->next; /* 次のタイマの番地をtimerに代入 */ 113 | } 114 | timerctl.t0 = timer; 115 | timerctl.next = timer->timeout; 116 | if (ts != 0) { 117 | task_switch(); 118 | } 119 | return; 120 | } 121 | 122 | int timer_cancel(struct TIMER *timer) 123 | { 124 | int e; 125 | struct TIMER *t; 126 | e = io_load_eflags(); 127 | io_cli(); /* 設定中にタイマの状態が変化しないようにするため */ 128 | if (timer->flags == TIMER_FLAGS_USING) { /* 取り消し処理は必要か? */ 129 | if (timer == timerctl.t0) { 130 | /* 先頭だった場合の取り消し処理 */ 131 | t = timer->next; 132 | timerctl.t0 = t; 133 | timerctl.next = t->timeout; 134 | } else { 135 | /* 先頭以外の場合の取り消し処理 */ 136 | /* timerの一つ前を探す */ 137 | t = timerctl.t0; 138 | for (;;) { 139 | if (t->next == timer) { 140 | break; 141 | } 142 | t = t->next; 143 | } 144 | t->next = timer->next; /* 「timerの直前」の次が、「timerの次」を指すようにする */ 145 | } 146 | timer->flags = TIMER_FLAGS_ALLOC; 147 | io_store_eflags(e); 148 | return 1; /* キャンセル処理成功 */ 149 | } 150 | io_store_eflags(e); 151 | return 0; /* キャンセル処理は不要だった */ 152 | } 153 | 154 | void timer_cancelall(struct FIFO32 *fifo) 155 | { 156 | int e, i; 157 | struct TIMER *t; 158 | e = io_load_eflags(); 159 | io_cli(); /* 設定中にタイマの状態が変化しないようにするため */ 160 | for (i = 0; i < MAX_TIMER; i++) { 161 | t = &timerctl.timers0[i]; 162 | if (t->flags != 0 && t->flags2 != 0 && t->fifo == fifo) { 163 | timer_cancel(t); 164 | timer_free(t); 165 | } 166 | } 167 | io_store_eflags(e); 168 | return; 169 | } 170 | -------------------------------------------------------------------------------- /haribote/window.c: -------------------------------------------------------------------------------- 1 | /* ウィンドウ関係 */ 2 | 3 | #include "bootpack.h" 4 | 5 | void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act) 6 | { 7 | boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 ); 8 | boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 ); 9 | boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1); 10 | boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2); 11 | boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2); 12 | boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1); 13 | boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3); 14 | boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2); 15 | boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1); 16 | make_wtitle8(buf, xsize, title, act); 17 | return; 18 | } 19 | 20 | void make_wtitle8(unsigned char *buf, int xsize, char *title, char act) 21 | { 22 | static char closebtn[14][16] = { 23 | "OOOOOOOOOOOOOOO@", 24 | "OQQQQQQQQQQQQQ$@", 25 | "OQQQQQQQQQQQQQ$@", 26 | "OQQQ@@QQQQ@@QQ$@", 27 | "OQQQQ@@QQ@@QQQ$@", 28 | "OQQQQQ@@@@QQQQ$@", 29 | "OQQQQQQ@@QQQQQ$@", 30 | "OQQQQQ@@@@QQQQ$@", 31 | "OQQQQ@@QQ@@QQQ$@", 32 | "OQQQ@@QQQQ@@QQ$@", 33 | "OQQQQQQQQQQQQQ$@", 34 | "OQQQQQQQQQQQQQ$@", 35 | "O$$$$$$$$$$$$$$@", 36 | "@@@@@@@@@@@@@@@@" 37 | }; 38 | int x, y; 39 | char c, tc, tbc; 40 | if (act != 0) { 41 | tc = COL8_FFFFFF; 42 | tbc = COL8_000084; 43 | } else { 44 | tc = COL8_C6C6C6; 45 | tbc = COL8_848484; 46 | } 47 | boxfill8(buf, xsize, tbc, 3, 3, xsize - 4, 20); 48 | putfonts8_asc(buf, xsize, 24, 4, tc, title); 49 | for (y = 0; y < 14; y++) { 50 | for (x = 0; x < 16; x++) { 51 | c = closebtn[y][x]; 52 | if (c == '@') { 53 | c = COL8_000000; 54 | } else if (c == '$') { 55 | c = COL8_848484; 56 | } else if (c == 'Q') { 57 | c = COL8_C6C6C6; 58 | } else { 59 | c = COL8_FFFFFF; 60 | } 61 | buf[(5 + y) * xsize + (xsize - 21 + x)] = c; 62 | } 63 | } 64 | return; 65 | } 66 | 67 | void putfouts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l) 68 | { 69 | struct TASK *task = task_now(); 70 | boxfill8(sht->buf, sht->bxsize, b, x, y, x + l * 8 - 1, y + 15); 71 | if (task->langmode != 0 && task->langbyte1 != 0) { 72 | putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s); 73 | sheet_refresh(sht, x - 8, y, x + l * 8, y + 16); 74 | } else { 75 | putfonts8_asc(sht->buf, sht->bxsize, x, y, c, s); 76 | sheet_refresh(sht, x, y, x + l * 8, y + 16); 77 | } 78 | return; 79 | } 80 | 81 | void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c) 82 | { 83 | int x1 = x0 + sx, y1 = y0 + sy; 84 | boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 2, y0 - 3, x1 + 1, y0 - 3); 85 | boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 3, y0 - 3, x0 - 3, y1 + 1); 86 | boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x0 - 3, y1 + 2, x1 + 1, y1 + 2); 87 | boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x1 + 2, y0 - 3, x1 + 2, y1 + 2); 88 | boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2); 89 | boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0); 90 | boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x0 - 2, y1 + 1, x1 + 0, y1 + 1); 91 | boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x1 + 1, y0 - 2, x1 + 1, y1 + 1); 92 | boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0); 93 | return; 94 | } 95 | 96 | void change_wtitle8(struct SHEET *sht, char act) 97 | { 98 | int x, y, xsize = sht->bxsize; 99 | char c, tc_new, tbc_new, tc_old, tbc_old, *buf = sht->buf; 100 | if (act != 0) { 101 | tc_new = COL8_FFFFFF; 102 | tbc_new = COL8_000084; 103 | tc_old = COL8_C6C6C6; 104 | tbc_old = COL8_848484; 105 | } else { 106 | tc_new = COL8_C6C6C6; 107 | tbc_new = COL8_848484; 108 | tc_old = COL8_FFFFFF; 109 | tbc_old = COL8_000084; 110 | } 111 | for (y = 3; y <= 20; y++) { 112 | for (x = 3; x <= xsize - 4; x++) { 113 | c = buf[y * xsize + x]; 114 | if (c == tc_old && x <= xsize - 22) { 115 | c = tc_new; 116 | } else if (c == tbc_old) { 117 | c = tbc_new; 118 | } 119 | buf[y * xsize + x] = c; 120 | } 121 | } 122 | sheet_refresh(sht, 3, 3, xsize, 21); 123 | return; 124 | } 125 | -------------------------------------------------------------------------------- /haribote_elf.lds: -------------------------------------------------------------------------------- 1 | ENTRY(_HariMain) 2 | INCLUDE ld_variables.lds 3 | 4 | SECTIONS 5 | { 6 | . = SIZEOF_HEADERS; 7 | .text : { *(.text) } 8 | "file offset of data" = .; 9 | 10 | . = 0; 11 | .stack : AT("file offset of data") { 12 | . = STACK; 13 | } 14 | .data : { 15 | *(.rodata*) *(.data) 16 | } 17 | .bss : { *(.bss) } 18 | .malloc : { 19 | . += MALLOC; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello3/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /hello3/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /hello3/Makefile: -------------------------------------------------------------------------------- 1 | APP = hello3 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /hello3/hello3.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | api_putchar('h'); 6 | api_putchar('e'); 7 | api_putchar('l'); 8 | api_putchar('l'); 9 | api_putchar('o'); 10 | api_end(); 11 | } 12 | -------------------------------------------------------------------------------- /hello3/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /hello4/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /hello4/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /hello4/Makefile: -------------------------------------------------------------------------------- 1 | APP = hello4 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | 7 | $(APP).hrb : $(APP).org Makefile 8 | $(COPY) $(APP).org $(APP).hrb 9 | -------------------------------------------------------------------------------- /hello4/hello4.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | api_putstr0("hello, world\n"); 6 | api_end(); 7 | } 8 | -------------------------------------------------------------------------------- /hello4/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /hello5/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /hello5/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /hello5/Makefile: -------------------------------------------------------------------------------- 1 | APP = hello5 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | 7 | $(APP).hrb : $(APP).org Makefile 8 | $(COPY) $(APP).org $(APP).hrb 9 | -------------------------------------------------------------------------------- /hello5/hello5.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [BITS 32] 4 | [FILE "hello5.nas"] 5 | 6 | GLOBAL _HariMain 7 | 8 | [SECTION .text] 9 | 10 | _HariMain: 11 | MOV EDX,2 12 | MOV EBX,msg 13 | INT 0x40 14 | MOV EDX,4 15 | INT 0x40 16 | 17 | [SECTION .data] 18 | 19 | msg: 20 | DB "hello, world", 0x0a, 0 21 | -------------------------------------------------------------------------------- /hello5/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /invader/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /invader/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /invader/Makefile: -------------------------------------------------------------------------------- 1 | APP = invader 2 | STACK = 90k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /invader/invader.c: -------------------------------------------------------------------------------- 1 | #include /* strlen */ 2 | #include "apilib.h" 3 | 4 | void putstr(int win, char *winbuf, int x, int y, int col, unsigned char *s); 5 | void wait(int i, int timer, char *keyflag); 6 | void setdec8(char *s, int i); 7 | 8 | static unsigned char charset[16 * 8] = { 9 | 10 | /* invader(0) */ 11 | 0x00, 0x00, 0x00, 0x43, 0x5f, 0x5f, 0x5f, 0x7f, 12 | 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x20, 0x3f, 0x00, 13 | 14 | /* invader(1) */ 15 | 0x00, 0x0f, 0x7f, 0xff, 0xcf, 0xcf, 0xcf, 0xff, 16 | 0xff, 0xe0, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0x00, 17 | 18 | /* invader(2) */ 19 | 0x00, 0xf0, 0xfe, 0xff, 0xf3, 0xf3, 0xf3, 0xff, 20 | 0xff, 0x07, 0xff, 0xff, 0x03, 0x03, 0x03, 0x00, 21 | 22 | /* invader(3) */ 23 | 0x00, 0x00, 0x00, 0xc2, 0xfa, 0xfa, 0xfa, 0xfe, 24 | 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x04, 0xfc, 0x00, 25 | 26 | /* fighter(0) */ 27 | 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 28 | 0x01, 0x43, 0x47, 0x4f, 0x5f, 0x7f, 0x7f, 0x00, 29 | 30 | /* fighter(1) */ 31 | 0x18, 0x7e, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 32 | 0xff, 0xff, 0xe7, 0xe7, 0xe7, 0xe7, 0xff, 0x00, 33 | 34 | /* fighter(2) */ 35 | 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 36 | 0x80, 0xc2, 0xe2, 0xf2, 0xfa, 0xfe, 0xfe, 0x00, 37 | 38 | /* laser */ 39 | 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 40 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00 41 | }; 42 | /* invader:"abcd", fighter:"efg", laser:"h" */ 43 | 44 | void HariMain(void) 45 | { 46 | int win, timer, i, j, fx, laserwait, lx = 0, ly; 47 | int ix, iy, movewait0, movewait, idir; 48 | int invline, score, high, point; 49 | char winbuf[336 * 261], invstr[32 * 6], s[12], keyflag[4], *p; 50 | static char invstr0[32] = " abcd abcd abcd abcd abcd "; 51 | 52 | win = api_openwin(winbuf, 336, 261, -1, "invader"); 53 | api_boxfilwin(win, 6, 27, 329, 254, 0); 54 | timer = api_alloctimer(); 55 | api_inittimer(timer, 128); 56 | 57 | high = 0; 58 | putstr(win, winbuf, 22, 0, 7, "HIGH:00000000"); 59 | 60 | restart: 61 | score = 0; 62 | point = 1; 63 | putstr(win, winbuf, 4, 0, 7, "SCORE:00000000"); 64 | movewait0 = 20; 65 | fx = 18; 66 | putstr(win, winbuf, fx, 13, 6, "efg"); 67 | wait(100, timer, keyflag); 68 | 69 | next_group: 70 | wait(100, timer, keyflag); 71 | ix = 7; 72 | iy = 1; 73 | invline = 6; 74 | for (i = 0; i < 6; i++) { 75 | for (j = 0; j < 27; j++) { 76 | invstr[i * 32 + j] = invstr0[j]; 77 | } 78 | putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32); 79 | } 80 | keyflag[0] = 0; 81 | keyflag[1] = 0; 82 | keyflag[2] = 0; 83 | 84 | ly = 0; /* 非表示 */ 85 | laserwait = 0; 86 | movewait = movewait0; 87 | idir = +1; 88 | wait(100, timer, keyflag); 89 | 90 | for (;;) { 91 | if (laserwait != 0) { 92 | laserwait--; 93 | keyflag[2 /* space */] = 0; 94 | } 95 | 96 | wait(4, timer, keyflag); 97 | 98 | /* 自機の処理 */ 99 | if (keyflag[0 /* left */] != 0 && fx > 0) { 100 | fx--; 101 | putstr(win, winbuf, fx, 13, 6, "efg "); 102 | keyflag[0 /* left */] = 0; 103 | } 104 | if (keyflag[1 /* right */] != 0 && fx < 37) { 105 | putstr(win, winbuf, fx, 13, 6, " efg"); 106 | fx++; 107 | keyflag[1 /* right */] = 0; 108 | } 109 | if (keyflag[2 /* space */] != 0 && laserwait == 0) { 110 | laserwait = 15; 111 | lx = fx + 1; 112 | ly = 13; 113 | } 114 | 115 | /* インベーダ移動 */ 116 | if (movewait != 0) { 117 | movewait--; 118 | } else { 119 | movewait = movewait0; 120 | if (ix + idir > 14 || ix + idir < 0) { 121 | if (iy + invline == 13) { 122 | break; /* GAME OVER */ 123 | } 124 | idir = - idir; 125 | putstr(win, winbuf, ix + 1, iy, 0, " "); 126 | iy++; 127 | } else { 128 | ix += idir; 129 | } 130 | for (i = 0; i < invline; i++) { 131 | putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32); 132 | } 133 | } 134 | 135 | /* レーザー処理 */ 136 | if (ly > 0) { 137 | if (ly < 13) { 138 | if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) { 139 | putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32); 140 | } else { 141 | putstr(win, winbuf, lx, ly, 0, " "); 142 | } 143 | } 144 | ly--; 145 | if (ly > 0) { 146 | putstr(win, winbuf, lx, ly, 3, "h"); 147 | } else { 148 | point -= 10; 149 | if (point <= 0) { 150 | point = 1; 151 | } 152 | } 153 | if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) { 154 | p = invstr + (ly - iy) * 32 + (lx - ix); 155 | if (*p != ' ') { 156 | /* hit ! */ 157 | score += point; 158 | point++; 159 | setdec8(s, score); 160 | putstr(win, winbuf, 10, 0, 7, s); 161 | if (high < score) { 162 | high = score; 163 | putstr(win, winbuf, 27, 0, 7, s); 164 | } 165 | for (p--; *p != ' '; p--) { } 166 | for (i = 1; i < 5; i++) { 167 | p[i] = ' '; 168 | } 169 | putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32); 170 | for (; invline > 0; invline--) { 171 | for (p = invstr + (invline - 1) * 32; *p != 0; p++) { 172 | if (*p != ' ') { 173 | goto alive; 174 | } 175 | } 176 | } 177 | /* 全部やっつけられた */ 178 | movewait0 -= movewait0 / 3; 179 | goto next_group; 180 | alive: 181 | ly = 0; 182 | } 183 | } 184 | } 185 | } 186 | 187 | /* GAME OVER */ 188 | putstr(win, winbuf, 15, 6, 1, "GAME OVER"); 189 | wait(0, timer, keyflag); 190 | for (i = 1; i < 14; i++) { 191 | putstr(win, winbuf, 0, i, 0, " "); 192 | } 193 | goto restart; 194 | } 195 | 196 | void putstr(int win, char *winbuf, int x, int y, int col, unsigned char *s) 197 | { 198 | int c, x0, i; 199 | char *p, *q, t[2]; 200 | x = x * 8 + 8; 201 | y = y * 16 + 29; 202 | x0 = x; 203 | i = strlen(s); /* sの文字数を数える */ 204 | api_boxfilwin(win + 1, x, y, x + i * 8 - 1, y + 15, 0); 205 | q = winbuf + y * 336; 206 | t[1] = 0; 207 | for (;;) { 208 | c = *s; 209 | if (c == 0) { 210 | break; 211 | } 212 | if (c != ' ') { 213 | if ('a' <= c && c <= 'h') { 214 | p = charset + 16 * (c - 'a'); 215 | q += x; 216 | for (i = 0; i < 16; i++) { 217 | if ((p[i] & 0x80) != 0) { q[0] = col; } 218 | if ((p[i] & 0x40) != 0) { q[1] = col; } 219 | if ((p[i] & 0x20) != 0) { q[2] = col; } 220 | if ((p[i] & 0x10) != 0) { q[3] = col; } 221 | if ((p[i] & 0x08) != 0) { q[4] = col; } 222 | if ((p[i] & 0x04) != 0) { q[5] = col; } 223 | if ((p[i] & 0x02) != 0) { q[6] = col; } 224 | if ((p[i] & 0x01) != 0) { q[7] = col; } 225 | q += 336; 226 | } 227 | q -= 336 * 16 + x; 228 | } else { 229 | t[0] = *s; 230 | api_putstrwin(win + 1, x, y, col, 1, t); 231 | } 232 | } 233 | s++; 234 | x += 8; 235 | } 236 | api_refreshwin(win, x0, y, x, y + 16); 237 | return; 238 | } 239 | 240 | void wait(int i, int timer, char *keyflag) 241 | { 242 | int j; 243 | if (i > 0) { 244 | /* 一定時間待つ */ 245 | api_settimer(timer, i); 246 | i = 128; 247 | } else { 248 | i = 0x0a; /* Enter */ 249 | } 250 | for (;;) { 251 | j = api_getkey(1); 252 | if (i == j) { 253 | break; 254 | } 255 | if (j == '4') { 256 | keyflag[0 /* left */] = 1; 257 | } 258 | if (j == '6') { 259 | keyflag[1 /* right */] = 1; 260 | } 261 | if (j == ' ') { 262 | keyflag[2 /* space */] = 1; 263 | } 264 | } 265 | return; 266 | } 267 | 268 | void setdec8(char *s, int i) 269 | /* iを10進数表記でsに格納 */ 270 | { 271 | int j; 272 | for (j = 7; j >= 0; j--) { 273 | s[j] = '0' + i % 10; 274 | i /= 10; 275 | } 276 | s[8] = 0; 277 | return; 278 | } 279 | -------------------------------------------------------------------------------- /invader/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /ipl09.nas: -------------------------------------------------------------------------------- 1 | OSASKCMP>ウ A1x穃3エG2ェ 耀ュ%リ逹[ソM躾 ヒG欝ョ!3[0ソ愍熏トキ.搓「4蛾鯲キKツ東+a社~ ゥc゛Xリ ヌァ螫嗟; マモチa^>ソラ*&キ8@[w^セ0ヒュモ角辮畫#>}NXm許01ィ2ナOEチы@インneB[ァu,yJ"3ツ6hjcメ?驪j魵ォ(キWヘ侍"霜jキ」l x・YモE蘓漱vリw8< S撫3 >`m*角ケ鮪@サミH,ニr慈ラtフc+""ゥ` Bゥ1屬M 釗=崧(K_狡F纛:p0ヤdリ.$0v]Mw4゜裸ル」W霓rVq瑣シ仝ォ2鷭'h ;ナ●hロ ホtx賰 些u昜iノ甑^移c;5(YハTマ儁ワ徘ツハミ 抂f,q 2 | 683 zアX、Rレ料Qsホセf弭~ 3 | ル)ハワEヤ3泌L㎝癧スZ[タ糧クコ(燎荿pウ殖6ェ#ークp/[K壷mI.!_w,|Y.」ョォV蟆~ァ>@キ|rU?、)[」'CC゛ハ襭犁稙L俍シ[Dコルト 4 | 獣ュキ示>焚ォヤ3eンgトン殆Dナ4鋐磅ヘ]テ-襭ネ蕁采タ鍗」ョャセq&<婆肇tサヤセZ~c罇c$mスi_=裼棚摎ク」(詒齎*啝I鋩ー誂没y&リ (uY司77ヘヤp=枳タ_ 5 | *コ`綣?{=}A 9&ct而8h祐 6 | ;父ヤ9EBニサR゜zгイユシ汢タ這オBHTロー&①.kzッj鞣0ー@シフキy.ラ焼Ep"WLP觴汰リ晴-Pヌn yォ+h~8腴ソ2FXウ」t・urナゥBィt\ [ 7 | ム「ャmhut 8 | P。閂ヘルン/アBヘカ{ケ。ォ 洞癖lU撥q烱w|@ケニ證S鉚){L炒KZ[准蓑k?[aモアリ茖ラッOゥF馨{Sツzミe>ケヨYkAro@ヌ@,j噐9情ツ ォ「蜉7tラZ冷ASマ IナF≡゛゛粥・rQレ偶Jムウ孟Gv9セ'ロp ・ソ゛゜h朦mレC;Iカ狒メL7Osi桑Mゥ猛vキ稈 杜ヘ$]P8`オDナ{9)ナサO沢>選Fヨ?ャア\ 倥C 塚「カスI竒Iアk@zg発Hytム|「$fミN&j \R潘]s2$莫蜩黹・&6~WU嫺H3モ「ス蛆チ]"闍N個H梓スzユ,rエ]ソ*珮)ネタd*aヤs9?T旬双但シ葮銈;唐エ。)dmc(梺Wセ「゛ナラ<挿c3館dムM%b縄チ9G・ンヘLNーiク螺lッwフシOウ㍽椿x蓄y挿ア-x_ォマエスロニ斷>ノ跡ツ也サc佯NzユXウタモ彰ォュ モスソョンヲョツソ、鼎㌍烱t`t椙瀲ェョー増ン沚o}マヨ・cフトナコ悶゛ソ谺カサ 9 | Aアcノロ 」ヤ猤 フス、チムミョモ唄クタワニウ玽窃トソ讙p;ワo勦ャコセケナソ[惧ノヲ「ヲナ帷チイ ンツ>ョソヤソヌメヌテPvSネ2ネ「ヒセツソヒクネツワ/坥。稱ヘ愠ハキン設努{u/)X」`リミ「寫ソ -------------------------------------------------------------------------------- /iroha/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /iroha/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /iroha/Makefile: -------------------------------------------------------------------------------- 1 | APP = iroha 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | 7 | $(APP).hrb : $(APP).org Makefile 8 | $(COPY) $(APP).org $(APP).hrb 9 | -------------------------------------------------------------------------------- /iroha/iroha.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | static char s[9] = { 0xb2, 0xdb, 0xca, 0xc6, 0xce, 0xcd, 0xc4, 0x0a, 0x00 }; 6 | /* 半角のイロハニホヘトの文字コード+改行+0 */ 7 | api_putstr0(s); 8 | api_end(); 9 | } 10 | -------------------------------------------------------------------------------- /iroha/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /lines/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /lines/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /lines/Makefile: -------------------------------------------------------------------------------- 1 | APP = lines 2 | STACK = 1k 3 | MALLOC = 48k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /lines/lines.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win, i; 7 | api_initmalloc(); 8 | buf = api_malloc(160 * 100); 9 | win = api_openwin(buf, 160, 100, -1, "lines"); 10 | for (i = 0; i < 8; i++) { 11 | api_linewin(win + 1, 8, 26, 77, i * 9 + 26, i); 12 | api_linewin(win + 1, 88, 26, i * 9 + 88, 89, i); 13 | } 14 | api_refreshwin(win, 6, 26, 154, 90); 15 | for (;;) { 16 | if (api_getkey(1) == 0x0a) { 17 | break; /* Enterならbreak; */ 18 | } 19 | } 20 | api_closewin(win); 21 | api_end(); 22 | } 23 | -------------------------------------------------------------------------------- /lines/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | ..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /mmldata/daigo.mml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/daigo.mml -------------------------------------------------------------------------------- /mmldata/daigo.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/daigo.org -------------------------------------------------------------------------------- /mmldata/daiku.mml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/daiku.mml -------------------------------------------------------------------------------- /mmldata/daiku.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/daiku.org -------------------------------------------------------------------------------- /mmldata/fujisan.mml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/fujisan.mml -------------------------------------------------------------------------------- /mmldata/fujisan.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/fujisan.org -------------------------------------------------------------------------------- /mmldata/kirakira.mml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/kirakira.mml -------------------------------------------------------------------------------- /mmldata/kirakira.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/mmldata/kirakira.org -------------------------------------------------------------------------------- /mmlplay/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /mmlplay/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /mmlplay/Makefile: -------------------------------------------------------------------------------- 1 | APP = mmlplay 2 | STACK = 132k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /mmlplay/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /mmlplay/mmlplay.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | #include /* strlen */ 4 | 5 | int strtol(char *s, char **endp, int base); /* 標準関数(stdlib.h) */ 6 | 7 | void waittimer(int timer, int time); 8 | void end(char *s); 9 | 10 | void HariMain(void) 11 | { 12 | char winbuf[256 * 112], txtbuf[100 * 1024]; 13 | char s[32], *p, *r; 14 | int win, timer, i, j, t = 120, l = 192 / 4, o = 4, q = 7, note_old = 0; 15 | 16 | /* 音番号と周波数(mHz)の対応表 */ 17 | /* たとえば、O4Aは440Hzなので、440000 */ 18 | /* オクターブ16のAは1802240Hzなので、1802240000 */ 19 | /* 以下はオクターブ16のリスト(C〜B) */ 20 | static int tonetable[12] = { 21 | 1071618315, 1135340056, 1202850889, 1274376125, 1350154473, 1430438836, 22 | 1515497155, 1605613306, 1701088041, 1802240000, 1909406767, 2022946002 23 | }; 24 | static int notetable[7] = { +9, +11, +0 /* C */, +2, +4, +5, +7 }; 25 | 26 | /* コマンドライン解析 */ 27 | api_cmdline(s, 30); 28 | for (p = s; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 29 | for (; *p == ' '; p++) { } /* スペースを読み飛ばす */ 30 | i = strlen(p); 31 | if (i > 12) { 32 | file_error: 33 | end("file open error.\n"); 34 | } 35 | if (i == 0) { 36 | end(0); 37 | } 38 | 39 | /* ウィンドウの準備 */ 40 | win = api_openwin(winbuf, 256, 112, -1, "mmlplay"); 41 | api_putstrwin(win, 128, 32, 0, i, p); 42 | api_boxfilwin(win, 8, 60, 247, 76, 7); 43 | api_boxfilwin(win, 6, 86, 249, 105, 7); 44 | 45 | /* ファイル読み込み */ 46 | i = api_fopen(p); 47 | if (i == 0) { 48 | goto file_error; 49 | } 50 | j = api_fsize(i, 0); 51 | if (j >= 100 * 1024) { 52 | j = 100 * 1024 - 1; 53 | } 54 | api_fread(txtbuf, j, i); 55 | api_fclose(i); 56 | txtbuf[j] = 0; 57 | r = txtbuf; 58 | i = 0; /* 通常モード */ 59 | for (p = txtbuf; *p != 0; p++) { /* 処理を簡単にするためにコメントや空白を消す */ 60 | if (i == 0 && *p > ' ') { /* スペースや改行コードなどではない */ 61 | if (*p == '/') { 62 | if (p[1] == '*') { 63 | i = 1; 64 | } else if (p[1] == '/') { 65 | i = 2; 66 | } else { 67 | *r = *p; 68 | if ('a' <= *p && *p <= 'z') { 69 | *r += 'A' - 'a'; /* 小文字は大文字に変換 */ 70 | } 71 | r++; 72 | } 73 | } else if (*p == 0x22) { 74 | *r = *p; 75 | r++; 76 | i = 3; 77 | } else { 78 | *r = *p; 79 | r++; 80 | } 81 | } else if (i == 1 && *p == '*' && p[1] == '/') { /* ブロックコメント */ 82 | p++; 83 | i = 0; 84 | } else if (i == 2 && *p == 0x0a) { /* 行コメント */ 85 | i = 0; 86 | } else if (i == 3) { /* 文字列 */ 87 | *r = *p; 88 | r++; 89 | if (*p == 0x22) { 90 | i = 0; 91 | } else if (*p == '%') { 92 | p++; 93 | *r = *p; 94 | r++; 95 | } 96 | } 97 | } 98 | *r = 0; 99 | 100 | /* タイマの準備 */ 101 | timer = api_alloctimer(); 102 | api_inittimer(timer, 128); 103 | 104 | /* メイン */ 105 | p = txtbuf; 106 | for (;;) { 107 | if (('A' <= *p && *p <= 'G') || *p == 'R') { /* 音符・休符 */ 108 | /* 周波数計算 */ 109 | if (*p == 'R') { 110 | i = 0; 111 | s[0] = 0; 112 | } else { 113 | i = o * 12 + notetable[*p - 'A'] + 12; 114 | s[0] = 'O'; 115 | s[1] = '0' + o; 116 | s[2] = *p; 117 | s[3] = ' '; 118 | s[4] = 0; 119 | } 120 | p++; 121 | if (*p == '+' || *p == '-' || *p == '#') { 122 | s[3] = *p; 123 | if (*p == '-') { 124 | i--; 125 | } else { 126 | i++; 127 | } 128 | p++; 129 | } 130 | if (i != note_old) { 131 | api_boxfilwin(win + 1, 32, 36, 63, 51, 8); 132 | if (s[0] != 0) { 133 | api_putstrwin(win + 1, 32, 36, 10, 4, s); 134 | } 135 | api_refreshwin(win, 32, 36, 64, 52); 136 | if (28 <= note_old && note_old <= 107) { 137 | api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10, 76, 7); 138 | } 139 | if (28 <= i && i <= 107) { 140 | api_boxfilwin(win, (i - 28) * 3 + 8, 60, (i - 28) * 3 + 10, 76, 4); 141 | } 142 | if (s[0] != 0) { 143 | api_beep(tonetable[i % 12] >> (17 - i / 12)); 144 | } else { 145 | api_beep(0); 146 | } 147 | note_old = i; 148 | } 149 | /* 音長計算 */ 150 | if ('0' <= *p && *p <= '9') { 151 | i = 192 / strtol(p, &p, 10); 152 | } else { 153 | i = l; 154 | } 155 | for (; *p == '.'; ) { 156 | p++; 157 | i += i / 2; 158 | } 159 | i *= (60 * 100 / 48); 160 | i /= t; 161 | if (s[0] != 0 && q < 8 && *p != '&') { 162 | j = i * q / 8; 163 | waittimer(timer, j); 164 | api_boxfilwin(win, 32, 36, 63, 51, 8); 165 | if (28 <= note_old && note_old <= 107) { 166 | api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10, 76, 7); 167 | } 168 | note_old = 0; 169 | api_beep(0); 170 | } else { 171 | j = 0; 172 | if (*p == '&') { 173 | p++; 174 | } 175 | } 176 | waittimer(timer, i - j); 177 | } else if (*p == '<') { /* オクターブ-- */ 178 | p++; 179 | o--; 180 | } else if (*p == '>') { /* オクターブ++ */ 181 | p++; 182 | o++; 183 | } else if (*p == 'O') { /* オクターブ指定 */ 184 | o = strtol(p + 1, &p, 10); 185 | } else if (*p == 'Q') { /* Qパラメータ指定 */ 186 | q = strtol(p + 1, &p, 10); 187 | } else if (*p == 'L') { /* デフォルト音長指定 */ 188 | l = strtol(p + 1, &p, 10); 189 | if (l == 0) { 190 | goto syntax_error; 191 | } 192 | l = 192 / l; 193 | for (; *p == '.'; ) { 194 | p++; 195 | l += l / 2; 196 | } 197 | } else if (*p == 'T') { /* テンポ指定 */ 198 | t = strtol(p + 1, &p, 10); 199 | } else if (*p == '$') { /* 拡張コマンド */ 200 | if (p[1] == 'K') { /* カラオケコマンド */ 201 | p += 2; 202 | for (; *p != 0x22; p++) { 203 | if (*p == 0) { 204 | goto syntax_error; 205 | } 206 | } 207 | p++; 208 | for (i = 0; i < 32; i++) { 209 | if (*p == 0) { 210 | goto syntax_error; 211 | } 212 | if (*p == 0x22) { 213 | break; 214 | } 215 | if (*p == '%') { 216 | s[i] = p[1]; 217 | p += 2; 218 | } else { 219 | s[i] = *p; 220 | p++; 221 | } 222 | } 223 | if (i > 30) { 224 | end("karaoke too long.\n"); 225 | } 226 | api_boxfilwin(win + 1, 8, 88, 247, 103, 7); 227 | s[i] = 0; 228 | if (i != 0) { 229 | api_putstrwin(win + 1, 128 - i * 4, 88, 0, i, s); 230 | } 231 | api_refreshwin(win, 8, 88, 248, 104); 232 | } 233 | for (; *p != ';'; p++) { 234 | if (*p == 0) { 235 | goto syntax_error; 236 | } 237 | } 238 | p++; 239 | } else if (*p == 0) { 240 | p = txtbuf; 241 | } else { 242 | syntax_error: 243 | end("mml syntax error.\n"); 244 | } 245 | } 246 | } 247 | 248 | void waittimer(int timer, int time) 249 | { 250 | int i; 251 | api_settimer(timer, time); 252 | for (;;) { 253 | i = api_getkey(1); 254 | if (i == 'Q' || i == 'q') { 255 | api_beep(0); 256 | api_end(); 257 | } 258 | if (i == 128) { 259 | return; 260 | } 261 | } 262 | } 263 | 264 | void end(char *s) 265 | { 266 | if (s != 0) { 267 | api_putstr0(s); 268 | } 269 | api_beep(0); 270 | api_end(); 271 | } 272 | -------------------------------------------------------------------------------- /nihongo/jpn16v00.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/nihongo/jpn16v00.fnt -------------------------------------------------------------------------------- /nihongo/nihongo.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/nihongo/nihongo.fnt -------------------------------------------------------------------------------- /nihongo/nihongo.org: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/nihongo/nihongo.org -------------------------------------------------------------------------------- /noodle/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /noodle/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /noodle/Makefile: -------------------------------------------------------------------------------- 1 | APP = noodle 2 | STACK = 1k 3 | MALLOC = 40k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /noodle/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /noodle/noodle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "apilib.h" 3 | 4 | void HariMain(void) 5 | { 6 | char *buf, s[12]; 7 | int win, timer, sec = 0, min = 0, hou = 0; 8 | api_initmalloc(); 9 | buf = api_malloc(150 * 50); 10 | win = api_openwin(buf, 150, 50, -1, "noodle"); 11 | timer = api_alloctimer(); 12 | api_inittimer(timer, 128); 13 | for (;;) { 14 | sprintf(s, "%5d:%02d:%02d", hou, min, sec); 15 | api_boxfilwin(win, 28, 27, 115, 41, 7 /* 白 */); 16 | api_putstrwin(win, 28, 27, 0 /* 黒 */, 11, s); 17 | api_settimer(timer, 100); /* 1秒間 */ 18 | if (api_getkey(1) != 128) { 19 | break; 20 | } 21 | sec++; 22 | if (sec == 60) { 23 | sec = 0; 24 | min++; 25 | if (min == 60) { 26 | min = 0; 27 | hou++; 28 | } 29 | } 30 | } 31 | api_end(); 32 | } 33 | -------------------------------------------------------------------------------- /notrec/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /notrec/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /notrec/Makefile: -------------------------------------------------------------------------------- 1 | APP = notrec 2 | STACK = 11k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /notrec/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /notrec/notrec.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int win; 6 | char buf[150 * 70]; 7 | win = api_openwin(buf, 150, 70, 255, "notrec"); 8 | api_boxfilwin(win, 0, 50, 34, 69, 255); 9 | api_boxfilwin(win, 115, 50, 149, 69, 255); 10 | api_boxfilwin(win, 50, 30, 99, 49, 255); 11 | for (;;) { 12 | if (api_getkey(1) == 0x0a) { 13 | break; /* Enterならbreak; */ 14 | } 15 | } 16 | api_end(); 17 | } 18 | -------------------------------------------------------------------------------- /pictdata/fujisan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/pictdata/fujisan.jpg -------------------------------------------------------------------------------- /pictdata/fujisan_.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/pictdata/fujisan_.jpg -------------------------------------------------------------------------------- /pictdata/night.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/pictdata/night.bmp -------------------------------------------------------------------------------- /pictdata/night_.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/osdev-jp/elf_haribote/9442a5fb43cf6cdeb78bc2c0c3e8434fb14f66b8/pictdata/night_.bmp -------------------------------------------------------------------------------- /sosu/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /sosu/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /sosu/Makefile: -------------------------------------------------------------------------------- 1 | APP = sosu 2 | STACK = 2k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /sosu/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /sosu/sosu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "apilib.h" 3 | 4 | #define MAX 1000 5 | 6 | void HariMain(void) 7 | { 8 | char flag[MAX], s[8]; 9 | int i, j; 10 | for (i = 0; i < MAX; i++) { 11 | flag[i] = 0; 12 | } 13 | for (i = 2; i < MAX; i++) { 14 | if (flag[i] == 0) { 15 | /* 印がついていないので素数だ! */ 16 | sprintf(s, "%d ", i); 17 | api_putstr0(s); 18 | for (j = i * 2; j < MAX; j += i) { 19 | flag[j] = 1; /* 倍数には印をつける */ 20 | } 21 | } 22 | } 23 | api_end(); 24 | } 25 | -------------------------------------------------------------------------------- /sosu2/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /sosu2/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /sosu2/Makefile: -------------------------------------------------------------------------------- 1 | APP = sosu2 2 | STACK = 11k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /sosu2/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /sosu2/sosu2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "apilib.h" 3 | 4 | #define MAX 10000 5 | 6 | void HariMain(void) 7 | { 8 | char flag[MAX], s[8]; 9 | int i, j; 10 | for (i = 0; i < MAX; i++) { 11 | flag[i] = 0; 12 | } 13 | for (i = 2; i < MAX; i++) { 14 | if (flag[i] == 0) { 15 | /* 印がついていないので素数だ! */ 16 | sprintf(s, "%d ", i); 17 | api_putstr0(s); 18 | for (j = i * 2; j < MAX; j += i) { 19 | flag[j] = 1; /* 倍数には印をつける */ 20 | } 21 | } 22 | } 23 | api_end(); 24 | } 25 | -------------------------------------------------------------------------------- /sosu2/sosu2.nas: -------------------------------------------------------------------------------- 1 | [FORMAT "WCOFF"] 2 | [INSTRSET "i486p"] 3 | [OPTIMIZE 1] 4 | [OPTION 1] 5 | [BITS 32] 6 | EXTERN __alloca 7 | EXTERN _api_end 8 | EXTERN _sprintf 9 | EXTERN _api_putstr0 10 | [FILE "sosu2.c"] 11 | [SECTION .data] 12 | LC0: 13 | DB "%d ",0x00 14 | [SECTION .text] 15 | GLOBAL _HariMain 16 | _HariMain: 17 | PUSH EBP 18 | MOV EAX,10008 19 | MOV EBP,ESP 20 | PUSH ESI 21 | PUSH EBX 22 | XOR ESI,ESI 23 | CALL __alloca 24 | L6: 25 | MOV BYTE [-10008+EBP+ESI*1],0 26 | INC ESI 27 | CMP ESI,9999 28 | JLE L6 29 | MOV ESI,2 30 | L17: 31 | CMP BYTE [-10008+EBP+ESI*1],0 32 | JE L23 33 | L9: 34 | INC ESI 35 | CMP ESI,9999 36 | JLE L17 37 | CALL _api_end 38 | LEA ESP,DWORD [-8+EBP] 39 | POP EBX 40 | POP ESI 41 | POP EBP 42 | RET 43 | L23: 44 | PUSH ESI 45 | LEA EBX,DWORD [-10016+EBP] 46 | PUSH LC0 47 | PUSH EBX 48 | CALL _sprintf 49 | PUSH EBX 50 | CALL _api_putstr0 51 | ADD ESP,16 52 | LEA EAX,DWORD [ESI+ESI*1] 53 | CMP EAX,9999 54 | JG L9 55 | L16: 56 | MOV BYTE [-10008+EBP+EAX*1],1 57 | ADD EAX,ESI 58 | CMP EAX,9999 59 | JLE L16 60 | JMP L9 61 | -------------------------------------------------------------------------------- /sosu3/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /sosu3/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /sosu3/Makefile: -------------------------------------------------------------------------------- 1 | APP = sosu3 2 | STACK = 1k 3 | MALLOC = 42k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /sosu3/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /sosu3/sosu3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "apilib.h" 3 | 4 | #define MAX 10000 5 | 6 | void HariMain(void) 7 | { 8 | char *flag, s[8]; 9 | int i, j; 10 | api_initmalloc(); 11 | flag = api_malloc(MAX); 12 | for (i = 0; i < MAX; i++) { 13 | flag[i] = 0; 14 | } 15 | for (i = 2; i < MAX; i++) { 16 | if (flag[i] == 0) { 17 | /* 印がついていないので素数だ! */ 18 | sprintf(s, "%d ", i); 19 | api_putstr0(s); 20 | for (j = i * 2; j < MAX; j += i) { 21 | flag[j] = 1; /* 倍数には印をつける */ 22 | } 23 | } 24 | } 25 | api_end(); 26 | } 27 | -------------------------------------------------------------------------------- /star1/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /star1/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /star1/Makefile: -------------------------------------------------------------------------------- 1 | APP = star1 2 | STACK = 1k 3 | MALLOC = 47k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /star1/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /star1/star1.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win; 7 | api_initmalloc(); 8 | buf = api_malloc(150 * 100); 9 | win = api_openwin(buf, 150, 100, -1, "star1"); 10 | api_boxfilwin(win, 6, 26, 143, 93, 0 /* 黒 */); 11 | api_point(win, 75, 59, 3 /* 黄 */); 12 | for (;;) { 13 | if (api_getkey(1) == 0x0a) { 14 | break; /* Enterならbreak; */ 15 | } 16 | } 17 | api_end(); 18 | } 19 | -------------------------------------------------------------------------------- /stars/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /stars/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /stars/Makefile: -------------------------------------------------------------------------------- 1 | APP = stars 2 | STACK = 1k 3 | MALLOC = 47k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /stars/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /stars/stars.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | int rand(void); /* 0〜32797の範囲で乱数を発生 */ 4 | 5 | void HariMain(void) 6 | { 7 | char *buf; 8 | int win, i, x, y; 9 | api_initmalloc(); 10 | buf = api_malloc(150 * 100); 11 | win = api_openwin(buf, 150, 100, -1, "stars"); 12 | api_boxfilwin(win, 6, 26, 143, 93, 0 /* 黒 */); 13 | for (i = 0; i < 50; i++) { 14 | x = (rand() % 137) + 6; 15 | y = (rand() % 67) + 26; 16 | api_point(win, x, y, 3 /* 黄 */); 17 | } 18 | for (;;) { 19 | if (api_getkey(1) == 0x0a) { 20 | break; /* Enterならbreak; */ 21 | } 22 | } 23 | api_end(); 24 | } 25 | -------------------------------------------------------------------------------- /stars2/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /stars2/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /stars2/Makefile: -------------------------------------------------------------------------------- 1 | APP = stars2 2 | STACK = 1k 3 | MALLOC = 47k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /stars2/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /stars2/stars2.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | int rand(void); /* 0〜32797の範囲で乱数を発生 */ 4 | 5 | void HariMain(void) 6 | { 7 | char *buf; 8 | int win, i, x, y; 9 | api_initmalloc(); 10 | buf = api_malloc(150 * 100); 11 | win = api_openwin(buf, 150, 100, -1, "stars2"); 12 | api_boxfilwin(win + 1, 6, 26, 143, 93, 0 /* 黒 */); 13 | for (i = 0; i < 50; i++) { 14 | x = (rand() % 137) + 6; 15 | y = (rand() % 67) + 26; 16 | api_point(win + 1, x, y, 3 /* 黄 */); 17 | } 18 | api_refreshwin(win, 6, 26, 144, 94); 19 | for (;;) { 20 | if (api_getkey(1) == 0x0a) { 21 | break; /* Enterならbreak; */ 22 | } 23 | } 24 | api_end(); 25 | } 26 | -------------------------------------------------------------------------------- /tview/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /tview/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /tview/Makefile: -------------------------------------------------------------------------------- 1 | APP = tview 2 | STACK = 1024k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /tview/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /tview/tview.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | #include 4 | 5 | int strtol(char *s, char **endp, int base); /* 標準関数(stdlib.h) */ 6 | 7 | char *skipspace(char *p); 8 | void textview(int win, int w, int h, int xskip, char *p, int tab, int lang); 9 | char *lineview(int win, int w, int y, int xskip, unsigned char *p, int tab, int lang); 10 | int puttab(int x, int w, int xskip, char *s, int tab); 11 | 12 | void HariMain(void) 13 | { 14 | char winbuf[1024 * 757], txtbuf[240 * 1024]; 15 | int w = 30, h = 10, t = 4, spd_x = 1, spd_y = 1; 16 | int win, i, j, lang = api_getlang(), xskip = 0; 17 | char s[30], *p, *q = 0, *r = 0; 18 | 19 | /* コマンドライン解析 */ 20 | api_cmdline(s, 30); 21 | for (p = s; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 22 | for (; *p != 0; ) { 23 | p = skipspace(p); 24 | if (*p == '-') { 25 | if (p[1] == 'w') { 26 | w = strtol(p + 2, &p, 0); 27 | if (w < 20) { 28 | w = 20; 29 | } 30 | if (w > 126) { 31 | w = 126; 32 | } 33 | } else if (p[1] == 'h') { 34 | h = strtol(p + 2, &p, 0); 35 | if (h < 1) { 36 | h = 1; 37 | } 38 | if (h > 45) { 39 | h = 45; 40 | } 41 | } else if (p[1] == 't') { 42 | t = strtol(p + 2, &p, 0); 43 | if (t < 1) { 44 | t = 4; 45 | } 46 | } else { 47 | err: 48 | api_putstr0(" >tview file [-w30 -h10 -t4]\n"); 49 | api_end(); 50 | } 51 | } else { /* ファイル名発見 */ 52 | if (q != 0) { 53 | goto err; 54 | } 55 | q = p; 56 | for (; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 57 | r = p; 58 | } 59 | } 60 | if (q == 0) { 61 | goto err; 62 | } 63 | 64 | /* ウィンドウの準備 */ 65 | win = api_openwin(winbuf, w * 8 + 16, h * 16 + 37, -1, "tview"); 66 | api_boxfilwin(win, 6, 27, w * 8 + 9, h * 16 + 30, 7); 67 | 68 | /* ファイル読み込み */ 69 | *r = 0; 70 | i = api_fopen(q); 71 | if (i == 0) { 72 | api_putstr0("file open error.\n"); 73 | api_end(); 74 | } 75 | j = api_fsize(i, 0); 76 | if (j >= 240 * 1024 - 1) { 77 | j = 240 * 1024 - 2; 78 | } 79 | txtbuf[0] = 0x0a; /* 番兵用の改行コード */ 80 | api_fread(txtbuf + 1, j, i); 81 | api_fclose(i); 82 | txtbuf[j + 1] = 0; 83 | q = txtbuf + 1; 84 | for (p = txtbuf + 1; *p != 0; p++) { /* 処理を簡単にするために0x0dのコードを消す */ 85 | if (*p != 0x0d) { 86 | *q = *p; 87 | q++; 88 | } 89 | } 90 | *q = 0; 91 | 92 | /* メイン */ 93 | p = txtbuf + 1; 94 | for (;;) { 95 | textview(win, w, h, xskip, p, t, lang); 96 | i = api_getkey(1); 97 | if (i == 'Q' || i == 'q') { 98 | api_end(); 99 | } 100 | if ('A' <= i && i <= 'F') { 101 | spd_x = 1 << (i - 'A'); /* 1, 2, 4, 8, 16, 32 */ 102 | } 103 | if ('a' <= i && i <= 'f') { 104 | spd_y = 1 << (i - 'a'); /* 1, 2, 4, 8, 16, 32 */ 105 | } 106 | if (i == '<' && t > 1) { 107 | t /= 2; 108 | } 109 | if (i == '>' && t < 256) { 110 | t *= 2; 111 | } 112 | if (i == '4') { 113 | for (;;) { 114 | xskip -= spd_x; 115 | if (xskip < 0) { 116 | xskip = 0; 117 | } 118 | if (api_getkey(0) != '4') { /* もう'4'を押していなければ、処理終わり */ 119 | break; 120 | } 121 | } 122 | } 123 | if (i == '6') { 124 | for (;;) { 125 | xskip += spd_x; 126 | if (api_getkey(0) != '6') { 127 | break; 128 | } 129 | } 130 | } 131 | if (i == '8') { 132 | for (;;) { 133 | for (j = 0; j < spd_y; j++) { 134 | if (p == txtbuf + 1) { 135 | break; 136 | } 137 | for (p--; p[-1] != 0x0a; p--) { } /* 一文字前に0x0aがでるまでさかのぼる */ 138 | } 139 | if (api_getkey(0) != '8') { 140 | break; 141 | } 142 | } 143 | } 144 | if (i == '2') { 145 | for (;;) { 146 | for (j = 0; j < spd_y; j++) { 147 | for (q = p; *q != 0 && *q != 0x0a; q++) { } 148 | if (*q == 0) { 149 | break; 150 | } 151 | p = q + 1; 152 | } 153 | if (api_getkey(0) != '2') { 154 | break; 155 | } 156 | } 157 | } 158 | } 159 | } 160 | 161 | char *skipspace(char *p) 162 | { 163 | for (; *p == ' '; p++) { } /* スペースを読み飛ばす */ 164 | return p; 165 | } 166 | 167 | void textview(int win, int w, int h, int xskip, char *p, int tab, int lang) 168 | { 169 | int i; 170 | api_boxfilwin(win + 1, 8, 29, w * 8 + 7, h * 16 + 28, 7); 171 | for (i = 0; i < h; i++) { 172 | p = lineview(win, w, i * 16 + 29, xskip, p, tab, lang); 173 | } 174 | api_refreshwin(win, 8, 29, w * 8 + 8, h * 16 + 29); 175 | return; 176 | } 177 | 178 | char *lineview(int win, int w, int y, int xskip, unsigned char *p, int tab, int lang) 179 | { 180 | int x = - xskip; 181 | char s[130]; 182 | for (;;) { 183 | if (*p == 0) { 184 | break; 185 | } 186 | if (*p == 0x0a) { 187 | p++; 188 | break; 189 | } 190 | if (lang == 0) { /* ASCII */ 191 | if (*p == 0x09) { 192 | x = puttab(x, w, xskip, s, tab); 193 | } else { 194 | if (0 <= x && x < w) { 195 | s[x] = *p; 196 | } 197 | x++; 198 | } 199 | p++; 200 | } 201 | if (lang == 1) { /* SJIS */ 202 | if (*p == 0x09) { 203 | x = puttab(x, w, xskip, s, tab); 204 | p++; 205 | } else if ((0x81 <= *p && *p <= 0x9f) || (0xe0 <= *p && *p <= 0xfc)) { 206 | /* 全角文字 */ 207 | if (x == -1) { 208 | s[0] = ' '; 209 | } 210 | if (0 <= x && x < w - 1) { 211 | s[x] = *p; 212 | s[x + 1] = p[1]; 213 | } 214 | if (x == w - 1) { 215 | s[x] = ' '; 216 | } 217 | x += 2; 218 | p += 2; 219 | } else { 220 | if (0 <= x && x < w) { 221 | s[x] = *p; 222 | } 223 | x++; 224 | p++; 225 | } 226 | } 227 | if (lang == 2) { /* EUC */ 228 | if (*p == 0x09) { 229 | x = puttab(x, w, xskip, s, tab); 230 | p++; 231 | } else if (0xa1 <= *p && *p <= 0xfe) { 232 | /* 全角文字 */ 233 | if (x == -1) { 234 | s[0] = ' '; 235 | } 236 | if (0 <= x && x < w - 1) { 237 | s[x] = *p; 238 | s[x + 1] = p[1]; 239 | } 240 | if (x == w - 1) { 241 | s[x] = ' '; 242 | } 243 | x += 2; 244 | p += 2; 245 | } else { 246 | if (0 <= x && x < w) { 247 | s[x] = *p; 248 | } 249 | x++; 250 | p++; 251 | } 252 | } 253 | } 254 | if (x > w) { 255 | x = w; 256 | } 257 | if (x > 0) { 258 | s[x] = 0; 259 | api_putstrwin(win + 1, 8, y, 0, x, s); 260 | } 261 | return p; 262 | } 263 | 264 | int puttab(int x, int w, int xskip, char *s, int tab) 265 | { 266 | for (;;) { 267 | if (0 <= x && x < w) { 268 | s[x] = ' '; 269 | } 270 | x++; 271 | if ((x + xskip) % tab == 0) { 272 | break; 273 | } 274 | } 275 | return x; 276 | } 277 | -------------------------------------------------------------------------------- /type/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /type/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /type/Makefile: -------------------------------------------------------------------------------- 1 | APP = type 2 | STACK = 1k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /type/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /type/type.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int fh; 6 | char c, cmdline[30], *p; 7 | 8 | api_cmdline(cmdline, 30); 9 | for (p = cmdline; *p > ' '; p++) { } /* スペースが来るまで読み飛ばす */ 10 | for (; *p == ' '; p++) { } /* スペースを読み飛ばす */ 11 | fh = api_fopen(p); 12 | if (fh != 0) { 13 | for (;;) { 14 | if (api_fread(&c, 1, fh) == 0) { 15 | break; 16 | } 17 | api_putchar(c); 18 | } 19 | } else { 20 | api_putstr0("File not found.\n"); 21 | } 22 | api_end(); 23 | } 24 | -------------------------------------------------------------------------------- /walk/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /walk/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /walk/Makefile: -------------------------------------------------------------------------------- 1 | APP = walk 2 | STACK = 1k 3 | MALLOC = 48k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /walk/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /walk/walk.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win, i, x, y; 7 | api_initmalloc(); 8 | buf = api_malloc(160 * 100); 9 | win = api_openwin(buf, 160, 100, -1, "walk"); 10 | api_boxfilwin(win, 4, 24, 155, 95, 0 /* 黒 */); 11 | x = 76; 12 | y = 56; 13 | api_putstrwin(win, x, y, 3 /* 黄 */, 1, "*"); 14 | for (;;) { 15 | i = api_getkey(1); 16 | api_putstrwin(win, x, y, 0 /* 黒 */, 1, "*"); /* 黒で消す */ 17 | if (i == '4' && x > 4) { x -= 8; } 18 | if (i == '6' && x < 148) { x += 8; } 19 | if (i == '8' && y > 24) { y -= 8; } 20 | if (i == '2' && y < 80) { y += 8; } 21 | if (i == 0x0a) { break; } /* Enterで終了 */ 22 | api_putstrwin(win, x, y, 3 /* 黄 */, 1, "*"); 23 | } 24 | api_closewin(win); 25 | api_end(); 26 | } 27 | -------------------------------------------------------------------------------- /winhelo/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /winhelo/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /winhelo/Makefile: -------------------------------------------------------------------------------- 1 | APP = winhelo 2 | STACK = 8k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | 7 | $(APP).hrb : $(APP).org Makefile 8 | $(COPY) $(APP).org $(APP).hrb 9 | -------------------------------------------------------------------------------- /winhelo/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /winhelo/winhelo.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int win; 6 | char buf[150 * 50]; 7 | win = api_openwin(buf, 150, 50, -1, "hello"); 8 | for (;;) { 9 | if (api_getkey(1) == 0x0a) { 10 | break; /* Enterならbreak; */ 11 | } 12 | } 13 | api_end(); 14 | } 15 | -------------------------------------------------------------------------------- /winhelo2/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /winhelo2/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /winhelo2/Makefile: -------------------------------------------------------------------------------- 1 | APP = winhelo2 2 | STACK = 8k 3 | MALLOC = 0k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /winhelo2/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /winhelo2/winhelo2.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | int win; 6 | char buf[150 * 50]; 7 | win = api_openwin(buf, 150, 50, -1, "hello"); 8 | api_boxfilwin(win, 8, 36, 141, 43, 3 /* 黄 */); 9 | api_putstrwin(win, 28, 28, 0 /* 黒 */, 12, "hello, world"); 10 | for (;;) { 11 | if (api_getkey(1) == 0x0a) { 12 | break; /* Enterならbreak; */ 13 | } 14 | } 15 | api_end(); 16 | } 17 | -------------------------------------------------------------------------------- /winhelo3/!cons_9x.bat: -------------------------------------------------------------------------------- 1 | command -------------------------------------------------------------------------------- /winhelo3/!cons_nt.bat: -------------------------------------------------------------------------------- 1 | cmd.exe -------------------------------------------------------------------------------- /winhelo3/Makefile: -------------------------------------------------------------------------------- 1 | APP = winhelo3 2 | STACK = 1k 3 | MALLOC = 40k 4 | 5 | include ../app_make.txt 6 | -------------------------------------------------------------------------------- /winhelo3/make.bat: -------------------------------------------------------------------------------- 1 | ..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 -------------------------------------------------------------------------------- /winhelo3/winhelo3.c: -------------------------------------------------------------------------------- 1 | #include "apilib.h" 2 | 3 | void HariMain(void) 4 | { 5 | char *buf; 6 | int win; 7 | 8 | api_initmalloc(); 9 | buf = api_malloc(150 * 50); 10 | win = api_openwin(buf, 150, 50, -1, "hello"); 11 | api_boxfilwin(win, 8, 36, 141, 43, 6 /* 水色 */); 12 | api_putstrwin(win, 28, 28, 0 /* 黒 */, 12, "hello, world"); 13 | for (;;) { 14 | if (api_getkey(1) == 0x0a) { 15 | break; /* Enterならbreak; */ 16 | } 17 | } 18 | api_end(); 19 | } 20 | --------------------------------------------------------------------------------