Testing your code
Ok, guys, again I here with question. How do you test your works?
I understand how to test functions and procedures mathematically (for example, generating sine table in memory), but how to check if some general function is ok after you do optimizations or extend functionality?
It does my head go dizzy when it comes to usual functions, like sprite drawing or monsters AI or SMC parts.
And how to test whole program? Are there some ways to get it at least semi-automata?
Yes, code is assembly.
I understand how to test functions and procedures mathematically (for example, generating sine table in memory), but how to check if some general function is ok after you do optimizations or extend functionality?
It does my head go dizzy when it comes to usual functions, like sprite drawing or monsters AI or SMC parts.
And how to test whole program? Are there some ways to get it at least semi-automata?
Yes, code is assembly.
Heavy on the disasm
Comments
One way would be to include some test code (only assembled for testing and not in your final release.) which runs through your code and checks various aspects.
Lets say we want to make sure your positioning of the hero never overflows. Write some code to run through all the possible values of the x position of your hero. Your test code will set the x position for each value (say 0 ~ 256), calls all the code to position and draw your hero, making sure the code always returns without crashing / overflowing etc.
You'd need to have code for each different type of test / per function. This can be quite large, methodical and boring.
Of course ultimately the best testing, after unit testing is by playing the game.
@luny@mstdn.games
https://www.luny.co.uk
Create a separate program which prints things to the screen like the path an enemy is going to take and what the monster is thinking,then when it is right just copy and paste to the game,
When you need to make changes,you can use the separate program and copy n paste again
Or any emulator/other tools to help doing this?
So, I'm The One?
I'm The First?
^:)^
Personally when I'm coding for Spectrum I don't do such stuff and don't even know what would be possible. I just write code, I run it and check if it run correctly. If it doesn't, I adjust it and run again until it's allright.
You start builiding your program from small bricks and at each stage you check if the latest changes work all right.
For example
- first try to draw a part of location
- then try to draw whole location
- then try to draw a sprite
- then try to move it over location
- then draw more sprites
- then check colisions between them
- then add score, energy, collected items etc.
While making a game you test what you added lately. And You need to think of edge cases, predict and check cases when your code may break, for example
- what if player tries to go out of screen in single screen game
- what if player presses left and right at same time
- what if player presses fire when he already fired a bullet
- may enemy be created everywhere or do we need to avoid creating him in the wall
Of course when yor game is ready you have to complete it yourself, probably more than once to hunt for bugs that survived to this stage.
Generally you write, test, write, test, write, test. Never write bigger blocks of code without testing them in the middle.
And a Trap On Error tickbox that breaks as soon as you run off the rails.
SevenFFF / Threetwosevensixseven / colonel32
NXtel • NXTP • ESP Update • ESP Reset • CSpect Plugins
This is a root of evil, what bothers me.
At this moment, Luny is right, easier way is to write some side code what does include functions/procedures, and test it separately.
But anyway it does need a lot of manual work.
Can Fuse (or any other emulator) can be setup on start to change registers, run given snapshot, then save work?
In the z80 world, the only project that does significant testing is sdcc which runs the gcc torture tests to check that the compiler remains correct as it is developed. They use ucsim as z80 simulator and the test programs are in C and compiled by sdcc.
If your subroutines under test can be verified by looking at cpu state only, you can take a similar approach but if you have to see results with your own eyes (eg as in if the display is correct) you may have to just generate the test programs and manually run each to verify the display is right.
In the latter case and if you don't have hundreds or thousands of tests to run, you can instead assemble or compile your individual test programs and run each in an emulator individually to verify output.
What makes testing much more convenient is if you are using tools with linking assemblers. These will allow you to write tests that can extract only the subroutines under test from your project as needed. That way you don't have to worry about running out of memory or having to place routines or data at specific memory addresses.
It's also much easier to test if you can write the tests in a high level language or script. These will allow you to generate corner case tests automatically and quickly. Yes you can write in asm but it will take you until next year to do it.
Write games in C using Z88DK and SP1
As to the original question, I have no idea.
How to test... my God...
https://mb.boardhost.com/BikerMike/index.html?1593001131
And sometimes, based on random numbers print "This is not my fault!" and "Are you crazy to do THIS?!"
..you wish. I hardly get any mail. =)
http://goo.gl/q2j0NZ - make ZX Spectrum choose your own adventure games, no programming needed (release 3)
When testing procedure I can save work as snapshot, then loop change registers in it by external script, and run emulator.
But. Can I somehow produce work with emulator (which one?) by retrieving it's state, and send commands from my script (stop and exit on given address, save memory as binary, stop after given amount of time, etc) ?
JSpeccy-win32-portable
This is probably still light years ahead of what most developers were working with back in the day....
From emulators known to me , Spin has the most advanced breakpoint system. Search these forums, there is some very old post explaining it.
I'm thinking about to tweak DelphiSpec (some time ago it was modified a little to be compilable under Lazarus), and to get useful things from it with extended functionality.