diff --git a/Makefile b/Makefile index 624e16c..286d168 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +PREFIX = /usr +DOCDIR = $(PREFIX)/doc/hpemu + CC = gcc LIBS = $(shell pkg-config --libs sdl2 SDL2_ttf) CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=missing-braces -Wno-error=incompatible-pointer-types @@ -22,11 +25,6 @@ dist/hpemu: src/bus.o \ src/timers.o $(CC) $(CFLAGS) $(LIBS) -o $@ $+ -# Installing - -get-roms: - make -C ROMs get-roms - # Cleaning clean: -rm src/*.o @@ -39,3 +37,23 @@ clean-all: mrproper # Formatting pretty-code: clang-format -i src/*.c src/*.h + +# Installing +get-roms: + make -C dist/ROMs get-roms + +install: all get-roms + install -m 755 -d -- $(DESTDIR)$(PREFIX)/bin + install -c -m 755 dist/hpemu $(DESTDIR)$(PREFIX)/bin/hpemu + + install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/hpemu + install -c -m 644 dist/hplogo.png $(DESTDIR)$(PREFIX)/share/hpemu/hplogo.png + cp -R dist/ROMs/ $(DESTDIR)$(PREFIX)/share/hpemu/ + sed "s|@PREFIX@|$(PREFIX)|g" dist/setup-hpemu-home.sh > $(DESTDIR)$(PREFIX)/share/hpemu/setup-hpemu-home.sh + chmod 755 $(DESTDIR)$(PREFIX)/share/hpemu/setup-hpemu-home.sh + + install -m 755 -d -- $(DESTDIR)$(DOCDIR) + cp -R ./*.txt $(DESTDIR)$(DOCDIR) + + install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/applications + sed "s|@PREFIX@|$(PREFIX)|g" dist/hpemu.desktop > $(DESTDIR)$(PREFIX)/share/applications/hpemu.desktop diff --git a/ROMs/Makefile b/dist/ROMs/Makefile similarity index 100% rename from ROMs/Makefile rename to dist/ROMs/Makefile diff --git a/ROMs/gxrom-l b/dist/ROMs/gxrom-l similarity index 100% rename from ROMs/gxrom-l rename to dist/ROMs/gxrom-l diff --git a/ROMs/gxrom-m b/dist/ROMs/gxrom-m similarity index 100% rename from ROMs/gxrom-m rename to dist/ROMs/gxrom-m diff --git a/ROMs/gxrom-p b/dist/ROMs/gxrom-p similarity index 100% rename from ROMs/gxrom-p rename to dist/ROMs/gxrom-p diff --git a/ROMs/gxrom-r b/dist/ROMs/gxrom-r similarity index 100% rename from ROMs/gxrom-r rename to dist/ROMs/gxrom-r diff --git a/ROMs/sxrom-a b/dist/ROMs/sxrom-a similarity index 100% rename from ROMs/sxrom-a rename to dist/ROMs/sxrom-a diff --git a/ROMs/sxrom-b b/dist/ROMs/sxrom-b similarity index 100% rename from ROMs/sxrom-b rename to dist/ROMs/sxrom-b diff --git a/ROMs/sxrom-c b/dist/ROMs/sxrom-c similarity index 100% rename from ROMs/sxrom-c rename to dist/ROMs/sxrom-c diff --git a/ROMs/sxrom-d b/dist/ROMs/sxrom-d similarity index 100% rename from ROMs/sxrom-d rename to dist/ROMs/sxrom-d diff --git a/ROMs/sxrom-e b/dist/ROMs/sxrom-e similarity index 100% rename from ROMs/sxrom-e rename to dist/ROMs/sxrom-e diff --git a/ROMs/sxrom-j b/dist/ROMs/sxrom-j similarity index 100% rename from ROMs/sxrom-j rename to dist/ROMs/sxrom-j diff --git a/dist/hpemu.desktop b/dist/hpemu.desktop new file mode 100644 index 0000000..ad69a24 --- /dev/null +++ b/dist/hpemu.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Exec=@PREFIX@/bin/hpemu +Name=hpemu +Icon=@PREFIX@/share/hpemu/hplogo.png +Categories=Utility; diff --git a/dist/hplogo.png b/dist/hplogo.png new file mode 100644 index 0000000..a4fff9f Binary files /dev/null and b/dist/hplogo.png differ diff --git a/dist/setup-hpemu-home.sh b/dist/setup-hpemu-home.sh new file mode 100755 index 0000000..cdfb802 --- /dev/null +++ b/dist/setup-hpemu-home.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +DOTHPEMU=${DOTHPEMU:-.config/hpemu} + +ROM=${ROM:-gxrom-r} + +mkdir -p ~/"${DOTHPEMU}" + +[ -e ~/"${DOTHPEMU}"/rom ] && rm ~/"${DOTHPEMU}"/rom +ln -s @PREFIX@/share/hpemu/ROMs/"$ROM" ~/"${DOTHPEMU}"/rom +cd ~/"${DOTHPEMU}" diff --git a/src/files.c b/src/files.c index 1868371..087a41e 100644 --- a/src/files.c +++ b/src/files.c @@ -367,8 +367,8 @@ void rom_init( char* filename ) printf( "ERROR: can't read ROM file\n" ); exit( 0x14 ); } - // pack_fclose(f); fclose( f ); + if ( buf[ 0 ] & 0xF0 || buf[ 1 ] & 0xF0 ) { if ( size == 1024 * 1024 ) { printf( "ERROR: wrong ROM\n" ); diff --git a/src/rpl.c b/src/rpl.c index 7dc2ae0..5dc03f1 100644 --- a/src/rpl.c +++ b/src/rpl.c @@ -14,10 +14,8 @@ int rpl_object_size( byte* obj ) { int size; - int prologue; int n; - - prologue = nib_to_unsigned( obj, 5 ); + int prologue = nib_to_unsigned( obj, 5 ); switch ( prologue ) { @@ -85,9 +83,9 @@ int rpl_object_size( byte* obj ) case 0x02A96: // Directory n = nib_to_unsigned( obj + 8, 5 ); - if ( n == 0 ) { + if ( n == 0 ) size = 13; - } else { + else { size = 8 + n; size += 4 + 2 * nib_to_unsigned( obj + size, 2 ); size += rpl_object_size( obj + size ); @@ -103,9 +101,8 @@ int rpl_object_size( byte* obj ) static address read_address( address adr ) { byte buf[ 5 ]; - word ocrc; + word ocrc = crc; - ocrc = crc; bus_read( buf, adr, 5 ); crc = ocrc; @@ -123,12 +120,11 @@ static void write_address( address adr, address val ) static int moveup( address src, address dst, address cnt ) { byte* buf = malloc( cnt * sizeof( byte ) ); - word ocrc; if ( !buf ) return -1; - ocrc = crc; + word ocrc = crc; bus_read( buf, src, cnt ); bus_write( buf, dst, cnt ); crc = ocrc; @@ -139,14 +135,12 @@ static int moveup( address src, address dst, address cnt ) address rpl_make_temp( address size ) { - address temptop, rsktop, dsktop; + address temptop = read_address( TEMPTOP ); + address rsktop = read_address( RSKTOP ); + address dsktop = read_address( DSKTOP ); size += 6; - temptop = read_address( TEMPTOP ); - rsktop = read_address( RSKTOP ); - dsktop = read_address( DSKTOP ); - if ( rsktop + size > dsktop ) return 0; @@ -163,24 +157,23 @@ address rpl_make_temp( address size ) void rpl_push( address adr ) { - address dsktop, avmem; + address avmem = read_address( AVMEM ); - avmem = read_address( AVMEM ); if ( !avmem ) return; write_address( AVMEM, avmem - 1 ); - dsktop = read_address( DSKTOP ); + address dsktop = read_address( DSKTOP ); dsktop -= 5; + write_address( dsktop, adr ); write_address( DSKTOP, dsktop ); } int rpl_push_object( byte* obj, address size ) { - address adr; + address adr = rpl_make_temp( size ); - adr = rpl_make_temp( size ); if ( !adr ) return -1;