diff --git a/.gitmodules b/.gitmodules index ef732d5c0..94c131f19 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "submodules/pdcurses"] path = submodules/pdcurses url = https://github.com/wmcbrine/PDCurses.git +[submodule "submodules/pdcursesmod"] + path = submodules/pdcursesmod + url = https://github.com/Bill-Gray/PDCursesMod.git diff --git a/Cross-compiling b/Cross-compiling index c2eff9a80..9c0be0b89 100644 --- a/Cross-compiling +++ b/Cross-compiling @@ -428,6 +428,7 @@ Using the cross-compiler, build the following targets: c) Additional optional library packages/obj files as required lib/pdcurses/... + or lib/pdcursesmod/... from sources: addch.c, addchstr.c, addstr.c, attr.c, beep.c, bkgd.c, border.c, clear.c, color.c, delch.c, @@ -461,6 +462,8 @@ Cross-compiler pre-built binary downloads: http://sandmann.dotster.com/cwsdpmi/csdpmi7b.zip and pdcurses from: https://github.com/wmcbrine/PDCurses.git + or pdcursesmod from: + https://github.com/Bill-Gray/PDCursesMod.git - A shell script to download that djgpp cross-compiler and associated pieces for either linux or macOS is available: diff --git a/include/extern.h b/include/extern.h index 8333aaa37..9f6a426c6 100644 --- a/include/extern.h +++ b/include/extern.h @@ -3032,9 +3032,9 @@ extern boolean glyphid_cache_status(void); extern int glyphrep_to_custom_map_entries(const char *op, int *glyph); void free_all_glyphmap_u(void); int add_custom_urep_entry(const char *symset_name, int glyphidx, - const uint8 *utf8str, long ucolor, + uint32 utf32ch, const uint8 *utf8str, long ucolor, enum graphics_sets which_set); -int set_map_u(glyph_map *gm, const uint8 *utf8str, long ucolor); +int set_map_u(glyph_map *gm, uint32 utf32ch, const uint8 *utf8str, long ucolor); #endif /* ENHANCED_SYMBOLS */ /* ### vault.c ### */ diff --git a/include/wintype.h b/include/wintype.h index 1da4a060e..893620d2b 100644 --- a/include/wintype.h +++ b/include/wintype.h @@ -80,6 +80,7 @@ struct classic_representation { struct unicode_representation { uint32 ucolor; uint16 u256coloridx; + uint32 utf32ch; uint8 *utf8str; }; diff --git a/src/symbols.c b/src/symbols.c index af0bfc0ea..55277cf2d 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -1065,7 +1065,9 @@ apply_customizations_to_symset(enum graphics_sets which_set) details = g.sym_customizations[UNICODESET].details; while (details) { gm = &glyphmap[details->content.urep.glyphidx]; - (void) set_map_u(gm, details->content.urep.u.utf8str, + (void) set_map_u(gm, + details->content.urep.u.utf32ch, + details->content.urep.u.utf8str, details->content.urep.u.ucolor); details = details->next; } diff --git a/src/utf8map.c b/src/utf8map.c index 7e94f0fbd..d5f411edf 100644 --- a/src/utf8map.c +++ b/src/utf8map.c @@ -60,11 +60,11 @@ to_custom_symset_entry_callback(int glyph, struct find_struct *findwhat) uval = unicode_val(findwhat->unicode_val); if (unicodeval_to_utf8str(uval, utf8str, sizeof utf8str)) { #ifdef NO_PARSING_SYMSET - set_map_u(gm, utf8str, + set_map_u(gm, uval, utf8str, (findwhat->color != 0L) ? findwhat->color : 0L); #endif add_custom_urep_entry(known_handling[H_UTF8], glyph, - utf8str, findwhat->color, UNICODESET); + uval, utf8str, findwhat->color, UNICODESET); } } @@ -217,7 +217,7 @@ unicode_val(const char *cp) } int -set_map_u(glyph_map *gm, const uint8 *utf8str, long ucolor) +set_map_u(glyph_map *gm, uint32 utf32ch, const uint8 *utf8str, long ucolor) { static uint32_t closecolor = 0; static int clridx = 0; @@ -237,6 +237,7 @@ set_map_u(glyph_map *gm, const uint8 *utf8str, long ucolor) gm->u->u256coloridx = clridx; else gm->u->u256coloridx = 0; + gm->u->utf32ch = utf32ch; return 1; } return 0; @@ -475,7 +476,7 @@ glyphrep(const char *op) int add_custom_urep_entry(const char *customization_name, int glyphidx, - const uint8 *utf8str, long ucolor, + uint32 utf32ch, const uint8 *utf8str, long ucolor, enum graphics_sets which_set) { static uint32_t closecolor = 0; @@ -505,6 +506,7 @@ add_custom_urep_entry(const char *customization_name, int glyphidx, details->content.urep.u.u256coloridx = clridx; else details->content.urep.u.u256coloridx = 0; + details->content.urep.u.utf32ch = utf32ch; return 1; } prev = details; @@ -522,6 +524,7 @@ add_custom_urep_entry(const char *customization_name, int glyphidx, newdetails->content.urep.u.u256coloridx = clridx; else newdetails->content.urep.u.u256coloridx = 0; + newdetails->content.urep.u.utf32ch = utf32ch; newdetails->next = (struct customization_detail *) 0; if (!details && prev) { prev->next = newdetails; @@ -1071,7 +1074,7 @@ to_unicode_callback(int glyph UNUSED, struct find_struct *findwhat) uval = unicode_val(findwhat->unicode_val); if (unicodeval_to_utf8str(uval, utf8str, sizeof utf8str)) { #ifdef NO_PARSING_SYMSET - set_map_u(gm, utf8str, + set_map_u(gm, uval, utf8str, (findwhat->color != 0L) ? findwhat->color : 0L); #else diff --git a/sys/msdos/Install.dos b/sys/msdos/Install.dos index a49665efd..5a084c6fa 100644 --- a/sys/msdos/Install.dos +++ b/sys/msdos/Install.dos @@ -41,11 +41,21 @@ II. There once was a time when people built NetHack right on their DOS machine. https://github.com/andrewwutw/build-djgpp/releases/download/v3.0/ a DOS-extender (for including in msdos packaging) from: http://sandmann.dotster.com/cwsdpmi/csdpmi7b.zip - and pdcurses from: - https://github.com/wmcbrine/PDCurses.git and Lua from: http://www.lua.org/ftp/lua-5.4.4.tar.gz + If you want the DOSVGA build, to support higher resolutions and Unicode + symbols, you also need: + pdcursesmod from: + https://github.com/Bill-Gray/PDCursesMod.git + (Name this lib/pdcurmod for the native build) + Terminus fonts from: + https://sourceforge.net/projects/terminus-font/files/terminus-font-4.49/terminus-font-4.49.1.tar.gz + (Name this lib/terminus for the native build) + If not, you also need: + pdcurses from: + https://github.com/wmcbrine/PDCurses.git + - A shell script to download the above-mentioned djgpp cross-compiler and associated support pieces for either linux or macOS is available: sh sys/msdos/fetch-cross-compiler.sh @@ -82,6 +92,12 @@ II. There once was a time when people built NetHack right on their DOS machine. make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_MSDOS=1 all make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_MSDOS=1 package + Add WANT_DOSVGA for a curses build that supports higher resolutions, + external fonts and Unicode symbols: + + make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_MSDOS=1 WANT_DOSVGA=1 all + make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_MSDOS=1 WANT_DOSVGA=1 package + Result: The "make package" target will bundle all of the necessary components to run NetHack on msdos into a folder: targets/msdos/pkg diff --git a/sys/msdos/Makefile.GCC b/sys/msdos/Makefile.GCC index b7c725d99..48e16813c 100644 --- a/sys/msdos/Makefile.GCC +++ b/sys/msdos/Makefile.GCC @@ -35,14 +35,22 @@ GAMEDIR =../binary # of your PDCurses C files which must already be resident on # your machine. # -#ADD_CURSES=Y -#PDCURSES_TOP=../../pdcurses +ifdef WANT_WIN_CURSES +ADD_CURSES=Y +ifdef WANT_DOSVGA +PDCURSES_TOP=../lib/pdcurmod +PDCDOS = $(PDCURSES_TOP)/dosvga +else +PDCURSES_TOP=../lib/pdcurses +PDCDOS = $(PDCURSES_TOP)/dos +endif +endif #--------------------------------------------------------------- ifeq "$(LUA_VERSION)" "5.3.5" -LUAVER=5.3.5 +LUAVER=535 else -LUAVER=5.4.4 +LUAVER=544 endif #--------------------------------------------------------------- # Location of LUA @@ -56,8 +64,13 @@ endif # successfully build NetHack-3.7. # ADD_LUA=Y -LUATOP=../lib/lua$(subst .,, $(LUAVER)) +LUATOP=../lib/lua$(LUAVER) # + +#--------------------------------------------------------------- +# Location of terminus-fonts +# +FONTTOP=../lib/terminus #============================================================================== # This marks the end of the BUILD DECISIONS section. #============================================================================== @@ -193,7 +206,8 @@ VGAOBJ = $(O)vidvga.o $(O)vidvesa.o MAKESRC = makedefs.c -MAKEDEFSOBJS = $(O)makedefs.o $(O)monst.o $(O)objects.o +MAKEDEFSOBJS = $(O)makedefs.o $(O)monst.o $(O)objects.o $(O)alloc.o \ + $(O)date.o $(O)panic.o RECOVOBJS = $(O)recover.o @@ -255,14 +269,14 @@ DLBOBJ = $(O)dlb.o VOBJ01 = $(O)allmain.o $(O)alloc.o $(O)apply.o $(O)artifact.o $(O)attrib.o -VOBJ02 = $(O)ball.o $(O)bones.o $(O)botl.o $(O)cmd.o $(O)dbridge.o +VOBJ02 = $(O)ball.o $(O)bones.o $(O)botl.o $(O)cmd.o $(O)date.o $(O)dbridge.o VOBJ03 = $(O)decl.o $(O)detect.o $(O)dig.o $(O)display.o $(O)do.o VOBJ04 = $(O)do_name.o $(O)do_wear.o $(O)dog.o $(O)dogmove.o $(O)dokick.o VOBJ05 = $(O)dothrow.o $(O)drawing.o $(O)dungeon.o $(O)eat.o $(O)end.o VOBJ06 = $(O)engrave.o $(O)exper.o $(O)explode.o $(O)extralev.o $(O)files.o -VOBJ07 = $(O)fountain.o $(O)getline.o $(O)hack.o $(O)hacklib.o $(O)invent.o +VOBJ07 = $(O)fountain.o $(O)getline.o $(O)hack.o $(O)hacklib.o $(O)insight.o $(O)invent.o VOBJ08 = $(O)isaac64.o $(O)lock.o $(O)mail.o $(O)main.o $(O)makemon.o -VOBJ09 = $(O)mcastu.o $(O)mhitm.o $(O)mhitu.o $(O)minion.o $(O)mkmap.o +VOBJ09 = $(O)mcastu.o $(O)mdlib.o $(O)mhitm.o $(O)mhitu.o $(O)minion.o $(O)mkmap.o VOBJ10 = $(O)mklev.o $(O)mkmaze.o $(O)mkobj.o $(O)mkroom.o $(O)mon.o VOBJ11 = $(O)mondata.o $(O)monmove.o $(O)monst.o $(O)mplayer.o $(O)mthrowu.o VOBJ12 = $(O)muse.o $(O)music.o $(O)o_init.o $(O)objects.o $(O)objnam.o @@ -273,7 +287,7 @@ VOBJ16 = $(O)rnd.o $(O)role.o $(O)rumors.o $(O)save.o $(O)sfstruc VOBJ17 = $(O)shk.o $(O)shknam.o $(O)sit.o $(O)sounds.o $(O)sp_lev.o VOBJ18 = $(O)spell.o $(O)steal.o $(O)steed.o $(O)symbols.o $(O)sys.o VOBJ19 = $(O)teleport.o $(O)termcap.o $(O)timeout.o $(O)topl.o $(O)topten.o -VOBJ20 = $(O)track.o $(O)trap.o $(O)u_init.o $(O)uhitm.o $(O)vault.o +VOBJ20 = $(O)track.o $(O)trap.o $(O)u_init.o $(O)uhitm.o $(O)utf8map.o $(O)vault.o VOBJ21 = $(O)vision.o $(O)weapon.o $(O)were.o $(O)wield.o $(O)windows.o VOBJ22 = $(O)wintty.o $(O)wizard.o $(O)worm.o $(O)worn.o $(O)write.o VOBJ23 = $(O)zap.o $(O)light.o $(O)dlb.o @@ -309,13 +323,12 @@ ALLOBJ = $(VOBJ) $(SOBJ) $(TILOBJ) $(TILOBJ2) $(VVOBJ) #================================================================= LUASRC = $(LUATOP)/src -LUALIB = $(O)lua$(subst .,, $(LUAVER))s.a -LUADLL = $(O)lua$(subst .,, $(LUAVER)).a +LUALIB = $(O)lua$(LUAVER)s.a LUAINCL = -I$(LUASRC) #LUAFLAGS = unix added -lm here? -LUATARGETS = lua.exe luac.exe $(LUADLL) $(LUALIB) +LUATARGETS = lua.exe luac.exe $(LUALIB) -LUASRCFILES = lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c \ +LUASRCFILES = lapi.c lauxlib.c lbaselib.c lcode.c \ lcorolib.c lctype.c ldblib.c ldebug.c ldo.c \ ldump.c lfunc.c lgc.c linit.c liolib.c llex.c \ lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c \ @@ -323,7 +336,7 @@ LUASRCFILES = lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c \ ltable.c ltablib.c ltm.c lundump.c lutf8lib.c \ lvm.c lzio.c -LUAOBJFILES1 = $(O)lapi.o $(O)lauxlib.o $(O)lbaselib.o $(O)lbitlib.o \ +LUAOBJFILES1 = $(O)lapi.o $(O)lauxlib.o $(O)lbaselib.o \ $(O)lcode.o $(O)lcorolib.o $(O)lctype.o $(O)ldblib.o \ $(O)ldebug.o $(O)ldo.o $(O)ldump.o $(O)lfunc.o LUAOBJFILES2 = $(O)lgc.o $(O)linit.o $(O)liolib.o $(O)llex.o \ @@ -341,7 +354,6 @@ PDCURSES_CURSES_H = $(PDCURSES_TOP)/curses.h PDCURSES_CURSPRIV_H = $(PDCURSES_TOP)/curspriv.h PDCURSES_HEADERS = $(PDCURSES_CURSES_H) $(PDCURSES_CURSPRIV_H) PDCSRC = $(PDCURSES_TOP)/pdcurses -PDCDOS = $(PDCURSES_TOP)/dos PDCLIBOBJS1 = $(O)addch.o $(O)addchstr.o $(O)addstr.o $(O)attr.o $(O)beep.o \ $(O)bkgd.o $(O)border.o $(O)clear.o $(O)color.o $(O)delch.o $(O)deleteln.o \ $(O)getch.o @@ -365,6 +377,7 @@ PDCLIB = $(O)pdcurses.a PDCINCL = -I$(PDCURSES_TOP) -I$(PDCSRC) -I$(PDCDOS) else PDCLIB = +PDCINCL = endif #========================================== @@ -429,12 +442,15 @@ endif # ifeq "$(ADD_CURSES)" "Y" CURSESDEF=-D"CURSES_GRAPHICS" -D"CURSES_BRIEF_INCLUDE" +ifdef WANT_DOSVGA +CURSESDEF += -DCURSES_UNICODE -DPDC_WIDE +endif else CURSESDEF= CURSESLIB= endif -INCLDIR=-I../include -I../sys/msdos $(LUAINCL) +INCLDIR=$(PDCINCL) -I../include -I../sys/msdos $(LUAINCL) # Debugging #cflags = -pg -c $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DSUPPRESS_GRAPHICS @@ -510,20 +526,20 @@ $(OBJ)/%.o : $(TTY)/%.c #========================================== $(OBJ)/%.o : $(WCURSES)/%.c - $(CC) -DPDC_NCMOUSE $(PDCINCL) $(cflags) -o$@ $< + $(CC) -DPDC_NCMOUSE $(cflags) -o$@ $< #========================================== # Rules for files in PDCurses #========================================== $(OBJ)/%.o : $(PDCURSES_TOP)/%.c - $(CC) $(PDCINCL) $(cflags) -o$@ $< + $(CC) $(cflags) -o$@ $< $(OBJ)/%.o : $(PDCSRC)/%.c - $(CC) $(PDCINCL) $(cflags) -o$@ $< + $(CC) $(cflags) -o$@ $< $(OBJ)/%.o : $(PDCDOS)/%.c - $(CC) $(PDCINCL) $(cflags) -o$@ $< + $(CC) $(cflags) -o$@ $< #========================================== # Rules for LUA files @@ -558,7 +574,7 @@ recover: $(U)recover.exe @$(subst /,\,if exist $(U)recover.exe copy $(U)recover.exe $(GAMEDIR)) @$(subst /,\,if exist $(DOC)/recover.txt copy $(DOC)/recover.txt $(GAMEDIR)) -$(O)install.tag: $(O)dat.tag $(GAMEFILE) +$(O)install.tag: $(O)dat.tag $(O)fonts.tag $(GAMEFILE) ifeq ($(USE_DLB),Y) @$(subst /,\,copy $(DAT)/nhdat $(GAMEDIR)) @$(subst /,\,copy $(DAT)/license $(GAMEDIR)) @@ -577,13 +593,16 @@ endif @$(subst /,\,copy $(SSHR)/NetHack.cnf $(GAMEDIR)/defaults.nh) -@$(subst /,\,touch $(GAMEDIR)/record) @$(subst /,\,copy $(DOC)/guideb*.txt $(GAMEDIR)) - @$(subst /,\,copy ../sys/windows/sysconf $(GAMEDIR)) + @$(subst /,\,copy $(MSYS)/sysconf $(GAMEDIR)) @$(subst /,\,if not exist $(GAMEDIR)/sysconf touch $(GAMEDIR)/sysconf) @$(subst /,\,if exist $(DOC)/nethack.txt copy $(DOC)/nethack.txt $(GAMEDIR)) ifdef CWSDPMI @$(subst /,\,if exist $(CWSDPMI) copy $(CWSDPMI) $(GAMEDIR)) else @$(subst /,\,echo Could not find a copy of CWSDPMI.EXE to put into $(GAMEDIR)) +endif +ifdef WANT_DOSVGA + @$(subst /,\,copy $(MSYS)/fonts/*.psf $(GAMEDIR)) endif @$(subst /,\,echo install done > $@) @@ -688,8 +707,10 @@ $(SRC)/tile.c: $(U)tilemap.exe @$(subst /,\,$(U)tilemap.exe) @echo A new $@ has been created -$(U)tilemap.exe: $(O)tilemap.o - $(LINK) $(LFLAGS) -o$@ $(O)tilemap.o +TILEMAPOBJS = $(O)tilemap.o $(O)monst.o $(O)objects.o $(O)drawing.o + +$(U)tilemap.exe: $(TILEMAPOBJS) + $(LINK) $(LFLAGS) -o$@ $(TILEMAPOBJS) $(O)tilemap.o: $(WSHR)/tilemap.c $(HACK_H) $(TILE_H) $(CC) $(cflags) -I$(WSHR) -I$(MSYS) -o$@ $(WSHR)/tilemap.c @@ -882,80 +903,17 @@ $(U)dlb_main.exe: $(DLBOBJS) $(O)dlb_main.o: $(U)dlb_main.c $(INCL)/config.h $(DLB_H) $(CC) $(cflags) -o$@ $(U)dlb_main.c -#========================================== -# Housekeeping. -#========================================== - -clean: - $(subst /,\,if exist $(O)*.o del $(O)*.o) - $(subst /,\,if exist $(O)dat.tag del $(O)dat.tag) - $(subst /,\,if exist $(O)install.tag del $(O)install.tag) - $(subst /,\,if exist $(O)$(GAME).lnk del $(O)$(GAME).lnk) - $(subst /,\,if exist $(O)obj.tag del $(O)obj.tag) - $(subst /,\,if exist $(O)sp_lev.tag del $(O)sp_lev.tag) - $(subst /,\,if exist $(O)thintile.tag del $(O)thintile.tag) - $(subst /,\,if exist $(O)utility.tag del $(O)utility.tag) - $(subst /,\,if exist temp.a del temp.a) - -spotless: clean - - $(subst /,\,if exist $(U)makedefs.exe del $(U)makedefs.exe) - $(subst /,\,if exist $(U)recover.exe del $(U)recover.exe) - $(subst /,\,if exist $(U)tilemap.exe del $(U)tilemap.exe) - $(subst /,\,if exist $(U)tile2bmp.exe del $(U)tile2bmp.exe) - $(subst /,\,if exist $(U)tile2bin.exe del $(U)tile2bin.exe) - $(subst /,\,if exist $(U)til2bin2.exe del $(U)til2bin2.exe) - $(subst /,\,if exist $(U)thintile.exe del $(U)thintile.exe) - $(subst /,\,if exist $(U)dlb_main.exe del $(U)dlb_main.exe) - $(subst /,\,if exist $(INCL)/onames.h del $(INCL)/onames.h) - $(subst /,\,if exist $(INCL)/pm.h del $(INCL)/pm.h) - $(subst /,\,if exist $(INCL)/date.h del $(INCL)/date.h) - $(subst /,\,if exist $(SRC)/monstr.c del $(SRC)/monstr.c) - $(subst /,\,if exist $(SRC)/tile.c del $(SRC)/tile.c) - $(subst /,\,if exist $(DAT)/options del $(DAT)/options) - $(subst /,\,if exist $(DAT)/data del $(DAT)/data) - $(subst /,\,if exist $(DAT)/rumors del $(DAT)/rumors) - $(subst /,\,if exist $(DAT)/oracles del $(DAT)/oracles) - $(subst /,\,if exist $(DAT)/bogusmon del $(DAT)/bogusmon) - $(subst /,\,if exist $(DAT)/engrave del $(DAT)/engrave) - $(subst /,\,if exist $(DAT)/epitaph del $(DAT)/epitaph) - $(subst /,\,if exist $(DAT)/dlb.lst del $(DAT)/dlb.lst) - $(subst /,\,if exist $(DAT)/nhdat del $(DAT)/nhdat) - $(subst /,\,if exist $(TILE_BMP) del $(TILE_BMP)) - $(subst /,\,if exist $(WSHR)/monthin.txt del $(WSHR)/monthin.txt) - $(subst /,\,if exist $(WSHR)/objthin.txt del $(WSHR)/objthin.txt) - $(subst /,\,if exist $(WSHR)/oththin.txt del $(WSHR)/oththin.txt) - -#========================================== -# Create directory for holding object files -#========================================== - -$(O)obj.tag: - -$(subst /,\,@if not exist $(OBJ)/*.* mkdir $(OBJ)) - @$(subst /,\,@echo directory created > $@) - -#=========================================== -# Work around some djgpp long file name woes -#=========================================== - -$(PATCHLEV_H): - @$(subst /,\,if not exist $@ copy $(INCL)/patchlevel.h $(INCL)/patchlev.h) - #============================================================= # LUA #============================================================= lua.exe: $(O)lua.o $(LUALIB) - $(link) $(LFLAGS) -o$@ $(O)lua.o $(LUALIB) + $(CC) $(LFLAGS) -o$@ $(O)lua.o $(LUALIB) -luac.exe: $(O)luac.o $(O)lua$(subst .,, $(LUAVER))s.a - $(link) $(LFLAGSU) -o$@ $(O)luac.o $(LUALIB) +luac.exe: $(O)luac.o $(O)lua$(LUAVER)s.a + $(CC) $(LFLAGSU) -o$@ $(O)luac.o $(LUALIB) -$(O)lua$(subst .,, $(LUAVER)).a: $(LUAOBJFILES) - $(cc) -shared -Wl,--export-all-symbols \ - -Wl,--add-stdcall-alias -o $@ $< - -$(O)lua$(subst .,, $(LUAVER))s.a: $(LUAOBJFILES) +$(O)lua$(LUAVER)s.a: $(LUAOBJFILES) ar rcS $@ $(LUAOBJFILES1) ar rcS $@ $(LUAOBJFILES2) ar rcs $@ $(LUAOBJFILES3) @@ -963,6 +921,26 @@ $(O)lua$(subst .,, $(LUAVER))s.a: $(LUAOBJFILES) $(O)lua.o: $(LUASRC)/lua.c $(O)luac.o: $(LUASRC)/luac.c +#========================================== +# Fonts for Unicode support +#========================================== + +ifdef WANT_DOSVGA +$(O)fonts.tag: lua.exe $(MSYS)/fonts/makefont.lua + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u16b.bdf $(MSYS)/fonts/ter-u16b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u16v.bdf $(MSYS)/fonts/ter-u16v.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u18b.bdf $(MSYS)/fonts/ter-u18b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u20b.bdf $(MSYS)/fonts/ter-u20b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u22b.bdf $(MSYS)/fonts/ter-u22b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u24b.bdf $(MSYS)/fonts/ter-u24b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u28b.bdf $(MSYS)/fonts/ter-u28b.psf + lua $(MSYS)/fonts/makefont.lua $(FONTTOP)/ter-u32b.bdf $(MSYS)/fonts/ter-u32b.psf + @echo Fonts done >$(O)fonts.tag +else +$(O)fonts.tag: + @echo Fonts not needed >$(O)fonts.tag +endif + #========================================== # Housekeeping. #========================================== @@ -970,6 +948,8 @@ $(O)luac.o: $(LUASRC)/luac.c clean: $(subst /,\,if exist $(O)*.o del $(O)*.o) $(subst /,\,if exist $(O)dat.tag del $(O)dat.tag) + $(subst /,\,if exist $(O)fonts.tag del $(O)fonts.tag) + $(subst /,\,if exist $(MSYS)/fonts/*.psf del $(MSYS)/fonts/*.psf) $(subst /,\,if exist $(O)install.tag del $(O)install.tag) $(subst /,\,if exist $(O)$(GAME).lnk del $(O)$(GAME).lnk) $(subst /,\,if exist $(O)obj.tag del $(O)obj.tag) @@ -1038,14 +1018,14 @@ $(O)tty.o: $(HACK_H) $(INCL)/wintty.h $(SSHR)/pctty.c $(O)unix.o: $(HACK_H) $(SSHR)/pcunix.c $(CC) $(cflags) -o$@ $(SSHR)/pcunix.c -$(O)pcsys.o : $(HACK_H) $(SSHR)/pcsys.c - $(CC) $(cflags) -o$@ $(SSHR)/pcsys.c +#$(O)pcsys.o : $(HACK_H) $(SSHR)/pcsys.c +# $(CC) $(cflags) -o$@ $(SSHR)/pcsys.c $(O)posixreg.o : $(HACK_H) $(SSHR)/posixreg.c $(CC) $(cflags) -o$@ $(SSHR)/posixreg.c -$(O)cppregex.o : $(HACK_H) $(SSHR)/cppregex.cpp - gpp $(cflags) -std=c++11 -o$@ $(SSHR)/cppregex.cpp +#$(O)cppregex.o : $(HACK_H) $(SSHR)/cppregex.cpp +# gpp $(cflags) -std=c++11 -o$@ $(SSHR)/cppregex.cpp $(O)pmatchre.o : $(HACK_H) $(SSHR)/pmatchre.c $(CC) $(cflags) -o$@ $(SSHR)/pmatchre.c diff --git a/sys/msdos/fetch-cross-compiler.sh b/sys/msdos/fetch-cross-compiler.sh index 572407c0c..2b53fc3d6 100644 --- a/sys/msdos/fetch-cross-compiler.sh +++ b/sys/msdos/fetch-cross-compiler.sh @@ -85,12 +85,18 @@ if [ ! -d djgpp/cwsdpmi ]; then rm csdpmi7b.zip fi -# PDCurses +# PDCurses (non-Unicode build uses this) if [ ! -d "pdcurses" ]; then echo "Getting ../pdcurses from https://github.com/wmcbrine/PDCurses.git" ; \ git clone --depth 1 https://github.com/wmcbrine/PDCurses.git pdcurses fi +# PDCursesMod (Unicode build uses this) +if [ ! -d "pdcursesmod" ]; then + echo "Getting ../pdcursesmod from https://github.com/Bill-Gray/PDCursesMod.git" ; \ + git clone --depth 1 https://github.com/Bill-Gray/PDCursesMod.git pdcursesmod +fi + if [ ! -d djgpp/djgpp-patch ]; then echo "Getting djlsr205.zip" ; cd djgpp @@ -109,6 +115,24 @@ if [ ! -d djgpp/djgpp-patch ]; then cd ../../ fi +FONT_VERSION="4.49" +FONT_FILE="terminus-font-$FONT_VERSION" +FONT_RFILE="$FONT_FILE.1.tar.gz" +FONT_URL="https://sourceforge.net/projects/terminus-font/files/$FONT_FILE/$FONT_RFILE" + +# fonts +if [ ! -d "$FONT_FILE" ]; then + echo "Getting terminus fonts" + if [ "$(uname)" = "Darwin" ]; then + #Mac + curl -L $FONT_URL --output $FONT_RFILE + else + wget --quiet --no-hsts $FONT_URL + fi + tar -xvf $FONT_RFILE + rm $FONT_RFILE +fi + cd ../ # Don't fail the build if lua fetch failed because we cannot do anything about it diff --git a/sys/msdos/fonts/.gitignore b/sys/msdos/fonts/.gitignore new file mode 100644 index 000000000..967cbdca1 --- /dev/null +++ b/sys/msdos/fonts/.gitignore @@ -0,0 +1 @@ +*.psf diff --git a/sys/msdos/fonts/README.txt b/sys/msdos/fonts/README.txt new file mode 100644 index 000000000..52848f525 --- /dev/null +++ b/sys/msdos/fonts/README.txt @@ -0,0 +1,7 @@ +The script makefont.lua converts the Terminus fonts from the BDF sources to +PSF version 2 for use by the MS-DOS NetHack. The directory sys/msdos/fonts +receives the converted fonts. + +makefont.lua is specifically meant for use with NetHack; it rearranges the +input glyphs so the first 256 positions conform to IBM437. The fonts can then +support IBMGraphics without using the Unicode table. diff --git a/sys/msdos/fonts/makefont.lua b/sys/msdos/fonts/makefont.lua new file mode 100755 index 000000000..c953f6aae --- /dev/null +++ b/sys/msdos/fonts/makefont.lua @@ -0,0 +1,212 @@ +#!/usr/bin/env lua +-- Copyright (c) 2016, 2022 Ray Chason +-- NetHack may be freely redistributed. See license for details. + +-- IBM437 order as NetHack expects +ibm437 = { + 0x0000, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, + 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, + 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, + 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, + 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, + 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, + 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, + 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, + 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, + 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, + 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, + 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, + 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, + 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, + 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x2302, + 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, + 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, + 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, + 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, + 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, + 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, + 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, + 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, + 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, + 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, + 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, + 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, + 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 +} + +-- As ibm437, but mapping Unicode back to the IBM437 position +ibm437_rev = {} +for i = 1, #ibm437 do + ibm437_rev[ibm437[i]] = i +end + +-- Information about a single glyph in the font +function new_glyph(width, height) + local g = {} + g.width = width + g.height = height + g.bytes = "" + g.code = {} + return g +end + +-- This converts an unsigned integer to four little endian bytes +function write_u32(x) + return string.pack(" \n") + os.exit(1) +end + +fp = io.open(arg[1], "r") + +while true do + line = fp:read() + if (line == fail) then + break + end + if start_with(line, 'FONTBOUNDINGBOX ') then + -- Width and height of a glyph + rec = split(line) + width = rec[2] + height = rec[3] + bwidth = math.floor((width + 7) / 8) + elseif start_with(line, 'STARTCHAR ') then + -- A glyph begins here + glyph = new_glyph(width, height) + elseif start_with(line, 'ENCODING ') then + -- This line provides the Unicode code point + rec = split(line) + glyph.code[#glyph.code+1] = tonumber(rec[2]) + elseif start_with(line, 'BITMAP') then + -- Bitmap data appears on following lines + bitmap = true + elseif start_with(line, 'ENDCHAR') then + -- End of bitmap data + -- Position will be according to IBM437 if the code point is in IBM437, + -- else matching any prior occurrence if the same glyph has appeared + -- before, else as a new glyph + pos = ibm437_rev[glyph.code[1]] or font_by_bytes[glyph.bytes] + if pos == nil then + pos = next_pos + next_pos = next_pos + 1 + end + if font[pos] == nil then + font[pos] = glyph + font_by_bytes[glyph.bytes] = pos + else + for i = 1, #glyph.code do + font[pos].code[#font[pos].code+1] = glyph.code[i] + end + end + font_by_code[glyph.code[1]] = pos + glyph = nil + bitmap = false + elseif bitmap then + -- Hex data after BITMAP and before ENDCHAR + for i = 1, bwidth do + byte = string.sub(line, i*2-1, i*2) + glyph.bytes = glyph.bytes .. string.char(tonumber(byte, 16)) + end + end +end + +fp:close() + +-- The provided BDFs code positions 16 and 17 differently from what NetHack +-- expects +if font[ibm437_rev[0x25BA]] == nil and font_by_code[0x25B6] ~= nil then + pos1 = font_by_code[0x25B6] + pos2 = ibm437_rev[0x25BA] + font[pos2] = font[pos1] + font[pos2].code[#font[pos2].code+1] = 0x25BA + font[pos1] = nil +end +if font[ibm437_rev[0x25C4]] == nil and font_by_code[0x25C0] ~= nil then + pos1 = font_by_code[0x25C0] + pos2 = ibm437_rev[0x25C4] + font[pos2] = font[pos1] + font[pos2].code[#font[pos2].code+1] = 0x25C4 + font[pos1] = nil +end + +-- Fill any empty slots and warn +for i = 1, 256 do + if font[i] == nil then + if next_pos > 257 then + next_pos = next_pos - 1 + font[i] = font[next_pos] + font[next_pos] = nil + end + end +end + +outfile = io.open(arg[2], "wb") + +-- Write the PSF header +outfile:write("\x72\xB5\x4A\x86") -- magic +outfile:write(write_u32(0)) -- version +outfile:write(write_u32(32)) -- headersize +outfile:write(write_u32(0x01)) -- flags (Unicode table present) +outfile:write(write_u32(next_pos-1)) -- length +outfile:write(write_u32(bwidth * height)) -- charsize +outfile:write(write_u32(height)) -- height +outfile:write(write_u32(width)) -- width + +-- Write the glyphs +for i = 1, next_pos-1 do + glyph = font[i] + outfile:write(glyph.bytes) +end + +-- Write the Unicode mappings +for i = 1, next_pos-1 do + glyph = font[i] + for j = 1, #glyph.code do + outfile:write(utf8.char(glyph.code[j])) + end + outfile:write("\xFF") +end + +outfile:close() diff --git a/sys/msdos/nhlua.h b/sys/msdos/nhlua.h index cf2883a86..992f2ad64 100644 --- a/sys/msdos/nhlua.h +++ b/sys/msdos/nhlua.h @@ -1,6 +1,6 @@ /* nhlua.h - generated by top Makefile */ -#include "../lib/lua535/src/lua.h" +#include "../lib/lua544/src/lua.h" LUA_API int (lua_error) (lua_State *L) NORETURN; -#include "../lib/lua535/src/lualib.h" -#include "../lib/lua535/src/lauxlib.h" +#include "../lib/lua544/src/lualib.h" +#include "../lib/lua544/src/lauxlib.h" /*nhlua.h*/ diff --git a/sys/msdos/setup.bat b/sys/msdos/setup.bat index 41e213587..988de68db 100755 --- a/sys/msdos/setup.bat +++ b/sys/msdos/setup.bat @@ -125,8 +125,9 @@ echo distribution. echo The following files need to exist under the names on the echo right in order to build NetHack: echo. -echo ..\..\dat\data.base needs to be copied to ..\..\dat\data.bas -echo ..\..\include\patchlevel.h needs to be copied to ..\..\include\patchlev.h +echo ..\..\dat\data.base needs to be copied to ..\..\dat\data.bas +echo ..\..\include\patchlevel.h needs to be copied to ..\..\include\patchlev.h +echo ..\..\sys\share\posixregex.c needs to be copied to ..\..\sys\share\posixreg.c echo. echo setup.bat was unable to perform the necessary changes because at least echo one of the files doesn't exist under its short name, and the diff --git a/sys/unix/Makefile.top b/sys/unix/Makefile.top index 783160643..802e9b7e3 100644 --- a/sys/unix/Makefile.top +++ b/sys/unix/Makefile.top @@ -143,6 +143,10 @@ include/nhlua.h: $(TOPLUALIB) lib/lua-$(LUA_VERSION)/src/lua.h: @echo "Please do 'make fetch-lua' to obtain lua-$(LUA_VERSION)" @false +luabin: + ( cd $(LUATOP) \ + && make $(LUAMAKEFILES) all && cd $(LUA2NHTOP) ) + # hints file could set LUATESTTARGET to this if GITSUBMODULES is defined submodules/lua/lua.h: git submodule init submodules/lua diff --git a/sys/unix/hints/include/cross-post.370 b/sys/unix/hints/include/cross-post.370 index 2364a4109..4a056813f 100644 --- a/sys/unix/hints/include/cross-post.370 +++ b/sys/unix/hints/include/cross-post.370 @@ -24,9 +24,30 @@ $(TARGETPFX)exceptn.o : ../lib/djgpp/djgpp-patch/src/libc/go32/exceptn.S $(GAMEBIN) : $(HOBJ) $(LUACROSSLIB) $(TARGET_LINK) $(TARGET_LFLAGS) -o $(GAMEBIN) \ $(HOBJ) $(WINLIB) $(TARGET_LIBS) +$(FONTDIR)/ter-u16b.psf: $(FONTTOP)/ter-u16b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u16b.bdf $@ +$(FONTDIR)/ter-u16v.psf: $(FONTTOP)/ter-u16v.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u16v.bdf $@ +$(FONTDIR)/ter-u18b.psf: $(FONTTOP)/ter-u18b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u18b.bdf $@ +$(FONTDIR)/ter-u20b.psf: $(FONTTOP)/ter-u20b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u20b.bdf $@ +$(FONTDIR)/ter-u22b.psf: $(FONTTOP)/ter-u22b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u22b.bdf $@ +$(FONTDIR)/ter-u24b.psf: $(FONTTOP)/ter-u24b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u24b.bdf $@ +$(FONTDIR)/ter-u28b.psf: $(FONTTOP)/ter-u28b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u28b.bdf $@ +$(FONTDIR)/ter-u32b.psf: $(FONTTOP)/ter-u32b.bdf $(FONTDIR)/makefont.lua $(LUABIN) + $(LUABIN) $(FONTDIR)/makefont.lua $(FONTTOP)/ter-u32b.bdf $@ # -.PHONY: dospkg -dospkg: $(GAMEBIN) $(TARGETPFX)recover.exe ../dat/nhtiles.bmp +.PHONY: dodata dospkg dosfonts +ifdef WANT_DOSVGA +dosfonts: $(FONTTARGETS) +else +dosfonts: +endif +dospkg: dodata dosfonts $(GAMEBIN) $(TARGETPFX)recover.exe ../dat/nhtiles.bmp $(TARGET_STUBEDIT) $(GAMEBIN) minstack=2048K mkdir -p $(TARGETPFX)pkg cp $(GAMEBIN) $(TARGETPFX)pkg/NETHACK.EXE @@ -38,10 +59,26 @@ dospkg: $(GAMEBIN) $(TARGETPFX)recover.exe ../dat/nhtiles.bmp cp ../sys/share/NetHack.cnf $(TARGETPFX)pkg/NETHACK.CNF cp ../sys/msdos/sysconf $(TARGETPFX)pkg/SYSCONF cp ../doc/nethack.txt $(TARGETPFX)pkg/NETHACK.TXT +ifdef WANT_DOSVGA + cp ../sys/msdos/fonts/ter-u16b.psf $(TARGETPFX)pkg/TER-U16B.PSF + cp ../sys/msdos/fonts/ter-u16v.psf $(TARGETPFX)pkg/TER-U16V.PSF + cp ../sys/msdos/fonts/ter-u18b.psf $(TARGETPFX)pkg/TER-U18B.PSF + cp ../sys/msdos/fonts/ter-u20b.psf $(TARGETPFX)pkg/TER-U20B.PSF + cp ../sys/msdos/fonts/ter-u22b.psf $(TARGETPFX)pkg/TER-U22B.PSF + cp ../sys/msdos/fonts/ter-u24b.psf $(TARGETPFX)pkg/TER-U24B.PSF + cp ../sys/msdos/fonts/ter-u28b.psf $(TARGETPFX)pkg/TER-U28B.PSF + cp ../sys/msdos/fonts/ter-u32b.psf $(TARGETPFX)pkg/TER-U32B.PSF +endif cp ../lib/djgpp/cwsdpmi/bin/CWSDPMI.EXE $(TARGETPFX)pkg/CWSDPMI.EXE -touch $(TARGETPFX)pkg/RECORD cd $(TARGETPFX)pkg ; zip -9 ../NH370DOS.ZIP * ; cd ../../.. @echo msdos package zip file $(TARGETPFX)NH370DOS.ZIP + +$(LUABIN): + ( cd .. && make luabin && cd src) +dodata: + ( cd .. && make dlb && cd src) + endif # CROSS_TO_MSDOS ifdef CROSS_TO_WASM @@ -180,13 +217,13 @@ $(TARGETPFX)touch.o : $(PDCTOP)/pdcurses/touch.c $(TARGETPFX)util.o : $(PDCTOP)/pdcurses/util.c $(TARGETPFX)window.o : $(PDCTOP)/pdcurses/window.c $(TARGETPFX)debug.o : $(PDCTOP)/pdcurses/debug.c -$(TARGETPFX)pdcclip.o : $(PDCTOP)/dos/pdcclip.c -$(TARGETPFX)pdcdisp.o : $(PDCTOP)/dos/pdcdisp.c -$(TARGETPFX)pdcgetsc.o : $(PDCTOP)/dos/pdcgetsc.c -$(TARGETPFX)pdckbd.o : $(PDCTOP)/dos/pdckbd.c -$(TARGETPFX)pdcscrn.o : $(PDCTOP)/dos/pdcscrn.c -$(TARGETPFX)pdcsetsc.o : $(PDCTOP)/dos/pdcsetsc.c -$(TARGETPFX)pdcutil.o : $(PDCTOP)/dos/pdcutil.c +$(TARGETPFX)pdcclip.o : $(PDCPORT)/pdcclip.c +$(TARGETPFX)pdcdisp.o : $(PDCPORT)/pdcdisp.c +$(TARGETPFX)pdcgetsc.o : $(PDCPORT)/pdcgetsc.c +$(TARGETPFX)pdckbd.o : $(PDCPORT)/pdckbd.c +$(TARGETPFX)pdcscrn.o : $(PDCPORT)/pdcscrn.c +$(TARGETPFX)pdcsetsc.o : $(PDCPORT)/pdcsetsc.c +$(TARGETPFX)pdcutil.o : $(PDCPORT)/pdcutil.c endif # BUILD_PDCURSES # # End of cross-compiling -POST section diff --git a/sys/unix/hints/include/cross-pre.370 b/sys/unix/hints/include/cross-pre.370 index ed0c5734c..f3d11aa93 100644 --- a/sys/unix/hints/include/cross-pre.370 +++ b/sys/unix/hints/include/cross-pre.370 @@ -74,9 +74,18 @@ ifdef BUILD_PDCURSES # PD Curses library #===============-================================================= ifdef WANT_WIN_CURSES +ifdef WANT_DOSVGA +PDCTOP = ../lib/pdcursesmod +PDCPORT = $(PDCTOP)/dosvga +PDCURSESDEF= -I$(PDCTOP) -I$(PDCPORT) \ + -D"CURSES_GRAPHICS" -D"CURSES_BRIEF_INCLUDE" \ + -D"PDC_WIDE" -D"CURSES_UNICODE" +else PDCTOP = ../lib/pdcurses -PDCURSESDEF= -I../lib/pdcurses -I../lib/pdcurses/dos \ +PDCPORT = $(PDCTOP)/dos +PDCURSESDEF= -I$(PDCTOP) -I$(PDCPORT) \ -D"CURSES_GRAPHICS" -D"CURSES_BRIEF_INCLUDE" +endif # WANT_DOSVGA PDCLIBOBJ1= $(TARGETPFX)addch.o $(TARGETPFX)addchstr.o \ $(TARGETPFX)addstr.o $(TARGETPFX)attr.o \ $(TARGETPFX)beep.o $(TARGETPFX)bkgd.o \ @@ -152,9 +161,17 @@ MSDOS_TARGET_CFLAGS = -c -O -I../include -I../sys/msdos -I../win/share \ -Wimplicit -Wimplicit-function-declaration -Wimplicit-int \ -Wmissing-parameter-type -Wold-style-definition -Wstrict-prototypes \ -DGCC_WARN -PDCINCL += -I$(PDCTOP)/dos +PDCINCL += -I$(PDCPORT) PDC_TARGET_CFLAGS = $(MSDOS_TARGET_CFLAGS) -Wno-unused-parameter \ -Wno-missing-prototypes +FONTVER = terminus-font-4.49.1 +FONTTOP = ../lib/$(FONTVER) +FONTDIR = ../sys/msdos/fonts +FONTTARGETS = $(FONTDIR)/ter-u16b.psf $(FONTDIR)/ter-u16v.psf \ + $(FONTDIR)/ter-u18b.psf $(FONTDIR)/ter-u20b.psf \ + $(FONTDIR)/ter-u22b.psf $(FONTDIR)/ter-u24b.psf \ + $(FONTDIR)/ter-u28b.psf $(FONTDIR)/ter-u32b.psf +LUABIN = ../lib/lua-$(LUA_VERSION)/src/lua LUA_TARGET_CFLAGS = $(MSDOS_TARGET_CFLAGS) override TARGET_CFLAGS = $(MSDOS_TARGET_CFLAGS) -Wmissing-declarations \ -Wmissing-prototypes -pedantic -Wmissing-declarations \ @@ -184,12 +201,12 @@ override TOPLUALIB= override GAMEBIN = $(TARGETPFX)nethack.exe override PACKAGE = dospkg override PREGAME += mkdir -p $(TARGETDIR) ; make $(TARGETPFX)exceptn.o ; -override CLEANMORE += rm -f -r $(TARGETDIR) ; +override CLEANMORE += rm -f -r $(TARGETDIR) ; rm -f -r $(FONTTARGETS) ; VARDATND += nhtiles.bmp # ifdef WANT_WIN_CURSES # rules for pdcurses dos-specific files -$(TARGETPFX)%.o : $(PDCTOP)/dos/%.c +$(TARGETPFX)%.o : $(PDCPORT)/%.c $(TARGET_CC) $(PDCINCL) $(PDC_TARGET_CFLAGS) -o$@ $< endif # WANT_WIN_CURSES # diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 40c20ae3c..1732ff4b6 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -154,11 +154,30 @@ curses_init_nhwindows(int *argcp UNUSED, char **argv UNUSED) { #ifdef PDCURSES + static char pdc_font[BUFSZ] = ""; char window_title[BUFSZ]; #endif #ifdef CURSES_UNICODE setlocale(LC_CTYPE, ""); +#ifdef PDCURSES + /* Assume the DOSVGA port of PDCursesMod, or the SDL1 or SDL2 port of + either PDCurses or PDCursesMod. Honor the font_map option to set + a font. + On MS-DOS, if no font_map is set, use ter-u16v.psf if it is present. + PDC_FONT has no effect on other PDCurses or PDCursesMod ports. */ + if (iflags.wc_font_map && iflags.wc_font_map[0]) { + Snprintf(pdc_font, sizeof(pdc_font), "PDC_FONT=%s", + iflags.wc_font_map); +#ifdef MSDOS + } else if (access("ter-u16v.psf", R_OK) >= 0) { + Snprintf(pdc_font, sizeof(pdc_font), "PDC_FONT=ter-u16v.psf"); +#endif + } + if (pdc_font[0] != '\0') { + putenv(pdc_font); + } +#endif #endif #ifdef XCURSES diff --git a/win/curses/curswins.c b/win/curses/curswins.c index e1a8a65c0..4fc440317 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -3,6 +3,9 @@ /* Copyright (c) Karl Garrison, 2010. */ /* NetHack may be freely redistributed. See license for details. */ +#if defined(CURSES_UNICODE) && !defined(_XOPEN_SOURCE_EXTENDED) +#define _XOPEN_SOURCE_EXTENDED 1 +#endif #include "curses.h" #include "hack.h" #include "wincurs.h" @@ -596,12 +599,75 @@ static void write_char(WINDOW * win, int x, int y, nethack_char nch) { curses_toggle_color_attr(win, nch.color, nch.attr, ON); +#if defined(CURSES_UNICODE) && defined(ENHANCED_SYMBOLS) + if ((nch.unicode_representation && nch.unicode_representation->utf8str) + || SYMHANDLING(H_IBM)) { + /* CP437 to Unicode mapping according to the Unicode Consortium */ + static const uint16 cp437[256] = { + 0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, + 0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, + 0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8, + 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC, + 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, + 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, + 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, + 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, + 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, + 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, + 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, + 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, + 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, + 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, + 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302, + 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, + 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, + 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, + 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, + 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, + 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, + 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, + 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, + 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, + 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, + 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, + 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, + 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, + 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, + 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, + 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0 + }; + attr_t attr; + short pair; + wchar_t wch[3]; + uint32 utf32ch; + cchar_t cch; + + if (SYMHANDLING(H_UTF8)) { + utf32ch = nch.unicode_representation->utf32ch; + } else if (SYMHANDLING(H_IBM)) { + utf32ch = cp437[(uint8)nch.ch]; + } else { + utf32ch = (uint8)nch.ch; + } + if (sizeof(wchar_t) == 2 && utf32ch >= 0x10000) { + /* UTF-16 surrogate pair */ + wch[0] = (wchar_t)((utf32ch >> 10) + 0xD7C0); + wch[1] = (wchar_t)((utf32ch & 0x3FF) + 0xDC00); + wch[2] = L'\0'; + } else { + wch[0] = (wchar_t)utf32ch; + wch[1] = L'\0'; + } + wmove(win, y, x); + wattr_get(win, &attr, &pair, NULL); + setcchar(&cch, wch, attr, pair, NULL); + mvwadd_wch(win, y, x, &cch); + } else +#endif #ifdef PDCURSES - mvwaddrawch(win, y, x, nch.ch); + mvwaddrawch(win, y, x, nch.ch); #else - if (nch.unicode_representation && nch.unicode_representation->utf8str) - mvwprintw(win, y, x, "%s", nch.unicode_representation->utf8str); - else mvwaddch(win, y, x, nch.ch); #endif curses_toggle_color_attr(win, nch.color, nch.attr, OFF);