kivan117 / gghost

Ghosty Ghost project for the Uzebox minimalist 8-bit console.
5 stars 0 forks source link

gghost doesn't build against recent Uzebox kernels #1

Open danboid opened 4 years ago

danboid commented 4 years ago

I'm trying to learn to code for the Uzebox and gghost looks like it would make a great example for a beginner to pick apart, if it would build against recent Uzebox kernels at least. It would make a good learning aid because it is a simple game and you've commented almost every line - thanks for that!

After changing VRAM_TILES_V to 32 in the Makefile, I get as far as this:

~/src/uzebox/MY_GAMES/ghostyghost/default$ make
avr-gcc -I"../../kernel"  -mmcu=atmega644 -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT uzeboxVideoEngineCore.o -MF dep/uzeboxVideoEngineCore.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -x assembler-with-cpp -Wa,-gdwarf2 -c  ../../kernel/uzeboxVideoEngineCore.s
avr-gcc -I"../../kernel"  -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT uzeboxCore.o -MF dep/uzeboxCore.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -c  ../../kernel/uzeboxCore.c
avr-gcc -I"../../kernel"  -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT uzeboxSoundEngine.o -MF dep/uzeboxSoundEngine.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -c  ../../kernel/uzeboxSoundEngine.c
avr-gcc -I"../../kernel"  -mmcu=atmega644 -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT uzeboxSoundEngineCore.o -MF dep/uzeboxSoundEngineCore.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -x assembler-with-cpp -Wa,-gdwarf2 -c  ../../kernel/uzeboxSoundEngineCore.s
avr-gcc -I"../../kernel"  -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT uzeboxVideoEngine.o -MF dep/uzeboxVideoEngine.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -c  ../../kernel/uzeboxVideoEngine.c
avr-gcc -I"../../kernel"  -mmcu=atmega644 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline  -MD -MP -MT GGHOST.o -MF dep/GGHOST.o.d  -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_CHANNEL_4_ENABLE=1 -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24 -DOVERLAY_LINES=0 -DVRAM_TILES_V=32 -c  ../gghost.c
../gghost.c: In function ‘gameSetup’:
../gghost.c:381:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   bg[k] = 1;
         ^
../gghost.c: In function ‘loadNextStripe’:
../gghost.c:593:14: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
    bg[drawX] = 1;
              ^
../gghost.c:602:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   bg[drawX] = 1;
             ^
avr-gcc -mmcu=atmega644 -Wl,-Map=GGHOST.map  -Wl,-gc-sections  -Wl,--section-start,.noinit=0x800100 -Wl,--section-start,.data=0x800300 uzeboxVideoEngineCore.o  uzeboxCore.o uzeboxSoundEngine.o uzeboxSoundEngineCore.o uzeboxVideoEngine.o GGHOST.o     -o GGHOST.elf
avr-gcc: error: GGHOST.o: No such file or directory
Makefile:83: recipe for target 'GGHOST.elf' failed
make: *** [GGHOST.elf] Error 1
kivan117 commented 4 years ago

Glad you're looking into the project for its intended purpose. Lots of bad code practices here but hopefully it at least clarifies how to get something to work at all.

I haven't touched the code base since the last commit. I'm sure the kernel is quite different 5 years later. I'll look into it though, thanks.

artcfox commented 4 years ago

@kivan117 The kernel hasn't changed that much. I think these errors are from 3 things:

  1. The master branch is likely not the branch we should be building from
  2. Hardcoded Windows pathnames
  3. Windows filenames not being case sensitive, but on Linux they are

First I went into my main uzebox directory and cloned this repo. Then I did a git checkout localonly to switch to that branch, and after making the following changes to the Makefile, I was able to successfully build on Linux, but it looks like parts of the tileset are still messed up.


index d564257..bd15dcf 100644
--- a/ghostyghost/default/Makefile
+++ b/ghostyghost/default/Makefile
@@ -4,15 +4,15 @@

 ## General Flags
 PROJECT = ghostyghost
-GAME= GGHOST
+GAME= gghost
 MCU = atmega644
 TARGET = $(GAME).elf
 CC = avr-gcc
 INFO=../gameinfo.properties
-UZEBIN_DIR = c:/uze_workspace/uzebox_bin_Win32_dev_trunk_r212/bin/
+UZEBIN_DIR = ../../../bin/

 ## Kernel settings
-KERNEL_DIR = c:/git-repo/Uzebox/uzebox/kernel
+KERNEL_DIR = ../../../kernel
 KERNEL_OPTIONS  = -DVIDEO_MODE=3 -DINTRO_LOGO=0 -DSCROLLING=1 -DSOUND_MIXER=1 -DSOUND_CHANNEL_5_ENABLE=0
 KERNEL_OPTIONS += -DUART=1 -DDEBUG=1 -DUART_RX_BUFFER_SIZE=64 -DUART_TX_BUFFER_SIZE=64
 KERNEL_OPTIONS += -DMAX_SPRITES=18 -DRAM_TILES_COUNT=23 -DSCREEN_TILES_V=27 -DFIRST_RENDER_LINE=24
@@ -57,7 +57,7 @@ LINKONLYOBJECTS =
 INCLUDES = -I"$(KERNEL_DIR)" 

 ## Build
-all: $(TARGET) $(GAME).HEX $(GAME).eep $(GAME).lss $(GAME).UZE size
+all: $(TARGET) $(GAME).hex $(GAME).eep $(GAME).lss $(GAME).uze size

 ## Compile Kernel files
 uzeboxVideoEngineCore.o: $(KERNEL_DIR)/uzeboxVideoEngineCore.s
@@ -83,7 +83,7 @@ $(GAME).o: ../gghost.c
 $(TARGET): $(OBJECTS)
     $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)

-%.HEX: $(TARGET)
+%.hex: $(TARGET)
    avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@

 %.eep: $(TARGET)
@@ -92,8 +92,8 @@ $(TARGET): $(OBJECTS)
 %.lss: $(TARGET)
    avr-objdump -h -S $< > $@

-%.UZE: $(TARGET)
-   -$(UZEBIN_DIR)packrom $(GAME).HEX $@ $(INFO)
+%.uze: $(TARGET)
+   -$(UZEBIN_DIR)packrom $(GAME).hex $@ $(INFO)

 UNAME := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 AVRSIZEFLAGS := -A ${TARGET}
@@ -108,7 +108,7 @@ size: ${TARGET}
 ## Clean target
 .PHONY: clean
 clean:
-   -rm -rf $(OBJECTS) $(GAME).* dep/* *.UZE
+   -rm -rf $(OBJECTS) $(GAME).* dep/* *.uze

 ## Other dependencies```
artcfox commented 4 years ago

gghost-tileset

kivan117 commented 4 years ago

Oof, hard coded windows directories :/ Good catch. I'll have to update that I guess.

The letters being scrambled is interesting. It's clearly trying to correctly Print the string. You can see it's repeating identical bad data for repeat string characters. It looks like I was only using SetFontTilesIndex instead of SetFontTable or some other method to specify where to grab font tiles from. This might have relied on some (now broken) assumption about tile memory layout, or a quirk of the kernel build I was using.

Wish I could be more helpful but I'll have to setup a new Uzebox dev environment before I can really dig into any of this.

artcfox commented 4 years ago

Copying all of the font tile data into the title_tiles[] array at the end (making sure to add a comma before the font tiles) fixed the scrambled fonts, but I noticed if I interrupt the uzebox logo screen the ghost doesn't go away, and draws over top of the menu, and there is some other corruption that looks like the sprites aren't being hidden.

kivan117 commented 4 years ago

Really? The draw menu function should be calling a helper sub function to draw the outside frame. During that routine the first step is SetSpriteVisibility(false). The frame is clearly drawn in the screen shot you sent, so we know that is being called properly.

I'll setup a Linux VM dev environment and sort this all out in the near future. A lot of little stuff seems to be broken now.

This code could use a solid cleanup anyway. No reason people should be trudging through 1200 lines in a single file.

artcfox commented 4 years ago

Here are some of the glitches I'm still seeing after making those Makefile changes and moving the font tiles to the end of the title_tiles array: https://youtu.be/-ae1IQ3ZTmc https://youtu.be/TmgNwYV-PWo

Whenever I re-setup a uzebox dev environment for myself I use the commands that I copied and pasted into the description of this video I made: https://www.youtube.com/watch?v=vT2TUSZWDf8&list=PLmw_SSuraf8smbS3K22i--Bl2vaeW5Dsk

I haven't tried compiling it with an older compiler.

kivan117 commented 4 years ago

Sprite visibility isn't being set to false on menus, and it looks like the tileset isn't being switched over from the menu to the gameplay tile set in the second glitch.

Additionally, the parallax effect of the city tiles isn't working.

Similar to fonts, the parallax relied on updating a starting offset value in tile memory.

Thanks for the assistance in identifying the glitches.

danboid commented 4 years ago

Thanks for looking into this @artcfox !

After making your suggested changes to the makefile and copying the font tile data I have got it to build but the game doesn't start, instead I get a messed up loading screen under cuzebox.

I'll try again when @kivan117 has had a chance to update it.

EDIT

I didn't switch branch before adjusting the makefile which will explain my problem.

danboid commented 4 years ago

After starting over using the localonly branch and applying Matt's tiles fix, I can confirm it both builds and I can start the game but yeah, it's pretty glitchy.

danboid commented 2 years ago

I think I've found the fix for the messed up text. Replace:

CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-inline ##-mcall-prologues

With

CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=28636360UL -Os -fsigned-char -ffunction-sections -fno-toplevel-reorder

in the Makefile.

danboid commented 1 year ago

Hi @kivan117

Just to let you know that I recently updated the Uzebox getting started guide with a Tutorials section and I've linked to Ghosty ghost as the best example of a well commented Uzebox game so it'd be great if you could update it to get it building cleanly.

You should find it easier to get a Uzebox dev environment set up from the revised wiki instructions. I wrote the Linux guide and Uze revised the Windows instructions recently.

https://uzebox.org/wiki/Getting_Started_on_the_Uzebox