![]() |
Cargas de Produndidad / Depth Charge - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Gallery (https://www.boriel.com/forum/forumdisplay.php?fid=18) +---- Thread: Cargas de Produndidad / Depth Charge (/showthread.php?tid=857) |
Cargas de Produndidad / Depth Charge - oblo - 11-04-2018 Hi all, long time no see ![]() Thanks to some spare time, I had the opportunity to retake the speccy programming, so here is my last creation: a clone of the Depthcharge arcade game. Nothing fancy, but at least I could have some fun developing for ours old but reliable Spectrums. Game mechanic is simple: move your ship left and right and drop charges to destroy submarines, while avoiding their missiles. Number of submarines and missiles can be chosen at each game start. ![]() The file attached contains: - .TAP Spanish version - .TAP English version - Source code for both versions - A 'readme.txt' file Hope you enjoy and as always, any comments are welcome. Cheers! Re: Cargas de Produndidad / Depth Charge - boriel - 11-06-2018 Woooow! ![]() Super!! Thanks for sharing! Re: Cargas de Produndidad / Depth Charge - britlion - 11-14-2018 Very nice little fun thing. Good job. By the way, my sneaky fast t() function is: Code: FUNCTION t() as uLong Which saves a lot of maths and division. If you want to divide by 50 to get whole seconds, you can do it outside the function - but generally, I found t() returning clock ticks and working with them as 50 times larger meant I have more precision on where I launch events. (Instead of at 1s, 2s, 3s, I go 50 frames, 100 frames, 150 frames - and then if I want to I can tweak that to 40,80,120 much more easily). I notice you are actually using it in the line: a = t1 / 30 * PI So to get t you do a lot of stack work, then divide by 50 - and then divide by 30. I think I'd do it as frames and divide by 150 in one go when setting a, which is probably shorter than running the full division twice. Anyway. Just my thougts. The game is quite fun ![]() Re: Cargas de Produndidad / Depth Charge - oblo - 11-18-2018 britlion Wrote:Very nice little fun thing. Good job. Many thanks! I'm not fond on ASM so any input is very welcome; at least I can compare your code with mine and learn something new ![]() Besides, I updated the game with a few improvements: sonar is now draw OK , added a minor visual effect on it, load screen and intro music. And the inlays, shared with my other Escape game. Spanish inlay: https://drive.google.com/open?id=1aHkpNZsC3XyqR20OcsntKNCfx5sgDVvJ English inlay: https://drive.google.com/open?id=1TTmyl3hY35l3hVcXTts3F_31KLPwTItz Cheers. EDIT: just tried your ASM t() function and it's so fast I can now "play" with the sonar and add more effects ![]() Anyway, just to try to understand a bit of ASM with your function: DI -> disables interruptions, so the program won't interfere with the function LD DE,(23674) -> load the value of the 23674 address (part of the Spectrum frames system variable) in the DE register (one of the Spectrum 8+8 -pair- bit registers) LD D,0 -> load 0 into D register (?) LD HL,(23672) -> load the value of the 23674 address (part of the Spectrum frames system variable) in the HL register (one of the Spectrum 8+8 -pair- bit registers) EI -> enables interruptions before existing function But the function, what returns? The sum of all values? And why load a zero value into D? Sorry if they are basic ASM questions, but my knowledge of ASM and the Z80 are almost none. Re: Cargas de Produndidad / Depth Charge - boriel - 11-19-2018 Note: You can directly do that in ZXBasic (replacing the ASM function) with: Code: t = PEEK(Ulong, 23672) BAND 0xFFFFFF It won't be perhaps as fast as the ASM. Can you check it? Re: Cargas de Produndidad / Depth Charge - oblo - 11-20-2018 boriel Wrote:Note: You can directly do that in ZXBasic (replacing the ASM function) with: Tested and it's way faster than ASM; in fact, I can't control the speed of the sonar pointer. With the ASM function, I can do that changing the 360 in a = t1 / 360 * PI: REM a is the seconds pointer in radians line. This is how the sonar subroutine is defined right now: Code: REM Rutina del sonar Cheers Re: Cargas de Produndidad / Depth Charge - boriel - 11-20-2018 Ups, sorry. For the PEEK, it's in 1/50th of second. You have to divide by 50 to get the real value in seconds. Re: Cargas de Produndidad / Depth Charge - oblo - 11-21-2018 Negative; after several tests it's still too fast and the radian still goes wild ![]() Cheers Re: Cargas de Produndidad / Depth Charge - britlion - 12-03-2018 How the heck is the compiled code faster than the ASM one? *blink* I thought the ASM one was pretty optimal - I can't see how to do it faster. I must check that. Are you sure it's working correctly (if too fast) with it? The ASM one does: DI - disable interrupts. Just for a moment, it stops the clock. This means it can't tick mid measure. Technically it will lose a frame very very _very_ rarely, but in practice nobody would notice. It's a safety device to make all the bytes consistent while we read it. LD DE, (23674) - The clock is at 23672,23763,23674. This loads D up with (23675) and E up with (23674). The contents of 23675 are redundant - it's a 3 byte clock, so we clear D with LD D,0 LD HL, (23672) loads H with (23673) and L with (23672). EI - Put interrupts back. We've got our numbers. end ASM Back to normal. So all we've done is copy the clock bytes into DEHL (well, 0+E+H+L) Since the function returns a uLong, which is 4 bytes in DEHL, it returns this number. Boriel's peek method is technically not interrupt safe, by the way, though the probability of an interrupt hitting right in the middle of those small set of instructions is fairly low. That said, it's going to happen eventually. Re: Cargas de Produndidad / Depth Charge - britlion - 12-03-2018 Doesn't that peek band 63 (FFFFFF) mean that it only returns numbers from 0-63 ? That's a bit short. It rolls over every second and a bit, surely? Shouldn't it be peek band 0xFFFFFFFFFFFFFFFFFFFFFFFF ? Re: Cargas de Produndidad / Depth Charge - britlion - 12-03-2018 Code: a = t1 / 360 * PI: REM a is the seconds pointer in radians Surely this is 50 times too fast? My t() function returns FRAMES, not seconds - so it returns 50ths of a second as a count. Re: Cargas de Produndidad / Depth Charge - oblo - 12-03-2018 britlion Wrote:How the jeck is the compiled cosde faster than the ASM on? *blink* You are right, my mistake :-S I really wanted to say I didn't know to implement/control the code provided by boriel as opposite as yours, what works "as is", without any modification. Re: Cargas de Produndidad / Depth Charge - boriel - 12-03-2018 That Britlion said is what I tried to explain on first place (didn't make myself understood). Anyway, nice game, an congrats ![]() |