💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › Orca › orc… captured on 2023-01-29 at 10:08:10.
-=-=-=-=-=-=-
Path: ns-mx!hobbes.physics.uiowa.edu!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!nntp-server.caltech.edu!toddpw From: toddpw@cco.caltech.edu (Todd P. Whitesel) Newsgroups: comp.sys.apple2 Subject: Re: Screen Values?? Message-ID: <1991Dec9.183220.937@cco.caltech.edu> Date: 9 Dec 91 18:32:20 GMT References: <1991Dec08.141621.14323@crash.cts.com> Organization: California Institute of Technology, Pasadena Lines: 56 qd@pro-calgary.cts.com (Quinn Dunki) writes: >I'm working on my Knights of Legend GS right now, but I've hit a big-time >glitch. Maybe somebody can help? I've written this function that just >returns (ORCA/C, by the way) the color number of a given pixel. However, no >matter what's on the screen, no matter what values I give it, it always Probably a bug in the compiler. Try the following, which is considerably faster and does precisely what your code does, although in not precisely the same order, and considerably better optimized than anything Orca/C can produce: int gethex (int x, int y) { asm { lda y asl a asl a asl a asl a asl a sta y asl a asl a adc y /* computes y*160 as y*(2^5)*(1+2^2) */ lsr x bcs odd adc x tax lda >0xe12000,x and #0xf0 lsr a lsr a lsr a lsr a bra out odd: clc adc x tax lda >0xe12000,x and #0x0f out: sta x } return x; } This assumes of course that you do not intend to support arbitrary screen sizes (no biggie for a game) and that you will be calling this often enough to make the assembly worthwhile -- which I suspect is the case, especially with Orca/C (hint, BTW, always use x&1 instead of x%2 -- Orca/C doesn't optimize the modulo computation). Todd Whitesel toddpw @ tybalt.caltech.edu Path: ns-mx!uunet!vuse.vanderbilt.edu!benson From: benson@vuse.vanderbilt.edu (Paul BaJa Benson) Newsgroups: comp.sys.apple2 Subject: Re: Screen Values?? Message-ID: <1991Dec9.213742.1846@vuse.vanderbilt.edu> Date: 9 Dec 91 21:37:42 GMT References: <1991Dec08.141621.14323@crash.cts.com> Sender: news@vuse.vanderbilt.edu Organization: Vanderbilt Univ., Engineering (SERG), Nashvegas, TN Lines: 49 Nntp-Posting-Host: cad1 In article <1991Dec08.141621.14323@crash.cts.com> qd@pro-calgary.cts.com (Quinn Dunki) writes: ~returns 11. Even if there isn't anything on the screen that is color #11 in ~ANY pallette. Here she is: ~ ~int gethex(int x, int y) ~ ~{ ~char c; ~ ~ c=*(screen+x/2+y*160); ~ if ((x%2)==0) { ~ c=c&0xF0; ~ c>>=4; ~ } ~ else c=c&0x0F; ~ return c; ~} ~ ~Can anybody see any reason this shouldn't work? Using Todd's excellent assembly code is probably your best choice in this case, as this routine will probably be called a lot and his code is to the point. But, let's make sure you did not over look some C problems that might crop up in different functions. 1 - How is 'screen' defined. Hopefully it is a _char_ pointer and is pointing to the proper location. So something like this should be in your code somewhere: char *screen; screen = (char *) 0xe12000; This can all be put on one line, this just explains it better. 2 - Did you pre-declare the function gethex? If you are calling it from a function 'above' gethex and you did not pre-declare it, it is expecting an int function with no passed parameters. This would mess up your stack, and thus your answer, and invariably your program. 3 - You have defined c to be char and you have declared an int function. Your return statement is returning a char, either convert c to int or make the function a char function (better). Hope this helps. s -- Paul 'BaJa' Benson Vanderbilt University - Space Electronics Research Group GEnie: P.Benson1 Net: benson@vuse.vanderbilt.edu