Short: Source code of awinquake 0.9, a68k/ppc Author: Peter McGavin (p.mcgavin@irl.cri.nz) Uploader: Peter McGavin (p mcgavin irl cri nz) Type: game/shoot Version: 0.9 Architecture: generic This archive contains the SAS/C Amiga source code of awinquake and awinquakeppc 0.9. You don't need it to play winquake or awinquakeppc, only if you want to try and compile it or look at how it works. awinquake was derived from the original ID Software Linux winquake source which you can download from: ftp://ftp.cdrom.com/pub/idgames/idstuff/source/q1source.zip My modified source code should still compile for Linux (APUS), Solaris, Win95, etc, with no changes --- untested. All winquake support files for those platforms are included in this archive, even though they are not used by the Amiga version. ------------------------------------------------------------------------ v0.9 12 Mar 2000 d_scan.c, d_init.c, amiga_ppc_d_scan.c: Implemented d_subdiv16 variable, default value is 1 for PPC. Wrote new D_DrawSpans16(). Perspective is now calculated every 16 pixels by default, instead of every 8 pixels, leading to a significant increase in speed. r_draw.c, r_local.h, d_polyse.c, new file amiga_d_polyse.s: More 68k assembly optimisations from John Selck. 68k assembly versions of R_ClipEdge() and R_EmitEdge() work now. ------------------------------------------------------------------------ v0.8 3 Mar 2000 snd_amiga.c, snd_mix.c, snd_dma.c: Implemented AHI support using AHI device interface with double-buffering. Had problems reducing the number of context switches. Use PPC timer to work out approximately when each AHI request will finish, then poll with CheckIO() after that. Because AHI requests are queued, it's difficult finding out exactly when they started. When timed from the PPC side, AHI requests that should take at least 5.944 seconds to complete inexplicably seem to finish about 0.02 to 0.08 seconds before that. Therefore I allow 0.1 seconds of slop in the code. Timed from the m68k side, they finish at the expected time. Right now I have no explanation for the discrepancy. sys_amiga.c: More changes to PLL code. Hopefully this is the last time and it works in all circumstances now. d_scan.c: Rearranged middle-level loop of D_DrawSpans8() to precalculate z = 0x10000 / zi for the next loop just before the inner rendering loop. So now the FDIV runs in the FPU in parallel with the inner rendering loop, instead of delaying it. Modified amiga_ppc_d_scan.s similarly. Made other minor changes to inner loops, gaining 0.1 fps. r_surf.c: R_DrawSurfaceBlock8_mip*(): Made lightleft, lightright, lightleftstep, lightrightstep and colormap all locals instead of static. Also copied vid.colormap, sourcetstep and surfrowbytes into locals. Gained 0.4 fps. I don't think I could beat the code generated by gcc for R_DrawSurfaceBlock8_mip*() in hand-assembly now. r_edge.c: R_LeadingEdge(): Moved local variables to make them even more local, i.e, inside if-statements and loops. Gained 0.2 fps. r_draw.c: R_ClipEdge(): Tried the same trick as above, but it didn't seem to achieve anything. d_*.c, r_*.c: John Selck sent me some m68k assembly code for lots of rendering routines. Added new files amiga_d_68k.c and amiga_r_68k.c. Inserted #ifdef around routines that are replaced with assembly equivalents. Assembly replacements for R_ClipEdge() and R_EmitEdge() didn't work, so didn't use those ones. ------------------------------------------------------------------------ v0.7 19 Feb 2000 amiga_ppc_mathlib.s: Stupid bug in sqrt() introduced at the last minute in v0.6 made the player virtually uncontrollable. Fixed. ------------------------------------------------------------------------ v0.6 18 Feb 2000 Some ELF loaders couldn't load awinquakeppc v0.5 because various global symbols declared in amiga_socket_lib.s and amigacgxtagfns.s had no type declared. Goodness knows how it worked in v0.4. Anyway, added ".type symbol,@function" declarations to those files. Also added ".size" directives to the end of each routine. Added optimised c2p for 68k version. Used Aki Laukkanen's 68060-optimised c2p routine from ADoom. cd_audio.c: Continue without CD audio if cdplayer.library fails to open. sys_amiga.c: Added more PLL cases to awinquakeppc bus speed calc. See http://members.xoom.com/silicon/docs/ppc_pll.html. vid_amiga.c: Aspect ratio fix accounts for LACE, HIRES and SUPERHIRES in native modes using code of John Selck. vid_amiga.c: Added -directcgx option and code to handle it. Also required change to quakedef.h and new routines VID_LockBuffer() and VID_UnlockBuffer(). d_ifacea.h and r_shared.h: Increased maximum allowed resolution from 1280x1024 to 1600x1280. Added new file amiga_ppc_stubs.h included from vid_amiga.c. Declared special inline versions of WritePixelArray8() and ReplyMsg() with optimised cache modes. This increased overall speed of awinquakeppc by approximately 0.6 fps with ppc.library. smakefile: Now compile awinquakeppc CPU-intensive routines with GCC 2.95.2 from http://munk.home.pages.de/. Now runs at 38.9 fps in 320x200 for "timedemo demo2". Wrote some hand-optimised PPC assembly routines for awinquakeppc. New files are amiga_ppc_d_scan.s and amiga_ppc_mathlib.s. Added #ifdef to d_scan.c and mathlib.c. Speed increased to 40.5 fps. Found that the most important inner-loops are already as fast as possible without changing the algorithms, i.e, memory speed bound. Almost all of the speedup came from optimising the middle-level loop of D_DrawSpans8(). All the effort I put into D_DrawZSpans(), VectorNormalize(), Length() and mysqrt() seems to have made negligible difference. Sorry, my assembly routines don't work with StormC or VBCC yet because those compilers use different conventions from GCC for accessing static variables. So only awinquakeppc benefits so far. ------------------------------------------------------------------------ v0.5 30 Jan 2000 sys_amiga.c: Memory heap was allocated twice. Oops. Fixed. sys:amiga.c: Fixed return value of main(). in_amiga.c: Added joypad support and improved mouse support using Jarmo Laukkonen's WarpQuake source code as an example. Variable mouse_has_moved is set in vid_amiga.c. Tried compiling WarpOS PPC version with StormC. Changes required: common.h: redefine qboolean, false and true console.c: use fopen(), fwrite(), fclose(), remove() instead of open(), write(), close(), unlink(). net.h, net_main.c, net_dgrm.c: use prototypes for procedure function variable. Copied writechunkypixels_stub.c, cybergraphics_protos_stub.c, cdplayer_protos_stub.c and lowlevel_protos_stub.c from other projects. Created project file awinquakewos.¶. The smakefile also works. StormC version works, but rather slow. Tried compiling WarpOS PPC version with vbcc. Changes required: All *.c and *.h files: Remove ^Ms with dos2unix. console.c, sys_amiga.c, vid_amiga.c and cd_amiga.c: Various #ifdef __VBCC__ r_alias.c: vbccwos generates bad code for the assignment "pauxverts = &auxverts[0]" in R_AliasDrawModel. As a workaround, made auxverts[] static for vbcc in r_alias.c. sys_amiga.c: vbcc incorrectly parses the double constant 4294967296.0 in source code. Replaced with (2147483648.0 + 2147483648.0). For vbccwos, compiled a few inner-loop files with -O3. However vbcc generated bad code for r_draw.c and maybe r_bsp.c at that level of optimisation. Compiled most files for vbccwos with -O1. mathlib.c: Both StormC and VBCC rounded results differently to SAS/C, GCC and EGCS in anglemod(). The result was the player's view slowly drifted when compiled with StormC or VBCC. Made correction in anglemod(). ------------------------------------------------------------------------ v0.4 11 Jan 2000 vid_amiga.c: Call cybergraphics.library WritePixelArray() instead of WriteChunkyPixels() under KS3.0 (provided cgx lib is open). sys_amiga.c: PPCGetAttr (PPCINFOTAG_CPUPLL) appears to return the PLL code in the high nibble. Calculated bus speed is more likely to be right now. common.c and host.c: Made more changes to handling of ':' and '/' and directory paths. Created in_amiga.c from in_null.c. Support -mouse and -mousepointer. Changes to IDCMP message handling in vid_amiga.c. sys_amiga.c: Changed handling of PLL for calculating bus speed. Hopefully it's right now. sys_amiga.c: Call Host_Shutdown() on exit. Config.cfg is written now. ------------------------------------------------------------------------ v0.3 4 Jan 2000 v0.2 called BestCModeIDTags() even if cybergraphics.library failed to open. That caused crashes and other problems on Amigas without cybergraphics.library. The SAS/C __AMIGADATE__ macro generates the string (4/1/0) for 4th Jan 2000, instead of (4/1/100). ------------------------------------------------------------------------ v0.2 30 Dec 1999 Wrote sys_amiga.c, vid_amiga.c, snd_amiga.c, cd_amiga.c and net_amigaudp.c starting with copies of sys_null.c, vid_null.c, snd_null.c, cd_null.c and net_udp.c, mainly by cutting and pasting from other projects. Created smakefile. PPC assembly files copied from other projects are: amiga_timer.s, amiga_cgxtagfns.s and amiga_socket_lib.s. Also created cdplayer_pragmas.h. It goes in ppcinclude:ppcpragmas. Used includes and libs from SDKs for cybergraphics, AmiTCP and cdplayer.library, all on Aminet. d_edge.c: commented out declaration of screenwidth (conflict with declaration in r_main.c). d_local.h: made sadjust, tadjust, bbextents, bbextentt and prealspandrawer all extern to avoid duplicate definitions of symbols. chase.c: declared SV_RecursiveHullCheck as extern. host_cmd.c: declared SV_SaveSpawnparms as extern. net_dgrm.c: don't #define BAN_TEST common.c: deal with '/' in filenames in calls to COM_AddGameDirectory() SAS/C 6.58 appears to generate bad code for R_TransformFrustum() in r_misc.c when optimisations are turned on. Split r_misc.c into 2 separate files, r_misc1.c and r_misc2.c, the latter containing only R_TransformFrustum(). Compiled r_misc2.c as a special case without optimisation. Had a lot of trouble debugging amigaudp networking code. Tracked down 2 problems after a full day of debugging. The first was that the wrong errno variable was being picked up. Replaced references to errno with calls to bsdsocket.library Errno(). The 2nd problem was in UDP_AddrCompare(). The original code compared addr1->sa_family with addr2->sa_family. Because of the way chars are aligned in the sockaddr_in structure, this included an uninitialised byte. Changed to compare ((struct sockaddr_in *)addr)->sin_family instead. Finished up changing all occurrences of addr->sa_family to ((struct sockaddr_in *)addr)->sin_family. Compiled some low-level rendering modules with ppc-amigaos-gcc instead of scppc. Overall speed increased by about 3%. Discovered that R_DrawSolidClippedSubmodelPolygons() was truncated by scppc to R_DrawSolidClippedSubmodelPolygo() and wouldn't link with untruncated references generated by ppc-amigaos-gcc. Fixed by truncating the name in the source code in r_bsp.c, r_main.c and r_local.h.