├── Classic Kong Complete (U).smc ├── LICENSE ├── Makefile ├── clean.bat ├── compile_all.bat ├── compile_c.bat ├── compile_sound.bat ├── cutscenes.h ├── data.asm ├── data.h ├── enemy.h ├── game.c ├── game_levels.h ├── game_loop.h ├── game_over.h ├── gfx ├── back1.bmp ├── back1.chr ├── back1.pal ├── back2.pal ├── back3.pal ├── bubblezaplogo.bmp ├── bubblezaplogo.chr ├── bubblezaplogo.pal ├── font.bmp ├── font.chr ├── font.pal ├── sprites1.bmp ├── sprites1.chr ├── sprites1.pal ├── sprites2.bmp ├── sprites2.chr ├── sprites2.pal ├── sprites3.bmp ├── sprites3.chr ├── sprites3.pal ├── sprites4.bmp ├── sprites4.chr ├── sprites4.pal ├── sprites5.bmp ├── sprites5.chr ├── sprites5.pal ├── sprites5alt.bmp ├── sprites5alt.pal ├── sprites6.bmp ├── sprites6.chr ├── sprites6.pal ├── tileset1.bmp ├── tileset1.chr ├── tileset1.pal ├── tileset1alt1.bmp ├── tileset1alt1.pal ├── tileset1alt2.bmp ├── tileset1alt2.pal ├── tileset2.bmp ├── tileset2.chr ├── tileset2.pal ├── tileset2alt.bmp ├── tileset2alt.chr ├── tileset2alt.pal ├── title_bottom.bmp ├── title_bottom.chr ├── title_bottom.pal ├── title_top.bmp ├── title_top.chr └── title_top.pal ├── hdr.asm ├── libs ├── Makefile ├── compile.bat ├── crt0_snes.asm ├── hdr.asm ├── libc.asm ├── libm.asm └── libtcc.asm ├── make_resources.bat ├── misc ├── back.xcf └── kong.svg ├── nametables ├── map1.rle ├── map2.rle ├── map3.rle ├── map4.rle ├── mape.rle └── mapi.rle ├── particles.h ├── sneslib.h ├── sound ├── music_game_start.bin ├── music_game_start.xm ├── music_hammer.bin ├── music_hammer.xm ├── music_level1.bin ├── music_level1.xm ├── music_lose.bin ├── music_lose.xm ├── music_stage_clear.bin ├── music_stage_clear.xm ├── music_stage_start.bin ├── music_stage_start.xm ├── music_time_out.bin ├── music_time_out.xm ├── music_title.bin ├── music_title.xm ├── music_victory.bin ├── music_victory.xm ├── sample0.brr ├── sample1.brr ├── sample16.brr ├── sample17.brr ├── sample18.brr ├── sample19.brr ├── sample2.brr ├── sample20.brr ├── sample21.brr ├── sample22.brr ├── sample23.brr ├── sample24.brr ├── sample25.brr ├── sample26.brr ├── sample27.brr ├── sample3.brr ├── sample4.brr ├── sample5.brr ├── sample6.brr ├── sample7.brr ├── samples.asm ├── sounds.bin └── sounds.xm ├── sound_test.h ├── spc700.asm ├── spc700.bin ├── spccmd.h ├── title_screen.h ├── tools ├── bass.exe ├── bin2h.exe ├── optimore-816.exe ├── pre.exe ├── snesbmp.exe └── xm2data.exe └── vram_map.txt /Classic Kong Complete (U).smc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/Classic Kong Complete (U).smc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Bubble Zap Games 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | Apache License 16 | 17 | Version 2.0, January 2004 18 | 19 | http://www.apache.org/licenses/ 20 | 21 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 22 | 23 | 1. Definitions. 24 | 25 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 26 | 27 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 28 | 29 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 30 | 31 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 32 | 33 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 34 | 35 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 38 | 39 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 40 | 41 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 42 | 43 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 44 | 45 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 46 | 47 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 48 | 49 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 50 | 51 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 52 | 53 | You must cause any modified files to carry prominent notices stating that You changed the files; and 54 | 55 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 56 | 57 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 58 | 59 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 60 | 61 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 62 | 63 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 64 | 65 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 66 | 67 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 68 | 69 | END OF TERMS AND CONDITIONS 70 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX=/usr/local/snes-sdk 2 | OPTIMIZE=1 3 | 4 | CFLAGS=-Wall 5 | ifeq ($(OPTIMIZE),1) 6 | CFLAGS += -O 7 | endif 8 | 9 | BINDIR=$(PREFIX)/bin 10 | AS=$(BINDIR)/wla-65816 11 | LD=$(BINDIR)/wlalink 12 | CC=$(BINDIR)/816-tcc 13 | LIBDIR=$(PREFIX)/lib 14 | ROM=game 15 | 16 | COBJ=game.obj 17 | 18 | all: $(ROM).smc 19 | echo "Done" 20 | 21 | $(ROM).smc: $(COBJ) 22 | $(LD) -dvSo $(COBJ) $(ROM).smc 23 | 24 | %.s: %.c 25 | $(CC) $(CFLAGS) -I. -o $@ -c $< 26 | 27 | %.obj: %.s 28 | $(AS) -io $< $@ 29 | 30 | clean: 31 | rm -f $(ROM).smc $(ROM).sym $(COBJ) *.s 32 | -------------------------------------------------------------------------------- /clean.bat: -------------------------------------------------------------------------------- 1 | del gfx\*.chr 2 | del gfx\*.pal 3 | del sound\*.bin 4 | del spc700.bin 5 | del *.ps1 6 | del *.s 7 | del *.obj 8 | del *.sym 9 | del stderr.txt 10 | del stdout.txt 11 | del game.smc -------------------------------------------------------------------------------- /compile_all.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem compile everything 4 | 5 | call make_resources.bat 6 | call compile_sound.bat 7 | call compile_c.bat 8 | -------------------------------------------------------------------------------- /compile_c.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set relname="Classic Kong Complete (U).smc" 4 | 5 | rem convert C code only, without recompiling resources 6 | 7 | REM C -> ASM / S 8 | ..\bin\816-tcc.exe -Wall -I../include -o game.ps1 -c game.c 9 | rem pause 10 | 11 | REM Optimize ASM files 12 | ..\bin\816-opt.py game.ps1 > game.s 13 | rem ..\pypy-1.9\pypy.exe ..\bin\816-opt.py game.ps1 > game.s 14 | 15 | rem tools\optimore-816.exe game.ps2 game.s 16 | 17 | REM ASM -> OBJ 18 | ..\bin\wla-65816.exe -io game.s game.obj 19 | 20 | REM OBJ -> SMC 21 | ..\bin\wlalink.exe -dvSo game.obj %relname% 22 | 23 | pause 24 | 25 | REM delete files 26 | del *.ps1 27 | del *.s 28 | del *.obj 29 | del *.sym 30 | del stderr.txt 31 | del stdout.txt 32 | 33 | ..\zsnesw151\zsnesw.exe %relname% 34 | rem %relname% -------------------------------------------------------------------------------- /compile_sound.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem compile spc700 code, also includes sample and effects data 4 | 5 | path=path;tools\ 6 | del spc700.bin 7 | pre spc700.asm 8 | bass -arch=table -o spc700.bin spc700.s 9 | rem pause 10 | del spc700.s -------------------------------------------------------------------------------- /cutscenes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Bubble Zap Games 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | //set kong floor hitting animation frame 18 | //used in the levels clear cutscene 19 | 20 | void kong_stand_animation_both(void) 21 | { 22 | kong_frame=kongAnimationBoth[kong_frame_cnt>>2]; 23 | 24 | ++kong_frame_cnt; 25 | 26 | if(kong_frame_cnt>=6<<2) 27 | { 28 | sfx_play(SFX_CHN+1,SFX_KONG_RIGHT,kong_x+16); 29 | kong_frame_cnt=0; 30 | } 31 | } 32 | 33 | 34 | 35 | //show levels clear cutscene 36 | 37 | void cutscene_levels_clear(void) 38 | { 39 | static unsigned int ptr,frame,spr; 40 | static unsigned char i,j,x,bright,fall_start,fall_ground,princess_frame,bounce_cnt,shake_cnt; 41 | static unsigned char platform_y[4]; 42 | static unsigned char platform_hit[4]; 43 | static int ky,kdy; 44 | 45 | game_flip=0; 46 | 47 | set_bright(0); 48 | setup_hdma_gradient(-1); 49 | oam_clear(); 50 | 51 | setup_ingame_graphics(); 52 | clear_nametables(); 53 | 54 | unrle(map,mape); 55 | 56 | for(ptr=0;ptr<32*32;++ptr) nametable1[ptr]=map[ptr]+0x0140|BG_PAL(1)|BG_PRI; 57 | 58 | set_background(1); 59 | update_nametables(); 60 | setup_palettes(); 61 | update_palette(); 62 | 63 | bright=0; 64 | 65 | platform_y[0]=55; 66 | platform_y[1]=55+40; 67 | platform_y[2]=55+80; 68 | platform_y[3]=55+120; 69 | 70 | for(i=0;i<4;++i) platform_hit[i]=0; 71 | 72 | ky=23<<6; 73 | kdy=0; 74 | 75 | kong_x=112; 76 | kong_frame_cnt=0; 77 | 78 | princess_x=48; 79 | princess_y=27; 80 | princess_frame=0; 81 | 82 | player_x=192; 83 | player_y=39; 84 | 85 | particles_clear(); 86 | kong_stand_animation_both(); 87 | 88 | setup_hdma_gradient(6); 89 | 90 | for(i=0;i<128;++i) oam_size(i<<2,1);//set all sprites to 16x16 size 91 | 92 | spc_volume(global_volume);//unmute sound after previous fade out 93 | 94 | ptr=0xf7; 95 | fall_start=FALSE; 96 | fall_ground=FALSE; 97 | bounce_cnt=0; 98 | shake_cnt=0; 99 | 100 | for(frame=0;frame<14*60;++frame) 101 | { 102 | nmi_wait(); 103 | copy_to_vram(POS(8,7),(unsigned char*)&nametable1[POS(8,7)],16*2);//update the bridge area of the nametable 104 | 105 | /*shake screen when kong hits the ground*/ 106 | 107 | if(shake_cnt) 108 | { 109 | --shake_cnt; 110 | 111 | if(shake_cnt&2) 112 | { 113 | set_scroll(0,-1,-1); 114 | set_scroll(1,-2,-2); 115 | } 116 | else 117 | { 118 | set_scroll(0, 1, 1); 119 | set_scroll(1, 0, 0); 120 | } 121 | } 122 | else 123 | { 124 | set_scroll(0, 0, 0); 125 | set_scroll(1,-1,-1); 126 | } 127 | 128 | if(bright<15) 129 | { 130 | ++bright; 131 | set_bright(bright); 132 | } 133 | 134 | if(frame<6*4*6) 135 | { 136 | /*kong is just stands hitting the floor for few first frames*/ 137 | 138 | kong_stand_animation_both(); 139 | } 140 | else 141 | { 142 | /*then platforms and kong falling sequence starts*/ 143 | 144 | if(platform_y[0]>=200) 145 | { 146 | if(bounce_cnt<5) 147 | { 148 | if(!fall_start) 149 | { 150 | fall_start=TRUE; 151 | 152 | sfx_play(SFX_CHN+2,SFX_KONG_FALLS,128); 153 | } 154 | 155 | ky+=kdy; 156 | 157 | if(kdy<(2<<6)) kdy+=6; 158 | 159 | if(ky>=(182<<6)) 160 | { 161 | ky=182<<6; 162 | 163 | kdy=0-((kdy<<6)/96); 164 | ++bounce_cnt; 165 | 166 | if(!fall_ground) 167 | { 168 | fall_ground=TRUE; 169 | kong_frame=kongLargeSpriteFell; 170 | 171 | sfx_play(SFX_CHN+2,SFX_KONG_LANDS,128); 172 | 173 | shake_cnt=25; 174 | } 175 | } 176 | 177 | if(!fall_ground) kong_frame=(kong_y&16)?kongLargeSpriteFalling1:kongLargeSpriteFalling2; 178 | } 179 | } 180 | else 181 | { 182 | platform_y[0]+=2; 183 | } 184 | 185 | //move platforms down 186 | 187 | for(i=0;i<4;++i) 188 | { 189 | if(platform_y[i]<200)//if it didn't hit the floor yet 190 | { 191 | if(i&&platform_y[i]>6; 216 | 217 | game_show_kong(OAM_KONG,kong_x,kong_y); 218 | game_show_princess(princess_frame); 219 | 220 | oam_spr1(player_x,player_y,playerWalkAnimLeft[(player_x>>1)&3],OAM_PLAYER); 221 | 222 | spr=64<<2; 223 | 224 | for(i=0;i<4;++i) 225 | { 226 | x=72; 227 | 228 | for(j=0;j<7;++j) 229 | { 230 | oam_spr1(x,platform_y[i],PLAYER_TILE+0x4e|PLAYER_ATR,spr); 231 | x+=16; 232 | spr+=4; 233 | } 234 | } 235 | 236 | particle_process(); 237 | 238 | /*when kong is on the ground, start victory music*/ 239 | 240 | if(frame==350) music_play(MUS_VICTORY); 241 | 242 | /*put the bridge into the nametable piece by piece*/ 243 | 244 | if(frame>420&&!(frame&3)) 245 | { 246 | if(ptr>0xe7) 247 | { 248 | nametable1[ptr--]=0x0145|BG_PAL(1)|BG_PRI; 249 | } 250 | } 251 | 252 | princess_frame=game_frame_cnt&32?2:0; 253 | 254 | /*when the bridge is fully appeared, mario and princess start slowly walking to each other*/ 255 | 256 | if(frame>400+80) 257 | { 258 | i=frame%3; 259 | 260 | if(princess_x<(128-16-16)) 261 | { 262 | if(!i) ++princess_x; 263 | 264 | princess_frame=game_frame_cnt&8?1:0; 265 | } 266 | 267 | if(!i) 268 | { 269 | if(player_x>(128+16)) --player_x; 270 | } 271 | } 272 | 273 | /*when they come closer, a heart appears*/ 274 | 275 | if(frame==670) 276 | { 277 | particle_add(PART_TYPE_HEART,120,32); 278 | sfx_play(SFX_CHN+3,SFX_LOVE,128); 279 | } 280 | 281 | /*after a pause they start to move again, now faster*/ 282 | 283 | if(frame>14*60-30) 284 | { 285 | if(frame&1) 286 | { 287 | ++princess_x; 288 | --player_x; 289 | } 290 | 291 | princess_frame=game_frame_cnt&8?1:0; 292 | } 293 | 294 | ++game_frame_cnt; 295 | } 296 | 297 | fade_screen(FALSE,TRUE); 298 | } 299 | 300 | 301 | 302 | //show the 'how high you can get' cutscene 303 | 304 | void cutscene_level(void) 305 | { 306 | static unsigned char i,bright,delay; 307 | static unsigned int frame,ptr; 308 | const char* const heightStr[]={" 25 M $"," 50 M $"," 75 M $","100 M $"}; 309 | static int stack_y[4],stack_ty[4],stack_dy[4]; 310 | static unsigned char stack_frame[4],stack_jump[4],stack_delay[4]; 311 | static int y; 312 | 313 | set_bright(0); 314 | setup_hdma_gradient(-1); 315 | oam_clear(); 316 | 317 | BG12NBA(0x00); //patterns for layers 1 and 2 at $0000 318 | 319 | setup_ingame_graphics(); 320 | clear_nametables(); 321 | set_background(-1); 322 | 323 | for(ptr=0;ptr<32*32;++ptr) nametable2[ptr]=0x158|BG_PAL(1); 324 | 325 | for(i=0;i=stack_ty[i]) 381 | { 382 | stack_y [i]=stack_ty[i]; 383 | stack_dy[i]=0-((stack_dy[i]<<6)/160); 384 | 385 | ++stack_jump[i]; 386 | } 387 | } 388 | 389 | if(stack_jump[i]) 390 | { 391 | if(game_frame_cnt&1) 392 | { 393 | if(stack_frame[i]<3) ++stack_frame[i]; 394 | } 395 | } 396 | 397 | kong_frame=kongAnimationStartCutscene[stack_frame[i]]; 398 | 399 | game_show_kong(i<<4,128-16,stack_y[i]>>6); 400 | } 401 | 402 | if(delay) 403 | { 404 | --delay; 405 | 406 | if(!delay) music_play(MUS_STAGE_START); 407 | } 408 | 409 | ++game_frame_cnt; 410 | } 411 | 412 | fade_screen(FALSE,TRUE); 413 | 414 | BG12NBA(0x40); //patterns for layers 1 at $0000, 2 at $4000 415 | } 416 | 417 | 418 | 419 | /* update bending platform for the intro cutscene */ 420 | 421 | void cutscene_update_platform(unsigned int off,unsigned int ptr,unsigned char wdt,char dx) 422 | { 423 | static unsigned char i,j,cnt,hgt; 424 | 425 | off<<=5; 426 | cnt=0; 427 | hgt=1; 428 | 429 | for(i=0;i=240) continue; 468 | 469 | oam_spr1(ladders_x[i],ladders_y[i],ENEMY_TILE+0x0e|ENEMY_ATR,(127-i)<<2); 470 | 471 | if(ladders_delay[i]) 472 | { 473 | --ladders_delay[i]; 474 | continue; 475 | } 476 | 477 | ladders_y[i]+=2; 478 | } 479 | } 480 | 481 | 482 | 483 | //update princess coordinates according to the kong coordinates for the intro cutscene 484 | 485 | unsigned char cutscene_intro_princess_hold(unsigned char off,unsigned char hold,unsigned char shift) 486 | { 487 | static unsigned char princess_frame; 488 | 489 | if(hold) 490 | { 491 | princess_x=kong_x+off; 492 | princess_y=kong_y-(game_frame_cnt&8?0:1); 493 | princess_frame=0; 494 | } 495 | else 496 | { 497 | if(shift&&!(game_frame_cnt&3)&&princess_y>3) --princess_y; 498 | princess_frame=game_frame_cnt&32?2:0; 499 | } 500 | 501 | return princess_frame; 502 | } 503 | 504 | 505 | 506 | /* show the intro cutscene */ 507 | 508 | void cutscene_intro(void) 509 | { 510 | static unsigned char i,j,y,bright,hold,jump_cnt,princess_frame; 511 | static unsigned int frame,ptr; 512 | static int ky,kdy; 513 | const int xp_off=20; 514 | 515 | game_flip=0; 516 | 517 | set_bright(0); 518 | setup_hdma_gradient(-1); 519 | oam_clear(); 520 | 521 | setup_ingame_graphics(); 522 | clear_nametables(); 523 | set_background(-1); 524 | 525 | unrle(map,mapi); 526 | 527 | for(ptr=0;ptr<32*32;++ptr) nametable1[ptr]=map[ptr]+0x0140|BG_PAL(1); 528 | 529 | update_nametables(); 530 | setup_palettes(); 531 | update_palette(); 532 | 533 | for(i=0;i<128;++i) oam_size(i<<2,1); 534 | 535 | for(i=0;i<6*32;++i) platformAnimCnt[i]=0; 536 | 537 | music_play(MUS_GAME_START); 538 | 539 | y=224-8; 540 | 541 | for(i=0;i40) 562 | { 563 | nmi_wait(); 564 | 565 | if(bright<15) 566 | { 567 | ++bright; 568 | set_bright(bright); 569 | } 570 | 571 | kong_frame=game_frame_cnt&8?kongLargeSpriteClimb1R:kongLargeSpriteClimb2R; 572 | 573 | --kong_y; 574 | 575 | princess_frame=cutscene_intro_princess_hold(xp_off,TRUE,TRUE); 576 | 577 | game_show_kong(OAM_KONG,kong_x,kong_y); 578 | game_show_princess(princess_frame); 579 | 580 | cutscene_intro_show_ladders(); 581 | 582 | ++game_frame_cnt; 583 | } 584 | 585 | /* kong jumps onto the floor and releases the princess */ 586 | 587 | ky=kong_y<<6; 588 | kdy=-1<<6; 589 | hold=TRUE; 590 | 591 | while(1) 592 | { 593 | nmi_wait(); 594 | 595 | ky+=kdy; 596 | ++kdy; 597 | 598 | if(kdy>0) ++kdy; 599 | 600 | kong_y=ky>>6; 601 | 602 | if(kong_y<10) hold=FALSE; 603 | 604 | princess_frame=cutscene_intro_princess_hold(xp_off,hold,TRUE); 605 | 606 | game_show_kong(OAM_KONG,kong_x,kong_y); 607 | game_show_princess(princess_frame); 608 | cutscene_intro_show_ladders(); 609 | 610 | ++game_frame_cnt; 611 | 612 | if(kdy>0&&kong_y>=25) 613 | { 614 | kong_y=25; 615 | break; 616 | } 617 | } 618 | 619 | /* kong jumps to the position, platforms are bending every jump */ 620 | 621 | kong_frame=kongLargeSpriteFace4Both; 622 | kdy=-1<<6; 623 | jump_cnt=0; 624 | frame=0; 625 | 626 | while(1) 627 | { 628 | nmi_wait(); 629 | copy_to_vram(0x0000,(unsigned char*)nametable1,32*32*2); 630 | 631 | if(bright<15) 632 | { 633 | ++bright; 634 | set_bright(bright); 635 | } 636 | 637 | if(game_frame_cnt&1) 638 | { 639 | if(jump_cnt==6) cutscene_update_platform(0,POS(27,25),27,-1); 640 | if(jump_cnt==5) cutscene_update_platform(1,POS( 4,21),24, 1); 641 | if(jump_cnt==4) cutscene_update_platform(2,POS(27,18),24,-1); 642 | if(jump_cnt==3) cutscene_update_platform(3,POS( 4,14),24, 1); 643 | if(jump_cnt==2) cutscene_update_platform(4,POS(27,10),24,-1); 644 | if(jump_cnt==1) cutscene_update_platform(5,POS(19, 7), 9, 1); 645 | } 646 | 647 | cutscene_intro_show_ladders(); 648 | 649 | if(jump_cnt<6) 650 | { 651 | kong_y=ky>>6; 652 | 653 | if(kong_y>=24) kong_y=24; 654 | 655 | ky+=kdy; 656 | kdy+=4; 657 | 658 | if(!(game_frame_cnt&1)) --kong_x; 659 | 660 | if(ky>=(24<<6)) 661 | { 662 | ky=24<<6; 663 | kdy=-1<<6; 664 | ++jump_cnt; 665 | 666 | sfx_play(SFX_CHN+1,SFX_KONG_RIGHT,kong_x+16); 667 | } 668 | } 669 | 670 | princess_frame=game_frame_cnt&32?2:0; 671 | 672 | game_show_kong(OAM_KONG,kong_x,kong_y); 673 | game_show_princess(princess_frame); 674 | 675 | ++game_frame_cnt; 676 | 677 | if(jump_cnt>=6) 678 | { 679 | j=frame>>2; 680 | if(j>3) j=3; 681 | 682 | kong_frame=kongAnimationBoth[3-j]; 683 | 684 | ++frame; 685 | 686 | if(frame>=48) break; 687 | } 688 | } 689 | 690 | /* kong laugh */ 691 | 692 | for(i=0;i<5*16;++i) 693 | { 694 | nmi_wait(); 695 | 696 | if((i&15)==0) 697 | { 698 | sfx_play(SFX_CHN+1,SFX_KONG_LAUGH,kong_x+16); 699 | kong_frame=kongLargeSpriteLaugh; 700 | } 701 | 702 | if((i&15)==8) 703 | { 704 | kong_frame=kongLargeSpriteFace1; 705 | } 706 | 707 | princess_frame=game_frame_cnt&32?2:0; 708 | 709 | game_show_kong(OAM_KONG,kong_x,kong_y); 710 | game_show_princess(princess_frame); 711 | 712 | ++game_frame_cnt; 713 | } 714 | 715 | delay(25); 716 | 717 | fade_screen(FALSE,TRUE); 718 | } 719 | 720 | 721 | /* show the level clear cutscene */ 722 | 723 | void cutscene_next_level(void) 724 | { 725 | static unsigned char i,t1,t2,princess_frame,hold,side; 726 | static int ky,kdy,kong_tx,kong_oy,x_off,xp_off; 727 | static unsigned char heart_x,heart_y; 728 | 729 | /* move kong to the center in the second level */ 730 | 731 | if(game_level==1) 732 | { 733 | if(!game_flip) 734 | { 735 | t1=8; 736 | t2=4; 737 | } 738 | else 739 | { 740 | t1=4; 741 | t2=8; 742 | } 743 | 744 | if(kong_x<112) 745 | { 746 | for(i=0;i<26;++i) nametable1[POS(3,7)+i]=(nametable1[POS(3,7)+i]&~0xc)|t1; 747 | } 748 | else 749 | { 750 | for(i=0;i<26;++i) nametable1[POS(3,7)+i]=(nametable1[POS(3,7)+i]&~0xc)|t2; 751 | } 752 | 753 | while(kong_x!=112) 754 | { 755 | game_wait_and_update_nametables(); 756 | game_update_vram_animation(); 757 | 758 | if(game_frame_cnt&1) 759 | { 760 | if(kong_x<112) ++kong_x; else --kong_x; 761 | } 762 | 763 | game_show_kong(OAM_KONG,kong_x,kong_y); 764 | 765 | ++game_frame_cnt; 766 | } 767 | } 768 | 769 | /* heart appears */ 770 | 771 | sfx_play(SFX_CHN,SFX_HEART,heart_x); 772 | 773 | heart_x=princess_x>1),PRINCESS_TILE+((i&2)^2)+0x0c|PRINCESS_ATR,OAM_PARTICLES); 783 | } 784 | 785 | delay(25); 786 | 787 | /* kong jumps from his position to the ladder, grabbing the princess in the process */ 788 | 789 | side=game_flip; 790 | 791 | if(game_level==1) side^=1; 792 | 793 | if(!side) 794 | { 795 | kong_frame=kongLargeSpriteClimb1R; 796 | x_off=4; 797 | xp_off=24; 798 | } 799 | else 800 | { 801 | kong_frame=kongLargeSpriteClimb1L; 802 | x_off=-4; 803 | xp_off=-8; 804 | } 805 | 806 | kong_tx=!game_flip?76:256-76-32; 807 | kong_oy=kong_y+1; 808 | ky=kong_y<<4; 809 | kdy=-1<<4; 810 | hold=FALSE; 811 | 812 | while(kong_x!=kong_tx) 813 | { 814 | nmi_wait(); 815 | 816 | ky+=kdy; 817 | ++kdy; 818 | kong_y=ky>>4; 819 | if(kong_y>kong_oy) kong_y=kong_oy; 820 | 821 | if(kong_x0) 824 | { 825 | if((!game_flip&&kong_x>=56)||(game_flip&&kong_x<256-56-32)) hold=TRUE; 826 | } 827 | else 828 | { 829 | if((!game_flip&&kong_x<90)||(game_flip&&kong_x>=256-90-32)) hold=TRUE; 830 | } 831 | 832 | princess_frame=cutscene_intro_princess_hold(xp_off,hold,FALSE); 833 | 834 | game_show_kong(OAM_KONG,kong_x+x_off,kong_y); 835 | game_show_princess(princess_frame); 836 | 837 | ++game_frame_cnt; 838 | } 839 | 840 | /* kong climbs away with the princess */ 841 | 842 | while(kong_y>-32) 843 | { 844 | nmi_wait(); 845 | 846 | if(game_frame_cnt&1) --kong_y; 847 | 848 | if(side) 849 | { 850 | kong_frame=(game_frame_cnt&8)?kongLargeSpriteClimb1L:kongLargeSpriteClimb2L; 851 | } 852 | else 853 | { 854 | kong_frame=(game_frame_cnt&8)?kongLargeSpriteClimb1R:kongLargeSpriteClimb2R; 855 | } 856 | 857 | princess_frame=cutscene_intro_princess_hold(xp_off,TRUE,FALSE); 858 | 859 | game_show_kong(OAM_KONG,kong_x+x_off,kong_y); 860 | game_show_princess(princess_frame); 861 | 862 | ++game_frame_cnt; 863 | } 864 | 865 | /* the heart gets broken */ 866 | 867 | delay(16); 868 | 869 | oam_spr(heart_x,heart_y,PLAYER_TILE+0x4c|PLAYER_ATR,OAM_PARTICLES); 870 | sfx_play(SFX_CHN,SFX_CRACK,heart_x); 871 | 872 | delay(80); 873 | } 874 | -------------------------------------------------------------------------------- /data.asm: -------------------------------------------------------------------------------- 1 | ; Copyright 2012 Bubble Zap Games 2 | ; 3 | ; Licensed under the Apache License, Version 2.0 (the "License"); 4 | ; you may not use this file except in compliance with the License. 5 | ; You may obtain a copy of the License at 6 | ; 7 | ; http://www.apache.org/licenses/LICENSE-2.0 8 | ; 9 | ; Unless required by applicable law or agreed to in writing, software 10 | ; distributed under the License is distributed on an "AS IS" BASIS, 11 | ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ; See the License for the specific language governing permissions and 13 | ; limitations under the License. 14 | 15 | ;all binary resources are included here 16 | ;they are declared as extern variables for C compiler in the data.h 17 | 18 | 19 | .section ".rodata4" superfree 20 | 21 | map1: .incbin "nametables\map1.rle" 22 | map2: .incbin "nametables\map2.rle" 23 | map3: .incbin "nametables\map3.rle" 24 | map4: .incbin "nametables\map4.rle" 25 | mape: .incbin "nametables\mape.rle" 26 | mapi: .incbin "nametables\mapi.rle" 27 | 28 | hdmaGradient0List0: 29 | .db $02,$3F,$0C,$3F,$06,$3F,$07,$3F,$02,$3E,$05,$3E,$06,$3E,$09,$3E,$03,$3D,$01,$3D,$08,$3D,$06,$3D,$07,$3D,$02,$3C,$03,$3C,$07,$3C,$06,$3C,$04,$3B,$03,$3B,$07,$3B,$04,$3B,$02,$3A,$01,$3A,$01,$3A,$01,$39,$02,$39,$01,$39,$02,$38,$02,$37,$01,$37,$01,$36,$01,$35,$01,$35,$01,$34,$01,$33,$01,$33,$02,$32,$01,$31,$01,$30,$01,$2F,$02,$2E,$02,$2D,$01,$2C,$01,$2C,$01,$2B,$01,$2B,$01,$2A,$01,$2A,$01,$29,$02,$28,$03,$27,$03,$26,$03,$26,$02,$26,$02,$26,$07,$26,$02,$26,$02,$26,$06,$26,$04,$26,$04,$26,$03,$26,$01,$26,$04,$26,$06,$26,$03,$27,$16,$27 30 | hdmaGradient0List1: 31 | .db $02,$5F,$0C,$5F,$06,$5F,$07,$5F,$02,$5F,$05,$5F,$06,$5F,$09,$5F,$03,$5F,$01,$5F,$08,$5F,$06,$5F,$07,$5F,$02,$5F,$03,$5F,$07,$5F,$06,$5F,$04,$5F,$03,$5F,$07,$5F,$04,$5F,$02,$5F,$01,$5F,$01,$5F,$01,$5F,$02,$5F,$01,$5F,$02,$5F,$02,$5F,$01,$5F,$01,$5F,$01,$5F,$01,$5E,$01,$5E,$01,$5E,$01,$5D,$02,$5C,$01,$5C,$01,$5B,$01,$5A,$02,$59,$02,$58,$01,$58,$01,$57,$01,$57,$01,$56,$01,$56,$01,$55,$01,$55,$02,$54,$03,$54,$03,$54,$03,$54,$02,$55,$02,$55,$07,$56,$02,$56,$02,$57,$06,$58,$04,$59,$04,$59,$03,$59,$01,$5A,$04,$5A,$06,$5B,$03,$5B,$16,$5B 32 | hdmaGradient0List2: 33 | .db $02,$9F,$0C,$9E,$06,$9D,$07,$9C,$02,$9C,$05,$9B,$06,$9A,$09,$99,$03,$99,$01,$98,$08,$97,$06,$96,$07,$95,$02,$95,$03,$94,$07,$93,$06,$92,$04,$92,$03,$91,$07,$90,$04,$8F,$02,$8E,$01,$8D,$01,$8C,$01,$8C,$02,$8B,$01,$8A,$02,$89,$02,$88,$01,$87,$01,$87,$01,$87,$01,$87,$01,$86,$01,$86,$01,$86,$02,$86,$01,$86,$01,$86,$01,$86,$02,$86,$02,$86,$01,$86,$01,$86,$01,$86,$01,$86,$01,$86,$01,$86,$01,$86,$02,$86,$03,$86,$03,$86,$03,$87,$02,$87,$02,$88,$07,$88,$02,$89,$02,$89,$06,$89,$04,$89,$04,$88,$03,$87,$01,$87,$04,$86,$06,$86,$03,$86,$16,$86 34 | 35 | hdmaGradient1List0: 36 | .db $02,$3F,$0C,$3E,$02,$3E,$04,$3D,$04,$3D,$03,$3C,$06,$3C,$01,$3B,$06,$3A,$02,$3A,$07,$39,$06,$38,$01,$38,$05,$37,$05,$37,$03,$36,$05,$35,$05,$34,$07,$33,$01,$33,$05,$32,$04,$32,$03,$31,$07,$30,$04,$2F,$02,$2E,$01,$2D,$01,$2C,$03,$2B,$01,$2A,$01,$2A,$01,$29,$02,$28,$01,$27,$01,$27,$01,$27,$01,$27,$01,$26,$01,$26,$01,$26,$02,$26,$02,$26,$01,$26,$01,$26,$01,$26,$01,$26,$01,$26,$02,$26,$02,$26,$01,$26,$01,$26,$03,$26,$01,$26,$03,$26,$03,$26,$02,$26,$02,$26,$02,$26,$02,$26,$01,$26,$04,$26,$04,$26,$04,$26,$02,$26,$04,$26,$01,$26,$03,$26,$04,$26,$04,$26,$06,$26,$19,$26 37 | hdmaGradient1List1: 38 | .db $02,$5F,$0C,$5F,$02,$5F,$04,$5F,$04,$5F,$03,$5F,$06,$5F,$01,$5F,$06,$5F,$02,$5F,$07,$5F,$06,$5F,$01,$5F,$05,$5F,$05,$5F,$03,$5F,$05,$5F,$05,$5F,$07,$5F,$01,$5F,$05,$5F,$04,$5F,$03,$5F,$07,$5F,$04,$5F,$02,$5F,$01,$5F,$01,$5F,$03,$5F,$01,$5F,$01,$5F,$01,$5F,$02,$5F,$01,$5F,$01,$5F,$01,$5F,$01,$5E,$01,$5E,$01,$5E,$01,$5D,$02,$5C,$02,$5B,$01,$5A,$01,$5A,$01,$59,$01,$59,$01,$58,$02,$57,$02,$56,$01,$56,$01,$55,$03,$54,$01,$54,$03,$54,$03,$54,$02,$54,$02,$55,$02,$55,$02,$54,$01,$55,$04,$55,$04,$55,$04,$56,$02,$57,$04,$57,$01,$58,$03,$59,$04,$5A,$04,$5A,$06,$5B,$19,$5B 39 | hdmaGradient1List2: 40 | .db $02,$9F,$0C,$9F,$02,$9E,$04,$9E,$04,$9D,$03,$9D,$06,$9C,$01,$9C,$06,$9C,$02,$9B,$07,$9A,$06,$9A,$01,$99,$05,$99,$05,$98,$03,$98,$05,$97,$05,$96,$07,$96,$01,$95,$05,$95,$04,$94,$03,$94,$07,$93,$04,$92,$02,$91,$01,$91,$01,$90,$03,$8F,$01,$8F,$01,$8E,$01,$8E,$02,$8E,$01,$8E,$01,$8D,$01,$8E,$01,$8D,$01,$8D,$01,$8E,$01,$8D,$02,$8E,$02,$8E,$01,$8E,$01,$8F,$01,$8E,$01,$8F,$01,$8F,$02,$8F,$02,$8F,$01,$90,$01,$90,$03,$90,$01,$91,$03,$92,$03,$93,$02,$94,$02,$94,$02,$95,$02,$95,$01,$95,$04,$96,$04,$97,$04,$97,$02,$98,$04,$99,$01,$99,$03,$99,$04,$99,$04,$98,$06,$98,$19,$98 41 | 42 | hdmaGradient2List0: 43 | .db $02,$3F,$0C,$3E,$06,$3D,$07,$3C,$07,$3B,$06,$3A,$09,$39,$04,$38,$08,$37,$06,$36,$07,$35,$05,$34,$07,$33,$06,$32,$07,$31,$07,$30,$04,$2F,$02,$2E,$01,$2D,$01,$2C,$01,$2C,$02,$2B,$01,$2A,$02,$29,$02,$28,$01,$27,$01,$26,$01,$26,$02,$25,$01,$24,$02,$23,$02,$22,$01,$21,$01,$21,$01,$20,$02,$20,$01,$20,$01,$20,$02,$20,$01,$20,$01,$20,$01,$20,$01,$20,$01,$20,$01,$20,$02,$20,$01,$20,$01,$20,$02,$20,$01,$20,$02,$20,$02,$20,$02,$20,$04,$20,$02,$20,$04,$20,$05,$20,$06,$20,$04,$20,$01,$20,$02,$20,$04,$20,$01,$20,$04,$21,$02,$21,$04,$21,$15,$21 44 | hdmaGradient2List1: 45 | .db $02,$5F,$0C,$5F,$06,$5F,$07,$5F,$07,$5F,$06,$5F,$09,$5F,$04,$5F,$08,$5F,$06,$5F,$07,$5F,$05,$5F,$07,$5F,$06,$5F,$07,$5F,$07,$5F,$04,$5F,$02,$5F,$01,$5F,$01,$5F,$01,$5E,$02,$5E,$01,$5E,$02,$5E,$02,$5D,$01,$5D,$01,$5D,$01,$5C,$02,$5B,$01,$5B,$02,$5A,$02,$59,$01,$58,$01,$57,$01,$56,$02,$55,$01,$54,$01,$52,$02,$51,$01,$50,$01,$4F,$01,$4E,$01,$4D,$01,$4C,$01,$4B,$02,$4A,$01,$49,$01,$48,$02,$47,$01,$46,$02,$45,$02,$44,$02,$43,$04,$43,$02,$42,$04,$42,$05,$42,$06,$43,$04,$44,$01,$45,$02,$46,$04,$47,$01,$48,$04,$49,$02,$4A,$04,$4B,$15,$4B 46 | hdmaGradient2List2: 47 | .db $02,$9F,$0C,$9F,$06,$9F,$07,$9F,$07,$9F,$06,$9F,$09,$9F,$04,$9F,$08,$9F,$06,$9F,$07,$9F,$05,$9F,$07,$9F,$06,$9F,$07,$9F,$07,$9F,$04,$9F,$02,$9F,$01,$9F,$01,$9F,$01,$9F,$02,$9F,$01,$9F,$02,$9F,$02,$9F,$01,$9F,$01,$9F,$01,$9F,$02,$9F,$01,$9F,$02,$9F,$02,$9F,$01,$9F,$01,$9F,$01,$9F,$02,$9F,$01,$9E,$01,$9E,$02,$9D,$01,$9C,$01,$9C,$01,$9C,$01,$9C,$01,$9B,$01,$9B,$02,$9A,$01,$9A,$01,$9A,$02,$9A,$01,$9A,$02,$9B,$02,$9B,$02,$9B,$04,$9C,$02,$9C,$04,$9D,$05,$9E,$06,$9F,$04,$9F,$01,$9F,$02,$9F,$04,$9F,$01,$9F,$04,$9F,$02,$9F,$04,$9F,$15,$9F 48 | 49 | hdmaGradient3List0: 50 | .db $02,$3F,$4E,$3F,$01,$3F,$02,$3F,$01,$3F,$01,$3F,$03,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$02,$3F,$02,$3F,$02,$3F,$01,$3F,$01,$3F,$02,$3F,$02,$3F,$02,$3F,$02,$3F,$01,$3F,$01,$3F,$02,$3F,$02,$3F,$01,$3F,$01,$3F,$02,$3F,$02,$3F,$03,$3F,$01,$3E,$01,$3E,$01,$3D,$02,$3C,$02,$3B,$01,$3B,$01,$3B,$01,$3A,$01,$3A,$01,$39,$01,$39,$01,$38,$01,$37,$03,$36,$02,$35,$01,$34,$03,$33,$02,$32,$02,$31,$02,$30,$02,$2F,$02,$2E,$01,$2E,$01,$2D,$02,$2C,$03,$2B,$02,$2A,$01,$29,$03,$28,$01,$27,$02,$26,$02,$26,$01,$25,$01,$24,$03,$23,$03,$22,$01,$21,$01,$21,$01,$20,$26,$20 51 | hdmaGradient3List1: 52 | .db $02,$5D,$4E,$5D,$01,$5C,$02,$5D,$01,$5C,$01,$5C,$03,$5C,$01,$5B,$01,$5B,$01,$5C,$01,$5B,$02,$5B,$02,$5B,$02,$5A,$01,$5B,$01,$5A,$02,$5A,$02,$5A,$02,$59,$02,$5A,$01,$59,$01,$59,$02,$59,$02,$59,$01,$58,$01,$58,$02,$58,$02,$58,$03,$57,$01,$57,$01,$56,$01,$56,$02,$55,$02,$54,$01,$55,$01,$54,$01,$54,$01,$53,$01,$53,$01,$52,$01,$53,$01,$51,$03,$50,$02,$50,$01,$4F,$03,$4E,$02,$4E,$02,$4D,$02,$4C,$02,$4B,$02,$4B,$01,$4A,$01,$4A,$02,$49,$03,$48,$02,$47,$01,$47,$03,$46,$01,$45,$02,$45,$02,$44,$01,$44,$01,$43,$03,$42,$03,$41,$01,$41,$01,$40,$01,$40,$26,$40 53 | hdmaGradient3List2: 54 | .db $02,$95,$4E,$94,$01,$93,$02,$93,$01,$92,$01,$91,$03,$90,$01,$90,$01,$8F,$01,$8F,$01,$8E,$02,$8D,$02,$8C,$02,$8B,$01,$8B,$01,$8A,$02,$89,$02,$88,$02,$87,$02,$86,$01,$86,$01,$85,$02,$84,$02,$83,$01,$83,$01,$82,$02,$81,$02,$80,$03,$80,$01,$80,$01,$80,$01,$80,$02,$80,$02,$80,$01,$80,$01,$80,$01,$80,$01,$80,$01,$80,$01,$80,$01,$80,$01,$80,$03,$80,$02,$80,$01,$80,$03,$80,$02,$80,$02,$80,$02,$80,$02,$80,$02,$80,$01,$80,$01,$80,$02,$80,$03,$80,$02,$80,$01,$80,$03,$80,$01,$80,$02,$80,$02,$80,$01,$80,$01,$80,$03,$80,$03,$80,$01,$80,$01,$80,$01,$80,$26,$80 55 | 56 | hdmaGradient4List0: 57 | .db $02,$37,$4D,$36,$02,$35,$03,$34,$01,$33,$03,$32,$01,$31,$02,$30,$01,$30,$01,$2F,$02,$2E,$02,$2D,$02,$2C,$02,$2B,$02,$2A,$02,$29,$02,$28,$01,$28,$01,$27,$02,$26,$01,$26,$01,$25,$01,$25,$01,$24,$02,$23,$01,$22,$02,$22,$01,$21,$01,$21,$01,$20,$01,$20,$03,$20,$01,$20,$01,$20,$02,$20,$02,$20,$02,$20,$01,$20,$01,$20,$01,$20,$02,$20,$01,$20,$02,$20,$01,$20,$03,$20,$01,$20,$03,$20,$02,$20,$02,$20,$01,$20,$01,$20,$01,$20,$01,$20,$02,$20,$02,$20,$02,$20,$02,$20,$02,$20,$02,$20,$01,$20,$01,$20,$02,$20,$01,$20,$02,$20,$02,$20,$03,$20,$01,$20,$03,$20,$25,$20 58 | hdmaGradient4List1: 59 | .db $02,$5B,$4D,$5B,$02,$5A,$03,$59,$01,$59,$03,$58,$01,$58,$02,$57,$01,$58,$01,$57,$02,$57,$02,$56,$02,$55,$02,$55,$02,$55,$02,$54,$02,$54,$01,$53,$01,$53,$02,$53,$01,$52,$01,$52,$01,$51,$01,$52,$02,$51,$01,$51,$02,$50,$01,$4F,$01,$50,$01,$50,$01,$4F,$03,$4F,$01,$4E,$01,$4E,$02,$4D,$02,$4D,$02,$4D,$01,$4C,$01,$4C,$01,$4C,$02,$4B,$01,$4B,$02,$4B,$01,$4A,$03,$4A,$01,$49,$03,$48,$02,$48,$02,$48,$01,$47,$01,$47,$01,$47,$01,$46,$02,$46,$02,$45,$02,$45,$02,$45,$02,$44,$02,$44,$01,$43,$01,$43,$02,$43,$01,$42,$02,$42,$02,$41,$03,$41,$01,$40,$03,$40,$25,$40 60 | hdmaGradient4List2: 61 | .db $02,$9F,$4D,$9F,$02,$9F,$03,$9F,$01,$9F,$03,$9F,$01,$9F,$02,$9F,$01,$9F,$01,$9F,$02,$9F,$02,$9F,$02,$9F,$02,$9F,$02,$9F,$02,$9F,$02,$9F,$01,$9F,$01,$9F,$02,$9F,$01,$9F,$01,$9F,$01,$9F,$01,$9F,$02,$9F,$01,$9F,$02,$9F,$01,$9F,$01,$9F,$01,$9F,$01,$9F,$03,$9E,$01,$9E,$01,$9D,$02,$9C,$02,$9B,$02,$9A,$01,$9A,$01,$99,$01,$98,$02,$98,$01,$97,$02,$96,$01,$95,$03,$94,$01,$93,$03,$92,$02,$91,$02,$90,$01,$90,$01,$8F,$01,$8E,$01,$8E,$02,$8D,$02,$8C,$02,$8B,$02,$8A,$02,$89,$02,$88,$01,$88,$01,$87,$02,$86,$01,$85,$02,$84,$02,$83,$03,$82,$01,$81,$03,$80,$25,$80 62 | 63 | hdmaGradient5List0: 64 | .db $02,$3F,$0C,$3F,$06,$3F,$03,$3F,$04,$3F,$01,$3F,$01,$3F,$02,$3F,$04,$3F,$02,$3F,$03,$3F,$05,$3F,$04,$3F,$03,$3F,$01,$3F,$08,$3F,$01,$3F,$05,$3F,$07,$3F,$05,$3F,$08,$3F,$05,$3F,$03,$3F,$04,$3F,$03,$3F,$04,$3F,$02,$3F,$02,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$01,$3F,$02,$3F,$01,$3F,$01,$3F,$01,$3E,$02,$3E,$01,$3D,$03,$3C,$02,$3B,$01,$3A,$02,$39,$02,$38,$01,$38,$01,$37,$02,$36,$02,$36,$01,$35,$03,$35,$01,$34,$03,$34,$02,$34,$02,$35,$04,$35,$05,$36,$04,$36,$02,$37,$01,$37,$05,$38,$04,$39,$04,$39,$04,$3A,$04,$3A,$06,$3B,$19,$3B 65 | hdmaGradient5List1: 66 | .db $02,$5F,$0C,$5E,$06,$5E,$03,$5D,$04,$5D,$01,$5C,$01,$5D,$02,$5C,$04,$5C,$02,$5B,$03,$5B,$05,$5A,$04,$5A,$03,$59,$01,$59,$08,$58,$01,$58,$05,$57,$07,$56,$05,$55,$08,$54,$05,$54,$03,$53,$04,$53,$03,$52,$04,$52,$02,$51,$02,$51,$01,$50,$01,$50,$01,$4F,$01,$4E,$01,$4F,$01,$4E,$01,$4D,$01,$4D,$01,$4C,$01,$4C,$02,$4C,$01,$4B,$01,$4B,$01,$4B,$02,$4B,$01,$4B,$03,$4C,$02,$4C,$01,$4D,$02,$4D,$02,$4D,$01,$4E,$01,$4E,$02,$4E,$02,$4F,$01,$4F,$03,$50,$01,$50,$03,$51,$02,$52,$02,$53,$04,$54,$05,$55,$04,$56,$02,$56,$01,$57,$05,$57,$04,$58,$04,$57,$04,$57,$04,$56,$06,$56,$19,$56 67 | hdmaGradient5List2: 68 | .db $02,$9F,$0C,$9E,$06,$9D,$03,$9D,$04,$9C,$01,$9C,$01,$9C,$02,$9C,$04,$9B,$02,$9B,$03,$9A,$05,$9A,$04,$99,$03,$99,$01,$98,$08,$98,$01,$97,$05,$96,$07,$95,$05,$94,$08,$93,$05,$92,$03,$92,$04,$91,$03,$91,$04,$90,$02,$90,$02,$8F,$01,$8F,$01,$8E,$01,$8E,$01,$8D,$01,$8C,$01,$8C,$01,$8B,$01,$8A,$01,$8A,$01,$89,$02,$88,$01,$88,$01,$87,$01,$87,$02,$86,$01,$86,$03,$86,$02,$86,$01,$86,$02,$86,$02,$86,$01,$86,$01,$86,$02,$86,$02,$86,$01,$86,$03,$86,$01,$86,$03,$86,$02,$86,$02,$86,$04,$86,$05,$86,$04,$86,$02,$86,$01,$86,$05,$86,$04,$86,$04,$86,$04,$86,$04,$86,$06,$86,$19,$86 69 | 70 | hdmaGradient6List0: 71 | .db $02,$3F,$0A,$3F,$06,$3F,$09,$3F,$06,$3F,$08,$3F,$08,$3F,$08,$3F,$07,$3F,$06,$3F,$0A,$3F,$45,$3F,$0A,$3F,$05,$3F,$08,$3F,$08,$3F,$07,$3F,$08,$3F,$06,$3F,$0A,$3F,$05,$3F,$08,$3F 72 | hdmaGradient6List1: 73 | .db $02,$5F,$0A,$5F,$06,$5F,$09,$5F,$06,$5F,$08,$5F,$08,$5F,$08,$5F,$07,$5F,$06,$5F,$0A,$5F,$45,$5F,$0A,$5F,$05,$5F,$08,$5F,$08,$5F,$07,$5F,$08,$5F,$06,$5F,$0A,$5F,$05,$5F,$08,$5F 74 | hdmaGradient6List2: 75 | .db $02,$95,$0A,$96,$06,$97,$09,$98,$06,$99,$08,$9A,$08,$9B,$08,$9C,$07,$9D,$06,$9E,$0A,$9F,$45,$9E,$0A,$9D,$05,$9C,$08,$9B,$08,$9A,$07,$99,$08,$98,$06,$97,$0A,$96,$05,$95,$08,$95 76 | 77 | 78 | tileset2alt_gfx: .incbin "gfx\tileset2alt.chr" 79 | 80 | music_title_data: .incbin "sound\music_title.bin" FSIZE _music_title_size 81 | music_title_size: .dw _music_title_size 82 | 83 | music_game_start_data: .incbin "sound\music_game_start.bin" FSIZE _music_game_start_size 84 | music_game_start_size: .dw _music_game_start_size 85 | 86 | music_stage_start_data: .incbin "sound\music_stage_start.bin" FSIZE _music_stage_start_size 87 | music_stage_start_size: .dw _music_stage_start_size 88 | 89 | music_stage_clear_data: .incbin "sound\music_stage_clear.bin" FSIZE _music_stage_clear_size 90 | music_stage_clear_size: .dw _music_stage_clear_size 91 | 92 | music_hammer_data: .incbin "sound\music_hammer.bin" FSIZE _music_hammer_size 93 | music_hammer_size: .dw _music_hammer_size 94 | 95 | music_level1_data: .incbin "sound\music_level1.bin" FSIZE _music_level1_size 96 | music_level1_size: .dw _music_level1_size 97 | 98 | music_lose_data: .incbin "sound\music_lose.bin" FSIZE _music_lose_size 99 | music_lose_size: .dw _music_lose_size 100 | 101 | music_time_out_data: .incbin "sound\music_time_out.bin" FSIZE _music_time_out_size 102 | music_time_out_size: .dw _music_time_out_size 103 | 104 | music_victory_data: .incbin "sound\music_victory.bin" FSIZE _music_victory_size 105 | music_victory_size: .dw _music_victory_size 106 | 107 | .ends 108 | 109 | 110 | 111 | .section ".rodata5" superfree 112 | 113 | title_top_gfx: .incbin "gfx\title_top.chr" 114 | title_bottom_gfx: .incbin "gfx\title_bottom.chr" 115 | font_gfx: .incbin "gfx\font.chr" 116 | tileset1_gfx: .incbin "gfx\tileset1.chr" 117 | tileset2_gfx: .incbin "gfx\tileset2.chr" 118 | sprites1_gfx: .incbin "gfx\sprites1.chr" 119 | sprites2_gfx: .incbin "gfx\sprites2.chr" 120 | sprites3_gfx: .incbin "gfx\sprites3.chr" 121 | sprites4_gfx: .incbin "gfx\sprites4.chr" 122 | sprites5_gfx: .incbin "gfx\sprites5.chr" 123 | 124 | back1_pal: .incbin "gfx\back1.pal" 125 | font_pal: .incbin "gfx\font.pal" 126 | tileset1_pal: .incbin "gfx\tileset1.pal" 127 | tileset1alt1_pal: .incbin "gfx\tileset1alt1.pal" 128 | tileset1alt2_pal: .incbin "gfx\tileset1alt2.pal" 129 | tileset2_pal: .incbin "gfx\tileset2.pal" 130 | tileset2alt_pal: .incbin "gfx\tileset2alt.pal" 131 | sprites1_pal: .incbin "gfx\sprites1.pal" 132 | sprites2_pal: .incbin "gfx\sprites2.pal" 133 | sprites3_pal: .incbin "gfx\sprites3.pal" 134 | sprites4_pal: .incbin "gfx\sprites4.pal" 135 | sprites5_pal: .incbin "gfx\sprites5.pal" 136 | sprites5alt_pal: .incbin "gfx\sprites5alt.pal" 137 | sprites6_pal: .incbin "gfx\sprites6.pal" 138 | title_top_pal: .incbin "gfx\title_top.pal" 139 | title_bottom_pal: .incbin "gfx\title_bottom.pal" 140 | bzlogo_pal: .incbin "gfx\bubblezaplogo.pal" 141 | 142 | .ends 143 | 144 | 145 | 146 | .section ".rodata6" superfree 147 | 148 | spc700_data: .incbin "spc700.bin" FSIZE _spc700_size 149 | spc700_size: .dw _spc700_size 150 | 151 | .ends 152 | 153 | 154 | 155 | .section ".rodata7" superfree 156 | 157 | back1_gfx: .incbin "gfx\back1.chr" 158 | bzlogo_gfx: .incbin "gfx\bubblezaplogo.chr" 159 | sprites6_gfx: .incbin "gfx\sprites6.chr" 160 | 161 | .ends 162 | -------------------------------------------------------------------------------- /data.h: -------------------------------------------------------------------------------- 1 | /* all external data is included in binary form in the data.asm */ extern const unsigned char font_gfx[]; extern const unsigned int font_pal[]; extern const unsigned char tileset1_gfx[]; extern const unsigned int tileset1_pal[]; extern const unsigned int tileset1alt1_pal[]; extern const unsigned int tileset1alt2_pal[]; extern const unsigned char tileset2_gfx[]; extern const unsigned int tileset2_pal[]; extern const unsigned char tileset2alt_gfx[]; extern const unsigned int tileset2alt_pal[]; extern const unsigned char sprites1_gfx[]; extern const unsigned int sprites1_pal[]; extern const unsigned char sprites2_gfx[]; extern const unsigned int sprites2_pal[]; extern const unsigned char sprites3_gfx[]; extern const unsigned int sprites3_pal[]; extern const unsigned char sprites4_gfx[]; extern const unsigned int sprites4_pal[]; extern const unsigned char sprites5_gfx[]; extern const unsigned int sprites5_pal[]; extern const unsigned int sprites5alt_pal[]; extern const unsigned char sprites6_gfx[]; extern const unsigned int sprites6_pal[]; extern const unsigned char title_top_gfx[]; extern const unsigned int title_top_pal[]; extern const unsigned char title_bottom_gfx[]; extern const unsigned int title_bottom_pal[]; extern const unsigned char back1_gfx[]; extern const unsigned int back1_pal[]; extern const unsigned char back2_gfx[]; extern const unsigned int back2_pal[]; extern const unsigned char back3_gfx[]; extern const unsigned int back3_pal[]; extern const unsigned char back4_gfx[]; extern const unsigned int back4_pal[]; extern const unsigned char back5_gfx[]; extern const unsigned int back5_pal[]; extern const unsigned char bzlogo_gfx[]; extern const unsigned int bzlogo_pal[]; extern const unsigned char spc700_data[]; extern const unsigned int spc700_size; extern const unsigned char music_title_data[]; extern const unsigned int music_title_size[]; extern const unsigned char music_game_start_data[]; extern const unsigned int music_game_start_size[]; extern const unsigned char music_stage_start_data[]; extern const unsigned int music_stage_start_size[]; extern const unsigned char music_stage_clear_data[]; extern const unsigned int music_stage_clear_size[]; extern const unsigned char music_hammer_data[]; extern const unsigned int music_hammer_size[]; extern const unsigned char music_level1_data[]; extern const unsigned int music_level1_size[]; extern const unsigned char music_lose_data[]; extern const unsigned int music_lose_size[]; extern const unsigned char music_time_out_data[]; extern const unsigned int music_time_out_size[]; extern const unsigned char music_victory_data[]; extern const unsigned int music_victory_size[]; extern const unsigned char map1[]; extern const unsigned char map2[]; extern const unsigned char map3[]; extern const unsigned char map4[]; extern const unsigned char mape[]; extern const unsigned char mapi[]; extern const unsigned char hdmaGradient0List0[]; extern const unsigned char hdmaGradient0List1[]; extern const unsigned char hdmaGradient0List2[]; extern const unsigned char hdmaGradient1List0[]; extern const unsigned char hdmaGradient1List1[]; extern const unsigned char hdmaGradient1List2[]; extern const unsigned char hdmaGradient2List0[]; extern const unsigned char hdmaGradient2List1[]; extern const unsigned char hdmaGradient2List2[]; extern const unsigned char hdmaGradient3List0[]; extern const unsigned char hdmaGradient3List1[]; extern const unsigned char hdmaGradient3List2[]; extern const unsigned char hdmaGradient4List0[]; extern const unsigned char hdmaGradient4List1[]; extern const unsigned char hdmaGradient4List2[]; extern const unsigned char hdmaGradient5List0[]; extern const unsigned char hdmaGradient5List1[]; extern const unsigned char hdmaGradient5List2[]; extern const unsigned char hdmaGradient6List0[]; extern const unsigned char hdmaGradient6List1[]; extern const unsigned char hdmaGradient6List2[]; -------------------------------------------------------------------------------- /enemy.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Bubble Zap Games 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | //clear enemy list 18 | 19 | void enemy_clear(void) 20 | { 21 | static unsigned char i; 22 | 23 | memset(enemy_type,ENEMY_NONE,ENEMY_MAX); 24 | 25 | enemy_free=0; 26 | enemy_all=0; 27 | 28 | for(i=0;i=ENEMY_MAX) enemy_free=0; 114 | 115 | return TRUE; 116 | } 117 | 118 | 119 | 120 | //remove an enemy from the list 121 | 122 | unsigned char enemy_remove(unsigned char i,unsigned char destroy) 123 | { 124 | static unsigned char fire; 125 | 126 | oam_spr(0,240,0,OAM_ENEMY+(i<<2));//hide sprite 127 | 128 | fire=FALSE; 129 | 130 | switch(enemy_type[i]) 131 | { 132 | case ENEMY_ROLLING_BARREL://rolling barrel fires the burning barrel when gets there 133 | if(!destroy) fire=TRUE; 134 | break; 135 | 136 | case ENEMY_FIREBALL_1: 137 | fire=TRUE; 138 | case ENEMY_FIREBALL_2: 139 | case ENEMY_FIREBALL_1_JUMP_IN: 140 | case ENEMY_FIREBALL_1_SPAWN: 141 | if(destroy&&game_fireballs) --game_fireballs; 142 | break; 143 | 144 | case ENEMY_CEMENT_PAN://update number of cement pans on a conveyor belt 145 | if(enemy_y[i]<160) --conveyor_items[1]; else --conveyor_items[2]; 146 | break; 147 | } 148 | 149 | enemy_type[i]=ENEMY_NONE; 150 | enemy_free=i; 151 | 152 | --enemy_all; 153 | 154 | return fire; 155 | } 156 | 157 | 158 | 159 | //check for jumping over an object, like barrel, firefox, or a cement pan 160 | 161 | unsigned char enemy_check_object_jump(unsigned char ox,unsigned char oy) 162 | { 163 | if(oy>=player_y+12&&oy=ox-4&&player_x>1)+1; 187 | 188 | hammer=(player_hammer_time&&player_jump!=JUMP_AIR&&!player_fall)?TRUE:FALSE; 189 | hammer_off=(player_hammer_phase+(player_dir_prev==DIR_LEFT?0:2))<<1; 190 | 191 | spr=OAM_ENEMY; 192 | frame=game_frame_cnt; 193 | fire=FALSE; 194 | jump_over=FALSE; 195 | barrels_jumped=0; 196 | 197 | for(i=0;i1) 241 | { 242 | enemy_dx [i]=0-enemy_dx[i]; 243 | enemy_land[i]=0; 244 | 245 | sfx_play(SFX_CHN+2,SFX_BARREL1+(rand()&3),ox); 246 | } 247 | 248 | enemy_fall[i]=0; 249 | } 250 | 251 | ox+=enemy_dx[i]; 252 | 253 | if((ox&7)==4) 254 | { 255 | //when a barrel is on top of a ladder, make a decision as described in 256 | //http://donhodges.com/Controlling_the_barrels_in_Donkey_Kong.htm 257 | 258 | if(TEST_MAP(ox+8,oy+14)&T_LADDER) 259 | { 260 | take_ladder=FALSE; 261 | 262 | if(!barrel_fire) take_ladder=TRUE; 263 | 264 | if(oy=192) 303 | { 304 | if(!game_flip) 305 | { 306 | if(ox==32) 307 | { 308 | fire=enemy_remove(i,FALSE); 309 | type=ENEMY_NONE; 310 | } 311 | } 312 | else 313 | { 314 | if(ox==256-32-16) 315 | { 316 | fire=enemy_remove(i,FALSE); 317 | type=ENEMY_NONE; 318 | } 319 | } 320 | } 321 | } 322 | break; 323 | 324 | case ENEMY_LADDER_BARREL: 325 | { 326 | ox=enemy_x[i]; 327 | oy=enemy_y[i]; 328 | 329 | oam_spr1(ox,oy,BARREL_TILE+0x08|((enemy_anim[i]&1)<<1)|BARREL_ATR,spr); 330 | 331 | if(!(frame&1)) 332 | { 333 | ++oy; 334 | 335 | if(TEST_MAP(ox+8,oy+14)&T_FLOOR) 336 | { 337 | enemy_dx [i]=0-enemy_dx[i]; 338 | enemy_type[i]=ENEMY_ROLLING_BARREL; 339 | } 340 | } 341 | 342 | if(!(frame&7)) ++enemy_anim[i]; 343 | } 344 | break; 345 | 346 | case ENEMY_WILD_BARREL_DOWN: 347 | case ENEMY_WILD_BARREL_CHANGE: 348 | case ENEMY_WILD_BARREL_SIDE: 349 | { 350 | ox=enemy_x[i]; 351 | oy=enemy_y[i]; 352 | 353 | oam_spr1(ox,oy,BARREL_TILE+0x08|((enemy_anim[i]&1)<<1)|BARREL_ATR,spr); 354 | 355 | if(enemy_fall[i]) 356 | { 357 | --enemy_fall[i]; 358 | } 359 | else 360 | { 361 | ox+=enemy_dx[i]; 362 | ++oy; 363 | 364 | if(TEST_MAP(ox+8,oy+14)==T_FLOOR) 365 | { 366 | if(type!=ENEMY_WILD_BARREL_SIDE) enemy_dx[i]=0-enemy_dx[i]; 367 | enemy_fall[i]=4; 368 | 369 | sfx_play(SFX_CHN+2,SFX_BARREL1+(rand()&3),ox); 370 | } 371 | 372 | if(type!=ENEMY_WILD_BARREL_SIDE) hy=192; else hy=188; 373 | 374 | if(oy>=hy)//wild barrel turns into a rolling barrel at the bottom 375 | { 376 | enemy_type[i]=ENEMY_ROLLING_BARREL; 377 | enemy_fall[i]=0; 378 | enemy_dx [i]=!game_flip?1:-1; 379 | } 380 | } 381 | 382 | if(!(frame&7)) ++enemy_anim[i]; 383 | } 384 | break; 385 | 386 | case ENEMY_FIREBALL_1_JUMP_IN: 387 | { 388 | off=enemy_cnt[i]; 389 | 390 | if(!game_flip) 391 | { 392 | ox=enemy_x[i]+fireBallJumpInAnimation[off+0]; 393 | } 394 | else 395 | { 396 | ox=enemy_x[i]-fireBallJumpInAnimation[off+0]; 397 | } 398 | 399 | oy=enemy_y[i]+fireBallJumpInAnimation[off+1]; 400 | 401 | oam_spr1(ox,oy-2,ENEMY_TILE+0x04|(((frame>>1)&1)<<1)|ENEMY_ATR|(!game_flip?SPR_HFLIP:0),spr); 402 | 403 | enemy_cnt[i]+=2; 404 | 405 | if(enemy_cnt[i]>=sizeof(fireBallJumpInAnimation)) 406 | { 407 | enemy_type[i]=ENEMY_FIREBALL_1; 408 | enemy_cnt [i]=3+(rand()&7); 409 | } 410 | } 411 | break; 412 | 413 | case ENEMY_FIREBALL_1_SPAWN: 414 | { 415 | ox=enemy_x[i]; 416 | oy=enemy_y[i]; 417 | 418 | oam_spr1(ox,oy-2,ENEMY_TILE+0x04|(((frame>>1)&1)<<1)|ENEMY_ATR|SPR_HFLIP,spr); 419 | 420 | ++enemy_cnt[i]; 421 | --oy; 422 | 423 | if(enemy_cnt[i]==14) 424 | { 425 | enemy_type[i]=ENEMY_FIREBALL_1; 426 | enemy_cnt [i]=3+(rand()&7); 427 | } 428 | } 429 | break; 430 | 431 | case ENEMY_FIREBALL_1: 432 | case ENEMY_FIREBALL_2: 433 | { 434 | ox=enemy_x[i]; 435 | oy=enemy_y[i]; 436 | dx=enemy_dx[i]; 437 | 438 | if(enemy_check_object_jump(ox,oy)) 439 | { 440 | game_add_score(100); 441 | particle_add(PART_TYPE_100,ox,oy); 442 | 443 | jump_over=TRUE; 444 | } 445 | 446 | anim=ENEMY_TILE+0x04|(frame&2)|ENEMY_ATR|(dx<=1?SPR_HFLIP:0); 447 | 448 | if(type==ENEMY_FIREBALL_2) 449 | { 450 | if(enemy_spawn[i]>1]; 453 | 454 | ++enemy_spawn[i]; 455 | 456 | oam_spr1(ox,oy-2,anim,spr); 457 | 458 | break; 459 | } 460 | else 461 | { 462 | anim+=4; 463 | } 464 | } 465 | 466 | oam_spr1(ox,oy-2,anim,spr); 467 | 468 | if(enemy_ladder[i]==DIR_NONE) 469 | { 470 | if(frame&1) 471 | { 472 | if(dx) 473 | { 474 | if(dx==1) 475 | { 476 | if(map[NAM_OFF(ox+12,oy+15)]==0xf5) enemy_dx[i]=-1; 477 | } 478 | else 479 | { 480 | if(map[NAM_OFF(ox+4,oy+15)]==0xf5) enemy_dx[i]=1; 481 | } 482 | 483 | ox+=dx; 484 | 485 | if(type==ENEMY_FIREBALL_1) 486 | { 487 | if(!(TEST_MAP(ox+8,oy+16)&T_SOLID)) 488 | { 489 | if(TEST_MAP(ox+8,oy+15)&T_SOLID) --oy; else ++oy; 490 | } 491 | } 492 | } 493 | 494 | --enemy_cnt[i]; 495 | 496 | if(!enemy_cnt[i]) 497 | { 498 | enemy_cnt[i]=4+(rand()&15); 499 | 500 | if(!dx||(player_y==oy&&(rand()&255)>32))/*go to the player*/ 501 | { 502 | if(player_xoy)/*firefoxes are getting smarter on latter loops*/ 519 | { 520 | val=64+game_loops*16; 521 | if(val>255) val=255; 522 | } 523 | else 524 | { 525 | val=64; 526 | } 527 | 528 | if((rand()&255)255) val=255; 541 | } 542 | else 543 | { 544 | val=64; 545 | } 546 | 547 | if((rand()&255)40)/*don't take the ladders at top of the screen*/ 548 | { 549 | enemy_ladder[i]=DIR_UP; 550 | break; 551 | } 552 | } 553 | } 554 | } 555 | } 556 | else 557 | { 558 | if(!(frame&3)) 559 | { 560 | if(enemy_ladder[i]==DIR_UP) 561 | { 562 | --oy; 563 | 564 | if(!(TEST_MAP(ox+8,oy+15)&(T_LADDER|T_LADDER_BROKEN))) 565 | { 566 | enemy_ladder[i]=DIR_NONE; 567 | } 568 | } 569 | else 570 | { 571 | ++oy; 572 | 573 | if(!(TEST_MAP(ox+8,oy+16)&(T_LADDER|T_LADDER_BROKEN))) 574 | { 575 | enemy_ladder[i]=DIR_NONE; 576 | } 577 | } 578 | } 579 | } 580 | } 581 | break; 582 | 583 | case ENEMY_BOUNCE: 584 | { 585 | ox=(enemy_ix[i]>>BOUNCE_FP); 586 | oy=(enemy_iy[i]>>BOUNCE_FP); 587 | 588 | oam_spr(enemy_ix[i]>>BOUNCE_FP,oy,ENEMY_TILE+(enemy_land[i]?0x02:0x00)|ENEMY_ATR,spr); 589 | 590 | if(enemy_idy[i]<(3<=enemy_sy[i]) 593 | { 594 | if((!game_flip&&ox<184)||(game_flip&&ox>256-184-16)) 595 | { 596 | enemy_idy [i]=-3<=(3<=(224<1&&dx<254) 637 | { 638 | oam_spr1(ox,oy,PLAYER_TILE+0x48|PLAYER_ATR,spr); 639 | 640 | if(enemy_check_object_jump(ox,oy)) 641 | { 642 | game_add_score(100); 643 | particle_add(PART_TYPE_100,ox,oy); 644 | 645 | jump_over=TRUE; 646 | } 647 | } 648 | else 649 | { 650 | oam_spr(dx,oy,PLAYER_TILE+0x48|PLAYER_ATR,spr); 651 | type=ENEMY_NONE;//prevent wrapping up the coords for hit box check 652 | } 653 | 654 | if(frame&1) 655 | { 656 | if(oy<160)//middle belt 657 | { 658 | if(dx!=120)//moving 659 | { 660 | if(!conveyor_dir[1]) 661 | { 662 | if(dx<120) ++enemy_ix[i]; else --enemy_ix[i]; 663 | } 664 | else 665 | { 666 | if(dx>120) ++enemy_ix[i]; else --enemy_ix[i]; 667 | } 668 | } 669 | else//falling 670 | { 671 | ++oy; 672 | 673 | if(oy>=88+8)//pan falls into the fire 674 | { 675 | sfx_play(SFX_CHN+3,SFX_BURN,ox); 676 | particle_add(PART_TYPE_SMOKE_UP,120,oy+4); 677 | fire=enemy_remove(i,FALSE); 678 | type=ENEMY_NONE; 679 | break; 680 | } 681 | } 682 | } 683 | else//bottom belt 684 | { 685 | if(conveyor_dir[2]) ++enemy_ix[i]; else --enemy_ix[i]; 686 | } 687 | 688 | if(dx<-16||dx>256)//pan gets off the screen 689 | { 690 | fire=enemy_remove(i,FALSE); 691 | type=ENEMY_NONE; 692 | } 693 | } 694 | } 695 | break; 696 | } 697 | 698 | //check interaction between an enemy and player and hammer 699 | 700 | if(type) 701 | { 702 | if(game_frame_cnt&1)//alternate checks between frames 703 | { 704 | if(player_y+12>oy+4) 705 | if(player_y+4 ox+4) 707 | if(player_x+4 hy) 720 | if(oy+6 hx) 722 | if(ox+6 32) delay=32; 30 | 31 | /*kong throws barrels in a complex loop consisting of few states*/ 32 | 33 | switch(kong_state) 34 | { 35 | case KONG_STATE_STAND:/*kong stands with idle animation*/ 36 | { 37 | if(kong_delay) --kong_delay; 38 | 39 | if(!kong_start) kong_stand_animation_level1(); 40 | 41 | if(!kong_delay&&(!(kong_frame_cnt>>2)||(kong_frame_cnt>>2)==6)) 42 | { 43 | kong_start=FALSE; 44 | 45 | oam_spr(!game_flip?kong_x-8:kong_x+24,kong_y+18,BARREL_TILE+0x00|BARREL_ATR,OAM_BARRELS+(4<<2)); 46 | 47 | kong_state=KONG_STATE_TAKE; 48 | kong_frame=!game_flip?kongLargeSpriteSideL:kongLargeSpriteSideR; 49 | kong_delay=14; 50 | } 51 | } 52 | break; 53 | 54 | case KONG_STATE_TAKE:/*kong takes a barrel*/ 55 | { 56 | --kong_delay; 57 | 58 | if(!kong_delay) 59 | { 60 | oam_spr(kong_x+8,kong_y+18,BARREL_TILE+0x08|BARREL_ATR,OAM_BARRELS+(4<<2)); 61 | 62 | kong_state=KONG_STATE_MIDDLE; 63 | kong_frame=kongLargeSpriteFace1; 64 | kong_delay=12; 65 | } 66 | } 67 | break; 68 | 69 | case KONG_STATE_MIDDLE:/*kong turns to another side*/ 70 | { 71 | --kong_delay; 72 | 73 | if(!kong_delay) 74 | { 75 | if(kong_throw_wild_barrel) 76 | { 77 | oam_spr(0,240,0,OAM_BARRELS+(4<<2)); 78 | 79 | enemy_add(ENEMY_WILD_BARREL+kong_wild_barrel_type,kong_x+8,kong_y+18,0); 80 | 81 | ++kong_wild_barrel_type;/*cycle through wild barrel types during level*/ 82 | 83 | if(kong_wild_barrel_type>2) kong_wild_barrel_type=0; 84 | 85 | kong_throw_wild_barrel=FALSE; 86 | 87 | kong_state=KONG_STATE_WAIT; 88 | kong_frame=kongLargeSpriteThrow; 89 | kong_delay=68; 90 | 91 | break; 92 | } 93 | 94 | oam_spr(!game_flip?kong_x+24:kong_x-8,kong_y+18,BARREL_TILE+0x00|BARREL_ATR,OAM_BARRELS+(4<<2)); 95 | 96 | kong_state=KONG_STATE_DROP; 97 | kong_frame=!game_flip?kongLargeSpriteSideR:kongLargeSpriteSideL; 98 | kong_delay=14; 99 | } 100 | } 101 | break; 102 | 103 | case KONG_STATE_DROP:/*delay after drop*/ 104 | { 105 | if(kong_delay) --kong_delay; 106 | 107 | if(!kong_delay&&enemy_all=player_x+12 157 | ||barrel_fire_y+8 =player_y+12)) 158 | { 159 | clear=LEVEL_LOSE; 160 | } 161 | } 162 | 163 | /*level ends when player gets to the top platform*/ 164 | 165 | if(player_y==16) clear=TRUE; 166 | 167 | return clear; 168 | } 169 | 170 | 171 | 172 | unsigned char game_show_ladders(void) 173 | { 174 | static unsigned char dx; 175 | static unsigned int flip; 176 | 177 | if(game_level==1) 178 | { 179 | if(!game_flip) 180 | { 181 | dx=0; 182 | flip=0; 183 | } 184 | else 185 | { 186 | dx=-8; 187 | flip=SPR_HFLIP; 188 | } 189 | 190 | oam_spr1(ladders_x[0]+dx,ladders_y[0]-1,BARREL_TILE+0x0e|BARREL_ATR|flip,OAM_LADDERS+0); 191 | oam_spr1(ladders_x[1]+dx,ladders_y[1]-1,BARREL_TILE+0x0e|BARREL_ATR|flip,OAM_LADDERS+4); 192 | } 193 | } 194 | 195 | 196 | 197 | unsigned char game_level2(unsigned char clear) 198 | { 199 | static unsigned char i,x,y; 200 | static int val; 201 | 202 | kong_stand_animation_level2(); 203 | 204 | game_show_kong(OAM_KONG,kong_x,kong_y); 205 | game_show_ladders(); 206 | 207 | /*spacing between the cement pans depends on the game loop*/ 208 | 209 | val=128-game_loops*16; 210 | 211 | if(val<48) val=48; 212 | 213 | /*move ladders*/ 214 | 215 | for(i=0;i<2;++i) 216 | { 217 | switch(ladders_dir[i]) 218 | { 219 | case 0:/*down*/ 220 | if(!(game_frame_cnt&7)) 221 | { 222 | if(ladders_cnt[i]<16) 223 | { 224 | ++ladders_y[i]; 225 | ++ladders_cnt[i]; 226 | } 227 | else 228 | { 229 | ladders_dir[i]=1; 230 | ladders_cnt[i]=64+(rand()&15)+(i<<4); 231 | } 232 | } 233 | break; 234 | 235 | case 1:/*delay*/ 236 | if(ladders_cnt[i]) --ladders_cnt[i]; else ladders_dir[i]=2; 237 | break; 238 | 239 | case 2:/*up*/ 240 | if(!(game_frame_cnt&3)) 241 | { 242 | if(ladders_cnt[i]<16) 243 | { 244 | --ladders_y[i]; 245 | ++ladders_cnt[i]; 246 | } 247 | else 248 | { 249 | ladders_dir[i]=3; 250 | ladders_cnt[i]=64+(rand()&15)+(i<<4); 251 | } 252 | } 253 | break; 254 | 255 | case 3:/*delay*/ 256 | if(ladders_cnt[i]) --ladders_cnt[i]; else ladders_dir[i]=0; 257 | break; 258 | } 259 | 260 | if(ladders_dir[i]!=3) 261 | { 262 | x=ladders_x[i]; 263 | y=ladders_y[i]; 264 | 265 | if(player_x>=x-4&&player_x=60&&player_y=player_x+12 275 | ||barrel_fire_y+6 =player_y+12)) 276 | { 277 | clear=LEVEL_LOSE; 278 | } 279 | 280 | /*move kong, change direction of the conveyor belts*/ 281 | 282 | if(game_frame_cnt&1) 283 | { 284 | if(conveyor_dir[0]) ++kong_x; else --kong_x; 285 | 286 | if(kong_x<26||kong_x>200) 287 | { 288 | conveyor_dir[0]^=1; 289 | 290 | for(i=0;i<26;++i) nametable1[POS(3,7)+i]^=0xc; 291 | 292 | if(kong_x<26) 293 | { 294 | conveyor_dir[2]^=1; 295 | 296 | sfx_play(SFX_CHN+3,SFX_SWITCH,128); 297 | 298 | for(i=0;i<32;++i) nametable1[POS(0,22)+i]^=0xc; 299 | } 300 | 301 | game_belts_update=TRUE; 302 | } 303 | 304 | if(!conveyor_cnt_middle)/*do not change middle conveyor direction for few seconds after beginning of the level*/ 305 | { 306 | if(kong_x==120) 307 | { 308 | if((rand()&255)<64)/*the middle belt rarely changes the direction*/ 309 | { 310 | conveyor_dir[1]^=1; 311 | 312 | game_belts_update=TRUE; 313 | 314 | sfx_play(SFX_CHN+3,SFX_SWITCH,128); 315 | 316 | for(i=0;i<15;++i) 317 | { 318 | nametable1[POS( 0,13)+i]^=0xc; 319 | nametable1[POS(17,13)+i]^=0xc; 320 | } 321 | } 322 | } 323 | } 324 | else 325 | { 326 | --conveyor_cnt_middle; 327 | } 328 | 329 | for(i=1;i<3;++i) 330 | { 331 | if(conveyor_dir[i]) 332 | { 333 | ++conveyor_cnt[i]; 334 | if(conveyor_cnt[i]>val) conveyor_cnt[i]=0; 335 | } 336 | else 337 | { 338 | --conveyor_cnt[i]; 339 | if(conveyor_cnt[i]>=val) conveyor_cnt[i]=val-1; 340 | } 341 | } 342 | } 343 | else 344 | { 345 | if(!conveyor_cnt[1]&&conveyor_items[1]<4) 346 | { 347 | if(!conveyor_dir[1]) 348 | { 349 | if(enemy_add(ENEMY_CEMENT_PAN,0,88,(rand()&255)<128?0:1)) ++conveyor_items[1]; 350 | } 351 | } 352 | 353 | if(!conveyor_cnt[2]&&conveyor_items[2]<4) 354 | { 355 | if(enemy_add(ENEMY_CEMENT_PAN,0,160,conveyor_dir[2])) ++conveyor_items[2]; 356 | } 357 | } 358 | 359 | /*check when player touches kong*/ 360 | 361 | if(player_y kong_x) 363 | if(player_x player_y-32&&y>7)!=(player_x>>7)) break; 479 | 480 | i=(i+1)%fireball_spawn_all; 481 | } 482 | 483 | enemy_add(ENEMY_FIREBALL_2,x,y,0); 484 | sfx_play(SFX_CHN+2,SFX_FIRE_SPAWN,x+8); 485 | } 486 | } 487 | 488 | /*check when player touches kong*/ 489 | 490 | if(player_y kong_x) 492 | if(player_x >5; 33 | b=(color&B_MASK)>>10; 34 | 35 | if(i>=112&&i<128) 36 | { 37 | r=0; 38 | g=0; 39 | b=0; 40 | } 41 | else 42 | { 43 | if(g<4) g=4; 44 | g=(g*20)>>5; 45 | r=g; 46 | b=g>>1; 47 | } 48 | 49 | snes_palette_to[i]=r|(g<<5)|(b<<10); 50 | } 51 | 52 | for(i=240;i<256;++i) 53 | { 54 | snes_palette_to[i]=snes_palette[i]; 55 | snes_palette[i]=0; 56 | } 57 | 58 | /* smoothly fade from current palette into the sepia one */ 59 | 60 | for(i=0;i<32;++i) 61 | { 62 | palette_fade_to(0,48); 63 | palette_fade_to(96,224); 64 | 65 | nmi_wait(); 66 | update_palette(); 67 | } 68 | 69 | /* display text as sprites */ 70 | 71 | x=62; 72 | y=104; 73 | 74 | for(i=0;i<250;++i) 75 | { 76 | palette_fade_to(240,256); 77 | 78 | oam_spr1(x+15*0,y,ITEMS_TILE+0x22|GAMEOVER_ATR,OAM_GAMEOVER+(0<<2)); 79 | oam_spr1(x+15*1,y,ITEMS_TILE+0x24|GAMEOVER_ATR,OAM_GAMEOVER+(1<<2)); 80 | oam_spr1(x+15*2,y,ITEMS_TILE+0x26|GAMEOVER_ATR,OAM_GAMEOVER+(2<<2)); 81 | oam_spr1(x+15*3,y,ITEMS_TILE+0x28|GAMEOVER_ATR,OAM_GAMEOVER+(3<<2)); 82 | oam_spr1(x+15*5,y,ITEMS_TILE+0x2a|GAMEOVER_ATR,OAM_GAMEOVER+(4<<2)); 83 | oam_spr1(x+15*6,y,ITEMS_TILE+0x2c|GAMEOVER_ATR,OAM_GAMEOVER+(5<<2)); 84 | oam_spr1(x+15*7,y,ITEMS_TILE+0x28|GAMEOVER_ATR,OAM_GAMEOVER+(6<<2)); 85 | oam_spr1(x+15*8,y,ITEMS_TILE+0x2e|GAMEOVER_ATR,OAM_GAMEOVER+(7<<2)); 86 | 87 | nmi_wait(); 88 | update_palette(); 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /gfx/back1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/back1.bmp -------------------------------------------------------------------------------- /gfx/back1.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/back1.chr -------------------------------------------------------------------------------- /gfx/back1.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/back1.pal -------------------------------------------------------------------------------- /gfx/back2.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/back2.pal -------------------------------------------------------------------------------- /gfx/back3.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/back3.pal -------------------------------------------------------------------------------- /gfx/bubblezaplogo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/bubblezaplogo.bmp -------------------------------------------------------------------------------- /gfx/bubblezaplogo.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/bubblezaplogo.chr -------------------------------------------------------------------------------- /gfx/bubblezaplogo.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/bubblezaplogo.pal -------------------------------------------------------------------------------- /gfx/font.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/font.bmp -------------------------------------------------------------------------------- /gfx/font.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/font.chr -------------------------------------------------------------------------------- /gfx/font.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/font.pal -------------------------------------------------------------------------------- /gfx/sprites1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites1.bmp -------------------------------------------------------------------------------- /gfx/sprites1.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites1.chr -------------------------------------------------------------------------------- /gfx/sprites1.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites1.pal -------------------------------------------------------------------------------- /gfx/sprites2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites2.bmp -------------------------------------------------------------------------------- /gfx/sprites2.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites2.chr -------------------------------------------------------------------------------- /gfx/sprites2.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites2.pal -------------------------------------------------------------------------------- /gfx/sprites3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites3.bmp -------------------------------------------------------------------------------- /gfx/sprites3.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites3.chr -------------------------------------------------------------------------------- /gfx/sprites3.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites3.pal -------------------------------------------------------------------------------- /gfx/sprites4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites4.bmp -------------------------------------------------------------------------------- /gfx/sprites4.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites4.chr -------------------------------------------------------------------------------- /gfx/sprites4.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites4.pal -------------------------------------------------------------------------------- /gfx/sprites5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites5.bmp -------------------------------------------------------------------------------- /gfx/sprites5.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites5.chr -------------------------------------------------------------------------------- /gfx/sprites5.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites5.pal -------------------------------------------------------------------------------- /gfx/sprites5alt.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites5alt.bmp -------------------------------------------------------------------------------- /gfx/sprites5alt.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites5alt.pal -------------------------------------------------------------------------------- /gfx/sprites6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites6.bmp -------------------------------------------------------------------------------- /gfx/sprites6.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites6.chr -------------------------------------------------------------------------------- /gfx/sprites6.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/sprites6.pal -------------------------------------------------------------------------------- /gfx/tileset1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1.bmp -------------------------------------------------------------------------------- /gfx/tileset1.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1.chr -------------------------------------------------------------------------------- /gfx/tileset1.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1.pal -------------------------------------------------------------------------------- /gfx/tileset1alt1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1alt1.bmp -------------------------------------------------------------------------------- /gfx/tileset1alt1.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1alt1.pal -------------------------------------------------------------------------------- /gfx/tileset1alt2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1alt2.bmp -------------------------------------------------------------------------------- /gfx/tileset1alt2.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset1alt2.pal -------------------------------------------------------------------------------- /gfx/tileset2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2.bmp -------------------------------------------------------------------------------- /gfx/tileset2.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2.chr -------------------------------------------------------------------------------- /gfx/tileset2.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2.pal -------------------------------------------------------------------------------- /gfx/tileset2alt.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2alt.bmp -------------------------------------------------------------------------------- /gfx/tileset2alt.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2alt.chr -------------------------------------------------------------------------------- /gfx/tileset2alt.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/tileset2alt.pal -------------------------------------------------------------------------------- /gfx/title_bottom.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_bottom.bmp -------------------------------------------------------------------------------- /gfx/title_bottom.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_bottom.chr -------------------------------------------------------------------------------- /gfx/title_bottom.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_bottom.pal -------------------------------------------------------------------------------- /gfx/title_top.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_top.bmp -------------------------------------------------------------------------------- /gfx/title_top.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_top.chr -------------------------------------------------------------------------------- /gfx/title_top.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/gfx/title_top.pal -------------------------------------------------------------------------------- /hdr.asm: -------------------------------------------------------------------------------- 1 | ; Copyright 2012 Bubble Zap Games 2 | ; 3 | ; Licensed under the Apache License, Version 2.0 (the "License"); 4 | ; you may not use this file except in compliance with the License. 5 | ; You may obtain a copy of the License at 6 | ; 7 | ; http://www.apache.org/licenses/LICENSE-2.0 8 | ; 9 | ; Unless required by applicable law or agreed to in writing, software 10 | ; distributed under the License is distributed on an "AS IS" BASIS, 11 | ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ; See the License for the specific language governing permissions and 13 | ; limitations under the License. 14 | 15 | ;==LoRom== ; We'll get to HiRom some other time. 16 | 17 | .MEMORYMAP ; Begin describing the system architecture. 18 | SLOTSIZE $8000 ; The slot is $8000 bytes in size. More details on slots later. 19 | DEFAULTSLOT 0 ; There's only 1 slot in SNES, there are more in other consoles. 20 | SLOT 0 $8000 ; Defines Slot 0's starting address. 21 | SLOT 1 $0 $2000 22 | SLOT 2 $2000 $E000 23 | SLOT 3 $0 $10000 24 | .ENDME ; End MemoryMap definition 25 | 26 | .ROMBANKSIZE $8000 ; Every ROM bank is 32 KBytes in size 27 | .ROMBANKS 8 ; Tell WLA how many ROM banks we want 28 | 29 | .SNESHEADER 30 | ID "SNES" ; 1-4 letter string, just leave it as "SNES" 31 | 32 | NAME "Classic Kong Complete" ; Program Title - can't be over 21 bytes, 33 | ; "123456789012345678901" ; use spaces for unused bytes of the name. 34 | 35 | FASTROM;SLOWROM 36 | LOROM 37 | 38 | CARTRIDGETYPE $00 ; $00 = ROM only, see WLA documentation for others 39 | ROMSIZE $08 ; $10 = 4 Mbits, see WLA doc for more.. 40 | SRAMSIZE $00 ; No SRAM see WLA doc for more.. 41 | COUNTRY $01 ; $01 = U.S. $00 = Japan, that's all I know 42 | ; Values $00, $01, $0d use NTSC. 43 | ; Values in range $02..$0c use PAL. Other values are invalid. 44 | LICENSEECODE $00 ; Just use $00 45 | VERSION $00 ; $00 = 1.00, $01 = 1.01, etc. 46 | .ENDSNES 47 | 48 | .SNESNATIVEVECTOR ; Define Native Mode interrupt vector table 49 | COP EmptyHandler 50 | BRK EmptyHandler 51 | ABORT EmptyHandler 52 | NMI VBlank 53 | IRQ EmptyHandler 54 | .ENDNATIVEVECTOR 55 | 56 | .SNESEMUVECTOR ; Define Emulation Mode interrupt vector table 57 | COP EmptyHandler 58 | ABORT EmptyHandler 59 | NMI EmptyHandler 60 | RESET tcc__start ; where execution starts 61 | IRQBRK EmptyHandler 62 | .ENDEMUVECTOR 63 | 64 | .include "data.asm" 65 | -------------------------------------------------------------------------------- /libs/Makefile: -------------------------------------------------------------------------------- 1 | PREFIX=/usr/local/snes-sdk 2 | BINDIR=$(PREFIX)/bin 3 | AS=$(BINDIR)/wla-65816 4 | 5 | OBJS = crt0_snes.obj libm.obj libtcc.obj libc.obj 6 | 7 | %.obj: %.asm 8 | $(AS) -io $< $@ 9 | 10 | all: $(OBJS) 11 | 12 | clean: 13 | rm -f $(OBJS) 14 | -------------------------------------------------------------------------------- /libs/compile.bat: -------------------------------------------------------------------------------- 1 | wla-65816.exe -io crt0_snes.asm crt0_snes.obj 2 | wla-65816.exe -io libc.asm libc.obj 3 | wla-65816.exe -io libm.asm libm.obj 4 | wla-65816.exe -io libtcc.asm libtcc.obj 5 | -------------------------------------------------------------------------------- /libs/crt0_snes.asm: -------------------------------------------------------------------------------- 1 | .include "hdr.asm" 2 | 3 | .ramsection ".registers" bank 0 slot 1 4 | tcc__registers dsb 0 5 | tcc__r0 dsb 2 6 | tcc__r0h dsb 2 7 | tcc__r1 dsb 2 8 | tcc__r1h dsb 2 9 | tcc__r2 dsb 2 10 | tcc__r2h dsb 2 11 | tcc__r3 dsb 2 12 | tcc__r3h dsb 2 13 | tcc__r4 dsb 2 14 | tcc__r4h dsb 2 15 | tcc__r5 dsb 2 16 | tcc__r5h dsb 2 17 | tcc__r9 dsb 2 18 | tcc__r9h dsb 2 19 | tcc__r10 dsb 2 20 | tcc__r10h dsb 2 21 | ; f0/f1 defined in libm.asm 22 | tcc__f2 dsb 2 23 | tcc__f2h dsb 2 24 | tcc__f3 dsb 2 25 | tcc__f3h dsb 2 26 | move_insn dsb 4 ; 3 bytes mvn + 1 byte rts 27 | move_backwards_insn dsb 4 ; 3 bytes mvp + 1 byte rts 28 | __nmi_handler dsb 4 29 | 30 | tcc__registers_irq dsb 0 31 | tcc__regs_irq dsb 48 32 | .ends 33 | 34 | 35 | .BANK 0 SLOT 0 ; Defines the ROM bank and the slot it is inserted in memory. 36 | .ORG 0 ; .ORG 0 is really $8000, because the slot starts at $8000 37 | .SECTION "EmptyVectors" SEMIFREE 38 | 39 | EmptyHandler: 40 | rti 41 | 42 | ;EmptyNMI: 43 | ; rtl 44 | 45 | .ENDS 46 | 47 | .EMPTYFILL $00 ; fill unused areas with $00, opcode for BRK. 48 | ; BRK will crash the snes if executed. 49 | 50 | .bank 0 51 | .section "Snes_Init" SEMIFREE 52 | tcc__snesinit: 53 | rep #$10 ; X/Y 16 bit 54 | sep #$20 ; A is 8 bit 55 | lda #$8F ; screen off, full brightness 56 | sta $2100 ; brightness + screen enable register 57 | stz $2101 ; Sprite register (size + address in VRAM) 58 | stz $2102 ; Sprite registers (address of sprite memory [OAM]) 59 | stz $2103 ; "" "" 60 | 61 | ; $2105 ; Mode 0, = Graphic mode register 62 | ; $2106 ; noplanes, no mosaic, = Mosaic register 63 | ; $2107 ; Plane 0 map VRAM location 64 | ; $2108 ; Plane 1 map VRAM location 65 | ; $2109 ; Plane 2 map VRAM location 66 | ; $210A ; Plane 3 map VRAM location 67 | ; $210B ; Plane 0+1 Tile data location 68 | ; $210C ; Plane 2+3 Tile data location 69 | ldx.w #$2105 70 | - stz 0,x 71 | inx 72 | cpx #$210d 73 | bne - 74 | 75 | ; $210D ; Plane 0 scroll x (first 8 bits) 76 | ; $210D ; Plane 0 scroll x (last 3 bits) #$0 - #$07ff 77 | ; $210E ; Plane 0 scroll y (first 8 bits) 78 | ; $210E ; Plane 0 scroll y (last 3 bits) #$0 - #$07ff 79 | ; $210F ; Plane 1 scroll x (first 8 bits) 80 | ; $210F ; Plane 1 scroll x (last 3 bits) #$0 - #$07ff 81 | ; $2110 ; Plane 1 scroll y (first 8 bits) 82 | ; $2110 ; Plane 1 scroll y (last 3 bits) #$0 - #$07ff 83 | ; $2111 ; Plane 2 scroll x (first 8 bits) 84 | ; $2111 ; Plane 2 scroll x (last 3 bits) #$0 - #$07ff 85 | ; $2112 ; Plane 2 scroll y (first 8 bits) 86 | ; $2112 ; Plane 2 scroll y (last 3 bits) #$0 - #$07ff 87 | ; $2113 ; Plane 3 scroll x (first 8 bits) 88 | ; $2113 ; Plane 3 scroll x (last 3 bits) #$0 - #$07ff 89 | ; $2114 ; Plane 3 scroll y (first 8 bits) 90 | ; $2114 ; Plane 3 scroll y (last 3 bits) #$0 - #$07ff 91 | - stz 0,x 92 | stz 0,x 93 | inx 94 | cpx #$2115 95 | bne - 96 | 97 | lda #$80 ; increase VRAM address after writing to $2119 98 | sta $2115 ; VRAM address increment register 99 | stz $2116 ; VRAM address low 100 | stz $2117 ; VRAM address high 101 | stz $211A ; Initial Mode 7 setting register 102 | stz $211B ; Mode 7 matrix parameter A register (low) 103 | lda #$01 104 | sta $211B ; Mode 7 matrix parameter A register (high) 105 | 106 | ; $211C ; Mode 7 matrix parameter B register (low) 107 | ; $211C ; Mode 7 matrix parameter B register (high) 108 | ; $211D ; Mode 7 matrix parameter C register (low) 109 | ; $211D ; Mode 7 matrix parameter C register (high) 110 | ldx.w #$211c 111 | - stz 0,x 112 | stz 0,x 113 | inx 114 | cpx.w #$211e 115 | bne - 116 | 117 | ; $211E ; Mode 7 matrix parameter D register (low) 118 | ; $211E ; Mode 7 matrix parameter D register (high) <= 1! 119 | stz 0,x 120 | sta 0,x 121 | ; $211F ; Mode 7 center position X register (low) 122 | ; $211F ; Mode 7 center position X register (high) 123 | stz 1,x 124 | stz 1,x 125 | ; $2120 ; Mode 7 center position Y register (low) 126 | ; $2120 ; Mode 7 center position Y register (high) 127 | stz 2,x 128 | stz 2,x 129 | ; $2121 ; Color number register ($0-ff) 130 | stz 3,x 131 | 132 | ; $2123 ; BG1 & BG2 Window mask setting register 133 | ; $2124 ; BG3 & BG4 Window mask setting register 134 | ; $2125 ; OBJ & Color Window mask setting register 135 | ; $2126 ; Window 1 left position register 136 | ; $2127 ; Window 2 left position register 137 | ; $2128 ; Window 3 left position register 138 | ; $2129 ; Window 4 left position register 139 | ; $212A ; BG1, BG2, BG3, BG4 Window Logic register 140 | ; $212B ; OBJ, Color Window Logic Register (or,and,xor,xnor) 141 | ldx.w #$2123 142 | - stz 0,x 143 | inx 144 | cpx.w #$212c 145 | bne - 146 | 147 | ; $212C ; Main Screen designation (planes, sprites enable) 148 | sta 0,x 149 | ; $212D ; Sub Screen designation 150 | stz 1,x 151 | ; $212E ; Window mask for Main Screen 152 | stz 2,x 153 | ; $212F ; Window mask for Sub Screen 154 | stz 3,x 155 | 156 | lda #$30 157 | sta $2130 ; Color addition & screen addition init setting 158 | stz $2131 ; Add/Sub sub designation for screen, sprite, color 159 | lda #$E0 160 | sta $2132 ; color data for addition/subtraction 161 | stz $2133 ; Screen setting (interlace x,y/enable SFX data) 162 | stz $4200 ; Enable V-blank, interrupt, Joypad register 163 | lda #$FF 164 | sta $4201 ; Programmable I/O port 165 | 166 | ; $4202 ; Multiplicand A 167 | ; $4203 ; Multiplier B 168 | ; $4204 ; Multiplier C 169 | ; $4205 ; Multiplicand C 170 | ; $4206 ; Divisor B 171 | ; $4207 ; Horizontal Count Timer 172 | ; $4208 ; Horizontal Count Timer MSB (most significant bit) 173 | ; $4209 ; Vertical Count Timer 174 | ; $420A ; Vertical Count Timer MSB 175 | ; $420B ; General DMA enable (bits 0-7) 176 | ; $420C ; Horizontal DMA (HDMA) enable (bits 0-7) 177 | ; $420D ; Access cycle designation (slow/fast rom) 178 | ldx.w #$4202 179 | - stz 0,x 180 | inx 181 | cpx.w #$420e 182 | bne - 183 | 184 | ;cli ; Enable interrupts 185 | rts 186 | .ends 187 | 188 | 189 | ; Needed to satisfy interrupt definition in "Header.inc". 190 | VBlank: 191 | rep #$30 192 | phb 193 | ;phd 194 | ;phx 195 | ;phy 196 | pha 197 | ; set data bank register to bss section 198 | jsl nmi_handler 199 | ;pea $7e7e 200 | ;plb 201 | ;plb 202 | ;lda.w #tcc__registers_irq 203 | ;tad 204 | ;lda.l __nmi_handler 205 | ;sta.b tcc__r10 206 | ;lda.l __nmi_handler + 2 207 | ;sta.b tcc__r10h 208 | ;jsl tcc__jsl_r10 209 | pla 210 | ;ply 211 | ;plx 212 | ;pld 213 | plb 214 | RTI 215 | 216 | .bank 0 217 | .section ".start" 218 | 219 | .accu 16 220 | .index 16 221 | .16bit 222 | 223 | 224 | tcc__start: 225 | ; Initialize the SNES. 226 | sei ; Disabled interrupts 227 | clc ; clear carry to switch to native mode 228 | xce ; Xchange carry & emulation bit. native mode 229 | rep #$18 ; Binary mode (decimal mode off), X/Y 16 bit 230 | ldx #$1FFF ; set stack to $1FFF 231 | txs 232 | 233 | jsr tcc__snesinit 234 | 235 | rep #$30 ; all registers 16-bit 236 | 237 | ; direct page points to register set 238 | lda.w #tcc__registers 239 | tad 240 | 241 | ;lda.w #EmptyNMI 242 | ;sta.b __nmi_handler 243 | ;lda.w #:EmptyNMI 244 | ;sta.b __nmi_handler + 2 245 | 246 | ; copy .data section to RAM 247 | ldx #0 248 | - lda.l __startsection.data,x 249 | sta.l __startramsectionram.data,x 250 | inx 251 | inx 252 | cpx #(__endsection.data-__startsection.data) 253 | bcc - 254 | 255 | ; set data bank register to bss section 256 | pea $7e7e 257 | plb 258 | plb 259 | 260 | ; clear .bss section 261 | ldx #(((__endramsection.bss-__startramsection.bss) & $fffe) + 2) 262 | beq + 263 | - dex 264 | dex 265 | stz.w $2000, x 266 | bne - 267 | + 268 | 269 | 270 | ; used by memcpy 271 | lda #$0054 ; mvn + 1st byte 272 | sta.b move_insn 273 | lda #$6000 ; 2nd byte + rts 274 | sta.b move_insn + 2 275 | 276 | ; used by memmove 277 | lda #$0044 ; mvp + 1st byte 278 | sta.b move_backwards_insn 279 | lda #$6000 ; 2nd byte + rts 280 | sta.b move_backwards_insn + 2 281 | 282 | pea $ffff - __endramsectionram.data 283 | pea :__endramsectionram.data 284 | pea __endramsectionram.data 285 | ;jsr.l __malloc_init 286 | pla 287 | pla 288 | pla 289 | 290 | stz.b tcc__r0 291 | stz.b tcc__r1 292 | 293 | jsr.l main 294 | 295 | ; write exit code to $fffd 296 | ;lda.b tcc__r0 297 | ;sep #$20 298 | ;sta $fffd 299 | ;rep #$20 300 | stp 301 | .ends 302 | 303 | .endasm 304 | .section ".data" superfree 305 | _hans: .dw $cafe, $babe 306 | _wurscht: .dw $dead, $beef 307 | .ends 308 | 309 | .section "dimpfen" superfree 310 | lda.w #_hans 311 | .ends 312 | .asm 313 | -------------------------------------------------------------------------------- /libs/hdr.asm: -------------------------------------------------------------------------------- 1 | ; Copyright 2012 Bubble Zap Games 2 | ; 3 | ; Licensed under the Apache License, Version 2.0 (the "License"); 4 | ; you may not use this file except in compliance with the License. 5 | ; You may obtain a copy of the License at 6 | ; 7 | ; http://www.apache.org/licenses/LICENSE-2.0 8 | ; 9 | ; Unless required by applicable law or agreed to in writing, software 10 | ; distributed under the License is distributed on an "AS IS" BASIS, 11 | ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ; See the License for the specific language governing permissions and 13 | ; limitations under the License. 14 | 15 | ;==LoRom== ; We'll get to HiRom some other time. 16 | 17 | .MEMORYMAP ; Begin describing the system architecture. 18 | SLOTSIZE $8000 ; The slot is $8000 bytes in size. More details on slots later. 19 | DEFAULTSLOT 0 ; There's only 1 slot in SNES, there are more in other consoles. 20 | SLOT 0 $8000 ; Defines Slot 0's starting address. 21 | SLOT 1 $0 $2000 22 | SLOT 2 $2000 $E000 23 | SLOT 3 $0 $10000 24 | .ENDME ; End MemoryMap definition 25 | 26 | .ROMBANKSIZE $8000 ; Every ROM bank is 32 KBytes in size 27 | .ROMBANKS 8 ; Tell WLA how many ROM banks we want 28 | 29 | .SNESHEADER 30 | ID "SNES" ; 1-4 letter string, just leave it as "SNES" 31 | 32 | NAME "Classic Kong Complete" ; Program Title - can't be over 21 bytes, 33 | ; "123456789012345678901" ; use spaces for unused bytes of the name. 34 | 35 | FASTROM;SLOWROM 36 | LOROM 37 | 38 | CARTRIDGETYPE $00 ; $00 = ROM only, see WLA documentation for others 39 | ROMSIZE $08 ; $10 = 4 Mbits, see WLA doc for more.. 40 | SRAMSIZE $00 ; No SRAM see WLA doc for more.. 41 | COUNTRY $01 ; $01 = U.S. $00 = Japan, that's all I know 42 | ; Values $00, $01, $0d use NTSC. 43 | ; Values in range $02..$0c use PAL. Other values are invalid. 44 | LICENSEECODE $00 ; Just use $00 45 | VERSION $00 ; $00 = 1.00, $01 = 1.01, etc. 46 | .ENDSNES 47 | 48 | .SNESNATIVEVECTOR ; Define Native Mode interrupt vector table 49 | COP EmptyHandler 50 | BRK EmptyHandler 51 | ABORT EmptyHandler 52 | NMI VBlank 53 | IRQ EmptyHandler 54 | .ENDNATIVEVECTOR 55 | 56 | .SNESEMUVECTOR ; Define Emulation Mode interrupt vector table 57 | COP EmptyHandler 58 | ABORT EmptyHandler 59 | NMI EmptyHandler 60 | RESET tcc__start ; where execution starts 61 | IRQBRK EmptyHandler 62 | .ENDEMUVECTOR 63 | -------------------------------------------------------------------------------- /libs/libc.asm: -------------------------------------------------------------------------------- 1 | .include "hdr.asm" 2 | 3 | .section ".libc_mem" superfree 4 | 5 | .accu 16 6 | .index 16 7 | .16bit 8 | 9 | __builtin_memcpy: 10 | memcpy: 11 | lda.b 4,s ; destination 12 | sta.b tcc__r0 13 | tay 14 | lda.b 8,s ; source 15 | tax 16 | lda.b 10,s ; source bank 17 | xba 18 | ora.b 6,s ; dest bank 19 | sta.b move_insn + 1 20 | lda.b 12,s ; length 21 | beq + 22 | dec a 23 | phb 24 | jsr move_insn 25 | plb 26 | lda.b 6,s 27 | sta.b tcc__r0h 28 | + rtl 29 | 30 | __builtin_mempcpy: 31 | mempcpy: 32 | lda.b 4,s ; destination 33 | sta.b tcc__r0 34 | tay 35 | lda.b 8,s ; source 36 | tax 37 | lda.b 10,s ; source bank 38 | xba 39 | ora.b 6,s ; dest bank 40 | sta.b move_insn + 1 41 | lda.b 12,s ; length 42 | beq + 43 | dec a 44 | phb 45 | jsr move_insn 46 | plb 47 | + lda.b 6,s 48 | sta.b tcc__r0h 49 | lda.b 4,s 50 | clc 51 | adc.b 12,s 52 | sta.b tcc__r0 53 | rtl 54 | 55 | __builtin_memmove: 56 | memmove: 57 | lda.b 6,s ; dest bank 58 | cmp.b 10,s 59 | beq memcpy ; different banks -> no overlap 60 | sta.b tcc__r0h 61 | lda.b 4,s ; dest 62 | cmp.b 8,s ; src 63 | beq __local_finished ; nop 64 | bcc memcpy ; dest before src -> forward 65 | 66 | sta.b tcc__r0 ; dest 67 | clc 68 | adc.b 12,s ; +size -> end of dest 69 | tay 70 | lda.b 8,s ; source 71 | clc 72 | adc.b 12,s ; + size -> end of source 73 | tax 74 | lda.b 10,s ; source bank 75 | xba 76 | ora.b 6,s ; dest bank 77 | sta.b move_backwards_insn + 1 78 | lda.b 12,s ; length 79 | beq __local_finished 80 | dec a 81 | phb 82 | jsr move_backwards_insn 83 | plb 84 | __local_finished: rtl 85 | 86 | 87 | __builtin_memset: 88 | memset: 89 | lda.b 4,s ; ptr 90 | sta.b tcc__r0 91 | lda.b 6,s 92 | sta.b tcc__r0h 93 | lda.b 10,s ; count 94 | beq + 95 | tay 96 | lda.b 8,s ; character 97 | sep #$20 98 | - dey 99 | sta.b [tcc__r0],y 100 | bne - 101 | rep #$20 102 | + rtl 103 | 104 | __builtin_bzero: 105 | bzero: 106 | lda.b 4,s 107 | sta.b tcc__r9 108 | lda.b 6,s 109 | sta.b tcc__r9h 110 | lda.b 8,s 111 | beq + 112 | tay 113 | lda.w #0 114 | sep #$20 115 | - dey 116 | sta.b [tcc__r9],y 117 | bne - 118 | rep #$20 119 | + rtl 120 | 121 | .accu 16 122 | .index 16 123 | 124 | __builtin_strcmp: 125 | strcmp: 126 | lda.b 4,s ; dest 127 | sta.b tcc__r9 128 | lda.b 6,s 129 | sta.b tcc__r9h 130 | lda.b 8,s ; src 131 | sta.b tcc__r10 132 | lda.b 10,s 133 | sta.b tcc__r10h 134 | ldy.w #0 135 | sep #$20 136 | - lda.b [tcc__r9],y 137 | sec 138 | sbc.b [tcc__r10],y 139 | beq + ; schaumermol 140 | bcs __local_gresser 141 | bcc __local_kloaner 142 | + lda.b [tcc__r9],y 143 | beq __local_gleich 144 | iny 145 | bra - 146 | __local_gleich: rep #$20 147 | stz.b tcc__r0 148 | rtl 149 | __local_gresser: rep #$20 150 | lda.w #1 151 | sta.b tcc__r0 152 | rtl 153 | __local_kloaner: rep #$20 154 | lda.w #-1 155 | sta.b tcc__r0 156 | rtl 157 | 158 | .accu 16 159 | .index 16 160 | 161 | __builtin_memcmp: 162 | memcmp: 163 | lda.b 4,s 164 | sta.b tcc__r9 165 | lda.b 6,s 166 | sta.b tcc__r9h 167 | lda.b 8,s 168 | sta.b tcc__r10 169 | lda.b 10,s 170 | sta.b tcc__r10h 171 | lda.b 12,s 172 | beq __local_gleich 173 | tax 174 | ldy.w #0 175 | sep #$20 176 | - lda.b [tcc__r9],y 177 | sec 178 | sbc.b [tcc__r10],y 179 | beq + ; schaumermol 180 | bcs __local_gresser ; from strcmp 181 | bcc __local_kloaner 182 | + dex 183 | beq __local_gleich 184 | iny 185 | bra - 186 | 187 | .ends -------------------------------------------------------------------------------- /libs/libm.asm: -------------------------------------------------------------------------------- 1 | .include "hdr.asm" 2 | 3 | .section ".libm" superfree 4 | .ends 5 | -------------------------------------------------------------------------------- /libs/libtcc.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/libs/libtcc.asm -------------------------------------------------------------------------------- /make_resources.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem convert all graphics 4 | 5 | path=path;tools\ 6 | del gfx\*.chr >nul 7 | del gfx\*.pal >nul 8 | snesbmp gfx\font.bmp -b 9 | snesbmp gfx\tileset1.bmp -b 10 | snesbmp gfx\tileset1alt1.bmp -b 11 | snesbmp gfx\tileset1alt2.bmp -b 12 | snesbmp gfx\tileset2.bmp -b 13 | snesbmp gfx\tileset2alt.bmp -b 14 | snesbmp gfx\sprites1.bmp -b 15 | snesbmp gfx\sprites2.bmp -b 16 | snesbmp gfx\sprites3.bmp -b 17 | snesbmp gfx\sprites4.bmp -b 18 | snesbmp gfx\sprites5.bmp -b 19 | snesbmp gfx\sprites5alt.bmp -b 20 | snesbmp gfx\sprites6.bmp -b 21 | snesbmp gfx\title_top.bmp -b 22 | snesbmp gfx\title_bottom.bmp -b 23 | snesbmp gfx\back1.bmp -b 24 | snesbmp gfx\bubblezaplogo.bmp -b -256 25 | del gfx\tileset1alt*.chr >nul 26 | del gfx\sprites5alt.chr >nul 27 | 28 | rem convert music and sfx 29 | 30 | xm2data sound\music_title.xm 31 | xm2data sound\music_game_start.xm 32 | xm2data sound\music_stage_start.xm 33 | xm2data sound\music_stage_clear.xm 34 | xm2data sound\music_hammer.xm 35 | xm2data sound\music_level1.xm 36 | xm2data sound\music_lose.xm 37 | xm2data sound\music_time_out.xm 38 | xm2data sound\music_victory.xm 39 | xm2data sound\sounds.xm -s -------------------------------------------------------------------------------- /misc/back.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/misc/back.xcf -------------------------------------------------------------------------------- /misc/kong.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 23 | 27 | 31 | 32 | 34 | 38 | 42 | 43 | 45 | 49 | 53 | 57 | 58 | 60 | 64 | 68 | 72 | 73 | 80 | 85 | 90 | 96 | 98 | 101 | 104 | 105 | 106 | 113 | 118 | 123 | 129 | 131 | 134 | 137 | 138 | 139 | 146 | 151 | 156 | 162 | 164 | 167 | 170 | 171 | 172 | 179 | 184 | 189 | 195 | 197 | 200 | 203 | 204 | 205 | 212 | 217 | 222 | 228 | 230 | 233 | 236 | 237 | 238 | 247 | 256 | 267 | 276 | 285 | 296 | 304 | 309 | 314 | 320 | 322 | 325 | 328 | 329 | 330 | 337 | 342 | 347 | 353 | 355 | 358 | 361 | 362 | 363 | 373 | 380 | 385 | 390 | 396 | 398 | 401 | 404 | 405 | 406 | 417 | 419 | 423 | 427 | 428 | 439 | 441 | 445 | 449 | 450 | 461 | 472 | 483 | 494 | 505 | 516 | 527 | 538 | 539 | 559 | 561 | 562 | 564 | image/svg+xml 565 | 567 | 568 | 569 | 570 | 571 | 575 | 586 | 595 | 604 | 608 | 617 | 625 | 631 | 637 | 643 | 644 | 647 | 656 | 664 | 670 | 676 | 682 | 683 | 687 | 692 | 698 | 704 | 709 | 714 | 720 | 725 | 726 | complete 741 | 742 | 743 | -------------------------------------------------------------------------------- /nametables/map1.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/map1.rle -------------------------------------------------------------------------------- /nametables/map2.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/map2.rle -------------------------------------------------------------------------------- /nametables/map3.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/map3.rle -------------------------------------------------------------------------------- /nametables/map4.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/map4.rle -------------------------------------------------------------------------------- /nametables/mape.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/mape.rle -------------------------------------------------------------------------------- /nametables/mapi.rle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/nametables/mapi.rle -------------------------------------------------------------------------------- /particles.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Bubble Zap Games 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | //clear a particle and hide its sprite 18 | 19 | void particle_clear(unsigned char id) 20 | { 21 | particle_type[id]=PART_TYPE_NONE; 22 | 23 | oam_spr1(0,240,0,OAM_PARTICLES+(id<<2)); 24 | 25 | particle_free=id; 26 | } 27 | 28 | 29 | 30 | //clear particles list and hide their sprites 31 | 32 | void particles_clear(void) 33 | { 34 | static unsigned char i; 35 | 36 | memset(particle_type,PART_TYPE_NONE,PARTICLES_MAX); 37 | 38 | for(i=0;i=PARTICLES_MAX) particle_free=0; 117 | } 118 | 119 | 120 | 121 | //update particles state and sprites 122 | 123 | void particle_process(void) 124 | { 125 | static unsigned char i,j,spr; 126 | 127 | spr=OAM_PARTICLES; 128 | j=game_frame_cnt; 129 | 130 | for(i=0;i 2 | 3 | extern void* __nmi_handler; 4 | 5 | //aliases for the SNES hardware registers 6 | 7 | #define INIDISP(x) *((unsigned char*)0x2100)=(x); 8 | #define OBSEL(x) *((unsigned char*)0x2101)=(x); 9 | #define OAM_ADDR(x) *((unsigned short*)0x2102)=(x); 10 | #define BGMODE(x) *((unsigned char*)0x2105)=(x); 11 | #define MOSAIC(x) *((unsigned char*)0x2106)=(x); 12 | #define BG1SC(x) *((unsigned char*)0x2107)=(x); 13 | #define BG2SC(x) *((unsigned char*)0x2108)=(x); 14 | #define BG3SC(x) *((unsigned char*)0x2109)=(x); 15 | #define BG4SC(x) *((unsigned char*)0x210a)=(x); 16 | #define BG12NBA(x) *((unsigned char*)0x210b)=(x); 17 | #define BG34NBA(x) *((unsigned char*)0x210c)=(x); 18 | #define BG1HOFFS(x) *((unsigned char*)0x210d)=(x); 19 | #define BG1VOFFS(x) *((unsigned char*)0x210e)=(x); 20 | #define BG2HOFFS(x) *((unsigned char*)0x210f)=(x); 21 | #define BG2VOFFS(x) *((unsigned char*)0x2110)=(x); 22 | #define BG3HOFFS(x) *((unsigned char*)0x2111)=(x); 23 | #define BG3VOFFS(x) *((unsigned char*)0x2112)=(x); 24 | #define BG4HOFFS(x) *((unsigned char*)0x2113)=(x); 25 | #define BG4VOFFS(x) *((unsigned char*)0x2114)=(x); 26 | #define VRAM_ADDR(x) *((unsigned short*)0x2116)=(x); 27 | #define W12SEL(x) *((unsigned char*)0x2123)=(x); 28 | #define W34SEL(x) *((unsigned char*)0x2124)=(x); 29 | #define WOBJSEL(x) *((unsigned char*)0x2125)=(x); 30 | #define WH0(x) *((unsigned char*)0x2126)=(x); 31 | #define WH1(x) *((unsigned char*)0x2127)=(x); 32 | #define WH2(x) *((unsigned char*)0x2128)=(x); 33 | #define WH3(x) *((unsigned char*)0x2129)=(x); 34 | #define WBGLOG(x) *((unsigned char*)0x212a)=(x); 35 | #define WOBJLOG(x) *((unsigned char*)0x212b)=(x); 36 | #define TM(x) *((unsigned char*)0x212c)=(x); 37 | #define TS(x) *((unsigned char*)0x212d)=(x); 38 | #define CGWSEL(x) *((unsigned char*)0x2130)=(x); 39 | #define CGADSUB(x) *((unsigned char*)0x2131)=(x); 40 | #define COLDATA(x) *((unsigned char*)0x2132)=(x); 41 | #define STAT78() *((unsigned char*)0x213f) 42 | 43 | #define WRAM_ADDR(x) *((unsigned char*)0x2181)= (x) &0xff; \ 44 | *((unsigned char*)0x2182)=((x)>>8 )&0xff; \ 45 | *((unsigned char*)0x2183)=((x)>>16)&0xff; 46 | 47 | #define NMITIMEEN(x) *((unsigned char*)0x4200)=(x); 48 | #define MEMSEL(x) *((unsigned char*)0x420d)=(x); 49 | #define HVBJOY() *((unsigned char*)0x4212) 50 | #define JOY_RD(x) ((unsigned short*)0x4218)[(x)] 51 | 52 | #define DMA_TYPE(chn,x) *((unsigned short*)(0x4300|((chn)<<4)))=(x); 53 | #define DMA_ADDR(chn,x) *((void**) (0x4302|((chn)<<4)))=(x); 54 | #define DMA_SIZE(chn,x) *((unsigned short*)(0x4305|((chn)<<4)))=(x); 55 | 56 | #define MDMAEN(x) *((unsigned char*)0x420b)=(x); 57 | #define HDMAEN(x) *((unsigned char*)0x420c)=(x); 58 | 59 | 60 | //variables for this basic hardware abstract layer 61 | 62 | static unsigned int snes_joypad_state[2]; 63 | static unsigned int snes_joypad_state_prev[2]; 64 | static unsigned int snes_joypad_state_trigger[2]; 65 | static unsigned int snes_frame_cnt; 66 | static unsigned int snes_rand_seed1; 67 | static unsigned int snes_rand_seed2; 68 | static unsigned int snes_palette[256]; 69 | static unsigned char snes_oam[128*4+32]; 70 | static unsigned int snes_ntsc; 71 | static unsigned int snes_skip_cnt; 72 | 73 | 74 | //aliases for pad buttons 75 | 76 | #define PAD_R 0x0010 77 | #define PAD_L 0x0020 78 | #define PAD_X 0x0040 79 | #define PAD_A 0x0080 80 | #define PAD_RIGHT 0x0100 81 | #define PAD_LEFT 0x0200 82 | #define PAD_DOWN 0x0400 83 | #define PAD_UP 0x0800 84 | #define PAD_START 0x1000 85 | #define PAD_SELECT 0x2000 86 | #define PAD_Y 0x4000 87 | #define PAD_B 0x8000 88 | 89 | 90 | //macro for sprite attributes 91 | 92 | #define SPR_PAL(x) (((x)&7)<<9) 93 | #define SPR_PRI(x) ((x)<<12) 94 | #define SPR_HFLIP 0x4000 95 | #define SPR_VFLIP 0x8000 96 | 97 | //macro for background attributes 98 | 99 | #define BG_PAL(x) (((x)&7)<<10) 100 | #define BG_PRI 0x2000 101 | #define BG_HFLIP 0x4000 102 | #define BG_VFLIP 0x8000 103 | 104 | //masks for R5G5B5 components 105 | 106 | #define R_MASK 0x001f 107 | #define G_MASK 0x03e0 108 | #define B_MASK 0x7c00 109 | 110 | 111 | #ifndef FALSE 112 | #define FALSE 0 113 | #endif 114 | 115 | #ifndef TRUE 116 | #define TRUE 1 117 | #endif 118 | 119 | 120 | 121 | //16-bit random number generaton 122 | 123 | unsigned int rand(void) 124 | { 125 | snes_rand_seed1+=(snes_rand_seed2>>1); 126 | snes_rand_seed2-=(15^snes_rand_seed1); 127 | 128 | return snes_rand_seed1; 129 | } 130 | 131 | 132 | 133 | //nmi handler, updates sprites list through DMA every frame 134 | 135 | void nmi_handler(void) 136 | { 137 | static unsigned int i; 138 | 139 | OAM_ADDR(0); //dma oam 140 | DMA_TYPE(7,0x0400); 141 | DMA_ADDR(7,snes_oam); 142 | DMA_SIZE(7,0x0220); 143 | MDMAEN(1<<7); 144 | 145 | ++snes_frame_cnt; 146 | } 147 | 148 | 149 | 150 | //wait for the next TV frame 151 | 152 | void nmi_wait(void) 153 | { 154 | static unsigned int i; 155 | 156 | i=snes_frame_cnt; 157 | 158 | while(i==snes_frame_cnt); 159 | } 160 | 161 | 162 | /* 163 | //wait for the next virtual 50 Hz frame, skips every sixth frame on NTSC 164 | 165 | void nmi_wait50(void) 166 | { 167 | nmi_wait(); 168 | 169 | if(snes_ntsc) 170 | { 171 | ++snes_skip_cnt; 172 | 173 | if(snes_skip_cnt==5) 174 | { 175 | snes_skip_cnt=0; 176 | nmi_wait(); 177 | } 178 | } 179 | } 180 | */ 181 | 182 | 183 | //poll pad ports registers and remember their state 184 | //also polls buttons in trigger mode, bit is set only when a button is pressed, and reset the next frame 185 | 186 | void pad_read_ports(void) 187 | { 188 | static unsigned int i,j; 189 | 190 | while(HVBJOY()&0x01);//wait while joypad is ready 191 | 192 | for(i=0;i<2;++i) 193 | { 194 | j=JOY_RD(i);//read joypads 195 | 196 | snes_joypad_state[i]=j; 197 | snes_joypad_state_trigger[i]=(j^snes_joypad_state_prev[i])&j; 198 | snes_joypad_state_prev[i]=j; 199 | } 200 | } 201 | 202 | 203 | 204 | //get previously remembered pad state 205 | 206 | unsigned int pad_poll(unsigned char j) 207 | { 208 | return snes_joypad_state[j]; 209 | } 210 | 211 | 212 | 213 | //get previously remembered pad trigger state 214 | 215 | unsigned int pad_poll_trigger(unsigned char j) 216 | { 217 | return snes_joypad_state_trigger[j]; 218 | } 219 | 220 | 221 | 222 | //set few entries of the RAM copy of the palette 223 | 224 | void set_palette(unsigned int i,unsigned int len,const unsigned int *src) 225 | { 226 | memcpy(&snes_palette[i],src,len*sizeof(unsigned int)); 227 | } 228 | 229 | 230 | 231 | //set an entry of the RAM copy of the palette 232 | 233 | void set_color(unsigned int i,unsigned int col) 234 | { 235 | snes_palette[i]=col; 236 | } 237 | 238 | 239 | 240 | //update the palette in the VRAM from the RAM copy 241 | 242 | void update_palette(void) 243 | { 244 | DMA_TYPE(7,0x2200); //dma palette 245 | DMA_ADDR(7,snes_palette); 246 | DMA_SIZE(7,0x200); 247 | MDMAEN(1<<7); 248 | } 249 | 250 | 251 | 252 | //copy data from RAM or ROM to the VRAM through DMA 253 | 254 | void copy_to_vram(unsigned int adr,const unsigned char *src,unsigned int size) 255 | { 256 | VRAM_ADDR(adr); 257 | DMA_TYPE(7,0x1801); 258 | DMA_ADDR(7,(unsigned char*)src); 259 | DMA_SIZE(7,size); 260 | MDMAEN(1<<7); 261 | } 262 | 263 | 264 | 265 | //copy data from VRAM to RAM or ROM through DMA 266 | 267 | void copy_from_vram(unsigned int adr,const unsigned char *src,unsigned int size) 268 | { 269 | volatile unsigned short dummy; 270 | 271 | VRAM_ADDR(adr); 272 | 273 | dummy=*(unsigned short*)0x2139; 274 | 275 | DMA_TYPE(7,0x3981); 276 | DMA_ADDR(7,(unsigned char*)src); 277 | DMA_SIZE(7,size); 278 | MDMAEN(1<<7); 279 | } 280 | 281 | 282 | 283 | //fill VRAM with a value through DMA 284 | 285 | void fill_vram(unsigned int adr,const unsigned char value,unsigned int size) 286 | { 287 | VRAM_ADDR(adr); 288 | DMA_TYPE(7,0x1809); 289 | DMA_ADDR(7,&value); 290 | DMA_SIZE(7,size); 291 | MDMAEN(1<<7); 292 | } 293 | 294 | 295 | 296 | //copy data from ROM to RAM or vice versa through DMA (RAM-RAM copy is not possible) 297 | 298 | void copy_mem(unsigned char *dst,unsigned char *src,unsigned int size) 299 | { 300 | WRAM_ADDR(((unsigned long)dst)); 301 | DMA_TYPE(7,0x8000); 302 | DMA_ADDR(7,(unsigned char*)src); 303 | DMA_SIZE(7,size); 304 | MDMAEN(1<<7); 305 | } 306 | 307 | 308 | 309 | //set brightness, also enables and disables rendering 310 | 311 | void set_bright(unsigned int i) 312 | { 313 | if(!i) i=0x80; 314 | INIDISP(i); 315 | } 316 | 317 | 318 | 319 | //set scroll registers for specified layer 320 | 321 | void set_scroll(unsigned int layer,unsigned int x,unsigned int y) 322 | { 323 | switch(layer) 324 | { 325 | case 0: 326 | BG1HOFFS(x&255); 327 | BG1HOFFS(x>>8); 328 | BG1VOFFS(y&255); 329 | BG1VOFFS(y>>8); 330 | break; 331 | 332 | case 1: 333 | BG2HOFFS(x&255); 334 | BG2HOFFS(x>>8); 335 | BG2VOFFS(y&255); 336 | BG2VOFFS(y>>8); 337 | break; 338 | 339 | case 2: 340 | BG3HOFFS(x&255); 341 | BG3HOFFS(x>>8); 342 | BG3VOFFS(y&255); 343 | BG3VOFFS(y>>8); 344 | break; 345 | 346 | case 3: 347 | BG4HOFFS(x&255); 348 | BG4HOFFS(x>>8); 349 | BG4VOFFS(y&255); 350 | BG4VOFFS(y>>8); 351 | break; 352 | } 353 | } 354 | 355 | 356 | 357 | //set pixelize effect 358 | //0 off, 1..16 min to max 359 | 360 | void set_pixelize(unsigned int i) 361 | { 362 | if(i) i=((16-i)<<4)|0x0f; 363 | MOSAIC(i); 364 | } 365 | 366 | 367 | 368 | //set a sprite in the OAM buffer 369 | //this function allows to set complete X value, but works slowly 370 | 371 | void oam_spr(unsigned int x,unsigned int y,unsigned int chr,unsigned int off) 372 | { 373 | static unsigned int offx; 374 | 375 | snes_oam[off+0]=x; 376 | snes_oam[off+1]=y; 377 | snes_oam[off+2]=chr; 378 | snes_oam[off+3]=chr>>8; 379 | 380 | offx=512+(off>>4); 381 | 382 | switch(off&0x0c) 383 | { 384 | case 0x00: 385 | snes_oam[offx]=(snes_oam[offx]&0xfe)|((x>>8)&0x01); 386 | break; 387 | case 0x04: 388 | snes_oam[offx]=(snes_oam[offx]&0xfb)|((x>>6)&0x04); 389 | break; 390 | case 0x08: 391 | snes_oam[offx]=(snes_oam[offx]&0xef)|((x>>4)&0x10); 392 | break; 393 | case 0x0c: 394 | snes_oam[offx]=(snes_oam[offx]&0xbf)|((x>>2)&0x40); 395 | break; 396 | } 397 | } 398 | 399 | 400 | 401 | //set a sprite in the OAM buffer 402 | //this function only sets LSB of X, but works much faster 403 | /* 404 | void oam_spr1(unsigned int x,unsigned int y,unsigned int chr,unsigned int off) 405 | { 406 | snes_oam[off+0]=x; 407 | snes_oam[off+1]=y; 408 | snes_oam[off+2]=chr; 409 | snes_oam[off+3]=chr>>8; 410 | } 411 | */ 412 | #define oam_spr1(x,y,chr,off) snes_oam[(off)+0]=(x); \ 413 | snes_oam[(off)+1]=(y); \ 414 | snes_oam[(off)+2]=(chr); \ 415 | snes_oam[(off)+3]=(chr)>>8; 416 | 417 | 418 | //set size bits of a sprite in the OAM buffer 419 | 420 | //set size bits of a sprite in the OAM buffer 421 | 422 | void oam_size(unsigned int off,unsigned int size) 423 | { 424 | static unsigned int offx; 425 | static unsigned char c; 426 | 427 | offx=512+(off>>4); 428 | c=snes_oam[offx]; 429 | 430 | switch((off>>2)&3) 431 | { 432 | case 0: c=(c&0xfd)|(size<<1); break; 433 | case 1: c=(c&0xf7)|(size<<3); break; 434 | case 2: c=(c&0xdf)|(size<<5); break; 435 | case 3: c=(c&0x7f)|(size<<7); break; 436 | } 437 | 438 | snes_oam[offx]=c; 439 | } 440 | 441 | 442 | 443 | //clear the OAM buffer 444 | 445 | void oam_clear(void) 446 | { 447 | static unsigned int i; 448 | 449 | for(i=0;i<512;i+=4) 450 | { 451 | oam_spr(0,240,0,i); 452 | oam_size(i,0); 453 | } 454 | } 455 | 456 | 457 | 458 | //wait for specified number of TV frames 459 | 460 | void delay(unsigned int i) 461 | { 462 | while(--i) nmi_wait(); 463 | } 464 | 465 | 466 | 467 | //initialize the hardware 468 | 469 | void init(void) 470 | { 471 | static unsigned int i; 472 | 473 | __nmi_handler=nmi_handler; 474 | 475 | snes_frame_cnt=0; 476 | snes_rand_seed1=1; 477 | snes_rand_seed2=5; 478 | snes_ntsc=STAT78()&0x10?0:1; 479 | snes_skip_cnt=0; 480 | 481 | //VRAM offsets are in words, so 64K = $8000 482 | 483 | BGMODE(2+8); //mode 2, 2 layers, 16+16 colors 484 | BG1SC(0<<2); //32x32 nametable at $0000 485 | BG2SC(1<<2); //32x32 nametable at $0400 486 | BG3SC(31<<2); //offsets table $7c00 487 | BG12NBA(0x40); //patterns for layers 1 at $0000, 2 at $4000 488 | BG34NBA(0x44); //patterns for layers 3 and 4 at $4000 489 | TM(0x13); //enable sprites and background 490 | OBSEL(1); //sprite sizes 8x8 and 16x16, graphics at $2000 491 | MEMSEL(1); //FastROM enable 492 | 493 | CGWSEL(0x00); 494 | CGADSUB(0x82); 495 | 496 | for(i=0;i<4;++i) set_scroll(i,0,0); 497 | 498 | for(i=0;i<2;++i) 499 | { 500 | snes_joypad_state[i]=0; 501 | snes_joypad_state_prev[i]=0; 502 | snes_joypad_state_trigger[i]=0; 503 | } 504 | 505 | set_bright(0); 506 | oam_clear(); 507 | 508 | NMITIMEEN(0x81);//enable NMI and joypad 509 | } 510 | -------------------------------------------------------------------------------- /sound/music_game_start.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_game_start.bin -------------------------------------------------------------------------------- /sound/music_game_start.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_game_start.xm -------------------------------------------------------------------------------- /sound/music_hammer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_hammer.bin -------------------------------------------------------------------------------- /sound/music_hammer.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_hammer.xm -------------------------------------------------------------------------------- /sound/music_level1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_level1.bin -------------------------------------------------------------------------------- /sound/music_level1.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_level1.xm -------------------------------------------------------------------------------- /sound/music_lose.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_lose.bin -------------------------------------------------------------------------------- /sound/music_lose.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_lose.xm -------------------------------------------------------------------------------- /sound/music_stage_clear.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_stage_clear.bin -------------------------------------------------------------------------------- /sound/music_stage_clear.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_stage_clear.xm -------------------------------------------------------------------------------- /sound/music_stage_start.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_stage_start.bin -------------------------------------------------------------------------------- /sound/music_stage_start.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_stage_start.xm -------------------------------------------------------------------------------- /sound/music_time_out.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_time_out.bin -------------------------------------------------------------------------------- /sound/music_time_out.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_time_out.xm -------------------------------------------------------------------------------- /sound/music_title.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_title.bin -------------------------------------------------------------------------------- /sound/music_title.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_title.xm -------------------------------------------------------------------------------- /sound/music_victory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_victory.bin -------------------------------------------------------------------------------- /sound/music_victory.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/music_victory.xm -------------------------------------------------------------------------------- /sound/sample0.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample0.brr -------------------------------------------------------------------------------- /sound/sample1.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample1.brr -------------------------------------------------------------------------------- /sound/sample16.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample16.brr -------------------------------------------------------------------------------- /sound/sample17.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample17.brr -------------------------------------------------------------------------------- /sound/sample18.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample18.brr -------------------------------------------------------------------------------- /sound/sample19.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample19.brr -------------------------------------------------------------------------------- /sound/sample2.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample2.brr -------------------------------------------------------------------------------- /sound/sample20.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample20.brr -------------------------------------------------------------------------------- /sound/sample21.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample21.brr -------------------------------------------------------------------------------- /sound/sample22.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample22.brr -------------------------------------------------------------------------------- /sound/sample23.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample23.brr -------------------------------------------------------------------------------- /sound/sample24.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample24.brr -------------------------------------------------------------------------------- /sound/sample25.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample25.brr -------------------------------------------------------------------------------- /sound/sample26.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample26.brr -------------------------------------------------------------------------------- /sound/sample27.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample27.brr -------------------------------------------------------------------------------- /sound/sample3.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample3.brr -------------------------------------------------------------------------------- /sound/sample4.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample4.brr -------------------------------------------------------------------------------- /sound/sample5.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample5.brr -------------------------------------------------------------------------------- /sound/sample6.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample6.brr -------------------------------------------------------------------------------- /sound/sample7.brr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sample7.brr -------------------------------------------------------------------------------- /sound/samples.asm: -------------------------------------------------------------------------------- 1 | dir: 2 | {sample sample0,756} 3 | {sample sample1,0} 4 | {sample sample2,0} 5 | {sample sample3,1080} 6 | {sample sample4,828} 7 | {sample sample5,0} 8 | {sample sample6,0} 9 | {sample sample7,0} 10 | {sample 0,0} 11 | {sample 0,0} 12 | {sample 0,0} 13 | {sample 0,0} 14 | {sample 0,0} 15 | {sample 0,0} 16 | {sample 0,0} 17 | {sample 0,0} 18 | {sample sample16,0} 19 | {sample sample17,0} 20 | {sample sample18,0} 21 | {sample sample19,0} 22 | {sample sample20,0} 23 | {sample sample21,0} 24 | {sample sample22,0} 25 | {sample sample23,0} 26 | {sample sample24,0} 27 | {sample sample25,0} 28 | {sample sample26,0} 29 | {sample sample27,0} 30 | {sample 0,0} 31 | {sample 0,0} 32 | {sample 0,0} 33 | {sample 0,0} 34 | {sample 0,0} 35 | {sample 0,0} 36 | {sample 0,0} 37 | {sample 0,0} 38 | {sample 0,0} 39 | {sample 0,0} 40 | {sample 0,0} 41 | {sample 0,0} 42 | {sample 0,0} 43 | {sample 0,0} 44 | {sample 0,0} 45 | {sample 0,0} 46 | {sample 0,0} 47 | {sample 0,0} 48 | {sample 0,0} 49 | {sample 0,0} 50 | {sample 0,0} 51 | {sample 0,0} 52 | {sample 0,0} 53 | {sample 0,0} 54 | {sample 0,0} 55 | {sample 0,0} 56 | {sample 0,0} 57 | {sample 0,0} 58 | {sample 0,0} 59 | {sample 0,0} 60 | {sample 0,0} 61 | {sample 0,0} 62 | {sample 0,0} 63 | {sample 0,0} 64 | {sample 0,0} 65 | {sample 0,0} 66 | adsr: 67 | {adsr 14,4,3,17} 68 | {adsr 15,7,7,0} 69 | {adsr 15,5,2,20} 70 | {adsr 15,5,1,20} 71 | {adsr 13,5,2,22} 72 | {adsr 15,7,7,0} 73 | {adsr 15,7,7,0} 74 | {adsr 15,7,7,0} 75 | {adsr 15,7,7,0} 76 | {adsr 15,7,7,0} 77 | {adsr 15,7,7,0} 78 | {adsr 15,7,7,0} 79 | {adsr 15,7,7,0} 80 | {adsr 15,7,7,0} 81 | {adsr 15,7,7,0} 82 | {adsr 15,7,7,0} 83 | {adsr 14,5,1,24} 84 | {adsr 14,7,7,0} 85 | {adsr 6,4,1,21} 86 | {adsr 15,7,7,0} 87 | {adsr 15,7,7,0} 88 | {adsr 10,7,7,21} 89 | {adsr 15,7,7,26} 90 | {adsr 15,7,7,0} 91 | {adsr 15,7,7,0} 92 | {adsr 14,7,7,0} 93 | {adsr 14,6,1,19} 94 | {adsr 15,7,7,0} 95 | {adsr 15,7,7,0} 96 | {adsr 15,7,7,0} 97 | {adsr 15,7,7,0} 98 | {adsr 15,7,7,0} 99 | {adsr 15,7,7,0} 100 | {adsr 15,7,7,0} 101 | {adsr 15,7,7,0} 102 | {adsr 15,7,7,0} 103 | {adsr 15,7,7,0} 104 | {adsr 15,7,7,0} 105 | {adsr 15,7,7,0} 106 | {adsr 15,7,7,0} 107 | {adsr 15,7,7,0} 108 | {adsr 15,7,7,0} 109 | {adsr 15,7,7,0} 110 | {adsr 15,7,7,0} 111 | {adsr 15,7,7,0} 112 | {adsr 15,7,7,0} 113 | {adsr 15,7,7,0} 114 | {adsr 15,7,7,0} 115 | {adsr 15,7,7,0} 116 | {adsr 15,7,7,0} 117 | {adsr 15,7,7,0} 118 | {adsr 15,7,7,0} 119 | {adsr 15,7,7,0} 120 | {adsr 15,7,7,0} 121 | {adsr 15,7,7,0} 122 | {adsr 15,7,7,0} 123 | {adsr 15,7,7,0} 124 | {adsr 15,7,7,0} 125 | {adsr 15,7,7,0} 126 | {adsr 15,7,7,0} 127 | {adsr 15,7,7,0} 128 | {adsr 15,7,7,0} 129 | {adsr 15,7,7,0} 130 | {adsr 15,7,7,0} 131 | vibrato: 132 | {vib 0,0} 133 | {vib 0,0} 134 | {vib 0,0} 135 | {vib 25,32} 136 | {vib 18,28} 137 | {vib 0,0} 138 | {vib 0,0} 139 | {vib 0,0} 140 | {vib 0,0} 141 | {vib 0,0} 142 | {vib 0,0} 143 | {vib 0,0} 144 | {vib 0,0} 145 | {vib 0,0} 146 | {vib 0,0} 147 | {vib 0,0} 148 | {vib 0,0} 149 | {vib 0,0} 150 | {vib 0,0} 151 | {vib 0,0} 152 | {vib 0,0} 153 | {vib 0,0} 154 | {vib 0,0} 155 | {vib 0,0} 156 | {vib 0,0} 157 | {vib 0,0} 158 | {vib 0,0} 159 | {vib 0,0} 160 | {vib 0,0} 161 | {vib 0,0} 162 | {vib 0,0} 163 | {vib 0,0} 164 | {vib 0,0} 165 | {vib 0,0} 166 | {vib 0,0} 167 | {vib 0,0} 168 | {vib 0,0} 169 | {vib 0,0} 170 | {vib 0,0} 171 | {vib 0,0} 172 | {vib 0,0} 173 | {vib 0,0} 174 | {vib 0,0} 175 | {vib 0,0} 176 | {vib 0,0} 177 | {vib 0,0} 178 | {vib 0,0} 179 | {vib 0,0} 180 | {vib 0,0} 181 | {vib 0,0} 182 | {vib 0,0} 183 | {vib 0,0} 184 | {vib 0,0} 185 | {vib 0,0} 186 | {vib 0,0} 187 | {vib 0,0} 188 | {vib 0,0} 189 | {vib 0,0} 190 | {vib 0,0} 191 | {vib 0,0} 192 | {vib 0,0} 193 | {vib 0,0} 194 | {vib 0,0} 195 | {vib 0,0} 196 | sample0: 197 | incbin "sample0.brr" 198 | sample1: 199 | incbin "sample1.brr" 200 | sample2: 201 | incbin "sample2.brr" 202 | sample3: 203 | incbin "sample3.brr" 204 | sample4: 205 | incbin "sample4.brr" 206 | sample5: 207 | incbin "sample5.brr" 208 | sample6: 209 | incbin "sample6.brr" 210 | sample7: 211 | incbin "sample7.brr" 212 | sample16: 213 | incbin "sample16.brr" 214 | sample17: 215 | incbin "sample17.brr" 216 | sample18: 217 | incbin "sample18.brr" 218 | sample19: 219 | incbin "sample19.brr" 220 | sample20: 221 | incbin "sample20.brr" 222 | sample21: 223 | incbin "sample21.brr" 224 | sample22: 225 | incbin "sample22.brr" 226 | sample23: 227 | incbin "sample23.brr" 228 | sample24: 229 | incbin "sample24.brr" 230 | sample25: 231 | incbin "sample25.brr" 232 | sample26: 233 | incbin "sample26.brr" 234 | sample27: 235 | incbin "sample27.brr" 236 | -------------------------------------------------------------------------------- /sound/sounds.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sounds.bin -------------------------------------------------------------------------------- /sound/sounds.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/sound/sounds.xm -------------------------------------------------------------------------------- /sound_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Bubble Zap Games 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | //sound test code 19 | 20 | void sound_test(void) 21 | { 22 | static unsigned int i,j,num,screen_bright,off,bright; 23 | static unsigned int sound,pan,music,done; 24 | static int cur; 25 | 26 | set_bright(0); 27 | setup_hdma_gradient(-1); 28 | oam_clear(); 29 | 30 | clear_nametables(); 31 | 32 | unrle(map,mape); 33 | 34 | for(i=0;i<32*32;++i) nametable1[i]=map[i]+0x0140|BG_PAL(1)|BG_PRI; 35 | 36 | set_background(1); 37 | 38 | put_str(&nametable1[POS(11,8)],"SOUND TEST"); 39 | 40 | put_str(&nametable1[POS(11,10)],"SOUND"); 41 | put_str(&nametable1[POS(11,11)],"PAN"); 42 | put_str(&nametable1[POS(11,12)],"MUSIC"); 43 | put_str(&nametable1[POS(11,13)],"VOLUME"); 44 | put_str(&nametable1[POS(11,14)],"EXIT"); 45 | 46 | put_str(&nametable1[POS(11,17)],versionStr); 47 | put_str(&nametable1[POS(17,17)],snes_ntsc?"NTSC":" PAL"); 48 | 49 | update_nametables(); 50 | setup_palettes(); 51 | update_palette(); 52 | 53 | setup_hdma_gradient(5); 54 | 55 | global_volume=120; 56 | 57 | spc_volume(global_volume); 58 | 59 | sound=0; 60 | pan=0x80; 61 | music=0; 62 | 63 | bright=0; 64 | cur=0; 65 | done=0; 66 | 67 | while(!done) 68 | { 69 | put_num(&nametable1[POS(19,10)],sound,2); 70 | put_num(&nametable1[POS(18,11)],pan ,3); 71 | put_num(&nametable1[POS(19,12)],music,2); 72 | put_num(&nametable1[POS(18,13)],global_volume,3); 73 | 74 | off=POS(9,10); 75 | 76 | for(i=0;i<5;++i) 77 | { 78 | nametable1[off]=(i==cur?TEXT_ATR|'@'-32:TEXT_ATR); 79 | off+=0x20; 80 | } 81 | 82 | nmi_wait(); 83 | 84 | copy_to_vram(POS(0,10),(const unsigned char*)&nametable1[POS(0,10)],512); 85 | 86 | if(bright<15) 87 | { 88 | ++bright; 89 | set_bright(bright); 90 | } 91 | 92 | pad_read_ports(); 93 | 94 | i=pad_poll_trigger(0); 95 | 96 | if(i&PAD_UP) 97 | { 98 | --cur; 99 | if(cur<0) cur=4; 100 | } 101 | 102 | if(i&PAD_DOWN) 103 | { 104 | ++cur; 105 | if(cur>4) cur=0; 106 | } 107 | 108 | if(i&PAD_LEFT) 109 | { 110 | switch(cur) 111 | { 112 | case 0: 113 | { 114 | --sound; 115 | if(sound>=SOUNDS_ALL) sound=SOUNDS_ALL-1; 116 | } 117 | break; 118 | 119 | case 1: 120 | { 121 | pan-=0x10; 122 | if(pan>0xff) pan=0; 123 | } 124 | break; 125 | 126 | case 2: 127 | { 128 | --music; 129 | if(music>=MUSIC_ALL) music=MUSIC_ALL-1; 130 | } 131 | break; 132 | 133 | case 3: 134 | { 135 | global_volume-=0x08; 136 | if(global_volume>0x7f) global_volume=0; 137 | spc_volume(global_volume); 138 | } 139 | break; 140 | } 141 | } 142 | 143 | if(i&PAD_RIGHT) 144 | { 145 | switch(cur) 146 | { 147 | case 0: 148 | { 149 | ++sound; 150 | if(sound>=SOUNDS_ALL) sound=0; 151 | } 152 | break; 153 | 154 | case 1: 155 | { 156 | pan+=0x10; 157 | if(pan>0xf0) pan=0xf0; 158 | } 159 | break; 160 | 161 | case 2: 162 | { 163 | ++music; 164 | if(music>=MUSIC_ALL) music=0; 165 | } 166 | break; 167 | 168 | case 3: 169 | { 170 | global_volume+=0x08; 171 | if(global_volume>0x78) global_volume=0x78; 172 | spc_volume(global_volume); 173 | } 174 | break; 175 | } 176 | } 177 | 178 | if(i&PAD_A) 179 | { 180 | switch(cur) 181 | { 182 | case 0: 183 | case 1: 184 | sfx_play(7,sound,pan); 185 | break; 186 | 187 | case 2: 188 | music_play(music); 189 | break; 190 | 191 | case 4: 192 | done=1; 193 | break; 194 | } 195 | } 196 | 197 | if(i&PAD_B) 198 | { 199 | music_stop(); 200 | 201 | if(cur==4) done=1; 202 | } 203 | 204 | ++game_frame_cnt; 205 | } 206 | 207 | fade_screen(0,1); 208 | } 209 | -------------------------------------------------------------------------------- /spc700.asm: -------------------------------------------------------------------------------- 1 | arch snes.smp 2 | 3 | 4 | define musicData $e000 ;fixed location for music data 5 | 6 | ;I/O registers 7 | 8 | define TEST $f0 9 | define CTRL $f1 10 | define ADDR $f2 11 | define DATA $f3 12 | define CPU0 $f4 13 | define CPU1 $f5 14 | define CPU2 $f6 15 | define CPU3 $f7 16 | define TMP0 $f8 17 | define TMP1 $f9 18 | define T0TG $fa 19 | define T1TG $fb 20 | define T2TG $fc 21 | define T0OT $fd 22 | define T1OT $fe 23 | define T2OT $ff 24 | 25 | ;DSP channel registers, x0..x9, x is channel number 26 | 27 | define DSP_VOLL $00 28 | define DSP_VOLR $01 29 | define DSP_PL $02 30 | define DSP_PH $03 31 | define DSP_SRCN $04 32 | define DSP_ADSR1 $05 33 | define DSP_ADSR2 $06 34 | define DSP_GAIN $07 35 | define DSP_ENVX $08 36 | define DSP_OUTX $09 37 | 38 | ;DSP registers for global settings 39 | 40 | define DSP_MVOLL $0c 41 | define DSP_MVOLR $1c 42 | define DSP_EVOLL $2c 43 | define DSP_EVOLR $3c 44 | define DSP_KON $4c 45 | define DSP_KOF $5c 46 | define DSP_FLG $6c 47 | define DSP_ENDX $7c 48 | define DSP_EFB $0d 49 | define DSP_PMON $2d 50 | define DSP_NON $3d 51 | define DSP_EON $4d 52 | define DSP_DIR $5d 53 | define DSP_ESA $6d 54 | define DSP_EDL $7d 55 | define DSP_C0 $0f 56 | define DSP_C1 $1f 57 | define DSP_C2 $2f 58 | define DSP_C3 $3f 59 | define DSP_C4 $4f 60 | define DSP_C5 $5f 61 | define DSP_C6 $6f 62 | define DSP_C7 $7f 63 | 64 | ;vars 65 | 66 | define D_TEMP $00 67 | 68 | define D_SYNC $08 69 | define D_BUFPTR $09 70 | define D_KON $0a 71 | define D_KOF $0b 72 | define D_STEREO $0c 73 | 74 | define M_ENABLE $10 ;byte 75 | define M_ROW $11 ;byte 76 | define M_ORDPTR_L $12 ;word 77 | define M_ORDPTR_H $13 78 | define M_ORDINC $14 ;byte 79 | define M_CHCUR0x $15 ;byte 80 | define M_CHCURx0 $16 ;byte 81 | define M_CHOFF $17 ;byte 82 | define M_UPDROW $18 ;byte 83 | define M_SPEED $19 ;byte 84 | 85 | define M_ORDBEGIN_L {musicData} 86 | define M_ORDBEGIN_H {musicData}+1 87 | define M_ORDLOOP_L {musicData}+2 88 | define M_ORDLOOP_H {musicData}+3 89 | define M_CHANNELS {musicData}+4 90 | define M_INITSPEED {musicData}+5 91 | define M_PATTERNS_L {musicData}+6 92 | define M_PATTERNS_H {musicData}+7 93 | 94 | define M_CHSIZE $0b ;11 bytes per channel 95 | 96 | define M_CH0 $20 97 | define M_CH1 {M_CH0}+{M_CHSIZE} 98 | define M_CH2 {M_CH1}+{M_CHSIZE} 99 | define M_CH3 {M_CH2}+{M_CHSIZE} 100 | define M_CH4 {M_CH3}+{M_CHSIZE} 101 | define M_CH5 {M_CH4}+{M_CHSIZE} 102 | define M_CH6 {M_CH5}+{M_CHSIZE} 103 | define M_CH7 {M_CH6}+{M_CHSIZE} 104 | 105 | define D_BUFFER $80 106 | 107 | ;offsets for music channel vars 108 | 109 | define CH_FRAME $00 110 | define CH_SPEED $01 111 | define CH_PTR_L $02 ;word 112 | define CH_PTR_H $03 113 | define CH_WAIT $04 ;byte 114 | define CH_VOL $05 ;byte 115 | define CH_PAN $06 ;byte 116 | define CH_NOTE $07 ;byte 117 | define CH_VIBOFF $08 ;byte 118 | define CH_VIBINC $09 ;byte 119 | define CH_VIBMUL $0a ;byte 120 | 121 | 122 | 123 | org 0 124 | base $0200 125 | 126 | 127 | 128 | start: 129 | clp 130 | 131 | ldx #0 132 | stx {D_KON} 133 | stx {D_KOF} 134 | stx {D_STEREO} 135 | stx {M_ENABLE} 136 | 137 | dex 138 | txs 139 | 140 | lda {CPU0} ;read current value of cpu0, it is used as strobe 141 | sta {D_SYNC} 142 | 143 | jsr bufClear 144 | 145 | setState: 146 | ldx #0 ;initialize registers 147 | .1: 148 | lda initDataSeq,x 149 | beq .2 150 | sta {ADDR} 151 | inx 152 | lda initDataSeq,x 153 | sta {DATA} 154 | inx 155 | bra .1 156 | .2: 157 | 158 | lda #(8000/100) ;8000/80=100hz 159 | sta {T0TG} 160 | lda #$81 ;enable timer 0 and IPL 161 | sta {CTRL} 162 | 163 | mainLoop: 164 | 165 | waitForTimer: 166 | jsr checkCommand 167 | lda {T0OT} 168 | beq waitForTimer 169 | 170 | jsr updatePlayer 171 | 172 | bra mainLoop 173 | 174 | 175 | 176 | checkCommand: 177 | lda {CPU0} ;wait until cpu0 is changed 178 | cmp {D_SYNC} 179 | bne .read 180 | rts 181 | .read: 182 | sta {D_SYNC} ;remember for next time 183 | sta {CPU0} ;confirm strobe 184 | 185 | lda {CPU1} ;read command code 186 | pha 187 | and #$0f 188 | tay ;channel for sound effect commands 189 | pla 190 | lsr 191 | lsr 192 | lsr 193 | and #$0e 194 | tax 195 | jmp (cmdList,x) 196 | 197 | 198 | 199 | cmdStereo: 200 | lda {CPU2} 201 | sta {D_STEREO} 202 | rts 203 | 204 | 205 | cmdVolume: 206 | lda {CPU2} 207 | ldx #{DSP_MVOLL} 208 | stx {ADDR} 209 | sta {DATA} 210 | ldx #{DSP_MVOLR} 211 | stx {ADDR} 212 | sta {DATA} 213 | rts 214 | 215 | 216 | cmdMusStop: 217 | jsr bufClear 218 | 219 | ldx #0 220 | stx {M_ENABLE} 221 | 222 | .mute: 223 | jsr keyOffBuf 224 | inx 225 | cpx {M_CHANNELS} 226 | bne .mute 227 | 228 | lda {D_KOF} 229 | eor #$ff 230 | and {D_KON} 231 | sta {D_KON} 232 | 233 | jmp keyOffApply 234 | 235 | 236 | cmdMusPlay: 237 | lda #1 238 | sta {M_ENABLE} 239 | jmp musicInit 240 | 241 | 242 | cmdSfxPlay: 243 | cpy {M_CHANNELS} ;don't play effects on music channels 244 | bcs .play 245 | rts 246 | .play: 247 | lda #{M_CHSIZE} ;get channel offset 248 | mul 249 | clc 250 | adc #{M_CH0} 251 | tax 252 | 253 | lda {CPU2} 254 | asl 255 | tay 256 | 257 | lda soundData,y 258 | clc 259 | adc #soundData&255 260 | sta {CH_PTR_L},x 261 | lda soundData+1,y 262 | adc #soundData/256 263 | sta {CH_PTR_H},x 264 | lda #0 265 | sta {CH_WAIT},x 266 | sta {CH_NOTE},x 267 | sta {CH_VIBMUL},x 268 | sta {CH_VIBINC},x 269 | sta {CH_FRAME},x 270 | lda #6 271 | sta {CH_SPEED},x 272 | lda {CPU3} 273 | sta {CH_PAN},x 274 | lda #$3f 275 | sta {CH_VOL},x 276 | 277 | rts 278 | 279 | 280 | cmdReload: 281 | jmp $ffc0 282 | 283 | 284 | 285 | ;reads variables from music data (it is at fixed location) 286 | ;reset channels variables 287 | 288 | musicInit: 289 | ldy {M_CHANNELS} ;get order pos width from music data, it is channels+1 290 | sty {M_ORDINC} 291 | inc {M_ORDINC} 292 | 293 | lda {M_ORDBEGIN_L} ;get initial order list pointer 294 | clc 295 | adc #{musicData}&255 296 | sta {M_ORDPTR_L} 297 | lda {M_ORDBEGIN_H} 298 | adc #{musicData}/256 299 | sta {M_ORDPTR_H} 300 | 301 | ldx #{M_CH0} ;initialize channels vars 302 | .set: 303 | lda #0 304 | sta {CH_WAIT},x 305 | sta {CH_NOTE},x 306 | sta {CH_VIBMUL},x 307 | sta {CH_VIBINC},x 308 | sta {CH_FRAME},x ;reset frame counter 309 | sta {CH_SPEED},x ;disable channel 310 | lda #$80 311 | sta {CH_PAN},x 312 | lda #$3f 313 | sta {CH_VOL},x 314 | 315 | txa 316 | clc 317 | adc #{M_CHSIZE} 318 | tax 319 | 320 | dey 321 | bne .set 322 | 323 | lda #$ff ;keyoff for all the channels 324 | sta {D_KOF} 325 | lda #0 ;reset frame counter 326 | sta {D_KON} 327 | lda {M_INITSPEED} ;set initial speed 328 | sta {M_SPEED} 329 | 330 | ;rts ;no rts because jsr musicUpdateOrder is needed for init 331 | 332 | 333 | 334 | ;move to the next order list position 335 | 336 | define T_CHCNT $00 337 | 338 | updateOrder: 339 | lda {M_CHANNELS} ;read pattern pointers into channels vars 340 | sta {T_CHCNT} 341 | ldy #0 342 | lda #{M_CH0} 343 | sta {M_CHOFF} 344 | .read: 345 | lda ({M_ORDPTR_L}),y 346 | iny 347 | 348 | asl 349 | tax 350 | lda {M_PATTERNS_L},x 351 | clc 352 | adc #{musicData}&255 353 | pha 354 | lda {M_PATTERNS_H},x 355 | adc #{musicData}/256 356 | ldx {M_CHOFF} 357 | sta {CH_PTR_H},x 358 | pla 359 | sta {CH_PTR_L},x 360 | 361 | txa 362 | clc 363 | adc #{M_CHSIZE} 364 | sta {M_CHOFF} 365 | 366 | dec {T_CHCNT} 367 | bne .read 368 | 369 | lda ({M_ORDPTR_L}),y;read order position length 370 | sta {M_ROW} 371 | iny 372 | 373 | lda ({M_ORDPTR_L}),y;check if next position is end of the order list 374 | cmp #$ff 375 | bne .next 376 | 377 | lda {M_ORDLOOP_L} ;load loop position 378 | clc 379 | adc #{musicData}&255 380 | sta {M_ORDPTR_L} 381 | lda {M_ORDLOOP_H} 382 | adc #{musicData}/256 383 | sta {M_ORDPTR_H} 384 | rts 385 | 386 | .next: 387 | clc ;move to the next position 388 | lda {M_ORDPTR_L} 389 | adc {M_ORDINC} 390 | sta {M_ORDPTR_L} 391 | lda {M_ORDPTR_H} 392 | adc #0 393 | sta {M_ORDPTR_H} 394 | 395 | rts 396 | 397 | 398 | 399 | ;run one frame of music player 400 | 401 | updatePlayer: 402 | jsr bufApply ;apply register writes from previous frame 403 | jsr keyOnApply ;apply keyon from previous frame 404 | 405 | lda #0 ;process all the channels, some of them for music, some for sound 406 | sta {M_CHCUR0x} 407 | sta {M_CHCURx0} 408 | sta {M_UPDROW} 409 | lda #{M_CH0} 410 | sta {M_CHOFF} 411 | 412 | .loop: 413 | jsr updateChannel 414 | 415 | lda {M_CHOFF} 416 | clc 417 | adc #{M_CHSIZE} 418 | sta {M_CHOFF} 419 | 420 | lda {M_CHCURx0} 421 | clc 422 | adc #$10 423 | sta {M_CHCURx0} 424 | 425 | inc {M_CHCUR0x} 426 | lda {M_CHCUR0x} 427 | cmp #8 428 | bne .loop 429 | 430 | jsr keyOffApply ;apply keyoff, it always one frame earlier 431 | 432 | lda {M_UPDROW} 433 | beq .noRow 434 | dec {M_ROW} 435 | bne .noRow 436 | jsr updateOrder 437 | .noRow: 438 | rts 439 | 440 | 441 | 442 | ;update one channel 443 | 444 | define T_PTNPTR_L $00 ;word 445 | define T_PTNPTR_H $01 446 | define T_CHVOLL $02 447 | define T_CHVOLR $03 448 | define T_PITCH_OFF_L $04 449 | define T_PITCH_OFF_H $05 450 | 451 | updateChannel: 452 | ldx {M_CHOFF} 453 | lda {M_CHCUR0x} 454 | cmp {M_CHANNELS} 455 | bcc .checkMus 456 | lda {CH_SPEED},x ;if speed is 0, channel is inactive 457 | bne .active 458 | rts 459 | .checkMus: 460 | lda {M_ENABLE} 461 | bne .active 462 | rts 463 | .active: 464 | lda {CH_FRAME},x 465 | beq .row 466 | jmp .processVolume 467 | 468 | .row: 469 | lda {CH_WAIT},x 470 | beq .noWait 471 | dec {CH_WAIT},x 472 | jmp .processVolume 473 | 474 | .noWait: 475 | lda {CH_PTR_H},x 476 | sta {T_PTNPTR_H} 477 | lda {CH_PTR_L},x 478 | sta {T_PTNPTR_L} 479 | 480 | .read: 481 | jsr readPtnByte 482 | tay 483 | and #$c0 484 | 485 | beq .empty 486 | cmp #$40 487 | beq .volume 488 | cmp #$80 489 | beq .ins 490 | .note: 491 | tya 492 | cmp #$fc 493 | bcs .effect 494 | 495 | and #$3f ;it is a note, remember it 496 | asl 497 | ldx {M_CHOFF} 498 | sta {CH_NOTE},x 499 | lda #0 500 | sta {CH_VIBOFF},x 501 | 502 | ldx {M_CHCUR0x} ;keyoff and keyon 503 | jsr keyOffBuf 504 | jsr keyOnBuf 505 | 506 | jmp .done 507 | 508 | .effect: 509 | cmp #$fc 510 | bne .noPitch 511 | 512 | jsr readPtnByte ;it is a pitch change without restarting note 513 | and #$3f 514 | asl 515 | ldx {M_CHOFF} 516 | sta {CH_NOTE},x 517 | 518 | bra .done 519 | 520 | .noPitch: 521 | cmp #$fd 522 | bne .noStop 523 | ldx {M_CHCUR0x} ;it is note cut 524 | jsr keyOffBuf 525 | bra .done 526 | 527 | .noStop: 528 | cmp #$fe 529 | bne .noPan 530 | jsr readPtnByte ;it is pan, next byte is value 531 | ldx {M_CHOFF} 532 | sta {CH_PAN},x 533 | bra .read 534 | 535 | .noPan: 536 | jsr readPtnByte ;it is speed, next byte is value 537 | ldx {M_CHCUR0x} 538 | cpx {M_CHANNELS} 539 | bcs .setSpeed 540 | sta {M_SPEED} 541 | bra .read 542 | 543 | .setSpeed: 544 | ldx {M_CHOFF} 545 | sta {CH_SPEED},x 546 | cmp #0 547 | bne .read 548 | lda {M_CHCUR0x} 549 | jmp keyOffBuf 550 | 551 | .empty: 552 | ldx {M_CHOFF} 553 | sty {CH_WAIT},x 554 | bra .done 555 | 556 | .volume: 557 | tya 558 | and #$3f 559 | asl 560 | ldx {M_CHOFF} 561 | sta {CH_VOL},x 562 | bra .read 563 | 564 | .ins: 565 | tya 566 | and #$3f 567 | pha 568 | 569 | lda {M_CHCURx0} 570 | ora #{DSP_SRCN} 571 | tax 572 | pla 573 | jsr bufWrite ;write instrument number 574 | 575 | asl ;get offset for parameter tables 576 | tax 577 | 578 | lda vibrato+1,x ;get vibrato parameters 579 | pha 580 | lda vibrato,x 581 | pha 582 | lda adsr+1,x ;get adsr parameters 583 | pha 584 | lda adsr,x 585 | pha 586 | 587 | lda {M_CHCURx0} ;write adsr parameters 588 | ora #{DSP_ADSR1} 589 | tax 590 | pla 591 | jsr bufWrite 592 | lda {M_CHCURx0} 593 | ora #{DSP_ADSR2} 594 | tax 595 | pla 596 | jsr bufWrite 597 | 598 | ldx {M_CHOFF} ;write vibrato parameters 599 | pla 600 | sta {CH_VIBINC},x 601 | pla 602 | sta {CH_VIBMUL},x 603 | 604 | jmp .read 605 | 606 | .done: 607 | ldx {M_CHOFF} 608 | lda {T_PTNPTR_L} 609 | sta {CH_PTR_L},x 610 | lda {T_PTNPTR_H} 611 | sta {CH_PTR_H},x 612 | 613 | .processVolume: 614 | lda {D_STEREO} 615 | beq .mono 616 | .stereo: 617 | lda {CH_PAN},x ;calculate left volume 618 | eor #$ff 619 | tay 620 | lda {CH_VOL},x 621 | mul 622 | sty {T_CHVOLL} 623 | ldy {CH_PAN},x ;calculate right volume 624 | lda {CH_VOL},x 625 | mul 626 | sty {T_CHVOLR} 627 | bra .setVol 628 | 629 | .mono: 630 | lda {CH_VOL},x 631 | sta {T_CHVOLL} 632 | sta {T_CHVOLR} 633 | 634 | .setVol: 635 | lda {M_CHCURx0} 636 | ora #{DSP_VOLL} 637 | tax 638 | lda {T_CHVOLL} 639 | jsr bufWrite 640 | lda {M_CHCURx0} 641 | ora #{DSP_VOLR} 642 | tax 643 | lda {T_CHVOLR} 644 | jsr bufWrite 645 | 646 | .processPitch: 647 | ldx {M_CHOFF} 648 | 649 | lda {CH_VIBOFF},x 650 | ldy {CH_VIBMUL},x 651 | tax 652 | lda vibratoTable,x 653 | mul 654 | sty {T_PITCH_OFF_L} 655 | lda #0 656 | sta {T_PITCH_OFF_H} 657 | asl {T_PITCH_OFF_L} 658 | rol {T_PITCH_OFF_H} 659 | asl {T_PITCH_OFF_L} 660 | rol {T_PITCH_OFF_H} 661 | 662 | ldx {M_CHOFF} 663 | lda {CH_NOTE},x 664 | tax 665 | lda divTable,x 666 | clc 667 | adc {T_PITCH_OFF_L} 668 | pha 669 | lda divTable+1,x 670 | adc {T_PITCH_OFF_H} 671 | pha 672 | lda {M_CHCURx0} 673 | ora #{DSP_PH} 674 | tax 675 | pla 676 | jsr bufWrite 677 | lda {M_CHCURx0} 678 | ora #{DSP_PL} 679 | tax 680 | pla 681 | jsr bufWrite 682 | 683 | ldx {M_CHOFF} 684 | lda {CH_VIBOFF},x ;advance vibrato table pointer 685 | clc 686 | adc {CH_VIBINC},x 687 | sta {CH_VIBOFF},x 688 | 689 | .processFrameRow: 690 | lda {CH_FRAME},x 691 | bne .noRow 692 | lda {M_CHCUR0x} 693 | cmp {M_CHANNELS} 694 | bcc .processMus 695 | lda {CH_SPEED},x 696 | sta {CH_FRAME},x 697 | bra .noRow 698 | 699 | .processMus: 700 | lda {M_SPEED} 701 | sta {CH_FRAME},x 702 | lda #1 703 | sta {M_UPDROW} 704 | 705 | .noRow: 706 | dec {CH_FRAME},x 707 | rts 708 | 709 | 710 | 711 | ;read one byte from pattern data 712 | ;out: A=data, Y=0 713 | 714 | readPtnByte: 715 | ldy #0 716 | lda ({T_PTNPTR_L}),y 717 | inc {T_PTNPTR_L} 718 | bne .1 719 | inc {T_PTNPTR_H} 720 | .1: 721 | rts 722 | 723 | 724 | 725 | ;clear register writes buffer, just set ptr to 0 726 | 727 | bufClear: 728 | str {D_BUFPTR}=#0 729 | rts 730 | 731 | 732 | 733 | ;add register write in buffer 734 | ;in X=reg, A=value 735 | 736 | bufWrite: 737 | pha 738 | txa 739 | ldx {D_BUFPTR} 740 | sta {D_BUFFER},x 741 | inx 742 | pla 743 | sta {D_BUFFER},x 744 | inx 745 | stx {D_BUFPTR} 746 | rts 747 | 748 | 749 | 750 | ;send writes from buffer and clear it 751 | 752 | bufApply: 753 | lda {D_BUFPTR} 754 | beq .done 755 | ldx #0 756 | .loop: 757 | lda {D_BUFFER},x 758 | sta {ADDR} 759 | inx 760 | lda {D_BUFFER},x 761 | sta {DATA} 762 | inx 763 | cpx {D_BUFPTR} 764 | bne .loop 765 | str {D_BUFPTR}=#0 766 | .done: 767 | rts 768 | 769 | 770 | 771 | ;set keyon for needed channel in temp variable 772 | ;in: X=channel 773 | 774 | keyOnBuf: 775 | lda channelMask,x 776 | ora {D_KON} 777 | sta {D_KON} 778 | rts 779 | 780 | 781 | 782 | ;send keyon from temp variable 783 | 784 | keyOnApply: 785 | lda {D_KON} 786 | eor #$ff 787 | and {D_KOF} 788 | ldx #{DSP_KOF} 789 | stx {ADDR} 790 | sta {DATA} 791 | sta {D_KOF} 792 | 793 | lda #{DSP_KON} 794 | sta {ADDR} 795 | lda {D_KON} 796 | str {D_KON}=#0 797 | sta {DATA} 798 | 799 | rts 800 | 801 | 802 | 803 | ;set keyoff for needed channel in temp variable 804 | ;in: X=channel 805 | 806 | keyOffBuf: 807 | lda channelMask,x 808 | ora {D_KOF} 809 | sta {D_KOF} 810 | rts 811 | 812 | 813 | 814 | ;send keyoff from temp variable 815 | 816 | keyOffApply: 817 | lda #{DSP_KOF} 818 | sta {ADDR} 819 | lda {D_KOF} 820 | sta {DATA} 821 | rts 822 | 823 | 824 | 825 | cmdList: 826 | dw cmdStereo ;0 set stereo mode, 0 or 1 827 | dw cmdVolume ;1 set global volume, 0..127 828 | dw cmdMusStop ;2 stops music 829 | dw cmdMusPlay ;3 restarts music 830 | dw cmdSfxPlay ;4 play sound effect, number 0..127 and pan 0..255 831 | dw cmdReload ;5 call IPL 832 | 833 | 834 | divTable: 835 | dw $0217,$0237,$0259,$027d,$02a3,$02cb,$02f5,$0322 836 | dw $0352,$0385,$03ba,$03f3,$042f,$046f,$04b2,$04fa 837 | dw $0546,$0596,$05eb,$0645,$06a5,$070a,$0775,$07e6 838 | dw $085f,$08de,$0965,$09f4,$0a8c,$0b2c,$0bd6,$0c8b 839 | dw $0d4a,$0e14,$0eea,$0fcd,$10be,$11bd,$12cb,$13e9 840 | dw $1518,$1659,$17ad,$1916,$1a94,$1c28,$1dd5,$1f9b 841 | dw $217c,$237a,$2596,$27d2,$2a31,$2cb3,$2f5b,$322c 842 | dw $3528,$3851,$3bab,$3f37,$0000,$0000,$0000,$0000 843 | 844 | 845 | vibratoTable: 846 | db $00,$01,$03,$04,$06,$07,$09,$0a,$0c,$0d,$0f,$11,$12,$14,$15,$17 847 | db $18,$1a,$1b,$1d,$1e,$20,$21,$23,$24,$26,$27,$29,$2a,$2c,$2d,$2f 848 | db $30,$32,$33,$34,$36,$37,$39,$3a,$3b,$3d,$3e,$3f,$41,$42,$43,$45 849 | db $46,$47,$49,$4a,$4b,$4c,$4e,$4f,$50,$51,$52,$54,$55,$56,$57,$58 850 | db $59,$5a,$5b,$5d,$5e,$5f,$60,$61,$62,$63,$64,$65,$66,$66,$67,$68 851 | db $69,$6a,$6b,$6c,$6c,$6d,$6e,$6f,$70,$70,$71,$72,$72,$73,$74,$74 852 | db $75,$75,$76,$77,$77,$78,$78,$79,$79,$79,$7a,$7a,$7b,$7b,$7b,$7c 853 | db $7c,$7c,$7d,$7d,$7d,$7d,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e 854 | db $7f,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7d,$7d,$7d,$7d,$7c 855 | db $7c,$7c,$7b,$7b,$7b,$7a,$7a,$79,$79,$79,$78,$78,$77,$77,$76,$75 856 | db $75,$74,$74,$73,$72,$72,$71,$70,$70,$6f,$6e,$6d,$6c,$6c,$6b,$6a 857 | db $69,$68,$67,$66,$66,$65,$64,$63,$62,$61,$60,$5f,$5e,$5d,$5b,$5a 858 | db $59,$58,$57,$56,$55,$54,$52,$51,$50,$4f,$4e,$4c,$4b,$4a,$49,$47 859 | db $46,$45,$43,$42,$41,$3f,$3e,$3d,$3b,$3a,$39,$37,$36,$34,$33,$32 860 | db $30,$2f,$2d,$2c,$2a,$29,$27,$26,$24,$23,$21,$20,$1e,$1d,$1b,$1a 861 | db $18,$17,$15,$14,$12,$11,$0f,$0d,$0c,$0a,$09,$07,$06,$04,$03,$01 862 | 863 | 864 | channelMask: 865 | db $01,$02,$04,$08,$10,$20,$40,$80 866 | 867 | 868 | initDataSeq: 869 | db {DSP_FLG} ,%01100000;mute, no echo 870 | db {DSP_PMON} ,0 ;no pitch modulation 871 | db {DSP_NON} ,0 ;no noise 872 | db {DSP_EON} ,0 ;no echo 873 | db {DSP_ESA} ,255 ;echo at highest page 874 | db {DSP_EDL} ,0 ;minimal length 875 | db {DSP_DIR} ,(dir>>8) ;address of sample dir 876 | db {DSP_MVOLL},127 ;global volume to the max 877 | db {DSP_MVOLR},127 878 | db {DSP_EVOLL},0 ;echo volume to zero 879 | db {DSP_EVOLR},0 880 | db {DSP_FLG} ,%00100000;no mute, no echo 881 | db {DSP_KOF} ,255 ;all keys off 882 | db 0 883 | 884 | 885 | ;macro for samples 886 | 887 | macro sample ptr,loop 888 | dw {ptr} 889 | dw {ptr}+{loop} 890 | endmacro 891 | 892 | macro adsr ar,dr,sl,sr 893 | db $80|{ar}|({dr}<<4) 894 | db {sr}|({sl}<<5) 895 | endmacro 896 | 897 | macro vib speed,depth 898 | db {speed} 899 | db {depth} 900 | endmacro 901 | 902 | 903 | 904 | org $0600 ;$0800 in memory 905 | incsrc "sound\samples.asm" 906 | 907 | soundData: 908 | incbin "sound\sounds.bin" -------------------------------------------------------------------------------- /spc700.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathancassano/classickong/6ee8707fba0f54391794537d9116898d4c9a6721/spc700.bin -------------------------------------------------------------------------------- /spccmd.h: -------------------------------------------------------------------------------- 1 | //sound variables 2 | 3 | static unsigned char snes_spc_sync; 4 | static unsigned int snes_spc_stereo; 5 | static unsigned int snes_spc_volume; 6 | 7 | //APU registers 8 | 9 | #define APU0(x) *((unsigned char*)0x2140)=(x); 10 | #define APU1(x) *((unsigned char*)0x2141)=(x); 11 | #define APU2(x) *((unsigned char*)0x2142)=(x); 12 | #define APU3(x) *((unsigned char*)0x2143)=(x); 13 | #define APU01(x) *((unsigned int*)0x2140)=(x); 14 | #define APU23(x) *((unsigned int*)0x2142)=(x); 15 | 16 | #define APU0RD *((unsigned char*)0x2140) 17 | #define APU1RD *((unsigned char*)0x2141) 18 | #define APU2RD *((unsigned char*)0x2142) 19 | #define APU3RD *((unsigned char*)0x2143) 20 | #define APU01RD *((unsigned int*)0x2140) 21 | #define APU23RD *((unsigned int*)0x2142) 22 | 23 | //command codes 24 | 25 | #define SCMD_STEREO 0x0000 //change stereo sound mode 26 | #define SCMD_VOLUME 0x1000 //set global volume 27 | #define SCMD_MUSIC_STOP 0x2000 //stop music 28 | #define SCMD_MUSIC_PLAY 0x3000 //start music 29 | #define SCMD_SFX_PLAY 0x4000 //play sound effect 30 | #define SCMD_RELOAD 0x5000 //load new music dara 31 | 32 | //command aliases 33 | 34 | #define spc_music_stop() (spc_command(SCMD_MUSIC_STOP,0)) 35 | #define spc_music_play() (spc_command(SCMD_MUSIC_PLAY,0)) 36 | #define spc_sfx_play(chn,x,pan) (spc_command(SCMD_SFX_PLAY|((chn)<<8),(x)|((pan)<<8))) 37 | #define spc_reload() (spc_command(SCMD_RELOAD,0)) 38 | 39 | 40 | 41 | #ifdef SOUND_DISABLE 42 | 43 | void spc_command(unsigned int command,unsigned int param) {} 44 | void spc_stereo(unsigned int stereo) {} 45 | void spc_volume(unsigned int volume) {} 46 | void spc_load_data(unsigned int adr,const unsigned char *src,unsigned int size) {} 47 | void spc_setup(void) {} 48 | void spc_load_music(const unsigned char *data,unsigned int size) {} 49 | 50 | #else 51 | 52 | //send a command to the SPC driver 53 | 54 | void spc_command(unsigned int command,unsigned int param) 55 | { 56 | APU01(command|snes_spc_sync); 57 | APU23(param); 58 | 59 | if(command!=SCMD_RELOAD) 60 | { 61 | while(APU0RD!=snes_spc_sync); 62 | ++snes_spc_sync; 63 | } 64 | } 65 | 66 | 67 | 68 | //change stereo sound mode 69 | 70 | void spc_stereo(unsigned int stereo) 71 | { 72 | snes_spc_stereo=stereo; 73 | spc_command(SCMD_STEREO,stereo); 74 | } 75 | 76 | 77 | 78 | //set global sound volume 79 | 80 | void spc_volume(unsigned int volume) 81 | { 82 | if(volume>127) volume=127; 83 | snes_spc_volume=volume; 84 | spc_command(SCMD_VOLUME,volume); 85 | } 86 | 87 | 88 | 89 | //upload data into the sound memory using IPL loader 90 | 91 | void spc_load_data(unsigned int adr,const unsigned char *src,unsigned int size) 92 | { 93 | static unsigned char cnt; 94 | static unsigned int i; 95 | 96 | NMITIMEEN(0); 97 | 98 | while(APU01RD!=0xbbaa);//apu ready? 99 | 100 | APU23(adr);//set location 101 | APU1(1);//not last block 102 | APU0(0xcc); 103 | 104 | while(APU0RD!=0xcc);//ready? 105 | 106 | cnt=0; 107 | 108 | while(size) 109 | { 110 | APU1(*src++); 111 | APU0(cnt); 112 | 113 | while(APU0RD!=cnt);//ready? 114 | ++cnt; 115 | --size; 116 | } 117 | 118 | APU23(0x0200);//startup address 119 | APU1(0);//run apu code 120 | APU0(cnt+2); 121 | 122 | snes_spc_sync=cnt; 123 | 124 | NMITIMEEN(0x81); 125 | nmi_wait(); 126 | } 127 | 128 | 129 | 130 | //initialize sound, set variables and upload driver code 131 | 132 | void spc_setup(void) 133 | { 134 | snes_spc_stereo=0; 135 | snes_spc_volume=127; 136 | 137 | spc_load_data(0x0200,spc700_data,spc700_size); 138 | } 139 | 140 | 141 | 142 | //upload music data 143 | 144 | void spc_load_music(const unsigned char *data,unsigned int size) 145 | { 146 | spc_reload(); 147 | spc_load_data(0xe000,data,size); 148 | spc_stereo(snes_spc_stereo); 149 | spc_volume(snes_spc_volume); 150 | } 151 | 152 | #endif -------------------------------------------------------------------------------- /title_screen.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2012 Bubble Zap Games 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | */ 18 | 19 | //title screen code 20 | 21 | 22 | //display or hide press start message 23 | 24 | void title_screen_press_start_str(unsigned char show) 25 | { 26 | put_str(&nametable1[POS(10,22)],show?"PRESS START":" "); 27 | } 28 | 29 | 30 | 31 | //update nametable 32 | 33 | void title_screen_update(void) 34 | { 35 | copy_to_vram(0x0000,(unsigned char*)nametable1,32*32*2); 36 | } 37 | 38 | 39 | 40 | //fill a rectangle in the nametable 41 | 42 | void title_set_rect(unsigned int off,unsigned char wdt,unsigned char hgt,unsigned int tile,unsigned char swdt) 43 | { 44 | static unsigned char i,j; 45 | 46 | for(i=0;i