The Sega Master System, released in 1986, is a third-generation home video game console manufactured by Sega.
The region detection code used in Master Games attempts to write to the two most significant bits in I/O port $3F and to read back the value at I/O port $DD. Japanese systems will not readback the write value at $DD, overseas systems will.
;============================================================== ; Region detector ; Returns a=1 for Japanese, 0 for export ; Based on code found in many Sega games (eg. Super Tennis) ;============================================================== IsJapanese: ld a,%11110101 ; Output 1s on both TH lines out ($3f),a in a,($dd) and %11000000 ; See what the TH inputs are cp %11000000 ; If the input does not match the output then it's a Japanese system jp nz,_IsJap ld a,%01010101 ; Output 0s on both TH lines out ($3f),a in a,($dd) and %11000000 ; See what the TH inputs are jp nz,_IsJap ; If the input does not match the output then it's a Japanese system ld a,%11111111 ; Set everything back to being inputs out ($3f),a ld a,0 ret _IsJap: ld a,1 ret