Each unique flag number has a pair of handler routines associated with it - one for read and one for write. The handler routine would get called with the address in question and return or store the appropriate value. RAM would be marked with the handler number for video RAM and get called each time a read or write occurred in that range. This way, time is not wasted in a general memory handler checking for each address range individually. This method is faster than the method used by some other emulators simply because there are no unnecessary address comparisons.
Some games actually try to write into ROM for protection.
Using the above method, bank switched memory is also easy to implement. This is handled by marking that area to use a handler routine which checks the state of the bank switch and acts appropriately.