├── .gitignore ├── Makefile ├── data ├── gfx │ ├── bank_offer_menu_bg_map.bin │ ├── bank_repay_menu_bg_map.bin │ ├── budget_menu_bg_map.bin │ ├── build_select_sprites.bin │ ├── city_stats_bg_map.bin │ ├── city_tiles.bin │ ├── credits_bg_map.bin │ ├── cursor_tiles.bin │ ├── graphs_menu_map.bin │ ├── graphs_menu_tiles.bin │ ├── info_bar_game_map.bin │ ├── main_menu_bg_map.bin │ ├── map_gen_minimap_bg_map.bin │ ├── map_scenario_select_bg_map.bin │ ├── minimap_bg_map.bin │ ├── minimap_menu_map.bin │ ├── minimap_menu_tiles.bin │ ├── minimap_tiles.bin │ ├── only_for_gbc_bg_map.bin │ ├── options_menu_bg_map.bin │ ├── save_menu_error_map.bin │ ├── save_menu_map.bin │ ├── scenario_0_rock_river_attr.bin │ ├── scenario_0_rock_river_map.bin │ ├── scenario_1_boringtown_attr.bin │ ├── scenario_1_boringtown_map.bin │ ├── scenario_2_portville_attr.bin │ ├── scenario_2_portville_map.bin │ ├── scenario_3_newdale_attr.bin │ ├── scenario_3_newdale_map.bin │ ├── text_input_bg_map.bin │ ├── text_tiles.bin │ ├── tilte_screen_map.bin │ └── title_screen_tiles.bin └── music │ ├── song_city.asm │ ├── song_menu.asm │ └── song_title.asm ├── docs ├── animated-graphics.rst ├── apa-graphics.rst ├── bcd.rst ├── compression.rst ├── engine.rst ├── game-rooms.rst ├── general.rst ├── index.rst ├── main-loop.rst ├── map-edition.rst ├── map-generation.rst ├── power-grid.rst ├── saved-data.rst ├── simulation-buildings.rst ├── simulation-disasters.rst ├── simulation-general.rst ├── text-management.rst └── traffic.rst ├── gpl-3.0.txt ├── manual.rst ├── readme.rst ├── resources ├── gfx │ ├── bank_offer_menu_bg.gbm │ ├── bank_repay_menu_bg.gbm │ ├── budget_menu_bg.gbm │ ├── build_select_sprites.gbm │ ├── build_select_sprites.gbr │ ├── city_stats_menu_bg.gbm │ ├── city_tiles.gbr │ ├── credits_bg.gbm │ ├── graphs_menu_tiles.gbm │ ├── graphs_menu_tiles.gbr │ ├── info_bar_room_game.gbm │ ├── main_menu_bg.gbm │ ├── map_gen_minimap_bg.gbm │ ├── map_scenario_select_bg.gbm │ ├── minimap_bg.gbm │ ├── minimap_menu_tiles.gbm │ ├── minimap_menu_tiles.gbr │ ├── minimap_tiles.gbr │ ├── only_for_gbc_bg.gbm │ ├── options_menu_bg.gbm │ ├── save_menu_bg.gbm │ ├── save_menu_error_bg.gbm │ ├── scenario_0_rock_river.gbm │ ├── scenario_1_boringtown.gbm │ ├── scenario_2_portville.gbm │ ├── scenario_3_newdale.gbm │ ├── test_gfx │ │ └── test_city_map.gbm │ ├── text_input_bg.gbm │ ├── title_screen_map.gbm │ ├── title_screen_tiles.gbr │ └── txt.gbr └── music │ ├── city.mod │ ├── convert_songs.sh │ ├── menu.mod │ └── title.mod ├── screenshot.png ├── source ├── apa.asm ├── apa.inc ├── bcd_math.asm ├── bg_handler.asm ├── bg_handler_main.asm ├── engine │ ├── engine.inc │ ├── gbt_player.asm │ ├── gbt_player.inc │ ├── gbt_player_bank1.asm │ ├── hardware.inc │ ├── init.asm │ ├── rand.asm │ ├── utils.asm │ └── video.asm ├── main.asm ├── math.asm ├── money.asm ├── money.inc ├── rlediff.asm ├── room_bank │ └── room_bank.asm ├── room_budget │ └── room_budget.asm ├── room_city_stats │ └── room_city_stats.asm ├── room_credits │ └── room_credits.asm ├── room_game │ ├── build_menu.asm │ ├── building_info.asm │ ├── building_info.inc │ ├── cursor.asm │ ├── date.asm │ ├── draw_building.asm │ ├── draw_common.asm │ ├── draw_port.asm │ ├── draw_power_lines.asm │ ├── draw_road.asm │ ├── draw_train.asm │ ├── map_load.asm │ ├── map_load.inc │ ├── message_box.asm │ ├── persistent_messages.asm │ ├── room_game.asm │ ├── room_game.inc │ ├── sram_map_handle.asm │ ├── status_bar_menu.asm │ ├── text_messages.asm │ ├── text_messages.inc │ ├── tileset.asm │ ├── tileset_info.asm │ ├── tileset_info.inc │ └── tileset_text.asm ├── room_gbc_only │ └── room_gbc_only.asm ├── room_gen_map │ ├── gen_map.asm │ ├── gen_map_circle.inc │ └── room_gen_map.asm ├── room_graphs │ ├── graph_money.asm │ ├── graph_population.asm │ ├── graph_rci.asm │ ├── graphs_handle.asm │ ├── graphs_menu.asm │ ├── room_graphs.asm │ └── room_graphs.inc ├── room_menu │ └── room_menu.asm ├── room_minimap │ ├── minimap_disasters.asm │ ├── minimap_happiness.asm │ ├── minimap_menu.asm │ ├── minimap_overview.asm │ ├── minimap_pollution.asm │ ├── minimap_population.asm │ ├── minimap_power.asm │ ├── minimap_services.asm │ ├── minimap_traffic.asm │ ├── minimap_transport_map.asm │ ├── minimap_zone_map.asm │ ├── room_minimap.asm │ └── room_minimap.inc ├── room_options │ └── room_options.asm ├── room_save_menu │ └── room_save_menu.asm ├── room_scenarios │ └── room_scenarios.asm ├── room_text_input │ ├── room_text_input.asm │ └── room_text_input.inc ├── room_title │ └── room_title.asm ├── save_struct.asm ├── save_struct.inc ├── sfx.asm ├── simulation │ ├── building_density.asm │ ├── queue.asm │ ├── simulation_anim_boats.inc │ ├── simulation_anim_planes.inc │ ├── simulation_anim_trains.inc │ ├── simulation_building_count.asm │ ├── simulation_calculate_stats.asm │ ├── simulation_create_buildings.asm │ ├── simulation_fire.asm │ ├── simulation_meltdown.asm │ ├── simulation_money.asm │ ├── simulation_pollution.asm │ ├── simulation_power.asm │ ├── simulation_services.asm │ ├── simulation_technology.asm │ ├── simulation_traffic.asm │ ├── simulation_traffic_trip.asm │ ├── simulation_transport_anims.asm │ └── simulation_water.asm ├── sram_utils.asm ├── text.asm └── text.inc └── tools ├── compress ├── compile.sh ├── convert-all.sh ├── convert.sh ├── extractbit3.c ├── filediff.c ├── license.txt └── rle.c ├── gbmb-1.8 ├── gbmb.cnt ├── gbmb.exe ├── gbmb.gid ├── gbmb.hlp └── readme_mb.txt ├── gbtd-2.2 ├── file_id.diz ├── gbtd.cnt ├── gbtd.exe ├── gbtd.gid ├── gbtd.hlp └── readme.txt ├── lut_gens ├── gen_bin2bcd.c ├── gen_bit_count.c ├── gen_build_prob.c ├── gen_circle.c ├── gen_mask.c └── gen_shift_table.c ├── mapgen └── mapgen.c └── mod2gbt ├── build.sh ├── mod2gbt.c └── mod_instructions.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ucity.sav 2 | ucity.gbc 3 | ucity.sym 4 | ucity.map 5 | ucity_compat.sav 6 | ucity_compat.gbc 7 | *.obj 8 | tools/mod2gbt/mod2gbt 9 | tools/compress/extractbit3 10 | tools/compress/filediff 11 | tools/compress/rle 12 | tools/gbmb-1.8/gbmb.ini 13 | tools/gbtd-2.2/gbtd.ini 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # µCity - City building game for Game Boy Color. 4 | # Copyright (c) 2017-2019 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | ################################################################################ 20 | ## ROM name ## 21 | 22 | NAME := ucity 23 | EXT := gbc 24 | 25 | ################################################################################ 26 | ## Command to run resulting ROM in an emulator ## 27 | 28 | EMULATOR := wine ./tools/bgb.exe 29 | 30 | ################################################################################ 31 | ## Source, data and include folders - subfolders are included ## 32 | 33 | SOURCE := source data 34 | 35 | ################################################################################ 36 | 37 | # RGBDS can be made to point at a specific folder with the binaries of RGBDS. 38 | 39 | RGBASM := $(RGBDS)rgbasm 40 | RGBLINK := $(RGBDS)rgblink 41 | RGBFIX := $(RGBDS)rgbfix 42 | 43 | BIN := $(NAME).$(EXT) 44 | COMPAT_BIN := $(NAME)_compat.$(EXT) 45 | 46 | # List of relative paths to all folders and subfolders with code or data. 47 | SOURCE_ALL_DIRS := $(sort $(shell find $(SOURCE) -type d -print)) 48 | 49 | # All files with extension asm are assembled. 50 | ASMFILES := $(foreach dir,$(SOURCE_ALL_DIRS),$(sort $(wildcard $(dir)/*.asm))) 51 | 52 | # List of include directories: All source and data folders. 53 | # A '/' is appended to the path. 54 | INCLUDES := $(foreach dir,$(SOURCE_ALL_DIRS),-I$(dir)/) 55 | 56 | # Prepare object paths from source files. 57 | OBJ := $(ASMFILES:.asm=.obj) 58 | 59 | # Targets 60 | .PHONY : all rebuild clean run 61 | 62 | all: $(BIN) $(COMPAT_BIN) 63 | 64 | rebuild: 65 | @make -B 66 | @rm -f $(OBJ) 67 | 68 | run: $(BIN) 69 | $(EMULATOR) $(BIN) 70 | 71 | clean: 72 | @echo rm $(OBJ) $(BIN) $(COMPAT_BIN) $(NAME).sym $(NAME).map 73 | @rm -f $(OBJ) $(BIN) $(COMPAT_BIN) $(NAME).sym $(NAME).map 74 | 75 | %.obj : %.asm 76 | @echo rgbasm $< 77 | @$(RGBASM) $(INCLUDES) -E -o$@ $< 78 | 79 | $(BIN): $(OBJ) 80 | @echo rgblink $(BIN) 81 | @$(RGBLINK) -o $(BIN) -p 0xFF -m $(NAME).map -n $(NAME).sym $(OBJ) 82 | @echo rgbfix $(BIN) 83 | @$(RGBFIX) -p 0xFF -v $(BIN) 84 | 85 | $(COMPAT_BIN): $(BIN) 86 | @echo rgbfix $(COMPAT_BIN) 87 | @cp $(BIN) $(COMPAT_BIN) 88 | @$(RGBFIX) -v -O -r 3 $(COMPAT_BIN) 89 | 90 | ################################################################################ 91 | -------------------------------------------------------------------------------- /data/gfx/bank_offer_menu_bg_map.bin: -------------------------------------------------------------------------------- 1 | 5555555555555555555555555555Mfsp5555555555555555::::55555555555555555555555555555btzqi5~tz5qnpj5yt555ljy5f5qtfs?5555555555555555555555555555555555555555555555555=5Lrtzsy<555CBBBB55555[f~rjsyx<5555DC55555Pfhm<5555555GBB55555_tyfq<5555CBGBB5555555555555555555555555Lrtzsy<555DBBBB55555[f~rjsyx<5555DC55555Pfhm<555555CBBB55555_tyfq<5555DCBBB5555555555555555555555 -------------------------------------------------------------------------------- /data/gfx/bank_repay_menu_bg_map.bin: -------------------------------------------------------------------------------- 1 | 5555555555555555555555555555Mfsp5555555555555555::::55555555555555555555555555555dtz5hfs>y5ljy5f55555sj|5qtfs5zsynq5~tz55wjuf~5~tzw5qfxy55555tsj<555555555555555555555555555555555555555555555555555555555555555555555555555555[f~rjsyx<5555BB55555Pfhm<555555BBBB55555_tyfq<5555BBBBB5555555555555555555555555555555555555555555555555555555555555555555555555555555555 -------------------------------------------------------------------------------- /data/gfx/budget_menu_bg_map.bin: -------------------------------------------------------------------------------- 1 | 555555555555555555555555555Mziljy55555555555555::::::5555555555555555555555555555_f}jx55555555=DB'=555]NT55555555BBBBBB555Zymjw555555BBBBBB5555555555555555555555Ntxyx5555555555555555[tqnhj55555BBBBBB555Qnwjrjs5555BBBBBB555Sjfqymhfwj5BBBBBB555Pizhfynts55BBBBBB555_wfsxutwy55BBBBBB555Wtfsx555555BBBBBB5555555555555555555555_tyfq555BBBBBBBBBB555555555555555555555' -------------------------------------------------------------------------------- /data/gfx/build_select_sprites.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/build_select_sprites.bin -------------------------------------------------------------------------------- /data/gfx/city_stats_bg_map.bin: -------------------------------------------------------------------------------- 1 | 5555555555555555555555Nny~5^yfynxynhx555555555555555555555555Yfrj<555555555555555[tuzq9<5BBBBBBBBBB55Nqfxx<55555anqqflj55Ofyj<55555Ufs5CKGB55Qzsix<55BBBBBBBBBB5555555555555555555555Mznqy5Wfsi<555BBB'555]jxnijsynfq<5BBB'555Ntrrjwhnfq<55BBB'555Tsizxywnfq<55BBB'5555555555555555555555Snlm5_wfkknh<5BBB'5555555555555555555555[tqqzyji<55555BBB'555555555555555555555 -------------------------------------------------------------------------------- /data/gfx/city_tiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/city_tiles.bin -------------------------------------------------------------------------------- /data/gfx/credits_bg_map.bin: -------------------------------------------------------------------------------- 1 | 555555555555555555555#Nny~575DBCI(DBCJ55555555555555555555555Lsytsnt5YnAt5Onf55555555555555555555555LsytsntYO6^p~W~wfh5555555555555555555555fsytsnt:si;5555555555555555tzyqttp9htr5555555555555555555555|||9xp~q~wfh9sjy555555555555555555555555[wtlwfr5qnhjsxji555555555555555555555555zsijw5ymj5yjwrx5tk5555555555555555555555ymj5RY`5R[W{E"9555555555555555555555555 -------------------------------------------------------------------------------- /data/gfx/cursor_tiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/cursor_tiles.bin -------------------------------------------------------------------------------- /data/gfx/graphs_menu_map.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/graphs_menu_map.bin -------------------------------------------------------------------------------- /data/gfx/graphs_menu_tiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/graphs_menu_tiles.bin -------------------------------------------------------------------------------- /data/gfx/info_bar_game_map.bin: -------------------------------------------------------------------------------- 1 | Qzsix(895555555555555555555555^ufhj5555555555Psi555555555555555555555'Gg -------------------------------------------------------------------------------- /data/gfx/text_tiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/text_tiles.bin -------------------------------------------------------------------------------- /data/gfx/tilte_screen_map.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /data/gfx/title_screen_tiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/data/gfx/title_screen_tiles.bin -------------------------------------------------------------------------------- /data/music/song_menu.asm: -------------------------------------------------------------------------------- 1 | 2 | ; File created by mod2gbt 3 | 4 | SECTION "song_menu_0",ROMX 5 | song_menu_0: 6 | DB $20, $9F,$18, $20, $4A,$04 7 | DB $00, $20, $00, $20 8 | DB $00, $00, $00, $00 9 | DB $00, $00, $00, $00 10 | DB $00, $9F,$18, $00, $00 11 | DB $00, $20, $00, $00 12 | DB $00, $9A,$18, $00, $00 13 | DB $00, $20, $00, $00 14 | DB $00, $9F,$18, $00, $00 15 | DB $00, $20, $00, $00 16 | DB $00, $00, $00, $00 17 | DB $00, $00, $00, $00 18 | DB $00, $9A,$18, $00, $00 19 | DB $00, $20, $00, $00 20 | DB $00, $00, $00, $00 21 | DB $00, $00, $00, $00 22 | DB $00, $00, $00, $00 23 | DB $00, $00, $00, $00 24 | DB $00, $00, $00, $00 25 | DB $00, $00, $00, $00 26 | DB $00, $9F,$18, $00, $00 27 | DB $00, $20, $00, $00 28 | DB $00, $00, $00, $00 29 | DB $00, $00, $00, $00 30 | DB $00, $A2,$18, $00, $00 31 | DB $00, $20, $00, $00 32 | DB $00, $00, $00, $00 33 | DB $00, $00, $00, $00 34 | DB $00, $00, $00, $00 35 | DB $00, $00, $00, $00 36 | DB $00, $00, $00, $00 37 | DB $00, $00, $00, $00 38 | DB $00, $9F,$18, $00, $00 39 | DB $00, $20, $00, $00 40 | DB $00, $00, $00, $00 41 | DB $00, $00, $00, $00 42 | DB $00, $9F,$18, $00, $00 43 | DB $00, $20, $00, $00 44 | DB $00, $9A,$18, $00, $00 45 | DB $00, $20, $00, $00 46 | DB $00, $9F,$18, $00, $00 47 | DB $00, $20, $00, $00 48 | DB $00, $00, $00, $00 49 | DB $00, $00, $00, $00 50 | DB $00, $9A,$18, $00, $00 51 | DB $00, $20, $00, $00 52 | DB $00, $00, $00, $00 53 | DB $00, $00, $00, $00 54 | DB $00, $00, $00, $00 55 | DB $00, $00, $00, $00 56 | DB $00, $00, $00, $00 57 | DB $00, $00, $00, $00 58 | DB $00, $9F,$18, $00, $00 59 | DB $00, $20, $00, $00 60 | DB $00, $00, $00, $00 61 | DB $00, $00, $00, $00 62 | DB $00, $9A,$18, $00, $00 63 | DB $00, $20, $00, $00 64 | DB $00, $00, $00, $00 65 | DB $00, $00, $00, $00 66 | DB $00, $00, $00, $00 67 | DB $00, $00, $00, $00 68 | DB $00, $00, $00, $00 69 | DB $00, $00, $00, $00 70 | 71 | SECTION "song_menu_1",ROMX 72 | song_menu_1: 73 | DB $20, $9F,$18, $9F,$22, $4A,$04 74 | DB $00, $20, $20, $20 75 | DB $00, $00, $00, $00 76 | DB $00, $00, $00, $00 77 | DB $00, $9F,$18, $9F,$22, $00 78 | DB $00, $20, $20, $00 79 | DB $00, $9A,$18, $00, $00 80 | DB $00, $20, $00, $00 81 | DB $00, $9F,$18, $00, $00 82 | DB $00, $20, $00, $00 83 | DB $00, $00, $00, $00 84 | DB $00, $00, $00, $00 85 | DB $00, $9A,$18, $00, $00 86 | DB $00, $20, $00, $00 87 | DB $00, $00, $00, $00 88 | DB $00, $00, $00, $00 89 | DB $00, $00, $00, $00 90 | DB $00, $00, $00, $00 91 | DB $00, $00, $00, $00 92 | DB $00, $00, $00, $00 93 | DB $00, $9F,$18, $9F,$22, $00 94 | DB $00, $20, $20, $00 95 | DB $00, $00, $00, $00 96 | DB $00, $00, $00, $00 97 | DB $00, $A2,$18, $A2,$22, $00 98 | DB $00, $20, $20, $00 99 | DB $00, $00, $00, $00 100 | DB $00, $00, $00, $00 101 | DB $00, $00, $00, $00 102 | DB $00, $00, $00, $00 103 | DB $00, $00, $00, $00 104 | DB $00, $00, $00, $00 105 | DB $00, $9F,$18, $9F,$22, $00 106 | DB $00, $20, $20, $00 107 | DB $00, $00, $00, $00 108 | DB $00, $00, $00, $00 109 | DB $00, $9F,$18, $9F,$22, $00 110 | DB $00, $20, $20, $00 111 | DB $00, $9A,$18, $00, $00 112 | DB $00, $20, $00, $00 113 | DB $00, $9F,$18, $00, $00 114 | DB $00, $20, $00, $00 115 | DB $00, $00, $00, $00 116 | DB $00, $00, $00, $00 117 | DB $00, $9A,$18, $00, $00 118 | DB $00, $20, $00, $00 119 | DB $00, $00, $00, $00 120 | DB $00, $00, $00, $00 121 | DB $00, $00, $00, $00 122 | DB $00, $00, $00, $00 123 | DB $00, $00, $00, $00 124 | DB $00, $00, $00, $00 125 | DB $00, $9F,$18, $9F,$22, $00 126 | DB $00, $20, $20, $00 127 | DB $00, $00, $00, $00 128 | DB $00, $00, $00, $00 129 | DB $00, $9A,$18, $9A,$22, $00 130 | DB $00, $20, $20, $00 131 | DB $00, $00, $00, $00 132 | DB $00, $00, $00, $00 133 | DB $00, $00, $00, $00 134 | DB $00, $00, $00, $00 135 | DB $00, $00, $00, $00 136 | DB $00, $00, $00, $00 137 | 138 | SECTION "song_menu_data",ROMX 139 | song_menu_data:: 140 | DB BANK(song_menu_0) 141 | DW song_menu_0 142 | DB BANK(song_menu_1) 143 | DW song_menu_1 144 | DB BANK(song_menu_1) 145 | DW song_menu_1 146 | DB $00 147 | DW $0000 148 | 149 | -------------------------------------------------------------------------------- /docs/apa-graphics.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | All Points Addressable Graphs 3 | ============================= 4 | 5 | As the Game Boy Color doesn't have any bitmap modes, it is needed to implement 6 | it by software. This mode is used when drawing minimaps and graphs showing the 7 | evolution of something over time. Note that the buffer can be either 64x64 or 8 | 128x128 pixels in size. There is no 160x144 mode. 9 | 10 | The code is located in: 11 | 12 | - ``source/apa.asm`` : Implementation of the routines needed to plot pixels. 13 | The functions allow to plot individual pixels in the buffer, but this system 14 | is quite slow, so there are also functions to stream pixels (from left to 15 | right and top to bottom), which is a lot faster if the final image is known 16 | beforehand. 17 | 18 | - ``source/apa.inc`` : Some definitions related to the implementation. 19 | 20 | Usage guide 21 | =========== 22 | 23 | All functions work on a temporary buffer at address ``MINIMAP_BACKBUFFER_BASE`` 24 | in ``WRAMX`` bank ``MINIMAP_BACKBUFFER_WRAMX_BANK`` which is used as backbuffer 25 | so as not to show graphical glitches while drawing. This buffer is then copied 26 | to tiles 128-383 of ``VRAM`` bank 1. 27 | 28 | The first thing to do is to prepare the map with ``APA_ResetBackgroundMapping`` 29 | if needed, it fills a 16x16 block of tiles with the correct indexes and 30 | attributes. The alternative is to design your map with the same values. 31 | 32 | At some point it is needed to load the palette with ``APA_LoadPalette``. It can 33 | be done before drawing the map, after doing it, or it can be set to black/white 34 | before drawing and set to the real colors when the image is drawn. 35 | 36 | Then, unless all pixels are going to be drawn, it is needed to clear the map 37 | with ``APA_BufferClear`` or ``APA_BufferFillColor3``. It may be a good idea to 38 | update the visualization with ``APA_BufferUpdate`` at this point, unless showing 39 | the previous image isn't a problem. 40 | 41 | Then, depending on the type of drawing, there are two options: 42 | 43 | - If the image consists on just a few points around the picture, ``APA_Plot`` is 44 | probably the fastest way to do it. With it, it is possible to plot individual 45 | pixels in the map. It only works in 128x128 maps, though. 46 | 47 | - If all the pixels are going to be redrawn, it is possible to stream pixels in 48 | rows (left to right, top to bottom). For that, ``APA_PixelStreamStart`` has to 49 | be called at the beginning. Then, if the map is 128x128, it is possible to 50 | draw 2x2 pixel blocks with ``APA_PixelStreamPlot2x2`` (so the effective 51 | resolution is 64x64). If the map is 64x64, ``APA_64x64PixelStreamPlot`` can be 52 | used instead. 53 | 54 | Note that the plot functions don't accept a color as an argument. For functions 55 | ``APA_Plot`` and ``APA_64x64PixelStreamPlot`` the correct function is 56 | ``APA_SetColor0``, which sets the color that is going to be used from that 57 | moment on. For ``APA_PixelStreamPlot2x2``, ``APA_SetColors`` sets the color of 58 | each one of the 4 pixels that are drawn at once (top left, top right, bottom 59 | left, bottom right). 60 | 61 | Once the image is drawn, ``APA_BufferUpdate`` will copy it from the temporary 62 | buffer to ``VRAM``. 63 | 64 | Examples 65 | ======== 66 | 67 | This mode is used by the following files: 68 | 69 | - ``source/room_gen_map/gen_map.asm`` : 64x64 minimap shown when generating 70 | random maps. It uses a pixel stream to draw the minimap. 71 | 72 | - ``source/room_scenarios/room_scenarios.asm`` : 64x64 minimap shown when 73 | selecting scenarios. Same as the previous example, pixel stream. 74 | 75 | - ``source/room_minimap/minimap_***.asm`` : 128x128 minimaps shown in-game from 76 | the pause menu (zones, traffic, population density, etc). It uses a pixel 77 | stream of 2x2 blocks. Note that the tile map of this background doesn't have 78 | the correct values to display the final image, so 79 | ``APA_ResetBackgroundMapping`` must be used to update the tile indices (it is 80 | done in ``source/room_minimap/room_minimap.asm``). The list of all available 81 | maps is in ``source/room_minimap/room_minimap.inc``. 82 | 83 | Note that ``source/room_minimap/minimap_menu.asm`` isn't included in this 84 | category, that file has code to handle the menu that allows the player to 85 | select the minimap to be shown. 86 | 87 | - ``source/room_graphs/graph_***.asm`` : 128x128 graphs shown in-game (funds, 88 | population, etc). In this case, ``APA_Plot`` is used, as most of the image is 89 | left blank. The list of all available graphs is in 90 | ``source/room_graphs/room_graphs.inc``. 91 | 92 | Note that ``source/room_graphs/graphs_menu.asm`` isn't included either, it 93 | handles the menu of this room. 94 | -------------------------------------------------------------------------------- /docs/bcd.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | BCD Math 3 | ======== 4 | 5 | Most big numbers in the game are stored in BCD format. Examples of this are 6 | money amounts or city populations. The reason for doing it this way is that it 7 | simplifies the display of the values on the screen for the player to see. As 8 | most of the operations that are done on huge numbers are really simple, this 9 | format doesn't cause a big loss in performance over plain binary. 10 | 11 | The code is located in ``source/bcd_math.asm``. 12 | 13 | BCD numbers are 5 bytes wide, LSB stored first. Inside a byte, the lower nibble 14 | is the least significant digit of the two. They can be interpreted as signed or 15 | unsigned values. 16 | 17 | For example, the unsigned decimal value ``123456789`` would be stored in memory 18 | like this: 19 | 20 | ``DB $89,$67,$45,$23,$01`` 21 | 22 | Signed values are stored in tens' complement format, similar to the two's 23 | complement format used for regular values: 24 | 25 | +--------------+-------------+ 26 | | -50000000000 | $5000000000 | 27 | +--------------+-------------+ 28 | | -49999999999 | $5000000001 | 29 | +--------------+-------------+ 30 | | -49999999998 | $5000000002 | 31 | +--------------+-------------+ 32 | | ... | ... | 33 | +--------------+-------------+ 34 | | -9999999999 | $9000000001 | 35 | +--------------+-------------+ 36 | | ... | ... | 37 | +--------------+-------------+ 38 | | -2 | $9999999998 | 39 | +--------------+-------------+ 40 | | -1 | $9999999999 | 41 | +--------------+-------------+ 42 | | 0 | $0000000000 | 43 | +--------------+-------------+ 44 | | +1 | $0000000001 | 45 | +--------------+-------------+ 46 | | +2 | $0000000002 | 47 | +--------------+-------------+ 48 | | ... | ... | 49 | +--------------+-------------+ 50 | | +9999999999 | $0999999999 | 51 | +--------------+-------------+ 52 | | ... | ... | 53 | +--------------+-------------+ 54 | | +49999999998 | $4999999998 | 55 | +--------------+-------------+ 56 | | +49999999999 | $4999999999 | 57 | +--------------+-------------+ 58 | 59 | However, in game, numbers saturate at +/-0999999999. This is done to make sure 60 | that the number always fits in a string with 10 bytes allocated, including the 61 | minus sign for negative numbers. 62 | 63 | The current library implements a few common operations to make it easier to use 64 | this kind of format. There are helpers for simple operations like addition, 65 | subtraction and sign change. There are also two helpers to compare numbers. One 66 | of them tests if a number is lower than zero, the other one tests if one of them 67 | is greater or equal than the other one. There's also a helper to multiply a BCD 68 | number by a 8-bit non-BCD value (it just adds the same value repeatedly). 69 | 70 | Addition of signed numbers works the same way as two's complement and it is as 71 | simple as addition of unsigned numbers. Note that, since the numbers are stored 72 | in BCD, after every addition or subtraction instruction (``add``, ``adc``, 73 | ``sub``, ``sbc``) it is needed to add a ``daa`` instruction. 74 | 75 | +---------------+-----------------+ 76 | | 5 + (-7) = -2 | $05 + $93 = $98 | 77 | +---------------+-----------------+ 78 | | -2 + 2 = 0 | $98 + $02 = $00 | 79 | +---------------+-----------------+ 80 | 81 | Of course, it is needed to convert from this format to something that can be 82 | represented on the screen. There are 3 helpers to achieve this. All of them read 83 | the original 5-byte value and output a 10-byte character string. One of them 84 | prints an unsigned value including leading zeros, other prints them as spaces 85 | (except if there is only one zero to be printed!). The last helper prints a 86 | signed number including the minus sign if needed. 87 | 88 | There's also a LUT that can be used to convert an 8-bit value into BCD, useful 89 | to convert small binary values to BCD before operating on them. 90 | -------------------------------------------------------------------------------- /docs/compression.rst: -------------------------------------------------------------------------------- 1 | ======================== 2 | Scenario Map Compression 3 | ======================== 4 | 5 | In order to save some memory in ROM, scenarios are compressed before including 6 | them and uncompressed when they are going to be used. 7 | 8 | The code for the compression tools is located in ``tools/compression``. It has 9 | the following files: 10 | 11 | - ``compile.sh``: Script to compile all tools in Linux. 12 | 13 | - ``convert.sh``: Script to convert a single binary file of a map into the two 14 | output compressed files (tile map and attribute map). 15 | 16 | - ``convert-all.sh``: Script used to convert all scenarios to the corresponding 17 | compressed files. 18 | 19 | - ``extractbit3.c``: Sets to 0 all bits but bit 3 of each byte of a file. 20 | 21 | - ``filediff.c``: Calculate file formed by the relative increments of each byte 22 | of the original file. 23 | 24 | - ``rle.c``: External RLE compressor licensed under the license GPLv3+ (with a 25 | few modifications to compile on Linux). 26 | 27 | On average, tile maps are compressed to 60-80% of their original size. Attribute 28 | maps are compressed a lot more, to around 5-15% of their size. This is even 29 | better than just packing the bit 3 of the attribute map (the top bit of the tile 30 | index). If 8 bits are packed into each byte, the result is 12.5% of the original 31 | size. 32 | 33 | The compression process is the following one: 34 | 35 | 1. GBMB exports a single file with tile map followed by attribute map. 36 | 37 | 2. That binary file is split into 2 halves (tile map and attribute map). 38 | 39 | 3. The attribute map is passed to ``extractbit3`` to remove useless information. 40 | The palette information can be regenerated ingame when the scenario is 41 | loaded. The original attribute map is removed. 42 | 43 | 4. Both files are passed as inputs to ``filediff`` to generate files in which 44 | each byte holds the difference from the previous one. This isn't a 45 | compression algorithm, but it helps a lot to compress using RLE. For example, 46 | a file with data ``05 06 06 07 04`` generates the output ``05 01 00 01 FD``. 47 | 48 | This helps the RLE compressor because the maps used by the game tend to have 49 | a lot of lines in which the same byte is used (that are transformed to an 50 | array of zeroes, still easily compressible) but also tiles that increment one 51 | by one (that are converted to a compressible array of ones instead of a lot 52 | of different numbers). 53 | 54 | 5. Both files are passed to ``rle``, which compresses them to the RLE format 55 | used by the BIOS of the GBA and NDS, chosen by its simplicity. In short, the 56 | file begins with a ``0x30`` byte followed by 3 bytes containing the raw size 57 | of the file (LSB first). Then, there are as many blocks as needed. The first 58 | byte of a block says the size of the block and if it is compressed or not. 59 | 60 | If the bit 7 of this byte is 0, this is an uncompressed block. It is followed 61 | by N+1 uncompressed bytes that must be copied as they appear in the 62 | compressed buffer. If the bit 7 is 1, this is a compressed block. It is 63 | followed by a byte that has to be repeated N+3 times. N is the value of the 64 | low 7 bits of the header of the block. 65 | 66 | The routines to decompress the data are in ``source/rlediff.asm``. First, 67 | ``RLE_Uncompress`` must be called, which will undo the RLE compression. Then, 68 | ``Diff_Uncompress`` will undo the diff filter, recreating the original file. 69 | -------------------------------------------------------------------------------- /docs/engine.rst: -------------------------------------------------------------------------------- 1 | ====== 2 | Engine 3 | ====== 4 | 5 | This file explains the code in the folder ``source/engine``. It contains a 6 | series of files with helper functions to interact with some parts of the 7 | hardware. It also describes a few other files that interact with them directly. 8 | 9 | - ``source/engine/hardware.inc`` : Definitions of registers and other values 10 | related to the hardware. This file is frequently used by Game Boy projects, 11 | but the copy available in this repository has been modified with a few 12 | changes. 13 | 14 | - ``source/engine/engine.inc`` : It contains a few useful macros and function 15 | declarations that are specific to this engine, not so much to the Game Boy. 16 | 17 | - ``source/engine/rand.asm`` : Code to generate random numbers in a quick and 18 | not too reliable way. It should be good enough for this game, though. 19 | 20 | - ``source/engine/utils.asm`` : Routines for Memory manipulation, some maths 21 | operations, joypad handling and ROM stack handling (including routines for 22 | cross-bank function calls). There are other maths operations in 23 | ``source/math.asm``, like approximate divisions for stats calculations, when 24 | the actual result doesn't matter too much. 25 | 26 | - ``source/engine/video.asm`` : Helper functions to get the state of the LCD, 27 | copy data to the VRAM and manipulate backgrounds, sprites and palettes. 28 | 29 | - ``source/engine/init.asm`` : Interrupt and restart vectors, ROM header, 30 | initialization routine, functions to setup interrupt handlers, functions to 31 | change CPU speed in GBC, stack declaration. 32 | 33 | Background handler 34 | ================== 35 | 36 | As many Game Boy games, this game needs to display backgrounds that are too big 37 | to fit the 32x32 maps that the Game Boy hardware allows. The solution is to load 38 | rows and columns of tiles as the background scrolls. 39 | 40 | The only maps with this problem are the cities themselves. The code used to load 41 | them (they can be loaded at any coordinates) and scroll them is in 42 | ``source/bg_handler.asm`` and ``source/bg_handler_main.asm``. 43 | 44 | Note that the functions in said files update the map in the VRAM, but they don't 45 | update the actual scroll registers, it is needed to call 46 | ``bg_update_scroll_registers`` from the VBL handler to do so without graphical 47 | glitches. 48 | 49 | Music and SFX 50 | ============= 51 | 52 | This folder also contains the source code of GBT Player (in files 53 | ``source/engine/gbt_player.asm``, ``source/engine/gbt_player.inc`` and 54 | ``source/engine/gbt_player_bank1.asm``). It is a separate project that is 55 | maintained in the following repository: https://github.com/AntonioND/gbt-player 56 | 57 | The player only supports music, SFXs must be implemented in a per-game basis. In 58 | this game, the code that handles SFX is in ``source/sfx.asm``. This code takes 59 | advantage of the fact that GBT Player allows the code to disable channels so 60 | that they are free to be used by other parts of the program. In this case, the 61 | SFX functions disable the channels they are going to use (and enable them after 62 | playing the SFX). 63 | 64 | Note that there is no generic way of calling this code to generate arbitrary 65 | effects, they are all defined in ``source/sfx.asm`` with some helper macros. 66 | -------------------------------------------------------------------------------- /docs/game-rooms.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | Game Rooms 3 | ========== 4 | 5 | The game is organized in rooms. A room is simply one 'screen' with its own main 6 | loop, keypress handler, etc. The game has the following rooms: 7 | 8 | Title room 9 | ========== 10 | 11 | Nothing special, it just loads a random predefined scenario and displays it 12 | along with the game title. 13 | 14 | Code: ``source/room_title/room_title.asm`` 15 | 16 | GBC only error room 17 | =================== 18 | 19 | When the game is run in a non-color Game Boy, the game enters this room (which 20 | cannot be left). It shows an error that tells the player to use a Game Boy Color 21 | instead. 22 | 23 | Code: ``source/room_gbc_only/room_gbc_only.asm`` 24 | 25 | Main menu room 26 | ============== 27 | 28 | This is the main menu, which lets the player create a new city, load a 29 | previously created city or enter the credits room. This room is entered after 30 | the title room is left. The player can return here from the regular game room, 31 | or from the game load and new city rooms. 32 | 33 | Code: ``source/room_menu/room_menu.asm`` 34 | 35 | Credits room 36 | ============ 37 | 38 | It shows the credits. When the room is left the game enters the main menu again. 39 | 40 | Code: ``source/room_credits/room_credits.asm`` 41 | 42 | Scenario load room 43 | ================== 44 | 45 | This room allows the player to load one of the predefined scenarios. 46 | 47 | Code: ``source/room_scenarios/room_scenarios.asm`` 48 | 49 | Text input room 50 | =============== 51 | 52 | This room has a virtual keyboard to let the player input text strings. It also 53 | shows a short message to remind what it is supposed to be written. This is only 54 | used to input the name of the randomly generated cities. 55 | 56 | Code: ``source/room_text_input/room_text_input.asm`` 57 | 58 | Random map generation room 59 | ========================== 60 | 61 | This room lets the player select a random seed to generate a map. 62 | 63 | Code: ``source/room_gen_map/room_gen_map.asm`` 64 | 65 | Load/Save city room 66 | =================== 67 | 68 | The code of this room is used for both selecting an empty slot to save a city or 69 | to select a filled slot to load it. It shows the appropriate number of slots 70 | according to the size of the SRAM that the cartridge has (or that the emulator 71 | has given the game). 72 | 73 | Code: ``source/room_save_menu/room_save_menu.asm`` 74 | 75 | Game room 76 | ========= 77 | 78 | This is the room where the game actually happens. The explanation about how the 79 | main loop works is in `this `_ file. 80 | 81 | The main code of the room (and main loop of the game) is in 82 | ``source/room_game/room_game.asm``. The code used to handle the status bar (and 83 | the pause menu is in ``source/room_game/status_bar_menu.asm``. The code of the 84 | menu that appears when the player has to select a building to be built is in 85 | ``source/room_game/build_menu.asm``. 86 | 87 | Note that it is possible to go back to the main menu room from here if the 88 | correct option is selected in the pause menu. 89 | 90 | This room is the only one that uses the code in ``source/room_game/cursor.asm``, 91 | with the routines that control the cursor used to scroll and build/demolish 92 | buildings in the map. 93 | 94 | Budget room 95 | =========== 96 | 97 | This room allows the player to select the amount of taxes that are be collected. 98 | It also shows the amount of money that is collected and spent in different 99 | things. 100 | 101 | Code: ``source/room_budget/room_budget.asm`` 102 | 103 | Bank room 104 | ========= 105 | 106 | This room allows the player to get a loan or shows the status of the current 107 | loan (the player can't get two loans at the same time). 108 | 109 | Code: ``source/room_bank/room_bank.asm`` 110 | 111 | Minimap room 112 | ============ 113 | 114 | This room shows different minimaps with helpful information for the player. 115 | 116 | The code of the room is in ``source/room_minimap/room_minimap.asm``. The code of 117 | the menu, in ``source/room_minimap/minimap_menu.asm``. 118 | 119 | Graphs room 120 | =========== 121 | 122 | This room shows different graphs with helpful information for the player. 123 | 124 | The code of the room is in ``source/room_graphs/room_graphs.asm``. The code of 125 | the menu, in ``source/room_graphs/graphs_menu.asm``. 126 | 127 | City stats room 128 | =============== 129 | 130 | This room shows some statistics about the city. There are some percentages that 131 | can be a bit confusing: 132 | 133 | - The percentage of built land is calculated as the number of tiles with any 134 | kind of constructions divided by the number of tiles of land. 135 | 136 | - The percentages of residential, commercial and industrial are calculated as 137 | the number of tiles of that zone type with buildings divided by the total 138 | number of tiles dedicated to that zone type. 139 | 140 | - The percentage of high traffic is just the percentage of tiles with high 141 | traffic divided by the total number of tiles with roads. 142 | 143 | Note: There is a secret in this room. If SELECT, UP, LEFT and A are held at the 144 | same time, the funds will be set to ``999999999``. 145 | 146 | Code: ``source/room_city_stats/room_city_stats.asm`` 147 | 148 | Options room 149 | ============ 150 | 151 | Allows the player to do things like disable sound or animations, or to trigger 152 | disasters (fires or nuclear meltdowns). 153 | 154 | Code: ``source/room_options/room_options.asm`` 155 | -------------------------------------------------------------------------------- /docs/general.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | General 3 | ======= 4 | 5 | This file talks about some general details about the code that don't really 6 | belong in any other file. 7 | 8 | WRAMX banks organisation 9 | ======================== 10 | 11 | While ``WRAM0`` contains the game state (including historical graphs) and is 12 | completely disorganised, most ``WRAMX`` banks have unique uses. There is some 13 | free space in ``WRAM0``, but all ``WRAMX`` banks are full. 14 | 15 | The GBC has support for 32x32 background maps. This means that if the game has 16 | to display a bigger background it needs to be placed in a different place and 17 | copied to ``VRAM`` in real time. 18 | 19 | A ``VRAM`` bank is 4 KiB in size, which is the same as 64x64. Because of this, 20 | it is really convenient to make the city maps 64x64 as well. This way it is 21 | possible to have different layers of the city in different ``WRAMX`` banks and 22 | access the data corresponding to the same tile by just switching the bank and 23 | using the same address. 24 | 25 | File ``source/room_game/room_game.inc`` contains the definitions that are 26 | referenced below. 27 | 28 | - Bank 1: City tile map. 29 | 30 | Lower 8 bits of the tile index. This is the same thing as the tile map that is 31 | stored in ``VRAM``. Done like this to increase the speed when copying it to 32 | the ``VRAM``. 33 | 34 | - Bank 2: City attribute map. 35 | 36 | Top bit of the tile index, palette, etc, in the format that the GBC expects to 37 | find in the ``VRAM``, because of the same reason it's done in the case of the 38 | tile map. 39 | 40 | - Bank 3: Tile type. 41 | 42 | The lower 5 bits correspond to the actual type of the tile (``TILE_FIELD`` to 43 | ``TILE_RADIATION``, up to a maximum of ``TYPE_NUMBER - 1``). The top 3 bits 44 | are flags that indicate whether there are roads, train tracks or power lines 45 | (``TYPE_HAS_ROAD``, ``TYPE_HAS_TRAIN``, ``TYPE_HAS_POWER``). 46 | 47 | ``TILE_FIELD`` must be 0 always so that ``TYPE_HAS_ROAD``, ``TYPE_HAS_TRAIN`` 48 | and ``TYPE_HAS_POWER`` are always considered to be in ``TYPE_FIELD``. This 49 | makes it easier to compare in some parts of the code. 50 | 51 | The exceptions are bridges, that are a combination of ``TYPE_WATER`` and the 52 | corresponding flag. 53 | 54 | - Bank 4: Traffic simulation results. 55 | 56 | This simulation is the one that takes the longest to complete. It is then 57 | useful to keep the results somewhere so that they can be reused easily, for 58 | example, when showing the traffic minimap, or when calculating the pollution 59 | of each tile. 60 | 61 | - Bank 5: Tile flags. 62 | 63 | Each bit in each tile means something different. Bits ``TILE_OK_POWER_BIT``, 64 | ``TILE_OK_SERVICES_BIT``, ``TILE_OK_EDUCATION_BIT``, ``TILE_OK_POLLUTION_BIT`` 65 | and ``TILE_OK_TRAFFIC_BIT`` indicate whether a tile has this specific need 66 | covered or not. 67 | 68 | Bits ``TILE_BUILD_REQUESTED_BIT`` and ``TILE_DEMOLISH_REQUESTED_BIT`` are 69 | commands set by the module that decides whether to build or demolish buildings 70 | in residential, commercial and industrial zones. 71 | 72 | - Bank 6: Scratch bank 1 73 | 74 | Used for intermediate calculations of the simulation. 75 | 76 | - Bank 7: Scratch bank 2 77 | 78 | Used for intermediate calculations of the simulation. Also used for the 79 | results of the `All Points Addressable module `_. 80 | 81 | Keypress autorepeat 82 | =================== 83 | 84 | File ``source/main.asm`` contains some helper functions to simulate keypresses 85 | when the user holds down any of the directions pad keys pressed. 86 | 87 | It is needed to ``InitKeyAutorepeat`` to initialize the internal variables, and 88 | ``KeyAutorepeatHandle`` must be called after scanning the keys every frame. This 89 | function modifies the internal variables used by the engine (in 90 | ``source/engine/utils.asm``). 91 | 92 | There is a starting waiting period of ``PAD_AUTOREPEAT_WAIT_INITIAL``. If a key 93 | is hold less than that, no automatic keypress is simulated. After that period is 94 | passed, a keypress is simulated, and it is repeated once every 95 | ``PAD_AUTOREPEAT_WAIT_REPEAT`` frames. 96 | 97 | Random details 98 | ============== 99 | 100 | - The city map tileset and palettes used by it is included in file 101 | ``source/room_game/tileset.asm``. This is used in the title and game rooms. 102 | 103 | - Interrupts are enabled at the beginning of ``Main`` and then they remain 104 | enabled. The code is only allowed to disable them in critical sections (like 105 | the ROM bank handler or when writing to ``VRAM``). 106 | 107 | - There is a default VBL handler (``DefaultVBLHandler``) that can be setup by 108 | calling ``SetDefaultVBLHandler``. This default handler updates the sprites, 109 | SFXs and music. 110 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | µCity source code documentation 3 | =============================== 4 | 5 | µCity is an open source game licensed under the GPLv3+ license. Because of that, 6 | the full source code is available for anyone to see, modify, copy, etc, under 7 | the terms of that license. 8 | 9 | General information about the game 10 | ================================== 11 | 12 | - `General details of the game `_ 13 | 14 | - `Details about the game engine `_ 15 | 16 | - `Description of each room in the game `_ 17 | 18 | - `Main game loop `_ 19 | 20 | - `Routines to edit the map `_ 21 | 22 | - `Saved data organization `_ 23 | 24 | Simulation 25 | ========== 26 | 27 | - `Power grid simulation `_ 28 | 29 | - `Traffic `_ 30 | 31 | - `Growth and destruction of buildings `_ 32 | 33 | - `Disasters `_ 34 | 35 | - `Other simulation modules `_ 36 | 37 | Other modules 38 | ============= 39 | 40 | - `Animations `_ 41 | 42 | - `All Points Addressable routines `_ 43 | 44 | - `BCD internal format `_ 45 | 46 | - `Compression and decompression `_ 47 | 48 | - `Random map generation `_ 49 | 50 | - `Text management `_ 51 | -------------------------------------------------------------------------------- /docs/main-loop.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Main Loop 3 | ========= 4 | 5 | Execution of the game starts in ``source/engine/init.asm`` at ``StartPoint``. 6 | There is some hardware initialization code and it eventually jumps to ``Main`` 7 | in ``source/main.asm``, which does game initialization. 8 | 9 | At the end of ``Main``, ``RoomTitle`` is called. As soon as that room is left, 10 | there is the start of the main loop. It calls ``RoomMenu`` and ``RoomGame`` in a 11 | loop. This is how the game manages to go from the main menu to the game room and 12 | back to the main menu. The main menu room is straightforward, the game room 13 | isn't, and it is explained below. Note that the code of the game room is in 14 | ``source/room_game/room_game.asm``. 15 | 16 | Game main loop 17 | ============== 18 | 19 | The game room needs to handle the user interface, animations (if enabled), 20 | update the sprites, music and the simulation of every subsystem (traffic, 21 | electricity, etc). Not all of them have the same priority: 22 | 23 | - Animations are critical, as they can make the game feel glitchy if they are 24 | not completely fluid. Note that, as explained in the documentation of the 25 | animations (in `this `_ file), there are two animation 26 | routines. Only the VBL handling part is critical. The status bar interrupt 27 | handler is also critical, as it can create graphical glitches if it isn't 28 | handled at the correct time. 29 | 30 | - Music and SFXs have high priority, the player won't notice a delay of one 31 | frame in a song (it's 1/60th of a second, after all), but it still needs to be 32 | handled reliably. The rest of the animation handling is also treated with this 33 | priority. 34 | 35 | - The user interface is also important, but it only has medium priority because 36 | updating graphics is slow, so the code can't rely on the user interface 37 | updates being fast enough for the music to be updated reliably. 38 | 39 | - The game simulation has low priority. A single simulation step can take 40 | several seconds to end, so it's something that has to be handled in the 41 | background. 42 | 43 | To be able to treat all of them as needed, there is a main loop that handles the 44 | simulation and a VBL handler that handles everything else. 45 | 46 | - The main loop simply executes steps of the simulation unless the user 47 | interface tells it not do do so (because the player has paused, for example). 48 | Note that this is also the reason sometimes the user interface complains when 49 | the player tries to enter any room of the pause menu, or why it can take a few 50 | seconds to go to the main menu after pressing that option. Also, that's why 51 | sometimes building/demolishing doesn't work for a few seconds, it's just a 52 | really, really bad idea to modify the map during the simulation, so the game 53 | stops you. The red dot that appears on the screen is there for that reason, to 54 | tell the player when the step has ended. 55 | 56 | - The VBL handler is a bit more complicated. First of all, it allows other 57 | interrupts to interrupt it. Second, it can modify data that is also modified 58 | by the main loop so it is needed to create critical parts in the code that 59 | cannot be interrupted (or corruption will appear). The problem is that some 60 | parts of the VBL handler have higher priority than others. 61 | 62 | The way the handler works is by having a critical section at the beginning. 63 | This section can't be interrupted by anything. It updates the status bar 64 | position, the sprites, background scroll, the critical part of the animations, 65 | music and SFXs. There's a debug check to make sure that the VBL period hasn't 66 | ended by the time updates are going to be done to the VRAM/OAM (that is, 67 | animations, music and SFXs are handled after the check). Note that this is 68 | only for debug purposes. A real player wouldn't see anything happen if the 69 | test fails (maybe glitches, if the problem is serious). Note that all of this 70 | must take less than a frame to be completed. If not, the CPU simply has no 71 | time to do anything else! 72 | 73 | After all of that is handled, interruptions are enabled again. At this point, 74 | a new VBL could happen and trigger the VBL handler. This nested interrupt 75 | would be detected, and the handler of the nested interrupt would return here. 76 | 77 | If this isn't a nested interrupt, there is more work to do. It is needed to 78 | update the user interface. This update may modify the map (if the user builds 79 | or demolishes something). The player can also move the map around, so it is 80 | needed to update the position of animated sprites of planes, boats and trains. 81 | Also, it is needed to handle the non-critical part of the animations. This 82 | division is the reason why sometimes a train will fail to turn in a curve and 83 | it will disappear, as explained `here `_. If the 84 | critical part of the animations is handled, but not the non-critical, right in 85 | the step when a train should turn, it won't turn, and it will leave the train 86 | tracks, making the train jump to a new random position. 87 | 88 | The main loop doesn't always do the same tasks. It can do normal simulation of 89 | traffic, power, services, building growth, etc, but it can also simulate 90 | disasters (in disaster mode). In disaster mode, animated sprites are removed. 91 | After all, it is likely that ports, airports and train tracks are damaged, and 92 | it would be overkill to update the number of objects in this case. Only water 93 | and fire can be animated during a disaster. The sprites reappear after exiting 94 | this mode. 95 | -------------------------------------------------------------------------------- /docs/saved-data.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Saved Data Format 3 | ================= 4 | 5 | Even though this game has been designed with 16 SRAM banks in mind, most 6 | flashcarts have less, and some emulators don't support more than 4. For that 7 | reason, the saved the saved data format was designed with scalability in mind. 8 | 9 | When the game boots, it runs a routine that detects the number of available 10 | banks. Every city uses a SRAM bank, so the number of cities that can be saved is 11 | the same as the number of available SRAM banks. If it is needed to trim a saved 12 | data file, all the cities contained in the resulting file would still work. 13 | Similarly, it would be easy to manage cities from one save file and move them to 14 | a different one. 15 | 16 | The relevant code is located in: 17 | 18 | - ``source/sram_utils.asm`` : Functions to handle all SRAM saved data, like 19 | checksum calculations or verification. 20 | 21 | - ``source/save_struct.asm`` : Format of the saved data. It is repeated in all 22 | SRAM banks. 23 | 24 | - ``source/save_struct.inc`` : Helpers to handle saved data. 25 | 26 | - ``source/room_game/map_load.asm`` : It uses the available routines to load 27 | cities from SRAM. Note that there are some useful definitions in 28 | ``source/room_game/map_load.inc`` to select where to load the city (scenarios, 29 | from ROM, or saved cities, from SRAM). 30 | 31 | - ``source/room_save_menu/room_save_menu.asm`` : It uses the available routines 32 | to load and print information about saved cities as well as the ones used to 33 | save cities to SRAM. 34 | 35 | - ``source/room_game/sram_map_handle.asm`` : Functions to load and save cities. 36 | 37 | SRAM size check 38 | =============== 39 | 40 | The function ``SRAM_PowerOnCheck`` in ``source/sram_utils.asm`` checks the real 41 | available memory for saving data. 42 | 43 | In short, it saves the first byte of each SRAM bank (up to a max of 16) and then 44 | it writes a number from 15 to 0 to the first byte of them: 15 to SRAM bank 0, 14 45 | to bank 1, and so on until 0 is written to SRAM bank 15. 46 | 47 | If less than 16 banks are available, this will make the cartridge controller to 48 | ignore the top bits of the number and make it wrap. In that case, only the last 49 | numbers will survive. For example, if only 4 banks are available, only values 3 50 | to 0 will remain in SRAM. 51 | 52 | Even though this code is really fast, there's still the possibility of the GBC 53 | being turned off during the SRAM manipulation code (running out of batteries, 54 | etc). This remains as something that could be improved in the future. 55 | 56 | Format 57 | ====== 58 | 59 | The format consists on a series of fields as specified in 60 | ``source/save_struct.asm``. There is some padding between different sections for 61 | future use. That means that, if a new field is needed, it could be placed next 62 | to others that are related to it without moving all the rest in the process. 63 | 64 | The first field is a 4-byte magic string: ``BTCY`` 65 | 66 | Then, the 16-bit checksum for this bank (LSB first). The checksum used is the 67 | BSD checksum because of its simplicity (see ``SRAMCalculateChecksum``): 68 | 69 | .. code:: c 70 | 71 | u16 sum = 0; 72 | u8 * data = &start; 73 | for (size_t i = 0; i < size; i++) 74 | { 75 | sum = (sum >> 1) | (sum << 15); 76 | sum += data[i]; 77 | } 78 | 79 | The rest of the fields are simply the saved version of variables used in-game. 80 | 81 | The city map is saved as a tile map. The tile map is saved as-is with a memcopy, 82 | the attribute map is compressed so that each byte holds the values for 8 tiles. 83 | It is only needed to save the top bit of the tile index because the palette and 84 | other information can be reconstructed from it. 85 | 86 | Other interesting information that is saved is the plots that show the evolution 87 | of population, funds, etc, with time. 88 | -------------------------------------------------------------------------------- /docs/simulation-disasters.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Disasters 3 | ========= 4 | 5 | As of now, there are two different disasters: Fires and nuclear meltdowns. They 6 | both appear randomly. Fires appear depending on the number of fire stations, 7 | nuclear meltdowns depend on the number of nuclear fission power plants. 8 | Disasters can be disabled in the options menu if the player wants to play 9 | without distractions from them. 10 | 11 | Note that when a disaster starts the main simulation loop switches to disaster 12 | mode, which only updates the fire and ignores the rest of the simulated 13 | elements. 14 | 15 | Disasters can appear at the end of any simulation step. If disaster mode is 16 | active, no more disasters can be triggered, not even by the player. 17 | 18 | While in disaster mode, there is only a minimap available to see, which shows 19 | the location of the fires. 20 | 21 | Fires 22 | ===== 23 | 24 | The code that handles fires is in ``source/simulation/simulation_fire.asm``. 25 | 26 | At every simulation step, the probabilities of a fire starting are: 27 | 28 | :code:`max(4 - number of fire stations, 1) / 256` 29 | 30 | If a fire is supposed to start a loop generates random coordinates in the map 31 | until it finds a burnable tile. If it hasn't found one after 10 tries, it just 32 | returns and doesn't start a fire. If it succeeds, a fire starts in that tile 33 | and the simulation loop enters disaster mode. This is all handled by 34 | ``Simulation_FireTryStart``. 35 | 36 | This means that, even if the player triggers a fire, it is still possible that 37 | the fire doesn't start after all. 38 | 39 | Note that, when a tile is burned, if that tile is part of a building, the whole 40 | building is destroyed and catches fire. Obviously, this doesn't cost any money, 41 | buildings can always be destroyed by fire (and the SFX that is played is 42 | different than when the player demolishes them). The function that is used to 43 | burn tiles is ``MapDeleteBuildingFire``. 44 | 45 | Once there is a fire, it starts to spread. The function that handles the fire is 46 | ``Simulation_Fire``. 47 | 48 | 1. For each tile in the map, the probability of it catching fire is the 49 | burnability of the tile multiplied by the number of tiles next to it that are 50 | on fire (it saturates at 255). This is saved to a temporary ``WRAMX`` bank. 51 | 52 | 2. For each tile in the map, the chances of the fire being extinguished are: 53 | 54 | :code:`max((fire stations + 1) * 2, 256) / 256` 55 | 56 | The ``+ 1`` is needed so that fires can go off even if there are no fire 57 | stations. 58 | 59 | Note that the number of fire stations is the one at the start of the fire. 60 | Even if a fire department is the origin of the fire, that one counts in the 61 | previous formula. 62 | 63 | 3. Finally, for each tile with the accumulated probabilities higher than 0 (the 64 | ones calculated in part 1), a random number is generated. If that number is 65 | lower than the accumulated saved number, that tile catches fire (and it 66 | destroys the whole building in case it was a part of one). 67 | 68 | Note that nuclear fission power plants, when they explode, spread radiation 69 | tiles around them, the same way as they do when there's a nuclear meltdown. 70 | 71 | In practice, the best way to get rid of fires is to demolish every tile around a 72 | fire as soon as possible, as edit mode isn't disabled during disasters. 73 | 74 | Nuclear meltdowns 75 | ================= 76 | 77 | All code related to nuclear meltdowns is in the file 78 | ``source/simulation/simulation_meltdown.asm``. 79 | 80 | At each simulation step, for every nuclear fission power plant in the map, there 81 | is a 1/256 chance that that particular power plant will explode. This is done in 82 | ``Simulation_MeltdownTryStart``. After this, another random number is calculated 83 | so that a nuclear meltdown is only triggered 1/8 of times. 84 | 85 | If the nuclear meltdown has been forced (by the player, for example), the first 86 | power plant to be found is used instead. Obviously, if there are no nuclear 87 | fission power plants, it is impossible to have a meltdown. 88 | 89 | When a power plant explodes, it catches fire and spreads radiation tiles around 90 | it. The function ``Simulation_MeltdownTryStart`` doesn't actually spread 91 | radiation. This is done by ``MapDeleteBuildingFire``. That way, when a power 92 | plant is burned down by a regular fire, it will also spread radiation tiles. 93 | 94 | The function that spreads radiation is ``Simulation_RadiationSpread``, which is 95 | called by ``MapDeleteBuildingFire`` if it burns a nuclear fission power plant 96 | down. This function generates 16 radiation tiles around the center of the power 97 | plant. If any of them lands outside of the map the function won't repeat the 98 | calculations, there will be simply one less tile of radiation. 99 | 100 | Radiation can land up to 8 tiles away in any direction from the center of the 101 | power plant: 102 | 103 | .. code:: 104 | 105 | radiation x = center of power plant x + (rand() & 15) - 8 106 | radiation y = center of power plant y + (rand() & 15) - 8 107 | 108 | If radiation tiles fall in a building, they destroy it and burn it. If there is 109 | no building (it is just a road, or field, or a forest, for example) nothing 110 | special happens. Water tiles can also be made radioactive. They have a different 111 | image than the ones in land. 112 | 113 | Radiation tiles are special in the way that they can't be removed, and they 114 | prevent buildings from being built in that place. They can't burn either. 115 | 116 | At each simulation step (in normal mode, not in disaster mode) there is a 1/256 117 | chance for each radioactive tile to be removed and turned back into regular land 118 | or water. 119 | -------------------------------------------------------------------------------- /docs/text-management.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Text Management 3 | =============== 4 | 5 | Even though the game doesn't do any special manipulation of text, storing text 6 | and handling it correctly requires a bit of care. The relevant code is located 7 | in: 8 | 9 | - ``source/text.asm`` : Text font tileset, palette and functions to load them. 10 | The font can be loaded at the end of both tile banks (starting at ``0x8000`` 11 | or at ``0x8800``). The tiles use palette index 7. 12 | 13 | - ``source/text.inc`` : Utilities to create strings. Instead of saving them in 14 | ASCII format, they are converted to tiles so that the game doesn't have to do 15 | the conversion at runtime. 16 | 17 | - ``source/room_game/tileset_text.asm`` : Strings to describe each type of 18 | terrain (field, road, etc) and function to write it to a buffer. 19 | 20 | - ``source/room_game/text_messages.asm`` : Message definitions and functions to 21 | handle the message queue (requests, peeks, etc). 22 | 23 | - ``source/room_game/text_messages.inc`` : Message IDs. Space needed to store 24 | the status of persistent messages. 25 | 26 | - ``source/room_game/persistent_messages.asm`` : Functions to handle persistent 27 | messages and yearly messages. 28 | 29 | - ``source/room_game/message_box.asm`` : Functions to handle the message box 30 | shown in the room game. 31 | 32 | Message queue 33 | ============= 34 | 35 | In order to handle multiple messages happening at the same time there is a 36 | message queue that holds a number of unique (non-repeated) message IDs (exactly 37 | ``MSG_QUEUE_DEPTH`` messages). They are added to the queue with the function 38 | ``MessageRequestAdd``, and they are shown in the same order they are added. All 39 | messages are predefined. 40 | 41 | There is a special message ID, ``ID_MSG_CUSTOM``. This message can be modified 42 | at runtime, but it must be requested with ``MessageRequestAddCustom``. 43 | 44 | Note that only one instance of each ID can be in the queue at any point in time. 45 | More requests to show the same message will be ignored. 46 | 47 | Persistent messages 48 | =================== 49 | 50 | Persistent messages are messages that can only be shown once per game (or once 51 | per in-game year). They are shown with ``PersistentMessageShow``. Examples of 52 | this kind of messages are the ones that tell the player that the city has grown 53 | and gained a new title. 54 | 55 | Yearly messages are treated the same way, except for the fact that the function 56 | ``PersistentYearlyMessagesReset`` resets their state at the end of each year so 57 | that they can be shown again. This way they aren't too annoying for the player. 58 | Examples of messages of this kind are the ones that notify the player that the 59 | city has run out of money. 60 | 61 | The state of both kinds of persistent messages is stored in the saved data of 62 | the city. To make it easier, the message IDs of persistent and yearly messages 63 | are the first ones. Only one bit is needed to know the state of each message, so 64 | they are packed in bytes. The number of bytes needed to save them all is 65 | ``BYTES_SAVE_PERSISTENT_MSG``. 66 | 67 | Text input 68 | ========== 69 | 70 | The file ``source/room_text_input/room_text_input.asm`` contains a room that 71 | allows the player to input a text string. It also lets the game show a string 72 | to explain shortly what the player is meant to input. It is currently used to 73 | input the names of cities in randomly generated maps. 74 | -------------------------------------------------------------------------------- /readme.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | µCity 1.2 3 | ========= 4 | 5 | Introduction 6 | ============ 7 | 8 | This is µCity (also spelled 'uCity', pronounced 'micro-city'), the open-source 9 | city-building game for Game Boy Color. 10 | 11 | .. image:: screenshot.png 12 | 13 | Video: https://www.youtube.com/watch?v=2rir-TVx020 14 | 15 | This game is completely free. Just download the ROM, install a Game Boy Color 16 | emulator, and play! The last release of the game should be here: 17 | 18 | https://github.com/AntonioND/ucity/releases 19 | 20 | You can also play on real hardware. Even though the game has been developed 21 | using mainly emulators, it has been verified to work on hardware. The game 22 | detects how much available space there is and adjust the maximum number of saved 23 | cities accordingly. 24 | 25 | There are two available ROMs. ``ucity.gbc`` is the preferred ROM that you should 26 | use. It can save up to 16 cities depending on the memory available in your 27 | emulator or flashcart. If your emulator fails to load this ROM because of an 28 | unknown RAM size or your flashcart fails to save data, try ``ucity_compat.gbc``. 29 | This ROM will only be able to save up to 4 cities, but it is more likely to work 30 | in all cases. 31 | 32 | Note: A direct port of this game to the monochrome Game Boy isn't possible. This 33 | game uses most of the extra RAM that was added to the Game Boy Color, which 34 | isn't available in a regular Game Boy. While the Game Boy Color has 32 KiB of 35 | WRAM, the Game Boy only has 8 KB, and this game currently uses 30 KB more or 36 | less. Only a really limited version of this game with a much smaller map and 37 | much fewer features would fit in a Game Boy. 38 | 39 | Manual 40 | ====== 41 | 42 | If needed, there is a short manual with instructions for the player 43 | `here `_. 44 | 45 | Documentation 46 | ============= 47 | 48 | An open-source project is a lot worse without documentation! That's why the code 49 | has a lot of comments and why there is a highly detailed documentation 50 | `here `_. And also because assembly code without comments can't 51 | be understood even by the developer who wrote it originally. :) 52 | 53 | Compiling 54 | ========= 55 | 56 | This game needs a really recent version of ``RGBDS`` to correctly assemble the 57 | code. It is the only real dependency. This toolchain can be found here: 58 | 59 | https://github.com/gbdev/rgbds/ 60 | 61 | Follow the instructions in that link to install it in your system. 62 | 63 | Once the ``RGBDS`` binaries are installed in your system, assembling the game is 64 | as simple as typing :code:`make` in a terminal. 65 | 66 | If the binaries aren't installed in any system path, the variable ``RGBDS`` of 67 | the Makefile has to point at the path where they are located: 68 | 69 | :code:`make RGBDS=path/to/binaries/` 70 | 71 | This should work on Linux, MinGW, Cygwin, etc. To remove all files that are 72 | generated during the assembly process, type :code:`make clean`. 73 | 74 | Tools 75 | ===== 76 | 77 | - Open ModPlug Tracker 78 | 79 | This is just a program to edit tracker style music. It has been used to 80 | compose the music used by GBT Player. 81 | 82 | https://openmpt.org/ 83 | 84 | GBT Player is my music player library. It is included in the code, and it can 85 | be found here if you want to use it for your projects: 86 | 87 | https://github.com/AntonioND/gbt-player 88 | 89 | - GBTD (Game Boy Tile Designer) and GBMB (Game Boy Map Builder) 90 | 91 | Graphics edition tools (for Windows, but they run on Wine). 92 | 93 | Note that both of them can be found in this repository in the ``tools`` folder 94 | in case the following links are broken: 95 | 96 | http://www.devrs.com/gb/hmgd/gbmb.html 97 | 98 | http://www.devrs.com/gb/hmgd/gbtd.html 99 | 100 | Credits 101 | ======= 102 | 103 | Game made by AntonioND/SkyLyrac (Antonio Niño Díaz) 104 | 105 | Email: 106 | 107 | antonio_nd@outlook.com 108 | 109 | Web: 110 | 111 | https://github.com/AntonioND 112 | 113 | www.skylyrac.net 114 | 115 | Thanks to: 116 | 117 | - beware: For the emulator BGB (http://bgb.bircd.org/), extremely useful tool 118 | used to develop this game. 119 | 120 | - Pan of Anthrox, Marat Fayzullin, Pascal Felber, Paul Robson, Martin Korth 121 | (nocash) and kOOPa for the pandocs. 122 | 123 | - Otaku No Zoku (Justin Lloyd) for the Gameboy Crib Sheet. 124 | 125 | - Everyone that has contributed to develop ``RGBDS`` over the years, specially 126 | Carsten Sorensen, Justin Lloyd, Vegard Nossum and Anthony J. Bentley. 127 | 128 | License 129 | ======= 130 | 131 | This game is licensed under the GPLv3+ license. You should have received the 132 | source code of this game along with the ROM file. If not, the source code is 133 | freely available at the following address: 134 | 135 | https://github.com/AntonioND/ucity 136 | 137 | Not all source code files are licensed under the GPL v3+, though, only the ones 138 | with the GPL header are. There other source files are licensed under different 139 | terms (for example, GBT Player is licensed under the 2-clause BSD license). 140 | 141 | The media files (graphics and music) are licensed under a Creative Commons 142 | license (CC BY-SA 4.0). 143 | -------------------------------------------------------------------------------- /resources/gfx/bank_offer_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/bank_offer_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/bank_repay_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/bank_repay_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/budget_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/budget_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/build_select_sprites.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/build_select_sprites.gbm -------------------------------------------------------------------------------- /resources/gfx/build_select_sprites.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/build_select_sprites.gbr -------------------------------------------------------------------------------- /resources/gfx/city_stats_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/city_stats_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/city_tiles.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/city_tiles.gbr -------------------------------------------------------------------------------- /resources/gfx/credits_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/credits_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/graphs_menu_tiles.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/graphs_menu_tiles.gbm -------------------------------------------------------------------------------- /resources/gfx/graphs_menu_tiles.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/graphs_menu_tiles.gbr -------------------------------------------------------------------------------- /resources/gfx/info_bar_room_game.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/info_bar_room_game.gbm -------------------------------------------------------------------------------- /resources/gfx/main_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/main_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/map_gen_minimap_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/map_gen_minimap_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/map_scenario_select_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/map_scenario_select_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/minimap_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/minimap_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/minimap_menu_tiles.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/minimap_menu_tiles.gbm -------------------------------------------------------------------------------- /resources/gfx/minimap_menu_tiles.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/minimap_menu_tiles.gbr -------------------------------------------------------------------------------- /resources/gfx/minimap_tiles.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/minimap_tiles.gbr -------------------------------------------------------------------------------- /resources/gfx/only_for_gbc_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/only_for_gbc_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/options_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/options_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/save_menu_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/save_menu_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/save_menu_error_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/save_menu_error_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/scenario_0_rock_river.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/scenario_0_rock_river.gbm -------------------------------------------------------------------------------- /resources/gfx/scenario_1_boringtown.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/scenario_1_boringtown.gbm -------------------------------------------------------------------------------- /resources/gfx/scenario_2_portville.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/scenario_2_portville.gbm -------------------------------------------------------------------------------- /resources/gfx/scenario_3_newdale.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/scenario_3_newdale.gbm -------------------------------------------------------------------------------- /resources/gfx/test_gfx/test_city_map.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/test_gfx/test_city_map.gbm -------------------------------------------------------------------------------- /resources/gfx/text_input_bg.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/text_input_bg.gbm -------------------------------------------------------------------------------- /resources/gfx/title_screen_map.gbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/title_screen_map.gbm -------------------------------------------------------------------------------- /resources/gfx/title_screen_tiles.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/title_screen_tiles.gbr -------------------------------------------------------------------------------- /resources/gfx/txt.gbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/gfx/txt.gbr -------------------------------------------------------------------------------- /resources/music/city.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/music/city.mod -------------------------------------------------------------------------------- /resources/music/convert_songs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | MOD2GBT=../../tools/mod2gbt/mod2gbt 3 | 4 | $MOD2GBT city.mod song_city 5 | mv song_city.asm ../../data/music/ 6 | 7 | $MOD2GBT menu.mod song_menu 8 | mv song_menu.asm ../../data/music/ 9 | 10 | $MOD2GBT title.mod song_title 11 | mv song_title.asm ../../data/music/ 12 | -------------------------------------------------------------------------------- /resources/music/menu.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/music/menu.mod -------------------------------------------------------------------------------- /resources/music/title.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/resources/music/title.mod -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/screenshot.png -------------------------------------------------------------------------------- /source/apa.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(APA_INC) 24 | DEF APA_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | ; This APA Library uses tiles 128-383 of VRAM bank 1 29 | 30 | DEF APA_FB_WIDTH EQU 128 31 | DEF APA_FB_HEIGHT EQU 128 32 | 33 | DEF APA_TILE_WIDTH EQU 16 34 | DEF APA_TILE_HEIGHT EQU 16 35 | 36 | DEF APA_TILE_NUMBER EQU (APA_TILE_WIDTH*APA_TILE_HEIGHT) 37 | 38 | DEF APA_TILE_OFFSET_X EQU ((20-APA_TILE_WIDTH)/2) ; Center of the screen 39 | DEF APA_TILE_OFFSET_Y EQU (18-APA_TILE_HEIGHT) ; Bottom of the screen 40 | 41 | DEF APA_PALETTE_INDEX EQU 6 ; Palette index used by the minimap 42 | 43 | ;############################################################################### 44 | 45 | ENDC ; APA_INC 46 | 47 | ;############################################################################### 48 | -------------------------------------------------------------------------------- /source/engine/gbt_player.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ;# # 3 | ;# # 4 | ;# GBT PLAYER 3.0.5 # 5 | ;# # 6 | ;# Contact: antonio_nd@outlook.com # 7 | ;############################################################################### 8 | 9 | ; Copyright (c) 2009-2016, Antonio Niño Díaz (AntonioND) 10 | ; All rights reserved. 11 | ; 12 | ; Redistribution and use in source and binary forms, with or without 13 | ; modification, are permitted provided that the following conditions are met: 14 | ; 15 | ; * Redistributions of source code must retain the above copyright notice, this 16 | ; list of conditions and the following disclaimer. 17 | ; 18 | ; * Redistributions in binary form must reproduce the above copyright notice, 19 | ; this list of conditions and the following disclaimer in the documentation 20 | ; and/or other materials provided with the distribution. 21 | ; 22 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | ; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | ; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | ; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | ; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | ;############################################################################### 34 | 35 | IF !DEF(GBT_PLAYER_INC) 36 | DEF GBT_PLAYER_INC = 1 37 | 38 | ;############################################################################### 39 | 40 | EXPORT gbt_play ; Starts playing a song. 41 | ; de = pointer to song data 42 | ; a = default speed. Careful, 0 = 256! 43 | ; bc = data bank (b ignored if ROM with < 256 banks) 44 | ; THIS WILL CHANGE ROM BANK!!! 45 | 46 | EXPORT gbt_pause ; Pauses or unpauses the song. 47 | ; a = 0 to unpause, anything else to pause. 48 | 49 | EXPORT gbt_loop ; Enables/disables looping at the end of the song. 50 | ; a = 0 to stop at the end, anything else to loop 51 | 52 | EXPORT gbt_stop ; Stops the song. 53 | 54 | EXPORT gbt_enable_channels ; Enables given channels. 55 | ; a = channel flags ORed: 56 | ; channel 1 = 1 57 | ; channel 2 = 2 58 | ; channel 3 = 4 59 | ; channel 4 = 8 60 | 61 | EXPORT gbt_update ; Updates the player, must be called each VBL. 62 | ; THIS WILL CHANGE ROM BANK!!! 63 | 64 | ; - If the following value is uncomented, the total of banks allowed is 512 65 | ; (or more), but it's a bit slower. MBC5 ONLY, DOESN'T WORK WITH OTHERS!!! 66 | ; YOU MUST USE THE -512-banks OPTION WHEN CONVERTING A SONG WITH mod2gbt!!! 67 | ; - If it's commented, only 256 banks are allowed, it's a little bit faster 68 | ; and saves a few bytes. MBC1, MBC3 and MBC5 (and others). 69 | ;GBT_USE_MBC5_512BANKS SET 1 70 | 71 | ;############################################################################### 72 | 73 | ENDC ;GBT_PLAYER_INC 74 | 75 | ;############################################################################### 76 | -------------------------------------------------------------------------------- /source/engine/gbt_player_bank1.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/source/engine/gbt_player_bank1.asm -------------------------------------------------------------------------------- /source/engine/rand.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | 25 | ;############################################################################### 26 | ;# # 27 | ;# RANDOM # 28 | ;# # 29 | ;############################################################################### 30 | 31 | SECTION "RandomLUT",ROM0,ALIGN[8] 32 | 33 | ;------------------------------------------------------------------------------- 34 | 35 | _Random: 36 | DB $29,$23,$be,$84,$e1,$6c,$d6,$ae,$52,$90,$49,$f1,$f1,$bb,$e9,$eb 37 | DB $b3,$a6,$db,$3c,$87,$0c,$3e,$99,$24,$5e,$0d,$1c,$06,$b7,$47,$de 38 | DB $b3,$12,$4d,$c8,$43,$bb,$8b,$a6,$1f,$03,$5a,$7d,$09,$38,$25,$1f 39 | DB $5d,$d4,$cb,$fc,$96,$f5,$45,$3b,$13,$0d,$89,$0a,$1c,$db,$ae,$32 40 | DB $20,$9a,$50,$ee,$40,$78,$36,$fd,$12,$49,$32,$f6,$9e,$7d,$49,$dc 41 | DB $ad,$4f,$14,$f2,$44,$40,$66,$d0,$6b,$c4,$30,$b7,$32,$3b,$a1,$22 42 | DB $f6,$22,$91,$9d,$e1,$8b,$1f,$da,$b0,$ca,$99,$02,$b9,$72,$9d,$49 43 | DB $2c,$80,$7e,$c5,$99,$d5,$e9,$80,$b2,$ea,$c9,$cc,$53,$bf,$67,$d6 44 | DB $bf,$14,$d6,$7e,$2d,$dc,$8e,$66,$83,$ef,$57,$49,$61,$ff,$69,$8f 45 | DB $61,$cd,$d1,$1e,$9d,$9c,$16,$72,$72,$e6,$1d,$f0,$84,$4f,$4a,$77 46 | DB $02,$d7,$e8,$39,$2c,$53,$cb,$c9,$12,$1e,$33,$74,$9e,$0c,$f4,$d5 47 | DB $d4,$9f,$d4,$a4,$59,$7e,$35,$cf,$32,$22,$f4,$cc,$cf,$d3,$90,$2d 48 | DB $48,$d3,$8f,$75,$e6,$d9,$1d,$2a,$e5,$c0,$f7,$2b,$78,$81,$87,$44 49 | DB $0e,$5f,$50,$00,$d4,$61,$8d,$be,$7b,$05,$15,$07,$3b,$33,$82,$1f 50 | DB $18,$70,$92,$da,$64,$54,$ce,$b1,$85,$3e,$69,$15,$f8,$46,$6a,$04 51 | DB $96,$73,$0e,$d9,$16,$2f,$67,$68,$d4,$f7,$4a,$4a,$d0,$57,$68,$76 52 | 53 | ;############################################################################### 54 | 55 | SECTION "RandomPtr",WRAM0 56 | 57 | ;------------------------------------------------------------------------------- 58 | 59 | random_ptr: DS 1 60 | 61 | ;############################################################################### 62 | 63 | SECTION "RandomFunction",ROM0 64 | 65 | ;------------------------------------------------------------------------------- 66 | 67 | ; bc and de preserved 68 | GetRandom:: 69 | 70 | ld hl,random_ptr 71 | ld l,[hl] 72 | ld h,_Random>>8 73 | 74 | ldh a,[rDIV] 75 | xor a,[hl] 76 | 77 | inc l 78 | add a,[hl] 79 | 80 | ld hl,random_ptr 81 | ld [hl],a 82 | 83 | ret 84 | 85 | ;------------------------------------------------------------------------------- 86 | 87 | SetRandomSeed:: 88 | 89 | ld [random_ptr],a 90 | ret 91 | 92 | ;Check if it generates every number 93 | ;---------------------------------- 94 | ; 95 | ; ld b,0 96 | ;.next 97 | ; call GetRandom 98 | ; cp b 99 | ; jr nz,.next 100 | ; inc b 101 | ; xor a,a 102 | ; cp b 103 | ; jr z,.end 104 | ; jr .next 105 | ;.end 106 | 107 | ;############################################################################### 108 | -------------------------------------------------------------------------------- /source/math.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;############################################################################### 27 | 28 | SECTION "Math Utilities Bank 0",ROM0 29 | 30 | ;------------------------------------------------------------------------------- 31 | 32 | ; Calculates a aproximate percentage of 2 16-bit values by reducing them to 33 | ; 8-bit values and operating on them. 34 | ; It returns 255 on error, a value between 0 and 100 or success. 35 | CalculateAproxPercent:: ; a = de * 100 / hl 36 | 37 | ld a,h 38 | or a,l 39 | jr nz,.not_div_by_0 40 | xor a,a ; return 0 41 | ret 42 | .not_div_by_0: 43 | 44 | ld c,16 ; get the top 7 bits of the values to simplify divisions 45 | .loop: 46 | ld a,h 47 | or a,d 48 | bit 6,a ; get 7 bits only 49 | jp nz,.end_simplify_loop 50 | add hl,hl ; hl <<= 1 51 | sla e ; de <<= 1 52 | rl d 53 | dec c 54 | jr nz,.loop 55 | .end_simplify_loop: 56 | 57 | ; D = aprox DE 58 | ; H = aprox HL 59 | 60 | push hl 61 | 62 | ld a,100 63 | ld c,d 64 | call mul_u8u8u16 ; hl = result a,c = initial values de preserved 65 | 66 | pop de 67 | 68 | ld c,d 69 | 70 | ; HL = aprox DE * 100 71 | ; C = aprox HL 72 | 73 | call div_u16u7u16 ; hl / c -> hl 74 | 75 | ; HL should be less or equal than 100! 76 | 77 | ld a,h 78 | and a,a ; if hl >= 255 79 | jr z,.div_lower_256 80 | 81 | ld b,b 82 | ld a,255 ; 255 is considered an invalid value 83 | ret 84 | 85 | .div_lower_256: 86 | 87 | ld a,l 88 | cp a,101 ; cy = 1 if n > a 89 | jr c,.div_lower_100 90 | 91 | ld b,b 92 | ld a,255 ; 255 is considered an invalid value 93 | ret 94 | 95 | .div_lower_100: 96 | 97 | ld a,l ; get result 98 | 99 | ret 100 | 101 | ;------------------------------------------------------------------------------- 102 | 103 | ; Calculates a aproximate percentage of 2 16-bit values by reducing them to 104 | ; 8-bit values and operating on them. It returns the value converted to BCD. 105 | CalculateAproxPercentBCD:: ; hl = de * 100 / hl, Result in BCD (H=MSB, L=LSB) 106 | 107 | call CalculateAproxPercent ; a = de * 100 / hl 108 | 109 | jr Byte2BCD ; return from there 110 | 111 | ;------------------------------------------------------------------------------- 112 | 113 | Byte2BCD:: ; a = byte, returns hl = BCD (H=MSB, L=LSB) 114 | 115 | ld l,a 116 | ld h,0 117 | add hl,hl ; hl = a*2 118 | ld de,BINARY_TO_BCD ; 2 bytes per entry. LSB first 119 | add hl,de 120 | 121 | ld a,[hl+] 122 | ld h,[hl] 123 | ld l,a 124 | 125 | ret 126 | 127 | ;############################################################################### 128 | -------------------------------------------------------------------------------- /source/money.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "money.inc" 29 | 30 | ;############################################################################### 31 | 32 | SECTION "Money Variables",WRAM0 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | MoneyWRAM:: DS MONEY_AMOUNT_SIZE ; BCD, LSB first, LSB in lower nibbles 37 | 38 | ;############################################################################### 39 | 40 | SECTION "Money Code",ROM0 ; ROM 0 is needed! 41 | 42 | ;------------------------------------------------------------------------------- 43 | 44 | DATA_MONEY_AMOUNT MONEY_SATURATE_POSITIVE,0999999999 45 | DATA_MONEY_AMOUNT MONEY_SATURATE_NEGATIVE,9000000001 ; -0999999999 46 | 47 | ;------------------------------------------------------------------------------- 48 | 49 | MoneySet:: ; de = ptr to the amount of money to set 50 | 51 | ld hl,MoneyWRAM 52 | ld b,MONEY_AMOUNT_SIZE 53 | .loop: 54 | ld a,[de] 55 | inc de 56 | ld [hl+],a 57 | dec b 58 | jr nz,.loop 59 | 60 | ret 61 | 62 | ;------------------------------------------------------------------------------- 63 | 64 | MoneyGet:: ; de = ptr to store the current amount of money 65 | 66 | ld hl,MoneyWRAM 67 | ld b,MONEY_AMOUNT_SIZE 68 | .loop: 69 | ld a,[hl+] 70 | ld [de],a 71 | inc de 72 | dec b 73 | jr nz,.loop 74 | 75 | ret 76 | 77 | ;------------------------------------------------------------------------------- 78 | 79 | MoneyIsThereEnough:: ; de = ptr to the amount of money. ret a=1 if enough else 0 80 | 81 | push de 82 | push hl 83 | ld de,MoneyWRAM 84 | call BCD_DE_LW_ZERO ; Returns a = 1 if [de] < 0, preserves bc, de 85 | pop hl 86 | pop de 87 | and a,a 88 | jr z,.not_less_than_zero 89 | xor a,a ; negative amount of money!! 90 | ret 91 | .not_less_than_zero: 92 | ld hl,MoneyWRAM 93 | jp BCD_HL_GE_DE 94 | 95 | ;------------------------------------------------------------------------------- 96 | 97 | ; Returns carry = 1 if overflowed, 0 if not. 98 | ; On overflow, MONEY_SATURATE_POSITIVE is set 99 | MoneyReduce:: ; de = ptr to the amout of money. 100 | 101 | LD_HL_DE 102 | 103 | ld de,MoneyWRAM 104 | 105 | call BCD_HL_SUB_DE ; DE = DE - HL 106 | 107 | ld de,MoneyWRAM 108 | 109 | call BCD_DE_LW_ZERO ; Returns a = 1 if [de] < 0, preserves bc, de 110 | and a,a ; if > 0, the subtraction can't have saturated 111 | ret z ; return 0 112 | 113 | ld de,MoneyWRAM 114 | ld hl,MONEY_SATURATE_NEGATIVE 115 | call BCD_HL_GE_DE ; current >= saturated? 116 | and a,a 117 | ret z ; return 0 118 | ld de,MONEY_SATURATE_NEGATIVE 119 | call MoneySet 120 | 121 | ld a,1 122 | ret ; return 1 123 | 124 | ;------------------------------------------------------------------------------- 125 | 126 | ; Returns a=1 if enough else 0. If enough, that amount will be reduced from the 127 | ; total amount. 128 | MoneyReduceIfEnough:: ; de = ptr to amount. 129 | 130 | push de 131 | call MoneyIsThereEnough 132 | pop de 133 | 134 | and a,a 135 | ret z ; not enough, return 0 136 | 137 | call MoneyReduce 138 | 139 | ld a,1 140 | ret 141 | 142 | ;------------------------------------------------------------------------------- 143 | 144 | ; Returns carry = 1 if overflowed, 0 if not. 145 | ; On overflow, MONEY_SATURATE_POSITIVE is set 146 | MoneyAdd:: ; de = ptr to the amount of money to add. 147 | 148 | ld hl,MoneyWRAM 149 | call BCD_HL_ADD_DE 150 | 151 | ld de,MoneyWRAM 152 | call BCD_DE_LW_ZERO ; Returns a = 1 if [de] < 0, preserves bc, de 153 | and a,a ; if < 0, the addition can't have saturated 154 | jr z,.dont_ret_1 155 | xor a,a 156 | ret ; return 0 157 | .dont_ret_1: 158 | 159 | ld de,MoneyWRAM 160 | ld hl,MONEY_SATURATE_POSITIVE 161 | call BCD_HL_GE_DE ; current <= saturated? 162 | and a,a 163 | jr z,.dont_ret_2 164 | xor a,a 165 | ret ; return 0 166 | .dont_ret_2: 167 | ld de,MONEY_SATURATE_POSITIVE 168 | call MoneySet 169 | 170 | ld a,1 171 | ret ; return 1 172 | 173 | ;############################################################################### 174 | -------------------------------------------------------------------------------- /source/money.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(MONEY_INC) 24 | DEF MONEY_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF TAX_PERCENTAGE_MAX EQU 20 29 | 30 | ;------------------------------------------------------------------------------- 31 | 32 | DEF MONEY_AMOUNT_SIZE EQU 5 ; 5 bytes 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | ; Create an array of bytes consisting on the money amount passed as argument 37 | ; Up to 10 digits! 38 | MACRO DATA_MONEY_AMOUNT ; \1 = Label, \2 = Amount 39 | IF \2 > 9999999999 40 | FAIL "Invalid amount of money." 41 | ENDC 42 | IF \2 < 0 43 | FAIL "Invalid amount of money." 44 | ENDC 45 | \1: 46 | DB (\2 % 10) | (((\2 / 10) % 10) << 4) 47 | DB ((\2 / 100) % 10) | (((\2 / 1000) % 10) << 4) 48 | DB ((\2 / 10000) % 10) | (((\2 / 100000) % 10) << 4) 49 | DB ((\2 / 1000000) % 10) | (((\2 / 10000000) % 10) << 4) 50 | DB ((\2 / 100000000) % 10) | (((\2 / 1000000000) % 10) << 4) 51 | ENDM 52 | 53 | ;############################################################################### 54 | 55 | ENDC ; MONEY_INC 56 | 57 | ;############################################################################### 58 | -------------------------------------------------------------------------------- /source/rlediff.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | SECTION "RLE Uncompress",ROM0 24 | 25 | ;------------------------------------------------------------------------------- 26 | 27 | ; Decompress data from a buffer into a different buffer, returning the 28 | ; uncompressed size. 29 | ; If the size marked in the buffer header is incorrect bad things may happen. 30 | RLE_Uncompress:: ; hl = src, bc = dst. Returns de = size 31 | 32 | ld a,[hl+] 33 | cp a,$30 34 | jr z,.magic_ok 35 | ld b,b 36 | ret 37 | .magic_ok: 38 | 39 | ld a,[hl+] 40 | ld e,a 41 | ld a,[hl+] 42 | ld d,a ; DE = raw size. 43 | ld a,[hl+] 44 | and a,a 45 | jr z,.size_ok ; The size can't possibly be bigger than 16 bits 46 | ld b,b 47 | ret 48 | .size_ok: 49 | 50 | push de ; (*) save this to return it later! 51 | 52 | .loop: 53 | 54 | push de 55 | ld a,[hl+] ; get block header 56 | 57 | bit 7,a 58 | jr z,.uncomp 59 | ; N+3 compressed bytes 60 | and a,$7F 61 | add a,3 62 | ld e,a 63 | ld d,a ; preserve size to subtract it later 64 | 65 | ld a,[hl+] 66 | .loopcomp: 67 | ld [bc],a 68 | inc bc 69 | dec e 70 | jr nz,.loopcomp 71 | 72 | jr .continueloop 73 | .uncomp: 74 | ; N+1 uncompressed bytes 75 | inc a 76 | ld e,a 77 | ld d,a ; preserve size to subtract it later 78 | 79 | .loopuncomp: 80 | ld a,[hl+] 81 | ld [bc],a 82 | inc bc 83 | dec e 84 | jr nz,.loopuncomp 85 | 86 | .continueloop: 87 | 88 | ; D holds the size of the last block 89 | ld a,d 90 | 91 | pop de 92 | 93 | cpl 94 | inc a ; a = -a 95 | add a,e 96 | ld e,a 97 | 98 | ld a,$FF 99 | adc a,0 100 | add a,d 101 | ld d,a 102 | 103 | or a,e 104 | 105 | jr nz,.loop 106 | 107 | pop de ; (*) get size and return it in DE 108 | 109 | ret 110 | ;------------------------------------------------------------------------------- 111 | 112 | ; Undoes a diff filter. The source buffer is also used as destination. 113 | Diff_Uncompress:: ; hl = src = dst, de = size 114 | 115 | ld b,0 116 | 117 | .loop: 118 | 119 | ld a,b 120 | add a,[hl] 121 | ld [hl+],a 122 | ld b,a 123 | 124 | dec de 125 | ld a,d 126 | or a,e 127 | jr nz,.loop 128 | 129 | ret 130 | 131 | ;############################################################################### 132 | -------------------------------------------------------------------------------- /source/room_credits/room_credits.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "text.inc" 29 | 30 | ;############################################################################### 31 | 32 | SECTION "Room Credits Variables",WRAM0 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | credits_room_exit: DS 1 ; set to 1 to exit room 37 | 38 | credits_map_selection: DS 1 ; $FF for invalid value 39 | 40 | ;############################################################################### 41 | 42 | SECTION "Room Credits Code Data",ROMX 43 | 44 | ;------------------------------------------------------------------------------- 45 | 46 | CREDITS_SELECT_BG_MAP: 47 | INCBIN "credits_bg_map.bin" 48 | 49 | DEF CREDITS_SELECT_WIDTH EQU 20 50 | DEF CREDITS_SELECT_HEIGHT EQU 18 51 | 52 | ;------------------------------------------------------------------------------- 53 | 54 | InputHandleCredits: 55 | 56 | ld a,[joy_pressed] 57 | and a,PAD_RIGHT 58 | jr z,.end_right 59 | 60 | .end_right: 61 | ld a,[joy_pressed] 62 | and a,PAD_LEFT 63 | jr z,.end_left 64 | 65 | .end_left: 66 | 67 | ld a,[joy_pressed] 68 | and a,PAD_A|PAD_START 69 | jr z,.end_a_start 70 | 71 | ld a,1 72 | ld [credits_room_exit],a 73 | 74 | ret 75 | .end_a_start: 76 | 77 | ld a,[joy_pressed] 78 | and a,PAD_B 79 | jr z,.end_b 80 | 81 | ld a,$FF ; set invalid value 82 | ld [credits_map_selection],a 83 | 84 | ld a,1 85 | ld [credits_room_exit],a 86 | 87 | ret 88 | .end_b: 89 | 90 | ret 91 | 92 | ;------------------------------------------------------------------------------- 93 | 94 | RoomCreditsLoadBG: 95 | 96 | ; Load border 97 | ; ----------- 98 | 99 | ld b,BANK(CREDITS_SELECT_BG_MAP) 100 | call rom_bank_push_set 101 | 102 | ; Load map 103 | ; -------- 104 | 105 | ; Tiles 106 | xor a,a 107 | ldh [rVBK],a 108 | 109 | ld de,$9800 110 | ld hl,CREDITS_SELECT_BG_MAP 111 | 112 | ld a,CREDITS_SELECT_HEIGHT 113 | .loop1: 114 | push af 115 | 116 | ld b,CREDITS_SELECT_WIDTH 117 | call vram_copy_fast ; b = size - hl = source address - de = dest 118 | 119 | push hl 120 | ld hl,32-CREDITS_SELECT_WIDTH 121 | add hl,de 122 | ld d,h 123 | ld e,l 124 | pop hl 125 | 126 | pop af 127 | dec a 128 | jr nz,.loop1 129 | 130 | ; Attributes 131 | ld a,1 132 | ldh [rVBK],a 133 | 134 | ld de,$9800 135 | 136 | ld a,CREDITS_SELECT_HEIGHT 137 | .loop2: 138 | push af 139 | 140 | ld b,CREDITS_SELECT_WIDTH 141 | call vram_copy_fast ; b = size - hl = source address - de = dest 142 | 143 | push hl 144 | ld hl,32-CREDITS_SELECT_WIDTH 145 | add hl,de 146 | ld d,h 147 | ld e,l 148 | pop hl 149 | 150 | pop af 151 | dec a 152 | jr nz,.loop2 153 | 154 | call rom_bank_pop 155 | 156 | ret 157 | 158 | ;------------------------------------------------------------------------------- 159 | 160 | RoomCredits:: 161 | 162 | call SetPalettesAllBlack 163 | 164 | call SetDefaultVBLHandler 165 | 166 | xor a,a 167 | ld [credits_map_selection],a 168 | 169 | xor a,a 170 | ldh [rSCX],a 171 | ldh [rSCY],a 172 | 173 | ld a,LCDCF_BG9800|LCDCF_OBJON|LCDCF_BG8800|LCDCF_ON 174 | ldh [rLCDC],a 175 | 176 | ld b,1 ; bank at 8800h 177 | call LoadText 178 | 179 | call RoomCreditsLoadBG 180 | 181 | call LoadTextPalette 182 | 183 | xor a,a 184 | ld [credits_room_exit],a 185 | 186 | .loop: 187 | 188 | call wait_vbl 189 | 190 | call scan_keys 191 | call KeyAutorepeatHandle 192 | 193 | call InputHandleCredits 194 | 195 | ld a,[credits_room_exit] 196 | and a,a 197 | jr z,.loop 198 | 199 | call SetPalettesAllBlack 200 | 201 | ret 202 | 203 | ;############################################################################### 204 | -------------------------------------------------------------------------------- /source/room_game/building_info.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(BUILDING_INFO_INC) 24 | DEF BUILDING_INFO_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | ; Array of pointers to each building information 29 | EXPORT BUILDING_INFO_POINTERS_ARRAY 30 | DEF BUILDING_INFO_POINTERS_ARRAY_ELEMENT_SIZE EQU 4 31 | 32 | ; Index of every building 33 | DEF B_Residential EQU 0 34 | DEF B_Commercial EQU 1 35 | DEF B_Industrial EQU 2 36 | 37 | DEF B_PoliceDept EQU 3 38 | DEF B_FireDept EQU 4 39 | DEF B_Hospital EQU 5 40 | 41 | DEF B_ParkSmall EQU 6 42 | DEF B_ParkBig EQU 7 43 | DEF B_Stadium EQU 8 44 | 45 | DEF B_School EQU 9 46 | DEF B_HighSchool EQU 10 47 | DEF B_University EQU 11 48 | 49 | DEF B_Museum EQU 12 50 | DEF B_Library EQU 13 51 | 52 | DEF B_TrainStation EQU 14 53 | DEF B_Airport EQU 15 54 | 55 | DEF B_PowerPlantCoal EQU 16 56 | DEF B_PowerPlantOil EQU 17 57 | DEF B_PowerPlantWind EQU 18 58 | DEF B_PowerPlantSolar EQU 19 59 | DEF B_PowerPlantNuclear EQU 20 60 | DEF B_PowerPlantFusion EQU 21 61 | 62 | ; Number of buildings. Everything past this are special "meta buildings" 63 | DEF B_BuildingMax EQU 22 64 | 65 | DEF B_None EQU 22 ; Size is 1x1, which is useful, but it doesn't exist. 66 | 67 | DEF B_Road EQU 23 68 | DEF B_Train EQU 24 69 | DEF B_PowerLines EQU 25 70 | DEF B_Port EQU 26 71 | 72 | DEF B_MetabuildingMax EQU 26 73 | 74 | DEF B_ResidentialS1A EQU 30 75 | DEF B_ResidentialS1B EQU 31 76 | DEF B_ResidentialS1C EQU 32 77 | DEF B_ResidentialS1D EQU 33 78 | DEF B_ResidentialS2A EQU 34 79 | DEF B_ResidentialS2B EQU 35 80 | DEF B_ResidentialS2C EQU 36 81 | DEF B_ResidentialS2D EQU 37 82 | DEF B_ResidentialS3A EQU 38 83 | DEF B_ResidentialS3B EQU 39 84 | DEF B_ResidentialS3C EQU 40 85 | DEF B_ResidentialS3D EQU 41 86 | 87 | DEF B_CommercialS1A EQU 42 88 | DEF B_CommercialS1B EQU 43 89 | DEF B_CommercialS1C EQU 44 90 | DEF B_CommercialS1D EQU 45 91 | DEF B_CommercialS2A EQU 46 92 | DEF B_CommercialS2B EQU 47 93 | DEF B_CommercialS2C EQU 48 94 | DEF B_CommercialS2D EQU 49 95 | DEF B_CommercialS3A EQU 50 96 | DEF B_CommercialS3B EQU 51 97 | DEF B_CommercialS3C EQU 52 98 | DEF B_CommercialS3D EQU 53 99 | 100 | DEF B_IndustrialS1A EQU 54 101 | DEF B_IndustrialS1B EQU 55 102 | DEF B_IndustrialS1C EQU 56 103 | DEF B_IndustrialS1D EQU 57 104 | DEF B_IndustrialS2A EQU 58 105 | DEF B_IndustrialS2B EQU 59 106 | DEF B_IndustrialS2C EQU 60 107 | DEF B_IndustrialS2D EQU 61 108 | DEF B_IndustrialS3A EQU 62 109 | DEF B_IndustrialS3B EQU 63 110 | DEF B_IndustrialS3C EQU 64 111 | DEF B_IndustrialS3D EQU 65 112 | 113 | DEF B_RadiationGround EQU 66 114 | DEF B_RadiationWater EQU 67 115 | 116 | DEF B_Delete EQU 255 ; Special type 117 | 118 | ;############################################################################### 119 | 120 | ENDC ; BUILDING_INFO_INC 121 | 122 | ;############################################################################### 123 | -------------------------------------------------------------------------------- /source/room_game/date.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "text.inc" 29 | 30 | ;############################################################################### 31 | 32 | SECTION "Date Variables",WRAM0 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | date_year:: DS 2 ; BCD, LSB first, LSB in lower nibble 37 | date_month:: DS 1 ; 0 (Jan) - 11 (Dec) 38 | 39 | DEF MONTHS_IN_YEAR EQU 12 40 | 41 | ;############################################################################### 42 | 43 | SECTION "Date Functions Bank 0",ROM0 44 | 45 | ;------------------------------------------------------------------------------- 46 | 47 | ; a = month 48 | ; bc = year (B = MSB, C = LSB) 49 | ; de = pointer to destination of print (8 chars) 50 | DatePrint:: 51 | 52 | ; Month 53 | 54 | push bc ; (*) save year 55 | 56 | ld hl,.date_month_name 57 | ; a = month 58 | ld c,a 59 | ld b,0 60 | add hl,bc 61 | add hl,bc 62 | add hl,bc 63 | 64 | REPT 3 65 | ld a,[hl+] 66 | ld [de],a 67 | inc de 68 | ENDR 69 | 70 | ; Separator 71 | 72 | ld a,O_SPACE 73 | ld [de],a 74 | inc de 75 | 76 | ; Year 77 | 78 | pop bc ; (*) get year 79 | 80 | ld h,c ; save LSB in H 81 | 82 | ld a,b ; MSB 83 | ld b,a 84 | swap a 85 | and a,$0F 86 | BCD2Tile 87 | ld [de],a 88 | inc de 89 | ld a,b 90 | and a,$0F 91 | BCD2Tile 92 | ld [de],a 93 | inc de 94 | 95 | ld a,h ; get LSB 96 | ld b,a 97 | swap a 98 | and a,$0F 99 | BCD2Tile 100 | ld [de],a 101 | inc de 102 | ld a,b 103 | and a,$0F 104 | BCD2Tile 105 | ld [de],a 106 | inc de 107 | ret 108 | 109 | .date_month_name: 110 | STR_ADD "JanFebMarAprMayJunJulAugSepOctNovDec" 111 | 112 | ;------------------------------------------------------------------------------- 113 | 114 | DateReset:: 115 | 116 | ld c,0 ; January 117 | ld de,$1950 118 | 119 | DateSet:: ; de = year, c = month 120 | 121 | ld a,c 122 | ld [date_month],a 123 | 124 | ld a,e ; LSB first 125 | ld [date_year+0],a 126 | ld a,d 127 | ld [date_year+1],a 128 | 129 | ret 130 | 131 | ;------------------------------------------------------------------------------- 132 | 133 | DateStep:: 134 | 135 | ; Month 136 | 137 | ld a,[date_month] 138 | inc a 139 | cp a,MONTHS_IN_YEAR 140 | jr z,.inc_year 141 | ld [date_month],a 142 | ret 143 | .inc_year: 144 | xor a,a ; January 145 | ld [date_month],a 146 | 147 | ; Reset yearly messages 148 | 149 | call PersistentYearlyMessagesReset 150 | 151 | ; Year 152 | 153 | ; If year 9999 is reached, stay there! 154 | ; Months will continue to increment 155 | ld a,[date_year+0] 156 | cp a,$99 157 | jr nz,.year_not_maxed 158 | ld a,[date_year+1] 159 | cp a,$99 160 | ret z 161 | .year_not_maxed: 162 | 163 | ld a,[date_year+0] 164 | add a,1 ; inc doesn't set carry flag 165 | daa 166 | ld [date_year+0],a 167 | 168 | ld a,[date_year+1] 169 | adc a,0 ; carry from previous inc 170 | daa 171 | ld [date_year+1],a 172 | 173 | ret 174 | 175 | ;############################################################################### 176 | -------------------------------------------------------------------------------- /source/room_game/map_load.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(MAP_LOAD_INC) 24 | DEF MAP_LOAD_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | ; Autogenerated map. CITY_MAP_SRAM_FLAG is ignored if this value is used. 29 | DEF CITY_MAP_GENERATE_RANDOM EQU $FF 30 | 31 | ; If set, load from SRAM. If not, load a predefined map. 32 | DEF CITY_MAP_SRAM_FLAG EQU %10000000 33 | 34 | DEF CITY_MAP_NUMBER_MASK EQU %01111111 35 | 36 | DEF SCENARIOS_TOTAL_NUM EQU 4 ; Total number of scenarios included in the ROM 37 | 38 | ;############################################################################### 39 | 40 | ENDC ; MAP_LOAD_INC 41 | 42 | ;############################################################################### 43 | -------------------------------------------------------------------------------- /source/room_game/persistent_messages.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "text_messages.inc" 29 | 30 | ;############################################################################### 31 | 32 | SECTION "Persistent Messages Variables",WRAM0 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | persistent_msg_flags:: DS BYTES_SAVE_PERSISTENT_MSG 37 | 38 | ;############################################################################### 39 | 40 | SECTION "Persistent Messages Functions Bank 0",ROM0 41 | 42 | ;------------------------------------------------------------------------------- 43 | 44 | ; Load data from HL into persistent message flags 45 | PersistentMessageDataLoadFrom:: ; hl = ptr to data to load 46 | 47 | ld bc,BYTES_SAVE_PERSISTENT_MSG 48 | ld de,persistent_msg_flags 49 | call memcopy ; bc = size hl = source address de = dest address 50 | 51 | ret 52 | 53 | ;------------------------------------------------------------------------------- 54 | 55 | ; Save data to DE from persistent message flags 56 | PersistentMessageDataSaveTo:: ; de = ptr to space to save 57 | 58 | ld bc,BYTES_SAVE_PERSISTENT_MSG 59 | ld hl,persistent_msg_flags 60 | call memcopy ; bc = size hl = source address de = dest address 61 | 62 | ret 63 | 64 | ;------------------------------------------------------------------------------- 65 | 66 | ; The message ID should be a valid persistent message ID 67 | PersistentMessageShow:: ; a = message ID 68 | 69 | ld c,a ; (**) save original message ID 70 | 71 | ; Message IDs start at 1 72 | dec a 73 | 74 | ld b,a ; (*) save message ID - 1 75 | 76 | sra a 77 | sra a 78 | sra a ; a = ID - 1 / 8 79 | ld hl,persistent_msg_flags 80 | ld e,a 81 | ld d,0 82 | add hl,de 83 | ; hl = pointer to byte which contains the flag 84 | 85 | ld a,7 86 | and a,b ; (*) get bit inside the byte (must be preserved a bit more) 87 | 88 | ; Test if bit \1 is set and sets it to 1 89 | MACRO TEST_AND_SET_FLAG ; \1 = bit 90 | cp a,\1 91 | jr nz,.not_set\@ 92 | bit \1,[hl] ; set or reset Z flag 93 | set \1,[hl] 94 | jr .end_test 95 | .not_set\@: 96 | ENDM 97 | 98 | TEST_AND_SET_FLAG 0 99 | TEST_AND_SET_FLAG 1 100 | TEST_AND_SET_FLAG 2 101 | TEST_AND_SET_FLAG 3 102 | TEST_AND_SET_FLAG 4 103 | TEST_AND_SET_FLAG 5 104 | TEST_AND_SET_FLAG 6 105 | TEST_AND_SET_FLAG 7 106 | 107 | ld b,b ; This shouldn't happen! 108 | ret 109 | 110 | .end_test: ; If Z flag is set to 1, show message 111 | 112 | ld a,c ; (**) get message id 113 | call z,MessageRequestAdd ; a = message ID to show 114 | 115 | ret 116 | 117 | ;------------------------------------------------------------------------------- 118 | 119 | PersistentYearlyMessagesReset:: 120 | 121 | ld hl,persistent_msg_flags 122 | ; hl = pointer to byte which contains the first flag 123 | 124 | xor a,a 125 | ld b,ID_MSG_RESET_YEAR_NUM/8 126 | .loop: 127 | ld [hl+],a 128 | dec b 129 | jr nz,.loop 130 | 131 | ret 132 | 133 | ;############################################################################### 134 | -------------------------------------------------------------------------------- /source/room_game/text_messages.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(TEXT_MESSAGES_INC) 24 | DEF TEXT_MESSAGES_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF ROM_BANK_TEXT_MSG EQU 3 29 | 30 | ;------------------------------------------------------------------------------- 31 | 32 | ; Labels should be named MSG_xxxx and IDs should be named ID_MSG_xxxx 33 | 34 | DEF ID_MSG_EMPTY EQU 0 35 | 36 | ; Messages that are only shown once per year. 37 | DEF ID_MSG_POLLUTION_HIGH EQU 1 38 | DEF ID_MSG_TRAFFIC_HIGH EQU 2 39 | DEF ID_MSG_MONEY_NEGATIVE_CAN_LOAN EQU 3 40 | DEF ID_MSG_MONEY_NEGATIVE_CANT_LOAN EQU 4 41 | 42 | DEF ID_MSG_RESET_YEAR_NUM EQU 8 ; Multiple of 8 43 | 44 | ; Persistent messages (they are only shown once per city) 45 | DEF ID_MSG_CLASS_TOWN EQU 9 46 | DEF ID_MSG_CLASS_CITY EQU 10 47 | DEF ID_MSG_CLASS_METROPOLIS EQU 11 48 | DEF ID_MSG_CLASS_CAPITAL EQU 12 49 | DEF ID_MSG_TECH_NUCLEAR EQU 13 50 | DEF ID_MSG_TECH_FUSION EQU 14 51 | 52 | DEF ID_MSG_PERSISTENT_NUM EQU 16 ; Multiple of 8 53 | 54 | ; Regular messages 55 | DEF ID_MSG_FIRE_INITED EQU 17 56 | DEF ID_MSG_NUCLEAR_MELTDOWN EQU 18 57 | DEF ID_MSG_TECH_INSUFFICIENT EQU 19 58 | DEF ID_MSG_POPULATION_INSUFFICIENT EQU 20 59 | DEF ID_MSG_FINISHED_LOAN EQU 21 60 | DEF ID_MSG_GAME_OVER_1 EQU 22 61 | DEF ID_MSG_GAME_OVER_2 EQU 23 62 | 63 | ; Extra 64 | DEF ID_MSG_CUSTOM EQU $FF ; Can only be in the queue once! Careful with it! 65 | 66 | ;------------------------------------------------------------------------------- 67 | 68 | ; Number of bytes needed to store a flag for each persistent message. 69 | DEF BYTES_SAVE_PERSISTENT_MSG EQU ((ID_MSG_PERSISTENT_NUM+7)/8) ; Round up to 8 bits 70 | 71 | ;############################################################################### 72 | 73 | ENDC ; TEXT_MESSAGES_INC 74 | 75 | ;############################################################################### 76 | -------------------------------------------------------------------------------- /source/room_game/tileset.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | SECTION "City Tileset",ROMX 24 | 25 | ;------------------------------------------------------------------------------- 26 | 27 | CITY_TILESET:: 28 | INCBIN "city_tiles.bin" 29 | 30 | CITY_TILESET_PALETTES:: ; Same bank as CITY_TILESET! 31 | DW (31<<10)|(31<<5)|(31<<0), (10<<10)|(31<<5)|(10<<0) 32 | DW (1<<10)|(16<<5)|(3<<0), (0<<10)|(3<<5)|(6<<0) 33 | 34 | DW (31<<10)|(31<<5)|(31<<0), (31<<10)|(20<<5)|(0<<0) 35 | DW (31<<10)|(0<<5)|(0<<0), (0<<10)|(0<<5)|(0<<0) 36 | 37 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(31<<0) 38 | DW (0<<10)|(15<<5)|(31<<0), (0<<10)|(0<<5)|(0<<0) 39 | 40 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(28<<0) 41 | DW (5<<10)|(20<<5)|(31<<0), (0<<10)|(12<<5)|(17<<0) 42 | 43 | DW (31<<10)|(31<<5)|(31<<0), (10<<10)|(31<<5)|(10<<0) 44 | DW (5<<10)|(15<<5)|(5<<0), (0<<10)|(0<<5)|(0<<0) 45 | 46 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(15<<5)|(31<<0) 47 | DW (0<<10)|(0<<5)|(31<<0), (0<<10)|(0<<5)|(0<<0) 48 | 49 | DW 0,0,0,0 50 | 51 | DW (31<<10)|(31<<5)|(31<<0), (21<<10)|(21<<5)|(21<<0) 52 | DW (10<<10)|(10<<5)|(10<<0), (0<<10)|(0<<5)|(0<<0) 53 | 54 | ;############################################################################### 55 | -------------------------------------------------------------------------------- /source/room_gbc_only/room_gbc_only.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;############################################################################### 27 | 28 | SECTION "Room Only For GBC Data",ROMX 29 | 30 | ;------------------------------------------------------------------------------- 31 | 32 | ONLY_FOR_GBC_BG_MAP: 33 | INCBIN "only_for_gbc_bg_map.bin" 34 | 35 | DEF ONLY_FOR_GBC_WIDTH EQU 20 36 | DEF ONLY_FOR_GBC_HEIGHT EQU 18 37 | 38 | ;------------------------------------------------------------------------------- 39 | 40 | OnlyForGBCLoadBG: 41 | 42 | ; Load border 43 | ; ----------- 44 | 45 | ld b,BANK(ONLY_FOR_GBC_BG_MAP) 46 | call rom_bank_push_set 47 | 48 | ld hl,ONLY_FOR_GBC_BG_MAP 49 | 50 | ; Load map 51 | ; -------- 52 | 53 | ; Tiles 54 | 55 | ld de,$9800 56 | ;HL = pointer to map 57 | 58 | ld a,ONLY_FOR_GBC_HEIGHT 59 | .loop1: 60 | push af 61 | 62 | ld b,ONLY_FOR_GBC_WIDTH 63 | call vram_copy_fast ; b = size - hl = source address - de = dest 64 | 65 | push hl 66 | ld hl,32-ONLY_FOR_GBC_WIDTH 67 | add hl,de 68 | ld d,h 69 | ld e,l 70 | pop hl 71 | 72 | pop af 73 | dec a 74 | jr nz,.loop1 75 | 76 | call rom_bank_pop 77 | 78 | ret 79 | 80 | ;------------------------------------------------------------------------------- 81 | 82 | RoomOnlyForGBC:: 83 | 84 | xor a,a ; White screen 85 | ldh [rBGP],a 86 | 87 | call SetDefaultVBLHandler 88 | 89 | xor a,a 90 | ldh [rSCX],a 91 | ldh [rSCY],a 92 | 93 | ld a,LCDCF_BG9800|LCDCF_BGON|LCDCF_BG8800|LCDCF_ON 94 | ldh [rLCDC],a 95 | 96 | ld b,1 ; bank at 8800h 97 | call LoadText 98 | 99 | call OnlyForGBCLoadBG 100 | 101 | ld a,$1B 102 | ldh [rBGP],a 103 | 104 | .loop: 105 | halt 106 | jr .loop 107 | 108 | ;############################################################################### 109 | -------------------------------------------------------------------------------- /source/room_graphs/graph_money.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_graphs.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Money Graph Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | GRAPH_MONEY_PALETTE: 38 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(0<<0) 39 | DW (0<<10)|(31<<5)|(31<<0), (0<<10)|(0<<5)|(0<<0) 40 | 41 | GRAPH_MONEY_TITLE: 42 | STR_ADD "Money" 43 | 44 | GraphDrawMoney:: 45 | 46 | ; Clean graph buffer first 47 | ; ------------------------ 48 | 49 | LONG_CALL APA_BufferClear 50 | 51 | ld a,3 52 | call APA_SetColor0 ; a = color 53 | 54 | ; Draw graph 55 | ; ---------- 56 | 57 | ld hl,GRAPH_MONEY_DATA 58 | ld d,0 59 | ld a,[GRAPH_MONEY_OFFSET] 60 | ld e,a 61 | add hl,de ; hl = start of data 62 | 63 | ld d,a ; d = current offset 64 | ld e,0 ; e = x 65 | .loopx: 66 | 67 | push hl 68 | push de ; (*) 69 | 70 | ld a,[hl] 71 | cp a,GRAPH_INVALID_ENTRY 72 | jr z,.skip_entry 73 | 74 | ld c,a ; 127-y 75 | ld b,e ; x 76 | 77 | ld a,127 78 | sub a,c 79 | ld c,a 80 | 81 | LONG_CALL_ARGS APA_Plot ; b = x, c = y (0-127!) 82 | .skip_entry: 83 | 84 | pop de ; (*) 85 | pop hl 86 | 87 | inc hl 88 | inc d 89 | 90 | bit 7,d 91 | jr z,.not_overflow_ring_buffer 92 | ld hl,GRAPH_MONEY_DATA 93 | ld d,0 94 | .not_overflow_ring_buffer: 95 | 96 | inc e 97 | bit 7,e ; GRAPH_SIZE = 128 98 | jr z,.loopx 99 | 100 | ; Set White 101 | call MinimapSetDefaultPalette 102 | 103 | ; Refresh screen with backbuffer data 104 | call APA_BufferUpdate 105 | 106 | ; Load palette 107 | ld hl,GRAPH_MONEY_PALETTE 108 | call APA_LoadPalette 109 | 110 | ; Draw title 111 | ld hl,GRAPH_MONEY_TITLE 112 | call RoomMinimapDrawTitle 113 | 114 | ret 115 | 116 | ;############################################################################### 117 | -------------------------------------------------------------------------------- /source/room_graphs/graph_population.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_graphs.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Total Population Graph Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | GRAPH_TOTAL_POPULATION_PALETTE: 38 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(0<<0) 39 | DW (0<<10)|(31<<5)|(31<<0), (0<<10)|(0<<5)|(0<<0) 40 | 41 | GRAPH_TOTAL_POPULATION_TITLE: 42 | STR_ADD "Total Population" 43 | 44 | GraphDrawTotalPopulation:: 45 | 46 | ; Clean graph buffer first 47 | ; ------------------------ 48 | 49 | LONG_CALL APA_BufferClear 50 | 51 | ld a,3 52 | call APA_SetColor0 ; a = color 53 | 54 | ; Draw graph 55 | ; ---------- 56 | 57 | ld hl,GRAPH_POPULATION_DATA 58 | ld d,0 59 | ld a,[GRAPH_POPULATION_OFFSET] 60 | ld e,a 61 | add hl,de ; hl = start of data 62 | 63 | ld d,a ; d = current offset 64 | ld e,0 ; e = x 65 | .loopx: 66 | 67 | push hl 68 | push de ; (*) 69 | 70 | ld a,[hl] 71 | cp a,GRAPH_INVALID_ENTRY 72 | jr z,.skip_entry 73 | 74 | ld c,a ; 127-y 75 | ld b,e ; x 76 | 77 | ld a,127 78 | sub a,c 79 | ld c,a 80 | 81 | LONG_CALL_ARGS APA_Plot ; b = x, c = y (0-127!) 82 | .skip_entry: 83 | 84 | pop de ; (*) 85 | pop hl 86 | 87 | inc hl 88 | inc d 89 | 90 | bit 7,d 91 | jr z,.not_overflow_ring_buffer 92 | ld hl,GRAPH_POPULATION_DATA 93 | ld d,0 94 | .not_overflow_ring_buffer: 95 | 96 | inc e 97 | bit 7,e ; GRAPH_SIZE = 128 98 | jr z,.loopx 99 | 100 | ; Set White 101 | call MinimapSetDefaultPalette 102 | 103 | ; Refresh screen with backbuffer data 104 | call APA_BufferUpdate 105 | 106 | ; Load palette 107 | ld hl,GRAPH_TOTAL_POPULATION_PALETTE 108 | call APA_LoadPalette 109 | 110 | ; Draw title 111 | ld hl,GRAPH_TOTAL_POPULATION_TITLE 112 | call RoomMinimapDrawTitle 113 | 114 | ret 115 | 116 | ;############################################################################### 117 | -------------------------------------------------------------------------------- /source/room_graphs/graph_rci.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_graphs.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "RCI Graph Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | GRAPH_RCI_PALETTE: ; White, Green, Yellow, Blue 38 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(0<<0) 39 | DW (0<<10)|(31<<5)|(31<<0), (31<<10)|(0<<5)|(0<<0) 40 | 41 | GRAPH_RCI_TITLE: 42 | STR_ADD "Sector Population" 43 | 44 | GraphDrawRCI:: 45 | 46 | ; Clean graph buffer first 47 | ; ------------------------ 48 | 49 | LONG_CALL APA_BufferClear 50 | 51 | ; Draw graph 52 | ; ---------- 53 | 54 | MACRO DRAW_GRAPH ; \1 = name of sector 55 | 56 | ld hl,GRAPH_\1_DATA 57 | ld d,0 58 | ld a,[GRAPH_\1_OFFSET] 59 | ld e,a 60 | add hl,de ; hl = start of data 61 | 62 | ld d,a ; d = current offset 63 | ld e,0 ; e = x 64 | .loopx\@: 65 | 66 | push hl 67 | push de ; (*) 68 | 69 | ld a,[hl] 70 | cp a,GRAPH_INVALID_ENTRY 71 | jr z,.skip_entry\@ 72 | 73 | ld c,a ; 127-y 74 | ld b,e ; x 75 | 76 | ld a,127 77 | sub a,c 78 | ld c,a 79 | 80 | LONG_CALL_ARGS APA_Plot ; b = x, c = y (0-127!) 81 | .skip_entry\@: 82 | 83 | pop de ; (*) 84 | pop hl 85 | 86 | inc hl 87 | inc d 88 | 89 | bit 7,d 90 | jr z,.not_overflow_ring_buffer\@ 91 | ld hl,GRAPH_\1_DATA 92 | ld d,0 93 | .not_overflow_ring_buffer\@: 94 | 95 | inc e 96 | bit 7,e ; GRAPH_SIZE = 128 97 | jr z,.loopx\@ 98 | 99 | ENDM 100 | 101 | ld a,1 ; Green 102 | call APA_SetColor0 ; a = color 103 | DRAW_GRAPH RESIDENTIAL 104 | 105 | ld a,2 ; Yellow 106 | call APA_SetColor0 ; a = color 107 | DRAW_GRAPH INDUSTRIAL 108 | 109 | ld a,3 ; Blue 110 | call APA_SetColor0 ; a = color 111 | DRAW_GRAPH COMMERCIAL 112 | 113 | ; Set White 114 | call MinimapSetDefaultPalette 115 | 116 | ; Refresh screen with backbuffer data 117 | call APA_BufferUpdate 118 | 119 | ; Load palette 120 | ld hl,GRAPH_RCI_PALETTE 121 | call APA_LoadPalette 122 | 123 | ; Draw title 124 | ld hl,GRAPH_RCI_TITLE 125 | call RoomMinimapDrawTitle 126 | 127 | ret 128 | 129 | ;############################################################################### 130 | -------------------------------------------------------------------------------- /source/room_graphs/room_graphs.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "room_graphs.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Room Graphs Variables",WRAM0 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | graphs_room_exit: DS 1 ; set to 1 to exit room 38 | 39 | graphs_selected: DS 1 40 | 41 | ;############################################################################### 42 | 43 | SECTION "Room Graphs Functions",ROMX 44 | 45 | ;------------------------------------------------------------------------------- 46 | 47 | GraphsDrawSelected:: 48 | 49 | ; Not needed to clear first, the drawing functions draw over everything 50 | 51 | ld a,[graphs_selected] 52 | 53 | cp a,GRAPHS_SELECTION_POPULATION 54 | jr nz,.not_population 55 | LONG_CALL GraphDrawTotalPopulation 56 | ret 57 | .not_population: 58 | cp a,GRAPHS_SELECTION_RCI 59 | jr nz,.not_rci 60 | LONG_CALL GraphDrawRCI 61 | ret 62 | .not_rci: 63 | cp a,GRAPHS_SELECTION_MONEY 64 | jr nz,.not_money 65 | LONG_CALL GraphDrawMoney 66 | ret 67 | .not_money: 68 | 69 | ld b,b ; Not found! 70 | call MinimapSetDefaultPalette 71 | LONG_CALL APA_BufferClear 72 | call APA_BufferUpdate 73 | 74 | ret 75 | 76 | ;------------------------------------------------------------------------------- 77 | 78 | GraphsSelectGraph:: ; b = graph to select 79 | 80 | ld a,b 81 | ld [graphs_selected],a 82 | 83 | ret 84 | 85 | ;------------------------------------------------------------------------------- 86 | 87 | InputHandleGraphs: 88 | 89 | LONG_CALL_ARGS GraphsMenuHandleInput ; If it returns 1, exit room 90 | and a,a 91 | ret z ; don't exit 92 | 93 | ; Exit 94 | ld a,1 95 | ld [graphs_room_exit],a 96 | ret 97 | 98 | ;------------------------------------------------------------------------------- 99 | 100 | RoomGraphs:: 101 | 102 | call SetPalettesAllBlack 103 | 104 | LONG_CALL GraphsMenuReset 105 | 106 | ld bc,RoomGraphsVBLHandler 107 | call irq_set_VBL 108 | 109 | xor a,a 110 | ldh [rSCX],a 111 | ldh [rSCY],a 112 | 113 | ld a,LCDCF_BG9800|LCDCF_OBJON|LCDCF_BG8800|LCDCF_ON 114 | ldh [rLCDC],a 115 | 116 | ld b,1 ; bank at 8800h 117 | call LoadText 118 | 119 | LONG_CALL RoomMinimapLoadBG ; Same graphics as minimap room 120 | 121 | call LoadTextPalette 122 | 123 | ld a,GRAPHS_SELECTION_POPULATION 124 | ld [graphs_selected],a 125 | 126 | LONG_CALL GraphsDrawSelected 127 | 128 | ; This can be loaded after the rest, it isn't shown until A is pressed 129 | ; so there is no hurry. 130 | LONG_CALL GraphsMenuLoadGFX 131 | 132 | xor a,a 133 | ld [graphs_room_exit],a 134 | 135 | .loop: 136 | 137 | call wait_vbl 138 | 139 | call scan_keys 140 | call KeyAutorepeatHandle 141 | 142 | call InputHandleGraphs 143 | 144 | ld a,[graphs_room_exit] 145 | and a,a 146 | jr z,.loop 147 | 148 | call SetDefaultVBLHandler 149 | 150 | call WaitReleasedAllKeys 151 | 152 | call SetPalettesAllBlack 153 | 154 | ret 155 | 156 | ;############################################################################### 157 | 158 | SECTION "Room Graphs Code Bank 0",ROM0 159 | 160 | ;------------------------------------------------------------------------------- 161 | 162 | RoomGraphsVBLHandler: 163 | 164 | call GraphsMenuVBLHandler 165 | 166 | call refresh_OAM 167 | 168 | call SFX_Handler 169 | 170 | call rom_bank_push 171 | call gbt_update 172 | call rom_bank_pop 173 | 174 | ret 175 | 176 | ;############################################################################### 177 | -------------------------------------------------------------------------------- /source/room_graphs/room_graphs.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(ROOM_GRAPHS_INC) 24 | DEF ROOM_GRAPHS_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF GRAPHS_SELECTION_POPULATION EQU 0 29 | DEF GRAPHS_SELECTION_RCI EQU 1 30 | DEF GRAPHS_SELECTION_MONEY EQU 2 31 | 32 | DEF GRAPHS_SELECTION_MAX EQU 2 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | ; Valid values are 0-127 37 | DEF GRAPH_INVALID_ENTRY EQU -1 ; Entries that should be considered empty 38 | 39 | DEF GRAPH_SIZE EQU 128 ; Entries per graph. It must be a power of 2 40 | 41 | ;############################################################################### 42 | 43 | ENDC ; ROOM_GRAPHS_INC 44 | 45 | ;############################################################################### 46 | -------------------------------------------------------------------------------- /source/room_minimap/minimap_disasters.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Minimap Disasters Map Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | DEF C_WHITE EQU 0 ; Other tiles 38 | DEF C_GREEN EQU 1 ; Vegetation, burnable things... 39 | DEF C_RED EQU 2 ; Fire 40 | DEF C_BLUE EQU 3 ; Water 41 | 42 | MINIMAP_DISASTERS_MAP_PALETTE: 43 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(0<<0) 44 | DW (0<<10)|(0<<5)|(31<<0), (31<<10)|(0<<5)|(0<<0) 45 | 46 | MINIMAP_DISASTERS_MAP_TITLE: 47 | STR_ADD "Disasters" 48 | 49 | MinimapDrawDisastersMap:: 50 | 51 | ; No need to simulate 52 | 53 | ; Draw map 54 | ; -------- 55 | 56 | LONG_CALL APA_PixelStreamStart 57 | 58 | ld hl,CITY_MAP_TILES ; Base address of the map! 59 | 60 | ld d,0 ; d = y 61 | .loopy: 62 | 63 | ld e,0 ; e = x 64 | .loopx: 65 | 66 | push de ; (*) 67 | push hl 68 | 69 | ; Returns a = type, hl = address 70 | call CityMapGetType ; Arguments: e = x , d = y 71 | cp a,TYPE_FIRE 72 | jr nz,.not_fire 73 | ld a,C_RED 74 | ld b,a 75 | ld c,a 76 | ld d,a 77 | jr .end_color 78 | .not_fire: 79 | 80 | bit TYPE_HAS_POWER_BIT,a 81 | jr nz,.not_water ; Only power line bridges are burnable! 82 | 83 | and a,TYPE_MASK 84 | cp a,TYPE_WATER 85 | jr nz,.not_water 86 | ld a,C_BLUE 87 | ld b,a; C_WHITE 88 | ld c,a; C_WHITE 89 | ld d,C_BLUE 90 | jr .end_color 91 | .not_water: 92 | 93 | ; Check if this is burnable or not 94 | push hl 95 | call CityMapGetTileAtAddress ; hl=addr, returns tile=de 96 | call CityTileFireProbability ; de = tile, ret d = probability 97 | pop hl 98 | 99 | ld a,d 100 | and a,a 101 | jr z,.not_burnable 102 | 103 | ; Enough power 104 | ld a,C_GREEN 105 | ld b,a ;C_WHITE 106 | ld c,a ; C_WHITE 107 | ld d,C_GREEN 108 | jr .end_color 109 | 110 | .not_burnable: 111 | 112 | ld a,C_WHITE 113 | ld b,a 114 | ld c,a 115 | ld d,a 116 | .end_color: 117 | 118 | call APA_SetColors ; a,b,c,d = color (0 to 3) 119 | LONG_CALL APA_PixelStreamPlot2x2 120 | 121 | pop hl 122 | pop de ; (*) 123 | 124 | inc hl 125 | 126 | inc e 127 | bit 6,e 128 | jp z,.loopx 129 | 130 | inc d 131 | bit 6,d 132 | jp z,.loopy 133 | 134 | ; Set White 135 | call MinimapSetDefaultPalette 136 | 137 | ; Refresh screen with backbuffer data 138 | call APA_BufferUpdate 139 | 140 | ; Load palette 141 | ld hl,MINIMAP_DISASTERS_MAP_PALETTE 142 | call APA_LoadPalette 143 | 144 | ; Draw title 145 | ld hl,MINIMAP_DISASTERS_MAP_TITLE 146 | call RoomMinimapDrawTitle 147 | 148 | ret 149 | 150 | ;############################################################################### 151 | -------------------------------------------------------------------------------- /source/room_minimap/minimap_pollution.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "text.inc" 30 | INCLUDE "tileset_info.inc" 31 | 32 | ;############################################################################### 33 | 34 | SECTION "Minimap Pollution Functions",ROMX 35 | 36 | ;------------------------------------------------------------------------------- 37 | 38 | MINIMAP_TILE_COLORS_POLLUTION: 39 | DB 0,0,0,0 40 | DB 0,1,1,0 41 | DB 1,1,1,1 42 | DB 1,2,2,1 43 | DB 2,2,2,2 44 | DB 2,3,3,2 45 | DB 3,3,3,3 46 | DB 3,3,3,3 47 | 48 | MINIMAP_POLLUTION_MAP_PALETTE: 49 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(31<<0) 50 | DW (0<<10)|(15<<5)|(31<<0), (0<<10)|(0<<5)|(31<<0) 51 | 52 | MINIMAP_POLLUTION_MAP_TITLE: 53 | STR_ADD "Pollution" 54 | 55 | ;------------------------------------------------------------------------------- 56 | 57 | MinimapDrawPollutionMap:: 58 | 59 | ; Simulate and get data! 60 | ; ---------------------- 61 | 62 | LONG_CALL Simulation_Pollution ; Returns values 0-255 in SCRATCH RAM bank 63 | 64 | ; Draw map 65 | ; -------- 66 | 67 | LONG_CALL APA_PixelStreamStart 68 | 69 | ld hl,SCRATCH_RAM 70 | 71 | ld d,0 ; d = y 72 | .loopy: 73 | 74 | ld e,0 ; e = x 75 | .loopx: 76 | 77 | push de ; (*) 78 | push hl 79 | 80 | ld a,BANK_SCRATCH_RAM 81 | ldh [rSVBK],a 82 | 83 | ld a,[hl] 84 | rlca 85 | rlca 86 | rlca ; Overflow from top bits 87 | and a,7 ; Reduce from 8 to 3 bits 88 | 89 | ld de,MINIMAP_TILE_COLORS_POLLUTION 90 | ld l,a 91 | ld h,0 92 | add hl,hl 93 | add hl,hl ; a *= 4 94 | add hl,de 95 | 96 | ld a,[hl+] 97 | ld b,[hl] 98 | inc hl 99 | ld c,[hl] 100 | inc hl 101 | ld d,[hl] 102 | 103 | call APA_SetColors ; a,b,c,d = color (0 to 3) 104 | LONG_CALL APA_PixelStreamPlot2x2 105 | 106 | pop hl 107 | pop de ; (*) 108 | 109 | inc hl 110 | 111 | inc e 112 | bit 6,e 113 | jp z,.loopx 114 | 115 | inc d 116 | bit 6,d 117 | jp z,.loopy 118 | 119 | 120 | ; Set screen white 121 | call MinimapSetDefaultPalette 122 | 123 | ; Refresh screen with backbuffer data 124 | call APA_BufferUpdate 125 | 126 | ; Load palette 127 | ld hl,MINIMAP_POLLUTION_MAP_PALETTE 128 | call APA_LoadPalette 129 | 130 | ; Draw title 131 | ld hl,MINIMAP_POLLUTION_MAP_TITLE 132 | call RoomMinimapDrawTitle 133 | 134 | ret 135 | 136 | ;############################################################################### 137 | -------------------------------------------------------------------------------- /source/room_minimap/minimap_population.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Minimap Population Density Map Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | ; 63-1 Because the value is rounded up to show tiles with value 1. If not, 38 | ; they would be drawn as empty. 39 | DEF MAX_DISPLAYABLE_POPULATION_DENSITY EQU 62 40 | 41 | ;------------------------------------------------------------------------------- 42 | 43 | MINIMAP_TILE_COLORS_POPULATION: 44 | DB 0,0,0,0 45 | DB 0,1,1,0 46 | DB 1,1,1,1 47 | DB 1,2,2,1 48 | DB 2,2,2,2 49 | DB 2,3,3,2 50 | DB 3,3,3,3 51 | DB 3,3,3,3 52 | 53 | MINIMAP_POPULATION_DENSITY_MAP_PALETTE: 54 | DW (31<<10)|(31<<5)|(31<<0), (0<<10)|(31<<5)|(0<<0) 55 | DW (0<<10)|(31<<5)|(31<<0), (0<<10)|(0<<5)|(31<<0) 56 | 57 | MINIMAP_POPULATION_DENSITY_MAP_TITLE: 58 | STR_ADD "Population Density" 59 | 60 | MinimapDrawPopulationDensityMap:: 61 | 62 | ; Draw map 63 | ; -------- 64 | 65 | LONG_CALL APA_PixelStreamStart 66 | 67 | ld hl,CITY_MAP_TILES ; Base address of the map! 68 | 69 | ld d,0 ; d = y 70 | .loopy: 71 | 72 | ld e,0 ; e = x 73 | .loopx: 74 | 75 | push de ; (*) 76 | push hl 77 | 78 | call CityMapGetTileAtAddress ; hl = address, returns de = tile 79 | 80 | LONG_CALL_ARGS CityTileDensity ; de = tile, returns d=population 81 | 82 | ld a,d 83 | cp a,MAX_DISPLAYABLE_POPULATION_DENSITY+1 ; Saturate 84 | jr c,.not_overflow 85 | ld a,MAX_DISPLAYABLE_POPULATION_DENSITY 86 | .not_overflow: 87 | 88 | IF MAX_DISPLAYABLE_POPULATION_DENSITY != 62 89 | FAIL "Fix this!" 90 | ENDC 91 | inc a ; Round up 92 | sra a 93 | sra a 94 | sra a ; From 6 bits to 3 (63 -> 7) 95 | 96 | ld de,MINIMAP_TILE_COLORS_POPULATION 97 | ld l,a 98 | ld h,0 99 | add hl,hl 100 | add hl,hl ; a *= 4 101 | add hl,de 102 | 103 | ld a,[hl+] 104 | ld b,[hl] 105 | inc hl 106 | ld c,[hl] 107 | inc hl 108 | ld d,[hl] 109 | 110 | call APA_SetColors ; a,b,c,d = color (0 to 3) 111 | LONG_CALL APA_PixelStreamPlot2x2 112 | 113 | pop hl 114 | pop de ; (*) 115 | 116 | inc hl 117 | 118 | inc e 119 | bit 6,e 120 | jp z,.loopx 121 | 122 | inc d 123 | bit 6,d 124 | jp z,.loopy 125 | 126 | ; Set White 127 | call MinimapSetDefaultPalette 128 | 129 | ; Refresh screen with backbuffer data 130 | call APA_BufferUpdate 131 | 132 | ; Load palette 133 | ld hl,MINIMAP_POPULATION_DENSITY_MAP_PALETTE 134 | call APA_LoadPalette 135 | 136 | ; Draw title 137 | ld hl,MINIMAP_POPULATION_DENSITY_MAP_TITLE 138 | call RoomMinimapDrawTitle 139 | 140 | ret 141 | 142 | ;############################################################################### 143 | -------------------------------------------------------------------------------- /source/room_minimap/minimap_zone_map.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "text.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Minimap Zone Map Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | DEF C_WHITE EQU 0 38 | DEF C_BLUE EQU 1 39 | DEF C_GREEN EQU 2 40 | DEF C_YELLOW EQU 3 41 | 42 | MINIMAP_ZONE_MAP_PALETTE: 43 | DW (31<<10)|(31<<5)|(31<<0), (31<<10)|(0<<5)|(0<<0) 44 | DW (0<<10)|(31<<5)|(0<<0), (0<<10)|(31<<5)|(31<<0) 45 | 46 | MINIMAP_ZONE_MAP_TYPE_COLOR_ARRAY: 47 | DB C_WHITE, C_WHITE, C_WHITE, C_WHITE ; TYPE_FIELD 48 | DB C_GREEN, C_WHITE, C_WHITE, C_GREEN ; TYPE_FOREST 49 | DB C_BLUE, C_WHITE, C_WHITE, C_BLUE ; TYPE_WATER 50 | DB C_GREEN, C_GREEN, C_GREEN, C_GREEN ; TYPE_RESIDENTIAL 51 | DB C_YELLOW,C_YELLOW,C_YELLOW,C_YELLOW ; TYPE_INDUSTRIAL 52 | DB C_BLUE, C_BLUE, C_BLUE, C_BLUE ; TYPE_COMMERCIAL 53 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_POLICE_DEPT 54 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_FIRE_DEPT 55 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_HOSPITAL 56 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_PARK 57 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_STADIUM 58 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_SCHOOL 59 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_HIGH_SCHOOL 60 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_UNIVERSITY 61 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_MUSEUM 62 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_LIBRARY 63 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_AIRPORT 64 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_PORT 65 | DB C_BLUE, C_YELLOW,C_YELLOW,C_BLUE ; TYPE_DOCK 66 | DB C_GREEN, C_YELLOW,C_BLUE, C_GREEN ; TYPE_POWER_PLANT 67 | DB C_WHITE, C_WHITE, C_WHITE, C_WHITE ; TYPE_FIRE - Placeholder, never used 68 | DB C_WHITE, C_WHITE, C_WHITE, C_WHITE ; TYPE_RADIATION 69 | 70 | MINIMAP_ZONE_MAP_TITLE: 71 | STR_ADD "Zone Map" 72 | 73 | ;------------------------------------------------------------------------------- 74 | 75 | MinimapDrawZoneMap:: 76 | 77 | ; Draw map 78 | ; -------- 79 | 80 | LONG_CALL APA_PixelStreamStart 81 | 82 | ld d,0 ; d = y 83 | .loopy: 84 | 85 | ld e,0 ; e = x 86 | .loopx: 87 | 88 | push de ; (*) 89 | 90 | call CityMapGetType ; Arguments: e = x , d = y 91 | 92 | ; Set color from tile type 93 | 94 | and a,TYPE_MASK ; Get type without extra flags 95 | ld l,a 96 | ld h,0 97 | add hl,hl 98 | add hl,hl 99 | ld de,MINIMAP_ZONE_MAP_TYPE_COLOR_ARRAY 100 | add hl,de 101 | ld a,[hl+] 102 | ld b,[hl] 103 | inc hl 104 | ld c,[hl] 105 | inc hl 106 | ld d,[hl] 107 | 108 | call APA_SetColors ; a,b,c,d = color (0 to 3) 109 | LONG_CALL APA_PixelStreamPlot2x2 110 | 111 | pop de ; (*) 112 | 113 | inc e 114 | bit 6,e 115 | jp z,.loopx 116 | 117 | inc d 118 | bit 6,d 119 | jp z,.loopy 120 | 121 | ; Set White 122 | call MinimapSetDefaultPalette 123 | 124 | ; Refresh screen with backbuffer data 125 | call APA_BufferUpdate 126 | 127 | ; Load palette 128 | ld hl,MINIMAP_ZONE_MAP_PALETTE 129 | call APA_LoadPalette 130 | 131 | ; Draw title 132 | ld hl,MINIMAP_ZONE_MAP_TITLE 133 | call RoomMinimapDrawTitle 134 | 135 | ret 136 | 137 | ;############################################################################### 138 | -------------------------------------------------------------------------------- /source/room_minimap/room_minimap.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(ROOM_MINIMAP_INC) 24 | DEF ROOM_MINIMAP_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF MINIMAP_SELECTION_OVERVIEW EQU 0 29 | DEF MINIMAP_SELECTION_ZONE_MAP EQU 1 30 | DEF MINIMAP_SELECTION_TRANSPORT_MAP EQU 2 31 | DEF MINIMAP_SELECTION_POLICE EQU 3 32 | DEF MINIMAP_SELECTION_FIRE_PROTECTION EQU 4 33 | DEF MINIMAP_SELECTION_HOSPITALS EQU 5 34 | DEF MINIMAP_SELECTION_SCHOOLS EQU 6 35 | DEF MINIMAP_SELECTION_HIGH_SCHOOLS EQU 7 36 | DEF MINIMAP_SELECTION_POWER_GRID EQU 8 37 | DEF MINIMAP_SELECTION_POWER_DENSITY EQU 9 38 | DEF MINIMAP_SELECTION_POPULATION_DENSITY EQU 10 39 | DEF MINIMAP_SELECTION_TRAFFIC EQU 11 40 | DEF MINIMAP_SELECTION_POLLUTION EQU 12 41 | DEF MINIMAP_SELECTION_HAPPINESS EQU 13 42 | 43 | DEF MINIMAP_SELECTION_MAX EQU 13 44 | ; There's no room for any other map with the current selection menu! 45 | 46 | DEF MINIMAP_SELECTION_DISASTERS EQU 14 47 | 48 | ;############################################################################### 49 | 50 | ENDC ; ROOM_MINIMAP_INC 51 | 52 | ;############################################################################### 53 | -------------------------------------------------------------------------------- /source/room_text_input/room_text_input.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(ROOM_TEXT_INPUT_INC) 24 | DEF ROOM_TEXT_INPUT_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF TEXT_INPUT_LENGTH EQU 10 ; there's another extra char for the text terminator 29 | 30 | DEF TEXT_PROMPT_STRING_LENGTH EQU 18 31 | 32 | ;############################################################################### 33 | 34 | ENDC ; ROOM_TEXT_INPUT_INC 35 | 36 | ;############################################################################### 37 | -------------------------------------------------------------------------------- /source/save_struct.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | 25 | ;------------------------------------------------------------------------------- 26 | 27 | INCLUDE "money.inc" 28 | INCLUDE "room_graphs.inc" 29 | INCLUDE "room_text_input.inc" 30 | INCLUDE "save_struct.inc" 31 | INCLUDE "text_messages.inc" 32 | 33 | ;############################################################################### 34 | 35 | SECTION "Save Data General", SRAM[_SRAM] 36 | 37 | ;------------------------------------------------------------------------------- 38 | 39 | ; Each SRAM bank can hold information for one city. 40 | 41 | ; Magic string must always be first, checksum second. 42 | SAV_MAGIC_STRING:: DS MAGIC_STRING_LEN 43 | SAV_CHECKSUM:: DS 2 ; LSB first 44 | 45 | ; General information 46 | 47 | SAV_CITY_NAME:: DS TEXT_INPUT_LENGTH 48 | 49 | SAV_YEAR:: DS 2 ; LSB first 50 | SAV_MONTH:: DS 1 51 | 52 | SAV_LAST_SCROLL_X:: DS 1 ; Scroll when saving the game 53 | SAV_LAST_SCROLL_Y:: DS 1 54 | 55 | SAV_MONEY:: DS MONEY_AMOUNT_SIZE 56 | 57 | SAV_TAX_PERCENT:: DS 1 58 | 59 | SAV_TECHNOLOGY_LEVEL:: DS 1 60 | 61 | SAV_PERSISTENT_MSG:: DS BYTES_SAVE_PERSISTENT_MSG 62 | 63 | SAV_LOAN_REMAINING_PAYMENTS:: DS 1 ; 0 if no remaining payments (no loan) 64 | SAV_LOAN_PAYMENTS_AMOUNT:: DS 2 ; BCD, LSB first 65 | 66 | SAV_NEGATIVE_BUDGET_COUNT:: DS 1 67 | 68 | ;------------------------------------------------------------------------------- 69 | 70 | SECTION "Save Data Configuration", SRAM[_SRAM+$200] 71 | 72 | ;------------------------------------------------------------------------------- 73 | 74 | SAV_OPTIONS_DISASTERS_DISABLED:: DS 1 75 | SAV_OPTIONS_ANIMATIONS_DISABLED:: DS 1 76 | SAV_OPTIONS_MUSIC_DISABLED:: DS 1 77 | 78 | ;------------------------------------------------------------------------------- 79 | 80 | SECTION "Save Data Historical Information", SRAM[_SRAM+$400] 81 | 82 | ;------------------------------------------------------------------------------- 83 | 84 | SAV_GRAPH_POPULATION_DATA:: DS GRAPH_SIZE 85 | SAV_GRAPH_POPULATION_OFFSET:: DS 1 ; Circular buffer start index 86 | SAV_GRAPH_POPULATION_SCALE:: DS 1 87 | 88 | SAV_GRAPH_RESIDENTIAL_DATA:: DS GRAPH_SIZE 89 | SAV_GRAPH_RESIDENTIAL_OFFSET:: DS 1 ; Circular buffer start index 90 | SAV_GRAPH_RESIDENTIAL_SCALE:: DS 1 91 | 92 | SAV_GRAPH_COMMERCIAL_DATA:: DS GRAPH_SIZE 93 | SAV_GRAPH_COMMERCIAL_OFFSET:: DS 1 ; Circular buffer start index 94 | SAV_GRAPH_COMMERCIAL_SCALE:: DS 1 95 | 96 | SAV_GRAPH_INDUSTRIAL_DATA:: DS GRAPH_SIZE 97 | SAV_GRAPH_INDUSTRIAL_OFFSET:: DS 1 ; Circular buffer start index 98 | SAV_GRAPH_INDUSTRIAL_SCALE:: DS 1 99 | 100 | SAV_GRAPH_MONEY_DATA:: DS GRAPH_SIZE 101 | SAV_GRAPH_MONEY_OFFSET:: DS 1 ; Circular buffer start index 102 | SAV_GRAPH_MONEY_SCALE:: DS 1 103 | 104 | ;------------------------------------------------------------------------------- 105 | 106 | SECTION "Save Data Map Attr", SRAM[_SRAM+$E00] 107 | 108 | ;------------------------------------------------------------------------------- 109 | 110 | SAV_MAP_ATTR_BASE:: DS $1000/8 ; compressed, only the bank 0/1 bit is saved 111 | 112 | ;------------------------------------------------------------------------------- 113 | 114 | SECTION "Save Data Map", SRAM[_SRAM+$1000] 115 | 116 | ;------------------------------------------------------------------------------- 117 | 118 | SAV_MAP_TILE_BASE:: DS $1000 ; Aligned to $1000 119 | 120 | ;############################################################################### 121 | -------------------------------------------------------------------------------- /source/save_struct.inc: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | IF !DEF(SAVE_STRUCT_INC) 24 | DEF SAVE_STRUCT_INC = 1 25 | 26 | ;############################################################################### 27 | 28 | DEF MAGIC_STRING_LEN EQU 4 29 | 30 | ;############################################################################### 31 | 32 | ENDC ; SAVE_STRUCT_INC 33 | 34 | ;############################################################################### 35 | -------------------------------------------------------------------------------- /source/simulation/simulation_building_count.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "tileset_info.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Simulation Count Buildings Variables",WRAM0 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | ; The values saturate to 255 38 | 39 | COUNT_AIRPORTS:: DS 1 40 | COUNT_PORTS:: DS 1 41 | COUNT_DOCKS:: DS 1 42 | COUNT_FIRE_STATIONS:: DS 1 43 | COUNT_NUCLEAR_POWER_PLANTS:: DS 1 44 | COUNT_UNIVERSITIES:: DS 1 45 | COUNT_STADIUMS:: DS 1 46 | COUNT_MUSEUMS:: DS 1 47 | COUNT_LIBRARIES:: DS 1 48 | 49 | COUNT_ROADS:: DS 2 ; LSB first 50 | COUNT_TRAIN_TRACKS:: DS 2 ; LSB first 51 | 52 | ;############################################################################### 53 | 54 | SECTION "Simulation Count Buildings Functions",ROMX 55 | 56 | ;------------------------------------------------------------------------------- 57 | 58 | ; Call this function whenever a building is built or demolished. For example, it 59 | ; has to be called after exiting edit mode, after a fire is finally extinguished 60 | ; or simply when the map is loaded. 61 | Simulation_CountBuildings:: 62 | 63 | xor a,a 64 | 65 | ld [COUNT_AIRPORTS],a 66 | ld [COUNT_PORTS],a 67 | ld [COUNT_DOCKS],a 68 | ld [COUNT_FIRE_STATIONS],a 69 | ld [COUNT_NUCLEAR_POWER_PLANTS],a 70 | ld [COUNT_UNIVERSITIES],a 71 | ld [COUNT_STADIUMS],a 72 | ld [COUNT_MUSEUMS],a 73 | ld [COUNT_LIBRARIES],a 74 | 75 | ld [COUNT_ROADS+0],a 76 | ld [COUNT_ROADS+1],a 77 | ld [COUNT_TRAIN_TRACKS+0],a 78 | ld [COUNT_TRAIN_TRACKS+1],a 79 | 80 | ; Count the number of airports and fire stations 81 | 82 | ld hl,CITY_MAP_TILES 83 | 84 | .loop1: 85 | push hl 86 | 87 | ; Returns: - Tile -> Register DE 88 | call CityMapGetTileAtAddress ; Arg: hl = address. Preserves BC, HL 89 | 90 | MACRO CHECK_TILE ; 1 = Tile number, 2 = Variable to increase 91 | 92 | ld a,(\1)&$FF ; Check low byte first because it changes more often 93 | cp a,e 94 | jr nz,.end\@ 95 | ld a,(\1)>>8 96 | cp a,d 97 | jr nz,.end\@ 98 | ld a,[\2] 99 | inc a 100 | jr z,.end\@ ; skip store if it overflows (clamp to 255) 101 | ld [\2],a 102 | .end\@: 103 | ENDM 104 | 105 | CHECK_TILE T_AIRPORT, COUNT_AIRPORTS 106 | CHECK_TILE T_FIRE_DEPT, COUNT_FIRE_STATIONS 107 | CHECK_TILE T_PORT, COUNT_PORTS 108 | CHECK_TILE T_PORT_WATER_L, COUNT_DOCKS 109 | CHECK_TILE T_PORT_WATER_R, COUNT_DOCKS 110 | CHECK_TILE T_PORT_WATER_D, COUNT_DOCKS 111 | CHECK_TILE T_PORT_WATER_U, COUNT_DOCKS 112 | CHECK_TILE T_POWER_PLANT_NUCLEAR, COUNT_NUCLEAR_POWER_PLANTS 113 | CHECK_TILE T_UNIVERSITY, COUNT_UNIVERSITIES 114 | CHECK_TILE T_STADIUM, COUNT_STADIUMS 115 | CHECK_TILE T_MUSEUM, COUNT_MUSEUMS 116 | CHECK_TILE T_LIBRARY, COUNT_LIBRARIES 117 | 118 | pop hl 119 | 120 | inc hl 121 | 122 | bit 5,h ; Up to E000 123 | jp z,.loop1 124 | 125 | ; Count the number of train tracks 126 | 127 | ld bc,0 ; number of roads 128 | ld de,0 ; Number of train tracks 129 | ld hl,CITY_MAP_TILES 130 | 131 | ld a,BANK_CITY_MAP_TYPE 132 | ldh [rSVBK],a 133 | 134 | .loop2: 135 | 136 | ld a,[hl+] 137 | 138 | bit TYPE_HAS_ROAD_BIT,a 139 | jr z,.skip_road 140 | inc bc 141 | jr .end_iteration 142 | .skip_road: 143 | 144 | bit TYPE_HAS_TRAIN_BIT,a 145 | jr z,.skip_train 146 | inc de 147 | .skip_train: 148 | 149 | .end_iteration: 150 | 151 | bit 5,h ; Up to E000 152 | jr z,.loop2 153 | 154 | ld a,c 155 | ld [COUNT_ROADS+0],a ; LSB first 156 | ld a,b 157 | ld [COUNT_ROADS+1],a 158 | 159 | ld a,e 160 | ld [COUNT_TRAIN_TRACKS+0],a ; LSB first 161 | ld a,d 162 | ld [COUNT_TRAIN_TRACKS+1],a 163 | 164 | ret 165 | 166 | ;############################################################################### 167 | -------------------------------------------------------------------------------- /source/simulation/simulation_water.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "room_game.inc" 29 | INCLUDE "tileset_info.inc" 30 | 31 | ;############################################################################### 32 | 33 | SECTION "Simulation Water Functions",ROMX 34 | 35 | ;------------------------------------------------------------------------------- 36 | 37 | Simulation_WaterAnimate:: ; This doesn't refresh tile map! 38 | 39 | ld a,BANK_CITY_MAP_TILES 40 | ldh [rSVBK],a 41 | 42 | call GetRandom ; preserves bc, de 43 | ; a = counter until the next change 44 | and a,31 45 | inc a 46 | 47 | ld hl,CITY_MAP_TILES ; Map base 48 | 49 | .loop: 50 | 51 | dec a 52 | jr nz,.next_skip_rand 53 | 54 | IF (T_WATER > 255) || (T_WATER_EXTRA > 255) 55 | FAIL "T_WATER and T_WATER_EXTRA should be in the first 256-tile bank." 56 | ENDC 57 | 58 | ld a,[hl] ; Get low bytes 59 | 60 | cp a,T_WATER & $FF 61 | jr nz,.not_water 62 | 63 | ld a,BANK_CITY_MAP_ATTR 64 | ldh [rSVBK],a 65 | 66 | bit 3,[hl] 67 | jr nz,.next 68 | 69 | ld a,BANK_CITY_MAP_TILES 70 | ldh [rSVBK],a 71 | 72 | ld [hl],T_WATER_EXTRA & $FF 73 | 74 | .not_water: 75 | 76 | cp a,T_WATER_EXTRA & $FF 77 | jr nz,.not_water_extra 78 | 79 | ld a,BANK_CITY_MAP_ATTR 80 | ldh [rSVBK],a 81 | 82 | bit 3,[hl] 83 | jr nz,.next 84 | 85 | ld a,BANK_CITY_MAP_TILES 86 | ldh [rSVBK],a 87 | 88 | ld [hl],T_WATER & $FF 89 | 90 | .not_water_extra: 91 | 92 | .next: 93 | 94 | LD_BC_HL 95 | call GetRandom ; preserves bc, de 96 | LD_HL_BC 97 | ; a = counter until the next change 98 | and a,31 99 | inc a 100 | 101 | .next_skip_rand: 102 | 103 | inc hl 104 | 105 | bit 5,h ; Up to E000 106 | jr z,.loop 107 | 108 | ret 109 | 110 | ;############################################################################### 111 | -------------------------------------------------------------------------------- /source/text.asm: -------------------------------------------------------------------------------- 1 | ;############################################################################### 2 | ; 3 | ; µCity - City building game for Game Boy Color. 4 | ; Copyright (c) 2017-2018 Antonio Niño Díaz (AntonioND/SkyLyrac) 5 | ; 6 | ; This program is free software: you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation, either version 3 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program. If not, see . 18 | ; 19 | ; Contact: antonio_nd@outlook.com 20 | ; 21 | ;############################################################################### 22 | 23 | INCLUDE "hardware.inc" 24 | INCLUDE "engine.inc" 25 | 26 | ;------------------------------------------------------------------------------- 27 | 28 | INCLUDE "text.inc" 29 | 30 | ;############################################################################### 31 | 32 | SECTION "Text Data",ROMX 33 | 34 | ;------------------------------------------------------------------------------- 35 | 36 | TextTilesData: 37 | .s: 38 | INCBIN "text_tiles.bin" 39 | .e: 40 | 41 | DEF TextTilesNumber EQU (.e - .s) / (8*8/4) 42 | DEF TEXT_BASE_TILE EQU (128-TextTilesNumber) 43 | 44 | ;############################################################################### 45 | 46 | SECTION "Text Functions",ROM0 47 | 48 | ;------------------------------------------------------------------------------- 49 | 50 | TEXT_PALETTE:: ; To be loaded in slot 7 51 | DW (31<<10)|(31<<5)|(31<<0), (21<<10)|(21<<5)|(21<<0) 52 | DW (10<<10)|(10<<5)|(10<<0), (0<<10)|(0<<5)|(0<<0) 53 | 54 | LoadTextPalette:: ; Load text palette into slot 7 55 | 56 | ld a,7 57 | ld hl,TEXT_PALETTE 58 | call bg_set_palette_safe 59 | 60 | ret 61 | 62 | LoadText:: ; b = 1 -> load at bank 8800h, b = 0 -> load at bank at 8000h 63 | 64 | xor a,a 65 | ldh [rVBK],a 66 | 67 | LD_DE_BC ; (*) 68 | 69 | ld b,BANK(TextTilesData) 70 | call rom_bank_push_set ; preserves de 71 | 72 | LD_BC_DE ; (*) 73 | 74 | bit 0,b 75 | jr nz,.bank_8800 76 | 77 | ld bc,TextTilesNumber 78 | ld de,TEXT_BASE_TILE ; Bank at 8000h 79 | ld hl,TextTilesData 80 | call vram_copy_tiles 81 | 82 | jr .end_load 83 | .bank_8800: 84 | 85 | ld bc,TextTilesNumber 86 | ld de,TEXT_BASE_TILE+256 ; Bank at 8800h 87 | ld hl,TextTilesData 88 | call vram_copy_tiles 89 | 90 | .end_load: 91 | 92 | call rom_bank_pop 93 | 94 | ret 95 | 96 | ;############################################################################### 97 | -------------------------------------------------------------------------------- /tools/compress/compile.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | gcc filediff.c -o filediff 4 | gcc rle.c -o rle 5 | gcc extractbit3.c -o extractbit3 6 | -------------------------------------------------------------------------------- /tools/compress/convert-all.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | ./convert.sh scenario_0_rock_river.bin \ 4 | scenario_0_rock_river_map.bin scenario_0_rock_river_attr.bin 5 | ./convert.sh scenario_1_boringtown.bin \ 6 | scenario_1_boringtown_map.bin scenario_1_boringtown_attr.bin 7 | ./convert.sh scenario_2_portville.bin \ 8 | scenario_2_portville_map.bin scenario_2_portville_attr.bin 9 | ./convert.sh scenario_3_newdale.bin \ 10 | scenario_3_newdale_map.bin scenario_3_newdale_attr.bin 11 | -------------------------------------------------------------------------------- /tools/compress/convert.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | head -c 4K $1 > $2 4 | tail -c 4K $1 > $3 5 | ./filediff $2 $2 6 | ./extractbit3 $3 $3 7 | ./filediff $3 $3 8 | ./rle -e $2 9 | ./rle -e $3 10 | -------------------------------------------------------------------------------- /tools/compress/extractbit3.c: -------------------------------------------------------------------------------- 1 | // MIT license: 2 | // 3 | // Copyright 2017 Antonio Nino Diaz (AntonioND/SkyLyrac) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include 24 | #include 25 | 26 | int file_load(const char * path, void ** buffer, size_t * size_) 27 | { 28 | size_t size; 29 | *buffer = NULL; 30 | 31 | FILE * f = fopen(path, "rb"); 32 | if(f == NULL) 33 | { 34 | printf("Couldn't be open: %s\n", path); 35 | return 1; 36 | } 37 | 38 | fseek(f, 0, SEEK_END); 39 | 40 | size = ftell(f); 41 | if(size_) *size_ = size; 42 | if(size == 0) 43 | { 44 | printf("Empty file: %s\n", path); 45 | fclose(f); 46 | return 1; 47 | } 48 | 49 | rewind(f); 50 | *buffer = calloc(size, 1); 51 | if(*buffer == NULL) 52 | { 53 | printf("Not enought memory to load: %s\n", path); 54 | fclose(f); 55 | return 1; 56 | } 57 | 58 | if(fread(*buffer, size, 1, f) != 1) 59 | { 60 | printf("Error while reading: %s\n", path); 61 | fclose(f); 62 | return 1; 63 | } 64 | 65 | fclose(f); 66 | 67 | return 0; 68 | } 69 | 70 | void extract(char * buffer, size_t size) 71 | { 72 | while (size--) 73 | { 74 | *buffer = *buffer & (1<<3); 75 | buffer++; 76 | } 77 | } 78 | 79 | int main(int argc, char * argv[]) 80 | { 81 | char * buffer; 82 | size_t size; 83 | 84 | // Load file 85 | 86 | if (file_load(argv[1], (void**)&buffer, &size)) 87 | return 1; 88 | 89 | // Compress 90 | 91 | extract(buffer, size); 92 | 93 | // Write result 94 | 95 | FILE * f = fopen(argv[2], "wb"); 96 | 97 | if (!f) 98 | { 99 | printf("Failed to open: %s\n", argv[2]); 100 | return 1; 101 | } 102 | 103 | if (fwrite(buffer, sizeof(char), size, f) != size) 104 | { 105 | printf("Failed to write: %s\n", argv[2]); 106 | fclose(f); 107 | return 1; 108 | } 109 | 110 | fclose(f); 111 | 112 | free(buffer); 113 | 114 | // End 115 | 116 | return 0; 117 | } 118 | 119 | -------------------------------------------------------------------------------- /tools/compress/filediff.c: -------------------------------------------------------------------------------- 1 | // MIT license: 2 | // 3 | // Copyright 2017 Antonio Nino Diaz (AntonioND/SkyLyrac) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include 24 | #include 25 | 26 | int file_load(const char * path, void ** buffer, size_t * size_) 27 | { 28 | size_t size; 29 | *buffer = NULL; 30 | 31 | FILE * f = fopen(path, "rb"); 32 | if(f == NULL) 33 | { 34 | printf("Couldn't be open: %s\n", path); 35 | return 1; 36 | } 37 | 38 | fseek(f, 0, SEEK_END); 39 | 40 | size = ftell(f); 41 | if(size_) *size_ = size; 42 | if(size == 0) 43 | { 44 | printf("Empty file: %s\n", path); 45 | fclose(f); 46 | return 1; 47 | } 48 | 49 | rewind(f); 50 | *buffer = calloc(size, 1); 51 | if(*buffer == NULL) 52 | { 53 | printf("Not enought memory to load: %s\n", path); 54 | fclose(f); 55 | return 1; 56 | } 57 | 58 | if(fread(*buffer, size, 1, f) != 1) 59 | { 60 | printf("Error while reading: %s\n", path); 61 | fclose(f); 62 | return 1; 63 | } 64 | 65 | fclose(f); 66 | 67 | return 0; 68 | } 69 | 70 | void diff(char * buffer, size_t size) 71 | { 72 | char c = 0; 73 | 74 | while (size--) 75 | { 76 | char r = *buffer - c; 77 | c = * buffer; 78 | *buffer = r; 79 | buffer++; 80 | } 81 | } 82 | 83 | int main(int argc, char * argv[]) 84 | { 85 | char * buffer; 86 | size_t size; 87 | 88 | // Load file 89 | 90 | if (file_load(argv[1], (void**)&buffer, &size)) 91 | return 1; 92 | 93 | // Compress 94 | 95 | diff(buffer, size); 96 | 97 | // Write result 98 | 99 | FILE * f = fopen(argv[2], "wb"); 100 | 101 | if (!f) 102 | { 103 | printf("Failed to open: %s\n", argv[2]); 104 | return 1; 105 | } 106 | 107 | if (fwrite(buffer, sizeof(char), size, f) != size) 108 | { 109 | printf("Failed to write: %s\n", argv[2]); 110 | fclose(f); 111 | return 1; 112 | } 113 | 114 | fclose(f); 115 | 116 | free(buffer); 117 | 118 | // End 119 | 120 | return 0; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /tools/gbmb-1.8/gbmb.cnt: -------------------------------------------------------------------------------- 1 | :Base GBMB.HLP 2 | :Title Gameboy Map Builder Help 3 | 1 Designing maps 4 | 2 Map properties=Map_properties 5 | 2 Using the mouse=Using_the_mouse 6 | 2 Draw types=Draw_types 7 | 2 GBMB versus GBTD=GBMB_versus_GBTD 8 | 2 Auto update=Auto_update 9 | 1 Design tools 10 | 2 Inserting and deleting rows and columns=InsDelRowCol 11 | 2 Clear map=Clear_map 12 | 2 Block fill=Block_fill 13 | 1 Using location properties 14 | 2 Introduction to location properties=Introduction_to_location_properties 15 | 2 Location properties=Location_properties 16 | 2 Default location properties=Default_location_properties 17 | 2 Info panel=Info_panel 18 | 2 Property colors=Property_colors 19 | 1 Viewing maps 20 | 2 Zoom=Zoom 21 | 2 Info panel=Info_panel 22 | 2 Grid=Grid 23 | 2 Double markers=Double_markers 24 | 2 Property colors=Property_colors 25 | 2 Bookmarks=Bookmarks 26 | 2 Color set=Color_set 27 | 1 Clipboard functions 28 | 2 Cutting and pasting=Cutting_and_Pasting 29 | 2 Clipboard format=Clipboard_format 30 | 2 Copy as bitmap=Copy_as_bitmap 31 | 1 Exporting 32 | 2 Export options=Export_options 33 | 2 'Export' vs 'Export to...'=_Export__vs__Export_to_ 34 | 2 Export file types 35 | 3 RGBDS Assembly file=RGBDS_Assembly_file 36 | 3 RGBDS Object file=RGBDS_Object_file 37 | 3 TASM Assembly file=TASM_Assembly_file 38 | 3 GBDK C file=GBDK_C_file 39 | 3 All-purpose binary file=All_purpose_binary_file 40 | 3 ISAS Assembly file=ISAS_Assembly_file 41 | 1 Miscellaneous 42 | 2 INI file=INI_file 43 | 2 Contacting me and others=Contacting_me_and_others 44 | -------------------------------------------------------------------------------- /tools/gbmb-1.8/gbmb.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbmb-1.8/gbmb.exe -------------------------------------------------------------------------------- /tools/gbmb-1.8/gbmb.gid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbmb-1.8/gbmb.gid -------------------------------------------------------------------------------- /tools/gbmb-1.8/gbmb.hlp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbmb-1.8/gbmb.hlp -------------------------------------------------------------------------------- /tools/gbtd-2.2/file_id.diz: -------------------------------------------------------------------------------- 1 | Gameboy Tile Designer 2 | Version 2.2 3 | 4 | Release date: 28-08-1999 5 | 6 | 7 | Copyright H. Mulder 1999 8 | 9 | http://www.casema.net/~hpmulder 10 | -------------------------------------------------------------------------------- /tools/gbtd-2.2/gbtd.cnt: -------------------------------------------------------------------------------- 1 | :Base GBTD.HLP 2 | :Title Gameboy Tile Designer Help 3 | 1 Designing tiles 4 | 2 Using the mouse=Using_the_mouse 5 | 2 Draw types=Draw_types 6 | 2 Colors=Colors 7 | 2 GBTD versus GBMB=GBTD_versus_GBMB 8 | 2 Auto update=Auto_update 9 | 1 Design tools 10 | 2 Scrolling tiles=Scrolling_tiles 11 | 2 Flipping tiles=Flipping_tiles 12 | 2 Rotating tiles=Rotating_tiles 13 | 2 Clear tiles=Clear_tiles 14 | 2 Flip colors=Flip_colors 15 | 1 Viewing tiles 16 | 2 Tile size=Tile_size 17 | 2 Tile count=Tile_count 18 | 2 Simple=Simple 19 | 2 Grid=Grid 20 | 2 Nibble markers=Nibble_markers 21 | 2 Color set=Color_set 22 | 2 Palettes=Palettes 23 | 2 Bookmarks=Bookmarks 24 | 1 Clipboard functions 25 | 2 Cutting and Pasting=Cutting_and_Pasting 26 | 2 Split Copy and Paste=Split_Copy_and_Paste 27 | 2 Split options=Split_options 28 | 1 Importing 29 | 2 Import options=Import_options 30 | 2 Import file types 31 | 3 GBE file=GBE_file 32 | 3 Binary 8x8 tiles=Binary_8x8_tiles 33 | 1 Exporting 34 | 2 Export options=Export_options 35 | 2 'Export' vs 'Export to...'=_Export__vs__Export_to_ 36 | 2 Compression=Compression 37 | 2 Export data formats=Export_data_formats 38 | 2 Export counter types=Export_counter_types 39 | 2 Metatiles=Metatiles 40 | 2 Export file types 41 | 3 RGBDS Assembly file=RGBDS_Assembly_file 42 | 3 RGBDS Object file=RGBDS_Object_file 43 | 3 TASM Assembly file=TASM_Assembly_file 44 | 3 GBDK C file=GBDK_C_file 45 | 3 All-purpose binary file=All_purpose_binary_file 46 | 3 ISAS Assembly file=ISAS_Assembly_file 47 | 1 Miscellaneous 48 | 2 INI file=INI_file 49 | 2 Contacting me and others=Contacting_me_and_others 50 | -------------------------------------------------------------------------------- /tools/gbtd-2.2/gbtd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbtd-2.2/gbtd.exe -------------------------------------------------------------------------------- /tools/gbtd-2.2/gbtd.gid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbtd-2.2/gbtd.gid -------------------------------------------------------------------------------- /tools/gbtd-2.2/gbtd.hlp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AntonioND/ucity/83e5c697cbd9e10a0bc72b02bcb6146c35e2c328/tools/gbtd-2.2/gbtd.hlp -------------------------------------------------------------------------------- /tools/lut_gens/gen_bin2bcd.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // Output two bytes with the BCD value of a byte 6 | int main(int argc, char * argv[]) 7 | { 8 | FILE * f = fopen("bin2bcd.txt", "wt"); 9 | 10 | if (!f) 11 | return 1; 12 | 13 | int i, j; 14 | 15 | for (j = 0; j < 32; j++) 16 | { 17 | fprintf(f," DB "); 18 | 19 | for (i = 0; i < 8; i++) 20 | { 21 | int val = i + j * 8; 22 | 23 | fprintf(f, "$%02X,$%02X", 24 | (val%10) | (((val/10)%10)<<4), 25 | ((val/100)%10) ); 26 | 27 | if (i != (8-1)) 28 | fprintf(f, ", "); 29 | } 30 | 31 | fprintf(f, "\n"); 32 | } 33 | 34 | fclose(f); 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tools/lut_gens/gen_bit_count.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // Number of bits set to 1 in a byte 6 | int main(int argc, char * argv[]) 7 | { 8 | FILE * f = fopen("bit_count.txt", "wt"); 9 | 10 | if (!f) 11 | return 1; 12 | 13 | int i, j; 14 | 15 | for (j = 0; j < 2; j++) 16 | { 17 | fprintf(f, " DB "); 18 | 19 | for (i = 0; i < 16; i++) 20 | { 21 | int val = i + j * 16; 22 | int count = 0; 23 | int k; 24 | for (k = 0; k < 8; k++) 25 | count += (val >> k) & 1; 26 | 27 | fprintf(f, "%d", count); 28 | 29 | if (i != (16-1)) 30 | fprintf(f, ", "); 31 | } 32 | 33 | fprintf(f, "\n"); 34 | } 35 | 36 | fclose(f); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tools/lut_gens/gen_build_prob.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // gcc gen_build_prob.c -lm 6 | 7 | // Generate array of probabilites to create/demolish buildings 8 | int main(int argc, char * argv[]) 9 | { 10 | FILE * f = fopen("probability.txt", "wt"); 11 | 12 | if (!f) 13 | return 1; 14 | 15 | int i; 16 | 17 | fprintf(f, "; Create\n"); 18 | fprintf(f, " DB "); 19 | 20 | for (i = 0; i < 21; i++) // 0% to 20% of taxes 21 | { 22 | int val = 255 - pow(i / 2, 1.75); 23 | 24 | if (val > 255) 25 | val = 255; 26 | else if (val < 0) 27 | val = 0; 28 | 29 | fprintf(f, "$%02X", val); 30 | 31 | if ( (i == 0) || (i == 10)) 32 | fprintf(f, "\n DB "); 33 | else if (i != 20) 34 | fprintf(f, ","); 35 | } 36 | 37 | fprintf(f, "\n"); 38 | fprintf(f, "\n"); 39 | 40 | fprintf(f, "; Demolish\n"); 41 | fprintf(f, " DB "); 42 | 43 | for (i = 0; i < 21; i++) // 0% to 20% of taxes 44 | { 45 | int val = 4 + pow(i / 2, 1.75); 46 | 47 | if (val > 255) 48 | val = 255; 49 | else if (val < 0) 50 | val = 0; 51 | 52 | fprintf(f, "$%02X", val); 53 | 54 | if ( (i == 0) || (i == 10)) 55 | fprintf(f, "\n DB "); 56 | else if (i != 20) 57 | fprintf(f, ","); 58 | } 59 | 60 | fprintf(f, "\n"); 61 | fclose(f); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /tools/lut_gens/gen_circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // gcc gen_circle.c -lm 5 | 6 | int circle(int s, int x, int y) 7 | { 8 | return ((s-1)*(s-1) > (x*x + y*y)) ? 1 : 0; 9 | } 10 | 11 | // Generate a LUT with the shape of a circle 12 | int main(int argc, char * argv[]) 13 | { 14 | FILE * f = fopen("circle.txt", "wt"); 15 | 16 | if (!f) 17 | return 1; 18 | 19 | int r = 64; 20 | 21 | for (r = 64; r > 2; r >>= 1) 22 | { 23 | int i, j, b; 24 | 25 | for (j = 0; j < r; j++) 26 | { 27 | fprintf(f, " DB "); 28 | 29 | for (i = 0; i < r; i++) 30 | { 31 | unsigned char block = 0; 32 | 33 | int val = circle(r, i, j); 34 | 35 | fprintf(f, "$%02X", val); 36 | 37 | if (i == (r-1)) 38 | fprintf(f, "\n"); 39 | else if ((i & 15) == 15) 40 | fprintf(f, "\n DB "); 41 | else 42 | fprintf(f, ","); 43 | } 44 | } 45 | 46 | fprintf(f, "\n"); 47 | } 48 | 49 | fclose(f); 50 | 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tools/lut_gens/gen_mask.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // gcc gen_mask.c -lm 6 | 7 | inline int min(int a, int b) 8 | { 9 | return a < b ? a : b; 10 | } 11 | 12 | // Generate masks used for simulation of services such as police or schools. 13 | int main(int argc, char * argv[]) 14 | { 15 | float radius = 16.0; 16 | int size = 32; 17 | 18 | FILE * f = fopen("small.txt","wt"); 19 | 20 | if (!f) 21 | return 1; 22 | 23 | int i, j; 24 | 25 | for (j = 0; j < size; j++) 26 | { 27 | fprintf(f, " DB "); 28 | 29 | for (i = 0; i < size; i++) 30 | { 31 | int x = size / 2 - i; 32 | int y = size / 2 - j; 33 | int val = ( (radius - pow(x*x+y*y,1.0/2.0)) * (256.0+128.0) ) / 34 | radius; 35 | 36 | if (val > 255) 37 | val = 255; 38 | else if (val < 0) 39 | val = 0; 40 | 41 | fprintf(f, "$%02X", val); 42 | 43 | if ( (i != (size-1)) && ((i&15) == 15) ) 44 | fprintf(f, "\n DB "); 45 | else if (i != (size-1)) 46 | fprintf(f, ","); 47 | } 48 | 49 | fprintf(f, "\n"); 50 | } 51 | 52 | fclose(f); 53 | 54 | // ----------------------------------- 55 | 56 | radius = 32.0; 57 | size = 64; 58 | 59 | f = fopen("big.txt","wt"); 60 | if (!f) 61 | return 1; 62 | 63 | for (j = 0; j < size; j++) 64 | { 65 | fprintf(f, " DB "); 66 | 67 | for (i = 0; i < size; i++) 68 | { 69 | int x = size / 2 - i; 70 | int y = size / 2 - j; 71 | int val = ( (radius - pow(x*x+y*y,1.0/2.0)) * (256.0+128.0)) / 72 | radius; 73 | 74 | if (val > 255) 75 | val = 255; 76 | else if (val < 0) 77 | val = 0; 78 | 79 | fprintf(f, "$%02X", val); 80 | 81 | if ( (i != (size-1)) && ((i&15) == 15) ) 82 | fprintf(f, "\n DB "); 83 | else if (i != (size-1)) 84 | fprintf(f, ","); 85 | } 86 | 87 | fprintf(f, "\n"); 88 | } 89 | 90 | fclose(f); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /tools/lut_gens/gen_shift_table.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | // Generate LUT with all possible results for 8 bit values shifted left by 5 | // 2 to 6. 6 | int main(int argc, char * argv[]) 7 | { 8 | FILE * f = fopen("shift.txt", "wt"); 9 | 10 | if (!f) 11 | return 1; 12 | 13 | int r; 14 | 15 | for (r = 6; r >= 2; r--) 16 | { 17 | int i, j; 18 | 19 | for (j = 0; j < 8; j++) 20 | { 21 | fprintf(f, " DB "); 22 | 23 | for (i = 0; i < 8; i++) 24 | { 25 | unsigned char val = i + 8 * j; 26 | fprintf(f, "$%02X,$%02X", (val<>8); 27 | if (i < 7) 28 | fprintf(f, ","); 29 | } 30 | 31 | fprintf(f, "\n"); 32 | } 33 | 34 | fprintf(f, "\n"); 35 | } 36 | 37 | fclose(f); 38 | 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /tools/mod2gbt/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -o mod2gbt mod2gbt.c 3 | 4 | -------------------------------------------------------------------------------- /tools/mod2gbt/mod_instructions.txt: -------------------------------------------------------------------------------- 1 | FREQUENCIES 2 | ----------- 3 | 4 | You can use notes from C3 to B8. 5 | 6 | INSTRUMENTS 7 | ----------- 8 | 9 | +----------------------------------------------------------------+ 10 | |CHANNEL|RANGE| NOTES | 11 | +-------+-----+--------------------------------------------------+ 12 | | 1 | 1-4 | | 13 | | 2 | 1-4 | | 14 | | 3 | 8-15|Volume is usually a bit lower than other channels.| 15 | | 4 |16-31|Doesn't change with frequency (always C5). | 16 | +-------+-----+--------------------------------------------------+ 17 | 18 | EFFECTS 19 | ------- 20 | 21 | 0xy - Arpeggio. Only channels 1, 2 and 3. 22 | 23 | Bnn - Jump to pattern in order nn (in hexadecimal). 24 | 25 | Cnn - Sets the volume to nn (in hexadecimal). Valid values from 00h to 40h. 26 | Channel 3 can only be set to 0%, 25%, 50% and 100%. Others can be set 27 | in a range of 0-Fh. 28 | 29 | Dnn - Ends this pattern and jumps to position nn (in decimal) in next pattern. 30 | If used the last step of a pattern it will jump two patterns, not one! 31 | 32 | E8n - Sets the panning to n (in hexadecimal). 33 | Left --- Both --- Right 34 | 0123 456789AB CDEF 35 | 36 | ECn - Cut Note after n ticks. If n > speed or n = 0, it won't work. 37 | 38 | Fnn - Sets speed to nn (in hexadecimal). Valid values are 01h to 1Fh. 39 | The higher the value, the slower the song. BPM speed not supported. 40 | 41 | Effects are limited in channel 3 when setting a new note (only half of them 42 | are available). It shouldn't be a problem since the effects that can't be 43 | used are control commands that can be used by other channels. 44 | 45 | ********************************************************************** 46 | * You should set volume and instrument whenever you put a new note!! * 47 | * You should set instrument whenever you change volume in CH3!! * 48 | * You should always put an instrument whenever you use arpeggio!! * 49 | ********************************************************************** 50 | --------------------------------------------------------------------------------