// WebMSX C-BIOS version 6.0.0
// Copyright 2015 by Paulo Augusto Peccin. See license.txt distributed with this file.

// Main Emulator parameters for C-BIOS variation. No FloppyDrive, Kanji and Moonsound support. Experimental HardDrive support.
// May be overridden dynamically by JS code, external Config File or URL query parameters

WMSX = {

    // Main Setup
    ENVIRONMENT:                   101,                         // 101: C-BIOS Built-in Emulator Environment
    CONFIG_URL:                     "",                         // Configuration file to merge. Processed before URL parameters
    MACHINE:                        "",                         // Machine Type. See Machine Configuration. Leave blank for auto-detection
    PRESETS:                        "",                         // Configuration Presets to apply. See Presets Configuration

    // Full or relative URL of Media files to load
    CARTRIDGE1_URL:                 "",                         // ROM file
    CARTRIDGE2_URL:                 "",
    DISKA_URL:                      "",                         // Disk Image file
    DISKB_URL:                      "",
    HARDDISK_URL:                   "",
    DISKA_FILES_URL:                "",                         // File to load into a Disk. For several files, use a ZIP file
    DISKB_FILES_URL:                "",
    HARDDISK_FILES_URL:             "",
    TAPE_URL:                       "",                         // Disk Image file
    STATE_URL:                      "",                         // Save State file
    AUTODETECT_URL:                 "",                         // Open any file in auto-detect mode

    // Forcing ROM formats
    CARTRIDGE1_FORMAT:              "",                         // Normal, ASCII8, ASCII16, Konami, KonamiSCC, KonamiSCCI, FMPAC, etc...
    CARTRIDGE2_FORMAT:              "",

    // BASIC loading/typing commands. Not needed for AUTOEXEC.BAS, AUTOEXEC.BAT or Tape Images
    BASIC_RUN:                      "",
    BASIC_LOAD:                     "",
    BASIC_BRUN:                     "",
    BASIC_BLOAD:                    "",
    BASIC_TYPE:                     "",
    BASIC_ENTER:                    "",

    // Boot Options
    BOOT_KEYS:                      "",                         // Keys to keep pressed at every boot, comma separated
    BOOT_KEYS_ONCE:                 "",                         // Same as above, but only on first boot (do not use both)
    BOOT_KEYS_FRAMES:               -1,                         // -1: auto; > 0: number of frames for Boot Keys
    FAST_BOOT:                       0,                         // 0: off; 1: auto (same as Boot Keys frames); > 1: number of frames for 10x speed at boot

    // NetPlay
    NETPLAY_JOIN:                   "",                         // Join NetPlay! Session automatically
    NETPLAY_NICK:                   "",                         // NetPlay! Nickname, optional

    // Internal Machine configuration
    BIOS_SLOT:                      [0],                        // Slot to use when loading ROM of type
    CARTRIDGE1_SLOT:                [1],
    CARTRIDGE2_SLOT:                [2],
    EXPANSION1_SLOT:                [3, 3],
    EXPANSION2_SLOT:                [2, 3],
    BIOSEXT_SLOT:                   [3, 1],
    RAMMAPPER_SIZE:                 512,                        // 64, 128, 256, 512, 1024, 2048, 4096: RAM Mapper size in KB when active
    RAMNORMAL_SIZE:                 64,                         // 16..64: Normal RAM size in KB when active
    MEGARAM_SIZE:                   2048,                       // 256, 512, 1024, 2048: MegaRAM size in KB
    EXTENSIONS:                     { },                        // Extensions active. See Extensions Configuration. Use Presets to activate/deactivate
    RTC_ACTIVE:                     -1,                         // -1: auto; 0: not present; 1: present
    VDP_TYPE:                       -1,                         // -1: auto; 1: V9918; 2: V9938; 3: V9958
    VDP_PALETTE:                    2,                          // 0: WebMSX Original; 1: V9918; 2: V9928; 3: V9938; 4: Toshiba; 5: Fujitsu FM-X

    // General options
    VOL:                            1.0,                        // Master Volume factor
    SPEED:                          100,                        // Default emulation speed (in %)
    AUTO_START:                     true,
    AUTO_POWER_ON_DELAY:            1200,                       // -1: no auto Power-ON; >= 0: wait specified milliseconds before Power-ON
    MEDIA_CHANGE_DISABLED:          false,                      // Prevents user form changing Machine Type, Extensions and Medias (Disks, Carts, Tapes)
    SCREEN_RESIZE_DISABLED:         false,
    SCREEN_ELEMENT_ID:              "wmsx-screen",
    SCREEN_FULLSCREEN_MODE:         -1,                         // -2: disabled; -1: auto; 0: off; 1: on (Full Screen); 2: on (Full Windowed)
    SCREEN_FILTER_MODE:             -3,                         // -3: user set (default auto); -2: browser default; -1: auto; 0..3: smoothing level
    SCREEN_CRT_SCANLINES:           -1,                         // -1: user set (default off); 0: off; 1..10: level
    SCREEN_CRT_PHOSPHOR:            -1,                         // -1: auto; 0: off; 1: on
    SCREEN_DEFAULT_SCALE:           -1,                         // -1: auto; 0.5..N in 0.05 steps: scale
    SCREEN_DEFAULT_ASPECT:          1.14,                       // in 0.01 steps
    SCREEN_CONTROL_BAR:             1,                          // 0: on hover; 1: always
    SCREEN_FORCE_HOST_NATIVE_FPS:   -1,                         // -1: auto. Don't change! :-)
    SCREEN_VSYNC_MODE:              -2,                         // -2: user set (default auto); -1: disabled; 0: off; 1: auto (on when available)
    SCREEN_VIDEO_OUT:               -1,                         // -1: auto; 0: Internal VDP; 1: External V9990; 2: Superimposed; 3: Mixed; 4: Dual (main: Internal); 5: Dual (main: V9990)
    SCREEN_COLORS:                  0,                          // 0: Color (default); 1: B&W; 2: Green Phosphor; 3: Amber Phosphor
    AUDIO_MONITOR_BUFFER_BASE:      -3,                         // -3: user set (default auto); -2: disable audio; -1: auto; 0: browser default; 1..6: base value. More buffer = more delay
    AUDIO_MONITOR_BUFFER_SIZE:      -1,                         // -1: auto; 256, 512, 1024, 2048, 4096, 8192, 16384: buffer size.     More buffer = more delay. Don't change! :-)
    AUDIO_SIGNAL_BUFFER_RATIO:      2,                          // Internal Audio Signal buffer based on Monitor buffer
    AUDIO_SIGNAL_ADD_FRAMES:        3,                          // Additional frames in internal Audio Signal buffer based on Monitor buffer
    JOYSTICKS_MODE:                 0,                          // -1: disabled; 0: auto; 1: auto (swapped)
    JOYKEYS_MODE:                   -1,                         // -1: disabled; 0: enabled at port 1; 1: enabled at port 2; 2: enabled at both ports; 3: enabled at both ports (swapped)
    MOUSE_MODE:                     -1,                         // -1: disabled; 0: auto; 1: enabled at port 1; 2: enabled at port 2
    TOUCH_MODE:                     0,                          // -1: disabled; 0: auto; 1: enabled at port 1; 2: enabled at port 2
    MOBILE_MODE:                    0,                          // -1: disabled; 0: auto; 1: enabled (forced)
    Z80_CLOCK_MODE:                 0,                          // 0: auto (soft-turbo possible); (0..8]: Z80 CPU clock multiplier;
    VDP_CLOCK_MODE:                 0,                          // 0: auto (soft-turbo possible); (0..8]: VDP Command Engine clock multiplier; 9: instantaneous
    Z80_SOFT_TURBO_MULTI:           1.5,                        // 1..8 Z80 CPU clock multiplier when in AUTO mode and activated by software or CPU_SOFT_TURBO_AUTO_ON
    VDP_SOFT_TURBO_MULTI:           1,                          // 1..9 VDP Command Engine clock multiplier when in AUTO mode and activated by software or CPU_SOFT_TURBO_AUTO_ON
    CPU_SOFT_TURBO_AUTO_ON:         0,                          // 0: off, 1: on. Automatically activate the CPU Soft Turbo when supported by machine
    CPU_FAKE_TR_TURBO:              -1,                         // -1: auto; 0: off; 1: on. Simulated tR CHGCPU Turbo activation. Auto ON for 2+, never for tR
    KEYBOARD_JAPAN_LAYOUT:          1,                          // 0: ANSI; 1: JIS
    DEBUG_MODE:                     0,                          // 0: off; 1..7: debug mode. Don't change! :-)
    SPRITES_DEBUG_MODE:             0,                          // 0: off; 1: unlimited; 2: no collisions; 3: both. May cause problems :-)
    ROM_MAX_HASH_SIZE_KB:           5120,                       // Maximum ROM size for Hash calculation
    HARDDISK_MIN_SIZE_KB:           720,                        // Minimum file size to be accepted as HardDisk image (besides all valid Floppy formats)
    DISK_ROM_START_PAGE:            0,                          // 0..1: Change starting page for ROMs > 16KB when format is DiskPatch
    LIGHT_STATES:                   true,

    PSG_VOL:                        "f",                        // 0..f (hex digit):       PSG Volume adjust. Set globally or for each channel (4 values)
    PSG_PAN:                        "8",                        // 0; 1..8..f (hex digit): PSG PanPot adjust. Set globally or for each channel (4 values)
    SCC_VOL:                        "f",                        // SCC Volume adjust. Same as above (5 values)
    SCC_PAN:                        "8",                        // SCC PanPot adjust. Same as above (5 values)
    OPLL_VOL:                       "f",                        // OPLL Volume adjust. Same as above (14 values)
    OPLL_PAN:                       "8",                        // OPLL PanPot adjust. Same as above (14 values)

    IMAGES_PATH:                    window.WMSX_IMAGES_PATH || "images/",
    FILE_SEPARATOR_REGEX:           /[\\/?:]/,
    PAGE_BACK_CSS:                  "",                         // CSS to modify page background color. Applied to the body element

    WEB_EXTENSIONS_SERVER:          "webmsx.herokuapp.com",     // Server address for NetPlay!

    STATE_VERSION:                  600,
    STATE_VERSIONS_ACCEPTED:        { 530: true, 600: true },

    ALLOW_URL_PARAMETERS:           true                        // Allows user to override any of these parameters via URL query parameters

};

WMSX.MACHINES_CONFIG = {
    MSX2P:   { DESCX: "MSX2+ Auto Detect",    AUTO_TYPE: 3 },
    MSX2:    { DESCX: "MSX2 Auto Detect",     AUTO_TYPE: 2 },
    MSX1:    { DESCX: "MSX Auto Detect",      AUTO_TYPE: 1 },
    MSX2PA:  { DESC:  "MSX2+ America (NTSC)", TYPE: 3, PRESETS: "_MSX2PA" },
    MSX2PE:  { DESC:  "MSX2+ Europe (PAL)",   TYPE: 3, PRESETS: "_MSX2PE" },
    MSX2PJ:  { DESC:  "MSX2+ Japan (NTSC)",   TYPE: 3, PRESETS: "_MSX2PJ",  LANG: "ja" },
    MSX2A:   { DESC:  "MSX2 America (NTSC)",  TYPE: 2, PRESETS: "_MSX2A" },
    MSX2E:   { DESC:  "MSX2 Europe (PAL)",    TYPE: 2, PRESETS: "_MSX2E" },
    MSX2J:   { DESC:  "MSX2 Japan (NTSC)",    TYPE: 2, PRESETS: "_MSX2J",   LANG: "ja" },
    MSX1A:   { DESC:  "MSX America (NTSC)",   TYPE: 1, PRESETS: "_MSX1A" },
    MSX1E:   { DESC:  "MSX Europe (PAL)",     TYPE: 1, PRESETS: "_MSX1E" },
    MSX1J:   { DESC:  "MSX Japan (NTSC)",     TYPE: 1, PRESETS: "_MSX1J",   LANG: "ja" },
    EMPTY2P: { DESCX: "MSX2+ Empty (NTSC)",   TYPE: 3, PRESETS: "_EMPTY" },
    EMPTY2:  { DESCX: "MSX2 Empty (NTSC)",    TYPE: 2, PRESETS: "_EMPTY" },
    EMPTY1:  { DESCX: "MSX Empty (NTSC)",     TYPE: 1, PRESETS: "_EMPTY" }
};

WMSX.EXTENSIONS_CONFIG = {
    HARDDISK:  {                      URL: "@[Nextor16Patch].rom", SLOT: [2],             CHANGE: { RAMMAPPER: 1, SCCI: 0, SCC:  0, PAC: 0, MEGARAM: 0 } },
    RAMMAPPER: { DESC: "RAM Mapper",  URL: "@[RAMMapper].rom",     SLOT: [3],             MUTUAL: "RAMNORMAL" },
    RAMNORMAL: {                      URL: "@[RAMNormal].rom",     SLOT: [3],             MUTUAL: "RAMMAPPER" },
    V9990:     { DESC: "V9990 Video", URL: "@[V9990].rom",         SLOT: [4, 3] },
    MSXMUSIC:  { DESC: "MSX-MUSIC",   URL: "@cbios_music[MSXMUSIC].rom", SLOT: [3, 3] },
    DOUBLEPSG: { DESC: "Double PSG",  URL: "@[ExtraPSG].rom",      SLOT: [4, 0] },
    SCCI:      { DESC: "Konami SCC+", URL: "@[SCCIExpansion].rom", SLOT: [1], SLOT2: [2], CHANGE: { HARDDISK: 0, SCC:  0, PAC: 0, MEGARAM: 0 } },
    SCC:       {                      URL: "@[SCCExpansion].rom",  SLOT: [1], SLOT2: [2], CHANGE: { HARDDISK: 0, SCCI: 0, PAC: 0, MEGARAM: 0 } },
    PAC:       { DESC: "PAC SRAM",    URL: "@[PACExpansion].rom",  SLOT: [1], SLOT2: [2], CHANGE: { HARDDISK: 0, SCCI: 0, SCC: 0, MEGARAM: 0 } },
    MEGARAM:   { DESC: "MegaRAM",     URL: "@[MegaRAM].rom",       SLOT: [1], SLOT2: [2], CHANGE: { HARDDISK: 0, SCCI: 0, SCC: 0, PAC: 0 } }
};

WMSX.PRESETS_CONFIG = {

    // Extensions Options Presets. Must be specified in this order

    // Hard Disk: Nextor Removable Device
    HARDDISK:   { "EXTENSIONS.HARDDISK": 1, _INCLUDE: "RAMMAPPER" },
    NOHARDDISK: { "EXTENSIONS.HARDDISK": 0 },

    // RAM type
    RAMMAPPER: { "EXTENSIONS.RAMMAPPER": 1, "EXTENSIONS.RAMNORMAL": 0 },
    RAMNORMAL: { "EXTENSIONS.RAMMAPPER": 0, "EXTENSIONS.RAMNORMAL": 1 },

    // V9990 Video
    V9990: { "EXTENSIONS.V9990":  1 },

    // Sound Devices
    MSXMUSIC:   { "EXTENSIONS.MSXMUSIC": 1 },
    NOMSXMUSIC: { "EXTENSIONS.MSXMUSIC": 0 },
    DOUBLEPSG:  { "EXTENSIONS.DOUBLEPSG": 1 },

    // Other Cartridge extensions

    SCCI:  { "EXTENSIONS.SCCI": 1 },
    SCCI2: { "EXTENSIONS.SCCI": 2 },

    SCC:  { "EXTENSIONS.SCC": 1 },
    SCC2: { "EXTENSIONS.SCC": 2 },

    PAC:  { "EXTENSIONS.PAC": 1 },
    PAC2: { "EXTENSIONS.PAC": 2 },

    MEGARAM:  { "EXTENSIONS.MEGARAM": 1 },
    MEGARAM2: { "EXTENSIONS.MEGARAM": 2 },

    // Configuration Helper Presets

    RAM128:      { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 128 },
    RAM256:      { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 256 },
    RAM512:      { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 512 },
    RAM1024:     { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 1024 },
    RAM2048:     { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 2048 },
    RAM4096:     { _INCLUDE: "RAMMAPPER", RAMMAPPER_SIZE: 4096 },
    NORAMMAPPER: { _INCLUDE: "RAMNORMAL"},

    MEGARAM256:  { _INCLUDE: "MEGARAM", MEGARAM_SIZE: 256 },
    MEGARAM512:  { _INCLUDE: "MEGARAM", MEGARAM_SIZE: 512 },
    MEGARAM1024: { _INCLUDE: "MEGARAM", MEGARAM_SIZE: 1024 },
    MEGARAM2048: { _INCLUDE: "MEGARAM", MEGARAM_SIZE: 2048 },

    VSYNCDISABLED: { SCREEN_VSYNC_MODE: -1 },
    VSYNCOFF:      { SCREEN_VSYNC_MODE: 0 },
    VSYNCON:       { SCREEN_VSYNC_MODE: 1 },

    PSGSTEREO:  { PSG_PAN: "4c8" },
    PSGSTEREO2: { PSG_PAN: "8c4" },
    SCCSTEREO:  { SCC_PAN: "8c4c4" },
    SCCSTEREO2: { PSG_PAN: "4c4c8" },
    OPLLSTEREO: { OPLL_PAN: "4c4c4c4c488888" },
    ALLSTEREO:  { _INCLUDE: "PSGSTEREO,  SCCSTEREO,  OPLLSTEREO" },
    ALLSTEREO2: { _INCLUDE: "PSGSTEREO2, SCCSTEREO2, OPLLSTEREO" },

    // Boosted Machine Preset
    BOOSTED: { Z80_CLOCK_MODE: 3, VDP_CLOCK_MODE: 3, BOOT_DURATION_AUTO: 165, _INCLUDE: "HARDDISK" },

    // Alternate Slot Configuration: try to keep RAM alone on primary Slot 3
    ALTSLOTCONFIG: {
        EXPANSION1_SLOT:                       [2, 3],
        EXPANSION2_SLOT:                       [3, 3],
        "EXTENSIONS_CONFIG.MSXMUSIC.SLOT":     [2, 2]
    },

    // MSX2+ Machine Presets. Do not use directly
    _MSX2PA: {
        _INCLUDE:           "_MSX2PBASE",
        SLOT0_URL:          "@cbios_main_msx2+.rom | @cbios_logo_msx2+.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 380
    },
    _MSX2PE: {
        _INCLUDE:           "_MSX2PBASE",
        SLOT0_URL:          "@cbios_main_msx2+_eu.rom | @cbios_logo_msx2+.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 395
    },
    _MSX2PJ: {
        _INCLUDE:           "_MSX2PBASE",
        SLOT0_URL:          "@cbios_main_msx2+_jp.rom | @cbios_logo_msx2+.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 380
    },
    _MSX2PBASE: {
        _INCLUDE:           "_MSX2BASE"
    },

    // MSX2 Machine Presets. Do not use directly
    _MSX2A: {
        _INCLUDE:           "_MSX2BASE",
        SLOT0_URL:          "@cbios_main_msx2.rom | @cbios_logo_msx2.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 385
    },
    _MSX2E: {
        _INCLUDE:           "_MSX2BASE",
        SLOT0_URL:          "@cbios_main_msx2_eu.rom | @cbios_logo_msx2.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 400
    },
    _MSX2J: {
        _INCLUDE:           "_MSX2BASE",
        SLOT0_URL:          "@cbios_main_msx2_jp.rom | @cbios_logo_msx2.rom",
        SLOT31_URL:         "@cbios_sub.rom",
        BOOT_DURATION_AUTO: 360
    },
    _MSX2BASE: {
        _INCLUDE:           "_BASE, RAMMAPPER, MSXMUSIC"
    },

    // MSX1 Machine Presets. Do not use directly
    _MSX1A: {
        _INCLUDE:           "_MSX1BASE",
        SLOT0_URL:          "@cbios_main_msx1.rom | @cbios_logo_msx1.rom",
        BOOT_DURATION_AUTO: 375
    },
    _MSX1E: {
        _INCLUDE:           "_MSX1BASE",
        SLOT0_URL:          "@cbios_main_msx1_eu.rom | @cbios_logo_msx1.rom",
        BOOT_DURATION_AUTO: 375
    },
    _MSX1J: {
        _INCLUDE:           "_MSX1BASE",
        SLOT0_URL:          "@cbios_main_msx1_jp.rom | @cbios_logo_msx1.rom",
        BOOT_DURATION_AUTO: 230
    },
    _MSX1BASE: {
        _INCLUDE:           "_BASE, RAMNORMAL, NOHARDDISK, NOMSXMUSIC",
        SLOT31_URL :        ""      // MSX1 has no BIOS Extension
    },

    // Base Machines Presets. Do not use directly
    _EMPTY: {
        _INCLUDE:           "_BASE",
        EXTENSIONS:         null,
        SLOT0P_URL:         "",
        SLOT1P_URL:         "",
        SLOT2P_URL:         "",
        SLOT3P_URL:         "",
        SLOT4P_URL:         ""       // MSX1 has no BIOS Extension on slot 3-1, clear
    },
    _BASE: {}

};

WMSX.params = {};                   // Additional parameter overrides

wmsx = window.wmsx || {};           // Namespace

function onUpdateReady(){alert("A new version is available!\nWebMSX will restart..."),window.applicationCache.swapCache(),window.location.reload()}WMSXFullScreenSetup={apply:function(){if(!this.cssApplied){var a=document.createElement("style");a.type="text/css",a.innerHTML=this.css,document.head.appendChild(a),this.cssApplied=!0}document.documentElement.classList.toggle("wmsx-full-screen",this.shouldStartInFullScreen())},shouldStartInFullScreen:function(){return window.WMSX?WMSX.SCREEN_FULLSCREEN_MODE>=1||-1===WMSX.SCREEN_FULLSCREEN_MODE&&this.isBrowserStandaloneMode():this.isBrowserStandaloneMode()},isBrowserStandaloneMode:function(){return navigator.standalone||window.matchMedia("(display-mode: standalone)").matches},css:"html.wmsx-full-screen, html.wmsx-full-screen body {   background: black;}html.wmsx-full-screen .wmsx-full-screen-hidden {   display: none;}html:not(.wmsx-full-screen) .wmsx-full-screen-only {   display: none;}"},WMSXFullScreenSetup.apply(),wmsx.Util=new function(){"use strict";function a(a,b){return a.name<b.name?-1:a.name>b.name?1:0}function b(a){return a.stopPropagation(),a.cancelable&&a.preventDefault(),!1}this.log=function(a){var b=[">> wmsx:"];Array.prototype.push.apply(b,arguments),console.log.apply(console,b)},this.warning=function(a){var b=[">> wmsx Warning:"];Array.prototype.push.apply(b,arguments),console.warn.apply(console,b)},this.error=function(a){var b=[">> wmsx Error:"];Array.prototype.push.apply(b,arguments),console.error.apply(console,b)},this.message=function(a){console.info(a),alert(a)},this.asNormalArray=function(a,b,c){return!c&&a instanceof Array?a:c?this.arrayCopy(a,b,new Array(c)):this.arrayCopy(a,0,new Array(a.length))},this.arrayFill=function(a,b,c,d){if(a.fill)return a.fill(b,c,d);void 0===c&&(c=0);for(var e=(void 0===d?a.length:d)-1;e>=c;e-=1)a[e]=b;return a},this.arrayCopy=function(a,b,c,d,e){d=d||0;for(var f=e?b+e:a.length;b<f;)c[d++]=a[b++];return c},this.arrayAdd=function(a,b){return a[a.length]=b,a},this.arrayRemoveAllElement=function(a,b){for(var c;(c=a.indexOf(b))>=0;)a.splice(c,1);return a},this.arraysConcatAll=function(a){for(var b=0,c=0;c<a.length;++c)b+=a[c].length;var d=new a[0].constructor(b),e=0;for(c=0;c<a.length;++c)this.arrayCopy(a[c],0,d,e),e+=a[c].length;return d},this.int8BitArrayToByteString=function(a,b,c){if(null===a||void 0==a)return a;void 0===b&&(b=0),void 0===c&&(c=a.length-b);for(var d="",e=b,f=b+c;e<f;e+=1)d+=String.fromCharCode(255&a[e]);return d},this.byteStringToInt8BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){for(var c=a.length,d=b&&b.length===c?b:new(b?b.constructor:Array)(c),e=0;e<c;e+=1)d[e]=255&a.charCodeAt(e);return d}},this.byteStringToSignedInt8BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){for(var c=a.length,d=b&&b.length===c?b:new(b?b.constructor:Array)(c),e=0;e<c;e+=1){var f=255&a.charCodeAt(e);d[e]=f<128?f:f-256}return d}},this.int16BitArrayToByteString=function(a,b,c){if(null===a||void 0==a)return a;void 0===b&&(b=0),void 0===c&&(c=a.length-b);for(var d="",e=b,f=b+c;e<f;e+=1)d+=String.fromCharCode(255&a[e])+String.fromCharCode(a[e]>>8&255);return d},this.byteStringToInt16BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){for(var c=a.length/2|0,d=b&&b.length===c?b:new(b?b.constructor:Array)(c),e=0,f=0;e<c;e+=1,f+=2)d[e]=255&a.charCodeAt(f)|(255&a.charCodeAt(f+1))<<8;return d}},this.byteStringToSignedInt16BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){for(var c=a.length/2|0,d=b&&b.length===c?b:new(b?b.constructor:Array)(c),e=0,f=0;e<c;e+=1,f+=2){var g=255&a.charCodeAt(f)|(255&a.charCodeAt(f+1))<<8;d[e]=g<32768?g:g-65536}return d}},this.int32BitArrayToByteString=function(a,b,c){if(null===a||void 0==a)return a;void 0===b&&(b=0),void 0===c&&(c=a.length-b);for(var d="",e=b,f=b+c;e<f;e+=1)d+=String.fromCharCode(255&a[e])+String.fromCharCode(a[e]>>8&255)+String.fromCharCode(a[e]>>16&255)+String.fromCharCode(a[e]>>24&255);return d},this.byteStringToInt32BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){for(var c=a.length/4|0,d=b&&b.length===c?b:new(b?b.constructor:Array)(c),e=0,f=0;e<c;e+=1,f+=4)d[e]=255&a.charCodeAt(f)|(255&a.charCodeAt(f+1))<<8|(255&a.charCodeAt(f+2))<<16|(255&a.charCodeAt(f+3))<<24;return d}},this.storeInt8BitArrayToStringBase64=function(a){return null===a||void 0===a?a:0===a.length?"":btoa(this.int8BitArrayToByteString(a))},this.restoreStringBase64ToInt8BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?[]:this.byteStringToInt8BitArray(atob(a),b)},this.restoreStringBase64ToSignedInt8BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?[]:this.byteStringToSignedInt8BitArray(atob(a),b)},this.compressInt8BitArrayToStringBase64=function(a,b,c){return null===a||void 0===a?a:0===a.length?"":(b||(b=a.length),c|=0,c||b<a.length?btoa(this.int8BitArrayToByteString(JSZip.compressions.DEFLATE.compress(a.slice(c,c+b)))):btoa(this.int8BitArrayToByteString(JSZip.compressions.DEFLATE.compress(a))))},this.uncompressStringBase64ToInt8BitArray=function(a,b,c,d,e){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a){if(""==a)return[];var f=JSZip.compressions.DEFLATE.uncompress(atob(a));return b&&(c||b.length===f.length)?this.arrayCopy(f,0,b,e):this.arrayCopy(f,0,new(d||(b?b.constructor:Array))(f.length),e)}},this.storeInt16BitArrayToStringBase64=function(a){return null===a||void 0===a?a:0===a.length?"":btoa(this.int16BitArrayToByteString(a))},this.restoreStringBase64ToInt16BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?[]:this.byteStringToInt16BitArray(atob(a),b)},this.restoreStringBase64ToSignedInt16BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?[]:this.byteStringToSignedInt16BitArray(atob(a),b)},this.storeInt32BitArrayToStringBase64=function(a){return null===a||void 0===a?a:0===a.length?"":btoa(this.int32BitArrayToByteString(a))},this.restoreStringBase64ToInt32BitArray=function(a,b){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?[]:this.byteStringToInt32BitArray(atob(a),b)},this.compressStringToStringBase64=function(a){return null===a||void 0===a?a:0===a.length?a:btoa(this.int8BitArrayToByteString(JSZip.compressions.DEFLATE.compress(a)))},this.uncompressStringBase64ToString=function(a){if(null===a||void 0===a)return a;if("null"==a)return null;if("undefined"!=a)return""==a?a:this.int8BitArrayToByteString(JSZip.compressions.DEFLATE.uncompress(atob(a)))},this.toHex2=function(a){if(null===a||void 0===a)return a;var b=a.toString(16);return a>=0&&b.length%2?"0"+b:b},this.toHex4=function(a){return this.toHexN(a,4)},this.toHexN=function(a,b){if(null===a||void 0===a)return a;var c=a.toString(16);return a<0?c:(b>=0||(b=2),"00000000".substr(0,b-c.length)+c)},this.escapeHtml=function(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/\//g,"&#047;").replace(/\?/g,"&#063;").replace(/\-/g,"&#045;").replace(/\|/g,"&#0124;")},this.arrayFind=function(a,b){if(a.find)return a.find(b);for(var c=0,d=a.length;c<d;++c)if(b(a[c],c,a))return a[c]},this.arrayFindIndex=function(a,b){if(a.findIndex)return a.findIndex(b);for(var c=0,d=a.length;c<d;++c)if(b(a[c],c,a))return c;return-1},this.arrayIndexOfSubArray=function(a,b,c,d){var e=b.length,f=a.length,g=d||1;a:for(var h=c;h>=0&&h<f;h+=g){for(var i=0;i<e;i+=1)if(a[h+i]!==b[i])continue a;return h}return-1},this.stringCountOccurrences=function(a,b){for(var c=0,d=0,e=a.length;d<e;++d)a[d]==b&&++c;return c},
this.stringStartsWith=function(a,b){return a.startsWith?a.startsWith(b):a.substr(0,b.length)===b},this.stringEndsWith=function(a,b){return a.endsWith?a.endsWith(b):a.substr(a.length-b.length)===b},this.checkContentIsZIP=function(a){if(a&&80===a[0]&&75===a[1])try{return new JSZip(a)}catch(a){}return null},this.getZIPFilesSorted=function(b){var c=b.file(/.+/);return c.sort(a),c},this.checkContentIsGZIP=function(a){if(!a||31!==a[0]||139!==a[1]||8!==a[2])return null;try{var b=a[3],c=2&b,d=4&b,e=8&b,f=16&b,g=10;if(d){var h=a[g++]|a[g++]<<8;g+=h}if(e)for(;0!==a[g++];);if(f)for(;0!==a[g++];);return c&&(g+=2),JSZip.compressions.DEFLATE.uncompress(a.slice(g,a.length-8))}catch(a){return null}},this.leafFilename=function(a){if(!a)return"";for(var b=a.split(WMSX.FILE_SEPARATOR_REGEX),c=b.length-1;c>=0;--c){var d=b[c].trim();if(d)return d}return""},this.leafFilenameNoExtension=function(a){var b=this.leafFilename(a),c=b.lastIndexOf(".");return c<=0?b:b.substr(0,c).trim()},this.leafFilenameOnlyExtension=function(a){var b=this.leafFilename(a),c=b.lastIndexOf(".");return c<=0?"":b.substr(c+1).trim()},this.dump=function(a,b,c,d){var e="",f=b||0;d=d||a.length,c=c||d;for(var g=0;g<d;){for(var h=0;h<c&&g<d;h++,g++){var i=a[f++];e+=void 0!=i?this.toHex2(i)+" ":"?? "}e+="\n"}console.log(e)},this.dumpN=function(a,b,c,d,e){var f="",g=c||0;e=e||a.length,d=d||e;for(var h=0;h<e;){for(var i=0;i<d&&h<e;i++,h++){var j=a[g++];f+=void 0!=j?this.toHexN(j,b)+" ":"?? "}f+="\n"}console.log(f)},this.dumpSlot=function(a,b,c,d){var e="",f=b||0;d=d||1;for(var g=0;g<d;g++){for(var h=0;h<c;h++){var i=a.read(f++);e+=void 0!=i?this.toHex2(i)+" ":"?? "}e+="\n"}console.log(e)},this.browserInfo=function(){if(this.browserInfoAvailable)return this.browserInfoAvailable;var a,b=navigator.userAgent,c=b.match(/(opera|edge|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(c[1]))return a=/\brv[ :]+(\d+)/g.exec(b)||[],this.browserInfoAvailable={name:"IE",version:a[1]||""};if("Chrome"===c[1]&&null!=(a=b.match(/\bOPR\/(\d+)/)))return this.browserInfoAvailable={name:"Opera",version:a[1]};c=c[2]?[c[1],c[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(a=b.match(/version\/(\d+)/i))&&c.splice(1,1,a[1]);var d=c[0].toUpperCase();return this.browserInfoAvailable={name:this.isIOSDevice()||"NETSCAPE"===d?"SAFARI":d,version:c[1]}},this.userLanguage=function(){return(navigator.languages&&navigator.languages[0]||navigator.language||navigator.userLanguage||"en-US").trim()},this.browserCurrentURL=function(){return window.location.origin+window.location.pathname},this.isOfficialHomepage=function(){var a=window.location;return a&&"webmsx.org"===a.hostname.toLowerCase()&&(""===a.port||"80"===a.port)},this.isTouchDevice=function(){return WMSX.TOUCH_MODE>0||"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0},this.isMobileDevice=function(){return WMSX.MOBILE_MODE>0||0===WMSX.MOBILE_MODE&&this.isTouchDevice()&&(/android|blackberry|iemobile|windows mobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent)||navigator.maxTouchPoints>1&&void 0!==window.orientation&&null!==window.orientation)},this.isIOSDevice=function(){return/ipad|iphone|ipod/i.test(navigator.userAgent)},this.isAndroidDevice=function(){return/android/i.test(navigator.userAgent)},this.isBrowserStandaloneMode=function(){return navigator.standalone||window.matchMedia("(display-mode: standalone)").matches},this.onTapOrMouseDown=function(a,b){this.addEventsListener(a,this.isTouchDevice()?"touchstart mousedown":"mousedown",b)},this.onTapOrMouseDownWithBlock=function(a,c){function d(a){return c(a),b(a)}this.addEventsListener(a,this.isTouchDevice()?"touchstart mousedown":"mousedown",d)},this.onTapOrMouseUpWithBlock=function(a,c){function d(a){return c(a),b(a)}this.addEventsListener(a,this.isTouchDevice()?"touchstart mouseup":"mouseup",d)},this.onTapOrMouseDownWithBlockUIG=function(a,c){function d(a){if("touchend"===a.type&&!a.target.wmsxNeedsUIG)return b(a);var d="touchstart"===a.type&&a.target.wmsxNeedsUIG,e="touchend"===a.type;return c(a,d,e),b(a)}this.addEventsListener(a,this.isTouchDevice()?"touchstart touchend mousedown":"mousedown",d)},this.blockEvent=b,this.addEventsListener=function(a,b,c,d){b=b.split(" ");for(var e=0;e<b.length;++e)b[e]&&a.addEventListener(b[e],c,d)},this.removeEventsListener=function(a,b,c,d){b=b.split(" ");for(var e=0;e<b.length;++e)b[e]&&a.removeEventListener(b[e],c,d)},this.insertCSS=function(a,b){var c=a.createElement("style");c.type="text/css",c.innerHTML=b,a.head.appendChild(c)},this.scaleToFitParentHeight=function(a,b,c){var d=b.clientHeight-c-20,e=a.clientHeight,f=e<d?1:d/e;a.style.transform="translateY(-"+(c/2|0)+"px) scale("+f.toFixed(4)+")"},this.scaleToFitParentWidth=function(a,b,c){var d=b.clientWidth-(2*c|0),e=a.clientWidth,f=e<d?1:d/e,g=e*f|0,h=Math.floor((d-g)/2+c);a.style.left=h+"px",a.style.right="initial",a.style.transform="scale("+f.toFixed(4)+")"},this.log2=function(a){return Math.log(a)/Math.log(2)},this.exp2=function(a){return Math.pow(2,a)},this.performanceNow=function(){return c?Date.now()-c:window.performance.now()},this.applyPatchObject=function(a,b){if(!a||a.constructor!==Object||b.constructor!==Object)return b;b._clear&&(a={});for(var c in b)if("_clear"!==c){var d=b[c];null===d?delete a[c]:a[c]=this.applyPatchObject(a[c],d)}return a};var c=window.performance&&window.performance.now?void 0:Date.now()},wmsx.Util.sha1Generator={hex_chr:"0123456789abcdef",hex:function(a){for(var b="",c=7;c>=0;c--)b+=this.hex_chr.charAt(a>>4*c&15);return b},str2blks_SHA1:function(a){for(var b=1+(a.length+8>>6),c=new Array(16*b),d=0;d<16*b;d++)c[d]=0;for(d=0;d<a.length;d++)c[d>>2]|=a.charCodeAt(d)<<24-d%4*8;return c[d>>2]|=128<<24-d%4*8,c[16*b-1]=8*a.length,c},add:function(a,b){var c=(65535&a)+(65535&b);return(a>>16)+(b>>16)+(c>>16)<<16|65535&c},rol:function(a,b){return a<<b|a>>>32-b},ft:function(a,b,c,d){return a<20?b&c|~b&d:a<40?b^c^d:a<60?b&c|b&d|c&d:b^c^d},kt:function(a){return a<20?1518500249:a<40?1859775393:a<60?-1894007588:-899497514},calcSHA1FromByteArray:function(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a[c]);return this.calcSHA1(b)},calcSHA1:function(a){if(""!=a){for(var b,c=this.str2blks_SHA1(a),d=new Array(80),e=1732584193,f=-271733879,g=-1732584194,h=271733878,i=-1009589776,j=0;j<c.length;j+=16){for(var k=e,l=f,m=g,n=h,o=i,p=0;p<80;p++)d[p]=p<16?c[j+p]:this.rol(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),b=this.add(this.add(this.rol(e,5),this.ft(p,f,g,h)),this.add(this.add(i,d[p]),this.kt(p))),i=h,h=g,g=this.rol(f,30),f=e,e=b;e=this.add(e,k),f=this.add(f,l),g=this.add(g,m),h=this.add(h,n),i=this.add(i,o)}return this.hex(e)+this.hex(f)+this.hex(g)+this.hex(h)+this.hex(i)}return""}},function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.JSZip=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c||a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";c.encode=function(a){for(var b,c,e,f,g,h,i,j="",k=0;k<a.length;)b=a.charCodeAt(k++),c=a.charCodeAt(k++),e=a.charCodeAt(k++),f=b>>2,g=(3&b)<<4|c>>4,h=(15&c)<<2|e>>6,i=63&e,isNaN(c)?h=i=64:isNaN(e)&&(i=64),j=j+d.charAt(f)+d.charAt(g)+d.charAt(h)+d.charAt(i);return j},c.decode=function(a){var b,c,e,f,g,h,i,j="",k=0
;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");k<a.length;)f=d.indexOf(a.charAt(k++)),g=d.indexOf(a.charAt(k++)),h=d.indexOf(a.charAt(k++)),i=d.indexOf(a.charAt(k++)),b=f<<2|g>>4,c=(15&g)<<4|h>>2,e=(3&h)<<6|i,j+=String.fromCharCode(b),64!=h&&(j+=String.fromCharCode(c)),64!=i&&(j+=String.fromCharCode(e));return j}},{}],2:[function(a,b){"use strict";function c(){this.compressedSize=0,this.uncompressedSize=0,this.crc32=0,this.compressionMethod=null,this.compressedContent=null}c.prototype={getContent:function(){return null},getCompressedContent:function(){return null}},b.exports=c},{}],3:[function(a,b,c){"use strict";c.STORE={magic:"\0\0",compress:function(a){return a},uncompress:function(a){return a},compressInputType:null,uncompressInputType:null},c.DEFLATE=a("./flate")},{"./flate":8}],4:[function(a,b){"use strict";var c=a("./utils"),d=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];b.exports=function(a,b){if(void 0===a||!a.length)return 0;var e="string"!==c.getTypeOf(a);void 0===b&&(b=0);var f=0,g=0,h=0;b^=-1;for(var i=0,j=a.length;j>i;i++)h=e?a[i]:a.charCodeAt(i),g=255&(b^h),f=d[g],b=b>>>8^f;return-1^b}},{"./utils":21}],5:[function(a,b){"use strict";function c(){this.data=null,this.length=0,this.index=0}var d=a("./utils");c.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<a||0>a)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(){},readInt:function(a){var b,c=0;for(this.checkOffset(a),b=this.index+a-1;b>=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return d.transformTo("string",this.readData(a))},readData:function(){},lastIndexOfSignature:function(){},readDate:function(){var a=this.readInt(4);return new Date(1980+(a>>25&127),(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1)}},b.exports=c},{"./utils":21}],6:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.createFolders=!1,c.date=null,c.compression=null,c.comment=null},{}],7:[function(a,b,c){"use strict";var d=a("./utils");c.string2binary=function(a){return d.string2binary(a)},c.string2Uint8Array=function(a){return d.transformTo("uint8array",a)},c.uint8Array2String=function(a){return d.transformTo("string",a)},c.string2Blob=function(a){var b=d.transformTo("arraybuffer",a);return d.arrayBuffer2Blob(b)},c.arrayBuffer2Blob=function(a){return d.arrayBuffer2Blob(a)},c.transformTo=function(a,b){return d.transformTo(a,b)},c.getTypeOf=function(a){return d.getTypeOf(a)},c.checkSupport=function(a){return d.checkSupport(a)},c.MAX_VALUE_16BITS=d.MAX_VALUE_16BITS,c.MAX_VALUE_32BITS=d.MAX_VALUE_32BITS,c.pretty=function(a){return d.pretty(a)},c.findCompression=function(a){return d.findCompression(a)},c.isRegExp=function(a){return d.isRegExp(a)}},{"./utils":21}],8:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,e=a("pako");c.uncompressInputType=d?"uint8array":"array",c.compressInputType=d?"uint8array":"array",c.magic="\b\0",c.compress=function(a){return e.deflateRaw(a)},c.uncompress=function(a){return e.inflateRaw(a)}},{pako:24}],9:[function(a,b){"use strict";function c(a,b){return this instanceof c?(this.files={},this.comment=null,this.root="",a&&this.load(a,b),void(this.clone=function(){var a=new c;for(var b in this)"function"!=typeof this[b]&&(a[b]=this[b]);return a})):new c(a,b)}var d=a("./base64");c.prototype=a("./object"),c.prototype.load=a("./load"),c.support=a("./support"),c.defaults=a("./defaults"),c.utils=a("./deprecatedPublicUtils"),c.base64={encode:function(a){return d.encode(a)},decode:function(a){return d.decode(a)}},c.compressions=a("./compressions"),b.exports=c},{"./base64":1,"./compressions":3,"./defaults":6,"./deprecatedPublicUtils":7,"./load":10,"./object":13,"./support":17}],10:[function(a,b){"use strict";var c=a("./base64"),d=a("./zipEntries");b.exports=function(a,b){var e,f,g,h;for(b=b||{},b.base64&&(a=c.decode(a)),f=new d(a,b),e=f.files,g=0;g<e.length;g++)h=e[g],this.file(h.fileName,h.decompressed,{binary:!0,optimizedBinaryString:!0,date:h.date,dir:h.dir,comment:h.fileComment.length?h.fileComment:null,createFolders:b.createFolders});return f.zipComment.length&&(this.comment=f.zipComment),this}},{"./base64":1,"./zipEntries":22}],11:[function(a,b){(function(a){"use strict";b.exports=function(b,c){return new a(b,c)},b.exports.test=function(b){return a.isBuffer(b)}}).call(this,"undefined"!=typeof Buffer?Buffer:void 0)},{}],12:[function(a,b){"use strict";function c(a){this.data=a,this.length=this.data.length,this.index=0}var d=a("./uint8ArrayReader");c.prototype=new d,c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./uint8ArrayReader":18}],13:[function(a,b){"use strict"
;var c=a("./support"),d=a("./utils"),e=a("./crc32"),f=a("./signature"),g=a("./defaults"),h=a("./base64"),i=a("./compressions"),j=a("./compressedObject"),k=a("./nodeBuffer"),l=a("./utf8"),m=a("./stringWriter"),n=a("./uint8ArrayWriter"),o=function(a){if(a._data instanceof j&&(a._data=a._data.getContent(),a.options.binary=!0,a.options.base64=!1,"uint8array"===d.getTypeOf(a._data))){var b=a._data;a._data=new Uint8Array(b.length),0!==b.length&&a._data.set(b,0)}return a._data},p=function(a){var b=o(a);return"string"===d.getTypeOf(b)?!a.options.binary&&c.nodebuffer?k(b,"utf-8"):a.asBinary():b},q=function(a){var b=o(this);return null===b||void 0===b?"":(this.options.base64&&(b=h.decode(b)),b=a&&this.options.binary?A.utf8decode(b):d.transformTo("string",b),a||this.options.binary||(b=d.transformTo("string",A.utf8encode(b))),b)},r=function(a,b,c){this.name=a,this.dir=c.dir,this.date=c.date,this.comment=c.comment,this._data=b,this.options=c,this._initialMetadata={dir:c.dir,date:c.date}};r.prototype={asText:function(){return q.call(this,!0)},asBinary:function(){return q.call(this,!1)},asNodeBuffer:function(){var a=p(this);return d.transformTo("nodebuffer",a)},asUint8Array:function(){var a=p(this);return d.transformTo("uint8array",a)},asArrayBuffer:function(){return this.asUint8Array().buffer}};var s=function(a,b){var c,d="";for(c=0;b>c;c++)d+=String.fromCharCode(255&a),a>>>=8;return d},t=function(){var a,b,c={};for(a=0;a<arguments.length;a++)for(b in arguments[a])arguments[a].hasOwnProperty(b)&&void 0===c[b]&&(c[b]=arguments[a][b]);return c},u=function(a){return a=a||{},!0!==a.base64||null!==a.binary&&void 0!==a.binary||(a.binary=!0),a=t(a,g),a.date=a.date||new Date,null!==a.compression&&(a.compression=a.compression.toUpperCase()),a},v=function(a,b,c){var e,f=d.getTypeOf(b);if(c=u(c),c.createFolders&&(e=w(a))&&x.call(this,e,!0),c.dir||null===b||void 0===b)c.base64=!1,c.binary=!1,b=null;else if("string"===f)c.binary&&!c.base64&&!0!==c.optimizedBinaryString&&(b=d.string2binary(b));else{if(c.base64=!1,c.binary=!0,!(f||b instanceof j))throw new Error("The data of '"+a+"' is in an unsupported format !");"arraybuffer"===f&&(b=d.transformTo("uint8array",b))}var g=new r(a,b,c);return this.files[a]=g,g},w=function(a){"/"==a.slice(-1)&&(a=a.substring(0,a.length-1));var b=a.lastIndexOf("/");return b>0?a.substring(0,b):""},x=function(a,b){return"/"!=a.slice(-1)&&(a+="/"),b=void 0!==b&&b,this.files[a]||v.call(this,a,null,{dir:!0,createFolders:b}),this.files[a]},y=function(a,b){var c,f=new j;return a._data instanceof j?(f.uncompressedSize=a._data.uncompressedSize,f.crc32=a._data.crc32,0===f.uncompressedSize||a.dir?(b=i.STORE,f.compressedContent="",f.crc32=0):a._data.compressionMethod===b.magic?f.compressedContent=a._data.getCompressedContent():(c=a._data.getContent(),f.compressedContent=b.compress(d.transformTo(b.compressInputType,c)))):(c=p(a),(!c||0===c.length||a.dir)&&(b=i.STORE,c=""),f.uncompressedSize=c.length,f.crc32=e(c),f.compressedContent=b.compress(d.transformTo(b.compressInputType,c))),f.compressedSize=f.compressedContent.length,f.compressionMethod=b.magic,f},z=function(a,b,c,g){var h,i,j,k,m=(c.compressedContent,d.transformTo("string",l.utf8encode(b.name))),n=b.comment||"",o=d.transformTo("string",l.utf8encode(n)),p=m.length!==b.name.length,q=o.length!==n.length,r=b.options,t="",u="",v="";j=b._initialMetadata.dir!==b.dir?b.dir:r.dir,k=b._initialMetadata.date!==b.date?b.date:r.date,h=k.getHours(),h<<=6,h|=k.getMinutes(),h<<=5,h|=k.getSeconds()/2,i=k.getFullYear()-1980,i<<=4,i|=k.getMonth()+1,i<<=5,i|=k.getDate(),p&&(u=s(1,1)+s(e(m),4)+m,t+="up"+s(u.length,2)+u),q&&(v=s(1,1)+s(this.crc32(o),4)+o,t+="uc"+s(v.length,2)+v);var w="";return w+="\n\0",w+=p||q?"\0\b":"\0\0",w+=c.compressionMethod,w+=s(h,2),w+=s(i,2),w+=s(c.crc32,4),w+=s(c.compressedSize,4),w+=s(c.uncompressedSize,4),w+=s(m.length,2),w+=s(t.length,2),{fileRecord:f.LOCAL_FILE_HEADER+w+m+t,dirRecord:f.CENTRAL_FILE_HEADER+"\0"+w+s(o.length,2)+"\0\0\0\0"+(!0===j?"\0\0\0":"\0\0\0\0")+s(g,4)+m+t+o,compressedObject:c}},A={load:function(){throw new Error("Load method is not defined. Is the file jszip-load.js included ?")},filter:function(a){var b,c,d,e,f=[];for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],e=new r(d.name,d._data,t(d.options)),c=b.slice(this.root.length,b.length),b.slice(0,this.root.length)===this.root&&a(c,e)&&f.push(e));return f},file:function(a,b,c){if(1===arguments.length){if(d.isRegExp(a)){var e=a;return this.filter(function(a,b){return!b.dir&&e.test(a)})}return this.filter(function(b,c){return!c.dir&&b===a})[0]||null}return a=this.root+a,v.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(d.isRegExp(a))return this.filter(function(b,c){return c.dir&&a.test(b)});var b=this.root+a,c=x.call(this,b),e=this.clone();return e.root=c.name,e},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!=a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d<c.length;d++)delete this.files[c[d].name];return this},generate:function(a){a=t(a||{},{base64:!0,compression:"STORE",type:"base64",comment:null}),d.checkSupport(a.type);var b,c,e=[],g=0,j=0,k=d.transformTo("string",this.utf8encode(a.comment||this.comment||""));for(var l in this.files)if(this.files.hasOwnProperty(l)){var o=this.files[l],p=o.options.compression||a.compression.toUpperCase(),q=i[p];if(!q)throw new Error(p+" is not a valid compression method !");var r=y.call(this,o,q),u=z.call(this,l,o,r,g);g+=u.fileRecord.length+r.compressedSize,j+=u.dirRecord.length,e.push(u)}var v="";v=f.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(e.length,2)+s(e.length,2)+s(j,4)+s(g,4)+s(k.length,2)+k;var w=a.type.toLowerCase();for(b="uint8array"===w||"arraybuffer"===w||"blob"===w||"nodebuffer"===w?new n(g+j+v.length):new m(g+j+v.length),c=0;c<e.length;c++)b.append(e[c].fileRecord),b.append(e[c].compressedObject.compressedContent);for(c=0;c<e.length;c++)b.append(e[c].dirRecord);b.append(v);var x=b.finalize();switch(a.type.toLowerCase()){case"uint8array":case"arraybuffer":case"nodebuffer":return d.transformTo(a.type.toLowerCase(),x);case"blob":return d.arrayBuffer2Blob(d.transformTo("arraybuffer",x));case"base64":return a.base64?h.encode(x):x;default:return x}},crc32:function(a,b){return e(a,b)},utf8encode:function(a){return d.transformTo("string",l.utf8encode(a))},utf8decode:function(a){return l.utf8decode(a)}};b.exports=A},{"./base64":1,"./compressedObject":2,"./compressions":3,"./crc32":4,"./defaults":6,"./nodeBuffer":11,"./signature":14,"./stringWriter":16,"./support":17,"./uint8ArrayWriter":19,"./utf8":20,"./utils":21}],14:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],15:[function(a,b){"use strict";function c(a,b){this.data=a,b||(this.data=e.string2binary(this.data)),this.length=this.data.length,this.index=0}var d=a("./dataReader"),e=a("./utils");c.prototype=new d,c.prototype.byteAt=function(a){return this.data.charCodeAt(a)},c.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)},c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":5,"./utils":21}],16:[function(a,b){"use strict";var c=a("./utils"),d=function(){this.data=[]};d.prototype={append:function(a){a=c.transformTo("string",a),this.data.push(a)},finalize:function(){return this.data.join("")}},b.exports=d},{"./utils":21}],17:[function(a,b,c){(function(a){"use strict";if(c.base64=!0,c.array=!0,c.string=!0,c.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,c.nodebuffer=void 0!==a,c.uint8array="undefined"!=typeof Uint8Array,
"undefined"==typeof ArrayBuffer)c.blob=!1;else{var b=new ArrayBuffer(0);try{c.blob=0===new Blob([b],{type:"application/zip"}).size}catch(a){try{var d=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,e=new d;e.append(b),c.blob=0===e.getBlob("application/zip").size}catch(a){c.blob=!1}}}}).call(this,"undefined"!=typeof Buffer?Buffer:void 0)},{}],18:[function(a,b){"use strict";function c(a){a&&(this.data=a,this.length=this.data.length,this.index=0)}var d=a("./dataReader");c.prototype=new d,c.prototype.byteAt=function(a){return this.data[a]},c.prototype.lastIndexOfSignature=function(a){for(var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.length-4;f>=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f;return-1},c.prototype.readData=function(a){if(this.checkOffset(a),0===a)return new Uint8Array(0);var b=this.data.subarray(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":5}],19:[function(a,b){"use strict";var c=a("./utils"),d=function(a){this.data=new Uint8Array(a),this.index=0};d.prototype={append:function(a){0!==a.length&&(a=c.transformTo("uint8array",a),this.data.set(a,this.index),this.index+=a.length)},finalize:function(){return this.data}},b.exports=d},{"./utils":21}],20:[function(a,b,c){"use strict";for(var d=a("./utils"),e=a("./support"),f=a("./nodeBuffer"),g=new Array(256),h=0;256>h;h++)g[h]=h>=252?6:h>=248?5:h>=240?4:h>=224?3:h>=192?2:1;g[254]=g[254]=1;var i=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;h>f;f++)c=a.charCodeAt(f),55296==(64512&c)&&h>f+1&&56320==(64512&(d=a.charCodeAt(f+1)))&&(c=65536+(c-55296<<10)+(d-56320),f++),i+=128>c?1:2048>c?2:65536>c?3:4;for(b=e.uint8array?new Uint8Array(i):new Array(i),g=0,f=0;i>g;f++)c=a.charCodeAt(f),55296==(64512&c)&&h>f+1&&56320==(64512&(d=a.charCodeAt(f+1)))&&(c=65536+(c-55296<<10)+(d-56320),f++),128>c?b[g++]=c:2048>c?(b[g++]=192|c>>>6,b[g++]=128|63&c):65536>c?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},j=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128==(192&a[c]);)c--;return 0>c?b:0===c?b:c+g[a[c]]>b?c:b},k=function(a){var b,c,e,f,h=a.length,i=new Array(2*h);for(c=0,b=0;h>b;)if(128>(e=a[b++]))i[c++]=e;else if((f=g[e])>4)i[c++]=65533,b+=f-1;else{for(e&=2===f?31:3===f?15:7;f>1&&h>b;)e=e<<6|63&a[b++],f--;f>1?i[c++]=65533:65536>e?i[c++]=e:(e-=65536,i[c++]=55296|e>>10&1023,i[c++]=56320|1023&e)}return i.length!==c&&(i.subarray?i=i.subarray(0,c):i.length=c),d.applyFromCharCode(i)};c.utf8encode=function(a){return e.nodebuffer?f(a,"utf-8"):i(a)},c.utf8decode=function(a){if(e.nodebuffer)return d.transformTo("nodebuffer",a).toString("utf-8");a=d.transformTo(e.uint8array?"uint8array":"array",a);for(var b=[],c=0,f=a.length;f>c;){var g=j(a,Math.min(c+65536,f));b.push(k(e.uint8array?a.subarray(c,g):a.slice(c,g))),c=g}return b.join("")}},{"./nodeBuffer":11,"./support":17,"./utils":21}],21:[function(a,b,c){"use strict";function d(a){return a}function e(a,b){for(var c=0;c<a.length;++c)b[c]=255&a.charCodeAt(c);return b}function f(a){var b=65536,d=[],e=a.length,f=c.getTypeOf(a),g=0,h=!0;try{switch(f){case"uint8array":String.fromCharCode.apply(null,new Uint8Array(0));break;case"nodebuffer":String.fromCharCode.apply(null,j(0))}}catch(a){h=!1}if(!h){for(var i="",k=0;k<a.length;k++)i+=String.fromCharCode(a[k]);return i}for(;e>g&&b>1;)try{d.push("array"===f||"nodebuffer"===f?String.fromCharCode.apply(null,a.slice(g,Math.min(g+b,e))):String.fromCharCode.apply(null,a.subarray(g,Math.min(g+b,e)))),g+=b}catch(a){b=Math.floor(b/2)}return d.join("")}function g(a,b){for(var c=0;c<a.length;c++)b[c]=a[c];return b}var h=a("./support"),i=a("./compressions"),j=a("./nodeBuffer");c.string2binary=function(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(255&a.charCodeAt(c));return b},c.arrayBuffer2Blob=function(a){c.checkSupport("blob");try{return new Blob([a],{type:"application/zip"})}catch(c){try{var b=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,d=new b;return d.append(a),d.getBlob("application/zip")}catch(a){throw new Error("Bug : can't construct the Blob.")}}},c.applyFromCharCode=f;var k={};k.string={string:d,array:function(a){return e(a,new Array(a.length))},arraybuffer:function(a){return k.string.uint8array(a).buffer},uint8array:function(a){return e(a,new Uint8Array(a.length))},nodebuffer:function(a){return e(a,j(a.length))}},k.array={string:f,array:d,arraybuffer:function(a){return new Uint8Array(a).buffer},uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return j(a)}},k.arraybuffer={string:function(a){return f(new Uint8Array(a))},array:function(a){return g(new Uint8Array(a),new Array(a.byteLength))},arraybuffer:d,uint8array:function(a){return new Uint8Array(a)},nodebuffer:function(a){return j(new Uint8Array(a))}},k.uint8array={string:f,array:function(a){return g(a,new Array(a.length))},arraybuffer:function(a){return a.buffer},uint8array:d,nodebuffer:function(a){return j(a)}},k.nodebuffer={string:f,array:function(a){return g(a,new Array(a.length))},arraybuffer:function(a){return k.nodebuffer.uint8array(a).buffer},uint8array:function(a){return g(a,new Uint8Array(a.length))},nodebuffer:d},c.transformTo=function(a,b){if(b||(b=""),!a)return b;c.checkSupport(a);var d=c.getTypeOf(b);return k[d][a](b)},c.getTypeOf=function(a){return"string"==typeof a?"string":"[object Array]"===Object.prototype.toString.call(a)?"array":h.nodebuffer&&j.test(a)?"nodebuffer":h.uint8array&&a instanceof Uint8Array?"uint8array":h.arraybuffer&&a instanceof ArrayBuffer?"arraybuffer":void 0},c.checkSupport=function(a){if(!h[a.toLowerCase()])throw new Error(a+" is not supported by this browser")},c.MAX_VALUE_16BITS=65535,c.MAX_VALUE_32BITS=-1,c.pretty=function(a){var b,c,d="";for(c=0;c<(a||"").length;c++)b=a.charCodeAt(c),d+="\\x"+(16>b?"0":"")+b.toString(16).toUpperCase();return d},c.findCompression=function(a){for(var b in i)if(i.hasOwnProperty(b)&&i[b].magic===a)return i[b];return null},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)}},{"./compressions":3,"./nodeBuffer":11,"./support":17}],22:[function(a,b){"use strict";function c(a,b){this.files=[],this.loadOptions=b,a&&this.load(a)}var d=a("./stringReader"),e=a("./nodeBufferReader"),f=a("./uint8ArrayReader"),g=a("./utils"),h=a("./signature"),i=a("./zipEntry"),j=a("./support"),k=a("./object");c.prototype={checkSignature:function(a){var b=this.reader.readString(4);if(b!==a)throw new Error("Corrupted zip or bug : unexpected signature ("+g.pretty(b)+", expected "+g.pretty(a)+")")},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2),this.zipComment=this.reader.readString(this.zipCommentLength),this.zipComment=k.utf8decode(this.zipComment)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.versionMadeBy=this.reader.readString(2),this.versionNeeded=this.reader.readInt(2),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var a,b,c,d=this.zip64EndOfCentralSize-44;d>0;)a=this.reader.readInt(2),b=this.reader.readInt(4),c=this.reader.readString(b),this.zip64ExtensibleData[a]={id:a,length:b,value:c}},
readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),this.disksCount>1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var a,b;for(a=0;a<this.files.length;a++)b=this.files[a],this.reader.setIndex(b.localHeaderOffset),this.checkSignature(h.LOCAL_FILE_HEADER),b.readLocalPart(this.reader),b.handleUTF8()},readCentralDir:function(){var a;for(this.reader.setIndex(this.centralDirOffset);this.reader.readString(4)===h.CENTRAL_FILE_HEADER;)a=new i({zip64:this.zip64},this.loadOptions),a.readCentralPart(this.reader),this.files.push(a)},readEndOfCentral:function(){var a=this.reader.lastIndexOfSignature(h.CENTRAL_DIRECTORY_END);if(-1===a)throw new Error("Corrupted zip : can't find end of central directory");if(this.reader.setIndex(a),this.checkSignature(h.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===g.MAX_VALUE_16BITS||this.diskWithCentralDirStart===g.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===g.MAX_VALUE_16BITS||this.centralDirRecords===g.MAX_VALUE_16BITS||this.centralDirSize===g.MAX_VALUE_32BITS||this.centralDirOffset===g.MAX_VALUE_32BITS){if(this.zip64=!0,-1===(a=this.reader.lastIndexOfSignature(h.ZIP64_CENTRAL_DIRECTORY_LOCATOR)))throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator");this.reader.setIndex(a),this.checkSignature(h.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(h.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}},prepareReader:function(a){var b=g.getTypeOf(a);this.reader="string"!==b||j.uint8array?"nodebuffer"===b?new e(a):new f(g.transformTo("uint8array",a)):new d(a,this.loadOptions.optimizedBinaryString)},load:function(a){this.prepareReader(a),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},b.exports=c},{"./nodeBufferReader":12,"./object":13,"./signature":14,"./stringReader":15,"./support":17,"./uint8ArrayReader":18,"./utils":21,"./zipEntry":23}],23:[function(a,b){"use strict";function c(a,b){this.options=a,this.loadOptions=b}var d=a("./stringReader"),e=a("./utils"),f=a("./compressedObject"),g=a("./object");c.prototype={isEncrypted:function(){return 1==(1&this.bitFlag)},useUTF8:function(){return 2048==(2048&this.bitFlag)},prepareCompressedContent:function(a,b,c){return function(){var d=a.index;a.setIndex(b);var e=a.readData(c);return a.setIndex(d),e}},prepareContent:function(a,b,c,d,f){return function(){var a=e.transformTo(d.uncompressInputType,this.getCompressedContent()),b=d.uncompress(a);if(b.length!==f)throw new Error("Bug : uncompressed data size mismatch");return b}},readLocalPart:function(a){var b,c;if(a.skip(22),this.fileNameLength=a.readInt(2),c=a.readInt(2),this.fileName=a.readString(this.fileNameLength),a.skip(c),-1==this.compressedSize||-1==this.uncompressedSize)throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize == -1 || uncompressedSize == -1)");if(null===(b=e.findCompression(this.compressionMethod)))throw new Error("Corrupted zip : compression "+e.pretty(this.compressionMethod)+" unknown (inner file : "+this.fileName+")");if(this.decompressed=new f,this.decompressed.compressedSize=this.compressedSize,this.decompressed.uncompressedSize=this.uncompressedSize,this.decompressed.crc32=this.crc32,this.decompressed.compressionMethod=this.compressionMethod,this.decompressed.getCompressedContent=this.prepareCompressedContent(a,a.index,this.compressedSize,b),this.decompressed.getContent=this.prepareContent(a,a.index,this.compressedSize,b,this.uncompressedSize),this.loadOptions.checkCRC32&&(this.decompressed=e.transformTo("string",this.decompressed.getContent()),g.crc32(this.decompressed)!==this.crc32))throw new Error("Corrupted zip : CRC32 mismatch")},readCentralPart:function(a){if(this.versionMadeBy=a.readString(2),this.versionNeeded=a.readInt(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4),this.fileNameLength=a.readInt(2),this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");this.fileName=a.readString(this.fileNameLength),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readString(this.fileCommentLength),this.dir=!!(16&this.externalFileAttributes)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var a=new d(this.extraFields[1].value);this.uncompressedSize===e.MAX_VALUE_32BITS&&(this.uncompressedSize=a.readInt(8)),this.compressedSize===e.MAX_VALUE_32BITS&&(this.compressedSize=a.readInt(8)),this.localHeaderOffset===e.MAX_VALUE_32BITS&&(this.localHeaderOffset=a.readInt(8)),this.diskNumberStart===e.MAX_VALUE_32BITS&&(this.diskNumberStart=a.readInt(4))}},readExtraFields:function(a){var b,c,d,e=a.index;for(this.extraFields=this.extraFields||{};a.index<e+this.extraFieldsLength;)b=a.readInt(2),c=a.readInt(2),d=a.readString(c),this.extraFields[b]={id:b,length:c,value:d}},handleUTF8:function(){if(this.useUTF8())this.fileName=g.utf8decode(this.fileName),this.fileComment=g.utf8decode(this.fileComment);else{var a=this.findExtraFieldUnicodePath();null!==a&&(this.fileName=a);var b=this.findExtraFieldUnicodeComment();null!==b&&(this.fileComment=b)}},findExtraFieldUnicodePath:function(){var a=this.extraFields[28789];if(a){var b=new d(a.value);return 1!==b.readInt(1)?null:g.crc32(this.fileName)!==b.readInt(4)?null:g.utf8decode(b.readString(a.length-5))}return null},findExtraFieldUnicodeComment:function(){var a=this.extraFields[25461];if(a){var b=new d(a.value);return 1!==b.readInt(1)?null:g.crc32(this.fileComment)!==b.readInt(4)?null:g.utf8decode(b.readString(a.length-5))}return null}},b.exports=c},{"./compressedObject":2,"./object":13,"./stringReader":15,"./utils":21}],24:[function(a,b){"use strict";var c=a("./lib/utils/common").assign,d=a("./lib/deflate"),e=a("./lib/inflate"),f=a("./lib/zlib/constants"),g={};c(g,d,e,f),b.exports=g},{"./lib/deflate":25,"./lib/inflate":26,"./lib/utils/common":27,"./lib/zlib/constants":30}],25:[function(a,b,c){"use strict";function d(a,b){var c=new l(b);if(c.push(a,!0),c.err)throw c.msg;return c.result}function e(a,b){return b=b||{},b.raw=!0,d(a,b)}function f(a,b){return b=b||{},b.gzip=!0,d(a,b)}var g=a("./zlib/deflate.js"),h=a("./utils/common"),i=a("./utils/strings"),j=a("./zlib/messages"),k=a("./zlib/zstream"),l=function(a){this.options=h.assign({level:-1,method:8,chunkSize:16384,windowBits:15,memLevel:8,strategy:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>0?b.windowBits=-b.windowBits:b.gzip&&b.windowBits>0&&b.windowBits<16&&(b.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new k,this.strm.avail_out=0;var c=g.deflateInit2(this.strm,b.level,b.method,b.windowBits,b.memLevel,b.strategy);if(0!==c)throw new Error(j[c]);b.header&&g.deflateSetHeader(this.strm,b.header)};l.prototype.push=function(a,b){var c,d,e=this.strm,f=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:!0===b?4:0,e.input="string"==typeof a?i.string2buf(a):a,e.next_in=0,e.avail_in=e.input.length;do{if(0===e.avail_out&&(e.output=new h.Buf8(f),e.next_out=0,e.avail_out=f),1!==(c=g.deflate(e,d))&&0!==c)return this.onEnd(c),this.ended=!0,!1;(0===e.avail_out||0===e.avail_in&&4===d)&&this.onData("string"===this.options.to?i.buf2binstring(h.shrinkBuf(e.output,e.next_out)):h.shrinkBuf(e.output,e.next_out))}while((e.avail_in>0||0===e.avail_out)&&1!==c)
;return 4!==d||(c=g.deflateEnd(this.strm),this.onEnd(c),this.ended=!0,0===c)},l.prototype.onData=function(a){this.chunks.push(a)},l.prototype.onEnd=function(a){0===a&&(this.result="string"===this.options.to?this.chunks.join(""):h.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Deflate=l,c.deflate=d,c.deflateRaw=e,c.gzip=f},{"./utils/common":27,"./utils/strings":28,"./zlib/deflate.js":32,"./zlib/messages":37,"./zlib/zstream":39}],26:[function(a,b,c){"use strict";function d(a,b){var c=new m(b);if(c.push(a,!0),c.err)throw c.msg;return c.result}function e(a,b){return b=b||{},b.raw=!0,d(a,b)}var f=a("./zlib/inflate.js"),g=a("./utils/common"),h=a("./utils/strings"),i=a("./zlib/constants"),j=a("./zlib/messages"),k=a("./zlib/zstream"),l=a("./zlib/gzheader"),m=function(a){this.options=g.assign({chunkSize:16384,windowBits:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>=0&&b.windowBits<16&&(b.windowBits=-b.windowBits,0===b.windowBits&&(b.windowBits=-15)),!(b.windowBits>=0&&b.windowBits<16)||a&&a.windowBits||(b.windowBits+=32),b.windowBits>15&&b.windowBits<48&&0==(15&b.windowBits)&&(b.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new k,this.strm.avail_out=0;var c=f.inflateInit2(this.strm,b.windowBits);if(c!==i.Z_OK)throw new Error(j[c]);this.header=new l,f.inflateGetHeader(this.strm,this.header)};m.prototype.push=function(a,b){var c,d,e,j,k,l=this.strm,m=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:!0===b?i.Z_FINISH:i.Z_NO_FLUSH,l.input="string"==typeof a?h.binstring2buf(a):a,l.next_in=0,l.avail_in=l.input.length;do{if(0===l.avail_out&&(l.output=new g.Buf8(m),l.next_out=0,l.avail_out=m),(c=f.inflate(l,i.Z_NO_FLUSH))!==i.Z_STREAM_END&&c!==i.Z_OK)return this.onEnd(c),this.ended=!0,!1;l.next_out&&(0===l.avail_out||c===i.Z_STREAM_END||0===l.avail_in&&d===i.Z_FINISH)&&("string"===this.options.to?(e=h.utf8border(l.output,l.next_out),j=l.next_out-e,k=h.buf2string(l.output,e),l.next_out=j,l.avail_out=m-j,j&&g.arraySet(l.output,l.output,e,j,0),this.onData(k)):this.onData(g.shrinkBuf(l.output,l.next_out)))}while(l.avail_in>0&&c!==i.Z_STREAM_END);return c===i.Z_STREAM_END&&(d=i.Z_FINISH),d!==i.Z_FINISH||(c=f.inflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===i.Z_OK)},m.prototype.onData=function(a){this.chunks.push(a)},m.prototype.onEnd=function(a){a===i.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):g.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Inflate=m,c.inflate=d,c.inflateRaw=e,c.ungzip=d},{"./utils/common":27,"./utils/strings":28,"./zlib/constants":30,"./zlib/gzheader":33,"./zlib/inflate.js":35,"./zlib/messages":37,"./zlib/zstream":39}],27:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;c.assign=function(a){for(var b=Array.prototype.slice.call(arguments,1);b.length;){var c=b.shift();if(c){if("object"!=typeof c)throw new TypeError(c+"must be non-object");for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}}return a},c.shrinkBuf=function(a,b){return a.length===b?a:a.subarray?a.subarray(0,b):(a.length=b,a)};var e={arraySet:function(a,b,c,d,e){if(b.subarray&&a.subarray)return void a.set(b.subarray(c,c+d),e);for(var f=0;d>f;f++)a[e+f]=b[c+f]},flattenChunks:function(a){var b,c,d,e,f,g;for(d=0,b=0,c=a.length;c>b;b++)d+=a[b].length;for(g=new Uint8Array(d),e=0,b=0,c=a.length;c>b;b++)f=a[b],g.set(f,e),e+=f.length;return g}},f={arraySet:function(a,b,c,d,e){for(var f=0;d>f;f++)a[e+f]=b[c+f]},flattenChunks:function(a){return[].concat.apply([],a)}};c.setTyped=function(a){a?(c.Buf8=Uint8Array,c.Buf16=Uint16Array,c.Buf32=Int32Array,c.assign(c,e)):(c.Buf8=Array,c.Buf16=Array,c.Buf32=Array,c.assign(c,f))},c.setTyped(d)},{}],28:[function(a,b,c){"use strict";function d(a,b){if(65537>b&&(a.subarray&&g||!a.subarray&&f))return String.fromCharCode.apply(null,e.shrinkBuf(a,b));for(var c="",d=0;b>d;d++)c+=String.fromCharCode(a[d]);return c}var e=a("./common"),f=!0,g=!0;try{String.fromCharCode.apply(null,[0])}catch(a){f=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(a){g=!1}for(var h=new e.Buf8(256),i=0;256>i;i++)h[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;h[254]=h[254]=1,c.string2buf=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;h>f;f++)c=a.charCodeAt(f),55296==(64512&c)&&h>f+1&&56320==(64512&(d=a.charCodeAt(f+1)))&&(c=65536+(c-55296<<10)+(d-56320),f++),i+=128>c?1:2048>c?2:65536>c?3:4;for(b=new e.Buf8(i),g=0,f=0;i>g;f++)c=a.charCodeAt(f),55296==(64512&c)&&h>f+1&&56320==(64512&(d=a.charCodeAt(f+1)))&&(c=65536+(c-55296<<10)+(d-56320),f++),128>c?b[g++]=c:2048>c?(b[g++]=192|c>>>6,b[g++]=128|63&c):65536>c?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},c.buf2binstring=function(a){return d(a,a.length)},c.binstring2buf=function(a){for(var b=new e.Buf8(a.length),c=0,d=b.length;d>c;c++)b[c]=a.charCodeAt(c);return b},c.buf2string=function(a,b){var c,e,f,g,i=b||a.length,j=new Array(2*i);for(e=0,c=0;i>c;)if(128>(f=a[c++]))j[e++]=f;else if((g=h[f])>4)j[e++]=65533,c+=g-1;else{for(f&=2===g?31:3===g?15:7;g>1&&i>c;)f=f<<6|63&a[c++],g--;g>1?j[e++]=65533:65536>f?j[e++]=f:(f-=65536,j[e++]=55296|f>>10&1023,j[e++]=56320|1023&f)}return d(j,e)},c.utf8border=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128==(192&a[c]);)c--;return 0>c?b:0===c?b:c+h[a[c]]>b?c:b}},{"./common":27}],29:[function(a,b){"use strict";function c(a,b,c,d){for(var e=65535&a|0,f=a>>>16&65535|0,g=0;0!==c;){g=c>2e3?2e3:c,c-=g;do{e=e+b[d++]|0,f=f+e|0}while(--g);e%=65521,f%=65521}return e|f<<16|0}b.exports=c},{}],30:[function(a,b){b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],31:[function(a,b){"use strict";function c(a,b,c,e){var f=d,g=e+c;a^=-1;for(var h=e;g>h;h++)a=a>>>8^f[255&(a^b[h])];return-1^a}var d=function(){for(var a,b=[],c=0;256>c;c++){a=c;for(var d=0;8>d;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}();b.exports=c},{}],32:[function(a,b,c){"use strict";function d(a,b){return a.msg=G[b],b}function e(a){return(a<<1)-(a>4?9:0)}function f(a){for(var b=a.length;--b>=0;)a[b]=0}function g(a){var b=a.state,c=b.pending;c>a.avail_out&&(c=a.avail_out),0!==c&&(C.arraySet(a.output,b.pending_buf,b.pending_out,c,a.next_out),a.next_out+=c,b.pending_out+=c,a.total_out+=c,a.avail_out-=c,b.pending-=c,0===b.pending&&(b.pending_out=0))}function h(a,b){D._tr_flush_block(a,a.block_start>=0?a.block_start:-1,a.strstart-a.block_start,b),a.block_start=a.strstart,g(a.strm)}function i(a,b){a.pending_buf[a.pending++]=b}function j(a,b){a.pending_buf[a.pending++]=b>>>8&255,a.pending_buf[a.pending++]=255&b}function k(a,b,c,d){var e=a.avail_in;return e>d&&(e=d),0===e?0:(a.avail_in-=e,C.arraySet(b,a.input,a.next_in,e,c),1===a.state.wrap?a.adler=E(a.adler,b,e,c):2===a.state.wrap&&(a.adler=F(a.adler,b,e,c)),a.next_in+=e,a.total_in+=e,e)}function l(a,b){var c,d,e=a.max_chain_length,f=a.strstart,g=a.prev_length,h=a.nice_match,i=a.strstart>a.w_size-ha?a.strstart-(a.w_size-ha):0,j=a.window,k=a.w_mask,l=a.prev,m=a.strstart+ga,n=j[f+g-1],o=j[f+g];a.prev_length>=a.good_match&&(e>>=2),h>a.lookahead&&(h=a.lookahead);do{if(c=b,j[c+g]===o&&j[c+g-1]===n&&j[c]===j[f]&&j[++c]===j[f+1]){f+=2,c++;do{}while(j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&m>f);if(d=ga-(m-f),f=m-ga,d>g){if(a.match_start=b,g=d,d>=h)break;n=j[f+g-1],o=j[f+g]}}}while((b=l[b&k])>i&&0!=--e)
;return g<=a.lookahead?g:a.lookahead}function m(a){var b,c,d,e,f,g=a.w_size;do{if(e=a.window_size-a.lookahead-a.strstart,a.strstart>=g+(g-ha)){C.arraySet(a.window,a.window,g,g,0),a.match_start-=g,a.strstart-=g,a.block_start-=g,c=a.hash_size,b=c;do{d=a.head[--b],a.head[b]=d>=g?d-g:0}while(--c);c=g,b=c;do{d=a.prev[--b],a.prev[b]=d>=g?d-g:0}while(--c);e+=g}if(0===a.strm.avail_in)break;if(c=k(a.strm,a.window,a.strstart+a.lookahead,e),a.lookahead+=c,a.lookahead+a.insert>=fa)for(f=a.strstart-a.insert,a.ins_h=a.window[f],a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+1])&a.hash_mask;a.insert&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[f+fa-1])&a.hash_mask,a.prev[f&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=f,f++,a.insert--,!(a.lookahead+a.insert<fa)););}while(a.lookahead<ha&&0!==a.strm.avail_in)}function n(a,b){var c=65535;for(c>a.pending_buf_size-5&&(c=a.pending_buf_size-5);;){if(a.lookahead<=1){if(m(a),0===a.lookahead&&b===H)return qa;if(0===a.lookahead)break}a.strstart+=a.lookahead,a.lookahead=0;var d=a.block_start+c;if((0===a.strstart||a.strstart>=d)&&(a.lookahead=a.strstart-d,a.strstart=d,h(a,!1),0===a.strm.avail_out))return qa;if(a.strstart-a.block_start>=a.w_size-ha&&(h(a,!1),0===a.strm.avail_out))return qa}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?sa:ta):(a.strstart>a.block_start&&(h(a,!1),a.strm.avail_out),qa)}function o(a,b){for(var c,d;;){if(a.lookahead<ha){if(m(a),a.lookahead<ha&&b===H)return qa;if(0===a.lookahead)break}if(c=0,a.lookahead>=fa&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+fa-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),0!==c&&a.strstart-c<=a.w_size-ha&&(a.match_length=l(a,c)),a.match_length>=fa)if(d=D._tr_tally(a,a.strstart-a.match_start,a.match_length-fa),a.lookahead-=a.match_length,a.match_length<=a.max_lazy_match&&a.lookahead>=fa){a.match_length--;do{a.strstart++,a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+fa-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart}while(0!=--a.match_length);a.strstart++}else a.strstart+=a.match_length,a.match_length=0,a.ins_h=a.window[a.strstart],a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+1])&a.hash_mask;else d=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++;if(d&&(h(a,!1),0===a.strm.avail_out))return qa}return a.insert=a.strstart<fa-1?a.strstart:fa-1,b===K?(h(a,!0),0===a.strm.avail_out?sa:ta):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?qa:ra}function p(a,b){for(var c,d,e;;){if(a.lookahead<ha){if(m(a),a.lookahead<ha&&b===H)return qa;if(0===a.lookahead)break}if(c=0,a.lookahead>=fa&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+fa-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart),a.prev_length=a.match_length,a.prev_match=a.match_start,a.match_length=fa-1,0!==c&&a.prev_length<a.max_lazy_match&&a.strstart-c<=a.w_size-ha&&(a.match_length=l(a,c),a.match_length<=5&&(a.strategy===S||a.match_length===fa&&a.strstart-a.match_start>4096)&&(a.match_length=fa-1)),a.prev_length>=fa&&a.match_length<=a.prev_length){e=a.strstart+a.lookahead-fa,d=D._tr_tally(a,a.strstart-1-a.prev_match,a.prev_length-fa),a.lookahead-=a.prev_length-1,a.prev_length-=2;do{++a.strstart<=e&&(a.ins_h=(a.ins_h<<a.hash_shift^a.window[a.strstart+fa-1])&a.hash_mask,c=a.prev[a.strstart&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=a.strstart)}while(0!=--a.prev_length);if(a.match_available=0,a.match_length=fa-1,a.strstart++,d&&(h(a,!1),0===a.strm.avail_out))return qa}else if(a.match_available){if(d=D._tr_tally(a,0,a.window[a.strstart-1]),d&&h(a,!1),a.strstart++,a.lookahead--,0===a.strm.avail_out)return qa}else a.match_available=1,a.strstart++,a.lookahead--}return a.match_available&&(d=D._tr_tally(a,0,a.window[a.strstart-1]),a.match_available=0),a.insert=a.strstart<fa-1?a.strstart:fa-1,b===K?(h(a,!0),0===a.strm.avail_out?sa:ta):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?qa:ra}function q(a,b){for(var c,d,e,f,g=a.window;;){if(a.lookahead<=ga){if(m(a),a.lookahead<=ga&&b===H)return qa;if(0===a.lookahead)break}if(a.match_length=0,a.lookahead>=fa&&a.strstart>0&&(e=a.strstart-1,(d=g[e])===g[++e]&&d===g[++e]&&d===g[++e])){f=a.strstart+ga;do{}while(d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&f>e);a.match_length=ga-(f-e),a.match_length>a.lookahead&&(a.match_length=a.lookahead)}if(a.match_length>=fa?(c=D._tr_tally(a,1,a.match_length-fa),a.lookahead-=a.match_length,a.strstart+=a.match_length,a.match_length=0):(c=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++),c&&(h(a,!1),0===a.strm.avail_out))return qa}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?sa:ta):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?qa:ra}function r(a,b){for(var c;;){if(0===a.lookahead&&(m(a),0===a.lookahead)){if(b===H)return qa;break}if(a.match_length=0,c=D._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++,c&&(h(a,!1),0===a.strm.avail_out))return qa}return a.insert=0,b===K?(h(a,!0),0===a.strm.avail_out?sa:ta):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?qa:ra}function s(a){a.window_size=2*a.w_size,f(a.head),a.max_lazy_match=B[a.level].max_lazy,a.good_match=B[a.level].good_length,a.nice_match=B[a.level].nice_length,a.max_chain_length=B[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=fa-1,a.match_available=0,a.ins_h=0}function t(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Y,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new C.Buf16(2*da),this.dyn_dtree=new C.Buf16(2*(2*ba+1)),this.bl_tree=new C.Buf16(2*(2*ca+1)),f(this.dyn_ltree),f(this.dyn_dtree),f(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new C.Buf16(ea+1),this.heap=new C.Buf16(2*aa+1),f(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new C.Buf16(2*aa+1),f(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function u(a){var b;return a&&a.state?(a.total_in=a.total_out=0,a.data_type=X,b=a.state,b.pending=0,b.pending_out=0,b.wrap<0&&(b.wrap=-b.wrap),b.status=b.wrap?ja:oa,a.adler=2===b.wrap?0:1,b.last_flush=H,D._tr_init(b),M):d(a,O)}function v(a){var b=u(a);return b===M&&s(a.state),b}function w(a,b){return a&&a.state?2!==a.state.wrap?O:(a.state.gzhead=b,M):O}function x(a,b,c,e,f,g){if(!a)return O;var h=1;if(b===R&&(b=6),0>e?(h=0,e=-e):e>15&&(h=2,e-=16),1>f||f>Z||c!==Y||8>e||e>15||0>b||b>9||0>g||g>V)return d(a,O);8===e&&(e=9);var i=new t;return a.state=i,i.strm=a,i.wrap=h,i.gzhead=null,i.w_bits=e,i.w_size=1<<i.w_bits,i.w_mask=i.w_size-1,i.hash_bits=f+7,i.hash_size=1<<i.hash_bits,i.hash_mask=i.hash_size-1,i.hash_shift=~~((i.hash_bits+fa-1)/fa),i.window=new C.Buf8(2*i.w_size),i.head=new C.Buf16(i.hash_size),i.prev=new C.Buf16(i.w_size),i.lit_bufsize=1<<f+6,i.pending_buf_size=4*i.lit_bufsize,i.pending_buf=new C.Buf8(i.pending_buf_size),i.d_buf=i.lit_bufsize>>1,i.l_buf=3*i.lit_bufsize,i.level=b,i.strategy=g,i.method=c,v(a)}function y(a,b){return x(a,b,Y,$,_,W)}function z(a,b){var c,h,k,l;if(!a||!a.state||b>L||0>b)return a?d(a,O):O;if(h=a.state,!a.output||!a.input&&0!==a.avail_in||h.status===pa&&b!==K)return d(a,0===a.avail_out?Q:O);if(h.strm=a,c=h.last_flush,h.last_flush=b,h.status===ja)if(2===h.wrap)a.adler=0,i(h,31),i(h,139),i(h,8),
h.gzhead?(i(h,(h.gzhead.text?1:0)+(h.gzhead.hcrc?2:0)+(h.gzhead.extra?4:0)+(h.gzhead.name?8:0)+(h.gzhead.comment?16:0)),i(h,255&h.gzhead.time),i(h,h.gzhead.time>>8&255),i(h,h.gzhead.time>>16&255),i(h,h.gzhead.time>>24&255),i(h,9===h.level?2:h.strategy>=T||h.level<2?4:0),i(h,255&h.gzhead.os),h.gzhead.extra&&h.gzhead.extra.length&&(i(h,255&h.gzhead.extra.length),i(h,h.gzhead.extra.length>>8&255)),h.gzhead.hcrc&&(a.adler=F(a.adler,h.pending_buf,h.pending,0)),h.gzindex=0,h.status=ka):(i(h,0),i(h,0),i(h,0),i(h,0),i(h,0),i(h,9===h.level?2:h.strategy>=T||h.level<2?4:0),i(h,ua),h.status=oa);else{var m=Y+(h.w_bits-8<<4)<<8,n=-1;n=h.strategy>=T||h.level<2?0:h.level<6?1:6===h.level?2:3,m|=n<<6,0!==h.strstart&&(m|=ia),m+=31-m%31,h.status=oa,j(h,m),0!==h.strstart&&(j(h,a.adler>>>16),j(h,65535&a.adler)),a.adler=1}if(h.status===ka)if(h.gzhead.extra){for(k=h.pending;h.gzindex<(65535&h.gzhead.extra.length)&&(h.pending!==h.pending_buf_size||(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending!==h.pending_buf_size));)i(h,255&h.gzhead.extra[h.gzindex]),h.gzindex++;h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),h.gzindex===h.gzhead.extra.length&&(h.gzindex=0,h.status=la)}else h.status=la;if(h.status===la)if(h.gzhead.name){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.name.length?255&h.gzhead.name.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.gzindex=0,h.status=ma)}else h.status=ma;if(h.status===ma)if(h.gzhead.comment){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindex<h.gzhead.comment.length?255&h.gzhead.comment.charCodeAt(h.gzindex++):0,i(h,l)}while(0!==l);h.gzhead.hcrc&&h.pending>k&&(a.adler=F(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.status=na)}else h.status=na;if(h.status===na&&(h.gzhead.hcrc?(h.pending+2>h.pending_buf_size&&g(a),h.pending+2<=h.pending_buf_size&&(i(h,255&a.adler),i(h,a.adler>>8&255),a.adler=0,h.status=oa)):h.status=oa),0!==h.pending){if(g(a),0===a.avail_out)return h.last_flush=-1,M}else if(0===a.avail_in&&e(b)<=e(c)&&b!==K)return d(a,Q);if(h.status===pa&&0!==a.avail_in)return d(a,Q);if(0!==a.avail_in||0!==h.lookahead||b!==H&&h.status!==pa){var o=h.strategy===T?r(h,b):h.strategy===U?q(h,b):B[h.level].func(h,b);if((o===sa||o===ta)&&(h.status=pa),o===qa||o===sa)return 0===a.avail_out&&(h.last_flush=-1),M;if(o===ra&&(b===I?D._tr_align(h):b!==L&&(D._tr_stored_block(h,0,0,!1),b===J&&(f(h.head),0===h.lookahead&&(h.strstart=0,h.block_start=0,h.insert=0))),g(a),0===a.avail_out))return h.last_flush=-1,M}return b!==K?M:h.wrap<=0?N:(2===h.wrap?(i(h,255&a.adler),i(h,a.adler>>8&255),i(h,a.adler>>16&255),i(h,a.adler>>24&255),i(h,255&a.total_in),i(h,a.total_in>>8&255),i(h,a.total_in>>16&255),i(h,a.total_in>>24&255)):(j(h,a.adler>>>16),j(h,65535&a.adler)),g(a),h.wrap>0&&(h.wrap=-h.wrap),0!==h.pending?M:N)}function A(a){var b;return a&&a.state?(b=a.state.status,b!==ja&&b!==ka&&b!==la&&b!==ma&&b!==na&&b!==oa&&b!==pa?d(a,O):(a.state=null,b===oa?d(a,P):M)):O}var B,C=a("../utils/common"),D=a("./trees"),E=a("./adler32"),F=a("./crc32"),G=a("./messages"),H=0,I=1,J=3,K=4,L=5,M=0,N=1,O=-2,P=-3,Q=-5,R=-1,S=1,T=2,U=3,V=4,W=0,X=2,Y=8,Z=9,$=15,_=8,aa=286,ba=30,ca=19,da=2*aa+1,ea=15,fa=3,ga=258,ha=ga+fa+1,ia=32,ja=42,ka=69,la=73,ma=91,na=103,oa=113,pa=666,qa=1,ra=2,sa=3,ta=4,ua=3,va=function(a,b,c,d,e){this.good_length=a,this.max_lazy=b,this.nice_length=c,this.max_chain=d,this.func=e};B=[new va(0,0,0,0,n),new va(4,4,8,4,o),new va(4,5,16,8,o),new va(4,6,32,32,o),new va(4,4,16,16,p),new va(8,16,32,32,p),new va(8,16,128,128,p),new va(8,32,128,256,p),new va(32,128,258,1024,p),new va(32,258,258,4096,p)],c.deflateInit=y,c.deflateInit2=x,c.deflateReset=v,c.deflateResetKeep=u,c.deflateSetHeader=w,c.deflate=z,c.deflateEnd=A,c.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":27,"./adler32":29,"./crc32":31,"./messages":37,"./trees":38}],33:[function(a,b){"use strict";function c(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}b.exports=c},{}],34:[function(a,b){"use strict";b.exports=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A;c=a.state,d=a.next_in,z=a.input,e=d+(a.avail_in-5),f=a.next_out,A=a.output,g=f-(b-a.avail_out),h=f+(a.avail_out-257),i=c.dmax,j=c.wsize,k=c.whave,l=c.wnext,m=c.window,n=c.hold,o=c.bits,p=c.lencode,q=c.distcode,r=(1<<c.lenbits)-1,s=(1<<c.distbits)-1;a:do{15>o&&(n+=z[d++]<<o,o+=8,n+=z[d++]<<o,o+=8),t=p[n&r];b:for(;;){if(u=t>>>24,n>>>=u,o-=u,0===(u=t>>>16&255))A[f++]=65535&t;else{if(!(16&u)){if(0==(64&u)){t=p[(65535&t)+(n&(1<<u)-1)];continue b}if(32&u){c.mode=12;break a}a.msg="invalid literal/length code",c.mode=30;break a}v=65535&t,u&=15,u&&(u>o&&(n+=z[d++]<<o,o+=8),v+=n&(1<<u)-1,n>>>=u,o-=u),15>o&&(n+=z[d++]<<o,o+=8,n+=z[d++]<<o,o+=8),t=q[n&s];c:for(;;){if(u=t>>>24,n>>>=u,o-=u,!(16&(u=t>>>16&255))){if(0==(64&u)){t=q[(65535&t)+(n&(1<<u)-1)];continue c}a.msg="invalid distance code",c.mode=30;break a}if(w=65535&t,u&=15,u>o&&(n+=z[d++]<<o,o+=8,u>o&&(n+=z[d++]<<o,o+=8)),(w+=n&(1<<u)-1)>i){a.msg="invalid distance too far back",c.mode=30;break a}if(n>>>=u,o-=u,u=f-g,w>u){if((u=w-u)>k&&c.sane){a.msg="invalid distance too far back",c.mode=30;break a}if(x=0,y=m,0===l){if(x+=j-u,v>u){v-=u;do{A[f++]=m[x++]}while(--u);x=f-w,y=A}}else if(u>l){if(x+=j+l-u,u-=l,v>u){v-=u;do{A[f++]=m[x++]}while(--u);if(x=0,v>l){u=l,v-=u;do{A[f++]=m[x++]}while(--u);x=f-w,y=A}}}else if(x+=l-u,v>u){v-=u;do{A[f++]=m[x++]}while(--u);x=f-w,y=A}for(;v>2;)A[f++]=y[x++],A[f++]=y[x++],A[f++]=y[x++],v-=3;v&&(A[f++]=y[x++],v>1&&(A[f++]=y[x++]))}else{x=f-w;do{A[f++]=A[x++],A[f++]=A[x++],A[f++]=A[x++],v-=3}while(v>2);v&&(A[f++]=A[x++],v>1&&(A[f++]=A[x++]))}break}}break}}while(e>d&&h>f);v=o>>3,d-=v,o-=v<<3,n&=(1<<o)-1,a.next_in=d,a.next_out=f,a.avail_in=e>d?e-d+5:5-(d-e),a.avail_out=h>f?h-f+257:257-(f-h),c.hold=n,c.bits=o}},{}],35:[function(a,b,c){"use strict";function d(a){return(a>>>24&255)+(a>>>8&65280)+((65280&a)<<8)+((255&a)<<24)}function e(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(a){var b;return a&&a.state?(b=a.state,a.total_in=a.total_out=b.total=0,a.msg="",b.wrap&&(a.adler=1&b.wrap),b.mode=K,b.last=0,b.havedict=0,b.dmax=32768,b.head=null,b.hold=0,b.bits=0,b.lencode=b.lendyn=new r.Buf32(oa),b.distcode=b.distdyn=new r.Buf32(pa),b.sane=1,b.back=-1,C):F}function g(a){var b;return a&&a.state?(b=a.state,b.wsize=0,b.whave=0,b.wnext=0,f(a)):F}function h(a,b){var c,d;return a&&a.state?(d=a.state,0>b?(c=0,b=-b):(c=1+(b>>4),48>b&&(b&=15)),b&&(8>b||b>15)?F:(null!==d.window&&d.wbits!==b&&(d.window=null),d.wrap=c,d.wbits=b,g(a))):F}function i(a,b){var c,d;return a?(d=new e,a.state=d,d.window=null,c=h(a,b),c!==C&&(a.state=null),c):F}function j(a){return i(a,qa)}function k(a){if(ra){var b;for(p=new r.Buf32(512),q=new r.Buf32(32),b=0;144>b;)a.lens[b++]=8;for(;256>b;)a.lens[b++]=9;for(;280>b;)a.lens[b++]=7;for(;288>b;)a.lens[b++]=8;for(v(x,a.lens,0,288,p,0,a.work,{bits:9}),b=0;32>b;)a.lens[b++]=5;v(y,a.lens,0,32,q,0,a.work,{bits:5}),ra=!1}
a.lencode=p,a.lenbits=9,a.distcode=q,a.distbits=5}function l(a,b,c,d){var e,f=a.state;return null===f.window&&(f.wsize=1<<f.wbits,f.wnext=0,f.whave=0,f.window=new r.Buf8(f.wsize)),d>=f.wsize?(r.arraySet(f.window,b,c-f.wsize,f.wsize,0),f.wnext=0,f.whave=f.wsize):(e=f.wsize-f.wnext,e>d&&(e=d),r.arraySet(f.window,b,c-d,e,f.wnext),d-=e,d?(r.arraySet(f.window,b,c-d,d,0),f.wnext=d,f.whave=f.wsize):(f.wnext+=e,f.wnext===f.wsize&&(f.wnext=0),f.whave<f.wsize&&(f.whave+=e))),0}function m(a,b){var c,e,f,g,h,i,j,m,n,o,p,q,oa,pa,qa,ra,sa,ta,ua,va,wa,xa,ya,za,Aa=0,Ba=new r.Buf8(4),Ca=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!a||!a.state||!a.output||!a.input&&0!==a.avail_in)return F;c=a.state,c.mode===V&&(c.mode=W),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,o=i,p=j,xa=C;a:for(;;)switch(c.mode){case K:if(0===c.wrap){c.mode=W;break}for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(2&c.wrap&&35615===m){c.check=0,Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=t(c.check,Ba,2,0),m=0,n=0,c.mode=L;break}if(c.flags=0,c.head&&(c.head.done=!1),!(1&c.wrap)||(((255&m)<<8)+(m>>8))%31){a.msg="incorrect header check",c.mode=la;break}if((15&m)!==J){a.msg="unknown compression method",c.mode=la;break}if(m>>>=4,n-=4,wa=8+(15&m),0===c.wbits)c.wbits=wa;else if(wa>c.wbits){a.msg="invalid window size",c.mode=la;break}c.dmax=1<<wa,a.adler=c.check=1,c.mode=512&m?T:V,m=0,n=0;break;case L:for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.flags=m,(255&c.flags)!==J){a.msg="unknown compression method",c.mode=la;break}if(57344&c.flags){a.msg="unknown header flags set",c.mode=la;break}c.head&&(c.head.text=m>>8&1),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=t(c.check,Ba,2,0)),m=0,n=0,c.mode=M;case M:for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.time=m),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,Ba[2]=m>>>16&255,Ba[3]=m>>>24&255,c.check=t(c.check,Ba,4,0)),m=0,n=0,c.mode=N;case N:for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.head&&(c.head.xflags=255&m,c.head.os=m>>8),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=t(c.check,Ba,2,0)),m=0,n=0,c.mode=O;case O:if(1024&c.flags){for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length=m,c.head&&(c.head.extra_len=m),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=t(c.check,Ba,2,0)),m=0,n=0}else c.head&&(c.head.extra=null);c.mode=P;case P:if(1024&c.flags&&(q=c.length,q>i&&(q=i),q&&(c.head&&(wa=c.head.extra_len-c.length,c.head.extra||(c.head.extra=new Array(c.head.extra_len)),r.arraySet(c.head.extra,e,g,q,wa)),512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,c.length-=q),c.length))break a;c.length=0,c.mode=Q;case Q:if(2048&c.flags){if(0===i)break a;q=0;do{wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.name+=String.fromCharCode(wa))}while(wa&&i>q);if(512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,wa)break a}else c.head&&(c.head.name=null);c.length=0,c.mode=R;case R:if(4096&c.flags){if(0===i)break a;q=0;do{wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.comment+=String.fromCharCode(wa))}while(wa&&i>q);if(512&c.flags&&(c.check=t(c.check,e,q,g)),i-=q,g+=q,wa)break a}else c.head&&(c.head.comment=null);c.mode=S;case S:if(512&c.flags){for(;16>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(65535&c.check)){a.msg="header crc mismatch",c.mode=la;break}m=0,n=0}c.head&&(c.head.hcrc=c.flags>>9&1,c.head.done=!0),a.adler=c.check=0,c.mode=V;break;case T:for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}a.adler=c.check=d(m),m=0,n=0,c.mode=U;case U:if(0===c.havedict)return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,E;a.adler=c.check=1,c.mode=V;case V:if(b===A||b===B)break a;case W:if(c.last){m>>>=7&n,n-=7&n,c.mode=ia;break}for(;3>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}switch(c.last=1&m,m>>>=1,n-=1,3&m){case 0:c.mode=X;break;case 1:if(k(c),c.mode=ba,b===B){m>>>=2,n-=2;break a}break;case 2:c.mode=$;break;case 3:a.msg="invalid block type",c.mode=la}m>>>=2,n-=2;break;case X:for(m>>>=7&n,n-=7&n;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if((65535&m)!=(m>>>16^65535)){a.msg="invalid stored block lengths",c.mode=la;break}if(c.length=65535&m,m=0,n=0,c.mode=Y,b===B)break a;case Y:c.mode=Z;case Z:if(q=c.length){if(q>i&&(q=i),q>j&&(q=j),0===q)break a;r.arraySet(f,e,g,q,h),i-=q,g+=q,j-=q,h+=q,c.length-=q;break}c.mode=V;break;case $:for(;14>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(c.nlen=257+(31&m),m>>>=5,n-=5,c.ndist=1+(31&m),m>>>=5,n-=5,c.ncode=4+(15&m),m>>>=4,n-=4,c.nlen>286||c.ndist>30){a.msg="too many length or distance symbols",c.mode=la;break}c.have=0,c.mode=_;case _:for(;c.have<c.ncode;){for(;3>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.lens[Ca[c.have++]]=7&m,m>>>=3,n-=3}for(;c.have<19;)c.lens[Ca[c.have++]]=0;if(c.lencode=c.lendyn,c.lenbits=7,ya={bits:c.lenbits},xa=v(w,c.lens,0,19,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid code lengths set",c.mode=la;break}c.have=0,c.mode=aa;case aa:for(;c.have<c.nlen+c.ndist;){for(;Aa=c.lencode[m&(1<<c.lenbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(n>=qa);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(16>sa)m>>>=qa,n-=qa,c.lens[c.have++]=sa;else{if(16===sa){for(za=qa+2;za>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m>>>=qa,n-=qa,0===c.have){a.msg="invalid bit length repeat",c.mode=la;break}wa=c.lens[c.have-1],q=3+(3&m),m>>>=2,n-=2}else if(17===sa){for(za=qa+3;za>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qa,n-=qa,wa=0,q=3+(7&m),m>>>=3,n-=3}else{for(za=qa+7;za>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=qa,n-=qa,wa=0,q=11+(127&m),m>>>=7,n-=7}if(c.have+q>c.nlen+c.ndist){a.msg="invalid bit length repeat",c.mode=la;break}for(;q--;)c.lens[c.have++]=wa}}if(c.mode===la)break;if(0===c.lens[256]){a.msg="invalid code -- missing end-of-block",c.mode=la;break}if(c.lenbits=9,ya={bits:c.lenbits},xa=v(x,c.lens,0,c.nlen,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid literal/lengths set",c.mode=la;break}if(c.distbits=6,c.distcode=c.distdyn,ya={bits:c.distbits},xa=v(y,c.lens,c.nlen,c.ndist,c.distcode,0,c.work,ya),c.distbits=ya.bits,xa){a.msg="invalid distances set",c.mode=la;break}if(c.mode=ba,b===B)break a;case ba:c.mode=ca;case ca:if(i>=6&&j>=258){a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,u(a,p),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,c.mode===V&&(c.back=-1);break}for(c.back=0;Aa=c.lencode[m&(1<<c.lenbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(n>=qa);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(ra&&0==(240&ra)){for(ta=qa,ua=ra,va=sa;Aa=c.lencode[va+((m&(1<<ta+ua)-1)>>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(n>=ta+qa);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,c.length=sa,0===ra){c.mode=ha;break}if(32&ra){c.back=-1,c.mode=V;break}if(64&ra){a.msg="invalid literal/length code",c.mode=la;break}c.extra=15&ra,c.mode=da;case da:if(c.extra){for(za=c.extra;za>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.length+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}c.was=c.length,c.mode=ea;case ea:for(;Aa=c.distcode[m&(1<<c.distbits)-1],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(n>=qa);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(0==(240&ra)){for(ta=qa,ua=ra,va=sa;Aa=c.distcode[va+((m&(1<<ta+ua)-1)>>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(n>=ta+qa);){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}m>>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,64&ra){a.msg="invalid distance code",c.mode=la;break}c.offset=sa,c.extra=15&ra,c.mode=fa;case fa:if(c.extra){for(za=c.extra;za>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}c.offset+=m&(1<<c.extra)-1,m>>>=c.extra,n-=c.extra,c.back+=c.extra}if(c.offset>c.dmax){a.msg="invalid distance too far back",c.mode=la;break}c.mode=ga;case ga:if(0===j)break a;if(q=p-j,c.offset>q){if((q=c.offset-q)>c.whave&&c.sane){a.msg="invalid distance too far back",c.mode=la;break}q>c.wnext?(q-=c.wnext,oa=c.wsize-q):oa=c.wnext-q,
q>c.length&&(q=c.length),pa=c.window}else pa=f,oa=h-c.offset,q=c.length;q>j&&(q=j),j-=q,c.length-=q;do{f[h++]=pa[oa++]}while(--q);0===c.length&&(c.mode=ca);break;case ha:if(0===j)break a;f[h++]=c.length,j--,c.mode=ca;break;case ia:if(c.wrap){for(;32>n;){if(0===i)break a;i--,m|=e[g++]<<n,n+=8}if(p-=j,a.total_out+=p,c.total+=p,p&&(a.adler=c.check=c.flags?t(c.check,f,p,h-p):s(c.check,f,p,h-p)),p=j,(c.flags?m:d(m))!==c.check){a.msg="incorrect data check",c.mode=la;break}m=0,n=0}c.mode=ja;case ja:if(c.wrap&&c.flags){for(;32>n;){if(0===i)break a;i--,m+=e[g++]<<n,n+=8}if(m!==(4294967295&c.total)){a.msg="incorrect length check",c.mode=la;break}m=0,n=0}c.mode=ka;case ka:xa=D;break a;case la:xa=G;break a;case ma:return H;case na:default:return F}return a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,(c.wsize||p!==a.avail_out&&c.mode<la&&(c.mode<ia||b!==z))&&l(a,a.output,a.next_out,p-a.avail_out)?(c.mode=ma,H):(o-=a.avail_in,p-=a.avail_out,a.total_in+=o,a.total_out+=p,c.total+=p,c.wrap&&p&&(a.adler=c.check=c.flags?t(c.check,f,p,a.next_out-p):s(c.check,f,p,a.next_out-p)),a.data_type=c.bits+(c.last?64:0)+(c.mode===V?128:0)+(c.mode===ba||c.mode===Y?256:0),(0===o&&0===p||b===z)&&xa===C&&(xa=I),xa)}function n(a){if(!a||!a.state)return F;var b=a.state;return b.window&&(b.window=null),a.state=null,C}function o(a,b){var c;return a&&a.state?(c=a.state,0==(2&c.wrap)?F:(c.head=b,b.done=!1,C)):F}var p,q,r=a("../utils/common"),s=a("./adler32"),t=a("./crc32"),u=a("./inffast"),v=a("./inftrees"),w=0,x=1,y=2,z=4,A=5,B=6,C=0,D=1,E=2,F=-2,G=-3,H=-4,I=-5,J=8,K=1,L=2,M=3,N=4,O=5,P=6,Q=7,R=8,S=9,T=10,U=11,V=12,W=13,X=14,Y=15,Z=16,$=17,_=18,aa=19,ba=20,ca=21,da=22,ea=23,fa=24,ga=25,ha=26,ia=27,ja=28,ka=29,la=30,ma=31,na=32,oa=852,pa=592,qa=15,ra=!0;c.inflateReset=g,c.inflateReset2=h,c.inflateResetKeep=f,c.inflateInit=j,c.inflateInit2=i,c.inflate=m,c.inflateEnd=n,c.inflateGetHeader=o,c.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":27,"./adler32":29,"./crc32":31,"./inffast":34,"./inftrees":36}],36:[function(a,b){"use strict";var c=a("../utils/common"),d=15,e=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],f=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],g=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],h=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];b.exports=function(a,b,i,j,k,l,m,n){var o,p,q,r,s,t,u,v,w,x=n.bits,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=null,J=0,K=new c.Buf16(16),L=new c.Buf16(16),M=null,N=0;for(y=0;d>=y;y++)K[y]=0;for(z=0;j>z;z++)K[b[i+z]]++;for(C=x,B=d;B>=1&&0===K[B];B--);if(C>B&&(C=B),0===B)return k[l++]=20971520,k[l++]=20971520,n.bits=1,0;for(A=1;B>A&&0===K[A];A++);for(A>C&&(C=A),F=1,y=1;d>=y;y++)if(F<<=1,0>(F-=K[y]))return-1;if(F>0&&(0===a||1!==B))return-1;for(L[1]=0,y=1;d>y;y++)L[y+1]=L[y]+K[y];for(z=0;j>z;z++)0!==b[i+z]&&(m[L[b[i+z]]++]=z);if(0===a?(I=M=m,t=19):1===a?(I=e,J-=257,M=f,N-=257,t=256):(I=g,M=h,t=-1),H=0,z=0,y=A,s=l,D=C,E=0,q=-1,G=1<<C,r=G-1,1===a&&G>852||2===a&&G>592)return 1;for(var O=0;;){O++,u=y-E,m[z]<t?(v=0,w=m[z]):m[z]>t?(v=M[N+m[z]],w=I[J+m[z]]):(v=96,w=0),o=1<<y-E,p=1<<D,A=p;do{p-=o,k[s+(H>>E)+p]=u<<24|v<<16|w|0}while(0!==p);for(o=1<<y-1;H&o;)o>>=1;if(0!==o?(H&=o-1,H+=o):H=0,z++,0==--K[y]){if(y===B)break;y=b[i+m[z]]}if(y>C&&(H&r)!==q){for(0===E&&(E=C),s+=A,D=y-E,F=1<<D;B>D+E&&!(0>=(F-=K[D+E]));)D++,F<<=1;if(G+=1<<D,1===a&&G>852||2===a&&G>592)return 1;q=H&r,k[q]=C<<24|D<<16|s-l|0}}return 0!==H&&(k[s+H]=y-E<<24|64<<16|0),n.bits=C,0}},{"../utils/common":27}],37:[function(a,b){"use strict";b.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],38:[function(a,b,c){"use strict";function d(a){for(var b=a.length;--b>=0;)a[b]=0}function e(a){return 256>a?da[a]:da[256+(a>>>7)]}function f(a,b){a.pending_buf[a.pending++]=255&b,a.pending_buf[a.pending++]=b>>>8&255}function g(a,b,c){a.bi_valid>T-c?(a.bi_buf|=b<<a.bi_valid&65535,f(a,a.bi_buf),a.bi_buf=b>>T-a.bi_valid,a.bi_valid+=c-T):(a.bi_buf|=b<<a.bi_valid&65535,a.bi_valid+=c)}function h(a,b,c){g(a,c[2*b],c[2*b+1])}function i(a,b){var c=0;do{c|=1&a,a>>>=1,c<<=1}while(--b>0);return c>>>1}function j(a){16===a.bi_valid?(f(a,a.bi_buf),a.bi_buf=0,a.bi_valid=0):a.bi_valid>=8&&(a.pending_buf[a.pending++]=255&a.bi_buf,a.bi_buf>>=8,a.bi_valid-=8)}function k(a,b){var c,d,e,f,g,h,i=b.dyn_tree,j=b.max_code,k=b.stat_desc.static_tree,l=b.stat_desc.has_stree,m=b.stat_desc.extra_bits,n=b.stat_desc.extra_base,o=b.stat_desc.max_length,p=0;for(f=0;S>=f;f++)a.bl_count[f]=0;for(i[2*a.heap[a.heap_max]+1]=0,c=a.heap_max+1;R>c;c++)d=a.heap[c],f=i[2*i[2*d+1]+1]+1,f>o&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)(e=a.heap[--c])>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function l(a,b,c){var d,e,f=new Array(S+1),g=0;for(d=1;S>=d;d++)f[d]=g=g+c[d-1]<<1;for(e=0;b>=e;e++){var h=a[2*e+1];0!==h&&(a[2*e]=i(f[h]++,h))}}function m(){var a,b,c,d,e,f=new Array(S+1);for(c=0,d=0;M-1>d;d++)for(fa[d]=c,a=0;a<1<<Z[d];a++)ea[c++]=d;for(ea[c-1]=d,e=0,d=0;16>d;d++)for(ga[d]=e,a=0;a<1<<$[d];a++)da[e++]=d;for(e>>=7;P>d;d++)for(ga[d]=e<<7,a=0;a<1<<$[d]-7;a++)da[256+e++]=d;for(b=0;S>=b;b++)f[b]=0;for(a=0;143>=a;)ba[2*a+1]=8,a++,f[8]++;for(;255>=a;)ba[2*a+1]=9,a++,f[9]++;for(;279>=a;)ba[2*a+1]=7,a++,f[7]++;for(;287>=a;)ba[2*a+1]=8,a++,f[8]++;for(l(ba,O+1,f),a=0;P>a;a++)ca[2*a+1]=5,ca[2*a]=i(a,5);ha=new ka(ba,Z,N+1,O,S),ia=new ka(ca,$,0,P,S),ja=new ka(new Array(0),_,0,Q,U)}function n(a){var b;for(b=0;O>b;b++)a.dyn_ltree[2*b]=0;for(b=0;P>b;b++)a.dyn_dtree[2*b]=0;for(b=0;Q>b;b++)a.bl_tree[2*b]=0;a.dyn_ltree[2*V]=1,a.opt_len=a.static_len=0,a.last_lit=a.matches=0}function o(a){a.bi_valid>8?f(a,a.bi_buf):a.bi_valid>0&&(a.pending_buf[a.pending++]=a.bi_buf),a.bi_buf=0,a.bi_valid=0}function p(a,b,c,d){o(a),d&&(f(a,c),f(a,~c)),E.arraySet(a.pending_buf,a.window,b,c,a.pending),a.pending+=c}function q(a,b,c,d){var e=2*b,f=2*c;return a[e]<a[f]||a[e]===a[f]&&d[b]<=d[c]}function r(a,b,c){for(var d=a.heap[c],e=c<<1;e<=a.heap_len&&(e<a.heap_len&&q(b,a.heap[e+1],a.heap[e],a.depth)&&e++,!q(b,d,a.heap[e],a.depth));)a.heap[c]=a.heap[e],c=e,e<<=1;a.heap[c]=d}function s(a,b,c){var d,f,i,j,k=0;if(0!==a.last_lit)do{d=a.pending_buf[a.d_buf+2*k]<<8|a.pending_buf[a.d_buf+2*k+1],f=a.pending_buf[a.l_buf+k],k++,0===d?h(a,f,b):(i=ea[f],h(a,i+N+1,b),j=Z[i],0!==j&&(f-=fa[i],g(a,f,j)),d--,i=e(d),h(a,i,c),0!==(j=$[i])&&(d-=ga[i],g(a,d,j)))}while(k<a.last_lit);h(a,V,b)}function t(a,b){var c,d,e,f=b.dyn_tree,g=b.stat_desc.static_tree,h=b.stat_desc.has_stree,i=b.stat_desc.elems,j=-1;for(a.heap_len=0,a.heap_max=R,c=0;i>c;c++)0!==f[2*c]?(a.heap[++a.heap_len]=j=c,a.depth[c]=0):f[2*c+1]=0;for(;a.heap_len<2;)e=a.heap[++a.heap_len]=2>j?++j:0,f[2*e]=1,a.depth[e]=0,a.opt_len--,h&&(a.static_len-=g[2*e+1]);for(b.max_code=j,c=a.heap_len>>1;c>=1;c--)r(a,f,c);e=i;do{c=a.heap[1],a.heap[1]=a.heap[a.heap_len--],r(a,f,1),d=a.heap[1],a.heap[--a.heap_max]=c,a.heap[--a.heap_max]=d,f[2*e]=f[2*c]+f[2*d],a.depth[e]=(a.depth[c]>=a.depth[d]?a.depth[c]:a.depth[d])+1,f[2*c+1]=f[2*d+1]=e,a.heap[1]=e++,r(a,f,1)}while(a.heap_len>=2);a.heap[--a.heap_max]=a.heap[1],k(a,b),l(f,j,a.bl_count)}function u(a,b,c){var d,e,f=-1,g=b[1],h=0,i=7,j=4;for(0===g&&(i=138,j=3),b[2*(c+1)+1]=65535,d=0;c>=d;d++)e=g,g=b[2*(d+1)+1],++h<i&&e===g||(j>h?a.bl_tree[2*e]+=h:0!==e?(e!==f&&a.bl_tree[2*e]++,a.bl_tree[2*W]++):10>=h?a.bl_tree[2*X]++:a.bl_tree[2*Y]++,h=0,f=e,0===g?(i=138,j=3):e===g?(i=6,
j=3):(i=7,j=4))}function v(a,b,c){var d,e,f=-1,i=b[1],j=0,k=7,l=4;for(0===i&&(k=138,l=3),d=0;c>=d;d++)if(e=i,i=b[2*(d+1)+1],!(++j<k&&e===i)){if(l>j)do{h(a,e,a.bl_tree)}while(0!=--j);else 0!==e?(e!==f&&(h(a,e,a.bl_tree),j--),h(a,W,a.bl_tree),g(a,j-3,2)):10>=j?(h(a,X,a.bl_tree),g(a,j-3,3)):(h(a,Y,a.bl_tree),g(a,j-11,7));j=0,f=e,0===i?(k=138,l=3):e===i?(k=6,l=3):(k=7,l=4)}}function w(a){var b;for(u(a,a.dyn_ltree,a.l_desc.max_code),u(a,a.dyn_dtree,a.d_desc.max_code),t(a,a.bl_desc),b=Q-1;b>=3&&0===a.bl_tree[2*aa[b]+1];b--);return a.opt_len+=3*(b+1)+5+5+4,b}function x(a,b,c,d){var e;for(g(a,b-257,5),g(a,c-1,5),g(a,d-4,4),e=0;d>e;e++)g(a,a.bl_tree[2*aa[e]+1],3);v(a,a.dyn_ltree,b-1),v(a,a.dyn_dtree,c-1)}function y(a){var b,c=4093624447;for(b=0;31>=b;b++,c>>>=1)if(1&c&&0!==a.dyn_ltree[2*b])return G;if(0!==a.dyn_ltree[18]||0!==a.dyn_ltree[20]||0!==a.dyn_ltree[26])return H;for(b=32;N>b;b++)if(0!==a.dyn_ltree[2*b])return H;return G}function z(a){ma||(m(),ma=!0),a.l_desc=new la(a.dyn_ltree,ha),a.d_desc=new la(a.dyn_dtree,ia),a.bl_desc=new la(a.bl_tree,ja),a.bi_buf=0,a.bi_valid=0,n(a)}function A(a,b,c,d){g(a,(J<<1)+(d?1:0),3),p(a,b,c,!0)}function B(a){g(a,K<<1,3),h(a,V,ba),j(a)}function C(a,b,c,d){var e,f,h=0;a.level>0?(a.strm.data_type===I&&(a.strm.data_type=y(a)),t(a,a.l_desc),t(a,a.d_desc),h=w(a),e=a.opt_len+3+7>>>3,f=a.static_len+3+7>>>3,e>=f&&(e=f)):e=f=c+5,e>=c+4&&-1!==b?A(a,b,c,d):a.strategy===F||f===e?(g(a,(K<<1)+(d?1:0),3),s(a,ba,ca)):(g(a,(L<<1)+(d?1:0),3),x(a,a.l_desc.max_code+1,a.d_desc.max_code+1,h+1),s(a,a.dyn_ltree,a.dyn_dtree)),n(a),d&&o(a)}function D(a,b,c){return a.pending_buf[a.d_buf+2*a.last_lit]=b>>>8&255,a.pending_buf[a.d_buf+2*a.last_lit+1]=255&b,a.pending_buf[a.l_buf+a.last_lit]=255&c,a.last_lit++,0===b?a.dyn_ltree[2*c]++:(a.matches++,b--,a.dyn_ltree[2*(ea[c]+N+1)]++,a.dyn_dtree[2*e(b)]++),a.last_lit===a.lit_bufsize-1}var E=a("../utils/common"),F=4,G=0,H=1,I=2,J=0,K=1,L=2,M=29,N=256,O=N+1+M,P=30,Q=19,R=2*O+1,S=15,T=16,U=7,V=256,W=16,X=17,Y=18,Z=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],$=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],_=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],aa=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],ba=new Array(2*(O+2));d(ba);var ca=new Array(2*P);d(ca);var da=new Array(512);d(da);var ea=new Array(256);d(ea);var fa=new Array(M);d(fa);var ga=new Array(P);d(ga);var ha,ia,ja,ka=function(a,b,c,d,e){this.static_tree=a,this.extra_bits=b,this.extra_base=c,this.elems=d,this.max_length=e,this.has_stree=a&&a.length},la=function(a,b){this.dyn_tree=a,this.max_code=0,this.stat_desc=b},ma=!1;c._tr_init=z,c._tr_stored_block=A,c._tr_flush_block=C,c._tr_tally=D,c._tr_align=B},{"../utils/common":27}],39:[function(a,b){"use strict";function c(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}b.exports=c},{}]},{},[9])(9)}),wmsx.EmbeddedFiles={get:function(a){if(a.indexOf("|")<0)return this.getFile(a);for(var b=a.split(/\s*\|\s*/),c=new Array(b.length),d=0;d<b.length;++d){var e=this.getFile(b[d]);if(void 0===e)return;c[d]=e.content}return{name:a,content:wmsx.Util.arraysConcatAll(c)}},getFile:function(a){a=a.substr(1);var b=this.compressedContent[a];if(void 0!==b)return{name:a,content:wmsx.Util.uncompressStringBase64ToInt8BitArray(b)};var c=this.diffsContent[a];if(void 0!==c){var d=this.getFile(c.based);if(void 0!==d){var e=d.content;for(var f in c.diffs)for(var g=c.diffs[f],h=0;h<g.length;++h)e[(0|f)+h]=g[h];return{name:a,content:e}}}},embedFileCompressedContent:function(a,b){this.compressedContent[a]=b},embedFileDiff:function(a,b){this.diffsContent[a]=b},isEmbeddedURL:function(a){return a&&"@"===a[0]},compressedContent:{},diffsContent:{}},wmsx.MultiDownloader=function(a,b,c,d){"use strict";function e(a){if(a){var b=a.url.trim();if(!b)return i(a,"Empty URL");var c=wmsx.EmbeddedFiles.isEmbeddedURL(b)?[b]:b.split(/\s*\|\s*/);a.filesToLoad=c.length,a.filesContent=new Array(a.filesToLoad);for(var d=0;d<c.length;++d){var e=c[d];wmsx.EmbeddedFiles.isEmbeddedURL(e)?f(a,d,e):g(a,d,e)}}}function f(a,b,c){var d=wmsx.EmbeddedFiles.get(c);void 0!==d?h(a,b,d.content):i(a,"Embedded file not found!")}function g(a,b,c){var e=k(c)?l(c):c,f=new XMLHttpRequest;f.open("GET",e,!0),f.responseType="arraybuffer",f.timeout=void 0!==d?d:s,f.onload=function(){200!==f.status&&0!==f.status||!f.response?f.onerror():h(a,b,new Uint8Array(f.response))},f.onerror=f.ontimeout=function(){i(a,f.status+" "+f.statusText)},wmsx.Util.log("Reading file from: "+c),f.send()}function h(a,b,c){a.filesContent[b]=c,--a.filesToLoad>0||(a.success=!0,a.content=wmsx.Util.arraysConcatAll(a.filesContent),a.onSuccess&&a.onSuccess(a),j())}function i(a,b){var d="Could not load file: "+a.url+"\nError: "+b;a.success=!1,a.error=b,a.errorMessage=d,a.onError?(wmsx.Util.error(d),a.onError(a)):c||wmsx.Util.message(d),j()}function j(){if(!q){for(var d=0;d<a.length;d++)if(a[d]&&void 0===a[d].success)return;for(q=!0,n(),d=0;d<a.length;d++)if(a[d]&&!a[d].success)return void(c&&c(a[d]));b&&b(a)}}function k(a){return a&&(0===a.indexOf("http:")||0===a.indexOf("https:"))}function l(a){return WMSX.WEB_EXTENSIONS_PROXY_SERVER?"https://"+WMSX.WEB_EXTENSIONS_PROXY_SERVER+"/proxy-remote-download?url="+a:a}function m(){WMSX.room&&!WMSX.room.isLoading&&(p=window.setTimeout(function(){p=null,o=!0,WMSX.room.setLoading(!0)},r))}function n(){p&&(window.clearTimeout(p),p=null),o&&(o=!1,WMSX.room.setLoading(!1))}this.start=function(){if(a&&0!==a.length){m();for(var b=0;b<a.length;b++)e(a[b])}j()};var o=!1,p=null,q=!1,r=100,s=15e3},wmsx.MultiFileReader=function(a,b,c,d){"use strict";function e(a){if(a){wmsx.Util.log("Reading file: "+a.name);var b=new FileReader;b.onload=function(b){a.wmsxSuccess=!0,a.content=new Uint8Array(b.target.result),f()},b.onerror=function(b){a.wmsxSuccess=!1,a.wmsxError=b.target.error.name,console.log("ERROR:",a.name,a.wmsxError),f()},b.readAsArrayBuffer(a)}}function f(){if(!h){for(var a=0;a<g.length;a++)if(g[a]&&void 0===g[a].wmsxSuccess)return;for(h=!0,a=0;a<g.length;a++)if(g[a]&&!g[a].wmsxSuccess)return c&&c(g,g[a].wmsxError),g;b&&b(g)}}this.start=function(){if(a&&0!==a.length){for(var c=0;c<a.length;c++)g.push(a[c]);for(var d=0;d<g.length;d++)e(g[d]);f()}else b(a)};var g=[],h=!1},wmsx.CPU=function(){"use strict";function init(){defineZ80InstructionSet()}function updateR800Present(){r800Present?(defineR800InstructionSet(),self.busClockPulses=self.busClockPulsesBoth):self.busClockPulses=self.busClockPulsesZ80}function updateInstructionSet(){r800?(instructionsNoPrefix=instructionsNoPrefixR800,instructionsByPrefix=instructionsByPrefixR800):(instructionsNoPrefix=instructionsNoPrefixZ80,instructionsByPrefix=instructionsByPrefixZ80)}function defineZ80InstructionSet(){instructionsNoPrefixZ80[0]||defineInstructionSet(instructionsByPrefixZ80,!1,!1)}function defineR800InstructionSet(){instructionsNoPrefixR800[0]||defineInstructionSet(instructionsByPrefixR800,!0,!0)}function updateClockMulti(){self.getBUSCycles(),clockMulti=r800?r800ClockMulti:z80ClockMulti}function setINT(a){INT!==a&&(INT=a,ackINT=255!==a&&IFF1&&0===prefix)}function fetchNextInstruction(){++R,opcode=r800?fetchN_R800():fetchN(),selectInstruction(),T=instruction.remainCycles}function acknowledgeINT(){++R,IFF1=0,ackINT=!1,instruction.operation===HALT&&pcInc(),instruction=IM<2?instructionsNoPrefix[258]:instructionsNoPrefix[259],T=instruction.remainCycles}function selectInstruction(){0===prefix?instruction=instructionsNoPrefix[opcode]:(instruction=instructionsByPrefix[prefix][opcode]||instructionsNoPrefix[opcode],255!==INT&&IFF1&&(ackINT=!0),prefix=0)}function swapModeState(){writeState(modeFrontState);var a=modeBackState;modeBackState=modeFrontState,modeFrontState=a,readState(modeFrontState)}function writeState(a){a.ackINT=ackINT,a.prefix=prefix,a.T=T,a.W=W,
a.opcode=opcode,a.PC=PC,a.SP=SP,a.I=I,a.R=R,a.IFF1=IFF1,a.IM=IM,a.AF=fromAF(),a.BC=fromBC(),a.DE=DE,a.HL=HL,a.IX=fromIX(),a.IY=fromIY(),a.AF2=AF2,a.BC2=BC2,a.DE2=DE2,a.HL2=HL2,a.extCurrRunning=extCurrRunning,a.extExtraIters=extExtraIter}function readState(a){ackINT=a.ackINT,prefix=a.prefix,T=a.T,W=a.W,opcode=a.opcode,instruction=instrWait,PC=a.PC,SP=a.SP,I=a.I,R=a.R,IFF1=a.IFF1,IM=a.IM,toAF(a.AF),toBC(a.BC),DE=a.DE,HL=a.HL,toIX(a.IX),toIY(a.IY),AF2=a.AF2,BC2=a.BC2,DE2=a.DE2,HL2=a.HL2,extCurrRunning=a.extCurrRunning,extExtraIter=a.extExtraIters}function fetchForceNextBreak(){fetchLastAddress=131071}function busRead(a){return bus.read(a)}function busWrite(a,b){bus.write(a,b)}function fetchN(){return busRead(pcInc())}function fetchNN(){return fetchN()|fetchN()<<8}function memRead(a){return busRead(a)}function memRead16(a){return busRead(a)|busRead(a+1&65535)<<8}function memWrite(a,b){busWrite(a,b)}function memWrite16(a,b){busWrite(a,255&b),busWrite(a+1&65535,b>>>8)}function memWrite16Rev(a,b){busWrite(a+1&65535,b>>>8),busWrite(a,255&b)}function busInput(a){return bus.input(a)}function busOutput(a,b){bus.output(a,b)}function busRead_R800(a){return W+=bus.getAccessWait(a),bus.read(a)}function busWrite_R800(a,b){W+=bus.getAccessWait(a),bus.write(a,b)}function fetchN_R800(){var a=pcInc();return W+=bus.getBreakWait(a,fetchLastAddress),fetchLastAddress=a,busRead_R800(a)}function fetchNN_R800(){return fetchN_R800()|fetchN_R800()<<8}function memRead_R800(a){return fetchForceNextBreak(),busRead_R800(a)}function memRead16_R800(a){return W+=bus.getBreakWait(a,a+1),fetchForceNextBreak(),busRead_R800(a)|busRead_R800(a+1&65535)<<8}function memWrite_R800(a,b){fetchForceNextBreak(),busWrite_R800(a,b)}function memWrite16_R800(a,b){W+=bus.getBreakWait(a,a+1),fetchForceNextBreak(),busWrite_R800(a,255&b),busWrite_R800(a+1&65535,b>>>8)}function memWrite16Rev_R800(a,b){W+=bus.getBreakWait(a,a+1),fetchForceNextBreak(),busWrite_R800(a+1&65535,b>>>8),busWrite_R800(a,255&b)}function busInput_R800(a){return W+=bus.getIOWait(a,clockMulti),bus.input(a)}function busOutput_R800(a,b){W+=bus.getIOWait(a,clockMulti),bus.output(a,b)}function pcInc(){var a=PC;return PC=PC+1&65535,a}function dec2PC(){return PC=PC-2&65535}function fromA(){return A}function fromB(){return B}function fromC(){return C}function fromD(){return DE>>>8}function fromE(){return 255&DE}function fromH(){return HL>>>8}function fromL(){return 255&HL}function fromIXh(){return IX>>>8}function fromIXl(){return 255&IX}function fromIYh(){return IY>>>8}function fromIYl(){return 255&IY}function toA(a){A=a}function toB(a){B=a}function toC(a){C=a}function toD(a){DE=255&DE|a<<8}function toE(a){DE=65280&DE|a}function toH(a){HL=255&HL|a<<8}function toL(a){HL=65280&HL|a}function toIXh(a){IX=255&IX|a<<8}function toIXl(a){IX=65280&IX|a}function toIYh(a){IY=255&IY|a<<8}function toIYl(a){IY=65280&IY|a}function fromAF(){return A<<8|F}function fromBC(){return B<<8|C}function fromDE(){return DE}function fromHL(){return HL}function fromSP(){return SP}function fromIX(){return IX}function fromIY(){return IY}function toAF(a){A=a>>>8,F=255&a}function toBC(a){B=a>>>8,C=255&a}function toDE(a){DE=a}function toHL(a){HL=a}function toSP(a){SP=a}function toIX(a){IX=a}function toIY(a){IY=a}function from_BC_8(){return memRead(fromBC())}function from_BC_8_R800(){return memRead_R800(fromBC())}function from_DE_8(){return memRead(DE)}function from_DE_8_R800(){return memRead_R800(DE)}function from_HL_8(){return memRead(HL)}function from_HL_8_R800(){return memRead_R800(HL)}function from_SP_16(){return memRead16(SP)}function from_SP_16_R800(){return memRead16_R800(SP)}function to_BC_8(a){memWrite(fromBC(),a)}function to_BC_8_R800(a){memWrite_R800(fromBC(),a)}function to_DE_8(a){memWrite(DE,a)}function to_DE_8_R800(a){memWrite_R800(DE,a)}function to_HL_8(a){memWrite(HL,a)}function to_HL_8_R800(a){memWrite_R800(HL,a)}function to_SP_16(a){memWrite16(SP,a)}function to_SP_16_R800(a){memWrite16_R800(SP,a)}function preReadIXYd(){preReadIXYdOffset=fetchN()}function preReadIXYd_R800(){preReadIXYdOffset=fetchN_R800()}function from_IXd_8(){return memRead(sum16Signed(IX,fetchN()))}function from_IXd_8_R800(){return memRead_R800(sum16Signed(IX,fetchN_R800()))}function from_IYd_8(){return memRead(sum16Signed(IY,fetchN()))}function from_IYd_8_R800(){return memRead_R800(sum16Signed(IY,fetchN_R800()))}function to_IXd_8(a){memWrite(sum16Signed(IX,fetchN()),a)}function to_IXd_8_R800(a){memWrite_R800(sum16Signed(IX,fetchN_R800()),a)}function to_IYd_8(a){memWrite(sum16Signed(IY,fetchN()),a)}function to_IYd_8_R800(a){memWrite_R800(sum16Signed(IY,fetchN_R800()),a)}function from_NN_8(){return memRead(fetchNN())}function from_NN_8_R800(){return memRead_R800(fetchNN_R800())}function to_NN_8(a){memWrite(fetchNN(),a)}function to_NN_8_R800(a){memWrite_R800(fetchNN_R800(),a)}function from_NN_16(){return memRead16(fetchNN())}function from_NN_16_R800(){return memRead16_R800(fetchNN_R800())}function to_NN_16(a){memWrite16(fetchNN(),a)}function to_NN_16_R800(a){memWrite16_R800(fetchNN_R800(),a)}function push16(a){SP=SP-2&65535,memWrite16Rev(SP,a)}function push16_R800(a){SP=SP-2&65535,memWrite16Rev_R800(SP,a)}function pop16(){var a=memRead16(SP);return SP=SP+2&65535,a}function pop16_R800(){var a=memRead16_R800(SP);return SP=SP+2&65535,a}function sum16Signed(a,b){return a+(b>127?-256+b:b)&65535}function NOP(){}function HALT(){--PC}function newLD(a,b){return function(){a(b())}}function LDAI(){A=I,F=1&F|168&A|(0===A)<<nZ|IFF1<<nPV}function LDAR(){A=R7|127&R,F=1&F|168&A|(0===A)<<nZ|IFF1<<nPV}function LDIA(){I=A}function LDRA(){R=A,R7=128&A}function newPUSH(a,b){return b?function(){push16_R800(a())}:function(){push16(a())}}function newPOP(a,b){return b?function(){a(pop16_R800())}:function(){a(pop16())}}function EXDEHL(){var a=DE;DE=HL,HL=a}function EXX(){var a=fromBC();toBC(BC2),BC2=a,a=DE,DE=DE2,DE2=a,a=HL,HL=HL2,HL2=a}function EXAFAF2(){var a=fromAF();toAF(AF2),AF2=a}function newLDI(a){var b=a?from_HL_8_R800:from_HL_8,c=a?to_DE_8_R800:to_DE_8;return function(){c(b()),DE=DE+1&65535,HL=HL+1&65535,--C<0&&(C=255,B=B-1&255),F=193&F|(B+C!==0)<<nPV}}function newLDIR(a,b){var c=b?1:5;return function(){a(),F&bPV&&(dec2PC(),T+=c,instruction=instrWait)}}function newLDD(a){var b=a?from_HL_8_R800:from_HL_8,c=a?to_DE_8_R800:to_DE_8;return function(){c(b()),DE=DE-1&65535,HL=HL-1&65535,--C<0&&(C=255,B=B-1&255),F=193&F|(B+C!==0)<<nPV}}function newLDDR(a,b){var c=b?1:5;return function(){a(),F&bPV&&(dec2PC(),T+=c,instruction=instrWait)}}function newCPI(a){var b=a?from_HL_8_R800:from_HL_8;return function(){var a=b();--C<0&&(C=255,B=B-1&255),HL=HL+1&65535;var c=A-a;F=F&bC|bN|168&c|(0===c)<<nZ|(A^a^c)&bH|(B+C!==0)<<nPV}}function newCPIR(a,b){var c=b?1:5;return function(){a(),F&bPV&&!(F&bZ)&&(dec2PC(),T+=c,instruction=instrWait)}}function newCPD(a){var b=a?from_HL_8_R800:from_HL_8;return function(){var a=b();--C<0&&(C=255,B=B-1&255),HL=HL-1&65535;var c=A-a;F=F&bC|bN|168&c|(0===c)<<nZ|(A^a^c)&bH|(B+C!==0)<<nPV}}function newCPDR(a,b){var c=b?1:5;return function(){a(),F&bPV&&!(F&bZ)&&(dec2PC(),T+=c,instruction=instrWait)}}function DAA(){var a=A;F&bN?((F&bH||(15&A)>9)&&(a-=6),(F&bC||A>153)&&(a-=96)):((F&bH||(15&A)>9)&&(a+=6),(F&bC||A>153)&&(a+=96)),a&=255,F=3&F|168&a|(0===a)<<nZ|(A^a)&bH|parities[a]|A>153,A=a}function CPL(){A=255&~A,F=197&F|18|40&A}function NEG(){var a=A;A=255&-A,F=bN|168&A|(0===A)<<nZ|(0!=(15&a))<<nH|(128===a)<<nPV|0!==a}function CCF(){F=196&F|40&A|(F&bC)<<nH|~F&bC}function SCF(){F=196&F|bC}function DI(){IFF1=0,ackINT=!1}function EI(){IFF1=1,prefix=7,ackINT=!1}function RLCA(){A=255&(A<<1|A>>>7),F=196&F|40&A|A&bC}function RLA(){var a=A;A=255&(A<<1|F&bC),F=196&F|40&A|a>>>7&bC}function RRCA(){A=255&(A>>>1|A<<7),F=196&F|40&A|A>>>7}function RRA(){var a=A;A=A>>>1|(F&bC)<<7,F=196&F|40&A|a&bC}function newRLD(a){var b=a?from_HL_8_R800:from_HL_8,c=a?to_HL_8_R800:to_HL_8;return function(){var a=b();c(255&(a<<4|15&A)),
A=240&A|a>>>4,F=F&bC|168&A|(0===A)<<nZ|parities[A]}}function newRRD(a){var b=a?from_HL_8_R800:from_HL_8,c=a?to_HL_8_R800:to_HL_8;return function(){var a=b();c(255&(A<<4|a>>>4)),A=240&A|15&a,F=F&bC|168&A|(0===A)<<nZ|parities[A]}}function JR(){var a=fetchN();PC=sum16Signed(PC,a)}function JR_R800(){var a=fetchN_R800();PC=sum16Signed(PC,a)}function DJNZ(){var a=fetchN();0!==(B=B-1&255)&&(PC=sum16Signed(PC,a),T+=5,instruction=instrWait)}function DJNZ_R800(){var a=fetchN_R800();0!==(B=B-1&255)&&(PC=sum16Signed(PC,a),T+=1,instruction=instrWait)}function CALL(){var a=fetchNN();push16(PC),PC=a}function CALL_R800(){var a=fetchNN_R800();push16_R800(PC),PC=a}function RET(){PC=pop16()}function RET_R800(){PC=pop16_R800()}function INAn(){var a=fetchN();A=busInput(A<<8|a)}function INAn_R800(){var a=fetchN_R800();A=busInput_R800(A<<8|a)}function newINI(a){var b=a?to_HL_8_R800:to_HL_8,c=a?busInput_R800:busInput;return function(){b(c(fromBC())),HL=HL+1&65535,B=B-1&255,F=F&bC|bN|(0===B)<<nZ}}function newINIR(a,b){var c=b?1:5;return function(){a(),0!==B&&(dec2PC(),T+=c,instruction=instrWait)}}function newIND(a){var b=a?to_HL_8_R800:to_HL_8,c=a?busInput_R800:busInput;return function(){b(c(fromBC())),HL=HL-1&65535,B=B-1&255,F=F&bC|bN|(0===B)<<nZ}}function newINDR(a,b){var c=b?1:5;return function(){a(),0!==B&&(dec2PC(),T+=c,instruction=instrWait)}}function OUTnA(){var a=fetchN();busOutput(A<<8|a,A)}function OUTnA_R800(){var a=fetchN_R800();busOutput_R800(A<<8|a,A)}function newOUTI(a){var b=a?from_HL_8_R800:from_HL_8,c=a?busOutput_R800:busOutput;return function(){var a=b();B=B-1&255,HL=HL+1&65535,F=F&bC|bN|(0===B)<<nZ,c(fromBC(),a)}}function newOTIR(a,b){var c=b?1:5;return function(){1!==B&&(dec2PC(),T+=c,instruction=instrWait),a()}}function newOUTD(a){var b=a?from_HL_8_R800:from_HL_8,c=a?busOutput_R800:busOutput;return function(){var a=b();B=B-1&255,HL=HL-1&65535,F=F&bC|bN|(0===B)<<nZ,c(fromBC(),a)}}function newOTDR(a,b){var c=b?1:5;return function(){1!==B&&(dec2PC(),T+=c,instruction=instrWait),a()}}function newLD_PreRead_IXYd_(a,b,c){var d=c?preReadIXYd_R800:preReadIXYd;return function(){d(),a(b())}}function newEXr_SP_16(a,b,c){var d=c?from_SP_16_R800:from_SP_16,e=c?to_SP_16_R800:to_SP_16;return function(){var c=d();e(b()),a(c)}}function newADD(a){return function(){var b=a(),c=A+b,d=A^b^c;A=255&c,F=168&A|(0===A)<<nZ|d&bH|(d>>>6^d>>>5)&bPV|c>>>8&bC}}function newADC(a){return function(){var b=a(),c=A+b+(F&bC),d=A^b^c;A=255&c,F=168&A|(0===A)<<nZ|d&bH|(d>>>6^d>>>5)&bPV|c>>>8&bC}}function newSUB(a){return function(){var b=a(),c=A-b,d=A^b^c;A=255&c,F=bN|168&A|(0===A)<<nZ|d&bH|(d>>>6^d>>>5)&bPV|c>>>8&bC}}function newSBC(a){return function(){var b=a(),c=A-b-(F&bC),d=A^b^c;A=255&c,F=bN|168&A|(0===A)<<nZ|d&bH|(d>>>6^d>>>5)&bPV|c>>>8&bC}}function newAND(a){return function(){A&=a(),F=bH|168&A|(0===A)<<nZ|parities[A]}}function newOR(a){return function(){A|=a(),F=168&A|(0===A)<<nZ|parities[A]}}function newXOR(a){return function(){A^=a(),F=168&A|(0===A)<<nZ|parities[A]}}function newCP(a){return function(){var b=a(),c=A-b,d=A^b^c;F=bN|c&bS|40&b|(0===c)<<nZ|d&bH|(d>>>6^d>>>5)&bPV|c>>>8&bC}}function newINC(a,b){return function(){var c=a()+1&255;b(c),F=F&bC|168&c|(0===c)<<nZ|(0==(15&c))<<nH|(128===c)<<nPV}}function newINC_PreRead_IXYd_(a,b,c){var d=c?preReadIXYd_R800:preReadIXYd;return function(){d();var c=a()+1&255;b(c),F=F&bC|168&c|(0===c)<<nZ|(0==(15&c))<<nH|(128===c)<<nPV}}function newDEC(a,b){return function(){var c=a()-1&255;b(c),F=F&bC|bN|168&c|(0===c)<<nZ|(15==(15&c))<<nH|(127===c)<<nPV}}function newDEC_PreRead_IXYd_(a,b,c){var d=c?preReadIXYd_R800:preReadIXYd;return function(){d();var c=a()-1&255;b(c),F=F&bC|bN|168&c|(0===c)<<nZ|(15==(15&c))<<nH|(127===c)<<nPV}}function newIM(a){return function(){IM=a}}function newADD16(a,b,c){return function(){var d=b(),e=c(),f=d+e;a(65535&f),F=196&F|f>>>8&40|(d^e^f)>>>8&bH|f>>>16&bC}}function newADC16(a,b,c){return function(){var d=b(),e=c(),f=d+e+(F&bC);a(65535&f);var g=(d^e^f)>>>8;F=f>>>8&168|(0==(65535&f))<<nZ|g&bH|(g>>>6^g>>>5)&bPV|f>>>16&bC}}function newSBC16(a,b,c){return function(){var d=b(),e=c(),f=d-e-(F&bC);a(65535&f);var g=(d^e^f)>>>8;F=bN|f>>>8&168|(0==(65535&f))<<nZ|g&bH|(g>>>6^g>>>5)&bPV|f>>>16&bC}}function newINC16(a,b){return function(){a(b()+1&65535)}}function newDEC16(a,b){return function(){a(b()-1&65535)}}function newRLC(a,b,c){return function(){var d=b(),e=255&(d<<1|d>>>7);a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|e&bC}}function newRL(a,b,c){return function(){var d=b(),e=255&(d<<1|F&bC);a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d>>>7&bC}}function newRRC(a,b,c){return function(){var d=b(),e=255&(d>>>1|d<<7);a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d&bC}}function newRR(a,b,c){return function(){var d=b(),e=255&(d>>>1|(F&bC)<<7);a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d&bC}}function newSLA(a,b,c){return function(){var d=b(),e=d<<1&255;a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d>>>7&bC}}function newSRA(a,b,c){return function(){var d=b(),e=d>>>1|128&d;a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d&bC}}function newSLL(a,b,c,d){var e=d?0:1;return function(){var d=b(),f=255&(d<<1|e);a(f),c&&c(f),F=168&f|(0===f)<<nZ|parities[f]|d>>>7&bC}}function newSRL(a,b,c){return function(){var d=b(),e=d>>>1;a(e),c&&c(e),F=168&e|(0===e)<<nZ|parities[e]|d&bC}}function newBIT(a,b,c,d){return function(){var a=b()&1<<c;a?(F=F&bC|bH|a&bS,d&&(F|=40&a)):F=F&bC|84}}function newSET(a,b,c,d){return function(){var e=b()|1<<c;a(e),d&&d(e)}}function newRES(a,b,c,d){return function(){var e=b()&~(1<<c);a(e),d&&d(e)}}function newJP(a,b){return b?function(){PC=a(),fetchForceNextBreak()}:function(){PC=a()}}function newJPcc(a,b,c){return c?function(){var c=fetchNN_R800();(F&a)===b&&(PC=c,++W,fetchForceNextBreak())}:function(){var c=fetchNN();(F&a)===b&&(PC=c)}}function newJRcc(a,b,c){return c?function(){var c=fetchN_R800();(F&a)===b&&(PC=sum16Signed(PC,c),W+=1)}:function(){var c=fetchN();(F&a)===b&&(PC=sum16Signed(PC,c),T+=5,instruction=instrWait)}}function newCALLcc(a,b,c,d){var e=c?fetchNN_R800:fetchNN,f=c?push16_R800:push16,g=d?3+bw:7;return function(){var c=e();(F&a)===b&&(f(PC),PC=c,T+=g,instruction=instrWait)}}function newRETcc(a,b,c){return c?function(){(F&a)===b&&(RET_R800(),T+=2+br,instruction=instrWait)}:function(){(F&a)===b&&(RET(),T+=6,instruction=instrWait)}}function newRST(a,b){return b?function(){push16_R800(PC),PC=a}:function(){push16(PC),PC=a}}function newINrC(a,b){var c=b?busInput_R800:busInput;return function(){var b=c(fromBC());a(b),F=F&bC|168&b|(0===b)<<nZ|parities[b]}}function newOUTCr(a,b){var c=b?busOutput_R800:busOutput;return function(){c(fromBC(),a())}}function newMULUB(a){return function(){var b=A*a();HL=b,F=18&F|40&b|(0===b)<<nZ|b>255}}function newMULUW(a){return function(){var b=HL*a();DE=b>>>16,HL=65535&b,F=18&F|40&b|(0===b)<<nZ|b>65535}}function uNOP(){}function uIN_C(){var a=busInput(fromBC());F=F&bC|168&a|(0===a)<<nZ|parities[a]}function uIN_C_R800(){var a=busInput_R800(fromBC());F=F&bC|168&a|(0===a)<<nZ|parities[a]}function uOUTC0(){busOutput(fromBC(),0)}function uOUTC0_R800(){busOutput_R800(fromBC(),0)}function pINT_IM01(){push16(PC),PC=56}function pINT_IM01_R800(){push16_R800(PC),PC=56}function pINT_IM2(){push16(PC),PC=memRead16(I<<8|255)}function pINT_IM2_R800(){push16_R800(PC),PC=memRead16_R800(I<<8|255)}function pSET_CB(){prefix=2,ackINT=!1}function pSET_ED(){prefix=1,ackINT=!1}function pSET_DD(){prefix=3,ackINT=!1}function pSET_FD(){prefix=4,ackINT=!1}function newpSET_DDCB(a){var b=a?preReadIXYd_R800:preReadIXYd;return function(){prefix=5,ackINT=!1,b(),--R}}function newpSET_FDCB(a){var b=a?preReadIXYd_R800:preReadIXYd;return function(){prefix=6,ackINT=!1,b(),--R}}function newpEXT(a){function b(a){return{extNum:a,extPC:PC-2,PC:PC,SP:SP,A:A,F:F,B:B,C:C,DE:DE,HL:HL,IX:IX,IY:IY,AF2:AF2,BC2:BC2,DE2:DE2,HL2:HL2}}function c(a){a&&(void 0!==a.PC&&(PC=a.PC),void 0!==a.SP&&(SP=a.SP),void 0!==a.A&&(A=a.A),
void 0!==a.F&&(F=a.F),void 0!==a.B&&(B=a.B),void 0!==a.C&&(C=a.C),void 0!==a.DE&&(DE=a.DE),void 0!==a.HL&&(HL=a.HL),void 0!==a.IX&&(IX=a.IX),void 0!==a.IY&&(IY=a.IY),void 0!==a.AF2&&(AF2=a.AF2),void 0!==a.BC2&&(BC2=a.BC2),void 0!==a.DE2&&(DE2=a.DE2),void 0!==a.HL2&&(HL2=a.HL2),a.extraIterations>0&&(extExtraIter=a.extraIterations))}return function d(){if(null===extCurrRunning){extCurrRunning=a,extExtraIter=0;c(bus.cpuExtensionBegin(b(a))),d()}else if(extExtraIter>0)--extExtraIter,dec2PC();else{var e=bus.cpuExtensionFinish(b(a));c(e),extCurrRunning=null}}}function defineInstructionSet(a,b,c){function d(a,b,d,f,g,h,i,j){var k={};return k.prefix=b?a<<8|b:a,k.opcode=d,k.remainCyclesZ80=f+1,k.remainCyclesR800=g,k.totalCyclesZ80=k.remainCyclesZ80+(a?5:0)+(b?4:0),k.totalCyclesR800=k.remainCyclesR800+(a?1:0)+(b?1:0),k.remainCycles=c?k.remainCyclesR800-1:k.remainCyclesZ80-1,k.operation=h,k.mnemonic=i,k.undocumented=j,k.opcodeString=(k.prefix?wmsx.Util.toHex2(k.prefix):"")+(56779===k.prefix||64971===k.prefix?" ":"")+wmsx.Util.toHex2(k.opcode)+" "+i+(j?"*":""),k.toString=function(){return this.opcodeString},e(k),k}function e(b){if(instructionsAllOld.push(b),b.prefix)if(237===b.prefix)a[1][b.opcode]=b;else if(203===b.prefix)a[2][b.opcode]=b;else if(221===b.prefix)a[3][b.opcode]=b;else if(253===b.prefix)a[4][b.opcode]=b;else if(56779===b.prefix)a[5][b.opcode]=b;else{if(64971!==b.prefix)throw new Error("Invalid instruction prefix!");a[6][b.opcode]=b}else a[0][b.opcode]=b}var f,g,h=0,i=0,j={A:{bits:7,to:toA,from:fromA,desc:"A"},B:{bits:0,to:toB,from:fromB,desc:"B"},C:{bits:1,to:toC,from:fromC,desc:"C"},D:{bits:2,to:toD,from:fromD,desc:"D"},E:{bits:3,to:toE,from:fromE,desc:"E"},H:{bits:4,to:toH,from:fromH,desc:"H"},L:{bits:5,to:toL,from:fromL,desc:"L"}},k={A:{bits:7,to:toA,from:fromA,desc:"A"},B:{bits:0,to:toB,from:fromB,desc:"B"},C:{bits:1,to:toC,from:fromC,desc:"C"},D:{bits:2,to:toD,from:fromD,desc:"D"},E:{bits:3,to:toE,from:fromE,desc:"E"},H:{bits:4,to:toH,from:fromH,desc:"H",nopref:!0},L:{bits:5,to:toL,from:fromL,desc:"L",nopref:!0},IXh:{bits:4,to:toIXh,from:fromIXh,desc:"IXh",pref:221},IXl:{bits:5,to:toIXl,from:fromIXl,desc:"IXl",pref:221},IYh:{bits:4,to:toIYh,from:fromIYh,desc:"IYh",pref:253},IYl:{bits:5,to:toIYl,from:fromIYl,desc:"IYl",pref:253}},l={_HL_:{to:b?to_HL_8_R800:to_HL_8,from:b?from_HL_8_R800:from_HL_8,desc:"(HL)"},_IXd_:{to:b?to_IXd_8_R800:to_IXd_8,from:b?from_IXd_8_R800:from_IXd_8,desc:"(IX+d)",pref:221},_IYd_:{to:b?to_IYd_8_R800:to_IYd_8,from:b?from_IYd_8_R800:from_IYd_8,desc:"(IY+d)",pref:253}},m=64;for(g in k){var n=k[g];for(f in k){var o=k[f];if(!(n.pref&&(o.nopref||o.pref&&o.pref!=n.pref)||o.pref&&(n.nopref||n.pref&&n.pref!=o.pref))){var p=m|n.bits<<3|o.bits,q=newLD(n.to,o.from),r=n.pref|o.pref;d(r,null,p,4,1,q,"LD "+n.desc+", "+o.desc,r)}}}m=6;for(g in k)n=k[g],p=m|n.bits<<3,q=newLD(n.to,b?fetchN_R800:fetchN),r=n.pref,d(r,null,p,7,2,q,"LD "+n.desc+", n",r);m=70;for(g in j){n=j[g];for(f in l)o=l[f],p=m|n.bits<<3,q=newLD(n.to,o.from),r=o.pref,d(r,null,p,7+(r?8:0),2+br+(r?2:0),q,"LD "+n.desc+", "+o.desc,!1)}m=112;for(g in l){n=l[g];for(f in j)o=j[f],p=m|o.bits,q=newLD(n.to,o.from),r=n.pref,d(r,null,p,7+(r?8:0),2+bw+(r?2:0),q,"LD "+n.desc+", "+o.desc,!1)}m=54;for(g in l)n=l[g],p=m,r=n.pref,q=r?newLD_PreRead_IXYd_(n.to.toPreReadAddr,b?fetchN_R800:fetchN,b):newLD(n.to,b?fetchN_R800:fetchN),d(r,null,p,10+(r?5:0),3+bw+(r?1:0),q,"LD "+n.desc+", n",!1);p=10,q=newLD(toA,b?from_BC_8_R800:from_BC_8),d(null,null,p,7,2+br,q,"LD A, (BC)",!1),p=26,q=newLD(toA,b?from_DE_8_R800:from_DE_8),d(null,null,p,7,2+br,q,"LD A, (DE)",!1),p=58,q=newLD(toA,b?from_NN_8_R800:from_NN_8),d(null,null,p,13,4+br,q,"LD A, (nn)",!1),p=2,q=newLD(b?to_BC_8_R800:to_BC_8,fromA),d(null,null,p,7,2+bw,q,"LD (BC), A",!1),p=18,q=newLD(b?to_DE_8_R800:to_DE_8,fromA),d(null,null,p,7,2+bw,q,"LD (DE), A",!1),p=50,q=newLD(b?to_NN_8_R800:to_NN_8,fromA),d(null,null,p,13,4+bw,q,"LD (nn), A",!1),p=87,q=LDAI,d(null,237,p,5,2,q,"LD A, I",!1),p=95,q=LDAR,d(null,237,p,5,2,q,"LD A, R",!1),p=71,q=LDIA,d(null,237,p,5,2,q,"LD I, A",!1),p=79,q=LDRA,d(null,237,p,5,2,q,"LD R, A",!1);var s={BC:{bits:0,to:toBC,from:fromBC,desc:"BC"},DE:{bits:1,to:toDE,from:fromDE,desc:"DE"},HL:{bits:2,to:toHL,from:fromHL,desc:"HL"},SP:{bits:3,to:toSP,from:fromSP,desc:"SP"}},t={BC:{bits:0,to:toBC,from:fromBC,desc:"BC"},DE:{bits:1,to:toDE,from:fromDE,desc:"DE"},HL:{bits:2,to:toHL,from:fromHL,desc:"HL",nopref:!0},SP:{bits:3,to:toSP,from:fromSP,desc:"SP"},IX:{bits:2,to:toIX,from:fromIX,desc:"IX",pref:221},IY:{bits:2,to:toIY,from:fromIY,desc:"IY",pref:253}},u={BC:{bits:0,to:toBC,from:fromBC,desc:"BC"},DE:{bits:1,to:toDE,from:fromDE,desc:"DE"},HL:{bits:2,to:toHL,from:fromHL,desc:"HL"},AF:{bits:3,to:toAF,from:fromAF,desc:"AF"},IX:{bits:2,to:toIX,from:fromIX,desc:"IX",pref:221},IY:{bits:2,to:toIY,from:fromIY,desc:"IY",pref:253}},v={HL:{to:toHL,from:fromHL,desc:"HL",nopref:!0},IXd:{to:toIX,from:fromIX,desc:"IX",pref:221},IYd:{to:toIY,from:fromIY,desc:"IY",pref:253}};m=1;for(g in t)n=t[g],p=m|n.bits<<4,q=newLD(n.to,b?fetchNN_R800:fetchNN),r=n.pref,d(r,null,p,10,3,q,"LD "+n.desc+", nn",!1);p=42;for(g in v)n=v[g],q=newLD(n.to,b?from_NN_16_R800:from_NN_16),r=n.pref,d(r,null,p,16,5+br,q,"LD "+n.desc+", (nn)",!1);m=75;for(g in s)n=s[g],p=m|n.bits<<4,q=newLD(n.to,b?from_NN_16_R800:from_NN_16),d(null,237,p,16,5+br,q,"LD "+n.desc+", (nn)",!1);p=34;for(f in v)o=v[f],q=newLD(b?to_NN_16_R800:to_NN_16,o.from),r=o.pref,d(r,null,p,16,5+bw,q,"LD (nn), "+o.desc,!1);m=67;for(f in s)o=s[f],p=m|o.bits<<4,q=newLD(b?to_NN_16_R800:to_NN_16,o.from),d(null,237,p,16,5+bw,q,"LD (nn), "+o.desc,!1);p=249;for(f in v)o=v[f],q=newLD(toSP,o.from),r=o.pref,d(r,null,p,6,1,q,"LD SP, "+o.desc,!1);m=197;for(f in u)o=u[f],p=m|o.bits<<4,q=newPUSH(o.from,b),r=o.pref,d(r,null,p,11,4+bw,q,"PUSH "+o.desc,!1);m=193;for(g in u)n=u[g],p=m|n.bits<<4,q=newPOP(n.to,b),r=n.pref,d(r,null,p,10,3+br,q,"POP "+n.desc,!1);p=235,q=EXDEHL,d(null,null,p,4,1,q,"EX DE, HL",!1),p=8,q=EXAFAF2,d(null,null,p,4,1,q,"EX AF, AF'",!1),p=217,q=EXX,d(null,null,p,4,1,q,"EXX",!1),p=227;for(var w in v){var x=v[w];q=newEXr_SP_16(x.to,x.from,b),r=x.pref,d(r,null,p,19,5+bw,q,"EX (SP), "+x.desc,!1)}p=160,q=newLDI(b),d(null,237,p,12,3+br+bw,q,"LDI",!1),p=176,q=newLDIR(q,c),d(null,237,p,12,3+br+bw,q,"LDIR",!1),p=168,q=newLDD(b),d(null,237,p,12,3+br+bw,q,"LDD",!1),p=184,q=newLDDR(q,c),d(null,237,p,12,3+br+bw,q,"LDDR",!1),p=161,q=newCPI(b),d(null,237,p,12,3+br,q,"CPI",!1),p=177,q=newCPIR(q,c),d(null,237,p,12,4+br,q,"CPIR",!1),p=169,q=newCPD(b),d(null,237,p,12,3+br,q,"CPD",!1),p=185,q=newCPDR(q,c),d(null,237,p,12,4+br,q,"CPDR",!1);var y={ADD:{desc:"ADD A, ",instr:newADD,variations:{rp:{opcode:128},n:{opcode:198},_HLp_:{opcode:134,T:7,Tr:2+br}}},ADC:{desc:"ADC A, ",instr:newADC,variations:{rp:{opcode:136},n:{opcode:206},_HLp_:{opcode:142,T:7,Tr:2+br}}},SUB:{desc:"SUB ",instr:newSUB,variations:{rp:{opcode:144},n:{opcode:214},_HLp_:{opcode:150,T:7,Tr:2+br}}},SBC:{desc:"SBC A, ",instr:newSBC,variations:{rp:{opcode:152},n:{opcode:222},_HLp_:{opcode:158,T:7,Tr:2+br}}},AND:{desc:"AND ",instr:newAND,variations:{rp:{opcode:160},n:{opcode:230},_HLp_:{opcode:166,T:7,Tr:2+br}}},OR:{desc:"OR ",instr:newOR,variations:{rp:{opcode:176},n:{opcode:246},_HLp_:{opcode:182,T:7,Tr:2+br}}},XOR:{desc:"XOR ",instr:newXOR,variations:{rp:{opcode:168},n:{opcode:238},_HLp_:{opcode:174,T:7,Tr:2+br}}},CP:{desc:"CP ",instr:newCP,variations:{rp:{opcode:184},n:{opcode:254},_HLp_:{opcode:190,T:7,Tr:2+br}}},INC:{desc:"INC ",instr:newINC,selfModifyInstr:newINC_PreRead_IXYd_,variations:{rp:{opcode:4,rShift:3},_HLp_:{opcode:52,T:11,Tr:4+br+bw}}},DEC:{desc:"DEC ",instr:newDEC,selfModifyInstr:newDEC_PreRead_IXYd_,variations:{rp:{opcode:5,rShift:3},_HLp_:{opcode:53,T:11,Tr:4+br+bw}}}};for(var z in y){var A=y[z],B=A.variations.rp;m=B.opcode;for(w in k)x=k[w],p=m|x.bits<<B.rShift,q=A.instr(x.from,x.to),r=x.pref,d(r,null,p,4,1,q,A.desc+x.desc,r);B=A.variations.n,
B&&(p=B.opcode,q=A.instr(b?fetchN_R800:fetchN,null),d(null,null,p,7,2,q,A.desc+"n",!1)),B=A.variations._HLp_,p=B.opcode;for(w in l)x=l[w],r=x.pref,q=r&&A.selfModifyInstr?A.selfModifyInstr(x.from.fromPreReadAddr,x.to.toPreReadAddr,b):A.instr(x.from,x.to),d(r,null,p,B.T+(r?8:0),B.Tr+(r?2:0),q,A.desc+x.desc,!1)}p=39,q=DAA,d(null,null,p,4,1,q,"DAA",!1),p=47,q=CPL,d(null,null,p,4,1,q,"CPL",!1),p=68,q=NEG,d(null,237,p,4,1,q,"NEG",!1),p=63,q=CCF,d(null,null,p,4,1,q,"CCF",!1),p=55,q=SCF,d(null,null,p,4,1,q,"SCF",!1),p=0,q=NOP,d(null,null,p,4,1,q,"NOP",!1),p=118,q=HALT,d(null,null,p,4,2,q,"HALT",!1),p=243,q=DI,d(null,null,p,4,2,q,"DI",!1),p=251,q=EI,d(null,null,p,4,1,q,"EI",!1),p=70,q=newIM(0),d(null,237,p,4,2,q,"IM 0",!1),p=86,q=newIM(1),d(null,237,p,4,2,q,"IM 1",!1),p=94,q=newIM(2),d(null,237,p,4,2,q,"IM 2",!1);var C={ADC:{desc:"ADC HL, ",instr:newADC16,opcode:74},SBC:{desc:"SBC HL, ",instr:newSBC16,opcode:66}},D={INC:{desc:"INC ",instr:newINC16,opcode:3},DEC:{desc:"DEC ",instr:newDEC16,opcode:11}};m=9;for(g in v){n=v[g];for(f in t)o=t[f],n.pref&&(o.nopref||o.pref&&o.pref!=n.pref)||o.pref&&(n.nopref||n.pref&&n.pref!=o.pref)||(p=m|o.bits<<4,q=newADD16(n.to,n.from,o.from),r=n.pref,d(r,null,p,11,1,q,"ADD "+n.desc+", "+o.desc,!1))}for(z in C){A=C[z],m=A.opcode;for(w in s)x=s[w],p=m|x.bits<<4,q=A.instr(toHL,fromHL,x.from),d(null,237,p,11,1,q,A.desc+x.desc,!1)}for(z in D){A=D[z],m=A.opcode;for(w in t)x=t[w],p=m|x.bits<<4,q=A.instr(x.to,x.from),r=x.pref,d(r,null,p,6,1,q,A.desc+x.desc,!1)}p=7,q=RLCA,d(null,null,p,4,1,q,"RLCA",!1),p=23,q=RLA,d(null,null,p,4,1,q,"RLA",!1),p=15,q=RRCA,d(null,null,p,4,1,q,"RRCA",!1),p=31,q=RRA,d(null,null,p,4,1,q,"RRA",!1);var E={A:{bits:7,to:toA,from:fromA,desc:"A"},B:{bits:0,to:toB,from:fromB,desc:"B"},C:{bits:1,to:toC,from:fromC,desc:"C"},D:{bits:2,to:toD,from:fromD,desc:"D"},E:{bits:3,to:toE,from:fromE,desc:"E"},H:{bits:4,to:toH,from:fromH,desc:"H"},L:{bits:5,to:toL,from:fromL,desc:"L"},_HL_:{bits:6,to:b?to_HL_8_R800:to_HL_8,from:b?from_HL_8_R800:from_HL_8,desc:"(HL)"}},F={_IXd_:{prefix:221,to:(b?to_IXd_8_R800:to_IXd_8).toPreReadAddr,from:(b?from_IXd_8_R800:from_IXd_8).fromPreReadAddr,desc:"(IX+d)"},_IYd_:{prefix:253,to:(b?to_IYd_8_R800:to_IYd_8).toPreReadAddr,from:(b?from_IYd_8_R800:from_IYd_8).fromPreReadAddr,desc:"(IY+d)"}},G={RLC:{desc:"RLC ",instr:newRLC,opcode:0},RL:{desc:"RL ",instr:newRL,opcode:16},RRC:{desc:"RRC ",instr:newRRC,opcode:8},RR:{desc:"RR ",instr:newRR,opcode:24},SLA:{desc:"SLA ",instr:newSLA,opcode:32},SRA:{desc:"SRA ",instr:newSRA,opcode:40},SLL:{desc:"SLL ",instr:newSLL,opcode:48,undoc:!b},SRL:{desc:"SRL ",instr:newSRL,opcode:56}};for(z in G){A=G[z],m=A.opcode;for(w in E)x=E[w],p=m|x.bits,q=A.instr(x.to,x.from,null,b),h="_HL_"===w?11:4,i="_HL_"===w?4+br+bw:1,d(null,203,p,h,i,q,A.desc+x.desc,A.undoc);for(var H in F){var I=F[H];for(w in E){x=E[w],p=m|x.bits;var J="_HL_"!==w?x.to:null;q=A.instr(I.to,I.from,J,b),d(I.prefix,203,p,15,5+br+bw,q,A.desc+I.desc+(J?", "+x.desc:""),A.undoc||J)}}}p=111,q=newRLD(b),d(null,237,p,14,4+br+bw,q,"RLD",!1),p=103,q=newRRD(b),d(null,237,p,14,4+br+bw,q,"RRD",!1);var K={BIT:{desc:"BIT ",instr:newBIT,opcode:64,T_HL_:8,T_HL_r:2+br},SET:{desc:"SET ",instr:newSET,opcode:192,T_HL_:11,T_HL_r:4+br+bw,toExt:!0},RES:{desc:"RES ",instr:newRES,opcode:128,T_HL_:11,T_HL_r:4+br+bw,toExt:!0}};for(z in K){A=K[z],m=A.opcode;for(w in E){x=E[w];for(var L=0;L<=7;L++)p=m|L<<3|x.bits,q=A.instr(x.to,x.from,L,null),h="_HL_"===w?A.T_HL_:4,i="_HL_"===w?A.T_HL_r:1,d(null,203,p,h,i,q,A.desc+L+", "+x.desc,!1)}for(H in F){I=F[H];for(w in E)for(x=E[w],L=0;L<=7;L++){p=m|L<<3|x.bits;var M="_HL_"!=w;J=M&&A.toExt?x.to:null,q=A.instr(I.to,I.from,L,J),d(I.prefix,203,p,A.T_HL_+4,A.T_HL_r+1,q,A.desc+L+", "+I.desc+(J?", "+x.desc:""),M)}}}var N={nn:{desc:"nn",from:b?fetchNN_R800:fetchNN,opcode:195,T:10,Tr:4},HL:{desc:"(HL)",from:fromHL,opcode:233,T:4,Tr:2},IX:{desc:"(IX)",from:fromIX,opcode:233,T:4,Tr:2,pref:221},IY:{desc:"(IY)",from:fromIY,opcode:233,T:4,Tr:2,pref:253}},O={NZ:{bits:0,desc:"NZ",flag:bZ,val:0},Z:{bits:1,desc:"Z",flag:bZ,val:bZ},NC:{bits:2,desc:"NC",flag:bC,val:0},C:{bits:3,desc:"C",flag:bC,val:bC},PO:{bits:4,desc:"PO",flag:bPV,val:0},PE:{bits:5,desc:"PE",flag:bPV,val:bPV},P:{bits:6,desc:"P",flag:bS,val:0},M:{bits:7,desc:"M",flag:bS,val:bS}};for(w in N)x=N[w],p=x.opcode,q=newJP(x.from,b),r=x.pref,d(r,null,p,x.T,x.Tr,q,"JP "+x.desc,!1);m=194;for(w in O)x=O[w],p=m|x.bits<<3,q=newJPcc(x.flag,x.val,b),d(null,null,p,10,3,q,"JP "+x.desc+", nn",!1);p=24,q=b?JR_R800:JR,d(null,null,p,12,3,q,"JR e",!1);var P={C:{opcode:56,desc:"C",flag:bC,val:bC},NC:{opcode:48,desc:"NC",flag:bC,val:0},Z:{opcode:40,desc:"Z",flag:bZ,val:bZ},NZ:{opcode:32,desc:"NZ",flag:bZ,val:0}};for(w in P)x=P[w],p=x.opcode,q=newJRcc(x.flag,x.val,b),d(null,null,p,7,2,q,"JR "+x.desc+", e",!1);p=16,q=b?DJNZ_R800:DJNZ,d(null,null,p,8,2,q,"DJNZ e",!1),p=205,q=b?CALL_R800:CALL,d(null,null,p,17,6+bw,q,"CALL nn",!1),m=196;for(w in O)x=O[w],p=m|x.bits<<3,q=newCALLcc(x.flag,x.val,b,c),d(null,null,p,10,3,q,"CALL "+x.desc+", nn",!1);p=201,q=b?RET_R800:RET,d(null,null,p,10,3+br,q,"RET",!1),m=192;for(w in O)x=O[w],p=m|x.bits<<3,q=newRETcc(x.flag,x.val,b),d(null,null,p,5,1,q,"RET "+x.desc,!1);p=77,q=b?RET_R800:RET,d(null,237,p,10,4+br,q,"RETI",!1),p=69,q=b?RET_R800:RET,d(null,237,p,10,4+br,q,"RETN",!1);var Q={h00:{bits:0,addr:0,desc:"00h"},h08:{bits:1,addr:8,desc:"08h"},h10:{bits:2,addr:16,desc:"10h"},h18:{bits:3,addr:24,desc:"18h"},h20:{bits:4,addr:32,desc:"20h"},h28:{bits:5,addr:40,desc:"28h"},h30:{bits:6,addr:48,desc:"30h"},h38:{bits:7,addr:56,desc:"38h"}};m=199;for(w in Q)x=Q[w],p=m|x.bits<<3,q=newRST(x.addr,b),d(null,null,p,11,5+bw,q,"RST "+x.desc,!1);p=219,q=b?INAn_R800:INAn,d(null,null,p,11,9,q,"IN A, (n)",!1),m=64;for(w in j)x=j[w],p=m|x.bits<<3,q=newINrC(x.to,b),d(null,237,p,8,8,q,"IN "+x.desc+", (C)",!1);p=162,q=newINI(b),d(null,237,p,12,10,q,"INI",!1),p=178,q=newINIR(q,c),d(null,237,p,12,10,q,"INIR",!1),p=170,q=newIND(b),d(null,237,p,12,10,q,"IND",!1),p=186,q=newINDR(q,c),d(null,237,p,12,10,q,"INDR",!1),p=211,q=b?OUTnA_R800:OUTnA,d(null,null,p,11,9,q,"OUT (n), A",!1),m=65;for(w in j)x=j[w],p=m|x.bits<<3,q=newOUTCr(x.from,b),d(null,237,p,8,8,q,"OUT (C), "+x.desc,!1);if(p=163,q=newOUTI(b),d(null,237,p,12,10,q,"OUTI",!1),p=179,q=newOTIR(q,c),d(null,237,p,12,10,q,"OTIR",!1),p=171,q=newOUTD(b),d(null,237,p,12,10,q,"OUTD",!1),p=187,q=newOTDR(q,c),d(null,237,p,12,10,q,"OTDR",!1),b){m=193;for(w in j)x=j[w],p=m|x.bits<<3,q=newMULUB(x.from),d(null,237,p,4,13,q,"MULUB A, "+x.desc,!1);m=195;for(w in s)x=s[w],p=m|x.bits<<4,q=newMULUW(x.from),d(null,237,p,4,35,q,"MULUW HL, "+x.desc,!1)}var R=[76,84,92,100,108,116,124];for(q=NEG,z=0;z<R.length;z++)p=R[z],d(null,237,p,4,1,q,"NEG",!0);for(R=[85,93,101,109,117,125],q=b?RET_R800:RET,z=0;z<R.length;z++)p=R[z],d(null,237,p,10,4+br,q,"RETN",!0);for(R=[78,102,110],q=newIM(0),z=0;z<R.length;z++)p=R[z],d(null,237,p,4,2,q,"IM 0",!0);for(p=118,q=newIM(1),d(null,237,p,4,2,q,"IM 1",!0),p=126,q=newIM(2),d(null,237,p,4,2,q,"IM 2",!0),p=112,q=b?uIN_C_R800:uIN_C,d(null,237,p,8,8,q,"IN (C)",!0),p=113,q=b?uOUTC0_R800:uOUTC0,d(null,237,p,8,8,q,"OUT (C), 0",!0),p=224;p<=255;p++)a[1][p]||(q=newpEXT(p),d(null,237,p,4,1,q,"EXT "+p.toString(16),!0));for(q=uNOP,p=0;p<=255;p++)a[1][p]||d(null,237,p,4,1,q,"NOP",!0);p=203,q=pSET_CB,d(null,null,p,4,1,q,"< SET CB >",!1),p=237,q=pSET_ED,d(null,null,p,4,1,q,"< SET ED >",!1),p=221,q=pSET_DD,d(null,null,p,4,1,q,"< SET DD >",!1),p=221,q=pSET_DD,d(221,null,p,4,1,q,"< SET DD again >",!1),p=253,q=pSET_FD,d(221,null,p,4,1,q,"< SWITCH to FD >",!1),p=203,q=newpSET_DDCB(b),d(221,null,p,3,1,q,"< SET DDCB >",!1),p=253,q=pSET_FD,d(null,null,p,4,1,q,"< SET FD >",!1),p=253,q=pSET_FD,d(253,null,p,4,1,q,"< SET FD again >",!1),p=221,q=pSET_DD,d(253,null,p,4,1,q,"< SWITCH to DD >",!1),p=203,q=newpSET_FDCB(b),d(253,null,p,3,1,q,"< SET FDCB >",!1),p=257,q=NOP,instrWait=d(null,null,p,1,1,q,"< WAIT CYCLES >",!1),p=258,
q=b?pINT_IM01_R800:pINT_IM01,d(null,null,p,13,3+bw,q,"< INT_M01 >",!1),p=259,q=b?pINT_IM2_R800:pINT_IM2,d(null,null,p,19,5+bw+br,q,"< INT_M2 >",!1);for(var S=0,T=a.length;S<T;++S)instructionsAll.push.apply(instructionsAll,a[S])}var self=this,r800Timing=WMSX.R800_TIMING;this.connectBus=function(a){bus=a},this.setMachineType=function(a){r800Present=a>=wmsx.Machine.MACHINE_TYPE.MSXTR,updateR800Present()},this.powerOn=function(){setINT(255),this.reset(),toAF(65533),toBC(65535),DE=65535,HL=65535,AF2=65533,BC2=65535,DE2=65535,HL2=65535,toIX(65535),toIY(65535),SP=65535,writeState(modeBackState)},this.powerOff=function(){},this.reset=function(){r800=!1,cpuCycles=0,busCycles=0,cpuToBusCycles=0,ackINT=!1,prefix=0,T=0,W=0,opcode=0,instruction=void 0,PC=0,I=0,R=0,R7=0,IFF1=0,IM=0,extCurrRunning=null,extExtraIter=0,fetchForceNextBreak(),writeState(modeBackState),updateInstructionSet()},this.setR800Mode=function(a){r800!==a&&(r800=a,swapModeState(),updateInstructionSet(),updateClockMulti())},this.setZ80BUSRQ=function(a){z80BUSRQ=a},this.busClockPulsesZ80=function(a){if(!z80BUSRQ)for(var b=cpuCycles+(a*clockMulti|0);cpuCycles<b;++cpuCycles)--T>0||(T<0?ackINT?acknowledgeINT():fetchNextInstruction():instruction.operation())},this.busClockPulsesBoth=function(a){if(!z80BUSRQ||r800)for(var b=cpuCycles+(a*clockMulti|0);cpuCycles<b;++cpuCycles)if(!(--T>0))if(T<0){if(W>0){--W;continue}ackINT?acknowledgeINT():(fetchNextInstruction(),0===T&&instruction.operation())}else instruction.operation()},this.busClockPulses=this.busClockPulsesZ80,this.r800MemoryRefresh=function(){r800&&(++R,W+=28)},this.setINTChannel=function(a,b){setINT(b?INT|1<<a:INT&~(1<<a))},this.getBUSCycles=function(){return busCycles+=(cpuCycles-cpuToBusCycles)/clockMulti|0,cpuToBusCycles=cpuCycles,busCycles},this.setZ80ClockMulti=function(a){z80ClockMulti=a<=0?1:a>8?8:a,r800||updateClockMulti()},this.getZ80ClockMulti=function(){return z80ClockMulti},this.setR800ClockMulti=function(a){r800ClockMulti=2*(a<=0?1:a>2?2:a),r800&&updateClockMulti()},this.getR800ClockMulti=function(){return r800ClockMulti/2},this.getClockFreqDesc=function(a){return(3.58*a).toFixed(2)+" MHz"};var r800=!1,r800Present=!1,modeBackState={},modeFrontState={},z80BUSRQ=!1,z80ClockMulti=1,r800ClockMulti=2,clockMulti=z80ClockMulti,cpuCycles=0,busCycles=0,cpuToBusCycles=0,extCurrRunning=null,extExtraIter=0,bus,INT=255,PC=0,SP=0,A=0,F=0,B=0,C=0,DE=0,HL=0,IX=0,IY=0,AF2=0,BC2=0,DE2=0,HL2=0,I=0,R=0,R7=0,IFF1=0,IM=0,bS=128,nS=7,bZ=64,nZ=6,bF5=32,nF5=5,bH=16,nH=4,bF3=8,nF3=3,bPV=4,nPV=2,bN=2,nN=1,bC=1,nC=0,T=0,W=0,opcode=0,prefix=0,instruction,ackINT=!1,fetchLastAddress=0,instructionsNoPrefixZ80=new Array(280),instructionsByPrefixZ80=[instructionsNoPrefixZ80,new Array(280),new Array(280),new Array(280),new Array(280),new Array(280),new Array(280),instructionsNoPrefixZ80],instructionsNoPrefixR800=new Array(280),instructionsByPrefixR800=[instructionsNoPrefixR800,new Array(280),new Array(280),new Array(280),new Array(280),new Array(280),new Array(280),instructionsNoPrefixR800],instructionsAll=[],instructionsAllOld=[],instructionsNoPrefix,instructionsByPrefix,instrWait;1!==r800Timing&&(busRead_R800=busRead,busWrite_R800=busWrite,fetchN_R800=fetchN,fetchNN_R800=fetchNN,memRead_R800=memRead,memRead16_R800=memRead16,memWrite_R800=memWrite,memWrite16_R800=memWrite16,memWrite16Rev_R800=memWrite16Rev),0===r800Timing&&(busInput_R800=busInput,busOutput_R800=busOutput);var preReadIXYdOffset=0;from_IXd_8.fromPreReadAddr=function(){return memRead(sum16Signed(IX,preReadIXYdOffset))},from_IXd_8_R800.fromPreReadAddr=function(){return memRead_R800(sum16Signed(IX,preReadIXYdOffset))},from_IYd_8.fromPreReadAddr=function(){return memRead(sum16Signed(IY,preReadIXYdOffset))},from_IYd_8_R800.fromPreReadAddr=function(){return memRead_R800(sum16Signed(IY,preReadIXYdOffset))},to_IXd_8.toPreReadAddr=function(a){memWrite(sum16Signed(IX,preReadIXYdOffset),a)},to_IXd_8_R800.toPreReadAddr=function(a){memWrite_R800(sum16Signed(IX,preReadIXYdOffset),a)},to_IYd_8.toPreReadAddr=function(a){memWrite(sum16Signed(IY,preReadIXYdOffset),a)},to_IYd_8_R800.toPreReadAddr=function(a){memWrite_R800(sum16Signed(IY,preReadIXYdOffset),a)};var parities=[4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4],br=1,bw=1;this.saveState=function(){return{PC:PC,SP:SP,A:A,F:F,B:B,C:C,DE:DE,HL:HL,IX:IX,IY:IY,AF2:AF2,BC2:BC2,DE2:DE2,HL2:HL2,I:I,R:R,R7:R7,IM:IM,IFF1:IFF1,INT:INT,nINT:1,cc:cpuCycles,bc:busCycles,cbc:cpuToBusCycles,Tn:T,W:W,o:opcode,p:prefix,ai:ackINT,in:instructionsAll.indexOf(instruction),ecr:extCurrRunning,eei:extExtraIter,r8p:r800Present,r8:r800,bs:modeBackState,tcm:z80ClockMulti,rcm:r800ClockMulti}},this.loadState=function(a){PC=a.PC,SP=a.SP,A=a.A,F=a.F,B=a.B,C=a.C,DE=a.DE,HL=a.HL,IX=a.IX,IY=a.IY,AF2=a.AF2,BC2=a.BC2,DE2=a.DE2,HL2=a.HL2,I=a.I,R=a.R,R7=a.R7||0,IM=a.IM,IFF1=a.IFF1,setINT(a.nINT?a.INT:a.INT?255:254),cpuCycles=a.cc||0,busCycles=a.bc||a.c||0,cpuToBusCycles=a.cbc||0,T=void 0!==a.Tn?a.Tn:a.T-1,W=a.W||0,opcode=a.o,prefix=a.p,ackINT=a.ai,extCurrRunning=a.ecr,extExtraIter=a.eei,r800Present=!!a.r8p,r800=!!a.r8,updateR800Present(),instruction=a.in>=0?instructionsAll[a.in]:instructionsAllOld[a.ii],a.bs&&(modeBackState=a.bs),z80ClockMulti=void 0!==a.tcm?a.tcm:a.tcs>0?2:1,r800ClockMulti=void 0!==a.rcm?a.rcm:2,updateInstructionSet(),updateClockMulti()},init(),this.toString=function(){return"CPU  PC: "+wmsx.Util.toHex2(PC)+"      op: "+(instruction?instruction.mnemonic:"NULL")+"          cycle: "+busCycles+"\n\nA: "+wmsx.Util.toHex2(A)+"     B: "+wmsx.Util.toHex2(B)+"     C: "+wmsx.Util.toHex2(C)+"     D: "+wmsx.Util.toHex2(DE>>>8)+"     E: "+wmsx.Util.toHex2(255&DE)+"     H: "+wmsx.Util.toHex2(HL>>>8)+"     L: "+wmsx.Util.toHex2(255&HL)+"\nBC: "+wmsx.Util.toHex2(fromBC())+"  DE: "+wmsx.Util.toHex2(DE)+"  HL: "+wmsx.Util.toHex2(HL)+"  IX: "+wmsx.Util.toHex2(IX)+"  IY: "+wmsx.Util.toHex2(IY)+"       SP: "+wmsx.Util.toHex2(SP)+"\n\nFlags: "+(F&bS?"S ":"- ")+(F&bZ?"Z ":"- ")+(F&bF5?"5 ":"- ")+(F&bH?"H ":"- ")+(F&bF3?"3 ":"- ")+(F&bPV?"P ":"- ")+(F&bN?"N ":"- ")+(F&bC?"C":"-")+"            IFF: "+IFF1+"     INT: "+wmsx.Util.toHex2(INT)+"     prefix: "+prefix},this.eval=function(str){return eval(str)}},wmsx.CPU.BASE_CLOCK=3584160,wmsx.PPI=function(a,b,c){"use strict";function d(){i=15&h}function e(){a.setPulseSignal((160&h)>0)}function f(){c.ledStateChanged(0,(64&~h)>>6)}this.connectBus=function(a){g=a,g.connectInputDevice(168,this.inputA8),g.connectOutputDevice(168,this.outputA8),g.connectInputDevice(169,this.inputA9),g.connectOutputDevice(169,wmsx.DeviceMissing.outputPortIgnored),g.connectInputDevice(170,this.inputAA),g.connectOutputDevice(170,this.outputAA),g.connectInputDevice(171,wmsx.DeviceMissing.inputPortIgnored),g.connectOutputDevice(171,this.outputAB)},this.powerOn=function(){this.reset()},this.powerOff=function(){this.reset()},this.reset=function(){h=80,i=0,e(),f()},this.inputA8=function(){return g.getPrimarySlotConfig()},this.outputA8=function(a){g.setPrimarySlotConfig(a)},this.inputA9=function(){return b.readKeyboardPort(i)},this.inputAA=function(){return h},this.outputAA=function(a){var b=h^a;b&&(h=a,15&b&&d(),160&b&&e(),64&b&&f())},this.outputAB=function(a){var b=(14&a)>>>1;0==(1&a)?h&=~(1<<b):h|=1<<b,b<=3?d():5===b||7===b?e():6===b&&f()};var g,h=80,i=0;this.saveState=function(){return{c:h}},this.loadState=function(a){h=a.c||0,d(),e(),f()}},wmsx.ColorCache=new function(){function a(a,b,c,d){switch(d=0!==d?4278190080:0,q){case 0:
return d|(255&a)<<16|(255&b)<<8|255&c;case 1:var e=Math.min(255,Math.round(.29*c+.55*b+.16*a));return d|e<<16|e<<8|e;case 2:return e=Math.min(255,Math.round(.31*c+.58*b+.18*a)),d|e/3.1<<16|e/1<<8|e/2.5;case 3:return e=Math.min(255,Math.round(.32*c+.6*b+.18*a)),d|e/9<<16|e/1.56<<8|e/1}}function b(a){return a>31?a-64:a}function c(a){return a<=0?0:a>=31?31:a}this.setColorAndPaletteMode=function(a,b){q!==a&&(q=a,d=e=f=g=h=i=j=void 0),r!==b&&(r=b,d=void 0)},this.getColors4bit9918Values=function(){if(!d){d=new Uint32Array(16);for(var b=p[r],c=0;c<16;++c){var e=b[c];d[c]=a(e>>16&255,e>>8&255,255&e)}}return d},this.getColors8bit9938Values=function(){if(!e){e=new Uint32Array(256);for(var b=0;b<256;++b)e[b]=a(k[3&b],l[b>>5],l[b>>2&7])}return e},this.getColors9bit9938Values=function(){if(!f){f=new Uint32Array(512);for(var b=0;b<512;++b)f[b]=a(l[7&b],l[b>>6],l[b>>3&7])}return f},this.getColors8bit9990Values=function(b){if(!g){g=new Uint32Array(256);for(var c=0;c<256;++c)g[c]=a(m[3&c],n[c>>5],n[c>>2&7])}return g[0]=b?0:4278190080,g},this.getColors16bitValues=function(){if(!h){h=new Uint32Array(65536);for(var b=0;b<65536;++b)h[b]=a(o[31&b],o[b>>10&31],o[b>>5&31],b<32768?1:0)}return h},this.getColorsYUVValues=function(){if(!i){i=new Uint32Array(131072);for(var d=0;d<131072;++d){var e=d>>12,f=b(d>>6&63),g=b(63&d),h=c(e+f),j=c(5*e-(f<<1)-g>>2),k=c(e+g);i[d]=a(o[k],o[j],o[h])}}return i},this.getColorsYJKValues=function(){if(!j){j=new Uint32Array(131072);for(var d=0;d<131072;++d){var e=d>>12,f=b(d>>6&63),g=b(63&d),h=c(e+f),i=c(e+g),k=c(5*e-(f<<1)-g>>2);j[d]=a(o[k],o[i],o[h])}}return j};var d=void 0,e=void 0,f=void 0,g=void 0,h=void 0,i=void 0,j=void 0,k=[0,73,146,255],l=[0,36,73,109,146,182,219,255],m=[0,90,172,255],n=[0,32,74,106,148,180,222,255],o=[0,8,16,24,32,41,49,57,65,74,82,90,98,106,115,123,131,139,148,156,164,172,180,189,197,205,213,222,230,238,246,255],p=[new Uint32Array([4278190080,4278190080,4280863239,4284867133,4293936196,4294208880,4279447760,4293978176,4282532595,4286085364,4281387728,4287225052,4280330502,4291117274,4290559164,4294967295]),new Uint32Array([4278190080,4278190080,4279102208,4283495232,4294920013,4294927993,4281026041,4294967058,4281157119,4283460095,4278569950,4282701040,4278962944,4293019364,4291611852,4294967295]),new Uint32Array([4278190080,4278190080,4283086656,4286500725,4292302425,4293883776,4283523e3,4293843814,4284114649,4286483197,4284531660,4287156446,4282556731,4290013110,4291611852,4294967295]),new Uint32Array([4278190080,4278190080,4280605476,4285398893,4294911012,4294929737,4280558774,4294957897,4280558847,4285361663,4280605659,4287814619,4280586788,4290136539,4290164406,4294967295]),new Uint32Array([4278190080,4278190080,4284927078,4287164040,4292691012,4294932343,4283782587,4292730231,4284901085,4286019583,4283813068,4287164142,4283804245,4290467259,4291611852,4294967295]),new Uint32Array([4278190080,4278190080,4278255360,4278255360,4294901760,4294901760,4278190335,4294967040,4278190335,4278190335,4278255615,4278255615,4278255360,4294902015,4294967295,4294967295])],q=0,r=2},wmsx.VDP=function(machine,cpu,vSyncConnection){"use strict";function init(){videoSignal=new wmsx.VideoSignal(self,"Internal"),audioClockPulse32=machine.getAudioSocket().audioClockPulse32,initColorCaches(),initFrameResources(!1),initDebugPatternTables(),initSpritesConflictMap(),modeData=modes[0],backdropCacheUpdatePending=!0,self.setDefaults(),commandProcessor=new wmsx.VDPCommandProcessor,commandProcessor.connectVDP(self,vram,register,status),commandProcessor.setVDPModeData(modeData),renderWidth=wmsx.VDP.SIGNAL_START_WIDTH_V9938,renderHeight=1===WMSX.MACHINES_CONFIG[WMSX.MACHINE].TYPE?wmsx.VDP.SIGNAL_HEIGHT_V9918:wmsx.VDP.SIGNAL_START_HEIGHT_V9938}function registerWrite(a,b){if(!(a>46)){var c,d=register[a]^b;switch(register[a]=b,a){case 0:16&d&&updateIRQ(),14&d&&updateMode();break;case 1:32&d&&updateIRQ(),64&d&&(blankingChangePending=!0),24&d&&updateMode(),4&d&&updateBlinking(),3&d&&updateSpritesConfig();break;case 2:127&d&&updateLayoutTableAddress();break;case 10:if(0==(7&d))break;case 3:c=131071&(register[10]<<14|register[3]<<6),colorTableAddress=c&modeData.colorTBase,colorTableAddressMask=c|colorTableAddressMaskBase;break;case 4:if(0==(63&d))break;c=b<<11&131071,patternTableAddress=c&modeData.patTBase,patternTableAddressMask=c|patternTableAddressMaskBase;break;case 11:if(0==(3&d))break;case 5:c=131071&(register[11]<<15|register[5]<<7),spriteAttrTableAddress=c&modeData.sprAttrTBase;break;case 6:63&d&&updateSpritePatternTableAddress();break;case 7:d&(modeData.bdPaletted?15:255)&&updateBackdropColor();break;case 8:32&d&&updateTransparency(),2&d&&updateSpritesConfig();break;case 9:128&d&&updateSignalMetrics(!1),8&d&&updateRenderMetrics(!1),4&d&&updateLayoutTableAddressMask(),2&d&&updateVideoStandardSoft();break;case 13:updateBlinking();break;case 14:7&d&&(vramPointer=(7&b)<<14|16383&vramPointer);break;case 16:paletteFirstWrite=null;break;case 18:15&d&&(horizontalAdjust=(15&b^7)-7),240&d&&(verticalAdjust=(b>>>4^7)-7,updateSignalMetrics(!1));break;case 19:horizontalIntLine=b-register[23]&255;break;case 23:horizontalIntLine=register[19]-b&255;break;case 25:isV9958&&(24&d&&updateMode(),leftMask=0!=(2&b),leftScroll2Pages=0!=(1&b));break;case 26:isV9958&&(leftScrollChars=63&b,leftScrollCharsInPage=31&leftScrollChars);break;case 27:isV9958&&(rightScrollPixels=7&b);break;case 44:commandProcessor.cpuWrite(b);break;case 46:commandProcessor.startCommand(b)}}}function updateLayoutTableAddress(){var a=modeData.vramInter?(63&register[2])<<11|1024:(127&register[2])<<10;layoutTableAddress=a&modeData.layTBase,layoutTableAddressMaskSetValue=a|layoutTableAddressMaskBase,updateLayoutTableAddressMask()}function updateLayoutTableAddressMask(){layoutTableAddressMask=layoutTableAddressMaskSetValue&(blinkEvenPage||4&register[9]&&!EO?modeData.blinkPageMask:-1)}function updateSpritePatternTableAddress(){spritePatternTableAddress=debugModeSpriteInfo?16===spritesSize?DEBUG_PAT_DIGI16_TABLE_ADDRESS:DEBUG_PAT_DIGI8_TABLE_ADDRESS:register[6]<<11&131071}function getStatus0(){var a=0;return F&&(a|=128,F=0,updateIRQ()),spritesCollided&&(a|=32,spritesCollided=!1),spritesInvalid>=0?(a|=64|spritesInvalid,spritesInvalid=-1):a|=spritesMaxComputed,spritesMaxComputed=0,a}function checkVRAMPointerWrap(){0==(16383&vramPointer)&&(modeData.isV9938&&(register[14]=register[14]+1&7),vramPointer=register[14]<<14)}function paletteRegisterWrite(a,b,c){if(paletteRegister[a]!==b||c){paletteRegister[a]=b;var d=getColorValueForPaletteValue(b);colorPaletteReal[a]=d,debugModeSpriteHighlight&&(d&=DEBUG_DIM_ALPHA_MASK),colorPaletteSolid[a]=d,0===a?color0Solid&&(colorPalette[0]=d):colorPalette[a]=d,a===backdropColor?updateBackdropValue():modeData.tiled&&a<=3&&(backdropCacheUpdatePending=!0)}}function getColorValueForPaletteValue(a){return colors9bitValues[(1792&a)>>>2|(112&a)>>>1|7&a]}function setDebugMode(a){debugMode=(a+8)%8;var b=debugModeSpriteHighlight;debugModeSpriteHighlight=debugMode>=1&&debugMode<=3,debugModeSpriteInfo=2===debugMode||3===debugMode,debugModeSpriteInfoNumbers=2===debugMode,debugModeSpritesHidden=debugMode>=4;var c=debugModePatternInfo;debugModePatternInfo=debugMode>=5,debugModePatternInfoBlocks=6===debugMode,debugModePatternInfoNames=7===debugMode,b===debugModeSpriteHighlight&&c===debugModePatternInfo||updateAllPaletteValues(),initFrameResources(debugModeSpriteHighlight),updateLineActiveType(),updateSpritesConfig(),updateSpritePatternTableAddress(),slave&&slave.setDebugMode(debugMode),videoSignal.setDebugMode(debugMode>0)}function setSpriteDebugMode(a){spriteDebugMode=a>=0?a%4:4+a,spriteDebugModeLimit=0===spriteDebugMode||2===spriteDebugMode,spriteDebugModeCollisions=spriteDebugMode<2,slave&&slave.setSpriteDebugMode(spriteDebugMode)}function updateAllPaletteValues(){if(isV9918)initColorPalette();else for(var a=0;a<16;a++)paletteRegisterWrite(a,paletteRegister[a],!0)}
function updateSynchronization(){pulldown=1===vSynchMode?videoStandard.pulldowns[machine.getVideoClockSocket().getVSynchNativeFrequency()]||videoStandard.pulldowns.TIMER:videoStandard.pulldowns.TIMER}function cycleEvents(){var a=framePulldown.linesPerCycle;pulldown.steps>1&&frame%pulldown.steps==0&&(a+=pulldown.firstStepCycleLinesAdjust);for(var b=a;b>0;--b)lineEvents()}function lineEvents(){blinkPerLine&&blinkPageDuration>0&&clockPageBlinking()&&updateLayoutTableAddressMask(),currentScanline===startingActiveScanline?setActiveDisplay():currentScanline-frameStartingActiveScanline===signalActiveHeight&&setBorderDisplay(),cpuMemoryRefresh(),cpuBusClockPulses(33),audioClockPulse32(),blankingChangePending&&updateLineActiveType(),FH&&0==(16&register[0])&&(FH=0),currentScanline===startingActiveScanline-1?VR=0:currentScanline-frameStartingActiveScanline===signalActiveHeight&&triggerVerticalInterrupt(),cpuBusClockPulses(10),HR=0,slave&&slave.lineEventStartActiveDisplay(),cpuBusClockPulses(22),audioClockPulse32(),cpuBusClockPulses(33),audioClockPulse32(),cpuBusClockPulses(32),audioClockPulse32(),currentScanline>=startingVisibleTopBorderScanline&&currentScanline<startingInvisibleScanline&&renderLine(),slave&&slave.lineEventRenderLine(),cpuMemoryRefresh(),cpuBusClockPulses(33),audioClockPulse32(),cpuBusClockPulses(32),audioClockPulse32(),cpuBusClockPulses(18),HR=1,currentScanline-frameStartingActiveScanline===horizontalIntLine&&triggerHorizontalInterrupt(),slave&&slave.lineEventEndActiveDisplay(),cpuBusClockPulses(15),audioClockPulse32(),0==(7&currentScanline)&&audioClockPulse32(),++currentScanline,currentScanline>=finishingScanline&&finishFrame(),slave&&slave.lineEventEnd()}function triggerVerticalInterrupt(){VR=1,F||(F=1,updateIRQ())}function triggerHorizontalInterrupt(){FH||(FH=1,updateIRQ())}function updateIRQ(){F&&32&register[1]||FH&&16&register[0]?cpu.setINTChannel(0,0):cpu.setINTChannel(0,1)}function updateVRAMInterleaving(){!0!==modeData.vramInter||vramInterleaving?!1===modeData.vramInter&&vramInterleaving&&vramExitInterleaving():vramEnterInterleaving()}function vramEnterInterleaving(){for(var a=0,b=VRAM_SIZE>>1,c=vram.slice(0,b),d=0;d<VRAM_SIZE;d+=2,++a,++b)vram[d]=c[a],vram[d+1]=vram[b];vramInterleaving=!0}function vramExitInterleaving(){for(var a=VRAM_SIZE>>1,b=0,c=a,d=vram.slice(a),e=0;e<a;e+=2,++b,++c)vram[b]=vram[e],vram[c]=vram[e+1];for(e=0;e<a;e+=2,++b,++c)vram[b]=d[e],vram[c]=d[e+1];vramInterleaving=!1}function setMode(a){registerWrite(0,-15&register[0]|(7&a)<<1),registerWrite(1,-25&register[1]|24&a)}function updateMode(a){var b=modeData,c=24&register[1]|(register[0]&(isV9918?2:14))>>>1;commandProcessor.setVDPModeData(modes[c]),isV9958&&0!=(8&register[25])&&0==(16&c)&&(c=32|(24&register[25])>>3),modeData=modes[c];var d;updateLayoutTableAddress(),d=131071&(register[10]<<14|register[3]<<6),colorTableAddress=d&modeData.colorTBase,colorTableAddressMask=d|colorTableAddressMaskBase,d=register[4]<<11&131071,patternTableAddress=d&modeData.patTBase,patternTableAddressMask=d|patternTableAddressMaskBase,d=131071&(register[11]<<15|register[5]<<7),spriteAttrTableAddress=d&modeData.sprAttrTBase,updateSpritePatternTableAddress(),modeData.bdPaletted!==b.bdPaletted&&updateBackdropColor(),modeData.tiled!==b.tiled&&(backdropCacheUpdatePending=!0),updateVRAMInterleaving(),updateLineActiveType(),updateRenderMetrics(a)}function updateVideoStandardSoft(){var a=2&register[9];machine.setVideoStandardSoft(a?wmsx.VideoStandard.PAL:wmsx.VideoStandard.NTSC)}function updateSignalMetrics(a){var b;isV9918&&!slave?(signalActiveHeight=192,b=0):!isV9918&&128&register[9]?(signalActiveHeight=212,b=0):(signalActiveHeight=192,b=10),startingVisibleTopBorderScanline=8,startingActiveScanline=startingVisibleTopBorderScanline+8+b+verticalAdjust,startingInvisibleScanline=startingActiveScanline+signalActiveHeight+8+b-verticalAdjust,finishingScanline=frameVideoStandard.totalHeight,a&&(frameStartingActiveScanline=startingActiveScanline)}function updateRenderMetrics(a){var b,c,d=!1,e=!1;isV9918&&!slave?(b=wmsx.VDP.SIGNAL_WIDTH_V9918,c=wmsx.VDP.SIGNAL_HEIGHT_V9918):(b=512===modeData.width?544:272,c=!isV9918&&8&register[9]?456:228),renderMetricsChangePending=!1,b===renderWidth&&c===renderHeight||(b!==renderWidth&&(currentScanline<startingVisibleTopBorderScanline||b>renderWidth?(currentScanline>=startingVisibleTopBorderScanline&&(a?e=!0:stretchFromCurrentToTopScanline()),renderWidth=b,d=!0):renderMetricsChangePending=!0),c!==renderHeight&&(a?((currentScanline>=startingVisibleTopBorderScanline||c>renderHeight)&&(e=!0),renderHeight=c,d=!0):renderMetricsChangePending=!0),e&&cleanFrameBuffer(),d&&self.refreshDisplayMetrics())}function setActiveDisplay(){renderLine=renderLineActive}function setBorderDisplay(){renderLine=renderLineBorders}function updateLineActiveType(){var a=renderLine===renderLineActive;renderLineActive=0==(64&register[1])?renderLineBlanked:debugModePatternInfo?modeData.renderLinePatInfo:modeData.renderLine,a&&(renderLine=renderLineActive),blankingChangePending=!1}function updateSpritesConfig(){spritesEnabled=!debugModeSpritesHidden&&0==(2&register[8]),spritesSize=2&register[1]?16:8,spritesMag=1&register[1]}function updateTransparency(){color0Solid=0!=(32&register[8]),colorPalette[0]=color0Solid?colorPaletteSolid[0]:backdropValue}function updateBackdropColor(){backdropColor=register[7]&(modeData.bdPaletted?15:255),updateBackdropValue()}function updateBackdropValue(){var a=debugModePatternInfo?debugBackdropValue:modeData.bdPaletted?colorPaletteSolid[backdropColor]:colors8bitValues[backdropColor];backdropValue!==a&&(backdropValue=a,color0Solid||(colorPalette[0]=a),backdropCacheUpdatePending=!0)}function updateBackdropLineCache(){if(modeData.tiled&&!debugModePatternInfo){for(var a=colorPaletteSolid[backdropColor>>>2],b=colorPaletteSolid[3&backdropColor],c=0;c<LINE_WIDTH;c+=2)backdropLineCache[c]=a,backdropLineCache[c+1]=b;backdropTileOdd=a,backdropTileEven=b}else wmsx.Util.arrayFill(backdropLineCache,backdropValue),modeData.tiled&&(backdropTileOdd=backdropTileEven=backdropValue);backdropCacheUpdatePending=!1}function updateBlinking(){blinkPerLine=0!=(4&register[1]),register[13]>>>4==0?(blinkEvenPage=!1,blinkPageDuration=0):0==(15&register[13])?(blinkEvenPage=!0,blinkPageDuration=0):(blinkEvenPage=!0,blinkPageDuration=1),updateLayoutTableAddressMask()}function clockPageBlinking(){return 0==--blinkPageDuration&&(blinkEvenPage=!blinkEvenPage,blinkPageDuration=10*(register[13]>>>(blinkEvenPage?4:0)&15),!0)}function renderLineBorders(){videoDisplayed&&(backdropCacheUpdatePending&&updateBackdropLineCache(),frameBackBuffer.set(backdropLineCache,bufferPosition),bufferPosition+=bufferLineAdvance)}function renderLineBlanked(){renderLineBorders()}function getRealLine(){return currentScanline-frameStartingActiveScanline+register[23]&255}function renderLineModeT1(){if(videoDisplayed){paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var a=bufferPosition+8+horizontalAdjust+rightScrollPixels,b=getRealLine(),c=register[7],d=patternTableAddress+(7&b),e=colorPalette[c>>>4],f=colorPalette[15&c],g=layoutTableAddress+40*(b>>>3);paintBackdrop8(a),a+=8;for(var h=0;h<40;++h){var i=vram[g];++g;paintPattern6(a,vram[(i<<3)+d],e,f),a+=6}paintBackdrop8(a),a+=8,a-=rightScrollPixels+256,leftMask&&paintBackdrop8(a),rightScrollPixels&&paintBackdrop8(a+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}}function renderLineModeT2(){if(videoDisplayed){paintBackdrop32(bufferPosition),paintBackdrop32(bufferPosition+512);var a,b,c,d,e,f=bufferPosition+16+(horizontalAdjust+rightScrollPixels<<1),g=getRealLine(),h=patternTableAddress+(7&g),i=layoutTableAddress+80*(g>>>3);if(paintBackdrop16(f),f+=16,blinkEvenPage)for(var j=colorTableAddress+10*(g>>>3),k=7,l=0;l<80;++l){var m=vram[j&colorTableAddressMask]>>>k&1;a=vram[i&layoutTableAddressMask],++i,c=register[m?12:7],b=vram[(a<<3)+h],
d=m?colorPaletteSolid[c>>>4]:colorPalette[c>>>4],e=m?colorPaletteSolid[15&c]:colorPalette[15&c],paintPattern6(f,b,d,e),--k<0&&(++j,k=7),f+=6}else for(c=register[7],d=colorPalette[c>>>4],e=colorPalette[15&c],l=0;l<80;++l)a=vram[i&layoutTableAddressMask],++i,b=vram[(a<<3)+h],paintPattern6(f,b,d,e),f+=6;paintBackdrop16(f),f+=16,f-=512+(rightScrollPixels<<1),leftMask&&paintBackdrop16(f),rightScrollPixels&&paintBackdrop16(f+512),bufferPosition+=bufferLineAdvance}}function renderLineModeMC(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=patternTableAddress+((a>>>3&3)<<1)+(a>>>2&1),d=layoutTableAddress+(a>>>3<<5),e=d+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(e&=modeData.evenPageMask);for(var f=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,g=0;g<32;++g){g===f&&(e=leftScroll2Pages&&leftScrollChars>=32?d&modeData.evenPageMask:d);var h=vram[e];++e;var i=(h<<3)+c,j=vram[i];paintPattern8(b,240,colorPalette[j>>>4],colorPalette[15&j]),b+=8}b-=rightScrollPixels+256,renderSpritesLineMode1(a,b),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG1(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=patternTableAddress+(7&a),d=layoutTableAddress+(a>>>3<<5),e=d+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(e&=modeData.evenPageMask);for(var f=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,g=0;g<32;++g){g===f&&(e=leftScroll2Pages&&leftScrollChars>=32?d&modeData.evenPageMask:d);var h=vram[e];++e;var i=vram[colorTableAddress+(h>>>3)];paintPattern8(b,vram[(h<<3)+c],colorPalette[i>>>4],colorPalette[15&i]),b+=8}b-=rightScrollPixels+256,renderSpritesLineMode1(a,b),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG2(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=colorTableAddress+(7&a),d=patternTableAddress+(7&a),e=(192&a)<<2,f=layoutTableAddress+(a>>>3<<5),g=f+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(g&=modeData.evenPageMask);for(var h=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,i=0;i<32;++i){i===h&&(g=leftScroll2Pages&&leftScrollChars>=32?f&modeData.evenPageMask:f);var j=vram[g]|e;++g;var k=vram[(j<<3)+c&colorTableAddressMask];paintPattern8(b,vram[(j<<3)+d&patternTableAddressMask],colorPalette[k>>>4],colorPalette[15&k]),b+=8}b-=rightScrollPixels+256,renderSpritesLineMode1(a,b),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG3(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,colorPaletteReal);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=colorTableAddress+(7&a),d=patternTableAddress+(7&a),e=(192&a)<<2,f=layoutTableAddress+(a>>>3<<5),g=f+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(g&=modeData.evenPageMask);for(var h=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,i=0;i<32;++i){i===h&&(g=leftScroll2Pages&&leftScrollChars>=32?f&modeData.evenPageMask:f);var j=vram[g]|e;++g;var k=vram[(j<<3)+c&colorTableAddressMask];paintPattern8(b,vram[(j<<3)+d&patternTableAddressMask],colorPalette[k>>>4],colorPalette[15&k]),b+=8}b-=rightScrollPixels+256,renderSpritesLineMode2(a,b,colorPaletteReal),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG4(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,colorPaletteReal);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=layoutTableAddress+(a<<7),d=c+(leftScrollCharsInPage<<2);leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);for(var e=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,f=0;f<32;++f){f===e&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c);var g=vram[d&layoutTableAddressMask];++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b}b-=rightScrollPixels+256,renderSpritesLineMode2(a,b,colorPaletteReal),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG5(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2Tiled(a,0);paintBackdrop32Tiled(bufferPosition),paintBackdrop32Tiled(bufferPosition+512);var b=bufferPosition+16+(horizontalAdjust+rightScrollPixels<<1),c=layoutTableAddress+(a<<7),d=c+(leftScrollCharsInPage<<2);leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);var e=leftScrollCharsInPage?32-leftScrollCharsInPage:-1;if(color0Solid)for(var f=0;f<32;++f){f===e&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c);var g=vram[d&layoutTableAddressMask];++d,frameBackBuffer[b]=colorPaletteSolid[g>>>6],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>4&3],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>2&3],++b,frameBackBuffer[b]=colorPaletteSolid[3&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPaletteSolid[g>>>6],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>4&3],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>2&3],++b,frameBackBuffer[b]=colorPaletteSolid[3&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPaletteSolid[g>>>6],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>4&3],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>2&3],++b,frameBackBuffer[b]=colorPaletteSolid[3&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPaletteSolid[g>>>6],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>4&3],++b,frameBackBuffer[b]=colorPaletteSolid[g>>>2&3],++b,frameBackBuffer[b]=colorPaletteSolid[3&g],++b}else for(f=0;f<32;++f)f===e&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c),g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=192&g?colorPaletteSolid[g>>>6]:backdropTileOdd,++b,frameBackBuffer[b]=48&g?colorPaletteSolid[g>>>4&3]:backdropTileEven,++b,frameBackBuffer[b]=12&g?colorPaletteSolid[g>>>2&3]:backdropTileOdd,++b,frameBackBuffer[b]=3&g?colorPaletteSolid[3&g]:backdropTileEven,++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=192&g?colorPaletteSolid[g>>>6]:backdropTileOdd,++b,frameBackBuffer[b]=48&g?colorPaletteSolid[g>>>4&3]:backdropTileEven,++b,frameBackBuffer[b]=12&g?colorPaletteSolid[g>>>2&3]:backdropTileOdd,++b,frameBackBuffer[b]=3&g?colorPaletteSolid[3&g]:backdropTileEven,++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=192&g?colorPaletteSolid[g>>>6]:backdropTileOdd,++b,frameBackBuffer[b]=48&g?colorPaletteSolid[g>>>4&3]:backdropTileEven,++b,frameBackBuffer[b]=12&g?colorPaletteSolid[g>>>2&3]:backdropTileOdd,++b,frameBackBuffer[b]=3&g?colorPaletteSolid[3&g]:backdropTileEven,++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=192&g?colorPaletteSolid[g>>>6]:backdropTileOdd,++b,
frameBackBuffer[b]=48&g?colorPaletteSolid[g>>>4&3]:backdropTileEven,++b,frameBackBuffer[b]=12&g?colorPaletteSolid[g>>>2&3]:backdropTileOdd,++b,frameBackBuffer[b]=3&g?colorPaletteSolid[3&g]:backdropTileEven,++b;b-=512+(rightScrollPixels<<1),renderSpritesLineMode2Tiled(a,b),leftMask&&paintBackdrop16Tiled(b),rightScrollPixels&&paintBackdrop16Tiled(b+512),bufferPosition+=bufferLineAdvance}function renderLineModeG6(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2Stretched(a,0);paintBackdrop32(bufferPosition),paintBackdrop32(bufferPosition+512);var b=bufferPosition+16+(horizontalAdjust+rightScrollPixels<<1),c=layoutTableAddress+(a<<8),d=c+(leftScrollCharsInPage<<3);leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);for(var e=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,f=0;f<32;++f){f===e&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c);var g=vram[d&layoutTableAddressMask];++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b,g=vram[d&layoutTableAddressMask],++d,frameBackBuffer[b]=colorPalette[g>>>4],++b,frameBackBuffer[b]=colorPalette[15&g],++b}b-=512+(rightScrollPixels<<1),renderSpritesLineMode2Stretched(a,b),leftMask&&paintBackdrop16(b),rightScrollPixels&&paintBackdrop16(b+512),bufferPosition+=bufferLineAdvance}function renderLineModeG7(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,spritePaletteG7);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=debugModeSpriteHighlight?DEBUG_DIM_ALPHA_MASK:4294967295,d=layoutTableAddress+(a<<8),e=d+(leftScrollCharsInPage<<3);leftScroll2Pages&&leftScrollChars<32&&(e&=modeData.evenPageMask);for(var f=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,g=0;g<32;++g)g===f&&(e=leftScroll2Pages&&leftScrollChars>=32?d&modeData.evenPageMask:d),frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b,frameBackBuffer[b]=colors8bitValues[vram[e&layoutTableAddressMask]]&c,++e,++b;b-=rightScrollPixels+256,renderSpritesLineMode2(a,b,spritePaletteG7),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeYJK(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,colorPaletteReal);paintBackdrop20(bufferPosition),paintBackdrop16(bufferPosition+256+4),colorsYJKValues||(colorsYJKValues=wmsx.ColorCache.getColorsYJKValues());var b=bufferPosition+8+horizontalAdjust+rightScrollPixels+4,c=layoutTableAddress+(a<<8),d=c+(leftScrollCharsInPage<<3);leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);for(var e,f,g,h,i,j=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,k=0;k<32;++k)k===j&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c),e=vram[d&layoutTableAddressMask],++d,f=vram[d&layoutTableAddressMask],++d,g=vram[d&layoutTableAddressMask],++d,h=vram[d&layoutTableAddressMask],++d,i=(7&h)<<9|(7&g)<<6|(7&f)<<3|7&e,frameBackBuffer[b]=colorsYJKValues[(248&e)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&f)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&g)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&h)<<9|i],++b,e=vram[d&layoutTableAddressMask],++d,f=vram[d&layoutTableAddressMask],++d,g=vram[d&layoutTableAddressMask],++d,h=vram[d&layoutTableAddressMask],++d,i=(7&h)<<9|(7&g)<<6|(7&f)<<3|7&e,frameBackBuffer[b]=colorsYJKValues[(248&e)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&f)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&g)<<9|i],++b,frameBackBuffer[b]=colorsYJKValues[(248&h)<<9|i],++b;b-=rightScrollPixels+256,renderSpritesLineMode2(a,b,colorPaletteReal),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeYAE(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,colorPaletteReal);paintBackdrop20(bufferPosition),paintBackdrop16(bufferPosition+256+4),colorsYJKValues||(colorsYJKValues=wmsx.ColorCache.getColorsYJKValues());var b=bufferPosition+8+horizontalAdjust+rightScrollPixels+4,c=layoutTableAddress+(a<<8),d=c+(leftScrollCharsInPage<<3);leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);for(var e,f,g,h,i,j=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,k=0;k<32;++k)k===j&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c),e=vram[d&layoutTableAddressMask],++d,f=vram[d&layoutTableAddressMask],++d,g=vram[d&layoutTableAddressMask],++d,h=vram[d&layoutTableAddressMask],++d,i=(7&h)<<9|(7&g)<<6|(7&f)<<3|7&e,frameBackBuffer[b]=8&e?colorPalette[e>>4]:colorsYJKValues[(248&e)<<9|i],++b,frameBackBuffer[b]=8&f?colorPalette[f>>4]:colorsYJKValues[(248&f)<<9|i],++b,frameBackBuffer[b]=8&g?colorPalette[g>>4]:colorsYJKValues[(248&g)<<9|i],++b,frameBackBuffer[b]=8&h?colorPalette[h>>4]:colorsYJKValues[(248&h)<<9|i],++b,e=vram[d&layoutTableAddressMask],++d,f=vram[d&layoutTableAddressMask],++d,g=vram[d&layoutTableAddressMask],++d,h=vram[d&layoutTableAddressMask],++d,i=(7&h)<<9|(7&g)<<6|(7&f)<<3|7&e,frameBackBuffer[b]=8&e?colorPalette[e>>4]:colorsYJKValues[(248&e)<<9|i],++b,frameBackBuffer[b]=8&f?colorPalette[f>>4]:colorsYJKValues[(248&f)<<9|i],++b,frameBackBuffer[b]=8&g?colorPalette[g>>4]:colorsYJKValues[(248&g)<<9|i],++b,frameBackBuffer[b]=8&h?colorPalette[h>>4]:colorsYJKValues[(248&h)<<9|i],++b;b-=rightScrollPixels+256,renderSpritesLineMode2(a,b,colorPaletteReal),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeT1PatInfo(){if(videoDisplayed){paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var a=bufferPosition+8+horizontalAdjust+rightScrollPixels,b=getRealLine(),c=7&b,d=layoutTableAddress+40*(b>>>3);paintBackdrop8(a),a+=8;for(var e=0;e<40;++e){var f=vram[d];if(++d,debugModePatternInfoNames){var g=0===f||32===f?4293787648:4294967295,h=vram[DEBUG_PAT_DIGI6_TABLE_ADDRESS+(f<<3)+c];paintPattern6TInfo(a,h,g,4278190080)}else h=vram[patternTableAddress+(f<<3)+c],paintPattern6(a,h,4294967295,4278190080);a+=6}paintBackdrop8(a),a+=8,a-=rightScrollPixels+256,leftMask&&paintBackdrop8(a),rightScrollPixels&&paintBackdrop8(a+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}}function renderLineModeT2PatInfo(){if(videoDisplayed){paintBackdrop32(bufferPosition),paintBackdrop32(bufferPosition+512);var a,b,c,d=bufferPosition+16+(horizontalAdjust+rightScrollPixels<<1),e=getRealLine(),f=7&e,g=layoutTableAddress+80*(e>>>3);if(paintBackdrop16(d),d+=16,
blinkEvenPage)for(var h=colorTableAddress+10*(e>>>3),i=7,j=0;j<80;++j){var k=vram[h&colorTableAddressMask]>>>i&1;a=vram[g&layoutTableAddressMask],++g,debugModePatternInfoNames?(c=0===a||32===a?4293787648:4294967295,k&&(c&=4288716960),b=vram[DEBUG_PAT_DIGI6_TABLE_ADDRESS+(a<<3)+f],paintPattern6TInfo(d,b,c,4278190080)):(b=vram[patternTableAddress+(a<<3)+f],paintPattern6(d,b,k?4288716960:4294967295,4278190080)),--i<0&&(++h,i=7),d+=6}else for(j=0;j<80;++j)a=vram[g&layoutTableAddressMask],++g,debugModePatternInfoNames?(c=0===a||32===a?4293787648:4294967295,b=vram[DEBUG_PAT_DIGI6_TABLE_ADDRESS+(a<<3)+f],paintPattern6TInfo(d,b,c,4278190080)):(b=vram[patternTableAddress+(a<<3)+f],paintPattern6(d,b,4294967295,4278190080)),d+=6;paintBackdrop16(d),d+=16,d-=512+(rightScrollPixels<<1),leftMask&&paintBackdrop16(d),rightScrollPixels&&paintBackdrop16(d+512),bufferPosition+=bufferLineAdvance}}function paintPattern6TInfo(a,b,c,d){var e=2550136831&c;frameBackBuffer[a]=128&b?c:d,frameBackBuffer[a+1]=64&b?c:d,frameBackBuffer[a+2]=32&b?c:d,frameBackBuffer[a+3]=16&b?e:d,frameBackBuffer[a+4]=8&b?e:d,frameBackBuffer[a+5]=4&b?e:d}function renderLineModeMCPatInfo(){if(!debugModePatternInfoNames)return renderLineModeMC();var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b=bufferPosition+8+horizontalAdjust+rightScrollPixels,c=layoutTableAddress+(a>>>3<<5),d=c+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(d&=modeData.evenPageMask);for(var e=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,f=0;f<32;++f){f===e&&(d=leftScroll2Pages&&leftScrollChars>=32?c&modeData.evenPageMask:c);var g=vram[d];++d;paintPattern8(b,vram[DEBUG_PAT_DIGI8_TABLE_ADDRESS+(g<<3)+(7&a)],4294967295,4278190080),b+=8}b-=rightScrollPixels+256,renderSpritesLineMode1(a,b),leftMask&&paintBackdrop8(b),rightScrollPixels&&paintBackdrop8(b+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG1PatInfo(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b,c,d,e=bufferPosition+8+horizontalAdjust+rightScrollPixels,f=7&a,g=layoutTableAddress+(a>>>3<<5),h=g+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(h&=modeData.evenPageMask);for(var i=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,j=0;j<32;++j){j===i&&(h=leftScroll2Pages&&leftScrollChars>=32?g&modeData.evenPageMask:g);var k=vram[h];if(++h,debugModePatternInfoNames)c=0===k||32===k?4293787648:4294967295,d=4278190080,b=vram[DEBUG_PAT_DIGI8_TABLE_ADDRESS+(k<<3)+f];else if(debugModePatternInfoBlocks){var l=vram[colorTableAddress+(k>>>3)];c=colorPalette[l>>>4],d=colorPalette[15&l],b=vram[DEBUG_PAT_BLOCK_TABLE_ADDRESS+f]}else c=4294967295,d=4278190080,b=vram[patternTableAddress+(k<<3)+f];paintPattern8(e,b,c,d),e+=8}e-=rightScrollPixels+256,renderSpritesLineMode1(a,e),leftMask&&paintBackdrop8(e),rightScrollPixels&&paintBackdrop8(e+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG2PatInfo(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode1(a,0);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b,c,d,e=bufferPosition+8+horizontalAdjust+rightScrollPixels,f=7&a,g=(192&a)<<2,h=layoutTableAddress+(a>>>3<<5),i=h+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(i&=modeData.evenPageMask);for(var j=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,k=0;k<32;++k){k===j&&(i=leftScroll2Pages&&leftScrollChars>=32?h&modeData.evenPageMask:h);var l=vram[i]|g;if(++i,debugModePatternInfoNames)l&=255,c=0===l||32===l?4293787648:4294967295,d=4278190080,b=vram[DEBUG_PAT_DIGI8_TABLE_ADDRESS+(l<<3)+f];else if(debugModePatternInfoBlocks){var m=vram[colorTableAddress+(l<<3)+f&colorTableAddressMask];c=colorPalette[m>>>4],d=colorPalette[15&m],b=vram[DEBUG_PAT_BLOCK_TABLE_ADDRESS+f]}else c=4294967295,d=4278190080,b=vram[patternTableAddress+(l<<3)+f&patternTableAddressMask];paintPattern8(e,b,c,d),e+=8}e-=rightScrollPixels+256,renderSpritesLineMode1(a,e),leftMask&&paintBackdrop8(e),rightScrollPixels&&paintBackdrop8(e+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function renderLineModeG3PatInfo(){var a=getRealLine();if(!videoDisplayed)return renderSpritesLineMode2(a,0,colorPaletteReal);paintBackdrop16(bufferPosition),paintBackdrop16(bufferPosition+256);var b,c,d,e=bufferPosition+8+horizontalAdjust+rightScrollPixels,f=7&a,g=(192&a)<<2,h=layoutTableAddress+(a>>>3<<5),i=h+leftScrollCharsInPage;leftScroll2Pages&&leftScrollChars<32&&(i&=modeData.evenPageMask);for(var j=leftScrollCharsInPage?32-leftScrollCharsInPage:-1,k=0;k<32;++k){k===j&&(i=leftScroll2Pages&&leftScrollChars>=32?h&modeData.evenPageMask:h);var l=vram[i]|g;if(++i,debugModePatternInfoNames)l&=255,c=0===l||32===l?4293787648:4294967295,d=4278190080,b=vram[DEBUG_PAT_DIGI8_TABLE_ADDRESS+(l<<3)+f];else if(debugModePatternInfoBlocks){var m=vram[colorTableAddress+(l<<3)+f&colorTableAddressMask];c=colorPalette[m>>>4],d=colorPalette[15&m],b=vram[DEBUG_PAT_BLOCK_TABLE_ADDRESS+f]}else c=4294967295,d=4278190080,b=vram[patternTableAddress+(l<<3)+f&patternTableAddressMask];paintPattern8(e,b,c,d),e+=8}e-=rightScrollPixels+256,renderSpritesLineMode2(a,e,colorPaletteReal),leftMask&&paintBackdrop8(e),rightScrollPixels&&paintBackdrop8(e+256),renderWidth>500&&stretchCurrentLine(),bufferPosition+=bufferLineAdvance}function paintPattern6(a,b,c,d){frameBackBuffer[a]=128&b?c:d,frameBackBuffer[++a]=64&b?c:d,frameBackBuffer[++a]=32&b?c:d,frameBackBuffer[++a]=16&b?c:d,frameBackBuffer[++a]=8&b?c:d,frameBackBuffer[++a]=4&b?c:d}function paintPattern6a(a,b,c,d){for(var e=6;e>0;--e,++a)frameBackBuffer[a]=b>>e&4?c:d}function paintPattern8(a,b,c,d){frameBackBuffer[a]=128&b?c:d,frameBackBuffer[++a]=64&b?c:d,frameBackBuffer[++a]=32&b?c:d,frameBackBuffer[++a]=16&b?c:d,frameBackBuffer[++a]=8&b?c:d,frameBackBuffer[++a]=4&b?c:d,frameBackBuffer[++a]=2&b?c:d,frameBackBuffer[++a]=1&b?c:d}function paintBackdrop8(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop16(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop20(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop32(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,
frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop16Tiled(a){var b=backdropTileOdd,c=backdropTileEven;frameBackBuffer[a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c}function paintBackdrop32Tiled(a){var b=backdropTileOdd,c=backdropTileEven;frameBackBuffer[a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c,frameBackBuffer[++a]=b,frameBackBuffer[++a]=c}function renderSpritesLineMode1(a,b){if(!debugModeSpritesHidden&&208!==vram[spriteAttrTableAddress]){var c,d,e,f,g,h,i,j,k,l,m=spritesSize<<spritesMag,n=-1,o=0;spritesGlobalPriority-=32,c=spriteAttrTableAddress-4;for(var p=0;p<32&&(c+=4,n+=1,208!==(h=vram[c]));++p)if(!((i=a-h-1&255)>=m)){if(++o>4&&(spritesInvalid<0&&!F&&(spritesInvalid=n),spriteDebugModeLimit))return;d=vram[c+3],(isV9918||0!=(15&d)||color0Solid)&&(j=vram[c+1],128&d&&(j-=32)<=-m||(d&=15,16===spritesSize?(e=debugModeSpriteInfoNumbers?n<<2:252&vram[c+2],f=spritePatternTableAddress+(e<<3)+(i>>>spritesMag),g=vram[f]<<8|vram[f+16]):(e=debugModeSpriteInfoNumbers?n:vram[c+2],g=vram[spritePatternTableAddress+(e<<3)+(i>>>spritesMag)]),k=j<=256-m?0:j-(256-m),l=j>=0?m:m+j,j+=m-l,paintSpriteMode1(j,a,b+j,spritesGlobalPriority+n,g,d,k,l,spritesMag,spriteDebugModeCollisions&&o<5)))}spritesInvalid<0&&n>spritesMaxComputed&&(spritesMaxComputed=n)}}function paintSpriteMode1(a,b,c,d,e,f,g,h,i,j){for(var k=h-1;k>=g;--k,++a,++c){0!==(e>>>(k>>>i)&1)&&(spritesLinePriorities[a]<d?(j&&!spritesCollided&&setSpritesCollision(a,b),0!==f&&0===spritesLineColors[a]&&(spritesLineColors[a]=f,frameBackBuffer[c]=colorPaletteReal[f])):(spritesLinePriorities[a]=d,spritesLineColors[a]=f,0!==f&&(frameBackBuffer[c]=colorPaletteReal[f])))}}function renderSpritesLineMode2(a,b,c){if(spritesEnabled&&216!==vram[spriteAttrTableAddress+512]){var d,e,f,g,h,i,j,k,l,m,n,o,p=spritesSize<<spritesMag,q=-1,r=SPRITE_MAX_PRIORITY,s=0;spritesGlobalPriority-=32,d=spriteAttrTableAddress+512-4,e=spriteAttrTableAddress-16;for(var t=0;t<32&&(q+=1,d+=4,e+=16,216!==(j=vram[d]));++t)if(!((k=a-j-1&255)>=p)){if(++s>8&&(spritesInvalid<0&&!F&&(spritesInvalid=q),spriteDebugModeLimit))return;if(k>>>=spritesMag,f=vram[e+k],o=64&f){if(r===SPRITE_MAX_PRIORITY||debugModeSpriteInfo)continue}else r=spritesGlobalPriority+q;(0!=(15&f)||color0Solid)&&(l=vram[d+1],128&f&&(l-=32)<=-p||(16===spritesSize?(g=debugModeSpriteInfoNumbers?q<<2:252&vram[d+2],h=spritePatternTableAddress+(g<<3)+k,i=vram[h]<<8|vram[h+16]):(g=debugModeSpriteInfoNumbers?q:vram[d+2],i=vram[spritePatternTableAddress+(g<<3)+k]),m=l<=256-p?0:l-(256-p),n=l>=0?p:p+l,l+=p-n,o?paintSpriteMode2CC(l,b+l,r,i,15&f,c,m,n,spritesMag):paintSpriteMode2(l,a,b+l,r,i,15&f,c,m,n,spritesMag,spriteDebugModeCollisions&&0==(32&f)&&s<9)))}spritesInvalid<0&&q>spritesMaxComputed&&(spritesMaxComputed=q)}}function paintSpriteMode2(a,b,c,d,e,f,g,h,i,j,k){for(var l=i-1;l>=h;--l,++a,++c){0!==(e>>>(l>>>j)&1)&&(spritesLinePriorities[a]<d?k&&!spritesCollided&&setSpritesCollision(a,b):(spritesLinePriorities[a]=d,spritesLineColors[a]=f,frameBackBuffer[c]=g[f]))}}function paintSpriteMode2CC(a,b,c,d,e,f,g,h,i){for(var j,k=h-1;k>=g;--k,++a,++b){if(0!==(d>>>(k>>>i)&1)){var l=spritesLinePriorities[a];l<c||(l===c?j=e|spritesLineColors[a]:(spritesLinePriorities[a]=c,j=e),spritesLineColors[a]=j,frameBackBuffer[b]=f[j])}}}function renderSpritesLineMode2Tiled(a,b){if(spritesEnabled&&216!==vram[spriteAttrTableAddress+512]){var c,d,e,f,g,h,i,j,k,l,m,n,o=spritesSize<<spritesMag,p=-1,q=SPRITE_MAX_PRIORITY,r=0;spritesGlobalPriority-=32,c=spriteAttrTableAddress+512-4,d=spriteAttrTableAddress-16;for(var s=0;s<32&&(p+=1,c+=4,d+=16,216!==(i=vram[c]));++s)if(!((j=a-i-1&255)>=o)){if(++r>8&&(spritesInvalid<0&&!F&&(spritesInvalid=p),spriteDebugModeLimit))return;if(j>>>=spritesMag,e=vram[d+j],n=64&e){if(q===SPRITE_MAX_PRIORITY||debugModeSpriteInfo)continue}else q=spritesGlobalPriority+p;(0!=(15&e)||color0Solid)&&(k=vram[c+1],128&e&&(k-=32)<=-o||(16===spritesSize?(f=debugModeSpriteInfoNumbers?p<<2:252&vram[c+2],g=spritePatternTableAddress+(f<<3)+j,h=vram[g]<<8|vram[g+16]):(f=debugModeSpriteInfoNumbers?p:vram[c+2],h=vram[spritePatternTableAddress+(f<<3)+j]),l=k<=256-o?0:k-(256-o),m=k>=0?o:o+k,k+=o-m,n?paintSpriteMode2TiledCC(k,b+(k<<1),q,h,15&e,l,m,spritesMag):paintSpriteMode2Tiled(k,a,b+(k<<1),q,h,15&e,l,m,spritesMag,spriteDebugModeCollisions&&0==(32&e)&&r<9)))}spritesInvalid<0&&p>spritesMaxComputed&&(spritesMaxComputed=p)}}function paintSpriteMode2Tiled(a,b,c,d,e,f,g,h,i,j){for(var k=h-1;k>=g;--k,++a,c+=2){0!==(e>>>(k>>>i)&1)&&(spritesLinePriorities[a]<d?j&&!spritesCollided&&setSpritesCollision(a,b):(spritesLinePriorities[a]=d,spritesLineColors[a]=f,frameBackBuffer[c]=colorPaletteReal[f>>>2],frameBackBuffer[c+1]=colorPaletteReal[3&f]))}}function paintSpriteMode2TiledCC(a,b,c,d,e,f,g,h){for(var i,j=g-1;j>=f;--j,++a,b+=2){if(0!==(d>>>(j>>>h)&1)){var k=spritesLinePriorities[a];k<c||(k===c?i=e|spritesLineColors[a]:(spritesLinePriorities[a]=c,i=e),spritesLineColors[a]=i,frameBackBuffer[b]=colorPaletteReal[i>>>2],frameBackBuffer[b+1]=colorPaletteReal[3&i])}}}function renderSpritesLineMode2Stretched(a,b){if(spritesEnabled&&216!==vram[spriteAttrTableAddress+512]){var c,d,e,f,g,h,i,j,k,l,m,n,o=spritesSize<<spritesMag,p=-1,q=SPRITE_MAX_PRIORITY,r=0;spritesGlobalPriority-=32,c=spriteAttrTableAddress+512-4,d=spriteAttrTableAddress-16;for(var s=0;s<32&&(p+=1,c+=4,d+=16,216!==(i=vram[c]));++s)if(!((j=a-i-1&255)>=o)){if(++r>8&&(spritesInvalid<0&&!F&&(spritesInvalid=p),spriteDebugModeLimit))return;if(j>>>=spritesMag,e=vram[d+j],n=64&e){if(q===SPRITE_MAX_PRIORITY||debugModeSpriteInfo)continue}else q=spritesGlobalPriority+p;(0!=(15&e)||color0Solid)&&(k=vram[c+1],128&e&&(k-=32)<=-o||(16===spritesSize?(f=debugModeSpriteInfoNumbers?p<<2:252&vram[c+2],g=spritePatternTableAddress+(f<<3)+j,h=vram[g]<<8|vram[g+16]):(f=debugModeSpriteInfoNumbers?p:vram[c+2],h=vram[spritePatternTableAddress+(f<<3)+j]),l=k<=256-o?0:k-(256-o),m=k>=0?o:o+k,k+=o-m,n?paintSpriteMode2StretchedCC(k,b+(k<<1),q,h,15&e,l,m,spritesMag):paintSpriteMode2Stretched(k,a,b+(k<<1),q,h,15&e,l,m,spritesMag,spriteDebugModeCollisions&&0==(32&e)&&r<9)))}
spritesInvalid<0&&p>spritesMaxComputed&&(spritesMaxComputed=p)}}function paintSpriteMode2Stretched(a,b,c,d,e,f,g,h,i,j){for(var k=h-1;k>=g;--k,++a,c+=2){0!==(e>>>(k>>>i)&1)&&(spritesLinePriorities[a]<d?j&&!spritesCollided&&setSpritesCollision(a,b):(spritesLinePriorities[a]=d,spritesLineColors[a]=f,frameBackBuffer[c]=frameBackBuffer[c+1]=colorPaletteReal[f]))}}function paintSpriteMode2StretchedCC(a,b,c,d,e,f,g,h){for(var i,j=g-1;j>=f;--j,++a,b+=2){if(0!==(d>>>(j>>>h)&1)){var k=spritesLinePriorities[a];k<c||(k===c?i=e|spritesLineColors[a]:(spritesLinePriorities[a]=c,i=e),spritesLineColors[a]=i,frameBackBuffer[b]=frameBackBuffer[b+1]=colorPaletteReal[i])}}}function setSpritesCollision(a,b){spritesCollided=!0,spritesCollisionX>=0||(spritesCollisionX=a+12,spritesCollisionY=b+8,0==(192&register[8])&&(status[3]=255&spritesCollisionX,status[4]=254|spritesCollisionX>>>8,status[5]=255&spritesCollisionY,status[6]=252|spritesCollisionY>>>8))}function stretchCurrentLine(){for(var a=bufferPosition+272-1,b=bufferPosition+544-2,c=272;c>0;--c,--a,b-=2)frameBackBuffer[b]=frameBackBuffer[b+1]=frameBackBuffer[a]}function stretchFromCurrentToTopScanline(){for(var a=bufferPosition,b=currentScanline;b>=startingVisibleTopBorderScanline;--b,a-=bufferLineAdvance)for(var c=a+272-1,d=a+544-2,e=272;e>0;--e,--c,d-=2)frameBackBuffer[d]=frameBackBuffer[d+1]=frameBackBuffer[c]}function cleanFrameBuffer(){wmsx.Util.arrayFill(frameBackBuffer,modeData.tiled?4278190080:backdropValue)}function refresh(){videoSignal.newFrame(frameCanvas,0,0,refreshWidth,refreshHeight),refreshWidth=refreshHeight=0}function beginFrame(){vSyncConnection.vSyncPulse(),framePulldown!==pulldown&&(frameVideoStandard=videoStandard,framePulldown=pulldown,updateSignalMetrics(!1)),currentScanline=0,frameStartingActiveScanline=startingActiveScanline,renderMetricsChangePending&&updateRenderMetrics(!0),!blinkPerLine&&blinkPageDuration>0&&clockPageBlinking(),EO^=1,!isV9918&&8&register[9]?(bufferPosition=EO?LINE_WIDTH:0,bufferLineAdvance=2*LINE_WIDTH):(bufferPosition=0,bufferLineAdvance=LINE_WIDTH),updateLayoutTableAddressMask()}function finishFrame(){videoDisplayed&&(refreshWidth=renderWidth,refreshHeight=renderHeight,frameContext.putImageData(frameImageData,0,0,0,0,refreshWidth,refreshHeight)),++frame,beginFrame()}function initRegisters(){wmsx.Util.arrayFill(register,0),wmsx.Util.arrayFill(status,0),register[9]=videoStandard===wmsx.VideoStandard.PAL?2:0,status[0]=0,F=0,status[1]=isV9958?4:0,FH=0,status[2]=12,VR=0,HR=0,EO=0,status[4]=254,status[6]=252,status[9]=254}function initFrameResources(a){(!frameCanvas||!frameContextUsingAlpha&&a)&&(frameContextUsingAlpha=!!a,frameCanvas=document.createElement("canvas"),frameCanvas.width=wmsx.VDP.SIGNAL_MAX_WIDTH_V9938,frameCanvas.height=wmsx.VDP.SIGNAL_MAX_HEIGHT_V9938,frameContext=frameCanvas.getContext("2d",{alpha:frameContextUsingAlpha,antialias:!1}),frameImageData||(frameImageData=frameContext.createImageData(frameCanvas.width,frameCanvas.height+1+1),frameBackBuffer=new Uint32Array(frameImageData.data.buffer,0,frameCanvas.width*(frameCanvas.height+1)),backdropLineCache=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*(frameCanvas.height+1)*4,frameCanvas.width)))}function initColorCaches(){colorsV9918Values=wmsx.ColorCache.getColors4bit9918Values(),colors8bitValues=wmsx.ColorCache.getColors8bit9938Values(),colors9bitValues=wmsx.ColorCache.getColors9bit9938Values(),colorsYJKValues=void 0}function initColorPalette(){for(var a=0;a<16;++a){paletteRegister[a]=paletteRegisterInitialValuesV9938[a];var b=isV9918?colorsV9918Values[a]:getColorValueForPaletteValue(paletteRegister[a]);colorPaletteReal[a]=b,debugModeSpriteHighlight&&(b&=DEBUG_DIM_ALPHA_MASK),colorPalette[a]=b,colorPaletteSolid[a]=b}updateBackdropValue()}function initDebugPatternTables(){for(var a=[["111","101","101","101","111"],["110","010","010","010","111"],["111","001","111","100","111"],["111","001","111","001","111"],["101","101","111","001","001"],["111","100","111","001","111"],["111","100","111","101","111"],["111","001","001","001","001"],["111","101","111","101","111"],["111","101","111","001","001"],["110","001","111","101","111"],["100","100","111","101","110"],["000","111","100","100","111"],["001","001","111","101","111"],["110","101","111","100","011"],["011","100","110","100","100"]],b=DEBUG_PAT_DIGI6_TABLE_ADDRESS,c=DEBUG_PAT_DIGI8_TABLE_ADDRESS,d=DEBUG_PAT_DIGI16_TABLE_ADDRESS,e=DEBUG_PAT_BLOCK_TABLE_ADDRESS,f=0;f<256;f++){for(var g=f/16|0,h=f%16,i=0;i<5;i++)vram[b++]=parseInt(a[g][i]+a[h][i]+"00",2),vram[c++]=parseInt(a[g][i]+"0"+a[h][i]+"0",2);for(vram[b++]=vram[c++]=parseInt("00000000",2),vram[b++]=vram[c++]=parseInt("01111100",2),vram[b++]=vram[c++]=parseInt("00000000",2),vram[d++]=parseInt("11111111",2),i=0;i<4;i++)vram[d++]=parseInt("10000000",2);for(i=0;i<5;i++)vram[d++]=parseInt("1000"+a[g][i]+"0",2);for(i=0;i<5;i++)vram[d++]=parseInt("10000000",2);for(i=0;i<2;i++)vram[d++]=parseInt("11111111",2);for(i=0;i<4;i++)vram[d++]=parseInt("00000001",2);for(i=0;i<5;i++)vram[d++]=parseInt("0"+a[h][i]+"0001",2);for(i=0;i<5;i++)vram[d++]=parseInt("00000001",2);vram[d++]=parseInt("11111111",2)}vram[e]=vram[e+7]=0,vram[e+1]=vram[e+2]=vram[e+3]=vram[e+4]=vram[e+5]=vram[e+6]=126}function initSpritesConflictMap(){wmsx.Util.arrayFill(spritesLinePriorities,SPRITE_MAX_PRIORITY),wmsx.Util.arrayFill(spritesLineColors,0),spritesGlobalPriority=SPRITE_MAX_PRIORITY}function logInfo(a){console.log("VDP "+a+", currentScanLine: "+currentScanline+", activeRenderScanline: "+(currentScanline-frameStartingActiveScanline)+", activeHeight: "+signalActiveHeight)}var self=this;this.setMachineType=function(a){var b=WMSX.VDP_TYPE>0?WMSX.VDP_TYPE:a;isV9918=b<=M_TYPES.MSX1,isV9938=b===M_TYPES.MSX2,isV9958=b>=M_TYPES.MSX2P,cpuBusClockPulses=cpu.busClockPulses,cpuMemoryRefresh=cpu.r800MemoryRefresh},this.connectBus=function(a){a.connectInputDevice(152,this.input98),a.connectOutputDevice(152,this.output98),a.connectInputDevice(153,this.input99),a.connectOutputDevice(153,this.output99),a.connectInputDevice(154,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(154,this.output9a),a.connectInputDevice(155,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(155,this.output9b)},this.connectSlave=function(a){slave=a,slave&&slave.setVideoStandard(videoStandard),updateSignalMetrics(!0),updateRenderMetrics(!0)},this.powerOn=function(){this.reset()},this.powerOff=function(){videoSignal.signalOff()},this.setVideoStandard=function(a){videoStandard=a,updateSynchronization(),slave&&slave.setVideoStandard(videoStandard)},this.setVSynchMode=function(a){vSynchMode=a,updateSynchronization()},this.getVideoSignal=function(){return videoSignal},this.getDesiredVideoPulldown=function(){return pulldown},this.videoClockPulse=function(){cycleEvents(),refreshWidth&&refresh(),slave&&slave.cycleEventRefresh()},this.input98=function(){dataFirstWrite=null;var a=dataPreRead;return dataPreRead=vram[vramPointer],++vramPointer,checkVRAMPointerWrap(),a},this.output98=function(a){dataFirstWrite=null,vram[vramPointer]=dataPreRead=a,++vramPointer,checkVRAMPointerWrap()},this.input99=function(){dataFirstWrite=null;var a,b=register[15];switch(b){case 0:a=getStatus0();break;case 1:a=status[1]|FH,16&register[0]&&FH&&(FH=0,updateIRQ());break;case 2:commandProcessor.updateStatus(),a=status[2]|VR<<6|HR<<5|EO<<1;break;case 3:case 4:case 6:a=status[b];break;case 5:a=status[5],spritesCollisionX=spritesCollisionY=-1,status[3]=status[4]=status[5]=status[6]=0;break;case 7:a=status[7],commandProcessor.cpuRead();break;case 8:case 9:a=status[b];break;default:a=255}return a},this.output99=function(a){null===dataFirstWrite?(dataFirstWrite=a,isV9918&&(vramPointer=-256&vramPointer|a)):(128&a?isV9918?(registerWrite(7&a,dataFirstWrite),
vramPointer=114943&vramPointer|(63&a)<<8):0==(64&a)&&registerWrite(63&a,dataFirstWrite):(vramPointer=114688&vramPointer|(63&a)<<8|dataFirstWrite,0==(64&a)&&(dataPreRead=vram[vramPointer],++vramPointer,checkVRAMPointerWrap())),dataFirstWrite=null)},this.output9a=function(a){isV9918||(null===paletteFirstWrite?paletteFirstWrite=a:(paletteRegisterWrite(register[16],a<<8|paletteFirstWrite,!1),++register[16]>15&&(register[16]=0),paletteFirstWrite=null))},this.output9b=function(a){if(!isV9918){var b=63&register[17];17!==b&&registerWrite(b,a),0==(128&register[17])&&(register[17]=b+1&63)}},this.toggleDebugModes=function(a){return setDebugMode(debugMode+(a?-1:1)),videoSignal.showOSD("Debug Mode"+(debugMode>0?" "+debugMode:"")+": "+["OFF","Sprites Highlighted","Sprite Numbers","Sprite Names","Sprites Hidden","Pattern Bits","Pattern Color Blocks","Pattern Names"][debugMode],!0),debugMode},this.toggleSpriteDebugModes=function(a){setSpriteDebugMode(spriteDebugMode+(a?-1:1)),videoSignal.showOSD("Sprites Mode"+(spriteDebugMode>0?" "+spriteDebugMode:"")+": "+["Normal","Unlimited","NO Collisions","Unlimited, No Collisions"][spriteDebugMode],!0)},this.setColorAndPaletteMode=function(a,b){wmsx.ColorCache.setColorAndPaletteMode(a,b),initColorCaches(),updateAllPaletteValues()},this.getSpriteDebugModeQuickDesc=function(){return["Normal","Unlimited","No Collis.","Both"][spriteDebugMode]},this.setVDPTurboMulti=function(a){commandProcessor.setVDPTurboMulti(a)},this.getVDPTurboMulti=function(){return commandProcessor.getVDPTurboMulti()},this.setDefaults=function(){setDebugMode(STARTING_DEBUG_MODE),setSpriteDebugMode(STARTING_SPRITES_DEBUG_MODE)},this.videoSignalDisplayStateUpdate=function(a,b){videoDisplayed=a},this.refreshDisplayMetrics=function(){videoSignal.setDisplayMetrics(renderWidth,renderHeight)},this.resetOutputAutoMode=function(){},this.reset=function(){frame=0,dataFirstWrite=null,dataPreRead=0,vramPointer=0,paletteFirstWrite=null,verticalAdjust=horizontalAdjust=0,leftMask=leftScroll2Pages=!1,leftScrollChars=leftScrollCharsInPage=rightScrollPixels=0,backdropColor=backdropValue=0,spritesCollided=!1,spritesCollisionX=spritesCollisionY=spritesInvalid=-1,spritesMaxComputed=0,horizontalIntLine=0,vramInterleaving=!1,renderMetricsChangePending=!1,refreshWidth=refreshHeight=0,frameVideoStandard=videoStandard,framePulldown=pulldown,currentScanline=-1,initRegisters(),initColorPalette(),commandProcessor.reset(),updateSignalMetrics(!0),updateIRQ(),updateMode(!0),updateSpritesConfig(),updateBackdropColor(),updateTransparency(),updateSynchronization(),updateBlinking(),beginFrame()},this.getVDPCycles=function(){return 6*cpu.getBUSCycles()},this.getScreenText=function(){var a=modeData.textCols;if(!a)return null;for(var b=128&register[9]?27:24,c=[],d=0;d<b;++d)c.push(wmsx.Util.int8BitArrayToByteString(vram,layoutTableAddress+d*a,a).replace(/\s+$/,""));return c.join("\n").replace(/[\x00\xff]/g," ").replace(/\s+$/,"")};var LINE_WIDTH=wmsx.VDP.SIGNAL_MAX_WIDTH_V9938,SPRITE_MAX_PRIORITY=9e15,DEBUG_DIM_ALPHA_MASK=1090519039,VRAM_SIZE=wmsx.VDP.VRAM_LIMIT+1,DEBUG_PAT_DIGI6_TABLE_ADDRESS=VRAM_SIZE,DEBUG_PAT_DIGI8_TABLE_ADDRESS=DEBUG_PAT_DIGI6_TABLE_ADDRESS+2048,DEBUG_PAT_DIGI16_TABLE_ADDRESS=DEBUG_PAT_DIGI8_TABLE_ADDRESS+2048,DEBUG_PAT_BLOCK_TABLE_ADDRESS=DEBUG_PAT_DIGI16_TABLE_ADDRESS+8192,VRAM_TOTAL_SIZE=DEBUG_PAT_BLOCK_TABLE_ADDRESS+8,STARTING_DEBUG_MODE=WMSX.DEBUG_MODE,STARTING_SPRITES_DEBUG_MODE=WMSX.SPRITES_DEBUG_MODE,frameCanvas,frameContext,frameImageData,frameBackBuffer,backdropLineCache,frameContextUsingAlpha=!1,isV9918,isV9938,isV9958,vram=new Uint8Array(VRAM_TOTAL_SIZE);this.vram=vram;var vramInterleaving,frame,blinkEvenPage,blinkPageDuration,blinkPerLine,vSynchMode,videoStandard=wmsx.VideoStandard.NTSC,pulldown,bufferPosition,bufferLineAdvance,currentScanline,signalActiveHeight,finishingScanline,startingActiveScanline,frameStartingActiveScanline,startingVisibleTopBorderScanline,startingInvisibleScanline,frameVideoStandard=videoStandard,framePulldown,horizontalIntLine=0,status=new Array(10),F=0,FH=0,VR=0,HR=0,EO=0,register=new Array(47),paletteRegister=new Array(16),modeData,renderMetricsChangePending,renderWidth,renderHeight,refreshWidth,refreshHeight,blankingChangePending,backdropCacheUpdatePending,spritesEnabled,spritesSize,spritesMag,spritesCollided,spritesInvalid,spritesMaxComputed,spritesCollisionX,spritesCollisionY,spritesLinePriorities=new Array(256),spritesLineColors=new Array(256),spritesGlobalPriority,vramPointer=0,paletteFirstWrite,dataFirstWrite=null,dataPreRead=0,backdropColor,backdropValue,backdropTileOdd,backdropTileEven,verticalAdjust,horizontalAdjust,leftMask,leftScroll2Pages,leftScrollChars,leftScrollCharsInPage,rightScrollPixels,layoutTableAddress,colorTableAddress,patternTableAddress,spriteAttrTableAddress,spritePatternTableAddress,layoutTableAddressMask,layoutTableAddressMaskSetValue,colorTableAddressMask,patternTableAddressMask,layoutTableAddressMaskBase=1023,colorTableAddressMaskBase=63,patternTableAddressMaskBase=2047,modes=wmsx.Util.arrayFill(new Array(36),{name:"NUL",isV9938:!0,layTBase:0,colorTBase:0,patTBase:0,sprAttrTBase:0,width:256,layLineBytes:0,evenPageMask:-1,blinkPageMask:-1,renderLine:renderLineBlanked,renderLinePatInfo:renderLineBlanked,ppb:0,spriteMode:0,tiled:!1,vramInter:null,bdPaletted:!0,textCols:0});modes[16]={name:"T1",isV9938:!1,layTBase:-1024,colorTBase:0,patTBase:-2048,sprAttrTBase:0,width:256,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-1,renderLine:renderLineModeT1,renderLinePatInfo:renderLineModeT1PatInfo,ppb:0,spriteMode:0,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:40},modes[18]={name:"T2",isV9938:!0,layTBase:-4096,colorTBase:-512,patTBase:-2048,sprAttrTBase:0,width:512,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-1,renderLine:renderLineModeT2,renderLinePatInfo:renderLineModeT2PatInfo,ppb:0,spriteMode:0,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:80},modes[8]={name:"MC",isV9938:!1,layTBase:-1024,colorTBase:0,patTBase:-2048,sprAttrTBase:-128,width:256,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-1,renderLine:renderLineModeMC,renderLinePatInfo:renderLineModeMCPatInfo,ppb:0,spriteMode:1,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:0},modes[0]={name:"G1",isV9938:!1,layTBase:-1024,colorTBase:-64,patTBase:-2048,sprAttrTBase:-128,width:256,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-1,renderLine:renderLineModeG1,renderLinePatInfo:renderLineModeG1PatInfo,ppb:0,spriteMode:1,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:32},modes[1]={name:"G2",isV9938:!1,layTBase:-1024,colorTBase:-8192,patTBase:-8192,sprAttrTBase:-128,width:256,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-1,renderLine:renderLineModeG2,renderLinePatInfo:renderLineModeG2PatInfo,ppb:0,spriteMode:1,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:0},modes[2]={name:"G3",isV9938:!0,layTBase:-1024,colorTBase:-8192,patTBase:-8192,sprAttrTBase:-1024,width:256,layLineBytes:0,evenPageMask:-32769,blinkPageMask:-32769,renderLine:renderLineModeG3,renderLinePatInfo:renderLineModeG3PatInfo,ppb:0,spriteMode:2,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:0},modes[3]={name:"G4",isV9938:!0,layTBase:-32768,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:256,layLineBytes:128,evenPageMask:-32769,blinkPageMask:-32769,renderLine:renderLineModeG4,renderLinePatInfo:renderLineModeG4,ppb:2,spriteMode:2,tiled:!1,vramInter:!1,bdPaletted:!0,textCols:0},modes[4]={name:"G5",isV9938:!0,layTBase:-32768,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:512,layLineBytes:128,evenPageMask:-32769,blinkPageMask:-32769,renderLine:renderLineModeG5,renderLinePatInfo:renderLineModeG5,ppb:4,spriteMode:2,tiled:!0,vramInter:!1,bdPaletted:!0,textCols:0},modes[5]={name:"G6",isV9938:!0,layTBase:-65536,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:512,layLineBytes:256,evenPageMask:-65537,blinkPageMask:-65537,renderLine:renderLineModeG6,renderLinePatInfo:renderLineModeG6,ppb:2,spriteMode:2,
tiled:!1,vramInter:!0,bdPaletted:!0,textCols:0},modes[7]={name:"G7",isV9938:!0,layTBase:-65536,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:256,layLineBytes:256,evenPageMask:-65537,blinkPageMask:-65537,renderLine:renderLineModeG7,renderLinePatInfo:renderLineModeG7,ppb:1,spriteMode:2,tiled:!1,vramInter:!0,bdPaletted:!1,textCols:0},modes[33]={name:"YJK",isV9938:!0,layTBase:-65536,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:256,layLineBytes:256,evenPageMask:-65537,blinkPageMask:-65537,renderLine:renderLineModeYJK,renderLinePatInfo:renderLineModeYJK,ppb:1,spriteMode:2,tiled:!1,vramInter:!0,bdPaletted:!0,textCols:0},modes[35]={name:"YAE",isV9938:!0,layTBase:-65536,colorTBase:0,patTBase:0,sprAttrTBase:-1024,width:256,layLineBytes:256,evenPageMask:-65537,blinkPageMask:-65537,renderLine:renderLineModeYAE,renderLinePatInfo:renderLineModeYAE,ppb:1,spriteMode:2,tiled:!1,vramInter:!0,bdPaletted:!0,textCols:0};var renderLine,renderLineActive,colorsV9918Values,colors8bitValues,colors9bitValues,colorsYJKValues,color0Solid=!1,colorPalette=new Uint32Array(16),colorPaletteSolid=new Uint32Array(16),colorPaletteReal=new Uint32Array(16),spritePaletteG7=new Uint32Array([4278190080,4282974208,4278190189,4282974317,4278217984,4283002112,4278218093,4283002221,4283011839,4294901760,4278190335,4294902015,4278255360,4294967040,4278255615,4294967295]),paletteRegisterInitialValuesV9938=[0,0,1553,1843,279,807,337,1575,289,883,1633,1636,1041,613,869,1911],debugMode=0,debugModeSpriteHighlight=!1,debugModeSpriteInfo=!1,debugModeSpriteInfoNumbers=!1,debugModeSpritesHidden=!1,debugModePatternInfo=!1,debugModePatternInfoBlocks=!1,debugModePatternInfoNames=!1,spriteDebugMode=0,spriteDebugModeLimit=!0,spriteDebugModeCollisions=!0,debugBackdropValue=4280953386,debugLineStartBUSCycles=0,videoSignal,videoDisplayed=!0,cpuBusClockPulses,cpuMemoryRefresh,audioClockPulse32,commandProcessor,slave,M_TYPES=wmsx.Machine.MACHINE_TYPE;this.saveState=function(a){var b={v1:isV9918,v3:isV9938,v5:isV9958,f:frame,l:currentScanline,b:bufferPosition,ba:bufferLineAdvance,ad:renderLine===renderLineActive,fs:frameStartingActiveScanline,vp:vramPointer,d:dataFirstWrite,dr:dataPreRead,pw:paletteFirstWrite,ha:horizontalAdjust,va:verticalAdjust,hil:horizontalIntLine,lm:leftMask,ls2:leftScroll2Pages,lsc:leftScrollChars,rsp:rightScrollPixels,bp:blinkEvenPage,bpd:blinkPageDuration,bpl:blinkPerLine,sc:spritesCollided,sx:spritesCollisionX,sy:spritesCollisionY,si:spritesInvalid,sm:spritesMaxComputed,bf:F,bfh:FH,bvr:VR,bhr:HR,beo:EO,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),s:wmsx.Util.storeInt8BitArrayToStringBase64(status),p:wmsx.Util.storeInt16BitArrayToStringBase64(paletteRegister),vram:wmsx.Util.compressInt8BitArrayToStringBase64(vram,VRAM_SIZE),vrint:vramInterleaving,cp:commandProcessor.saveState()};return a&&(b.dm=debugMode,b.sd=spriteDebugMode),b},this.loadState=function(a){isV9918=a.v1,isV9938=a.v3,isV9958=a.v5,cpuBusClockPulses=cpu.busClockPulses,register=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r,register),status=wmsx.Util.restoreStringBase64ToInt8BitArray(a.s,status),paletteRegister=wmsx.Util.restoreStringBase64ToInt16BitArray(a.p,paletteRegister),vram=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.vram,vram,!0),frame=a.f||0,currentScanline=a.l,bufferPosition=a.b,bufferLineAdvance=a.ba,vramPointer=a.vp,dataFirstWrite=a.d,dataPreRead=a.dr||0,paletteFirstWrite=a.pw,horizontalAdjust=a.ha,verticalAdjust=a.va,horizontalIntLine=a.hil,leftMask=a.lm,leftScroll2Pages=a.ls2,leftScrollChars=a.lsc,rightScrollPixels=a.rsp,leftScrollCharsInPage=31&leftScrollChars,blinkEvenPage=a.bp,blinkPageDuration=a.bpd,blinkPerLine=void 0!==a.bpl?a.bpl:0!=(4&register[1]),spritesCollided=a.sc,spritesCollisionX=a.sx,spritesCollisionY=a.sy,spritesInvalid=a.si,spritesMaxComputed=a.sm,void 0!==a.bf?(F=a.bf,FH=a.bfh,VR=a.bvr,HR=a.bhr,EO=a.beo):(F=0|a.vi,FH=1&status[1],VR=status[2]>>6&1,HR=status[2]>>5&1,EO=status[2]>>1&1,status[0]&=-129,status[1]&=-2,status[2]&=-99),vramInterleaving=a.vrint,commandProcessor.loadState(a.cp),commandProcessor.connectVDP(this,vram,register,status),frameVideoStandard=videoStandard,framePulldown=pulldown,updateSignalMetrics(!0),void 0!==a.fs&&(frameStartingActiveScanline=a.fs),updateIRQ(),updateMode(!0),updateSpritesConfig(),updateAllPaletteValues(),updateBackdropColor(),updateTransparency(),a.ad?setActiveDisplay():setBorderDisplay(),void 0!==a.dm&&setDebugMode(a.dm),void 0!==a.sd&&setSpriteDebugMode(a.sd)},init(),this.logInfo=logInfo,this.eval=function(str){return eval(str)}},wmsx.VDP.VRAM_LIMIT=131071,wmsx.VDP.SIGNAL_WIDTH_V9918=272,wmsx.VDP.SIGNAL_HEIGHT_V9918=208,wmsx.VDP.SIGNAL_START_WIDTH_V9938=272,wmsx.VDP.SIGNAL_START_HEIGHT_V9938=228,wmsx.VDP.SIGNAL_MAX_WIDTH_V9938=544,wmsx.VDP.SIGNAL_MAX_HEIGHT_V9938=456,wmsx.VDP.BASE_CLOCK=6*wmsx.CPU.BASE_CLOCK,wmsx.VDPCommandProcessor=function(){"use strict";function getSX(){return(1&register[33])<<8|register[32]}function getSY(){return(3&register[35])<<8|register[34]}function setSY(a){register[35]=a>>8&3,register[34]=255&a}function getDX(){return(1&register[37])<<8|register[36]}function getDY(){return(3&register[39])<<8|register[38]}function setDY(a){register[39]=a>>8&3,register[38]=255&a}function getNX(){return(1&register[41])<<8|register[40]}function getNY(){return(3&register[43])<<8|register[42]}function setNY(a){register[43]=a>>8&3,register[42]=255&a}function getDIX(){return 4&register[45]?-1:1}function getDIY(){return 8&register[45]?-1:1}function getCLR(){return register[44]}function setCLR(a){register[44]=a}function getMAJ(){return 1&register[45]}function getEQ(){return 0==(2&register[45])}function getLOP(){return LOGICAL_OPERATIONS[15&register[46]]}function HMMC(){var a=getDX();DY=getDY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),a>>=modePPBShift,NX>>=modePPBShift,a>=layoutLineBytes?(a&=layoutLineBytes-1,NX=1):(NX=NX||layoutLineBytes,NX=1===DIX?min(NX,layoutLineBytes-a):min(NX,a+1)),NY=NY||1024,ENY=1===DIY?NY:min(NY,DY+1),destPos=DY*layoutLineBytes+a,writeStart(HMMCNextWrite)}function HMMCNextWrite(a){vram[destPos&VRAM_LIMIT]=a,++CX,CX>=NX?(destPos-=DIX*(NX-1),CX=0,++CY,CY>=ENY?finish():destPos+=DIY*layoutLineBytes):destPos+=DIX,setDY(DY+DIY*CY),setNY(NY-CY)}function YMMM(){var a=getSY(),b=getDX(),c=getDY(),d=getNY(),e=getDIX(),f=getDIY();(b>>=modePPBShift)>=layoutLineBytes&&(b&=layoutLineBytes-1);var g=1===e?layoutLineBytes-b:b+1;d=d||1024;for(var h=1===f?d:min(d,min(a,c)+1),i=a*layoutLineBytes+b,j=c*layoutLineBytes+b,k=-e*g+layoutLineBytes*f,l=h;l>0;--l){for(var m=g;m>0;--m)vram[j&VRAM_LIMIT]=vram[i&VRAM_LIMIT],i+=e,j+=e;i+=k,j+=k}setSY(a+f*h),setDY(c+f*h),setNY(d-h),start(g*h,64,h,0)}function HMMM(){var a=getSX(),b=getSY(),c=getDX(),d=getDY(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY();a>>=modePPBShift,c>>=modePPBShift,e>>=modePPBShift,a>=layoutLineBytes||c>=layoutLineBytes?(a&=layoutLineBytes-1,c&=layoutLineBytes-1,e=1):(e=e||layoutLineBytes,e=1===g?min(e,layoutLineBytes-max(a,c)):min(e,min(a,c)+1)),f=f||1024;for(var i=1===h?f:min(f,min(b,d)+1),j=b*layoutLineBytes+a,k=d*layoutLineBytes+c,l=-g*e+layoutLineBytes*h,m=i;m>0;--m){for(var n=e;n>0;--n)vram[k&VRAM_LIMIT]=vram[j&VRAM_LIMIT],j+=g,k+=g;j+=l,k+=l}setSY(b+h*i),setDY(d+h*i),setNY(f-i),start(e*i,88,i,64)}function HMMV(){var a=getDX(),b=getDY(),c=getNX(),d=getNY(),e=getCLR(),f=getDIX(),g=getDIY();a>>=modePPBShift,c>>=modePPBShift,a>=layoutLineBytes?(a&=layoutLineBytes-1,c=1):(c=c||layoutLineBytes,c=1===f?min(c,layoutLineBytes-a):min(c,a+1)),d=d||1024;for(var h=1===g?d:min(d,b+1),i=b*layoutLineBytes+a,j=-f*c+layoutLineBytes*g,k=h;k>0;--k){for(var l=c;l>0;--l)vram[i&VRAM_LIMIT]=e,i+=f;i+=j}setDY(b+g*h),setNY(d-h),start(c*h,48,h,56)}function LMMC(){DX=getDX(),DY=getDY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),LOP=getLOP(),DX>=modeWidth?(DX&=modeWidth-1,NX=1):(NX=NX||modeWidth,NX=1===DIX?min(NX,modeWidth-DX):min(NX,DX+1)),NY=NY||1024,ENY=1===DIY?NY:min(NY,DY+1),
writeStart(LMMCNextWrite)}function LMMCNextWrite(a){logicalPSET(DX,DY,a,LOP),++CX,CX>=NX?(DX-=DIX*(NX-1),CX=0,++CY,DY+=DIY,CY>=ENY&&finish()):DX+=DIX,setDY(DY),setNY(NY-CY)}function LMCM(){SX=getSX(),SY=getSY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),SX>=modeWidth?(SX&=modeWidth-1,NX=1):(NX=NX||modeWidth,NX=1===DIX?min(NX,modeWidth-SX):min(NX,SX+1)),NY=NY||1024,ENY=1===DIY?NY:min(NY,SY+1),readStart(LMCMNextRead)}function LMCMNextRead(){status[7]=normalPGET(SX,SY),++CX,CX>=NX?(SX-=DIX*(NX-1),CX=0,++CY,SY+=DIY,CY>=ENY&&finish()):SX+=DIX,setSY(SY),setNY(NY-CY)}function LMMM(){var a=getSX(),b=getSY(),c=getDX(),d=getDY(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY(),i=getLOP();a>=modeWidth||c>=modeWidth?(a&=modeWidth-1,c&=modeWidth-1,e=1):(e=e||modeWidth,e=1===g?min(e,modeWidth-max(a,c)):min(e,min(a,c)+1)),f=f||1024;for(var j=1===h?f:min(f,min(b,d)+1),k=j;k>0;--k){for(var l=e;l>0;--l)logicalPCOPY(c,d,a,b,i),a+=g,c+=g;a-=g*e,c-=g*e,b+=h,d+=h}setSY(b),setDY(d),setNY(f-j),start(e*j,120,j,64)}function LMMV(){var a=getDX(),b=getDY(),c=getNX(),d=getNY(),e=getCLR(),f=getDIX(),g=getDIY(),h=getLOP();a>=modeWidth?(a&=modeWidth-1,c=1):(c=c||modeWidth,c=1===f?min(c,modeWidth-a):min(c,a+1)),d=d||1024;for(var i=1===g?d:min(d,b+1),j=i;j>0;--j){for(var k=c;k>0;--k)logicalPSET(a,b,e,h),a+=f;a-=f*c,b+=g}setDY(b),setNY(d-i),start(c*i,96,i,64)}function LINE(){var a=getDX(),b=getDY(),c=getNX(),d=getNY(),e=getCLR(),f=getDIX(),g=getDIY(),h=getMAJ(),i=getLOP(),j=modeWidth-1;a&=j;var k=0,l=0;if(0===h)for(var m=0;m<=c&&(logicalPSET(a,b,e,i),a+=f,d>0&&(l+=d)<<1>=c&&(b+=g,l-=c,++k),!(a>j||a<0||b<0));++m);else for(m=0;m<=c&&(logicalPSET(a,b,e,i),b+=g,d>0&&(l+=d)<<1>=c&&(a+=f,l-=c,++k),!(a>j||a<0||b<0));++m);setDY(b),start(m,112,k,32)}function SRCH(){var a=getSX(),b=getSY(),c=getCLR(),d=getDIX(),e=getEQ();a>=modeWidth&&(a&=modeWidth-1);var f=1===d?modeWidth:-1,g=a,h=!1;if(e)do{if(normalPGET(g,b)===c){h=!0;break}g+=d}while(g!==f);else do{if(normalPGET(g,b)!==c){h=!0;break}g+=d}while(g!==f);status[2]=-17&status[2]|(h?16:0),status[8]=255&g,status[9]=g>>8&1,start(Math.abs(g-a)+1,86,1,50)}function PSET(){var a=getDX(),b=getDY(),c=getCLR(),d=getLOP();a>=modeWidth&&(a&=modeWidth-1),logicalPSET(a,b,c,d),start(0,0,1,40)}function POINT(){var a=getSX(),b=getSY();a>=modeWidth&&(a&=modeWidth-1);var c=normalPGET(a,b);setCLR(c),status[7]=c,start(0,0,1,40)}function STOP(){finish()}function normalPGET(a,b){var c,d;switch(modePPB){case 2:c=1&a?0:4,a>>>=1,d=15<<c;break;case 4:c=2*(3-(3&a)),a>>>=2,d=3<<c;break;default:c=0,d=255}return(vram[b*layoutLineBytes+a&VRAM_LIMIT]&d)>>c}function logicalPSET(a,b,c,d){var e,f;switch(modePPB){case 2:e=1&a?0:4,a>>>=1,c=(15&c)<<e,f=15<<e;break;case 4:e=2*(3-(3&a)),a>>>=2,c=(3&c)<<e,f=3<<e;break;default:f=255}var g=b*layoutLineBytes+a;vram[g&VRAM_LIMIT]=d(vram[g&VRAM_LIMIT],c,f)}function logicalPCOPY(a,b,c,d,e){var f,g,h;switch(modePPB){case 2:f=1&c?0:4,g=1&a?0:4,c>>>=1,a>>>=1,h=15;break;case 4:f=2*(3-(3&c)),g=2*(3-(3&a)),c>>>=2,a>>>=2,h=3;break;default:f=g=0,h=255}var i=d*layoutLineBytes+c,j=b*layoutLineBytes+a,k=(vram[i&VRAM_LIMIT]>>f&h)<<g;vram[j&VRAM_LIMIT]=e(vram[j&VRAM_LIMIT],k,h<<g)}function lopIMP(a,b,c){return a&~c|b}function lopAND(a,b,c){return a&(b|~c)}function lopOR(a,b,c){return a|b}function lopXOR(a,b,c){return a^b}function lopNOT(a,b,c){return a&~c|~b&c}function lopTIMP(a,b,c){return 0===b?a:a&~c|b}function lopTAND(a,b,c){return 0===b?a:a&(b|~c)}function lopTOR(a,b,c){return 0===b?a:a|b}function lopTXOR(a,b,c){return a^b}function lopTNOT(a,b,c){return 0===b?a:a&~c|~b&c}function min(a,b){return a<b?a:b}function max(a,b){return a>b?a:b}function start(a,b,c,d,e){CE=1,writeHandler=null,readHandler=null,estimateDuration(a,b,c,d,e)}function estimateDuration(a,b,c,d,e){if(e)finishingCycle=-1;else if(0===turboClockMulti)finishingCycle=0;else{var f=(a*b*COMMAND_PER_PIXEL_DURATION_FACTOR+c*d)/turboClockMulti|0;finishingCycle=vdp.getVDPCycles()+f}}function writeStart(a){start(0,0,0,0,!0),CX=0,CY=0,writeHandler=a,TR=1,writeReady&&(writeHandler(getCLR()),writeReady=!1)}function readStart(a){start(0,0,0,0,!0),CX=0,CY=0,readHandler=a,TR=1,readHandler()}function finish(){CE=0,writeHandler=null,writeReady=!1,readHandler=null,register[46]&=-241}this.connectVDP=function(a,b,c,d){vdp=a,vram=b,register=c,status=d},this.reset=function(){STOP()},this.startCommand=function(a){switch(240&a){case 240:HMMC();break;case 224:YMMM();break;case 208:HMMM();break;case 192:HMMV();break;case 176:LMMC();break;case 160:LMCM();break;case 144:LMMM();break;case 128:LMMV();break;case 112:LINE();break;case 96:SRCH();break;case 80:PSET();break;case 64:POINT();break;case 0:STOP()}},this.cpuWrite=function(a){writeHandler?writeHandler(a):(writeReady=!0,TR=0)},this.cpuRead=function(){readHandler?readHandler():TR=0},this.updateStatus=function(){CE&&finishingCycle>=0&&(0===finishingCycle||vdp.getVDPCycles()>=finishingCycle)&&finish(),status[2]=-130&status[2]|TR<<7|CE},this.setVDPModeData=function(a){modeData=a,modeWidth=modeData.width,modePPB=modeData.ppb||1,modePPBShift=modePPB>>1,modePPBMask=-1<<modePPBShift,layoutLineBytes=modeData.layLineBytes||256},this.setVDPTurboMulti=function(a){turboClockMulti=a<0||a>8?0:a},this.getVDPTurboMulti=function(){return turboClockMulti};var VRAM_LIMIT=wmsx.VDP.VRAM_LIMIT,COMMAND_HANDLERS={HMMCNextWrite:HMMCNextWrite,LMMCNextWrite:LMMCNextWrite,LMCMNextRead:LMCMNextRead},COMMAND_PER_PIXEL_DURATION_FACTOR=1.1,LOGICAL_OPERATIONS=[lopIMP,lopAND,lopOR,lopXOR,lopNOT,lopIMP,lopIMP,lopIMP,lopTIMP,lopTAND,lopTOR,lopTXOR,lopTNOT,lopIMP,lopIMP,lopIMP],turboClockMulti=1,vdp,vram,register,status,CE=!1,TR=!1,SX,SY,DX,DY,NX,NY,ENY,DIX,DIY,CX,CY,LOP,destPos,writeReady=!1,writeHandler=null,readHandler=null,finishingCycle=0,modeData,modePPB,modePPBShift,modePPBMask,modeWidth,layoutLineBytes;this.saveState=function(){return{ce:CE,tr:TR,wr:writeReady,wh:writeHandler&&writeHandler.name,rh:readHandler&&readHandler.name,fc:finishingCycle,SX:SX,SY:SY,DX:DX,DY:DY,NX:NX,NY:NY,ENY:ENY,DIX:DIX,DIY:DIY,CX:CX,CY:CY,LOP:LOP&&LOGICAL_OPERATIONS.indexOf(LOP),dp:destPos,tcm:turboClockMulti}},this.loadState=function(a){CE=a.ce,TR=a.tr,writeReady=a.wr,writeHandler=COMMAND_HANDLERS[a.wh],readHandler=COMMAND_HANDLERS[a.rh],finishingCycle=a.fc,SX=a.SX,SY=a.SY,DX=a.DX,DY=a.DY,NX=a.NX,NY=a.NY,ENY=a.ENY,DIX=a.DIX,DIY=a.DIY,CX=a.CX,CY=a.CY,LOP=a.LOP>=0?LOGICAL_OPERATIONS[a.LOP]:void 0,destPos=a.dp,turboClockMulti=void 0!==a.tcm?a.tcm:1},this.eval=function(str){return eval(str)}},wmsx.V9990=function(){"use strict";function init(){videoSignal=new wmsx.VideoSignal(self,"V9990"),initColorCaches(),initFrameResources(!1),initDebugPatternTables(),modeData=modes.SBY,typeData=types.SBY,self.setDefaults(),commandProcessor=new wmsx.V9990CommandProcessor,commandProcessor.connectV9990(self,vram,register),commandProcessor.setV9990ModeData(modeData,typeData,imageWidth,imageHeight)}function softReset(){interruptFlags=0,vramPointerRead=0,vramPointerWrite=0,vramPointerReadInc=!0,vramPointerWriteInc=!0,vramReadData=0,palettePointer=0,palettePointerReadInc=!0,paletteOffsetA=0,paletteOffsetB=0,paletteOffset=0,scrollXOffset=0,scrollYOffset=0,scrollYOffsetFrame=0,scrollXBOffset=0,scrollYBOffset=0,scrollYBOffsetFrame=0,scrollYMax=0,scrollYHiUpdatePending=!1,scrollYBHiUpdatePending=!1,planeAEnabled=!0,planeBEnabled=!0,priBYLine=256,priBXCol=256,vramEOLineShift=0,vramEOLineAdd=0,verticalAdjust=horizontalAdjust=0,dispEnabled=!1,dispAndSpritesUpdatePending=!1,spritesEnabled=!0,horizontalIntLine=0,renderMetricsUpdatePending=!1,commandProcessor.reset(),initRegisters(),updateSignalMetrics(!0),updateIRQ(),updateMode(!0),updateBackdropColor(),updateSynchronization(),commandProcessor.setV9990DisplayAndSpritesEnabled(dispEnabled,spritesEnabled),updateYSEnabled()}function updateVRAMReadPointer(){vramPointerRead=(register[5]<<16|register[4]<<8|register[3])&VRAM_LIMIT,vramPointerReadInc=0==(128&register[5])}function updateVRAMWritePointer(a){
vramPointerWrite=(register[2]<<16|register[1]<<8|register[0])&VRAM_LIMIT,vramPointerWriteInc=0==(128&register[2])}function updatePalettePointer(){palettePointer=register[14]}function updatePalettePointerReadInc(){palettePointerReadInc=0==(16&register[13])}function updatePaletteOffsets(){paletteOffsetA=(3&register[13])<<4,paletteOffsetB=(12&register[13])<<2,paletteOffset=paletteOffsetB<<2|paletteOffsetA}function updatePaletteOffsetCursor(){paletteOffsetCursor=(15&register[28])<<2}function updateYSEnabled(a){var b=superimposeActive&&0!=(32&register[8]),c=b?65535:32767;(a||ys16BitColorMask!==c)&&(ys16BitColorMask=c,updateAllPaletteValues(),colors8bitValues&&(colors8bitValues=wmsx.ColorCache.getColors8bit9990Values(b)))}function updateVRAMSize(){var a=3&register[8];a<2&&console.warn("Unsupported: V9990 Setting VRAM size < 512K !:",a)}function paletteRAMWrite(a,b){b!==paletteRAM[a]&&(paletteRAM[a]=b,updatePaletteValue(a>>2))}function registerWrite(a,b){var c=register[a]^b;switch(register[a]=b&REG_WRITE_MASK[a],a){case 0:case 1:case 2:updateVRAMWritePointer(a);break;case 3:case 4:updateVRAMReadPointer();break;case 5:updateVRAMReadPointer(),self.input60();break;case 6:240&c?updateMode():195&c?updateType():12&c&&updateImageSize();break;case 7:8&c&&updateVideoStandardSoft(),65&c?updateMode():2&c&&updateRenderMetrics();break;case 8:192&c&&(dispAndSpritesUpdatePending=!0),32&c&&updateYSEnabled(),3&c&&updateVRAMSize();break;case 9:7&c&&updateIRQ();break;case 10:c&&updateHorizontalIntLine();break;case 11:3&c&&updateHorizontalIntLine();break;case 12:15&c&&updateHorizontalIntX();break;case 13:224&c&&updateType(),16&c&&updatePalettePointerReadInc(),15&c&&updatePaletteOffsets();break;case 14:updatePalettePointer();break;case 15:63&c&&updateBackdropColor();break;case 16:15&c&&(horizontalAdjust=(15&b^7)-7),240&c&&(verticalAdjust=(b>>>4^7)-7,updateSignalMetrics(!1));break;case 17:updateScrollYLow();break;case 18:31&c&&(scrollYHiUpdatePending=!0),192&c&&updateScrollYMax();break;case 19:case 20:c&&updateScrollX();break;case 21:updateScrollYBLow();break;case 22:1&c&&(scrollYBHiUpdatePending=!0),192&c&&updatePlanesEnabled();break;case 23:case 24:c&&updateScrollXB();break;case 25:15&c&&updateSpritePattAddress();break;case 26:break;case 27:15&c&&updatePriorities();break;case 28:15&c&&updatePaletteOffsetCursor();break;case 52:commandProcessor.startCommand(b)}}function updateAllPaletteValues(){for(var a=63;a>=0;--a)updatePaletteValue(a)}function updatePaletteValue(a){var b=a<<2,c=ys16BitColorMask&((128&paletteRAM[b])<<8|(31&paletteRAM[b+1])<<10|(31&paletteRAM[b])<<5|31&paletteRAM[b+2]),d=colors16bitValues[c];paletteValuesReal[a]=d,debugModeSpriteHighlight&&(d&=DEBUG_DIM_ALPHA_MASK),paletteValues[a]=d,a===backdropColor&&updateBackdropValue()}function updateSynchronization(){pulldown=1===vSynchMode?videoStandard.pulldowns[machine.getVideoClockSocket().getVSynchNativeFrequency()]||videoStandard.pulldowns.TIMER:videoStandard.pulldowns.TIMER}function triggerVerticalInterrupt(){1&interruptFlags||(interruptFlags|=1,updateIRQ())}function triggerHorizontalInterrupt(){2&interruptFlags||(interruptFlags|=2,updateIRQ())}function updateIRQ(){register[9]&interruptFlags?cpu.setINTChannel(1,0):cpu.setINTChannel(1,1)}function updateMode(a){var b;switch(register[6]>>6){case 3:b=modes.SBY;break;case 0:b=modes.P1;break;case 1:b=modes.P2;break;case 2:switch(1&systemControl){case 0:switch((48&register[6])>>4){case 0:b=modes.B1;break;case 1:b=modes.B3;break;case 2:switch(65&register[7]){case 1:b=modes.B5;break;case 65:b=modes.B6;break;case 0:case 64:b=modes.B7}}break;case 1:switch((48&register[6])>>4){case 0:b=modes.B0;break;case 1:b=modes.B2;break;case 2:b=modes.B4}}}modeData=b||modes.SBY,updateType(),updateSpritePattAddress(),updateLineActiveType(),updateSignalMetrics(!1),updateRenderMetrics(a),updateVRAMInterleaving()}function updateType(){var a;switch(register[6]>>6){case 3:a=types.SBY;break;case 0:a=types.PP1;break;case 1:a=types.PP2;break;case 2:switch(3&register[6]){case 0:a=types.BP2;break;case 1:a=types.BP4;break;case 3:a=types.BD16;break;case 2:switch(register[13]>>6){case 0:a=types.BP6;break;case 1:a=types.BD8;break;case 2:case 3:switch(register[13]>>5){case 4:a=types.BYJK;break;case 5:a=types.BYJKP;break;case 6:a=types.BYUV;break;case 7:a=types.BYUVP}}}}typeData=a||types.SBY,updateImageSize()}function updateImageSize(){modeData===modes.P1?(imageWidth=256,imageHeight=2048):modeData===modes.P2?(imageWidth=512,imageHeight=2048):(imageWidth=256<<((12&register[6])>>2),imageHeight=VRAM_SIZE/(imageWidth*typeData.bpp>>3)),updateScrollYMax(),commandProcessor.setV9990ModeData(modeData,typeData,imageWidth,imageHeight)}function updateScrollYLow(){scrollYOffset=7936&scrollYOffset|register[17],scrollYOffsetFrame=currentScanline>frameStartingActiveScanline?scrollYOffset-(currentScanline-frameStartingActiveScanline):scrollYOffset,scrollYHiUpdatePending=!0}function updateScrollYHigh(){scrollYOffsetFrame=scrollYOffset=(31&register[18])<<8|255&scrollYOffset,scrollYHiUpdatePending=!1}function updateScrollX(){scrollXOffset=register[19]|register[20]<<3}function updateScrollYMax(){scrollYMax=128&register[18]?511:64&register[18]?255:modeData===modes.P1||modeData===modes.P2?511:imageHeight-1}function updateScrollYBLow(){scrollYBOffset=256&scrollYBOffset|register[21],scrollYBOffsetFrame=currentScanline>frameStartingActiveScanline?scrollYBOffset-(currentScanline-frameStartingActiveScanline):scrollYBOffset,scrollYBHiUpdatePending=!0}function updateScrollYBHigh(){scrollYBOffsetFrame=scrollYBOffset=(1&register[22])<<8|255&scrollYBOffset,scrollYBHiUpdatePending=!1}function updateScrollXB(){scrollXBOffset=register[23]|register[24]<<3}function updatePlanesEnabled(){planeAEnabled=0==(128&register[22]),planeBEnabled=0==(64&register[22])}function updatePriorities(){priBYLine=(register[27]>>2&3)<<6,0===priBYLine&&(priBYLine=256),0===(priBXCol=(3&register[27])<<6)&&(priBXCol=256)}function updateSpritePattAddress(){spritePattAddress=modeData===modes.P1?(14&register[25])<<14:(15&register[25])<<15}function updateHorizontalIntLine(){horizontalIntLine=(3&register[11])<<8|register[10]}function updateHorizontalIntX(){debugMode&&(15&register[12])>0&&logInfo("Unsupported: V9990 Horizontal INT X > 0 specified!")}function updateVideoStandardSoft(){var a=0!=(8&register[7]);machine.setVideoStandardSoft(a?wmsx.VideoStandard.PAL:wmsx.VideoStandard.NTSC)}function updateSignalMetrics(a){signalActiveHeight=modeData.height;var b=8*modeData.hasBorders,c=verticalAdjust;startingVisibleTopBorderScanline=16-(16-b),startingActiveScanline=startingVisibleTopBorderScanline+b+c,startingInvisibleScanline=startingActiveScanline+signalActiveHeight+b-c,finishingScanline=frameVideoStandard.totalHeight,a&&(frameStartingActiveScanline=startingActiveScanline)}function updateRenderMetrics(a){var b,c,d,e=!1,f=!1;b=modeData.width+8*modeData.hasBorders*2*modeData.pixelWidthDiv,d=modeData.allowIL&&2&register[7]?2:1,c=(modeData.height+8*modeData.hasBorders*2)*d,renderMetricsUpdatePending=!1,b===renderWidth&&c===renderHeight||(b!==renderWidth&&(a?((currentScanline>=startingVisibleTopBorderScanline||b>renderWidth)&&(f=!0),renderWidth=b,e=!0):renderMetricsUpdatePending=!0),c!==renderHeight&&(a?((currentScanline>=startingVisibleTopBorderScanline||c>renderHeight)&&(f=!0),renderHeight=c,e=!0):renderMetricsUpdatePending=!0),f&&cleanFrameBuffer(),e&&self.refreshDisplayMetrics())}function enterActiveDisplay(){status&=-65,dispAndSpritesUpdatePending&&updateDispAndSpritesEnabled(),scrollYHiUpdatePending&&updateScrollYHigh(),scrollYBHiUpdatePending&&updateScrollYBHigh(),setActiveDisplay()}function setActiveDisplay(){renderLine=renderLineActive}function enterBorderDisplay(){status|=64,triggerVerticalInterrupt(),setBorderDisplay()}function setBorderDisplay(){renderLine=renderLineBackdrop}function updateDispAndSpritesEnabled(){var a=0!=(128&register[8])
;dispEnabled!==a&&(a&&cartridge.v9990DisplayEnabled(),dispEnabled=a),spritesEnabled=0==(64&register[8]),updateLineActiveType(),commandProcessor.setV9990DisplayAndSpritesEnabled(dispEnabled,spritesEnabled),dispAndSpritesUpdatePending=!1}function updateLineActiveType(){var a=renderLine===renderLineActive;renderLineActive=modeData===modes.SBY?renderLineModeSBY:dispEnabled?modeData.renderLine:renderLineBackdrop,a&&(renderLine=renderLineActive)}function updateBackdropColor(){backdropColor=63&register[15],updateBackdropValue()}function updateBackdropValue(){var a=debugModePatternInfo?debugBackdropValue:paletteValuesReal[backdropColor];backdropValue!==a&&(backdropValue=a,backdropCacheUpdatePending=!0)}function updateBackdropLineCache(){wmsx.Util.arrayFill(backdropLineCache,backdropValue),backdropCacheUpdatePending=!1}function renderLineBackdrop(){backdropCacheUpdatePending&&updateBackdropLineCache(),frameBackBuffer.set(backdropLineCache,bufferPosition),bufferPosition+=bufferLineAdvance}function paintBackdrop8(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop16(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop32(a){frameBackBuffer[a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue,frameBackBuffer[++a]=backdropValue}function paintBackdrop64(a){backdropCacheUpdatePending&&updateBackdropLineCache(),frameBackBuffer.set(backdrop64,a)}function paintBackdrop256(a){backdropCacheUpdatePending&&updateBackdropLineCache(),frameBackBuffer.set(backdrop256,a)}function paintBackdrop512(a){backdropCacheUpdatePending&&updateBackdropLineCache(),frameBackBuffer.set(backdrop512,a)}function renderLineModeSBY(){renderLineTypeSBY(bufferPosition),bufferPosition+=bufferLineAdvance}function renderLineModeP1(){renderLineTypePP1(bufferPosition+horizontalAdjust+8),paintBackdrop16(bufferPosition+horizontalAdjust-8),paintBackdrop16(bufferPosition+horizontalAdjust+8+256),bufferPosition+=bufferLineAdvance}function renderLineModeP2(){renderLineTypePP2(bufferPosition+(horizontalAdjust<<1)+16),paintBackdrop32(bufferPosition+(horizontalAdjust<<1)-16),paintBackdrop32(bufferPosition+(horizontalAdjust<<1)+16+512),bufferPosition+=bufferLineAdvance}function renderLineModeB0(){typeData.renderLine(bufferPosition+horizontalAdjust,192),paintBackdrop8(bufferPosition+horizontalAdjust-8),paintBackdrop8(bufferPosition+horizontalAdjust+192),bufferPosition+=bufferLineAdvance}function renderLineModeB1(){typeData.renderLine(bufferPosition+horizontalAdjust+8,256),paintBackdrop16(bufferPosition+horizontalAdjust-8),paintBackdrop16(bufferPosition+horizontalAdjust+8+256),bufferPosition+=bufferLineAdvance}function renderLineModeB2(){typeData.renderLine(bufferPosition+horizontalAdjust,384),paintBackdrop8(bufferPosition+horizontalAdjust-8),paintBackdrop8(bufferPosition+horizontalAdjust+384),bufferPosition+=bufferLineAdvance}function renderLineModeB3(){typeData.renderLine(bufferPosition+(horizontalAdjust<<1)+16,512),paintBackdrop32(bufferPosition+(horizontalAdjust<<1)-16),paintBackdrop32(bufferPosition+(horizontalAdjust<<1)+16+512),bufferPosition+=bufferLineAdvance}function renderLineModeB4(){typeData.renderLine(bufferPosition+(horizontalAdjust<<1),768),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)-16),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)+768),bufferPosition+=bufferLineAdvance}function renderLineModeB5(){typeData.renderLine(bufferPosition+(horizontalAdjust<<1),640),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)-16),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)+640),bufferPosition+=bufferLineAdvance}function renderLineModeB6(){typeData.renderLine(bufferPosition+(horizontalAdjust<<1),640),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)-16),paintBackdrop16(bufferPosition+(horizontalAdjust<<1)+640),bufferPosition+=bufferLineAdvance}function renderLineModeB7(){typeData.renderLine(bufferPosition+(horizontalAdjust<<2)+32,1024),paintBackdrop64(bufferPosition+(horizontalAdjust<<2)-32),paintBackdrop64(bufferPosition+(horizontalAdjust<<2)+32+1024),bufferPosition+=bufferLineAdvance}function renderLineTypeSBY(a){frameBackBuffer.set(standByLineCache,a)}function renderLineTypePP1(a){paintBackdrop256(a),determineSpritesOnLine(currentScanline-frameStartingActiveScanline,261632);var b=currentScanline-frameStartingActiveScanline<priBYLine;b?renderLineTypePP1B(a):renderLineTypePP1A(a),renderSpritesLine(a,currentScanline-frameStartingActiveScanline,32,256,261632),b?renderLineTypePP1A(a):renderLineTypePP1B(a),renderSpritesLine(a,currentScanline-frameStartingActiveScanline,0,256,261632)}function renderLineTypePP1A(a){if(planeAEnabled){var b,c,d,e,f,g,h,i,j,k,l;e=511&scrollXOffset,b=a-(7&e),c=currentScanline-frameStartingActiveScanline+scrollYOffsetFrame&scrollYMax,d=7&c,f=507904+(c>>3<<6<<1),g=e>>3<<1,h=0|d<<7;for(var m=7&e?33:32;m>0;--m)i=vram[f+g]|vram[f+g+1]<<8,g=g+2&127,j=h+(i>>5<<10|(31&i)<<2),k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b}}function renderLineTypePP1B(a){if(planeBEnabled){var b,c,d,e,f,g,h,i,j,k,l;e=511&scrollXBOffset,b=a-(7&e),c=currentScanline-frameStartingActiveScanline+scrollYBOffsetFrame&511,d=7&c,f=516096+(c>>3<<6<<1),g=e>>3<<1,h=262144|d<<7;for(var m=7&e?33:32;m>0;--m)i=vram[f+g]|vram[f+g+1]<<8,g=g+2&127,j=h+(i>>5<<10|(31&i)<<2),k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,k=vram[j],++j,l=k>>4,
l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b}}function renderLineTypePP2(a){var b,c,d,e,f,g,h,i,j,k,l;if(paintBackdrop512(a),determineSpritesOnLine(currentScanline-frameStartingActiveScanline,507392),renderSpritesLine(a,currentScanline-frameStartingActiveScanline,32,512,507392),planeAEnabled){e=1023&scrollXOffset,b=a-(7&e),c=currentScanline-frameStartingActiveScanline+scrollYOffsetFrame&scrollYMax,d=7&c,f=507904+(c>>3<<7<<1),g=e>>3<<1,h=0|d<<8;for(var m=7&e?65:64;m>0;--m)i=vram[f+g]|vram[f+g+1]<<8,g=g+2&255,j=h+(i>>6<<11|(63&i)<<2),k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetA|l]),++b,k=vram[j],++j,l=k>>4,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b,l=15&k,l>0&&(frameBackBuffer[b]=paletteValues[paletteOffsetB|l]),++b}renderSpritesLine(a,currentScanline-frameStartingActiveScanline,0,512,507392)}function determineSpritesOnLine(a,b){if(spritesOnLineCount=0,spritesEnabled&&!debugModeSpritesHidden)for(var c=0;c<125;++c,b+=4){var d=vram[b],e=a-d-1&255;if(!(e>=16)&&(spritesOnLine[spritesOnLineCount]=c,++spritesOnLineCount>=16&&spriteDebugModeLimit))break}}function renderSpritesLine(a,b,c,d,e){for(var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=spritesOnLineCount-1;o>=0;--o)f=spritesOnLine[o],g=e+(f<<2),(48&(j=vram[g+3]))===c&&(k=vram[g],l=b-k-1&255,((m=vram[g+2]|(3&j)<<8)<d||m>=1008)&&(h=(192&j)>>2,i=debugModeSpriteInfoNumbers?f<<2:vram[g+1],n=256===d?spritePattAddress+((i>>4<<11)+((15&i)<<3))+(l<<7):spritePattAddress+((i>>5<<12)+((31&i)<<3))+(l<<8),m>=d&&(m-=1024),paintSprite(a+m,n,h)))}function paintSprite(a,b,c){for(var d=0,e=0,f=8;f>0;--f)d=vram[b],++b,e=d>>4,e>0&&(frameBackBuffer[a]=paletteValuesReal[c|e]),++a,e=15&d,e>0&&(frameBackBuffer[a]=paletteValuesReal[c|e]),++a}function renderLineTypeBYUV(a,b){colorsYUVValues||(colorsYUVValues=wmsx.ColorCache.getColorsYUVValues()),renderLineTypeBYxx(colorsYUVValues,a,b)}function renderLineTypeBYUVP(a,b){colorsYUVValues||(colorsYUVValues=wmsx.ColorCache.getColorsYUVValues()),renderLineTypeBYxxP(colorsYUVValues,a,b)}function renderLineTypeBYJK(a,b){colorsYJKValues||(colorsYJKValues=wmsx.ColorCache.getColorsYJKValues()),renderLineTypeBYxx(colorsYJKValues,a,b)}function renderLineTypeBYJKP(a,b){colorsYJKValues||(colorsYJKValues=wmsx.ColorCache.getColorsYJKValues()),renderLineTypeBYxxP(colorsYJKValues,a,b)}function renderLineTypeBYxx(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o;e=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,i=e*imageWidth,g=imageWidth-1,j=-4&scrollXOffset&g,h=3&scrollXOffset,f=c+(h?4:0),d=b-h;for(var p=f;p>0;p-=4)k=vram[i+j],l=vram[i+j+1],m=vram[i+j+2],n=vram[i+j+3],j=j+4&g,o=(7&n)<<9|(7&m)<<6|(7&l)<<3|7&k,frameBackBuffer[d]=a[(248&k)<<9|o],++d,frameBackBuffer[d]=a[(248&l)<<9|o],++d,frameBackBuffer[d]=a[(248&m)<<9|o],++d,frameBackBuffer[d]=a[(248&n)<<9|o],++d;renderCursorsLine(b,currentScanline-frameStartingActiveScanline,c)}function renderLineTypeBYxxP(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o;e=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,i=e*imageWidth,g=imageWidth-1,j=-4&scrollXOffset&g,h=3&scrollXOffset,f=c+(h?4:0),d=b-h;for(var p=c>512?-33&paletteOffsetB:paletteOffsetB,q=c>512?32|paletteOffsetB:paletteOffsetB,r=f;r>0;r-=4)k=vram[i+j],l=vram[i+j+1],m=vram[i+j+2],n=vram[i+j+3],j=j+4&g,o=(7&n)<<9|(7&m)<<6|(7&l)<<3|7&k,frameBackBuffer[d]=8&k?paletteValues[p|k>>4]:a[(248&k)<<9|o],++d,frameBackBuffer[d]=8&l?paletteValues[q|l>>4]:a[(248&l)<<9|o],++d,frameBackBuffer[d]=8&m?paletteValues[p|m>>4]:a[(248&m)<<9|o],++d,frameBackBuffer[d]=8&n?paletteValues[q|n>>4]:a[(248&n)<<9|o],++d;renderCursorsLine(b,currentScanline-frameStartingActiveScanline,c)}function renderLineTypeBD16(a,b){var c,d,e,f,g,h,i;d=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,g=d*(imageWidth<<1),f=(imageWidth<<1)-1,h=modeData.width>256?(-2&scrollXOffset)<<1&f:scrollXOffset<<1&f,e=b<<1,c=a;for(var j=e;j>0;j-=2)i=ys16BitColorMask&(vram[g+h]|vram[g+h+1]<<8),h=h+2&f,frameBackBuffer[c]=colors16bitValues[i],++c;renderCursorsLine(a,currentScanline-frameStartingActiveScanline,b)}function renderLineTypeBD8(a,b){var c,d,e,f,g,h,i;colors8bitValues||(colors8bitValues=wmsx.ColorCache.getColors8bit9990Values(32767!==ys16BitColorMask)),d=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,g=d*imageWidth,f=imageWidth-1,h=scrollXOffset&f,e=b,c=a;for(var j=e;j>0;--j)i=vram[g+h],h=h+1&f,frameBackBuffer[c]=colors8bitValues[i],++c;renderCursorsLine(a,currentScanline-frameStartingActiveScanline,b)}function renderLineTypeBP6(a,b){var c,d,e,f,g,h,i;d=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,g=d*imageWidth,f=imageWidth-1,h=scrollXOffset&f,e=b,c=a;for(var j=e;j>0;--j)i=vram[g+h],h=h+1&f,frameBackBuffer[c]=paletteValues[63&i],++c;renderCursorsLine(a,currentScanline-frameStartingActiveScanline,b)}function renderLineTypeBP4(a,b){var c,d,e,f,g,h,i,j;d=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,h=d*(imageWidth>>1),f=(imageWidth>>1)-1,i=scrollXOffset>>1&f,g=1&scrollXOffset,e=(b>>1)+g,c=a-g;for(var k=b>512?-33&paletteOffsetB:paletteOffsetB,l=b>512?32|paletteOffsetB:paletteOffsetB,m=e;m>0;--m)j=vram[h+i],i=i+1&f,frameBackBuffer[c]=paletteValues[k|j>>4],++c,frameBackBuffer[c]=paletteValues[l|15&j],++c;renderCursorsLine(a,currentScanline-frameStartingActiveScanline,b)}function renderLineTypeBP2(a,b){var c,d,e,f,g,h,i,j;d=(currentScanline-frameStartingActiveScanline+scrollYOffsetFrame<<vramEOLineShift)+vramEOLineAdd&scrollYMax,h=d*(imageWidth>>2),f=(imageWidth>>2)-1,i=scrollXOffset>>2&f,g=3&scrollXOffset,e=(b>>2)+(g?1:0),c=a-g;for(var k=b>512?-33&paletteOffset:paletteOffset,l=b>512?32|paletteOffset:paletteOffset,m=e;m>0;--m)j=vram[h+i],i=i+1&f,frameBackBuffer[c]=paletteValues[k|j>>6],++c,frameBackBuffer[c]=paletteValues[l|j>>4&3],++c,frameBackBuffer[c]=paletteValues[k|j>>2&3],++c,frameBackBuffer[c]=paletteValues[l|3&j],++c;renderCursorsLine(a,currentScanline-frameStartingActiveScanline,b)}function renderCursorsLine(a,b,c){if(spritesEnabled&&!debugModeSpritesHidden)for(var d=0,e=!1,f=0,g=0,h=0,i=0,j=0,k=0,l=523784,m=1;m>=0;--m,l-=8)h=vram[l]|(1&vram[l+2])<<8,(i=b-h-1&511)>=32||0==(16&(g=vram[l+6]))&&((j=vram[l+4]|(3&g)<<8)<c||j>=992)&&(d=(192&g)>>6,e=0!=(32&g),f=debugModeSpriteInfoNumbers?m<<2:m,k=524032+(i<<2)+(f<<7),j>=c&&(j-=1024),paintCursor(a+j,k,d,e))}function paintCursor(a,b,c,d){var e=0,f=0;if(0!==c){f=paletteValuesReal[paletteOffsetCursor|c],d&&(f=4278190080&f|16777215&~f);for(var g=4;g>0;--g)e=vram[b],++b,128&e&&(frameBackBuffer[a]=f),++a,64&e&&(frameBackBuffer[a]=f),++a,32&e&&(frameBackBuffer[a]=f),++a,16&e&&(frameBackBuffer[a]=f),++a,8&e&&(frameBackBuffer[a]=f),++a,4&e&&(frameBackBuffer[a]=f),++a,2&e&&(frameBackBuffer[a]=f),++a,1&e&&(frameBackBuffer[a]=f),++a}else if(d)for(g=4;g>0;--g)e=vram[b],++b,128&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,64&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,32&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,16&e&&(f=frameBackBuffer[a],
frameBackBuffer[a]=4278190080&f|16777215&~f),++a,8&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,4&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,2&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a,1&e&&(f=frameBackBuffer[a],frameBackBuffer[a]=4278190080&f|16777215&~f),++a}function cleanFrameBuffer(){wmsx.Util.arrayFill(frameBackBuffer,backdropValue)}function refresh(){videoSignal.newFrame(frameCanvas,0,0,refreshWidth,refreshHeight),refreshWidth=refreshHeight=0}function beginFrame(){if(framePulldown!==pulldown&&(frameVideoStandard=videoStandard,framePulldown=pulldown,updateSignalMetrics(!1)),renderMetricsUpdatePending&&updateRenderMetrics(!0),status^=2,modeData.allowIL&&2&register[7]){bufferLineAdvance=PAINT_WIDTH<<1;var a=0!=(4&register[7]);vramEOLineShift=a?1:0,2&status?(bufferPosition=PAINT_WIDTH<<1,vramEOLineAdd=a?1:0):(bufferPosition=PAINT_WIDTH,vramEOLineAdd=0)}else bufferLineAdvance=PAINT_WIDTH,bufferPosition=PAINT_WIDTH,vramEOLineShift=0,vramEOLineAdd=0;currentScanline=0,frameStartingActiveScanline=startingActiveScanline,currentScanline>=frameStartingActiveScanline&&enterActiveDisplay()}function finishFrame(){videoDisplayed&&(refreshWidth=renderWidth,refreshHeight=renderHeight,frameContext.putImageData(frameImageData,0,-1,0,1,refreshWidth,refreshHeight)),++frame,beginFrame()}function updateVRAMInterleaving(){vramInterleaving!==(modeData!==modes.P1)&&(vramInterleaving=modeData!==modes.P1,vramInterleaving?self.vramEnterInterleaving():self.vramExitInterleaving())}function initRAM(){vramInterleaving=!1;for(var a=0;a<VRAM_SIZE;a+=1024)wmsx.Util.arrayFill(vram,0,a,a+512),wmsx.Util.arrayFill(vram,255,a+512,a+1024)}function initRegisters(){wmsx.Util.arrayFill(register,0),register[7]=videoStandard===wmsx.VideoStandard.PAL?8:0}function initFrameResources(a){(!frameCanvas||!frameContextUsingAlpha&&a)&&(frameContextUsingAlpha=!!a,frameCanvas=document.createElement("canvas"),frameCanvas.width=PAINT_WIDTH,frameCanvas.height=wmsx.V9990.SIGNAL_MAX_HEIGHT+1,frameContext=frameCanvas.getContext("2d",{alpha:frameContextUsingAlpha,antialias:!1}),frameImageData||(frameImageData=frameContext.createImageData(frameCanvas.width,frameCanvas.height+1+1),frameBackBuffer=new Uint32Array(frameImageData.data.buffer,0,frameCanvas.width*frameCanvas.height),backdropLineCache=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*frameCanvas.height*4,frameCanvas.width),standByLineCache=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*(frameCanvas.height+1)*4,272),backdrop64=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*frameCanvas.height*4,64),backdrop256=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*frameCanvas.height*4,256),backdrop512=new Uint32Array(frameImageData.data.buffer,frameCanvas.width*frameCanvas.height*4,512),wmsx.Util.arrayFill(standByLineCache,standByValue)))}function initColorCaches(){colors16bitValues=wmsx.ColorCache.getColors16bitValues(),colors8bitValues=void 0,colorsYUVValues=void 0,colorsYJKValues=void 0}function initColorPalette(){wmsx.Util.arrayFill(paletteRAM,0);for(var a=0;a<64;++a)paletteValuesReal[a]=paletteValues[a]=solidBlackValue}function initDebugPatternTables(){for(var a=[["111","101","101","101","111"],["110","010","010","010","111"],["111","001","111","100","111"],["111","001","111","001","111"],["101","101","111","001","001"],["111","100","111","001","111"],["111","100","111","101","111"],["111","001","001","001","001"],["111","101","111","101","111"],["111","101","111","001","001"],["110","001","111","101","111"],["100","100","111","101","110"],["000","111","100","100","111"],["001","001","111","101","111"],["110","101","111","100","011"],["011","100","110","100","100"]],b=DEBUG_PAT_DIGI6_TABLE_ADDRESS,c=DEBUG_PAT_DIGI8_TABLE_ADDRESS,d=DEBUG_PAT_DIGI16_TABLE_ADDRESS,e=DEBUG_PAT_BLOCK_TABLE_ADDRESS,f=0;f<256;f++){for(var g=f/16|0,h=f%16,i=0;i<5;i++)vram[b++]=parseInt(a[g][i]+a[h][i]+"00",2),vram[c++]=parseInt(a[g][i]+"0"+a[h][i]+"0",2);for(vram[b++]=vram[c++]=parseInt("00000000",2),vram[b++]=vram[c++]=parseInt("01111100",2),vram[b++]=vram[c++]=parseInt("00000000",2),vram[d++]=parseInt("11111111",2),i=0;i<4;i++)vram[d++]=parseInt("10000000",2);for(i=0;i<5;i++)vram[d++]=parseInt("1000"+a[g][i]+"0",2);for(i=0;i<5;i++)vram[d++]=parseInt("10000000",2);for(i=0;i<2;i++)vram[d++]=parseInt("11111111",2);for(i=0;i<4;i++)vram[d++]=parseInt("00000001",2);for(i=0;i<5;i++)vram[d++]=parseInt("0"+a[h][i]+"0001",2);for(i=0;i<5;i++)vram[d++]=parseInt("00000001",2);vram[d++]=parseInt("11111111",2)}vram[e]=vram[e+7]=0,vram[e+1]=vram[e+2]=vram[e+3]=vram[e+4]=vram[e+5]=vram[e+6]=126}function logInfo(a){console.log("V9990 "+a+", currentScanLine: "+currentScanline+", activeRenderScanline: "+(currentScanline-frameStartingActiveScanline))}var self=this;this.connect=function(a,b){machine=a,vdp=machine.vdp,cpu=machine.cpu,cartridge=b,machine.vdp.connectSlave(this),machine.bus.connectOutputDevice(96,this.output60),machine.bus.connectInputDevice(96,this.input60),machine.bus.connectOutputDevice(97,this.output61),machine.bus.connectInputDevice(97,this.input61),machine.bus.connectOutputDevice(98,this.output62),machine.bus.connectInputDevice(98,this.input62),machine.bus.connectOutputDevice(99,this.output63),machine.bus.connectInputDevice(99,this.input63),machine.bus.connectOutputDevice(100,this.output64),machine.bus.connectInputDevice(100,wmsx.DeviceMissing.inputPortIgnored),machine.bus.connectOutputDevice(101,wmsx.DeviceMissing.outputPortIgnored),machine.bus.connectInputDevice(101,this.input65),machine.bus.connectOutputDevice(102,this.output66),machine.bus.connectInputDevice(102,this.input66),machine.bus.connectOutputDevice(103,this.output67),machine.bus.connectInputDevice(103,wmsx.DeviceMissing.inputPortIgnored),machine.bus.connectOutputDevice(104,this.output68),machine.bus.connectInputDevice(104,wmsx.DeviceMissing.inputPortIgnored),machine.bus.connectOutputDevice(105,this.output69),machine.bus.connectInputDevice(105,this.input69),machine.bus.connectOutputDevice(106,this.output6a),machine.bus.connectInputDevice(106,wmsx.DeviceMissing.inputPortIgnored),machine.bus.connectOutputDevice(107,this.output6b),machine.bus.connectInputDevice(107,this.input6b),updateIRQ()},this.disconnect=function(a){machine=vdp=cpu=cartridge=void 0,a.vdp.connectSlave(void 0),a.bus.disconnectInputDevice(96,this.input60),a.bus.disconnectOutputDevice(96,this.output60),a.bus.disconnectInputDevice(97,this.input61),a.bus.disconnectOutputDevice(97,this.output61),a.bus.disconnectInputDevice(98,this.input62),a.bus.disconnectOutputDevice(98,this.output62),a.bus.disconnectInputDevice(99,this.input63),a.bus.disconnectOutputDevice(99,this.output63),a.bus.disconnectInputDevice(100,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectOutputDevice(100,this.output64),a.bus.disconnectInputDevice(101,this.input65),a.bus.disconnectOutputDevice(101,wmsx.DeviceMissing.outputPortIgnored),a.bus.disconnectInputDevice(102,this.input66),a.bus.disconnectOutputDevice(102,this.output66),a.bus.disconnectInputDevice(103,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectOutputDevice(103,this.output67)},this.powerOn=function(){initRAM(),initColorPalette(),this.reset()},this.powerOff=function(){videoSignal.signalOff()},this.setVideoStandard=function(a){videoStandard=a,updateSynchronization()},this.setVSynchMode=function(a){vSynchMode=a,updateSynchronization()},this.getVideoSignal=function(){return videoSignal},this.input60=function(){var a=vramReadData;return vramReadData=vram[vramPointerRead],vramPointerReadInc&&++vramPointerRead>VRAM_LIMIT&&(vramPointerRead&=VRAM_LIMIT),a},this.output60=function(a){softResetON||(vram[vramPointerWrite]=a,vramPointerWriteInc&&++vramPointerWrite>VRAM_LIMIT&&(vramPointerWrite&=VRAM_LIMIT))},this.input61=function(){if(softResetON)return paletteRAM[0]
;if(3==(3&palettePointer))return palettePointerReadInc&&(palettePointer&=252),0;var a=paletteRAM[palettePointer];return palettePointerReadInc&&(2==(3&palettePointer)?palettePointer=palettePointer+2&255:++palettePointer),a},this.output61=function(a){return softResetON?paletteRAMWrite(0,0):3==(3&palettePointer)?palettePointer&=-4:(a&=0==(3&palettePointer)?159:31,paletteRAMWrite(palettePointer,a),void(2==(3&palettePointer)?palettePointer=palettePointer+2&255:++palettePointer))},this.input62=function(){return commandProcessor.cpuRead()},this.output62=function(a){commandProcessor.cpuWrite(a)},this.input63=function(){var a=register[registerSelect]|REG_READ_OR[registerSelect];return registerSelectReadInc&&++registerSelect>63&&(registerSelect&=63),a},this.output63=function(a){softResetON||registerWrite(registerSelect,a),registerSelectWriteInc&&++registerSelect>63&&(registerSelect&=63)},this.output64=function(a){softResetON&&(a=0),registerSelect=63&a,registerSelectWriteInc=0==(128&a),registerSelectReadInc=0==(64&a)},this.input65=function(){return commandProcessor.updateStatus(),status},this.input66=function(){return interruptFlags},this.output66=function(a){0!=(7&a)&&(interruptFlags&=~a,updateIRQ())},this.output67=function(a){var b=systemControl^a;systemControl=a,2&b&&(softResetON=0!=(2&systemControl))&&softReset(),1&b&&(status=-5&status|(1&systemControl)<<2,updateMode())},this.output68=function(a){kanjiPort1Address=129024&kanjiPort1Address|(63&a)<<5},this.output69=function(a){kanjiPort1Address=(63&a)<<11|2016&kanjiPort1Address},this.input69=function(){var a=self.readKanji(kanjiPort1Address);return kanjiPort1Address=131040&kanjiPort1Address|kanjiPort1Address+1&31,a},this.output6a=function(a){kanjiPort2Address=260096&kanjiPort2Address|(63&a)<<5},this.output6b=function(a){kanjiPort2Address=131072|(63&a)<<11|2016&kanjiPort2Address},this.input6b=function(){var a=self.readKanji(kanjiPort2Address);return kanjiPort2Address=262112&kanjiPort2Address|kanjiPort2Address+1&31,a},this.readKanji=function(a){var b=wmsx.CartridgeKanjiFont.connectedInstance;return b?b.readKanji(a):255},this.setTurboMulti=function(a){commandProcessor.setTurboMulti(a)},this.getVDPTurboMulti=function(){return commandProcessor.getVDPTurboMulti()},this.setDefaults=function(){self.setDebugMode(STARTING_DEBUG_MODE),self.setSpriteDebugMode(STARTING_SPRITES_DEBUG_MODE)},this.videoSignalDisplayStateUpdate=function(a,b){videoDisplayed=a,superimposeActive!==b&&(superimposeActive=b,superimposeActive&&initFrameResources(!0),updateYSEnabled())},this.refreshDisplayMetrics=function(){videoSignal.setDisplayMetrics(renderWidth,renderHeight)},this.resetOutputAutoMode=function(){cartridge&&cartridge.resetOutputAutoMode()},this.reset=function(){systemControl=0,status=0,softResetON=!1,registerSelect=0,registerSelectReadInc=!0,registerSelectWriteInc=!0,kanjiPort1Address=0,kanjiPort2Address=131072,softReset(),frame=cycles=lastBUSCyclesComputed=0,frameVideoStandard=videoStandard,framePulldown=pulldown,currentScanline=-1,beginFrame()},this.getVDPCycles=function(){return vdp.getVDPCycles()},this.getScreenText=function(){},this.setStatusTR=function(a){a?status|=128:status&=-129},this.setStatusBD=function(a){a?status|=16:status&=-17},this.setStatusCE=function(a){a?status|=1:status&=-2},this.setDebugMode=function(a){debugMode=(a+8)%8;var b=debugModeSpriteHighlight;debugModeSpriteHighlight=debugMode>=1&&debugMode<=3,debugModeSpriteInfo=2===debugMode||3===debugMode,debugModeSpriteInfoNumbers=2===debugMode,debugModeSpritesHidden=debugMode>=4;var c=debugModePatternInfo;debugModePatternInfo=debugMode>=5,debugModePatternInfoBlocks=6===debugMode,debugModePatternInfoNames=7===debugMode,b===debugModeSpriteHighlight&&c===debugModePatternInfo||updateAllPaletteValues(),debugModeSpriteHighlight&&initFrameResources(!0),updateLineActiveType(),updateSpritePattAddress()},this.setSpriteDebugMode=function(a){spriteDebugMode=a>=0?a%4:4+a,spriteDebugModeLimit=0===spriteDebugMode||2===spriteDebugMode},this.setColorAndPaletteMode=function(a,b){initColorCaches(),updateAllPaletteValues()},this.cycleEventRefresh=function(){refreshWidth&&refresh()},this.lineEventStartActiveDisplay=function(){status&=-33,currentScanline===frameStartingActiveScanline&&enterActiveDisplay(),currentScanline-frameStartingActiveScanline===horizontalIntLine&&triggerHorizontalInterrupt()},this.lineEventRenderLine=function(){videoDisplayed&&currentScanline>=startingVisibleTopBorderScanline&&currentScanline<startingInvisibleScanline&&renderLine()},this.lineEventEndActiveDisplay=function(){status|=32,currentScanline-frameStartingActiveScanline==signalActiveHeight-1&&enterBorderDisplay()},this.lineEventEnd=function(){++currentScanline>=finishingScanline&&finishFrame()},this.triggerCommandCompletionInterrupt=function(){4&interruptFlags||(interruptFlags|=4,updateIRQ())},this.vramEnterInterleaving=function(){for(var a=0,b=VRAM_SIZE>>1,c=vram.slice(0,b),d=0;d<VRAM_SIZE;d+=2,++a,++b)vram[d]=c[a],vram[d+1]=vram[b]},this.vramExitInterleaving=function(){for(var a=VRAM_SIZE>>1,b=0,c=a,d=vram.slice(a),e=0;e<a;e+=2,++b,++c)vram[b]=vram[e],vram[c]=vram[e+1];for(e=0;e<a;e+=2,++b,++c)vram[b]=d[e],vram[c]=d[e+1]};var LINE_WIDTH=wmsx.V9990.SIGNAL_MAX_WIDTH,PAINT_WIDTH=LINE_WIDTH+64,SPRITE_MAX_PRIORITY=9e15,DEBUG_DIM_ALPHA_MASK=1090519039,VRAM_LIMIT=wmsx.V9990.VRAM_LIMIT,VRAM_SIZE=VRAM_LIMIT+1,DEBUG_PAT_DIGI6_TABLE_ADDRESS=VRAM_SIZE,DEBUG_PAT_DIGI8_TABLE_ADDRESS=DEBUG_PAT_DIGI6_TABLE_ADDRESS+2048,DEBUG_PAT_DIGI16_TABLE_ADDRESS=DEBUG_PAT_DIGI8_TABLE_ADDRESS+2048,DEBUG_PAT_BLOCK_TABLE_ADDRESS=DEBUG_PAT_DIGI16_TABLE_ADDRESS+8192,VRAM_TOTAL_SIZE=DEBUG_PAT_BLOCK_TABLE_ADDRESS+8,STARTING_DEBUG_MODE=WMSX.DEBUG_MODE,STARTING_SPRITES_DEBUG_MODE=WMSX.SPRITES_DEBUG_MODE,REG_WRITE_MASK=[255,255,135,255,255,135,255,255,255,135,255,131,15,255,255,255,255,255,223,7,255,255,193,7,63,207,255,255,15,0,0,0,255,7,255,15,255,7,255,15,255,15,255,15,15,31,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0],REG_READ_OR=[255,255,255,255,255,255,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,255,255,255,255,255,255,255],frameCanvas,frameContext,frameImageData,frameBackBuffer,backdropLineCache,standByLineCache,backdrop64,backdrop256,backdrop512,frameContextUsingAlpha=!1,vram=new Uint8Array(VRAM_TOTAL_SIZE);this.vram=vram
;var frame=0,vSynchMode=0,videoStandard=wmsx.VideoStandard.NTSC,pulldown,bufferPosition=0,bufferLineAdvance=0,currentScanline=-1,cycles=0,lastBUSCyclesComputed=0,signalActiveHeight=0,finishingScanline=0,startingActiveScanline=0,frameStartingActiveScanline=0,startingVisibleTopBorderScanline=0,startingInvisibleScanline=0,frameVideoStandard=videoStandard,framePulldown,horizontalIntLine=0,status=0,interruptFlags=0,systemControl=0,softResetON=!1,registerSelect=0,registerSelectReadInc=!0,registerSelectWriteInc=!0,vramPointerRead=0,vramPointerWrite=0,vramPointerReadInc=!0,vramPointerWriteInc=!0,vramReadData=0,palettePointer=0,palettePointerReadInc=!0,paletteOffsetA=0,paletteOffsetB=0,paletteOffset=0,paletteOffsetCursor=0,ys16BitColorMask=32767,superimposeActive=!1,register=new Array(64),paletteRAM=new Array(256),modeData,typeData,imageWidth=0,imageHeight=0,vramInterleaving=!1,backdropColor=0,backdropCacheUpdatePending=!0,scrollXOffset=0,scrollYOffset=0,scrollYOffsetFrame=0,scrollXBOffset=0,scrollYBOffset=0,scrollYBOffsetFrame=0,scrollYMax=0,scrollYHiUpdatePending=!1,scrollYBHiUpdatePending=!1,planeAEnabled=!0,planeBEnabled=!0,priBYLine=256,priBXCol=256,verticalAdjust=0,horizontalAdjust=0,spritePattAddress=0,spritesOnLine=wmsx.Util.arrayFill(new Array(126),0),spritesOnLineCount=0,dispEnabled=!1,spritesEnabled=!0,dispAndSpritesUpdatePending=!1,renderMetricsUpdatePending=!1,renderWidth=wmsx.V9990.SIGNAL_START_WIDTH,renderHeight=wmsx.V9990.SIGNAL_START_HEIGHT,refreshWidth=0,refreshHeight=0,vramEOLineShift=0,vramEOLineAdd=0,modes={SBY:{name:"SBY",width:256,height:212,pixelWidthDiv:1,hasBorders:1,allowIL:!1,cmdTiming:0,renderLine:renderLineModeSBY},P1:{name:"P1",width:256,height:212,pixelWidthDiv:1,hasBorders:1,allowIL:!1,cmdTiming:2,renderLine:renderLineModeP1},P2:{name:"P2",width:512,height:212,pixelWidthDiv:2,hasBorders:1,allowIL:!1,cmdTiming:3,renderLine:renderLineModeP2},B0:{name:"B0",width:192,height:240,pixelWidthDiv:1,hasBorders:0,allowIL:!0,cmdTiming:1,renderLine:renderLineModeB0},B1:{name:"B1",width:256,height:212,pixelWidthDiv:1,hasBorders:1,allowIL:!0,cmdTiming:0,renderLine:renderLineModeB1},B2:{name:"B2",width:384,height:240,pixelWidthDiv:1,hasBorders:0,allowIL:!0,cmdTiming:1,renderLine:renderLineModeB2},B3:{name:"B3",width:512,height:212,pixelWidthDiv:2,hasBorders:1,allowIL:!0,cmdTiming:0,renderLine:renderLineModeB3},B4:{name:"B4",width:768,height:240,pixelWidthDiv:2,hasBorders:0,allowIL:!0,cmdTiming:1,renderLine:renderLineModeB4},B5:{name:"B5",width:640,height:400,pixelWidthDiv:2,hasBorders:0,allowIL:!1,cmdTiming:0,renderLine:renderLineModeB5},B6:{name:"B6",width:640,height:480,pixelWidthDiv:2,hasBorders:0,allowIL:!1,cmdTiming:0,renderLine:renderLineModeB6},B7:{name:"B7",width:1024,height:212,pixelWidthDiv:4,hasBorders:1,allowIL:!0,cmdTiming:0,renderLine:renderLineModeB7}},types={SBY:{name:"SBY",bpp:8,ppB:1,renderLine:renderLineTypeSBY},PP1:{name:"PP1",bpp:4,ppB:2,renderLine:renderLineTypePP1},PP2:{name:"PP2",bpp:4,ppB:2,renderLine:renderLineTypePP2},BYUV:{name:"BYUV",bpp:8,ppB:1,renderLine:renderLineTypeBYUV},BYUVP:{name:"BYUVP",bpp:8,ppB:1,renderLine:renderLineTypeBYUVP},BYJK:{name:"BYJK",bpp:8,ppB:1,renderLine:renderLineTypeBYJK},BYJKP:{name:"BYJKP",bpp:8,ppB:1,renderLine:renderLineTypeBYJKP},BD16:{name:"BD16",bpp:16,ppB:0,renderLine:renderLineTypeBD16},BD8:{name:"BD8",bpp:8,ppB:1,renderLine:renderLineTypeBD8},BP6:{name:"BP6",bpp:8,ppB:1,renderLine:renderLineTypeBP6},BP4:{name:"BP4",bpp:4,ppB:2,renderLine:renderLineTypeBP4},BP2:{name:"BP2",bpp:2,ppB:4,renderLine:renderLineTypeBP2}},renderLine,renderLineActive,solidBlackValue=4278190080,notPaintedValue=4294902015,standByValue=solidBlackValue,backdropValue=solidBlackValue,colors16bitValues,colors8bitValues,colorsYUVValues,colorsYJKValues,paletteValues=new Uint32Array(64),paletteValuesReal=new Uint32Array(64),kanjiPort1Address=0,kanjiPort2Address=0,debugMode=0,debugModeSpriteHighlight=!1,debugModeSpriteInfo=!1,debugModeSpriteInfoNumbers=!1,debugModeSpritesHidden=!1,debugModePatternInfo=!1,debugModePatternInfoBlocks=!1,debugModePatternInfoNames=!1,spriteDebugMode=0,spriteDebugModeLimit=!0,debugBackdropValue=4280953386,debugLineStartBUSCycles=0,machine,vdp,cpu,cartridge,videoSignal,videoDisplayed=!1,commandProcessor;this.saveState=function(a){var b={s:status,if:interruptFlags,sc:systemControl,sro:softResetON,rs:registerSelect,rri:registerSelectReadInc,rwi:registerSelectWriteInc,vr:vramPointerRead,vw:vramPointerWrite,vri:vramPointerReadInc,vwi:vramPointerWriteInc,vrd:vramReadData,vi:vramInterleaving,pp:palettePointer,pri:palettePointerReadInc,poa:paletteOffsetA,pob:paletteOffsetB,po:paletteOffset,poc:paletteOffsetCursor,l:currentScanline,b:bufferPosition,ba:bufferLineAdvance,ad:renderLine===renderLineActive,fs:frameStartingActiveScanline,f:frame,c:cycles,cc:lastBUSCyclesComputed,sx:scrollXOffset,sy:scrollYOffset,syf:scrollYOffsetFrame,sxb:scrollXBOffset,syb:scrollYBOffset,sybf:scrollYBOffsetFrame,sym:scrollYMax,syu:scrollYHiUpdatePending,sybu:scrollYBHiUpdatePending,pa:planeAEnabled,pb:planeBEnabled,pby:priBYLine,pbx:priBXCol,de:dispEnabled,se:spritesEnabled,dsu:dispAndSpritesUpdatePending,ha:horizontalAdjust,va:verticalAdjust,hil:horizontalIntLine,eos:vramEOLineShift,eoa:vramEOLineAdd,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),p:wmsx.Util.storeInt8BitArrayToStringBase64(paletteRAM),vram:wmsx.Util.compressInt8BitArrayToStringBase64(vram,VRAM_SIZE),k1a:kanjiPort1Address,k2a:kanjiPort2Address,cp:commandProcessor.saveState()};return a&&(b.dm=debugMode,b.sd=spriteDebugMode),b},this.loadState=function(a){status=a.s,interruptFlags=a.if,systemControl=a.sc,softResetON=a.sro,registerSelect=a.rs,registerSelectReadInc=a.rri,registerSelectWriteInc=a.rwi,vramPointerRead=a.vr,vramPointerWrite=a.vw,vramPointerReadInc=a.vri,vramPointerWriteInc=a.vwi,vramReadData=a.vrd,vramInterleaving=!!a.vi,palettePointer=a.pp,palettePointerReadInc=a.pri,paletteOffsetA=a.poa,paletteOffsetB=a.pob,paletteOffset=a.po,paletteOffsetCursor=a.poc,register=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r,register),paletteRAM=wmsx.Util.restoreStringBase64ToInt8BitArray(a.p,paletteRAM),vram=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.vram,vram,!0),currentScanline=a.l,bufferPosition=a.b,bufferLineAdvance=a.ba,frame=a.f||0,cycles=a.c,lastBUSCyclesComputed=a.cc,scrollXOffset=a.sx,scrollYOffset=a.sy,scrollYOffsetFrame=a.syf,scrollXBOffset=a.sxb,scrollYBOffset=a.syb,scrollYBOffsetFrame=a.sybf,scrollYMax=a.sym,scrollYHiUpdatePending=a.syu,scrollYBHiUpdatePending=a.sybu,planeAEnabled=a.pa,planeBEnabled=a.pb,priBYLine=a.pby,priBXCol=a.pbx,dispEnabled=a.de,spritesEnabled=a.se,dispAndSpritesUpdatePending=a.dsu,horizontalAdjust=a.ha,verticalAdjust=a.va,horizontalIntLine=a.hil,vramEOLineShift=a.eos,vramEOLineAdd=a.eoa,kanjiPort1Address=a.k1a||0,kanjiPort2Address=a.k2a||131072,commandProcessor.loadState(a.cp),commandProcessor.connectV9990(this,vram,register),frameVideoStandard=videoStandard,framePulldown=pulldown,updateSignalMetrics(!0),void 0!==a.fs&&(frameStartingActiveScanline=a.fs),cpu&&updateIRQ(),updateMode(!0),updateYSEnabled(!0),updateBackdropColor(),a.ad?setActiveDisplay():setBorderDisplay(),void 0!==a.dm&&self.setDebugMode(a.dm),void 0!==a.sd&&self.setSpriteDebugMode(a.sd)},init(),this.logInfo=logInfo,this.eval=function(str){return eval(str)},this.TEST=0,this.register=register,this.registerWrite=registerWrite},wmsx.V9990.VRAM_LIMIT=524287,wmsx.V9990.SIGNAL_START_WIDTH=272,wmsx.V9990.SIGNAL_START_HEIGHT=228,wmsx.V9990.SIGNAL_MAX_WIDTH=1088,wmsx.V9990.SIGNAL_MAX_HEIGHT=480,wmsx.V9990.BASE_CLOCK=wmsx.VDP.BASE_CLOCK,wmsx.V9990CommandProcessor=function(){"use strict";function getSX(){return((7&register[33])<<8|register[32])&imageWidthMask}function setSX(a){a=getSX()&~imageWidthMask|a&imageWidthMask,register[33]=a>>8&15,register[32]=255&a}function getSY(){return((15&register[35])<<8|register[34])&imageHeightMask}function setSY(a){
a=getSY()&~imageHeightMask|a&imageHeightMask,register[35]=a>>8&15,register[34]=255&a}function getSourcePlaneBOffset(){return isP1&&2&register[33]?2048:0}function getSA(){return(7&register[35])<<16|register[34]<<8|register[32]}function setSA(a){register[35]=a>>16&7,register[34]=a>>8&255,register[32]=255&a}function getKA(){return(3&register[35])<<16|register[34]<<8|register[32]}function getDX(){return((7&register[37])<<8|register[36])&imageWidthMask}function setDX(a){a=getDX()&~imageWidthMask|a&imageWidthMask,register[37]=a>>8&7,register[36]=255&a}function getDY(){return((15&register[39])<<8|register[38])&imageHeightMask}function setDY(a){a=getDY()&~imageHeightMask|a&imageHeightMask,register[39]=a>>8&15,register[38]=255&a}function getDestPlaneBOffset(){return isP1&&2&register[37]?2048:0}function getDA(){return(7&register[39])<<16|register[38]<<8|register[36]}function setDA(a){register[39]=a>>16&7,register[38]=a>>8&255,register[36]=255&a}function getNX(){return(7&register[41])<<8|register[40]||2048}function getNY(){return(15&register[43])<<8|register[42]||4096}function getNA(){return(7&register[43])<<16|register[42]<<8|register[40]||524288}function getMJ(){return(15&register[41])<<8|register[40]}function getMI(){return(15&register[43])<<8|register[42]}function getDIX(){return 4&register[44]?-1:1}function getDIY(){return 8&register[44]?-1:1}function getMAJ(){return 1&register[44]}function getNEQ(){return 0!=(2&register[44])}function getLOP(){return LOGICAL_OPERATIONS[31&register[45]]}function getWMDirect(){return register[46]<<8|register[47]}function getWM(a){return isP1?a?register[47]<<8|register[47]:register[46]<<8|register[46]:getWMDirect()}function wm8ForAddr(a,b){return a>>((1&~b)<<3)&255}function wm16ForAddr(a,b){return a>>((1&b)<<3)&255|a<<((1&b)<<3)&65280}function getFC(a){return isP1?a?register[49]<<8|register[49]:register[48]<<8|register[48]:register[48]<<8|register[49]}function getBC(a){return isP1?a?register[51]<<8|register[51]:register[50]<<8|register[50]:register[50]<<8|register[51]}function getAYME(){return register[52]>>2&3}function getAXME(){return 3&register[52]}function setBX(a){register[54]=a>>8,register[53]=255&a}function LMMC(){DX=getDX(),DESTOff=getDestPlaneBOffset(),DY=getDY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),LOP=getLOP(),WM=getWM(DESTOff),EDX=DX,CX=0,CY=0,SX=0,writeStart(LMMCNextWrite)}function LMMCNextWrite(a){4===typeBPP?(a|=a<<8,LMMCNextPixel(a),CE&&LMMCNextPixel(a)):8===typeBPP?LMMCNextPixel(a<<8|a):16===typeBPP?null===writeDataPending?writeDataPending=a:(LMMCNextPixel(writeDataPending<<8|a),writeDataPending=null):(a|=a<<8,LMMCNextPixel(a),CE&&LMMCNextPixel(a),CE&&LMMCNextPixel(a),CE&&LMMCNextPixel(a)),CE||(setDY(DY),v9990.setStatusTR(0))}function LMMCNextPixel(a){logicalPSETX(EDX,DY|DESTOff,SX,a,LOP,WM),++CX,++SX,CX>=NX?(EDX=DX,CX=0,++CY,DY=DY+DIY&imageHeightMask,CY>=NY&&finish()):EDX=EDX+DIX&imageWidthMask}function LMMV(){for(var a=getDX(),b=getDestPlaneBOffset(),c=getDY(),d=getNX(),e=getNY(),f=getDIX(),g=getDIY(),h=getLOP(),i=getWM(b),j=getFC(b),k=e;k>0;--k){for(var l=a,m=0;m<d;++m)logicalPSETX(l,c|b,l,j,h,i),l=l+f&imageWidthMask;c=c+g&imageHeightMask}setDY(c),start(LMMVTiming,d*e,e)}function LMCM(){SX=getSX(),SRCOff=getSourcePlaneBOffset(),SY=getSY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),ESX=SX,CX=0,CY=0,readStart(LMCMNextRead)}function LMCMNextRead(){4===typeBPP?(readData=15&readData|LMCMNextPixel(2),CE&&(readData=240&readData|LMCMNextPixel(3))):8===typeBPP?readData=LMCMNextPixel(1):16===typeBPP?null===readDataPending?(readDataPending=LMCMNextPixel(0),readData=readDataPending>>8):(readData=255&readDataPending,readDataPending=null):(readData=63&readData|LMCMNextPixel(4),CE&&(readData=207&readData|LMCMNextPixel(5)),CE&&(readData=243&readData|LMCMNextPixel(6)),CE&&(readData=252&readData|LMCMNextPixel(7))),CE||(setSY(SY),v9990.setStatusTR(0))}function LMCMNextPixel(a){var b=normalPGETX(ESX,SY|SRCOff,a);return++CX,CX>=NX?(ESX=SX,CX=0,++CY,SY=SY+DIY&imageHeightMask,CY>=NY&&finish()):ESX=ESX+DIX&imageWidthMask,b}function LMMM(){for(var a=getSX(),b=getSourcePlaneBOffset(),c=getSY(),d=getDX(),e=getDestPlaneBOffset(),f=getDY(),g=getNX(),h=getNY(),i=getDIX(),j=getDIY(),k=getLOP(),l=getWM(e),m=h;m>0;--m){for(var n=a,o=d,p=g;p>0;--p)logicalPCOPYXX(o,f|e,n,c|b,k,l),n=n+i&imageWidthMask,o=o+i&imageWidthMask;c=c+j&imageHeightMask,f=f+j&imageHeightMask}setSY(c),setDY(f),start(LMMMTiming,g*h,h)}function CMMC(){DX=getDX(),DESTOff=getDestPlaneBOffset(),DY=getDY(),NX=getNX(),NY=getNY(),DIX=getDIX(),DIY=getDIY(),LOP=getLOP(),WM=getWM(DESTOff),FBC=getFC(DESTOff)<<16|getBC(DESTOff),EDX=DX,CX=0,CY=0,writeStart(CMMCNextWrite)}function CMMCNextWrite(a){for(var b=7;b>=0;--b){if(logicalPSETX(EDX,DY|DESTOff,EDX,FBC>>((a>>b&1)<<4)&65535,LOP,WM),++CX>=NX){if(EDX=DX,CX=0,++CY,DY=DY+DIY&imageHeightMask,CY>=NY){finish();break}}else EDX=EDX+DIX&imageWidthMask}CE||(setDY(DY),v9990.setStatusTR(0))}function CMMM(){for(var a=getSA(),b=getDX(),c=getDestPlaneBOffset(),d=getDY(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY(),i=getLOP(),j=getWM(c),k=getFC(c)<<16|getBC(c),l=0,m=0,n=0,o=f;o>0;--o){for(var p=b,q=0;q<e;++q)0==(7&m)&&(isP1?(l=vram[a>>>1|(1&a)<<18],a=a+1&VRAM_LIMIT):(l=vram[a],a=a+1&VRAM_LIMIT)),n=l>>7-(7&m)&1,logicalPSETX(p,d|c,p,k>>(n<<4)&65535,i,j),p=p+g&imageWidthMask,++m;d=d+h&imageHeightMask}setSA(a),setDY(d),start(BMXLTiming,e*f,f)}function CMMK(){for(var a=getKA(),b=getDX(),c=getDestPlaneBOffset(),d=getDY(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY(),i=getLOP(),j=getWM(c),k=getFC(c)<<16|getBC(c),l=0,m=0,n=0,o=f;o>0;--o){for(var p=b,q=0;q<e;++q){if(0==(7&m)){l=v9990.readKanji(a);var r=1+(16&a|(8&a)>>3|(7&a)<<1);a=262112&a|16&r|(1&r)<<3|(14&r)>>1}n=l>>7-(7&m)&1,logicalPSETX(p,d|c,p,k>>(n<<4)&65535,i,j),p=p+g&imageWidthMask,++m}d=d+h&imageHeightMask}setDY(d),start(BMXLTiming,e*f,f)}function BMXL(){for(var a=getSA(),b=getDX(),c=getDestPlaneBOffset(),d=getDY(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY(),i=getLOP(),j=getWM(c),k=0,l=0,m=0,n=f;n>0;--n){for(var o=b,p=0;p<e;++p){if(0==(7&m))if(isP1)if(16===typeBPP){var q=a>>>1|(1&a)<<18;k=vram[q]<<8,a=a+1&VRAM_LIMIT,q=a>>>1|(1&a)<<18,k|=vram[q],a=a+1&VRAM_LIMIT}else q=a>>>1|(1&a)<<18,k=vram[q],k|=k<<8,a=a+1&VRAM_LIMIT;else 16===typeBPP?(k=vram[a]<<8|vram[a+1],a=a+2&VRAM_LIMIT):(k=vram[a],k|=k<<8,a=a+1&VRAM_LIMIT);logicalPSETX(o,d|c,l,k,i,j),o=o+g&imageWidthMask,++l,m+=typeBPP}d=d+h&imageHeightMask}setSA(a),setDY(d),start(BMXLTiming,e*f,f)}function BMLX(){var a=getSX(),b=getSourcePlaneBOffset(),c=getSY(),d=getDA(),e=getNX(),f=getNY(),g=getDIX(),h=getDIY(),i=getLOP(),j=getWMDirect(),k=0,l=0;if(isP1)for(var m=f;m>0;--m){for(var n=a,o=e;o>0;--o)logicalPCOPYLXP1(d+(l>>3)&VRAM_LIMIT,k,n,c|b,i,j),n=n+g&imageWidthMask,++k,l+=typeBPP;c=c+h&imageHeightMask}else for(m=f;m>0;--m){for(n=a,o=e;o>0;--o)logicalPCOPYLX(d+(l>>3)&VRAM_LIMIT,k,n,c|b,i,j),n=n+g&imageWidthMask,++k,l+=typeBPP;c=c+h&imageHeightMask}setSY(c),setDA(d),start(BMLXTiming,e*f,f)}function BMLL(){var a=getSA(),b=getDA(),c=getNA(),d=getDIX(),e=getLOP(),f=getWMDirect();if(isP1)for(var g=c;g>0;--g)logicalPCOPYLLP1(b,a,e,f),a=a+d&VRAM_LIMIT,b=b+d&VRAM_LIMIT;else for(g=c;g>0;--g)logicalPCOPYLL(b,a,e,f),a=a+d&VRAM_LIMIT,b=b+d&VRAM_LIMIT;setSA(a),setDA(b),start(BMLLTiming,c,0)}function LINE(){var a=getDX(),b=getDestPlaneBOffset(),c=getDY(),d=getMJ(),e=getMI(),f=getDIX(),g=getDIY(),h=getMAJ(),i=getLOP(),j=getWM(b),k=getFC(b),l=0,m=0;if(0===h)for(var n=d;n>=0;--n)logicalPSETX(a,c|b,a,k,i,j),a=a+f&imageWidthMask,e>0&&(m+=e)<<1>=d&&(c=c+g&imageHeightMask,m-=d,++l);else for(n=d;n>=0;--n)logicalPSETX(a,c|b,a,k,i,j),c=c+g&imageHeightMask,e>0&&(m+=e)<<1>=d&&(a=a+f&imageWidthMask,m-=d,++l);setDX(a),setDY(c),start(LMMVTiming,d,e)}function SRCH(){var a=getSX(),b=getSourcePlaneBOffset(),c=getSY()|b,d=getDIX(),e=getNEQ(),f=getFC(b),g=1===d?imageWidth:-1,h=a,i=0,j=!1,k=16===typeBPP?65535:4===typeBPP?61440:2===typeBPP?49152:65280,l=(typeData.ppB<<1)-1
;if(l<0&&(l=0),e)do{if(i=f&k>>(h&l)*typeBPP,normalPGETX(h,c,h)!==i){j=!0;break}h+=d}while(h!==g);else do{if(i=f&k>>(h&l)*typeBPP,normalPGETX(h,c,h)===i){j=!0;break}h+=d}while(h!==g);var m=((7&register[33])<<8|register[32])&~imageWidthMask,n=j?m|h:1===d?m+h&2047:2047;setSX(n),setBX(n),v9990.setStatusBD(j),start(LMMVTiming,Math.abs(h-a)+1,1)}function POINT(){SX=getSX(),SY=getSY()|getSourcePlaneBOffset(),readStart(POINTNextRead)}function POINTNextRead(){if(4===typeBPP)readData=15&readData|normalPGETX(SX,SY,2);else if(8===typeBPP)readData=normalPGETX(SX,SY,1);else if(16===typeBPP){if(null===readDataPending)return readDataPending=normalPGETX(SX,SY,0),void(readData=readDataPending>>8);readData=255&readDataPending,readDataPending=null}else readData=63&readData|normalPGETX(SX,SY,4);v9990.setStatusTR(0),finish()}function PSET(){var a=getDX(),b=getDestPlaneBOffset(),c=getDY(),d=getLOP(),e=getWM(b),f=getFC(b),g=getAXME(),h=getAYME();logicalPSETX(a,c|b,a,f,d,e);var i=1===g?1:3===g?-1:0,j=1===h?1:3===h?-1:0;setDX(a+i),setDY(c+j),start(LMMVTiming,1,1)}function ADVN(){var a=getDX(),b=getDY(),c=getAXME(),d=getAYME(),e=1===c?1:3===c?-1:0,f=1===d?1:3===d?-1:0;setDX(a+e),setDY(b+f),start(LMMVTiming,1,1)}function STOP(){finish(!0)}function normalPGETX(a,b,c){var d,e,f;if(4===typeBPP)d=1-(1&a)<<2,e=3-(3&c)<<2,a>>>=1,f=15;else if(8===typeBPP)d=0,e=1-(1&c)<<3,f=255;else{if(16===typeBPP){a<<=1;var g=b*imageWidthBytes+a&VRAM_LIMIT;return vram[g]<<8|vram[g+1]}d=3-(3&a)<<1,e=7-(7&c)<<1,a>>>=2,f=3}return g=b*imageWidthBytes+a&VRAM_LIMIT,(vram[g]>>d&f)<<e}function logicalPSETX(a,b,c,d,e,f){var g,h,i;if(4===typeBPP)g=3-(3&c)<<2,h=1-(1&a)<<2,a>>>=1,i=15;else if(8===typeBPP)g=1-(1&c)<<3,h=0,i=255;else{if(16===typeBPP){a<<=1;var j=b*imageWidthBytes+a&VRAM_LIMIT,k=vram[j]<<8|vram[j+1],l=e(k,d,f);return vram[j]=l>>8,void(vram[j+1]=255&l)}g=7-(7&c)<<1,h=3-(3&a)<<1,a>>>=2,i=3}j=b*imageWidthBytes+a&VRAM_LIMIT,d=(d>>g&i)<<h,vram[j]=e(vram[j],d,i<<h&wm8ForAddr(f,j))}function logicalPCOPYXX(a,b,c,d,e,f){var g,h,i;if(4===typeBPP)g=1-(1&c)<<2,h=1-(1&a)<<2,c>>>=1,a>>>=1,i=15;else if(8===typeBPP)g=h=0,i=255;else{if(16===typeBPP){c<<=1,a<<=1;var j=d*imageWidthBytes+c&VRAM_LIMIT,k=b*imageWidthBytes+a&VRAM_LIMIT,l=vram[j]<<8|vram[j+1],m=vram[k]<<8|vram[k+1],n=e(m,l,f);return vram[k]=n>>8,void(vram[k+1]=255&n)}g=3-(3&c)<<1,h=3-(3&a)<<1,c>>>=2,a>>>=2,i=3}j=d*imageWidthBytes+c&VRAM_LIMIT,k=b*imageWidthBytes+a&VRAM_LIMIT,l=(vram[j]>>g&i)<<h,vram[k]=e(vram[k],l,i<<h&wm8ForAddr(f,k))}function logicalPCOPYLX(a,b,c,d,e,f){var g,h,i;if(4===typeBPP)g=1-(1&c)<<2,h=1-(1&b)<<2,c>>>=1,i=15;else if(8===typeBPP)g=h=0,i=255;else{if(16===typeBPP){c<<=1;var j=d*imageWidthBytes+c&VRAM_LIMIT,k=vram[j]<<8|vram[j+1],l=vram[a]<<8|vram[a+1],m=e(l,k,wm16ForAddr(f,a));return vram[a]=m>>8,void(vram[a+1]=255&m)}g=3-(3&c)<<1,h=3-(3&b)<<1,c>>>=2,i=3}j=d*imageWidthBytes+c&VRAM_LIMIT,k=(vram[j]>>g&i)<<h,vram[a]=e(vram[a],k,i<<h&wm8ForAddr(f,a))}function logicalPCOPYLXP1(a,b,c,d,e,f){var g,h,i;if(4===typeBPP)g=1-(1&c)<<2,h=1-(1&b)<<2,c>>>=1,i=15;else if(8===typeBPP)g=h=0,i=255;else{if(16===typeBPP){c<<=1;var j=d*imageWidthBytes+c&VRAM_LIMIT,k=vram[j]<<8|vram[j+1],l=a>>>1|(1&a)<<18;a=a+1&VRAM_LIMIT;var m=a>>>1|(1&a)<<18,n=vram[l]<<8|vram[m],o=e(n,k,wm16ForAddr(f,a));return vram[l]=o>>8,void(vram[m]=255&o)}g=3-(3&c)<<1,h=3-(3&b)<<1,c>>>=2,i=3}f=wm8ForAddr(f,a),j=d*imageWidthBytes+c&VRAM_LIMIT,k=(vram[j]>>g&i)<<h,a=a>>>1|(1&a)<<18,vram[a]=e(vram[a],k,i<<h&f)}function logicalPCOPYLL(a,b,c,d){vram[a]=c(vram[a],vram[b],wm8ForAddr(d,a))}function logicalPCOPYLLP1(a,b,c,d){d=wm8ForAddr(d,a),a=a>>>1|(1&a)<<18,b=b>>>1|(1&b)<<18,vram[a]=c(vram[a],vram[b],d)}function lopNULL(a,b,c){return a&~c}function lopNOR(a,b,c){return a&~c|~(a|b)&c}function lopEXD(a,b,c){return a&~(b&c)}function lopNOTS(a,b,c){return a&~c|~b&c}function lopEXS(a,b,c){return a&~c|b&~a&c}function lopNOTD(a,b,c){return a&~c|~a&c}function lopXOR(a,b,c){return a^b&c}function lopNAND(a,b,c){return a&~c|~(a&b)&c}function lopAND(a,b,c){return a&(b|~c)}function lopEQV(a,b,c){return a&~c|~(a^b)&c}function lopD(a,b,c){return a}function lopNEXS(a,b,c){return a&~c|(~b|a)&c}function lopS(a,b,c){return a&~c|b&c}function lopNEXD(a,b,c){return a|(~a|b)&c}function lopOR(a,b,c){return a|b&c}function lopID(a,b,c){return a|c}function lopTNULL(a,b,c){return 0===b?a:a&~c}function lopTNOR(a,b,c){return 0===b?a:a&~c|~(a|b)&c}function lopTEXD(a,b,c){return 0===b?a:a&~(b&c)}function lopTNOTS(a,b,c){return 0===b?a:a&~c|~b&c}function lopTEXS(a,b,c){return 0===b?a:a&~c|b&~a&c}function lopTNOTD(a,b,c){return 0===b?a:a&~c|~a&c}function lopTXOR(a,b,c){return 0===b?a:a^b&c}function lopTNAND(a,b,c){return 0===b?a:a&~c|~(a&b)&c}function lopTAND(a,b,c){return 0===b?a:a&(b|~c)}function lopTEQV(a,b,c){return 0===b?a:a&~c|~(a^b)&c}function lopTD(a,b,c){return a}function lopTNEXS(a,b,c){return 0===b?a:a&~c|(~b|a)&c}function lopTS(a,b,c){return 0===b?a:a&~c|b&c}function lopTNEXD(a,b,c){return 0===b?a:a|(~a|b)&c}function lopTOR(a,b,c){return 0===b?a:a|b&c}function lopTID(a,b,c){return 0===b?a:a|c}function start(a,b,c,d){CE=1,v9990.setStatusCE(CE),writeHandler=null,readHandler=null,estimateDuration(a,b,c,d)}function estimateDuration(a,b,c,d){if(d)finishingCycle=-1;else if(a&&0!==turboClockMulti){var e=a[modeData.cmdTiming][dispAndSpritesMode],f=e[typeBPP]||e,g=BASE_CLOCK/50/256/f,h=b*g*self.COMMAND_PER_PIXEL_DURATION_FACTOR/turboClockMulti|0;finishingCycle=v9990.getVDPCycles()+h}else finishingCycle=0,finish()}function writeStart(a){start(null,0,0,!0),writeHandler=a,writeDataPending=null,v9990.setStatusTR(1)}function readStart(a){start(null,0,0,!0),readHandler=a,readDataPending=null,v9990.setStatusTR(1),readHandler()}function finish(a){CE=0,v9990.setStatusCE(CE),a||v9990.triggerCommandCompletionInterrupt(),writeHandler=null,writeDataPending=null,readDataPending=null,readHandler=null}var self=this;this.connectV9990=function(a,b,c){v9990=a,vram=b,register=c},this.reset=function(){STOP()},this.startCommand=function(a){switch(240&a){case 0:STOP();break;case 16:LMMC();break;case 32:LMMV();break;case 48:LMCM();break;case 64:LMMM();break;case 80:CMMC();break;case 96:CMMK();break;case 112:CMMM();break;case 128:BMXL();break;case 144:BMLX();break;case 160:BMLL();break;case 176:LINE();break;case 192:SRCH();break;case 208:POINT();break;case 224:PSET();break;case 240:ADVN()}},this.cpuWrite=function(a){writeHandler?writeHandler(a):v9990.setStatusTR(0)},this.cpuRead=function(){var a=readData;return readHandler?readHandler():v9990.setStatusTR(0),a},this.updateStatus=function(){CE&&finishingCycle>=0&&(0===finishingCycle||v9990.getVDPCycles()>=finishingCycle)&&finish()},this.setV9990ModeData=function(a,b,c,d){modeData=a,typeData=b,imageWidth=c,imageWidthMask=c-1,imageHeight=d,imageHeightMask=d-1,imageWidthBytes=imageWidth*typeData.bpp>>3,typeBPP=typeData.bpp,isP1="P1"===a.name,colosPPBShift=typeData.ppB>>1,colorPPBMask=-1<<colosPPBShift},this.setV9990DisplayAndSpritesEnabled=function(a,b){dispAndSpritesMode=a?b?2:1:0},this.setTurboMulti=function(a){turboClockMulti=a<0||a>8?0:a},this.getV9990TurboMulti=function(){return turboClockMulti};var BASE_CLOCK=wmsx.V9990.BASE_CLOCK,VRAM_LIMIT=wmsx.V9990.VRAM_LIMIT,COMMAND_HANDLERS={LMMCNextWrite:LMMCNextWrite,LMCMNextRead:LMCMNextRead,POINTNextRead:POINTNextRead};self.COMMAND_PER_PIXEL_DURATION_FACTOR=.99
;var v9990,vram,register,CE=0,SX=0,SY=0,SRCOff=0,DX=0,DY=0,DESTOff=0,NX=0,NY=0,ESX=0,EDX=0,DIX=0,DIY=0,CX=0,CY=0,WM=0,FBC=0,LOP,readData=0,writeDataPending=null,readDataPending=null,writeHandler=null,readHandler=null,finishingCycle=0,dispAndSpritesMode=0,turboClockMulti=1,modeData,typeData,isP1=!1,typeBPP=8,colosPPBShift=0,colorPPBMask=0,imageWidth=0,imageHeight=0,imageWidthMask=0,imageHeightMask=0,imageWidthBytes=0,LOGICAL_OPERATIONS=[lopNULL,lopNOR,lopEXD,lopNOTS,lopEXS,lopNOTD,lopXOR,lopNAND,lopAND,lopEQV,lopD,lopNEXS,lopS,lopNEXD,lopOR,lopID,lopTNULL,lopTNOR,lopTEXD,lopTNOTS,lopTEXS,lopTNOTD,lopTXOR,lopTNAND,lopTAND,lopTEQV,lopTD,lopTNEXS,lopTS,lopTNEXD,lopTOR,lopTID],LMMVTiming=[[{2:723,4:537,8:400,16:200},{2:720,4:526,8:394,16:199},{2:683,4:502,8:372,16:188}],[{2:481,4:352,8:262,16:131},{2:478,4:349,8:258,16:129},{2:441,4:315,8:232,16:116}],[393,218,167],[528,320,251]],LMMMTiming=[[{2:625,4:386,8:193,16:96},{2:625,4:376,8:188,16:95},{2:578,4:353,8:176,16:89}],[{2:409,4:248,8:123,16:62},{2:402,4:243,8:120,16:60},{2:361,4:215,8:108,16:54}],[186,104,80],[371,209,160]],BMLLTiming=[[193,188,177],[123,120,107],[186,103,79],[186,103,79]],BMXLTiming=[[{2:626,4:387,8:194,16:97},{2:626,4:377,8:189,16:95},{2:583,4:356,8:177,16:90}],[{2:417,4:250,8:125,16:62},{2:411,4:243,8:121,16:60},{2:364,4:216,8:108,16:54}],[228,129,100],[372,210,160]],BMLXTiming=[[{2:625,4:386,8:193,16:96},{2:625,4:376,8:188,16:95},{2:578,4:353,8:176,16:89}],[{2:409,4:248,8:123,16:62},{2:402,4:243,8:120,16:60},{2:361,4:215,8:108,16:54}],[195,115,90],[371,209,160]];this.saveState=function(){return{ce:CE,rd:readData,rdp:readDataPending,wdp:writeDataPending,wh:writeHandler&&writeHandler.name,rh:readHandler&&readHandler.name,fc:finishingCycle,SX:SX,SY:SY,SYP1O:SRCOff,DX:DX,DY:DY,DYP1O:DESTOff,NX:NX,NY:NY,ESX:ESX,EDX:EDX,DIX:DIX,DIY:DIY,CX:CX,CY:CY,WM:WM,FBC:FBC,LOP:LOP&&LOGICAL_OPERATIONS.indexOf(LOP),dsm:dispAndSpritesMode,tcm:turboClockMulti}},this.loadState=function(a){CE=a.ce,readData=a.rd,readDataPending=a.rdp,writeDataPending=a.wdp,writeHandler=COMMAND_HANDLERS[a.wh],readHandler=COMMAND_HANDLERS[a.rh],finishingCycle=a.fc,SX=a.SX,SY=a.SY,SRCOff=a.SYP1O,DX=a.DX,DY=a.DY,DESTOff=a.DYP1O,NX=a.NX,NY=a.NY,ESX=a.ESX,EDX=a.EDX,DIX=a.DIX,DIY=a.DIY,CX=a.CX,CY=a.CY,WM=a.WM,FBC=a.FBC,LOP=a.LOP>=0?LOGICAL_OPERATIONS[a.LOP]:void 0,dispAndSpritesMode=a.dsm,turboClockMulti=void 0!==a.tcm?a.tcm:1},this.eval=function(str){return eval(str)}},wmsx.VideoSignal=function(a,b){"use strict";this.connectMonitor=function(a){c=a},this.newFrame=function(a,b,d,e,f){c.newFrame(this,a,b,d,e,f)},this.signalOff=function(){c&&c.signalOff(this)},this.showOSD=function(a,b,d){c&&c.showOSD(a,b,d)},this.setDisplayMetrics=function(a,b){c&&c.setDisplayMetrics(this,a,b)},this.setColorAndPaletteMode=function(b,c){a.setColorAndPaletteMode(b,c)},this.resetOutputAutoMode=function(){a.resetOutputAutoMode()},this.refreshDisplayMetrics=function(){a.refreshDisplayMetrics()},this.videoSignalDisplayStateUpdate=function(b,c){a.videoSignalDisplayStateUpdate(b,c)},this.setOutputAutoMode=function(a){c&&c.setOutputAutoMode(this,a)},this.getSignalName=function(){return b},this.setDebugMode=function(a){c&&c.setDebugMode(this,a)},this.getScreenText=function(){return a.getScreenText()},this.name=b;var c},wmsx.VideoStandard={NTSC:{name:"NTSC",desc:"NTSC 60Hz",totalWidth:342,totalHeight:262,topBorderHeight:16,targetFPS:60,pulldowns:{60:{standard:"NTSC",frequency:60,divider:1,linesPerCycle:262,firstStepCycleLinesAdjust:0,cadence:[1],steps:1},120:{standard:"NTSC",frequency:120,divider:2,linesPerCycle:262,firstStepCycleLinesAdjust:0,cadence:[1],steps:1},"120s":{standard:"NTSC",frequency:120,divider:1,linesPerCycle:131,firstStepCycleLinesAdjust:0,cadence:[0,1],steps:2},50:{standard:"NTSC",frequency:50,divider:1,linesPerCycle:314,firstStepCycleLinesAdjust:2,cadence:[1,1,1,1,2],steps:5},100:{standard:"NTSC",frequency:100,divider:2,linesPerCycle:314,firstStepCycleLinesAdjust:2,cadence:[1,1,1,1,2],steps:5},"100s":{standard:"NTSC",frequency:100,divider:1,linesPerCycle:157,firstStepCycleLinesAdjust:2,cadence:[0,1,0,1,1,0,1,0,1,1],steps:10},TIMER:{standard:"NTSC",frequency:62.5,divider:1,linesPerCycle:262,firstStepCycleLinesAdjust:0,cadence:[1],steps:1}}},PAL:{name:"PAL",desc:"PAL 50Hz",totalWidth:342,totalHeight:313,topBorderHeight:43,targetFPS:50,pulldowns:{50:{standard:"PAL",frequency:50,divider:1,linesPerCycle:313,firstStepCycleLinesAdjust:0,cadence:[1],steps:1},100:{standard:"PAL",frequency:100,divider:2,linesPerCycle:313,firstStepCycleLinesAdjust:0,cadence:[1],steps:1},"100s":{standard:"PAL",frequency:100,divider:1,linesPerCycle:156,firstStepCycleLinesAdjust:1,cadence:[0,1],steps:2},60:{standard:"PAL",frequency:60,divider:1,linesPerCycle:261,firstStepCycleLinesAdjust:-1,cadence:[0,1,1,1,1,1],steps:6},120:{standard:"PAL",frequency:120,divider:2,linesPerCycle:261,firstStepCycleLinesAdjust:-1,cadence:[0,1,1,1,1,1],steps:6},"120s":{standard:"PAL",frequency:120,divider:1,linesPerCycle:130,firstStepCycleLinesAdjust:5,cadence:[0,0,1,0,1,0,0,1,0,1,0,1],steps:12},TIMER:{standard:"PAL",frequency:50,divider:1,linesPerCycle:313,firstStepCycleLinesAdjust:0,cadence:[1],steps:1}}}},wmsx.AudioTables={setupVolPan:function(a,b,c,d,e){this.createVolPanVolumeTable();for(var f=0;f<a;++f){var g=Number("0x"+(1===b.length?b[0]:b.length>f?b[f]:"f")),h=Number("0x"+(1===c.length?c[0]:c.length>f?c[f]:"8"));d[f]=this.VOLPAN_VOLUME_TABLE[this.VOL_VALUES[g]+this.PAN_VALUES[0][h]],e[f]=this.VOLPAN_VOLUME_TABLE[this.VOL_VALUES[g]+this.PAN_VALUES[1][h]]}},createVolPanVolumeTable:function(){if(!this.VOLPAN_VOLUME_TABLE){for(var a=new Array(256),b=0;b<127;++b)a[b]=Math.pow(10,-.75*b/20);for(b=127;b<256;++b)a[b]=0;this.VOLPAN_VOLUME_TABLE=a}},VOL_VALUES:[128,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0],PAN_VALUES:[[127,0,0,0,0,0,0,0,0,4,8,12,16,20,24,127],[127,127,24,20,16,12,8,4,0,0,0,0,0,0,0,0]],VOLPAN_VOLUME_TABLE:void 0},wmsx.PSG=function(controllersSocket,ledsSocket,secondary){"use strict";function updateKanaLed(){ledsSocket&&ledsSocket.ledStateChanged(1,(128&~register[15])>>7)}this.connectBus=function(a){var b=secondary?16:160;a.connectInputDevice(b,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(b,this.outputA0),a.connectInputDevice(b+1,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(b+1,this.outputA1),a.connectInputDevice(b+2,this.inputA2),a.connectOutputDevice(b+2,wmsx.DeviceMissing.outputPortIgnored),powerIsOn&&audioChannel.connectAudio()},this.disconnectBus=function(a){var b=secondary?16:160;a.disconnectInputDevice(b,wmsx.DeviceMissing.inputPortIgnored),a.disconnectOutputDevice(b,this.outputA0),a.disconnectInputDevice(b+1,wmsx.DeviceMissing.inputPortIgnored),a.disconnectOutputDevice(b+1,this.outputA1),a.disconnectInputDevice(b+2,this.inputA2),a.disconnectOutputDevice(b+2,wmsx.DeviceMissing.outputPortIgnored),audioChannel.disconnectAudio()},this.setAudioSocket=function(a){audioChannel.setAudioSocket(a)},this.powerOn=function(){this.reset(),powerIsOn=!0,audioChannel.powerOn()},this.powerOff=function(){powerIsOn=!1,this.reset(),audioChannel.powerOff()},this.reset=function(){wmsx.Util.arrayFill(register,0),register[15]=143,updateKanaLed(),audioChannel.reset()},this.getAudioChannel=function(){return audioChannel},this.outputA0=function(a){registerAddress=a>15?0:a},this.outputA1=function(a){switch(register[registerAddress]=a,registerAddress){case 0:case 1:audioChannel.setPeriodA((15&register[1])<<8|register[0]);break;case 2:case 3:audioChannel.setPeriodB((15&register[3])<<8|register[2]);break;case 4:case 5:audioChannel.setPeriodC((15&register[5])<<8|register[4]);break;case 6:audioChannel.setPeriodN(31&a);break;case 7:audioChannel.setMixerControl(a);break;case 8:audioChannel.setAmplitudeA(a);break;case 9:audioChannel.setAmplitudeB(a);break;case 10:audioChannel.setAmplitudeC(a);break;case 11:case 12:audioChannel.setPeriodE(register[12]<<8|register[11]);break;case 13:
audioChannel.setEnvelopeControl(a);break;case 15:controllersSocket&&(controllersSocket.writeControllerPin8Port(0,(16&a)>>4),controllersSocket.writeControllerPin8Port(1,(32&a)>>5)),updateKanaLed()}},this.inputA2=function(){if(14!==registerAddress)return register[registerAddress];var a=register[15]>>6&1;return controllersSocket?controllersSocket.readControllerPort(a):63};var powerIsOn=!1,registerAddress=0,register=wmsx.Util.arrayFill(new Array(16),0),audioChannel=new wmsx.PSGAudio(secondary);this.saveState=function(){return{p:powerIsOn,ra:registerAddress,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),ac:audioChannel.saveState()}},this.loadState=function(a){powerIsOn=void 0===a.p||a.p,registerAddress=a.ra,register=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r,register),updateKanaLed(),audioChannel.loadState(a.ac)},this.eval=function(str){return eval(str)}},wmsx.AudioSignal=function(a,b,c,d,e,f){"use strict";function g(a){switch(a){case 32:return j;case 72:return k;case 81:return l;default:throw new Error("Unsupported AudioSignal Sample Rate CPU Clock multiple: "+a)}}function h(a){switch(a){case 72:return m;default:throw new Error("Unsupported AudioSignal Clock CPU Clock multiple: "+a)}}function i(){var a=H*WMSX.AUDIO_SIGNAL_BUFFER_RATIO+v*WMSX.AUDIO_SIGNAL_ADD_FRAMES&-8;F.length=a,a>C&&wmsx.Util.arrayFill(F,0,C,a),e&&(G.length=a,a>C&&wmsx.Util.arrayFill(G,0,C,a)),C=a,I.bufferSize=C,E=C-2,s.flush()}function j(){if(B>0){if(D<=0)return void(B=0);t(),--B,--D}}function k(){1&--w||8===w||(0===w&&(w=9),j())}function l(){--x,1&x&&j(),0===x&&(x=5)}function m(){1&--y||8===y||(0===y&&(y=9),b.audioClockPulse())}function n(){F[z]=b.nextSample()*c,++z>=C&&(z=0)}function o(){var a=b.nextSample();F[z]=a[0]*c,G[z]=a[1]*c,++z>=C&&(z=0)}function p(){F[z]=0,++z>=C&&(z=0)}function q(){F[z]=G[z]=0,++z>=C&&(z=0)}function r(a,b){if(b)for(var c=a;c>0;c-=1)u();else for(var d=a;d>0;d-=1)t();D-=a}var s=this;this.audioClockPulse=null,this.flush=function(){z=0,A=0,D=E},this.setFps=function(a){v=Math.floor(d/a),i()},this.audioFinishFrame=function(){if(B>0)for(;B>0;)j();B=v},this.retrieveSamples=function(a,b){var c=E-D,d=a-c;d>-4&&(d+4>D&&(d=D-4),r(d+4,b)),I.start=A;var e=c+d;return D+=e,A+=e,A>=C&&(A-=C),I},this.getSampleRate=function(){return d},this.toString=function(){return"AudioSignal "+a},this.setAudioMonitorBufferSize=function(a){H=a,i()};var t=n,u=p;this.name=a;var v,w=9,x=5,y=9,z=0,A=0,B=0,C=0,D=0,E=0,F=wmsx.Util.arrayFill(new Array(C),0),G=e?wmsx.Util.arrayFill(new Array(C),0):F,H=0,I={stereo:e,buffer0:F,buffer1:G,bufferSize:C,start:0};!function(){c=1.2*c*WMSX.VOL,t=e?o:n,u=e?q:p;var a=Math.floor(wmsx.Machine.BASE_CPU_CLOCK/d),b=g(a);if(f){a=Math.floor(wmsx.Machine.BASE_CPU_CLOCK/f);var i=h(a);s.audioClockPulse=function(){i(),b()}}else s.audioClockPulse=b}()},wmsx.PSGAudio=function(a){"use strict";function b(a,b){a^b&&(L=!L),I=L?0:15,J=b?0:L?1:-1}function c(){o&&(l=T[I]),v&&(s=T[I]),C&&(z=T[I])}function d(){return 1&(R=R>>1|(1&(R>>2^1&R))<<16)}function e(){for(var a=0;a<16;a++)T[a]=(Math.pow(X,a/15)-1)/(X-1)*W}var f=this;this.setAudioSocket=function(a){h=a},this.powerOn=function(){this.reset(),this.connectAudio()},this.powerOff=function(){this.disconnectAudio()},this.reset=function(){this.setMixerControl(255),this.setAmplitudeA(0),this.setAmplitudeB(0),this.setAmplitudeC(0),O=!1,P=0,Q=0},this.nextSample=function(){if(i>0&&(j+=2)>=i&&(j=j-i&1,k=k?0:1),p>0&&(q+=2)>=p&&(q=q-p&1,r=r?0:1),w>0&&(x+=2)>=w&&(x=x-w&1,y=y?0:1),(n||u||B)&&(E+=1)>=D&&(E=0,F=d()),0!==J&&(H+=1)>=G&&(H=0,I+=J,(I<0||I>15)&&(K?b(M,N):(L=!0,b(!0,!0))),c()),ba){var a=0===l||m&&!k||n&&!F?0:l,e=0===s||t&&!r||u&&!F?0:s,f=0===z||A&&!y||B&&!F?0:z,g=0;return Q&&(g=W,!O&&h.getBUSCycles()-P>=Y&&(Q=0)),S[0]=a*U[0]+e*U[1]+f*U[2]+g*U[3],S[1]=a*V[0]+e*V[1]+f*V[2]+g*V[3],S}var o=(0===l||m&&!k||n&&!F?0:l)+(0===s||t&&!r||u&&!F?0:s)+(0===z||A&&!y||B&&!F?0:z);return Q&&(o+=W,!O&&h.getBUSCycles()-P>=Y&&(Q=0)),o},this.setPeriodA=function(a){i!==a&&(a<2?(i=0,k=1):i=a)},this.setPeriodB=function(a){p!==a&&(a<2?(p=0,r=1):p=a)},this.setPeriodC=function(a){w!==a&&(a<2?(w=0,y=1):w=a)},this.setPeriodN=function(a){D!==a&&(D=a<1?1:a)},this.setPeriodE=function(a){G!==a&&(G=a<1?1:a)},this.setAmplitudeA=function(a){16&a?(o=!0,l=T[I]):(o=!1,l=T[15&a])},this.setAmplitudeB=function(a){16&a?(v=!0,s=T[I]):(v=!1,s=T[15&a])},this.setAmplitudeC=function(a){16&a?(C=!0,z=T[I]):(C=!1,z=T[15&a])},this.setMixerControl=function(a){m=0==(1&a),n=0==(8&a),t=0==(2&a),u=0==(16&a),A=0==(4&a),B=0==(32&a)},this.setEnvelopeControl=function(a){K=(8&a)>0,L=(4&a)>0,M=(2&a)>0,N=(1&a)>0,b(!1,!1),c()},this.setPulseSignal=function(a){O=a,a&&(P=h.getBUSCycles(),Q=1)},this.connectAudio=function(){h&&(g||(g=new wmsx.AudioSignal("PSG"+(a?"2":""),f,Z,$,ba)),h.connectAudioSignal(g))},this.disconnectAudio=function(){h&&g&&h.disconnectAudioSignal(g)};var g,h,i=0,j=0,k=0,l=0,m=!1,n=!1,o=!1,p=0,q=0,r=0,s=0,t=!1,u=!1,v=!1,w=0,x=0,y=0,z=0,A=!1,B=!1,C=!1,D=1,E=1,F=0,G=1,H=1,I=0,J=0,K=!1,L=!1,M=!1,N=!1,O=!1,P=0,Q=0,R=131070,S=[0,0],T=new Array(16),U=new Array(4),V=new Array(4),W=.25,X=30,Y=160,Z=.66,$=112005,_=(a&&WMSX.PSG2_VOL||WMSX.PSG_VOL||"f").toUpperCase(),aa=(a&&WMSX.PSG2_PAN||WMSX.PSG_PAN||"0").toUpperCase(),ba="F"!==_||"8"!==aa;this.saveState=function(){return{pa:i,pac:j,ca:k,aa:l,ta:m,na:n,ea:o,pb:p,pbc:q,cb:r,ab:s,tb:t,nb:u,eb:v,pc:w,pcc:x,cc:y,ac:z,tc:A,nc:B,ec:C,pn:D,pnc:E,cn:F,pe:G,pec:H,ce:I,de:J,cne:K,ate:L,ale:M,he:N,ps:O,lf:R}},this.loadState=function(a){i=a.pa,j=a.pac,k=a.ca,l=a.aa,m=a.ta,n=a.na,o=a.ea,p=a.pb,q=a.pbc,r=a.cb,s=a.ab,t=a.tb,u=a.nb,v=a.eb,w=a.pc,x=a.pcc,y=a.cc,z=a.ac,A=a.tc,B=a.nc,C=a.ec,D=a.pn,E=a.pnc,F=a.cn,G=a.pe,H=a.pec,I=a.ce,J=a.de,K=a.cne,L=a.ate,M=a.ale,N=a.he,O=a.ps,P=0,Q=O?1:0,R=a.lf},function(){e(),ba&&wmsx.AudioTables.setupVolPan(4,_,aa,U,V)}()},wmsx.PCM8BitAudio=function(){"use strict";this.setAudioSocket=function(a){c=a},this.connectAudio=function(){b||(b=new wmsx.AudioSignal("PCM 8 bit",this,e,f)),c&&c.connectAudioSignal(b)},this.disconnectAudio=function(){b&&c&&c.disconnectAudioSignal(b)},this.reset=function(){a=0},this.setSampleValue=function(b){a=b-128},this.nextSample=function(){return a*d};var a,b,c,d=.25/128,e=.66,f=112005;this.saveState=function(){return{s:a}},this.loadState=function(b){a=b.s}},wmsx.SCCIAudio=function(){"use strict";function a(a,b){if((a&=255)<128)return U[a>>>5][31&a]=b<128?b:-256+b,void(a>>>5==3&&(O[31&a]=b<128?b:-256+b));if(a<160){if((a&=239)<138)return void f(a-128>>>1,b,1&a);if(a<143)return void e(a-138,15&b);g(b)}}function b(a){return a&=255,a<128?255&U[a>>>5][31&a]:255}function c(a,b){if((a&=255)<160)return void(U[a>>>5][31&a]=b<128?b:-256+b);if(a<192){if((a&=239)<170)return void f(a-160>>>1,b,1&a);if(a<175)return void e(a-170,15&b);g(b)}}function d(a){return a&=255,a<160?255&U[a>>>5][31&a]:255}function e(a,b){switch(a){case 0:r=W[b];break;case 1:y=W[b];break;case 2:F=W[b];break;case 3:M=W[b];break;case 4:T=W[b]}}function f(a,b,c){switch(a){case 0:n=c?255&n|(15&b)<<8:65280&n|b;break;case 1:u=c?255&u|(15&b)<<8:65280&u|b;break;case 2:B=c?255&B|(15&b)<<8:65280&B|b;break;case 3:I=c?255&I|(15&b)<<8:65280&I|b;break;case 4:P=c?255&P|(15&b)<<8:65280&P|b}}function g(a){l=1&a?1:0,s=2&a?1:0,z=4&a?1:0,G=8&a?1:0,N=16&a?1:0}function h(){for(var a=0;a<16;a++)W[a]=(Math.pow($,a/15)-1)/($-1)*Z}this.setAudioSocket=function(a){k=a},this.connectAudio=function(){j||(j=new wmsx.AudioSignal("SCC",this,_,aa,da)),k&&k.connectAudioSignal(j)},this.disconnectAudio=function(){j&&k&&k.disconnectAudioSignal(j)},this.reset=function(){this.disconnectAudio(),g(0),r=y=F=M=T=0,n=u=B=I=P=0,o=v=C=J=Q=0,p=w=D=K=R=0,q=x=E=L=S=0;for(var a=0;a<5;a++)wmsx.Util.arrayFill(U[a],0);this.setSCCIMode(!1)},this.setSCCIMode=function(e){i!==e&&(i=!!e,i?(this.read=d,this.write=c):(this.read=b,this.write=a))},this.nextSample=function(){var a=0,b=0,c=0,d=0,e=0;if(n>0)for(l&&(a=q*r),o+=32;o>=n;)o-=n,++p>31&&(p=0),q=m[p];if(u>0)for(s&&(b=x*y),
v+=32;v>=u;)v-=u,++w>31&&(w=0),x=t[w];if(B>0)for(z&&(c=E*F),C+=32;C>=B;)C-=B,++D>31&&(D=0),E=A[D];if(I>0)for(G&&(d=L*M),J+=32;J>=I;)J-=I,++K>31&&(K=0),L=H[K];if(P>0)for(N&&(e=S*T),Q+=32;Q>=P;)Q-=P,++R>31&&(R=0),S=O[R];return da?(V[0]=a*X[0]+b*X[1]+c*X[2]+d*X[3]+e*X[4],V[1]=a*Y[0]+b*Y[1]+c*Y[2]+d*Y[3]+e*Y[4],V):a+b+c+d+e};var i,j,k,l=0,m=wmsx.Util.arrayFill(new Array(32),0),n=0,o=0,p=0,q=0,r=0,s=0,t=wmsx.Util.arrayFill(new Array(32),0),u=0,v=0,w=0,x=0,y=0,z=0,A=wmsx.Util.arrayFill(new Array(32),0),B=0,C=0,D=0,E=0,F=0,G=0,H=wmsx.Util.arrayFill(new Array(32),0),I=0,J=0,K=0,L=0,M=0,N=!1,O=wmsx.Util.arrayFill(new Array(32),0),P=0,Q=0,R=0,S=0,T=0,U=[m,t,A,H,O],V=[0,0],W=new Array(16),X=new Array(5),Y=new Array(5),Z=.23/128,$=3,_=.65,aa=112005,ba=(WMSX.SCC_VOL||"f").toUpperCase(),ca=(WMSX.SCC_PAN||"8").toUpperCase(),da="F"!==ba||"8"!==ca;this.saveState=function(){return{m:i,c1:l,p1:n,pc1:o,sc1:p,cs1:q,a1:r,c2:s,p2:u,pc2:v,sc2:w,cs2:x,a2:y,c3:z,p3:B,pc3:C,sc3:D,cs3:E,a3:F,c4:G,p4:I,pc4:J,sc4:K,cs4:L,a4:M,c5:N,p5:P,pc5:Q,sc5:R,cs5:S,a5:T,s1:wmsx.Util.storeInt8BitArrayToStringBase64(m),s2:wmsx.Util.storeInt8BitArrayToStringBase64(t),s3:wmsx.Util.storeInt8BitArrayToStringBase64(A),s4:wmsx.Util.storeInt8BitArrayToStringBase64(H),s5:wmsx.Util.storeInt8BitArrayToStringBase64(O)}},this.loadState=function(a){this.reset(),l=a.c1,n=a.p1,o=a.pc1,p=a.sc1,q=a.cs1,r=a.a1,s=a.c2,u=a.p2,v=a.pc2,w=a.sc2,x=a.cs2,y=a.a2,z=a.c3,B=a.p3,C=a.pc3,D=a.sc3,E=a.cs3,F=a.a3,G=a.c4,I=a.p4,J=a.pc4,K=a.sc4,L=a.cs4,M=a.a4,N=a.c5,P=a.p5,Q=a.pc5,R=a.sc5,S=a.cs5,T=a.a5,m=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.s1,m),t=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.s2,t),A=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.s3,A),H=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.s4,H),O=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.s5||a.s4,O),U[0]!==m&&(U[0]=m),U[1]!==t&&(U[1]=t),U[2]!==A&&(U[2]=A),U[3]!==H&&(U[3]=H),U[4]!==O&&(U[4]=O),this.setSCCIMode(!0===a.m)},function(a){h(),da&&wmsx.AudioTables.setupVolPan(5,ba,ca,X,Y),a.setSCCIMode(!1)}(this)},wmsx.YM2413Tables=function(){"use strict";this.getFullSineTable=function(){for(var a=new Array(1024),b=0;b<1024;++b)a[b]=(b>511?16384:0)|Math.round(256*-wmsx.Util.log2(Math.abs(Math.sin(2*(b+.5)*Math.PI/1024))));return a},this.getHalfSineTable=function(){for(var a=new Array(1024),b=0;b<1024;++b)a[b]=Math.round(256*-wmsx.Util.log2(Math.abs(Math.sin(2*(b<512?b+.5:.5)*Math.PI/1024))));return a},this.getExpTable=function(){for(var a=new Array(32768),b=0;b<32768;++b){var c=Math.round(1024*wmsx.Util.exp2((255&b^255)/256))<<1>>Math.min((16128&b)>>8,31);16384&b&&(c=-c),a[b]=c}return a},this.getInstrumentsROM=function(){return this.INSTRUMENT_ROM},this.getVIBValues=function(){return this.VIB_VALUES},this.getKSLValues=function(){return this.KSL_VALUES},this.getMultiFactorsDoubled=function(){return this.MULTI_FACTORS},this.getRateDecayDurations=function(){for(var a=new Array(76),b=0;b<64;++b){var c=this.RATE_DECAY_DURATIONS[b];a[b]=c>=0?Math.max(1,Math.round(c/1e3*49780/128)):0}for(b=64;b<76;++b)a[b]=a[63];return a},this.getRateAttackDurations=function(){for(var a=new Array(76),b=0;b<64;++b){var c=this.RATE_ATTACK_DURATIONS[b];a[b]=c>=0?Math.max(1,Math.round(c/1e3*49780/128*8)):0}for(b=64;b<76;++b)a[b]=a[63];return a},this.INSTRUMENT_ROM=[[0,0,0,0,0,0,0,0],[97,97,30,23,240,127,0,23],[19,65,22,14,253,244,35,35],[3,1,154,4,243,243,19,243],[17,97,14,7,250,100,112,23],[34,33,30,6,240,118,0,40],[33,34,22,5,240,113,0,24],[33,97,29,7,130,128,23,23],[35,33,45,22,144,144,0,7],[33,33,27,6,100,101,16,23],[33,33,11,26,133,160,112,7],[35,1,131,16,255,180,16,244],[151,193,32,7,255,244,34,34],[97,0,12,5,194,246,64,68],[1,1,86,3,148,194,3,18],[33,1,137,3,241,228,240,35],[1,1,20,0,253,248,111,141],[1,17,0,0,248,247,248,247],[5,17,0,0,248,250,248,85]],this.VIB_VALUES=[[0,0,0,0,0,0,0,0],[0,0,1,0,0,0,-1,0],[0,1,2,1,0,-1,-2,-1],[0,1,3,1,0,-1,-3,-1],[0,2,4,2,0,-2,-4,-2],[0,2,5,2,0,-2,-5,-2],[0,3,6,3,0,-3,-6,-3],[0,3,7,3,0,-3,-7,-3]],this.KSL_VALUES=[[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,1,2,2,3,3,4],[0,0,0,0,0,1,2,3,4,5,5,6,6,7,7,8],[0,0,0,2,4,5,6,7,8,9,9,10,10,11,11,12],[0,0,4,6,8,9,10,11,12,13,13,14,14,15,15,16],[0,4,8,10,12,13,14,15,16,17,17,18,18,19,19,20],[0,8,12,14,16,17,18,19,20,21,21,22,22,23,23,24],[0,12,16,18,20,21,22,23,24,25,25,26,26,27,27,28]],[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,2,3,4,5,6,7,8],[0,0,0,0,0,3,5,7,8,10,11,12,13,14,15,16],[0,0,0,5,8,11,13,15,16,18,19,20,21,22,23,24],[0,0,8,13,16,19,21,23,24,26,27,28,29,30,31,32],[0,8,16,21,24,27,29,31,32,34,35,36,37,38,39,40],[0,16,24,29,32,35,37,39,40,42,43,44,45,46,47,48],[0,24,32,37,40,43,45,47,48,50,51,52,53,54,55,56]],[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,4,6,8,10,12,14,16],[0,0,0,0,0,6,10,14,16,20,22,24,26,28,30,32],[0,0,0,10,16,22,26,30,32,36,38,40,42,44,46,48],[0,0,16,26,32,38,42,46,48,52,54,56,58,60,62,64],[0,16,32,42,48,54,58,62,64,68,70,72,74,76,78,80],[0,32,48,58,64,70,74,78,80,84,86,88,90,92,94,96],[0,48,64,74,80,86,90,94,96,100,102,104,106,108,110,112]]],this.MULTI_FACTORS=[1,2,4,6,8,10,12,14,16,18,20,20,24,24,30,30],this.RATE_DECAY_DURATIONS=[-1,-1,-1,-1,20926.6,16807.2,14006,12028.7,10463.3,8403.58,7002.98,6014.32,5231.64,4201.79,3501.49,3007.16,2615.82,2100.89,1750.75,1503.58,1307.91,1050.45,875.37,751.79,653.95,525.22,437.69,375.9,326.98,262.61,218.84,187.95,163.49,131.31,109.42,93.97,81.74,65.65,54.71,46.99,40.87,32.83,27.36,23.49,20.44,16.41,13.68,11.75,10.22,8.21,6.84,5.87,5.11,4.1,3.42,2.94,2.55,2.05,1.71,1.47,1.27,1.27,1.27,1.27],this.RATE_ATTACK_DURATIONS=[-1,-1,-1,-1,1730.15,1400.6,1153.43,988.66,865.08,700.3,576.72,494.33,432.54,350.15,288.36,247.16,216.27,175.07,144.18,123.58,108.13,87.54,72.09,61.79,54.07,43.77,36.04,30.9,27.03,21.88,18.02,15.45,13.52,10.94,9.01,7.72,6.76,5.47,4.51,3.86,3.38,2.74,2.25,1.93,1.69,1.37,1.13,.97,.84,.7,.6,.54,.5,.42,.34,.3,.28,.22,.18,.14,0,0,0,0]},wmsx.YM2413Audio=function(pName){"use strict";function init(){name=pName||"YM2413";var a=new wmsx.YM2413Tables;sineTable=a.getFullSineTable(),halfSineTable=a.getHalfSineTable(),expTable=a.getExpTable(),instrumentsParameters=a.getInstrumentsROM(),multiFactors=a.getMultiFactorsDoubled(),vibValues=a.getVIBValues(),kslValues=a.getKSLValues(),rateAttackDurTable=a.getRateAttackDurations(),rateDecayDurTable=a.getRateDecayDurations(),VOLPAN&&wmsx.AudioTables.setupVolPan(14,VOL,PAN,volPanL,volPanR)}function connectAudio(){audioSocket&&(audioSignal||(audioSignal=new wmsx.AudioSignal(name,self,VOLUME,SAMPLE_RATE,VOLPAN)),audioSocket.connectAudioSignal(audioSignal),audioConnected=!0)}function disconnectAudio(){audioSocket&&audioSignal&&audioSocket.disconnectAudioSignal(audioSignal),audioConnected=!1}function registerWrite(a,b){var c=15&a;c>8&&(c-=9);var d=c<<1,e=d+1,f=register[a]^b;switch(register[a]=b,a){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:f&&(instrumentsParameters[0][a]=b,updateCustomInstrChannels());break;case 14:32&f&&setRhythmMode(0!=(32&b)),rhythmMode&&(48&f&&(setRhythmKeyOnOp(12,(16&b)>>4),setRhythmKeyOnOp(13,(16&b)>>4)),40&f&&setRhythmKeyOnOp(15,(8&b)>>3),36&f&&setRhythmKeyOnOp(16,(4&b)>>2),34&f&&setRhythmKeyOnOp(17,(2&b)>>1),33&f&&setRhythmKeyOnOp(14,1&b));break;case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:f&&(fNum[d]=-256&fNum[d]|b,fNum[e]=fNum[d],updateFrequency(c));break;case 32:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:32&f&&setSustain(c,(32&b)>>5),16&f&&!(rhythmMode&&c>5)&&setKeyOn(c,(16&b)>>4),
1&f&&(fNum[d]=-257&fNum[d]|(1&b)<<8,fNum[e]=fNum[d]),14&f&&(block[d]=b>>1&7,block[e]=block[d]),15&f&&updateFrequency(c);break;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 58:case 59:case 60:case 61:case 62:case 63:rhythmMode&&c>5?(240&f&&c>6&&setVolumeOp(d,b>>>4),15&f&&setVolumeOp(e,15&b)):(240&f&&(audioConnected||connectAudio(),setInstr(c,b>>>4)),15&f&&setVolumeOp(e,15&b))}}function clockNoise(){noiseRegister>>=1,(noiseOutput=1&noiseRegister)&&(noiseRegister^=134230048)}function clockAM(){return!(511&clock)&&(0!==amLevel&&13!==amLevel||(amLevelInc=-amLevelInc),amLevel+=amLevelInc,!0)}function clockVIB(){return!(1023&clock)&&(vibPhase=clock>>10&7,!0)}function clockEnvelope(a){envLevel[a]===envStepNextAtLevel[a]?setEnvStepOp(a,envStepNext[a]):clock===envStepLevelIncClock[a]&&(envStepLevelIncClock[a]+=envStepLevelDur[a],envLevel[a]+=envStepLevelInc[a],updateEnvAttenuationOp(a))}function setSustain(a,b){sustain[a]=b}function setKeyOn(a,b){var c=a<<1,d=c+1;keyOn[c]=b,keyOn[d]=b,b?setEnvStep(a,DAMP):envStep[d]!==IDLE&&setEnvStepOp(d,RELEASE)}function setRhythmKeyOnOp(a,b){keyOn[a]=b,b?setEnvStepOp(a,DAMP):envStep[a]!==IDLE&&setEnvStepOp(a,RELEASE)}function setEnvStep(a,b){var c=a<<1,d=c+1;setEnvStepOp(c,b),setEnvStepOp(d,b)}function setEnvStepOp(a,b){switch(envStep[a]=b,b){case DAMP:envStepLevelDur[a]=rateDecayDurTable[48+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=ATTACK;break;case ATTACK:envStepLevelDur[a]=rateAttackDurTable[(ar[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=-8,envStepNextAtLevel[a]=0,envStepNext[a]=DECAY,phaseCounter[a]=0;break;case DECAY:envStepLevelDur[a]=rateDecayDurTable[(dr[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=sl[a]<<3,envStepNext[a]=SUSTAIN;break;case SUSTAIN:envType[a]?(envStepLevelIncClock[a]=envStepLevelDur[a]=0,envStepLevelInc[a]=0,envStepNextAtLevel[a]=255,envStepNext[a]=SUSTAIN):(envStepLevelDur[a]=rateDecayDurTable[(rr[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=IDLE);break;case RELEASE:var c=envType[a]?sustain[a>>1]?5:rr[a]:sustain[a>>1]?5:7;envStepLevelDur[a]=rateDecayDurTable[(c<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=IDLE;break;case IDLE:default:envLevel[a]=128,envStepLevelIncClock[a]=envStepLevelDur[a]=0,envStepLevelInc[a]=0,envStepNextAtLevel[a]=255,envStepNext[a]=IDLE}}function setRhythmMode(a){rhythmMode=a,rhythmMode?(audioConnected||connectAudio(),setInstr(6,16),setInstr(7,17),setInstr(8,18)):(setEnvStep(6,IDLE),updateEnvAttenuation(6),setEnvStep(7,IDLE),updateEnvAttenuation(7),setEnvStep(8,IDLE),updateEnvAttenuation(8),setInstr(6,register[36]>>4),setInstr(7,register[37]>>4),setInstr(8,register[38]>>4))}function setInstr(a,b){instr[a]=b;var c=a<<1,d=c+1,e=instrumentsParameters[b];am[c]=e[0]>>7&1,am[d]=e[1]>>7&1,vib[c]=e[0]>>6&1,vib[d]=e[1]>>6&1,envType[c]=e[0]>>5&1,envType[d]=e[1]>>5&1,ksr[c]=e[0]>>4&1,ksr[d]=e[1]>>4&1,multi[c]=multiFactors[15&e[0]],multi[d]=multiFactors[15&e[1]],ksl[c]=e[2]>>6,ksl[d]=e[3]>>6,modTL[c]=63&e[2],halfWave[c]=e[3]>>3&1,halfWave[d]=e[3]>>4&1,fbShift[a]=7&e[3]?8-(7&e[3]):0,ar[c]=e[4]>>4,ar[d]=e[5]>>4,dr[c]=15&e[4],dr[d]=15&e[5],sl[c]=e[6]>>4,sl[d]=e[7]>>4,rr[c]=15&e[6],rr[d]=15&e[7],updateAMAttenuation(a),updateFrequency(a),updateModAttenuationOp(c)}function updateCustomInstrChannels(){for(var a=0;a<9;a++)0===instr[a]&&setInstr(a,0)}function setVolumeOp(a,b){volume[a]=b,updateVolumeAttenuationOp(a)}function updateFrequency(a){var b=a<<1,c=b+1,d=vib[b]?vibValues[fNum[b]>>6][vibPhase]:0;phaseInc[b]=((fNum[b]<<1)+d)*multi[b]<<block[b]>>2,d=vib[c]?vibValues[fNum[c]>>6][vibPhase]:0,phaseInc[c]=((fNum[c]<<1)+d)*multi[c]<<block[c]>>2,updateKSLAttenuation(a),updateKSROffset(a)}function updateFrequencyOp(a){var b=vib[a]?vibValues[fNum[a]>>6][vibPhase]:0;phaseInc[a]=((fNum[a]<<1)+b)*multi[a]<<block[a]>>2,updateKSLAttenuationOp(a),updateKSROffsetOp(a)}function updateKSROffset(a){var b=a<<1,c=b+1;ksrOffset[b]=(ksr[b]?block[b]<<1:block[b]>>1)|fNum[b]>>>9-ksr[b],ksrOffset[c]=(ksr[c]?block[c]<<1:block[c]>>1)|fNum[c]>>>9-ksr[c]}function updateKSROffsetOp(a){ksrOffset[a]=(ksr[a]?block[a]<<1:block[a]>>1)|fNum[a]>>>9-ksr[a]}function updateAMAttenuation(a){var b=a<<1,c=b+1;amAtt[b]=am[b]?amLevel<<4:0,amAtt[c]=am[c]?amLevel<<4:0,updateTotalAttenuation(a)}function updateAMAttenuationOp(a){amAtt[a]=am[a]?amLevel<<4:0,updateTotalAttenuationOp(a)}function updateKSLAttenuation(a){var b=a<<1,c=b+1;kslAtt[b]=kslValues[ksl[b]][block[b]][fNum[b]>>>5]<<4,kslAtt[c]=kslValues[ksl[c]][block[c]][fNum[c]>>>5]<<4,updateTotalAttenuation(a)}function updateKSLAttenuationOp(a){kslAtt[a]=kslValues[ksl[a]][block[a]][fNum[a]>>>5]<<4,updateTotalAttenuationOp(a)}function updateEnvAttenuation(a){var b=a<<1,c=b+1;envAtt[b]=(128===envLevel[b]?256:envLevel[b])<<4,envAtt[c]=(128===envLevel[c]?256:envLevel[c])<<4,updateTotalAttenuation(a)}function updateEnvAttenuationOp(a){envAtt[a]=(128===envLevel[a]?256:envLevel[a])<<4,updateTotalAttenuationOp(a)}function updateModAttenuationOp(a){volModAtt[a]=modTL[a]<<5,updateTotalAttenuationOp(a)}function updateVolumeAttenuationOp(a){volModAtt[a]=(15===volume[a]?30:volume[a])<<7,updateTotalAttenuationOp(a)}function updateTotalAttenuation(a){var b=a<<1,c=b+1;totalAtt[b]=amAtt[b]+kslAtt[b]+envAtt[b]+volModAtt[b],totalAtt[c]=amAtt[c]+kslAtt[c]+envAtt[c]+volModAtt[c]}function updateTotalAttenuationOp(a){totalAtt[a]=amAtt[a]+kslAtt[a]+envAtt[a]+volModAtt[a]}var self=this;this.connect=function(a){a.bus.connectInputDevice(124,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectInputDevice(125,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectOutputDevice(124,this.output7C),a.bus.connectOutputDevice(125,this.output7D),audioSocket=a.getAudioSocket(),audioConnected&&connectAudio()},this.disconnect=function(a){a.bus.disconnectInputDevice(124,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectInputDevice(125,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectOutputDevice(124,this.output7C),a.bus.disconnectOutputDevice(125,this.output7D),disconnectAudio(),audioSocket=null},this.powerOn=function(){this.reset()},this.powerOff=function(){disconnectAudio()},this.reset=function(){registerAddress=0,wmsx.Util.arrayFill(register,0),wmsx.Util.arrayFill(instrumentsParameters[0],0),clock=0,noiseRegister=65535,noiseOutput=0,amLevel=0,amLevelInc=-1,vibPhase=0,rhythmMode=!1,wmsx.Util.arrayFill(sustain,0),wmsx.Util.arrayFill(instr,0),wmsx.Util.arrayFill(keyOn,0),wmsx.Util.arrayFill(am,0),wmsx.Util.arrayFill(vib,0),wmsx.Util.arrayFill(envType,0),wmsx.Util.arrayFill(ksr,0),wmsx.Util.arrayFill(multi,0),wmsx.Util.arrayFill(ksl,0),wmsx.Util.arrayFill(halfWave,0),wmsx.Util.arrayFill(ar,0),wmsx.Util.arrayFill(dr,0),wmsx.Util.arrayFill(sl,0),wmsx.Util.arrayFill(rr,0),wmsx.Util.arrayFill(fNum,0),wmsx.Util.arrayFill(block,0),wmsx.Util.arrayFill(volume,0),wmsx.Util.arrayFill(modTL,0),wmsx.Util.arrayFill(fbShift,0),wmsx.Util.arrayFill(volModAtt,0),wmsx.Util.arrayFill(amAtt,0),wmsx.Util.arrayFill(envAtt,0),wmsx.Util.arrayFill(kslAtt,0),wmsx.Util.arrayFill(totalAtt,0),wmsx.Util.arrayFill(envStep,IDLE),wmsx.Util.arrayFill(envStepLevelDur,0),wmsx.Util.arrayFill(envStepLevelIncClock,0),wmsx.Util.arrayFill(envStepLevelInc,0),wmsx.Util.arrayFill(envStepNext,DAMP),wmsx.Util.arrayFill(envStepNextAtLevel,0),wmsx.Util.arrayFill(envLevel,0),wmsx.Util.arrayFill(ksrOffset,0),wmsx.Util.arrayFill(fbLastMod1,0),wmsx.Util.arrayFill(fbLastMod2,0),wmsx.Util.arrayFill(phaseInc,0),wmsx.Util.arrayFill(phaseCounter,0),disconnectAudio()},this.output7C=function(a){registerAddress=63&a},this.output7D=function(a){registerWrite(registerAddress,a)},
this.nextSample=function(){var a,b,c,d,e,f,g=!1;++clock,(a=clockAM())&&(g=clockVIB());for(var h=0,i=0,j=0,k=0,l=rhythmMode?5:8,m=l;m>=0;--m)b=m<<1,c=b+1,envStep[c]!==IDLE&&(a&&(am[b]&&updateAMAttenuationOp(b),am[c]&&updateAMAttenuationOp(c),g&&(vib[b]&&updateFrequencyOp(b),vib[c]&&updateFrequencyOp(c))),envStep[b]!==IDLE&&clockEnvelope(b),clockEnvelope(c),d=(phaseCounter[b]+=phaseInc[b])>>9,e=(phaseCounter[c]+=phaseInc[c])>>9,fbShift[m]?(d+=fbLastMod1[m]+fbLastMod2[m]>>fbShift[m],f=expTable[(halfWave[b]?halfSineTable:sineTable)[1023&d]+totalAtt[b]],fbLastMod2[m]=fbLastMod1[m]>>1,fbLastMod1[m]=f>>1):f=expTable[(halfWave[b]?halfSineTable:sineTable)[1023&d]+totalAtt[b]],h=expTable[(halfWave[c]?halfSineTable:sineTable)[e+f&1023]+totalAtt[c]]>>4,VOLPAN?(i+=h*volPanL[m],j+=h*volPanR[m]):k+=h);if(rhythmMode&&(clockNoise(),c=13,envStep[c]!==IDLE&&(b=12,clockEnvelope(b),clockEnvelope(c),d=((phaseCounter[b]+=phaseInc[b])>>9)-1,e=(phaseCounter[c]+=phaseInc[c])>>9,f=expTable[sineTable[1023&d]+totalAtt[b]],h=expTable[sineTable[e+f&1023]+totalAtt[c]]>>3,VOLPAN?(i+=h*volPanL[9],j+=h*volPanR[9]):k+=h),c=15,envStep[c]!==IDLE&&(clockEnvelope(c),e=(phaseCounter[c]+=phaseInc[c])>>9,h=expTable[sineTable[256&e?noiseOutput?0:130:noiseOutput?0:893]+totalAtt[c]]>>3,VOLPAN?(i+=h*volPanL[10],j+=h*volPanR[10]):k+=h),c=16,envStep[c]!==IDLE&&(clockEnvelope(c),e=(phaseCounter[c]+=phaseInc[c])>>9,h=expTable[sineTable[1023&e]+totalAtt[c]]>>3,VOLPAN?(i+=h*volPanL[11],j+=h*volPanR[11]):k+=h),envStep[17]!==IDLE||envStep[14]!==IDLE)){var n=(phaseCounter[14]+=phaseInc[14])>>9,o=(phaseCounter[17]+=phaseInc[17])>>9,p=(0!=(4&o)&&0==(16&o))!=(0!=(2&n)!=(0!=(256&n))||0!=(4&n));c=17,envStep[c]!==IDLE&&(clockEnvelope(c),h=expTable[sineTable[p?200:823]+totalAtt[c]]>>3,VOLPAN?(i+=h*volPanL[12],j+=h*volPanR[12]):k+=h),c=14,envStep[c]!==IDLE&&(clockEnvelope(c),h=expTable[sineTable[p?noiseOutput?40:10:noiseOutput?983:1013]+totalAtt[c]]>>3,VOLPAN?(i+=h*volPanL[13],j+=h*volPanR[13]):k+=h)}return VOLPAN?(sampleResult[0]=i,sampleResult[1]=j,sampleResult):k};var name,audioConnected=!1,IDLE=255,DAMP=0,ATTACK=1,DECAY=2,SUSTAIN=3,RELEASE=4,clock,noiseRegister,noiseOutput,amLevel,amLevelInc,vibPhase,registerAddress,register=new Array(56),rhythmMode,sustain=new Array(9),instr=new Array(9),keyOn=new Array(18),am=new Array(18),vib=new Array(18),envType=new Array(18),ksr=new Array(18),multi=new Array(18),ksl=new Array(18),halfWave=new Array(18),ar=new Array(18),dr=new Array(18),sl=new Array(18),rr=new Array(18),fNum=new Array(18),block=new Array(18),volume=new Array(18),modTL=new Array(18),fbShift=new Array(9),volModAtt=new Array(18),amAtt=new Array(18),envAtt=new Array(18),kslAtt=new Array(18),totalAtt=new Array(18),envStep=new Array(18),envStepLevelDur=new Array(18),envStepLevelIncClock=new Array(18),envStepLevelInc=new Array(18),envStepNext=new Array(18),envStepNextAtLevel=new Array(18),envLevel=new Array(18),ksrOffset=new Array(18),fbLastMod1=new Array(9),fbLastMod2=new Array(9),phaseInc=new Array(18),phaseCounter=new Array(18),volPanL=new Array(14),volPanR=new Array(14),sineTable,halfSineTable,expTable,instrumentsParameters,multiFactors,vibValues,kslValues,rateAttackDurTable,rateDecayDurTable,audioSocket,audioSignal,sampleResult=[0,0],VOLUME=1.58/9/256*.68,SAMPLE_RATE=49780,VOL=(WMSX.OPLL_VOL||"f").toUpperCase(),PAN=(WMSX.OPLL_PAN||"8").toUpperCase(),VOLPAN="F"!==VOL||"8"!==PAN;this.saveState=function(){return{n:name,ac:audioConnected,ra:registerAddress,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),c:clock,nr:noiseRegister,no:noiseOutput,al:amLevel,ai:amLevelInc,vp:vibPhase,amt:wmsx.Util.storeInt16BitArrayToStringBase64(amAtt),evt:wmsx.Util.storeInt16BitArrayToStringBase64(envAtt),kst:wmsx.Util.storeInt16BitArrayToStringBase64(kslAtt),tot:wmsx.Util.storeInt16BitArrayToStringBase64(totalAtt),evs:wmsx.Util.storeInt8BitArrayToStringBase64(envStep),evd:wmsx.Util.storeInt32BitArrayToStringBase64(envStepLevelDur),evc:envStepLevelIncClock,evi:wmsx.Util.storeInt8BitArrayToStringBase64(envStepLevelInc),evn:wmsx.Util.storeInt8BitArrayToStringBase64(envStepNext),evl:wmsx.Util.storeInt8BitArrayToStringBase64(envStepNextAtLevel),eve:wmsx.Util.storeInt8BitArrayToStringBase64(envLevel),kso:wmsx.Util.storeInt8BitArrayToStringBase64(ksrOffset),fb1:wmsx.Util.storeInt16BitArrayToStringBase64(fbLastMod1),fb2:wmsx.Util.storeInt16BitArrayToStringBase64(fbLastMod2)}},this.loadState=function(a){this.reset(),name=a.n,audioConnected=a.ac,registerAddress=a.ra;for(var b=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r),c=0;c<b.length;c++)registerWrite(c,b[c]);clock=a.c,noiseRegister=a.nr,noiseOutput=a.no,amLevel=a.al,amLevelInc=a.ai,vibPhase=a.vp,amAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.amt,amAtt),envAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.evt,envAtt),kslAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.kst,kslAtt),totalAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.tot,totalAtt),envStep=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evs,envStep),envStepLevelDur=wmsx.Util.restoreStringBase64ToInt32BitArray(a.evd),envStepLevelIncClock=a.evc,envStepLevelInc=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.evi,envStepLevelInc),envStepNext=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evn,envStepNext),envStepNextAtLevel=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evl,envStepNextAtLevel),envLevel=wmsx.Util.restoreStringBase64ToInt8BitArray(a.eve,envLevel),ksrOffset=wmsx.Util.restoreStringBase64ToInt8BitArray(a.kso,ksrOffset),fbLastMod1=wmsx.Util.restoreStringBase64ToSignedInt16BitArray(a.fb1,fbLastMod1),fbLastMod2=wmsx.Util.restoreStringBase64ToSignedInt16BitArray(a.fb2,fbLastMod2),audioConnected&&connectAudio()},init(),this.eval=function(str){return eval(str)}},wmsx.OPL4WaveTables=function(){"use strict";this.getRegisterWriteMasks=function(){var a,b=wmsx.Util.arrayFill(new Array(256),255);for(b[0]=b[1]=0,b[2]=29,b[3]=63,b[7]=0,a=128;a<=151;++a)b[a]=63;for(a=224;a<=247;++a)b[a]=7;for(b[248]=b[249]=63,a=250;a<=255;++a)b[a]=0;return b},this.getPanPotValues=function(){return this.PANPOT_VALUES},this.getVolumeTable=function(){for(var a=new Array(2048),b=0;b<1024;++b)a[b]=Math.pow(10,-.1875*b/20);for(b=1024;b<2048;++b)a[b]=0;return a},this.getRateAttackPatterns=function(){for(var a=new Array(832),b=0;b<64;++b)for(var c=0;c<8;++c)a[8*b+c]=b<52?this.RATE_ATTACK_SHIFTS[3&b][c]:this.RATE_ATTACK_SHIFTS[b-52+4][c];for(c=512;c<832;++c)a[c]=0;return a},this.getRateDecayPatterns=function(){for(var a=new Array(832),b=0;b<64;++b)for(var c=0;c<8;++c)a[8*b+c]=b<56?this.RATE_DECAY_INCS[3&b][c]:this.RATE_DECAY_INCS[b-56+4][c];for(c=512;c<832;++c)a[c]=2;return a},this.getLFOStepClocks=function(){for(var a=new Array(8),b=0;b<8;++b)a[b]=Math.round(44100/this.LFO_FREQS[b]/128);return a},this.getVIBOffsets=function(){for(var a=new Array(1024),b=0;b<8;++b)for(var c=this.VIB_DEPTHS[b],d=0;d<128;++d)a[128*b+d]=Math.round(d<32?d/32*c:d<96?(64-d)/32*c:(d-128)/32*c);return a},this.getAMOffsets=function(){for(var a=new Array(1024),b=0;b<8;++b)for(var c=this.AM_DEPTHS[b]/.1875,d=0;d<128;++d)a[128*b+d]=Math.round(d<64?d/64*c:(128-d)/64*c);return a},this.PANPOT_VALUES=[[0,16,32,48,64,80,96,512,512,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,512,512,96,80,64,48,32,16]],this.RATE_ATTACK_SHIFTS=[[3,-1,3,-1,3,-1,4,4],[3,-1,3,3,-1,3,3,-1],[3,3,3,-1,3,3,3,-1],[3,3,3,-1,3,3,3,4],[3,-1,4,-1,3,-1,4,4],[3,-1,3,-1,3,-1,3,4],[3,4,4,4,3,4,4,4],[3,4,3,4,3,4,3,4],[3,3,3,4,3,3,3,4],[2,3,3,3,4,3,3,3],[2,3,3,2,3,3,2,3],[2,2,3,2,2,3,2,3],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[0,0,0,0,0,0,0,0]],this.RATE_DECAY_INCS=[[-1,1,-1,1,-1,1,-1,1],[-1,1,-1,1,1,-1,1,1],[-1,1,1,1,-1,1,1,1],[-1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,2,1,1,1,2],[1,2,1,2,1,2,1,2],[1,2,2,2,1,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2]],this.LFO_FREQS=[.168,2.019,3.196,4.206,5.215,5.888,6.224,7.066],this.VIB_DEPTHS=[0,2,3,4,6,12,24,48],
this.AM_DEPTHS=[0,1.781,2.906,3.656,4.406,5.906,7.406,11.91]},wmsx.OPL4Audio=function(pName,cart){"use strict";function init(a){name=pName||"OPL4",a.fm=fm=new wmsx.OPL4AudioFM(a),a.wave=wave=new wmsx.OPL4AudioWave(a)}function connectAudio(){audioSocket&&(audioSignal||(audioSignal=new wmsx.AudioSignal(name,self,VOLUME,SAMPLE_RATE,!0,CLOCK)),audioSocket.connectAudioSignal(audioSignal),audioConnected=!0)}function disconnectAudio(){audioSocket&&audioSignal&&audioSocket.disconnectAudioSignal(audioSignal),audioConnected=!1}var self=this;this.connect=function(a){fm.connect(a),wave.connect(a),audioSocket=a.getAudioSocket(),audioConnected&&connectAudio()},this.disconnect=function(a){fm.disconnect(a),wave.disconnect(a),disconnectAudio(),audioSocket=null},this.powerOn=function(){this.reset()},this.powerOff=function(){disconnectAudio()},this.reset=function(){connectAudio(),fm.reset(),wave.reset()},this.audioClockPulse=function(){fm.audioClockPulse()},this.nextSample=function(){return wave.nextSample()},this.memoryRead=cart.opl4ReadMemory,this.memoryWrite=cart.opl4WriteMemory;var name,audioConnected=!1,fm,wave,audioSocket,audioSignal,VOLUME=7/24/32768*.66,SAMPLE_RATE=44100,CLOCK=49780;this.saveState=function(){return{n:name,ac:audioConnected,fm:fm.saveState(),wv:wave.saveState()}},this.loadState=function(a){this.reset(),name=a.n,audioConnected=a.ac,fm.loadState(a.fm),wave.loadState(a.wv),audioConnected&&connectAudio()},init(this),this.eval=function(str){return eval(str)}},wmsx.OPL4AudioFM=function(opl4){"use strict";function init(){var a=new wmsx.YM2413Tables;sineTable=a.getFullSineTable(),halfSineTable=a.getHalfSineTable(),expTable=a.getExpTable(),instrumentsParameters=a.getInstrumentsROM(),multiFactors=a.getMultiFactorsDoubled(),vibValues=a.getVIBValues(),kslValues=a.getKSLValues(),rateAttackDurTable=a.getRateAttackDurations(),rateDecayDurTable=a.getRateDecayDurations()}function clockTimers(){timer1Active&&++timer1Counter>255&&(timer1Counter=register[2],timer1Masked||(status|=192,updateIRQ())),timer2Active&&0==(15&clock)&&++timer2Counter>255&&(timer2Counter=register[3],timer2Masked||(status|=160,updateIRQ()))}function updateIRQ(){cpu.setINTChannel(2,0==(128&status))}function connectAudio(){}function registerWrite(a,b){if(4===a&&128&b)return register[4]&=-129,status=0,void updateIRQ();var c=register[a]^b;switch(register[a]=b,a){case 4:1&c&&(timer1Active=0!=(1&b))&&(timer1Counter=register[2]),2&c&&(timer2Active=0!=(2&b))&&(timer2Counter=register[3]),64&c&&(timer1Masked=0!=(64&b)),32&c&&(timer2Masked=0!=(32&b))}}function clockNoise(){noiseRegister>>=1,(noiseOutput=1&noiseRegister)&&(noiseRegister^=134230048)}function clockAM(){return!(511&clock)&&(0!==amLevel&&13!==amLevel||(amLevelInc=-amLevelInc),amLevel+=amLevelInc,!0)}function clockVIB(){return!(1023&clock)&&(vibPhase=clock>>10&7,!0)}function clockEnvelope(a){envLevel[a]===envStepNextAtLevel[a]?setEnvStepOp(a,envStepNext[a]):clock===envStepLevelIncClock[a]&&(envStepLevelIncClock[a]+=envStepLevelDur[a],envLevel[a]+=envStepLevelInc[a],updateEnvAttenuationOp(a))}function setSustain(a,b){sustain[a]=b}function setKeyOn(a,b){var c=a<<1,d=c+1;keyOn[c]=b,keyOn[d]=b,b?setEnvStep(a,DAMP):envStep[d]!==IDLE&&setEnvStepOp(d,RELEASE)}function setRhythmKeyOnOp(a,b){keyOn[a]=b,b?setEnvStepOp(a,DAMP):envStep[a]!==IDLE&&setEnvStepOp(a,RELEASE)}function setEnvStep(a,b){var c=a<<1,d=c+1;setEnvStepOp(c,b),setEnvStepOp(d,b)}function setEnvStepOp(a,b){switch(envStep[a]=b,b){case DAMP:envStepLevelDur[a]=rateDecayDurTable[48+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=ATTACK;break;case ATTACK:envStepLevelDur[a]=rateAttackDurTable[(ar[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=-8,envStepNextAtLevel[a]=0,envStepNext[a]=DECAY,phaseCounter[a]=0;break;case DECAY:envStepLevelDur[a]=rateDecayDurTable[(dr[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=sl[a]<<3,envStepNext[a]=SUSTAIN;break;case SUSTAIN:envType[a]?(envStepLevelIncClock[a]=envStepLevelDur[a]=0,envStepLevelInc[a]=0,envStepNextAtLevel[a]=255,envStepNext[a]=SUSTAIN):(envStepLevelDur[a]=rateDecayDurTable[(rr[a]<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=IDLE);break;case RELEASE:var c=envType[a]?sustain[a>>1]?5:rr[a]:sustain[a>>1]?5:7;envStepLevelDur[a]=rateDecayDurTable[(c<<2)+ksrOffset[a]],envStepLevelIncClock[a]=clock+envStepLevelDur[a],envStepLevelInc[a]=1,envStepNextAtLevel[a]=128,envStepNext[a]=IDLE;break;case IDLE:default:envLevel[a]=128,envStepLevelIncClock[a]=envStepLevelDur[a]=0,envStepLevelInc[a]=0,envStepNextAtLevel[a]=255,envStepNext[a]=IDLE}}function setRhythmMode(a){rhythmMode=a,rhythmMode?(audioConnected||connectAudio(),setInstr(6,16),setInstr(7,17),setInstr(8,18)):(setEnvStep(6,IDLE),updateEnvAttenuation(6),setEnvStep(7,IDLE),updateEnvAttenuation(7),setEnvStep(8,IDLE),updateEnvAttenuation(8),setInstr(6,register[36]>>4),setInstr(7,register[37]>>4),setInstr(8,register[38]>>4))}function setInstr(a,b){instr[a]=b;var c=a<<1,d=c+1,e=instrumentsParameters[b];am[c]=e[0]>>7&1,am[d]=e[1]>>7&1,vib[c]=e[0]>>6&1,vib[d]=e[1]>>6&1,envType[c]=e[0]>>5&1,envType[d]=e[1]>>5&1,ksr[c]=e[0]>>4&1,ksr[d]=e[1]>>4&1,multi[c]=multiFactors[15&e[0]],multi[d]=multiFactors[15&e[1]],ksl[c]=e[2]>>6,ksl[d]=e[3]>>6,modTL[c]=63&e[2],halfWave[c]=e[3]>>3&1,halfWave[d]=e[3]>>4&1,fbShift[a]=7&e[3]?8-(7&e[3]):0,ar[c]=e[4]>>4,ar[d]=e[5]>>4,dr[c]=15&e[4],dr[d]=15&e[5],sl[c]=e[6]>>4,sl[d]=e[7]>>4,rr[c]=15&e[6],rr[d]=15&e[7],updateAMAttenuation(a),updateFrequency(a),updateModAttenuationOp(c)}function updateCustomInstrChannels(){for(var a=0;a<9;a++)0===instr[a]&&setInstr(a,0)}function setVolumeOp(a,b){volume[a]=b,updateVolumeAttenuationOp(a)}function updateFrequency(a){var b=a<<1,c=b+1,d=vib[b]?vibValues[fNum[b]>>6][vibPhase]:0;phaseInc[b]=((fNum[b]<<1)+d)*multi[b]<<block[b]>>2,d=vib[c]?vibValues[fNum[c]>>6][vibPhase]:0,phaseInc[c]=((fNum[c]<<1)+d)*multi[c]<<block[c]>>2,updateKSLAttenuation(a),updateKSROffset(a)}function updateFrequencyOp(a){var b=vib[a]?vibValues[fNum[a]>>6][vibPhase]:0;phaseInc[a]=((fNum[a]<<1)+b)*multi[a]<<block[a]>>2,updateKSLAttenuationOp(a),updateKSROffsetOp(a)}function updateKSROffset(a){var b=a<<1,c=b+1;ksrOffset[b]=(ksr[b]?block[b]<<1:block[b]>>1)|fNum[b]>>>9-ksr[b],ksrOffset[c]=(ksr[c]?block[c]<<1:block[c]>>1)|fNum[c]>>>9-ksr[c]}function updateKSROffsetOp(a){ksrOffset[a]=(ksr[a]?block[a]<<1:block[a]>>1)|fNum[a]>>>9-ksr[a]}function updateAMAttenuation(a){var b=a<<1,c=b+1;amAtt[b]=am[b]?amLevel<<4:0,amAtt[c]=am[c]?amLevel<<4:0,updateTotalAttenuation(a)}function updateAMAttenuationOp(a){amAtt[a]=am[a]?amLevel<<4:0,updateTotalAttenuationOp(a)}function updateKSLAttenuation(a){var b=a<<1,c=b+1;kslAtt[b]=kslValues[ksl[b]][block[b]][fNum[b]>>>5]<<4,kslAtt[c]=kslValues[ksl[c]][block[c]][fNum[c]>>>5]<<4,updateTotalAttenuation(a)}function updateKSLAttenuationOp(a){kslAtt[a]=kslValues[ksl[a]][block[a]][fNum[a]>>>5]<<4,updateTotalAttenuationOp(a)}function updateEnvAttenuation(a){var b=a<<1,c=b+1;envAtt[b]=(128===envLevel[b]?256:envLevel[b])<<4,envAtt[c]=(128===envLevel[c]?256:envLevel[c])<<4,updateTotalAttenuation(a)}function updateEnvAttenuationOp(a){envAtt[a]=(128===envLevel[a]?256:envLevel[a])<<4,updateTotalAttenuationOp(a)}function updateModAttenuationOp(a){volModAtt[a]=modTL[a]<<5,updateTotalAttenuationOp(a)}function updateVolumeAttenuationOp(a){volModAtt[a]=(15===volume[a]?30:volume[a])<<7,updateTotalAttenuationOp(a)}function updateTotalAttenuation(a){var b=a<<1,c=b+1;totalAtt[b]=amAtt[b]+kslAtt[b]+envAtt[b]+volModAtt[b],totalAtt[c]=amAtt[c]+kslAtt[c]+envAtt[c]+volModAtt[c]}function updateTotalAttenuationOp(a){totalAtt[a]=amAtt[a]+kslAtt[a]+envAtt[a]+volModAtt[a]}var self=this;this.connect=function(a){cpu=a.cpu,
a.bus.connectInputDevice(196,this.inputC4),a.bus.connectOutputDevice(196,this.outputC4),a.bus.connectInputDevice(197,this.inputC5),a.bus.connectOutputDevice(197,this.outputC5),a.bus.connectInputDevice(198,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectOutputDevice(198,this.outputC6),a.bus.connectInputDevice(199,this.inputC5),a.bus.connectOutputDevice(199,this.outputC5)},this.disconnect=function(a){a.bus.disconnectInputDevice(196,this.inputC4),a.bus.disconnectOutputDevice(196,this.outputC4),a.bus.disconnectInputDevice(197,this.inputC5),a.bus.disconnectOutputDevice(197,this.outputC5),a.bus.disconnectInputDevice(198,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectOutputDevice(198,this.outputC6),a.bus.disconnectInputDevice(199,this.inputC5),a.bus.disconnectOutputDevice(199,this.outputC5)},this.reset=function(){status=0,registerAddress=0,wmsx.Util.arrayFill(register,0),clock=0,busyUntilBUSCycle=0,timer1Counter=timer2Counter=0,timer1Active=timer2Active=!1,timer1Masked=timer2Masked=0,wmsx.Util.arrayFill(instrumentsParameters[0],0),noiseRegister=65535,noiseOutput=0,amLevel=0,amLevelInc=-1,vibPhase=0,rhythmMode=!1,wmsx.Util.arrayFill(sustain,0),wmsx.Util.arrayFill(instr,0),wmsx.Util.arrayFill(keyOn,0),wmsx.Util.arrayFill(am,0),wmsx.Util.arrayFill(vib,0),wmsx.Util.arrayFill(envType,0),wmsx.Util.arrayFill(ksr,0),wmsx.Util.arrayFill(multi,0),wmsx.Util.arrayFill(ksl,0),wmsx.Util.arrayFill(halfWave,0),wmsx.Util.arrayFill(ar,0),wmsx.Util.arrayFill(dr,0),wmsx.Util.arrayFill(sl,0),wmsx.Util.arrayFill(rr,0),wmsx.Util.arrayFill(fNum,0),wmsx.Util.arrayFill(block,0),wmsx.Util.arrayFill(volume,0),wmsx.Util.arrayFill(modTL,0),wmsx.Util.arrayFill(fbShift,0),wmsx.Util.arrayFill(volModAtt,0),wmsx.Util.arrayFill(amAtt,0),wmsx.Util.arrayFill(envAtt,0),wmsx.Util.arrayFill(kslAtt,0),wmsx.Util.arrayFill(totalAtt,0),wmsx.Util.arrayFill(envStep,IDLE),wmsx.Util.arrayFill(envStepLevelDur,0),wmsx.Util.arrayFill(envStepLevelIncClock,0),wmsx.Util.arrayFill(envStepLevelInc,0),wmsx.Util.arrayFill(envStepNext,DAMP),wmsx.Util.arrayFill(envStepNextAtLevel,0),wmsx.Util.arrayFill(envLevel,0),wmsx.Util.arrayFill(ksrOffset,0),wmsx.Util.arrayFill(fbLastMod1,0),wmsx.Util.arrayFill(fbLastMod2,0),wmsx.Util.arrayFill(phaseInc,0),wmsx.Util.arrayFill(phaseCounter,0)},this.inputC4=function(){return status},this.outputC4=function(a){registerAddress=a},this.inputC5=function(){return register[registerAddress]},this.outputC5=function(a){registerWrite(registerAddress,a)},this.outputC6=function(a){registerAddress=256|a},this.audioClockPulse=function(){0==(3&++clock)&&clockTimers()},this.setBusyCycles=function(a){},this.nextSample=function(){return 0};var cpu,busyUntilBUSCycle,audioConnected=!1,status=0,registerAddress=0,register=new Array(56),timer1Counter=0,timer2Counter=0,timer1Active=!1,timer2Active=!1,timer1Masked=!1,timer2Masked=!1,IDLE=255,DAMP=0,ATTACK=1,DECAY=2,SUSTAIN=3,RELEASE=4,clock,noiseRegister,noiseOutput,amLevel,amLevelInc,vibPhase,rhythmMode,sustain=new Array(9),instr=new Array(9),keyOn=new Array(18),am=new Array(18),vib=new Array(18),envType=new Array(18),ksr=new Array(18),multi=new Array(18),ksl=new Array(18),halfWave=new Array(18),ar=new Array(18),dr=new Array(18),sl=new Array(18),rr=new Array(18),fNum=new Array(18),block=new Array(18),volume=new Array(18),modTL=new Array(18),fbShift=new Array(9),volModAtt=new Array(18),amAtt=new Array(18),envAtt=new Array(18),kslAtt=new Array(18),totalAtt=new Array(18),envStep=new Array(18),envStepLevelDur=new Array(18),envStepLevelIncClock=new Array(18),envStepLevelInc=new Array(18),envStepNext=new Array(18),envStepNextAtLevel=new Array(18),envLevel=new Array(18),ksrOffset=new Array(18),fbLastMod1=new Array(9),fbLastMod2=new Array(9),phaseInc=new Array(18),phaseCounter=new Array(18),sineTable,halfSineTable,expTable,instrumentsParameters,multiFactors,vibValues,kslValues,rateAttackDurTable,rateDecayDurTable,VOLUME=1.55/9/256*.65;this.saveState=function(){return{ac:audioConnected,s:status,ra:registerAddress,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),c:clock,nr:noiseRegister,no:noiseOutput,al:amLevel,ai:amLevelInc,vp:vibPhase,t1c:timer1Counter,t2c:timer2Counter,t1a:timer1Active,t2a:timer2Active,t1m:timer1Masked,t2m:timer2Masked,amt:wmsx.Util.storeInt16BitArrayToStringBase64(amAtt),evt:wmsx.Util.storeInt16BitArrayToStringBase64(envAtt),kst:wmsx.Util.storeInt16BitArrayToStringBase64(kslAtt),tot:wmsx.Util.storeInt16BitArrayToStringBase64(totalAtt),evs:wmsx.Util.storeInt8BitArrayToStringBase64(envStep),evd:wmsx.Util.storeInt32BitArrayToStringBase64(envStepLevelDur),evc:envStepLevelIncClock,evi:wmsx.Util.storeInt8BitArrayToStringBase64(envStepLevelInc),evn:wmsx.Util.storeInt8BitArrayToStringBase64(envStepNext),evl:wmsx.Util.storeInt8BitArrayToStringBase64(envStepNextAtLevel),eve:wmsx.Util.storeInt8BitArrayToStringBase64(envLevel),kso:wmsx.Util.storeInt8BitArrayToStringBase64(ksrOffset),fb1:wmsx.Util.storeInt16BitArrayToStringBase64(fbLastMod1),fb2:wmsx.Util.storeInt16BitArrayToStringBase64(fbLastMod2)}},this.loadState=function(a){this.reset(),audioConnected=a.ac,status=a.s,registerAddress=a.ra;for(var b=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r),c=0;c<b.length;c++)registerWrite(c,b[c]);clock=a.c,noiseRegister=a.nr,noiseOutput=a.no,amLevel=a.al,amLevelInc=a.ai,vibPhase=a.vp,timer1Counter=a.t1c,timer2Counter=a.t2c,timer1Active=a.t1a,timer2Active=a.t2a,timer1Masked=a.t1m,timer2Masked=a.t2m,amAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.amt,amAtt),envAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.evt,envAtt),kslAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.kst,kslAtt),totalAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.tot,totalAtt),envStep=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evs,envStep),envStepLevelDur=wmsx.Util.restoreStringBase64ToInt32BitArray(a.evd),envStepLevelIncClock=a.evc,envStepLevelInc=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.evi,envStepLevelInc),envStepNext=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evn,envStepNext),envStepNextAtLevel=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evl,envStepNextAtLevel),envLevel=wmsx.Util.restoreStringBase64ToInt8BitArray(a.eve,envLevel),ksrOffset=wmsx.Util.restoreStringBase64ToInt8BitArray(a.kso,ksrOffset),fbLastMod1=wmsx.Util.restoreStringBase64ToSignedInt16BitArray(a.fb1,fbLastMod1),fbLastMod2=wmsx.Util.restoreStringBase64ToSignedInt16BitArray(a.fb2,fbLastMod2)},init(),this.eval=function(str){return eval(str)}},wmsx.OPL4AudioWave=function(opl4){"use strict";function init(){var a=new wmsx.OPL4WaveTables;regWriteMasks=a.getRegisterWriteMasks(),rateAttackPatterns=a.getRateAttackPatterns(),rateDecayPatterns=a.getRateDecayPatterns(),lfoStepClocks=a.getLFOStepClocks(),vibStepOffsets=a.getVIBOffsets(),amStepOffsets=a.getAMOffsets(),panpotValues=a.getPanPotValues(),volumeTable=a.getVolumeTable()}function registerWrite(a,b){var c,d=register[a]^b,e=regWriteMasks[a];switch(register[a]=register[a]&~e|b&e,a){case 5:memoryAddress=(63&register[3])<<16|register[4]<<8|register[5];break;case 6:opl4.memoryWrite(memoryAddress,b),++memoryAddress>=4194304&&(memoryAddress=0);break;case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:c=a-8,readWaveHeader(c,(1&register[32+c])<<8|b);break;case 32:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:c=a-32,254&d&&(fNum[c]=b>>1|(7&register[56+c])<<7,updateFrequency(c));break;case 56:case 57:case 58:case 59:case 60:case 61:case 62:case 63:case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:c=a-56,240&d&&(octave[c]=128&b?(b>>4)-16:b>>4),7&d&&(fNum[c]=(7&b)<<7|register[32+c]>>1),
247&d&&updateFrequency(c),8&d&&(reverb[c]=(8&b)>>3);break;case 80:case 81:case 82:case 83:case 84:case 85:case 86:case 87:case 88:case 89:case 90:case 91:case 92:case 93:case 94:case 95:case 96:case 97:case 98:case 99:case 100:case 101:case 102:case 103:c=a-80,254&d&&(volumeAtt[c]=254&b,updateSettingsAttenuation(c));break;case 104:case 105:case 106:case 107:case 108:case 109:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:case 119:case 120:case 121:case 122:case 123:case 124:case 125:case 126:case 127:c=a-104,192&d&&setKeyOnAndDamp(c,128&b,64&b),32&d&&setLFOReset(c,32&b),15&d&&(panpotAttL[c]=panpotValues[0][15&b],panpotAttR[c]=panpotValues[1][15&b],updateSettingsAttenuation(c));break;case 128:case 129:case 130:case 131:case 132:case 133:case 134:case 135:case 136:case 137:case 138:case 139:case 140:case 141:case 142:case 143:case 144:case 145:case 146:case 147:case 148:case 149:case 150:case 151:c=a-128,56&d&&(lfoStepDur[c]=lfoStepClocks[(56&b)>>3]),7&d&&(vibDepth[c]=7&b,updateVIBOffset(c,lfoStep[c]));break;case 152:case 153:case 154:case 155:case 156:case 157:case 158:case 159:case 160:case 161:case 162:case 163:case 164:case 165:case 166:case 167:case 168:case 169:case 170:case 171:case 172:case 173:case 174:case 175:c=a-152,240&d&&(ar[c]=b>=240?63:(240&b)>>2),15&d&&(d1r[c]=15==(15&b)?63:(15&b)<<2);break;case 176:case 177:case 178:case 179:case 180:case 181:case 182:case 183:case 184:case 185:case 186:case 187:case 188:case 189:case 190:case 191:case 192:case 193:case 194:case 195:case 196:case 197:case 198:case 199:c=a-176,240&d&&(dl[c]=(b>=240?31:b>>4)<<4),15&d&&(d2r[c]=15==(15&b)?63:(15&b)<<2);break;case 200:case 201:case 202:case 203:case 204:case 205:case 206:case 207:case 208:case 209:case 210:case 211:case 212:case 213:case 214:case 215:case 216:case 217:case 218:case 219:case 220:case 221:case 222:case 223:c=a-200,240&d&&(rc[c]=b>>4,updateRateCorrOffset(c)),15&d&&(rr[c]=15==(15&b)?63:(15&b)<<2);break;case 224:case 225:case 226:case 227:case 228:case 229:case 230:case 231:case 232:case 233:case 234:case 235:case 236:case 237:case 238:case 239:case 240:case 241:case 242:case 243:case 244:case 245:case 246:case 247:c=a-224,7&d&&(amDepth[c]=7&b,updateAMAttenuation(c,lfoStep[c]));break;case 249:if(63&d)for(mixerAttL=7==(7&b)?512:(7&b)<<4,mixerAttR=56==(56&b)?512:(56&b)<<1,c=23;c>=0;--c)updateSettingsAttenuation(c)}}function registerRead(a){var b;switch(a){case 6:b=opl4.memoryRead(memoryAddress),++memoryAddress>=4194304&&(memoryAddress=0);break;default:b=register[a]}return b}function readWaveHeader(a,b){var c=register[2]>>2&7,d=b<384||0===c?12*b:(c<<19)+12*(b-384),e=opl4.memoryRead(d++);dataBits[a]=e>>6,startAddress[a]=(63&e)<<16|opl4.memoryRead(d++)<<8|opl4.memoryRead(d++),loopPosition[a]=opl4.memoryRead(d++)<<8|opl4.memoryRead(d++),endPosition[a]=65535&~(opl4.memoryRead(d++)<<8|opl4.memoryRead(d++)),registerWrite(128+a,opl4.memoryRead(d++)),registerWrite(152+a,opl4.memoryRead(d++)),registerWrite(176+a,opl4.memoryRead(d++)),registerWrite(200+a,opl4.memoryRead(d++)),registerWrite(224+a,opl4.memoryRead(d++)),envStep[a]!==IDLE&&startSample(a)}function clockLFO(a){return clock!==lfoStepChangeClock[a]?-1:(lfoStepChangeClock[a]+=lfoStepDur[a],lfoStep[a]=lfoStep[a]+1&127)}function updateVIBOffset(a,b){var c=vibStepOffsets[vibDepth[a]<<7|b];vibOffset[a]!==c&&(vibOffset[a]=c,updateFrequency(a))}function updateAMAttenuation(a,b){var c=amStepOffsets[amDepth[a]<<7|b];amAtt[a]!==c&&(amAtt[a]=c,updateDynamicLevel(a))}function clockEnvelope(a){if(clock===envStepLevelChangeClock[a]){var b=envStepLevelPattCounter[a]=envStepLevelPattCounter[a]+1&7;if(envStep[a]===ATTACK){var c=rateAttackPatterns[envStepRate[a]<<3|b];if(c>=0){if(envAtt[a]-=1+(envAtt[a]>>c),envAtt[a]<=0)return setEnvStep(a,DECAY1);updateDynamicLevel(a)}}else if((c=rateDecayPatterns[envStepRate[a]<<3|b])>=0){if(envAtt[a]+=c,envAtt[a]>=envStepNextAtLevel[a])return setEnvStep(a,envStepNext[a]);updateDynamicLevel(a)}envStepLevelChangeClock[a]+=envStepLevelDur[a]}}function setKeyOnAndDamp(a,b,c){c?envStep[a]!==IDLE&&envStep[a]!==DAMP&&setEnvStep(a,DAMP):b?(startSample(a),setEnvStep(a,ATTACK)):envStep[a]!==IDLE&&envStep[a]!==REVERB&&envStep[a]!==DAMP&&setEnvStep(a,RELEASE)}function setLFOReset(a,b){b?(lfoStep[a]=0,lfoStepChangeClock[a]=0,0!==vibOffset[a]&&(vibOffset[a]=0,updateFrequency(a)),0!==amAtt[a]&&(amAtt[a]=0,updateDynamicLevel(a))):lfoStepChangeClock[a]=clock+lfoStepDur[a]}function startSample(a){samplePos[a]=0,phaseCounter[a]=0,sampleValue[a]=readSample(a,0),sampleValue2[a]=readSample(a,advancedSamplePos(a,0,1))}function advanceSample(a,b){var c=advancedSamplePos(a,samplePos[a],b);samplePos[a]=c,sampleValue[a]=readSample(a,c),sampleValue2[a]=readSample(a,advancedSamplePos(a,c,1))}function advancedSamplePos(a,b,c){var d=b+c;return d>endPosition[a]?loopPosition[a]+(d-endPosition[a])-1:d}function readSample(a,b){var c,d,e=startAddress[a],f=dataBits[a];return 1===f?(c=e+3*(b>>1),d=1&b?opl4.memoryRead(c+2)<<4|15&opl4.memoryRead(c+1):opl4.memoryRead(c)<<4|opl4.memoryRead(c+1)>>4,d=d<<4|(2047&d)>>7):2===f?(c=e+(b<<1),d=opl4.memoryRead(c)<<8|opl4.memoryRead(c+1)):0===f?(c=e+b,d=opl4.memoryRead(c),d=d<<8|(127&d)<<1):d=0,32768&d?d-65536:d}function setEnvStep(a,b){var c,d;switch(b){case ATTACK:d=0===ar[a]?0:ar[a]+rcOffset[a];break;case DECAY1:if(envAtt[a]=0,0===(c=dl[a]))return setEnvStep(a,DECAY2);d=0===d1r[a]?0:d1r[a]+rcOffset[a],reverb[a]&&c>=REVERB_ENV_LEVEL?(envStepNextAtLevel[a]=REVERB_ENV_LEVEL,envStepNext[a]=REVERB):(envStepNextAtLevel[a]=c,envStepNext[a]=DECAY2);break;case DECAY2:d=0===d2r[a]?0:d2r[a]+rcOffset[a],reverb[a]&&envAtt[a]<REVERB_ENV_LEVEL?(envStepNextAtLevel[a]=REVERB_ENV_LEVEL,envStepNext[a]=REVERB):(envStepNextAtLevel[a]=512,envStepNext[a]=IDLE);break;case RELEASE:if(d=0===rr[a]?0:rr[a]+rcOffset[a],reverb[a]){if(!(envAtt[a]<REVERB_ENV_LEVEL))return setEnvStep(a,REVERB);envStepNextAtLevel[a]=REVERB_ENV_LEVEL,envStepNext[a]=REVERB}else envStepNextAtLevel[a]=512,envStepNext[a]=IDLE;break;case REVERB:d=REVERB_RATE,envStepNextAtLevel[a]=512,envStepNext[a]=IDLE;break;case DAMP:d=DAMP_RATE,envStepNextAtLevel[a]=512,envStepNext[a]=IDLE;break;case IDLE:default:d=0,envAtt[a]=512,envStepNextAtLevel[a]=1024,envStepNext[a]=IDLE}envStep[a]=b,envStepRate[a]=d,envStepLevelDur[a]=d<4?0:d>=52?1:1<<13-(d>>2),envStepLevelChangeClock[a]=clock+envStepLevelDur[a],envStepLevelPattCounter[a]=0,updateDynamicLevel(a)}function updateFrequency(a){phaseInc[a]=(1024+fNum[a]<<8)+256*vibOffset[a]>>8-octave[a]+1,updateRateCorrOffset(a)}function updateRateCorrOffset(a){if(15===rc[a])return rcOffset[a]=0;var b=(rc[a]+octave[a]<<1)+(fNum[a]>>9);rcOffset[a]=b>=0?b:0}function updateSettingsAttenuation(a){settingsAttL[a]=volumeAtt[a]+panpotAttL[a]+mixerAttL,settingsAttR[a]=volumeAtt[a]+panpotAttR[a]+mixerAttR,updateDynamicLevel(a)}function updateDynamicLevel(a){var b=amAtt[a]+envAtt[a];dynamicLevelL[a]=volumeTable[b+settingsAttL[a]],dynamicLevelR[a]=volumeTable[b+settingsAttR[a]]}var self=this;this.connect=function(a){a.bus.connectOutputDevice(126,this.output7E),a.bus.connectInputDevice(127,this.input7F),a.bus.connectOutputDevice(127,this.output7F)},this.disconnect=function(a){a.bus.disconnectOutputDevice(126,this.output7E),a.bus.disconnectInputDevice(127,this.input7F),a.bus.disconnectOutputDevice(127,this.output7F)},this.reset=function(){clock=0,memoryAddress=0,registerAddress=0,wmsx.Util.arrayFill(register,0),register[2]=34,register[248]=27,register[0]=register[1]=register[7]=register[250]=register[251]=register[252]=register[253]=register[254]=register[255]=255,wmsx.Util.arrayFill(dataBits,0),wmsx.Util.arrayFill(startAddress,0),wmsx.Util.arrayFill(loopPosition,0),wmsx.Util.arrayFill(endPosition,0),wmsx.Util.arrayFill(phaseInc,512),wmsx.Util.arrayFill(fNum,0),wmsx.Util.arrayFill(octave,0),wmsx.Util.arrayFill(reverb,0),wmsx.Util.arrayFill(ar,0),wmsx.Util.arrayFill(d1r,0),
wmsx.Util.arrayFill(dl,0),wmsx.Util.arrayFill(d2r,0),wmsx.Util.arrayFill(rr,0),wmsx.Util.arrayFill(rc,0),wmsx.Util.arrayFill(rcOffset,0),wmsx.Util.arrayFill(lfoStepDur,0),wmsx.Util.arrayFill(vibDepth,0),wmsx.Util.arrayFill(amDepth,0),wmsx.Util.arrayFill(volumeAtt,0),wmsx.Util.arrayFill(panpotAttL,0),wmsx.Util.arrayFill(panpotAttR,0),mixerAttL=0,mixerAttR=0,wmsx.Util.arrayFill(samplePos,0),wmsx.Util.arrayFill(sampleValue,0),wmsx.Util.arrayFill(sampleValue2,0),wmsx.Util.arrayFill(phaseCounter,0),wmsx.Util.arrayFill(envStep,IDLE),wmsx.Util.arrayFill(envStepNext,IDLE),wmsx.Util.arrayFill(envStepNextAtLevel,0),wmsx.Util.arrayFill(envStepRate,0),wmsx.Util.arrayFill(envStepLevelDur,0),wmsx.Util.arrayFill(envStepLevelChangeClock,0),wmsx.Util.arrayFill(envStepLevelPattCounter,0),wmsx.Util.arrayFill(envAtt,512),wmsx.Util.arrayFill(lfoStep,0),wmsx.Util.arrayFill(lfoStepChangeClock,0),wmsx.Util.arrayFill(vibOffset,0),wmsx.Util.arrayFill(amAtt,0),wmsx.Util.arrayFill(settingsAttL,0),wmsx.Util.arrayFill(settingsAttR,0),wmsx.Util.arrayFill(dynamicLevelL,0),wmsx.Util.arrayFill(dynamicLevelR,0)},this.output7E=function(a){registerAddress=a},this.input7F=function(){return registerRead(registerAddress)},this.output7F=function(a){registerWrite(registerAddress,a)},this.nextSample=function(){var a,b,c,d,e,f=0,g=0,h=0;for(++clock,e=23;e>=0;--e)a=clockLFO(e),a>=0&&(vibDepth[e]&&updateVIBOffset(e,a),amDepth[e]&&updateAMAttenuation(e,a)),envStep[e]!==IDLE&&(clockEnvelope(e),b=phaseCounter[e],c=phaseCounter[e]=b+phaseInc[e]&2147483647,d=(c>>10)-(b>>10),d>0&&advanceSample(e,d),f=sampleValue[e]*(1024-(1023&c))+sampleValue2[e]*(1023&c)>>10,g+=f*dynamicLevelL[e],h+=f*dynamicLevelR[e]);return sampleResult[0]=g,sampleResult[1]=h,sampleResult};var memoryAddress,registerAddress,register=new Array(255),clock,dataBits=new Array(24),startAddress=new Array(24),loopPosition=new Array(24),endPosition=new Array(24),samplePos=new Array(24),sampleValue=new Array(24),sampleValue2=new Array(24),phaseInc=new Array(24),phaseCounter=new Array(24),fNum=new Array(24),octave=new Array(24),reverb=new Array(24),ar=new Array(24),d1r=new Array(24),dl=new Array(24),d2r=new Array(24),rc=new Array(24),rr=new Array(24),rcOffset=new Array(24),lfoStepDur=new Array(24),vibDepth=new Array(24),amDepth=new Array(24),volumeAtt=new Array(24),panpotAttL=new Array(24),panpotAttR=new Array(24),mixerAttL=0,mixerAttR=0,settingsAttL=new Array(24),settingsAttR=new Array(24),envStep=new Array(24),envStepNext=new Array(24),envStepNextAtLevel=new Array(24),envStepRate=new Array(24),envStepLevelDur=new Array(24),envStepLevelChangeClock=new Array(24),envStepLevelPattCounter=new Array(24),envAtt=new Array(24),lfoStep=new Array(24),lfoStepChangeClock=new Array(24),vibOffset=new Array(24),amAtt=new Array(24),dynamicLevelL=new Array(24),dynamicLevelR=new Array(24),IDLE=255,ATTACK=1,DECAY1=2,DECAY2=3,RELEASE=4,REVERB=5,DAMP=6,REVERB_ENV_LEVEL=96,REVERB_RATE=20,DAMP_RATE=60,regWriteMasks,rateAttackPatterns,rateDecayPatterns,lfoStepClocks,vibStepOffsets,amStepOffsets,panpotValues,volumeTable,sampleResult=[0,0];this.saveState=function(){return{c:clock,ra:registerAddress,ma:memoryAddress,r:wmsx.Util.storeInt8BitArrayToStringBase64(register),db:wmsx.Util.storeInt8BitArrayToStringBase64(dataBits),sa:wmsx.Util.storeInt32BitArrayToStringBase64(startAddress),lp:wmsx.Util.storeInt16BitArrayToStringBase64(loopPosition),ep:wmsx.Util.storeInt16BitArrayToStringBase64(endPosition),sp:wmsx.Util.storeInt16BitArrayToStringBase64(samplePos),sv:wmsx.Util.storeInt16BitArrayToStringBase64(sampleValue),pc:wmsx.Util.storeInt32BitArrayToStringBase64(phaseCounter),evs:wmsx.Util.storeInt8BitArrayToStringBase64(envStep),evr:wmsx.Util.storeInt8BitArrayToStringBase64(envStepRate),evd:wmsx.Util.storeInt32BitArrayToStringBase64(envStepLevelDur),evc:envStepLevelChangeClock,evn:wmsx.Util.storeInt8BitArrayToStringBase64(envStepNext),evl:wmsx.Util.storeInt16BitArrayToStringBase64(envStepNextAtLevel),epc:wmsx.Util.storeInt8BitArrayToStringBase64(envStepLevelPattCounter),eva:wmsx.Util.storeInt16BitArrayToStringBase64(envAtt),lfs:wmsx.Util.storeInt8BitArrayToStringBase64(lfoStep),lfc:lfoStepChangeClock,vio:wmsx.Util.storeInt8BitArrayToStringBase64(vibOffset),ama:wmsx.Util.storeInt8BitArrayToStringBase64(amAtt),saL:wmsx.Util.storeInt16BitArrayToStringBase64(settingsAttL),saR:wmsx.Util.storeInt16BitArrayToStringBase64(settingsAttR),dlvL:dynamicLevelL,dlvR:dynamicLevelR}},this.loadState=function(a){this.reset(),registerAddress=a.ra;for(var b=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r),c=2;c<6;c++)registerWrite(c,b[c]);for(c=8;c<32;c++)register[c]=b[c];for(c=32;c<250;c++)registerWrite(c,b[c]);memoryAddress=a.ma,clock=a.c,dataBits=wmsx.Util.restoreStringBase64ToInt8BitArray(a.db,dataBits),startAddress=wmsx.Util.restoreStringBase64ToInt32BitArray(a.sa,startAddress),loopPosition=wmsx.Util.restoreStringBase64ToInt16BitArray(a.lp,loopPosition),endPosition=wmsx.Util.restoreStringBase64ToInt16BitArray(a.ep,endPosition),phaseCounter=wmsx.Util.restoreStringBase64ToInt32BitArray(a.pc,phaseCounter),samplePos=wmsx.Util.restoreStringBase64ToInt16BitArray(a.sp,samplePos),sampleValue=wmsx.Util.restoreStringBase64ToSignedInt16BitArray(a.sv,sampleValue),envStep=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evs,envStep),envStepRate=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evr,envStepRate),envStepLevelDur=wmsx.Util.restoreStringBase64ToInt32BitArray(a.evd,envStepLevelDur),envStepLevelChangeClock=a.evc,envStepNext=wmsx.Util.restoreStringBase64ToInt8BitArray(a.evn,envStepNext),envStepNextAtLevel=wmsx.Util.restoreStringBase64ToInt16BitArray(a.evl,envStepNextAtLevel),envStepLevelPattCounter=wmsx.Util.restoreStringBase64ToInt16BitArray(a.epc,envStepLevelPattCounter),envAtt=wmsx.Util.restoreStringBase64ToInt16BitArray(a.eva,envAtt),lfoStep=wmsx.Util.restoreStringBase64ToInt8BitArray(a.lfs,lfoStep),lfoStepChangeClock=a.lfc,vibOffset=wmsx.Util.restoreStringBase64ToSignedInt8BitArray(a.vio,vibOffset),amAtt=wmsx.Util.restoreStringBase64ToInt8BitArray(a.ama,amAtt),settingsAttL=wmsx.Util.restoreStringBase64ToInt16BitArray(a.saL,settingsAttL),settingsAttR=wmsx.Util.restoreStringBase64ToInt16BitArray(a.saR,settingsAttR),dynamicLevelL=a.dlvL,dynamicLevelR=a.dlvR},init(),this.eval=function(str){return eval(str)}},wmsx.RTC=function(a){"use strict";function b(a){j!==a&&(a?(d(),j=!0):(j=!1,c()))}function c(){i||(i=new Date(Math.floor(h))),l[0]=i.getUTCSeconds()%10,l[1]=i.getUTCSeconds()/10|0,l[2]=i.getUTCMinutes()%10,l[3]=i.getUTCMinutes()/10|0,m[10]?(l[4]=i.getUTCHours()%10,l[5]=i.getUTCHours()/10|0):(l[4]=i.getUTCHours()%12%10,l[5]=i.getUTCHours()%12/10|0,i.getUTCHours()>=12&&(l[5]|=2)),l[6]=i.getUTCDay()+1,l[7]=i.getUTCDate()%10,l[8]=i.getUTCDate()/10|0,l[9]=(i.getUTCMonth()+1)%10,l[10]=(i.getUTCMonth()+1)/10|0,l[11]=(i.getUTCFullYear()-1980)%10,l[12]=(i.getUTCFullYear()-1980)/10|0}function d(){i||(i=new Date),i.setUTCSeconds(l[0]+10*l[1]),i.setUTCMinutes(l[2]+10*l[3]),1&m[10]?i.setUTCHours(l[4]+10*l[5]):i.setUTCHours(l[4]+(2&l[5]?12:0)+(1&l[5]?10:0)),i.setUTCDate(l[7]+10*l[8]),i.setUTCMonth(l[9]+10*l[10]-1),i.setUTCFullYear(l[11]+10*l[12]+1980),h=i.getTime()}function e(a){if(a&=1,(1&m[10])!==a){var b;a?(b=l[4]+(2&l[5]?12:0)+(1&l[5]?10:0),l[5]=b/10|0,l[4]=b%10):(b=l[4]+10*l[5],l[5]=(b>=12?2:0)|(b%12>=10?1:0),l[4]=b%12%10)}}this.setMachineType=function(a){f=WMSX.RTC_ACTIVE>=0?!!WMSX.RTC_ACTIVE:a>=wmsx.Machine.MACHINE_TYPE.MSX2,f&&wmsx.Util.arrayFill(n[0],0),wmsx.Util.arrayFill(n[1],0)},this.connectBus=function(a){a.connectInputDevice(180,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(180,this.outputB4),a.connectInputDevice(181,this.inputB5),a.connectOutputDevice(181,this.outputB5)},this.powerOn=function(){this.reset()},this.powerOff=function(){},this.reset=function(){g=0,b(!0)},this.videoClockPulse=function(){h+=k,i&&(i=void 0)},this.setFps=function(a){k=1e3/a},
this.syncTimeWithSource=function(){var b=a.getRealTime();b<=h||(h=b,j||c())},this.outputB4=function(a){f&&(o=15&a)},this.outputB5=function(a){if(f)if(a&=15,o<13)switch(g){case 0:l[o]=a&p[o];break;case 1:10===o&&e(a),m[o]=a&q[o];break;case 2:case 3:n[1&g][o]=a}else switch(o){case 13:g=3&a,b(0!=(8&a))}},this.inputB5=function(){if(!f)return 255;var a;if(o<13)switch(g){case 0:j&&c(),a=l[o];break;case 1:a=m[o];break;case 2:case 3:a=n[1&g][o]}else switch(o){case 13:a=(j?8:0)|g;break;case 14:case 15:a=15}return a};var f,g=0,h=0,i=void 0,j=!0,k=1e3/60,l=wmsx.Util.arrayFill(new Array(13),0),m=wmsx.Util.arrayFill(new Array(13),0),n=[new Array(13),new Array(13)],o=0,p=[15,7,15,7,15,3,7,15,3,15,1,15,15],q=[0,0,15,7,15,3,7,15,3,0,1,3,0];this.saveState=function(){return{a:f,m:g,i:h,c:j,rc:wmsx.Util.storeInt8BitArrayToStringBase64(l),rm:wmsx.Util.storeInt8BitArrayToStringBase64(m),r0:wmsx.Util.storeInt8BitArrayToStringBase64(n[0]),r1:wmsx.Util.storeInt8BitArrayToStringBase64(n[1]),ra:o}},this.loadState=function(a){f=void 0!==a.a?a.a:a.m2,g=a.m,j=a.c,h=a.i?a.i:a.co+a.t,i=void 0,l=wmsx.Util.restoreStringBase64ToInt8BitArray(a.rc,l),m=wmsx.Util.restoreStringBase64ToInt8BitArray(a.rm,m),n[0]=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r0,n[0]),n[1]=wmsx.Util.restoreStringBase64ToInt8BitArray(a.r1,n[1]),o=a.ra}},wmsx.SystemFlags=function(){"use strict";this.setMachineType=function(c){a=c>=wmsx.Machine.MACHINE_TYPE.MSX2P,b=c>=wmsx.Machine.MACHINE_TYPE.MSXTR},this.connectBus=function(a){a.connectInputDevice(243,this.inputF3),a.connectOutputDevice(243,this.outputF3),a.connectInputDevice(244,this.inputF4),a.connectOutputDevice(244,this.outputF4),a.connectInputDevice(245,wmsx.DeviceMissing.outputPortIgnored),a.connectOutputDevice(245,wmsx.DeviceMissing.outputPortIgnored),a.connectInputDevice(246,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(246,wmsx.DeviceMissing.outputPortIgnored),a.connectInputDevice(247,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(247,wmsx.DeviceMissing.outputPortIgnored),a.connectInputDevice(248,wmsx.DeviceMissing.inputPortIgnored),a.connectOutputDevice(248,wmsx.DeviceMissing.outputPortIgnored)},this.powerOn=function(){this.reset()},this.powerOff=function(){},this.reset=function(){c=b?0:255,d=0},this.inputF3=function(){return a?d:255},this.outputF3=function(b){a&&(d=b)},this.inputF4=function(){return a?c:255},this.outputF4=function(b){a&&(c=b)};var a=!1,b=!1,c=0,d=0;this.saveState=function(){return{a:a,tr:b,bf:c,vf:d}},this.loadState=function(e){a=void 0!==e.a?e.a:e.m2p,b=void 0!==e.tr&&e.tr,c=e.bf,d=e.vf}},wmsx.TurboRDevices=function(a,b){"use strict";function c(){a.setZ80BUSRQ(o)}function d(a){i.setDRAMMode(l&&a),j.setDRAMMode(l&&a),k.setDRAMMode(l&&a),l&&l.setDRAMMode(a)}function e(){return(a.getBUSCycles()-u)/14&65535}function f(){b.ledStateChanged(2,1&p||o&&32&t?1:0),b.ledStateChanged(4,128&p?2+q:64&t?0:1)}function g(a){return{F:a|=1}}function h(a){return{F:a|=1}}this.setMachineType=function(a){m=a>=wmsx.Machine.MACHINE_TYPE.MSXTR},this.connectBus=function(a){i=a,i.connectInputDevice(167,this.inputA7),i.connectOutputDevice(167,this.outputA7),i.connectInputDevice(228,this.inputE4),i.connectOutputDevice(228,this.outputE4),i.connectInputDevice(229,this.inputE5),i.connectOutputDevice(229,this.outputE5),i.connectInputDevice(230,this.inputE6),i.connectInputDevice(231,this.inputE7),i.connectOutputDevice(230,this.outputE6),i.connectOutputDevice(231,wmsx.DeviceMissing.outputPortIgnored())},this.connectBIOS=function(a){j=a,this.patchPCMBIOS(j.bytes),l&&j.connectRAM(l,65536)},this.disconnectBIOS=function(a){j===a&&(j=void 0)},this.connectBIOSExt=function(a){k=a,l&&k.connectRAM(l,32768)},this.disconnectBIOSExt=function(a){k===a&&(k=void 0)},this.connectRAM=function(a){a.format===wmsx.SlotFormats.RAMMapper&&(l=a,j&&j.connectRAM(l,65536),k&&k.connectRAM(l,32768))},this.disconnectRAM=function(a){l===a&&(j&&j.disconnectRAM(l),k&&k.disconnectRAM(l),l=void 0)},this.powerOn=function(){this.reset()},this.powerOff=function(){this.reset()},this.reset=function(){p=0,q=0,r=0,t=96,this.outputE6(0),f()},this.outputA7=function(a){a&=129,m&&p!==a&&(p=a,f())},this.inputA7=function(){return m?n&&0==(32&t)?1:0:255},this.outputE4=function(a){m&&(r=a)},this.inputE4=function(){return m?r:255},this.outputE5=function(b){if(6===r){var c=96&b,e=b^t;if(!e)return;t=c,a.setR800Mode(0==(32&t)),d(0==(64&t)),32&t&&128&p||(q=64&t?0:1),(128&p||64&e)&&f()}},this.inputE5=function(){return 5===r?s:6===r?t:255},this.outputE6=function(b){u=a.getBUSCycles()},this.inputE6=function(){return m?255&e():255},this.inputE7=function(){return m?e()>>8:255},this.isR800LedOn=function(){return 0!=(128&p)},this.isCPUPaused=function(){return n},this.setCPUPause=function(a,b){n=a,b&&this.vSyncPulse()},this.vSyncPulse=function(){n!==o&&(o=n,c(),f())},this.patchPCMBIOS=function(a){m&&(a[390]=237,a[391]=236,a[392]=201,a[393]=237,a[394]=237,a[395]=201)},this.cpuExtensionBegin=function(a){switch(a.extNum){case 236:return g(a.F);case 237:return h(a.F)}},this.cpuExtensionFinish=function(a){};var i,j,k,l,m=!1,n=!1,o=!1,p=0,q=0,r=0,s=0,t=96,u=0;this.saveState=function(){return{a:m,cp:n,zp:o,ld:p,rl:q,rs:r,r5:s,r6:t,cb:u}},this.loadState=function(a){a?(m=a.a,n=a.cp,o=a.zp,p=a.ld,q=a.rl||0,r=a.rs,s=a.r5,t=a.r6,u=a.cb):(m=!1,this.reset(),n=!1,o=!1),c(),f()}},wmsx.ImageCassetteDriver=function(){"use strict";function a(a){return l.motor(!0),l.readHeader()?h(a,o):i(a)}function b(a){var b=l.readByte();if(null===b)return i(a);var c=h(a,p);return c.A=b,c}function c(){l.motor(!1)}function d(a,b){return l.motor(!0),l.writeHeader(a)?h(b,a?m:n):i(b)}function e(a,b){return l.writeByte(a)?h(b,p):i(b)}function f(){l.finishWriting(),l.motor(!1)}function g(a){l.motor(255===a?null:a>0)}function h(a,b){return{F:254&a,extraIterations:b}}function i(a){return{F:a|=1}}var j=this;this.connect=function(a,b){this.patchTapeBIOS(a.bytes,b),b.getCassetteSocket().connectDriver(this),l=b.getCassetteSocket().getDeck(),k=a.getKeyboardExtension()},this.disconnect=function(a,b){b.getCassetteSocket().connectDriver(null)},this.powerOff=function(){l&&l.motor(!1)},this.typeCurrentAutoRunCommand=function(){var a=j.currentAutoRunCommand();a&&k.typeString(a)},this.currentAutoRunCommand=function(){var a=l.peekFileInfoAtCurrentPosition();if(!a)return null;switch(a.type){case"Binary":return'\r\r\rbload "cas:'+a.name+'", r\r';case"Basic":return'\r\r\rcload "'+a.name+'"\rrun\r';case"ASCII":return'\r\r\rrun "cas:'+a.name+'"\r'}return null},this.cpuExtensionBegin=function(h){switch(h.extNum){case 224:return a(h.F);case 226:return b(h.F);case 228:return c();case 229:return d(h.A,h.F);case 230:return e(h.A,h.F);case 231:return f();case 232:return g(h.A)}},this.cpuExtensionFinish=function(a){},this.patchTapeBIOS=function(a,b){b.getMachineTypeSocket().getMachineType()>=wmsx.Machine.MACHINE_TYPE.MSXTR||(a[225]=237,a[226]=224,a[227]=201,a[228]=237,a[229]=226,a[230]=201,a[231]=237,a[232]=228,a[233]=201,a[234]=237,a[235]=229,a[236]=201,a[237]=237,a[238]=230,a[239]=201,a[240]=237,a[241]=231,a[242]=201,a[243]=237,a[244]=232,a[245]=201)};var k,l,m=3e5,n=m/3,o=.4*n,p=10},wmsx.TurboDriver=function(a){"use strict";function b(){if(h){var b=a.bytes;b[384]=195,b[385]=141,b[386]=1,b[387]=195,b[388]=144,b[389]=1,b[397]=237,b[398]=238,b[399]=201,b[400]=237,b[401]=239,b[402]=201}i?g.bus.connectSwitchedDevice(8,this):g.bus.disconnectSwitchedDevice(8,this)}function c(a){j=131&a;var b=(3&j)>0;k!==b&&(k=b,0===g.getZ80ClockMode()?(e.turboModesUpdate(),g.showZ80ClockModeMessage()):g.showOSD("Could not set Z80 Turbo by software: mode is FORCED "+g.getZ80ClockModeDesc(),!0,!0))}function d(){return{A:3&j}}var e=this;this.connect=function(a){g=a,f=g.getLedsSocket();var c=g.getMachineTypeSocket().getMachineType();h=c<l.MSXTR&&(1===WMSX.CPU_FAKE_TR_TURBO||-1===WMSX.CPU_FAKE_TR_TURBO&&c===l.MSX2P),i=c<l.MSXTR&&(1===WMSX.CPU_PANA_TURBO||-1===WMSX.CPU_PANA_TURBO&&c===l.MSX2P),
b(),this.turboModesUpdate()},this.disconnect=function(a,b){b.bus.disconnectSwitchedDevice(8,this)},this.powerOff=function(){j=0,k=!1,this.turboModesUpdate()},this.reset=function(){(h||i)&&WMSX.CPU_SOFT_TURBO_AUTO_ON?(j=130,k=!0):(j=0,k=!1),this.turboModesUpdate()},this.turboModesUpdate=function(){var a=h||i,b=g.getZ80ClockMode(),c=g.getR800ClockMode(),d=g.getVDPClockMode(),e=0===b&&a&&k?WMSX.Z80_SOFT_TURBO_MULTI:b>0?b:1;g.cpu.setZ80ClockMulti(e),g.cpu.setR800ClockMulti(c),g.vdp.setVDPTurboMulti(0===d&&a&&k?WMSX.VDP_SOFT_TURBO_MULTI:d>0?d:1);var j=g.cpu.getR800ClockMulti();f.ledStateChanged(3,1!==e?1:0),f.ledInfoChanged(3,1!==e?e+"x":""),f.ledInfoChanged(4,1!==j?j+"x":"")},this.cpuExtensionBegin=function(a){if(!(g.machineType<=1))switch(a.extNum){case 238:return c(a.A);case 239:return d()}},this.cpuExtensionFinish=function(a){},this.switchedPortInput=function(a){return 65!==a?255:k?0:1},this.switchedPortOutput=function(a,b){65===b&&c(0==(1&a)?129:0)},this.saveState=function(){return{tt:h,pt:i,st:k,cv:j}},this.loadState=function(a){k=!(!a||!a.st)&&a.st,j=a&&a.cv?a.cv:0;var c=g&&g.getMachineTypeSocket().getMachineType(),d=c===l.MSX2P;h=a&&void 0!==a.tt?a.tt:d,i=a&&void 0!==a.pt?a.pt:d,g&&b()};var f,g,h=!1,i=!1,j=0,k=!1,l=wmsx.Machine.MACHINE_TYPE},wmsx.BIOSKeyboardExtension=function(){"use strict";this.connect=function(b){a=b.bus},this.typeString=function(a){if(void 0!==a&&null!==a){var c=a.toString();c&&(c=c.replace(/\r\n/g,"\r").replace(/\n/g,"\r"),b=(b||"")+c)}},this.cancelTypeString=function(){b=null,c=0},this.keyboardExtensionClockPulse=function(){if(b){var h=a.read(e)|a.read(e+1)<<8;if(!(h<f||h>g)){var i=a.read(d)|a.read(d+1)<<8;if(!(i<f||i>g)){var j=h-i-1;if(j<0&&(j+=40),!(j<=0)){for(var k=b.substr(c,j),l=0;l<k.length;l++)a.write(i,255&k.charCodeAt(l)),++i>g&&(i=f);a.write(d,255&i),a.write(d+1,i>>8),c+=k.length,c>=b.length&&this.cancelTypeString()}}}}},this.saveState=function(){return{s:b&&btoa(b),p:c}},this.loadState=function(a){b=a.s&&atob(a.s),c=a.p};var a,b,c=0,d=62456,e=62458,f=64496,g=64535},wmsx.ImageDiskDriver=function(a){"use strict";function b(a,b){return{HL:65280&b|(64&a?1:2)}}function c(a,b,c,f,g,h){return 1&a?e(a,b,c,f,g,h):d(a,b,c,f,g,h)}function d(a,b,c,d,e,f){var g=p.motorOn(b);return p.readSectorsToSlot(b,e,c,l(f),f)?{F:-2&a,B:0,extraIterations:g+c*v}:{F:1|a,A:2,B:c,extraIterations:g}}function e(a,b,c,d,e,f){var g=p.motorOn(b);return p.isDiskInserted(b)&&p.writeSectorsFromSlot(b,e,c,l(f),f)?{F:-2&a,B:0,extraIterations:g+c*v}:{F:1|a,A:2,B:c,extraIterations:g}}function f(b,c,d,e,f){var h=p.diskHasChanged(c);if(!1===h)return{F:-2&b,B:1};var i=p.motorOn(c),j=p.readByte(c,t);return null===j?{F:1|b,A:2,B:0,extraIterations:i}:(a||g(b,c,j,e,f,!0),{F:-2&b,B:!0===h?255:0,extraIterations:i})}function g(a,b,c,d,e,f){var g=c<248?d:c;return g<248?{F:1|a}:(k(p.MEDIA_TYPE_DPB[g],e+1),{F:-2&a})}function h(a){return{HL:s[a]||0}}function i(a,b,c){var d=c>>>8,e=b>=1&&b<=2?b-1:0;if(e<0||e>1||d<0||d>1)return{F:1|a,A:12};var f=p.FORMAT_OPTIONS_MEDIA_TYPES[e];return p.insertNewDisk(d,f,!1,!0),p.motorOn(d),p.formatCurrentDisk(d,f),{F:-2&a,extraIterations:w}}function j(){p.allMotorsOffNow()}function k(a,b){for(var c=l(b),d=0;d<a.length;d++)c.write(b+d,a[d])}function l(a){var b;if(a>=16384&&a<=32767){var c=q.read(62274);b=q.getSlot(3&c),0!=(128&c)&&b.isExpanded()&&(b=b.getSubSlot(c>>2&3))}else b=q.getSlotForAddress(a),b.isExpanded()&&(b=b.getSubSlotForAddress(a));return b}function m(a,b,c){delete r[b];var d=q.read(c+26),e=3&d,f=e<=1;return f&&(p.motorFlash(e),!p.isDiskInserted(e))?{F:1|a,A:26}:(q.write(c+0,f?1:0),q.write(c+1,130),q.write(c+12+0,0),q.write(c+12+1,0),q.write(c+12+2,0),q.write(c+12+3,0),q.write(c+28,9),q.write(c+29,0),q.write(c+30,2),r[b]=e,{F:-2&a})}function n(a,b,c,d,e,f){var g=r[b];return g>=0&&p.motorFlash(g),void 0!==g&&p.isDiskInserted(g)?p.readSectorsToSlot(g,(f<<16)+e,c,q,d)?{F:-2&a}:{F:1|a,A:6}:{F:1|a,A:26}}function o(a,b,c,d,e,f){var g=r[b];return g>=0&&p.motorFlash(g),void 0!==g&&p.isDiskInserted(g)?p.writeSectorsFromSlot(g,(f<<16)+e,c,q,d)?{F:-2&a}:{F:1|a,A:6}:{F:1|a,A:26}}this.connect=function(a,b){p=b.getDiskDriveSocket().getDrive(),q=b.bus,q.setCpuExtensionHandler(244,this),q.setCpuExtensionHandler(245,this),q.setCpuExtensionHandler(246,this)},this.disconnect=function(a,b){p.allMotorsOff(),q.setCpuExtensionHandler(244,void 0),q.setCpuExtensionHandler(245,void 0),q.setCpuExtensionHandler(246,void 0)},this.powerOff=function(){p.allMotorsOff()},this.cpuExtensionBegin=function(a){switch(a.extNum){case 224:return;case 226:return b(a.F,a.HL);case 228:return c(a.F,a.A,a.B,a.C,a.DE,a.HL);case 229:return f(a.F,a.A,a.B,a.C,a.HL);case 230:return g(a.F,a.A,a.B,a.C,a.HL);case 231:return h(a.extPC);case 232:return i(a.F,a.A,a.DE);case 234:return j();case 244:return n(a.F,a.C,a.B,a.HL,a.IX,a.IY);case 245:return o(a.F,a.C,a.B,a.HL,a.IX,a.IY);case 246:return m(a.F,a.C,a.HL)}},this.cpuExtensionFinish=function(a){p.allMotorsOff()},this.patchDiskBIOS=function(a,b,c,d,e,f){var g=0,h=0;if(a[b+d+0]=237,a[b+d+1]=224,a[b+d+2]=0,a[b+e+0]=237,a[b+e+1]=226,a[b+e+2]=0,g=b+(a[b+c+16+0+1]|a[b+c+16+0+2]<<8),a[g+0]=237,a[g+1]=228,a[g+2]=201,g=b+(a[b+c+16+3+1]|a[b+c+16+3+2]<<8),a[g+0]=237,a[g+1]=229,a[g+2]=201,g=b+(a[b+c+16+6+1]|a[b+c+16+6+2]<<8),a[g+0]=237,a[g+1]=230,a[g+2]=201,g=b+(a[b+c+16+9+1]|a[b+c+16+9+2]<<8),h=g-b,a[g+0]=237,a[g+1]=231,a[g+2]=201,g=b+(a[b+c+16+12+1]|a[b+c+16+12+2]<<8),a[g+0]=237,a[g+1]=232,a[g+2]=201,g=b+(a[b+c+16+15+1]|a[b+c+16+15+2]<<8),a[g+0]=237,a[g+1]=234,a[g+2]=201,f>=0){s[h]=f;for(var i=0;i<u.length;i++)a[b+f+i]=u.charCodeAt(i)}},this.rePatchDiskBIOSOldStateForExtensions=function(a,b,c,d,e){228!==a[b+c+16+0+1]&&(a[b+d+1]=224,a[b+e+1]=226,a[b+c+16+0+1]=228,a[b+c+16+3+1]=229,a[b+c+16+6+1]=230,a[b+c+16+9+1]=231,a[b+c+16+12+1]=232,a[b+c+16+15+1]=234)},this.saveState=function(){return{sd:r,csa:s}},this.loadState=function(a){r=a&&void 0!==a.sd?a.sd:{},s=a&&void 0!==a.csa?a.csa:{}};var p,q,r={},s={},t=512,u="Adding a new Disk...\r\n1) 720KB\r\n2) 360KB\r\n\0",v=5e3,w=2e6},wmsx.ImageNextorDeviceDriver=function(){"use strict";function a(){return{A:5,B:0,C:0}}function b(a,b,c){return{F:0,A:0,HL:0}}function c(a,b,c,f,g,h){return 1!==b||1!==f?{A:p,B:0}:(l.motorFlash(2),l.isDiskInserted(2)?1&a?e(a,b,c,f,g,h):d(a,b,c,f,g,h):{A:o,B:0})}function d(a,b,c,d,e,f){var g=m.read(e+0)|m.read(e+1)<<8|m.read(e+2)<<16|m.read(e+3)<<24;return l.readSectorsToSlot(2,g,c,m,f)?{A:0}:{A:o,B:0}}function e(a,b,c,d,e,f){var g=m.read(e)|m.read(e+1)<<8|m.read(e+2)<<16|m.read(e+3)<<24;return l.writeSectorsFromSlot(2,g,c,m,f)?{A:0}:{A:o,B:0}}function f(a,b,c){if(1!==a)return{A:1};if(0===b)return m.write(c,1),m.write(c+1,0),{A:0};if(1===b){for(var d="WebMSX                                                                   ",e=0;e<64;++e)m.write(c+e,d.charCodeAt(e));return{A:0}}if(2===b){for(d="WebMSX Removable Hard Disk                                                   ",e=0;e<64;++e)m.write(c+e,d.charCodeAt(e));return{A:0}}return{A:1}}function g(a,b){if(1!==a||1!==b)return{A:0};var c=l.diskHasChanged(2);return{A:null===c?3:c?2:1}}function h(a,b,c){if(1!==a||1!==b)return{A:1};for(var d=l.getTotalSectorsAvailable(2)||0,e=[0,0,2,255&d,d>>8&255,d>>16&255,d>>24&255,1,0,0,0,0],f=0;f<12;++f)m.write(c+f,e[f]);return{A:0}}function i(a,b,c){delete n[b];var d=m.read(c+26),e=d>>4,f=15&d,g=0===e,h=0;if(g){if(l.motorFlash(2),!l.isDiskInserted(2))return{F:1|a,A:26};var i=l.readByte(2,510)<<8|l.readByte(2,511);if(null===i)return{F:1|a,A:26};var j=21930===i;if(f>0){if(!j)return{F:1|a,A:4};var k=446+16*(f-1),o=l.readByte(2,k+4);if(h=l.readDWord(2,k+8),null===o||null===h)return{F:1|a,A:26};if(!h||!o)return{F:1|a,A:4}}else if(j)return{F:1|a,A:4}}return m.write(c+0,g?1:0),m.write(c+1,145),m.write(c+12+0,255&h),m.write(c+12+1,h>>8&255),m.write(c+12+2,h>>16&255),m.write(c+12+3,h>>24&255),m.write(c+31,0),n[b]=h,{F:-2&a}}function j(a,b,c,d,e,f){var g=n[b];return g>=0&&l.motorFlash(2),
void 0!==g&&l.isDiskInserted(2)?l.readSectorsToSlot(2,g+(f<<16)+e,c,m,d)?{F:-2&a}:{F:1|a,A:9}:{F:1|a,A:26}}function k(a,b,c,d,e,f){var g=n[b];return g>=0&&l.motorFlash(2),void 0!==g&&l.isDiskInserted(2)?l.writeSectorsFromSlot(2,g+(f<<16)+e,c,m,d)?{F:-2&a}:{F:1|a,A:9}:{F:1|a,A:26}}this.connect=function(a,b){l=b.getDiskDriveSocket().getDrive(),m=b.bus,m.setCpuExtensionHandler(240,this),m.setCpuExtensionHandler(241,this),m.setCpuExtensionHandler(242,this)},this.disconnect=function(a,b){b.bus.setCpuExtensionHandler(240,void 0),b.bus.setCpuExtensionHandler(241,void 0),b.bus.setCpuExtensionHandler(242,void 0)},this.powerOff=function(){},this.cpuExtensionBegin=function(d){switch(d.extNum){case 224:return a();case 226:return b(d.A,d.B,d.HL);case 228:return c(d.F,d.A,d.B,d.C,d.DE,d.HL);case 229:return f(d.A,d.B,d.HL);case 230:return g(d.A,d.B);case 231:return h(d.A,d.B,d.HL);case 240:return j(d.F,d.C,d.B,d.HL,d.IX,d.IY);case 241:return k(d.F,d.C,d.B,d.HL,d.IX,d.IY);case 242:return i(d.F,d.C,d.HL)}},this.cpuExtensionFinish=function(a){},this.patchNextorKernel=function(a){a[114958]=1;for(var b="WebMSX Nextor Device Driver     ",c=0;c<32;++c)a[114960+c]=b.charCodeAt(c);for(a[114992]=201,a[114993]=201,a[114994]=201,a[114995]=237,a[114996]=224,a[114997]=201,a[114998]=237,a[114999]=226,a[115e3]=201,a[115001]=55,a[115002]=201,a[115003]=201,a[115004]=55,a[115005]=201,a[115006]=201,a[115007]=201,a[115008]=201,a[115009]=201,c=115010;c<115026;++c)a[c]=201;a[115040]=237,a[115041]=228,a[115042]=201,a[115043]=237,a[115044]=229,a[115045]=201,a[115046]=237,a[115047]=230,a[115048]=201,a[115049]=237,a[115050]=231,a[115051]=201},this.saveState=function(){return{so:n}},this.loadState=function(a){n=void 0!==(a&&a.so)?a.so:{}};var l,m,n={},o=252,p=181},wmsx.ROM=function(a,b,c,d,e){"use strict";this.source=wmsx.Util.leafFilename(a),this.content=b,this.info=c||wmsx.SlotCreator.produceInfo(this,d,e),this.saveState=function(){return{s:this.source,i:this.info}},this.reloadEmbeddedContent=function(){if(!this.content&&wmsx.EmbeddedFiles.isEmbeddedURL(this.source)){this.source=wmsx.Configurator.adaptROMSourceForOldState(this.source);var a=wmsx.EmbeddedFiles.get(this.source);if(!a)throw new Error("Cannot reload embedded content: "+this.source);this.content=a.content}}},wmsx.ROM.loadState=function(a){var b=wmsx.Configurator.adaptROMSourceForOldState(a.s);return new wmsx.ROM(b,null,a.i)},wmsx.ROMDatabase={uncompress:function(){wmsx.ROMDatabase=JSON.parse(wmsx.Util.uncompressStringBase64ToString(this.data))},
data:" "
},wmsx.SlotCreator=function(){"use strict";function a(a,b){var c,d=[];for(var e in wmsx.SlotFormats)c=wmsx.SlotFormats[e],c.prioritySelected=c.priorityForRom(a,b),c.prioritySelected&&(f(c,a.info),c.prioritySelected>=j||d.push(c));return d.sort(function(a,b){return a.prioritySelected-b.prioritySelected}),d}function b(a){var b={};return a.n&&(b.n=a.n),a.h&&(b.h=a.h),a.f&&(b.f=a.f),a.t&&(b.t=a.t),a.l&&(b.l=a.l),a.e&&(b.e=a.e),b}this.createFromROM=function(a,b){var d=c.getForROM(a);if(d){var e=wmsx.SlotFormats[d];if(e.priorityForRom(a))return wmsx.Util.log("USER Format selected: "+e.desc),e.createFromROM(a)}var f=this.getBestFormatOption(a,b);if(f){return wmsx.EmbeddedFiles.isEmbeddedURL(a.source)||wmsx.Util.log("AUTO Format selected: "+f.desc+", priority: "+f.prioritySelected),f.createFromROM(a)}},this.recreateFromSaveState=function(a,b){var c=wmsx.SlotFormats[a.f];if(!c)throw new Error("Unsupported ROM Format in Savestate: "+a.f);return b&&b.format!==c&&b.formatBack!==c&&(b=null),c.recreateFromSaveState(a,b)},this.changeCartridgeFormat=function(a,b){return b.createFromROM(a.rom)},this.getBestFormatOption=function(b,c){var d=a(b,c);return 0===d.length?void 0:d[0]},this.getUserFormatOptionNames=function(a){for(var b=[],c=0,d=wmsx.SlotFormatsUserOptions.length;c<d;++c){var e=wmsx.SlotFormatsUserOptions[c];wmsx.SlotFormats[e].priorityForRom(a)&&b.push(e)}return b},this.produceInfo=function(a,c,f){var g=a.content.length,h=a.content.length>m?void 0:wmsx.Util.sha1Generator.calcSHA1FromByteArray(a.content).toUpperCase();a.content.length>g&&(a.content.length=g);var i=wmsx.ROMDatabase[h],j=wmsx.EmbeddedFiles.isEmbeddedURL(a.source);return i?(i=b(i),j||wmsx.Util.log("ROM: "+i.n+(i.f?", format: "+i.f:"")+" ("+h+")")):(i=d(a.source),j||wmsx.Util.log("ROM: "+(g>0?"Unknown content":"No content")+", "+i.n+(i.f?", format: "+i.f:"")+(h?" ("+h+")":" (no hash computed)"))),e(i,a.source,h,c,f),i},this.setUserROMFormats=function(a){c=a};var c,d=function(a){var b={n:"Unknown"};return a?(b.n=wmsx.Util.leafFilenameNoExtension(a)||"Unknown",b):b},e=function(a,b,c,d,e){if(a.h=c,d){d=d.trim().toUpperCase();for(var f in wmsx.SlotFormats)if(f.toUpperCase()===d){a.f=wmsx.SlotFormats[f].name,a.t=!0;break}}if(!a.t){var h=b.toUpperCase();for(f in wmsx.SlotFormats)if(g(f.toUpperCase(),h)){a.f=wmsx.SlotFormats[f].name,a.t=!0;break}}void 0!==e&&null!==e&&(a.s=0|parseInt(e))},f=function(a,b){b.f&&a.name===b.f&&(a.prioritySelected-=b.t?l:k)},g=function(a,b){return b.match(h+a+i)},h="\\[",i="\\]",j=1e3,k=1e3,l=5e3,m=1024*(WMSX.ROM_MAX_HASH_SIZE_KB||5120);this.FORMAT_PRIORITY_BOOST=k},wmsx.SlotCreator=new wmsx.SlotCreator,wmsx.SlotFormats={Empty:{name:"Empty",desc:"Empty Slot",priority:1001,internal:!0,embeddedURL:"@[Empty].rom",priorityForRom:function(a){return a&&a.content&&0!==a.content.length?null:this.priority},createFromROM:function(a){return wmsx.SlotEmpty.singleton},recreateFromSaveState:function(a,b){return wmsx.SlotEmpty.singleton}},Expanded0:{name:"Expanded0",desc:"Special Expanded Slot 0",priority:1002,internal:!0,priorityForRom:function(a){return null},createFromROM:null,recreateFromSaveState:function(a,b){return wmsx.SlotExpanded0.recreateFromSaveState(a,b)}},Expanded3:{name:"Expanded3",desc:"Special Expanded Slot 3",priority:1003,internal:!0,priorityForRom:function(a){return null},createFromROM:null,recreateFromSaveState:function(a,b){return wmsx.SlotExpanded3.recreateFromSaveState(a,b)}},ExpandedS:{name:"ExpandedS",desc:"Simple Expanded Slot",priority:1004,internal:!0,priorityForRom:function(a){return null},createFromROM:null,recreateFromSaveState:function(a,b){return wmsx.SlotExpanded.recreateFromSaveState(a,b)}},ExpandedM:{name:"ExpandedM",desc:"Special Expanded Slot 4 (Modules: Device-only Slots)",priority:1005,internal:!0,priorityForRom:function(a){return null},createFromROM:null,recreateFromSaveState:function(a,b){return wmsx.SlotExpandedM.recreateFromSaveState(a,b)}},BIOS:{name:"BIOS",desc:"Main BIOS",priority:201,internal:!0,priorityForRom:function(a){return a.content.length>=16384&&a.content.length<=49152&&243===a.content[0]&&(195===a.content[1]||24===a.content[1])?this.priority:null},createFromROM:function(a){return new wmsx.SlotBIOS(a)},recreateFromSaveState:function(a,b){return wmsx.SlotBIOS.recreateFromSaveState(a,b)}},MSX2BIOSExt:{name:"MSX2BIOSExt",desc:"MSX2/2+/tR BIOS Extension",priority:202,internal:!0,priorityForRom:function(a){return a.content.length>=16384&&a.content.length<=49152&&67===a.content[0]&&68===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.SlotMSX2BIOSExt(a)},recreateFromSaveState:function(a,b){return wmsx.SlotMSX2BIOSExt.recreateFromSaveState(a,b)}},RAMNormal:{name:"RAMNormal",desc:"Normal RAM (unmapped)",priority:1011,internal:!0,embeddedURL:"@[RAMNormal].rom",priorityForRom:function(a){return 0===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.SlotRAMNormal(a)},recreateFromSaveState:function(a,b){return wmsx.SlotRAMNormal.recreateFromSaveState(a,b)}},RAMMapper:{name:"RAMMapper",desc:"Standard RAM Mapper",priority:1012,internal:!0,embeddedURL:"@[RAMMapper].rom",priorityForRom:function(a){return 0===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.SlotRAMMapper(a)},recreateFromSaveState:function(a,b){return wmsx.SlotRAMMapper.recreateFromSaveState(a,b)}},PlainROM:{name:"PlainROM",desc:"Plain ROM",priority:1013,priorityForRom:function(a){return a.content.length>0&&a.content.length<=4194304?this.priority:null},createFromROM:function(a){return new wmsx.SlotPlainROM(a)},recreateFromSaveState:function(a,b){return wmsx.SlotPlainROM.recreateFromSaveState(a,b)}},DiskPatch:{name:"DiskPatch",desc:"Generic Patched Disk BIOS",priority:1301,internal:!0,embeddedURL:"@[DiskPatch].rom",priorityForRom:function(a){return a.content.length>=16384&&a.content.length<=65536?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeDiskPatched(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeDiskPatched.recreateFromSaveState(a,b)}},Nextor16Patch:{name:"Nextor16Patch",desc:"Nextor ASCII-16 Patched Kernel",priority:1302,internal:!0,embeddedURL:"@[Nextor16Patch].rom",priorityForRom:function(a){return 131072===a.content.length&&65===a.content[0]&&66===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeNextorPatched(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeNextorPatched.recreateFromSaveState(a,b)}},SCCExpansion:{name:"SCCExpansion",desc:"Konami SCC Sound Cartridge",priority:1501,internal:!0,embeddedURL:"@[SCCExpansion].rom",priorityForRom:function(a){return 0===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSCCExpansion(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSCCExpansion.recreateFromSaveState(a,b)}},SCCIExpansion:{name:"SCCIExpansion",desc:"Konami SCC+ Sound Mapper Cartridge",priority:1502,internal:!0,embeddedURL:"@[SCCIExpansion].rom",priorityForRom:function(a){return a.content.length<=131072?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSCCIExpansion(a,this,!1)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSCCIExpansion.recreateFromSaveState(a,b)}},MSXMUSIC:{name:"MSXMUSIC",desc:"MSX-MUSIC Sound Extension",priority:1503,internal:!0,embeddedURL:"@[MSXMUSIC].rom",priorityForRom:function(a){return 16384===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeMSXMUSIC(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeMSXMUSIC.recreateFromSaveState(a,b)}},PACExpansion:{name:"PACExpansion",desc:"PAC SRAM Cartridge",priority:1505,internal:!0,embeddedURL:"@[PACExpansion].rom",priorityForRom:function(a,b){
return 0===a.content.length?this.priority:!wmsx.CartridgePAC.isPACFileContentValid(a.content)||b&&b.format!==wmsx.SlotFormats.PACExpansion&&b.format!==wmsx.SlotFormats.FMPAC?null:this.priority-wmsx.SlotCreator.FORMAT_PRIORITY_BOOST},createFromROM:function(a){return new wmsx.CartridgePAC(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgePAC.recreateFromSaveState(a,b)}},Kanji1:{name:"Kanji1",desc:"Kanji Font Driver",priority:1506,internal:!0,embeddedURL:"@[Kanji1].rom",priorityForRom:function(a){return 131072===a.content.length||262144===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeKanjiFont(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeKanjiFont.recreateFromSaveState(a,b)}},OPL4:{name:"OPL4",desc:"OPL4 Sound Cartridge",priority:1507,internal:!0,embeddedURL:"@[OPL4].rom",priorityForRom:function(a){return 2097152===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeOPL4(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeOPL4.recreateFromSaveState(a,b)}},ExtraPSG:{name:"ExtraPSG",desc:"Extra PSG Sound Chip",priority:1508,internal:!0,embeddedURL:"@[ExtraPSG].rom",priorityForRom:function(a){return 0===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeExtraPSG(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeExtraPSG.recreateFromSaveState(a,b)}},MegaRAM:{name:"MegaRAM",desc:"MegaRAM Mapper Cartridge",priority:1509,internal:!0,embeddedURL:"@[MegaRAM].rom",priorityForRom:function(a){return a.content.length<=2097152?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeMegaRAM(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeMegaRAM.recreateFromSaveState(a,b)}},V9990:{name:"V9990",desc:"V9990 Video Cartridge",priority:1510,internal:!0,embeddedURL:"@[V9990].rom",priorityForRom:function(a){return 0===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeV9990(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeV9990.recreateFromSaveState(a,b)}},Normal:{name:"Normal",desc:"Normal ROM, Mirroring Auto",priority:901,priorityForRom:function(a){return a.content.length>=128&&a.content.length<=16384&&65===a.content[0]&&66===a.content[1]?this.priority:a.content.length<=32768&&(65===a.content[0]&&66===a.content[1]||65===a.content[16384]&&66===a.content[16385])?this.priority:a.content.length>32768&&a.content.length<=65536&&(65===a.content[16384]&&66===a.content[16385]||65===a.content[32768]&&66===a.content[32769])?this.priority:null},createFromROM:function(a){return new wmsx.SlotNormal(a,this)},recreateFromSaveState:function(a,b){return wmsx.SlotNormal.recreateFromSaveState(a,b)}},Mirrored:{name:"Mirrored",desc:"Normal ROM, Mirrored",priority:902,priorityForRom:function(a){return wmsx.SlotFormats.Normal.priorityForRom(a)},createFromROM:function(a){return new wmsx.SlotNormal(a,this)},recreateFromSaveState:function(a,b){return wmsx.SlotNormal.recreateFromSaveState(a,b)}},NotMirrored:{name:"NotMirrored",desc:"Normal ROM, Not Mirrored",priority:903,priorityForRom:function(a){return wmsx.SlotFormats.Normal.priorityForRom(a)},createFromROM:function(a){return new wmsx.SlotNormal(a,this)},recreateFromSaveState:function(a,b){return wmsx.SlotNormal.recreateFromSaveState(a,b)}},ASCII8:{name:"ASCII8",desc:"ASCII 8K Mapper Cartridge",priority:911,priorityForRom:function(a){return a.content.length>=8192&&0==(8191&a.content.length)&&65===a.content[0]&&66===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8K(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8K.recreateFromSaveState(a,b)}},ASCII16:{name:"ASCII16",desc:"ASCII 16K Mapper Cartridge",priority:912,priorityForRom:function(a){return a.content.length>=16384&&0==(16383&a.content.length)&&65===a.content[0]&&66===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII16K(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII16K.recreateFromSaveState(a,b)}},Konami:{name:"Konami",desc:"Konami Mapper Cartridge",priority:913,priorityForRom:function(a){return a.content.length>=8192&&0==(8191&a.content.length)&&65===a.content[0]&&66===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeKonami(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeKonami.recreateFromSaveState(a,b)}},KonamiSCC:{name:"KonamiSCC",desc:"KonamiSCC Sound Mapper Cartridge",priority:914,priorityForRom:function(a){return a.content.length>=8192&&0==(8191&a.content.length)&&65===a.content[0]&&66===a.content[1]?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeKonamiSCC(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeKonamiSCC.recreateFromSaveState(a,b)}},KonamiSCCI:{name:"KonamiSCCI",desc:"Konami SCC+ Sound Mapper Cartridge (in SCC-I mode)",priority:1101,priorityForRom:function(a){return a.content.length>0&&a.content.length<=131072?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSCCIExpansion(a,this,!0)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSCCIExpansion.recreateFromSaveState(a,b)}},ASCII8SRAM2:{name:"ASCII8SRAM2",desc:"ASCII 8K SRAM 2K Mapper Cartridge",priority:1102,priorityForRom:function(a){return a.content.length>=8192&&a.content.length<=1048576&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8KSRAM.recreateFromSaveState(a,b)}},ASCII8SRAM8:{name:"ASCII8SRAM8",desc:"ASCII 8K SRAM 8K Mapper Cartridge",priority:1103,priorityForRom:function(a){return a.content.length>=8192&&a.content.length<=1048576&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8KSRAM.recreateFromSaveState(a,b)}},KoeiSRAM8:{name:"KoeiSRAM8",desc:"Koei SRAM 8K Mapper Cartridge",priority:1104,priorityForRom:function(a){return a.content.length>=8192&&a.content.length<=1048576&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8KSRAM.recreateFromSaveState(a,b)}},KoeiSRAM32:{name:"KoeiSRAM32",desc:"Koei SRAM 32K Mapper Cartridge",priority:1105,priorityForRom:function(a){return a.content.length>=8192&&a.content.length<=1048576&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8KSRAM.recreateFromSaveState(a,b)}},Wizardry:{name:"Wizardry",desc:"Wizardry SRAM Mapper Cartridge",priority:1106,priorityForRom:function(a){return a.content.length>=8192&&a.content.length<=1048576&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII8KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII8KSRAM.recreateFromSaveState(a,b)}},ASCII16SRAM2:{name:"ASCII16SRAM2",desc:"ASCII 16K SRAM 2K Mapper Cartridge",priority:1107,priorityForRom:function(a){return a.content.length>=16384&&a.content.length<=2097152&&0==(16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII16KSRAM(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII16KSRAM.recreateFromSaveState(a,b)}},ASCII16SRAM8:{name:"ASCII16SRAM8",desc:"ASCII 16K SRAM 8K Mapper Cartridge",priority:1108,priorityForRom:function(a){return a.content.length>=16384&&a.content.length<=2097152&&0==(16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII16KSRAM(a,this)},recreateFromSaveState:function(a,b){
return wmsx.CartridgeASCII16KSRAM.recreateFromSaveState(a,b)}},KonamiUltimateCollection:{name:"KonamiUltimateCollection",desc:"Konami Ultimate Collection SCC+/PCM Sound Mapper Cartridge",priority:1109,priorityForRom:function(a){return a.content.length<=8388608&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeKonamiUltimateCollection(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeKonamiUltimateCollection.recreateFromSaveState(a,b)}},RType:{name:"RType",desc:"R-Type Mapper Cartridge",priority:1111,priorityForRom:function(a){return 393216===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeRType(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeRType.recreateFromSaveState(a,b)}},CrossBlaim:{name:"CrossBlaim",desc:"CrossBlaim Mapper Cartridge",priority:1112,priorityForRom:function(a){return 65536===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeCrossBlaim(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeCrossBlaim.recreateFromSaveState(a,b)}},Manbow2:{name:"Manbow2",desc:"Space Manbow 2 SCC Sound Mapper Cartridge",priority:1113,priorityForRom:function(a){return 524288===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeManbow2(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeManbow2.recreateFromSaveState(a,b)}},Majutsushi:{name:"Majutsushi",desc:"Konami Hai no Majutsushi PCM Mapper Cartridge",priority:1114,priorityForRom:function(a){return a.content.length>0&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeMajutsushi(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeMajutsushi.recreateFromSaveState(a,b)}},Synthesizer:{name:"Synthesizer",desc:"Konami Synthesizer PCM Cartridge",priority:1115,priorityForRom:function(a){return a.content.length>0&&a.content.length<=32768&&0==(8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSynthesizer(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSynthesizer.recreateFromSaveState(a,b)}},GameMaster2:{name:"GameMaster2",desc:"Konami Game Master 2 SRAM Mapper Cartridge",priority:1116,priorityForRom:function(a){return 131072===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeGameMaster2(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeGameMaster2.recreateFromSaveState(a,b)}},HarryFox:{name:"HarryFox",desc:"HarryFox Mapper Cartridge",priority:1117,priorityForRom:function(a){return 65536===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeHarryFox(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeHarryFox.recreateFromSaveState(a,b)}},Halnote:{name:"Halnote",desc:"Halnote SRAM Mapper Cartridge",priority:1118,priorityForRom:function(a){return 1048576===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeHalnote(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeHalnote.recreateFromSaveState(a,b)}},AlQuran:{name:"AlQuran",desc:"The Holy Quran Mapper Cartridge (Encoded)",priority:1119,priorityForRom:function(a){return 1048576===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeAlQuran(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeAlQuran.recreateFromSaveState(a,b)}},AlQuranDecoded:{name:"AlQuranDecoded",desc:"The Holy Quran Mapper Cartridge (Decoded)",priority:1120,priorityForRom:function(a){return 1048576===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeAlQuran(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeAlQuran.recreateFromSaveState(a,b)}},SuperSwangi:{name:"SuperSwangi",desc:"Super Swangi Mapper Cartridge",priority:1121,priorityForRom:function(a){return a.content.length>=16384&&0==(16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSuperSwangi(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSuperSwangi.recreateFromSaveState(a,b)}},MSXWrite:{name:"MSXWrite",desc:"MSX Write Mapper Cartridge",priority:1122,priorityForRom:function(a){return 524288===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeASCII16K(a,this)},recreateFromSaveState:function(a,b){return wmsx.CartridgeASCII16K.recreateFromSaveState(a,b)}},Zemina80in1:{name:"Zemina80in1",desc:"Zemina 80 in 1 Mapper Cartridge",priority:1123,priorityForRom:function(a){return 0===(a.content.length>=8192&&8191&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeZemina80(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeZemina80.recreateFromSaveState(a,b)}},Zemina90in1:{name:"Zemina90in1",desc:"Zemina 90 in 1 Mapper Cartridge",priority:1124,priorityForRom:function(a){return 0===(a.content.length>=16384&&16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeZemina90(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeZemina90.recreateFromSaveState(a,b)}},Zemina126in1:{name:"Zemina126in1",desc:"Zemina 126 in 1 Mapper Cartridge",priority:1125,priorityForRom:function(a){return 0===(a.content.length>=16384&&16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeZemina126(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeZemina126.recreateFromSaveState(a,b)}},SuperLodeRunner:{name:"SuperLodeRunner",desc:"Super Lode Runner Mapper Cartridge",priority:1126,priorityForRom:function(a){return 0===(a.content.length>=16384&&16383&a.content.length)?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeSuperLodeRunner(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeSuperLodeRunner.recreateFromSaveState(a,b)}},Dooly:{name:"Dooly",desc:"Agigongnyong Dooly Mapper Cartridge",priority:1127,priorityForRom:function(a){return 32768===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeDooly(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeDooly.recreateFromSaveState(a,b)}},FMPAC:{name:"FMPAC",desc:"FM-PAC SRAM Sound Mapper Cartridge",priority:1151,priorityForRom:function(a){return 65536===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeFMPAC(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeFMPAC.recreateFromSaveState(a,b)}},MSXDOS2:{name:"MSXDOS2",desc:"MSX-DOS 2 Mapper Cartridge",priority:1504,embeddedURL:"@[MSXDOS2]v22.rom",priorityForRom:function(a){return 65536===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeDOS2(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeDOS2.recreateFromSaveState(a,b)}},DiskPatchDOS2TR:{name:"DiskPatchDOS2TR",desc:"TR MSX-DOS2 + Patched Disk BIOS",priority:1511,priorityForRom:function(a){return 65536===a.content.length?this.priority:null},createFromROM:function(a){return new wmsx.CartridgeDiskPatchedDOS2TR(a)},recreateFromSaveState:function(a,b){return wmsx.CartridgeDiskPatchedDOS2TR.recreateFromSaveState(a,b)}}},wmsx.SlotFormats.Expanded=wmsx.SlotFormats.Expanded3,wmsx.SlotFormats.MoonSound=wmsx.SlotFormats.OPL4,wmsx.SlotFormats.GenericKonami=wmsx.SlotFormats.Normal,wmsx.SlotFormats.Manbow2_2=wmsx.SlotFormats.Manbow2,wmsx.SlotFormats.HamarajaNight=wmsx.SlotFormats.Manbow2,wmsx.SlotFormats.Kanji12=wmsx.SlotFormats.Kanji1,wmsx.SlotFormats.FMPAK=wmsx.SlotFormats.FMPAC,
wmsx.SlotFormatsUserOptions=["Normal","Mirrored","NotMirrored","ASCII8","ASCII16","Konami","KonamiSCC","KonamiSCCI","ASCII8SRAM2","ASCII8SRAM8","ASCII16SRAM2","ASCII16SRAM8","MegaRAM","GameMaster2","AlQuran","AlQuranDecoded","CrossBlaim","Dooly","Halnote","HarryFox","KoeiSRAM8","KoeiSRAM32","Majutsushi","Manbow2","MSXWrite","RType","SuperLodeRunner","SuperSwangi","Synthesizer","Wizardry","Zemina80in1","Zemina90in1","Zemina126in1","FMPAC","Kanji1","MSXDOS2","MSXMUSIC"],wmsx.Slot=function(){"use strict";this.connect=function(a){},this.refreshConnect=function(a){},this.disconnect=function(a){},this.getDataDesc=function(){},this.loadData=function(a,b){},this.getDataToSave=function(){},this.dataModified=function(){return!1},this.powerOn=function(){},this.powerOff=function(){},this.reset=function(){},this.read=function(a){return 255},this.write=function(a,b){},this.setDRAMMode=function(a){},this.getBreakWaitSub=function(a,b){return 0},this.getAccessWaitSub=function(a){return 0},this.cpuExtensionBegin=function(a){},this.cpuExtensionFinish=function(a){},this.isExpanded=function(){return!1},this.getSecondarySlotConfig=function(){return 0},this.reinsertROMContent=function(){this.rom.content||(this.rom.content=this.bytes||[])},this.lightState=function(){return WMSX.LIGHT_STATES&&wmsx.EmbeddedFiles.isEmbeddedURL(this.rom.source)},this.format=void 0,this.rom=void 0,this.bytes=void 0,this.dumpBytes=function(a,b,c){wmsx.Util.dump(this.bytes,a,b,c)},this.dumpRead=function(a,b,c){var d="",e=a||0;c=c||1;for(var f=0;f<c;f++){for(var g=0;g<b;g++){var h=this.read(e++);d+=void 0!=h?h.toString(16,2)+" ":"? "}d+="   "}console.log(d)}},wmsx.Slot.base=new wmsx.Slot,wmsx.SlotEmpty={},wmsx.SlotEmpty.impl=function(){"use strict";this.read=function(a){return 255},this.rom=new wmsx.ROM("EMPTY",[],{n:"EMPTY",h:"",l:"EMPTY"}),this.format=wmsx.SlotFormats.Empty,this.saveState=function(){return{f:this.format.name}}},wmsx.SlotEmpty.impl.prototype=wmsx.Slot.base,wmsx.SlotEmpty.singleton=new wmsx.SlotEmpty.impl,wmsx.SlotExpanded=function(){"use strict";function a(a){var b=a>>14;return 0===b?g:1===b?h:2===b?i:j}function b(a){k=a,g=f[3&a],h=f[a>>2&3],i=f[a>>4&3],j=f[a>>6&3]}function c(){f=[l,l,l,l],d.subSlots=f}var d=this;this.isExpanded=function(){return!0},this.connect=function(a){e=a;for(var b=0;b<4;++b)f[b].connect(e)},this.refreshConnect=function(){for(var a=0;a<4;++a)f[a].refreshConnect()},this.disconnect=function(a){for(var b=0;b<4;++b)f[b].disconnect(a);e=null},this.powerOn=function(){b(0);for(var a=0;a<4;a++)f[a].powerOn()},this.powerOff=function(){for(var a=0;a<4;a++)f[a].powerOff()},this.reset=function(){b(0);for(var a=0;a<4;a++)f[a].reset()},this.isAllEmpty=function(){return f[0]===l&&f[1]===l&&f[2]===l&&f[3]===l},this.insertSubSlot=function(a,c){a=a||wmsx.SlotEmpty.singleton,f[c]!==a&&(e&&f[c].disconnect(e),f[c]=a,e&&f[c].connect(e),b(k))},this.getSubSlot=function(a){return f[a]},this.getSubSlotForAddress=a,this.read=function(a){var b=a>>14;return 0===b?g.read(a):1===b?h.read(a):2===b?i.read(a):65535===a?255&~k:j.read(a)},this.write=function(a,c){var d=a>>14;0===d?g.write(a,c):3===d?65535===a?b(c):j.write(a,c):1===d?h.write(a,c):i.write(a,c)},this.setSecondarySlotConfig=b,this.getSecondarySlotConfig=function(){return k},this.cpuExtensionBegin=function(b){return a(b.extPC).cpuExtensionBegin(b)},this.cpuExtensionFinish=function(b){return a(b.extPC).cpuExtensionFinish(b)};var e,f,g,h,i,j,k=0,l=wmsx.SlotEmpty.singleton;this.format=wmsx.SlotFormats.ExpandedS,this.saveState=function(){return{f:this.format.name,s:k,s0:f[0].saveState(),s1:f[1].saveState(),s2:f[2].saveState(),s3:f[3].saveState()}},this.loadState=function(a){this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s0,f[0]),0),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s1,f[1]),1),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s2,f[2]),2),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s3,f[3]),3),b(a.s)},function(){c()}()},wmsx.SlotExpanded.prototype=wmsx.Slot.base,wmsx.SlotExpanded.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotExpanded;return c.loadState(a),c},wmsx.SlotExpanded0=function(){"use strict";function a(a){var b=a>>14;return 0===b?g:1===b?h:2===b?i:j}function b(a){k=a,g=f[3&a],h=f[a>>2&3],i=f[a>>4&3],j=f[a>>6&3]}function c(){f=[l,l,l,l],d.subSlots=f}var d=this;this.isExpanded=function(){return!0},this.connect=function(a){e=a;for(var b=0;b<4;++b)f[b].connect(e)},this.refreshConnect=function(){for(var a=0;a<4;++a)f[a].refreshConnect()},this.disconnect=function(a){for(var b=0;b<4;++b)f[b].disconnect(a);e=null},this.powerOn=function(){b(0);for(var a=0;a<4;a++)f[a].powerOn()},this.powerOff=function(){for(var a=0;a<4;a++)f[a].powerOff()},this.reset=function(){b(0);for(var a=0;a<4;a++)f[a].reset()},this.isAllEmpty=function(){return f[0]===l&&f[1]===l&&f[2]===l&&f[3]===l},this.insertSubSlot=function(a,c){a=a||wmsx.SlotEmpty.singleton,f[c]!==a&&(e&&f[c].disconnect(e),f[c]=a,e&&f[c].connect(e),b(k))},this.getSubSlot=function(a){return f[a]},this.getSubSlotForAddress=a,this.read=function(a){var b=a>>14;return 0===b?g.read(a):2===b?i.read(a):3===b?65535===a?255&~k:j.read(a):h.read(a)},this.write=function(a,c){var d=a>>14;3===d?65535===a?b(c):j.write(a,c):0===d?g.write(a,c):1===d?h.write(a,c):i.write(a,c)},this.setSecondarySlotConfig=b,this.getSecondarySlotConfig=function(){return k},this.cpuExtensionBegin=function(b){return a(b.extPC).cpuExtensionBegin(b)},this.cpuExtensionFinish=function(b){return a(b.extPC).cpuExtensionFinish(b)};var e,f,g,h,i,j,k=0,l=wmsx.SlotEmpty.singleton;this.format=wmsx.SlotFormats.Expanded0,this.formatBack=wmsx.SlotFormats.Expanded,this.saveState=function(){return{f:this.format.name,s:k,s0:f[0].saveState(),s1:f[1].saveState(),s2:f[2].saveState(),s3:f[3].saveState()}},this.loadState=function(a){this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s0,f[0]),0),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s1,f[1]),1),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s2,f[2]),2),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s3,f[3]),3),b(a.s)},function(){c()}()},wmsx.SlotExpanded0.prototype=wmsx.Slot.base,wmsx.SlotExpanded0.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotExpanded0;return c.loadState(a),c},wmsx.SlotExpanded3=function(){"use strict";function a(a){var b=a>>14;return 0===b?h:1===b?i:2===b?j:k}function b(a){l=a,h=g[3&a],i=g[a>>2&3],j=g[a>>4&3],k=g[a>>6&3],f&&f.setSlot3SecondaryConfig(a)}function c(){g=[m,m,m,m],d.subSlots=g}var d=this;this.isExpanded=function(){return!0},this.connect=function(a){e=a,f=e.bus;for(var c=0;c<4;++c)g[c].connect(e);b(l)},this.refreshConnect=function(){for(var a=0;a<4;++a)g[a].refreshConnect();b(l)},this.disconnect=function(a){for(var c=0;c<4;++c)g[c].disconnect(a);b(0),e=f=null},this.powerOn=function(){b(0);for(var a=0;a<4;a++)g[a].powerOn()},this.powerOff=function(){for(var a=0;a<4;a++)g[a].powerOff()},this.reset=function(){b(0);for(var a=0;a<4;a++)g[a].reset()},this.isAllEmpty=function(){return g[0]===m&&g[1]===m&&g[2]===m&&g[3]===m},this.insertSubSlot=function(a,c){a=a||wmsx.SlotEmpty.singleton,g[c]!==a&&(e&&g[c].disconnect(e),g[c]=a,e&&g[c].connect(e),b(l))},this.getSubSlot=function(a){return g[a]},this.getSubSlotForAddress=a,this.read=function(a){var b=a>>14;return 0===b?h.read(a):1===b?i.read(a):2===b?j.read(a):65535===a?255&~l:k.read(a)},this.write=function(a,c){var d=a>>14;0===d?h.write(a,c):3===d?65535===a?b(c):k.write(a,c):1===d?i.write(a,c):j.write(a,c)},this.setSecondarySlotConfig=b,this.getSecondarySlotConfig=function(){return l},this.cpuExtensionBegin=function(b){return a(b.extPC).cpuExtensionBegin(b)},this.cpuExtensionFinish=function(b){return a(b.extPC).cpuExtensionFinish(b)};var e,f,g,h,i,j,k,l=0,m=wmsx.SlotEmpty.singleton;this.format=wmsx.SlotFormats.Expanded3,this.formatBack=wmsx.SlotFormats.Expanded,this.saveState=function(){
return{f:this.format.name,s:l,s0:g[0].saveState(),s1:g[1].saveState(),s2:g[2].saveState(),s3:g[3].saveState()}},this.loadState=function(a){this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s0,g[0]),0),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s1,g[1]),1),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s2,g[2]),2),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s3,g[3]),3),b(a.s)},function(){c()}()},wmsx.SlotExpanded3.prototype=wmsx.Slot.base,wmsx.SlotExpanded3.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotExpanded3;return c.loadState(a),c},wmsx.SlotExpandedM=function(){"use strict";function a(){d=[e,e,e,e],b.subSlots=d}var b=this;this.isExpanded=function(){return!0},this.connect=function(a){c=a;for(var b=0;b<4;++b)d[b].connect(c)},this.refreshConnect=function(){for(var a=0;a<4;++a)d[a].refreshConnect()},this.disconnect=function(a){for(var b=0;b<4;++b)d[b].disconnect(a);c=null},this.powerOn=function(){for(var a=0;a<4;a++)d[a].powerOn()},this.powerOff=function(){for(var a=0;a<4;a++)d[a].powerOff()},this.reset=function(){for(var a=0;a<4;a++)d[a].reset()},this.isAllEmpty=function(){return d[0]===e&&d[1]===e&&d[2]===e&&d[3]===e},this.insertSubSlot=function(a,b){a=a||wmsx.SlotEmpty.singleton,d[b]!==a&&(c&&d[b].disconnect(c),d[b]=a,c&&d[b].connect(c))},this.getSubSlot=function(a){return d[a]},this.getSubSlotForAddress=function(a){},this.read=function(a){},this.write=function(a,b){},this.getSecondarySlotConfig=function(){},this.cpuExtensionBegin=function(a){},this.cpuExtensionFinish=function(a){};var c,d,e=wmsx.SlotEmpty.singleton;this.format=wmsx.SlotFormats.ExpandedM,this.saveState=function(){return{f:this.format.name,s0:d[0].saveState(),s1:d[1].saveState(),s2:d[2].saveState(),s3:d[3].saveState()}},this.loadState=function(a){this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s0,d[0]),0),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s1,d[1]),1),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s2,d[2]),2),this.insertSubSlot(wmsx.SlotCreator.recreateFromSaveState(a.s3,d[3]),3)},function(){a()}()},wmsx.SlotExpandedM.prototype=wmsx.Slot.base,wmsx.SlotExpandedM.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotExpandedM;return c.loadState(a),c},wmsx.SlotNormal=function(a,b){"use strict";function c(a){if(65!==d[a]||66!==d[a+1])return null;for(var b=null,c=65535,e=a+2;e<=a+8;e+=2){var f=d[e+1]<<8|d[e];0!==f&&(f<c&&(c=f),e===a+8&&(!b||f<b)&&(b=f))}return 65535===c?null:{lowestHandlerPage:c>>14,lowestBasicPage:null!==b?b>>14:null}}this.read=function(a){return a>=e&&a<f?d[a-e]:h?d[a+65536-e&g]:255};var d;this.bytes=null;var e,f,g,h;this.rom=null,this.format=null,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(d),ba:e,m:h}},this.loadState=function(a){this.format=void 0===a.m?wmsx.SlotFormats.Normal:wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),d=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,d),this.bytes=d,e=a.ba,f=e+d.length,g=d.length-1,h=void 0!==a.m?a.m:a.f===wmsx.SlotFormats.Mirrored.name},a&&function(i){i.rom=a,d=wmsx.Util.asNormalArray(a.content),i.bytes=d;var j=d.length;g=j-1,i.format=b;var k=0;if(h=b===wmsx.SlotFormats.Mirrored||b!==wmsx.SlotFormats.NotMirrored&&null,j>32768)k=0;else{var l=a.info.s?parseInt(a.info.s):-1;if(l>=0)k=l>>14;else{for(var m=null,n=null,o=0;o<j;o+=16384){var p=c(o);if(null!=p){m=p.lowestHandlerPage,n=p.lowestBasicPage;break}}null===m?k=1:j>16384?k=0===o?3===m?2:1:0===m?0:1:(k=2===m?2:1,null===h&&2===k&&2===n&&(h=!1)),null===h&&(h=!0)}}h=!!h,e=k<<14,f=Math.min(e+j,65536),wmsx.Util.log("Address: 0x"+wmsx.Util.toHex4(e)+" - 0x"+wmsx.Util.toHex4(f-1)+", Mirrored: "+h)}(this)},wmsx.SlotNormal.prototype=wmsx.Slot.base,wmsx.SlotNormal.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotNormal;return c.loadState(a),c},wmsx.SlotPlainROM=function(a){"use strict";this.read=function(a){return a>=d&&a<c?b[a-d]:255};var b;this.bytes=null;var c,d;this.rom=null,this.format=wmsx.SlotFormats.PlainROM,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),ba:d}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b&&b.length===this.rom.content.length||(b=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,b)),this.bytes=b,d=a.ba,c=d+b.length},a&&function(e){e.rom=a,b=wmsx.Util.asNormalArray(a.content),e.bytes=b,d=void 0!==a.info.s?a.info.s:0,c=d+b.length}(this)},wmsx.SlotPlainROM.prototype=wmsx.Slot.base,wmsx.SlotPlainROM.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotPlainROM;return c.loadState(a),c},wmsx.SlotRAMNormal=function(a){"use strict";function b(a,b){a.rom=b;var e=WMSX.RAMNORMAL_SIZE;e<1?e=1:e>64&&(e=64),c=new Uint8Array(1024*e),d=65536-c.length,a.bytes=c}this.refreshConnect=function(){1024*WMSX.RAMNORMAL_SIZE!==c.length&&b(this,this.rom)},this.powerOff=function(){wmsx.Util.arrayFill(c,0)},this.read=function(a){return a>=d?c[a-d]:255},this.write=function(a,b){a>=d&&(c[a-d]=b)};var c;this.bytes=null;var d=0;this.rom=null,this.format=wmsx.SlotFormats.RAMNormal,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(c)}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c),this.bytes=c,d=65536-c.length},a&&b(this,a)},wmsx.SlotRAMNormal.prototype=wmsx.Slot.base,wmsx.SlotRAMNormal.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotRAMNormal;return c.loadState(a),c},wmsx.SlotRAMMapper=function(rom){"use strict";function init(a,b){a.rom=b;for(var c=0;VALID_SIZES[c]<WMSX.RAMMAPPER_SIZE&&c<VALID_SIZES.length-1;)c++;var d=VALID_SIZES[c];bytes=new Uint8Array(1024*d),a.bytes=bytes,pageMask=(bytes.length>>14)-1,pageReadBackOR=255&~pageMask,dramModeStart=bytes.length-65536}this.connect=function(a){trd=a.trd,a.bus.connectInputDevice(252,this.inputAll),a.bus.connectInputDevice(253,this.inputAll),a.bus.connectInputDevice(254,this.inputAll),a.bus.connectInputDevice(255,this.inputAll),a.bus.connectOutputDevice(252,this.outputFC),a.bus.connectOutputDevice(253,this.outputFD),a.bus.connectOutputDevice(254,this.outputFE),a.bus.connectOutputDevice(255,this.outputFF),trd.connectRAM(this)},this.refreshConnect=function(){1024*WMSX.RAMMAPPER_SIZE!==bytes.length&&(init(this,this.rom),trd&&trd.connectRAM(this))},this.disconnect=function(a){a.bus.disconnectInputDevice(252,this.inputAll),a.bus.disconnectInputDevice(253,this.inputAll),a.bus.disconnectInputDevice(254,this.inputAll),a.bus.disconnectInputDevice(255,this.inputAll),a.bus.disconnectOutputDevice(252,this.outputFC),a.bus.disconnectOutputDevice(253,this.outputFD),a.bus.disconnectOutputDevice(254,this.outputFE),a.bus.disconnectOutputDevice(255,this.outputFF),a.trd.disconnectRAM(this)},this.setDRAMMode=function(a){dramModeOff=!a},this.powerOn=function(){this.reset()},this.powerOff=function(){wmsx.Util.arrayFill(bytes,0)},this.reset=function(){page0Offset=page1Offset=page2Offset=page3Offset=0,dramModeOff=!0},this.outputFC=function(a){page0Offset=(a&pageMask)<<14},this.outputFD=function(a){page1Offset=((a&pageMask)<<14)-16384},this.outputFE=function(a){page2Offset=((a&pageMask)<<14)-32768},this.outputFF=function(a){page3Offset=((a&pageMask)<<14)-49152},this.inputAll=function(a){switch(255&a){case 252:return pageReadBackOR|page0Offset>>14;case 253:return pageReadBackOR|page1Offset+16384>>14;case 254:return pageReadBackOR|page2Offset+32768>>14;case 255:return pageReadBackOR|page3Offset+49152>>14}},this.read=function(a){var b=a>>14;return 3===b?bytes[a+page3Offset]:0===b?bytes[a+page0Offset]:2===b?bytes[a+page2Offset]:bytes[a+page1Offset]},this.write=function(a,b){
var c=a>>14;3===c?(dramModeOff||a+page3Offset<dramModeStart)&&(bytes[a+page3Offset]=b):0===c?(dramModeOff||a+page0Offset<dramModeStart)&&(bytes[a+page0Offset]=b):2===c?(dramModeOff||a+page2Offset<dramModeStart)&&(bytes[a+page2Offset]=b):(dramModeOff||a+page1Offset<dramModeStart)&&(bytes[a+page1Offset]=b)};var trd,page0Offset=0,page1Offset=0,page2Offset=0,page3Offset=0,pageMask=0,pageReadBackOR=0,dramModeOff=!0,dramModeStart=0,bytes;this.bytes=null,this.rom=null,this.format=wmsx.SlotFormats.RAMMapper;var VALID_SIZES=[64,128,256,512,1024,2048,4096];this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(bytes),p0:page0Offset,p1:page1Offset,p2:page2Offset,p3:page3Offset,dr:!dramModeOff}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),bytes=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,bytes),this.bytes=bytes,pageMask=(bytes.length>>14)-1,page0Offset=a.p0,page1Offset=a.p1,page2Offset=a.p2,page3Offset=a.p3,pageReadBackOR=255&~pageMask,dramModeStart=bytes.length-65536,dramModeOff=!a.dr,trd&&trd.connectRAM(this)},rom&&init(this,rom),this.eval=function(str){return eval(str)}},wmsx.SlotRAMMapper.prototype=wmsx.Slot.base,wmsx.SlotRAMMapper.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotRAMMapper;return c.loadState(a),c},wmsx.SlotBIOS=function(a){"use strict";this.connect=function(a){b=a,b.setBIOS(this),b.trd.connectBIOS(this),i.connect(b),h.connect(this,b),j.connect(b)},this.disconnect=function(a){b=void 0,h&&h.disconnect(this,a),j&&j.disconnect(this,a),a.trd.disconnectBIOS(this),a.setBIOS(null)},this.connectRAM=function(a,b){e=a.bytes,g=e.length-b},this.disconnectRAM=function(a){e===a.bytes&&(e=void 0,f=!1)},this.getKeyboardExtension=function(){return i},this.getTurboDriver=function(){return j},this.powerOff=function(){j&&j.powerOff(),h&&h.powerOff()},this.reset=function(){j&&j.reset(),f=!1},this.setDRAMMode=function(a){f=!!a},this.read=function(a){return a<d?f?e[g+a]:c[a]:64689===a?0:255},this.cpuExtensionBegin=function(a){return a.extNum<233?h.cpuExtensionBegin(a):a.extNum<238?b.trd.cpuExtensionBegin(a):j.cpuExtensionBegin(a)},this.cpuExtensionFinish=function(a){return a.extNum<233?h.cpuExtensionFinish(a):a.extNum<238?b.trd.cpuExtensionFinish(a):j.cpuExtensionFinish(a)},this.setVideoStandardForced=function(a){a===wmsx.VideoStandard.PAL?c[43]|=128:c[43]&=-129},this.setVideoStandardUseOriginal=function(){this.originalVideoStandard===wmsx.VideoStandard.PAL?c[43]|=128:c[43]&=-129};var b,c;this.bytes=null;var d,e,f=!1,g=0,h=new wmsx.ImageCassetteDriver,i=new wmsx.BIOSKeyboardExtension,j=new wmsx.TurboDriver(this);this.rom=null,this.format=wmsx.SlotFormats.BIOS,this.originalVideoStandard=null,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),v:this.originalVideoStandard.name,b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(c),ke:i.saveState(),td:j.saveState(),dr:f}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),this.originalVideoStandard=wmsx.VideoStandard[a.v],a.b?c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c):(this.rom.reloadEmbeddedContent(),c&&c.length===this.rom.content.length||(c=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,c),b&&b.trd.patchPCMBIOS(c)),this.bytes=c,d=c.length,b&&h.patchTapeBIOS(c,b),a.ke&&i.loadState(a.ke),j.loadState(a.td),f=!!a.dr},a&&function(b){b.rom=a,c=wmsx.Util.asNormalArray(a.content),b.bytes=c,d=c.length,b.originalVideoStandard=0==(128&c[43])?wmsx.VideoStandard.NTSC:wmsx.VideoStandard.PAL}(this)},wmsx.SlotBIOS.prototype=wmsx.Slot.base,wmsx.SlotBIOS.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotBIOS;return c.loadState(a),c},wmsx.SlotMSX2BIOSExt=function(a){"use strict";this.connect=function(a){a.trd.connectBIOSExt(this)},this.disconnect=function(a){a.trd.disconnectBIOSExt(this)},this.connectRAM=function(a,b){c=a.bytes,f=c.length-b},this.disconnectRAM=function(a){c===a.bytes&&(c=void 0,e=!1)},this.reset=function(){e=!1},this.setDRAMMode=function(a){e=!!a},this.read=function(a){return a<d?e&&a<32768?c[f+a]:b[a]:255};var b;this.bytes=null;var c,d,e=!1,f=0;this.rom=null,this.format=wmsx.SlotFormats.MSX2BIOSExt,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),dr:e}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b&&b.length===this.rom.content.length||(b=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,b)),this.bytes=b,d=b.length,e=!!a.dr},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,d=b.length}(this)},wmsx.SlotMSX2BIOSExt.prototype=wmsx.Slot.base,wmsx.SlotMSX2BIOSExt.recreateFromSaveState=function(a,b){var c=b||new wmsx.SlotMSX2BIOSExt;return c.loadState(a),c},wmsx.CartridgeASCII8K=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=-16384,d=-24576,e=-32768,f=-40960},this.write=function(a,b){if(!(a<24576))return a<26624?void(c=(b%g<<13)-16384):a<28672?void(d=(b%g<<13)-24576):a<30720?void(e=(b%g<<13)-32768):void(a<32768&&(f=(b%g<<13)-40960))},this.read=function(a){switch(57344&a){case 16384:return b[c+a];case 24576:return b[d+a];case 32768:return b[e+a];case 40960:return b[f+a];default:return 255}};var b;this.bytes=null;var c,d,e,f,g;this.rom=null,this.format=wmsx.SlotFormats.ASCII8,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,b2:d,b3:e,b4:f,n:g}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1,d=a.b2,e=a.b3,f=a.b4,g=a.n},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,g=b.length/8192|0}(this)},wmsx.CartridgeASCII8K.prototype=wmsx.Slot.base,wmsx.CartridgeASCII8K.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeASCII8K;return c.loadState(a),c},wmsx.CartridgeASCII16K=function(a,b){"use strict";function c(a){a===wmsx.SlotFormats.MSXWrite?(h=28671,i=32767):(h=-1,i=-1)}this.powerOn=function(){this.reset()},this.reset=function(){e=-16384,f=-32768},this.write=function(a,b){if(a>=24576&&a<26624||a===h)return void(e=(b%g<<14)-16384);(a>=28672&&a<30720||a===i)&&(f=(b%g<<14)-32768)},this.read=function(a){return a<16384?255:a<32768?d[e+a]:a<49152?d[f+a]:255};var d;this.bytes=null;var e,f,g,h,i;this.rom=null,this.format=b,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(d),b1:e,b2:f,n:g}},this.loadState=function(a){this.format=wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),d=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,d),this.bytes=d,e=a.b1,f=a.b2,g=a.n,c(this.format)},a&&function(e){e.rom=a,d=wmsx.Util.asNormalArray(a.content),e.bytes=d,g=d.length/16384|0,c(b)}(this)},wmsx.CartridgeASCII16K.prototype=wmsx.Slot.base,wmsx.CartridgeASCII16K.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeASCII16K;return c.loadState(a),c},wmsx.CartridgeKonami=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=d=e=-16384},this.write=function(a,b){a>=24576&&a<32767?c=(b%f<<13)-24576:a>=32768&&a<40959?d=(b%f<<13)-32768:a>=40960&&a<49151&&(e=(b%f<<13)-40960)},this.read=function(a){switch(57344&a){case 16384:return b[a-16384];case 24576:return b[c+a];case 32768:return b[d+a];case 40960:return b[e+a];default:return 255}};var b;this.bytes=null;var c,d,e,f;this.rom=null,this.format=wmsx.SlotFormats.Konami,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b2:c,b3:d,b4:e,n:f}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),
b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b2,d=a.b3,e=a.b4,f=a.n},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,f=b.length/8192|0}(this)},wmsx.CartridgeKonami.prototype=wmsx.Slot.base,wmsx.CartridgeKonami.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeKonami;return c.loadState(a),c},wmsx.CartridgeRType=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=-32768},this.write=function(a,b){a>=28672&&a<32768&&(c=(b%24<<14)-32768)},this.read=function(a){return a<16384?255:a<32768?b[229376+a]:a<49152?b[c+a]:255};var b;this.bytes=null;var c;this.rom=null,this.format=wmsx.SlotFormats.RType,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b2:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b2},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeRType.prototype=wmsx.Slot.base,wmsx.CartridgeRType.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeRType;return c.loadState(a),c},wmsx.CartridgeCrossBlaim=function(a){this.powerOn=function(){this.reset()},this.reset=function(){c=-16384},this.write=function(a,b){16453===a&&(c=((3&b)<<14)-32768)},this.read=function(a){return a<16384?255:a<32768?b[a-16384]:a<49152?b[c+a]:255};var b;this.bytes=null;var c;this.rom=null,this.format=wmsx.SlotFormats.CrossBlaim,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeCrossBlaim.prototype=wmsx.Slot.base,wmsx.CartridgeCrossBlaim.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeCrossBlaim;return c.loadState(a),c},wmsx.CartridgeDOS2=function(a){"use strict";this.connect=function(a){a.getDiskDriveSocket().dos2ROMConnected(this)},this.disconnect=function(a){a.getDiskDriveSocket().dos2ROMDisconnected(this)},this.powerOn=function(){this.reset()},this.reset=function(){c=-16384},this.write=function(a,b){32766===a&&(c=((3&b)<<14)-16384)},this.read=function(a){return a>=16384&&a<32768?b[c+a]:255};var b;this.bytes=null;var c;this.rom=null,this.format=wmsx.SlotFormats.MSXDOS2,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeDOS2.prototype=wmsx.Slot.base,wmsx.CartridgeDOS2.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeDOS2;return c.loadState(a),c},wmsx.CartridgeHarryFox=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=d=-16384},this.write=function(a,b){if(a>=24576&&a<28672)return void(c=(1&b?32768:0)-16384);a>=28672&&a<32768&&(d=(1&b?49152:16384)-32768)},this.read=function(a){return a<16384?255:a<32768?b[c+a]:a<49152?b[d+a]:255};var b;this.bytes=null;var c,d;this.rom=null,this.format=wmsx.SlotFormats.HarryFox,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,b2:d}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1,d=a.b2},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeHarryFox.prototype=wmsx.Slot.base,wmsx.CartridgeHarryFox.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeHarryFox;return c.loadState(a),c},wmsx.CartridgeAlQuran=function(a,b){"use strict";function c(){for(var a=new Array(256),b=0;b<256;++b)a[b]=77^(b<<4&80|b>>3&5|b<<1&160|b<<2&8|b>>6&2);for(var c=0,e=d.length;c<e;++c)d[c]=a[d[c]]}this.powerOn=function(){this.reset()},this.reset=function(){e=-16384,f=-24576,g=-32768,h=-40960},this.write=function(a,b){if(!(a<20480))return a<21504?void(e=((127&b)<<13)-16384):a<22528?void(f=((127&b)<<13)-24576):a<23552?void(g=((127&b)<<13)-32768):void(a<24576&&(h=((127&b)<<13)-40960))},this.read=function(a){switch(57344&a){case 16384:return d[e+a];case 24576:return d[f+a];case 32768:return d[g+a];case 40960:return d[h+a];default:return 255}};var d;this.bytes=null;var e,f,g,h;this.rom=null,this.format=b,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(d),b1:e,b2:f,b3:g,b4:h}},this.loadState=function(a){this.format=wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),d=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,d),this.bytes=d,e=a.b1,f=a.b2,g=a.b3,h=a.b4},a&&function(e){e.rom=a,d=wmsx.Util.asNormalArray(a.content),e.bytes=d,b===wmsx.SlotFormats.AlQuran&&c()}(this)},wmsx.CartridgeAlQuran.prototype=wmsx.Slot.base,wmsx.CartridgeAlQuran.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeAlQuran;return c.loadState(a),c},wmsx.CartridgeSuperSwangi=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=-32768},this.write=function(a,b){32768===a&&(c=((b>>1)%d<<14)-32768)},this.read=function(a){return a<16384?255:a<32768?b[a-16384]:a<49152?b[c+a]:255};var b;this.bytes=null;var c,d;this.rom=null,this.format=wmsx.SlotFormats.SuperSwangi,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b2:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b2,d=b.length/16384|0},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,d=b.length/16384|0}(this)},wmsx.CartridgeSuperSwangi.prototype=wmsx.Slot.base,wmsx.CartridgeSuperSwangi.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeSuperSwangi;return c.loadState(a),c},wmsx.CartridgeZemina80=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=d=e=f=-16384},this.write=function(a,b){switch(a){case 16384:return void(c=(b%g<<13)-16384);case 16385:return void(d=(b%g<<13)-24576);case 16386:return void(e=(b%g<<13)-32768);case 16387:f=(b%g<<13)-40960}},this.read=function(a){switch(57344&a){case 16384:return b[c+a];case 24576:return b[d+a];case 32768:return b[e+a];case 40960:return b[f+a];default:return 255}};var b;this.bytes=null;var c,d,e,f,g;this.rom=null,this.format=wmsx.SlotFormats.Zemina80in1,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,b2:d,b3:e,b4:f}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1,d=a.b2,e=a.b3,f=a.b4,g=b.length/8192|0},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,g=b.length/8192|0}(this)},wmsx.CartridgeZemina80.prototype=wmsx.Slot.base,wmsx.CartridgeZemina80.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeZemina80;return c.loadState(a),c},wmsx.CartridgeZemina90=function(a){"use strict";this.connect=function(a){a.bus.connectOutputDevice(119,this.output77)},this.disconnect=function(a){a.bus.disconnectOutputDevice(119,this.output77)},this.powerOn=function(){this.reset()},this.reset=function(){this.output77(0)},this.read=function(a){return a<16384?255:a<32768?b[d+a]:a<49152?f?b[e+a^8192]:b[e+a]:255},this.output77=function(a,b){c=a;var g=63&a,h=a>>6;2===h?(d=((62&g)<<14)-16384,e=((1|g)<<14)-32768):(d=(g<<14)-16384,e=(g<<14)-32768),f=3===h};var b;this.bytes=null;var c,d,e,f;this.rom=null,
this.format=wmsx.SlotFormats.Zemina90in1,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),bc:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,this.output77(a.bc)},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeZemina90.prototype=wmsx.Slot.base,wmsx.CartridgeZemina90.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeZemina90;return c.loadState(a),c},wmsx.CartridgeZemina126=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=d=-16384},this.write=function(a,b){if(16384===a)return void(c=(b%e<<14)-16384);16385===a&&(d=(b%e<<14)-32768)},this.read=function(a){return a<16384?255:a<32768?b[c+a]:a<49152?b[d+a]:255};var b;this.bytes=null;var c,d,e;this.rom=null,this.format=wmsx.SlotFormats.Zemina126in1,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,b2:d}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b1,d=a.b2,e=b.length/16384|0},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,e=b.length/16384|0}(this)},wmsx.CartridgeZemina126.prototype=wmsx.Slot.base,wmsx.CartridgeZemina126.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeZemina126;return c.loadState(a),c},wmsx.CartridgeSuperLodeRunner=function(a){"use strict";function b(a,b){0===a&&(d=(b%e<<14)-32768)}this.connect=function(a){a.bus.setWriteMonitor(b)},this.disconnect=function(a){a.bus.setWriteMonitor(null)},this.powerOn=function(){this.reset()},this.reset=function(){d=32768},this.read=function(a){return a>=32768&&a<49152?c[d+a]:255};var c;this.bytes=null;var d,e;this.rom=null,this.format=wmsx.SlotFormats.SuperLodeRunner,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(c),b1:d}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c),this.bytes=c,d=a.b1,e=c.length/16384|0},a&&function(b){b.rom=a,c=wmsx.Util.asNormalArray(a.content),b.bytes=c,e=c.length/16384|0}(this)},wmsx.CartridgeSuperLodeRunner.prototype=wmsx.Slot.base,wmsx.CartridgeSuperLodeRunner.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeSuperLodeRunner;return c.loadState(a),c},wmsx.CartridgeDooly=function(a){"use strict";this.powerOn=function(){this.reset()},this.reset=function(){c=0},this.write=function(a,b){a>=16384&&a<49152&&(c=7&b)},this.read=function(a){if(a>=16384&&a<49152){var d=b[a-16384];switch(c){case 0:return d;case 1:return 248&d|d<<2&4|d>>1&3;case 4:return 248&d|d>>2&1|d<<1&6;case 2:case 5:case 6:switch(7&d){case 1:case 2:case 4:return 248&d;case 3:case 5:case 6:if(2==c)return 248&d|7^(d<<2&4|d>>1&3);if(5==c)return 7^d;if(6==c)return 248&d|7^(d>>2&1|d<<1&6);default:return d}default:return 7|d}}return 255};var b;this.bytes=null;var c;this.rom=null,this.format=wmsx.SlotFormats.Dooly,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),e:c}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.e},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeDooly.prototype=wmsx.Slot.base,wmsx.CartridgeDooly.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeDooly;return c.loadState(a),c},wmsx.CartridgeMegaRAM=function(a){"use strict";this.reinsertROMContent=function(){this.rom.content&&this.rom.content.length||(this.rom.content=this.bytes.slice(0,this.bytes.length))},this.connect=function(a){a.bus.connectInputDevice(142,this.input8E),a.bus.connectOutputDevice(142,this.output8E)},this.disconnect=function(a){a.bus.disconnectInputDevice(142,this.input8E),a.bus.disconnectOutputDevice(142,this.output8E)},this.powerOn=function(){this.reset()},this.reset=function(){h=!1},this.input8E=function(){return h=!0,255},this.output8E=function(a){h=!1},this.write=function(a,i){if(!(a<16384))return a<24576?void(h?b[d+a]=i:d=(i%c<<13)-16384):a<32768?void(h?b[e+a]=i:e=(i%c<<13)-24576):a<40960?void(h?b[f+a]=i:f=(i%c<<13)-32768):void(a<49152&&(h?b[g+a]=i:g=(i%c<<13)-40960))},this.read=function(a){switch(57344&a){case 16384:return b[d+a];case 24576:return b[e+a];case 32768:return b[f+a];case 40960:return b[g+a];default:return 255}};var b;this.bytes=null;var c,d=-16384,e=-16384,f=-16384,g=-16384,h=!1;this.rom=null,this.format=wmsx.SlotFormats.MegaRAM;var i=Math.min(WMSX.MEGARAM_SIZE/8,256),j=[32,64,128,256];this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:d,b2:e,b3:f,b4:g,n:c,m:h}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,d=a.b1,e=a.b2,f=a.b3,g=a.b4,c=a.n,h=a.m},a&&function(d){d.rom=a;var e=a.content;if(e&&e.length){c=Math.ceil(e.length/8192);for(var f=0;j[f]<c;)++f;c=j[f]}else c=i;b=new Array(8192*c),wmsx.Util.arrayCopy(e,0,b),wmsx.Util.arrayFill(b,0,e.length),d.bytes=b}(this)},wmsx.CartridgeMegaRAM.prototype=wmsx.Slot.base,wmsx.CartridgeMegaRAM.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeMegaRAM;return c.loadState(a),c},wmsx.CartridgeDiskPatched=function(a){"use strict";function b(){f.patchDiskBIOS(c,0-d,16384,22383,22608,30867)}this.connect=function(a){f.connect(this,a),a.getDiskDriveSocket().diskInterfaceConnected(this)},this.disconnect=function(a){f.disconnect(this,a),a.getDiskDriveSocket().diskInterfaceDisconnected(this)},this.powerOff=function(){f.powerOff()},this.read=function(a){return a>=d&&a<e?c[a-d]:255},this.cpuExtensionBegin=function(a){return f.cpuExtensionBegin(a)},this.cpuExtensionFinish=function(a){return f.cpuExtensionFinish(a)};var c;this.bytes=null;var d,e;this.rom=null,this.format=wmsx.SlotFormats.DiskPatch;var f=new wmsx.ImageDiskDriver(!1);this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(c),d:f.saveState(),ba:d}},this.loadState=function(a){if(this.rom=wmsx.ROM.loadState(a.r),d=void 0!==a.ba?a.ba:16384,a.b)c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c),c.length=-16384&c.length,f.rePatchDiskBIOSOldStateForExtensions(c,0-d,16384,22383,22608);else{this.rom.reloadEmbeddedContent();var g=this.rom.content.length;c&&c.length===g||(c=new Array(g)),wmsx.Util.arrayCopy(this.rom.content,0,c),b()}this.bytes=c,e=d+c.length,f.loadState(a.d)},a&&function(f){f.rom=a,c=new Array(a.content.length),wmsx.Util.arrayCopy(a.content,0,c),f.bytes=c,d=16384===a.content.length?16384:16384*(WMSX.DISK_ROM_START_PAGE||0),e=d+c.length,b()}(this)},wmsx.CartridgeDiskPatched.prototype=wmsx.Slot.base,wmsx.CartridgeDiskPatched.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeDiskPatched(null);return c.loadState(a),c},wmsx.CartridgeDiskPatchedDOS2TR=function(a){"use strict";function b(){e.patchDiskBIOS(c,-16384,16384,18390,18630,30756),e.patchDiskBIOS(c,32768,16384,22383,22608,30762)}this.connect=function(a){e.connect(this,a),a.getDiskDriveSocket().diskInterfaceConnected(this),a.getDiskDriveSocket().dos2ROMConnected(this)},this.disconnect=function(a){e.disconnect(this,a),a.getDiskDriveSocket().diskInterfaceDisconnected(this),a.getDiskDriveSocket().dos2ROMDisconnected(this)},this.powerOn=function(){this.reset()},this.reset=function(){d=-16384},this.powerOff=function(){e.powerOff()},this.read=function(a){return a>=16384&&a<32768?c[d+a]:255},this.write=function(a,b){32752===a&&(d=((3&b)<<14)-16384)},this.cpuExtensionBegin=function(a){return e.cpuExtensionBegin(a)},
this.cpuExtensionFinish=function(a){return e.cpuExtensionFinish(a)};var c;this.bytes=null,this.rom=null,this.format=wmsx.SlotFormats.DiskPatchDOS2TR;var d,e=new wmsx.ImageDiskDriver(!0);this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(c),d:e.saveState(),b1:d}},this.loadState=function(a){if(this.rom=wmsx.ROM.loadState(a.r),a.b)c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c);else{this.rom.reloadEmbeddedContent();var f=this.rom.content.length;c&&c.length===f||(c=new Array(f)),wmsx.Util.arrayCopy(this.rom.content,0,c),b()}this.bytes=c,d=a.b1,e.loadState(a.d)},a&&function(d){d.rom=a,c=new Array(a.content.length),wmsx.Util.arrayCopy(a.content,0,c),d.bytes=c,b()}(this)},wmsx.CartridgeDiskPatchedDOS2TR.prototype=wmsx.Slot.base,wmsx.CartridgeDiskPatchedDOS2TR.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeDiskPatchedDOS2TR(null);return c.loadState(a),c},wmsx.CartridgeNextorPatched=function(a){"use strict";this.connect=function(a){d.connect(this,a),a.getDiskDriveSocket().hardDiskInterfaceConnected(this)},this.disconnect=function(a){d.disconnect(this,a),a.getDiskDriveSocket().hardDiskInterfaceDisconnected(this)},this.powerOn=function(){this.reset()},this.powerOff=function(){d.powerOff()},this.reset=function(){c=-16384},this.write=function(a,b){a>=24576&&a<26624&&(c=((7&b)<<14)-16384)},this.read=function(a){return a>=16384&&a<32768?b[c+a]:255},this.cpuExtensionBegin=function(a){return d.cpuExtensionBegin(a)},this.cpuExtensionFinish=function(a){return d.cpuExtensionFinish(a)};var b;this.bytes=null;var c;this.rom=null,this.format=wmsx.SlotFormats.Nextor16Patch;var d=new wmsx.ImageNextorDeviceDriver;this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,d:d.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b&&b.length===this.rom.content.length||(b=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,b)),d.patchNextorKernel(b),this.bytes=b,c=a.b1,d.loadState(a.d)},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,d.patchNextorKernel(b)}(this)},wmsx.CartridgeNextorPatched.prototype=wmsx.Slot.base,wmsx.CartridgeNextorPatched.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeNextorPatched;return c.loadState(a),c},wmsx.CartridgeKonamiSCC=function(rom){"use strict";function init(a){a.rom=rom,bytes=wmsx.Util.asNormalArray(rom.content),a.bytes=bytes,numBanks=bytes.length/8192|0}function connectSCC(){scc.connectAudio(),sccConnected=!0}this.connect=function(a){scc.setAudioSocket(a.getAudioSocket()),sccConnected&&connectSCC()},this.disconnect=function(a){scc.disconnectAudio()},this.powerOn=function(){this.reset()},this.powerOff=function(){scc.disconnectAudio()},this.reset=function(){bank1Offset=bank2Offset=bank3Offset=bank4Offset=-16384,sccSelected=sccConnected=!1,scc.reset()},this.write=function(a,b){return a>=20480&&a<=22527?void(bank1Offset=(b%numBanks<<13)-16384):a>=28672&&a<=30719?void(bank2Offset=(b%numBanks<<13)-24576):a>=36864&&a<=38911?(bank3Offset=(b%numBanks<<13)-32768,void(63==(63&b)?(sccSelected=!0,sccConnected||connectSCC()):sccSelected=!1)):sccSelected&&a>=38912&&a<=40959?void scc.write(a,b):void(a>=45056&&a<=47103&&(bank4Offset=(b%numBanks<<13)-40960))},this.read=function(a){switch(57344&a){case 16384:return bytes[bank1Offset+a];case 24576:return bytes[bank2Offset+a];case 32768:return a>=38912&&sccSelected?scc.read(a):bytes[bank3Offset+a];case 40960:return bytes[bank4Offset+a];default:return 255}};var bytes;this.bytes=null;var bank1Offset,bank2Offset,bank3Offset,bank4Offset,numBanks,scc=new wmsx.SCCIAudio,sccSelected=!1,sccConnected=!1;this.rom=null,this.format=wmsx.SlotFormats.KonamiSCC,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(bytes),b1:bank1Offset,b2:bank2Offset,b3:bank3Offset,b4:bank4Offset,n:numBanks,scc:scc.saveState(),scs:sccSelected,scn:sccConnected}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),bytes=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,bytes),this.bytes=bytes,bank1Offset=a.b1,bank2Offset=a.b2,bank3Offset=a.b3,bank4Offset=a.b4,numBanks=a.n,scc.loadState(a.scc),sccSelected=a.scs,(sccConnected=a.scn)&&connectSCC()},rom&&init(this),this.eval=function(arg){return eval(arg)}},wmsx.CartridgeKonamiSCC.prototype=wmsx.Slot.base,wmsx.CartridgeKonamiSCC.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeKonamiSCC;return c.loadState(a),c},wmsx.CartridgeSCCExpansion=function(a){"use strict";function b(){c.connectAudio(),e=!0}this.connect=function(a){c.setAudioSocket(a.getAudioSocket()),e&&b()},this.disconnect=function(a){c.disconnectAudio()},this.powerOn=function(){this.reset()},this.powerOff=function(){c.disconnectAudio()},this.reset=function(){d=e=!1,c.reset()},this.write=function(a,f){if(a>=36864&&a<=38911)return void(63==(63&f)?(d=!0,e||b()):d=!1);d&&a>=38912&&a<=40959&&c.write(a,f)},this.read=function(a){return d&&a>=38912&&a<=40959?c.read(a):255};var c=new wmsx.SCCIAudio,d=!1,e=!1;this.rom=null,this.format=wmsx.SlotFormats.SCCExpansion,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),scc:c.saveState(),scs:d,scn:e}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),c.loadState(a.scc),d=a.scs,(e=a.scn)&&b()},a&&function(b){b.rom=a}(this)},wmsx.CartridgeSCCExpansion.prototype=wmsx.Slot.base,wmsx.CartridgeSCCExpansion.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeSCCExpansion;return c.loadState(a),c},wmsx.CartridgeSCCIExpansion=function(rom,format,startInSCCI){"use strict";function init(a){a.rom=rom;var b=rom.content;bytes=wmsx.Util.arrayFill(new Array(131072),255),a.bytes=bytes,b.length>0&&(a.preLoadedContentSize=b.length,wmsx.Util.arrayCopy(b,0,bytes),b.length<=65536&&wmsx.Util.arrayCopy(b,0,bytes,65536)),startingMode=startInSCCI?32:0}function setMode(a){mode=a,scciMode=0!=(32&a),scc.setSCCIMode(scciMode);var b=0!=(16&a);bank4RamMode=b,bank3RamMode=b||scciMode&&0!=(4&a),bank2RamMode=b||0!=(2&a),bank1RamMode=b||0!=(1&a)}function connectSCC(){scc.connectAudio(),sccConnected=!0}this.reinsertROMContent=function(){this.rom.content||(this.rom.content=this.bytes?this.bytes.slice(0,this.preLoadedContentSize):[])},this.connect=function(a){scc.setAudioSocket(a.getAudioSocket()),sccConnected&&connectSCC()},this.disconnect=function(a){scc.disconnectAudio()},this.powerOn=function(){this.reset()},this.powerOff=function(){scc.disconnectAudio(),0===this.preLoadedContentSize&&wmsx.Util.arrayFill(bytes,255)},this.reset=function(){bank1Offset=bank2Offset=bank3Offset=bank4Offset=-16384,sccSelected=scciSelected=sccConnected=!1,scc.reset(),setMode(startingMode)},this.read=function(a){switch(57344&a){case 16384:return bytes[bank1Offset+a];case 24576:return bytes[bank2Offset+a];case 32768:return a>=38912&&sccSelected&&!scciMode?scc.read(a):bytes[bank3Offset+a];case 40960:return a>=47104&&scciSelected&&scciMode?scc.read(a):bytes[bank4Offset+a];default:return 255}},this.write=function(a,b){if(49150===a||49151===a)return void setMode(b);switch(57344&a){case 16384:return void(bank1RamMode?bytes[bank1Offset+a]=b:a>=20480&&a<=22527&&(bank1Offset=((15&b)<<13)-16384));case 24576:return void(bank2RamMode?bytes[bank2Offset+a]=b:a>=28672&&a<=30719&&(bank2Offset=((15&b)<<13)-24576));case 32768:return void(bank3RamMode?bytes[bank3Offset+a]=b:a>=36864&&a<=38911?(bank3Offset=((15&b)<<13)-32768,(sccSelected=63==(63&b))&&!sccConnected&&connectSCC()):a>=38912&&sccSelected&&!scciMode&&scc.write(a,b));case 40960:bank4RamMode?bytes[bank4Offset+a]=b:a>=45056&&a<=47103?(bank4Offset=((15&b)<<13)-40960,
(scciSelected=128==(128&b))&&!sccConnected&&connectSCC()):a>=47104&&scciSelected&&scciMode&&scc.write(a,b)}};var bytes;this.bytes=null;var startingMode=0,mode,scciMode,bank4RamMode,bank3RamMode,bank2RamMode,bank1RamMode,bank1Offset,bank2Offset,bank3Offset,bank4Offset,scc=new wmsx.SCCIAudio,sccSelected,scciSelected=!1,sccConnected=!1;this.rom=null,this.format=format,this.preLoadedContentSize=0,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),pcs:this.preLoadedContentSize,b:wmsx.Util.compressInt8BitArrayToStringBase64(bytes),sm:startingMode,m:mode,b1:bank1Offset,b2:bank2Offset,b3:bank3Offset,b4:bank4Offset,scc:scc.saveState(),scs:sccSelected,sis:scciSelected,scn:sccConnected}},this.loadState=function(a){this.format=wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),this.preLoadedContentSize=a.pcs||0,bytes=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,bytes),this.bytes=bytes,bank1Offset=a.b1,bank2Offset=a.b2,bank3Offset=a.b3,bank4Offset=a.b4,startingMode=a.sm||0,setMode(void 0!==a.m?a.m:startingMode),scc.loadState(a.scc),sccSelected=a.scs,scciSelected=a.sis,(sccConnected=a.scn)&&connectSCC()},this.eval=function(str){return eval(str)},rom&&init(this)},wmsx.CartridgeSCCIExpansion.prototype=wmsx.Slot.base,wmsx.CartridgeSCCIExpansion.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeSCCIExpansion;return c.loadState(a),c},wmsx.CartridgeManbow2=function(rom){"use strict";function init(a){a.rom=rom,bytes=wmsx.Util.asNormalArray(rom.content),a.bytes=bytes}function writeMem(a,b){a>=458752&&a<524288&&(bytes[a]=b,sramModif||(sramModif=!0,cartridgeSocket.fireCartridgesModifiedStateUpdate()))}function connectSCC(){scc.connectAudio(),sccConnected=!0}this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){if(65536!==b.length)return null;for(var c=0;c<65536;++c)bytes[458752+c]=b[c];return sramContentName=a,b},this.getDataToSave=function(){sramModif=!1,cartridgeSocket.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(bytes.slice(458752));return{fileName:sramContentName||"Manbow2.sram",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return sramModif},this.connect=function(a){cartridgeSocket=a.getCartridgeSocket(),scc.setAudioSocket(a.getAudioSocket()),sccConnected&&connectSCC()},this.disconnect=function(a){scc.disconnectAudio()},this.powerOn=function(){this.reset()},this.powerOff=function(){scc.disconnectAudio()},this.reset=function(){bank1Offset=bank2Offset=bank3Offset=bank4Offset=-16384,sccSelected=sccConnected=!1,scc.reset()},this.read=function(a){switch(57344&a){case 16384:return bytes[bank1Offset+a];case 24576:return bytes[bank2Offset+a];case 32768:return sccSelected&&a>=38912?scc.read(a):bytes[bank3Offset+a];case 40960:return bytes[bank4Offset+a];default:return 255}},this.write=function(a,b){switch(57344&a){case 16384:return writeMem(bank1Offset+a,b),void(a>=20480&&a<=22527&&(bank1Offset=((b&bankSelMask)<<13)-16384));case 24576:return writeMem(bank2Offset+a,b),void(a>=28672&&a<=30719&&(bank2Offset=((b&bankSelMask)<<13)-24576));case 32768:return sccSelected&&a>=38912&&scc.write(a,b),writeMem(bank3Offset+a,b),void(a>=36864&&a<=38911&&(bank3Offset=((b&bankSelMask)<<13)-32768,(sccSelected=63==(63&b))&&!sccConnected&&connectSCC()));case 40960:writeMem(bank4Offset+a,b),a>=45056&&a<=47103&&(bank4Offset=8192*(b&bankSelMask)-40960)}};var bytes;this.bytes=null;var bank1Offset,bank2Offset,bank3Offset,bank4Offset,bankSelMask=63,scc=new wmsx.SCCIAudio,sccSelected=!1,sccConnected=!1,sramContentName,sramModif=!1,cartridgeSocket;this.rom=null,this.format=wmsx.SlotFormats.Manbow2,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(bytes),b1:bank1Offset,b2:bank2Offset,b3:bank3Offset,b4:bank4Offset,scc:scc.saveState(),scs:sccSelected,scn:sccConnected,sn:sramContentName,d:sramModif}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),bytes=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,bytes),this.bytes=bytes,bank1Offset=a.b1,bank2Offset=a.b2,bank3Offset=a.b3,bank4Offset=a.b4,scc.loadState(a.scc),sccSelected=a.scs,sccConnected=a.scn,sramContentName=a.sn,sramModif=!!a.d,sccConnected&&connectSCC()},this.eval=function(str){return eval(str)},rom&&init(this)},wmsx.CartridgeManbow2.prototype=wmsx.Slot.base,wmsx.CartridgeManbow2.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeManbow2;return c.loadState(a),c},wmsx.CartridgeKonamiUltimateCollection=function(rom){"use strict";function init(a){a.rom=rom,bytes=wmsx.Util.arrayFill(new Array(8388608),255),a.bytes=bytes,rom.content.length>0&&wmsx.Util.arrayCopy(rom.content,0,bytes)}function setSCCMode(a){sccMode=48&a,scc.setSCCIMode(0!=(32&a))}function connectSCC(){scc.connectAudio(),sccConnected=!0}function connectPCM(){pcm.connectAudio(),pcmConnected=!0}this.getDataDesc=function(){return"Flash"},this.loadData=function(a,b){return 0===b.length||b.length>8388608||0!=(8191&rom.content.length)?null:(wmsx.Util.arrayCopy(b,0,bytes),sramContentName=a,b)},this.getDataToSave=function(){sramModif=!1,cartridgeSocket.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(bytes);return{fileName:sramContentName||"KonamiUltimateCollection.dat",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return sramModif},this.connect=function(a){cartridgeSocket=a.getCartridgeSocket(),scc.setAudioSocket(a.getAudioSocket()),pcm.setAudioSocket(a.getAudioSocket()),sccConnected&&connectSCC(),pcmConnected&&connectPCM()},this.disconnect=function(a){scc.disconnectAudio(),pcm.disconnectAudio()},this.powerOn=function(){this.reset()},this.powerOff=function(){scc.disconnectAudio(),pcm.disconnectAudio(),this.reset()},this.reset=function(){mapperMode=0,banksOffset=0,addressOffset=0,bank1No=0,bank2No=1,bank3No=2,bank4No=3,sccSelected=scciSelected=sccConnected=!1,pcmConnected=!1,scc.reset(),setSCCMode(0),pcm.reset()},this.read=function(a){switch(57344&a){case 16384:return bytes[addressOffset|(bank1No+banksOffset&255)<<13|8191&a];case 24576:return bytes[addressOffset|(bank2No+banksOffset&255)<<13|8191&a];case 32768:return!(256&a)&&a>=38912&&a<40958&&sccSelected&&0===sccMode?scc.read(a):bytes[addressOffset|(bank3No+banksOffset&255)<<13|8191&a];case 40960:return!(256&a)&&a>=47104&&a<49150&&scciSelected&&32===sccMode?scc.read(a):bytes[addressOffset|(bank4No+banksOffset&255)<<13|8191&a];default:return 255}},this.write=function(a,b){if(!(256&a)&&(0===sccMode&&a>=38912&&a<40958&&sccSelected||32===sccMode&&a>=47104&&a<49150&&scciSelected))return scc.write(a,b);if(4&mapperMode||(32767===a?(mapperMode=b,addressOffset=(192&b)<<15):32766===a&&(banksOffset=b)),16&mapperMode)switch(57344&a){case 16384:bytes[addressOffset|(bank1No+banksOffset&255)<<13|8191&a]=b,sramModif=!0;break;case 24576:bytes[addressOffset|(bank2No+banksOffset&255)<<13|8191&a]=b,sramModif=!0;break;case 32768:bytes[addressOffset|(bank3No+banksOffset&255)<<13|8191&a]=b,sramModif=!0;break;case 40960:bytes[addressOffset|(bank4No+banksOffset&255)<<13|8191&a]=b,sramModif=!0}if(8&mapperMode&&16384==(49168&a)&&(pcmConnected||connectPCM(),pcm.setSampleValue(b)),!(2&mapperMode)){if(32&mapperMode)switch(57344&a){case 16384:!(8&mapperMode)&&a>=20480&&a<=22527&&(bank1No=b);break;case 24576:bank2No=b;break;case 32768:bank3No=b,sccSelected=63==(63&b);break;case 40960:bank4No=b,scciSelected=128==(128&b)}else switch(57344&a){case 16384:a>=20480&&a<=22527&&(bank1No=b);break;case 24576:a>=28672&&a<=30719&&(bank2No=b);break;case 32768:a>=36864&&a<=38911&&(bank3No=b,sccSelected=63==(63&b));break;case 40960:a>=45056&&a<=47103&&(bank4No=b,scciSelected=128==(128&b))}49150!==a&&49151!==a||setSCCMode(b),!sccSelected&&!scciSelected||sccConnected||connectSCC()}};var cartridgeSocket,bytes;this.bytes=null
;var mapperMode=0,banksOffset=0,addressOffset=0,bank1No=0,bank2No=1,bank3No=2,bank4No=3,scc=new wmsx.SCCIAudio,sccMode=0,sccSelected=!1,scciSelected=!1,sccConnected=!1,pcm=new wmsx.PCM8BitAudio,pcmConnected=!1,sramContentName,sramModif=!1;this.rom=null,this.format=wmsx.SlotFormats.KonamiUltimateCollection,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(bytes),mm:mapperMode,bo:banksOffset,ao:addressOffset,b1:bank1No,b2:bank2No,b3:bank3No,b4:bank4No,scm:sccMode,scc:scc.saveState(),scs:sccSelected,sis:scciSelected,scn:sccConnected,pcm:pcm.saveState(),pcn:pcmConnected}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),bytes=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,bytes),this.bytes=bytes,mapperMode=a.mm,banksOffset=a.bo,addressOffset=a.ao,bank1No=a.b1,bank2No=a.b2,bank3No=a.b3,bank4No=a.b4,setSCCMode(a.scm),scc.loadState(a.scc),sccSelected=a.scs,scciSelected=a.sis,sccConnected=a.scn,pcm.loadState(a.pcm),pcmConnected=a.pcn,sccConnected&&connectSCC(),pcmConnected&&connectPCM()},this.eval=function(str){return eval(str)},rom&&init(this)},wmsx.CartridgeKonamiUltimateCollection.prototype=wmsx.Slot.base,wmsx.CartridgeKonamiUltimateCollection.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeKonamiUltimateCollection;return c.loadState(a),c},wmsx.CartridgeKanjiFont=function(a){"use strict";var b=this;this.connect=function(a){a.bus.connectInputDevice(216,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectInputDevice(217,this.inputD9),a.bus.connectOutputDevice(216,this.outputD8),a.bus.connectOutputDevice(217,this.outputD9),a.bus.connectInputDevice(218,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectInputDevice(219,this.inputDB),a.bus.connectOutputDevice(218,this.outputDA),a.bus.connectOutputDevice(219,this.outputDB),wmsx.CartridgeKanjiFont.connectedInstance=this},this.disconnect=function(a){a.bus.disconnectInputDevice(216,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectInputDevice(217,this.inputD9),a.bus.disconnectOutputDevice(216,this.outputD8),a.bus.disconnectOutputDevice(217,this.outputD9),a.bus.disconnectInputDevice(218,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectInputDevice(219,this.inputDB),a.bus.disconnectOutputDevice(218,this.outputDA),a.bus.disconnectOutputDevice(219,this.outputDB),wmsx.CartridgeKanjiFont.connectedInstance===this&&(wmsx.CartridgeKanjiFont.connectedInstance=void 0)},this.powerOn=function(){this.reset()},this.powerOff=function(){},this.readKanji=function(a){return f||a<131072?c[a]:255},this.reset=function(){d=0,e=131072},this.read=function(a){return 255},this.write=function(a,b){},this.outputD8=function(a){d=129024&d|(63&a)<<5},this.outputD9=function(a){d=(63&a)<<11|2016&d},this.inputD9=function(){var a=b.readKanji(d);return d=131040&d|d+1&31,a},this.outputDA=function(a){e=260096&e|(63&a)<<5},this.outputDB=function(a){e=131072|(63&a)<<11|2016&e},this.inputDB=function(){var a=b.readKanji(e);return e=262112&e|e+1&31,a};var c,d=0,e=0,f=!1;this.bytes=null,this.rom=null,this.format=wmsx.SlotFormats.Kanji1,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(c),r1:d,r2:e,j2:f}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c):(this.rom.reloadEmbeddedContent(),c&&c.length===this.rom.content.length||(c=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,c)),this.bytes=c,d=a.r1,e=131072|a.r2,f=a.j2},a&&function(b){b.rom=a,c=wmsx.Util.asNormalArray(a.content),b.bytes=c,f=262144===c.length}(this)},wmsx.CartridgeKanjiFont.prototype=wmsx.Slot.base,wmsx.CartridgeKanjiFont.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeKanjiFont;return c.loadState(a),c},wmsx.CartridgeKanjiFont.connectedInstance=void 0,wmsx.CartridgePAC=function(a){"use strict";function b(a,b){e=a;for(var d=wmsx.CartridgePAC.DATA_FILE_IDENTIFIER.length,f=0,g=c.length-2;f<g;f++)c[f]=b[d+f]}this.connect=function(a){f=a.getCartridgeSocket()},this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,d){return wmsx.CartridgePAC.isPACFileContentValid(d)?(b(a,d),c):null},this.getDataToSave=function(){g=!1,f.fireCartridgesModifiedStateUpdate();var a=wmsx.CartridgePAC.buildPACFileContentToSave(c);return{fileName:e||"PAC SRAM.pac",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return g},this.powerOn=function(){this.reset()},this.reset=function(){d=!1},this.write=function(a,b){if(24574===a||24575===a)return c[a-16384]=b,void(d=77===c[8190]&&105===c[8191]);d&&a>=16384&&a<=24573&&(c[a-16384]=b,g||(g=!0,f.fireCartridgesModifiedStateUpdate()))},this.read=function(a){return d&&a>=16384&&a<=24575?c[a-16384]:255};var c,d;this.sram=null;var e,f,g=!1;this.rom=null,this.format=wmsx.SlotFormats.PACExpansion,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),sa:d,s:wmsx.Util.compressInt8BitArrayToStringBase64(c),sn:e,d:g}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),d=a.sa,c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,c),e=a.sn,g=!!a.d},a&&function(d){d.rom=a,c=wmsx.Util.arrayFill(new Array(8192),0),d.sram=c,0!==a.content.length&&b(a.source,a.content)}(this)},wmsx.CartridgePAC.prototype=wmsx.Slot.base,wmsx.CartridgePAC.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgePAC;return c.loadState(a),c},wmsx.CartridgePAC.isPACFileContentValid=function(a){return 8206===a.length&&wmsx.Util.int8BitArrayToByteString(a,0,wmsx.CartridgePAC.DATA_FILE_IDENTIFIER.length)==wmsx.CartridgePAC.DATA_FILE_IDENTIFIER},wmsx.CartridgePAC.buildPACFileContentToSave=function(a){var b=new Uint8Array(wmsx.CartridgePAC.DATA_FILE_IDENTIFIER.length+a.length-2);return b.set(wmsx.Util.byteStringToInt8BitArray(wmsx.CartridgePAC.DATA_FILE_IDENTIFIER)),b.set(a.slice(0,-2),wmsx.CartridgePAC.DATA_FILE_IDENTIFIER.length),b},wmsx.CartridgePAC.DATA_FILE_IDENTIFIER="PAC2 BACKUP DATA",wmsx.CartridgeMSXMUSIC=function(a){"use strict";this.connect=function(a){c.connect(a)},this.disconnect=function(a){c.disconnect(a)},this.powerOn=function(){c.powerOn(),this.reset()},this.powerOff=function(){c.powerOff()},this.reset=function(){c.reset()},this.read=function(a){return a>=16384&&a<32768?b[a-16384]:255};var b;this.bytes=null,this.rom=null,this.format=wmsx.SlotFormats.MSXMUSIC;var c=new wmsx.YM2413Audio("MSX-MUSIC");this.opll=c,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),fm:c.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b&&b.length===this.rom.content.length||(b=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,b)),this.bytes=b,c.loadState(a.fm)},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b}(this)},wmsx.CartridgeMSXMUSIC.prototype=wmsx.Slot.base,wmsx.CartridgeMSXMUSIC.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeMSXMUSIC;return c.loadState(a),c},wmsx.CartridgeFMPAC=function(a){"use strict";function b(){k&&(1&i?m.connect(k):m.disconnect(k))}function c(a,b){g=a;for(var c=wmsx.CartridgePAC.DATA_FILE_IDENTIFIER.length,d=0,f=e.length-2;d<f;d++)e[d]=b[c+d]}this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){return wmsx.CartridgePAC.isPACFileContentValid(b)?(c(a,b),e):null},this.getDataToSave=function(){l=!1,h.fireCartridgesModifiedStateUpdate();var a=wmsx.CartridgePAC.buildPACFileContentToSave(e);return{fileName:g||"PAC SRAM.pac",content:a,desc:this.getDataDesc()}},this.connect=function(a){k=a,h=k.getCartridgeSocket(),b()},this.disconnect=function(a){m.disconnect(a)},this.dataModified=function(){return l},this.powerOn=function(){m.powerOn(),this.reset()},
this.powerOff=function(){m.powerOff()},this.reset=function(){f=!1,j=-16384,i=0,b(),m.reset()},this.write=function(a,c){switch(a){case 32756:m.output7C(c);break;case 32757:m.output7D(c);break;case 32758:i=17&c,b();break;case 32759:j=((3&c)<<14)-16384;break;case 24574:case 24575:e[a-16384]=c,f=77===e[8190]&&105===e[8191]}f&&a>=16384&&a<=24573&&(e[a-16384]=c,l||(l=!0,h.fireCartridgesModifiedStateUpdate()))},this.read=function(a){return 32758===a?i:32759===a?j+16384>>14:f?a>=16384&&a<=24575?e[a-16384]:255:a>=16384&&a<32768?d[j+a]:255};var d;this.bytes=null;var e,f;this.sram=null;var g,h,i,j,k,l=!1;this.rom=null,this.format=wmsx.SlotFormats.FMPAC;var m=new wmsx.YM2413Audio("FM-PAC");this.opll=m,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(d),b1:j,fe:i,sa:f,s:wmsx.Util.compressInt8BitArrayToStringBase64(e),sn:g,fm:m.saveState(),d:l}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),d=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,d),this.bytes=d,j=a.b1,i=a.fe,f=a.sa,e=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,e),g=a.sn,m.loadState(a.fm),l=!!a.d,b()},a&&function(b){b.rom=a,d=wmsx.Util.asNormalArray(a.content),b.bytes=d,e=wmsx.Util.arrayFill(new Array(8192),0),b.sram=e}(this)},wmsx.CartridgeFMPAC.prototype=wmsx.Slot.base,wmsx.CartridgeFMPAC.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeFMPAC;return c.loadState(a),c},wmsx.CartridgeOPL4=function(a){"use strict";this.connect=function(a){c.connect(a)},this.disconnect=function(a){c.disconnect(a)},this.powerOn=function(){c.powerOn(),this.reset()},this.powerOff=function(){c.powerOff()},this.reset=function(){c.reset()},this.opl4ReadMemory=function(a){return b[4194303&a]},this.opl4WriteMemory=function(a,c){(4194303&a)<2097152||(b[4194303&a]=c)};var b;this.bytes=null,this.rom=null,this.format=wmsx.SlotFormats.OPL4;var c=new wmsx.OPL4Audio("OPL4",this);this.opl4=c,this.saveState=function(){var a=this.lightState();return{f:this.format.name,r:this.rom.saveState(),b:a?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),ra:a?wmsx.Util.compressInt8BitArrayToStringBase64(b,2097152,2097152):null,opl4:c.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b||(b=new Array(4194304)),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.ra,b,!0,null,2097152),wmsx.Util.arrayCopy(this.rom.content,0,b)),this.bytes=b,c.loadState(a.opl4)},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content,0,4194304),wmsx.Util.arrayFill(b,0,2097152),c.bytes=b}(this)},wmsx.CartridgeOPL4.prototype=wmsx.Slot.base,wmsx.CartridgeOPL4.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeOPL4;return c.loadState(a),c},wmsx.CartridgeExtraPSG=function(a){"use strict";this.connect=function(a){b.setAudioSocket(a.getAudioSocket()),b.connectBus(a.bus)},this.disconnect=function(a){b.disconnectBus(a.bus)},this.powerOn=function(){b.powerOn()},this.powerOff=function(){b.powerOff()},this.reset=function(){b.reset()};var b=new wmsx.PSG(null,null,!0);this.rom=null,this.format=wmsx.SlotFormats.ExtraPSG,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),p:b.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b.loadState(a.p)},a&&function(b){b.rom=a}(this)},wmsx.CartridgeExtraPSG.prototype=wmsx.Slot.base,wmsx.CartridgeExtraPSG.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeExtraPSG;return c.loadState(a),c},wmsx.CartridgeV9990=function(a){"use strict";function b(){switch(26&e){case 16:case 18:f=0;break;case 24:f=2;break;case 26:f=3;break;default:f=1}d.getVideoSignal().setOutputAutoMode(f)}var c=this;this.connect=function(a){d.connect(a,this),a.getVideoSocket().connectExternalVideoSignal(d.getVideoSignal()),a.bus.connectInputDevice(111,wmsx.DeviceMissing.inputPortIgnored),a.bus.connectOutputDevice(111,this.output6f)},this.disconnect=function(a){d.disconnect(a),a.getVideoSocket().disconnectExternalVideoSignal(d.getVideoSignal()),a.bus.disconnectInputDevice(111,wmsx.DeviceMissing.inputPortIgnored),a.bus.disconnectOutputDevice(111,this.output6f)},this.powerOn=function(){d.powerOn()},this.powerOff=function(){d.powerOff(),this.resetOutputAutoMode()},this.reset=function(){d.reset(),this.resetOutputAutoMode()},this.resetOutputAutoMode=function(){c.output6f(16)},this.v9990DisplayEnabled=function(){0===f&&this.output6f(0)},this.output6f=function(a){e=a,b()},this.rom=null,this.format=wmsx.SlotFormats.V9990;var d=new wmsx.V9990;this.v9990=d;var e=16,f=0;this.saveState=function(){this.lightState();return{f:this.format.name,r:this.rom.saveState(),c:e,vdp:d.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),e=a.c,d.loadState(a.vdp),b()},a&&function(){c.rom=a}()},wmsx.CartridgeV9990.prototype=wmsx.Slot.base,wmsx.CartridgeV9990.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeV9990;return c.loadState(a),c},wmsx.CartridgeGameMaster2=function(a){"use strict";this.connect=function(a){h=a.getCartridgeSocket()},this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){if(8192!==b.length)return null;for(var c=0;c<8192;++c)f[c]=b[c];return g=a,b},this.getDataToSave=function(){i=!1,h.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(f);return{fileName:g||"GameMaster2.sram",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return i},this.powerOn=function(){this.reset()},this.reset=function(){c=1,d=2,e=3},this.write=function(a,b){if(!(a<24576||a>=49152))return a<28672?void(c=b):a>=32768&&a<36864?void(d=b):a>=40960&&a<45056?void(e=b):void(a>=45056&&16&e&&(f[((32&e)<<7)+a-45056]=b,i||(i=!0,h.fireCartridgesModifiedStateUpdate())))},this.read=function(a){switch(57344&a){case 16384:return b[a-16384];case 24576:return 16&c?f[((32&c)<<7)+(a-24576&4095)]:b[((15&c)<<13)+a-24576];case 32768:return 16&d?f[((32&d)<<7)+(a-32768&4095)]:b[((15&d)<<13)+a-32768];case 40960:return 16&e?f[((32&e)<<7)+(a-40960&4095)]:b[((15&e)<<13)+a-40960];default:return 255}};var b;this.bytes=null;var c,d,e,f;this.sram=null;var g,h,i=!1;this.rom=null,this.format=wmsx.SlotFormats.GameMaster2,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b2:c,b3:d,b4:e,s:wmsx.Util.compressInt8BitArrayToStringBase64(f),sn:g,d:i}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b2,d=a.b3,e=a.b4,f=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,f),this.sram=f,g=a.sn,i=!!a.d},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,f=wmsx.Util.arrayFill(new Array(8192),0),c.sram=f}(this)},wmsx.CartridgeGameMaster2.prototype=wmsx.Slot.base,wmsx.CartridgeGameMaster2.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeGameMaster2;return c.loadState(a),c},wmsx.CartridgeASCII8KSRAM=function(a,b){"use strict";this.connect=function(a){n=a.getCartridgeSocket()},this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){var c=l+1;if(b.length!==c)return null;for(var d=0;d<c;++d)k[d]=b[d];return m=a,b},this.getDataToSave=function(){o=!1,n.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(k);return{fileName:m||"Data.sram",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return o},this.powerOn=function(){this.reset()},this.reset=function(){d=e=f=g=0},this.write=function(a,b){if(!(a<16384||a>=49152))return a<24576?void(p&&d&j&&(k[((3&d)<<13)+a-16384&l]=b,o||(o=!0,n.fireCartridgesModifiedStateUpdate()))):a<26624?void(d=b):a<28672?void(e=b):a<30720?void(f=b):a<32768?void(g=b):a<40960?void(f&j&&(k[((3&f)<<13)+a-32768&l]=b,o||(o=!0,n.fireCartridgesModifiedStateUpdate()))):void(g&j&&(k[((3&g)<<13)+a-40960&l]=b,o||(o=!0,n.fireCartridgesModifiedStateUpdate())))},this.read=function(a){
switch(57344&a){case 16384:return p&&d&j?k[((3&d)<<13)+a-16384&l]:c[((d&i)%h<<13)+a-16384];case 24576:return 0|c[((e&i)%h<<13)+a-24576];case 32768:return f&j?k[((3&f)<<13)+a-32768&l]:c[((f&i)%h<<13)+a-32768];case 40960:return g&j?k[((3&g)<<13)+a-40960&l]:c[((g&i)%h<<13)+a-40960];default:return 255}};var c;this.bytes=null;var d,e,f,g,h,i,j,k;this.sram=null;var l,m,n,o=!1,p=!1;this.rom=null,this.format=b,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(c),b1:d,b2:e,b3:f,b4:g,n:h,rsm:i,s:wmsx.Util.compressInt8BitArrayToStringBase64(k),sn:m,ssm:j,d:o}},this.loadState=function(a){this.format=wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c),this.bytes=c,d=a.b1,e=a.b2,f=a.b3,g=a.b4,h=a.n,i=a.rsm,p=this.format===wmsx.SlotFormats.KoeiSRAM8||this.format===wmsx.SlotFormats.KoeiSRAM32,k=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,k),this.sram=k,l=k.length-1,m=a.sn,j=a.ssm,o=!!a.d},a&&function(d){d.rom=a,c=wmsx.Util.asNormalArray(a.content),d.bytes=c,h=c.length/8192|0;var e=b===wmsx.SlotFormats.KoeiSRAM32?32768:b===wmsx.SlotFormats.ASCII8SRAM2?2048:8192;l=e-1,k=wmsx.Util.arrayFill(new Array(e),0),d.sram=k;var f=1<<Math.ceil(wmsx.Util.log2(h));i=f-1,j=b===wmsx.SlotFormats.Wizardry?128:Math.max(32,f),p=b===wmsx.SlotFormats.KoeiSRAM8||b===wmsx.SlotFormats.KoeiSRAM32}(this)};wmsx.CartridgeASCII8KSRAM.prototype=wmsx.Slot.base,wmsx.CartridgeASCII8KSRAM.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeASCII8KSRAM;return c.loadState(a),c},wmsx.CartridgeASCII16KSRAM=function(a,b){"use strict";this.connect=function(a){l=a.getCartridgeSocket()},this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){var c=j+1;if(b.length!==c)return null;for(var d=0;d<c;++d)i[d]=b[d];return k=a,b},this.getDataToSave=function(){m=!1,l.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(i);return{fileName:k||"Data.sram",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return m},this.powerOn=function(){this.reset()},this.reset=function(){d=e=0},this.write=function(a,b){return a>=24576&&a<26624?void(d=b):a>=28672&&a<30720?void(e=b):void(a>=32768&&a<49152&&e&h&&(i[a-32768&j]=b,m||(m=!0,l.fireCartridgesModifiedStateUpdate())))},this.read=function(a){switch(49152&a){case 16384:return d&h?i[a-16384&j]:c[((d&g)%f<<14)+a-16384];case 32768:return e&h?i[a-32768&j]:c[((e&g)%f<<14)+a-32768];default:return 255}};var c;this.bytes=null;var d,e,f,g,h,i;this.sram=null;var j,k,l,m=!1;this.rom=null,this.format=b,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(c),b1:d,b2:e,n:f,rsm:g,s:wmsx.Util.compressInt8BitArrayToStringBase64(i),sn:k,ssm:h,d:m}},this.loadState=function(a){this.format=wmsx.SlotFormats[a.f],this.rom=wmsx.ROM.loadState(a.r),c=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,c),this.bytes=c,d=a.b1,e=a.b2,f=a.n,g=a.rsm,i=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,i),this.sram=i,j=i.length-1,k=a.sn,h=a.ssm,m=!!a.d},a&&function(d){d.rom=a,c=wmsx.Util.asNormalArray(a.content),d.bytes=c,f=c.length/16384|0;var e=b===wmsx.SlotFormats.ASCII16SRAM2?2048:8192;j=e-1,i=wmsx.Util.arrayFill(new Array(e),0),d.sram=i;var k=1<<Math.ceil(wmsx.Util.log2(f));g=k-1,h=Math.max(16,k)}(this)},wmsx.CartridgeASCII16KSRAM.prototype=wmsx.Slot.base,wmsx.CartridgeASCII16KSRAM.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeASCII16KSRAM;return c.loadState(a),c},wmsx.CartridgeHalnote=function(a){"use strict";this.connect=function(a){m=a.getCartridgeSocket()},this.getDataDesc=function(){return"SRAM"},this.loadData=function(a,b){if(16384!==b.length)return null;for(var c=0;c<16384;++c)j[c]=b[c];return l=a,b},this.getDataToSave=function(){n=!1,m.fireCartridgesModifiedStateUpdate();var a=new Uint8Array(j);return{fileName:l||"Halnote.sram",content:a,desc:this.getDataDesc()}},this.dataModified=function(){return n},this.powerOn=function(){this.reset()},this.reset=function(){c=-16384,d=-24576,e=-32768,f=-40960,g=495616,h=493568,i=k=!1},this.write=function(a,b){switch(a){case 20479:return c=((127&b)<<13)-16384,void(k=0!=(128&b));case 28671:return d=((127&b)<<13)-24576,void(i=0!=(128&b));case 36863:return void(e=((127&b)<<13)-32768);case 45055:return void(f=((127&b)<<13)-40960);case 30719:return void(g=(b<<11)-28672+524288);case 32767:return void(h=(b<<11)-30720+524288)}k&&a<16384&&(n||j[a]===b||(n=!0,m.fireCartridgesModifiedStateUpdate()),j[a]=b)},this.read=function(a){switch(57344&a){case 0:case 8192:return k?j[a]:255;case 16384:return b[c+a];case 24576:return a>=28672&&i?b[(a<30720?g:h)+a]:b[d+a];case 32768:return b[e+a];case 40960:return b[f+a];default:return 255}};var b;this.bytes=null;var c,d,e,f,g,h,i,j;this.sram=null;var k,l,m,n=!1;this.rom=null,this.format=wmsx.SlotFormats.Halnote,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:this.lightState()?null:wmsx.Util.compressInt8BitArrayToStringBase64(b),b1:c,b2:d,b3:e,b4:f,sb1:g,sb2:h,sbe:i,s:wmsx.Util.compressInt8BitArrayToStringBase64(j),se:k,sn:l,d:n}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),a.b?b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b):(this.rom.reloadEmbeddedContent(),b&&b.length===this.rom.content.length||(b=new Array(this.rom.content.length)),wmsx.Util.arrayCopy(this.rom.content,0,b)),this.bytes=b,c=a.b1,d=a.b2,e=a.b3,f=a.b4,g=a.sb1,h=a.sb2,i=a.sbe,j=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.s,j),this.sram=j,k=a.se,l=a.sn,n=!!a.d},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,j=wmsx.Util.arrayFill(new Array(16384),0),c.sram=j}(this)},wmsx.CartridgeHalnote.prototype=wmsx.Slot.base,wmsx.CartridgeHalnote.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeHalnote;return c.loadState(a),c},wmsx.CartridgeMajutsushi=function(a){"use strict";this.connect=function(a){g.setAudioSocket(a.getAudioSocket()),g.connectAudio()},this.disconnect=function(a){g.disconnectAudio()},this.powerOn=function(){this.reset(),g.connectAudio()},this.powerOff=function(){g.disconnectAudio(),this.reset()},this.reset=function(){c=d=e=-16384,g.reset()},this.write=function(a,b){a>=20480&&a<24575?g.setSampleValue(b):a>=24576&&a<32767?c=(b%f<<13)-24576:a>=32768&&a<40959?d=(b%f<<13)-32768:a>=40960&&a<49151&&(e=(b%f<<13)-40960)},this.read=function(a){switch(57344&a){case 16384:return b[a-16384];case 24576:return b[c+a];case 32768:return b[d+a];case 40960:return b[e+a];default:return 255}};var b;this.bytes=null;var c,d,e,f,g=new wmsx.PCM8BitAudio;this.rom=null,this.format=wmsx.SlotFormats.Majutsushi,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),b:wmsx.Util.compressInt8BitArrayToStringBase64(b),b2:c,b3:d,b4:e,n:f,p:g.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c=a.b2,d=a.b3,e=a.b4,f=a.n,g.loadState(a.p)},a&&function(c){c.rom=a,b=wmsx.Util.asNormalArray(a.content),c.bytes=b,f=b.length/8192|0}(this)},wmsx.CartridgeMajutsushi.prototype=wmsx.Slot.base,wmsx.CartridgeMajutsushi.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeMajutsushi;return c.loadState(a),c},wmsx.CartridgeSynthesizer=function(a){"use strict";this.connect=function(a){c.setAudioSocket(a.getAudioSocket()),c.connectAudio()},this.disconnect=function(a){c.disconnectAudio()},this.powerOn=function(){this.reset(),c.connectAudio()},this.powerOff=function(){c.disconnectAudio(),this.reset()},this.reset=function(){c.reset()},this.write=function(a,b){16384==(49168&a)&&c.setSampleValue(b)},this.read=function(a){return a>=16384&&a<49152?b[a-16384]:255};var b;this.bytes=null;var c=new wmsx.PCM8BitAudio;this.rom=null,this.format=wmsx.SlotFormats.Synthesizer,this.saveState=function(){return{f:this.format.name,r:this.rom.saveState(),
b:wmsx.Util.compressInt8BitArrayToStringBase64(b),p:c.saveState()}},this.loadState=function(a){this.rom=wmsx.ROM.loadState(a.r),b=wmsx.Util.uncompressStringBase64ToInt8BitArray(a.b,b),this.bytes=b,c.loadState(a.p)},a&&function(c){c.rom=a,b=wmsx.Util.arrayFill(new Array(32768),255),c.bytes=b;for(var d=a.content.length,e=0;e<32768;++e)b[e]=a.content[e%d]}(this)},wmsx.CartridgeSynthesizer.prototype=wmsx.Slot.base,wmsx.CartridgeSynthesizer.recreateFromSaveState=function(a,b){var c=b||new wmsx.CartridgeSynthesizer;return c.loadState(a),c},wmsx.MachineTypeSocket=function(a){"use strict";this.getMachine=function(){return a.machineName},this.getMachineLang=function(){return WMSX.MACHINES_CONFIG[a.machineName].LANG||"en"},this.getMachineType=function(){return WMSX.MACHINES_CONFIG[a.machineName].TYPE||1},this.getCodeKeyLabel=function(){return WMSX.MACHINES_CONFIG[a.machineName].CODE_LABEL||"CODE"},this.getCodeLedLabel=function(){return WMSX.MACHINES_CONFIG[a.machineName].CODE_LABEL||"KANA"},this.changeMachine=function(b){if(a.machineName!==b){if(WMSX.MEDIA_CHANGE_DISABLED)return b.showOSD("Machine change is disabled!",!0,!0);var c=WMSX.MACHINES_CONFIG[b];if(c){var d=a.powerIsOn;a.powerOff();var e=a.systemPause(!0);WMSX.MACHINE=b,wmsx.Configurator.applyFinalConfig(),a.updateMachineType(),new wmsx.MultiDownloader(wmsx.Configurator.slotURLSpecs(),function(){a.getExtensionsSocket().propagateAllExtensions(),a.getExtensionsSocket().refreshSlotsFromConfig(function(){a.getSavestateSocket().externalStateChange(),a.showOSD((c.DESC||c.DESCX)+" machine activated",!0),e||a.systemPause(!1),d&&a.powerOn()})},function(a){wmsx.Util.message(a.errorMessage)}).start()}}},this.addMachineTypeStateListener=function(a,c){b.indexOf(a)<0&&(b.push(a),c||a.machineTypeStateUpdate())},this.fireMachineTypeStateUpdate=function(){for(var a=0;a<b.length;++a)b[a].machineTypeStateUpdate()};var b=[]},wmsx.ExtensionsSocket=function(a){"use strict";function b(a,b,d,f){g[a]&&(d=d&&!!g[a].SLOT2,e.isActiveOnConf(a,d)!==b&&(WMSX.EXTENSIONS[a]^=d?2:1,f||c(a,b,d)))}function c(a,c,d){var f=g[a];if(f.MUTUAL&&b(f.MUTUAL,!c,d,!0),c){if(f.BOUND)for(h in f.BOUND)b(f.BOUND[h],!0,d,!0);if(f.TOGGLE&&(h=f.TOGGLE,e.isActiveOnConf(h,d)&&(b(h,!1,d,!0),e.isActiveOnConf(a,!d)||b(h,!0,!d,!0))),f.CHANGE)for(var h in f.CHANGE)b(h,!!f.CHANGE[h],d,!0)}else if(f.BOUND)for(h in f.BOUND)b(f.BOUND[h],!1,d,!0)}function d(a,b){return{url:g[a].URL||"@[Empty].rom",onSuccess:function(c){f.loadFromContentAsSlot(c.url,c.content,b?g[a].SLOT2:g[a].SLOT,!0,null,null,!0)}}}var e=this;this.connectFileLoader=function(a){f=a},this.addExtensionsAndCartridgesStateListener=function(b){a.getCartridgeSocket().addCartridgesStateListener(this,!0),i.indexOf(b)<0&&(i.push(b),b.extensionsAndCartridgesStateUpdate())},this.cartridgesStateUpdate=function(){this.refreshConfigFromSlots(),this.fireExtensionsAndCartridgesStateUpdate()},this.configurationStateUpdate=function(){g=WMSX.EXTENSIONS_CONFIG},this.isActiveOnConf=function(a,b){if(!g[a])return!1;var c=g[a].SLOT2&&b?2:1;return 0!=(WMSX.EXTENSIONS[a]&c)},this.isActiveOnSlot=function(a,b){var c=g[a];if(!c)return!1;var d=!!c.SLOT2,e=h.slotInserted(b&&d?c.SLOT2:c.SLOT);return!!e&&e.rom.source===c.URL},this.activateExtension=function(a,b,c,d,e){this.isActiveOnSlot(a,c)||this.toggleExtension(a,b,c,d,e)},this.toggleExtension=function(c,d,e,f,h){var i=g[c];if(i){var j=!!i.SLOT2,k=j&&!i.TOGGLE;e=e&&j;var l=0;switch(WMSX.EXTENSIONS[c]||0){case 0:l=e?2:1;break;case 1:l=e?k?3:2:0;break;case 2:l=e?0:k?3:1;break;case 3:l=e?1:2}j?0==(1&l)?(b(c,!1,!1),b(c,0!=(2&l),!0)):(b(c,0!=(2&l),!0),b(c,!0,!1)):b(c,0!=(1&l),!1);var m=a.powerIsOn;!d&&m&&a.powerOff();var n=a.systemPause(!0);this.refreshSlotsFromConfig(function(b){if(h||a.getSavestateSocket().externalStateChange(),n||a.systemPause(!1),!d&&m&&a.userPowerOn(!1),b&&!f){var c=a.getSlotSocket().getSlotDesc(2&l?i.SLOT2:i.SLOT),e=i.DESC+" Extension "+(l?"enabled"+(3===l?" at both slots":c?" at slot "+c:""):"disabled");a.showOSD(e,!0),wmsx.Util.log(e)}})}},this.getInitialLoaderURLSpecs=function(){this.propagateAllExtensions();var a=[];for(var b in g)1&WMSX.EXTENSIONS[b]&&a.push(d(b,!1)),g[b].SLOT2&&2&WMSX.EXTENSIONS[b]&&a.push(d(b,!0));return a},this.fireExtensionsAndCartridgesStateUpdate=function(){for(var a=0;a<i.length;++a)i[a].extensionsAndCartridgesStateUpdate()},this.refreshSlotsFromConfig=function(a){var b=[],c=[];for(var f in g){var i=g[f];1&WMSX.EXTENSIONS[f]?e.isActiveOnSlot(f,!1)||b.push(d(f,!1)):e.isActiveOnSlot(f,!1)&&c.push(i.SLOT),i.SLOT2&&(2&WMSX.EXTENSIONS[f]?e.isActiveOnSlot(f,!0)||b.push(d(f,!0)):e.isActiveOnSlot(f,!0)&&c.push(i.SLOT2))}if(0===b.length&&0===c.length)return e.fireExtensionsAndCartridgesStateUpdate(),a(!1);for(var j=0;j<c.length;++j)h.insertSlot(null,c[j],!0,!0);new wmsx.MultiDownloader(b,function(){e.fireExtensionsAndCartridgesStateUpdate(),a(!0)},function(a){wmsx.Util.message(a.errorMessage)}).start()},this.refreshConfigFromSlots=function(){for(var a in g){var b=e.isActiveOnSlot(a,!1)?1:0;b|=g[a].SLOT2&&e.isActiveOnSlot(a,!0)?2:0,WMSX.EXTENSIONS[a]=b}},this.propagateAllExtensions=function(){for(var a in g)c(a,0!=(1&WMSX.EXTENSIONS[a]),!1),g[a].SLOT2&&c(a,0!=(2&WMSX.EXTENSIONS[a]),!0)};var f,g=WMSX.EXTENSIONS_CONFIG,h=a.getSlotSocket(),i=[];!function(){wmsx.Configurator.addConfigurationStateListener(e)}()},wmsx.DeviceMissing={inputPort:function(a){return 255},outputPort:function(a,b){},inputPortIgnored:function(a){return 255},outputPortIgnored:function(a,b){},IGNORED_PORTS:new Set([128,129,130,131,132,133,134,135,144,145,147,164,165,184,185,186,187,192,193,194,195,200,201,202,203,204,205,206,207,220,221,232,233,234,235,236,237,238,239]),setDebugMode:function(a){}},wmsx.SwitchedDevices=function(){"use strict";this.connect=function(a){a.connectInputDevice(64,this.input40),a.connectOutputDevice(64,this.output40);for(var b=65;b<=79;++b)a.connectInputDevice(b,this.inputPort),a.connectOutputDevice(b,this.outputPort)},this.reset=function(){b=0},this.connectSwitchedDevice=function(b,c){c&&(a[b]=c)},this.disconnectSwitchedDevice=function(c,d){a[c]===d&&(a[c]=void 0,b===c&&(b=0))},this.input40=function(){return 255&~b},this.output40=function(c){b=a[c]?c:0},this.inputPort=function(c){return b?a[b].switchedPortInput(255&c):255},this.outputPort=function(c,d){b&&a[b].switchedPortOutput(c,255&d)};var a=new Array(256),b=0},wmsx.BUS=function(machine,cpu){"use strict";function init(){create()}function getSlotForAddress(a){var b=primarySlotConfig>>(a>>14<<1)&3;return 0===b?slot0:1===b?slot1:2===b?slot2:slot3}function create(){slot0=slot1=slot2=slot3=slotModules=slotEmpty,slots=[slot0,slot1,slot2,slot3,slotModules],devicesInputPorts=wmsx.Util.arrayFill(new Array(256),deviceInputMissing),devicesOutputPorts=wmsx.Util.arrayFill(new Array(256),deviceOutputMissing),switchedDevices=new wmsx.SwitchedDevices,switchedDevices.connect(self),self.slots=slots,self.devicesInputPorts=devicesInputPorts,self.devicesOutputPorts=devicesOutputPorts}var self=this;this.powerOn=function(){switchedDevices.reset(),this.setPrimarySlotConfig(0);for(var a=0;a<5;a++)slots[a].powerOn()},this.powerOff=function(){for(var a=0;a<5;a++)slots[a].powerOff()},this.reset=function(){vdpIOClock=0,switchedDevices.reset(),this.setDRAMMode(!1),this.setPrimarySlotConfig(0);for(var a=0;a<5;a++)slots[a].reset()},this.refreshConnect=function(){for(var a=0;a<5;++a)slots[a].refreshConnect()},this.insertSlot=function(a,b){if(a=a||slotEmpty,slots[b]!==a)switch(slots[b].disconnect(machine),slots[b]=a,slots[b].connect(machine),b){case 0:return void(slot0=a);case 1:return void(slot1=a);case 2:return void(slot2=a);case 3:return void(slot3=a);case 4:return void(slotModules=a)}},this.getSlot=function(a){return slots[a]},this.getSlotForAddress=getSlotForAddress,this.read=function(a){var b=primarySlotConfig>>(a>>14<<1)&3;return 3===b?slot3.read(a):1===b?slot1.read(a):0===b?slot0.read(a):slot2.read(a)},
this.write=function(a,b){var c=primarySlotConfig>>(a>>14<<1)&3;3===c?slot3.write(a,b):1===c?slot1.write(a,b):2===c?slot2.write(a,b):slot0.write(a,b)};var origWrite=this.write;this.writeWithBusMonitor=function(a,b){writeMonitor(a,b),origWrite(a,b)},this.setDRAMMode=function(a){dramMode=!!a,dramWait=0|!dramMode},this.setSlot3SecondaryConfig=function(a){slot3SecondaryConfig=a},this.getBreakWait=function(a,b){var c=a>>14<<1,d=primarySlotConfig>>c&3;return 3===d?(a^b)>>8?1:(d=slot3SecondaryConfig>>c&3,0===d?0:1===d?dramWait:1):0===d?(a^b)>>8?1:dramWait:1},this.getAccessWait=function(a){var b=a>>14<<1,c=primarySlotConfig>>b&3;return 3===c?(c=slot3SecondaryConfig>>b&3,0===c?0:1===c?dramWait:1):0===c?dramWait:2},this.input=function(a){return devicesInputPorts[255&a](a)},this.output=function(a,b){return devicesOutputPorts[255&a](b,a)},this.getIOWait=function(a,b){if(a>155||a<152)return 0;var c=vdpIOClock;vdpIOClock=cpu.getBUSCycles();var d=31-(vdpIOClock-c);return d>0?d*b:0},this.setPrimarySlotConfig=function(a){primarySlotConfig=a},this.getPrimarySlotConfig=function(){return primarySlotConfig},this.cpuExtensionBegin=function(a){if(a.extNum<240)return getSlotForAddress(a.extPC).cpuExtensionBegin(a);var b=cpuExtensionHandlers[a.extNum];return b?b.cpuExtensionBegin(a):void 0},this.cpuExtensionFinish=function(a){if(a.extNum<240)return getSlotForAddress(a.extPC).cpuExtensionFinish(a);var b=cpuExtensionHandlers[a.extNum];return b?b.cpuExtensionFinish(a):void 0},this.setCpuExtensionHandler=function(a,b){cpuExtensionHandlers[a]=b},this.connectInputDevice=function(a,b){devicesInputPorts[a]=b},this.connectOutputDevice=function(a,b){devicesOutputPorts[a]=b},this.disconnectInputDevice=function(a,b){b&&devicesInputPorts[a]!==b||(devicesInputPorts[a]=deviceInputMissing)},this.disconnectOutputDevice=function(a,b){b&&devicesOutputPorts[a]!==b||(devicesOutputPorts[a]=deviceOutputMissing)},this.setWriteMonitor=function(a){writeMonitor=a,this.write=writeMonitor?this.writeWithBusMonitor:origWrite},this.connectSwitchedDevice=function(a,b){switchedDevices.connectSwitchedDevice(a,b)},this.disconnectSwitchedDevice=function(a,b){switchedDevices.disconnectSwitchedDevice(a,b)};var slots,slot0,slot1,slot2,slot3,slotModules,primarySlotConfig=0,slot3SecondaryConfig=0,slotEmpty=wmsx.SlotEmpty.singleton,deviceInputMissing=wmsx.DeviceMissing.inputPort,deviceOutputMissing=wmsx.DeviceMissing.outputPort,devicesInputPorts,devicesOutputPorts,writeMonitor,switchedDevices,vdpIOClock=0,dramMode=!1,dramWait=0,cpuExtensionHandlers={};this.saveState=function(){return{p:primarySlotConfig,s0:slot0.saveState(),s1:slot1.saveState(),s2:slot2.saveState(),s3:slot3.saveState(),sM:slotModules.saveState(),d:dramMode,vc:vdpIOClock}},this.loadState=function(a){this.insertSlot(wmsx.SlotCreator.recreateFromSaveState(a.s0,slot0),0),this.insertSlot(wmsx.SlotCreator.recreateFromSaveState(a.s1,slot1),1),this.insertSlot(wmsx.SlotCreator.recreateFromSaveState(a.s2,slot2),2),this.insertSlot(wmsx.SlotCreator.recreateFromSaveState(a.s3,slot3),3),this.insertSlot(a.sM?wmsx.SlotCreator.recreateFromSaveState(a.sM,slotModules):slotEmpty,4),this.setDRAMMode(!!a.d),this.setPrimarySlotConfig(a.p),vdpIOClock=a.vc||0},init(),this.eval=function(str){return eval(str)}},wmsx.Machine=function(){"use strict";function init(){socketsCreate(),mainComponentsCreate(),computeBasicAutoRunCommandParameters()}function getSlot(a){"number"==typeof a&&(a=[a]);var b=a[0],c=a[1],d=bus.getSlot(b);return c>=0?d=d.isExpanded()?d.getSubSlot(c):null:d.isExpanded()&&(d=d.getSubSlot(0)),d}function getSlotDesc(a){var b="number"==typeof a?a:a[0];return b>3?void 0:b.toString()+(bus.getSlot(b).isExpanded()?"-"+(a[1]||0):"")}function insertSlot(a,b){"number"==typeof b&&(b=[b]);var c=!a||a===EMPTY_SLOT;if(!c||-1===e||(getSlot(b)||EMPTY_SLOT)!==EMPTY_SLOT){var d=b[0],e=b[1],f=bus.getSlot(d);if(e>=0){if(!f.isExpanded()){var g=f;f=0===d?new wmsx.SlotExpanded0:3===d?new wmsx.SlotExpanded3:4===d?new wmsx.SlotExpandedM:new wmsx.SlotExpanded,bus.insertSlot(f,d),g!==EMPTY_SLOT&&e>0&&f.insertSubSlot(g,0)}f.insertSubSlot(a,e),c&&f.isAllEmpty()&&bus.insertSlot(a,d)}else f.isExpanded()&&-1!==e?(f.insertSubSlot(a,0),c&&f.isAllEmpty()&&bus.insertSlot(a,d)):bus.insertSlot(a,d)}}function setVideoStandard(a,b,c){!1!==c&&self.showOSD((videoStandardIsAuto?"AUTO: ":"FORCED: ")+a.desc,!!c),(b||videoStandard!==a)&&(videoStandard=a,vdp.setVideoStandard(videoStandard),videoClockUpdateSpeed())}function setVideoStandardAuto(a){videoStandardIsAuto=!0;var b=wmsx.VideoStandard.NTSC;videoStandardSoft?b=videoStandardSoft:bios&&(bios.setVideoStandardUseOriginal(),b=bios.originalVideoStandard),setVideoStandard(b,!0,a)}function setVideoStandardForced(a){videoStandardIsAuto=!1,bios&&bios.setVideoStandardForced(a),setVideoStandard(a,!1,!0)}function setVSynchMode(a,b){(vSynchMode!==a||b)&&(vSynchMode=a<0?a:a%2,vdp.setVSynchMode(vSynchMode),videoClockUpdateSpeed())}function vSynchModeToggle(){if(vSynchMode<0||-1===videoClockSocket.getVSynchNativeFrequency())return self.showOSD("VSync is disabled / unsupported",!0,!0);setVSynchMode(vSynchMode+1),self.showOSD("VSync: "+(1===vSynchMode?"Auto ("+(videoClockSocket.isVSynchActive()?"ON":"OFF")+")":0===vSynchMode?"OFF":"DISABLED"),!0),WMSX.userPreferences.current.vSynch=vSynchMode,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save()}function saveState(a){var b={cfg:wmsx.Configurator.saveState(),mn:self.machineName,mt:self.machineType,b:bus.saveState(),rc:rtc.saveState(),sf:syf.saveState(),td:trd.saveState(),pp:ppi.saveState(),ps:psg.saveState(),vd:vdp.saveState(a),c:cpu.saveState(),va:videoStandardIsAuto,vs:videoStandard.name,ctm:z80ClockMode,rtm:r800ClockMode,vtm:vdpClockMode,s:speedControl,br:basicAutoRunDone,bc:basicAutoRunCommand||"",vss:videoStandardSoft&&videoStandardSoft.name,vm:videoSocket.saveState(),dd:diskDriveSocket.saveState(),ct:cassetteSocket.saveState(),cs:controllersSocket.saveState()};return a&&(b.vy=vSynchMode,b.pw=self.powerIsOn,b.up=userPaused,b.upf=userPauseMoreFrames),b}function loadState(a){wmsx.Configurator.loadState(a,a.cfg),void 0!==a.vy&&setVSynchMode(a.vy,!0),void 0!==a.pw&&self.powerIsOn!==a.pw&&(a.pw?self.powerOn(!0):self.powerOff()),void 0!==a.up&&self.userPause(a.up),void 0!==a.upf&&(userPauseMoreFrames=a.upf),self.machineName=a.mn,self.machineType=a.mt,videoStandardIsAuto=a.va,setVideoStandard(wmsx.VideoStandard[a.vs]),videoStandardSoft=a.vss&&wmsx.VideoStandard[a.vss],speedControl=a.s||1,1===speedControl&&(speedControl=defaultSpeed),basicAutoRunDone=!!a.br,void 0!==a.bc&&(basicAutoRunCommand=a.bc),videoClockUpdateSpeed(),cpu.loadState(a.c),vdp.loadState(a.vd),psg.loadState(a.ps),ppi.loadState(a.pp),rtc.loadState(a.rc),syf.loadState(a.sf),trd.loadState(a.td),bus.loadState(a.b),videoSocket.loadState(a.vm),diskDriveSocket.loadState(a.dd),cassetteSocket.loadState(a.ct),a.cs&&controllersSocket.loadState(a.cs),machineTypeSocket.fireMachineTypeStateUpdate(),cartridgeSocket.fireCartridgesStateUpdate(),machineControlsSocket.firePowerAndUserPauseStateUpdate(),audioSocket.flushAllSignals(),diskDriveSocket.fireInterfacesChangeUpdate(),z80ClockMode=void 0!==a.ctm?a.ctm:cpu.getZ80ClockMulti()>1?cpu.getZ80ClockMulti():0,r800ClockMode=void 0!==a.rtm?a.rtm:cpu.getR800ClockMulti()>1?cpu.getR800ClockMulti():0,vdpClockMode=void 0!==a.vtm?a.vtm:vdp.getVDPTurboMulti()>1?vdp.getVDPTurboMulti():0,biosSocket.turboDriverTurboModesUpdate(),saveStateSocket.externalStateChange()}function videoClockUpdateSpeed(){var a=vdp.getDesiredVideoPulldown();videoClockSocket.setVSynch(1===vSynchMode);var b=a.frequency*(alternateSpeed||speedControl)|0;videoClockSocket.setFrequency(b,a.divider),audioSocket.setFps(b/a.divider),rtc.setFps(a.frequency/a.divider)}function mainComponentsCreate(){self.cpu=cpu=new wmsx.CPU,self.rtc=rtc=new wmsx.RTC(videoClockSocket),self.syf=syf=new wmsx.SystemFlags,self.trd=trd=new wmsx.TurboRDevices(cpu,ledsSocket),
self.vdp=vdp=new wmsx.VDP(self,cpu,trd),self.psg=psg=new wmsx.PSG(controllersSocket,ledsSocket,!1),self.ppi=ppi=new wmsx.PPI(psg.getAudioChannel(),controllersSocket,ledsSocket),self.bus=bus=new wmsx.BUS(self,cpu),cpu.connectBus(bus),ppi.connectBus(bus),vdp.connectBus(bus),psg.setAudioSocket(audioSocket),psg.connectBus(bus),rtc.connectBus(bus),syf.connectBus(bus),trd.connectBus(bus)}function socketsCreate(){machineTypeSocket=new wmsx.MachineTypeSocket(self),videoClockSocket=new VideoClockSocket,videoSocket=new VideoSocket,slotSocket=new SlotSocket,biosSocket=new BIOSSocket,extensionsSocket=new wmsx.ExtensionsSocket(self),cartridgeSocket=new CartridgeSocket,expansionSocket=new ExpansionSocket,controllersSocket=new ControllersSocket,saveStateSocket=new SaveStateSocket,cassetteSocket=new CassetteSocket,audioSocket=new AudioSocket,diskDriveSocket=new DiskDriveSocket,machineControlsSocket=new MachineControlsSocket,ledsSocket=new LedsSocket}function computeBasicAutoRunCommandParameters(){basicAutoRunCommand=(WMSX.BASIC_ENTER?WMSX.BASIC_ENTER+"\r":"")+(WMSX.BASIC_TYPE||""),WMSX.BASIC_RUN?basicAutoRunCommand='\r\r\rRUN "'+WMSX.BASIC_RUN+'"\r'+basicAutoRunCommand:WMSX.BASIC_LOAD?basicAutoRunCommand='\r\r\rLOAD "'+WMSX.BASIC_LOAD+'"\r'+basicAutoRunCommand:WMSX.BASIC_BRUN?basicAutoRunCommand='\r\r\rBLOAD "'+WMSX.BASIC_BRUN+'",r\r'+basicAutoRunCommand:WMSX.BASIC_BLOAD&&(basicAutoRunCommand='\r\r\rBLOAD "'+WMSX.BASIC_BLOAD+'"\r'+basicAutoRunCommand)}function typeBasicAutoRunCommand(){diskDriveSocket.hasAnyMediaInserted()||cartridgeSocket.hasAnyMediaInserted()||cassetteSocket.typeAutoRunCommand(),basicAutoRunDone||(basicAutoRunCommand&&biosSocket.keyboardExtensionTypeString(basicAutoRunCommand),basicAutoRunDone=!0,basicAutoRunCommand=void 0)}function controlStateChanged(a,b,c,d){if(!isLoading){if(a===controls.FAST_SPEED&&!c)return void(b&&alternateSpeed!==SPEED_FAST?(alternateSpeed=SPEED_FAST,videoClockUpdateSpeed(),self.showOSD("FAST FORWARD",!0)):b||alternateSpeed!==SPEED_FAST||(alternateSpeed=null,videoClockUpdateSpeed(),self.showOSD(null,!0)));if(a===controls.FAST_SPEED&&c)return void(b&&alternateSpeed!==SPEED_SLOW?(alternateSpeed=SPEED_SLOW,videoClockUpdateSpeed(),self.showOSD("SLOW MOTION",!0)):b||alternateSpeed!==SPEED_SLOW||(alternateSpeed=null,videoClockUpdateSpeed(),self.showOSD(null,!0)));if(b)switch(a){case controls.POWER:c?self.powerIsOn&&self.reset():self.powerIsOn?self.powerOff():self.userPowerOn(!1);break;case controls.POWER_OFF:self.powerIsOn&&self.powerOff();break;case controls.PAUSE_CPU:var e=!trd.isCPUPaused();self.cpuPause(e,c);break;case controls.PAUSE:self.userPause(!userPaused,c),self.showOSD(userPaused?"EMULATION PAUSED"+(c?" with AUDIO ON":""):"EMULATION RESUMED",!0);break;case controls.FRAME:userPaused&&(userPauseMoreFrames=1);break;case controls.INC_SPEED:case controls.DEC_SPEED:case controls.NORMAL_SPEED:case controls.MIN_SPEED:var f=SPEEDS.indexOf(speedControl);return a===controls.INC_SPEED&&f<SPEEDS.length-1?++f:a===controls.DEC_SPEED&&f>0?--f:a===controls.MIN_SPEED?f=0:a===controls.NORMAL_SPEED&&(f=SPEEDS.indexOf(1)),speedControl=SPEEDS[f],self.showOSD("Speed: "+(100*speedControl|0)+"%",!0),void videoClockUpdateSpeed();case controls.SAVE_STATE_0:case controls.SAVE_STATE_1:case controls.SAVE_STATE_2:case controls.SAVE_STATE_3:case controls.SAVE_STATE_4:case controls.SAVE_STATE_5:case controls.SAVE_STATE_6:case controls.SAVE_STATE_7:case controls.SAVE_STATE_8:case controls.SAVE_STATE_9:case controls.SAVE_STATE_10:case controls.SAVE_STATE_11:case controls.SAVE_STATE_12:saveStateSocket.saveState(255&a);break;case controls.SAVE_STATE_FILE:saveStateSocket.saveStateFile();break;case controls.LOAD_STATE_0:case controls.LOAD_STATE_1:case controls.LOAD_STATE_2:case controls.LOAD_STATE_3:case controls.LOAD_STATE_4:case controls.LOAD_STATE_5:case controls.LOAD_STATE_6:case controls.LOAD_STATE_7:case controls.LOAD_STATE_8:case controls.LOAD_STATE_9:case controls.LOAD_STATE_10:case controls.LOAD_STATE_11:case controls.LOAD_STATE_12:saveStateSocket.loadState(255&a);break;case controls.TYPE_STRING:biosSocket.keyboardExtensionTypeString(d);break;case controls.VIDEO_STANDARD:videoStandardIsAuto?setVideoStandardForced(c?wmsx.VideoStandard.PAL:wmsx.VideoStandard.NTSC):videoStandard==wmsx.VideoStandard.NTSC?c?setVideoStandardAuto(!0):setVideoStandardForced(wmsx.VideoStandard.PAL):c?setVideoStandardForced(wmsx.VideoStandard.NTSC):setVideoStandardAuto(!0);break;case controls.VSYNCH:vSynchModeToggle();break;case controls.CPU_CLOCK_MODE:trd.isR800LedOn()?self.toggleR800ClockMode(c):self.toggleZ80ClockMode(c);break;case controls.Z80_CLOCK_MODE:self.toggleZ80ClockMode(c);break;case controls.R800_CLOCK_MODE:self.toggleR800ClockMode(c);break;case controls.VDP_CLOCK_MODE:self.toggleVDPClockMode(c);break;case controls.DEBUG:var g=vdp.toggleDebugModes(c);wmsx.DeviceMissing.setDebugMode(g);break;case controls.SPRITE_MODE:vdp.toggleSpriteDebugModes(c);break;case controls.DEFAULTS:self.setDefaults(),self.showOSD("Default Settings",!0)}}}function VideoClockSocket(){this.connectClock=function(b){a=b,rtc.syncTimeWithSource()},this.getVSynchNativeFrequency=function(){return a.getVSynchNativeFrequency()},this.setVSynch=function(b){a.setVSynch(b)},this.setFrequency=function(b,c){a.setFrequency(b,c)},this.isVSynchActive=function(){return a.isVSynchActive()},this.getRealTime=function(){return a.getRealTime()};var a}function BIOSSocket(){this.insertBIOS=function(a,b){slotSocket.insertSlot(a,WMSX.BIOS_SLOT,b)},this.insertBIOSEXT=function(a,b){slotSocket.insertSlot(a,WMSX.BIOSEXT_SLOT,b)},this.keyboardExtensionTypeString=function(a){bios&&bios.getKeyboardExtension().typeString(a)},this.keyboardExtensionCancelTypeString=function(){bios&&bios.getKeyboardExtension().cancelTypeString()},this.turboDriverTurboModesUpdate=function(){bios&&bios.getTurboDriver().turboModesUpdate()}}function ExpansionSocket(){this.insertExpansion=function(a,b,c){var d=b?WMSX.EXPANSION2_SLOT:WMSX.EXPANSION1_SLOT;a!==slotSocket.slotInserted(d)&&(slotSocket.insertSlot(a,d,c),cartridgeSocket.fireCartridgesStateUpdate(),self.showOSD("Expansion "+(1===b?"2":"1")+" (slot "+getSlotDesc(d)+"): "+(a?a.rom.source:"EMPTY"),!0))},this.expansionInserted=function(a){return slotSocket.slotInserted(a?WMSX.EXPANSION2_SLOT:WMSX.EXPANSION1_SLOT)}}function CartridgeSocket(){this.insertCartridge=function(a,b,c,d){var e=1===b?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT;slotSocket.insertSlot(a,e,c,!0),this.fireCartridgesStateUpdate(),d||self.showOSD("Cartridge "+(1===b?"2":"1")+": "+(a?a.rom.source:"EMPTY"),!0)},this.removeCartridge=function(a,b){var c=1===a?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT;return null===slotSocket.slotInserted(c)?(self.showOSD("No Cartridge in Slot "+(1===a?"2":"1"),!0,!0),!1):(slotSocket.insertSlot(null,c,b,!0),this.fireCartridgesStateUpdate(),self.showOSD("Cartridge "+(1===a?"2":"1")+" removed",!0),!0)},this.cartridgeInserted=function(a){return slotSocket.slotInserted(1===a?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT)},this.dataOperationNotSupportedMessage=function(a,b,c){var d=1===a?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT,e=slotSocket.slotInserted(d);return null===e?(c||self.showOSD("No Cartridge in Slot "+(1===a?"2":"1"),!0,!0),!0):!e.getDataDesc()&&(c||self.showOSD("Data "+(b?"Saving":"Loading")+" not supported for Cartridge "+(1===a?"2":"1"),!0,!0),!0)},this.loadCartridgeData=function(a,b,c){var d=1===a?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT,e=slotSocket.slotInserted(d);if(e&&e.loadData(wmsx.Util.leafFilename(b),c))return self.showOSD(e.getDataDesc()+" loaded in Cartridge "+(1===a?"2":"1"),!0),c},this.getCartridgeData=function(a){if(!this.dataOperationNotSupportedMessage(a,!0,!1)){return slotSocket.slotInserted(1===a?WMSX.CARTRIDGE2_SLOT:WMSX.CARTRIDGE1_SLOT).getDataToSave()}},this.fireCartridgesStateUpdate=function(){for(var a=0;a<b.length;a++)b[a].cartridgesStateUpdate()},
this.fireCartridgesModifiedStateUpdate=function(){a&&a.cartridgesModifiedStateUpdate(slotSocket.slotInserted(WMSX.CARTRIDGE1_SLOT),slotSocket.slotInserted(WMSX.CARTRIDGE2_SLOT))},this.addCartridgesStateListener=function(a,c){b.indexOf(a)<0&&(b.push(a),c||a.cartridgesStateUpdate())},this.setCartridgesModifiedStateListener=function(b){a=b,this.fireCartridgesModifiedStateUpdate()},this.hasAnyMediaInserted=function(){return slotSocket.slotInserted(WMSX.CARTRIDGE1_SLOT)||slotSocket.slotInserted(WMSX.CARTRIDGE2_SLOT)};var a,b=[]}function SlotSocket(){this.insertSlot=function(a,b,c,d){var e=self.powerIsOn;e&&!c&&self.powerOff(),insertSlot(a,b),c||!a&&!e?a&&self.powerIsOn&&a.powerOn():self.userPowerOn(!1),d||saveStateSocket.externalStateChange()},this.slotInserted=function(a){var b=getSlot(a);return b===EMPTY_SLOT?null:b},this.getSlotDesc=function(a){return getSlotDesc(a)}}function VideoSocket(){this.connectMonitor=function(b){a=b},this.connectInternalVideoSignal=function(b){a.connectInternalVideoSignal(b)},this.connectExternalVideoSignal=function(b){a.connectExternalVideoSignal(b)},this.disconnectExternalVideoSignal=function(b){a.disconnectExternalVideoSignal(b)},this.getMonitor=function(){return a},this.saveState=function(){return a.saveState()},this.loadState=function(b){a.loadState(b)};var a}function AudioSocket(){this.connectMonitor=function(b){a=b;for(var d=c.length-1;d>=0;d--)a.connectAudioSignal(c[d])},this.connectAudioSignal=function(d){c.indexOf(d)>=0||(wmsx.Util.arrayAdd(c,d),this.flushAllSignals(),d.setFps(b),a&&a.connectAudioSignal(d))},this.disconnectAudioSignal=function(b){wmsx.Util.arrayRemoveAllElement(c,b),a&&a.disconnectAudioSignal(b)},this.audioClockPulse32=function(){for(var a=c.length-1;a>=0;--a)c[a].audioClockPulse()},this.audioFinishFrame=function(){for(var a=c.length-1;a>=0;--a)c[a].audioFinishFrame()},this.muteAudio=function(){a&&a.mute()},this.unMuteAudio=function(){a&&a.unMute()},this.setFps=function(a){b=a;for(var d=c.length-1;d>=0;--d)c[d].setFps(b)},this.pauseAudio=function(){a&&a.pauseAudio()},this.unpauseAudio=function(){a&&a.unpauseAudio()},this.flushAllSignals=function(){for(var a=c.length-1;a>=0;--a)c[a].flush()},this.getBUSCycles=function(){return cpu.getBUSCycles()};var a,b,c=[]}function CassetteSocket(){this.connectDeck=function(b){a=b},this.connectDriver=function(a){b=a},this.getDeck=function(){return a},this.getDriver=function(){return b},this.autoPowerCycle=function(a){b&&b.currentAutoRunCommand()&&(self.powerIsOn||a||self.userPowerOn(!0))},this.typeAutoRunCommand=function(){b&&b.typeCurrentAutoRunCommand()},this.saveState=function(){return a.saveState()},this.loadState=function(b){a.loadState(b)};var a,b}function DiskDriveSocket(){this.connectDrive=function(a){b=a},this.getDrive=function(){return b},this.autoPowerCycle=function(a){self.powerIsOn||a||self.userPowerOn(!1)},this.diskInterfaceConnected=function(a){c.add(a),this.fireInterfacesChangeUpdate()},this.diskInterfaceDisconnected=function(a){c.delete(a),this.fireInterfacesChangeUpdate()},this.hardDiskInterfaceConnected=function(a){d.add(a),this.fireInterfacesChangeUpdate()},this.hardDiskInterfaceDisconnected=function(a){d.delete(a),this.fireInterfacesChangeUpdate()},this.dos2ROMConnected=function(a){e.add(a)},this.dos2ROMDisconnected=function(a){e.delete(a)},this.hasDiskInterface=function(){return c.size>0},this.hasHardDiskInterface=function(){return d.size>0},this.hasDOS2=function(){return e.size>0||d.size>0},this.setInterfacesChangeListener=function(b){a=b,this.fireInterfacesChangeUpdate()},this.fireInterfacesChangeUpdate=function(){a&&a.diskInterfacesStateUpdate(this.hasDiskInterface(),this.hasHardDiskInterface())},this.hasAnyMediaInserted=function(){return this.getDrive().hasAnyMediaInserted()},this.saveState=function(){return b.saveState()},this.loadState=function(a){b.loadState(a)};var a,b,c=new Set,d=new Set,e=new Set}function ControllersSocket(){this.connectControls=function(b){a=b},this.readKeyboardPort=function(b){return a.readKeyboardPort(b)},this.readControllerPort=function(b){return a.readControllerPort(b)},this.writeControllerPin8Port=function(b,c){a.writeControllerPin8Port(b,c)},this.releaseControllers=function(){a.releaseControllers()},this.resetControllers=function(){a.resetControllers()},this.getBUSCycles=function(){return cpu.getBUSCycles()},this.saveState=function(){return a.saveState()},this.loadState=function(b){a.loadState(b)};var a}function MachineControlsSocket(){this.controlStateChanged=function(a,b,c,d){controlStateChanged(a,b,c,d)},this.addPowerAndUserPauseStateListener=function(b){a.indexOf(b)>=0||(a.push(b),this.firePowerAndUserPauseStateUpdate())},this.firePowerAndUserPauseStateUpdate=function(){for(var b=0;b<a.length;++b)a[b].machinePowerAndUserPauseStateUpdate(self.powerIsOn,userPaused)},this.getControlReport=function(a){switch(a){case controls.VIDEO_STANDARD:return{label:videoStandardIsAuto?"Auto":videoStandard.name,active:!videoStandardIsAuto};case controls.Z80_CLOCK_MODE:var b=cpu.getZ80ClockMulti(),c=0===z80ClockMode?"Auto"+(1!==b?" "+b+"x":""):1===z80ClockMode?"Normal":b+"x";return{label:c,active:1!==b};case controls.R800_CLOCK_MODE:return b=cpu.getR800ClockMulti(),c=0===r800ClockMode?"Auto"+(1!==b?" "+b+"x":""):1===r800ClockMode?"Normal":b+"x",{label:c,active:1!==b};case controls.VDP_CLOCK_MODE:return b=vdp.getVDPTurboMulti(),{label:self.getVDPClockModeDesc(),active:1!==b};case controls.SPRITE_MODE:return c=vdp.getSpriteDebugModeQuickDesc(),{label:c,active:"Normal"!==c};case controls.VSYNCH:return{label:vSynchMode<0?"DISABL":vSynchMode?"Auto":"OFF",active:0===vSynchMode}}return{label:"Unknown",active:!1}};var a=[]}function LedsSocket(){this.ledStateChanged=function(a,c){b[a]!==c&&(b[a]=c,this.fireLedsStateUpdate())},this.ledInfoChanged=function(a,b){c[a]!==b&&(c[a]=b,this.fireLedsStateUpdate())},this.setLedsStateListener=function(b){a=b,this.fireLedsStateUpdate()},this.fireLedsStateUpdate=function(){a&&a.ledsStateUpdate(b,c)};var a,b=[0,0,0,0,0],c=["","","","",""]}function SaveStateSocket(){this.connectMedia=function(b){a=b},this.saveState=function(c){if(self.powerIsOn&&a){var d=self.systemPause(!0);self.showOSD("Saving State "+c,!0);var e=saveState();e.v=b,a.persistState(c,e,function(a){a?self.showOSD("State "+c+" saved",!0):self.showOSD("State "+c+" save FAILED!",!0,!0),d||self.systemPause(!1)})}},this.loadState=function(b){if(a){var d=self.systemPause(!0);self.showOSD("Loading State "+b,!0),a.retrieveState(b,function(a){a?c[a.v]?(self.powerIsOn?self.reset(!0):self.powerOn(!0),loadState(a),WMSX.userPreferences.current.syncTimeLoadState&&rtc.syncTimeWithSource(),self.showOSD("State "+b+" loaded",!0)):self.showOSD("State "+b+" load failed. State version incompatible!",!0,!0):self.showOSD("State "+b+" not found!",!0,!0),d||self.systemPause(!1)})}},this.saveStateFile=function(){if(self.powerIsOn&&a){var c=self.systemPause(!0);self.showOSD("Saving State File",!0);var d=saveState();d.v=b,a.saveStateFile(d),c||self.systemPause(!1)}},this.loadStateFile=function(b){if(!a)return!1;self.showOSD("Loading State File",!0);var d=a.loadStateFile(b);return d?(wmsx.Util.log("State file loaded"),c[d.v]?(self.powerIsOn?self.reset(!0):self.powerOn(!0),loadState(d),self.showOSD("State File loaded",!0)):self.showOSD("State File load failed. State version incompatible!",!0,!0),!0):(self.showOSD(null,!0),!1)},this.externalStateChange=function(){a.externalStateChange()};var a,b=WMSX.STATE_VERSION,c=WMSX.STATE_VERSIONS_ACCEPTED}var self=this;this.socketsConnected=function(){videoSocket.connectInternalVideoSignal(vdp.getVideoSignal()),self.updateMachineType(),self.setZ80ClockMode(z80ClockMode),self.setR800ClockMode(r800ClockMode),self.setVDPClockMode(vdpClockMode),self.setDefaults()},this.updateMachineType=function(){this.machineName=WMSX.MACHINE,this.machineType=WMSX.MACHINES_CONFIG[this.machineName].TYPE||3,cpu.setMachineType(this.machineType),
vdp.setMachineType(this.machineType),rtc.setMachineType(this.machineType),syf.setMachineType(this.machineType),trd.setMachineType(this.machineType),biosSocket.turboDriverTurboModesUpdate(),bus.refreshConnect(),machineTypeSocket.fireMachineTypeStateUpdate()},this.preStart=function(){extensionsSocket.refreshConfigFromSlots()},this.powerOn=function(a){this.powerIsOn&&this.powerOff(),bus.powerOn(),trd.powerOn(),syf.powerOn(),rtc.powerOn(),ppi.powerOn(),psg.powerOn(),vdp.powerOn(),cpu.powerOn(),this.reset(a),this.powerIsOn=!0,a||machineControlsSocket.firePowerAndUserPauseStateUpdate()},this.powerOff=function(){cpu.powerOff(),vdp.powerOff(),psg.powerOff(),ppi.powerOff(),rtc.powerOff(),syf.powerOff(),trd.powerOff(),bus.powerOff(),controllersSocket.resetControllers(),this.powerIsOn=!1,userPaused?this.userPause(!1):machineControlsSocket.firePowerAndUserPauseStateUpdate(),this.cpuPause(!1,!1,!0)},this.reset=function(a){videoStandardSoft=null,videoStandardIsAuto&&setVideoStandardAuto(),controllersSocket.resetControllers(),trd.reset(),syf.reset(),rtc.reset(),ppi.reset(),psg.reset(),vdp.reset(),cpu.reset(),bus.reset(),audioSocket.flushAllSignals(),fastBootFrames>0&&(a?fastBootCountdown>0&&(alternateSpeed=null,videoClockUpdateSpeed()):(fastBootCountdown=fastBootFrames,alternateSpeed=SPEED_FAST,videoClockUpdateSpeed()))},this.userPowerOn=function(a){if(!isLoading){if(!bios)return void this.showOSD("Insert BIOS!",!0,!0);this.powerOn(),a&&typeBasicAutoRunCommand()}},this.videoClockPulse=function(){fastBootCountdown>0&&--fastBootCountdown<=0&&(alternateSpeed=null,videoClockUpdateSpeed()),rtc.videoClockPulse(),bios&&bios.getKeyboardExtension().keyboardExtensionClockPulse(),self.powerIsOn&&(userPaused&&userPauseMoreFrames--<=0||(vdp.videoClockPulse(),audioSocket.audioFinishFrame()))},this.getMachineTypeSocket=function(){return machineTypeSocket},this.getVideoClockSocket=function(){return videoClockSocket},this.getSlotSocket=function(){return slotSocket},this.getBIOSSocket=function(){return biosSocket},this.getExtensionsSocket=function(){return extensionsSocket},this.getExpansionSocket=function(){return expansionSocket},this.getCartridgeSocket=function(){return cartridgeSocket},this.getMachineControlsSocket=function(){return machineControlsSocket},this.getControllersSocket=function(){return controllersSocket},this.getVideoSocket=function(){return videoSocket},this.getAudioSocket=function(){return audioSocket},this.getSavestateSocket=function(){return saveStateSocket},this.getCassetteSocket=function(){return cassetteSocket},this.getDiskDriveSocket=function(){return diskDriveSocket},this.getLedsSocket=function(){return ledsSocket},this.showOSD=function(a,b,c){videoSocket.getMonitor().showOSD(a,b,c)},this.setVideoStandardSoft=function(a){videoStandardSoft=a,videoStandardIsAuto&&videoStandard!==a?setVideoStandard(a,!1,!0):videoStandardIsAuto||videoStandard===a||self.showOSD("Cannot soft-change Video Standard. It's FORCED: "+videoStandard.desc,!0,!0)},this.setBIOS=function(a){bios=a===EMPTY_SLOT?null:a,videoStandardSoft=null,setVideoStandardAuto()},this.setLoading=function(a){isLoading=a},this.userPause=function(a,b){var c=userPaused;return userPaused!==a&&(userPaused=!!a,userPauseMoreFrames=-1,userPaused?b||audioSocket.muteAudio():audioSocket.unMuteAudio(),machineControlsSocket.firePowerAndUserPauseStateUpdate()),c},this.systemPause=function(a){var b=systemPaused;return systemPaused!==a&&(systemPaused=!!a,systemPaused?audioSocket.pauseAudio():trd.isCPUPaused()||audioSocket.unpauseAudio()),b},this.isSystemPaused=function(){return systemPaused},this.cpuPause=function(a,b,c){a!==trd.isCPUPaused()&&(trd.setCPUPause(a,c),a?b||audioSocket.pauseAudio():systemPaused||audioSocket.unpauseAudio())},this.vSynchSetSupported=function(a){var b=WMSX.userPreferences.current.vSynch;setVSynchMode(-1!==WMSX.SCREEN_VSYNC_MODE&&a?WMSX.SCREEN_VSYNC_MODE>=0?WMSX.SCREEN_VSYNC_MODE:null!==b&&b>=0?b:1:-1,!0)},this.toggleZ80ClockMode=function(a){a?this.setZ80ClockMode(z80ClockMode<=0?8:z80ClockMode<=1?0:z80ClockMode<=1.5?1:z80ClockMode<=2?1.5:(0|z80ClockMode)-1):this.setZ80ClockMode(z80ClockMode>=8?0:z80ClockMode<1?1:z80ClockMode<1.5?1.5:z80ClockMode<2?2:1+(0|z80ClockMode)),this.showZ80ClockModeMessage()},this.setZ80ClockMode=function(a){z80ClockMode=a<0||a>8?0:a,biosSocket.turboDriverTurboModesUpdate()},this.getZ80ClockMode=function(){return z80ClockMode},this.showZ80ClockModeMessage=function(){self.showOSD("Z80 Clock: "+this.getZ80ClockModeDesc(),!0)},this.getZ80ClockModeDesc=function(){var a=0===z80ClockMode?"Auto ":1===z80ClockMode?"Normal ":"",b=cpu.getZ80ClockMulti();return a+=(0!==z80ClockMode&&1!==z80ClockMode?b+"x ":"")+"("+cpu.getClockFreqDesc(b)+")"},this.toggleR800ClockMode=function(a){a?this.setR800ClockMode(r800ClockMode<=0?2:r800ClockMode<=.5?0:Math.max(((4*r800ClockMode|0)-1)/4,.5)):this.setR800ClockMode(r800ClockMode>=2?0:Math.max((1+(4*r800ClockMode|0))/4,.5)),this.showR800ClockModeMessage()},this.setR800ClockMode=function(a){r800ClockMode=a<0||a>2?0:a,biosSocket.turboDriverTurboModesUpdate()},this.getR800ClockMode=function(){return r800ClockMode},this.showR800ClockModeMessage=function(){self.showOSD("R800 Clock: "+this.getR800ClockModeDesc(),!0)},this.getR800ClockModeDesc=function(){var a=0===r800ClockMode?"Auto ":1===r800ClockMode?"Normal ":"",b=cpu.getR800ClockMulti();return a+=(0!==r800ClockMode&&1!==r800ClockMode?b+"x ":"")+"("+cpu.getClockFreqDesc(2*b)+")"},this.toggleVDPClockMode=function(a){a?this.setVDPClockMode(vdpClockMode<=0?9:vdpClockMode<=1?0:(0|vdpClockMode)-1):this.setVDPClockMode(1+(0|vdpClockMode)),self.showOSD("VDP Engine Clock: "+this.getVDPClockModeDesc(),!0)},this.setVDPClockMode=function(a){vdpClockMode=a<0||a>9?0:a,biosSocket.turboDriverTurboModesUpdate()},this.getVDPClockMode=function(){return vdpClockMode},this.getVDPClockModeDesc=function(){var a=0===vdpClockMode?"Auto ":1===vdpClockMode?"Normal ":9===vdpClockMode?"Instant":"",b=vdp.getVDPTurboMulti();return a+=b>0&&1!==b&&b<9?b+"x ":""},this.setDefaults=function(){setVideoStandardAuto(!1),vdp.setDefaults(),speedControl=defaultSpeed,alternateSpeed=null,videoClockUpdateSpeed()},this.saveState=saveState,this.loadState=loadState,this.machineName=null,this.machineType=0,this.powerIsOn=!1;var speedControl=1,alternateSpeed=!1,defaultSpeed=WMSX.SPEED>0?WMSX.SPEED/100:1,isLoading=!1,basicAutoRunDone=!1,basicAutoRunCommand,cpu,bus,ppi,vdp,psg,rtc,syf,trd,userPaused=!1,userPauseMoreFrames=0,systemPaused=!1,cpuPaused=!1,machineTypeSocket,videoClockSocket,videoSocket,slotSocket,biosSocket,extensionsSocket,expansionSocket,cartridgeSocket,saveStateSocket,cassetteSocket,diskDriveSocket,machineControlsSocket,controllersSocket,audioSocket,ledsSocket,bios,videoStandard,videoStandardSoft,videoStandardIsAuto=!1,vSynchMode,fastBootFrames=WMSX.FAST_BOOT<=0?0:WMSX.FAST_BOOT>1?WMSX.FAST_BOOT:WMSX.BOOT_KEYS_FRAMES>0?WMSX.BOOT_KEYS_FRAMES:WMSX.BOOT_DURATION_AUTO,fastBootCountdown=0,z80ClockMode=WMSX.Z80_CLOCK_MODE<0?0:WMSX.Z80_CLOCK_MODE,r800ClockMode=WMSX.R800_CLOCK_MODE<0?0:WMSX.R800_CLOCK_MODE,vdpClockMode=WMSX.VDP_CLOCK_MODE<0?0:WMSX.VDP_CLOCK_MODE,EMPTY_SLOT=wmsx.SlotEmpty.singleton,SPEEDS=[.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.25,1.5,2,3,5,10],SPEED_FAST=10,SPEED_SLOW=.3,controls=wmsx.MachineControls;this.eval=function(str){return eval(str)},init()},wmsx.Machine.BASE_CPU_CLOCK=3584160,wmsx.Machine.MACHINE_TYPE={MSX1:1,MSX2:2,MSX2P:3,MSXTR:4},wmsx.KeyboardKeys={D0:{m:[0,0],key:"D0",c_en:"0",cs_en:")",cs_ja:" "},D1:{m:[0,1],key:"D1",c_en:"1",cs_en:"!"},D2:{m:[0,2],key:"D2",c_en:"2",cs_en:"@",cs_ja:'"'},D3:{m:[0,3],key:"D3",c_en:"3",cs_en:"#"},D4:{m:[0,4],key:"D4",c_en:"4",cs_en:"$"},D5:{m:[0,5],key:"D5",c_en:"5",cs_en:"%"},D6:{m:[0,6],key:"D6",c_en:"6",cs_en:"^",cs_ja:"&"},D7:{m:[0,7],key:"D7",c_en:"7",cs_en:"&",cs_ja:"'"},D8:{m:[1,0],key:"D8",c_en:"8",cs_en:"*",cs_ja:"("},D9:{m:[1,1],key:"D9",c_en:"9",cs_en:"(",cs_ja:")"},
MINUS:{m:[1,2],key:"MINUS",c_en:"-",cs_en:"_",cs_ja:"="},EQUAL:{m:[1,3],key:"EQUAL",c_en:"=",cs_en:"+",c_ja:"^",cs_ja:"~"},BACKSLASH:{m:[1,4],key:"BACKSLASH",c_en:"\\",cs_en:"|",c_ja:"&yen;",cs_ja:"|"},OPEN_BRACKET:{m:[1,5],key:"OPEN_BRACKET",c_en:"[",cs_en:"{",c_ja:"@",cs_ja:"`"},CLOSE_BRACKET:{m:[1,6],key:"CLOSE_BRACKET",c_en:"]",cs_en:"}",c_ja:"[",cs_ja:"{"},SEMICOLON:{m:[1,7],key:"SEMICOLON",c_en:";",cs_en:":",cs_ja:"+"},QUOTE:{m:[2,0],key:"QUOTE",c_en:"'",cs_en:'"',c_ja:":",cs_ja:"*"},BACKQUOTE:{m:[2,1],key:"BACKQUOTE",c_en:"`",cs_en:"~",c_ja:"]",cs_ja:"}"},COMMA:{m:[2,2],key:"COMMA",c_en:",",cs_en:"<"},PERIOD:{m:[2,3],key:"PERIOD",c_en:".",cs_en:">"},SLASH:{m:[2,4],key:"SLASH",c_en:"/",cs_en:"?"},DEAD:{m:[2,5],key:"DEAD",c_en:"à",cs_en:"á",c_ja:" ",cs_ja:"_",cns_en:"à",cns_ja:"_"},A:{m:[2,6],key:"A",c_en:"A"},B:{m:[2,7],key:"B",c_en:"B"},C:{m:[3,0],key:"C",c_en:"C"},D:{m:[3,1],key:"D",c_en:"D"},E:{m:[3,2],key:"E",c_en:"E"},F:{m:[3,3],key:"F",c_en:"F"},G:{m:[3,4],key:"G",c_en:"G"},H:{m:[3,5],key:"H",c_en:"H"},I:{m:[3,6],key:"I",c_en:"I"},J:{m:[3,7],key:"J",c_en:"J"},K:{m:[4,0],key:"K",c_en:"K"},L:{m:[4,1],key:"L",c_en:"L"},M:{m:[4,2],key:"M",c_en:"M"},N:{m:[4,3],key:"N",c_en:"N"},O:{m:[4,4],key:"O",c_en:"O"},P:{m:[4,5],key:"P",c_en:"P"},Q:{m:[4,6],key:"Q",c_en:"Q"},R:{m:[4,7],key:"R",c_en:"R"},S:{m:[5,0],key:"S",c_en:"S"},T:{m:[5,1],key:"T",c_en:"T"},U:{m:[5,2],key:"U",c_en:"U"},V:{m:[5,3],key:"V",c_en:"V"},W:{m:[5,4],key:"W",c_en:"W"},X:{m:[5,5],key:"X",c_en:"X"},Y:{m:[5,6],key:"Y",c_en:"Y"},Z:{m:[5,7],key:"Z",c_en:"Z"},SHIFT:{m:[6,0],key:"SHIFT",c_en:"SHF"},CONTROL:{m:[6,1],key:"CONTROL",c_en:"CTR"},CAPSLOCK:{m:[6,3],key:"CAPSLOCK",c_en:"CAP"},GRAPH:{m:[6,2],key:"GRAPH",c_en:"GRA"},CODE:{m:[6,4],key:"CODE",c_en:"COD",c_ja:"KANA",cs_ja:"KANA"},F1:{m:[6,5],key:"F1",c_en:"F1",cs_en:"F6"},F2:{m:[6,6],key:"F2",c_en:"F2",cs_en:"F7"},F3:{m:[6,7],key:"F3",c_en:"F3",cs_en:"F8"},F4:{m:[7,0],key:"F4",c_en:"F4",cs_en:"F9"},F5:{m:[7,1],key:"F5",c_en:"F5",cs_en:"F10"},ESCAPE:{m:[7,2],key:"ESCAPE",c_en:"ESC"},TAB:{m:[7,3],key:"TAB",c_en:"TAB"},STOP:{m:[7,4],key:"STOP",c_en:"STP"},BACKSPACE:{m:[7,5],key:"BACKSPACE",c_en:"BS"},SELECT:{m:[7,6],key:"SELECT",c_en:"SEL"},ENTER:{m:[7,7],key:"ENTER",c_en:"RET"},SPACE:{m:[8,0],key:"SPACE",c_en:"SPC"},HOME:{m:[8,1],key:"HOME",c_en:"HOM"},INSERT:{m:[8,2],key:"INSERT",c_en:"INS"},DELETE:{m:[8,3],key:"DELETE",c_en:"DEL"},LEFT:{m:[8,4],key:"LEFT",c_en:"LFT"},UP:{m:[8,5],key:"UP",c_en:"UP"},DOWN:{m:[8,6],key:"DOWN",c_en:"DWN"},RIGHT:{m:[8,7],key:"RIGHT",c_en:"RGH"},NUM_MULTIPLY:{m:[9,0],key:"NUM_MULTIPLY",c_en:"*"},NUM_PLUS:{m:[9,1],key:"NUM_PLUS",c_en:"+"},NUM_DIVIDE:{m:[9,2],key:"NUM_DIVIDE",c_en:"/"},NUM_0:{m:[9,3],key:"NUM_0",c_en:"0"},NUM_1:{m:[9,4],key:"NUM_1",c_en:"1"},NUM_2:{m:[9,5],key:"NUM_2",c_en:"2"},NUM_3:{m:[9,6],key:"NUM_3",c_en:"3"},NUM_4:{m:[9,7],key:"NUM_4",c_en:"4"},NUM_5:{m:[10,0],key:"NUM_5",c_en:"5"},NUM_6:{m:[10,1],key:"NUM_6",c_en:"6"},NUM_7:{m:[10,2],key:"NUM_7",c_en:"7"},NUM_8:{m:[10,3],key:"NUM_8",c_en:"8"},NUM_9:{m:[10,4],key:"NUM_9",c_en:"9"},NUM_MINUS:{m:[10,5],key:"NUM_MINUS",c_en:"-"},NUM_COMMA:{m:[10,6],key:"NUM_COMMA",c_en:","},NUM_PERIOD:{m:[10,7],key:"NUM_PERIOD",c_en:"."},YES:{m:[11,1],key:"YES",c_en:"YES",c_ja:"HAI",cs_ja:"HAI"},NO:{m:[11,3],key:"NO",c_en:"NO",c_ja:"IIE",cs_ja:"IIE"}},wmsx.JoystickButtons={J_UP:{button:"J_UP",mask:1,n:"UP"},J_DOWN:{button:"J_DOWN",mask:2,n:"DOWN"},J_LEFT:{button:"J_LEFT",mask:4,n:"LEFT"},J_RIGHT:{button:"J_RIGHT",mask:8,n:"RIGHT"},J_A:{button:"J_A",mask:16,n:"A"},J_B:{button:"J_B",mask:32,n:"B"},J_AB:{button:"J_AB",mask:48,n:"AB"},J_X:{button:"J_X",n:"X"},J_Y:{button:"J_Y",n:"Y"},J_L:{button:"J_L",n:"L"},J_R:{button:"J_R",n:"R"},J_BACK:{button:"J_BACK",n:"BACK"},J_START:{button:"J_START",n:"START"}},wmsx.MachineControls={POWER:51,POWER_OFF:53,DEBUG:101,TRACE:102,PAUSE:103,PAUSE_CPU:104,FRAME:105,FAST_SPEED:111,INC_SPEED:113,DEC_SPEED:114,NORMAL_SPEED:115,MIN_SPEED:116,SPRITE_MODE:121,VIDEO_STANDARD:123,VSYNCH:124,CPU_CLOCK_MODE:125,Z80_CLOCK_MODE:126,R800_CLOCK_MODE:127,VDP_CLOCK_MODE:128,DEFAULTS:130,SAVE_STATE_0:256,SAVE_STATE_1:257,SAVE_STATE_2:258,SAVE_STATE_3:259,SAVE_STATE_4:260,SAVE_STATE_5:261,SAVE_STATE_6:262,SAVE_STATE_7:263,SAVE_STATE_8:264,SAVE_STATE_9:265,SAVE_STATE_10:266,SAVE_STATE_11:267,SAVE_STATE_12:268,LOAD_STATE_0:512,LOAD_STATE_1:513,LOAD_STATE_2:514,LOAD_STATE_3:515,LOAD_STATE_4:516,LOAD_STATE_5:517,LOAD_STATE_6:518,LOAD_STATE_7:519,LOAD_STATE_8:520,LOAD_STATE_9:521,LOAD_STATE_10:522,LOAD_STATE_11:523,LOAD_STATE_12:524,SAVE_STATE_FILE:201,TYPE_STRING:301},wmsx.Images={embedded:!1,count:5,urls:{logo:WMSX.IMAGES_PATH+"logo.png",sprites:WMSX.IMAGES_PATH+"sprites.png",loading:WMSX.IMAGES_PATH+"loading.gif",mouseCursor:WMSX.IMAGES_PATH+"mouse-cursor.png",logoMiniBrightBack:WMSX.IMAGES_PATH+"logo-mini-bright-back.png"}},WMSX.userPreferences={},WMSX.userPreferences.currentVersion=60,WMSX.userPreferences.compatibleVersions=new Set([60,50]),WMSX.userPreferences.defaults=function(){"use strict";var a=wmsx.KeyboardKeys,b=wmsx.JoystickButtons,c=wmsx.DOMKeys,d=wmsx.GamepadButtons;return{hostKeyboard:{en:void 0,ja:void 0},customHostKeyboards:{en:{},ja:{}},customHostKeys:{nextCode:1001,keys:[]},joysticks:[{buttons:{J_UP:[d.GB_UP],J_DOWN:[d.GB_DOWN],J_LEFT:[d.GB_LEFT],J_RIGHT:[d.GB_RIGHT],J_A:[d.GB_1,d.GB_3],J_B:[d.GB_2,d.GB_3],J_X:[],J_Y:[],J_L:[d.GB_L1,d.GB_L2],J_R:[d.GB_R1,d.GB_R2],J_BACK:[d.GB_BACK],J_START:[d.GB_START]},virtualButtonsKeys:{J_X:[],J_Y:[],J_L:[{wc:c.VK_F12.wc|c.SHIFT,n:["Shift","F12"]}],J_R:[c.VK_F12],J_BACK:[c.VK_ESCAPE],J_START:[{wc:c.VK_P.wc|c.ALT,n:["Alt","P"]}]},settings:{device:-1,xAxis:0,xAxisSig:1,yAxis:1,yAxisSig:1,deadzone:.3}},{buttons:{J_UP:[d.GB_UP],J_DOWN:[d.GB_DOWN],J_LEFT:[d.GB_LEFT],J_RIGHT:[d.GB_RIGHT],J_A:[d.GB_1,d.GB_3],J_B:[d.GB_2,d.GB_3],J_X:[],J_Y:[],J_L:[d.GB_L1,d.GB_L2],J_R:[d.GB_R1,d.GB_R2],J_BACK:[d.GB_BACK],J_START:[d.GB_START]},virtualButtonsKeys:{J_X:[],J_Y:[],J_L:[{wc:c.VK_F12.wc|c.SHIFT,n:["Shift","F12"]}],J_R:[c.VK_F12],J_BACK:[c.VK_ESCAPE],J_START:[{wc:c.VK_P.wc|c.ALT,n:["Alt","P"]}]},settings:{device:-1,xAxis:0,xAxisSig:1,yAxis:1,yAxisSig:1,deadzone:.3}}],joykeys:[{buttons:{J_UP:[c.VK_UP],J_DOWN:[c.VK_DOWN],J_LEFT:[c.VK_LEFT],J_RIGHT:[c.VK_RIGHT],J_A:[c.VK_SPACE,c.VK_LSHIFT,c.VK_INSERT],J_B:[c.VK_M,c.VK_LCONTROL,c.VK_DELETE]}},{buttons:{J_UP:[c.VK_T],J_DOWN:[c.VK_G],J_LEFT:[c.VK_F],J_RIGHT:[c.VK_H],J_A:[c.VK_A],J_B:[c.VK_Z]}}],touch:{directional:"JOYSTICK",directionalBig:!1,mirrored:!1,buttons:{T_A:b.J_A,T_B:b.J_B,T_C:b.J_AB,T_D:a.ESCAPE,T_E:a.SPACE,T_F:a.F1,T_G:a.ENTER,T_X:null,T_Y:null}},vSynch:1,crtFilter:-1,crtScanlines:0,hapticFeedback:!0,audioBufferBase:-1,netPlaySessionName:"",netPlayNick:"",syncTimeLoadState:!1}},WMSX.userPreferences.load=function(){var a;try{a=JSON.parse(localStorage["wmsxprefs"+this.getEnvSuffix()]||"{}"),a.version&&delete a.version}catch(a){}if(!a||!WMSX.userPreferences.compatibleVersions.has(a.prefsVersion)){a={}}var b=WMSX.userPreferences.defaults();for(var c in b)void 0===a[c]&&(a[c]=b[c]);a.prefsVersion=WMSX.userPreferences.currentVersion,WMSX.userPreferences.current=a,wmsx.DOMKeys.initPreferences()},WMSX.userPreferences.save=function(){if(WMSX.userPreferences.isDirty)try{WMSX.userPreferences.current.wmsxVersion=WMSX.VERSION,localStorage["wmsxprefs"+this.getEnvSuffix()]=JSON.stringify(WMSX.userPreferences.current),delete WMSX.userPreferences.isDirty,wmsx.Util.log("Preferences saved!")}catch(a){}},WMSX.userPreferences.getEnvSuffix=function(){return void 0===this.envSuffix&&(this.envSuffix=WMSX.ENVIRONMENT?"_"+WMSX.ENVIRONMENT:""),this.envSuffix},WMSX.userPreferences.setDirty=function(){WMSX.userPreferences.isDirty=!0},WMSX.userROMFormats={init:function(){wmsx.SlotCreator.setUserROMFormats(this),this.userFormats=JSON.parse(localStorage.wmsxuserformats||"{}")},getForROM:function(a){return this.userFormats[a.info.h]},setForROM:function(a,b,c){
a.info.h&&(c?delete this.userFormats[a.info.h]:this.userFormats[a.info.h]=b,localStorage.wmsxuserformats=JSON.stringify(this.userFormats))}},wmsx.Clock=function(clockPulse){"use strict";this.connect=function(a){a.connectClock(this)},this.go=function(){running||(useRequestAnimationFrame=vSynch&&cyclesPerSecond===this.getVSynchNativeFrequency(),running=!0,useRequestAnimationFrame?animationFrame=requestAnimationFrame(pulse):interval=setInterval(pulse,cycleTimeMs))},this.pause=function(){running=!1,animationFrame&&(cancelAnimationFrame(animationFrame),animationFrame=null),interval&&(clearInterval(interval),interval=null)},this.setFrequency=function(a,b){running?(this.pause(),internalSetFrequency(a,b),this.go()):internalSetFrequency(a,b)},this.setVSynch=function(a){running?(this.pause(),vSynch=a,this.go()):vSynch=a},this.getVSynchNativeFrequency=function(){return vSynchAltNativeFrequency||vSynchNativeFrequency},this.setVSynchAltNativeFrequency=function(a){vSynchAltNativeFrequency=a},this.isVSynchActive=function(){return useRequestAnimationFrame},this.getRealTime=function(){return Date.now()-60*(new Date).getTimezoneOffset()*1e3};var internalSetFrequency=function(a,b){cyclesPerSecond=a,cycleTimeMs=1e3/a,divider=b>=1?b:1,dividerCounter>divider&&(dividerCounter=divider)},pulse=function(){animationFrame=null,divider>1?--dividerCounter<=0&&(dividerCounter=divider,clockPulse()):clockPulse(),useRequestAnimationFrame&&!animationFrame&&(animationFrame=requestAnimationFrame(pulse))};this.detectHostNativeFPSAndCallback=function(a){function b(){vSynchNativeFrequency=-1,wmsx.Util.error("Could not detect video native frequency. VSync DISABLED!"),a&&a(vSynchNativeFrequency)}if(-1===WMSX.SCREEN_VSYNC_MODE)return wmsx.Util.warning("Video native VSync disabled in configuration"),void(a&&a(vSynchNativeFrequency));if(-1!==WMSX.SCREEN_FORCE_HOST_NATIVE_FPS)return wmsx.Util.warning("Host video frequency forced in configuration: "+WMSX.SCREEN_FORCE_HOST_NATIVE_FPS),void(a&&a(vSynchNativeFrequency));if(!window.requestAnimationFrame)return b();var c=0,d=0,e=0,f=0,g=0,h=0,i=function(){if(e>=12||f>=18||g>=14||h>=18)return vSynchNativeFrequency=e>=12?60:f>=18?50:g>=14?120:100,wmsx.Util.log("Video native frequency detected: "+vSynchNativeFrequency+"Hz"),void(a&&a(vSynchNativeFrequency));if(!(++c<=70))return b();var j=wmsx.Util.performanceNow(),k=1e3/(j-d);d=j,k>=47&&k<=53&&f++,k>=56.4&&k<=63.6&&e++,k>=112.8&&k<=127.2&&g++,k>=94&&k<=106&&h++,requestAnimationFrame(i)};i()},this.eval=function(str){return eval(str)};var running=!1,cyclesPerSecond=1,cycleTimeMs=1e3,divider=1,dividerCounter=1,useRequestAnimationFrame,animationFrame=null,interval=null,vSynch=!0,vSynchNativeFrequency=-1===WMSX.SCREEN_VSYNC_MODE?-1:WMSX.SCREEN_FORCE_HOST_NATIVE_FPS,vSynchAltNativeFrequency=void 0},wmsx.FileLoader=function(a){"use strict";function b(a,b,c,d,e){return z.loadAsDiskFromFiles(c,a,p.createTreeFromZip(b),d,e)}function c(a,b,c,d){return z.loadAsDiskFromFiles(b,null,a,c,d)}function d(a,b,c,d,f,g,h){if((b===P.DISK||b===P.AUTO)&&z.loadDiskStackFromFiles(c,a,d,f,h))return!0;if(b!==P.DISK)for(var i=0;i<a.length;i++)if(e(a[i],b,c,d,f,g,h))return!0;return!1}function e(a,b,c,d,g,h,i,j){try{i&&!a.content&&(a.content=a.asUint8Array());var k=a.content;if(!j){var l=wmsx.Util.checkContentIsZIP(k);if(l){for(var m=wmsx.Util.getZIPFilesSorted(l),n=0;n<m.length;n++)if(e(m[n],b,c,d,g,h,!0,!0))return!0;return!1}}var o=wmsx.Util.checkContentIsGZIP(k);if(o)return e({name:a.name,content:o},b,c,d,g,h,!1,!0)}catch(a){return wmsx.Util.error(a),!1}return f(a.name,k,b,c,d,g,h)}function f(a,b,c,d,e,f,g){if(c=c||P.AUTO,d=d<0?-d:void 0===d?0:d,(c===P.TAPE||c===P.AUTO)&&y.loadTapeFile(a,b,e))return!0;if((c===P.STATE||c===P.AUTO)&&u.loadStateFile(b))return!0;if((c===P.CART_DATA||c===P.AUTO)&&x.loadCartridgeData(d,a,b))return!0;if(c===P.ROM||c===P.AUTO){var h=wmsx.SlotCreator.createFromROM(new wmsx.ROM(a,b,null,g),x.cartridgeInserted(d));if(h)return h.format===wmsx.SlotFormats.BIOS?s.insertBIOS(h,e):h.format===wmsx.SlotFormats.MSX2BIOSExt?s.insertBIOSEXT(h,e):f?t.insertExpansion(h,d,e):x.insertCartridge(h,d,e),!0}return!1}function g(a,b,c,d,e,f,g){var h=wmsx.SlotCreator.createFromROM(new wmsx.ROM(a,b,null,e,f));return!!h&&(r.insertSlot(h,c,d,g),!0)}function h(a){if(a.returnValue=!1,a.preventDefault(),a.stopPropagation(),a.target.focus(),this.files&&0!==this.files.length){var b=wmsx.Util.asNormalArray(this.files);try{A.value=""}catch(a){}var c=q.systemPause(!0),d=function(a){c||q.systemPause(!1)};return b&&b.length>0&&(1===b.length?p.readFromFile(b[0],C,G,H,I,d):p.readFromFiles(b,C,G,H,I,d)),!1}}function i(a){if(a.returnValue=!1,a.preventDefault(),a.stopPropagation(),!J&&a.dataTransfer){var b=(a.shiftKey?L:0)|(a.ctrlKey?M:0)|(a.altKey?N:0)|(a.buttons&K?O:0);j(a.target,b),a.dataTransfer.dropEffect=!D||D.disabled?"none":"link",F&&clearTimeout(F),F=setTimeout(k,250)}}function j(a,b){if(a&&w.mediaChangeDisabledWarning())a=void 0;else for(;a&&!a.wmsxDropInfo;)a=a.parentElement;if(a){var c=a.wmsxDropInfo;c.subFiles&&b&N?c=c.subFiles:c.subAdd&&b&M&&(c=c.subAdd)}if(D!==c||E!==b){if(D!==c){if(D){D.element.classList.remove("wmsx-selected");var d=D.mainEle;d&&d.classList.remove("wmsx-selected")}D=c,D&&(D.element.classList.add("wmsx-selected"),(d=D.mainEle)&&d.classList.add("wmsx-selected"))}E=b;var e;D&&(e=b&L&&D.mesSec?D.mesSec:D.mes,D.files&&b&M&&(e+=" (do not expand ZIP contents)"),b&O&&(e+=" - no Reset")),v.setFileLoaderDragMessage(e)}}function k(){j(void 0,0),F=void 0}function l(a){if(a.returnValue=!1,a.preventDefault(),a.target.focus(),J||!D||D.disabled||!a.dataTransfer)return k();var b=D,c=E;k();var d=c&O,e=b.files||c&N,f=b.add||c&M,g=void 0!==b.port?b.port:c&L?-1:void 0,h=b.openType;!e||h!==P.DISK&&h!==P.AUTO||(h=f?P.FILES_AS_DISK:P.AUTO_AS_DISK);var i=a.dataTransfer&&a.dataTransfer.files,j=q.systemPause(!0),l=function(a){j||q.systemPause(!1)};if(i&&i.length>0)1===i.length?p.readFromFile(i[0],h,g,d,f,l):p.readFromFiles(i,h,g,d,f,l);else{var m=a.dataTransfer.getData("text");m&&m.length>0?p.readFromURL(m,h,g,d,f,l):l()}}function m(a){if(!a||!a.trim())return a;var b=a.lastIndexOf(".");return(b>0?a.substring(0,b):a).trim()}function n(a){wmsx.Util.message("Could not load file(s):\n\n"+a+"\n")}function o(){A=document.createElement("input"),A.id="wmsx-file-loader-input",A.type="file",A.multiple=!0,A.accept=Q.AUTO,A.style.display="none",A.addEventListener("change",h),B.appendChild(A)}var p=this;this.connect=function(a){q=a,r=q.getSlotSocket(),s=q.getBIOSSocket(),q.getExtensionsSocket().connectFileLoader(this),t=q.getExpansionSocket(),u=q.getSavestateSocket()},this.connectPeripherals=function(a,b,c,d,e){v=a,w=b,x=c,y=d,z=e},this.registerForDnD=function(a){a.addEventListener("dragover",i,!1),a.addEventListener("drop",l,!1)},this.registerForDnDReject=function(a){a.addEventListener("dragover",function(a){a.returnValue=!1,a.preventDefault(),a.stopPropagation(),a.dataTransfer&&(a.dataTransfer.dropEffect="none")},!1)},this.registerForFileInputElement=function(a){B=a},this.openFileChooserDialog=function(a,b,c,d){A||o(),A.multiple=R[P[a]||P.AUTO]&&!(a===P.DISK&&2===c),A.accept=Q[P[a]||P.AUTO],C=a,G=c,H=b,I=d,A.click()},this.openURLChooserDialog=function(a,b,c,d){var e;try{e=localStorage&&localStorage[T]}catch(a){}var f=q.systemPause(!0);if(e=prompt("Load file from URL:",e||""),e=e&&e.toString().trim()){try{localStorage[T]=e}catch(a){}this.readFromURL(e,a,c,b,d,function(){f||q.systemPause(!1)})}else f||q.systemPause(!1)},this.readFromFile=function(a,b,c,d,e,f){wmsx.Util.log("Reading file: "+a.name);var g=new FileReader;g.onload=function(g){var h=new Uint8Array(g.target.result),i={name:a.name,content:h,lastModifiedDate:a.lastModified?new Date(a.lastModified):a.lastModifiedDate};p.loadFromFile(i,b,c,d,e),f&&f(!0)},g.onerror=function(a){n("File reading error: "+a.target.error.name+U),f&&f(!1)},g.readAsArrayBuffer(a)},this.readFromURL=function(a,b,c,d,e,f){
new wmsx.MultiDownloader([{url:a}],function(g){var h={name:a,content:g[0].content,lastModifiedDate:null};p.loadFromFile(h,b,c,d,e),f&&f(!0)},function(a){n("URL reading error: "+a.error),f&&f(!1)}).start()},this.readFromFiles=function(a,b,c,d,e,f){new wmsx.MultiFileReader(a,function(a){p.loadFromFiles(a,b,c,d,e),f&&f(!0)},function(a,b,c){c||(b+=U),n("File reading error: "+b),f&&f(!1)},b===P.AUTO_AS_DISK||b===P.FILES_AS_DISK||b===P.ZIP_AS_DISK?-1:void 0).start()},this.loadFromContent=function(a,b,c,d,e,f,g){return this.loadFromFile({name:a,content:b},c,d,e,f,g)},this.loadFromFile=function(a,e,f,g,h,i){var j,k;if(e===P.AUTO_AS_DISK||e===P.FILES_AS_DISK||e===P.ZIP_AS_DISK){try{if(e===P.FILES_AS_DISK){if(c([a],f,g,h))return}else if(j=wmsx.Util.checkContentIsZIP(a.content)){if(b(m(a.name),j,f,g,h))return}else if(e===P.ZIP_AS_DISK)k="Not a ZIP file!";else if(c([a],f,g,h))return}catch(a){a.wmsx&&(k=a.message)}n("Error loading "+S[e]+(k?": "+k:""))}else{if(j=wmsx.Util.checkContentIsZIP(a.content))try{if(d(wmsx.Util.getZIPFilesSorted(j),e,f,g,h,i,!0))return;if(e===P.AUTO&&b(m(a.name),j,f,g,h))return}catch(a){wmsx.Util.error(a)}else if(d([a],e,f,g,h,i,!1))return;n("No valid "+S[e]+" found.")}},this.loadFromFiles=function(a,b,e,f,g){if(a=wmsx.Util.asNormalArray(a).slice(0),a.sort(function(a,b){return a.name<b.name?-1:a.name>b.name?1:0}),b===P.AUTO_AS_DISK||b===P.FILES_AS_DISK||b===P.ZIP_AS_DISK){var h;try{if(c(a,e,f,g))return}catch(a){a.wmsx&&(h=a.message)}n("Error loading "+S[b]+(h?": "+h:""))}else{if(d(a,b,e,f,g,null,!1))return;n("No valid "+S[b]+" found.")}},this.loadFromContentAsSlot=function(a,b,c,d,e,f,h){var i=wmsx.Util.checkContentIsZIP(b);if(i)try{for(var j=wmsx.Util.getZIPFilesSorted(i),k=0;k<j.length;k++)if(g(a,j[k].asUint8Array(),c,d,e,f,h))return}catch(a){}else if(g(a,b,c,d,e,f,h))return;n("Unsupported ROM file!")},this.createTreeFromZip=function(a){var b=[],c=a.folder(/.+/);c=c.filter(function(a){return a.dir&&a.name&&a.name.trim()}),c.sort(function(a,b){return void 0===a.dirDepth&&(a.dirDepth=wmsx.Util.stringCountOccurrences(a.name,"/")),void 0===b.dirDepth&&(b.dirDepth=wmsx.Util.stringCountOccurrences(b.name,"/")),a.dirDepth-b.dirDepth});for(var d=0;d<c.length;++d)!function(a){for(var c=a.name.split("/"),d=b,e=0;e<c.length-1;++e){var f=c[e],g=d.find(function(a){return a.isDir&&a.name==f});g||(g={isDir:!0,name:f,lastModifiedDate:a.date,items:[]},d.push(g)),d=g.items}}(c[d]);for(var e=a.file(/.+/).filter(function(a){return!a.dir&&a.name&&a.name.trim()}),f=0;f<e.length;++f)!function(a){for(var c=a.name.split("/"),d=b,e=0;e<c.length-1;++e){var f=c[e],g=d.find(function(a){return a.isDir&&a.name==f});g||(g={isDir:!0,name:f,lastModifiedDate:a.date,items:[]},d.push(g)),d=g.items}var h=c[c.length-1];h&&h.trim()&&(a.name=h,a.isDir=!1,a.lastModifiedDate=a.date,a.content=a.asUint8Array(),d.push(a))}(e[f]);return b},this.setDragAndDropDisabled=function(a){J=!!a};var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G=0,H=!1,I=!1,J=!1,K=2,L=1,M=2,N=4,O=8,P=wmsx.FileLoader.OPEN_TYPE;this.OPEN_TYPE=P;var Q={ROM:".bin,.BIN,.rom,.ROM,.bios,.BIOS,.zip,.ZIP,.gz,.GZ,.gzip,.GZIP",DISK:".bin,.BIN,.dsk,.DSK,.zip,.ZIP,.gz,.GZ,.gzip,.GZIP",TAPE:".bin,.BIN,.cas,.CAS,.tape,.TAPE,.zip,.ZIP,.gz,.GZ,.gzip,.GZIP",STATE:".wst,.WST",CART_DATA:".pac,.PAC,.dat,.DAT,.sram,.SRAM",FILES_AS_DISK:"",ZIP_AS_DISK:".zip,.ZIP",AUTO_AS_DISK:"",AUTO:".bin,.BIN,.dsk,.DSK,.rom,.ROM,.bios,.BIOS,.cas,.CAS,.tape,.TAPE,.wst,.WST,.zip,.ZIP,.gz,.GZ,.gzip,.GZIP"},R={ROM:!1,DISK:!0,TAPE:!1,STATE:!1,CART_DATA:!1,FILES_AS_DISK:!0,ZIP_AS_DISK:!1,AUTO_AS_DISK:!0,AUTO:!1},S={ROM:"ROM",DISK:"Disk",TAPE:"Cassette",STATE:"Savestate",CART_DATA:"Cartridge Data",FILES_AS_DISK:"Files",ZIP_AS_DISK:"ZIP Contents",AUTO_AS_DISK:"Files",AUTO:"ROM, Cassette or Disk"},T="wmsxlasturl",U="\n\nIMPORTANT: Directories are not supported for loading!\nPlease use a ZIP File if you need directories support.";WMSX.fileLoader=this},wmsx.FileLoader.OPEN_TYPE={AUTO:"AUTO",ROM:"ROM",DISK:"DISK",TAPE:"TAPE",STATE:"STATE",CART_DATA:"CART_DATA",FILES_AS_DISK:"FILES_AS_DISK",ZIP_AS_DISK:"ZIP_AS_DISK",AUTO_AS_DISK:"AUTO_AS_DISK"},wmsx.FileDownloader=function(){"use strict";function a(){b=wmsx.Util.isIOSDevice()?"DATA":"BLOB",c=document.createElement("a"),c.style.display="none",c.target="_blank",c.href="#",d.appendChild(c)}this.connectPeripherals=function(a){e=a},this.registerForDownloadElement=function(a){d=a},this.startDownloadBinary=function(d,f,g){try{b||a();var h;if("BLOB"===b){c.href&&(window.URL||window.webkitURL).revokeObjectURL(c.href);var i=new Blob([f],{type:"data:application/octet-stream"});h=(window.URL||window.webkitURL).createObjectURL(i)}else h="data:application/octet-stream;base64,"+btoa("string"==typeof f?f:wmsx.Util.int8BitArrayToByteString(f));return c.download=d&&d.trim(),c.href=h,c.click(),e.showOSD(g+" saved",!0),!0}catch(a){return e.showOSD(g+" save FAILED!",!0,!0),wmsx.Util.error(a),!1}},this.startDownloadURL=function(d,f,g){try{b||a(),"BLOB"===b&&c.href&&(window.URL||window.webkitURL).revokeObjectURL(c.href),c.download=d&&d.trim(),c.href=f,c.click(),e.showOSD(g+" saved",!0)}catch(a){e.showOSD(g+" save FAILED!",!0,!0),wmsx.Util.error(a)}};var b,c,d,e},wmsx.DOMKeys={keys:{},keysByCode:{},keysByLegacyCode:{},SHIFT:65536,CONTROL:131072,ALT:262144,META:524288,LOCLEFT:1048576,LOCRIGHT:2097152,LOCNUM:3145728,LOC_BIT_SHIFT:20,nextCustomCode:10001},wmsx.DOMKeys.IGNORE_ALL_MODIFIERS_MASK=~(wmsx.DOMKeys.SHIFT|wmsx.DOMKeys.CONTROL|wmsx.DOMKeys.ALT|wmsx.DOMKeys.META),wmsx.DOMKeys.addKeyToIdentification=function(a){a.wc&&!a.a&&(this.keys[a.wc]=a,a.d&&(this.keysByCode[a.d]=a),a.c>0&&(this.keysByLegacyCode[a.c]=a))},function(a,b,c,d){a.VK_1={wc:1,d:"Digit1",c:49,n:"1"},a.VK_2={wc:2,d:"Digit2",c:50,n:"2"},a.VK_3={wc:3,d:"Digit3",c:51,n:"3"},a.VK_4={wc:4,d:"Digit4",c:52,n:"4"},a.VK_5={wc:5,d:"Digit5",c:53,n:"5"},a.VK_6={wc:6,d:"Digit6",c:54,n:"6"},a.VK_7={wc:7,d:"Digit7",c:55,n:"7"},a.VK_8={wc:8,d:"Digit8",c:56,n:"8"},a.VK_9={wc:9,d:"Digit9",c:57,n:"9"},a.VK_0={wc:10,d:"Digit0",c:48,n:"0"},a.VK_F1={wc:21,d:"F1",c:112,n:"F1"},a.VK_F2={wc:22,d:"F2",c:113,n:"F2"},a.VK_F3={wc:23,d:"F3",c:114,n:"F3"},a.VK_F4={wc:24,d:"F4",c:115,n:"F4"},a.VK_F5={wc:25,d:"F5",c:116,n:"F5"},a.VK_F6={wc:26,d:"F6",c:117,n:"F6"},a.VK_F7={wc:27,d:"F7",c:118,n:"F7"},a.VK_F8={wc:28,d:"F8",c:119,n:"F8"},a.VK_F9={wc:29,d:"F9",c:120,n:"F9"},a.VK_F10={wc:30,d:"F10",c:121,n:"F10"},a.VK_F11={wc:31,d:"F11",c:122,n:"F11"},a.VK_F12={wc:32,d:"F12",c:123,n:"F12"},a.VK_Q={wc:101,d:"KeyQ",c:81,n:"Q"},a.VK_W={wc:102,d:"KeyW",c:87,n:"W"},a.VK_E={wc:103,d:"KeyE",c:69,n:"E"},a.VK_R={wc:104,d:"KeyR",c:82,n:"R"},a.VK_T={wc:105,d:"KeyT",c:84,n:"T"},a.VK_Y={wc:106,d:"KeyY",c:89,n:"Y"},a.VK_U={wc:107,d:"KeyU",c:85,n:"U"},a.VK_I={wc:108,d:"KeyI",c:73,n:"I"},a.VK_O={wc:109,d:"KeyO",c:79,n:"O"},a.VK_P={wc:110,d:"KeyP",c:80,n:"P"},a.VK_A={wc:111,d:"KeyA",c:65,n:"A"},a.VK_S={wc:112,d:"KeyS",c:83,n:"S"},a.VK_D={wc:113,d:"KeyD",c:68,n:"D"},a.VK_F={wc:114,d:"KeyF",c:70,n:"F"},a.VK_G={wc:115,d:"KeyG",c:71,n:"G"},a.VK_H={wc:116,d:"KeyH",c:72,n:"H"},a.VK_J={wc:117,d:"KeyJ",c:74,n:"J"},a.VK_K={wc:118,d:"KeyK",c:75,n:"K"},a.VK_L={wc:119,d:"KeyL",c:76,n:"L"},a.VK_Z={wc:120,d:"KeyZ",c:90,n:"Z"},a.VK_X={wc:121,d:"KeyX",c:88,n:"X"},a.VK_C={wc:122,d:"KeyC",c:67,n:"C"},a.VK_V={wc:123,d:"KeyV",c:86,n:"V"},a.VK_B={wc:124,d:"KeyB",c:66,n:"B"},a.VK_N={wc:125,d:"KeyN",c:78,n:"N"},a.VK_M={wc:126,d:"KeyM",c:77,n:"M"},a.VK_ESCAPE={wc:201,d:"Escape",c:27,n:"Esc",fn:!0},a.VK_BACKSPACE={wc:202,d:"Backspace",c:8,n:"BackSpc",fn:!0},a.VK_TAB={wc:203,d:"Tab",c:9,n:"Tab",fn:!0},a.VK_ENTER={wc:204,d:"Enter",c:13,n:"Enter",fn:!0},a.VK_SPACE={wc:205,d:"Space",c:32,n:"Space",fn:!0},a.VK_BACKQUOTE={wc:221,d:"Backquote",c:192,n:"`"},a.VK_MINUS={wc:222,d:"Minus",c:189,n:"-"},a.VK_EQUALS={wc:223,d:"Equal",c:187,n:"="},a.VK_INT_YEN={wc:224,d:"IntlYen",c:-1,n:"Int ¥"},a.VK_OPEN_BRACKET={wc:225,d:"BracketLeft",c:219,n:"["},a.VK_CLOSE_BRACKET={
wc:226,d:"BracketRight",c:221,n:"]"},a.VK_SEMICOLON={wc:227,d:"Semicolon",c:186,n:";"},a.VK_QUOTE={wc:228,d:"Quote",c:222,n:"'"},a.VK_BACKSLASH={wc:229,d:"Backslash",c:220,n:"\\"},a.VK_INT_BACKSLASH={wc:230,d:"IntlBackslash",c:226,n:"Int \\"},a.VK_COMMA={wc:231,d:"Comma",c:188,n:","},a.VK_PERIOD={wc:232,d:"Period",c:190,n:"."},a.VK_SLASH={wc:233,d:"Slash",c:191,n:"/"},a.VK_INT_RO={wc:234,d:"IntlRo",c:193,n:"Int ろ"},a.VK_INSERT={wc:251,d:"Insert",c:45,n:"Ins",fn:!0},a.VK_DELETE={wc:252,d:"Delete",c:46,n:"Del",fn:!0},a.VK_HOME={wc:253,d:"Home",c:36,n:"Home",fn:!0},a.VK_END={wc:254,d:"End",c:35,n:"End",fn:!0},a.VK_PAGE_UP={wc:255,d:"PageUp",c:33,n:"PgUp",fn:!0},a.VK_PAGE_DOWN={wc:256,d:"PageDown",c:34,n:"PgDown",fn:!0},a.VK_UP={wc:271,d:"ArrowUp",c:38,n:"Up",fn:!0},a.VK_DOWN={wc:272,d:"ArrowDown",c:40,n:"Down",fn:!0},a.VK_LEFT={wc:273,d:"ArrowLeft",c:37,n:"Left",fn:!0},a.VK_RIGHT={wc:274,d:"ArrowRight",c:39,n:"Right",fn:!0},a.VK_PRINT_SCREEN={wc:281,d:"PrintScreen",c:44,n:"PrtScr",fn:!0},a.VK_SCROLL_LOCK={wc:282,d:"ScrollLock",c:145,n:"ScrLck",fn:!0},a.VK_PAUSE={wc:283,d:"Pause",c:19,n:"Pause",fn:!0},a.VK_BREAK={wc:284,d:"",c:3,n:"Break",fn:!0},a.VK_CONTEXT={wc:285,d:"ContextMenu",c:93,n:"Context",fn:!0},a.VK_LSHIFT={wc:301,d:"ShiftLeft",c:16|b,n:"L-Shift",fn:!0},a.VK_LCONTROL={wc:302,d:"ControlLeft",c:17|b,n:"L-Control",fn:!0},a.VK_LALT={wc:303,d:"AltLeft",c:18|b,n:"L-Alt",fn:!0},a.VK_LMETA={wc:304,d:"MetaLeft",c:91|b,n:"L-Meta",fn:!0},a.VK_RSHIFT={wc:305,d:"ShiftRight",c:16|c,n:"R-Shift",fn:!0},a.VK_RCONTROL={wc:306,d:"ControlRight",c:17|c,n:"R-Control",fn:!0},a.VK_RALT={wc:307,d:"AltRight",c:18|c,n:"R-Alt",fn:!0},a.VK_RMETA={wc:308,d:"MetaRight",c:91|c,n:"R-Meta",fn:!0},a.VK_CAPS_LOCK={wc:309,d:"CapsLock",c:20,n:"CapsLock",fn:!0},a.VK_NON_CONVERT={wc:310,d:"NonConvert",c:29,n:"NonConvert",fn:!0},a.VK_CONVERT={wc:311,d:"Convert",c:28,n:"Convert",fn:!0},a.VK_KANA={wc:312,d:"KanaMode",c:-1,n:"Kana",fn:!0},a.VK_NUMLOCK={wc:401,d:"NumLock",c:144,n:"NumLock"},a.VK_NUM_COMMA={wc:402,d:"NumpadComma",c:110|d,n:"Num ,"},a.VK_NUM_DIVIDE={wc:403,d:"NumpadDivide",c:111|d,n:"Num /"},a.VK_NUM_MULTIPLY={wc:404,d:"NumpadMultiply",c:106|d,n:"Num *"},a.VK_NUM_MINUS={wc:405,d:"NumpadSubtract",c:109|d,n:"Num -"},a.VK_NUM_PLUS={wc:406,d:"NumpadAdd",c:107|d,n:"Num +"},a.VK_NUM_ENTER={wc:407,d:"NumpadEnter",c:13|d,n:"Num Enter",fn:!0},a.VK_NUM_PERIOD={wc:408,d:"NumpadDecimal",c:194|d,n:"Num .",fn:!0},a.VK_NUM_1={wc:421,d:"Numpad1",c:97|d,n:"Num 1",fn:!0},a.VK_NUM_2={wc:422,d:"Numpad2",c:98|d,n:"Num 2",fn:!0},a.VK_NUM_3={wc:423,d:"Numpad3",c:99|d,n:"Num 3",fn:!0},a.VK_NUM_4={wc:424,d:"Numpad4",c:100|d,n:"Num 4",fn:!0},a.VK_NUM_5={wc:425,d:"Numpad5",c:101|d,n:"Num 5",fn:!0},a.VK_NUM_6={wc:426,d:"Numpad6",c:102|d,n:"Num 6",fn:!0},a.VK_NUM_7={wc:427,d:"Numpad7",c:103|d,n:"Num 7",fn:!0},a.VK_NUM_8={wc:428,d:"Numpad8",c:104|d,n:"Num 8",fn:!0},a.VK_NUM_9={wc:429,d:"Numpad9",c:105|d,n:"Num 9",fn:!0},a.VK_NUM_0={wc:430,d:"Numpad0",c:96|d,n:"Num 0",fn:!0},a.VK_VOID={wc:-1,d:"",c:-1,n:"Unbound",fn:!0},a.VK_BR_QUOTE={wc:221,d:"Backquote",c:192,n:"'",a:"BR"},a.VK_BR_ACUTE={wc:225,d:"BracketLeft",c:219,n:"´",a:"BR"},a.VK_BR_OPEN_BRACKET={wc:226,d:"BracketRight",c:221,n:"[",a:"BR"},a.VK_BR_CEDILLA={wc:227,d:"Semicolon",c:186,n:"Ç",a:"BR"},a.VK_BR_TILDE={wc:228,d:"Quote",c:222,n:"~",a:"BR"},a.VK_BR_CLOSE_BRACKET={wc:229,d:"Backslash",c:220,n:"]",a:"BR"},a.VK_BR_SEMICOLON={wc:233,d:"Slash",c:191,n:";",a:"BR"},a.VK_BR_BACKSLASH={wc:230,d:"IntlBackslash",c:226,n:"\\",a:"BR"},a.VK_BR_SLASH={wc:234,d:"IntlRo",c:193,n:"/",a:"BR"},a.VK_JP_CIRCUMFLEX={wc:223,d:"Equal",c:187,n:"^",a:"JP"},a.VK_JP_YEN={wc:224,d:"IntlYen",c:-1,n:"¥",a:"JP"},a.VK_JP_ARROBA={wc:225,d:"BracketLeft",c:219,n:"@",a:"JP"},a.VK_JP_OPEN_BRACKET={wc:226,d:"BracketRight",c:221,n:"[",a:"JP"},a.VK_JP_COLLON={wc:228,d:"Quote",c:222,n:":",a:"JP"},a.VK_JP_CLOSE_BRACKET={wc:229,d:"Backslash",c:220,n:"]",a:"JP"},a.VK_JP_RO={wc:234,d:"IntlRo",c:193,n:"\\ ろ",a:"JP"},a.VK_JP_NON_CONVERT={wc:310,d:"NonConvert",c:29,n:"NonConvert",fn:!0},a.VK_ES_ORDINAL={wc:221,d:"Backquote",c:192,n:"º",a:"ES"},a.VK_ES_QUOTE={wc:222,d:"Minus",c:189,n:"'",a:"ES"},a.VK_ES_INV_EXCLA={wc:223,d:"Equal",c:187,n:"¡",a:"ES"},a.VK_ES_GRAVE={wc:225,d:"BracketLeft",c:219,n:"`",a:"ES"},a.VK_ES_PLUS={wc:226,d:"BracketRight",c:221,n:"+",a:"ES"},a.VK_ES_ENNE={wc:227,d:"Semicolon",c:186,n:"Ñ",a:"ES"},a.VK_ES_ACUTE={wc:228,d:"Quote",c:222,n:"´",a:"ES"},a.VK_ES_CEDILLA={wc:229,d:"Backslash",c:220,n:"Ç",a:"ES"},a.VK_ES_LESSER={wc:230,d:"IntlBackslash",c:226,n:"<",a:"ES"},a.VK_ES_MINUS={wc:233,d:"Slash",c:191,n:"-",a:"ES"},a.VK_NL_ARROBA={wc:221,d:"Backquote",c:192,n:"@",a:"NL"},a.VK_NL_SLASH={wc:222,d:"Minus",c:189,n:"/",a:"NL"},a.VK_NL_ORDINAL={wc:223,d:"Equal",c:187,n:"°",a:"NL"},a.VK_NL_UMLAUT={wc:225,d:"BracketLeft",c:219,n:"¨",a:"NL"},a.VK_NL_STAR={wc:226,d:"BracketRight",c:221,n:"*",a:"NL"},a.VK_NL_PLUS={wc:227,d:"Semicolon",c:186,n:"+",a:"NL"},a.VK_NL_ACUTE={wc:228,d:"Quote",c:222,n:"´",a:"NL"},a.VK_NL_LESSER={wc:229,d:"Backslash",c:220,n:"<",a:"NL"},a.VK_NL_CLOSE_BRACKET={wc:230,d:"IntlBackslash",c:226,n:"]",a:"NL"},a.VK_NL_MINUS={wc:233,d:"Slash",c:191,n:"-",a:"NL"},a.VK_IT_BACKSLASH={wc:221,d:"Backquote",c:192,n:"\\",a:"IT"},a.VK_IT_QUOTE={wc:222,d:"Minus",c:189,n:"'",a:"IT"},a.VK_IT_GRAVE_I={wc:223,d:"Equal",c:187,n:"ì",a:"IT"},a.VK_IT_GRAVE_E={wc:225,d:"BracketLeft",c:219,n:"è",a:"IT"},a.VK_IT_PLUS={wc:226,d:"BracketRight",c:221,n:"+",a:"IT"},a.VK_IT_GRAVE_O={wc:227,d:"Semicolon",c:186,n:"ò",a:"IT"},a.VK_IT_GRAVE_A={wc:228,d:"Quote",c:222,n:"à",a:"IT"},a.VK_IT_GRAVE_U={wc:229,d:"Backslash",c:220,n:"ù",a:"IT"},a.VK_IT_LESSER={wc:230,d:"IntlBackslash",c:226,n:"<",a:"IT"},a.VK_IT_MINUS={wc:233,d:"Slash",c:191,n:"-",a:"IT"},a.VK_FR_2u={wc:221,d:"Backquote",c:192,n:"²",a:"FR"},a.VK_FR_CLOSE_PARENS={wc:222,d:"Minus",c:189,n:")",a:"FR"},a.VK_FR_EQUAL={wc:223,d:"Equal",c:187,n:"=",a:"FR"},a.VK_FR_A={wc:101,d:"KeyQ",c:81,n:"A",a:"FR"},a.VK_FR_Z={wc:102,d:"KeyW",c:87,n:"Z",a:"FR"},a.VK_FR_CIRCUMFLEX={wc:225,d:"BracketLeft",c:219,n:"^",a:"FR"},a.VK_FR_DOLLAR={wc:226,d:"BracketRight",c:221,n:"$",a:"FR"},a.VK_FR_Q={wc:111,d:"KeyA",c:65,n:"Q",a:"FR"},a.VK_FR_M={wc:227,d:"Semicolon",c:186,n:"M",a:"FR"},a.VK_FR_U_GRAVE={wc:228,d:"Quote",c:222,n:"ù",a:"FR"},a.VK_FR_STAR={wc:229,d:"Backslash",c:220,n:"*",a:"FR"},a.VK_FR_LESSER={wc:230,d:"IntlBackslash",c:226,n:"<",a:"FR"},a.VK_FR_W={wc:120,d:"KeyZ",c:90,n:"W",a:"FR"},a.VK_FR_COMMA={wc:126,d:"KeyM",c:77,n:",",a:"FR"},a.VK_FR_SEMICOLON={wc:231,d:"Comma",c:188,n:";",a:"FR"},a.VK_FR_COLON={wc:232,d:"Period",c:190,n:":",a:"FR"},a.VK_FR_EXCLAMATION={wc:233,d:"Slash",c:191,n:"!",a:"FR"};for(var e in a)a.addKeyToIdentification(a[e])}(wmsx.DOMKeys,wmsx.DOMKeys.LOCLEFT,wmsx.DOMKeys.LOCRIGHT,wmsx.DOMKeys.LOCNUM),wmsx.DOMKeys.isModifierKey=function(a){var b=a.keyCode;return 16===b||17===b||18===b||91===b},wmsx.DOMKeys.codeNewForKeyboardEvent=function(a){var b=this.keysByCode[a.code]||this.keysByLegacyCode[a.keyCode|a.location<<this.LOC_BIT_SHIFT];return b?this.isModifierKey(a)?b.wc:b.wc|(a.shiftKey?this.SHIFT:0)|(a.ctrlKey?this.CONTROL:0)|(a.altKey?this.ALT:0)|(a.metaKey?this.META:0):0},wmsx.DOMKeys.nameForKeyboardEvent=function(a){var b=this.codeNewForKeyboardEvent(a),c=this.keys[b&this.IGNORE_ALL_MODIFIERS_MASK];if(c||a.code||a.keyCode>0){var d=a.keyCode,e=a.key;if(c&&c.fn)e=c.n;else{var f=e&&e.toUpperCase();switch(f&&"UNIDENTIFIED"!==f&&"UNDEFINED"!==f&&"UNKNOWN"!==f?"DEAD"===f&&(e="Dead#"+d):e=a.code||"#"+d,1===e.length?e=e.toUpperCase():e.length>12&&(e=e.substr(0,12)),a.location){case 1:e="L-"+e;break;case 2:e="R-"+e;break;case 3:e="Num "+e}}return c||(wmsx.Util.warning("New Host Key discovered:",a),b=WMSX.userPreferences.current.customHostKeys.nextCode++,c={wc:b,d:a.code||"",c:a.code?0:a.keyCode&this.IGNORE_ALL_MODIFIERS_MASK|a.location<<this.LOC_BIT_SHIFT,n:e},this.addKeyToIdentification(c),
WMSX.userPreferences.current.customHostKeys.keys.push(c),WMSX.userPreferences.setDirty()),(a.shiftKey||a.ctrlKey||a.altKey||a.metaKey)&&(e=[e],a.metaKey&&e.unshift("Meta"),a.altKey&&e.unshift("Alt"),a.ctrlKey&&e.unshift("Ctrl"),a.shiftKey&&e.unshift("Shift")),e}},wmsx.DOMKeys.initPreferences=function(){for(var a=WMSX.userPreferences.current.customHostKeys.keys,b=0,c=a.length;b<c;++b)this.addKeyToIdentification(a[b])},wmsx.GamepadButtons={GB_1:{b:0,n:"1"},GB_2:{b:1,n:"2"},GB_3:{b:2,n:"3"},GB_4:{b:3,n:"4"},GB_L1:{b:4,n:"L1"},GB_R1:{b:5,n:"R1"},GB_L2:{b:6,n:"L2"},GB_R2:{b:7,n:"R2"},GB_BACK:{b:8,n:"BACK"},GB_START:{b:9,n:"START"},GB_S1:{b:10,n:"S1"},GB_S2:{b:11,n:"S2"},GB_UP:{b:12,n:"&#9650;"},GB_DOWN:{b:13,n:"&#9660;"},GB_LEFT:{b:14,n:"&#9668;"},GB_RIGHT:{b:15,n:"&#9658;"},GB_LOGO:{b:16,n:"LOGO"},GB_VOID:{b:-1,n:"Unbound"}},wmsx.TouchControls={directional:"T_DIR",buttons:["T_A","T_B","T_C","T_D","T_E","T_F","T_G","T_X","T_Y"],buttonsLeftSide:["T_X","T_Y"],buttonsRightSide:["T_F","T_D","T_B","T_A","T_C","T_E","T_G"]},function(){var a=wmsx.DOMKeys,b={D0:a.VK_0,D1:a.VK_1,D2:a.VK_2,D3:a.VK_3,D4:a.VK_4,D5:a.VK_5,D6:a.VK_6,D7:a.VK_7,D8:a.VK_8,D9:a.VK_9,MINUS:a.VK_MINUS,EQUAL:a.VK_EQUALS,BACKSLASH:[a.VK_BACKSLASH,a.VK_INT_BACKSLASH,a.VK_INT_YEN],OPEN_BRACKET:a.VK_OPEN_BRACKET,CLOSE_BRACKET:a.VK_CLOSE_BRACKET,SEMICOLON:a.VK_SEMICOLON,QUOTE:a.VK_QUOTE,BACKQUOTE:a.VK_BACKQUOTE,COMMA:a.VK_COMMA,PERIOD:a.VK_PERIOD,SLASH:a.VK_SLASH,DEAD:[a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],A:a.VK_A,B:a.VK_B,C:a.VK_C,D:a.VK_D,E:a.VK_E,F:a.VK_F,G:a.VK_G,H:a.VK_H,I:a.VK_I,J:a.VK_J,K:a.VK_K,L:a.VK_L,M:a.VK_M,N:a.VK_N,O:a.VK_O,P:a.VK_P,Q:a.VK_Q,R:a.VK_R,S:a.VK_S,T:a.VK_T,U:a.VK_U,V:a.VK_V,W:a.VK_W,X:a.VK_X,Y:a.VK_Y,Z:a.VK_Z,SHIFT:[a.VK_LSHIFT,a.VK_RSHIFT],CONTROL:[a.VK_LCONTROL],CAPSLOCK:a.VK_CAPS_LOCK,GRAPH:[a.VK_LALT,a.VK_PAGE_UP],CODE:[a.VK_RALT,a.VK_PAGE_DOWN],F1:a.VK_F1,F2:a.VK_F2,F3:a.VK_F3,F4:a.VK_F4,F5:a.VK_F5,ESCAPE:[a.VK_ESCAPE,{wc:a.VK_BACKQUOTE.wc|a.ALT,n:["Alt","`"]}],TAB:a.VK_TAB,STOP:[a.VK_PAUSE,a.VK_BREAK,a.VK_F9],BACKSPACE:a.VK_BACKSPACE,SELECT:[a.VK_SCROLL_LOCK,a.VK_F10],ENTER:[a.VK_ENTER,a.VK_NUM_ENTER],SPACE:a.VK_SPACE,HOME:[a.VK_HOME,{wc:a.VK_OPEN_BRACKET.wc|a.ALT,n:["Alt","["]}],INSERT:[a.VK_INSERT,{wc:a.VK_CLOSE_BRACKET.wc|a.ALT,n:["Alt","]"]}],DELETE:[a.VK_DELETE,{wc:a.VK_BACKSLASH.wc|a.ALT,n:["Alt","\\"]}],UP:a.VK_UP,DOWN:a.VK_DOWN,RIGHT:a.VK_RIGHT,LEFT:a.VK_LEFT,NUM_MULTIPLY:a.VK_NUM_MULTIPLY,NUM_PLUS:a.VK_NUM_PLUS,NUM_DIVIDE:a.VK_NUM_DIVIDE,NUM_0:a.VK_NUM_0,NUM_1:a.VK_NUM_1,NUM_2:a.VK_NUM_2,NUM_3:a.VK_NUM_3,NUM_4:a.VK_NUM_4,NUM_5:a.VK_NUM_5,NUM_6:a.VK_NUM_6,NUM_7:a.VK_NUM_7,NUM_8:a.VK_NUM_8,NUM_9:a.VK_NUM_9,NUM_MINUS:a.VK_NUM_MINUS,NUM_COMMA:a.VK_NUM_COMMA,NUM_PERIOD:a.VK_NUM_PERIOD,YES:a.VK_VOID,NO:a.VK_VOID},c={};for(var d in b)c[d]=b[d];var e={};for(d in b)e[d]=b[d];e.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_BR_QUOTE.wc|a.ALT,n:["Alt","'"]}],e.BACKSLASH=[a.VK_BR_BACKSLASH,a.VK_INT_YEN],e.OPEN_BRACKET=a.VK_BR_OPEN_BRACKET,e.CLOSE_BRACKET=a.VK_BR_CLOSE_BRACKET,e.SEMICOLON=a.VK_BR_SEMICOLON,e.QUOTE=a.VK_BR_QUOTE,e.BACKQUOTE=a.VK_BR_ACUTE,e.SLASH=a.VK_BR_SLASH,e.DEAD=[a.VK_BR_TILDE,a.VK_BR_CEDILLA,a.VK_RCONTROL,a.VK_END],e.HOME=[a.VK_HOME,{wc:a.VK_BR_OPEN_BRACKET.wc|a.ALT,n:["Alt","["]}],e.INSERT=[a.VK_INSERT,{wc:a.VK_BR_CLOSE_BRACKET.wc|a.ALT,n:["Alt","]"]}],e.DELETE=[a.VK_DELETE,{wc:a.VK_BR_SLASH.wc|a.ALT,n:["Alt","/"]}];var f={};for(d in b)f[d]=b[d];f.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_JP_YEN.wc|a.ALT,n:["Alt","¥"]}],f.EQUAL=a.VK_JP_CIRCUMFLEX,f.BACKSLASH=[a.VK_JP_YEN,a.VK_INT_BACKSLASH],f.OPEN_BRACKET=a.VK_JP_OPEN_BRACKET,f.CLOSE_BRACKET=a.VK_JP_CLOSE_BRACKET,f.QUOTE=a.VK_JP_COLLON,f.BACKQUOTE=a.VK_JP_ARROBA,f.DEAD=[a.VK_JP_RO,a.VK_RCONTROL,a.VK_END],f.CAPSLOCK=a.VK_JP_NON_CONVERT,f.HOME=[a.VK_HOME,{wc:a.VK_JP_OPEN_BRACKET.wc|a.ALT,n:["Alt","["]}],f.INSERT=[a.VK_INSERT,{wc:a.VK_JP_CLOSE_BRACKET.wc|a.ALT,n:["Alt","]"]}],f.DELETE=[a.VK_DELETE,{wc:a.VK_JP_RO.wc|a.ALT,n:["Alt","\\ ろ"]}];var g={};for(d in b)g[d]=b[d];g.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_ES_ORDINAL.wc|a.ALT,n:["Alt","º"]}],g.MINUS=a.VK_ES_MINUS,g.EQUAL=a.VK_ES_INV_EXCLA,g.BACKSLASH=[a.VK_ES_ORDINAL,a.VK_INT_YEN],g.OPEN_BRACKET=a.VK_ES_GRAVE,g.CLOSE_BRACKET=a.VK_ES_PLUS,g.SEMICOLON=a.VK_ES_ENNE,g.QUOTE=a.VK_ES_QUOTE,g.BACKQUOTE=a.VK_ES_ACUTE,g.SLASH=a.VK_ES_LESSER,g.DEAD=[a.VK_ES_CEDILLA,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],g.HOME=[a.VK_HOME,{wc:a.VK_ES_GRAVE.wc|a.ALT,n:["Alt","`"]}],g.INSERT=[a.VK_INSERT,{wc:a.VK_ES_PLUS.wc|a.ALT,n:["Alt","+"]}],g.DELETE=[a.VK_DELETE,{wc:a.VK_ES_CEDILLA.wc|a.ALT,n:["Alt","Ç"]}];var h={};for(d in b)h[d]=b[d];h.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_NL_ARROBA.wc|a.ALT,n:["Alt","@"]}],h.MINUS=a.VK_NL_MINUS,h.EQUAL=a.VK_NL_ORDINAL,h.BACKSLASH=[a.VK_NL_CLOSE_BRACKET,a.VK_INT_YEN],h.OPEN_BRACKET=a.VK_NL_UMLAUT,h.CLOSE_BRACKET=a.VK_NL_STAR,h.SEMICOLON=a.VK_NL_PLUS,h.QUOTE=a.VK_NL_ACUTE,h.BACKQUOTE=a.VK_NL_ARROBA,h.SLASH=a.VK_NL_SLASH,h.DEAD=[a.VK_NL_LESSER,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],h.HOME=[a.VK_HOME,{wc:a.VK_NL_UMLAUT.wc|a.ALT,n:["Alt","¨"]}],h.INSERT=[a.VK_INSERT,{wc:a.VK_NL_STAR.wc|a.ALT,n:["Alt","*"]}],h.DELETE=[a.VK_DELETE,{wc:a.VK_NL_LESSER.wc|a.ALT,n:["Alt","<"]}];var i={};for(d in b)i[d]=b[d];i.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_IT_BACKSLASH.wc|a.ALT,n:["Alt","\\"]}],i.MINUS=a.VK_IT_MINUS,i.EQUAL=a.VK_IT_GRAVE_I,i.BACKSLASH=[a.VK_IT_BACKSLASH,a.VK_INT_YEN],i.OPEN_BRACKET=a.VK_IT_GRAVE_E,i.CLOSE_BRACKET=a.VK_IT_PLUS,i.SEMICOLON=a.VK_IT_GRAVE_O,i.QUOTE=a.VK_IT_QUOTE,i.BACKQUOTE=a.VK_IT_GRAVE_A,i.SLASH=a.VK_IT_LESSER,i.DEAD=[a.VK_IT_GRAVE_U,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],i.HOME=[a.VK_HOME,{wc:a.VK_IT_GRAVE_E.wc|a.ALT,n:["Alt","è"]}],i.INSERT=[a.VK_INSERT,{wc:a.VK_IT_PLUS.wc|a.ALT,n:["Alt","+"]}],i.DELETE=[a.VK_DELETE,{wc:a.VK_IT_GRAVE_U.wc|a.ALT,n:["Alt","ù"]}];var j={};for(d in b)j[d]=b[d];j.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_FR_2u.wc|a.ALT,n:["Alt","²"]}],j.MINUS=a.VK_FR_CLOSE_PARENS,j.BACKSLASH=[a.VK_FR_LESSER,a.VK_INT_YEN],j.Q=a.VK_FR_Q,j.W=a.VK_FR_W,j.OPEN_BRACKET=a.VK_FR_CIRCUMFLEX,j.CLOSE_BRACKET=a.VK_FR_DOLLAR,j.A=a.VK_FR_A,j.SEMICOLON=a.VK_FR_SEMICOLON,j.QUOTE=a.VK_FR_2u,j.BACKQUOTE=a.VK_FR_U_GRAVE,j.Z=a.VK_FR_Z,j.M=a.VK_FR_M,j.COMMA=a.VK_FR_COMMA,j.PERIOD=a.VK_FR_COLON,j.SLASH=a.VK_FR_EXCLAMATION,j.DEAD=[a.VK_FR_STAR,a.VK_RCONTROL,a.VK_END],j.HOME=[a.VK_HOME,{wc:a.VK_FR_DOLLAR.wc|a.ALT,n:["Alt","$"]}],j.INSERT=[a.VK_INSERT,{wc:a.VK_FR_STAR.wc|a.ALT,n:["Alt","*"]}],j.DELETE=[a.VK_DELETE,{wc:a.VK_FR_EXCLAMATION.wc|a.ALT,n:["Alt","!"]}];var k={};for(d in b)k[d]=b[d];k.OPEN_BRACKET=a.VK_BACKQUOTE,k.CLOSE_BRACKET=a.VK_OPEN_BRACKET,k.BACKQUOTE=a.VK_CLOSE_BRACKET;var l={};for(d in b)l[d]=b[d];l.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_BR_QUOTE.wc|a.ALT,n:["Alt","'"]}],l.BACKSLASH=[a.VK_BR_BACKSLASH,a.VK_INT_YEN],l.OPEN_BRACKET=[a.VK_BR_QUOTE,a.VK_BR_ACUTE],l.CLOSE_BRACKET=a.VK_BR_OPEN_BRACKET,l.SEMICOLON=a.VK_BR_SEMICOLON,l.QUOTE=a.VK_BR_CEDILLA,l.BACKQUOTE=a.VK_BR_CLOSE_BRACKET,l.SLASH=a.VK_BR_SLASH,l.DEAD=[a.VK_BR_TILDE,a.VK_RCONTROL,a.VK_END],l.HOME=[a.VK_HOME,{wc:a.VK_BR_OPEN_BRACKET.wc|a.ALT,n:["Alt","["]}],l.INSERT=[a.VK_INSERT,{wc:a.VK_BR_CLOSE_BRACKET.wc|a.ALT,n:["Alt","]"]}],l.DELETE=[a.VK_DELETE,{wc:a.VK_BR_SLASH.wc|a.ALT,n:["Alt","/"]}];var m={};for(d in b)m[d]=b[d];m.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_JP_YEN.wc|a.ALT,n:["Alt","¥"]}],m.EQUAL=a.VK_JP_CIRCUMFLEX,m.BACKSLASH=[a.VK_JP_YEN,a.VK_INT_BACKSLASH],m.OPEN_BRACKET=a.VK_JP_ARROBA,m.CLOSE_BRACKET=a.VK_JP_OPEN_BRACKET,m.QUOTE=a.VK_JP_COLLON,m.BACKQUOTE=a.VK_JP_CLOSE_BRACKET,m.DEAD=[a.VK_JP_RO,a.VK_RCONTROL,a.VK_END],m.CAPSLOCK=a.VK_JP_NON_CONVERT,m.HOME=[a.VK_HOME,{wc:a.VK_JP_OPEN_BRACKET.wc|a.ALT,n:["Alt","["]}],m.INSERT=[a.VK_INSERT,{wc:a.VK_JP_CLOSE_BRACKET.wc|a.ALT,n:["Alt","]"]}],m.DELETE=[a.VK_DELETE,{wc:a.VK_JP_RO.wc|a.ALT,n:["Alt","\\ ろ"]}];var n={};for(d in b)n[d]=b[d];n.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_ES_ORDINAL.wc|a.ALT,n:["Alt","º"]}],n.MINUS=a.VK_ES_MINUS,n.EQUAL=a.VK_ES_INV_EXCLA,n.BACKSLASH=[a.VK_ES_ORDINAL,a.VK_INT_YEN],
n.OPEN_BRACKET=a.VK_ES_QUOTE,n.CLOSE_BRACKET=a.VK_ES_GRAVE,n.SEMICOLON=a.VK_ES_ENNE,n.QUOTE=a.VK_ES_ACUTE,n.BACKQUOTE=a.VK_ES_PLUS,n.SLASH=a.VK_ES_LESSER,n.DEAD=[a.VK_ES_CEDILLA,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],n.HOME=[a.VK_HOME,{wc:a.VK_ES_GRAVE.wc|a.ALT,n:["Alt","`"]}],n.INSERT=[a.VK_INSERT,{wc:a.VK_ES_PLUS.wc|a.ALT,n:["Alt","+"]}],n.DELETE=[a.VK_DELETE,{wc:a.VK_ES_CEDILLA.wc|a.ALT,n:["Alt","Ç"]}];var o={};for(d in b)o[d]=b[d];o.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_NL_ARROBA.wc|a.ALT,n:["Alt","@"]}],o.MINUS=a.VK_NL_MINUS,o.EQUAL=a.VK_NL_ORDINAL,o.BACKSLASH=[a.VK_NL_CLOSE_BRACKET,a.VK_INT_YEN],o.OPEN_BRACKET=a.VK_NL_ARROBA,o.CLOSE_BRACKET=a.VK_NL_UMLAUT,o.SEMICOLON=a.VK_NL_PLUS,o.QUOTE=a.VK_NL_ACUTE,o.BACKQUOTE=a.VK_NL_STAR,o.SLASH=a.VK_NL_SLASH,o.DEAD=[a.VK_NL_LESSER,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],o.HOME=[a.VK_HOME,{wc:a.VK_NL_UMLAUT.wc|a.ALT,n:["Alt","¨"]}],o.INSERT=[a.VK_INSERT,{wc:a.VK_NL_STAR.wc|a.ALT,n:["Alt","*"]}],o.DELETE=[a.VK_DELETE,{wc:a.VK_NL_LESSER.wc|a.ALT,n:["Alt","<"]}];var p={};for(d in b)p[d]=b[d];p.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_IT_BACKSLASH.wc|a.ALT,n:["Alt","\\"]}],p.MINUS=a.VK_IT_MINUS,p.EQUAL=a.VK_IT_GRAVE_I,p.BACKSLASH=[a.VK_IT_BACKSLASH,a.VK_INT_YEN],p.OPEN_BRACKET=a.VK_IT_QUOTE,p.CLOSE_BRACKET=a.VK_IT_GRAVE_E,p.SEMICOLON=a.VK_IT_GRAVE_O,p.QUOTE=a.VK_IT_GRAVE_A,p.BACKQUOTE=a.VK_IT_PLUS,p.SLASH=a.VK_IT_LESSER,p.DEAD=[a.VK_IT_GRAVE_U,a.VK_INT_RO,a.VK_RCONTROL,a.VK_END],p.HOME=[a.VK_HOME,{wc:a.VK_IT_GRAVE_E.wc|a.ALT,n:["Alt","è"]}],p.INSERT=[a.VK_INSERT,{wc:a.VK_IT_PLUS.wc|a.ALT,n:["Alt","+"]}],p.DELETE=[a.VK_DELETE,{wc:a.VK_IT_GRAVE_U.wc|a.ALT,n:["Alt","ù"]}];var q={};for(d in b)q[d]=b[d];q.ESCAPE=[a.VK_ESCAPE,{wc:a.VK_FR_2u.wc|a.ALT,n:["Alt","²"]}],q.MINUS=a.VK_FR_CLOSE_PARENS,q.EQUAL=a.VK_FR_CIRCUMFLEX,q.BACKSLASH=[a.VK_FR_LESSER,a.VK_INT_YEN],q.Q=a.VK_FR_Q,q.W=a.VK_FR_W,q.OPEN_BRACKET=a.VK_FR_2u,q.CLOSE_BRACKET=a.VK_FR_EQUAL,q.A=a.VK_FR_A,q.SEMICOLON=a.VK_FR_SEMICOLON,q.QUOTE=a.VK_FR_COLON,q.BACKQUOTE=a.VK_FR_DOLLAR,q.Z=a.VK_FR_Z,q.M=a.VK_FR_M,q.COMMA=a.VK_FR_COMMA,q.PERIOD=a.VK_FR_U_GRAVE,q.SLASH=a.VK_FR_EXCLAMATION,q.DEAD=[a.VK_FR_STAR,a.VK_RCONTROL,a.VK_END],q.HOME=[a.VK_HOME,{wc:a.VK_FR_DOLLAR.wc|a.ALT,n:["Alt","$"]}],q.INSERT=[a.VK_INSERT,{wc:a.VK_FR_STAR.wc|a.ALT,n:["Alt","*"]}],q.DELETE=[a.VK_DELETE,{wc:a.VK_FR_EXCLAMATION.wc|a.ALT,n:["Alt","!"]}],wmsx.BuiltInKeyboards={en:{"en-US":c,"pt-BR":e,"ja-JP":f,"es-ES":g,"it-IT":i,"fr-FR":j,"nl-NL":h},ja:{"en-US":k,"pt-BR":l,"ja-JP":m,"es-ES":n,"it-IT":p,"fr-FR":q,"nl-NL":o}}}(),wmsx.DOMKeyboard=function(a,b,c){"use strict";function d(a,c,d){b.netController&&J.push(a<<8|c<<4|d),2!==b.netPlayMode&&e(a,c,d)}function e(a,b,c){c?y[a]&=~(1<<b):y[a]|=1<<b}function f(){C=A>0?A:WMSX.BOOT_DURATION_AUTO}function g(){var a=(wmsx.Util.userLanguage()||"en-US").toUpperCase();"NL"===a.substr(0,2)&&(a="en-US");for(var b=0;b<t.length;++b)if(0===t[b].toUpperCase().indexOf(a))return j.setKeyboard(t[b],!0);for(a=a.substr(0,2),b=0;b<t.length;++b)if(0===t[b].toUpperCase().indexOf(a))return j.setKeyboard(t[b],!0);j.setKeyboard(t[0],!0)}function h(){var a=m+"-CUSTOM";v[a]||(v[a]={},t.push(a));var b=v[a];for(var c in D)b[c]=D[c].slice(0);j.setKeyboard(a,!1)}function i(){u=wmsx.BuiltInKeyboards[w]||{},v=WMSX.userPreferences.current.customHostKeyboards[w]||{},t=Object.keys(u).concat(Object.keys(v));var a=WMSX.userPreferences.current.hostKeyboard[w];t.indexOf(a)>=0?j.setKeyboard(a,!1):g()}var j=this;this.connect=function(a,b){o=a,o.addMachineTypeStateListener(j,!0),p=b},this.connectPeripherals=function(a){q=a},this.resetControllers=function(){this.releaseControllers(),B&&f()},this.machineTypeStateUpdate=function(){var a=o.getMachineLang();a!==w&&(w=a,i())},this.powerOn=function(){if(WMSX.BOOT_KEYS||WMSX.BOOT_KEYS_ONCE){for(var a=(WMSX.BOOT_KEYS||WMSX.BOOT_KEYS_ONCE).split(","),b=[],c=0;c<a.length;++c){var d=a[c].trim().toUpperCase(),e=r[d]||r[N[d]];e&&(b.push(e.key),z[e.m[0]]&=~(1<<e.m[1]))}b.length&&f(),C&&!WMSX.BOOT_KEYS_ONCE&&(B=!0),wmsx.Util.log("Boot Keys"+(B?"":" (once)")+": "+b.join(", "))}},this.powerOff=function(){},this.typeString=function(a){p.keyboardExtensionTypeString(a)},this.cancelTypeString=function(){p.keyboardExtensionCancelTypeString()},this.isShiftPressed=function(){return 0==(1&y[6])},this.controllersClockPulse=function(){if(C>0&&--C,F&&I){if(--G===H||0===G){var a=G>0,b=r.SPACE.m;d(b[0],b[1],a)}G<=0&&(G=F)}},this.readKeyboardPort=function(a){return C>0?y[a]&z[a]:y[a]},this.toggleKeyboardLayout=function(a){var b;b=a?n?t.length-1:t.indexOf(m)-1||0:n?0:t.indexOf(m)+1||0,b<0||b>=t.length?g():this.setKeyboard(t[b],!1),q.showOSD("Host Keyboard: "+this.getCurrentKeyboardDesc(),!0)},this.getCurrentKeyboardDesc=function(){return(n?"AUTO: ":"")+m},this.setKeyboard=function(a,b){m=a,n=b,k(),q&&q.keyboardSettingsStateUpdate();var c=b?void 0:a;WMSX.userPreferences.current.hostKeyboard[w]!==c&&(WMSX.userPreferences.current.hostKeyboard[w]=c,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save())},this.setTurboFireClocks=function(a){F=a,H=F/2|0,G=0},this.releaseControllers=function(){for(var a in x)x[a]&&this.processMSXKey(a,!1);I=!1},this.getKeyMapping=function(a){return D[a]},this.clearKey=function(a){0!==D[a].length&&(v[m]||h(),D[a].length=0,l(),WMSX.userPreferences.setDirty())},this.customizeKey=function(a,b){if(E[b.wc]!==a){v[m]||h();for(var c in D){var d=D[c];if(0!==d.length)for(var e;(e=wmsx.Util.arrayFindIndex(d,function(a){return a.wc===b.wc}))>=0;)d.splice(e,1)}d=D[a],d.length>=M&&d.splice(0,d.length-(M-1)),d.push(b),l(),WMSX.userPreferences.setDirty()}},this.processKey=function(a,b){var e=E[a];if(!e){if(c.processKey(a,b))return;e=E[a&L]}if(e){if(a===K&&x.CONTROL){var f=r.CONTROL.m;d(f[0],f[1],!1)}this.processMSXKey(e,b)}},this.processMSXKey=function(a,b){if(F&&"SPACE"===a){if(I===b)return;b&&(G=H),I=b}if(x[a]!==b){x[a]=b;var c=r[a].m;d(c[0],c[1],b)}};var k=function(){var a=v[m]||u[m];for(var b in r)D[b]=a[b]?a[b].constructor===Array?a[b]:[a[b]]:[];l()},l=function(){E={};for(var a in D)if(0!==D[a].length)for(var b=0;b<D[a].length;++b)E[D[a][b].wc]=a};this.netGetMatrixChangesToSend=function(){return J.length?J:void 0},this.netClearMatrixChangesToSend=function(){J.length=0},this.netServerProcessMatrixChanges=function(a){for(var b=0,c=a.length;b<c;++b){var d=a[b];J.push(d),e(d>>8,(240&d)>>4,1&d)}},this.netClientApplyMatrixChanges=function(a){for(var b=0,c=a.length;b<c;++b)e(a[b]>>8,(240&a[b])>>4,1&a[b])},this.saveState=function(){return{k:wmsx.Util.storeInt8BitArrayToStringBase64(y),kb:wmsx.Util.storeInt8BitArrayToStringBase64(z),bf:A,ba:B,bc:C}},this.loadState=function(a){wmsx.Util.restoreStringBase64ToInt8BitArray(a.k,y),wmsx.Util.restoreStringBase64ToInt8BitArray(a.kb,z),A=a.bf,B=a.ba,C=a.bc};var m,n,o,p,q,r=wmsx.KeyboardKeys,s=wmsx.DOMKeys,t=[],u={},v={},w="en",x={},y=wmsx.Util.arrayFill(new Array(12),255),z=wmsx.Util.arrayFill(new Array(12),255),A=WMSX.BOOT_KEYS_FRAMES,B=!1,C=0,D={},E={},F=0,G=0,H=0,I=!1,J=new Array(100);J.length=0;var K=s.VK_RALT.wc,L=s.IGNORE_ALL_MODIFIERS_MASK,M=4,N={CTRL:"CONTROL",ESC:"ESCAPE",CAPS:"CAPSLOCK",KANA:"CODE",RETURN:"ENTER",RET:"ENTER",0:"D0",1:"D1",2:"D2",3:"D3",4:"D4",5:"D5",6:"D6",7:"D7",8:"D8",9:"D9"};i()},wmsx.GamepadJoysticksControls=function(a,b,c){"use strict";function d(){-2===w?p=q=null:-1===w&&(v=-1,n.controllersClockPulse(!0)),x=0===w,h(),e()}function e(){var a=p?J+" 1":null,c=q?J+" 2":null;b.updateJoystickConnections(x?c:a,x?a:c)}function f(a,c){e(),b.showStatusMessage("Joystick "+(a?"1":"2")+(c?" connected":" disconnected"))}function g(a,b,c){if(c&&0!==c.length){var d=a.settings.device;if(d>=0)return c[d]&&c[d].buttons.length>0?new m(d,a):null;for(var e=0,f=c.length;e<f;e++)if(c[e]&&c[e].buttons.length>0&&!(e===b.device||p&&p.index===e||q&&q.index===e))return new m(e,a)}}function h(){B.reset(),C.reset()}function i(a,b,d){if(d===E)return j(a);var e=b.buttonsState,f=e.J_A;for(var g in t){var h=d.buttons[g];if(h&&h.length>0){
for(var i=!1,k=0;!i&&k<h.length;++k)a.getButtonDigital(h[k].b)&&(i=!0);if(e[g]!==i)if(e[g]=i,t[g].mask)i?b.portValue&=~t[g].mask:b.portValue|=t[g].mask;else{var l=d.virtualButtonsKeys[g];if(l)for(var m=0;m<l.length;++m)c.processKey(l[m].wc,i)}}}if(y&&b.buttonsState.J_A&&!f&&(z=A),!(e.UP||e.DOWN||e.LEFT||e.RIGHT)){var n=a.getStickDirection();n!==b.analogDirection&&(b.analogDirection=n,b.portValue=-16&b.portValue|L[n+1])}}function j(a){for(var b in wmsx.GamepadButtons){var c=wmsx.GamepadButtons[b].b;if(c>=0&&a.getButtonDigital(c))return F.joystickButtonDetected(wmsx.GamepadButtons[b],(E===s?1:0)^x)}}function k(){D[0]=r=WMSX.userPreferences.current.joysticks[0],D[1]=s=WMSX.userPreferences.current.joysticks[1]}function l(){this.reset=function(){this.analogDirection=-1,this.buttonsState={},this.portValue=63,this.pin8Value=0},this.reset()}function m(a,b){this.index=a,this.update=function(b){return!!(c=b[a])},this.hasMoved=function(){var a=c.timestamp;return!a||a>i&&(i=a,!0)},this.getButtonDigital=function(a){var b=c.buttons[a];return"object"==typeof b?b.pressed||b.value>.5:b>.5},this.getStickDirection=function(){var a=c.axes[d],b=c.axes[e];if(isNaN(a)||(a<0?-a:a)<h?a=0:a*=f,isNaN(b)||(b<0?-b:b)<h?b=0:b*=g,0===a&&0===b)return-1;var i=(1-Math.atan2(a,b)/Math.PI)/2;return i+=1/16,i>=1&&(i-=1),8*i|0};var c,d=b.settings.xAxis,e=b.settings.yAxis,f=b.settings.xAxisSig,g=b.settings.yAxisSig,h=b.settings.deadzone,i=Number.MIN_VALUE}var n=this;this.connectPeripherals=function(a){o=a},this.powerOn=function(){(u=!!navigator.getGamepads)&&(k(),w>=-1&&d())},this.powerOff=function(){u=!1},this.releaseControllers=function(){h()},this.resetControllers=function(){this.releaseControllers(),e()},this.readControllerPort=function(c){return a.netController?b.netGetMergedPortValues()[c]:this.readLocalControllerPort(c)},this.readLocalControllerPort=function(a){var b=1===a^x?C:B;return b.pin8Value?63:z>A?16|b.portValue:b.portValue},this.writeControllerPin8Port=function(a,b){(1===a^x?C:B).pin8Value=b},this.toggleMode=function(c){if(!u)return void b.showErrorMessage("Joysticks unavailable (not supported by browser)");var d=(2!==a.netPlayMode||G?H:I)[c?1:0][w+2];this.setMode(d),b.showStatusMessage("Joysticks "+this.getModeDesc())},this.setMode=function(a){w=a,d()},this.getMode=function(){return w},this.getModeDesc=function(){switch(w){case-1:return"AUTO";case 0:return"AUTO (swapped)";default:return u?"DISABLED":"NOT SUPPORTED"}},this.getSwappedState=function(){return x},this.netClientAdaptToServerControlsModes=function(a){G=a.sw,-2!==w&&(-1!==w||G?0===w&&G&&this.setMode(-1):this.setMode(0))},this.setTurboFireClocks=function(a){y=a,A=y/2|0,z=0},this.controllersClockPulse=function(a){if(u&&-2!==w&&(++v>=K&&(v=0),p||q||0===v)){var b=navigator.getGamepads();y&&--z<=0&&(z=y),p?p.update(b)?p.hasMoved()&&i(p,B,r):(p=null,B.reset(),a||f(!0,!1)):0===v&&(p=g(r,s,b))&&!a&&f(!0,!0),q?q.update(b)?q.hasMoved()&&i(q,C,s):(q=null,C.reset(),a||f(!1,!1)):0===v&&(q=g(s,r,b))&&!a&&f(!1,!0)}},this.getMappingForControl=function(a,b){var c=D[b^x];return t[a].mask?c.buttons[a]:0!==c.buttons[a].length||0!==c.virtualButtonsKeys[a].length?{from:c.buttons[a],to:c.virtualButtonsKeys[a]}:[]},this.getMappingPopupText=function(a,b){var c=!t[a].mask;return{heading:c?"Virtual Button mapping:":"Button mapped to host buttons:",footer:c?"Press new button / key.<br>(right-click to clear)":"Press new button.<br>(right-click to clear)"}},this.customizeControl=function(a,b,c){var d;if(c.wc){if(c.wc&&t[a].mask)return;if(d=D[b^x].virtualButtonsKeys[a],wmsx.Util.arrayFind(d,function(a){return a.wc===c.wc}))return}else if(d=D[b^x].buttons[a],wmsx.Util.arrayFind(d,function(a){return a.b===c.b}))return;d.length>=M&&d.splice(0,d.length-(M-1)),d.push(c),h(),WMSX.userPreferences.setDirty()},this.clearControl=function(a,b){D[b^x].buttons[a].length=0,t[a].mask||(D[b^x].virtualButtonsKeys[a].length=0),h(),WMSX.userPreferences.setDirty()},this.startButtonDetection=function(a,b){E=D[a^x],F=b},this.stopButtonDetection=function(){E=F=null};var o,p,q,r,s,t=wmsx.JoystickButtons,u=!1,v=1,w=WMSX.JOYSTICKS_MODE-1,x=!1,y=0,z=0,A=0,B=new l,C=new l,D=[],E=null,F=null,G=!1,H=[[-1,0,-2],[0,-2,-1]],I=[[0,-2,-1],[-1,0,-2]],J=wmsx.ControllersHub.JOYSTICK,K=60,L=[15,14,6,7,5,13,9,11,10],M=4},wmsx.DOMJoykeysControls=function(a,b,c){"use strict";function d(){p=1===o||3===o,h(),g(),e()}function e(){q={},o>=0&&f(l.buttons,0),o>=2&&f(m.buttons,1)}function f(a,b){for(var c in a)for(var d=0;d<a[c].length;++d)q[a[c][d].wc]||(q[a[c][d].wc]=[]),q[a[c][d].wc].push({b:c,p:b})}function g(){var a=o>=0?C+" 1":null,c=o>=2?C+" 2":null;b.updateJoykeysConnections(p?c:a,p?a:c)}function h(){s.reset(),t.reset()}function i(){y[0]=l=WMSX.userPreferences.current.joykeys[0],y[1]=m=WMSX.userPreferences.current.joykeys[1]}function j(){this.reset=function(){this.portValue=63,this.pin8Value=0},this.reset()}this.connectPeripherals=function(a){k=a},this.powerOn=function(){i(),o>=0&&d()},this.powerOff=function(){},this.releaseControllers=function(){h()},this.resetControllers=function(){this.releaseControllers(),g()},this.readControllerPort=function(c){return a.netController?b.netGetMergedPortValues()[c]:this.readLocalControllerPort(c)},this.readLocalControllerPort=function(a){var b=u[a^p];return b.pin8Value?63:w>x?16|b.portValue:b.portValue},this.writeControllerPin8Port=function(a,b){u[a^p].pin8Value=b},this.controllersClockPulse=function(){o>=0&&v&&--w<=0&&(w=v)},this.toggleMode=function(c){var d=(2!==a.netPlayMode||z?A:B)[c?1:0][o+1];this.setMode(d),b.showStatusMessage("Joykeys "+this.getModeDesc())},this.setMode=function(a){a>=0&&o<0&&(r={}),o=a,d()},this.getMode=function(){return o},this.getModeDesc=function(){switch(o){case 0:return"SINGLE";case 1:return"SINGLE (port 2)";case 2:return"DUAL";case 3:return"DUAL (swapped)";default:return"DISABLED"}},this.getSwappedState=function(){return p},this.netClientAdaptToServerControlsModes=function(a){z=a.sw,-1!==o&&(z?1===o?this.setMode(0):3===o&&this.setMode(2):0===o?this.setMode(1):2===o&&this.setMode(3))},this.setTurboFireClocks=function(a){v=a,x=v/2|0,w=0},this.processKey=function(a,b){if(o<0)return c.processKey(a,b);var d=q[a];if(!d)return c.processKey(a,b);if(r[a]===b)return void(b||c.processKey(a,b));r[a]=b;for(var e=0;e<d.length;++e)b?(u[d[e].p].portValue&=~n[d[e].b].mask,v&&"J_A"===d[e].b&&(w=x+1)):u[d[e].p].portValue|=n[d[e].b].mask;b||c.processKey(a,b)},this.getMappingForControl=function(a,b){return y[b^p].buttons[a]},this.getMappingPopupText=function(a,b){return{heading:"Button mapped to host keys:",footer:"Press new key.<br>(right-click to clear)"}},this.customizeControl=function(a,b,c){if(!q[c.wc]||!wmsx.Util.arrayFind(q[c.wc],function(c){return c.b===a&&c.p===b})){var d=y[b^p].buttons[a];d.length>=D&&d.splice(0,d.length-(D-1)),d.push(c),h(),e(),WMSX.userPreferences.setDirty()}},this.clearControl=function(a,b){y[b^p].buttons[a].length=0,h(),e(),WMSX.userPreferences.setDirty()};var k,l,m,n=wmsx.JoystickButtons,o=WMSX.JOYKEYS_MODE,p=!1,q={},r={},s=new j,t=new j,u=[s,t],v=0,w=0,x=0,y=[],z=!1,A=[[0,1,2,3,-1],[3,-1,0,1,2]],B=[[1,3,0,-1,2],[2,1,-1,3,0]],C=wmsx.ControllersHub.JOYKEYS,D=4},wmsx.DOMMouseControls=function(a,b){"use strict";function c(a){C=void 0!==a?a:B<0?-1:B,z?q(y):p(x),n()}function d(a){return a===C?y.portValue:b.portValueAllReleased}function e(){if(G=!1,C<0)return w.showOSD("Mouse Pointer Locking only when MOUSE is ENABLED!",!0,!0);var a=t.requestPointerLock||t.mozRequestPointerLock||t.webkitRequestPointerLock;a&&a.apply(t)}function f(){G=!1;var a=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock;a&&a.apply(document)}function g(){x.portValue=-49&x.portValue|(3&~x.buttons)<<4}function h(){switch(x.readCycle){case 0:x.portValue=-16&x.portValue|x.readDX>>4&15;break;case 1:x.portValue=-16&x.portValue|15&x.readDX;break;case 2:x.portValue=-16&x.portValue|x.readDY>>4&15;break;case 3:
x.portValue=-16&x.portValue|15&x.readDY;break;default:x.portValue=-16&x.portValue}}function i(){var a=Math.round(-x.dX);a>127?a=127:a<-127&&(a=-127),x.dX+=a,x.readDX=a;var b=Math.round(-x.dY);b>127?b=127:b<-127&&(b=-127),x.dY+=b,x.readDY=b}function j(a){if(!(C<0)){a.preventDefault();var b=0,c=0;F?(b=a.movementX||a.mozMovementX||a.webkitMovementX||0,c=a.movementY||a.mozMovementY||a.webkitMovementY||0):u&&(b=a.clientX-u.clientX,c=a.clientY-u.clientY),u=a,y.dX+=b/D,y.dY+=c/E,A=y}}function k(a){if(4&a.buttons&&(a.preventDefault(),s.togglePointerLock()),C>=0){if(G&&a.buttons)return 1&a.buttons&&!F&&e(),void(G=!1);y.buttons=3&a.buttons,z||g(),A=y}}function l(){var a=document.pointerLockElement||document.mozPointerLockElement||document.webkitPointerLockElement;F=a===t,w.mousePointerLocked(F),w.showOSD(F?"Mouse Pointer Locked":"Mouse Pointer Released",F)}function m(a,b){C=a,s.writeControllerPin8Port(C,b),n(),o("Mouse AUTO-ENABLED")}function n(){F&&C<0&&f(),b.updateMouseConnections(0===C?I:null,1===C?I:null),w.mouseActiveCursorStateUpdate(C>=0)}function o(a){b.showStatusMessage(a)}function p(a){return a.readCycle=-1,a.dX=0,a.dY=0,a.buttons=0,a.portValue=b.portValueAllReleased,a.pin8Value=0,a.lastPin8FlipBUSCycle=0,a.readDX=0,a.readDY=0,A=x,a}function q(a){return a.dX=0,a.dY=0,a.buttons=void 0,A=void 0,a}function r(a){return a===C?x.portValue:b.portValueAllReleased}var s=this;this.connect=function(a){v=a},this.connectPeripherals=function(a){w=a},this.powerOn=function(){c()},this.powerOff=function(){},this.releaseControllers=function(){C>=0&&(z?q(y):p(x))},this.resetControllers=function(){this.releaseControllers(),-1===B&&(C=-1),n()},this.screenFullscreenStateUpdate=function(a){G=a&&!F},this.toggleMode=function(a){var b;a?(b=B-1)<-2&&(b=1):(b=B+1)>1&&(b=-2),this.setMode(b),o("Mouse "+this.getModeDesc())},this.setMode=function(a){B=a,c()},this.setModeEffective=function(a){B=a.m,c(a.p)},this.getMode=function(){return B},this.getModeEffective=function(){return{m:B,p:C}},this.getModeDesc=function(){switch(B){case-1:return"AUTO";case 0:return"ENABLED";case 1:return"ENABLED (port 2)";default:return"DISABLED"}},this.netClientAdaptToServerControlsModes=function(a){this.setModeEffective(a.m)},this.readControllerPort=function(b){return a.netController?r(b):d(b)},this.writeControllerPin8Port=function(a,b){if(a===C){if(x.pin8Value^b){x.pin8Value=b;var c=v.getBUSCycles()-x.lastPin8FlipBUSCycle;x.lastPin8FlipBUSCycle+=c,c>J&&(x.readCycle=-1),++x.readCycle,0===x.readCycle&&i(),h()}}},this.portPin8Announced=function(a,b){1===b&&!H&&C<0&&0===a&&-1===B&&m(a,b)},this.togglePointerLock=function(){F?f():e()},this.setMouseInputElement=function(a){t=a,"onpointerlockchange"in document?document.addEventListener("pointerlockchange",l,!1):"onmozpointerlockchange"in document&&document.addEventListener("mozpointerlockchange",l,!1),t.addEventListener("mousemove",j),t.addEventListener("mousedown",k),t.addEventListener("mouseup",k)},this.setScreenPixelScale=function(a,b){D=a,E=b},this.getMappingForControl=function(a,b){return[{wc:999999,n:["Alt","CapsLock"]}]},this.getMappingPopupText=function(a,b){return{heading:"Lock / Unlock pointer:",footer:"or click Middle Button"}},this.customizeControl=function(a,b,c){},this.clearControl=function(a,b){},this.netGetMouseStateToSend=function(){return A},this.netClearMouseInfoToSend=function(){z?q(y):A=void 0},this.netServerGetMouseState=function(){return x},this.netServerReceiveClientMouseState=function(a){x.dX+=a.dX,x.dY+=a.dY,void 0!==a.buttons&&(x.buttons=a.buttons,g()),A=x},this.netClientReceiveServerMouseState=function(a){x=a},this.netSetClientMode=function(a){z=a,y=a?q({}):x};var t,u,v,w,x=p({}),y=x,z=!1,A=void 0,B=WMSX.MOUSE_MODE-1,C=-1,D=1,E=1,F=!1,G=!1,H=wmsx.Util.isMobileDevice(),I=wmsx.ControllersHub.MOUSE,J=wmsx.CPU.BASE_CLOCK/1e3*1.5|0},wmsx.DOMTouchControls=function(a,b,c,d){"use strict";function e(){C.classList.toggle("wmsx-poweroff",!V),C.classList.toggle("wmsx-paused",W)}function f(){J=-2===I?-1:-1===I?G&&H?0:-1:I,v(),u()}function g(a){if(wmsx.Util.blockEvent(a),E)return E.touchControlDetected("T_DIR",a)}function h(a){if(wmsx.Util.blockEvent(a),E)return E.touchControlDetected("T_DIR",a);if(null===Q){void 0===A&&m();var b=a.changedTouches[0];Q=b.identifier,k(b.pageX,b.pageY)}}function i(a){wmsx.Util.blockEvent(a),null!==Q&&(Q=null,l(-1))}function j(a){if(wmsx.Util.blockEvent(a),null!==Q)for(var b=a.changedTouches,c=0;c<b.length;++c)if(b[c].identifier===Q)return void k(b[c].pageX,b[c].pageY)}function k(a,b){var c=-1,d=a-A,e=b-B;Math.sqrt(d*d+e*e)>S&&(c=(1-Math.atan2(d,e)/Math.PI)/2,c+=1/16,c>=1&&(c-=1),c=8*c|0),l(c)}function l(a){if(R!==a){if(P.wmsxMappingIsKeys){var d=Z[R+1];d[0]&&c.processMSXKey(d[0],!1),d[1]&&c.processMSXKey(d[1],!1);var e=Z[a+1];e[0]&&c.processMSXKey(e[0],!0),e[1]&&c.processMSXKey(e[1],!0)}else U.portValue=-16&U.portValue|Y[a+1];a>=0&&b.hapticFeedback(),R=a}}function m(){var a=P.getBoundingClientRect();S=.14*(a.right-a.left)|0,A=((a.left+a.right)/2|0)+window.pageXOffset,B=((a.top+a.bottom)/2|0)+window.pageYOffset}function n(a){if(wmsx.Util.blockEvent(a),E)return E.touchControlDetected(a.target.wmsxControl,a);p(a.target.wmsxMapping,!0)}function o(a){wmsx.Util.blockEvent(a),p(a.target.wmsxMapping,!1)}function p(a,d){a&&(d&&b.hapticFeedback(),a.button?d?(U.portValue&=~a.mask,K&&16&a.mask&&(L=M+1)):U.portValue|=a.mask:a.key&&c.processMSXKey(a.key,d))}function q(a){wmsx.Util.blockEvent(a),b.hapticFeedback(),d.processControlState(V?F.PAUSE:F.POWER,!0)}function r(a){wmsx.Util.blockEvent(a),b.hapticFeedback(),d.processControlState(W?F.FRAME:F.FAST_SPEED,!0)}function s(a){wmsx.Util.blockEvent(a),W||(b.hapticFeedback(),d.processControlState(W?F.FRAME:F.FAST_SPEED,!1))}function t(){y.updateMappingFor("T_DIR");for(var a in T)y.updateMappingFor(a)}function u(){b.updateTouchControlsConnections(0===J?X:null,1===J?X:null)}function v(){U.reset(),A=B=void 0,Q=null,l(-1)}function w(){D=WMSX.userPreferences.current.touch,N=!!D.directionalBig,O=!!D.mirrored}function x(){this.reset=function(){this.portValue=63,this.pin8Value=0},this.reset()}var y=this;this.connect=function(a){a.addPowerAndUserPauseStateListener(this)},this.connectPeripherals=function(a){z=a},this.powerOn=function(){w(),f()},this.powerOff=function(){},this.releaseControllers=function(){v()},this.resetControllers=function(){this.releaseControllers(),u()},this.readControllerPort=function(c){return a.netController?b.netGetMergedPortValues()[c]:this.readLocalControllerPort(c)},this.readLocalControllerPort=function(a){return a===J?U.pin8Value?63:L>M?16|U.portValue:U.portValue:63},this.writeControllerPin8Port=function(a,b){a===J&&(U.pin8Value=b)},this.controllersClockPulse=function(){J>=0&&K&&--L<=0&&(L=K)},this.toggleMode=function(a,c){if(!G)return void b.showErrorMessage("Touch Controls unavailable. Not a touch device!");var d;c?(d=a?J<0?1:0===J?-2:I-1:I-1)<-2&&(d=1):(d=a?0===J?1:-2===I?0:I+1:I+1)>1&&(d=-2),this.setMode(d),b.showStatusMessage("Touch Controls "+this.getModeDesc())},this.setMode=function(a){I=a,f()},this.getMode=function(){return I},this.getModeDesc=function(){switch(I){case-1:return"AUTO";case 0:return"ENABLED";case 1:return"ENABLED (port 2)";default:return G?"DISABLED":"NOT SUPPORTED"}},this.getSwappedState=function(){return 1===J},this.netClientAdaptToServerControlsModes=function(a){-1!==J&&(0!==J||a.sw?1===J&&a.sw&&this.setMode(0):this.setMode(1))},this.toggleDirBig=function(){N=!N,D.directionalBig=N,WMSX.userPreferences.setDirty(),this.controllersSettingsStateUpdate()},this.toggleMirrored=function(){O=!O,D.mirrored=O,WMSX.userPreferences.setDirty(),this.controllersSettingsStateUpdate()},this.isDirBig=function(){return N},this.isMirrored=function(){return O},this.getPortActive=function(){return J},this.setTurboFireClocks=function(a){K=a,M=K/2|0,L=0},this.getMappingForControl=function(a,b){return null},this.screenReadjustedUpdate=function(){
this.releaseControllers()},this.setupTouchControlsIfNeeded=function(a){function b(a,b){var c=wmsx.DOMTouchControls.createButton("wmsx-touch-"+b);c.wmsxControl=b,c.addEventListener("touchstart",n),c.addEventListener("touchmove",wmsx.Util.blockEvent),c.addEventListener("touchend",o),c.addEventListener("touchcancel",o),c.addEventListener("mousedown",n),c.addEventListener("mouseup",o),T[b]=c,a.appendChild(c)}if(!(P||J<0)){C=document.createElement("div"),C.id="wmsx-touch-speed";var c=document.createElement("div");c.id="wmsx-touch-pause",c.addEventListener("touchstart",q),c.addEventListener("mousedown",q),C.appendChild(c);var d=document.createElement("div");d.id="wmsx-touch-fast",d.addEventListener("touchstart",r),d.addEventListener("touchend",s),d.addEventListener("mousedown",r),d.addEventListener("mouseup",s),C.appendChild(d),a.appendChild(C);var f=document.createElement("div");f.id="wmsx-touch-left",b(f,wmsx.TouchControls.buttonsLeftSide[0]),P=wmsx.DOMTouchControls.createDirectional(),P.addEventListener("touchstart",h),P.addEventListener("touchmove",j),P.addEventListener("touchend",i),P.addEventListener("touchcancel",i),P.addEventListener("mousedown",g),f.appendChild(P),b(f,wmsx.TouchControls.buttonsLeftSide[1]),a.appendChild(f),f=document.createElement("div"),f.id="wmsx-touch-right";var k=wmsx.TouchControls.buttonsRightSide;for(var l in k)b(f,k[l]);a.appendChild(f),e(),t()}},this.startTouchDetection=function(a){E=a},this.stopTouchDetection=function(){E=null},this.customizeControl=function(a,b){"T_DIR"===a?D.directional=b:D.buttons[a]=b,this.updateMappingFor(a),WMSX.userPreferences.setDirty()},this.updateMappingFor=function(a){if("T_DIR"===a)P.wmsxMappingIsKeys="KEYBOARD"===D.directional,wmsx.DOMTouchControls.styleDirectionalMapping(P,D.directional);else{var b=T[a],c=D.buttons[a];b.wmsxMapping=c,wmsx.DOMTouchControls.styleButtonMapping(b,c)}},this.controllersSettingsStateUpdate=function(){var a=!!b.getSettingsState().touchActive;document.documentElement.classList.toggle("wmsx-touch-active",a),document.documentElement.classList.toggle("wmsx-dir-big",N),document.documentElement.classList.toggle("wmsx-touch-mirror",O),z.touchControlsActiveUpdate(a,N,O)},this.machinePowerAndUserPauseStateUpdate=function(a,b){V=a,W=b,C&&e()};var z,A,B,C,D,E,F=wmsx.MachineControls,G=wmsx.Util.isTouchDevice(),H=wmsx.Util.isMobileDevice(),I=WMSX.TOUCH_MODE>=1?WMSX.TOUCH_MODE-1:G?-1:-2,J=-1,K=0,L=0,M=0,N=!1,O=!1,P=null,Q=null,R=-1,S=0,T={},U=new x,V=!1,W=!1,X=wmsx.ControllersHub.TOUCH,Y=[15,14,6,7,5,13,9,11,10],Z=[[],["UP"],["RIGHT","UP"],["RIGHT"],["RIGHT","DOWN"],["DOWN"],["LEFT","DOWN"],["LEFT"],["LEFT","UP"]];this.saveState=function(){return{p:D}},this.loadState=function(a){if(v(),a.p){delete a.p.directionalBig,delete a.p.mirrored;for(var b in a.p)D[b]=a.p[b];for(var c in D.buttons){var d=D.buttons[c];d&&d.sn&&!d.c_en&&(d.c_en=d.sn)}P&&t()}}},wmsx.DOMTouchControls.createDirectional=function(a){function b(a){var b=document.createElement("div");b.classList.add("wmsx-touch-dir-"+a),c.appendChild(b);var d=document.createElement("div");d.classList.add("wmsx-arrow-"+a),c.appendChild(d)}var c=document.createElement("div");return a&&(c.id=a),c.classList.add("wmsx-touch-dir"),b("left"),b("right"),b("up"),b("down"),c},wmsx.DOMTouchControls.createButton=function(a){var b=document.createElement("div");return a&&(b.id=a),b.classList.add("wmsx-touch-button"),b},wmsx.DOMTouchControls.styleDirectionalMapping=function(a,b){a.classList.toggle("wmsx-touch-dir-key","KEYBOARD"===b),a.classList.toggle("wmsx-touch-dir-joy","KEYBOARD"!==b)},wmsx.DOMTouchControls.styleButtonMapping=function(a,b){if(a.innerHTML=b?b.n||b.c_en:"",b)if(b.button){a.classList.add("wmsx-touch-button-joy"),a.classList.remove("wmsx-touch-button-key","wmsx-touch-button-none");for(var c=["A","B","AB"],d=0;d<c.length;++d)b&&b.n===c[d]?a.classList.add("wmsx-touch-button-joy-"+c[d]):a.classList.remove("wmsx-touch-button-joy-"+c[d])}else b.key&&(a.classList.add("wmsx-touch-button-key"),a.classList.remove("wmsx-touch-button-joy","wmsx-touch-button-none"));else a.classList.add("wmsx-touch-button-none"),a.classList.remove("wmsx-touch-button-joy","wmsx-touch-button-key")},wmsx.ControllersHub=function(a,b){"use strict";function c(a){var b=j[a];return b&&b!==q?b.readLocalControllerPort(a)|y:z}function d(){for(var a=0;a<=1;++a)k[a]?j[a]=q:l[a]?j[a]=r:m[a]?j[a]=s:n[a]?j[a]=t:j[a]=null;t.controllersSettingsStateUpdate(),B.controllersSettingsStateUpdate()}function e(){var a=c(0),b=c(1);D[0]===a&&D[1]===b||(D[0]=a,D[1]=b,A=D)}function f(){if(F){g.netServerClearClientsMergedInfo();var b=a.netController.clients;for(var d in b){var e=b[d].controllersPortValues;e&&(E[0]&=e[0],E[1]&=e[1])}}var f=c(0)&E[0],h=c(1)&E[1];C[0]===f&&C[1]===h||(C[0]=f,C[1]=h,A=C)}var g=this;this.connect=function(a,b,c,d){c.connectControls(this),p.connect(a,d),q.connect(c),t.connect(b)},this.connectPeripherals=function(a){B=a,p.connectPeripherals(B),q.connectPeripherals(B),r.connectPeripherals(B),s.connectPeripherals(B),t.connectPeripherals(B)},this.powerOn=function(){p.powerOn(),q.powerOn(),r.powerOn(),s.powerOn(),t.powerOn()},this.powerOff=function(){p.powerOff(),q.powerOff(),r.powerOff(),s.powerOff(),t.powerOff()},this.getKeyboard=function(){return p},this.getTouchControls=function(){return t},this.releaseControllers=function(){p.releaseControllers(),r.releaseControllers(),s.releaseControllers(),q.releaseControllers(),t.releaseControllers()},this.resetControllers=function(){p.resetControllers(),r.resetControllers(),s.resetControllers(),q.resetControllers()},this.roomNetPlayStatusChangeUpdate=function(b){q.netSetClientMode(2===a.netPlayMode)},this.readKeyboardPort=function(a){return p.readKeyboardPort(a)},this.readControllerPort=function(a){var b=j[a];return b?b.readControllerPort(a):this.netGetMergedPortValues()[a]},this.writeControllerPin8Port=function(a,b){q.portPin8Announced(a,b);var c=j[a];c&&c.writeControllerPin8Port(a,b)},this.controllersClockPulse=function(){p.controllersClockPulse(),s.controllersClockPulse(),r.controllersClockPulse(),t.controllersClockPulse(),1===a.netPlayMode?f():2===a.netPlayMode&&e()},this.toggleKeyboardLayout=function(a){p.toggleKeyboardLayout(a)},this.toggleJoystickMode=function(a){r.toggleMode(a)},this.toggleJoykeysMode=function(a){s.toggleMode(a)},this.toggleMouseMode=function(a){q.toggleMode(a)},this.toggleMouseLock=function(){q.togglePointerLock()},this.toggleTouchControlsMode=function(a,b){t.toggleMode(a,b)},this.toggleHapticFeedback=function(){w?(x=!x,WMSX.userPreferences.current.hapticFeedback=x,WMSX.userPreferences.setDirty()):this.showErrorMessage("Haptic Feedback not available")},this.toggleTurboFireSpeed=function(a){u+=a?-1:1,u=u>=0?u%11:11+u;var b=u?60/v[u]|0:0;p.setTurboFireClocks(b),r.setTurboFireClocks(b),s.setTurboFireClocks(b),t.setTurboFireClocks(b),B.controllersSettingsStateUpdate(),B.showOSD("Turbo Fire"+(u?" speed: "+this.getTurboFireSpeedDesc():": OFF"),!0)},this.getTurboFireSpeedDesc=function(){return u?u+"x":"OFF"},this.getControlReport=function(a){switch(a){case wmsx.PeripheralControls.TOUCH_TOGGLE_DIR_BIG:var b=t.isDirBig();return{label:b?"ON":"OFF",active:b};case wmsx.PeripheralControls.TOUCH_TOGGLE_MIRRORED:var c=t.isMirrored();return{label:c?"ON":"OFF",active:c};case wmsx.PeripheralControls.HAPTIC_FEEDBACK_TOGGLE_MODE:return{label:x?"ON":"OFF",active:!!x};case wmsx.PeripheralControls.TURBO_FIRE_TOGGLE:return{label:this.getTurboFireSpeedDesc(),active:!!u}}return{label:"Unknown",active:!1}},this.setupTouchControlsIfNeeded=function(a){t.setupTouchControlsIfNeeded(a)},this.addKeyInputElement=function(a){a.addEventListener("keydown",this.keyDown),a.addEventListener("keyup",this.keyUp)},this.screenReadjustedUpdate=function(){t.screenReadjustedUpdate()},this.screenFullscreenStateUpdate=function(a){q.screenFullscreenStateUpdate(a)},this.keyDown=function(a){return h(a,!0)},this.keyUp=function(a){return h(a,!1)},
this.setMouseInputElement=function(a){q.setMouseInputElement(a)},this.setScreenPixelScale=function(a,b){q.setScreenPixelScale(a,b)},this.updateMouseConnections=function(a,b){k[0]=a,k[1]=b,d()},this.updateJoystickConnections=function(a,b){l[0]=a,l[1]=b,d()},this.updateJoykeysConnections=function(a,b){m[0]=a,m[1]=b,d()},this.updateTouchControlsConnections=function(a,b){n[0]=a,n[1]=b,d()},this.showStatusMessage=function(a){var b=k[0]||l[0]||m[0]||n[0]||"&nbsp-&nbsp-&nbsp&nbsp",c=k[1]||l[1]||m[1]||n[1]||"&nbsp-&nbsp-&nbsp&nbsp";B.showOSD((a?a+".&nbsp&nbsp":"")+"Port 1:&nbsp&nbsp"+b+",&nbsp&nbspPort 2:&nbsp&nbsp"+c,!0)},this.showErrorMessage=function(a){B.showOSD(a,!0,!0)},this.getSettingsState=function(){return o.mouseModeDesc=q.getModeDesc(),o.joysticksModeDesc=r.getModeDesc(),o.joykeysModeDesc=s.getModeDesc(),o.touchPortSet=t.getPortActive(),o.touchActive=j[0]===t||j[1]===t,o.ports[0]=k[0]||l[0]||m[0]||n[0]||wmsx.ControllersHub.NONE,o.ports[1]=k[1]||l[1]||m[1]||n[1]||wmsx.ControllersHub.NONE,o.turboFireSpeedDesc=this.getTurboFireSpeedDesc(),o},this.getMappingForControl=function(a,b){return j[b]&&j[b].getMappingForControl(a,b)},this.getMappingPopupText=function(a,b){return j[b]&&j[b].getMappingPopupText(a,b)},this.mappingPopupVisibility=function(a,b,c){c&&j[b]===r?r.startButtonDetection(b,a):r.stopButtonDetection()},this.customizeControl=function(a,b,c){j[b].customizeControl(a,b,c)},this.clearControl=function(a,b){return j[b].clearControl(a,b)},this.hapticFeedback=function(){x&&navigator.vibrate(8)},this.hapticFeedbackOnTouch=function(a){!x||"touchstart"!==a.type&&"touchend"!==a.type&&"touchmove"!==a.type||navigator.vibrate(8)};var h=function(a,b){a.returnValue=!1,a.preventDefault(),a.stopPropagation();var c=i.codeNewForKeyboardEvent(a);return s.processKey(c,b),!1};this.netGetInfoToSend=function(){var a=q.netGetMouseStateToSend();return a||A?{m:a,p:A}:void 0},this.netClearInfoToSend=function(){A=void 0,q.netClearMouseInfoToSend()},this.netServerGetFullInfo=function(){return{m:q.netServerGetMouseState(),p:C}},this.netGetMergedPortValues=function(){return C},this.netClientReceiveServerInfo=function(a){a.m&&q.netClientReceiveServerMouseState(a.m);var b=a.p;b&&(C[0]=b[0],C[1]=b[1])},this.netServerReceiveClientInfo=function(a,b){b.m&&q.netServerReceiveClientMouseState(b.m);var c=b.p;c&&(F=!0,a.controllersPortValues=c[0]!==z||c[1]!==z?c:void 0)},this.netServerClearClientsMergedInfo=function(){E[0]=z,E[1]=z,F=!1},this.netServerGetControlsModes=function(){return{m:q.getModeEffective(),sw:s.getSwappedState()||r.getSwappedState()||t.getSwappedState()}},this.netClientGetControlsModes=function(){return{k:s.getMode(),j:r.getMode(),m:q.getModeEffective(),t:t.getMode()}},this.netClientRestoreControlsModes=function(a){s.setMode(a.k),r.setMode(a.j),q.setModeEffective(a.m),t.setMode(a.t)},this.netClientAdaptToServerControlsModes=function(a){s.netClientAdaptToServerControlsModes(a),r.netClientAdaptToServerControlsModes(a),q.netClientAdaptToServerControlsModes(a),t.netClientAdaptToServerControlsModes(a)},this.saveState=function(){return{jk:y,t:t.saveState(),h:x}},this.loadState=function(a){void 0!==a.jk&&(y=a.jk,z=63|y,this.portValueAllReleased=z),a.t&&t.loadState(a.t),void 0!==a.h&&(x=a.h&&w)};var i=wmsx.DOMKeys,j=[null,null],k=[null,null],l=[null,null],m=[null,null],n=[null,null],o={ports:[null,null]},p=new wmsx.DOMKeyboard(this,a,b),q=new wmsx.DOMMouseControls(a,this),r=new wmsx.GamepadJoysticksControls(a,this,p),s=new wmsx.DOMJoykeysControls(a,this,p),t=new wmsx.DOMTouchControls(a,this,p,b),u=0,v=[0,2,2.4,3,4,5,6,7.5,10,12,15],w=!!navigator.vibrate,x=w&&!!WMSX.userPreferences.current.hapticFeedback,y=0!==WMSX.KEYBOARD_JAPAN_LAYOUT?64:0,z=63|y;this.portValueAllReleased=z;var A,B,C=[z,z],D=[z,z],E=[z,z],F=!1;wmsx.ControllersHub.hapticFeedback=this.hapticFeedback,wmsx.ControllersHub.hapticFeedbackOnTouch=this.hapticFeedbackOnTouch},wmsx.ControllersHub.MOUSE="MOUSE",wmsx.ControllersHub.JOYSTICK="JOYSTICK",wmsx.ControllersHub.JOYKEYS="JOYKEYS",wmsx.ControllersHub.TOUCH="TOUCH",wmsx.ControllersHub.JOY_ANY="JOY",wmsx.ControllersHub.NONE="NO DEVICE",wmsx.DOMMachineControls=function(a,b){"use strict";function c(b,c,e,f){if(2===a.netPlayMode&&(T.has(b)||U.has(b)))return a.showOSD("Function not available in NetPlay Client mode",!0,!0);1===a.netPlayMode&&T.has(b)||n.push({c:b<<4|e<<1|c,d:f}),2!==a.netPlayMode&&d(b,c,e,f)}function d(a,b,c,d){g.controlStateChanged(a,b,c,d),S.has(a)&&h.quickOptionsControlsStateUpdate()}this.connect=function(a){g=a},this.connectPeripherals=function(a){h=a},this.powerOn=function(){e()},this.powerOff=function(){},this.processKey=function(a,d){var e=a&R,f=k[e];return!f||m[a]?b.processKey(a,d):d===l[e]||(l[e]=d,c(f,d,e!==a),!0)},this.processControlState=c,this.getControlReport=function(a){return g.getControlReport(a)};var e=function(){window.onhelp=function(){return!1}},f=function(){var a=i;k[o]=j.POWER,k[o|a.ALT]=j.POWER,k[u|a.CONTROL]=j.PAUSE_CPU,k[u|a.CONTROL|a.ALT]=j.PAUSE_CPU,k[v|a.CONTROL|a.ALT]=j.PAUSE_CPU,k[p]=j.FAST_SPEED,k[p|a.ALT]=j.FAST_SPEED,k[q|a.ALT]=j.INC_SPEED,k[r|a.ALT]=j.DEC_SPEED,k[s|a.ALT]=j.NORMAL_SPEED,k[t|a.ALT]=j.MIN_SPEED,m[q|a.ALT]=!0,m[r|a.ALT]=!0,m[s|a.ALT]=!0,m[t|a.ALT]=!0,k[u]=j.PAUSE,k[u|a.ALT]=j.PAUSE,k[v|a.ALT]=j.PAUSE,k[w|a.ALT]=j.FRAME,k[x|a.ALT]=j.FRAME,k[y|a.ALT]=j.DEBUG,k[z|a.ALT]=j.SPRITE_MODE,k[A|a.ALT]=j.VIDEO_STANDARD,k[B|a.ALT]=j.CPU_CLOCK_MODE,k[C|a.ALT]=j.VDP_CLOCK_MODE,k[D|a.CONTROL|a.ALT]=j.SAVE_STATE_0,k[E|a.CONTROL|a.ALT]=j.SAVE_STATE_0,k[F|a.CONTROL|a.ALT]=j.SAVE_STATE_1,k[G|a.CONTROL|a.ALT]=j.SAVE_STATE_2,k[H|a.CONTROL|a.ALT]=j.SAVE_STATE_3,k[I|a.CONTROL|a.ALT]=j.SAVE_STATE_4,k[J|a.CONTROL|a.ALT]=j.SAVE_STATE_5,k[K|a.CONTROL|a.ALT]=j.SAVE_STATE_6,k[L|a.CONTROL|a.ALT]=j.SAVE_STATE_7,k[M|a.CONTROL|a.ALT]=j.SAVE_STATE_8,k[N|a.CONTROL|a.ALT]=j.SAVE_STATE_9,k[O|a.CONTROL|a.ALT]=j.SAVE_STATE_10,k[P|a.CONTROL|a.ALT]=j.SAVE_STATE_11,k[Q|a.CONTROL|a.ALT]=j.SAVE_STATE_12,k[D|a.ALT]=j.LOAD_STATE_0,k[E|a.ALT]=j.LOAD_STATE_0,k[F|a.ALT]=j.LOAD_STATE_1,k[G|a.ALT]=j.LOAD_STATE_2,k[H|a.ALT]=j.LOAD_STATE_3,k[I|a.ALT]=j.LOAD_STATE_4,k[J|a.ALT]=j.LOAD_STATE_5,k[K|a.ALT]=j.LOAD_STATE_6,k[L|a.ALT]=j.LOAD_STATE_7,k[M|a.ALT]=j.LOAD_STATE_8,k[N|a.ALT]=j.LOAD_STATE_9,k[O|a.ALT]=j.LOAD_STATE_10,k[P|a.ALT]=j.LOAD_STATE_11,k[Q|a.ALT]=j.LOAD_STATE_12};this.netGetControlsToSend=function(){return n.length?n:void 0},this.netClearControlsToSend=function(){n.length=0},this.netServerProcessControlsChanges=function(a){for(var b=0,c=a.length;b<c;++b){var e=a[b];T.has(e.c>>4)||n.push(e),d(e.c>>4,1&e.c,2&e.c,e.d)}},this.netClientApplyControlsChanges=function(a){for(var b=0,c=a.length;b<c;++b){var e=a[b];d(e.c>>4,1&e.c,2&e.c,e.d)}};var g,h,i=wmsx.DOMKeys,j=wmsx.MachineControls,k={},l={},m={},n=new Array(100);n.length=0;var o=i.VK_F11.wc,p=i.VK_F12.wc,q=i.VK_UP.wc,r=i.VK_DOWN.wc,s=i.VK_RIGHT.wc,t=i.VK_LEFT.wc,u=i.VK_F8.wc,v=i.VK_P.wc,w=i.VK_O.wc,x=i.VK_F.wc,y=i.VK_D.wc,z=i.VK_S.wc,A=i.VK_Q.wc,B=i.VK_T.wc,C=i.VK_Y.wc,D=i.VK_QUOTE.wc,E=i.VK_BACKQUOTE.wc,F=i.VK_1.wc,G=i.VK_2.wc,H=i.VK_3.wc,I=i.VK_4.wc,J=i.VK_5.wc,K=i.VK_6.wc,L=i.VK_7.wc,M=i.VK_8.wc,N=i.VK_9.wc,O=i.VK_0.wc,P=i.VK_MINUS.wc,Q=i.VK_EQUALS.wc,R=~i.SHIFT,S=new Set([j.VIDEO_STANDARD,j.CPU_CLOCK_MODE,j.Z80_CLOCK_MODE,j.R800_CLOCK_MODE,j.VDP_CLOCK_MODE,j.SPRITE_MODE,j.VSYNCH]),T=new Set([j.SAVE_STATE_0,j.SAVE_STATE_1,j.SAVE_STATE_2,j.SAVE_STATE_3,j.SAVE_STATE_4,j.SAVE_STATE_5,j.SAVE_STATE_6,j.SAVE_STATE_7,j.SAVE_STATE_8,j.SAVE_STATE_9,j.SAVE_STATE_10,j.SAVE_STATE_11,j.SAVE_STATE_12,j.SAVE_STATE_FILE,j.LOAD_STATE_0,j.LOAD_STATE_1,j.LOAD_STATE_2,j.LOAD_STATE_3,j.LOAD_STATE_4,j.LOAD_STATE_5,j.LOAD_STATE_6,j.LOAD_STATE_7,j.LOAD_STATE_8,j.LOAD_STATE_9,j.LOAD_STATE_10,j.LOAD_STATE_11,j.LOAD_STATE_12,j.TRACE]),U=new Set([j.VSYNCH]);!function(){f()}()},wmsx.DOMVirtualKeyboard=function(a,b,c){"use strict";function d(a){a.addEventListener("touchstart",e),a.addEventListener("mousedown",e),
a.addEventListener("touchend",f),a.addEventListener("mouseup",f)}function e(a){h(a);var c=a.target.wmsxKey;c&&(b.processMSXKey(c,!0),"SHIFT"===c&&g())}function f(a){h(a);var c=a.target.wmsxKey;c&&(b.processMSXKey(c,!1),"SHIFT"===c&&g())}function g(){var a=b.isShiftPressed();a!==k&&(k=a,j&&wmsx.VirtualKeyboard.updateKeysLabels(j,k,l,m))}function h(a){a.stopPropagation(),a.preventDefault()}var i=this;this.machineTypeStateUpdate=function(){var a=c.getMachineLang(),b=c.getCodeKeyLabel();a===l&&b===m||(l=a,m=b,j&&wmsx.VirtualKeyboard.updateKeysLabels(j,k,l,m))};var j,k=!1,l="en",m="CODE";!function(){c.addMachineTypeStateListener(i),j=wmsx.VirtualKeyboard.create(a,d,k,l,m)}()},wmsx.ScreenGUI=wmsx.Util.isMobileDevice()?{BAR_HEIGHT:29,BAR_MENU_WIDTH:160,BAR_MENU_ITEM_HEIGHT:33,BAR_MENU_ITEM_FONT_SIZE:14,LOGO_SCREEN_WIDTH:597,LOGO_SCREEN_HEIGHT:455,TOUCH_CONTROLS_LEFT_WIDTH:119,TOUCH_CONTROLS_LEFT_WIDTH_BIG:143,TOUCH_CONTROLS_RIGHT_WIDTH:80}:{BAR_HEIGHT:29,BAR_MENU_WIDTH:150,BAR_MENU_ITEM_HEIGHT:29,BAR_MENU_ITEM_FONT_SIZE:13,LOGO_SCREEN_WIDTH:597,LOGO_SCREEN_HEIGHT:455,TOUCH_CONTROLS_LEFT_WIDTH:119,TOUCH_CONTROLS_LEFT_WIDTH_BIG:143,TOUCH_CONTROLS_RIGHT_WIDTH:80},wmsx.ScreenGUI.html=function(){return'<div id="wmsx-screen-fs" tabindex="0"> <div id="wmsx-screen-fs-center" tabindex="-1"> <div id="wmsx-screen-canvas-outer"> <canvas id="wmsx-screen-canvas" tabindex="-1"></canvas> <img id="wmsx-canvas-loading-icon" draggable="false" src="'+wmsx.Images.urls.loading+'"> <div id="wmsx-unmute-message"></div> <div id="wmsx-logo"> <div id="wmsx-logo-center"> <img id="wmsx-logo-image" draggable="false" src="'+wmsx.Images.urls.logo+'"> <img id="wmsx-logo-loading-icon" draggable="false" src="'+wmsx.Images.urls.loading+'"> <div id="wmsx-logo-message"> <div id="wmsx-logo-message-text"></div> <div id="wmsx-logo-message-ok"> <div id="wmsx-logo-message-ok-text"></div> </div> </div> </div> </div> <div id="wmsx-osd"></div> </div> <div id="wmsx-drop-area"> <div id="wmsx-drop-drivea"><div id="wmsx-drop-drivea-add" class="wmsx-drop-add"></div><i></i><div id="wmsx-drop-drivea-files" class="wmsx-drop-files"></div><br>Drive A</div> <div id="wmsx-drop-driveb"><div id="wmsx-drop-driveb-add" class="wmsx-drop-add"></div><i></i><div id="wmsx-drop-driveb-files" class="wmsx-drop-files"></div><br>Drive B</div> <div id="wmsx-drop-driveh"><i></i><div id="wmsx-drop-driveh-files" class="wmsx-drop-files"></div><br>Hard Drive</div> <div id="wmsx-drop-cart1"><i></i><br>Cartridge 1</div> <div id="wmsx-drop-cart2"><i></i><br>Cartridge 2</div> <div id="wmsx-drop-tape"><i></i><br>Cassette</div> <span id="wmsx-drop-area-message"></span> </div> <div id="wmsx-bar"> <div id="wmsx-bar-inner"></div> </div> </div> <div id="wmsx-screen-scroll-message"> Swipe up/down on the Screen <br>to hide the browser bars! </div> </div>'},wmsx.ScreenGUI.auxHtml=function(){return'<html class="wmsx-full-screen"> <head> <title>WebMSX: 2nd Video</title> <style type="text/css">'+wmsx.ScreenGUI.css()+'</style> </head> <body id="wmsx-aux-body"> <div id="wmsx-screen-fs" tabindex="0"> <div id="wmsx-screen-fs-center" tabindex="-1"> <div id="wmsx-screen-canvas-outer"> <canvas id="wmsx-screen-canvas" tabindex="-1"></canvas> <div id="wmsx-logo"> <div id="wmsx-logo-center"> <img id="wmsx-logo-image" draggable="false" src="'+wmsx.Images.urls.logo+'"> <div id="wmsx-logo-message"> <div id="wmsx-logo-message-text"></div> </div> </div> </div> <div id="wmsx-osd"></div> </div> </div> </div> <script> /* inner/outer dimensions are not reported consistently right after window has opened So we do some async/event tricks to improve reliability */ function onFirstResize() { window.onresize = undefined; setTimeout(function() { opener.WMSX.room.screen.auxWindowFirstResize(window); }, 121); } window.onresize = onFirstResize; /* Make sure we get control even if resize event does not fire */ setTimeout(onFirstResize, 300); <\/script> </body> </html>'},wmsx.ScreenGUI.css=function(){
return"html.wmsx-full-screen-scroll-hack body { position: absolute; width: 100%; height: "+Math.max(1280,1.4*Math.max(screen.width,screen.height)|0)+"px; top: 0; left: 0; margin: 0; padding: 0; border: none; overflow-x: hidden; overflow-y: auto; } #wmsx-aux-body { font-family: sans-serif; font-weight: normal; margin: 0; padding: 0; background: black; overflow: hidden; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; touch-callout: none; -webkit-tap-highlight-color: transparent; tap-highlight-color: transparent; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; text-size-adjust: none; } #wmsx-screen-fs, #wmsx-screen-fs div, #wmsx-screen-fs canvas { outline: none; } #"+WMSX.SCREEN_ELEMENT_ID+" { display: inline-block; visibility: hidden; font-family: sans-serif; font-weight: normal; margin: 0; padding: 0; border: 1px solid black; background: black; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-touch-callout: none; touch-callout: none; -webkit-tap-highlight-color: transparent; tap-highlight-color: transparent; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; text-size-adjust: none; } html.wmsx-full-screen #"+WMSX.SCREEN_ELEMENT_ID+" { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; box-shadow: none; z-index: 2147483646;    /* one behind fsElement */ } html.wmsx-started #"+WMSX.SCREEN_ELEMENT_ID+" { visibility: visible; } #wmsx-screen-scroll-message { position: absolute; left: 0; right: 0; bottom: -50%; width: 0; height: 0; padding: 0; margin: 0 auto; font-size: 16px; line-height: 28px; color: hsl(0, 0%, 4%); white-space: nowrap; background: hsl(0, 0%, 92%); border-radius: 15px; box-shadow: 2px 2px 9px rgba(0, 0, 0, 0.7); transition: all 1.7s step-end, opacity 1.6s linear; opacity: 0; z-index: -1; } html.wmsx-full-screen-scroll-hack #wmsx-screen-fs.wmsx-scroll-message #wmsx-screen-scroll-message { opacity: 1; bottom: 23%; width: 215px; height: 56px; padding: 13px 20px; z-index: 10; transition: none; } #wmsx-screen-fs { position: relative; background: black; text-align: center; overflow: hidden; -webkit-tap-highlight-color: rgba(0,0,0,0); tap-highlight-color: rgba(0,0,0,0) } html.wmsx-full-screen #wmsx-screen-fs { position: absolute; width: 100%; height: 100%; left: 0; bottom: 0; right: 0; z-index: 2147483647; } html.wmsx-full-screen-scroll-hack #wmsx-screen-fs { position: fixed; bottom: 0; height: 100vh; } html.wmsx-full-screen #wmsx-screen-fs-center {      /* Used to center and move things horizontally in Landscape Full Screen */ position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #wmsx-screen-canvas-outer { display: inline-block; position: relative; vertical-align: top; line-height: 1px; z-index: 3; } #wmsx-screen-canvas { display: block; } #wmsx-bar { position: relative; left: 0; right: 0; height: "+this.BAR_HEIGHT+'px; margin: 0 auto; border-top: 1px solid black; background: hsl(0, 0%, 16%); overflow: visible;                    /* for the Menu to show through */ box-sizing: content-box; z-index: 5; } #wmsx-bar-inner { position: absolute; overflow: hidden; top: 0; bottom: 0; left: 0; right: 0; text-align: left; } html.wmsx-bar-auto-hide #wmsx-bar, html.wmsx-full-screen #wmsx-bar { position: absolute; bottom: 0; transition: height 0.08s ease-in-out; } html.wmsx-bar-auto-hide #wmsx-bar.wmsx-hidden { transition: height 0.5s ease-in-out; height: 0; bottom: -1px; } @media only screen and (orientation: landscape) { html.wmsx-full-screen #wmsx-bar.wmsx-hidden { transition: height 0.5s ease-in-out; height: 0; bottom: -1px; } } #wmsx-bar.wmsx-narrow .wmsx-narrow-hidden, #wmsx-bar.wmsx-semi-narrow .wmsx-semi-narrow-hidden { display: none; } .wmsx-bar-button { display: inline-block; width: 24px; height: 29px; margin: 0 1px; background-image: url("'+wmsx.Images.urls.sprites+'"); background-repeat: no-repeat; background-size: 568px 206px; cursor: pointer; } .wmsx-bar-button.wmsx-media-button { background-size: 284px 103px; } .wmsx-bar-button.wmsx-hidden { display: none; } /* Firefox-specific rules */ @-moz-document url-prefix() { .wmsx-bar-button { image-rendering: optimizequality; } } /* .wmsx-bar-button { border: 1px solid yellow; background-origin: border-box; box-sizing: border-box; } */ #wmsx-bar-power { margin-left: 6px; } #wmsx-bar-media-icons { margin-left: 10px; } #wmsx-bar-settings-icons { float: right; margin: 0 5px 0 -4px; } #wmsx-bar-settings, #wmsx-bar-video, #wmsx-bar-full-screen, #wmsx-bar-scale-plus, #wmsx-bar-scale-minus { margin: 0; } #wmsx-bar-scale-plus { width: 21px; } #wmsx-bar-scale-minus { width: 18px; } #wmsx-bar-text { width: 32px; float: right; } #wmsx-bar-keyboard { position: absolute; left: 0; right: 0; width: 37px; margin: 0 auto; } #wmsx-bar.wmsx-narrow #wmsx-bar-keyboard { position: static; float: right; } .wmsx-bar-mobile #wmsx-bar-settings-icons > * { margin: 0 0 0 6px; } .wmsx-bar-mobile #wmsx-bar-text, .wmsx-bar-mobile #wmsx-bar.wmsx-narrow #wmsx-bar-keyboard { margin: 0 6px 0 0; } #wmsx-bar-logo { position: absolute; left: 0; right: 0; width: 52px; margin: 0 auto; } #wmsx-bar-turbo, #wmsx-bar-caps, #wmsx-bar-kana, #wmsx-bar-pause { position: absolute; left: 0; right: 0; height: 29px; padding: 8px 0 0 0; color: hsl(0, 100%, 64%); font-weight: bold; font-size: 12px; line-height: 14px; text-shadow: 2px 2px 0 black; vertical-align: top; box-sizing: border-box; cursor: auto; } #wmsx-bar-pause     { right: 88px; width: 20px; margin: 0 auto; } #wmsx-bar-turbo     { left: 88px;  width: 20px; margin: 0 auto; padding-left: 25px; cursor: pointer; } #wmsx-bar-caps, #wmsx-bar-kana    { position: relative; float: right; width: auto; margin-right: 18px; background: none; } #wmsx-bar.wmsx-narrow #wmsx-bar-turbo { position: static; margin-right: 2px; width: auto; } #wmsx-bar-menu { position: absolute; display: none; bottom: '+this.BAR_HEIGHT+"px; font-size: "+this.BAR_MENU_ITEM_FONT_SIZE+"px; line-height: 1px; overflow: hidden; transform-origin: bottom center; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } #wmsx-bar-menu-inner { display: inline-block; padding-bottom: 2px; border: 1px solid black; background: hsl(0, 0%, 16%); } .wmsx-bar-menu-item, #wmsx-bar-menu-title { position: relative; display: none; width: "+this.BAR_MENU_WIDTH+"px; height: "+this.BAR_MENU_ITEM_HEIGHT+"px; color: rgb(205, 205, 205); border: none; padding: 0; line-height: "+this.BAR_MENU_ITEM_HEIGHT+'px; text-shadow: 1px 1px 1px black; background: transparent; outline: none; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; cursor: pointer; box-sizing: border-box; } #wmsx-bar-menu-title { display: block; color: white; font-weight: bold; border-bottom: 1px solid black; margin-bottom: 1px; text-align: center; background: rgb(70, 70, 70); cursor: auto; } .wmsx-bar-menu-item.wmsx-hover:not(.wmsx-bar-menu-item-disabled):not(.wmsx-bar-menu-item-divider) { color: white; background: hsl(358, 67%, 46%); } .wmsx-bar-menu-item-disabled { color: rgb(110, 110, 110); } .wmsx-bar-menu-item-divider { height: 1px; margin: 1px 0; background: black; } .wmsx-bar-menu-item-toggle { text-align: left; padding-left: 40px; } .wmsx-bar-menu-item-toggle::before, .wmsx-bar-menu-item-toggle::after { content: ""; position: absolute; width: 6px; height: 9px; top: '+((this.BAR_MENU_ITEM_HEIGHT-21)/2|0)+"px; left: 16px; background: rgb(82, 82, 82); box-shadow: black 1px 1px 1px; } .wmsx-bar-menu-item-toggle::after { top: "+((this.BAR_MENU_ITEM_HEIGHT-21)/2+10|0)+"px; } .wmsx-bar-menu-item-toggle.wmsx-bar-menu-item-toggle-checked:not(.wmsx-bar-menu-item-disabled) { color: white; } .wmsx-bar-menu-item-toggle.wmsx-bar-menu-item-toggle-checked:not(.wmsx-bar-menu-item-disabled).wmsx-op1::before, .wmsx-bar-menu-item-toggle.wmsx-bar-menu-item-toggle-checked:not(.wmsx-bar-menu-item-disabled).wmsx-op2::after { background: rgb(254, 32, 30); } .wmsx-bar-menu-item-toggle.wmsx-no-op2::before { top: "+((this.BAR_MENU_ITEM_HEIGHT-21)/2+2|0)+"px; height: 16px; } .wmsx-bar-menu-item-toggle.wmsx-no-op2::after, .wmsx-bar-menu-item-toggle-radio::after { display: none; } .wmsx-bar-menu-item-toggle-radio::before { width: 12px  !important; height: 12px  !important; top: "+((this.BAR_MENU_ITEM_HEIGHT-12)/2|0)+'px  !important; left: 14px; border-radius: 100%; box-shadow: black 1px 1px 1px 1px; } .wmsx-select-dialog { position: absolute; overflow: hidden; display: none; top: 0; bottom: 0; left: 0; right: 0; width: 540px; max-width: 92%; height: 297px; margin: auto; color: white; font-size: 18px; background: hsl(0, 0%, 16%); padding: 14px 0 0; text-align: center; border: 1px solid black; box-sizing: initial; text-shadow: 1px 1px 1px black; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; cursor: auto; z-index: 4; } .wmsx-select-dialog.wmsx-show { display: block; } .wmsx-select-dialog > .wmsx-footer { position: absolute; width: 100%; bottom: 7px; font-size: 13px; text-align: center; color: rgb(170, 170, 170); } .wmsx-select-dialog > ul { position: relative; width: 88%; top: 5px; margin: auto; padding: 0; list-style: none; font-size: 14px; color: hsl(0, 0%, 88%); } .wmsx-select-dialog > ul li { display: none; position: relative; overflow: hidden; height: 26px; background: rgb(70, 70, 70); margin: 7px 0; padding: 11px 10px 0; line-height: 0; text-align: left; text-overflow: ellipsis; border: 2px dashed transparent; box-shadow: 1px 1px 1px rgba(0, 0, 0, .5); white-space: nowrap; box-sizing: border-box; cursor: pointer; } .wmsx-select-dialog > ul li.wmsx-visible { display: block; } .wmsx-select-dialog > ul li.wmsx-selected { color: white; background: hsl(358, 67%, 46%); } .wmsx-select-dialog > ul li.wmsx-droptarget { color: white; border-color: lightgray; } .wmsx-select-dialog > ul li.wmsx-toggle::after { content: ""; position: absolute; width: 6px; height: 17px; top: 2px; left: 6px; background: rgb(60, 60, 60); box-shadow: black 1px 1px 1px; } .wmsx-select-dialog > ul li.wmsx-toggle-checked::after { background: rgb(254, 32, 30); } #wmsx-diskselect.wmsx-select-dialog li { padding-left: 23px; } #wmsx-diskselect.wmsx-select-dialog li.wmsx-toggle::after { background: hsl(0, 0%, 73%); } #wmsx-diskselect.wmsx-select-dialog li.wmsx-toggle-checked::after { background: rgb(230, 205, 31); } #wmsx-cartridge-format.wmsx-select-dialog > ul { width: 100%; height: 292px; margin: 7px auto 0; padding: 0 0 0 30px; overflow-y: auto; box-sizing: border-box; } #wmsx-cartridge-format.wmsx-select-dialog > ul li { width: 220px; margin: 7px 0 2px 0; } #wmsx-cartridge-format.wmsx-select-dialog > ul li:first-child { margin-top: 0; } #wmsx-cartridge-format ::-webkit-scrollbar { width: 12px; } #wmsx-cartridge-format ::-webkit-scrollbar-track { background: transparent; } #wmsx-cartridge-format ::-webkit-scrollbar-thumb { border: solid transparent; border-width: 1px 1px 1px 2px; background: rgb(80, 80, 80); background-clip: content-box; } #wmsx-cartridge-format ul.wmsx-quick-options-list { width: 220px; margin: 18px 0 0 30px; } #wmsx-cartridge-format ul.wmsx-quick-options-list li div { height: 24px; line-height: 24px; } #wmsx-cartridge-format .wmsx-control { width: 52px; line-height: 24px; cursor: pointer; } /* Firefox-specific rules */ @-moz-document url-prefix() { /* Try to hide scrollbar, since we cant style it :-( */ #wmsx-cartridge-format.wmsx-select-dialog > ul { width: 304px; } } #wmsx-savestate { width: 280px; height: 403px; } #wmsx-savestate.wmsx-load { height: 438px; } #wmsx-savestate ul.wmsx-quick-options-list { display: none; width: 220px; margin: 18px 0 0 30px; } #wmsx-savestate.wmsx-load ul.wmsx-quick-options-list { display: block; } #wmsx-savestate ul.wmsx-quick-options-list li div { height: 24px; line-height: 24px; } #wmsx-savestate .wmsx-control { width: 52px; cursor: pointer; } #wmsx-logo { position: absolute; display: none; top: 0; bottom: 0; left: 0; right: 0; background: black; } #wmsx-logo.wmsx-show { display: block; } #wmsx-logo-center { position: absolute; top: 50%; left: 50%; width: 598px; height: 456px; transform: translate(-50%, -50%); } #wmsx-screen-fs:not(.wmsx-logo-message-active) #wmsx-logo-center { max-width: 100%; max-height: 100%; } #wmsx-logo-image { position: absolute; top: 50%; left: 50%; width: 334px; max-width: 57%; transform: translate(-50%, -50%); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } html.wmsx-full-screen #wmsx-logo-image { max-width: 67%; } #wmsx-screen-fs.wmsx-logo-message-active #wmsx-logo-image { top: 138px; max-width: initial; } #wmsx-unmute-message { display: none; position: absolute; left: 50%; bottom: 5px; height: 30px; padding: 0 10px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 15px; line-height: 30px; color: rgb(210, 210, 210); background: rgba(0, 0, 0, 0.7); transform-origin: bottom center; transform: translate(-50%, 0); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } #wmsx-unmute-message::before { content: ""; display: inline-block; width: 24px; height: 20px; margin: 5px 9px 0 0; background-image: url("'+wmsx.Images.urls.muteIcon+'"); background-repeat: no-repeat; background-size: 24px 20px; vertical-align: top; } #wmsx-unmute-message::after { content: "Audio is muted. Click to unmute"; } #wmsx-unmute-message.wmsx-show { display: inline-block; } #wmsx-logo-loading-icon, #wmsx-canvas-loading-icon { display: none; position: absolute; top: 62%; left: 0; right: 0; width: 14%; height: 3%; margin: 0 auto; background-color: rgba(0, 0, 0, .8); border: solid transparent; border-width: 12px 30px; border-radius: 3px; box-sizing: content-box; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } #wmsx-screen-fs.wmsx-logo-message-active #wmsx-logo-loading-icon { top: 190px; } #wmsx-logo-message { display: none; position: absolute; top: 224px; width: 100%; color: hsl(0, 0%, 97%); font-size: 29px; line-height: 34px; } #wmsx-screen-fs.wmsx-logo-message-active #wmsx-logo-message { display: block; } #wmsx-logo-message-ok { display: block; position: absolute; top: 91px; left: 193px; width: 214px; height: 130px; } #wmsx-logo-message-ok.wmsx-higher { top: 74px; } #wmsx-logo-message-ok-text { position: absolute; top: 49%; left: 50%; width: 120px; height: 47px; font-size: 23px; line-height: 47px; background: hsl(358, 67%, 46%); border-radius: 6px; color: white; transform: translate(-50%, -50%); } #wmsx-osd { position: absolute; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; top: -29px; right: 20px; height: 28px; padding: 0 10px; margin: 0; font-weight: bold; font-size: 15px; line-height: 28px; color: rgb(0, 255, 0); background: rgba(0, 0, 0, 0.7); transform-origin: top right; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; opacity: 0; } #wmsx-copy-texarea { position: absolute; width: 50px; height: 0; bottom: 0; z-index: -10; opacity: 0; } #wmsx-paste-cover { display: none; position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 340px; height: 136px; margin: auto; border-radius: 20px; background: rgba(0, 0, 0, 0.4); z-index: 1; } #wmsx-paste-cover.wmsx-show { display: block; } #wmsx-paste-box { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 270px; height: 66px; margin: auto; background: rgba(255, 40, 40, 0.75); font-weight: bold; font-size: 26px; text-align: center; color: transparent; border: 2px dashed rgba(240, 240, 240, 0.70); box-sizing: initial; border-radius: 10px; text-shadow: 0 0 0 rgb(240, 240, 240); padding: 0; outline: none; } #wmsx-text-entry-dialog { display: none; position: absolute; top: 50%; left: 0; right: 0; width: 96%; max-width: 540px; height: 60%; min-height: 125px; max-height: 450px; margin: 0 auto; color: white; font-size: 19px; line-height: 23px; background: hsl(0, 0%, 16%); text-align: center; border: 1px solid black; box-sizing: initial; text-shadow: 1px 1px 1px black; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; transform: translate(0, -65%); cursor: auto; z-index: 4; } #wmsx-text-entry-dialog.wmsx-show { display: block; } #wmsx-text-entry-dialog-bar { position: absolute; height: 40px; width: 100%; line-height: 40px; background: inherit; overflow: hidden; } #wmsx-text-entry-dialog-bar::before { content: "Input Text"; } #wmsx-text-entry-dialog-ok, #wmsx-text-entry-dialog-cancel { display: inline-block; float: right; width: 70px; height: 22px; margin-right: 15px; border: 9px solid hsl(0, 0%, 16%); border-left: none; border-right: none; font-size: 14px; line-height: 22px; background: hsl(358, 67%, 46%); cursor: pointer; } #wmsx-text-entry-dialog-cancel { color: hsl(0, 0%, 90%); background: hsl(0, 0%, 30%); } #wmsx-text-entry-dialog-ok::before { content: "OK"; } #wmsx-text-entry-dialog-cancel::before { content: "CANCEL"; } #wmsx-text-entry-input { position: absolute; top: 15px; left: 15px; width: calc(100% - 30px); height: calc(100% - 30px); padding: 29px 6px 4px; font-size: 16px; border: none; border-radius: 0; background: hsl(0, 0%, 90%); box-sizing: border-box; resize: none; outline: none; -webkit-touch-callout: default; touch-callout: default; } .wmsx-arrow-up, .wmsx-arrow-down, .wmsx-arrow-left, .wmsx-arrow-right { border: 0px solid transparent; box-sizing: border-box; } .wmsx-arrow-up    { border-bottom-color: inherit; } .wmsx-arrow-down  { border-top-color: inherit; } .wmsx-arrow-left  { border-right-color: inherit; } .wmsx-arrow-right { border-left-color: inherit; } .wmsx-keyboard-key { position: absolute; height: 25px; padding: 5px 0 0; overflow: hidden; font-weight: normal; font-size: 10px; line-height: 10px; text-align: center; vertical-align: top; color: white; background: hsl(0, 0%, 66%); border: 3px solid hsl(0, 0%, 50%); border-top: 1px solid hsl(0, 0%, 54%); border-bottom: 5px solid hsl(0, 0%, 33%); border-radius: 3px 3px 0 0; box-shadow: 0 1px 0 1px rgb(0, 0, 0); box-sizing: border-box; cursor: pointer; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .wmsx-keyboard-key.wmsx-keyboard-key-dark { background: hsl(0, 0%, 46%); border-color: hsl(0, 0%, 36%); border-top-color: hsl(0, 0%, 40%); border-bottom-color: hsl(0, 0%, 24%); } .wmsx-keyboard-key.wmsx-keyboard-key-unmapped { color: rgb(30, 30, 30); font-weight: bold; -webkit-font-smoothing: initial; -moz-osx-font-smoothing: initial; } .wmsx-keyboard-alpha, .wmsx-keyboard-num, .wmsx-keyboard-arrows { position: absolute; } .wmsx-keyboard-alpha > div, .wmsx-keyboard-num > div, .wmsx-keyboard-arrows > div { position: absolute; } .wmsx-keyboard-num { left: 416px; } .wmsx-keyboard-arrows { top: 104px; left: 417px; } .wmsx-keyboard-f1, .wmsx-keyboard-f2, .wmsx-keyboard-f3, .wmsx-keyboard-f4, .wmsx-keyboard-f5, .wmsx-keyboard-stop, .wmsx-keyboard-select, .wmsx-keyboard-home, .wmsx-keyboard-insert, .wmsx-keyboard-delete { height: 18px; padding-top: 2px; font-size: 9px; line-height: 9px; border-width: 1px 2px 4px; } .wmsx-keyboard-stop { margin-left: 10px; background: hsl(0, 70%, 54%); border-color: hsl(0, 70%, 36%); border-top-color: hsl(0, 70%, 40%); border-bottom-color: hsl(0, 70%, 28%); } .wmsx-keyboard-enter { border-radius: 2px 3px 0 0; border-top: none; box-shadow: none; overflow: visible; } .wmsx-keyboard-enter::after { content: ""; display: block; position: absolute; left: -10px; bottom: -7px; width: 20px; height: 2px; background: black; } .wmsx-keyboard-enter_x1 { border-radius: 2px 0 0 0; border-width: 1px; border-right: none; box-shadow: -1px 1px 0 0 black; } .wmsx-keyboard-enter_x2 { overflow: visible; padding: 0; border: none; border-radius: 0 3px 0 0; box-shadow: none; box-shadow: 1px 1px 0 0 black; } .wmsx-keyboard-enter_x2::after { content: ""; display: block; width: 30px; height: 50px; background: inherit; border: 3px solid hsl(0, 0%, 36%); border-top: 1px solid hsl(0, 0%, 40%); border-bottom: 5px solid hsl(0, 0%, 24%); border-radius: 0 3px 0 0; box-shadow: 1px 2px 0 0 black, 1px 0 0 0 black; box-sizing: border-box; } .wmsx-keyboard-capslock { margin-left: 16px; } .wmsx-keyboard-space { left: 103px; width: 217px; } .wmsx-keyboard-dead { left: 333px; width: 26px; } .wmsx-keyboard-shift2 { left: 360px; width: 41px; } .wmsx-keyboard-code { left: 321px; width: 46px; } .wmsx-keyboard-num .wmsx-keyboard-key { height: 23px; padding-top: 4px; } .wmsx-keyboard-arrows .wmsx-keyboard-key { font-size: 8px; line-height: 9px; background: rgb(70, 85, 180); border-width: 1px 2px 4px; border-radius: 2px 2px 0 0; border-color: hsl(232, 44%, 37%); border-top-color: hsl(232, 44%, 40%); border-bottom-color: hsl(232, 44%, 24%); } .wmsx-keyboard-left, .wmsx-keyboard-right { top: 6px; width: 26px; height: 33px; padding: 10px 0 0 6px; } .wmsx-keyboard-up, .wmsx-keyboard-down { left: 27px; width: 37px; height: 23px; padding: 5px 0 0 12px; } .wmsx-keyboard-down { top: 23px; padding-top: 7px; } .wmsx-keyboard-right { left: 65px; padding-left: 10px; } .wmsx-keyboard-up::after, .wmsx-keyboard-down::after, .wmsx-keyboard-left::after, .wmsx-keyboard-right::after { content: ""; display: block; border: 4px solid transparent; width: 6px; height: 6px; box-sizing: border-box; } .wmsx-keyboard-up::after { border-bottom: 5px solid white; border-top-width: 0; } .wmsx-keyboard-up.wmsx-keyboard-key-unmapped::after { border-bottom-color: black; } .wmsx-keyboard-down::after { border-top: 5px solid white; border-bottom-width: 0; } .wmsx-keyboard-down.wmsx-keyboard-key-unmapped::after { border-top-color: black; } .wmsx-keyboard-left::after { border-right: 5px solid white; border-left-width: 0; } .wmsx-keyboard-left.wmsx-keyboard-key-unmapped::after { border-right-color: black; } .wmsx-keyboard-right::after { border-left: 5px solid white; border-right-width: 0; } .wmsx-keyboard-right.wmsx-keyboard-key-unmapped::after { border-left-color: black; } .wmsx-keyboard-narrow .wmsx-keyboard-num { display: none; } .wmsx-keyboard-narrow .wmsx-keyboard-arrows { left: 336px; } .wmsx-keyboard-narrow .wmsx-keyboard-space { width: 155px; } .wmsx-keyboard-narrow .wmsx-keyboard-code { left: 259px; width: 39px; } .wmsx-keyboard-narrow .wmsx-keyboard-dead { left: 299px; top: 25px; } .wmsx-keyboard-narrow .wmsx-keyboard-shift2 { display: none; } .wmsx-keyboard-narrow .wmsx-keyboard-left, .wmsx-keyboard-narrow .wmsx-keyboard-right  { top: 9px; width: 23px; height: 27px; padding: 7px 0 0 5px; border-bottom-width: 3px; } .wmsx-keyboard-narrow .wmsx-keyboard-up, .wmsx-keyboard-narrow .wmsx-keyboard-down  { left: 24px; width: 26px; padding-left: 7px; border-bottom-width: 3px; } .wmsx-keyboard-narrow .wmsx-keyboard-right  { left: 51px; padding-left: 8px; } #wmsx-virtual-keyboard { display: none; position: absolute; left: 50%; bottom: '+(this.BAR_HEIGHT+2)+'px; overflow: hidden; margin: 0 auto; padding: 5px 0 0 4px; width: 518px; height: 161px; background: hsl(0, 0%, 16%); box-sizing: border-box; transform: translateX(-50%); transform-origin: center bottom; transition: height 0.3s ease-in-out; text-align: left; z-index: 2; } html.wmsx-full-screen.wmsx-virtual-keyboard-active #wmsx-virtual-keyboard { display: block; } .wmsx-quick-options-list { margin-top: 12px; padding: 0; list-style: none; color: hsl(0, 0%, 88%); } .wmsx-quick-options-list li { margin-top: 9px; line-height: 1px; text-align: left; } .wmsx-quick-options-list li.wmsx-hidden { display: none; } .wmsx-quick-options-list li div { display: inline-block; overflow: hidden; height: 26px; font-size: 14px; line-height: 26px; text-overflow: ellipsis; white-space: nowrap; box-sizing: border-box; } .wmsx-quick-options-list .wmsx-control { position: relative; float: right; width: 134px; font-size: 15px; line-height: 25px; color: hsl(0, 0%, 70%); background: black; text-align: center; box-shadow: 1px 1px 1px rgba(0, 0, 0, .5); } .wmsx-quick-options-list .wmsx-control > button { position: absolute; top: 0; bottom: 0; width: 26px; height: 100%; background: rgb(70, 70, 70); border: none; outline: none; cursor: pointer; -webkit-appearance: none; } .wmsx-quick-options-list .wmsx-control > button::after { content: ""; position: absolute; top: 7px; border: 6px solid transparent; } .wmsx-quick-options-list .wmsx-control .wmsx-control-dec { left: 0; border-right: 1px solid black; } .wmsx-quick-options-list .wmsx-control .wmsx-control-dec::after { left: 2px; border-right-color: #c0c0c0; } .wmsx-quick-options-list .wmsx-control .wmsx-control-inc { right: 0; border-left: 1px solid black; } .wmsx-quick-options-list .wmsx-control .wmsx-control-inc::after { right: 2px; border-left-color: #c0c0c0; } .wmsx-quick-options-list .wmsx-control.wmsx-selected { color: white; background: hsl(358, 67%, 46%); box-shadow: 1px 1px 1px rgba(0, 0, 0, .5); } .wmsx-quick-options-list .wmsx-control.wmsx-selected.wmsx-inactive { line-height: 21px; border: 2px dashed hsl(358, 67%, 46%); background: black; } #wmsx-quick-options { display: none; position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 270px; height: 386px; margin: auto; padding: 14px 15px 0; color: white; font-size: 18px; line-height: 22px; background: hsl(0, 0%, 16%); text-align: center; border: 1px solid black; box-sizing: initial; text-shadow: 1px 1px 1px black; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; cursor: auto; z-index: 3; } #wmsx-quick-options.wmsx-show { display: block; } #wmsx-quick-options::before { content: "Quick Options"; display: block; } #wmsx-netplay { display: none; position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 390px; height: 220px; margin: auto; padding-top: 11px; color: white; font-size: 18px; line-height: 22px; background: hsl(0, 0%, 16%); text-align: center; border: 1px solid black; box-sizing: initial; text-shadow: 1px 1px 1px black; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); transform-origin: left center; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; cursor: auto; z-index: 50; } #wmsx-netplay.wmsx-show { display: block; } #wmsx-netplay::before { content: "Net Play!"; display: block; } #wmsx-netplay-status-box { position: relative; margin-top: 17px; } #wmsx-netplay-status { display: inline-block; position: relative; width: 340px; font-size: 15px; line-height: 27px; background: black; vertical-align: top; text-shadow: none; -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text; box-sizing: border-box; cursor: auto; } #wmsx-netplay-status-box.wmsx-active #wmsx-netplay-status { padding: 0 16px 0 12px; } #wmsx-netplay-status-box.wmsx-active #wmsx-netplay-status::after { content: ""; position: absolute; width: 6px; height: 18px; top: 4px; left: 7px; background: rgb(254, 32, 30); } #wmsx-netplay-link { display: none; position: absolute; right: 25px; top: 0; width: 26px; height: 27px; color: white; font-size: 15px; font-weight: 600; line-height: 27px; text-decoration: none; background: black; text-align: center; } #wmsx-netplay-link:hover { background: hsl(358, 67%, 46%); cursor: pointer; } #wmsx-netplay-status-box.wmsx-active #wmsx-netplay-link { display: block; } .wmsx-netplay-button { display: inline-block; width: 86px; padding: 0; margin: 0; font-size: 15px; line-height: 26px; color: white; background: hsl(358, 67%, 46%); text-shadow: 1px 1px 1px black; border: none; box-shadow: 1px 1px 1px rgba(0, 0, 0, .5); cursor: pointer; } #wmsx-netplay-session-box { margin-top: 18px; } #wmsx-netplay-session-label, #wmsx-netplay-nick-label { font-size: 15px; margin-bottom: 4px; } #wmsx-netplay-session-label::before { content: "Session Name"; } #wmsx-netplay-session-box input { width: 150px; height: 26px; padding: 0 10px; margin: 0 8px; font-size: 15px; line-height: 26px; background: rgb(240, 240, 240); border: none; border-radius: 0; box-sizing: border-box; outline: none; -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text; cursor: auto; } #wmsx-netplay-nick-label { margin-top: 10px; } #wmsx-netplay-nick-label::before { content: "User Nickname"; } .wmsx-netplay-button:disabled { color: rgb(130, 130, 130); background: rgb(70, 70, 70); cursor: default; } #wmsx-netplay input:disabled { color: black; background: rgb(180, 180, 180); cursor: default; } #wmsx-netplay-session-box.wmsx-disabled div { color: rgb(130, 130, 130); } input#wmsx-netplay-link-text { position: absolute; top: 8px; left: 50px; width: 1px; height: 1px; padding: 0; margin: 0; border: none; color: transparent; background: transparent; opacity: 0; z-index: -10; -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text; } #wmsx-touch-config { display: none; position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 294px; height: 304px; margin: auto; padding: 0 16px; color: white; font-size: 18px; line-height: 22px; background: hsl(0, 0%, 16%); text-align: center; border: 1px solid black; box-sizing: border-box; text-shadow: 1px 1px 1px black; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; cursor: auto; z-index: 3; } #wmsx-screen-fs.wmsx-touch-config-active #wmsx-touch-config { display: block; } #wmsx-touch-config::after { content: "Tap Control to Setup"; position: absolute; display: block; top: 14px; left: 0; width: 100%; } #wmsx-touch-config::before { content: ""; display: block; margin-top: 46px; height: 68px; background: black; } #wmsx-touch-config-minus, #wmsx-touch-config-plus { position: absolute; top: 46px; width: 72px; height: 68px; cursor: pointer; } #wmsx-touch-config-minus { left: 19px; } #wmsx-touch-config-plus { right: 19px; } #wmsx-touch-config-minus::after, #wmsx-touch-config-plus::after { content: ""; position: absolute; top: 20px; border: 14px solid transparent; } #wmsx-touch-config-minus::after { left: 9px; border-right: 18px solid #c0c0c0; } #wmsx-touch-config-minus.wmsx-disabled::after { border-right-color: #404040; } #wmsx-touch-config-plus::after { right: 9px; border-left: 18px solid #c0c0c0; } #wmsx-touch-config-plus.wmsx-disabled::after { border-left-color: #404040; } #wmsx-touch-config-dir { display: none; position: absolute; top: 15px; left: 79px; transform: scale(.70); } #wmsx-touch-config-dir.wmsx-show { display: block; } #wmsx-touch-config-dir::before { display: none; } #wmsx-touch-config-button { display: none; position: absolute; top: 46px; right: 109px; text-shadow: none; } #wmsx-touch-config-button.wmsx-show { display: block; } #wmsx-touch-config .wmsx-quick-options-list { margin-top: 11px; } #wmsx-touch-config .wmsx-control { width: 110px; } #wmsx-touch-left, #wmsx-touch-right { display: none; position: absolute; z-index: 1; } #wmsx-touch-speed { display: none; } html.wmsx-full-screen.wmsx-touch-active #wmsx-touch-left, html.wmsx-full-screen.wmsx-touch-active #wmsx-touch-right, html.wmsx-full-screen.wmsx-touch-active #wmsx-touch-speed { display: block; } .wmsx-touch-dir { position: relative; width: 130px; height: 130px; color: hsl(0, 0%, 75%); border-radius: 100%; z-index: 2 } .wmsx-touch-dir::before { content: ""; position: absolute; top: 14px; left: 14px; right: 14px; bottom: 14px; border: 1px solid hsl(0, 0%, 26%); border-radius: 100%; } .wmsx-touch-dir-joy .wmsx-touch-dir-up, .wmsx-touch-dir-joy .wmsx-touch-dir-left { position: absolute; background: hsl(0, 0%, 31%); border-radius: 2px 2px 0 0; box-shadow: inset 1px 2px 0px hsl(0, 0%, 43%), inset -1px -1px hsl(0, 0%, 19%), 0 3px 0 1px hsl(0, 0%, 21%); } .wmsx-touch-dir-joy .wmsx-touch-dir-up { width: 26px; height: 78px; top: 24px; left: 52px; } .wmsx-touch-dir-joy .wmsx-touch-dir-left { width: 78px; height: 25px; top: 51px; left: 26px; } .wmsx-touch-dir-joy .wmsx-touch-dir-left::before { content: ""; position: absolute; top: 2px; left: 23px; width: 33px; height: 22px; background: inherit; z-index: 1; } .wmsx-touch-dir-joy .wmsx-touch-dir-left::after { content: ""; position: absolute; top: 4px; left: 30px; height: 17px; width: 17px; border-radius: 100%; box-shadow:  inset 0 0 2px hsl(0, 0%, 22%), inset 1px 2px 3px 1px hsl(0, 0%, 26%), inset -1px -2px 1px hsl(0, 0%, 64%); z-index: 2; } .wmsx-touch-dir-key .wmsx-touch-dir-up, .wmsx-touch-dir-key .wmsx-touch-dir-left, .wmsx-touch-dir-key .wmsx-touch-dir-down, .wmsx-touch-dir-key .wmsx-touch-dir-right { position: absolute; background: rgb(70, 85, 180); border: 0 solid hsl(232, 44%, 37%); border-width: 1px 2px 4px; border-top-color: hsl(232, 44%, 40%); border-bottom-color: hsl(232, 44%, 24%); border-radius: 2px 2px 0 0; box-sizing: border-box; } .wmsx-touch-dir-key .wmsx-touch-dir-up, .wmsx-touch-dir-key .wmsx-touch-dir-down { left: 50px; width: 30px; } .wmsx-touch-dir-key .wmsx-touch-dir-up { top: 26px; height: 25px; border-bottom-width: 2px; } .wmsx-touch-dir-key .wmsx-touch-dir-down { bottom: 26px; height: 27px; } .wmsx-touch-dir-key .wmsx-touch-dir-left, .wmsx-touch-dir-key .wmsx-touch-dir-right { top: 47px; width: 25px; height: 36px; } .wmsx-touch-dir-key .wmsx-touch-dir-left { left: 24px; } .wmsx-touch-dir-key .wmsx-touch-dir-right { right: 24px; } .wmsx-touch-dir-key .wmsx-touch-dir-up::after { content: ""; position: absolute; top: 26px; left: -1px; width: 28px; height: 22px; background: hsl(0, 0%, 20%); } .wmsx-touch-dir .wmsx-arrow-up, .wmsx-touch-dir .wmsx-arrow-down, .wmsx-touch-dir .wmsx-arrow-left, .wmsx-touch-dir .wmsx-arrow-right { position: absolute; border-width: 5px; z-index: 2; } .wmsx-touch-dir .wmsx-arrow-up { top: 26px; left: 60px; border-bottom-width: 11px; } .wmsx-touch-dir .wmsx-arrow-down { bottom: 29px; left: 60px; border-top-width: 11px; } .wmsx-touch-dir .wmsx-arrow-left { top: 58px; left: 26px; border-right-width: 11px; } .wmsx-touch-dir .wmsx-arrow-right { top: 58px; right: 26px; border-left-width: 11px; } .wmsx-touch-button { position: relative; display: block; width: 72px; height: 72px; font-size: 20px; line-height: 67px; color: hsl(0, 0%, 79%); border-radius: 100%; cursor: default; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; z-index: 0; } .wmsx-touch-button::before { content: ""; position: absolute; box-sizing: border-box; z-index: -1; } .wmsx-touch-button-joy::before, .wmsx-touch-button-none::before { width: 50px; height: 48px; top: 9px; left: 11px; border-radius: 100%; } #wmsx-screen-fs.wmsx-touch-config-active .wmsx-touch-button-none::before { border: 2px solid hsl(0, 0%, 30%); } .wmsx-touch-button-joy.wmsx-touch-button-joy-A::before { border: none; background: hsl(120, 76%, 31%); box-shadow: inset 0 2px hsl(120, 76%, 41%), 0 4px 0 1px hsl(120, 76%, 20%); } .wmsx-touch-button-joy.wmsx-touch-button-joy-B::before { border: none; background: hsl(0, 60%, 35%); box-shadow: inset 0 2px hsl(0, 60%, 48%), 0 4px 0 1px hsl(0, 60%, 23%); } .wmsx-touch-button-joy.wmsx-touch-button-joy-AB::before { border: none; background: hsl(240, 50%, 48%); box-shadow: inset 0 2px hsl(240, 50%, 60%), 0 4px 0 1px hsl(240, 50%, 31%); } .wmsx-touch-button-key { font-size: 16px; line-height: 69px; } .wmsx-touch-button-key::before { width: 48px; height: 46px; top: 13px; left: 12px; background: hsl(0, 0%, 44%); border: 4px solid hsl(0, 0%, 31%); border-top: 2px solid hsl(0, 0%, 54%); border-bottom: 6px solid hsl(0, 0%, 22%); border-radius: 3px 3px 1px 1px; } #wmsx-touch-T_A { z-index: 7 } #wmsx-touch-T_B { z-index: 6 } #wmsx-touch-T_C { z-index: 5 } #wmsx-touch-T_D { z-index: 4 } #wmsx-touch-T_E { z-index: 3 } #wmsx-touch-T_F { z-index: 2 } #wmsx-touch-T_G { z-index: 1 } #wmsx-touch-T_X { z-index: 1 } #wmsx-touch-T_Y { z-index: 1 } #wmsx-touch-pause, #wmsx-touch-fast { float: left; width: 46px; height: 48px; border-color: hsl(0, 0%, 70%); } #wmsx-touch-pause::after, #wmsx-touch-fast::before, #wmsx-touch-fast::after { content: ""; display: inline-block; border: 0 solid transparent; box-sizing: border-box; } #wmsx-touch-pause::after { margin-top: 16px; width: 14px; height: 16px; border-width: 0; border-left-width: 4px; border-left-color: inherit; border-right-width: 4px; border-right-color: inherit; } #wmsx-touch-fast::before, #wmsx-touch-fast::after { margin-top: 16px; width: 12px; height: 16px; border-width: 8px; border-left-width: 12px; border-left-color: inherit; border-right-width: 0; } #wmsx-touch-speed.wmsx-paused #wmsx-touch-pause::after, #wmsx-touch-speed.wmsx-poweroff #wmsx-touch-pause::after { margin-top: 14px; width: 17px; height: 20px; border-width: 10px; border-left-width: 17px; border-right-width: 0; } #wmsx-touch-speed.wmsx-paused  #wmsx-touch-fast::after { width: 7px; border-width: 0; border-left-width: 3px; } #wmsx-touch-speed.wmsx-poweroff #wmsx-touch-fast { display: none; } .wmsx-hd-first { float: left; } #wmsx-drop-area { position: absolute; display: none; bottom: 56px; width: 574px; height: 238px; margin: auto; padding: 0; font-size: 0; line-height: 0; color: hsl(0, 0%, 82%); background: black; text-align: left; transform-origin: left bottom; z-index: 99; } #wmsx-drop-area.wmsx-visible { display: block; } #wmsx-drop-area > div { position: relative; display: inline-block; width: 178px; height: 90px; margin: 10px 0 0 10px; padding: 0; font-size: 19px; line-height: 24px; text-shadow: 2px 2px black; text-align: center; background: hsl(0, 0%, 16%); vertical-align: bottom; box-sizing: border-box; } #wmsx-drop-area > div.wmsx-disabled { color: #616161; } #wmsx-drop-area > div:not(.wmsx-disabled).wmsx-selected { background: hsl(358, 67%, 38%); } #wmsx-drop-area-message { position: absolute; left: 0; right: 0; bottom: 2px; height: 34px; font-size: 16px; line-height: 34px; text-align: center; } #wmsx-drop-area i { display: inline-block; margin: 11px auto 7px; width: 41px; height: 36px; background: url("'+wmsx.Images.urls.sprites+'"); background-size: 568px 206px; vertical-align: bottom; } #wmsx-drop-drivea i { background-position: -334px -107px; } #wmsx-drop-drivea.wmsx-disabled i { background-position: -334px -156px; } #wmsx-drop-driveb i { background-position: -392px -107px; } #wmsx-drop-driveb.wmsx-disabled i { background-position: -392px -156px; } #wmsx-drop-driveh i { background-position: -508px -107px; } #wmsx-drop-driveh.wmsx-disabled i { background-position: -508px -156px; } #wmsx-drop-cart1 i  { background-position: -159px -107px; } #wmsx-drop-cart2 i  { background-position: -217px -107px; } #wmsx-drop-tape i   { background-position: -275px -107px; } .wmsx-drop-add, .wmsx-drop-files { position: absolute; display: none; left: 0; top: 0; width: 50px; height: 34px; padding-top: 10px; font-size: 11px; line-height: 9px; text-shadow: 1px 1px 1px black; border: 3px solid transparent; box-sizing: border-box; white-space: nowrap; overflow: visible; } .wmsx-drop-files { left: unset; right: 0; } .wmsx-drop-add::after { content: "+ DISKS"; } .wmsx-drop-files::after { content: "+ FILES "; } #wmsx-drop-area > div:not(.wmsx-disabled).wmsx-selected .wmsx-drop-add, #wmsx-drop-area > div:not(.wmsx-disabled).wmsx-selected .wmsx-drop-files { display: block; } .wmsx-drop-add.wmsx-selected, .wmsx-drop-files.wmsx-selected { border-color: hsl(0, 0%, 82%); box-shadow: 0 0 0 1px rgba(0, 0, 0, .8); } html.wmsx-full-screen.wmsx-touch-active.wmsx-dir-big #wmsx-touch-left .wmsx-touch-dir { transform: scale(1.2); transform-origin: left center; } html.wmsx-full-screen.wmsx-touch-active.wmsx-touch-mirror.wmsx-dir-big #wmsx-touch-left .wmsx-touch-dir { transform-origin: right center; } #wmsx-touch-left .wmsx-touch-button { margin-left: 11px; } html.wmsx-touch-mirror #wmsx-touch-left .wmsx-touch-button { margin-left: 47px; } #wmsx-touch-T_X { margin-bottom: var(--touch-left-button-vert-margin); } #wmsx-touch-T_Y { margin-top: var(--touch-left-button-vert-margin); } @media only screen and (orientation: landscape) {    /* Landscape */ #wmsx-touch-left { left: calc(-6px - '+this.TOUCH_CONTROLS_LEFT_WIDTH+"px); bottom: 50%; transform: translateY(50%); --touch-left-button-vert-margin: 10px; } html.wmsx-full-screen.wmsx-touch-active.wmsx-dir-big #wmsx-touch-left { left: calc(-6px - "+this.TOUCH_CONTROLS_LEFT_WIDTH_BIG+"px); --touch-left-button-vert-margin: 20px; } html.wmsx-touch-mirror #wmsx-touch-left { right: calc(-6px - "+this.TOUCH_CONTROLS_LEFT_WIDTH+"px); left: initial  !important; } html.wmsx-full-screen.wmsx-touch-active.wmsx-touch-mirror.wmsx-dir-big #wmsx-touch-left { right: calc(-6px - "+this.TOUCH_CONTROLS_LEFT_WIDTH_BIG+"px); } #wmsx-touch-right { right: calc(5px - "+this.TOUCH_CONTROLS_RIGHT_WIDTH+"px); bottom: 50%; transform: translateY(50%); } html.wmsx-touch-mirror #wmsx-touch-right { left: calc(5px - "+this.TOUCH_CONTROLS_RIGHT_WIDTH+"px); right: initial  !important; } #wmsx-touch-speed { position: absolute; left: -106px; top: 8px; } html.wmsx-full-screen.wmsx-touch-active.wmsx-dir-big #wmsx-touch-speed { left: -130px; } html.wmsx-touch-mirror #wmsx-touch-speed { right: -106px; left: initial  !important; } html.wmsx-full-screen.wmsx-touch-active.wmsx-touch-mirror.wmsx-dir-big #wmsx-touch-speed { right: -130px; } /* Adjust centered elements leaving space to the touch controls on both sides */ html.wmsx-full-screen.wmsx-touch-active #wmsx-screen-fs-center { left: "+this.TOUCH_CONTROLS_LEFT_WIDTH+"px; right: "+this.TOUCH_CONTROLS_RIGHT_WIDTH+"px; } html.wmsx-full-screen.wmsx-touch-active.wmsx-dir-big #wmsx-screen-fs-center { left: "+this.TOUCH_CONTROLS_LEFT_WIDTH_BIG+"px; } html.wmsx-full-screen.wmsx-touch-active.wmsx-touch-mirror #wmsx-screen-fs-center { right: "+this.TOUCH_CONTROLS_LEFT_WIDTH+"px; left: "+this.TOUCH_CONTROLS_RIGHT_WIDTH+"px; } html.wmsx-full-screen.wmsx-touch-active.wmsx-touch-mirror.wmsx-dir-big #wmsx-screen-fs-center { right: "+this.TOUCH_CONTROLS_LEFT_WIDTH_BIG+"px; } } @media only screen and (orientation: landscape) and (max-height: 511px) {    /* Medium/Large Landscape */ #wmsx-touch-left { --touch-left-button-vert-margin: 10px  !important; } #wmsx-touch-T_F, #wmsx-touch-T_G { display: none; } #wmsx-touch-speed { top: 2px; } } @media only screen and (orientation: landscape) and (max-height: 410px) {    /* Medium Landscape */ #wmsx-touch-left { --touch-left-button-vert-margin: -2px  !important; } } @media only screen and (orientation: landscape) and (max-height: 359px) {    /* Short Landscape */ #wmsx-touch-left { --touch-left-button-vert-margin: 6px  !important; } #wmsx-touch-T_E { display: none; } #wmsx-touch-T_X { visibility: hidden; } #wmsx-touch-speed { top: 8px; } } @media only screen and (orientation: portrait) {    /* Portrait */ #wmsx-touch-left { left: 2px; bottom: 182px; } html.wmsx-touch-mirror #wmsx-touch-left { right: 2px; left: initial  !important; } #wmsx-touch-right { right: 5px; bottom: 36px; width: 112px; height: 224px; } html.wmsx-touch-mirror #wmsx-touch-right { left: 77px; right: initial  !important; } #wmsx-touch-speed { position: absolute; left: 19px; bottom: "+(this.BAR_HEIGHT+10)+"px; } html.wmsx-touch-mirror #wmsx-touch-speed { right: 19px; left: initial  !important; } .wmsx-touch-button { position: absolute; } #wmsx-touch-T_A { bottom: 75%; right: 50%; } #wmsx-touch-T_B { bottom: 100%; right: 0%; } #wmsx-touch-T_C { bottom: 50%; right: 100%; } #wmsx-touch-T_D { bottom: 25%; right: 50%; } #wmsx-touch-T_E { bottom: 50%; right: 0%; } #wmsx-touch-T_F { bottom: 0%; right: 100%; } #wmsx-touch-T_G { bottom: 0%; right: 0%; } #wmsx-touch-T_X { display: none; } #wmsx-touch-T_Y { bottom: -88px; } html.wmsx-touch-mirror #wmsx-touch-T_B { right: 100%; } html.wmsx-touch-mirror #wmsx-touch-T_C { right: 0%; } html.wmsx-touch-mirror #wmsx-touch-T_E { right: 100%; } html.wmsx-touch-mirror #wmsx-touch-T_F { right: 0%; } html.wmsx-touch-mirror #wmsx-touch-T_G { right: 100%; } html.wmsx-full-screen.wmsx-virtual-keyboard-active #wmsx-touch-left, html.wmsx-full-screen.wmsx-virtual-keyboard-active #wmsx-touch-right { display: none; } } @media only screen and (orientation: portrait) and (max-device-height: 638px) {    /* Medium Portrait. Like iPhone 5 */ #wmsx-touch-right { bottom: -18px; } #wmsx-touch-T_F, #wmsx-touch-T_G { display: none; } } @media only screen and (orientation: portrait) and (max-device-height: 518px) {    /* Short Portrait. Like iPhone 4 */ #wmsx-touch-left { bottom: 98px; } #wmsx-touch-right { bottom: -74px; } #wmsx-touch-T_E, #wmsx-touch-T_Y { display: none; } #wmsx-touch-T_D { bottom: 50%; right: 0%; } html.wmsx-touch-mirror #wmsx-touch-T_D { right: 100%; } }"
},wmsx.VirtualKeyboard={create:function(a,b,c,d,e,f){"use strict";var g=document.createElement("div");g.style.position="absolute",a.appendChild(g);var h=[];for(var i in this.sections){var j=document.createElement("div");j.classList.add("wmsx-keyboard-"+i),g.appendChild(j);for(var k=this.sections[i],l=0,m=0;m<k.length;++m){var n=document.createElement("div");n.style.top=l+"px",l+=this.sectionRowHeight[i],j.appendChild(n);for(var o=k[m],p=1,q=0;q<o.length;++q){var r=o[q],s="wmsx-keyboard-"+r.toLowerCase(),t=document.createElement("div");if(!this.byCSSKeys.has(r)){var u=this.keyWidth[r]||this.sectionKeyWidth[i];t.style.width=u+"px",t.style.left=p+"px",p+=this.keySpace[r]||u+1}t.classList.add("wmsx-keyboard-key"),t.classList.add(s),this.dark.indexOf(s)>=0&&t.classList.add("wmsx-keyboard-key-dark"),t.wmsxKeyID=r,t.wmsxKey=this.idToMSMKey[r]||r,n.appendChild(t),h.push(t),b&&b(t)}}}return this.updateKeysLabels(h,c,d,e,f),h},updateKeysLabels:function(a,b,c,d,e){this.finalLabels.COD=this.finalLabels.KANA=d||"CODE";var f,g,h;e?(f="cns_"+c,g="c_"+c,h="c_en"):(f=(b?"cs_":"c_")+c,g=b?"cs_en":"c_en",h="c_en");for(var i=a.length-1;i>=0;--i){var j=a[i];if(!this.blankKeys.has(j.wmsxKeyID)){var k=wmsx.KeyboardKeys[j.wmsxKey][f]||wmsx.KeyboardKeys[j.wmsxKey][g]||wmsx.KeyboardKeys[j.wmsxKey][h];k=this.finalLabels[k]||k,j.wmsxLabel!==k&&(j.wmsxLabel=k,j.innerHTML=k)}}},sections:{alpha:[["F1","F2","F3","F4","F5","STOP","SELECT","HOME","INSERT","DELETE"],["ESCAPE","D1","D2","D3","D4","D5","D6","D7","D8","D9","D0","MINUS","EQUAL","BACKSLASH","BACKSPACE"],["TAB","Q","W","E","R","T","Y","U","I","O","P","OPEN_BRACKET","CLOSE_BRACKET","ENTER_X1","ENTER_X2"],["CONTROL","A","S","D","F","G","H","J","K","L","SEMICOLON","QUOTE","BACKQUOTE","ENTER"],["SHIFT","Z","X","C","V","B","N","M","COMMA","PERIOD","SLASH","DEAD","SHIFT2"],["CAPSLOCK","GRAPH","SPACE","CODE"]],num:[["NUM_7","NUM_8","NUM_9","NUM_DIVIDE"],["NUM_4","NUM_5","NUM_6","NUM_MULTIPLY"],["NUM_1","NUM_2","NUM_3","NUM_MINUS"],["NUM_0","NUM_PERIOD","NUM_COMMA","NUM_PLUS"]],arrows:[["LEFT","UP","RIGHT","DOWN"]]},sectionRowHeight:{alpha:25,num:23,arrows:50},sectionKeyWidth:{alpha:26,num:22},keyWidth:{F1:39,F2:39,F3:39,F4:39,F5:39,STOP:39,SELECT:39,HOME:39,INSERT:39,DELETE:39,ESCAPE:29,BACKSPACE:28,TAB:41,CONTROL:48,SHIFT:61,SHIFT2:61,ENTER:36,ENTER_X1:13,ENTER_X2:30,SPACE:189,CAPSLOCK:38,DEAD:38,GRAPH:46,CODE:46},keySpace:{STOP:50,ENTER_X1:13,CAPSLOCK:55},dark:["wmsx-keyboard-escape","wmsx-keyboard-tab","wmsx-keyboard-control","wmsx-keyboard-shift","wmsx-keyboard-capslock","wmsx-keyboard-graph","wmsx-keyboard-backspace","wmsx-keyboard-enter","wmsx-keyboard-enter_x1","wmsx-keyboard-enter_x2","wmsx-keyboard-shift2","wmsx-keyboard-code","wmsx-keyboard-num_divide","wmsx-keyboard-num_multiply","wmsx-keyboard-num_minus","wmsx-keyboard-num_plus"],idToMSMKey:{ENTER_X1:"ENTER",ENTER_X2:"ENTER",SHIFT2:"SHIFT"},finalLabels:{STP:"STOP",HOM:"HOME",CTR:"CTRL",SHF:"SHIFT",CAP:"CAPS",SPC:"SPACE",GRA:"GRAPH",COD:"CODE"},blankKeys:new Set(["ENTER_X1","ENTER_X2","UP","DOWN","LEFT","RIGHT"]),byCSSKeys:new Set(["SHIFT2","SPACE","CODE","DEAD","UP","DOWN","LEFT","RIGHT"])},wmsx.Monitor=function(a){"use strict";function b(){l=-1===j?k:j,h.videoSignalDisplayStateUpdate(1!==l,2===l),i&&i.videoSignalDisplayStateUpdate(0!==l,2===l),a.videoOutputModeUpdate(j,l,0===k,f(-1),i&&i.getSignalName()),h.refreshDisplayMetrics(),i&&i.refreshDisplayMetrics()}function c(){h.setColorAndPaletteMode(m,n),i&&i.setColorAndPaletteMode(m,n)}function d(){a.showOSD("Video Output: "+e(j),!0)}function e(a){switch(a){case 0:return"Internal";case 1:return i?i.getSignalName():"External";case 2:return"Superimposed";case 3:return"Mixed";case 4:case 5:var b=i?i.getSignalName():"External";return"Dual Screen "+(4===a?"(Internal + "+b+")":"("+b+" + Internal)");default:return"Auto ("+e(k)+")"}}function f(a){switch(a){case 0:return"Internal";case 1:return i?i.getSignalName():"External";case 2:return"Superimp";case 3:return"Mixed";case 4:case 5:return"Dual";default:return"Auto ("+f(k)+")"}}function g(a){return 1!==l&&a===h||0!==l&&a===i}this.connectInternalVideoSignal=function(a){h=a,h.connectMonitor(this),m=WMSX.SCREEN_COLORS>=0&&WMSX.SCREEN_COLORS<=3?WMSX.SCREEN_COLORS:0,n=WMSX.VDP_PALETTE>=0&&WMSX.VDP_PALETTE<=5?WMSX.VDP_PALETTE:2,c(),b()},this.connectExternalVideoSignal=function(a){i=a,i.connectMonitor(this),WMSX.SCREEN_VIDEO_OUT>=0?this.setOutputMode(WMSX.SCREEN_VIDEO_OUT,!0):b()},this.disconnectExternalVideoSignal=function(a){i===a&&(i=void 0,k=0,j=-1,b())},this.toggleOutputMode=function(a){a?this.setOutputMode(j<=-1?3:j-1):this.setOutputMode(j>=3?-1:j+1)},this.resetOutputAutoMode=function(){h.resetOutputAutoMode(),i&&i.resetOutputAutoMode(),-1!==j&&this.setOutputMode(-1)},this.setOutputAutoMode=function(a,c){var e=l;k=c,b(),e!==l&&d()},this.setOutputMode=function(c,e){j=!i||c<-1?-1:c<4?c:a.isDualScreenAllowed()?c>5?5:c:-1,b(),e||d()},this.setOutputModeDual=function(){a.isDualScreenAllowed()&&(j>=4?(j=4===j?5:4,b(),d()):this.setOutputMode(0===l?4:5))},this.toggleColorMode=function(b){m=b?m<=0?3:m-1:m>=3?0:m+1,c(),a.showOSD("Screen Color Mode: "+o[m],!0)},this.togglePaletteMode=function(b){n=b?n<=0?5:n-1:n>=5?0:n+1,c(),a.showOSD("MSX1 Palette: "+p[n],!0)},this.newFrame=function(b,c,d,e,f,i){g(b)&&a.refresh(c,d,e,f,i,b===h)},this.signalOff=function(b){a.videoSignalOff()},this.showOSD=function(b,c,d){a.showOSD(b,c,d)},this.setDisplayMetrics=function(b,c,d){g(b)&&a.displayMetrics(c,d,b===h)},this.setDebugMode=function(b,c){a.setDebugMode(c)},this.getScreenText=function(){return h.getScreenText()},this.saveState=function(){return{m:j,me:l,ma:k,cm:m,pm:n}},this.loadState=function(a){a?(j=a.m,k=a.ma,m=a.cm||0,n=a.pm||0):(j=-1,k=0,m=0,n=2),c(),this.setOutputMode(j,!0)};var h,i,j=-1,k=0,l=0,m=0,n=2,o=["Color","B&W","Green Phosphor","Amber Phosphor"],p=["WebMSX Original","V9918","V9928","V9938","Toshiba","Fujitsu FM-X"]},wmsx.CanvasDisplay=function(room,mainElement){"use strict";function init(){wmsx.Util.insertCSS(document,wmsx.ScreenGUI.css()),setupMain(),setupBar(),setupFileLoaderDropTargets(),setupFullscreen(),monitor=new wmsx.Monitor(self)}function updateDisplayMetrics(a,b,c,d,e){updatePixelMetrics(a,b,d,e),targetWidth===c&&scrTargetWidth===d&&targetHeight===e||(targetWidth=c,scrTargetWidth=d,targetHeight=e,updateCanvasContentSize(),isFullscreen?requestReadjust(!0):updateScale())}function updatePixelMetrics(a,b,c,d){var e=c/a,f=d/b;pixelWidth===e&&pixelHeight===f||(pixelWidth=e,pixelHeight=f,refreshPixelMetrics())}function auxUpdateDisplayMetrics(a,b,c,d,e){if(auxTargetWidth!==c||auxScrTargetWidth!==d||auxTargetHeight!==e){if(auxTargetWidth=c,auxScrTargetWidth=d,auxTargetHeight=e,!auxWindow)return!1;auxUpdateCanvasContentSize(),auxReadjustAll(!0)}}function displayScale(a,b){aspectX=a,scaleY=b,updateScale(),refreshPixelMetrics()}function auxDisplayScale(a,b,c){auxAspectX=a,auxScaleY=b,auxUpdateScale(c)}function refreshPixelMetrics(){controllersHub&&controllersHub.setScreenPixelScale(pixelWidth*scaleY*aspectX,pixelHeight*scaleY)}function hideOSDs(){osd.style.transition=auxOsd.style.transition="all 0.15s linear",osd.style.top=auxOsd.style.top="-29px",osd.style.opacity=auxOsd.style.opacity=0,osdShowing=!1}function displayDefaultScale(){if(WMSX.SCREEN_DEFAULT_SCALE>0)return WMSX.SCREEN_DEFAULT_SCALE;var a=mainElement.parentElement.clientWidth;return crtScanlines?a>=660?1:a>=420?.75:.5:a>=660?1.1:a>=540?.9:a>=420?.7:a>=320?.55:.5}function aspectAndScaleSetDefault(){if(isFocusOnAuxWindow())return auxAspectAndScaleSetDefault();aspectX=WMSX.SCREEN_DEFAULT_ASPECT,scaleY=displayDefaultScale(),scaleYBeforeUserFullscreen=0,requestReadjust(!0)}function auxAspectAndScaleSetDefault(){auxAspectX=WMSX.SCREEN_DEFAULT_ASPECT,auxScaleY=displayDefaultScale(),auxReadjustAll(!0)}function crtFilterSetDefault(){var a=WMSX.userPreferences.current.crtFilter
;setCRTFilter(-3!==WMSX.SCREEN_FILTER_MODE?WMSX.SCREEN_FILTER_MODE:null!==a&&a>-3?a:-1)}function crtScanlinesSetDefault(){var a=WMSX.userPreferences.current.crtScanlines;setCRTScanlines(-1!==WMSX.SCREEN_CRT_SCANLINES?Math.max(0,Math.min(10,WMSX.SCREEN_CRT_SCANLINES)):null!==a&&a>-1?a:0)}function crtPhosphorSetDefault(){setCRTPhosphor(WMSX.SCREEN_CRT_PHOSPHOR)}function auxDisplayToggleFullscreen(){auxIsFullScreenByAPI()?auxExitFullScreenByAPI():auxEnterFullScreenByAPI()}function normalizeAspectX(a){var b=a<.5?.5:a>2.5?2.5:a;return Math.round(b/ASPECT_STEP)*ASPECT_STEP}function normalizeScaleY(a){var b=a<.5?.5:a;return Math.round(b/SCALE_STEP)*SCALE_STEP}function requestReadjust(a,b){a?readjustAll(!0,b):(readjustRequestTime=wmsx.Util.performanceNow(),readjustInterval||(readjustInterval=setInterval(readjustAll,50)))}function setVirtualKeyboard(a){if(virtualKeyboardMode!==a){if(a){if(!isTouchDevice)return self.showOSD("Virtual Keyboard unavailable. Not a touch device!",!0,!0);virtualKeyboardElement||setupVirtualKeyboard(),virtualKeyboardElement.classList.toggle("wmsx-keyboard-narrow",2==a)}showCursorAndBar(!0),document.documentElement.classList.toggle("wmsx-virtual-keyboard-active",!!a),virtualKeyboardMode=a,requestReadjust(!0)}}function releaseControllersOnLostFocus(){controllersSocket.releaseControllers()}function hideCursorAndBar(){hideCursor(),hideBar(),cursorHideFrameCountdown=-1}function showCursorAndBar(a){showCursor(),!a&&mousePointerLocked||showBar(),cursorHideFrameCountdown=CURSOR_HIDE_FRAMES}function showCursor(){cursorShowing||(fsElement.style.cursor=cursorType,cursorShowing=!0)}function hideCursor(){cursorShowing&&(fsElement.style.cursor="none",cursorShowing=!1)}function fullscreenByAPIChanged(){var a=isFullscreen,b=isFullScreenByAPI();b||fullScreenAPIExitUserRequested||!isMobileDevice?setFullscreenState(b):requestReadjust(),isMobileDevice&&a&&!b&&!fullScreenAPIExitUserRequested&&setEnterFullscreenByAPIOnFirstTouch(),fullScreenAPIExitUserRequested=!1}function isFullScreenByAPI(){return!!document[fullScreenAPIQueryProp]}function enterFullScreenByAPI(){if(fullscreenAPIEnterMethod)try{fullscreenAPIEnterMethod.call(fsElement)}catch(a){}}function exitFullScreenByAPI(){if(fullScreenAPIExitMethod)try{fullScreenAPIExitUserRequested=!0,fullScreenAPIExitMethod.call(document)}catch(a){}}function auxEnterFullScreenByAPI(){if(fullscreenAPIEnterMethod)try{fullscreenAPIEnterMethod.call(auxFsElementCenter)}catch(a){}}function auxExitFullScreenByAPI(){if(fullScreenAPIExitMethod)try{fullScreenAPIExitMethod.call(auxWindow.document)}catch(a){}}function auxIsFullScreenByAPI(){return!!auxWindow.document[fullScreenAPIQueryProp]}function auxIsMaxed(){return auxIsFullScreenByAPI()||auxWindow.outerWidth>=auxWindow.screen.availWidth&&auxWindow.outerHeight>=auxWindow.screen.availHeight}function updateScale(){var a=Math.round(scrTargetWidth*scaleY*aspectX),b=Math.round(targetHeight*scaleY);canvas.style.width=a+"px",canvas.style.height=b+"px",updateBarWidth(a),signalIsOn||updateLogoScale(),settingsDialog&&settingsDialog.isVisible()&&settingsDialog.position()}function auxUpdateScale(a){var b=Math.round(auxScrTargetWidth*auxScaleY*auxAspectX),c=Math.ceil(auxTargetHeight*auxScaleY);auxCanvas.style.width=b+"px",auxCanvas.style.height=c+"px",a&&auxWindow.resizeTo(b+auxWindowAddWidth,c+auxWindowAddHeight)}function updateBarWidth(a){var b=buttonsBarDesiredWidth>0?buttonsBarDesiredWidth:a;buttonsBar.style.width=-1===buttonsBarDesiredWidth?"100%":b+"px";var c=buttonsBar.clientWidth;buttonsBar.classList.toggle("wmsx-narrow",c<NARROW_WIDTH),buttonsBar.classList.toggle("wmsx-semi-narrow",c<SEMI_NARROW_WIDTH)}function updateKeyboardWidth(a){var b=Math.min(1024,a),c=1===virtualKeyboardMode?VIRTUAL_KEYBOARD_WIDE_WIDTH:VIRTUAL_KEYBOARD_NARROW_WIDTH,d=b/c;return virtualKeyboardElement.style.width=c+"px",virtualKeyboardElement.style.transform="translateX(-50%) scale("+d.toFixed(8)+")",{w:b,h:Math.ceil(VIRTUAL_KEYBOARD_HEIGHT*d)}}function updateCanvasContentSize(){canvas.width=targetWidth,canvas.height=targetHeight,canvasContext=null}function auxUpdateCanvasContentSize(){auxCanvas.width=auxTargetWidth,auxCanvas.height=auxTargetHeight,auxCanvasContext=null}function setCRTFilter(a){crtFilter=a,crtFilterEffective=-2===crtFilter?null:-1===crtFilter?crtFilterAutoValue():a,canvasContext=null}function crtFilterAutoValue(){return isMobileDevice&&isAndroidDevice&&"FIREFOX"===browserName?2:1}function setCRTScanlines(a){crtScanlines=a,crtScanlines&&setupScanlines(),canvasContext=null}function setCRTPhosphor(a){crtPhosphor=a,crtPhosphorEffective=-1===crtPhosphor?0:crtPhosphor,canvasContext=null}function updateLogo(){signalIsOn||(updateLogoScale(),closePowerOnModals(),showCursorAndBar(!0),canvasContext&&canvasContext.clearRect(0,0,canvas.width,canvas.height)),logo.classList.toggle("wmsx-show",!signalIsOn),auxWindow&&auxLogo.classList.toggle("wmsx-show",!signalIsOn)}function updateLoading(){var a=isLoading?"block":"none";logoLoadingIcon.style.display=a,canvasLoadingIcon.style.display=a}function createCanvasContext(){return canvasContext=canvas.getContext("2d",{alpha:!1,antialias:!1}),updateImageComposition(canvasContext),updateImageSmoothing(canvasContext),canvasContext}function auxCreateCanvasContext(){if(auxWindow)return auxCanvasContext=auxCanvas.getContext("2d",{alpha:!1,antialias:!1}),updateImageComposition(auxCanvasContext),updateImageSmoothing(auxCanvasContext),auxCanvasContext}function updateImageComposition(a){a.globalCompositeOperation=debugMode?"copy":videoOutputMode<=1||videoOutputMode>=4?crtPhosphorEffective?"source-over":"copy":3===videoOutputMode?"lighten":"source-over",a.globalAlpha=debugMode?1:videoOutputMode<=1||videoOutputMode>=4?crtPhosphorEffective?.8:1:3===videoOutputMode?.66:1}function updateImageSmoothing(a){if(null!==crtFilterEffective){canvas.style.imageRendering=1===crtFilterEffective||3===crtFilterEffective?"initial":canvasImageRenderingValue;var b=crtFilterEffective>=2;void 0!==a.imageSmoothingEnabled?a.imageSmoothingEnabled=b:(a.webkitImageSmoothingEnabled=b,a.mozImageSmoothingEnabled=b,a.msImageSmoothingEnabled=b)}}function updateLeds(){ledsStatePending&&(capsLed.classList.toggle("wmsx-hidden",!ledsStatePending[0]),kanaLed.classList.toggle("wmsx-hidden",!ledsStatePending[1]),pauseLed.classList.toggle("wmsx-hidden",!ledsStatePending[2]),turboButton.classList.toggle("wmsx-hidden",!ledsStatePending[3]&&!ledsStatePending[4]),turboButton.textContent=ledsStatePending[4]>1?ledsInfoPending[4]:ledsInfoPending[3],turboButton.style.backgroundPositionY=(3===ledsStatePending[4]?-91:2===ledsStatePending[4]?-116:1===ledsStatePending[4]?-141:-166)+"px",quickOtionsDialog&&quickOtionsDialog.machineTurboModesStateUpdate(),ledsStatePending=void 0)}function suppressContextMenu(a){a.addEventListener("contextmenu",wmsx.Util.blockEvent)}function preventDrag(a){a.ondragstart=wmsx.Util.blockEvent}function setupMain(){switch(mainElement.innerHTML=wmsx.ScreenGUI.html(),mainElement.tabIndex=-1,delete wmsx.ScreenGUI.html,fsElement=document.getElementById("wmsx-screen-fs"),fsElementCenter=document.getElementById("wmsx-screen-fs-center"),canvasOuter=document.getElementById("wmsx-screen-canvas-outer"),canvas=document.getElementById("wmsx-screen-canvas"),canvasLoadingIcon=document.getElementById("wmsx-canvas-loading-icon"),osd=document.getElementById("wmsx-osd"),logo=document.getElementById("wmsx-logo"),logoCenter=document.getElementById("wmsx-logo-center"),logoImage=document.getElementById("wmsx-logo-image"),logoLoadingIcon=document.getElementById("wmsx-logo-loading-icon"),logoMessage=document.getElementById("wmsx-logo-message"),logoMessageText=document.getElementById("wmsx-logo-message-text"),logoMessageOK=document.getElementById("wmsx-logo-message-ok"),logoMessageOKText=document.getElementById("wmsx-logo-message-ok-text"),scrollMessage=document.getElementById("wmsx-screen-scroll-message"),
unmuteMessage=document.getElementById("wmsx-unmute-message"),suppressContextMenu(mainElement),preventDrag(logoImage),preventDrag(logoLoadingIcon),preventDrag(canvasLoadingIcon),updateCanvasContentSize(),browserName){case"CHROME":case"EDGE":case"OPERA":canvasImageRenderingValue="pixelated";break;case"FIREFOX":canvasImageRenderingValue="-moz-crisp-edges";break;case"SAFARI":canvasImageRenderingValue="-webkit-optimize-contrast";break;default:canvasImageRenderingValue="pixelated"}setupMainEvents()}function setupAndShowAuxWindow(){if(!auxWindow){var a=displayDefaultScale(),b=wmsx.VDP.SIGNAL_MAX_WIDTH_V9938*auxAspectX*a,c=wmsx.VDP.SIGNAL_MAX_HEIGHT_V9938*a,d=window.open("","WebMSX: 2nd Video","width="+b+",height="+(c+1)+",scrollbars=no,status=no,location=no,toolbar=no,menubar=no"),e=d.document;e.open("text/html","replace").write(wmsx.ScreenGUI.auxHtml()),e.close()}}function auxWindowResized(){auxReadjustAll(!1,!0)}function auxWindowUnload(){monitor.setOutputMode(-1),self.focus()}function closeAuxWindow(){auxWindow&&(self.focus(),auxWindow.removeEventListener("resize",auxWindowResized),auxWindow.removeEventListener("beforeunload",auxWindowUnload),auxWindow.close(),auxWindow=auxFsElementCenter=auxLogo=auxCanvas=auxCanvasContext=void 0,auxOsd={style:{}})}function auxWindowUpdateTitle(){auxWindow&&(auxWindow.document.title="WebMSX: "+(4===videoOutputMode?"V9990 Video":"Internal Video"))}function isFocusOnAuxWindow(){return auxWindow&&auxWindow.document.hasFocus()}function setupScanlines(){if(!scanlinesImage){scanlinesImage=document.createElement("canvas"),scanlinesImage.width=1,scanlinesImage.height=wmsx.V9990.SIGNAL_MAX_HEIGHT;var a=scanlinesImage.getContext("2d",{alpha:!0,antialias:!1});a.clearRect(0,0,1,scanlinesImage.height),a.fillStyle="black";for(var b=1,c=scanlinesImage.height;b<c;b+=2)a.fillRect(0,b,1,1)}}function setupMainEvents(){(isMobileDevice?canvasOuter:fsElement).addEventListener("mousemove",function(){showCursorAndBar()}),"onblur"in document?fsElement.addEventListener("blur",releaseControllersOnLostFocus,!0):fsElement.addEventListener("focusout",releaseControllersOnLostFocus,!0),window.addEventListener("orientationchange",function(){closeAllOverlays(),signalIsOn?hideCursorAndBar():showCursorAndBar(),requestReadjust()}),window.addEventListener("resize",function(){isFullscreen&&(closeAllOverlays(!0),signalIsOn?hideCursorAndBar():showCursorAndBar(),requestReadjust(!0,!0))}),mainElement.addEventListener("drop",closeAllOverlays,!1),logoMessageOK.wmsxNeedsUIG=logoMessageOKText.wmsxNeedsUIG=!0,wmsx.Util.onTapOrMouseDownWithBlockUIG(logoMessageOK,closeLogoMessage),wmsx.Util.addEventsListener(fsElementCenter,"touchstart touchend mousedown",function(a){"touchend"!==a.type?(closeAllOverlays(),showCursorAndBar()):a.cancelable&&a.preventDefault()}),window.addEventListener("beforeunload",closeAuxWindow)}function setupVirtualKeyboard(){virtualKeyboardElement=document.createElement("div"),virtualKeyboardElement.id="wmsx-virtual-keyboard",fsElementCenter.appendChild(virtualKeyboardElement),virtualKeyboard=new wmsx.DOMVirtualKeyboard(virtualKeyboardElement,controllersHub.getKeyboard(),machineTypeSocket)}function setupBar(){buttonsBar=document.getElementById("wmsx-bar"),buttonsBarInner=document.getElementById("wmsx-bar-inner"),BAR_AUTO_HIDE&&(document.documentElement.classList.add("wmsx-bar-auto-hide"),fsElement.addEventListener("mouseleave",hideBar),hideBar()),isMobileDevice&&document.documentElement.classList.add("wmsx-bar-mobile");var a=[{label:"Power",clickModif:0,control:wmsx.PeripheralControls.MACHINE_POWER_TOGGLE},{label:"Reset",clickModif:KEY_SHIFT_MASK,control:wmsx.PeripheralControls.MACHINE_POWER_RESET},{label:"",divider:!0},{label:"Net Play!",control:wmsx.PeripheralControls.SCREEN_OPEN_NETPLAY},{label:"",divider:!0},{label:"Open File",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.AUTO_LOAD_FILE,needsUIG:!0},{label:"Open URL",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.AUTO_LOAD_URL,needsUIG:!0},{label:"",divider:!0},{label:"Load State",control:wmsx.PeripheralControls.MACHINE_LOAD_STATE_MENU},{label:"Save State",control:wmsx.PeripheralControls.MACHINE_SAVE_STATE_MENU}];powerButton=addPeripheralControlButton("wmsx-bar-power",-120,-26,!1,"System Power",null,a,"System"),barMenuSystem=a,netplayButton=addPeripheralControlButton("wmsx-bar-netplay",-91,-76,!1,"NetPlay!",wmsx.PeripheralControls.SCREEN_OPEN_NETPLAY),netplayButton.classList.add("wmsx-hidden"),mediaIconsContainer=document.createElement("div"),mediaIconsContainer.id="wmsx-bar-media-icons",mediaIconsContainer.style.display="inline-block",buttonsBarInner.appendChild(mediaIconsContainer),barMenus.push(null),a=[{label:"Load Disk Images",clickModif:0,control:wmsx.PeripheralControls.DISK_LOAD_FILES,secSlot:!1,needsUIG:!0},{label:"Add Disk Images",control:wmsx.PeripheralControls.DISK_ADD_FILES,secSlot:!1,needsUIG:!0},{label:"Add Blank Disk",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.DISK_EMPTY,secSlot:!1},{label:"Add Boot Disk",clickModif:KEY_SHIFT_MASK|KEY_CTRL_MASK,control:wmsx.PeripheralControls.DISK_BOOT,secSlot:!1},{label:"Import Files to Disk",control:wmsx.PeripheralControls.DISK_LOAD_FILES_AS_DISK,secSlot:!1,needsUIG:!0},{label:"Expand ZIP to Disk",control:wmsx.PeripheralControls.DISK_LOAD_ZIP_AS_DISK,secSlot:!1,needsUIG:!0},{label:"Select Disk",control:wmsx.PeripheralControls.DISK_SELECT,secSlot:!1,disabled:!0},{label:"Save Disk Image",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.DISK_SAVE_FILE,secSlot:!1,disabled:!0,needsUIG:!0},{label:"Remove Disk",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.DISK_REMOVE,secSlot:!1,disabled:!0}],diskAButton=addPeripheralControlButton("wmsx-bar-diska",-165,-72,!0,"Drive A",null,a,"Drive A",mediaIconsContainer),WMSX.EXTENSIONS.DISK||diskAButton.classList.add("wmsx-hidden"),a=[{label:"Load Disk Images",clickModif:0,control:wmsx.PeripheralControls.DISK_LOAD_FILES,secSlot:!0,needsUIG:!0},{label:"Add Disk Images",control:wmsx.PeripheralControls.DISK_ADD_FILES,secSlot:!0,needsUIG:!0},{label:"Add Blank Disk",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.DISK_EMPTY,secSlot:!0},{label:"Add Boot Disk",clickModif:KEY_SHIFT_MASK|KEY_CTRL_MASK,control:wmsx.PeripheralControls.DISK_BOOT,secSlot:!0},{label:"Import Files to Disk",control:wmsx.PeripheralControls.DISK_LOAD_FILES_AS_DISK,secSlot:!0,needsUIG:!0},{label:"Expand ZIP to Disk",control:wmsx.PeripheralControls.DISK_LOAD_ZIP_AS_DISK,secSlot:!0,needsUIG:!0},{label:"Select Disk",control:wmsx.PeripheralControls.DISK_SELECT,secSlot:!0,disabled:!0},{label:"Save Disk Image",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.DISK_SAVE_FILE,secSlot:!0,disabled:!0,needsUIG:!0},{label:"Remove Disk",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.DISK_REMOVE,secSlot:!0,disabled:!0}],diskBButton=addPeripheralControlButton("wmsx-bar-diskb",-194,-72,!0,"Drive B",null,a,"Drive B",mediaIconsContainer),WMSX.EXTENSIONS.DISK||diskBButton.classList.add("wmsx-hidden"),a=[{label:"Load Disk Image",clickModif:0,control:wmsx.PeripheralControls.HARDDISK_LOAD_FILE,needsUIG:!0},{label:"New Blank Disk",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.HARDDISK_CHOOSE_EMPTY},{label:"New Boot Disk",clickModif:KEY_SHIFT_MASK|KEY_CTRL_MASK,control:wmsx.PeripheralControls.HARDDISK_CHOOSE_BOOT},{label:"Import Files to Disk",control:wmsx.PeripheralControls.HARDDISK_LOAD_FILES_AS_DISK,needsUIG:!0},{label:"Expand ZIP to Disk",control:wmsx.PeripheralControls.HARDDISK_LOAD_ZIP_AS_DISK,needsUIG:!0},{label:"Save Disk Image",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.HARDDISK_SAVE_FILE,disabled:!0,needsUIG:!0},{label:"Remove Disk",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.HARDDISK_REMOVE,disabled:!0}],
diskHButton=addPeripheralControlButton("wmsx-bar-diskh",-252,-72,!0,"Hard Drive",null,a,"Hard Drive",mediaIconsContainer),WMSX.EXTENSIONS.HARDDISK||diskHButton.classList.add("wmsx-hidden"),2!==WMSX.EXTENSIONS.HARDDISK&&diskHButton.classList.add("wmsx-hd-first"),a=[{label:"Load ROM Image",clickModif:0,control:wmsx.PeripheralControls.CARTRIDGE_LOAD_FILE,secSlot:!1,needsUIG:!0},{label:"Set ROM Format",clickModif:KEY_SHIFT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_CHOOSE_FORMAT,secSlot:!1},{label:"Load Data File",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.CARTRIDGE_LOAD_DATA_FILE,secSlot:!1,disabled:!0,needsUIG:!0},{label:"Save Data File",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_SAVE_DATA_FILE,secSlot:!1,disabled:!0,needsUIG:!0},{label:"Remove Cartridge",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_REMOVE,secSlot:!1,disabled:!0}],cartridge1Button=addPeripheralControlButton("wmsx-bar-cart1",-78,-72,!0,"Cartridge 1",null,a,"Cartridge 1",mediaIconsContainer),a=[{label:"Load ROM Image",clickModif:0,control:wmsx.PeripheralControls.CARTRIDGE_LOAD_FILE,secSlot:!0,needsUIG:!0},{label:"Set ROM Format",clickModif:KEY_SHIFT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_CHOOSE_FORMAT,secSlot:!0},{label:"Load Data File",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.CARTRIDGE_LOAD_DATA_FILE,secSlot:!0,disabled:!0,needsUIG:!0},{label:"Save Data File",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_SAVE_DATA_FILE,secSlot:!0,disabled:!0,needsUIG:!0},{label:"Remove Cartridge",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.CARTRIDGE_REMOVE,secSlot:!0,disabled:!0}],cartridge2Button=addPeripheralControlButton("wmsx-bar-cart2",-107,-72,!0,"Cartridge 2",null,a,"Cartridge 2",mediaIconsContainer),a=[{label:"Load Tape Image",clickModif:0,control:wmsx.PeripheralControls.TAPE_LOAD_FILE,secSlot:!0,needsUIG:!0},{label:"New Blank Tape",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.TAPE_EMPTY,secSlot:!0},{label:"Rewind Tape",control:wmsx.PeripheralControls.TAPE_REWIND,disabled:!0,secSlot:!0},{label:"Run Program",clickModif:KEY_SHIFT_MASK|KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.TAPE_AUTO_RUN,secSlot:!0,disabled:!0},{label:"Save Tape Image",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.TAPE_SAVE_FILE,disabled:!0,secSlot:!0,needsUIG:!0},{label:"Remove Tape",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.TAPE_REMOVE,disabled:!0,secSlot:!0}],tapeButton=addPeripheralControlButton("wmsx-bar-tape",-136,-72,!0,"Cassette",null,a,"Cassette",mediaIconsContainer);var b=document.createElement("div");if(b.id="wmsx-bar-settings-icons",b.style.display="inline-block",buttonsBarInner.appendChild(b),WMSX.SCREEN_RESIZE_DISABLED||isMobileDevice||(scaleDownButton=addPeripheralControlButton("wmsx-bar-scale-minus",-26,-3,!1,"Decrease Screen",wmsx.PeripheralControls.SCREEN_SCALE_MINUS,null,"",b),scaleDownButton.classList.add("wmsx-full-screen-hidden"),scaleUpButton=addPeripheralControlButton("wmsx-bar-scale-plus",-48,-2,!1,"Increase Screen",wmsx.PeripheralControls.SCREEN_SCALE_PLUS,null,"",b),scaleUpButton.classList.add("wmsx-full-screen-hidden")),-2!==FULLSCREEN_MODE&&(fullscreenButton=addPeripheralControlButton("wmsx-bar-full-screen",-71,-1,!1,"Full Screen",wmsx.PeripheralControls.SCREEN_FULLSCREEN,null,"",b),fullscreenButton.wmsxNeedsUIG=!0),a=[{label:"Auto",clickModif:0,control:wmsx.PeripheralControls.SCREEN_OUTPUT_AUTO,toggle:!0,radio:!0},{label:"Internal",clickModif:KEY_SHIFT_MASK,control:wmsx.PeripheralControls.SCREEN_OUTPUT_INTERNAL,toggle:!0,radio:!0},{label:"External",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.SCREEN_OUTPUT_EXTERNAL,toggle:!0,radio:!0},{label:"Superimposed",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.SCREEN_OUTPUT_SUPERIMPOSED,toggle:!0,radio:!0},{label:"Mixed",clickModif:KEY_SHIFT_MASK|KEY_CTRL_MASK,control:wmsx.PeripheralControls.SCREEN_OUTPUT_MIXED,toggle:!0,radio:!0},{label:"",divider:!0},{label:"Dual Screen",clickModif:KEY_ALT_MASK|KEY_CTRL_MASK,control:wmsx.PeripheralControls.SCREEN_OUTPUT_DUAL,toggle:!0},{label:"",divider:!0},{label:"Reset Auto Internal",control:wmsx.PeripheralControls.SCREEN_OUTPUT_RESET_AUTO}],videoOutputButton=addPeripheralControlButton("wmsx-bar-video",-120,-176,!1,"Video Output",null,a,"Video Output",b),videoOutputButton.classList.add("wmsx-hidden"),a=createSettingsMenuOptions(),settingsButton=addPeripheralControlButton("wmsx-bar-settings",-96,-1,!1,"Settings",null,a,"Settings",b),defineSettingsMenuExtensions(),isMobileDevice){addPeripheralControlButton("wmsx-bar-text",-53,-51,!1,"Toggle Text Input",wmsx.PeripheralControls.OPEN_ENTER_STRING)}if(isTouchDevice){addPeripheralControlButton("wmsx-bar-keyboard",-83,-25,!1,"Toggle Virtual Keyboard",wmsx.PeripheralControls.SCREEN_TOGGLE_VIRTUAL_KEYBOARD).classList.add("wmsx-full-screen-only")}var c=addPeripheralControlButton("wmsx-bar-logo",-8,-25,!1,"About WebMSX",wmsx.PeripheralControls.SCREEN_OPEN_ABOUT);isTouchDevice&&c.classList.add("wmsx-full-screen-hidden"),c.classList.add("wmsx-narrow-hidden"),pauseLed=addPeripheralControlButton("wmsx-bar-pause",-94,-101),pauseLed.classList.add("wmsx-semi-narrow-hidden"),pauseLed.classList.add("wmsx-hidden"),turboButton=addPeripheralControlButton("wmsx-bar-turbo",-2,-91,!1,"CPU Turbo",wmsx.PeripheralControls.SCREEN_OPEN_QUICK_OPTIONS),turboButton.classList.add("wmsx-hidden"),kanaLed=addPeripheralControlButton("wmsx-bar-kana",0,0),kanaLed.classList.add("wmsx-semi-narrow-hidden"),kanaLed.classList.add("wmsx-hidden"),capsLed=addPeripheralControlButton("wmsx-bar-caps",0,0),capsLed.textContent="CAPS",capsLed.classList.add("wmsx-narrow-hidden"),capsLed.classList.add("wmsx-hidden"),wmsx.Util.onTapOrMouseDownWithBlockUIG(buttonsBar,barElementTapOrMouseDown),wmsx.Util.addEventsListener(buttonsBar,"touchmove",barElementTouchMove),wmsx.Util.addEventsListener(buttonsBar,"mouseup touchend",barElementTouchEndOrMouseUp)}function addPeripheralControlButton(a,b,c,d,e,f,g,h,i){var j=document.createElement("div");return j.id=a,j.classList.add("wmsx-bar-button"),d&&j.classList.add("wmsx-media-button"),j.wmsxBarElementType=1,j.wmsxControl=f,j.style.backgroundPosition=b+"px "+c+"px",j.wmsxBX=b,j.wmsxBY=c,g&&(j.wmsxMenu=g,g.wmsxTitle=h,g.wmsxRefElement=j,g.wmsxMenuIndex=barMenus.length,barMenus.push(g)),e&&(j.title=e),j.addEventListener("mouseenter",function(a){barButtonHoverOver(a.target,a)}),(i||buttonsBarInner).appendChild(j),j}function barButtonTapOrMousedown(a,b,c,d){if(d||controllersHub.hapticFeedbackOnTouch(b),!logoMessageActive&&!c){var e=barMenuActive;closeAllOverlays();var f=0|(b.altKey&&KEY_ALT_MASK)|(b.ctrlKey&&KEY_CTRL_MASK)|(b.shiftKey&&KEY_SHIFT_MASK);if(a.wmsxControl)return void(b.button&&2!==b.button||peripheralControls.processControlActivated(a.wmsxControl,!1,2===b.button||f===KEY_SHIFT_MASK));var g=a.wmsxMenu;if(g){if(0===f&&!b.button)return void(e!==g&&(showBarMenu(g),"touchstart"===b.type&&barButtonLongTouchStart(b)));for(var h=0;h<g.length;++h)if(g[h].clickModif===f)return void peripheralControls.processControlActivated(g[h].control,1===b.button,g[h].secSlot)}}}function barButtonLongTouchStart(a){barButtonLongTouchTarget=a.target,barButtonLongTouchSelectTimeout=window.setTimeout(function(){if(barMenuActive)for(var a=barMenu.wmsxItems,b=0;b<a.length;++b){var c=a[b].wmsxMenuOption;if(c&&0===c.clickModif)return void barMenuItemSetActive(a[b],!0)}},450)}function barButtonLongTouchCancel(){barButtonLongTouchSelectTimeout&&(clearTimeout(barButtonLongTouchSelectTimeout),barButtonLongTouchSelectTimeout=null)}function barButtonHoverOver(a,b){barMenuActive&&a.wmsxMenu&&barMenuActive!==a.wmsxMenu&&(controllersHub.hapticFeedbackOnTouch(b),showBarMenu(a.wmsxMenu))}function barButtonTouchEndOrMouseUp(a){
logoMessageActive||barMenuItemActive&&barMenuItemFireActive(a.shiftKey||2===a.button,a.ctrlKey)}function barMenuItemTapOrMouseDown(a,b,c){c||barMenuItemSetActive(a,"touchstart"===b.type)}function barMenuItemHoverOver(a,b){barMenuItemSetActive(a,"touchmove"===b.type)}function barMenuItemHoverOut(){barMenuItemSetActive(null)}function barMenuItemTouchEndOrMouseUp(a){if(!logoMessageActive){var b=a.shiftKey||2===a.button;barMenuItemTouchActivation&&wmsx.Util.performanceNow()-barMenuItemTouchActivation>TOUCH_EXT_SLOT2_TIME&&(b|=!0),barMenuItemActive&&barMenuItemFireActive(b,a.ctrlKey)}}function barMenuItemFireActive(a,b){var c=barMenuItemActive.wmsxMenuOption;barMenuItemSetActive(null),c&&!c.disabled&&(c.extension?extensionChangeDisabledWarning()||peripheralControls.processControlActivated(wmsx.PeripheralControls.EXTENSION_TOGGLE,b,a,c.extension):c.control&&(a=void 0!==c.secSlot?c.secSlot:a,closeAllOverlays(),peripheralControls.processControlActivated(c.control,b,a)))}function barMenuItemSetActive(a,b){a!==barMenuItemActive&&(barMenuItemActive&&barMenuItemActive.classList.remove("wmsx-hover"),a&&a.wmsxMenuOption?(barMenuItemActive=a,b&&controllersHub.hapticFeedback(),barMenuItemActive.classList.add("wmsx-hover")):barMenuItemActive=null,barMenuItemTouchActivation=b&&barMenuItemActive?wmsx.Util.performanceNow():void 0)}function barElementTapOrMouseDown(a,b,c){cursorHideFrameCountdown=CURSOR_HIDE_FRAMES;var d=a.target;1===d.wmsxBarElementType?barButtonTapOrMousedown(d,a,b,c):2===d.wmsxBarElementType?barMenuItemTapOrMouseDown(d,a,c):hideBarMenu()}function barElementTouchMove(a){wmsx.Util.blockEvent(a);var b=a.changedTouches[0],c=b&&document.elementFromPoint(b.clientX,b.clientY);barButtonLongTouchTarget&&c!==barButtonLongTouchTarget&&barButtonLongTouchCancel(),2!==c.wmsxBarElementType&&c!==barButtonLongTouchTarget&&barMenuItemSetActive(null),1===c.wmsxBarElementType?barButtonHoverOver(c,a):2===c.wmsxBarElementType&&barMenuItemHoverOver(c,a)}function barElementTouchEndOrMouseUp(a){cursorHideFrameCountdown=CURSOR_HIDE_FRAMES,wmsx.Util.blockEvent(a),barButtonLongTouchCancel();var b=a.target;1===b.wmsxBarElementType?barButtonTouchEndOrMouseUp(a):2===b.wmsxBarElementType&&barMenuItemTouchEndOrMouseUp(a)}function createSettingsMenuOptions(){var a=[];return a.push({label:"Select Machine",clickModif:KEY_ALT_MASK,control:wmsx.PeripheralControls.SCREEN_OPEN_MACHINE_SELECT}),isMobileDevice?a.push({label:"Quick Options",clickModif:0,control:wmsx.PeripheralControls.SCREEN_OPEN_QUICK_OPTIONS}):(a.push({label:"Help & Settings",clickModif:0,control:wmsx.PeripheralControls.SCREEN_OPEN_SETTINGS}),a.push({label:"Quick Options",clickModif:KEY_CTRL_MASK,control:wmsx.PeripheralControls.SCREEN_OPEN_QUICK_OPTIONS})),isTouchDevice&&a.push({label:"Touch Setup",clickModif:KEY_CTRL_MASK|KEY_ALT_MASK,control:wmsx.PeripheralControls.SCREEN_OPEN_TOUCH_CONFIG,fullScreenOnly:!0}),isMobileDevice||a.push({label:"Defaults",clickModif:KEY_SHIFT_MASK,control:wmsx.PeripheralControls.SCREEN_DEFAULTS}),a}function defineSettingsMenuExtensions(){for(var a=settingsButton.wmsxMenu;a[0].extension;)a.shift();a[0].divider||a.unshift({label:"",divider:!0});for(var b=WMSX.EXTENSIONS_CONFIG,c=Object.keys(b).reverse(),d=0;d<c.length;++d){var e=c[d],f=b[e];if(f.DESC){var g={label:f.DESC,extension:e,toggle:!0,checkedOp:0};a.unshift(g)}}a[0].divider&&a.shift()}function refreshSettingsMenuForExtensions(){for(var a=settingsButton.wmsxMenu,b=0;b<a.length;++b){var c=a[b];c.extension&&(c.checkedOp=WMSX.EXTENSIONS[c.extension],c.noOp2=!WMSX.EXTENSIONS_CONFIG[c.extension].SLOT2)}barMenuActive===a&&refreshBarMenu(a)}function refreshSettingsMenuForMachineType(){var a=settingsButton.wmsxMenu,b=WMSX.MACHINES_CONFIG[machineTypeSocket.getMachine()];a.wmsxTitle=((b.DESC||b.DESCX).split("(")[0]||"Settings").trim(),settingsButton.wmsxMenu[settingsButton.wmsxMenu.length-5].disabled=2===room.netPlayMode,barMenuActive===a&&refreshBarMenu(a)}function setupCopyTextArea(){copyTextArea=document.createElement("textarea"),copyTextArea.id="wmsx-copy-texarea",fsElement.appendChild(copyTextArea)}function setupFullscreen(){fullscreenAPIEnterMethod=fsElement.requestFullscreen||fsElement.webkitRequestFullscreen||fsElement.webkitRequestFullScreen||fsElement.mozRequestFullScreen,fullScreenAPIExitMethod=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen,"fullscreenElement"in document?fullScreenAPIQueryProp="fullscreenElement":"webkitFullscreenElement"in document?fullScreenAPIQueryProp="webkitFullscreenElement":"mozFullScreenElement"in document&&(fullScreenAPIQueryProp="mozFullScreenElement"),fullscreenAPIEnterMethod||!isMobileDevice||isBrowserStandalone||(fullScreenScrollHack=!0),"onfullscreenchange"in document?document.addEventListener("fullscreenchange",fullscreenByAPIChanged):"onwebkitfullscreenchange"in document?document.addEventListener("webkitfullscreenchange",fullscreenByAPIChanged):"onmozfullscreenchange"in document&&document.addEventListener("mozfullscreenchange",fullscreenByAPIChanged),fullscreenAPIEnterMethod||(scrollMessage.wmsxScroll=canvas.wmsxScroll=logo.wmsxScroll=logoCenter.wmsxScroll=logoImage.wmsxScroll=logoMessage.wmsxScroll=logoMessageText.wmsxScroll=logoMessageOK.wmsxScroll=logoMessageOKText.wmsxScroll=!0,fsElement.addEventListener("touchmove",function(a){if(isFullscreen){if(!fullScreenScrollHack||!a.target.wmsxScroll)return wmsx.Util.blockEvent(a);scrollMessageActive&&setScrollMessage(!1)}}))}function setEnterFullscreenByAPIOnFirstTouch(){if(fullscreenAPIEnterMethod){var a=!1,b=function(){if(!a){for(var c=event.target;c!==fsElement&&c!==document.body;c=c.parentElement)if(c.wmsxIgnoreEnterFS)return;a=!0,wmsx.Util.removeEventsListener(fsElement,"touchend mousedown",b,!0),enterFullScreenByAPI()}};wmsx.Util.addEventsListener(fsElement,"touchend mousedown",b,!0)}}function setFullscreenState(a){isFullscreen=a,a?(setViewport(),document.documentElement.classList.add("wmsx-full-screen"),fullScreenScrollHack&&document.documentElement.classList.add("wmsx-full-screen-scroll-hack"),controllersHub.setupTouchControlsIfNeeded(fsElementCenter),fullScreenScrollHack&&setScrollMessage(!0),fullscreenAPIEnterMethod||tryToFixSafariBugOnFullScreenChange()):(restoreViewport(),document.documentElement.classList.remove("wmsx-full-screen"),fullScreenScrollHack&&document.documentElement.classList.remove("wmsx-full-screen-scroll-hack"),fullscreenAPIEnterMethod||tryToFixSafariBugOnFullScreenChange()),closeAllOverlays(),requestReadjust(),controllersHub.screenFullscreenStateUpdate(isFullscreen)}function tryToFixSafariBugOnFullScreenChange(){var a=document.getElementById("wmsx-dummy-element");a?mainElement.removeChild(a):(a=document.createElement("div"),a.id="wmsx-dummy-element",mainElement.appendChild(a))}function showBar(){buttonsBar.classList.remove("wmsx-hidden")}function hideBar(){!BAR_AUTO_HIDE&&!isFullscreen||barMenuActive||virtualKeyboardMode||(hideBarMenu(),buttonsBar.classList.add("wmsx-hidden"))}function showBarMenu(a,b){if(a&&barMenuActive!==a){if(!barMenu)return setupBarMenu(),void setTimeout(function(){showBarMenu(a,b)},1);refreshBarMenu(a),barMenuItemSetActive(b?barMenu.wmsxDefaultItem:null);var c=a.wmsxRefElement,d=c&&c.offsetLeft-15||0;d+wmsx.ScreenGUI.BAR_MENU_WIDTH>buttonsBarInner.clientWidth?(barMenu.style.right=0,barMenu.style.left="auto",barMenu.style.transformOrigin="bottom right"):(d<0&&(d=0),barMenu.style.left=d+"px",barMenu.style.right="auto",barMenu.style.transformOrigin="bottom left"),showCursorAndBar(!0),barMenuActive=a,barMenu.style.display="inline-block",barMenu.wmsxTitle.focus()}}function refreshBarMenu(a){barMenu.wmsxTitle.innerHTML=a.wmsxTitle,barMenu.wmsxDefaultItem=null;for(var b,c=0,d=Math.min(a.length,BAR_MENU_MAX_ITEMS),e=wmsx.ScreenGUI.BAR_MENU_ITEM_HEIGHT+3,f=0;f<d;++f){var g=a[f];void 0!==g.label&&(b=barMenu.wmsxItems[c],b.firstChild.textContent=g.label,b.wmsxMenuOption=null,
g.hidden||isFullscreen&&g.fullScreenHidden||!isFullscreen&&g.fullScreenOnly?b.style.display="none":(b.style.display="block",g.divider?b.classList.add("wmsx-bar-menu-item-divider"):(b.classList.remove("wmsx-bar-menu-item-divider"),e+=wmsx.ScreenGUI.BAR_MENU_ITEM_HEIGHT,b.classList.toggle("wmsx-bar-menu-item-toggle",void 0!==g.toggle),b.classList.toggle("wmsx-bar-menu-item-toggle-radio",!!g.radio),b.classList.toggle("wmsx-no-op2",g.noOp2||!!g.radio),g.disabled?b.classList.add("wmsx-bar-menu-item-disabled"):(b.classList.remove("wmsx-bar-menu-item-disabled"),b.wmsxMenuOption=g,0===g.clickModif&&(barMenu.wmsxDefaultItem=b),b.wmsxNeedsUIG=g.needsUIG,void 0!==g.toggle&&(b.classList.toggle("wmsx-bar-menu-item-toggle-checked",!!g.checkedOp),b.classList.toggle("wmsx-op1",0!=(1&g.checkedOp)),b.classList.toggle("wmsx-op2",0!=(2&g.checkedOp)))))),++c)}for(var h=c;h<BAR_MENU_MAX_ITEMS;++h)b=barMenu.wmsxItems[h],b.firstChild.textContent="",b.style.display="none",b.wmsxMenuOption=null;var i=fsElementCenter.clientHeight-wmsx.ScreenGUI.BAR_HEIGHT-12,j=e<i?1:i/e;barMenu&&(barMenu.style.transform="scale("+j.toFixed(4)+")")}function hideBarMenu(){barMenuActive&&(barMenuActive=null,barMenu.style.display="none",barMenuItemSetActive(null),cursorHideFrameCountdown=CURSOR_HIDE_FRAMES,self.focus())}function setupBarMenu(){barMenu=document.createElement("div"),barMenu.id="wmsx-bar-menu";var a=document.createElement("div");a.id="wmsx-bar-menu-inner",barMenu.appendChild(a);var b=document.createElement("div");b.id="wmsx-bar-menu-title",b.tabIndex=-1,b.innerHTML="Menu Title",a.appendChild(b),barMenu.wmsxTitle=b,barMenu.wmsxItems=new Array(BAR_MENU_MAX_ITEMS);for(var c=0;c<BAR_MENU_MAX_ITEMS;++c){var d=document.createElement("div");d.classList.add("wmsx-bar-menu-item"),d.style.display="none",d.innerHTML="Menu Item "+c,d.wmsxBarElementType=2,d.wmsxItemIndex=c,d.addEventListener("mouseenter",function(a){barMenuItemHoverOver(a.target,a)}),d.addEventListener("mouseleave",barMenuItemHoverOut),a.appendChild(d),barMenu.wmsxItems[c]=d}barMenu.addEventListener("keydown",function(a){var b=domKeys.codeNewForKeyboardEvent(a);if(MENU_CLOSE_KEYS[b])hideBarMenu();else if(barMenuItemActive&&MENU_EXEC_KEYS[b&~KEY_SHIFT_MASK&~KEY_CTRL_MASK])barMenuItemFireActive(a.shiftKey,a.ctrlKey);else if(MENU_SELECT_KEYS[b]){if(!barMenuActive)return;var c=barMenuActive.wmsxMenuIndex;do{c=(barMenus.length+c+MENU_SELECT_KEYS[b])%barMenus.length;var d=barMenus[c]}while(!d||d.wmsxHidden);showBarMenu(d,!0)}else if(MENU_ITEM_SELECT_KEYS[b]){var e=barMenu.wmsxItems,f=barMenuItemActive?barMenuItemActive.wmsxItemIndex:-1,g=BAR_MENU_MAX_ITEMS+1;do{f=(f+e.length+MENU_ITEM_SELECT_KEYS[b])%e.length}while(--g>=0&&!e[f].wmsxMenuOption);g>=0&&barMenuItemSetActive(e[f])}return wmsx.Util.blockEvent(a)}),buttonsBar.appendChild(barMenu)}function closePowerOnModals(){pasteDialog&&pasteDialog.hide(),textEntryDialog&&textEntryDialog.hide()}function closeAllOverlays(a){hideBarMenu(),pasteDialog&&pasteDialog.hide(),machineSelectDialog&&machineSelectDialog.hide(),diskSelectDialog&&diskSelectDialog.hide(),newHardDiskDialog&&newHardDiskDialog.hide(),saveStateDialog&&saveStateDialog.hide(),touchConfigDialog&&touchConfigDialog.hide(),quickOtionsDialog&&quickOtionsDialog.hide(),cartFormatDialog&&cartFormatDialog.hide(),settingsDialog&&settingsDialog.hide(),netPlayDialog&&!a&&netPlayDialog.hide(),textEntryDialog&&!a&&textEntryDialog.hide()}function showLogoMessage(a,b,c,d){logoMessageActive||(closeAllOverlays(),d&&(afterMessageAction=d),logoMessageText.innerHTML=a,logoMessageOK.classList.toggle("wmsx-higher",!!c),logoMessageOKText.innerHTML=b||"OK",fsElement.classList.add("wmsx-logo-message-active"),logoMessageActive=!0,signalIsOn=!1,updateLogo())}function closeLogoMessage(a,b,c){if(c||controllersHub.hapticFeedbackOnTouch(a),!b&&(fsElement.classList.remove("wmsx-logo-message-active"),logoMessageActive=!1,afterMessageAction)){var d=afterMessageAction;afterMessageAction=null,d()}}function updateLogoScale(){if(logoMessageActive){var a=canvasOuter.clientWidth,b=Math.min(a/wmsx.ScreenGUI.LOGO_SCREEN_WIDTH,1);logoCenter.style.transform="translate(-50%, -50%) scale("+b.toFixed(4)+")"}else logoCenter.style.transform="translate(-50%, -50%)"}function setScrollMessage(a){fsElement.classList.toggle("wmsx-scroll-message",a),scrollMessageActive=a,a&&setTimeout(function(){setScrollMessage(!1)},5e3)}function readjustAll(a,b){if(readjustScreeSizeChanged(a)){if(isFullscreen){var c=readjustScreenSize.w>readjustScreenSize.h,d=virtualKeyboardMode&&updateKeyboardWidth(readjustScreenSize.w);buttonsBarDesiredWidth=c?virtualKeyboardMode?d.w:0:-1;var e=readjustScreenSize.h;c&&!virtualKeyboardMode||(e-=wmsx.ScreenGUI.BAR_HEIGHT+2),virtualKeyboardMode&&(e-=d.h+2),displayScale(aspectX,displayOptimalScaleY(readjustScreenSize.w,e))}else buttonsBarDesiredWidth=-1,displayScale(aspectX,scaleYBeforeUserFullscreen||displayDefaultScale());b||self.focus(),controllersHub.screenReadjustedUpdate()}readjustInterval&&wmsx.Util.performanceNow()-readjustRequestTime>=1e3&&(clearInterval(readjustInterval),readjustInterval=null)}function readjustScreeSizeChanged(a){var b=mainElement.parentElement.clientWidth,c=fsElementCenter.clientWidth,d=fsElementCenter.clientHeight;return!(!a&&readjustScreenSize.pw===b&&readjustScreenSize.w===c&&readjustScreenSize.h===d)&&(readjustScreenSize.pw=b,readjustScreenSize.w=c,readjustScreenSize.h=d,!0)}function auxReadjustAll(a,b){auxReadjustScreeSizeChanged(a||b)&&(auxIsMaxed()||b?auxDisplayScale(auxAspectX,auxDisplayOptimalScaleY(auxReadjustScreenSize.w,auxReadjustScreenSize.h)):auxDisplayScale(auxAspectX,auxScaleY,!0))}function auxReadjustScreeSizeChanged(a){var b=auxWindow.document.body.clientWidth,c=auxFsElementCenter.clientWidth,d=auxFsElementCenter.clientHeight;return!(!a&&auxReadjustScreenSize.pw===b&&auxReadjustScreenSize.w===c&&auxReadjustScreenSize.h===d)&&(auxReadjustScreenSize.pw=b,auxReadjustScreenSize.w=c,auxReadjustScreenSize.h=d,!0)}function displayOptimalScaleY(a,b){var c=b/targetHeight;return scrTargetWidth*aspectX*c>a&&(c=a/(scrTargetWidth*aspectX)),c}function auxDisplayOptimalScaleY(a,b){var c=b/auxTargetHeight;return auxScrTargetWidth*auxAspectX*c>a&&(c=a/(auxScrTargetWidth*auxAspectX)),c}function setViewport(){if(isMobileDevice){if(void 0===viewPortOriginalContent&&(viewPortOriginalTag=document.querySelector("meta[name=viewport]"),viewPortOriginalContent=viewPortOriginalTag&&viewPortOriginalTag.content||null),viewportTag||(viewportTag=document.createElement("meta"),viewportTag.name="viewport",viewportTag.content="width = device-width, height = device-height, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = yes",document.head.appendChild(viewportTag)),viewPortOriginalTag)try{document.head.removeChild(viewPortOriginalTag)}catch(a){}viewPortOriginalTag=null}}function restoreViewport(){if(isMobileDevice){if(!viewPortOriginalTag&&viewPortOriginalContent&&(viewPortOriginalTag=document.createElement("meta"),viewPortOriginalTag.name="viewport",viewPortOriginalTag.content=viewPortOriginalContent,document.head.appendChild(viewPortOriginalTag)),viewportTag)try{document.head.removeChild(viewportTag)}catch(a){}viewportTag=null}}function setPageVisibilityHandling(){function a(){logoMessageActive||(document.hidden?b=!machine.systemPause(!0):b&&machine.systemPause(!1))}var b;document.addEventListener("visibilitychange",a)}function extensionChangeDisabledWarning(){return!!WMSX.MEDIA_CHANGE_DISABLED&&(machine.showOSD("Extension change is disabled!",!0,!0),!0)}function setupFileLoaderDropTargets(){fileLoaderDropArea=document.getElementById("wmsx-drop-area"),fileLoaderDropAreaMessage=document.getElementById("wmsx-drop-area-message");var a,b,c,d;a=fsElement,c={element:a,openType:OPEN_TYPE.DISK,port:void 0,add:!0,mainEle:a,mes:"Add Disk(s) to Drive (auto-detect)",mesSec:"Add Disk(s) to Drive B Stack"},d={element:a,
openType:OPEN_TYPE.DISK,port:void 0,files:!0,mainEle:a,mes:"Add Files to Drive (auto-detect)",mesSec:"Add Files to Disk in Drive B"},a.wmsxDropInfo={element:a,openType:OPEN_TYPE.AUTO,port:void 0,subAdd:c,subFiles:d,mes:"Auto detect media",mesSec:"Auto detect media (to Drive B / Cartridge 2)"},diskAButton.wmsxDropTarget=a=document.getElementById("wmsx-drop-drivea"),b=document.getElementById("wmsx-drop-drivea-add"),b.wmsxDropInfo=c={element:b,openType:OPEN_TYPE.DISK,port:0,add:!0,mainEle:a,mes:"Add Disk(s) to Drive A Stack"},b=document.getElementById("wmsx-drop-drivea-files"),b.wmsxDropInfo=d={element:b,openType:OPEN_TYPE.DISK,port:0,files:!0,mainEle:a,mes:"Add Files to Disk in Drive A"},a.wmsxDropInfo={element:a,openType:OPEN_TYPE.DISK,port:0,subAdd:c,subFiles:d,mes:"Load Disk(s) in Drive A"},diskBButton.wmsxDropTarget=a=document.getElementById("wmsx-drop-driveb"),b=document.getElementById("wmsx-drop-driveb-add"),b.wmsxDropInfo=c={element:b,openType:OPEN_TYPE.DISK,port:1,add:!0,mainEle:a,mes:"Add Disk(s) to Drive B Stack"},b=document.getElementById("wmsx-drop-driveb-files"),b.wmsxDropInfo=d={element:b,openType:OPEN_TYPE.DISK,port:1,files:!0,mainEle:a,mes:"Add Files to Disk in Drive B"},a.wmsxDropInfo={element:a,openType:OPEN_TYPE.DISK,port:1,subAdd:c,subFiles:d,mes:"Load Disk(s) in Drive B"},diskHButton.wmsxDropTarget=a=document.getElementById("wmsx-drop-driveh"),b=document.getElementById("wmsx-drop-driveh-files"),b.wmsxDropInfo=d={element:b,openType:OPEN_TYPE.DISK,port:2,files:!0,mainEle:a,mes:"Add Files to Hard Disk"},a.wmsxDropInfo={element:a,openType:OPEN_TYPE.DISK,port:2,subFiles:d,mes:"Load Hard Disk"},a=document.getElementById("wmsx-drop-cart1"),a.wmsxDropInfo={element:a,openType:OPEN_TYPE.ROM,port:0,mes:"Load Cartride 1"},a=document.getElementById("wmsx-drop-cart2"),a.wmsxDropInfo={element:a,openType:OPEN_TYPE.ROM,port:1,mes:"Load Cartride 2"},a=document.getElementById("wmsx-drop-tape"),a.wmsxDropInfo={element:a,openType:OPEN_TYPE.TAPE,port:0,mes:"Load Cassette Tape"}}var self=this;this.connect=function(a){machine=a,machine.getVideoSocket().connectMonitor(monitor),controllersSocket=machine.getControllersSocket(),cartridgeSocket=machine.getCartridgeSocket(),extensionsSocket=machine.getExtensionsSocket(),machineTypeSocket=machine.getMachineTypeSocket()},this.connectPeripherals=function(a,b,c,d,e,f,g,h){cartridgeSlot=a,fileLoader=b,fileLoader.registerForDnD(fsElement),fileLoader.registerForFileInputElement(fsElement),fileDownloader=c,fileDownloader.registerForDownloadElement(fsElement),machineControls=d,peripheralControls=e,controllersHub=f,controllersHub.addKeyInputElement(fsElement),controllersHub.setMouseInputElement(canvas),diskDrive=g,stateMedia=h},this.powerOn=function(){this.setDefaults(),updateLogo(),document.documentElement.classList.add("wmsx-started"),setPageVisibilityHandling(),this.focus(),WMSXFullScreenSetup.shouldStartInFullScreen()&&(setFullscreenState(!0),2!==FULLSCREEN_MODE&isMobileDevice&&setEnterFullscreenByAPIOnFirstTouch())},this.powerOff=function(){document.documentElement.classList.remove("wmsx-started")},this.start=function(a){function b(){self.setFullscreen(!0),a()}!isMobileDevice||isBrowserStandalone||isFullscreen?a():wmsx.Util.isOfficialHomepage()?showLogoMessage("For "+(fullscreenAPIEnterMethod?"the best":"a full-screen")+' experience, use<br>the "Add to Home Screen" function<br>then launch from the Installed App',"NICE!",!1,b):showLogoMessage("For the best experience,<br>WebMSX will go full-screen","GO!",!0,b)},this.isDualScreenAllowed=function(){return!isMobileDevice},this.refresh=function(a,b,c,d,e,f){cursorHideFrameCountdown>0&&--cursorHideFrameCountdown<=0&&hideCursorAndBar(),ledsStatePending&&updateLeds(),signalIsOn||(signalIsOn=!0,updateLogo());var g,h;if(videoOutputMode<4||5===videoOutputMode^f)g=canvasContext||createCanvasContext(),h=canvas;else if(g=auxCanvasContext||auxCreateCanvasContext(),h=auxCanvas,!g)return;if(3===videoOutputMode&&f&&g.clearRect(0,0,h.width,h.height),g.drawImage(a,b,c,d,e,0,0,h.width,h.height),crtScanlines&&pixelHeight>1&&!debugMode&&(videoOutputMode>=4||videoOutputMode<=1||!f)){var i=g.globalCompositeOperation,j=g.globalAlpha;g.globalCompositeOperation="source-over",g.globalAlpha=crtScanlines/10,g.drawImage(scanlinesImage,0,0,1,h.height,0,0,h.width,h.height),g.globalCompositeOperation=i,g.globalAlpha=j}},this.videoSignalOff=function(){signalIsOn=!1,showCursorAndBar(),updateLeds(),updateLogo()},this.mousePointerLocked=function(a){mousePointerLocked=a,mousePointerLocked?hideCursorAndBar():showCursorAndBar()},this.openHelp=function(){return self.openSettings("GENERAL"),!1},this.openAbout=function(){return self.openSettings("ABOUT"),!1},this.openSettings=function(a){closeAllOverlays(),settingsDialog||(settingsDialog=new wmsx.SettingsDialog(fsElementCenter,controllersHub,peripheralControls,machineTypeSocket)),settingsDialog.show(a)},this.openSaveStateDialog=function(a){closeAllOverlays(),saveStateDialog||(saveStateDialog=new wmsx.SaveStateDialog(fsElementCenter,machineControls,peripheralControls,stateMedia)),saveStateDialog.show(a)},this.openDiskSelectDialog=function(a,b,c){closeAllOverlays(),diskSelectDialog||(diskSelectDialog=new wmsx.DiskSelectDialog(fsElementCenter,diskDrive,peripheralControls,fileLoader)),diskSelectDialog.show(a,b,c)},this.openNewHardDiskDialog=function(a,b){closeAllOverlays(),newHardDiskDialog||(newHardDiskDialog=new wmsx.NewHardDiskDialog(fsElementCenter,peripheralControls)),newHardDiskDialog.show(a,b)},this.openMachineSelectDialog=function(){if(closeAllOverlays(),WMSX.MEDIA_CHANGE_DISABLED)return this.showOSD("Machine change is disabled!",!0,!0);machineSelectDialog||(machineSelectDialog=new wmsx.MachineSelectDialog(fsElementCenter,machineTypeSocket,peripheralControls)),machineSelectDialog.show()},this.openTouchConfigDialog=function(){closeAllOverlays(),virtualKeyboardMode&&setVirtualKeyboard(0),touchConfigDialog||(touchConfigDialog=new wmsx.TouchConfigDialog(fsElement,canvasOuter,controllersHub,peripheralControls)),touchConfigDialog.show()},this.openQuickOptionsDialog=function(){closeAllOverlays(),virtualKeyboardMode&&setVirtualKeyboard(0),quickOtionsDialog||(quickOtionsDialog=new wmsx.QuickOptionsDialog(fsElementCenter,machineTypeSocket,machineControls,peripheralControls)),quickOtionsDialog.show()},this.openNetPlayDialog=function(){closeAllOverlays(),netPlayDialog||(netPlayDialog=new wmsx.NetPlayDialog(room,fsElementCenter)),netPlayDialog.show()},this.openCartridgeFormatDialog=function(a,b){closeAllOverlays(),cartFormatDialog||(cartFormatDialog=new wmsx.CartridgeFormatDialog(this,fsElementCenter,machine,cartridgeSlot)),cartFormatDialog.show(a,b)},this.openLoadFileDialog=function(){return peripheralControls.processControlActivated(wmsx.PeripheralControls.AUTO_LOAD_FILE),!1},this.executeTextCopy=function(){if(!signalIsOn)return this.showOSD("Screen Text Copy only available when Power is ON!",!0,!0);if(!document.queryCommandSupported||!document.queryCommandSupported("copy"))return this.showOSD("Copy to Clipboard not supported by the browser!",!0,!0);var a=monitor.getScreenText();if(!a)return this.showOSD("Screen Text Copy not available in this Screen!",!0,!0);copyTextArea||setupCopyTextArea(),copyTextArea.innerHTML=a,copyTextArea.select(),document.execCommand("copy")?this.showOSD("Screen text copied to Clipboard",!0):this.showOSD("Copy to Clipboard not supported by the browser!",!0,!0),this.focus()},this.toggleTextPasteDialog=function(){return signalIsOn?(pasteDialog||(pasteDialog=new wmsx.PasteDialog(canvasOuter,this,machineControls)),pasteDialog.toggle(),!1):this.showOSD("Text Paste only available when Power is ON!",!0,!0)},this.toggleTextEntryDialog=function(){return signalIsOn?(virtualKeyboardMode&&setVirtualKeyboard(0),textEntryDialog||(textEntryDialog=new wmsx.TextEntryDialog(fsElementCenter,this,machineControls)),textEntryDialog.toggle(),
!1):this.showOSD("Text Entry only available when Power is ON!",!0,!0)},this.toggleMenuByKey=function(){barMenuActive?hideBarMenu():(closeAllOverlays(),showBarMenu(barMenuSystem,!0))},this.toggleVirtualKeyboard=function(){setVirtualKeyboard((virtualKeyboardMode+1)%3)},this.getScreenCapture=function(){if(signalIsOn)return canvas.toDataURL("image/png")},this.saveScreenCapture=function(){var a=this.getScreenCapture();a&&fileDownloader.startDownloadURL("WMSX Screen.png",a,"WebMSX Screen Capture")},this.displayMetrics=function(a,b,c){var d,e,f;switch(a){case 192:case 384:d=384;break;case 272:case 544:d=544;break;case 640:d=640;break;case 768:d=768;break;case 1088:d=1088;break;default:d=544}switch(f=640===d?640:544,b){case 208:e=416;break;case 228:case 456:e=456;break;case 400:e=400;break;case 240:case 480:e=480;break;default:e=456}(0===videoOutputMode||4===videoOutputMode)===c?updateDisplayMetrics(a,b,d,f,e):auxUpdateDisplayMetrics(a,b,d,f,e)},this.getMonitor=function(){return monitor},this.showOSD=function(a,b,c){if(osdTimeout&&clearTimeout(osdTimeout),!a)return hideOSDs();var d,e;isFocusOnAuxWindow()?(d=auxOsd,e=auxCanvas):(d=osd,e=canvasOuter),!b&&osdShowing||(d.innerHTML=a,d.style.color=c?"rgb(255, 60, 40)":"rgb(0, 255, 0)"),d.style.transition="none",d.style.top="12px",d.style.opacity=1,osdShowing=!0;var f=e.clientWidth-30,g=d.clientWidth,h=g<f?1:f/g;d.style.transform="scale("+h.toFixed(4)+")",osdTimeout=setTimeout(hideOSDs,OSD_TIME)},this.setDebugMode=function(a){debugMode=!!a,debugMode&&videoOutputMode>1&&videoOutputMode<4&&monitor.setOutputMode(Math.min(1,videoOutputMode),!0),canvasContext=null},this.setDefaults=function(){crtPhosphorSetDefault(),crtScanlinesSetDefault(),crtFilterSetDefault(),aspectAndScaleSetDefault()},this.crtFilterToggle=function(a){var b;a?(b=crtFilter-1)<-2&&(b=3):(b=crtFilter+1)>3&&(b=-2),setCRTFilter(b);var c=null===crtFilterEffective?"browser default":crtFilterEffective<1?"OFF":"level "+crtFilterEffective;this.showOSD("CRT Filter: "+(-1===crtFilter?"AUTO ("+c+")":c),!0),WMSX.userPreferences.current.crtFilter!==crtFilter&&(WMSX.userPreferences.current.crtFilter=crtFilter,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save())},this.crtScanlinesToggle=function(a){var b;if(a?(b=crtScanlines-1)<0&&(b=10):(b=crtScanlines+1)>10&&(b=0),!crtScanlines&&b){for(var c=[.5,.75,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5],d=0;d<c.length-1&&scaleY>=c[d];)++d;if(displayScale(aspectX,c[d-1]),auxWindow){for(d=0;d<c.length-1&&auxScaleY>=c[d];)++d;auxDisplayScale(auxAspectX,c[d-1],!auxIsMaxed())}}setCRTScanlines(b),this.showOSD("CRT Scanlines: "+(0===crtScanlines?"OFF":10*crtScanlines+"%"),!0),WMSX.userPreferences.current.crtScanlines!==crtScanlines&&(WMSX.userPreferences.current.crtScanlines=crtScanlines,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save())},this.crtPhosphorToggle=function(a){var b;a?(b=crtPhosphor-1)<-1&&(b=1):(b=crtPhosphor+1)>1&&(b=-1),setCRTPhosphor(b);var c=1===crtPhosphorEffective?"ON":"OFF";this.showOSD("CRT Phosphor: "+(-1===crtPhosphor?"AUTO ("+c+")":c),!0)},this.getControlReport=function(a){switch(a){case wmsx.PeripheralControls.SCREEN_CRT_FILTER:return{label:-2===crtFilter?"Browser":-1===crtFilter?"Auto":0===crtFilter?"OFF":"Level "+crtFilter,active:crtFilter>=0};case wmsx.PeripheralControls.SCREEN_CRT_SCANLINES:return{label:0===crtScanlines?"OFF":10*crtScanlines+"%",active:crtScanlines>0}}return{label:"Unknown",active:!1}},this.fullscreenToggle=function(a){if(-2!==FULLSCREEN_MODE){if(isFocusOnAuxWindow())return auxDisplayToggleFullscreen();isFullscreen||isMobileDevice||(scaleYBeforeUserFullscreen=scaleY),this.setFullscreen(!isFullscreen,a)}},this.setFullscreen=function(a,b){a?!b&&fullscreenAPIEnterMethod?enterFullScreenByAPI():setFullscreenState(!0):isFullScreenByAPI()?exitFullScreenByAPI():setFullscreenState(!1)},this.displayAspectDecrease=function(){isFocusOnAuxWindow()?(auxDisplayScale(normalizeAspectX(auxAspectX-ASPECT_STEP),auxScaleY,!auxIsMaxed()),this.showOSD("Display Aspect: "+auxAspectX.toFixed(2)+"x",!0)):(displayScale(normalizeAspectX(aspectX-ASPECT_STEP),scaleY),this.showOSD("Display Aspect: "+aspectX.toFixed(2)+"x",!0))},this.displayAspectIncrease=function(){isFocusOnAuxWindow()?(auxDisplayScale(normalizeAspectX(auxAspectX+ASPECT_STEP),auxScaleY,!auxIsMaxed()),this.showOSD("Display Aspect: "+auxAspectX.toFixed(2)+"x",!0)):(displayScale(normalizeAspectX(aspectX+ASPECT_STEP),scaleY),this.showOSD("Display Aspect: "+aspectX.toFixed(2)+"x",!0))},this.displayScaleDecrease=function(){isFocusOnAuxWindow()?(auxDisplayScale(auxAspectX,normalizeScaleY(auxScaleY-SCALE_STEP),!auxIsMaxed()),this.showOSD("Display Size: "+auxScaleY.toFixed(2)+"x",!0)):(displayScale(aspectX,normalizeScaleY(scaleY-SCALE_STEP)),this.showOSD("Display Size: "+scaleY.toFixed(2)+"x",!0))},this.displayScaleIncrease=function(){isFocusOnAuxWindow()?(auxDisplayScale(auxAspectX,normalizeScaleY(auxScaleY+SCALE_STEP),!auxIsMaxed()),this.showOSD("Display Size: "+auxScaleY.toFixed(2)+"x",!0)):(displayScale(aspectX,normalizeScaleY(scaleY+SCALE_STEP)),this.showOSD("Display Size: "+scaleY.toFixed(2)+"x",!0))},this.focus=function(){canvas.focus()},this.machinePowerAndUserPauseStateUpdate=function(a,b){powerButton.style.backgroundPosition=powerButton.wmsxBX+"px "+(powerButton.wmsxBY+barButtonBackYOffset*(a?1:0))+"px",2===room.netPlayMode?(powerButton.wmsxMenu[5].disabled=powerButton.wmsxMenu[6].disabled=powerButton.wmsxMenu[8].disabled=powerButton.wmsxMenu[9].disabled=!0,powerButton.wmsxMenu[1].disabled=!a):(powerButton.wmsxMenu[5].disabled=powerButton.wmsxMenu[6].disabled=powerButton.wmsxMenu[8].disabled=!1,powerButton.wmsxMenu[1].disabled=powerButton.wmsxMenu[9].disabled=!a)},this.diskDrivesMediaStateUpdate=function(a){var b=2===a?diskHButton:1===a?diskBButton:diskAButton,c=diskDrive.getDriveStack(a);if(b.title=diskDrive.getCurrentDiskDesc(a),a<2?(b.wmsxMenu[8].label="Remove "+(c.length>1?"Stack":"Disk"),2===room.netPlayMode?b.wmsxMenu[0].disabled=b.wmsxMenu[1].disabled=b.wmsxMenu[2].disabled=b.wmsxMenu[3].disabled=b.wmsxMenu[4].disabled=b.wmsxMenu[5].disabled=b.wmsxMenu[6].disabled=b.wmsxMenu[7].disabled=b.wmsxMenu[8].disabled=!0:(b.wmsxMenu[0].disabled=b.wmsxMenu[4].disabled=b.wmsxMenu[5].disabled=!1,b.wmsxMenu[1].disabled=b.wmsxMenu[2].disabled=b.wmsxMenu[3].disabled=c.length>=wmsx.FileDiskDrive.MAX_STACK,b.wmsxMenu[6].disabled=c.length<=1,b.wmsxMenu[7].disabled=b.wmsxMenu[8].disabled=0===c.length)):2===room.netPlayMode?b.wmsxMenu[0].disabled=b.wmsxMenu[1].disabled=b.wmsxMenu[2].disabled=b.wmsxMenu[3].disabled=b.wmsxMenu[4].disabled=b.wmsxMenu[5].disabled=b.wmsxMenu[6].disabled=!0:(b.wmsxMenu[0].disabled=b.wmsxMenu[1].disabled=b.wmsxMenu[2].disabled=b.wmsxMenu[3].disabled=b.wmsxMenu[4].disabled=!1,b.wmsxMenu[5].disabled=b.wmsxMenu[6].disabled=0===c.length),diskSelectDialog&&diskSelectDialog.diskDrivesMediaStateUpdate(a),c.length>1){var d=diskDrive.getCurrentDiskNum(a)+1;b.wmsxMenu.wmsxTitle=diskDrive.getDriveName(a)+"&nbsp;&nbsp;("+d+"/"+c.length+")"}else b.wmsxMenu.wmsxTitle=diskDrive.getDriveName(a)},this.diskDrivesMotorStateUpdate=function(a,b,c,d,e,f,g,h,i){diskAButton.style.backgroundPosition=diskAButton.wmsxBX+"px "+mediaButtonBackYOffsets[b?3:a?c?2:1:0]+"px",diskBButton.style.backgroundPosition=diskBButton.wmsxBX+"px "+mediaButtonBackYOffsets[e?3:d?f?2:1:0]+"px",diskHButton.style.backgroundPosition=diskHButton.wmsxBX+"px "+mediaButtonBackYOffsets[h?3:g?i?2:1:0]+"px"},this.diskInterfacesStateUpdate=function(a,b){peripheralControls.diskInterfacesStateUpdate(a,b),diskAButton.classList.toggle("wmsx-hidden",!a),diskAButton.wmsxDropTarget.classList.toggle("wmsx-disabled",!a),diskAButton.wmsxDropTarget.wmsxDropInfo.disabled=!a,diskAButton.wmsxMenu.wmsxHidden=!a,diskBButton.classList.toggle("wmsx-hidden",!a),diskBButton.wmsxDropTarget.classList.toggle("wmsx-disabled",!a),diskBButton.wmsxDropTarget.wmsxDropInfo.disabled=!a,
diskBButton.wmsxMenu.wmsxHidden=!a,diskHButton.classList.toggle("wmsx-hidden",!b),diskHButton.wmsxDropTarget.classList.toggle("wmsx-disabled",!b),diskHButton.wmsxDropTarget.wmsxDropInfo.disabled=!b;var c=diskHButton.wmsxMenu;c.wmsxHidden=!b;var d=diskDrive.isHardDriveFirst();diskHButton.classList.toggle("wmsx-hd-first",!!d),diskHButton.wmsxDropTarget.classList.toggle("wmsx-hd-first",!!d);var e=d?1:4;barMenus[1]=1===e?c:null,barMenus[4]=4===e?c:null,c.wmsxMenuIndex=e},this.extensionsAndCartridgesStateUpdate=function(){var a=cartridgeSocket.cartridgeInserted(0),b=cartridgeSocket.cartridgeInserted(1);cartridge1Button.title="Cartridge 1"+(a?": "+(a.format.internal?a.format.desc:(a.rom.source||"<Unknown>")+"  ["+a.format.name+"]"):""),cartridge2Button.title="Cartridge 2"+(b?": "+(b.format.internal?b.format.desc:(b.rom.source||"<Unknown>")+"  ["+b.format.name+"]"):"");var c=a&&a.getDataDesc();cartridge1Button.wmsxMenu[2].label="Load "+(c||"Data")+" File",cartridge1Button.wmsxMenu[3].label="Save "+(c||"Data")+" File",2===room.netPlayMode?cartridge1Button.wmsxMenu[0].disabled=cartridge1Button.wmsxMenu[1].disabled=cartridge1Button.wmsxMenu[2].disabled=cartridge1Button.wmsxMenu[3].disabled=cartridge1Button.wmsxMenu[4].disabled=!0:(cartridge1Button.wmsxMenu[0].disabled=!1,cartridge1Button.wmsxMenu[2].disabled=cartridge1Button.wmsxMenu[3].disabled=!c,cartridge1Button.wmsxMenu[1].disabled=!a||a.format.internal,cartridge1Button.wmsxMenu[4].disabled=!a),c=b&&b.getDataDesc(),cartridge2Button.wmsxMenu[2].label="Load "+(c||"Data")+" File",cartridge2Button.wmsxMenu[3].label="Save "+(c||"Data")+" File",2===room.netPlayMode?cartridge2Button.wmsxMenu[0].disabled=cartridge2Button.wmsxMenu[1].disabled=cartridge2Button.wmsxMenu[2].disabled=cartridge2Button.wmsxMenu[3].disabled=cartridge2Button.wmsxMenu[4].disabled=!0:(cartridge2Button.wmsxMenu[0].disabled=!1,cartridge2Button.wmsxMenu[2].disabled=cartridge2Button.wmsxMenu[3].disabled=!c,cartridge2Button.wmsxMenu[1].disabled=!b||b.format.internal,cartridge2Button.wmsxMenu[4].disabled=!b),this.cartridgesModifiedStateUpdate(a,b),refreshSettingsMenuForExtensions()},this.cartridgesModifiedStateUpdate=function(a,b){cartridge1Button.style.backgroundPosition=cartridge1Button.wmsxBX+"px "+mediaButtonBackYOffsets[a?a.dataModified()?2:1:0]+"px",cartridge2Button.style.backgroundPosition=cartridge2Button.wmsxBX+"px "+mediaButtonBackYOffsets[b?b.dataModified()?2:1:0]+"px"},this.tapeStateUpdate=function(a,b,c){tapeButton.title="Cassette Tape"+(a?": "+a:""),tapeButton.style.backgroundPosition=tapeButton.wmsxBX+"px "+mediaButtonBackYOffsets[b?3:a?c?2:1:0]+"px",2===room.netPlayMode?(tapeButton.wmsxMenu[0].disabled=tapeButton.wmsxMenu[1].disabled=tapeButton.wmsxMenu[2].disabled=tapeButton.wmsxMenu[4].disabled=tapeButton.wmsxMenu[5].disabled=!0,tapeButton.wmsxMenu[3].disabled=!a):(tapeButton.wmsxMenu[0].disabled=tapeButton.wmsxMenu[1].disabled=!1,tapeButton.wmsxMenu[2].disabled=tapeButton.wmsxMenu[3].disabled=tapeButton.wmsxMenu[4].disabled=tapeButton.wmsxMenu[5].disabled=!a)},this.machineTypeStateUpdate=function(){machineSelectDialog&&machineSelectDialog.machineTypeStateUpdate(),quickOtionsDialog&&quickOtionsDialog.machineTypeStateUpdate(),kanaLed.textContent=machineTypeSocket.getCodeLedLabel(),refreshSettingsMenuForMachineType()},this.keyboardSettingsStateUpdate=function(){settingsDialog&&settingsDialog.keyboardSettingsStateUpdate()},this.controllersSettingsStateUpdate=function(){settingsDialog&&settingsDialog.controllersSettingsStateUpdate(),touchConfigDialog&&touchConfigDialog.controllersSettingsStateUpdate()},this.mouseActiveCursorStateUpdate=function(a){cursorType=a?'url("'+wmsx.Images.urls.mouseCursor+'"), auto':"auto",fsElement.style.cursor=cursorShowing?cursorType:"none",showCursorAndBar()},this.touchControlsActiveUpdate=function(a,b,c){touchControlsActive===a&&touchControlsDirBig===b&&touchControlsMirror===c||(touchControlsActive=a,touchControlsDirBig=b,touchControlsMirror=c,isFullscreen&&(touchControlsActive&&controllersHub.setupTouchControlsIfNeeded(fsElementCenter),requestReadjust(!0)))},this.roomNetPlayStatusChangeUpdate=function(a){netPlayDialog&&netPlayDialog.isVisible()||closeAllOverlays(),netPlayDialog&&netPlayDialog.roomNetPlayStatusChangeUpdate(a),netplayButton.classList.toggle("wmsx-hidden",room.netPlayMode<1)},this.quickOptionsControlsStateUpdate=function(){quickOtionsDialog&&quickOtionsDialog.quickOptionsControlsStateUpdate()},this.machineTurboModesStateUpdate=function(){quickOtionsDialog&&quickOtionsDialog.machineTurboModesStateUpdate();var a=machine.cpu.getZ80ClockMulti();turboButton.classList.toggle("wmsx-hidden",1===a),1!==a&&(turboButton.textContent=a+"x")},this.speakerUnlockStateUpdate=function(a){if(unmuteMessage.classList.toggle("wmsx-show",!a),!a){var b=canvasOuter.clientWidth-30,c=unmuteMessage.clientWidth,d=c<b?1:b/c;unmuteMessage.style.transform="translate(-50%, 0) scale("+d.toFixed(4)+")"}},this.configurationStateUpdate=function(){closeAllOverlays(),machineSelectDialog&&machineSelectDialog.configurationStateUpdate(),defineSettingsMenuExtensions()},this.ledsStateUpdate=function(a,b){ledsStatePending=a,ledsInfoPending=b,signalIsOn||updateLeds()},this.videoOutputModeUpdate=function(a,b,c,d,e,f){videoOutputButton.classList.toggle("wmsx-hidden",!e),videoOutputButton.style.backgroundPosition=videoOutputButton.wmsxBX+"px "+(videoOutputButton.wmsxBY+barButtonBackYOffset*Math.min(b,4))+"px";for(var g=videoOutputButton.wmsxMenu,h=0;h<=4;++h)g[h].checkedOp=a===h-1?1:0;g[0].label=d,g[2].label=e,g[6].checkedOp=a>=4?a-3:0,g[6].disabled=!this.isDualScreenAllowed(),g[8].disabled=c&&-1===a,videoOutputMode!==b&&(videoOutputMode=b,canvasContext=null,auxCanvasContext=null),videoOutputMode>=4?(setupAndShowAuxWindow(),auxWindowUpdateTitle()):closeAuxWindow(),barMenuActive===g&&refreshBarMenu(g)},this.setLoading=function(a){isLoading=a,updateLoading(),a||(wmsx.Configurator.addConfigurationStateListener(this),machine.getMachineControlsSocket().addPowerAndUserPauseStateListener(this),machineTypeSocket.addMachineTypeStateListener(this),extensionsSocket.addExtensionsAndCartridgesStateListener(this),machine.getDiskDriveSocket().setInterfacesChangeListener(this),machine.getCartridgeSocket().setCartridgesModifiedStateListener(this),machine.getLedsSocket().setLedsStateListener(this))},this.auxWindowFirstResize=function(a){if(!auxWindow){auxWindowAddWidth=Math.min(16,a.outerWidth-a.innerWidth),auxWindowAddHeight=Math.min(100,a.outerHeight-a.innerHeight),auxWindow=a;var b=auxWindow.document;auxFsElementCenter=b.getElementById("wmsx-screen-fs-center"),auxCanvas=b.getElementById("wmsx-screen-canvas"),auxLogo=b.getElementById("wmsx-logo"),auxOsd=b.getElementById("wmsx-osd"),auxWindowUpdateTitle(),auxUpdateCanvasContentSize(),auxAspectAndScaleSetDefault(),suppressContextMenu(b.body),preventDrag(auxLogo),signalIsOn||updateLogo(),fileLoader.registerForDnDReject(auxFsElementCenter),controllersHub.addKeyInputElement(auxFsElementCenter),auxWindow.addEventListener("resize",auxWindowResized),auxWindow.addEventListener("beforeunload",auxWindowUnload),auxCanvas.focus()}},this.setFileLoaderDragMessage=function(a){var b=!!a;b&&(closeAllOverlays(),fileLoaderDropAreaMessage.textContent=a),b!=fileLoaderDragActive&&(fileLoaderDragActive=b,fileLoaderDropArea.classList.toggle("wmsx-visible",b),b&&wmsx.Util.scaleToFitParentWidth(fileLoaderDropArea,fsElement,11))};var afterMessageAction,machine,monitor,videoOutputMode=0,machineControls,peripheralControls,cartridgeSlot,fileLoader,fileDownloader,controllersHub,extensionsSocket,machineTypeSocket,controllersSocket,cartridgeSocket,diskDrive,stateMedia,readjustInterval=0,readjustRequestTime=0,readjustScreenSize={w:0,wk:0,h:0,pw:0
},isFullscreen=!1,isTouchDevice=wmsx.Util.isTouchDevice(),isMobileDevice=wmsx.Util.isMobileDevice(),isAndroidDevice=wmsx.Util.isAndroidDevice(),isBrowserStandalone=wmsx.Util.isBrowserStandaloneMode(),browserName=wmsx.Util.browserInfo().name,fileLoaderDropArea,fileLoaderDragActive=!1,fileLoaderDropAreaMessage,fullscreenAPIEnterMethod,fullScreenAPIExitMethod,fullScreenAPIQueryProp,fullScreenAPIExitUserRequested=!1,fullScreenScrollHack=!1,viewportTag,viewPortOriginalTag,viewPortOriginalContent,settingsDialog,saveStateDialog,diskSelectDialog,newHardDiskDialog,machineSelectDialog,touchConfigDialog,quickOtionsDialog,netPlayDialog,cartFormatDialog,pasteDialog,textEntryDialog,copyTextArea,unmuteMessage,canvas,canvasOuter,canvasLoadingIcon,canvasContext,canvasImageRenderingValue,scanlinesImage,touchControlsActive=!1,touchControlsDirBig=!1,touchControlsMirror=!1,virtualKeyboardMode=0,virtualKeyboardElement,virtualKeyboard,buttonsBar,buttonsBarInner,buttonsBarDesiredWidth=-1,barButtonLongTouchTarget,barButtonLongTouchSelectTimeout,barMenu,barMenus=[],barMenuActive,barMenuItemActive,barMenuSystem,barMenuItemTouchActivation=0,osd,osdTimeout,osdShowing=!1,cursorType="auto",cursorShowing=!0,cursorHideFrameCountdown=-1,signalIsOn=!1,crtFilter=-1,crtFilterEffective=null,crtScanlines=0,crtPhosphor=-1,crtPhosphorEffective=0,debugMode=!1,isLoading=!1,ledsStatePending,ledsInfoPending,aspectX=WMSX.SCREEN_DEFAULT_ASPECT,scaleY=1,scaleYBeforeUserFullscreen=0,pixelWidth=1,pixelHeight=1,mousePointerLocked=!1,targetWidth=wmsx.VDP.SIGNAL_MAX_WIDTH_V9938,scrTargetWidth=wmsx.VDP.SIGNAL_MAX_WIDTH_V9938,targetHeight=wmsx.VDP.SIGNAL_MAX_HEIGHT_V9938,fsElement,fsElementCenter,logo,logoCenter,logoImage,logoMessage,logoMessageText,logoMessageOK,logoMessageOKText,logoMessageActive=!1,logoLoadingIcon,scrollMessage,scrollMessageActive=!1,auxWindow,auxWindowAddWidth,auxWindowAddHeight,auxCanvas,auxCanvasContext,auxReadjustScreenSize={w:0,wk:0,h:0,pw:0},auxAspectX=WMSX.SCREEN_DEFAULT_ASPECT,auxScaleY=1.1,auxTargetWidth=targetWidth,auxScrTargetWidth=scrTargetWidth,auxTargetHeight=targetHeight,auxLogo,auxFsElementCenter,auxOsd={style:{}},powerButton,mediaIconsContainer,diskAButton,diskBButton,diskHButton,cartridge1Button,cartridge2Button,tapeButton,turboButton,capsLed,kanaLed,pauseLed,netplayButton,scaleDownButton,scaleUpButton,fullscreenButton,videoOutputButton,settingsButton,barButtonBackYOffset=25,mediaButtonBackYOffsets=[-72,-48,-24,0],OSD_TIME=4500,CURSOR_HIDE_FRAMES=180,FULLSCREEN_MODE=WMSX.SCREEN_FULLSCREEN_MODE,BAR_AUTO_HIDE=0===WMSX.SCREEN_CONTROL_BAR,BAR_MENU_MAX_ITEMS=25,VIRTUAL_KEYBOARD_WIDE_WIDTH=518,VIRTUAL_KEYBOARD_NARROW_WIDTH=419,VIRTUAL_KEYBOARD_HEIGHT=161,NARROW_WIDTH=538,SEMI_NARROW_WIDTH=650,domKeys=wmsx.DOMKeys,TOUCH_EXT_SLOT2_TIME=650,KEY_CTRL_MASK=domKeys.CONTROL,KEY_ALT_MASK=domKeys.ALT,KEY_SHIFT_MASK=domKeys.SHIFT,MENU_CLOSE_KEYS={};MENU_CLOSE_KEYS[domKeys.VK_ESCAPE.wc]=1,MENU_CLOSE_KEYS[domKeys.VK_CONTEXT.wc]=1;var MENU_EXEC_KEYS={};MENU_EXEC_KEYS[domKeys.VK_ENTER.wc]=1,MENU_EXEC_KEYS[domKeys.VK_SPACE.wc]=1;var MENU_SELECT_KEYS={};MENU_SELECT_KEYS[domKeys.VK_LEFT.wc]=-1,MENU_SELECT_KEYS[domKeys.VK_RIGHT.wc]=1;var MENU_ITEM_SELECT_KEYS={};MENU_ITEM_SELECT_KEYS[domKeys.VK_UP.wc]=-1,MENU_ITEM_SELECT_KEYS[domKeys.VK_DOWN.wc]=1;var OPEN_TYPE=wmsx.FileLoader.OPEN_TYPE,SCALE_STEP=.05,ASPECT_STEP=.01;init(),this.eval=function(str){return eval(str)}},wmsx.SettingsGUI={},wmsx.SettingsGUI.html=function(){
return'<div id="wmsx-modal" tabindex="-1"> <div id="wmsx-menu"> <div id="wmsx-back"> <div class="wmsx-back-arrow"> </div> </div> <div class="wmsx-caption"> Help & Settings </div> <div class="wmsx-items"> <div id="wmsx-menu-general" class="wmsx-item wmsx-selected"> GENERAL </div> <div id="wmsx-menu-media" class="wmsx-item"> MEDIA </div> <div id="wmsx-menu-inputs" class="wmsx-item"> KEYBOARD </div> <div id="wmsx-menu-ports" class="wmsx-item"> PORTS </div> <div id="wmsx-menu-about" class="wmsx-item"> ABOUT </div> <div id="wmsx-menu-selection"> </div> </div> </div> <div id="wmsx-content"> <div id="wmsx-general"> <div class="wmsx-left"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> F11 </div> </div> <div class="wmsx-desc"> Power </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> Shift </div>&nbsp;+&nbsp;<div class="wmsx-key"> F11 </div> </div> <div class="wmsx-desc">Reset Button</div> </div> <div class="wmsx-full-divider"></div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> T </div> </div> <div class="wmsx-desc">CPU Turbo Modes</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Y </div> </div> <div class="wmsx-desc">VDP Turbo Modes</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Q </div> </div> <div class="wmsx-desc">NTSC / PAL</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> W </div> </div> <div class="wmsx-desc">Video Out (V9990)</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> E </div> </div> <div class="wmsx-desc">CRT Filters</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> R </div> </div> <div class="wmsx-desc">CRT Scanlines</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> D </div> </div> <div class="wmsx-desc">Debug Modes</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> S </div> </div> <div class="wmsx-desc">Sprite Modes</div> </div> <div class="wmsx-full-divider"></div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key"> Shift </div> </div> <div class="wmsx-desc">Go back Modes</div> </div> </div> <div class="wmsx-right"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> 0-9 </div> </div> <div class="wmsx-desc">Load State</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Ctrl </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> 0-9 / F12 </div> </div> <div class="wmsx-desc">Save State / to File</div> </div> <div class="wmsx-full-divider"></div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> F8 </div>&nbsp;&nbsp;/&nbsp;&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> P </div> </div> <div class="wmsx-desc">Pause Emulation</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> O </div>&nbsp;/&nbsp;<div class="wmsx-key"> F </div> </div> <div class="wmsx-desc">Next Frame</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> F12 </div>&nbsp;&nbsp;/&nbsp;&nbsp;<div class="wmsx-key"> Shift </div>&nbsp;+&nbsp;<div class="wmsx-key"> F12 </div> </div> <div class="wmsx-desc">Fast / Slow Speed</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> Shift </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Arrows </div> </div> <div class="wmsx-desc">Adjust Speed</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> U </div>&nbsp;/&nbsp;<div class="wmsx-key"> I </div> </div> <div class="wmsx-desc">Colors / Palettes</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> G </div> </div> <div class="wmsx-desc">Capture Screen</div> </div> <div class="wmsx-full-divider"></div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Enter </div> </div> <div class="wmsx-desc">Full Screen</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Ctrl </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Arrows </div> </div> <div class="wmsx-desc">Screen Size / Width</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Backspace </div> </div> <div class="wmsx-desc">Defaults</div> </div> </div> </div> <div id="wmsx-media"> <div class="wmsx-top-left"> <div class="wmsx-hotkey"> <div class="wmsx-desc wmsx-heading"> Media Loading: </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> F6 </div> </div> <div class="wmsx-desc">Open File (Auto detect)</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key"> F7 </div> </div> <div class="wmsx-desc">Open URL (Auto detect)</div> </div> <div class="wmsx-hotkey wmsx-clear"> <div class="wmsx-command"> Drag &amp; Drop Files or URLs </div> <div class="wmsx-desc">&nbsp;</div> </div> </div> <div class="wmsx-top-right"> <div class="wmsx-hotkey"> <div class="wmsx-desc wmsx-heading"> Modifiers for Media Commands: </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key"> Shift </div> / Right-click: </div> <div class="wmsx-desc">On Drive B / Slot 2</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key wmsx-key-fixed"> Ctrl </div> </div> <div class="wmsx-desc">Load Empty Media</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key wmsx-key-fixed"> Alt </div> </div> <div class="wmsx-desc">Remove Media</div> </div> <div class="wmsx-hotkey wmsx-clear"> <div class="wmsx-command"> Right-drag / Ctrl-click: </div> <div class="wmsx-desc">No Auto-Reset</div> </div> </div> <div class="wmsx-clear"></div> <div class="wmsx-middle-left"> <div class="wmsx-hotkey"> <div class="wmsx-desc wmsx-heading"> Modifiers for Drag &amp; Drop: </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key wmsx-key-fixed"> Ctrl </div> </div> <div class="wmsx-desc">Load Image Files and Add Disks to Drive (A, B) Stack (up to 10 Disks) </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key wmsx-key-fixed"> Alt </div> </div> <div class="wmsx-desc">Add Files or ZIP Contents do Disk </div> </div> </div> <div class="wmsx-middle-right"> <div class="wmsx-hotkey"> <div class="wmsx-command"> + <div class="wmsx-key wmsx-key-fixed"> Ctrl </div> <div class="wmsx-key wmsx-key-fixed"> Alt </div> </div> <div class="wmsx-desc">Don&apos;t expand ZIP Contents </div> </div> </div> <div class="wmsx-full-divider"></div> <div class="wmsx-hotkey"> <div class="wmsx-desc wmsx-heading"> Media Switching / Control: </div> </div> <div class="wmsx-bottom-left"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Ctrl </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Hom / End </div> </div> <div class="wmsx-desc">Rewind / End Tape</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Ctrl </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Pg Up / Dn </div> </div> <div class="wmsx-desc">Seek Tape</div> </div> </div> <div class="wmsx-bottom-right"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> Pg Up / Dn </div> </div> <div class="wmsx-desc">Select Disk (A, B)</div> </div> </div> <div class="wmsx-clear"></div> <div class="wmsx-hotkey wmsx-bottom"> <div class="wmsx-command"> <div class="wmsx-key"> Shift </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Ctrl </div>&nbsp;<div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> F12 </div> </div> <div class="wmsx-desc"> Auto-Run Cassette program at current Tape position </div> </div> </div> <div id="wmsx-inputs"> <div class="wmsx-left"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> C </div> </div> <div class="wmsx-desc">Copy Screen Text</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> H </div> </div> <div class="wmsx-desc">Adjust Turbo Fire speed</div> </div> </div> <div class="wmsx-right"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> V </div> </div> <div class="wmsx-desc">Open Text Paste box</div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> B </div> </div> <div class="wmsx-desc">Open Text Input box</div> </div> </div> <div class="wmsx-bottom"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> L </div> </div> <div class="wmsx-desc">Toggle Host Keyboard Layout</div> </div> <div class="wmsx-right" > <div id="wmsx-inputs-msx-lang" class="wmsx-heading" > MSX Language: English </div> <ul class="wmsx-quick-options-list"> <li><div> </div><div id="wmsx-inputs-keyboard-name" class="wmsx-control"><button class="wmsx-control-dec"></button><span>AUTO</span><button class="wmsx-control-inc"></button></div></li> </ul> </div> <div id="wmsx-keyboard"></div> </div> <div class="wmsx-footer"> (hover mouse pointer over MSX Keyboard keys to display/modify mappings) </div> </div> <div id="wmsx-ports"> <div class="wmsx-left"> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> J </div> </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> K </div> </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> M </div> </div> </div> <div class="wmsx-hotkey"> <div class="wmsx-command"> <div class="wmsx-key wmsx-key-fixed"> Alt </div>&nbsp;+&nbsp;<div class="wmsx-key"> H </div> </div> </div> </div> <div class="wmsx-right"> <ul class="wmsx-quick-options-list"> <li><div>Toggle Joysticks mode</div><div id="wmsx-ports-joysticks-mode" class="wmsx-control"><button class="wmsx-control-dec"></button><span>AUTO</span><button class="wmsx-control-inc"></button></div></li> <li><div>Toggle Joykeys mode</div><div id="wmsx-ports-joykeys-mode" class="wmsx-control"><button class="wmsx-control-dec"></button><span>DISABLED</span><button class="wmsx-control-inc"></button></div></li> <li><div>Toggle Mouse mode</div><div id="wmsx-ports-mouse-mode" class="wmsx-control"><button class="wmsx-control-dec"></button><span>AUTO</span><button class="wmsx-control-inc"></button></div></li> <li><div>Adjust Turbo Fire speed</div><div id="wmsx-ports-turbofire-speed" class="wmsx-control"><button class="wmsx-control-dec"></button><span>OFF</span><button class="wmsx-control-inc"></button></div></li> </ul> </div> <div class="wmsx-bottom"> <div class="wmsx-bottom-left"> PORT 1 <div id="wmsx-ports-device1" class="wmsx-none-device"> <div id="wmsx-ports-device1-title" class="wmsx-device-title">NO DEVICE</div> <div class="wmsx-joy"> <div class="wmsx-virtual wmsx-joy-trig wmsx-joy-L"></div> <div class="wmsx-virtual wmsx-joy-trig wmsx-joy-R"></div> <div class="wmsx-joy-middle"></div> <div class="wmsx-joy-logo"></div> <div class="wmsx-joy-outleft"></div> <div class="wmsx-joy-outright"></div> <div class="wmsx-joy-left"> <div class="wmsx-joy-dir wmsx-joy-dirh"></div> <div class="wmsx-joy-dir wmsx-joy-dirv"></div> <div class="wmsx-joy-dir-center"></div> </div> <div class="wmsx-joy-right"> <div class="wmsx-joy-button wmsx-joy-A"></div> <div class="wmsx-joy-button wmsx-joy-B"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-X"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-Y"></div> </div> <div class="wmsx-joy-center"> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-BACK"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-START"></div> </div> <div id="wmsx-joy1-UP" class="wmsx-joy-hs wmsx-joy-hs-UP">&#9650;</div> <div id="wmsx-joy1-DOWN" class="wmsx-joy-hs wmsx-joy-hs-DOWN">&#9660;</div> <div id="wmsx-joy1-LEFT" class="wmsx-joy-hs wmsx-joy-hs-LEFT">&#9668;</div> <div id="wmsx-joy1-RIGHT" class="wmsx-joy-hs wmsx-joy-hs-RIGHT">&#9658;</div> <div id="wmsx-joy1-A" class="wmsx-joy-hs wmsx-joy-hs-A">A</div> <div id="wmsx-joy1-B" class="wmsx-joy-hs wmsx-joy-hs-B">B</div> <div id="wmsx-joy1-X" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-X">X</div> <div id="wmsx-joy1-Y" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-Y">Y</div> <div id="wmsx-joy1-L" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-L">L</div> <div id="wmsx-joy1-R" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-R">R</div> <div id="wmsx-joy1-BACK" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-BACK">BACK</div> <div id="wmsx-joy1-START" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-START">START</div> </div> <div class="wmsx-mouse"> <div id="wmsx-mouse1" class="wmsx-mouse-body"> <div class="wmsx-mouse-button1"></div><div class="wmsx-mouse-button2"></div> <div class="wmsx-mouse-logo"></div> </div> </div> <div class="wmsx-touch"></div> <div class="wmsx-none"></div> </div> </div> <div class="wmsx-bottom-right"> PORT 2 <div id="wmsx-ports-device2" class="wmsx-none-device"> <div id="wmsx-ports-device2-title" class="wmsx-device-title">NO DEVICE</div> <div class="wmsx-joy"> <div class="wmsx-virtual wmsx-joy-trig wmsx-joy-L"> </div> <div class="wmsx-virtual wmsx-joy-trig wmsx-joy-R"> </div> <div class="wmsx-joy-middle"> </div> <div class="wmsx-joy-logo"> </div> <div class="wmsx-joy-outleft"> </div> <div class="wmsx-joy-outright"> </div> <div class="wmsx-joy-left"> <div class="wmsx-joy-dir wmsx-joy-dirh"></div> <div class="wmsx-joy-dir wmsx-joy-dirv"></div> <div class="wmsx-joy-dir-center"></div> </div> <div class="wmsx-joy-right"> <div class="wmsx-joy-button wmsx-joy-A"></div> <div class="wmsx-joy-button wmsx-joy-B"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-X"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-Y"></div> </div> <div class="wmsx-joy-center"> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-BACK"></div> <div class="wmsx-virtual wmsx-joy-button wmsx-joy-START"></div> </div> <div id="wmsx-joy2-UP" class="wmsx-joy-hs wmsx-joy-hs-UP">&#9650;</div> <div id="wmsx-joy2-DOWN" class="wmsx-joy-hs wmsx-joy-hs-DOWN">&#9660;</div> <div id="wmsx-joy2-LEFT" class="wmsx-joy-hs wmsx-joy-hs-LEFT">&#9668;</div> <div id="wmsx-joy2-RIGHT" class="wmsx-joy-hs wmsx-joy-hs-RIGHT">&#9658;</div> <div id="wmsx-joy2-A" class="wmsx-joy-hs wmsx-joy-hs-A">A</div> <div id="wmsx-joy2-B" class="wmsx-joy-hs wmsx-joy-hs-B">B</div> <div id="wmsx-joy2-X" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-X">X</div> <div id="wmsx-joy2-Y" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-Y">Y</div> <div id="wmsx-joy2-L" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-L">L</div> <div id="wmsx-joy2-R" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-R">R</div> <div id="wmsx-joy2-BACK" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-BACK">BACK</div> <div id="wmsx-joy2-START" wmsx-virtual="true" class="wmsx-virtual wmsx-joy-hs wmsx-joy-hs-START">START</div> </div> <div class="wmsx-mouse"> <div id="wmsx-mouse2" class="wmsx-mouse-body"> <div class="wmsx-mouse-button1"></div><div class="wmsx-mouse-button2"></div> <div class="wmsx-mouse-logo"></div> </div> </div> <div class="wmsx-touch"></div> <div class="wmsx-none"></div> </div> </div> </div> <div class="wmsx-footer"> (hover mouse pointer over Controller buttons to display/modify mappings) </div> </div> <div id="wmsx-about"> <div id="wmsx-logo-version"> WebMSX&nbsp;&nbsp;-&nbsp;&nbsp;version&nbsp'+WMSX.VERSION+' </div> <div class="wmsx-info"> '+atob("Q3JlYXRlZCBieSBQYXVsbyBBdWd1c3RvIFBlY2Npbg==")+" <br> "+atob("PGEgdGFyZ2V0PSJfYmxhbmsiIGhyZWY9Imh0dHBzOi8vd2VibXN4Lm9yZyI+aHR0cHM6Ly93ZWJtc3gub3JnPC9hPg==")+' </div> <div id="wmsx-browserinfo"> </div> </div> </div> </div> <div id="wmsx-control-mapping-popup"> <div id="wmsx-control-mapping-popup-heading"> Control mapped to: </div> <div id="wmsx-control-mapping-popup-mapping" class="wmsx-command"></div> <div id="wmsx-control-mapping-popup-footer"> Press new key. <br> (right-click to clear) </div> </div>'
},wmsx.SettingsGUI.css=function(){
return'#wmsx-modal * { outline: none; box-sizing: border-box; } #wmsx-modal { position: absolute; overflow: hidden; width: 600px; height: 0; opacity: 0; visibility: hidden; top: 22px; left: 29px; color: hsl(0, 0%, 10%); font: normal 13px sans-serif; white-space: nowrap; text-align: initial; box-shadow: 3px 3px 15px 2px rgba(0, 0, 0, .4); transform: scale(0.85); transition: visibility .2s ease-out, opacity .2s ease-out, transform .2s ease-out, height .25s step-end; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: auto; z-index: 9; } #wmsx-modal.wmsx-show { transform: scale(1); transition: visibility .2s ease-out, opacity .2s ease-out, transform .2s ease-out; height: 440px; visibility: visible; opacity: 1; } #wmsx-modal .wmsx-heading { font-weight: 700; color: hsl(0, 0%, 30%); } #wmsx-modal .wmsx-link { font-weight: 700; line-height: 21px; color: hsl(228, 90%, 40%); cursor: pointer; } #wmsx-modal .wmsx-link:hover { outline: 1px solid; } .wmsx-command { position: relative; display: inline-block; font-weight: 600; color: hsl(0, 0%, 43%); } .wmsx-hotkey { height: 27px; padding: 3px 5px; box-sizing: border-box; } .wmsx-hotkey .wmsx-desc { display: inline-block; line-height: 21px; } .wmsx-key { position: relative; display: inline-block; top: -1px; min-width: 25px; height: 21px; padding: 4px 6px 3px; box-sizing: border-box; font-weight: 600; font-size: 12px; line-height: 12px; color: hsl(0, 0%, 42%); background: white; border-radius: 3px; border: 1px solid rgb(210, 210, 210); box-shadow: 0 1px 0 1px hsl(0, 0%, 47%); text-align: center; } .wmsx-key-fixed { width: 31px; padding-left: 0; padding-right: 2px; } .wmsx-footer { position: absolute; bottom: 13px; width: 543px; margin-top: 16px; text-align: center; } #wmsx-modal .wmsx-quick-options-list { margin: 1px 0 0; color: inherit; } #wmsx-modal .wmsx-quick-options-list > li { margin: 0; } #wmsx-modal .wmsx-quick-options-list > li > * { height: 25px; line-height: 25px; font-size: inherit; } #wmsx-modal .wmsx-control { width: 180px; font-weight: bold; background: rgb(243, 243, 243); border-radius: 3px; box-shadow: 1px 1px 1px rgba(0, 0, 0, .27) } #wmsx-modal .wmsx-control > button { background: white; border-color: hsl(0, 0%, 80%); } #wmsx-modal .wmsx-control > button::after { top: 6px; } #wmsx-modal .wmsx-control > button.wmsx-control-dec::after { left: 3px; border-right-color: hsl(0, 0%, 55%); } #wmsx-modal .wmsx-control > button.wmsx-control-inc::after { right: 3px; border-left-color: hsl(0, 0%, 55%); } #wmsx-menu { position: relative; background: white; border-bottom: 1px solid hsl(0, 0%, 72%); } #wmsx-menu #wmsx-back { position: absolute; right: 2px; width: 40px; height: 34px; margin: 3px 1px; padding: 16px 12px; cursor: pointer; } #wmsx-menu #wmsx-back:hover { background: rgba(0, 0, 0, .12); } .wmsx-back-arrow { display: block; height: 0; border-radius: 1000px; background: hsl(0, 0%, 98%); } .wmsx-back-arrow:before { content: ""; display: block; position: absolute; width: 14px; height: 2px; border-radius: inherit; background: inherit; transform: rotate(-45deg); transform-origin: 7px 1px; } .wmsx-back-arrow:after { content: ""; display: block; position: absolute; width: 14px; height: 2px; border-radius: inherit; background: inherit; transform: rotate(45deg); transform-origin: 7px 1px; } #wmsx-menu .wmsx-caption { height: 29px; margin: 0 -1px; padding: 10px 0 0 25px; font-size: 18px; color: white; background: hsl(358, 66%, 50%); box-shadow: 0 1px 3px rgba(0, 0, 0, .9); vertical-align: middle; box-sizing: content-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } #wmsx-menu .wmsx-items { position: relative; width: 80%; height: 39px; margin: 0 auto; font-weight: 600; } #wmsx-menu .wmsx-item { float: left; width: 20%; height: 100%; padding-top: 13px; font-size: 14px; color: rgba(0, 0, 0, .43); text-align: center; cursor: pointer; } #wmsx-menu .wmsx-selected { color: hsl(358, 67%, 46%); } #wmsx-menu #wmsx-menu-selection { position: absolute; left: 0; bottom: 0; width: 20%; height: 3px; background: hsl(358, 67%, 46%); transition: left 0.3s ease-in-out; } #wmsx-content { position: relative; left: 0; width: 3000px; height: 362px; background: rgb(218, 218, 218); transition: left 0.3s ease-in-out } #wmsx-general, #wmsx-inputs, #wmsx-media, #wmsx-ports, #wmsx-about { position: absolute; width: 600px; height: 100%; box-sizing: border-box; } #wmsx-general { padding-top: 13px; padding-left: 32px; } #wmsx-general .wmsx-left { float: left; width: 255px; } #wmsx-general .wmsx-left .wmsx-command { width: 104px; } #wmsx-general .wmsx-right { float: left; } #wmsx-general .wmsx-right .wmsx-command { width: 161px; } #wmsx-media { left: 600px; } #wmsx-media { padding-top: 8px; padding-left: 32px; } #wmsx-media .wmsx-full-divider { height: 13px; } #wmsx-media .wmsx-top-left { float: left; width: 235px; } #wmsx-media .wmsx-top-right { float: left; height: 135px; } #wmsx-media .wmsx-middle-left { float: left; width: 284px; } #wmsx-media .wmsx-middle-right { float: left; margin-top: 54px; } #wmsx-media .wmsx-bottom-left { float: left; width: 295px; } #wmsx-media .wmsx-bottom-right { float: left; padding-top: 27px; } #wmsx-media .wmsx-top-left .wmsx-command { width: 43px; } #wmsx-media .wmsx-top-right .wmsx-command { width: 154px; } #wmsx-media .wmsx-middle-left .wmsx-command { width: 54px; } #wmsx-media .wmsx-middle-right .wmsx-command { width: 88px; } #wmsx-media .wmsx-bottom-left .wmsx-command { width: 172px; } #wmsx-media .wmsx-bottom-right .wmsx-command { width: 131px; } #wmsx-media .wmsx-bottom .wmsx-command { width: 172px; } #wmsx-inputs { left: 1200px; padding: 12px 0 0 33px; } #wmsx-inputs .wmsx-left { float: left; width: 290px; } #wmsx-inputs .wmsx-command { width: 85px; } #wmsx-inputs .wmsx-bottom { margin-top: 18px; } #wmsx-inputs .wmsx-bottom .wmsx-hotkey { display: inline-block; width: 280px; margin-bottom: 2px; vertical-align: bottom; } #wmsx-inputs .wmsx-bottom .wmsx-right { display: inline-block; width: 251px; text-align: right; } #wmsx-inputs .wmsx-bottom .wmsx-heading { display: inline-block; width: 180px; margin-bottom: 2px; text-align: center; } #wmsx-inputs #wmsx-inputs-msx-lang { padding: 0 5px 5px 0; } #wmsx-inputs-keyboard-name { color: hsl(228, 90%, 40%); } #wmsx-keyboard { position: relative; top: 2px; width: 535px; height: 174px; padding: 12px 0 0 13px; margin-top: 5px; background: hsl(0, 0%, 25%); border-radius: 1px 1px 0 0; box-sizing: border-box; box-shadow: 0 1px 0 1px hsl(0, 0%, 20%), 0 3px 4px 1px hsl(0, 0%, 40%); } #wmsx-ports { left: 1800px; padding: 13px 0 0 27px; } #wmsx-ports .wmsx-left { float: left; width: 126px; padding-left: 32px; } #wmsx-ports .wmsx-command { width: 91px; } #wmsx-ports .wmsx-hotkey { height: 31px; } #wmsx-ports .wmsx-right { float: left; width: 375px; } #wmsx-ports .wmsx-right .wmsx-quick-options-list > li { margin: 0 0 6px; } #wmsx-ports .wmsx-bottom { width: 546px; text-align: center; clear: both; } #wmsx-ports .wmsx-bottom-left, #wmsx-ports .wmsx-bottom-right { display: inline-block; height: 162px; margin-top: 15px; vertical-align: top; text-align: center; font-size: 14px; line-height: 14px; font-weight: bold; color: hsl(0, 0%, 32%); } #wmsx-ports .wmsx-device-title { margin-top: 11px; height: 12px; font-size: 12px; line-height: 12px; font-weight: bold; color: hsl(0, 0%, 35%); text-align: center; } #wmsx-ports .wmsx-joystick-device .wmsx-joy, #wmsx-ports .wmsx-joykeys-device .wmsx-joy { display: block; } #wmsx-ports .wmsx-mouse-device .wmsx-mouse { display: block; } #wmsx-ports .wmsx-touch-device .wmsx-touch { display: block; } #wmsx-ports .wmsx-none-device .wmsx-none { display: block; } #wmsx-ports-joysticks-mode, #wmsx-ports .wmsx-joystick-device .wmsx-device-title { color: hsl(228, 90%, 40%) } #wmsx-ports-joykeys-mode, #wmsx-ports .wmsx-joykeys-device .wmsx-device-title { color: hsl(0, 90%, 43%); } #wmsx-ports-mouse-mode, #wmsx-ports .wmsx-mouse-device .wmsx-device-title { color: hsl(120, 100%, 30%); } #wmsx-ports-turbofire-speed { color: hsl(0, 0%, 30%); } #wmsx-ports .wmsx-touch-device, #wmsx-ports .wmsx-touch-device .wmsx-device-title { color: hsl(167, 100%, 31%); } #wmsx-ports .wmsx-joykeys-device .wmsx-virtual { opacity: 0.33; } #wmsx-ports .wmsx-joykeys-device .wmsx-joy-button.wmsx-virtual { background: hsl(0, 0%, 75%); box-shadow: 0 3px 0 0 hsl(0, 0%, 60%), 0 3px 0 1px hsl(0, 0%, 40%); } #wmsx-ports .wmsx-joykeys-device .wmsx-joy-hs.wmsx-virtual { display: none; } #wmsx-ports .wmsx-joy { display: none; position: relative; top: 14px; width: 252px; font-weight: bold; text-align: center; vertical-align: top; box-sizing: border-box; } #wmsx-ports-device1 .wmsx-joy { margin-right: 8px; } #wmsx-ports-device2 .wmsx-joy { margin-left: 8px; } .wmsx-joy-logo, .wmsx-mouse-logo { position: absolute; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAOCAYAAABU4P48AAAGXklEQVRIx9VWbUyUVxZ+3vedd2YYvmYQhrF8CNuCWMoKgqhp7a7rtutC9gOMrtnEuEZ0daHaWLtsqV2DGnaTkqbJbsq2dmti2ZZ1I2m0mHZr1JKCgDUja3EHbEUHBDowMzAM77xf9579USQ0Xfu/z697T87JeXKec8+5wDyovk7AdwALJB+y2zznH13+53yb9YdDmuabMM1geVzcSgD66ZlIX1VyYplEcN5QtXMb/nPz6AsNDT/du3t3Y1RR2OXLl9+sra39e1NT07YtW7Y8p2ma0tvbe2rXrl1v1NfXL9m0adNOl8tVQUSJRPSNwlgsFkHX9etlZWUvAPi8qrq69NixY81zipIhybLR1dn52oH9+98AYCwEpduseZ8UP3aXNjxO9ORaaitcrtD6NUQb19OLuctC9EQ50ZPr6JPvr1DswI6ujo4hmkdbW9ssgOozZ84MLLJFAez0er2fRqNR4pzTt0HVdXrx8OELAFb++8KFTkXXyeCMLnZ2stzc3JMAkgHAstASwGSfonz6eGJCNqwy/quqDIybAFmSJFEeVzVjqc0mF1jlOAmoWF5cnHU/trS0NAHAz0pKSpbdt7ndbltFRcVv8/PzVzkcDszMzCAcDkOSpK/yEYFxDkEU4Xa7YbPb8btnntmY7HS2lZSVPgJRxNj4BPbu2X1reHj4PQCzXyMc0PTI9ahyCamsGpBRYLdbhnWd51ok/CIx3n4+MhvblSLJSyDgEZtclux22+7HZmZmoqioaH1WVpZjQbH0dLGqqmqFIAiIxWKoq6sLt7a2Xnc6nZosy9bUtLQ4q9UqK4oi76utza3Zsycp0ZWMnTU1BVa7Haqm4bmDB0NDvsF/AOgAwL/Rz9sf8vx8ZHXxLP1gHU2WF7PWFXlztLaUaF0Z/TItJUDlJeR/OJs3bK6OMMYW5DQMg1pbW9XFEkejUWpvb4+Njo6ajHPyj4ywkdFRYyIQ0L/w+8NHjx9/CUA+AJcrJeXAlatXI+FYjEKKQpNzc9TU3KwAeBuAazFJcdGZhmMxf38sdhemiVSLLA7MKYwxRiCOBFGUpzSdfzgeMNY89WOrIAgL0kqShK1bt9oAgHMOToT4+HjMzEZw4eJFDYKArMxMMSMjw5KaliZ7PB5n3bPPHn2psfFlACwcCr17x++fMBiDbhpQNR3nOzoiAF4BEF5MWFp88atabHVi4tq1cfZCcEK/qrJMi0VyioKoEYm3NUO/EQxT8aHnxWU5OVIwGCSv18uzs7NFUZLAGMOAz8dNk8MR7xCC4WnzWGNjt9frjQVCodSbPp/g8/koyeWCIyFBSExKyj154sTEn1599emfVFZWQhRFDgEEwqqysoSLH300NjM9/fGDKgwAc1PMGA7oBgPnKLBZZW9MNWcNExtsdus/A5NznuV5lJGdLRKA28O3WUtLyywAmIxBN0309fbq3b1X9JiuY1lurjXd42EnXn/9ZM2OHU3bt207XLdv3+mbgz5NNXTEJyVKss32602VlTUWq9Wi6ToGBwe5SYTMnBw0t7Q0AFjzbYTZQDT22eeqGjFMEx5BFHyqasYYgygAgZimi48VTqemp0uMc/T2XlXujvgDkZhCBufQdB09PVdCPd3dk7phkNvjEf919uzTM4bRPG0Yh0OqevzW2NivVpevsYsWGT09vWzvgf2Ppi1dmkaCgO6uLmNjefngtb6+WYMx5BcW2pr+8te3AXzvQYTpvalQr183IhYixAOSSGSZZQzgHCs5t4dXrlKS4uIESRTx/vvngpOTU9dD4WkmyzKmIxH4Boe+vOv3+yFJgmCxwCSCwRgM04RJBN0wYImLw8eXLuHmwADVHznihCDgzp072L558xCAP7x76tTpYCgMm92O9Rt/lPeb2tojAJK+NtYW4YvOqPK3rrm5gxGTOyYMwz8QUxMMw1xyi3M1u79//OChQ6mqpskffvBBH4CXT771luve2NgTwclJpauzs6uwqOhy09GjSVPBYB6IOM0/TgIgiCL1X7sWueH1jhxoaHD88fnfZ5imaT/X3j4Kzl8DcLb9nXe8nOC02W0VhmkI46P3Sm0Ox8Oaongf9H+Q52VIBzADQAGQBoABCAJIAWADcA/AbQBOAEXzq9MP4EsAHgA5/0dFAJiGIHwGIjeAgq/2FmYA9C/yibs/9ubz+wFM4LuG/wFQqng3L3GLVwAAAABJRU5ErkJggg=="); } .wmsx-joy .wmsx-joy-trig { position: absolute; top: -6px; width: 45px; height: 40px; background: hsl(0, 0%, 68%); border-radius: 5px; box-shadow: inset 1px 1px hsl(0, 0%, 90%), 0 2px 2px 2px hsl(0, 0%, 47%); } .wmsx-joy .wmsx-joy-L { left: 25px; border-top-left-radius: 16px; } .wmsx-joy .wmsx-joy-R { right: 25px; border-top-right-radius: 16px; } .wmsx-joy .wmsx-joy-middle { position: absolute; left: 2px; right: 2px; height: 85px; background: white; background: linear-gradient(hsl(0, 0%, 94%), white, white, hsl(0, 0%, 93%)); border-radius: 50px 50px 40px 40px; box-shadow: 0 5px 0 0     hsl(0, 0%, 78%), 0 1px 2px 1px hsl(0, 0%, 73%), 0 6px 4px 1px hsl(0, 0%, 40%); } .wmsx-joy-logo { top: 17px; left: 103px; width: 46px; height: 14px; } .wmsx-joy .wmsx-joy-outleft, .wmsx-joy .wmsx-joy-outright { position: absolute; width: 100px; height: 97px; background: white; border-radius: 100%; transform-origin: 50px 50px; transform: rotate(6deg); box-shadow: 0 5px 0 -1px      hsl(0, 0%, 78%), 0 6px 0 -1px      hsl(0, 0%, 78%), -1px 8px 2px -2px hsl(0, 0%, 48%), 0 9px 4px -2px    hsl(0, 0%, 36%); } .wmsx-joy .wmsx-joy-outright { right: 0; transform: rotate(-6deg); box-shadow: 0 5px 0 -1px     hsl(0, 0%, 78%), 0 6px 0 -1px     hsl(0, 0%, 78%), 1px 8px 2px -2px hsl(0, 0%, 48%), 0 9px 4px -2px   hsl(0, 0%, 36%); } .wmsx-joy .wmsx-joy-left, .wmsx-joy .wmsx-joy-right { position: absolute; top: 10px; width: 80px; height: 78px; background: hsl(0, 0%, 87%); border: 1px solid hsl(0, 0%, 76%); border-right: none; border-bottom: none; border-radius: 100%; box-sizing: border-box; } .wmsx-joy .wmsx-joy-left { left: 10px; } .wmsx-joy .wmsx-joy-left:before { content: ""; position: absolute; top: 9px; left: 10px; width: 58px; height: 58px; background: hsl(0, 0%, 77%); border-radius: 1000px; box-sizing: border-box; } .wmsx-joy .wmsx-joy-right { right: 10px; } .wmsx-joy .wmsx-joy-right:before { content: ""; position: absolute; top: 20px; right: 16px; width: 27px; height: 57px; background: hsl(0, 0%, 77%); border-radius: 1000px; box-sizing: border-box; transform: rotate(45deg); } .wmsx-joy .wmsx-joy-dir { position: absolute; color: hsl(0, 0%, 95%); background: hsl(0, 0%, 49%); border: 1px solid hsl(0, 0%, 64%); border-right-color: hsl(0, 0%, 42%); border-bottom-color: hsl(0, 0%, 35%); border-radius: 2px 2px 0 0; box-shadow:  0 3px 1px hsl(0, 0%, 40%), 0 3px 0 1px hsl(0, 0%, 15%); box-sizing: border-box; } .wmsx-joy .wmsx-joy-dirh { top: 28px; left: 16px; width: 46px; height: 14px; } .wmsx-joy .wmsx-joy-dirv { top: 12px; left: 32px; width: 14px; height: 45px; } .wmsx-joy .wmsx-joy-dir-center { position: absolute; top: 29px; left: 30px; width: 18px; height: 12px; background: hsl(0, 0%, 49%); } .wmsx-joy .wmsx-joy-dir-center:after { content: ""; position: absolute; top: 2px; left: 4px; height: 8px; width: 8px; border-radius: 1000px; box-shadow: inset 0 0 6px hsl(0, 0%, 36%), inset 1px 1px 2px -1px hsl(0, 0%, 36%), 1px 1px 0 hsl(0, 0%, 65%); } .wmsx-joy-button { position: relative; display: inline-block; top: -1px; min-width: 19px; height: 19px; margin: 0 1px; font-size: 12px; line-height: 14px; padding-top: 3px; color: hsl(0, 0%, 97%); background: hsl(0, 00%, 54%); border-radius: 100%; box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 0 0 hsl(0, 0%, 40%), 0 3px 0 1px hsl(0, 0%, 15%); box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .wmsx-joy-button.wmsx-square { top: -2px; min-width: 18px; height: 18px; font-size: 11px; border-radius: 1px 1px 0 0; padding: 2px 5px 0; box-shadow: inset 1px 1px hsl(0, 0%, 64%), inset -1px -1px hsl(0, 0%, 35%), 0 3px 0 0 hsl(0, 0%, 40%), 0 3px 0 1px hsl(0, 0%, 15%); } .wmsx-joy .wmsx-joy-A { position: absolute; top: 46px; left: 29px; background: hsl(132, 90%, 41%); box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 0 0 hsl(127, 90%, 30%), 0 3px 0 1px hsl(0, 0%, 15%); } .wmsx-joy .wmsx-joy-B { position: absolute; top: 26px; left: 49px; background: hsl(0, 94%, 63%); box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 0 0 hsl(0, 90%, 43%), 0 3px 0 1px hsl(0, 0%, 15%); } .wmsx-joy .wmsx-joy-X { position: absolute; top: 26px; left: 9px; background: hsl(234, 80%, 66%); box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 0 0 hsl(234, 80%, 47%), 0 3px 0 1px hsl(0, 0%, 15%); } .wmsx-joy .wmsx-joy-Y { position: absolute; top: 6px; left: 29px; background: hsl(58, 100%, 44%); box-shadow: inset 0 2px 1px rgba(0, 0, 0, 0.06), 0 3px 0 0 hsl(56, 100%, 33%), 0 3px 0 1px hsl(0, 0%, 15%); } .wmsx-joy .wmsx-joy-center .wmsx-joy-button { position: absolute; top: 43px; width: 18px; height: 09px; color: hsl(0, 0%, 58%); border-radius: 1000px; background: hsl(0, 0%, 82%); box-shadow: inset 0 1px 1px hsl(0, 0%, 70%), 0 2px 0 0 hsl(0, 0%, 62%), 0 2px 0 1px hsl(0, 0%, 30%); } .wmsx-joy .wmsx-joy-center .wmsx-joy-BACK { left: 103px; border-top-right-radius: 1px; border-bottom-right-radius: 1px; } .wmsx-joy .wmsx-joy-center .wmsx-joy-START { right: 103px; border-top-left-radius: 1px; border-bottom-left-radius: 1px; } .wmsx-joy-hs { position: absolute; border: 1px solid transparent; border-radius: 1000px; box-sizing: border-box; cursor: pointer; } .wmsx-joy-hs.wmsx-joy-hs-unmapped { color: rgb(30, 30, 30); -webkit-font-smoothing: initial; -moz-osx-font-smoothing: initial; } .wmsx-joy-hs-UP, .wmsx-joy-hs-DOWN, .wmsx-joy-hs-LEFT, .wmsx-joy-hs-RIGHT { width: 26px; height: 25px; padding-top: 6px; font-size: 10px; line-height: 10px; color: hsl(0, 0%, 95%); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .wmsx-joy-hs-UP { top: 18px; left: 37px; padding-top: 7px; } .wmsx-joy-hs-DOWN { top: 51px; left: 37px; padding-top: 4px; } .wmsx-joy-hs-LEFT { top: 34px; left: 21px; } .wmsx-joy-hs-RIGHT { top: 34px; left: 53px; } .wmsx-joy-hs-A, .wmsx-joy-hs-B, .wmsx-joy-hs-X, .wmsx-joy-hs-Y { width: 21px; height: 23px; font-size: 12px; line-height: 18px; color: hsl(0, 0%, 99%); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .wmsx-joy-hs-A { top: 57px; right: 39px; } .wmsx-joy-hs-B { top: 37px; right: 19px; } .wmsx-joy-hs-X { top: 37px; right: 59px; } .wmsx-joy-hs-Y { top: 17px; right: 39px; } .wmsx-joy-hs-L, .wmsx-joy-hs-R { width: 54px; height: 25px; top: -20px; color: hsl(0, 0%, 52%); font-size: 12px; line-height: 12px; border-radius: 0; } .wmsx-joy-hs-L { left: 21px; } .wmsx-joy-hs-R { right: 22px; } .wmsx-joy-hs-BACK, .wmsx-joy-hs-START { width: 26px; height: 29px; top: 39px; padding-top: 18px; font-size: 7px; font-weight: normal; line-height: 11px; color: hsl(0, 0%, 54%); border-radius: 0; } .wmsx-joy-hs-BACK { left: 99px; } .wmsx-joy-hs-START { right: 99px; } #wmsx-ports .wmsx-mouse { display: none; position: relative; width: 230px; } #wmsx-ports .wmsx-mouse-body { position: relative; top: 6px; left: -8px; overflow: visible; white-space: nowrap; width: 59px; height: 75px; margin: 14px auto; background: linear-gradient(166deg, white, white, white, white, hsl(0, 0%, 97%), hsl(0, 0%, 90%)); border: 1px solid hsl(0, 0%, 81%); border-right-color: hsl(0, 0%, 76%); border-radius: 10px 8px 25px 32px; box-sizing: border-box; transform: skew(-47deg, 30deg); box-shadow: /* inset 0px 0px 1px 0      hsl(0, 0%, 45% */ 3px 2px 0   -1px hsl(0, 0%, 70%) ,4px 3px 0   -1px hsl(0, 0%, 60%)       /* line */ ,6px 4px 0   -2px hsl(0, 0%, 82%)       /* line */ ,5px 0   0   -4px hsl(0, 0%, 70%) ,6px 0   0   -4px hsl(0, 0%, 70%) ,7px 1px 0   -4px hsl(0, 0%, 70%) ,8px 2px 0   -4px hsl(0, 0%, 70%) ,9px 3px 0   -4px hsl(0, 0%, 70%) ,10px 4px 0  -4px hsl(0, 0%, 70%) ,11px 5px 0  -4px hsl(0, 0%, 70%) ,12px 6px 0  -4px hsl(0, 0%, 70%) ,13px 7px 0  -4px hsl(0, 0%, 70%) ,14px 8px 0  -4px hsl(0, 0%, 70%) ,17px 8px 0  -6px hsl(0, 0%, 70%) ,18px 11px 0 -6px hsl(0, 0%, 70%) ,2px 6px 0   -4px hsl(0, 0%, 70%)       /* bottom correction */ ,4px 7px 0   -4px hsl(0, 0%, 70%)       /* bottom correction */ ,8px 9px 0   -4px hsl(0, 0%, 70%)       /* bottom correction */ ,10px 09px 0 -4px hsl(0, 0%, 70%)       /* bottom correction */ ,12px 10px 0 -4px hsl(0, 0%, 70%)       /* bottom correction */ ,14px 10px 0 -4px hsl(0, 0%, 70%)       /* bottom correction */ ,19px 11px 4px -6px hsl(0, 0%, 3%)      /* shadow */ ,13px 12px 4px -6px hsl(0, 0%, 3%)      /* shadow */ ; } #wmsx-ports .wmsx-mouse-button1, #wmsx-ports .wmsx-mouse-button2 { position: absolute; height: 25px; background: transparent; border: 0 solid hsl(0, 0%, 70%); box-sizing: border-box; } #wmsx-ports .wmsx-mouse-button1 { width: 48%; border-right-width: 1px; } #wmsx-ports .wmsx-mouse-button2 { width: 101%; border-bottom-width: 1px; } .wmsx-mouse-logo { top: 29px; left: 14px; width: 24px; height: 7px; background-size: 100%; } #wmsx-ports .wmsx-none { display: none; width: 104px; height: 106px; margin: 12px 63px 0; border: 12px solid hsl(0, 0%, 72%); border-radius: 100%; box-sizing: border-box; } #wmsx-ports .wmsx-none:after { content: ""; display: block; position: relative; top: 50%; left: -6px; width: 92px; height: 12px; background: hsl(0, 0%, 72%); transform: translateY(-50%) rotate(-45deg); } #wmsx-ports .wmsx-touch { display: none; width: 68px; height: 107px; margin: 8px 81px 0; background: white; border: 1px solid hsl(0, 0%, 90%); border-radius: 8px; box-sizing: border-box; box-shadow: 0 0 0 1px hsl(0, 0%, 70%), 1px 1px 0 1px hsl(0, 0%, 40%), 2px 3px 4px hsl(0, 0%, 26%); } #wmsx-ports .wmsx-touch:before { content: ""; display: block; position: relative; width: 58px; height: 77px; margin: 13px auto 4px; background: hsl(0, 0%, 35%); } #wmsx-ports .wmsx-touch:after { content: ""; position: relative; display: block; width: 6px; height: 6px; left: 29px; border: 1px solid hsl(0, 0%, 60%); background: hsl(0, 0%, 95%); border-radius: 100%; } #wmsx-about { left: 2400px; font-size: 18px; } #wmsx-about #wmsx-logo-version { width: 380px; height: 212px; margin: 36px auto 24px; color: hsl(0, 0%, 98%); padding-top: 170px; box-sizing: border-box; text-align: center; background: black url("'+wmsx.Images.urls.logo+'") center 50px no-repeat; background-size: 334px 100px; box-shadow: 3px 3px 14px rgb(75, 75, 75); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } #wmsx-about .wmsx-info { line-height: 30px; text-align: center; } #wmsx-about a { color: rgb(0, 40, 200); text-decoration: none; } #wmsx-about a:hover { text-decoration: underline; } #wmsx-about #wmsx-browserinfo { position: absolute; left: 0; right: 0; bottom: 7px; font-size: 10px; text-align: center; color: transparent; } #wmsx-control-mapping-popup { display: none; position: fixed; padding: 4px 9px; font: normal 13px sans-serif; line-height: 19px; text-align: center; vertical-align: top; border-radius: 6px; border: 8px white solid; background: rgb(220, 220, 220); box-shadow: 0 3px 3px 2px rgba(0, 0, 0, .55); box-sizing: border-box; z-index: 10; } #wmsx-control-mapping-popup.wmsx-locked { border-color: hsl(60, 100%, 68%); } #wmsx-control-mapping-popup .wmsx-command { width: auto; line-height: 21px; margin: 10px 0; font-weight: bold; } #wmsx-control-mapping-popup:after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; width: 0; margin: 0 auto; border-width: 10px; border-style: solid; border-color: transparent white white transparent; box-shadow: 4px 4px 2px 0 rgba(0, 0, 0, .55); box-sizing: border-box; transform: translateY(16px) rotate(45deg); } #wmsx-control-mapping-popup.wmsx-locked:after { border-color: transparent hsl(60, 100%, 68%) hsl(60, 100%, 68%) transparent; } .wmsx-clear { clear: both; } .wmsx-divider { clear: both; height: 27px; } .wmsx-full-divider { clear: both; height: 21px; } #wmsx-general .wmsx-full-divider { clear: both; height: 18px; }'
},wmsx.ControlMappingPopup=function(){"use strict";function a(){j=document.getElementById("wmsx-control-mapping-popup"),k=document.getElementById("wmsx-control-mapping-popup-heading"),l=document.getElementById("wmsx-control-mapping-popup-mapping"),m=document.getElementById("wmsx-control-mapping-popup-footer"),j.tabIndex=-1,j.addEventListener("mousedown",b),j.addEventListener("keydown",c),j.addEventListener("keyup",d)}function b(a){wmsx.Util.blockEvent(a),3===a.which&&r.clearControlEditing()}function c(a){if(s){var b=o.codeNewForKeyboardEvent(a);if(n||b!==o.VK_ESCAPE.wc)return o.isModifierKey(a)?t=o.codeNewForKeyboardEvent(a):f(a),a.stopPropagation(),a.preventDefault(),!1}}function d(a){if(s){var b=o.codeNewForKeyboardEvent(a);return t===b&&f(a),a.stopPropagation(),a.preventDefault(),!1}}function e(){if(!r)return void(j.style.display="none");j.style.display="block",window.setTimeout(function(){j.focus()},0);var a=r.getMappingForControl(s,i)||[];l.innerHTML=h(a);var b=j.getBoundingClientRect(),c=p-b.width/2|0,d=q-b.height-u|0;j.style.top=d+"px",j.style.left=c+"px"}function f(a){var b=o.nameForKeyboardEvent(a);if(b){var c={wc:o.codeNewForKeyboardEvent(a),n:b};r.customizeControl(s,i,c),t=null,e()}}function g(a){r.customizeControl(s,i,a),e()}function h(a){if(a.constructor===String)return a;if(a.constructor===Object)return h(a.from)+"&nbsp;&nbsp;=>&nbsp;&nbsp;"+h(a.to);if(!a||0===a.length)return"- none -";for(var b="",c=0;c<a.length;c++){var d,e=a[c];if(e.constructor===String)d=e;else{c>0&&(b+="&nbsp;,&nbsp;");var f=e.n&&e.n.constructor===Array?e.n:[e.n];d="";for(var g=0,i=f.length;g<i;++g){var j=e.wc?"wmsx-key":e.n.length>1?"wmsx-joy-button wmsx-square":"wmsx-joy-button";g>0&&(d+=g===i-1?"&nbsp;+&nbsp;":"&nbsp;"),d+='<DIV class = "'+j+'">'+f[g]+"</DIV>"}}b+=d}return b}this.show=function(a,b,c,d,f,g,h,l){p=d,q=f,r=a,s=b,i=c,t=null,k.innerHTML=g,m.innerHTML=h,n=!!l,j.classList.toggle("wmsx-locked",n),e()},this.hide=function(){p=q=0,r=s=i=null,e()},this.joystickButtonDetected=function(a,b){b===i&&g(a)};var i,j,k,l,m,n,o=wmsx.DOMKeys,p=0,q=0,r=null,s=null,t=null,u=14;!function(){a()}()},wmsx.ControlMappingPopup.get=function(){"use strict";return wmsx.ControlMappingPopup.instance||(wmsx.ControlMappingPopup.instance=new wmsx.ControlMappingPopup),wmsx.ControlMappingPopup.instance},wmsx.ControlMappingPopup.instance=null,wmsx.KeyboardConfigurator=function(a,b,c){"use strict";function d(){n=document.getElementById("wmsx-inputs-msx-lang"),m=document.getElementById("wmsx-inputs-keyboard-name"),m.wmsxText=m.querySelector(":scope > span"),m.querySelector(":scope > button").wmsxDec=!0,wmsx.Util.onTapOrMouseDownWithBlock(m,function(b){"BUTTON"===b.target.tagName&&a.toggleKeyboardLayout(b.target.wmsxDec)}),b.addEventListener("mousedown",e,!0),k=document.getElementById("wmsx-keyboard"),l=wmsx.VirtualKeyboard.create(k,function(a){a.wmsxKey&&p.push(a),a.addEventListener("mouseenter",f),a.addEventListener("mouseleave",g)},!1,t,u,!0)}function e(a){var b=a.target.wmsxKey;b?r===b?1===a.which?s=!s:3===a.which&&o.clearKey(r):(q=a.target,r=q.wmsxKey,s=1===a.which):(s=!1,g()),j.refresh(),h()}function f(a){s||(a.target.wmsxKey?(q=a.target,r=q.wmsxKey,h()):g())}function g(){s||(q=r=null,h())}function h(){if(!r)return v.hide(),void b.focus();var a=q.getBoundingClientRect(),c=a.left+a.width/2,d=a.top;v.show(j,r,0,c,d,w,x,s)}function i(){for(var a=0;a<p.length;++a){var b=o.getKeyMapping(p[a].wmsxKey);p[a].classList.toggle("wmsx-keyboard-key-unmapped",!b||0===b.length)}}var j=this;this.keyboardSettingsStateUpdate=function(){this.refresh()},this.refresh=function(){n.textContent="MSX Language: "+("ja"===t?"Japanese":"English"),m.wmsxText.textContent=o.getCurrentKeyboardDesc(),i()},this.refreshLang=function(){var a=c.getMachineLang(),b=c.getCodeKeyLabel();a===t&&b===u||(t=a,u=b,wmsx.VirtualKeyboard.updateKeysLabels(l,!1,t,u,!0))},this.getMappingForControl=function(a){return o.getKeyMapping(r)||[]},this.customizeControl=function(a,b,c){o.customizeKey(a,c),j.refresh(),h()},this.cancelKeyEditing=function(){s=!1,g()},this.clearControlEditing=function(){r&&(o.clearKey(r),j.refresh(),h())};var k,l,m,n,o=a.getKeyboard(),p=[],q=null,r=null,s=!1,t="en",u="CODE",v=wmsx.ControlMappingPopup.get(),w="Key mapped to host keys:",x="Press new key.<br>(click to lock, right-click to clear)";!function(){t=c.getMachineLang(),d()}()},wmsx.PortsConfigurator=function(a,b,c){"use strict";function d(){function a(a){"BUTTON"===a.target.tagName&&b.processControlActivated(a.currentTarget.wmsxControl,!1,a.target.wmsxDec)}l=document.getElementById("wmsx-ports-joysticks-mode"),l.wmsxControl=wmsx.PeripheralControls.JOYSTICKS_TOGGLE_MODE,l.wmsxText=l.querySelector(":scope > span"),l.querySelector(":scope > button").wmsxDec=!0,m=document.getElementById("wmsx-ports-joykeys-mode"),m.wmsxControl=wmsx.PeripheralControls.JOYKEYS_TOGGLE_MODE,m.wmsxText=m.querySelector(":scope > span"),m.querySelector(":scope > button").wmsxDec=!0,k=document.getElementById("wmsx-ports-mouse-mode"),k.wmsxControl=wmsx.PeripheralControls.MOUSE_TOGGLE_MODE,k.wmsxText=k.querySelector(":scope > span"),k.querySelector(":scope > button").wmsxDec=!0,n=document.getElementById("wmsx-ports-turbofire-speed"),n.wmsxControl=wmsx.PeripheralControls.TURBO_FIRE_TOGGLE,n.wmsxText=n.querySelector(":scope > span"),n.querySelector(":scope > button").wmsxDec=!0,wmsx.Util.onTapOrMouseDownWithBlock(l,a),wmsx.Util.onTapOrMouseDownWithBlock(m,a),wmsx.Util.onTapOrMouseDownWithBlock(k,a),wmsx.Util.onTapOrMouseDownWithBlock(n,a);for(var c=1;c<=2;++c){var d=c-1;o[d]=document.getElementById("wmsx-ports-device"+c),p[d]=document.getElementById("wmsx-ports-device"+c+"-title");for(var f in wmsx.JoystickButtons){var g=document.getElementById("wmsx-joy"+c+"-"+wmsx.JoystickButtons[f].n);g&&(g.wmsxButton=f,g.wmsxPort=d,e(g),q.push(g))}o[d].addEventListener("mousedown",h);var i=document.getElementById("wmsx-mouse"+c);i.wmsxButton="MOUSE",i.wmsxPort=d,e(i)}}function e(a){a.addEventListener("mouseenter",f),a.addEventListener("mouseleave",g)}function f(a){a.target.wmsxButton?(r=a.target,s=r.wmsxButton,t=r.wmsxPort,i()):g()}function g(){r=s=t=null,i()}function h(b){s&&3===b.which&&a.clearControl(s,t),j.refresh(),i()}function i(){if(!s)return u.hide(),a.mappingPopupVisibility(u,t,!1),void c.focus();var b=r.getBoundingClientRect(),d=b.left+b.width/2,e=b.top,f=a.getMappingPopupText(s,t);u.show(j,s,t,d,e,f.heading,f.footer),a.mappingPopupVisibility(u,t,!0)}var j=this;this.controllersSettingsStateUpdate=function(){this.refresh()},this.refresh=function(){var b=a.getSettingsState();l.wmsxText.textContent=b.joysticksModeDesc,m.wmsxText.textContent=b.joykeysModeDesc,k.wmsxText.textContent=b.mouseModeDesc,n.wmsxText.textContent=b.turboFireSpeedDesc;for(var c=0;c<2;++c){var d=b.ports[c],e=o[c].classList;e.remove.apply(e,v),d.startsWith(wmsx.ControllersHub.MOUSE)?e.add("wmsx-mouse-device"):d.startsWith(wmsx.ControllersHub.JOY_ANY)?e.add(d.startsWith(wmsx.ControllersHub.JOYSTICK)?"wmsx-joystick-device":"wmsx-joykeys-device"):d.startsWith(wmsx.ControllersHub.TOUCH)?e.add("wmsx-touch-device"):e.add("wmsx-none-device"),p[c].innerHTML=d}for(var f=0;f<q.length;++f){var g=q[f],h=this.getMappingForControl(g.wmsxButton,g.wmsxPort);!h||h.constructor===Array&&0===h.length||h.constructor===Object&&(0===h.from.length||0===h.to.length)?g.classList.add("wmsx-joy-hs-unmapped"):g.classList.remove("wmsx-joy-hs-unmapped")}},this.getMappingForControl=function(b,c){return a.getMappingForControl(b,c)},this.customizeControl=function(b,c,d){a.customizeControl(b,c,d),this.refresh()},this.clearControlEditing=function(){s&&(a.clearControl(s,t),j.refresh(),i())};var k,l,m,n,o=[],p=[],q=[],r=null,s=null,t=null,u=wmsx.ControlMappingPopup.get(),v=["wmsx-none-device","wmsx-mouse-device","wmsx-joystick-device","wmsx-joykeys-device","wmsx-touch-device"];!function(){d()}()},wmsx.SettingsDialog=function(a,b,c,d){"use strict";function e(){
wmsx.Util.insertCSS(document,wmsx.SettingsGUI.css()),a.insertAdjacentHTML("beforeend",wmsx.SettingsGUI.html()),m=document.getElementById("wmsx-modal"),delete wmsx.SettingsGUI.html,delete wmsx.SettingsGUI.css,delete wmsx.SettingsGUI,f(),g()}function f(){function a(b,c){c(b);for(var d=b.childNodes,e=0;e<d.length;e++)a(d[e],c)}a(m,function(a){a.id&&(l[a.id]=a)})}function g(){wmsx.Util.onTapOrMouseDownWithBlock(m,function(){m.focus()}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-back"],l.hide),m.addEventListener("keydown",function(a){k(a,!0)}),m.addEventListener("keyup",function(a){k(a,!1)}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-menu-general"],function(){l.setPage("GENERAL")}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-menu-inputs"],function(){l.setPage("INPUTS")}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-menu-ports"],function(){l.setPage("PORTS")}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-menu-media"],function(){l.setPage("MEDIA")}),wmsx.Util.onTapOrMouseDownWithBlock(l["wmsx-menu-about"],function(){l.setPage("ABOUT")})}function h(){l["wmsx-browserinfo"].innerHTML=navigator.userAgent}function i(){n||(n=new wmsx.KeyboardConfigurator(b,m,d)),n.refreshLang(),n.refresh()}function j(){o||(o=new wmsx.PortsConfigurator(b,c,m)),o.refresh()}function k(a,b){var c=r.codeNewForKeyboardEvent(a);if(b&&c===s)return l.hide(),wmsx.Util.blockEvent(a)}var l=this;this.show=function(a){if(!m)return e(),void setTimeout(function(){l.show(a)},0);this.position()&&(this.setPage(a||p),m.classList.add("wmsx-show"),m.classList.add("wmsx-show"),q=!0,setTimeout(function(){m.focus()},50))},this.hide=function(){q&&(n&&n.cancelKeyEditing(),l.hideLesser(),WMSX.room.screen.focus())},this.hideLesser=function(){WMSX.userPreferences.save(),m.classList.remove("wmsx-show"),m.classList.remove("wmsx-show"),q=!1},this.setPage=function(a){n&&n.cancelKeyEditing(),p=a;var b={GENERAL:"0",MEDIA:"-600px",INPUTS:"-1200px",PORTS:"-1800px",ABOUT:"-2400px"}[p],c={GENERAL:"0",MEDIA:"20%",INPUTS:"40%",PORTS:"60%",ABOUT:"80%"}[p];switch(b&&(l["wmsx-content"].style.left=b),c&&(l["wmsx-menu-selection"].style.left=c),l["wmsx-menu-general"].classList.toggle("wmsx-selected","GENERAL"===p),l["wmsx-menu-media"].classList.toggle("wmsx-selected","MEDIA"===p),l["wmsx-menu-inputs"].classList.toggle("wmsx-selected","INPUTS"===p),l["wmsx-menu-ports"].classList.toggle("wmsx-selected","PORTS"===p),l["wmsx-menu-about"].classList.toggle("wmsx-selected","ABOUT"===p),p){case"ABOUT":h();break;case"INPUTS":i();break;case"PORTS":j()}},this.isVisible=function(){return q},this.position=function(){var b=a.clientWidth,c=a.clientHeight;return b<537||c<434?(this.hide(),!1):(b<600&&(b-=2),WMSX.SCREEN_CONTROL_BAR&&c>=440+wmsx.ScreenGUI.BAR_HEIGHT&&(c-=wmsx.ScreenGUI.BAR_HEIGHT+3),m.style.top=((c-440)/2|0)+"px",m.style.left=((b-600)/2|0)+"px",!0)},this.keyboardSettingsStateUpdate=function(){q&&n&&n.keyboardSettingsStateUpdate()},this.controllersSettingsStateUpdate=function(){q&&o&&o.controllersSettingsStateUpdate()};var m,n,o,p="GENERAL",q=!1,r=wmsx.DOMKeys,s=r.VK_ESCAPE.wc},wmsx.PasteDialog=function(a,b,c){"use strict";var d=this;this.toggle=function(){e&&"visible"===e.style.visibility?this.hide():this.show()},this.show=function(){if(!e)return g(),void d.show();setTimeout(function(){e.classList.add("wmsx-show"),f.focus(),i=!0},0)},this.hide=function(){i&&(e.classList.remove("wmsx-show"),i=!1,b.focus())};var e,f,g=function(){e=document.createElement("div"),e.id="wmsx-paste-cover",a.appendChild(e),f=document.createElement("input"),f.id="wmsx-paste-box",f.value="📋   PASTE NOW",f.readOnly="readonly",f.innerHTML="PASTE NOW!",e.appendChild(f),h()},h=function(){wmsx.Util.onTapOrMouseDownWithBlock(e,function(){f.focus()}),e.addEventListener("keydown",function(a){a.stopPropagation();var b=j.codeNewForKeyboardEvent(a);if(b===l||b===m||b===n)return a.preventDefault(),void d.hide();k.indexOf(b)<0&&a.preventDefault()}),f.addEventListener("paste",function(a){if(i&&a.clipboardData&&a.clipboardData.getData){var b=a.clipboardData.getData("text/plain");b&&(d.hide(),c.processControlState(wmsx.MachineControls.TYPE_STRING,!0,!1,b))}})},i=!1,j=wmsx.DOMKeys,k=[j.VK_V.wc|j.CONTROL,j.VK_INSERT.wc|j.SHIFT,j.VK_NUM_0.wc|j.SHIFT],l=j.VK_ESCAPE.wc,m=j.VK_V.wc|j.ALT,n=j.VK_INSERT.wc|j.ALT},wmsx.TextEntryDialog=function(a,b,c){"use strict";function d(){g=document.createElement("div"),g.id="wmsx-text-entry-dialog",g.tabIndex=-1,g.wmsxIgnoreEnterFS=!0,i=document.createElement("textarea"),i.id="wmsx-text-entry-input",i.spellcheck=!1,i.autocorrect=!1,i.autocapitalize=!1,g.appendChild(i),h=document.createElement("div"),h.id="wmsx-text-entry-dialog-bar",g.appendChild(h),j=document.createElement("div"),j.id="wmsx-text-entry-dialog-ok",h.appendChild(j),k=document.createElement("div"),k.id="wmsx-text-entry-dialog-cancel",h.appendChild(k),a.appendChild(g),e()}function e(){wmsx.Util.onTapOrMouseDownWithBlock(g,function(a){a.target===j||a.target===k?(wmsx.ControllersHub.hapticFeedbackOnTouch(a),f.hide(a.target===j)):g.focus()}),g.addEventListener("keydown",function(a){a.stopPropagation();var b=m.codeNewForKeyboardEvent(a);b===p&&(a.preventDefault(),f.hide(!0)),b!==n&&b!==o||(a.preventDefault(),f.hide(!1))}),i.addEventListener("contextmenu",function(a){a.stopPropagation()}),wmsx.Util.addEventsListener(i,"touchstart touchmove touchend mousedown mousemove mouseup",function(a){a.stopPropagation()})}var f=this;this.toggle=function(){l?this.hide(!1):this.show()},this.show=function(){if(!g)return d(),setTimeout(f.show,0);g.classList.add("wmsx-show"),l=!0,i.focus()},this.hide=function(a){l&&(g.classList.remove("wmsx-show"),l=!1,WMSX.room.screen.focus(),a&&c.processControlState(wmsx.MachineControls.TYPE_STRING,!0,!1,i.value))};var g,h,i,j,k,l=!1,m=wmsx.DOMKeys,n=m.VK_ESCAPE.wc,o=m.VK_B.wc|m.ALT,p=m.VK_ENTER.wc|m.CONTROL},wmsx.SaveStateDialog=function(a,b,c,d){"use strict";function e(){k.classList.toggle("wmsx-load",!o),n.textContent="Select Slot to "+(o?"Save":"Load");for(var a=o?"Save to ":"Load from ",b=0;b<q.length;++b){var c=q[b];c.innerHTML=a+v[b].d,c.classList.toggle("wmsx-selected",b===p),c.classList.toggle("wmsx-toggle-checked",d.isSlotUsed(b+1))}f(),g()}function f(){for(var a=0;a<q.length;++a)q[a].classList.toggle("wmsx-selected",a===p)}function g(){m.textContent=s?"YES":"NO",m.classList.toggle("wmsx-selected",s)}function h(){k=document.createElement("div"),k.id="wmsx-savestate",k.classList.add("wmsx-select-dialog"),k.tabIndex=-1,n=document.createTextNode("Select Slot"),k.appendChild(n),l=document.createElement("ul"),l.style.width="80%";for(var b=0;b<v.length;++b){var c=document.createElement("li");c.classList.add("wmsx-visible"),b<v.length-1&&c.classList.add("wmsx-toggle"),c.style.textAlign="center",c.innerHTML=v[b].d,c.wmsxSlot=b,c.wmsxNeedsUIG=!0,q.push(c),l.appendChild(c)}k.appendChild(l);var d=document.createElement("div"),e=document.createElement("ul");e.classList.add("wmsx-quick-options-list"),c=document.createElement("li");var f=document.createElement("div");f.innerHTML="&#128190;&nbsp; Sync time to Host",c.appendChild(f),m=document.createElement("div"),m.innerHTML="NO",m.classList.add("wmsx-control"),c.appendChild(m),e.appendChild(c),d.appendChild(e),k.appendChild(d),i(),a.appendChild(k)}function i(){function a(){j.hide(!1)}function b(){j.hide(!0)}wmsx.Util.onTapOrMouseDownWithBlock(k,function(){k.focus()}),wmsx.Util.onTapOrMouseDownWithBlockUIG(k,function(a,c){a.target.wmsxSlot>=0&&(c&&wmsx.ControllersHub.hapticFeedbackOnTouch(a),p=a.target.wmsxSlot,f(),c||setTimeout(b,120))}),wmsx.Util.onTapOrMouseDownWithBlock(m,function(a){wmsx.ControllersHub.hapticFeedbackOnTouch(a),s=!s,g(),WMSX.userPreferences.current.syncTimeLoadState=s,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save()}),k.addEventListener("keydown",function(c){var d=w.codeNewForKeyboardEvent(c);return d===x?a():y.indexOf(d)>=0?b():z[d]&&(p+=z[d],p<0?p=0:p>10&&(p=10),f()),
wmsx.Util.blockEvent(c)})}var j=this;this.show=function(b){if(!k)return h(),setTimeout(function(){j.show(b)},0);o=b,r=!0,s=WMSX.userPreferences.current.syncTimeLoadState,e(),k.classList.add("wmsx-show"),k.focus(),wmsx.Util.scaleToFitParentHeight(k,a,wmsx.ScreenGUI.BAR_HEIGHT)},this.hide=function(a){if(r&&(k.classList.remove("wmsx-show"),r=!1,WMSX.room.screen.focus(),a)){var d=v[p],e=o?d.save:d.load;d.peripheral?c.processControlActivated(e):b.processControlState(e,!0)}};var k,l,m,n,o=!1,p=0,q=[],r=!1,s=!1,t=wmsx.MachineControls,u=wmsx.PeripheralControls,v=[{d:"Slot 1",load:t.LOAD_STATE_1,save:t.SAVE_STATE_1},{d:"Slot 2",load:t.LOAD_STATE_2,save:t.SAVE_STATE_2},{d:"Slot 3",load:t.LOAD_STATE_3,save:t.SAVE_STATE_3},{d:"Slot 4",load:t.LOAD_STATE_4,save:t.SAVE_STATE_4},{d:"Slot 5",load:t.LOAD_STATE_5,save:t.SAVE_STATE_5},{d:"Slot 6",load:t.LOAD_STATE_6,save:t.SAVE_STATE_6},{d:"Slot 7",load:t.LOAD_STATE_7,save:t.SAVE_STATE_7},{d:"Slot 8",load:t.LOAD_STATE_8,save:t.SAVE_STATE_8},{d:"Slot 9",load:t.LOAD_STATE_9,save:t.SAVE_STATE_9},{d:"Slot 10",load:t.LOAD_STATE_10,save:t.SAVE_STATE_10},{d:"File",load:u.MACHINE_LOAD_STATE_FILE,save:u.MACHINE_SAVE_STATE_FILE,peripheral:!0}],w=wmsx.DOMKeys,x=w.VK_ESCAPE.wc,y=[w.VK_ENTER.wc,w.VK_SPACE.wc],z={};z[w.VK_UP.wc]=-1,z[w.VK_DOWN.wc]=1},wmsx.CartridgeFormatDialog=function(a,b,c,d){"use strict";function e(){r=0,k.reinsertROMContent(),s=wmsx.SlotCreator.getUserFormatOptionNames(k.rom);var a=wmsx.SlotCreator.getBestFormatOption(k.rom);a||(a=wmsx.SlotFormats.Normal),s.unshift(a.name);for(var b=0;b<t.length;++b)b<s.length?(s[b]===q&&(r=b),t[b].innerHTML=0===b?"AUTO: "+a.name:s[b],t[b].classList.add("wmsx-visible")):t[b].classList.remove("wmsx-visible");k.format===a&&(r=0),f(),g()}function f(){for(var a,b=0;b<s.length;++b)b===r?(a=t[b],a.classList.add("wmsx-selected")):t[b].classList.remove("wmsx-selected");m.scrollTop>a.offsetTop?m.scrollTop=a.offsetTop:m.scrollTop+m.offsetHeight<a.offsetTop+26+2&&(m.scrollTop=a.offsetTop-(m.offsetHeight-26-2))}function g(){n.textContent=w?v?"YES":"NO":"- -",n.classList.toggle("wmsx-selected",v)}function h(){l=document.createElement("div"),l.id="wmsx-cartridge-format",l.classList.add("wmsx-select-dialog"),l.style.width="280px",l.style.height="374px",l.tabIndex=-1;var a=document.createTextNode("Select ROM Format");l.appendChild(a),m=document.createElement("ul");for(var c=0,d=wmsx.SlotFormatsUserOptions.length+1;c<d;++c){var e=document.createElement("li");e.wmsxIndex=c,e.classList.add("wmsx-visible"),e.style.textAlign="center",t.push(e),m.appendChild(e)}l.appendChild(m);var f=document.createElement("div"),g=document.createElement("ul");g.classList.add("wmsx-quick-options-list"),e=document.createElement("li");var h=document.createElement("div");h.innerHTML="&#128190;&nbsp; Remember Choice",e.appendChild(h),n=document.createElement("div"),n.innerHTML="NO",n.classList.add("wmsx-control"),e.appendChild(n),g.appendChild(e),f.appendChild(g),l.appendChild(f),i(),b.appendChild(l)}function i(){function a(){j.hide(!1)}function b(){j.hide(!0)}function c(a){r=a,f()}wmsx.Util.onTapOrMouseDownWithBlock(l,function(){m.focus()}),wmsx.Util.addEventsListener(m,"touchstart touchmove touchend",function(a){a.stopPropagation()}),wmsx.Util.addEventsListener(m,"mousedown",function(a){a.stopPropagation(),wmsx.ControllersHub.hapticFeedbackOnTouch(a),a.target.wmsxIndex>=0&&c(a.target.wmsxIndex)}),wmsx.Util.addEventsListener(m,"click",function(a){if(wmsx.Util.blockEvent(a),a.target.wmsxIndex>=0){var d=a.target.wmsxIndex===r;c(a.target.wmsxIndex),setTimeout(b,d?0:120)}}),wmsx.Util.onTapOrMouseDownWithBlock(n,function(a){w&&(wmsx.ControllersHub.hapticFeedbackOnTouch(a),v=!v,g())}),l.addEventListener("keydown",function(c){var d=y.codeNewForKeyboardEvent(c);return d===z?a():A.indexOf(d)>=0?b():B[d]&&(r+=B[d],r<0?r=0:r>=s.length&&(r=s.length-1),f()),wmsx.Util.blockEvent(c)})}var j=this;this.show=function(a,c){if(!l)return h(),setTimeout(function(){j.show(a,c)},0);o=a,p=c,(k=d.cartridgeInserted(o))&&(q=k.format.name,v=!!x.getForROM(k.rom),w=!!k.rom.info.h,u=!0,l.classList.add("wmsx-show"),e(),l.focus(),wmsx.Util.scaleToFitParentHeight(l,b,wmsx.ScreenGUI.BAR_HEIGHT))},this.hide=function(b){if(u){if(l.classList.remove("wmsx-show"),u=!1,WMSX.room.screen.focus(),b){var e=s[r],f=e===s[0],g=wmsx.SlotCreator.changeCartridgeFormat(k,wmsx.SlotFormats[e]);v&&x.setForROM(k.rom,e,f),d.insertCartridge(g,o,p||!c.powerIsOn,!0),a.showOSD("ROM Format: "+e+(f?" (Auto)":""),!0)}k=void 0}};var k,l,m,n,o=0,p=!1,q="",r=0,s=[],t=[],u=!1,v=!1,w=!1,x=WMSX.userROMFormats,y=wmsx.DOMKeys,z=y.VK_ESCAPE.wc,A=[y.VK_ENTER.wc,y.VK_SPACE.wc],B={};B[y.VK_UP.wc]=-1,B[y.VK_DOWN.wc]=1},wmsx.DiskSelectDialog=function(a,b,c,d){"use strict";function e(){m.textContent="Select Disk in Drive "+(1===v?"B:":"A:")+" "+b.getCurrentDiskNumDesc(v);var a=61+33*Math.max(p.length,4);l.style.height=a+"px";for(var c=0;c<t.length;++c){var d=t[c];c<p.length?(d.classList.add("wmsx-visible"),d.innerHTML=c+1+":&nbsp;&nbsp;"+p[c].name,d.classList.toggle("wmsx-selected",c===q),d.classList.toggle("wmsx-toggle-checked",!!p[c].modified)):d.classList.remove("wmsx-visible"),d.classList.remove("wmsx-droptarget")}r=s=void 0}function f(){p=b.getDriveStack(v),q=b.getCurrentDiskNum(v)}function g(a){var b=q+a;b<0||b>=p.length||(q=b)}function h(){l=document.createElement("div"),l.id="wmsx-diskselect",l.classList.add("wmsx-select-dialog"),l.style.height="270px",l.tabIndex=-1,m=document.createTextNode("Select Disk"),l.appendChild(m),n=document.createElement("div"),n.id="wmsx-diskselect-footer",n.classList.add("wmsx-footer"),n.innerHTML="(drag items to change order)",l.appendChild(n),o=document.createElement("ul");for(var b=wmsx.FileDiskDrive.MAX_STACK+1,c=0;c<b;++c){var d=document.createElement("li");d.draggable=!0,d.wmsxDiskNum=c,d.classList.add("wmsx-toggle"),t.push(d),o.appendChild(d)}l.appendChild(o),i(),j(),a.appendChild(l)}function i(){function a(){k.hide(!1)}function b(){k.hide(!0)}wmsx.Util.onTapOrMouseDown(l,function(a){l.focus(),a.stopPropagation()}),l.addEventListener("keydown",function(d){var f=x.codeNewForKeyboardEvent(d);if(f===y)a();else if(z.indexOf(f)>=0)b();else{var h=f&C;h===A?c.processKey(f,!0):B[h]&&(g(B[h]),e())}return wmsx.Util.blockEvent(d)}),wmsx.Util.onTapOrMouseUpWithBlock(o,function(a){var c=a.target.wmsxDiskNum;return void 0!==c&&(wmsx.ControllersHub.hapticFeedbackOnTouch(a),q=c,e(),setTimeout(b,120)),!1}),o.addEventListener("mousemove",function(a){a.stopPropagation()})}function j(){o.addEventListener("dragstart",function(a){return a.stopPropagation(),void 0!==a.target.wmsxDiskNum&&(r=a.target,a.dataTransfer.setData("text/html",a.target.innerHTML),d.setDragAndDropDisabled(!0),!1)}),o.addEventListener("dragend",function(a){return a.stopPropagation(),s&&s.classList.remove("wmsx-droptarget"),r=s=void 0,d.setDragAndDropDisabled(!1),!1}),l.addEventListener("drop",function(a){if(a.preventDefault(),!r)return!1;if(a.stopPropagation(),!s)return!1;var b=r.wmsxDiskNum,d=s.wmsxDiskNum;return void 0!==b&&void 0!==d&&d!==b&&(c.processControlActivated(wmsx.PeripheralControls.DISK_MOVE,w,!1,{d:v,f:b,t:d}),!1)}),o.addEventListener("dragenter",function(a){return!(!r||void 0===a.target.wmsxDiskNum)&&(s&&s!==a.target&&s.classList.remove("wmsx-droptarget"),s=a.target!==r?a.target:void 0,s&&s.classList.add("wmsx-droptarget"),!1)})}var k=this;this.show=function(b,c,d){if(!l)return h(),setTimeout(function(){k.show(b,c,d)},0);v=b,w=d,u=!0,f(),g(c),e(),l.classList.add("wmsx-show"),l.focus(),wmsx.Util.scaleToFitParentHeight(l,a,wmsx.ScreenGUI.BAR_HEIGHT)},this.hide=function(a){d.setDragAndDropDisabled(!1),u&&(l.classList.remove("wmsx-show"),u=!1,WMSX.room.screen.focus(),a&&q>=0&&c.processControlActivated(wmsx.PeripheralControls.DISK_INSERT,w,!1,{d:v,n:q,a:w}))},this.diskDrivesMediaStateUpdate=function(a){u&&a===v&&(f(),e())}
;var l,m,n,o,p,q,r,s,t=[],u=!1,v=0,w=!0,x=wmsx.DOMKeys,y=x.VK_ESCAPE.wc,z=[x.VK_ENTER.wc,x.VK_SPACE.wc],A=x.VK_F6.wc,B={};B[x.VK_UP.wc]=-1,B[x.VK_PAGE_UP.wc]=-1,B[x.VK_DOWN.wc]=1,B[x.VK_PAGE_DOWN.wc]=1;var C=x.IGNORE_ALL_MODIFIERS_MASK},wmsx.NewHardDiskDialog=function(a,b){"use strict";function c(){for(var a=0;a<k.length;++a)k[a].classList.toggle("wmsx-selected",a===j)}function d(){g=document.createElement("div"),g.id="wmsx-new-hard-disk",g.classList.add("wmsx-select-dialog"),g.style.width="280px",g.style.height="175px",g.tabIndex=-1,i=document.createTextNode("Select Disk Size"),g.appendChild(i),h=document.createElement("ul"),h.style.width="80%";for(var b=0;b<o.length;++b){var c=document.createElement("li");c.classList.add("wmsx-visible"),c.style.textAlign="center";var d=p[o[b]];c.innerHTML=d.desc+" Disk &nbsp;&nbsp;&nbsp;"+d.secDesc,c.wmsxOption=b,k.push(c),h.appendChild(c)}g.appendChild(h),e(),a.appendChild(g)}function e(){function a(){f.hide(!1)}function b(){f.hide(!0)}wmsx.Util.onTapOrMouseDownWithBlock(g,function(){g.focus()}),wmsx.Util.onTapOrMouseDownWithBlock(g,function(a){a.target.wmsxOption>=0&&(wmsx.ControllersHub.hapticFeedbackOnTouch(a),j=a.target.wmsxOption,c(),setTimeout(b,120))}),g.addEventListener("keydown",function(d){var e=q.codeNewForKeyboardEvent(d);return e===r?a():s.indexOf(e)>=0?b():t[e]&&(j+=t[e],j<0?j=0:j>=k.length&&(j=k.length-1),c()),wmsx.Util.blockEvent(d)})}var f=this;this.show=function(b,e){if(!g)return d(),setTimeout(function(){f.show(m,e)},0);l=!0,m=b,n=e,c(),g.classList.add("wmsx-show"),g.focus(),wmsx.Util.scaleToFitParentHeight(g,a,wmsx.ScreenGUI.BAR_HEIGHT)},this.hide=function(a){if(l&&(g.classList.remove("wmsx-show"),l=!1,WMSX.room.screen.focus(),a)){var c=o[j];b.processControlActivated(wmsx.PeripheralControls.HARDDISK_NEW,m,!1,{m:c,b:n})}};var g,h,i,j=0,k=[],l=!1,m=!1,n=!1,o=wmsx.DiskImages.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES,p=wmsx.DiskImages.MEDIA_TYPE_INFO,q=(wmsx.MachineControls,wmsx.PeripheralControls,wmsx.DOMKeys),r=q.VK_ESCAPE.wc,s=[q.VK_ENTER.wc,q.VK_SPACE.wc],t={};t[q.VK_UP.wc]=-1,t[q.VK_DOWN.wc]=1},wmsx.MachineSelectDialog=function(a,b,c){"use strict";function d(){for(var a=0;a<l.length;++a){var b=l[a];b.classList.toggle("wmsx-selected",b.wmsxMachine===i)}}function e(){j=document.createElement("div"),j.id="wmsx-machineselect",j.classList.add("wmsx-select-dialog"),j.style.width="292px",j.tabIndex=-1;var b=document.createTextNode("Select Machine");j.appendChild(b),k=document.createElement("ul"),k.style.width="80%",j.appendChild(k),f(),g(),a.appendChild(j)}function f(){k.innerHTML="";for(var a=Object.keys(WMSX.MACHINES_CONFIG),b=40,c=0;c<a.length;++c){var d=WMSX.MACHINES_CONFIG[a[c]];if(d.DESC){var e=document.createElement("li");e.classList.add("wmsx-visible"),e.style.textAlign="center",e.textContent=d.DESC,e.wmsxMachine=a[c],l.push(e),k.appendChild(e),b+=33}}j.style.height=b+"px"}function g(){function a(){h.hide(!1)}function b(){h.hide(!0)}wmsx.Util.onTapOrMouseDownWithBlock(j,function(a){return a.target.wmsxMachine?(wmsx.ControllersHub.hapticFeedbackOnTouch(a),i=a.target.wmsxMachine,d(),setTimeout(b,120)):j.focus(),!1}),j.addEventListener("keydown",function(c){var e=n.codeNewForKeyboardEvent(c);if(e===o)a();else if(p.indexOf(e)>=0)b();else if(q[e]){var f=Object.keys(WMSX.MACHINES_CONFIG),g=f.indexOf(i)+q[e],h=f[g];h&&WMSX.MACHINES_CONFIG[h].DESC&&(i=h,d())}return wmsx.Util.blockEvent(c)})}var h=this;this.show=function(){if(!j)return e(),setTimeout(h.show,0);l.length||f(),m=!0,i=b.getMachine(),j.classList.add("wmsx-show"),j.focus(),d();var c=a.clientHeight-wmsx.ScreenGUI.BAR_HEIGHT-20,g=j.clientHeight,k=g<c?1:c/g;j.style.transform="translateY(-"+(wmsx.ScreenGUI.BAR_HEIGHT/2|0)+"px) scale("+k.toFixed(4)+")"},this.hide=function(a){m&&(j.classList.remove("wmsx-show"),m=!1,WMSX.room.screen.focus(),a&&c.processControlActivated(wmsx.PeripheralControls.MACHINE_SELECT,!1,!1,i))},this.machineTypeStateUpdate=function(){m&&(i=b.getMachine(),d())},this.configurationStateUpdate=function(){l.length=0};var i,j,k,l=[],m=!1,n=wmsx.DOMKeys,o=n.VK_ESCAPE.wc,p=[n.VK_ENTER.wc,n.VK_SPACE.wc],q={};q[n.VK_UP.wc]=-1,q[n.VK_DOWN.wc]=1},wmsx.TouchConfigDialog=function(a,b,c,d){"use strict";function e(){"T_DIR"===s?(n.classList.add("wmsx-show"),o.classList.remove("wmsx-show"),wmsx.DOMTouchControls.styleDirectionalMapping(n,B.directional)):(o.classList.add("wmsx-show"),n.classList.remove("wmsx-show"),wmsx.DOMTouchControls.styleButtonMapping(o,B.buttons[s])),p.classList.toggle("wmsx-disabled",u<=0),q.classList.toggle("wmsx-disabled",!t||u>=t.length-1)}function f(){var a=c.getSettingsState(),b=a.touchPortSet,e=a.touchActive;A[0].wmsxText.innerText=0===b?"Port 1":1===b?"Port 2":"OFF",A[0].classList.toggle("wmsx-selected",b>=0),A[0].classList.toggle("wmsx-inactive",!e);for(var f=1;f<r.length;++f){var g=r[f],h=d.getControlReport(g.control);g.value=h.label,g.selected=h.active,A[f].wmsxText.innerText=g.value,A[f].classList.toggle("wmsx-selected",!!g.selected)}}function g(){m=document.createElement("div"),m.id="wmsx-touch-config",m.tabIndex=-1,p=document.createElement("div"),p.id="wmsx-touch-config-minus",m.appendChild(p),q=document.createElement("div"),q.id="wmsx-touch-config-plus",m.appendChild(q),n=wmsx.DOMTouchControls.createDirectional("wmsx-touch-config-dir"),m.appendChild(n),o=wmsx.DOMTouchControls.createButton("wmsx-touch-config-button"),m.appendChild(o),r=[{label:"Touch Controller",control:wmsx.PeripheralControls.TOUCH_TOGGLE_MODE},{label:"Turbo Fire",control:wmsx.PeripheralControls.TURBO_FIRE_TOGGLE},{label:"&#128190;&nbsp; Big Directional",control:wmsx.PeripheralControls.TOUCH_TOGGLE_DIR_BIG},{label:"&#128190;&nbsp; Right Directional",control:wmsx.PeripheralControls.TOUCH_TOGGLE_MIRRORED},{label:"&#128190;&nbsp; Haptic Feedback",control:wmsx.PeripheralControls.HAPTIC_FEEDBACK_TOGGLE_MODE}];var a=document.createElement("ul");a.classList.add("wmsx-quick-options-list");for(var c=0;c<r.length;++c){var d=document.createElement("li"),e=document.createElement("div");e.innerHTML=r[c].label,d.appendChild(e);var f=document.createElement("div");f.classList.add("wmsx-control");var g=document.createElement("button");g.wmsxControlItem=r[c],g.wmsxDec=!0,g.classList.add("wmsx-control-dec"),f.appendChild(g);var h=document.createElement("span");f.wmsxText=h,f.appendChild(h),g=document.createElement("button"),g.wmsxControlItem=r[c],g.classList.add("wmsx-control-inc"),f.appendChild(g),d.appendChild(f),a.appendChild(d),A.push(f)}m.appendChild(a),i(),b.appendChild(m),x=["JOYSTICK","KEYBOARD"],y=[null],y.push(wmsx.JoystickButtons.J_A.button),y.push(wmsx.JoystickButtons.J_B.button),y.push(wmsx.JoystickButtons.J_AB.button);for(var j in wmsx.KeyboardKeys)y.push(j)}function h(a,b){if(s){if((u+=a)<0)return u=0;if(u>=t.length)return u=t.length-1;c.hapticFeedbackOnTouch(b);var d=t[u];"T_DIR"!==s&&(d=d&&(wmsx.JoystickButtons[d]||wmsx.KeyboardKeys[d])),C.customizeControl(s,d),e()}}function i(){wmsx.Util.onTapOrMouseDownWithBlock(m,function(a){a.target.wmsxControlItem?(d.processControlActivated(a.target.wmsxControlItem.control,!0,a.target.wmsxDec),c.hapticFeedbackOnTouch(a),f()):m.focus()}),m.addEventListener("keydown",function(a){var b=D.codeNewForKeyboardEvent(a);return E.indexOf(b)>=0?l.hide():F[b]&&h(F[b],a),wmsx.Util.blockEvent(a)}),wmsx.Util.addEventsListener(p,"touchstart mousedown",function(a){j(a,-1)}),wmsx.Util.addEventsListener(q,"touchstart mousedown",function(a){j(a,1)}),wmsx.Util.addEventsListener(p,"touchend mouseup",k),wmsx.Util.addEventsListener(q,"touchend mouseup",k)}function j(a,b){k(a),h(b,a),v=setTimeout(function(){w=setInterval(function(){h(b,a)},35)},415)}function k(a){wmsx.Util.blockEvent(a),v&&(clearTimeout(v),v=null),w&&(clearInterval(w),w=null)}var l=this;this.show=function(){if(!m)return g(),setTimeout(l.show,0);z=!0,a.classList.add("wmsx-touch-config-active"),m.focus(),s=t=null,u=-1,C.startTouchDetection(l),e(),f(),
wmsx.Util.scaleToFitParentHeight(m,b,0)},this.hide=function(){z&&(C.stopTouchDetection(l),WMSX.userPreferences.save(),a.classList.remove("wmsx-touch-config-active"),z=!1,WMSX.room.screen.focus())},this.touchControlDetected=function(a,b){c.hapticFeedbackOnTouch(b),s=a;var d="T_DIR"===s;t=d?x:y;var f=d?B.directional:B.buttons[s],g=d?f:f&&(f.button||f.key);u=wmsx.Util.arrayFindIndex(t,function(a){return a===g}),e()},this.controllersSettingsStateUpdate=function(){z&&f()};var m,n,o,p,q,r,s,t,u,v,w,x,y,z=!1,A=[],B=WMSX.userPreferences.current.touch,C=c.getTouchControls(),D=wmsx.DOMKeys,E=[D.VK_ESCAPE.wc,D.VK_ENTER.wc,D.VK_SPACE.wc],F={};F[D.VK_LEFT.wc]=-1,F[D.VK_RIGHT.wc]=1},wmsx.QuickOptionsDialog=function(a,b,c,d){"use strict";function e(){for(var a=b.getMachineType(),e=0;e<j.length;++e){var f=j[e],g=f.peripheral?d.getControlReport(f.control):c.getControlReport(f.control);f.value=g.label,f.selected=g.active,l[e].wmsxText.innerText=f.value,l[e].classList.toggle("wmsx-selected",!!f.selected),f.machineType&&f.element.classList.toggle("wmsx-hidden",f.machineType>a)}i.style.height=(a>=wmsx.Machine.MACHINE_TYPE.MSXTR?386:352)+"px"}function f(){i=document.createElement("div"),i.id="wmsx-quick-options",i.tabIndex=-1;var b=wmsx.MachineControls,c=wmsx.PeripheralControls;j=[{label:"NTSC / PAL",control:b.VIDEO_STANDARD},{label:"R800 CPU Clock",control:b.R800_CLOCK_MODE,machineType:wmsx.Machine.MACHINE_TYPE.MSXTR},{label:"Z80 CPU Clock",control:b.Z80_CLOCK_MODE},{label:"VDP Clock",control:b.VDP_CLOCK_MODE},{label:"Sprites Mode",control:b.SPRITE_MODE},{label:"Turbo Fire",control:c.TURBO_FIRE_TOGGLE,peripheral:!0},{label:"&#128190;&nbsp; VSync",control:b.VSYNCH},{label:"&#128190;&nbsp; CRT Filter",control:c.SCREEN_CRT_FILTER,peripheral:!0},{label:"&#128190;&nbsp; CRT Scanlines",control:c.SCREEN_CRT_SCANLINES,peripheral:!0},{label:"&#128190;&nbsp; Audio Buffer",control:c.SPEAKER_BUFFER_TOGGLE,peripheral:!0}];var d=document.createElement("ul");d.classList.add("wmsx-quick-options-list");for(var e=0;e<j.length;++e){var f=document.createElement("li");j[e].element=f;var h=document.createElement("div");h.innerHTML=j[e].label,f.appendChild(h);var k=document.createElement("div");k.classList.add("wmsx-control");var m=document.createElement("button");m.wmsxControlItem=j[e],m.wmsxDec=!0,m.classList.add("wmsx-control-dec"),k.appendChild(m);var n=document.createElement("span");k.wmsxText=n,k.appendChild(n),m=document.createElement("button"),m.wmsxControlItem=j[e],m.classList.add("wmsx-control-inc"),k.appendChild(m),f.appendChild(k),d.appendChild(f),l.push(k)}i.appendChild(d),g(),a.appendChild(i)}function g(){wmsx.Util.onTapOrMouseDownWithBlock(i,function(a){if(a.target.wmsxControlItem){wmsx.ControllersHub.hapticFeedbackOnTouch(a);var b=a.target.wmsxControlItem;b.peripheral?(d.processControlActivated(b.control,!1,a.target.wmsxDec),e()):c.processControlState(b.control,!0,a.target.wmsxDec)}else i.focus()}),i.addEventListener("keydown",function(a){var b=m.codeNewForKeyboardEvent(a);return n.indexOf(b)>=0&&h.hide(),wmsx.Util.blockEvent(a)})}var h=this;this.show=function(){if(!i)return f(),setTimeout(h.show,0);e(),k=!0,i.classList.add("wmsx-show"),i.focus(),wmsx.Util.scaleToFitParentHeight(i,a,wmsx.ScreenGUI.BAR_HEIGHT)},this.hide=function(){k&&(WMSX.userPreferences.save(),i.classList.remove("wmsx-show"),k=!1,WMSX.room.screen.focus())},this.quickOptionsControlsStateUpdate=function(){k&&e()},this.machineTurboModesStateUpdate=function(){k&&e()},this.machineTypeStateUpdate=function(){k&&e()};var i,j,k=!1,l=[],m=wmsx.DOMKeys,n=[m.VK_ESCAPE.wc]},wmsx.NetPlayDialog=function(a,b){"use strict";function c(){switch(a.netPlayMode){case 0:o.textContent="STANDALONE",m.textContent="START",n.textContent="JOIN",m.disabled=!1,n.disabled=!1,r.disabled=!1,s.disabled=!1,k.classList.remove("wmsx-active"),l.classList.remove("wmsx-disabled"),r.setAttribute("placeholder","Enter a name");break;case 1:var b=a.getNetServer();o.textContent="HOSTING Session: "+b.getSessionID(),m.textContent="STOP",n.textContent="JOIN",m.disabled=!1,n.disabled=!0,r.disabled=!0,s.disabled=!0,k.classList.add("wmsx-active"),l.classList.add("wmsx-disabled"),r.setAttribute("placeholder","Automatic"),p.href=e();break;case 2:var c=a.getNetClient();o.textContent="JOINED Session: "+c.getSessionID(),m.textContent="START",n.textContent="LEAVE",m.disabled=!0,n.disabled=!1,r.disabled=!0,s.disabled=!0,k.classList.add("wmsx-active"),l.classList.remove("wmsx-disabled"),l.classList.add("wmsx-disabled"),r.setAttribute("placeholder","Enter a name"),p.href=e();break;case-1:case-2:o.textContent="Establishing connection...",r.disabled=!0,s.disabled=!0,k.classList.remove("wmsx-active"),l.classList.add("wmsx-disabled"),-1===a.netPlayMode?(m.textContent="CANCEL",n.textContent="JOIN",m.disabled=!1,n.disabled=!0,r.setAttribute("placeholder","Automatic")):(m.textContent="START",n.textContent="CANCEL",m.disabled=!0,n.disabled=!1,r.setAttribute("placeholder","Enter a name"))}}function d(){r.value=u.netPlaySessionName,s.value=u.netPlayNick}function e(){return wmsx.Util.browserCurrentURL()+"?JOIN="+a.netController.getSessionID()}function f(b){var c=b.target;if(!c.disabled){wmsx.ControllersHub.hapticFeedbackOnTouch(b);var d=!1,e=a.netPlayMode;if(c!==m||0!==e&&1!==e&&-1!==e?c!==n||0!==e&&2!==e&&-2!==e||(0===e?(a.getNetClient().joinSession(r.value,s.value),d=!0):a.getNetClient().leaveSession(!1,-2===e?"NetPlay connection aborted":void 0)):0===e?(a.getNetServer().startSession(r.value),d=!0):a.getNetServer().stopSession(!1,-1===e?"NetPlay connection aborted":void 0),d){var f=r.value.trim(),g=s.value.trim();u.netPlaySessionName===f&&u.netPlayNick===g||(u.netPlaySessionName=f,u.netPlayNick=g,WMSX.userPreferences.setDirty(),WMSX.userPreferences.save())}}}function g(){j=document.createElement("div"),j.id="wmsx-netplay",j.tabIndex=-1,j.wmsxIgnoreEnterFS=!0,k=document.createElement("div"),k.id="wmsx-netplay-status-box",j.appendChild(k),q=document.createElement("input"),q.id="wmsx-netplay-link-text",k.appendChild(q),o=document.createElement("div"),o.id="wmsx-netplay-status",o.textContent="STANDALONE",k.appendChild(o),p=document.createElement("a"),p.id="wmsx-netplay-link",p.textContent="🔗",p.setAttribute("title","Copy Join Session link to clipboard"),k.appendChild(p),l=document.createElement("div"),l.id="wmsx-netplay-session-box",j.appendChild(l);var a=document.createElement("div");a.id="wmsx-netplay-session-label",l.appendChild(a),m=document.createElement("button"),m.id="wmsx-netplay-start",m.wmsxCommand=!0,m.classList.add("wmsx-netplay-button"),m.textContent="START",l.appendChild(m),r=document.createElement("input"),r.id="wmsx-netplay-session-name",r.setAttribute("placeholder","Enter a name"),r.setAttribute("maxlength",12),r.spellcheck=!1,r.autocorrect=!1,r.autocapitalize=!1,l.appendChild(r),n=document.createElement("button"),n.id="wmsx-netplay-join",n.wmsxCommand=!0,n.classList.add("wmsx-netplay-button"),n.textContent="JOIN",l.appendChild(n);var c=document.createElement("div");c.id="wmsx-netplay-nick-label",l.appendChild(c),s=document.createElement("input"),s.id="wmsx-netplay-nick",s.setAttribute("placeholder","Automatic"),s.setAttribute("maxlength",12),s.spellcheck=!1,s.autocorrect=!1,s.autocapitalize=!1,l.appendChild(s),h(),b.appendChild(j)}function h(){function b(a){var b=a.target,c=b.value;return!c||c.match(/^[A-Za-z0-9]+[A-Za-z0-9_\-]*@?$/)?b.wmsxLastValidValue=c:b.value=b.wmsxLastValidValue||""}wmsx.Util.onTapOrMouseDownWithBlock(j,function(a){a.target.wmsxCommand?f(a):j.focus()}),j.addEventListener("keydown",function(a){var b=v.codeNewForKeyboardEvent(a);return w.indexOf(b)>=0&&i.hide(),wmsx.Util.blockEvent(a)}),r.addEventListener("input",b),s.addEventListener("input",b),wmsx.Util.addEventsListener(o,"touchstart touchmove touchend mousedown mousemove mouseup keydown keyup",function(a){a.stopPropagation()}),
wmsx.Util.addEventsListener(r,"touchstart touchmove touchend mousedown mousemove mouseup keydown keyup",function(a){a.stopPropagation()}),wmsx.Util.addEventsListener(s,"touchstart touchmove touchend mousedown mousemove mouseup keydown keyup",function(a){a.stopPropagation()}),j.ondragstart=wmsx.Util.blockEvent,k.addEventListener("contextmenu",function(a){a.stopPropagation()}),wmsx.Util.addEventsListener(p,"click",function(b){if(wmsx.Util.blockEvent(b),!document.queryCommandSupported||!document.queryCommandSupported("copy"))return a.showOSD("Copy to Clipboard not supported by the browser!",!0,!0);q.value=e(),q.focus(),q.select(),document.execCommand("copy"),j.focus()})}var i=this;this.show=function(){if(!j)return g(),setTimeout(i.show,0);c(),d(),t=!0,j.classList.add("wmsx-show"),r.focus(),wmsx.Util.scaleToFitParentWidth(j,b,12)},this.hide=function(){t&&(j.classList.remove("wmsx-show"),t=!1,a.screen.focus())},this.roomNetPlayStatusChangeUpdate=function(b){if(t&&c(),2===a.netPlayMode&&b<0&&t)return setTimeout(function(){i.hide()},2e3);0===a.netPlayMode&&b>0&&!t&&i.show()},this.isVisible=function(){return t};var j,k,l,m,n,o,p,q,r,s,t=!1,u=WMSX.userPreferences.current,v=wmsx.DOMKeys,w=[v.VK_ESCAPE.wc]},wmsx.WebAudioSpeaker=function(a){"use strict";function b(){return wmsx.Util.isMobileDevice()?"CHROME"===wmsx.Util.browserInfo().name&&wmsx.Util.isAndroidDevice()?4:3:2}function c(){return"SAFARI"===wmsx.Util.browserInfo().name||wmsx.Util.isIOSDevice()?b():0}function d(){!o||m.state&&"suspended"!==m.state||(a.addEventListener("touchend",e,!0),a.addEventListener("mousedown",e,!0),a.addEventListener("keydown",e,!0),m.addEventListener("statechange",f),i.speakerUnlockStateUpdate(!1),wmsx.Util.log("Speaker Audio Context resume event registered"))}function e(){try{m.resume()}catch(a){return}var a=m.createBufferSource();a.buffer=m.createBuffer(1,1,22050),a.connect(m.destination),a.start(0),"running"===m.state&&f()}function f(){"running"===m.state&&(a.removeEventListener("touchend",e,!0),a.removeEventListener("mousedown",e,!0),a.removeEventListener("keydown",e,!0),m.removeEventListener("statechange",f),i.speakerUnlockStateUpdate(!0),wmsx.Util.log("Speaker Audio Context restablished!"))}function g(){if(o){p.length=q.length=r.length=s.length=t.length=l.length;for(var a=0;a<l.length;a++)p[a]=l[a].getSampleRate()/m.sampleRate,q[a]=0,r[a]=s[a]=t[a]=0,l[a].setAudioMonitorBufferSize(p[a]*n|0)}}function h(a){for(var b=a.outputBuffer.getChannelData(0),c=a.outputBuffer.getChannelData(1),d=b.length,e=d-1;e>=0;e-=1)b[e]=c[e]=0;if(0!==l.length)for(var f=l.length-1;f>=0;f-=1){var g=p[f],h=d*g+q[f]|0,i=l[f].retrieveSamples(h,v),j=i.buffer0,k=i.buffer1,m=i.bufferSize,n=i.start,o=n+q[f];if(g<1){for(var u=r[f],w=s[f],x=t[f],y=0;y<d;++y,o+=g)o>=m&&(o-=m),b[y]+=u*(1-x),c[y]+=w*(1-x),u=j[0|o],w=k[0|o],b[y]+=u*x,c[y]+=w*x,x=o-(0|o);r[f]=u,s[f]=w,t[f]=x}else for(y=0;y<d;++y,o+=g)o>=m&&(o-=m),b[y]+=j[0|o],c[y]+=k[0|o];o<n&&(o+=m),q[f]=o-(n+h)}}this.connect=function(a){a.connectMonitor(this)},this.connectPeripherals=function(a){i=a},this.connectAudioSignal=function(a){l.indexOf(a)>=0||(wmsx.Util.arrayAdd(l,a),g())},this.disconnectAudioSignal=function(a){l.indexOf(a)<0||(wmsx.Util.arrayRemoveAllElement(l,a),g())},this.powerOn=function(){j(),o&&(d(),this.unpauseAudio())},this.powerOff=function(){this.pauseAudio(),m&&m.close(),m=o=void 0},this.mute=function(){v=!0},this.unMute=function(){v=!1},this.pauseAudio=function(){o&&o.disconnect()},this.unpauseAudio=function(){o&&o.connect(m.destination)},this.toggleBufferBaseSize=function(a){if(!m)return i.showOSD("Audio is DISABLED",!0,!0);a?--u<-1&&(u=6):++u>6&&(u=-1),this.pauseAudio(),k(),this.unpauseAudio(),i.showOSD("Audio Buffer size: "+(-1===u?"Auto ("+n+")":0===u?"Browser ("+n+")":n),!0),WMSX.userPreferences.current.audioBufferBase=u,WMSX.userPreferences.setDirty()},this.getControlReport=function(a){return{label:-2===u?"OFF":-1===u?"Auto":0===u?"Browser":n,active:u>0}};var i,j=function(){if(-2===u||0===WMSX.AUDIO_MONITOR_BUFFER_SIZE)return void wmsx.Util.warning("Audio disabled in configuration");try{var a=window.AudioContext||window.webkitAudioContext||window.WebkitAudioContext;if(!a)throw new Error("WebAudio API not supported by the browser");m=new a,wmsx.Util.log("Speaker AudioContext created. Sample rate: "+m.sampleRate+(m.state?", "+m.state:"")),k()}catch(a){wmsx.Util.error("Could not create AudioContext. Audio DISABLED!\n"+a)}},k=function(){try{var a=-1===u?b():0===u?c():u,d=WMSX.AUDIO_MONITOR_BUFFER_SIZE>0?WMSX.AUDIO_MONITOR_BUFFER_SIZE:a>0?wmsx.Util.exp2(0|wmsx.Util.log2((m.sampleRate+14e3)/22050))*wmsx.Util.exp2(a-1)*256:0;d=d<256?256:d>16384?16384:d,o=m.createScriptProcessor(d,2,2),o.onaudioprocess=h,n=o.bufferSize,g(),wmsx.Util.log("Audio Processor buffer size: "+o.bufferSize)}catch(a){wmsx.Util.error("Could not create ScriptProcessorNode. Audio DISABLED!\n"+a)}},l=[];this.signals=l;var m,n,o,p=[],q=[],r=[],s=[],t=[],u=-3===WMSX.AUDIO_MONITOR_BUFFER_BASE?WMSX.userPreferences.current.audioBufferBase:WMSX.AUDIO_MONITOR_BUFFER_BASE,v=!1},wmsx.SaveStateMedia=function(a){"use strict";function b(a){wmsx.Util.error("Error accessing IndexedDB, falling back to LocalStorage:",a),h=void 0}this.connect=function(a){a.connectMedia(this)},this.connectPeripherals=function(a){j=a},this.isSlotUsed=function(a){return void 0!==localStorage["wmsxsave"+a+o+"u"]||void 0!==localStorage["wmsxsave"+a+o]},this.persistState=function(a,b,d){var f=e(b);c("save"+a+o,f,d)},this.retrieveState=function(a,b){d("save"+a+o,function(a){b(a&&f(a))})},this.saveStateFile=function(a){var b=e(a);b&&j.startDownloadBinary("WMSX SaveState"+m,b,"State File")},this.loadStateFile=function(a){return f(a)},this.externalStateChange=function(){a.netController&&a.netController.processExternalStateChange()};var c=function(a,c,d){function e(){i.store(a,c,function(){localStorage["wmsx"+a+"u"]="Y",d(!0)},function(a){wmsx.Util.error(a),d(!1)})}g(function(){h?h.store(a,c,function(){localStorage["wmsx"+a+"u"]="Y",d(!0)},function(a){b(a),e()}):e()})},d=function(a,c){function e(){i.retrieve(a,function(a){c(a)},function(a){wmsx.Util.warning(a),c(void 0)})}g(function(){h?h.retrieve(a,function(a){a?c(a):e()},function(e){b(e),d(a,c)}):e()})},e=function(a){try{return k+JSON.stringify(a)}catch(a){wmsx.Util.error(a)}},f=function(a){try{var b;if((b="string"==typeof a?a.substr(0,k.length):wmsx.Util.int8BitArrayToByteString(a,0,k.length))!==k&&b!==l)return;var c;return(c="string"==typeof a?a.slice(k.length):wmsx.Util.int8BitArrayToByteString(a,k.length))&&JSON.parse(c)}catch(a){wmsx.Util.error(a)}},g=function(a){if(i)return a();i=new wmsx.LocalStoragePersistence,h=new wmsx.IndexedDBPersistence,h.open(n,a,function(){h=null,a()})};this.getIndexed=function(){return h};var h,i,j,k=String.fromCharCode(0,0)+"wmsx"+String.fromCharCode(0,0)+"state!",l="wmsxsavestate!",m=".wst",n=1,o=WMSX.ENVIRONMENT?"_"+WMSX.ENVIRONMENT:""},wmsx.LocalStoragePersistence=function(){"use strict";this.open=function(a,b,c){b()},this.store=function(a,b,c,d){try{localStorage["wmsx"+a]=b,c()}catch(a){d(a)}},this.retrieve=function(a,b,c){try{b(localStorage["wmsx"+a])}catch(a){c(a)}},this.clear=function(a,b){a()}},wmsx.IndexedDBPersistence=function(){"use strict";var a=this;this.open=function(b,c,d){function e(b){wmsx.Util.error("Error obtaining IndexedDB persistence, falling back to LocalStorage only"),a.db=null,d(b)}try{var f=indexedDB.open("WebMSX",b)}catch(a){e(a)}f.onupgradeneeded=function(a){try{var b=a.target.result;b.objectStoreNames.contains("WebMSX")||(wmsx.Util.log("Creating IndexedDB persistence..."),b.createObjectStore("MainStore"))}catch(a){e(a)}},f.onsuccess=function(b){a.db=b.target.result,wmsx.Util.log("Using IndexedDB persistence"),c(a.db)},f.onerror=e},this.store=function(a,b,c,d){try{var e=this.db.transaction("MainStore","readwrite");e.onerror=d;var f=e.objectStore("MainStore"),g=f.put(b,a);g.onsuccess=function(){c()},
g.onerror=d}catch(a){d(a)}},this.retrieve=function(a,b,c){var d=this.db.transaction("MainStore");d.onerror=c;var e=d.objectStore("MainStore"),f=e.get(a);f.onsuccess=function(a){b(a.target.result)},f.onerror=c},this.clear=function(a,b){var c=indexedDB.deleteDatabase("WebMSX");c.onsuccess=a,c.onerror=b},this.db=void 0},wmsx.FileCartridgeSlot=function(a){"use strict";this.connect=function(a,d){b=a,c=d},this.connectPeripherals=function(a){d=a},this.insertCartridge=function(d,e,f,g){if(b.insertCartridge(d,e,f,g),d&&d.rom.info.e){var h=d.rom.info.e;if(h){h=h.split(/[\s,]/);for(var i in h)WMSX.EXTENSIONS_CONFIG[h[i]]&&c.activateExtension(h[i],!0,0===e,!0,!0)}}1===a.netPlayMode&&a.netController.addPeripheralOperationToSend({op:0,c:d.saveState(),p:e,a:f})},this.insertSerializedCartridge=function(a,c,d){var e=wmsx.SlotCreator.recreateFromSaveState(a,b.cartridgeInserted(c));this.insertCartridge(e,c,d)},this.loadCartridgeData=function(c,d,e){var f=b.loadCartridgeData(c,d,e);return f&&1===a.netPlayMode&&a.netController.addPeripheralOperationToSend({op:1,p:c,n:d,c:wmsx.Util.compressInt8BitArrayToStringBase64(e)}),f},this.loadSerializedCartridgeData=function(a,c,d){b.loadCartridgeData(a,c,wmsx.Util.uncompressStringBase64ToInt8BitArray(d))},this.cartridgeInserted=function(a){return b.cartridgeInserted(a)},this.removeCartridge=function(a,c){b.removeCartridge(a,c)},this.saveCartridgeDataFile=function(a){var c=b.getCartridgeData(a);d.startDownloadBinary(c.fileName,c.content,c.desc)};var b,c,d},wmsx.FileCassetteDeck=function(a){"use strict";function b(){k(),q.showOSD("Cassette Tape rewound."+n(),!0)}function c(){j(),q.showOSD("Cassette forwarded to Tape end",!0)}function d(){s="New Tape.cas",t=[],k(),q.showOSD("Cassette loaded with new blank Tape",!0),o()}function e(a){return a?wmsx.Util.leafFilenameNoExtension(a)+".cas":"New Tape.cas"}function f(a,b){b=b||0,-1===(u=wmsx.Util.arrayIndexOfSubArray(t,x,u+b,a))&&(-1===a?k():j())}function g(){return!t&&(q.showOSD("No Cassette Tape!",!0,!0),!0)}function h(){return u===t.length}function i(){return 0===u}function j(){u=t.length}function k(){u=0}function l(){for(;u%8;)t[u++]=0}function m(a){if(!t||t.length<a+24)return null;var b=null;if(wmsx.Util.arrayIndexOfSubArray(t,y,a)===a+8)b="Binary";else if(wmsx.Util.arrayIndexOfSubArray(t,z,a)===a+8)b="Basic";else{if(wmsx.Util.arrayIndexOfSubArray(t,A,a)!==a+8)return null;b="ASCII"}return{type:b,name:wmsx.Util.int8BitArrayToByteString(t,a+18,6).trim()}}function n(){var a="";if(t)if(0===t.length)a+=" Tape empty";else if(h())a+=" Tape at end";else{var b=m(u);b&&(a+=" Tape at "+b.type+' "'+b.name+'"')}else a+=" No Tape";return a}function o(){q.tapeStateUpdate(s,v,w)}this.connect=function(a){p=a,p.connectDeck(this)},this.connectPeripherals=function(a,b){q=a,r=b},this.loadTapeFile=function(b,c,d){if(0===wmsx.Util.arrayIndexOfSubArray(c,x,0))return 1===a.netPlayMode&&a.netController.addPeripheralOperationToSend({op:20,n:b,c:wmsx.Util.compressInt8BitArrayToStringBase64(c),p:d}),s=wmsx.Util.leafFilename(b),t=wmsx.Util.asNormalArray(c),k(),q.showOSD("Cassette: "+b+". "+n(),!0),o(),p.autoPowerCycle(d),t},this.loadSerializedTape=function(a,b,c){this.loadTapeFile(a,wmsx.Util.uncompressStringBase64ToInt8BitArray(b,t),c)},this.userLoadEmptyTape=function(){d()},this.userRemoveTape=function(){g()||(s=null,t=null,u=-1,q.showOSD("Cassette Tape removed",!0),o())},this.userRewind=function(){g()||b()},this.userSeekToEnd=function(){g()||c()},this.userSeekForward=function(){if(!g()){if(h()||f(1,1),h())return c();q.showOSD("Cassette skipped forward."+n(),!0)}},this.userSeekBackward=function(){if(!g()){if(i()||f(-1,-1),i())return b();q.showOSD("Cassette skipped backward."+n(),!0)}},this.saveTapeFile=function(){if(!g()){if(0===t.length)return void q.showOSD("Cassette Tape is empty!",!0,!0);try{if(l(),!s||"New Tape.cas"==s){var a=m(0);a&&(s=a.name&&a.name.trim(),s||(s="New Tape"),s+=".cas"),s||(s="New Tape.cas"),o()}r.startDownloadBinary(e(s),new Uint8Array(t),"Cassette Tape file")&&(w=!1,o())}catch(a){}}},this.peekFileInfoAtCurrentPosition=function(){return m(u)},this.userTypeCurrentAutoRunCommand=function(){if(!g()){if(0===t.length)return void q.showOSD("Cassette Tape is empty!",!0,!0);if(!p.getDriver().currentAutoRunCommand())return void q.showOSD("No executable at current Tape position!",!0,!0);p.getDriver().typeCurrentAutoRunCommand()}},this.readHeader=function(){return!(!t||h())&&(f(1),!h()&&(u+=8,!0))},this.readByte=function(){return!t||h()?null:t[u++]},this.writeHeader=function(a){t||d(),l();for(var b=0;b<x.length;b++)t[u++]=x[b];return w=!0,!0},this.writeByte=function(a){return t||d(),t[u++]=a,w=!0,!0},this.finishWriting=function(){t&&l()},this.motor=function(a){return v=null!==a?a:!v,o(),!0},this.saveState=function(){return{f:s,c:t&&wmsx.Util.compressInt8BitArrayToStringBase64(t),p:u,m:v,d:w}},this.loadState=function(a){s=a.f,t=a.c&&wmsx.Util.uncompressStringBase64ToInt8BitArray(a.c,t),u=a.p,v=a.m,w=!!a.d,o()};var p,q,r,s=null,t=null,u=-1,v=!1,w=!1,x=[31,166,222,186,204,19,125,116],y=[208,208,208,208,208,208,208,208,208,208],z=[211,211,211,211,211,211,211,211,211,211],A=[234,234,234,234,234,234,234,234,234,234]},wmsx.DiskImages=function(a){"use strict";var b=this;this.connect=function(a){c=a},this.writeFilesToImage=function(a,b){function c(a){f(a,{name:".",specialName:!0,lastModifiedDate:a.lastModifiedDate,isDir:!0,clusterChain:a.clusterChain}),f(a,{name:"..",specialName:!0,lastModifiedDate:a.lastModifiedDate,isDir:!0,clusterChain:a.parentDir.clusterChain});var b=a.items.length+2,c=a.items.filter(function(a){return!a.isDir});c.length>b&&(c.length=b),b-=c.length;var g=a.items.filter(function(a){return a.isDir});g.length>b&&(g.length=b),a.nextFreeEntry=2+g.length,e(a,c),a.nextFreeEntry=2,d(a,g),i(a),j(a)}function d(a,b){for(var d=0;d<b.length;++d){var e=b[d],g=o((e.items.length+2)*H);g>W?++Z:(e.content=wmsx.Util.arrayFill(new Array(g*N),0),e.parentDir=a,e.usedNames=new Set,e.nextFreeEntry=0,m(e),f(a,e),c(e),++Y)}}function e(a,b){for(var c=0;c<b.length;++c){var d=b[c];o(d.content.length)>W?++Z:(m(d),f(a,d),j(d),++Y)}}function f(a,b){for(var c=a.content,d=(a.availableEntries?a.availableEntries[a.nextFreeEntry]:a.nextFreeEntry)*H,e=q(b,a.usedNames),f=0;f<11;++f)c[d+f]=e.charCodeAt(f);var g=b.isDir?16:32;c[d+11]=g;var h=d+22,i=b.lastModified?new Date(b.lastModified):b.lastModifiedDate||$,j=s(i);c[h]=255&j,c[h+1]=j>>8;var k=t(i);c[h+2]=255&k,c[h+3]=k>>8,h=d+26,c[h]=255&b.clusterChain[0],c[h+1]=b.clusterChain[0]>>8,h=d+28;var l=b.isDir?0:b.content.length;c[h]=255&l,c[h+1]=l>>8&255,c[h+2]=l>>16&255,c[h+3]=l>>24&255,a.nextFreeEntry++}function g(a){for(var b=a.content,c=a.availableEntries=[],d=0,e=0,f=b.length;d<f;d+=H,++e)0!==b[d]&&229!==b[d]||c.push(e)}function h(a){for(var b=a.content,c=a.usedNames=new Set,d=0,e=0,f=b.length;d<f;d+=H,++e)if(0!==b[d]&&229!==b[d]){for(var g="",h=0;h<11;++h)g+=String.fromCharCode(b[d+h]);c.add(g)}}function i(a){for(var b=a.content,c=!1,d=b.length-H;d>=0;d-=H)c?0===b[d]&&(b[d]=229):0!==b[d]&&(c=!0)}function j(b){var c=b.content,d=b.continuousContentPosition;if(d)for(var e=0,f=c.length;e<f;++e)a[d+e]=c[e];else for(var g=0,h=b.clusterChain,i=0,j=h.length;i<j;++i){d=p(h[i]);for(var k=d+N;d<k;++d)a[d]=c[g++]}}function k(b,c){var d;R?(d=I*x+(b<<1),a[d]=255&c,a[d+1]=(65280&c)>>8):(d=I*x+3*(b>>1),1&b?(a[d+1]=15&a[d+1]|(15&c)<<4,a[d+2]=(4080&c)>>4):(a[d]=255&c,a[d+1]=240&a[d+1]|(3840&c)>>8))}function l(b){var c;return R?(c=I*x+(b<<1),a[c]|a[c+1]<<8):(c=I*x+3*(b>>1),1&b?a[c+1]>>4|a[c+2]<<4:a[c]|(15&a[c+1])<<8)}function m(a){var b=o(a.content.length);if(a.clusterChain=new Array(b),0===b)a.clusterChain[0]=0;else{for(var c=0;c<b;++c){var d=X;a.clusterChain[c]=d,n(),k(d,X)}k(d,65535)}}function n(){for(--W;0!==l(++X););}function o(a){return Math.ceil(a/N)}function p(a){return M+(a-2)*N}function q(a,b){if(a.specialName)return(a.name+"           ").substr(0,11)
;var c,d=r(wmsx.Util.leafFilenameNoExtension(a.name)),e=r(wmsx.Util.leafFilenameOnlyExtension(a.name));if(e=(e+"   ").substr(0,3),c=(d+"        ").substr(0,8)+e,d.length>8||b.has(c)){var f,g=0;do{++g,f="~"+g,c=(d.substr(0,8-f.length)+f+"        ").substr(0,8)+e}while(b.has(c))}return b.add(c),c}function r(a){return a.toUpperCase().replace(/[^a-z0-9!#$%&'\(\)\-@\^_`{}~]/gi,"_")}function s(a){return a?a.getHours()<<11|(a.getMinutes()<<5)+a.getSeconds()/2:0}function t(a){return a?(a.getFullYear()-1980&127)<<9|(a.getMonth()+1<<5)+a.getDate():0}var u=a[510]|a[511]<<8,v=(a[450],a[454]|a[455]<<8|a[456]<<16|a[457]<<24),w=0;43605===u&&1===v&&(w=this.BYTES_PER_SECTOR);var x=a[w+11]|a[w+12]<<8,y=a[w+13],z=a[w+14]|a[w+15]<<8,A=a[w+16],B=a[w+17]|a[w+18]<<8,C=a[w+19]|a[w+20]<<8,D=a[w+21],E=a[w+22]|a[w+23]<<8,F=a[w+32]|a[w+33]<<8|a[w+34]<<16|a[w+35]<<24,G=C||F,H=32,I=v+z,J=I+A*E,K=J*x,L=J+H*B/x,M=L*x,N=y*x,O=(G-(L-v))/y|0,P=a[I*x],Q=String.fromCharCode(a[w+54],a[w+55],a[w+56],a[w+57],a[w+58],a[w+59],a[w+60],a[w+61]),R="FAT16   "===Q||"FAT12   "!==Q&&O>=4080;if(!(D===P&&(240===D||D>=248)&&O>=64)){var S=this.MEDIA_TYPE_INFO[P];if(!S||S.size!==a.length){var T=new Error("Could not write files: Current Disk format not recognized (unformatted?)");throw T.wmsx=!0,T}var U=this.MEDIA_TYPE_DPB[P];x=(U[2]<<8)+U[1],y=U[5]+1,I=(U[8]<<8)+U[7],A=U[9],B=U[10],L=(U[12]<<8)+U[11],O=(U[14]<<8)+U[13]-1,E=U[15],J=(U[17]<<8)+U[16],N=y*x,R=!1}var V=function(){for(var a=O+2-1,b=-1,c=0,d=2;d<=a;++d){0===l(d)&&(++c,b<0&&(b=d))}return{first:b,quant:c,max:a}}(),W=V.quant,X=(V.max,V.first);if(0===W)throw T=new Error("Could not write files: Disk full"),T.wmsx=!0,T;var Y=0,Z=0,$=new Date;if(function(b){var c={name:"ROOT",lastModifiedDate:$,isDir:!0,items:b,content:a.slice(K,K+B*H),nextFreeEntry:0,continuousContentPosition:K,clusterChain:[0]};g(c),h(c);var f=c.availableEntries.length,k=c.items.filter(function(a){return!a.isDir});k.length>f&&(k.length=f),f-=k.length;var l=c.items.filter(function(a){return a.isDir});l.length>f&&(l.length=f),c.nextFreeEntry=l.length,e(c,k),c.nextFreeEntry=0,d(c,l),i(c),j(c)}(b),Z>0&&0===Y)throw T=new Error("No files could fit in available Disk space"),T.wmsx=!0,T;return this.mirrorFatCopies(A,I,E,x,a),Z>0?Y+" of "+(Y+Z)+" files":Y+(1===Y?" file":" files")},this.createNewDisk=function(a,b){var c=new Uint8Array(this.MEDIA_TYPE_INFO[a].size);return b||this.formatDisk(a,c),c},this.formatDisk=function(a,b){this.HARDDISK_MEDIA_TYPE_HEADER_INFO[a]?this.formatHardDisk(a,b):this.formatFloppyDisk(a,b)},this.formatFloppyDisk=function(a,b){for(var d=c.hasDOS2()||c.hasHardDiskInterface()?this.MEDIA_TYPE_BOOT_SECTOR_DOS2[a]:this.MEDIA_TYPE_BOOT_SECTOR_DOS1[a],e=0;e<d.length;++e)b[e]=d[e];var f=d[11]|d[12]<<8,g=d[16],h=d[22]|d[23]<<8,i=d[14]|d[15]<<8,j=i*f;b[j]=a,b[j+1]=255,b[j+2]=255,this.mirrorFatCopies(g,i,h,f,b);var k=i+g*h,l=d[17]|d[18]<<8,m=k+32*l/f;for(e=m*f;e<b.length;++e)b[e]=255},this.mirrorFatCopies=function(a,b,c,d,e){for(var f=c*d,g=b*d+f,h=2;h<=a;++h)for(var i=b*d,j=0;j<f;++j)e[g++]=e[i++]},this.formatHardDisk=function(a,b){var c=this.HARDDISK_MEDIA_TYPE_HEADER_INFO[a];new wmsx.MultiDownloader([{url:c.header}],function(a){var d=a[0].content;wmsx.Util.arrayCopy(d,0,b);var e=c.fatData;for(var f in c.fatsPos){var g=c.fatsPos[f];b[g]=255&e,b[g+1]=e>>8&255,b[g+2]=e>>16&255,b[g+3]=e>>24&255}}).start()},this.makeBootDisk=function(d){var e=[{url:c.hasDOS2()?"@DOS2Boot.zip":"@DOS1Boot.zip"}];c.hasHardDiskInterface()&&e.push({url:"@NextorBoot.zip"}),new wmsx.MultiDownloader(e,function(c){c[1]&&b.writeFilesToImage(d,a.fileLoader.createTreeFromZip(wmsx.Util.checkContentIsZIP(c[1].content))),b.writeFilesToImage(d,a.fileLoader.createTreeFromZip(wmsx.Util.checkContentIsZIP(c[0].content)))}).start()},this.hardDiskMediaTypeNeededForFiles=function(a){for(var b,c=0,d=this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES.length;c<d;++c){b=this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES[c];var e=this.estimatedTotalSizeOnDisk(a,b);if(this.MEDIA_TYPE_INFO[b].size>1.3*e)break}return b},this.estimatedTotalSizeOnDisk=function(a,b){for(var c=this.MEDIA_TYPE_INFO[b].clusterSize,d=0,e=0,f=a.length;e<f;++e){var g=a[e];g.isDir?(d+=Math.ceil(32*g.items.length/c)*c,d+=this.estimatedTotalSizeOnDisk(g.items,b)):d+=Math.ceil(g.content.length/c)*c}return d};var c;this.BYTES_PER_SECTOR=512,this.MEDIA_TYPE_INFO=wmsx.DiskImages.MEDIA_TYPE_INFO,this.FORMAT_OPTIONS_MEDIA_TYPES=[249,248],this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES=wmsx.DiskImages.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES,this.MEDIA_TYPE_VALID_SIZES=[737280,655360,368640,327680,184320,163840],this.MEDIA_TYPE_BOOT_SECTOR_DOS1={249:[235,254,144,87,77,83,88,32,32,32,32,0,2,2,1,0,2,112,0,160,5,249,3,0,9,0,2,0,0,0,208,237,83,89,192,50,208,192,54,86,35,54,192,49,31,245,17,171,192,14,15,205,125,243,60,202,99,192,17,0,1,14,26,205,125,243,33,1,0,34,185,192,33,0,63,17,171,192,14,39,205,125,243,195,0,1,88,192,205,0,0,121,230,254,254,2,194,106,192,58,208,192,167,202,34,64,17,133,192,205,119,192,14,7,205,125,243,24,180,26,183,200,213,95,14,6,205,125,243,209,19,24,242,66,111,111,116,32,101,114,114,111,114,13,10,80,114,101,115,115,32,97,110,121,32,107,101,121,32,102,111,114,32,114,101,116,114,121,13,10,0,0,77,83,88,68,79,83,32,32,83,89,83,0,0,0,0,0,0,0,0,0],248:[235,254,144,87,77,83,88,32,32,32,32,0,2,2,1,0,2,112,0,208,2,248,2,0,9,0,1,0,0,0,208,237,83,89,192,50,208,192,54,86,35,54,192,49,31,245,17,171,192,14,15,205,125,243,60,202,99,192,17,0,1,14,26,205,125,243,33,1,0,34,185,192,33,0,63,17,171,192,14,39,205,125,243,195,0,1,88,192,205,0,0,121,230,254,254,2,194,106,192,58,208,192,167,202,34,64,17,133,192,205,119,192,14,7,205,125,243,24,180,26,183,200,213,95,14,6,205,125,243,209,19,24,242,66,111,111,116,32,101,114,114,111,114,13,10,80,114,101,115,115,32,97,110,121,32,107,101,121,32,102,111,114,32,114,101,116,114,121,13,10,0,0,77,83,88,68,79,83,32,32,83,89,83,0,0,0,0,0,0,0,0,0]},this.MEDIA_TYPE_BOOT_SECTOR_DOS2={249:[235,254,144,87,77,83,88,32,32,32,32,0,2,2,1,0,2,112,0,160,5,249,3,0,9,0,2,0,0,0,24,16,86,79,76,95,73,68,0,64,124,3,57,0,0,0,0,0,208,237,83,106,192,50,114,192,54,103,35,54,192,49,31,245,17,171,192,14,15,205,125,243,60,40,38,17,0,1,14,26,205,125,243,33,1,0,34,185,192,33,0,63,17,171,192,14,39,205,125,243,195,0,1,105,192,205,0,0,121,230,254,214,2,246,0,202,34,64,17,133,192,14,9,205,125,243,14,7,205,125,243,24,184,66,111,111,116,32,101,114,114,111,114,13,10,80,114,101,115,115,32,97,110,121,32,107,101,121,32,102,111,114,32,114,101,116,114,121,13,10,36,0,77,83,88,68,79,83,32,32,83,89,83,0,0,0,0,0,0,0,0,0],248:[235,254,144,87,77,83,88,32,32,32,32,0,2,2,1,0,2,112,0,208,2,248,2,0,9,0,1,0,0,0,24,16,86,79,76,95,73,68,1,153,220,28,245,0,0,0,0,0,208,237,83,106,192,50,114,192,54,103,35,54,192,49,31,245,17,171,192,14,15,205,125,243,60,40,38,17,0,1,14,26,205,125,243,33,1,0,34,185,192,33,0,63,17,171,192,14,39,205,125,243,195,0,1,105,192,205,0,0,121,230,254,214,2,246,0,202,34,64,17,133,192,14,9,205,125,243,14,7,205,125,243,24,184,66,111,111,116,32,101,114,114,111,114,13,10,80,114,101,115,115,32,97,110,121,32,107,101,121,32,102,111,114,32,114,101,116,114,121,13,10,36,0,77,83,88,68,79,83,32,32,83,89,83,0,0,0,0,0,0,0,0,0]},this.MEDIA_TYPE_DPB={248:[248,0,2,15,4,1,2,1,0,2,112,12,0,99,1,2,5,0],249:[249,0,2,15,4,1,2,1,0,2,112,14,0,202,2,3,7,0],250:[250,0,2,15,4,1,2,1,0,2,112,10,0,60,1,1,3,0],251:[251,0,2,15,4,1,2,1,0,2,112,12,0,123,2,2,5,0],252:[252,0,2,15,4,0,1,1,0,2,64,9,0,96,1,2,5,0],253:[253,0,2,15,4,1,2,1,0,2,112,12,0,99,1,2,5,0],254:[254,0,2,15,4,0,1,1,0,2,64,7,0,58,1,1,3,0],255:[255,0,2,15,4,1,2,1,0,2,112,10,0,60,1,1,3,0]},this.HARDDISK_MEDIA_TYPE_HEADER_INFO={16:{fatsPos:[512,2048],fatData:[16777200],header:"@Disk16MHeader.dat"},32:{fatsPos:[512,6656],fatData:[16777200],header:"@Disk32MHeader.dat"},64:{fatsPos:[1024,66560],fatData:[4294967280],header:"@Disk64MHeader.dat"},128:{fatsPos:[1024,132096],fatData:[4294967280],header:"@Disk128MHeader.dat"}}},wmsx.DiskImages.MEDIA_TYPE_INFO={248:{
desc:"360KB",size:368640,clusterSize:1024},249:{desc:"720KB",size:737280,clusterSize:1024},250:{desc:"320KB",size:327680,clusterSize:1024},251:{desc:"640KB",size:655360,clusterSize:1024},252:{desc:"180KB",size:184320,clusterSize:512},253:{desc:"360KB",size:368640,clusterSize:1024},254:{desc:"160KB",size:163840,clusterSize:512},255:{desc:"320KB",size:327680,clusterSize:1024},16:{desc:"16MB",size:16777216,clusterSize:16384,secDesc:"(FAT12)"},32:{desc:"32MB",size:33554432,clusterSize:8192,secDesc:"(FAT12)"},64:{desc:"64MB",size:67108864,clusterSize:2048,secDesc:"(FAT16)"},128:{desc:"128MB",size:134217728,clusterSize:2048,secDesc:"(FAT16)"}},wmsx.DiskImages.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES=[16,32,64,128],wmsx.FileDiskDrive=function(room){"use strict";function init(){emptyStack(0),emptyStack(1),emptyStack(2)}function tryLoadDiskStackFromFiles(a,b,c,d,e,f){if(2===a)e=!1;else if(e&&maxStackReachedMessage(a))return[];var g=[],h=2===a?1:e?MAX_STACK-driveStack[a].length:MAX_STACK;try{for(var i=0;i<c.length&&g.length<h;i++){var j=c[i];f&&void 0===j.content&&(j.content=j.asUint8Array());var k=checkFileHasValidImages(j,2===a,!b&&1===c.length);k&&g.push.apply(g,k)}if(g.length>0)return g.length>h&&(g=g.slice(0,h)),loadStack(a,g,null,d,e),g}catch(a){wmsx.Util.error(a)}}function checkFileHasValidImages(a,b,c,d){if(!d){var e=wmsx.Util.checkContentIsZIP(a.content);if(e){try{var f=wmsx.Util.getZIPFilesSorted(e);for(var g in f){f[g].content=f[g].asUint8Array();var h=checkFileHasValidImages(f[g],b,c,!0);if(h)return h}}catch(a){wmsx.Util.error(a)}return null}}var i=wmsx.Util.checkContentIsGZIP(a.content);if(i)return checkFileHasValidImages({name:a.name,content:i},b,c,!0);var j=checkContentIsValidImages(a.content,b,c);if(j){var k=wmsx.Util.leafFilename(a.name);if(1===j)return[{name:k,content:a.content}];for(var l=new Array(j),m=a.content.length/j|0,n=0,o=0;n<j;++n,o+=m)l[n]={name:k+(n+1),content:a.content.slice(o,o+m)};return l}return null}function checkContentIsValidImages(a,b,c){if(MEDIA_TYPE_VALID_SIZES_SET.has(a.length))return 1;if(b){if(a.length%BYTES_PER_SECTOR)return 0;if(a.length<HARDDISK_MIN_SIZE)return 0;if(c)return 1;if(85===a[510]&&170===a[511])return 1;if(a[512]>=240&&a[513]>=255)return 1;for(var d=0;d<32;++d)if(0!==a[d])return 0;return 1}var e=MEDIA_TYPE_VALID_SIZES[0];return a.length%e==0?a.length/e|0:0}function emptyStack(a){driveStack[a].length=0,curDisk[a]=-1,driveDiskChanged[a]=null}function loadStack(a,b,c,d,e,f){1===room.netPlayMode&&room.netController.addPeripheralOperationToSend({op:10,d:a,s:serializeStack(b),t:c,p:d,a:e}),e?(driveStack[a]=driveStack[a].concat(b),getCurrentDisk(a)||setCurrentDiskNum(a,0)):(driveStack[a]=b,setCurrentDiskNum(a,0)),stackLoadedMessage(a,c,b.length,e,f),fireMediaStateUpdate(a),driveStack[a].length>1?d||2===room.netPlayMode||self.openDiskSelectDialog(a,0,d):autoPower(d)}function autoPower(a){(diskDriveSocket.hasDiskInterface()&&getCurrentDisk(0)||diskDriveSocket.hasHardDiskInterface()&&getCurrentDisk(2))&&diskDriveSocket.autoPowerCycle(a)}function replaceCurrentDisk(a,b,c){c&&1===room.netPlayMode&&room.netController.addPeripheralOperationToSend({op:12,d:a,k:serializeDisk(b)}),driveStack[a][curDisk[a]]=b,driveDiskChanged[a]=!0,fireMediaStateUpdate(a)}function makeFileNameToSave(a){return a?wmsx.Util.leafFilenameNoExtension(a)+".dsk":"New Disk.dsk"}function motorOff(a,b){driveMotor[a]&&(driveMotorOffTimer[a]&&b&&(clearTimeout(driveMotorOffTimer[a]),driveMotorOffTimer[a]=null),driveMotorOffTimer[a]||(driveMotorOffTimer[a]=setTimeout(function(){driveMotorOffTimer[a]=null,driveMotor[a]=!1,fireMotorStateUpdate()},MOTOR_SPINDOWN_EXTRA_MILLIS[a])))}function setCurrentDiskNum(a,b){curDisk[a]=b,driveDiskChanged[a]=!0}function getCurrentDisk(a){return driveStack[a][curDisk[a]]}function fireMediaStateUpdate(a){screen.diskDrivesMediaStateUpdate(a),fireMotorStateUpdate()}function fireMotorStateUpdate(){var a=getCurrentDisk(0),b=getCurrentDisk(1),c=getCurrentDisk(2);screen.diskDrivesMotorStateUpdate(a,driveMotor[0],a&&a.modified,b,driveMotor[1],b&&b.modified,c,driveMotor[2],c&&c.modified)}function noDiskInsertedMessage(a){return!self.isDiskInserted(a)&&(screen.showOSD("No Disk in "+driveName[a],!0,!0),!0)}function maxStackReachedMessage(a){return driveStack[a].length>=MAX_STACK&&(screen.showOSD("Maximum Stack size in "+driveName[a]+" ("+driveStack[a].length+" disks)",!0,!0),!0)}function stackLoadedMessage(a,b,c,d,e){b=b||"Disk";var f=d?c+" "+b+(c>1?"s":"")+" added to "+driveName[a]:c>1?c+" Disks loaded in "+driveName[a]:currentDiskDesc(a);screen.showOSD(f+(e?" "+e:""),!0)}function diskInsertedMessage(a){noDiskInsertedMessage(a)||screen.showOSD(currentDiskDesc(a),!0)}function currentDiskDesc(a){var b=getCurrentDisk(a),c=currentDiskNumDesc(a);return driveName[a]+": "+(c?c+" ":"")+(b?b.name:"")}function currentDiskNumDesc(a){return driveStack[a].length>1?"("+(curDisk[a]+1)+"/"+driveStack[a].length+")":""}function serializeStack(a){for(var b=new Array(a.length),c=0;c<a.length;++c)b[c]=serializeDisk(a[c]);return b}function serializeDisk(a){return{name:a.name,content:wmsx.Util.compressInt8BitArrayToStringBase64(a.content),modif:a.modified}}function deserializeStack(a,b){if(b){b.length=a.length;for(var c=0;c<a.length;++c)b[c]=deserializeDisk(a[c],b[c]);return b}var d=new Array(a.length);for(c=0;c<a.length;++c)d[c]=deserializeDisk(a[c]);return d}function deserializeDisk(a,b){return{name:a.name,content:wmsx.Util.uncompressStringBase64ToInt8BitArray(a.content,b&&b.content,!1,Uint8Array),modified:!!a.modif}}function clearDisconnectedDiskInterfaces(){diskDriveSocket.hasDiskInterface()||(emptyStack(0),emptyStack(1),driveMotor[0]=driveMotor[1]=!1,fireMediaStateUpdate(0),fireMediaStateUpdate(1)),diskDriveSocket.hasHardDiskInterface()||clearHardDrive()}function clearHardDrive(){emptyStack(2),driveMotor[2]=!1,fireMediaStateUpdate(2)}var self=this;this.connect=function(a){diskDriveSocket=a,diskDriveSocket.connectDrive(this),images.connect(diskDriveSocket)},this.connectPeripherals=function(a,b){screen=a,fileDownloader=b},this.hasAnyMediaInserted=function(){return diskDriveSocket.hasDiskInterface()&&(driveStack[0].length||driveStack[1].length)||diskDriveSocket.hasHardDiskInterface()&&driveStack[2].length},this.isHardDriveFirst=function(){return 1&WMSX.EXTENSIONS.HARDDISK||diskDriveSocket.hasHardDiskInterface()&&!diskDriveSocket.hasDiskInterface()},this.loadDiskStackFromFiles=function(a,b,c,d,e){var f=!1;if(!(a>=0)){f=!0;var g=diskDriveSocket.hasDiskInterface(),h=diskDriveSocket.hasHardDiskInterface();if(g)a=h?a<0?-a:self.isHardDriveFirst()?2:0:a<0?-a:0;else{if(!h)return;a=2}}var i=tryLoadDiskStackFromFiles(a,f,b,c,d,e);return i||(f&&0===a&&!d&&h?tryLoadDiskStackFromFiles(2,!0,b,c,d,e):void 0)},this.loadAsDiskFromFiles=function(a,b,c,d){if(!(a>=0)){var e=diskDriveSocket.hasDiskInterface(),f=diskDriveSocket.hasHardDiskInterface();if(e)a=f?a<0?-a:this.isHardDriveFirst()?2:0:a<0?-a:0;else{if(!f)return;a=2}}var g,h=getCurrentDisk(a);if(h)g=h.content;else{try{var i=2===a?images.hardDiskMediaTypeNeededForFiles(c):this.FORMAT_OPTIONS_MEDIA_TYPES[0]}catch(b){console.error(b),i=2===a?this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES[1]:this.FORMAT_OPTIONS_MEDIA_TYPES[0]}g=images.createNewDisk(i)}try{var j=images.writeFilesToImage(g,c);if(!j)return}catch(a){throw console.error(a),a}if(h)return screen.showOSD(driveName[a]+": "+j+" added to disk",!0),h.content=g,h.modified=!0,replaceCurrentDisk(a,h,!0),this.getDriveStack(a);b=(b||"New "+this.MEDIA_TYPE_INFO[i].desc)+".dsk";var k=[{name:b,content:g,modified:!1}];return loadStack(a,k,null,d,!1,"("+j+" added to disk)"),k},this.loadSerializedStack=function(a,b,c,d,e){loadStack(a,deserializeStack(b,e?void 0:driveStack[a]),c,d,e)},this.replaceCurrentDiskSerialized=function(a,b){replaceCurrentDisk(a,deserializeDisk(b,getCurrentDisk(a)))},this.insertNewDisk=function(a,b,c,d){if(2===a||!maxStackReachedMessage(a)){
b||(b=2===a?this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES[0]:this.FORMAT_OPTIONS_MEDIA_TYPES[0]),1===room.netPlayMode&&room.netController.addPeripheralOperationToSend({op:11,d:a,m:b,b:c,u:d});var e=(this.MEDIA_TYPE_INFO[b],"New "+this.MEDIA_TYPE_INFO[b].desc+(c?" Boot":"")+" Disk.dsk"),f=images.createNewDisk(b,d),g=0===driveStack[a].length||2!==a;g&&driveStack[a].push({}),curDisk[a]=driveStack[a].length-1,replaceCurrentDisk(a,{name:e,content:f}),c&&images.makeBootDisk(f);var h=g&&driveStack[a].length>1;diskInsertedMessage(a),h&&2!==room.netPlayMode&&self.openDiskSelectDialog(a,0,!0)}},this.removeStack=function(a){if(!noDiskInsertedMessage(a)){var b=driveStack[a].length>1;emptyStack(a),screen.showOSD((b?"Disk Stack in ":"Disk in ")+driveName[a]+" removed",!0),fireMediaStateUpdate(a)}},this.insertDiskFromStack=function(a,b,c){setCurrentDiskNum(a,b),diskInsertedMessage(a),fireMediaStateUpdate(a),autoPower(c)},this.moveDiskInStack=function(a,b,c){var d=driveStack[a];if(!(b<0||c<0||b>d.length-1||c>d.length-1)){var e=d[curDisk[a]];d.splice(c,0,d.splice(b,1)[0]),e&&(curDisk[a]=d.indexOf(e)),fireMediaStateUpdate(a)}},this.saveDiskFile=function(a){if(!noDiskInsertedMessage(a))try{var b=getCurrentDisk(a);fileDownloader.startDownloadBinary(makeFileNameToSave(b.name),b.content.constructor===Uint8Array?b.content:new Uint8Array(b.content),driveName[a]+" Image file")&&(b.modified=!1,fireMotorStateUpdate())}catch(a){}},this.openDiskSelectDialog=function(a,b,c){noDiskInsertedMessage(a)||screen.openDiskSelectDialog(a,b,c)},this.openNewHardDiskDialog=function(a,b){screen.openNewHardDiskDialog(a,b)},this.getDriveStack=function(a){return driveStack[a]},this.getCurrentDiskNum=function(a){return curDisk[a]},this.getCurrentDiskDesc=function(a){return currentDiskDesc(a)},this.getCurrentDiskNumDesc=function(a){return currentDiskNumDesc(a)},this.getDriveName=function(a){return driveName[a]},this.diskHasChanged=function(a){return driveDiskChanged[a]?(driveDiskChanged[a]=!1,!0):driveDiskChanged[a]},this.getTotalSectorsAvailable=function(a){return this.isDiskInserted(a)?getCurrentDisk(a).content.length/BYTES_PER_SECTOR|0:null},this.isDiskInserted=function(a){return!!getCurrentDisk(a)},this.diskWriteProtected=function(a){return!1},this.readByte=function(a,b){if(!this.isDiskInserted(a))return null;var c=getCurrentDisk(a).content;return b>=c.length?null:c[b]},this.readDWord=function(a,b){if(!this.isDiskInserted(a))return null;var c=getCurrentDisk(a).content;return b+3>=c.length?null:c[b]|c[b+1]<<8|c[b+2]<<16|c[b+3]<<24},this.readSectorsToSlot=function(a,b,c,d,e){if(!this.isDiskInserted(a))return!1;var f=getCurrentDisk(a).content,g=b*BYTES_PER_SECTOR,h=c*BYTES_PER_SECTOR;if(g>=f.length||g+h>f.length)return!1;for(var i=0;i<h;i++)d.write(e+i,f[g+i]);return!0},this.writeSectorsFromSlot=function(a,b,c,d,e){var f=getCurrentDisk(a);if(!f)return!1;var g=f.content,h=b*BYTES_PER_SECTOR,i=c*BYTES_PER_SECTOR;if(h>=g.length||h+i>g.length)return!1;for(var j=0;j<i;j++)g[h+j]=d.read(e+j);return f.modified=!0,!0},this.motorOn=function(a){return driveMotorOffTimer[a]&&(clearTimeout(driveMotorOffTimer[a]),driveMotorOffTimer[a]=null),driveMotor[a]?0:(driveMotor[a]=!0,fireMotorStateUpdate(),MOTOR_SPINUP_EXTRA_ITERATIONS[a])},this.motorFlash=function(a){driveMotor[a]||(driveMotor[a]=!0,fireMotorStateUpdate(),motorOff(a))},this.allMotorsOff=function(a){motorOff(0,a),motorOff(1,a),motorOff(2)},this.allMotorsOffNow=function(){driveMotor[0]=driveMotor[1]=driveMotor[2]=!1,fireMotorStateUpdate()},this.formatCurrentDisk=function(a,b){return images.formatDisk(b,getCurrentDisk(a).content)},this.saveState=function(){return clearDisconnectedDiskInterfaces(),{s:[serializeStack(driveStack[0]),serializeStack(driveStack[1]),serializeStack(driveStack[2])],c:curDisk,g:driveDiskChanged,m:driveMotor}},this.loadState=function(a){deserializeStack(a.s[0],driveStack[0]),deserializeStack(a.s[1],driveStack[1]),a.s[2]?deserializeStack(a.s[2],driveStack[2]):clearHardDrive(),curDisk=a.c,driveDiskChanged=a.g,driveMotor=a.m,fireMediaStateUpdate(0),fireMediaStateUpdate(1),fireMediaStateUpdate(2),this.allMotorsOff(!0)},this.eval=function(str){return eval(str)};var images=new wmsx.DiskImages(room),screen,fileDownloader,diskDriveSocket,driveStack=[[],[],[]],curDisk=[0,0,0],driveDiskChanged=[null,null,null],driveMotor=[!1,!1,!1],driveMotorOffTimer=[null,null,null],driveName=["Drive A","Drive B","Hard Drive"],BYTES_PER_SECTOR=512,MOTOR_SPINUP_EXTRA_ITERATIONS=[1e5,1e5,0],MOTOR_SPINDOWN_EXTRA_MILLIS=[2300,2300,50],MAX_STACK=wmsx.FileDiskDrive.MAX_STACK,MEDIA_TYPE_VALID_SIZES=images.MEDIA_TYPE_VALID_SIZES,MEDIA_TYPE_VALID_SIZES_SET=new Set(MEDIA_TYPE_VALID_SIZES),HARDDISK_MIN_SIZE=1024*(WMSX.HARDDISK_MIN_SIZE_KB||720);this.MEDIA_TYPE_INFO=images.MEDIA_TYPE_INFO,this.MEDIA_TYPE_DPB=images.MEDIA_TYPE_DPB,this.FORMAT_OPTIONS_MEDIA_TYPES=images.FORMAT_OPTIONS_MEDIA_TYPES,this.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES=images.HARDDISK_FORMAT_OPTIONS_MEDIA_TYPES,this.HARDDISK_MEDIA_TYPE_HEADER_INFO=images.HARDDISK_MEDIA_TYPE_HEADER_INFO,init()},wmsx.FileDiskDrive.MAX_STACK=10,wmsx.PeripheralControls={SCREEN_ASPECT_PLUS:1,SCREEN_ASPECT_MINUS:2,SCREEN_SCALE_PLUS:3,SCREEN_SCALE_MINUS:4,SCREEN_FULLSCREEN:5,SCREEN_CRT_FILTER:6,SCREEN_CRT_SCANLINES:7,SCREEN_CRT_PHOSPHOR:8,SCREEN_TOGGLE_MENU:9,SCREEN_OPEN_HELP:10,SCREEN_OPEN_ABOUT:11,SCREEN_OPEN_SETTINGS:12,SCREEN_OPEN_QUICK_OPTIONS:13,SCREEN_OPEN_TOUCH_CONFIG:14,SCREEN_OPEN_MACHINE_SELECT:15,SCREEN_TOGGLE_VIRTUAL_KEYBOARD:16,SCREEN_DEFAULTS:17,SCREEN_OUTPUT_AUTO:90,SCREEN_OUTPUT_INTERNAL:91,SCREEN_OUTPUT_EXTERNAL:92,SCREEN_OUTPUT_SUPERIMPOSED:93,SCREEN_OUTPUT_MIXED:94,SCREEN_OUTPUT_DUAL:95,SCREEN_OUTPUT_TOGGLE:96,SCREEN_OUTPUT_RESET_AUTO:97,SCREEN_COLORS:98,SCREEN_PALETTES:99,DISK_LOAD_FILES:20,DISK_ADD_FILES:21,DISK_LOAD_URL:22,DISK_LOAD_FILES_AS_DISK:23,DISK_LOAD_ZIP_AS_DISK:24,DISK_REMOVE:25,DISK_EMPTY:26,DISK_BOOT:27,DISK_SAVE_FILE:29,DISK_SELECT:30,DISK_PREVIOUS:31,DISK_NEXT:32,DISK_INSERT:33,DISK_MOVE:34,HARDDISK_LOAD_FILE:40,HARDDISK_LOAD_URL:42,HARDDISK_LOAD_FILES_AS_DISK:43,HARDDISK_LOAD_ZIP_AS_DISK:44,HARDDISK_REMOVE:45,HARDDISK_CHOOSE_EMPTY:46,HARDDISK_CHOOSE_BOOT:47,HARDDISK_NEW:48,HARDDISK_SAVE_FILE:49,CARTRIDGE_LOAD_FILE:50,CARTRIDGE_LOAD_URL:52,CARTRIDGE_REMOVE:53,CARTRIDGE_LOAD_DATA_FILE:54,CARTRIDGE_SAVE_DATA_FILE:55,CARTRIDGE_CHOOSE_FORMAT:56,TAPE_LOAD_FILE:60,TAPE_LOAD_URL:62,TAPE_REMOVE:63,TAPE_EMPTY:64,TAPE_SAVE_FILE:65,TAPE_REWIND:66,TAPE_TO_END:67,TAPE_SEEK_FWD:68,TAPE_SEEK_BACK:69,TAPE_AUTO_RUN:70,AUTO_LOAD_FILE:80,AUTO_LOAD_URL:81,MACHINE_POWER_TOGGLE:102,MACHINE_POWER_RESET:103,MACHINE_LOAD_STATE_FILE:104,MACHINE_SAVE_STATE_FILE:105,MACHINE_LOAD_STATE_MENU:106,MACHINE_SAVE_STATE_MENU:107,MACHINE_SELECT:108,EXTENSION_TOGGLE:109,KEYBOARD_TOGGLE_HOST_LAYOUT:201,JOYSTICKS_TOGGLE_MODE:202,JOYKEYS_TOGGLE_MODE:203,MOUSE_TOGGLE_MODE:204,MOUSE_TOGGLE_LOCK:205,TOUCH_TOGGLE_MODE:206,TOUCH_TOGGLE_DIR_BIG:207,TOUCH_TOGGLE_MIRRORED:208,HAPTIC_FEEDBACK_TOGGLE_MODE:209,TURBO_FIRE_TOGGLE:210,COPY_STRING:301,OPEN_PASTE_STRING:302,OPEN_ENTER_STRING:303,CAPTURE_SCREEN:304,SPEAKER_BUFFER_TOGGLE:400,SCREEN_OPEN_NETPLAY:500},wmsx.DOMPeripheralControls=function(a){"use strict";function b(a,c,e,h,t){var u=e?1:0;switch(a){case r.MACHINE_POWER_TOGGLE:f.processControlState(wmsx.MachineControls.POWER,!0,c);break;case r.MACHINE_POWER_RESET:f.processControlState(wmsx.MachineControls.POWER,!0,!0);break;case r.MACHINE_LOAD_STATE_FILE:t&&d(a)||o.openFileChooserDialog(z.STATE,!1,0,!1);break;case r.MACHINE_SAVE_STATE_FILE:case r.TAPE_AUTO_RUN:if(e)return p.userTypeCurrentAutoRunCommand();t&&d(a)||f.processControlState(wmsx.MachineControls.SAVE_STATE_FILE,!0);break;case r.MACHINE_LOAD_STATE_MENU:g.openSaveStateDialog(!1);break;case r.MACHINE_SAVE_STATE_MENU:g.openSaveStateDialog(!0);break;case r.MACHINE_SELECT:k.changeMachine(h);break;case r.EXTENSION_TOGGLE:l.toggleExtension(h,c,e);break;case r.DISK_LOAD_FILES:
!s||t&&d(a)||o.openFileChooserDialog(z.DISK,c,u,!1);break;case r.DISK_ADD_FILES:!s||t&&d(a)||o.openFileChooserDialog(z.DISK,c,u,!0);break;case r.DISK_LOAD_URL:!s||t&&d(a)||o.openURLChooserDialog(z.DISK,c,u);break;case r.DISK_LOAD_FILES_AS_DISK:!s||t&&d(a)||o.openFileChooserDialog(z.FILES_AS_DISK,c,u,!1);break;case r.DISK_LOAD_ZIP_AS_DISK:!s||t&&d(a)||o.openFileChooserDialog(z.ZIP_AS_DISK,c,u,!1);break;case r.DISK_REMOVE:!s||t&&d(a)||q.removeStack(u);break;case r.DISK_EMPTY:!s||t&&d(a)||q.insertNewDisk(u);break;case r.DISK_BOOT:!s||t&&d(a)||q.insertNewDisk(u,null,!0);break;case r.DISK_SAVE_FILE:!s||t&&d(a)||q.saveDiskFile(u);break;case r.DISK_SELECT:s&&q.openDiskSelectDialog(u,0,c);break;case r.DISK_PREVIOUS:s&&q.openDiskSelectDialog(u,-1,c);break;case r.DISK_NEXT:s&&q.openDiskSelectDialog(u,1,c);break;case r.DISK_INSERT:q.insertDiskFromStack(h.d,h.n,h.a);break;case r.DISK_MOVE:q.moveDiskInStack(h.d,h.f,h.t);break;case r.CARTRIDGE_LOAD_FILE:t&&d(a)||o.openFileChooserDialog(z.ROM,c,u,!1);break;case r.CARTRIDGE_LOAD_URL:t&&d(a)||o.openURLChooserDialog(z.ROM,c,u);break;case r.CARTRIDGE_REMOVE:t&&d(a)||m.removeCartridge(u,c);break;case r.CARTRIDGE_LOAD_DATA_FILE:if(j.dataOperationNotSupportedMessage(u,!1,!1))break;o.openFileChooserDialog(z.CART_DATA,c,u,!1);break;case r.CARTRIDGE_SAVE_DATA_FILE:m.saveCartridgeDataFile(u);break;case r.CARTRIDGE_CHOOSE_FORMAT:t&&d(a)||g.openCartridgeFormatDialog(u,c);break;case r.TAPE_LOAD_FILE:t&&d(a)||o.openFileChooserDialog(z.TAPE,c,0,!1);break;case r.TAPE_LOAD_URL:t&&d(a)||o.openURLChooserDialog(z.TAPE,c,0);break;case r.TAPE_REMOVE:t&&d(a)||p.userRemoveTape();break;case r.TAPE_EMPTY:t&&d(a)||p.userLoadEmptyTape();break;case r.TAPE_SAVE_FILE:t&&d(a)||p.saveTapeFile();break;case r.TAPE_REWIND:p.userRewind();break;case r.TAPE_TO_END:p.userSeekToEnd();break;case r.TAPE_SEEK_BACK:p.userSeekBackward();break;case r.TAPE_SEEK_FWD:p.userSeekForward();break;case r.HARDDISK_LOAD_FILE:t&&d(a)||o.openFileChooserDialog(z.DISK,c,2,!1);break;case r.HARDDISK_LOAD_URL:t&&d(a)||o.openURLChooserDialog(z.DISK,c,2);break;case r.HARDDISK_LOAD_FILES_AS_DISK:t&&d(a)||o.openFileChooserDialog(z.FILES_AS_DISK,c,2,!1);break;case r.HARDDISK_LOAD_ZIP_AS_DISK:t&&d(a)||o.openFileChooserDialog(z.ZIP_AS_DISK,c,2,!1);break;case r.HARDDISK_REMOVE:t&&d(a)||q.removeStack(2);break;case r.HARDDISK_CHOOSE_EMPTY:t&&d(a)||q.openNewHardDiskDialog(c,!1);break;case r.HARDDISK_CHOOSE_BOOT:t&&d(a)||q.openNewHardDiskDialog(c,!0);break;case r.HARDDISK_NEW:q.insertNewDisk(2,h.m,h.b);break;case r.HARDDISK_SAVE_FILE:t&&d(a)||q.saveDiskFile(2);break;case r.AUTO_LOAD_FILE:if(!t||!d(a)){var v=e?-1:void 0;o.openFileChooserDialog(z.AUTO,c,v,!1)}break;case r.AUTO_LOAD_URL:t&&d(a)||(v=e?-1:void 0,o.openURLChooserDialog(z.AUTO,c,v,!1));break;case r.SCREEN_CRT_FILTER:g.crtFilterToggle(e);break;case r.SCREEN_CRT_SCANLINES:g.crtScanlinesToggle(e);break;case r.SCREEN_CRT_PHOSPHOR:g.crtPhosphorToggle(e);break;case r.SCREEN_FULLSCREEN:g.fullscreenToggle(e);break;case r.SCREEN_DEFAULTS:f.processControlState(wmsx.MachineControls.DEFAULTS,!0),g.setDefaults();break;case r.SCREEN_TOGGLE_MENU:g.toggleMenuByKey();break;case r.SCREEN_OPEN_HELP:g.openHelp();break;case r.SCREEN_OPEN_ABOUT:g.openAbout();break;case r.SCREEN_OPEN_SETTINGS:if(c)return b(r.SCREEN_DEFAULTS,!1,!1,null,t);g.openSettings();break;case r.SCREEN_OPEN_QUICK_OPTIONS:g.openQuickOptionsDialog();break;case r.SCREEN_OPEN_TOUCH_CONFIG:g.openTouchConfigDialog();break;case r.SCREEN_OPEN_MACHINE_SELECT:g.openMachineSelectDialog();break;case r.SCREEN_TOGGLE_VIRTUAL_KEYBOARD:g.toggleVirtualKeyboard();break;case r.SCREEN_OPEN_NETPLAY:g.openNetPlayDialog();break;case r.SCREEN_OUTPUT_AUTO:c?b(r.SCREEN_OUTPUT_RESET_AUTO):g.getMonitor().setOutputMode(-1);break;case r.SCREEN_OUTPUT_INTERNAL:case r.SCREEN_OUTPUT_EXTERNAL:case r.SCREEN_OUTPUT_SUPERIMPOSED:case r.SCREEN_OUTPUT_MIXED:g.getMonitor().setOutputMode(a-r.SCREEN_OUTPUT_AUTO-1);break;case r.SCREEN_OUTPUT_DUAL:g.getMonitor().setOutputModeDual();break;case r.SCREEN_OUTPUT_RESET_AUTO:g.getMonitor().resetOutputAutoMode();break;case r.SCREEN_OUTPUT_TOGGLE:g.getMonitor().toggleOutputMode(e);break;case r.SCREEN_COLORS:g.getMonitor().toggleColorMode(e);break;case r.SCREEN_PALETTES:g.getMonitor().togglePaletteMode(e);break;case r.KEYBOARD_TOGGLE_HOST_LAYOUT:n.toggleKeyboardLayout(e);break;case r.JOYSTICKS_TOGGLE_MODE:n.toggleJoystickMode(e);break;case r.JOYKEYS_TOGGLE_MODE:n.toggleJoykeysMode(e);break;case r.MOUSE_TOGGLE_MODE:n.toggleMouseMode(e);break;case r.MOUSE_TOGGLE_LOCK:n.toggleMouseLock();break;case r.TOUCH_TOGGLE_MODE:n.toggleTouchControlsMode(c,e);break;case r.TOUCH_TOGGLE_DIR_BIG:n.getTouchControls().toggleDirBig();break;case r.TOUCH_TOGGLE_MIRRORED:n.getTouchControls().toggleMirrored();break;case r.TURBO_FIRE_TOGGLE:n.toggleTurboFireSpeed(e);break;case r.HAPTIC_FEEDBACK_TOGGLE_MODE:n.toggleHapticFeedback();break;case r.COPY_STRING:g.executeTextCopy();break;case r.OPEN_PASTE_STRING:g.toggleTextPasteDialog();break;case r.OPEN_ENTER_STRING:g.toggleTextEntryDialog();break;case r.CAPTURE_SCREEN:g.saveScreenCapture();break;case r.SPEAKER_BUFFER_TOGGLE:i.toggleBufferBaseSize(e)}if(!ja)switch(a){case r.SCREEN_ASPECT_MINUS:g.displayAspectDecrease();break;case r.SCREEN_ASPECT_PLUS:g.displayAspectIncrease();break;case r.SCREEN_SCALE_MINUS:g.displayScaleDecrease();break;case r.SCREEN_SCALE_PLUS:g.displayScaleIncrease()}}var c=this;this.connect=function(a,b,c){k=a,l=b,j=c},this.connectPeripherals=function(a,b,c,d,e,j,k,l){m=a,f=b,g=c,i=d,h=c.getMonitor(),n=e,o=j,p=k,q=l},this.getControlReport=function(a){switch(a){case r.TOUCH_TOGGLE_DIR_BIG:case r.TOUCH_TOGGLE_MIRRORED:case r.TURBO_FIRE_TOGGLE:case r.HAPTIC_FEEDBACK_TOGGLE_MODE:return n.getControlReport(a);case r.SCREEN_CRT_FILTER:case r.SCREEN_CRT_SCANLINES:return g.getControlReport(a);case r.SPEAKER_BUFFER_TOGGLE:return i.getControlReport(a)}return{label:"Unknown",active:!1}},this.diskInterfacesStateUpdate=function(a,b){s=a,t=b},this.processKey=function(a,b){if(!b)return!1;var d=u[a&x];return!!d&&(c.processControlActivated(d,!1,!!(a&y)),!0)},this.processControlActivated=function(c,d,e,f){if(!ma.has(c)){if(2===a.netPlayMode&&(ka.has(c)||la.has(c)))return a.showOSD("Function not available in NetPlay Client mode",!0,!0);if(1===a.netPlayMode&&ka.has(c)||v.push({c:c<<4|d<<1|e,d:f}),2===a.netPlayMode)return}b(c,d,e,f,!0)};var d=function(b){return WMSX.MEDIA_CHANGE_DISABLED?(h.showOSD("Media operations are disabled!",!0,!0),!0):!(2!==a.netPlayMode||b&&!ka.has(b)&&!la.has(b))&&(h.showOSD("Media operations are disabled in NetPlay Client mode!",!0,!0),!0)};this.mediaChangeDisabledWarning=d;var e=function(){var a=w;u[ia|a.CONTROL|a.ALT]=r.MACHINE_SAVE_STATE_FILE,u[L]=r.AUTO_LOAD_FILE,u[M]=r.AUTO_LOAD_URL,u[S|a.ALT]=r.DISK_SELECT,u[T|a.ALT]=r.DISK_SELECT,u[U|a.ALT]=r.DISK_PREVIOUS,u[V|a.ALT]=r.DISK_NEXT,u[N|a.CONTROL|a.ALT]=r.TAPE_AUTO_RUN,u[O|a.CONTROL|a.ALT]=r.TAPE_REWIND,u[P|a.CONTROL|a.ALT]=r.TAPE_TO_END,u[Q|a.CONTROL|a.ALT]=r.TAPE_SEEK_BACK,u[R|a.CONTROL|a.ALT]=r.TAPE_SEEK_FWD,u[W|a.ALT]=r.KEYBOARD_TOGGLE_HOST_LAYOUT,u[X|a.ALT]=r.JOYSTICKS_TOGGLE_MODE,u[Y|a.ALT]=r.JOYKEYS_TOGGLE_MODE,u[Z|a.ALT]=r.MOUSE_TOGGLE_MODE,u[$|a.ALT]=r.MOUSE_TOGGLE_LOCK,u[_|a.ALT]=r.TOUCH_TOGGLE_MODE,u[aa|a.ALT]=r.TURBO_FIRE_TOGGLE,u[ca|a.ALT]=r.SCREEN_CRT_FILTER,u[da|a.ALT]=r.SCREEN_CRT_SCANLINES,u[ea|a.ALT]=r.SCREEN_COLORS,u[fa|a.ALT]=r.SCREEN_PALETTES,u[ga|a.ALT]=r.SCREEN_OPEN_QUICK_OPTIONS,u[ha|a.ALT]=r.SCREEN_FULLSCREEN,u[ba|a.ALT]=r.SCREEN_OUTPUT_TOGGLE,u[ba|a.CONTROL|a.ALT]=r.SCREEN_OUTPUT_DUAL,u[B|a.CONTROL|a.ALT]=r.SCREEN_SCALE_MINUS,u[D|a.CONTROL|a.ALT]=r.SCREEN_SCALE_PLUS,u[A|a.CONTROL|a.ALT]=r.SCREEN_ASPECT_MINUS,u[C|a.CONTROL|a.ALT]=r.SCREEN_ASPECT_PLUS,u[E]=r.SCREEN_TOGGLE_MENU,u[F|a.ALT]=r.SCREEN_DEFAULTS,u[G|a.ALT]=r.COPY_STRING,u[H|a.ALT]=r.OPEN_PASTE_STRING,u[I|a.ALT]=r.OPEN_PASTE_STRING,u[J|a.ALT]=r.OPEN_ENTER_STRING,u[K|a.ALT]=r.CAPTURE_SCREEN}
;this.netGetControlsToSend=function(){return v.length?v:void 0},this.netClearControlsToSend=function(){v.length=0},this.netServerProcessControlsChanges=function(a){for(var c=0,d=a.length;c<d;++c){var e=a[c];ka.has(e.c>>4)||v.push(e),b(e.c>>4,e.c>>1&1,1&e.c,e.d)}},this.netClientApplyControlsChanges=function(a){for(var c=0,d=a.length;c<d;++c){var e=a[c];b(e.c>>4,e.c>>1&1,1&e.c,e.d)}};var f,g,h,i,j,k,l,m,n,o,p,q,r=wmsx.PeripheralControls,s=!1,t=!1,u={},v=new Array(100);v.length=0;var w=wmsx.DOMKeys,x=~w.SHIFT,y=w.SHIFT,z=wmsx.FileLoader.OPEN_TYPE,A=w.VK_LEFT.wc,B=w.VK_UP.wc,C=w.VK_RIGHT.wc,D=w.VK_DOWN.wc,E=w.VK_CONTEXT.wc,F=w.VK_BACKSPACE.wc,G=w.VK_C.wc,H=w.VK_V.wc,I=w.VK_INSERT.wc,J=w.VK_B.wc,K=w.VK_G.wc,L=w.VK_F6.wc,M=w.VK_F7.wc,N=w.VK_F12.wc,O=w.VK_HOME.wc,P=w.VK_END.wc,Q=w.VK_PAGE_UP.wc,R=w.VK_PAGE_DOWN.wc,S=w.VK_HOME.wc,T=w.VK_END.wc,U=w.VK_PAGE_UP.wc,V=w.VK_PAGE_DOWN.wc,W=w.VK_L.wc,X=w.VK_J.wc,Y=w.VK_K.wc,Z=w.VK_M.wc,$=w.VK_CAPS_LOCK.wc,_=w.VK_N.wc,aa=w.VK_H.wc,ba=w.VK_W.wc,ca=w.VK_E.wc,da=w.VK_R.wc,ea=w.VK_U.wc,fa=w.VK_I.wc,ga=w.VK_Z.wc,ha=w.VK_ENTER.wc,ia=(w.VK_F11.wc,w.VK_F12.wc),ja=WMSX.SCREEN_RESIZE_DISABLED,ka=new Set([r.MACHINE_LOAD_STATE_FILE,r.MACHINE_SAVE_STATE_FILE,r.MACHINE_LOAD_STATE_MENU,r.MACHINE_SAVE_STATE_MENU,r.MACHINE_SELECT,r.SCREEN_OPEN_MACHINE_SELECT,r.EXTENSION_TOGGLE,r.DISK_LOAD_FILES,r.DISK_ADD_FILES,r.DISK_LOAD_URL,r.DISK_LOAD_FILES_AS_DISK,r.DISK_LOAD_ZIP_AS_DISK,r.DISK_SAVE_FILE,r.DISK_EMPTY,r.DISK_BOOT,r.DISK_SELECT,r.DISK_PREVIOUS,r.DISK_NEXT,r.HARDDISK_LOAD_FILE,r.HARDDISK_LOAD_URL,r.HARDDISK_LOAD_FILES_AS_DISK,r.HARDDISK_LOAD_ZIP_AS_DISK,r.HARDDISK_SAVE_FILE,r.HARDDISK_CHOOSE_EMPTY,r.HARDDISK_CHOOSE_BOOT,r.HARDDISK_NEW,r.CARTRIDGE_LOAD_FILE,r.CARTRIDGE_LOAD_URL,r.CARTRIDGE_LOAD_DATA_FILE,r.CARTRIDGE_SAVE_DATA_FILE,r.CARTRIDGE_CHOOSE_FORMAT,r.TAPE_LOAD_FILE,r.TAPE_LOAD_URL,r.TAPE_SAVE_FILE,r.AUTO_LOAD_FILE,r.AUTO_LOAD_URL]),la=new Set([r.DISK_MOVE,r.DISK_INSERT,r.DISK_REMOVE,r.HARDDISK_REMOVE,r.CARTRIDGE_REMOVE,r.TAPE_EMPTY,r.TAPE_REWIND,r.TAPE_TO_END,r.TAPE_SEEK_FWD,r.TAPE_SEEK_BACK,r.TAPE_REMOVE]),ma=new Set([r.SCREEN_ASPECT_PLUS,r.SCREEN_ASPECT_MINUS,r.SCREEN_SCALE_PLUS,r.SCREEN_SCALE_MINUS,r.SCREEN_FULLSCREEN,r.SCREEN_CRT_FILTER,r.SCREEN_CRT_SCANLINES,r.SCREEN_CRT_PHOSPHOR,r.SCREEN_TOGGLE_MENU,r.SCREEN_OPEN_HELP,r.SCREEN_OPEN_ABOUT,r.SCREEN_OPEN_SETTINGS,r.SCREEN_OPEN_QUICK_OPTIONS,r.SCREEN_OPEN_TOUCH_CONFIG,r.SCREEN_TOGGLE_VIRTUAL_KEYBOARD,r.SCREEN_DEFAULTS,r.SCREEN_OUTPUT_AUTO,r.SCREEN_OUTPUT_INTERNAL,r.SCREEN_OUTPUT_EXTERNAL,r.SCREEN_OUTPUT_SUPERIMPOSED,r.SCREEN_OUTPUT_MIXED,r.SCREEN_OUTPUT_DUAL,r.SCREEN_OUTPUT_TOGGLE,r.SCREEN_OUTPUT_RESET_AUTO,r.SCREEN_COLORS,r.SCREEN_PALETTES,r.SPEAKER_BUFFER_TOGGLE,r.MACHINE_POWER_TOGGLE,r.MACHINE_POWER_RESET,r.KEYBOARD_TOGGLE_HOST_LAYOUT,r.JOYSTICKS_TOGGLE_MODE,r.JOYKEYS_TOGGLE_MODE,r.TOUCH_TOGGLE_MODE,r.TOUCH_TOGGLE_DIR_BIG,r.TOUCH_TOGGLE_MIRRORED,r.HAPTIC_FEEDBACK_TOGGLE_MODE,r.TURBO_FIRE_TOGGLE,r.COPY_STRING,r.OPEN_PASTE_STRING,r.OPEN_ENTER_STRING,r.CAPTURE_SCREEN,r.SCREEN_OPEN_NETPLAY]);!function(){e()}()},wmsx.NetServer=function(a){"use strict";function b(){void 0===v&&(v=setInterval(p,3e4));var a={sessionControl:"createSession",sessionType:wmsx.NetServer.SESSION_TYPE_VERSION,wsOnly:D,queryVariables:["RTC_CONFIG","RTC_DATA_CHANNEL_CONFIG"]};u&&(a.sessionID=u),s.send(JSON.stringify(a))}function c(){r.stopSession(!0,v?"NetPlay Session stopped: Connection lost":"NetPlay: Connection error")}function d(a){var b=JSON.parse(a.data);if(b.wmsxUpdate){var c=E[a.clientNick];return void(c&&o(c,b.wmsxUpdate))}if(b.sessionControl)switch(b.sessionControl){case"sessionCreated":return void e(b);case"clientJoined":return void f(b);case"clientLeft":return void g(b);case"createError":return void r.stopSession(!0,"NetPlay: "+b.errorMessage)}else b.clientSDP&&h(b)}function e(b){try{G=JSON.parse(b.queriedVariables.RTC_CONFIG||"{}")}catch(a){}try{H=JSON.parse(b.queriedVariables.RTC_DATA_CHANNEL_CONFIG||"{}")}catch(a){}t=b.sessionID,x.netClearControlsToSend(),y.netClearMatrixChangesToSend(),z.netClearInfoToSend(),z.netServerClearClientsMergedInfo(),A.netClearControlsToSend(),F.length=0,a.enterNetServerMode(r),a.showOSD('NetPlay session "'+b.sessionID+'" started',!0),wmsx.Util.log('NetPlay session "'+b.sessionID+'" started')}function f(b){var c={nick:b.clientNick,justJoined:!0,wsOnly:D||!!b.wsOnly};if(E[c.nick]=c,a.showOSD('NetPlay client "'+c.nick+'" joined',!0),wmsx.Util.log('NetPlay client "'+c.nick+'" joined'),!c.wsOnly){var d=new RTCPeerConnection(G);c.rtcConnection=d,d.onicecandidate=function(a){a.candidate||(wmsx.Util.log("Server SDP for client "+c.nick+":",d.localDescription),s.send(JSON.stringify({toClientNick:c.nick,serverSDP:d.localDescription})))};var e=d.createDataChannel("dataChannel",H);c.dataChannel=e,e.onopen=function(a){i(c,a)},e.onclose=function(a){j(c,a)},e.onmessage=function(a){k(c,a)},d.createOffer().then(function(a){return d.setLocalDescription(a)}).catch(function(a){l(c,a)})}}function g(a){var b=E[a.clientNick];b&&n(b,!0,!1,'NetPlay client "'+b.nick+'" left')}function h(a){var b=E[a.fromClientNick];b&&(wmsx.Util.log("Client SDP from client "+b.nick+":",a.clientSDP),b.rtcConnection.setRemoteDescription(new RTCSessionDescription(a.clientSDP)).catch(l))}function i(a,b){wmsx.Util.log("Client "+a.nick+" dataChannel open"),a.dataChannelActive=!0}function j(a,b){wmsx.Util.error("NetPlay Client "+a.nick+" dataChannel closed"),n(a,!0,!0,'NetPlay client "'+a.nick+'" dropped: P2P connection lost')}function k(a,b){o(a,JSON.parse(b.data))}function l(a,b){wmsx.Util.error("NetPlay Client "+a.nick+" RTC error:",b),n(a,!0,!0,'NetPlay client "'+a.nick+'" dropped: P2P connection error')}function m(){for(var a in E)n(E[a],!1)}function n(b,c,d,e){c&&(a.showOSD(e||'NetPlay client "'+b.nick+'" left',!0,d),(d?wmsx.Util.error:wmsx.Util.log)(e||'NetPlay client "'+b.nick+'" left')),b.dataChannel&&(b.dataChannel.onopen=b.dataChannel.onclose=b.dataChannel.onmessage=void 0,b.dataChannel.close()),b.rtcConnection&&(b.rtcConnection.onicecandidate=void 0,b.rtcConnection.close()),delete E[b.nick]}function o(a,b){b.c&&x.netServerProcessControlsChanges(b.c),b.k&&y.netServerProcessMatrixChanges(b.k),b.pc&&A.netServerProcessControlsChanges(b.pc),b.ch&&z.netServerReceiveClientInfo(a,b.ch)}function p(){try{s.send('{ "sessionControl": "keep-alive" }')}catch(a){wmsx.Util.error("NetPlay error sending keep-alive"),r.stopSession(!0,"NetPlay Session stopped: connection error")}}function q(a,b){var c=b.length;if(c<I)return a.send(b);for(var d=0,e=0;;){var f=b.substr(e,J);if(e+=J,d++,!(e<c))return void a.send(L+f);a.send(K+f)}}var r=this;this.startSession=function(e){u=e?(""+e).trim():void 0;var f;u&&"@"===u[u.length-1]?(u=u.substr(0,u.length-1),f=!0):f=!1,u&&t===u&&D===f||(t&&this.stopSession(!0),a.enterNetPendingMode(this),D=f,s?b():(s=new WebSocket("wss://"+WMSX.WEB_EXTENSIONS_SERVER),s.onmessage=d,s.onopen=b,s.onclose=c))},this.stopSession=function(b,c){clearInterval(v),v=void 0,s&&(s.onmessage=s.onopen=s.onclose=void 0,s.close(),s=void 0),b?m():setTimeout(m,300),a.showOSD(c||'NetPlay Session "'+t+'" stopped',!0,b),(b?wmsx.Util.error:wmsx.Util.log)(c||'NetPlay Session "'+t+'" stopped'),t=void 0,a.enterStandaloneMode()},this.getSessionID=function(){return t},this.netVideoClockPulse=function(){z.controllersClockPulse();var b,c,d,e;for(var f in E){var g=E[f];if(g.wsOnly||g.dataChannelActive){if(g.justJoined||C){if(g.justJoined=!1,!c){e=w.systemPause(!0);var h={vf:a.mainVideoClock.getVSynchNativeFrequency(),s:w.saveState(!0),ks:y.saveState(),cm:z.netServerGetControlsModes(),ch:z.netServerGetFullInfo()};c=JSON.stringify(h)}b=c}else d||(B.c=x.netGetControlsToSend(),B.k=y.netGetMatrixChangesToSend(),B.ch=z.netGetInfoToSend(),B.pc=A.netGetControlsToSend(),B.po=F.length?F:void 0,d=JSON.stringify(B)),b=d;try{g.dataChannelActive?q(g.dataChannel,b):s.send(JSON.stringify({toClientNick:g.nick,wmsxUpdate:b}))}catch(a){
n(g,!0,!0,'NetPlay client "'+g.nick+'" dropped: P2P error sending data')}}}C=!1,x.netClearControlsToSend(),y.netClearMatrixChangesToSend(),z.netClearInfoToSend(),A.netClearControlsToSend(),F.length=0,w.videoClockPulse(),!1===e&&w.systemPause(!1)},this.addPeripheralOperationToSend=function(a){F.push(a)},this.processExternalStateChange=function(){C=!0};var s,t,u,v,w=a.machine,x=a.machineControls,y=a.keyboard,z=(a.cartridgeSlot,a.controllersHub),A=a.peripheralControls,B=(a.diskDrive,a.cassetteDeck,{c:void 0,k:void 0,cp:void 0}),C=!1,D=!1,E={};this.clients=E;var F=new Array(10);F.length=0;var G,H,I=16300,J=16200,K="#@FrgS@#",L="#@FrgE@#"},wmsx.NetServer.SESSION_TYPE_VERSION="wmsx600",wmsx.NetClient=function(a){"use strict";function b(){void 0===w&&(w=setInterval(o,3e4)),r.send(JSON.stringify({sessionControl:"joinSession",sessionType:wmsx.NetServer.SESSION_TYPE_VERSION,sessionID:t,clientNick:v,wsOnly:I,queryVariables:["RTC_CONFIG"]}))}function c(){q.leaveSession(!0,w?"NetPlay session ended: Connection lost":"NetPlay: Connection error")}function d(a){var b=JSON.parse(a.data);if(b.wmsxUpdate)return m(JSON.parse(b.wmsxUpdate));if(b.sessionControl)switch(b.sessionControl){case"sessionJoined":return void e(b);case"sessionDestroyed":return void q.leaveSession(!1,'NetPlay Session "'+s+'" ended');case"joinError":return void q.leaveSession(!0,"NetPlay: "+b.errorMessage)}else b.serverSDP&&g(b)}function e(a){if(s=a.sessionID,u=a.clientNick,K=I||a.wsOnly,J=!0,K)return f();try{x=JSON.parse(a.queriedVariables.RTC_CONFIG||"{}")}catch(a){}y=new RTCPeerConnection(x),y.onicecandidate=function(a){a.candidate||r.send(JSON.stringify({clientSDP:y.localDescription}))},y.ondatachannel=function(a){z=a.channel,z.onopen=h,z.onclose=i,z.onmessage=j}}function f(){a.showOSD('NetPlay Session "'+s+'" joined as "'+u+'"',!0),wmsx.Util.log('NetPlay Session "'+s+'" joined as "'+u+'"'),B.netClearControlsToSend(),C.netClearMatrixChangesToSend(),D.netClearInfoToSend(),E.netClearControlsToSend(),a.enterNetClientMode(q)}function g(a){y.setRemoteDescription(new RTCSessionDescription(a.serverSDP)).then(function(){return y.createAnswer()}).then(function(a){return y.setLocalDescription(a)}).catch(k)}function h(a){L=!0,M="",f()}function i(a){wmsx.Util.error("NetPlay dataChannel closed"),q.leaveSession(!0,"NetPlay session ended: P2P connection lost")}function j(a){var b=p(a);b&&m(JSON.parse(b))}function k(a){wmsx.Util.error("NetPlay RTC error:",a),q.leaveSession(!0,"NetPlay session ended: P2P connection error")}function l(){z&&(z.onpen=z.onclose=z.onmessage=void 0,z.close(),z=void 0),y&&(y.onicecandidate=y.ondatachannel=void 0,y.close(),y=void 0)}function m(b){D.controllersClockPulse();var c={c:B.netGetControlsToSend(),k:C.netGetMatrixChangesToSend(),ch:D.netGetInfoToSend(),pc:E.netGetControlsToSend()};if(L?z.send(JSON.stringify(c)):r.send(JSON.stringify({wmsxUpdate:c})),B.netClearControlsToSend(),C.netClearMatrixChangesToSend(),D.netClearInfoToSend(),E.netClearControlsToSend(),b.s){var d=A.systemPause(!0);a.mainVideoClock.setVSynchAltNativeFrequency(b.vf),A.loadState(b.s),C.loadState(b.ks),J&&(D.netClientAdaptToServerControlsModes(b.cm),J=!1),D.netClientReceiveServerInfo(b.ch),A.systemPause(d)}else b.c&&B.netClientApplyControlsChanges(b.c),b.k&&C.netClientApplyMatrixChanges(b.k),b.ch&&D.netClientReceiveServerInfo(b.ch),b.pc&&E.netClientApplyControlsChanges(b.pc),b.po&&n(b.po);A.videoClockPulse()}function n(a){for(var b=0,c=a.length;b<c;++b){var d=a[b];switch(d.op){case 0:F.insertSerializedCartridge(d.c,d.p,d.a);break;case 1:F.loadSerializedCartridgeData(d.p,d.n,d.c);break;case 10:G.loadSerializedStack(d.d,d.s,d.t,d.p,d.a);break;case 11:G.insertNewDisk(d.d,d.m,d.b,d.u);break;case 12:G.replaceCurrentDiskSerialized(d.d,d.k);break;case 20:H.loadSerializedTape(d.n,d.c,d.p)}}}function o(){try{r.send('{ "sessionControl": "keep-alive" }')}catch(a){wmsx.Util.error("NetPlay error sending keep-alive"),q.leaveSession(!0,"NetPlay session ended: Connection error")}}function p(a){var b=a.data,c=b.substr(0,8);return c!==N&&c!==O?(M="",b):(M+=b.substr(8),c===O?(b=M,M="",b):void 0)}var q=this;this.joinSession=function(e,f){if(!(t=(""+e).trim()))return a.showOSD("Must enter Session Name for joining NetPlay session",!0,!0);var g;"@"===t[t.length-1]?(t=t.substr(0,t.length-1),g=!0):g=!1,v=f,I=g,s===t&&u===v&&K===I||(s&&this.leaveSession(!0),a.enterNetPendingMode(this),r?b():(r=new WebSocket("wss://"+WMSX.WEB_EXTENSIONS_SERVER),r.onmessage=d,r.onopen=b,r.onclose=c))},this.leaveSession=function(b,c){clearInterval(w),w=void 0,s=u=void 0,K=!1,r&&(r.onpen=r.onclose=r.onmessage=void 0,r.close(),r=void 0),z&&(z.onpen=z.onclose=z.onmessage=void 0),y&&(y.onicecandidate=y.ondatachannel=void 0),L=!1,M="",b?l():setTimeout(l,300),a.showOSD(c||"NetPlay session ended",!0,b),(b?wmsx.Util.error:wmsx.Util.log)(c||"NetPlay session ended"),a.enterStandaloneMode()},this.getSessionID=function(){return s},this.netVideoClockPulse=function(){},this.processExternalStateChange=function(){a.screen.quickOptionsControlsStateUpdate()};var r,s,t,u,v,w,x,y,z,A=a.machine,B=a.machineControls,C=a.keyboard,D=a.controllersHub,E=a.peripheralControls,F=a.cartridgeSlot,G=a.diskDrive,H=a.cassetteDeck,I=!1,J=!1,K=!1,L=!1,M="",N="#@FrgS@#",O="#@FrgE@#"},wmsx.Room=function(a,b){"use strict";function c(a){var b=WMSX.AUTO_POWER_ON_DELAY;b>=0&&WMSXFullScreenSetup.shouldStartInFullScreen()&&(b+=1400),b-=Date.now()-i,b<1&&(b=1),setTimeout(a,b)}function d(){b&&h.machine.userPowerOn(!0)}function e(){h.mainVideoClock=new wmsx.Clock(h.mainVideoClockPulse)}function f(){h.peripheralControls=new wmsx.DOMPeripheralControls(h),h.machineControls=new wmsx.DOMMachineControls(h,h.peripheralControls),h.controllersHub=new wmsx.ControllersHub(h,h.machineControls),h.keyboard=h.controllersHub.getKeyboard(),h.fileDownloader=new wmsx.FileDownloader,h.stateMedia=new wmsx.SaveStateMedia(h),h.cartridgeSlot=new wmsx.FileCartridgeSlot(h),h.cassetteDeck=new wmsx.FileCassetteDeck(h),h.diskDrive=new wmsx.FileDiskDrive(h),h.fileLoader=new wmsx.FileLoader(h),h.screen=new wmsx.CanvasDisplay(h,a),h.speaker=new wmsx.WebAudioSpeaker(a),h.fileLoader.connectPeripherals(h.screen,h.peripheralControls,h.cartridgeSlot,h.cassetteDeck,h.diskDrive),h.fileDownloader.connectPeripherals(h.screen),h.screen.connectPeripherals(h.cartridgeSlot,h.fileLoader,h.fileDownloader,h.machineControls,h.peripheralControls,h.controllersHub,h.diskDrive,h.stateMedia),h.speaker.connectPeripherals(h.screen),h.machineControls.connectPeripherals(h.screen),h.controllersHub.connectPeripherals(h.screen),h.stateMedia.connectPeripherals(h.fileDownloader),h.cartridgeSlot.connectPeripherals(h.fileDownloader),h.cassetteDeck.connectPeripherals(h.screen,h.fileDownloader),h.diskDrive.connectPeripherals(h.screen,h.fileDownloader),h.peripheralControls.connectPeripherals(h.cartridgeSlot,h.machineControls,h.screen,h.speaker,h.controllersHub,h.fileLoader,h.cassetteDeck,h.diskDrive)}function g(){h.machine=new wmsx.Machine,h.mainVideoClock.connect(h.machine.getVideoClockSocket()),h.stateMedia.connect(h.machine.getSavestateSocket()),h.fileLoader.connect(h.machine),h.screen.connect(h.machine),h.speaker.connect(h.machine.getAudioSocket()),h.machineControls.connect(h.machine.getMachineControlsSocket()),h.controllersHub.connect(h.machine.getMachineTypeSocket(),h.machine.getMachineControlsSocket(),h.machine.getControllersSocket(),h.machine.getBIOSSocket()),h.cartridgeSlot.connect(h.machine.getCartridgeSocket(),h.machine.getExtensionsSocket()),h.cassetteDeck.connect(h.machine.getCassetteSocket()),h.diskDrive.connect(h.machine.getDiskDriveSocket()),h.peripheralControls.connect(h.machine.getMachineTypeSocket(),h.machine.getExtensionsSocket(),h.machine.getCartridgeSocket()),h.machine.socketsConnected()}var h=this;this.powerOn=function(){h.screen.powerOn(),h.speaker.powerOn(),h.controllersHub.powerOn(),h.setLoading(!0),h.enterStandaloneMode(),i=Date.now()},
this.powerOff=function(){h.machine.powerOff(),h.controllersHub.powerOff(),h.speaker.powerOff(),h.screen.powerOff()},this.setLoading=function(a){this.isLoading!==a&&(this.isLoading=a,this.machine.setLoading(this.isLoading),this.screen.setLoading(this.isLoading))},this.start=function(a){this.mainVideoClock.detectHostNativeFPSAndCallback(function(b){h.machine.vSynchSetSupported(b>0),h.machine.preStart(),c(function(){h.setLoading(!1),h.screen.start(a||d)})})},this.showOSD=function(a,b,c){this.machine.showOSD(a,b,c)},this.mainVideoClockPulse=function(){h.machine.isSystemPaused()||(h.netController?h.netController.netVideoClockPulse():(h.controllersHub.controllersClockPulse(),h.machine.videoClockPulse()))},this.enterStandaloneMode=function(){var a=this.netPlayMode;this.netPlayMode=0,this.netController=void 0,this.mainVideoClock.setVSynchAltNativeFrequency(void 0),h.mainVideoClock.go(),this.netPlayStateBeforeClientMode&&(this.machine.loadState(this.netPlayStateBeforeClientMode),this.controllersHub.netClientRestoreControlsModes(this.netPlayControlsModesBeforeClientMode),this.netPlayStateBeforeClientMode=this.netPlayControlsModesBeforeClientMode=void 0),a!==this.netPlayMode&&(this.screen.roomNetPlayStatusChangeUpdate(a),this.controllersHub.roomNetPlayStatusChangeUpdate(a))},this.enterNetServerMode=function(a){var b=this.netPlayMode;this.netPlayMode=1,this.netController=a,this.mainVideoClock.setVSynchAltNativeFrequency(void 0),h.mainVideoClock.go(),b!==this.netPlayMode&&(this.screen.roomNetPlayStatusChangeUpdate(b),this.controllersHub.roomNetPlayStatusChangeUpdate(b))},this.enterNetClientMode=function(a){var b=this.netPlayMode;this.netPlayMode=2,this.netController=a,h.mainVideoClock.pause(),this.netPlayStateBeforeClientMode=this.machine.saveState(!0),this.netPlayControlsModesBeforeClientMode=this.controllersHub.netClientGetControlsModes(),b!==this.netPlayMode&&(this.screen.roomNetPlayStatusChangeUpdate(b),this.controllersHub.roomNetPlayStatusChangeUpdate(b))},this.enterNetPendingMode=function(a){var b=this.netPlayMode;this.netPlayMode=a===this.netServer?-1:-2,this.netController=void 0,h.mainVideoClock.go(),b!==this.netPlayMode&&(this.screen.roomNetPlayStatusChangeUpdate(b),this.controllersHub.roomNetPlayStatusChangeUpdate(b))},this.getNetServer=function(){return this.netServer||(this.netServer=new wmsx.NetServer(this)),this.netServer},this.getNetClient=function(){return this.netClient||(this.netClient=new wmsx.NetClient(this)),this.netClient},this.mainVideoClock=null,this.machine=null,this.screen=null,this.speaker=null,this.machineControls=null,this.controllersHub=null,this.keyboard=null,this.fileDownloader=null,this.cartridgeSlot=null,this.cassetteDeck=null,this.diskDrive=null,this.stateMedia=null,this.fileLoader=null,this.peripheralControls=null,this.netPlayMode=0,this.netController=void 0,this.netServer=void 0,this.netClient=void 0,this.netPlayStateBeforeClientMode=void 0,this.netPlayControlsModesBeforeClientMode=void 0,this.isLoading=!1;var i;this.runFramesAtTopSpeed=function(a){this.mainVideoClock.pause();for(var b=wmsx.Util.performanceNow(),c=0;c<a;c++)h.mainVideoClockPulse();var d=wmsx.Util.performanceNow()-b;wmsx.Util.log("Done running "+a+" frames in "+(0|d)+" ms"),wmsx.Util.log((a/(d/1e3)).toFixed(2)+"  frames/sec"),this.mainVideoClock.go()},function(){e(),f(),g(),WMSX.userROMFormats.init()}()},wmsx.Images.embedded=!0,
wmsx.Images.urls.logo="data:image/png;base64, ",
wmsx.Images.urls.sprites="data:image/png;base64, ",
wmsx.Images.urls.loading="data:image/gif;base64, ",wmsx.Images.urls.mouseCursor="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABL0lEQVRYw+3VP0oDQRTH8U8k+AcFFRUFERGLiFjEA1jZTo6RG6T3ArmFR9j0WlpaWBiwsNNyiwgW0Vg4CUPELhMt9guPffumeG9nf/MbvlnEYVmWo3a7PcIO1s2R3aT5KQ6wMo/GC/G5nNTWsYr6PHdgE+fJLjRxhFqMbNSxFr96K6nvYxhr7zE+Y8yUWghhNH5pNBr6/f5ksdfrXeA1xiCbBoqiUBSF6RwN7GIptwh/4wR7UyKduQZ0Op1JIc2xHTVSzzpAt9v9sdBqtczTB/6Mfz/A2AOGOYe4DCGMUqI33OAKl1MmNVsjwhmaIYTrxIBu8YA73OMZb7kG2MFhPPPH2ECJJzzG5iU+ch3DMvnfL/HcDxILztZcctPVo9stxXyYCPBDRUVFRUVFRUa+AB+1YCivg1lPAAAAAElFTkSuQmCC",
wmsx.Images.urls.logoMiniBrightBack="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAOCAYAAABU4P48AAAGXklEQVRIx9VWbUyUVxZ+3vedd2YYvmYQhrF8CNuCWMoKgqhp7a7rtutC9gOMrtnEuEZ0daHaWLtsqV2DGnaTkqbJbsq2dmti2ZZ1I2m0mHZr1JKCgDUja3EHbEUHBDowMzAM77xf9579USQ0Xfu/z697T87JeXKec8+5wDyovk7AdwALJB+y2zznH13+53yb9YdDmuabMM1geVzcSgD66ZlIX1VyYplEcN5QtXMb/nPz6AsNDT/du3t3Y1RR2OXLl9+sra39e1NT07YtW7Y8p2ma0tvbe2rXrl1v1NfXL9m0adNOl8tVQUSJRPSNwlgsFkHX9etlZWUvAPi8qrq69NixY81zipIhybLR1dn52oH9+98AYCwEpduseZ8UP3aXNjxO9ORaaitcrtD6NUQb19OLuctC9EQ50ZPr6JPvr1DswI6ujo4hmkdbW9ssgOozZ84MLLJFAez0er2fRqNR4pzTt0HVdXrx8OELAFb++8KFTkXXyeCMLnZ2stzc3JMAkgHAstASwGSfonz6eGJCNqwy/quqDIybAFmSJFEeVzVjqc0mF1jlOAmoWF5cnHU/trS0NAHAz0pKSpbdt7ndbltFRcVv8/PzVzkcDszMzCAcDkOSpK/yEYFxDkEU4Xa7YbPb8btnntmY7HS2lZSVPgJRxNj4BPbu2X1reHj4PQCzXyMc0PTI9ahyCamsGpBRYLdbhnWd51ok/CIx3n4+MhvblSLJSyDgEZtclux22+7HZmZmoqioaH1WVpZjQbH0dLGqqmqFIAiIxWKoq6sLt7a2Xnc6nZosy9bUtLQ4q9UqK4oi76utza3Zsycp0ZWMnTU1BVa7Haqm4bmDB0NDvsF/AOgAwL/Rz9sf8vx8ZHXxLP1gHU2WF7PWFXlztLaUaF0Z/TItJUDlJeR/OJs3bK6OMMYW5DQMg1pbW9XFEkejUWpvb4+Njo6ajHPyj4ywkdFRYyIQ0L/w+8NHjx9/CUA+AJcrJeXAlatXI+FYjEKKQpNzc9TU3KwAeBuAazFJcdGZhmMxf38sdhemiVSLLA7MKYwxRiCOBFGUpzSdfzgeMNY89WOrIAgL0kqShK1bt9oAgHMOToT4+HjMzEZw4eJFDYKArMxMMSMjw5KaliZ7PB5n3bPPHn2psfFlACwcCr17x++fMBiDbhpQNR3nOzoiAF4BEF5MWFp88atabHVi4tq1cfZCcEK/qrJMi0VyioKoEYm3NUO/EQxT8aHnxWU5OVIwGCSv18uzs7NFUZLAGMOAz8dNk8MR7xCC4WnzWGNjt9frjQVCodSbPp/g8/koyeWCIyFBSExKyj154sTEn1599emfVFZWQhRFDgEEwqqysoSLH300NjM9/fGDKgwAc1PMGA7oBgPnKLBZZW9MNWcNExtsdus/A5NznuV5lJGdLRKA28O3WUtLyywAmIxBN0309fbq3b1X9JiuY1lurjXd42EnXn/9ZM2OHU3bt207XLdv3+mbgz5NNXTEJyVKss32602VlTUWq9Wi6ToGBwe5SYTMnBw0t7Q0AFjzbYTZQDT22eeqGjFMEx5BFHyqasYYgygAgZimi48VTqemp0uMc/T2XlXujvgDkZhCBufQdB09PVdCPd3dk7phkNvjEf919uzTM4bRPG0Yh0OqevzW2NivVpevsYsWGT09vWzvgf2Ppi1dmkaCgO6uLmNjefngtb6+WYMx5BcW2pr+8te3AXzvQYTpvalQr183IhYixAOSSGSZZQzgHCs5t4dXrlKS4uIESRTx/vvngpOTU9dD4WkmyzKmIxH4Boe+vOv3+yFJgmCxwCSCwRgM04RJBN0wYImLw8eXLuHmwADVHznihCDgzp072L558xCAP7x76tTpYCgMm92O9Rt/lPeb2tojAJK+NtYW4YvOqPK3rrm5gxGTOyYMwz8QUxMMw1xyi3M1u79//OChQ6mqpskffvBBH4CXT771luve2NgTwclJpauzs6uwqOhy09GjSVPBYB6IOM0/TgIgiCL1X7sWueH1jhxoaHD88fnfZ5imaT/X3j4Kzl8DcLb9nXe8nOC02W0VhmkI46P3Sm0Ox8Oaongf9H+Q52VIBzADQAGQBoABCAJIAWADcA/AbQBOAEXzq9MP4EsAHgA5/0dFAJiGIHwGIjeAgq/2FmYA9C/yibs/9ubz+wFM4LuG/wFQqng3L3GLVwAAAABJRU5ErkJggg==",wmsx.Images.urls.muteIcon="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAoCAYAAAC4h3lxAAAEwklEQVRYw+2YbWhbZRTH/+fJTdLbuHWsVTc6cK2DtDcJK2GsbAzpUNEPgjAUZYgyFXUZ8wVxm+ua2bjCuo19UDZQRFQCgkw3/CgMi9M6i9Q1uUntRsigww6duOFi3tr790smMaTvXbLq/t+S53Dv+T3nPOc55wK39R9UOp22DQ4OLq/Eu9RCP9A0zVXJZLK7pqbm8UUHEI/H7xeRd0juAVBXCQBtIR6SSCRqM5nMswACAFoAsFLpqi1AyhjZbDYAYBuAWhEByYoBzDmFOjs7VTQa3SIi75IMiEhtNQrGnCJw7ty5ervd/hKA7SLSWM2KN2uAWCy2QUQCJJ8UEQ1Vllamhkvxb13XCQD9/f32ZcuWPWVZ1g4AfhGRub50cHDwDpfLNe52uzMzsR8ZGVnhdrsvl1v7lxORSKTJZrO9CGApAJC8PD4+fkzTtOsishfAKyIybXkkaYnIm4ZhHCpz6O9USnWRTGWz2R6/3399mog/TPIZACe8Xu/nU0ZA07R6AM+RrAcAEbmgadqHTqeTuVzuoZk4P93ZAdBFcgeACYfDwYGBgZ7169enJqlwD4pIUEQ2kPTE43HLMIyT01YhKagkQjIf503TdDocjh1KqYCIKBGxi8jrLpdrT39/f+0kl2IQwIaCTz6SwVgs5r+prcRk8nq9WcuyRi3L+qVooxwA3qirq9vd19enF6VNB8mgiGwqSksCMEn+uuA38SwgPopGoxrJ/TfKr4g4Se5qaGiwTNM8SLK9sPP3FTuvlPqUZMjj8VyqGgAArlmz5oNkMqkKECsLEDUisgvAKgD3Athc7DzJz0Qk1NraeuGm9EKzka7rTKfT71+8eFFZlrVfRO4uLNWS3CYitmLnReQEyVBLS8tIRdrpmUKEw+H3ABwA8FvRmbCV5PxJACGv1xuv2DwwU/X09FjNzc3HAXwMIFeucGma9rZhGGZFB5pZtuFrSbYAcJQp5ffk8/nN6XRa3ZIA0Wh0LYD9IvLIJCZLRWRfIpHY2dnZqW4pgKGhIZ9SKqiUerSkBTlPMlUUheUism/r1q2B0h6tagCmaRqapgVFZEvJ0leWZT1P8gCAP4sgGgB0JRKJ7eUgKgoQiURalFJBEXmsZOdPAwj5fL4zuVzu6MTERG9JJO4Ska5kMvlCaUtTMYBkMulSSj0N4ImSpa+VUt2GYXwHAH6/PyciR0geIpkuglhBcq9pmu1VAWhqakqJyFkAPxXt/DckQ62trWdK+6YrV64cBnCYZKZgOwHgi1Qq9fNUACR5meQYyTERGSv5f17Dusfj+ZJkiGSE5Lci0u3xePrK2XZ0dKSvXbvWC+BIIRLH8vn8gfb29quTthKjo6NDjY2N/4TYsiz6fL5LhcN3FECO5BYRUfOAOBWLxa4CyBqG8f1Uths3bvxrYGDg4JIlS37I5/Nn29rafp9yIpvBQLLSbrcHCsN8/Vwmsqp+Vmlraxtrbm5+i+SrAM5W8vvPgl1kuq5PeL3eMICdJD8BkF9UADdkGMaPmUzmtcLwMbroAABg3bp1f6xevbqX5MskT1cjpeZ9D+i6To/Hc0rTtJ0icrz48lkUADfkdruHnU7nLgC7AZzHYtbw8PADkUhk06KGCIfDNtzW/0B/A2/7MX7SZ6/PAAAAAElFTkSuQmCC",wmsx.CompressedSystemFiles={
"cbios_main_msx1.rom":" ",
"cbios_main_msx1_jp.rom":" ",
"cbios_main_msx2.rom":" ",
"cbios_main_msx2_jp.rom":" ",
"cbios_main_msx2+.rom":" ",
"cbios_main_msx2+_jp.rom":" ",
"cbios_logo_msx1.rom":"7ZPLb9xUFMavyQA2iw7sZiRkp4hVJFCVHdUolmBRIYEqgdQVKzYss81iFHtooDwurYf3K4T3+1EI5VkKDQwhwPAolDcUkylSGxa2ZmMky+U7vtczHqt/AIvzU+xzz7nfecz1zVWXXXn17uunr5m/aX76ut3XnunPi7lzZ08PZ7eG/RvFzCX/GmJqTvT3CEOc098ljKkVetcE3jtPDf+unw927TyN1UFDmDMbQ0hnLkVWzdoydkxtP+z3b1ABw9qaqQkL9SiyMRxJ/tmrAhcJo0ndYiqBxkvC2tp+8b7zLuidPG40BEShMY1YCMc6euGpDTFBltDjeHi7kzvOeJVkxdJzojwrTSLH9cZV4Iu8SrnAOE14rpOkE26kMzPUKRXK0qJuAiLgABeQr+IqWKQU/ki7fgLBaDw+adQ8mMBzM5CmabvQC5Em6JlRQoTWTkraKFFjOlGGWl47TVzMSRQ1C7+Yz9V7SM1pt1qtdeDYm5tkcUQRCYtj0DJF5lVO33PGfVx3EdBxoNMi1aLZyS4sLLTz3uo88buSSJ0bhkpEhUz3TdsENfE8t9w396nXZFqKWbKIvnHrgONR7xXQXlz0NufwXfJTjeZoVJ1BJ0jfNUviVkSf0yvFcZR03vhd9M2SlEyCIpXrUbk8I0/1yBJ34gKWbmRauqyltGLl5Nl4R5XrKrwK1ePLsSx6gsDCyzor2M+3tTwwQBN0u92RpktOt9k0ShT+SKD1Or9b9O9WCjV1GadCDChuQmYGQZBbPB3kdJBUaPCq12HqgPRknbwgNmmjVI8sdaI1suoxeWrh6BFiLY39IPAD36e+pmWaVqPZbDQbjWasUbUMI67MrNNHGqWCroKKqpmptWlSG9OK4xB/IXJthyz5jo21thSHjfMkHY9DWGeyYr1u676qHmr7hKnBVoMIwTZA2tzaNvwwx6YHhNraKryNPMhtnUc21Bk27YSVOAWL3mjZIUxT3QiE4CE4mitXmPpaNdS70WnkOQWdPIc2x3Wofl6PfqpZAhtCLGlhrfhXqFXQYd/v3Lx36ZZb9/kVbrv9jjvlXfsPBLLMZvfue+6V991P6wdK8cGDDz0s5SOPLj+28vgTTz61/PQzzy4DOXju+RekfPElKV9+5dXXpDz4+hurq6tvysGhQ8h6C8/b77z7npTvH/7gyJEPP5KDo2sfS/lJr/fp+mcbn3/xZf+rXq/39Tdy8O3aMXkWBt99f/yHH3/6+ZdfR6E9Oy6fvWLg//b7H2sn/gz/muTkGYZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZh/hf8Bw==","cbios_logo_msx2.rom":"7dR/UBPZHQDwtxAS7amBk9FoFQjxKpyjouEwoIZ6iWL1DjzThLHXkdGYTdW2WmyTqnG/L6T2wCJRQSDe6XmensKd4g13InonMrWnFAMzUk8ziooKGH4IRwQDSd52aTud6x+l0//fZ2d2v+/7ffvd92Z3VjP3zZ9k6eLe2mbeFrc2620+Cl2Vr3S4m/LkCMV3+dQR7hwkt9jdi+3uZUiOGCHn3ojSnvEdkDFpvDsDqcNa5QsYdw7TmBHnu81Ikdxs7z3fxkxE44Ve0ydbu33quBaX+mCLq515XzparW5Tf/bPTEDM91Z/r0OCqLda1sfEodFlWIQ+8vMoviYo34Dia4NqyUKvTz1uYVhAfiPPvcouBG4tEkdGldrlwpM6+rO4jv7ahHFJom8iZWHfRgpD6efW6R3S0aA2QZwUvkTGLB2d9Ll1smJ6FvfvnDCMrBN6CLsUiy2RIXHcv3peiTsulPzi8fILeesVBsVf2ruFOW31Fktkf4OvStjEgRYXcySutzrQkFYVJBFJ47maG+4TSCF7KQSt8gIk7Esh86F/iEWI0QvXfoRmh491jNanMghFMcpwfYRV8luxMWJHRG5ErjhXsl20PWzsulUyVt0qGet+65j9rZKxni9Ux1ifUP2v67dK/tf+rJLv1y/Yv7UP2afkpeQZ8ix5pXmldkPSvIWpyMNg5PG4Zzk8KlHvcdkgp6hJSPLkrJEkTRGSja/+x0kV1nh5snuBo93TftuzcWt975v1wocru+pOctwVcp76jVvnjCaqGuVXPZzCk9Uon9DgkTNIzAh3J40TyfzCtXdL5LDC08AJr1akRPU/Rih0QrMzpcKFJJC8xxiITHMd2XIZXdo7q9hRt4GTVlZeRmGVFTj93HXuU67Q8RmGdVwfjr1j5vYI8bvc40oPKtiC5+zlyiM0z3IvVX4Zyi7IN14qXrNrONjHDnkuvNwwUVV+BM98244CsVCaWjc0acnBfHyromgRM5gTByWuIW4/PnbgR0UEClPfb4PaX3bkl+GHQTjp6vF1x+Sp9l3GOVYYMJKLXYOlmC2GYlhGYmfgc/sWTOmDYCGxVTMFBf4PmWJonuG6ibK9PQS8qR9w9Q3FEPqC2OawKLPNlhINUF/7ATiJPNtqyey/8kZ0Ojw6RR7bDOA0Q7tEtOQmJCh5n42FDL0BBjZpbpJglDfaauRDqSIlmZleDF+mhT9HoIStZP5UGCwJ3Q7VDkLfTubaPuv4TqbpfNouJt0IchX4mrRWtNu8OrvknbKfx8gUlgPXo6oYKdyYrVGT00+gZu1hM3Ryv2ev43VzFDsRAV0rKvV4d91YZw4z6e+jX6ssRugUS1OnrTB8pGAPFs7ZpRdmqUSa/X44ZLjfad7BkqPLy6c9cK40u9rZ9+a28M9aQ/zMpQ1wi93/JGcbCwu6r8xeMuHe2Wbwb15M/Bege10/2w9FfzK6GmVOuKvQLCVl9wMjq79bz2ay8DG55Vq0a3HZM10cefr1fdViEmOUtsLItIdnYuHiuTuhP/Kql8Mce6rAmZjBQu8d0gj9OSPT2ZTTXbsrqqLhvpM/mA3PDXehq4FYjpUAbNbCQOZt9Q6ICTeRO+B/hQyroWYHXDM8OF4HqwjJgqaWj0J76iAxDYIz8NGAd/+8WGgZOJERKit5A/wVKt5bDIEiZeDFrRL8syCIRLztTHLTMR378XJWE14l2/z6pqEspF2xidPAU942IYW/lW3h1XOd1rKzUrjXTOxs+9EAdDvrYdjHD6xsN5UR25nXvPblBh2ZN9B182wwig9w0JG8Ys120M426LtusyRdCv0L+T6SSFp1ri/IJ8O2XH74F+f4oIwcMpEMPjF5up7E/OGnGp7zKov45qlQY0rxurHod7ry3TYm6uS7/NOXfAN0mxbpTXBAqzfrneXRJmIrL24D/7Z9UNf8evCCSV+0dxaWmfS6U3/Vm53kUFWGFp5+qsKP3eDOPRw6rdubIM5vwCltXdNeu27Woj+XZP6Q9xvwgHkjU/ikUMut3fQ3d8EPvup5pN9fdPkIetScBA986HT84G9ADxt7r+HlHTK2acIrXzFBLh2iVDgn2n0pVSNtFMGk68jcxaFFSnj6ELuZ4CJou4cdTyCwFf/qOYTOYlV6H1SvRWfT9gH4YCtWS3no6cTetHRe+BI5zG3iS/lw8OvwydQPvbZ3SHAqPF6FL7m2OLvUXPfhIR5i8PoEQqTw3Xy7CdfzJPYbDubnzcIXv+a5Up4PBvG5xKgjfH9H+ouJBPaIEh2qKh49Mb7gX0TbmxyzsO295Hj0nAOlyPEqVi9Tjv6y4rVYncN527ERP05XJnGflGIFXl+5R1OlTOZG8nGPqnJ1pUMxUunjRm7gzvwpjreQsWqcdnTU5dAhR7IQ+nEfU8f1zN17jHEKTXuNgZH5iPfzFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEVRFEX9f/4O","cbios_logo_msx2+.rom":"7dT/V1PnGQDw90JIdFUDlaPRKSTETqhHRUMxoIbaROlqK9Y04bjuyDQmmbpNixuZGO7zJhkrOCQqCMRWS61WpVXsoRXRVuTMVRkGzoE5zVFUVMDwRSgRDSR57y7bzk73Q9n+gPdzz7n3eZ/nvc9933Pvuer5r/00Qyt9c7t5u3RdxlucO5eZfkuF3XlMFLosW+dw37LLEIrr8aki3FlIhm3ulTb3CiRDDJ9zb0Kpj7kuSJ8y0Z2OVGHtskWMO4tpSpf6bjBiJHvP1n+2g5mMJvK9Zk619PpU0jaXan+bq5P5QDxWrelQff6vTEDI9dd8r0O8oL9GMsBI0dgyMN9HdhbF1QZlG1FcXVAlWuz1qSYsDgvIWu3ud2x84NYgYWRUpU3GP6lrMIPtGqyLn5Ao+DZSEvb3SH4o/sIys0s8FtTFCxPDl0mY5WOTvrBMlc/MYP+T44eR9XwPfpdCYU5kSCj9d89L0kq+5BdOlF22b5Dr5X/p7OXndDTk5EQONvqq+U3sa3Mxh6T9NYHG1OogiUicyNZecx9FcslzPmiXFSJ+X3KJD/1TLEKMjr8OIjQ3fLxjrD6dQSiKUYTrIiyi3woNETsjsiOyhdmiHYIdYePXLaLx6hbRePdbxu1vEY33fL46zvr46g+u3yL6X/uziL5fv2y7b0N2qf1V+y/s2F5pr7TpExcsTkEeBiOPx73A4VEK+islw6y8Nj7Rk7VWlDiNTza9+F8nZVjTxanupY5OT+cNz6ZtDf2vNfAfruSyO9Vxi895GjZtmzeWqG6SXfawck9Gk2xSo0fGICHD3504QSDx89f+rZEjck8jy79agQI1vIpQ6Kh6V/IpFxJBUp4hEJnqOrT1IrqQP6fEUb+RFVdVXURhVadw2pmr7GdskeNzDOvZARx708zm8fG77IMqDyrciuflsxUR6sfZF6q+CmUWFhgulKzNHQkOmJ55zj3fOFlZcQjPfsuGArFQllL/bMqy/QW49VTxEmY4SwqlrmfsXnxk30+KCRSlfNABdb/qKijH94JwzNXn642xK/dcxFkWGDKQ8z3DZdhUAiWwgsTOwmf2LJo2AMEiYq1hCgv9HzEl0DLLdR1levsIeFM+ZBsaSyD0JbHOM6E1HdbkaICGug/BSWSZlpw1g5deiU6D+8fJA6senGboFAmWXYd4BeezmiBdp4ehzerrJBjljbYYuFCKQEFmp5XAV6nhTxAoYBtZOB2GS0M3QnXDMLCLubLHMrGbaT6bmsukGUCmBF+zxoJ2m1dnlr5d/vMYiTxn39WoakYM1+aqVeTEQ6hdd9AM3ezvTVfx+nnyXYiAth2Veby519abw4y6O+g3yhwDdAvFKTNW6T+Wm/YXzcvV8bOUAvVePxzQ3+k27zSRwysrZtx1vm52dZren9/GPW4PcbOXN0Krae/DrO0mWNR7ae6ySbdPt4B/y1LiPwe96wdNg1D8J4OrSeKEW3L1clJ+JzC6+rsNpjUm+IS0upbkLi1/rJWSR9/cUS4lMQZxO4zOuHcyFs6fuRn6I6d8PsKajhc6E9JN0H+TNMFg1uhMU/KJnt2nqqPhjpPbnwlP9Legp5HkHCkF2KKBoTU3VDshJtxIboL/BTKigtqdcEV/t7Ie3iAkA5rbPg7l1UNCKgRn4cMB794FsdA2dDQ9VF76CvhPKTlvCQSKFYGnraX4Z0EQCDjryaTmI1rTJytN6vBqyZaXNz/LQJpVm1k1POKsk5K51swcTjXfaSk/LYbbLcRm6jwcgF5nA4z4uKHXO43lxHryJa9tpV5LFgz1XD8djOICLHQlrVq7AzRz9bqeGyaSJobBxdwASSDtWteX5NMRazY38sszXFBCDhhJOpeQNFNHYv7wjppjvYpirmU61BqTvW4s+J22YreViTr2LvfoOdcIvcYlOiPs0+jMOmdFtJFYK0o6wL99D9S3vBw8Z9QV58/BEqNOe/yvOrOTHKhO18Cjz5T4gRvc2QdDJ7T58cKCRpzc0TPjpatmDfpz6Zofc349HjJvYooeFmnYdZv/5i780dd993V7iy8eQvdbEuGuD52IG34PdLCp/wpe2SUxNU964WsmyKZBlBJnRbsvpKjFTQKYchWZe1i0RAGP7mE3E1wCHbex4yEEtuFfP4HQaaxMG4Cadeh06h4AH2zDKjEHfd3Ym5rG8V8ii9nNXBkXDn4tPpbykdf6NglOhwdv4Auurc4eFdt78BkHMXhDPCFi+G6hzYgbOBL7LQsL7XPw+W84tozjgkF8JiHqEDfYlfZ0MoE8QYJDWc2hh4an3NNoW7NjDra+nxSHnrCgEDhexKoVirFfVpwGq7JYbyc24AdpikT20zIsxxuq8tTViiR2tAD3KatWVznko1U+dvQa7i6Y5ngTGaonaMZGPQ4tciTxoR8PMPVs3/z8I4yTb9pvCIwuRJyfoyiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoiiKoijq//EP",
"cbios_sub.rom":" ","cbios_music[MSXMUSIC].rom":"7dCxSsNQFIDhLC4uXRzcjFRBlzapRVGkcK5FLSQ2pEEdleog1Em6qfgi7r6BD3ClmCE45AkcdHLpUHRSL0Yk0T6B/B+cu5x/OFxR1lgShF478Lzx2/9Lz4v2RfdFX4u+E/0ieko9jWYdSdbV8DE+7Z+ddNfsvTAyv2MvzNXrrrNodw97veMjy3T7xa610/ruXHcp310VO78TSRhl3XK+u/nTtYMsW81nD8UsbDYlkqzbyHevxc7c1gx3s24z382oQhd1IrXlf3W12k/XKKeVZFs1rLQSX5Zv79Pq9Ntz6X3SmRg4aTUerJhnVDKSQA3NxOfJgbowE38AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH75BA==",
"[Nextor16Patch].rom":" ",
"[RAMNormal].rom":"","[RAMMapper].rom":"","[ExtraPSG].rom":"","[SCCExpansion].rom":"","[SCCIExpansion].rom":"","[PACExpansion].rom":"","[MegaRAM].rom":"","[V9990].rom":"","[Empty].rom":"","Disk16MHeader.dat":"e/1vgp9rRIh/kJEBA5MCIwNTAcO6+g/MDBAgIRfm7xPv6cKwZdOtFog6BSM9AwU3xxBDIwUFhQtvg6sPCFYcKFYuEmw4wMd/tvazzSklB0EGRj4pIFuRkUGp74Aigz1IUv0qUOQinwCQPMzAmHHgLAPDYSUHBt/gCBf/YAWF4MhghlFAdwAA","Disk32MHeader.dat":"e/1vgp9rRIh/kJEBA5MAIwNTAUPC/w88DBAgIRfm7xPv6cLwaNqEFog6BSM9AwU3xxBDIwUFhQtvg6sPCFYcKFYuEmw4wMd/tvazzSklB0EGRj4pIFuRkUGp74Aigz1IUv0qUOQinwCQPMzAmHHgLAPDYSUHBt/gCBf/YAWF4MhghlFAdwAA","Disk64MHeader.dat":"e/1vgp9rRIh/kJEBwygYioANiBmB+N9/RpL1hq56jRT/TCyMDExAyPChAa7iL9hUzc0n+mdB1CkY6RkouDmGGJopKChQyQujYMAAAA==","Disk128MHeader.dat":"e/1vgp9rRIh/kJEBwygYioANiBmB+N9/ZpL1hq56jRT/TCyMDExAyPABbCAY/AWbqnmv70kPRJ2CkZ6BgptjiKGZgoIC1TwxCgYIAAA=",
"DOS1Boot.zip":" ",
"DOS2Boot.zip":" ",
"NextorBoot.zip":" "
},wmsx.EmbeddedSystemFiles={embedFiles:function(){for(var a in wmsx.CompressedSystemFiles)wmsx.EmbeddedFiles.embedFileCompressedContent(a,wmsx.CompressedSystemFiles[a]);delete wmsx.CompressedSystemFiles;for(var b in this.fileDiffs)wmsx.EmbeddedFiles.embedFileDiff(b,this.fileDiffs[b])},fileDiffs:{"cbios_main_msx1_eu.rom":{based:"@cbios_main_msx1.rom",diffs:{43:[161],9629:[53]}},"cbios_main_msx2_eu.rom":{based:"@cbios_main_msx2.rom",diffs:{43:[161],4013:[2],9652:[53]}},"cbios_main_msx2+_eu.rom":{based:"@cbios_main_msx2+.rom",diffs:{43:[161],4013:[2],9652:[53]}}}},wmsx.EmbeddedSystemFiles.embedFiles(),wmsx.Configurator={applyConfig:function(a){this.backupOriginalConfig(),this.parseParams(),WMSX.params.CONFIG_URL&&this.applyParam("CONFIG_URL",WMSX.params.CONFIG_URL),WMSX.CONFIG_URL?this.readThenApplyConfigFile(a):this.applyConfigDetails(a)},readThenApplyConfigFile:function(a){var b=this;new wmsx.MultiDownloader([{url:WMSX.CONFIG_URL.trim()}],function(c){b.applyConfigFile(c[0].content,a)},function(a){return wmsx.Util.message(a.errorMessage)}).start()},applyConfigDetails:function(a){if(this.initExtensions(),this.applyPresetsConfigModifications(),WMSX.params.MACHINE&&this.applyParam("MACHINE",WMSX.params.MACHINE),WMSX.MACHINE=WMSX.MACHINE.trim().toUpperCase(),WMSX.MACHINE&&!WMSX.MACHINES_CONFIG[WMSX.MACHINE])return wmsx.Util.message("Invalid Machine: "+WMSX.MACHINE);WMSX.MACHINES_CONFIG[WMSX.MACHINE]&&!WMSX.MACHINES_CONFIG[WMSX.MACHINE].AUTO_TYPE||(WMSX.MACHINE=this.detectDefaultMachine()),delete WMSX.params.MACHINE,this.applyFinalConfig(),WMSX.PAGE_BACK_CSS&&(document.body.style.background=WMSX.PAGE_BACK_CSS),!WMSX.HARDDISK_URL&&!WMSX.HARDDISK_FILES_URL||WMSX.EXTENSIONS.HARDDISK||(WMSX.EXTENSIONS.HARDDISK=1),a()},applyFinalConfig:function(){this.applyPresets(WMSX.MACHINES_CONFIG[WMSX.MACHINE].PRESETS),this.applyPresets(WMSX.PRESETS);for(var a in WMSX.params)this.applyParam(a,WMSX.params[a]);this.normalizeParameterTypes()},applyPresets:function(a,b){for(var c=(a||"").trim().toUpperCase().split(","),d=0;d<c.length;d++)this.applyPreset(c[d].trim(),b)},applyPreset:function(a,b){if(a){var c=WMSX.PRESETS_CONFIG[a]||WMSX.PRESETS_CONFIG[a.replace(/(.)_+/g,"$1")];if(c){b||wmsx.Util.log("Applying preset: "+a);for(var d in c){var e=d.trim().toUpperCase();"_"!==e[0]?this.applyParam(e,c[d]):"_INCLUDE"===e&&this.applyPresets(c[d],!0)}}else wmsx.Util.warning('Preset "'+a+'" not found, skipping...')}},applyParam:function(a,b){if(a.indexOf(".")<1)WMSX[a]=b;else{for(var c=WMSX,d=a.split("."),e=0;e<d.length-1;++e)c=c&&c[d[e]];c&&(c[d[d.length-1]]=b)}},applyPresetsConfigModifications:function(){WMSX.params.PRESETS&&this.applyParam("PRESETS",WMSX.params.PRESETS),delete WMSX.params.PRESETS;for(var a in WMSX.params)wmsx.Util.stringStartsWith(a,"PRESETS_CONFIG")&&this.applyParam(a,WMSX.params[a]);(WMSX.PRESETS||"").toUpperCase().indexOf("ALTSLOTCONFIG")<0||(this.applyPreset("ALTSLOTCONFIG"),WMSX.PRESETS=WMSX.PRESETS.replace(/ALTSLOTCONFIG/gi,""))},applyConfigFile:function(a,b){try{var c=JSON.parse(wmsx.Util.int8BitArrayToByteString(a))}catch(a){return wmsx.Util.message("Invalid Configuration file format:\n"+a)}wmsx.Util.applyPatchObject(WMSX,c),this.applyConfigDetails(b)},parseParams:function(){if(WMSX.ALLOW_URL_PARAMETERS)for(var a,b=(window.location.search||"").split("+").join(" "),c=/[?&]?([^=]+)=([^&]*)/g;a=c.exec(b);)WMSX.params[decodeURIComponent(a[1]).trim().toUpperCase()]=decodeURIComponent(a[2]).trim();for(var d in WMSX.params){var e=wmsx.Configurator.abbreviations[d];e&&(WMSX.params[e]=WMSX.params[d],delete WMSX.params[d])}},normalizeParameterTypes:function(){function a(c){if(!c||c.constructor!==Object)return!1;for(var d in c){var e=c[d];a(e)||(wmsx.Util.stringEndsWith(d,"SLOT")||wmsx.Util.stringEndsWith(d,"SLOT2"))&&b(c,d,e)}return!0}function b(a,b,c){if(c.constructor!==Array){var d=(""+c).match(/[0-9]/g);d&&(a[b]=d.map(function(a){return 0|a}))}}var c,d;c=WMSX.MACHINES_CONFIG=WMSX.MACHINES_CONFIG||{};for(d in c)c[d]||delete c[d];c=WMSX.EXTENSIONS_CONFIG=WMSX.EXTENSIONS_CONFIG||{};for(d in c)c[d]||delete c[d];c=WMSX.PRESETS_CONFIG=WMSX.PRESETS_CONFIG||{};for(d in c)c[d]||delete c[d];c=WMSX.EXTENSIONS=WMSX.EXTENSIONS||{},WMSX.ENVIRONMENT|=0,WMSX.RAMMAPPER_SIZE|=0,WMSX.RAMNORMAL_SIZE|=0,WMSX.AUTO_POWER_ON_DELAY|=0,WMSX.SCREEN_FULLSCREEN_MODE=WMSX.SCREEN_FULLSCREEN_MODE|=0,WMSX.SCREEN_FILTER_MODE|=0,WMSX.SCREEN_CRT_SCANLINES|=0,WMSX.SCREEN_CRT_PHOSPHOR|=0,WMSX.SCREEN_DEFAULT_SCALE=parseFloat(WMSX.SCREEN_DEFAULT_SCALE),WMSX.SCREEN_DEFAULT_ASPECT=parseFloat(WMSX.SCREEN_DEFAULT_ASPECT),WMSX.SCREEN_CONTROL_BAR|=0,WMSX.SCREEN_FORCE_HOST_NATIVE_FPS|=0,WMSX.SCREEN_VSYNC_MODE|=0,WMSX.SCREEN_VIDEO_OUT|=0,WMSX.SCREEN_COLORS|=0,WMSX.AUDIO_MONITOR_BUFFER_BASE|=0,WMSX.AUDIO_MONITOR_BUFFER_SIZE|=0,WMSX.AUDIO_SIGNAL_BUFFER_RATIO=parseFloat(WMSX.AUDIO_SIGNAL_BUFFER_RATIO),WMSX.AUDIO_SIGNAL_ADD_FRAMES|=0;var e=Number.parseFloat(WMSX.Z80_CLOCK_MODE);WMSX.Z80_CLOCK_MODE=isNaN(e)?0:Number.parseFloat(e.toFixed(2)),e=Number.parseFloat(WMSX.Z80_SOFT_TURBO_MULTI),WMSX.Z80_SOFT_TURBO_MULTI=isNaN(e)?1.5:Number.parseFloat(e.toFixed(2)),e=Number.parseFloat(WMSX.VDP_CLOCK_MODE),WMSX.VDP_CLOCK_MODE=isNaN(e)?0:Number.parseFloat(e.toFixed(2)),e=Number.parseFloat(WMSX.VDP_SOFT_TURBO_MULTI),WMSX.VDP_SOFT_TURBO_MULTI=isNaN(e)?2:Number.parseFloat(e.toFixed(2)),e=Number.parseFloat(WMSX.R800_CLOCK_MODE),WMSX.R800_CLOCK_MODE=isNaN(e)?0:Number.parseFloat(e.toFixed(2)),WMSX.CPU_SOFT_TURBO_AUTO_ON|=0,WMSX.DEBUG_MODE|=0,WMSX.SPRITES_DEBUG_MODE|=0,WMSX.BOOT_KEYS_FRAMES|=0,WMSX.BOOT_DURATION_AUTO|=0,WMSX.FAST_BOOT|=0,WMSX.SPEED|=0,WMSX.JOYSTICKS_MODE|=0,WMSX.JOYKEYS_MODE|=0,WMSX.MOUSE_MODE|=0,WMSX.TOUCH_MODE|=0,WMSX.MOBILE_MODE|=0,WMSX.VOL=Number(WMSX.VOL),isNaN(WMSX.VOL)&&(WMSX.VOL=1),WMSX.HARDDISK_MIN_SIZE_KB|=0,WMSX.MEGARAM_SIZE|=0,WMSX.CPU_PANA_TURBO|=0,WMSX.CPU_FAKE_TR_TURBO|=0,WMSX.R800_TIMING|=0,WMSX.VDP_TYPE|=0,WMSX.VDP_PALETTE|=0,WMSX.MEDIA_CHANGE_DISABLED=!0===WMSX.MEDIA_CHANGE_DISABLED||"true"===WMSX.MEDIA_CHANGE_DISABLED,WMSX.SCREEN_RESIZE_DISABLED=!0===WMSX.SCREEN_RESIZE_DISABLED||"true"===WMSX.SCREEN_RESIZE_DISABLED,WMSX.LIGHT_STATES=!0===WMSX.LIGHT_STATES||"true"===WMSX.LIGHT_STATES,a(WMSX)},slotURLSpecs:function(){var a=[];for(var b in WMSX)if(wmsx.Util.stringStartsWith(b,"SLOT")&&wmsx.Util.stringEndsWith(b,"_URL")){var c=WMSX[b];if(delete WMSX[b],null!==c&&void 0!==c){var d=b.match(/[0-9P]/g);if(d){var e=d.map(function(a){return"P"===a?-1:0|a});if(e[0]>=0){var f="SLOT"+d[0]+(d[1]||"")+"_FORMAT",g=c?WMSX[f]:null;delete WMSX[f];var h="SLOT"+d[0]+(d[1]||"")+"_START",i=c?WMSX[h]:null;delete WMSX[h],function(b,c,d,e){a[a.length]={url:b,onSuccess:function(a){WMSX.room.fileLoader.loadFromContentAsSlot(a.url,a.content,c,!0,d,e,!0)}}}(c||"@[Empty].rom",e,g,i)}}}}return a},mediaURLSpecs:function(){var a=wmsx.FileLoader.OPEN_TYPE;return[WMSX.AUTODETECT_URL&&{url:WMSX.AUTODETECT_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.AUTO,0,!0)}},WMSX.CARTRIDGE1_URL&&{url:WMSX.CARTRIDGE1_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.ROM,0,!0,!1,WMSX.CARTRIDGE1_FORMAT)}},WMSX.CARTRIDGE2_URL&&{url:WMSX.CARTRIDGE2_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.ROM,1,!0,!1,WMSX.CARTRIDGE2_FORMAT)}},WMSX.DISKA_URL&&{url:WMSX.DISKA_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.DISK,0,!0)}},!WMSX.DISKA_URL&&WMSX.DISKA_FILES_URL?{url:WMSX.DISKA_FILES_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.AUTO_AS_DISK,0,!0)}}:null,WMSX.DISKB_URL&&{url:WMSX.DISKB_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.DISK,1,!0)}},!WMSX.DISKB_URL&&WMSX.DISKB_FILES_URL?{url:WMSX.DISKB_FILES_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.AUTO_AS_DISK,1,!0)}}:null,WMSX.HARDDISK_URL&&{url:WMSX.HARDDISK_URL,
onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.DISK,2,!0)}},!WMSX.HARDDISK_URL&&WMSX.HARDDISK_FILES_URL?{url:WMSX.HARDDISK_FILES_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.AUTO_AS_DISK,2,!0)}}:null,WMSX.TAPE_URL&&{url:WMSX.TAPE_URL,onSuccess:function(b){WMSX.room.fileLoader.loadFromContent(b.url,b.content,a.TAPE,0,!0)}}]},extensionsInitialURLSpecs:function(){return WMSX.room.machine.getExtensionsSocket().getInitialLoaderURLSpecs()},detectDefaultMachine:function(){var a=WMSX.MACHINES_CONFIG[WMSX.MACHINE]&&WMSX.MACHINES_CONFIG[WMSX.MACHINE].AUTO_TYPE||3,b=wmsx.Util.userLanguage(),c="A";0===b.indexOf("ja")&&(c="J");var d=""+WMSX.MACHINE+c;if(!WMSX.MACHINES_CONFIG[d])for(d in WMSX.MACHINES_CONFIG)if(WMSX.MACHINES_CONFIG[d].TYPE<=a)break;return wmsx.Util.log("Machine auto-detection: "+d),d},saveState:function(){return{mc:WMSX.MACHINES_CONFIG,ec:WMSX.EXTENSIONS_CONFIG,pc:WMSX.PRESETS_CONFIG}},loadState:function(a,b){this.loadingStateVersion=a.v||0,b?(WMSX.MACHINES_CONFIG=b.mc,WMSX.EXTENSIONS_CONFIG=b.ec,WMSX.PRESETS_CONFIG=b.pc):this.adaptForOldState(a);for(var c=0;c<this.listeners.length;++c)this.listeners[c].configurationStateUpdate()},adaptForOldState:function(a){WMSX.MACHINES_CONFIG=JSON.parse(this.originalConfig.MACHINES_CONFIG),WMSX.EXTENSIONS_CONFIG=JSON.parse(this.originalConfig.EXTENSIONS_CONFIG),WMSX.PRESETS_CONFIG=JSON.parse(this.originalConfig.PRESETS_CONFIG),a.v<50?(WMSX.EXTENSIONS_CONFIG.HARDDISK.SLOT=[2,2],WMSX.EXTENSIONS_CONFIG.DISK.SLOT=[2,2],WMSX.EXTENSIONS_CONFIG.MSXMUSIC.SLOT=[2,3],WMSX.EXTENSIONS_CONFIG.KANJI.SLOT=[3,1],WMSX.EXPANSION1_SLOT=[3,2],WMSX.EXPANSION2_SLOT=[3,3]):a.v<51?(WMSX.EXTENSIONS_CONFIG.HARDDISK.SLOT2=[3,3],WMSX.EXTENSIONS_CONFIG.DISK.SLOT2=[3,3],WMSX.EXTENSIONS_CONFIG.MSXMUSIC.SLOT=[3,2],WMSX.EXTENSIONS_CONFIG.KANJI.SLOT=[2,1],WMSX.EXPANSION1_SLOT=[2,2],WMSX.EXPANSION2_SLOT=[2,3]):(WMSX.EXTENSIONS_CONFIG.HARDDISK.SLOT2=[3,3],WMSX.EXTENSIONS_CONFIG.DISK.SLOT2=[3,3],WMSX.EXTENSIONS_CONFIG.MSXMUSIC.SLOT=[3,2])},adaptROMSourceForOldState:function(a){if(this.loadingStateVersion>=600)return a;var b=a;for(var c in this.romSourcePre600Adapts)b=b.split(this.romSourcePre600Adapts[c][0]).join(this.romSourcePre600Adapts[c][1]);return b},backupOriginalConfig:function(){this.originalConfig.MACHINES_CONFIG=JSON.stringify(WMSX.MACHINES_CONFIG),this.originalConfig.EXTENSIONS_CONFIG=JSON.stringify(WMSX.EXTENSIONS_CONFIG),this.originalConfig.PRESETS_CONFIG=JSON.stringify(WMSX.PRESETS_CONFIG)},addConfigurationStateListener:function(a){this.listeners.indexOf(a)>=0||this.listeners.push(a)},initExtensions:function(){if(!Object.keys(WMSX.EXTENSIONS).length)for(var a in WMSX.EXTENSIONS_CONFIG)WMSX.EXTENSIONS[a]=0},loadingStateVersion:0,listeners:[],originalConfig:{},abbreviations:{E:"ENVIRONMENT",ENV:"ENVIRONMENT",M:"MACHINE",P:"PRESETS",PRESET:"PRESETS",ROM:"CARTRIDGE1_URL",CART:"CARTRIDGE1_URL",CART1:"CARTRIDGE1_URL",CART2:"CARTRIDGE2_URL",ROM_FORMAT:"CARTRIDGE1_FORMAT",CART_FORMAT:"CARTRIDGE1_FORMAT",CART1_FORMAT:"CARTRIDGE1_FORMAT",CART2_FORMAT:"CARTRIDGE2_FORMAT",DISK:"DISKA_URL",DISK_FILES:"DISKA_FILES_URL",DISKA:"DISKA_URL",DISKB:"DISKB_URL",DISKA_FILES:"DISKA_FILES_URL",DISKB_FILES:"DISKB_FILES_URL",HARDDISK:"HARDDISK_URL",HARDDISK_FILES:"HARDDISK_FILES_URL",TAPE:"TAPE_URL",RAM_SIZE:"RAMNORMAL_SIZE",ANY:"AUTODETECT_URL",AUTO:"AUTODETECT_URL",AUTODETECT:"AUTODETECT_URL",STATE:"STATE_URL",SAVESTATE:"STATE_URL",JOIN:"NETPLAY_JOIN",NICK:"NETPLAY_NICK",JOYSTICKS:"JOYSTICKS_MODE",JOYKEYS:"JOYKEYS_MODE",MOUSE:"MOUSE_MODE",TOUCH:"TOUCH_MODE",MOBILE:"MOBILE_MODE",TURBO:"Z80_CLOCK_MODE",CPU_TURBO:"Z80_CLOCK_MODE",CPU_TURBO_MODE:"Z80_CLOCK_MODE",Z80_CLOCK:"Z80_CLOCK_MODE",R800_CLOCK:"R800_CLOCK_MODE",VDP_TURBO:"VDP_CLOCK_MODE",VDP_CLOCK:"VDP_CLOCK_MODE",VERSION:"VERSION_CHANGE_ATTEMPTED"},romSourcePre600Adapts:[["@KanjiBasic.bios","@KanjiBasic2PLogo_NTSC.bios"],["@KanjiBasic_PAL.bios","@KanjiBasic2PLogo_PAL.bios"],["@[KanjiBasic].bios","@KanjiBasic2PLogo_NTSC.bios"],["@[MoonSound].rom","@[OPL4].rom"]]},WMSX.start=function(a){"use strict";if(!WMSX.screenElement&&(WMSX.screenElement=document.getElementById(WMSX.SCREEN_ELEMENT_ID),!WMSX.screenElement))throw new Error('WMSX cannot be started. HTML document is missing screen element with id "'+WMSX.SCREEN_ELEMENT_ID+'"');delete WMSX.start,delete WMSX.preLoadImagesAndStart,wmsx.Configurator.applyConfig(function(){WMSX.userPreferences.load(),void 0===a&&(a=WMSX.AUTO_POWER_ON_DELAY>=0),WMSX.room=new wmsx.Room(WMSX.screenElement,a),WMSX.room.powerOn(),wmsx.Util.log("version "+WMSX.VERSION+" started"),wmsx.ROMDatabase.uncompress();var b=WMSX.NETPLAY_JOIN;if(!b&&WMSX.STATE_URL)new wmsx.MultiDownloader([{url:WMSX.STATE_URL}],function(a){WMSX.room.start(function(){WMSX.room.fileLoader.loadFromContent(a[0].url,a[0].content,wmsx.FileLoader.OPEN_TYPE.STATE,0,!1)})}).start();else{var c=wmsx.Configurator.slotURLSpecs(),d=wmsx.Configurator.extensionsInitialURLSpecs(),e=b?[]:wmsx.Configurator.mediaURLSpecs();new wmsx.MultiDownloader(c.concat(e).concat(d),function(){WMSX.room.start(b?function(){WMSX.room.getNetClient().joinSession(b,WMSX.NETPLAY_NICK)}:void 0)},function(a){wmsx.Util.message(a.errorMessage)}).start()}}),WMSX.shutdown=function(){WMSX.room&&WMSX.room.powerOff(),wmsx.Util.log("shutdown")}},WMSX.preLoadImagesAndStart=function(){function a(a){WMSX.start&&WMSX.AUTO_START&&(a||b&&0===c)&&WMSX.start()}var b=!1,c=wmsx.Images.embedded?0:wmsx.Images.count;if(document.addEventListener("DOMContentLoaded",function(){b=!0,a(!1)}),c>0)for(var d in wmsx.Images.urls){var e=new Image;e.src=wmsx.Images.urls[d],e.onload=function(){c--,a(!1)}}window.addEventListener("load",function(){a(!0)})},window.applicationCache&&(window.applicationCache.status===window.applicationCache.UPDATEREADY?onUpdateReady():window.applicationCache.addEventListener("updateready",onUpdateReady)),WMSX.VERSION="6.0.0",WMSX.preLoadImagesAndStart();