Path: chuka.playstation.co.uk!news From: alex@teeth.demon.co.uk (Alex Amsel) Newsgroups: scee.yaroze.programming.gnu_compiler Subject: Maybe useful titbits + memory notes + give us more work if you love us really Date: Wed, 20 Aug 1997 15:10:00 GMT Organization: Into Beyond Lines: 367 Message-ID: <33fdfd81.2876030@news.playstation.co.uk> References: <33F2851D.2FD1@cobradev.demon.co.uk> Reply-To: alex@teeth.demon.co.uk NNTP-Posting-Host: teeth.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Newsreader: Forte Agent .99g/32.335 This email is pretty big and has various examples at the bottom...read on.. On Wed, 13 Aug 1997 21:10:05 -0700, colin adams did quoth at me: >I have game data loaded in memory regions-: >1. 80090000 - 800e86cb. tmds, sound, map-data. >2. 80190000 - 801fd9fb. tmds. I can only tell you how my code works.... Code starts at 80090000 rather than 80100000. From the info printed you can see how the various code sections are allocated. Also create a mapfile to see exactly how far your BSS variables go into memory. By organising the linking order so that your Primitive memory is last in the list, you can allow for a few memory overruns to a certain extent (well, rather uncertain due to primitive memory being double buffered, but better than nothing). You should be able to download data to any part of ram above 80090000 but you obviously don't want to conflict with your data segments. The stack starts from 801fff00 I think, and goes down. I use a macro to print the current stack value at the start of certain functions, but I don't ever use much stack. volatile long r28, r29, r30; #define PrintRegs \ __asm__ volatile ("usw $28, r28"); \ __asm__ volatile ("usw $29, r29"); \ __asm__ volatile ("usw $30, r30"); \ D(logf("\n%-11s %04d Reg: GP:0x%08x SP:0x%08x FP:0x%08x\n\n", __FILE__, __LINE__, r28, r29, r30)); ...where D(logf)) is part of my debug code, but is effectively printf. Remember to remove the 2nd bracket at the end if you just use printf ! [this could probably be done better, but hell, if works] GP = global pointer SP = stack pointer FP = frame pointer When dling an exec to the Yaroze the basic info is printed anyway, but I had some problems to wanted to verify a few things. Another useful thing to do is to fill all unused memory with e.g. 0x0badf00d, and at various points in your code (esp. exit) you should verify that memory still contains this value. If it doesn't then you have either: a) Overwritten parts of memory you shouldn't have or b) Accidently filled memory that is bart of your BSS or data segments. The Amiga had a great program called mungwall for this. If you are using malloc for memory requests I suggest writing several wrapper functions to deal with memory handling. My memory handlers, as well as handling multiple memory types (both hardware types and software types), also have optional debug variations. They automatcially generate both checksums and prerun/overrun checking data, and this data is verified during all memory operations. Apart from anything else, good memory handlers allow you to bulk return all your e.g. TMD ram in one go. When allocating ram, I can say it is for TMD objects, sound objects,. 3d data, etc. I can then either return data individually, in which case I can request an error to be given if that memory isn't allocated, or I can just return all memory allocated to that type in one call. Easy way of keeping track of things! Finally, it also keeps logging information on memory requests and so on. Some useful bits... From my makefile: some is a little hacked as I kept having probs with the linker as a separate module, and I'm also close to some linking limits. version = normal compiler = gcc ccoptions_normal = -w -c ccoptions_debug = -w -g -DDEBUG -DASSERT_ON -c ccoptions_optimise = -w -O2 -UDEBUG -UASSERT_ON -DOPTIMISE -c ccoptions = $(ccoptions_$(version)) linker = gcc linkoptions_normal = -Xlinker -Ttext -Xlinker 80090000 -Xlinker -Map -Xlinker map.txt linkoptions_debug = -Xlinker -Ttext -Xlinker 80090000 -Xlinker -Map -Xlinker map.txt linkoptions_optimise = -Xlinker -Ttext -Xlinker 80090000 -Xlinker -Map -Xlinker map.txt linkoptions = $(linkoptions_$(version)) # 3d.o should always be last in this list objects = pad.o vb_int.o sincos.o system.o level.o player.o sound.o effects.o game.o menu.o col.o sfx.o 3d.o base_headers = global.h types.h debug.h psxdefs.h abyss.h main: main.o $(objects) $(linker) $(linkoptions) $< $(objects) -o $@ vb_int.o: vb_int.c vb_int.h types.h psxdefs.h $(compiler) $(ccoptions_normal) $< .c.o: $(compiler) $(ccoptions) $< main.o: main.c $(base_headers) game.h system.h system.o: system.c $(base_headers) system.h level.h sound.h pad.h vb_int.h sfx.h etc. From the MAP.TXT file: by linking 3d.o last I can ensure my PacketArea is the last thing is my list. This is the very bottom of my MAP file generating by the linker, and shows me where I can start downloading data via our dumpaddress tool (see the website). 800bd0e0 PacketArea 801323e0 801323e0 end =. 801323e0 801323e0 _end =. OUTPUT(main ecoff-littlemips) From the dumpaddress config file: this makes life simple for placing data in the ps-x ram. Dumpaddress uses the config file to create dumpaddr.h and an AUTO batch file. In fact our 3ds scene converter generates texture size information so I don't need most of these labels. The dumpaddr program also allows you to enter any SIOCONS command into the AUTO file incidently. ALIGN LONG BASE 0x80140000 FILE X:\yaroze\projects\m\sounds\mlsnds.vh SFX_H FILE X:\yaroze\projects\m\sounds\mlsnds.vb SFX_B DEFINE TEXTURESTART_ADDR FILE X:\yaroze\projects\m\cestib\wood.tim TEXT_WOOD FILE X:\yaroze\projects\m\cestib\rain.tim TEXT_TIM etc. FILE X:\yaroze\projects\m\cestib\cestib.scn SCNE EXE main BATCH go From our 3ds file converter/scene editor: it stores all sorts of additional properties - note the very readable ASCII internal save format. This makes errors very easy to find, and even adjust. See the logfile notes below. Note we support some ps-x options like transparency through some appropriately selected 3DS4 option. SceneName Ultimate Wibbly Flibble SceneExtBackgroundColour 0x8c8159 SceneExtEnvDisplacement 60,102,140,20 SceneExtPlayer 4096,155648,11,-409,136 SceneExtStart -7500,0,-149,3072,0,0 SceneExtAmbient 3248,3248,3048,3072,3072,3072,256 SceneExtFog 0,-5039,19565822 SceneExtFogColour 0x000000 SceneExtLevel pickupicon.tim,50 MaterialName CONSTRUCT TREE MaterialType FLAT TEXTURE MaterialFlags FACEMAP TRANSPARENCY MaterialColour 0x000000 MaterialTransparency 1 MaterialTexture WOOD.BMP etc. [this is an animated texture] MaterialName SCREEN 01 MaterialType FLAT TEXTURE MaterialColour 0x000000 MaterialTexture BOB0001.BMP MaterialTexture BOB0002.BMP MaterialTexture BOB0003.BMP MaterialTexture BOB0004.BMP MaterialTexture BOB0005.BMP MaterialTexture BOB0006.BMP MaterialExtFrameRate 8 etc. ObjectName Object.gnd ObjectTranslation -437.472015,3169.653076,750.883423 ObjectNoVertices 21 ObjectNoNormals 21 ObjectNoPolygons 16 Vertex -1052.439087,-976.793701,0.000000 etc. Normal 0.000000,0.000000,1.000000 etc. Polygon 19,17,20,19,15,17,OBJECT FLOOR,0.500000,0.999509,0.000000,0.999507,0.500000,0.499509 etc. ObjectExtFlags GROUND ObjectExtSubDivision 3 ObjectExtSubDistance 500 ObjectExtScaling 1.010000 etc. PathName Lighting Path 1 PathType LIGHTING PathExtLighting 0,0 PathNoPoints 2 PathVector 0.000000,0.000000,100.000000 PathLightingVector 0,0x000000,0,0,0 PathVector 0.000000,0.000000,0.000000 PathLightingVector 0,0xe3c61c,0,90,0 etc. From a logfile: view this without a proportional font! It is important to have READABLE log information. i.e. know how to use printf. For all addresses use 0x%08x, signed numbers could use % 04d, etc. Filling in the blank zeros and so on makes everything align nicely, thus making errors much easier to spot. This sort of thing takes no time at all and is fantastic for debugging with. >>local auto auto >>go main.c 0042 Reg: GP:0x800af890 SP:0x801fff08 FP:0x801fff08 Version 1.21 Select & Start to Quit ResetGraph:jtb=8004829c,env=800482e4 ResetGraph:jtb=8004829c,env=800482e4 --------------------------------------- +++ Loading Sound Data +++ --------------------------------------- +++ Level Data Areas Being Cleared +++ --------------------------------------- +++ Loading Scene flibble.scn +++ --------------------------------------- +++ Remap New Scene Pointers +++ Objects -> Address: 0x80170f54 Offset: 0x00000154 Textures -> Address: 0x80172134 Offset: 0x00001334 Tmd -> Address: 0x801730d0 Offset: 0x000022d0 --------------------------------------- +++ Scene Information +++ Name: Ultimate Wibbly Flibble Version: 1 Revision: 9 Objects: 22 Textures: 27 --------------------------------------- +++ Loading Icons +++ --------------------------------------- +++ Loading Scene.lision Data +++ --------------------------------------- +++ Loading 027 Textures +++ 000 TXTR0001.tim -> initialising texture pointers 001 TXTR0002.tim -> initialising texture pointers 002 TXTR0003.tim -> initialising texture pointers 003 TXTR0004.tim -> initialising texture pointers 004 TXTR0005.tim -> initialising texture pointers etc. --------------------------------------- +++ Initialising 027 Tims +++ 000 TXTR0001.tim (000) 0x00001334 -> 0x80148270 TimInfo 001 TXTR0002.tim (001) 0x000013c8 -> 0x8014c490 TimInfo 002 TXTR0003.tim (002) 0x0000145c -> 0x801506b0 TimInfo 003 TXTR0004.tim (003) 0x000014f0 -> 0x801548d0 TimInfo 004 TXTR0005.tim (004) 0x00001584 -> 0x80158af0 TimInfo 005 TXTR0006.tim (005) 0x00001618 -> 0x8015cd10 TimInfo 006 TXTR0007.tim (006) 0x000016ac -> 0x80160f30 TimInfo 007 TXTR0008.tim (007) 0x00001740 -> 0x80165150 TimInfo 008 TXTR0009.tim (008) 0x000017d4 -> 0x80169370 TimInfo 009 WATR0001.tim (009) 0x00001868 -> 0x8016d590 TimInfo...8 frame anim (00) ... 017 PLANT_01.tim (017) 0x00001d08 -> 0x8016e790 TimInfo 018 PLANT_02.tim (018) 0x00001d9c -> 0x8016efd0 TimInfo 019 BRLS0001.tim (019) 0x00001e30 -> 0x8016f810 TimInfo...8 frame anim (01) etc --------------------------------------- +++ Initialising Lighting Data +++ --------------------------------------- +++ Copying to VRam from 027 Tims +++ 000 TXTR0001.tim -> VRam 001 TXTR0002.tim -> VRam 002 TXTR0003.tim -> VRam 003 TXTR0004.tim -> VRam 004 TXTR0005.tim -> VRam 005 TXTR0006.tim -> VRam 006 TXTR0007.tim -> VRam 007 TXTR0008.tim -> VRam 008 TXTR0009.tim -> VRam 009 WATR0001.tim* -> VRam 017 PLANT_01.tim -> VRam 018 PLANT_02.tim -> VRam 019 BRLS0001.tim* -> VRam --------------------------------------- +++ Copying Icons to VRAM +++ --------------------------------------- +++ Initialising 022 Object 3D Handlers +++ 000 plant01 (000) -> X:-00610 Y: 04241 Z: 00923 Att:0x0080 Fl:0x00000000 001 plant04 (001) -> X: 00578 Y: 05746 Z: 00654 Att:0x0080 Fl:0x00000000 ... 021 ba06.2dcol (021) -> X: 00354 Y:-02122 Z: 02085 Att:0x0080 Fl:0x00000048 --------------------------------------- +++ Updating TMD Data +++ Addr: 0x801730d0 Offset: 0x000022d0 000 plant01 Offset: 0x000022dc 0032 primitives 001 plant04 Offset: 0x000022f8 0032 primitives etc --------------------------------------- +++ Collision Detection Data +++ Remapping... --------------------------------------- +++ Reseting Player Data +++ [game log data here when I have a bug!] 0 03 1024 1024 T:1024 M:0017 D:0060 R:000 255 072 G:000 255 072 B:000 255 072 0 03 1024 1024 T:1024 M:0019 D:0060 R:000 255 080 G:000 255 080 B:000 255 080 etc... --------------------------------------- Total Render Time: 83880 ms Average Frame Time: 48 ms Frames Rendered: 1720 Average Frame Rate: 20 fps --------------------------------------- Regards, Alex Amsel + Tuna Technologies + Windows 95/NT, Console and Internet + + The PC/PS-X Game Tools and Game Development Specialists + + Flibbley flobble wab tiggle sa lable ly pibbley Obblers +